@adapttable/ai-react 0.2.23 → 0.2.24

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,57 @@
1
1
  # @adapttable/ai-react
2
2
 
3
+ ## 0.2.24
4
+
5
+ ### Patch Changes
6
+
7
+ - 923b252: A table agent loads the WebMCP registrar only when it sets `webmcp`. The controller is also on the new `@adapttable/ai/agent` entry, which the React, Vue and Angular bindings now use, so `tableAgent` starts 0.54–0.58 KiB smaller in each framework and the registrar arrives as a 1.1 KiB chunk the first time a table offers itself to a page agent.
8
+ - Updated dependencies [923b252]
9
+ - Updated dependencies [d1f33b7]
10
+ - Updated dependencies [501fb5c]
11
+ - Updated dependencies [35abf7a]
12
+ - Updated dependencies [340c486]
13
+ - Updated dependencies [f94d978]
14
+ - Updated dependencies [e0ed9dd]
15
+ - Updated dependencies [5545290]
16
+ - Updated dependencies [1bf65dd]
17
+ - Updated dependencies [ee0f202]
18
+ - Updated dependencies [536aa89]
19
+ - Updated dependencies [04d741f]
20
+ - Updated dependencies [cdbba81]
21
+ - Updated dependencies [cb9f9db]
22
+ - Updated dependencies [da4baa0]
23
+ - Updated dependencies [bee0c9f]
24
+ - Updated dependencies [636d0ad]
25
+ - Updated dependencies [8af4736]
26
+ - Updated dependencies [bb9ee7a]
27
+ - Updated dependencies [633e23c]
28
+ - Updated dependencies [ed8a86d]
29
+ - Updated dependencies [d2beb5a]
30
+ - Updated dependencies [a96cfee]
31
+ - Updated dependencies [fbc52e8]
32
+ - Updated dependencies [7ad8d9a]
33
+ - Updated dependencies [03d7f36]
34
+ - Updated dependencies [08245ea]
35
+ - Updated dependencies [5d503be]
36
+ - Updated dependencies [bb4e606]
37
+ - Updated dependencies [ffd1a07]
38
+ - Updated dependencies [ad4c90a]
39
+ - Updated dependencies [3ecb133]
40
+ - Updated dependencies [5a791f2]
41
+ - Updated dependencies [3c0ae19]
42
+ - Updated dependencies [6612d37]
43
+ - Updated dependencies [c60895f]
44
+ - Updated dependencies [48cea86]
45
+ - Updated dependencies [d1b7ece]
46
+ - Updated dependencies [1bfa985]
47
+ - Updated dependencies [4effc96]
48
+ - Updated dependencies [eb084d0]
49
+ - Updated dependencies [5b7bc3c]
50
+ - Updated dependencies [b36d160]
51
+ - Updated dependencies [3b2a5bd]
52
+ - @adapttable/ai@0.8.0
53
+ - @adapttable/react@2.0.0
54
+
3
55
  ## 0.2.23
4
56
 
5
57
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1,8 +1,10 @@
1
1
  "use client";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- let _adapttable_ai = require("@adapttable/ai");
3
+ require("@adapttable/ai");
4
+ let _adapttable_ai_assistant = require("@adapttable/ai/assistant");
4
5
  let _adapttable_react_adapter = require("@adapttable/react/adapter");
5
6
  let react = require("react");
7
+ let _adapttable_ai_agent = require("@adapttable/ai/agent");
6
8
  let react_dom = require("react-dom");
7
9
  let react_jsx_runtime = require("react/jsx-runtime");
8
10
  let _adapttable_ai_voice = require("@adapttable/ai/voice");
@@ -55,10 +57,10 @@ function useTableAssistant(options) {
55
57
  viewState,
56
58
  progress
57
59
  };
58
- storeRef.current ??= (0, _adapttable_ai.createTableAssistant)((0, _adapttable_ai.tableAssistantInputs)(options, table));
60
+ storeRef.current ??= (0, _adapttable_ai_assistant.createTableAssistant)((0, _adapttable_ai_assistant.tableAssistantInputs)(options, table));
59
61
  const store = storeRef.current;
60
62
  (0, react.useEffect)(() => {
61
- store.update((0, _adapttable_ai.tableAssistantInputs)(options, table));
63
+ store.update((0, _adapttable_ai_assistant.tableAssistantInputs)(options, table));
62
64
  });
63
65
  (0, react.useEffect)(() => {
64
66
  const mount = { superseded: false };
@@ -79,7 +81,7 @@ function useTableAssistant(options) {
79
81
  onOpenChange?.(next);
80
82
  }, [options.open, onOpenChange]);
81
83
  return {
82
- ...(0, _adapttable_ai.tableAssistantFields)(state, store),
84
+ ...(0, _adapttable_ai_assistant.tableAssistantFields)(state, store),
83
85
  approval: approval ?? null,
84
86
  open,
85
87
  setOpen
@@ -110,7 +112,7 @@ function TableAgentProvider({ feature, children }) {
110
112
  });
111
113
  };
112
114
  const controllerRef = (0, react.useRef)(null);
113
- controllerRef.current ??= (0, _adapttable_ai.createTableAgentController)({
115
+ controllerRef.current ??= (0, _adapttable_ai_agent.createTableAgentController)({
114
116
  options: optionsRef,
115
117
  runtime: runtimeRef,
116
118
  flushAdmission: () => {
@@ -132,7 +134,7 @@ function TableAgentProvider({ feature, children }) {
132
134
  }, [controller]);
133
135
  const session = state.session;
134
136
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_adapttable_react_adapter.FeatureStateScope, {
135
- stateKey: _adapttable_ai.TABLE_AGENT_STATE,
137
+ stateKey: _adapttable_ai_agent.TABLE_AGENT_STATE,
136
138
  value: {
137
139
  catalog: () => session.catalog(),
138
140
  describe: (key) => session.describe(key),
@@ -210,7 +212,7 @@ function useSpeechInput(options) {
210
212
  return (0, react.useSyncExternalStore)(session.subscribe, session.getSnapshot, session.getSnapshot);
211
213
  }
212
214
  //#endregion
213
- exports.TABLE_AGENT_STATE = _adapttable_ai.TABLE_AGENT_STATE;
215
+ exports.TABLE_AGENT_STATE = _adapttable_ai_agent.TABLE_AGENT_STATE;
214
216
  exports.tableAgent = tableAgent;
215
217
  exports.useSpeechInput = useSpeechInput;
216
218
  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","tableAssistantInputs","useSyncExternalStore","useCallback","tableAssistantFields","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","useState","createSpeechSession","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 type AssistantUndoView,\n createTableAssistant,\n tableAssistantFields,\n tableAssistantInputs,\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 AgentProgress,\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. Defaults to whether the table has a write\n * waiting on the reader; a host that renders the approval elsewhere — or\n * wires `bridge.approvals` — passes it 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: AssistantUndoView | 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 `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 const mountRef = useRef<{ superseded: boolean } | null>(null);\n const table = { approval, alwaysAllow, viewState, progress };\n storeRef.current ??= createTableAssistant(\n tableAssistantInputs(options, table)\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(tableAssistantInputs(options, table));\n });\n\n useEffect(() => {\n const mount = { superseded: false };\n if (mountRef.current) mountRef.current.superseded = true;\n mountRef.current = mount;\n store.connect();\n return () => {\n // React may replay this effect without rendering a replacement store.\n // Release the connection, retaining the inert controller for that next\n // setup. This also hands durable work to the host before unmounting.\n // useSyncExternalStore removes its own subscription on cleanup.\n store.disconnect();\n queueMicrotask(() => {\n if (!mount.superseded) store.dispose();\n });\n };\n }, [store]);\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 ...tableAssistantFields(state, store),\n approval: approval ?? null,\n open,\n setOpen,\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 speech session in `@adapttable/ai/voice` owns the\n * browser APIs, the permission states, the language choice and when the\n * microphone is replaced; this subscribes to it, keeps it alive for the life\n * of the composer, and writes what it hears through the caller's `setDraft` —\n * which is the one channel voice is allowed to use, so a spoken sentence\n * becomes a draft the reader can see and fix rather than a request the table\n * 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 createSpeechSession,\n type SpeechClip,\n type VoiceOptions,\n} from \"@adapttable/ai/voice\";\nimport type { SpeechInputHandle } from \"@adapttable/react/adapter\";\nimport { useEffect, useRef, useState, 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\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 // The latest options, read by the session whenever it needs them, so heard\n // text reaches whatever the latest render passed.\n const latest = useRef(options);\n latest.current = options;\n const [session] = useState(() => createSpeechSession(() => latest.current));\n // Every commit brings the microphone in line with the options; equivalent\n // options keep the one that is listening.\n useEffect(() => {\n session.sync();\n });\n // Strict Mode releases and syncs again, so each setup owns a live controller.\n useEffect(() => () => session.release(), [session]);\n return useSyncExternalStore(\n session.subscribe,\n session.getSnapshot,\n session.getSnapshot\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsRA,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,MA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QAAA,GAAOC,MAAAA,qBAAAA,CACL,QAAQ,WACR,QAAQ,aACR,QAAQ,WACV;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","tableAssistantInputs","useSyncExternalStore","useCallback","tableAssistantFields","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","useState","createSpeechSession","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 type AssistantUndoView,\n} from \"@adapttable/ai\";\nimport {\n createTableAssistant,\n tableAssistantFields,\n tableAssistantInputs,\n} from \"@adapttable/ai/assistant\";\nimport {\n AGENT_ALWAYS_ALLOW_STATE,\n AGENT_APPROVAL_STATE,\n AGENT_PROGRESS_STATE,\n AGENT_VIEW_STATE,\n type AgentApprovalPending,\n type AgentProgress,\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. Defaults to whether the table has a write\n * waiting on the reader; a host that renders the approval elsewhere — or\n * wires `bridge.approvals` — passes it 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: AssistantUndoView | 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 `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 const mountRef = useRef<{ superseded: boolean } | null>(null);\n const table = { approval, alwaysAllow, viewState, progress };\n storeRef.current ??= createTableAssistant(\n tableAssistantInputs(options, table)\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(tableAssistantInputs(options, table));\n });\n\n useEffect(() => {\n const mount = { superseded: false };\n if (mountRef.current) mountRef.current.superseded = true;\n mountRef.current = mount;\n store.connect();\n return () => {\n // React may replay this effect without rendering a replacement store.\n // Release the connection, retaining the inert controller for that next\n // setup. This also hands durable work to the host before unmounting.\n // useSyncExternalStore removes its own subscription on cleanup.\n store.disconnect();\n queueMicrotask(() => {\n if (!mount.superseded) store.dispose();\n });\n };\n }, [store]);\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 ...tableAssistantFields(state, store),\n approval: approval ?? null,\n open,\n setOpen,\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 type TableAgentBridge as NeutralBridge,\n type TableAgentController,\n type TableAgentControllerOptions,\n} from \"@adapttable/ai\";\nimport {\n createTableAgentController,\n TABLE_AGENT_STATE,\n} from \"@adapttable/ai/agent\";\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 speech session in `@adapttable/ai/voice` owns the\n * browser APIs, the permission states, the language choice and when the\n * microphone is replaced; this subscribes to it, keeps it alive for the life\n * of the composer, and writes what it hears through the caller's `setDraft` —\n * which is the one channel voice is allowed to use, so a spoken sentence\n * becomes a draft the reader can see and fix rather than a request the table\n * 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 createSpeechSession,\n type SpeechClip,\n type VoiceOptions,\n} from \"@adapttable/ai/voice\";\nimport type { SpeechInputHandle } from \"@adapttable/react/adapter\";\nimport { useEffect, useRef, useState, 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\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 // The latest options, read by the session whenever it needs them, so heard\n // text reaches whatever the latest render passed.\n const latest = useRef(options);\n latest.current = options;\n const [session] = useState(() => createSpeechSession(() => latest.current));\n // Every commit brings the microphone in line with the options; equivalent\n // options keep the one that is listening.\n useEffect(() => {\n session.sync();\n });\n // Strict Mode releases and syncs again, so each setup owns a live controller.\n useEffect(() => () => session.release(), [session]);\n return useSyncExternalStore(\n session.subscribe,\n session.getSnapshot,\n session.getSnapshot\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,MAAM,YAAA,GAAWA,MAAAA,OAAAA,CAAuC,IAAI;CAC5D,MAAM,QAAQ;EAAE;EAAU;EAAa;EAAW;CAAS;CAC3D,SAAS,aAAA,GAAYC,yBAAAA,qBAAAA,EAAAA,GACnBC,yBAAAA,qBAAAA,CAAqB,SAAS,KAAK,CACrC;CACA,MAAM,QAAQ,SAAS;CAKvB,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,QAAA,GAAOA,yBAAAA,qBAAAA,CAAqB,SAAS,KAAK,CAAC;CACnD,CAAC;CAED,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,QAAQ,EAAE,YAAY,MAAM;EAClC,IAAI,SAAS,SAAS,SAAS,QAAQ,aAAa;EACpD,SAAS,UAAU;EACnB,MAAM,QAAQ;EACd,aAAa;GAKX,MAAM,WAAW;GACjB,qBAAqB;IACnB,IAAI,CAAC,MAAM,YAAY,MAAM,QAAQ;GACvC,CAAC;EACH;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D;CAMzE,OAAO;EAJL,IAAI;EACJ;EACA,UAAU,EAAE,UAAU,mBAAmB;CAE9B;AACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACnJA,SAAgB,eACd,SACmB;CAGnB,MAAM,UAAA,GAASC,MAAAA,OAAAA,CAAO,OAAO;CAC7B,OAAO,UAAU;CACjB,MAAM,CAAC,YAAA,GAAWC,MAAAA,SAAAA,QAAAA,GAAeC,qBAAAA,oBAAAA,OAA0B,OAAO,OAAO,CAAC;CAG1E,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,QAAQ,KAAK;CACf,CAAC;CAED,CAAA,GAAA,MAAA,UAAA,aAAsB,QAAQ,QAAQ,GAAG,CAAC,OAAO,CAAC;CAClD,QAAA,GAAOC,MAAAA,qBAAAA,CACL,QAAQ,WACR,QAAQ,aACR,QAAQ,WACV;AACF"}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
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, AssistantUndoView, SharedApproval, TABLE_AGENT_STATE, 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, AssistantUndoView, SharedApproval, TableAgentBridge as TableAgentBridge$1, TableAgentColumnPatch, TableAgentControllerOptions, TableAssistantSnapshot, TableAssistantStore } from "@adapttable/ai";
3
3
  import { AgentApprovalPending, AgentProgress, SpeechInputHandle, StaticTableFeature } from "@adapttable/react/adapter";
4
+ import { TABLE_AGENT_STATE } from "@adapttable/ai/agent";
4
5
  import { SpeechClip, VoiceOptions } from "@adapttable/ai/voice";
5
6
  //#region src/assistant.d.ts
6
7
  /** How {@link useTableAssistant} is configured. @public */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"mappings":";;;;;;UAqFiB;;WAEN,SAAS;;;;;;;;WAQT,YAAY;;;;;;;;;;WAUZ;;WAEA,uBAAuB;;WAEvB;;WAEA,gBAAgB;;;;;;;;;;WAUhB;;;;;;;;;;;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,MAAM;;WAEN,gBAAgB;;WAEhB,aAAa,2BAA2B;;WAExC,wBAAwB;;WAExB,oBAAoB;;WAEpB,sBAAsB;;WAEtB,gBAAgB,eAAe;WAC/B;WACA,UAAU;;WAEV;;;;;;WAMA;;;;;;;;;;;;;;iBAeK,kBACd,SAAS,wBACR;;;KC3OS,mBAAmB,mBAAc;;;;;;;;;;;KAgBjC,oBAAoB;;;;;;;;iBA2HhB,WAAW,SAAS,oBAAoB;;;;UC5JvC;WACN,QAAQ;;WAER;;WAEA,WAAW;;WAEX,UAAU,MAAM;;;;;;;;;;iBAWX,eACd,SAAS,wBACR"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"mappings":";;;;;;;UAuFiB;;WAEN,SAAS;;;;;;;;WAQT,YAAY;;;;;;;;;;WAUZ;;WAEA,uBAAuB;;WAEvB;;WAEA,gBAAgB;;;;;;;;;;WAUhB;;;;;;;;;;;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,MAAM;;WAEN,gBAAgB;;WAEhB,aAAa,2BAA2B;;WAExC,wBAAwB;;WAExB,oBAAoB;;WAEpB,sBAAsB;;WAEtB,gBAAgB,eAAe;WAC/B;WACA,UAAU;;WAEV;;;;;;WAMA;;;;;;;;;;;;;;iBAeK,kBACd,SAAS,wBACR;;;KC3OS,mBAAmB,mBAAc;;;;;;;;;;;KAgBjC,oBAAoB;;;;;;;;iBA2HhB,WAAW,SAAS,oBAAoB;;;;UC9JvC;WACN,QAAQ;;WAER;;WAEA,WAAW;;WAEX,UAAU,MAAM;;;;;;;;;;iBAWX,eACd,SAAS,wBACR"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
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, AssistantUndoView, SharedApproval, TABLE_AGENT_STATE, 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, AssistantUndoView, SharedApproval, TableAgentBridge as TableAgentBridge$1, TableAgentColumnPatch, TableAgentControllerOptions, TableAssistantSnapshot, TableAssistantStore } from "@adapttable/ai";
3
3
  import { AgentApprovalPending, AgentProgress, SpeechInputHandle, StaticTableFeature } from "@adapttable/react/adapter";
4
+ import { TABLE_AGENT_STATE } from "@adapttable/ai/agent";
4
5
  import { SpeechClip, VoiceOptions } from "@adapttable/ai/voice";
5
6
  //#region src/assistant.d.ts
6
7
  /** How {@link useTableAssistant} is configured. @public */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"mappings":";;;;;;UAqFiB;;WAEN,SAAS;;;;;;;;WAQT,YAAY;;;;;;;;;;WAUZ;;WAEA,uBAAuB;;WAEvB;;WAEA,gBAAgB;;;;;;;;;;WAUhB;;;;;;;;;;;WAWA,cAAc;;;;;;;;WAQd,sBAAsB;;;;;;;;;WAStB,YAAY,QAAQ;;WAEpB,eAAe;;;;;;;;;WASf,oBAAoB;;WAEpB,oBAAoB,mBAAmB;;;;;;;;;WASvC;;;UAIM;WACN,QAAQ;;;;;;;;WAQR;WACA,mBAAmB;WACnB;WACA,WAAW;;W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WAEN,gBAAgB;;WAEhB,aAAa,2BAA2B;;WAExC,wBAAwB;;WAExB,oBAAoB;;WAEpB,sBAAsB;;WAEtB,gBAAgB,eAAe;WAC/B;WACA,UAAU;;WAEV;;;;;;WAMA;;;;;;;;;;;;;;iBAeK,kBACd,SAAS,wBACR;;;KC3OS,mBAAmB,mBAAc;;;;;;;;;;;KAgBjC,oBAAoB;;;;;;;;iBA2HhB,WAAW,SAAS,oBAAoB;;;;UC9JvC;WACN,QAAQ;;WAER;;WAEA,WAAW;;WAEX,UAAU,MAAM;;;;;;;;;;iBAWX,eACd,SAAS,wBACR"}
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use client";
2
- import { TABLE_AGENT_STATE, createTableAgentController, createTableAssistant, tableAssistantFields, tableAssistantInputs } from "@adapttable/ai";
2
+ import "@adapttable/ai";
3
+ import { createTableAssistant, tableAssistantFields, tableAssistantInputs } from "@adapttable/ai/assistant";
3
4
  import { AGENT_ALWAYS_ALLOW_STATE, AGENT_APPROVAL_STATE, AGENT_PROGRESS_STATE, AGENT_VIEW_STATE, FeatureStateScope, useFeatureState, useTableRuntime } from "@adapttable/react/adapter";
4
5
  import { useCallback, useDebugValue, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
6
+ import { TABLE_AGENT_STATE, createTableAgentController } from "@adapttable/ai/agent";
5
7
  import { flushSync } from "react-dom";
6
8
  import { jsx } from "react/jsx-runtime";
7
9
  import { createSpeechSession } from "@adapttable/ai/voice";
@@ -86,14 +88,6 @@ function useTableAssistant(options) {
86
88
  }
87
89
  //#endregion
88
90
  //#region src/react.tsx
89
- /**
90
- * Opt-in table feature — `@adapttable/ai-react`.
91
- *
92
- * `@adapttable/ai` stays React-free. This package mounts a provider that
93
- * drives `@adapttable/ai`'s table agent controller from React: it keeps the
94
- * controller's inputs current, re-renders on its snapshot and the table's
95
- * changes, and publishes what the controller holds as feature state.
96
- */
97
91
  function TableAgentProvider({ feature, children }) {
98
92
  const options = feature.options;
99
93
  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 type AssistantUndoView,\n createTableAssistant,\n tableAssistantFields,\n tableAssistantInputs,\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 AgentProgress,\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. Defaults to whether the table has a write\n * waiting on the reader; a host that renders the approval elsewhere — or\n * wires `bridge.approvals` — passes it 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: AssistantUndoView | 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 `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 const mountRef = useRef<{ superseded: boolean } | null>(null);\n const table = { approval, alwaysAllow, viewState, progress };\n storeRef.current ??= createTableAssistant(\n tableAssistantInputs(options, table)\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(tableAssistantInputs(options, table));\n });\n\n useEffect(() => {\n const mount = { superseded: false };\n if (mountRef.current) mountRef.current.superseded = true;\n mountRef.current = mount;\n store.connect();\n return () => {\n // React may replay this effect without rendering a replacement store.\n // Release the connection, retaining the inert controller for that next\n // setup. This also hands durable work to the host before unmounting.\n // useSyncExternalStore removes its own subscription on cleanup.\n store.disconnect();\n queueMicrotask(() => {\n if (!mount.superseded) store.dispose();\n });\n };\n }, [store]);\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 ...tableAssistantFields(state, store),\n approval: approval ?? null,\n open,\n setOpen,\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 speech session in `@adapttable/ai/voice` owns the\n * browser APIs, the permission states, the language choice and when the\n * microphone is replaced; this subscribes to it, keeps it alive for the life\n * of the composer, and writes what it hears through the caller's `setDraft` —\n * which is the one channel voice is allowed to use, so a spoken sentence\n * becomes a draft the reader can see and fix rather than a request the table\n * 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 createSpeechSession,\n type SpeechClip,\n type VoiceOptions,\n} from \"@adapttable/ai/voice\";\nimport type { SpeechInputHandle } from \"@adapttable/react/adapter\";\nimport { useEffect, useRef, useState, 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\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 // The latest options, read by the session whenever it needs them, so heard\n // text reaches whatever the latest render passed.\n const latest = useRef(options);\n latest.current = options;\n const [session] = useState(() => createSpeechSession(() => latest.current));\n // Every commit brings the microphone in line with the options; equivalent\n // options keep the one that is listening.\n useEffect(() => {\n session.sync();\n });\n // Strict Mode releases and syncs again, so each setup owns a live controller.\n useEffect(() => () => session.release(), [session]);\n return useSyncExternalStore(\n session.subscribe,\n session.getSnapshot,\n session.getSnapshot\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsRA,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,oBAAo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;;;;;;ACjJA,SAAgB,eACd,SACmB;CAGnB,MAAM,SAAS,OAAO,OAAO;CAC7B,OAAO,UAAU;CACjB,MAAM,CAAC,WAAW,eAAe,0BAA0B,OAAO,OAAO,CAAC;CAG1E,gBAAgB;EACd,QAAQ,KAAK;CACf,CAAC;CAED,sBAAsB,QAAQ,QAAQ,GAAG,CAAC,OAAO,CAAC;CAClD,OAAO,qBACL,QAAQ,WACR,QAAQ,aACR,QAAQ,WACV;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 type AssistantUndoView,\n} from \"@adapttable/ai\";\nimport {\n createTableAssistant,\n tableAssistantFields,\n tableAssistantInputs,\n} from \"@adapttable/ai/assistant\";\nimport {\n AGENT_ALWAYS_ALLOW_STATE,\n AGENT_APPROVAL_STATE,\n AGENT_PROGRESS_STATE,\n AGENT_VIEW_STATE,\n type AgentApprovalPending,\n type AgentProgress,\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. Defaults to whether the table has a write\n * waiting on the reader; a host that renders the approval elsewhere — or\n * wires `bridge.approvals` — passes it 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: AssistantUndoView | 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 `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 const mountRef = useRef<{ superseded: boolean } | null>(null);\n const table = { approval, alwaysAllow, viewState, progress };\n storeRef.current ??= createTableAssistant(\n tableAssistantInputs(options, table)\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(tableAssistantInputs(options, table));\n });\n\n useEffect(() => {\n const mount = { superseded: false };\n if (mountRef.current) mountRef.current.superseded = true;\n mountRef.current = mount;\n store.connect();\n return () => {\n // React may replay this effect without rendering a replacement store.\n // Release the connection, retaining the inert controller for that next\n // setup. This also hands durable work to the host before unmounting.\n // useSyncExternalStore removes its own subscription on cleanup.\n store.disconnect();\n queueMicrotask(() => {\n if (!mount.superseded) store.dispose();\n });\n };\n }, [store]);\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 ...tableAssistantFields(state, store),\n approval: approval ?? null,\n open,\n setOpen,\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 type TableAgentBridge as NeutralBridge,\n type TableAgentController,\n type TableAgentControllerOptions,\n} from \"@adapttable/ai\";\nimport {\n createTableAgentController,\n TABLE_AGENT_STATE,\n} from \"@adapttable/ai/agent\";\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 speech session in `@adapttable/ai/voice` owns the\n * browser APIs, the permission states, the language choice and when the\n * microphone is replaced; this subscribes to it, keeps it alive for the life\n * of the composer, and writes what it hears through the caller's `setDraft` —\n * which is the one channel voice is allowed to use, so a spoken sentence\n * becomes a draft the reader can see and fix rather than a request the table\n * 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 createSpeechSession,\n type SpeechClip,\n type VoiceOptions,\n} from \"@adapttable/ai/voice\";\nimport type { SpeechInputHandle } from \"@adapttable/react/adapter\";\nimport { useEffect, useRef, useState, 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\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 // The latest options, read by the session whenever it needs them, so heard\n // text reaches whatever the latest render passed.\n const latest = useRef(options);\n latest.current = options;\n const [session] = useState(() => createSpeechSession(() => latest.current));\n // Every commit brings the microphone in line with the options; equivalent\n // options keep the one that is listening.\n useEffect(() => {\n session.sync();\n });\n // Strict Mode releases and syncs again, so each setup owns a live controller.\n useEffect(() => () => session.release(), [session]);\n return useSyncExternalStore(\n session.subscribe,\n session.getSnapshot,\n session.getSnapshot\n );\n}\n"],"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AmB,UAAU;KAAkB,OAAO,MAAM;KAC1D,UAAA,oBAAC,mBAAD;MACE,UAAU;MACV,OAAO,MAAM;MAEZ;KACgB,CAAA;IACF,CAAA;GACF,CAAA;EACF,CAAA;CACF,CAAA;AAEvB;;;;;;;;AASA,SAAgB,WAAW,SAAgD;CAMzE,OAAO;EAJL,IAAI;EACJ;EACA,UAAU,EAAE,UAAU,mBAAmB;CAE9B;AACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACnJA,SAAgB,eACd,SACmB;CAGnB,MAAM,SAAS,OAAO,OAAO;CAC7B,OAAO,UAAU;CACjB,MAAM,CAAC,WAAW,eAAe,0BAA0B,OAAO,OAAO,CAAC;CAG1E,gBAAgB;EACd,QAAQ,KAAK;CACf,CAAC;CAED,sBAAsB,QAAQ,QAAQ,GAAG,CAAC,OAAO,CAAC;CAClD,OAAO,qBACL,QAAQ,WACR,QAAQ,aACR,QAAQ,WACV;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adapttable/ai-react",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "description": "React bindings for AdaptTable AI — tableAgent and useTableAssistant.",
5
5
  "keywords": [
6
6
  "react",
@@ -44,8 +44,8 @@
44
44
  "./package.json": "./package.json"
45
45
  },
46
46
  "dependencies": {
47
- "@adapttable/ai": "0.7.2",
48
- "@adapttable/react": "1.12.0",
47
+ "@adapttable/ai": "0.8.0",
48
+ "@adapttable/react": "2.0.0",
49
49
  "react-compiler-runtime": "^1.0.0"
50
50
  },
51
51
  "peerDependencies": {
@@ -53,7 +53,7 @@
53
53
  "react-dom": "^18.0.0 || ^19.0.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@adapttable/unstyled": "3.6.0",
56
+ "@adapttable/unstyled": "4.0.0",
57
57
  "@testing-library/react": "^16.3.2",
58
58
  "react": "^19.2.8",
59
59
  "react-dom": "^19.2.8"