@assistant-ui/react 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -38,19 +38,33 @@ __export(src_exports, {
38
38
  INTERNAL: () => internal_exports,
39
39
  MessagePrimitive: () => message_exports,
40
40
  ThreadPrimitive: () => thread_exports,
41
- useBeginMessageEdit: () => useBeginMessageEdit,
42
- useCopyMessage: () => useCopyMessage,
43
- useGoToNextBranch: () => useGoToNextBranch,
44
- useGoToPreviousBranch: () => useGoToPreviousBranch,
41
+ useActionBarCopy: () => useActionBarCopy,
42
+ useActionBarEdit: () => useActionBarEdit,
43
+ useActionBarReload: () => useActionBarReload,
44
+ useBranchPickerCount: () => useBranchPickerCount,
45
+ useBranchPickerNext: () => useBranchPickerNext,
46
+ useBranchPickerNumber: () => useBranchPickerNumber,
47
+ useBranchPickerPrevious: () => useBranchPickerPrevious,
48
+ useComposerCancel: () => useComposerCancel,
49
+ useComposerIf: () => useComposerIf,
50
+ useComposerSend: () => useComposerSend,
51
+ useContentPartDisplay: () => useContentPartDisplay,
52
+ useContentPartImage: () => useContentPartImage,
53
+ useContentPartInProgressIndicator: () => useContentPartInProgressIndicator,
54
+ useContentPartText: () => useContentPartText,
45
55
  useLocalRuntime: () => useLocalRuntime,
46
- useReloadMessage: () => useReloadMessage
56
+ useMessageIf: () => useMessageIf,
57
+ useThreadEmpty: () => useThreadEmpty,
58
+ useThreadIf: () => useThreadIf,
59
+ useThreadScrollToBottom: () => useThreadScrollToBottom,
60
+ useThreadSuggestion: () => useThreadSuggestion
47
61
  });
48
62
  module.exports = __toCommonJS(src_exports);
49
63
 
50
- // src/actions/useCopyMessage.tsx
64
+ // src/primitive-hooks/actionBar/useActionBarCopy.tsx
51
65
  var import_react4 = require("react");
52
66
 
53
- // src/context/MessageContext.ts
67
+ // src/context/react/MessageContext.ts
54
68
  var import_react = require("react");
55
69
  var MessageContext = (0, import_react.createContext)(null);
56
70
  var useMessageContext = () => {
@@ -96,36 +110,54 @@ var getMessageText = (message) => {
96
110
  return textParts.map((part) => part.text).join("\n\n");
97
111
  };
98
112
 
99
- // src/actions/useCopyMessage.tsx
100
- var useCopyMessage = ({ copiedDuration = 3e3 }) => {
101
- const { useMessage, useMessageUtils, useComposer } = useMessageContext();
113
+ // src/primitive-hooks/actionBar/useActionBarCopy.tsx
114
+ var useActionBarCopy = ({
115
+ copiedDuration = 3e3
116
+ } = {}) => {
117
+ const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();
102
118
  const hasCopyableContent = useCombinedStore(
103
- [useMessage, useComposer],
119
+ [useMessage, useEditComposer],
104
120
  (m, c) => {
105
- return c.isEditing || m.message.content.some((c2) => c2.type === "text");
121
+ return !c.isEditing && m.message.content.some((c2) => c2.type === "text");
106
122
  }
107
123
  );
108
124
  const callback = (0, import_react4.useCallback)(() => {
109
125
  const { message } = useMessage.getState();
110
126
  const { setIsCopied } = useMessageUtils.getState();
111
- const { isEditing, value: composerValue } = useComposer.getState();
127
+ const { isEditing, value: composerValue } = useEditComposer.getState();
112
128
  const valueToCopy = isEditing ? composerValue : getMessageText(message);
113
129
  navigator.clipboard.writeText(valueToCopy);
114
130
  setIsCopied(true);
115
131
  setTimeout(() => setIsCopied(false), copiedDuration);
116
- }, [useMessage, useMessageUtils, useComposer, copiedDuration]);
132
+ }, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);
117
133
  if (!hasCopyableContent) return null;
118
134
  return callback;
119
135
  };
120
136
 
121
- // src/actions/useReloadMessage.tsx
122
- var import_react6 = require("react");
123
-
124
- // src/context/ThreadContext.ts
137
+ // src/primitive-hooks/actionBar/useActionBarEdit.tsx
125
138
  var import_react5 = require("react");
126
- var ThreadContext = (0, import_react5.createContext)(null);
139
+ var useActionBarEdit = () => {
140
+ const { useMessage, useEditComposer } = useMessageContext();
141
+ const disabled = useCombinedStore(
142
+ [useMessage, useEditComposer],
143
+ (m, c) => m.message.role !== "user" || c.isEditing
144
+ );
145
+ const callback = (0, import_react5.useCallback)(() => {
146
+ const { edit } = useEditComposer.getState();
147
+ edit();
148
+ }, [useEditComposer]);
149
+ if (disabled) return null;
150
+ return callback;
151
+ };
152
+
153
+ // src/primitive-hooks/actionBar/useActionBarReload.tsx
154
+ var import_react7 = require("react");
155
+
156
+ // src/context/react/ThreadContext.ts
157
+ var import_react6 = require("react");
158
+ var ThreadContext = (0, import_react6.createContext)(null);
127
159
  var useThreadContext = () => {
128
- const context = (0, import_react5.useContext)(ThreadContext);
160
+ const context = (0, import_react6.useContext)(ThreadContext);
129
161
  if (!context)
130
162
  throw new Error(
131
163
  "This component must be used within an AssistantRuntimeProvider."
@@ -133,15 +165,15 @@ var useThreadContext = () => {
133
165
  return context;
134
166
  };
135
167
 
136
- // src/actions/useReloadMessage.tsx
137
- var useReloadMessage = () => {
168
+ // src/primitive-hooks/actionBar/useActionBarReload.tsx
169
+ var useActionBarReload = () => {
138
170
  const { useThread, useThreadActions, useViewport } = useThreadContext();
139
171
  const { useMessage } = useMessageContext();
140
172
  const disabled = useCombinedStore(
141
173
  [useThread, useMessage],
142
174
  (t, m) => t.isRunning || m.message.role !== "assistant"
143
175
  );
144
- const callback = (0, import_react6.useCallback)(() => {
176
+ const callback = (0, import_react7.useCallback)(() => {
145
177
  const { parentId } = useMessage.getState();
146
178
  useThreadActions.getState().startRun(parentId);
147
179
  useViewport.getState().scrollToBottom();
@@ -150,29 +182,20 @@ var useReloadMessage = () => {
150
182
  return callback;
151
183
  };
152
184
 
153
- // src/actions/useBeginMessageEdit.tsx
154
- var import_react7 = require("react");
155
- var useBeginMessageEdit = () => {
156
- const { useMessage, useComposer } = useMessageContext();
157
- const disabled = useCombinedStore(
158
- [useMessage, useComposer],
159
- (m, c) => m.message.role !== "user" || c.isEditing
160
- );
161
- const callback = (0, import_react7.useCallback)(() => {
162
- const { edit } = useComposer.getState();
163
- edit();
164
- }, [useComposer]);
165
- if (disabled) return null;
166
- return callback;
185
+ // src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
186
+ var useBranchPickerCount = () => {
187
+ const { useMessage } = useMessageContext();
188
+ const branchCount = useMessage((s) => s.branches.length);
189
+ return branchCount;
167
190
  };
168
191
 
169
- // src/actions/useGoToNextBranch.tsx
192
+ // src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
170
193
  var import_react8 = require("react");
171
- var useGoToNextBranch = () => {
194
+ var useBranchPickerNext = () => {
172
195
  const { useThreadActions } = useThreadContext();
173
- const { useMessage, useComposer } = useMessageContext();
196
+ const { useMessage, useEditComposer } = useMessageContext();
174
197
  const disabled = useCombinedStore(
175
- [useMessage, useComposer],
198
+ [useMessage, useEditComposer],
176
199
  (m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
177
200
  );
178
201
  const callback = (0, import_react8.useCallback)(() => {
@@ -183,13 +206,20 @@ var useGoToNextBranch = () => {
183
206
  return callback;
184
207
  };
185
208
 
186
- // src/actions/useGoToPreviousBranch.tsx
209
+ // src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
210
+ var useBranchPickerNumber = () => {
211
+ const { useMessage } = useMessageContext();
212
+ const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
213
+ return branchIdx + 1;
214
+ };
215
+
216
+ // src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
187
217
  var import_react9 = require("react");
188
- var useGoToPreviousBranch = () => {
218
+ var useBranchPickerPrevious = () => {
189
219
  const { useThreadActions } = useThreadContext();
190
- const { useMessage, useComposer } = useMessageContext();
220
+ const { useMessage, useEditComposer } = useMessageContext();
191
221
  const disabled = useCombinedStore(
192
- [useMessage, useComposer],
222
+ [useMessage, useEditComposer],
193
223
  (m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
194
224
  );
195
225
  const callback = (0, import_react9.useCallback)(() => {
@@ -200,6 +230,203 @@ var useGoToPreviousBranch = () => {
200
230
  return callback;
201
231
  };
202
232
 
233
+ // src/primitive-hooks/composer/useComposerCancel.tsx
234
+ var import_react13 = require("react");
235
+
236
+ // src/context/react/AssistantContext.ts
237
+ var import_react10 = require("react");
238
+ var AssistantContext = (0, import_react10.createContext)(
239
+ null
240
+ );
241
+ var useAssistantContext = () => {
242
+ const context = (0, import_react10.useContext)(AssistantContext);
243
+ if (!context)
244
+ throw new Error(
245
+ "This component must be used within an AssistantRuntimeProvider."
246
+ );
247
+ return context;
248
+ };
249
+
250
+ // src/context/react/ComposerContext.ts
251
+ var import_react11 = require("react");
252
+ var useComposerContext = () => {
253
+ const { useComposer } = useThreadContext();
254
+ const { useEditComposer } = (0, import_react11.useContext)(MessageContext) ?? {};
255
+ return (0, import_react11.useMemo)(
256
+ () => ({
257
+ useComposer: useEditComposer ?? useComposer,
258
+ type: useEditComposer ? "edit" : "new"
259
+ }),
260
+ [useEditComposer, useComposer]
261
+ );
262
+ };
263
+
264
+ // src/context/react/ContentPartContext.ts
265
+ var import_react12 = require("react");
266
+ var ContentPartContext = (0, import_react12.createContext)(
267
+ null
268
+ );
269
+ var useContentPartContext = () => {
270
+ const context = (0, import_react12.useContext)(ContentPartContext);
271
+ if (!context)
272
+ throw new Error(
273
+ "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
274
+ );
275
+ return context;
276
+ };
277
+
278
+ // src/primitive-hooks/composer/useComposerCancel.tsx
279
+ var useComposerCancel = () => {
280
+ const { useComposer } = useComposerContext();
281
+ const disabled = useComposer((c) => !c.isEditing);
282
+ const callback = (0, import_react13.useCallback)(() => {
283
+ const { cancel } = useComposer.getState();
284
+ cancel();
285
+ }, [useComposer]);
286
+ if (disabled) return null;
287
+ return callback;
288
+ };
289
+
290
+ // src/primitive-hooks/composer/useComposerIf.tsx
291
+ var useComposerIf = (props) => {
292
+ const { useComposer } = useComposerContext();
293
+ return useComposer((composer) => {
294
+ if (props.editing === true && !composer.isEditing) return false;
295
+ if (props.editing === false && composer.isEditing) return false;
296
+ return true;
297
+ });
298
+ };
299
+
300
+ // src/primitive-hooks/composer/useComposerSend.tsx
301
+ var import_react14 = require("react");
302
+ var useComposerSend = () => {
303
+ const { useComposer } = useComposerContext();
304
+ const disabled = useComposer((c) => !c.isEditing || c.value.length === 0);
305
+ const callback = (0, import_react14.useCallback)(() => {
306
+ const { send } = useComposer.getState();
307
+ send();
308
+ }, [useComposer]);
309
+ if (disabled) return null;
310
+ return callback;
311
+ };
312
+
313
+ // src/primitive-hooks/contentPart/useContentPartDisplay.tsx
314
+ var useContentPartDisplay = () => {
315
+ const { useContentPart } = useContentPartContext();
316
+ const display = useContentPart((c) => {
317
+ if (c.part.type !== "ui")
318
+ throw new Error(
319
+ "This component can only be used inside ui content parts."
320
+ );
321
+ return c.part.display;
322
+ });
323
+ return display;
324
+ };
325
+
326
+ // src/primitive-hooks/contentPart/useContentPartImage.tsx
327
+ var useContentPartImage = () => {
328
+ const { useContentPart } = useContentPartContext();
329
+ const image = useContentPart((c) => {
330
+ if (c.part.type !== "image")
331
+ throw new Error(
332
+ "ContentPartImage can only be used inside image content parts."
333
+ );
334
+ return c.part.image;
335
+ });
336
+ return image;
337
+ };
338
+
339
+ // src/primitive-hooks/contentPart/useContentPartInProgressIndicator.tsx
340
+ var useContentPartInProgressIndicator = () => {
341
+ const { useMessageUtils } = useMessageContext();
342
+ const { useContentPart } = useContentPartContext();
343
+ const indicator = useCombinedStore(
344
+ [useMessageUtils, useContentPart],
345
+ (m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
346
+ );
347
+ return indicator;
348
+ };
349
+
350
+ // src/primitive-hooks/contentPart/useContentPartText.tsx
351
+ var useContentPartText = () => {
352
+ const { useContentPart } = useContentPartContext();
353
+ const text = useContentPart((c) => {
354
+ if (c.part.type !== "text")
355
+ throw new Error(
356
+ "ContentPartText can only be used inside text content parts."
357
+ );
358
+ return c.part.text;
359
+ });
360
+ return text;
361
+ };
362
+
363
+ // src/primitive-hooks/message/useMessageIf.tsx
364
+ var useMessageIf = (props) => {
365
+ const { useMessage, useMessageUtils } = useMessageContext();
366
+ return useCombinedStore(
367
+ [useMessage, useMessageUtils],
368
+ ({ message, branches, isLast }, { isCopied, isHovering }) => {
369
+ if (props.hasBranches === true && branches.length < 2) return false;
370
+ if (props.user && message.role !== "user") return false;
371
+ if (props.assistant && message.role !== "assistant") return false;
372
+ if (props.lastOrHover === true && !isHovering && !isLast) return false;
373
+ if (props.copied === true && !isCopied) return false;
374
+ if (props.copied === false && isCopied) return false;
375
+ return true;
376
+ }
377
+ );
378
+ };
379
+
380
+ // src/primitive-hooks/thread/useThreadIf.tsx
381
+ var useThreadIf = (props) => {
382
+ const { useThread } = useThreadContext();
383
+ return useThread((thread) => {
384
+ if (props.empty === true && thread.messages.length !== 0) return false;
385
+ if (props.empty === false && thread.messages.length === 0) return false;
386
+ if (props.running === true && !thread.isRunning) return false;
387
+ if (props.running === false && thread.isRunning) return false;
388
+ return true;
389
+ });
390
+ };
391
+
392
+ // src/primitive-hooks/thread/useThreadEmpty.tsx
393
+ var useThreadEmpty = () => {
394
+ return useThreadIf({ empty: true });
395
+ };
396
+
397
+ // src/primitive-hooks/thread/useThreadScrollToBottom.tsx
398
+ var import_react15 = require("react");
399
+ var useThreadScrollToBottom = () => {
400
+ const { useViewport } = useThreadContext();
401
+ const isAtBottom = useViewport((s) => s.isAtBottom);
402
+ const handleScrollToBottom = (0, import_react15.useCallback)(() => {
403
+ const { scrollToBottom } = useViewport.getState();
404
+ scrollToBottom();
405
+ }, [useViewport]);
406
+ if (isAtBottom) return null;
407
+ return handleScrollToBottom;
408
+ };
409
+
410
+ // src/primitive-hooks/thread/useThreadSuggestion.tsx
411
+ var import_react16 = require("react");
412
+ var useThreadSuggestion = ({
413
+ prompt,
414
+ autoSend
415
+ }) => {
416
+ const { useThread, useComposer } = useThreadContext();
417
+ const disabled = useThread((t) => t.isRunning);
418
+ const callback = (0, import_react16.useCallback)(() => {
419
+ const thread = useThread.getState();
420
+ const composer = useComposer.getState();
421
+ composer.setValue(prompt);
422
+ if (autoSend && !thread.isRunning) {
423
+ composer.send();
424
+ }
425
+ }, [useThread, useComposer, prompt, autoSend]);
426
+ if (disabled) return null;
427
+ return callback;
428
+ };
429
+
203
430
  // src/primitives/thread/index.ts
204
431
  var thread_exports = {};
205
432
  __export(thread_exports, {
@@ -214,9 +441,9 @@ __export(thread_exports, {
214
441
 
215
442
  // src/primitives/thread/ThreadRoot.tsx
216
443
  var import_react_primitive = require("@radix-ui/react-primitive");
217
- var import_react10 = require("react");
444
+ var import_react17 = require("react");
218
445
  var import_jsx_runtime = require("react/jsx-runtime");
219
- var ThreadRoot = (0, import_react10.forwardRef)(
446
+ var ThreadRoot = (0, import_react17.forwardRef)(
220
447
  (props, ref) => {
221
448
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.div, { ...props, ref });
222
449
  }
@@ -224,16 +451,6 @@ var ThreadRoot = (0, import_react10.forwardRef)(
224
451
  ThreadRoot.displayName = "ThreadRoot";
225
452
 
226
453
  // src/primitives/thread/ThreadIf.tsx
227
- var useThreadIf = (props) => {
228
- const { useThread } = useThreadContext();
229
- return useThread((thread) => {
230
- if (props.empty === true && thread.messages.length !== 0) return false;
231
- if (props.empty === false && thread.messages.length === 0) return false;
232
- if (props.running === true && !thread.isRunning) return false;
233
- if (props.running === false && thread.isRunning) return false;
234
- return true;
235
- });
236
- };
237
454
  var ThreadIf = ({ children, ...query }) => {
238
455
  const result = useThreadIf(query);
239
456
  return result ? children : null;
@@ -249,15 +466,15 @@ var ThreadEmpty = ({ children }) => {
249
466
  var import_primitive = require("@radix-ui/primitive");
250
467
  var import_react_compose_refs = require("@radix-ui/react-compose-refs");
251
468
  var import_react_primitive2 = require("@radix-ui/react-primitive");
252
- var import_react13 = require("react");
469
+ var import_react20 = require("react");
253
470
 
254
471
  // src/utils/hooks/useOnResizeContent.tsx
255
472
  var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
256
- var import_react11 = require("react");
473
+ var import_react18 = require("react");
257
474
  var useOnResizeContent = (ref, callback) => {
258
475
  const callbackRef = (0, import_react_use_callback_ref.useCallbackRef)(callback);
259
- const el = ref.current;
260
- (0, import_react11.useEffect)(() => {
476
+ (0, import_react18.useEffect)(() => {
477
+ const el = ref.current;
261
478
  if (!el) return;
262
479
  const resizeObserver = new ResizeObserver(() => {
263
480
  callbackRef();
@@ -286,16 +503,16 @@ var useOnResizeContent = (ref, callback) => {
286
503
  resizeObserver.disconnect();
287
504
  mutationObserver.disconnect();
288
505
  };
289
- }, [el, callbackRef]);
506
+ }, [ref, callbackRef]);
290
507
  };
291
508
 
292
509
  // src/utils/hooks/useOnScrollToBottom.tsx
293
510
  var import_react_use_callback_ref2 = require("@radix-ui/react-use-callback-ref");
294
- var import_react12 = require("react");
511
+ var import_react19 = require("react");
295
512
  var useOnScrollToBottom = (callback) => {
296
513
  const callbackRef = (0, import_react_use_callback_ref2.useCallbackRef)(callback);
297
514
  const { useViewport } = useThreadContext();
298
- (0, import_react12.useEffect)(() => {
515
+ (0, import_react19.useEffect)(() => {
299
516
  return useViewport.getState().onScrollToBottom(() => {
300
517
  callbackRef();
301
518
  });
@@ -304,14 +521,14 @@ var useOnScrollToBottom = (callback) => {
304
521
 
305
522
  // src/primitives/thread/ThreadViewport.tsx
306
523
  var import_jsx_runtime3 = require("react/jsx-runtime");
307
- var ThreadViewport = (0, import_react13.forwardRef)(({ autoScroll = true, onScroll, children, ...rest }, forwardedRef) => {
308
- const messagesEndRef = (0, import_react13.useRef)(null);
309
- const divRef = (0, import_react13.useRef)(null);
524
+ var ThreadViewport = (0, import_react20.forwardRef)(({ autoScroll = true, onScroll, children, ...rest }, forwardedRef) => {
525
+ const messagesEndRef = (0, import_react20.useRef)(null);
526
+ const divRef = (0, import_react20.useRef)(null);
310
527
  const ref = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, divRef);
311
528
  const { useViewport } = useThreadContext();
312
- const firstRenderRef = (0, import_react13.useRef)(true);
313
- const isScrollingToBottomRef = (0, import_react13.useRef)(false);
314
- const lastScrollTop = (0, import_react13.useRef)(0);
529
+ const firstRenderRef = (0, import_react20.useRef)(true);
530
+ const isScrollingToBottomRef = (0, import_react20.useRef)(false);
531
+ const lastScrollTop = (0, import_react20.useRef)(0);
315
532
  const scrollToBottom = () => {
316
533
  const div = messagesEndRef.current;
317
534
  if (!div || !autoScroll) return;
@@ -360,13 +577,13 @@ var ThreadViewport = (0, import_react13.forwardRef)(({ autoScroll = true, onScro
360
577
  ThreadViewport.displayName = "ThreadViewport";
361
578
 
362
579
  // src/primitives/thread/ThreadMessages.tsx
363
- var import_react16 = require("react");
580
+ var import_react22 = require("react");
364
581
 
365
582
  // src/context/providers/MessageProvider.tsx
366
- var import_react14 = require("react");
583
+ var import_react21 = require("react");
367
584
  var import_zustand3 = require("zustand");
368
585
 
369
- // src/context/stores/MessageComposer.ts
586
+ // src/context/stores/EditComposer.ts
370
587
  var import_zustand = require("zustand");
371
588
 
372
589
  // src/context/stores/BaseComposer.ts
@@ -377,7 +594,7 @@ var makeBaseComposer = (set) => ({
377
594
  }
378
595
  });
379
596
 
380
- // src/context/stores/MessageComposer.ts
597
+ // src/context/stores/EditComposer.ts
381
598
  var makeEditComposerStore = ({
382
599
  onEdit,
383
600
  onSend
@@ -440,10 +657,10 @@ var syncMessage = (thread, getBranches, useMessage, messageIndex) => {
440
657
  };
441
658
  var useMessageContext2 = (messageIndex) => {
442
659
  const { useThread, useThreadActions } = useThreadContext();
443
- const [context] = (0, import_react14.useState)(() => {
660
+ const [context] = (0, import_react21.useState)(() => {
444
661
  const useMessage = (0, import_zustand3.create)(() => ({}));
445
662
  const useMessageUtils = makeMessageUtilsStore();
446
- const useComposer = makeEditComposerStore({
663
+ const useEditComposer = makeEditComposerStore({
447
664
  onEdit: () => {
448
665
  const message = useMessage.getState().message;
449
666
  if (message.role !== "user")
@@ -474,9 +691,9 @@ var useMessageContext2 = (messageIndex) => {
474
691
  useMessage,
475
692
  messageIndex
476
693
  );
477
- return { useMessage, useMessageUtils, useComposer };
694
+ return { useMessage, useMessageUtils, useEditComposer };
478
695
  });
479
- (0, import_react14.useEffect)(() => {
696
+ (0, import_react21.useEffect)(() => {
480
697
  return useThread.subscribe((thread) => {
481
698
  syncMessage(
482
699
  thread,
@@ -496,50 +713,13 @@ var MessageProvider = ({
496
713
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MessageContext.Provider, { value: context, children });
497
714
  };
498
715
 
499
- // src/context/ComposerContext.ts
500
- var import_react15 = require("react");
501
- var useComposerContext = () => {
502
- const { useComposer } = useThreadContext();
503
- const { useComposer: useEditComposer } = (0, import_react15.useContext)(MessageContext) ?? {};
504
- return (0, import_react15.useMemo)(
505
- () => ({
506
- useComposer: useEditComposer ?? useComposer,
507
- type: useEditComposer ? "edit" : "new"
508
- }),
509
- [useEditComposer, useComposer]
510
- );
511
- };
512
-
513
716
  // src/primitives/composer/ComposerIf.tsx
514
- var useComposerIf = (props) => {
515
- const { useComposer } = useComposerContext();
516
- return useComposer((composer) => {
517
- if (props.editing === true && !composer.isEditing) return false;
518
- if (props.editing === false && composer.isEditing) return false;
519
- return true;
520
- });
521
- };
522
717
  var ComposerIf = ({ children, ...query }) => {
523
718
  const result = useComposerIf(query);
524
719
  return result ? children : null;
525
720
  };
526
721
 
527
722
  // src/primitives/message/MessageIf.tsx
528
- var useMessageIf = (props) => {
529
- const { useMessage, useMessageUtils } = useMessageContext();
530
- return useCombinedStore(
531
- [useMessage, useMessageUtils],
532
- ({ message, branches, isLast }, { isCopied, isHovering }) => {
533
- if (props.hasBranches === true && branches.length < 2) return false;
534
- if (props.user && message.role !== "user") return false;
535
- if (props.assistant && message.role !== "assistant") return false;
536
- if (props.lastOrHover === true && !isHovering && !isLast) return false;
537
- if (props.copied === true && !isCopied) return false;
538
- if (props.copied === false && isCopied) return false;
539
- return true;
540
- }
541
- );
542
- };
543
723
  var MessageIf = ({ children, ...query }) => {
544
724
  const result = useMessageIf(query);
545
725
  return result ? children : null;
@@ -567,7 +747,7 @@ var ThreadMessageImpl = ({
567
747
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MessageIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AssistantMessage, {}) })
568
748
  ] });
569
749
  };
570
- var ThreadMessage = (0, import_react16.memo)(
750
+ var ThreadMessage = (0, import_react22.memo)(
571
751
  ThreadMessageImpl,
572
752
  (prev, next) => prev.messageIndex === next.messageIndex && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
573
753
  );
@@ -588,56 +768,42 @@ var ThreadMessages = ({ components }) => {
588
768
  });
589
769
  };
590
770
 
591
- // src/primitives/thread/ThreadScrollToBottom.tsx
771
+ // src/utils/createActionButton.tsx
592
772
  var import_primitive2 = require("@radix-ui/primitive");
593
773
  var import_react_primitive3 = require("@radix-ui/react-primitive");
594
- var import_react17 = require("react");
774
+ var import_react23 = require("react");
595
775
  var import_jsx_runtime6 = require("react/jsx-runtime");
596
- var ThreadScrollToBottom = (0, import_react17.forwardRef)(({ onClick, ...rest }, ref) => {
597
- const { useViewport } = useThreadContext();
598
- const isAtBottom = useViewport((s) => s.isAtBottom);
599
- const handleScrollToBottom = () => {
600
- useViewport.getState().scrollToBottom();
601
- };
602
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
603
- import_react_primitive3.Primitive.button,
604
- {
605
- ...rest,
606
- disabled: isAtBottom,
607
- ref,
608
- onClick: (0, import_primitive2.composeEventHandlers)(onClick, handleScrollToBottom)
609
- }
610
- );
611
- });
612
- ThreadScrollToBottom.displayName = "ThreadScrollToBottom";
776
+ var createActionButton = (displayName, useActionButton) => {
777
+ const ActionButton = (0, import_react23.forwardRef)((props, forwardedRef) => {
778
+ const callback = useActionButton(props);
779
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
780
+ import_react_primitive3.Primitive.button,
781
+ {
782
+ type: "button",
783
+ disabled: !callback,
784
+ ...props,
785
+ ref: forwardedRef,
786
+ onClick: (0, import_primitive2.composeEventHandlers)(props.onClick, () => {
787
+ callback?.();
788
+ })
789
+ }
790
+ );
791
+ });
792
+ ActionButton.displayName = displayName;
793
+ return ActionButton;
794
+ };
795
+
796
+ // src/primitives/thread/ThreadScrollToBottom.tsx
797
+ var ThreadScrollToBottom = createActionButton(
798
+ "ThreadScrollToBottom",
799
+ useThreadScrollToBottom
800
+ );
613
801
 
614
802
  // src/primitives/thread/ThreadSuggestion.tsx
615
- var import_primitive3 = require("@radix-ui/primitive");
616
- var import_react_primitive4 = require("@radix-ui/react-primitive");
617
- var import_react18 = require("react");
618
- var import_jsx_runtime7 = require("react/jsx-runtime");
619
- var ThreadSuggestion = (0, import_react18.forwardRef)(({ onClick, prompt, method, autoSend: send, ...rest }, ref) => {
620
- const { useThread, useComposer } = useThreadContext();
621
- const isDisabled = useThread((t) => t.isRunning);
622
- const handleApplySuggestion = () => {
623
- const thread = useThread.getState();
624
- const composer = useComposer.getState();
625
- composer.setValue(prompt);
626
- if (send && !thread.isRunning) {
627
- composer.send();
628
- }
629
- };
630
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
631
- import_react_primitive4.Primitive.button,
632
- {
633
- ...rest,
634
- disabled: isDisabled,
635
- ref,
636
- onClick: (0, import_primitive3.composeEventHandlers)(onClick, handleApplySuggestion)
637
- }
638
- );
639
- });
640
- ThreadSuggestion.displayName = "ThreadSuggestion";
803
+ var ThreadSuggestion = createActionButton(
804
+ "ThreadSuggestion",
805
+ useThreadSuggestion
806
+ );
641
807
 
642
808
  // src/primitives/composer/index.ts
643
809
  var composer_exports = {};
@@ -650,16 +816,16 @@ __export(composer_exports, {
650
816
  });
651
817
 
652
818
  // src/primitives/composer/ComposerRoot.tsx
653
- var import_primitive4 = require("@radix-ui/primitive");
819
+ var import_primitive3 = require("@radix-ui/primitive");
654
820
  var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
655
- var import_react_primitive5 = require("@radix-ui/react-primitive");
656
- var import_react19 = require("react");
657
- var import_jsx_runtime8 = require("react/jsx-runtime");
658
- var ComposerRoot = (0, import_react19.forwardRef)(
821
+ var import_react_primitive4 = require("@radix-ui/react-primitive");
822
+ var import_react24 = require("react");
823
+ var import_jsx_runtime7 = require("react/jsx-runtime");
824
+ var ComposerRoot = (0, import_react24.forwardRef)(
659
825
  ({ onSubmit, ...rest }, forwardedRef) => {
660
826
  const { useViewport } = useThreadContext();
661
827
  const { useComposer } = useComposerContext();
662
- const formRef = (0, import_react19.useRef)(null);
828
+ const formRef = (0, import_react24.useRef)(null);
663
829
  const ref = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, formRef);
664
830
  const handleSubmit = (e) => {
665
831
  const composerState = useComposer.getState();
@@ -668,12 +834,12 @@ var ComposerRoot = (0, import_react19.forwardRef)(
668
834
  composerState.send();
669
835
  useViewport.getState().scrollToBottom();
670
836
  };
671
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
672
- import_react_primitive5.Primitive.form,
837
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
838
+ import_react_primitive4.Primitive.form,
673
839
  {
674
840
  ...rest,
675
841
  ref,
676
- onSubmit: (0, import_primitive4.composeEventHandlers)(onSubmit, handleSubmit)
842
+ onSubmit: (0, import_primitive3.composeEventHandlers)(onSubmit, handleSubmit)
677
843
  }
678
844
  );
679
845
  }
@@ -681,13 +847,13 @@ var ComposerRoot = (0, import_react19.forwardRef)(
681
847
  ComposerRoot.displayName = "ComposerRoot";
682
848
 
683
849
  // src/primitives/composer/ComposerInput.tsx
684
- var import_primitive5 = require("@radix-ui/primitive");
850
+ var import_primitive4 = require("@radix-ui/primitive");
685
851
  var import_react_compose_refs3 = require("@radix-ui/react-compose-refs");
686
852
  var import_react_slot = require("@radix-ui/react-slot");
687
- var import_react20 = require("react");
853
+ var import_react25 = require("react");
688
854
  var import_react_textarea_autosize = __toESM(require("react-textarea-autosize"));
689
- var import_jsx_runtime9 = require("react/jsx-runtime");
690
- var ComposerInput = (0, import_react20.forwardRef)(
855
+ var import_jsx_runtime8 = require("react/jsx-runtime");
856
+ var ComposerInput = (0, import_react25.forwardRef)(
691
857
  ({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
692
858
  const { useThread } = useThreadContext();
693
859
  const { useComposer, type } = useComposerContext();
@@ -696,7 +862,7 @@ var ComposerInput = (0, import_react20.forwardRef)(
696
862
  return c.value;
697
863
  });
698
864
  const Component = asChild ? import_react_slot.Slot : import_react_textarea_autosize.default;
699
- const textareaRef = (0, import_react20.useRef)(null);
865
+ const textareaRef = (0, import_react25.useRef)(null);
700
866
  const ref = (0, import_react_compose_refs3.useComposedRefs)(forwardedRef, textareaRef);
701
867
  const handleKeyPress = (e) => {
702
868
  if (disabled) return;
@@ -714,23 +880,22 @@ var ComposerInput = (0, import_react20.forwardRef)(
714
880
  }
715
881
  };
716
882
  const autoFocusEnabled = autoFocus && !disabled;
717
- const focus = (0, import_react20.useCallback)(() => {
883
+ const focus = (0, import_react25.useCallback)(() => {
718
884
  const textarea = textareaRef.current;
719
885
  if (!textarea || !autoFocusEnabled) return;
720
- console.log("focus");
721
886
  textarea.focus();
722
887
  textarea.setSelectionRange(
723
888
  textareaRef.current.value.length,
724
889
  textareaRef.current.value.length
725
890
  );
726
891
  }, [autoFocusEnabled]);
727
- (0, import_react20.useEffect)(() => focus(), [focus]);
892
+ (0, import_react25.useEffect)(() => focus(), [focus]);
728
893
  useOnScrollToBottom(() => {
729
894
  if (type === "new") {
730
895
  focus();
731
896
  }
732
897
  });
733
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
898
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
734
899
  Component,
735
900
  {
736
901
  value,
@@ -738,12 +903,12 @@ var ComposerInput = (0, import_react20.forwardRef)(
738
903
  ref,
739
904
  autoFocus,
740
905
  disabled,
741
- onChange: (0, import_primitive5.composeEventHandlers)(onChange, (e) => {
906
+ onChange: (0, import_primitive4.composeEventHandlers)(onChange, (e) => {
742
907
  const composerState = useComposer.getState();
743
908
  if (!composerState.isEditing) return;
744
909
  return composerState.setValue(e.target.value);
745
910
  }),
746
- onKeyDown: (0, import_primitive5.composeEventHandlers)(onKeyDown, handleKeyPress)
911
+ onKeyDown: (0, import_primitive4.composeEventHandlers)(onKeyDown, handleKeyPress)
747
912
  }
748
913
  );
749
914
  }
@@ -751,47 +916,13 @@ var ComposerInput = (0, import_react20.forwardRef)(
751
916
  ComposerInput.displayName = "ComposerInput";
752
917
 
753
918
  // src/primitives/composer/ComposerSend.tsx
754
- var import_react_primitive6 = require("@radix-ui/react-primitive");
755
- var import_react21 = require("react");
756
- var import_jsx_runtime10 = require("react/jsx-runtime");
757
- var ComposerSend = (0, import_react21.forwardRef)(
758
- ({ disabled, ...rest }, ref) => {
759
- const { useComposer } = useComposerContext();
760
- const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
761
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
762
- import_react_primitive6.Primitive.button,
763
- {
764
- type: "submit",
765
- ...rest,
766
- ref,
767
- disabled: disabled || !hasValue
768
- }
769
- );
770
- }
771
- );
772
- ComposerSend.displayName = "ComposerSend";
919
+ var ComposerSend = createActionButton("ComposerSend", useComposerSend);
773
920
 
774
921
  // src/primitives/composer/ComposerCancel.tsx
775
- var import_primitive6 = require("@radix-ui/primitive");
776
- var import_react_primitive7 = require("@radix-ui/react-primitive");
777
- var import_react22 = require("react");
778
- var import_jsx_runtime11 = require("react/jsx-runtime");
779
- var ComposerCancel = (0, import_react22.forwardRef)(({ onClick, ...rest }, ref) => {
780
- const { useComposer } = useComposerContext();
781
- const handleCancel = () => {
782
- useComposer.getState().cancel();
783
- };
784
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
785
- import_react_primitive7.Primitive.button,
786
- {
787
- type: "button",
788
- ...rest,
789
- ref,
790
- onClick: (0, import_primitive6.composeEventHandlers)(onClick, handleCancel)
791
- }
792
- );
793
- });
794
- ComposerCancel.displayName = "ComposerCancel";
922
+ var ComposerCancel = createActionButton(
923
+ "ComposerCancel",
924
+ useComposerCancel
925
+ );
795
926
 
796
927
  // src/primitives/message/index.ts
797
928
  var message_exports = {};
@@ -803,11 +934,11 @@ __export(message_exports, {
803
934
  });
804
935
 
805
936
  // src/primitives/message/MessageRoot.tsx
806
- var import_primitive7 = require("@radix-ui/primitive");
807
- var import_react_primitive8 = require("@radix-ui/react-primitive");
808
- var import_react23 = require("react");
809
- var import_jsx_runtime12 = require("react/jsx-runtime");
810
- var MessageRoot = (0, import_react23.forwardRef)(
937
+ var import_primitive5 = require("@radix-ui/primitive");
938
+ var import_react_primitive5 = require("@radix-ui/react-primitive");
939
+ var import_react26 = require("react");
940
+ var import_jsx_runtime9 = require("react/jsx-runtime");
941
+ var MessageRoot = (0, import_react26.forwardRef)(
811
942
  ({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
812
943
  const { useMessageUtils } = useMessageContext();
813
944
  const setIsHovering = useMessageUtils((s) => s.setIsHovering);
@@ -817,13 +948,13 @@ var MessageRoot = (0, import_react23.forwardRef)(
817
948
  const handleMouseLeave = () => {
818
949
  setIsHovering(false);
819
950
  };
820
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
821
- import_react_primitive8.Primitive.div,
951
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
952
+ import_react_primitive5.Primitive.div,
822
953
  {
823
954
  ...rest,
824
955
  ref,
825
- onMouseEnter: (0, import_primitive7.composeEventHandlers)(onMouseEnter, handleMouseEnter),
826
- onMouseLeave: (0, import_primitive7.composeEventHandlers)(onMouseLeave, handleMouseLeave)
956
+ onMouseEnter: (0, import_primitive5.composeEventHandlers)(onMouseEnter, handleMouseEnter),
957
+ onMouseLeave: (0, import_primitive5.composeEventHandlers)(onMouseLeave, handleMouseLeave)
827
958
  }
828
959
  );
829
960
  }
@@ -831,40 +962,12 @@ var MessageRoot = (0, import_react23.forwardRef)(
831
962
  MessageRoot.displayName = "MessageRoot";
832
963
 
833
964
  // src/primitives/message/MessageContent.tsx
834
- var import_react28 = require("react");
835
-
836
- // src/context/AssistantContext.ts
837
- var import_react24 = require("react");
838
- var AssistantContext = (0, import_react24.createContext)(
839
- null
840
- );
841
- var useAssistantContext = () => {
842
- const context = (0, import_react24.useContext)(AssistantContext);
843
- if (!context)
844
- throw new Error(
845
- "This component must be used within an AssistantRuntimeProvider."
846
- );
847
- return context;
848
- };
849
-
850
- // src/context/ContentPartContext.ts
851
- var import_react25 = require("react");
852
- var ContentPartContext = (0, import_react25.createContext)(
853
- null
854
- );
855
- var useContentPartContext = () => {
856
- const context = (0, import_react25.useContext)(ContentPartContext);
857
- if (!context)
858
- throw new Error(
859
- "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
860
- );
861
- return context;
862
- };
965
+ var import_react29 = require("react");
863
966
 
864
967
  // src/context/providers/ContentPartProvider.tsx
865
- var import_react26 = require("react");
968
+ var import_react27 = require("react");
866
969
  var import_zustand4 = require("zustand");
867
- var import_jsx_runtime13 = require("react/jsx-runtime");
970
+ var import_jsx_runtime10 = require("react/jsx-runtime");
868
971
  var syncContentPart = ({ message }, useContentPart, partIndex) => {
869
972
  const part = message.content[partIndex];
870
973
  if (!part) return;
@@ -881,14 +984,14 @@ var syncContentPart = ({ message }, useContentPart, partIndex) => {
881
984
  };
882
985
  var useContentPartContext2 = (partIndex) => {
883
986
  const { useMessage } = useMessageContext();
884
- const [context] = (0, import_react26.useState)(() => {
987
+ const [context] = (0, import_react27.useState)(() => {
885
988
  const useContentPart = (0, import_zustand4.create)(
886
989
  () => ({})
887
990
  );
888
991
  syncContentPart(useMessage.getState(), useContentPart, partIndex);
889
992
  return { useContentPart };
890
993
  });
891
- (0, import_react26.useEffect)(() => {
994
+ (0, import_react27.useEffect)(() => {
892
995
  syncContentPart(useMessage.getState(), context.useContentPart, partIndex);
893
996
  return useMessage.subscribe((message) => {
894
997
  syncContentPart(message, context.useContentPart, partIndex);
@@ -901,65 +1004,46 @@ var ContentPartProvider = ({
901
1004
  children
902
1005
  }) => {
903
1006
  const context = useContentPartContext2(partIndex);
904
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ContentPartContext.Provider, { value: context, children });
1007
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ContentPartContext.Provider, { value: context, children });
905
1008
  };
906
1009
 
907
1010
  // src/primitives/contentPart/ContentPartDisplay.tsx
908
1011
  var ContentPartDisplay = () => {
909
- const { useContentPart } = useContentPartContext();
910
- const display = useContentPart((c) => {
911
- if (c.part.type !== "ui")
912
- throw new Error(
913
- "ContentPartDisplay can only be used inside ui content parts."
914
- );
915
- return c.part.display;
916
- });
1012
+ const display = useContentPartDisplay();
917
1013
  return display ?? null;
918
1014
  };
919
1015
 
920
1016
  // src/primitives/contentPart/ContentPartInProgressIndicator.tsx
921
1017
  var ContentPartInProgressIndicator = () => {
922
- const { useMessageUtils } = useMessageContext();
923
- const { useContentPart } = useContentPartContext();
924
- const indicator = useCombinedStore(
925
- [useMessageUtils, useContentPart],
926
- (m, c) => c.status === "in_progress" ? m.inProgressIndicator : null
927
- );
1018
+ const indicator = useContentPartInProgressIndicator();
928
1019
  return indicator;
929
1020
  };
930
1021
 
931
1022
  // src/primitives/contentPart/ContentPartText.tsx
932
- var import_react_primitive9 = require("@radix-ui/react-primitive");
933
- var import_react27 = require("react");
934
- var import_jsx_runtime14 = require("react/jsx-runtime");
935
- var ContentPartText = (0, import_react27.forwardRef)((props, forwardedRef) => {
936
- const { useContentPart } = useContentPartContext();
937
- const text = useContentPart((c) => {
938
- if (c.part.type !== "text")
939
- throw new Error(
940
- "ContentPartText can only be used inside text content parts."
941
- );
942
- return c.part.text;
943
- });
944
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_primitive9.Primitive.span, { ...props, ref: forwardedRef, children: text });
1023
+ var import_react_primitive6 = require("@radix-ui/react-primitive");
1024
+ var import_react28 = require("react");
1025
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1026
+ var ContentPartText = (0, import_react28.forwardRef)((props, forwardedRef) => {
1027
+ const text = useContentPartText();
1028
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_primitive6.Primitive.span, { ...props, ref: forwardedRef, children: text });
945
1029
  });
946
1030
  ContentPartText.displayName = "ContentPartText";
947
1031
 
948
1032
  // src/primitives/message/MessageContent.tsx
949
- var import_jsx_runtime15 = require("react/jsx-runtime");
1033
+ var import_jsx_runtime12 = require("react/jsx-runtime");
950
1034
  var defaultComponents = {
951
- Text: () => /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
952
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ContentPartText, {}),
953
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ContentPartInProgressIndicator, {})
1035
+ Text: () => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1036
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ContentPartText, {}),
1037
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ContentPartInProgressIndicator, {})
954
1038
  ] }),
955
1039
  Image: () => null,
956
- UI: () => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ContentPartDisplay, {}),
1040
+ UI: () => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ContentPartDisplay, {}),
957
1041
  tools: {
958
1042
  Fallback: (props) => {
959
1043
  const { useToolUIs } = useAssistantContext();
960
1044
  const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));
961
1045
  if (!Render) return null;
962
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Render, { ...props });
1046
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Render, { ...props });
963
1047
  }
964
1048
  }
965
1049
  };
@@ -978,15 +1062,15 @@ var MessageContentPartComponent = ({
978
1062
  const type = part.type;
979
1063
  switch (type) {
980
1064
  case "text":
981
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Text, { part, status });
1065
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Text, { part, status });
982
1066
  case "image":
983
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Image, { part, status });
1067
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Image, { part, status });
984
1068
  case "ui":
985
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(UI, { part, status });
1069
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(UI, { part, status });
986
1070
  case "tool-call": {
987
1071
  const Tool = by_name[part.toolName] || Fallback;
988
1072
  const addResult = (result) => addToolResult(part.toolCallId, result);
989
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Tool, { part, status, addResult });
1073
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Tool, { part, status, addResult });
990
1074
  }
991
1075
  default:
992
1076
  throw new Error(`Unknown content part type: ${type}`);
@@ -996,9 +1080,9 @@ var MessageContentPartImpl = ({
996
1080
  partIndex,
997
1081
  components
998
1082
  }) => {
999
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ContentPartProvider, { partIndex, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(MessageContentPartComponent, { components }) });
1083
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ContentPartProvider, { partIndex, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MessageContentPartComponent, { components }) });
1000
1084
  };
1001
- var MessageContentPart = (0, import_react28.memo)(
1085
+ var MessageContentPart = (0, import_react29.memo)(
1002
1086
  MessageContentPartImpl,
1003
1087
  (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
1004
1088
  );
@@ -1007,7 +1091,7 @@ var MessageContent = ({ components }) => {
1007
1091
  const contentLength = useMessage((s) => s.message.content.length);
1008
1092
  return new Array(contentLength).fill(null).map((_, idx) => {
1009
1093
  const partIndex = idx;
1010
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1094
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1011
1095
  MessageContentPart,
1012
1096
  {
1013
1097
  partIndex,
@@ -1019,13 +1103,13 @@ var MessageContent = ({ components }) => {
1019
1103
  };
1020
1104
 
1021
1105
  // src/primitives/message/MessageInProgress.tsx
1022
- var import_react_primitive10 = require("@radix-ui/react-primitive");
1023
- var import_react29 = require("react");
1024
- var import_jsx_runtime16 = require("react/jsx-runtime");
1025
- var MessageInProgress = (0, import_react29.forwardRef)((props, ref) => {
1106
+ var import_react_primitive7 = require("@radix-ui/react-primitive");
1107
+ var import_react30 = require("react");
1108
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1109
+ var MessageInProgress = (0, import_react30.forwardRef)((props, ref) => {
1026
1110
  const { useMessageUtils } = useMessageContext();
1027
- (0, import_react29.useMemo)(() => {
1028
- useMessageUtils.getState().setInProgressIndicator(/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_primitive10.Primitive.span, { ...props, ref }));
1111
+ (0, import_react30.useMemo)(() => {
1112
+ useMessageUtils.getState().setInProgressIndicator(/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_primitive7.Primitive.span, { ...props, ref }));
1029
1113
  }, [useMessageUtils, props, ref]);
1030
1114
  return null;
1031
1115
  });
@@ -1041,57 +1125,38 @@ __export(branchPicker_exports, {
1041
1125
  Root: () => BranchPickerRoot
1042
1126
  });
1043
1127
 
1044
- // src/utils/createActionButton.tsx
1045
- var import_primitive8 = require("@radix-ui/primitive");
1046
- var import_react_primitive11 = require("@radix-ui/react-primitive");
1047
- var import_react30 = require("react");
1048
- var import_jsx_runtime17 = require("react/jsx-runtime");
1049
- var createActionButton = (useActionButton) => {
1050
- const ActionButton = (0, import_react30.forwardRef)((props, forwardedRef) => {
1051
- const onClick = useActionButton(props);
1052
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1053
- import_react_primitive11.Primitive.button,
1054
- {
1055
- type: "button",
1056
- disabled: !onClick,
1057
- ...props,
1058
- ref: forwardedRef,
1059
- onClick: (0, import_primitive8.composeEventHandlers)(props.onClick, onClick ?? void 0)
1060
- }
1061
- );
1062
- });
1063
- ActionButton.displayName = "ActionButton";
1064
- return ActionButton;
1065
- };
1066
-
1067
1128
  // src/primitives/branchPicker/BranchPickerNext.tsx
1068
- var BranchPickerNext = createActionButton(useGoToNextBranch);
1129
+ var BranchPickerNext = createActionButton(
1130
+ "BranchPickerNext",
1131
+ useBranchPickerNext
1132
+ );
1069
1133
 
1070
1134
  // src/primitives/branchPicker/BranchPickerPrevious.tsx
1071
- var BranchPickerPrevious = createActionButton(useGoToPreviousBranch);
1135
+ var BranchPickerPrevious = createActionButton(
1136
+ "BranchPickerPrevious",
1137
+ useBranchPickerPrevious
1138
+ );
1072
1139
 
1073
1140
  // src/primitives/branchPicker/BranchPickerCount.tsx
1074
- var import_jsx_runtime18 = require("react/jsx-runtime");
1141
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1075
1142
  var BranchPickerCount = () => {
1076
- const { useMessage } = useMessageContext();
1077
- const branchCount = useMessage((s) => s.branches.length);
1078
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_jsx_runtime18.Fragment, { children: branchCount });
1143
+ const branchCount = useBranchPickerCount();
1144
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: branchCount });
1079
1145
  };
1080
1146
 
1081
1147
  // src/primitives/branchPicker/BranchPickerNumber.tsx
1082
- var import_jsx_runtime19 = require("react/jsx-runtime");
1148
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1083
1149
  var BranchPickerNumber = () => {
1084
- const { useMessage } = useMessageContext();
1085
- const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
1086
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_jsx_runtime19.Fragment, { children: branchIdx + 1 });
1150
+ const branchNumber = useBranchPickerNumber();
1151
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: branchNumber });
1087
1152
  };
1088
1153
 
1089
1154
  // src/primitives/branchPicker/BranchPickerRoot.tsx
1090
- var import_react_primitive12 = require("@radix-ui/react-primitive");
1155
+ var import_react_primitive8 = require("@radix-ui/react-primitive");
1091
1156
  var import_react31 = require("react");
1092
- var import_jsx_runtime20 = require("react/jsx-runtime");
1157
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1093
1158
  var BranchPickerRoot = (0, import_react31.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
1094
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_react_primitive12.Primitive.div, { ...rest, ref }) });
1159
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(MessageIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_primitive8.Primitive.div, { ...rest, ref }) });
1095
1160
  });
1096
1161
  BranchPickerRoot.displayName = "BranchPickerRoot";
1097
1162
 
@@ -1105,13 +1170,17 @@ __export(actionBar_exports, {
1105
1170
  });
1106
1171
 
1107
1172
  // src/primitives/actionBar/ActionBarRoot.tsx
1108
- var import_react_primitive13 = require("@radix-ui/react-primitive");
1173
+ var import_react_primitive9 = require("@radix-ui/react-primitive");
1109
1174
  var import_react32 = require("react");
1110
- var import_jsx_runtime21 = require("react/jsx-runtime");
1111
- var ActionBarRoot = (0, import_react32.forwardRef)(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
1175
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1176
+ var useActionBarFloatStatus = ({
1177
+ hideWhenRunning,
1178
+ autohide,
1179
+ autohideFloat
1180
+ }) => {
1112
1181
  const { useThread } = useThreadContext();
1113
1182
  const { useMessage, useMessageUtils } = useMessageContext();
1114
- const hideAndfloatStatus = useCombinedStore(
1183
+ return useCombinedStore(
1115
1184
  [useThread, useMessage, useMessageUtils],
1116
1185
  (t, m, mu) => {
1117
1186
  if (hideWhenRunning && t.isRunning) return "hidden" /* Hidden */;
@@ -1123,9 +1192,16 @@ var ActionBarRoot = (0, import_react32.forwardRef)(({ hideWhenRunning, autohide,
1123
1192
  return "normal" /* Normal */;
1124
1193
  }
1125
1194
  );
1195
+ };
1196
+ var ActionBarRoot = (0, import_react32.forwardRef)(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
1197
+ const hideAndfloatStatus = useActionBarFloatStatus({
1198
+ hideWhenRunning,
1199
+ autohide,
1200
+ autohideFloat
1201
+ });
1126
1202
  if (hideAndfloatStatus === "hidden" /* Hidden */) return null;
1127
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1128
- import_react_primitive13.Primitive.div,
1203
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1204
+ import_react_primitive9.Primitive.div,
1129
1205
  {
1130
1206
  ...hideAndfloatStatus === "floating" /* Floating */ ? { "data-floating": "true" } : null,
1131
1207
  ...rest,
@@ -1136,13 +1212,22 @@ var ActionBarRoot = (0, import_react32.forwardRef)(({ hideWhenRunning, autohide,
1136
1212
  ActionBarRoot.displayName = "ActionBarRoot";
1137
1213
 
1138
1214
  // src/primitives/actionBar/ActionBarCopy.tsx
1139
- var ActionBarCopy = createActionButton(useCopyMessage);
1215
+ var ActionBarCopy = createActionButton(
1216
+ "ActionBarCopy",
1217
+ useActionBarCopy
1218
+ );
1140
1219
 
1141
1220
  // src/primitives/actionBar/ActionBarReload.tsx
1142
- var ActionBarReload = createActionButton(useReloadMessage);
1221
+ var ActionBarReload = createActionButton(
1222
+ "ActionBarReload",
1223
+ useActionBarReload
1224
+ );
1143
1225
 
1144
1226
  // src/primitives/actionBar/ActionBarEdit.tsx
1145
- var ActionBarEdit = createActionButton(useBeginMessageEdit);
1227
+ var ActionBarEdit = createActionButton(
1228
+ "ActionBarEdit",
1229
+ useActionBarEdit
1230
+ );
1146
1231
 
1147
1232
  // src/primitives/contentPart/index.ts
1148
1233
  var contentPart_exports = {};
@@ -1154,19 +1239,12 @@ __export(contentPart_exports, {
1154
1239
  });
1155
1240
 
1156
1241
  // src/primitives/contentPart/ContentPartImage.tsx
1157
- var import_react_primitive14 = require("@radix-ui/react-primitive");
1242
+ var import_react_primitive10 = require("@radix-ui/react-primitive");
1158
1243
  var import_react33 = require("react");
1159
- var import_jsx_runtime22 = require("react/jsx-runtime");
1244
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1160
1245
  var ContentPartImage = (0, import_react33.forwardRef)((props, forwardedRef) => {
1161
- const { useContentPart } = useContentPartContext();
1162
- const image = useContentPart((c) => {
1163
- if (c.part.type !== "image")
1164
- throw new Error(
1165
- "ContentPartImage can only be used inside image content parts."
1166
- );
1167
- return c.part.image;
1168
- });
1169
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react_primitive14.Primitive.img, { src: image, ...props, ref: forwardedRef });
1246
+ const image = useContentPartImage();
1247
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_primitive10.Primitive.img, { src: image, ...props, ref: forwardedRef });
1170
1248
  });
1171
1249
  ContentPartImage.displayName = "ContentPartImage";
1172
1250
 
@@ -1603,7 +1681,7 @@ var makeThreadActionStore = (runtimeRef) => {
1603
1681
  };
1604
1682
 
1605
1683
  // src/context/providers/ThreadProvider.tsx
1606
- var import_jsx_runtime23 = require("react/jsx-runtime");
1684
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1607
1685
  var ThreadProvider = ({
1608
1686
  children,
1609
1687
  runtime
@@ -1638,14 +1716,14 @@ var ThreadProvider = ({
1638
1716
  return runtime.subscribe(onRuntimeUpdate);
1639
1717
  }, [context, runtime]);
1640
1718
  const RuntimeSynchronizer = runtime.unstable_synchronizer;
1641
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(ThreadContext.Provider, { value: context, children: [
1642
- RuntimeSynchronizer && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(RuntimeSynchronizer, {}),
1719
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(ThreadContext.Provider, { value: context, children: [
1720
+ RuntimeSynchronizer && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(RuntimeSynchronizer, {}),
1643
1721
  children
1644
1722
  ] });
1645
1723
  };
1646
1724
 
1647
1725
  // src/context/providers/AssistantProvider.tsx
1648
- var import_jsx_runtime24 = require("react/jsx-runtime");
1726
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1649
1727
  var AssistantProvider = ({ children, runtime }) => {
1650
1728
  const runtimeRef = (0, import_react36.useRef)(runtime);
1651
1729
  (0, import_react36.useInsertionEffect)(() => {
@@ -1660,13 +1738,13 @@ var AssistantProvider = ({ children, runtime }) => {
1660
1738
  (0, import_react36.useEffect)(() => {
1661
1739
  return runtime.registerModelConfigProvider(getModelCOnfig);
1662
1740
  }, [runtime, getModelCOnfig]);
1663
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ThreadProvider, { runtime, children }) });
1741
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ThreadProvider, { runtime, children }) });
1664
1742
  };
1665
1743
 
1666
1744
  // src/context/providers/AssistantRuntimeProvider.tsx
1667
- var import_jsx_runtime25 = require("react/jsx-runtime");
1745
+ var import_jsx_runtime21 = require("react/jsx-runtime");
1668
1746
  var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
1669
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(AssistantProvider, { runtime, children });
1747
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(AssistantProvider, { runtime, children });
1670
1748
  };
1671
1749
  var AssistantRuntimeProvider = (0, import_react37.memo)(AssistantRuntimeProviderImpl);
1672
1750
 
@@ -1686,11 +1764,25 @@ __export(internal_exports, {
1686
1764
  INTERNAL,
1687
1765
  MessagePrimitive,
1688
1766
  ThreadPrimitive,
1689
- useBeginMessageEdit,
1690
- useCopyMessage,
1691
- useGoToNextBranch,
1692
- useGoToPreviousBranch,
1767
+ useActionBarCopy,
1768
+ useActionBarEdit,
1769
+ useActionBarReload,
1770
+ useBranchPickerCount,
1771
+ useBranchPickerNext,
1772
+ useBranchPickerNumber,
1773
+ useBranchPickerPrevious,
1774
+ useComposerCancel,
1775
+ useComposerIf,
1776
+ useComposerSend,
1777
+ useContentPartDisplay,
1778
+ useContentPartImage,
1779
+ useContentPartInProgressIndicator,
1780
+ useContentPartText,
1693
1781
  useLocalRuntime,
1694
- useReloadMessage
1782
+ useMessageIf,
1783
+ useThreadEmpty,
1784
+ useThreadIf,
1785
+ useThreadScrollToBottom,
1786
+ useThreadSuggestion
1695
1787
  });
1696
1788
  //# sourceMappingURL=index.js.map