@ai-setting/roy-agent-core 1.5.83 → 1.5.85

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 (40) hide show
  1. package/dist/env/agent/index.js +2 -2
  2. package/dist/env/event-source/index.js +2 -2
  3. package/dist/env/index.js +14 -14
  4. package/dist/env/prompt/index.js +1 -1
  5. package/dist/env/task/delegate/index.js +2 -2
  6. package/dist/env/task/index.js +3 -3
  7. package/dist/env/task/plugins/index.js +1 -1
  8. package/dist/env/workflow/engine/index.js +3 -4
  9. package/dist/env/workflow/index.js +7 -7
  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 +16 -2
  13. package/dist/index.js +17 -16
  14. package/dist/shared/@ai-setting/{roy-agent-core-f6p7wwpd.js → roy-agent-core-0kt57b72.js} +1 -6
  15. package/dist/shared/@ai-setting/{roy-agent-core-whw7jap0.js → roy-agent-core-1db4vpc6.js} +3 -2
  16. package/dist/shared/@ai-setting/{roy-agent-core-68sef3es.js → roy-agent-core-29fh9mxg.js} +1 -1
  17. package/dist/shared/@ai-setting/roy-agent-core-3sv590cv.js +132 -0
  18. package/dist/shared/@ai-setting/{roy-agent-core-m4qjnhz6.js → roy-agent-core-5kdw0p98.js} +114 -68
  19. package/dist/shared/@ai-setting/{roy-agent-core-78yzt2bq.js → roy-agent-core-7fdzfsm6.js} +2 -2
  20. package/dist/shared/@ai-setting/{roy-agent-core-mbre4fxg.js → roy-agent-core-7z4xtrmw.js} +16 -0
  21. package/dist/shared/@ai-setting/{roy-agent-core-am646wfz.js → roy-agent-core-86d4exyf.js} +5 -2
  22. package/dist/shared/@ai-setting/roy-agent-core-c67wr8sp.js +11 -0
  23. package/dist/shared/@ai-setting/{roy-agent-core-v3t28k5n.js → roy-agent-core-dp73ghtz.js} +24 -26
  24. package/dist/shared/@ai-setting/{roy-agent-core-qjv8537d.js → roy-agent-core-dv12wpdv.js} +1 -1
  25. package/dist/shared/@ai-setting/{roy-agent-core-6b0r2e7j.js → roy-agent-core-gttz2jpm.js} +15 -52
  26. package/dist/shared/@ai-setting/{roy-agent-core-496zzm5a.js → roy-agent-core-h4h55x4h.js} +183 -3
  27. package/dist/shared/@ai-setting/roy-agent-core-hhrg314p.js +34 -0
  28. package/dist/shared/@ai-setting/{roy-agent-core-vcvgq9hy.js → roy-agent-core-mmkyydw7.js} +128 -6
  29. package/dist/shared/@ai-setting/roy-agent-core-r5axf0ad.js +751 -0
  30. package/dist/shared/@ai-setting/{roy-agent-core-74cp3zp1.js → roy-agent-core-taxvytzz.js} +4 -1
  31. package/dist/shared/@ai-setting/roy-agent-core-tq9528d3.js +336 -0
  32. package/dist/shared/@ai-setting/{roy-agent-core-nc0n0bdc.js → roy-agent-core-xckhrs2p.js} +2 -3
  33. package/dist/shared/@ai-setting/{roy-agent-core-67yzhmg2.js → roy-agent-core-ya1ayt1k.js} +1 -1
  34. package/dist/shared/@ai-setting/{roy-agent-core-015vw11k.js → roy-agent-core-yx0vw1aw.js} +8 -6
  35. package/package.json +1 -1
  36. package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
  37. package/dist/shared/@ai-setting/roy-agent-core-6b57g1zk.js +0 -103
  38. package/dist/shared/@ai-setting/roy-agent-core-7z8fzxck.js +0 -265
  39. package/dist/shared/@ai-setting/roy-agent-core-a6j7g1qe.js +0 -428
  40. package/dist/shared/@ai-setting/roy-agent-core-qf9gvx02.js +0 -39
@@ -0,0 +1,751 @@
1
+ import {
2
+ TAG_MAX_COUNT,
3
+ TAG_MIN_COUNT
4
+ } from "./roy-agent-core-tq9528d3.js";
5
+ import {
6
+ AskUserError,
7
+ init_workflow_hil
8
+ } from "./roy-agent-core-e25xkv53.js";
9
+ import {
10
+ TracedAs,
11
+ init_decorator
12
+ } from "./roy-agent-core-k05v31rc.js";
13
+ import {
14
+ createLogger,
15
+ init_logger
16
+ } from "./roy-agent-core-shme7set.js";
17
+ import {
18
+ __legacyDecorateClassTS
19
+ } from "./roy-agent-core-fs0mn2jk.js";
20
+
21
+ // src/env/workflow/tools/ask-user-tool.ts
22
+ init_workflow_hil();
23
+ import { z } from "zod";
24
+ var AskUserInputSchema = z.object({
25
+ query: z.string().describe("The question or request to ask the user"),
26
+ options: z.array(z.string()).optional().describe("Optional choices for the user"),
27
+ required_confirm: z.boolean().optional().describe("If true, user must explicitly confirm")
28
+ });
29
+ var askUserTool = {
30
+ name: "ask_user",
31
+ description: "Ask user for input or confirmation. Use this tool when you need user input or validation to continue the workflow.",
32
+ parameters: AskUserInputSchema,
33
+ async execute(args, context) {
34
+ const runId = context.metadata?.runId || "unknown";
35
+ const sessionId = context.metadata?.sessionId || `workflow_${runId}`;
36
+ const nodeId = context.metadata?.nodeId || "unknown";
37
+ let fullQuery = args.query;
38
+ if (args.options && args.options.length > 0) {
39
+ fullQuery = `${args.query} (选项: ${args.options.join(", ")})`;
40
+ }
41
+ throw new AskUserError(runId, sessionId, nodeId, "agent", fullQuery);
42
+ },
43
+ metadata: {
44
+ category: "workflow",
45
+ tags: ["human-in-loop", "user-input"],
46
+ version: "1.0.0"
47
+ }
48
+ };
49
+ var askUserToolInstance = askUserTool;
50
+
51
+ // src/env/workflow/tools/workflow-get-tool.ts
52
+ init_logger();
53
+ import { z as z2 } from "zod";
54
+ var logger = createLogger("workflow-get-tool");
55
+ var WorkflowGetInputSchema = z2.object({
56
+ name: z2.string().optional().describe("Workflow name to get definition details"),
57
+ run_id: z2.string().optional().describe("Run/session ID to get run status")
58
+ });
59
+ function createWorkflowGetTool(workflowService) {
60
+ return {
61
+ name: "workflow_get",
62
+ description: "Get workflow definition details by name, or run status by run_id. Returns workflow name, version, description, inputs schema, and node list.",
63
+ parameters: WorkflowGetInputSchema,
64
+ execute: async (args, ctx) => {
65
+ const params = WorkflowGetInputSchema.parse(args);
66
+ try {
67
+ if (params.run_id) {
68
+ const session = await workflowService.getSession(params.run_id);
69
+ if (!session) {
70
+ return {
71
+ success: false,
72
+ output: "",
73
+ error: `Run not found: ${params.run_id}`,
74
+ metadata: { execution_time_ms: 0 }
75
+ };
76
+ }
77
+ let messages = [];
78
+ try {
79
+ messages = await workflowService.getSessionMessages(params.run_id);
80
+ } catch {}
81
+ return {
82
+ success: true,
83
+ output: JSON.stringify({
84
+ run_id: session.id,
85
+ status: session.metadata?.status,
86
+ workflow_name: session.metadata?.workflowName,
87
+ workflow_version: session.metadata?.workflowVersion,
88
+ input: session.metadata?.input,
89
+ created_at: session.createdAt,
90
+ updated_at: session.updatedAt,
91
+ message_count: messages.length
92
+ }, null, 2),
93
+ metadata: { execution_time_ms: 0 }
94
+ };
95
+ }
96
+ if (params.name) {
97
+ const workflow = workflowService.getWorkflowByName(params.name);
98
+ if (!workflow) {
99
+ return {
100
+ success: false,
101
+ output: "",
102
+ error: `Workflow not found: ${params.name}`,
103
+ metadata: { execution_time_ms: 0 }
104
+ };
105
+ }
106
+ return {
107
+ success: true,
108
+ output: JSON.stringify({
109
+ name: workflow.name,
110
+ version: workflow.version,
111
+ description: workflow.description,
112
+ inputs: workflow.definition.inputs,
113
+ definition: workflow.definition,
114
+ config: workflow.definition.config,
115
+ tags: workflow.tags,
116
+ created_at: workflow.createdAt,
117
+ updated_at: workflow.updatedAt
118
+ }, null, 2),
119
+ metadata: { execution_time_ms: 0 }
120
+ };
121
+ }
122
+ return {
123
+ success: false,
124
+ output: "",
125
+ error: "Either 'name' or 'run_id' must be provided",
126
+ metadata: { execution_time_ms: 0 }
127
+ };
128
+ } catch (error) {
129
+ logger.error("Failed to get workflow info", { error });
130
+ return {
131
+ success: false,
132
+ output: "",
133
+ error: error instanceof Error ? error.message : String(error),
134
+ metadata: { execution_time_ms: 0 }
135
+ };
136
+ }
137
+ }
138
+ };
139
+ }
140
+
141
+ // src/env/workflow/tools/workflow-list-tool.ts
142
+ init_logger();
143
+ import { z as z3 } from "zod";
144
+ var logger2 = createLogger("workflow-list-tool");
145
+ var WorkflowListInputSchema = z3.object({
146
+ tag: z3.string().optional().describe("Filter by single tag (legacy single-tag filter)"),
147
+ tags: z3.array(z3.string()).optional().describe("Filter by multiple tags (AND)"),
148
+ search: z3.string().optional().describe("Search workflows by keyword"),
149
+ limit: z3.number().positive().optional().describe("Maximum number of results to return"),
150
+ offset: z3.number().min(0).optional().describe("Offset for pagination")
151
+ });
152
+ function createWorkflowListTool(workflowService) {
153
+ return {
154
+ name: "workflow_list",
155
+ description: "List all registered workflows with optional filtering. " + "Returns `workflows`, `total` (filtered count regardless of pagination), `count` (returned count), " + "`limit`, `offset`, and `available_tags` (sorted by usage_count DESC). " + "Multi-tag filter uses AND logic. " + "\uD83D\uDCA1 TIP: The `available_tags` field tells you what tags already exist. " + "Before calling `workflow_add` with new tags, call `workflow_tag_list` to discover " + "existing tags and prefer reusing them for semantic consistency " + "(e.g. reuse 'ci-cd' rather than creating 'continuous-integration'). " + "Avoid tag proliferation is a design goal — limit the number of distinct tags in the pool.",
156
+ parameters: WorkflowListInputSchema,
157
+ execute: async (args, ctx) => {
158
+ const params = WorkflowListInputSchema.parse(args);
159
+ try {
160
+ const options = {};
161
+ if (params.tag !== undefined)
162
+ options.tag = params.tag;
163
+ if (params.search !== undefined)
164
+ options.search = params.search;
165
+ if (params.limit !== undefined)
166
+ options.limit = params.limit;
167
+ if (params.offset !== undefined)
168
+ options.offset = params.offset;
169
+ if (params.tags && params.tags.length > 0) {
170
+ const result2 = await workflowService.searchWorkflowsWithTags ? await workflowService.searchWorkflowsWithTags({
171
+ tags: params.tags,
172
+ limit: params.limit,
173
+ offset: params.offset
174
+ }) : { workflows: workflowService.searchWorkflows({ tags: params.tags, limit: params.limit, offset: params.offset }), available_tags: [], total: 0 };
175
+ return {
176
+ success: true,
177
+ output: JSON.stringify({
178
+ workflows: result2.workflows.map((w) => ({
179
+ name: w.name,
180
+ version: w.version,
181
+ description: w.description,
182
+ tags: w.tags,
183
+ created_at: w.createdAt
184
+ })),
185
+ available_tags: result2.available_tags,
186
+ total: result2.total,
187
+ count: result2.workflows.length,
188
+ limit: params.limit,
189
+ offset: params.offset
190
+ }, null, 2),
191
+ metadata: { execution_time_ms: 0 }
192
+ };
193
+ }
194
+ const result = workflowService.listWorkflowsWithTags ? await workflowService.listWorkflowsWithTags(options) : {
195
+ workflows: workflowService.listWorkflows(options),
196
+ available_tags: [],
197
+ total: 0
198
+ };
199
+ return {
200
+ success: true,
201
+ output: JSON.stringify({
202
+ workflows: result.workflows.map((w) => ({
203
+ name: w.name,
204
+ version: w.version,
205
+ description: w.description,
206
+ tags: w.tags,
207
+ created_at: w.createdAt
208
+ })),
209
+ available_tags: result.available_tags,
210
+ total: result.total,
211
+ count: result.workflows.length,
212
+ limit: params.limit,
213
+ offset: params.offset
214
+ }, null, 2),
215
+ metadata: { execution_time_ms: 0 }
216
+ };
217
+ } catch (error) {
218
+ logger2.error("Failed to list workflows", { error });
219
+ return {
220
+ success: false,
221
+ output: "",
222
+ error: error instanceof Error ? error.message : String(error),
223
+ metadata: { execution_time_ms: 0 }
224
+ };
225
+ }
226
+ }
227
+ };
228
+ }
229
+
230
+ // src/env/workflow/tools/workflow-tag-list-tool.ts
231
+ init_logger();
232
+ init_decorator();
233
+ import { z as z4 } from "zod";
234
+ var logger3 = createLogger("workflow-tag-list-tool");
235
+ var WorkflowTagListInputSchema = z4.object({
236
+ sort_by: z4.enum(["usage_count", "name", "created_at"]).default("usage_count").describe("Sort field: usage_count (default), name, or created_at"),
237
+ order: z4.enum(["asc", "desc"]).default("desc").describe("Sort order: desc (default) or asc"),
238
+ limit: z4.number().int().positive().max(1000).optional().describe("Max number of tags to return (default 100, max 1000)")
239
+ });
240
+
241
+ class WorkflowTagListRunner {
242
+ service;
243
+ constructor(service) {
244
+ this.service = service;
245
+ }
246
+ async run(options) {
247
+ if (typeof this.service.listTags !== "function") {
248
+ return { tags: [], total: 0 };
249
+ }
250
+ return await this.service.listTags(options);
251
+ }
252
+ }
253
+ __legacyDecorateClassTS([
254
+ TracedAs("workflow.tool.tag_list", {
255
+ recordParams: true,
256
+ recordResult: false,
257
+ log: false
258
+ })
259
+ ], WorkflowTagListRunner.prototype, "run", null);
260
+ function createWorkflowTagListTool(workflowService) {
261
+ const runner = new WorkflowTagListRunner(workflowService);
262
+ return {
263
+ name: "workflow_tag_list",
264
+ description: `List all existing workflow tags from the workflow_tags tag pool. ` + `⚠️ IMPORTANT: Call this tool BEFORE workflow_add to see available tags. ` + `When adding a new workflow, you should select tags from this pool to ensure ` + `semantic consistency. New tags will be auto-created if needed, but prefer existing ones. ` + `Returns tags sorted by usage_count DESC by default (most-used first).`,
265
+ parameters: WorkflowTagListInputSchema,
266
+ execute: async (args, _ctx) => {
267
+ try {
268
+ const params = WorkflowTagListInputSchema.parse(args);
269
+ const result = await runner.run({
270
+ sortBy: params.sort_by,
271
+ order: params.order,
272
+ limit: params.limit
273
+ });
274
+ const output = {
275
+ tags: result.tags,
276
+ total: result.total,
277
+ hint: "Select 1-3 tags from this list when calling workflow_add. Existing tags ensure semantic consistency across workflows."
278
+ };
279
+ return {
280
+ success: true,
281
+ output: JSON.stringify(output, null, 2),
282
+ metadata: { execution_time_ms: 0 }
283
+ };
284
+ } catch (error) {
285
+ logger3.error("Failed to list workflow tags", { error });
286
+ return {
287
+ success: false,
288
+ output: "",
289
+ error: error instanceof Error ? error.message : String(error),
290
+ metadata: { execution_time_ms: 0 }
291
+ };
292
+ }
293
+ }
294
+ };
295
+ }
296
+
297
+ // src/env/workflow/tools/workflow-add-tool.ts
298
+ import { z as z5 } from "zod";
299
+ init_logger();
300
+ import yaml from "yaml";
301
+ var logger4 = createLogger("workflow-add-tool");
302
+ var WorkflowAddInputSchema = z5.object({
303
+ definition: z5.any().optional().describe("Workflow definition object (alternative to definition_yaml)"),
304
+ definition_yaml: z5.string().optional().describe("Workflow definition as YAML or JSON string"),
305
+ name: z5.string().min(1).optional().describe("Workflow name (must match definition.name when both provided)"),
306
+ description: z5.string().optional().describe("Workflow description (overrides definition_yaml description)"),
307
+ tags: z5.array(z5.string()).min(TAG_MIN_COUNT, `Workflow requires at least ${TAG_MIN_COUNT} tag`).max(TAG_MAX_COUNT, `Workflow supports at most ${TAG_MAX_COUNT} tags`).describe(`Tags (${TAG_MIN_COUNT}-${TAG_MAX_COUNT} required). ` + `STRONGLY RECOMMENDED: select from existing tag pool via workflow_tag_list ` + `to ensure semantic consistency. ` + `Format: lowercase or kebab-case preferred (e.g. "ai", "data-pipeline").`)
308
+ });
309
+ function parseDefinitionYaml(content) {
310
+ try {
311
+ const parsed = yaml.parse(content);
312
+ if (parsed && typeof parsed === "object") {
313
+ return parsed;
314
+ }
315
+ } catch {}
316
+ try {
317
+ return JSON.parse(content);
318
+ } catch {
319
+ throw new Error("definition_yaml is not valid YAML or JSON");
320
+ }
321
+ }
322
+ function createWorkflowAddTool(workflowService) {
323
+ return {
324
+ name: "workflow_add",
325
+ description: `Create a new workflow. Tags are required (${TAG_MIN_COUNT}-${TAG_MAX_COUNT}). ` + `⚠️ IMPORTANT: Before calling this tool, you MUST call workflow_tag_list first ` + `to retrieve the existing tag pool. ` + `Select tags from this pool to ensure semantic consistency across workflows. ` + `New tags will be auto-created if not in the pool, but prefer existing ones when possible.`,
326
+ parameters: WorkflowAddInputSchema,
327
+ execute: async (args, _ctx) => {
328
+ try {
329
+ const params = WorkflowAddInputSchema.parse(args);
330
+ if (!Array.isArray(params.tags) || params.tags.length === 0) {
331
+ return {
332
+ success: false,
333
+ output: "",
334
+ error: "Workflow requires at least 1 tag (got empty)",
335
+ metadata: { execution_time_ms: 0 }
336
+ };
337
+ }
338
+ for (let i = 0;i < params.tags.length; i++) {
339
+ const t = params.tags[i] ?? "";
340
+ if (typeof t !== "string" || t.trim().length === 0) {
341
+ return {
342
+ success: false,
343
+ output: "",
344
+ error: `tag at index ${i} is empty`,
345
+ metadata: { execution_time_ms: 0 }
346
+ };
347
+ }
348
+ if (t.includes(",")) {
349
+ return {
350
+ success: false,
351
+ output: "",
352
+ error: `tag "${t}" contains comma; pass them as separate --tags`,
353
+ metadata: { execution_time_ms: 0 }
354
+ };
355
+ }
356
+ }
357
+ let definition = {};
358
+ if (params.definition && typeof params.definition === "object") {
359
+ if (params.definition.name && params.name && params.definition.name !== params.name) {
360
+ return {
361
+ success: false,
362
+ output: "",
363
+ error: `definition.name ('${params.definition.name}') does not match name ('${params.name}')`,
364
+ metadata: { execution_time_ms: 0 }
365
+ };
366
+ }
367
+ definition = params.definition;
368
+ } else if (params.definition_yaml) {
369
+ try {
370
+ definition = parseDefinitionYaml(params.definition_yaml);
371
+ } catch (e) {
372
+ return {
373
+ success: false,
374
+ output: "",
375
+ error: e instanceof Error ? e.message : String(e),
376
+ metadata: { execution_time_ms: 0 }
377
+ };
378
+ }
379
+ } else {
380
+ return {
381
+ success: false,
382
+ output: "",
383
+ error: "definition is required (provide `definition` object, `definition_yaml`, or just `name`)",
384
+ metadata: { execution_time_ms: 0 }
385
+ };
386
+ }
387
+ if (params.name && !definition.name) {
388
+ definition.name = params.name;
389
+ }
390
+ if (params.description && !definition.description) {
391
+ definition.description = params.description;
392
+ }
393
+ if (!definition.name) {
394
+ return {
395
+ success: false,
396
+ output: "",
397
+ error: "definition must have a `name` field",
398
+ metadata: { execution_time_ms: 0 }
399
+ };
400
+ }
401
+ const workflow = await workflowService.createWorkflow(definition, {
402
+ tags: params.tags
403
+ });
404
+ const availableTags = workflowService.tagRepository?.list?.()?.map((t) => ({
405
+ name: t.name,
406
+ count: t.usage_count
407
+ })) ?? [];
408
+ return {
409
+ success: true,
410
+ output: JSON.stringify({
411
+ workflow: {
412
+ name: workflow.name,
413
+ version: workflow.version,
414
+ description: workflow.description,
415
+ tags: workflow.tags,
416
+ created_at: workflow.createdAt
417
+ },
418
+ available_tags: availableTags
419
+ }, null, 2),
420
+ metadata: { execution_time_ms: 0 }
421
+ };
422
+ } catch (error) {
423
+ if (error && typeof error === "object" && "issues" in error && Array.isArray(error.issues)) {
424
+ const zodError = error;
425
+ const messages = zodError.issues.map((i) => i.message ?? "validation failed");
426
+ return {
427
+ success: false,
428
+ output: "",
429
+ error: messages.join("; "),
430
+ metadata: { execution_time_ms: 0 }
431
+ };
432
+ }
433
+ logger4.error("Failed to add workflow", { error });
434
+ return {
435
+ success: false,
436
+ output: "",
437
+ error: error instanceof Error ? error.message : String(error),
438
+ metadata: { execution_time_ms: 0 }
439
+ };
440
+ }
441
+ }
442
+ };
443
+ }
444
+
445
+ // src/env/workflow/tools/workflow-search-tool.ts
446
+ init_logger();
447
+ import { z as z6 } from "zod";
448
+ var logger5 = createLogger("workflow-search-tool");
449
+ var WorkflowSearchInputSchema = z6.object({
450
+ keyword: z6.string().optional().describe("Search keyword in name and description (case-insensitive substring)"),
451
+ tags: z6.array(z6.string()).optional().describe("Filter by tags (ALL must match - AND filter)"),
452
+ limit: z6.number().positive().optional().describe("Maximum number of results"),
453
+ offset: z6.number().min(0).optional().describe("Pagination offset")
454
+ });
455
+ function createWorkflowSearchTool(workflowService) {
456
+ return {
457
+ name: "workflow_search",
458
+ description: "Search workflows by keyword and/or tags. Multiple tags use AND filter. v2: returns available_tags so the caller knows what tags exist.",
459
+ parameters: WorkflowSearchInputSchema,
460
+ execute: async (args, _ctx) => {
461
+ try {
462
+ const params = WorkflowSearchInputSchema.parse(args);
463
+ if (!params.keyword && (!params.tags || params.tags.length === 0)) {
464
+ return {
465
+ success: false,
466
+ output: "",
467
+ error: "At least one of 'keyword' or 'tags' must be provided",
468
+ metadata: { execution_time_ms: 0 }
469
+ };
470
+ }
471
+ const result = await workflowService.searchWorkflowsWithTags({
472
+ keyword: params.keyword,
473
+ tags: params.tags,
474
+ limit: params.limit,
475
+ offset: params.offset
476
+ });
477
+ return {
478
+ success: true,
479
+ output: JSON.stringify({
480
+ workflows: result.workflows.map((w) => ({
481
+ name: w.name,
482
+ version: w.version,
483
+ description: w.description,
484
+ tags: w.tags,
485
+ createdAt: w.createdAt,
486
+ updatedAt: w.updatedAt
487
+ })),
488
+ available_tags: result.available_tags,
489
+ total: result.total,
490
+ count: result.workflows.length,
491
+ keyword: params.keyword,
492
+ tags: params.tags,
493
+ limit: params.limit,
494
+ offset: params.offset
495
+ }, null, 2),
496
+ metadata: { execution_time_ms: 0 }
497
+ };
498
+ } catch (error) {
499
+ logger5.error("Failed to search workflows", { error });
500
+ return {
501
+ success: false,
502
+ output: "",
503
+ error: error instanceof Error ? error.message : String(error),
504
+ metadata: { execution_time_ms: 0 }
505
+ };
506
+ }
507
+ }
508
+ };
509
+ }
510
+
511
+ // src/env/workflow/tools/run-workflow.ts
512
+ init_logger();
513
+ import { z as z7 } from "zod";
514
+ var logger6 = createLogger("run-workflow-tool");
515
+ var RunWorkflowInputSchema = z7.object({
516
+ workflow_name: z7.string().describe("Name of the workflow to run"),
517
+ input: z7.record(z7.any()).optional().describe("Input to pass to the workflow"),
518
+ sync: z7.boolean().default(true).describe("Wait for completion (default: true)"),
519
+ timeout: z7.number().positive().optional().describe("Timeout in milliseconds (default: 1800000 = 30 min)")
520
+ });
521
+ function createRunWorkflowTool(workflowService) {
522
+ return {
523
+ name: "workflow_run",
524
+ description: "Run a workflow by name with optional input. Returns run_id, status, output, error, and duration_ms. Default timeout: 30 minutes.",
525
+ parameters: RunWorkflowInputSchema,
526
+ sandbox: {
527
+ enabled: false
528
+ },
529
+ permission: {
530
+ level: "safe"
531
+ },
532
+ metadata: {
533
+ category: "workflow",
534
+ tags: ["workflow", "execute", "run"],
535
+ version: "1.0.0",
536
+ experimental: false
537
+ },
538
+ execute: async (args, ctx) => {
539
+ const startTime = Date.now();
540
+ const { workflow_name, input, sync = true, timeout = 1800000 } = args;
541
+ logger6.info(`Running workflow: ${workflow_name}`, { input, sync, timeout });
542
+ let timeoutHandle;
543
+ let durationMs;
544
+ try {
545
+ let result;
546
+ if (timeout) {
547
+ result = await Promise.race([
548
+ workflowService.runWorkflow(workflow_name, input, { sync }),
549
+ new Promise((_, reject) => {
550
+ timeoutHandle = setTimeout(() => {
551
+ reject(new Error("Workflow execution timed out"));
552
+ }, timeout);
553
+ })
554
+ ]);
555
+ } else {
556
+ result = await workflowService.runWorkflow(workflow_name, input, { sync });
557
+ }
558
+ if (timeoutHandle) {
559
+ clearTimeout(timeoutHandle);
560
+ }
561
+ durationMs = Date.now() - startTime;
562
+ if (sync) {
563
+ return {
564
+ success: result.status === "completed",
565
+ output: {
566
+ run_id: result.runId,
567
+ status: result.status,
568
+ output: result.output,
569
+ error: result.error,
570
+ duration_ms: result.durationMs || durationMs
571
+ },
572
+ metadata: {
573
+ execution_time_ms: durationMs
574
+ }
575
+ };
576
+ } else {
577
+ return {
578
+ success: true,
579
+ output: {
580
+ run_id: result.runId,
581
+ status: result.status,
582
+ duration_ms: durationMs
583
+ },
584
+ metadata: {
585
+ execution_time_ms: durationMs
586
+ }
587
+ };
588
+ }
589
+ } catch (error) {
590
+ if (timeoutHandle) {
591
+ clearTimeout(timeoutHandle);
592
+ }
593
+ durationMs = Date.now() - startTime;
594
+ const errorMessage = error instanceof Error ? error.message : String(error);
595
+ if (errorMessage.includes("Workflow not found")) {
596
+ return {
597
+ success: false,
598
+ output: "",
599
+ error: `Workflow not found: ${workflow_name}`,
600
+ metadata: {
601
+ execution_time_ms: durationMs
602
+ }
603
+ };
604
+ }
605
+ if (errorMessage.includes("abort") || errorMessage.includes("timed out")) {
606
+ return {
607
+ success: false,
608
+ output: "",
609
+ error: `Workflow execution timed out or was aborted: ${workflow_name}`,
610
+ metadata: {
611
+ execution_time_ms: durationMs
612
+ }
613
+ };
614
+ }
615
+ if (logger6?.error) {
616
+ logger6.error(`Failed to run workflow: ${workflow_name}`, { error: errorMessage });
617
+ }
618
+ return {
619
+ success: false,
620
+ output: "",
621
+ error: `Failed to run workflow ${workflow_name}: ${errorMessage}`,
622
+ metadata: {
623
+ execution_time_ms: durationMs
624
+ }
625
+ };
626
+ }
627
+ }
628
+ };
629
+ }
630
+ var _runWorkflowTool = null;
631
+ var _workflowService = null;
632
+ function initRunWorkflowTool(workflowService) {
633
+ _workflowService = workflowService;
634
+ _runWorkflowTool = createRunWorkflowTool(workflowService);
635
+ }
636
+ function getRunWorkflowTool() {
637
+ if (!_runWorkflowTool || !_workflowService) {
638
+ throw new Error("workflow_run tool not initialized. Call initRunWorkflowTool(workflowService) first.");
639
+ }
640
+ return _runWorkflowTool;
641
+ }
642
+ function resetRunWorkflowTool() {
643
+ _runWorkflowTool = null;
644
+ _workflowService = null;
645
+ }
646
+ function createLegacyRunWorkflowTool(workflowService) {
647
+ const tool = createRunWorkflowTool(workflowService);
648
+ return {
649
+ ...tool,
650
+ name: "run-workflow"
651
+ };
652
+ }
653
+
654
+ // src/env/workflow/tools/workflow-run-status-tool.ts
655
+ init_logger();
656
+ import { z as z8 } from "zod";
657
+ var logger7 = createLogger("workflow-run-status-tool");
658
+ var WorkflowRunStatusInputSchema = z8.object({
659
+ run_id: z8.string().describe("Run/session ID to query status")
660
+ });
661
+ function createWorkflowRunStatusTool(workflowService) {
662
+ return {
663
+ name: "workflow_run_status",
664
+ description: "Query the status of a workflow run by run_id. Returns run_id, status, output, error, and progress information.",
665
+ parameters: WorkflowRunStatusInputSchema,
666
+ execute: async (args, ctx) => {
667
+ const params = WorkflowRunStatusInputSchema.parse(args);
668
+ try {
669
+ const session = await workflowService.getSession(params.run_id);
670
+ if (!session) {
671
+ return {
672
+ success: false,
673
+ output: "",
674
+ error: `Run not found: ${params.run_id}`,
675
+ metadata: { execution_time_ms: 0 }
676
+ };
677
+ }
678
+ const metadata = session.metadata;
679
+ let messages = [];
680
+ try {
681
+ messages = await workflowService.getSessionMessages(params.run_id);
682
+ } catch {}
683
+ return {
684
+ success: true,
685
+ output: JSON.stringify({
686
+ run_id: session.id,
687
+ title: session.title,
688
+ status: metadata?.status || "unknown",
689
+ workflow_name: metadata?.workflowName,
690
+ workflow_version: metadata?.workflowVersion,
691
+ input: metadata?.input,
692
+ created_at: session.createdAt,
693
+ updated_at: session.updatedAt,
694
+ message_count: messages.length
695
+ }, null, 2),
696
+ metadata: { execution_time_ms: 0 }
697
+ };
698
+ } catch (error) {
699
+ logger7.error("Failed to get run status", { error });
700
+ return {
701
+ success: false,
702
+ output: "",
703
+ error: error instanceof Error ? error.message : String(error),
704
+ metadata: { execution_time_ms: 0 }
705
+ };
706
+ }
707
+ }
708
+ };
709
+ }
710
+
711
+ // src/env/workflow/tools/workflow-run-stop-tool.ts
712
+ init_logger();
713
+ import { z as z9 } from "zod";
714
+ var logger8 = createLogger("workflow-run-stop-tool");
715
+ var WorkflowRunStopInputSchema = z9.object({
716
+ run_id: z9.string().describe("Run/session ID to stop"),
717
+ reason: z9.string().optional().describe("Optional reason for stopping the workflow")
718
+ });
719
+ function createWorkflowRunStopTool(workflowService) {
720
+ return {
721
+ name: "workflow_run_stop",
722
+ description: "Stop a running workflow by run_id. Optionally provide a reason. Returns success status.",
723
+ parameters: WorkflowRunStopInputSchema,
724
+ execute: async (args, ctx) => {
725
+ const params = WorkflowRunStopInputSchema.parse(args);
726
+ try {
727
+ await workflowService.stopRun(params.run_id, params.reason);
728
+ return {
729
+ success: true,
730
+ output: JSON.stringify({
731
+ success: true,
732
+ run_id: params.run_id,
733
+ status: "stopped",
734
+ reason: params.reason || undefined
735
+ }, null, 2),
736
+ metadata: { execution_time_ms: 0 }
737
+ };
738
+ } catch (error) {
739
+ logger8.error("Failed to stop workflow run", { error });
740
+ return {
741
+ success: false,
742
+ output: "",
743
+ error: error instanceof Error ? error.message : String(error),
744
+ metadata: { execution_time_ms: 0 }
745
+ };
746
+ }
747
+ }
748
+ };
749
+ }
750
+
751
+ export { AskUserInputSchema, askUserTool, askUserToolInstance, WorkflowGetInputSchema, createWorkflowGetTool, WorkflowListInputSchema, createWorkflowListTool, WorkflowTagListInputSchema, createWorkflowTagListTool, WorkflowAddInputSchema, createWorkflowAddTool, WorkflowSearchInputSchema, createWorkflowSearchTool, RunWorkflowInputSchema, createRunWorkflowTool, initRunWorkflowTool, getRunWorkflowTool, resetRunWorkflowTool, createLegacyRunWorkflowTool, WorkflowRunStatusInputSchema, createWorkflowRunStatusTool, WorkflowRunStopInputSchema, createWorkflowRunStopTool };