@ai-setting/roy-agent-core 1.5.15-test → 1.5.17-beta.1

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/dist/config/index.d.ts +1250 -0
  2. package/dist/config/index.js +32 -0
  3. package/dist/env/agent/index.d.ts +2279 -0
  4. package/dist/env/agent/index.js +24 -0
  5. package/dist/env/commands/index.d.ts +1131 -0
  6. package/dist/env/commands/index.js +14 -0
  7. package/dist/env/debug/formatters/index.d.ts +236 -0
  8. package/dist/env/debug/formatters/index.js +11 -0
  9. package/dist/env/debug/index.d.ts +1652 -0
  10. package/dist/env/debug/index.js +26 -0
  11. package/dist/env/hook/index.d.ts +279 -0
  12. package/dist/env/hook/index.js +29 -0
  13. package/dist/env/index.d.ts +3481 -0
  14. package/dist/env/index.js +82 -0
  15. package/dist/env/llm/index.d.ts +1760 -0
  16. package/dist/env/llm/index.js +40 -0
  17. package/dist/env/log-trace/index.d.ts +1574 -0
  18. package/dist/env/log-trace/index.js +83 -0
  19. package/dist/env/mcp/index.d.ts +1331 -0
  20. package/dist/env/mcp/index.js +39 -0
  21. package/dist/env/mcp/tool/index.d.ts +183 -0
  22. package/dist/env/mcp/tool/index.js +14 -0
  23. package/dist/env/memory/built-in/index.d.ts +232 -0
  24. package/dist/env/memory/built-in/index.js +11 -0
  25. package/dist/env/memory/index.d.ts +1799 -0
  26. package/dist/env/memory/index.js +56 -0
  27. package/dist/env/memory/plugin/index.d.ts +747 -0
  28. package/dist/env/memory/plugin/index.js +36 -0
  29. package/dist/env/prompt/index.d.ts +1164 -0
  30. package/dist/env/prompt/index.js +20 -0
  31. package/dist/env/session/index.d.ts +1908 -0
  32. package/dist/env/session/index.js +25 -0
  33. package/dist/env/session/storage/index.d.ts +564 -0
  34. package/dist/env/session/storage/index.js +18 -0
  35. package/dist/env/skill/index.d.ts +1266 -0
  36. package/dist/env/skill/index.js +34 -0
  37. package/dist/env/skill/tool/index.d.ts +193 -0
  38. package/dist/env/skill/tool/index.js +9 -0
  39. package/dist/env/task/delegate/index.d.ts +1612 -0
  40. package/dist/env/task/delegate/index.js +18 -0
  41. package/dist/env/task/events/index.d.ts +171 -0
  42. package/dist/env/task/events/index.js +7 -0
  43. package/dist/env/task/hooks/index.d.ts +624 -0
  44. package/dist/env/task/hooks/index.js +7 -0
  45. package/dist/env/task/index.d.ts +1553 -0
  46. package/dist/env/task/index.js +34 -0
  47. package/dist/env/task/plugins/index.d.ts +466 -0
  48. package/dist/env/task/plugins/index.js +23 -0
  49. package/dist/env/task/storage/index.d.ts +241 -0
  50. package/dist/env/task/storage/index.js +14 -0
  51. package/dist/env/task/tools/index.d.ts +1485 -0
  52. package/dist/env/task/tools/index.js +17 -0
  53. package/dist/env/task/tools/operation/index.d.ts +1484 -0
  54. package/dist/env/task/tools/operation/index.js +15 -0
  55. package/dist/env/tool/built-in/index.d.ts +218 -0
  56. package/dist/env/tool/built-in/index.js +25 -0
  57. package/dist/env/tool/index.d.ts +1396 -0
  58. package/dist/env/tool/index.js +39 -0
  59. package/dist/env/workflow/decorators/index.d.ts +2161 -0
  60. package/dist/env/workflow/decorators/index.js +27 -0
  61. package/dist/env/workflow/engine/index.d.ts +3453 -0
  62. package/dist/env/workflow/engine/index.js +28 -0
  63. package/dist/env/workflow/index.d.ts +3546 -0
  64. package/dist/env/workflow/index.js +136 -0
  65. package/dist/env/workflow/nodes/index.d.ts +2092 -0
  66. package/dist/env/workflow/nodes/index.js +19 -0
  67. package/dist/env/workflow/service/index.d.ts +227 -0
  68. package/dist/env/workflow/service/index.js +13 -0
  69. package/dist/env/workflow/storage/index.d.ts +165 -0
  70. package/dist/env/workflow/storage/index.js +27 -0
  71. package/dist/env/workflow/tools/index.d.ts +416 -0
  72. package/dist/env/workflow/tools/index.js +159 -0
  73. package/dist/env/workflow/types/index.d.ts +2255 -0
  74. package/dist/env/workflow/types/index.js +98 -0
  75. package/dist/env/workflow/utils/index.d.ts +2031 -0
  76. package/dist/env/workflow/utils/index.js +637 -0
  77. package/dist/index.d.ts +7858 -0
  78. package/dist/index.js +399 -0
  79. package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +258 -0
  80. package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +36 -0
  81. package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +349 -0
  82. package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +117 -0
  83. package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +11 -0
  84. package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +393 -0
  85. package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +200 -0
  86. package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +299 -0
  87. package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +206 -0
  88. package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +393 -0
  89. package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +350 -0
  90. package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +180 -0
  91. package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +408 -0
  92. package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +284 -0
  93. package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +762 -0
  94. package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +10 -0
  95. package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +14 -0
  96. package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +922 -0
  97. package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +15 -0
  98. package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +1130 -0
  99. package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +14 -0
  100. package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +653 -0
  101. package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +93 -0
  102. package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +872 -0
  103. package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +11 -0
  104. package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +64 -0
  105. package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +378 -0
  106. package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +492 -0
  107. package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +52 -0
  108. package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +171 -0
  109. package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +862 -0
  110. package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +1387 -0
  111. package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +208 -0
  112. package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +139 -0
  113. package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +534 -0
  114. package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +204 -0
  115. package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +603 -0
  116. package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +97 -0
  117. package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +587 -0
  118. package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +176 -0
  119. package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +60 -0
  120. package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +442 -0
  121. package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +57 -0
  122. package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +66 -0
  123. package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +10 -0
  124. package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +267 -0
  125. package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +584 -0
  126. package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +102 -0
  127. package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +549 -0
  128. package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +15 -0
  129. package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +213 -0
  130. package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +812 -0
  131. package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +1316 -0
  132. package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +1205 -0
  133. package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +328 -0
  134. package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +20 -0
  135. package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +2098 -0
  136. package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +419 -0
  137. package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +368 -0
  138. package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +377 -0
  139. package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +172 -0
  140. package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +103 -0
  141. package/package.json +29 -8
@@ -0,0 +1,349 @@
1
+ import {
2
+ createLogger,
3
+ init_logger
4
+ } from "./roy-agent-core-44hnfb02.js";
5
+
6
+ // src/env/mcp/tool/adapter.ts
7
+ init_logger();
8
+ import { z } from "zod";
9
+ var logger = createLogger("mcp-adapter");
10
+ function validateRequiredParams(inputSchema, args) {
11
+ if (!inputSchema) {
12
+ return { valid: true, missing: [] };
13
+ }
14
+ const schema = inputSchema;
15
+ const required = schema.required ?? [];
16
+ if (required.length === 0) {
17
+ return { valid: true, missing: [] };
18
+ }
19
+ const missing = [];
20
+ for (const param of required) {
21
+ const value = args[param];
22
+ if (value === undefined || value === null) {
23
+ missing.push(param);
24
+ }
25
+ }
26
+ if (missing.length > 0) {
27
+ return {
28
+ valid: false,
29
+ missing,
30
+ error: `Missing required parameter${missing.length > 1 ? "s" : ""}: ${missing.join(", ")}`
31
+ };
32
+ }
33
+ return { valid: true, missing: [] };
34
+ }
35
+ function adaptMcpTool(mcpTool, mcpClient, serverName) {
36
+ const toolName = `mcp_${serverName}_${mcpTool.name}`;
37
+ const description = `MCP tool [${serverName}/${mcpTool.name}]: ${mcpTool.description ?? ""}`;
38
+ const paramsSchema = convertInputSchemaToZod(mcpTool.inputSchema);
39
+ return {
40
+ name: toolName,
41
+ description,
42
+ parameters: paramsSchema,
43
+ execute: async (args, _ctx) => {
44
+ const toolArgs = args ?? {};
45
+ const validation = validateRequiredParams(mcpTool.inputSchema, toolArgs);
46
+ if (!validation.valid) {
47
+ logger.warn(`[McpAdapter] Tool call skipped: ${toolName}`, {
48
+ reason: "missing_required_params",
49
+ missing: validation.missing
50
+ });
51
+ return {
52
+ success: false,
53
+ output: "",
54
+ error: validation.error
55
+ };
56
+ }
57
+ try {
58
+ const result = await mcpClient.callTool({
59
+ name: mcpTool.name,
60
+ arguments: toolArgs
61
+ });
62
+ return convertMcpCallResult(result);
63
+ } catch (error) {
64
+ const errorMessage = error instanceof Error ? error.message : String(error);
65
+ const errorCode = error?.code;
66
+ logger.error(`[McpAdapter] Tool call failed: ${toolName}`, {
67
+ error: errorMessage,
68
+ errorCode,
69
+ receivedArgs: toolArgs
70
+ });
71
+ let userMessage = errorMessage;
72
+ if (errorCode === -32602) {
73
+ userMessage = `Invalid parameters for tool "${mcpTool.name}": ${errorMessage}`;
74
+ }
75
+ return {
76
+ success: false,
77
+ output: "",
78
+ error: userMessage
79
+ };
80
+ }
81
+ },
82
+ metadata: {
83
+ category: "mcp",
84
+ tags: ["mcp", serverName],
85
+ mcpTool: {
86
+ originalName: mcpTool.name,
87
+ originalDescription: mcpTool.description || "",
88
+ inputSchema: mcpTool.inputSchema
89
+ }
90
+ }
91
+ };
92
+ }
93
+ function convertInputSchemaToZod(inputSchema) {
94
+ if (!inputSchema) {
95
+ return z.unknown();
96
+ }
97
+ const schema = inputSchema;
98
+ const properties = schema.properties ?? {};
99
+ const required = schema.required ?? [];
100
+ if (schema.anyOf || schema.oneOf) {
101
+ const unions = schema.anyOf || schema.oneOf || [];
102
+ const zodUnions = unions.map((s) => jsonSchemaToZod(s, false)).filter((t) => t);
103
+ if (zodUnions.length > 0) {
104
+ return z.union(zodUnions);
105
+ }
106
+ }
107
+ if (schema.allOf) {
108
+ const schemas = [];
109
+ for (const subSchema of schema.allOf) {
110
+ const sub = jsonSchemaToZod(subSchema, false);
111
+ schemas.push(sub);
112
+ }
113
+ if (schemas.length === 1) {
114
+ return schemas[0];
115
+ }
116
+ let combined = schemas[0];
117
+ for (let i = 1;i < schemas.length; i++) {
118
+ combined = z.intersection(combined, schemas[i]);
119
+ }
120
+ return combined;
121
+ }
122
+ const zodFields = {};
123
+ const fieldDescriptions = {};
124
+ for (const [key, prop] of Object.entries(properties)) {
125
+ const isRequired = required.includes(key);
126
+ const fieldResult = jsonSchemaToZod(prop, !isRequired);
127
+ const propSchema = prop;
128
+ if (propSchema.description) {
129
+ fieldDescriptions[key] = propSchema.description;
130
+ }
131
+ if (!isRequired) {
132
+ zodFields[key] = fieldResult.optional();
133
+ } else {
134
+ zodFields[key] = fieldResult;
135
+ }
136
+ }
137
+ if (Object.keys(zodFields).length === 0) {
138
+ return schema.description ? z.unknown().describe(schema.description) : z.unknown();
139
+ }
140
+ const result = z.object(zodFields);
141
+ if (schema.description) {
142
+ return result.describe(schema.description);
143
+ }
144
+ return result;
145
+ }
146
+ function jsonSchemaToZod(prop, isOptional) {
147
+ const description = prop.description;
148
+ let baseType;
149
+ if (prop.nullable === true) {
150
+ const innerType = jsonSchemaToZod({ ...prop, nullable: undefined }, isOptional);
151
+ baseType = z.union([innerType, z.null()]);
152
+ if (description) {
153
+ return baseType.describe(description);
154
+ }
155
+ return baseType;
156
+ }
157
+ if (prop.anyOf || prop.oneOf) {
158
+ const unions = prop.anyOf || prop.oneOf || [];
159
+ const zodUnions = unions.map((s) => jsonSchemaToZod(s, false)).filter((t) => t);
160
+ if (zodUnions.length > 0) {
161
+ baseType = z.union(zodUnions);
162
+ if (description) {
163
+ return baseType.describe(description);
164
+ }
165
+ return baseType;
166
+ }
167
+ }
168
+ if (prop.allOf) {
169
+ const schemas = [];
170
+ for (const subSchema of prop.allOf) {
171
+ const sub = jsonSchemaToZod(subSchema, false);
172
+ schemas.push(sub);
173
+ }
174
+ if (schemas.length === 1) {
175
+ baseType = schemas[0];
176
+ } else {
177
+ baseType = z.intersection(schemas[0], schemas[1]);
178
+ for (let i = 2;i < schemas.length; i++) {
179
+ baseType = z.intersection(baseType, schemas[i]);
180
+ }
181
+ }
182
+ if (description) {
183
+ return baseType.describe(description);
184
+ }
185
+ return baseType;
186
+ }
187
+ const types = prop.types || (prop.type ? [prop.type] : []);
188
+ if (types.length > 1) {
189
+ const zodTypes = types.map((t) => getZodTypeForBasicType(t, prop)).filter((t) => t);
190
+ if (zodTypes.length > 0) {
191
+ baseType = z.union(zodTypes);
192
+ if (description) {
193
+ return baseType.describe(description);
194
+ }
195
+ return baseType;
196
+ }
197
+ }
198
+ const type = types[0];
199
+ if (!type) {
200
+ if (prop.enum) {
201
+ return handleEnum(prop, description);
202
+ }
203
+ baseType = z.unknown();
204
+ if (description) {
205
+ return baseType.describe(description);
206
+ }
207
+ return baseType;
208
+ }
209
+ baseType = getZodTypeForBasicType(type, prop);
210
+ if (description) {
211
+ const schemaDescription = baseType._def?.description;
212
+ if (schemaDescription) {
213
+ return baseType.describe(`${schemaDescription}. ${description}`);
214
+ }
215
+ return baseType.describe(description);
216
+ }
217
+ return baseType;
218
+ }
219
+ function getZodTypeForBasicType(type, prop) {
220
+ switch (type) {
221
+ case "string": {
222
+ if (prop.enum && prop.enum.length > 0 && prop.enum.every((v) => typeof v === "string")) {
223
+ return handleEnum(prop, prop.description);
224
+ }
225
+ let schema = z.string();
226
+ if (typeof prop.minLength === "number") {
227
+ schema = schema.min(prop.minLength);
228
+ }
229
+ if (typeof prop.maxLength === "number") {
230
+ schema = schema.max(prop.maxLength);
231
+ }
232
+ if (prop.pattern) {
233
+ try {
234
+ schema = schema.regex(new RegExp(prop.pattern));
235
+ } catch {}
236
+ }
237
+ if (prop.format) {
238
+ schema = schema.describe(`Format: ${prop.format}`);
239
+ }
240
+ if (prop.default !== undefined) {
241
+ schema = schema.default(prop.default);
242
+ }
243
+ return schema;
244
+ }
245
+ case "number":
246
+ case "integer": {
247
+ let schema = type === "integer" ? z.number().int() : z.number();
248
+ if (typeof prop.minimum === "number") {
249
+ schema = schema.min(prop.minimum);
250
+ }
251
+ if (typeof prop.maximum === "number") {
252
+ schema = schema.max(prop.maximum);
253
+ }
254
+ if (prop.default !== undefined) {
255
+ schema = schema.default(prop.default);
256
+ }
257
+ return schema;
258
+ }
259
+ case "boolean": {
260
+ let schema = z.boolean();
261
+ if (prop.default !== undefined) {
262
+ schema = schema.default(prop.default);
263
+ }
264
+ return schema;
265
+ }
266
+ case "array": {
267
+ let itemSchema = z.unknown();
268
+ if (prop.items) {
269
+ itemSchema = jsonSchemaToZod(prop.items, false);
270
+ }
271
+ let schema = z.array(itemSchema);
272
+ if (prop.additionalProperties && typeof prop.additionalProperties !== "boolean") {
273
+ const additionalItems = jsonSchemaToZod(prop.additionalProperties, false);
274
+ schema = z.array(z.union([itemSchema, additionalItems]));
275
+ }
276
+ return schema;
277
+ }
278
+ case "object": {
279
+ if (prop.properties) {
280
+ const fields = {};
281
+ const required = prop.required ?? [];
282
+ for (const [key, value] of Object.entries(prop.properties)) {
283
+ const isRequired = required.includes(key);
284
+ fields[key] = isRequired ? jsonSchemaToZod(value, false) : jsonSchemaToZod(value, true).optional();
285
+ }
286
+ return z.object(fields);
287
+ }
288
+ if (prop.additionalProperties) {
289
+ if (typeof prop.additionalProperties === "boolean") {
290
+ return z.record(z.string(), z.unknown());
291
+ }
292
+ return z.record(z.string(), jsonSchemaToZod(prop.additionalProperties, false));
293
+ }
294
+ return z.record(z.string(), z.unknown());
295
+ }
296
+ case "null":
297
+ return z.null();
298
+ case "null | string":
299
+ case "string | null":
300
+ return z.union([z.string(), z.null()]);
301
+ case "null | number":
302
+ case "number | null":
303
+ return z.union([z.number(), z.null()]);
304
+ default:
305
+ if (prop.enum) {
306
+ return handleEnum(prop);
307
+ }
308
+ return z.unknown();
309
+ }
310
+ }
311
+ function handleEnum(prop, existingDescription) {
312
+ if (!prop.enum || prop.enum.length === 0) {
313
+ return z.unknown();
314
+ }
315
+ const stringValues = prop.enum.filter((v) => typeof v === "string");
316
+ if (stringValues.length === 0) {
317
+ return z.any();
318
+ }
319
+ let schema;
320
+ if (stringValues.length === 1) {
321
+ schema = z.literal(stringValues[0]);
322
+ } else {
323
+ schema = z.enum([stringValues[0], ...stringValues.slice(1)]);
324
+ }
325
+ const valuesList = stringValues.map((v) => `"${v}"`).join(", ");
326
+ const valuesDescription = `Valid values: ${valuesList}`;
327
+ if (existingDescription) {
328
+ return schema.describe(`${existingDescription}. ${valuesDescription}`);
329
+ }
330
+ return schema.describe(valuesDescription);
331
+ }
332
+ function convertMcpCallResult(result) {
333
+ const content = result.content;
334
+ const textContent = content?.filter((c) => c.type === "text")?.map((c) => c.text)?.join("") ?? "";
335
+ return {
336
+ success: !result.isError,
337
+ output: textContent,
338
+ error: result.isError ? textContent : undefined
339
+ };
340
+ }
341
+ function createMcpToolsDescription(tools) {
342
+ if (tools.length === 0) {
343
+ return " No MCP tools currently available.";
344
+ }
345
+ return tools.map((t) => ` - ${t.name}: ${t.description}`).join(`
346
+ `);
347
+ }
348
+
349
+ export { adaptMcpTool, convertInputSchemaToZod, createMcpToolsDescription };
@@ -0,0 +1,117 @@
1
+ import {
2
+ __esm
3
+ } from "./roy-agent-core-fs0mn2jk.js";
4
+
5
+ // src/env/workflow/decorators/decorator-node.ts
6
+ class DecoratorNode {
7
+ type = "decorator";
8
+ id;
9
+ methodName;
10
+ instance;
11
+ dependsOn;
12
+ timeout;
13
+ retryConfig;
14
+ constructor(definition) {
15
+ const config = definition.config;
16
+ this.id = definition.id;
17
+ this.methodName = config._methodName;
18
+ this.instance = config._instance;
19
+ this.dependsOn = definition.depends_on || [];
20
+ this.timeout = definition.timeout;
21
+ this.retryConfig = definition.retry;
22
+ }
23
+ async execute(context) {
24
+ const startTime = Date.now();
25
+ const method = this.instance[this.methodName];
26
+ if (typeof method !== "function") {
27
+ return {
28
+ success: false,
29
+ error: `Method '${this.methodName}' is not a function`,
30
+ duration: Date.now() - startTime
31
+ };
32
+ }
33
+ const input = this.prepareInput(context);
34
+ const result = await this.executeWithRetry(input, context.abort);
35
+ return {
36
+ success: !result.error,
37
+ output: result.output,
38
+ error: result.error,
39
+ duration: Date.now() - startTime,
40
+ metadata: {
41
+ methodName: this.methodName
42
+ }
43
+ };
44
+ }
45
+ prepareInput(context) {
46
+ const nodeOutputs = context.nodeOutputs;
47
+ if (this.dependsOn.length === 0) {
48
+ return context.input || {};
49
+ }
50
+ const input = {};
51
+ for (const depId of this.dependsOn) {
52
+ const depOutput = nodeOutputs instanceof Map ? nodeOutputs.get(depId) : nodeOutputs?.[depId];
53
+ if (depOutput && typeof depOutput === "object") {
54
+ if ("output" in depOutput) {
55
+ input[depId] = depOutput.output;
56
+ } else {
57
+ input[depId] = depOutput;
58
+ }
59
+ }
60
+ }
61
+ return input;
62
+ }
63
+ async executeWithRetry(input, abort) {
64
+ const maxAttempts = this.retryConfig?.max_attempts ?? 1;
65
+ const backoff = this.retryConfig?.backoff ?? "exponential";
66
+ const initialDelay = this.retryConfig?.initial_delay ?? 1000;
67
+ let lastError;
68
+ for (let attempt = 1;attempt <= maxAttempts; attempt++) {
69
+ if (abort?.aborted) {
70
+ return { error: "Execution aborted" };
71
+ }
72
+ try {
73
+ const output = await this.executeWithTimeout(input, abort);
74
+ return { output };
75
+ } catch (error) {
76
+ lastError = error instanceof Error ? error : new Error(String(error));
77
+ if (attempt < maxAttempts) {
78
+ const delay = this.calculateBackoff(backoff, initialDelay, attempt - 1);
79
+ await this.sleep(delay, abort);
80
+ }
81
+ }
82
+ }
83
+ return { error: lastError?.message || "Unknown error" };
84
+ }
85
+ async executeWithTimeout(input, abort) {
86
+ if (!this.timeout) {
87
+ return this.instance[this.methodName](input);
88
+ }
89
+ const timeoutPromise = new Promise((_, reject) => {
90
+ setTimeout(() => {
91
+ reject(new Error(`Execution timeout after ${this.timeout}ms`));
92
+ }, this.timeout);
93
+ });
94
+ return Promise.race([
95
+ this.instance[this.methodName](input),
96
+ timeoutPromise
97
+ ]);
98
+ }
99
+ calculateBackoff(backoff, initialDelay, attempt) {
100
+ if (backoff === "exponential") {
101
+ return initialDelay * Math.pow(2, attempt);
102
+ }
103
+ return initialDelay;
104
+ }
105
+ sleep(ms, abort) {
106
+ return new Promise((resolve) => {
107
+ const timeout = setTimeout(resolve, ms);
108
+ abort?.addEventListener("abort", () => {
109
+ clearTimeout(timeout);
110
+ resolve();
111
+ });
112
+ });
113
+ }
114
+ }
115
+ var init_decorator_node = () => {};
116
+
117
+ export { DecoratorNode, init_decorator_node };
@@ -0,0 +1,11 @@
1
+ // src/env/hook/types.ts
2
+ function createHook(meta, fn) {
3
+ return {
4
+ ...meta,
5
+ execute: fn
6
+ };
7
+ }
8
+ function createPriorityHook(name, fn, priority) {
9
+ return createHook({ name, priority }, fn);
10
+ }
11
+ export { createHook, createPriorityHook };