@assistant-ui/react 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -44,6 +44,7 @@ __export(src_exports, {
44
44
  useActionBarCopy: () => useActionBarCopy,
45
45
  useActionBarEdit: () => useActionBarEdit,
46
46
  useActionBarReload: () => useActionBarReload,
47
+ useAppendMessage: () => useAppendMessage,
47
48
  useAssistantContext: () => useAssistantContext,
48
49
  useAssistantInstructions: () => useAssistantInstructions,
49
50
  useAssistantTool: () => useAssistantTool,
@@ -59,11 +60,11 @@ __export(src_exports, {
59
60
  useContentPartContext: () => useContentPartContext,
60
61
  useContentPartDisplay: () => useContentPartDisplay,
61
62
  useContentPartImage: () => useContentPartImage,
62
- useContentPartInProgressIndicator: () => useContentPartInProgressIndicator,
63
63
  useContentPartText: () => useContentPartText,
64
64
  useLocalRuntime: () => useLocalRuntime,
65
65
  useMessageContext: () => useMessageContext,
66
66
  useMessageIf: () => useMessageIf,
67
+ useSwitchToNewThread: () => useSwitchToNewThread,
67
68
  useThreadContext: () => useThreadContext,
68
69
  useThreadEmpty: () => useThreadEmpty,
69
70
  useThreadIf: () => useThreadIf,
@@ -72,192 +73,19 @@ __export(src_exports, {
72
73
  });
73
74
  module.exports = __toCommonJS(src_exports);
74
75
 
75
- // src/primitive-hooks/actionBar/useActionBarCopy.tsx
76
- var import_react4 = require("react");
77
-
78
- // src/context/react/MessageContext.ts
79
- var import_react = require("react");
80
- var MessageContext = (0, import_react.createContext)(null);
81
- var useMessageContext = () => {
82
- const context = (0, import_react.useContext)(MessageContext);
83
- if (!context)
84
- throw new Error(
85
- "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
86
- );
87
- return context;
88
- };
89
-
90
- // src/utils/combined/useCombinedStore.ts
91
- var import_react3 = require("react");
92
-
93
- // src/utils/combined/createCombinedStore.ts
94
- var import_react2 = require("react");
95
- var createCombinedStore = (stores) => {
96
- const subscribe = (callback) => {
97
- const unsubscribes = stores.map((store) => store.subscribe(callback));
98
- return () => {
99
- for (const unsub of unsubscribes) {
100
- unsub();
101
- }
102
- };
103
- };
104
- return (selector) => {
105
- const getSnapshot = () => selector(...stores.map((store) => store.getState()));
106
- return (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
107
- };
108
- };
109
-
110
- // src/utils/combined/useCombinedStore.ts
111
- var useCombinedStore = (stores, selector) => {
112
- const useCombined = (0, import_react3.useMemo)(() => createCombinedStore(stores), stores);
113
- return useCombined(selector);
114
- };
115
-
116
- // src/utils/getMessageText.tsx
117
- var getMessageText = (message) => {
118
- const textParts = message.content.filter(
119
- (part) => part.type === "text"
120
- );
121
- return textParts.map((part) => part.text).join("\n\n");
122
- };
123
-
124
- // src/primitive-hooks/actionBar/useActionBarCopy.tsx
125
- var useActionBarCopy = ({
126
- copiedDuration = 3e3
127
- } = {}) => {
128
- const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();
129
- const hasCopyableContent = useCombinedStore(
130
- [useMessage, useEditComposer],
131
- (m, c) => {
132
- return !c.isEditing && m.message.content.some((c2) => c2.type === "text");
133
- }
134
- );
135
- const callback = (0, import_react4.useCallback)(() => {
136
- const { message } = useMessage.getState();
137
- const { setIsCopied } = useMessageUtils.getState();
138
- const { isEditing, value: composerValue } = useEditComposer.getState();
139
- const valueToCopy = isEditing ? composerValue : getMessageText(message);
140
- navigator.clipboard.writeText(valueToCopy);
141
- setIsCopied(true);
142
- setTimeout(() => setIsCopied(false), copiedDuration);
143
- }, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);
144
- if (!hasCopyableContent) return null;
145
- return callback;
146
- };
147
-
148
- // src/primitive-hooks/actionBar/useActionBarEdit.tsx
149
- var import_react5 = require("react");
150
- var useActionBarEdit = () => {
151
- const { useMessage, useEditComposer } = useMessageContext();
152
- const disabled = useCombinedStore(
153
- [useMessage, useEditComposer],
154
- (m, c) => m.message.role !== "user" || c.isEditing
155
- );
156
- const callback = (0, import_react5.useCallback)(() => {
157
- const { edit } = useEditComposer.getState();
158
- edit();
159
- }, [useEditComposer]);
160
- if (disabled) return null;
161
- return callback;
162
- };
163
-
164
- // src/primitive-hooks/actionBar/useActionBarReload.tsx
165
- var import_react7 = require("react");
166
-
167
- // src/context/react/ThreadContext.ts
168
- var import_react6 = require("react");
169
- var ThreadContext = (0, import_react6.createContext)(null);
170
- var useThreadContext = () => {
171
- const context = (0, import_react6.useContext)(ThreadContext);
172
- if (!context)
173
- throw new Error(
174
- "This component must be used within an AssistantRuntimeProvider."
175
- );
176
- return context;
177
- };
178
-
179
- // src/primitive-hooks/actionBar/useActionBarReload.tsx
180
- var useActionBarReload = () => {
181
- const { useThread, useThreadActions, useComposer, useViewport } = useThreadContext();
182
- const { useMessage } = useMessageContext();
183
- const disabled = useCombinedStore(
184
- [useThread, useMessage],
185
- (t, m) => t.isRunning || m.message.role !== "assistant"
186
- );
187
- const callback = (0, import_react7.useCallback)(() => {
188
- const { parentId } = useMessage.getState();
189
- useThreadActions.getState().startRun(parentId);
190
- useViewport.getState().scrollToBottom();
191
- useComposer.getState().focus();
192
- }, [useThreadActions, useComposer, useViewport, useMessage]);
193
- if (disabled) return null;
194
- return callback;
195
- };
196
-
197
- // src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
198
- var useBranchPickerCount = () => {
199
- const { useMessage } = useMessageContext();
200
- const branchCount = useMessage((s) => s.branches.length);
201
- return branchCount;
202
- };
203
-
204
- // src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
205
- var import_react8 = require("react");
206
- var useBranchPickerNext = () => {
207
- const { useThreadActions } = useThreadContext();
208
- const { useMessage, useEditComposer } = useMessageContext();
209
- const disabled = useCombinedStore(
210
- [useMessage, useEditComposer],
211
- (m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
212
- );
213
- const callback = (0, import_react8.useCallback)(() => {
214
- const { message, branches } = useMessage.getState();
215
- useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
216
- }, [useThreadActions, useMessage]);
217
- if (disabled) return null;
218
- return callback;
219
- };
220
-
221
- // src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
222
- var useBranchPickerNumber = () => {
223
- const { useMessage } = useMessageContext();
224
- const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
225
- return branchIdx + 1;
226
- };
227
-
228
- // src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
229
- var import_react9 = require("react");
230
- var useBranchPickerPrevious = () => {
231
- const { useThreadActions } = useThreadContext();
232
- const { useMessage, useEditComposer } = useMessageContext();
233
- const disabled = useCombinedStore(
234
- [useMessage, useEditComposer],
235
- (m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
236
- );
237
- const callback = (0, import_react9.useCallback)(() => {
238
- const { message, branches } = useMessage.getState();
239
- useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
240
- }, [useThreadActions, useMessage]);
241
- if (disabled) return null;
242
- return callback;
243
- };
244
-
245
- // src/primitive-hooks/composer/useComposerCancel.tsx
246
- var import_react16 = require("react");
247
-
248
76
  // src/context/providers/AssistantRuntimeProvider.tsx
249
- var import_react13 = require("react");
77
+ var import_react5 = require("react");
250
78
 
251
79
  // src/context/providers/AssistantProvider.tsx
252
- var import_react12 = require("react");
80
+ var import_react4 = require("react");
253
81
 
254
82
  // src/context/react/AssistantContext.ts
255
- var import_react10 = require("react");
256
- var AssistantContext = (0, import_react10.createContext)(
83
+ var import_react = require("react");
84
+ var AssistantContext = (0, import_react.createContext)(
257
85
  null
258
86
  );
259
87
  var useAssistantContext = () => {
260
- const context = (0, import_react10.useContext)(AssistantContext);
88
+ const context = (0, import_react.useContext)(AssistantContext);
261
89
  if (!context)
262
90
  throw new Error(
263
91
  "This component must be used within an AssistantRuntimeProvider."
@@ -356,7 +184,19 @@ var makeAssistantToolUIsStore = () => (0, import_zustand2.create)((set) => {
356
184
  });
357
185
 
358
186
  // src/context/providers/ThreadProvider.tsx
359
- var import_react11 = require("react");
187
+ var import_react3 = require("react");
188
+
189
+ // src/context/react/ThreadContext.ts
190
+ var import_react2 = require("react");
191
+ var ThreadContext = (0, import_react2.createContext)(null);
192
+ var useThreadContext = () => {
193
+ const context = (0, import_react2.useContext)(ThreadContext);
194
+ if (!context)
195
+ throw new Error(
196
+ "This component must be used within an AssistantRuntimeProvider."
197
+ );
198
+ return context;
199
+ };
360
200
 
361
201
  // src/context/stores/Composer.ts
362
202
  var import_zustand3 = require("zustand");
@@ -370,7 +210,7 @@ var makeBaseComposer = (set) => ({
370
210
  });
371
211
 
372
212
  // src/context/stores/Composer.ts
373
- var makeComposerStore = (useThread, useThreadActions) => {
213
+ var makeComposerStore = (useThread, useThreadMessages, useThreadActions) => {
374
214
  const focusListeners = /* @__PURE__ */ new Set();
375
215
  return (0, import_zustand3.create)()((set, get, store) => {
376
216
  return {
@@ -380,7 +220,7 @@ var makeComposerStore = (useThread, useThreadActions) => {
380
220
  const { setValue, value } = get();
381
221
  setValue("");
382
222
  useThreadActions.getState().append({
383
- parentId: useThread.getState().messages.at(-1)?.id ?? null,
223
+ parentId: useThreadMessages.getState().at(-1)?.id ?? null,
384
224
  role: "user",
385
225
  content: [{ type: "text", text: value }]
386
226
  });
@@ -410,7 +250,6 @@ var makeComposerStore = (useThread, useThreadActions) => {
410
250
  var import_zustand4 = require("zustand");
411
251
  var makeThreadStore = (runtimeRef) => {
412
252
  return (0, import_zustand4.create)(() => ({
413
- messages: runtimeRef.current.messages,
414
253
  isRunning: runtimeRef.current.isRunning
415
254
  }));
416
255
  };
@@ -450,62 +289,91 @@ var makeThreadActionStore = (runtimeRef) => {
450
289
  );
451
290
  };
452
291
 
292
+ // src/context/stores/ThreadMessages.ts
293
+ var import_zustand7 = require("zustand");
294
+ var makeThreadMessagesStore = (runtimeRef) => {
295
+ return (0, import_zustand7.create)(() => runtimeRef.current.messages);
296
+ };
297
+
453
298
  // src/context/providers/ThreadProvider.tsx
454
299
  var import_jsx_runtime = require("react/jsx-runtime");
455
300
  var ThreadProvider = ({
456
301
  children,
457
302
  runtime
458
303
  }) => {
459
- const runtimeRef = (0, import_react11.useRef)(runtime);
460
- (0, import_react11.useInsertionEffect)(() => {
304
+ const runtimeRef = (0, import_react3.useRef)(runtime);
305
+ (0, import_react3.useInsertionEffect)(() => {
461
306
  runtimeRef.current = runtime;
462
307
  });
463
- const [context] = (0, import_react11.useState)(() => {
308
+ const [context] = (0, import_react3.useState)(() => {
464
309
  const useThread = makeThreadStore(runtimeRef);
310
+ const useThreadMessages = makeThreadMessagesStore(runtimeRef);
465
311
  const useThreadActions = makeThreadActionStore(runtimeRef);
466
312
  const useViewport = makeThreadViewportStore();
467
- const useComposer = makeComposerStore(useThread, useThreadActions);
313
+ const useComposer = makeComposerStore(
314
+ useThread,
315
+ useThreadMessages,
316
+ useThreadActions
317
+ );
468
318
  return {
469
319
  useThread,
320
+ useThreadMessages,
470
321
  useThreadActions,
471
322
  useComposer,
472
323
  useViewport
473
324
  };
474
325
  });
475
- (0, import_react11.useEffect)(() => {
326
+ (0, import_react3.useEffect)(() => {
476
327
  const onRuntimeUpdate = () => {
477
328
  context.useThread.setState(
478
329
  Object.freeze({
479
- messages: runtimeRef.current.messages,
480
330
  isRunning: runtimeRef.current.isRunning
481
331
  }),
482
332
  true
483
333
  );
334
+ context.useThreadMessages.setState(Object.freeze(runtimeRef.current.messages), true);
484
335
  };
485
336
  onRuntimeUpdate();
486
337
  return runtime.subscribe(onRuntimeUpdate);
487
338
  }, [context, runtime]);
488
- const RuntimeSynchronizer = runtime.unstable_synchronizer;
339
+ const subscribe = (0, import_react3.useCallback)(
340
+ (c) => runtime.subscribe(c),
341
+ [runtime]
342
+ );
343
+ const RuntimeSynchronizer = (0, import_react3.useSyncExternalStore)(
344
+ subscribe,
345
+ () => runtime.unstable_synchronizer,
346
+ () => void 0
347
+ );
489
348
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ThreadContext.Provider, { value: context, children: [
490
349
  RuntimeSynchronizer && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RuntimeSynchronizer, {}),
491
350
  children
492
351
  ] });
493
352
  };
494
353
 
354
+ // src/context/stores/AssistantActions.tsx
355
+ var import_zustand8 = require("zustand");
356
+ var makeAssistantActionsStore = (runtimeRef) => (0, import_zustand8.create)(
357
+ () => Object.freeze({
358
+ switchToThread: () => runtimeRef.current.switchToThread(null)
359
+ })
360
+ );
361
+
495
362
  // src/context/providers/AssistantProvider.tsx
496
363
  var import_jsx_runtime2 = require("react/jsx-runtime");
497
364
  var AssistantProvider = ({ children, runtime }) => {
498
- const runtimeRef = (0, import_react12.useRef)(runtime);
499
- (0, import_react12.useInsertionEffect)(() => {
365
+ const runtimeRef = (0, import_react4.useRef)(runtime);
366
+ (0, import_react4.useInsertionEffect)(() => {
500
367
  runtimeRef.current = runtime;
501
368
  });
502
- const [context] = (0, import_react12.useState)(() => {
369
+ const [context] = (0, import_react4.useState)(() => {
503
370
  const useModelConfig = makeAssistantModelConfigStore();
504
371
  const useToolUIs = makeAssistantToolUIsStore();
505
- return { useModelConfig, useToolUIs };
372
+ const useAssistantActions = makeAssistantActionsStore(runtimeRef);
373
+ return { useModelConfig, useToolUIs, useAssistantActions };
506
374
  });
507
375
  const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
508
- (0, import_react12.useEffect)(() => {
376
+ (0, import_react4.useEffect)(() => {
509
377
  return runtime.registerModelConfigProvider(getModelCOnfig);
510
378
  }, [runtime, getModelCOnfig]);
511
379
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ThreadProvider, { runtime, children }) });
@@ -516,14 +384,28 @@ var import_jsx_runtime3 = require("react/jsx-runtime");
516
384
  var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
517
385
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AssistantProvider, { runtime, children });
518
386
  };
519
- var AssistantRuntimeProvider = (0, import_react13.memo)(AssistantRuntimeProviderImpl);
387
+ var AssistantRuntimeProvider = (0, import_react5.memo)(AssistantRuntimeProviderImpl);
388
+
389
+ // src/context/react/ComposerContext.ts
390
+ var import_react7 = require("react");
391
+
392
+ // src/context/react/MessageContext.ts
393
+ var import_react6 = require("react");
394
+ var MessageContext = (0, import_react6.createContext)(null);
395
+ var useMessageContext = () => {
396
+ const context = (0, import_react6.useContext)(MessageContext);
397
+ if (!context)
398
+ throw new Error(
399
+ "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
400
+ );
401
+ return context;
402
+ };
520
403
 
521
404
  // src/context/react/ComposerContext.ts
522
- var import_react14 = require("react");
523
405
  var useComposerContext = () => {
524
406
  const { useComposer } = useThreadContext();
525
- const { useEditComposer } = (0, import_react14.useContext)(MessageContext) ?? {};
526
- return (0, import_react14.useMemo)(
407
+ const { useEditComposer } = (0, import_react7.useContext)(MessageContext) ?? {};
408
+ return (0, import_react7.useMemo)(
527
409
  () => ({
528
410
  useComposer: useEditComposer ?? useComposer,
529
411
  type: useEditComposer ? "edit" : "new"
@@ -533,12 +415,12 @@ var useComposerContext = () => {
533
415
  };
534
416
 
535
417
  // src/context/react/ContentPartContext.ts
536
- var import_react15 = require("react");
537
- var ContentPartContext = (0, import_react15.createContext)(
418
+ var import_react8 = require("react");
419
+ var ContentPartContext = (0, import_react8.createContext)(
538
420
  null
539
421
  );
540
422
  var useContentPartContext = () => {
541
- const context = (0, import_react15.useContext)(ContentPartContext);
423
+ const context = (0, import_react8.useContext)(ContentPartContext);
542
424
  if (!context)
543
425
  throw new Error(
544
426
  "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
@@ -546,11 +428,267 @@ var useContentPartContext = () => {
546
428
  return context;
547
429
  };
548
430
 
431
+ // src/hooks/useAppendMessage.tsx
432
+ var import_react9 = require("react");
433
+ var toAppendMessage = (useThreadMessages, message) => {
434
+ if (typeof message === "string") {
435
+ return {
436
+ parentId: useThreadMessages.getState().at(-1)?.id ?? null,
437
+ role: "user",
438
+ content: [{ type: "text", text: message }]
439
+ };
440
+ }
441
+ return {
442
+ parentId: message.parentId ?? useThreadMessages.getState().at(-1)?.id ?? null,
443
+ role: message.role ?? "user",
444
+ content: message.content
445
+ };
446
+ };
447
+ var useAppendMessage = () => {
448
+ const { useThreadMessages, useThreadActions, useViewport, useComposer } = useThreadContext();
449
+ const append = (0, import_react9.useCallback)(
450
+ (message) => {
451
+ const appendMessage = toAppendMessage(useThreadMessages, message);
452
+ useThreadActions.getState().append(appendMessage);
453
+ useViewport.getState().scrollToBottom();
454
+ useComposer.getState().focus();
455
+ },
456
+ [useThreadMessages, useThreadActions, useViewport, useComposer]
457
+ );
458
+ return append;
459
+ };
460
+
461
+ // src/hooks/useSwitchToNewThread.tsx
462
+ var import_react10 = require("react");
463
+ var useSwitchToNewThread = () => {
464
+ const { useAssistantActions } = useAssistantContext();
465
+ const { useComposer } = useThreadContext();
466
+ const switchToNewThread = (0, import_react10.useCallback)(() => {
467
+ useAssistantActions.getState().switchToThread(null);
468
+ useComposer.getState().focus();
469
+ }, [useAssistantActions, useComposer]);
470
+ return switchToNewThread;
471
+ };
472
+
473
+ // src/model-config/useAssistantTool.tsx
474
+ var import_react11 = require("react");
475
+ var useAssistantTool = (tool) => {
476
+ const { useModelConfig, useToolUIs } = useAssistantContext();
477
+ const registerModelConfigProvider = useModelConfig(
478
+ (s) => s.registerModelConfigProvider
479
+ );
480
+ const setToolUI = useToolUIs((s) => s.setToolUI);
481
+ (0, import_react11.useEffect)(() => {
482
+ const { toolName, render, ...rest } = tool;
483
+ const config = {
484
+ tools: {
485
+ [tool.toolName]: rest
486
+ }
487
+ };
488
+ const unsub1 = registerModelConfigProvider(() => config);
489
+ const unsub2 = render ? setToolUI(toolName, render) : void 0;
490
+ return () => {
491
+ unsub1();
492
+ unsub2?.();
493
+ };
494
+ }, [registerModelConfigProvider, setToolUI, tool]);
495
+ };
496
+
497
+ // src/model-config/makeAssistantTool.tsx
498
+ var makeAssistantTool = (tool) => {
499
+ const Tool = () => {
500
+ useAssistantTool(tool);
501
+ return null;
502
+ };
503
+ return Tool;
504
+ };
505
+
506
+ // src/model-config/useAssistantToolUI.tsx
507
+ var import_react12 = require("react");
508
+ var useAssistantToolUI = (tool) => {
509
+ const { useToolUIs } = useAssistantContext();
510
+ const setToolUI = useToolUIs((s) => s.setToolUI);
511
+ (0, import_react12.useEffect)(() => {
512
+ if (!tool) return;
513
+ const { toolName, render } = tool;
514
+ return setToolUI(toolName, render);
515
+ }, [setToolUI, tool]);
516
+ };
517
+
518
+ // src/model-config/makeAssistantToolUI.tsx
519
+ var makeAssistantToolUI = (tool) => {
520
+ const ToolUI = () => {
521
+ useAssistantToolUI(tool);
522
+ return null;
523
+ };
524
+ return ToolUI;
525
+ };
526
+
527
+ // src/model-config/useAssistantInstructions.tsx
528
+ var import_react13 = require("react");
529
+ var useAssistantInstructions = (instruction) => {
530
+ const { useModelConfig } = useAssistantContext();
531
+ const registerModelConfigProvider = useModelConfig(
532
+ (s) => s.registerModelConfigProvider
533
+ );
534
+ (0, import_react13.useEffect)(() => {
535
+ const config = {
536
+ system: instruction
537
+ };
538
+ return registerModelConfigProvider(() => config);
539
+ }, [registerModelConfigProvider, instruction]);
540
+ };
541
+
542
+ // src/primitive-hooks/actionBar/useActionBarCopy.tsx
543
+ var import_react16 = require("react");
544
+
545
+ // src/utils/combined/useCombinedStore.ts
546
+ var import_react15 = require("react");
547
+
548
+ // src/utils/combined/createCombinedStore.ts
549
+ var import_react14 = require("react");
550
+ var createCombinedStore = (stores) => {
551
+ const subscribe = (callback) => {
552
+ const unsubscribes = stores.map((store) => store.subscribe(callback));
553
+ return () => {
554
+ for (const unsub of unsubscribes) {
555
+ unsub();
556
+ }
557
+ };
558
+ };
559
+ return (selector) => {
560
+ const getSnapshot = () => selector(...stores.map((store) => store.getState()));
561
+ return (0, import_react14.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
562
+ };
563
+ };
564
+
565
+ // src/utils/combined/useCombinedStore.ts
566
+ var useCombinedStore = (stores, selector) => {
567
+ const useCombined = (0, import_react15.useMemo)(() => createCombinedStore(stores), stores);
568
+ return useCombined(selector);
569
+ };
570
+
571
+ // src/utils/getMessageText.tsx
572
+ var getMessageText = (message) => {
573
+ const textParts = message.content.filter(
574
+ (part) => part.type === "text"
575
+ );
576
+ return textParts.map((part) => part.text).join("\n\n");
577
+ };
578
+
579
+ // src/primitive-hooks/actionBar/useActionBarCopy.tsx
580
+ var useActionBarCopy = ({
581
+ copiedDuration = 3e3
582
+ } = {}) => {
583
+ const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();
584
+ const hasCopyableContent = useCombinedStore(
585
+ [useMessage, useEditComposer],
586
+ (m, c) => {
587
+ return !c.isEditing && m.message.content.some((c2) => c2.type === "text");
588
+ }
589
+ );
590
+ const callback = (0, import_react16.useCallback)(() => {
591
+ const { message } = useMessage.getState();
592
+ const { setIsCopied } = useMessageUtils.getState();
593
+ const { isEditing, value: composerValue } = useEditComposer.getState();
594
+ const valueToCopy = isEditing ? composerValue : getMessageText(message);
595
+ navigator.clipboard.writeText(valueToCopy);
596
+ setIsCopied(true);
597
+ setTimeout(() => setIsCopied(false), copiedDuration);
598
+ }, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);
599
+ if (!hasCopyableContent) return null;
600
+ return callback;
601
+ };
602
+
603
+ // src/primitive-hooks/actionBar/useActionBarEdit.tsx
604
+ var import_react17 = require("react");
605
+ var useActionBarEdit = () => {
606
+ const { useMessage, useEditComposer } = useMessageContext();
607
+ const disabled = useCombinedStore(
608
+ [useMessage, useEditComposer],
609
+ (m, c) => m.message.role !== "user" || c.isEditing
610
+ );
611
+ const callback = (0, import_react17.useCallback)(() => {
612
+ const { edit } = useEditComposer.getState();
613
+ edit();
614
+ }, [useEditComposer]);
615
+ if (disabled) return null;
616
+ return callback;
617
+ };
618
+
619
+ // src/primitive-hooks/actionBar/useActionBarReload.tsx
620
+ var import_react18 = require("react");
621
+ var useActionBarReload = () => {
622
+ const { useThread, useThreadActions, useComposer, useViewport } = useThreadContext();
623
+ const { useMessage } = useMessageContext();
624
+ const disabled = useCombinedStore(
625
+ [useThread, useMessage],
626
+ (t, m) => t.isRunning || m.message.role !== "assistant"
627
+ );
628
+ const callback = (0, import_react18.useCallback)(() => {
629
+ const { parentId } = useMessage.getState();
630
+ useThreadActions.getState().startRun(parentId);
631
+ useViewport.getState().scrollToBottom();
632
+ useComposer.getState().focus();
633
+ }, [useThreadActions, useComposer, useViewport, useMessage]);
634
+ if (disabled) return null;
635
+ return callback;
636
+ };
637
+
638
+ // src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
639
+ var useBranchPickerCount = () => {
640
+ const { useMessage } = useMessageContext();
641
+ const branchCount = useMessage((s) => s.branches.length);
642
+ return branchCount;
643
+ };
644
+
645
+ // src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
646
+ var import_react19 = require("react");
647
+ var useBranchPickerNext = () => {
648
+ const { useThreadActions } = useThreadContext();
649
+ const { useMessage, useEditComposer } = useMessageContext();
650
+ const disabled = useCombinedStore(
651
+ [useMessage, useEditComposer],
652
+ (m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
653
+ );
654
+ const callback = (0, import_react19.useCallback)(() => {
655
+ const { message, branches } = useMessage.getState();
656
+ useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
657
+ }, [useThreadActions, useMessage]);
658
+ if (disabled) return null;
659
+ return callback;
660
+ };
661
+
662
+ // src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
663
+ var useBranchPickerNumber = () => {
664
+ const { useMessage } = useMessageContext();
665
+ const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
666
+ return branchIdx + 1;
667
+ };
668
+
669
+ // src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
670
+ var import_react20 = require("react");
671
+ var useBranchPickerPrevious = () => {
672
+ const { useThreadActions } = useThreadContext();
673
+ const { useMessage, useEditComposer } = useMessageContext();
674
+ const disabled = useCombinedStore(
675
+ [useMessage, useEditComposer],
676
+ (m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
677
+ );
678
+ const callback = (0, import_react20.useCallback)(() => {
679
+ const { message, branches } = useMessage.getState();
680
+ useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
681
+ }, [useThreadActions, useMessage]);
682
+ if (disabled) return null;
683
+ return callback;
684
+ };
685
+
549
686
  // src/primitive-hooks/composer/useComposerCancel.tsx
687
+ var import_react21 = require("react");
550
688
  var useComposerCancel = () => {
551
689
  const { useComposer } = useComposerContext();
552
690
  const disabled = useComposer((c) => !c.isEditing);
553
- const callback = (0, import_react16.useCallback)(() => {
691
+ const callback = (0, import_react21.useCallback)(() => {
554
692
  const { cancel } = useComposer.getState();
555
693
  cancel();
556
694
  }, [useComposer]);
@@ -569,12 +707,12 @@ var useComposerIf = (props) => {
569
707
  };
570
708
 
571
709
  // src/primitive-hooks/composer/useComposerSend.tsx
572
- var import_react17 = require("react");
710
+ var import_react22 = require("react");
573
711
  var useComposerSend = () => {
574
712
  const { useViewport, useComposer: useNewComposer } = useThreadContext();
575
713
  const { useComposer } = useComposerContext();
576
714
  const disabled = useComposer((c) => !c.isEditing || c.value.length === 0);
577
- const callback = (0, import_react17.useCallback)(() => {
715
+ const callback = (0, import_react22.useCallback)(() => {
578
716
  const composerState = useComposer.getState();
579
717
  if (!composerState.isEditing) return;
580
718
  composerState.send();
@@ -611,17 +749,6 @@ var useContentPartImage = () => {
611
749
  return image;
612
750
  };
613
751
 
614
- // src/primitive-hooks/contentPart/useContentPartInProgressIndicator.tsx
615
- var useContentPartInProgressIndicator = () => {
616
- const { useMessageUtils } = useMessageContext();
617
- const { useContentPart } = useContentPartContext();
618
- const indicator = useCombinedStore(
619
- [useMessageUtils, useContentPart],
620
- (m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
621
- );
622
- return indicator;
623
- };
624
-
625
752
  // src/primitive-hooks/contentPart/useContentPartText.tsx
626
753
  var useContentPartText = () => {
627
754
  const { useContentPart } = useContentPartContext();
@@ -654,14 +781,17 @@ var useMessageIf = (props) => {
654
781
 
655
782
  // src/primitive-hooks/thread/useThreadIf.tsx
656
783
  var useThreadIf = (props) => {
657
- const { useThread } = useThreadContext();
658
- return useThread((thread) => {
659
- if (props.empty === true && thread.messages.length !== 0) return false;
660
- if (props.empty === false && thread.messages.length === 0) return false;
661
- if (props.running === true && !thread.isRunning) return false;
662
- if (props.running === false && thread.isRunning) return false;
663
- return true;
664
- });
784
+ const { useThread, useThreadMessages } = useThreadContext();
785
+ return useCombinedStore(
786
+ [useThread, useThreadMessages],
787
+ (thread, messages) => {
788
+ if (props.empty === true && messages.length !== 0) return false;
789
+ if (props.empty === false && messages.length === 0) return false;
790
+ if (props.running === true && !thread.isRunning) return false;
791
+ if (props.running === false && thread.isRunning) return false;
792
+ return true;
793
+ }
794
+ );
665
795
  };
666
796
 
667
797
  // src/primitive-hooks/thread/useThreadEmpty.tsx
@@ -670,11 +800,11 @@ var useThreadEmpty = () => {
670
800
  };
671
801
 
672
802
  // src/primitive-hooks/thread/useThreadScrollToBottom.tsx
673
- var import_react18 = require("react");
803
+ var import_react23 = require("react");
674
804
  var useThreadScrollToBottom = () => {
675
805
  const { useComposer, useViewport } = useThreadContext();
676
806
  const isAtBottom = useViewport((s) => s.isAtBottom);
677
- const handleScrollToBottom = (0, import_react18.useCallback)(() => {
807
+ const handleScrollToBottom = (0, import_react23.useCallback)(() => {
678
808
  useViewport.getState().scrollToBottom();
679
809
  useComposer.getState().focus();
680
810
  }, [useViewport, useComposer]);
@@ -683,14 +813,14 @@ var useThreadScrollToBottom = () => {
683
813
  };
684
814
 
685
815
  // src/primitive-hooks/thread/useThreadSuggestion.tsx
686
- var import_react19 = require("react");
816
+ var import_react24 = require("react");
687
817
  var useThreadSuggestion = ({
688
818
  prompt,
689
819
  autoSend
690
820
  }) => {
691
821
  const { useThread, useComposer } = useThreadContext();
692
822
  const disabled = useThread((t) => t.isRunning);
693
- const callback = (0, import_react19.useCallback)(() => {
823
+ const callback = (0, import_react24.useCallback)(() => {
694
824
  const thread = useThread.getState();
695
825
  const composer = useComposer.getState();
696
826
  composer.setValue(prompt);
@@ -705,16 +835,17 @@ var useThreadSuggestion = ({
705
835
  // src/primitives/actionBar/index.ts
706
836
  var actionBar_exports = {};
707
837
  __export(actionBar_exports, {
708
- Copy: () => ActionBarCopy,
709
- Edit: () => ActionBarEdit,
710
- Reload: () => ActionBarReload,
711
- Root: () => ActionBarRoot
838
+ Copy: () => ActionBarPrimitiveCopy,
839
+ Edit: () => ActionBarPrimitiveEdit,
840
+ Reload: () => ActionBarPrimitiveReload,
841
+ Root: () => ActionBarPrimitiveRoot
712
842
  });
713
843
 
714
844
  // src/primitives/actionBar/ActionBarRoot.tsx
715
845
  var import_react_primitive = require("@radix-ui/react-primitive");
716
- var import_react20 = require("react");
717
- var import_jsx_runtime4 = require("react/jsx-runtime");
846
+ var import_react25 = require("react");
847
+
848
+ // src/primitives/actionBar/useActionBarFloatStatus.tsx
718
849
  var useActionBarFloatStatus = ({
719
850
  hideWhenRunning,
720
851
  autohide,
@@ -735,7 +866,10 @@ var useActionBarFloatStatus = ({
735
866
  }
736
867
  );
737
868
  };
738
- var ActionBarRoot = (0, import_react20.forwardRef)(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
869
+
870
+ // src/primitives/actionBar/ActionBarRoot.tsx
871
+ var import_jsx_runtime4 = require("react/jsx-runtime");
872
+ var ActionBarPrimitiveRoot = (0, import_react25.forwardRef)(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
739
873
  const hideAndfloatStatus = useActionBarFloatStatus({
740
874
  hideWhenRunning,
741
875
  autohide,
@@ -751,15 +885,15 @@ var ActionBarRoot = (0, import_react20.forwardRef)(({ hideWhenRunning, autohide,
751
885
  }
752
886
  );
753
887
  });
754
- ActionBarRoot.displayName = "ActionBarRoot";
888
+ ActionBarPrimitiveRoot.displayName = "ActionBarPrimitive.Root";
755
889
 
756
890
  // src/utils/createActionButton.tsx
757
891
  var import_primitive = require("@radix-ui/primitive");
758
892
  var import_react_primitive2 = require("@radix-ui/react-primitive");
759
- var import_react21 = require("react");
893
+ var import_react26 = require("react");
760
894
  var import_jsx_runtime5 = require("react/jsx-runtime");
761
895
  var createActionButton = (displayName, useActionButton) => {
762
- const ActionButton = (0, import_react21.forwardRef)((props, forwardedRef) => {
896
+ const ActionButton = (0, import_react26.forwardRef)((props, forwardedRef) => {
763
897
  const callback = useActionButton(props);
764
898
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
765
899
  import_react_primitive2.Primitive.button,
@@ -779,61 +913,64 @@ var createActionButton = (displayName, useActionButton) => {
779
913
  };
780
914
 
781
915
  // src/primitives/actionBar/ActionBarCopy.tsx
782
- var ActionBarCopy = createActionButton(
783
- "ActionBarCopy",
916
+ var ActionBarPrimitiveCopy = createActionButton(
917
+ "ActionBarPrimitive.Copy",
784
918
  useActionBarCopy
785
919
  );
786
920
 
787
921
  // src/primitives/actionBar/ActionBarReload.tsx
788
- var ActionBarReload = createActionButton(
789
- "ActionBarReload",
922
+ var ActionBarPrimitiveReload = createActionButton(
923
+ "ActionBarPrimitive.Reload",
790
924
  useActionBarReload
791
925
  );
792
926
 
793
927
  // src/primitives/actionBar/ActionBarEdit.tsx
794
- var ActionBarEdit = createActionButton(
795
- "ActionBarEdit",
928
+ var ActionBarPrimitiveEdit = createActionButton(
929
+ "ActionBarPrimitive.Edit",
796
930
  useActionBarEdit
797
931
  );
798
932
 
799
933
  // src/primitives/assistantModal/index.ts
800
934
  var assistantModal_exports = {};
801
935
  __export(assistantModal_exports, {
802
- Content: () => AssistantModalContent,
803
- Root: () => AssistantModalRoot,
804
- Trigger: () => AssistantModalTrigger
936
+ Content: () => AssistantModalPrimitiveContent,
937
+ Root: () => AssistantModalPrimitiveRoot,
938
+ Trigger: () => AssistantModalPrimitiveTrigger
805
939
  });
806
940
 
807
941
  // src/primitives/assistantModal/AssistantModalRoot.tsx
808
- var import_react23 = require("react");
809
- var PopoverPrimitive = __toESM(require("@radix-ui/react-popover"));
942
+ var import_react28 = require("react");
943
+ var PopoverPrimitive2 = __toESM(require("@radix-ui/react-popover"));
810
944
  var import_primitive2 = require("@radix-ui/primitive");
811
945
 
812
946
  // src/utils/hooks/useOnComposerFocus.tsx
813
947
  var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
814
- var import_react22 = require("react");
948
+ var import_react27 = require("react");
815
949
  var useOnComposerFocus = (callback) => {
816
950
  const callbackRef = (0, import_react_use_callback_ref.useCallbackRef)(callback);
817
951
  const { useComposer } = useThreadContext();
818
- (0, import_react22.useEffect)(() => {
952
+ (0, import_react27.useEffect)(() => {
819
953
  return useComposer.getState().onFocus(() => {
820
954
  callbackRef();
821
955
  });
822
956
  }, [useComposer, callbackRef]);
823
957
  };
824
958
 
959
+ // src/primitives/assistantModal/scope.tsx
960
+ var PopoverPrimitive = __toESM(require("@radix-ui/react-popover"));
961
+ var usePopoverScope = PopoverPrimitive.createPopoverScope();
962
+
825
963
  // src/primitives/assistantModal/AssistantModalRoot.tsx
826
964
  var import_jsx_runtime6 = require("react/jsx-runtime");
827
- var usePopoverScope = PopoverPrimitive.createPopoverScope();
828
965
  var useAssistantModalOpenState = (defaultOpen = false) => {
829
- const state = (0, import_react23.useState)(defaultOpen);
966
+ const state = (0, import_react28.useState)(defaultOpen);
830
967
  const [, setOpen] = state;
831
968
  useOnComposerFocus(() => {
832
969
  setOpen(true);
833
970
  });
834
971
  return state;
835
972
  };
836
- var AssistantModalRoot = ({
973
+ var AssistantModalPrimitiveRoot = ({
837
974
  __scopeAssistantModal,
838
975
  defaultOpen,
839
976
  open,
@@ -843,7 +980,7 @@ var AssistantModalRoot = ({
843
980
  const scope = usePopoverScope(__scopeAssistantModal);
844
981
  const [modalOpen, setOpen] = useAssistantModalOpenState(defaultOpen);
845
982
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
846
- PopoverPrimitive.Root,
983
+ PopoverPrimitive2.Root,
847
984
  {
848
985
  ...scope,
849
986
  open: open === void 0 ? modalOpen : open,
@@ -852,26 +989,29 @@ var AssistantModalRoot = ({
852
989
  }
853
990
  );
854
991
  };
855
- AssistantModalRoot.displayName = "AssistantModalRoot";
992
+ AssistantModalPrimitiveRoot.displayName = "AssistantModalPrimitive.Root";
856
993
 
857
994
  // src/primitives/assistantModal/AssistantModalTrigger.tsx
858
- var import_react24 = require("react");
859
- var PopoverPrimitive2 = __toESM(require("@radix-ui/react-popover"));
995
+ var import_react29 = require("react");
996
+ var PopoverPrimitive3 = __toESM(require("@radix-ui/react-popover"));
860
997
  var import_jsx_runtime7 = require("react/jsx-runtime");
861
- var AssistantModalTrigger = (0, import_react24.forwardRef)(
862
- ({ __scopeAssistantModal, ...rest }, ref) => {
998
+ var AssistantModalPrimitiveTrigger = (0, import_react29.forwardRef)(
999
+ ({
1000
+ __scopeAssistantModal,
1001
+ ...rest
1002
+ }, ref) => {
863
1003
  const scope = usePopoverScope(__scopeAssistantModal);
864
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PopoverPrimitive2.Trigger, { ...scope, ...rest, ref });
1004
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PopoverPrimitive3.Trigger, { ...scope, ...rest, ref });
865
1005
  }
866
1006
  );
867
- AssistantModalTrigger.displayName = "AssistantModalTrigger";
1007
+ AssistantModalPrimitiveTrigger.displayName = "AssistantModalPrimitive.Trigger";
868
1008
 
869
1009
  // src/primitives/assistantModal/AssistantModalContent.tsx
870
- var import_react25 = require("react");
871
- var PopoverPrimitive3 = __toESM(require("@radix-ui/react-popover"));
1010
+ var import_react30 = require("react");
1011
+ var PopoverPrimitive4 = __toESM(require("@radix-ui/react-popover"));
872
1012
  var import_primitive3 = require("@radix-ui/primitive");
873
1013
  var import_jsx_runtime8 = require("react/jsx-runtime");
874
- var AssistantModalContent = (0, import_react25.forwardRef)(
1014
+ var AssistantModalPrimitiveContent = (0, import_react30.forwardRef)(
875
1015
  ({
876
1016
  __scopeAssistantModal,
877
1017
  side,
@@ -881,8 +1021,8 @@ var AssistantModalContent = (0, import_react25.forwardRef)(
881
1021
  ...props
882
1022
  }, forwardedRef) => {
883
1023
  const scope = usePopoverScope(__scopeAssistantModal);
884
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PopoverPrimitive3.Portal, { ...scope, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
885
- PopoverPrimitive3.Content,
1024
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PopoverPrimitive4.Portal, { ...scope, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1025
+ PopoverPrimitive4.Content,
886
1026
  {
887
1027
  ...scope,
888
1028
  ...props,
@@ -897,97 +1037,101 @@ var AssistantModalContent = (0, import_react25.forwardRef)(
897
1037
  ) });
898
1038
  }
899
1039
  );
900
- AssistantModalContent.displayName = "AssistantModalContent";
1040
+ AssistantModalPrimitiveContent.displayName = "AssistantModalPrimitive.Content";
901
1041
 
902
1042
  // src/primitives/branchPicker/index.ts
903
1043
  var branchPicker_exports = {};
904
1044
  __export(branchPicker_exports, {
905
- Count: () => BranchPickerCount,
906
- Next: () => BranchPickerNext,
907
- Number: () => BranchPickerNumber,
1045
+ Count: () => BranchPickerPrimitiveCount,
1046
+ Next: () => BranchPickerPrimitiveNext,
1047
+ Number: () => BranchPickerPrimitiveNumber,
908
1048
  Previous: () => BranchPickerPrevious,
909
- Root: () => BranchPickerRoot
1049
+ Root: () => BranchPickerPrimitiveRoot
910
1050
  });
911
1051
 
912
1052
  // src/primitives/branchPicker/BranchPickerNext.tsx
913
- var BranchPickerNext = createActionButton(
914
- "BranchPickerNext",
1053
+ var BranchPickerPrimitiveNext = createActionButton(
1054
+ "BranchPickerPrimitive.Next",
915
1055
  useBranchPickerNext
916
1056
  );
917
1057
 
918
1058
  // src/primitives/branchPicker/BranchPickerPrevious.tsx
919
1059
  var BranchPickerPrevious = createActionButton(
920
- "BranchPickerPrevious",
1060
+ "BranchPickerPrimitive.Previous",
921
1061
  useBranchPickerPrevious
922
1062
  );
923
1063
 
924
1064
  // src/primitives/branchPicker/BranchPickerCount.tsx
925
1065
  var import_jsx_runtime9 = require("react/jsx-runtime");
926
- var BranchPickerCount = () => {
1066
+ var BranchPickerPrimitiveCount = () => {
927
1067
  const branchCount = useBranchPickerCount();
928
1068
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: branchCount });
929
1069
  };
1070
+ BranchPickerPrimitiveCount.displayName = "BranchPickerPrimitive.Count";
930
1071
 
931
1072
  // src/primitives/branchPicker/BranchPickerNumber.tsx
932
1073
  var import_jsx_runtime10 = require("react/jsx-runtime");
933
- var BranchPickerNumber = () => {
1074
+ var BranchPickerPrimitiveNumber = () => {
934
1075
  const branchNumber = useBranchPickerNumber();
935
1076
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: branchNumber });
936
1077
  };
1078
+ BranchPickerPrimitiveNumber.displayName = "BranchPickerPrimitive.Number";
937
1079
 
938
1080
  // src/primitives/branchPicker/BranchPickerRoot.tsx
939
1081
  var import_react_primitive6 = require("@radix-ui/react-primitive");
940
- var import_react31 = require("react");
1082
+ var import_react37 = require("react");
941
1083
 
942
1084
  // src/primitives/message/index.ts
943
1085
  var message_exports = {};
944
1086
  __export(message_exports, {
945
- Content: () => MessageContent,
946
- If: () => MessageIf,
947
- InProgress: () => MessageInProgress,
948
- Root: () => MessageRoot
1087
+ Content: () => MessagePrimitiveContent,
1088
+ If: () => MessagePrimitiveIf,
1089
+ InProgress: () => MessagePrimitiveInProgress,
1090
+ Root: () => MessagePrimitiveRoot
949
1091
  });
950
1092
 
951
1093
  // src/primitives/message/MessageRoot.tsx
952
1094
  var import_primitive4 = require("@radix-ui/primitive");
953
1095
  var import_react_primitive3 = require("@radix-ui/react-primitive");
954
- var import_react26 = require("react");
1096
+ var import_react31 = require("react");
955
1097
  var import_jsx_runtime11 = require("react/jsx-runtime");
956
- var MessageRoot = (0, import_react26.forwardRef)(
957
- ({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
958
- const { useMessageUtils } = useMessageContext();
959
- const setIsHovering = useMessageUtils((s) => s.setIsHovering);
960
- const handleMouseEnter = () => {
961
- setIsHovering(true);
962
- };
963
- const handleMouseLeave = () => {
964
- setIsHovering(false);
965
- };
966
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
967
- import_react_primitive3.Primitive.div,
968
- {
969
- ...rest,
970
- ref,
971
- onMouseEnter: (0, import_primitive4.composeEventHandlers)(onMouseEnter, handleMouseEnter),
972
- onMouseLeave: (0, import_primitive4.composeEventHandlers)(onMouseLeave, handleMouseLeave)
973
- }
974
- );
975
- }
976
- );
977
- MessageRoot.displayName = "MessageRoot";
1098
+ var MessagePrimitiveRoot = (0, import_react31.forwardRef)(({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
1099
+ const { useMessageUtils } = useMessageContext();
1100
+ const setIsHovering = useMessageUtils((s) => s.setIsHovering);
1101
+ const handleMouseEnter = () => {
1102
+ setIsHovering(true);
1103
+ };
1104
+ const handleMouseLeave = () => {
1105
+ setIsHovering(false);
1106
+ };
1107
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1108
+ import_react_primitive3.Primitive.div,
1109
+ {
1110
+ ...rest,
1111
+ ref,
1112
+ onMouseEnter: (0, import_primitive4.composeEventHandlers)(onMouseEnter, handleMouseEnter),
1113
+ onMouseLeave: (0, import_primitive4.composeEventHandlers)(onMouseLeave, handleMouseLeave)
1114
+ }
1115
+ );
1116
+ });
1117
+ MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
978
1118
 
979
1119
  // src/primitives/message/MessageIf.tsx
980
- var MessageIf = ({ children, ...query }) => {
1120
+ var MessagePrimitiveIf = ({
1121
+ children,
1122
+ ...query
1123
+ }) => {
981
1124
  const result = useMessageIf(query);
982
1125
  return result ? children : null;
983
1126
  };
1127
+ MessagePrimitiveIf.displayName = "MessagePrimitive.If";
984
1128
 
985
1129
  // src/primitives/message/MessageContent.tsx
986
- var import_react29 = require("react");
1130
+ var import_react35 = require("react");
987
1131
 
988
1132
  // src/context/providers/ContentPartProvider.tsx
989
- var import_react27 = require("react");
990
- var import_zustand7 = require("zustand");
1133
+ var import_react32 = require("react");
1134
+ var import_zustand9 = require("zustand");
991
1135
  var import_jsx_runtime12 = require("react/jsx-runtime");
992
1136
  var syncContentPart = ({ message }, useContentPart, partIndex) => {
993
1137
  const part = message.content[partIndex];
@@ -1005,14 +1149,14 @@ var syncContentPart = ({ message }, useContentPart, partIndex) => {
1005
1149
  };
1006
1150
  var useContentPartContext2 = (partIndex) => {
1007
1151
  const { useMessage } = useMessageContext();
1008
- const [context] = (0, import_react27.useState)(() => {
1009
- const useContentPart = (0, import_zustand7.create)(
1152
+ const [context] = (0, import_react32.useState)(() => {
1153
+ const useContentPart = (0, import_zustand9.create)(
1010
1154
  () => ({})
1011
1155
  );
1012
1156
  syncContentPart(useMessage.getState(), useContentPart, partIndex);
1013
1157
  return { useContentPart };
1014
1158
  });
1015
- (0, import_react27.useEffect)(() => {
1159
+ (0, import_react32.useEffect)(() => {
1016
1160
  syncContentPart(useMessage.getState(), context.useContentPart, partIndex);
1017
1161
  return useMessage.subscribe((message) => {
1018
1162
  syncContentPart(message, context.useContentPart, partIndex);
@@ -1029,42 +1173,67 @@ var ContentPartProvider = ({
1029
1173
  };
1030
1174
 
1031
1175
  // src/primitives/contentPart/ContentPartDisplay.tsx
1032
- var ContentPartDisplay = () => {
1176
+ var ContentPartPrimitiveDisplay = () => {
1033
1177
  const display = useContentPartDisplay();
1034
1178
  return display ?? null;
1035
1179
  };
1180
+ ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
1181
+
1182
+ // src/utils/OutPortal.tsx
1183
+ var import_react33 = require("react");
1184
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1185
+ var OutPortal = ({ node }) => {
1186
+ const parentRef = (0, import_react33.useRef)(null);
1187
+ (0, import_react33.useLayoutEffect)(() => {
1188
+ const parent = parentRef.current;
1189
+ if (!parent || !node) return;
1190
+ parent.appendChild(node);
1191
+ return () => {
1192
+ parent.removeChild(node);
1193
+ };
1194
+ }, [node]);
1195
+ if (!node) return null;
1196
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { ref: parentRef });
1197
+ };
1036
1198
 
1037
1199
  // src/primitives/contentPart/ContentPartInProgressIndicator.tsx
1038
- var ContentPartInProgressIndicator = () => {
1039
- const indicator = useContentPartInProgressIndicator();
1040
- return indicator;
1200
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1201
+ var ContentPartPrimitiveInProgressIndicator = () => {
1202
+ const { useMessageUtils } = useMessageContext();
1203
+ const { useContentPart } = useContentPartContext();
1204
+ const indicator = useCombinedStore(
1205
+ [useMessageUtils, useContentPart],
1206
+ (m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
1207
+ );
1208
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(OutPortal, { node: indicator });
1041
1209
  };
1210
+ ContentPartPrimitiveInProgressIndicator.displayName = "ContentPartPrimitive.InProgressIndicator";
1042
1211
 
1043
1212
  // src/primitives/contentPart/ContentPartText.tsx
1044
1213
  var import_react_primitive4 = require("@radix-ui/react-primitive");
1045
- var import_react28 = require("react");
1046
- var import_jsx_runtime13 = require("react/jsx-runtime");
1047
- var ContentPartText = (0, import_react28.forwardRef)((props, forwardedRef) => {
1214
+ var import_react34 = require("react");
1215
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1216
+ var ContentPartPrimitiveText = (0, import_react34.forwardRef)((props, forwardedRef) => {
1048
1217
  const text = useContentPartText();
1049
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_primitive4.Primitive.p, { ...props, ref: forwardedRef, children: text });
1218
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_primitive4.Primitive.span, { ...props, ref: forwardedRef, children: text });
1050
1219
  });
1051
- ContentPartText.displayName = "ContentPartText";
1220
+ ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
1052
1221
 
1053
1222
  // src/primitives/message/MessageContent.tsx
1054
- var import_jsx_runtime14 = require("react/jsx-runtime");
1223
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1055
1224
  var defaultComponents = {
1056
- Text: () => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
1057
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ContentPartText, { style: { whiteSpace: "pre-line" } }),
1058
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ContentPartInProgressIndicator, {})
1225
+ Text: () => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("p", { style: { whiteSpace: "pre-line" }, children: [
1226
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveText, {}),
1227
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveInProgressIndicator, {})
1059
1228
  ] }),
1060
1229
  Image: () => null,
1061
- UI: () => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ContentPartDisplay, {}),
1230
+ UI: () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartPrimitiveDisplay, {}),
1062
1231
  tools: {
1063
1232
  Fallback: (props) => {
1064
1233
  const { useToolUIs } = useAssistantContext();
1065
1234
  const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));
1066
1235
  if (!Render) return null;
1067
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Render, { ...props });
1236
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Render, { ...props });
1068
1237
  }
1069
1238
  }
1070
1239
  };
@@ -1083,15 +1252,15 @@ var MessageContentPartComponent = ({
1083
1252
  const type = part.type;
1084
1253
  switch (type) {
1085
1254
  case "text":
1086
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Text, { part, status });
1255
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Text, { part, status });
1087
1256
  case "image":
1088
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Image, { part, status });
1257
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Image, { part, status });
1089
1258
  case "ui":
1090
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(UI, { part, status });
1259
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(UI, { part, status });
1091
1260
  case "tool-call": {
1092
1261
  const Tool = by_name[part.toolName] || Fallback;
1093
1262
  const addResult = (result) => addToolResult(part.toolCallId, result);
1094
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Tool, { part, status, addResult });
1263
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Tool, { part, status, addResult });
1095
1264
  }
1096
1265
  default:
1097
1266
  throw new Error(`Unknown content part type: ${type}`);
@@ -1101,18 +1270,20 @@ var MessageContentPartImpl = ({
1101
1270
  partIndex,
1102
1271
  components
1103
1272
  }) => {
1104
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ContentPartProvider, { partIndex, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageContentPartComponent, { components }) });
1273
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartProvider, { partIndex, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(MessageContentPartComponent, { components }) });
1105
1274
  };
1106
- var MessageContentPart = (0, import_react29.memo)(
1275
+ var MessageContentPart = (0, import_react35.memo)(
1107
1276
  MessageContentPartImpl,
1108
1277
  (prev, next) => prev.partIndex === next.partIndex && prev.components?.Text === next.components?.Text && prev.components?.Image === next.components?.Image && prev.components?.UI === next.components?.UI && prev.components?.tools === next.components?.tools
1109
1278
  );
1110
- var MessageContent = ({ components }) => {
1279
+ var MessagePrimitiveContent = ({
1280
+ components
1281
+ }) => {
1111
1282
  const { useMessage } = useMessageContext();
1112
1283
  const contentLength = useMessage((s) => s.message.content.length);
1113
1284
  return new Array(contentLength).fill(null).map((_, idx) => {
1114
1285
  const partIndex = idx;
1115
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1286
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1116
1287
  MessageContentPart,
1117
1288
  {
1118
1289
  partIndex,
@@ -1122,71 +1293,69 @@ var MessageContent = ({ components }) => {
1122
1293
  );
1123
1294
  });
1124
1295
  };
1296
+ MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
1125
1297
 
1126
1298
  // src/primitives/message/MessageInProgress.tsx
1299
+ var import_react_dom = require("react-dom");
1127
1300
  var import_react_primitive5 = require("@radix-ui/react-primitive");
1128
- var import_react30 = require("react");
1129
- var import_jsx_runtime15 = require("react/jsx-runtime");
1130
- var MessageInProgress = (0, import_react30.forwardRef)((props, ref) => {
1301
+ var import_react36 = require("react");
1302
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1303
+ var MessagePrimitiveInProgress = (0, import_react36.forwardRef)((props, ref) => {
1131
1304
  const { useMessageUtils } = useMessageContext();
1132
- (0, import_react30.useMemo)(() => {
1133
- useMessageUtils.getState().setInProgressIndicator(/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_primitive5.Primitive.span, { ...props, ref }));
1134
- }, [useMessageUtils, props, ref]);
1135
- return null;
1305
+ const portalNode = useMessageUtils((s) => s.inProgressIndicator);
1306
+ return (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_primitive5.Primitive.span, { ...props, ref }), portalNode);
1136
1307
  });
1137
- MessageInProgress.displayName = "MessageInProgress";
1308
+ MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
1138
1309
 
1139
1310
  // src/primitives/branchPicker/BranchPickerRoot.tsx
1140
- var import_jsx_runtime16 = require("react/jsx-runtime");
1141
- var BranchPickerRoot = (0, import_react31.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
1142
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_primitive6.Primitive.div, { ...rest, ref }) });
1311
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1312
+ var BranchPickerPrimitiveRoot = (0, import_react37.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
1313
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_primitive6.Primitive.div, { ...rest, ref }) });
1143
1314
  });
1144
- BranchPickerRoot.displayName = "BranchPickerRoot";
1315
+ BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
1145
1316
 
1146
1317
  // src/primitives/composer/index.ts
1147
1318
  var composer_exports = {};
1148
1319
  __export(composer_exports, {
1149
- Cancel: () => ComposerCancel,
1150
- If: () => ComposerIf,
1151
- Input: () => ComposerInput,
1152
- Root: () => ComposerRoot,
1153
- Send: () => ComposerSend
1320
+ Cancel: () => ComposerPrimitiveCancel,
1321
+ If: () => ComposerPrimitiveIf,
1322
+ Input: () => ComposerPrimitiveInput,
1323
+ Root: () => ComposerPrimitiveRoot,
1324
+ Send: () => ComposerPrimitiveSend
1154
1325
  });
1155
1326
 
1156
1327
  // src/primitives/composer/ComposerRoot.tsx
1157
1328
  var import_primitive5 = require("@radix-ui/primitive");
1158
1329
  var import_react_primitive7 = require("@radix-ui/react-primitive");
1159
- var import_react32 = require("react");
1160
- var import_jsx_runtime17 = require("react/jsx-runtime");
1161
- var ComposerRoot = (0, import_react32.forwardRef)(
1162
- ({ onSubmit, ...rest }, forwardedRef) => {
1163
- const send = useComposerSend();
1164
- const handleSubmit = (e) => {
1165
- if (!send) return;
1166
- e.preventDefault();
1167
- send();
1168
- };
1169
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1170
- import_react_primitive7.Primitive.form,
1171
- {
1172
- ...rest,
1173
- ref: forwardedRef,
1174
- onSubmit: (0, import_primitive5.composeEventHandlers)(onSubmit, handleSubmit)
1175
- }
1176
- );
1177
- }
1178
- );
1179
- ComposerRoot.displayName = "ComposerRoot";
1330
+ var import_react38 = require("react");
1331
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1332
+ var ComposerPrimitiveRoot = (0, import_react38.forwardRef)(({ onSubmit, ...rest }, forwardedRef) => {
1333
+ const send = useComposerSend();
1334
+ const handleSubmit = (e) => {
1335
+ e.preventDefault();
1336
+ if (!send) return;
1337
+ send();
1338
+ };
1339
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1340
+ import_react_primitive7.Primitive.form,
1341
+ {
1342
+ ...rest,
1343
+ ref: forwardedRef,
1344
+ onSubmit: (0, import_primitive5.composeEventHandlers)(onSubmit, handleSubmit)
1345
+ }
1346
+ );
1347
+ });
1348
+ ComposerPrimitiveRoot.displayName = "ComposerPrimitive.Root";
1180
1349
 
1181
1350
  // src/primitives/composer/ComposerInput.tsx
1182
1351
  var import_primitive6 = require("@radix-ui/primitive");
1183
1352
  var import_react_compose_refs = require("@radix-ui/react-compose-refs");
1184
1353
  var import_react_slot = require("@radix-ui/react-slot");
1185
- var import_react33 = require("react");
1354
+ var import_react39 = require("react");
1186
1355
  var import_react_textarea_autosize = __toESM(require("react-textarea-autosize"));
1187
1356
  var import_react_use_escape_keydown = require("@radix-ui/react-use-escape-keydown");
1188
- var import_jsx_runtime18 = require("react/jsx-runtime");
1189
- var ComposerInput = (0, import_react33.forwardRef)(
1357
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1358
+ var ComposerPrimitiveInput = (0, import_react39.forwardRef)(
1190
1359
  ({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
1191
1360
  const { useThread } = useThreadContext();
1192
1361
  const { useComposer, type } = useComposerContext();
@@ -1195,7 +1364,7 @@ var ComposerInput = (0, import_react33.forwardRef)(
1195
1364
  return c.value;
1196
1365
  });
1197
1366
  const Component = asChild ? import_react_slot.Slot : import_react_textarea_autosize.default;
1198
- const textareaRef = (0, import_react33.useRef)(null);
1367
+ const textareaRef = (0, import_react39.useRef)(null);
1199
1368
  const ref = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, textareaRef);
1200
1369
  (0, import_react_use_escape_keydown.useEscapeKeydown)((e) => {
1201
1370
  const composer = useComposer.getState();
@@ -1214,7 +1383,7 @@ var ComposerInput = (0, import_react33.forwardRef)(
1214
1383
  }
1215
1384
  };
1216
1385
  const autoFocusEnabled = autoFocus && !disabled;
1217
- const focus = (0, import_react33.useCallback)(() => {
1386
+ const focus = (0, import_react39.useCallback)(() => {
1218
1387
  const textarea = textareaRef.current;
1219
1388
  if (!textarea || !autoFocusEnabled) return;
1220
1389
  textarea.focus({ preventScroll: true });
@@ -1223,13 +1392,13 @@ var ComposerInput = (0, import_react33.forwardRef)(
1223
1392
  textareaRef.current.value.length
1224
1393
  );
1225
1394
  }, [autoFocusEnabled]);
1226
- (0, import_react33.useEffect)(() => focus(), [focus]);
1395
+ (0, import_react39.useEffect)(() => focus(), [focus]);
1227
1396
  useOnComposerFocus(() => {
1228
1397
  if (type === "new") {
1229
1398
  focus();
1230
1399
  }
1231
1400
  });
1232
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1401
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1233
1402
  Component,
1234
1403
  {
1235
1404
  value,
@@ -1246,113 +1415,120 @@ var ComposerInput = (0, import_react33.forwardRef)(
1246
1415
  );
1247
1416
  }
1248
1417
  );
1249
- ComposerInput.displayName = "ComposerInput";
1418
+ ComposerPrimitiveInput.displayName = "ComposerPrimitive.Input";
1250
1419
 
1251
1420
  // src/primitives/composer/ComposerSend.tsx
1252
- var import_react34 = require("react");
1421
+ var import_react40 = require("react");
1253
1422
  var import_react_primitive8 = require("@radix-ui/react-primitive");
1254
- var import_jsx_runtime19 = require("react/jsx-runtime");
1255
- var ComposerSend = (0, import_react34.forwardRef)(
1256
- ({ disabled, ...rest }, ref) => {
1257
- const { useComposer } = useComposerContext();
1258
- const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
1259
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1260
- import_react_primitive8.Primitive.button,
1261
- {
1262
- type: "submit",
1263
- ...rest,
1264
- ref,
1265
- disabled: disabled || !hasValue
1266
- }
1267
- );
1268
- }
1269
- );
1270
- ComposerSend.displayName = "ComposerSend";
1423
+ var import_jsx_runtime21 = require("react/jsx-runtime");
1424
+ var ComposerPrimitiveSend = (0, import_react40.forwardRef)(({ disabled, ...rest }, ref) => {
1425
+ const { useComposer } = useComposerContext();
1426
+ const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
1427
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1428
+ import_react_primitive8.Primitive.button,
1429
+ {
1430
+ type: "submit",
1431
+ ...rest,
1432
+ ref,
1433
+ disabled: disabled || !hasValue
1434
+ }
1435
+ );
1436
+ });
1437
+ ComposerPrimitiveSend.displayName = "ComposerPrimitive.Send";
1271
1438
 
1272
1439
  // src/primitives/composer/ComposerCancel.tsx
1273
- var ComposerCancel = createActionButton(
1274
- "ComposerCancel",
1440
+ var ComposerPrimitiveCancel = createActionButton(
1441
+ "ComposerPrimitive.Cancel",
1275
1442
  useComposerCancel
1276
1443
  );
1277
1444
 
1278
1445
  // src/primitives/composer/ComposerIf.tsx
1279
- var ComposerIf = ({ children, ...query }) => {
1446
+ var ComposerPrimitiveIf = ({
1447
+ children,
1448
+ ...query
1449
+ }) => {
1280
1450
  const result = useComposerIf(query);
1281
1451
  return result ? children : null;
1282
1452
  };
1453
+ ComposerPrimitiveIf.displayName = "ComposerPrimitive.If";
1283
1454
 
1284
1455
  // src/primitives/contentPart/index.ts
1285
1456
  var contentPart_exports = {};
1286
1457
  __export(contentPart_exports, {
1287
- Display: () => ContentPartDisplay,
1288
- Image: () => ContentPartImage,
1289
- InProgressIndicator: () => ContentPartInProgressIndicator,
1290
- Text: () => ContentPartText
1458
+ Display: () => ContentPartPrimitiveDisplay,
1459
+ Image: () => ContentPartPrimitiveImage,
1460
+ InProgressIndicator: () => ContentPartPrimitiveInProgressIndicator,
1461
+ Text: () => ContentPartPrimitiveText
1291
1462
  });
1292
1463
 
1293
1464
  // src/primitives/contentPart/ContentPartImage.tsx
1294
1465
  var import_react_primitive9 = require("@radix-ui/react-primitive");
1295
- var import_react35 = require("react");
1296
- var import_jsx_runtime20 = require("react/jsx-runtime");
1297
- var ContentPartImage = (0, import_react35.forwardRef)((props, forwardedRef) => {
1466
+ var import_react41 = require("react");
1467
+ var import_jsx_runtime22 = require("react/jsx-runtime");
1468
+ var ContentPartPrimitiveImage = (0, import_react41.forwardRef)((props, forwardedRef) => {
1298
1469
  const image = useContentPartImage();
1299
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_react_primitive9.Primitive.img, { src: image, ...props, ref: forwardedRef });
1470
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react_primitive9.Primitive.img, { src: image, ...props, ref: forwardedRef });
1300
1471
  });
1301
- ContentPartImage.displayName = "ContentPartImage";
1472
+ ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
1302
1473
 
1303
1474
  // src/primitives/thread/index.ts
1304
1475
  var thread_exports = {};
1305
1476
  __export(thread_exports, {
1306
- Empty: () => ThreadEmpty,
1307
- If: () => ThreadIf,
1308
- Messages: () => ThreadMessages,
1309
- Root: () => ThreadRoot,
1310
- ScrollToBottom: () => ThreadScrollToBottom,
1311
- Suggestion: () => ThreadSuggestion,
1312
- Viewport: () => ThreadViewport
1477
+ Empty: () => ThreadPrimitiveEmpty,
1478
+ If: () => ThreadPrimitiveIf,
1479
+ Messages: () => ThreadPrimitiveMessages,
1480
+ Root: () => ThreadPrimitiveRoot,
1481
+ ScrollToBottom: () => ThreadPrimitiveScrollToBottom,
1482
+ Suggestion: () => ThreadPrimitiveSuggestion,
1483
+ Viewport: () => ThreadPrimitiveViewport
1313
1484
  });
1314
1485
 
1315
1486
  // src/primitives/thread/ThreadRoot.tsx
1316
1487
  var import_react_primitive10 = require("@radix-ui/react-primitive");
1317
- var import_react36 = require("react");
1318
- var import_jsx_runtime21 = require("react/jsx-runtime");
1319
- var ThreadRoot = (0, import_react36.forwardRef)(
1320
- (props, ref) => {
1321
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react_primitive10.Primitive.div, { ...props, ref });
1322
- }
1323
- );
1324
- ThreadRoot.displayName = "ThreadRoot";
1488
+ var import_react42 = require("react");
1489
+ var import_jsx_runtime23 = require("react/jsx-runtime");
1490
+ var ThreadPrimitiveRoot = (0, import_react42.forwardRef)((props, ref) => {
1491
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_react_primitive10.Primitive.div, { ...props, ref });
1492
+ });
1493
+ ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
1325
1494
 
1326
1495
  // src/primitives/thread/ThreadEmpty.tsx
1327
- var ThreadEmpty = ({ children }) => {
1496
+ var ThreadPrimitiveEmpty = ({
1497
+ children
1498
+ }) => {
1328
1499
  const empty = useThreadEmpty();
1329
1500
  return empty ? children : null;
1330
1501
  };
1502
+ ThreadPrimitiveEmpty.displayName = "ThreadPrimitive.Empty";
1331
1503
 
1332
1504
  // src/primitives/thread/ThreadIf.tsx
1333
- var ThreadIf = ({ children, ...query }) => {
1505
+ var ThreadPrimitiveIf = ({
1506
+ children,
1507
+ ...query
1508
+ }) => {
1334
1509
  const result = useThreadIf(query);
1335
1510
  return result ? children : null;
1336
1511
  };
1512
+ ThreadPrimitiveIf.displayName = "ThreadPrimitive.If";
1337
1513
 
1338
1514
  // src/primitives/thread/ThreadViewport.tsx
1339
1515
  var import_react_compose_refs3 = require("@radix-ui/react-compose-refs");
1340
1516
  var import_react_primitive11 = require("@radix-ui/react-primitive");
1341
- var import_react41 = require("react");
1517
+ var import_react47 = require("react");
1342
1518
 
1343
1519
  // src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
1344
1520
  var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
1345
- var import_react40 = require("react");
1521
+ var import_react46 = require("react");
1346
1522
 
1347
1523
  // src/utils/hooks/useOnResizeContent.tsx
1348
1524
  var import_react_use_callback_ref2 = require("@radix-ui/react-use-callback-ref");
1349
- var import_react38 = require("react");
1525
+ var import_react44 = require("react");
1350
1526
 
1351
1527
  // src/utils/hooks/useManagedRef.ts
1352
- var import_react37 = require("react");
1528
+ var import_react43 = require("react");
1353
1529
  var useManagedRef = (callback) => {
1354
- const cleanupRef = (0, import_react37.useRef)();
1355
- const ref = (0, import_react37.useCallback)(
1530
+ const cleanupRef = (0, import_react43.useRef)();
1531
+ const ref = (0, import_react43.useCallback)(
1356
1532
  (el) => {
1357
1533
  if (cleanupRef.current) {
1358
1534
  cleanupRef.current();
@@ -1369,7 +1545,7 @@ var useManagedRef = (callback) => {
1369
1545
  // src/utils/hooks/useOnResizeContent.tsx
1370
1546
  var useOnResizeContent = (callback) => {
1371
1547
  const callbackRef = (0, import_react_use_callback_ref2.useCallbackRef)(callback);
1372
- const refCallback = (0, import_react38.useCallback)(
1548
+ const refCallback = (0, import_react44.useCallback)(
1373
1549
  (el) => {
1374
1550
  const resizeObserver = new ResizeObserver(() => {
1375
1551
  callbackRef();
@@ -1406,11 +1582,11 @@ var useOnResizeContent = (callback) => {
1406
1582
 
1407
1583
  // src/utils/hooks/useOnScrollToBottom.tsx
1408
1584
  var import_react_use_callback_ref3 = require("@radix-ui/react-use-callback-ref");
1409
- var import_react39 = require("react");
1585
+ var import_react45 = require("react");
1410
1586
  var useOnScrollToBottom = (callback) => {
1411
1587
  const callbackRef = (0, import_react_use_callback_ref3.useCallbackRef)(callback);
1412
1588
  const { useViewport } = useThreadContext();
1413
- (0, import_react39.useEffect)(() => {
1589
+ (0, import_react45.useEffect)(() => {
1414
1590
  return useViewport.getState().onScrollToBottom(() => {
1415
1591
  callbackRef();
1416
1592
  });
@@ -1421,11 +1597,11 @@ var useOnScrollToBottom = (callback) => {
1421
1597
  var useThreadViewportAutoScroll = ({
1422
1598
  autoScroll = true
1423
1599
  }) => {
1424
- const divRef = (0, import_react40.useRef)(null);
1600
+ const divRef = (0, import_react46.useRef)(null);
1425
1601
  const { useViewport } = useThreadContext();
1426
- const firstRenderRef = (0, import_react40.useRef)(true);
1427
- const lastScrollTop = (0, import_react40.useRef)(0);
1428
- const isScrollingToBottomRef = (0, import_react40.useRef)(false);
1602
+ const firstRenderRef = (0, import_react46.useRef)(true);
1603
+ const lastScrollTop = (0, import_react46.useRef)(0);
1604
+ const isScrollingToBottomRef = (0, import_react46.useRef)(false);
1429
1605
  const scrollToBottom = () => {
1430
1606
  const div = divRef.current;
1431
1607
  if (!div || !autoScroll) return;
@@ -1471,29 +1647,29 @@ var useThreadViewportAutoScroll = ({
1471
1647
  };
1472
1648
 
1473
1649
  // src/primitives/thread/ThreadViewport.tsx
1474
- var import_jsx_runtime22 = require("react/jsx-runtime");
1475
- var ThreadViewport = (0, import_react41.forwardRef)(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
1650
+ var import_jsx_runtime24 = require("react/jsx-runtime");
1651
+ var ThreadPrimitiveViewport = (0, import_react47.forwardRef)(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
1476
1652
  const autoScrollRef = useThreadViewportAutoScroll({
1477
1653
  autoScroll
1478
1654
  });
1479
1655
  const ref = (0, import_react_compose_refs3.useComposedRefs)(forwardedRef, autoScrollRef);
1480
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react_primitive11.Primitive.div, { ...rest, ref, children });
1656
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react_primitive11.Primitive.div, { ...rest, ref, children });
1481
1657
  });
1482
- ThreadViewport.displayName = "ThreadViewport";
1658
+ ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
1483
1659
 
1484
1660
  // src/primitives/thread/ThreadMessages.tsx
1485
- var import_react43 = require("react");
1661
+ var import_react49 = require("react");
1486
1662
 
1487
1663
  // src/context/providers/MessageProvider.tsx
1488
- var import_react42 = require("react");
1489
- var import_zustand10 = require("zustand");
1664
+ var import_react48 = require("react");
1665
+ var import_zustand12 = require("zustand");
1490
1666
 
1491
1667
  // src/context/stores/EditComposer.ts
1492
- var import_zustand8 = require("zustand");
1668
+ var import_zustand10 = require("zustand");
1493
1669
  var makeEditComposerStore = ({
1494
1670
  onEdit,
1495
1671
  onSend
1496
- }) => (0, import_zustand8.create)()((set, get, store) => ({
1672
+ }) => (0, import_zustand10.create)()((set, get, store) => ({
1497
1673
  ...makeBaseComposer(set, get, store),
1498
1674
  isEditing: false,
1499
1675
  edit: () => {
@@ -1513,12 +1689,9 @@ var makeEditComposerStore = ({
1513
1689
  }));
1514
1690
 
1515
1691
  // src/context/stores/MessageUtils.ts
1516
- var import_zustand9 = require("zustand");
1517
- var makeMessageUtilsStore = () => (0, import_zustand9.create)((set) => ({
1518
- inProgressIndicator: null,
1519
- setInProgressIndicator: (value) => {
1520
- set({ inProgressIndicator: value });
1521
- },
1692
+ var import_zustand11 = require("zustand");
1693
+ var makeMessageUtilsStore = () => (0, import_zustand11.create)((set) => ({
1694
+ inProgressIndicator: document.createElement("span"),
1522
1695
  isCopied: false,
1523
1696
  setIsCopied: (value) => {
1524
1697
  set({ isCopied: value });
@@ -1530,15 +1703,15 @@ var makeMessageUtilsStore = () => (0, import_zustand9.create)((set) => ({
1530
1703
  }));
1531
1704
 
1532
1705
  // src/context/providers/MessageProvider.tsx
1533
- var import_jsx_runtime23 = require("react/jsx-runtime");
1534
- var getIsLast = (thread, message) => {
1535
- return thread.messages[thread.messages.length - 1]?.id === message.id;
1706
+ var import_jsx_runtime25 = require("react/jsx-runtime");
1707
+ var getIsLast = (messages, message) => {
1708
+ return messages[messages.length - 1]?.id === message.id;
1536
1709
  };
1537
- var syncMessage = (thread, getBranches, useMessage, messageIndex) => {
1538
- const parentId = thread.messages[messageIndex - 1]?.id ?? null;
1539
- const message = thread.messages[messageIndex];
1710
+ var syncMessage = (messages, getBranches, useMessage, messageIndex) => {
1711
+ const parentId = messages[messageIndex - 1]?.id ?? null;
1712
+ const message = messages[messageIndex];
1540
1713
  if (!message) return;
1541
- const isLast = getIsLast(thread, message);
1714
+ const isLast = getIsLast(messages, message);
1542
1715
  const branches = getBranches(message.id);
1543
1716
  const currentState = useMessage.getState();
1544
1717
  if (currentState.message === message && currentState.parentId === parentId && currentState.branches === branches && currentState.isLast === isLast)
@@ -1551,9 +1724,9 @@ var syncMessage = (thread, getBranches, useMessage, messageIndex) => {
1551
1724
  });
1552
1725
  };
1553
1726
  var useMessageContext2 = (messageIndex) => {
1554
- const { useThread, useThreadActions } = useThreadContext();
1555
- const [context] = (0, import_react42.useState)(() => {
1556
- const useMessage = (0, import_zustand10.create)(() => ({}));
1727
+ const { useThreadMessages, useThreadActions } = useThreadContext();
1728
+ const [context] = (0, import_react48.useState)(() => {
1729
+ const useMessage = (0, import_zustand12.create)(() => ({}));
1557
1730
  const useMessageUtils = makeMessageUtilsStore();
1558
1731
  const useEditComposer = makeEditComposerStore({
1559
1732
  onEdit: () => {
@@ -1582,15 +1755,15 @@ var useMessageContext2 = (messageIndex) => {
1582
1755
  }
1583
1756
  });
1584
1757
  syncMessage(
1585
- useThread.getState(),
1758
+ useThreadMessages.getState(),
1586
1759
  useThreadActions.getState().getBranches,
1587
1760
  useMessage,
1588
1761
  messageIndex
1589
1762
  );
1590
1763
  return { useMessage, useMessageUtils, useEditComposer };
1591
1764
  });
1592
- (0, import_react42.useEffect)(() => {
1593
- return useThread.subscribe((thread) => {
1765
+ (0, import_react48.useEffect)(() => {
1766
+ return useThreadMessages.subscribe((thread) => {
1594
1767
  syncMessage(
1595
1768
  thread,
1596
1769
  useThreadActions.getState().getBranches,
@@ -1598,7 +1771,7 @@ var useMessageContext2 = (messageIndex) => {
1598
1771
  messageIndex
1599
1772
  );
1600
1773
  });
1601
- }, [useThread, useThreadActions, context, messageIndex]);
1774
+ }, [useThreadMessages, useThreadActions, context, messageIndex]);
1602
1775
  return context;
1603
1776
  };
1604
1777
  var MessageProvider = ({
@@ -1606,11 +1779,11 @@ var MessageProvider = ({
1606
1779
  children
1607
1780
  }) => {
1608
1781
  const context = useMessageContext2(messageIndex);
1609
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(MessageContext.Provider, { value: context, children });
1782
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(MessageContext.Provider, { value: context, children });
1610
1783
  };
1611
1784
 
1612
1785
  // src/primitives/thread/ThreadMessages.tsx
1613
- var import_jsx_runtime24 = require("react/jsx-runtime");
1786
+ var import_jsx_runtime26 = require("react/jsx-runtime");
1614
1787
  var getComponents = (components) => {
1615
1788
  return {
1616
1789
  EditComposer: components.EditComposer ?? components.UserMessage ?? components.Message,
@@ -1623,25 +1796,27 @@ var ThreadMessageImpl = ({
1623
1796
  components
1624
1797
  }) => {
1625
1798
  const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
1626
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(MessageProvider, { messageIndex, children: [
1627
- /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(MessageIf, { user: true, children: [
1628
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ComposerIf, { editing: false, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(UserMessage, {}) }),
1629
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ComposerIf, { editing: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(EditComposer, {}) })
1799
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(MessageProvider, { messageIndex, children: [
1800
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(MessagePrimitiveIf, { user: true, children: [
1801
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(UserMessage, {}) }),
1802
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(EditComposer, {}) })
1630
1803
  ] }),
1631
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(MessageIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(AssistantMessage, {}) })
1804
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(AssistantMessage, {}) })
1632
1805
  ] });
1633
1806
  };
1634
- var ThreadMessage = (0, import_react43.memo)(
1807
+ var ThreadMessage = (0, import_react49.memo)(
1635
1808
  ThreadMessageImpl,
1636
1809
  (prev, next) => prev.messageIndex === next.messageIndex && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
1637
1810
  );
1638
- var ThreadMessages = ({ components }) => {
1639
- const { useThread } = useThreadContext();
1640
- const messagesLength = useThread((t) => t.messages.length);
1811
+ var ThreadPrimitiveMessages = ({
1812
+ components
1813
+ }) => {
1814
+ const { useThreadMessages } = useThreadContext();
1815
+ const messagesLength = useThreadMessages((t) => t.length);
1641
1816
  if (messagesLength === 0) return null;
1642
1817
  return new Array(messagesLength).fill(null).map((_, idx) => {
1643
1818
  const messageIndex = idx;
1644
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1819
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
1645
1820
  ThreadMessage,
1646
1821
  {
1647
1822
  messageIndex,
@@ -1651,21 +1826,22 @@ var ThreadMessages = ({ components }) => {
1651
1826
  );
1652
1827
  });
1653
1828
  };
1829
+ ThreadPrimitiveMessages.displayName = "ThreadPrimitive.Messages";
1654
1830
 
1655
1831
  // src/primitives/thread/ThreadScrollToBottom.tsx
1656
- var ThreadScrollToBottom = createActionButton(
1657
- "ThreadScrollToBottom",
1832
+ var ThreadPrimitiveScrollToBottom = createActionButton(
1833
+ "ThreadPrimitive.ScrollToBottom",
1658
1834
  useThreadScrollToBottom
1659
1835
  );
1660
1836
 
1661
1837
  // src/primitives/thread/ThreadSuggestion.tsx
1662
- var ThreadSuggestion = createActionButton(
1663
- "ThreadSuggestion",
1838
+ var ThreadPrimitiveSuggestion = createActionButton(
1839
+ "ThreadPrimitive.Suggestion",
1664
1840
  useThreadSuggestion
1665
1841
  );
1666
1842
 
1667
1843
  // src/runtime/local/useLocalRuntime.tsx
1668
- var import_react44 = require("react");
1844
+ var import_react50 = require("react");
1669
1845
 
1670
1846
  // src/runtime/utils/idUtils.tsx
1671
1847
  var import_non_secure = require("nanoid/non-secure");
@@ -1827,13 +2003,91 @@ var MessageRepository = class {
1827
2003
  }
1828
2004
  };
1829
2005
 
2006
+ // src/runtime/core/BaseAssistantRuntime.tsx
2007
+ var BaseAssistantRuntime = class {
2008
+ constructor(_thread) {
2009
+ this._thread = _thread;
2010
+ this._thread = _thread;
2011
+ this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
2012
+ }
2013
+ _unsubscribe;
2014
+ get thread() {
2015
+ return this._thread;
2016
+ }
2017
+ set thread(thread) {
2018
+ this._unsubscribe();
2019
+ this._thread = thread;
2020
+ this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
2021
+ this.subscriptionHandler();
2022
+ }
2023
+ get messages() {
2024
+ return this.thread.messages;
2025
+ }
2026
+ get isRunning() {
2027
+ return this.thread.isRunning;
2028
+ }
2029
+ getBranches(messageId) {
2030
+ return this.thread.getBranches(messageId);
2031
+ }
2032
+ switchToBranch(branchId) {
2033
+ return this.thread.switchToBranch(branchId);
2034
+ }
2035
+ append(message) {
2036
+ return this.thread.append(message);
2037
+ }
2038
+ startRun(parentId) {
2039
+ return this.thread.startRun(parentId);
2040
+ }
2041
+ cancelRun() {
2042
+ return this.thread.cancelRun();
2043
+ }
2044
+ addToolResult(toolCallId, result) {
2045
+ return this.thread.addToolResult(toolCallId, result);
2046
+ }
2047
+ _subscriptions = /* @__PURE__ */ new Set();
2048
+ subscribe(callback) {
2049
+ this._subscriptions.add(callback);
2050
+ return () => this._subscriptions.delete(callback);
2051
+ }
2052
+ subscriptionHandler = () => {
2053
+ for (const callback of this._subscriptions) callback();
2054
+ };
2055
+ get unstable_synchronizer() {
2056
+ return this.thread.unstable_synchronizer;
2057
+ }
2058
+ };
2059
+
1830
2060
  // src/runtime/local/LocalRuntime.tsx
1831
- var LocalRuntime = class {
2061
+ var LocalRuntime = class extends BaseAssistantRuntime {
2062
+ _configProviders;
1832
2063
  constructor(adapter) {
2064
+ const configProviders = /* @__PURE__ */ new Set();
2065
+ super(new LocalThreadRuntime(configProviders, adapter));
2066
+ this._configProviders = configProviders;
2067
+ }
2068
+ set adapter(adapter) {
2069
+ this.thread.adapter = adapter;
2070
+ }
2071
+ registerModelConfigProvider(provider) {
2072
+ this._configProviders.add(provider);
2073
+ return () => this._configProviders.delete(provider);
2074
+ }
2075
+ switchToThread(threadId) {
2076
+ if (threadId) {
2077
+ throw new Error("LocalRuntime does not yet support switching threads");
2078
+ }
2079
+ return this.thread = new LocalThreadRuntime(
2080
+ this._configProviders,
2081
+ this.thread.adapter
2082
+ );
2083
+ }
2084
+ };
2085
+ var LocalThreadRuntime = class {
2086
+ constructor(_configProviders, adapter) {
2087
+ this._configProviders = _configProviders;
1833
2088
  this.adapter = adapter;
1834
2089
  }
1835
2090
  _subscriptions = /* @__PURE__ */ new Set();
1836
- _configProviders = /* @__PURE__ */ new Set();
1837
2091
  abortController = null;
1838
2092
  repository = new MessageRepository();
1839
2093
  get messages() {
@@ -1912,96 +2166,24 @@ var LocalRuntime = class {
1912
2166
  this._subscriptions.add(callback);
1913
2167
  return () => this._subscriptions.delete(callback);
1914
2168
  }
1915
- registerModelConfigProvider(provider) {
1916
- this._configProviders.add(provider);
1917
- return () => this._configProviders.delete(provider);
1918
- }
1919
2169
  addToolResult() {
1920
- throw new Error("LocalRuntime does not yet support tool results");
2170
+ throw new Error("LocalRuntime does not yet support adding tool results");
1921
2171
  }
1922
2172
  };
1923
2173
 
1924
2174
  // src/runtime/local/useLocalRuntime.tsx
1925
2175
  var useLocalRuntime = (adapter) => {
1926
- const [runtime] = (0, import_react44.useState)(() => new LocalRuntime(adapter));
1927
- (0, import_react44.useInsertionEffect)(() => {
2176
+ const [runtime] = (0, import_react50.useState)(() => new LocalRuntime(adapter));
2177
+ (0, import_react50.useInsertionEffect)(() => {
1928
2178
  runtime.adapter = adapter;
1929
2179
  });
1930
2180
  return runtime;
1931
2181
  };
1932
2182
 
1933
- // src/model-config/useAssistantTool.tsx
1934
- var import_react45 = require("react");
1935
- var useAssistantTool = (tool) => {
1936
- const { useModelConfig, useToolUIs } = useAssistantContext();
1937
- const registerModelConfigProvider = useModelConfig(
1938
- (s) => s.registerModelConfigProvider
1939
- );
1940
- const setToolUI = useToolUIs((s) => s.setToolUI);
1941
- (0, import_react45.useEffect)(() => {
1942
- const { toolName, render, ...rest } = tool;
1943
- const config = {
1944
- tools: {
1945
- [tool.toolName]: rest
1946
- }
1947
- };
1948
- const unsub1 = registerModelConfigProvider(() => config);
1949
- const unsub2 = render ? setToolUI(toolName, render) : void 0;
1950
- return () => {
1951
- unsub1();
1952
- unsub2?.();
1953
- };
1954
- }, [registerModelConfigProvider, setToolUI, tool]);
1955
- };
1956
-
1957
- // src/model-config/makeAssistantTool.tsx
1958
- var makeAssistantTool = (tool) => {
1959
- const Tool = () => {
1960
- useAssistantTool(tool);
1961
- return null;
1962
- };
1963
- return Tool;
1964
- };
1965
-
1966
- // src/model-config/useAssistantToolUI.tsx
1967
- var import_react46 = require("react");
1968
- var useAssistantToolUI = (tool) => {
1969
- const { useToolUIs } = useAssistantContext();
1970
- const setToolUI = useToolUIs((s) => s.setToolUI);
1971
- (0, import_react46.useEffect)(() => {
1972
- if (!tool) return;
1973
- const { toolName, render } = tool;
1974
- return setToolUI(toolName, render);
1975
- }, [setToolUI, tool]);
1976
- };
1977
-
1978
- // src/model-config/makeAssistantToolUI.tsx
1979
- var makeAssistantToolUI = (tool) => {
1980
- const ToolUI = () => {
1981
- useAssistantToolUI(tool);
1982
- return null;
1983
- };
1984
- return ToolUI;
1985
- };
1986
-
1987
- // src/model-config/useAssistantInstructions.tsx
1988
- var import_react47 = require("react");
1989
- var useAssistantInstructions = (instruction) => {
1990
- const { useModelConfig } = useAssistantContext();
1991
- const registerModelConfigProvider = useModelConfig(
1992
- (s) => s.registerModelConfigProvider
1993
- );
1994
- (0, import_react47.useEffect)(() => {
1995
- const config = {
1996
- system: instruction
1997
- };
1998
- return registerModelConfigProvider(() => config);
1999
- }, [registerModelConfigProvider, instruction]);
2000
- };
2001
-
2002
2183
  // src/internal.ts
2003
2184
  var internal_exports = {};
2004
2185
  __export(internal_exports, {
2186
+ BaseAssistantRuntime: () => BaseAssistantRuntime,
2005
2187
  MessageRepository: () => MessageRepository,
2006
2188
  ProxyConfigProvider: () => ProxyConfigProvider
2007
2189
  });
@@ -2021,6 +2203,7 @@ __export(internal_exports, {
2021
2203
  useActionBarCopy,
2022
2204
  useActionBarEdit,
2023
2205
  useActionBarReload,
2206
+ useAppendMessage,
2024
2207
  useAssistantContext,
2025
2208
  useAssistantInstructions,
2026
2209
  useAssistantTool,
@@ -2036,11 +2219,11 @@ __export(internal_exports, {
2036
2219
  useContentPartContext,
2037
2220
  useContentPartDisplay,
2038
2221
  useContentPartImage,
2039
- useContentPartInProgressIndicator,
2040
2222
  useContentPartText,
2041
2223
  useLocalRuntime,
2042
2224
  useMessageContext,
2043
2225
  useMessageIf,
2226
+ useSwitchToNewThread,
2044
2227
  useThreadContext,
2045
2228
  useThreadEmpty,
2046
2229
  useThreadIf,