@botiverse/oar 0.52.0 → 0.54.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/README.md +23 -10
- package/dist/contracts/failure.d.ts +1 -1
- package/dist/contracts/install.d.ts +11 -1
- package/dist/contracts/install.d.ts.map +1 -1
- package/dist/contracts/records.d.ts +25 -4
- package/dist/contracts/records.d.ts.map +1 -1
- package/dist/contracts/session.d.ts +4 -3
- package/dist/contracts/session.d.ts.map +1 -1
- package/dist/contracts/status.d.ts +20 -2
- package/dist/contracts/status.d.ts.map +1 -1
- package/dist/contracts/tasks.d.ts +6 -5
- package/dist/contracts/tasks.d.ts.map +1 -1
- package/dist/observe/agent-status.d.ts +7 -5
- package/dist/observe/agent-status.d.ts.map +1 -1
- package/dist/observe/agent-status.js +71 -12
- package/dist/observe/agent-status.js.map +1 -1
- package/dist/observe/conversation.d.ts +6 -0
- package/dist/observe/conversation.d.ts.map +1 -1
- package/dist/observe/conversation.js +8 -1
- package/dist/observe/conversation.js.map +1 -1
- package/dist/observe/display-text.d.ts +9 -2
- package/dist/observe/display-text.d.ts.map +1 -1
- package/dist/observe/display-text.js +22 -3
- package/dist/observe/display-text.js.map +1 -1
- package/dist/observe/graph.d.ts +14 -0
- package/dist/observe/graph.d.ts.map +1 -0
- package/dist/observe/graph.js +40 -0
- package/dist/observe/graph.js.map +1 -0
- package/dist/observe/index.d.ts +1 -0
- package/dist/observe/index.d.ts.map +1 -1
- package/dist/observe/index.js +1 -0
- package/dist/observe/index.js.map +1 -1
- package/dist/observe/input-delivery.d.ts.map +1 -1
- package/dist/observe/input-delivery.js +8 -2
- package/dist/observe/input-delivery.js.map +1 -1
- package/dist/observe/session-view-events.d.ts +1 -1
- package/dist/observe/session-view-events.d.ts.map +1 -1
- package/dist/observe/session-view-events.js +11 -16
- package/dist/observe/session-view-events.js.map +1 -1
- package/dist/observe/session-view-fold.d.ts +5 -4
- package/dist/observe/session-view-fold.d.ts.map +1 -1
- package/dist/observe/session-view-fold.js +9 -6
- package/dist/observe/session-view-fold.js.map +1 -1
- package/dist/observe/session-view-inputs.d.ts +7 -1
- package/dist/observe/session-view-inputs.d.ts.map +1 -1
- package/dist/observe/session-view-inputs.js +37 -1
- package/dist/observe/session-view-inputs.js.map +1 -1
- package/dist/observe/session-view.d.ts +11 -6
- package/dist/observe/session-view.d.ts.map +1 -1
- package/dist/observe/session-view.js +10 -6
- package/dist/observe/session-view.js.map +1 -1
- package/dist/observe/tool-activity.d.ts +7 -3
- package/dist/observe/tool-activity.d.ts.map +1 -1
- package/dist/observe/tool-activity.js +29 -70
- package/dist/observe/tool-activity.js.map +1 -1
- package/dist/observe/tool-groups.d.ts.map +1 -1
- package/dist/observe/tool-groups.js +6 -1
- package/dist/observe/tool-groups.js.map +1 -1
- package/dist/observe/tool-paths.d.ts +3 -0
- package/dist/observe/tool-paths.d.ts.map +1 -0
- package/dist/observe/tool-paths.js +53 -0
- package/dist/observe/tool-paths.js.map +1 -0
- package/dist/observe/turns.d.ts +21 -12
- package/dist/observe/turns.d.ts.map +1 -1
- package/dist/observe/turns.js +61 -39
- package/dist/observe/turns.js.map +1 -1
- package/dist/observe/usage-totals.d.ts +27 -0
- package/dist/observe/usage-totals.d.ts.map +1 -0
- package/dist/observe/usage-totals.js +64 -0
- package/dist/observe/usage-totals.js.map +1 -0
- package/dist/observe/usage.d.ts +3 -17
- package/dist/observe/usage.d.ts.map +1 -1
- package/dist/observe/usage.js +14 -69
- package/dist/observe/usage.js.map +1 -1
- package/dist/runtimes/claude/account-usage.d.ts.map +1 -1
- package/dist/runtimes/claude/account-usage.js +3 -2
- package/dist/runtimes/claude/account-usage.js.map +1 -1
- package/dist/runtimes/claude/auth-status.d.ts +0 -1
- package/dist/runtimes/claude/auth-status.d.ts.map +1 -1
- package/dist/runtimes/claude/auth-status.js +1 -4
- package/dist/runtimes/claude/auth-status.js.map +1 -1
- package/dist/runtimes/claude/content.d.ts +1 -0
- package/dist/runtimes/claude/content.d.ts.map +1 -1
- package/dist/runtimes/claude/content.js +20 -0
- package/dist/runtimes/claude/content.js.map +1 -1
- package/dist/runtimes/claude/environment.d.ts +22 -0
- package/dist/runtimes/claude/environment.d.ts.map +1 -0
- package/dist/runtimes/claude/environment.js +44 -0
- package/dist/runtimes/claude/environment.js.map +1 -0
- package/dist/runtimes/claude/input-lifecycle.d.ts +19 -0
- package/dist/runtimes/claude/input-lifecycle.d.ts.map +1 -0
- package/dist/runtimes/claude/input-lifecycle.js +68 -0
- package/dist/runtimes/claude/input-lifecycle.js.map +1 -0
- package/dist/runtimes/claude/inventory.d.ts.map +1 -1
- package/dist/runtimes/claude/inventory.js +2 -1
- package/dist/runtimes/claude/inventory.js.map +1 -1
- package/dist/runtimes/claude/launch.d.ts.map +1 -1
- package/dist/runtimes/claude/launch.js +4 -1
- package/dist/runtimes/claude/launch.js.map +1 -1
- package/dist/runtimes/claude/list-models.d.ts.map +1 -1
- package/dist/runtimes/claude/list-models.js +2 -1
- package/dist/runtimes/claude/list-models.js.map +1 -1
- package/dist/runtimes/claude/login.d.ts.map +1 -1
- package/dist/runtimes/claude/login.js +2 -1
- package/dist/runtimes/claude/login.js.map +1 -1
- package/dist/runtimes/claude/logout.d.ts.map +1 -1
- package/dist/runtimes/claude/logout.js +2 -1
- package/dist/runtimes/claude/logout.js.map +1 -1
- package/dist/runtimes/claude/projection.d.ts +20 -6
- package/dist/runtimes/claude/projection.d.ts.map +1 -1
- package/dist/runtimes/claude/projection.js +31 -30
- package/dist/runtimes/claude/projection.js.map +1 -1
- package/dist/runtimes/claude/session.d.ts.map +1 -1
- package/dist/runtimes/claude/session.js +55 -41
- package/dist/runtimes/claude/session.js.map +1 -1
- package/dist/runtimes/claude/tasks.d.ts +5 -2
- package/dist/runtimes/claude/tasks.d.ts.map +1 -1
- package/dist/runtimes/claude/tasks.js +22 -4
- package/dist/runtimes/claude/tasks.js.map +1 -1
- package/dist/runtimes/claude/update.d.ts.map +1 -1
- package/dist/runtimes/claude/update.js +3 -1
- package/dist/runtimes/claude/update.js.map +1 -1
- package/dist/runtimes/codex/session.d.ts.map +1 -1
- package/dist/runtimes/codex/session.js +2 -5
- package/dist/runtimes/codex/session.js.map +1 -1
- package/dist/runtimes/pi/catalog.d.ts.map +1 -1
- package/dist/runtimes/pi/catalog.js +16 -3
- package/dist/runtimes/pi/catalog.js.map +1 -1
- package/dist/shared/acp/records.d.ts.map +1 -1
- package/dist/shared/acp/records.js +6 -17
- package/dist/shared/acp/records.js.map +1 -1
- package/dist/shared/install.d.ts +2 -0
- package/dist/shared/install.d.ts.map +1 -1
- package/dist/shared/install.js +6 -3
- package/dist/shared/install.js.map +1 -1
- package/dist/shared/session-kernel.d.ts +6 -6
- package/dist/shared/session-kernel.d.ts.map +1 -1
- package/dist/shared/session-kernel.js +6 -19
- package/dist/shared/session-kernel.js.map +1 -1
- package/dist/shared/update.d.ts +2 -0
- package/dist/shared/update.d.ts.map +1 -1
- package/dist/shared/update.js +1 -1
- package/dist/shared/update.js.map +1 -1
- package/package.json +1 -1
package/dist/observe/turns.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ControlOutcome, InputImage, RejectionCode, Session, RawEvent, TurnOutcome } from "../contracts/session.js";
|
|
2
2
|
/**
|
|
3
3
|
* Turn helpers for consumers. A turn is a SPAN on the stream, not a control
|
|
4
|
-
* object:
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* object: a prompt request is its fallback start; native input_queued and
|
|
5
|
+
* turn_active with inputId can establish its actual start. It ends at the runtime's own
|
|
6
|
+
* `turn_ended` event (or at the process exit oar observed). A native before-start input drop
|
|
7
|
+
* also resolves an input-scoped wait (aborted for interruption, failed for refusal), without synthesizing a turn end.
|
|
7
8
|
*
|
|
8
9
|
* Scope: the ROOT SESSION's ROOT AGENT. A derived child session's records
|
|
9
10
|
* (codex child threads, grok child sessions) carry the child's own `sessionId`
|
|
@@ -14,25 +15,31 @@ import type { ControlOutcome, InputImage, RejectionCode, Session, RawEvent, Turn
|
|
|
14
15
|
/**
|
|
15
16
|
* The root-agent turn end after `afterSeq`, if the stream already holds one:
|
|
16
17
|
* the runtime's turn_ended event, or an observed process exit. When `sessionId`
|
|
17
|
-
* is given, only that session's records count.
|
|
18
|
+
* is given, only that session's records count. inputId gates on a matching
|
|
19
|
+
* native input_queued until its turn_active; without that evidence, the first
|
|
20
|
+
* end wins. A matching input drop resolves as aborted for interruption or
|
|
21
|
+
* failed for refusal.
|
|
18
22
|
*/
|
|
19
|
-
export declare function turnEndAfter(records: readonly RawEvent[], afterSeq: number, sessionId?: string): TurnOutcome | null;
|
|
23
|
+
export declare function turnEndAfter(records: readonly RawEvent[], afterSeq: number, sessionId?: string, inputId?: string): TurnOutcome | null;
|
|
20
24
|
/**
|
|
21
25
|
* Resolve with the first turn end of the session's root agent recorded after
|
|
22
26
|
* `afterSeq`, from the retained log if it already happened, otherwise live.
|
|
23
|
-
* A derived child session's turn end never satisfies it.
|
|
27
|
+
* A derived child session's turn end never satisfies it. With inputId, native
|
|
28
|
+
* queue/start evidence excludes intervening turns. Without it, behavior is unchanged.
|
|
24
29
|
*/
|
|
25
|
-
export declare function awaitTurnEnd(session: Session, afterSeq: number): Promise<TurnOutcome>;
|
|
30
|
+
export declare function awaitTurnEnd(session: Session, afterSeq: number, inputId?: string): Promise<TurnOutcome>;
|
|
26
31
|
/**
|
|
27
32
|
* Resolve once the root agent is idle: at once (null) when `session.status()`
|
|
28
|
-
* already says so, otherwise with the outcome
|
|
29
|
-
*
|
|
33
|
+
* already says so, otherwise with the outcome when the owned input and any
|
|
34
|
+
* intervening turn are no longer pending. The status is read and the subscription placed through one cursor,
|
|
30
35
|
* so a turn ending in between is not missed. Nothing is prompted here: a
|
|
31
36
|
* runtime that runs a queued input as a turn of its own makes the next
|
|
32
37
|
* prompt `busy`, and this is how a caller waits that out instead of polling.
|
|
33
38
|
*/
|
|
34
39
|
export declare function awaitIdle(session: Session): Promise<TurnOutcome | null>;
|
|
35
40
|
export interface PromptRunOptions {
|
|
41
|
+
/** Input identity for native turn correlation. A fresh UUID is used when omitted. */
|
|
42
|
+
readonly inputId?: string;
|
|
36
43
|
/** Abort the turn when it has not ended after this long; the run then reports `interrupted` with the observed turn outcome. */
|
|
37
44
|
readonly timeoutMs?: number;
|
|
38
45
|
/** Abort the turn when this fires (a caller-side cancel), reported the same way. */
|
|
@@ -48,7 +55,7 @@ export type PromptRun =
|
|
|
48
55
|
readonly code: RejectionCode;
|
|
49
56
|
readonly reason: string;
|
|
50
57
|
}
|
|
51
|
-
/** The runtime ended the turn
|
|
58
|
+
/** The runtime ended the turn or dropped the input. `text` is the root agent's text of this turn, concatenated. */
|
|
52
59
|
| {
|
|
53
60
|
readonly kind: "ended";
|
|
54
61
|
readonly result: ControlOutcome;
|
|
@@ -65,13 +72,15 @@ export type PromptRun =
|
|
|
65
72
|
};
|
|
66
73
|
/**
|
|
67
74
|
* Prompt, then wait for the runtime to end the turn it opened. A rejected
|
|
68
|
-
* prompt returns without waiting.
|
|
75
|
+
* prompt returns without waiting. Sends the caller's inputId or a fresh UUID
|
|
76
|
+
* to correlate native queue/start facts, without requiring that evidence. With `timeoutMs` / `signal`, a turn still
|
|
69
77
|
* running when either fires is aborted; the result is `interrupted` only when
|
|
70
78
|
* that abort was taken over. An abort the runtime refuses because the turn
|
|
71
79
|
* had just ended is the ordinary late-abort race, and the run is `ended`.
|
|
72
80
|
* After an accepted abort the turn's end is awaited with no further limit:
|
|
73
81
|
* a native turn end keeps its outcome; exit after that accepted abort is
|
|
74
|
-
* `aborted`.
|
|
82
|
+
* `aborted`. A native before-start input drop resolves as `aborted` for interruption or `failed` for refusal.
|
|
83
|
+
* Without one of these facts the helper continues waiting.
|
|
75
84
|
*/
|
|
76
85
|
export declare function promptAndWait(session: Session, input: string, options?: PromptRunOptions): Promise<PromptRun>;
|
|
77
86
|
//# sourceMappingURL=turns.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turns.d.ts","sourceRoot":"","sources":["../../src/observe/turns.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEzH
|
|
1
|
+
{"version":3,"file":"turns.d.ts","sourceRoot":"","sources":["../../src/observe/turns.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEzH;;;;;;;;;;;;GAYG;AAEH;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,SAAS,QAAQ,EAAE,EAC5B,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GACf,WAAW,GAAG,IAAI,CAOpB;AAiCD;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAG7G;AAeD;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAQ7E;AAED,MAAM,WAAW,gBAAgB;IAC/B,qFAAqF;IACrF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,+HAA+H;IAC/H,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,oFAAoF;IACpF,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;CACzC;AAED,MAAM,MAAM,SAAS;AACnB,oFAAoF;AAClF;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE;AACvH,mHAAmH;GACjH;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AACnH,oJAAoJ;GAClJ;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,GAAG,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/J;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,SAAS,CAAC,CAsBvH"}
|
package/dist/observe/turns.js
CHANGED
|
@@ -2,9 +2,10 @@ import { initialStatus, reduceStatus } from "./agent-status.js";
|
|
|
2
2
|
import { exitTurnOutcome } from "./turn-stop.js";
|
|
3
3
|
/**
|
|
4
4
|
* Turn helpers for consumers. A turn is a SPAN on the stream, not a control
|
|
5
|
-
* object:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* object: a prompt request is its fallback start; native input_queued and
|
|
6
|
+
* turn_active with inputId can establish its actual start. It ends at the runtime's own
|
|
7
|
+
* `turn_ended` event (or at the process exit oar observed). A native before-start input drop
|
|
8
|
+
* also resolves an input-scoped wait (aborted for interruption, failed for refusal), without synthesizing a turn end.
|
|
8
9
|
*
|
|
9
10
|
* Scope: the ROOT SESSION's ROOT AGENT. A derived child session's records
|
|
10
11
|
* (codex child threads, grok child sessions) carry the child's own `sessionId`
|
|
@@ -15,10 +16,13 @@ import { exitTurnOutcome } from "./turn-stop.js";
|
|
|
15
16
|
/**
|
|
16
17
|
* The root-agent turn end after `afterSeq`, if the stream already holds one:
|
|
17
18
|
* the runtime's turn_ended event, or an observed process exit. When `sessionId`
|
|
18
|
-
* is given, only that session's records count.
|
|
19
|
+
* is given, only that session's records count. inputId gates on a matching
|
|
20
|
+
* native input_queued until its turn_active; without that evidence, the first
|
|
21
|
+
* end wins. A matching input drop resolves as aborted for interruption or
|
|
22
|
+
* failed for refusal.
|
|
19
23
|
*/
|
|
20
|
-
export function turnEndAfter(records, afterSeq, sessionId) {
|
|
21
|
-
const read = turnEndReader(afterSeq, sessionId);
|
|
24
|
+
export function turnEndAfter(records, afterSeq, sessionId, inputId) {
|
|
25
|
+
const read = turnEndReader(afterSeq, sessionId, inputId);
|
|
22
26
|
for (const record of records) {
|
|
23
27
|
const outcome = read(record);
|
|
24
28
|
if (outcome !== null) {
|
|
@@ -28,37 +32,58 @@ export function turnEndAfter(records, afterSeq, sessionId) {
|
|
|
28
32
|
return null;
|
|
29
33
|
}
|
|
30
34
|
/** Keep request/response correlation across both the retained prefix and live records. */
|
|
31
|
-
function turnEndReader(afterSeq, sessionId) {
|
|
35
|
+
function turnEndReader(afterSeq, sessionId, inputId, onText, onlyWhenIdle = false) {
|
|
32
36
|
let status = initialStatus;
|
|
37
|
+
let waitingForInput = false;
|
|
33
38
|
return (record) => {
|
|
34
39
|
if (record.agentPath.length > 0 || (sessionId !== undefined && record.sessionId !== sessionId)) {
|
|
35
40
|
return null;
|
|
36
41
|
}
|
|
37
42
|
const previous = status;
|
|
38
43
|
status = reduceStatus(previous, record, sessionId);
|
|
39
|
-
if (record.seq <= afterSeq) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
44
|
if (record.kind === "frame") {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
for (const event of record.body.events) {
|
|
46
|
+
if (inputId !== undefined && event.kind === "input_queued" && event.inputId === inputId) {
|
|
47
|
+
waitingForInput = true;
|
|
48
|
+
}
|
|
49
|
+
if (inputId !== undefined && event.kind === "turn_active" && event.inputId === inputId) {
|
|
50
|
+
waitingForInput = false;
|
|
51
|
+
}
|
|
52
|
+
if (inputId !== undefined && event.kind === "input_dropped" && event.inputId === inputId) {
|
|
53
|
+
waitingForInput = false;
|
|
54
|
+
if (record.seq > afterSeq && (!onlyWhenIdle || status.kind === "idle")) {
|
|
55
|
+
return event.reason === "turn_interrupted" ? { kind: "aborted" }
|
|
56
|
+
: { kind: "failed", failure: event.failure ?? "unknown", reason: event.message ?? "runtime refused the input" };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (record.seq > afterSeq && !waitingForInput && event.kind === "text_delta") {
|
|
60
|
+
onText?.(event.text);
|
|
61
|
+
}
|
|
62
|
+
if (record.seq > afterSeq && !waitingForInput && event.kind === "turn_ended" && (!onlyWhenIdle || status.kind === "idle")) {
|
|
63
|
+
return event.outcome;
|
|
64
|
+
}
|
|
46
65
|
}
|
|
47
66
|
}
|
|
48
|
-
return record.kind === "response" && record.body.kind === "exited"
|
|
49
|
-
? exitTurnOutcome(previous.kind === "running" ? previous.stop :
|
|
67
|
+
return record.seq > afterSeq && record.kind === "response" && record.body.kind === "exited"
|
|
68
|
+
? exitTurnOutcome(previous.kind === "running" ? previous.stop ?? previous.pendingPrompt?.stop : previous.pendingPrompt?.stop)
|
|
50
69
|
: null;
|
|
51
70
|
};
|
|
52
71
|
}
|
|
53
72
|
/**
|
|
54
73
|
* Resolve with the first turn end of the session's root agent recorded after
|
|
55
74
|
* `afterSeq`, from the retained log if it already happened, otherwise live.
|
|
56
|
-
* A derived child session's turn end never satisfies it.
|
|
75
|
+
* A derived child session's turn end never satisfies it. With inputId, native
|
|
76
|
+
* queue/start evidence excludes intervening turns. Without it, behavior is unchanged.
|
|
57
77
|
*/
|
|
58
|
-
export async function awaitTurnEnd(session, afterSeq) {
|
|
78
|
+
export async function awaitTurnEnd(session, afterSeq, inputId) {
|
|
79
|
+
const outcome = await watchTurn(session, afterSeq, inputId);
|
|
80
|
+
return outcome;
|
|
81
|
+
}
|
|
82
|
+
/** One reader owns both the turn boundary and its text, including replay before subscription. */
|
|
83
|
+
async function watchTurn(session, afterSeq, inputId, onText, onlyWhenIdle = false) {
|
|
59
84
|
const { promise, resolve } = Promise.withResolvers();
|
|
60
85
|
let done = false;
|
|
61
|
-
const read = turnEndReader(afterSeq, session.id);
|
|
86
|
+
const read = turnEndReader(afterSeq, session.id, inputId, onText, onlyWhenIdle);
|
|
62
87
|
const unsubscribe = session.rawEvents((record) => {
|
|
63
88
|
if (done) {
|
|
64
89
|
return;
|
|
@@ -69,54 +94,52 @@ export async function awaitTurnEnd(session, afterSeq) {
|
|
|
69
94
|
resolve(outcome);
|
|
70
95
|
}
|
|
71
96
|
}, { sessionId: session.id, afterSeq: -1 });
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
97
|
+
try {
|
|
98
|
+
return await promise;
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
unsubscribe();
|
|
102
|
+
}
|
|
75
103
|
}
|
|
76
104
|
/**
|
|
77
105
|
* Resolve once the root agent is idle: at once (null) when `session.status()`
|
|
78
|
-
* already says so, otherwise with the outcome
|
|
79
|
-
*
|
|
106
|
+
* already says so, otherwise with the outcome when the owned input and any
|
|
107
|
+
* intervening turn are no longer pending. The status is read and the subscription placed through one cursor,
|
|
80
108
|
* so a turn ending in between is not missed. Nothing is prompted here: a
|
|
81
109
|
* runtime that runs a queued input as a turn of its own makes the next
|
|
82
110
|
* prompt `busy`, and this is how a caller waits that out instead of polling.
|
|
83
111
|
*/
|
|
84
112
|
export async function awaitIdle(session) {
|
|
85
113
|
const status = session.status();
|
|
86
|
-
if (status.value.kind === "idle") {
|
|
114
|
+
if (status.value.kind === "idle" && status.value.pendingPrompt === undefined) {
|
|
87
115
|
return null;
|
|
88
116
|
}
|
|
89
|
-
const
|
|
117
|
+
const inputId = status.value.pendingPrompt?.inputId ?? (status.value.kind === "running" ? status.value.inputId : undefined);
|
|
118
|
+
const outcome = await watchTurn(session, status.seq, inputId, undefined, true);
|
|
90
119
|
return outcome;
|
|
91
120
|
}
|
|
92
121
|
/**
|
|
93
122
|
* Prompt, then wait for the runtime to end the turn it opened. A rejected
|
|
94
|
-
* prompt returns without waiting.
|
|
123
|
+
* prompt returns without waiting. Sends the caller's inputId or a fresh UUID
|
|
124
|
+
* to correlate native queue/start facts, without requiring that evidence. With `timeoutMs` / `signal`, a turn still
|
|
95
125
|
* running when either fires is aborted; the result is `interrupted` only when
|
|
96
126
|
* that abort was taken over. An abort the runtime refuses because the turn
|
|
97
127
|
* had just ended is the ordinary late-abort race, and the run is `ended`.
|
|
98
128
|
* After an accepted abort the turn's end is awaited with no further limit:
|
|
99
129
|
* a native turn end keeps its outcome; exit after that accepted abort is
|
|
100
|
-
* `aborted`.
|
|
130
|
+
* `aborted`. A native before-start input drop resolves as `aborted` for interruption or `failed` for refusal.
|
|
131
|
+
* Without one of these facts the helper continues waiting.
|
|
101
132
|
*/
|
|
102
133
|
export async function promptAndWait(session, input, options = {}) {
|
|
103
|
-
const
|
|
134
|
+
const inputId = options.inputId ?? globalThis.crypto.randomUUID();
|
|
135
|
+
const result = await session.prompt(input, { inputId, ...(options.images === undefined ? {} : { images: options.images }) });
|
|
104
136
|
if (result.kind === "rejected") {
|
|
105
137
|
return { kind: "rejected", result, code: result.code, reason: result.reason };
|
|
106
138
|
}
|
|
107
139
|
let text = "";
|
|
108
|
-
const stopReading = session.rawEvents((record) => {
|
|
109
|
-
if (record.kind === "frame" && record.agentPath.length === 0 && record.sessionId === session.id) {
|
|
110
|
-
for (const event of record.body.events) {
|
|
111
|
-
if (event.kind === "text_delta") {
|
|
112
|
-
text += event.text;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}, { sessionId: session.id, afterSeq: result.seq });
|
|
117
140
|
const limit = armLimits(options);
|
|
118
141
|
try {
|
|
119
|
-
const ended =
|
|
142
|
+
const ended = watchTurn(session, result.seq, inputId, (delta) => { text += delta; });
|
|
120
143
|
const first = await Promise.race([ended, limit.fired]);
|
|
121
144
|
if (typeof first !== "string") {
|
|
122
145
|
return { kind: "ended", result, outcome: first, text };
|
|
@@ -129,7 +152,6 @@ export async function promptAndWait(session, input, options = {}) {
|
|
|
129
152
|
}
|
|
130
153
|
finally {
|
|
131
154
|
limit.disarm();
|
|
132
|
-
stopReading();
|
|
133
155
|
}
|
|
134
156
|
}
|
|
135
157
|
/** The caller's limits as one promise that settles with whichever fires first (never, when none is set), and the disarm for when the turn ends first. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turns.js","sourceRoot":"","sources":["../../src/observe/turns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD
|
|
1
|
+
{"version":3,"file":"turns.js","sourceRoot":"","sources":["../../src/observe/turns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD;;;;;;;;;;;;GAYG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,OAA4B,EAC5B,QAAgB,EAChB,SAAkB,EAClB,OAAgB;IAEhB,MAAM,IAAI,GAAG,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACzD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7B,IAAI,OAAO,KAAK,IA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IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,EAAE,CAAC;QACrC,OAAO,EAAE,CAAC;IACZ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,OAAO;QACL,KAAK;QACL,MAAM,EAAE,GAAG,EAAE;YACX,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;YACD,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SessionGraph, SessionUsage, TokenTotals, UsageReport } from "../contracts/session.js";
|
|
2
|
+
/** One agent's latest running total. */
|
|
3
|
+
export interface AgentTotal {
|
|
4
|
+
readonly agentPath: readonly string[];
|
|
5
|
+
readonly tokens: TokenTotals;
|
|
6
|
+
}
|
|
7
|
+
/** What one session's records said about tokens: each agent's latest running total, and the runtime's own session total when it reports one. */
|
|
8
|
+
export interface SessionTokens {
|
|
9
|
+
readonly agents: ReadonlyMap<string, AgentTotal>;
|
|
10
|
+
readonly total: TokenTotals | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A session's usage from each agent's latest running total and, where the
|
|
14
|
+
* runtime reports one beyond its agents' figures (claude's `modelUsage`), its
|
|
15
|
+
* own session total: then the total is the runtime's, and what no agent
|
|
16
|
+
* accounts for is `unattributed`, the difference, never split by estimate.
|
|
17
|
+
* Elsewhere the agents' figures sum to the total. Shared by `usageOf` and the
|
|
18
|
+
* session view.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sessionUsageFrom(byAgent: readonly AgentTotal[], reported: TokenTotals | null): SessionUsage;
|
|
21
|
+
/** Every session derived from `sessionId` in the graph, nested ones too, each once; never `sessionId` itself. */
|
|
22
|
+
export declare function derivedFrom(graph: SessionGraph, sessionId: string): ReadonlySet<string>;
|
|
23
|
+
/** Latest totals per agent, without mutating a previously published view. */
|
|
24
|
+
export declare function foldSessionTokens(previous: SessionTokens | undefined, agentPath: readonly string[], usage: UsageReport): SessionTokens;
|
|
25
|
+
/** Own usage and each reachable child's latest total, shared by query and view. */
|
|
26
|
+
export declare function usageFromSessions(sessions: ReadonlyMap<string, SessionTokens>, sessionId: string, graph: SessionGraph): SessionUsage;
|
|
27
|
+
//# sourceMappingURL=usage-totals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-totals.d.ts","sourceRoot":"","sources":["../../src/observe/usage-totals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGpG,wCAAwC;AACxC,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B;AAED,gJAAgJ;AAChJ,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjD,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;CACpC;AAMD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI,GAAG,YAAY,CAgB3G;AAED,iHAAiH;AACjH,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAavF;AAED,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa,GAAG,SAAS,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,WAAW,GAAG,aAAa,CAMtI;AAED,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,YAAY,CASpI"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { addTokens, noTokens, subtractTokens } from "../shared/token-totals.js";
|
|
2
|
+
function hasTokens(tokens) {
|
|
3
|
+
return tokens.input > 0 || tokens.output > 0;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A session's usage from each agent's latest running total and, where the
|
|
7
|
+
* runtime reports one beyond its agents' figures (claude's `modelUsage`), its
|
|
8
|
+
* own session total: then the total is the runtime's, and what no agent
|
|
9
|
+
* accounts for is `unattributed`, the difference, never split by estimate.
|
|
10
|
+
* Elsewhere the agents' figures sum to the total. Shared by `usageOf` and the
|
|
11
|
+
* session view.
|
|
12
|
+
*/
|
|
13
|
+
export function sessionUsageFrom(byAgent, reported) {
|
|
14
|
+
if (byAgent.length === 0 && reported === null) {
|
|
15
|
+
// Nothing reported yet (or a runtime whose interface never carries token
|
|
16
|
+
// totals): null, never a guessed zero.
|
|
17
|
+
return { total: null };
|
|
18
|
+
}
|
|
19
|
+
// A cache part is in the total once any agent reported it, summed over those that did.
|
|
20
|
+
const attributed = byAgent.reduce((sum, entry) => addTokens(sum, entry.tokens), noTokens);
|
|
21
|
+
const remainder = reported === null ? null : subtractTokens(reported, attributed);
|
|
22
|
+
const unattributed = remainder !== null && hasTokens(remainder) ? remainder : null;
|
|
23
|
+
const onlyRoot = byAgent.length <= 1 && byAgent.every((entry) => entry.agentPath.length === 0);
|
|
24
|
+
return {
|
|
25
|
+
total: reported ?? attributed,
|
|
26
|
+
...(onlyRoot && unattributed === null ? {} : { byAgent }),
|
|
27
|
+
...(unattributed === null ? {} : { unattributed }),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Every session derived from `sessionId` in the graph, nested ones too, each once; never `sessionId` itself. */
|
|
31
|
+
export function derivedFrom(graph, sessionId) {
|
|
32
|
+
const found = new Set();
|
|
33
|
+
const queue = [sessionId];
|
|
34
|
+
while (queue.length > 0) {
|
|
35
|
+
const parent = queue.shift();
|
|
36
|
+
for (const edge of graph.edges) {
|
|
37
|
+
if (edge.parent === parent && edge.child !== sessionId && !found.has(edge.child)) {
|
|
38
|
+
found.add(edge.child);
|
|
39
|
+
queue.push(edge.child);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return found;
|
|
44
|
+
}
|
|
45
|
+
/** Latest totals per agent, without mutating a previously published view. */
|
|
46
|
+
export function foldSessionTokens(previous, agentPath, usage) {
|
|
47
|
+
const agents = new Map(previous?.agents);
|
|
48
|
+
if (usage.tokens !== undefined) {
|
|
49
|
+
agents.set(JSON.stringify(agentPath), { agentPath, tokens: usage.tokens });
|
|
50
|
+
}
|
|
51
|
+
return { agents, total: usage.total ?? previous?.total ?? null };
|
|
52
|
+
}
|
|
53
|
+
/** Own usage and each reachable child's latest total, shared by query and view. */
|
|
54
|
+
export function usageFromSessions(sessions, sessionId, graph) {
|
|
55
|
+
const ofSession = (id) => {
|
|
56
|
+
const session = sessions.get(id);
|
|
57
|
+
return session === undefined ? { total: null } : sessionUsageFrom([...session.agents.values()], session.total);
|
|
58
|
+
};
|
|
59
|
+
const own = ofSession(sessionId);
|
|
60
|
+
const childTotals = [...derivedFrom(graph, sessionId)].flatMap((child) => ofSession(child).total ?? []);
|
|
61
|
+
return own.total === null || childTotals.length === 0 ? own
|
|
62
|
+
: { ...own, withChildren: childTotals.reduce((sum, tokens) => addTokens(sum, tokens), own.total) };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=usage-totals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-totals.js","sourceRoot":"","s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AK,IAAI,QAAQ,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;AACnE,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,iBAAiB,CAAC,QAA4C,EAAE,SAAiB,EAAE,KAAmB;IACpH,MAAM,SAAS,GAAG,CAAC,EAAU,EAAgB,EAAE;QAC7C,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACjC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACjH,CAAC,CAAC;IACF,MAAM,GAAG,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,WAAW,GAAG,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACxG,OAAO,GAAG,CAAC,KAAK,KAAK,IAAI,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG;QACzD,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,YAAY,EAAE,WAAW,CAAC,MAAM,CAAc,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;AACpH,CAAC"}
|
package/dist/observe/usage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContextUsage, QueryResult, RawEvent, SessionGraph, SessionUsage
|
|
1
|
+
import type { ContextUsage, QueryResult, RawEvent, SessionGraph, SessionUsage } from "../contracts/session.js";
|
|
2
2
|
/** The latest model the runtime reported for the root agent; null before any. */
|
|
3
3
|
export declare function modelOf(records: readonly RawEvent[], sessionId?: string): QueryResult<string | null>;
|
|
4
4
|
/** The latest reasoning-effort level the runtime reported for the root agent; null before any. */
|
|
@@ -7,20 +7,6 @@ export declare function effortOf(records: readonly RawEvent[], sessionId?: strin
|
|
|
7
7
|
export declare function serviceTierOf(records: readonly RawEvent[], sessionId?: string): QueryResult<string | null>;
|
|
8
8
|
/** The latest context fullness the runtime reported for the root agent; null before any. */
|
|
9
9
|
export declare function contextUsageOf(records: readonly RawEvent[], sessionId?: string): QueryResult<ContextUsage | null>;
|
|
10
|
-
/** One agent's latest running total. */
|
|
11
|
-
interface AgentTotal {
|
|
12
|
-
readonly agentPath: readonly string[];
|
|
13
|
-
readonly tokens: TokenTotals;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* A session's usage from each agent's latest running total and, where the
|
|
17
|
-
* runtime reports one beyond its agents' figures (claude's `modelUsage`), its
|
|
18
|
-
* own session total: then the total is the runtime's, and what no agent
|
|
19
|
-
* accounts for is `unattributed`, the difference, never split by estimate.
|
|
20
|
-
* Elsewhere the agents' figures sum to the total. Shared by `usageOf` and the
|
|
21
|
-
* session view.
|
|
22
|
-
*/
|
|
23
|
-
export declare function sessionUsageFrom(byAgent: readonly AgentTotal[], reported: TokenTotals | null): SessionUsage;
|
|
24
10
|
/**
|
|
25
11
|
* Session total plus a per-agent breakdown. Each agent's totals are the
|
|
26
12
|
* LATEST figure its records reported (adapters resolve their runtime's
|
|
@@ -29,10 +15,10 @@ export declare function sessionUsageFrom(byAgent: readonly AgentTotal[], reporte
|
|
|
29
15
|
* construction; with the runtime's own session total, when it reports one,
|
|
30
16
|
* the breakdown plus `unattributed` sums to the total. Agents are the
|
|
31
17
|
* `agentPath`s of THIS session; derived child sessions are not agents of it.
|
|
32
|
-
*
|
|
18
|
+
* The graph defaults to graphOf(records); an explicit graph overrides it.
|
|
19
|
+
* Each derived child session's total (folded from
|
|
33
20
|
* its own records the same way) is added once into `withChildren`, and the
|
|
34
21
|
* answer's `seq` covers those records too.
|
|
35
22
|
*/
|
|
36
23
|
export declare function usageOf(records: readonly RawEvent[], sessionId?: string, graph?: SessionGraph): QueryResult<SessionUsage>;
|
|
37
|
-
export {};
|
|
38
24
|
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/observe/usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,YAAY,
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/observe/usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,YAAY,EACb,MAAM,yBAAyB,CAAC;AA0BjC,iFAAiF;AACjF,wBAAgB,OAAO,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAYpG;AAED,kGAAkG;AAClG,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAYrG;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAY1G;AAED,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,YAAY,GAAG,IAAI,CAAC,CAYjH;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC,CAsBzH"}
|
package/dist/observe/usage.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { graphOf } from "./graph.js";
|
|
2
|
+
import { derivedFrom, foldSessionTokens, usageFromSessions } from "./usage-totals.js";
|
|
2
3
|
/**
|
|
3
4
|
* Query = projection over the stream. Model, token usage and context
|
|
4
5
|
* fullness are folds over seq-carrying records, never a second source of
|
|
@@ -16,9 +17,6 @@ import { addTokens, noTokens, subtractTokens } from "../shared/token-totals.js";
|
|
|
16
17
|
* totals on the parent's connection, and without this scope the child's
|
|
17
18
|
* figure overwrote the root's under the same `agentPath []` key.
|
|
18
19
|
*/
|
|
19
|
-
function pathKey(agentPath) {
|
|
20
|
-
return JSON.stringify(agentPath);
|
|
21
|
-
}
|
|
22
20
|
function inSession(record, sessionId) {
|
|
23
21
|
return sessionId === undefined || record.sessionId === sessionId;
|
|
24
22
|
}
|
|
@@ -94,49 +92,6 @@ export function contextUsageOf(records, sessionId) {
|
|
|
94
92
|
}
|
|
95
93
|
return { value, seq };
|
|
96
94
|
}
|
|
97
|
-
function hasTokens(tokens) {
|
|
98
|
-
return tokens.input > 0 || tokens.output > 0;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* A session's usage from each agent's latest running total and, where the
|
|
102
|
-
* runtime reports one beyond its agents' figures (claude's `modelUsage`), its
|
|
103
|
-
* own session total: then the total is the runtime's, and what no agent
|
|
104
|
-
* accounts for is `unattributed`, the difference, never split by estimate.
|
|
105
|
-
* Elsewhere the agents' figures sum to the total. Shared by `usageOf` and the
|
|
106
|
-
* session view.
|
|
107
|
-
*/
|
|
108
|
-
export function sessionUsageFrom(byAgent, reported) {
|
|
109
|
-
if (byAgent.length === 0 && reported === null) {
|
|
110
|
-
// Nothing reported yet (or a runtime whose interface never carries token
|
|
111
|
-
// totals): null, never a guessed zero.
|
|
112
|
-
return { total: null };
|
|
113
|
-
}
|
|
114
|
-
// A cache part is in the total once any agent reported it, summed over those that did.
|
|
115
|
-
const attributed = byAgent.reduce((sum, entry) => addTokens(sum, entry.tokens), noTokens);
|
|
116
|
-
const remainder = reported === null ? null : subtractTokens(reported, attributed);
|
|
117
|
-
const unattributed = remainder !== null && hasTokens(remainder) ? remainder : null;
|
|
118
|
-
const onlyRoot = byAgent.length <= 1 && byAgent.every((entry) => entry.agentPath.length === 0);
|
|
119
|
-
return {
|
|
120
|
-
total: reported ?? attributed,
|
|
121
|
-
...(onlyRoot && unattributed === null ? {} : { byAgent }),
|
|
122
|
-
...(unattributed === null ? {} : { unattributed }),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
/** Every session derived from `sessionId` in the graph, nested ones too, each once; never `sessionId` itself. */
|
|
126
|
-
function derivedFrom(graph, sessionId) {
|
|
127
|
-
const found = new Set();
|
|
128
|
-
const queue = [sessionId];
|
|
129
|
-
while (queue.length > 0) {
|
|
130
|
-
const parent = queue.shift();
|
|
131
|
-
for (const edge of graph.edges) {
|
|
132
|
-
if (edge.parent === parent && edge.child !== sessionId && !found.has(edge.child)) {
|
|
133
|
-
found.add(edge.child);
|
|
134
|
-
queue.push(edge.child);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return found;
|
|
139
|
-
}
|
|
140
95
|
/**
|
|
141
96
|
* Session total plus a per-agent breakdown. Each agent's totals are the
|
|
142
97
|
* LATEST figure its records reported (adapters resolve their runtime's
|
|
@@ -145,47 +100,37 @@ function derivedFrom(graph, sessionId) {
|
|
|
145
100
|
* construction; with the runtime's own session total, when it reports one,
|
|
146
101
|
* the breakdown plus `unattributed` sums to the total. Agents are the
|
|
147
102
|
* `agentPath`s of THIS session; derived child sessions are not agents of it.
|
|
148
|
-
*
|
|
103
|
+
* The graph defaults to graphOf(records); an explicit graph overrides it.
|
|
104
|
+
* Each derived child session's total (folded from
|
|
149
105
|
* its own records the same way) is added once into `withChildren`, and the
|
|
150
106
|
* answer's `seq` covers those records too.
|
|
151
107
|
*/
|
|
152
108
|
export function usageOf(records, sessionId, graph) {
|
|
153
|
-
const
|
|
109
|
+
const lineage = graph ?? graphOf(records);
|
|
110
|
+
const children = sessionId === undefined ? new Set() : derivedFrom(lineage, sessionId);
|
|
154
111
|
const sessions = new Map();
|
|
155
112
|
let seq = -1;
|
|
156
113
|
for (const record of records) {
|
|
157
|
-
|
|
114
|
+
const related = inSession(record, sessionId) || children.has(record.sessionId);
|
|
115
|
+
const linked = record.kind === "frame" && record.body.events.some((event) => event.kind === "session_linked" && children.has(event.child) && (event.parent === sessionId || children.has(event.parent)));
|
|
116
|
+
if (related || linked) {
|
|
117
|
+
seq = record.seq;
|
|
118
|
+
}
|
|
119
|
+
if (!related) {
|
|
158
120
|
continue;
|
|
159
121
|
}
|
|
160
|
-
seq = record.seq;
|
|
161
122
|
if (record.kind !== "frame") {
|
|
162
123
|
continue;
|
|
163
124
|
}
|
|
164
125
|
// Unscoped, every session folds into one (the collision the scope exists to avoid).
|
|
165
126
|
const key = sessionId === undefined ? "" : record.sessionId;
|
|
166
|
-
const session = sessions.get(key) ?? { agents: new Map(), total: null };
|
|
167
|
-
sessions.set(key, session);
|
|
168
127
|
for (const event of record.body.events) {
|
|
169
128
|
if (event.kind !== "usage") {
|
|
170
129
|
continue;
|
|
171
130
|
}
|
|
172
|
-
|
|
173
|
-
session.agents.set(pathKey(record.agentPath), { agentPath: record.agentPath, tokens: event.usage.tokens });
|
|
174
|
-
}
|
|
175
|
-
if (event.usage.total !== undefined) {
|
|
176
|
-
session.total = event.usage.total;
|
|
177
|
-
}
|
|
131
|
+
sessions.set(key, foldSessionTokens(sessions.get(key), record.agentPath, event.usage));
|
|
178
132
|
}
|
|
179
133
|
}
|
|
180
|
-
|
|
181
|
-
const session = sessions.get(id);
|
|
182
|
-
return session === undefined ? { total: null } : sessionUsageFrom([...session.agents.values()], session.total);
|
|
183
|
-
};
|
|
184
|
-
const own = usageOfSession(sessionId ?? "");
|
|
185
|
-
const childTotals = [...children].flatMap((child) => usageOfSession(child).total ?? []);
|
|
186
|
-
if (own.total === null || childTotals.length === 0) {
|
|
187
|
-
return { value: own, seq };
|
|
188
|
-
}
|
|
189
|
-
return { value: { ...own, withChildren: childTotals.reduce((sum, tokens) => addTokens(sum, tokens), own.total) }, seq };
|
|
134
|
+
return { value: usageFromSessions(sessions, sessionId ?? "", sessionId === undefined ? { nodes: [], edges: [] } : lineage), seq };
|
|
190
135
|
}
|
|
191
136
|
//# sourceMappingURL=usage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/observe/usage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/observe/usage.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,EAAsB,MAAM,mBAAmB,CAAC;AAE1G;;;;;;;;;;;;;;;;GAgBG;AAEH,SAAS,SAAS,CAAC,MAAgB,EAAE,SAA6B;IAChE,OAAO,SAAS,KAAK,SAAS,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,CAAC;AACnE,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,OAAO,CAAC,OAA4B,EAAE,SAAkB;IACtE,IAAI,KAAK,GAAkB,IAAI,CAAC;IAChC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC;IACb,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC;YAAC,SAAS;QAAC,CAAC;QAChD,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACjB,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,IA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