@adapttable/ai-react 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,317 @@
1
+
2
+ import { AgentApply, AgentCapabilityDefinition, AgentContextInputs, AgentObservation, AgentSession, AlwaysAllowedState, ApprovalResult, ApprovalSubject, AssistantAllowance, AssistantAnswer, AssistantInterruption, AssistantInterruption as AssistantInterruption$1, AssistantMessage, AssistantQuestion, AssistantResumeHandle, AssistantResumeHandle as AssistantResumeHandle$1, AssistantStatus, AssistantSuggestion, AssistantSuggestion as AssistantSuggestion$1, AssistantTransport, CommitPolicy, SharedApproval, TableAgentBridge as TableAgentBridge$1, TableAgentColumnPatch, TableAssistantSnapshot, TableAssistantStore, WritePolicy } from "@adapttable/ai";
3
+ import { AgentApprovalPending, AgentProgress, SpeechInputHandle, StaticTableFeature } from "@adapttable/react/adapter";
4
+ import { ActionAiOptions } from "@adapttable/core";
5
+ import { SpeechClip, VoiceOptions } from "@adapttable/ai/voice";
6
+ //#region src/assistant.d.ts
7
+ /** How {@link useTableAssistant} is configured. @public */
8
+ interface TableAssistantOptions {
9
+ /** The live session. Changing it starts a new conversation. */
10
+ readonly session: AgentSession | undefined;
11
+ /**
12
+ * Where a turn goes. Omit and the assistant stays disconnected.
13
+ *
14
+ * May be a fresh object every render — the controller reads the latest one
15
+ * rather than reconnecting on its identity, so a host is not forced to
16
+ * memoize it.
17
+ */
18
+ readonly transport?: AssistantTransport;
19
+ /**
20
+ * Changes when the transport should be re-established.
21
+ *
22
+ * The conversation resets on a new session, because that is a new table.
23
+ * Swapping one transport for another — a backend for a scripted one — is
24
+ * not visible in the object identity, so a host that does it names the
25
+ * change here. A backend transport must never quietly become a simulated
26
+ * one under the same key.
27
+ */
28
+ readonly transportKey?: string;
29
+ /** Everything authored, filtered live against what the table offers. */
30
+ readonly suggestions?: readonly AssistantSuggestion$1[];
31
+ /** Controlled panel state. Omit for uncontrolled. */
32
+ readonly open?: boolean;
33
+ /** Called on every open/close request, controlled or not. */
34
+ readonly onOpenChange?: (open: boolean) => void;
35
+ /**
36
+ * Whether a write from this conversation is waiting on a human.
37
+ *
38
+ * `execute` does not return while an approval is open, so the turn looks
39
+ * like thinking from in here. A host that renders the approval — or wires
40
+ * `bridge.approvals` — passes it back so the panel can say what is
41
+ * actually happening. The turn is still in flight and still stoppable.
42
+ */
43
+ readonly awaitingApproval?: boolean;
44
+ /**
45
+ * What the reader has waved through, when the panel is mounted outside the
46
+ * table.
47
+ *
48
+ * A panel inside the table reads this from feature state and needs nothing
49
+ * here. One beside it cannot, so a host wires `bridge.alwaysAllowed` and
50
+ * passes what it publishes — the same arrangement `bridge.approvals` and
51
+ * `bridge.viewInputs` already have. Without it a reader can wave a
52
+ * capability through and have no way to take it back.
53
+ */
54
+ readonly alwaysAllow?: AlwaysAllowedState;
55
+ /**
56
+ * Live view and filter data the manifest does not carry.
57
+ *
58
+ * Read when a turn starts and again when it settles, so per-turn undo can
59
+ * tell what the turn moved. A function rather than a value: a fixed object
60
+ * would report that nothing changed.
61
+ */
62
+ readonly contextInputs?: () => AgentContextInputs;
63
+ /**
64
+ * Work that outlived its connection, handed over the moment it does.
65
+ *
66
+ * Durable recovery starts here and ends outside this package: a host that
67
+ * stores the handle where it survives a reload can offer a resume when the
68
+ * reader comes back, and a host that does nothing loses the work with the
69
+ * page.
70
+ */
71
+ readonly onDetach?: (handle: AssistantResumeHandle$1) => void;
72
+ /** A handle kept from a previous page, to resume into this one. */
73
+ readonly resumeHandle?: AssistantResumeHandle$1;
74
+ /**
75
+ * The transcript, when your app owns it.
76
+ *
77
+ * Omit it and the conversation lives in the controller. Supply it to load
78
+ * the last conversation from your own API, append a message that arrived on
79
+ * a socket, or keep it where it survives a reload — pass a new array and the
80
+ * panel shows it. Pair it with `onMessagesChange`.
81
+ */
82
+ readonly messages?: readonly AssistantMessage[];
83
+ /** Told whenever the transcript changes, with the whole of it. */
84
+ readonly onMessagesChange?: (messages: readonly AssistantMessage[]) => void;
85
+ /**
86
+ * How much of the conversation travels with each turn.
87
+ *
88
+ * `"full"` (default) sends every earlier message, for a backend that
89
+ * remembers nothing. A number sends that many of the most recent. `0` sends
90
+ * none — the reader's message still travels, and a backend holding its own
91
+ * session supplies the rest. What the reader sees is never trimmed.
92
+ */
93
+ readonly conversation?: "full" | number;
94
+ }
95
+ /** What a host renders from. @public */
96
+ interface TableAssistantState {
97
+ readonly status: AssistantStatus;
98
+ /**
99
+ * Whether a turn is in flight and can still be stopped.
100
+ *
101
+ * Separate from {@link TableAssistantState.status}: a write parked on a
102
+ * human approval reports `awaiting-approval` but is still running, and
103
+ * Stop still ends it.
104
+ */
105
+ readonly busy: boolean;
106
+ readonly messages: readonly AssistantMessage[];
107
+ readonly draft: string;
108
+ readonly setDraft: (draft: string) => void;
109
+ /** Send the draft, or the given text. Resolves when the turn settles. */
110
+ readonly send: (text?: string) => Promise<void>;
111
+ /** Abort the turn in flight. Safe to call when nothing is in flight. */
112
+ readonly stop: () => void;
113
+ /**
114
+ * Rejoin work a released connection left running.
115
+ *
116
+ * A no-op with nothing to rejoin, which is what `resumable` says.
117
+ */
118
+ readonly resume: () => Promise<void>;
119
+ /**
120
+ * What became of the last turn, when no reply ended it.
121
+ *
122
+ * `"stopped"` is the reader's own decision; `"detached"` is a released
123
+ * connection, where the work may still be running.
124
+ */
125
+ readonly interrupted: AssistantInterruption$1 | undefined;
126
+ /** The work `resume` would rejoin, or nothing. */
127
+ readonly resumable: AssistantResumeHandle$1 | undefined;
128
+ /** Drop the transcript. Refuses while a turn is in flight. */
129
+ readonly clear: () => void;
130
+ /**
131
+ * A write waiting on the reader, or nothing.
132
+ *
133
+ * Hand it to the panel as `approval` and the conversation reviews it —
134
+ * which is where a write asked for in the conversation belongs. The panel
135
+ * draws it only when the approval's presentation names the widget, so
136
+ * passing it costs nothing on a table reviewing elsewhere.
137
+ */
138
+ readonly approval: AgentApprovalPending | null;
139
+ /**
140
+ * How far the capability now running has got, or nothing.
141
+ *
142
+ * Published by the table while a long call works through its rows. It never
143
+ * becomes the receipt: when the turn settles this goes and the receipts say
144
+ * what happened.
145
+ */
146
+ readonly progress: AgentProgress | null;
147
+ /** Answer the pending question and let the turn continue. */
148
+ readonly answer: (answer: {
149
+ optionId?: string;
150
+ text?: string;
151
+ }) => void;
152
+ /**
153
+ * Whether the last turn that moved the table can still be put back.
154
+ *
155
+ * Null when no turn moved it. Re-read every render, because the offer ends
156
+ * the moment anything else changes the view. `blockedCode` is a token the
157
+ * labels translate — the panel never shows a reader a code.
158
+ */
159
+ readonly undo: {
160
+ readonly messageId: string;
161
+ readonly available: boolean;
162
+ readonly blockedCode?: string;
163
+ } | null;
164
+ /** Put that turn back. A no-op once the offer has expired. */
165
+ readonly undoTurn: () => Promise<void>;
166
+ /** Put one action of the last turn back, by its receipt's replay identity. */
167
+ readonly undoAction: (idempotencyKey: string) => Promise<void>;
168
+ /** What the reader said not to ask about again, each with its own name. */
169
+ readonly alwaysAllowed: readonly AssistantAllowance[];
170
+ /** Ask about one of them again from now on. */
171
+ readonly revokeAlwaysAllow: (capability: string) => void;
172
+ /** The suggestions this table can run right now, re-checked every render. */
173
+ readonly suggestions: readonly AssistantSuggestion$1[];
174
+ /** Send a suggestion's prompt as if the reader had typed it. */
175
+ readonly runSuggestion: (id: string) => Promise<void>;
176
+ readonly open: boolean;
177
+ readonly setOpen: (open: boolean) => void;
178
+ /** The last failure, cleared by the next successful turn. */
179
+ readonly error: string | undefined;
180
+ /**
181
+ * The machine code behind {@link error}, when a turn ended with work
182
+ * pending. A surface with labels turns it into a sentence for the reader;
183
+ * the message beside it is written for whoever is debugging the turn.
184
+ */
185
+ readonly errorCode: string | undefined;
186
+ }
187
+ /**
188
+ * Run a table assistant.
189
+ *
190
+ * A thin subscriber to the neutral controller in `@adapttable/ai/assistant`:
191
+ * React supplies the external-store mechanism, the live inputs and the
192
+ * controlled presentation state, and owns none of the lifecycle.
193
+ *
194
+ * @param options - Session, transport and presentation.
195
+ * @returns Everything a panel needs, and nothing about how it looks.
196
+ *
197
+ * @public
198
+ */
199
+ declare function useTableAssistant(options: TableAssistantOptions): TableAssistantState;
200
+ //#endregion
201
+ //#region src/react.d.ts
202
+ type TableAgentBridge = TableAgentBridge$1<AgentApprovalPending>;
203
+ /**
204
+ * Feature-state key for the live {@link AgentSession}.
205
+ *
206
+ * @public
207
+ */
208
+ declare const TABLE_AGENT_STATE: import("@adapttable/react/adapter").FeatureStateKey<AgentSession>;
209
+ /**
210
+ * Options for {@link tableAgent}.
211
+ *
212
+ * @public
213
+ */
214
+ interface TableAgentOptions {
215
+ /** Host-supplied table identity. */
216
+ readonly tableId: string;
217
+ /** Whether host callbacks already authorize writes. */
218
+ readonly writePolicy?: WritePolicy;
219
+ /** When a write must be confirmed. */
220
+ readonly approval?: SharedApproval;
221
+ /** Whether an approved write stages or persists. */
222
+ readonly commit?: CommitPolicy;
223
+ /** Host confirmation. When set, chrome is skipped. */
224
+ readonly onApprove?: (subject: ApprovalSubject, signal?: AbortSignal) => Promise<ApprovalResult>;
225
+ /** Per-column readability, writability, and labels. */
226
+ readonly columns?: Readonly<Record<string, TableAgentColumnPatch>>;
227
+ /** Largest `rows.read` window. */
228
+ readonly readMax?: number;
229
+ /** Host callbacks for manifest and session attach. */
230
+ readonly bridge?: TableAgentBridge;
231
+ /** Host- or test-supplied observation. Live tables omit this. */
232
+ readonly observe?: () => AgentObservation;
233
+ /** Extra apply callbacks the live table does not already expose. */
234
+ readonly apply?: AgentApply;
235
+ /** Custom governed capabilities for this table. */
236
+ readonly capabilities?: readonly AgentCapabilityDefinition[];
237
+ /**
238
+ * This table's approval policy for individual capabilities, by key.
239
+ *
240
+ * The same shape a row or bulk action carries. An entry **replaces**
241
+ * {@link approval} for that one capability rather than narrowing it:
242
+ * `required` asks on a table that asks for nothing, and `automatic` skips the
243
+ * human on a table that asks for writes. Both directions are deliberate —
244
+ * this is the developer's own answer to "who confirms this".
245
+ *
246
+ * It is not the reader's answer. "Don't ask again" is `approval.alwaysAllow`
247
+ * plus the approval memory: opt-in per capability, revocable, and reset by a
248
+ * contract change. A capability carrying `required` here keeps asking however
249
+ * often the reader waves it through.
250
+ *
251
+ * Approval decides who confirms an operation, never whether the table offers
252
+ * it: a key the table does not wire, or one in
253
+ * {@link excludeCapabilities}, stays unavailable whatever this says.
254
+ */
255
+ readonly capabilityApproval?: Readonly<Record<string, ActionAiOptions>>;
256
+ /**
257
+ * Capability keys the agent may not use on this table.
258
+ *
259
+ * One list, for built-ins and custom definitions alike. It only ever denies:
260
+ * a key the table does not wire stays unavailable whatever this says, and no
261
+ * entry here can enable a forbidden operation. The table's own controls are
262
+ * untouched — denying `view.setFilters` to the agent leaves a person
263
+ * filtering exactly as before.
264
+ */
265
+ readonly excludeCapabilities?: readonly string[];
266
+ /**
267
+ * Offer this table's capabilities to a browser-resident agent.
268
+ *
269
+ * `true` offers everything the session permits; an object narrows the
270
+ * surface. It narrows only — a capability the table excludes stays
271
+ * unavailable, and a browser confirmation is in addition to the table's own
272
+ * approval rather than instead of it. Does nothing in a browser without the
273
+ * API, and nothing on a server.
274
+ */
275
+ readonly webmcp?: true | {
276
+ readonly exposedTo?: readonly string[];
277
+ /**
278
+ * Told what was registered, and told `[]` when the registration goes.
279
+ *
280
+ * For a surface that lists the tools a browser agent can see. Nothing
281
+ * depends on it: a page that does not care never passes it.
282
+ */
283
+ readonly onRegister?: (names: readonly string[]) => void;
284
+ };
285
+ }
286
+ /**
287
+ * Observe a live table and publish a deterministic capability manifest.
288
+ *
289
+ * Omitting this feature from `features` ships no agent bytes.
290
+ *
291
+ * @public
292
+ */
293
+ declare function tableAgent(options: TableAgentOptions): StaticTableFeature;
294
+ //#endregion
295
+ //#region src/useSpeechInput.d.ts
296
+ /** How the hook is configured. @public */
297
+ interface UseSpeechInputOptions {
298
+ readonly voice?: VoiceOptions;
299
+ /** The table's locale, used when no language list was given. */
300
+ readonly locale?: string;
301
+ /** Where heard text goes. Always the draft, never a send. */
302
+ readonly setDraft: (text: string) => void;
303
+ /** Where a recording goes, in backend mode. */
304
+ readonly onClip?: (clip: SpeechClip) => void;
305
+ }
306
+ /**
307
+ * Run dictation for one composer.
308
+ *
309
+ * @param options - Voice configuration and where heard text should go.
310
+ * @returns What the composer needs, or an unavailable handle when voice is off.
311
+ *
312
+ * @public
313
+ */
314
+ declare function useSpeechInput(options: UseSpeechInputOptions): SpeechInputHandle;
315
+ //#endregion
316
+ export { type AssistantAnswer, type AssistantInterruption, type AssistantMessage, type AssistantQuestion, type AssistantResumeHandle, type AssistantStatus, type AssistantSuggestion, type SharedApproval, TABLE_AGENT_STATE, type TableAgentBridge, type TableAgentColumnPatch, type TableAgentOptions, type TableAssistantOptions, type TableAssistantSnapshot, type TableAssistantState, type TableAssistantStore, type UseSpeechInputOptions, tableAgent, useSpeechInput, useTableAssistant };
317
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/assistant.tsx","../src/react.tsx","../src/useSpeechInput.ts"],"mappings":";;;;;;;UAmFiB;;WAEN,SAAS;;;;;;;;WAQT,YAAY;;;;;;;;;;WAUZ;;WAEA,uBAAuB;;WAEvB;;WAEA,gBAAgB;;;;;;;;;WAShB;;;;;;;;;;;WAWA,cAAc;;;;;;;;WAQd,sBAAsB;;;;;;;;;WAStB,YAAY,QAAQ;;WAEpB,eAAe;;;;;;;;;WASf,oBAAoB;;WAEpB,oBAAoB,mBAAmB;;;;;;;;;WASvC;;;UAIM;WACN,QAAQ;;;;;;;;WAQR;WACA,mBAAmB;WACnB;WACA,WAAW;;WAEX,OAAO,kBAAkB;;WAEzB;;;;;;WAMA,cAAc;;;;;;;WAOd,aAAa;;WAEb,WAAW;;WAEX;;;;;;;;;WASA,UAAU;;;;;;;;WAQV,UAAU;;WAEV,SAAS;IAAU;IAAmB;;;;;;;;;WAQtC;aACE;aACA;aACA;;;WAGF,gBAAgB;;WAEhB,aAAa,2BAA2B;;WAExC,wBAAwB;;WAExB,oBAAoB;;WAEpB,sBAAsB;;WAEtB,gBAAgB,eAAe;WAC/B;WACA,UAAU;;WAEV;;;;;;WAMA;;;;;;;;;;;;;;iBAeK,kBACd,SAAS,wBACR;;;KCtLS,mBAAmB,mBAAc;;;;;;cAehC,uDAAiB,gBAAA;;;;;;UAOb;;WAEN;;WAEA,cAAc;;WAEd,WAAW;;WAEX,SAAS;;WAET,aACP,SAAS,iBACT,SAAS,gBACN,QAAQ;;WAEJ,UAAU,SAAS,eAAe;;WAElC;;WAEA,SAAS;;WAET,gBAAgB;;WAEhB,QAAQ;;WAER,wBAAwB;;;;;;;;;;;;;;;;;;;WAmBxB,qBAAqB,SAAS,eAAe;;;;;;;;;;WAU7C;;;;;;;;;;WAUA;aAGM;;;;;;;aAOA,cAAc;;;;;;;;;;iBAw5Cf,WAAW,SAAS,oBAAoB;;;;UCtjDvC;WACN,QAAQ;;WAER;;WAEA,WAAW;;WAEX,UAAU,MAAM;;;;;;;;;;iBAaX,eACd,SAAS,wBACR"}