@genesislcap/ai-assistant 15.82.0 → 15.84.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/ai-assistant.api.json +2811 -233
  2. package/dist/ai-assistant.d.ts +835 -93
  3. package/dist/chat-driver.cjs +452 -99
  4. package/dist/chat-driver.cjs.map +4 -4
  5. package/dist/chat-driver.mjs +452 -99
  6. package/dist/chat-driver.mjs.map +4 -4
  7. package/dist/custom-elements.json +1903 -907
  8. package/dist/dts/autopilot/autopilot-driver.d.ts +117 -11
  9. package/dist/dts/autopilot/autopilot-driver.d.ts.map +1 -1
  10. package/dist/dts/autopilot/autopilot-session.d.ts +55 -7
  11. package/dist/dts/autopilot/autopilot-session.d.ts.map +1 -1
  12. package/dist/dts/autopilot/autopilot-tools.d.ts +3 -2
  13. package/dist/dts/autopilot/autopilot-tools.d.ts.map +1 -1
  14. package/dist/dts/autopilot/decision-message.d.ts +35 -3
  15. package/dist/dts/autopilot/decision-message.d.ts.map +1 -1
  16. package/dist/dts/autopilot/hand-back/hand-back.controller.d.ts +2 -2
  17. package/dist/dts/autopilot/hand-back/hand-back.controller.d.ts.map +1 -1
  18. package/dist/dts/autopilot/hand-back/hand-back.d.ts +2 -2
  19. package/dist/dts/autopilot/hand-back/hand-back.d.ts.map +1 -1
  20. package/dist/dts/autopilot/index.d.ts +1 -0
  21. package/dist/dts/autopilot/index.d.ts.map +1 -1
  22. package/dist/dts/autopilot/widget-tools.d.ts +95 -0
  23. package/dist/dts/autopilot/widget-tools.d.ts.map +1 -0
  24. package/dist/dts/channel/ai-activity-channel.d.ts +10 -0
  25. package/dist/dts/channel/ai-activity-channel.d.ts.map +1 -1
  26. package/dist/dts/components/ai-driver/ai-driver.d.ts +25 -6
  27. package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
  28. package/dist/dts/components/ai-driver/base-driver-decorator.d.ts +2 -0
  29. package/dist/dts/components/ai-driver/base-driver-decorator.d.ts.map +1 -1
  30. package/dist/dts/components/chat-driver/chat-driver.d.ts +14 -2
  31. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  32. package/dist/dts/components/chat-driver/interaction-controller.d.ts +61 -17
  33. package/dist/dts/components/chat-driver/interaction-controller.d.ts.map +1 -1
  34. package/dist/dts/config/config.d.ts +31 -6
  35. package/dist/dts/config/config.d.ts.map +1 -1
  36. package/dist/dts/config/define-stateful-agent.d.ts +5 -1
  37. package/dist/dts/config/define-stateful-agent.d.ts.map +1 -1
  38. package/dist/dts/genesis/write-outcome.d.ts.map +1 -1
  39. package/dist/dts/index.d.ts +4 -2
  40. package/dist/dts/index.d.ts.map +1 -1
  41. package/dist/dts/main/main.d.ts +11 -0
  42. package/dist/dts/main/main.d.ts.map +1 -1
  43. package/dist/dts/main/main.template.d.ts.map +1 -1
  44. package/dist/dts/notifications/agent-notifications.d.ts +6 -2
  45. package/dist/dts/notifications/agent-notifications.d.ts.map +1 -1
  46. package/dist/dts/notifications/agent-notifier.d.ts +26 -4
  47. package/dist/dts/notifications/agent-notifier.d.ts.map +1 -1
  48. package/dist/dts/state/decision-surface.d.ts +22 -4
  49. package/dist/dts/state/decision-surface.d.ts.map +1 -1
  50. package/dist/dts/state/interaction-context.d.ts +23 -4
  51. package/dist/dts/state/interaction-context.d.ts.map +1 -1
  52. package/dist/dts/state/interaction-registry.d.ts +55 -6
  53. package/dist/dts/state/interaction-registry.d.ts.map +1 -1
  54. package/dist/dts/state/live-interactions.d.ts +28 -0
  55. package/dist/dts/state/live-interactions.d.ts.map +1 -0
  56. package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
  57. package/dist/dts/state/persistence/session-snapshot.d.ts +16 -5
  58. package/dist/dts/state/persistence/session-snapshot.d.ts.map +1 -1
  59. package/dist/dts/state/test-interaction-context.d.ts +93 -0
  60. package/dist/dts/state/test-interaction-context.d.ts.map +1 -0
  61. package/dist/dts/types/ai-chat-widget.d.ts +7 -6
  62. package/dist/dts/types/ai-chat-widget.d.ts.map +1 -1
  63. package/dist/dts/types/interaction-context.d.ts +128 -17
  64. package/dist/dts/types/interaction-context.d.ts.map +1 -1
  65. package/dist/dts/types/interaction-interceptor.d.ts +48 -6
  66. package/dist/dts/types/interaction-interceptor.d.ts.map +1 -1
  67. package/dist/dts/types/interaction-surface.d.ts +145 -23
  68. package/dist/dts/types/interaction-surface.d.ts.map +1 -1
  69. package/dist/esm/autopilot/autopilot-driver.js +313 -60
  70. package/dist/esm/autopilot/autopilot-session.js +219 -40
  71. package/dist/esm/autopilot/autopilot-tools.js +11 -7
  72. package/dist/esm/autopilot/decision-message.js +105 -26
  73. package/dist/esm/autopilot/hand-back/hand-back.controller.js +2 -1
  74. package/dist/esm/autopilot/index.js +1 -0
  75. package/dist/esm/autopilot/widget-tools.js +39 -0
  76. package/dist/esm/components/ai-driver/base-driver-decorator.js +17 -0
  77. package/dist/esm/components/chat-driver/chat-driver.js +18 -2
  78. package/dist/esm/components/chat-driver/interaction-controller.js +232 -71
  79. package/dist/esm/components/settings-modal/settings-modal.template.js +2 -2
  80. package/dist/esm/config/define-stateful-agent.js +22 -1
  81. package/dist/esm/genesis/write-outcome.js +8 -4
  82. package/dist/esm/index.js +2 -0
  83. package/dist/esm/main/main.js +39 -3
  84. package/dist/esm/main/main.template.js +4 -1
  85. package/dist/esm/notifications/agent-notifications.js +11 -1
  86. package/dist/esm/notifications/agent-notifier.js +41 -7
  87. package/dist/esm/state/debug-event-log.js +5 -5
  88. package/dist/esm/state/decision-surface.js +137 -54
  89. package/dist/esm/state/interaction-context.js +41 -8
  90. package/dist/esm/state/interaction-registry.js +11 -0
  91. package/dist/esm/state/live-interactions.js +36 -0
  92. package/dist/esm/state/persistence/session-persister.js +44 -17
  93. package/dist/esm/state/persistence/session-snapshot.js +2 -2
  94. package/dist/esm/state/test-interaction-context.js +99 -0
  95. package/docs/notifications.md +55 -5
  96. package/docs/styling.md +33 -0
  97. package/package.json +19 -19
  98. package/sandbox/README.md +3 -2
  99. package/sandbox/autopilot.ts +26 -6
  100. package/sandbox/sandbox.ts +2 -0
  101. /package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +0 -0
@@ -75,10 +75,13 @@ export declare interface AgentAttentionDetail {
75
75
  * - `'autopilot-handed-back'` — the autopilot handed something to the person.
76
76
  * - `'autopilot-stopped'` — the autopilot stopped working: the flow ended, the turn ended with
77
77
  * nothing left for it to answer, or it hit a wall such as the budget.
78
+ * - `'turn-ended'` — a turn ended and the assistant is waiting for the person to type (GENC-1660):
79
+ * nothing else waits on them (no open interaction), the person did not stop the turn, and no
80
+ * autopilot is running for the flow. Only the `'needs-input'` level shows it.
78
81
  *
79
82
  * @beta
80
83
  */
81
- export declare type AgentAttentionKind = 'widget-needs-input' | 'autopilot-handed-back' | 'autopilot-stopped';
84
+ export declare type AgentAttentionKind = 'widget-needs-input' | 'autopilot-handed-back' | 'autopilot-stopped' | 'turn-ended';
82
85
 
83
86
  /**
84
87
  * Configuration for an agent passed to `FoundationAiAssistant`.
@@ -360,6 +363,16 @@ export declare interface AgenticActivityEvents {
360
363
  * publishes it.
361
364
  */
362
365
  'agent-attention': AgentAttentionDetail;
366
+ /**
367
+ * An interaction no longer waits on the person (GENC-1660): it settled, or a claimant (such as
368
+ * the autopilot, on Resume) took it. A notification shown for it is stale, so the assistant for
369
+ * that session closes it if it is still showing. Published for every interaction, whether a
370
+ * notification was shown or not. Tab-local, like `agent-attention`.
371
+ */
372
+ 'agent-attention-ended': {
373
+ sessionKey: string;
374
+ interactionId: string;
375
+ };
363
376
  /**
364
377
  * A session's agent notification settings may have changed (GENC-1676): the person's level, what
365
378
  * the app offers, or which assistant on the page holds the session. A notification level picker
@@ -403,7 +416,8 @@ export declare interface AgentLifecycleContext {
403
416
  * - `'autopilot'` — only when the autopilot hands back to the person or stops working. Offered
404
417
  * only when the app sets `chatConfig.ui.notifications.autopilot`.
405
418
  * - `'needs-input'` — every `'autopilot'` case, plus any widget that asks for the person's
406
- * attention (`InteractionContext.requestAttention`).
419
+ * attention (`InteractionContext.requestAttention`), and every turn that ends with the assistant
420
+ * waiting for the person to type (GENC-1660).
407
421
  *
408
422
  * @beta
409
423
  */
@@ -755,11 +769,11 @@ export declare type AiAssistantState = 'idle' | 'loading' | 'cancelling' | 'erro
755
769
  * a `shouldAutoFocus`, and a pending widget cannot be read for a `result`.
756
770
  *
757
771
  * The host sets the widget's `interaction` on mount and REPLACES it (pending →
758
- * resolved) on completion.
772
+ * resolved) on completion. `TController` types the pending context's `controller` (GENC-1660).
759
773
  *
760
774
  * @beta
761
775
  */
762
- export declare type AiChatInteraction<TData = unknown, TResult = unknown> = {
776
+ export declare type AiChatInteraction<TData = unknown, TResult = unknown, TController = unknown> = {
763
777
  status: 'pending';
764
778
  /** Immutable inputs for the interaction. */
765
779
  data: TData;
@@ -770,9 +784,10 @@ export declare type AiChatInteraction<TData = unknown, TResult = unknown> = {
770
784
  shouldAutoFocus: boolean;
771
785
  /**
772
786
  * Live, remount-surviving scratch for this interaction. Present ONLY while
773
- * pending — the host disposes it on resolve. See {@link InteractionContext}.
787
+ * pending — the host disposes it on resolve. See {@link InteractionContext}. Its
788
+ * `controller` is typed `TController`, as the widget was registered.
774
789
  */
775
- interactionContext: InteractionContext;
790
+ interactionContext: InteractionContext<Record<string, unknown>, unknown, TController>;
776
791
  } | {
777
792
  status: 'resolved';
778
793
  /** Same inputs — the resolved view still reads them. */
@@ -844,11 +859,11 @@ export declare class AiChatMarkdown extends GenesisElement {
844
859
  *
845
860
  * @beta
846
861
  */
847
- export declare interface AiChatWidget<TData = unknown, TResult = unknown> {
862
+ export declare interface AiChatWidget<TData = unknown, TResult = unknown, TController = unknown> {
848
863
  /** Stable per-interaction UUID; constant across remounts, present in both states. */
849
864
  interactionId: string;
850
865
  /** The current interaction state (pending or resolved). */
851
- interaction: AiChatInteraction<TData, TResult>;
866
+ interaction: AiChatInteraction<TData, TResult, TController>;
852
867
  }
853
868
 
854
869
  /**
@@ -1062,19 +1077,36 @@ export declare interface AiDriver extends EventTarget {
1062
1077
  */
1063
1078
  getFlowOwner?(): string | null;
1064
1079
  /**
1065
- * The checkpoint of the long action in flight, or the one a reload cut and nothing has taken over
1066
- * yet (GENC-1660 §4.12), for the host to save with the session.
1080
+ * Every checkpoint to save with the session (GENC-1660 §4.12): those a reload cut that nothing
1081
+ * has taken over yet, oldest first, then the long action in flight's, if it has saved one.
1067
1082
  *
1068
1083
  * Optional, so a third-party driver need not implement it; every shipped driver does.
1069
1084
  *
1070
1085
  * @beta
1071
1086
  */
1087
+ getInteractionCheckpoints?(): readonly PersistedInteractionCheckpoint[];
1088
+ /**
1089
+ * Bring back the checkpoints saved with the session. Their interactions were cut by the reload,
1090
+ * so each waits for a request of its own widget type that the registration's `sameWork` agrees is
1091
+ * the same work: it is offered to every such request until one agrees, kept through refusals and
1092
+ * through checkpoints other interactions save meanwhile, and dropped when the flow ends. Replaces
1093
+ * whatever the driver held.
1094
+ *
1095
+ * @beta
1096
+ */
1097
+ restoreInteractionCheckpoints?(saved: readonly PersistedInteractionCheckpoint[]): void;
1098
+ /**
1099
+ * One checkpoint to save: the long action in flight's, else the newest a reload cut.
1100
+ *
1101
+ * @deprecated Use {@link AiDriver.getInteractionCheckpoints}, which also returns the cut
1102
+ * checkpoints still waiting while another long action runs; this one loses them.
1103
+ * @beta
1104
+ */
1072
1105
  getInteractionCheckpoint?(): PersistedInteractionCheckpoint | undefined;
1073
1106
  /**
1074
- * Bring back a checkpoint saved with the session. Its interaction was cut by the reload, so it
1075
- * waits for the first request of the same widget type, which takes it over if the registration's
1076
- * `sameWork` agrees; it is dropped when the flow ends.
1107
+ * Bring back one checkpoint, or none (which clears every checkpoint held).
1077
1108
  *
1109
+ * @deprecated Use {@link AiDriver.restoreInteractionCheckpoints}.
1078
1110
  * @beta
1079
1111
  */
1080
1112
  restoreInteractionCheckpoint?(saved: PersistedInteractionCheckpoint | undefined): void;
@@ -1265,11 +1297,13 @@ export declare interface AiDriverEventMap {
1265
1297
  /**
1266
1298
  * An interaction settled, by whatever route — a widget, a controller's `ctx.resolve`, a claimant,
1267
1299
  * a timeout (GENC-1660). Detail: its id, and `answeredBy` when someone answered it (absent for a
1268
- * timeout or a stop).
1300
+ * timeout or a stop); `resolvedItself` in its place when a widget registered `resolvesItself`
1301
+ * settled on its own, which nobody answered but after which the turn carries on.
1269
1302
  */
1270
1303
  'interaction-settled': CustomEvent<{
1271
1304
  interactionId: string;
1272
1305
  answeredBy?: string;
1306
+ resolvedItself?: boolean;
1273
1307
  }>;
1274
1308
  /** Spend was recorded against an already-resolved interaction. */
1275
1309
  'external-cost-recorded': CustomEvent<{
@@ -1624,6 +1658,19 @@ export declare interface AutopilotConfig<S = unknown> {
1624
1658
  definitions: ChatToolDefinition[];
1625
1659
  handlers: ChatToolHandlers;
1626
1660
  };
1661
+ /**
1662
+ * Tools that read from one widget type while it is open, built with `widgetTools`: reads with
1663
+ * parameters, which a surface's views cannot take (one table's rows, a page of them). Declared
1664
+ * here, never discovered from registrations, so the tool list is fixed when the autopilot's
1665
+ * session starts — the fixed three, `tools` and these, sorted by name — and every decision sends
1666
+ * the same one, which keeps the cache. Each call is routed to the interaction of its widget type
1667
+ * being decided, and refused with a reason when none is; while one is open, the platform puts a
1668
+ * line naming its tools in front of the tail. Reads only.
1669
+ *
1670
+ * Every tool name must be unique across these, `tools` and the fixed three: `defineAutopilot`
1671
+ * throws otherwise.
1672
+ */
1673
+ widgetTools?: WidgetTools[];
1627
1674
  /**
1628
1675
  * How the working agent is told a decision was made for the user, e.g. "Decided on the user's
1629
1676
  * behalf, from their brief". Must not name the autopilot.
@@ -1641,10 +1688,14 @@ export declare interface AutopilotConfig<S = unknown> {
1641
1688
  /** Model calls per decision before it is handed back; `> 0`, or the default is used. Default 6. */
1642
1689
  maxIterationsPerDecision?: number;
1643
1690
  /**
1644
- * Written answers (`reply`) allowed per step before `reply` is withdrawn, so refining a proposal
1645
- * cannot loop with the working agent re-proposing it. `>= 0` (0 never offers one), or the
1646
- * default is used. Default 2. Enforced by the platform, not asked of the model: past the limit it
1647
- * can only accept or hand back.
1691
+ * Refinements allowed per step before every refining action is withdrawn, so refining a proposal
1692
+ * cannot loop with the working agent re-proposing it. A refinement is a written answer (`reply`)
1693
+ * or a full-form action declared `refines` (a regenerate with instructions), counted together.
1694
+ * `>= 0` (0 never offers one), or the default is used. Default 2. Enforced by the platform, not
1695
+ * asked of the model: past the limit it can only accept or hand back. Counted the moment one is
1696
+ * taken, so a refining action that does not settle cannot be repeated past it within a decision.
1697
+ * The decision tells the model how many are left (`Refinements left at this step: N`) wherever the
1698
+ * widget has a refining action, so a widget's own summary need not count them.
1648
1699
  */
1649
1700
  maxRefinements?: number;
1650
1701
  /**
@@ -1663,8 +1714,8 @@ export declare interface AutopilotConfig<S = unknown> {
1663
1714
  maxDecisionCostUsd?: number;
1664
1715
  /**
1665
1716
  * How long the autopilot's work on a claimed interaction may go quiet before it is handed back,
1666
- * in ms; `> 0`, or the default is used. Quiet means either no ready surface and no heartbeat
1667
- * (`ctx.notify()`), or a decision of its own still running with no model call landing and no
1717
+ * in ms; `> 0`, or the default is used. Quiet means either no ready surface (no decision due,
1718
+ * which includes a controller that says it is working) and no heartbeat (`ctx.notify()`), or a decision of its own still running with no model call landing and no
1668
1719
  * heartbeat — a stalled model call, which has no timeout of its own. A decision handed back this
1669
1720
  * way is stopped. Must outlast the slowest honest wait, such as a compile. Default 10 minutes.
1670
1721
  */
@@ -1691,6 +1742,13 @@ export declare interface AutopilotCopy {
1691
1742
  paused: string;
1692
1743
  /** While the autopilot waits on one answer it handed back. */
1693
1744
  selfPaused: string;
1745
+ /**
1746
+ * The slim bar's status while running but waiting on the person for a question the autopilot
1747
+ * never took — one its `widgetPolicy` keeps for them, one that is `userOnly`, or one with no
1748
+ * controller to act through — e.g. "Waiting for your answer". Not a hand-back, which is
1749
+ * `selfPaused`: nothing pauses, and the autopilot carries on by itself once they answer.
1750
+ */
1751
+ waitingForUser: string;
1694
1752
  /** In front of a hand-back reason, in the widget's banner, e.g. "I need your input on this one:". */
1695
1753
  handBackLead: string;
1696
1754
  /** The toggle pill's label and its accessible name, e.g. "Autopilot". */
@@ -1769,7 +1827,18 @@ export declare class AutopilotDriver extends BaseDriverDecorator implements Auto
1769
1827
  private mode;
1770
1828
  private pauseState?;
1771
1829
  private held?;
1772
- /** Written answers given on the current step, for the refinement limit. */
1830
+ /**
1831
+ * The interaction open right now, whoever holds it: claimed or not, it was offered here first.
1832
+ * `held` covers only what the autopilot claimed, so this is how the status knows that the working
1833
+ * agent is parked on a question left with the person (see `waitingOnUser`).
1834
+ */
1835
+ private open?;
1836
+ /**
1837
+ * The open interaction, when the autopilot declined it only for being paused as it opened: a live
1838
+ * Resume may still take it (see `takeOpenOnResume`). Cleared when it is taken or settles.
1839
+ */
1840
+ private declinedWhilePaused?;
1841
+ /** Refining actions taken on the current step (written answers among them), for the limit. */
1773
1842
  private refinements?;
1774
1843
  /** The watchdog's next check, while a claimed interaction is pending. */
1775
1844
  private watchdog?;
@@ -1799,8 +1868,23 @@ export declare class AutopilotDriver extends BaseDriverDecorator implements Auto
1799
1868
  private ranSinceStop;
1800
1869
  /** The check that confirms the autopilot stopped, once it looked like it had. */
1801
1870
  private stopCheck?;
1871
+ /** Stops each wait for a widget left with the person to ask them; see `reportHandBackWhenAsking`. */
1872
+ private readonly handBackWaits;
1802
1873
  constructor(inner: AiDriver, options: AutopilotDriverOptions);
1803
1874
  get state(): AutopilotHostState;
1875
+ /**
1876
+ * Whether the working agent is parked on a question the person holds, with the autopilot deciding
1877
+ * nothing: one it never took — its policy keeps it for the person, it is `userOnly` (the turn-level
1878
+ * hand-back among them), it has no controller, or it opened while paused and no Resume has taken
1879
+ * it since (a restored mode takes nothing) — or one another interceptor took and then gave to the
1880
+ * person. One the autopilot handed back reads `selfPaused`, and one a pause handed over reads
1881
+ * `paused`; `state` settles both before asking this.
1882
+ *
1883
+ * Never one that asks them nothing (see `asksThePerson`): the person holds it, but it is work
1884
+ * running, which settles by itself, so "waiting for your answer" would be untrue. A hand-back is
1885
+ * reported by the same rule (see `reportHandBackWhenAsking`).
1886
+ */
1887
+ private waitingOnUser;
1804
1888
  get copy(): AutopilotCopy;
1805
1889
  subscribe(listener: () => void): () => void;
1806
1890
  pause(): void;
@@ -1838,9 +1922,9 @@ export declare class AutopilotDriver extends BaseDriverDecorator implements Auto
1838
1922
  *
1839
1923
  * Sent only if the question still stands when the answer lands: no pause or resume since it was
1840
1924
  * asked (Pause stops it, and the question is the person's to answer by typing), the flow still
1841
- * running, the working agent idle, and the question still the last thing it said. Otherwise the
1842
- * answer goes nowhere — not sent, not counted, not recorded as acted — and its cost is recorded as
1843
- * dropped, as it is whenever no reply is sent to carry it.
1925
+ * running and the autopilot still available to it, the working agent idle, and the question still
1926
+ * the last thing it said. Otherwise the answer goes nowhere — not sent, not counted, not recorded
1927
+ * as acted — and its cost is recorded as dropped, as it is whenever no reply is sent to carry it.
1844
1928
  */
1845
1929
  private answer;
1846
1930
  /**
@@ -1868,14 +1952,69 @@ export declare class AutopilotDriver extends BaseDriverDecorator implements Auto
1868
1952
  private endSessions;
1869
1953
  dispose(): Promise<void>;
1870
1954
  private onInteractionOpened;
1955
+ private decline;
1956
+ /**
1957
+ * Report a widget the autopilot declined, and so left with the person, as a hand-back (GENC-1660)
1958
+ * — but only once it waits on them: by the rule the status reads (`asksThePerson`), or because the
1959
+ * widget asked for their attention. Then only if it still does, and is still theirs, after
1960
+ * `HAND_BACK_GRACE_MS`, so one that settles itself as it mounts never reports. One that is working
1961
+ * reports when it starts asking, with the message it asked with. One that settles first, or that
1962
+ * another interceptor claims first, never reports: that claimant reports its own hand-back.
1963
+ *
1964
+ * The report is the interaction's one notification. The widget's own request is taken over
1965
+ * (`hold.takeAttention`), so it is not reported as well, before or after: it only counts as the
1966
+ * widget asking. When its request has already counted — reported while the person held it, before
1967
+ * a decline on Resume — the person was told then, so nothing more is reported.
1968
+ */
1969
+ private reportHandBackWhenAsking;
1970
+ /**
1971
+ * Whether the autopilot running for `owner` may take `opened`: the agent that answers for it, or
1972
+ * why not, as `autopilot.declined` records it. The mode is the caller's to check — the open path
1973
+ * asks this only while running, and a live Resume only for what opened while paused — so both ask
1974
+ * the same questions in the same order.
1975
+ */
1976
+ private eligibility;
1977
+ /**
1978
+ * Hold an interaction the autopilot claimed, watch it, and decide it once its surface is ready.
1979
+ * `deferred` when the claim is granted only after the caller returns (the open path), so the
1980
+ * decision waits a microtask for it; a late claim through `hold.claim` is granted already.
1981
+ *
1982
+ * The decision starts only if the autopilot still holds it then, with no pause or resume in
1983
+ * between: a pause hands it over, and the Resume after that decides it itself.
1984
+ */
1985
+ private take;
1986
+ /**
1987
+ * Decide `held` once a decision is due on it (`onSurfaceReady`): at once if one is, or when its
1988
+ * controller next makes one due — exposes a surface, enables an action, or says it is asking.
1989
+ * Only if, by then, the autopilot still holds it with no pause or resume in between: a pause hands
1990
+ * it over, and the Resume after that decides it itself.
1991
+ */
1992
+ private decideWhenReady;
1993
+ /**
1994
+ * On a live Resume: take the open interaction if it was declined only because the autopilot was
1995
+ * paused when it opened, and would be claimed if it opened now — the same checks as the open
1996
+ * path. Returns whether it took it. A person may have started on it; it is taken as it stands, as
1997
+ * Resume takes back one a pause handed over, and the autopilot reads it as it now is.
1998
+ */
1999
+ private takeOpenOnResume;
2000
+ /**
2001
+ * Follow every interaction while it is open, claimed or not, so the status can say when the
2002
+ * person is the one being waited on (see `waitingOnUser`), and tell the host each time that
2003
+ * changes: when it opens, when it moves between holders, and when it settles.
2004
+ */
2005
+ private trackOpen;
1871
2006
  /** Run one decision on the flow's session, and act on how it ended. */
1872
2007
  private decide;
1873
2008
  /** The step a decision belongs to, for the refinement limit (§4.4). */
1874
2009
  private stepKey;
1875
- /** Whether a written answer is still allowed on this step. The count resets when the step changes. */
1876
- private mayRefine;
2010
+ /**
2011
+ * How many refining actions (written answers, and full-form actions declared `refines`) are left
2012
+ * on this step: none left withdraws them all. Read fresh, so a refinement taken mid-decision (a
2013
+ * `refines` action that does not settle) counts at once. The count resets when the step changes.
2014
+ */
2015
+ private refinementsLeft;
1877
2016
  private countRefinement;
1878
- /** Written answers allowed per step: the config's when it is a whole number `>= 0`. */
2017
+ /** Refinements allowed per step: the config's when it is a whole number `>= 0`. */
1879
2018
  private refinementLimit;
1880
2019
  /**
1881
2020
  * The watchdog (§4.2, critique S5): a claimed interaction whose work has gone quiet for longer
@@ -1910,7 +2049,10 @@ export declare class AutopilotDriver extends BaseDriverDecorator implements Auto
1910
2049
  private copyFor;
1911
2050
  private sessionFor;
1912
2051
  private record;
1913
- /** Report that something needs the person, for the assistant to notify them (GENC-1676). */
2052
+ /**
2053
+ * Report that something needs the person, for the assistant to notify them (GENC-1676), with the
2054
+ * widget's own message when it gave one (GENC-1660).
2055
+ */
1914
2056
  private attention;
1915
2057
  /**
1916
2058
  * Report the autopilot stopping work on its own (GENC-1676): after running and working, nothing
@@ -1954,7 +2096,7 @@ export declare interface AutopilotDriverOptions {
1954
2096
  */
1955
2097
  export declare class AutopilotHandBack extends GenesisElement {
1956
2098
  interactionId: string;
1957
- interaction?: AiChatInteraction<HandBackData, HandBackResult['payload']>;
2099
+ interaction?: AiChatInteraction<HandBackData, HandBackResult['payload'], HandBackController>;
1958
2100
  draft: string;
1959
2101
  get data(): HandBackData | undefined;
1960
2102
  /** What was chosen, once resolved. */
@@ -1978,7 +2120,8 @@ export declare interface AutopilotHost {
1978
2120
  pause(): void;
1979
2121
  /**
1980
2122
  * Resume. Takes back an interaction that pausing handed over; during the autopilot's own
1981
- * hand-back it means "decide it yourself".
2123
+ * hand-back it means "decide it yourself". Takes an interaction that opened while paused and is
2124
+ * still open, when it would have claimed it had it been running then.
1982
2125
  */
1983
2126
  resume(): void;
1984
2127
  /** The existing Stop, which also pauses, so what is shown stays honest. */
@@ -2004,9 +2147,16 @@ export declare interface AutopilotHostState {
2004
2147
  readonly interactionId?: string;
2005
2148
  readonly reason?: string;
2006
2149
  };
2007
- /** The slim bar's one-line status. */
2150
+ /**
2151
+ * The slim bar's one-line status, from `AutopilotCopy`: `running`, or `waitingForUser` while the
2152
+ * working agent waits on a question the autopilot left with the person; `selfPaused` while it
2153
+ * waits on one it handed back; `paused` otherwise.
2154
+ */
2008
2155
  readonly status: string;
2009
- /** Whether something waits on the person: drives the "needs you" badge. */
2156
+ /**
2157
+ * Whether the autopilot stopped and needs the person — its own hand-back of a widget or of a
2158
+ * turn: drives the "needs you" badge. Not set for a question it never took (see `status`).
2159
+ */
2010
2160
  readonly needsUser: boolean;
2011
2161
  /**
2012
2162
  * Whether something is happening: the working agent is busy, or the autopilot is deciding (a
@@ -2388,6 +2538,8 @@ export declare abstract class BaseDriverDecorator<TInner extends AiDriver = AiDr
2388
2538
  setPinnedAgent(name: string | null): void;
2389
2539
  setFlowOwner(name: string | null): void;
2390
2540
  getFlowOwner(): string | null;
2541
+ getInteractionCheckpoints(): readonly PersistedInteractionCheckpoint[];
2542
+ restoreInteractionCheckpoints(saved: readonly PersistedInteractionCheckpoint[]): void;
2391
2543
  getInteractionCheckpoint(): PersistedInteractionCheckpoint | undefined;
2392
2544
  restoreInteractionCheckpoint(saved: PersistedInteractionCheckpoint | undefined): void;
2393
2545
  /**
@@ -3547,9 +3699,21 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
3547
3699
  * host) to build the widget's pending `interaction` descriptor.
3548
3700
  */
3549
3701
  getInteractionContext(interactionId: string): InteractionContext | undefined;
3550
- /** {@inheritDoc AiDriver.getInteractionCheckpoint} */
3702
+ /** {@inheritDoc AiDriver.getInteractionCheckpoints} */
3703
+ getInteractionCheckpoints(): readonly PersistedInteractionCheckpoint[];
3704
+ /** {@inheritDoc AiDriver.restoreInteractionCheckpoints} */
3705
+ restoreInteractionCheckpoints(saved: readonly PersistedInteractionCheckpoint[]): void;
3706
+ /**
3707
+ * {@inheritDoc AiDriver.getInteractionCheckpoint}
3708
+ *
3709
+ * @deprecated Use `getInteractionCheckpoints`.
3710
+ */
3551
3711
  getInteractionCheckpoint(): PersistedInteractionCheckpoint | undefined;
3552
- /** {@inheritDoc AiDriver.restoreInteractionCheckpoint} */
3712
+ /**
3713
+ * {@inheritDoc AiDriver.restoreInteractionCheckpoint}
3714
+ *
3715
+ * @deprecated Use `restoreInteractionCheckpoints`.
3716
+ */
3553
3717
  restoreInteractionCheckpoint(saved: PersistedInteractionCheckpoint | undefined): void;
3554
3718
  /**
3555
3719
  * Replace the history message owning `interactionId`. `false` when it is no longer in history.
@@ -3933,6 +4097,50 @@ export declare interface ContinueFromHistoryOptions {
3933
4097
  tailNote?: string;
3934
4098
  }
3935
4099
 
4100
+ /**
4101
+ * What a widget controller needs from whatever hosts it (GENC-1660): the slice of
4102
+ * {@link InteractionContext} a controller uses, so it can be built and tested without the rest. An
4103
+ * `InteractionContext` is one, so a registration passes its `ctx` straight through:
4104
+ *
4105
+ * ```ts
4106
+ * class ReviewController {
4107
+ * constructor(data: ReviewData, private readonly host: ControllerHost<ReviewResult>) {
4108
+ * host.exposeSurface?.({ … });
4109
+ * }
4110
+ * }
4111
+ * registerInteraction<ReviewController>('review', {
4112
+ * controller: (data, ctx) => new ReviewController(data as ReviewData, ctx),
4113
+ * });
4114
+ * ```
4115
+ *
4116
+ * `heldBy`, `exposeDecision` and `exposeSurface` are optional so a view can build the same
4117
+ * controller over a stand-in host for a card with no live context (a resolved one in the
4118
+ * transcript, a gallery): nobody can claim it, so it has nothing to expose and only the person
4119
+ * holds it. Read an absent `heldBy` as `'user'`.
4120
+ *
4121
+ * `TResult` is the payload type the controller resolves with; `TState` what it keeps on `state`.
4122
+ *
4123
+ * @beta
4124
+ */
4125
+ export declare interface ControllerHost<TResult = unknown, TState extends object = object> {
4126
+ /** Survives a remount; where a controller keeps anything the person has started. */
4127
+ readonly state: TState;
4128
+ /** Settle the interaction. See {@link InteractionContext.resolve}. */
4129
+ resolve(result: InteractionResult<TResult>, options?: InteractionResolveOptions): void;
4130
+ /** Something in the controller's state or view model changed. See {@link InteractionContext.notify}. */
4131
+ notify(): void;
4132
+ /** Who holds the interaction right now: `'user'`, or the claimant's id. Absent means the person. */
4133
+ readonly heldBy?: InteractionHolder;
4134
+ /** See {@link InteractionContext.exposeDecision}. Absent on a stand-in host. */
4135
+ exposeDecision?(decision: DecisionSpec): void;
4136
+ /** See {@link InteractionContext.exposeSurface}. Absent on a stand-in host. */
4137
+ exposeSurface?(surface: SurfaceSpec): void;
4138
+ /** See {@link InteractionContext.setWorking}. Absent on a stand-in host. */
4139
+ setWorking?(working: boolean): void;
4140
+ /** See {@link InteractionContext.requestAttention}. Absent on a stand-in host. */
4141
+ requestAttention?(message?: string): void;
4142
+ }
4143
+
3936
4144
  /** A model used during a recorded cost session. */
3937
4145
  export declare interface CostSessionModelEntry {
3938
4146
  model: string;
@@ -3988,6 +4196,36 @@ export declare interface CostSessionRecord {
3988
4196
  models: CostSessionModelEntry[];
3989
4197
  }
3990
4198
 
4199
+ /**
4200
+ * Build a real interaction context for a controller test (GENC-1660), so the test exercises the
4201
+ * platform's own context — its `state`, `once`, `notify`, surfaces and their checks — rather than a
4202
+ * hand-built fake that can drift from it. Nothing renders, nothing is persisted, and no driver is
4203
+ * involved: resolving records the result, and the interaction is disposed as it would be.
4204
+ *
4205
+ * @example
4206
+ * ```ts
4207
+ * const t = createTestInteractionContext<ReviewController, ReviewResult>({
4208
+ * data: { round: 1 },
4209
+ * controller: (data, ctx) => new ReviewController(data as ReviewData, ctx),
4210
+ * });
4211
+ * t.setHeldBy('autopilot');
4212
+ * await t.act('regenerate', { text: 'amounts in EUR' });
4213
+ * assert.equal(t.result?.payload, { action: 'regenerate', instructions: 'amounts in EUR' });
4214
+ * ```
4215
+ *
4216
+ * @beta
4217
+ */
4218
+ export declare function createTestInteractionContext<TController = unknown, TResult = unknown>(options?: {
4219
+ /** Defaults to `'test-interaction'`. */
4220
+ readonly interactionId?: string;
4221
+ /** The `data` handed to `controller`. */
4222
+ readonly data?: unknown;
4223
+ /** Build the controller as the platform would, and install it as `context.controller`. */
4224
+ readonly controller?: InteractionControllerFactory<TController>;
4225
+ /** A checkpoint the platform handed over, as after a reload (`ctx.checkpoint`). */
4226
+ readonly checkpoint?: unknown;
4227
+ }): TestInteractionContext<TController, TResult>;
4228
+
3991
4229
  /**
3992
4230
  * Creates a tool fold — a facade that hides a group of related tools behind a single
3993
4231
  * named entry, revealing them progressively when the model invokes the facade.
@@ -4118,10 +4356,12 @@ export declare type DecisionOption = string | {
4118
4356
  /** The option's text, as the person sees it. */
4119
4357
  readonly label: string;
4120
4358
  /**
4121
- * Whether it can be chosen right now — the button's own guard (e.g. `validated` for a
4122
- * Continue). Read fresh every time. A disabled option is listed as unavailable and refused.
4359
+ * Why it cannot be chosen right now, or `undefined` when it can — the button's own guard (e.g.
4360
+ * "2 validation errors" for a Continue that needs a validated handler). Read fresh every time.
4361
+ * An unavailable option is listed with its reason and refused with it. Absent means always
4362
+ * available; an empty string or a throw counts as unavailable, with a generic reason.
4123
4363
  */
4124
- readonly enabledWhen?: () => boolean;
4364
+ readonly unavailable?: () => string | undefined;
4125
4365
  };
4126
4366
 
4127
4367
  /**
@@ -4134,13 +4374,47 @@ export declare interface DecisionSpec {
4134
4374
  readonly options: readonly DecisionOption[];
4135
4375
  /** Adds a `select({ options })` action that picks several. */
4136
4376
  readonly multi?: boolean;
4137
- /** Adds a `reply({ text })` action: an answer in the chooser's own words. */
4377
+ /**
4378
+ * Adds a `reply({ text })` action: an answer in the chooser's own words. It refines, so it counts
4379
+ * against the autopilot's per-step refinement limit and is withdrawn past it.
4380
+ */
4138
4381
  readonly freeText?: boolean;
4382
+ /**
4383
+ * Why the `reply` action cannot be used right now, or `undefined` when it can: the same guard
4384
+ * pattern as an option's {@link DecisionOption} `unavailable`, read fresh. For a widget whose
4385
+ * written answer only makes sense in some states (a review gate that failed, say, where only
4386
+ * handing back is left). Ignored without `freeText`.
4387
+ */
4388
+ readonly freeTextUnavailable?: () => string | undefined;
4139
4389
  /**
4140
4390
  * What a decision needs that the person sees on screen in some other form — e.g.
4141
4391
  * `{ validated: true }`. A getter, so it is read fresh whenever the decision is described.
4142
4392
  */
4143
4393
  readonly facts?: () => Readonly<Record<string, unknown>>;
4394
+ /**
4395
+ * Named views a claimant may read on demand: content too long to send with every decision but
4396
+ * sometimes needed to make it. Each is listed in the decision with its description, and read with
4397
+ * `widget_read({ view })`; a view not listed here is refused. `widget_read()` with no view still
4398
+ * reads the decision's `facts`.
4399
+ *
4400
+ * The same shape as the full form's {@link SurfaceSpec.views}, so a widget can offer something
4401
+ * to read and keep the short form's generated options.
4402
+ *
4403
+ * @example
4404
+ * ```ts
4405
+ * ctx.exposeDecision({
4406
+ * options: ['Yes, add one', 'No, skip this step'],
4407
+ * choose,
4408
+ * views: {
4409
+ * moreInfo: {
4410
+ * description: 'The "More info" explainer the person can open on the card.',
4411
+ * read: () => data.moreInfo,
4412
+ * },
4413
+ * },
4414
+ * });
4415
+ * ```
4416
+ */
4417
+ readonly views?: Readonly<Record<string, SurfaceView>>;
4144
4418
  /**
4145
4419
  * Model-only guidance the person would not see. The decision's own text comes from the
4146
4420
  * widget's `asText`, which is what the person saw.
@@ -4207,12 +4481,16 @@ export declare function defineAgent<const T extends AgentConfig>(config: T): T;
4207
4481
  * …,
4208
4482
  * autopilot: defineAutopilot<BootstrapState>({
4209
4483
  * availableWhen: ({ state }) => briefApproved(state.machine),
4210
- * widgetPolicy: { 'planning-question': 'allowed' },
4484
+ * widgetPolicy: { 'planning-question': 'allowed', 'sample-data-review': 'allowed' },
4485
+ * widgetTools: [SAMPLE_DATA_TOOLS],
4211
4486
  * systemPrompt: ({ state }) => `${AUTOPILOT_BASE}\n<brief>${frozenBrief(state)}</brief>`,
4212
4487
  * }),
4213
4488
  * });
4214
4489
  * ```
4215
4490
  *
4491
+ * Throws if two of its tools share a name — its widget tools, its own `tools` and the platform's
4492
+ * fixed three — since one would silently shadow the other.
4493
+ *
4216
4494
  * @beta
4217
4495
  */
4218
4496
  export declare function defineAutopilot<S = unknown>(config: AutopilotConfig<S>): AutopilotConfig<S>;
@@ -6450,6 +6728,17 @@ export declare class FoundationAiAssistant extends GenesisElement {
6450
6728
  * the session ref captured at turn start, then the cleanup the state setter would have done.
6451
6729
  */
6452
6730
  private settleAfterTurn;
6731
+ /**
6732
+ * Report a turn that ended with the assistant waiting for the person to type (GENC-1660), for the
6733
+ * Always level: `turn-ended` on the activity bus, like every other notification report.
6734
+ *
6735
+ * Only for a turn that ran to its end, failed ones included: not one the person stopped
6736
+ * (`cancelling`), since they are there. Not while an interaction waits on them, which reports
6737
+ * itself, so the person is never told twice about one moment. And not while an autopilot runs for
6738
+ * the flow: it answers, hands back or reports its own stop. Sub-agents' turns never get here; they
6739
+ * run inside one of the parent's.
6740
+ */
6741
+ private reportTurnEnded;
6453
6742
  onChatHeaderMouseDown(e: MouseEvent): void;
6454
6743
  handleInteractionCompleted(e: Event): void;
6455
6744
  /**
@@ -6611,6 +6900,26 @@ export declare type GenesisWriteReviewCompletedEventDetail = InteractionResult<G
6611
6900
  */
6612
6901
  export declare function getAiPopoutManager(): FoundationAiPopoutManager | undefined;
6613
6902
 
6903
+ /**
6904
+ * The live context of a pending interaction, by its id (GENC-1660), for UI that the chat does not
6905
+ * render and so is never handed one: a layout side panel that shows a widget's detail, say. It can
6906
+ * subscribe, read `heldBy` and reach the controller directly, rather than through a channel of its
6907
+ * own. `undefined` once the interaction has resolved (its context is disposed then) and for an id
6908
+ * that never opened.
6909
+ *
6910
+ * `TController` types `controller`, as it was registered (`registerInteraction<TController>()`).
6911
+ * Unchecked: the caller says what it expects.
6912
+ *
6913
+ * @example
6914
+ * ```ts
6915
+ * const ctx = getInteractionContext<ReviewController>(interactionId);
6916
+ * const unsubscribe = ctx?.subscribe(() => this.render(ctx.controller?.view(), ctx.heldBy));
6917
+ * ```
6918
+ *
6919
+ * @beta
6920
+ */
6921
+ export declare function getInteractionContext<TController = unknown>(interactionId: string): InteractionContext<Record<string, unknown>, unknown, TController> | undefined;
6922
+
6614
6923
  /**
6615
6924
  * The registration for a component name, or `undefined` when it has none.
6616
6925
  *
@@ -6626,6 +6935,19 @@ export declare function getInteractionRegistration(name: string): InteractionReg
6626
6935
  */
6627
6936
  export declare type HandBackChoice = 'carry-on' | 'try-again' | 'compact' | 'pause' | 'reply';
6628
6937
 
6938
+ /**
6939
+ * The hand-back's controller. DOM-free: it exposes the choices as a decision (so the visible
6940
+ * transcript and the debug log describe it like any widget) and resolves through `ctx.resolve`. The
6941
+ * hand-back is always `userOnly`, so nothing but the person ever answers it.
6942
+ */
6943
+ declare class HandBackController {
6944
+ readonly data: HandBackData;
6945
+ private readonly ctx;
6946
+ constructor(data: HandBackData, ctx: ControllerHost<HandBackResult['payload']>);
6947
+ /** The person's choice, from the view's buttons or its text box. */
6948
+ choose(answer: DecisionAnswer): void;
6949
+ }
6950
+
6629
6951
  /**
6630
6952
  * The hand-back's inputs. Every word it shows comes from here, so it follows the autopilot's
6631
6953
  * `AutopilotCopy`.
@@ -6747,7 +7069,7 @@ export declare type InteractionCompletedEventDetail = ChatInteractionEventsMap['
6747
7069
  *
6748
7070
  * @beta
6749
7071
  */
6750
- export declare interface InteractionContext<TState extends object = Record<string, unknown>, TCheckpoint = unknown> {
7072
+ export declare interface InteractionContext<TState extends object = Record<string, unknown>, TCheckpoint = unknown, TController = unknown> {
6751
7073
  /** Stable id of the interaction this context belongs to. */
6752
7074
  readonly interactionId: string;
6753
7075
  /**
@@ -6790,6 +7112,10 @@ export declare interface InteractionContext<TState extends object = Record<strin
6790
7112
  * live resource here must guard on the resolved state and stop touching `once`
6791
7113
  * when the interaction completes — a stray late call (e.g. an async callback
6792
7114
  * landing after a `timeoutMs` timeout) gets `null` rather than a leaked resource.
7115
+ *
7116
+ * Once means once for the interaction's whole life, so it cannot fire twice: anything a
7117
+ * claimant's hand-back must do again (reopening a side panel it shut while it held the
7118
+ * interaction, say) needs a flag on `state` instead, cleared when it is undone.
6793
7119
  */
6794
7120
  once<T>(key: string, factory: () => T): T | null;
6795
7121
  /**
@@ -6812,16 +7138,53 @@ export declare interface InteractionContext<TState extends object = Record<strin
6812
7138
  onDispose(fn: () => void): void;
6813
7139
  /**
6814
7140
  * The widget's controller, built by the platform from its registration when the interaction was
6815
- * requested, before anything rendered. `undefined` for an unregistered widget. One per
6816
- * interaction for its whole life, so a remounted view picks up the same one.
7141
+ * requested, before anything rendered. `undefined` for an unregistered widget, and inside the
7142
+ * registration's own factory, which is building it. One per interaction for its whole life, so a
7143
+ * remounted view picks up the same one. Typed by `TController`: a registration made with
7144
+ * `registerInteraction<TController>()` builds one, and a view reads it typed through
7145
+ * `AiChatInteraction`'s third type argument.
6817
7146
  */
6818
- readonly controller: unknown;
7147
+ readonly controller: TController | undefined;
6819
7148
  /**
6820
7149
  * Settle the interaction with `result` — the controller's way to resolve, in place of an element
6821
7150
  * emitting `interaction-completed`, so resolving needs no mounted view. Goes through the same
6822
7151
  * path, so cost and diagnostics fold in as before. Settles once: later calls do nothing.
7152
+ *
7153
+ * Pass `{ resolvedItself: true }` when this outcome settled by itself and asked nobody, for a
7154
+ * widget that sometimes works on its own and sometimes asks (see
7155
+ * {@link InteractionResolveOptions.resolvedItself}).
6823
7156
  */
6824
- resolve(result: unknown): void;
7157
+ resolve(result: unknown, options?: InteractionResolveOptions): void;
7158
+ /**
7159
+ * What the controller last said it is doing (GENC-1660), through {@link InteractionContext.setWorking}:
7160
+ * `true` working on its own (generating, running tests), `false` asking (what it has exposed is
7161
+ * the decision to make now), `undefined` until it says either.
7162
+ */
7163
+ readonly working: boolean | undefined;
7164
+ /**
7165
+ * Say whether the controller is working on its own or asking (GENC-1660), for a widget that does
7166
+ * both — e.g. it generates, then opens a review gate. Optional: a controller that never calls it
7167
+ * behaves exactly as before. Notifies when it changes.
7168
+ *
7169
+ * - **Status.** While it is working the person is not being asked anything, so an autopilot's
7170
+ * status reads running rather than waiting for the user, even while the person holds it. Said
7171
+ * either way, it overrides the registration's `resolvesItself` for this interaction.
7172
+ * - **Readiness** (see {@link InteractionSurface.isReady}). While it is working, nothing it
7173
+ * exposed is a decision yet, so a claimant is never sent one mid-work, even with actions
7174
+ * enabled. Once it says it is asking, what it exposed is the decision to make now, even with
7175
+ * every action unavailable — a failed gate the claimant may not cancel, say: the claimant is
7176
+ * then sent it with the actions marked unavailable, and can only hand it back. Never said, a
7177
+ * decision is due once something is enabled, as before.
7178
+ *
7179
+ * @example
7180
+ * ```ts
7181
+ * ctx.setWorking(true);
7182
+ * const code = await generate();
7183
+ * ctx.exposeDecision({ options: [...], choose });
7184
+ * ctx.setWorking(false); // the gate is open: decide it, even if nothing can be chosen
7185
+ * ```
7186
+ */
7187
+ setWorking(working: boolean): void;
6825
7188
  /**
6826
7189
  * Expose what can be decided here (the short form). Called by the controller: in its constructor
6827
7190
  * for a pure question, or when its gate opens for a widget that works first. Calling again
@@ -6837,9 +7200,10 @@ export declare interface InteractionContext<TState extends object = Record<strin
6837
7200
  /** The surface the controller exposed, or `undefined` until it exposes one. */
6838
7201
  readonly surface: InteractionSurface | undefined;
6839
7202
  /**
6840
- * Run `fn` once the surface is ready (see `InteractionSurface.isReady`) — or now if
6841
- * it already is. Readiness is re-checked on every `notify()`, so a gate whose guard turns true
6842
- * later fires it then. Never runs after the interaction ends. Returns an unsubscribe.
7203
+ * Run `fn` once the surface is ready (see `InteractionSurface.isReady`, which honours
7204
+ * {@link InteractionContext.setWorking}) — or now if it already is. Readiness is re-checked on
7205
+ * every `notify()` (which `setWorking` and both `expose` calls make), so a gate whose guard turns
7206
+ * true later fires it then. Never runs after the interaction ends. Returns an unsubscribe.
6843
7207
  */
6844
7208
  onSurfaceReady(fn: () => void): () => void;
6845
7209
  /**
@@ -6857,10 +7221,12 @@ export declare interface InteractionContext<TState extends object = Record<strin
6857
7221
  * widget that only shows information never calls it.
6858
7222
  *
6859
7223
  * Safe to call from anywhere, the controller's constructor included: the platform reports it
6860
- * only once it has decided who holds the interaction, and drops it if a claimant (the autopilot)
6861
- * holds it then or when it is called — the claimant's own hand-back notifies instead. Only the
6862
- * first call counts, whatever happened to it; later ones do nothing, as do calls after the
6863
- * interaction ends.
7224
+ * only once it has decided who holds the interaction, and holds it back if a claimant (the
7225
+ * autopilot) holds it then or when it is called — the claimant's own hand-back notifies instead,
7226
+ * with `message` (GENC-1660). An autopilot that may not answer the interaction reports the
7227
+ * hand-back in its place too, once the widget waits on the person: the call then only says it
7228
+ * does, and gives that one notification its text. Only the first call counts, whatever happened
7229
+ * to it; later ones do nothing, as do calls after the interaction ends.
6864
7230
  *
6865
7231
  * @param message - The notification's text for this case. Defaults to the app's
6866
7232
  * `chatConfig.ui.notifications.message`, then to "The assistant is ready for your next input".
@@ -6868,27 +7234,31 @@ export declare interface InteractionContext<TState extends object = Record<strin
6868
7234
  requestAttention(message?: string): void;
6869
7235
  /**
6870
7236
  * What is already done, for long work that should survive a reload: the last checkpoint saved,
6871
- * or the one the platform handed over — after a restore, the first request for the same widget
6872
- * type takes over the checkpoint the reload cut, if the registration's `sameWork` agrees.
6873
- * `undefined` for fresh work. See `runSteps`, which reads and writes it for you.
7237
+ * or the one the platform handed over. After a restore, a checkpoint the reload cut waits for a
7238
+ * request of the same widget type that the registration's `sameWork` agrees is the same work —
7239
+ * offered to each such request in turn, however many other interactions come first, and kept
7240
+ * through every refusal — and is handed to the first that agrees. `undefined` for fresh work. See
7241
+ * `runSteps`, which reads and writes it for you.
6874
7242
  */
6875
7243
  readonly checkpoint: TCheckpoint | undefined;
6876
7244
  /**
6877
7245
  * Save a checkpoint into the session snapshot, so a reload does not lose it. Kept as JSON, so it
6878
7246
  * must be storable as JSON; keep it small and hold anything large by reference (a job id, a store
6879
- * key). One per interaction: each save replaces the last. Cleared when the interaction settles,
6880
- * and when its flow ends.
7247
+ * key). One per interaction: each save replaces the last. Never replaces a checkpoint a reload cut
7248
+ * that is still waiting for its own widget. Cleared when the interaction settles, and when its
7249
+ * flow ends.
6881
7250
  */
6882
7251
  saveCheckpoint(checkpoint: TCheckpoint): void;
6883
7252
  }
6884
7253
 
6885
7254
  /**
6886
7255
  * Builds a widget's controller when its interaction is requested (GENC-1660). DOM-free: it owns the
6887
- * interaction's state, its surface and resolving it; the view only renders.
7256
+ * interaction's state, its surface and resolving it; the view only renders. `ctx` is a
7257
+ * `ControllerHost` as it stands, so a controller that takes one is passed it directly.
6888
7258
  *
6889
7259
  * @beta
6890
7260
  */
6891
- export declare type InteractionControllerFactory = (data: unknown, ctx: InteractionContext) => unknown;
7261
+ export declare type InteractionControllerFactory<TController = unknown> = (data: unknown, ctx: InteractionContext<Record<string, unknown>, unknown, TController>) => TController;
6892
7262
 
6893
7263
  /**
6894
7264
  * Detail payload for the `interaction-cost` event — a POSITIVE DELTA in USD, not a running total.
@@ -6905,12 +7275,26 @@ export { InteractionEdit }
6905
7275
  * Every interceptor is offered one, but only the claimant's works: on any other interceptor's
6906
7276
  * handle, and after the interaction ends, its members do nothing and return `false`. A claim is
6907
7277
  * granted only once `onInteractionOpened` has returned `'claim'` (it may yet be refused), so the
6908
- * claimant's own handle does nothing until then either: act on it afterwards. Views read the
7278
+ * claimant's own handle does nothing until then either: act on it afterwards. An interceptor that
7279
+ * declined can still become the claimant later with `claim`, while nobody else is. Views read the
6909
7280
  * result as `ctx.heldBy`; they never change it.
6910
7281
  *
6911
7282
  * @beta
6912
7283
  */
6913
7284
  export declare interface InteractionHold {
7285
+ /**
7286
+ * Claim the interaction after declining it when it opened, as if it had claimed it then: it
7287
+ * moves to this interceptor, and the other members work for it from here on. For an interceptor
7288
+ * whose reason to decline has gone while the interaction is still open, such as an autopilot
7289
+ * that was paused when it opened and has since been resumed.
7290
+ *
7291
+ * Refused, returning `false` with nothing changed, while the interceptors are still being asked
7292
+ * (a claim at open is made by returning `'claim'`), once any interceptor has claimed it — this
7293
+ * one included, even if it has since given it to the person, which `set('claimant')` undoes —
7294
+ * when it is `userOnly`, and after it has ended. Notifies the context's subscribers and records
7295
+ * `interaction.held`, marked `late`.
7296
+ */
7297
+ claim(): boolean;
6914
7298
  /**
6915
7299
  * Give the interaction to the person (`'user'`) or back to the claimant (`'claimant'`). Notifies
6916
7300
  * the context's subscribers and records `interaction.held`. Returns whether it applied.
@@ -6933,7 +7317,8 @@ export declare interface InteractionHold {
6933
7317
  * Settle the interaction AS the claimant (GENC-1660). The only route that stamps the claimant as
6934
7318
  * `answeredBy`: an answer through the host's `resolveInteraction` — a click — is the person's,
6935
7319
  * whoever held the interaction at the time, so attribution never depends on a view honouring
6936
- * `heldBy`. Returns `false`, settling nothing, unless this interceptor holds it right now.
7320
+ * `heldBy`. The result's `userMessage` is ignored: the person did not say it. Returns `false`,
7321
+ * settling nothing, unless this interceptor holds it right now.
6937
7322
  */
6938
7323
  resolve(result: unknown): boolean;
6939
7324
  /**
@@ -6943,7 +7328,8 @@ export declare interface InteractionHold {
6943
7328
  * and `note`, verbatim, as what they were shown about it — so `recordDecision` is not needed.
6944
7329
  *
6945
7330
  * A finishing action settles the interaction AS the claimant, as {@link InteractionHold.resolve}
6946
- * does, so it is stamped `answeredBy` the claimant.
7331
+ * does, so it is stamped `answeredBy` the claimant. Its `note` is what the person is shown about
7332
+ * the choice; the widget's `userMessage` echo is never shown for a claimant's answer, note or not.
6947
7333
  *
6948
7334
  * Refused, with nothing run, unless this interceptor holds the interaction right now, the
6949
7335
  * surface has that action, it is enabled and `args` fit it. One action runs at a time: a call
@@ -6958,6 +7344,28 @@ export declare interface InteractionHold {
6958
7344
  invoke(action: string, args?: unknown, options?: {
6959
7345
  note?: string;
6960
7346
  }): Promise<InvokeResult>;
7347
+ /**
7348
+ * The message the widget passed to `InteractionContext.requestAttention`, once it has asked with
7349
+ * one (GENC-1660). A widget's request is not reported while a claimant holds the interaction, so
7350
+ * a claimant that hands it to the person reports with this, and the person reads the widget's
7351
+ * own words. Readable by every interceptor, claimant or not: one that declines the interaction
7352
+ * reports the hand-back too.
7353
+ */
7354
+ attentionMessage(): string | undefined;
7355
+ /**
7356
+ * Report the widget's request for the person's attention in its place (GENC-1660), for an
7357
+ * interceptor that leaves the interaction with the person and reports that itself, such as an
7358
+ * autopilot handing a widget it may not answer to the person. The widget's
7359
+ * `InteractionContext.requestAttention` is then not reported on its own: `onRequest` is called
7360
+ * instead, when it would have been, so the interceptor knows the widget is asking and the person
7361
+ * gets one notification for the interaction. `attentionMessage` still returns the widget's words.
7362
+ *
7363
+ * Works for every interceptor, claimant or not, while the interaction is open. Returns the undo,
7364
+ * for an interceptor that ends up not reporting after all, or `undefined` when there is nothing to
7365
+ * take: the widget's request already counted, the interaction has ended, or another interceptor
7366
+ * took it first.
7367
+ */
7368
+ takeAttention(onRequest: (message?: string) => void): (() => void) | undefined;
6961
7369
  }
6962
7370
 
6963
7371
  /**
@@ -6974,8 +7382,9 @@ export declare type InteractionHolder = 'user' | (string & {});
6974
7382
  * decorator such as an autopilot or a test harness.
6975
7383
  *
6976
7384
  * Interceptors are asked outermost first. The first to claim an interaction holds it; the rest
6977
- * observe — they see the same context but their `hold` does nothing. Nobody can claim a `userOnly`
6978
- * interaction. A throwing interceptor is logged and treated as abstaining.
7385
+ * observe — they see the same context but their `hold` does nothing. When none claims it, any of
7386
+ * them may claim it later with `hold.claim`, the first to do so winning. Nobody can claim a
7387
+ * `userOnly` interaction. A throwing interceptor is logged and treated as abstaining.
6979
7388
  *
6980
7389
  * @beta
6981
7390
  */
@@ -7023,21 +7432,25 @@ export declare interface InteractionOpened {
7023
7432
  readonly userOnly: boolean;
7024
7433
  /** The interaction's live context, the same object its widget is handed. */
7025
7434
  readonly ctx: InteractionContext;
7026
- /** See {@link InteractionHold}. Works only for the interceptor whose claim was granted. */
7435
+ /**
7436
+ * See {@link InteractionHold}. Works only for the interceptor whose claim was granted, at open or
7437
+ * later through `claim`.
7438
+ */
7027
7439
  readonly hold: InteractionHold;
7028
7440
  }
7029
7441
 
7030
7442
  /**
7031
- * How a widget is registered with the platform, once, at start-up (GENC-1660).
7443
+ * How a widget is registered with the platform, once, at start-up (GENC-1660). `TController` is
7444
+ * the type its factory builds, which `ctx.controller` then carries.
7032
7445
  *
7033
7446
  * @beta
7034
7447
  */
7035
- export declare interface InteractionRegistration {
7448
+ export declare interface InteractionRegistration<TController = unknown> {
7036
7449
  /**
7037
7450
  * Builds the controller when the interaction is requested, before anything renders. Without
7038
7451
  * one the widget works exactly as today and is never handed to a claimant.
7039
7452
  */
7040
- readonly controller?: InteractionControllerFactory;
7453
+ readonly controller?: InteractionControllerFactory<TController>;
7041
7454
  /** The custom element that renders it. Defaults to the registered name. */
7042
7455
  readonly view?: string;
7043
7456
  /**
@@ -7056,8 +7469,45 @@ export declare interface InteractionRegistration {
7056
7469
  * Without it, the same widget type is enough. Compare identity only — the fields the work's
7057
7470
  * output depends on, kept in the checkpoint itself — never the model's prose, which a resumed call
7058
7471
  * rewrites.
7472
+ *
7473
+ * Asked of every request of this widget type until it agrees: a refusal keeps the checkpoint for
7474
+ * a later request, so it must refuse whatever is not this work (another handler, superseded code)
7475
+ * rather than rely on being asked only once.
7059
7476
  */
7060
7477
  readonly sameWork?: (saved: unknown, next: unknown) => boolean;
7478
+ /**
7479
+ * Whether the widget does its work and settles on its own, asking the person nothing: a
7480
+ * generation run that resolves when it is done, which the person may interrupt (a Skip button)
7481
+ * but is not being asked to answer. Defaults to `false`, a widget that asks.
7482
+ *
7483
+ * While one is open the turn is working, not parked on the person, so an autopilot's status stays
7484
+ * `running` rather than `waitingForUser`. When it settles by any route but a claimant's hold,
7485
+ * nobody answered it: the interaction message carries no `answeredBy`, the `interaction-settled`
7486
+ * event and the `interaction.resolved` debug event carry `resolvedItself: true` instead, and the
7487
+ * transcript a claimant reads labels it `finished` rather than answered by the user. The platform
7488
+ * cannot tell the widget finishing from the person interrupting it — both settle it the same way
7489
+ * — so a widget whose agent needs to know which says so in its own result.
7490
+ *
7491
+ * Claiming is unchanged: a claimant can take one only through a controller and its policy, as for
7492
+ * any widget.
7493
+ *
7494
+ * For a widget that sometimes works on its own and sometimes asks — a generation phase that ends
7495
+ * at a review gate — leave this unset and say it per interaction instead: `ctx.setWorking(true)`
7496
+ * while it works (the status), and `ctx.resolve(result, { resolvedItself: true })` for an outcome
7497
+ * that settled itself (a generation that failed outright). A controller's `setWorking` overrides
7498
+ * this flag for the status of its own interaction.
7499
+ *
7500
+ * @example
7501
+ * ```ts
7502
+ * registerInteraction('sample-data-generation', {
7503
+ * resolvesItself: true,
7504
+ * asText: sampleDataAsText,
7505
+ * });
7506
+ * ```
7507
+ *
7508
+ * @beta
7509
+ */
7510
+ readonly resolvesItself?: boolean;
7061
7511
  }
7062
7512
 
7063
7513
  /**
@@ -7067,13 +7517,40 @@ export declare interface InteractionRegistration {
7067
7517
  */
7068
7518
  declare type InteractionRequester = <T>(componentName: string, data: any, options?: InteractionRequestOptions, onOpened?: (interactionId: string) => void, ownerPath?: readonly string[], onSettled?: (settled: InteractionSettled) => void) => Promise<T>;
7069
7519
 
7520
+ /**
7521
+ * How a controller settles its interaction, beside the result (GENC-1660). See
7522
+ * {@link InteractionContext.resolve}.
7523
+ *
7524
+ * @beta
7525
+ */
7526
+ export declare interface InteractionResolveOptions {
7527
+ /**
7528
+ * This outcome settled by itself and nobody answered it — a generation that failed outright, say
7529
+ * — though the widget is not registered `resolvesItself` because at other times it asks (a review
7530
+ * gate). It is then treated exactly as a `resolvesItself` widget's settle: no `answeredBy` on the
7531
+ * message, the asking tool's result or the `interaction-settled` event, and `resolvedItself: true`
7532
+ * on the message, the event and the `interaction.resolved` debug event, so neither the working
7533
+ * agent nor a claimant is told the person decided it.
7534
+ *
7535
+ * Ignored when a claimant settles it through its hold (a finishing action that ends up resolving
7536
+ * here is the claimant's answer), and on a timeout or a stop, which nobody answered anyway.
7537
+ */
7538
+ readonly resolvedItself?: boolean;
7539
+ }
7540
+
7070
7541
  /**
7071
7542
  * Who answered an interaction, as its requester is told (GENC-1660). `answeredBy` is absent when it
7072
- * closed unanswered (a timeout or a stop); `decision` is present when an interceptor answered;
7073
- * `edited` is present when the person answered one an interceptor had changed first.
7543
+ * closed unanswered (a timeout or a stop) and when nobody answered it because it settled by itself
7544
+ * (`resolvedItself`); `decision` is present when an interceptor answered; `edited` is present when
7545
+ * the person answered one an interceptor had changed first.
7074
7546
  */
7075
7547
  declare interface InteractionSettled {
7076
7548
  readonly answeredBy?: string;
7549
+ /**
7550
+ * It settled by itself, other than through a claimant's hold: its widget is registered
7551
+ * `resolvesItself`, or its controller resolved this outcome with `{ resolvedItself: true }`.
7552
+ */
7553
+ readonly resolvedItself?: boolean;
7077
7554
  readonly decision?: DelegatedDecision;
7078
7555
  readonly edited?: DelegatedEdits;
7079
7556
  }
@@ -7087,20 +7564,35 @@ declare interface InteractionSettled {
7087
7564
  export declare interface InteractionSurface {
7088
7565
  /** Model-only guidance, from the decision's `prompt`. */
7089
7566
  readonly prompt?: string;
7090
- /** Read fresh on every call. */
7567
+ /** Read fresh on every call. Always `{}` on a full-form surface. */
7091
7568
  facts(): Readonly<Record<string, unknown>>;
7092
7569
  /** A full-form surface's description. Absent on a short-form decision. */
7093
7570
  describe?(): string;
7094
- /** A full-form surface's views. */
7095
- readonly views?: readonly string[];
7096
- /** Read one view of a full-form surface; absent on a short-form decision. */
7571
+ /**
7572
+ * Its views, by name, each with the description the model is shown: a full-form surface's or a
7573
+ * short-form decision's. Absent when it has none.
7574
+ */
7575
+ readonly views?: Readonly<Record<string, string>>;
7576
+ /** A full-form surface's {@link SurfaceSpec.preview}: the view sent with the decision. */
7577
+ readonly preview?: string;
7578
+ /**
7579
+ * Read one view by name, or the default with none: a short-form decision's facts, or a full-form
7580
+ * surface's preview (`undefined` when it names none). A name it does not list reads as
7581
+ * `undefined`. Absent when it has no views.
7582
+ */
7097
7583
  read?(view?: string): unknown;
7098
7584
  /** Read fresh on every call: `enabled` reflects each option's guard right now. */
7099
7585
  actions(): readonly SurfaceAction[];
7100
7586
  /**
7101
- * Whether a claimant could act on it now. A short-form decision is ready once one of its options
7102
- * is enabled; a full-form surface once any of its actions is, since editing comes before
7103
- * finishing (its Save may be disabled until something is edited).
7587
+ * Whether a decision is due now: what a claimant is sent a decision on (`onSurfaceReady`).
7588
+ *
7589
+ * First, what the controller said through `ctx.setWorking`: while it is working, never, whatever
7590
+ * is enabled; once it is asking, always, even with every action unavailable — the claimant is
7591
+ * then sent the decision with the actions marked unavailable, and can only hand it back. When it
7592
+ * has said neither, the surface's own rule: a short-form decision is ready once one of its
7593
+ * finishing options is enabled (a `reply` counts, having no guard); a full-form surface once any
7594
+ * of its actions is, since editing comes before finishing (its Save may be disabled until
7595
+ * something is edited).
7104
7596
  */
7105
7597
  isReady(): boolean;
7106
7598
  }
@@ -7564,10 +8056,21 @@ export declare interface PersistedSession {
7564
8056
  mode: 'running' | 'paused';
7565
8057
  };
7566
8058
  /**
7567
- * The checkpoint of a long action (GENC-1660 §4.12): what a widget's work had already done, so a
7568
- * reload skips it. Kept here rather than on the interaction message, which a restore trims. On
7569
- * restore it waits for the first request of the same widget type. Optional and additive, like
7570
- * `condensePolicies`.
8059
+ * The checkpoints of long actions (GENC-1660 §4.12): what widgets' work had already done, so a
8060
+ * reload skips it — the one in flight, and any an earlier reload cut that nothing has taken over
8061
+ * yet. Kept here rather than on the interaction messages, which a restore trims. On restore each
8062
+ * waits for a request of its own widget type that `sameWork` agrees is the same work. Optional
8063
+ * and additive, like `condensePolicies`; omitted when there are none.
8064
+ */
8065
+ checkpoints?: Array<{
8066
+ componentName: string;
8067
+ value: unknown;
8068
+ }>;
8069
+ /**
8070
+ * The one checkpoint a snapshot held before `checkpoints` existed. Read on restore when
8071
+ * `checkpoints` is absent; never written now.
8072
+ *
8073
+ * @deprecated Written as `checkpoints`.
7571
8074
  */
7572
8075
  checkpoint?: {
7573
8076
  componentName: string;
@@ -7630,9 +8133,19 @@ declare type ProviderRefusedDetail = NonNullable<Extract<ChatDriverResult, {
7630
8133
  *
7631
8134
  * Registering is optional and additive: an unregistered widget works exactly as before.
7632
8135
  *
8136
+ * Generic over the controller its factory builds, which types `ctx.controller` for the factory and
8137
+ * for anything that reads the context with the same type argument (a view, a widget tool):
8138
+ *
8139
+ * ```ts
8140
+ * registerInteraction<ReviewController>('review', {
8141
+ * controller: (data, ctx) => new ReviewController(data as ReviewData, ctx),
8142
+ * asText: reviewAsText,
8143
+ * });
8144
+ * ```
8145
+ *
7633
8146
  * @beta
7634
8147
  */
7635
- export declare function registerInteraction(name: string, registration: InteractionRegistration): void;
8148
+ export declare function registerInteraction<TController = unknown>(name: string, registration: InteractionRegistration<TController>): void;
7636
8149
 
7637
8150
  /**
7638
8151
  * Build a {@link TieredAIProviderSwitcher} — which registers the tier-shaped provider
@@ -8520,7 +9033,7 @@ export declare type SuggestionsState = {
8520
9033
  * @beta
8521
9034
  */
8522
9035
  export declare interface SurfaceAction {
8523
- /** The name to invoke it by: an option's id, or `select` / `reply`. */
9036
+ /** The name to invoke it by: an option's id, `select` / `reply`, or a full-form action's name. */
8524
9037
  readonly name: string;
8525
9038
  /** The text the person sees for it, where it has one. */
8526
9039
  readonly label?: string;
@@ -8528,11 +9041,20 @@ export declare interface SurfaceAction {
8528
9041
  readonly finishes: boolean;
8529
9042
  /** Whether it can be run right now. */
8530
9043
  readonly enabled: boolean;
9044
+ /** Why it cannot be run right now, when it is not enabled. */
9045
+ readonly unavailable?: string;
8531
9046
  /**
8532
9047
  * What its `args` must look like, where it takes any: `options` (a multi-select's picks), `text`
8533
- * (a written answer) or `fields` (an object, described by `argsSchema`).
9048
+ * (one free-text argument: a written answer, or a full-form action declared with
9049
+ * {@link SurfaceActionSpec.text}) or `fields` (an object, described by `argsSchema`).
8534
9050
  */
8535
9051
  readonly args?: 'options' | 'text' | 'fields';
9052
+ /**
9053
+ * Whether it counts against the autopilot's per-step refinement limit (`maxRefinements`), and is
9054
+ * withdrawn once the limit is reached: `reply`, and a full-form action declared with
9055
+ * {@link SurfaceActionSpec.refines}.
9056
+ */
9057
+ readonly refines?: boolean;
8536
9058
  /** A full-form action's own description, for the model. Short-form options have none. */
8537
9059
  readonly description?: string;
8538
9060
  /** For `fields`: the JSON schema its arguments are checked against. */
@@ -8543,6 +9065,9 @@ export declare interface SurfaceAction {
8543
9065
  * One action of a full-form surface (GENC-1660 §4.2): a named thing a claimant can do, which may or
8544
9066
  * may not settle the interaction.
8545
9067
  *
9068
+ * It takes nothing, one free-text argument (`text`), or a form (`argsSchema`), never both of the
9069
+ * last two.
9070
+ *
8546
9071
  * @beta
8547
9072
  */
8548
9073
  export declare interface SurfaceActionSpec {
@@ -8550,16 +9075,42 @@ export declare interface SurfaceActionSpec {
8550
9075
  readonly description: string;
8551
9076
  /** Whether it settles the interaction. An editing action (`edit_rows`) does not. */
8552
9077
  readonly finishes?: boolean;
8553
- /** The button's own guard, read fresh: the claimant can never do what the view would refuse. */
8554
- readonly enabledWhen?: () => boolean;
8555
9078
  /**
8556
- * The JSON schema of its arguments, an object. Its `properties` and `required` are checked before
8557
- * it runs; a mismatch is refused with the reason, so the model can correct itself.
9079
+ * Why it cannot be run right now, or `undefined` when it can: the button's own guard, read fresh,
9080
+ * so the claimant can never do what the view would refuse. The reason is shown with the action
9081
+ * and given when a call is refused. Absent means always available; an empty string or a throw
9082
+ * counts as unavailable, with a generic reason.
9083
+ */
9084
+ readonly unavailable?: () => string | undefined;
9085
+ /**
9086
+ * It takes one free-text argument, which the claimant passes as `widget_act`'s own `text`, as
9087
+ * for `reply` — e.g. a regenerate's instruction. `run` then receives that text, trimmed, as a
9088
+ * string; an empty one is refused before it runs. Prefer it to an `argsSchema` with one string
9089
+ * property: plain text needs no JSON inside a string, which models get wrong.
9090
+ */
9091
+ readonly text?: boolean;
9092
+ /**
9093
+ * The JSON schema of its arguments, an object, for a real form. Its `properties` and `required`
9094
+ * are checked before it runs; a mismatch is refused with the reason, so the model can correct
9095
+ * itself. The claimant sends them as JSON text in `widget_act`'s `fields`, which is parsed
9096
+ * leniently (an object is taken as it is, a code fence is stripped), and invalid JSON is refused
9097
+ * with an example built from this schema. For one free-text argument use
9098
+ * {@link SurfaceActionSpec.text} instead.
8558
9099
  */
8559
9100
  readonly argsSchema?: Readonly<Record<string, unknown>>;
9101
+ /**
9102
+ * It refines rather than accepts — a regenerate with instructions, a retry with changes — so it
9103
+ * counts against the autopilot's per-step refinement limit (`maxRefinements`) exactly as a
9104
+ * written `reply` does, and is withdrawn (not listed, and refused) once the limit is reached.
9105
+ * Counted per step, not per interaction, so a refine that opens a new review of the same step
9106
+ * still counts. A claimant's limit only: a person's button is never limited by it.
9107
+ */
9108
+ readonly refines?: boolean;
8560
9109
  /**
8561
9110
  * Do it — the SAME code the view's control runs. A finishing action resolves the interaction; an
8562
- * editing one returns what changed (fresh errors, say), which the claimant is shown.
9111
+ * editing one returns what changed (fresh errors, say), which the claimant is shown. Receives
9112
+ * the text for a {@link SurfaceActionSpec.text} action, the checked object for an `argsSchema`
9113
+ * one, and `{}` otherwise.
8563
9114
  *
8564
9115
  * A finishing action should settle promptly. While one runs asynchronously, the claimant can run
8565
9116
  * nothing else, and it keeps the claimant's credit even if the interaction is handed to the person
@@ -8581,18 +9132,52 @@ export declare interface SurfaceActionSpec {
8581
9132
  export declare interface SurfaceSpec {
8582
9133
  /** For the model: what this is, and what good looks like. Read fresh. */
8583
9134
  describe(): string;
8584
- /** The names of the views `read` answers, e.g. `['summary', 'rows', 'errors']`. */
8585
- readonly views?: readonly string[];
8586
9135
  /**
8587
- * The widget's state as JSON, by view, so a large widget is read a slice at a time. Called with
8588
- * no view for the default (shown with the decision, so pick something small).
9136
+ * Named views a claimant may read with `widget_read({ view })`, each listed in the decision with
9137
+ * its description — the same shape as a short-form decision's {@link DecisionSpec.views}. Fixed
9138
+ * names with no parameters: a read that takes any (one table's rows) is a widget tool (see
9139
+ * `widgetTools`), and a view not listed here is refused.
9140
+ */
9141
+ readonly views?: Readonly<Record<string, SurfaceView>>;
9142
+ /**
9143
+ * The view sent with the decision, as `Now:`, to save a round trip; `widget_read()` with no view
9144
+ * reads it again. One of {@link SurfaceSpec.views}; unset sends none. Keep it small, and do not
9145
+ * repeat the widget's `asText`, which opens the same decision message: send what the text form
9146
+ * does not already say.
8589
9147
  */
8590
- read(view?: string): unknown;
9148
+ readonly preview?: string;
8591
9149
  readonly actions: Readonly<Record<string, SurfaceActionSpec>>;
8592
9150
  /** Model-only guidance, beside `describe`. */
8593
9151
  readonly prompt?: string;
8594
9152
  }
8595
9153
 
9154
+ /**
9155
+ * One named view of a surface (GENC-1660): content a claimant reads only when it asks for it, such
9156
+ * as a long explainer the person opens on the card, or a summary of a rich widget's state. Listed
9157
+ * in the decision with its description; its content is not, unless it is a full-form surface's
9158
+ * {@link SurfaceSpec.preview}.
9159
+ *
9160
+ * The same shape in both forms: a short-form decision's {@link DecisionSpec.views} and a full-form
9161
+ * surface's {@link SurfaceSpec.views}.
9162
+ *
9163
+ * A view takes no parameters. A read that needs them (one table's rows, a page at an offset) is a
9164
+ * widget tool instead: see `widgetTools`.
9165
+ *
9166
+ * Every read is capped at about 20,000 characters, cut with a note telling the model to ask for
9167
+ * less, so page anything that can grow.
9168
+ *
9169
+ * @beta
9170
+ */
9171
+ export declare interface SurfaceView {
9172
+ /**
9173
+ * For the model: what the view holds and when it is worth reading. Shown with every decision, so
9174
+ * keep it to a sentence — it is what tells the model the view exists at all.
9175
+ */
9176
+ readonly description: string;
9177
+ /** The view's content, as JSON. Read fresh on every `widget_read({ view })`. */
9178
+ read(): unknown;
9179
+ }
9180
+
8596
9181
  /**
8597
9182
  * Context passed to the function form of `systemPrompt` / `toolDefinitions`.
8598
9183
  * Resolved each tool-loop iteration so the agent can vary what the LLM sees per turn.
@@ -8643,6 +9228,67 @@ export declare type TailContextInput = string | ((ctx: SystemPromptContext) => s
8643
9228
  */
8644
9229
  export declare type TemperatureInput = number | ((ctx: SystemPromptContext) => number | Promise<number>);
8645
9230
 
9231
+ /**
9232
+ * What a claimant's action came to in a test: as `InteractionHold.invoke` reports it, less the
9233
+ * holding (a test context has no claimant to check).
9234
+ *
9235
+ * @beta
9236
+ */
9237
+ export declare type TestActResult = {
9238
+ readonly ok: true;
9239
+ readonly finished: boolean;
9240
+ readonly output?: unknown;
9241
+ } | {
9242
+ readonly ok: false;
9243
+ readonly error: 'no-surface' | 'unknown-action' | 'disabled' | 'invalid-args' | 'threw';
9244
+ readonly message: string;
9245
+ };
9246
+
9247
+ /**
9248
+ * A real {@link InteractionContext} for a controller test, with the handles a test needs
9249
+ * (GENC-1660). See {@link createTestInteractionContext}.
9250
+ *
9251
+ * @beta
9252
+ */
9253
+ export declare interface TestInteractionContext<TController = unknown, TResult = unknown> {
9254
+ /** The context, as the platform builds it: pass it to the controller as its host. */
9255
+ readonly context: InteractionContext<Record<string, unknown>, unknown, TController>;
9256
+ /** The controller, when built through `options.controller`; otherwise `undefined`. */
9257
+ readonly controller: TController | undefined;
9258
+ /** What the controller resolved with, or `undefined` while it has not. Only the first counts. */
9259
+ readonly result: InteractionResult<TResult> | undefined;
9260
+ /**
9261
+ * Whether the controller said its outcome settled by itself
9262
+ * (`ctx.resolve(result, { resolvedItself: true })`), which the platform then stamps as answered
9263
+ * by nobody. `false` while it has not resolved.
9264
+ */
9265
+ readonly resolvedItself: boolean;
9266
+ /** How many times `notify()` has been called. */
9267
+ readonly notifications: number;
9268
+ /**
9269
+ * The widget's `requestAttention` calls that were reported, as the platform would report them
9270
+ * (GENC-1660): only the first call counts, none after the interaction ends, and none while a
9271
+ * claimant holds it. The test context offers the interaction straight after building the
9272
+ * controller, with nobody claiming it, so a call made while being built is reported as the
9273
+ * person's; one made after `setHeldBy('autopilot')` is held back for the claimant's hand-back.
9274
+ */
9275
+ readonly attention: ReadonlyArray<{
9276
+ readonly message?: string;
9277
+ }>;
9278
+ /** The surface the controller exposed, as a claimant reads it; `undefined` until it exposes one. */
9279
+ readonly surface: InteractionSurface | undefined;
9280
+ /** Move the interaction to `holder` (`'user'`, or a claimant's id such as `'autopilot'`). */
9281
+ setHeldBy(holder: InteractionHolder): void;
9282
+ /**
9283
+ * Run one of the surface's actions as a claimant would, through the platform's own checks (the
9284
+ * action exists, its guard allows it, its arguments fit) and then its `run`: an option by id,
9285
+ * `select` with `{ options }`, `reply` or a text action with `{ text }`, a form with its fields.
9286
+ */
9287
+ act(action: string, args?: unknown): Promise<TestActResult>;
9288
+ /** End the interaction, running its `onDispose` callbacks, as settling it would. */
9289
+ dispose(): void;
9290
+ }
9291
+
8646
9292
  /**
8647
9293
  * Extended-thinking posture for an agent — whether the model reasons before answering. Either a
8648
9294
  * static `ChatThinkingPolicy` or a function resolved **once per user turn**, at the start of the
@@ -9164,6 +9810,102 @@ export declare class WebStorageSessionProvider implements SessionPersistenceProv
9164
9810
  savePreferences(sessionKey: string, preferences: SessionPreferences): Promise<void>;
9165
9811
  }
9166
9812
 
9813
+ /**
9814
+ * A widget's tools, bound to its component name: what {@link widgetTools} builds, and what an
9815
+ * autopilot's `widgetTools` takes.
9816
+ *
9817
+ * @beta
9818
+ */
9819
+ export declare interface WidgetTools {
9820
+ /** The widget type the tools read from: its registered component name. */
9821
+ readonly componentName: string;
9822
+ /** The tools, by name. */
9823
+ readonly tools: Readonly<Record<string, WidgetToolSpec<unknown, Record<string, unknown>>>>;
9824
+ }
9825
+
9826
+ /**
9827
+ * Declare tools that read from one widget type (GENC-1660): parameterised reads that a view cannot
9828
+ * express, such as one table's rows, or a page of them.
9829
+ *
9830
+ * Put them on the autopilot (`defineAutopilot({ widgetTools: [...] })`), never discovered from the
9831
+ * registration. Its tool list is fixed when its session starts, sorted by name, and identical for
9832
+ * every decision, so the cache never breaks. Each call is routed to the interaction of
9833
+ * `componentName` the autopilot is deciding, and `run` gets its controller; with none open, it is
9834
+ * refused with a reason. While one is open, the autopilot's tail says which tools are usable now.
9835
+ *
9836
+ * Reads only. Their results leave the autopilot's history at the end of the decision, as
9837
+ * `widget_read`'s do.
9838
+ *
9839
+ * @example
9840
+ * ```ts
9841
+ * export const SAMPLE_DATA_TOOLS = widgetTools('sample-data-review', {
9842
+ * sample_data_rows: {
9843
+ * definition: {
9844
+ * description: "One table's rows. Only while a sample-data review is open.",
9845
+ * parameters: {
9846
+ * type: 'object',
9847
+ * properties: { table: { type: 'string' }, offset: { type: 'integer' } },
9848
+ * required: ['table'],
9849
+ * },
9850
+ * },
9851
+ * run: (controller: SampleDataReviewController, args: { table: string; offset?: number }) =>
9852
+ * controller.rows(args.table, args.offset ?? 0),
9853
+ * },
9854
+ * });
9855
+ * ```
9856
+ *
9857
+ * @beta
9858
+ */
9859
+ export declare function widgetTools<TController, TArgs extends {
9860
+ [name: string]: object;
9861
+ }>(componentName: string, tools: {
9862
+ [K in keyof TArgs]: WidgetToolSpec<TController, TArgs[K]>;
9863
+ }): WidgetTools;
9864
+
9865
+ /**
9866
+ * One widget tool (GENC-1660): an ordinary tool with native, typed parameters that reads from the
9867
+ * widget open right now. `TController` is the widget's controller, as it was registered; `TArgs`
9868
+ * the parameters, as the model sends them.
9869
+ *
9870
+ * @beta
9871
+ */
9872
+ export declare interface WidgetToolSpec<TController = unknown, TArgs = Record<string, unknown>> {
9873
+ /**
9874
+ * The tool as the model sees it, less its name (the key it is declared under). Design it to the
9875
+ * same provider rules as any other tool: plain types, no type unions, no arrays of objects. Its
9876
+ * description should say when it applies, e.g. "Only while a sample-data review is open.": the
9877
+ * tool is offered on every decision, so the cached prefix never changes.
9878
+ *
9879
+ * Its `parameters`' `required` properties and their declared top-level types are checked before
9880
+ * `run` is called; a mismatch is refused with the reason.
9881
+ */
9882
+ readonly definition: Omit<ChatToolDefinition, 'name'>;
9883
+ /**
9884
+ * Why it cannot be used right now, or `undefined` when it can, for a tool that applies only in
9885
+ * some of its widget's states (the handler's code, once there is some). Read fresh: the tail lists
9886
+ * the tool only while this is `undefined`, and a call otherwise is refused with this reason before
9887
+ * `run`. Absent means whenever its widget is open; an empty string or a throw counts as
9888
+ * unavailable, with a generic reason. The tool stays declared either way, so the cached prefix
9889
+ * never changes.
9890
+ *
9891
+ * @example
9892
+ * ```ts
9893
+ * unavailable: (c) => (c.code ? undefined : 'No code has been generated yet.'),
9894
+ * ```
9895
+ */
9896
+ unavailable?(controller: TController): string | undefined;
9897
+ /**
9898
+ * Read what was asked from the open widget's controller, and return it: JSON, or text. Reads
9899
+ * only — it must never settle or change the widget; anything that does goes through a
9900
+ * `widget_act` action, under the claimant's hold. A throw is reported to the model as the reason
9901
+ * the read failed.
9902
+ *
9903
+ * What it returns is capped at about 20,000 characters, cut with a note telling the model to ask
9904
+ * for less, so page anything that can grow (an `offset`, a `limit`).
9905
+ */
9906
+ run(controller: TController, args: TArgs): unknown | Promise<unknown>;
9907
+ }
9908
+
9167
9909
  /**
9168
9910
  * A stored diagnostics stream with its `meta-snapshot`s replaced by `fresh` — what to
9169
9911
  * pass {@link assembleDebugLog} when reassembling a persisted stream for export.