@ai-setting/roy-agent-core 1.5.14-test → 1.5.15-test

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 (141) hide show
  1. package/package.json +1 -1
  2. package/dist/config/index.d.ts +0 -1250
  3. package/dist/config/index.js +0 -32
  4. package/dist/env/agent/index.d.ts +0 -2279
  5. package/dist/env/agent/index.js +0 -24
  6. package/dist/env/commands/index.d.ts +0 -1131
  7. package/dist/env/commands/index.js +0 -14
  8. package/dist/env/debug/formatters/index.d.ts +0 -236
  9. package/dist/env/debug/formatters/index.js +0 -11
  10. package/dist/env/debug/index.d.ts +0 -1652
  11. package/dist/env/debug/index.js +0 -26
  12. package/dist/env/hook/index.d.ts +0 -279
  13. package/dist/env/hook/index.js +0 -29
  14. package/dist/env/index.d.ts +0 -3481
  15. package/dist/env/index.js +0 -82
  16. package/dist/env/llm/index.d.ts +0 -1760
  17. package/dist/env/llm/index.js +0 -40
  18. package/dist/env/log-trace/index.d.ts +0 -1574
  19. package/dist/env/log-trace/index.js +0 -83
  20. package/dist/env/mcp/index.d.ts +0 -1331
  21. package/dist/env/mcp/index.js +0 -39
  22. package/dist/env/mcp/tool/index.d.ts +0 -183
  23. package/dist/env/mcp/tool/index.js +0 -14
  24. package/dist/env/memory/built-in/index.d.ts +0 -232
  25. package/dist/env/memory/built-in/index.js +0 -11
  26. package/dist/env/memory/index.d.ts +0 -1799
  27. package/dist/env/memory/index.js +0 -56
  28. package/dist/env/memory/plugin/index.d.ts +0 -747
  29. package/dist/env/memory/plugin/index.js +0 -36
  30. package/dist/env/prompt/index.d.ts +0 -1164
  31. package/dist/env/prompt/index.js +0 -20
  32. package/dist/env/session/index.d.ts +0 -1908
  33. package/dist/env/session/index.js +0 -25
  34. package/dist/env/session/storage/index.d.ts +0 -564
  35. package/dist/env/session/storage/index.js +0 -18
  36. package/dist/env/skill/index.d.ts +0 -1266
  37. package/dist/env/skill/index.js +0 -34
  38. package/dist/env/skill/tool/index.d.ts +0 -193
  39. package/dist/env/skill/tool/index.js +0 -9
  40. package/dist/env/task/delegate/index.d.ts +0 -1612
  41. package/dist/env/task/delegate/index.js +0 -18
  42. package/dist/env/task/events/index.d.ts +0 -171
  43. package/dist/env/task/events/index.js +0 -7
  44. package/dist/env/task/hooks/index.d.ts +0 -624
  45. package/dist/env/task/hooks/index.js +0 -7
  46. package/dist/env/task/index.d.ts +0 -1553
  47. package/dist/env/task/index.js +0 -34
  48. package/dist/env/task/plugins/index.d.ts +0 -466
  49. package/dist/env/task/plugins/index.js +0 -23
  50. package/dist/env/task/storage/index.d.ts +0 -241
  51. package/dist/env/task/storage/index.js +0 -14
  52. package/dist/env/task/tools/index.d.ts +0 -1485
  53. package/dist/env/task/tools/index.js +0 -17
  54. package/dist/env/task/tools/operation/index.d.ts +0 -1484
  55. package/dist/env/task/tools/operation/index.js +0 -15
  56. package/dist/env/tool/built-in/index.d.ts +0 -218
  57. package/dist/env/tool/built-in/index.js +0 -25
  58. package/dist/env/tool/index.d.ts +0 -1396
  59. package/dist/env/tool/index.js +0 -39
  60. package/dist/env/workflow/decorators/index.d.ts +0 -2161
  61. package/dist/env/workflow/decorators/index.js +0 -27
  62. package/dist/env/workflow/engine/index.d.ts +0 -3453
  63. package/dist/env/workflow/engine/index.js +0 -28
  64. package/dist/env/workflow/index.d.ts +0 -3546
  65. package/dist/env/workflow/index.js +0 -136
  66. package/dist/env/workflow/nodes/index.d.ts +0 -2092
  67. package/dist/env/workflow/nodes/index.js +0 -19
  68. package/dist/env/workflow/service/index.d.ts +0 -227
  69. package/dist/env/workflow/service/index.js +0 -13
  70. package/dist/env/workflow/storage/index.d.ts +0 -165
  71. package/dist/env/workflow/storage/index.js +0 -27
  72. package/dist/env/workflow/tools/index.d.ts +0 -416
  73. package/dist/env/workflow/tools/index.js +0 -159
  74. package/dist/env/workflow/types/index.d.ts +0 -2255
  75. package/dist/env/workflow/types/index.js +0 -98
  76. package/dist/env/workflow/utils/index.d.ts +0 -2031
  77. package/dist/env/workflow/utils/index.js +0 -637
  78. package/dist/index.d.ts +0 -7858
  79. package/dist/index.js +0 -399
  80. package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +0 -258
  81. package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
  82. package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +0 -349
  83. package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +0 -117
  84. package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +0 -11
  85. package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +0 -393
  86. package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +0 -200
  87. package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +0 -299
  88. package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
  89. package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +0 -393
  90. package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +0 -350
  91. package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +0 -180
  92. package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +0 -408
  93. package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +0 -284
  94. package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +0 -762
  95. package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +0 -10
  96. package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +0 -14
  97. package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +0 -922
  98. package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +0 -15
  99. package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +0 -1130
  100. package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
  101. package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +0 -653
  102. package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +0 -93
  103. package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +0 -872
  104. package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +0 -11
  105. package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +0 -64
  106. package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +0 -378
  107. package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +0 -492
  108. package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +0 -52
  109. package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +0 -171
  110. package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +0 -862
  111. package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +0 -1387
  112. package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +0 -208
  113. package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +0 -139
  114. package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +0 -534
  115. package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +0 -204
  116. package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +0 -603
  117. package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +0 -97
  118. package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +0 -587
  119. package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +0 -176
  120. package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +0 -60
  121. package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +0 -442
  122. package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +0 -57
  123. package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +0 -66
  124. package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +0 -10
  125. package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +0 -267
  126. package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +0 -584
  127. package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +0 -102
  128. package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +0 -549
  129. package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +0 -15
  130. package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +0 -213
  131. package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +0 -812
  132. package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +0 -1316
  133. package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +0 -1205
  134. package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +0 -328
  135. package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +0 -20
  136. package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +0 -2098
  137. package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +0 -419
  138. package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +0 -368
  139. package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +0 -377
  140. package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +0 -172
  141. package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +0 -103
@@ -1,637 +0,0 @@
1
- import {
2
- TracedAs,
3
- init_decorator
4
- } from "../../../shared/@ai-setting/roy-agent-core-zgypchmt.js";
5
- import"../../../shared/@ai-setting/roy-agent-core-44hnfb02.js";
6
- import"../../../shared/@ai-setting/roy-agent-core-xs5rsgat.js";
7
- import"../../../shared/@ai-setting/roy-agent-core-psv4v63c.js";
8
- import {
9
- __legacyDecorateClassTS
10
- } from "../../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
11
-
12
- // src/env/workflow/utils/template-resolver.ts
13
- class TemplateResolver {
14
- input;
15
- previousOutputs;
16
- constructor(options = {}) {
17
- this.input = options.input ?? {};
18
- this.previousOutputs = options.previousOutputs ?? new Map;
19
- }
20
- static fromContext(context) {
21
- return new TemplateResolver({
22
- input: context.input,
23
- previousOutputs: context.previousOutputs
24
- });
25
- }
26
- resolveValue(input) {
27
- if (input === null || input === undefined) {
28
- return input;
29
- }
30
- if (typeof input === "string") {
31
- const pureTemplate = this.extractPureTemplate(input);
32
- if (pureTemplate) {
33
- return this.resolvePureTemplate(pureTemplate);
34
- }
35
- return this.resolveString(input);
36
- }
37
- if (Array.isArray(input)) {
38
- return input.map((item) => this.resolveValue(item));
39
- }
40
- if (typeof input === "object") {
41
- const resolved = {};
42
- for (const [key, value] of Object.entries(input)) {
43
- resolved[key] = this.resolveValue(value);
44
- }
45
- return resolved;
46
- }
47
- return input;
48
- }
49
- extractPureTemplate(str) {
50
- const trimmed = str.trim();
51
- if (trimmed.startsWith("{{") && trimmed.endsWith("}}") && trimmed.length > 4) {
52
- const content = trimmed.slice(2, -2).trim();
53
- if (!content.includes("{{") && !content.includes("}}")) {
54
- return content;
55
- }
56
- }
57
- return null;
58
- }
59
- resolvePureTemplate(templateContent) {
60
- const value = this.resolveTemplateContent(templateContent);
61
- return value;
62
- }
63
- resolveTemplateContent(templateContent) {
64
- const trimmed = templateContent.trim();
65
- if (trimmed.startsWith("input.")) {
66
- return this.getNestedValue(this.input, trimmed.slice(6));
67
- }
68
- if (trimmed.startsWith("nodes.")) {
69
- return this.resolveNodePath(trimmed.slice(6));
70
- }
71
- if (trimmed !== "input" && trimmed !== "nodes") {
72
- const segments = trimmed.split(".");
73
- const nodeId = segments[0];
74
- const restPath = segments.slice(1).join(".") || undefined;
75
- return this.resolveNodePath(`${nodeId}${restPath ? "." + restPath : ""}`);
76
- }
77
- return;
78
- }
79
- resolveString(template) {
80
- if (!template || typeof template !== "string") {
81
- return template;
82
- }
83
- let resolved = template;
84
- resolved = resolved.replace(/\{\{input\.([^}]+)\}\}/g, (match, path) => {
85
- const value = this.getNestedValue(this.input, path);
86
- return this.stringify(value, match);
87
- });
88
- resolved = resolved.replace(/\{\{nodes\.([^}]+)\}\}/g, (match, path) => {
89
- const value = this.resolveNodePath(path);
90
- return this.stringify(value, match);
91
- });
92
- resolved = resolved.replace(/\{\{([a-zA-Z_][a-zA-Z0-9_-]*)(?:\.([^}]+))?\}\}/g, (match, nodeId, path) => {
93
- if (nodeId === "input") {
94
- return match;
95
- }
96
- if (nodeId === "nodes") {
97
- return match;
98
- }
99
- const value = this.resolveNodePath(`${nodeId}${path ? "." + path : ""}`);
100
- return this.stringify(value, match);
101
- });
102
- return resolved;
103
- }
104
- resolveNodePath(path) {
105
- const segments = path.split(".");
106
- const nodeId = segments[0];
107
- if (!nodeId) {
108
- return;
109
- }
110
- let value = this.previousOutputs.get(nodeId);
111
- if (value === undefined) {
112
- const normalizedUnderscore = nodeId.replace(/-/g, "_");
113
- const normalizedHyphen = nodeId.replace(/_/g, "-");
114
- if (normalizedUnderscore !== nodeId) {
115
- value = this.previousOutputs.get(normalizedUnderscore);
116
- }
117
- if (value === undefined && normalizedHyphen !== nodeId) {
118
- value = this.previousOutputs.get(normalizedHyphen);
119
- }
120
- }
121
- if (value === undefined) {
122
- return;
123
- }
124
- if (segments.length === 1) {
125
- if (value && typeof value === "object" && "result" in value && !("nodes" in value)) {
126
- value = value.result;
127
- }
128
- return value;
129
- }
130
- const secondSegment = segments[1];
131
- if (secondSegment === "result" || secondSegment === "output") {
132
- if (value && typeof value === "object" && "result" in value) {
133
- value = value.result;
134
- if (segments.length === 2) {
135
- return value;
136
- }
137
- for (let i = 2;i < segments.length; i++) {
138
- if (value === null || value === undefined) {
139
- return;
140
- }
141
- value = value[segments[i]];
142
- }
143
- return value;
144
- }
145
- }
146
- for (let i = 1;i < segments.length; i++) {
147
- if (value === null || value === undefined) {
148
- return;
149
- }
150
- value = value[segments[i]];
151
- }
152
- return value;
153
- }
154
- getNestedValue(obj, path) {
155
- if (!obj || !path) {
156
- return;
157
- }
158
- const segments = path.split(".");
159
- let current = obj;
160
- for (const segment of segments) {
161
- if (current === null || current === undefined) {
162
- return;
163
- }
164
- if (typeof current !== "object") {
165
- return;
166
- }
167
- current = current[segment];
168
- }
169
- return current;
170
- }
171
- stringify(value, originalTemplate) {
172
- if (value === undefined) {
173
- return originalTemplate;
174
- }
175
- if (typeof value === "string") {
176
- return value;
177
- }
178
- if (value === null) {
179
- return "null";
180
- }
181
- return JSON.stringify(value);
182
- }
183
- containsTemplates(str) {
184
- if (typeof str !== "string") {
185
- return false;
186
- }
187
- return /\{\{[^}]+\}\}/.test(str);
188
- }
189
- extractTemplates(str) {
190
- if (typeof str !== "string") {
191
- return [];
192
- }
193
- const matches = str.match(/\{\{[^}]+\}\}/g);
194
- return matches ?? [];
195
- }
196
- }
197
- function resolveTemplates(input, context) {
198
- const resolver = TemplateResolver.fromContext(context);
199
- return resolver.resolveValue(input);
200
- }
201
- function resolveTemplateString(template, context) {
202
- const resolver = TemplateResolver.fromContext(context);
203
- return resolver.resolveString(template);
204
- }
205
- // src/env/workflow/utils/recovery-validator.ts
206
- init_decorator();
207
-
208
- // src/env/workflow/utils/validation-rules.ts
209
- var ValidationErrorType;
210
- ((ValidationErrorType2) => {
211
- ValidationErrorType2["MISSING_VARIABLE"] = "MISSING_VARIABLE";
212
- ValidationErrorType2["INCOMPLETE_PARALLEL"] = "INCOMPLETE_PARALLEL";
213
- ValidationErrorType2["AMBIGUOUS_BRANCH"] = "AMBIGUOUS_BRANCH";
214
- ValidationErrorType2["LOOP_STATE_LOST"] = "LOOP_STATE_LOST";
215
- ValidationErrorType2["NESTED_WORKFLOW_INVALID"] = "NESTED_WORKFLOW_INVALID";
216
- ValidationErrorType2["NODE_STATE_INCONSISTENT"] = "NODE_STATE_INCONSISTENT";
217
- ValidationErrorType2["MISSING_DEPENDENCY"] = "MISSING_DEPENDENCY";
218
- })(ValidationErrorType ||= {});
219
- var SuggestedAction;
220
- ((SuggestedAction2) => {
221
- SuggestedAction2["RE_RUN"] = "RE_RUN";
222
- SuggestedAction2["CONFIRM"] = "CONFIRM";
223
- SuggestedAction2["SKIP"] = "SKIP";
224
- SuggestedAction2["PROVIDE_VALUE"] = "PROVIDE_VALUE";
225
- SuggestedAction2["IGNORE"] = "IGNORE";
226
- })(SuggestedAction ||= {});
227
-
228
- // src/env/workflow/utils/execution-state.ts
229
- init_decorator();
230
- class ExecutionStateBuilder {
231
- build(messages, definition) {
232
- const state = {
233
- completedNodes: new Set,
234
- inProgressNodes: new Set,
235
- pendingNodes: new Set,
236
- nodeOutputs: new Map,
237
- nodeInputs: new Map,
238
- variables: new Map,
239
- loopCounts: new Map
240
- };
241
- this.parseMessages(messages, state);
242
- this.buildPendingNodes(definition, state);
243
- return state;
244
- }
245
- parseMessages(messages, state) {
246
- let lastCallNodeId = null;
247
- let lastCallInput = null;
248
- for (const msg of messages) {
249
- const metadata = msg.metadata;
250
- const msgType = metadata?.type;
251
- switch (msgType) {
252
- case "workflow.node.call": {
253
- const nodeId = metadata?.workflowNodeId;
254
- if (nodeId) {
255
- lastCallNodeId = nodeId;
256
- lastCallInput = this.extractInput(msg);
257
- state.inProgressNodes.add(nodeId);
258
- state.nodeInputs.set(nodeId, lastCallInput);
259
- }
260
- break;
261
- }
262
- case "workflow.node.result": {
263
- if (lastCallNodeId) {
264
- state.inProgressNodes.delete(lastCallNodeId);
265
- state.completedNodes.add(lastCallNodeId);
266
- const output = this.extractOutput(msg);
267
- state.nodeOutputs.set(lastCallNodeId, output);
268
- this.extractVariables(output, state);
269
- lastCallNodeId = null;
270
- lastCallInput = null;
271
- }
272
- break;
273
- }
274
- case "workflow.node.interrupt": {
275
- if (lastCallNodeId) {
276
- state.inProgressNodes.add(lastCallNodeId);
277
- }
278
- break;
279
- }
280
- case "workflow.node.resume": {
281
- if (lastCallNodeId) {
282
- state.inProgressNodes.add(lastCallNodeId);
283
- }
284
- break;
285
- }
286
- }
287
- }
288
- }
289
- buildPendingNodes(definition, state) {
290
- const nodeIds = new Set((definition.nodes || []).map((n) => n.id));
291
- const allNodeIds = Array.from(nodeIds);
292
- const entryNodes = this.getEntryNodes(definition);
293
- for (const entryNode of entryNodes) {
294
- if (!state.completedNodes.has(entryNode)) {
295
- this.markPendingFromNode(entryNode, definition, state);
296
- }
297
- }
298
- for (const completedId of state.completedNodes) {
299
- const children = this.getDirectChildren(completedId, definition);
300
- for (const childId of children) {
301
- if (!state.completedNodes.has(childId) && !state.inProgressNodes.has(childId)) {
302
- state.pendingNodes.add(childId);
303
- }
304
- }
305
- }
306
- }
307
- getEntryNodes(definition) {
308
- const entry = definition.entry;
309
- if (!entry) {
310
- return [];
311
- }
312
- if (Array.isArray(entry)) {
313
- return entry;
314
- }
315
- return [entry];
316
- }
317
- markPendingFromNode(startNodeId, definition, state) {
318
- const visited = new Set;
319
- const queue = [startNodeId];
320
- while (queue.length > 0) {
321
- const nodeId = queue.shift();
322
- if (visited.has(nodeId)) {
323
- continue;
324
- }
325
- visited.add(nodeId);
326
- if (!state.completedNodes.has(nodeId)) {
327
- state.pendingNodes.add(nodeId);
328
- }
329
- const children = this.getDirectChildren(nodeId, definition);
330
- for (const childId of children) {
331
- if (!visited.has(childId)) {
332
- queue.push(childId);
333
- }
334
- }
335
- }
336
- }
337
- getDirectChildren(nodeId, definition) {
338
- const edges = definition.edges || definition.connections || [];
339
- return edges.filter((edge) => edge.source === nodeId || edge.from === nodeId).map((edge) => edge.target || edge.to);
340
- }
341
- extractInput(msg) {
342
- try {
343
- return JSON.parse(msg.content);
344
- } catch {
345
- return msg.content;
346
- }
347
- }
348
- extractOutput(msg) {
349
- try {
350
- return JSON.parse(msg.content);
351
- } catch {
352
- return msg.content;
353
- }
354
- }
355
- extractVariables(output, state) {
356
- if (!output || typeof output !== "object") {
357
- return;
358
- }
359
- const outputObj = output;
360
- for (const [key, value] of Object.entries(outputObj)) {
361
- if (key.startsWith("_") || key.startsWith("$")) {
362
- continue;
363
- }
364
- if (!state.variables.has(key)) {
365
- state.variables.set(key, value);
366
- }
367
- }
368
- }
369
- }
370
- __legacyDecorateClassTS([
371
- TracedAs("recovery.builder.build", { recordParams: true, recordResult: true, log: true })
372
- ], ExecutionStateBuilder.prototype, "build", null);
373
- __legacyDecorateClassTS([
374
- TracedAs("recovery.builder.parseMessages", { recordParams: true, recordResult: true, log: true })
375
- ], ExecutionStateBuilder.prototype, "parseMessages", null);
376
- __legacyDecorateClassTS([
377
- TracedAs("recovery.builder.buildPendingNodes", { recordParams: true, recordResult: true, log: true })
378
- ], ExecutionStateBuilder.prototype, "buildPendingNodes", null);
379
-
380
- // src/env/workflow/utils/recovery-validator.ts
381
- class RecoveryValidator {
382
- stateBuilder;
383
- constructor() {
384
- this.stateBuilder = new ExecutionStateBuilder;
385
- }
386
- async validate(messages, definition) {
387
- const state = this.stateBuilder.build(messages, definition);
388
- const errors = [];
389
- const warnings = [];
390
- errors.push(...this.validateStateIntegrity(state, definition));
391
- errors.push(...this.validateParallelBranches(state, definition));
392
- errors.push(...this.validateConditionBranches(state, definition));
393
- errors.push(...this.validateLoopState(state, definition));
394
- errors.push(...this.validateNestedWorkflows(state, definition));
395
- return {
396
- isValid: errors.length === 0,
397
- errors,
398
- warnings
399
- };
400
- }
401
- async generatePlan(messages, definition) {
402
- const state = this.stateBuilder.build(messages, definition);
403
- const validationResult = await this.validate(messages, definition);
404
- const pendingNodes = Array.from(state.pendingNodes);
405
- const completedNodes = Array.from(state.completedNodes);
406
- const resumePoint = this.determineResumePoint(state, definition);
407
- const summary = this.generateSummary(state, validationResult);
408
- return {
409
- canResume: validationResult.isValid,
410
- resumePoint,
411
- completedNodes,
412
- pendingNodes,
413
- skippedNodes: [],
414
- validationErrors: validationResult.errors,
415
- summary
416
- };
417
- }
418
- validateStateIntegrity(state, definition) {
419
- const errors = [];
420
- for (const nodeId of state.pendingNodes) {
421
- const node = definition.nodes?.find((n) => n.id === nodeId);
422
- if (!node?.config)
423
- continue;
424
- const variableRefs = this.extractVariableRefs(node.config);
425
- for (const varRef of variableRefs) {
426
- if (!state.nodeOutputs.has(varRef) && !state.variables.has(varRef)) {
427
- errors.push({
428
- type: "MISSING_VARIABLE" /* MISSING_VARIABLE */,
429
- nodeId,
430
- description: `变量 ${varRef} 不存在,需要重新运行`,
431
- suggestedAction: "RE_RUN" /* RE_RUN */,
432
- context: { variable: varRef, nodeConfig: node.config }
433
- });
434
- }
435
- }
436
- }
437
- return errors;
438
- }
439
- validateParallelBranches(state, definition) {
440
- const errors = [];
441
- const parallelGroups = this.identifyParallelGroups(definition);
442
- for (const group of parallelGroups) {
443
- const completedInGroup = group.filter((id) => state.completedNodes.has(id));
444
- const inProgressInGroup = group.filter((id) => state.inProgressNodes.has(id));
445
- if (inProgressInGroup.length > 0 || completedInGroup.length < group.length) {
446
- const mergeNode = this.findMergeNodeForParallel(group, definition);
447
- if (mergeNode && !state.completedNodes.has(mergeNode)) {
448
- const incomplete = group.filter((id) => !state.completedNodes.has(id));
449
- errors.push({
450
- type: "INCOMPLETE_PARALLEL" /* INCOMPLETE_PARALLEL */,
451
- nodeId: mergeNode,
452
- description: `并行分支 ${incomplete.join(", ")} 未完成`,
453
- suggestedAction: "RE_RUN" /* RE_RUN */,
454
- context: { incompleteBranches: incomplete, mergeNode }
455
- });
456
- }
457
- }
458
- }
459
- return errors;
460
- }
461
- validateConditionBranches(state, definition) {
462
- const errors = [];
463
- const edges = definition.edges || definition.connections || [];
464
- const conditionalEdges = edges.filter((e) => e.condition);
465
- for (const edge of conditionalEdges) {
466
- const conditionVars = this.extractVariableRefs(edge.condition);
467
- for (const varRef of conditionVars) {
468
- if (!state.nodeOutputs.has(varRef) && !state.variables.has(varRef)) {
469
- errors.push({
470
- type: "AMBIGUOUS_BRANCH" /* AMBIGUOUS_BRANCH */,
471
- nodeId: edge.target || edge.to,
472
- description: `条件分支无法确定:变量 ${varRef} 不存在`,
473
- suggestedAction: "CONFIRM" /* CONFIRM */,
474
- context: { variable: varRef, condition: edge.condition }
475
- });
476
- }
477
- }
478
- }
479
- return errors;
480
- }
481
- validateLoopState(state, definition) {
482
- const errors = [];
483
- const loops = this.identifyLoops(definition);
484
- for (const loop of loops) {
485
- const loopCounter = `loop_count_${loop.header}`;
486
- if (!state.nodeOutputs.has(loopCounter) && state.pendingNodes.has(loop.header)) {
487
- errors.push({
488
- type: "LOOP_STATE_LOST" /* LOOP_STATE_LOST */,
489
- nodeId: loop.header,
490
- description: `循环状态丢失,循环计数器 ${loopCounter} 不存在`,
491
- suggestedAction: "RE_RUN" /* RE_RUN */,
492
- context: { loopHeader: loop.header }
493
- });
494
- }
495
- }
496
- return errors;
497
- }
498
- validateNestedWorkflows(state, definition) {
499
- const errors = [];
500
- const workflowNodes = (definition.nodes || []).filter((n) => n.type === "workflow");
501
- for (const node of workflowNodes) {
502
- const nodeOutput = state.nodeOutputs.get(node.id);
503
- const subSessionId = nodeOutput?.sessionId;
504
- if (subSessionId && state.pendingNodes.has(node.id)) {}
505
- }
506
- return errors;
507
- }
508
- extractVariableRefs(obj) {
509
- const refs = [];
510
- if (!obj)
511
- return refs;
512
- const str = JSON.stringify(obj);
513
- const regex = /\{\{([^}]+)\}\}/g;
514
- let match;
515
- while ((match = regex.exec(str)) !== null) {
516
- refs.push(match[1].trim());
517
- }
518
- return refs;
519
- }
520
- identifyParallelGroups(definition) {
521
- const groups = [];
522
- const sources = new Map;
523
- const edges = definition.edges || definition.connections || [];
524
- for (const edge of edges) {
525
- const source = edge.source || edge.from;
526
- const target = edge.target || edge.to;
527
- const targets = sources.get(source) || [];
528
- targets.push(target);
529
- sources.set(source, targets);
530
- }
531
- for (const [_source, targets] of sources) {
532
- if (targets.length > 1) {
533
- groups.push(targets);
534
- }
535
- }
536
- return groups;
537
- }
538
- findMergeNodeForParallel(parallelIds, definition) {
539
- const edges = definition.edges || definition.connections || [];
540
- for (const edge of edges) {
541
- const target = edge.target || edge.to;
542
- const source = edge.source || edge.from;
543
- const allSourcesFromParallel = parallelIds.includes(source);
544
- const hasIncomingFromParallel = parallelIds.some((id) => edges.some((e) => (e.source || e.from) === id && (e.target || e.to) === target));
545
- if (allSourcesFromParallel && hasIncomingFromParallel) {
546
- return target;
547
- }
548
- }
549
- return null;
550
- }
551
- identifyLoops(definition) {
552
- const loops = [];
553
- const visited = new Set;
554
- const recStack = new Set;
555
- const edges = definition.edges || definition.connections || [];
556
- const getChildren = (nodeId) => {
557
- return edges.filter((e) => (e.source || e.from) === nodeId).map((e) => e.target || e.to);
558
- };
559
- const dfs = (nodeId, path) => {
560
- visited.add(nodeId);
561
- recStack.add(nodeId);
562
- const outgoing = getChildren(nodeId);
563
- for (const childId of outgoing) {
564
- if (!visited.has(childId)) {
565
- dfs(childId, [...path, childId]);
566
- } else if (recStack.has(childId)) {
567
- const loopStart = path.indexOf(childId);
568
- if (loopStart !== -1) {
569
- loops.push({
570
- header: childId,
571
- body: path.slice(loopStart)
572
- });
573
- }
574
- }
575
- }
576
- recStack.delete(nodeId);
577
- };
578
- for (const node of definition.nodes || []) {
579
- if (!visited.has(node.id)) {
580
- dfs(node.id, [node.id]);
581
- }
582
- }
583
- return loops;
584
- }
585
- determineResumePoint(state, definition) {
586
- const inProgress = Array.from(state.inProgressNodes);
587
- if (inProgress.length > 0) {
588
- return inProgress[0];
589
- }
590
- const pending = Array.from(state.pendingNodes);
591
- if (pending.length > 0) {
592
- return pending[0];
593
- }
594
- const entry = definition.entry;
595
- if (Array.isArray(entry)) {
596
- return entry[0] || "";
597
- }
598
- return entry || "";
599
- }
600
- generateSummary(state, result) {
601
- if (result.isValid) {
602
- return `恢复验证通过。已完成 ${state.completedNodes.size} 个节点,待执行 ${state.pendingNodes.size} 个节点。`;
603
- }
604
- const errorTypes = result.errors.map((e) => e.type).join(", ");
605
- return `恢复验证失败:${errorTypes}。${result.errors.length} 个错误需要处理。`;
606
- }
607
- }
608
- __legacyDecorateClassTS([
609
- TracedAs("recovery.validator.validate", { recordParams: true, recordResult: true, log: true })
610
- ], RecoveryValidator.prototype, "validate", null);
611
- __legacyDecorateClassTS([
612
- TracedAs("recovery.generate.plan", { recordParams: true, recordResult: true, log: true })
613
- ], RecoveryValidator.prototype, "generatePlan", null);
614
- __legacyDecorateClassTS([
615
- TracedAs("recovery.validator.validateStateIntegrity", { recordParams: true, recordResult: true, log: true })
616
- ], RecoveryValidator.prototype, "validateStateIntegrity", null);
617
- __legacyDecorateClassTS([
618
- TracedAs("recovery.validator.validateParallel", { recordParams: true, recordResult: true, log: true })
619
- ], RecoveryValidator.prototype, "validateParallelBranches", null);
620
- __legacyDecorateClassTS([
621
- TracedAs("recovery.validator.validateCondition", { recordParams: true, recordResult: true, log: true })
622
- ], RecoveryValidator.prototype, "validateConditionBranches", null);
623
- __legacyDecorateClassTS([
624
- TracedAs("recovery.validator.validateLoop", { recordParams: true, recordResult: true, log: true })
625
- ], RecoveryValidator.prototype, "validateLoopState", null);
626
- __legacyDecorateClassTS([
627
- TracedAs("recovery.validator.validateNested", { recordParams: true, recordResult: true, log: true })
628
- ], RecoveryValidator.prototype, "validateNestedWorkflows", null);
629
- export {
630
- resolveTemplates,
631
- resolveTemplateString,
632
- ValidationErrorType,
633
- TemplateResolver,
634
- SuggestedAction,
635
- RecoveryValidator,
636
- ExecutionStateBuilder
637
- };