@genesislcap/ai-assistant 15.85.1 → 15.86.0-GENC-0.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 (64) hide show
  1. package/dist/ai-assistant.api.json +5989 -1729
  2. package/dist/ai-assistant.d.ts +802 -2
  3. package/dist/chat-driver.cjs +1378 -84
  4. package/dist/chat-driver.cjs.map +4 -4
  5. package/dist/chat-driver.mjs +1371 -84
  6. package/dist/chat-driver.mjs.map +4 -4
  7. package/dist/custom-elements.json +1775 -68
  8. package/dist/dts/autopilot/autopilot-driver.d.ts +46 -2
  9. package/dist/dts/autopilot/autopilot-driver.d.ts.map +1 -1
  10. package/dist/dts/autopilot/autopilot-session.d.ts +25 -0
  11. package/dist/dts/autopilot/autopilot-session.d.ts.map +1 -1
  12. package/dist/dts/chat-driver-node.d.ts +2 -0
  13. package/dist/dts/chat-driver-node.d.ts.map +1 -1
  14. package/dist/dts/components/ai-driver/ai-driver.d.ts +15 -0
  15. package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
  16. package/dist/dts/components/ai-driver/base-driver-decorator.d.ts +6 -0
  17. package/dist/dts/components/ai-driver/base-driver-decorator.d.ts.map +1 -1
  18. package/dist/dts/components/chat-driver/chat-driver.d.ts +7 -0
  19. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  20. package/dist/dts/components/chat-driver/interaction-controller.d.ts +12 -0
  21. package/dist/dts/components/chat-driver/interaction-controller.d.ts.map +1 -1
  22. package/dist/dts/headless/describe-interaction.d.ts +17 -0
  23. package/dist/dts/headless/describe-interaction.d.ts.map +1 -0
  24. package/dist/dts/headless/headless-debug.d.ts +28 -0
  25. package/dist/dts/headless/headless-debug.d.ts.map +1 -0
  26. package/dist/dts/headless/headless-persistence.d.ts +35 -0
  27. package/dist/dts/headless/headless-persistence.d.ts.map +1 -0
  28. package/dist/dts/headless/headless-session.d.ts +170 -0
  29. package/dist/dts/headless/headless-session.d.ts.map +1 -0
  30. package/dist/dts/headless/headless.types.d.ts +429 -0
  31. package/dist/dts/headless/headless.types.d.ts.map +1 -0
  32. package/dist/dts/headless/index.d.ts +5 -0
  33. package/dist/dts/headless/index.d.ts.map +1 -0
  34. package/dist/dts/index.d.ts +2 -0
  35. package/dist/dts/index.d.ts.map +1 -1
  36. package/dist/dts/main/main.d.ts.map +1 -1
  37. package/dist/dts/state/debug-event-log.d.ts +1 -1
  38. package/dist/dts/state/debug-event-log.d.ts.map +1 -1
  39. package/dist/dts/state/persistence/debug-log-assembly.d.ts +49 -0
  40. package/dist/dts/state/persistence/debug-log-assembly.d.ts.map +1 -0
  41. package/dist/dts/state/persistence/index.d.ts +1 -0
  42. package/dist/dts/state/persistence/index.d.ts.map +1 -1
  43. package/dist/dts/state/persistence/session-persister.d.ts +7 -0
  44. package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
  45. package/dist/esm/autopilot/autopilot-driver.js +112 -6
  46. package/dist/esm/autopilot/autopilot-session.js +31 -16
  47. package/dist/esm/chat-driver-node.js +8 -0
  48. package/dist/esm/components/ai-driver/base-driver-decorator.js +12 -0
  49. package/dist/esm/components/chat-driver/chat-driver.js +8 -0
  50. package/dist/esm/components/chat-driver/interaction-controller.js +66 -0
  51. package/dist/esm/headless/describe-interaction.js +55 -0
  52. package/dist/esm/headless/headless-debug.js +62 -0
  53. package/dist/esm/headless/headless-persistence.js +192 -0
  54. package/dist/esm/headless/headless-session.js +760 -0
  55. package/dist/esm/headless/headless.types.js +1 -0
  56. package/dist/esm/headless/index.js +3 -0
  57. package/dist/esm/index.js +3 -0
  58. package/dist/esm/main/main.js +18 -37
  59. package/dist/esm/state/debug-event-log.js +8 -1
  60. package/dist/esm/state/persistence/debug-log-assembly.js +69 -0
  61. package/dist/esm/state/persistence/index.js +1 -0
  62. package/dist/esm/state/persistence/session-persister.js +16 -0
  63. package/package.json +17 -17
  64. package/scripts/smoke-chat-driver-node.mjs +3 -0
@@ -1229,6 +1229,20 @@ export declare interface AiDriver extends EventTarget {
1229
1229
  * @beta
1230
1230
  */
1231
1231
  addInteractionInterceptor?(interceptor: InteractionInterceptor): () => void;
1232
+ /**
1233
+ * Run one of a pending interaction's surface actions as the person: the programmatic equivalent
1234
+ * of clicking the widget, for a host with no DOM to click (GENC-1660). The interaction is
1235
+ * credited to the person (`answeredBy: 'user'`), never to a claimant, and an action that finishes
1236
+ * it settles it.
1237
+ *
1238
+ * Refused as `not-held` when the interaction has ended, or when a claimant holds it — one is not
1239
+ * pushed aside; the person takes it back first, for example by pausing the autopilot. Any other
1240
+ * refusal is as for `hold.invoke`, and nothing runs. Optional, so a third-party
1241
+ * driver need not implement it; every shipped driver does.
1242
+ *
1243
+ * @beta
1244
+ */
1245
+ invokeAsUser?(interactionId: string, action: string, args?: unknown): Promise<InvokeResult>;
1232
1246
  /**
1233
1247
  * Show a widget in the transcript OUTSIDE any tool loop, and resolve with its result
1234
1248
  * (GENC-1660): `requestInteraction` for something that is not a tool handler. How a decorator
@@ -1965,6 +1979,16 @@ export declare class AutopilotDriver extends BaseDriverDecorator implements Auto
1965
1979
  private turnHandBack?;
1966
1980
  /** A mode restored with the session, waiting for its flow to become the owner again. */
1967
1981
  private restored?;
1982
+ /**
1983
+ * The mode of a hand-off's target that has released, kept for its caller, which has not taken the
1984
+ * lock back yet (GENC-1751): the flow has no owner in between. See `carriedTo`.
1985
+ */
1986
+ private handingBack?;
1987
+ /**
1988
+ * The mode of the flow that just ended, should a one-way hand-off with nobody waiting turn out to
1989
+ * have ended it: that switch announces itself only after the owner has changed (GENC-1751).
1990
+ */
1991
+ private switchedFrom?;
1968
1992
  /**
1969
1993
  * Bumped on every pause and resume, and when its sessions end. A written answer is sent only if
1970
1994
  * none came between asking for it and its landing: one started before a pause is stale after it,
@@ -2005,7 +2029,10 @@ export declare class AutopilotDriver extends BaseDriverDecorator implements Auto
2005
2029
  pause(): void;
2006
2030
  resume(): void;
2007
2031
  stop(): void;
2008
- /** The mode to save with the session, while it is set for the current flow. */
2032
+ /**
2033
+ * The mode to save with the session, while it is set for the current flow — or kept for a
2034
+ * hand-off's caller while its target releases, saved for that target, as the stack saves it.
2035
+ */
2009
2036
  getPersistedMode(): PersistedAutopilotMode | undefined;
2010
2037
  /**
2011
2038
  * Bring back a saved mode. It applies once its flow is the owner again — at once if it already
@@ -2157,6 +2184,36 @@ export declare class AutopilotDriver extends BaseDriverDecorator implements Auto
2157
2184
  /** A claimed interaction settled, whoever settled it. */
2158
2185
  private onSettled;
2159
2186
  private onFlowOwnerChanged;
2187
+ /**
2188
+ * A one-way hand-off with nobody waiting is a plain switch, the caller deactivated, so nothing on
2189
+ * the stack says the owner it changed to took over the same task: its event, raised once the
2190
+ * target is active, does (GENC-1751).
2191
+ */
2192
+ private onHandOffStarted;
2193
+ /** The mode set for the current flow, or kept for the caller of a hand-back under way. */
2194
+ private current;
2195
+ /**
2196
+ * The mode that carries to `owner` because the owner changed for a hand-off or its hand-back, as
2197
+ * the hand-off stack shows it at that moment (GENC-1751):
2198
+ * - a hand-off: `owner` is the top frame's target, which has not finished. Its frame is on the
2199
+ * stack before the target is activated, and so is a waiting caller's passed on by a one-way
2200
+ * hand-off from a target;
2201
+ * - a hand-back: the top frame's target, which the mode is set for, has finished, and `owner` is
2202
+ * its caller, or no one while the target releases. Its frame leaves the stack only after the
2203
+ * caller is active again.
2204
+ *
2205
+ * Clear and an agents change empty the stack before the flow ends, so the mode ends with it, as
2206
+ * it ends with any flow. A turn routed away from the target ends the hand-offs the same way.
2207
+ */
2208
+ private carriedTo;
2209
+ /** Whether `owner` is the caller the top hand-off hands back to from `target`. */
2210
+ private handsBack;
2211
+ /**
2212
+ * Set `carried`'s mode for `owner`, which took the task over in a hand-off or its hand-back. A
2213
+ * pause the person chose carries with it; the autopilot's own hand-back of an interaction does
2214
+ * not, since that interaction settled before the hand-off could start.
2215
+ */
2216
+ private carry;
2160
2217
  private capabilityFor;
2161
2218
  private flowOwner;
2162
2219
  private bindingFor;
@@ -2283,6 +2340,13 @@ export declare interface AutopilotHostState {
2283
2340
  readonly working: boolean;
2284
2341
  }
2285
2342
 
2343
+ /**
2344
+ * The part of an `AutopilotHost` a session uses.
2345
+ *
2346
+ * @beta
2347
+ */
2348
+ export declare type AutopilotLike = Pick<AutopilotHost, 'state' | 'subscribe' | 'pause' | 'resume' | 'stop'>;
2349
+
2286
2350
  /**
2287
2351
  * The autopilot's mode for the current flow (GENC-1660 §4.10). `'unavailable'`: no autopilot for
2288
2352
  * this flow, or not yet (e.g. no approved brief). `'paused'`: available but not answering.
@@ -2696,6 +2760,11 @@ export declare abstract class BaseDriverDecorator<TInner extends AiDriver = AiDr
2696
2760
  * interactions. A decorator that answers interactions installs its own on `this.inner`.
2697
2761
  */
2698
2762
  addInteractionInterceptor(interceptor: InteractionInterceptor): () => void;
2763
+ /**
2764
+ * Forwarded: the interaction belongs to the driver that opened it. An inner driver that cannot
2765
+ * run actions answers as if the interaction had ended.
2766
+ */
2767
+ invokeAsUser(interactionId: string, action: string, args?: unknown): Promise<InvokeResult>;
2699
2768
  presentInteraction<T = InteractionResult>(componentName: string, data: unknown, options?: InteractionRequestOptions): Promise<T>;
2700
2769
  provideHandlerCapability(name: string, factory: HandlerCapabilityFactory): () => void;
2701
2770
  getContextReserve(): ContextReserveResolution | undefined;
@@ -2788,6 +2857,28 @@ declare type BudgetDetail = NonNullable<Extract<ChatDriverResult, {
2788
2857
  */
2789
2858
  export declare function budgetPercentOf(figures: VendorBudgetFigures): number;
2790
2859
 
2860
+ /**
2861
+ * The current page's diagnostic entries (GENC-1351 §5.8): the debug-log timeline entries
2862
+ * (`message`/`turn`/`event`), the driver's external diagnostics, and one `meta-snapshot` carrying
2863
+ * the export-time `meta` block. The assistant element reassembles these into the live log, and the
2864
+ * persister's forward-capture path diffs them against what has already been appended to the stored
2865
+ * stream. Extracted from the element so a host with no element (the headless session) derives its
2866
+ * log from the same code, not a second copy that could drift.
2867
+ *
2868
+ * DOM-free and framework-free.
2869
+ *
2870
+ * @beta
2871
+ */
2872
+ export declare function buildDiagnosticEntries(input: {
2873
+ driver: AiDriver | undefined;
2874
+ /** The debug-log key the meta events are kept under; none, no events. */
2875
+ stateKey: string | undefined;
2876
+ /** The `meta-snapshot` entry for right now (see `buildMetaSnapshot`). */
2877
+ metaSnapshot: () => DiagnosticEntry;
2878
+ /** The transcript to use when the driver has no raw history: the host's own copy. */
2879
+ messages?: readonly ChatMessage[];
2880
+ }): DiagnosticEntry[];
2881
+
2791
2882
  export { CachePolicy }
2792
2883
 
2793
2884
  /**
@@ -3841,6 +3932,12 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
3841
3932
  * @beta
3842
3933
  */
3843
3934
  addInteractionInterceptor(interceptor: InteractionInterceptor): () => void;
3935
+ /**
3936
+ * {@inheritDoc AiDriver.invokeAsUser}
3937
+ *
3938
+ * @beta
3939
+ */
3940
+ invokeAsUser(interactionId: string, action: string, args?: unknown): Promise<InvokeResult>;
3844
3941
  /**
3845
3942
  * {@inheritDoc AiDriver.presentInteraction}
3846
3943
  *
@@ -4788,6 +4885,69 @@ export declare type DelegatedMessage = ChatMessage & {
4788
4885
  delegate: string;
4789
4886
  };
4790
4887
 
4888
+ /**
4889
+ * One action of a pending interaction, as a model reads it: a SurfaceAction cut to what is
4890
+ * useful to choose by, with the number {@link describeInteraction} gave it. Plain data.
4891
+ *
4892
+ * @beta
4893
+ */
4894
+ export declare interface DescribedAction {
4895
+ /**
4896
+ * The number the action is chosen by, when it is a numbered option: the same number the
4897
+ * autopilot's list gives it, so "1" means the same option to both. Absent on a platform-owned
4898
+ * action (`select`, `reply`) or a named, full-form one, which are chosen by `name`.
4899
+ */
4900
+ readonly n?: number;
4901
+ /** The action's name: what `act` runs when it is not chosen by number. */
4902
+ readonly name: string;
4903
+ /** What the person would read on the button, when it differs from the name. */
4904
+ readonly label?: string;
4905
+ /** What a full-form action does, as its widget wrote it. */
4906
+ readonly description?: string;
4907
+ /** Whether it can be taken now. */
4908
+ readonly enabled: boolean;
4909
+ /** Why it cannot be, when it is not enabled and the widget said. */
4910
+ readonly unavailable?: string;
4911
+ /**
4912
+ * What it takes: `'options'` (`select`: several, by number or label), `'text'` (written words)
4913
+ * or `'fields'` (a JSON object fitting `argsSchema`). Absent: nothing.
4914
+ */
4915
+ readonly args?: 'options' | 'text' | 'fields';
4916
+ /** The shape `fields` must fit, for an action that takes them. */
4917
+ readonly argsSchema?: Readonly<Record<string, unknown>>;
4918
+ /** Whether running it settles the interaction. */
4919
+ readonly finishes: boolean;
4920
+ /** Whether it is a written refinement: one that counts against a step's limit. */
4921
+ readonly refines?: boolean;
4922
+ }
4923
+
4924
+ /**
4925
+ * What the person is being asked, as a compact JSON-serialisable record a model can read and
4926
+ * answer (GENC-1660): the same text the autopilot is sent for the decision (`renderDecision`,
4927
+ * so there is one rendering of a decision, not two), and its actions as data, numbered as that text
4928
+ * numbers them, so "1" means the same option here and there.
4929
+ *
4930
+ * With no surface — a widget with no controller, or one that has not exposed anything yet — there
4931
+ * is nothing to act on: `controller` is `false` (or `true` and not `ready`, while a controller that
4932
+ * will expose a surface has not yet), `actions` is empty, and `text` is the widget as text alone.
4933
+ *
4934
+ * Reads the surface fresh each time, so it describes the widget as it is now.
4935
+ *
4936
+ * @beta
4937
+ */
4938
+ export declare function describeInteraction(input: DescribeInteractionInput): InteractionDescription;
4939
+
4940
+ /**
4941
+ * The input of {@link describeInteraction}: a pending interaction as the driver knows it.
4942
+ *
4943
+ * @beta
4944
+ */
4945
+ export declare interface DescribeInteractionInput {
4946
+ readonly ctx: InteractionContext;
4947
+ readonly componentName: string;
4948
+ readonly data: unknown;
4949
+ }
4950
+
4791
4951
  /**
4792
4952
  * One entry in the diagnostics stream — the debug-log timeline-entry union
4793
4953
  * (`message` / `turn` / `event`, as `getDebugLog()` builds) plus a point-in-time
@@ -7276,6 +7436,573 @@ export declare interface HandOffOutcome {
7276
7436
  */
7277
7437
  export declare type HandOffOutcomeKind = 'completed' | 'released' | 'cleared' | 'agent-removed' | 'state-lost';
7278
7438
 
7439
+ /**
7440
+ * What `act` is given besides the action: the arguments a person would fill in.
7441
+ *
7442
+ * @beta
7443
+ */
7444
+ export declare interface HeadlessActArgs {
7445
+ /** Written words, for an action that takes `text`, such as `reply`. */
7446
+ readonly text?: string;
7447
+ /** Options for `select`, by number or label. */
7448
+ readonly options?: readonly string[];
7449
+ /** A form's fields: an object, or JSON text of one. */
7450
+ readonly fields?: unknown;
7451
+ }
7452
+
7453
+ /**
7454
+ * The result of `act`: the driver's, plus the interaction as it stands when it is still open.
7455
+ *
7456
+ * @beta
7457
+ */
7458
+ export declare type HeadlessActResult = InvokeResult & {
7459
+ /** The interaction after the action, when it is still pending. */
7460
+ readonly description?: InteractionDescription;
7461
+ };
7462
+
7463
+ /**
7464
+ * The current page's debug log: what `HeadlessSession.debugLog()` returns when nothing is
7465
+ * persisted, and the fallback when the stored stream cannot be read.
7466
+ *
7467
+ * @beta
7468
+ */
7469
+ export declare function headlessCurrentDebugLog(driver: AiDriver, stateKey: string, options?: HeadlessDebugOptions): DebugLog;
7470
+
7471
+ /**
7472
+ * What a debug log reports of the host that built it: the `meta` block's agents, state and host.
7473
+ *
7474
+ * @beta
7475
+ */
7476
+ export declare interface HeadlessDebugOptions {
7477
+ /** The configured agents, as the element's `agents` are. */
7478
+ readonly agents?: () => readonly AgentConfig[];
7479
+ /** The host's own debug state, shown as `meta.debug`. */
7480
+ readonly debugState?: () => unknown;
7481
+ /** The host name `meta.host` carries. The element's is `window.location.host`. Default `'headless'`. */
7482
+ readonly host?: string;
7483
+ /**
7484
+ * The active model and its context window, which the element learns from the provider registry's
7485
+ * status; the session has no registry, so the host says. Read each time they are needed.
7486
+ */
7487
+ readonly context?: () => {
7488
+ model?: string;
7489
+ contextLimit?: number;
7490
+ } | undefined;
7491
+ }
7492
+
7493
+ /**
7494
+ * The diagnostic entries for the session so far, from the same `buildDiagnosticEntries` the
7495
+ * browser's element and its persister use.
7496
+ *
7497
+ * @beta
7498
+ */
7499
+ export declare function headlessDiagnosticEntries(driver: AiDriver, stateKey: string, options?: HeadlessDebugOptions): DiagnosticEntry[];
7500
+
7501
+ /**
7502
+ * What a headless session logs, one entry per thing that happened. Every entry has a `seq` (from
7503
+ * 1, rising by one) and an `at` (an ISO time); `wait` is cursored by `seq`.
7504
+ *
7505
+ * @beta
7506
+ */
7507
+ export declare type HeadlessEvent = HeadlessEventBase & (({
7508
+ readonly type: 'decision';
7509
+ } & InteractionDescription & {
7510
+ /** The agents that asked for it, outermost first. */
7511
+ readonly ownerPath?: readonly string[];
7512
+ }) | {
7513
+ readonly type: 'working';
7514
+ readonly interactionId: string;
7515
+ readonly component: string;
7516
+ /** Who holds it; `'user'` when it is the person's but not ready yet. */
7517
+ readonly heldBy: string;
7518
+ } | {
7519
+ readonly type: 'settled';
7520
+ readonly interactionId: string;
7521
+ readonly component: string;
7522
+ /** Who answered it; absent for a timeout, a stop, or one that settled by itself. */
7523
+ readonly answeredBy?: string;
7524
+ /** Set when the widget settled by itself and nobody answered. */
7525
+ readonly resolvedItself?: boolean;
7526
+ /** Set when the session settled it for a widget that settles itself in a browser. */
7527
+ readonly auto?: boolean;
7528
+ /** Set when the host settled it raw, bypassing the widget's actions. */
7529
+ readonly raw?: boolean;
7530
+ } | {
7531
+ readonly type: 'message';
7532
+ /** One line of what the person would see, as the autopilot reads it ("Assistant: ..."). */
7533
+ readonly text: string;
7534
+ /** The line's full length, in characters, when `text` was cut. */
7535
+ readonly chars?: number;
7536
+ } | {
7537
+ readonly type: 'turn';
7538
+ /** The driver's reason, `'done'` for a finished turn; `'error'` when it threw. */
7539
+ readonly reason: string;
7540
+ /** Set when the turn ended in a typed failure rather than completing. */
7541
+ readonly failureReason?: string;
7542
+ /** The assistant's final text for the turn, when it said any. */
7543
+ readonly text?: string;
7544
+ /** The text's full length, in characters, when `text` was cut. */
7545
+ readonly chars?: number;
7546
+ } | {
7547
+ readonly type: 'autopilot';
7548
+ readonly mode: string;
7549
+ readonly status: string;
7550
+ readonly needsUser: boolean;
7551
+ readonly working: boolean;
7552
+ /** Why it is paused, when it said. */
7553
+ readonly reason?: string;
7554
+ } | {
7555
+ readonly type: 'probe';
7556
+ /** What the host's probe reads now. */
7557
+ readonly probe: Readonly<Record<string, unknown>>;
7558
+ /** The keys whose values changed since the last entry. */
7559
+ readonly changed: readonly string[];
7560
+ } | {
7561
+ readonly type: 'error';
7562
+ /** What failed: `'turn'`, `'auto-settle'`, `'probe'`, … */
7563
+ readonly where: string;
7564
+ readonly message: string;
7565
+ });
7566
+
7567
+ /**
7568
+ * The fields every {@link HeadlessEvent} has.
7569
+ *
7570
+ * @beta
7571
+ */
7572
+ export declare interface HeadlessEventBase {
7573
+ readonly seq: number;
7574
+ /** When it was logged, as an ISO time. */
7575
+ readonly at: string;
7576
+ }
7577
+
7578
+ /**
7579
+ * The type of a {@link HeadlessEvent}.
7580
+ *
7581
+ * @beta
7582
+ */
7583
+ export declare type HeadlessEventType = HeadlessEvent['type'];
7584
+
7585
+ /**
7586
+ * The `meta-snapshot` entry for right now, gathered the way the assistant element gathers it
7587
+ * (`buildMetaSnapshot` does the assembly; this reads what it reports): the live agent comes from
7588
+ * the DRIVER, the transcript from its raw history, and the figures from the transcript, so what a
7589
+ * headless host logs is what the browser would. The context window and model, which the element
7590
+ * learns from its provider registry, are the host's to say.
7591
+ *
7592
+ * @beta
7593
+ */
7594
+ export declare function headlessMetaSnapshot(driver: AiDriver, options?: HeadlessDebugOptions): DiagnosticEntry;
7595
+
7596
+ /**
7597
+ * Persistence for a {@link HeadlessSession}, as `headlessPersistence(...)` builds it. Lives apart
7598
+ * from the session so that the session itself, and the Node entry that exports it, never reach the
7599
+ * store, the persister or the framework they use.
7600
+ *
7601
+ * @beta
7602
+ */
7603
+ export declare interface HeadlessPersistence {
7604
+ /** The session key: the file under `sessions/` and the stream under `diag/`. */
7605
+ readonly stateKey: string;
7606
+ attach(host: HeadlessPersistenceHost): HeadlessPersistenceBinding;
7607
+ }
7608
+
7609
+ /**
7610
+ * Persistence for a `HeadlessSession`: it writes exactly what the browser writes — the
7611
+ * `sessions/<key>` snapshot and the `diag/<key>` stream — through the platform's
7612
+ * `SessionPersister` and the host's `SessionPersistenceProvider`, and builds the lifetime debug log
7613
+ * from the same code as the browser's Download.
7614
+ *
7615
+ * Exported from the package's main entry only, NOT from the Node entry (`./chat-driver`): it
7616
+ * reaches the session store, and through it `@genesislcap/foundation-redux`, which are not
7617
+ * Node-clean. The `persister` it makes is the registry's, so a host can restore through
7618
+ * `getPersister(stateKey)`.
7619
+ *
7620
+ * @example
7621
+ * ```ts
7622
+ * const session = new HeadlessSession(driver, {
7623
+ * persistence: headlessPersistence({ provider, stateKey: 'project-1', agents: () => agents }),
7624
+ * });
7625
+ * ```
7626
+ *
7627
+ * @beta
7628
+ */
7629
+ export declare function headlessPersistence(options: HeadlessPersistenceOptions): HeadlessPersistence;
7630
+
7631
+ /**
7632
+ * A session's saving, attached to a driver: it keeps what the persister reads current and asks it
7633
+ * to save when the browser's element would. Built by `HeadlessPersistence.attach`.
7634
+ *
7635
+ * @beta
7636
+ */
7637
+ export declare interface HeadlessPersistenceBinding {
7638
+ /** Note the prompt a person is about to send, for the flow it may start (`flowActivationPrompt`). */
7639
+ notePrompt(text: string): void;
7640
+ /** Save the snapshot and append the diagnostics now, rather than at the next throttled flush. */
7641
+ flush(): Promise<void>;
7642
+ /** The debug log for the whole session, stitched from the stored stream (see `lifetimeDebugLog`). */
7643
+ debugLog(): Promise<DebugLog>;
7644
+ /** Stop watching the driver and cancel pending saves. The saved session is left as it is. */
7645
+ dispose(): void;
7646
+ }
7647
+
7648
+ /**
7649
+ * What a persistence binding is built from: the session's driver, and its debug-log key.
7650
+ *
7651
+ * @beta
7652
+ */
7653
+ export declare interface HeadlessPersistenceHost {
7654
+ readonly driver: AiDriver;
7655
+ readonly sessionKey: string;
7656
+ }
7657
+
7658
+ /**
7659
+ * Options for {@link headlessPersistence}: where to save, and what the debug log says of the host.
7660
+ *
7661
+ * @beta
7662
+ */
7663
+ export declare interface HeadlessPersistenceOptions extends HeadlessDebugOptions {
7664
+ /** The storage backend, as a browser host supplies it. */
7665
+ readonly provider: SessionPersistenceProvider;
7666
+ /** The session key: the file under `sessions/` and the stream under `diag/`. */
7667
+ readonly stateKey: string;
7668
+ }
7669
+
7670
+ /**
7671
+ * What `read` asks for: a view of the widget, or one of the widget's tools (not both).
7672
+ *
7673
+ * @beta
7674
+ */
7675
+ export declare interface HeadlessReadRequest {
7676
+ /** A view's name, from the description's `views`. Absent (with no `tool`): the default read. */
7677
+ readonly view?: string;
7678
+ /** A widget tool's name, from `HeadlessSessionOptions.widgetTools`. */
7679
+ readonly tool?: string;
7680
+ /** The tool's arguments. */
7681
+ readonly args?: Record<string, unknown>;
7682
+ }
7683
+
7684
+ /**
7685
+ * The result of `read`: what was read as text (capped), or why it was refused.
7686
+ *
7687
+ * @beta
7688
+ */
7689
+ export declare type HeadlessReadResult = {
7690
+ readonly ok: true;
7691
+ readonly content: string;
7692
+ readonly error?: never;
7693
+ } | {
7694
+ readonly ok: false;
7695
+ readonly content?: never;
7696
+ readonly error: string;
7697
+ };
7698
+
7699
+ /**
7700
+ * The result of a call that may be refused: the reason, as words, in `error`.
7701
+ *
7702
+ * @beta
7703
+ */
7704
+ export declare type HeadlessResult = {
7705
+ readonly ok: true;
7706
+ readonly error?: never;
7707
+ } | {
7708
+ readonly ok: false;
7709
+ readonly error: string;
7710
+ };
7711
+
7712
+ /**
7713
+ * What `send` may carry besides the words.
7714
+ *
7715
+ * @beta
7716
+ */
7717
+ export declare interface HeadlessSendOptions {
7718
+ readonly attachments?: ChatAttachment[];
7719
+ /** Route the turn to this agent, as `SendMessageOptions.agent` does. */
7720
+ readonly agent?: string;
7721
+ }
7722
+
7723
+ /**
7724
+ * A driver with no screen: a way for a host with no browser (a coding agent behind a small HTTP
7725
+ * server, a test) to run a whole assistant journey as the person (GENC-1660).
7726
+ *
7727
+ * It watches the driver for interactions and turns the conversation into an append-only log of
7728
+ * plain-data events (see {@link HeadlessEvent}): `decision` when the person has something to
7729
+ * answer, `working` when someone else has it, `settled`, the visible `message`s, the end of each
7730
+ * `turn`, the autopilot's state, and the host's own `probe`. The caller reads the log with
7731
+ * {@link HeadlessSession.wait}, a long poll cursored by `seq`, so nothing is lost between calls.
7732
+ * It answers with {@link HeadlessSession.act}, which runs a widget's action as a click would, with
7733
+ * the same numbered options the autopilot is shown.
7734
+ *
7735
+ * It only observes: its interceptor never claims an interaction, so an autopilot on the same
7736
+ * driver works as it always does, and what the session reports as a `decision` is what the autopilot
7737
+ * has handed to the person. Plain classes only: no DOM, no FAST.
7738
+ *
7739
+ * @beta
7740
+ */
7741
+ export declare class HeadlessSession {
7742
+ private readonly driver;
7743
+ private readonly options;
7744
+ private readonly sessionKey;
7745
+ private readonly allowRaw;
7746
+ private readonly clock;
7747
+ private readonly autopilotHost;
7748
+ private readonly events;
7749
+ private seq;
7750
+ private readonly tracked;
7751
+ /** What the session did to an interaction itself, for `settled` to say when the driver reports it. */
7752
+ private readonly origin;
7753
+ private readonly waiters;
7754
+ private readonly teardown;
7755
+ /** How much of the driver's history has been reported as messages. */
7756
+ private seen;
7757
+ /** The `send` in flight, if any. */
7758
+ private turn;
7759
+ /**
7760
+ * The turn that is running, whoever started it, until the driver has been idle for a beat:
7761
+ * `start` is where its messages begin in the history. Its `reason` and `failureReason` are what
7762
+ * ended it, when something said.
7763
+ */
7764
+ private open;
7765
+ /** History length when the last turn closed: where a turn the session did not start begins. */
7766
+ private base;
7767
+ private quiesceTimer;
7768
+ private poller;
7769
+ private readonly persistence;
7770
+ private lastProbe;
7771
+ private lastAutopilot;
7772
+ private disposed;
7773
+ constructor(driver: AiDriver, options?: HeadlessSessionOptions);
7774
+ /**
7775
+ * Send the person's message, and start the turn. Returns as soon as the turn has started, not
7776
+ * when it ends: a turn includes every interaction parked on the person, so it can run as long as
7777
+ * the journey. Its end is the `turn` event.
7778
+ *
7779
+ * Refused, never thrown, when the message is empty, or a turn is already running.
7780
+ */
7781
+ send(text: string, options?: HeadlessSendOptions): HeadlessResult;
7782
+ /**
7783
+ * Run one of a pending interaction's actions as the person, as a click would (the answer is
7784
+ * credited `answeredBy: 'user'`). `action` is a number from the description's actions, or an
7785
+ * action's name; `args` carry the text, the options (numbers or labels) or the form's fields it
7786
+ * takes. Refused, with the reason and what is enabled, when a claimant holds the interaction,
7787
+ * the action is unknown or disabled, or its arguments do not fit: nothing runs then.
7788
+ *
7789
+ * The result is the driver's `InvokeResult`, plus `description` of the interaction when it is
7790
+ * still open.
7791
+ */
7792
+ act(interactionId: string, action: string | number, args?: HeadlessActArgs): Promise<HeadlessActResult>;
7793
+ /**
7794
+ * Settle a pending interaction raw, with `result` as the widget would have resolved it,
7795
+ * bypassing its actions and everything they check: an escape hatch for a widget with no
7796
+ * controller, or one that cannot be acted on. Logs `settled` with `raw: true` and records
7797
+ * `headless.raw-resolved`. Refused when `allowRaw` is `false` or the interaction is not pending.
7798
+ */
7799
+ resolve(interactionId: string, result: unknown): HeadlessResult;
7800
+ /**
7801
+ * Read from a pending interaction without changing it: one of its views, or (with `tool`) one of
7802
+ * the widget tools given to the session. The text is capped. A view the surface does not list is
7803
+ * refused, naming those it does, as the autopilot's `widget_read` does.
7804
+ */
7805
+ read(interactionId: string, request?: HeadlessReadRequest): Promise<HeadlessReadResult>;
7806
+ /**
7807
+ * Wait for the log to say something, then return what it said. Resolves as soon as an event in
7808
+ * `until` is in the log after `since` (immediately, when one already is), or at `maxWaitMs` with
7809
+ * status `'working'`. Either way it returns every event after `since`, and `nextSeq`, the cursor
7810
+ * for the next call: poll with it and nothing is lost.
7811
+ */
7812
+ wait(request: HeadlessWaitRequest): Promise<HeadlessWaitResult>;
7813
+ /** Every event logged after `since` (default: all the log keeps), without waiting. */
7814
+ eventsSince(since?: number): readonly HeadlessEvent[];
7815
+ /**
7816
+ * What is going on now: whether a turn runs, the interaction the person should answer first (and
7817
+ * the others open behind it), the autopilot, what it has cost, and the host's probe.
7818
+ */
7819
+ state(): HeadlessState;
7820
+ /**
7821
+ * Save the session now: the snapshot, and the diagnostics appended since the last flush, rather
7822
+ * than at the next throttled save. A no-op without `persistence`.
7823
+ */
7824
+ flush(): Promise<void>;
7825
+ /**
7826
+ * The debug log, the document the browser's Download gives. With `persistence`, the log of the
7827
+ * whole session stitched from the stored stream with a fresh `meta-snapshot` (`lifetimeDebugLog`,
7828
+ * the same code); without, the current page's, from `buildDiagnosticEntries`. Never throws.
7829
+ */
7830
+ debugLog(): Promise<DebugLog>;
7831
+ /** Stop the running turn, when the driver can. */
7832
+ stop(): HeadlessResult;
7833
+ /**
7834
+ * Pause, resume or stop the autopilot, when there is one. Pausing hands what it holds to the
7835
+ * person, which then appears as a `decision`.
7836
+ */
7837
+ autopilot(mode: 'pause' | 'resume' | 'stop'): HeadlessResult;
7838
+ /** Detach: remove the interceptor and every subscription, and release anyone waiting. */
7839
+ dispose(): void;
7840
+ private listen;
7841
+ private history;
7842
+ /** An interaction opened: watch it. Who holds it is not decided yet, so it is reported later. */
7843
+ private onOpened;
7844
+ /** The driver says an interaction settled, by whatever route. */
7845
+ private onSettled;
7846
+ /** The interaction's context was disposed: if nothing said it settled, say it did. */
7847
+ private onEnded;
7848
+ private settle;
7849
+ private release;
7850
+ /** New messages in the driver's history: report what the person would see of them. */
7851
+ private onHistory;
7852
+ private reportMessages;
7853
+ private onAutopilot;
7854
+ private autopilotSignature;
7855
+ private describe;
7856
+ /**
7857
+ * Report where an interaction stands, when that has changed. A `decision` when the person holds
7858
+ * it and can act; `working` when a claimant holds it or it is not ready yet. A `decision` is
7859
+ * logged again only when its description changed materially: who holds it, whether it is ready
7860
+ * or has a controller, or which actions are enabled. The text and facts alone do not count.
7861
+ */
7862
+ private evaluate;
7863
+ /**
7864
+ * Settle a widget that settles itself in a browser, as it would on mounting. Once, and only when
7865
+ * the person holds it. Returns whether it settled it.
7866
+ */
7867
+ private autoSettle;
7868
+ private readTool;
7869
+ /**
7870
+ * Notice a turn begin or end, whoever started it. The driver being busy (or a `send` in flight)
7871
+ * is a turn; once it has been idle for a beat the turn is over and is reported, once. The beat
7872
+ * covers the gaps inside one turn, such as a hand-off continuing it, which are a microtask long.
7873
+ * A turn that begins the instant another ends, with no idle between, is reported as one.
7874
+ */
7875
+ private observe;
7876
+ /** Report the open turn as ended, unless the driver is busy again. */
7877
+ private closeTurn;
7878
+ /** Without a shared bus nothing says a turn ended, so while one is open the driver is asked. */
7879
+ private startPolling;
7880
+ private stopPolling;
7881
+ private logTurn;
7882
+ private log;
7883
+ private append;
7884
+ private readProbe;
7885
+ /** Read the probe again; a change in any top-level value is a `probe` event. */
7886
+ private checkProbe;
7887
+ private waited;
7888
+ }
7889
+
7890
+ /**
7891
+ * Options for a {@link HeadlessSession}.
7892
+ *
7893
+ * @beta
7894
+ */
7895
+ export declare interface HeadlessSessionOptions {
7896
+ /** The debug-log key its meta events go under: the driver's own. Defaults to `''`. */
7897
+ readonly sessionKey?: string;
7898
+ /** What the host calls itself, recorded with `headless.attached`, e.g. `'cli'`. */
7899
+ readonly label?: string;
7900
+ /**
7901
+ * Widgets that settle themselves in a browser when their element mounts, with no controller
7902
+ * to act on, by widget type: each maps the widget's `data` to the result to settle it with.
7903
+ * When one opens the session settles it with that result (once the open has completed), logs
7904
+ * `settled` with `auto: true`, and never reports it as a `decision`.
7905
+ */
7906
+ readonly autoSettle?: Readonly<Record<string, (data: unknown) => unknown>>;
7907
+ /** The widget tools `read({ tool })` may run, as for the autopilot. */
7908
+ readonly widgetTools?: readonly WidgetTools[];
7909
+ /**
7910
+ * Host state shown in `state()` as `probe`, e.g. its app phase. Read again at every event; a
7911
+ * change in any top-level value is logged as a `probe` event.
7912
+ */
7913
+ readonly probe?: () => Record<string, unknown>;
7914
+ /** Whether `resolve` (settling an interaction raw) is allowed. Default `true`. */
7915
+ readonly allowRaw?: boolean;
7916
+ /**
7917
+ * The autopilot, when the driver handed to the session is not itself one (a decorator wrapped
7918
+ * over it hides it). Default: the driver, when it has the shape of an `AutopilotHost`.
7919
+ */
7920
+ readonly autopilot?: AutopilotLike;
7921
+ /** The time source for `at`, in milliseconds. Default `Date.now`. */
7922
+ readonly clock?: () => number;
7923
+ /**
7924
+ * Where the session is saved, as `headlessPersistence(...)` builds it: the same
7925
+ * `sessions/<key>` snapshot and `diag/<key>` stream the browser writes. Absent: nothing is
7926
+ * saved, and `debugLog()` is the current page's.
7927
+ */
7928
+ readonly persistence?: HeadlessPersistence;
7929
+ /**
7930
+ * What `debugLog()` reports of the host when nothing is persisted (with `persistence` its own
7931
+ * options are used instead).
7932
+ */
7933
+ readonly debug?: HeadlessDebugOptions;
7934
+ /**
7935
+ * The bus the driver was built with (`ChatDriver`'s `activityBus` option), to hear turns end the
7936
+ * moment they do, whoever started them. Without it a turn the session did not start is noticed
7937
+ * by watching the driver's history and polling `isBusy()`, which is the slower route.
7938
+ */
7939
+ readonly activityBus?: Pick<AgenticActivityBus, 'subscribe'>;
7940
+ }
7941
+
7942
+ /**
7943
+ * What a headless session is doing now.
7944
+ *
7945
+ * @beta
7946
+ */
7947
+ export declare interface HeadlessState {
7948
+ /** Whether the driver is running a turn. */
7949
+ readonly busy: boolean;
7950
+ /** The oldest interaction the person holds and can act on, or `null`. */
7951
+ readonly pending: InteractionDescription | null;
7952
+ /** The other open interactions: a claimant's, or not ready yet, or behind the first. */
7953
+ readonly others: readonly PendingSummary[];
7954
+ /** The autopilot's state, when there is one. */
7955
+ readonly autopilot?: {
7956
+ readonly mode: string;
7957
+ readonly status: string;
7958
+ readonly needsUser: boolean;
7959
+ readonly working: boolean;
7960
+ };
7961
+ /** What the conversation has cost so far, in `sumUsage`'s four buckets. */
7962
+ readonly cost: AggregateUsage;
7963
+ /** The host's probe, read now. */
7964
+ readonly probe: Readonly<Record<string, unknown>>;
7965
+ /** The `seq` of the last event logged: `wait`'s cursor. */
7966
+ readonly lastSeq: number;
7967
+ }
7968
+
7969
+ /**
7970
+ * What `wait` takes.
7971
+ *
7972
+ * @beta
7973
+ */
7974
+ export declare interface HeadlessWaitRequest {
7975
+ /**
7976
+ * The cursor: the `seq` of the last event already seen. Events after it are returned. Absent:
7977
+ * from the start of the log.
7978
+ */
7979
+ readonly since?: number;
7980
+ /**
7981
+ * The event types that end the wait. Default: `decision`, `turn`, `error`, and an `autopilot`
7982
+ * entry that `needsUser`. One naming `autopilot` ends it on any autopilot entry.
7983
+ */
7984
+ readonly until?: readonly HeadlessEventType[];
7985
+ /** The longest to wait, in milliseconds. */
7986
+ readonly maxWaitMs: number;
7987
+ }
7988
+
7989
+ /**
7990
+ * What `wait` returns.
7991
+ *
7992
+ * @beta
7993
+ */
7994
+ export declare interface HeadlessWaitResult {
7995
+ /** Every event after `since`, up to now. */
7996
+ readonly events: readonly HeadlessEvent[];
7997
+ /**
7998
+ * `'ready'`: an event the caller was waiting for is among them. `'working'`: none came in
7999
+ * time. `'closed'`: the session was disposed.
8000
+ */
8001
+ readonly status: 'ready' | 'working' | 'closed';
8002
+ /** The cursor to pass as `since` next time: the `seq` of the last event logged. */
8003
+ readonly nextSeq: number;
8004
+ }
8005
+
7279
8006
  /**
7280
8007
  * A single in-flight per-call chat-input override pushed by a `requestSubAgent`
7281
8008
  * or `requestInteraction` call. Tracked as an array (not a counter) so the
@@ -7524,6 +8251,42 @@ export declare type InteractionControllerFactory<TController = unknown> = (data:
7524
8251
  */
7525
8252
  export declare type InteractionCostEventDetail = ChatInteractionEventsMap['interaction-cost'];
7526
8253
 
8254
+ /**
8255
+ * What a pending interaction needs from the person, as a compact, JSON-serialisable view a model
8256
+ * can read and answer.
8257
+ *
8258
+ * @beta
8259
+ */
8260
+ export declare interface InteractionDescription {
8261
+ readonly interactionId: string;
8262
+ /** The widget type. */
8263
+ readonly component: string;
8264
+ /** Who holds it: `'user'`, or a claimant such as `'autopilot'`. */
8265
+ readonly heldBy: string;
8266
+ /**
8267
+ * Whether the widget has a controller and so a surface to act on. `false`: nothing here can be
8268
+ * run with `act`; `text` is all the widget says, and only a raw `resolve` can settle it.
8269
+ */
8270
+ readonly controller: boolean;
8271
+ /**
8272
+ * Whether the person can act now. A widget with no controller is ready; one with a surface is
8273
+ * ready when it has an enabled finishing action and is not busy working.
8274
+ */
8275
+ readonly ready: boolean;
8276
+ /**
8277
+ * What the autopilot would be sent for it: the same `renderDecision` text (the widget as text,
8278
+ * its views and facts, the numbered actions), or the widget as text alone where there is no
8279
+ * surface.
8280
+ */
8281
+ readonly text: string;
8282
+ /** Every action, in the order the list shows them. Empty with no surface. */
8283
+ readonly actions: readonly DescribedAction[];
8284
+ /** The views `read` takes, each with what it holds. */
8285
+ readonly views?: Readonly<Record<string, string>>;
8286
+ /** The surface's facts, as they stand now. */
8287
+ readonly facts?: Readonly<Record<string, unknown>>;
8288
+ }
8289
+
7527
8290
  export { InteractionEdit }
7528
8291
 
7529
8292
  /**
@@ -7898,6 +8661,30 @@ export declare function isAiAssistantDocked(): boolean;
7898
8661
  */
7899
8662
  export declare const isDelegated: (message: ChatMessage) => message is DelegatedMessage;
7900
8663
 
8664
+ /**
8665
+ * The debug log for the WHOLE session (GENC-1351 §5.8 / §5.10), not just this page's activity:
8666
+ * the persisted diagnostics stream with its stored `meta-snapshot`s replaced by a fresh one
8667
+ * (`withFreshMetaSnapshot`), so its context and cost figures are current. When the provider
8668
+ * stores no diagnostics, there is no key, the stream is empty or loading it fails, it is
8669
+ * `fallback()` — the current-page log. Never throws.
8670
+ *
8671
+ * The one derivation of the lifetime log: the assistant element's `getLifetimeDebugLog` and the
8672
+ * headless session both call it, because a second one drifts, and for this log that means silently
8673
+ * understating spend.
8674
+ *
8675
+ * @beta
8676
+ */
8677
+ export declare function lifetimeDebugLog(input: {
8678
+ provider: SessionPersistenceProvider | undefined;
8679
+ stateKey: string | undefined;
8680
+ /** Land the current page's unflushed diagnostics delta, so the log includes it. */
8681
+ flush: () => Promise<void> | void;
8682
+ /** The `meta-snapshot` entry for right now. */
8683
+ metaSnapshot: () => DiagnosticEntry;
8684
+ /** The current-page log, for when there is no stored stream to stitch. */
8685
+ fallback: () => DebugLog;
8686
+ }): Promise<DebugLog>;
8687
+
7901
8688
  /**
7902
8689
  * The interchangeable "assistant is working" loading-indicator styles. At most
7903
8690
  * one of these may be enabled at a time — enabling one disables the other.
@@ -8289,6 +9076,18 @@ export declare class OrchestratingDriver extends BaseDriverDecorator<ChatDriver>
8289
9076
  private appendInlineMessage;
8290
9077
  }
8291
9078
 
9079
+ /**
9080
+ * Something else pending, besides the one `state().pending` describes.
9081
+ *
9082
+ * @beta
9083
+ */
9084
+ export declare interface PendingSummary {
9085
+ readonly interactionId: string;
9086
+ readonly component: string;
9087
+ readonly heldBy: string;
9088
+ readonly ready: boolean;
9089
+ }
9090
+
8292
9091
  /**
8293
9092
  * Schema version of the persisted session shape. Bump on an incompatible
8294
9093
  * change; a snapshot whose `version` doesn't match is discarded on load rather
@@ -8300,7 +9099,8 @@ export declare const PERSISTED_SESSION_VERSION = 1;
8300
9099
 
8301
9100
  /**
8302
9101
  * The autopilot's mode as saved with the session (GENC-1660 §4.8): which flow it was set for, and
8303
- * whether it was running. Cleared when that flow ends, so a saved mode never outlives its flow.
9102
+ * whether it was running. Cleared when that flow ends, so a saved mode never outlives its flow. A
9103
+ * hand-off does not end it: the mode goes with the task to the target, and back (GENC-1751).
8304
9104
  *
8305
9105
  * @beta
8306
9106
  */