@ai-setting/roy-agent-core 1.5.80 → 1.5.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/env/agent/index.js +2 -2
- package/dist/env/event-source/index.js +2 -2
- package/dist/env/index.js +13 -13
- package/dist/env/prompt/index.js +1 -1
- package/dist/env/task/delegate/index.js +2 -2
- package/dist/env/task/index.js +4 -4
- package/dist/env/task/plugins/index.js +1 -1
- package/dist/env/task/tools/index.js +1 -1
- package/dist/env/workflow/engine/index.js +3 -3
- package/dist/env/workflow/index.js +5 -5
- package/dist/env/workflow/nodes/index.js +1 -1
- package/dist/env/workflow/tools/index.js +26 -142
- package/dist/env/workflow/utils/index.js +1 -1
- package/dist/index.js +14 -14
- package/dist/shared/@ai-setting/{roy-agent-core-jazhr292.js → roy-agent-core-6b0r2e7j.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-a6j7g1qe.js +428 -0
- package/dist/shared/@ai-setting/{roy-agent-core-7t0jen73.js → roy-agent-core-df3ng0pz.js} +6 -2
- package/dist/shared/@ai-setting/{roy-agent-core-0tgnq4nz.js → roy-agent-core-f6p7wwpd.js} +64 -5
- package/dist/shared/@ai-setting/{roy-agent-core-99j4w3fx.js → roy-agent-core-gb9gbkc3.js} +2 -0
- package/dist/shared/@ai-setting/{roy-agent-core-ajx32wzj.js → roy-agent-core-j754zgb4.js} +13 -0
- package/dist/shared/@ai-setting/{roy-agent-core-7mw366pc.js → roy-agent-core-j8q8119y.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-zf62vkc4.js → roy-agent-core-mbre4fxg.js} +32 -1
- package/dist/shared/@ai-setting/{roy-agent-core-11dnsfwp.js → roy-agent-core-p8jv13bm.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-4ws3w7cx.js → roy-agent-core-qbgd7bp6.js} +5 -2
- package/dist/shared/@ai-setting/{roy-agent-core-8x1gmqcv.js → roy-agent-core-t2q0rwt7.js} +3 -2
- package/dist/shared/@ai-setting/{roy-agent-core-s83ararq.js → roy-agent-core-v3t28k5n.js} +35 -3
- package/dist/shared/@ai-setting/{roy-agent-core-d32ecc9z.js → roy-agent-core-vgyj2rq9.js} +103 -1
- package/dist/shared/@ai-setting/{roy-agent-core-n9tw52zb.js → roy-agent-core-w83v54mj.js} +11 -6
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AskUserError,
|
|
3
|
+
init_workflow_hil
|
|
4
|
+
} from "./roy-agent-core-e25xkv53.js";
|
|
5
|
+
import {
|
|
6
|
+
createLogger,
|
|
7
|
+
init_logger
|
|
8
|
+
} from "./roy-agent-core-shme7set.js";
|
|
9
|
+
|
|
10
|
+
// src/env/workflow/tools/ask-user-tool.ts
|
|
11
|
+
init_workflow_hil();
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
var AskUserInputSchema = z.object({
|
|
14
|
+
query: z.string().describe("The question or request to ask the user"),
|
|
15
|
+
options: z.array(z.string()).optional().describe("Optional choices for the user"),
|
|
16
|
+
required_confirm: z.boolean().optional().describe("If true, user must explicitly confirm")
|
|
17
|
+
});
|
|
18
|
+
var askUserTool = {
|
|
19
|
+
name: "ask_user",
|
|
20
|
+
description: "Ask user for input or confirmation. Use this tool when you need user input or validation to continue the workflow.",
|
|
21
|
+
parameters: AskUserInputSchema,
|
|
22
|
+
async execute(args, context) {
|
|
23
|
+
const runId = context.metadata?.runId || "unknown";
|
|
24
|
+
const sessionId = context.metadata?.sessionId || `workflow_${runId}`;
|
|
25
|
+
const nodeId = context.metadata?.nodeId || "unknown";
|
|
26
|
+
let fullQuery = args.query;
|
|
27
|
+
if (args.options && args.options.length > 0) {
|
|
28
|
+
fullQuery = `${args.query} (选项: ${args.options.join(", ")})`;
|
|
29
|
+
}
|
|
30
|
+
throw new AskUserError(runId, sessionId, nodeId, "agent", fullQuery);
|
|
31
|
+
},
|
|
32
|
+
metadata: {
|
|
33
|
+
category: "workflow",
|
|
34
|
+
tags: ["human-in-loop", "user-input"],
|
|
35
|
+
version: "1.0.0"
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var askUserToolInstance = askUserTool;
|
|
39
|
+
|
|
40
|
+
// src/env/workflow/tools/workflow-get-tool.ts
|
|
41
|
+
init_logger();
|
|
42
|
+
import { z as z2 } from "zod";
|
|
43
|
+
var logger = createLogger("workflow-get-tool");
|
|
44
|
+
var WorkflowGetInputSchema = z2.object({
|
|
45
|
+
name: z2.string().optional().describe("Workflow name to get definition details"),
|
|
46
|
+
run_id: z2.string().optional().describe("Run/session ID to get run status")
|
|
47
|
+
});
|
|
48
|
+
function createWorkflowGetTool(workflowService) {
|
|
49
|
+
return {
|
|
50
|
+
name: "workflow_get",
|
|
51
|
+
description: "Get workflow definition details by name, or run status by run_id. Returns workflow name, version, description, inputs schema, and node list.",
|
|
52
|
+
parameters: WorkflowGetInputSchema,
|
|
53
|
+
execute: async (args, ctx) => {
|
|
54
|
+
const params = WorkflowGetInputSchema.parse(args);
|
|
55
|
+
try {
|
|
56
|
+
if (params.run_id) {
|
|
57
|
+
const session = await workflowService.getSession(params.run_id);
|
|
58
|
+
if (!session) {
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
output: "",
|
|
62
|
+
error: `Run not found: ${params.run_id}`,
|
|
63
|
+
metadata: { execution_time_ms: 0 }
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
let messages = [];
|
|
67
|
+
try {
|
|
68
|
+
messages = await workflowService.getSessionMessages(params.run_id);
|
|
69
|
+
} catch {}
|
|
70
|
+
return {
|
|
71
|
+
success: true,
|
|
72
|
+
output: JSON.stringify({
|
|
73
|
+
run_id: session.id,
|
|
74
|
+
status: session.metadata?.status,
|
|
75
|
+
workflow_name: session.metadata?.workflowName,
|
|
76
|
+
workflow_version: session.metadata?.workflowVersion,
|
|
77
|
+
input: session.metadata?.input,
|
|
78
|
+
created_at: session.createdAt,
|
|
79
|
+
updated_at: session.updatedAt,
|
|
80
|
+
message_count: messages.length
|
|
81
|
+
}, null, 2),
|
|
82
|
+
metadata: { execution_time_ms: 0 }
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (params.name) {
|
|
86
|
+
const workflow = workflowService.getWorkflowByName(params.name);
|
|
87
|
+
if (!workflow) {
|
|
88
|
+
return {
|
|
89
|
+
success: false,
|
|
90
|
+
output: "",
|
|
91
|
+
error: `Workflow not found: ${params.name}`,
|
|
92
|
+
metadata: { execution_time_ms: 0 }
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
success: true,
|
|
97
|
+
output: JSON.stringify({
|
|
98
|
+
name: workflow.name,
|
|
99
|
+
version: workflow.version,
|
|
100
|
+
description: workflow.description,
|
|
101
|
+
inputs: workflow.definition.inputs,
|
|
102
|
+
definition: workflow.definition,
|
|
103
|
+
config: workflow.definition.config,
|
|
104
|
+
tags: workflow.tags,
|
|
105
|
+
created_at: workflow.createdAt,
|
|
106
|
+
updated_at: workflow.updatedAt
|
|
107
|
+
}, null, 2),
|
|
108
|
+
metadata: { execution_time_ms: 0 }
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
success: false,
|
|
113
|
+
output: "",
|
|
114
|
+
error: "Either 'name' or 'run_id' must be provided",
|
|
115
|
+
metadata: { execution_time_ms: 0 }
|
|
116
|
+
};
|
|
117
|
+
} catch (error) {
|
|
118
|
+
logger.error("Failed to get workflow info", { error });
|
|
119
|
+
return {
|
|
120
|
+
success: false,
|
|
121
|
+
output: "",
|
|
122
|
+
error: error instanceof Error ? error.message : String(error),
|
|
123
|
+
metadata: { execution_time_ms: 0 }
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/env/workflow/tools/workflow-list-tool.ts
|
|
131
|
+
init_logger();
|
|
132
|
+
import { z as z3 } from "zod";
|
|
133
|
+
var logger2 = createLogger("workflow-list-tool");
|
|
134
|
+
var WorkflowListInputSchema = z3.object({
|
|
135
|
+
tag: z3.string().optional().describe("Filter by tag"),
|
|
136
|
+
search: z3.string().optional().describe("Search workflows by keyword"),
|
|
137
|
+
limit: z3.number().positive().optional().describe("Maximum number of results to return"),
|
|
138
|
+
offset: z3.number().min(0).optional().describe("Offset for pagination")
|
|
139
|
+
});
|
|
140
|
+
function createWorkflowListTool(workflowService) {
|
|
141
|
+
return {
|
|
142
|
+
name: "workflow_list",
|
|
143
|
+
description: "List all registered workflows with optional filtering by tag or keyword search. Returns workflow name, version, description, and tags.",
|
|
144
|
+
parameters: WorkflowListInputSchema,
|
|
145
|
+
execute: async (args, ctx) => {
|
|
146
|
+
const params = WorkflowListInputSchema.parse(args);
|
|
147
|
+
try {
|
|
148
|
+
const options = {};
|
|
149
|
+
if (params.tag !== undefined)
|
|
150
|
+
options.tag = params.tag;
|
|
151
|
+
if (params.search !== undefined)
|
|
152
|
+
options.search = params.search;
|
|
153
|
+
if (params.limit !== undefined)
|
|
154
|
+
options.limit = params.limit;
|
|
155
|
+
if (params.offset !== undefined)
|
|
156
|
+
options.offset = params.offset;
|
|
157
|
+
const workflows = workflowService.listWorkflows(options);
|
|
158
|
+
return {
|
|
159
|
+
success: true,
|
|
160
|
+
output: JSON.stringify({
|
|
161
|
+
workflows: workflows.map((w) => ({
|
|
162
|
+
name: w.name,
|
|
163
|
+
version: w.version,
|
|
164
|
+
description: w.description,
|
|
165
|
+
tags: w.tags,
|
|
166
|
+
created_at: w.createdAt
|
|
167
|
+
})),
|
|
168
|
+
total: workflows.length,
|
|
169
|
+
count: workflows.length,
|
|
170
|
+
limit: params.limit,
|
|
171
|
+
offset: params.offset
|
|
172
|
+
}, null, 2),
|
|
173
|
+
metadata: { execution_time_ms: 0 }
|
|
174
|
+
};
|
|
175
|
+
} catch (error) {
|
|
176
|
+
logger2.error("Failed to list workflows", { error });
|
|
177
|
+
return {
|
|
178
|
+
success: false,
|
|
179
|
+
output: "",
|
|
180
|
+
error: error instanceof Error ? error.message : String(error),
|
|
181
|
+
metadata: { execution_time_ms: 0 }
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/env/workflow/tools/run-workflow.ts
|
|
189
|
+
init_logger();
|
|
190
|
+
import { z as z4 } from "zod";
|
|
191
|
+
var logger3 = createLogger("run-workflow-tool");
|
|
192
|
+
var RunWorkflowInputSchema = z4.object({
|
|
193
|
+
workflow_name: z4.string().describe("Name of the workflow to run"),
|
|
194
|
+
input: z4.record(z4.any()).optional().describe("Input to pass to the workflow"),
|
|
195
|
+
sync: z4.boolean().default(true).describe("Wait for completion (default: true)"),
|
|
196
|
+
timeout: z4.number().positive().optional().describe("Timeout in milliseconds (default: 1800000 = 30 min)")
|
|
197
|
+
});
|
|
198
|
+
function createRunWorkflowTool(workflowService) {
|
|
199
|
+
return {
|
|
200
|
+
name: "workflow_run",
|
|
201
|
+
description: "Run a workflow by name with optional input. Returns run_id, status, output, error, and duration_ms. Default timeout: 30 minutes.",
|
|
202
|
+
parameters: RunWorkflowInputSchema,
|
|
203
|
+
sandbox: {
|
|
204
|
+
enabled: false
|
|
205
|
+
},
|
|
206
|
+
permission: {
|
|
207
|
+
level: "safe"
|
|
208
|
+
},
|
|
209
|
+
metadata: {
|
|
210
|
+
category: "workflow",
|
|
211
|
+
tags: ["workflow", "execute", "run"],
|
|
212
|
+
version: "1.0.0",
|
|
213
|
+
experimental: false
|
|
214
|
+
},
|
|
215
|
+
execute: async (args, ctx) => {
|
|
216
|
+
const startTime = Date.now();
|
|
217
|
+
const { workflow_name, input, sync = true, timeout = 1800000 } = args;
|
|
218
|
+
logger3.info(`Running workflow: ${workflow_name}`, { input, sync, timeout });
|
|
219
|
+
let timeoutHandle;
|
|
220
|
+
let durationMs;
|
|
221
|
+
try {
|
|
222
|
+
let result;
|
|
223
|
+
if (timeout) {
|
|
224
|
+
result = await Promise.race([
|
|
225
|
+
workflowService.runWorkflow(workflow_name, input, { sync }),
|
|
226
|
+
new Promise((_, reject) => {
|
|
227
|
+
timeoutHandle = setTimeout(() => {
|
|
228
|
+
reject(new Error("Workflow execution timed out"));
|
|
229
|
+
}, timeout);
|
|
230
|
+
})
|
|
231
|
+
]);
|
|
232
|
+
} else {
|
|
233
|
+
result = await workflowService.runWorkflow(workflow_name, input, { sync });
|
|
234
|
+
}
|
|
235
|
+
if (timeoutHandle) {
|
|
236
|
+
clearTimeout(timeoutHandle);
|
|
237
|
+
}
|
|
238
|
+
durationMs = Date.now() - startTime;
|
|
239
|
+
if (sync) {
|
|
240
|
+
return {
|
|
241
|
+
success: result.status === "completed",
|
|
242
|
+
output: {
|
|
243
|
+
run_id: result.runId,
|
|
244
|
+
status: result.status,
|
|
245
|
+
output: result.output,
|
|
246
|
+
error: result.error,
|
|
247
|
+
duration_ms: result.durationMs || durationMs
|
|
248
|
+
},
|
|
249
|
+
metadata: {
|
|
250
|
+
execution_time_ms: durationMs
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
} else {
|
|
254
|
+
return {
|
|
255
|
+
success: true,
|
|
256
|
+
output: {
|
|
257
|
+
run_id: result.runId,
|
|
258
|
+
status: result.status,
|
|
259
|
+
duration_ms: durationMs
|
|
260
|
+
},
|
|
261
|
+
metadata: {
|
|
262
|
+
execution_time_ms: durationMs
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (timeoutHandle) {
|
|
268
|
+
clearTimeout(timeoutHandle);
|
|
269
|
+
}
|
|
270
|
+
durationMs = Date.now() - startTime;
|
|
271
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
272
|
+
if (errorMessage.includes("Workflow not found")) {
|
|
273
|
+
return {
|
|
274
|
+
success: false,
|
|
275
|
+
output: "",
|
|
276
|
+
error: `Workflow not found: ${workflow_name}`,
|
|
277
|
+
metadata: {
|
|
278
|
+
execution_time_ms: durationMs
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
if (errorMessage.includes("abort") || errorMessage.includes("timed out")) {
|
|
283
|
+
return {
|
|
284
|
+
success: false,
|
|
285
|
+
output: "",
|
|
286
|
+
error: `Workflow execution timed out or was aborted: ${workflow_name}`,
|
|
287
|
+
metadata: {
|
|
288
|
+
execution_time_ms: durationMs
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
if (logger3?.error) {
|
|
293
|
+
logger3.error(`Failed to run workflow: ${workflow_name}`, { error: errorMessage });
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
success: false,
|
|
297
|
+
output: "",
|
|
298
|
+
error: `Failed to run workflow ${workflow_name}: ${errorMessage}`,
|
|
299
|
+
metadata: {
|
|
300
|
+
execution_time_ms: durationMs
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
var _runWorkflowTool = null;
|
|
308
|
+
var _workflowService = null;
|
|
309
|
+
function initRunWorkflowTool(workflowService) {
|
|
310
|
+
_workflowService = workflowService;
|
|
311
|
+
_runWorkflowTool = createRunWorkflowTool(workflowService);
|
|
312
|
+
}
|
|
313
|
+
function getRunWorkflowTool() {
|
|
314
|
+
if (!_runWorkflowTool || !_workflowService) {
|
|
315
|
+
throw new Error("workflow_run tool not initialized. Call initRunWorkflowTool(workflowService) first.");
|
|
316
|
+
}
|
|
317
|
+
return _runWorkflowTool;
|
|
318
|
+
}
|
|
319
|
+
function resetRunWorkflowTool() {
|
|
320
|
+
_runWorkflowTool = null;
|
|
321
|
+
_workflowService = null;
|
|
322
|
+
}
|
|
323
|
+
function createLegacyRunWorkflowTool(workflowService) {
|
|
324
|
+
const tool = createRunWorkflowTool(workflowService);
|
|
325
|
+
return {
|
|
326
|
+
...tool,
|
|
327
|
+
name: "run-workflow"
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/env/workflow/tools/workflow-run-status-tool.ts
|
|
332
|
+
init_logger();
|
|
333
|
+
import { z as z5 } from "zod";
|
|
334
|
+
var logger4 = createLogger("workflow-run-status-tool");
|
|
335
|
+
var WorkflowRunStatusInputSchema = z5.object({
|
|
336
|
+
run_id: z5.string().describe("Run/session ID to query status")
|
|
337
|
+
});
|
|
338
|
+
function createWorkflowRunStatusTool(workflowService) {
|
|
339
|
+
return {
|
|
340
|
+
name: "workflow_run_status",
|
|
341
|
+
description: "Query the status of a workflow run by run_id. Returns run_id, status, output, error, and progress information.",
|
|
342
|
+
parameters: WorkflowRunStatusInputSchema,
|
|
343
|
+
execute: async (args, ctx) => {
|
|
344
|
+
const params = WorkflowRunStatusInputSchema.parse(args);
|
|
345
|
+
try {
|
|
346
|
+
const session = await workflowService.getSession(params.run_id);
|
|
347
|
+
if (!session) {
|
|
348
|
+
return {
|
|
349
|
+
success: false,
|
|
350
|
+
output: "",
|
|
351
|
+
error: `Run not found: ${params.run_id}`,
|
|
352
|
+
metadata: { execution_time_ms: 0 }
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
const metadata = session.metadata;
|
|
356
|
+
let messages = [];
|
|
357
|
+
try {
|
|
358
|
+
messages = await workflowService.getSessionMessages(params.run_id);
|
|
359
|
+
} catch {}
|
|
360
|
+
return {
|
|
361
|
+
success: true,
|
|
362
|
+
output: JSON.stringify({
|
|
363
|
+
run_id: session.id,
|
|
364
|
+
title: session.title,
|
|
365
|
+
status: metadata?.status || "unknown",
|
|
366
|
+
workflow_name: metadata?.workflowName,
|
|
367
|
+
workflow_version: metadata?.workflowVersion,
|
|
368
|
+
input: metadata?.input,
|
|
369
|
+
created_at: session.createdAt,
|
|
370
|
+
updated_at: session.updatedAt,
|
|
371
|
+
message_count: messages.length
|
|
372
|
+
}, null, 2),
|
|
373
|
+
metadata: { execution_time_ms: 0 }
|
|
374
|
+
};
|
|
375
|
+
} catch (error) {
|
|
376
|
+
logger4.error("Failed to get run status", { error });
|
|
377
|
+
return {
|
|
378
|
+
success: false,
|
|
379
|
+
output: "",
|
|
380
|
+
error: error instanceof Error ? error.message : String(error),
|
|
381
|
+
metadata: { execution_time_ms: 0 }
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/env/workflow/tools/workflow-run-stop-tool.ts
|
|
389
|
+
init_logger();
|
|
390
|
+
import { z as z6 } from "zod";
|
|
391
|
+
var logger5 = createLogger("workflow-run-stop-tool");
|
|
392
|
+
var WorkflowRunStopInputSchema = z6.object({
|
|
393
|
+
run_id: z6.string().describe("Run/session ID to stop"),
|
|
394
|
+
reason: z6.string().optional().describe("Optional reason for stopping the workflow")
|
|
395
|
+
});
|
|
396
|
+
function createWorkflowRunStopTool(workflowService) {
|
|
397
|
+
return {
|
|
398
|
+
name: "workflow_run_stop",
|
|
399
|
+
description: "Stop a running workflow by run_id. Optionally provide a reason. Returns success status.",
|
|
400
|
+
parameters: WorkflowRunStopInputSchema,
|
|
401
|
+
execute: async (args, ctx) => {
|
|
402
|
+
const params = WorkflowRunStopInputSchema.parse(args);
|
|
403
|
+
try {
|
|
404
|
+
await workflowService.stopRun(params.run_id, params.reason);
|
|
405
|
+
return {
|
|
406
|
+
success: true,
|
|
407
|
+
output: JSON.stringify({
|
|
408
|
+
success: true,
|
|
409
|
+
run_id: params.run_id,
|
|
410
|
+
status: "stopped",
|
|
411
|
+
reason: params.reason || undefined
|
|
412
|
+
}, null, 2),
|
|
413
|
+
metadata: { execution_time_ms: 0 }
|
|
414
|
+
};
|
|
415
|
+
} catch (error) {
|
|
416
|
+
logger5.error("Failed to stop workflow run", { error });
|
|
417
|
+
return {
|
|
418
|
+
success: false,
|
|
419
|
+
output: "",
|
|
420
|
+
error: error instanceof Error ? error.message : String(error),
|
|
421
|
+
metadata: { execution_time_ms: 0 }
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export { AskUserInputSchema, askUserTool, askUserToolInstance, WorkflowGetInputSchema, createWorkflowGetTool, WorkflowListInputSchema, createWorkflowListTool, RunWorkflowInputSchema, createRunWorkflowTool, initRunWorkflowTool, getRunWorkflowTool, resetRunWorkflowTool, createLegacyRunWorkflowTool, WorkflowRunStatusInputSchema, createWorkflowRunStatusTool, WorkflowRunStopInputSchema, createWorkflowRunStopTool };
|
|
@@ -143,8 +143,12 @@ function createTaskTool(taskComponent) {
|
|
|
143
143
|
then create the child task with that parent_task_id.
|
|
144
144
|
|
|
145
145
|
**Example:**
|
|
146
|
-
- First: task_list(depth=0) → find root task
|
|
147
|
-
|
|
146
|
+
- First: task_list(depth=0) → find an appropriate root task for your project
|
|
147
|
+
(e.g. one whose title matches your project name). Use the returned root task's
|
|
148
|
+
id as \`parent_task_id\` — do NOT hardcode a specific id; the root task id varies
|
|
149
|
+
across deployments and resets.
|
|
150
|
+
- Then: task_create(title="New feature", parent_task_id=<root_task_id>, ...)
|
|
151
|
+
where \`<root_task_id>\` is the id returned by task_list, NOT a hardcoded number.
|
|
148
152
|
`,
|
|
149
153
|
parameters: CreateTaskToolSchema,
|
|
150
154
|
execute: async (args, ctx) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_SUBAGENT_PROMPT
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-mbre4fxg.js";
|
|
4
4
|
import {
|
|
5
5
|
TaskHookPoints
|
|
6
6
|
} from "./roy-agent-core-92z6t4he.js";
|
|
@@ -211,6 +211,32 @@ var DelegateToolParameters = z.object({
|
|
|
211
211
|
reason: z.string().describe("Brief reason for calling this tool (max 30 chars, e.g., 'Delegate refactor task')").optional(),
|
|
212
212
|
similar_task_ids: z.array(z.number()).max(3).describe("Similar task IDs (max 3) to reference for improving task execution. Search for similar tasks before calling this tool.")
|
|
213
213
|
});
|
|
214
|
+
function buildEntryAgentPrompt(options) {
|
|
215
|
+
const { workflowName, originalPrompt, description } = options;
|
|
216
|
+
return `# Workflow 调度请求
|
|
217
|
+
|
|
218
|
+
你被调用是因为上游 \`delegate_task\` 检测到 workflow 类型 subagent **${workflowName}**。
|
|
219
|
+
请通过 \`workflow run\` 命令调度对应 workflow。
|
|
220
|
+
|
|
221
|
+
## 调度目标
|
|
222
|
+
|
|
223
|
+
- **Workflow 名称**: \`${workflowName}\`
|
|
224
|
+
- **任务描述**: ${description}
|
|
225
|
+
|
|
226
|
+
## 原始用户请求
|
|
227
|
+
|
|
228
|
+
${originalPrompt}
|
|
229
|
+
|
|
230
|
+
## 你的行动
|
|
231
|
+
|
|
232
|
+
1. \`workflow get ${workflowName}\` 查 workflow 入参 schema
|
|
233
|
+
2. 从"原始用户请求"提取符合 schema 的 input 字段
|
|
234
|
+
3. \`workflow run ${workflowName} --input '<json>'\` 触发 workflow
|
|
235
|
+
4. 返回结果
|
|
236
|
+
|
|
237
|
+
不要做其他工作。只走 \`workflow run\` 路径。
|
|
238
|
+
`;
|
|
239
|
+
}
|
|
214
240
|
var DEFAULT_TIMEOUT = 1800000;
|
|
215
241
|
var PROGRESS_INTERVAL = 120000;
|
|
216
242
|
|
|
@@ -222,6 +248,21 @@ class BackgroundTaskManager {
|
|
|
222
248
|
constructor(env) {
|
|
223
249
|
this.env = env;
|
|
224
250
|
}
|
|
251
|
+
static DEFAULT_WORKFLOW_ENTRY_AGENT = "workflow-agent";
|
|
252
|
+
resolveEntryAgent(subagentType) {
|
|
253
|
+
try {
|
|
254
|
+
const agentComponent = this.env?.getComponent?.("agent");
|
|
255
|
+
const registry = agentComponent?.getRegistry?.();
|
|
256
|
+
const agent = registry?.get?.(subagentType);
|
|
257
|
+
if (!agent || agent.type !== "workflow") {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
return agent.entryAgent ?? BackgroundTaskManager.DEFAULT_WORKFLOW_ENTRY_AGENT;
|
|
261
|
+
} catch (err) {
|
|
262
|
+
logger.warn(`[BackgroundTaskManager] resolveEntryAgent failed for ${subagentType}: ${err}`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
225
266
|
getSessionComponent() {
|
|
226
267
|
return this.env?.getComponent?.("session");
|
|
227
268
|
}
|
|
@@ -614,6 +655,9 @@ Use these as guidance to improve task execution efficiency.`;
|
|
|
614
655
|
logger.info(`[BackgroundTaskManager] Disposed`);
|
|
615
656
|
}
|
|
616
657
|
}
|
|
658
|
+
__legacyDecorateClassTS([
|
|
659
|
+
TracedAs("task.background.resolveEntryAgent", { recordParams: true, recordResult: true })
|
|
660
|
+
], BackgroundTaskManager.prototype, "resolveEntryAgent", null);
|
|
617
661
|
__legacyDecorateClassTS([
|
|
618
662
|
TracedAs("task.background.createTask", { recordParams: false, recordResult: true, log: true })
|
|
619
663
|
], BackgroundTaskManager.prototype, "createTask", null);
|
|
@@ -716,20 +760,35 @@ No need to poll — just wait for the notification and use \`task_get\` with the
|
|
|
716
760
|
async function handleBackgroundTask(backgroundTaskManager, parentSessionId, description, prompt, subagentType, timeout, similarTaskIds) {
|
|
717
761
|
const startTime = Date.now();
|
|
718
762
|
try {
|
|
763
|
+
let actualSubagentType = subagentType;
|
|
764
|
+
let actualPrompt = prompt;
|
|
765
|
+
let originalWorkflowName;
|
|
766
|
+
const entryAgent = backgroundTaskManager.resolveEntryAgent(subagentType);
|
|
767
|
+
if (entryAgent) {
|
|
768
|
+
originalWorkflowName = subagentType;
|
|
769
|
+
actualSubagentType = entryAgent;
|
|
770
|
+
actualPrompt = buildEntryAgentPrompt({
|
|
771
|
+
workflowName: originalWorkflowName,
|
|
772
|
+
originalPrompt: prompt,
|
|
773
|
+
description
|
|
774
|
+
});
|
|
775
|
+
logger.info(`[delegate_task] Routing workflow subagent '${subagentType}' → entry-agent '${entryAgent}'`);
|
|
776
|
+
}
|
|
719
777
|
const { taskId: bgProcessId, subSessionId } = await backgroundTaskManager.createTask({
|
|
720
778
|
parentSessionId,
|
|
721
779
|
description,
|
|
722
|
-
prompt,
|
|
723
|
-
subagentType,
|
|
780
|
+
prompt: actualPrompt,
|
|
781
|
+
subagentType: actualSubagentType,
|
|
724
782
|
timeout,
|
|
725
|
-
similarTaskIds
|
|
783
|
+
similarTaskIds,
|
|
784
|
+
originalWorkflowName
|
|
726
785
|
});
|
|
727
786
|
const output = [
|
|
728
787
|
`✅ Background task accepted`,
|
|
729
788
|
"",
|
|
730
789
|
`\uD83D\uDCCB Process ID: ${bgProcessId}`,
|
|
731
790
|
`\uD83D\uDCDD Description: ${description}`,
|
|
732
|
-
`\uD83E\uDD16 Sub-agent: ${
|
|
791
|
+
`\uD83E\uDD16 Sub-agent: ${actualSubagentType}${originalWorkflowName ? ` (workflow: ${originalWorkflowName})` : ""}`,
|
|
733
792
|
`⏱️ Timeout: ${(timeout || DEFAULT_TIMEOUT) / 1000}s`,
|
|
734
793
|
"",
|
|
735
794
|
`Use stop_task with task_id="${bgProcessId}" to cancel this task.`
|
|
@@ -105,6 +105,8 @@ var init_template_resolver = __esm(() => {
|
|
|
105
105
|
return template;
|
|
106
106
|
}
|
|
107
107
|
let resolved = template;
|
|
108
|
+
resolved = resolved.replace(/\{\{\s+/g, "{{");
|
|
109
|
+
resolved = resolved.replace(/\s+\}\}/g, "}}");
|
|
108
110
|
resolved = resolved.replace(/\{\{inputs\./g, "{{input.");
|
|
109
111
|
resolved = resolved.replace(/\{\{input\.([^}]+)\}\}/g, (match, path) => {
|
|
110
112
|
const value = this.getNestedValue(this.input, path);
|
|
@@ -64,6 +64,19 @@ var init_tool_node = __esm(() => {
|
|
|
64
64
|
} else {
|
|
65
65
|
input = {};
|
|
66
66
|
}
|
|
67
|
+
if (toolName === "bash" && typeof input.command === "string") {
|
|
68
|
+
const trimmed = input.command.replace(/\n+$/, "");
|
|
69
|
+
const echoMatch = trimmed.match(/^echo\s+"([\s\S]*)"\s*$/);
|
|
70
|
+
if (echoMatch) {
|
|
71
|
+
let inner = echoMatch[1];
|
|
72
|
+
inner = inner.replace(/\\/g, "\\\\");
|
|
73
|
+
inner = inner.replace(/"/g, "\\\"");
|
|
74
|
+
inner = inner.replace(/\$/g, "\\$");
|
|
75
|
+
inner = inner.replace(/\`/g, "\\`");
|
|
76
|
+
inner = inner.replace(/\n/g, "\\n");
|
|
77
|
+
input.command = 'echo "' + inner + '"';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
67
80
|
let output;
|
|
68
81
|
try {
|
|
69
82
|
const toolContext = {
|
|
@@ -26,6 +26,7 @@ var AgentConfigSchema = z.object({
|
|
|
26
26
|
name: z.string(),
|
|
27
27
|
type: z.enum(["primary", "sub", "workflow"]),
|
|
28
28
|
workflow: z.string().optional(),
|
|
29
|
+
entryAgent: z.string().optional(),
|
|
29
30
|
description: z.string().optional(),
|
|
30
31
|
systemPromptRef: z.string().optional(),
|
|
31
32
|
systemPrompt: z.string().optional(),
|
|
@@ -150,6 +151,32 @@ class AgentRegistry {
|
|
|
150
151
|
}
|
|
151
152
|
return agent.workflow;
|
|
152
153
|
}
|
|
154
|
+
getEntryAgent(name) {
|
|
155
|
+
const agent = this.agents.get(name);
|
|
156
|
+
if (!agent || agent.type !== "workflow") {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
return agent.entryAgent;
|
|
160
|
+
}
|
|
161
|
+
registerWorkflowAgent() {
|
|
162
|
+
const name = "workflow-agent";
|
|
163
|
+
if (this.agents.has(name))
|
|
164
|
+
return;
|
|
165
|
+
const agent = {
|
|
166
|
+
name,
|
|
167
|
+
type: "primary",
|
|
168
|
+
description: "Workflow 调度中介 — 负责将请求转交给 workflow run 执行",
|
|
169
|
+
allowedTools: [
|
|
170
|
+
"workflow_get",
|
|
171
|
+
"workflow_list",
|
|
172
|
+
"workflow_run",
|
|
173
|
+
"workflow_run_status",
|
|
174
|
+
"workflow_run_stop"
|
|
175
|
+
],
|
|
176
|
+
deniedTools: []
|
|
177
|
+
};
|
|
178
|
+
this.agents.set(name, agent);
|
|
179
|
+
}
|
|
153
180
|
async load() {
|
|
154
181
|
try {
|
|
155
182
|
return await this.loadFromDirectory(this.configDir);
|
|
@@ -249,7 +276,8 @@ class AgentRegistry {
|
|
|
249
276
|
...agent.toolRetries !== undefined ? { toolRetries: agent.toolRetries } : {},
|
|
250
277
|
...agent.doomLoopThreshold !== undefined ? { doomLoopThreshold: agent.doomLoopThreshold } : {},
|
|
251
278
|
...agent.filterHistory !== undefined ? { filterHistory: agent.filterHistory } : {},
|
|
252
|
-
...agent.workflow !== undefined ? { workflow: agent.workflow } : {}
|
|
279
|
+
...agent.workflow !== undefined ? { workflow: agent.workflow } : {},
|
|
280
|
+
...agent.entryAgent !== undefined ? { entryAgent: agent.entryAgent } : {}
|
|
253
281
|
};
|
|
254
282
|
return yaml.stringify(config).trimEnd() + `
|
|
255
283
|
`;
|
|
@@ -308,6 +336,9 @@ __legacyDecorateClassTS([
|
|
|
308
336
|
__legacyDecorateClassTS([
|
|
309
337
|
TracedAs("agent.registry.getWorkflowName", { recordParams: true, recordResult: true })
|
|
310
338
|
], AgentRegistry.prototype, "getWorkflowName", null);
|
|
339
|
+
__legacyDecorateClassTS([
|
|
340
|
+
TracedAs("agent.registry.getEntryAgent", { recordParams: true, recordResult: true })
|
|
341
|
+
], AgentRegistry.prototype, "getEntryAgent", null);
|
|
311
342
|
__legacyDecorateClassTS([
|
|
312
343
|
TracedAs("agent.registry.load", { recordParams: false, recordResult: true, log: true })
|
|
313
344
|
], AgentRegistry.prototype, "load", null);
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
BackgroundTaskManager,
|
|
6
6
|
createDelegateTool,
|
|
7
7
|
createStopTool
|
|
8
|
-
} from "./roy-agent-core-
|
|
8
|
+
} from "./roy-agent-core-f6p7wwpd.js";
|
|
9
9
|
import {
|
|
10
10
|
SQLiteTaskStore,
|
|
11
11
|
getDefaultTaskDbPath
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
listTasksTool,
|
|
21
21
|
searchTasksTool,
|
|
22
22
|
updateTaskTool
|
|
23
|
-
} from "./roy-agent-core-
|
|
23
|
+
} from "./roy-agent-core-df3ng0pz.js";
|
|
24
24
|
import {
|
|
25
25
|
createOperationTool,
|
|
26
26
|
deleteOperationTool,
|