feat(agent): add controlled task execution
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { tool } from "@opencode-ai/plugin";
|
||||
import { getInternalBridgeConfig } from "../internalBridge.js";
|
||||
import { proposedTaskActionSchema } from "../../src/product/operational-task-contract.js";
|
||||
|
||||
export default tool({
|
||||
description: "Propose a work-order creation or command action for human approval after its node exists in the published current plan. This tool only creates a pending approval record and can never execute the action. After success, republish the plan with the returned action_id in action_refs before publishing the final report. 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;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user