@ai-setting/roy-agent-core 1.5.37 → 1.5.41
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 +4 -3
- package/dist/env/agent/index.js +10 -9
- package/dist/env/commands/index.js +7 -6
- package/dist/env/context/index.js +21 -0
- package/dist/env/debug/index.js +4 -3
- package/dist/env/event-source/index.js +12 -6
- package/dist/env/hook/index.js +2 -1
- package/dist/env/index.js +41 -18
- package/dist/env/llm/index.js +8 -7
- package/dist/env/log-trace/index.js +10 -9
- package/dist/env/mcp/index.js +8 -7
- package/dist/env/mcp/tool/index.js +4 -4
- package/dist/env/memory/index.js +12 -11
- package/dist/env/memory/plugin/index.js +4 -4
- package/dist/env/plugin/index.js +18 -0
- package/dist/env/prompt/index.js +7 -6
- package/dist/env/session/index.js +11 -10
- package/dist/env/session/storage/index.js +2 -6
- package/dist/env/skill/index.js +7 -6
- package/dist/env/task/delegate/index.js +6 -5
- package/dist/env/task/index.js +10 -8
- package/dist/env/task/plugins/index.js +13 -6
- package/dist/env/task/storage/index.js +4 -4
- package/dist/env/tool/built-in/index.js +3 -3
- package/dist/env/tool/index.js +8 -7
- package/dist/env/workflow/engine/index.js +5 -5
- package/dist/env/workflow/index.js +9 -8
- package/dist/env/workflow/storage/index.js +5 -5
- package/dist/env/workflow/tools/index.js +3 -3
- package/dist/env/workflow/utils/index.js +4 -4
- package/dist/index.js +67 -60
- package/dist/shared/@ai-setting/{roy-agent-core-44hnfb02.js → roy-agent-core-10n2jh7p.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-xt3fx7m1.js → roy-agent-core-15x8fe5h.js} +38 -56
- package/dist/shared/@ai-setting/{roy-agent-core-1akcqxj9.js → roy-agent-core-1bfmxx89.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ty94k28r.js → roy-agent-core-2jnzv9at.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-cefh9hjv.js → roy-agent-core-4jqq077c.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-xs5rsgat.js → roy-agent-core-58k274fg.js} +108 -23
- package/dist/shared/@ai-setting/{roy-agent-core-jfh9q2qh.js → roy-agent-core-7b35emr7.js} +0 -15
- package/dist/shared/@ai-setting/{roy-agent-core-3rr5k71j.js → roy-agent-core-8n4bz6y3.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-zpn0bqa8.js → roy-agent-core-9ffsvvcf.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-az13yzmc.js +11 -0
- package/dist/shared/@ai-setting/{roy-agent-core-0wdjp769.js → roy-agent-core-b4wd9tn6.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-6kvtahqv.js → roy-agent-core-c3ct1346.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-psv4v63c.js → roy-agent-core-c6592r3c.js} +19 -2
- package/dist/shared/@ai-setting/{roy-agent-core-c2wjwx16.js → roy-agent-core-c8f2hync.js} +305 -287
- package/dist/shared/@ai-setting/roy-agent-core-cevpwnq7.js +147 -0
- package/dist/shared/@ai-setting/{roy-agent-core-hkb529dw.js → roy-agent-core-dxbsc1zy.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-vqspcspb.js → roy-agent-core-e130w7mv.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-3jywqmdd.js → roy-agent-core-e9fdm13a.js} +319 -65
- package/dist/shared/@ai-setting/{roy-agent-core-j0ke54vy.js → roy-agent-core-ee6nnnqw.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-qdmt6nz7.js → roy-agent-core-eg6nv09z.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-hd1z20yq.js → roy-agent-core-frx4p6d1.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-bvr1761x.js → roy-agent-core-hsxn8m1j.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-86gphny5.js → roy-agent-core-jqy2mdyq.js} +15 -1
- package/dist/shared/@ai-setting/{roy-agent-core-c0d3dtjd.js → roy-agent-core-kajktp3d.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-eajcvp4e.js → roy-agent-core-kwhv9dcd.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-r9ezzemr.js → roy-agent-core-m0wp34r4.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-fg1kxf70.js → roy-agent-core-nqgrjja0.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-mx489p7f.js → roy-agent-core-psvwzdhj.js} +263 -33
- package/dist/shared/@ai-setting/{roy-agent-core-d7cyjkf7.js → roy-agent-core-pwkk12p4.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-97ma0pr5.js → roy-agent-core-pxcrzyv9.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-zgypchmt.js → roy-agent-core-q5qj0fes.js} +19 -11
- package/dist/shared/@ai-setting/{roy-agent-core-sx7wsvnn.js → roy-agent-core-qakqwbbh.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-qfdp3pvq.js → roy-agent-core-rsybkb38.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-ty33mnr7.js +14 -0
- package/dist/shared/@ai-setting/{roy-agent-core-3prpabp8.js → roy-agent-core-v53rfk99.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-wjd5kars.js → roy-agent-core-wb43x8hd.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-e2vk2qh7.js → roy-agent-core-yc543gnq.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-gf2c2pxr.js → roy-agent-core-ycg9rk6z.js} +3 -3
- package/dist/shared/@ai-setting/roy-agent-core-z33en0cz.js +44 -0
- package/dist/shared/@ai-setting/{roy-agent-core-by55z88t.js → roy-agent-core-zrja5v78.js} +11 -11
- package/dist/shared/@ai-setting/{roy-agent-core-wft9ra24.js → roy-agent-core-zwp3jp02.js} +4 -4
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
BackgroundTaskManager,
|
|
3
3
|
createDelegateTool,
|
|
4
4
|
createStopTool
|
|
5
|
-
} from "./roy-agent-core-
|
|
5
|
+
} from "./roy-agent-core-v53rfk99.js";
|
|
6
6
|
import {
|
|
7
7
|
SQLiteTaskStore,
|
|
8
8
|
getDefaultTaskDbPath
|
|
9
|
-
} from "./roy-agent-core-
|
|
9
|
+
} from "./roy-agent-core-hsxn8m1j.js";
|
|
10
10
|
import {
|
|
11
11
|
completeTaskTool,
|
|
12
12
|
createTaskTool,
|
|
@@ -28,19 +28,26 @@ import {
|
|
|
28
28
|
import {
|
|
29
29
|
TaskEntityEventTypes
|
|
30
30
|
} from "./roy-agent-core-8gxth0eh.js";
|
|
31
|
+
import {
|
|
32
|
+
TracedAs,
|
|
33
|
+
init_decorator
|
|
34
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
31
35
|
import {
|
|
32
36
|
envKeyToConfigKey
|
|
33
37
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
34
38
|
import {
|
|
35
39
|
BaseComponent
|
|
36
|
-
} from "./roy-agent-core-
|
|
40
|
+
} from "./roy-agent-core-4jqq077c.js";
|
|
37
41
|
import {
|
|
38
42
|
globalHookManager
|
|
39
|
-
} from "./roy-agent-core-
|
|
43
|
+
} from "./roy-agent-core-jqy2mdyq.js";
|
|
40
44
|
import {
|
|
41
45
|
createLogger,
|
|
42
46
|
init_logger
|
|
43
|
-
} from "./roy-agent-core-
|
|
47
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
48
|
+
import {
|
|
49
|
+
__legacyDecorateClassTS
|
|
50
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
44
51
|
|
|
45
52
|
// src/env/task/task-component.ts
|
|
46
53
|
init_logger();
|
|
@@ -146,6 +153,7 @@ class DefaultTagService {
|
|
|
146
153
|
}
|
|
147
154
|
|
|
148
155
|
// src/env/task/task-component.ts
|
|
156
|
+
init_decorator();
|
|
149
157
|
var logger2 = createLogger("task");
|
|
150
158
|
|
|
151
159
|
class TaskComponent extends BaseComponent {
|
|
@@ -410,7 +418,7 @@ class TaskComponent extends BaseComponent {
|
|
|
410
418
|
return this.store.listTasks(options);
|
|
411
419
|
}
|
|
412
420
|
async completeTask(id, sessionId) {
|
|
413
|
-
const task = await this.
|
|
421
|
+
const task = await this.updateTask(id, {
|
|
414
422
|
status: "completed",
|
|
415
423
|
progress: 100
|
|
416
424
|
});
|
|
@@ -453,63 +461,37 @@ class TaskComponent extends BaseComponent {
|
|
|
453
461
|
getTagService() {
|
|
454
462
|
return this.tagService;
|
|
455
463
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
try {
|
|
465
|
-
const agents = getRequiredAgents();
|
|
466
|
-
for (const agentConfig of agents) {
|
|
467
|
-
agentComponent.registerAgent(agentConfig.name, agentConfig);
|
|
468
|
-
}
|
|
469
|
-
} catch (err) {
|
|
470
|
-
logger2.warn(`Failed to auto-register agents for plugin ${plugin.name}: ${err}`);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
for (const hook of plugin.hooks) {
|
|
475
|
-
const pluginConfig = plugin.config;
|
|
476
|
-
const priority = hook.priority ?? pluginConfig?.priority ?? 0;
|
|
477
|
-
const hookName = `${this.name}:${plugin.name}:${hook.point}`;
|
|
478
|
-
const pluginRef = plugin;
|
|
479
|
-
globalHookManager.register(hook.point, {
|
|
480
|
-
name: hookName,
|
|
481
|
-
priority,
|
|
482
|
-
execute: async (ctx) => {
|
|
483
|
-
const pluginCtx = {
|
|
484
|
-
component: ctx.component,
|
|
485
|
-
data: ctx.data,
|
|
486
|
-
metadata: ctx.metadata,
|
|
487
|
-
phase: ctx.phase,
|
|
488
|
-
hookPoint: hook.point
|
|
489
|
-
};
|
|
490
|
-
await pluginRef.execute(pluginCtx);
|
|
491
|
-
}
|
|
492
|
-
});
|
|
464
|
+
registerHook(hookPoint, hook) {
|
|
465
|
+
globalHookManager.register(hookPoint, hook);
|
|
466
|
+
this.plugins.set(this.makePluginKey(hookPoint, hook.name), hook);
|
|
467
|
+
logger2.debug(`[TaskComponent] Registered hook: ${hook.name} at ${hookPoint}`);
|
|
468
|
+
}
|
|
469
|
+
registerHooks(hooks) {
|
|
470
|
+
for (const { hookPoint, hook } of hooks) {
|
|
471
|
+
this.registerHook(hookPoint, hook);
|
|
493
472
|
}
|
|
494
|
-
logger2.info(`[TaskComponent] Registered plugin: ${plugin.name}`, {
|
|
495
|
-
hooks: plugin.hooks.map((h) => h.point)
|
|
496
|
-
});
|
|
497
473
|
}
|
|
498
|
-
|
|
499
|
-
const
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
globalHookManager.unregister(hook.point, `${this.name}:${name}`);
|
|
474
|
+
unregisterHook(hookPoint, hookName) {
|
|
475
|
+
const removed = globalHookManager.unregister(hookPoint, hookName);
|
|
476
|
+
if (removed) {
|
|
477
|
+
this.plugins.delete(this.makePluginKey(hookPoint, hookName));
|
|
478
|
+
logger2.info(`[TaskComponent] Unregistered hook: ${hookName} from ${hookPoint}`);
|
|
504
479
|
}
|
|
505
|
-
|
|
506
|
-
logger2.info(`[TaskComponent] Unregistered plugin: ${name}`);
|
|
507
|
-
return true;
|
|
480
|
+
return removed;
|
|
508
481
|
}
|
|
509
|
-
|
|
482
|
+
listHooks() {
|
|
510
483
|
return Array.from(this.plugins.values());
|
|
511
484
|
}
|
|
485
|
+
makePluginKey(hookPoint, hookName) {
|
|
486
|
+
return `${hookPoint}::${hookName}`;
|
|
487
|
+
}
|
|
488
|
+
countHooks(hookPoint) {
|
|
489
|
+
return globalHookManager.count(hookPoint);
|
|
490
|
+
}
|
|
512
491
|
}
|
|
492
|
+
__legacyDecorateClassTS([
|
|
493
|
+
TracedAs("task.component.executeHook", { recordParams: true })
|
|
494
|
+
], TaskComponent.prototype, "executeHook", null);
|
|
513
495
|
// src/env/task/types.ts
|
|
514
496
|
import { z } from "zod";
|
|
515
497
|
var TaskStatusEnum = z.enum(["todo", "active", "completed", "paused", "cancelled"]);
|
|
@@ -23,11 +23,11 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
TracedAs,
|
|
25
25
|
init_decorator
|
|
26
|
-
} from "./roy-agent-core-
|
|
26
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
27
27
|
import {
|
|
28
28
|
createLogger,
|
|
29
29
|
init_logger
|
|
30
|
-
} from "./roy-agent-core-
|
|
30
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
31
31
|
import {
|
|
32
32
|
__esm,
|
|
33
33
|
__export,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SQLiteSpanStorage,
|
|
3
3
|
init_span_storage
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-c6592r3c.js";
|
|
5
5
|
import {
|
|
6
6
|
__esm,
|
|
7
7
|
__export,
|
|
@@ -95,6 +95,9 @@ __export(exports_tracer_provider, {
|
|
|
95
95
|
getTracerProvider: () => getTracerProvider,
|
|
96
96
|
OTelTracerProvider: () => OTelTracerProvider
|
|
97
97
|
});
|
|
98
|
+
function isOtelTraceDebugEnabled() {
|
|
99
|
+
return process.env.ROY_TRACE_DEBUG_OTEL === "1" || process.env.ROY_TRACE_DEBUG === "1";
|
|
100
|
+
}
|
|
98
101
|
|
|
99
102
|
class OTelSpanImpl {
|
|
100
103
|
name;
|
|
@@ -129,19 +132,40 @@ class OTelSpanImpl {
|
|
|
129
132
|
if (error) {
|
|
130
133
|
this.error = error.message;
|
|
131
134
|
}
|
|
132
|
-
this.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
135
|
+
const duration = this.endTime - (this.startTime || 0);
|
|
136
|
+
if (isOtelTraceDebugEnabled()) {
|
|
137
|
+
console.log(`[OTelSpan] Ending span: name="${this.name}" traceId=${this.spanContext.traceId} spanId=${this.spanContext.spanId} duration=${duration}ms status=${error ? "ERROR" : "OK"}`);
|
|
138
|
+
}
|
|
139
|
+
let storage = this.storage;
|
|
140
|
+
if (!storage) {
|
|
141
|
+
console.warn(`[OTelSpan] storage is null for "${this.name}", attempting to re-fetch...`);
|
|
142
|
+
const provider = getTracerProvider();
|
|
143
|
+
storage = provider.getStorage();
|
|
144
|
+
}
|
|
145
|
+
if (storage) {
|
|
146
|
+
const isInitialized = storage.db || storage.initialized;
|
|
147
|
+
if (!isInitialized) {
|
|
148
|
+
console.warn(`[OTelSpan] storage not initialized for "${this.name}", initializing now...`);
|
|
149
|
+
storage.initialize().catch((err) => {
|
|
150
|
+
console.error(`[OTelSpan] Failed to initialize storage:`, err);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
storage.save({
|
|
154
|
+
traceId: this.spanContext.traceId,
|
|
155
|
+
spanId: this.spanContext.spanId,
|
|
156
|
+
parentSpanId: this.spanContext.parentSpanId,
|
|
157
|
+
name: this.name,
|
|
158
|
+
kind: this.kind,
|
|
159
|
+
status: error ? "error" /* ERROR */ : "ok" /* OK */,
|
|
160
|
+
startTime: this.startTime,
|
|
161
|
+
endTime: this.endTime,
|
|
162
|
+
attributes: this.attributes,
|
|
163
|
+
result,
|
|
164
|
+
error: this.error
|
|
165
|
+
});
|
|
166
|
+
} else {
|
|
167
|
+
console.error(`[OTelSpan] Failed to save span "${this.name}": storage still null after re-fetch`);
|
|
168
|
+
}
|
|
145
169
|
this.onEnd?.();
|
|
146
170
|
}
|
|
147
171
|
}
|
|
@@ -154,11 +178,13 @@ class OTelTracerImpl {
|
|
|
154
178
|
activeSpans = new Map;
|
|
155
179
|
onSpanEndCallback;
|
|
156
180
|
provider;
|
|
181
|
+
instanceId;
|
|
157
182
|
constructor(name, version, storage, provider) {
|
|
158
183
|
this.name = name;
|
|
159
184
|
this.version = version;
|
|
160
185
|
this.storage = storage;
|
|
161
186
|
this.provider = provider;
|
|
187
|
+
this.instanceId = `${name}@${provider.instanceId}`;
|
|
162
188
|
}
|
|
163
189
|
setOnSpanEndCallback(callback) {
|
|
164
190
|
this.onSpanEndCallback = callback;
|
|
@@ -169,8 +195,37 @@ class OTelTracerImpl {
|
|
|
169
195
|
startSpan(name, options) {
|
|
170
196
|
const parentFromOptions = options?.parent;
|
|
171
197
|
const hasExplicitParent = options && "parent" in options;
|
|
198
|
+
const hasExplicitContext = options && "context" in options;
|
|
172
199
|
const globalContext = this.provider.getGlobalContext();
|
|
173
200
|
let effectiveParentContext;
|
|
201
|
+
let traceId;
|
|
202
|
+
let spanId;
|
|
203
|
+
let parentSpanId;
|
|
204
|
+
let spanContext;
|
|
205
|
+
if (hasExplicitContext && options?.context) {
|
|
206
|
+
const injectedContext = options.context;
|
|
207
|
+
traceId = injectedContext.traceId;
|
|
208
|
+
spanId = this.generateSpanId();
|
|
209
|
+
parentSpanId = injectedContext.spanId;
|
|
210
|
+
spanContext = {
|
|
211
|
+
traceId,
|
|
212
|
+
spanId,
|
|
213
|
+
parentSpanId
|
|
214
|
+
};
|
|
215
|
+
this.currentContext = {
|
|
216
|
+
traceId,
|
|
217
|
+
spanId,
|
|
218
|
+
parentSpanId
|
|
219
|
+
};
|
|
220
|
+
const span2 = new OTelSpanImpl(name, spanContext, this.storage, injectedContext, () => this.handleSpanEnd(spanContext.spanId, injectedContext.spanId));
|
|
221
|
+
if (options?.attributes) {
|
|
222
|
+
for (const [key, value] of Object.entries(options.attributes)) {
|
|
223
|
+
span2.setAttribute(key, value);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
this.activeSpans.set(spanId, span2);
|
|
227
|
+
return span2;
|
|
228
|
+
}
|
|
174
229
|
if (hasExplicitParent) {
|
|
175
230
|
effectiveParentContext = parentFromOptions;
|
|
176
231
|
} else if (this.currentContext) {
|
|
@@ -178,9 +233,8 @@ class OTelTracerImpl {
|
|
|
178
233
|
} else if (globalContext) {
|
|
179
234
|
effectiveParentContext = globalContext;
|
|
180
235
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
let parentSpanId;
|
|
236
|
+
traceId = effectiveParentContext?.traceId || this.generateTraceId();
|
|
237
|
+
spanId = this.generateSpanId();
|
|
184
238
|
if (hasExplicitParent && parentFromOptions) {
|
|
185
239
|
parentSpanId = parentFromOptions.parentSpanId || parentFromOptions.spanId;
|
|
186
240
|
} else if (this.currentContext) {
|
|
@@ -188,7 +242,7 @@ class OTelTracerImpl {
|
|
|
188
242
|
} else if (globalContext) {
|
|
189
243
|
parentSpanId = globalContext.spanId;
|
|
190
244
|
}
|
|
191
|
-
|
|
245
|
+
spanContext = {
|
|
192
246
|
traceId,
|
|
193
247
|
spanId,
|
|
194
248
|
parentSpanId
|
|
@@ -205,6 +259,9 @@ class OTelTracerImpl {
|
|
|
205
259
|
}
|
|
206
260
|
}
|
|
207
261
|
this.activeSpans.set(spanId, span);
|
|
262
|
+
if (isOtelTraceDebugEnabled()) {
|
|
263
|
+
console.log(`[OTelTracer] ✓ Span created: name="${name}" traceId=${traceId} spanId=${spanId} parentSpanId=${parentSpanId || "-"}`);
|
|
264
|
+
}
|
|
208
265
|
return span;
|
|
209
266
|
}
|
|
210
267
|
injectToEnv(env) {
|
|
@@ -218,6 +275,14 @@ class OTelTracerImpl {
|
|
|
218
275
|
setCurrentContext(context) {
|
|
219
276
|
this.currentContext = context;
|
|
220
277
|
}
|
|
278
|
+
findStackParentSpan(spanId) {
|
|
279
|
+
for (const [, span] of this.activeSpans) {
|
|
280
|
+
if (span.spanContext.parentSpanId === spanId) {
|
|
281
|
+
return span;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
221
286
|
endSpan(span) {
|
|
222
287
|
const spanContext = span.spanContext;
|
|
223
288
|
this.activeSpans.delete(spanContext.spanId);
|
|
@@ -243,6 +308,16 @@ class OTelTracerImpl {
|
|
|
243
308
|
return parentContext;
|
|
244
309
|
}
|
|
245
310
|
}
|
|
311
|
+
const stackParentSpan = this.findStackParentSpan(spanContext.spanId);
|
|
312
|
+
if (stackParentSpan) {
|
|
313
|
+
const parentContext = {
|
|
314
|
+
traceId: stackParentSpan.spanContext.traceId,
|
|
315
|
+
spanId: stackParentSpan.spanContext.spanId,
|
|
316
|
+
parentSpanId: stackParentSpan.spanContext.parentSpanId
|
|
317
|
+
};
|
|
318
|
+
this.currentContext = parentContext;
|
|
319
|
+
return parentContext;
|
|
320
|
+
}
|
|
246
321
|
this.currentContext = undefined;
|
|
247
322
|
return;
|
|
248
323
|
}
|
|
@@ -255,8 +330,6 @@ class OTelTracerImpl {
|
|
|
255
330
|
return Math.floor(Math.random() * 18446744073709552000).toString(16).padStart(16, "0");
|
|
256
331
|
}
|
|
257
332
|
handleSpanEnd(spanId, parentSpanId) {
|
|
258
|
-
this.activeSpans.delete(spanId);
|
|
259
|
-
const currentTraceId = this.currentContext?.traceId;
|
|
260
333
|
if (parentSpanId) {
|
|
261
334
|
const parentSpan = this.activeSpans.get(parentSpanId);
|
|
262
335
|
if (parentSpan) {
|
|
@@ -267,15 +340,24 @@ class OTelTracerImpl {
|
|
|
267
340
|
};
|
|
268
341
|
return;
|
|
269
342
|
}
|
|
270
|
-
if (
|
|
343
|
+
if (this.currentContext?.traceId) {
|
|
271
344
|
this.currentContext = {
|
|
272
|
-
traceId:
|
|
345
|
+
traceId: this.currentContext.traceId,
|
|
273
346
|
spanId: parentSpanId,
|
|
274
347
|
parentSpanId: undefined
|
|
275
348
|
};
|
|
276
349
|
return;
|
|
277
350
|
}
|
|
278
351
|
}
|
|
352
|
+
const stackParentSpan = this.findStackParentSpan(spanId);
|
|
353
|
+
if (stackParentSpan) {
|
|
354
|
+
this.currentContext = {
|
|
355
|
+
traceId: stackParentSpan.spanContext.traceId,
|
|
356
|
+
spanId: stackParentSpan.spanContext.spanId,
|
|
357
|
+
parentSpanId: stackParentSpan.spanContext.parentSpanId
|
|
358
|
+
};
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
279
361
|
this.currentContext = undefined;
|
|
280
362
|
}
|
|
281
363
|
}
|
|
@@ -285,7 +367,10 @@ class OTelTracerProvider {
|
|
|
285
367
|
storage;
|
|
286
368
|
initialized = false;
|
|
287
369
|
globalContext;
|
|
370
|
+
instanceId;
|
|
288
371
|
constructor(storage, dbPath) {
|
|
372
|
+
providerCounter++;
|
|
373
|
+
this.instanceId = `Provider#${providerCounter}`;
|
|
289
374
|
this.storage = storage || new SQLiteSpanStorage(dbPath || getDefaultDbPath());
|
|
290
375
|
}
|
|
291
376
|
async initialize() {
|
|
@@ -358,7 +443,7 @@ function getDefaultDbPath() {
|
|
|
358
443
|
const dataHome = process.env.XDG_DATA_HOME || path.join(home, ".local", "share");
|
|
359
444
|
return path.join(dataHome, "roy-agent", "traces.db");
|
|
360
445
|
}
|
|
361
|
-
var providerInstance = null;
|
|
446
|
+
var providerInstance = null, providerCounter = 0;
|
|
362
447
|
var init_tracer_provider = __esm(() => {
|
|
363
448
|
init_span_storage();
|
|
364
449
|
init_propagation();
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TracedAs,
|
|
3
|
-
init_decorator
|
|
4
|
-
} from "./roy-agent-core-zgypchmt.js";
|
|
5
|
-
import {
|
|
6
|
-
__legacyDecorateClassTS
|
|
7
|
-
} from "./roy-agent-core-fs0mn2jk.js";
|
|
8
|
-
|
|
9
1
|
// src/env/session/session-message-converter.ts
|
|
10
|
-
init_decorator();
|
|
11
2
|
import { randomUUID } from "crypto";
|
|
12
3
|
var DEFAULT_REASONING_BUDGET_TOKENS = 1e4;
|
|
13
4
|
|
|
@@ -194,11 +185,5 @@ class SessionMessageConverter {
|
|
|
194
185
|
};
|
|
195
186
|
}
|
|
196
187
|
}
|
|
197
|
-
__legacyDecorateClassTS([
|
|
198
|
-
TracedAs("session-message-converter.toModelMessage", { recordParams: true, recordResult: true, log: true })
|
|
199
|
-
], SessionMessageConverter.prototype, "toModelMessage", null);
|
|
200
|
-
__legacyDecorateClassTS([
|
|
201
|
-
TracedAs("session-message-converter.fromModelMessage", { recordParams: true, recordResult: true, log: true })
|
|
202
|
-
], SessionMessageConverter.prototype, "fromModelMessage", null);
|
|
203
188
|
|
|
204
189
|
export { SessionMessageConverter };
|
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
5
5
|
import {
|
|
6
6
|
BaseComponent
|
|
7
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-4jqq077c.js";
|
|
8
8
|
import {
|
|
9
9
|
createLogger,
|
|
10
10
|
init_logger
|
|
11
|
-
} from "./roy-agent-core-
|
|
11
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
12
12
|
|
|
13
13
|
// src/env/commands/commands-component.ts
|
|
14
14
|
import path2 from "path";
|
|
@@ -4,6 +4,9 @@ import {
|
|
|
4
4
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
5
5
|
|
|
6
6
|
// src/env/log-trace/span-storage.ts
|
|
7
|
+
function isSpanStorageDebugEnabled() {
|
|
8
|
+
return process.env.ROY_TRACE_DEBUG_STORAGE === "1" || process.env.ROY_TRACE_DEBUG === "1";
|
|
9
|
+
}
|
|
7
10
|
function getDatabaseClass() {
|
|
8
11
|
if (typeof Bun !== "undefined") {
|
|
9
12
|
const { Database } = __require("bun:sqlite");
|
|
@@ -74,15 +77,29 @@ class SQLiteSpanStorage {
|
|
|
74
77
|
this.initialized = true;
|
|
75
78
|
}
|
|
76
79
|
save(span) {
|
|
77
|
-
if (!this.db)
|
|
80
|
+
if (!this.db) {
|
|
81
|
+
if (isSpanStorageDebugEnabled()) {
|
|
82
|
+
console.log(`[SpanStorage] save() skipped: db not initialized for span "${span.name}" traceId=${span.traceId}`);
|
|
83
|
+
}
|
|
78
84
|
return;
|
|
85
|
+
}
|
|
79
86
|
const stmt = this.db.prepare(`
|
|
80
87
|
INSERT OR REPLACE INTO span
|
|
81
88
|
(span_id, trace_id, parent_span_id, name, kind, status, start_time, end_time, attributes, result, error, time_created)
|
|
82
89
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
83
90
|
`);
|
|
84
91
|
const resultValue = span.result !== undefined && span.result !== null ? typeof span.result === "string" ? span.result : JSON.stringify(span.result) : null;
|
|
85
|
-
|
|
92
|
+
if (isSpanStorageDebugEnabled()) {
|
|
93
|
+
console.log(`[SpanStorage] Saving to "${this.dbPath}": name="${span.name}" traceId=${span.traceId} spanId=${span.spanId} status=${span.status}`);
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const result = 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());
|
|
97
|
+
if (isSpanStorageDebugEnabled()) {
|
|
98
|
+
console.log(`[SpanStorage] Save result: changes=${result?.changes}, lastInsertRowid=${result?.lastInsertRowid}`);
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
console.error(`[SpanStorage] Save ERROR:`, err);
|
|
102
|
+
}
|
|
86
103
|
}
|
|
87
104
|
saveBatch(spans) {
|
|
88
105
|
for (const span of spans) {
|