@ai-setting/roy-agent-core 1.4.11 → 1.4.12
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.
- package/dist/config/index.js +23 -0
- package/dist/env/agent/index.js +3035 -0
- package/dist/env/commands/index.js +1685 -0
- package/dist/env/debug/formatters/index.js +639 -0
- package/dist/env/debug/index.js +2300 -0
- package/dist/env/hook/index.js +273 -0
- package/dist/env/index.js +12591 -0
- package/dist/env/llm/index.js +2736 -0
- package/dist/env/log-trace/index.js +1779 -0
- package/dist/env/mcp/index.js +2173 -0
- package/dist/env/mcp/tool/index.js +1149 -0
- package/dist/env/memory/built-in/index.js +225 -0
- package/dist/env/memory/index.js +2171 -0
- package/dist/env/memory/plugin/index.js +1263 -0
- package/dist/env/prompt/index.js +2107 -0
- package/dist/env/session/index.js +3594 -0
- package/dist/env/session/storage/index.js +2049 -0
- package/dist/env/skill/index.js +1635 -0
- package/dist/env/skill/tool/index.js +114 -0
- package/dist/env/task/delegate/index.js +1844 -0
- package/dist/env/task/hooks/index.js +67 -0
- package/dist/env/task/index.js +3578 -0
- package/dist/env/task/plugins/index.js +1626 -0
- package/dist/env/task/storage/index.js +1464 -0
- package/dist/env/task/tools/index.js +344 -0
- package/dist/env/task/tools/operation/index.js +270 -0
- package/dist/env/tool/built-in/index.js +1151 -0
- package/dist/env/tool/index.js +2284 -0
- package/dist/env/workflow/decorators/index.js +449 -0
- package/dist/env/workflow/engine/index.js +4391 -0
- package/dist/env/workflow/index.js +6214 -0
- package/dist/env/workflow/nodes/index.js +650 -0
- package/dist/env/workflow/service/index.js +262 -0
- package/dist/env/workflow/storage/index.js +1236 -0
- package/dist/env/workflow/tools/index.js +1081 -0
- package/dist/env/workflow/types/index.js +479 -0
- package/dist/env/workflow/utils/index.js +1631 -0
- package/dist/index.js +15006 -14265
- package/package.json +2 -2
|
@@ -0,0 +1,2284 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
function __accessProp(key) {
|
|
7
|
+
return this[key];
|
|
8
|
+
}
|
|
9
|
+
var __toCommonJS = (from) => {
|
|
10
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
11
|
+
if (entry)
|
|
12
|
+
return entry;
|
|
13
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (var key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(entry, key))
|
|
17
|
+
__defProp(entry, key, {
|
|
18
|
+
get: __accessProp.bind(from, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
__moduleCache.set(from, entry);
|
|
23
|
+
return entry;
|
|
24
|
+
};
|
|
25
|
+
var __moduleCache;
|
|
26
|
+
var __returnValue = (v) => v;
|
|
27
|
+
function __exportSetter(name, newValue) {
|
|
28
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
29
|
+
}
|
|
30
|
+
var __export = (target, all) => {
|
|
31
|
+
for (var name in all)
|
|
32
|
+
__defProp(target, name, {
|
|
33
|
+
get: all[name],
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
set: __exportSetter.bind(all, name)
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
40
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
41
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
42
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
43
|
+
else
|
|
44
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
45
|
+
if (d = decorators[i])
|
|
46
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
47
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
48
|
+
};
|
|
49
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
50
|
+
var __require = import.meta.require;
|
|
51
|
+
|
|
52
|
+
// packages/core/src/env/log-trace/opentelemetry/propagation.ts
|
|
53
|
+
function padLeft(str, length) {
|
|
54
|
+
return str.padStart(length, "0");
|
|
55
|
+
}
|
|
56
|
+
function isValidHex(str) {
|
|
57
|
+
return /^[0-9a-f]+$/i.test(str);
|
|
58
|
+
}
|
|
59
|
+
function serialize(context) {
|
|
60
|
+
const traceId = padLeft(context.traceId.toLowerCase(), TRACE_ID_LENGTH);
|
|
61
|
+
const spanId = padLeft(context.spanId.toLowerCase(), PARENT_SPAN_ID_LENGTH);
|
|
62
|
+
const parts = [
|
|
63
|
+
TRACE_CONTEXT_VERSION,
|
|
64
|
+
traceId,
|
|
65
|
+
spanId,
|
|
66
|
+
TRACE_FLAGS_SAMPLED
|
|
67
|
+
];
|
|
68
|
+
return parts.join("-");
|
|
69
|
+
}
|
|
70
|
+
function parse(traceparent) {
|
|
71
|
+
if (!traceparent || typeof traceparent !== "string") {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const trimmed = traceparent.trim();
|
|
75
|
+
const parts = trimmed.split("-");
|
|
76
|
+
if (parts.length !== 4) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const [version, traceId, senderSpanId, flags] = parts;
|
|
80
|
+
if (version !== TRACE_CONTEXT_VERSION) {
|
|
81
|
+
if (version > TRACE_CONTEXT_VERSION) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (traceId.length !== TRACE_ID_LENGTH || !isValidHex(traceId)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (senderSpanId.length !== PARENT_SPAN_ID_LENGTH || !isValidHex(senderSpanId)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (flags.length !== FLAGS_LENGTH || !isValidHex(flags)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
traceId: traceId.toLowerCase(),
|
|
96
|
+
spanId: senderSpanId.toLowerCase()
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
var TRACE_CONTEXT_VERSION = "00", TRACE_FLAGS_SAMPLED = "01", TRACEPARENT_HEADER = "TRACEPARENT", TRACE_ID_LENGTH = 32, PARENT_SPAN_ID_LENGTH = 16, FLAGS_LENGTH = 2, propagation;
|
|
100
|
+
var init_propagation = __esm(() => {
|
|
101
|
+
propagation = {
|
|
102
|
+
inject(carrier, context) {
|
|
103
|
+
carrier[TRACEPARENT_HEADER] = serialize(context);
|
|
104
|
+
},
|
|
105
|
+
extract(carrier) {
|
|
106
|
+
const traceparent = carrier[TRACEPARENT_HEADER];
|
|
107
|
+
if (!traceparent) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
return parse(traceparent);
|
|
111
|
+
},
|
|
112
|
+
getTraceparentHeader() {
|
|
113
|
+
return TRACEPARENT_HEADER;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// packages/core/src/env/log-trace/span-storage.ts
|
|
119
|
+
var exports_span_storage = {};
|
|
120
|
+
__export(exports_span_storage, {
|
|
121
|
+
SQLiteSpanStorage: () => SQLiteSpanStorage
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
class SQLiteSpanStorage {
|
|
125
|
+
db = null;
|
|
126
|
+
dbPath;
|
|
127
|
+
initialized = false;
|
|
128
|
+
constructor(dbPath) {
|
|
129
|
+
if (!dbPath) {
|
|
130
|
+
throw new Error("SQLiteSpanStorage requires a valid dbPath parameter");
|
|
131
|
+
}
|
|
132
|
+
if (dbPath === ":memory:") {
|
|
133
|
+
throw new Error("SQLiteSpanStorage does not support :memory: mode. Use a file path instead.");
|
|
134
|
+
}
|
|
135
|
+
this.dbPath = dbPath;
|
|
136
|
+
}
|
|
137
|
+
async initialize() {
|
|
138
|
+
if (this.initialized)
|
|
139
|
+
return;
|
|
140
|
+
const { Database } = __require("bun:sqlite");
|
|
141
|
+
const fs = __require("fs");
|
|
142
|
+
const path = __require("path");
|
|
143
|
+
const dir = path.dirname(this.dbPath);
|
|
144
|
+
if (!fs.existsSync(dir)) {
|
|
145
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
146
|
+
}
|
|
147
|
+
this.db = new Database(this.dbPath);
|
|
148
|
+
this.db.run("PRAGMA journal_mode=WAL");
|
|
149
|
+
this.db.run("PRAGMA busy_timeout=5000");
|
|
150
|
+
this.db.run("PRAGMA synchronous=NORMAL");
|
|
151
|
+
this.db.run(`
|
|
152
|
+
CREATE TABLE IF NOT EXISTS span (
|
|
153
|
+
span_id TEXT PRIMARY KEY,
|
|
154
|
+
trace_id TEXT NOT NULL,
|
|
155
|
+
parent_span_id TEXT,
|
|
156
|
+
name TEXT NOT NULL,
|
|
157
|
+
kind TEXT NOT NULL,
|
|
158
|
+
status TEXT NOT NULL,
|
|
159
|
+
start_time INTEGER NOT NULL,
|
|
160
|
+
end_time INTEGER,
|
|
161
|
+
attributes TEXT,
|
|
162
|
+
result TEXT,
|
|
163
|
+
error TEXT,
|
|
164
|
+
time_created INTEGER NOT NULL
|
|
165
|
+
)
|
|
166
|
+
`);
|
|
167
|
+
this.db.run("CREATE INDEX IF NOT EXISTS idx_span_trace ON span(trace_id)");
|
|
168
|
+
this.db.run("CREATE INDEX IF NOT EXISTS idx_span_parent ON span(parent_span_id)");
|
|
169
|
+
this.initialized = true;
|
|
170
|
+
}
|
|
171
|
+
save(span) {
|
|
172
|
+
if (!this.db)
|
|
173
|
+
return;
|
|
174
|
+
const stmt = this.db.prepare(`
|
|
175
|
+
INSERT OR REPLACE INTO span
|
|
176
|
+
(span_id, trace_id, parent_span_id, name, kind, status, start_time, end_time, attributes, result, error, time_created)
|
|
177
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
178
|
+
`);
|
|
179
|
+
const resultValue = span.result !== undefined && span.result !== null ? typeof span.result === "string" ? span.result : JSON.stringify(span.result) : null;
|
|
180
|
+
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());
|
|
181
|
+
}
|
|
182
|
+
saveBatch(spans) {
|
|
183
|
+
for (const span of spans) {
|
|
184
|
+
this.save(span);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
findByTraceId(traceId) {
|
|
188
|
+
if (!this.db)
|
|
189
|
+
return [];
|
|
190
|
+
const rows = this.db.prepare("SELECT * FROM span WHERE trace_id = ?").all(traceId);
|
|
191
|
+
return this.buildTree(rows.map(this.rowToSpan));
|
|
192
|
+
}
|
|
193
|
+
findBySpanId(spanId) {
|
|
194
|
+
if (!this.db)
|
|
195
|
+
return;
|
|
196
|
+
const row = this.db.prepare("SELECT * FROM span WHERE span_id = ?").get(spanId);
|
|
197
|
+
return row ? this.rowToSpan(row) : undefined;
|
|
198
|
+
}
|
|
199
|
+
listTraces(limit = 10) {
|
|
200
|
+
if (!this.db)
|
|
201
|
+
return [];
|
|
202
|
+
const rows = this.db.prepare(`
|
|
203
|
+
SELECT trace_id,
|
|
204
|
+
MIN(start_time) as start_time,
|
|
205
|
+
MAX(end_time) as end_time,
|
|
206
|
+
COUNT(*) as span_count
|
|
207
|
+
FROM span
|
|
208
|
+
GROUP BY trace_id
|
|
209
|
+
ORDER BY start_time DESC
|
|
210
|
+
LIMIT ?
|
|
211
|
+
`).all(limit);
|
|
212
|
+
return rows.map((row) => ({
|
|
213
|
+
traceId: row.trace_id,
|
|
214
|
+
rootSpanName: "unknown",
|
|
215
|
+
startTime: row.start_time,
|
|
216
|
+
endTime: row.end_time,
|
|
217
|
+
duration: row.end_time - row.start_time,
|
|
218
|
+
spanCount: row.span_count,
|
|
219
|
+
status: "ok"
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
deleteByTraceId(traceId) {
|
|
223
|
+
if (this.db) {
|
|
224
|
+
this.db.prepare("DELETE FROM span WHERE trace_id = ?").run(traceId);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
close() {
|
|
228
|
+
if (this.db) {
|
|
229
|
+
this.db.close();
|
|
230
|
+
this.db = null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
rowToSpan(row) {
|
|
234
|
+
return {
|
|
235
|
+
traceId: row.trace_id,
|
|
236
|
+
spanId: row.span_id,
|
|
237
|
+
parentSpanId: row.parent_span_id,
|
|
238
|
+
name: row.name,
|
|
239
|
+
kind: row.kind,
|
|
240
|
+
status: row.status,
|
|
241
|
+
startTime: row.start_time,
|
|
242
|
+
endTime: row.end_time,
|
|
243
|
+
attributes: row.attributes ? JSON.parse(row.attributes) : {},
|
|
244
|
+
result: row.result || undefined,
|
|
245
|
+
error: row.error || undefined
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
buildTree(spans) {
|
|
249
|
+
const spanMap = new Map;
|
|
250
|
+
const roots = [];
|
|
251
|
+
for (const span of spans) {
|
|
252
|
+
spanMap.set(span.spanId, { ...span, children: [] });
|
|
253
|
+
}
|
|
254
|
+
for (const span of spanMap.values()) {
|
|
255
|
+
if (span.parentSpanId) {
|
|
256
|
+
const parent = spanMap.get(span.parentSpanId);
|
|
257
|
+
if (parent) {
|
|
258
|
+
parent.children.push(span);
|
|
259
|
+
} else {
|
|
260
|
+
roots.push(span);
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
roots.push(span);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return roots;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// packages/core/src/env/log-trace/types.ts
|
|
271
|
+
var SpanKind, SpanStatus;
|
|
272
|
+
var init_types = __esm(() => {
|
|
273
|
+
((SpanKind2) => {
|
|
274
|
+
SpanKind2["CLIENT"] = "client";
|
|
275
|
+
SpanKind2["SERVER"] = "server";
|
|
276
|
+
SpanKind2["INTERNAL"] = "internal";
|
|
277
|
+
})(SpanKind ||= {});
|
|
278
|
+
((SpanStatus2) => {
|
|
279
|
+
SpanStatus2["OK"] = "ok";
|
|
280
|
+
SpanStatus2["ERROR"] = "error";
|
|
281
|
+
})(SpanStatus ||= {});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// packages/core/src/env/log-trace/opentelemetry/tracer-provider.ts
|
|
285
|
+
var exports_tracer_provider = {};
|
|
286
|
+
__export(exports_tracer_provider, {
|
|
287
|
+
resetTracerProvider: () => resetTracerProvider,
|
|
288
|
+
getTracerProvider: () => getTracerProvider,
|
|
289
|
+
OTelTracerProvider: () => OTelTracerProvider
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
class OTelSpanImpl {
|
|
293
|
+
name;
|
|
294
|
+
kind;
|
|
295
|
+
spanContext;
|
|
296
|
+
attributes = {};
|
|
297
|
+
startTime;
|
|
298
|
+
endTime;
|
|
299
|
+
error;
|
|
300
|
+
storage;
|
|
301
|
+
parentSpanContext;
|
|
302
|
+
onEnd;
|
|
303
|
+
constructor(name, spanContext, storage, parentSpanContext, onEnd) {
|
|
304
|
+
this.name = name;
|
|
305
|
+
this.kind = "internal";
|
|
306
|
+
this.spanContext = spanContext;
|
|
307
|
+
this.parentSpanContext = parentSpanContext;
|
|
308
|
+
this.startTime = Date.now();
|
|
309
|
+
this.storage = storage;
|
|
310
|
+
this.onEnd = onEnd;
|
|
311
|
+
}
|
|
312
|
+
setAttribute(key, value) {
|
|
313
|
+
this.attributes[key] = value;
|
|
314
|
+
}
|
|
315
|
+
addEvent(name, attributes) {
|
|
316
|
+
const events = this.attributes._events || [];
|
|
317
|
+
events.push({ name, attributes });
|
|
318
|
+
this.attributes._events = events;
|
|
319
|
+
}
|
|
320
|
+
end(result, error) {
|
|
321
|
+
this.endTime = Date.now();
|
|
322
|
+
if (error) {
|
|
323
|
+
this.error = error.message;
|
|
324
|
+
}
|
|
325
|
+
this.storage.save({
|
|
326
|
+
traceId: this.spanContext.traceId,
|
|
327
|
+
spanId: this.spanContext.spanId,
|
|
328
|
+
parentSpanId: this.spanContext.parentSpanId,
|
|
329
|
+
name: this.name,
|
|
330
|
+
kind: this.kind,
|
|
331
|
+
status: error ? "error" /* ERROR */ : "ok" /* OK */,
|
|
332
|
+
startTime: this.startTime,
|
|
333
|
+
endTime: this.endTime,
|
|
334
|
+
attributes: this.attributes,
|
|
335
|
+
result,
|
|
336
|
+
error: this.error
|
|
337
|
+
});
|
|
338
|
+
this.onEnd?.();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
class OTelTracerImpl {
|
|
343
|
+
name;
|
|
344
|
+
version;
|
|
345
|
+
storage;
|
|
346
|
+
currentContext;
|
|
347
|
+
activeSpans = new Map;
|
|
348
|
+
onSpanEndCallback;
|
|
349
|
+
provider;
|
|
350
|
+
constructor(name, version, storage, provider) {
|
|
351
|
+
this.name = name;
|
|
352
|
+
this.version = version;
|
|
353
|
+
this.storage = storage;
|
|
354
|
+
this.provider = provider;
|
|
355
|
+
}
|
|
356
|
+
setOnSpanEndCallback(callback) {
|
|
357
|
+
this.onSpanEndCallback = callback;
|
|
358
|
+
}
|
|
359
|
+
getActiveSpanCount() {
|
|
360
|
+
return this.activeSpans.size;
|
|
361
|
+
}
|
|
362
|
+
startSpan(name, options) {
|
|
363
|
+
const parentFromOptions = options?.parent;
|
|
364
|
+
const hasExplicitParent = options && "parent" in options;
|
|
365
|
+
const globalContext = this.provider.getGlobalContext();
|
|
366
|
+
let effectiveParentContext;
|
|
367
|
+
if (hasExplicitParent) {
|
|
368
|
+
effectiveParentContext = parentFromOptions;
|
|
369
|
+
} else if (this.currentContext) {
|
|
370
|
+
effectiveParentContext = this.currentContext;
|
|
371
|
+
} else if (globalContext) {
|
|
372
|
+
effectiveParentContext = globalContext;
|
|
373
|
+
}
|
|
374
|
+
const traceId = effectiveParentContext?.traceId || this.generateTraceId();
|
|
375
|
+
const spanId = this.generateSpanId();
|
|
376
|
+
let parentSpanId;
|
|
377
|
+
if (hasExplicitParent && parentFromOptions) {
|
|
378
|
+
parentSpanId = parentFromOptions.parentSpanId || parentFromOptions.spanId;
|
|
379
|
+
} else if (this.currentContext) {
|
|
380
|
+
parentSpanId = this.currentContext.spanId;
|
|
381
|
+
} else if (globalContext) {
|
|
382
|
+
parentSpanId = globalContext.spanId;
|
|
383
|
+
}
|
|
384
|
+
const spanContext = {
|
|
385
|
+
traceId,
|
|
386
|
+
spanId,
|
|
387
|
+
parentSpanId
|
|
388
|
+
};
|
|
389
|
+
this.currentContext = {
|
|
390
|
+
traceId,
|
|
391
|
+
spanId,
|
|
392
|
+
parentSpanId
|
|
393
|
+
};
|
|
394
|
+
const span = new OTelSpanImpl(name, spanContext, this.storage, effectiveParentContext, () => this.handleSpanEnd(spanContext.spanId, effectiveParentContext?.spanId));
|
|
395
|
+
if (options?.attributes) {
|
|
396
|
+
for (const [key, value] of Object.entries(options.attributes)) {
|
|
397
|
+
span.setAttribute(key, value);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
this.activeSpans.set(spanId, span);
|
|
401
|
+
return span;
|
|
402
|
+
}
|
|
403
|
+
injectToEnv(env) {
|
|
404
|
+
if (this.currentContext) {
|
|
405
|
+
propagation.inject(env, this.currentContext);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
getCurrentContext() {
|
|
409
|
+
return this.currentContext;
|
|
410
|
+
}
|
|
411
|
+
setCurrentContext(context) {
|
|
412
|
+
this.currentContext = context;
|
|
413
|
+
}
|
|
414
|
+
endSpan(span) {
|
|
415
|
+
const spanContext = span.spanContext;
|
|
416
|
+
this.activeSpans.delete(spanContext.spanId);
|
|
417
|
+
const currentTraceId = this.currentContext?.traceId;
|
|
418
|
+
if (spanContext.parentSpanId) {
|
|
419
|
+
const parentSpan = this.activeSpans.get(spanContext.parentSpanId);
|
|
420
|
+
if (parentSpan) {
|
|
421
|
+
const parentContext = {
|
|
422
|
+
traceId: spanContext.traceId,
|
|
423
|
+
spanId: parentSpan.spanContext.spanId,
|
|
424
|
+
parentSpanId: parentSpan.spanContext.parentSpanId
|
|
425
|
+
};
|
|
426
|
+
this.currentContext = parentContext;
|
|
427
|
+
return parentContext;
|
|
428
|
+
}
|
|
429
|
+
if (currentTraceId) {
|
|
430
|
+
const parentContext = {
|
|
431
|
+
traceId: currentTraceId,
|
|
432
|
+
spanId: spanContext.parentSpanId,
|
|
433
|
+
parentSpanId: undefined
|
|
434
|
+
};
|
|
435
|
+
this.currentContext = parentContext;
|
|
436
|
+
return parentContext;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
this.currentContext = undefined;
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
generateTraceId() {
|
|
443
|
+
const timestamp = Date.now().toString(16).padStart(12, "0");
|
|
444
|
+
const random = Array.from({ length: 5 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("");
|
|
445
|
+
return (timestamp + random).slice(0, 32).padStart(32, "0");
|
|
446
|
+
}
|
|
447
|
+
generateSpanId() {
|
|
448
|
+
return Math.floor(Math.random() * 18446744073709552000).toString(16).padStart(16, "0");
|
|
449
|
+
}
|
|
450
|
+
handleSpanEnd(spanId, parentSpanId) {
|
|
451
|
+
this.activeSpans.delete(spanId);
|
|
452
|
+
const currentTraceId = this.currentContext?.traceId;
|
|
453
|
+
if (parentSpanId) {
|
|
454
|
+
const parentSpan = this.activeSpans.get(parentSpanId);
|
|
455
|
+
if (parentSpan) {
|
|
456
|
+
this.currentContext = {
|
|
457
|
+
traceId: parentSpan.spanContext.traceId,
|
|
458
|
+
spanId: parentSpan.spanContext.spanId,
|
|
459
|
+
parentSpanId: parentSpan.spanContext.parentSpanId
|
|
460
|
+
};
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (currentTraceId) {
|
|
464
|
+
this.currentContext = {
|
|
465
|
+
traceId: currentTraceId,
|
|
466
|
+
spanId: parentSpanId,
|
|
467
|
+
parentSpanId: undefined
|
|
468
|
+
};
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
this.currentContext = undefined;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
class OTelTracerProvider {
|
|
477
|
+
tracers = new Map;
|
|
478
|
+
storage;
|
|
479
|
+
initialized = false;
|
|
480
|
+
globalContext;
|
|
481
|
+
constructor(storage, dbPath) {
|
|
482
|
+
this.storage = storage || new SQLiteSpanStorage(dbPath || getDefaultDbPath());
|
|
483
|
+
}
|
|
484
|
+
async initialize() {
|
|
485
|
+
if (this.initialized)
|
|
486
|
+
return;
|
|
487
|
+
await this.storage.initialize();
|
|
488
|
+
this.initialized = true;
|
|
489
|
+
}
|
|
490
|
+
isInitialized() {
|
|
491
|
+
return this.initialized;
|
|
492
|
+
}
|
|
493
|
+
getGlobalContext() {
|
|
494
|
+
return this.globalContext;
|
|
495
|
+
}
|
|
496
|
+
setGlobalContext(context) {
|
|
497
|
+
this.globalContext = context;
|
|
498
|
+
}
|
|
499
|
+
getTracer(name, version) {
|
|
500
|
+
const key = `${name}@${version || "0.0.0"}`;
|
|
501
|
+
let tracer = this.tracers.get(key);
|
|
502
|
+
if (!tracer) {
|
|
503
|
+
tracer = new OTelTracerImpl(name, version, this.storage, this);
|
|
504
|
+
this.tracers.set(key, tracer);
|
|
505
|
+
if (this.initialized) {
|
|
506
|
+
this.restoreFromEnv(tracer);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return tracer;
|
|
510
|
+
}
|
|
511
|
+
restoreFromEnv(tracer) {
|
|
512
|
+
const extracted = propagation.extract(process.env);
|
|
513
|
+
if (extracted) {
|
|
514
|
+
tracer.setCurrentContext({
|
|
515
|
+
traceId: extracted.traceId,
|
|
516
|
+
spanId: extracted.spanId,
|
|
517
|
+
parentSpanId: undefined
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
shutdown() {
|
|
522
|
+
for (const tracer of this.tracers.values()) {}
|
|
523
|
+
this.tracers.clear();
|
|
524
|
+
this.storage.close();
|
|
525
|
+
this.initialized = false;
|
|
526
|
+
this.globalContext = undefined;
|
|
527
|
+
delete process.env["TRACEPARENT"];
|
|
528
|
+
delete process.env["TRACE_ID"];
|
|
529
|
+
delete process.env["LOG_TRACE_REQUEST_ID"];
|
|
530
|
+
}
|
|
531
|
+
getStorage() {
|
|
532
|
+
return this.storage;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
function getTracerProvider() {
|
|
536
|
+
if (!providerInstance) {
|
|
537
|
+
providerInstance = new OTelTracerProvider;
|
|
538
|
+
}
|
|
539
|
+
return providerInstance;
|
|
540
|
+
}
|
|
541
|
+
function resetTracerProvider() {
|
|
542
|
+
if (providerInstance) {
|
|
543
|
+
providerInstance.shutdown();
|
|
544
|
+
providerInstance = null;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
function getDefaultDbPath() {
|
|
548
|
+
const os = __require("os");
|
|
549
|
+
const path = __require("path");
|
|
550
|
+
const home = os.homedir();
|
|
551
|
+
const dataHome = process.env.XDG_DATA_HOME || path.join(home, ".local", "share");
|
|
552
|
+
return path.join(dataHome, "roy-agent", "traces.db");
|
|
553
|
+
}
|
|
554
|
+
var providerInstance = null;
|
|
555
|
+
var init_tracer_provider = __esm(() => {
|
|
556
|
+
init_propagation();
|
|
557
|
+
init_types();
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
// packages/core/src/env/tool/built-in/bash.ts
|
|
561
|
+
import { z } from "zod";
|
|
562
|
+
import { exec } from "child_process";
|
|
563
|
+
import { promisify } from "util";
|
|
564
|
+
function getCurrentSpanContext() {
|
|
565
|
+
try {
|
|
566
|
+
const { getTracerProvider: getTracerProvider2 } = (init_tracer_provider(), __toCommonJS(exports_tracer_provider));
|
|
567
|
+
const provider = getTracerProvider2();
|
|
568
|
+
if (!provider.isInitialized()) {
|
|
569
|
+
throw new Error("Provider not initialized");
|
|
570
|
+
}
|
|
571
|
+
const tracer = provider.getTracer("roy-tracer");
|
|
572
|
+
const ctx = tracer.getCurrentContext();
|
|
573
|
+
if (ctx && ctx.traceId && ctx.spanId) {
|
|
574
|
+
return ctx;
|
|
575
|
+
}
|
|
576
|
+
} catch {}
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
function getCurrentTraceId() {
|
|
580
|
+
const ctx = getCurrentSpanContext();
|
|
581
|
+
if (ctx) {
|
|
582
|
+
return ctx.traceId;
|
|
583
|
+
}
|
|
584
|
+
return process.env.TRACE_ID;
|
|
585
|
+
}
|
|
586
|
+
var execAsync, bashTool;
|
|
587
|
+
var init_bash = __esm(() => {
|
|
588
|
+
init_propagation();
|
|
589
|
+
execAsync = promisify(exec);
|
|
590
|
+
bashTool = {
|
|
591
|
+
name: "bash",
|
|
592
|
+
description: "Execute shell commands in the terminal. Use this to run system commands, scripts, or interact with the file system.",
|
|
593
|
+
parameters: z.object({
|
|
594
|
+
command: z.string().describe("The shell command to execute"),
|
|
595
|
+
workdir: z.string().optional().describe("Working directory for the command"),
|
|
596
|
+
timeout: z.number().int().positive().optional().describe("Timeout in milliseconds"),
|
|
597
|
+
env: z.record(z.string()).optional().describe("Additional environment variables")
|
|
598
|
+
}),
|
|
599
|
+
sandbox: {
|
|
600
|
+
enabled: true,
|
|
601
|
+
config: {
|
|
602
|
+
filesystem: {
|
|
603
|
+
denyRead: ["/etc/shadow", "/etc/sudoers", "/etc/sudoers.d/*"],
|
|
604
|
+
denyWrite: ["/etc", "/usr/bin", "/usr/sbin", "/bin", "/sbin"]
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
},
|
|
608
|
+
permission: {
|
|
609
|
+
requireConfirmation: true,
|
|
610
|
+
level: "dangerous"
|
|
611
|
+
},
|
|
612
|
+
metadata: {
|
|
613
|
+
category: "system",
|
|
614
|
+
tags: ["shell", "command", "terminal", "exec"],
|
|
615
|
+
version: "1.2.0"
|
|
616
|
+
},
|
|
617
|
+
execute: async (args, ctx) => {
|
|
618
|
+
const startTime = Date.now();
|
|
619
|
+
const { command, workdir, timeout = 60000, env } = args;
|
|
620
|
+
const currentSpanCtx = getCurrentSpanContext();
|
|
621
|
+
const traceId = currentSpanCtx?.traceId || getCurrentTraceId();
|
|
622
|
+
const options = {
|
|
623
|
+
timeout
|
|
624
|
+
};
|
|
625
|
+
if (workdir || ctx.workdir) {
|
|
626
|
+
options.cwd = workdir || ctx.workdir;
|
|
627
|
+
}
|
|
628
|
+
const childEnv = {};
|
|
629
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
630
|
+
if (value !== undefined) {
|
|
631
|
+
childEnv[key] = value;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
if (currentSpanCtx) {
|
|
635
|
+
const carrier = {};
|
|
636
|
+
propagation.inject(carrier, currentSpanCtx);
|
|
637
|
+
if (carrier["TRACEPARENT"]) {
|
|
638
|
+
childEnv["TRACEPARENT"] = carrier["TRACEPARENT"];
|
|
639
|
+
}
|
|
640
|
+
childEnv["TRACE_ID"] = currentSpanCtx.traceId;
|
|
641
|
+
childEnv["PARENT_SPAN_ID"] = currentSpanCtx.spanId;
|
|
642
|
+
} else if (traceId) {
|
|
643
|
+
const spanId2 = Math.floor(Math.random() * 18446744073709552000).toString(16).padStart(16, "0");
|
|
644
|
+
childEnv["TRACEPARENT"] = `00-${traceId}-${spanId2}-01`;
|
|
645
|
+
childEnv["TRACE_ID"] = traceId;
|
|
646
|
+
}
|
|
647
|
+
if (env) {
|
|
648
|
+
Object.assign(childEnv, env);
|
|
649
|
+
}
|
|
650
|
+
options.env = childEnv;
|
|
651
|
+
let otelSpan = undefined;
|
|
652
|
+
try {
|
|
653
|
+
const { getTracerProvider: getTracerProvider2 } = (init_tracer_provider(), __toCommonJS(exports_tracer_provider));
|
|
654
|
+
const provider = getTracerProvider2();
|
|
655
|
+
const tracer = provider.getTracer("roy-tracer");
|
|
656
|
+
otelSpan = tracer.startSpan(`bash: ${command.slice(0, 50)}${command.length > 50 ? "..." : ""}`, {
|
|
657
|
+
attributes: {
|
|
658
|
+
"bash.command": command.slice(0, 200),
|
|
659
|
+
"bash.workdir": workdir || ctx.workdir || "",
|
|
660
|
+
"bash.timeout": timeout
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
} catch {}
|
|
664
|
+
const spanId = otelSpan?.spanContext?.spanId;
|
|
665
|
+
try {
|
|
666
|
+
const { stdout, stderr } = await execAsync(command, options);
|
|
667
|
+
if (otelSpan) {
|
|
668
|
+
otelSpan.end({ stdout, stderr });
|
|
669
|
+
}
|
|
670
|
+
return {
|
|
671
|
+
success: true,
|
|
672
|
+
output: stdout || "(no output)",
|
|
673
|
+
metadata: {
|
|
674
|
+
execution_time_ms: Date.now() - startTime,
|
|
675
|
+
stdout,
|
|
676
|
+
stderr,
|
|
677
|
+
exit_code: 0,
|
|
678
|
+
trace_id: traceId,
|
|
679
|
+
parent_span_id: currentSpanCtx?.spanId,
|
|
680
|
+
span_id: spanId
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
} catch (error) {
|
|
684
|
+
const exitCode = error.code || 1;
|
|
685
|
+
const stdout = error.stdout || "";
|
|
686
|
+
const stderr = error.stderr || error.message;
|
|
687
|
+
const execError = new Error(stderr);
|
|
688
|
+
execError.name = "BashExecutionError";
|
|
689
|
+
if (otelSpan) {
|
|
690
|
+
otelSpan.end(undefined, execError);
|
|
691
|
+
}
|
|
692
|
+
return {
|
|
693
|
+
success: exitCode === 0,
|
|
694
|
+
output: stdout || "(no output)",
|
|
695
|
+
error: stderr,
|
|
696
|
+
metadata: {
|
|
697
|
+
execution_time_ms: Date.now() - startTime,
|
|
698
|
+
stdout,
|
|
699
|
+
stderr,
|
|
700
|
+
exit_code: exitCode,
|
|
701
|
+
trace_id: traceId,
|
|
702
|
+
parent_span_id: currentSpanCtx?.spanId,
|
|
703
|
+
span_id: spanId
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
// packages/core/src/env/tool/built-in/echo.ts
|
|
712
|
+
var echoTool;
|
|
713
|
+
var init_echo = __esm(() => {
|
|
714
|
+
echoTool = {
|
|
715
|
+
name: "echo",
|
|
716
|
+
description: "Echo a message to the console. Useful for logging in workflows.",
|
|
717
|
+
parameters: {
|
|
718
|
+
name: "message",
|
|
719
|
+
schema: {
|
|
720
|
+
type: "string",
|
|
721
|
+
description: "The message to echo"
|
|
722
|
+
}
|
|
723
|
+
},
|
|
724
|
+
execute: async (args, _ctx) => {
|
|
725
|
+
const message = args?.message || "(no message)";
|
|
726
|
+
return {
|
|
727
|
+
success: true,
|
|
728
|
+
output: message,
|
|
729
|
+
metadata: {
|
|
730
|
+
execution_time_ms: 0
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
// packages/core/src/env/tool/built-in/glob.ts
|
|
738
|
+
import { z as z2 } from "zod";
|
|
739
|
+
import { glob as globAsync } from "glob";
|
|
740
|
+
var globTool;
|
|
741
|
+
var init_glob = __esm(() => {
|
|
742
|
+
globTool = {
|
|
743
|
+
name: "glob",
|
|
744
|
+
description: "Search for files matching a glob pattern. Use this to find files by name patterns like **/*.ts or **/*.md.",
|
|
745
|
+
parameters: z2.object({
|
|
746
|
+
pattern: z2.string().describe("Glob pattern to match (e.g., **/*.ts, **/*.md)"),
|
|
747
|
+
cwd: z2.string().optional().describe("Working directory to search in"),
|
|
748
|
+
maxResults: z2.number().int().positive().optional().describe("Maximum number of results to return"),
|
|
749
|
+
ignore: z2.array(z2.string()).optional().describe("Patterns to ignore")
|
|
750
|
+
}),
|
|
751
|
+
sandbox: {
|
|
752
|
+
enabled: true
|
|
753
|
+
},
|
|
754
|
+
metadata: {
|
|
755
|
+
category: "file",
|
|
756
|
+
tags: ["search", "file", "glob", "pattern"],
|
|
757
|
+
version: "1.0.0"
|
|
758
|
+
},
|
|
759
|
+
execute: async (args, ctx) => {
|
|
760
|
+
const startTime = Date.now();
|
|
761
|
+
const { pattern, cwd, maxResults = 100, ignore } = args;
|
|
762
|
+
const searchDir = cwd || ctx.workdir || process.cwd();
|
|
763
|
+
try {
|
|
764
|
+
const files = await globAsync(pattern, {
|
|
765
|
+
cwd: searchDir,
|
|
766
|
+
ignore: ignore || ["**/node_modules/**", "**/.git/**"],
|
|
767
|
+
maxDepth: 20
|
|
768
|
+
});
|
|
769
|
+
const limitedFiles = files.slice(0, maxResults);
|
|
770
|
+
const output = limitedFiles.join(`
|
|
771
|
+
`);
|
|
772
|
+
return {
|
|
773
|
+
success: true,
|
|
774
|
+
output,
|
|
775
|
+
metadata: {
|
|
776
|
+
execution_time_ms: Date.now() - startTime,
|
|
777
|
+
output_size: output.length,
|
|
778
|
+
total_matches: files.length,
|
|
779
|
+
returned_matches: limitedFiles.length
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
} catch (error) {
|
|
783
|
+
return {
|
|
784
|
+
success: false,
|
|
785
|
+
output: "",
|
|
786
|
+
error: error instanceof Error ? error.message : String(error),
|
|
787
|
+
metadata: {
|
|
788
|
+
execution_time_ms: Date.now() - startTime
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
// packages/core/src/env/tool/built-in/read-file.ts
|
|
797
|
+
import { z as z3 } from "zod";
|
|
798
|
+
import { readFile } from "fs/promises";
|
|
799
|
+
var readFileTool;
|
|
800
|
+
var init_read_file = __esm(() => {
|
|
801
|
+
readFileTool = {
|
|
802
|
+
name: "read_file",
|
|
803
|
+
description: "Read the contents of a file. Use this to read source code, configuration files, or any text files.",
|
|
804
|
+
parameters: z3.object({
|
|
805
|
+
path: z3.string().describe("The file path to read"),
|
|
806
|
+
offset: z3.number().int().nonnegative().optional().describe("Line offset to start reading from"),
|
|
807
|
+
limit: z3.number().int().positive().optional().describe("Number of lines to read"),
|
|
808
|
+
encoding: z3.enum(["utf-8", "base64"]).default("utf-8").optional().describe("File encoding")
|
|
809
|
+
}),
|
|
810
|
+
sandbox: {
|
|
811
|
+
enabled: true,
|
|
812
|
+
config: {
|
|
813
|
+
filesystem: {
|
|
814
|
+
denyRead: ["/etc/shadow", "/etc/sudoers", "/root/.ssh"]
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
permission: {
|
|
819
|
+
level: "safe"
|
|
820
|
+
},
|
|
821
|
+
metadata: {
|
|
822
|
+
category: "file",
|
|
823
|
+
tags: ["read", "file", "io"],
|
|
824
|
+
version: "1.0.0"
|
|
825
|
+
},
|
|
826
|
+
execute: async (args, ctx) => {
|
|
827
|
+
const startTime = Date.now();
|
|
828
|
+
const { path: filePath, offset, limit, encoding = "utf-8" } = args;
|
|
829
|
+
try {
|
|
830
|
+
const content = await readFile(filePath, encoding);
|
|
831
|
+
let output;
|
|
832
|
+
const contentBuffer = content;
|
|
833
|
+
const contentStr = typeof contentBuffer === "string" ? contentBuffer : contentBuffer.toString(encoding);
|
|
834
|
+
if (offset !== undefined || limit !== undefined) {
|
|
835
|
+
const lines = contentStr.split(`
|
|
836
|
+
`);
|
|
837
|
+
const startLine = offset || 0;
|
|
838
|
+
const endLine = limit ? startLine + limit : lines.length;
|
|
839
|
+
output = lines.slice(startLine, endLine).join(`
|
|
840
|
+
`);
|
|
841
|
+
} else {
|
|
842
|
+
output = contentStr;
|
|
843
|
+
}
|
|
844
|
+
return {
|
|
845
|
+
success: true,
|
|
846
|
+
output,
|
|
847
|
+
metadata: {
|
|
848
|
+
execution_time_ms: Date.now() - startTime,
|
|
849
|
+
output_size: output.length,
|
|
850
|
+
file_path: filePath
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
} catch (error) {
|
|
854
|
+
return {
|
|
855
|
+
success: false,
|
|
856
|
+
output: "",
|
|
857
|
+
error: error instanceof Error ? error.message : String(error),
|
|
858
|
+
metadata: {
|
|
859
|
+
execution_time_ms: Date.now() - startTime
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
// packages/core/src/env/tool/built-in/write-file.ts
|
|
868
|
+
import { z as z4 } from "zod";
|
|
869
|
+
import { writeFile, mkdir } from "fs/promises";
|
|
870
|
+
import { dirname } from "path";
|
|
871
|
+
var writeFileTool;
|
|
872
|
+
var init_write_file = __esm(() => {
|
|
873
|
+
writeFileTool = {
|
|
874
|
+
name: "write_file",
|
|
875
|
+
description: "Write content to a file. Use this to create new files or overwrite existing ones.",
|
|
876
|
+
parameters: z4.object({
|
|
877
|
+
path: z4.string().describe("The file path to write to"),
|
|
878
|
+
content: z4.string().describe("The content to write"),
|
|
879
|
+
createDirs: z4.boolean().default(false).optional().describe("Create parent directories if they don't exist"),
|
|
880
|
+
append: z4.boolean().default(false).optional().describe("Append to file instead of overwrite")
|
|
881
|
+
}),
|
|
882
|
+
sandbox: {
|
|
883
|
+
enabled: true,
|
|
884
|
+
config: {
|
|
885
|
+
filesystem: {
|
|
886
|
+
denyWrite: ["/etc", "/usr", "/bin", "/sbin", "/boot", "/sys"]
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
},
|
|
890
|
+
permission: {
|
|
891
|
+
requireConfirmation: true,
|
|
892
|
+
level: "dangerous"
|
|
893
|
+
},
|
|
894
|
+
metadata: {
|
|
895
|
+
category: "file",
|
|
896
|
+
tags: ["write", "file", "io", "create"],
|
|
897
|
+
version: "1.0.0"
|
|
898
|
+
},
|
|
899
|
+
execute: async (args, ctx) => {
|
|
900
|
+
const startTime = Date.now();
|
|
901
|
+
const { path: filePath, content, createDirs = false, append = false } = args;
|
|
902
|
+
try {
|
|
903
|
+
if (createDirs) {
|
|
904
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
905
|
+
}
|
|
906
|
+
const flags = append ? "a" : "w";
|
|
907
|
+
await writeFile(filePath, content, { flag: flags });
|
|
908
|
+
return {
|
|
909
|
+
success: true,
|
|
910
|
+
output: append ? `Content appended to: ${filePath}` : `File written: ${filePath}`,
|
|
911
|
+
metadata: {
|
|
912
|
+
execution_time_ms: Date.now() - startTime,
|
|
913
|
+
output_size: content.length,
|
|
914
|
+
file_path: filePath
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
} catch (error) {
|
|
918
|
+
return {
|
|
919
|
+
success: false,
|
|
920
|
+
output: "",
|
|
921
|
+
error: error instanceof Error ? error.message : String(error),
|
|
922
|
+
metadata: {
|
|
923
|
+
execution_time_ms: Date.now() - startTime
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
// packages/core/src/env/tool/built-in/edit-file.ts
|
|
932
|
+
import { z as z5 } from "zod";
|
|
933
|
+
import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
934
|
+
function escapeRegExp(string) {
|
|
935
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
936
|
+
}
|
|
937
|
+
var editFileTool;
|
|
938
|
+
var init_edit_file = __esm(() => {
|
|
939
|
+
editFileTool = {
|
|
940
|
+
name: "edit_file",
|
|
941
|
+
description: "Edit a file by replacing specific text. Use this to make targeted changes to files by specifying what to find and what to replace.",
|
|
942
|
+
parameters: z5.object({
|
|
943
|
+
path: z5.string().describe("The file path to edit"),
|
|
944
|
+
oldString: z5.string().describe("The text to find and replace"),
|
|
945
|
+
newString: z5.string().describe("The replacement text"),
|
|
946
|
+
replaceAll: z5.boolean().default(false).optional().describe("Replace all occurrences instead of just the first")
|
|
947
|
+
}),
|
|
948
|
+
sandbox: {
|
|
949
|
+
enabled: true,
|
|
950
|
+
config: {
|
|
951
|
+
filesystem: {
|
|
952
|
+
denyWrite: ["/etc", "/usr/bin", "/usr/sbin", "/bin", "/sbin"]
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
},
|
|
956
|
+
permission: {
|
|
957
|
+
requireConfirmation: true,
|
|
958
|
+
level: "dangerous"
|
|
959
|
+
},
|
|
960
|
+
metadata: {
|
|
961
|
+
category: "file",
|
|
962
|
+
tags: ["edit", "file", "replace", "modify"],
|
|
963
|
+
version: "1.0.0"
|
|
964
|
+
},
|
|
965
|
+
execute: async (args, ctx) => {
|
|
966
|
+
const startTime = Date.now();
|
|
967
|
+
const { path: filePath, oldString, newString, replaceAll = false } = args;
|
|
968
|
+
try {
|
|
969
|
+
const content = await readFile2(filePath, "utf-8");
|
|
970
|
+
const searchPattern = replaceAll ? new RegExp(escapeRegExp(oldString), "g") : new RegExp(escapeRegExp(oldString));
|
|
971
|
+
if (!searchPattern.test(content)) {
|
|
972
|
+
return {
|
|
973
|
+
success: false,
|
|
974
|
+
output: "",
|
|
975
|
+
error: `Could not find "${oldString}" in file ${filePath}`,
|
|
976
|
+
metadata: {
|
|
977
|
+
execution_time_ms: Date.now() - startTime
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
const newContent = replaceAll ? content.replace(new RegExp(escapeRegExp(oldString), "g"), newString) : content.replace(oldString, newString);
|
|
982
|
+
await writeFile2(filePath, newContent, "utf-8");
|
|
983
|
+
return {
|
|
984
|
+
success: true,
|
|
985
|
+
output: replaceAll ? `Replaced all occurrences in: ${filePath}` : `Replaced text in: ${filePath}`,
|
|
986
|
+
metadata: {
|
|
987
|
+
execution_time_ms: Date.now() - startTime,
|
|
988
|
+
file_path: filePath
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
} catch (error) {
|
|
992
|
+
return {
|
|
993
|
+
success: false,
|
|
994
|
+
output: "",
|
|
995
|
+
error: error instanceof Error ? error.message : String(error),
|
|
996
|
+
metadata: {
|
|
997
|
+
execution_time_ms: Date.now() - startTime
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
// packages/core/src/env/tool/built-in/grep.ts
|
|
1006
|
+
import { z as z6 } from "zod";
|
|
1007
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1008
|
+
import { glob as globAsync2 } from "glob";
|
|
1009
|
+
var grepTool;
|
|
1010
|
+
var init_grep = __esm(() => {
|
|
1011
|
+
grepTool = {
|
|
1012
|
+
name: "grep",
|
|
1013
|
+
description: "Search for text patterns in files. Use this to find specific strings, code patterns, or content across multiple files.",
|
|
1014
|
+
parameters: z6.object({
|
|
1015
|
+
pattern: z6.string().describe("The pattern to search for"),
|
|
1016
|
+
path: z6.string().optional().describe("File or directory path to search in"),
|
|
1017
|
+
include: z6.string().optional().describe("Glob pattern for files to include (e.g., *.ts, *.js)"),
|
|
1018
|
+
caseSensitive: z6.boolean().default(true).optional().describe("Whether the search should be case sensitive"),
|
|
1019
|
+
maxResults: z6.number().int().positive().default(50).optional().describe("Maximum number of results"),
|
|
1020
|
+
showLineNumbers: z6.boolean().default(true).optional().describe("Show line numbers in results")
|
|
1021
|
+
}),
|
|
1022
|
+
sandbox: {
|
|
1023
|
+
enabled: true
|
|
1024
|
+
},
|
|
1025
|
+
metadata: {
|
|
1026
|
+
category: "file",
|
|
1027
|
+
tags: ["search", "grep", "find", "pattern"],
|
|
1028
|
+
version: "1.0.0"
|
|
1029
|
+
},
|
|
1030
|
+
execute: async (args, ctx) => {
|
|
1031
|
+
const startTime = Date.now();
|
|
1032
|
+
const {
|
|
1033
|
+
pattern,
|
|
1034
|
+
path: searchPath,
|
|
1035
|
+
include,
|
|
1036
|
+
caseSensitive = true,
|
|
1037
|
+
maxResults = 50,
|
|
1038
|
+
showLineNumbers = true
|
|
1039
|
+
} = args;
|
|
1040
|
+
const basePath = searchPath || ctx.workdir || process.cwd();
|
|
1041
|
+
try {
|
|
1042
|
+
let files = [];
|
|
1043
|
+
if (include) {
|
|
1044
|
+
files = await globAsync2(include, {
|
|
1045
|
+
cwd: basePath,
|
|
1046
|
+
ignore: ["**/node_modules/**", "**/.git/**"],
|
|
1047
|
+
maxDepth: 10
|
|
1048
|
+
});
|
|
1049
|
+
} else {
|
|
1050
|
+
files = await globAsync2("**/*", {
|
|
1051
|
+
cwd: basePath,
|
|
1052
|
+
ignore: ["**/node_modules/**", "**/.git/**"],
|
|
1053
|
+
maxDepth: 10
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
const results = [];
|
|
1057
|
+
const regexFlags = caseSensitive ? "" : "i";
|
|
1058
|
+
const regex = new RegExp(pattern, regexFlags);
|
|
1059
|
+
for (const file of files) {
|
|
1060
|
+
if (results.length >= maxResults)
|
|
1061
|
+
break;
|
|
1062
|
+
try {
|
|
1063
|
+
const content = await readFile3(`${basePath}/${file}`, "utf-8");
|
|
1064
|
+
const lines = content.split(`
|
|
1065
|
+
`);
|
|
1066
|
+
for (let i = 0;i < lines.length; i++) {
|
|
1067
|
+
if (regex.test(lines[i])) {
|
|
1068
|
+
const lineNum = showLineNumbers ? `${i + 1}:` : "";
|
|
1069
|
+
results.push(`${file}:${lineNum}${lines[i]}`);
|
|
1070
|
+
if (results.length >= maxResults)
|
|
1071
|
+
break;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
} catch {}
|
|
1075
|
+
}
|
|
1076
|
+
const output = results.join(`
|
|
1077
|
+
`) || "(no matches found)";
|
|
1078
|
+
return {
|
|
1079
|
+
success: true,
|
|
1080
|
+
output,
|
|
1081
|
+
metadata: {
|
|
1082
|
+
execution_time_ms: Date.now() - startTime,
|
|
1083
|
+
output_size: output.length,
|
|
1084
|
+
matches_count: results.length,
|
|
1085
|
+
files_searched: files.length
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
} catch (error) {
|
|
1089
|
+
return {
|
|
1090
|
+
success: false,
|
|
1091
|
+
output: "",
|
|
1092
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1093
|
+
metadata: {
|
|
1094
|
+
execution_time_ms: Date.now() - startTime
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
});
|
|
1101
|
+
|
|
1102
|
+
// packages/core/src/env/tool/built-in/index.ts
|
|
1103
|
+
var exports_built_in = {};
|
|
1104
|
+
__export(exports_built_in, {
|
|
1105
|
+
writeFileTool: () => writeFileTool,
|
|
1106
|
+
readFileTool: () => readFileTool,
|
|
1107
|
+
grepTool: () => grepTool,
|
|
1108
|
+
globTool: () => globTool,
|
|
1109
|
+
getBuiltInTool: () => getBuiltInTool,
|
|
1110
|
+
getAllBuiltInTools: () => getAllBuiltInTools,
|
|
1111
|
+
editFileTool: () => editFileTool,
|
|
1112
|
+
echoTool: () => echoTool,
|
|
1113
|
+
bashTool: () => bashTool
|
|
1114
|
+
});
|
|
1115
|
+
function getAllBuiltInTools() {
|
|
1116
|
+
return [
|
|
1117
|
+
bashTool,
|
|
1118
|
+
echoTool,
|
|
1119
|
+
globTool,
|
|
1120
|
+
readFileTool,
|
|
1121
|
+
writeFileTool,
|
|
1122
|
+
editFileTool,
|
|
1123
|
+
grepTool
|
|
1124
|
+
];
|
|
1125
|
+
}
|
|
1126
|
+
function getBuiltInTool(name) {
|
|
1127
|
+
const tools = getAllBuiltInTools();
|
|
1128
|
+
return tools.find((t) => t.name === name);
|
|
1129
|
+
}
|
|
1130
|
+
var init_built_in = __esm(() => {
|
|
1131
|
+
init_bash();
|
|
1132
|
+
init_echo();
|
|
1133
|
+
init_glob();
|
|
1134
|
+
init_read_file();
|
|
1135
|
+
init_write_file();
|
|
1136
|
+
init_edit_file();
|
|
1137
|
+
init_grep();
|
|
1138
|
+
});
|
|
1139
|
+
|
|
1140
|
+
// packages/core/src/env/log-trace/logger.ts
|
|
1141
|
+
import { appendFileSync, existsSync, mkdirSync } from "fs";
|
|
1142
|
+
import { join } from "path";
|
|
1143
|
+
function simplifyFilePath(fullPath) {
|
|
1144
|
+
let path = fullPath.replace(/\\/g, "/");
|
|
1145
|
+
const bunfsMatch = path.match(/\/\$bunfs\/root\/(.+)$/);
|
|
1146
|
+
if (bunfsMatch) {
|
|
1147
|
+
const virtualPath = bunfsMatch[1];
|
|
1148
|
+
const packagesMatch = virtualPath.match(/(packages\/[^/]+\/src\/[^/]+\/.+)$/);
|
|
1149
|
+
if (packagesMatch) {
|
|
1150
|
+
return packagesMatch[1];
|
|
1151
|
+
}
|
|
1152
|
+
return virtualPath;
|
|
1153
|
+
}
|
|
1154
|
+
const fileProtocolMatch = path.match(/@roy-agent\+core@file\+([^/]+)\/node_modules\/@roy-agent\/core\/(.+)$/);
|
|
1155
|
+
if (fileProtocolMatch) {
|
|
1156
|
+
const rootPkg = fileProtocolMatch[1].replace(/\+/g, "/");
|
|
1157
|
+
const remaining = fileProtocolMatch[2];
|
|
1158
|
+
const prefix = rootPkg;
|
|
1159
|
+
const suffix = remaining.startsWith("src/") ? remaining : `src/${remaining}`;
|
|
1160
|
+
return `${prefix}/${suffix}`;
|
|
1161
|
+
}
|
|
1162
|
+
const packagesRootMatch = path.match(/(packages\/[^/]+\/src\/[^/]+\/.+)$/);
|
|
1163
|
+
if (packagesRootMatch) {
|
|
1164
|
+
return packagesRootMatch[1];
|
|
1165
|
+
}
|
|
1166
|
+
const rootMarkers = ["packages/core/src", "packages/core", "packages"];
|
|
1167
|
+
for (const marker of rootMarkers) {
|
|
1168
|
+
const idx = path.indexOf(marker);
|
|
1169
|
+
if (idx !== -1) {
|
|
1170
|
+
return path.substring(idx);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
return path;
|
|
1174
|
+
}
|
|
1175
|
+
function getDefaultLogDir() {
|
|
1176
|
+
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
1177
|
+
try {
|
|
1178
|
+
const xdg = __require("xdg-basedir");
|
|
1179
|
+
if (xdg.xdgData) {
|
|
1180
|
+
return join(xdg.xdgData, "roy-agent", "logs");
|
|
1181
|
+
}
|
|
1182
|
+
} catch {}
|
|
1183
|
+
return join(home, ".local", "share", "roy-agent", "logs");
|
|
1184
|
+
}
|
|
1185
|
+
function isQuietMode() {
|
|
1186
|
+
return quietMode;
|
|
1187
|
+
}
|
|
1188
|
+
function setQuietMode(enabled) {
|
|
1189
|
+
quietMode = enabled;
|
|
1190
|
+
}
|
|
1191
|
+
function setConfigComponent(component) {
|
|
1192
|
+
configComponentInstance = component;
|
|
1193
|
+
}
|
|
1194
|
+
function getLogLevel() {
|
|
1195
|
+
if (configComponentInstance) {
|
|
1196
|
+
const level = configComponentInstance.get("log_trace.logging.level");
|
|
1197
|
+
if (level && ["debug", "info", "warn", "error"].includes(level)) {
|
|
1198
|
+
return level;
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
const envLevel = process.env.LOG_LEVEL;
|
|
1202
|
+
if (envLevel && ["debug", "info", "warn", "error"].includes(envLevel)) {
|
|
1203
|
+
return envLevel;
|
|
1204
|
+
}
|
|
1205
|
+
return "info";
|
|
1206
|
+
}
|
|
1207
|
+
function getCategoryLogLevel(category) {
|
|
1208
|
+
if (configComponentInstance) {
|
|
1209
|
+
const levels = configComponentInstance.get("log_trace.logging.levels");
|
|
1210
|
+
if (levels && typeof levels === "object") {
|
|
1211
|
+
const categoryLevel = levels[category];
|
|
1212
|
+
if (categoryLevel && ["debug", "info", "warn", "error"].includes(categoryLevel)) {
|
|
1213
|
+
return categoryLevel;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
const directLevel = configComponentInstance.get(`log_trace.logging.levels.${category}`);
|
|
1217
|
+
if (directLevel && ["debug", "info", "warn", "error"].includes(directLevel)) {
|
|
1218
|
+
return directLevel;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
const envKey = `LOG_LEVEL_${category.toUpperCase().replace(/:/g, "_")}`;
|
|
1222
|
+
const envLevel = process.env[envKey];
|
|
1223
|
+
if (envLevel && ["debug", "info", "warn", "error"].includes(envLevel)) {
|
|
1224
|
+
return envLevel;
|
|
1225
|
+
}
|
|
1226
|
+
return getLogLevel();
|
|
1227
|
+
}
|
|
1228
|
+
function isAbsolutePath(path) {
|
|
1229
|
+
if (path.startsWith("/")) {
|
|
1230
|
+
return true;
|
|
1231
|
+
}
|
|
1232
|
+
if (/^[a-zA-Z]:[/\\]/.test(path)) {
|
|
1233
|
+
return true;
|
|
1234
|
+
}
|
|
1235
|
+
return false;
|
|
1236
|
+
}
|
|
1237
|
+
function expandHomeDir(path) {
|
|
1238
|
+
if (path.startsWith("~")) {
|
|
1239
|
+
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
1240
|
+
return join(home, path.slice(1));
|
|
1241
|
+
}
|
|
1242
|
+
return path;
|
|
1243
|
+
}
|
|
1244
|
+
function getLogFile() {
|
|
1245
|
+
if (configComponentInstance) {
|
|
1246
|
+
const file = configComponentInstance.get("log_trace.logging.file");
|
|
1247
|
+
if (file) {
|
|
1248
|
+
return file;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
return "app.log";
|
|
1252
|
+
}
|
|
1253
|
+
function getLogDir() {
|
|
1254
|
+
if (configComponentInstance) {
|
|
1255
|
+
const dir = configComponentInstance.get("log_trace.logging.dir");
|
|
1256
|
+
if (dir) {
|
|
1257
|
+
return dir;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
return getDefaultLogDir();
|
|
1261
|
+
}
|
|
1262
|
+
function getMaxOutput() {
|
|
1263
|
+
if (configComponentInstance) {
|
|
1264
|
+
const maxOutput = configComponentInstance.get("log-trace.logging.maxOutput");
|
|
1265
|
+
if (typeof maxOutput === "number") {
|
|
1266
|
+
return maxOutput;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
function setLogDirOverride(dir) {
|
|
1272
|
+
logDirOverride = dir;
|
|
1273
|
+
}
|
|
1274
|
+
function getLogDirOverride() {
|
|
1275
|
+
return logDirOverride;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
class Logger {
|
|
1279
|
+
prefix;
|
|
1280
|
+
constructor(prefix) {
|
|
1281
|
+
this.prefix = prefix;
|
|
1282
|
+
}
|
|
1283
|
+
shouldLog(level) {
|
|
1284
|
+
const categoryLevel = getCategoryLogLevel(this.prefix);
|
|
1285
|
+
return levelPriority[level] >= levelPriority[categoryLevel];
|
|
1286
|
+
}
|
|
1287
|
+
ensureLogDirectory(dir) {
|
|
1288
|
+
if (!existsSync(dir)) {
|
|
1289
|
+
try {
|
|
1290
|
+
mkdirSync(dir, { recursive: true });
|
|
1291
|
+
} catch (err) {
|
|
1292
|
+
console.error("[Logger] Failed to create log directory:", dir, err);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
getCallerLocation() {
|
|
1297
|
+
const originalLimit = Error.stackTraceLimit;
|
|
1298
|
+
Error.stackTraceLimit = 10;
|
|
1299
|
+
const err = new Error;
|
|
1300
|
+
Error.captureStackTrace(err, this.formatMessage);
|
|
1301
|
+
const stack = err.stack?.split(`
|
|
1302
|
+
`) || [];
|
|
1303
|
+
Error.stackTraceLimit = originalLimit;
|
|
1304
|
+
for (let i = 1;i < stack.length; i++) {
|
|
1305
|
+
const line = stack[i];
|
|
1306
|
+
if (line.includes("at ") && !line.includes("logger.ts") && !line.includes("formatMessage")) {
|
|
1307
|
+
const match = line.match(/at\s+.+\s+\((.+):(\d+):\d+\)/) || line.match(/at\s+(.+):(\d+):\d+/);
|
|
1308
|
+
if (match) {
|
|
1309
|
+
const filePath = match[1];
|
|
1310
|
+
const relativePath = this.getRelativePath(filePath);
|
|
1311
|
+
return {
|
|
1312
|
+
file: relativePath,
|
|
1313
|
+
line: parseInt(match[2], 10)
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
return null;
|
|
1319
|
+
}
|
|
1320
|
+
getRelativePath(fullPath) {
|
|
1321
|
+
return simplifyFilePath(fullPath);
|
|
1322
|
+
}
|
|
1323
|
+
formatMessage(level, message, data) {
|
|
1324
|
+
const now = new Date;
|
|
1325
|
+
const timestamp = now.toLocaleString("zh-CN", {
|
|
1326
|
+
timeZone: "Asia/Shanghai",
|
|
1327
|
+
year: "numeric",
|
|
1328
|
+
month: "2-digit",
|
|
1329
|
+
day: "2-digit",
|
|
1330
|
+
hour: "2-digit",
|
|
1331
|
+
minute: "2-digit",
|
|
1332
|
+
second: "2-digit",
|
|
1333
|
+
hour12: false
|
|
1334
|
+
}).replace(/\//g, "-") + "." + String(now.getMilliseconds()).padStart(3, "0");
|
|
1335
|
+
const prefix = this.prefix ? `[${this.prefix}]` : "";
|
|
1336
|
+
let traceIdStr = "";
|
|
1337
|
+
try {
|
|
1338
|
+
const provider = getTracerProvider();
|
|
1339
|
+
const tracer = provider.getTracer("roy-tracer");
|
|
1340
|
+
const context = tracer.getCurrentContext();
|
|
1341
|
+
if (context?.traceId) {
|
|
1342
|
+
traceIdStr = `[traceId=${context.traceId}]`;
|
|
1343
|
+
}
|
|
1344
|
+
} catch {}
|
|
1345
|
+
let locationStr = "";
|
|
1346
|
+
if (data && typeof data === "object" && "callerLocation" in data) {
|
|
1347
|
+
const logData = data;
|
|
1348
|
+
locationStr = logData.callerLocation ? ` [${logData.callerLocation}]` : "";
|
|
1349
|
+
const { callerLocation: _callerLocation, ...rest } = logData;
|
|
1350
|
+
data = Object.keys(rest).length > 0 ? rest : undefined;
|
|
1351
|
+
} else {
|
|
1352
|
+
const location = this.getCallerLocation();
|
|
1353
|
+
if (location) {
|
|
1354
|
+
locationStr = ` [${location.file}:${location.line}]`;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
let formatted = `${timestamp} [${level.toUpperCase()}]${traceIdStr}${locationStr}${prefix} ${message}`;
|
|
1358
|
+
if (data !== undefined) {
|
|
1359
|
+
if (typeof data === "object") {
|
|
1360
|
+
formatted += " " + JSON.stringify(data).replace(/\n/g, "");
|
|
1361
|
+
} else {
|
|
1362
|
+
formatted += " " + String(data);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
const maxOutput = getMaxOutput();
|
|
1366
|
+
if (maxOutput && maxOutput > 0 && formatted.length > maxOutput) {
|
|
1367
|
+
formatted = formatted.substring(0, maxOutput) + " [TRUNCATED]";
|
|
1368
|
+
}
|
|
1369
|
+
return formatted;
|
|
1370
|
+
}
|
|
1371
|
+
writeToFile(message) {
|
|
1372
|
+
try {
|
|
1373
|
+
const dir = getLogDir();
|
|
1374
|
+
const filename = getLogFile();
|
|
1375
|
+
const expandedDir = expandHomeDir(dir);
|
|
1376
|
+
const resolvedDir = isAbsolutePath(expandedDir) ? expandedDir : join(process.cwd(), expandedDir);
|
|
1377
|
+
this.ensureLogDirectory(resolvedDir);
|
|
1378
|
+
const logFile = join(resolvedDir, filename);
|
|
1379
|
+
appendFileSync(logFile, message + `
|
|
1380
|
+
`, "utf-8");
|
|
1381
|
+
} catch (err) {
|
|
1382
|
+
console.error("[Logger] Failed to write to log file:", err);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
log(level, message, data) {
|
|
1386
|
+
if (!this.shouldLog(level))
|
|
1387
|
+
return;
|
|
1388
|
+
const formatted = this.formatMessage(level, message, data);
|
|
1389
|
+
this.writeToFile(formatted);
|
|
1390
|
+
if (!isQuietMode()) {
|
|
1391
|
+
const consoleMethod = level === "error" ? console.error : level === "warn" ? console.warn : level === "info" ? console.log : console.debug;
|
|
1392
|
+
consoleMethod(formatted);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
debug(message, data) {
|
|
1396
|
+
this.log("debug", message, data);
|
|
1397
|
+
}
|
|
1398
|
+
info(message, data) {
|
|
1399
|
+
this.log("info", message, data);
|
|
1400
|
+
}
|
|
1401
|
+
warn(message, data) {
|
|
1402
|
+
this.log("warn", message, data);
|
|
1403
|
+
}
|
|
1404
|
+
error(message, data) {
|
|
1405
|
+
this.log("error", message, data);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
function createLogger(prefix) {
|
|
1409
|
+
if (!loggerCache.has(prefix)) {
|
|
1410
|
+
loggerCache.set(prefix, new Logger(prefix));
|
|
1411
|
+
}
|
|
1412
|
+
return loggerCache.get(prefix);
|
|
1413
|
+
}
|
|
1414
|
+
function getLogLevels() {
|
|
1415
|
+
return ["debug", "info", "warn", "error"];
|
|
1416
|
+
}
|
|
1417
|
+
var configComponentInstance = null, quietMode = false, logDirOverride, levelPriority, loggerCache;
|
|
1418
|
+
var init_logger = __esm(() => {
|
|
1419
|
+
init_tracer_provider();
|
|
1420
|
+
levelPriority = {
|
|
1421
|
+
debug: 0,
|
|
1422
|
+
info: 1,
|
|
1423
|
+
warn: 2,
|
|
1424
|
+
error: 3
|
|
1425
|
+
};
|
|
1426
|
+
loggerCache = new Map;
|
|
1427
|
+
});
|
|
1428
|
+
|
|
1429
|
+
// packages/core/src/env/workflow/types/workflow-hil.ts
|
|
1430
|
+
function createNodeInterruptEvent(runId, nodeId, nodeType, query, agentSessionId) {
|
|
1431
|
+
return {
|
|
1432
|
+
type: "node.interrupt",
|
|
1433
|
+
run_id: runId,
|
|
1434
|
+
timestamp: Date.now(),
|
|
1435
|
+
node_id: nodeId,
|
|
1436
|
+
node_type: nodeType,
|
|
1437
|
+
query,
|
|
1438
|
+
...agentSessionId ? { agent_session_id: agentSessionId } : {}
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
function createWorkflowAskUserEvent(runId, sessionId, nodeId, nodeType, query) {
|
|
1442
|
+
return {
|
|
1443
|
+
type: "workflow.ask-user",
|
|
1444
|
+
run_id: runId,
|
|
1445
|
+
timestamp: Date.now(),
|
|
1446
|
+
session_id: sessionId,
|
|
1447
|
+
node_id: nodeId,
|
|
1448
|
+
node_type: nodeType,
|
|
1449
|
+
query
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
var AskUserError;
|
|
1453
|
+
var init_workflow_hil = __esm(() => {
|
|
1454
|
+
AskUserError = class AskUserError extends Error {
|
|
1455
|
+
runId;
|
|
1456
|
+
sessionId;
|
|
1457
|
+
nodeId;
|
|
1458
|
+
nodeType;
|
|
1459
|
+
query;
|
|
1460
|
+
agentSessionId;
|
|
1461
|
+
timestamp;
|
|
1462
|
+
type = "ask-user";
|
|
1463
|
+
name = "AskUserError";
|
|
1464
|
+
constructor(runId, sessionId, nodeId, nodeType, query, agentSessionId, timestamp = Date.now()) {
|
|
1465
|
+
super(`[${nodeType}:${nodeId}] Ask user: ${query}`);
|
|
1466
|
+
this.runId = runId;
|
|
1467
|
+
this.sessionId = sessionId;
|
|
1468
|
+
this.nodeId = nodeId;
|
|
1469
|
+
this.nodeType = nodeType;
|
|
1470
|
+
this.query = query;
|
|
1471
|
+
this.agentSessionId = agentSessionId;
|
|
1472
|
+
this.timestamp = timestamp;
|
|
1473
|
+
}
|
|
1474
|
+
toEvent() {
|
|
1475
|
+
return {
|
|
1476
|
+
type: "workflow.ask-user",
|
|
1477
|
+
run_id: this.runId,
|
|
1478
|
+
timestamp: this.timestamp,
|
|
1479
|
+
session_id: this.sessionId,
|
|
1480
|
+
node_id: this.nodeId,
|
|
1481
|
+
node_type: this.nodeType,
|
|
1482
|
+
query: this.query
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
});
|
|
1487
|
+
|
|
1488
|
+
// packages/core/src/env/hook/types.ts
|
|
1489
|
+
function createHook(meta, fn) {
|
|
1490
|
+
return {
|
|
1491
|
+
...meta,
|
|
1492
|
+
execute: fn
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
function createPriorityHook(name, fn, priority) {
|
|
1496
|
+
return createHook({ name, priority }, fn);
|
|
1497
|
+
}
|
|
1498
|
+
// packages/core/src/env/hook/hook-manager.ts
|
|
1499
|
+
class HookManager {
|
|
1500
|
+
_hooks = new Map;
|
|
1501
|
+
componentName;
|
|
1502
|
+
componentVersion;
|
|
1503
|
+
defaultPriority;
|
|
1504
|
+
constructor(options = {}) {
|
|
1505
|
+
this.componentName = options.componentName ?? "unknown";
|
|
1506
|
+
this.componentVersion = options.componentVersion ?? "0.0.0";
|
|
1507
|
+
this.defaultPriority = options.defaultPriority ?? 0;
|
|
1508
|
+
}
|
|
1509
|
+
register(hookPoint, hook) {
|
|
1510
|
+
const hooks = this.getOrCreateHooks(hookPoint);
|
|
1511
|
+
hooks.push(hook);
|
|
1512
|
+
}
|
|
1513
|
+
registerMany(hookPoint, hooks) {
|
|
1514
|
+
const hookList = this.getOrCreateHooks(hookPoint);
|
|
1515
|
+
hookList.push(...hooks);
|
|
1516
|
+
}
|
|
1517
|
+
unregister(hookPoint, name) {
|
|
1518
|
+
const hooks = this._hooks.get(hookPoint);
|
|
1519
|
+
if (!hooks)
|
|
1520
|
+
return false;
|
|
1521
|
+
const index = hooks.findIndex((h) => h.name === name);
|
|
1522
|
+
if (index === -1)
|
|
1523
|
+
return false;
|
|
1524
|
+
hooks.splice(index, 1);
|
|
1525
|
+
return true;
|
|
1526
|
+
}
|
|
1527
|
+
unregisterAll(hookPoint) {
|
|
1528
|
+
this._hooks.delete(hookPoint);
|
|
1529
|
+
}
|
|
1530
|
+
async execute(hookPoint, data, metadata = {}) {
|
|
1531
|
+
const hooks = this._hooks.get(hookPoint);
|
|
1532
|
+
if (!hooks || hooks.length === 0)
|
|
1533
|
+
return;
|
|
1534
|
+
const sortedHooks = this.sortHooks(hooks);
|
|
1535
|
+
const ctx = this.createContext(hookPoint, data, metadata, "before");
|
|
1536
|
+
for (const hook of sortedHooks) {
|
|
1537
|
+
await this.safeExecute(hook, ctx);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
async executeAndCollect(hookPoint, data, metadata = {}) {
|
|
1541
|
+
const hooks = this._hooks.get(hookPoint);
|
|
1542
|
+
if (!hooks || hooks.length === 0)
|
|
1543
|
+
return [];
|
|
1544
|
+
const sortedHooks = this.sortHooks(hooks);
|
|
1545
|
+
const ctx = this.createContext(hookPoint, data, metadata, "before");
|
|
1546
|
+
const results = [];
|
|
1547
|
+
for (const hook of sortedHooks) {
|
|
1548
|
+
const result = await this.safeExecuteAndReturn(hook, ctx);
|
|
1549
|
+
if (result !== undefined) {
|
|
1550
|
+
results.push(result);
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
return results;
|
|
1554
|
+
}
|
|
1555
|
+
count(hookPoint) {
|
|
1556
|
+
return this._hooks.get(hookPoint)?.length ?? 0;
|
|
1557
|
+
}
|
|
1558
|
+
clear() {
|
|
1559
|
+
this._hooks.clear();
|
|
1560
|
+
}
|
|
1561
|
+
getHookPoints() {
|
|
1562
|
+
return Array.from(this._hooks.keys());
|
|
1563
|
+
}
|
|
1564
|
+
hasHooks(hookPoint) {
|
|
1565
|
+
return this.count(hookPoint) > 0;
|
|
1566
|
+
}
|
|
1567
|
+
setComponentInfo(name, version) {
|
|
1568
|
+
this.componentName = name;
|
|
1569
|
+
this.componentVersion = version;
|
|
1570
|
+
}
|
|
1571
|
+
get hooks() {
|
|
1572
|
+
return this._hooks;
|
|
1573
|
+
}
|
|
1574
|
+
async executeWithIntervention(hookPoint, data, metadata = {}) {
|
|
1575
|
+
const hooks = this._hooks.get(hookPoint);
|
|
1576
|
+
if (!hooks || hooks.length === 0) {
|
|
1577
|
+
return { stopped: false, results: [] };
|
|
1578
|
+
}
|
|
1579
|
+
const sortedHooks = this.sortHooks(hooks);
|
|
1580
|
+
const ctx = this.createContext(hookPoint, data, metadata, "before");
|
|
1581
|
+
const results = [];
|
|
1582
|
+
let stopped = false;
|
|
1583
|
+
let action;
|
|
1584
|
+
for (const hook of sortedHooks) {
|
|
1585
|
+
if (stopped)
|
|
1586
|
+
break;
|
|
1587
|
+
const result = await this.safeExecuteAndReturn(hook, ctx);
|
|
1588
|
+
results.push(result);
|
|
1589
|
+
if (result && typeof result === "object" && "stopped" in result) {
|
|
1590
|
+
const hookResult = result;
|
|
1591
|
+
if (hookResult.stopped) {
|
|
1592
|
+
stopped = true;
|
|
1593
|
+
action = hookResult.action;
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
return { stopped, action, results };
|
|
1598
|
+
}
|
|
1599
|
+
getOrCreateHooks(hookPoint) {
|
|
1600
|
+
let hooks = this._hooks.get(hookPoint);
|
|
1601
|
+
if (!hooks) {
|
|
1602
|
+
hooks = [];
|
|
1603
|
+
this._hooks.set(hookPoint, hooks);
|
|
1604
|
+
}
|
|
1605
|
+
return hooks;
|
|
1606
|
+
}
|
|
1607
|
+
sortHooks(hooks) {
|
|
1608
|
+
return [...hooks].sort((a, b) => {
|
|
1609
|
+
const priorityA = a.priority ?? this.defaultPriority;
|
|
1610
|
+
const priorityB = b.priority ?? this.defaultPriority;
|
|
1611
|
+
return priorityA - priorityB;
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
createContext(hookPoint, data, metadata, phase) {
|
|
1615
|
+
return {
|
|
1616
|
+
component: {
|
|
1617
|
+
name: this.componentName,
|
|
1618
|
+
version: this.componentVersion
|
|
1619
|
+
},
|
|
1620
|
+
data,
|
|
1621
|
+
metadata,
|
|
1622
|
+
phase,
|
|
1623
|
+
hookPoint
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1626
|
+
async safeExecute(hook, ctx) {
|
|
1627
|
+
try {
|
|
1628
|
+
await hook.execute(ctx);
|
|
1629
|
+
} catch (error) {
|
|
1630
|
+
console.error(`Hook "${hook.name}" failed:`, error);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
async safeExecuteAndReturn(hook, ctx) {
|
|
1634
|
+
try {
|
|
1635
|
+
return await hook.execute(ctx);
|
|
1636
|
+
} catch (error) {
|
|
1637
|
+
console.error(`Hook "${hook.name}" failed:`, error);
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
// packages/core/src/env/hook/global-hook-manager.ts
|
|
1643
|
+
var globalHookManager = new HookManager;
|
|
1644
|
+
var AgentHookPoints = {
|
|
1645
|
+
BEFORE_START: "agent:before.start",
|
|
1646
|
+
BEFORE_LLM: "agent:before.llm",
|
|
1647
|
+
AFTER_LLM: "agent:after.llm",
|
|
1648
|
+
BEFORE_TOOL: "agent:before.tool",
|
|
1649
|
+
AFTER_TOOL: "agent:after.tool",
|
|
1650
|
+
ON_ITERATION: "agent:on.iteration",
|
|
1651
|
+
ON_THRESHOLD: "agent:on.threshold",
|
|
1652
|
+
AFTER_COMPLETE: "agent:after.complete",
|
|
1653
|
+
ON_ERROR: "agent:on.error"
|
|
1654
|
+
};
|
|
1655
|
+
var LLMHookPoints = {
|
|
1656
|
+
BEFORE_INVOKE: "llm:before.invoke",
|
|
1657
|
+
AFTER_INVOKE: "llm:after.invoke",
|
|
1658
|
+
ON_STREAM: "llm:on.stream"
|
|
1659
|
+
};
|
|
1660
|
+
var ToolHookPoints = {
|
|
1661
|
+
BEFORE_EXECUTE: "tool:before.execute",
|
|
1662
|
+
AFTER_EXECUTE: "tool:after.execute",
|
|
1663
|
+
BEFORE_REGISTER: "tool:before.register",
|
|
1664
|
+
AFTER_REGISTER: "tool:after.register",
|
|
1665
|
+
ON_ERROR: "tool:on.error"
|
|
1666
|
+
};
|
|
1667
|
+
var hookPointAliases = {
|
|
1668
|
+
"before.tool": "tool:before.execute",
|
|
1669
|
+
"after.tool": "tool:after.execute",
|
|
1670
|
+
"llm.before-invoke": "llm:before.invoke",
|
|
1671
|
+
"llm.after-invoke": "llm:after.invoke",
|
|
1672
|
+
"llm.stream": "llm:on.stream"
|
|
1673
|
+
};
|
|
1674
|
+
function setupAliasHooks() {
|
|
1675
|
+
const originalRegister = globalHookManager.register.bind(globalHookManager);
|
|
1676
|
+
globalHookManager.register = function(hookPoint, hook) {
|
|
1677
|
+
originalRegister(hookPoint, hook);
|
|
1678
|
+
const alias = hookPointAliases[hookPoint];
|
|
1679
|
+
if (alias) {
|
|
1680
|
+
originalRegister(alias, hook);
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
setupAliasHooks();
|
|
1685
|
+
async function executeAgentHook(hookPoint, data, metadata = {}) {
|
|
1686
|
+
await globalHookManager.execute(hookPoint, data, metadata);
|
|
1687
|
+
}
|
|
1688
|
+
async function executeAgentHookWithIntervention(hookPoint, data, metadata = {}) {
|
|
1689
|
+
return globalHookManager.executeWithIntervention(hookPoint, data, metadata);
|
|
1690
|
+
}
|
|
1691
|
+
async function executeLLMHook(hookPoint, data, metadata = {}) {
|
|
1692
|
+
await globalHookManager.execute(hookPoint, data, metadata);
|
|
1693
|
+
}
|
|
1694
|
+
async function executeToolHook(hookPoint, data, metadata = {}) {
|
|
1695
|
+
await globalHookManager.execute(hookPoint, data, metadata);
|
|
1696
|
+
}
|
|
1697
|
+
// packages/core/src/env/tool/tool-component.ts
|
|
1698
|
+
import { z as z7 } from "zod";
|
|
1699
|
+
|
|
1700
|
+
// packages/core/src/env/component.ts
|
|
1701
|
+
class BaseComponent {
|
|
1702
|
+
_status = "created";
|
|
1703
|
+
_enabled = true;
|
|
1704
|
+
env;
|
|
1705
|
+
hookManager;
|
|
1706
|
+
constructor() {
|
|
1707
|
+
this.hookManager = new HookManager;
|
|
1708
|
+
}
|
|
1709
|
+
getStatus() {
|
|
1710
|
+
return this._status;
|
|
1711
|
+
}
|
|
1712
|
+
getConfig() {
|
|
1713
|
+
return {
|
|
1714
|
+
name: this.name,
|
|
1715
|
+
version: this.version,
|
|
1716
|
+
enabled: this._enabled,
|
|
1717
|
+
env: this.env
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
isEnvInitialized() {
|
|
1721
|
+
return this._status !== "created";
|
|
1722
|
+
}
|
|
1723
|
+
setStatus(status) {
|
|
1724
|
+
this._status = status;
|
|
1725
|
+
}
|
|
1726
|
+
getEnv() {
|
|
1727
|
+
return this.env;
|
|
1728
|
+
}
|
|
1729
|
+
async init(config) {
|
|
1730
|
+
if (config?.env) {
|
|
1731
|
+
this.env = config.env;
|
|
1732
|
+
}
|
|
1733
|
+
this.setStatus("initializing");
|
|
1734
|
+
try {
|
|
1735
|
+
if (config?.name)
|
|
1736
|
+
Object.defineProperty(this, "name", { value: config.name, writable: false });
|
|
1737
|
+
if (config?.version)
|
|
1738
|
+
Object.defineProperty(this, "version", { value: config.version, writable: false });
|
|
1739
|
+
} catch {}
|
|
1740
|
+
if (config?.enabled !== undefined)
|
|
1741
|
+
this._enabled = config.enabled;
|
|
1742
|
+
this.hookManager.setComponentInfo(this.name, this.version);
|
|
1743
|
+
await this.onInit();
|
|
1744
|
+
this.setStatus("running");
|
|
1745
|
+
}
|
|
1746
|
+
async start() {
|
|
1747
|
+
if (this._started)
|
|
1748
|
+
return;
|
|
1749
|
+
this._started = true;
|
|
1750
|
+
await this.onStart();
|
|
1751
|
+
this.setStatus("running");
|
|
1752
|
+
}
|
|
1753
|
+
async stop() {
|
|
1754
|
+
this.setStatus("stopping");
|
|
1755
|
+
this.hookManager.clear();
|
|
1756
|
+
await this.onStop();
|
|
1757
|
+
this.setStatus("stopped");
|
|
1758
|
+
}
|
|
1759
|
+
async onInit() {}
|
|
1760
|
+
async onStart() {}
|
|
1761
|
+
async onStop() {}
|
|
1762
|
+
registerHook(hookPoint, hook) {
|
|
1763
|
+
this.hookManager.register(hookPoint, hook);
|
|
1764
|
+
}
|
|
1765
|
+
addHook(hookPoint, name, fn, priority) {
|
|
1766
|
+
this.hookManager.register(hookPoint, createHook({ name, priority }, fn));
|
|
1767
|
+
}
|
|
1768
|
+
removeHook(hookPoint, name) {
|
|
1769
|
+
return this.hookManager.unregister(hookPoint, name);
|
|
1770
|
+
}
|
|
1771
|
+
async executeHooks(hookPoint, data, metadata) {
|
|
1772
|
+
await this.hookManager.execute(hookPoint, data, metadata);
|
|
1773
|
+
}
|
|
1774
|
+
getConfigComponent() {
|
|
1775
|
+
return this.env?.getComponent("config");
|
|
1776
|
+
}
|
|
1777
|
+
getRuntimeConfig(key, defaultValue) {
|
|
1778
|
+
const configComponent = this.getConfigComponent();
|
|
1779
|
+
if (configComponent) {
|
|
1780
|
+
const value = configComponent.get(key);
|
|
1781
|
+
if (value !== undefined) {
|
|
1782
|
+
return value;
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
return defaultValue;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
// packages/core/src/env/tool/registry.ts
|
|
1790
|
+
class ToolRegistry {
|
|
1791
|
+
tools = new Map;
|
|
1792
|
+
register(tool, registration) {
|
|
1793
|
+
this.tools.set(tool.name, registration);
|
|
1794
|
+
}
|
|
1795
|
+
unregister(name) {
|
|
1796
|
+
return this.tools.delete(name);
|
|
1797
|
+
}
|
|
1798
|
+
getTool(name) {
|
|
1799
|
+
return this.tools.get(name);
|
|
1800
|
+
}
|
|
1801
|
+
getAllTools() {
|
|
1802
|
+
return Array.from(this.tools.values());
|
|
1803
|
+
}
|
|
1804
|
+
listTools(filter) {
|
|
1805
|
+
let tools = this.getAllTools();
|
|
1806
|
+
if (!filter) {
|
|
1807
|
+
return tools.map((r) => r.tool);
|
|
1808
|
+
}
|
|
1809
|
+
if (filter.name) {
|
|
1810
|
+
const names = Array.isArray(filter.name) ? filter.name : [filter.name];
|
|
1811
|
+
tools = tools.filter((r) => names.some((pattern) => this.matchGlob(r.tool.name, pattern)));
|
|
1812
|
+
}
|
|
1813
|
+
if (filter.category) {
|
|
1814
|
+
tools = tools.filter((r) => r.tool.metadata?.category === filter.category);
|
|
1815
|
+
}
|
|
1816
|
+
if (filter.tags && filter.tags.length > 0) {
|
|
1817
|
+
tools = tools.filter((r) => filter.tags.some((tag) => r.tool.metadata?.tags?.includes(tag)));
|
|
1818
|
+
}
|
|
1819
|
+
if (filter.source) {
|
|
1820
|
+
tools = tools.filter((r) => r.source === filter.source);
|
|
1821
|
+
}
|
|
1822
|
+
if (filter.enabledOnly) {
|
|
1823
|
+
tools = tools.filter((r) => r.enabled);
|
|
1824
|
+
}
|
|
1825
|
+
if (filter.exclude && filter.exclude.length > 0) {
|
|
1826
|
+
tools = tools.filter((r) => !filter.exclude.includes(r.tool.name));
|
|
1827
|
+
}
|
|
1828
|
+
return tools.map((r) => r.tool);
|
|
1829
|
+
}
|
|
1830
|
+
has(name) {
|
|
1831
|
+
return this.tools.has(name);
|
|
1832
|
+
}
|
|
1833
|
+
getCount() {
|
|
1834
|
+
return this.tools.size;
|
|
1835
|
+
}
|
|
1836
|
+
enable(name) {
|
|
1837
|
+
const reg = this.tools.get(name);
|
|
1838
|
+
if (reg) {
|
|
1839
|
+
reg.enabled = true;
|
|
1840
|
+
return true;
|
|
1841
|
+
}
|
|
1842
|
+
return false;
|
|
1843
|
+
}
|
|
1844
|
+
disable(name) {
|
|
1845
|
+
const reg = this.tools.get(name);
|
|
1846
|
+
if (reg) {
|
|
1847
|
+
reg.enabled = false;
|
|
1848
|
+
return true;
|
|
1849
|
+
}
|
|
1850
|
+
return false;
|
|
1851
|
+
}
|
|
1852
|
+
clear() {
|
|
1853
|
+
this.tools.clear();
|
|
1854
|
+
}
|
|
1855
|
+
snapshot() {
|
|
1856
|
+
return this.getAllTools();
|
|
1857
|
+
}
|
|
1858
|
+
restore(snapshot) {
|
|
1859
|
+
this.clear();
|
|
1860
|
+
for (const reg of snapshot) {
|
|
1861
|
+
this.tools.set(reg.tool.name, reg);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
matchGlob(str, pattern) {
|
|
1865
|
+
if (pattern === "*")
|
|
1866
|
+
return true;
|
|
1867
|
+
if (!pattern.includes("*"))
|
|
1868
|
+
return str === pattern;
|
|
1869
|
+
const regexPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
1870
|
+
return new RegExp(`^${regexPattern}$`).test(str);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// packages/core/src/env/tool/validator.ts
|
|
1875
|
+
import { ZodError } from "zod";
|
|
1876
|
+
|
|
1877
|
+
class ToolValidator {
|
|
1878
|
+
async validate(tool, args) {
|
|
1879
|
+
try {
|
|
1880
|
+
const parsed = await tool.parameters.parseAsync(args);
|
|
1881
|
+
return {
|
|
1882
|
+
success: true,
|
|
1883
|
+
data: parsed
|
|
1884
|
+
};
|
|
1885
|
+
} catch (error) {
|
|
1886
|
+
if (error instanceof ZodError) {
|
|
1887
|
+
const errorMessage = tool.formatValidationError ? tool.formatValidationError(error) : this.formatError(error);
|
|
1888
|
+
return {
|
|
1889
|
+
success: false,
|
|
1890
|
+
error: `Invalid arguments for tool '${tool.name}': ${errorMessage}`
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
return {
|
|
1894
|
+
success: false,
|
|
1895
|
+
error: `Validation error: ${error}`
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
formatError(error) {
|
|
1900
|
+
return error.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join("; ");
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
// packages/core/src/env/tool/tool-component.ts
|
|
1905
|
+
init_logger();
|
|
1906
|
+
|
|
1907
|
+
// packages/core/src/config/env-key.ts
|
|
1908
|
+
function toEnvKey(key, prefix) {
|
|
1909
|
+
let keyNormalized = key.replace(/[.-]/g, "_");
|
|
1910
|
+
keyNormalized = keyNormalized.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/_+/g, "_").toUpperCase();
|
|
1911
|
+
if (prefix) {
|
|
1912
|
+
const separator = prefix.endsWith("_") ? "" : "_";
|
|
1913
|
+
return `${prefix}${separator}${keyNormalized}`;
|
|
1914
|
+
}
|
|
1915
|
+
return keyNormalized;
|
|
1916
|
+
}
|
|
1917
|
+
function fromEnvKey(envKey, prefix) {
|
|
1918
|
+
if (!prefix) {
|
|
1919
|
+
return envKey;
|
|
1920
|
+
}
|
|
1921
|
+
if (envKey.startsWith(prefix)) {
|
|
1922
|
+
const afterPrefix = envKey.slice(prefix.length);
|
|
1923
|
+
if (afterPrefix.startsWith("_")) {
|
|
1924
|
+
return afterPrefix.slice(1);
|
|
1925
|
+
}
|
|
1926
|
+
return afterPrefix;
|
|
1927
|
+
}
|
|
1928
|
+
return envKey;
|
|
1929
|
+
}
|
|
1930
|
+
function envKeyToConfigKey(envKey, prefix, componentName) {
|
|
1931
|
+
const prefixUpper = prefix.toUpperCase();
|
|
1932
|
+
if (!envKey.startsWith(prefixUpper)) {
|
|
1933
|
+
return;
|
|
1934
|
+
}
|
|
1935
|
+
const componentUpperNormalized = componentName.replace(/-/g, "_").toUpperCase();
|
|
1936
|
+
let keyPart = envKey.slice(prefixUpper.length);
|
|
1937
|
+
if (keyPart.startsWith("_")) {
|
|
1938
|
+
keyPart = keyPart.slice(1);
|
|
1939
|
+
}
|
|
1940
|
+
if (!keyPart) {
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
const firstUnderscore = keyPart.indexOf("_");
|
|
1944
|
+
let restPart;
|
|
1945
|
+
if (firstUnderscore === -1) {
|
|
1946
|
+
restPart = keyPart;
|
|
1947
|
+
} else {
|
|
1948
|
+
const firstPart = keyPart.slice(0, firstUnderscore);
|
|
1949
|
+
const remaining = keyPart.slice(firstUnderscore + 1);
|
|
1950
|
+
if (firstPart === componentUpperNormalized) {
|
|
1951
|
+
restPart = remaining;
|
|
1952
|
+
} else {
|
|
1953
|
+
restPart = keyPart;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
if (!restPart) {
|
|
1957
|
+
return;
|
|
1958
|
+
}
|
|
1959
|
+
const restPartConverted = restPart.replace(/_/g, ".");
|
|
1960
|
+
return `${componentName}.${restPartConverted.toLowerCase()}`;
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
// packages/core/src/env/tool/tool-config-registration.ts
|
|
1964
|
+
var TOOL_DEFAULTS = {
|
|
1965
|
+
"tool.toolsDir": ".roy/tools",
|
|
1966
|
+
"tool.builtInTools.enabled": true,
|
|
1967
|
+
"tool.builtInTools.loadAll": true,
|
|
1968
|
+
"tool.sandbox.enabled": false,
|
|
1969
|
+
"tool.sandbox.type": "native",
|
|
1970
|
+
"tool.execution.timeout": 30000,
|
|
1971
|
+
"tool.execution.maxConcurrency": 5
|
|
1972
|
+
};
|
|
1973
|
+
var TOOL_CONFIG_REGISTRATION = {
|
|
1974
|
+
name: "tool",
|
|
1975
|
+
sources: [
|
|
1976
|
+
{ type: "env", envPrefix: "TOOL", priority: 20, watch: false }
|
|
1977
|
+
],
|
|
1978
|
+
keys: [
|
|
1979
|
+
{ key: "tool.toolsDir", sources: ["env", "file"] },
|
|
1980
|
+
{ key: "tool.builtInTools.enabled", sources: ["env", "file"] },
|
|
1981
|
+
{ key: "tool.builtInTools.loadAll", sources: ["env", "file"] },
|
|
1982
|
+
{ key: "tool.sandbox.enabled", sources: ["env", "file"] },
|
|
1983
|
+
{ key: "tool.sandbox.type", sources: ["env", "file"] },
|
|
1984
|
+
{ key: "tool.execution.timeout", sources: ["env", "file"] },
|
|
1985
|
+
{ key: "tool.execution.maxConcurrency", sources: ["env", "file"] }
|
|
1986
|
+
]
|
|
1987
|
+
};
|
|
1988
|
+
|
|
1989
|
+
// packages/core/src/env/tool/tool-component.ts
|
|
1990
|
+
init_workflow_hil();
|
|
1991
|
+
var logger = createLogger("tool");
|
|
1992
|
+
|
|
1993
|
+
class ToolComponent extends BaseComponent {
|
|
1994
|
+
name = "tool";
|
|
1995
|
+
version = "1.0.0";
|
|
1996
|
+
registry;
|
|
1997
|
+
validator;
|
|
1998
|
+
config;
|
|
1999
|
+
configComponent;
|
|
2000
|
+
configWatcher;
|
|
2001
|
+
constructor() {
|
|
2002
|
+
super();
|
|
2003
|
+
this.registry = new ToolRegistry;
|
|
2004
|
+
this.validator = new ToolValidator;
|
|
2005
|
+
}
|
|
2006
|
+
async init(config) {
|
|
2007
|
+
await super.init(config);
|
|
2008
|
+
const options = config?.options;
|
|
2009
|
+
if (!options?.configComponent) {
|
|
2010
|
+
throw new Error("ConfigComponent is required for ToolComponent initialization");
|
|
2011
|
+
}
|
|
2012
|
+
this.configComponent = options.configComponent;
|
|
2013
|
+
await this.registerConfig(options);
|
|
2014
|
+
if (this.config?.builtInTools?.enabled !== false) {
|
|
2015
|
+
await this.loadBuiltInTools();
|
|
2016
|
+
}
|
|
2017
|
+
logger.info(`ToolComponent initialized with ${this.getToolCount()} tools`);
|
|
2018
|
+
}
|
|
2019
|
+
async registerConfig(options) {
|
|
2020
|
+
const configComponent = options.configComponent;
|
|
2021
|
+
if (!configComponent)
|
|
2022
|
+
return;
|
|
2023
|
+
const { configPath, envPrefix, config } = options;
|
|
2024
|
+
const prefix = envPrefix !== undefined ? envPrefix : "TOOL";
|
|
2025
|
+
configComponent.registerComponent(TOOL_CONFIG_REGISTRATION);
|
|
2026
|
+
if (configPath) {
|
|
2027
|
+
configComponent.registerSource({
|
|
2028
|
+
type: "file",
|
|
2029
|
+
relativePath: configPath,
|
|
2030
|
+
optional: true,
|
|
2031
|
+
watch: false
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2034
|
+
await configComponent.load("tool");
|
|
2035
|
+
const toolKeys = [
|
|
2036
|
+
"tool.toolsDir",
|
|
2037
|
+
"tool.builtInTools.enabled",
|
|
2038
|
+
"tool.builtInTools.loadAll",
|
|
2039
|
+
"tool.builtInTools.names",
|
|
2040
|
+
"tool.sandbox.enabled",
|
|
2041
|
+
"tool.sandbox.type",
|
|
2042
|
+
"tool.sandbox.defaultConfig",
|
|
2043
|
+
"tool.execution.timeout",
|
|
2044
|
+
"tool.execution.maxConcurrency"
|
|
2045
|
+
];
|
|
2046
|
+
for (const key of toolKeys) {
|
|
2047
|
+
const envKey = toEnvKey(key, prefix);
|
|
2048
|
+
const value = process.env[envKey];
|
|
2049
|
+
if (value !== undefined) {
|
|
2050
|
+
await configComponent.set(key, value);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
const envPrefixUpper = prefix.toUpperCase();
|
|
2054
|
+
for (const envKey of Object.keys(process.env)) {
|
|
2055
|
+
if (!envKey.startsWith(envPrefixUpper + "_"))
|
|
2056
|
+
continue;
|
|
2057
|
+
const configKey = envKeyToConfigKey(envKey, prefix, "tool");
|
|
2058
|
+
if (configKey && !toolKeys.includes(configKey)) {
|
|
2059
|
+
const value = process.env[envKey];
|
|
2060
|
+
if (value !== undefined) {
|
|
2061
|
+
await configComponent.set(configKey, value);
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
for (const [key, value] of Object.entries(TOOL_DEFAULTS)) {
|
|
2066
|
+
if (configComponent.get(key) === undefined) {
|
|
2067
|
+
await configComponent.set(key, value);
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
if (config) {
|
|
2071
|
+
const flatConfig = this.flattenConfig(config);
|
|
2072
|
+
for (const [key, value] of Object.entries(flatConfig)) {
|
|
2073
|
+
await configComponent.set(key, value);
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
this.registerConfigWatcher(configComponent);
|
|
2077
|
+
const configData = {};
|
|
2078
|
+
for (const key of toolKeys) {
|
|
2079
|
+
const value = configComponent.get(key);
|
|
2080
|
+
if (value !== undefined) {
|
|
2081
|
+
configData[key.replace(/^tool\./, "")] = value;
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
if (config) {
|
|
2085
|
+
Object.assign(configData, config);
|
|
2086
|
+
}
|
|
2087
|
+
const parsed = ToolComponentConfigSchema.safeParse(configData);
|
|
2088
|
+
if (parsed.success) {
|
|
2089
|
+
this.config = parsed.data;
|
|
2090
|
+
} else {
|
|
2091
|
+
this.config = config || {};
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
flattenConfig(obj, prefix = "tool") {
|
|
2095
|
+
const result = {};
|
|
2096
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2097
|
+
const fullKey = `${prefix}.${key}`;
|
|
2098
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
2099
|
+
Object.assign(result, this.flattenConfig(value, fullKey));
|
|
2100
|
+
} else {
|
|
2101
|
+
result[fullKey] = value;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
return result;
|
|
2105
|
+
}
|
|
2106
|
+
registerConfigWatcher(configComponent) {
|
|
2107
|
+
if (typeof configComponent.watch !== "function") {
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2110
|
+
this.configWatcher = configComponent.watch("tool.*", (event) => {
|
|
2111
|
+
this.onConfigChange(event);
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
onConfigChange(event) {
|
|
2115
|
+
logger.info(`Tool config changed: ${event.key}`, {
|
|
2116
|
+
oldValue: event.oldValue,
|
|
2117
|
+
newValue: event.newValue
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
2120
|
+
async onStop() {
|
|
2121
|
+
this.configWatcher?.();
|
|
2122
|
+
this.configWatcher = undefined;
|
|
2123
|
+
this.setStatus("stopped");
|
|
2124
|
+
}
|
|
2125
|
+
register(tool, source = "dynamic") {
|
|
2126
|
+
globalHookManager.execute(ToolHookPoints.BEFORE_REGISTER, { tool });
|
|
2127
|
+
this.registry.register(tool, {
|
|
2128
|
+
tool,
|
|
2129
|
+
registeredAt: Date.now(),
|
|
2130
|
+
source,
|
|
2131
|
+
enabled: true
|
|
2132
|
+
});
|
|
2133
|
+
logger.debug(`Registered tool: ${tool.name}`);
|
|
2134
|
+
globalHookManager.execute(ToolHookPoints.AFTER_REGISTER, { tool });
|
|
2135
|
+
}
|
|
2136
|
+
registerMany(tools, source = "dynamic") {
|
|
2137
|
+
for (const tool of tools) {
|
|
2138
|
+
this.register(tool, source);
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
unregister(name) {
|
|
2142
|
+
return this.registry.unregister(name);
|
|
2143
|
+
}
|
|
2144
|
+
getTool(name) {
|
|
2145
|
+
return this.registry.getTool(name)?.tool;
|
|
2146
|
+
}
|
|
2147
|
+
listTools(filter) {
|
|
2148
|
+
return this.registry.listTools(filter);
|
|
2149
|
+
}
|
|
2150
|
+
getToolCount() {
|
|
2151
|
+
return this.registry.getCount();
|
|
2152
|
+
}
|
|
2153
|
+
hasTool(name) {
|
|
2154
|
+
return this.registry.has(name);
|
|
2155
|
+
}
|
|
2156
|
+
getToolsByCategory(category) {
|
|
2157
|
+
return this.listTools({ category });
|
|
2158
|
+
}
|
|
2159
|
+
async execute(request) {
|
|
2160
|
+
const { name, args, context, skipHooks } = request;
|
|
2161
|
+
const registration = this.registry.getTool(name);
|
|
2162
|
+
if (!registration) {
|
|
2163
|
+
return {
|
|
2164
|
+
success: false,
|
|
2165
|
+
output: "",
|
|
2166
|
+
error: `Tool not found: ${name}`
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
if (!registration.enabled) {
|
|
2170
|
+
return {
|
|
2171
|
+
success: false,
|
|
2172
|
+
output: "",
|
|
2173
|
+
error: `Tool disabled: ${name}`
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
const tool = registration.tool;
|
|
2177
|
+
if (!skipHooks) {
|
|
2178
|
+
await globalHookManager.execute(ToolHookPoints.BEFORE_EXECUTE, { tool, args, context }, { toolName: tool.name });
|
|
2179
|
+
}
|
|
2180
|
+
const startTime = Date.now();
|
|
2181
|
+
try {
|
|
2182
|
+
const validationResult = await this.validator.validate(tool, args);
|
|
2183
|
+
if (!validationResult.success) {
|
|
2184
|
+
return {
|
|
2185
|
+
success: false,
|
|
2186
|
+
output: "",
|
|
2187
|
+
error: validationResult.error,
|
|
2188
|
+
metadata: {
|
|
2189
|
+
execution_time_ms: Date.now() - startTime
|
|
2190
|
+
}
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
const result = await tool.execute(validationResult.data, context);
|
|
2194
|
+
if (!result.metadata) {
|
|
2195
|
+
result.metadata = { execution_time_ms: Date.now() - startTime };
|
|
2196
|
+
} else {
|
|
2197
|
+
result.metadata.execution_time_ms = Date.now() - startTime;
|
|
2198
|
+
}
|
|
2199
|
+
if (!skipHooks) {
|
|
2200
|
+
await globalHookManager.execute(ToolHookPoints.AFTER_EXECUTE, { tool, args, context, result }, { toolName: tool.name });
|
|
2201
|
+
}
|
|
2202
|
+
return result;
|
|
2203
|
+
} catch (error) {
|
|
2204
|
+
if (error instanceof AskUserError) {
|
|
2205
|
+
throw error;
|
|
2206
|
+
}
|
|
2207
|
+
const errorResult = {
|
|
2208
|
+
success: false,
|
|
2209
|
+
output: "",
|
|
2210
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2211
|
+
metadata: {
|
|
2212
|
+
execution_time_ms: Date.now() - startTime
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
if (!skipHooks) {
|
|
2216
|
+
await globalHookManager.execute(ToolHookPoints.AFTER_EXECUTE, { tool, args, context, result: errorResult }, { toolName: tool.name });
|
|
2217
|
+
}
|
|
2218
|
+
if (!skipHooks) {
|
|
2219
|
+
await globalHookManager.execute(ToolHookPoints.ON_ERROR, { tool, args, context, error }, { toolName: tool.name });
|
|
2220
|
+
}
|
|
2221
|
+
return errorResult;
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
async loadBuiltInTools() {
|
|
2225
|
+
try {
|
|
2226
|
+
const { getAllBuiltInTools: getAllBuiltInTools2 } = await Promise.resolve().then(() => (init_built_in(), exports_built_in));
|
|
2227
|
+
const tools = getAllBuiltInTools2();
|
|
2228
|
+
this.registerMany(tools, "built-in");
|
|
2229
|
+
logger.info(`Loaded ${tools.length} built-in tools`);
|
|
2230
|
+
} catch (err) {
|
|
2231
|
+
logger.warn(`Failed to load built-in tools: ${err.message}`);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
getHookPoints() {
|
|
2235
|
+
return [
|
|
2236
|
+
ToolHookPoints.BEFORE_EXECUTE,
|
|
2237
|
+
ToolHookPoints.AFTER_EXECUTE,
|
|
2238
|
+
ToolHookPoints.BEFORE_REGISTER,
|
|
2239
|
+
ToolHookPoints.AFTER_REGISTER,
|
|
2240
|
+
ToolHookPoints.ON_ERROR
|
|
2241
|
+
];
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
var ToolComponentConfigSchema = z7.object({
|
|
2245
|
+
toolsDir: z7.string().optional(),
|
|
2246
|
+
builtInTools: z7.object({
|
|
2247
|
+
enabled: z7.boolean().default(true),
|
|
2248
|
+
loadAll: z7.boolean().default(true),
|
|
2249
|
+
names: z7.array(z7.string()).optional()
|
|
2250
|
+
}).default({}),
|
|
2251
|
+
sandbox: z7.object({
|
|
2252
|
+
enabled: z7.boolean().default(false),
|
|
2253
|
+
type: z7.enum(["native", "docker"]).default("native"),
|
|
2254
|
+
defaultConfig: z7.record(z7.unknown()).optional()
|
|
2255
|
+
}).default({}),
|
|
2256
|
+
execution: z7.object({
|
|
2257
|
+
timeout: z7.number().int().positive().default(60000),
|
|
2258
|
+
maxConcurrency: z7.number().int().positive().default(4)
|
|
2259
|
+
}).default({})
|
|
2260
|
+
});
|
|
2261
|
+
|
|
2262
|
+
// packages/core/src/env/tool/index.ts
|
|
2263
|
+
init_built_in();
|
|
2264
|
+
init_bash();
|
|
2265
|
+
init_echo();
|
|
2266
|
+
init_glob();
|
|
2267
|
+
init_read_file();
|
|
2268
|
+
init_write_file();
|
|
2269
|
+
init_edit_file();
|
|
2270
|
+
init_grep();
|
|
2271
|
+
export {
|
|
2272
|
+
writeFileTool,
|
|
2273
|
+
readFileTool,
|
|
2274
|
+
grepTool,
|
|
2275
|
+
globTool,
|
|
2276
|
+
getBuiltInTool,
|
|
2277
|
+
getAllBuiltInTools,
|
|
2278
|
+
editFileTool,
|
|
2279
|
+
echoTool,
|
|
2280
|
+
bashTool,
|
|
2281
|
+
ToolValidator,
|
|
2282
|
+
ToolRegistry,
|
|
2283
|
+
ToolComponent
|
|
2284
|
+
};
|