@assistant-ui/react 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -4,179 +4,6 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
- // src/primitive-hooks/actionBar/useActionBarCopy.tsx
8
- import { useCallback } from "react";
9
-
10
- // src/context/react/MessageContext.ts
11
- import { createContext, useContext } from "react";
12
- var MessageContext = createContext(null);
13
- var useMessageContext = () => {
14
- const context = useContext(MessageContext);
15
- if (!context)
16
- throw new Error(
17
- "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
18
- );
19
- return context;
20
- };
21
-
22
- // src/utils/combined/useCombinedStore.ts
23
- import { useMemo } from "react";
24
-
25
- // src/utils/combined/createCombinedStore.ts
26
- import { useSyncExternalStore } from "react";
27
- var createCombinedStore = (stores) => {
28
- const subscribe = (callback) => {
29
- const unsubscribes = stores.map((store) => store.subscribe(callback));
30
- return () => {
31
- for (const unsub of unsubscribes) {
32
- unsub();
33
- }
34
- };
35
- };
36
- return (selector) => {
37
- const getSnapshot = () => selector(...stores.map((store) => store.getState()));
38
- return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
39
- };
40
- };
41
-
42
- // src/utils/combined/useCombinedStore.ts
43
- var useCombinedStore = (stores, selector) => {
44
- const useCombined = useMemo(() => createCombinedStore(stores), stores);
45
- return useCombined(selector);
46
- };
47
-
48
- // src/utils/getMessageText.tsx
49
- var getMessageText = (message) => {
50
- const textParts = message.content.filter(
51
- (part) => part.type === "text"
52
- );
53
- return textParts.map((part) => part.text).join("\n\n");
54
- };
55
-
56
- // src/primitive-hooks/actionBar/useActionBarCopy.tsx
57
- var useActionBarCopy = ({
58
- copiedDuration = 3e3
59
- } = {}) => {
60
- const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();
61
- const hasCopyableContent = useCombinedStore(
62
- [useMessage, useEditComposer],
63
- (m, c) => {
64
- return !c.isEditing && m.message.content.some((c2) => c2.type === "text");
65
- }
66
- );
67
- const callback = useCallback(() => {
68
- const { message } = useMessage.getState();
69
- const { setIsCopied } = useMessageUtils.getState();
70
- const { isEditing, value: composerValue } = useEditComposer.getState();
71
- const valueToCopy = isEditing ? composerValue : getMessageText(message);
72
- navigator.clipboard.writeText(valueToCopy);
73
- setIsCopied(true);
74
- setTimeout(() => setIsCopied(false), copiedDuration);
75
- }, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);
76
- if (!hasCopyableContent) return null;
77
- return callback;
78
- };
79
-
80
- // src/primitive-hooks/actionBar/useActionBarEdit.tsx
81
- import { useCallback as useCallback2 } from "react";
82
- var useActionBarEdit = () => {
83
- const { useMessage, useEditComposer } = useMessageContext();
84
- const disabled = useCombinedStore(
85
- [useMessage, useEditComposer],
86
- (m, c) => m.message.role !== "user" || c.isEditing
87
- );
88
- const callback = useCallback2(() => {
89
- const { edit } = useEditComposer.getState();
90
- edit();
91
- }, [useEditComposer]);
92
- if (disabled) return null;
93
- return callback;
94
- };
95
-
96
- // src/primitive-hooks/actionBar/useActionBarReload.tsx
97
- import { useCallback as useCallback3 } from "react";
98
-
99
- // src/context/react/ThreadContext.ts
100
- import { createContext as createContext2, useContext as useContext2 } from "react";
101
- var ThreadContext = createContext2(null);
102
- var useThreadContext = () => {
103
- const context = useContext2(ThreadContext);
104
- if (!context)
105
- throw new Error(
106
- "This component must be used within an AssistantRuntimeProvider."
107
- );
108
- return context;
109
- };
110
-
111
- // src/primitive-hooks/actionBar/useActionBarReload.tsx
112
- var useActionBarReload = () => {
113
- const { useThread, useThreadActions, useComposer, useViewport } = useThreadContext();
114
- const { useMessage } = useMessageContext();
115
- const disabled = useCombinedStore(
116
- [useThread, useMessage],
117
- (t, m) => t.isRunning || m.message.role !== "assistant"
118
- );
119
- const callback = useCallback3(() => {
120
- const { parentId } = useMessage.getState();
121
- useThreadActions.getState().startRun(parentId);
122
- useViewport.getState().scrollToBottom();
123
- useComposer.getState().focus();
124
- }, [useThreadActions, useComposer, useViewport, useMessage]);
125
- if (disabled) return null;
126
- return callback;
127
- };
128
-
129
- // src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
130
- var useBranchPickerCount = () => {
131
- const { useMessage } = useMessageContext();
132
- const branchCount = useMessage((s) => s.branches.length);
133
- return branchCount;
134
- };
135
-
136
- // src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
137
- import { useCallback as useCallback4 } from "react";
138
- var useBranchPickerNext = () => {
139
- const { useThreadActions } = useThreadContext();
140
- const { useMessage, useEditComposer } = useMessageContext();
141
- const disabled = useCombinedStore(
142
- [useMessage, useEditComposer],
143
- (m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
144
- );
145
- const callback = useCallback4(() => {
146
- const { message, branches } = useMessage.getState();
147
- useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
148
- }, [useThreadActions, useMessage]);
149
- if (disabled) return null;
150
- return callback;
151
- };
152
-
153
- // src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
154
- var useBranchPickerNumber = () => {
155
- const { useMessage } = useMessageContext();
156
- const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
157
- return branchIdx + 1;
158
- };
159
-
160
- // src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
161
- import { useCallback as useCallback5 } from "react";
162
- var useBranchPickerPrevious = () => {
163
- const { useThreadActions } = useThreadContext();
164
- const { useMessage, useEditComposer } = useMessageContext();
165
- const disabled = useCombinedStore(
166
- [useMessage, useEditComposer],
167
- (m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
168
- );
169
- const callback = useCallback5(() => {
170
- const { message, branches } = useMessage.getState();
171
- useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
172
- }, [useThreadActions, useMessage]);
173
- if (disabled) return null;
174
- return callback;
175
- };
176
-
177
- // src/primitive-hooks/composer/useComposerCancel.tsx
178
- import { useCallback as useCallback6 } from "react";
179
-
180
7
  // src/context/providers/AssistantRuntimeProvider.tsx
181
8
  import { memo } from "react";
182
9
 
@@ -184,12 +11,12 @@ import { memo } from "react";
184
11
  import { useEffect as useEffect2, useInsertionEffect as useInsertionEffect2, useRef as useRef2, useState as useState2 } from "react";
185
12
 
186
13
  // src/context/react/AssistantContext.ts
187
- import { createContext as createContext3, useContext as useContext3 } from "react";
188
- var AssistantContext = createContext3(
14
+ import { createContext, useContext } from "react";
15
+ var AssistantContext = createContext(
189
16
  null
190
17
  );
191
18
  var useAssistantContext = () => {
192
- const context = useContext3(AssistantContext);
19
+ const context = useContext(AssistantContext);
193
20
  if (!context)
194
21
  throw new Error(
195
22
  "This component must be used within an AssistantRuntimeProvider."
@@ -288,7 +115,26 @@ var makeAssistantToolUIsStore = () => create2((set) => {
288
115
  });
289
116
 
290
117
  // src/context/providers/ThreadProvider.tsx
291
- import { useEffect, useInsertionEffect, useRef, useState } from "react";
118
+ import {
119
+ useCallback,
120
+ useEffect,
121
+ useInsertionEffect,
122
+ useRef,
123
+ useState,
124
+ useSyncExternalStore
125
+ } from "react";
126
+
127
+ // src/context/react/ThreadContext.ts
128
+ import { createContext as createContext2, useContext as useContext2 } from "react";
129
+ var ThreadContext = createContext2(null);
130
+ var useThreadContext = () => {
131
+ const context = useContext2(ThreadContext);
132
+ if (!context)
133
+ throw new Error(
134
+ "This component must be used within an AssistantRuntimeProvider."
135
+ );
136
+ return context;
137
+ };
292
138
 
293
139
  // src/context/stores/Composer.ts
294
140
  import { create as create3 } from "zustand";
@@ -417,13 +263,29 @@ var ThreadProvider = ({
417
263
  onRuntimeUpdate();
418
264
  return runtime.subscribe(onRuntimeUpdate);
419
265
  }, [context, runtime]);
420
- const RuntimeSynchronizer = runtime.unstable_synchronizer;
266
+ const subscribe = useCallback(
267
+ (c) => runtime.subscribe(c),
268
+ [runtime]
269
+ );
270
+ const RuntimeSynchronizer = useSyncExternalStore(
271
+ subscribe,
272
+ () => runtime.unstable_synchronizer,
273
+ () => void 0
274
+ );
421
275
  return /* @__PURE__ */ jsxs(ThreadContext.Provider, { value: context, children: [
422
276
  RuntimeSynchronizer && /* @__PURE__ */ jsx(RuntimeSynchronizer, {}),
423
277
  children
424
278
  ] });
425
279
  };
426
280
 
281
+ // src/context/stores/AssistantActions.tsx
282
+ import { create as create7 } from "zustand";
283
+ var makeAssistantActionsStore = (runtimeRef) => create7(
284
+ () => Object.freeze({
285
+ switchToThread: () => runtimeRef.current.switchToThread(null)
286
+ })
287
+ );
288
+
427
289
  // src/context/providers/AssistantProvider.tsx
428
290
  import { jsx as jsx2 } from "react/jsx-runtime";
429
291
  var AssistantProvider = ({ children, runtime }) => {
@@ -434,7 +296,8 @@ var AssistantProvider = ({ children, runtime }) => {
434
296
  const [context] = useState2(() => {
435
297
  const useModelConfig = makeAssistantModelConfigStore();
436
298
  const useToolUIs = makeAssistantToolUIsStore();
437
- return { useModelConfig, useToolUIs };
299
+ const useAssistantActions = makeAssistantActionsStore(runtimeRef);
300
+ return { useModelConfig, useToolUIs, useAssistantActions };
438
301
  });
439
302
  const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
440
303
  useEffect2(() => {
@@ -448,41 +311,311 @@ import { jsx as jsx3 } from "react/jsx-runtime";
448
311
  var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
449
312
  return /* @__PURE__ */ jsx3(AssistantProvider, { runtime, children });
450
313
  };
451
- var AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
314
+ var AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
315
+
316
+ // src/context/react/ComposerContext.ts
317
+ import { useContext as useContext4, useMemo } from "react";
318
+
319
+ // src/context/react/MessageContext.ts
320
+ import { createContext as createContext3, useContext as useContext3 } from "react";
321
+ var MessageContext = createContext3(null);
322
+ var useMessageContext = () => {
323
+ const context = useContext3(MessageContext);
324
+ if (!context)
325
+ throw new Error(
326
+ "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
327
+ );
328
+ return context;
329
+ };
330
+
331
+ // src/context/react/ComposerContext.ts
332
+ var useComposerContext = () => {
333
+ const { useComposer } = useThreadContext();
334
+ const { useEditComposer } = useContext4(MessageContext) ?? {};
335
+ return useMemo(
336
+ () => ({
337
+ useComposer: useEditComposer ?? useComposer,
338
+ type: useEditComposer ? "edit" : "new"
339
+ }),
340
+ [useEditComposer, useComposer]
341
+ );
342
+ };
343
+
344
+ // src/context/react/ContentPartContext.ts
345
+ import { createContext as createContext4, useContext as useContext5 } from "react";
346
+ var ContentPartContext = createContext4(
347
+ null
348
+ );
349
+ var useContentPartContext = () => {
350
+ const context = useContext5(ContentPartContext);
351
+ if (!context)
352
+ throw new Error(
353
+ "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
354
+ );
355
+ return context;
356
+ };
357
+
358
+ // src/hooks/useAppendMessage.tsx
359
+ import { useCallback as useCallback2 } from "react";
360
+ var toAppendMessage = (useThread, message) => {
361
+ if (typeof message === "string") {
362
+ return {
363
+ parentId: useThread.getState().messages.at(-1)?.id ?? null,
364
+ role: "user",
365
+ content: [{ type: "text", text: message }]
366
+ };
367
+ }
368
+ return {
369
+ parentId: message.parentId ?? useThread.getState().messages.at(-1)?.id ?? null,
370
+ role: message.role ?? "user",
371
+ content: message.content
372
+ };
373
+ };
374
+ var useAppendMessage = () => {
375
+ const { useThread, useThreadActions, useViewport, useComposer } = useThreadContext();
376
+ const append = useCallback2(
377
+ (message) => {
378
+ const appendMessage = toAppendMessage(useThread, message);
379
+ useThreadActions.getState().append(appendMessage);
380
+ useViewport.getState().scrollToBottom();
381
+ useComposer.getState().focus();
382
+ },
383
+ [useThread, useThreadActions, useViewport, useComposer]
384
+ );
385
+ return append;
386
+ };
387
+
388
+ // src/hooks/useSwitchToNewThread.tsx
389
+ import { useCallback as useCallback3 } from "react";
390
+ var useSwitchToNewThread = () => {
391
+ const { useAssistantActions } = useAssistantContext();
392
+ const { useComposer } = useThreadContext();
393
+ const switchToNewThread = useCallback3(() => {
394
+ useAssistantActions.getState().switchToThread(null);
395
+ useComposer.getState().focus();
396
+ }, [useAssistantActions, useComposer]);
397
+ return switchToNewThread;
398
+ };
399
+
400
+ // src/model-config/useAssistantTool.tsx
401
+ import { useEffect as useEffect3 } from "react";
402
+ var useAssistantTool = (tool) => {
403
+ const { useModelConfig, useToolUIs } = useAssistantContext();
404
+ const registerModelConfigProvider = useModelConfig(
405
+ (s) => s.registerModelConfigProvider
406
+ );
407
+ const setToolUI = useToolUIs((s) => s.setToolUI);
408
+ useEffect3(() => {
409
+ const { toolName, render, ...rest } = tool;
410
+ const config = {
411
+ tools: {
412
+ [tool.toolName]: rest
413
+ }
414
+ };
415
+ const unsub1 = registerModelConfigProvider(() => config);
416
+ const unsub2 = render ? setToolUI(toolName, render) : void 0;
417
+ return () => {
418
+ unsub1();
419
+ unsub2?.();
420
+ };
421
+ }, [registerModelConfigProvider, setToolUI, tool]);
422
+ };
423
+
424
+ // src/model-config/makeAssistantTool.tsx
425
+ var makeAssistantTool = (tool) => {
426
+ const Tool = () => {
427
+ useAssistantTool(tool);
428
+ return null;
429
+ };
430
+ return Tool;
431
+ };
432
+
433
+ // src/model-config/useAssistantToolUI.tsx
434
+ import { useEffect as useEffect4 } from "react";
435
+ var useAssistantToolUI = (tool) => {
436
+ const { useToolUIs } = useAssistantContext();
437
+ const setToolUI = useToolUIs((s) => s.setToolUI);
438
+ useEffect4(() => {
439
+ if (!tool) return;
440
+ const { toolName, render } = tool;
441
+ return setToolUI(toolName, render);
442
+ }, [setToolUI, tool]);
443
+ };
444
+
445
+ // src/model-config/makeAssistantToolUI.tsx
446
+ var makeAssistantToolUI = (tool) => {
447
+ const ToolUI = () => {
448
+ useAssistantToolUI(tool);
449
+ return null;
450
+ };
451
+ return ToolUI;
452
+ };
453
+
454
+ // src/model-config/useAssistantInstructions.tsx
455
+ import { useEffect as useEffect5 } from "react";
456
+ var useAssistantInstructions = (instruction) => {
457
+ const { useModelConfig } = useAssistantContext();
458
+ const registerModelConfigProvider = useModelConfig(
459
+ (s) => s.registerModelConfigProvider
460
+ );
461
+ useEffect5(() => {
462
+ const config = {
463
+ system: instruction
464
+ };
465
+ return registerModelConfigProvider(() => config);
466
+ }, [registerModelConfigProvider, instruction]);
467
+ };
468
+
469
+ // src/primitive-hooks/actionBar/useActionBarCopy.tsx
470
+ import { useCallback as useCallback4 } from "react";
471
+
472
+ // src/utils/combined/useCombinedStore.ts
473
+ import { useMemo as useMemo2 } from "react";
474
+
475
+ // src/utils/combined/createCombinedStore.ts
476
+ import { useSyncExternalStore as useSyncExternalStore2 } from "react";
477
+ var createCombinedStore = (stores) => {
478
+ const subscribe = (callback) => {
479
+ const unsubscribes = stores.map((store) => store.subscribe(callback));
480
+ return () => {
481
+ for (const unsub of unsubscribes) {
482
+ unsub();
483
+ }
484
+ };
485
+ };
486
+ return (selector) => {
487
+ const getSnapshot = () => selector(...stores.map((store) => store.getState()));
488
+ return useSyncExternalStore2(subscribe, getSnapshot, getSnapshot);
489
+ };
490
+ };
491
+
492
+ // src/utils/combined/useCombinedStore.ts
493
+ var useCombinedStore = (stores, selector) => {
494
+ const useCombined = useMemo2(() => createCombinedStore(stores), stores);
495
+ return useCombined(selector);
496
+ };
497
+
498
+ // src/utils/getMessageText.tsx
499
+ var getMessageText = (message) => {
500
+ const textParts = message.content.filter(
501
+ (part) => part.type === "text"
502
+ );
503
+ return textParts.map((part) => part.text).join("\n\n");
504
+ };
505
+
506
+ // src/primitive-hooks/actionBar/useActionBarCopy.tsx
507
+ var useActionBarCopy = ({
508
+ copiedDuration = 3e3
509
+ } = {}) => {
510
+ const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();
511
+ const hasCopyableContent = useCombinedStore(
512
+ [useMessage, useEditComposer],
513
+ (m, c) => {
514
+ return !c.isEditing && m.message.content.some((c2) => c2.type === "text");
515
+ }
516
+ );
517
+ const callback = useCallback4(() => {
518
+ const { message } = useMessage.getState();
519
+ const { setIsCopied } = useMessageUtils.getState();
520
+ const { isEditing, value: composerValue } = useEditComposer.getState();
521
+ const valueToCopy = isEditing ? composerValue : getMessageText(message);
522
+ navigator.clipboard.writeText(valueToCopy);
523
+ setIsCopied(true);
524
+ setTimeout(() => setIsCopied(false), copiedDuration);
525
+ }, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);
526
+ if (!hasCopyableContent) return null;
527
+ return callback;
528
+ };
529
+
530
+ // src/primitive-hooks/actionBar/useActionBarEdit.tsx
531
+ import { useCallback as useCallback5 } from "react";
532
+ var useActionBarEdit = () => {
533
+ const { useMessage, useEditComposer } = useMessageContext();
534
+ const disabled = useCombinedStore(
535
+ [useMessage, useEditComposer],
536
+ (m, c) => m.message.role !== "user" || c.isEditing
537
+ );
538
+ const callback = useCallback5(() => {
539
+ const { edit } = useEditComposer.getState();
540
+ edit();
541
+ }, [useEditComposer]);
542
+ if (disabled) return null;
543
+ return callback;
544
+ };
545
+
546
+ // src/primitive-hooks/actionBar/useActionBarReload.tsx
547
+ import { useCallback as useCallback6 } from "react";
548
+ var useActionBarReload = () => {
549
+ const { useThread, useThreadActions, useComposer, useViewport } = useThreadContext();
550
+ const { useMessage } = useMessageContext();
551
+ const disabled = useCombinedStore(
552
+ [useThread, useMessage],
553
+ (t, m) => t.isRunning || m.message.role !== "assistant"
554
+ );
555
+ const callback = useCallback6(() => {
556
+ const { parentId } = useMessage.getState();
557
+ useThreadActions.getState().startRun(parentId);
558
+ useViewport.getState().scrollToBottom();
559
+ useComposer.getState().focus();
560
+ }, [useThreadActions, useComposer, useViewport, useMessage]);
561
+ if (disabled) return null;
562
+ return callback;
563
+ };
564
+
565
+ // src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
566
+ var useBranchPickerCount = () => {
567
+ const { useMessage } = useMessageContext();
568
+ const branchCount = useMessage((s) => s.branches.length);
569
+ return branchCount;
570
+ };
571
+
572
+ // src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
573
+ import { useCallback as useCallback7 } from "react";
574
+ var useBranchPickerNext = () => {
575
+ const { useThreadActions } = useThreadContext();
576
+ const { useMessage, useEditComposer } = useMessageContext();
577
+ const disabled = useCombinedStore(
578
+ [useMessage, useEditComposer],
579
+ (m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
580
+ );
581
+ const callback = useCallback7(() => {
582
+ const { message, branches } = useMessage.getState();
583
+ useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
584
+ }, [useThreadActions, useMessage]);
585
+ if (disabled) return null;
586
+ return callback;
587
+ };
452
588
 
453
- // src/context/react/ComposerContext.ts
454
- import { useContext as useContext4, useMemo as useMemo2 } from "react";
455
- var useComposerContext = () => {
456
- const { useComposer } = useThreadContext();
457
- const { useEditComposer } = useContext4(MessageContext) ?? {};
458
- return useMemo2(
459
- () => ({
460
- useComposer: useEditComposer ?? useComposer,
461
- type: useEditComposer ? "edit" : "new"
462
- }),
463
- [useEditComposer, useComposer]
464
- );
589
+ // src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
590
+ var useBranchPickerNumber = () => {
591
+ const { useMessage } = useMessageContext();
592
+ const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
593
+ return branchIdx + 1;
465
594
  };
466
595
 
467
- // src/context/react/ContentPartContext.ts
468
- import { createContext as createContext4, useContext as useContext5 } from "react";
469
- var ContentPartContext = createContext4(
470
- null
471
- );
472
- var useContentPartContext = () => {
473
- const context = useContext5(ContentPartContext);
474
- if (!context)
475
- throw new Error(
476
- "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
477
- );
478
- return context;
596
+ // src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
597
+ import { useCallback as useCallback8 } from "react";
598
+ var useBranchPickerPrevious = () => {
599
+ const { useThreadActions } = useThreadContext();
600
+ const { useMessage, useEditComposer } = useMessageContext();
601
+ const disabled = useCombinedStore(
602
+ [useMessage, useEditComposer],
603
+ (m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
604
+ );
605
+ const callback = useCallback8(() => {
606
+ const { message, branches } = useMessage.getState();
607
+ useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
608
+ }, [useThreadActions, useMessage]);
609
+ if (disabled) return null;
610
+ return callback;
479
611
  };
480
612
 
481
613
  // src/primitive-hooks/composer/useComposerCancel.tsx
614
+ import { useCallback as useCallback9 } from "react";
482
615
  var useComposerCancel = () => {
483
616
  const { useComposer } = useComposerContext();
484
617
  const disabled = useComposer((c) => !c.isEditing);
485
- const callback = useCallback6(() => {
618
+ const callback = useCallback9(() => {
486
619
  const { cancel } = useComposer.getState();
487
620
  cancel();
488
621
  }, [useComposer]);
@@ -501,12 +634,12 @@ var useComposerIf = (props) => {
501
634
  };
502
635
 
503
636
  // src/primitive-hooks/composer/useComposerSend.tsx
504
- import { useCallback as useCallback7 } from "react";
637
+ import { useCallback as useCallback10 } from "react";
505
638
  var useComposerSend = () => {
506
639
  const { useViewport, useComposer: useNewComposer } = useThreadContext();
507
640
  const { useComposer } = useComposerContext();
508
641
  const disabled = useComposer((c) => !c.isEditing || c.value.length === 0);
509
- const callback = useCallback7(() => {
642
+ const callback = useCallback10(() => {
510
643
  const composerState = useComposer.getState();
511
644
  if (!composerState.isEditing) return;
512
645
  composerState.send();
@@ -602,11 +735,11 @@ var useThreadEmpty = () => {
602
735
  };
603
736
 
604
737
  // src/primitive-hooks/thread/useThreadScrollToBottom.tsx
605
- import { useCallback as useCallback8 } from "react";
738
+ import { useCallback as useCallback11 } from "react";
606
739
  var useThreadScrollToBottom = () => {
607
740
  const { useComposer, useViewport } = useThreadContext();
608
741
  const isAtBottom = useViewport((s) => s.isAtBottom);
609
- const handleScrollToBottom = useCallback8(() => {
742
+ const handleScrollToBottom = useCallback11(() => {
610
743
  useViewport.getState().scrollToBottom();
611
744
  useComposer.getState().focus();
612
745
  }, [useViewport, useComposer]);
@@ -615,14 +748,14 @@ var useThreadScrollToBottom = () => {
615
748
  };
616
749
 
617
750
  // src/primitive-hooks/thread/useThreadSuggestion.tsx
618
- import { useCallback as useCallback9 } from "react";
751
+ import { useCallback as useCallback12 } from "react";
619
752
  var useThreadSuggestion = ({
620
753
  prompt,
621
754
  autoSend
622
755
  }) => {
623
756
  const { useThread, useComposer } = useThreadContext();
624
757
  const disabled = useThread((t) => t.isRunning);
625
- const callback = useCallback9(() => {
758
+ const callback = useCallback12(() => {
626
759
  const thread = useThread.getState();
627
760
  const composer = useComposer.getState();
628
761
  composer.setValue(prompt);
@@ -637,16 +770,17 @@ var useThreadSuggestion = ({
637
770
  // src/primitives/actionBar/index.ts
638
771
  var actionBar_exports = {};
639
772
  __export(actionBar_exports, {
640
- Copy: () => ActionBarCopy,
641
- Edit: () => ActionBarEdit,
642
- Reload: () => ActionBarReload,
643
- Root: () => ActionBarRoot
773
+ Copy: () => ActionBarPrimitiveCopy,
774
+ Edit: () => ActionBarPrimitiveEdit,
775
+ Reload: () => ActionBarPrimitiveReload,
776
+ Root: () => ActionBarPrimitiveRoot
644
777
  });
645
778
 
646
779
  // src/primitives/actionBar/ActionBarRoot.tsx
647
780
  import { Primitive } from "@radix-ui/react-primitive";
648
781
  import { forwardRef } from "react";
649
- import { jsx as jsx4 } from "react/jsx-runtime";
782
+
783
+ // src/primitives/actionBar/useActionBarFloatStatus.tsx
650
784
  var useActionBarFloatStatus = ({
651
785
  hideWhenRunning,
652
786
  autohide,
@@ -667,7 +801,10 @@ var useActionBarFloatStatus = ({
667
801
  }
668
802
  );
669
803
  };
670
- var ActionBarRoot = forwardRef(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
804
+
805
+ // src/primitives/actionBar/ActionBarRoot.tsx
806
+ import { jsx as jsx4 } from "react/jsx-runtime";
807
+ var ActionBarPrimitiveRoot = forwardRef(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
671
808
  const hideAndfloatStatus = useActionBarFloatStatus({
672
809
  hideWhenRunning,
673
810
  autohide,
@@ -683,7 +820,7 @@ var ActionBarRoot = forwardRef(({ hideWhenRunning, autohide, autohideFloat, ...r
683
820
  }
684
821
  );
685
822
  });
686
- ActionBarRoot.displayName = "ActionBarRoot";
823
+ ActionBarPrimitiveRoot.displayName = "ActionBarPrimitive.Root";
687
824
 
688
825
  // src/utils/createActionButton.tsx
689
826
  import { composeEventHandlers } from "@radix-ui/primitive";
@@ -711,52 +848,55 @@ var createActionButton = (displayName, useActionButton) => {
711
848
  };
712
849
 
713
850
  // src/primitives/actionBar/ActionBarCopy.tsx
714
- var ActionBarCopy = createActionButton(
715
- "ActionBarCopy",
851
+ var ActionBarPrimitiveCopy = createActionButton(
852
+ "ActionBarPrimitive.Copy",
716
853
  useActionBarCopy
717
854
  );
718
855
 
719
856
  // src/primitives/actionBar/ActionBarReload.tsx
720
- var ActionBarReload = createActionButton(
721
- "ActionBarReload",
857
+ var ActionBarPrimitiveReload = createActionButton(
858
+ "ActionBarPrimitive.Reload",
722
859
  useActionBarReload
723
860
  );
724
861
 
725
862
  // src/primitives/actionBar/ActionBarEdit.tsx
726
- var ActionBarEdit = createActionButton(
727
- "ActionBarEdit",
863
+ var ActionBarPrimitiveEdit = createActionButton(
864
+ "ActionBarPrimitive.Edit",
728
865
  useActionBarEdit
729
866
  );
730
867
 
731
868
  // src/primitives/assistantModal/index.ts
732
869
  var assistantModal_exports = {};
733
870
  __export(assistantModal_exports, {
734
- Content: () => AssistantModalContent,
735
- Root: () => AssistantModalRoot,
736
- Trigger: () => AssistantModalTrigger
871
+ Content: () => AssistantModalPrimitiveContent,
872
+ Root: () => AssistantModalPrimitiveRoot,
873
+ Trigger: () => AssistantModalPrimitiveTrigger
737
874
  });
738
875
 
739
876
  // src/primitives/assistantModal/AssistantModalRoot.tsx
740
877
  import { useState as useState3 } from "react";
741
- import * as PopoverPrimitive from "@radix-ui/react-popover";
878
+ import * as PopoverPrimitive2 from "@radix-ui/react-popover";
742
879
  import { composeEventHandlers as composeEventHandlers2 } from "@radix-ui/primitive";
743
880
 
744
881
  // src/utils/hooks/useOnComposerFocus.tsx
745
882
  import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
746
- import { useEffect as useEffect3 } from "react";
883
+ import { useEffect as useEffect6 } from "react";
747
884
  var useOnComposerFocus = (callback) => {
748
885
  const callbackRef = useCallbackRef(callback);
749
886
  const { useComposer } = useThreadContext();
750
- useEffect3(() => {
887
+ useEffect6(() => {
751
888
  return useComposer.getState().onFocus(() => {
752
889
  callbackRef();
753
890
  });
754
891
  }, [useComposer, callbackRef]);
755
892
  };
756
893
 
894
+ // src/primitives/assistantModal/scope.tsx
895
+ import * as PopoverPrimitive from "@radix-ui/react-popover";
896
+ var usePopoverScope = PopoverPrimitive.createPopoverScope();
897
+
757
898
  // src/primitives/assistantModal/AssistantModalRoot.tsx
758
899
  import { jsx as jsx6 } from "react/jsx-runtime";
759
- var usePopoverScope = PopoverPrimitive.createPopoverScope();
760
900
  var useAssistantModalOpenState = (defaultOpen = false) => {
761
901
  const state = useState3(defaultOpen);
762
902
  const [, setOpen] = state;
@@ -765,7 +905,7 @@ var useAssistantModalOpenState = (defaultOpen = false) => {
765
905
  });
766
906
  return state;
767
907
  };
768
- var AssistantModalRoot = ({
908
+ var AssistantModalPrimitiveRoot = ({
769
909
  __scopeAssistantModal,
770
910
  defaultOpen,
771
911
  open,
@@ -775,7 +915,7 @@ var AssistantModalRoot = ({
775
915
  const scope = usePopoverScope(__scopeAssistantModal);
776
916
  const [modalOpen, setOpen] = useAssistantModalOpenState(defaultOpen);
777
917
  return /* @__PURE__ */ jsx6(
778
- PopoverPrimitive.Root,
918
+ PopoverPrimitive2.Root,
779
919
  {
780
920
  ...scope,
781
921
  open: open === void 0 ? modalOpen : open,
@@ -784,26 +924,29 @@ var AssistantModalRoot = ({
784
924
  }
785
925
  );
786
926
  };
787
- AssistantModalRoot.displayName = "AssistantModalRoot";
927
+ AssistantModalPrimitiveRoot.displayName = "AssistantModalPrimitive.Root";
788
928
 
789
929
  // src/primitives/assistantModal/AssistantModalTrigger.tsx
790
930
  import { forwardRef as forwardRef3 } from "react";
791
- import * as PopoverPrimitive2 from "@radix-ui/react-popover";
931
+ import * as PopoverPrimitive3 from "@radix-ui/react-popover";
792
932
  import { jsx as jsx7 } from "react/jsx-runtime";
793
- var AssistantModalTrigger = forwardRef3(
794
- ({ __scopeAssistantModal, ...rest }, ref) => {
933
+ var AssistantModalPrimitiveTrigger = forwardRef3(
934
+ ({
935
+ __scopeAssistantModal,
936
+ ...rest
937
+ }, ref) => {
795
938
  const scope = usePopoverScope(__scopeAssistantModal);
796
- return /* @__PURE__ */ jsx7(PopoverPrimitive2.Trigger, { ...scope, ...rest, ref });
939
+ return /* @__PURE__ */ jsx7(PopoverPrimitive3.Trigger, { ...scope, ...rest, ref });
797
940
  }
798
941
  );
799
- AssistantModalTrigger.displayName = "AssistantModalTrigger";
942
+ AssistantModalPrimitiveTrigger.displayName = "AssistantModalPrimitive.Trigger";
800
943
 
801
944
  // src/primitives/assistantModal/AssistantModalContent.tsx
802
945
  import { forwardRef as forwardRef4 } from "react";
803
- import * as PopoverPrimitive3 from "@radix-ui/react-popover";
946
+ import * as PopoverPrimitive4 from "@radix-ui/react-popover";
804
947
  import { composeEventHandlers as composeEventHandlers3 } from "@radix-ui/primitive";
805
948
  import { jsx as jsx8 } from "react/jsx-runtime";
806
- var AssistantModalContent = forwardRef4(
949
+ var AssistantModalPrimitiveContent = forwardRef4(
807
950
  ({
808
951
  __scopeAssistantModal,
809
952
  side,
@@ -813,8 +956,8 @@ var AssistantModalContent = forwardRef4(
813
956
  ...props
814
957
  }, forwardedRef) => {
815
958
  const scope = usePopoverScope(__scopeAssistantModal);
816
- return /* @__PURE__ */ jsx8(PopoverPrimitive3.Portal, { ...scope, children: /* @__PURE__ */ jsx8(
817
- PopoverPrimitive3.Content,
959
+ return /* @__PURE__ */ jsx8(PopoverPrimitive4.Portal, { ...scope, children: /* @__PURE__ */ jsx8(
960
+ PopoverPrimitive4.Content,
818
961
  {
819
962
  ...scope,
820
963
  ...props,
@@ -829,43 +972,45 @@ var AssistantModalContent = forwardRef4(
829
972
  ) });
830
973
  }
831
974
  );
832
- AssistantModalContent.displayName = "AssistantModalContent";
975
+ AssistantModalPrimitiveContent.displayName = "AssistantModalPrimitive.Content";
833
976
 
834
977
  // src/primitives/branchPicker/index.ts
835
978
  var branchPicker_exports = {};
836
979
  __export(branchPicker_exports, {
837
- Count: () => BranchPickerCount,
838
- Next: () => BranchPickerNext,
839
- Number: () => BranchPickerNumber,
980
+ Count: () => BranchPickerPrimitiveCount,
981
+ Next: () => BranchPickerPrimitiveNext,
982
+ Number: () => BranchPickerPrimitiveNumber,
840
983
  Previous: () => BranchPickerPrevious,
841
- Root: () => BranchPickerRoot
984
+ Root: () => BranchPickerPrimitiveRoot
842
985
  });
843
986
 
844
987
  // src/primitives/branchPicker/BranchPickerNext.tsx
845
- var BranchPickerNext = createActionButton(
846
- "BranchPickerNext",
988
+ var BranchPickerPrimitiveNext = createActionButton(
989
+ "BranchPickerPrimitive.Next",
847
990
  useBranchPickerNext
848
991
  );
849
992
 
850
993
  // src/primitives/branchPicker/BranchPickerPrevious.tsx
851
994
  var BranchPickerPrevious = createActionButton(
852
- "BranchPickerPrevious",
995
+ "BranchPickerPrimitive.Previous",
853
996
  useBranchPickerPrevious
854
997
  );
855
998
 
856
999
  // src/primitives/branchPicker/BranchPickerCount.tsx
857
1000
  import { Fragment, jsx as jsx9 } from "react/jsx-runtime";
858
- var BranchPickerCount = () => {
1001
+ var BranchPickerPrimitiveCount = () => {
859
1002
  const branchCount = useBranchPickerCount();
860
1003
  return /* @__PURE__ */ jsx9(Fragment, { children: branchCount });
861
1004
  };
1005
+ BranchPickerPrimitiveCount.displayName = "BranchPickerPrimitive.Count";
862
1006
 
863
1007
  // src/primitives/branchPicker/BranchPickerNumber.tsx
864
1008
  import { Fragment as Fragment2, jsx as jsx10 } from "react/jsx-runtime";
865
- var BranchPickerNumber = () => {
1009
+ var BranchPickerPrimitiveNumber = () => {
866
1010
  const branchNumber = useBranchPickerNumber();
867
1011
  return /* @__PURE__ */ jsx10(Fragment2, { children: branchNumber });
868
1012
  };
1013
+ BranchPickerPrimitiveNumber.displayName = "BranchPickerPrimitive.Number";
869
1014
 
870
1015
  // src/primitives/branchPicker/BranchPickerRoot.tsx
871
1016
  import { Primitive as Primitive6 } from "@radix-ui/react-primitive";
@@ -874,10 +1019,10 @@ import { forwardRef as forwardRef8 } from "react";
874
1019
  // src/primitives/message/index.ts
875
1020
  var message_exports = {};
876
1021
  __export(message_exports, {
877
- Content: () => MessageContent,
878
- If: () => MessageIf,
879
- InProgress: () => MessageInProgress,
880
- Root: () => MessageRoot
1022
+ Content: () => MessagePrimitiveContent,
1023
+ If: () => MessagePrimitiveIf,
1024
+ InProgress: () => MessagePrimitiveInProgress,
1025
+ Root: () => MessagePrimitiveRoot
881
1026
  });
882
1027
 
883
1028
  // src/primitives/message/MessageRoot.tsx
@@ -885,41 +1030,43 @@ import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primiti
885
1030
  import { Primitive as Primitive3 } from "@radix-ui/react-primitive";
886
1031
  import { forwardRef as forwardRef5 } from "react";
887
1032
  import { jsx as jsx11 } from "react/jsx-runtime";
888
- var MessageRoot = forwardRef5(
889
- ({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
890
- const { useMessageUtils } = useMessageContext();
891
- const setIsHovering = useMessageUtils((s) => s.setIsHovering);
892
- const handleMouseEnter = () => {
893
- setIsHovering(true);
894
- };
895
- const handleMouseLeave = () => {
896
- setIsHovering(false);
897
- };
898
- return /* @__PURE__ */ jsx11(
899
- Primitive3.div,
900
- {
901
- ...rest,
902
- ref,
903
- onMouseEnter: composeEventHandlers4(onMouseEnter, handleMouseEnter),
904
- onMouseLeave: composeEventHandlers4(onMouseLeave, handleMouseLeave)
905
- }
906
- );
907
- }
908
- );
909
- MessageRoot.displayName = "MessageRoot";
1033
+ var MessagePrimitiveRoot = forwardRef5(({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
1034
+ const { useMessageUtils } = useMessageContext();
1035
+ const setIsHovering = useMessageUtils((s) => s.setIsHovering);
1036
+ const handleMouseEnter = () => {
1037
+ setIsHovering(true);
1038
+ };
1039
+ const handleMouseLeave = () => {
1040
+ setIsHovering(false);
1041
+ };
1042
+ return /* @__PURE__ */ jsx11(
1043
+ Primitive3.div,
1044
+ {
1045
+ ...rest,
1046
+ ref,
1047
+ onMouseEnter: composeEventHandlers4(onMouseEnter, handleMouseEnter),
1048
+ onMouseLeave: composeEventHandlers4(onMouseLeave, handleMouseLeave)
1049
+ }
1050
+ );
1051
+ });
1052
+ MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
910
1053
 
911
1054
  // src/primitives/message/MessageIf.tsx
912
- var MessageIf = ({ children, ...query }) => {
1055
+ var MessagePrimitiveIf = ({
1056
+ children,
1057
+ ...query
1058
+ }) => {
913
1059
  const result = useMessageIf(query);
914
1060
  return result ? children : null;
915
1061
  };
1062
+ MessagePrimitiveIf.displayName = "MessagePrimitive.If";
916
1063
 
917
1064
  // src/primitives/message/MessageContent.tsx
918
1065
  import { memo as memo2 } from "react";
919
1066
 
920
1067
  // src/context/providers/ContentPartProvider.tsx
921
- import { useEffect as useEffect4, useState as useState4 } from "react";
922
- import { create as create7 } from "zustand";
1068
+ import { useEffect as useEffect7, useState as useState4 } from "react";
1069
+ import { create as create8 } from "zustand";
923
1070
  import { jsx as jsx12 } from "react/jsx-runtime";
924
1071
  var syncContentPart = ({ message }, useContentPart, partIndex) => {
925
1072
  const part = message.content[partIndex];
@@ -938,13 +1085,13 @@ var syncContentPart = ({ message }, useContentPart, partIndex) => {
938
1085
  var useContentPartContext2 = (partIndex) => {
939
1086
  const { useMessage } = useMessageContext();
940
1087
  const [context] = useState4(() => {
941
- const useContentPart = create7(
1088
+ const useContentPart = create8(
942
1089
  () => ({})
943
1090
  );
944
1091
  syncContentPart(useMessage.getState(), useContentPart, partIndex);
945
1092
  return { useContentPart };
946
1093
  });
947
- useEffect4(() => {
1094
+ useEffect7(() => {
948
1095
  syncContentPart(useMessage.getState(), context.useContentPart, partIndex);
949
1096
  return useMessage.subscribe((message) => {
950
1097
  syncContentPart(message, context.useContentPart, partIndex);
@@ -961,36 +1108,38 @@ var ContentPartProvider = ({
961
1108
  };
962
1109
 
963
1110
  // src/primitives/contentPart/ContentPartDisplay.tsx
964
- var ContentPartDisplay = () => {
1111
+ var ContentPartPrimitiveDisplay = () => {
965
1112
  const display = useContentPartDisplay();
966
1113
  return display ?? null;
967
1114
  };
1115
+ ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
968
1116
 
969
1117
  // src/primitives/contentPart/ContentPartInProgressIndicator.tsx
970
- var ContentPartInProgressIndicator = () => {
1118
+ var ContentPartPrimitiveInProgressIndicator = () => {
971
1119
  const indicator = useContentPartInProgressIndicator();
972
1120
  return indicator;
973
1121
  };
1122
+ ContentPartPrimitiveInProgressIndicator.displayName = "ContentPartPrimitive.InProgressIndicator";
974
1123
 
975
1124
  // src/primitives/contentPart/ContentPartText.tsx
976
1125
  import { Primitive as Primitive4 } from "@radix-ui/react-primitive";
977
1126
  import { forwardRef as forwardRef6 } from "react";
978
1127
  import { jsx as jsx13 } from "react/jsx-runtime";
979
- var ContentPartText = forwardRef6((props, forwardedRef) => {
1128
+ var ContentPartPrimitiveText = forwardRef6((props, forwardedRef) => {
980
1129
  const text = useContentPartText();
981
1130
  return /* @__PURE__ */ jsx13(Primitive4.p, { ...props, ref: forwardedRef, children: text });
982
1131
  });
983
- ContentPartText.displayName = "ContentPartText";
1132
+ ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
984
1133
 
985
1134
  // src/primitives/message/MessageContent.tsx
986
1135
  import { Fragment as Fragment3, jsx as jsx14, jsxs as jsxs2 } from "react/jsx-runtime";
987
1136
  var defaultComponents = {
988
1137
  Text: () => /* @__PURE__ */ jsxs2(Fragment3, { children: [
989
- /* @__PURE__ */ jsx14(ContentPartText, { style: { whiteSpace: "pre-line" } }),
990
- /* @__PURE__ */ jsx14(ContentPartInProgressIndicator, {})
1138
+ /* @__PURE__ */ jsx14(ContentPartPrimitiveText, { style: { whiteSpace: "pre-line" } }),
1139
+ /* @__PURE__ */ jsx14(ContentPartPrimitiveInProgressIndicator, {})
991
1140
  ] }),
992
1141
  Image: () => null,
993
- UI: () => /* @__PURE__ */ jsx14(ContentPartDisplay, {}),
1142
+ UI: () => /* @__PURE__ */ jsx14(ContentPartPrimitiveDisplay, {}),
994
1143
  tools: {
995
1144
  Fallback: (props) => {
996
1145
  const { useToolUIs } = useAssistantContext();
@@ -1039,7 +1188,9 @@ var MessageContentPart = memo2(
1039
1188
  MessageContentPartImpl,
1040
1189
  (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
1041
1190
  );
1042
- var MessageContent = ({ components }) => {
1191
+ var MessagePrimitiveContent = ({
1192
+ components
1193
+ }) => {
1043
1194
  const { useMessage } = useMessageContext();
1044
1195
  const contentLength = useMessage((s) => s.message.content.length);
1045
1196
  return new Array(contentLength).fill(null).map((_, idx) => {
@@ -1054,38 +1205,42 @@ var MessageContent = ({ components }) => {
1054
1205
  );
1055
1206
  });
1056
1207
  };
1208
+ MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
1057
1209
 
1058
1210
  // src/primitives/message/MessageInProgress.tsx
1059
1211
  import { Primitive as Primitive5 } from "@radix-ui/react-primitive";
1060
1212
  import {
1061
1213
  forwardRef as forwardRef7,
1062
- useMemo as useMemo3
1214
+ useEffect as useEffect8
1063
1215
  } from "react";
1064
1216
  import { jsx as jsx15 } from "react/jsx-runtime";
1065
- var MessageInProgress = forwardRef7((props, ref) => {
1217
+ var MessagePrimitiveInProgress = forwardRef7((props, ref) => {
1066
1218
  const { useMessageUtils } = useMessageContext();
1067
- useMemo3(() => {
1219
+ useEffect8(() => {
1068
1220
  useMessageUtils.getState().setInProgressIndicator(/* @__PURE__ */ jsx15(Primitive5.span, { ...props, ref }));
1221
+ return () => {
1222
+ useMessageUtils.getState().setInProgressIndicator(null);
1223
+ };
1069
1224
  }, [useMessageUtils, props, ref]);
1070
1225
  return null;
1071
1226
  });
1072
- MessageInProgress.displayName = "MessageInProgress";
1227
+ MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
1073
1228
 
1074
1229
  // src/primitives/branchPicker/BranchPickerRoot.tsx
1075
1230
  import { jsx as jsx16 } from "react/jsx-runtime";
1076
- var BranchPickerRoot = forwardRef8(({ hideWhenSingleBranch, ...rest }, ref) => {
1077
- return /* @__PURE__ */ jsx16(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx16(Primitive6.div, { ...rest, ref }) });
1231
+ var BranchPickerPrimitiveRoot = forwardRef8(({ hideWhenSingleBranch, ...rest }, ref) => {
1232
+ return /* @__PURE__ */ jsx16(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx16(Primitive6.div, { ...rest, ref }) });
1078
1233
  });
1079
- BranchPickerRoot.displayName = "BranchPickerRoot";
1234
+ BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
1080
1235
 
1081
1236
  // src/primitives/composer/index.ts
1082
1237
  var composer_exports = {};
1083
1238
  __export(composer_exports, {
1084
- Cancel: () => ComposerCancel,
1085
- If: () => ComposerIf,
1086
- Input: () => ComposerInput,
1087
- Root: () => ComposerRoot,
1088
- Send: () => ComposerSend
1239
+ Cancel: () => ComposerPrimitiveCancel,
1240
+ If: () => ComposerPrimitiveIf,
1241
+ Input: () => ComposerPrimitiveInput,
1242
+ Root: () => ComposerPrimitiveRoot,
1243
+ Send: () => ComposerPrimitiveSend
1089
1244
  });
1090
1245
 
1091
1246
  // src/primitives/composer/ComposerRoot.tsx
@@ -1095,25 +1250,23 @@ import {
1095
1250
  forwardRef as forwardRef9
1096
1251
  } from "react";
1097
1252
  import { jsx as jsx17 } from "react/jsx-runtime";
1098
- var ComposerRoot = forwardRef9(
1099
- ({ onSubmit, ...rest }, forwardedRef) => {
1100
- const send = useComposerSend();
1101
- const handleSubmit = (e) => {
1102
- if (!send) return;
1103
- e.preventDefault();
1104
- send();
1105
- };
1106
- return /* @__PURE__ */ jsx17(
1107
- Primitive7.form,
1108
- {
1109
- ...rest,
1110
- ref: forwardedRef,
1111
- onSubmit: composeEventHandlers5(onSubmit, handleSubmit)
1112
- }
1113
- );
1114
- }
1115
- );
1116
- ComposerRoot.displayName = "ComposerRoot";
1253
+ var ComposerPrimitiveRoot = forwardRef9(({ onSubmit, ...rest }, forwardedRef) => {
1254
+ const send = useComposerSend();
1255
+ const handleSubmit = (e) => {
1256
+ e.preventDefault();
1257
+ if (!send) return;
1258
+ send();
1259
+ };
1260
+ return /* @__PURE__ */ jsx17(
1261
+ Primitive7.form,
1262
+ {
1263
+ ...rest,
1264
+ ref: forwardedRef,
1265
+ onSubmit: composeEventHandlers5(onSubmit, handleSubmit)
1266
+ }
1267
+ );
1268
+ });
1269
+ ComposerPrimitiveRoot.displayName = "ComposerPrimitive.Root";
1117
1270
 
1118
1271
  // src/primitives/composer/ComposerInput.tsx
1119
1272
  import { composeEventHandlers as composeEventHandlers6 } from "@radix-ui/primitive";
@@ -1121,14 +1274,14 @@ import { useComposedRefs } from "@radix-ui/react-compose-refs";
1121
1274
  import { Slot } from "@radix-ui/react-slot";
1122
1275
  import {
1123
1276
  forwardRef as forwardRef10,
1124
- useCallback as useCallback10,
1125
- useEffect as useEffect5,
1277
+ useCallback as useCallback13,
1278
+ useEffect as useEffect9,
1126
1279
  useRef as useRef3
1127
1280
  } from "react";
1128
1281
  import TextareaAutosize from "react-textarea-autosize";
1129
1282
  import { useEscapeKeydown } from "@radix-ui/react-use-escape-keydown";
1130
1283
  import { jsx as jsx18 } from "react/jsx-runtime";
1131
- var ComposerInput = forwardRef10(
1284
+ var ComposerPrimitiveInput = forwardRef10(
1132
1285
  ({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
1133
1286
  const { useThread } = useThreadContext();
1134
1287
  const { useComposer, type } = useComposerContext();
@@ -1156,7 +1309,7 @@ var ComposerInput = forwardRef10(
1156
1309
  }
1157
1310
  };
1158
1311
  const autoFocusEnabled = autoFocus && !disabled;
1159
- const focus = useCallback10(() => {
1312
+ const focus = useCallback13(() => {
1160
1313
  const textarea = textareaRef.current;
1161
1314
  if (!textarea || !autoFocusEnabled) return;
1162
1315
  textarea.focus({ preventScroll: true });
@@ -1165,7 +1318,7 @@ var ComposerInput = forwardRef10(
1165
1318
  textareaRef.current.value.length
1166
1319
  );
1167
1320
  }, [autoFocusEnabled]);
1168
- useEffect5(() => focus(), [focus]);
1321
+ useEffect9(() => focus(), [focus]);
1169
1322
  useOnComposerFocus(() => {
1170
1323
  if (type === "new") {
1171
1324
  focus();
@@ -1188,94 +1341,101 @@ var ComposerInput = forwardRef10(
1188
1341
  );
1189
1342
  }
1190
1343
  );
1191
- ComposerInput.displayName = "ComposerInput";
1344
+ ComposerPrimitiveInput.displayName = "ComposerPrimitive.Input";
1192
1345
 
1193
1346
  // src/primitives/composer/ComposerSend.tsx
1194
1347
  import { forwardRef as forwardRef11 } from "react";
1195
1348
  import { Primitive as Primitive8 } from "@radix-ui/react-primitive";
1196
1349
  import { jsx as jsx19 } from "react/jsx-runtime";
1197
- var ComposerSend = forwardRef11(
1198
- ({ disabled, ...rest }, ref) => {
1199
- const { useComposer } = useComposerContext();
1200
- const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
1201
- return /* @__PURE__ */ jsx19(
1202
- Primitive8.button,
1203
- {
1204
- type: "submit",
1205
- ...rest,
1206
- ref,
1207
- disabled: disabled || !hasValue
1208
- }
1209
- );
1210
- }
1211
- );
1212
- ComposerSend.displayName = "ComposerSend";
1350
+ var ComposerPrimitiveSend = forwardRef11(({ disabled, ...rest }, ref) => {
1351
+ const { useComposer } = useComposerContext();
1352
+ const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
1353
+ return /* @__PURE__ */ jsx19(
1354
+ Primitive8.button,
1355
+ {
1356
+ type: "submit",
1357
+ ...rest,
1358
+ ref,
1359
+ disabled: disabled || !hasValue
1360
+ }
1361
+ );
1362
+ });
1363
+ ComposerPrimitiveSend.displayName = "ComposerPrimitive.Send";
1213
1364
 
1214
1365
  // src/primitives/composer/ComposerCancel.tsx
1215
- var ComposerCancel = createActionButton(
1216
- "ComposerCancel",
1366
+ var ComposerPrimitiveCancel = createActionButton(
1367
+ "ComposerPrimitive.Cancel",
1217
1368
  useComposerCancel
1218
1369
  );
1219
1370
 
1220
1371
  // src/primitives/composer/ComposerIf.tsx
1221
- var ComposerIf = ({ children, ...query }) => {
1372
+ var ComposerPrimitiveIf = ({
1373
+ children,
1374
+ ...query
1375
+ }) => {
1222
1376
  const result = useComposerIf(query);
1223
1377
  return result ? children : null;
1224
1378
  };
1379
+ ComposerPrimitiveIf.displayName = "ComposerPrimitive.If";
1225
1380
 
1226
1381
  // src/primitives/contentPart/index.ts
1227
1382
  var contentPart_exports = {};
1228
1383
  __export(contentPart_exports, {
1229
- Display: () => ContentPartDisplay,
1230
- Image: () => ContentPartImage,
1231
- InProgressIndicator: () => ContentPartInProgressIndicator,
1232
- Text: () => ContentPartText
1384
+ Display: () => ContentPartPrimitiveDisplay,
1385
+ Image: () => ContentPartPrimitiveImage,
1386
+ InProgressIndicator: () => ContentPartPrimitiveInProgressIndicator,
1387
+ Text: () => ContentPartPrimitiveText
1233
1388
  });
1234
1389
 
1235
1390
  // src/primitives/contentPart/ContentPartImage.tsx
1236
1391
  import { Primitive as Primitive9 } from "@radix-ui/react-primitive";
1237
1392
  import { forwardRef as forwardRef12 } from "react";
1238
1393
  import { jsx as jsx20 } from "react/jsx-runtime";
1239
- var ContentPartImage = forwardRef12((props, forwardedRef) => {
1394
+ var ContentPartPrimitiveImage = forwardRef12((props, forwardedRef) => {
1240
1395
  const image = useContentPartImage();
1241
1396
  return /* @__PURE__ */ jsx20(Primitive9.img, { src: image, ...props, ref: forwardedRef });
1242
1397
  });
1243
- ContentPartImage.displayName = "ContentPartImage";
1398
+ ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
1244
1399
 
1245
1400
  // src/primitives/thread/index.ts
1246
1401
  var thread_exports = {};
1247
1402
  __export(thread_exports, {
1248
- Empty: () => ThreadEmpty,
1249
- If: () => ThreadIf,
1250
- Messages: () => ThreadMessages,
1251
- Root: () => ThreadRoot,
1252
- ScrollToBottom: () => ThreadScrollToBottom,
1253
- Suggestion: () => ThreadSuggestion,
1254
- Viewport: () => ThreadViewport
1403
+ Empty: () => ThreadPrimitiveEmpty,
1404
+ If: () => ThreadPrimitiveIf,
1405
+ Messages: () => ThreadPrimitiveMessages,
1406
+ Root: () => ThreadPrimitiveRoot,
1407
+ ScrollToBottom: () => ThreadPrimitiveScrollToBottom,
1408
+ Suggestion: () => ThreadPrimitiveSuggestion,
1409
+ Viewport: () => ThreadPrimitiveViewport
1255
1410
  });
1256
1411
 
1257
1412
  // src/primitives/thread/ThreadRoot.tsx
1258
1413
  import { Primitive as Primitive10 } from "@radix-ui/react-primitive";
1259
1414
  import { forwardRef as forwardRef13 } from "react";
1260
1415
  import { jsx as jsx21 } from "react/jsx-runtime";
1261
- var ThreadRoot = forwardRef13(
1262
- (props, ref) => {
1263
- return /* @__PURE__ */ jsx21(Primitive10.div, { ...props, ref });
1264
- }
1265
- );
1266
- ThreadRoot.displayName = "ThreadRoot";
1416
+ var ThreadPrimitiveRoot = forwardRef13((props, ref) => {
1417
+ return /* @__PURE__ */ jsx21(Primitive10.div, { ...props, ref });
1418
+ });
1419
+ ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
1267
1420
 
1268
1421
  // src/primitives/thread/ThreadEmpty.tsx
1269
- var ThreadEmpty = ({ children }) => {
1422
+ var ThreadPrimitiveEmpty = ({
1423
+ children
1424
+ }) => {
1270
1425
  const empty = useThreadEmpty();
1271
1426
  return empty ? children : null;
1272
1427
  };
1428
+ ThreadPrimitiveEmpty.displayName = "ThreadPrimitive.Empty";
1273
1429
 
1274
1430
  // src/primitives/thread/ThreadIf.tsx
1275
- var ThreadIf = ({ children, ...query }) => {
1431
+ var ThreadPrimitiveIf = ({
1432
+ children,
1433
+ ...query
1434
+ }) => {
1276
1435
  const result = useThreadIf(query);
1277
1436
  return result ? children : null;
1278
1437
  };
1438
+ ThreadPrimitiveIf.displayName = "ThreadPrimitive.If";
1279
1439
 
1280
1440
  // src/primitives/thread/ThreadViewport.tsx
1281
1441
  import { useComposedRefs as useComposedRefs3 } from "@radix-ui/react-compose-refs";
@@ -1288,13 +1448,13 @@ import { useRef as useRef5 } from "react";
1288
1448
 
1289
1449
  // src/utils/hooks/useOnResizeContent.tsx
1290
1450
  import { useCallbackRef as useCallbackRef2 } from "@radix-ui/react-use-callback-ref";
1291
- import { useCallback as useCallback12 } from "react";
1451
+ import { useCallback as useCallback15 } from "react";
1292
1452
 
1293
1453
  // src/utils/hooks/useManagedRef.ts
1294
- import { useCallback as useCallback11, useRef as useRef4 } from "react";
1454
+ import { useCallback as useCallback14, useRef as useRef4 } from "react";
1295
1455
  var useManagedRef = (callback) => {
1296
1456
  const cleanupRef = useRef4();
1297
- const ref = useCallback11(
1457
+ const ref = useCallback14(
1298
1458
  (el) => {
1299
1459
  if (cleanupRef.current) {
1300
1460
  cleanupRef.current();
@@ -1311,7 +1471,7 @@ var useManagedRef = (callback) => {
1311
1471
  // src/utils/hooks/useOnResizeContent.tsx
1312
1472
  var useOnResizeContent = (callback) => {
1313
1473
  const callbackRef = useCallbackRef2(callback);
1314
- const refCallback = useCallback12(
1474
+ const refCallback = useCallback15(
1315
1475
  (el) => {
1316
1476
  const resizeObserver = new ResizeObserver(() => {
1317
1477
  callbackRef();
@@ -1348,11 +1508,11 @@ var useOnResizeContent = (callback) => {
1348
1508
 
1349
1509
  // src/utils/hooks/useOnScrollToBottom.tsx
1350
1510
  import { useCallbackRef as useCallbackRef3 } from "@radix-ui/react-use-callback-ref";
1351
- import { useEffect as useEffect6 } from "react";
1511
+ import { useEffect as useEffect10 } from "react";
1352
1512
  var useOnScrollToBottom = (callback) => {
1353
1513
  const callbackRef = useCallbackRef3(callback);
1354
1514
  const { useViewport } = useThreadContext();
1355
- useEffect6(() => {
1515
+ useEffect10(() => {
1356
1516
  return useViewport.getState().onScrollToBottom(() => {
1357
1517
  callbackRef();
1358
1518
  });
@@ -1414,28 +1574,28 @@ var useThreadViewportAutoScroll = ({
1414
1574
 
1415
1575
  // src/primitives/thread/ThreadViewport.tsx
1416
1576
  import { jsx as jsx22 } from "react/jsx-runtime";
1417
- var ThreadViewport = forwardRef14(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
1577
+ var ThreadPrimitiveViewport = forwardRef14(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
1418
1578
  const autoScrollRef = useThreadViewportAutoScroll({
1419
1579
  autoScroll
1420
1580
  });
1421
1581
  const ref = useComposedRefs3(forwardedRef, autoScrollRef);
1422
1582
  return /* @__PURE__ */ jsx22(Primitive11.div, { ...rest, ref, children });
1423
1583
  });
1424
- ThreadViewport.displayName = "ThreadViewport";
1584
+ ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
1425
1585
 
1426
1586
  // src/primitives/thread/ThreadMessages.tsx
1427
1587
  import { memo as memo3 } from "react";
1428
1588
 
1429
1589
  // src/context/providers/MessageProvider.tsx
1430
- import { useEffect as useEffect7, useState as useState5 } from "react";
1431
- import { create as create10 } from "zustand";
1590
+ import { useEffect as useEffect11, useState as useState5 } from "react";
1591
+ import { create as create11 } from "zustand";
1432
1592
 
1433
1593
  // src/context/stores/EditComposer.ts
1434
- import { create as create8 } from "zustand";
1594
+ import { create as create9 } from "zustand";
1435
1595
  var makeEditComposerStore = ({
1436
1596
  onEdit,
1437
1597
  onSend
1438
- }) => create8()((set, get, store) => ({
1598
+ }) => create9()((set, get, store) => ({
1439
1599
  ...makeBaseComposer(set, get, store),
1440
1600
  isEditing: false,
1441
1601
  edit: () => {
@@ -1455,8 +1615,8 @@ var makeEditComposerStore = ({
1455
1615
  }));
1456
1616
 
1457
1617
  // src/context/stores/MessageUtils.ts
1458
- import { create as create9 } from "zustand";
1459
- var makeMessageUtilsStore = () => create9((set) => ({
1618
+ import { create as create10 } from "zustand";
1619
+ var makeMessageUtilsStore = () => create10((set) => ({
1460
1620
  inProgressIndicator: null,
1461
1621
  setInProgressIndicator: (value) => {
1462
1622
  set({ inProgressIndicator: value });
@@ -1495,7 +1655,7 @@ var syncMessage = (thread, getBranches, useMessage, messageIndex) => {
1495
1655
  var useMessageContext2 = (messageIndex) => {
1496
1656
  const { useThread, useThreadActions } = useThreadContext();
1497
1657
  const [context] = useState5(() => {
1498
- const useMessage = create10(() => ({}));
1658
+ const useMessage = create11(() => ({}));
1499
1659
  const useMessageUtils = makeMessageUtilsStore();
1500
1660
  const useEditComposer = makeEditComposerStore({
1501
1661
  onEdit: () => {
@@ -1531,7 +1691,7 @@ var useMessageContext2 = (messageIndex) => {
1531
1691
  );
1532
1692
  return { useMessage, useMessageUtils, useEditComposer };
1533
1693
  });
1534
- useEffect7(() => {
1694
+ useEffect11(() => {
1535
1695
  return useThread.subscribe((thread) => {
1536
1696
  syncMessage(
1537
1697
  thread,
@@ -1566,18 +1726,20 @@ var ThreadMessageImpl = ({
1566
1726
  }) => {
1567
1727
  const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
1568
1728
  return /* @__PURE__ */ jsxs3(MessageProvider, { messageIndex, children: [
1569
- /* @__PURE__ */ jsxs3(MessageIf, { user: true, children: [
1570
- /* @__PURE__ */ jsx24(ComposerIf, { editing: false, children: /* @__PURE__ */ jsx24(UserMessage, {}) }),
1571
- /* @__PURE__ */ jsx24(ComposerIf, { editing: true, children: /* @__PURE__ */ jsx24(EditComposer, {}) })
1729
+ /* @__PURE__ */ jsxs3(MessagePrimitiveIf, { user: true, children: [
1730
+ /* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ jsx24(UserMessage, {}) }),
1731
+ /* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ jsx24(EditComposer, {}) })
1572
1732
  ] }),
1573
- /* @__PURE__ */ jsx24(MessageIf, { assistant: true, children: /* @__PURE__ */ jsx24(AssistantMessage, {}) })
1733
+ /* @__PURE__ */ jsx24(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ jsx24(AssistantMessage, {}) })
1574
1734
  ] });
1575
1735
  };
1576
1736
  var ThreadMessage = memo3(
1577
1737
  ThreadMessageImpl,
1578
1738
  (prev, next) => prev.messageIndex === next.messageIndex && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
1579
1739
  );
1580
- var ThreadMessages = ({ components }) => {
1740
+ var ThreadPrimitiveMessages = ({
1741
+ components
1742
+ }) => {
1581
1743
  const { useThread } = useThreadContext();
1582
1744
  const messagesLength = useThread((t) => t.messages.length);
1583
1745
  if (messagesLength === 0) return null;
@@ -1593,16 +1755,17 @@ var ThreadMessages = ({ components }) => {
1593
1755
  );
1594
1756
  });
1595
1757
  };
1758
+ ThreadPrimitiveMessages.displayName = "ThreadPrimitive.Messages";
1596
1759
 
1597
1760
  // src/primitives/thread/ThreadScrollToBottom.tsx
1598
- var ThreadScrollToBottom = createActionButton(
1599
- "ThreadScrollToBottom",
1761
+ var ThreadPrimitiveScrollToBottom = createActionButton(
1762
+ "ThreadPrimitive.ScrollToBottom",
1600
1763
  useThreadScrollToBottom
1601
1764
  );
1602
1765
 
1603
1766
  // src/primitives/thread/ThreadSuggestion.tsx
1604
- var ThreadSuggestion = createActionButton(
1605
- "ThreadSuggestion",
1767
+ var ThreadPrimitiveSuggestion = createActionButton(
1768
+ "ThreadPrimitive.Suggestion",
1606
1769
  useThreadSuggestion
1607
1770
  );
1608
1771
 
@@ -1769,13 +1932,91 @@ var MessageRepository = class {
1769
1932
  }
1770
1933
  };
1771
1934
 
1935
+ // src/runtime/core/BaseAssistantRuntime.tsx
1936
+ var BaseAssistantRuntime = class {
1937
+ constructor(_thread) {
1938
+ this._thread = _thread;
1939
+ this._thread = _thread;
1940
+ this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
1941
+ }
1942
+ _unsubscribe;
1943
+ get thread() {
1944
+ return this._thread;
1945
+ }
1946
+ set thread(thread) {
1947
+ this._unsubscribe();
1948
+ this._thread = thread;
1949
+ this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
1950
+ this.subscriptionHandler();
1951
+ }
1952
+ get messages() {
1953
+ return this.thread.messages;
1954
+ }
1955
+ get isRunning() {
1956
+ return this.thread.isRunning;
1957
+ }
1958
+ getBranches(messageId) {
1959
+ return this.thread.getBranches(messageId);
1960
+ }
1961
+ switchToBranch(branchId) {
1962
+ return this.thread.switchToBranch(branchId);
1963
+ }
1964
+ append(message) {
1965
+ return this.thread.append(message);
1966
+ }
1967
+ startRun(parentId) {
1968
+ return this.thread.startRun(parentId);
1969
+ }
1970
+ cancelRun() {
1971
+ return this.thread.cancelRun();
1972
+ }
1973
+ addToolResult(toolCallId, result) {
1974
+ return this.thread.addToolResult(toolCallId, result);
1975
+ }
1976
+ _subscriptions = /* @__PURE__ */ new Set();
1977
+ subscribe(callback) {
1978
+ this._subscriptions.add(callback);
1979
+ return () => this._subscriptions.delete(callback);
1980
+ }
1981
+ subscriptionHandler = () => {
1982
+ for (const callback of this._subscriptions) callback();
1983
+ };
1984
+ get unstable_synchronizer() {
1985
+ return this.thread.unstable_synchronizer;
1986
+ }
1987
+ };
1988
+
1772
1989
  // src/runtime/local/LocalRuntime.tsx
1773
- var LocalRuntime = class {
1990
+ var LocalRuntime = class extends BaseAssistantRuntime {
1991
+ _configProviders;
1774
1992
  constructor(adapter) {
1993
+ const configProviders = /* @__PURE__ */ new Set();
1994
+ super(new LocalThreadRuntime(configProviders, adapter));
1995
+ this._configProviders = configProviders;
1996
+ }
1997
+ set adapter(adapter) {
1998
+ this.thread.adapter = adapter;
1999
+ }
2000
+ registerModelConfigProvider(provider) {
2001
+ this._configProviders.add(provider);
2002
+ return () => this._configProviders.delete(provider);
2003
+ }
2004
+ switchToThread(threadId) {
2005
+ if (threadId) {
2006
+ throw new Error("LocalRuntime does not yet support switching threads");
2007
+ }
2008
+ return this.thread = new LocalThreadRuntime(
2009
+ this._configProviders,
2010
+ this.thread.adapter
2011
+ );
2012
+ }
2013
+ };
2014
+ var LocalThreadRuntime = class {
2015
+ constructor(_configProviders, adapter) {
2016
+ this._configProviders = _configProviders;
1775
2017
  this.adapter = adapter;
1776
2018
  }
1777
2019
  _subscriptions = /* @__PURE__ */ new Set();
1778
- _configProviders = /* @__PURE__ */ new Set();
1779
2020
  abortController = null;
1780
2021
  repository = new MessageRepository();
1781
2022
  get messages() {
@@ -1854,12 +2095,8 @@ var LocalRuntime = class {
1854
2095
  this._subscriptions.add(callback);
1855
2096
  return () => this._subscriptions.delete(callback);
1856
2097
  }
1857
- registerModelConfigProvider(provider) {
1858
- this._configProviders.add(provider);
1859
- return () => this._configProviders.delete(provider);
1860
- }
1861
2098
  addToolResult() {
1862
- throw new Error("LocalRuntime does not yet support tool results");
2099
+ throw new Error("LocalRuntime does not yet support adding tool results");
1863
2100
  }
1864
2101
  };
1865
2102
 
@@ -1872,78 +2109,10 @@ var useLocalRuntime = (adapter) => {
1872
2109
  return runtime;
1873
2110
  };
1874
2111
 
1875
- // src/model-config/useAssistantTool.tsx
1876
- import { useEffect as useEffect8 } from "react";
1877
- var useAssistantTool = (tool) => {
1878
- const { useModelConfig, useToolUIs } = useAssistantContext();
1879
- const registerModelConfigProvider = useModelConfig(
1880
- (s) => s.registerModelConfigProvider
1881
- );
1882
- const setToolUI = useToolUIs((s) => s.setToolUI);
1883
- useEffect8(() => {
1884
- const { toolName, render, ...rest } = tool;
1885
- const config = {
1886
- tools: {
1887
- [tool.toolName]: rest
1888
- }
1889
- };
1890
- const unsub1 = registerModelConfigProvider(() => config);
1891
- const unsub2 = render ? setToolUI(toolName, render) : void 0;
1892
- return () => {
1893
- unsub1();
1894
- unsub2?.();
1895
- };
1896
- }, [registerModelConfigProvider, setToolUI, tool]);
1897
- };
1898
-
1899
- // src/model-config/makeAssistantTool.tsx
1900
- var makeAssistantTool = (tool) => {
1901
- const Tool = () => {
1902
- useAssistantTool(tool);
1903
- return null;
1904
- };
1905
- return Tool;
1906
- };
1907
-
1908
- // src/model-config/useAssistantToolUI.tsx
1909
- import { useEffect as useEffect9 } from "react";
1910
- var useAssistantToolUI = (tool) => {
1911
- const { useToolUIs } = useAssistantContext();
1912
- const setToolUI = useToolUIs((s) => s.setToolUI);
1913
- useEffect9(() => {
1914
- if (!tool) return;
1915
- const { toolName, render } = tool;
1916
- return setToolUI(toolName, render);
1917
- }, [setToolUI, tool]);
1918
- };
1919
-
1920
- // src/model-config/makeAssistantToolUI.tsx
1921
- var makeAssistantToolUI = (tool) => {
1922
- const ToolUI = () => {
1923
- useAssistantToolUI(tool);
1924
- return null;
1925
- };
1926
- return ToolUI;
1927
- };
1928
-
1929
- // src/model-config/useAssistantInstructions.tsx
1930
- import { useEffect as useEffect10 } from "react";
1931
- var useAssistantInstructions = (instruction) => {
1932
- const { useModelConfig } = useAssistantContext();
1933
- const registerModelConfigProvider = useModelConfig(
1934
- (s) => s.registerModelConfigProvider
1935
- );
1936
- useEffect10(() => {
1937
- const config = {
1938
- system: instruction
1939
- };
1940
- return registerModelConfigProvider(() => config);
1941
- }, [registerModelConfigProvider, instruction]);
1942
- };
1943
-
1944
2112
  // src/internal.ts
1945
2113
  var internal_exports = {};
1946
2114
  __export(internal_exports, {
2115
+ BaseAssistantRuntime: () => BaseAssistantRuntime,
1947
2116
  MessageRepository: () => MessageRepository,
1948
2117
  ProxyConfigProvider: () => ProxyConfigProvider
1949
2118
  });
@@ -1962,6 +2131,7 @@ export {
1962
2131
  useActionBarCopy,
1963
2132
  useActionBarEdit,
1964
2133
  useActionBarReload,
2134
+ useAppendMessage,
1965
2135
  useAssistantContext,
1966
2136
  useAssistantInstructions,
1967
2137
  useAssistantTool,
@@ -1982,6 +2152,7 @@ export {
1982
2152
  useLocalRuntime,
1983
2153
  useMessageContext,
1984
2154
  useMessageIf,
2155
+ useSwitchToNewThread,
1985
2156
  useThreadContext,
1986
2157
  useThreadEmpty,
1987
2158
  useThreadIf,