import { tool } from "../tool.js"; import { getInternalBridgeConfig } from "../internalBridge.js"; import { taskProgressSchema } from "../../src/product/investigation-report.js"; import { taskPublicationGraphProgressSchema } from "./task-publication-schema.js"; export default tool({ description: "Save an optional investigation process reference with summary and optional graph_update. Update when the route materially changes, an important finding or failed attempt should be recorded, or a report is being organized. No per-step publication, frequent refresh, or live synchronization is required. The Server retains prior nodes and paths and generates Mermaid. Use stable node_id values; only submit changes. Before extending a saved graph, read get_task_context section=progress when needed. Optional status annotations are reference, recorded, needs_input, failed, and not_taken. They describe the saved explanation, not execution lifecycle: recorded means a finding exists, not that a task, calculation, work order, or field action completed. Retain failed attempts with the actual reason in detail; append a new node and edge for a retry or alternative. Text-only updates preserve the graph. Graphs never schedule execution, settle runs, or infer human completion. Use known supply feature ids and saved evidence/action references. Reuse request_id on retries.", args: { request_id: tool.schema.string().uuid().describe("Stable UUID idempotency key; reuse for retries of this progress publication"), progress: taskPublicationGraphProgressSchema, }, async execute(args, context) { const progress = taskProgressSchema.parse(taskPublicationGraphProgressSchema.parse(args.progress)); const { baseUrl, internalToken } = getInternalBridgeConfig(); const response = await fetch(`${baseUrl}/internal/operational-task/artifacts`, { method: "POST", headers: { "Content-Type": "application/json", "x-agent-internal-token": internalToken }, signal: context.signal, body: JSON.stringify({ session_id: context.sessionID, request_id: args.request_id, progress }), }); const text = await response.text(); if (!response.ok) throw new Error(`task progress publish failed (${response.status}): ${text}`); return text; }, });