@assistant-ui/react 0.1.12 → 0.2.2

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