import { tool } from "../tool.js"; import { getInternalBridgeConfig } from "../internalBridge.js"; import { proposedTaskActionSchema } from "../../src/product/operational-task-contract.js"; export default tool({ description: "Propose a concrete work-order creation or command draft for human approval after saving an interim concluded report for the current run. This tool only creates a pending approval record and can never execute the action. No execution plan is required; node_id is an optional display reference. After success, publish a final report and optionally link the returned action_id in diagram node_refs. create_work_order requires title, description and work_order_type; its priority is normal or urgent. issue_command requires command_type, target, parameters, impact_summary, non-empty preconditions and expires_at.", args: { request_id: tool.schema.string().describe("Stable UUID idempotency key for this proposal"), kind: tool.schema.enum(["create_work_order", "issue_command"]), reason: tool.schema.string(), payload: tool.schema.union([ tool.schema.object({ title: tool.schema.string(), description: tool.schema.string(), work_order_type: tool.schema.string(), priority: tool.schema.enum(["normal", "urgent"]).default("normal"), scheduled_at: tool.schema.string().nullable().optional(), location: tool.schema.string().nullable().optional(), assignee: tool.schema.string().nullable().optional(), }).strict(), tool.schema.object({ command_type: tool.schema.string(), target: tool.schema.object({ kind: tool.schema.string(), id: tool.schema.string(), }).strict(), parameters: tool.schema.record(tool.schema.string(), tool.schema.unknown()), impact_summary: tool.schema.string(), preconditions: tool.schema.array(tool.schema.string()).min(1), expires_at: tool.schema.string(), }).strict(), ]), evidence_refs: tool.schema.array(tool.schema.string()), node_id: tool.schema.string().optional(), }, async execute(action, context) { const validatedAction = proposedTaskActionSchema.parse(action); const { baseUrl, internalToken } = getInternalBridgeConfig(); const response = await fetch(`${baseUrl}/internal/operational-task/actions`, { method: "POST", headers: { "Content-Type": "application/json", "x-agent-internal-token": internalToken }, body: JSON.stringify({ session_id: context.sessionID, action: validatedAction }), }); const text = await response.text(); if (!response.ok) throw new Error(`task action proposal failed (${response.status}): ${text}`); return text; }, });