@assistant-ui/react-ag-ui 0.0.60 → 0.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/agUiExtras.d.ts +1 -3
  2. package/dist/agUiExtras.d.ts.map +1 -1
  3. package/dist/hooks.d.ts +3 -5
  4. package/dist/hooks.d.ts.map +1 -1
  5. package/dist/index.d.ts +7 -5
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/runtime/AgUiThreadRuntimeCore.d.ts +152 -144
  8. package/dist/runtime/AgUiThreadRuntimeCore.d.ts.map +1 -1
  9. package/dist/runtime/AgUiThreadRuntimeCore.js +141 -23
  10. package/dist/runtime/AgUiThreadRuntimeCore.js.map +1 -1
  11. package/dist/runtime/adapter/conversions.d.ts +51 -53
  12. package/dist/runtime/adapter/conversions.d.ts.map +1 -1
  13. package/dist/runtime/adapter/conversions.js +65 -21
  14. package/dist/runtime/adapter/conversions.js.map +1 -1
  15. package/dist/runtime/adapter/run-aggregator.d.ts +89 -88
  16. package/dist/runtime/adapter/run-aggregator.d.ts.map +1 -1
  17. package/dist/runtime/adapter/run-aggregator.js +35 -2
  18. package/dist/runtime/adapter/run-aggregator.js.map +1 -1
  19. package/dist/runtime/adapter/subscriber.d.ts +107 -108
  20. package/dist/runtime/adapter/subscriber.d.ts.map +1 -1
  21. package/dist/runtime/adapter/tool-approval.d.ts +3 -4
  22. package/dist/runtime/adapter/tool-approval.d.ts.map +1 -1
  23. package/dist/runtime/event-parser.d.ts +3 -5
  24. package/dist/runtime/event-parser.d.ts.map +1 -1
  25. package/dist/runtime/interrupt-internals.d.ts +1 -3
  26. package/dist/runtime/interrupt-internals.d.ts.map +1 -1
  27. package/dist/runtime/logger.d.ts +2 -4
  28. package/dist/runtime/logger.d.ts.map +1 -1
  29. package/dist/runtime/mcp-tool-result.d.ts +4 -6
  30. package/dist/runtime/mcp-tool-result.d.ts.map +1 -1
  31. package/dist/runtime/types.d.ts +237 -238
  32. package/dist/runtime/types.d.ts.map +1 -1
  33. package/dist/useAgUiRuntime.d.ts +13 -15
  34. package/dist/useAgUiRuntime.d.ts.map +1 -1
  35. package/dist/useAgUiRuntime.js +9 -2
  36. package/dist/useAgUiRuntime.js.map +1 -1
  37. package/package.json +6 -6
  38. package/src/runtime/AgUiThreadRuntimeCore.ts +239 -32
  39. package/src/runtime/adapter/conversions.content.test.ts +56 -0
  40. package/src/runtime/adapter/conversions.ts +112 -44
  41. package/src/runtime/adapter/run-aggregator.ts +53 -2
  42. package/src/useAgUiRuntime.history.test.tsx +93 -2
  43. package/src/useAgUiRuntime.thread-switch.test.tsx +84 -4
  44. package/src/useAgUiRuntime.ts +12 -3
  45. package/src/useAgUiRuntime.voice.test.tsx +402 -0
@@ -1,9 +1,8 @@
1
- import { Logger } from "./logger.js";
2
- import { McpToolCallResult } from "./mcp-tool-result.js";
3
- import { AttachmentAdapter, CreateAppendMessage, DictationAdapter, ExternalStoreSharedOptions, ExternalStoreThreadListAdapter, FeedbackAdapter, RealtimeVoiceAdapter, SpeechSynthesisAdapter, ThreadHistoryAdapter, ThreadMessage } from "@assistant-ui/core";
4
- import { AbstractAgent } from "@ag-ui/client";
5
- import { ReadonlyJSONValue } from "assistant-stream/utils";
6
- //#region src/runtime/types.d.ts
1
+ import type { CreateAppendMessage, AttachmentAdapter, DictationAdapter, ExternalStoreSharedOptions, ExternalStoreThreadListAdapter, FeedbackAdapter, RealtimeVoiceAdapter, SpeechSynthesisAdapter, ThreadHistoryAdapter, ThreadMessage } from "@assistant-ui/core";
2
+ import type { AbstractAgent } from "@ag-ui/client";
3
+ import type { Logger } from "./logger.js";
4
+ import type { ReadonlyJSONValue } from "assistant-stream/utils";
5
+ import type { McpToolCallResult } from "./mcp-tool-result.js";
7
6
  /**
8
7
  * @experimental This API is still under active development and might change without notice.
9
8
  *
@@ -11,259 +10,259 @@ import { ReadonlyJSONValue } from "assistant-stream/utils";
11
10
  * the messages (and optional state) to hydrate the thread with.
12
11
  */
13
12
  type SwitchToThreadResult = {
14
- messages: readonly ThreadMessage[];
15
- state?: ReadonlyJSONValue;
16
- /**
17
- * Set when the thread has a run in flight. The runtime resumes the run
18
- * after hydrating, the same way `ThreadHistoryAdapter.load()` does when it
19
- * returns `unstable_resume: true`.
20
- */
21
- unstable_resume?: boolean;
13
+ messages: readonly ThreadMessage[];
14
+ state?: ReadonlyJSONValue;
15
+ /**
16
+ * Set when the thread has a run in flight. The runtime resumes the run
17
+ * after hydrating, the same way `ThreadHistoryAdapter.load()` does when it
18
+ * returns `unstable_resume: true`.
19
+ */
20
+ unstable_resume?: boolean;
22
21
  };
23
22
  export type UseAgUiThreadListAdapter = Omit<ExternalStoreThreadListAdapter, "onSwitchToThread"> & {
24
- onSwitchToThread?: ((threadId: string) => Promise<SwitchToThreadResult> | SwitchToThreadResult) | undefined;
23
+ onSwitchToThread?: ((threadId: string) => Promise<SwitchToThreadResult> | SwitchToThreadResult) | undefined;
25
24
  };
26
25
  export type UseAgUiRuntimeAdapters = {
27
- attachments?: AttachmentAdapter;
28
- speech?: SpeechSynthesisAdapter;
29
- dictation?: DictationAdapter;
30
- voice?: RealtimeVoiceAdapter;
31
- feedback?: FeedbackAdapter;
32
- history?: ThreadHistoryAdapter;
33
- /**
34
- * @experimental This API is still under active development and might change without notice.
35
- */
36
- threadList?: UseAgUiThreadListAdapter;
26
+ attachments?: AttachmentAdapter;
27
+ speech?: SpeechSynthesisAdapter;
28
+ dictation?: DictationAdapter;
29
+ voice?: RealtimeVoiceAdapter;
30
+ feedback?: FeedbackAdapter;
31
+ history?: ThreadHistoryAdapter;
32
+ /**
33
+ * @experimental This API is still under active development and might change without notice.
34
+ */
35
+ threadList?: UseAgUiThreadListAdapter;
37
36
  };
38
37
  export type AgUiResumeTranscript = "full" | "appended";
39
38
  export type UseAgUiRuntimeOptions = ExternalStoreSharedOptions & {
40
- agent: AbstractAgent;
41
- logger?: Partial<Logger>;
42
- showThinking?: boolean;
43
- /**
44
- * What `messages` carries on a resume run, meaning a `RunAgentInput` that
45
- * also carries `resume`. The AG-UI interrupt spec leaves this undefined: its
46
- * contract rules constrain the thread id, interrupt coverage, idempotency,
47
- * and expiry, and none of them mentions `messages`. Hosts therefore disagree,
48
- * and both readings are conformant.
49
- *
50
- * `"full"` sends the whole thread, which is what `@ag-ui/client` itself does.
51
- * Hosts that resume from a checkpoint ignore the transcript, and hosts that
52
- * rebuild the interrupted run from it need it.
53
- *
54
- * `"appended"` sends only what was appended locally after the interrupted
55
- * assistant message, which is nothing for an approval or a denial and the new
56
- * user turn for `steerAway`. Choose it for a host that owns the thread and
57
- * seeds a resume request from its own stored snapshot, because such a host
58
- * appends the request body to that snapshot and a re-sent transcript
59
- * duplicates the interrupted turn in its stored history. A host that rebuilds
60
- * the run from `messages` has nothing to resume from under `"appended"`, and
61
- * a host that derives its outgoing `MESSAGES_SNAPSHOT` from the request body
62
- * emits a truncated one.
63
- *
64
- * Defaults to `"full"`.
65
- */
66
- resumeTranscript?: AgUiResumeTranscript | undefined;
67
- /**
68
- * When the user sends, edits, or reloads a message while client-side tool
69
- * calls are still pending, automatically cancel the unresolved tool calls
70
- * with an error result so the agent's tool-call accounting stays
71
- * consistent. Pending AG-UI interrupts are exempt: they still reject the
72
- * run and must be answered with `useAgUiSubmitInterruptResponses` or
73
- * discarded with `useAgUiSteerAway`. When disabled, `useAgUiSteerAway`
74
- * remains the explicit way to cancel pending tool calls.
75
- * Defaults to `true`.
76
- */
77
- autoCancelPendingToolCalls?: boolean | undefined;
78
- /**
79
- * Buffer a message sent while a run is in flight and send it once the run
80
- * settles, exposing it on `composer.queue` for `ComposerPrimitive.Queue`.
81
- * The runtime owns the queue lifecycle because flushing needs the agent's
82
- * send path and the run's own busy and idle edges.
83
- */
84
- unstable_enableMessageQueue?: boolean | undefined;
85
- onError?: (e: Error) => void;
86
- onCancel?: () => void;
87
- adapters?: UseAgUiRuntimeAdapters;
39
+ agent: AbstractAgent;
40
+ logger?: Partial<Logger>;
41
+ showThinking?: boolean;
42
+ /**
43
+ * What `messages` carries on a resume run, meaning a `RunAgentInput` that
44
+ * also carries `resume`. The AG-UI interrupt spec leaves this undefined: its
45
+ * contract rules constrain the thread id, interrupt coverage, idempotency,
46
+ * and expiry, and none of them mentions `messages`. Hosts therefore disagree,
47
+ * and both readings are conformant.
48
+ *
49
+ * `"full"` sends the whole thread, which is what `@ag-ui/client` itself does.
50
+ * Hosts that resume from a checkpoint ignore the transcript, and hosts that
51
+ * rebuild the interrupted run from it need it.
52
+ *
53
+ * `"appended"` sends only what was appended locally after the interrupted
54
+ * assistant message, which is nothing for an approval or a denial and the new
55
+ * user turn for `steerAway`. Choose it for a host that owns the thread and
56
+ * seeds a resume request from its own stored snapshot, because such a host
57
+ * appends the request body to that snapshot and a re-sent transcript
58
+ * duplicates the interrupted turn in its stored history. A host that rebuilds
59
+ * the run from `messages` has nothing to resume from under `"appended"`, and
60
+ * a host that derives its outgoing `MESSAGES_SNAPSHOT` from the request body
61
+ * emits a truncated one.
62
+ *
63
+ * Defaults to `"full"`.
64
+ */
65
+ resumeTranscript?: AgUiResumeTranscript | undefined;
66
+ /**
67
+ * When the user sends, edits, or reloads a message while client-side tool
68
+ * calls are still pending, automatically cancel the unresolved tool calls
69
+ * with an error result so the agent's tool-call accounting stays
70
+ * consistent. Pending AG-UI interrupts are exempt: they still reject the
71
+ * run and must be answered with `useAgUiSubmitInterruptResponses` or
72
+ * discarded with `useAgUiSteerAway`. When disabled, `useAgUiSteerAway`
73
+ * remains the explicit way to cancel pending tool calls.
74
+ * Defaults to `true`.
75
+ */
76
+ autoCancelPendingToolCalls?: boolean | undefined;
77
+ /**
78
+ * Buffer a message sent while a run is in flight and send it once the run
79
+ * settles, exposing it on `composer.queue` for `ComposerPrimitive.Queue`.
80
+ * The runtime owns the queue lifecycle because flushing needs the agent's
81
+ * send path and the run's own busy and idle edges.
82
+ */
83
+ unstable_enableMessageQueue?: boolean | undefined;
84
+ onError?: (e: Error) => void;
85
+ onCancel?: () => void;
86
+ adapters?: UseAgUiRuntimeAdapters;
88
87
  };
89
88
  export type AgUiInterruptReason = "tool_call" | "input_required" | "confirmation" | (string & {});
90
89
  export type AgUiInterrupt = {
91
- id: string;
92
- reason: AgUiInterruptReason;
93
- message?: string;
94
- toolCallId?: string;
95
- responseSchema?: Record<string, unknown>;
96
- expiresAt?: string;
97
- metadata?: Record<string, unknown>;
90
+ id: string;
91
+ reason: AgUiInterruptReason;
92
+ message?: string;
93
+ toolCallId?: string;
94
+ responseSchema?: Record<string, unknown>;
95
+ expiresAt?: string;
96
+ metadata?: Record<string, unknown>;
98
97
  };
99
98
  export type AgUiResumeEntry = {
100
- interruptId: string;
101
- status: "resolved" | "cancelled";
102
- payload?: unknown;
99
+ interruptId: string;
100
+ status: "resolved" | "cancelled";
101
+ payload?: unknown;
103
102
  };
104
103
  export type AgUiRuntimeExtras = {
105
- interrupts: readonly AgUiInterrupt[];
106
- sendA2uiAction: (action: Record<string, unknown>) => void;
107
- submitInterruptResponses: (responses: readonly AgUiResumeEntry[]) => Promise<void>;
108
- steerAway: (message: CreateAppendMessage, responses?: readonly AgUiResumeEntry[]) => Promise<void>;
109
- state: ReadonlyJSONValue | undefined;
110
- setState: (next: ReadonlyJSONValue | ((prev: ReadonlyJSONValue | undefined) => ReadonlyJSONValue)) => void;
104
+ interrupts: readonly AgUiInterrupt[];
105
+ sendA2uiAction: (action: Record<string, unknown>) => void;
106
+ submitInterruptResponses: (responses: readonly AgUiResumeEntry[]) => Promise<void>;
107
+ steerAway: (message: CreateAppendMessage, responses?: readonly AgUiResumeEntry[]) => Promise<void>;
108
+ state: ReadonlyJSONValue | undefined;
109
+ setState: (next: ReadonlyJSONValue | ((prev: ReadonlyJSONValue | undefined) => ReadonlyJSONValue)) => void;
111
110
  };
112
111
  export type AgUiRunFinishedOutcome = {
113
- type: "success";
112
+ type: "success";
114
113
  } | {
115
- type: "interrupt";
116
- interrupts: AgUiInterrupt[];
114
+ type: "interrupt";
115
+ interrupts: AgUiInterrupt[];
117
116
  };
118
117
  export type AgUiSubagentFinishedOutcome = {
119
- type: "success";
118
+ type: "success";
120
119
  } | {
121
- type: "suspended";
122
- interruptIds?: string[];
120
+ type: "suspended";
121
+ interruptIds?: string[];
123
122
  };
124
123
  export type AgUiEvent = {
125
- type: "RUN_STARTED";
126
- runId: string;
127
- } | {
128
- type: "RUN_FINISHED";
129
- runId: string;
130
- outcome?: AgUiRunFinishedOutcome;
131
- } | {
132
- type: "RUN_CANCELLED";
133
- runId?: string;
134
- } | {
135
- type: "RUN_ERROR";
136
- message?: string;
137
- code?: string;
138
- } | {
139
- type: "TEXT_MESSAGE_START";
140
- messageId?: string;
141
- subagentRunId?: string;
142
- } | {
143
- type: "TEXT_MESSAGE_CONTENT";
144
- messageId?: string;
145
- delta: string;
146
- subagentRunId?: string;
147
- } | {
148
- type: "TEXT_MESSAGE_END";
149
- messageId?: string;
150
- subagentRunId?: string;
151
- } | {
152
- type: "TEXT_MESSAGE_CHUNK";
153
- messageId?: string;
154
- delta: string;
155
- subagentRunId?: string;
156
- } | {
157
- type: "THINKING_START";
158
- title?: string;
159
- } | {
160
- type: "THINKING_TEXT_MESSAGE_START";
161
- } | {
162
- type: "THINKING_TEXT_MESSAGE_CONTENT";
163
- delta: string;
164
- } | {
165
- type: "THINKING_TEXT_MESSAGE_END";
166
- } | {
167
- type: "THINKING_END";
168
- } | {
169
- type: "REASONING_START";
170
- messageId?: string;
171
- subagentRunId?: string;
172
- } | {
173
- type: "REASONING_MESSAGE_START";
174
- messageId?: string;
175
- subagentRunId?: string;
176
- } | {
177
- type: "REASONING_MESSAGE_CONTENT";
178
- messageId?: string;
179
- delta: string;
180
- subagentRunId?: string;
181
- } | {
182
- type: "REASONING_MESSAGE_END";
183
- messageId?: string;
184
- subagentRunId?: string;
185
- } | {
186
- type: "REASONING_ENCRYPTED_VALUE";
187
- subtype: "message" | "tool-call";
188
- entityId: string;
189
- encryptedValue: string;
190
- subagentRunId?: string;
191
- } | {
192
- type: "REASONING_END";
193
- messageId?: string;
194
- subagentRunId?: string;
195
- } | {
196
- type: "TOOL_CALL_START";
197
- toolCallId: string;
198
- toolCallName?: string;
199
- parentMessageId?: string;
200
- subagentRunId?: string;
201
- } | {
202
- type: "TOOL_CALL_ARGS";
203
- toolCallId: string;
204
- delta: string;
205
- subagentRunId?: string;
206
- } | {
207
- type: "TOOL_CALL_END";
208
- toolCallId: string;
209
- subagentRunId?: string;
210
- } | {
211
- type: "TOOL_CALL_CHUNK";
212
- toolCallId?: string;
213
- toolCallName?: string;
214
- parentMessageId?: string;
215
- delta?: string;
216
- subagentRunId?: string;
217
- } | {
218
- type: "TOOL_CALL_RESULT";
219
- messageId?: string;
220
- toolCallId: string;
221
- content: string;
222
- role?: "tool";
223
- mcpResult?: McpToolCallResult;
224
- subagentRunId?: string;
225
- } | {
226
- type: "ACTIVITY_SNAPSHOT";
227
- activityType: string;
228
- content: Record<string, unknown>;
229
- messageId?: string;
230
- replace?: boolean;
231
- subagentRunId?: string;
232
- } | {
233
- type: "RAW";
234
- event: any;
235
- source?: string;
236
- } | {
237
- type: "CUSTOM";
238
- name: string;
239
- value: any;
240
- } | {
241
- type: "STATE_SNAPSHOT";
242
- snapshot: any;
243
- } | {
244
- type: "STATE_DELTA";
245
- delta: any[];
246
- } | {
247
- type: "MESSAGES_SNAPSHOT";
248
- messages: any[];
249
- } | {
250
- type: "SUBAGENT_STARTED";
251
- subagentRunId: string;
252
- name: string;
253
- description?: string;
254
- parentSubagentRunId?: string;
255
- parentToolCallId?: string;
256
- parentMessageId?: string;
257
- } | {
258
- type: "SUBAGENT_FINISHED";
259
- subagentRunId: string;
260
- result?: unknown;
261
- outcome?: AgUiSubagentFinishedOutcome;
262
- } | {
263
- type: "SUBAGENT_ERROR";
264
- subagentRunId: string;
265
- message: string;
266
- code?: string;
124
+ type: "RUN_STARTED";
125
+ runId: string;
126
+ } | {
127
+ type: "RUN_FINISHED";
128
+ runId: string;
129
+ outcome?: AgUiRunFinishedOutcome;
130
+ } | {
131
+ type: "RUN_CANCELLED";
132
+ runId?: string;
133
+ } | {
134
+ type: "RUN_ERROR";
135
+ message?: string;
136
+ code?: string;
137
+ } | {
138
+ type: "TEXT_MESSAGE_START";
139
+ messageId?: string;
140
+ subagentRunId?: string;
141
+ } | {
142
+ type: "TEXT_MESSAGE_CONTENT";
143
+ messageId?: string;
144
+ delta: string;
145
+ subagentRunId?: string;
146
+ } | {
147
+ type: "TEXT_MESSAGE_END";
148
+ messageId?: string;
149
+ subagentRunId?: string;
150
+ } | {
151
+ type: "TEXT_MESSAGE_CHUNK";
152
+ messageId?: string;
153
+ delta: string;
154
+ subagentRunId?: string;
155
+ } | {
156
+ type: "THINKING_START";
157
+ title?: string;
158
+ } | {
159
+ type: "THINKING_TEXT_MESSAGE_START";
160
+ } | {
161
+ type: "THINKING_TEXT_MESSAGE_CONTENT";
162
+ delta: string;
163
+ } | {
164
+ type: "THINKING_TEXT_MESSAGE_END";
165
+ } | {
166
+ type: "THINKING_END";
167
+ } | {
168
+ type: "REASONING_START";
169
+ messageId?: string;
170
+ subagentRunId?: string;
171
+ } | {
172
+ type: "REASONING_MESSAGE_START";
173
+ messageId?: string;
174
+ subagentRunId?: string;
175
+ } | {
176
+ type: "REASONING_MESSAGE_CONTENT";
177
+ messageId?: string;
178
+ delta: string;
179
+ subagentRunId?: string;
180
+ } | {
181
+ type: "REASONING_MESSAGE_END";
182
+ messageId?: string;
183
+ subagentRunId?: string;
184
+ } | {
185
+ type: "REASONING_ENCRYPTED_VALUE";
186
+ subtype: "message" | "tool-call";
187
+ entityId: string;
188
+ encryptedValue: string;
189
+ subagentRunId?: string;
190
+ } | {
191
+ type: "REASONING_END";
192
+ messageId?: string;
193
+ subagentRunId?: string;
194
+ } | {
195
+ type: "TOOL_CALL_START";
196
+ toolCallId: string;
197
+ toolCallName?: string;
198
+ parentMessageId?: string;
199
+ subagentRunId?: string;
200
+ } | {
201
+ type: "TOOL_CALL_ARGS";
202
+ toolCallId: string;
203
+ delta: string;
204
+ subagentRunId?: string;
205
+ } | {
206
+ type: "TOOL_CALL_END";
207
+ toolCallId: string;
208
+ subagentRunId?: string;
209
+ } | {
210
+ type: "TOOL_CALL_CHUNK";
211
+ toolCallId?: string;
212
+ toolCallName?: string;
213
+ parentMessageId?: string;
214
+ delta?: string;
215
+ subagentRunId?: string;
216
+ } | {
217
+ type: "TOOL_CALL_RESULT";
218
+ messageId?: string;
219
+ toolCallId: string;
220
+ content: string;
221
+ role?: "tool";
222
+ mcpResult?: McpToolCallResult;
223
+ subagentRunId?: string;
224
+ } | {
225
+ type: "ACTIVITY_SNAPSHOT";
226
+ activityType: string;
227
+ content: Record<string, unknown>;
228
+ messageId?: string;
229
+ replace?: boolean;
230
+ subagentRunId?: string;
231
+ } | {
232
+ type: "RAW";
233
+ event: any;
234
+ source?: string;
235
+ } | {
236
+ type: "CUSTOM";
237
+ name: string;
238
+ value: any;
239
+ } | {
240
+ type: "STATE_SNAPSHOT";
241
+ snapshot: any;
242
+ } | {
243
+ type: "STATE_DELTA";
244
+ delta: any[];
245
+ } | {
246
+ type: "MESSAGES_SNAPSHOT";
247
+ messages: any[];
248
+ } | {
249
+ type: "SUBAGENT_STARTED";
250
+ subagentRunId: string;
251
+ name: string;
252
+ description?: string;
253
+ parentSubagentRunId?: string;
254
+ parentToolCallId?: string;
255
+ parentMessageId?: string;
256
+ } | {
257
+ type: "SUBAGENT_FINISHED";
258
+ subagentRunId: string;
259
+ result?: unknown;
260
+ outcome?: AgUiSubagentFinishedOutcome;
261
+ } | {
262
+ type: "SUBAGENT_ERROR";
263
+ subagentRunId: string;
264
+ message: string;
265
+ code?: string;
267
266
  };
268
- //#endregion
267
+ export {};
269
268
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/runtime/types.ts"],"mappings":";;;;;;;;;;;;KAuBK;EACH,mBAAmB;EACnB,QAAQ;;;;;;EAMR;;YAGU,2BAA2B,K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vB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC"}
@@ -1,19 +1,17 @@
1
- import { AgUiInterrupt, AgUiResumeEntry, UseAgUiRuntimeOptions } from "./runtime/types.js";
2
- import { AssistantRuntime } from "@assistant-ui/core";
3
- //#region src/useAgUiRuntime.d.ts
1
+ import type { AssistantRuntime } from "@assistant-ui/core";
2
+ import type { AgUiInterrupt, AgUiResumeEntry, UseAgUiRuntimeOptions } from "./runtime/types.js";
4
3
  export type AgUiAssistantRuntime = AssistantRuntime & {
5
- /**
6
- * @deprecated Use the `useAgUiInterrupts()` hook instead. This method is kept
7
- * for backward compatibility and will be removed in a future major release.
8
- */
9
- unstable_getPendingInterrupts: () => readonly AgUiInterrupt[];
10
- /**
11
- * @deprecated Use the `useAgUiSubmitInterruptResponses()` hook instead. This
12
- * method is kept for backward compatibility and will be removed in a future
13
- * major release.
14
- */
15
- unstable_submitInterruptResponses: (responses: readonly AgUiResumeEntry[]) => Promise<void>;
4
+ /**
5
+ * @deprecated Use the `useAgUiInterrupts()` hook instead. This method is kept
6
+ * for backward compatibility and will be removed in a future major release.
7
+ */
8
+ unstable_getPendingInterrupts: () => readonly AgUiInterrupt[];
9
+ /**
10
+ * @deprecated Use the `useAgUiSubmitInterruptResponses()` hook instead. This
11
+ * method is kept for backward compatibility and will be removed in a future
12
+ * major release.
13
+ */
14
+ unstable_submitInterruptResponses: (responses: readonly AgUiResumeEntry[]) => Promise<void>;
16
15
  };
17
16
  export declare function useAgUiRuntime(options: UseAgUiRuntimeOptions): AgUiAssistantRuntime;
18
- //#endregion
19
17
  //# sourceMappingURL=useAgUiRuntime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAgUiRuntime.d.ts","names":[],"sources":["../src/useAgUiRuntime.ts"],"mappings":";;;YA0CY,uBAAuB;;;;;EAKjC,8CAA8C;;;;;;EAM9C,oCACE,oBAAoB,sBACjB;;wBAGS,eACd,SAAS,wBACR"}
1
+ {"version":3,"file":"useAgUiRuntime.d.ts","sourceRoot":"","sources":["../src/useAgUiRuntime.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EACV,gBAAgB,EAIjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,qBAAqB,EACtB,2BAAwB;AASzB,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG;IACpD;;;OAGG;IACH,6BAA6B,EAAE,MAAM,SAAS,aAAa,EAAE,CAAC;IAC9D;;;;OAIG;IACH,iCAAiC,EAAE,CACjC,SAAS,EAAE,SAAS,eAAe,EAAE,KAClC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,oBAAoB,CAgRtB"}
@@ -82,19 +82,23 @@ function useAgUiRuntime(options) {
82
82
  ...rest,
83
83
  onSwitchToNewThread: onSwitchToNewThread ? async () => {
84
84
  const generation = ++threadSwitchGenerationRef.current;
85
+ core.applyExternalMessages([]);
86
+ core.resetThreadState();
85
87
  await onSwitchToNewThread();
86
88
  if (generation !== threadSwitchGenerationRef.current) return;
87
89
  core.applyExternalMessages([]);
88
- core.resetState();
90
+ core.resetThreadState();
89
91
  } : void 0,
90
92
  onSwitchToThread: onSwitchToThread ? async (threadId) => {
91
93
  const generation = ++threadSwitchGenerationRef.current;
92
94
  core.applyExternalMessages([]);
95
+ core.resetThreadState();
93
96
  const result = await onSwitchToThread(threadId);
94
97
  if (generation !== threadSwitchGenerationRef.current) return;
98
+ core.applyExternalMessages([]);
99
+ core.resetThreadState();
95
100
  core.applyExternalMessages(result.messages);
96
101
  if (result.state !== void 0) core.loadExternalState(result.state);
97
- else core.resetState();
98
102
  if (result.unstable_resume) core.resumeInFlightRun(result.messages);
99
103
  } : void 0
100
104
  };
@@ -129,8 +133,10 @@ function useAgUiRuntime(options) {
129
133
  setState: (next) => core.setState(next)
130
134
  }),
131
135
  unstable_enableToolInvocations: true,
136
+ unstable_persistsHistory: true,
132
137
  setToolStatuses,
133
138
  onNew: (message) => core.append(message),
139
+ onVoiceTranscript: (message) => core.appendVoiceTranscript(message),
134
140
  onEdit: (message) => {
135
141
  queueController?.clear();
136
142
  return core.edit(message);
@@ -144,6 +150,7 @@ function useAgUiRuntime(options) {
144
150
  core.cancel();
145
151
  },
146
152
  onAddToolResult: (options) => core.addToolResult(options),
153
+ unstable_onRecordToolInteraction: (options) => core.recordToolInteraction(options),
147
154
  onRespondToToolApproval: (options) => core.respondToToolApproval(options).catch((error) => {
148
155
  core.reportError(error);
149
156
  throw error;