@assistant-ui/react 0.5.52 → 0.5.55

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- var _chunk4LR4BB23js = require('./chunk-4LR4BB23.js');
13
+ var _chunkCWAZOKEWjs = require('./chunk-CWAZOKEW.js');
14
14
 
15
15
 
16
16
  var _chunkDCHYNTHIjs = require('./chunk-DCHYNTHI.js');
@@ -23,56 +23,76 @@ var _react = require('react');
23
23
 
24
24
  // src/context/react/AssistantContext.ts
25
25
 
26
- var AssistantContext = _react.createContext.call(void 0,
27
- null
28
- );
29
- function useAssistantContext(options) {
30
- const context = _react.useContext.call(void 0, AssistantContext);
31
- if (!_optionalChain([options, 'optionalAccess', _2 => _2.optional]) && !context)
32
- throw new Error(
33
- "This component must be used within an AssistantRuntimeProvider."
34
- );
35
- return context;
36
- }
37
26
 
38
- // src/context/stores/AssistantModelConfig.ts
39
- var _zustand = require('zustand');
27
+ // src/context/react/utils/createContextHook.ts
40
28
 
41
- // src/utils/ProxyConfigProvider.ts
42
- var ProxyConfigProvider = (_class = class {constructor() { _class.prototype.__init.call(this); }
43
- __init() {this._providers = /* @__PURE__ */ new Set()}
44
- getModelConfig() {
45
- return _chunk4LR4BB23js.mergeModelConfigs.call(void 0, this._providers);
46
- }
47
- registerModelConfigProvider(provider) {
48
- this._providers.add(provider);
49
- return () => {
50
- this._providers.delete(provider);
51
- };
29
+ function createContextHook(context, providerName) {
30
+ function useContextHook(options) {
31
+ const contextValue = _react.useContext.call(void 0, context);
32
+ if (!_optionalChain([options, 'optionalAccess', _2 => _2.optional]) && !contextValue) {
33
+ throw new Error(`This component must be used within ${providerName}.`);
34
+ }
35
+ return contextValue;
52
36
  }
53
- }, _class);
37
+ return useContextHook;
38
+ }
54
39
 
55
- // src/context/stores/AssistantModelConfig.ts
56
- var makeAssistantModelConfigStore = () => _zustand.create.call(void 0, () => {
57
- const proxy = new ProxyConfigProvider();
58
- return Object.freeze({
59
- getModelConfig: () => {
60
- return proxy.getModelConfig();
61
- },
62
- registerModelConfigProvider: (provider) => {
63
- return proxy.registerModelConfigProvider(provider);
40
+ // src/context/react/utils/createContextStoreHook.ts
41
+ function createContextStoreHook(contextHook, contextKey) {
42
+ function useStoreStoreHook(options) {
43
+ const context = contextHook(options);
44
+ if (!context) {
45
+ if (!_optionalChain([options, 'optionalAccess', _3 => _3.optional])) {
46
+ throw new Error(`This component must be used within a ${contextKey}.`);
47
+ }
48
+ return null;
64
49
  }
65
- });
66
- });
50
+ return context[contextKey];
51
+ }
52
+ function useStoreHook(param) {
53
+ let optional = false;
54
+ let selector;
55
+ if (typeof param === "function") {
56
+ selector = param;
57
+ } else if (param && typeof param === "object") {
58
+ optional = !!param.optional;
59
+ selector = param.selector;
60
+ }
61
+ const store = useStoreStoreHook({
62
+ optional
63
+ });
64
+ if (!store) return null;
65
+ return selector ? store(selector) : store();
66
+ }
67
+ return {
68
+ [contextKey]: useStoreHook,
69
+ [`${contextKey}Store`]: useStoreStoreHook
70
+ };
71
+ }
67
72
 
68
- // src/context/stores/AssistantToolUIs.ts
73
+ // src/context/react/AssistantContext.ts
74
+ var AssistantContext = _react.createContext.call(void 0,
75
+ null
76
+ );
77
+ var useAssistantContext = createContextHook(
78
+ AssistantContext,
79
+ "AssistantRuntimeProvider"
80
+ );
81
+ var { useAssistantRuntime, useAssistantRuntimeStore } = createContextStoreHook(useAssistantContext, "useAssistantRuntime");
82
+ var { useToolUIs, useToolUIsStore } = createContextStoreHook(
83
+ useAssistantContext,
84
+ "useToolUIs"
85
+ );
86
+ var { useAssistantActions, useAssistantActionsStore } = createContextStoreHook(useAssistantContext, "useAssistantActions");
69
87
 
88
+ // src/context/stores/AssistantToolUIs.ts
89
+ var _zustand = require('zustand');
70
90
  var makeAssistantToolUIsStore = () => _zustand.create.call(void 0, (set) => {
71
91
  const renderers = /* @__PURE__ */ new Map();
72
92
  return Object.freeze({
73
93
  getToolUI: (name) => {
74
94
  const arr = renderers.get(name);
75
- const last = _optionalChain([arr, 'optionalAccess', _3 => _3.at, 'call', _4 => _4(-1)]);
95
+ const last = _optionalChain([arr, 'optionalAccess', _4 => _4.at, 'call', _5 => _5(-1)]);
76
96
  if (last) return last;
77
97
  return null;
78
98
  },
@@ -103,22 +123,34 @@ var makeAssistantToolUIsStore = () => _zustand.create.call(void 0, (set) => {
103
123
  // src/context/react/ThreadContext.ts
104
124
 
105
125
  var ThreadContext = _react.createContext.call(void 0, null);
106
- function useThreadContext(options) {
107
- const context = _react.useContext.call(void 0, ThreadContext);
108
- if (!_optionalChain([options, 'optionalAccess', _5 => _5.optional]) && !context)
109
- throw new Error(
110
- "This component must be used within an AssistantRuntimeProvider."
111
- );
112
- return context;
113
- }
114
-
115
- // src/context/stores/Composer.ts
116
-
117
- var makeComposerStore = (useThreadRuntime) => {
126
+ var useThreadContext = createContextHook(
127
+ ThreadContext,
128
+ "AssistantRuntimeProvider"
129
+ );
130
+ var { useThreadRuntime, useThreadRuntimeStore } = createContextStoreHook(useThreadContext, "useThreadRuntime");
131
+ var { useThread, useThreadStore } = createContextStoreHook(
132
+ useThreadContext,
133
+ "useThread"
134
+ );
135
+ var { useThreadMessages, useThreadMessagesStore } = createContextStoreHook(useThreadContext, "useThreadMessages");
136
+ var { useThreadActions, useThreadActionsStore } = createContextStoreHook(useThreadContext, "useThreadActions");
137
+ var {
138
+ useComposer: useThreadComposer,
139
+ useComposerStore: useThreadComposerStore
140
+ } = createContextStoreHook(useThreadContext, "useComposer");
141
+ var {
142
+ useViewport: useThreadViewport,
143
+ useViewportStore: useThreadViewportStore
144
+ } = createContextStoreHook(useThreadContext, "useViewport");
145
+
146
+ // src/context/stores/ThreadComposer.ts
147
+
148
+ var makeThreadComposerStore = (useThreadRuntime2) => {
118
149
  const focusListeners = /* @__PURE__ */ new Set();
119
150
  return _zustand.create.call(void 0, )((_, get) => {
120
- const runtime = useThreadRuntime.getState();
151
+ const runtime = useThreadRuntime2.getState();
121
152
  return {
153
+ type: "thread",
122
154
  get value() {
123
155
  return get().text;
124
156
  },
@@ -127,27 +159,27 @@ var makeComposerStore = (useThreadRuntime) => {
127
159
  },
128
160
  attachments: runtime.composer.attachments,
129
161
  addAttachment: (file) => {
130
- useThreadRuntime.getState().composer.addAttachment(file);
162
+ useThreadRuntime2.getState().composer.addAttachment(file);
131
163
  },
132
164
  removeAttachment: (attachmentId) => {
133
- useThreadRuntime.getState().composer.removeAttachment(attachmentId);
165
+ useThreadRuntime2.getState().composer.removeAttachment(attachmentId);
134
166
  },
135
167
  reset: () => {
136
- useThreadRuntime.getState().composer.reset();
168
+ useThreadRuntime2.getState().composer.reset();
137
169
  },
138
170
  text: runtime.composer.text,
139
171
  setText: (text) => {
140
- useThreadRuntime.getState().composer.setText(text);
172
+ useThreadRuntime2.getState().composer.setText(text);
141
173
  },
142
174
  canCancel: runtime.capabilities.cancel,
143
175
  isEditing: true,
144
176
  isEmpty: runtime.composer.isEmpty,
145
177
  send: () => {
146
- const runtime2 = useThreadRuntime.getState();
178
+ const runtime2 = useThreadRuntime2.getState();
147
179
  runtime2.composer.send();
148
180
  },
149
181
  cancel: () => {
150
- useThreadRuntime.getState().cancelRun();
182
+ useThreadRuntime2.getState().cancelRun();
151
183
  },
152
184
  focus: () => {
153
185
  for (const listener of focusListeners) {
@@ -252,8 +284,8 @@ var subscribeToMainThread = (runtime, callback) => {
252
284
 
253
285
 
254
286
  // src/runtimes/core/BaseAssistantRuntime.tsx
255
- var BaseAssistantRuntime = (_class2 = class {
256
- constructor(_thread) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);
287
+ var BaseAssistantRuntime = (_class = class {
288
+ constructor(_thread) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
257
289
  this._thread = _thread;
258
290
  this._thread = _thread;
259
291
  }
@@ -264,15 +296,15 @@ var BaseAssistantRuntime = (_class2 = class {
264
296
  this._thread = thread;
265
297
  this.subscriptionHandler();
266
298
  }
267
- __init2() {this._subscriptions = /* @__PURE__ */ new Set()}
299
+ __init() {this._subscriptions = /* @__PURE__ */ new Set()}
268
300
  subscribe(callback) {
269
301
  this._subscriptions.add(callback);
270
302
  return () => this._subscriptions.delete(callback);
271
303
  }
272
- __init3() {this.subscriptionHandler = () => {
304
+ __init2() {this.subscriptionHandler = () => {
273
305
  for (const callback of this._subscriptions) callback();
274
306
  }}
275
- }, _class2);
307
+ }, _class);
276
308
 
277
309
  // src/internal.ts
278
310
  var internal_exports = {};
@@ -289,13 +321,13 @@ _chunkDCHYNTHIjs.__export.call(void 0, internal_exports, {
289
321
  });
290
322
 
291
323
  // src/runtimes/utils/ThreadRuntimeComposer.tsx
292
- var ThreadRuntimeComposer = (_class3 = class {
293
- constructor(runtime, notifySubscribers) {;_class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);
324
+ var ThreadRuntimeComposer = (_class2 = class {
325
+ constructor(runtime, notifySubscribers) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);
294
326
  this.runtime = runtime;
295
327
  this.notifySubscribers = notifySubscribers;
296
328
  }
297
329
 
298
- __init4() {this.attachmentAccept = "*"}
330
+ __init3() {this.attachmentAccept = "*"}
299
331
  get isEmpty() {
300
332
  return !this.text.trim() && !this.attachments.length;
301
333
  }
@@ -308,7 +340,7 @@ var ThreadRuntimeComposer = (_class3 = class {
308
340
  }
309
341
  return false;
310
342
  }
311
- __init5() {this._attachments = []}
343
+ __init4() {this._attachments = []}
312
344
  get attachments() {
313
345
  return this._attachments;
314
346
  }
@@ -329,7 +361,7 @@ var ThreadRuntimeComposer = (_class3 = class {
329
361
  this._attachments = this._attachments.toSpliced(index, 1);
330
362
  this.notifySubscribers();
331
363
  }
332
- __init6() {this._text = ""}
364
+ __init5() {this._text = ""}
333
365
  get text() {
334
366
  return this._text;
335
367
  }
@@ -356,6 +388,20 @@ var ThreadRuntimeComposer = (_class3 = class {
356
388
  });
357
389
  this.reset();
358
390
  }
391
+ }, _class2);
392
+
393
+ // src/utils/ProxyConfigProvider.ts
394
+ var ProxyConfigProvider = (_class3 = class {constructor() { _class3.prototype.__init6.call(this); }
395
+ __init6() {this._providers = /* @__PURE__ */ new Set()}
396
+ getModelConfig() {
397
+ return _chunkCWAZOKEWjs.mergeModelConfigs.call(void 0, this._providers);
398
+ }
399
+ registerModelConfigProvider(provider) {
400
+ this._providers.add(provider);
401
+ return () => {
402
+ this._providers.delete(provider);
403
+ };
404
+ }
359
405
  }, _class3);
360
406
 
361
407
  // src/utils/idUtils.tsx
@@ -373,7 +419,8 @@ var fromCoreMessages = (message) => {
373
419
  };
374
420
  var fromCoreMessage = (message, {
375
421
  id = generateId(),
376
- status = { type: "complete", reason: "unknown" }
422
+ status = { type: "complete", reason: "unknown" },
423
+ attachments = []
377
424
  } = {}) => {
378
425
  const commonProps = {
379
426
  id,
@@ -401,7 +448,7 @@ var fromCoreMessage = (message, {
401
448
  ...commonProps,
402
449
  role,
403
450
  content: message.content,
404
- attachments: []
451
+ attachments
405
452
  };
406
453
  case "system":
407
454
  return {
@@ -608,6 +655,7 @@ var MessageRepository = (_class4 = class {constructor() { _class4.prototype.__in
608
655
 
609
656
  // src/utils/smooth/useSmooth.tsx
610
657
 
658
+ var _reactusecallbackref = require('@radix-ui/react-use-callback-ref');
611
659
 
612
660
  // src/utils/smooth/SmoothContext.tsx
613
661
 
@@ -617,6 +665,22 @@ var MessageRepository = (_class4 = class {constructor() { _class4.prototype.__in
617
665
 
618
666
 
619
667
 
668
+
669
+ // src/context/react/ContentPartContext.ts
670
+
671
+ var ContentPartContext = _react.createContext.call(void 0,
672
+ null
673
+ );
674
+ var useContentPartContext = createContextHook(
675
+ ContentPartContext,
676
+ "a component passed to <MessagePrimitive.Content components={...}>"
677
+ );
678
+ var { useContentPart, useContentPartStore } = createContextStoreHook(
679
+ useContentPartContext,
680
+ "useContentPart"
681
+ );
682
+
683
+ // src/utils/smooth/SmoothContext.tsx
620
684
  var _jsxruntime = require('react/jsx-runtime');
621
685
  var SmoothContext = _react.createContext.call(void 0, null);
622
686
  var makeSmoothContext = (initialState) => {
@@ -625,9 +689,9 @@ var makeSmoothContext = (initialState) => {
625
689
  };
626
690
  var SmoothContextProvider = ({ children }) => {
627
691
  const outer = useSmoothContext({ optional: true });
628
- const { useContentPart } = useContentPartContext();
692
+ const contentPartStore = useContentPartStore();
629
693
  const [context] = _react.useState.call(void 0,
630
- () => makeSmoothContext(useContentPart.getState().status)
694
+ () => makeSmoothContext(contentPartStore.getState().status)
631
695
  );
632
696
  if (outer) return children;
633
697
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SmoothContext.Provider, { value: context, children });
@@ -647,13 +711,17 @@ function useSmoothContext(options) {
647
711
  );
648
712
  return context;
649
713
  }
650
- var useSmoothStatus = () => {
651
- const { useSmoothStatus: useSmoothStatus2 } = useSmoothContext();
652
- return useSmoothStatus2();
714
+ var { useSmoothStatus, useSmoothStatusStore } = createContextStoreHook(
715
+ useSmoothContext,
716
+ "useSmoothStatus"
717
+ );
718
+
719
+ // src/context/ReadonlyStore.ts
720
+ var writableStore = (store) => {
721
+ return store;
653
722
  };
654
723
 
655
724
  // src/utils/smooth/useSmooth.tsx
656
- var _reactusecallbackref = require('@radix-ui/react-use-callback-ref');
657
725
  var TextStreamAnimator = (_class5 = class {
658
726
  constructor(currentText, setText) {;_class5.prototype.__init10.call(this);_class5.prototype.__init11.call(this);_class5.prototype.__init12.call(this);_class5.prototype.__init13.call(this);
659
727
  this.currentText = currentText;
@@ -702,21 +770,28 @@ var SMOOTH_STATUS = Object.freeze({
702
770
  type: "running"
703
771
  });
704
772
  var useSmooth = (state, smooth = false) => {
705
- const { useSmoothStatus: useSmoothStatus2 } = _nullishCoalesce(useSmoothContext({ optional: true }), () => ( {}));
706
773
  const {
707
774
  part: { text }
708
775
  } = state;
709
- const { useMessage } = useMessageContext();
710
776
  const id = useMessage((m) => m.message.id);
711
777
  const idRef = _react.useRef.call(void 0, id);
712
778
  const [displayedText, setDisplayedText] = _react.useState.call(void 0, text);
779
+ const smoothStatusStore = useSmoothStatusStore({ optional: true });
713
780
  const setText = _reactusecallbackref.useCallbackRef.call(void 0, (text2) => {
714
781
  setDisplayedText(text2);
715
- _optionalChain([useSmoothStatus2, 'optionalAccess', _31 => _31.setState, 'call', _32 => _32(text2 !== state.part.text ? SMOOTH_STATUS : state.status)]);
782
+ if (smoothStatusStore) {
783
+ writableStore(smoothStatusStore).setState(
784
+ text2 !== state.part.text ? SMOOTH_STATUS : state.status
785
+ );
786
+ }
716
787
  });
717
788
  _react.useEffect.call(void 0, () => {
718
- _optionalChain([useSmoothStatus2, 'optionalAccess', _33 => _33.setState, 'call', _34 => _34(text !== displayedText ? SMOOTH_STATUS : state.status)]);
719
- }, [useSmoothStatus2, text, displayedText, state.status]);
789
+ if (smoothStatusStore) {
790
+ writableStore(smoothStatusStore).setState(
791
+ text !== state.part.text ? SMOOTH_STATUS : state.status
792
+ );
793
+ }
794
+ }, [smoothStatusStore, text, displayedText, state.status, state.part.text]);
720
795
  const [animatorRef] = _react.useState.call(void 0,
721
796
  new TextStreamAnimator(text, setText)
722
797
  );
@@ -909,7 +984,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
909
984
  });
910
985
  if (mergeRoundtrips) {
911
986
  const previousMessage = messages[messages.length - 1];
912
- if (_optionalChain([previousMessage, 'optionalAccess', _35 => _35.role]) === "assistant") {
987
+ if (_optionalChain([previousMessage, 'optionalAccess', _31 => _31.role]) === "assistant") {
913
988
  previousMessage.content.push(...newContent);
914
989
  break;
915
990
  }
@@ -922,7 +997,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
922
997
  }
923
998
  case "tool": {
924
999
  const previousMessage = messages[messages.length - 1];
925
- if (_optionalChain([previousMessage, 'optionalAccess', _36 => _36.role]) !== "assistant")
1000
+ if (_optionalChain([previousMessage, 'optionalAccess', _32 => _32.role]) !== "assistant")
926
1001
  throw new Error(
927
1002
  "A tool message must be preceded by an assistant message."
928
1003
  );
@@ -998,14 +1073,14 @@ function streamPartDecoderStream() {
998
1073
  controller.enqueue(decodeStreamPart(chunk));
999
1074
  }
1000
1075
  });
1001
- return new (0, _chunk4LR4BB23js.PipeableTransformStream)((readable) => {
1076
+ return new (0, _chunkCWAZOKEWjs.PipeableTransformStream)((readable) => {
1002
1077
  return readable.pipeThrough(new TextDecoderStream()).pipeThrough(chunkByLineStream()).pipeThrough(decodeStream);
1003
1078
  });
1004
1079
  }
1005
1080
 
1006
1081
  // src/runtimes/edge/streams/utils/index.ts
1007
1082
  var streamUtils = {
1008
- streamPartEncoderStream: _chunk4LR4BB23js.streamPartEncoderStream,
1083
+ streamPartEncoderStream: _chunkCWAZOKEWjs.streamPartEncoderStream,
1009
1084
  streamPartDecoderStream
1010
1085
  };
1011
1086
 
@@ -1114,8 +1189,8 @@ var EdgeChatAdapter = class {
1114
1189
  credentials: _nullishCoalesce(this.options.credentials, () => ( "same-origin")),
1115
1190
  body: JSON.stringify({
1116
1191
  system: config.system,
1117
- messages: _chunk4LR4BB23js.toCoreMessages.call(void 0, messages),
1118
- tools: config.tools ? _chunk4LR4BB23js.toLanguageModelTools.call(void 0, config.tools) : [],
1192
+ messages: _chunkCWAZOKEWjs.toCoreMessages.call(void 0, messages),
1193
+ tools: config.tools ? _chunkCWAZOKEWjs.toLanguageModelTools.call(void 0, config.tools) : [],
1119
1194
  ...config.callSettings,
1120
1195
  ...config.config,
1121
1196
  ...this.options.body
@@ -1125,7 +1200,7 @@ var EdgeChatAdapter = class {
1125
1200
  if (result.status !== 200) {
1126
1201
  throw new Error(`Status ${result.status}: ${await result.text()}`);
1127
1202
  }
1128
- const stream = result.body.pipeThrough(streamPartDecoderStream()).pipeThrough(assistantDecoderStream()).pipeThrough(_chunk4LR4BB23js.toolResultStream.call(void 0, config.tools, abortSignal)).pipeThrough(_chunk4LR4BB23js.runResultStream.call(void 0, ));
1203
+ const stream = result.body.pipeThrough(streamPartDecoderStream()).pipeThrough(assistantDecoderStream()).pipeThrough(_chunkCWAZOKEWjs.toolResultStream.call(void 0, config.tools, abortSignal)).pipeThrough(_chunkCWAZOKEWjs.runResultStream.call(void 0, ));
1129
1204
  let update;
1130
1205
  for await (update of asAsyncIterable(stream)) {
1131
1206
  yield update;
@@ -1151,7 +1226,7 @@ var useEdgeRuntime = ({
1151
1226
  };
1152
1227
 
1153
1228
  // src/runtimes/local/shouldContinue.tsx
1154
- var shouldContinue = (result) => _optionalChain([result, 'access', _37 => _37.status, 'optionalAccess', _38 => _38.type]) === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
1229
+ var shouldContinue = (result) => _optionalChain([result, 'access', _33 => _33.status, 'optionalAccess', _34 => _34.type]) === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
1155
1230
 
1156
1231
  // src/runtimes/local/LocalThreadRuntime.tsx
1157
1232
  var LocalThreadRuntime = (_class6 = class {
@@ -1197,13 +1272,13 @@ var LocalThreadRuntime = (_class6 = class {
1197
1272
  set options({ initialMessages, ...options }) {
1198
1273
  this._options = options;
1199
1274
  let hasUpdates = false;
1200
- const canSpeak = _optionalChain([options, 'access', _39 => _39.adapters, 'optionalAccess', _40 => _40.speech]) !== void 0;
1275
+ const canSpeak = _optionalChain([options, 'access', _35 => _35.adapters, 'optionalAccess', _36 => _36.speech]) !== void 0;
1201
1276
  if (this.capabilities.speak !== canSpeak) {
1202
1277
  this.capabilities.speak = canSpeak;
1203
1278
  hasUpdates = true;
1204
1279
  }
1205
- this.composer.setAttachmentAdapter(_optionalChain([options, 'access', _41 => _41.adapters, 'optionalAccess', _42 => _42.attachments]));
1206
- const canAttach = _optionalChain([options, 'access', _43 => _43.adapters, 'optionalAccess', _44 => _44.attachments]) !== void 0;
1280
+ this.composer.setAttachmentAdapter(_optionalChain([options, 'access', _37 => _37.adapters, 'optionalAccess', _38 => _38.attachments]));
1281
+ const canAttach = _optionalChain([options, 'access', _39 => _39.adapters, 'optionalAccess', _40 => _40.attachments]) !== void 0;
1207
1282
  if (this.capabilities.attachments !== canAttach) {
1208
1283
  this.capabilities.attachments = canAttach;
1209
1284
  hasUpdates = true;
@@ -1218,20 +1293,16 @@ var LocalThreadRuntime = (_class6 = class {
1218
1293
  this.notifySubscribers();
1219
1294
  }
1220
1295
  async append(message) {
1221
- if (message.role !== "user")
1222
- throw new Error(
1223
- "Only appending user messages are supported in LocalRuntime. This is likely an internal bug in assistant-ui."
1224
- );
1225
- const userMessageId = generateId();
1226
- const userMessage = {
1227
- id: userMessageId,
1228
- role: "user",
1229
- content: message.content,
1230
- attachments: _nullishCoalesce(message.attachments, () => ( [])),
1231
- createdAt: /* @__PURE__ */ new Date()
1232
- };
1233
- this.repository.addOrUpdateMessage(message.parentId, userMessage);
1234
- await this.startRun(userMessageId);
1296
+ const newMessage = fromCoreMessage(message, {
1297
+ attachments: message.attachments
1298
+ });
1299
+ this.repository.addOrUpdateMessage(message.parentId, newMessage);
1300
+ if (message.role === "user") {
1301
+ await this.startRun(newMessage.id);
1302
+ } else {
1303
+ this.repository.resetHead(newMessage.id);
1304
+ this.notifySubscribers();
1305
+ }
1235
1306
  }
1236
1307
  async startRun(parentId) {
1237
1308
  this.repository.resetHead(parentId);
@@ -1249,18 +1320,18 @@ var LocalThreadRuntime = (_class6 = class {
1249
1320
  }
1250
1321
  async performRoundtrip(parentId, message) {
1251
1322
  const messages = this.repository.getMessages();
1252
- _optionalChain([this, 'access', _45 => _45.abortController, 'optionalAccess', _46 => _46.abort, 'call', _47 => _47()]);
1323
+ _optionalChain([this, 'access', _41 => _41.abortController, 'optionalAccess', _42 => _42.abort, 'call', _43 => _43()]);
1253
1324
  this.abortController = new AbortController();
1254
1325
  const initialContent = message.content;
1255
- const initialRoundtrips = _optionalChain([message, 'access', _48 => _48.metadata, 'optionalAccess', _49 => _49.roundtrips]);
1256
- const initalCustom = _optionalChain([message, 'access', _50 => _50.metadata, 'optionalAccess', _51 => _51.custom]);
1326
+ const initialRoundtrips = _optionalChain([message, 'access', _44 => _44.metadata, 'optionalAccess', _45 => _45.roundtrips]);
1327
+ const initalCustom = _optionalChain([message, 'access', _46 => _46.metadata, 'optionalAccess', _47 => _47.custom]);
1257
1328
  const updateMessage = (m) => {
1258
1329
  message = {
1259
1330
  ...message,
1260
1331
  ...m.content ? { content: [...initialContent, ..._nullishCoalesce(m.content, () => ( []))] } : void 0,
1261
1332
  status: _nullishCoalesce(m.status, () => ( message.status)),
1262
1333
  // TODO deprecated, remove in v0.6
1263
- ..._optionalChain([m, 'access', _52 => _52.metadata, 'optionalAccess', _53 => _53.roundtrips]) ? {
1334
+ ..._optionalChain([m, 'access', _48 => _48.metadata, 'optionalAccess', _49 => _49.roundtrips]) ? {
1264
1335
  roundtrips: [
1265
1336
  ..._nullishCoalesce(initialRoundtrips, () => ( [])),
1266
1337
  ...m.metadata.roundtrips
@@ -1275,7 +1346,7 @@ var LocalThreadRuntime = (_class6 = class {
1275
1346
  ...m.metadata.roundtrips
1276
1347
  ]
1277
1348
  } : void 0,
1278
- ..._optionalChain([m, 'access', _54 => _54.metadata, 'optionalAccess', _55 => _55.custom]) ? {
1349
+ ..._optionalChain([m, 'access', _50 => _50.metadata, 'optionalAccess', _51 => _51.custom]) ? {
1279
1350
  custom: { ..._nullishCoalesce(initalCustom, () => ( {})), ...m.metadata.custom }
1280
1351
  } : void 0
1281
1352
  }
@@ -1285,7 +1356,7 @@ var LocalThreadRuntime = (_class6 = class {
1285
1356
  this.notifySubscribers();
1286
1357
  };
1287
1358
  const maxToolRoundtrips = _nullishCoalesce(this.options.maxToolRoundtrips, () => ( 1));
1288
- const toolRoundtrips = _nullishCoalesce(_optionalChain([message, 'access', _56 => _56.metadata, 'optionalAccess', _57 => _57.roundtrips, 'optionalAccess', _58 => _58.length]), () => ( 0));
1359
+ const toolRoundtrips = _nullishCoalesce(_optionalChain([message, 'access', _52 => _52.metadata, 'optionalAccess', _53 => _53.roundtrips, 'optionalAccess', _54 => _54.length]), () => ( 0));
1289
1360
  if (toolRoundtrips > maxToolRoundtrips) {
1290
1361
  updateMessage({
1291
1362
  status: {
@@ -1353,7 +1424,9 @@ var LocalThreadRuntime = (_class6 = class {
1353
1424
  toolCallId,
1354
1425
  result
1355
1426
  }) {
1356
- let { parentId, message } = this.repository.getMessage(messageId);
1427
+ const messageData = this.repository.getMessage(messageId);
1428
+ const { parentId } = messageData;
1429
+ let { message } = messageData;
1357
1430
  if (message.role !== "assistant")
1358
1431
  throw new Error("Tried to add tool result to non-assistant message");
1359
1432
  let added = false;
@@ -1382,7 +1455,7 @@ var LocalThreadRuntime = (_class6 = class {
1382
1455
  // TODO lift utterance state to thread runtime
1383
1456
 
1384
1457
  speak(messageId) {
1385
- const adapter = _optionalChain([this, 'access', _59 => _59.options, 'access', _60 => _60.adapters, 'optionalAccess', _61 => _61.speech]);
1458
+ const adapter = _optionalChain([this, 'access', _55 => _55.options, 'access', _56 => _56.adapters, 'optionalAccess', _57 => _57.speech]);
1386
1459
  if (!adapter) throw new Error("Speech adapter not configured");
1387
1460
  const { message } = this.repository.getMessage(messageId);
1388
1461
  if (this._utterance) {
@@ -1424,10 +1497,7 @@ var LocalRuntime = class extends BaseAssistantRuntime {
1424
1497
  registerModelConfigProvider(provider) {
1425
1498
  return this._proxyConfigProvider.registerModelConfigProvider(provider);
1426
1499
  }
1427
- switchToThread(threadId) {
1428
- if (threadId) {
1429
- throw new Error("LocalRuntime does not yet support switching threads");
1430
- }
1500
+ switchToNewThread() {
1431
1501
  const { initialMessages, ...options } = this.thread.options;
1432
1502
  return this.thread = new LocalThreadRuntime(
1433
1503
  this._proxyConfigProvider,
@@ -1435,6 +1505,12 @@ var LocalRuntime = class extends BaseAssistantRuntime {
1435
1505
  options
1436
1506
  );
1437
1507
  }
1508
+ switchToThread(threadId) {
1509
+ if (threadId !== null) {
1510
+ throw new Error("LocalRuntime does not yet support switching threads");
1511
+ }
1512
+ this.switchToNewThread();
1513
+ }
1438
1514
  reset({
1439
1515
  initialMessages
1440
1516
  } = {}) {
@@ -1443,7 +1519,7 @@ var LocalRuntime = class extends BaseAssistantRuntime {
1443
1519
  const messages = fromCoreMessages(initialMessages);
1444
1520
  this.thread.import({
1445
1521
  messages: messages.map((m, idx) => ({
1446
- parentId: _nullishCoalesce(_optionalChain([messages, 'access', _62 => _62[idx - 1], 'optionalAccess', _63 => _63.id]), () => ( null)),
1522
+ parentId: _nullishCoalesce(_optionalChain([messages, 'access', _58 => _58[idx - 1], 'optionalAccess', _59 => _59.id]), () => ( null)),
1447
1523
  message: m
1448
1524
  }))
1449
1525
  });
@@ -1572,7 +1648,7 @@ var getThreadMessageText = (message) => {
1572
1648
 
1573
1649
  // src/runtimes/external-store/ExternalStoreThreadRuntime.tsx
1574
1650
  var hasUpcomingMessage = (isRunning, messages) => {
1575
- return isRunning && _optionalChain([messages, 'access', _64 => _64[messages.length - 1], 'optionalAccess', _65 => _65.role]) !== "assistant";
1651
+ return isRunning && _optionalChain([messages, 'access', _60 => _60[messages.length - 1], 'optionalAccess', _61 => _61.role]) !== "assistant";
1576
1652
  };
1577
1653
  var ExternalStoreThreadRuntime = (_class8 = class {
1578
1654
  __init21() {this._subscriptions = /* @__PURE__ */ new Set()}
@@ -1618,11 +1694,11 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1618
1694
  reload: this._store.onReload !== void 0,
1619
1695
  cancel: this._store.onCancel !== void 0,
1620
1696
  speak: this._store.onSpeak !== void 0,
1621
- unstable_copy: _optionalChain([this, 'access', _69 => _69._store, 'access', _70 => _70.unstable_capabilities, 'optionalAccess', _71 => _71.copy]) !== false,
1697
+ unstable_copy: _optionalChain([this, 'access', _65 => _65._store, 'access', _66 => _66.unstable_capabilities, 'optionalAccess', _67 => _67.copy]) !== false,
1622
1698
  // default true
1623
- attachments: !!_optionalChain([this, 'access', _72 => _72.store, 'access', _73 => _73.adapters, 'optionalAccess', _74 => _74.attachments])
1699
+ attachments: !!_optionalChain([this, 'access', _68 => _68.store, 'access', _69 => _69.adapters, 'optionalAccess', _70 => _70.attachments])
1624
1700
  };
1625
- this.composer.setAttachmentAdapter(_optionalChain([this, 'access', _75 => _75._store, 'access', _76 => _76.adapters, 'optionalAccess', _77 => _77.attachments]));
1701
+ this.composer.setAttachmentAdapter(_optionalChain([this, 'access', _71 => _71._store, 'access', _72 => _72.adapters, 'optionalAccess', _73 => _73.attachments]));
1626
1702
  if (oldStore) {
1627
1703
  if (oldStore.convertMessage !== store.convertMessage) {
1628
1704
  this.converter = new ThreadMessageConverter();
@@ -1648,7 +1724,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1648
1724
  for (let i = 0; i < messages.length; i++) {
1649
1725
  const message = messages[i];
1650
1726
  const parent = messages[i - 1];
1651
- this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _78 => _78.id]), () => ( null)), message);
1727
+ this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _74 => _74.id]), () => ( null)), message);
1652
1728
  }
1653
1729
  if (this.assistantOptimisticId) {
1654
1730
  this.repository.deleteMessage(this.assistantOptimisticId);
@@ -1656,7 +1732,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1656
1732
  }
1657
1733
  if (hasUpcomingMessage(isRunning, messages)) {
1658
1734
  this.assistantOptimisticId = this.repository.appendOptimisticMessage(
1659
- _nullishCoalesce(_optionalChain([messages, 'access', _79 => _79.at, 'call', _80 => _80(-1), 'optionalAccess', _81 => _81.id]), () => ( null)),
1735
+ _nullishCoalesce(_optionalChain([messages, 'access', _75 => _75.at, 'call', _76 => _76(-1), 'optionalAccess', _77 => _77.id]), () => ( null)),
1660
1736
  {
1661
1737
  role: "assistant",
1662
1738
  content: []
@@ -1664,7 +1740,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1664
1740
  );
1665
1741
  }
1666
1742
  this.repository.resetHead(
1667
- _nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages, 'access', _82 => _82.at, 'call', _83 => _83(-1), 'optionalAccess', _84 => _84.id]))), () => ( null))
1743
+ _nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages, 'access', _78 => _78.at, 'call', _79 => _79(-1), 'optionalAccess', _80 => _80.id]))), () => ( null))
1668
1744
  );
1669
1745
  this.messages = this.repository.getMessages();
1670
1746
  this.notifySubscribers();
@@ -1682,7 +1758,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1682
1758
  this.updateMessages(this.repository.getMessages());
1683
1759
  }
1684
1760
  async append(message) {
1685
- if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _85 => _85.messages, 'access', _86 => _86.at, 'call', _87 => _87(-1), 'optionalAccess', _88 => _88.id]), () => ( null)))) {
1761
+ if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _81 => _81.messages, 'access', _82 => _82.at, 'call', _83 => _83(-1), 'optionalAccess', _84 => _84.id]), () => ( null)))) {
1686
1762
  if (!this._store.onEdit)
1687
1763
  throw new Error("Runtime does not support editing messages.");
1688
1764
  await this._store.onEdit(message);
@@ -1705,7 +1781,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1705
1781
  }
1706
1782
  let messages = this.repository.getMessages();
1707
1783
  const previousMessage = messages[messages.length - 1];
1708
- if (_optionalChain([previousMessage, 'optionalAccess', _89 => _89.role]) === "user" && previousMessage.id === _optionalChain([messages, 'access', _90 => _90.at, 'call', _91 => _91(-1), 'optionalAccess', _92 => _92.id])) {
1784
+ if (_optionalChain([previousMessage, 'optionalAccess', _85 => _85.role]) === "user" && previousMessage.id === _optionalChain([messages, 'access', _86 => _86.at, 'call', _87 => _87(-1), 'optionalAccess', _88 => _88.id])) {
1709
1785
  this.repository.deleteMessage(previousMessage.id);
1710
1786
  if (!this.composer.text.trim()) {
1711
1787
  this.composer.setText(getThreadMessageText(previousMessage));
@@ -1734,7 +1810,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1734
1810
  return () => this._subscriptions.delete(callback);
1735
1811
  }
1736
1812
  __init27() {this.updateMessages = (messages) => {
1737
- _optionalChain([this, 'access', _93 => _93._store, 'access', _94 => _94.setMessages, 'optionalCall', _95 => _95(
1813
+ _optionalChain([this, 'access', _89 => _89._store, 'access', _90 => _90.setMessages, 'optionalCall', _91 => _91(
1738
1814
  messages.flatMap(getExternalStoreMessage).filter((m) => m != null)
1739
1815
  )]);
1740
1816
  }}
@@ -1758,8 +1834,17 @@ var ExternalStoreRuntime = (_class9 = class extends BaseAssistantRuntime {
1758
1834
  registerModelConfigProvider(provider) {
1759
1835
  return this._proxyConfigProvider.registerModelConfigProvider(provider);
1760
1836
  }
1837
+ async switchToNewThread() {
1838
+ if (!this.store.onNewThread)
1839
+ throw new Error("Runtime does not support switching to new threads.");
1840
+ this.thread = new ExternalStoreThreadRuntime({
1841
+ messages: [],
1842
+ onNew: this.store.onNew
1843
+ });
1844
+ await this.store.onNewThread();
1845
+ }
1761
1846
  async switchToThread(threadId) {
1762
- if (threadId) {
1847
+ if (threadId !== null) {
1763
1848
  if (!this.store.onSwitchThread)
1764
1849
  throw new Error("Runtime does not support switching threads.");
1765
1850
  this.thread = new ExternalStoreThreadRuntime({
@@ -1768,13 +1853,7 @@ var ExternalStoreRuntime = (_class9 = class extends BaseAssistantRuntime {
1768
1853
  });
1769
1854
  this.store.onSwitchThread(threadId);
1770
1855
  } else {
1771
- if (!this.store.onNewThread)
1772
- throw new Error("Runtime does not support switching to new threads.");
1773
- this.thread = new ExternalStoreThreadRuntime({
1774
- messages: [],
1775
- onNew: this.store.onNew
1776
- });
1777
- await this.store.onNewThread();
1856
+ this.switchToNewThread();
1778
1857
  }
1779
1858
  }
1780
1859
  }, _class9);
@@ -1945,18 +2024,18 @@ var DangerousInBrowserAdapter = class {
1945
2024
  this.options = options;
1946
2025
  }
1947
2026
  async *run({ messages, abortSignal, config }) {
1948
- const res = await _chunk4LR4BB23js.getEdgeRuntimeStream.call(void 0, {
2027
+ const res = await _chunkCWAZOKEWjs.getEdgeRuntimeStream.call(void 0, {
1949
2028
  options: this.options,
1950
2029
  abortSignal,
1951
2030
  requestData: {
1952
2031
  system: config.system,
1953
- messages: _chunk4LR4BB23js.toCoreMessages.call(void 0, messages),
1954
- tools: config.tools ? _chunk4LR4BB23js.toLanguageModelTools.call(void 0, config.tools) : [],
2032
+ messages: _chunkCWAZOKEWjs.toCoreMessages.call(void 0, messages),
2033
+ tools: config.tools ? _chunkCWAZOKEWjs.toLanguageModelTools.call(void 0, config.tools) : [],
1955
2034
  ...config.callSettings,
1956
2035
  ...config.config
1957
2036
  }
1958
2037
  });
1959
- const stream = res.pipeThrough(_chunk4LR4BB23js.toolResultStream.call(void 0, config.tools, abortSignal)).pipeThrough(_chunk4LR4BB23js.runResultStream.call(void 0, ));
2038
+ const stream = res.pipeThrough(_chunkCWAZOKEWjs.toolResultStream.call(void 0, config.tools, abortSignal)).pipeThrough(_chunkCWAZOKEWjs.runResultStream.call(void 0, ));
1960
2039
  for await (const update of asAsyncIterable(stream)) {
1961
2040
  yield update;
1962
2041
  }
@@ -2149,11 +2228,6 @@ var CompositeAttachmentAdapter = class {
2149
2228
  }
2150
2229
  };
2151
2230
 
2152
- // src/context/ReadonlyStore.ts
2153
- var writableStore = (store) => {
2154
- return store;
2155
- };
2156
-
2157
2231
  // src/context/providers/ThreadProvider.tsx
2158
2232
 
2159
2233
  var ThreadProvider = ({
@@ -2161,18 +2235,18 @@ var ThreadProvider = ({
2161
2235
  provider
2162
2236
  }) => {
2163
2237
  const [context] = _react.useState.call(void 0, () => {
2164
- const useThreadRuntime = makeThreadRuntimeStore(provider.thread);
2165
- const useThread = makeThreadStore(useThreadRuntime);
2166
- const useThreadMessages = makeThreadMessagesStore(useThreadRuntime);
2167
- const useThreadActions = makeThreadActionStore(useThreadRuntime);
2238
+ const useThreadRuntime2 = makeThreadRuntimeStore(provider.thread);
2239
+ const useThread2 = makeThreadStore(useThreadRuntime2);
2240
+ const useThreadMessages2 = makeThreadMessagesStore(useThreadRuntime2);
2241
+ const useThreadActions2 = makeThreadActionStore(useThreadRuntime2);
2168
2242
  const useViewport = makeThreadViewportStore();
2169
- const useComposer = makeComposerStore(useThreadRuntime);
2243
+ const useComposer2 = makeThreadComposerStore(useThreadRuntime2);
2170
2244
  return {
2171
- useThread,
2172
- useThreadRuntime,
2173
- useThreadMessages,
2174
- useThreadActions,
2175
- useComposer,
2245
+ useThread: useThread2,
2246
+ useThreadRuntime: useThreadRuntime2,
2247
+ useThreadMessages: useThreadMessages2,
2248
+ useThreadActions: useThreadActions2,
2249
+ useComposer: useComposer2,
2176
2250
  useViewport
2177
2251
  };
2178
2252
  });
@@ -2224,6 +2298,7 @@ var ThreadProvider = ({
2224
2298
  var makeAssistantActionsStore = (runtimeRef) => _zustand.create.call(void 0,
2225
2299
  () => Object.freeze({
2226
2300
  switchToThread: () => runtimeRef.current.switchToThread(null),
2301
+ registerModelConfigProvider: (provider) => runtimeRef.current.registerModelConfigProvider(provider),
2227
2302
  getRuntime: () => runtimeRef.current
2228
2303
  })
2229
2304
  );
@@ -2242,21 +2317,15 @@ var AssistantProvider = ({ children, runtime }) => {
2242
2317
  runtimeRef.current = runtime;
2243
2318
  });
2244
2319
  const [context] = _react.useState.call(void 0, () => {
2245
- const useAssistantRuntime = makeAssistantRuntimeStore(runtime);
2246
- const useModelConfig = makeAssistantModelConfigStore();
2247
- const useToolUIs = makeAssistantToolUIsStore();
2248
- const useAssistantActions = makeAssistantActionsStore(runtimeRef);
2320
+ const useAssistantRuntime2 = makeAssistantRuntimeStore(runtime);
2321
+ const useToolUIs2 = makeAssistantToolUIsStore();
2322
+ const useAssistantActions2 = makeAssistantActionsStore(runtimeRef);
2249
2323
  return {
2250
- useModelConfig,
2251
- useToolUIs,
2252
- useAssistantRuntime,
2253
- useAssistantActions
2324
+ useToolUIs: useToolUIs2,
2325
+ useAssistantRuntime: useAssistantRuntime2,
2326
+ useAssistantActions: useAssistantActions2
2254
2327
  };
2255
2328
  });
2256
- const getModelConfig = context.useModelConfig();
2257
- _react.useEffect.call(void 0, () => {
2258
- return runtime.registerModelConfigProvider(getModelConfig);
2259
- }, [runtime, getModelConfig]);
2260
2329
  _react.useEffect.call(void 0,
2261
2330
  () => writableStore(context.useAssistantRuntime).setState(runtime, true),
2262
2331
  [runtime, context]
@@ -2275,91 +2344,93 @@ var AssistantRuntimeProvider = _react.memo.call(void 0, AssistantRuntimeProvider
2275
2344
 
2276
2345
 
2277
2346
 
2278
- // src/context/react/ContentPartContext.ts
2279
-
2280
- var ContentPartContext = _react.createContext.call(void 0,
2281
- null
2282
- );
2283
- function useContentPartContext(options) {
2284
- const context = _react.useContext.call(void 0, ContentPartContext);
2285
- if (!_optionalChain([options, 'optionalAccess', _96 => _96.optional]) && !context)
2286
- throw new Error(
2287
- "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
2288
- );
2289
- return context;
2290
- }
2291
-
2292
- // src/context/providers/TextContentPartProvider.tsx
2293
-
2294
2347
  var TextContentPartProvider = ({ children, text }) => {
2295
2348
  const [context] = _react.useState.call(void 0, () => {
2296
- const useContentPart = _zustand.create.call(void 0, () => ({
2349
+ const useContentPart2 = _zustand.create.call(void 0, () => ({
2297
2350
  status: { type: "complete" },
2298
2351
  part: { type: "text", text }
2299
2352
  }));
2300
2353
  return {
2301
- useContentPart
2354
+ useContentPart: useContentPart2
2302
2355
  };
2303
2356
  });
2304
2357
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartContext.Provider, { value: context, children });
2305
2358
  };
2306
2359
 
2307
- // src/context/react/ComposerContext.ts
2308
-
2309
-
2310
2360
  // src/context/react/MessageContext.ts
2311
2361
 
2312
2362
  var MessageContext = _react.createContext.call(void 0, null);
2313
- function useMessageContext(options) {
2314
- const context = _react.useContext.call(void 0, MessageContext);
2315
- if (!_optionalChain([options, 'optionalAccess', _97 => _97.optional]) && !context)
2316
- throw new Error(
2317
- "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
2318
- );
2319
- return context;
2320
- }
2363
+ var useMessageContext = createContextHook(
2364
+ MessageContext,
2365
+ "a component passed to <ThreadPrimitive.Messages components={...} />"
2366
+ );
2367
+ var { useMessage, useMessageStore } = createContextStoreHook(
2368
+ useMessageContext,
2369
+ "useMessage"
2370
+ );
2371
+ var { useMessageUtils, useMessageUtilsStore } = createContextStoreHook(
2372
+ useMessageContext,
2373
+ "useMessageUtils"
2374
+ );
2375
+ var { useEditComposer, useEditComposerStore } = createContextStoreHook(
2376
+ useMessageContext,
2377
+ "useEditComposer"
2378
+ );
2321
2379
 
2322
2380
  // src/context/react/ComposerContext.ts
2381
+
2323
2382
  var useComposerContext = () => {
2324
- const { useComposer } = useThreadContext();
2325
- const { useEditComposer } = _nullishCoalesce(useMessageContext({ optional: true }), () => ( {}));
2383
+ const { useComposer: useComposer2 } = useThreadContext();
2384
+ const { useEditComposer: useEditComposer2 } = _nullishCoalesce(useMessageContext({ optional: true }), () => ( {}));
2326
2385
  return _react.useMemo.call(void 0,
2327
2386
  () => ({
2328
- useComposer: _nullishCoalesce(useEditComposer, () => ( useComposer)),
2329
- type: useEditComposer ? "edit" : "new"
2387
+ useComposer: _nullishCoalesce(useEditComposer2, () => ( useComposer2)),
2388
+ type: useEditComposer2 ? "edit" : "new"
2330
2389
  }),
2331
- [useEditComposer, useComposer]
2390
+ [useEditComposer2, useComposer2]
2332
2391
  );
2333
2392
  };
2393
+ var { useComposer, useComposerStore } = createContextStoreHook(
2394
+ useComposerContext,
2395
+ "useComposer"
2396
+ );
2334
2397
 
2335
2398
  // src/hooks/useAppendMessage.tsx
2336
2399
 
2337
- var toAppendMessage = (useThreadMessages, message) => {
2400
+ var toAppendMessage = (useThreadMessages2, message) => {
2338
2401
  if (typeof message === "string") {
2339
2402
  return {
2340
- parentId: _nullishCoalesce(_optionalChain([useThreadMessages, 'access', _98 => _98.getState, 'call', _99 => _99(), 'access', _100 => _100.at, 'call', _101 => _101(-1), 'optionalAccess', _102 => _102.id]), () => ( null)),
2403
+ parentId: _nullishCoalesce(_optionalChain([useThreadMessages2, 'access', _92 => _92.getState, 'call', _93 => _93(), 'access', _94 => _94.at, 'call', _95 => _95(-1), 'optionalAccess', _96 => _96.id]), () => ( null)),
2341
2404
  role: "user",
2342
2405
  content: [{ type: "text", text: message }],
2343
2406
  attachments: []
2344
2407
  };
2345
2408
  }
2346
2409
  return {
2347
- parentId: _nullishCoalesce(_nullishCoalesce(message.parentId, () => ( _optionalChain([useThreadMessages, 'access', _103 => _103.getState, 'call', _104 => _104(), 'access', _105 => _105.at, 'call', _106 => _106(-1), 'optionalAccess', _107 => _107.id]))), () => ( null)),
2410
+ parentId: _nullishCoalesce(_nullishCoalesce(message.parentId, () => ( _optionalChain([useThreadMessages2, 'access', _97 => _97.getState, 'call', _98 => _98(), 'access', _99 => _99.at, 'call', _100 => _100(-1), 'optionalAccess', _101 => _101.id]))), () => ( null)),
2348
2411
  role: _nullishCoalesce(message.role, () => ( "user")),
2349
2412
  content: message.content,
2350
2413
  attachments: _nullishCoalesce(message.attachments, () => ( []))
2351
2414
  };
2352
2415
  };
2353
2416
  var useAppendMessage = () => {
2354
- const { useThreadMessages, useThreadActions, useViewport, useComposer } = useThreadContext();
2417
+ const threadMessagesStore = useThreadMessagesStore();
2418
+ const threadActionsStore = useThreadActionsStore();
2419
+ const threadViewportStore = useThreadViewportStore();
2420
+ const threadComposerStore = useThreadComposerStore();
2355
2421
  const append = _react.useCallback.call(void 0,
2356
2422
  (message) => {
2357
- const appendMessage = toAppendMessage(useThreadMessages, message);
2358
- useThreadActions.getState().append(appendMessage);
2359
- useViewport.getState().scrollToBottom();
2360
- useComposer.getState().focus();
2423
+ const appendMessage = toAppendMessage(threadMessagesStore, message);
2424
+ threadActionsStore.getState().append(appendMessage);
2425
+ threadViewportStore.getState().scrollToBottom();
2426
+ threadComposerStore.getState().focus();
2361
2427
  },
2362
- [useThreadMessages, useThreadActions, useViewport, useComposer]
2428
+ [
2429
+ threadMessagesStore,
2430
+ threadActionsStore,
2431
+ threadViewportStore,
2432
+ threadComposerStore
2433
+ ]
2363
2434
  );
2364
2435
  return append;
2365
2436
  };
@@ -2367,23 +2438,20 @@ var useAppendMessage = () => {
2367
2438
  // src/hooks/useSwitchToNewThread.tsx
2368
2439
 
2369
2440
  var useSwitchToNewThread = () => {
2370
- const { useAssistantActions } = useAssistantContext();
2371
- const { useComposer } = useThreadContext();
2441
+ const assistantActionsStore = useAssistantActionsStore();
2442
+ const threadComposerStore = useThreadComposerStore();
2372
2443
  const switchToNewThread = _react.useCallback.call(void 0, () => {
2373
- useAssistantActions.getState().switchToThread(null);
2374
- useComposer.getState().focus();
2375
- }, [useAssistantActions, useComposer]);
2444
+ assistantActionsStore.getState().switchToThread(null);
2445
+ threadComposerStore.getState().focus();
2446
+ }, [assistantActionsStore, threadComposerStore]);
2376
2447
  return switchToNewThread;
2377
2448
  };
2378
2449
 
2379
2450
  // src/model-config/useAssistantTool.tsx
2380
2451
 
2381
2452
  var useAssistantTool = (tool) => {
2382
- const { useModelConfig, useToolUIs } = useAssistantContext();
2383
- const registerModelConfigProvider = useModelConfig(
2384
- (s) => s.registerModelConfigProvider
2385
- );
2386
- const setToolUI = useToolUIs((s) => s.setToolUI);
2453
+ const assistantActionsStore = useAssistantActionsStore();
2454
+ const toolUIsStore = useToolUIsStore();
2387
2455
  _react.useEffect.call(void 0, () => {
2388
2456
  const { toolName, render, ...rest } = tool;
2389
2457
  const config = {
@@ -2391,15 +2459,15 @@ var useAssistantTool = (tool) => {
2391
2459
  [tool.toolName]: rest
2392
2460
  }
2393
2461
  };
2394
- const unsub1 = registerModelConfigProvider({
2462
+ const unsub1 = assistantActionsStore.getState().registerModelConfigProvider({
2395
2463
  getModelConfig: () => config
2396
2464
  });
2397
- const unsub2 = render ? setToolUI(toolName, render) : void 0;
2465
+ const unsub2 = render ? toolUIsStore.getState().setToolUI(toolName, render) : void 0;
2398
2466
  return () => {
2399
2467
  unsub1();
2400
- _optionalChain([unsub2, 'optionalCall', _108 => _108()]);
2468
+ _optionalChain([unsub2, 'optionalCall', _102 => _102()]);
2401
2469
  };
2402
- }, [registerModelConfigProvider, setToolUI, tool]);
2470
+ }, [assistantActionsStore, toolUIsStore, tool]);
2403
2471
  };
2404
2472
 
2405
2473
  // src/model-config/makeAssistantTool.tsx
@@ -2415,13 +2483,12 @@ var makeAssistantTool = (tool) => {
2415
2483
  // src/model-config/useAssistantToolUI.tsx
2416
2484
 
2417
2485
  var useAssistantToolUI = (tool) => {
2418
- const { useToolUIs } = useAssistantContext();
2419
- const setToolUI = useToolUIs((s) => s.setToolUI);
2486
+ const toolUIsStore = useToolUIsStore();
2420
2487
  _react.useEffect.call(void 0, () => {
2421
2488
  if (!tool) return;
2422
2489
  const { toolName, render } = tool;
2423
- return setToolUI(toolName, render);
2424
- }, [setToolUI, tool]);
2490
+ return toolUIsStore.getState().setToolUI(toolName, render);
2491
+ }, [toolUIsStore, tool]);
2425
2492
  };
2426
2493
 
2427
2494
  // src/model-config/makeAssistantToolUI.tsx
@@ -2437,16 +2504,13 @@ var makeAssistantToolUI = (tool) => {
2437
2504
  // src/model-config/useAssistantInstructions.tsx
2438
2505
 
2439
2506
  var useAssistantInstructions = (instruction) => {
2440
- const { useModelConfig } = useAssistantContext();
2441
- const registerModelConfigProvider = useModelConfig(
2442
- (s) => s.registerModelConfigProvider
2443
- );
2507
+ const runtimeStore = useAssistantRuntimeStore();
2444
2508
  _react.useEffect.call(void 0, () => {
2445
2509
  const config = {
2446
2510
  system: instruction
2447
2511
  };
2448
- return registerModelConfigProvider({ getModelConfig: () => config });
2449
- }, [registerModelConfigProvider, instruction]);
2512
+ return runtimeStore.getState().registerModelConfigProvider({ getModelConfig: () => config });
2513
+ }, [runtimeStore, instruction]);
2450
2514
  };
2451
2515
 
2452
2516
  // src/primitive-hooks/actionBar/useActionBarCopy.tsx
@@ -2482,23 +2546,25 @@ var useCombinedStore = (stores, selector) => {
2482
2546
  var useActionBarCopy = ({
2483
2547
  copiedDuration = 3e3
2484
2548
  } = {}) => {
2485
- const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();
2549
+ const messageStore = useMessageStore();
2550
+ const messageUtilsStore = useMessageUtilsStore();
2551
+ const editComposerStore = useEditComposerStore();
2486
2552
  const hasCopyableContent = useCombinedStore(
2487
- [useMessage, useEditComposer],
2553
+ [messageStore, editComposerStore],
2488
2554
  ({ message }, c) => {
2489
2555
  return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
2490
2556
  }
2491
2557
  );
2492
2558
  const callback = _react.useCallback.call(void 0, () => {
2493
- const { message } = useMessage.getState();
2494
- const { setIsCopied } = useMessageUtils.getState();
2495
- const { isEditing, text: composerValue } = useEditComposer.getState();
2559
+ const { message } = messageStore.getState();
2560
+ const { setIsCopied } = messageUtilsStore.getState();
2561
+ const { isEditing, text: composerValue } = editComposerStore.getState();
2496
2562
  const valueToCopy = isEditing ? composerValue : getThreadMessageText(message);
2497
2563
  navigator.clipboard.writeText(valueToCopy).then(() => {
2498
2564
  setIsCopied(true);
2499
2565
  setTimeout(() => setIsCopied(false), copiedDuration);
2500
2566
  });
2501
- }, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);
2567
+ }, [messageStore, messageUtilsStore, editComposerStore, copiedDuration]);
2502
2568
  if (!hasCopyableContent) return null;
2503
2569
  return callback;
2504
2570
  };
@@ -2506,15 +2572,12 @@ var useActionBarCopy = ({
2506
2572
  // src/primitive-hooks/actionBar/useActionBarEdit.tsx
2507
2573
 
2508
2574
  var useActionBarEdit = () => {
2509
- const { useMessage, useEditComposer } = useMessageContext();
2510
- const disabled = useCombinedStore(
2511
- [useMessage, useEditComposer],
2512
- (m, c) => m.message.role !== "user" || c.isEditing
2513
- );
2575
+ const editComposerStore = useEditComposerStore();
2576
+ const disabled = useEditComposer((c) => c.isEditing);
2514
2577
  const callback = _react.useCallback.call(void 0, () => {
2515
- const { edit } = useEditComposer.getState();
2578
+ const { edit } = editComposerStore.getState();
2516
2579
  edit();
2517
- }, [useEditComposer]);
2580
+ }, [editComposerStore]);
2518
2581
  if (disabled) return null;
2519
2582
  return callback;
2520
2583
  };
@@ -2522,18 +2585,26 @@ var useActionBarEdit = () => {
2522
2585
  // src/primitive-hooks/actionBar/useActionBarReload.tsx
2523
2586
 
2524
2587
  var useActionBarReload = () => {
2525
- const { useThread, useThreadActions, useComposer, useViewport } = useThreadContext();
2526
- const { useMessage } = useMessageContext();
2588
+ const messageStore = useMessageStore();
2589
+ const threadStore = useThreadStore();
2590
+ const threadActionsStore = useThreadActionsStore();
2591
+ const threadComposerStore = useThreadComposerStore();
2592
+ const threadViewportStore = useThreadViewportStore();
2527
2593
  const disabled = useCombinedStore(
2528
- [useThread, useMessage],
2594
+ [threadStore, messageStore],
2529
2595
  (t, m) => t.isRunning || t.isDisabled || m.message.role !== "assistant"
2530
2596
  );
2531
2597
  const callback = _react.useCallback.call(void 0, () => {
2532
- const { parentId } = useMessage.getState();
2533
- useThreadActions.getState().startRun(parentId);
2534
- useViewport.getState().scrollToBottom();
2535
- useComposer.getState().focus();
2536
- }, [useThreadActions, useComposer, useViewport, useMessage]);
2598
+ const { parentId } = messageStore.getState();
2599
+ threadActionsStore.getState().startRun(parentId);
2600
+ threadViewportStore.getState().scrollToBottom();
2601
+ threadComposerStore.getState().focus();
2602
+ }, [
2603
+ threadActionsStore,
2604
+ threadComposerStore,
2605
+ threadViewportStore,
2606
+ messageStore
2607
+ ]);
2537
2608
  if (disabled) return null;
2538
2609
  return callback;
2539
2610
  };
@@ -2541,19 +2612,21 @@ var useActionBarReload = () => {
2541
2612
  // src/primitive-hooks/actionBar/useActionBarSpeak.tsx
2542
2613
 
2543
2614
  var useActionBarSpeak = () => {
2544
- const { useThreadActions } = useThreadContext();
2545
- const { useMessage, useEditComposer, useMessageUtils } = useMessageContext();
2615
+ const messageStore = useMessageStore();
2616
+ const editComposerStore = useEditComposerStore();
2617
+ const threadActionsStore = useThreadActionsStore();
2618
+ const messageUtilsStore = useMessageUtilsStore();
2546
2619
  const hasSpeakableContent = useCombinedStore(
2547
- [useMessage, useEditComposer],
2620
+ [messageStore, editComposerStore],
2548
2621
  ({ message }, c) => {
2549
2622
  return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
2550
2623
  }
2551
2624
  );
2552
2625
  const callback = _react.useCallback.call(void 0, async () => {
2553
- const { message } = useMessage.getState();
2554
- const utt = useThreadActions.getState().speak(message.id);
2555
- useMessageUtils.getState().addUtterance(utt);
2556
- }, [useThreadActions, useMessage, useMessageUtils]);
2626
+ const { message } = messageStore.getState();
2627
+ const utt = threadActionsStore.getState().speak(message.id);
2628
+ messageUtilsStore.getState().addUtterance(utt);
2629
+ }, [threadActionsStore, messageStore, messageUtilsStore]);
2557
2630
  if (!hasSpeakableContent) return null;
2558
2631
  return callback;
2559
2632
  };
@@ -2561,18 +2634,17 @@ var useActionBarSpeak = () => {
2561
2634
  // src/primitive-hooks/actionBar/useActionBarStopSpeaking.tsx
2562
2635
 
2563
2636
  var useActionBarStopSpeaking = () => {
2564
- const { useMessageUtils } = useMessageContext();
2637
+ const messageUtilsStore = useMessageUtilsStore();
2565
2638
  const isSpeaking = useMessageUtils((u) => u.isSpeaking);
2566
2639
  const callback = _react.useCallback.call(void 0, async () => {
2567
- useMessageUtils.getState().stopSpeaking();
2568
- }, [useMessageUtils]);
2640
+ messageUtilsStore.getState().stopSpeaking();
2641
+ }, [messageUtilsStore]);
2569
2642
  if (!isSpeaking) return null;
2570
2643
  return callback;
2571
2644
  };
2572
2645
 
2573
2646
  // src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
2574
2647
  var useBranchPickerCount = () => {
2575
- const { useMessage } = useMessageContext();
2576
2648
  const branchCount = useMessage((s) => s.branches.length);
2577
2649
  return branchCount;
2578
2650
  };
@@ -2580,23 +2652,23 @@ var useBranchPickerCount = () => {
2580
2652
  // src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
2581
2653
 
2582
2654
  var useBranchPickerNext = () => {
2583
- const { useThreadActions } = useThreadContext();
2584
- const { useMessage, useEditComposer } = useMessageContext();
2655
+ const messageStore = useMessageStore();
2656
+ const editComposerStore = useEditComposerStore();
2657
+ const threadActionsStore = useThreadActionsStore();
2585
2658
  const disabled = useCombinedStore(
2586
- [useMessage, useEditComposer],
2659
+ [messageStore, editComposerStore],
2587
2660
  (m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
2588
2661
  );
2589
2662
  const callback = _react.useCallback.call(void 0, () => {
2590
- const { message, branches } = useMessage.getState();
2591
- useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
2592
- }, [useThreadActions, useMessage]);
2663
+ const { message, branches } = messageStore.getState();
2664
+ threadActionsStore.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
2665
+ }, [threadActionsStore, messageStore]);
2593
2666
  if (disabled) return null;
2594
2667
  return callback;
2595
2668
  };
2596
2669
 
2597
2670
  // src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
2598
2671
  var useBranchPickerNumber = () => {
2599
- const { useMessage } = useMessageContext();
2600
2672
  const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
2601
2673
  return branchIdx + 1;
2602
2674
  };
@@ -2604,16 +2676,17 @@ var useBranchPickerNumber = () => {
2604
2676
  // src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
2605
2677
 
2606
2678
  var useBranchPickerPrevious = () => {
2607
- const { useThreadActions } = useThreadContext();
2608
- const { useMessage, useEditComposer } = useMessageContext();
2679
+ const messageStore = useMessageStore();
2680
+ const editComposerStore = useEditComposerStore();
2681
+ const threadActionsStore = useThreadActionsStore();
2609
2682
  const disabled = useCombinedStore(
2610
- [useMessage, useEditComposer],
2683
+ [messageStore, editComposerStore],
2611
2684
  (m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
2612
2685
  );
2613
2686
  const callback = _react.useCallback.call(void 0, () => {
2614
- const { message, branches } = useMessage.getState();
2615
- useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
2616
- }, [useThreadActions, useMessage]);
2687
+ const { message, branches } = messageStore.getState();
2688
+ threadActionsStore.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
2689
+ }, [threadActionsStore, messageStore]);
2617
2690
  if (disabled) return null;
2618
2691
  return callback;
2619
2692
  };
@@ -2621,19 +2694,18 @@ var useBranchPickerPrevious = () => {
2621
2694
  // src/primitive-hooks/composer/useComposerCancel.tsx
2622
2695
 
2623
2696
  var useComposerCancel = () => {
2624
- const { useComposer } = useComposerContext();
2697
+ const composerStore = useComposerStore();
2625
2698
  const disabled = useComposer((c) => !c.canCancel);
2626
2699
  const callback = _react.useCallback.call(void 0, () => {
2627
- const { cancel } = useComposer.getState();
2700
+ const { cancel } = composerStore.getState();
2628
2701
  cancel();
2629
- }, [useComposer]);
2702
+ }, [composerStore]);
2630
2703
  if (disabled) return null;
2631
2704
  return callback;
2632
2705
  };
2633
2706
 
2634
2707
  // src/primitive-hooks/composer/useComposerIf.tsx
2635
2708
  var useComposerIf = (props) => {
2636
- const { useComposer } = useComposerContext();
2637
2709
  return useComposer((composer) => {
2638
2710
  if (props.editing === true && !composer.isEditing) return false;
2639
2711
  if (props.editing === false && composer.isEditing) return false;
@@ -2644,23 +2716,21 @@ var useComposerIf = (props) => {
2644
2716
  // src/primitive-hooks/composer/useComposerSend.tsx
2645
2717
 
2646
2718
  var useComposerSend = () => {
2647
- const {
2648
- useThread,
2649
- useViewport,
2650
- useComposer: useNewComposer
2651
- } = useThreadContext();
2652
- const { useComposer } = useComposerContext();
2719
+ const threadStore = useThreadStore();
2720
+ const threadViewportStore = useThreadViewportStore();
2721
+ const composerStore = useComposerStore();
2722
+ const threadComposerStore = useThreadComposerStore();
2653
2723
  const disabled = useCombinedStore(
2654
- [useThread, useComposer],
2724
+ [threadStore, composerStore],
2655
2725
  (t, c) => t.isRunning || !c.isEditing || c.isEmpty
2656
2726
  );
2657
2727
  const callback = _react.useCallback.call(void 0, () => {
2658
- const composerState = useComposer.getState();
2728
+ const composerState = composerStore.getState();
2659
2729
  if (!composerState.isEditing) return;
2660
2730
  composerState.send();
2661
- useViewport.getState().scrollToBottom();
2662
- useNewComposer.getState().focus();
2663
- }, [useNewComposer, useComposer, useViewport]);
2731
+ threadViewportStore.getState().scrollToBottom();
2732
+ threadComposerStore.getState().focus();
2733
+ }, [threadComposerStore, composerStore, threadViewportStore]);
2664
2734
  if (disabled) return null;
2665
2735
  return callback;
2666
2736
  };
@@ -2668,30 +2738,30 @@ var useComposerSend = () => {
2668
2738
  // src/primitive-hooks/composer/useComposerAddAttachment.tsx
2669
2739
 
2670
2740
  var useComposerAddAttachment = () => {
2671
- const { useComposer, useThreadRuntime } = useThreadContext();
2672
2741
  const disabled = useComposer((c) => !c.isEditing);
2742
+ const threadComposerStore = useThreadComposerStore();
2743
+ const threadRuntimeStore = useThreadRuntimeStore();
2673
2744
  const callback = _react.useCallback.call(void 0, () => {
2674
- const { addAttachment } = useComposer.getState();
2675
- const { attachmentAccept } = useThreadRuntime.getState().composer;
2745
+ const { addAttachment } = threadComposerStore.getState();
2746
+ const { attachmentAccept } = threadRuntimeStore.getState().composer;
2676
2747
  const input = document.createElement("input");
2677
2748
  input.type = "file";
2678
2749
  if (attachmentAccept !== "*") {
2679
2750
  input.accept = attachmentAccept;
2680
2751
  }
2681
2752
  input.onchange = (e) => {
2682
- const file = _optionalChain([e, 'access', _109 => _109.target, 'access', _110 => _110.files, 'optionalAccess', _111 => _111[0]]);
2753
+ const file = _optionalChain([e, 'access', _103 => _103.target, 'access', _104 => _104.files, 'optionalAccess', _105 => _105[0]]);
2683
2754
  if (!file) return;
2684
2755
  addAttachment(file);
2685
2756
  };
2686
2757
  input.click();
2687
- }, [useComposer, useThreadRuntime]);
2758
+ }, [threadComposerStore, threadRuntimeStore]);
2688
2759
  if (disabled) return null;
2689
2760
  return callback;
2690
2761
  };
2691
2762
 
2692
2763
  // src/primitive-hooks/contentPart/useContentPartDisplay.tsx
2693
2764
  var useContentPartDisplay = () => {
2694
- const { useContentPart } = useContentPartContext();
2695
2765
  const display = useContentPart((c) => {
2696
2766
  if (c.part.type !== "ui")
2697
2767
  throw new Error(
@@ -2704,7 +2774,6 @@ var useContentPartDisplay = () => {
2704
2774
 
2705
2775
  // src/primitive-hooks/contentPart/useContentPartImage.tsx
2706
2776
  var useContentPartImage = () => {
2707
- const { useContentPart } = useContentPartContext();
2708
2777
  const image = useContentPart((c) => {
2709
2778
  if (c.part.type !== "image")
2710
2779
  throw new Error(
@@ -2717,7 +2786,6 @@ var useContentPartImage = () => {
2717
2786
 
2718
2787
  // src/primitive-hooks/contentPart/useContentPartText.tsx
2719
2788
  var useContentPartText = () => {
2720
- const { useContentPart } = useContentPartContext();
2721
2789
  const text = useContentPart((c) => {
2722
2790
  if (c.part.type !== "text")
2723
2791
  throw new Error(
@@ -2730,9 +2798,10 @@ var useContentPartText = () => {
2730
2798
 
2731
2799
  // src/primitive-hooks/message/useMessageIf.tsx
2732
2800
  var useMessageIf = (props) => {
2733
- const { useMessage, useMessageUtils } = useMessageContext();
2801
+ const messageStore = useMessageStore();
2802
+ const messageUtilsStore = useMessageUtilsStore();
2734
2803
  return useCombinedStore(
2735
- [useMessage, useMessageUtils],
2804
+ [messageStore, messageUtilsStore],
2736
2805
  ({ message, branches, isLast }, { isCopied, isHovering, isSpeaking }) => {
2737
2806
  if (props.hasBranches === true && branches.length < 2) return false;
2738
2807
  if (props.user && message.role !== "user") return false;
@@ -2754,9 +2823,10 @@ var useMessageIf = (props) => {
2754
2823
 
2755
2824
  // src/primitive-hooks/thread/useThreadIf.tsx
2756
2825
  var useThreadIf = (props) => {
2757
- const { useThread, useThreadMessages } = useThreadContext();
2826
+ const threadStore = useThreadStore();
2827
+ const threadMessagesStore = useThreadMessagesStore();
2758
2828
  return useCombinedStore(
2759
- [useThread, useThreadMessages],
2829
+ [threadStore, threadMessagesStore],
2760
2830
  (thread, messages) => {
2761
2831
  if (props.empty === true && messages.length !== 0) return false;
2762
2832
  if (props.empty === false && messages.length === 0) return false;
@@ -2777,12 +2847,13 @@ var useThreadEmpty = () => {
2777
2847
  // src/primitive-hooks/thread/useThreadScrollToBottom.tsx
2778
2848
 
2779
2849
  var useThreadScrollToBottom = () => {
2780
- const { useComposer, useViewport } = useThreadContext();
2781
- const isAtBottom = useViewport((s) => s.isAtBottom);
2850
+ const isAtBottom = useThreadViewport((s) => s.isAtBottom);
2851
+ const threadViewportStore = useThreadViewportStore();
2852
+ const threadComposerStore = useThreadComposerStore();
2782
2853
  const handleScrollToBottom = _react.useCallback.call(void 0, () => {
2783
- useViewport.getState().scrollToBottom();
2784
- useComposer.getState().focus();
2785
- }, [useViewport, useComposer]);
2854
+ threadViewportStore.getState().scrollToBottom();
2855
+ threadComposerStore.getState().focus();
2856
+ }, [threadViewportStore, threadComposerStore]);
2786
2857
  if (isAtBottom) return null;
2787
2858
  return handleScrollToBottom;
2788
2859
  };
@@ -2793,19 +2864,20 @@ var useThreadSuggestion = ({
2793
2864
  prompt,
2794
2865
  autoSend
2795
2866
  }) => {
2796
- const { useThread, useComposer } = useThreadContext();
2867
+ const threadStore = useThreadStore();
2868
+ const composerStore = useThreadComposerStore();
2797
2869
  const append = useAppendMessage();
2798
2870
  const disabled = useThread((t) => t.isDisabled);
2799
2871
  const callback = _react.useCallback.call(void 0, () => {
2800
- const thread = useThread.getState();
2801
- const composer = useComposer.getState();
2872
+ const thread = threadStore.getState();
2873
+ const composer = composerStore.getState();
2802
2874
  if (autoSend && !thread.isRunning) {
2803
2875
  append(prompt);
2804
2876
  composer.setText("");
2805
2877
  } else {
2806
2878
  composer.setText(prompt);
2807
2879
  }
2808
- }, [useThread, useComposer, autoSend, append, prompt]);
2880
+ }, [threadStore, composerStore, autoSend, append, prompt]);
2809
2881
  if (disabled) return null;
2810
2882
  return callback;
2811
2883
  };
@@ -2831,10 +2903,11 @@ var useActionBarFloatStatus = ({
2831
2903
  autohide,
2832
2904
  autohideFloat
2833
2905
  }) => {
2834
- const { useThread } = useThreadContext();
2835
- const { useMessage, useMessageUtils } = useMessageContext();
2906
+ const threadStore = useThreadStore();
2907
+ const messageStore = useMessageStore();
2908
+ const messageUtilsStore = useMessageUtilsStore();
2836
2909
  return useCombinedStore(
2837
- [useThread, useMessage, useMessageUtils],
2910
+ [threadStore, messageStore, messageUtilsStore],
2838
2911
  (t, m, mu) => {
2839
2912
  if (hideWhenRunning && t.isRunning) return "hidden" /* Hidden */;
2840
2913
  const autohideEnabled = autohide === "always" || autohide === "not-last" && !m.isLast;
@@ -2892,7 +2965,7 @@ var createActionButton = (displayName, useActionButton, forwardProps = []) => {
2892
2965
  ref: forwardedRef,
2893
2966
  disabled: primitiveProps.disabled || !callback,
2894
2967
  onClick: _primitive.composeEventHandlers.call(void 0, primitiveProps.onClick, () => {
2895
- _optionalChain([callback, 'optionalCall', _112 => _112()]);
2968
+ _optionalChain([callback, 'optionalCall', _106 => _106()]);
2896
2969
  })
2897
2970
  }
2898
2971
  );
@@ -2948,11 +3021,12 @@ var ActionBarPrimitiveStopSpeaking = _react.forwardRef.call(void 0, (props, ref)
2948
3021
  ...props,
2949
3022
  ref,
2950
3023
  onClick: _primitive.composeEventHandlers.call(void 0, props.onClick, () => {
2951
- _optionalChain([callback, 'optionalCall', _113 => _113()]);
3024
+ _optionalChain([callback, 'optionalCall', _107 => _107()]);
2952
3025
  })
2953
3026
  }
2954
3027
  );
2955
3028
  });
3029
+ ActionBarPrimitiveStopSpeaking.displayName = "ActionBarPrimitive.StopSpeaking";
2956
3030
 
2957
3031
  // src/primitives/assistantModal/index.ts
2958
3032
  var assistantModal_exports = {};
@@ -2973,12 +3047,12 @@ var _reactpopover = require('@radix-ui/react-popover'); var PopoverPrimitive2 =
2973
3047
 
2974
3048
  var useOnComposerFocus = (callback) => {
2975
3049
  const callbackRef = _reactusecallbackref.useCallbackRef.call(void 0, callback);
2976
- const { useComposer } = useThreadContext();
3050
+ const threadComposerStore = useThreadComposerStore();
2977
3051
  _react.useEffect.call(void 0, () => {
2978
- return useComposer.getState().onFocus(() => {
3052
+ return threadComposerStore.getState().onFocus(() => {
2979
3053
  callbackRef();
2980
3054
  });
2981
- }, [useComposer, callbackRef]);
3055
+ }, [threadComposerStore, callbackRef]);
2982
3056
  };
2983
3057
 
2984
3058
  // src/primitives/assistantModal/scope.tsx
@@ -3160,10 +3234,10 @@ var useManagedRef = (callback) => {
3160
3234
  var _reactcomposerefs = require('@radix-ui/react-compose-refs');
3161
3235
 
3162
3236
  var useIsHoveringRef = () => {
3163
- const { useMessageUtils } = useMessageContext();
3237
+ const messageUtilsStore = useMessageUtilsStore();
3164
3238
  const callbackRef = _react.useCallback.call(void 0,
3165
3239
  (el) => {
3166
- const setIsHovering = useMessageUtils.getState().setIsHovering;
3240
+ const setIsHovering = messageUtilsStore.getState().setIsHovering;
3167
3241
  const handleMouseEnter = () => {
3168
3242
  setIsHovering(true);
3169
3243
  };
@@ -3178,14 +3252,14 @@ var useIsHoveringRef = () => {
3178
3252
  setIsHovering(false);
3179
3253
  };
3180
3254
  },
3181
- [useMessageUtils]
3255
+ [messageUtilsStore]
3182
3256
  );
3183
3257
  return useManagedRef(callbackRef);
3184
3258
  };
3185
- var MessagePrimitiveRoot = _react.forwardRef.call(void 0, ({ onMouseEnter, onMouseLeave, ...rest }, forwardRef30) => {
3259
+ var MessagePrimitiveRoot = _react.forwardRef.call(void 0, (props, forwardRef30) => {
3186
3260
  const isHoveringRef = useIsHoveringRef();
3187
3261
  const ref = _reactcomposerefs.useComposedRefs.call(void 0, forwardRef30, isHoveringRef);
3188
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactprimitive.Primitive.div, { ...rest, ref });
3262
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactprimitive.Primitive.div, { ...props, ref });
3189
3263
  });
3190
3264
  MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
3191
3265
 
@@ -3225,7 +3299,7 @@ var toContentPartStatus = (message, partIndex, part) => {
3225
3299
  return message.status;
3226
3300
  };
3227
3301
  var EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });
3228
- var getContentPartState = ({ message }, useContentPart, partIndex) => {
3302
+ var getContentPartState = ({ message }, useContentPart2, partIndex) => {
3229
3303
  let part = message.content[partIndex];
3230
3304
  if (!part) {
3231
3305
  if (message.content.length === 0 && partIndex === 0) {
@@ -3233,20 +3307,22 @@ var getContentPartState = ({ message }, useContentPart, partIndex) => {
3233
3307
  } else {
3234
3308
  return null;
3235
3309
  }
3310
+ } else if (message.content.length === 1 && part.type === "text" && part.text.length === 0) {
3311
+ part = EMPTY_CONTENT;
3236
3312
  }
3237
3313
  const status = toContentPartStatus(message, partIndex, part);
3238
- const currentState = _optionalChain([useContentPart, 'optionalAccess', _114 => _114.getState, 'call', _115 => _115()]);
3314
+ const currentState = _optionalChain([useContentPart2, 'optionalAccess', _108 => _108.getState, 'call', _109 => _109()]);
3239
3315
  if (currentState && currentState.part === part && currentState.status === status)
3240
3316
  return null;
3241
3317
  return Object.freeze({ part, status });
3242
3318
  };
3243
3319
  var useContentPartContext2 = (partIndex) => {
3244
- const { useMessage } = useMessageContext();
3320
+ const messageStore = useMessageStore();
3245
3321
  const [context] = _react.useState.call(void 0, () => {
3246
- const useContentPart = _zustand.create.call(void 0,
3247
- () => getContentPartState(useMessage.getState(), void 0, partIndex)
3322
+ const useContentPart2 = _zustand.create.call(void 0,
3323
+ () => getContentPartState(messageStore.getState(), void 0, partIndex)
3248
3324
  );
3249
- return { useContentPart };
3325
+ return { useContentPart: useContentPart2 };
3250
3326
  });
3251
3327
  _react.useEffect.call(void 0, () => {
3252
3328
  const syncContentPart = (message) => {
@@ -3258,9 +3334,9 @@ var useContentPartContext2 = (partIndex) => {
3258
3334
  if (!newState) return;
3259
3335
  writableStore(context.useContentPart).setState(newState, true);
3260
3336
  };
3261
- syncContentPart(useMessage.getState());
3262
- return useMessage.subscribe(syncContentPart);
3263
- }, [context, useMessage, partIndex]);
3337
+ syncContentPart(messageStore.getState());
3338
+ return messageStore.subscribe(syncContentPart);
3339
+ }, [context, messageStore, partIndex]);
3264
3340
  return context;
3265
3341
  };
3266
3342
  var ContentPartProvider = ({
@@ -3308,7 +3384,6 @@ ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
3308
3384
 
3309
3385
  // src/primitives/contentPart/ContentPartInProgress.tsx
3310
3386
  var ContentPartPrimitiveInProgress = ({ children }) => {
3311
- const { useContentPart } = useContentPartContext();
3312
3387
  const isInProgress = useContentPart((c) => c.status.type === "running");
3313
3388
  return isInProgress ? children : null;
3314
3389
  };
@@ -3320,7 +3395,6 @@ var ToolUIDisplay = ({
3320
3395
  UI,
3321
3396
  ...props
3322
3397
  }) => {
3323
- const { useToolUIs } = useAssistantContext();
3324
3398
  const Render = _nullishCoalesce(useToolUIs((s) => s.getToolUI(props.part.toolName)), () => ( UI));
3325
3399
  if (!Render) return null;
3326
3400
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Render, { ...props });
@@ -3335,24 +3409,24 @@ var defaultComponents = {
3335
3409
  };
3336
3410
  var MessageContentPartComponent = ({
3337
3411
  components: {
3338
- Empty = defaultComponents.Text,
3339
3412
  Text: Text2 = defaultComponents.Text,
3413
+ Empty,
3340
3414
  Image: Image2 = defaultComponents.Image,
3341
3415
  UI = defaultComponents.UI,
3342
3416
  tools: { by_name = {}, Fallback: Fallback2 = void 0 } = {}
3343
3417
  } = {}
3344
3418
  }) => {
3345
- const { useThreadActions } = useThreadContext();
3346
- const { useMessage } = useMessageContext();
3347
- const addToolResult = useThreadActions((t) => t.addToolResult);
3348
- const { useContentPart } = useContentPartContext();
3419
+ const messageStore = useMessageStore();
3420
+ const threadActionsStore = useThreadActionsStore();
3349
3421
  const { part, status } = useContentPart();
3350
3422
  const type = part.type;
3351
3423
  switch (type) {
3352
3424
  case "text":
3353
3425
  if (status.type === "requires-action")
3354
3426
  throw new Error("Encountered unexpected requires-action status");
3355
- if (part === EMPTY_CONTENT) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Empty, { part, status });
3427
+ if (part === EMPTY_CONTENT && !!Empty) {
3428
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Empty, { status });
3429
+ }
3356
3430
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Text2, { part, status });
3357
3431
  case "image":
3358
3432
  if (status.type === "requires-action")
@@ -3364,8 +3438,8 @@ var MessageContentPartComponent = ({
3364
3438
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UI, { part, status });
3365
3439
  case "tool-call": {
3366
3440
  const Tool = by_name[part.toolName] || Fallback2;
3367
- const addResult = (result) => addToolResult({
3368
- messageId: useMessage.getState().message.id,
3441
+ const addResult = (result) => threadActionsStore.getState().addToolResult({
3442
+ messageId: messageStore.getState().message.id,
3369
3443
  toolName: part.toolName,
3370
3444
  toolCallId: part.toolCallId,
3371
3445
  result
@@ -3393,12 +3467,11 @@ var MessageContentPartImpl = ({
3393
3467
  };
3394
3468
  var MessageContentPart = _react.memo.call(void 0,
3395
3469
  MessageContentPartImpl,
3396
- (prev, next) => prev.partIndex === next.partIndex && _optionalChain([prev, 'access', _116 => _116.components, 'optionalAccess', _117 => _117.Text]) === _optionalChain([next, 'access', _118 => _118.components, 'optionalAccess', _119 => _119.Text]) && _optionalChain([prev, 'access', _120 => _120.components, 'optionalAccess', _121 => _121.Image]) === _optionalChain([next, 'access', _122 => _122.components, 'optionalAccess', _123 => _123.Image]) && _optionalChain([prev, 'access', _124 => _124.components, 'optionalAccess', _125 => _125.UI]) === _optionalChain([next, 'access', _126 => _126.components, 'optionalAccess', _127 => _127.UI]) && _optionalChain([prev, 'access', _128 => _128.components, 'optionalAccess', _129 => _129.tools]) === _optionalChain([next, 'access', _130 => _130.components, 'optionalAccess', _131 => _131.tools])
3470
+ (prev, next) => prev.partIndex === next.partIndex && _optionalChain([prev, 'access', _110 => _110.components, 'optionalAccess', _111 => _111.Text]) === _optionalChain([next, 'access', _112 => _112.components, 'optionalAccess', _113 => _113.Text]) && _optionalChain([prev, 'access', _114 => _114.components, 'optionalAccess', _115 => _115.Image]) === _optionalChain([next, 'access', _116 => _116.components, 'optionalAccess', _117 => _117.Image]) && _optionalChain([prev, 'access', _118 => _118.components, 'optionalAccess', _119 => _119.UI]) === _optionalChain([next, 'access', _120 => _120.components, 'optionalAccess', _121 => _121.UI]) && _optionalChain([prev, 'access', _122 => _122.components, 'optionalAccess', _123 => _123.tools]) === _optionalChain([next, 'access', _124 => _124.components, 'optionalAccess', _125 => _125.tools])
3397
3471
  );
3398
3472
  var MessagePrimitiveContent = ({
3399
3473
  components
3400
3474
  }) => {
3401
- const { useMessage } = useMessageContext();
3402
3475
  const contentLength = useMessage((s) => s.message.content.length) || 1;
3403
3476
  return Array.from({ length: contentLength }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageContentPart, { partIndex: index, components }, index));
3404
3477
  };
@@ -3420,42 +3493,64 @@ var AttachmentContext = _react.createContext.call(void 0,
3420
3493
  );
3421
3494
  function useAttachmentContext(options) {
3422
3495
  const context = _react.useContext.call(void 0, AttachmentContext);
3423
- if (_optionalChain([options, 'optionalAccess', _132 => _132.type]) === "composer" && _optionalChain([context, 'optionalAccess', _133 => _133.type]) !== "composer")
3496
+ if (!_optionalChain([options, 'optionalAccess', _126 => _126.optional]) && !context)
3424
3497
  throw new Error(
3425
- "This component must be used within a ComposerPrimitive.Attachments component."
3498
+ "This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
3426
3499
  );
3427
- if (_optionalChain([options, 'optionalAccess', _134 => _134.type]) === "message" && _optionalChain([context, 'optionalAccess', _135 => _135.type]) !== "message")
3500
+ return context;
3501
+ }
3502
+ function useComposerAttachmentContext(options) {
3503
+ const context = useAttachmentContext(options);
3504
+ if (!context) return null;
3505
+ if (context.type !== "composer")
3428
3506
  throw new Error(
3429
- "This component must be used within a MessagePrimitive.Attachments component."
3507
+ "This component must be used within a ComposerPrimitive.Attachments component."
3430
3508
  );
3431
- if (!_optionalChain([options, 'optionalAccess', _136 => _136.optional]) && !context)
3509
+ return context;
3510
+ }
3511
+ function useMessageAttachmentContext(options) {
3512
+ const context = useAttachmentContext(options);
3513
+ if (!context) return null;
3514
+ if (context.type !== "message")
3432
3515
  throw new Error(
3433
- "This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
3516
+ "This component must be used within a MessagePrimitive.Attachments component."
3434
3517
  );
3435
3518
  return context;
3436
3519
  }
3520
+ var { useAttachment, useAttachmentStore } = createContextStoreHook(
3521
+ useAttachmentContext,
3522
+ "useAttachment"
3523
+ );
3524
+ var {
3525
+ useAttachment: useComposerAttachment,
3526
+ useAttachmentStore: useComposerAttachmentStore
3527
+ } = createContextStoreHook(useComposerAttachmentContext, "useAttachment");
3528
+ var {
3529
+ useAttachment: useMessageAttachment,
3530
+ useAttachmentStore: useMessageAttachmentStore
3531
+ } = createContextStoreHook(useMessageAttachmentContext, "useAttachment");
3437
3532
 
3438
3533
  // src/context/providers/MessageAttachmentProvider.tsx
3439
3534
 
3440
3535
 
3441
3536
 
3442
- var getAttachment = ({ message }, useAttachment, partIndex) => {
3537
+ var getAttachment = ({ message }, useAttachment2, partIndex) => {
3443
3538
  if (message.role !== "user") return null;
3444
3539
  const attachments = message.attachments;
3445
- let attachment = attachments[partIndex];
3540
+ const attachment = attachments[partIndex];
3446
3541
  if (!attachment) return null;
3447
- const currentState = _optionalChain([useAttachment, 'optionalAccess', _137 => _137.getState, 'call', _138 => _138()]);
3542
+ const currentState = _optionalChain([useAttachment2, 'optionalAccess', _127 => _127.getState, 'call', _128 => _128()]);
3448
3543
  if (currentState && currentState.attachment === attachment) return null;
3449
3544
  return Object.freeze({ attachment });
3450
3545
  };
3451
- var useMessageAttachmentContext = (partIndex) => {
3452
- const { useMessage } = useMessageContext();
3546
+ var useMessageAttachmentContext2 = (partIndex) => {
3547
+ const messageStore = useMessageStore();
3453
3548
  const [context] = _react.useState.call(void 0,
3454
3549
  () => {
3455
- const useAttachment = _zustand.create.call(void 0,
3456
- () => getAttachment(useMessage.getState(), void 0, partIndex)
3550
+ const useAttachment2 = _zustand.create.call(void 0,
3551
+ () => getAttachment(messageStore.getState(), void 0, partIndex)
3457
3552
  );
3458
- return { type: "message", useAttachment };
3553
+ return { type: "message", useAttachment: useAttachment2 };
3459
3554
  }
3460
3555
  );
3461
3556
  _react.useEffect.call(void 0, () => {
@@ -3468,16 +3563,16 @@ var useMessageAttachmentContext = (partIndex) => {
3468
3563
  if (!newState) return;
3469
3564
  writableStore(context.useAttachment).setState(newState, true);
3470
3565
  };
3471
- syncAttachment(useMessage.getState());
3472
- return useMessage.subscribe(syncAttachment);
3473
- }, [context, useMessage, partIndex]);
3566
+ syncAttachment(messageStore.getState());
3567
+ return messageStore.subscribe(syncAttachment);
3568
+ }, [context, messageStore, partIndex]);
3474
3569
  return context;
3475
3570
  };
3476
3571
  var MessageAttachmentProvider = ({
3477
3572
  attachmentIndex: partIndex,
3478
3573
  children
3479
3574
  }) => {
3480
- const context = useMessageAttachmentContext(partIndex);
3575
+ const context = useMessageAttachmentContext2(partIndex);
3481
3576
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AttachmentContext.Provider, { value: context, children });
3482
3577
  };
3483
3578
 
@@ -3487,19 +3582,18 @@ var getComponent = (components, attachment) => {
3487
3582
  const type = attachment.type;
3488
3583
  switch (type) {
3489
3584
  case "image":
3490
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _139 => _139.Image]), () => ( _optionalChain([components, 'optionalAccess', _140 => _140.Attachment])));
3585
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _129 => _129.Image]), () => ( _optionalChain([components, 'optionalAccess', _130 => _130.Attachment])));
3491
3586
  case "document":
3492
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _141 => _141.Document]), () => ( _optionalChain([components, 'optionalAccess', _142 => _142.Attachment])));
3587
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _131 => _131.Document]), () => ( _optionalChain([components, 'optionalAccess', _132 => _132.Attachment])));
3493
3588
  case "file":
3494
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _143 => _143.File]), () => ( _optionalChain([components, 'optionalAccess', _144 => _144.Attachment])));
3589
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _133 => _133.File]), () => ( _optionalChain([components, 'optionalAccess', _134 => _134.Attachment])));
3495
3590
  default:
3496
3591
  const _exhaustiveCheck = type;
3497
3592
  throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
3498
3593
  }
3499
3594
  };
3500
3595
  var AttachmentComponent = ({ components }) => {
3501
- const { useAttachment } = useAttachmentContext({ type: "message" });
3502
- const Component = useAttachment(
3596
+ const Component = useMessageAttachment(
3503
3597
  (a) => getComponent(components, a.attachment)
3504
3598
  );
3505
3599
  if (!Component) return null;
@@ -3510,10 +3604,9 @@ var MessageAttachmentImpl = ({ components, attachmentIndex }) => {
3510
3604
  };
3511
3605
  var MessageAttachment = _react.memo.call(void 0,
3512
3606
  MessageAttachmentImpl,
3513
- (prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _145 => _145.components, 'optionalAccess', _146 => _146.Image]) === _optionalChain([next, 'access', _147 => _147.components, 'optionalAccess', _148 => _148.Image]) && _optionalChain([prev, 'access', _149 => _149.components, 'optionalAccess', _150 => _150.Document]) === _optionalChain([next, 'access', _151 => _151.components, 'optionalAccess', _152 => _152.Document]) && _optionalChain([prev, 'access', _153 => _153.components, 'optionalAccess', _154 => _154.File]) === _optionalChain([next, 'access', _155 => _155.components, 'optionalAccess', _156 => _156.File]) && _optionalChain([prev, 'access', _157 => _157.components, 'optionalAccess', _158 => _158.Attachment]) === _optionalChain([next, 'access', _159 => _159.components, 'optionalAccess', _160 => _160.Attachment])
3607
+ (prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _135 => _135.components, 'optionalAccess', _136 => _136.Image]) === _optionalChain([next, 'access', _137 => _137.components, 'optionalAccess', _138 => _138.Image]) && _optionalChain([prev, 'access', _139 => _139.components, 'optionalAccess', _140 => _140.Document]) === _optionalChain([next, 'access', _141 => _141.components, 'optionalAccess', _142 => _142.Document]) && _optionalChain([prev, 'access', _143 => _143.components, 'optionalAccess', _144 => _144.File]) === _optionalChain([next, 'access', _145 => _145.components, 'optionalAccess', _146 => _146.File]) && _optionalChain([prev, 'access', _147 => _147.components, 'optionalAccess', _148 => _148.Attachment]) === _optionalChain([next, 'access', _149 => _149.components, 'optionalAccess', _150 => _150.Attachment])
3514
3608
  );
3515
3609
  var MessagePrimitiveAttachments = ({ components }) => {
3516
- const { useMessage } = useMessageContext();
3517
3610
  const attachmentsCount = useMessage(({ message }) => {
3518
3611
  if (message.role !== "user") return 0;
3519
3612
  return message.attachments.length;
@@ -3595,8 +3688,8 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
3595
3688
  onKeyDown,
3596
3689
  ...rest
3597
3690
  }, forwardedRef) => {
3598
- const { useThread } = useThreadContext();
3599
- const { useComposer, type } = useComposerContext();
3691
+ const threadStore = useThreadStore();
3692
+ const composerStore = useComposerStore();
3600
3693
  const value = useComposer((c) => {
3601
3694
  if (!c.isEditing) return "";
3602
3695
  return c.text;
@@ -3606,7 +3699,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
3606
3699
  const textareaRef = _react.useRef.call(void 0, null);
3607
3700
  const ref = _reactcomposerefs.useComposedRefs.call(void 0, forwardedRef, textareaRef);
3608
3701
  _reactuseescapekeydown.useEscapeKeydown.call(void 0, (e) => {
3609
- const composer = useComposer.getState();
3702
+ const composer = composerStore.getState();
3610
3703
  if (composer.canCancel) {
3611
3704
  composer.cancel();
3612
3705
  e.preventDefault();
@@ -3616,10 +3709,10 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
3616
3709
  if (isDisabled) return;
3617
3710
  if (e.nativeEvent.isComposing) return;
3618
3711
  if (e.key === "Enter" && e.shiftKey === false) {
3619
- const { isRunning } = useThread.getState();
3712
+ const { isRunning } = threadStore.getState();
3620
3713
  if (!isRunning) {
3621
3714
  e.preventDefault();
3622
- _optionalChain([textareaRef, 'access', _161 => _161.current, 'optionalAccess', _162 => _162.closest, 'call', _163 => _163("form"), 'optionalAccess', _164 => _164.requestSubmit, 'call', _165 => _165()]);
3715
+ _optionalChain([textareaRef, 'access', _151 => _151.current, 'optionalAccess', _152 => _152.closest, 'call', _153 => _153("form"), 'optionalAccess', _154 => _154.requestSubmit, 'call', _155 => _155()]);
3623
3716
  }
3624
3717
  }
3625
3718
  };
@@ -3635,7 +3728,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
3635
3728
  }, [autoFocusEnabled]);
3636
3729
  _react.useEffect.call(void 0, () => focus(), [focus]);
3637
3730
  useOnComposerFocus(() => {
3638
- if (type === "new") {
3731
+ if (composerStore.getState().type === "thread") {
3639
3732
  focus();
3640
3733
  }
3641
3734
  });
@@ -3648,7 +3741,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
3648
3741
  ref,
3649
3742
  disabled: isDisabled,
3650
3743
  onChange: _primitive.composeEventHandlers.call(void 0, onChange, (e) => {
3651
- const composerState = useComposer.getState();
3744
+ const composerState = composerStore.getState();
3652
3745
  if (!composerState.isEditing) return;
3653
3746
  return composerState.setText(e.target.value);
3654
3747
  }),
@@ -3684,21 +3777,21 @@ var ComposerPrimitiveAddAttachment = createActionButton(
3684
3777
 
3685
3778
 
3686
3779
 
3687
- var getAttachment2 = ({ attachments }, useAttachment, partIndex) => {
3688
- let attachment = attachments[partIndex];
3780
+ var getAttachment2 = ({ attachments }, useAttachment2, partIndex) => {
3781
+ const attachment = attachments[partIndex];
3689
3782
  if (!attachment) return null;
3690
- const currentState = _optionalChain([useAttachment, 'optionalAccess', _166 => _166.getState, 'call', _167 => _167()]);
3783
+ const currentState = _optionalChain([useAttachment2, 'optionalAccess', _156 => _156.getState, 'call', _157 => _157()]);
3691
3784
  if (currentState && currentState.attachment === attachment) return null;
3692
3785
  return Object.freeze({ attachment });
3693
3786
  };
3694
- var useComposerAttachmentContext = (partIndex) => {
3695
- const { useComposer } = useThreadContext();
3787
+ var useComposerAttachmentContext2 = (partIndex) => {
3788
+ const threadComposerStore = useThreadComposerStore();
3696
3789
  const [context] = _react.useState.call(void 0,
3697
3790
  () => {
3698
- const useAttachment = _zustand.create.call(void 0,
3699
- () => getAttachment2(useComposer.getState(), void 0, partIndex)
3791
+ const useAttachment2 = _zustand.create.call(void 0,
3792
+ () => getAttachment2(threadComposerStore.getState(), void 0, partIndex)
3700
3793
  );
3701
- return { type: "composer", useAttachment };
3794
+ return { type: "composer", useAttachment: useAttachment2 };
3702
3795
  }
3703
3796
  );
3704
3797
  _react.useEffect.call(void 0, () => {
@@ -3711,13 +3804,13 @@ var useComposerAttachmentContext = (partIndex) => {
3711
3804
  if (!newState) return;
3712
3805
  writableStore(context.useAttachment).setState(newState, true);
3713
3806
  };
3714
- syncAttachment(useComposer.getState());
3715
- return useComposer.subscribe(syncAttachment);
3716
- }, [context, useComposer, partIndex]);
3807
+ syncAttachment(threadComposerStore.getState());
3808
+ return threadComposerStore.subscribe(syncAttachment);
3809
+ }, [context, threadComposerStore, partIndex]);
3717
3810
  return context;
3718
3811
  };
3719
3812
  var ComposerAttachmentProvider = ({ attachmentIndex: partIndex, children }) => {
3720
- const context = useComposerAttachmentContext(partIndex);
3813
+ const context = useComposerAttachmentContext2(partIndex);
3721
3814
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AttachmentContext.Provider, { value: context, children });
3722
3815
  };
3723
3816
 
@@ -3727,19 +3820,18 @@ var getComponent2 = (components, attachment) => {
3727
3820
  const type = attachment.type;
3728
3821
  switch (type) {
3729
3822
  case "image":
3730
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _168 => _168.Image]), () => ( _optionalChain([components, 'optionalAccess', _169 => _169.Attachment])));
3823
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _158 => _158.Image]), () => ( _optionalChain([components, 'optionalAccess', _159 => _159.Attachment])));
3731
3824
  case "document":
3732
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _170 => _170.Document]), () => ( _optionalChain([components, 'optionalAccess', _171 => _171.Attachment])));
3825
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _160 => _160.Document]), () => ( _optionalChain([components, 'optionalAccess', _161 => _161.Attachment])));
3733
3826
  case "file":
3734
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _172 => _172.File]), () => ( _optionalChain([components, 'optionalAccess', _173 => _173.Attachment])));
3827
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _162 => _162.File]), () => ( _optionalChain([components, 'optionalAccess', _163 => _163.Attachment])));
3735
3828
  default:
3736
3829
  const _exhaustiveCheck = type;
3737
3830
  throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
3738
3831
  }
3739
3832
  };
3740
3833
  var AttachmentComponent2 = ({ components }) => {
3741
- const { useAttachment } = useAttachmentContext({ type: "composer" });
3742
- const Component = useAttachment(
3834
+ const Component = useComposerAttachment(
3743
3835
  (a) => getComponent2(components, a.attachment)
3744
3836
  );
3745
3837
  if (!Component) return null;
@@ -3750,11 +3842,10 @@ var ComposerAttachmentImpl = ({ components, attachmentIndex }) => {
3750
3842
  };
3751
3843
  var ComposerAttachment = _react.memo.call(void 0,
3752
3844
  ComposerAttachmentImpl,
3753
- (prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _174 => _174.components, 'optionalAccess', _175 => _175.Image]) === _optionalChain([next, 'access', _176 => _176.components, 'optionalAccess', _177 => _177.Image]) && _optionalChain([prev, 'access', _178 => _178.components, 'optionalAccess', _179 => _179.Document]) === _optionalChain([next, 'access', _180 => _180.components, 'optionalAccess', _181 => _181.Document]) && _optionalChain([prev, 'access', _182 => _182.components, 'optionalAccess', _183 => _183.File]) === _optionalChain([next, 'access', _184 => _184.components, 'optionalAccess', _185 => _185.File]) && _optionalChain([prev, 'access', _186 => _186.components, 'optionalAccess', _187 => _187.Attachment]) === _optionalChain([next, 'access', _188 => _188.components, 'optionalAccess', _189 => _189.Attachment])
3845
+ (prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _164 => _164.components, 'optionalAccess', _165 => _165.Image]) === _optionalChain([next, 'access', _166 => _166.components, 'optionalAccess', _167 => _167.Image]) && _optionalChain([prev, 'access', _168 => _168.components, 'optionalAccess', _169 => _169.Document]) === _optionalChain([next, 'access', _170 => _170.components, 'optionalAccess', _171 => _171.Document]) && _optionalChain([prev, 'access', _172 => _172.components, 'optionalAccess', _173 => _173.File]) === _optionalChain([next, 'access', _174 => _174.components, 'optionalAccess', _175 => _175.File]) && _optionalChain([prev, 'access', _176 => _176.components, 'optionalAccess', _177 => _177.Attachment]) === _optionalChain([next, 'access', _178 => _178.components, 'optionalAccess', _179 => _179.Attachment])
3754
3846
  );
3755
3847
  var ComposerPrimitiveAttachments = ({ components }) => {
3756
- const { useComposer } = useThreadContext();
3757
- const attachmentsCount = useComposer((s) => s.attachments.length);
3848
+ const attachmentsCount = useThreadComposer((s) => s.attachments.length);
3758
3849
  return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3759
3850
  ComposerAttachment,
3760
3851
  {
@@ -3879,12 +3970,12 @@ var useOnResizeContent = (callback) => {
3879
3970
 
3880
3971
  var useOnScrollToBottom = (callback) => {
3881
3972
  const callbackRef = _reactusecallbackref.useCallbackRef.call(void 0, callback);
3882
- const { useViewport } = useThreadContext();
3973
+ const threadViewportStore = useThreadViewportStore();
3883
3974
  _react.useEffect.call(void 0, () => {
3884
- return useViewport.getState().onScrollToBottom(() => {
3975
+ return threadViewportStore.getState().onScrollToBottom(() => {
3885
3976
  callbackRef();
3886
3977
  });
3887
- }, [useViewport, callbackRef]);
3978
+ }, [threadViewportStore, callbackRef]);
3888
3979
  };
3889
3980
 
3890
3981
  // src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
@@ -3892,7 +3983,7 @@ var useThreadViewportAutoScroll = ({
3892
3983
  autoScroll = true
3893
3984
  }) => {
3894
3985
  const divRef = _react.useRef.call(void 0, null);
3895
- const { useViewport } = useThreadContext();
3986
+ const threadViewportStore = useThreadViewportStore();
3896
3987
  const lastScrollTop = _react.useRef.call(void 0, 0);
3897
3988
  const isScrollingToBottomRef = _react.useRef.call(void 0, false);
3898
3989
  const scrollToBottom = (behavior) => {
@@ -3904,7 +3995,7 @@ var useThreadViewportAutoScroll = ({
3904
3995
  const handleScroll = () => {
3905
3996
  const div = divRef.current;
3906
3997
  if (!div) return;
3907
- const isAtBottom = useViewport.getState().isAtBottom;
3998
+ const isAtBottom = threadViewportStore.getState().isAtBottom;
3908
3999
  const newIsAtBottom = div.scrollHeight - div.scrollTop <= div.clientHeight + 1;
3909
4000
  if (!newIsAtBottom && lastScrollTop.current < div.scrollTop) {
3910
4001
  } else {
@@ -3912,13 +4003,15 @@ var useThreadViewportAutoScroll = ({
3912
4003
  isScrollingToBottomRef.current = false;
3913
4004
  }
3914
4005
  if (newIsAtBottom !== isAtBottom) {
3915
- writableStore(useViewport).setState({ isAtBottom: newIsAtBottom });
4006
+ writableStore(threadViewportStore).setState({
4007
+ isAtBottom: newIsAtBottom
4008
+ });
3916
4009
  }
3917
4010
  }
3918
4011
  lastScrollTop.current = div.scrollTop;
3919
4012
  };
3920
4013
  const resizeRef = useOnResizeContent(() => {
3921
- if (isScrollingToBottomRef.current || useViewport.getState().isAtBottom) {
4014
+ if (isScrollingToBottomRef.current || threadViewportStore.getState().isAtBottom) {
3922
4015
  scrollToBottom("instant");
3923
4016
  }
3924
4017
  handleScroll();
@@ -3938,7 +4031,7 @@ var useThreadViewportAutoScroll = ({
3938
4031
 
3939
4032
  // src/primitives/thread/ThreadViewport.tsx
3940
4033
 
3941
- var ThreadPrimitiveViewport = _react.forwardRef.call(void 0, ({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
4034
+ var ThreadPrimitiveViewport = _react.forwardRef.call(void 0, ({ autoScroll, children, ...rest }, forwardedRef) => {
3942
4035
  const autoScrollRef = useThreadViewportAutoScroll({
3943
4036
  autoScroll
3944
4037
  });
@@ -3960,6 +4053,7 @@ var makeEditComposerStore = ({
3960
4053
  onEdit,
3961
4054
  onSend
3962
4055
  }) => _zustand.create.call(void 0, )((set, get) => ({
4056
+ type: "edit",
3963
4057
  get value() {
3964
4058
  return get().text;
3965
4059
  },
@@ -4007,7 +4101,7 @@ var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => {
4007
4101
  },
4008
4102
  isSpeaking: false,
4009
4103
  stopSpeaking: () => {
4010
- _optionalChain([utterance, 'optionalAccess', _190 => _190.cancel, 'call', _191 => _191()]);
4104
+ _optionalChain([utterance, 'optionalAccess', _180 => _180.cancel, 'call', _181 => _181()]);
4011
4105
  },
4012
4106
  addUtterance: (utt) => {
4013
4107
  utterance = utt;
@@ -4022,15 +4116,15 @@ var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => {
4022
4116
  // src/context/providers/MessageProvider.tsx
4023
4117
 
4024
4118
  var getIsLast = (messages, message) => {
4025
- return _optionalChain([messages, 'access', _192 => _192[messages.length - 1], 'optionalAccess', _193 => _193.id]) === message.id;
4119
+ return _optionalChain([messages, 'access', _182 => _182[messages.length - 1], 'optionalAccess', _183 => _183.id]) === message.id;
4026
4120
  };
4027
- var getMessageState = (messages, getBranches, useMessage, messageIndex) => {
4028
- const parentId = _nullishCoalesce(_optionalChain([messages, 'access', _194 => _194[messageIndex - 1], 'optionalAccess', _195 => _195.id]), () => ( null));
4121
+ var getMessageState = (messages, getBranches, useMessage2, messageIndex) => {
4122
+ const parentId = _nullishCoalesce(_optionalChain([messages, 'access', _184 => _184[messageIndex - 1], 'optionalAccess', _185 => _185.id]), () => ( null));
4029
4123
  const message = messages[messageIndex];
4030
4124
  if (!message) return null;
4031
4125
  const isLast = getIsLast(messages, message);
4032
4126
  const branches = getBranches(message.id);
4033
- const currentState = _optionalChain([useMessage, 'optionalAccess', _196 => _196.getState, 'call', _197 => _197()]);
4127
+ const currentState = _optionalChain([useMessage2, 'optionalAccess', _186 => _186.getState, 'call', _187 => _187()]);
4034
4128
  if (currentState && currentState.message === message && currentState.parentId === parentId && currentState.branches === branches && currentState.isLast === isLast)
4035
4129
  return null;
4036
4130
  return Object.freeze({
@@ -4041,62 +4135,55 @@ var getMessageState = (messages, getBranches, useMessage, messageIndex) => {
4041
4135
  });
4042
4136
  };
4043
4137
  var useMessageContext2 = (messageIndex) => {
4044
- const { useThreadMessages, useThreadActions } = useThreadContext();
4138
+ const threadMessagesStore = useThreadMessagesStore();
4139
+ const threadActionsStore = useThreadActionsStore();
4045
4140
  const [context] = _react.useState.call(void 0, () => {
4046
- const useMessage = _zustand.create.call(void 0,
4141
+ const useMessage2 = _zustand.create.call(void 0,
4047
4142
  () => getMessageState(
4048
- useThreadMessages.getState(),
4049
- useThreadActions.getState().getBranches,
4143
+ threadMessagesStore.getState(),
4144
+ threadActionsStore.getState().getBranches,
4050
4145
  void 0,
4051
4146
  messageIndex
4052
4147
  )
4053
4148
  );
4054
- const useMessageUtils = makeMessageUtilsStore();
4055
- const useEditComposer = makeEditComposerStore({
4149
+ const useMessageUtils2 = makeMessageUtilsStore();
4150
+ const useEditComposer2 = makeEditComposerStore({
4056
4151
  onEdit: () => {
4057
- const message = useMessage.getState().message;
4058
- if (message.role !== "user")
4059
- throw new Error(
4060
- "Tried to edit a non-user message. Editing is only supported for user messages. This is likely an internal bug in assistant-ui."
4061
- );
4152
+ const message = useMessage2.getState().message;
4062
4153
  const text = getThreadMessageText(message);
4063
4154
  return text;
4064
4155
  },
4065
4156
  onSend: (text) => {
4066
- const { message, parentId } = useMessage.getState();
4067
- if (message.role !== "user")
4068
- throw new Error(
4069
- "Tried to edit a non-user message. Editing is only supported for user messages. This is likely an internal bug in assistant-ui."
4070
- );
4157
+ const { message, parentId } = useMessage2.getState();
4071
4158
  const previousText = getThreadMessageText(message);
4072
4159
  if (previousText === text) return;
4073
4160
  const nonTextParts = message.content.filter(
4074
4161
  (part) => part.type !== "text" && part.type !== "ui"
4075
4162
  );
4076
- useThreadActions.getState().append({
4163
+ threadActionsStore.getState().append({
4077
4164
  parentId,
4078
- role: "user",
4165
+ role: message.role,
4079
4166
  content: [{ type: "text", text }, ...nonTextParts],
4080
4167
  attachments: message.attachments
4081
4168
  });
4082
4169
  }
4083
4170
  });
4084
- return { useMessage, useMessageUtils, useEditComposer };
4171
+ return { useMessage: useMessage2, useMessageUtils: useMessageUtils2, useEditComposer: useEditComposer2 };
4085
4172
  });
4086
4173
  _react.useEffect.call(void 0, () => {
4087
4174
  const syncMessage = (thread) => {
4088
4175
  const newState = getMessageState(
4089
4176
  thread,
4090
- useThreadActions.getState().getBranches,
4177
+ threadActionsStore.getState().getBranches,
4091
4178
  context.useMessage,
4092
4179
  messageIndex
4093
4180
  );
4094
4181
  if (!newState) return;
4095
4182
  writableStore(context.useMessage).setState(newState, true);
4096
4183
  };
4097
- syncMessage(useThreadMessages.getState());
4098
- return useThreadMessages.subscribe(syncMessage);
4099
- }, [useThreadMessages, useThreadActions, context, messageIndex]);
4184
+ syncMessage(threadMessagesStore.getState());
4185
+ return threadMessagesStore.subscribe(syncMessage);
4186
+ }, [threadMessagesStore, threadActionsStore, context, messageIndex]);
4100
4187
  return context;
4101
4188
  };
4102
4189
  var MessageProvider = ({
@@ -4109,37 +4196,56 @@ var MessageProvider = ({
4109
4196
 
4110
4197
  // src/primitives/thread/ThreadMessages.tsx
4111
4198
 
4199
+ var isComponentsSame = (prev, next) => {
4200
+ return prev.Message === next.Message && prev.EditComposer === next.EditComposer && prev.UserEditComposer === next.UserEditComposer && prev.AssistantEditComposer === next.AssistantEditComposer && prev.SystemEditComposer === next.SystemEditComposer && prev.UserMessage === next.UserMessage && prev.AssistantMessage === next.AssistantMessage && prev.SystemMessage === next.SystemMessage;
4201
+ };
4112
4202
  var DEFAULT_SYSTEM_MESSAGE = () => null;
4113
- var getComponents = (components) => {
4114
- return {
4115
- EditComposer: _nullishCoalesce(_nullishCoalesce(components.EditComposer, () => ( components.UserMessage)), () => ( components.Message)),
4116
- UserMessage: _nullishCoalesce(components.UserMessage, () => ( components.Message)),
4117
- AssistantMessage: _nullishCoalesce(components.AssistantMessage, () => ( components.Message)),
4118
- SystemMessage: _nullishCoalesce(components.SystemMessage, () => ( DEFAULT_SYSTEM_MESSAGE))
4119
- };
4203
+ var getComponent3 = (components, role, isEditing) => {
4204
+ switch (role) {
4205
+ case "user":
4206
+ if (isEditing) {
4207
+ return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(components.UserEditComposer, () => ( components.EditComposer)), () => ( components.UserMessage)), () => ( components.Message));
4208
+ } else {
4209
+ return _nullishCoalesce(components.UserMessage, () => ( components.Message));
4210
+ }
4211
+ case "assistant":
4212
+ if (isEditing) {
4213
+ return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(components.AssistantEditComposer, () => ( components.EditComposer)), () => ( components.AssistantMessage)), () => ( components.Message));
4214
+ } else {
4215
+ return _nullishCoalesce(components.AssistantMessage, () => ( components.Message));
4216
+ }
4217
+ case "system":
4218
+ if (isEditing) {
4219
+ return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(components.SystemEditComposer, () => ( components.EditComposer)), () => ( components.SystemMessage)), () => ( components.Message));
4220
+ } else {
4221
+ return _nullishCoalesce(components.SystemMessage, () => ( DEFAULT_SYSTEM_MESSAGE));
4222
+ }
4223
+ default:
4224
+ const _exhaustiveCheck = role;
4225
+ throw new Error(`Unknown message role: ${_exhaustiveCheck}`);
4226
+ }
4227
+ };
4228
+ var ThreadMessageComponent = ({
4229
+ components
4230
+ }) => {
4231
+ const role = useMessage((m) => m.message.role);
4232
+ const isEditing = useEditComposer((c) => c.isEditing);
4233
+ const Component = getComponent3(components, role, isEditing);
4234
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Component, {});
4120
4235
  };
4121
4236
  var ThreadMessageImpl = ({
4122
4237
  messageIndex,
4123
4238
  components
4124
4239
  }) => {
4125
- const { UserMessage: UserMessage2, EditComposer: EditComposer2, AssistantMessage: AssistantMessage2, SystemMessage: SystemMessage2 } = getComponents(components);
4126
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, MessageProvider, { messageIndex, children: [
4127
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, MessagePrimitiveIf, { user: true, children: [
4128
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UserMessage2, {}) }),
4129
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, EditComposer2, {}) })
4130
- ] }),
4131
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AssistantMessage2, {}) }),
4132
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessagePrimitiveIf, { system: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SystemMessage2, {}) })
4133
- ] });
4240
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageProvider, { messageIndex, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadMessageComponent, { components }) });
4134
4241
  };
4135
4242
  var ThreadMessage = _react.memo.call(void 0,
4136
4243
  ThreadMessageImpl,
4137
- (prev, next) => prev.messageIndex === next.messageIndex && prev.components.Message === next.components.Message && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage && prev.components.SystemMessage === next.components.SystemMessage
4244
+ (prev, next) => prev.messageIndex === next.messageIndex && isComponentsSame(prev.components, next.components)
4138
4245
  );
4139
4246
  var ThreadPrimitiveMessagesImpl = ({
4140
4247
  components
4141
4248
  }) => {
4142
- const { useThreadMessages } = useThreadContext();
4143
4249
  const messagesLength = useThreadMessages((t) => t.length);
4144
4250
  if (messagesLength === 0) return null;
4145
4251
  return Array.from({ length: messagesLength }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadMessage, { messageIndex: index, components }, index));
@@ -4147,7 +4253,7 @@ var ThreadPrimitiveMessagesImpl = ({
4147
4253
  ThreadPrimitiveMessagesImpl.displayName = "ThreadPrimitive.Messages";
4148
4254
  var ThreadPrimitiveMessages = _react.memo.call(void 0,
4149
4255
  ThreadPrimitiveMessagesImpl,
4150
- (prev, next) => _optionalChain([prev, 'access', _198 => _198.components, 'optionalAccess', _199 => _199.Message]) === _optionalChain([next, 'access', _200 => _200.components, 'optionalAccess', _201 => _201.Message]) && _optionalChain([prev, 'access', _202 => _202.components, 'optionalAccess', _203 => _203.UserMessage]) === _optionalChain([next, 'access', _204 => _204.components, 'optionalAccess', _205 => _205.UserMessage]) && _optionalChain([prev, 'access', _206 => _206.components, 'optionalAccess', _207 => _207.EditComposer]) === _optionalChain([next, 'access', _208 => _208.components, 'optionalAccess', _209 => _209.EditComposer]) && _optionalChain([prev, 'access', _210 => _210.components, 'optionalAccess', _211 => _211.AssistantMessage]) === _optionalChain([next, 'access', _212 => _212.components, 'optionalAccess', _213 => _213.AssistantMessage]) && _optionalChain([prev, 'access', _214 => _214.components, 'optionalAccess', _215 => _215.SystemMessage]) === _optionalChain([next, 'access', _216 => _216.components, 'optionalAccess', _217 => _217.SystemMessage])
4256
+ (prev, next) => isComponentsSame(prev.components, next.components)
4151
4257
  );
4152
4258
 
4153
4259
  // src/primitives/thread/ThreadScrollToBottom.tsx
@@ -4177,10 +4283,10 @@ var ThreadConfigProvider = ({
4177
4283
  children,
4178
4284
  config
4179
4285
  }) => {
4180
- const assistant = useAssistantContext({ optional: true });
4286
+ const hasAssistant = !!useAssistantRuntimeStore({ optional: true });
4181
4287
  const configProvider = config && Object.keys(_nullishCoalesce(config, () => ( {}))).length > 0 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children });
4182
- if (!_optionalChain([config, 'optionalAccess', _218 => _218.runtime])) return configProvider;
4183
- if (assistant) {
4288
+ if (!_optionalChain([config, 'optionalAccess', _188 => _188.runtime])) return configProvider;
4289
+ if (hasAssistant) {
4184
4290
  throw new Error(
4185
4291
  "You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
4186
4292
  );
@@ -4201,19 +4307,16 @@ var _lucidereact = require('lucide-react');
4201
4307
 
4202
4308
  var useAllowCopy = (ensureCapability = false) => {
4203
4309
  const { assistantMessage: { allowCopy = true } = {} } = useThreadConfig();
4204
- const { useThread } = useThreadContext();
4205
4310
  const copySupported = useThread((t) => t.capabilities.unstable_copy);
4206
4311
  return allowCopy && (!ensureCapability || copySupported);
4207
4312
  };
4208
4313
  var useAllowSpeak = (ensureCapability = false) => {
4209
4314
  const { assistantMessage: { allowSpeak = true } = {} } = useThreadConfig();
4210
- const { useThread } = useThreadContext();
4211
4315
  const speakSupported = useThread((t) => t.capabilities.speak);
4212
4316
  return allowSpeak && (!ensureCapability || speakSupported);
4213
4317
  };
4214
4318
  var useAllowReload = (ensureCapability = false) => {
4215
4319
  const { assistantMessage: { allowReload = true } = {} } = useThreadConfig();
4216
- const { useThread } = useThreadContext();
4217
4320
  const reloadSupported = useThread((t) => t.capabilities.reload);
4218
4321
  return allowReload && (!ensureCapability || reloadSupported);
4219
4322
  };
@@ -4313,7 +4416,6 @@ var assistant_action_bar_default = Object.assign(
4313
4416
 
4314
4417
  var useAllowBranchPicker = (ensureCapability = false) => {
4315
4418
  const { branchPicker: { allowBranchPicker = true } = {} } = useThreadConfig();
4316
- const { useThread } = useThreadContext();
4317
4419
  const branchPickerSupported = useThread((t) => t.capabilities.edit);
4318
4420
  return allowBranchPicker && (!ensureCapability || branchPickerSupported);
4319
4421
  };
@@ -4452,7 +4554,7 @@ var AssistantMessageContent = _react.forwardRef.call(void 0, ({ components: comp
4452
4554
  {
4453
4555
  components: {
4454
4556
  ...componentsProp,
4455
- Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _219 => _219.Text]), () => ( components.Text)), () => ( content_part_default.Text)),
4557
+ Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _189 => _189.Text]), () => ( components.Text)), () => ( content_part_default.Text)),
4456
4558
  tools: toolsComponents
4457
4559
  }
4458
4560
  }
@@ -4507,8 +4609,7 @@ var ComposerAttachmentRoot = withDefaults("div", {
4507
4609
  });
4508
4610
  ComposerAttachmentRoot.displayName = "ComposerAttachmentRoot";
4509
4611
  var ComposerAttachment2 = () => {
4510
- const { useAttachment } = useAttachmentContext({ type: "composer" });
4511
- const attachment = useAttachment((a) => a.attachment);
4612
+ const attachment = useComposerAttachment((a) => a.attachment);
4512
4613
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, ComposerAttachmentRoot, { children: [
4513
4614
  ".",
4514
4615
  attachment.name.split(".").pop(),
@@ -4522,10 +4623,10 @@ var ComposerAttachmentRemove = _react.forwardRef.call(void 0, (props, ref) => {
4522
4623
  composer: { removeAttachment: { tooltip = "Remove file" } = {} } = {}
4523
4624
  } = {}
4524
4625
  } = useThreadConfig();
4525
- const { useComposer } = useThreadContext();
4526
- const { useAttachment } = useAttachmentContext();
4626
+ const composerStore = useThreadComposerStore();
4627
+ const attachmentStore = useAttachmentStore();
4527
4628
  const handleRemoveAttachment = () => {
4528
- useComposer.getState().removeAttachment(useAttachment.getState().attachment.id);
4629
+ composerStore.getState().removeAttachment(attachmentStore.getState().attachment.id);
4529
4630
  };
4530
4631
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
4531
4632
  TooltipIconButton,
@@ -4554,7 +4655,6 @@ var composer_attachment_default = Object.assign(
4554
4655
 
4555
4656
  var useAllowAttachments = (ensureCapability = false) => {
4556
4657
  const { composer: { allowAttachments = true } = {} } = useThreadConfig();
4557
- const { useThread } = useThreadContext();
4558
4658
  const attachmentsSupported = useThread((t) => t.capabilities.attachments);
4559
4659
  return allowAttachments && (!ensureCapability || attachmentsSupported);
4560
4660
  };
@@ -4597,7 +4697,7 @@ var ComposerAttachments = ({ components }) => {
4597
4697
  {
4598
4698
  components: {
4599
4699
  ...components,
4600
- Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _220 => _220.Attachment]), () => ( composer_attachment_default))
4700
+ Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _190 => _190.Attachment]), () => ( composer_attachment_default))
4601
4701
  }
4602
4702
  }
4603
4703
  ) });
@@ -4626,7 +4726,6 @@ var ComposerAddAttachment = _react.forwardRef.call(void 0, (props, ref) => {
4626
4726
  });
4627
4727
  ComposerAddAttachment.displayName = "ComposerAddAttachment";
4628
4728
  var useAllowCancel = () => {
4629
- const { useThread } = useThreadContext();
4630
4729
  const cancelSupported = useThread((t) => t.capabilities.cancel);
4631
4730
  return cancelSupported;
4632
4731
  };
@@ -4730,7 +4829,7 @@ var ThreadWelcomeSuggestion = ({
4730
4829
  };
4731
4830
  var ThreadWelcomeSuggestions = () => {
4732
4831
  const { welcome: { suggestions } = {} } = useThreadConfig();
4733
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([suggestions, 'optionalAccess', _221 => _221.map, 'call', _222 => _222((suggestion, idx) => {
4832
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([suggestions, 'optionalAccess', _191 => _191.map, 'call', _192 => _192((suggestion, idx) => {
4734
4833
  const key = `${suggestion.prompt}-${idx}`;
4735
4834
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestion, { suggestion }, key);
4736
4835
  })]) });
@@ -4755,7 +4854,6 @@ var thread_welcome_default = Object.assign(ThreadWelcome, exports7);
4755
4854
 
4756
4855
  var useAllowEdit = (ensureCapability = false) => {
4757
4856
  const { userMessage: { allowEdit = true } = {} } = useThreadConfig();
4758
- const { useThread } = useThreadContext();
4759
4857
  const editSupported = useThread((t) => t.capabilities.edit);
4760
4858
  return allowEdit && (!ensureCapability || editSupported);
4761
4859
  };
@@ -4790,7 +4888,6 @@ var UserMessageAttachmentRoot = withDefaults("div", {
4790
4888
  });
4791
4889
  UserMessageAttachmentRoot.displayName = "UserMessageAttachmentRoot";
4792
4890
  var UserMessageAttachment = () => {
4793
- const { useAttachment } = useAttachmentContext();
4794
4891
  const attachment = useAttachment((a) => a.attachment);
4795
4892
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, UserMessageAttachmentRoot, { children: [
4796
4893
  ".",
@@ -4831,7 +4928,7 @@ var UserMessageContent = _react.forwardRef.call(void 0,
4831
4928
  {
4832
4929
  components: {
4833
4930
  ...components,
4834
- Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _223 => _223.Text]), () => ( content_part_default.Text))
4931
+ Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _193 => _193.Text]), () => ( content_part_default.Text))
4835
4932
  }
4836
4933
  }
4837
4934
  ) });
@@ -4849,7 +4946,7 @@ var UserMessageAttachments = ({
4849
4946
  {
4850
4947
  components: {
4851
4948
  ...components,
4852
- Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _224 => _224.Attachment]), () => ( user_message_attachment_default))
4949
+ Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _194 => _194.Attachment]), () => ( user_message_attachment_default))
4853
4950
  }
4854
4951
  }
4855
4952
  ) }) });
@@ -4950,10 +5047,10 @@ var ThreadMessages = ({ components, ...rest }) => {
4950
5047
  thread_exports.Messages,
4951
5048
  {
4952
5049
  components: {
4953
- UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _225 => _225.UserMessage]), () => ( user_message_default)),
4954
- EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _226 => _226.EditComposer]), () => ( edit_composer_default)),
4955
- AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _227 => _227.AssistantMessage]), () => ( assistant_message_default)),
4956
- SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _228 => _228.SystemMessage]), () => ( SystemMessage))
5050
+ UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _195 => _195.UserMessage]), () => ( user_message_default)),
5051
+ EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _196 => _196.EditComposer]), () => ( edit_composer_default)),
5052
+ AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _197 => _197.AssistantMessage]), () => ( assistant_message_default)),
5053
+ SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _198 => _198.SystemMessage]), () => ( SystemMessage))
4957
5054
  },
4958
5055
  ...rest
4959
5056
  }
@@ -5143,5 +5240,33 @@ var assistant_modal_default = Object.assign(AssistantModal, exports13);
5143
5240
 
5144
5241
 
5145
5242
 
5146
- exports.ActionBarPrimitive = actionBar_exports; exports.AssistantActionBar = assistant_action_bar_default; exports.AssistantMessage = assistant_message_default; exports.AssistantModal = assistant_modal_default; exports.AssistantModalPrimitive = assistantModal_exports; exports.AssistantRuntimeProvider = AssistantRuntimeProvider; exports.BranchPicker = branch_picker_default; exports.BranchPickerPrimitive = branchPicker_exports; exports.Composer = composer_default; exports.ComposerAttachment = composer_attachment_default; exports.ComposerPrimitive = composer_exports; exports.CompositeAttachmentAdapter = CompositeAttachmentAdapter; exports.ContentPart = content_part_default; exports.ContentPartPrimitive = contentPart_exports; exports.EdgeChatAdapter = EdgeChatAdapter; exports.EditComposer = edit_composer_default; exports.ExternalStoreRuntime = ExternalStoreRuntime; exports.INTERNAL = internal_exports; exports.MessagePrimitive = message_exports; exports.SimpleImageAttachmentAdapter = SimpleImageAttachmentAdapter; exports.SimpleTextAttachmentAdapter = SimpleTextAttachmentAdapter; exports.TextContentPartProvider = TextContentPartProvider; exports.Thread = thread_default; exports.ThreadConfigProvider = ThreadConfigProvider; exports.ThreadPrimitive = thread_exports; exports.ThreadWelcome = thread_welcome_default; exports.UserActionBar = user_action_bar_default; exports.UserMessage = user_message_default; exports.UserMessageAttachment = user_message_attachment_default; exports.WebSpeechSynthesisAdapter = WebSpeechSynthesisAdapter; exports.fromCoreMessage = fromCoreMessage; exports.fromCoreMessages = fromCoreMessages; exports.fromLanguageModelMessages = fromLanguageModelMessages; exports.fromLanguageModelTools = fromLanguageModelTools; exports.getExternalStoreMessage = getExternalStoreMessage; exports.makeAssistantTool = makeAssistantTool; exports.makeAssistantToolUI = makeAssistantToolUI; exports.streamUtils = streamUtils; exports.subscribeToMainThread = subscribeToMainThread; exports.toCoreMessage = _chunk4LR4BB23js.toCoreMessage; exports.toCoreMessages = _chunk4LR4BB23js.toCoreMessages; exports.toLanguageModelMessages = _chunk4LR4BB23js.toLanguageModelMessages; exports.toLanguageModelTools = _chunk4LR4BB23js.toLanguageModelTools; exports.useActionBarCopy = useActionBarCopy; exports.useActionBarEdit = useActionBarEdit; exports.useActionBarReload = useActionBarReload; exports.useActionBarSpeak = useActionBarSpeak; exports.useActionBarStopSpeaking = useActionBarStopSpeaking; exports.useAppendMessage = useAppendMessage; exports.useAssistantContext = useAssistantContext; exports.useAssistantInstructions = useAssistantInstructions; exports.useAssistantTool = useAssistantTool; exports.useAssistantToolUI = useAssistantToolUI; exports.useBranchPickerCount = useBranchPickerCount; exports.useBranchPickerNext = useBranchPickerNext; exports.useBranchPickerNumber = useBranchPickerNumber; exports.useBranchPickerPrevious = useBranchPickerPrevious; exports.useComposerAddAttachment = useComposerAddAttachment; exports.useComposerCancel = useComposerCancel; exports.useComposerContext = useComposerContext; exports.useComposerIf = useComposerIf; exports.useComposerSend = useComposerSend; exports.useContentPartContext = useContentPartContext; exports.useContentPartDisplay = useContentPartDisplay; exports.useContentPartImage = useContentPartImage; exports.useContentPartText = useContentPartText; exports.useDangerousInBrowserRuntime = useDangerousInBrowserRuntime; exports.useEdgeRuntime = useEdgeRuntime; exports.useExternalMessageConverter = useExternalMessageConverter; exports.useExternalStoreRuntime = useExternalStoreRuntime; exports.useLocalRuntime = useLocalRuntime; exports.useMessageContext = useMessageContext; exports.useMessageIf = useMessageIf; exports.useSwitchToNewThread = useSwitchToNewThread; exports.useThreadConfig = useThreadConfig; exports.useThreadContext = useThreadContext; exports.useThreadEmpty = useThreadEmpty; exports.useThreadIf = useThreadIf; exports.useThreadScrollToBottom = useThreadScrollToBottom; exports.useThreadSuggestion = useThreadSuggestion;
5243
+
5244
+
5245
+
5246
+
5247
+
5248
+
5249
+
5250
+
5251
+
5252
+
5253
+
5254
+
5255
+
5256
+
5257
+
5258
+
5259
+
5260
+
5261
+
5262
+
5263
+
5264
+
5265
+
5266
+
5267
+
5268
+
5269
+
5270
+
5271
+ exports.ActionBarPrimitive = actionBar_exports; exports.AssistantActionBar = assistant_action_bar_default; exports.AssistantMessage = assistant_message_default; exports.AssistantModal = assistant_modal_default; exports.AssistantModalPrimitive = assistantModal_exports; exports.AssistantRuntimeProvider = AssistantRuntimeProvider; exports.BranchPicker = branch_picker_default; exports.BranchPickerPrimitive = branchPicker_exports; exports.Composer = composer_default; exports.ComposerAttachment = composer_attachment_default; exports.ComposerPrimitive = composer_exports; exports.CompositeAttachmentAdapter = CompositeAttachmentAdapter; exports.ContentPart = content_part_default; exports.ContentPartPrimitive = contentPart_exports; exports.EdgeChatAdapter = EdgeChatAdapter; exports.EditComposer = edit_composer_default; exports.ExternalStoreRuntime = ExternalStoreRuntime; exports.INTERNAL = internal_exports; exports.MessagePrimitive = message_exports; exports.SimpleImageAttachmentAdapter = SimpleImageAttachmentAdapter; exports.SimpleTextAttachmentAdapter = SimpleTextAttachmentAdapter; exports.TextContentPartProvider = TextContentPartProvider; exports.Thread = thread_default; exports.ThreadConfigProvider = ThreadConfigProvider; exports.ThreadPrimitive = thread_exports; exports.ThreadWelcome = thread_welcome_default; exports.UserActionBar = user_action_bar_default; exports.UserMessage = user_message_default; exports.UserMessageAttachment = user_message_attachment_default; exports.WebSpeechSynthesisAdapter = WebSpeechSynthesisAdapter; exports.fromCoreMessage = fromCoreMessage; exports.fromCoreMessages = fromCoreMessages; exports.fromLanguageModelMessages = fromLanguageModelMessages; exports.fromLanguageModelTools = fromLanguageModelTools; exports.getExternalStoreMessage = getExternalStoreMessage; exports.makeAssistantTool = makeAssistantTool; exports.makeAssistantToolUI = makeAssistantToolUI; exports.streamUtils = streamUtils; exports.subscribeToMainThread = subscribeToMainThread; exports.toCoreMessage = _chunkCWAZOKEWjs.toCoreMessage; exports.toCoreMessages = _chunkCWAZOKEWjs.toCoreMessages; exports.toLanguageModelMessages = _chunkCWAZOKEWjs.toLanguageModelMessages; exports.toLanguageModelTools = _chunkCWAZOKEWjs.toLanguageModelTools; exports.useActionBarCopy = useActionBarCopy; exports.useActionBarEdit = useActionBarEdit; exports.useActionBarReload = useActionBarReload; exports.useActionBarSpeak = useActionBarSpeak; exports.useActionBarStopSpeaking = useActionBarStopSpeaking; exports.useAppendMessage = useAppendMessage; exports.useAssistantActions = useAssistantActions; exports.useAssistantActionsStore = useAssistantActionsStore; exports.useAssistantContext = useAssistantContext; exports.useAssistantInstructions = useAssistantInstructions; exports.useAssistantRuntime = useAssistantRuntime; exports.useAssistantRuntimeStore = useAssistantRuntimeStore; exports.useAssistantTool = useAssistantTool; exports.useAssistantToolUI = useAssistantToolUI; exports.useBranchPickerCount = useBranchPickerCount; exports.useBranchPickerNext = useBranchPickerNext; exports.useBranchPickerNumber = useBranchPickerNumber; exports.useBranchPickerPrevious = useBranchPickerPrevious; exports.useComposer = useComposer; exports.useComposerAddAttachment = useComposerAddAttachment; exports.useComposerCancel = useComposerCancel; exports.useComposerContext = useComposerContext; exports.useComposerIf = useComposerIf; exports.useComposerSend = useComposerSend; exports.useComposerStore = useComposerStore; exports.useContentPart = useContentPart; exports.useContentPartContext = useContentPartContext; exports.useContentPartDisplay = useContentPartDisplay; exports.useContentPartImage = useContentPartImage; exports.useContentPartStore = useContentPartStore; exports.useContentPartText = useContentPartText; exports.useDangerousInBrowserRuntime = useDangerousInBrowserRuntime; exports.useEdgeRuntime = useEdgeRuntime; exports.useEditComposer = useEditComposer; exports.useEditComposerStore = useEditComposerStore; exports.useExternalMessageConverter = useExternalMessageConverter; exports.useExternalStoreRuntime = useExternalStoreRuntime; exports.useLocalRuntime = useLocalRuntime; exports.useMessage = useMessage; exports.useMessageContext = useMessageContext; exports.useMessageIf = useMessageIf; exports.useMessageStore = useMessageStore; exports.useMessageUtils = useMessageUtils; exports.useMessageUtilsStore = useMessageUtilsStore; exports.useSwitchToNewThread = useSwitchToNewThread; exports.useThread = useThread; exports.useThreadActions = useThreadActions; exports.useThreadActionsStore = useThreadActionsStore; exports.useThreadComposer = useThreadComposer; exports.useThreadComposerStore = useThreadComposerStore; exports.useThreadConfig = useThreadConfig; exports.useThreadContext = useThreadContext; exports.useThreadEmpty = useThreadEmpty; exports.useThreadIf = useThreadIf; exports.useThreadMessages = useThreadMessages; exports.useThreadMessagesStore = useThreadMessagesStore; exports.useThreadRuntime = useThreadRuntime; exports.useThreadRuntimeStore = useThreadRuntimeStore; exports.useThreadScrollToBottom = useThreadScrollToBottom; exports.useThreadStore = useThreadStore; exports.useThreadSuggestion = useThreadSuggestion; exports.useThreadViewport = useThreadViewport; exports.useThreadViewportStore = useThreadViewportStore; exports.useToolUIs = useToolUIs; exports.useToolUIsStore = useToolUIsStore;
5147
5272
  //# sourceMappingURL=index.js.map