@genesislcap/ai-assistant 15.11.0 → 15.12.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/ai-assistant.api.json +135 -0
- package/dist/ai-assistant.d.ts +75 -3
- package/dist/chat-driver.cjs +540 -117
- package/dist/chat-driver.cjs.map +4 -4
- package/dist/chat-driver.mjs +524 -116
- package/dist/chat-driver.mjs.map +4 -4
- package/dist/custom-elements.json +1822 -1483
- package/dist/dts/chat-driver-node.d.ts +5 -2
- package/dist/dts/chat-driver-node.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts +20 -3
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.thinking-policy.test.d.ts +2 -0
- package/dist/dts/components/chat-driver/chat-driver.thinking-policy.test.d.ts.map +1 -0
- package/dist/dts/components/chat-driver/chat-driver.trace-capture.test.d.ts +2 -0
- package/dist/dts/components/chat-driver/chat-driver.trace-capture.test.d.ts.map +1 -0
- package/dist/dts/config/config.d.ts +39 -2
- package/dist/dts/config/config.d.ts.map +1 -1
- package/dist/dts/config/define-stateful-agent.d.ts +15 -1
- package/dist/dts/config/define-stateful-agent.d.ts.map +1 -1
- package/dist/dts/main/main.template.d.ts.map +1 -1
- package/dist/dts/utils/strip-agent-handlers.d.ts +1 -1
- package/dist/dts/utils/sum-usage.d.ts +37 -4
- package/dist/dts/utils/sum-usage.d.ts.map +1 -1
- package/dist/dts/utils/usage-rows.d.ts +102 -0
- package/dist/dts/utils/usage-rows.d.ts.map +1 -0
- package/dist/dts/utils/usage-rows.test.d.ts +2 -0
- package/dist/dts/utils/usage-rows.test.d.ts.map +1 -0
- package/dist/esm/chat-driver-node.js +36 -1
- package/dist/esm/components/chat-driver/chat-driver.js +73 -10
- package/dist/esm/components/chat-driver/chat-driver.thinking-policy.test.js +137 -0
- package/dist/esm/components/chat-driver/chat-driver.trace-capture.test.js +200 -0
- package/dist/esm/config/define-stateful-agent.js +11 -0
- package/dist/esm/main/main.template.js +20 -1
- package/dist/esm/utils/strip-agent-handlers.js +1 -1
- package/dist/esm/utils/sum-usage.js +37 -4
- package/dist/esm/utils/usage-rows.js +90 -0
- package/dist/esm/utils/usage-rows.test.js +189 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/chat-driver-node.ts +58 -0
- package/src/components/chat-driver/chat-driver.thinking-policy.test.ts +185 -0
- package/src/components/chat-driver/chat-driver.trace-capture.test.ts +251 -0
- package/src/components/chat-driver/chat-driver.ts +90 -10
- package/src/config/config.ts +50 -1
- package/src/config/define-stateful-agent.ts +37 -0
- package/src/main/main.template.ts +19 -1
- package/src/utils/strip-agent-handlers.ts +1 -1
- package/src/utils/sum-usage.ts +37 -4
- package/src/utils/usage-rows.test.ts +237 -0
- package/src/utils/usage-rows.ts +187 -0
|
@@ -23,8 +23,11 @@ export * from './channel/ai-activity-bus';
|
|
|
23
23
|
export * from './config/config';
|
|
24
24
|
export * from './config/define-stateful-agent';
|
|
25
25
|
export * from './config/fallback-agents';
|
|
26
|
-
export { AnthropicProvider, AnthropicTransport, GeminiProvider, GeminiTransport, MutableAIProviderRegistry, SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS, isObservableAIProviderRegistry, } from '@genesislcap/foundation-ai';
|
|
27
|
-
export type { AIProvider, AIProviderRegistry, AnthropicModelId, CachePolicy, ChatFallback, ChatMessage, ChatRequestOptions, ChatToolChoice, ChatToolDefinition, ChatToolHandlers, GeminiModelId, } from '@genesislcap/foundation-ai';
|
|
26
|
+
export { AnthropicProvider, AnthropicTransport, GeminiProvider, GeminiTransport, MutableAIProviderRegistry, SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS, isObservableAIProviderRegistry, ANTHROPIC_CACHE_READ_MULTIPLIER, ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER, anthropicRatesFor, anthropicTokenCost, GEMINI_CACHED_INPUT_MULTIPLIER, GEMINI_LONG_CONTEXT_THRESHOLD, geminiRatesFor, geminiTokenCost, vendorOfModel, } from '@genesislcap/foundation-ai';
|
|
27
|
+
export type { AggregateUsage, AIProvider, AIProviderRegistry, AnthropicModelId, CachePolicy, ChatFallback, ChatMessage, ChatRequestOptions, ChatThinkingPolicy, ChatToolChoice, ChatToolDefinition, ChatToolHandlers, GeminiModelId, AnthropicUsageRecord, GeminiUsageRecord, TokenCost, TokenCostBreakdown, TokenRates, } from '@genesislcap/foundation-ai';
|
|
28
|
+
export { addUsage, emptyUsage, sumUsage, totalTokens } from './utils/sum-usage';
|
|
29
|
+
export { usageRows } from './utils/usage-rows';
|
|
30
|
+
export type { UsageRow } from './utils/usage-rows';
|
|
28
31
|
export { clearSession, getMetaEvents } from './state/debug-event-log';
|
|
29
32
|
export type { MetaEvent } from './state/debug-event-log';
|
|
30
33
|
export { buildTimelineEntries } from './state/persistence/build-timeline-entries';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-driver-node.d.ts","sourceRoot":"","sources":["../../src/chat-driver-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AASzC,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,yBAAyB,EAKzB,6BAA6B,EAC7B,0BAA0B,EAC1B,8BAA8B,
|
|
1
|
+
{"version":3,"file":"chat-driver-node.d.ts","sourceRoot":"","sources":["../../src/chat-driver-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,c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AE,eAAe,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -401,6 +401,12 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
401
401
|
* `undefined` requests no caching (equivalent to `{ scope: 'default' }`).
|
|
402
402
|
*/
|
|
403
403
|
private activeCachePolicyInput?;
|
|
404
|
+
/**
|
|
405
|
+
* Active agent's extended-thinking selector (static value or per-turn resolver). `undefined` —
|
|
406
|
+
* unset, or returned by the resolver — leaves the model on its own default posture, which is
|
|
407
|
+
* neither uniformly on nor off, so an agent that never sets this is unaffected by the option.
|
|
408
|
+
*/
|
|
409
|
+
private activeThinkingPolicyInput?;
|
|
404
410
|
/**
|
|
405
411
|
* Active agent's tail-context selector (static value or per-turn resolver). The driver frames
|
|
406
412
|
* the resolved string in a `<system-reminder>` marker and injects it at the message tail.
|
|
@@ -802,9 +808,20 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
802
808
|
* `condenseWhen` can register against the right call (it stamps the clocks
|
|
803
809
|
* straight off the driver). Absent for dispatch paths with no addressable tool
|
|
804
810
|
* call (e.g. the fold-close handler), where `condenseWhen` is a no-op.
|
|
805
|
-
* @param traceCapture - Optional per-
|
|
806
|
-
*
|
|
807
|
-
* so parallel tool calls each capture their own
|
|
811
|
+
* @param traceCapture - Optional per-tool-call accumulator. When provided, every
|
|
812
|
+
* sub-agent call's trace is **appended** here rather than written to shared
|
|
813
|
+
* instance state, so parallel tool calls each capture their own traces
|
|
814
|
+
* independently.
|
|
815
|
+
*
|
|
816
|
+
* Deliberately a list of traces, not one slot. A single handler may call
|
|
817
|
+
* `requestSubAgent` more than once — a code-driven scheduler dispatching a
|
|
818
|
+
* dependency graph, a retry of a timed-out child, any fan-out helper — and a
|
|
819
|
+
* single slot kept only the last, so every other child ran, was billed by the
|
|
820
|
+
* provider, and then vanished from history. The loss was silent in the worst
|
|
821
|
+
* way: `sumUsage` and `usageRows` both recurse into the trace, so they summed a
|
|
822
|
+
* truncated input and still agreed with each other. Measured at 1 of 7 traces
|
|
823
|
+
* kept on a seven-way fan-out, reporting ~2.3x under the real cost, with the
|
|
824
|
+
* error growing as the fan-out widens.
|
|
808
825
|
*/
|
|
809
826
|
private buildHandlerContext;
|
|
810
827
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-driver.d.ts","sourceRoot":"","sources":["../../../../src/components/chat-driver/chat-driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAGlB,cAAc,EACd,gBAAgB,EAEhB,WAAW,
|
|
1
|
+
{"version":3,"file":"chat-driver.d.ts","sourceRoot":"","sources":["../../../../src/components/chat-driver/chat-driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAGlB,cAAc,EACd,gBAAgB,EAEhB,WAAW,EAIX,cAAc,EAKd,yBAAyB,EAEzB,qBAAqB,EAGtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,oBAAoB,EAMrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,+BAA+B,CAAC;AACpF,OAAO,KAAK,EACV,WAAW,EAKX,iBAAiB,EAKjB,oBAAoB,EACpB,iBAAiB,EAElB,MAAM,qBAAqB,CAAC;AAgB7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAW1E,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAExE;;;GAGG;AACH,KAAK,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,gBAAgB,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAuFzF,wFAAwF;AACxF,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAMhE;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG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,EAAE,WAAW,EAAE,GAAG,IAAI;IAS3C,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAsD/F;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,OAAO,CAAC,mBAAmB;IAoG3B;;;;;OAKG;YACW,cAAc;IAsO5B;;;OAGG;IACG,mBAAmB,CAAC,eAAe,CAAC,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAoDrF,wFAAwF;IACxF,OAAO,CAAC,OAAO;IAKf;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAc1B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAMtB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IA+BxB,uFAAuF;IACvF,OAAO,CAAC,QAAQ;IAsChB,OAAO,CAAC,aAAa;IAQrB,8EAA8E;IAC9E,OAAO,CAAC,SAAS;IAWjB,mFAAmF;IACnF,OAAO,CAAC,2BAA2B;YAkCrB,WAAW;IAk9BzB,OAAO,CAAC,eAAe;CAoBxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-driver.thinking-policy.test.d.ts","sourceRoot":"","sources":["../../../../src/components/chat-driver/chat-driver.thinking-policy.test.ts"],"names":[],"mappings":"AAWA,OAAO,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-driver.trace-capture.test.d.ts","sourceRoot":"","sources":["../../../../src/components/chat-driver/chat-driver.trace-capture.test.ts"],"names":[],"mappings":"AAYA,OAAO,uBAAuB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CachePolicy, ChatFallback, ChatInputDuringExecutionMode, ChatMessage, ChatToolChoice, ChatToolDefinition, ChatToolHandlers } from '@genesislcap/foundation-ai';
|
|
2
|
-
export type { CachePolicy, ChatFallback, ChatInputDuringExecutionMode, ChatToolChoice };
|
|
1
|
+
import type { CachePolicy, ChatFallback, ChatInputDuringExecutionMode, ChatMessage, ChatThinkingPolicy, ChatToolChoice, ChatToolDefinition, ChatToolHandlers } from '@genesislcap/foundation-ai';
|
|
2
|
+
export type { CachePolicy, ChatFallback, ChatInputDuringExecutionMode, ChatThinkingPolicy, ChatToolChoice, };
|
|
3
3
|
/**
|
|
4
4
|
* Context passed to `onActivate` / `onDeactivate` lifecycle hooks on an agent.
|
|
5
5
|
*
|
|
@@ -136,6 +136,31 @@ export type ToolChoiceInput = ChatToolChoice | ((ctx: SystemPromptContext) => Ch
|
|
|
136
136
|
* @beta
|
|
137
137
|
*/
|
|
138
138
|
export type CachePolicyInput = CachePolicy | ((ctx: SystemPromptContext) => CachePolicy | Promise<CachePolicy>);
|
|
139
|
+
/**
|
|
140
|
+
* Extended-thinking posture for an agent — whether the model reasons before answering. Either a
|
|
141
|
+
* static `ChatThinkingPolicy` or a function resolved **once per user turn**, at the start of the
|
|
142
|
+
* tool loop. Pick the function form to vary it by current state: reason in the state that makes a
|
|
143
|
+
* real decision, and drop it in states that only step a known sequence, where reasoning bills at
|
|
144
|
+
* the full output rate to re-derive what the state machine already knows.
|
|
145
|
+
*
|
|
146
|
+
* Note the resolution point, which differs from every other per-turn input here: a tool-use loop
|
|
147
|
+
* is a single assistant turn and its thinking mode must hold for the whole of it, so this resolver
|
|
148
|
+
* is consulted on the first model call of a turn and its answer reused for the rest. A resolver
|
|
149
|
+
* that returns a different value part-way through a loop will not see it applied until the next
|
|
150
|
+
* user turn.
|
|
151
|
+
*
|
|
152
|
+
* **Omit — or return `undefined` from the function — to keep the model's own default**, which is
|
|
153
|
+
* a distinct third state rather than a synonym for either value: Sonnet 5 and Fable 5 think by
|
|
154
|
+
* default, the rest do not. So an agent that leaves this unset, or a resolver that answers
|
|
155
|
+
* `undefined` on some turns, behaves and prices exactly as it did before this option existed.
|
|
156
|
+
*
|
|
157
|
+
* A request, not a guarantee — transports clamp what a model cannot honour (Fable 5 and Gemini
|
|
158
|
+
* 2.5 Pro always think) and warn once instead of failing the turn. Resolved and applied the same
|
|
159
|
+
* way as {@link TemperatureInput}. See `ChatThinkingPolicy`.
|
|
160
|
+
*
|
|
161
|
+
* @beta
|
|
162
|
+
*/
|
|
163
|
+
export type ThinkingPolicyInput = ChatThinkingPolicy | ((ctx: SystemPromptContext) => ChatThinkingPolicy | undefined | Promise<ChatThinkingPolicy | undefined>);
|
|
139
164
|
/**
|
|
140
165
|
* Per-turn tail context for an agent — volatile content (current file/spec, diagnostics, live
|
|
141
166
|
* state) injected at the tail of every model-call so the model sees it without invalidating the
|
|
@@ -309,6 +334,18 @@ interface BaseAgentConfig {
|
|
|
309
334
|
* @beta
|
|
310
335
|
*/
|
|
311
336
|
cachePolicy?: CachePolicyInput;
|
|
337
|
+
/**
|
|
338
|
+
* Extended-thinking posture for this agent — whether the model reasons before answering. Either
|
|
339
|
+
* a static value or a function resolved **once per user turn** and held for that turn's whole
|
|
340
|
+
* tool loop (vary by state: `'auto'` where the turn is a genuine decision, `'off'` where it only
|
|
341
|
+
* steps a known sequence and reasoning is billed at the full output rate for no benefit). Omit —
|
|
342
|
+
* or return `undefined` — to keep the model's own default, which is neither `'auto'` nor `'off'`
|
|
343
|
+
* uniformly. Provider-neutral; transports clamp models that cannot honour it.
|
|
344
|
+
* See {@link ThinkingPolicyInput}.
|
|
345
|
+
*
|
|
346
|
+
* @beta
|
|
347
|
+
*/
|
|
348
|
+
thinkingPolicy?: ThinkingPolicyInput;
|
|
312
349
|
/**
|
|
313
350
|
* Volatile per-turn context injected at the tail of every model-call (after the history and any
|
|
314
351
|
* cache breakpoint), so it is seen each turn without busting the cached prefix — the place to put
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,4BAA4B,EAC5B,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAEpC,YAAY,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,4BAA4B,EAC5B,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAEpC,YAAY,EACV,WAAW,EACX,YAAY,EACZ,4BAA4B,EAC5B,kBAAkB,EAClB,cAAc,GACf,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,UAAU,EAAE,MAAM,CAAC;IACnB,+FAA+F;IAC/F,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,yDAAyD;IACzD,MAAM,EAAE,WAAW,CAAC;IACpB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,KAAK,EAAE,OAAO,CAAC;IACf,iDAAiD;IACjD,QAAQ,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IACrC,2FAA2F;IAC3F,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IACpC,mFAAmF;IACnF,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,MAAM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AED;;;;;;;;GAQG;AACH,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB;;;;;;;;;;;OAWG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC;IACf,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,qBAAqB,GAAG,mBAAmB,CAAC;AAEtE;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,WAAW,CAAC,KAAK,CAAC,CAAC,SAAS,WAAW,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAErE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CachePolicy, ChatMessage, ChatToolChoice, ChatToolDefinition, ChatToolHandlers } from '@genesislcap/foundation-ai';
|
|
1
|
+
import type { CachePolicy, ChatMessage, ChatThinkingPolicy, ChatToolChoice, ChatToolDefinition, ChatToolHandlers } from '@genesislcap/foundation-ai';
|
|
2
2
|
import type { AgentConfig, AgentLifecycleContext, AgentPersistenceContext, ChatInputDuringExecutionMode, ManualSelectionConfig, SystemPromptContext, UnresolvedToolContext } from './config';
|
|
3
3
|
/**
|
|
4
4
|
* Context passed to per-turn resolvers on a stateful agent — the standard
|
|
@@ -145,6 +145,20 @@ export interface StatefulAgentInit<S> {
|
|
|
145
145
|
* request no caching.
|
|
146
146
|
*/
|
|
147
147
|
cachePolicy?: CachePolicy | ((ctx: StatefulAgentContext<S>) => CachePolicy | Promise<CachePolicy>);
|
|
148
|
+
/**
|
|
149
|
+
* Extended-thinking posture. Either a static `ChatThinkingPolicy` or a function resolved with
|
|
150
|
+
* the current `state` **once per user turn** — the function form is the point of this option on
|
|
151
|
+
* a machine agent: `'auto'` in the state that makes a real decision, `'off'` in the states that
|
|
152
|
+
* only step a known sequence, where reasoning is billed at the full output rate to re-derive
|
|
153
|
+
* what the machine already knows. Omit, or return `undefined` from the function, to keep the
|
|
154
|
+
* model's own default for that turn.
|
|
155
|
+
*
|
|
156
|
+
* Resolved once per turn rather than per tool-loop iteration (unlike `temperature` and
|
|
157
|
+
* `toolChoice`): a tool-use loop is one assistant turn and its thinking mode must hold for the
|
|
158
|
+
* whole of it. A state transition part-way through a loop therefore takes effect on the next
|
|
159
|
+
* user turn, not immediately.
|
|
160
|
+
*/
|
|
161
|
+
thinkingPolicy?: ChatThinkingPolicy | ((ctx: StatefulAgentContext<S>) => ChatThinkingPolicy | undefined | Promise<ChatThinkingPolicy | undefined>);
|
|
148
162
|
/**
|
|
149
163
|
* Volatile per-turn tail context (current file/spec, diagnostics, live state). Either a static
|
|
150
164
|
* string or a function resolved each tool-loop iteration with the current `state`. Provide raw
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-stateful-agent.d.ts","sourceRoot":"","sources":["../../../src/config/define-stateful-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EAEvB,4BAA4B,EAC5B,qBAAqB,EAErB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"define-stateful-agent.d.ts","sourceRoot":"","sources":["../../../src/config/define-stateful-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EAEvB,4BAA4B,EAC5B,qBAAqB,EAErB,mBAAmB,EAQn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EAAuC,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAG1F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"main.template.d.ts","sourceRoot":"","sources":["../../../src/main/main.template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AASH,OAAO,EAAuC,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAG1F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AA2QpD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,oBAAoB,GAAI,GAAG,qBAAqB,KAAG,MAOlD,CAAC;AAEf;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,mBAAmB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,mBAAmB,GAAI,GAAG,qBAAqB,KAAG,MAAM,GAAG,IAC5B,CAAC;AAoD7C,gBAAgB;AAChB,eAAO,MAAM,6BAA6B,GACxC,oBAAoB,MAAM,KACzB,YAAY,CAAC,qBAAqB,CAwhBpC,CAAC"}
|
|
@@ -7,7 +7,7 @@ import type { AgentConfig } from '../config/config';
|
|
|
7
7
|
* `onDeactivate`, `getDebugSnapshot`, `onUnresolvedTool`) and the function
|
|
8
8
|
* form of the per-turn resolvers (`systemPrompt`, `toolDefinitions`,
|
|
9
9
|
* `displayName`, `provider`, `temperature`, `toolChoice`, `cachePolicy`,
|
|
10
|
-
* `toolHandlers`).
|
|
10
|
+
* `thinkingPolicy`, `toolHandlers`).
|
|
11
11
|
* 2. **Object "handler bags" whose *values* are functions** — `toolHandlers` in
|
|
12
12
|
* its object form is `{ name: handler }`, so `typeof` is `'object'`, not
|
|
13
13
|
* `'function'`. A by-value check on the field alone misses it, leaking a live
|
|
@@ -3,7 +3,7 @@ import type { AggregateUsage, ChatMessage } from '@genesislcap/foundation-ai';
|
|
|
3
3
|
* Zeroed {@link AggregateUsage}. A factory, not a shared const, because callers
|
|
4
4
|
* accumulate into the returned object.
|
|
5
5
|
*
|
|
6
|
-
* @
|
|
6
|
+
* @beta
|
|
7
7
|
*/
|
|
8
8
|
export declare function emptyUsage(): AggregateUsage;
|
|
9
9
|
/**
|
|
@@ -16,7 +16,7 @@ export declare function emptyUsage(): AggregateUsage;
|
|
|
16
16
|
* NOT the count of distinct tokens in the conversation, so it grows
|
|
17
17
|
* super-linearly with turn count and is expected to dwarf the context size.
|
|
18
18
|
*
|
|
19
|
-
* @
|
|
19
|
+
* @beta
|
|
20
20
|
*/
|
|
21
21
|
export declare function totalTokens(usage: AggregateUsage): number;
|
|
22
22
|
/**
|
|
@@ -26,7 +26,7 @@ export declare function totalTokens(usage: AggregateUsage): number;
|
|
|
26
26
|
* proves. Pure rather than in-place because both operands are live state a caller
|
|
27
27
|
* must not mutate.
|
|
28
28
|
*
|
|
29
|
-
* @
|
|
29
|
+
* @beta
|
|
30
30
|
*/
|
|
31
31
|
export declare function addUsage(a: AggregateUsage, b: AggregateUsage): AggregateUsage;
|
|
32
32
|
/**
|
|
@@ -53,7 +53,40 @@ export declare function addUsage(a: AggregateUsage, b: AggregateUsage): Aggregat
|
|
|
53
53
|
* Returns a zeroed total when no message carries usage — providers that report
|
|
54
54
|
* none (e.g. Chrome built-in) are skipped silently rather than guessed at.
|
|
55
55
|
*
|
|
56
|
-
* @
|
|
56
|
+
* @remarks
|
|
57
|
+
* This sums the WHOLE array, which is the right answer only when the array is the
|
|
58
|
+
* whole of the work being billed. A driver whose conversation **continues across
|
|
59
|
+
* rounds** opens its history with turns an earlier round already paid for, so
|
|
60
|
+
* summing it again bills them twice — and the session total then grows
|
|
61
|
+
* quadratically in the number of rounds while every individual figure in it stays
|
|
62
|
+
* correct. Nothing about the result looks wrong, which is why it is called out
|
|
63
|
+
* here rather than left to the caller to notice.
|
|
64
|
+
*
|
|
65
|
+
* Do NOT solve this with a "sum from this message onwards" marker. Compaction
|
|
66
|
+
* *replaces* the messages it summarises — and compaction is one of this function's
|
|
67
|
+
* own call sites — so the marker message can be absent from history by the time
|
|
68
|
+
* the sum runs, leaving the caller to either fail or silently sum everything,
|
|
69
|
+
* which is the double-count the marker was meant to prevent.
|
|
70
|
+
*
|
|
71
|
+
* Instead hold a **banked baseline**: spend that predates the current transcript,
|
|
72
|
+
* carried as a value, with `usage = banked + live` composed via {@link addUsage}.
|
|
73
|
+
* `resolveBankedUsage` in `utils/cost-session-history.ts` is the worked form, and
|
|
74
|
+
* the shape of its signature is the load-bearing part. It separates three cases:
|
|
75
|
+
*
|
|
76
|
+
* 1. no prior record — a genuine first round, so nothing is banked;
|
|
77
|
+
* 2. prior record, and the live transcript already accounts for it (a restored
|
|
78
|
+
* session) — carry the prior record's own banked figure forward;
|
|
79
|
+
* 3. prior record, and the transcript starts empty — bank the prior record's
|
|
80
|
+
* whole total, because nothing in the transcript can re-derive it.
|
|
81
|
+
*
|
|
82
|
+
* Case 1 and case 3 take the same arithmetic and mean opposite things, so the
|
|
83
|
+
* prior record must be a **required** input with no zero-defaulting path: a
|
|
84
|
+
* caller who carries a transcript and forgets its baseline reports the entire
|
|
85
|
+
* prior conversation as this round's spend. Distinguishing 2 from 3 is a separate
|
|
86
|
+
* decision, and getting it wrong is destructive in the other direction — it
|
|
87
|
+
* rewrites a total down to the current page-load and drops earlier spend.
|
|
88
|
+
*
|
|
89
|
+
* @beta
|
|
57
90
|
*/
|
|
58
91
|
export declare function sumUsage(messages: readonly ChatMessage[]): AggregateUsage;
|
|
59
92
|
//# sourceMappingURL=sum-usage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sum-usage.d.ts","sourceRoot":"","sources":["../../../src/utils/sum-usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9E;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,cAAc,CAQ3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAIzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,cAAc,GAAG,cAAc,CAQ7E;AAED
|
|
1
|
+
{"version":3,"file":"sum-usage.d.ts","sourceRoot":"","sources":["../../../src/utils/sum-usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9E;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,cAAc,CAQ3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAIzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,cAAc,GAAG,cAAc,CAQ7E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,cAAc,CAIzE"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { AIProviderType, ChatMessage } from '@genesislcap/foundation-ai';
|
|
2
|
+
/**
|
|
3
|
+
* One billable unit of spend, projected out of a transcript.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Deliberately **not** a `ChatMessage`, and not an extension of one. A row is a
|
|
7
|
+
* derived record for a ledger, and keeping the types distinct makes the one
|
|
8
|
+
* dangerous mistake — feeding rows back into `sumUsage`, which does its own
|
|
9
|
+
* recursion and would count everything twice — a compile error rather than a
|
|
10
|
+
* plausible wrong number.
|
|
11
|
+
*
|
|
12
|
+
* @beta
|
|
13
|
+
*/
|
|
14
|
+
export interface UsageRow {
|
|
15
|
+
/**
|
|
16
|
+
* Where the spend came from.
|
|
17
|
+
*
|
|
18
|
+
* - `'request'` — one model call, with a message behind it.
|
|
19
|
+
* - `'compaction'` — spend **banked** by a compaction. The turns that incurred it
|
|
20
|
+
* were summarised and deleted, so there is no single call to attribute it to;
|
|
21
|
+
* the amount survives on the summary's `compaction.rolledUpUsage`. Emitted as
|
|
22
|
+
* its own row because otherwise this money is simply missing from a per-call
|
|
23
|
+
* view while remaining present in the total, and the two disagree silently.
|
|
24
|
+
*/
|
|
25
|
+
source: 'request' | 'compaction';
|
|
26
|
+
/**
|
|
27
|
+
* Model that produced the call. `undefined` on a `'compaction'` row: the banked
|
|
28
|
+
* spend covers however many turns were summarised, which may have run on
|
|
29
|
+
* different models, so attributing it to one would invent a fact. (The summary's
|
|
30
|
+
* `compaction.model` is the model that did the *summarising* — a different thing,
|
|
31
|
+
* and not what this spend was.)
|
|
32
|
+
*/
|
|
33
|
+
model?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Vendor that served the call. Taken from the provider the driver stamped on the message,
|
|
36
|
+
* which is authoritative and covers vendors the model allowlists do not — a server-proxied
|
|
37
|
+
* `gpt-5` turn is `'openai'` here and unknown to `vendorOfModel`. Falls back to resolving
|
|
38
|
+
* {@link UsageRow.model} through `vendorOfModel` only for messages persisted before that
|
|
39
|
+
* field existed, and is left unset when neither knows rather than guessed at.
|
|
40
|
+
*/
|
|
41
|
+
provider?: AIProviderType;
|
|
42
|
+
/**
|
|
43
|
+
* USD for this row, as reported by the provider and stamped by the transport.
|
|
44
|
+
*
|
|
45
|
+
* `undefined` means no cost was reported — **not** zero. Nothing here estimates
|
|
46
|
+
* one from the token counts: an estimate is plausible, unremarkable and quietly
|
|
47
|
+
* wrong, whereas a total that is visibly too low gets investigated. A row with
|
|
48
|
+
* tokens but no `costUsd` is worth alarming on; that is the shape that check needs.
|
|
49
|
+
*/
|
|
50
|
+
costUsd?: number;
|
|
51
|
+
/** Non-LLM spend a host reported for this turn (an external service it called). */
|
|
52
|
+
externalCostUsd?: number;
|
|
53
|
+
/** Prompt tokens billed at the full uncached rate — the remainder after the cache buckets. */
|
|
54
|
+
uncachedInputTokens: number;
|
|
55
|
+
/** Prompt tokens served from the provider's cache. */
|
|
56
|
+
cacheReadTokens: number;
|
|
57
|
+
/** Prompt tokens written to the provider's cache. */
|
|
58
|
+
cacheWriteTokens: number;
|
|
59
|
+
/** Generated tokens, including reasoning tokens the provider bills as output. */
|
|
60
|
+
outputTokens: number;
|
|
61
|
+
/** Agent that produced the call, when known. */
|
|
62
|
+
agentName?: string;
|
|
63
|
+
/** Delegation depth: 0 for the top-level conversation, 1 for a sub-agent, 2 for its sub-agent, … */
|
|
64
|
+
subAgentDepth: number;
|
|
65
|
+
/** Id of the tool call that spawned this row's conversation — correlates a row back to its delegation. */
|
|
66
|
+
subAgentOf?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Project a transcript into one row per billable unit of spend.
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* Reads the messages and returns a table; it stores nothing, mutates nothing, and
|
|
73
|
+
* adds nothing to history. Use it where an **aggregate is not enough** — writing
|
|
74
|
+
* usage rows for per-project attribution, a cost dashboard, or auditing which turns
|
|
75
|
+
* came back unpriced. For a single total, `sumUsage` is the answer and this is the
|
|
76
|
+
* wrong tool.
|
|
77
|
+
*
|
|
78
|
+
* Walks the same shape `sumUsage` does, and is guaranteed to agree with it: summing
|
|
79
|
+
* `costUsd` and `externalCostUsd` across these rows equals `sumUsage(...).costUsd`
|
|
80
|
+
* over the same input, and the four token buckets reconcile likewise. That property
|
|
81
|
+
* is the point of the function — a per-call view that quietly disagrees with the
|
|
82
|
+
* total is worse than no per-call view, because both look right in isolation.
|
|
83
|
+
*
|
|
84
|
+
* Covers the two places spend hides:
|
|
85
|
+
*
|
|
86
|
+
* - **Sub-agent conversations.** A delegating tool call carries the child's entire
|
|
87
|
+
* conversation on `toolCall.subAgentTrace`, so a walk of top-level messages alone
|
|
88
|
+
* misses everything a delegating agent spent. A consumer that reimplemented this
|
|
89
|
+
* and omitted the branch reported $0.106 on a run that cost $0.234.
|
|
90
|
+
* - **Compactions.** A compaction deletes the messages it summarises, banking their
|
|
91
|
+
* spend on the summary. Those turns produce a single `source: 'compaction'` row.
|
|
92
|
+
*
|
|
93
|
+
* Messages carrying no usage at all (a user turn, a narration) produce no row.
|
|
94
|
+
*
|
|
95
|
+
* **Do not pass the result to `sumUsage`** — the types prevent it, and the reason is
|
|
96
|
+
* that both recurse, so a pre-flattened list would be counted twice. Both functions
|
|
97
|
+
* take raw history.
|
|
98
|
+
*
|
|
99
|
+
* @beta
|
|
100
|
+
*/
|
|
101
|
+
export declare function usageRows(messages: readonly ChatMessage[]): UsageRow[];
|
|
102
|
+
//# sourceMappingURL=usage-rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-rows.d.ts","sourceRoot":"","sources":["../../../src/utils/usage-rows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,cAAc,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAG9F;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;;;;;OASG;IACH,MAAM,EAAE,SAAS,GAAG,YAAY,CAAC;IACjC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mFAAmF;IACnF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8FAA8F;IAC9F,mBAAmB,EAAE,MAAM,CAAC;IAC5B,sDAAsD;IACtD,eAAe,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,gBAAgB,EAAE,MAAM,CAAC;IACzB,iFAAiF;IACjF,YAAY,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oGAAoG;IACpG,aAAa,EAAE,MAAM,CAAC;IACtB,0GAA0G;IAC1G,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAcD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,QAAQ,EAAE,CAEtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-rows.test.d.ts","sourceRoot":"","sources":["../../../src/utils/usage-rows.test.ts"],"names":[],"mappings":""}
|
|
@@ -35,7 +35,42 @@ export { AnthropicProvider, AnthropicTransport, GeminiProvider, GeminiTransport,
|
|
|
35
35
|
// foundation-ai's REAL list instead of maintaining a parallel hardcoded copy that silently drifts
|
|
36
36
|
// as the platform adds models (a valid new model would otherwise look like a misconfiguration).
|
|
37
37
|
// GENC-1461, create PR #1644 review.
|
|
38
|
-
SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS, isObservableAIProviderRegistry,
|
|
38
|
+
SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS, isObservableAIProviderRegistry,
|
|
39
|
+
// Request pricing. Re-exported HERE, not left to a direct `@genesislcap/foundation-ai`
|
|
40
|
+
// import, for the same reason as everything above it: a headless host that adds its own
|
|
41
|
+
// foundation-ai dependency gets a second copy, and the driver's malformed/truncated
|
|
42
|
+
// handling does `instanceof` on the transports' error classes. Reaching the pricing
|
|
43
|
+
// should not cost a consumer that guarantee.
|
|
44
|
+
//
|
|
45
|
+
// These take RAW provider usage rather than a `ChatMessage` — see the foundation-ai
|
|
46
|
+
// module docs. They are for the path where nothing stamped a cost (a proxied or
|
|
47
|
+
// server-side call holding a usage block); when a message already carries `cost`, use
|
|
48
|
+
// it, because it was computed with the per-TTL cache split the message no longer has.
|
|
49
|
+
ANTHROPIC_CACHE_READ_MULTIPLIER, ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER, anthropicRatesFor, anthropicTokenCost, GEMINI_CACHED_INPUT_MULTIPLIER, GEMINI_LONG_CONTEXT_THRESHOLD, geminiRatesFor, geminiTokenCost,
|
|
50
|
+
// Resolves a model id to its vendor, so a caller holding only `message.model` can pick
|
|
51
|
+
// between the two cost functions above without maintaining its own model→vendor map.
|
|
52
|
+
vendorOfModel, } from '@genesislcap/foundation-ai';
|
|
53
|
+
// Usage/cost summation. A headless consumer attributing spend to a run has no other route to it:
|
|
54
|
+
// the transports' `getLifetimeCost()` is per-instance and lifetime-scoped, so a shared registry
|
|
55
|
+
// makes it unattributable, and re-deriving cost from token counts is wrong in the one direction
|
|
56
|
+
// that matters (`inputTokens` is total prompt size INCLUDING the cached part, so re-pricing charges
|
|
57
|
+
// every cached token at full rate). `sumUsage` reads the per-request cost the transports already
|
|
58
|
+
// stamped, and recurses into `toolCalls[].subAgentTrace` — where the entire spend of a delegating
|
|
59
|
+
// agent lives — and into `compaction.rolledUpUsage`, which is spend whose messages no longer exist.
|
|
60
|
+
// Both are invisible when omitted: the total is merely too low, which reads as a cheap run.
|
|
61
|
+
//
|
|
62
|
+
// `addUsage`/`emptyUsage` are the composition primitives for a conversation that CONTINUES across
|
|
63
|
+
// rounds — see the guidance on `sumUsage` itself. `totalTokens` exists because the four buckets of
|
|
64
|
+
// an `AggregateUsage` are disjoint and safe to add, which the per-message fields are NOT.
|
|
65
|
+
export { addUsage, emptyUsage, sumUsage, totalTokens } from './utils/sum-usage';
|
|
66
|
+
// Per-call projection, for the cases an aggregate cannot serve: usage rows for
|
|
67
|
+
// per-project attribution, a cost dashboard, or auditing which turns came back
|
|
68
|
+
// unpriced. `usageRows` is guaranteed to reconcile with `sumUsage` — including spend a
|
|
69
|
+
// compaction banked, which has no message of its own and which a naive per-message walk
|
|
70
|
+
// therefore drops while the total keeps it. Both take RAW history; `UsageRow` is
|
|
71
|
+
// deliberately not a `ChatMessage`, so passing rows back into `sumUsage` (which recurses
|
|
72
|
+
// itself, and would double-count) does not compile.
|
|
73
|
+
export { usageRows } from './utils/usage-rows';
|
|
39
74
|
// Debug-log harvesting (GENC-1461 unified diagnostics). A headless consumer collates its driver's
|
|
40
75
|
// log — `buildTimelineEntries({ turnSnapshots: driver.getTurnSnapshots(), messages:
|
|
41
76
|
// driver.getHistory(), metaEvents: getMetaEvents(sessionKey) })` → `DiagnosticEntry[]` — ships it to
|