@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.d.cts
CHANGED
|
@@ -2354,9 +2354,12 @@ type TraceEventRecord = {
|
|
|
2354
2354
|
* A sub-agent's span (type span, actor.role subagent) is also pending while its
|
|
2355
2355
|
* run waits; the segment that ends the run records it again under the SAME
|
|
2356
2356
|
* spanId, finished. Draw one record per spanId: the highest sequence, dropping
|
|
2357
|
-
* earlier pending ones (foldSupersededSpans).
|
|
2357
|
+
* earlier pending and running ones (foldSupersededSpans).
|
|
2358
|
+
* `running`: a sub-agent's span recorded when a segment of its run starts, so a
|
|
2359
|
+
* reader of a trace streamed while the run goes has the group its steps point
|
|
2360
|
+
* at. The record that ends (or pauses) the segment supersedes it.
|
|
2358
2361
|
*/
|
|
2359
|
-
status: "success" | "error" | "skipped" | "retry" | "pending";
|
|
2362
|
+
status: "success" | "error" | "skipped" | "retry" | "pending" | "running";
|
|
2360
2363
|
durationMs?: number;
|
|
2361
2364
|
inputTokens?: number;
|
|
2362
2365
|
outputTokens?: number;
|
|
@@ -6099,11 +6102,13 @@ declare function isTraceSessionOpen(session: TraceSessionRuntime | undefined): s
|
|
|
6099
6102
|
* segments, and records are append-only: each pause records the run's agent span
|
|
6100
6103
|
* `pending`, and the segment that ends the run records it again under the SAME
|
|
6101
6104
|
* `spanId`, finished, with `durationMs` covering the run from its first segment
|
|
6102
|
-
* (so the span is drawn over its children from every segment, the wait included).
|
|
6103
|
-
*
|
|
6104
|
-
*
|
|
6105
|
-
*
|
|
6106
|
-
*
|
|
6105
|
+
* (so the span is drawn over its children from every segment, the wait included).
|
|
6106
|
+
* Each segment also opens with a `running` record of the span, so a trace read
|
|
6107
|
+
* while the run goes (a streamed one) has the group the child's steps point at
|
|
6108
|
+
* before the run ends. The rule for a reader: for each `spanId` the record with
|
|
6109
|
+
* the highest `sequence` wins, and an earlier record of that id is dropped only
|
|
6110
|
+
* when it is `pending` or `running`. Nothing else is ever dropped, so a repeated
|
|
6111
|
+
* id on records that are neither comes back untouched. Order is preserved.
|
|
6107
6112
|
*
|
|
6108
6113
|
* The session summary is not rewritten: `eventCounts` keeps counting every record
|
|
6109
6114
|
* that was written, which is what the file holds.
|
package/dist/index.d.ts
CHANGED
|
@@ -2354,9 +2354,12 @@ type TraceEventRecord = {
|
|
|
2354
2354
|
* A sub-agent's span (type span, actor.role subagent) is also pending while its
|
|
2355
2355
|
* run waits; the segment that ends the run records it again under the SAME
|
|
2356
2356
|
* spanId, finished. Draw one record per spanId: the highest sequence, dropping
|
|
2357
|
-
* earlier pending ones (foldSupersededSpans).
|
|
2357
|
+
* earlier pending and running ones (foldSupersededSpans).
|
|
2358
|
+
* `running`: a sub-agent's span recorded when a segment of its run starts, so a
|
|
2359
|
+
* reader of a trace streamed while the run goes has the group its steps point
|
|
2360
|
+
* at. The record that ends (or pauses) the segment supersedes it.
|
|
2358
2361
|
*/
|
|
2359
|
-
status: "success" | "error" | "skipped" | "retry" | "pending";
|
|
2362
|
+
status: "success" | "error" | "skipped" | "retry" | "pending" | "running";
|
|
2360
2363
|
durationMs?: number;
|
|
2361
2364
|
inputTokens?: number;
|
|
2362
2365
|
outputTokens?: number;
|
|
@@ -6099,11 +6102,13 @@ declare function isTraceSessionOpen(session: TraceSessionRuntime | undefined): s
|
|
|
6099
6102
|
* segments, and records are append-only: each pause records the run's agent span
|
|
6100
6103
|
* `pending`, and the segment that ends the run records it again under the SAME
|
|
6101
6104
|
* `spanId`, finished, with `durationMs` covering the run from its first segment
|
|
6102
|
-
* (so the span is drawn over its children from every segment, the wait included).
|
|
6103
|
-
*
|
|
6104
|
-
*
|
|
6105
|
-
*
|
|
6106
|
-
*
|
|
6105
|
+
* (so the span is drawn over its children from every segment, the wait included).
|
|
6106
|
+
* Each segment also opens with a `running` record of the span, so a trace read
|
|
6107
|
+
* while the run goes (a streamed one) has the group the child's steps point at
|
|
6108
|
+
* before the run ends. The rule for a reader: for each `spanId` the record with
|
|
6109
|
+
* the highest `sequence` wins, and an earlier record of that id is dropped only
|
|
6110
|
+
* when it is `pending` or `running`. Nothing else is ever dropped, so a repeated
|
|
6111
|
+
* id on records that are neither comes back untouched. Order is preserved.
|
|
6107
6112
|
*
|
|
6108
6113
|
* The session summary is not rewritten: `eventCounts` keeps counting every record
|
|
6109
6114
|
* that was written, which is what the file holds.
|
package/dist/index.mjs
CHANGED
|
@@ -1248,7 +1248,7 @@ function cacheWriteTokensOf(raw) {
|
|
|
1248
1248
|
init_content();
|
|
1249
1249
|
|
|
1250
1250
|
// src/version.ts
|
|
1251
|
-
var SDK_VERSION = "0.
|
|
1251
|
+
var SDK_VERSION = "0.19.0";
|
|
1252
1252
|
|
|
1253
1253
|
// src/utils/otlp/content.ts
|
|
1254
1254
|
init_content();
|
|
@@ -1742,7 +1742,7 @@ function sessionToOtlp(file, options) {
|
|
|
1742
1742
|
const agentName = file.agent?.name;
|
|
1743
1743
|
const everyEvent = file.events;
|
|
1744
1744
|
const exportedEvents = foldSupersededSpans(everyEvent).filter(
|
|
1745
|
-
(event) => options.terminal || !(event.type === "span" && event.status === "pending")
|
|
1745
|
+
(event) => options.terminal || !(event.type === "span" && (event.status === "pending" || event.status === "running"))
|
|
1746
1746
|
);
|
|
1747
1747
|
const startMs = parseMs(file.startedAt);
|
|
1748
1748
|
const nodes = exportedEvents.map((event) => {
|
|
@@ -3756,7 +3756,9 @@ function foldSupersededSpans(events) {
|
|
|
3756
3756
|
const current = winner.get(id);
|
|
3757
3757
|
if (current === void 0 || rank(events[i], i) >= rank(events[current], current)) winner.set(id, i);
|
|
3758
3758
|
}
|
|
3759
|
-
return events.filter(
|
|
3759
|
+
return events.filter(
|
|
3760
|
+
(event, i) => !(event.spanId && (event.status === "pending" || event.status === "running") && winner.get(event.spanId) !== i)
|
|
3761
|
+
);
|
|
3760
3762
|
}
|
|
3761
3763
|
function recordOrDeferTraceEvent(ctx, event, options) {
|
|
3762
3764
|
const session = ctx?.__traceSession;
|
|
@@ -10534,14 +10536,16 @@ function createAgent(opts) {
|
|
|
10534
10536
|
const startedAt = Date.now();
|
|
10535
10537
|
const recordSpan = (status, extra) => {
|
|
10536
10538
|
if (!traced || !isTraceSessionOpen(parentSession)) return;
|
|
10539
|
+
const running = status === "running";
|
|
10537
10540
|
recordSubagentSpan(parentSession, {
|
|
10538
10541
|
spanId: agentSpanId,
|
|
10539
|
-
|
|
10542
|
+
// The delegating tool_call span only exists once the tool returns.
|
|
10543
|
+
parentSpanId: running ? parentIterationSpanId : context?.traceSpanId ?? parentIterationSpanId,
|
|
10540
10544
|
name: opts.name || "agent",
|
|
10541
10545
|
status,
|
|
10542
|
-
durationMs: Date.now() - startedAt,
|
|
10546
|
+
durationMs: running ? void 0 : Date.now() - startedAt,
|
|
10543
10547
|
error: extra.error,
|
|
10544
|
-
info: { name: opts.name || "agent", mode: "asTool", depth: currentDepth + 1, parentToolCallId: context?.toolCallId, status: status === "success" ? "ok" : "error" },
|
|
10548
|
+
info: { name: opts.name || "agent", mode: "asTool", depth: currentDepth + 1, parentToolCallId: context?.toolCallId, status: running ? "running" : status === "success" ? "ok" : "error" },
|
|
10545
10549
|
task: input,
|
|
10546
10550
|
result: extra.result
|
|
10547
10551
|
});
|
|
@@ -10561,6 +10565,7 @@ function createAgent(opts) {
|
|
|
10561
10565
|
stream: Boolean(parentCtx.__streaming),
|
|
10562
10566
|
cancellationToken: parentCtx.__cancellationToken ?? parentCtx.__abortSignal
|
|
10563
10567
|
};
|
|
10568
|
+
recordSpan("running", {});
|
|
10564
10569
|
let res;
|
|
10565
10570
|
try {
|
|
10566
10571
|
res = await instance.invoke({ messages: childMessages, ctx: childCtx }, childConfig);
|
|
@@ -12761,14 +12766,16 @@ async function runChild(spec, input, deps, ref, opts) {
|
|
|
12761
12766
|
const traceScope = traced ? createSubagentTraceScope(parentSession, { agentSpanId, name: spec.name, spawnId, mode: spec.mode, hitl: opts.allowHITL, iterations: opts.record?.iterations }) : void 0;
|
|
12762
12767
|
const recordSegment = (status, info) => {
|
|
12763
12768
|
if (!traced || !isTraceSessionOpen(parentSession)) return;
|
|
12769
|
+
const unfinished = status === "pending" || status === "running";
|
|
12764
12770
|
recordSubagentSpan(parentSession, {
|
|
12765
12771
|
spanId: agentSpanId,
|
|
12766
|
-
// The tool_call span only exists once the tool returns; a
|
|
12767
|
-
// has not returned, so its span hangs off the iteration.
|
|
12768
|
-
parentSpanId:
|
|
12772
|
+
// The tool_call span only exists once the tool returns; a running or
|
|
12773
|
+
// paused child has not returned, so its span hangs off the iteration.
|
|
12774
|
+
parentSpanId: unfinished ? parentIterationSpanId : opts.parentSpanId ?? parentIterationSpanId,
|
|
12769
12775
|
name: spec.name,
|
|
12770
12776
|
status,
|
|
12771
|
-
|
|
12777
|
+
// A starting segment has no extent yet; a reader draws it over its children.
|
|
12778
|
+
durationMs: status === "running" ? void 0 : elapsedMs(),
|
|
12772
12779
|
error: info.error,
|
|
12773
12780
|
info: {
|
|
12774
12781
|
id: spawnId,
|
|
@@ -12779,7 +12786,7 @@ async function runChild(spec, input, deps, ref, opts) {
|
|
|
12779
12786
|
parentToolCallId: opts.parentToolCallId,
|
|
12780
12787
|
status: info.subagentStatus,
|
|
12781
12788
|
// Only a run that paused has more than one segment to tell about.
|
|
12782
|
-
...segment > 1 ||
|
|
12789
|
+
...segment > 1 || unfinished ? { segments: segment } : {},
|
|
12783
12790
|
...info.note ? { note: info.note } : {},
|
|
12784
12791
|
...spec.metadata ? { metadata: spec.metadata } : {}
|
|
12785
12792
|
},
|
|
@@ -12903,6 +12910,7 @@ async function runChild(spec, input, deps, ref, opts) {
|
|
|
12903
12910
|
}
|
|
12904
12911
|
if (traceScope) childInput = { ...childInput, ctx: { ...childInput.ctx || {}, __traceSession: traceScope } };
|
|
12905
12912
|
const usageBaseline = childInput.usage?.perRequest?.length ?? 0;
|
|
12913
|
+
recordSegment("running", { subagentStatus: "running", input });
|
|
12906
12914
|
let res;
|
|
12907
12915
|
try {
|
|
12908
12916
|
res = await child.invoke(childInput, childConfig);
|