@cognipeer/agent-sdk 0.18.0 → 0.19.0
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/index.cjs +19 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -7
- package/dist/index.d.ts +12 -7
- package/dist/index.mjs +19 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1258,7 +1258,7 @@ function cacheWriteTokensOf(raw) {
|
|
|
1258
1258
|
init_content();
|
|
1259
1259
|
|
|
1260
1260
|
// src/version.ts
|
|
1261
|
-
var SDK_VERSION = "0.
|
|
1261
|
+
var SDK_VERSION = "0.19.0";
|
|
1262
1262
|
|
|
1263
1263
|
// src/utils/otlp/content.ts
|
|
1264
1264
|
init_content();
|
|
@@ -1752,7 +1752,7 @@ function sessionToOtlp(file, options) {
|
|
|
1752
1752
|
const agentName = file.agent?.name;
|
|
1753
1753
|
const everyEvent = file.events;
|
|
1754
1754
|
const exportedEvents = foldSupersededSpans(everyEvent).filter(
|
|
1755
|
-
(event) => options.terminal || !(event.type === "span" && event.status === "pending")
|
|
1755
|
+
(event) => options.terminal || !(event.type === "span" && (event.status === "pending" || event.status === "running"))
|
|
1756
1756
|
);
|
|
1757
1757
|
const startMs = parseMs(file.startedAt);
|
|
1758
1758
|
const nodes = exportedEvents.map((event) => {
|
|
@@ -3766,7 +3766,9 @@ function foldSupersededSpans(events) {
|
|
|
3766
3766
|
const current = winner.get(id);
|
|
3767
3767
|
if (current === void 0 || rank(events[i], i) >= rank(events[current], current)) winner.set(id, i);
|
|
3768
3768
|
}
|
|
3769
|
-
return events.filter(
|
|
3769
|
+
return events.filter(
|
|
3770
|
+
(event, i) => !(event.spanId && (event.status === "pending" || event.status === "running") && winner.get(event.spanId) !== i)
|
|
3771
|
+
);
|
|
3770
3772
|
}
|
|
3771
3773
|
function recordOrDeferTraceEvent(ctx, event, options) {
|
|
3772
3774
|
const session = ctx?.__traceSession;
|
|
@@ -10544,14 +10546,16 @@ function createAgent(opts) {
|
|
|
10544
10546
|
const startedAt = Date.now();
|
|
10545
10547
|
const recordSpan = (status, extra) => {
|
|
10546
10548
|
if (!traced || !isTraceSessionOpen(parentSession)) return;
|
|
10549
|
+
const running = status === "running";
|
|
10547
10550
|
recordSubagentSpan(parentSession, {
|
|
10548
10551
|
spanId: agentSpanId,
|
|
10549
|
-
|
|
10552
|
+
// The delegating tool_call span only exists once the tool returns.
|
|
10553
|
+
parentSpanId: running ? parentIterationSpanId : context?.traceSpanId ?? parentIterationSpanId,
|
|
10550
10554
|
name: opts.name || "agent",
|
|
10551
10555
|
status,
|
|
10552
|
-
durationMs: Date.now() - startedAt,
|
|
10556
|
+
durationMs: running ? void 0 : Date.now() - startedAt,
|
|
10553
10557
|
error: extra.error,
|
|
10554
|
-
info: { name: opts.name || "agent", mode: "asTool", depth: currentDepth + 1, parentToolCallId: context?.toolCallId, status: status === "success" ? "ok" : "error" },
|
|
10558
|
+
info: { name: opts.name || "agent", mode: "asTool", depth: currentDepth + 1, parentToolCallId: context?.toolCallId, status: running ? "running" : status === "success" ? "ok" : "error" },
|
|
10555
10559
|
task: input,
|
|
10556
10560
|
result: extra.result
|
|
10557
10561
|
});
|
|
@@ -10571,6 +10575,7 @@ function createAgent(opts) {
|
|
|
10571
10575
|
stream: Boolean(parentCtx.__streaming),
|
|
10572
10576
|
cancellationToken: parentCtx.__cancellationToken ?? parentCtx.__abortSignal
|
|
10573
10577
|
};
|
|
10578
|
+
recordSpan("running", {});
|
|
10574
10579
|
let res;
|
|
10575
10580
|
try {
|
|
10576
10581
|
res = await instance.invoke({ messages: childMessages, ctx: childCtx }, childConfig);
|
|
@@ -12771,14 +12776,16 @@ async function runChild(spec, input, deps, ref, opts) {
|
|
|
12771
12776
|
const traceScope = traced ? createSubagentTraceScope(parentSession, { agentSpanId, name: spec.name, spawnId, mode: spec.mode, hitl: opts.allowHITL, iterations: opts.record?.iterations }) : void 0;
|
|
12772
12777
|
const recordSegment = (status, info) => {
|
|
12773
12778
|
if (!traced || !isTraceSessionOpen(parentSession)) return;
|
|
12779
|
+
const unfinished = status === "pending" || status === "running";
|
|
12774
12780
|
recordSubagentSpan(parentSession, {
|
|
12775
12781
|
spanId: agentSpanId,
|
|
12776
|
-
// The tool_call span only exists once the tool returns; a
|
|
12777
|
-
// has not returned, so its span hangs off the iteration.
|
|
12778
|
-
parentSpanId:
|
|
12782
|
+
// The tool_call span only exists once the tool returns; a running or
|
|
12783
|
+
// paused child has not returned, so its span hangs off the iteration.
|
|
12784
|
+
parentSpanId: unfinished ? parentIterationSpanId : opts.parentSpanId ?? parentIterationSpanId,
|
|
12779
12785
|
name: spec.name,
|
|
12780
12786
|
status,
|
|
12781
|
-
|
|
12787
|
+
// A starting segment has no extent yet; a reader draws it over its children.
|
|
12788
|
+
durationMs: status === "running" ? void 0 : elapsedMs(),
|
|
12782
12789
|
error: info.error,
|
|
12783
12790
|
info: {
|
|
12784
12791
|
id: spawnId,
|
|
@@ -12789,7 +12796,7 @@ async function runChild(spec, input, deps, ref, opts) {
|
|
|
12789
12796
|
parentToolCallId: opts.parentToolCallId,
|
|
12790
12797
|
status: info.subagentStatus,
|
|
12791
12798
|
// Only a run that paused has more than one segment to tell about.
|
|
12792
|
-
...segment > 1 ||
|
|
12799
|
+
...segment > 1 || unfinished ? { segments: segment } : {},
|
|
12793
12800
|
...info.note ? { note: info.note } : {},
|
|
12794
12801
|
...spec.metadata ? { metadata: spec.metadata } : {}
|
|
12795
12802
|
},
|
|
@@ -12913,6 +12920,7 @@ async function runChild(spec, input, deps, ref, opts) {
|
|
|
12913
12920
|
}
|
|
12914
12921
|
if (traceScope) childInput = { ...childInput, ctx: { ...childInput.ctx || {}, __traceSession: traceScope } };
|
|
12915
12922
|
const usageBaseline = childInput.usage?.perRequest?.length ?? 0;
|
|
12923
|
+
recordSegment("running", { subagentStatus: "running", input });
|
|
12916
12924
|
let res;
|
|
12917
12925
|
try {
|
|
12918
12926
|
res = await child.invoke(childInput, childConfig);
|