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
13 changes: 13 additions & 0 deletions inc/Api/Chat/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,19 @@ public static function handle_chat( WP_REST_Request $request ) {
$pipeline_id = (int) $request->get_param( 'selected_pipeline_id' );
if ( $pipeline_id > 0 ) {
$input['selected_pipeline_id'] = $pipeline_id;

// A selected pipeline means this request originates from the DM admin
// pipeline editor surface. Opt that surface into pipeline_editor mode
// (composed on top of chat) so it receives the pipeline/handler/flow
// guidance, the pipelines inventory, and the pipeline-editing tools.
// Portable surfaces (frontend widgets, bridges) send no pipeline and
// stay on generic chat. See data-machine#2425.
$requested_mode = sanitize_key( (string) ( $request->get_param( 'mode' ) ?? '' ) );
$composed_modes = array( 'chat', 'pipeline_editor' );
if ( '' !== $requested_mode && ! in_array( $requested_mode, $composed_modes, true ) ) {
$composed_modes[] = $requested_mode;
}
$input['modes'] = $composed_modes;
}

if ( $request_id ) {
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/ChatPipelinesDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function ( $directives ) {
$directives[] = array(
'class' => ChatPipelinesDirective::class,
'priority' => 45,
'modes' => array( 'chat' ),
'modes' => array( 'pipeline_editor' ),
);

return $directives;
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/AddPipelineStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class AddPipelineStep extends BaseTool {

public function __construct() {
$this->registerTool( 'add_pipeline_step', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/add-pipeline-step' ) );
$this->registerTool( 'add_pipeline_step', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/add-pipeline-step' ) );
}

private static function getValidStepTypes(): array {
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/ApiQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class ApiQuery extends BaseTool {

public function __construct() {
$this->registerTool( 'api_query', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'access_level' => 'editor' ) );
$this->registerTool( 'api_query', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'access_level' => 'editor' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/AuthenticateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class AuthenticateHandler extends BaseTool {

public function __construct() {
$this->registerTool( 'authenticate_handler', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'abilities' => array( 'datamachine/get-handlers', 'datamachine/get-auth-status', 'datamachine/save-auth-config', 'datamachine/disconnect-auth' ) ) );
$this->registerTool( 'authenticate_handler', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'abilities' => array( 'datamachine/get-handlers', 'datamachine/get-auth-status', 'datamachine/save-auth-config', 'datamachine/disconnect-auth' ) ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/ConfigureFlowSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class ConfigureFlowSteps extends BaseTool {

public function __construct() {
$this->registerTool( 'configure_flow_steps', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'abilities' => array( 'datamachine/update-flow-step', 'datamachine/validate-handler', 'datamachine/configure-flow-steps', 'datamachine/validate-flow-steps-config' ) ) );
$this->registerTool( 'configure_flow_steps', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'abilities' => array( 'datamachine/update-flow-step', 'datamachine/validate-handler', 'datamachine/configure-flow-steps', 'datamachine/validate-flow-steps-config' ) ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/ConfigurePipelineStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class ConfigurePipelineStep extends BaseTool {

public function __construct() {
$this->registerTool( 'configure_pipeline_step', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/update-pipeline-step' ) );
$this->registerTool( 'configure_pipeline_step', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/update-pipeline-step' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/CopyFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class CopyFlow extends BaseTool {

public function __construct() {
$this->registerTool( 'copy_flow', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/duplicate-flow' ) );
$this->registerTool( 'copy_flow', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/duplicate-flow' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/CreateFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class CreateFlow extends BaseTool {

public function __construct() {
$this->registerTool( 'create_flow', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'abilities' => array( 'datamachine/create-flow', 'datamachine/update-flow-step' ) ) );
$this->registerTool( 'create_flow', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'abilities' => array( 'datamachine/create-flow', 'datamachine/update-flow-step' ) ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/CreatePipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class CreatePipeline extends BaseTool {

public function __construct() {
$this->registerTool( 'create_pipeline', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/create-pipeline' ) );
$this->registerTool( 'create_pipeline', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/create-pipeline' ) );
}

private static function getValidStepTypes(): array {
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/DeleteFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class DeleteFile extends BaseTool {

public function __construct() {
$this->registerTool( 'delete_file', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/delete-flow-file' ) );
$this->registerTool( 'delete_file', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/delete-flow-file' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/DeleteFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class DeleteFlow extends BaseTool {

public function __construct() {
$this->registerTool( 'delete_flow', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/delete-flow' ) );
$this->registerTool( 'delete_flow', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/delete-flow' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/DeletePipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class DeletePipeline extends BaseTool {

public function __construct() {
$this->registerTool( 'delete_pipeline', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/delete-pipeline' ) );
$this->registerTool( 'delete_pipeline', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/delete-pipeline' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/DeletePipelineStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class DeletePipelineStep extends BaseTool {

public function __construct() {
$this->registerTool( 'delete_pipeline_step', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/delete-pipeline-step' ) );
$this->registerTool( 'delete_pipeline_step', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/delete-pipeline-step' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/ExecuteWorkflowTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class ExecuteWorkflowTool extends BaseTool {

public function __construct() {
$this->registerTool( 'execute_workflow', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/execute-workflow' ) );
$this->registerTool( 'execute_workflow', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/execute-workflow' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/GetHandlerDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class GetHandlerDefaults extends BaseTool {

public function __construct() {
$this->registerTool( 'get_handler_defaults', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'abilities' => array( 'datamachine/get-handler-site-defaults', 'datamachine/get-handlers', 'datamachine/get-handler-config-fields' ) ) );
$this->registerTool( 'get_handler_defaults', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'abilities' => array( 'datamachine/get-handler-site-defaults', 'datamachine/get-handlers', 'datamachine/get-handler-config-fields' ) ) );
}

public function getToolDefinition(): array {
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/GetProblemFlows.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class GetProblemFlows extends BaseTool {

public function __construct() {
$this->registerTool( 'get_problem_flows', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/get-problem-flows' ) );
$this->registerTool( 'get_problem_flows', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/get-problem-flows' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/ListFlows.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class ListFlows extends BaseTool {

public function __construct() {
$this->registerTool( 'list_flows', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/get-flows' ) );
$this->registerTool( 'list_flows', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/get-flows' ) );
}

public function getToolDefinition(): array {
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/ManageJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class ManageJobs extends BaseTool {

public function __construct() {
$this->registerTool( 'manage_jobs', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'abilities' => array( 'datamachine/get-jobs', 'datamachine/get-jobs-summary', 'datamachine/delete-jobs', 'datamachine/fail-job', 'datamachine/retry-job', 'datamachine/recover-stuck-jobs' ) ) );
$this->registerTool( 'manage_jobs', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'abilities' => array( 'datamachine/get-jobs', 'datamachine/get-jobs-summary', 'datamachine/delete-jobs', 'datamachine/fail-job', 'datamachine/retry-job', 'datamachine/recover-stuck-jobs' ) ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/ManageLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class ManageLogs extends BaseTool {

public function __construct() {
$this->registerTool( 'manage_logs', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'abilities' => array( 'datamachine/clear-logs', 'datamachine/get-log-metadata' ) ) );
$this->registerTool( 'manage_logs', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'abilities' => array( 'datamachine/clear-logs', 'datamachine/get-log-metadata' ) ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/ManageQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class ManageQueue extends BaseTool {

public function __construct() {
$this->registerTool( 'manage_queue', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'abilities' => array( 'datamachine/queue-add', 'datamachine/queue-list', 'datamachine/queue-clear', 'datamachine/queue-remove', 'datamachine/queue-update', 'datamachine/queue-move', 'datamachine/queue-mode' ) ) );
$this->registerTool( 'manage_queue', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'abilities' => array( 'datamachine/queue-add', 'datamachine/queue-list', 'datamachine/queue-clear', 'datamachine/queue-remove', 'datamachine/queue-update', 'datamachine/queue-move', 'datamachine/queue-mode' ) ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/ReadLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class ReadLogs extends BaseTool {

public function __construct() {
$this->registerTool( 'read_logs', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/read-logs' ) );
$this->registerTool( 'read_logs', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/read-logs' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/ReorderPipelineSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class ReorderPipelineSteps extends BaseTool {

public function __construct() {
$this->registerTool( 'reorder_pipeline_steps', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/reorder-pipeline-steps' ) );
$this->registerTool( 'reorder_pipeline_steps', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/reorder-pipeline-steps' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/RunFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class RunFlow extends BaseTool {

public function __construct() {
$this->registerTool( 'run_flow', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'abilities' => array( 'datamachine/run-flow', 'datamachine/schedule-flow' ) ) );
$this->registerTool( 'run_flow', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'abilities' => array( 'datamachine/run-flow', 'datamachine/schedule-flow' ) ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/SetHandlerDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class SetHandlerDefaults extends BaseTool {

public function __construct() {
$this->registerTool( 'set_handler_defaults', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/update-handler-defaults' ) );
$this->registerTool( 'set_handler_defaults', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/update-handler-defaults' ) );
}

public function getToolDefinition(): array {
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/SystemHealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class SystemHealthCheck extends BaseTool {

public function __construct() {
$this->registerTool( 'system_health_check', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/system-health-check' ) );
$this->registerTool( 'system_health_check', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/system-health-check' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/Api/Chat/Tools/UpdateFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class UpdateFlow extends BaseTool {

public function __construct() {
$this->registerTool( 'update_flow', array( $this, 'getToolDefinition' ), array( 'chat' ), array( 'ability' => 'datamachine/update-flow' ) );
$this->registerTool( 'update_flow', array( $this, 'getToolDefinition' ), array( 'pipeline_editor' ), array( 'ability' => 'datamachine/update-flow' ) );
}

/**
Expand Down
27 changes: 22 additions & 5 deletions inc/Engine/AI/Directives/AgentModeDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,23 @@ class AgentModeDirective implements DirectiveInterface {
private const CHAT_MODE = <<<'MD'
# Chat Session Context

This is a live chat session with a user in the Data Machine admin UI. You have tools to configure and manage workflows. Your identity, voice, and knowledge come from your memory files above.
This is a live interactive chat session with a user. Your identity, voice, and knowledge come from your memory files above.
MD;

/**
* Default pipeline editor mode guidance.
*
* The DM admin pipeline-editing surface (the pipeline chat with a selected
* pipeline) opts into this mode in addition to `chat`. It carries the
* pipeline/handler/flow operating manual that used to live in CHAT_MODE.
* Generic chat surfaces (frontend widgets, bridges) never receive it.
*
* @since 0.139.0
*/
private const PIPELINE_EDITOR_MODE = <<<'MD'
# Pipeline Editor Context

You are in the Data Machine admin pipeline editor. You have tools to configure and manage workflows.

## Data Machine Architecture

Expand Down Expand Up @@ -194,10 +210,11 @@ public static function get_outputs( string $provider_name, array $tools, ?string
*/
private static function get_default_for_mode( string $mode ): string {
return match ( $mode ) {
'chat' => self::CHAT_MODE,
'pipeline' => self::PIPELINE_MODE,
'system' => self::SYSTEM_MODE,
default => '',
'chat' => self::CHAT_MODE,
'pipeline_editor' => self::PIPELINE_EDITOR_MODE,
'pipeline' => self::PIPELINE_MODE,
'system' => self::SYSTEM_MODE,
default => '',
};
}

Expand Down
5 changes: 5 additions & 0 deletions inc/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ function () {
'description' => __( 'Structured workflow execution. Operates within defined steps — efficient models work well.', 'data-machine' ),
'memory_contexts' => array( 'agent_identity', 'agent_memory' ),
) );
AgentModeRegistry::register( 'pipeline_editor', 25, array(
'label' => __( 'Pipeline Editor Agent', 'data-machine' ),
'description' => __( 'Admin pipeline-editing surface. Composes on top of chat to add pipeline/handler/flow guidance, the pipelines inventory, and pipeline-editing tools.', 'data-machine' ),
'memory_contexts' => array( 'agent_identity', 'agent_memory', 'user_profile' ),
) );
AgentModeRegistry::register( 'system', 30, array(
'label' => __( 'System Agent', 'data-machine' ),
'description' => __( 'Background tasks like alt text generation and issue creation.', 'data-machine' ),
Expand Down
20 changes: 19 additions & 1 deletion tests/Unit/AI/Tools/ChatToolsAvailabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,29 @@ public function set_up(): void {
$this->resolver = new ToolPolicyResolver();
}

public function test_chat_tools_include_update_flow(): void {
public function test_chat_tools_exclude_pipeline_editing_tools(): void {
// Pipeline-editing tools (update_flow et al.) moved from the generic
// chat mode to the dedicated pipeline_editor mode so portable chat
// surfaces (frontend widget, bridge) no longer inherit them.
// See data-machine#2425.
$tools = $this->resolver->resolve( [
'mode' => ToolPolicyResolver::MODE_CHAT,
] );

$this->assertIsArray( $tools );
$this->assertArrayNotHasKey( 'update_flow', $tools );
$this->assertArrayNotHasKey( 'create_pipeline', $tools );
$this->assertArrayNotHasKey( 'run_flow', $tools );
$this->assertArrayNotHasKey( 'execute_workflow', $tools );
}

public function test_pipeline_editor_tools_include_update_flow(): void {
// The pipeline-editing tools live on the pipeline_editor mode now; the
// DM admin pipeline chat opts into [chat, pipeline_editor].
$tools = $this->resolver->resolve( [
'mode' => 'pipeline_editor',
] );

$this->assertIsArray( $tools );
$this->assertArrayHasKey( 'update_flow', $tools );
$this->assertIsArray( $tools['update_flow'] );
Expand Down
Loading
Loading