@adapttable/ai-react 0.2.9 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @adapttable/ai-react
2
2
 
3
+ ## 0.2.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [42a4349]
8
+ - Updated dependencies [42a4349]
9
+ - Updated dependencies [42a4349]
10
+ - @adapttable/ai@0.5.1
11
+ - @adapttable/core@3.8.0
12
+ - @adapttable/react@1.5.0
13
+
14
+ ## 0.2.10
15
+
16
+ ### Patch Changes
17
+
18
+ - d6e065c: Core owns the rest of what a second binding would otherwise copy from React. `@adapttable/core/binding` gains the state shapes the binding hooks return (`SelectionState`, `GridFocusState`, `TreeExpansionState`, `RowPinningState`, the URL-state results, `UseTableDataResult` and others), the `DENSITY_STATE` and `ROW_REORDER` keys with their state types, and the column-default and same-rows helpers (`resolveColumnDefaults`, `resolveColumnHeaders`, `columnPathText`, `sameRows`). `@adapttable/core` gains the column menu's drag-and-drop rules and state (`createColumnDragController`, `startColumnDrag`, `acceptColumnDrag`, `dropColumn`, `columnReorderKeyDown`), and `@adapttable/core/formula` the formula URL-state result. `@adapttable/ai` owns `TABLE_AGENT_STATE`.
19
+
20
+ `@adapttable/react`, `@adapttable/ai-react` and `@adapttable/angular` re-export or call these under their existing names; their public APIs and behaviour are unchanged.
21
+ - Updated dependencies [d6e065c]
22
+ - Updated dependencies [643545d]
23
+ - Updated dependencies [ed815b3]
24
+ - Updated dependencies [96e5cc0]
25
+ - @adapttable/core@3.7.0
26
+ - @adapttable/ai@0.5.0
27
+ - @adapttable/react@1.4.0
28
+
3
29
  ## 0.2.9
4
30
 
5
31
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -132,12 +132,6 @@ function inputsOf(options, approval, alwaysAllow, viewState, progress) {
132
132
  * controller's inputs current, re-renders on its snapshot and the table's
133
133
  * changes, and publishes what the controller holds as feature state.
134
134
  */
135
- /**
136
- * Feature-state key for the live {@link AgentSession}.
137
- *
138
- * @public
139
- */
140
- const TABLE_AGENT_STATE = (0, _adapttable_react_adapter.featureStateKey)("table-agent");
141
135
  function TableAgentProvider({ feature, children }) {
142
136
  const options = feature.options;
143
137
  const runtime = (0, _adapttable_react_adapter.useTableRuntime)();
@@ -175,7 +169,7 @@ function TableAgentProvider({ feature, children }) {
175
169
  }, [controller]);
176
170
  const session = state.session;
177
171
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_adapttable_react_adapter.FeatureStateScope, {
178
- stateKey: TABLE_AGENT_STATE,
172
+ stateKey: _adapttable_ai.TABLE_AGENT_STATE,
179
173
  value: {
180
174
  catalog: () => session.catalog(),
181
175
  describe: (key) => session.describe(key),
@@ -280,7 +274,7 @@ function useSpeechInput(options) {
280
274
  };
281
275
  }
282
276
  //#endregion
283
- exports.TABLE_AGENT_STATE = TABLE_AGENT_STATE;
277
+ exports.TABLE_AGENT_STATE = _adapttable_ai.TABLE_AGENT_STATE;
284
278
  exports.tableAgent = tableAgent;
285
279
  exports.useSpeechInput = useSpeechInput;
286
280
  exports.useTableAssistant = useTableAssistant;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["useState","useFeatureState","AGENT_APPROVAL_STATE","AGENT_ALWAYS_ALLOW_STATE","AGENT_VIEW_STATE","AGENT_PROGRESS_STATE","useRef","createTableAssistant","useSyncExternalStore","useCallback","featureStateKey","useTableRuntime","useRef","useState","createTableAgentController","flushSync","useCallback","useSyncExternalStore","FeatureStateScope","AGENT_APPROVAL_STATE","AGENT_ALWAYS_ALLOW_STATE","AGENT_VIEW_STATE","AGENT_PROGRESS_STATE","useRef","createSpeechInput","readRememberedLanguage","useSyncExternalStore"],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"sourcesContent":["/**\n * `@adapttable/ai-react` — the conversation lifecycle, without a UI.\n *\n * This entry owns state and nothing else: no markup, no launcher, no\n * provider client. A host renders its own panel from what the hook returns,\n * and the shipped widget is written against these same public values — which\n * is the only way to be sure it is not required.\n *\n * The rules that shape it:\n *\n * - **One send at a time**, reserved before any await. Two sends racing would\n * interleave two turns' actions against one table.\n * - **A draft survives failure.** Losing what someone typed because a\n * backend was down is worse than the outage.\n * - **A cancelled send is not a cancelled action.** Aborting before the\n * transport answers is clean; aborting after actions began is reported for\n * what it is, and nothing is retried — a mutation whose outcome is unknown\n * is never sent twice.\n * - **A late reply is dropped.** A turn that was stopped, or that belonged\n * to a previous table, never writes into the transcript.\n */\n\"use client\";\n\nimport {\n type AgentContextInputs,\n type AgentSession,\n type AlwaysAllowedState,\n type AssistantAllowance,\n type AssistantAudio,\n type AssistantInterruption,\n type AssistantMessage,\n type AssistantResumeHandle,\n type AssistantStatus,\n type AssistantSuggestion,\n type AssistantTransport,\n createTableAssistant,\n} from \"@adapttable/ai\";\nimport {\n AGENT_ALWAYS_ALLOW_STATE,\n AGENT_APPROVAL_STATE,\n AGENT_PROGRESS_STATE,\n AGENT_VIEW_STATE,\n type AgentAlwaysAllowState,\n type AgentApprovalPending,\n type AgentProgress,\n type AgentViewState,\n useFeatureState,\n} from \"@adapttable/react/adapter\";\nimport {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\n\n// The hook's own options and state name these, so the entry that publishes\n// the hook publishes them too — a consumer typing a variable from it should\n// not have to reach into another entry point for the pieces.\nexport type {\n ApprovalPolicy,\n AssistantReceiptStatus,\n AssistantReceiptSubject,\n CommitPolicy,\n RowAddressScope,\n WritePolicy,\n} from \"@adapttable/ai\";\nexport type {\n AssistantInterruption,\n AssistantMessage,\n AssistantResumeHandle,\n AssistantStatus,\n AssistantTransport,\n};\nexport type {\n AssistantExchange,\n AssistantQuestion,\n AssistantReceipt,\n AssistantTransportReply,\n AssistantTurnStatus,\n} from \"@adapttable/ai\";\nexport type { AssistantUndoOffer } from \"@adapttable/ai\";\n\n/** How {@link useTableAssistant} is configured. @public */\nexport interface TableAssistantOptions {\n /** The live session. Changing it starts a new conversation. */\n readonly session: AgentSession | undefined;\n /**\n * Where a turn goes. Omit and the assistant stays disconnected.\n *\n * May be a fresh object every render — the controller reads the latest one\n * rather than reconnecting on its identity, so a host is not forced to\n * memoize it.\n */\n readonly transport?: AssistantTransport;\n /**\n * Changes when the transport should be re-established.\n *\n * The conversation resets on a new session, because that is a new table.\n * Swapping one transport for another — a backend for a scripted one — is\n * not visible in the object identity, so a host that does it names the\n * change here. A backend transport must never quietly become a simulated\n * one under the same key.\n */\n readonly transportKey?: string;\n /** Everything authored, filtered live against what the table offers. */\n readonly suggestions?: readonly AssistantSuggestion[];\n /** Controlled panel state. Omit for uncontrolled. */\n readonly open?: boolean;\n /** Called on every open/close request, controlled or not. */\n readonly onOpenChange?: (open: boolean) => void;\n /**\n * Whether a write from this conversation is waiting on a human.\n *\n * `execute` does not return while an approval is open, so the turn looks\n * like thinking from in here. A host that renders the approval — or wires\n * `bridge.approvals` — passes it back so the panel can say what is\n * actually happening. The turn is still in flight and still stoppable.\n */\n readonly awaitingApproval?: boolean;\n /**\n * What the reader has waved through, when the panel is mounted outside the\n * table.\n *\n * A panel inside the table reads this from feature state and needs nothing\n * here. One beside it cannot, so a host wires `bridge.alwaysAllowed` and\n * passes what it publishes — the same arrangement `bridge.approvals` and\n * `bridge.viewInputs` already have. Without it a reader can wave a\n * capability through and have no way to take it back.\n */\n readonly alwaysAllow?: AlwaysAllowedState;\n /**\n * Live view and filter data the manifest does not carry.\n *\n * Read when a turn starts and again when it settles, so per-turn undo can\n * tell what the turn moved. A function rather than a value: a fixed object\n * would report that nothing changed.\n */\n readonly contextInputs?: () => AgentContextInputs;\n /**\n * Work that outlived its connection, handed over the moment it does.\n *\n * Durable recovery starts here and ends outside this package: a host that\n * stores the handle where it survives a reload can offer a resume when the\n * reader comes back, and a host that does nothing loses the work with the\n * page.\n */\n readonly onDetach?: (handle: AssistantResumeHandle) => void;\n /** A handle kept from a previous page, to resume into this one. */\n readonly resumeHandle?: AssistantResumeHandle;\n /**\n * The transcript, when your app owns it.\n *\n * Omit it and the conversation lives in the controller. Supply it to load\n * the last conversation from your own API, append a message that arrived on\n * a socket, or keep it where it survives a reload — pass a new array and the\n * panel shows it. Pair it with `onMessagesChange`.\n */\n readonly messages?: readonly AssistantMessage[];\n /** Told whenever the transcript changes, with the whole of it. */\n readonly onMessagesChange?: (messages: readonly AssistantMessage[]) => void;\n /**\n * How much of the conversation travels with each turn.\n *\n * `\"full\"` (default) sends every earlier message, for a backend that\n * remembers nothing. A number sends that many of the most recent. `0` sends\n * none — the reader's message still travels, and a backend holding its own\n * session supplies the rest. What the reader sees is never trimmed.\n */\n readonly conversation?: \"full\" | number;\n}\n\n/** What a host renders from. @public */\nexport interface TableAssistantState {\n readonly status: AssistantStatus;\n /**\n * Whether a turn is in flight and can still be stopped.\n *\n * Separate from {@link TableAssistantState.status}: a write parked on a\n * human approval reports `awaiting-approval` but is still running, and\n * Stop still ends it.\n */\n readonly busy: boolean;\n readonly messages: readonly AssistantMessage[];\n readonly draft: string;\n readonly setDraft: (draft: string) => void;\n /** Send the draft, or the given text. Resolves when the turn settles. */\n readonly send: (text?: string) => Promise<void>;\n /**\n * Send a recording as the reader's turn — pass it as `onClip` to\n * backend-mode `useSpeechInput`. The transcript the backend returns becomes\n * the reader's message.\n */\n readonly sendClip: (clip: AssistantAudio) => Promise<void>;\n /** Abort the turn in flight. Safe to call when nothing is in flight. */\n readonly stop: () => void;\n /**\n * Rejoin work a released connection left running.\n *\n * A no-op with nothing to rejoin, which is what `resumable` says.\n */\n readonly resume: () => Promise<void>;\n /**\n * What became of the last turn, when no reply ended it.\n *\n * `\"stopped\"` is the reader's own decision; `\"detached\"` is a released\n * connection, where the work may still be running.\n */\n readonly interrupted: AssistantInterruption | undefined;\n /** The work `resume` would rejoin, or nothing. */\n readonly resumable: AssistantResumeHandle | undefined;\n /** Drop the transcript. Refuses while a turn is in flight. */\n readonly clear: () => void;\n /**\n * A write waiting on the reader, or nothing.\n *\n * Hand it to the panel as `approval` and the conversation reviews it —\n * which is where a write asked for in the conversation belongs. The panel\n * draws it only when the approval's presentation names the widget, so\n * passing it costs nothing on a table reviewing elsewhere.\n */\n readonly approval: AgentApprovalPending | null;\n /**\n * How far the capability now running has got, or nothing.\n *\n * Published by the table while a long call works through its rows. It never\n * becomes the receipt: when the turn settles this goes and the receipts say\n * what happened.\n */\n readonly progress: AgentProgress | null;\n /** Answer the pending question and let the turn continue. */\n readonly answer: (answer: { optionId?: string; text?: string }) => void;\n /**\n * Whether the last turn that moved the table can still be put back.\n *\n * Null when no turn moved it. Re-read every render, because the offer ends\n * the moment anything else changes the view. `blockedCode` is a token the\n * labels translate — the panel never shows a reader a code.\n */\n readonly undo: {\n readonly messageId: string;\n readonly available: boolean;\n readonly blockedCode?: string;\n } | null;\n /** Put that turn back. A no-op once the offer has expired. */\n readonly undoTurn: () => Promise<void>;\n /** Put one action of the last turn back, by its receipt's replay identity. */\n readonly undoAction: (idempotencyKey: string) => Promise<void>;\n /** What the reader said not to ask about again, each with its own name. */\n readonly alwaysAllowed: readonly AssistantAllowance[];\n /** Ask about one of them again from now on. */\n readonly revokeAlwaysAllow: (capability: string) => void;\n /** The suggestions this table can run right now, re-checked every render. */\n readonly suggestions: readonly AssistantSuggestion[];\n /** Send a suggestion's prompt as if the reader had typed it. */\n readonly runSuggestion: (id: string) => Promise<void>;\n readonly open: boolean;\n readonly setOpen: (open: boolean) => void;\n /** The last failure, cleared by the next successful turn. */\n readonly error: string | undefined;\n /**\n * The machine code behind {@link error}, when a turn ended with work\n * pending. A surface with labels turns it into a sentence for the reader;\n * the message beside it is written for whoever is debugging the turn.\n */\n readonly errorCode: string | undefined;\n}\n\n/**\n * Run a table assistant.\n *\n * A thin subscriber to the neutral controller in `@adapttable/ai/assistant`:\n * React supplies the external-store mechanism, the live inputs and the\n * controlled presentation state, and owns none of the lifecycle.\n *\n * @param options - Session, transport and presentation.\n * @returns Everything a panel needs, and nothing about how it looks.\n *\n * @public\n */\nexport function useTableAssistant(\n options: TableAssistantOptions\n): TableAssistantState {\n const { onOpenChange } = options;\n const [uncontrolledOpen, setUncontrolledOpen] = useState(false);\n // The live approval, so a host wires the panel with one prop rather than\n // reaching for feature state itself.\n const approval = useFeatureState(AGENT_APPROVAL_STATE);\n // What the reader has waved through, published by the binding whether or\n // not an approval is open.\n const alwaysAllow = useFeatureState(AGENT_ALWAYS_ALLOW_STATE);\n // The table's own live view, published by `tableAgent`. A host that drives\n // the panel from state of its own passes `contextInputs` and this is unused.\n const viewState = useFeatureState(AGENT_VIEW_STATE);\n // How far a running capability has got, for the same reason: a panel inside\n // the table needs no host wiring to say what the work is doing.\n const progress = useFeatureState(AGENT_PROGRESS_STATE);\n\n // Created once, inert until the mount effect connects it. Constructing a\n // store during render must not open a connection — a render can be thrown\n // away, and Strict Mode throws the first one away on purpose.\n const storeRef = useRef<ReturnType<typeof createTableAssistant> | null>(null);\n storeRef.current ??= createTableAssistant(\n inputsOf(options, approval, alwaysAllow, viewState, progress)\n );\n const store = storeRef.current;\n\n // Live inputs, every render. The store decides what a change means: a new\n // session resets the conversation, a new transport key reconnects, and an\n // updated catalog or a newly arrived approval does neither.\n useEffect(() => {\n store.update(inputsOf(options, approval, alwaysAllow, viewState, progress));\n });\n\n useEffect(() => {\n store.connect();\n return () => {\n store.dispose();\n // A disposed store is never reused. Strict Mode's second setup, and any\n // later remount, builds a fresh one rather than reviving one that has\n // already released its connection.\n storeRef.current = null;\n };\n // Mount and unmount only: every other change reaches the store through\n // `update` above, which is what keeps connection effects out of render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const state = useSyncExternalStore(\n store.subscribe,\n store.getState,\n store.getState\n );\n\n const open = options.open ?? uncontrolledOpen;\n const setOpen = useCallback(\n (next: boolean) => {\n if (options.open === undefined) setUncontrolledOpen(next);\n onOpenChange?.(next);\n },\n [options.open, onOpenChange]\n );\n\n return {\n messages: state.messages,\n draft: state.draft,\n setDraft: store.setDraft,\n send: store.send,\n sendClip: store.sendClip,\n stop: store.stop,\n resume: store.resume,\n interrupted: state.interrupted,\n resumable: state.resumable,\n clear: store.clear,\n status: state.status,\n busy: state.busy,\n approval: approval ?? null,\n progress: state.progress,\n answer: store.answer,\n undo: state.undo\n ? {\n messageId: state.undo.messageId,\n available: state.undo.available,\n ...(state.undo.blocked\n ? { blockedCode: state.undo.blocked.code }\n : {}),\n }\n : null,\n undoTurn: store.undoTurn,\n undoAction: store.undoAction,\n alwaysAllowed: state.alwaysAllowed,\n revokeAlwaysAllow: store.revokeAlwaysAllow,\n suggestions: state.suggestions,\n runSuggestion: store.runSuggestion,\n open,\n setOpen,\n error: state.error,\n errorCode: state.errorCode,\n };\n}\n\n/** The hook's options as the store's live inputs. A projection, not a decision. */\nfunction inputsOf(\n options: TableAssistantOptions,\n approval: AgentApprovalPending | null | undefined,\n alwaysAllow: AgentAlwaysAllowState | null | undefined,\n viewState: AgentViewState | null | undefined,\n progress: AgentProgress | null | undefined\n) {\n // The host's own reader wins; otherwise the table's, which is what makes\n // per-turn undo work without a host lifting page and sort into its state.\n const contextInputs =\n options.contextInputs ??\n (viewState ? () => viewState.read() as AgentContextInputs : undefined);\n return {\n session: options.session,\n transport: options.transport,\n transportKey: options.transportKey,\n suggestions: options.suggestions,\n awaitingApproval: options.awaitingApproval,\n approval: approval ?? null,\n progress: progress ?? null,\n ...(contextInputs ? { contextInputs } : {}),\n ...(options.onDetach ? { onDetach: options.onDetach } : {}),\n ...(options.messages ? { messages: options.messages } : {}),\n ...(options.onMessagesChange\n ? { onMessagesChange: options.onMessagesChange }\n : {}),\n ...(options.conversation === undefined\n ? {}\n : { conversation: options.conversation }),\n ...(options.resumeHandle ? { resumeHandle: options.resumeHandle } : {}),\n // The host's own wins, for the same reason `contextInputs` does: a panel\n // beside the table has no feature state to read.\n ...((options.alwaysAllow ?? alwaysAllow)\n ? {\n alwaysAllowed: (options.alwaysAllow ?? alwaysAllow)?.capabilities,\n onRevokeAlwaysAllow: (options.alwaysAllow ?? alwaysAllow)?.revoke,\n }\n : {}),\n };\n}\n","/**\n * Opt-in table feature — `@adapttable/ai-react`.\n *\n * `@adapttable/ai` stays React-free. This package mounts a provider that\n * drives `@adapttable/ai`'s table agent controller from React: it keeps the\n * controller's inputs current, re-renders on its snapshot and the table's\n * changes, and publishes what the controller holds as feature state.\n */\nimport {\n type AgentSession,\n createTableAgentController,\n type TableAgentBridge as NeutralBridge,\n type TableAgentController,\n type TableAgentControllerOptions,\n} from \"@adapttable/ai\";\nimport {\n AGENT_ALWAYS_ALLOW_STATE,\n AGENT_APPROVAL_STATE,\n AGENT_PROGRESS_STATE,\n AGENT_VIEW_STATE,\n type AgentApprovalPending,\n type FeatureProviderProps,\n featureStateKey,\n FeatureStateScope,\n type StaticTableFeature,\n useTableRuntime,\n} from \"@adapttable/react/adapter\";\nimport {\n type ReactNode,\n useCallback,\n useDebugValue,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\n\nexport type { SharedApproval, TableAgentColumnPatch } from \"@adapttable/ai\";\n\n// The bridge contract is `@adapttable/ai`'s — a manifest, a session and a\n// pending approval are what any binding publishes, none of it React. Named\n// here with this binding's own pending shape so every existing import keeps\n// working.\nexport type TableAgentBridge = NeutralBridge<AgentApprovalPending>;\n\n/**\n * Feature-state key for the live {@link AgentSession}.\n *\n * @public\n */\nexport const TABLE_AGENT_STATE = featureStateKey<AgentSession>(\"table-agent\");\n\n/**\n * Options for {@link tableAgent}.\n *\n * The same options `@adapttable/ai`'s table agent controller takes: the\n * runtime half — identity, policy, columns, the host's callbacks and\n * capabilities — plus where updates are published and whether the table is\n * offered to a browser-resident agent.\n *\n * @public\n */\nexport type TableAgentOptions = TableAgentControllerOptions;\n\ninterface TableAgentFeature extends StaticTableFeature {\n readonly options: TableAgentOptions;\n}\n\nfunction TableAgentProvider({\n feature,\n children,\n}: Readonly<FeatureProviderProps>): ReactNode {\n const options = (feature as TableAgentFeature).options;\n const runtime = useTableRuntime();\n const optionsRef = useRef(options);\n optionsRef.current = options;\n const runtimeRef = useRef(runtime);\n runtimeRef.current = runtime;\n // A concrete provider update, rather than an empty `flushSync`, makes React\n // finish controlled-state work already queued by the reader before the\n // session takes its admission snapshot.\n const [admissionTick, setAdmissionTick] = useState(0);\n const flushAdmission = useRef<() => void>(() => undefined);\n flushAdmission.current = () => {\n flushSync(() => {\n setAdmissionTick(admissionTick + 1);\n });\n };\n\n // Built once and never during a render that is thrown away twice: the\n // controller opens nothing until `sync`, which only an effect calls.\n const controllerRef = useRef<TableAgentController | null>(null);\n controllerRef.current ??= createTableAgentController({\n options: optionsRef,\n runtime: runtimeRef,\n flushAdmission: () => {\n flushAdmission.current();\n },\n flush: flushSync,\n });\n const controller = controllerRef.current;\n\n // The table as a store: subscribe where there is one to subscribe to, and\n // read the stamp on every render either way. React re-reads the stamp after\n // it attaches, so a table that moved between the render and the\n // subscription is caught rather than missed. The value is not rendered;\n // re-rendering is the point, because that republishes the manifest.\n const neutralTable = runtime.view()?.neutralTable;\n // The controller subscribes to the table current at the call, so a\n // replaced table is a new subscription.\n const subscribeToTable = useCallback(\n (onStoreChange: () => void) =>\n neutralTable ? controller.subscribeTable(onStoreChange) : () => undefined,\n [controller, neutralTable]\n );\n const stamp = useSyncExternalStore(\n subscribeToTable,\n controller.tableStamp,\n controller.tableStamp\n );\n useDebugValue(stamp);\n\n const state = useSyncExternalStore(\n controller.subscribe,\n controller.getState,\n controller.getState\n );\n\n // Every commit: the controller decides what changed and tells only those\n // who need telling. A layout effect, so a host reading the manifest in its\n // own effects already has this render's.\n useLayoutEffect(() => {\n controller.sync();\n });\n\n // Going away is a close. Strict Mode's setup/cleanup/setup lands here too:\n // the cleanup releases everything, and the next sync sets it up again.\n useEffect(\n () => () => {\n controller.disconnect();\n },\n [controller]\n );\n\n // A new value every render on purpose. The table publishes its runtime\n // while its children render, after this provider has, so a surface below\n // learns what the session now offers only by re-rendering with it — and it\n // re-renders because the value it holds is a different one.\n const session = state.session;\n const published: AgentSession = {\n catalog: () => session.catalog(),\n describe: (key) => session.describe(key),\n execute: (key, args, expectedRevision, idempotencyKey, signal) =>\n session.execute(key, args, expectedRevision, idempotencyKey, signal),\n manifest: () => session.manifest(),\n };\n\n return (\n <FeatureStateScope stateKey={TABLE_AGENT_STATE} value={published}>\n <FeatureStateScope stateKey={AGENT_APPROVAL_STATE} value={state.approval}>\n <FeatureStateScope\n stateKey={AGENT_ALWAYS_ALLOW_STATE}\n value={state.alwaysAllow}\n >\n <FeatureStateScope stateKey={AGENT_VIEW_STATE} value={state.view}>\n <FeatureStateScope\n stateKey={AGENT_PROGRESS_STATE}\n value={state.progress}\n >\n {children}\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n );\n}\n\n/**\n * Observe a live table and publish a deterministic capability manifest.\n *\n * Omitting this feature from `features` ships no agent bytes.\n *\n * @public\n */\nexport function tableAgent(options: TableAgentOptions): StaticTableFeature {\n const feature: TableAgentFeature = {\n id: \"table-agent\",\n options,\n provider: { Provider: TableAgentProvider },\n };\n return feature;\n}\n","/**\n * Dictation, as a React hook — `@adapttable/ai-react`.\n *\n * Thin on purpose. The controller in `@adapttable/ai/voice` owns the browser\n * APIs, the permission states and the language choice; this subscribes to it,\n * keeps it alive for the life of the composer, and writes what it hears\n * through the caller's `setDraft` — which is the one channel voice is allowed\n * to use, so a spoken sentence becomes a draft the reader can see and fix\n * rather than a request the table has already acted on.\n *\n * It lives here rather than in `@adapttable/react` because it imports\n * `@adapttable/ai`, and that package must stay out of the base graph. The\n * chrome takes `SpeechInputHandle` — the structural shape this returns —\n * from `@adapttable/react/adapter`, which declares it without importing\n * anything.\n */\n\"use client\";\n\nimport {\n createSpeechInput,\n readRememberedLanguage,\n rememberLanguage,\n type SpeechClip,\n type SpeechInput,\n type SpeechState,\n type VoiceOptions,\n} from \"@adapttable/ai/voice\";\nimport type { SpeechInputHandle } from \"@adapttable/react/adapter\";\nimport { useEffect, useRef, useSyncExternalStore } from \"react\";\n\n/** How the hook is configured. @public */\nexport interface UseSpeechInputOptions {\n readonly voice?: VoiceOptions;\n /** The table's locale, used when no language list was given. */\n readonly locale?: string;\n /** Where heard text goes. Always the draft, never a send. */\n readonly setDraft: (text: string) => void;\n /** Where a recording goes, in backend mode. */\n readonly onClip?: (clip: SpeechClip) => void;\n}\n\nconst IDLE: SpeechState = { status: \"unsupported\", language: \"\", interim: \"\" };\n\n/**\n * Run dictation for one composer.\n *\n * @param options - Voice configuration and where heard text should go.\n * @returns What the composer needs, or an unavailable handle when voice is off.\n *\n * @public\n */\nexport function useSpeechInput(\n options: UseSpeechInputOptions\n): SpeechInputHandle {\n const { voice, locale, setDraft, onClip } = options;\n // Live callbacks, so the controller is built once and still calls whatever\n // the latest render passed rather than what the first one did.\n const draftRef = useRef(setDraft);\n draftRef.current = setDraft;\n const clipRef = useRef(onClip);\n clipRef.current = onClip;\n\n const languages = voice?.languages?.length\n ? voice.languages\n : [locale ?? \"en-US\"];\n const inputRef = useRef<SpeechInput | null>(null);\n if (voice && !inputRef.current) {\n inputRef.current = createSpeechInput({\n mode: voice.mode ?? \"browser\",\n languages,\n // Remembered from a previous visit when the browser kept it, and the\n // first offered language otherwise.\n ...(readRememberedLanguage()\n ? { initialLanguage: readRememberedLanguage() }\n : {}),\n onDraft: (text) => draftRef.current(text),\n onClip: (clip) => clipRef.current?.(clip),\n });\n }\n const input = inputRef.current;\n\n useEffect(\n () => () => {\n input?.dispose();\n // A disposed controller is never revived: a remount builds a fresh one,\n // the way the assistant store does.\n inputRef.current = null;\n },\n [input]\n );\n\n const state = useSyncExternalStore(\n (listener) => input?.subscribe(listener) ?? (() => undefined),\n () => input?.getState() ?? IDLE,\n () => IDLE\n );\n\n return {\n // Absent rather than dead: a mic that cannot listen is not drawn.\n available: Boolean(voice && input?.supported()),\n state,\n languages,\n start: () => input?.start(),\n stop: () => input?.stop(),\n set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MAAM,YAAA,GAAWC,MAAAA,OAAAA,CAAO,QAAQ;CAChC,SAAS,UAAU;CACnB,MAAM,WAAA,GAAUA,MAAAA,OAAAA,CAAO,MAAM;CAC7B,QAAQ,UAAU;CAElB,MAAM,YAAY,OAAO,WAAW,SAChC,MAAM,YACN,CAAC,UAAU,OAAO;CACtB,MAAM,YAAA,GAAWA,MAAAA,OAAAA,CAA2B,IAAI;CAChD,IAAI,SAAS,CAAC,SAAS,SACrB,SAAS,WAAA,GAAUC,qBAAAA,kBAAAA,CAAkB;EACnC,MAAM,MAAM,QAAQ;EACpB;EAGA,IAAA,GAAIC,qBAAAA,uBAAAA,CAAuB,IACvB,EAAE,kBAAA,GAAiBA,qBAAAA,uBAAAA,CAAuB,EAAE,IAC5C,CAAC;EACL,UAAU,SAAS,SAAS,QAAQ,IAAI;EACxC,SAAS,SAAS,QAAQ,UAAU,IAAI;CAC1C,CAAC;CAEH,MAAM,QAAQ,SAAS;CAEvB,CAAA,GAAA,MAAA,UAAA,aACc;EACV,OAAO,QAAQ;EAGf,SAAS,UAAU;CACrB,GACA,CAAC,KAAK,CACR;CAEA,MAAM,SAAA,GAAQC,MAAAA,qBAAAA,EACX,aAAa,OAAO,UAAU,QAAQ,YAAY,KAAA,UAC7C,OAAO,SAAS,KAAK,YACrB,IACR;CAEA,OAAO;EAEL,WAAW,QAAQ,SAAS,OAAO,UAAU,CAAC;EAC9C;EACA;EACA,aAAa,OAAO,MAAM;EAC1B,YAAY,OAAO,KAAK;EACxB,cAAc,aAAa;GACzB,OAAO,YAAY,QAAQ;GAC3B,CAAA,GAAA,qBAAA,iBAAA,CAAiB,QAAQ;EAC3B;CACF;AACF"}
1
+ {"version":3,"file":"index.cjs","names":["useState","useFeatureState","AGENT_APPROVAL_STATE","AGENT_ALWAYS_ALLOW_STATE","AGENT_VIEW_STATE","AGENT_PROGRESS_STATE","useRef","createTableAssistant","useSyncExternalStore","useCallback","useTableRuntime","useRef","useState","createTableAgentController","flushSync","useCallback","useSyncExternalStore","FeatureStateScope","TABLE_AGENT_STATE","AGENT_APPROVAL_STATE","AGENT_ALWAYS_ALLOW_STATE","AGENT_VIEW_STATE","AGENT_PROGRESS_STATE","useRef","createSpeechInput","readRememberedLanguage","useSyncExternalStore"],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"sourcesContent":["/**\n * `@adapttable/ai-react` — the conversation lifecycle, without a UI.\n *\n * This entry owns state and nothing else: no markup, no launcher, no\n * provider client. A host renders its own panel from what the hook returns,\n * and the shipped widget is written against these same public values — which\n * is the only way to be sure it is not required.\n *\n * The rules that shape it:\n *\n * - **One send at a time**, reserved before any await. Two sends racing would\n * interleave two turns' actions against one table.\n * - **A draft survives failure.** Losing what someone typed because a\n * backend was down is worse than the outage.\n * - **A cancelled send is not a cancelled action.** Aborting before the\n * transport answers is clean; aborting after actions began is reported for\n * what it is, and nothing is retried — a mutation whose outcome is unknown\n * is never sent twice.\n * - **A late reply is dropped.** A turn that was stopped, or that belonged\n * to a previous table, never writes into the transcript.\n */\n\"use client\";\n\nimport {\n type AgentContextInputs,\n type AgentSession,\n type AlwaysAllowedState,\n type AssistantAllowance,\n type AssistantAudio,\n type AssistantInterruption,\n type AssistantMessage,\n type AssistantResumeHandle,\n type AssistantStatus,\n type AssistantSuggestion,\n type AssistantTransport,\n createTableAssistant,\n} from \"@adapttable/ai\";\nimport {\n AGENT_ALWAYS_ALLOW_STATE,\n AGENT_APPROVAL_STATE,\n AGENT_PROGRESS_STATE,\n AGENT_VIEW_STATE,\n type AgentAlwaysAllowState,\n type AgentApprovalPending,\n type AgentProgress,\n type AgentViewState,\n useFeatureState,\n} from \"@adapttable/react/adapter\";\nimport {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\n\n// The hook's own options and state name these, so the entry that publishes\n// the hook publishes them too — a consumer typing a variable from it should\n// not have to reach into another entry point for the pieces.\nexport type {\n ApprovalPolicy,\n AssistantReceiptStatus,\n AssistantReceiptSubject,\n CommitPolicy,\n RowAddressScope,\n WritePolicy,\n} from \"@adapttable/ai\";\nexport type {\n AssistantInterruption,\n AssistantMessage,\n AssistantResumeHandle,\n AssistantStatus,\n AssistantTransport,\n};\nexport type {\n AssistantExchange,\n AssistantQuestion,\n AssistantReceipt,\n AssistantTransportReply,\n AssistantTurnStatus,\n} from \"@adapttable/ai\";\nexport type { AssistantUndoOffer } from \"@adapttable/ai\";\n\n/** How {@link useTableAssistant} is configured. @public */\nexport interface TableAssistantOptions {\n /** The live session. Changing it starts a new conversation. */\n readonly session: AgentSession | undefined;\n /**\n * Where a turn goes. Omit and the assistant stays disconnected.\n *\n * May be a fresh object every render — the controller reads the latest one\n * rather than reconnecting on its identity, so a host is not forced to\n * memoize it.\n */\n readonly transport?: AssistantTransport;\n /**\n * Changes when the transport should be re-established.\n *\n * The conversation resets on a new session, because that is a new table.\n * Swapping one transport for another — a backend for a scripted one — is\n * not visible in the object identity, so a host that does it names the\n * change here. A backend transport must never quietly become a simulated\n * one under the same key.\n */\n readonly transportKey?: string;\n /** Everything authored, filtered live against what the table offers. */\n readonly suggestions?: readonly AssistantSuggestion[];\n /** Controlled panel state. Omit for uncontrolled. */\n readonly open?: boolean;\n /** Called on every open/close request, controlled or not. */\n readonly onOpenChange?: (open: boolean) => void;\n /**\n * Whether a write from this conversation is waiting on a human.\n *\n * `execute` does not return while an approval is open, so the turn looks\n * like thinking from in here. A host that renders the approval — or wires\n * `bridge.approvals` — passes it back so the panel can say what is\n * actually happening. The turn is still in flight and still stoppable.\n */\n readonly awaitingApproval?: boolean;\n /**\n * What the reader has waved through, when the panel is mounted outside the\n * table.\n *\n * A panel inside the table reads this from feature state and needs nothing\n * here. One beside it cannot, so a host wires `bridge.alwaysAllowed` and\n * passes what it publishes — the same arrangement `bridge.approvals` and\n * `bridge.viewInputs` already have. Without it a reader can wave a\n * capability through and have no way to take it back.\n */\n readonly alwaysAllow?: AlwaysAllowedState;\n /**\n * Live view and filter data the manifest does not carry.\n *\n * Read when a turn starts and again when it settles, so per-turn undo can\n * tell what the turn moved. A function rather than a value: a fixed object\n * would report that nothing changed.\n */\n readonly contextInputs?: () => AgentContextInputs;\n /**\n * Work that outlived its connection, handed over the moment it does.\n *\n * Durable recovery starts here and ends outside this package: a host that\n * stores the handle where it survives a reload can offer a resume when the\n * reader comes back, and a host that does nothing loses the work with the\n * page.\n */\n readonly onDetach?: (handle: AssistantResumeHandle) => void;\n /** A handle kept from a previous page, to resume into this one. */\n readonly resumeHandle?: AssistantResumeHandle;\n /**\n * The transcript, when your app owns it.\n *\n * Omit it and the conversation lives in the controller. Supply it to load\n * the last conversation from your own API, append a message that arrived on\n * a socket, or keep it where it survives a reload — pass a new array and the\n * panel shows it. Pair it with `onMessagesChange`.\n */\n readonly messages?: readonly AssistantMessage[];\n /** Told whenever the transcript changes, with the whole of it. */\n readonly onMessagesChange?: (messages: readonly AssistantMessage[]) => void;\n /**\n * How much of the conversation travels with each turn.\n *\n * `\"full\"` (default) sends every earlier message, for a backend that\n * remembers nothing. A number sends that many of the most recent. `0` sends\n * none — the reader's message still travels, and a backend holding its own\n * session supplies the rest. What the reader sees is never trimmed.\n */\n readonly conversation?: \"full\" | number;\n}\n\n/** What a host renders from. @public */\nexport interface TableAssistantState {\n readonly status: AssistantStatus;\n /**\n * Whether a turn is in flight and can still be stopped.\n *\n * Separate from {@link TableAssistantState.status}: a write parked on a\n * human approval reports `awaiting-approval` but is still running, and\n * Stop still ends it.\n */\n readonly busy: boolean;\n readonly messages: readonly AssistantMessage[];\n readonly draft: string;\n readonly setDraft: (draft: string) => void;\n /** Send the draft, or the given text. Resolves when the turn settles. */\n readonly send: (text?: string) => Promise<void>;\n /**\n * Send a recording as the reader's turn — pass it as `onClip` to\n * backend-mode `useSpeechInput`. The transcript the backend returns becomes\n * the reader's message.\n */\n readonly sendClip: (clip: AssistantAudio) => Promise<void>;\n /** Abort the turn in flight. Safe to call when nothing is in flight. */\n readonly stop: () => void;\n /**\n * Rejoin work a released connection left running.\n *\n * A no-op with nothing to rejoin, which is what `resumable` says.\n */\n readonly resume: () => Promise<void>;\n /**\n * What became of the last turn, when no reply ended it.\n *\n * `\"stopped\"` is the reader's own decision; `\"detached\"` is a released\n * connection, where the work may still be running.\n */\n readonly interrupted: AssistantInterruption | undefined;\n /** The work `resume` would rejoin, or nothing. */\n readonly resumable: AssistantResumeHandle | undefined;\n /** Drop the transcript. Refuses while a turn is in flight. */\n readonly clear: () => void;\n /**\n * A write waiting on the reader, or nothing.\n *\n * Hand it to the panel as `approval` and the conversation reviews it —\n * which is where a write asked for in the conversation belongs. The panel\n * draws it only when the approval's presentation names the widget, so\n * passing it costs nothing on a table reviewing elsewhere.\n */\n readonly approval: AgentApprovalPending | null;\n /**\n * How far the capability now running has got, or nothing.\n *\n * Published by the table while a long call works through its rows. It never\n * becomes the receipt: when the turn settles this goes and the receipts say\n * what happened.\n */\n readonly progress: AgentProgress | null;\n /** Answer the pending question and let the turn continue. */\n readonly answer: (answer: { optionId?: string; text?: string }) => void;\n /**\n * Whether the last turn that moved the table can still be put back.\n *\n * Null when no turn moved it. Re-read every render, because the offer ends\n * the moment anything else changes the view. `blockedCode` is a token the\n * labels translate — the panel never shows a reader a code.\n */\n readonly undo: {\n readonly messageId: string;\n readonly available: boolean;\n readonly blockedCode?: string;\n } | null;\n /** Put that turn back. A no-op once the offer has expired. */\n readonly undoTurn: () => Promise<void>;\n /** Put one action of the last turn back, by its receipt's replay identity. */\n readonly undoAction: (idempotencyKey: string) => Promise<void>;\n /** What the reader said not to ask about again, each with its own name. */\n readonly alwaysAllowed: readonly AssistantAllowance[];\n /** Ask about one of them again from now on. */\n readonly revokeAlwaysAllow: (capability: string) => void;\n /** The suggestions this table can run right now, re-checked every render. */\n readonly suggestions: readonly AssistantSuggestion[];\n /** Send a suggestion's prompt as if the reader had typed it. */\n readonly runSuggestion: (id: string) => Promise<void>;\n readonly open: boolean;\n readonly setOpen: (open: boolean) => void;\n /** The last failure, cleared by the next successful turn. */\n readonly error: string | undefined;\n /**\n * The machine code behind {@link error}, when a turn ended with work\n * pending. A surface with labels turns it into a sentence for the reader;\n * the message beside it is written for whoever is debugging the turn.\n */\n readonly errorCode: string | undefined;\n}\n\n/**\n * Run a table assistant.\n *\n * A thin subscriber to the neutral controller in `@adapttable/ai/assistant`:\n * React supplies the external-store mechanism, the live inputs and the\n * controlled presentation state, and owns none of the lifecycle.\n *\n * @param options - Session, transport and presentation.\n * @returns Everything a panel needs, and nothing about how it looks.\n *\n * @public\n */\nexport function useTableAssistant(\n options: TableAssistantOptions\n): TableAssistantState {\n const { onOpenChange } = options;\n const [uncontrolledOpen, setUncontrolledOpen] = useState(false);\n // The live approval, so a host wires the panel with one prop rather than\n // reaching for feature state itself.\n const approval = useFeatureState(AGENT_APPROVAL_STATE);\n // What the reader has waved through, published by the binding whether or\n // not an approval is open.\n const alwaysAllow = useFeatureState(AGENT_ALWAYS_ALLOW_STATE);\n // The table's own live view, published by `tableAgent`. A host that drives\n // the panel from state of its own passes `contextInputs` and this is unused.\n const viewState = useFeatureState(AGENT_VIEW_STATE);\n // How far a running capability has got, for the same reason: a panel inside\n // the table needs no host wiring to say what the work is doing.\n const progress = useFeatureState(AGENT_PROGRESS_STATE);\n\n // Created once, inert until the mount effect connects it. Constructing a\n // store during render must not open a connection — a render can be thrown\n // away, and Strict Mode throws the first one away on purpose.\n const storeRef = useRef<ReturnType<typeof createTableAssistant> | null>(null);\n storeRef.current ??= createTableAssistant(\n inputsOf(options, approval, alwaysAllow, viewState, progress)\n );\n const store = storeRef.current;\n\n // Live inputs, every render. The store decides what a change means: a new\n // session resets the conversation, a new transport key reconnects, and an\n // updated catalog or a newly arrived approval does neither.\n useEffect(() => {\n store.update(inputsOf(options, approval, alwaysAllow, viewState, progress));\n });\n\n useEffect(() => {\n store.connect();\n return () => {\n store.dispose();\n // A disposed store is never reused. Strict Mode's second setup, and any\n // later remount, builds a fresh one rather than reviving one that has\n // already released its connection.\n storeRef.current = null;\n };\n // Mount and unmount only: every other change reaches the store through\n // `update` above, which is what keeps connection effects out of render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const state = useSyncExternalStore(\n store.subscribe,\n store.getState,\n store.getState\n );\n\n const open = options.open ?? uncontrolledOpen;\n const setOpen = useCallback(\n (next: boolean) => {\n if (options.open === undefined) setUncontrolledOpen(next);\n onOpenChange?.(next);\n },\n [options.open, onOpenChange]\n );\n\n return {\n messages: state.messages,\n draft: state.draft,\n setDraft: store.setDraft,\n send: store.send,\n sendClip: store.sendClip,\n stop: store.stop,\n resume: store.resume,\n interrupted: state.interrupted,\n resumable: state.resumable,\n clear: store.clear,\n status: state.status,\n busy: state.busy,\n approval: approval ?? null,\n progress: state.progress,\n answer: store.answer,\n undo: state.undo\n ? {\n messageId: state.undo.messageId,\n available: state.undo.available,\n ...(state.undo.blocked\n ? { blockedCode: state.undo.blocked.code }\n : {}),\n }\n : null,\n undoTurn: store.undoTurn,\n undoAction: store.undoAction,\n alwaysAllowed: state.alwaysAllowed,\n revokeAlwaysAllow: store.revokeAlwaysAllow,\n suggestions: state.suggestions,\n runSuggestion: store.runSuggestion,\n open,\n setOpen,\n error: state.error,\n errorCode: state.errorCode,\n };\n}\n\n/** The hook's options as the store's live inputs. A projection, not a decision. */\nfunction inputsOf(\n options: TableAssistantOptions,\n approval: AgentApprovalPending | null | undefined,\n alwaysAllow: AgentAlwaysAllowState | null | undefined,\n viewState: AgentViewState | null | undefined,\n progress: AgentProgress | null | undefined\n) {\n // The host's own reader wins; otherwise the table's, which is what makes\n // per-turn undo work without a host lifting page and sort into its state.\n const contextInputs =\n options.contextInputs ??\n (viewState ? () => viewState.read() as AgentContextInputs : undefined);\n return {\n session: options.session,\n transport: options.transport,\n transportKey: options.transportKey,\n suggestions: options.suggestions,\n awaitingApproval: options.awaitingApproval,\n approval: approval ?? null,\n progress: progress ?? null,\n ...(contextInputs ? { contextInputs } : {}),\n ...(options.onDetach ? { onDetach: options.onDetach } : {}),\n ...(options.messages ? { messages: options.messages } : {}),\n ...(options.onMessagesChange\n ? { onMessagesChange: options.onMessagesChange }\n : {}),\n ...(options.conversation === undefined\n ? {}\n : { conversation: options.conversation }),\n ...(options.resumeHandle ? { resumeHandle: options.resumeHandle } : {}),\n // The host's own wins, for the same reason `contextInputs` does: a panel\n // beside the table has no feature state to read.\n ...((options.alwaysAllow ?? alwaysAllow)\n ? {\n alwaysAllowed: (options.alwaysAllow ?? alwaysAllow)?.capabilities,\n onRevokeAlwaysAllow: (options.alwaysAllow ?? alwaysAllow)?.revoke,\n }\n : {}),\n };\n}\n","/**\n * Opt-in table feature — `@adapttable/ai-react`.\n *\n * `@adapttable/ai` stays React-free. This package mounts a provider that\n * drives `@adapttable/ai`'s table agent controller from React: it keeps the\n * controller's inputs current, re-renders on its snapshot and the table's\n * changes, and publishes what the controller holds as feature state.\n */\nimport {\n type AgentSession,\n createTableAgentController,\n TABLE_AGENT_STATE,\n type TableAgentBridge as NeutralBridge,\n type TableAgentController,\n type TableAgentControllerOptions,\n} from \"@adapttable/ai\";\nimport {\n AGENT_ALWAYS_ALLOW_STATE,\n AGENT_APPROVAL_STATE,\n AGENT_PROGRESS_STATE,\n AGENT_VIEW_STATE,\n type AgentApprovalPending,\n type FeatureProviderProps,\n FeatureStateScope,\n type StaticTableFeature,\n useTableRuntime,\n} from \"@adapttable/react/adapter\";\nimport {\n type ReactNode,\n useCallback,\n useDebugValue,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\n\nexport type { SharedApproval, TableAgentColumnPatch } from \"@adapttable/ai\";\n\n// The bridge contract is `@adapttable/ai`'s — a manifest, a session and a\n// pending approval are what any binding publishes, none of it React. Named\n// here with this binding's own pending shape so every existing import keeps\n// working.\nexport type TableAgentBridge = NeutralBridge<AgentApprovalPending>;\n\n// The live session's key is `@adapttable/ai`'s, so every agent binding\n// publishes and reads the same one.\nexport { TABLE_AGENT_STATE };\n\n/**\n * Options for {@link tableAgent}.\n *\n * The same options `@adapttable/ai`'s table agent controller takes: the\n * runtime half — identity, policy, columns, the host's callbacks and\n * capabilities — plus where updates are published and whether the table is\n * offered to a browser-resident agent.\n *\n * @public\n */\nexport type TableAgentOptions = TableAgentControllerOptions;\n\ninterface TableAgentFeature extends StaticTableFeature {\n readonly options: TableAgentOptions;\n}\n\nfunction TableAgentProvider({\n feature,\n children,\n}: Readonly<FeatureProviderProps>): ReactNode {\n const options = (feature as TableAgentFeature).options;\n const runtime = useTableRuntime();\n const optionsRef = useRef(options);\n optionsRef.current = options;\n const runtimeRef = useRef(runtime);\n runtimeRef.current = runtime;\n // A concrete provider update, rather than an empty `flushSync`, makes React\n // finish controlled-state work already queued by the reader before the\n // session takes its admission snapshot.\n const [admissionTick, setAdmissionTick] = useState(0);\n const flushAdmission = useRef<() => void>(() => undefined);\n flushAdmission.current = () => {\n flushSync(() => {\n setAdmissionTick(admissionTick + 1);\n });\n };\n\n // Built once and never during a render that is thrown away twice: the\n // controller opens nothing until `sync`, which only an effect calls.\n const controllerRef = useRef<TableAgentController | null>(null);\n controllerRef.current ??= createTableAgentController({\n options: optionsRef,\n runtime: runtimeRef,\n flushAdmission: () => {\n flushAdmission.current();\n },\n flush: flushSync,\n });\n const controller = controllerRef.current;\n\n // The table as a store: subscribe where there is one to subscribe to, and\n // read the stamp on every render either way. React re-reads the stamp after\n // it attaches, so a table that moved between the render and the\n // subscription is caught rather than missed. The value is not rendered;\n // re-rendering is the point, because that republishes the manifest.\n const neutralTable = runtime.view()?.neutralTable;\n // The controller subscribes to the table current at the call, so a\n // replaced table is a new subscription.\n const subscribeToTable = useCallback(\n (onStoreChange: () => void) =>\n neutralTable ? controller.subscribeTable(onStoreChange) : () => undefined,\n [controller, neutralTable]\n );\n const stamp = useSyncExternalStore(\n subscribeToTable,\n controller.tableStamp,\n controller.tableStamp\n );\n useDebugValue(stamp);\n\n const state = useSyncExternalStore(\n controller.subscribe,\n controller.getState,\n controller.getState\n );\n\n // Every commit: the controller decides what changed and tells only those\n // who need telling. A layout effect, so a host reading the manifest in its\n // own effects already has this render's.\n useLayoutEffect(() => {\n controller.sync();\n });\n\n // Going away is a close. Strict Mode's setup/cleanup/setup lands here too:\n // the cleanup releases everything, and the next sync sets it up again.\n useEffect(\n () => () => {\n controller.disconnect();\n },\n [controller]\n );\n\n // A new value every render on purpose. The table publishes its runtime\n // while its children render, after this provider has, so a surface below\n // learns what the session now offers only by re-rendering with it — and it\n // re-renders because the value it holds is a different one.\n const session = state.session;\n const published: AgentSession = {\n catalog: () => session.catalog(),\n describe: (key) => session.describe(key),\n execute: (key, args, expectedRevision, idempotencyKey, signal) =>\n session.execute(key, args, expectedRevision, idempotencyKey, signal),\n manifest: () => session.manifest(),\n };\n\n return (\n <FeatureStateScope stateKey={TABLE_AGENT_STATE} value={published}>\n <FeatureStateScope stateKey={AGENT_APPROVAL_STATE} value={state.approval}>\n <FeatureStateScope\n stateKey={AGENT_ALWAYS_ALLOW_STATE}\n value={state.alwaysAllow}\n >\n <FeatureStateScope stateKey={AGENT_VIEW_STATE} value={state.view}>\n <FeatureStateScope\n stateKey={AGENT_PROGRESS_STATE}\n value={state.progress}\n >\n {children}\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n );\n}\n\n/**\n * Observe a live table and publish a deterministic capability manifest.\n *\n * Omitting this feature from `features` ships no agent bytes.\n *\n * @public\n */\nexport function tableAgent(options: TableAgentOptions): StaticTableFeature {\n const feature: TableAgentFeature = {\n id: \"table-agent\",\n options,\n provider: { Provider: TableAgentProvider },\n };\n return feature;\n}\n","/**\n * Dictation, as a React hook — `@adapttable/ai-react`.\n *\n * Thin on purpose. The controller in `@adapttable/ai/voice` owns the browser\n * APIs, the permission states and the language choice; this subscribes to it,\n * keeps it alive for the life of the composer, and writes what it hears\n * through the caller's `setDraft` — which is the one channel voice is allowed\n * to use, so a spoken sentence becomes a draft the reader can see and fix\n * rather than a request the table has already acted on.\n *\n * It lives here rather than in `@adapttable/react` because it imports\n * `@adapttable/ai`, and that package must stay out of the base graph. The\n * chrome takes `SpeechInputHandle` — the structural shape this returns —\n * from `@adapttable/react/adapter`, which declares it without importing\n * anything.\n */\n\"use client\";\n\nimport {\n createSpeechInput,\n readRememberedLanguage,\n rememberLanguage,\n type SpeechClip,\n type SpeechInput,\n type SpeechState,\n type VoiceOptions,\n} from \"@adapttable/ai/voice\";\nimport type { SpeechInputHandle } from \"@adapttable/react/adapter\";\nimport { useEffect, useRef, useSyncExternalStore } from \"react\";\n\n/** How the hook is configured. @public */\nexport interface UseSpeechInputOptions {\n readonly voice?: VoiceOptions;\n /** The table's locale, used when no language list was given. */\n readonly locale?: string;\n /** Where heard text goes. Always the draft, never a send. */\n readonly setDraft: (text: string) => void;\n /** Where a recording goes, in backend mode. */\n readonly onClip?: (clip: SpeechClip) => void;\n}\n\nconst IDLE: SpeechState = { status: \"unsupported\", language: \"\", interim: \"\" };\n\n/**\n * Run dictation for one composer.\n *\n * @param options - Voice configuration and where heard text should go.\n * @returns What the composer needs, or an unavailable handle when voice is off.\n *\n * @public\n */\nexport function useSpeechInput(\n options: UseSpeechInputOptions\n): SpeechInputHandle {\n const { voice, locale, setDraft, onClip } = options;\n // Live callbacks, so the controller is built once and still calls whatever\n // the latest render passed rather than what the first one did.\n const draftRef = useRef(setDraft);\n draftRef.current = setDraft;\n const clipRef = useRef(onClip);\n clipRef.current = onClip;\n\n const languages = voice?.languages?.length\n ? voice.languages\n : [locale ?? \"en-US\"];\n const inputRef = useRef<SpeechInput | null>(null);\n if (voice && !inputRef.current) {\n inputRef.current = createSpeechInput({\n mode: voice.mode ?? \"browser\",\n languages,\n // Remembered from a previous visit when the browser kept it, and the\n // first offered language otherwise.\n ...(readRememberedLanguage()\n ? { initialLanguage: readRememberedLanguage() }\n : {}),\n onDraft: (text) => draftRef.current(text),\n onClip: (clip) => clipRef.current?.(clip),\n });\n }\n const input = inputRef.current;\n\n useEffect(\n () => () => {\n input?.dispose();\n // A disposed controller is never revived: a remount builds a fresh one,\n // the way the assistant store does.\n inputRef.current = null;\n },\n [input]\n );\n\n const state = useSyncExternalStore(\n (listener) => input?.subscribe(listener) ?? (() => undefined),\n () => input?.getState() ?? IDLE,\n () => IDLE\n );\n\n return {\n // Absent rather than dead: a mic that cannot listen is not drawn.\n available: Boolean(voice && input?.supported()),\n state,\n languages,\n start: () => input?.start(),\n stop: () => input?.stop(),\n setLanguage: (language) => {\n input?.setLanguage(language);\n rememberLanguage(language);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwRA,SAAgB,kBACd,SACqB;CACrB,MAAM,EAAE,iBAAiB;CACzB,MAAM,CAAC,kBAAkB,wBAAA,GAAuBA,MAAAA,SAAAA,CAAS,KAAK;CAG9D,MAAM,YAAA,GAAWC,0BAAAA,gBAAAA,CAAgBC,0BAAAA,oBAAoB;CAGrD,MAAM,eAAA,GAAcD,0BAAAA,gBAAAA,CAAgBE,0BAAAA,wBAAwB;CAG5D,MAAM,aAAA,GAAYF,0BAAAA,gBAAAA,CAAgBG,0BAAAA,gBAAgB;CAGlD,MAAM,YAAA,GAAWH,0BAAAA,gBAAAA,CAAgBI,0BAAAA,oBAAoB;CAKrD,MAAM,YAAA,GAAWC,MAAAA,OAAAA,CAAuD,IAAI;CAC5E,SAAS,aAAA,GAAYC,eAAAA,qBAAAA,CACnB,SAAS,SAAS,UAAU,aAAa,WAAW,QAAQ,CAC9D;CACA,MAAM,QAAQ,SAAS;CAKvB,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,OAAO,SAAS,SAAS,UAAU,aAAa,WAAW,QAAQ,CAAC;CAC5E,CAAC;CAED,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,QAAQ;EACd,aAAa;GACX,MAAM,QAAQ;GAId,SAAS,UAAU;EACrB;CAIF,GAAG,CAAC,CAAC;CAEL,MAAM,SAAA,GAAQC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AAiB,QAAQ;EAC3B;CACF;AACF"}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import { AgentContextInputs, AgentSession, AlwaysAllowedState, AssistantAllowance, AssistantAnswer, AssistantAudio, AssistantInterruption, AssistantInterruption as AssistantInterruption$1, AssistantMessage, AssistantQuestion, AssistantResumeHandle, AssistantResumeHandle as AssistantResumeHandle$1, AssistantStatus, AssistantSuggestion, AssistantSuggestion as AssistantSuggestion$1, AssistantTransport, SharedApproval, TableAgentBridge as TableAgentBridge$1, TableAgentColumnPatch, TableAgentControllerOptions, TableAssistantSnapshot, TableAssistantStore } from "@adapttable/ai";
2
+ import { AgentContextInputs, AgentSession, AlwaysAllowedState, AssistantAllowance, AssistantAnswer, AssistantAudio, AssistantInterruption, AssistantInterruption as AssistantInterruption$1, AssistantMessage, AssistantQuestion, AssistantResumeHandle, AssistantResumeHandle as AssistantResumeHandle$1, AssistantStatus, AssistantSuggestion, AssistantSuggestion as AssistantSuggestion$1, AssistantTransport, SharedApproval, TABLE_AGENT_STATE, TableAgentBridge as TableAgentBridge$1, TableAgentColumnPatch, TableAgentControllerOptions, TableAssistantSnapshot, TableAssistantStore } from "@adapttable/ai";
3
3
  import { AgentApprovalPending, AgentProgress, SpeechInputHandle, StaticTableFeature } from "@adapttable/react/adapter";
4
4
  import { SpeechClip, VoiceOptions } from "@adapttable/ai/voice";
5
5
  //#region src/assistant.d.ts
@@ -205,12 +205,6 @@ declare function useTableAssistant(options: TableAssistantOptions): TableAssista
205
205
  //#endregion
206
206
  //#region src/react.d.ts
207
207
  type TableAgentBridge = TableAgentBridge$1<AgentApprovalPending>;
208
- /**
209
- * Feature-state key for the live {@link AgentSession}.
210
- *
211
- * @public
212
- */
213
- declare const TABLE_AGENT_STATE: import("@adapttable/core/binding").FeatureStateKey<AgentSession>;
214
208
  /**
215
209
  * Options for {@link tableAgent}.
216
210
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"mappings":";;;;;;UAoFiB;;WAEN,SAAS;;;;;;;;WAQT,YAAY;;;;;;;;;;WAUZ;;WAEA,uBAAuB;;WAEvB;;WAEA,gBAAgB;;;;;;;;;WAShB;;;;;;;;;;;WAWA,cAAc;;;;;;;;WAQd,sBAAsB;;;;;;;;;WAStB,YAAY,QAAQ;;WAEpB,eAAe;;;;;;;;;WASf,oBAAoB;;WAEpB,oBAAoB,mBAAmB;;;;;;;;;WASvC;;;UAIM;WACN,QAAQ;;;;;;;;WAQR;WACA,mBAAmB;WACnB;WACA,WAAW;;WAEX,OAAO,kBAAkB;;;;;;WAMzB,WAAW,MAAM,mBAAmB;;WAEpC;;;;;;WAMA,cAAc;;;;;;;WAOd,aAAa;;WAEb,WAAW;;WAEX;;;;;;;;;WASA,UAAU;;;;;;;;WAQV,UAAU;;WAEV,SAAS;IAAU;IAAmB;;;;;;;;;WAQtC;aACE;aACA;aACA;;;WAGF,gBAAgB;;WAEhB,aAAa,2BAA2B;;WAExC,wBAAwB;;WAExB,oBAAoB;;WAEpB,sBAAsB;;WAEtB,gBAAgB,eAAe;WAC/B;WACA,UAAU;;WAEV;;;;;;WAMA;;;;;;;;;;;;;;iBAeK,kBACd,SAAS,wBACR;;;KC7OS,mBAAmB,mBAAc;;;;;;cAOhC,sDAAiB,gBAAA;;;;;;;;;;;KAYlB,oBAAoB;;;;;;;;iBA2HhB,WAAW,SAAS,oBAAoB;;;;UC5JvC;WACN,QAAQ;;WAER;;WAEA,WAAW;;WAEX,UAAU,MAAM;;;;;;;;;;iBAaX,eACd,SAAS,wBACR"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"mappings":";;;;;;UAoFiB;;WAEN,SAAS;;;;;;;;WAQT,YAAY;;;;;;;;;;WAUZ;;WAEA,uBAAuB;;WAEvB;;WAEA,gBAAgB;;;;;;;;;WAShB;;;;;;;;;;;WAWA,cAAc;;;;;;;;WAQd,sBAAsB;;;;;;;;;WAStB,YAAY,QAAQ;;WAEpB,eAAe;;;;;;;;;WASf,oBAAoB;;WAEpB,oBAAoB,mBAAmB;;;;;;;;;WASvC;;;UAIM;WACN,QAAQ;;;;;;;;WAQR;WACA,mBAAmB;WACnB;WACA,WAAW;;WAEX,OAAO,kBAAkB;;;;;;WAMzB,WAAW,MAAM,mBAAmB;;WAEpC;;;;;;WAMA,cAAc;;;;;;;WAOd,aAAa;;WAEb,WAAW;;WAEX;;;;;;;;;WASA,UAAU;;;;;;;;WAQV,UAAU;;WAEV,SAAS;IAAU;IAAmB;;;;;;;;;WAQtC;aACE;aACA;aACA;;;WAGF,gBAAgB;;WAEhB,aAAa,2BAA2B;;WAExC,wBAAwB;;WAExB,oBAAoB;;WAEpB,sBAAsB;;WAEtB,gBAAgB,eAAe;WAC/B;WACA,UAAU;;WAEV;;;;;;WAMA;;;;;;;;;;;;;;iBAeK,kBACd,SAAS,wBACR;;;KC7OS,mBAAmB,mBAAc;;;;;;;;;;;KAgBjC,oBAAoB;;;;;;;;iBA2HhB,WAAW,SAAS,oBAAoB;;;;UCzJvC;WACN,QAAQ;;WAER;;WAEA,WAAW;;WAEX,UAAU,MAAM;;;;;;;;;;iBAaX,eACd,SAAS,wBACR"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import { AgentContextInputs, AgentSession, AlwaysAllowedState, AssistantAllowance, AssistantAnswer, AssistantAudio, AssistantInterruption, AssistantInterruption as AssistantInterruption$1, AssistantMessage, AssistantQuestion, AssistantResumeHandle, AssistantResumeHandle as AssistantResumeHandle$1, AssistantStatus, AssistantSuggestion, AssistantSuggestion as AssistantSuggestion$1, AssistantTransport, SharedApproval, TableAgentBridge as TableAgentBridge$1, TableAgentColumnPatch, TableAgentControllerOptions, TableAssistantSnapshot, TableAssistantStore } from "@adapttable/ai";
2
+ import { AgentContextInputs, AgentSession, AlwaysAllowedState, AssistantAllowance, AssistantAnswer, AssistantAudio, AssistantInterruption, AssistantInterruption as AssistantInterruption$1, AssistantMessage, AssistantQuestion, AssistantResumeHandle, AssistantResumeHandle as AssistantResumeHandle$1, AssistantStatus, AssistantSuggestion, AssistantSuggestion as AssistantSuggestion$1, AssistantTransport, SharedApproval, TABLE_AGENT_STATE, TableAgentBridge as TableAgentBridge$1, TableAgentColumnPatch, TableAgentControllerOptions, TableAssistantSnapshot, TableAssistantStore } from "@adapttable/ai";
3
3
  import { AgentApprovalPending, AgentProgress, SpeechInputHandle, StaticTableFeature } from "@adapttable/react/adapter";
4
4
  import { SpeechClip, VoiceOptions } from "@adapttable/ai/voice";
5
5
  //#region src/assistant.d.ts
@@ -205,12 +205,6 @@ declare function useTableAssistant(options: TableAssistantOptions): TableAssista
205
205
  //#endregion
206
206
  //#region src/react.d.ts
207
207
  type TableAgentBridge = TableAgentBridge$1<AgentApprovalPending>;
208
- /**
209
- * Feature-state key for the live {@link AgentSession}.
210
- *
211
- * @public
212
- */
213
- declare const TABLE_AGENT_STATE: import("@adapttable/core/binding").FeatureStateKey<AgentSession>;
214
208
  /**
215
209
  * Options for {@link tableAgent}.
216
210
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"mappings":";;;;;;UAoFiB;;WAEN,SAAS;;;;;;;;WAQT,YAAY;;;;;;;;;;WAUZ;;WAEA,uBAAuB;;WAEvB;;WAEA,gBAAgB;;;;;;;;;WAShB;;;;;;;;;;;WAWA,cAAc;;;;;;;;WAQd,sBAAsB;;;;;;;;;WAStB,YAAY,QAAQ;;WAEpB,eAAe;;;;;;;;;WASf,oBAAoB;;WAEpB,oBAAoB,mBAAmB;;;;;;;;;WASvC;;;UAIM;WACN,QAAQ;;;;;;;;WAQR;WACA,mBAAmB;WACnB;WACA,WAAW;;WAEX,OAAO,kBAAkB;;;;;;WAMzB,WAAW,MAAM,mBAAmB;;WAEpC;;;;;;WA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a,2BAA2B;;WAExC,wBAAwB;;WAExB,oBAAoB;;WAEpB,sBAAsB;;WAEtB,gBAAgB,eAAe;WAC/B;WACA,UAAU;;WAEV;;;;;;WAMA;;;;;;;;;;;;;;iBAeK,kBACd,SAAS,wBACR;;;KC7OS,mBAAmB,mBAAc;;;;;;;;;;;KAgBjC,oBAAoB;;;;;;;;iBA2HhB,WAAW,SAAS,oBAAoB;;;;UCzJvC;WACN,QAAQ;;WAER;;WAEA,WAAW;;WAEX,UAAU,MAAM;;;;;;;;;;iBAaX,eACd,SAAS,wBACR"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
- import { createTableAgentController, createTableAssistant } from "@adapttable/ai";
3
- import { AGENT_ALWAYS_ALLOW_STATE, AGENT_APPROVAL_STATE, AGENT_PROGRESS_STATE, AGENT_VIEW_STATE, FeatureStateScope, featureStateKey, useFeatureState, useTableRuntime } from "@adapttable/react/adapter";
2
+ import { TABLE_AGENT_STATE, createTableAgentController, createTableAssistant } from "@adapttable/ai";
3
+ import { AGENT_ALWAYS_ALLOW_STATE, AGENT_APPROVAL_STATE, AGENT_PROGRESS_STATE, AGENT_VIEW_STATE, FeatureStateScope, useFeatureState, useTableRuntime } from "@adapttable/react/adapter";
4
4
  import { useCallback, useDebugValue, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
5
5
  import { flushSync } from "react-dom";
6
6
  import { jsx } from "react/jsx-runtime";
@@ -131,12 +131,6 @@ function inputsOf(options, approval, alwaysAllow, viewState, progress) {
131
131
  * controller's inputs current, re-renders on its snapshot and the table's
132
132
  * changes, and publishes what the controller holds as feature state.
133
133
  */
134
- /**
135
- * Feature-state key for the live {@link AgentSession}.
136
- *
137
- * @public
138
- */
139
- const TABLE_AGENT_STATE = featureStateKey("table-agent");
140
134
  function TableAgentProvider({ feature, children }) {
141
135
  const options = feature.options;
142
136
  const runtime = useTableRuntime();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"sourcesContent":["/**\n * `@adapttable/ai-react` — the conversation lifecycle, without a UI.\n *\n * This entry owns state and nothing else: no markup, no launcher, no\n * provider client. A host renders its own panel from what the hook returns,\n * and the shipped widget is written against these same public values — which\n * is the only way to be sure it is not required.\n *\n * The rules that shape it:\n *\n * - **One send at a time**, reserved before any await. Two sends racing would\n * interleave two turns' actions against one table.\n * - **A draft survives failure.** Losing what someone typed because a\n * backend was down is worse than the outage.\n * - **A cancelled send is not a cancelled action.** Aborting before the\n * transport answers is clean; aborting after actions began is reported for\n * what it is, and nothing is retried — a mutation whose outcome is unknown\n * is never sent twice.\n * - **A late reply is dropped.** A turn that was stopped, or that belonged\n * to a previous table, never writes into the transcript.\n */\n\"use client\";\n\nimport {\n type AgentContextInputs,\n type AgentSession,\n type AlwaysAllowedState,\n type AssistantAllowance,\n type AssistantAudio,\n type AssistantInterruption,\n type AssistantMessage,\n type AssistantResumeHandle,\n type AssistantStatus,\n type AssistantSuggestion,\n type AssistantTransport,\n createTableAssistant,\n} from \"@adapttable/ai\";\nimport {\n AGENT_ALWAYS_ALLOW_STATE,\n AGENT_APPROVAL_STATE,\n AGENT_PROGRESS_STATE,\n AGENT_VIEW_STATE,\n type AgentAlwaysAllowState,\n type AgentApprovalPending,\n type AgentProgress,\n type AgentViewState,\n useFeatureState,\n} from \"@adapttable/react/adapter\";\nimport {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\n\n// The hook's own options and state name these, so the entry that publishes\n// the hook publishes them too — a consumer typing a variable from it should\n// not have to reach into another entry point for the pieces.\nexport type {\n ApprovalPolicy,\n AssistantReceiptStatus,\n AssistantReceiptSubject,\n CommitPolicy,\n RowAddressScope,\n WritePolicy,\n} from \"@adapttable/ai\";\nexport type {\n AssistantInterruption,\n AssistantMessage,\n AssistantResumeHandle,\n AssistantStatus,\n AssistantTransport,\n};\nexport type {\n AssistantExchange,\n AssistantQuestion,\n AssistantReceipt,\n AssistantTransportReply,\n AssistantTurnStatus,\n} from \"@adapttable/ai\";\nexport type { AssistantUndoOffer } from \"@adapttable/ai\";\n\n/** How {@link useTableAssistant} is configured. @public */\nexport interface TableAssistantOptions {\n /** The live session. Changing it starts a new conversation. */\n readonly session: AgentSession | undefined;\n /**\n * Where a turn goes. Omit and the assistant stays disconnected.\n *\n * May be a fresh object every render — the controller reads the latest one\n * rather than reconnecting on its identity, so a host is not forced to\n * memoize it.\n */\n readonly transport?: AssistantTransport;\n /**\n * Changes when the transport should be re-established.\n *\n * The conversation resets on a new session, because that is a new table.\n * Swapping one transport for another — a backend for a scripted one — is\n * not visible in the object identity, so a host that does it names the\n * change here. A backend transport must never quietly become a simulated\n * one under the same key.\n */\n readonly transportKey?: string;\n /** Everything authored, filtered live against what the table offers. */\n readonly suggestions?: readonly AssistantSuggestion[];\n /** Controlled panel state. Omit for uncontrolled. */\n readonly open?: boolean;\n /** Called on every open/close request, controlled or not. */\n readonly onOpenChange?: (open: boolean) => void;\n /**\n * Whether a write from this conversation is waiting on a human.\n *\n * `execute` does not return while an approval is open, so the turn looks\n * like thinking from in here. A host that renders the approval — or wires\n * `bridge.approvals` — passes it back so the panel can say what is\n * actually happening. The turn is still in flight and still stoppable.\n */\n readonly awaitingApproval?: boolean;\n /**\n * What the reader has waved through, when the panel is mounted outside the\n * table.\n *\n * A panel inside the table reads this from feature state and needs nothing\n * here. One beside it cannot, so a host wires `bridge.alwaysAllowed` and\n * passes what it publishes — the same arrangement `bridge.approvals` and\n * `bridge.viewInputs` already have. Without it a reader can wave a\n * capability through and have no way to take it back.\n */\n readonly alwaysAllow?: AlwaysAllowedState;\n /**\n * Live view and filter data the manifest does not carry.\n *\n * Read when a turn starts and again when it settles, so per-turn undo can\n * tell what the turn moved. A function rather than a value: a fixed object\n * would report that nothing changed.\n */\n readonly contextInputs?: () => AgentContextInputs;\n /**\n * Work that outlived its connection, handed over the moment it does.\n *\n * Durable recovery starts here and ends outside this package: a host that\n * stores the handle where it survives a reload can offer a resume when the\n * reader comes back, and a host that does nothing loses the work with the\n * page.\n */\n readonly onDetach?: (handle: AssistantResumeHandle) => void;\n /** A handle kept from a previous page, to resume into this one. */\n readonly resumeHandle?: AssistantResumeHandle;\n /**\n * The transcript, when your app owns it.\n *\n * Omit it and the conversation lives in the controller. Supply it to load\n * the last conversation from your own API, append a message that arrived on\n * a socket, or keep it where it survives a reload — pass a new array and the\n * panel shows it. Pair it with `onMessagesChange`.\n */\n readonly messages?: readonly AssistantMessage[];\n /** Told whenever the transcript changes, with the whole of it. */\n readonly onMessagesChange?: (messages: readonly AssistantMessage[]) => void;\n /**\n * How much of the conversation travels with each turn.\n *\n * `\"full\"` (default) sends every earlier message, for a backend that\n * remembers nothing. A number sends that many of the most recent. `0` sends\n * none — the reader's message still travels, and a backend holding its own\n * session supplies the rest. What the reader sees is never trimmed.\n */\n readonly conversation?: \"full\" | number;\n}\n\n/** What a host renders from. @public */\nexport interface TableAssistantState {\n readonly status: AssistantStatus;\n /**\n * Whether a turn is in flight and can still be stopped.\n *\n * Separate from {@link TableAssistantState.status}: a write parked on a\n * human approval reports `awaiting-approval` but is still running, and\n * Stop still ends it.\n */\n readonly busy: boolean;\n readonly messages: readonly AssistantMessage[];\n readonly draft: string;\n readonly setDraft: (draft: string) => void;\n /** Send the draft, or the given text. Resolves when the turn settles. */\n readonly send: (text?: string) => Promise<void>;\n /**\n * Send a recording as the reader's turn — pass it as `onClip` to\n * backend-mode `useSpeechInput`. The transcript the backend returns becomes\n * the reader's message.\n */\n readonly sendClip: (clip: AssistantAudio) => Promise<void>;\n /** Abort the turn in flight. Safe to call when nothing is in flight. */\n readonly stop: () => void;\n /**\n * Rejoin work a released connection left running.\n *\n * A no-op with nothing to rejoin, which is what `resumable` says.\n */\n readonly resume: () => Promise<void>;\n /**\n * What became of the last turn, when no reply ended it.\n *\n * `\"stopped\"` is the reader's own decision; `\"detached\"` is a released\n * connection, where the work may still be running.\n */\n readonly interrupted: AssistantInterruption | undefined;\n /** The work `resume` would rejoin, or nothing. */\n readonly resumable: AssistantResumeHandle | undefined;\n /** Drop the transcript. Refuses while a turn is in flight. */\n readonly clear: () => void;\n /**\n * A write waiting on the reader, or nothing.\n *\n * Hand it to the panel as `approval` and the conversation reviews it —\n * which is where a write asked for in the conversation belongs. The panel\n * draws it only when the approval's presentation names the widget, so\n * passing it costs nothing on a table reviewing elsewhere.\n */\n readonly approval: AgentApprovalPending | null;\n /**\n * How far the capability now running has got, or nothing.\n *\n * Published by the table while a long call works through its rows. It never\n * becomes the receipt: when the turn settles this goes and the receipts say\n * what happened.\n */\n readonly progress: AgentProgress | null;\n /** Answer the pending question and let the turn continue. */\n readonly answer: (answer: { optionId?: string; text?: string }) => void;\n /**\n * Whether the last turn that moved the table can still be put back.\n *\n * Null when no turn moved it. Re-read every render, because the offer ends\n * the moment anything else changes the view. `blockedCode` is a token the\n * labels translate — the panel never shows a reader a code.\n */\n readonly undo: {\n readonly messageId: string;\n readonly available: boolean;\n readonly blockedCode?: string;\n } | null;\n /** Put that turn back. A no-op once the offer has expired. */\n readonly undoTurn: () => Promise<void>;\n /** Put one action of the last turn back, by its receipt's replay identity. */\n readonly undoAction: (idempotencyKey: string) => Promise<void>;\n /** What the reader said not to ask about again, each with its own name. */\n readonly alwaysAllowed: readonly AssistantAllowance[];\n /** Ask about one of them again from now on. */\n readonly revokeAlwaysAllow: (capability: string) => void;\n /** The suggestions this table can run right now, re-checked every render. */\n readonly suggestions: readonly AssistantSuggestion[];\n /** Send a suggestion's prompt as if the reader had typed it. */\n readonly runSuggestion: (id: string) => Promise<void>;\n readonly open: boolean;\n readonly setOpen: (open: boolean) => void;\n /** The last failure, cleared by the next successful turn. */\n readonly error: string | undefined;\n /**\n * The machine code behind {@link error}, when a turn ended with work\n * pending. A surface with labels turns it into a sentence for the reader;\n * the message beside it is written for whoever is debugging the turn.\n */\n readonly errorCode: string | undefined;\n}\n\n/**\n * Run a table assistant.\n *\n * A thin subscriber to the neutral controller in `@adapttable/ai/assistant`:\n * React supplies the external-store mechanism, the live inputs and the\n * controlled presentation state, and owns none of the lifecycle.\n *\n * @param options - Session, transport and presentation.\n * @returns Everything a panel needs, and nothing about how it looks.\n *\n * @public\n */\nexport function useTableAssistant(\n options: TableAssistantOptions\n): TableAssistantState {\n const { onOpenChange } = options;\n const [uncontrolledOpen, setUncontrolledOpen] = useState(false);\n // The live approval, so a host wires the panel with one prop rather than\n // reaching for feature state itself.\n const approval = useFeatureState(AGENT_APPROVAL_STATE);\n // What the reader has waved through, published by the binding whether or\n // not an approval is open.\n const alwaysAllow = useFeatureState(AGENT_ALWAYS_ALLOW_STATE);\n // The table's own live view, published by `tableAgent`. A host that drives\n // the panel from state of its own passes `contextInputs` and this is unused.\n const viewState = useFeatureState(AGENT_VIEW_STATE);\n // How far a running capability has got, for the same reason: a panel inside\n // the table needs no host wiring to say what the work is doing.\n const progress = useFeatureState(AGENT_PROGRESS_STATE);\n\n // Created once, inert until the mount effect connects it. Constructing a\n // store during render must not open a connection — a render can be thrown\n // away, and Strict Mode throws the first one away on purpose.\n const storeRef = useRef<ReturnType<typeof createTableAssistant> | null>(null);\n storeRef.current ??= createTableAssistant(\n inputsOf(options, approval, alwaysAllow, viewState, progress)\n );\n const store = storeRef.current;\n\n // Live inputs, every render. The store decides what a change means: a new\n // session resets the conversation, a new transport key reconnects, and an\n // updated catalog or a newly arrived approval does neither.\n useEffect(() => {\n store.update(inputsOf(options, approval, alwaysAllow, viewState, progress));\n });\n\n useEffect(() => {\n store.connect();\n return () => {\n store.dispose();\n // A disposed store is never reused. Strict Mode's second setup, and any\n // later remount, builds a fresh one rather than reviving one that has\n // already released its connection.\n storeRef.current = null;\n };\n // Mount and unmount only: every other change reaches the store through\n // `update` above, which is what keeps connection effects out of render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const state = useSyncExternalStore(\n store.subscribe,\n store.getState,\n store.getState\n );\n\n const open = options.open ?? uncontrolledOpen;\n const setOpen = useCallback(\n (next: boolean) => {\n if (options.open === undefined) setUncontrolledOpen(next);\n onOpenChange?.(next);\n },\n [options.open, onOpenChange]\n );\n\n return {\n messages: state.messages,\n draft: state.draft,\n setDraft: store.setDraft,\n send: store.send,\n sendClip: store.sendClip,\n stop: store.stop,\n resume: store.resume,\n interrupted: state.interrupted,\n resumable: state.resumable,\n clear: store.clear,\n status: state.status,\n busy: state.busy,\n approval: approval ?? null,\n progress: state.progress,\n answer: store.answer,\n undo: state.undo\n ? {\n messageId: state.undo.messageId,\n available: state.undo.available,\n ...(state.undo.blocked\n ? { blockedCode: state.undo.blocked.code }\n : {}),\n }\n : null,\n undoTurn: store.undoTurn,\n undoAction: store.undoAction,\n alwaysAllowed: state.alwaysAllowed,\n revokeAlwaysAllow: store.revokeAlwaysAllow,\n suggestions: state.suggestions,\n runSuggestion: store.runSuggestion,\n open,\n setOpen,\n error: state.error,\n errorCode: state.errorCode,\n };\n}\n\n/** The hook's options as the store's live inputs. A projection, not a decision. */\nfunction inputsOf(\n options: TableAssistantOptions,\n approval: AgentApprovalPending | null | undefined,\n alwaysAllow: AgentAlwaysAllowState | null | undefined,\n viewState: AgentViewState | null | undefined,\n progress: AgentProgress | null | undefined\n) {\n // The host's own reader wins; otherwise the table's, which is what makes\n // per-turn undo work without a host lifting page and sort into its state.\n const contextInputs =\n options.contextInputs ??\n (viewState ? () => viewState.read() as AgentContextInputs : undefined);\n return {\n session: options.session,\n transport: options.transport,\n transportKey: options.transportKey,\n suggestions: options.suggestions,\n awaitingApproval: options.awaitingApproval,\n approval: approval ?? null,\n progress: progress ?? null,\n ...(contextInputs ? { contextInputs } : {}),\n ...(options.onDetach ? { onDetach: options.onDetach } : {}),\n ...(options.messages ? { messages: options.messages } : {}),\n ...(options.onMessagesChange\n ? { onMessagesChange: options.onMessagesChange }\n : {}),\n ...(options.conversation === undefined\n ? {}\n : { conversation: options.conversation }),\n ...(options.resumeHandle ? { resumeHandle: options.resumeHandle } : {}),\n // The host's own wins, for the same reason `contextInputs` does: a panel\n // beside the table has no feature state to read.\n ...((options.alwaysAllow ?? alwaysAllow)\n ? {\n alwaysAllowed: (options.alwaysAllow ?? alwaysAllow)?.capabilities,\n onRevokeAlwaysAllow: (options.alwaysAllow ?? alwaysAllow)?.revoke,\n }\n : {}),\n };\n}\n","/**\n * Opt-in table feature — `@adapttable/ai-react`.\n *\n * `@adapttable/ai` stays React-free. This package mounts a provider that\n * drives `@adapttable/ai`'s table agent controller from React: it keeps the\n * controller's inputs current, re-renders on its snapshot and the table's\n * changes, and publishes what the controller holds as feature state.\n */\nimport {\n type AgentSession,\n createTableAgentController,\n type TableAgentBridge as NeutralBridge,\n type TableAgentController,\n type TableAgentControllerOptions,\n} from \"@adapttable/ai\";\nimport {\n AGENT_ALWAYS_ALLOW_STATE,\n AGENT_APPROVAL_STATE,\n AGENT_PROGRESS_STATE,\n AGENT_VIEW_STATE,\n type AgentApprovalPending,\n type FeatureProviderProps,\n featureStateKey,\n FeatureStateScope,\n type StaticTableFeature,\n useTableRuntime,\n} from \"@adapttable/react/adapter\";\nimport {\n type ReactNode,\n useCallback,\n useDebugValue,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\n\nexport type { SharedApproval, TableAgentColumnPatch } from \"@adapttable/ai\";\n\n// The bridge contract is `@adapttable/ai`'s — a manifest, a session and a\n// pending approval are what any binding publishes, none of it React. Named\n// here with this binding's own pending shape so every existing import keeps\n// working.\nexport type TableAgentBridge = NeutralBridge<AgentApprovalPending>;\n\n/**\n * Feature-state key for the live {@link AgentSession}.\n *\n * @public\n */\nexport const TABLE_AGENT_STATE = featureStateKey<AgentSession>(\"table-agent\");\n\n/**\n * Options for {@link tableAgent}.\n *\n * The same options `@adapttable/ai`'s table agent controller takes: the\n * runtime half — identity, policy, columns, the host's callbacks and\n * capabilities — plus where updates are published and whether the table is\n * offered to a browser-resident agent.\n *\n * @public\n */\nexport type TableAgentOptions = TableAgentControllerOptions;\n\ninterface TableAgentFeature extends StaticTableFeature {\n readonly options: TableAgentOptions;\n}\n\nfunction TableAgentProvider({\n feature,\n children,\n}: Readonly<FeatureProviderProps>): ReactNode {\n const options = (feature as TableAgentFeature).options;\n const runtime = useTableRuntime();\n const optionsRef = useRef(options);\n optionsRef.current = options;\n const runtimeRef = useRef(runtime);\n runtimeRef.current = runtime;\n // A concrete provider update, rather than an empty `flushSync`, makes React\n // finish controlled-state work already queued by the reader before the\n // session takes its admission snapshot.\n const [admissionTick, setAdmissionTick] = useState(0);\n const flushAdmission = useRef<() => void>(() => undefined);\n flushAdmission.current = () => {\n flushSync(() => {\n setAdmissionTick(admissionTick + 1);\n });\n };\n\n // Built once and never during a render that is thrown away twice: the\n // controller opens nothing until `sync`, which only an effect calls.\n const controllerRef = useRef<TableAgentController | null>(null);\n controllerRef.current ??= createTableAgentController({\n options: optionsRef,\n runtime: runtimeRef,\n flushAdmission: () => {\n flushAdmission.current();\n },\n flush: flushSync,\n });\n const controller = controllerRef.current;\n\n // The table as a store: subscribe where there is one to subscribe to, and\n // read the stamp on every render either way. React re-reads the stamp after\n // it attaches, so a table that moved between the render and the\n // subscription is caught rather than missed. The value is not rendered;\n // re-rendering is the point, because that republishes the manifest.\n const neutralTable = runtime.view()?.neutralTable;\n // The controller subscribes to the table current at the call, so a\n // replaced table is a new subscription.\n const subscribeToTable = useCallback(\n (onStoreChange: () => void) =>\n neutralTable ? controller.subscribeTable(onStoreChange) : () => undefined,\n [controller, neutralTable]\n );\n const stamp = useSyncExternalStore(\n subscribeToTable,\n controller.tableStamp,\n controller.tableStamp\n );\n useDebugValue(stamp);\n\n const state = useSyncExternalStore(\n controller.subscribe,\n controller.getState,\n controller.getState\n );\n\n // Every commit: the controller decides what changed and tells only those\n // who need telling. A layout effect, so a host reading the manifest in its\n // own effects already has this render's.\n useLayoutEffect(() => {\n controller.sync();\n });\n\n // Going away is a close. Strict Mode's setup/cleanup/setup lands here too:\n // the cleanup releases everything, and the next sync sets it up again.\n useEffect(\n () => () => {\n controller.disconnect();\n },\n [controller]\n );\n\n // A new value every render on purpose. The table publishes its runtime\n // while its children render, after this provider has, so a surface below\n // learns what the session now offers only by re-rendering with it — and it\n // re-renders because the value it holds is a different one.\n const session = state.session;\n const published: AgentSession = {\n catalog: () => session.catalog(),\n describe: (key) => session.describe(key),\n execute: (key, args, expectedRevision, idempotencyKey, signal) =>\n session.execute(key, args, expectedRevision, idempotencyKey, signal),\n manifest: () => session.manifest(),\n };\n\n return (\n <FeatureStateScope stateKey={TABLE_AGENT_STATE} value={published}>\n <FeatureStateScope stateKey={AGENT_APPROVAL_STATE} value={state.approval}>\n <FeatureStateScope\n stateKey={AGENT_ALWAYS_ALLOW_STATE}\n value={state.alwaysAllow}\n >\n <FeatureStateScope stateKey={AGENT_VIEW_STATE} value={state.view}>\n <FeatureStateScope\n stateKey={AGENT_PROGRESS_STATE}\n value={state.progress}\n >\n {children}\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n );\n}\n\n/**\n * Observe a live table and publish a deterministic capability manifest.\n *\n * Omitting this feature from `features` ships no agent bytes.\n *\n * @public\n */\nexport function tableAgent(options: TableAgentOptions): StaticTableFeature {\n const feature: TableAgentFeature = {\n id: \"table-agent\",\n options,\n provider: { Provider: TableAgentProvider },\n };\n return feature;\n}\n","/**\n * Dictation, as a React hook — `@adapttable/ai-react`.\n *\n * Thin on purpose. The controller in `@adapttable/ai/voice` owns the browser\n * APIs, the permission states and the language choice; this subscribes to it,\n * keeps it alive for the life of the composer, and writes what it hears\n * through the caller's `setDraft` — which is the one channel voice is allowed\n * to use, so a spoken sentence becomes a draft the reader can see and fix\n * rather than a request the table has already acted on.\n *\n * It lives here rather than in `@adapttable/react` because it imports\n * `@adapttable/ai`, and that package must stay out of the base graph. The\n * chrome takes `SpeechInputHandle` — the structural shape this returns —\n * from `@adapttable/react/adapter`, which declares it without importing\n * anything.\n */\n\"use client\";\n\nimport {\n createSpeechInput,\n readRememberedLanguage,\n rememberLanguage,\n type SpeechClip,\n type SpeechInput,\n type SpeechState,\n type VoiceOptions,\n} from \"@adapttable/ai/voice\";\nimport type { SpeechInputHandle } from \"@adapttable/react/adapter\";\nimport { useEffect, useRef, useSyncExternalStore } from \"react\";\n\n/** How the hook is configured. @public */\nexport interface UseSpeechInputOptions {\n readonly voice?: VoiceOptions;\n /** The table's locale, used when no language list was given. */\n readonly locale?: string;\n /** Where heard text goes. Always the draft, never a send. */\n readonly setDraft: (text: string) => void;\n /** Where a recording goes, in backend mode. */\n readonly onClip?: (clip: SpeechClip) => void;\n}\n\nconst IDLE: SpeechState = { status: \"unsupported\", language: \"\", interim: \"\" };\n\n/**\n * Run dictation for one composer.\n *\n * @param options - Voice configuration and where heard text should go.\n * @returns What the composer needs, or an unavailable handle when voice is off.\n *\n * @public\n */\nexport function useSpeechInput(\n options: UseSpeechInputOptions\n): SpeechInputHandle {\n const { voice, locale, setDraft, onClip } = options;\n // Live callbacks, so the controller is built once and still calls whatever\n // the latest render passed rather than what the first one did.\n const draftRef = useRef(setDraft);\n draftRef.current = setDraft;\n const clipRef = useRef(onClip);\n clipRef.current = onClip;\n\n const languages = voice?.languages?.length\n ? voice.languages\n : [locale ?? \"en-US\"];\n const inputRef = useRef<SpeechInput | null>(null);\n if (voice && !inputRef.current) {\n inputRef.current = createSpeechInput({\n mode: voice.mode ?? \"browser\",\n languages,\n // Remembered from a previous visit when the browser kept it, and the\n // first offered language otherwise.\n ...(readRememberedLanguage()\n ? { initialLanguage: readRememberedLanguage() }\n : {}),\n onDraft: (text) => draftRef.current(text),\n onClip: (clip) => clipRef.current?.(clip),\n });\n }\n const input = inputRef.current;\n\n useEffect(\n () => () => {\n input?.dispose();\n // A disposed controller is never revived: a remount builds a fresh one,\n // the way the assistant store does.\n inputRef.current = null;\n },\n [input]\n );\n\n const state = useSyncExternalStore(\n (listener) => input?.subscribe(listener) ?? (() => undefined),\n () => input?.getState() ?? IDLE,\n () => IDLE\n );\n\n return {\n // Absent rather than dead: a mic that cannot listen is not drawn.\n available: Boolean(voice && input?.supported()),\n state,\n languages,\n start: () => input?.start(),\n stop: () => input?.stop(),\n setLanguage: (language) => {\n input?.setLanguage(language);\n rememberLanguage(language);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwRA,SAAgB,kBACd,SACqB;CACrB,MAAM,EAAE,iBAAiB;CACzB,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,KAAK;CAG9D,MAAM,WAAW,gBAAgB,oBAAoB;CAGrD,MAAM,cAAc,gBAAgB,wBAAwB;CAG5D,MAAM,YAAY,gBAAgB,gBAAgB;CAGlD,MAAM,WAAW,gBAAgB,oBAAoB;CAKrD,MAAM,WAAW,OAAuD,IAAI;CAC5E,SAAS,YAAY,qBACnB,SAAS,SAAS,UAAU,aAAa,WAAW,QAAQ,CAC9D;CACA,MAAM,QAAQ,SAAS;CAKvB,gBAAgB;EACd,MAAM,OAAO,SAAS,SAAS,UAAU,aAAa,WAAW,QAAQ,CAAC;CAC5E,CAAC;CAED,gBAAgB;EACd,MAAM,QAAQ;EACd,aAAa;GACX,MAAM,QAAQ;GAId,SAAS,UAAU;EACrB;CAIF,GAAG,CAAC,CAAC;CAEL,MAAM,QAAQ,qBACZ,MAAM,WACN,MAAM,UACN,MAAM,QACR;CAEA,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,UAAU,aACb,SAAkB;EACjB,IAAI,QAAQ,SAAS,KAAA,GAAW,oBAAoB,IAAI;EACxD,eAAe,IAAI;CACrB,GACA,CAAC,QAAQ,MAAM,YAAY,CAC7B;CAEA,OAAO;EACL,UAAU,MAAM;EAChB,OAAO,MAAM;EACb,UAAU,MAAM;EAChB,MAAM,MAAM;EACZ,UAAU,MAAM;EAChB,MAAM,MAAM;EACZ,QAAQ,MAAM;EACd,aAAa,MAAM;EACnB,WAA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AU,CAAC;EAC9C;EACA;EACA,aAAa,OAAO,MAAM;EAC1B,YAAY,OAAO,KAAK;EACxB,cAAc,aAAa;GACzB,OAAO,YAAY,QAAQ;GAC3B,iBAAiB,QAAQ;EAC3B;CACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"sourcesContent":["/**\n * `@adapttable/ai-react` — the conversation lifecycle, without a UI.\n *\n * This entry owns state and nothing else: no markup, no launcher, no\n * provider client. A host renders its own panel from what the hook returns,\n * and the shipped widget is written against these same public values — which\n * is the only way to be sure it is not required.\n *\n * The rules that shape it:\n *\n * - **One send at a time**, reserved before any await. Two sends racing would\n * interleave two turns' actions against one table.\n * - **A draft survives failure.** Losing what someone typed because a\n * backend was down is worse than the outage.\n * - **A cancelled send is not a cancelled action.** Aborting before the\n * transport answers is clean; aborting after actions began is reported for\n * what it is, and nothing is retried — a mutation whose outcome is unknown\n * is never sent twice.\n * - **A late reply is dropped.** A turn that was stopped, or that belonged\n * to a previous table, never writes into the transcript.\n */\n\"use client\";\n\nimport {\n type AgentContextInputs,\n type AgentSession,\n type AlwaysAllowedState,\n type AssistantAllowance,\n type AssistantAudio,\n type AssistantInterruption,\n type AssistantMessage,\n type AssistantResumeHandle,\n type AssistantStatus,\n type AssistantSuggestion,\n type AssistantTransport,\n createTableAssistant,\n} from \"@adapttable/ai\";\nimport {\n AGENT_ALWAYS_ALLOW_STATE,\n AGENT_APPROVAL_STATE,\n AGENT_PROGRESS_STATE,\n AGENT_VIEW_STATE,\n type AgentAlwaysAllowState,\n type AgentApprovalPending,\n type AgentProgress,\n type AgentViewState,\n useFeatureState,\n} from \"@adapttable/react/adapter\";\nimport {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\n\n// The hook's own options and state name these, so the entry that publishes\n// the hook publishes them too — a consumer typing a variable from it should\n// not have to reach into another entry point for the pieces.\nexport type {\n ApprovalPolicy,\n AssistantReceiptStatus,\n AssistantReceiptSubject,\n CommitPolicy,\n RowAddressScope,\n WritePolicy,\n} from \"@adapttable/ai\";\nexport type {\n AssistantInterruption,\n AssistantMessage,\n AssistantResumeHandle,\n AssistantStatus,\n AssistantTransport,\n};\nexport type {\n AssistantExchange,\n AssistantQuestion,\n AssistantReceipt,\n AssistantTransportReply,\n AssistantTurnStatus,\n} from \"@adapttable/ai\";\nexport type { AssistantUndoOffer } from \"@adapttable/ai\";\n\n/** How {@link useTableAssistant} is configured. @public */\nexport interface TableAssistantOptions {\n /** The live session. Changing it starts a new conversation. */\n readonly session: AgentSession | undefined;\n /**\n * Where a turn goes. Omit and the assistant stays disconnected.\n *\n * May be a fresh object every render — the controller reads the latest one\n * rather than reconnecting on its identity, so a host is not forced to\n * memoize it.\n */\n readonly transport?: AssistantTransport;\n /**\n * Changes when the transport should be re-established.\n *\n * The conversation resets on a new session, because that is a new table.\n * Swapping one transport for another — a backend for a scripted one — is\n * not visible in the object identity, so a host that does it names the\n * change here. A backend transport must never quietly become a simulated\n * one under the same key.\n */\n readonly transportKey?: string;\n /** Everything authored, filtered live against what the table offers. */\n readonly suggestions?: readonly AssistantSuggestion[];\n /** Controlled panel state. Omit for uncontrolled. */\n readonly open?: boolean;\n /** Called on every open/close request, controlled or not. */\n readonly onOpenChange?: (open: boolean) => void;\n /**\n * Whether a write from this conversation is waiting on a human.\n *\n * `execute` does not return while an approval is open, so the turn looks\n * like thinking from in here. A host that renders the approval — or wires\n * `bridge.approvals` — passes it back so the panel can say what is\n * actually happening. The turn is still in flight and still stoppable.\n */\n readonly awaitingApproval?: boolean;\n /**\n * What the reader has waved through, when the panel is mounted outside the\n * table.\n *\n * A panel inside the table reads this from feature state and needs nothing\n * here. One beside it cannot, so a host wires `bridge.alwaysAllowed` and\n * passes what it publishes — the same arrangement `bridge.approvals` and\n * `bridge.viewInputs` already have. Without it a reader can wave a\n * capability through and have no way to take it back.\n */\n readonly alwaysAllow?: AlwaysAllowedState;\n /**\n * Live view and filter data the manifest does not carry.\n *\n * Read when a turn starts and again when it settles, so per-turn undo can\n * tell what the turn moved. A function rather than a value: a fixed object\n * would report that nothing changed.\n */\n readonly contextInputs?: () => AgentContextInputs;\n /**\n * Work that outlived its connection, handed over the moment it does.\n *\n * Durable recovery starts here and ends outside this package: a host that\n * stores the handle where it survives a reload can offer a resume when the\n * reader comes back, and a host that does nothing loses the work with the\n * page.\n */\n readonly onDetach?: (handle: AssistantResumeHandle) => void;\n /** A handle kept from a previous page, to resume into this one. */\n readonly resumeHandle?: AssistantResumeHandle;\n /**\n * The transcript, when your app owns it.\n *\n * Omit it and the conversation lives in the controller. Supply it to load\n * the last conversation from your own API, append a message that arrived on\n * a socket, or keep it where it survives a reload — pass a new array and the\n * panel shows it. Pair it with `onMessagesChange`.\n */\n readonly messages?: readonly AssistantMessage[];\n /** Told whenever the transcript changes, with the whole of it. */\n readonly onMessagesChange?: (messages: readonly AssistantMessage[]) => void;\n /**\n * How much of the conversation travels with each turn.\n *\n * `\"full\"` (default) sends every earlier message, for a backend that\n * remembers nothing. A number sends that many of the most recent. `0` sends\n * none — the reader's message still travels, and a backend holding its own\n * session supplies the rest. What the reader sees is never trimmed.\n */\n readonly conversation?: \"full\" | number;\n}\n\n/** What a host renders from. @public */\nexport interface TableAssistantState {\n readonly status: AssistantStatus;\n /**\n * Whether a turn is in flight and can still be stopped.\n *\n * Separate from {@link TableAssistantState.status}: a write parked on a\n * human approval reports `awaiting-approval` but is still running, and\n * Stop still ends it.\n */\n readonly busy: boolean;\n readonly messages: readonly AssistantMessage[];\n readonly draft: string;\n readonly setDraft: (draft: string) => void;\n /** Send the draft, or the given text. Resolves when the turn settles. */\n readonly send: (text?: string) => Promise<void>;\n /**\n * Send a recording as the reader's turn — pass it as `onClip` to\n * backend-mode `useSpeechInput`. The transcript the backend returns becomes\n * the reader's message.\n */\n readonly sendClip: (clip: AssistantAudio) => Promise<void>;\n /** Abort the turn in flight. Safe to call when nothing is in flight. */\n readonly stop: () => void;\n /**\n * Rejoin work a released connection left running.\n *\n * A no-op with nothing to rejoin, which is what `resumable` says.\n */\n readonly resume: () => Promise<void>;\n /**\n * What became of the last turn, when no reply ended it.\n *\n * `\"stopped\"` is the reader's own decision; `\"detached\"` is a released\n * connection, where the work may still be running.\n */\n readonly interrupted: AssistantInterruption | undefined;\n /** The work `resume` would rejoin, or nothing. */\n readonly resumable: AssistantResumeHandle | undefined;\n /** Drop the transcript. Refuses while a turn is in flight. */\n readonly clear: () => void;\n /**\n * A write waiting on the reader, or nothing.\n *\n * Hand it to the panel as `approval` and the conversation reviews it —\n * which is where a write asked for in the conversation belongs. The panel\n * draws it only when the approval's presentation names the widget, so\n * passing it costs nothing on a table reviewing elsewhere.\n */\n readonly approval: AgentApprovalPending | null;\n /**\n * How far the capability now running has got, or nothing.\n *\n * Published by the table while a long call works through its rows. It never\n * becomes the receipt: when the turn settles this goes and the receipts say\n * what happened.\n */\n readonly progress: AgentProgress | null;\n /** Answer the pending question and let the turn continue. */\n readonly answer: (answer: { optionId?: string; text?: string }) => void;\n /**\n * Whether the last turn that moved the table can still be put back.\n *\n * Null when no turn moved it. Re-read every render, because the offer ends\n * the moment anything else changes the view. `blockedCode` is a token the\n * labels translate — the panel never shows a reader a code.\n */\n readonly undo: {\n readonly messageId: string;\n readonly available: boolean;\n readonly blockedCode?: string;\n } | null;\n /** Put that turn back. A no-op once the offer has expired. */\n readonly undoTurn: () => Promise<void>;\n /** Put one action of the last turn back, by its receipt's replay identity. */\n readonly undoAction: (idempotencyKey: string) => Promise<void>;\n /** What the reader said not to ask about again, each with its own name. */\n readonly alwaysAllowed: readonly AssistantAllowance[];\n /** Ask about one of them again from now on. */\n readonly revokeAlwaysAllow: (capability: string) => void;\n /** The suggestions this table can run right now, re-checked every render. */\n readonly suggestions: readonly AssistantSuggestion[];\n /** Send a suggestion's prompt as if the reader had typed it. */\n readonly runSuggestion: (id: string) => Promise<void>;\n readonly open: boolean;\n readonly setOpen: (open: boolean) => void;\n /** The last failure, cleared by the next successful turn. */\n readonly error: string | undefined;\n /**\n * The machine code behind {@link error}, when a turn ended with work\n * pending. A surface with labels turns it into a sentence for the reader;\n * the message beside it is written for whoever is debugging the turn.\n */\n readonly errorCode: string | undefined;\n}\n\n/**\n * Run a table assistant.\n *\n * A thin subscriber to the neutral controller in `@adapttable/ai/assistant`:\n * React supplies the external-store mechanism, the live inputs and the\n * controlled presentation state, and owns none of the lifecycle.\n *\n * @param options - Session, transport and presentation.\n * @returns Everything a panel needs, and nothing about how it looks.\n *\n * @public\n */\nexport function useTableAssistant(\n options: TableAssistantOptions\n): TableAssistantState {\n const { onOpenChange } = options;\n const [uncontrolledOpen, setUncontrolledOpen] = useState(false);\n // The live approval, so a host wires the panel with one prop rather than\n // reaching for feature state itself.\n const approval = useFeatureState(AGENT_APPROVAL_STATE);\n // What the reader has waved through, published by the binding whether or\n // not an approval is open.\n const alwaysAllow = useFeatureState(AGENT_ALWAYS_ALLOW_STATE);\n // The table's own live view, published by `tableAgent`. A host that drives\n // the panel from state of its own passes `contextInputs` and this is unused.\n const viewState = useFeatureState(AGENT_VIEW_STATE);\n // How far a running capability has got, for the same reason: a panel inside\n // the table needs no host wiring to say what the work is doing.\n const progress = useFeatureState(AGENT_PROGRESS_STATE);\n\n // Created once, inert until the mount effect connects it. Constructing a\n // store during render must not open a connection — a render can be thrown\n // away, and Strict Mode throws the first one away on purpose.\n const storeRef = useRef<ReturnType<typeof createTableAssistant> | null>(null);\n storeRef.current ??= createTableAssistant(\n inputsOf(options, approval, alwaysAllow, viewState, progress)\n );\n const store = storeRef.current;\n\n // Live inputs, every render. The store decides what a change means: a new\n // session resets the conversation, a new transport key reconnects, and an\n // updated catalog or a newly arrived approval does neither.\n useEffect(() => {\n store.update(inputsOf(options, approval, alwaysAllow, viewState, progress));\n });\n\n useEffect(() => {\n store.connect();\n return () => {\n store.dispose();\n // A disposed store is never reused. Strict Mode's second setup, and any\n // later remount, builds a fresh one rather than reviving one that has\n // already released its connection.\n storeRef.current = null;\n };\n // Mount and unmount only: every other change reaches the store through\n // `update` above, which is what keeps connection effects out of render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const state = useSyncExternalStore(\n store.subscribe,\n store.getState,\n store.getState\n );\n\n const open = options.open ?? uncontrolledOpen;\n const setOpen = useCallback(\n (next: boolean) => {\n if (options.open === undefined) setUncontrolledOpen(next);\n onOpenChange?.(next);\n },\n [options.open, onOpenChange]\n );\n\n return {\n messages: state.messages,\n draft: state.draft,\n setDraft: store.setDraft,\n send: store.send,\n sendClip: store.sendClip,\n stop: store.stop,\n resume: store.resume,\n interrupted: state.interrupted,\n resumable: state.resumable,\n clear: store.clear,\n status: state.status,\n busy: state.busy,\n approval: approval ?? null,\n progress: state.progress,\n answer: store.answer,\n undo: state.undo\n ? {\n messageId: state.undo.messageId,\n available: state.undo.available,\n ...(state.undo.blocked\n ? { blockedCode: state.undo.blocked.code }\n : {}),\n }\n : null,\n undoTurn: store.undoTurn,\n undoAction: store.undoAction,\n alwaysAllowed: state.alwaysAllowed,\n revokeAlwaysAllow: store.revokeAlwaysAllow,\n suggestions: state.suggestions,\n runSuggestion: store.runSuggestion,\n open,\n setOpen,\n error: state.error,\n errorCode: state.errorCode,\n };\n}\n\n/** The hook's options as the store's live inputs. A projection, not a decision. */\nfunction inputsOf(\n options: TableAssistantOptions,\n approval: AgentApprovalPending | null | undefined,\n alwaysAllow: AgentAlwaysAllowState | null | undefined,\n viewState: AgentViewState | null | undefined,\n progress: AgentProgress | null | undefined\n) {\n // The host's own reader wins; otherwise the table's, which is what makes\n // per-turn undo work without a host lifting page and sort into its state.\n const contextInputs =\n options.contextInputs ??\n (viewState ? () => viewState.read() as AgentContextInputs : undefined);\n return {\n session: options.session,\n transport: options.transport,\n transportKey: options.transportKey,\n suggestions: options.suggestions,\n awaitingApproval: options.awaitingApproval,\n approval: approval ?? null,\n progress: progress ?? null,\n ...(contextInputs ? { contextInputs } : {}),\n ...(options.onDetach ? { onDetach: options.onDetach } : {}),\n ...(options.messages ? { messages: options.messages } : {}),\n ...(options.onMessagesChange\n ? { onMessagesChange: options.onMessagesChange }\n : {}),\n ...(options.conversation === undefined\n ? {}\n : { conversation: options.conversation }),\n ...(options.resumeHandle ? { resumeHandle: options.resumeHandle } : {}),\n // The host's own wins, for the same reason `contextInputs` does: a panel\n // beside the table has no feature state to read.\n ...((options.alwaysAllow ?? alwaysAllow)\n ? {\n alwaysAllowed: (options.alwaysAllow ?? alwaysAllow)?.capabilities,\n onRevokeAlwaysAllow: (options.alwaysAllow ?? alwaysAllow)?.revoke,\n }\n : {}),\n };\n}\n","/**\n * Opt-in table feature — `@adapttable/ai-react`.\n *\n * `@adapttable/ai` stays React-free. This package mounts a provider that\n * drives `@adapttable/ai`'s table agent controller from React: it keeps the\n * controller's inputs current, re-renders on its snapshot and the table's\n * changes, and publishes what the controller holds as feature state.\n */\nimport {\n type AgentSession,\n createTableAgentController,\n TABLE_AGENT_STATE,\n type TableAgentBridge as NeutralBridge,\n type TableAgentController,\n type TableAgentControllerOptions,\n} from \"@adapttable/ai\";\nimport {\n AGENT_ALWAYS_ALLOW_STATE,\n AGENT_APPROVAL_STATE,\n AGENT_PROGRESS_STATE,\n AGENT_VIEW_STATE,\n type AgentApprovalPending,\n type FeatureProviderProps,\n FeatureStateScope,\n type StaticTableFeature,\n useTableRuntime,\n} from \"@adapttable/react/adapter\";\nimport {\n type ReactNode,\n useCallback,\n useDebugValue,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\n\nexport type { SharedApproval, TableAgentColumnPatch } from \"@adapttable/ai\";\n\n// The bridge contract is `@adapttable/ai`'s — a manifest, a session and a\n// pending approval are what any binding publishes, none of it React. Named\n// here with this binding's own pending shape so every existing import keeps\n// working.\nexport type TableAgentBridge = NeutralBridge<AgentApprovalPending>;\n\n// The live session's key is `@adapttable/ai`'s, so every agent binding\n// publishes and reads the same one.\nexport { TABLE_AGENT_STATE };\n\n/**\n * Options for {@link tableAgent}.\n *\n * The same options `@adapttable/ai`'s table agent controller takes: the\n * runtime half — identity, policy, columns, the host's callbacks and\n * capabilities — plus where updates are published and whether the table is\n * offered to a browser-resident agent.\n *\n * @public\n */\nexport type TableAgentOptions = TableAgentControllerOptions;\n\ninterface TableAgentFeature extends StaticTableFeature {\n readonly options: TableAgentOptions;\n}\n\nfunction TableAgentProvider({\n feature,\n children,\n}: Readonly<FeatureProviderProps>): ReactNode {\n const options = (feature as TableAgentFeature).options;\n const runtime = useTableRuntime();\n const optionsRef = useRef(options);\n optionsRef.current = options;\n const runtimeRef = useRef(runtime);\n runtimeRef.current = runtime;\n // A concrete provider update, rather than an empty `flushSync`, makes React\n // finish controlled-state work already queued by the reader before the\n // session takes its admission snapshot.\n const [admissionTick, setAdmissionTick] = useState(0);\n const flushAdmission = useRef<() => void>(() => undefined);\n flushAdmission.current = () => {\n flushSync(() => {\n setAdmissionTick(admissionTick + 1);\n });\n };\n\n // Built once and never during a render that is thrown away twice: the\n // controller opens nothing until `sync`, which only an effect calls.\n const controllerRef = useRef<TableAgentController | null>(null);\n controllerRef.current ??= createTableAgentController({\n options: optionsRef,\n runtime: runtimeRef,\n flushAdmission: () => {\n flushAdmission.current();\n },\n flush: flushSync,\n });\n const controller = controllerRef.current;\n\n // The table as a store: subscribe where there is one to subscribe to, and\n // read the stamp on every render either way. React re-reads the stamp after\n // it attaches, so a table that moved between the render and the\n // subscription is caught rather than missed. The value is not rendered;\n // re-rendering is the point, because that republishes the manifest.\n const neutralTable = runtime.view()?.neutralTable;\n // The controller subscribes to the table current at the call, so a\n // replaced table is a new subscription.\n const subscribeToTable = useCallback(\n (onStoreChange: () => void) =>\n neutralTable ? controller.subscribeTable(onStoreChange) : () => undefined,\n [controller, neutralTable]\n );\n const stamp = useSyncExternalStore(\n subscribeToTable,\n controller.tableStamp,\n controller.tableStamp\n );\n useDebugValue(stamp);\n\n const state = useSyncExternalStore(\n controller.subscribe,\n controller.getState,\n controller.getState\n );\n\n // Every commit: the controller decides what changed and tells only those\n // who need telling. A layout effect, so a host reading the manifest in its\n // own effects already has this render's.\n useLayoutEffect(() => {\n controller.sync();\n });\n\n // Going away is a close. Strict Mode's setup/cleanup/setup lands here too:\n // the cleanup releases everything, and the next sync sets it up again.\n useEffect(\n () => () => {\n controller.disconnect();\n },\n [controller]\n );\n\n // A new value every render on purpose. The table publishes its runtime\n // while its children render, after this provider has, so a surface below\n // learns what the session now offers only by re-rendering with it — and it\n // re-renders because the value it holds is a different one.\n const session = state.session;\n const published: AgentSession = {\n catalog: () => session.catalog(),\n describe: (key) => session.describe(key),\n execute: (key, args, expectedRevision, idempotencyKey, signal) =>\n session.execute(key, args, expectedRevision, idempotencyKey, signal),\n manifest: () => session.manifest(),\n };\n\n return (\n <FeatureStateScope stateKey={TABLE_AGENT_STATE} value={published}>\n <FeatureStateScope stateKey={AGENT_APPROVAL_STATE} value={state.approval}>\n <FeatureStateScope\n stateKey={AGENT_ALWAYS_ALLOW_STATE}\n value={state.alwaysAllow}\n >\n <FeatureStateScope stateKey={AGENT_VIEW_STATE} value={state.view}>\n <FeatureStateScope\n stateKey={AGENT_PROGRESS_STATE}\n value={state.progress}\n >\n {children}\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n </FeatureStateScope>\n );\n}\n\n/**\n * Observe a live table and publish a deterministic capability manifest.\n *\n * Omitting this feature from `features` ships no agent bytes.\n *\n * @public\n */\nexport function tableAgent(options: TableAgentOptions): StaticTableFeature {\n const feature: TableAgentFeature = {\n id: \"table-agent\",\n options,\n provider: { Provider: TableAgentProvider },\n };\n return feature;\n}\n","/**\n * Dictation, as a React hook — `@adapttable/ai-react`.\n *\n * Thin on purpose. The controller in `@adapttable/ai/voice` owns the browser\n * APIs, the permission states and the language choice; this subscribes to it,\n * keeps it alive for the life of the composer, and writes what it hears\n * through the caller's `setDraft` — which is the one channel voice is allowed\n * to use, so a spoken sentence becomes a draft the reader can see and fix\n * rather than a request the table has already acted on.\n *\n * It lives here rather than in `@adapttable/react` because it imports\n * `@adapttable/ai`, and that package must stay out of the base graph. The\n * chrome takes `SpeechInputHandle` — the structural shape this returns —\n * from `@adapttable/react/adapter`, which declares it without importing\n * anything.\n */\n\"use client\";\n\nimport {\n createSpeechInput,\n readRememberedLanguage,\n rememberLanguage,\n type SpeechClip,\n type SpeechInput,\n type SpeechState,\n type VoiceOptions,\n} from \"@adapttable/ai/voice\";\nimport type { SpeechInputHandle } from \"@adapttable/react/adapter\";\nimport { useEffect, useRef, useSyncExternalStore } from \"react\";\n\n/** How the hook is configured. @public */\nexport interface UseSpeechInputOptions {\n readonly voice?: VoiceOptions;\n /** The table's locale, used when no language list was given. */\n readonly locale?: string;\n /** Where heard text goes. Always the draft, never a send. */\n readonly setDraft: (text: string) => void;\n /** Where a recording goes, in backend mode. */\n readonly onClip?: (clip: SpeechClip) => void;\n}\n\nconst IDLE: SpeechState = { status: \"unsupported\", language: \"\", interim: \"\" };\n\n/**\n * Run dictation for one composer.\n *\n * @param options - Voice configuration and where heard text should go.\n * @returns What the composer needs, or an unavailable handle when voice is off.\n *\n * @public\n */\nexport function useSpeechInput(\n options: UseSpeechInputOptions\n): SpeechInputHandle {\n const { voice, locale, setDraft, onClip } = options;\n // Live callbacks, so the controller is built once and still calls whatever\n // the latest render passed rather than what the first one did.\n const draftRef = useRef(setDraft);\n draftRef.current = setDraft;\n const clipRef = useRef(onClip);\n clipRef.current = onClip;\n\n const languages = voice?.languages?.length\n ? voice.languages\n : [locale ?? \"en-US\"];\n const inputRef = useRef<SpeechInput | null>(null);\n if (voice && !inputRef.current) {\n inputRef.current = createSpeechInput({\n mode: voice.mode ?? \"browser\",\n languages,\n // Remembered from a previous visit when the browser kept it, and the\n // first offered language otherwise.\n ...(readRememberedLanguage()\n ? { initialLanguage: readRememberedLanguage() }\n : {}),\n onDraft: (text) => draftRef.current(text),\n onClip: (clip) => clipRef.current?.(clip),\n });\n }\n const input = inputRef.current;\n\n useEffect(\n () => () => {\n input?.dispose();\n // A disposed controller is never revived: a remount builds a fresh one,\n // the way the assistant store does.\n inputRef.current = null;\n },\n [input]\n );\n\n const state = useSyncExternalStore(\n (listener) => input?.subscribe(listener) ?? (() => undefined),\n () => input?.getState() ?? IDLE,\n () => IDLE\n );\n\n return {\n // Absent rather than dead: a mic that cannot listen is not drawn.\n available: Boolean(voice && input?.supported()),\n state,\n languages,\n start: () => input?.start(),\n stop: () => input?.stop(),\n setLanguage: (language) => {\n input?.setLanguage(language);\n rememberLanguage(language);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwRA,SAAgB,kBACd,SACqB;CACrB,MAAM,EAAE,iBAAiB;CACzB,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,KAAK;CAG9D,MAAM,WAAW,gBAAgB,oBAAoB;CAGrD,MAAM,cAAc,gBAAgB,wBAAwB;CAG5D,MAAM,YAAY,gBAAgB,gBAAgB;CAGlD,MAAM,WAAW,gBAAgB,oBAAoB;CAKrD,MAAM,WAAW,OAAuD,IAAI;CAC5E,SAAS,YAAY,qBACnB,SAAS,SAAS,UAAU,aAAa,WAAW,QAAQ,CAC9D;CACA,MAAM,QAAQ,SAAS;CAKvB,gBAAgB;EACd,MAAM,OAAO,SAAS,SAAS,UAAU,aAAa,WAAW,QAAQ,CAAC;CAC5E,CAAC;CAED,gBAAgB;EACd,MAAM,QAAQ;EACd,aAAa;GACX,MAAM,QAAQ;GAId,SAAS,UAAU;EACrB;CAIF,GAAG,CAAC,CAAC;CAEL,MAAM,QAAQ,qBACZ,MAAM,WACN,MAAM,UACN,MAAM,QACR;CAEA,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,UAAU,aACb,SAAkB;EACjB,IAAI,QAAQ,SAAS,KAAA,GAAW,oBAAoB,IAAI;EACxD,eAAe,IAAI;CACrB,GACA,CAAC,QAAQ,MAAM,YAAY,CAC7B;CAEA,OA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AO,UAAU,QAAQ,YAAY,KAAA,UAC7C,OAAO,SAAS,KAAK,YACrB,IACR;CAEA,OAAO;EAEL,WAAW,QAAQ,SAAS,OAAO,UAAU,CAAC;EAC9C;EACA;EACA,aAAa,OAAO,MAAM;EAC1B,YAAY,OAAO,KAAK;EACxB,cAAc,aAAa;GACzB,OAAO,YAAY,QAAQ;GAC3B,iBAAiB,QAAQ;EAC3B;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adapttable/ai-react",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "React bindings for AdaptTable AI — tableAgent and useTableAssistant.",
5
5
  "keywords": [
6
6
  "react",
@@ -44,9 +44,9 @@
44
44
  "./package.json": "./package.json"
45
45
  },
46
46
  "dependencies": {
47
- "@adapttable/ai": "0.4.0",
48
- "@adapttable/core": "3.6.0",
49
- "@adapttable/react": "1.3.6",
47
+ "@adapttable/ai": "0.5.1",
48
+ "@adapttable/core": "3.8.0",
49
+ "@adapttable/react": "1.5.0",
50
50
  "react-compiler-runtime": "^1.0.0"
51
51
  },
52
52
  "peerDependencies": {