@genesislcap/ai-assistant 15.26.0 → 15.27.0-agent-log-submit.3
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 +1014 -110
- package/dist/ai-assistant.d.ts +236 -99
- package/dist/chat-driver.cjs +460 -373
- package/dist/chat-driver.cjs.map +4 -4
- package/dist/chat-driver.mjs +460 -373
- package/dist/chat-driver.mjs.map +4 -4
- package/dist/custom-elements.json +1171 -248
- package/dist/dts/components/chat-driver/chat-driver.d.ts +28 -200
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/interaction-controller.d.ts +99 -0
- package/dist/dts/components/chat-driver/interaction-controller.d.ts.map +1 -0
- package/dist/dts/components/chat-driver/turn-recorder.d.ts +191 -0
- package/dist/dts/components/chat-driver/turn-recorder.d.ts.map +1 -0
- package/dist/dts/components/settings-modal/settings-modal.d.ts.map +1 -1
- package/dist/dts/components/settings-modal/settings-modal.styles.d.ts.map +1 -1
- package/dist/dts/components/settings-modal/settings-modal.template.d.ts +28 -0
- package/dist/dts/components/settings-modal/settings-modal.template.d.ts.map +1 -1
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/main/main.d.ts +180 -1
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/main/main.styles.d.ts.map +1 -1
- package/dist/dts/main/main.template.d.ts +19 -0
- package/dist/dts/main/main.template.d.ts.map +1 -1
- package/dist/dts/state/ai-assistant-slice.d.ts +7 -1
- package/dist/dts/state/ai-assistant-slice.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-persistence-provider.d.ts +5 -0
- package/dist/dts/state/persistence/session-persistence-provider.d.ts.map +1 -1
- package/dist/dts/state/session-store.d.ts +1 -0
- package/dist/dts/state/session-store.d.ts.map +1 -1
- package/dist/dts/utils/format-message-timestamp.d.ts +77 -0
- package/dist/dts/utils/format-message-timestamp.d.ts.map +1 -0
- package/dist/dts/utils/resolve-debug-log-note.d.ts +25 -0
- package/dist/dts/utils/resolve-debug-log-note.d.ts.map +1 -0
- package/dist/dts/utils/resolve-preference-baseline.d.ts +18 -1
- package/dist/dts/utils/resolve-preference-baseline.d.ts.map +1 -1
- package/dist/esm/components/chat-driver/chat-driver.js +68 -404
- package/dist/esm/components/chat-driver/interaction-controller.js +235 -0
- package/dist/esm/components/chat-driver/turn-recorder.js +206 -0
- package/dist/esm/components/settings-modal/settings-modal.js +1 -0
- package/dist/esm/components/settings-modal/settings-modal.styles.js +85 -5
- package/dist/esm/components/settings-modal/settings-modal.template.js +220 -25
- package/dist/esm/main/main.js +510 -23
- package/dist/esm/main/main.styles.js +75 -0
- package/dist/esm/main/main.template.js +43 -2
- package/dist/esm/state/ai-assistant-slice.js +5 -0
- package/dist/esm/utils/format-message-timestamp.js +126 -0
- package/dist/esm/utils/resolve-debug-log-note.js +37 -0
- package/dist/esm/utils/resolve-preference-baseline.js +54 -2
- package/package.json +16 -16
- package/sandbox/README.md +45 -2
- package/sandbox/sandbox.ts +95 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AIProviderRegistry, ChatAttachment, ChatDriverResult, ChatMessage, InteractionRequestOptions, SubAgentFailureReason } from '@genesislcap/foundation-ai';
|
|
2
2
|
import { BudgetExhaustedError } from '@genesislcap/foundation-ai';
|
|
3
3
|
import { type ActivityBus } from '../../channel/ai-activity-bus';
|
|
4
4
|
import type { AgentConfig, SystemPromptInput, ToolDefinitionsInput, ToolHandlersInput } from '../../config/config';
|
|
@@ -8,8 +8,10 @@ import { type CompactionProjection } from '../../utils/context-tokens';
|
|
|
8
8
|
import { type CompactionPlanOptions } from '../../utils/history-transform';
|
|
9
9
|
import { AgentSession } from '../agent-session/agent-session';
|
|
10
10
|
import type { AiDriver, AllAgentSummary } from '../ai-driver/ai-driver';
|
|
11
|
+
import { type TurnSnapshot } from './turn-recorder';
|
|
11
12
|
/** Re-exported so `from './chat-driver'` keeps resolving these. */
|
|
12
13
|
export { EMPTY_RESPONSE_NUDGE, MALFORMED_CALL_NUDGE, REQUEST_CONTINUATION_TOOL, } from './chat-driver.constants';
|
|
14
|
+
export type { TurnSnapshot } from './turn-recorder';
|
|
13
15
|
/**
|
|
14
16
|
* The `budget` payload carried on a `'budget-exhausted'` {@link ChatDriverResult}.
|
|
15
17
|
* Derived from the type rather than restated so the two cannot drift.
|
|
@@ -27,107 +29,6 @@ type ProviderRefusedDetail = NonNullable<Extract<ChatDriverResult, {
|
|
|
27
29
|
* @beta
|
|
28
30
|
*/
|
|
29
31
|
export type ChatHistoryUpdatedEvent = CustomEvent<ReadonlyArray<ChatMessage>>;
|
|
30
|
-
/**
|
|
31
|
-
* One captured frame of what the LLM saw on a single tool-loop iteration.
|
|
32
|
-
* The driver records these as a ring buffer (cap: configurable via
|
|
33
|
-
* `chatConfig.agent.maxTurnSnapshots`, default 400) so the export log can show,
|
|
34
|
-
* per turn: which agent was active, the resolved system prompt, the tool names
|
|
35
|
-
* visible to the LLM, and any agent-supplied debug snapshot (e.g. machine
|
|
36
|
-
* state for stateful agents).
|
|
37
|
-
*
|
|
38
|
-
* @beta
|
|
39
|
-
*/
|
|
40
|
-
export interface TurnSnapshot {
|
|
41
|
-
/**
|
|
42
|
-
* Turn identifier, always a string. A driver's own turns are the bare counter
|
|
43
|
-
* (`"0"`, `"1"`, … — monotonic, does not reset on agent swap). Turns forwarded
|
|
44
|
-
* up from a sub-agent are re-labelled under the parent turn that activated them
|
|
45
|
-
* — a sub-agent invoked on parent turn 5 contributes `"5-1"`, `"5-2"`, …, and a
|
|
46
|
-
* nested sub-agent on `"5-2"` contributes `"5-2-1"`, …. See
|
|
47
|
-
* `forwardSubAgentSnapshots`.
|
|
48
|
-
*/
|
|
49
|
-
turnIndex: string;
|
|
50
|
-
/** ISO timestamp captured just before the LLM call. */
|
|
51
|
-
timestamp: string;
|
|
52
|
-
/** Name of the agent active when this LLM call ran. */
|
|
53
|
-
agentName?: string;
|
|
54
|
-
/**
|
|
55
|
-
* The agent's resolved system prompt sent to the LLM, verbatim — the **bare** prompt. The
|
|
56
|
-
* fold-surface suffix and the retry nudges live in {@link TurnSnapshot.tailContext} instead, to
|
|
57
|
-
* keep this byte-stable for prompt caching; read both fields to reconstruct what the model saw.
|
|
58
|
-
*/
|
|
59
|
-
systemPrompt?: string;
|
|
60
|
-
/**
|
|
61
|
-
* The framed `<system-reminder>` tail appended to the final user turn for this
|
|
62
|
-
* call, verbatim — never part of stored history, so this snapshot is the only
|
|
63
|
-
* record of it. Carries the framework's volatile additions (fold suffix, retry
|
|
64
|
-
* nudge) and the agent's per-turn `tailContext` (e.g. current file spec, live
|
|
65
|
-
* diagnostics). Undefined when the tail was empty (the normal case).
|
|
66
|
-
*/
|
|
67
|
-
tailContext?: string;
|
|
68
|
-
/** Tool names sent to the LLM, in order — definitions are static per name so names alone suffice. */
|
|
69
|
-
toolNames: string[];
|
|
70
|
-
/**
|
|
71
|
-
* Normalized `0`–`1` sampling temperature in effect for this call, if the
|
|
72
|
-
* agent (or its current state) configured one. Undefined → provider/model
|
|
73
|
-
* default. Mirrors the value resolved from `BaseAgentConfig.temperature`.
|
|
74
|
-
*/
|
|
75
|
-
temperature?: number;
|
|
76
|
-
/**
|
|
77
|
-
* Tool-call mode actually sent to the provider this call — the effective
|
|
78
|
-
* value, including the sub-agent `'required'` default. Undefined → `'auto'`.
|
|
79
|
-
* Mirrors the value resolved from `BaseAgentConfig.toolChoice`.
|
|
80
|
-
*/
|
|
81
|
-
toolChoice?: ChatToolChoice;
|
|
82
|
-
/**
|
|
83
|
-
* Per-turn display label resolved from the agent's `displayName`, e.g.
|
|
84
|
-
* "Guided Booking (Counterparties)". `agentName` stays as the canonical
|
|
85
|
-
* identity used for routing/filtering.
|
|
86
|
-
*/
|
|
87
|
-
agentLabel?: string;
|
|
88
|
-
/** Agent-supplied snapshot — machine state/context for stateful agents, undefined otherwise. */
|
|
89
|
-
agentSnapshot?: unknown;
|
|
90
|
-
/**
|
|
91
|
-
* Concrete model that ran this call (e.g. `'claude-sonnet-4-6'`) — the serving model
|
|
92
|
-
* where the provider reports one, else the model the resolved tier was configured
|
|
93
|
-
* with. Undefined when the provider exposes no `getStatus` and the transport stamped
|
|
94
|
-
* nothing.
|
|
95
|
-
*
|
|
96
|
-
* Recorded per call, so an agent whose `provider` selector varies by state (a tier
|
|
97
|
-
* switch between steps of a flow) has each step attributed to the model that actually
|
|
98
|
-
* ran it — without the reader having to join the turn to the message after it, which
|
|
99
|
-
* is impossible for a call that produced no message.
|
|
100
|
-
*/
|
|
101
|
-
model?: string;
|
|
102
|
-
/**
|
|
103
|
-
* Registry slot the provider resolved under for this call — a tier name like
|
|
104
|
-
* `'high'`/`'low'`, or the registry default's name. Kept alongside {@link
|
|
105
|
-
* TurnSnapshot.model} because they answer different questions: the slot is what the
|
|
106
|
-
* agent asked for, the model is what served it, and repointing a slot at a new model
|
|
107
|
-
* mid-session is only visible when both are recorded.
|
|
108
|
-
*/
|
|
109
|
-
providerName?: string;
|
|
110
|
-
/** Vendor behind the resolved slot (`'anthropic'`, `'gemini'`, …), when the provider reports it. */
|
|
111
|
-
provider?: AIProviderType;
|
|
112
|
-
/**
|
|
113
|
-
* What this one LLM call cost — the four disjoint token buckets plus USD, derived
|
|
114
|
-
* from the response's usage by `messageUsage`. Back-filled when the response lands
|
|
115
|
-
* (the rest of the snapshot is captured *before* the call), so it is `undefined`
|
|
116
|
-
* while the call is in flight, on providers that report no usage, and on a call that
|
|
117
|
-
* threw rather than returning — a malformed-call/truncation/402 error carries no usage
|
|
118
|
-
* block, so any tokens the provider billed for it are not recoverable here.
|
|
119
|
-
*
|
|
120
|
-
* A snapshot is one **model call**, not one user turn: every tool-loop iteration and
|
|
121
|
-
* every retried attempt records its own. That makes this the only record of spend on
|
|
122
|
-
* an attempt that produced no message — a blank or refused response is billed and
|
|
123
|
-
* then discarded (see the empty-response retries), so summing the transcript alone
|
|
124
|
-
* under-reports the turn.
|
|
125
|
-
*
|
|
126
|
-
* For a call that DID produce a message, this is the same money as that message's
|
|
127
|
-
* `cost`/token fields, not additional money — never add turn usage to message usage.
|
|
128
|
-
*/
|
|
129
|
-
usage?: AggregateUsage;
|
|
130
|
-
}
|
|
131
32
|
/**
|
|
132
33
|
* Construction-time configuration for {@link ChatDriver}. Everything except the provider
|
|
133
34
|
* registry is optional — most fields are also settable per-agent via `applyAgent`, so a
|
|
@@ -250,17 +151,8 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
250
151
|
private busy;
|
|
251
152
|
/** Epoch ms when the current turn loop began — drives the `turn.end` duration. */
|
|
252
153
|
private turnStartedAt;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
* Live per-interaction contexts (GENC-1390), keyed by interactionId. Created in
|
|
256
|
-
* `requestInteraction` alongside the pending entry, disposed + removed in
|
|
257
|
-
* `resolveInteraction`. Non-serialisable (sockets, timers, subscriber sets), so
|
|
258
|
-
* they live here on the driver — not on the DOM, not in the persisted store — and
|
|
259
|
-
* therefore survive the element remounts (layout reflow/drag, transcript
|
|
260
|
-
* re-render) that this feature exists to make harmless. At most one is live at a
|
|
261
|
-
* time (see the one-interaction-at-a-time guard in `requestInteraction`).
|
|
262
|
-
*/
|
|
263
|
-
private interactionContexts;
|
|
154
|
+
/** Custom UI interactions: the pending call, its live context, and any host to delegate to. */
|
|
155
|
+
private readonly interactions;
|
|
264
156
|
private systemPrompt?;
|
|
265
157
|
/**
|
|
266
158
|
* Preamble cost of the most recent request, set at the request-build site.
|
|
@@ -305,13 +197,6 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
305
197
|
*/
|
|
306
198
|
private activeAgentLabel?;
|
|
307
199
|
private displayName?;
|
|
308
|
-
/**
|
|
309
|
-
* When set, `requestInteraction` delegates to this callback instead of using
|
|
310
|
-
* this driver's own pending map. Wired by `invokeSubAgent` so a sub-agent's
|
|
311
|
-
* widget renders in — and resolves through — the parent (ultimately the
|
|
312
|
-
* root) driver, where the main UI is listening.
|
|
313
|
-
*/
|
|
314
|
-
private hostInteractionRequester?;
|
|
315
200
|
/**
|
|
316
201
|
* When set (e.g. by OrchestratingDriver), applied only to the conversation slice
|
|
317
202
|
* sent to the model — stored `history` stays unchanged for UI and logging.
|
|
@@ -424,33 +309,10 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
424
309
|
*/
|
|
425
310
|
private agentReleaseRequested;
|
|
426
311
|
/**
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
* arrive. See {@link TurnSnapshot} for the captured shape.
|
|
312
|
+
* Per-turn snapshots, forwarded sub-agent snapshots, and harvested external diagnostics —
|
|
313
|
+
* everything the exported debug log draws from this driver.
|
|
430
314
|
*/
|
|
431
|
-
private
|
|
432
|
-
/**
|
|
433
|
-
* `turn` + `message` diagnostic-log entries harvested from an out-of-band source (a resolved
|
|
434
|
-
* interaction whose widget returned `InteractionResult.diagnostics` — e.g. a server-side
|
|
435
|
-
* ChatDriver's debug log). `event` entries are NOT kept here — they're folded into the session's
|
|
436
|
-
* meta-event registry via `mergeMetaEvents` (see `resolveInteraction`) so they inherit fresh host
|
|
437
|
-
* indices, and reach the log through `getMetaEvents`. Append-only; the host folds these into its
|
|
438
|
-
* debug log alongside this driver's own timeline. Not cleared here — it lives with the driver
|
|
439
|
-
* instance, like `turnSnapshots`, so a new chat (fresh driver) starts empty while a compaction
|
|
440
|
-
* (same instance) keeps it. (GENC-1461.)
|
|
441
|
-
*/
|
|
442
|
-
private readonly externalDiagnostics;
|
|
443
|
-
/**
|
|
444
|
-
* Monotonic count of external-diagnostics batches harvested this driver-lifetime. Namespaces each
|
|
445
|
-
* batch's re-keyed `turn` entries so distinct server generations in one chat session can't collide
|
|
446
|
-
* on `turnIndex` in the forward-capture persister (which dedups turns by that key). (GENC-1461.)
|
|
447
|
-
*/
|
|
448
|
-
private externalDiagnosticsBatches;
|
|
449
|
-
/** Monotonic counter that survives agent swaps — useful for cross-referencing with history. */
|
|
450
|
-
private globalTurnIndex;
|
|
451
|
-
/** Captured from `applyAgent` so we don't store the whole `AgentConfig`. */
|
|
452
|
-
private debugSnapshotter?;
|
|
453
|
-
private readonly maxTurnSnapshots;
|
|
315
|
+
private readonly turnRecorder;
|
|
454
316
|
/**
|
|
455
317
|
* Aborted by `dispose()` on driver teardown (e.g. an agent-config swap).
|
|
456
318
|
* Threaded into every provider call as `ChatRequestOptions.signal`, so a
|
|
@@ -642,7 +504,7 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
642
504
|
* on to completion or the transport timeout. Called by the host on driver
|
|
643
505
|
* swap and by `OrchestratingDriver.dispose()`. Idempotent.
|
|
644
506
|
*
|
|
645
|
-
* Deliberately does NOT settle
|
|
507
|
+
* Deliberately does NOT settle pending interactions here: dispose is never
|
|
646
508
|
* reached while one is pending. The only host-level dispose is the agent-swap
|
|
647
509
|
* rebuild, which is guarded by `isBusy()` — a pending interaction keeps the
|
|
648
510
|
* tool loop suspended (`busy === true`), so the swap is deferred until the
|
|
@@ -883,7 +745,7 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
883
745
|
* log exporter to show what the LLM saw on each turn — system prompt, tool
|
|
884
746
|
* surface, and agent-supplied state (e.g. a machine snapshot).
|
|
885
747
|
*
|
|
886
|
-
* Ring-buffered at `
|
|
748
|
+
* Ring-buffered at `maxTurnSnapshots`; older entries are dropped.
|
|
887
749
|
*/
|
|
888
750
|
getTurnSnapshots(): ReadonlyArray<TurnSnapshot>;
|
|
889
751
|
/**
|
|
@@ -891,37 +753,10 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
891
753
|
* `InteractionResult.diagnostics` (e.g. a server-side ChatDriver's collated debug log). The host
|
|
892
754
|
* concatenates these into its own debug log so `downloadDebugLog`/the persisted diagnostics stream
|
|
893
755
|
* include external-engine logs; `event` entries are excluded here because they're merged into the
|
|
894
|
-
* session's meta-event registry instead
|
|
895
|
-
*
|
|
756
|
+
* session's meta-event registry instead and reach the log via `getMetaEvents`. Opaque,
|
|
757
|
+
* chronologically sorted by the host at assemble time. (GENC-1461.)
|
|
896
758
|
*/
|
|
897
759
|
getExternalDiagnostics(): ReadonlyArray<DiagnosticEntry>;
|
|
898
|
-
/**
|
|
899
|
-
* Merge a sub-agent's turn snapshots into this driver's buffer so they surface
|
|
900
|
-
* as `kind:'turn'` entries in the exported debug log. The child runs as a
|
|
901
|
-
* separate, discarded driver, so its snapshots would otherwise be lost. Each is
|
|
902
|
-
* re-labelled under the parent turn that activated the sub-agent: the child's
|
|
903
|
-
* own (numeric) turns become `"<parentTurn>-1"`, `"-2"`, … (1-based, in order);
|
|
904
|
-
* any already-forwarded grand-child labels (strings) have their leading segment
|
|
905
|
-
* remapped the same way, so nesting composes (`"5-2"` → `"5-2-1"`).
|
|
906
|
-
*
|
|
907
|
-
* Note: two sub-agents invoked in the *same* parent turn share the prefix, so
|
|
908
|
-
* their labels can repeat — `agentName` on each snapshot disambiguates them.
|
|
909
|
-
*/
|
|
910
|
-
private forwardSubAgentSnapshots;
|
|
911
|
-
/**
|
|
912
|
-
* Push one snapshot to the ring buffer. Called inside `runToolLoop` just
|
|
913
|
-
* before each LLM call — that's the latest point where the prompt, tool
|
|
914
|
-
* surface, and agent state line up with what the model is about to see.
|
|
915
|
-
*
|
|
916
|
-
* Returns the pushed object so the caller can back-fill what only the response
|
|
917
|
-
* knows (`usage`). Mutating it after the fact is safe whether or not the ring
|
|
918
|
-
* buffer has since evicted it — an evicted snapshot is simply no longer exported.
|
|
919
|
-
*/
|
|
920
|
-
private recordTurnSnapshot;
|
|
921
|
-
/**
|
|
922
|
-
* Optional transform applied to conversation history immediately before each LLM request.
|
|
923
|
-
* Cleared when `undefined`. Does not alter stored history.
|
|
924
|
-
*/
|
|
925
760
|
/**
|
|
926
761
|
* Mid-loop context guard policy (GENC-1567). `undefined` disables the guard.
|
|
927
762
|
*
|
|
@@ -955,6 +790,10 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
955
790
|
* far is not lost.
|
|
956
791
|
*/
|
|
957
792
|
private contextExhausted;
|
|
793
|
+
/**
|
|
794
|
+
* Optional transform applied to conversation history immediately before each LLM request.
|
|
795
|
+
* Cleared when `undefined`. Does not alter stored history.
|
|
796
|
+
*/
|
|
958
797
|
setProviderHistoryTransform(transform?: (history: ChatMessage[]) => ChatMessage[]): void;
|
|
959
798
|
getHistory(): ReadonlyArray<ChatMessage>;
|
|
960
799
|
getRawHistory(): readonly ChatMessage[];
|
|
@@ -1040,21 +879,12 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
1040
879
|
*/
|
|
1041
880
|
requestInteraction<T>(componentName: string, data: any, options?: InteractionRequestOptions): Promise<T>;
|
|
1042
881
|
/**
|
|
1043
|
-
* Add external (non-LLM) spend to an interaction's message AFTER it has resolved
|
|
1044
|
-
*
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
* does its whole job inside `if (interaction)` and then deletes the entry from
|
|
1048
|
-
* `pendingInteractions`. That is correct for the resolution itself, but it assumes a widget stops
|
|
1049
|
-
* costing money when it resolves, and several deliberately do not: a widget that resolves EARLY so
|
|
1050
|
-
* the assistant stops waiting (options shown, a preview rendered) may stay interactive for minutes
|
|
1051
|
-
* afterwards and do more paid work on the user's behalf. Re-emitting `interaction-completed` does
|
|
1052
|
-
* not help — with the interaction gone from the map the call is a silent no-op — so that spend had
|
|
1053
|
-
* nowhere to go and was simply missing from the figure shown to the user.
|
|
882
|
+
* Add external (non-LLM) spend to an interaction's message AFTER it has resolved — for a widget
|
|
883
|
+
* that resolves early so the assistant stops waiting, then keeps doing paid work on the user's
|
|
884
|
+
* behalf. `InteractionController.recordExternalCost` explains why the resolution path cannot
|
|
885
|
+
* carry this.
|
|
1054
886
|
*
|
|
1055
|
-
* Additive by design: the caller reports a DELTA, not a running total, so repeated calls sum.
|
|
1056
|
-
* touches only `externalCostUsd`; the recorded `interaction.resolved` payload is left exactly as
|
|
1057
|
-
* the resolution wrote it, because this is not a second resolution and must not read like one.
|
|
887
|
+
* Additive by design: the caller reports a DELTA, not a running total, so repeated calls sum.
|
|
1058
888
|
*
|
|
1059
889
|
* Deliberately does NOT require the interaction to be pending, does not resurrect it, and has no
|
|
1060
890
|
* loading/turn side effects — this is bookkeeping about a turn that already happened.
|
|
@@ -1064,8 +894,8 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
1064
894
|
* @returns `true` when the spend was recorded; `false` when it was not — either the value was
|
|
1065
895
|
* not a positive finite amount, or the message is no longer in history (trimmed or condensed
|
|
1066
896
|
* away). A real outcome a caller may want to log rather than a failure to throw on; every
|
|
1067
|
-
* `false` also records an `interaction.external-cost-dropped` meta event
|
|
1068
|
-
*
|
|
897
|
+
* `false` also records an `interaction.external-cost-dropped` meta event, so money can never
|
|
898
|
+
* disappear without a trace.
|
|
1069
899
|
* @beta
|
|
1070
900
|
*/
|
|
1071
901
|
recordExternalCost(interactionId: string, costUsd: number): boolean;
|
|
@@ -1081,14 +911,10 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
1081
911
|
*/
|
|
1082
912
|
getInteractionContext(interactionId: string): InteractionContext | undefined;
|
|
1083
913
|
/**
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1086
|
-
* the widget is parked in *this* driver's map (interactions resolve on the
|
|
1087
|
-
* host, not the child), so cancelling it here unblocks the sub-agent handler
|
|
1088
|
-
* awaiting it. The "one interaction at a time" invariant means there is at
|
|
1089
|
-
* most one.
|
|
914
|
+
* Replace the history message owning `interactionId`. `false` when it is no longer in history.
|
|
915
|
+
* Does not announce the change — the interaction paths differ on whether they should.
|
|
1090
916
|
*/
|
|
1091
|
-
private
|
|
917
|
+
private patchInteractionMessage;
|
|
1092
918
|
/**
|
|
1093
919
|
* Seeds the driver with a prior conversation history so a new component instance
|
|
1094
920
|
* can continue an existing conversation. Call this before the first user message.
|
|
@@ -1151,5 +977,7 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
|
|
|
1151
977
|
*/
|
|
1152
978
|
private appendDriverNotice;
|
|
1153
979
|
private appendToHistory;
|
|
980
|
+
/** Announce the current history to the host. */
|
|
981
|
+
private notifyHistoryUpdated;
|
|
1154
982
|
}
|
|
1155
983
|
//# sourceMappingURL=chat-driver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-driver.d.ts","sourceRoot":"","sources":["../../../../src/components/chat-driver/chat-driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
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,EAGhB,WAAW,EASX,yBAAyB,EACzB,qBAAqB,EAGtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,oBAAoB,EAOrB,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;AAU7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAM1E,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAGL,KAAK,qBAAqB,EAG3B,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAmBxE,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAElE,mEAAmE;AACnE,OAAO,EACL,oBAAoB,EACpB,oBAA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AW,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA0D/F;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,OAAO,CAAC,mBAAmB;IAoG3B;;;;;OAKG;YACW,cAAc;IAyP5B;;;OAGG;IACG,mBAAmB,CAAC,eAAe,CAAC,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;YA6DvE,WAAW;IA4lCzB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,eAAe;IAiBvB,gDAAgD;IAChD,OAAO,CAAC,oBAAoB;CAO7B"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ChatMessage, InteractionRequestOptions } from '@genesislcap/foundation-ai';
|
|
2
|
+
import type { ActivityBus } from '../../channel/ai-activity-bus';
|
|
3
|
+
import type { InteractionContext } from '../../types/interaction-context';
|
|
4
|
+
/**
|
|
5
|
+
* What a controller needs from the driver that owns it: the session it files meta events under,
|
|
6
|
+
* and the history and event target the interaction is rendered and resolved through.
|
|
7
|
+
*/
|
|
8
|
+
export interface InteractionDeps {
|
|
9
|
+
/** The debug-log session key. */
|
|
10
|
+
readonly sessionKey: string;
|
|
11
|
+
/** Signals the park boundary, so turn-aware UI can tell computing from awaiting the user. */
|
|
12
|
+
readonly activityBus: ActivityBus;
|
|
13
|
+
/** Read per call rather than captured: the active agent changes on a swap. */
|
|
14
|
+
activeAgentName(): string | undefined;
|
|
15
|
+
/** Append a message to the driver's history, which notifies the host itself. */
|
|
16
|
+
appendToHistory(message: ChatMessage): void;
|
|
17
|
+
/**
|
|
18
|
+
* Replace the history message owning `interactionId`. `false` when it is no longer in history
|
|
19
|
+
* (trimmed or condensed away). Does NOT notify the host — see `notifyHistoryUpdated`.
|
|
20
|
+
*/
|
|
21
|
+
patchInteractionMessage(interactionId: string, patch: (message: ChatMessage) => ChatMessage): boolean;
|
|
22
|
+
/** Announce the patched history on `history-updated`. */
|
|
23
|
+
notifyHistoryUpdated(): void;
|
|
24
|
+
/** Dispatch on the driver — the host listens there, not here. */
|
|
25
|
+
emit(event: Event): void;
|
|
26
|
+
/** Hand a widget's harvested `InteractionResult.diagnostics` to the driver's turn recorder. */
|
|
27
|
+
foldDiagnostics(interactionId: string, harvested: unknown): void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Custom UI interactions: parking a tool handler on a widget, and settling it when the user (or a
|
|
31
|
+
* timeout) answers.
|
|
32
|
+
*
|
|
33
|
+
* Owns the pending call and its live context, which are created and destroyed together. Everything
|
|
34
|
+
* else it needs is the driver's history and event target, reached through `InteractionDeps`.
|
|
35
|
+
*/
|
|
36
|
+
export declare class InteractionController {
|
|
37
|
+
private readonly deps;
|
|
38
|
+
private readonly pending;
|
|
39
|
+
/**
|
|
40
|
+
* Live per-interaction contexts (GENC-1390), keyed by interactionId. Created in `request`
|
|
41
|
+
* alongside the pending entry, disposed + removed in `resolve`. Non-serialisable (sockets,
|
|
42
|
+
* timers, subscriber sets), so they live here — not on the DOM, not in the persisted store — and
|
|
43
|
+
* therefore survive the element remounts (layout reflow/drag, transcript re-render) that this
|
|
44
|
+
* feature exists to make harmless. At most one is live at a time (see the
|
|
45
|
+
* one-interaction-at-a-time guard in `request`).
|
|
46
|
+
*/
|
|
47
|
+
private readonly contexts;
|
|
48
|
+
/**
|
|
49
|
+
* When set, `request` delegates to this callback instead of using this controller's own pending
|
|
50
|
+
* map. Wired by `invokeSubAgent` so a sub-agent's widget renders in — and resolves through — the
|
|
51
|
+
* parent (ultimately the root) driver, where the main UI is listening.
|
|
52
|
+
*/
|
|
53
|
+
private hostRequester?;
|
|
54
|
+
constructor(deps: InteractionDeps);
|
|
55
|
+
/** See `ChatDriver.setHostInteractionRequester`. */
|
|
56
|
+
setHostRequester(fn: <T>(componentName: string, data: any, options?: InteractionRequestOptions) => Promise<T>): void;
|
|
57
|
+
/** See `ChatDriver.requestInteraction`. */
|
|
58
|
+
request<T>(componentName: string, data: any, options?: InteractionRequestOptions): Promise<T>;
|
|
59
|
+
/**
|
|
60
|
+
* See `ChatDriver.resolveInteraction`. Warns and returns when the id is unknown — a widget can
|
|
61
|
+
* report twice, and the second report has nothing left to settle.
|
|
62
|
+
*/
|
|
63
|
+
resolve(interactionId: string, result: any): void;
|
|
64
|
+
/**
|
|
65
|
+
* See `ChatDriver.recordExternalCost`.
|
|
66
|
+
*
|
|
67
|
+
* **Why this exists separately from `resolve`.** A widget's spend reaches the session total only
|
|
68
|
+
* through `InteractionResult.costUsd`, which is read exactly once — `resolve` does its whole job
|
|
69
|
+
* against a live pending entry and then deletes it. That is correct for the resolution itself,
|
|
70
|
+
* but it assumes a widget stops costing money when it resolves, and several deliberately do not:
|
|
71
|
+
* a widget that resolves EARLY so the assistant stops waiting (options shown, a preview
|
|
72
|
+
* rendered) may stay interactive for minutes afterwards and do more paid work on the user's
|
|
73
|
+
* behalf. Re-emitting `interaction-completed` does not help — with the interaction gone from the
|
|
74
|
+
* map the call is a silent no-op — so that spend had nowhere to go and was simply missing from
|
|
75
|
+
* the figure shown to the user.
|
|
76
|
+
*
|
|
77
|
+
* Touches only `externalCostUsd`: the recorded `interaction.resolved` payload is left exactly as
|
|
78
|
+
* the resolution wrote it, because this is not a second resolution and must not read like one.
|
|
79
|
+
*/
|
|
80
|
+
recordExternalCost(interactionId: string, costUsd: number): boolean;
|
|
81
|
+
/** See `ChatDriver.getInteractionContext`. */
|
|
82
|
+
context(interactionId: string): InteractionContext | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Resolve every in-flight interaction with a `'timeout'` result, closing its
|
|
85
|
+
* widget read-only. Used when a sub-agent that owns the open widget times out:
|
|
86
|
+
* the widget is parked in *this* driver's map (interactions resolve on the
|
|
87
|
+
* host, not the child), so cancelling it here unblocks the sub-agent handler
|
|
88
|
+
* awaiting it. The "one interaction at a time" invariant means there is at
|
|
89
|
+
* most one.
|
|
90
|
+
*/
|
|
91
|
+
cancelAll(message: string): void;
|
|
92
|
+
/**
|
|
93
|
+
* Drop any live interaction contexts on driver teardown. Normally empty (a context is created
|
|
94
|
+
* and destroyed with its pending interaction, and dispose is not reached mid-interaction);
|
|
95
|
+
* disposed defensively so a stray context can never leak an open socket/timer.
|
|
96
|
+
*/
|
|
97
|
+
disposeContexts(): void;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=interaction-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interaction-controller.d.ts","sourceRoot":"","sources":["../../../../src/components/chat-driver/interaction-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,yBAAyB,EAE1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAMjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAa1E;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,6FAA6F;IAC7F,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,8EAA8E;IAC9E,eAAe,IAAI,MAAM,GAAG,SAAS,CAAC;IACtC,gFAAgF;IAChF,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5C;;;OAGG;IACH,uBAAuB,CACrB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,WAAW,GAC3C,OAAO,CAAC;IACX,yDAAyD;IACzD,oBAAoB,IAAI,IAAI,CAAC;IAC7B,iEAAiE;IACjE,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACzB,+FAA+F;IAC/F,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;CAClE;AAED;;;;;;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