@genesislcap/ai-assistant 15.35.1 → 15.35.4

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.
Files changed (27) hide show
  1. package/dist/ai-assistant.api.json +483 -0
  2. package/dist/ai-assistant.d.ts +192 -0
  3. package/dist/chat-driver.cjs +221 -4
  4. package/dist/chat-driver.cjs.map +2 -2
  5. package/dist/chat-driver.mjs +221 -4
  6. package/dist/chat-driver.mjs.map +2 -2
  7. package/dist/custom-elements.json +267 -1
  8. package/dist/dts/components/ai-driver/ai-driver.d.ts +31 -0
  9. package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
  10. package/dist/dts/components/chat-driver/chat-driver.d.ts +93 -0
  11. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  12. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +17 -0
  13. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
  14. package/dist/dts/state/persistence/index.d.ts +1 -0
  15. package/dist/dts/state/persistence/index.d.ts.map +1 -1
  16. package/dist/dts/state/persistence/session-persister.d.ts +12 -0
  17. package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
  18. package/dist/dts/state/persistence/session-snapshot.d.ts +14 -0
  19. package/dist/dts/state/persistence/session-snapshot.d.ts.map +1 -1
  20. package/dist/dts/utils/condense-history.d.ts +114 -0
  21. package/dist/dts/utils/condense-history.d.ts.map +1 -1
  22. package/dist/esm/components/chat-driver/chat-driver.js +140 -17
  23. package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +17 -0
  24. package/dist/esm/state/persistence/session-persister.js +63 -15
  25. package/dist/esm/state/persistence/session-snapshot.js +2 -17
  26. package/dist/esm/utils/condense-history.js +123 -0
  27. package/package.json +18 -18
@@ -1 +1 @@
1
- {"version":3,"file":"session-persister.d.ts","sourceRoot":"","sources":["../../../../src/state/persistence/session-persister.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EA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AAK,EAAE,kBAAkB,GAAG,IAAI;IAchD;;;;;;OAMG;IACH,mBAAmB,IAAI,IAAI;IAiB3B;;;;;;OAMG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAYvC;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,uBAAuB;IA6C/B,sEAAsE;IACtE,OAAO,IAAI,IAAI;CAMhB"}
1
+ {"version":3,"file":"session-persister.d.ts","sourceRoot":"","sources":["../../../../src/state/persistence/session-persister.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAYrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAE5E,OAAO,KAAK,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AA8CnG;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,cAAc,EAAE,MAAM,wBAAwB,CAAC;IAC/C,+EAA+E;IAC/E,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,oEAAoE;IACpE,SAAS,EAAE,MAAM,QAAQ,GAAG,SAAS,CAAC;IACtC,mEAAmE;IACnE,QAAQ,EAAE,MAAM,kBAAkB,GAAG,SAAS,CAAC;IAC/C;;;;OAIG;IACH,oBAAoB,EAAE,MAAM,eAAe,EAAE,CAAC;IAC9C;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,CAAC,MAAM,EAAE;QAC7B,oEAAoE;QACpE,eAAe,EAAE,MAAM,CAAC;QACxB,mEAAmE;QACnE,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,+DAA+D;QAC/D,MAAM,EAAE,MAAM,CAAC;KAChB,KAAK,IAAI,CAAC;IACX,uFAAuF;IACvF,sBAAsB,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B;IAsB9B;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,iBAAiB;IAQzB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,yBAAyB;IAiBjC;;;;OAIG;YACW,cAAc;IAiO5B;;;;;;OAMG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAyL9B;;;;;;;OAOG;IACH,OAAO,CAAC,uBAAuB;IAU/B;;;;OAIG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBvC;;;;OAIG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAatC;;;;;OAKG;IACH,eAAe,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI;IAchD;;;;;;OAMG;IACH,mBAAmB,IAAI,IAAI;IAiB3B;;;;;;OAMG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAYvC;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,uBAAuB;IA6C/B,sEAAsE;IACtE,OAAO,IAAI,IAAI;CAMhB"}
@@ -1,4 +1,5 @@
1
1
  import type { ChatMessage } from '@genesislcap/foundation-ai';
2
+ import type { PersistedCondensePolicy } from '../../utils/condense-history';
2
3
  import type { LoadSessionPayload } from '../ai-assistant-slice';
3
4
  /**
4
5
  * Schema version of the persisted session shape. Bump on an incompatible
@@ -51,6 +52,18 @@ export interface PersistedSession {
51
52
  * value shape is the agent's own, hence `unknown`.
52
53
  */
53
54
  agentSnapshots: Record<string, unknown>;
55
+ /**
56
+ * `condenseWhen` policies that had not fired yet when the session was saved, for tool calls in
57
+ * {@link PersistedSession.messages} (GENC-1632). Handed back to the driver on restore so those
58
+ * payloads still collapse when their trigger fires, instead of riding every provider call for the
59
+ * rest of the resumed session at full size. Payloads that HAD already collapsed need no entry:
60
+ * `messages` already stores them as the stubs the model was sent (GENC-1566).
61
+ *
62
+ * Optional and additive, so the schema `version` is unchanged: a snapshot written before this
63
+ * field existed restores exactly as it always did (nothing to re-register), and a reader that
64
+ * predates it ignores it. Omitted rather than written empty when there is nothing to carry.
65
+ */
66
+ condensePolicies?: PersistedCondensePolicy[];
54
67
  /**
55
68
  * Interrupted-flow marker (GENC-1351 §5.9). Present when the session was saved
56
69
  * while an agent declared its current state non-resumable (`resumable === false`).
@@ -86,6 +99,7 @@ export interface PersistedSessionInput {
86
99
  activeModel?: string;
87
100
  activeProviderName?: string;
88
101
  agentSnapshots?: Record<string, unknown>;
102
+ condensePolicies?: PersistedCondensePolicy[];
89
103
  }
90
104
  /**
91
105
  * Assemble a versioned {@link PersistedSession}, stamping `version` and
@@ -1 +1 @@
1
- {"version":3,"file":"session-snapshot.d.ts","sourceRoot":"","sources":["../../../../src/state/persistence/session-snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,qFAAqF;IACrF,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,qDAAqD;IACrD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iEAAiE;IACjE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kEAAkE;IAClE,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,8CAA8C;IAC9C,cAAc,EAAE,MAAM,CAAC;IACvB,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAA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;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,gBAAgB,GAAG,kBAAkB,CAe5E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CA6B/E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAIjF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,gBAAgB,EAC1B,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,GAChC,MAAM,EAAE,CAIV;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,aAAa,EAAE,MAAM,GAAG,IAAI,EAC5B,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC;IAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAQxE"}
@@ -42,6 +42,13 @@ export interface RegisteredCondensePolicy {
42
42
  activation: number;
43
43
  /** App-controlled phase epoch when the call was made — the `phaseEnd` clock. */
44
44
  phaseEpoch: number;
45
+ /**
46
+ * Name of the agent whose activation made the call (`undefined` on a driver with no installed
47
+ * agent). Not read by any trigger — `activation` is the clock — but a restored entry needs it to
48
+ * tell whether the agent re-activated after a reload is the one that owned the call, or a
49
+ * different one that has taken over (GENC-1632, see {@link rebaseRestoredCondensePolicy}).
50
+ */
51
+ agent?: string;
45
52
  /** `context.condensed` already emitted for the args payload (fire-once). */
46
53
  reportedArgs?: boolean;
47
54
  /** `context.condensed` already emitted for the response payload (fire-once). */
@@ -105,6 +112,113 @@ export interface CondenseContext {
105
112
  */
106
113
  batchCalls?: number;
107
114
  }
115
+ /**
116
+ * The driver's four condensation clocks as raw values — what {@link RegisteredCondensePolicy}
117
+ * stamps at `condenseWhen` time, and what a persisted entry is re-expressed against on the way out
118
+ * and rebased onto on the way back in (GENC-1632).
119
+ */
120
+ export interface CondenseClocks {
121
+ modelCall: number;
122
+ turn: number;
123
+ activation: number;
124
+ phaseEpoch: number;
125
+ }
126
+ /**
127
+ * A `condenseWhen` policy that had NOT fired when the session was saved, in the shape it is
128
+ * persisted in (GENC-1632).
129
+ *
130
+ * The clocks are stored as **elapsed counts, never raw values**, and that is the whole design. All
131
+ * four driver clocks restart at 0 on a page reload, so a raw stamp means nothing to the driver that
132
+ * reads it back, and it is wrong in whichever direction the arithmetic happens to fall. A phase
133
+ * epoch of 1 restored against a fresh driver's 0 needs TWO `endPhase()` calls to fire, so the
134
+ * Planning-phase document it guards is never shed at the end of Planning; an activation stamp
135
+ * that lands below the fresh driver's clock reads as "a later activation began" — the `agentEnd`
136
+ * trigger — and collapses the payload on the first provider call after the reload, mid-phase.
137
+ * "How far each clock had moved past the call when it was saved" survives any reset, because it
138
+ * is re-applied relative to whatever the new driver's clocks happen to read.
139
+ *
140
+ * Only unfired entries are persisted: a fired one has already been rendered into the stored
141
+ * transcript as the stub the model was sent (GENC-1566), so there is nothing left for it to do.
142
+ *
143
+ * @public
144
+ */
145
+ export interface PersistedCondensePolicy {
146
+ /** The tool call the policy is registered against. */
147
+ toolCallId: string;
148
+ /** The policy exactly as the tool declared it. */
149
+ policy: CondensePolicy;
150
+ /** Name of the agent whose activation made the call; absent on a driver with no installed agent. */
151
+ agent?: string;
152
+ /**
153
+ * How far each clock had advanced past the call's stamp at save time. `0` means "still the
154
+ * current one": the call's turn / activation / phase was the live one when the session was
155
+ * saved. A positive count means that boundary had already passed, so the trigger keyed on it
156
+ * fires on the first provider call after restore (it would have fired on the next call anyway;
157
+ * it only had not been latched because no call had happened since).
158
+ */
159
+ elapsed: {
160
+ modelCalls: number;
161
+ turns: number;
162
+ activations: number;
163
+ phases: number;
164
+ };
165
+ }
166
+ /** Whether `t` is a well-formed trigger — the same rule `condenseWhen` enforces on registration. */
167
+ export declare function isValidCondenseTrigger(t: CondenseTrigger | undefined): boolean;
168
+ /**
169
+ * Every tool-call id carried by an assistant message in `history`. Exported so the save side
170
+ * ({@link snapshotCondensePolicies}) and the restore side (`ChatDriver.restoreCondensePolicies`)
171
+ * compute "is this call still present?" from one definition — GENC-1632 review: the two had drifted
172
+ * into separate copies of the same loop.
173
+ */
174
+ export declare function toolCallIdsIn(history: readonly ChatMessage[]): Set<string>;
175
+ /**
176
+ * The entries to PERSIST alongside `history` (GENC-1632): every registered policy that has not
177
+ * fired yet and whose tool call is still in the transcript being saved, re-expressed as elapsed
178
+ * clock counts (see {@link PersistedCondensePolicy}).
179
+ *
180
+ * `history` is the transcript actually being written, not the driver's live one, because the two
181
+ * can differ: a non-resumable save freezes at the last user message, and a compaction may have
182
+ * summarised a call away. An entry whose call is not in the saved transcript has nothing to
183
+ * collapse after a reload, so it is not written.
184
+ *
185
+ * Pure, no writes to the registry — safe on a save path that runs on every autosave.
186
+ */
187
+ export declare function snapshotCondensePolicies(policies: ReadonlyMap<string, RegisteredCondensePolicy>, clocks: CondenseClocks, history: readonly ChatMessage[]): PersistedCondensePolicy[];
188
+ /**
189
+ * Validate one persisted entry read back from storage. Returns `undefined` for anything that is not
190
+ * a well-formed {@link PersistedCondensePolicy} — the blob came off a disk or a network, and a
191
+ * policy that cannot be evaluated must be dropped rather than reach `applyCondensation`, which
192
+ * trusts its registry. A missing or malformed `elapsed` count reads as `0` (the boundary had not
193
+ * passed), which errs towards keeping a payload visible rather than eliding it.
194
+ */
195
+ export declare function parsePersistedCondensePolicy(value: unknown): PersistedCondensePolicy | undefined;
196
+ /**
197
+ * Re-register a persisted entry against a (typically fresh) driver's clocks (GENC-1632): each
198
+ * stamp is the current clock minus the elapsed count, so every trigger stands exactly as far from
199
+ * firing as it did when the session was saved.
200
+ *
201
+ * Per clock, what that means after a reload:
202
+ * - `age` — exact. The model-call distance is preserved, so a result seen twice of its three
203
+ * allowed looks gets one more. The rebased `iteration` is usually negative (the call predates
204
+ * this driver's first model call), which the trigger arithmetic is indifferent to; it does
205
+ * surface as a negative `turn` on the eventual `context.condensed` event.
206
+ * - `turnEnd` — a call from the turn that was running at save time collapses on the next
207
+ * `sendMessage`. That is the original intent, not an approximation: a reload ends the turn.
208
+ * - `phaseEnd` — collapses at the next `endPhase()`, or at once if the phase had already ended.
209
+ * - `agentEnd` (and `phaseEnd`'s backstop) — an entry whose activation had already ended collapses
210
+ * at once. One owned by the activation live at save time is stamped with the CURRENT
211
+ * activation, which reads as live; but the driver will very likely advance its activation clock
212
+ * when the agent is re-installed after the reload, so this stamp is provisional and the driver
213
+ * must re-stamp it at that point — see `ChatDriver.installAgent`. Leaving it here would collapse
214
+ * the payload the moment the flow resumes, which is the failure this whole mechanism exists to
215
+ * avoid.
216
+ *
217
+ * The `reported*` latches start clear, so the eventual full→stub transition reports once, like any
218
+ * other entry. The stored transcript cannot hold a stub for an unfired entry, so there is no
219
+ * earlier report to duplicate.
220
+ */
221
+ export declare function rebaseRestoredCondensePolicy(entry: PersistedCondensePolicy, clocks: CondenseClocks): RegisteredCondensePolicy;
108
222
  /**
109
223
  * Structured detail for a `context.condensed` meta-event. The index signature
110
224
  * lets it satisfy `recordMetaEvent`'s `Record<string, unknown>` detail param
@@ -1 +1 @@
1
- {"version":3,"file":"condense-history.d.ts","sourceRoot":"","sources":["../../../src/utils/condense-history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG/F;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC,uFAAuF;AACvF,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,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BAAuB,GAAG,SAAS,CAyBhG;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,uBAAuB,EAC9B,MAAM,EAAE,cAAc,GACrB,wBAAwB,CAS1B;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,WAAW,EAAE,MAAM,CAAC;CACrB;AAiID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,WAAW,EAAE,EACtB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,wBAAwB,CAAC,EAC/C,GAAG,EAAE,eAAe,EACpB,WAAW,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,GAClD,WAAW,EAAE,CAyKf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,WAAW,EAAE,EACtB,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,wBAAwB,CAAC,GACtD,WAAW,EAAE,CA8Df"}
@@ -4,7 +4,7 @@ import { NOOP_ACTIVITY_BUS } from '../../channel/ai-activity-bus';
4
4
  import { resolveChatProvider } from '../../config/validate-providers';
5
5
  import { clearSession, getMetaEvents, mergeMetaEvents, recordMetaEvent, recordTurnError, recordTurnRetry, } from '../../state/debug-event-log';
6
6
  import { generateSuggestions } from '../../suggestions/generate-suggestions';
7
- import { applyCondensation, condenseForPersistence, } from '../../utils/condense-history';
7
+ import { applyCondensation, condenseForPersistence, isValidCondenseTrigger, parsePersistedCondensePolicy, rebaseRestoredCondensePolicy, snapshotCondensePolicies, toolCallIdsIn, } from '../../utils/condense-history';
8
8
  import { estimatePreambleTokens, estimateRequestTokens, } from '../../utils/context-tokens';
9
9
  import { applyHistoryCap, buildCompactionSummaryPrompt, planCompaction, normalizeForProvider, } from '../../utils/history-transform';
10
10
  import { logger } from '../../utils/logger';
@@ -92,8 +92,29 @@ export class ChatDriver extends EventTarget {
92
92
  * provider call to collapse stale payloads from the model-bound history only.
93
93
  * Accumulates across agents on a shared driver (a superseded read collapses no
94
94
  * matter which agent made it) and is never cleared — it dies with the driver.
95
+ *
96
+ * "Dies with the driver" used to mean a page reload silently disarmed every policy that had
97
+ * not fired yet: the restored transcript carried the full payload and nothing was left to
98
+ * collapse it, so it rode every later provider call (GENC-1632). The unfired entries are now
99
+ * persisted with the session and re-registered on restore — see
100
+ * {@link ChatDriver.getCondensePoliciesForPersistence} and
101
+ * {@link ChatDriver.restoreCondensePolicies}.
95
102
  */
96
103
  this.condensePolicies = new Map();
104
+ /**
105
+ * Restored policies whose owning activation was still live at save time, waiting for that agent
106
+ * to be re-installed so they can be stamped with the activation it resumes in (GENC-1632).
107
+ *
108
+ * They cannot be stamped at restore time. On a fresh page `activeAgentName` is unset, so the
109
+ * first `installAgent` after the reload is a "name change" and advances `currentActivation` —
110
+ * which is exactly the `agentEnd` signal. An entry stamped before that bump reads as belonging
111
+ * to an activation that has ended, and it and every `phaseEnd` entry (through the `agentEnd`
112
+ * backstop) collapse on the first provider call after the reload, mid-flow. For Create's
113
+ * Planning phase that is the uploaded scope document vanishing the moment the user carries on
114
+ * talking about it — a worse failure than the one being fixed. So the stamp is deferred to that
115
+ * `installAgent`, and consumed there once whichever agent it installs.
116
+ */
117
+ this.condenseAwaitingReactivation = new Set();
97
118
  /**
98
119
  * Monotonic model-call counter for the driver's whole lifetime — the age clock
99
120
  * for `condenseWhen({ on: { kind: 'age' } })`. The per-`sendMessage` `iterations`
@@ -625,8 +646,10 @@ export class ChatDriver extends EventTarget {
625
646
  // flow is over, so its `agentEnd`-tagged payloads become collapsible. Guarded
626
647
  // on a name change so re-applying the same agent (e.g. a per-turn re-resolve)
627
648
  // does not spuriously advance the clock and prematurely drop its payloads.
628
- if (config.name !== this.activeAgentName)
649
+ if (config.name !== this.activeAgentName) {
629
650
  this.currentActivation += 1;
651
+ this.resumeRestoredCondensePolicies(config.name);
652
+ }
630
653
  this.systemPrompt = config.systemPrompt;
631
654
  if (typeof config.toolDefinitions === 'function') {
632
655
  this.toolDefinitionsFactory = config.toolDefinitions;
@@ -997,6 +1020,113 @@ export class ChatDriver extends EventTarget {
997
1020
  getHistoryForPersistence() {
998
1021
  return condenseForPersistence([...this.history], this.condensePolicies);
999
1022
  }
1023
+ /** The four condensation clocks as they read now. */
1024
+ condenseClocks() {
1025
+ return {
1026
+ modelCall: this.modelCallSeq,
1027
+ turn: this.turnSeq,
1028
+ activation: this.currentActivation,
1029
+ phaseEpoch: this.currentPhaseEpoch,
1030
+ };
1031
+ }
1032
+ /**
1033
+ * The `condenseWhen` policies that have not fired yet, for the calls in `messages`, in the
1034
+ * clock-independent form {@link ChatDriver.restoreCondensePolicies} re-registers. See
1035
+ * {@link AiDriver.getCondensePoliciesForPersistence}.
1036
+ *
1037
+ * The other half of {@link ChatDriver.getHistoryForPersistence} (GENC-1632). That stores the
1038
+ * payloads the model has already stopped seeing as their stubs; this stores the policies for the
1039
+ * ones it has NOT stopped seeing yet, so a reload does not strand them at full size for the rest
1040
+ * of the session. Only entries whose call is in `messages` — the transcript actually being
1041
+ * written — are returned, so a frozen (non-resumable) or compacted save carries no policy for a
1042
+ * call it does not contain.
1043
+ *
1044
+ * @beta
1045
+ */
1046
+ getCondensePoliciesForPersistence(messages) {
1047
+ return snapshotCondensePolicies(this.condensePolicies, this.condenseClocks(), messages);
1048
+ }
1049
+ /**
1050
+ * Re-register policies saved by {@link ChatDriver.getCondensePoliciesForPersistence} against
1051
+ * the restored transcript. See {@link AiDriver.restoreCondensePolicies}.
1052
+ *
1053
+ * Call AFTER {@link ChatDriver.loadHistory} has seeded the restored transcript: an entry is
1054
+ * re-registered only if its tool call is in the driver's history, so one whose call the
1055
+ * restorable-boundary trim cut away (an orphaned trailing `tool_use`) is dropped rather than
1056
+ * resurrected against nothing.
1057
+ *
1058
+ * First-wins still holds per call: an entry is skipped if a policy is already registered for its
1059
+ * tool call — a restore never overrides what a live handler declared. `superseded` needs no
1060
+ * special handling — survivors are resolved from HISTORY order on every pass, so a restored entry
1061
+ * and a later call on the same `by` key resolve exactly as two live ones would.
1062
+ *
1063
+ * Clocks are rebased so each trigger is exactly as far from firing as it was at save time (see
1064
+ * `rebaseRestoredCondensePolicy`), with one deferral. An entry owned by the activation that was
1065
+ * live at save time, whose agent is not the one installed right now — the normal case on a
1066
+ * fresh page, where nothing is installed yet — is parked in
1067
+ * `condenseAwaitingReactivation` and stamped by the next `installAgent`: with
1068
+ * that agent's resumed activation if it is the same agent, or left behind (so it reads as
1069
+ * ended, which it has) if a different agent took over.
1070
+ *
1071
+ * A host with no agent to re-activate (a bare driver built from a static config) loses nothing
1072
+ * by this: the entry's owner (`undefined`) matches the installed agent (`undefined`), so it is
1073
+ * stamped live straight away and ends when the driver's single activation does — on
1074
+ * `releaseAgent` / `completeSubAgent`, exactly as a policy registered live would.
1075
+ *
1076
+ * Returns how many entries were actually re-armed, split from how many were merely present in
1077
+ * `entries` (review follow-up, GENC-1632): a malformed entry, one whose call the restorable-
1078
+ * boundary trim removed, or a first-wins duplicate is silently dropped, so the caller's own count
1079
+ * of `entries` can't tell "all of them came back" from "none did". `restored` is every entry that
1080
+ * reached `condensePolicies`; `awaitingReactivation` is the subset of those parked pending the
1081
+ * next `installAgent` rather than stamped live immediately.
1082
+ *
1083
+ * @beta
1084
+ */
1085
+ restoreCondensePolicies(entries) {
1086
+ if (!Array.isArray(entries) || entries.length === 0)
1087
+ return { restored: 0, awaitingReactivation: 0 };
1088
+ const present = toolCallIdsIn(this.history);
1089
+ const clocks = this.condenseClocks();
1090
+ let restored = 0;
1091
+ let awaitingReactivation = 0;
1092
+ for (const raw of entries) {
1093
+ const entry = parsePersistedCondensePolicy(raw);
1094
+ if (!entry || !present.has(entry.toolCallId))
1095
+ continue;
1096
+ if (this.condensePolicies.has(entry.toolCallId))
1097
+ continue;
1098
+ this.condensePolicies.set(entry.toolCallId, rebaseRestoredCondensePolicy(entry, clocks));
1099
+ restored += 1;
1100
+ if (entry.elapsed.activations === 0 && entry.agent !== this.activeAgentName) {
1101
+ this.condenseAwaitingReactivation.add(entry.toolCallId);
1102
+ awaitingReactivation += 1;
1103
+ }
1104
+ }
1105
+ return { restored, awaitingReactivation };
1106
+ }
1107
+ /**
1108
+ * Stamp the restored entries parked in `condenseAwaitingReactivation` now that
1109
+ * `installAgent` has advanced the activation clock for `agentName` (GENC-1632).
1110
+ *
1111
+ * Same agent → the flow the entry belonged to is resuming, so it takes the new activation and
1112
+ * stays full until THAT activation ends (and, for `phaseEnd`, until the next `endPhase()`).
1113
+ * Different agent → its owner did not come back; its activation is over, so it keeps the stamp
1114
+ * it was restored with, which is now behind the clock, and collapses on the next provider call
1115
+ * exactly as a live `agentEnd` payload does on a swap.
1116
+ *
1117
+ * One-shot: the set is emptied whatever the outcome, because only the FIRST activation after the
1118
+ * restore can be the resumption. Any later swap is an ordinary activation boundary.
1119
+ */
1120
+ resumeRestoredCondensePolicies(agentName) {
1121
+ if (this.condenseAwaitingReactivation.size === 0)
1122
+ return;
1123
+ for (const toolCallId of this.condenseAwaitingReactivation) {
1124
+ const entry = this.condensePolicies.get(toolCallId);
1125
+ if (entry && entry.agent === agentName)
1126
+ entry.activation = this.currentActivation;
1127
+ }
1128
+ this.condenseAwaitingReactivation.clear();
1129
+ }
1000
1130
  /**
1001
1131
  * {@inheritDoc AiDriver.getSuggestions}
1002
1132
  *
@@ -1338,12 +1468,9 @@ export class ChatDriver extends EventTarget {
1338
1468
  return;
1339
1469
  }
1340
1470
  const triggers = Array.isArray(policy.on) ? policy.on : [policy.on];
1341
- const validTrigger = (t) => (t === null || t === void 0 ? void 0 : t.kind) === 'superseded'
1342
- ? typeof t.by === 'string' && t.by.length > 0
1343
- : (t === null || t === void 0 ? void 0 : t.kind) === 'age'
1344
- ? typeof t.turns === 'number' && t.turns >= 1
1345
- : (t === null || t === void 0 ? void 0 : t.kind) === 'turnEnd' || (t === null || t === void 0 ? void 0 : t.kind) === 'agentEnd' || (t === null || t === void 0 ? void 0 : t.kind) === 'phaseEnd';
1346
- if (triggers.length === 0 || !triggers.every(validTrigger)) {
1471
+ // Shared with the restore path's validation (GENC-1632), so a policy that could not be
1472
+ // registered live can never be re-registered from a stored session either.
1473
+ if (triggers.length === 0 || !triggers.every(isValidCondenseTrigger)) {
1347
1474
  logger.warn(`ChatDriver(${(_b = this.activeAgentName) !== null && _b !== void 0 ? _b : 'unknown'}): condenseWhen called with an invalid trigger — ignoring`);
1348
1475
  return;
1349
1476
  }
@@ -1353,15 +1480,11 @@ export class ChatDriver extends EventTarget {
1353
1480
  logger.error(`ChatDriver(${(_c = this.activeAgentName) !== null && _c !== void 0 ? _c : 'unknown'}): condenseWhen called more than once for the same tool call — keeping the first policy, ignoring this one`);
1354
1481
  return;
1355
1482
  }
1356
- // Stamp the three clocks NOW (read straight off the driver — the handler
1357
- // runs during the current model-call's tool batch).
1358
- this.condensePolicies.set(activeToolCallId, {
1359
- policy,
1360
- iteration: this.modelCallSeq,
1361
- turn: this.turnSeq,
1362
- activation: this.currentActivation,
1363
- phaseEpoch: this.currentPhaseEpoch,
1364
- });
1483
+ // Stamp the four clocks NOW (read straight off the driver — the handler
1484
+ // runs during the current model-call's tool batch). `agent` is not a clock; it is
1485
+ // recorded so a persisted entry can tell, after a reload, whether the agent that
1486
+ // re-activates is the one that owned the call (GENC-1632).
1487
+ this.condensePolicies.set(activeToolCallId, Object.assign({ policy, iteration: this.modelCallSeq, turn: this.turnSeq, activation: this.currentActivation, phaseEpoch: this.currentPhaseEpoch }, (this.activeAgentName !== undefined && { agent: this.activeAgentName })));
1365
1488
  } });
1366
1489
  }
1367
1490
  /**
@@ -312,6 +312,23 @@ export class OrchestratingDriver extends EventTarget {
312
312
  getHistoryForPersistence() {
313
313
  return this.chatDriver.getHistoryForPersistence();
314
314
  }
315
+ /**
316
+ * Delegates to the inner {@link ChatDriver}, which owns the condensation registry and clocks
317
+ * (GENC-1632). The forward matters for the same reason as `getHistoryForPersistence` above: the
318
+ * persister reaches it through `?.`, so a missing forward would compile, pass the ChatDriver
319
+ * tests, and do nothing for every orchestrated host — which is every host with an agents array.
320
+ */
321
+ getCondensePoliciesForPersistence(messages) {
322
+ return this.chatDriver.getCondensePoliciesForPersistence(messages);
323
+ }
324
+ /**
325
+ * Delegates to the inner {@link ChatDriver} (GENC-1632). The deferred activation stamp it
326
+ * performs is taken by the inner driver's `installAgent`, which this driver's own
327
+ * `installAgent` always reaches, so nothing extra is needed here.
328
+ */
329
+ restoreCondensePolicies(entries) {
330
+ return this.chatDriver.restoreCondensePolicies(entries);
331
+ }
315
332
  /** {@inheritDoc AiDriver.setContextGuard} */
316
333
  setContextGuard(policy) {
317
334
  this.chatDriver.setContextGuard(policy);
@@ -263,6 +263,30 @@ export class SessionPersister {
263
263
  const raw = (_d = (_b = (_a = driver === null || driver === void 0 ? void 0 : driver.getHistoryForPersistence) === null || _a === void 0 ? void 0 : _a.call(driver)) !== null && _b !== void 0 ? _b : (_c = driver === null || driver === void 0 ? void 0 : driver.getRawHistory) === null || _c === void 0 ? void 0 : _c.call(driver)) !== null && _d !== void 0 ? _d : storeMessages;
264
264
  return raw.filter((m) => !isSessionNoticeMarker(m));
265
265
  }
266
+ /**
267
+ * The `condenseWhen` policies still waiting to fire for the calls in `messages` (GENC-1632) —
268
+ * the half of condensation `getHistoryForPersistence` cannot carry, because a payload whose
269
+ * trigger has not fired is stored full and needs its policy to collapse after a reload.
270
+ *
271
+ * `flowDropped` is the frozen (non-resumable) save: its snapshot drops the running flow, so the
272
+ * activation that owned the pending payloads does not resume and they are written as ended.
273
+ *
274
+ * Never throws: a failure here costs a resumed session some context, which is not worth losing
275
+ * the save over.
276
+ */
277
+ condensePoliciesToPersist(driver, messages, opts = {}) {
278
+ var _a;
279
+ try {
280
+ const pending = (_a = driver === null || driver === void 0 ? void 0 : driver.getCondensePoliciesForPersistence) === null || _a === void 0 ? void 0 : _a.call(driver, messages);
281
+ if (!(pending === null || pending === void 0 ? void 0 : pending.length) || !opts.flowDropped)
282
+ return pending;
283
+ return pending.map((e) => e.elapsed.activations > 0 ? e : Object.assign(Object.assign({}, e), { elapsed: Object.assign(Object.assign({}, e.elapsed), { activations: 1 }) }));
284
+ }
285
+ catch (e) {
286
+ logger.error('Session save: capturing condense policies failed:', e);
287
+ return undefined;
288
+ }
289
+ }
266
290
  /**
267
291
  * Capture the current session to durable storage (GENC-1351 §5.1). Reads the
268
292
  * full transcript from the driver and the restorable scalars from the store, and
@@ -340,10 +364,11 @@ export class SessionPersister {
340
364
  // completed exchanges that were already safely stored. Taking the max of the two
341
365
  // makes the boundary monotonic: it advances with each new prompt and never rewinds.
342
366
  const boundary = Math.max(keepThroughLastUserMessage(messages).length, this._persistedMessages);
367
+ const frozenMessages = messages.slice(0, Math.min(boundary, messages.length));
343
368
  const frozen = createPersistedSession({
344
369
  sessionKey: key,
345
370
  host: window.location.host,
346
- messages: messages.slice(0, Math.min(boundary, messages.length)),
371
+ messages: frozenMessages,
347
372
  activeAgentName: (_a = s.activeAgent) === null || _a === void 0 ? void 0 : _a.name,
348
373
  pinnedAgentName: s.pinnedAgentName,
349
374
  flowOwnerAgentName: null,
@@ -353,6 +378,14 @@ export class SessionPersister {
353
378
  activeModel: s.activeModel,
354
379
  activeProviderName: s.activeProviderName,
355
380
  agentSnapshots: {},
381
+ // Pending condense policies are carried here too (GENC-1632), but with the live
382
+ // activation marked as ENDED: this snapshot drops the flow's state, so on return the
383
+ // agent starts afresh rather than resuming, and the activation those payloads belonged to
384
+ // is over. Without the mark, a re-run of the same agent would be taken for a resumption
385
+ // and adopt the dead flow's `agentEnd` / `phaseEnd` payloads for its whole new run.
386
+ condensePolicies: this.condensePoliciesToPersist(driver, frozenMessages, {
387
+ flowDropped: true,
388
+ }),
356
389
  });
357
390
  // Skip the write when the frozen boundary has not moved — a flow autosaves on every
358
391
  // transcript change, and while it runs the last user message (and therefore the
@@ -420,6 +453,7 @@ export class SessionPersister {
420
453
  activeModel: s.activeModel,
421
454
  activeProviderName: s.activeProviderName,
422
455
  agentSnapshots,
456
+ condensePolicies: this.condensePoliciesToPersist(driver, messages),
423
457
  });
424
458
  // Observability (GENC-1351): record what each autosave captured for stateful
425
459
  // agents — `agents: []` here means no machine snapshot was taken (the bug to
@@ -487,7 +521,7 @@ export class SessionPersister {
487
521
  */
488
522
  restore() {
489
523
  return __awaiter(this, void 0, void 0, function* () {
490
- var _a, _b, _c, _d;
524
+ var _a, _b, _c, _d, _e;
491
525
  const { provider } = this.deps.getPersistence();
492
526
  if (!provider)
493
527
  return;
@@ -543,16 +577,6 @@ export class SessionPersister {
543
577
  // Seed the monotonic freeze floor too (GENC-1511): a flow that goes non-resumable
544
578
  // straight after a restore must not freeze BELOW what the restore just brought back.
545
579
  this._persistedMessages = trimmed.length;
546
- // Observability (GENC-1351): record exactly what the restore primed, so a
547
- // post-reload debug-log export shows whether a stateful agent's snapshot
548
- // actually came back (meta events reset on reload, so this is the only window
549
- // onto the saved→loaded handoff).
550
- this.logMeta('persistence.restored', {
551
- agents: Object.keys((_a = snapshot.agentSnapshots) !== null && _a !== void 0 ? _a : {}),
552
- agentSnapshots: snapshot.agentSnapshots,
553
- pinnedAgentName: snapshot.pinnedAgentName,
554
- flowOwnerAgentName: snapshot.flowOwnerAgentName,
555
- });
556
580
  // Loudly surface saved agent state that can't be rehydrated because the agent
557
581
  // isn't in the current set — otherwise the flow silently fails to resume, a
558
582
  // real footgun for hosts with dynamic agent arrays. Non-fatal: the transcript
@@ -616,7 +640,31 @@ export class SessionPersister {
616
640
  }
617
641
  const messages = [...trimmed, ...trailers];
618
642
  ref.actions.aiAssistant.loadSession(toLoadSessionPayload(Object.assign(Object.assign({}, snapshot), { messages })));
619
- (_b = driver === null || driver === void 0 ? void 0 : driver.loadHistory) === null || _b === void 0 ? void 0 : _b.call(driver, [...messages]);
643
+ (_a = driver === null || driver === void 0 ? void 0 : driver.loadHistory) === null || _a === void 0 ? void 0 : _a.call(driver, [...messages]);
644
+ // Re-arm the condense policies that had not fired at save time (GENC-1632) — AFTER
645
+ // `loadHistory`, because the driver keeps only entries whose tool call is in the history it
646
+ // now holds, which is how an entry for a call `trimToRestorableBoundary` cut away is dropped
647
+ // rather than resurrected. A snapshot from before the field existed has none, so this is a
648
+ // no-op and the restore is exactly what it was. Timing against the agent's re-activation is
649
+ // the driver's problem, not ours: it defers the activation stamp to the next `installAgent`.
650
+ const condenseRestore = (_b = driver === null || driver === void 0 ? void 0 : driver.restoreCondensePolicies) === null || _b === void 0 ? void 0 : _b.call(driver, snapshot.condensePolicies);
651
+ // Observability (GENC-1351, counts refined for GENC-1632 review): record exactly what the
652
+ // restore primed, so a post-reload debug-log export shows whether a stateful agent's snapshot
653
+ // actually came back (meta events reset on reload, so this is the only window onto the
654
+ // saved→loaded handoff). Logged HERE, after `restoreCondensePolicies` has run, rather than
655
+ // where the snapshot was first read: `stored` alone (the old field) counts what the snapshot
656
+ // OFFERED, not what came back — `restoreCondensePolicies` silently drops a malformed entry, one
657
+ // whose call the restorable-boundary trim removed, and a first-wins duplicate, so a bare
658
+ // `stored: 14` can't tell "all 14 re-armed" from "0 re-armed". `restored`/`awaitingReactivation`
659
+ // are left OFF the object (not zeroed) when there is no driver or it predates this method, so
660
+ // that case can't be misread as "re-armed none" either.
661
+ this.logMeta('persistence.restored', {
662
+ agents: Object.keys((_c = snapshot.agentSnapshots) !== null && _c !== void 0 ? _c : {}),
663
+ condensePolicies: Object.assign({ stored: Array.isArray(snapshot.condensePolicies) ? snapshot.condensePolicies.length : 0 }, condenseRestore),
664
+ agentSnapshots: snapshot.agentSnapshots,
665
+ pinnedAgentName: snapshot.pinnedAgentName,
666
+ flowOwnerAgentName: snapshot.flowOwnerAgentName,
667
+ });
620
668
  // Interrupted flow (§5.9): pre-fill the composer with the prompt that started
621
669
  // the flow so "send it again" is one keystroke, and record it for observability.
622
670
  if (snapshot.interrupted) {
@@ -639,8 +687,8 @@ export class SessionPersister {
639
687
  // driver's routing agrees with the restored (picker-locked) store state.
640
688
  const orchestrator = asOrchestrator(driver);
641
689
  if (orchestrator) {
642
- orchestrator.setPinnedAgent((_c = snapshot.pinnedAgentName) !== null && _c !== void 0 ? _c : null);
643
- orchestrator.setFlowOwner((_d = snapshot.flowOwnerAgentName) !== null && _d !== void 0 ? _d : null);
690
+ orchestrator.setPinnedAgent((_d = snapshot.pinnedAgentName) !== null && _d !== void 0 ? _d : null);
691
+ orchestrator.setFlowOwner((_e = snapshot.flowOwnerAgentName) !== null && _e !== void 0 ? _e : null);
644
692
  }
645
693
  logger.debug('Session restored', { key, messages: messages.length });
646
694
  }
@@ -13,23 +13,8 @@ export const PERSISTED_SESSION_VERSION = 1;
13
13
  * @internal
14
14
  */
15
15
  export function createPersistedSession(input) {
16
- var _a;
17
- return {
18
- version: PERSISTED_SESSION_VERSION,
19
- savedAt: new Date().toISOString(),
20
- host: input.host,
21
- sessionKey: input.sessionKey,
22
- messages: input.messages,
23
- activeAgentName: input.activeAgentName,
24
- pinnedAgentName: input.pinnedAgentName,
25
- flowOwnerAgentName: input.flowOwnerAgentName,
26
- sessionCostUsd: input.sessionCostUsd,
27
- contextTokens: input.contextTokens,
28
- contextLimit: input.contextLimit,
29
- activeModel: input.activeModel,
30
- activeProviderName: input.activeProviderName,
31
- agentSnapshots: (_a = input.agentSnapshots) !== null && _a !== void 0 ? _a : {},
32
- };
16
+ var _a, _b;
17
+ return Object.assign({ version: PERSISTED_SESSION_VERSION, savedAt: new Date().toISOString(), host: input.host, sessionKey: input.sessionKey, messages: input.messages, activeAgentName: input.activeAgentName, pinnedAgentName: input.pinnedAgentName, flowOwnerAgentName: input.flowOwnerAgentName, sessionCostUsd: input.sessionCostUsd, contextTokens: input.contextTokens, contextLimit: input.contextLimit, activeModel: input.activeModel, activeProviderName: input.activeProviderName, agentSnapshots: (_a = input.agentSnapshots) !== null && _a !== void 0 ? _a : {} }, (((_b = input.condensePolicies) === null || _b === void 0 ? void 0 : _b.length) ? { condensePolicies: input.condensePolicies } : {}));
33
18
  }
34
19
  /**
35
20
  * Resolve the notice text + pre-fill prompt for an interrupted (non-resumable) flow