@ai-setting/roy-agent-core 1.4.12 → 1.4.14

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 (127) hide show
  1. package/dist/packages/core/src/config/index.js +32 -0
  2. package/dist/packages/core/src/env/agent/index.js +24 -0
  3. package/dist/packages/core/src/env/commands/index.js +14 -0
  4. package/dist/packages/core/src/env/debug/formatters/index.js +11 -0
  5. package/dist/packages/core/src/env/debug/index.js +26 -0
  6. package/dist/packages/core/src/env/hook/index.js +29 -0
  7. package/dist/packages/core/src/env/index.js +81 -0
  8. package/dist/packages/core/src/env/llm/index.js +40 -0
  9. package/dist/packages/core/src/env/log-trace/index.js +83 -0
  10. package/dist/packages/core/src/env/mcp/index.js +39 -0
  11. package/dist/packages/core/src/env/mcp/tool/index.js +14 -0
  12. package/dist/packages/core/src/env/memory/built-in/index.js +11 -0
  13. package/dist/packages/core/src/env/memory/index.js +56 -0
  14. package/dist/packages/core/src/env/memory/plugin/index.js +36 -0
  15. package/dist/packages/core/src/env/prompt/index.js +20 -0
  16. package/dist/packages/core/src/env/session/index.js +25 -0
  17. package/dist/packages/core/src/env/session/storage/index.js +18 -0
  18. package/dist/packages/core/src/env/skill/index.js +34 -0
  19. package/dist/packages/core/src/env/skill/tool/index.js +9 -0
  20. package/dist/packages/core/src/env/task/delegate/index.js +18 -0
  21. package/dist/packages/core/src/env/task/hooks/index.js +7 -0
  22. package/dist/packages/core/src/env/task/index.js +30 -0
  23. package/dist/packages/core/src/env/task/plugins/index.js +23 -0
  24. package/dist/packages/core/src/env/task/storage/index.js +14 -0
  25. package/dist/packages/core/src/env/task/tools/index.js +17 -0
  26. package/dist/packages/core/src/env/task/tools/operation/index.js +15 -0
  27. package/dist/packages/core/src/env/tool/built-in/index.js +25 -0
  28. package/dist/packages/core/src/env/tool/index.js +39 -0
  29. package/dist/packages/core/src/env/workflow/decorators/index.js +27 -0
  30. package/dist/packages/core/src/env/workflow/engine/index.js +28 -0
  31. package/dist/packages/core/src/env/workflow/index.js +132 -0
  32. package/dist/packages/core/src/env/workflow/nodes/index.js +19 -0
  33. package/dist/packages/core/src/env/workflow/service/index.js +13 -0
  34. package/dist/packages/core/src/env/workflow/storage/index.js +27 -0
  35. package/dist/packages/core/src/env/workflow/tools/index.js +159 -0
  36. package/dist/packages/core/src/env/workflow/types/index.js +94 -0
  37. package/dist/packages/core/src/env/workflow/utils/index.js +637 -0
  38. package/dist/packages/core/src/index.js +398 -0
  39. package/dist/shared/@ai-setting/roy-agent-core-04fm8177.js +393 -0
  40. package/dist/shared/@ai-setting/roy-agent-core-04qgbjbe.js +172 -0
  41. package/dist/shared/@ai-setting/roy-agent-core-084qqd7t.js +11 -0
  42. package/dist/shared/@ai-setting/roy-agent-core-0gekht4e.js +1130 -0
  43. package/dist/shared/@ai-setting/roy-agent-core-0hdry23r.js +419 -0
  44. package/dist/shared/@ai-setting/roy-agent-core-0sgn3de4.js +102 -0
  45. package/dist/{env/task/tools/index.js → shared/@ai-setting/roy-agent-core-12x57kf1.js} +1 -59
  46. package/dist/shared/@ai-setting/roy-agent-core-1f3xrrm6.js +393 -0
  47. package/dist/shared/@ai-setting/roy-agent-core-1k28kg7h.js +368 -0
  48. package/dist/shared/@ai-setting/roy-agent-core-1z1zv5g8.js +258 -0
  49. package/dist/shared/@ai-setting/roy-agent-core-2hqxnaf3.js +851 -0
  50. package/dist/shared/@ai-setting/roy-agent-core-3dfq8awb.js +587 -0
  51. package/dist/shared/@ai-setting/roy-agent-core-3takar0s.js +93 -0
  52. package/dist/shared/@ai-setting/roy-agent-core-3tnb2005.js +117 -0
  53. package/dist/shared/@ai-setting/roy-agent-core-4vmcvkav.js +14 -0
  54. package/dist/shared/@ai-setting/roy-agent-core-4ws8atva.js +107 -0
  55. package/dist/{env/workflow/nodes/index.js → shared/@ai-setting/roy-agent-core-5fbp24se.js} +8 -55
  56. package/dist/shared/@ai-setting/roy-agent-core-5my94ywp.js +66 -0
  57. package/dist/shared/@ai-setting/roy-agent-core-6j0zcmwk.js +2146 -0
  58. package/dist/shared/@ai-setting/roy-agent-core-6w4pmxc7.js +266 -0
  59. package/dist/shared/@ai-setting/roy-agent-core-7vrk3add.js +10 -0
  60. package/dist/shared/@ai-setting/roy-agent-core-8dvbn7tw.js +64 -0
  61. package/dist/{env/memory/built-in/index.js → shared/@ai-setting/roy-agent-core-8mbmrwzs.js} +22 -76
  62. package/dist/shared/@ai-setting/roy-agent-core-8wzz66qe.js +620 -0
  63. package/dist/shared/@ai-setting/roy-agent-core-9ykq91jc.js +762 -0
  64. package/dist/shared/@ai-setting/roy-agent-core-dde19zke.js +1305 -0
  65. package/dist/shared/@ai-setting/roy-agent-core-f7g67gce.js +913 -0
  66. package/dist/{env/workflow/types/index.js → shared/@ai-setting/roy-agent-core-fq5mtxsy.js} +16 -154
  67. package/dist/{env/task/hooks/index.js → shared/@ai-setting/roy-agent-core-fs0mn2jk.js} +3 -18
  68. package/dist/{config/index.js → shared/@ai-setting/roy-agent-core-fvd9g6k8.js} +140 -605
  69. package/dist/shared/@ai-setting/roy-agent-core-gv1hrn3x.js +378 -0
  70. package/dist/{env/task/tools/operation/index.js → shared/@ai-setting/roy-agent-core-gy0wp5h7.js} +1 -58
  71. package/dist/shared/@ai-setting/roy-agent-core-hyza1gm7.js +15 -0
  72. package/dist/shared/@ai-setting/roy-agent-core-j8zx62zr.js +154 -0
  73. package/dist/shared/@ai-setting/roy-agent-core-jb2exr0d.js +442 -0
  74. package/dist/shared/@ai-setting/roy-agent-core-jv3b7v9w.js +57 -0
  75. package/dist/shared/@ai-setting/roy-agent-core-k1rxf9ya.js +513 -0
  76. package/dist/shared/@ai-setting/roy-agent-core-kydc9nwb.js +60 -0
  77. package/dist/shared/@ai-setting/roy-agent-core-m2x48hw6.js +97 -0
  78. package/dist/shared/@ai-setting/roy-agent-core-m6y668cc.js +377 -0
  79. package/dist/shared/@ai-setting/roy-agent-core-nczzf0ms.js +15 -0
  80. package/dist/shared/@ai-setting/roy-agent-core-nfj6knp5.js +36 -0
  81. package/dist/shared/@ai-setting/roy-agent-core-ntrp979d.js +204 -0
  82. package/dist/shared/@ai-setting/roy-agent-core-pd7g8z5v.js +1387 -0
  83. package/dist/shared/@ai-setting/roy-agent-core-pzk1syce.js +14 -0
  84. package/dist/shared/@ai-setting/roy-agent-core-q50tg9m2.js +862 -0
  85. package/dist/shared/@ai-setting/roy-agent-core-qg9tcaph.js +11 -0
  86. package/dist/shared/@ai-setting/roy-agent-core-qhyerewk.js +20 -0
  87. package/dist/shared/@ai-setting/roy-agent-core-qxybm159.js +82 -0
  88. package/dist/shared/@ai-setting/roy-agent-core-rh9dpkpw.js +549 -0
  89. package/dist/shared/@ai-setting/roy-agent-core-rr9p1g43.js +205 -0
  90. package/dist/{env/workflow/decorators/index.js → shared/@ai-setting/roy-agent-core-sbzvpfn7.js} +8 -173
  91. package/dist/shared/@ai-setting/roy-agent-core-t22nqt4d.js +788 -0
  92. package/dist/shared/@ai-setting/roy-agent-core-tkr5ynkh.js +200 -0
  93. package/dist/shared/@ai-setting/roy-agent-core-v4aabsf0.js +303 -0
  94. package/dist/{env/hook/index.js → shared/@ai-setting/roy-agent-core-w75rafhy.js} +3 -74
  95. package/dist/{env/debug/formatters/index.js → shared/@ai-setting/roy-agent-core-w76hqkmg.js} +11 -66
  96. package/dist/shared/@ai-setting/roy-agent-core-yfbgwes2.js +408 -0
  97. package/dist/shared/@ai-setting/roy-agent-core-yn761yve.js +299 -0
  98. package/dist/shared/@ai-setting/roy-agent-core-yrzmn4m1.js +492 -0
  99. package/dist/{env/workflow/service/index.js → shared/@ai-setting/roy-agent-core-yt8wdh2w.js} +1 -57
  100. package/package.json +3 -2
  101. package/dist/env/agent/index.js +0 -3035
  102. package/dist/env/commands/index.js +0 -1685
  103. package/dist/env/debug/index.js +0 -2300
  104. package/dist/env/index.js +0 -12591
  105. package/dist/env/llm/index.js +0 -2736
  106. package/dist/env/log-trace/index.js +0 -1779
  107. package/dist/env/mcp/index.js +0 -2173
  108. package/dist/env/mcp/tool/index.js +0 -1149
  109. package/dist/env/memory/index.js +0 -2171
  110. package/dist/env/memory/plugin/index.js +0 -1263
  111. package/dist/env/prompt/index.js +0 -2107
  112. package/dist/env/session/index.js +0 -3594
  113. package/dist/env/session/storage/index.js +0 -2049
  114. package/dist/env/skill/index.js +0 -1635
  115. package/dist/env/skill/tool/index.js +0 -114
  116. package/dist/env/task/delegate/index.js +0 -1844
  117. package/dist/env/task/index.js +0 -3578
  118. package/dist/env/task/plugins/index.js +0 -1626
  119. package/dist/env/task/storage/index.js +0 -1464
  120. package/dist/env/tool/built-in/index.js +0 -1151
  121. package/dist/env/tool/index.js +0 -2284
  122. package/dist/env/workflow/engine/index.js +0 -4391
  123. package/dist/env/workflow/index.js +0 -6214
  124. package/dist/env/workflow/storage/index.js +0 -1236
  125. package/dist/env/workflow/tools/index.js +0 -1081
  126. package/dist/env/workflow/utils/index.js +0 -1631
  127. package/dist/index.js +0 -22778
@@ -0,0 +1,442 @@
1
+ import {
2
+ AskUserError,
3
+ init_workflow_hil
4
+ } from "./roy-agent-core-8dvbn7tw.js";
5
+ import {
6
+ envKeyToConfigKey,
7
+ toEnvKey
8
+ } from "./roy-agent-core-jv3b7v9w.js";
9
+ import {
10
+ BaseComponent
11
+ } from "./roy-agent-core-m2x48hw6.js";
12
+ import {
13
+ ToolHookPoints,
14
+ globalHookManager
15
+ } from "./roy-agent-core-w75rafhy.js";
16
+ import {
17
+ createLogger,
18
+ init_logger
19
+ } from "./roy-agent-core-yn761yve.js";
20
+ import {
21
+ __require
22
+ } from "./roy-agent-core-fs0mn2jk.js";
23
+ // packages/core/src/env/tool/tool-component.ts
24
+ import { z } from "zod";
25
+
26
+ // packages/core/src/env/tool/registry.ts
27
+ class ToolRegistry {
28
+ tools = new Map;
29
+ register(tool, registration) {
30
+ this.tools.set(tool.name, registration);
31
+ }
32
+ unregister(name) {
33
+ return this.tools.delete(name);
34
+ }
35
+ getTool(name) {
36
+ return this.tools.get(name);
37
+ }
38
+ getAllTools() {
39
+ return Array.from(this.tools.values());
40
+ }
41
+ listTools(filter) {
42
+ let tools = this.getAllTools();
43
+ if (!filter) {
44
+ return tools.map((r) => r.tool);
45
+ }
46
+ if (filter.name) {
47
+ const names = Array.isArray(filter.name) ? filter.name : [filter.name];
48
+ tools = tools.filter((r) => names.some((pattern) => this.matchGlob(r.tool.name, pattern)));
49
+ }
50
+ if (filter.category) {
51
+ tools = tools.filter((r) => r.tool.metadata?.category === filter.category);
52
+ }
53
+ if (filter.tags && filter.tags.length > 0) {
54
+ tools = tools.filter((r) => filter.tags.some((tag) => r.tool.metadata?.tags?.includes(tag)));
55
+ }
56
+ if (filter.source) {
57
+ tools = tools.filter((r) => r.source === filter.source);
58
+ }
59
+ if (filter.enabledOnly) {
60
+ tools = tools.filter((r) => r.enabled);
61
+ }
62
+ if (filter.exclude && filter.exclude.length > 0) {
63
+ tools = tools.filter((r) => !filter.exclude.includes(r.tool.name));
64
+ }
65
+ return tools.map((r) => r.tool);
66
+ }
67
+ has(name) {
68
+ return this.tools.has(name);
69
+ }
70
+ getCount() {
71
+ return this.tools.size;
72
+ }
73
+ enable(name) {
74
+ const reg = this.tools.get(name);
75
+ if (reg) {
76
+ reg.enabled = true;
77
+ return true;
78
+ }
79
+ return false;
80
+ }
81
+ disable(name) {
82
+ const reg = this.tools.get(name);
83
+ if (reg) {
84
+ reg.enabled = false;
85
+ return true;
86
+ }
87
+ return false;
88
+ }
89
+ clear() {
90
+ this.tools.clear();
91
+ }
92
+ snapshot() {
93
+ return this.getAllTools();
94
+ }
95
+ restore(snapshot) {
96
+ this.clear();
97
+ for (const reg of snapshot) {
98
+ this.tools.set(reg.tool.name, reg);
99
+ }
100
+ }
101
+ matchGlob(str, pattern) {
102
+ if (pattern === "*")
103
+ return true;
104
+ if (!pattern.includes("*"))
105
+ return str === pattern;
106
+ const regexPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
107
+ return new RegExp(`^${regexPattern}$`).test(str);
108
+ }
109
+ }
110
+
111
+ // packages/core/src/env/tool/validator.ts
112
+ import { ZodError } from "zod";
113
+
114
+ class ToolValidator {
115
+ async validate(tool, args) {
116
+ try {
117
+ const parsed = await tool.parameters.parseAsync(args);
118
+ return {
119
+ success: true,
120
+ data: parsed
121
+ };
122
+ } catch (error) {
123
+ if (error instanceof ZodError) {
124
+ const errorMessage = tool.formatValidationError ? tool.formatValidationError(error) : this.formatError(error);
125
+ return {
126
+ success: false,
127
+ error: `Invalid arguments for tool '${tool.name}': ${errorMessage}`
128
+ };
129
+ }
130
+ return {
131
+ success: false,
132
+ error: `Validation error: ${error}`
133
+ };
134
+ }
135
+ }
136
+ formatError(error) {
137
+ return error.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join("; ");
138
+ }
139
+ }
140
+
141
+ // packages/core/src/env/tool/tool-component.ts
142
+ init_logger();
143
+
144
+ // packages/core/src/env/tool/tool-config-registration.ts
145
+ var TOOL_DEFAULTS = {
146
+ "tool.toolsDir": ".roy/tools",
147
+ "tool.builtInTools.enabled": true,
148
+ "tool.builtInTools.loadAll": true,
149
+ "tool.sandbox.enabled": false,
150
+ "tool.sandbox.type": "native",
151
+ "tool.execution.timeout": 30000,
152
+ "tool.execution.maxConcurrency": 5
153
+ };
154
+ var TOOL_CONFIG_REGISTRATION = {
155
+ name: "tool",
156
+ sources: [
157
+ { type: "env", envPrefix: "TOOL", priority: 20, watch: false }
158
+ ],
159
+ keys: [
160
+ { key: "tool.toolsDir", sources: ["env", "file"] },
161
+ { key: "tool.builtInTools.enabled", sources: ["env", "file"] },
162
+ { key: "tool.builtInTools.loadAll", sources: ["env", "file"] },
163
+ { key: "tool.sandbox.enabled", sources: ["env", "file"] },
164
+ { key: "tool.sandbox.type", sources: ["env", "file"] },
165
+ { key: "tool.execution.timeout", sources: ["env", "file"] },
166
+ { key: "tool.execution.maxConcurrency", sources: ["env", "file"] }
167
+ ]
168
+ };
169
+
170
+ // packages/core/src/env/tool/tool-component.ts
171
+ init_workflow_hil();
172
+ var logger = createLogger("tool");
173
+
174
+ class ToolComponent extends BaseComponent {
175
+ name = "tool";
176
+ version = "1.0.0";
177
+ registry;
178
+ validator;
179
+ config;
180
+ configComponent;
181
+ configWatcher;
182
+ constructor() {
183
+ super();
184
+ this.registry = new ToolRegistry;
185
+ this.validator = new ToolValidator;
186
+ }
187
+ async init(config) {
188
+ await super.init(config);
189
+ const options = config?.options;
190
+ if (!options?.configComponent) {
191
+ throw new Error("ConfigComponent is required for ToolComponent initialization");
192
+ }
193
+ this.configComponent = options.configComponent;
194
+ await this.registerConfig(options);
195
+ if (this.config?.builtInTools?.enabled !== false) {
196
+ await this.loadBuiltInTools();
197
+ }
198
+ logger.info(`ToolComponent initialized with ${this.getToolCount()} tools`);
199
+ }
200
+ async registerConfig(options) {
201
+ const configComponent = options.configComponent;
202
+ if (!configComponent)
203
+ return;
204
+ const { configPath, envPrefix, config } = options;
205
+ const prefix = envPrefix !== undefined ? envPrefix : "TOOL";
206
+ configComponent.registerComponent(TOOL_CONFIG_REGISTRATION);
207
+ if (configPath) {
208
+ configComponent.registerSource({
209
+ type: "file",
210
+ relativePath: configPath,
211
+ optional: true,
212
+ watch: false
213
+ });
214
+ }
215
+ await configComponent.load("tool");
216
+ const toolKeys = [
217
+ "tool.toolsDir",
218
+ "tool.builtInTools.enabled",
219
+ "tool.builtInTools.loadAll",
220
+ "tool.builtInTools.names",
221
+ "tool.sandbox.enabled",
222
+ "tool.sandbox.type",
223
+ "tool.sandbox.defaultConfig",
224
+ "tool.execution.timeout",
225
+ "tool.execution.maxConcurrency"
226
+ ];
227
+ for (const key of toolKeys) {
228
+ const envKey = toEnvKey(key, prefix);
229
+ const value = process.env[envKey];
230
+ if (value !== undefined) {
231
+ await configComponent.set(key, value);
232
+ }
233
+ }
234
+ const envPrefixUpper = prefix.toUpperCase();
235
+ for (const envKey of Object.keys(process.env)) {
236
+ if (!envKey.startsWith(envPrefixUpper + "_"))
237
+ continue;
238
+ const configKey = envKeyToConfigKey(envKey, prefix, "tool");
239
+ if (configKey && !toolKeys.includes(configKey)) {
240
+ const value = process.env[envKey];
241
+ if (value !== undefined) {
242
+ await configComponent.set(configKey, value);
243
+ }
244
+ }
245
+ }
246
+ for (const [key, value] of Object.entries(TOOL_DEFAULTS)) {
247
+ if (configComponent.get(key) === undefined) {
248
+ await configComponent.set(key, value);
249
+ }
250
+ }
251
+ if (config) {
252
+ const flatConfig = this.flattenConfig(config);
253
+ for (const [key, value] of Object.entries(flatConfig)) {
254
+ await configComponent.set(key, value);
255
+ }
256
+ }
257
+ this.registerConfigWatcher(configComponent);
258
+ const configData = {};
259
+ for (const key of toolKeys) {
260
+ const value = configComponent.get(key);
261
+ if (value !== undefined) {
262
+ configData[key.replace(/^tool\./, "")] = value;
263
+ }
264
+ }
265
+ if (config) {
266
+ Object.assign(configData, config);
267
+ }
268
+ const parsed = ToolComponentConfigSchema.safeParse(configData);
269
+ if (parsed.success) {
270
+ this.config = parsed.data;
271
+ } else {
272
+ this.config = config || {};
273
+ }
274
+ }
275
+ flattenConfig(obj, prefix = "tool") {
276
+ const result = {};
277
+ for (const [key, value] of Object.entries(obj)) {
278
+ const fullKey = `${prefix}.${key}`;
279
+ if (value && typeof value === "object" && !Array.isArray(value)) {
280
+ Object.assign(result, this.flattenConfig(value, fullKey));
281
+ } else {
282
+ result[fullKey] = value;
283
+ }
284
+ }
285
+ return result;
286
+ }
287
+ registerConfigWatcher(configComponent) {
288
+ if (typeof configComponent.watch !== "function") {
289
+ return;
290
+ }
291
+ this.configWatcher = configComponent.watch("tool.*", (event) => {
292
+ this.onConfigChange(event);
293
+ });
294
+ }
295
+ onConfigChange(event) {
296
+ logger.info(`Tool config changed: ${event.key}`, {
297
+ oldValue: event.oldValue,
298
+ newValue: event.newValue
299
+ });
300
+ }
301
+ async onStop() {
302
+ this.configWatcher?.();
303
+ this.configWatcher = undefined;
304
+ this.setStatus("stopped");
305
+ }
306
+ register(tool, source = "dynamic") {
307
+ globalHookManager.execute(ToolHookPoints.BEFORE_REGISTER, { tool });
308
+ this.registry.register(tool, {
309
+ tool,
310
+ registeredAt: Date.now(),
311
+ source,
312
+ enabled: true
313
+ });
314
+ logger.debug(`Registered tool: ${tool.name}`);
315
+ globalHookManager.execute(ToolHookPoints.AFTER_REGISTER, { tool });
316
+ }
317
+ registerMany(tools, source = "dynamic") {
318
+ for (const tool of tools) {
319
+ this.register(tool, source);
320
+ }
321
+ }
322
+ unregister(name) {
323
+ return this.registry.unregister(name);
324
+ }
325
+ getTool(name) {
326
+ return this.registry.getTool(name)?.tool;
327
+ }
328
+ listTools(filter) {
329
+ return this.registry.listTools(filter);
330
+ }
331
+ getToolCount() {
332
+ return this.registry.getCount();
333
+ }
334
+ hasTool(name) {
335
+ return this.registry.has(name);
336
+ }
337
+ getToolsByCategory(category) {
338
+ return this.listTools({ category });
339
+ }
340
+ async execute(request) {
341
+ const { name, args, context, skipHooks } = request;
342
+ const registration = this.registry.getTool(name);
343
+ if (!registration) {
344
+ return {
345
+ success: false,
346
+ output: "",
347
+ error: `Tool not found: ${name}`
348
+ };
349
+ }
350
+ if (!registration.enabled) {
351
+ return {
352
+ success: false,
353
+ output: "",
354
+ error: `Tool disabled: ${name}`
355
+ };
356
+ }
357
+ const tool = registration.tool;
358
+ if (!skipHooks) {
359
+ await globalHookManager.execute(ToolHookPoints.BEFORE_EXECUTE, { tool, args, context }, { toolName: tool.name });
360
+ }
361
+ const startTime = Date.now();
362
+ try {
363
+ const validationResult = await this.validator.validate(tool, args);
364
+ if (!validationResult.success) {
365
+ return {
366
+ success: false,
367
+ output: "",
368
+ error: validationResult.error,
369
+ metadata: {
370
+ execution_time_ms: Date.now() - startTime
371
+ }
372
+ };
373
+ }
374
+ const result = await tool.execute(validationResult.data, context);
375
+ if (!result.metadata) {
376
+ result.metadata = { execution_time_ms: Date.now() - startTime };
377
+ } else {
378
+ result.metadata.execution_time_ms = Date.now() - startTime;
379
+ }
380
+ if (!skipHooks) {
381
+ await globalHookManager.execute(ToolHookPoints.AFTER_EXECUTE, { tool, args, context, result }, { toolName: tool.name });
382
+ }
383
+ return result;
384
+ } catch (error) {
385
+ if (error instanceof AskUserError) {
386
+ throw error;
387
+ }
388
+ const errorResult = {
389
+ success: false,
390
+ output: "",
391
+ error: error instanceof Error ? error.message : String(error),
392
+ metadata: {
393
+ execution_time_ms: Date.now() - startTime
394
+ }
395
+ };
396
+ if (!skipHooks) {
397
+ await globalHookManager.execute(ToolHookPoints.AFTER_EXECUTE, { tool, args, context, result: errorResult }, { toolName: tool.name });
398
+ }
399
+ if (!skipHooks) {
400
+ await globalHookManager.execute(ToolHookPoints.ON_ERROR, { tool, args, context, error }, { toolName: tool.name });
401
+ }
402
+ return errorResult;
403
+ }
404
+ }
405
+ async loadBuiltInTools() {
406
+ try {
407
+ const { getAllBuiltInTools } = await import("../../packages/core/src/env/tool/built-in/index.js");
408
+ const tools = getAllBuiltInTools();
409
+ this.registerMany(tools, "built-in");
410
+ logger.info(`Loaded ${tools.length} built-in tools`);
411
+ } catch (err) {
412
+ logger.warn(`Failed to load built-in tools: ${err.message}`);
413
+ }
414
+ }
415
+ getHookPoints() {
416
+ return [
417
+ ToolHookPoints.BEFORE_EXECUTE,
418
+ ToolHookPoints.AFTER_EXECUTE,
419
+ ToolHookPoints.BEFORE_REGISTER,
420
+ ToolHookPoints.AFTER_REGISTER,
421
+ ToolHookPoints.ON_ERROR
422
+ ];
423
+ }
424
+ }
425
+ var ToolComponentConfigSchema = z.object({
426
+ toolsDir: z.string().optional(),
427
+ builtInTools: z.object({
428
+ enabled: z.boolean().default(true),
429
+ loadAll: z.boolean().default(true),
430
+ names: z.array(z.string()).optional()
431
+ }).default({}),
432
+ sandbox: z.object({
433
+ enabled: z.boolean().default(false),
434
+ type: z.enum(["native", "docker"]).default("native"),
435
+ defaultConfig: z.record(z.unknown()).optional()
436
+ }).default({}),
437
+ execution: z.object({
438
+ timeout: z.number().int().positive().default(60000),
439
+ maxConcurrency: z.number().int().positive().default(4)
440
+ }).default({})
441
+ });
442
+ export { ToolRegistry, ToolValidator, ToolComponent };
@@ -0,0 +1,57 @@
1
+ // packages/core/src/config/env-key.ts
2
+ function toEnvKey(key, prefix) {
3
+ let keyNormalized = key.replace(/[.-]/g, "_");
4
+ keyNormalized = keyNormalized.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/_+/g, "_").toUpperCase();
5
+ if (prefix) {
6
+ const separator = prefix.endsWith("_") ? "" : "_";
7
+ return `${prefix}${separator}${keyNormalized}`;
8
+ }
9
+ return keyNormalized;
10
+ }
11
+ function fromEnvKey(envKey, prefix) {
12
+ if (!prefix) {
13
+ return envKey;
14
+ }
15
+ if (envKey.startsWith(prefix)) {
16
+ const afterPrefix = envKey.slice(prefix.length);
17
+ if (afterPrefix.startsWith("_")) {
18
+ return afterPrefix.slice(1);
19
+ }
20
+ return afterPrefix;
21
+ }
22
+ return envKey;
23
+ }
24
+ function envKeyToConfigKey(envKey, prefix, componentName) {
25
+ const prefixUpper = prefix.toUpperCase();
26
+ if (!envKey.startsWith(prefixUpper)) {
27
+ return;
28
+ }
29
+ const componentUpperNormalized = componentName.replace(/-/g, "_").toUpperCase();
30
+ let keyPart = envKey.slice(prefixUpper.length);
31
+ if (keyPart.startsWith("_")) {
32
+ keyPart = keyPart.slice(1);
33
+ }
34
+ if (!keyPart) {
35
+ return;
36
+ }
37
+ const firstUnderscore = keyPart.indexOf("_");
38
+ let restPart;
39
+ if (firstUnderscore === -1) {
40
+ restPart = keyPart;
41
+ } else {
42
+ const firstPart = keyPart.slice(0, firstUnderscore);
43
+ const remaining = keyPart.slice(firstUnderscore + 1);
44
+ if (firstPart === componentUpperNormalized) {
45
+ restPart = remaining;
46
+ } else {
47
+ restPart = keyPart;
48
+ }
49
+ }
50
+ if (!restPart) {
51
+ return;
52
+ }
53
+ const restPartConverted = restPart.replace(/_/g, ".");
54
+ return `${componentName}.${restPartConverted.toLowerCase()}`;
55
+ }
56
+
57
+ export { toEnvKey, fromEnvKey, envKeyToConfigKey };