@ai-setting/roy-agent-core 1.5.13-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,176 +0,0 @@
1
- import {
2
- __esm,
3
- __require
4
- } from "./roy-agent-core-fs0mn2jk.js";
5
-
6
- // src/env/log-trace/span-storage.ts
7
- function getDatabaseClass() {
8
- if (typeof Bun !== "undefined") {
9
- const { Database } = __require("bun:sqlite");
10
- return Database;
11
- } else {
12
- return __require("better-sqlite3");
13
- }
14
- }
15
- function createCompatibleDatabase(path) {
16
- const Database = getDatabaseClass();
17
- const db = new Database(path);
18
- if (typeof db.run !== "function") {
19
- db.run = function(sql, ...params) {
20
- if (params.length > 0) {
21
- return this.prepare(sql).run(...params);
22
- } else {
23
- return this.exec(sql);
24
- }
25
- };
26
- }
27
- return db;
28
- }
29
-
30
- class SQLiteSpanStorage {
31
- db = null;
32
- dbPath;
33
- initialized = false;
34
- constructor(dbPath) {
35
- if (!dbPath) {
36
- throw new Error("SQLiteSpanStorage requires a valid dbPath parameter");
37
- }
38
- if (dbPath === ":memory:") {
39
- throw new Error("SQLiteSpanStorage does not support :memory: mode. Use a file path instead.");
40
- }
41
- this.dbPath = dbPath;
42
- }
43
- async initialize() {
44
- if (this.initialized)
45
- return;
46
- const fs = __require("fs");
47
- const path = __require("path");
48
- const dir = path.dirname(this.dbPath);
49
- if (!fs.existsSync(dir)) {
50
- fs.mkdirSync(dir, { recursive: true });
51
- }
52
- this.db = createCompatibleDatabase(this.dbPath);
53
- this.db.run("PRAGMA journal_mode=WAL");
54
- this.db.run("PRAGMA busy_timeout=5000");
55
- this.db.run("PRAGMA synchronous=NORMAL");
56
- this.db.run(`
57
- CREATE TABLE IF NOT EXISTS span (
58
- span_id TEXT PRIMARY KEY,
59
- trace_id TEXT NOT NULL,
60
- parent_span_id TEXT,
61
- name TEXT NOT NULL,
62
- kind TEXT NOT NULL,
63
- status TEXT NOT NULL,
64
- start_time INTEGER NOT NULL,
65
- end_time INTEGER,
66
- attributes TEXT,
67
- result TEXT,
68
- error TEXT,
69
- time_created INTEGER NOT NULL
70
- )
71
- `);
72
- this.db.run("CREATE INDEX IF NOT EXISTS idx_span_trace ON span(trace_id)");
73
- this.db.run("CREATE INDEX IF NOT EXISTS idx_span_parent ON span(parent_span_id)");
74
- this.initialized = true;
75
- }
76
- save(span) {
77
- if (!this.db)
78
- return;
79
- const stmt = this.db.prepare(`
80
- INSERT OR REPLACE INTO span
81
- (span_id, trace_id, parent_span_id, name, kind, status, start_time, end_time, attributes, result, error, time_created)
82
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
83
- `);
84
- const resultValue = span.result !== undefined && span.result !== null ? typeof span.result === "string" ? span.result : JSON.stringify(span.result) : null;
85
- stmt.run(span.spanId, span.traceId, span.parentSpanId || null, span.name, span.kind, span.status, span.startTime, span.endTime || null, JSON.stringify(span.attributes), resultValue, span.error || null, Date.now());
86
- }
87
- saveBatch(spans) {
88
- for (const span of spans) {
89
- this.save(span);
90
- }
91
- }
92
- findByTraceId(traceId) {
93
- if (!this.db)
94
- return [];
95
- const rows = this.db.prepare("SELECT * FROM span WHERE trace_id = ?").all(traceId);
96
- return this.buildTree(rows.map(this.rowToSpan));
97
- }
98
- findBySpanId(spanId) {
99
- if (!this.db)
100
- return;
101
- const row = this.db.prepare("SELECT * FROM span WHERE span_id = ?").get(spanId);
102
- return row ? this.rowToSpan(row) : undefined;
103
- }
104
- listTraces(limit = 10) {
105
- if (!this.db)
106
- return [];
107
- const rows = this.db.prepare(`
108
- SELECT trace_id,
109
- MIN(start_time) as start_time,
110
- MAX(end_time) as end_time,
111
- COUNT(*) as span_count
112
- FROM span
113
- GROUP BY trace_id
114
- ORDER BY start_time DESC
115
- LIMIT ?
116
- `).all(limit);
117
- return rows.map((row) => ({
118
- traceId: row.trace_id,
119
- rootSpanName: "unknown",
120
- startTime: row.start_time,
121
- endTime: row.end_time,
122
- duration: row.end_time - row.start_time,
123
- spanCount: row.span_count,
124
- status: "ok"
125
- }));
126
- }
127
- deleteByTraceId(traceId) {
128
- if (this.db) {
129
- this.db.prepare("DELETE FROM span WHERE trace_id = ?").run(traceId);
130
- }
131
- }
132
- close() {
133
- if (this.db) {
134
- this.db.close();
135
- this.db = null;
136
- }
137
- }
138
- rowToSpan(row) {
139
- return {
140
- traceId: row.trace_id,
141
- spanId: row.span_id,
142
- parentSpanId: row.parent_span_id,
143
- name: row.name,
144
- kind: row.kind,
145
- status: row.status,
146
- startTime: row.start_time,
147
- endTime: row.end_time,
148
- attributes: row.attributes ? JSON.parse(row.attributes) : {},
149
- result: row.result || undefined,
150
- error: row.error || undefined
151
- };
152
- }
153
- buildTree(spans) {
154
- const spanMap = new Map;
155
- const roots = [];
156
- for (const span of spans) {
157
- spanMap.set(span.spanId, { ...span, children: [] });
158
- }
159
- for (const span of spanMap.values()) {
160
- if (span.parentSpanId) {
161
- const parent = spanMap.get(span.parentSpanId);
162
- if (parent) {
163
- parent.children.push(span);
164
- } else {
165
- roots.push(span);
166
- }
167
- } else {
168
- roots.push(span);
169
- }
170
- }
171
- return roots;
172
- }
173
- }
174
- var init_span_storage = () => {};
175
-
176
- export { SQLiteSpanStorage, init_span_storage };
@@ -1,60 +0,0 @@
1
- // src/env/skill/types.ts
2
- import { z } from "zod";
3
- var SkillToolSchema = z.object({
4
- skill: z.string().describe("Skill name to load")
5
- });
6
-
7
- // src/env/skill/tool/skill-tool.ts
8
- function buildSkillDescription(items) {
9
- const lines = [
10
- "Load a skill by name. Available skills:",
11
- "",
12
- "## Available Skills",
13
- ""
14
- ];
15
- if (items.length === 0) {
16
- lines.push("No skills available.");
17
- } else {
18
- for (const item of items) {
19
- lines.push(`- **${item.name}**: "${item.description}"`);
20
- }
21
- }
22
- lines.push("");
23
- lines.push("Use the 'skill' parameter to specify which skill to load.");
24
- return lines.join(`
25
- `);
26
- }
27
- function createSkillTool(getSkillList, getSkill) {
28
- return {
29
- name: "skill",
30
- description: buildSkillDescription(getSkillList()),
31
- parameters: SkillToolSchema,
32
- execute: async (args, ctx) => {
33
- const params = SkillToolSchema.parse(args);
34
- try {
35
- const entry = getSkill(params.skill);
36
- if (!entry) {
37
- return {
38
- success: false,
39
- output: "",
40
- error: `Skill not found: ${params.skill}`,
41
- metadata: { execution_time_ms: 0 }
42
- };
43
- }
44
- return {
45
- success: true,
46
- output: entry.content,
47
- metadata: { execution_time_ms: 0 }
48
- };
49
- } catch (error) {
50
- return {
51
- success: false,
52
- output: "",
53
- error: error instanceof Error ? error.message : String(error),
54
- metadata: { execution_time_ms: 0 }
55
- };
56
- }
57
- }
58
- };
59
- }
60
- export { SkillToolSchema, buildSkillDescription, createSkillTool };
@@ -1,442 +0,0 @@
1
- import {
2
- AskUserError,
3
- init_workflow_hil
4
- } from "./roy-agent-core-e25xkv53.js";
5
- import {
6
- envKeyToConfigKey,
7
- toEnvKey
8
- } from "./roy-agent-core-qxhq8ven.js";
9
- import {
10
- BaseComponent
11
- } from "./roy-agent-core-kkbwepqb.js";
12
- import {
13
- ToolHookPoints,
14
- globalHookManager
15
- } from "./roy-agent-core-gjq1yk68.js";
16
- import {
17
- createLogger,
18
- init_logger
19
- } from "./roy-agent-core-44hnfb02.js";
20
- import {
21
- __require
22
- } from "./roy-agent-core-fs0mn2jk.js";
23
- // src/env/tool/tool-component.ts
24
- import { z } from "zod";
25
-
26
- // 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
- // 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
- // src/env/tool/tool-component.ts
142
- init_logger();
143
-
144
- // 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
- // 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("../../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 };