@ai-setting/roy-agent-core 1.5.81 → 1.5.84

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.
Files changed (34) hide show
  1. package/dist/env/agent/index.js +1 -1
  2. package/dist/env/event-source/index.js +2 -2
  3. package/dist/env/index.js +11 -10
  4. package/dist/env/prompt/index.js +1 -1
  5. package/dist/env/task/index.js +3 -3
  6. package/dist/env/task/plugins/index.js +1 -1
  7. package/dist/env/task/storage/index.js +1 -1
  8. package/dist/env/task/tools/index.js +1 -1
  9. package/dist/env/workflow/index.js +4 -3
  10. package/dist/env/workflow/service/index.js +8 -2
  11. package/dist/env/workflow/storage/index.js +11 -6
  12. package/dist/env/workflow/tools/index.js +15 -1
  13. package/dist/index.js +14 -12
  14. package/dist/shared/@ai-setting/{roy-agent-core-qbgd7bp6.js → roy-agent-core-015vw11k.js} +27 -1
  15. package/dist/shared/@ai-setting/{roy-agent-core-t2q0rwt7.js → roy-agent-core-29fh9mxg.js} +4 -7
  16. package/dist/shared/@ai-setting/roy-agent-core-3sv590cv.js +132 -0
  17. package/dist/shared/@ai-setting/{roy-agent-core-w83v54mj.js → roy-agent-core-7fdzfsm6.js} +42 -135
  18. package/dist/shared/@ai-setting/{roy-agent-core-df3ng0pz.js → roy-agent-core-7nh5h9fn.js} +31 -2
  19. package/dist/shared/@ai-setting/{roy-agent-core-am646wfz.js → roy-agent-core-86d4exyf.js} +5 -2
  20. package/dist/shared/@ai-setting/{roy-agent-core-vgyj2rq9.js → roy-agent-core-akepggsr.js} +150 -6
  21. package/dist/shared/@ai-setting/{roy-agent-core-v3t28k5n.js → roy-agent-core-bt7wezvg.js} +19 -10
  22. package/dist/shared/@ai-setting/roy-agent-core-c67wr8sp.js +11 -0
  23. package/dist/shared/@ai-setting/{roy-agent-core-496zzm5a.js → roy-agent-core-h4h55x4h.js} +183 -3
  24. package/dist/shared/@ai-setting/roy-agent-core-hhrg314p.js +34 -0
  25. package/dist/shared/@ai-setting/{roy-agent-core-r9y8ct0w.js → roy-agent-core-pcdzfwdv.js} +4 -0
  26. package/dist/shared/@ai-setting/{roy-agent-core-p8jv13bm.js → roy-agent-core-qjv8537d.js} +2 -2
  27. package/dist/shared/@ai-setting/roy-agent-core-r5axf0ad.js +751 -0
  28. package/dist/shared/@ai-setting/{roy-agent-core-74cp3zp1.js → roy-agent-core-taxvytzz.js} +4 -1
  29. package/dist/shared/@ai-setting/roy-agent-core-tq9528d3.js +336 -0
  30. package/dist/shared/@ai-setting/{roy-agent-core-j8q8119y.js → roy-agent-core-ya1ayt1k.js} +1 -1
  31. package/package.json +1 -1
  32. package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
  33. package/dist/shared/@ai-setting/roy-agent-core-6b57g1zk.js +0 -103
  34. package/dist/shared/@ai-setting/roy-agent-core-a6j7g1qe.js +0 -428
@@ -1,428 +0,0 @@
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 };