Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions inc/Api/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ public static function register_routes() {
'methods' => WP_REST_Server::READABLE,
'callback' => array( self::class, 'handle_get_tools' ),
'permission_callback' => '__return_true', // Public endpoint
'args' => array(),
'args' => array(
'context' => array(
'type' => 'string',
'enum' => array( 'pipeline', 'chat', 'standalone', 'system' ),
'required' => false,
'description' => 'Filter tools by execution context. Returns only tools available in the specified context.',
),
),
)
);
}
Expand All @@ -56,11 +63,13 @@ public static function register_routes() {
* Filters to only global tools (excludes handler-specific tools).
*
* @since 0.1.2
* @param \WP_REST_Request $request REST request object.
* @return \WP_REST_Response Tools response
*/
public static function handle_get_tools() {
public static function handle_get_tools( $request ) {
$context = $request->get_param( 'context' );
$tool_manager = new \DataMachine\Engine\AI\Tools\ToolManager();
$tools = $tool_manager->get_tools_for_api();
$tools = $tool_manager->get_tools_for_api( $context );

return rest_ensure_response(
array(
Expand Down
10 changes: 8 additions & 2 deletions inc/Core/Admin/Pages/Logs/assets/react/LogsApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Keeps the classic tabbed agent view, now backed by agent IDs.
*/

/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
Expand All @@ -14,12 +18,14 @@ import LogsFilters from './components/LogsFilters';
import LogsTable from './components/LogsTable';

const LogsApp = () => {
const [ filters, setFilters ] = useState( { level: '', search: '' } );

return (
<div className="datamachine-logs-app">
<LogsHeader />
<LogsAgentTabs />
<LogsFilters />
<LogsTable />
<LogsFilters filters={ filters } onFiltersChange={ setFilters } />
<LogsTable filters={ filters } />
</div>
);
};
Expand Down
20 changes: 11 additions & 9 deletions inc/Core/Admin/Pages/Logs/assets/react/components/LogsFilters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* WordPress dependencies
*/
import { useState, useCallback } from '@wordpress/element';
import { useCallback } from '@wordpress/element';
import { Button, SelectControl, SearchControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
/**
Expand All @@ -28,32 +28,34 @@ const LEVEL_OPTIONS = [
{ value: 'debug', label: __( 'Debug', 'data-machine' ) },
];

const LogsFilters = () => {
const LogsFilters = ( { filters, onFiltersChange } ) => {
const queryClient = useQueryClient();
const [ level, setLevel ] = useState( '' );
const [ search, setSearch ] = useState( '' );

const handleRefresh = useCallback( () => {
queryClient.invalidateQueries( { queryKey: logsKeys.all } );
}, [ queryClient ] );

// Store filters on window for LogsTable to read.
// This avoids prop-drilling through context for a simple page.
window.__dmLogsFilters = { level, search };
const setLevel = ( level ) => {
onFiltersChange( { ...filters, level } );
};

const setSearch = ( search ) => {
onFiltersChange( { ...filters, search } );
};

return (
<div className="datamachine-logs-filters">
<div className="datamachine-logs-filters-left">
<SelectControl
label={ __( 'Level', 'data-machine' ) }
value={ level }
value={ filters.level }
options={ LEVEL_OPTIONS }
onChange={ setLevel }
__nextHasNoMarginBottom
/>
<SearchControl
label={ __( 'Search', 'data-machine' ) }
value={ search }
value={ filters.search }
onChange={ setSearch }
placeholder={ __(
'Search messages...',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ const LEVEL_COLORS = {
debug: '#757575',
};

const LogsTable = () => {
const LogsTable = ( { filters = {} } ) => {
const [ page, setPage ] = useState( 1 );
const perPage = 50;
const selectedAgentId = useAgentStore( ( state ) => state.selectedAgentId );

// Read filters from window (set by LogsFilters).
const filters = window.__dmLogsFilters || {};

const queryFilters = {
per_page: perPage,
page,
Expand Down
6 changes: 3 additions & 3 deletions inc/Core/Admin/Pages/Pipelines/assets/react/queries/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export const useSchedulingIntervals = () =>
staleTime: Infinity, // Scheduling intervals don't change
} );

export const useTools = () =>
export const useTools = ( context = 'pipeline' ) =>
useQuery( {
queryKey: [ 'config', 'tools' ],
queryKey: [ 'config', 'tools', context ],
queryFn: async () => {
const result = await getTools();
const result = await getTools( context );
return result.success ? result.data : {};
},
staleTime: 30 * 60 * 1000, // 30 minutes - tools don't change often
Expand Down
6 changes: 4 additions & 2 deletions inc/Core/Admin/Pages/Pipelines/assets/react/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,12 @@ export const getProviders = async () => {
/**
* Get available tools
*
* @param {string|null} context - Optional context filter ('pipeline', 'chat', 'standalone', 'system')
* @return {Promise<Object>} Tools configuration
*/
export const getTools = async () => {
return await client.get( '/tools' );
export const getTools = async ( context = null ) => {
const params = context ? { context } : {};
return await client.get( '/tools', params );
};

/**
Expand Down
14 changes: 12 additions & 2 deletions inc/Engine/AI/Tools/ToolManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,19 @@ public function get_tools_for_settings_page(): array {
/**
* Get tools for REST API response.
*
* @param string|null $context Optional context to filter tools ('pipeline', 'chat', 'standalone', 'system').
* When null, returns all tools.
* @return array Tools formatted for API
*/
public function get_tools_for_api(): array {
$tools = $this->get_global_tools();
public function get_tools_for_api( ?string $context = null ): array {
// If context specified, use ToolPolicyResolver to filter appropriately
if ( null !== $context ) {
$resolver = new ToolPolicyResolver( $this );
$tools = $resolver->resolve( array( 'context' => $context ) );
} else {
$tools = $this->get_global_tools();
}

$formatted = array();

foreach ( $tools as $tool_id => $tool_config ) {
Expand All @@ -462,6 +471,7 @@ public function get_tools_for_api(): array {
'requires_config' => $this->requires_configuration( $tool_id ),
'configured' => $this->is_tool_configured( $tool_id ),
'globally_enabled' => $is_globally_enabled,
'contexts' => $tool_config['contexts'] ?? array(),
);
}

Expand Down
Loading