@assistant-ui/react 0.5.53 → 0.5.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,51 +123,64 @@ 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
  },
125
157
  setValue(value) {
126
158
  get().setText(value);
127
159
  },
160
+ attachmentAccept: runtime.composer.attachmentAccept,
128
161
  attachments: runtime.composer.attachments,
129
162
  addAttachment: (file) => {
130
- useThreadRuntime.getState().composer.addAttachment(file);
163
+ useThreadRuntime2.getState().composer.addAttachment(file);
131
164
  },
132
165
  removeAttachment: (attachmentId) => {
133
- useThreadRuntime.getState().composer.removeAttachment(attachmentId);
166
+ useThreadRuntime2.getState().composer.removeAttachment(attachmentId);
134
167
  },
135
168
  reset: () => {
136
- useThreadRuntime.getState().composer.reset();
169
+ useThreadRuntime2.getState().composer.reset();
137
170
  },
138
171
  text: runtime.composer.text,
139
172
  setText: (text) => {
140
- useThreadRuntime.getState().composer.setText(text);
173
+ useThreadRuntime2.getState().composer.setText(text);
141
174
  },
142
175
  canCancel: runtime.capabilities.cancel,
143
176
  isEditing: true,
144
177
  isEmpty: runtime.composer.isEmpty,
145
178
  send: () => {
146
- const runtime2 = useThreadRuntime.getState();
179
+ const runtime2 = useThreadRuntime2.getState();
147
180
  runtime2.composer.send();
148
181
  },
149
182
  cancel: () => {
150
- useThreadRuntime.getState().cancelRun();
183
+ useThreadRuntime2.getState().cancelRun();
151
184
  },
152
185
  focus: () => {
153
186
  for (const listener of focusListeners) {
@@ -252,8 +285,8 @@ var subscribeToMainThread = (runtime, callback) => {
252
285
 
253
286
 
254
287
  // src/runtimes/core/BaseAssistantRuntime.tsx
255
- var BaseAssistantRuntime = (_class2 = class {
256
- constructor(_thread) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);
288
+ var BaseAssistantRuntime = (_class = class {
289
+ constructor(_thread) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
257
290
  this._thread = _thread;
258
291
  this._thread = _thread;
259
292
  }
@@ -264,15 +297,15 @@ var BaseAssistantRuntime = (_class2 = class {
264
297
  this._thread = thread;
265
298
  this.subscriptionHandler();
266
299
  }
267
- __init2() {this._subscriptions = /* @__PURE__ */ new Set()}
300
+ __init() {this._subscriptions = /* @__PURE__ */ new Set()}
268
301
  subscribe(callback) {
269
302
  this._subscriptions.add(callback);
270
303
  return () => this._subscriptions.delete(callback);
271
304
  }
272
- __init3() {this.subscriptionHandler = () => {
305
+ __init2() {this.subscriptionHandler = () => {
273
306
  for (const callback of this._subscriptions) callback();
274
307
  }}
275
- }, _class2);
308
+ }, _class);
276
309
 
277
310
  // src/internal.ts
278
311
  var internal_exports = {};
@@ -289,13 +322,13 @@ _chunkDCHYNTHIjs.__export.call(void 0, internal_exports, {
289
322
  });
290
323
 
291
324
  // 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);
325
+ var ThreadRuntimeComposer = (_class2 = class {
326
+ constructor(runtime, notifySubscribers) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);
294
327
  this.runtime = runtime;
295
328
  this.notifySubscribers = notifySubscribers;
296
329
  }
297
330
 
298
- __init4() {this.attachmentAccept = "*"}
331
+ __init3() {this.attachmentAccept = "*"}
299
332
  get isEmpty() {
300
333
  return !this.text.trim() && !this.attachments.length;
301
334
  }
@@ -308,7 +341,7 @@ var ThreadRuntimeComposer = (_class3 = class {
308
341
  }
309
342
  return false;
310
343
  }
311
- __init5() {this._attachments = []}
344
+ __init4() {this._attachments = []}
312
345
  get attachments() {
313
346
  return this._attachments;
314
347
  }
@@ -329,7 +362,7 @@ var ThreadRuntimeComposer = (_class3 = class {
329
362
  this._attachments = this._attachments.toSpliced(index, 1);
330
363
  this.notifySubscribers();
331
364
  }
332
- __init6() {this._text = ""}
365
+ __init5() {this._text = ""}
333
366
  get text() {
334
367
  return this._text;
335
368
  }
@@ -356,6 +389,20 @@ var ThreadRuntimeComposer = (_class3 = class {
356
389
  });
357
390
  this.reset();
358
391
  }
392
+ }, _class2);
393
+
394
+ // src/utils/ProxyConfigProvider.ts
395
+ var ProxyConfigProvider = (_class3 = class {constructor() { _class3.prototype.__init6.call(this); }
396
+ __init6() {this._providers = /* @__PURE__ */ new Set()}
397
+ getModelConfig() {
398
+ return _chunkCWAZOKEWjs.mergeModelConfigs.call(void 0, this._providers);
399
+ }
400
+ registerModelConfigProvider(provider) {
401
+ this._providers.add(provider);
402
+ return () => {
403
+ this._providers.delete(provider);
404
+ };
405
+ }
359
406
  }, _class3);
360
407
 
361
408
  // src/utils/idUtils.tsx
@@ -609,6 +656,7 @@ var MessageRepository = (_class4 = class {constructor() { _class4.prototype.__in
609
656
 
610
657
  // src/utils/smooth/useSmooth.tsx
611
658
 
659
+ var _reactusecallbackref = require('@radix-ui/react-use-callback-ref');
612
660
 
613
661
  // src/utils/smooth/SmoothContext.tsx
614
662
 
@@ -618,6 +666,22 @@ var MessageRepository = (_class4 = class {constructor() { _class4.prototype.__in
618
666
 
619
667
 
620
668
 
669
+
670
+ // src/context/react/ContentPartContext.ts
671
+
672
+ var ContentPartContext = _react.createContext.call(void 0,
673
+ null
674
+ );
675
+ var useContentPartContext = createContextHook(
676
+ ContentPartContext,
677
+ "a component passed to <MessagePrimitive.Content components={...}>"
678
+ );
679
+ var { useContentPart, useContentPartStore } = createContextStoreHook(
680
+ useContentPartContext,
681
+ "useContentPart"
682
+ );
683
+
684
+ // src/utils/smooth/SmoothContext.tsx
621
685
  var _jsxruntime = require('react/jsx-runtime');
622
686
  var SmoothContext = _react.createContext.call(void 0, null);
623
687
  var makeSmoothContext = (initialState) => {
@@ -626,9 +690,9 @@ var makeSmoothContext = (initialState) => {
626
690
  };
627
691
  var SmoothContextProvider = ({ children }) => {
628
692
  const outer = useSmoothContext({ optional: true });
629
- const { useContentPart } = useContentPartContext();
693
+ const contentPartStore = useContentPartStore();
630
694
  const [context] = _react.useState.call(void 0,
631
- () => makeSmoothContext(useContentPart.getState().status)
695
+ () => makeSmoothContext(contentPartStore.getState().status)
632
696
  );
633
697
  if (outer) return children;
634
698
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SmoothContext.Provider, { value: context, children });
@@ -648,13 +712,17 @@ function useSmoothContext(options) {
648
712
  );
649
713
  return context;
650
714
  }
651
- var useSmoothStatus = () => {
652
- const { useSmoothStatus: useSmoothStatus2 } = useSmoothContext();
653
- return useSmoothStatus2();
715
+ var { useSmoothStatus, useSmoothStatusStore } = createContextStoreHook(
716
+ useSmoothContext,
717
+ "useSmoothStatus"
718
+ );
719
+
720
+ // src/context/ReadonlyStore.ts
721
+ var writableStore = (store) => {
722
+ return store;
654
723
  };
655
724
 
656
725
  // src/utils/smooth/useSmooth.tsx
657
- var _reactusecallbackref = require('@radix-ui/react-use-callback-ref');
658
726
  var TextStreamAnimator = (_class5 = class {
659
727
  constructor(currentText, setText) {;_class5.prototype.__init10.call(this);_class5.prototype.__init11.call(this);_class5.prototype.__init12.call(this);_class5.prototype.__init13.call(this);
660
728
  this.currentText = currentText;
@@ -703,21 +771,28 @@ var SMOOTH_STATUS = Object.freeze({
703
771
  type: "running"
704
772
  });
705
773
  var useSmooth = (state, smooth = false) => {
706
- const { useSmoothStatus: useSmoothStatus2 } = _nullishCoalesce(useSmoothContext({ optional: true }), () => ( {}));
707
774
  const {
708
775
  part: { text }
709
776
  } = state;
710
- const { useMessage } = useMessageContext();
711
777
  const id = useMessage((m) => m.message.id);
712
778
  const idRef = _react.useRef.call(void 0, id);
713
779
  const [displayedText, setDisplayedText] = _react.useState.call(void 0, text);
780
+ const smoothStatusStore = useSmoothStatusStore({ optional: true });
714
781
  const setText = _reactusecallbackref.useCallbackRef.call(void 0, (text2) => {
715
782
  setDisplayedText(text2);
716
- _optionalChain([useSmoothStatus2, 'optionalAccess', _31 => _31.setState, 'call', _32 => _32(text2 !== state.part.text ? SMOOTH_STATUS : state.status)]);
783
+ if (smoothStatusStore) {
784
+ writableStore(smoothStatusStore).setState(
785
+ text2 !== state.part.text ? SMOOTH_STATUS : state.status
786
+ );
787
+ }
717
788
  });
718
789
  _react.useEffect.call(void 0, () => {
719
- _optionalChain([useSmoothStatus2, 'optionalAccess', _33 => _33.setState, 'call', _34 => _34(text !== displayedText ? SMOOTH_STATUS : state.status)]);
720
- }, [useSmoothStatus2, text, displayedText, state.status]);
790
+ if (smoothStatusStore) {
791
+ writableStore(smoothStatusStore).setState(
792
+ text !== state.part.text ? SMOOTH_STATUS : state.status
793
+ );
794
+ }
795
+ }, [smoothStatusStore, text, displayedText, state.status, state.part.text]);
721
796
  const [animatorRef] = _react.useState.call(void 0,
722
797
  new TextStreamAnimator(text, setText)
723
798
  );
@@ -910,7 +985,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
910
985
  });
911
986
  if (mergeRoundtrips) {
912
987
  const previousMessage = messages[messages.length - 1];
913
- if (_optionalChain([previousMessage, 'optionalAccess', _35 => _35.role]) === "assistant") {
988
+ if (_optionalChain([previousMessage, 'optionalAccess', _31 => _31.role]) === "assistant") {
914
989
  previousMessage.content.push(...newContent);
915
990
  break;
916
991
  }
@@ -923,7 +998,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
923
998
  }
924
999
  case "tool": {
925
1000
  const previousMessage = messages[messages.length - 1];
926
- if (_optionalChain([previousMessage, 'optionalAccess', _36 => _36.role]) !== "assistant")
1001
+ if (_optionalChain([previousMessage, 'optionalAccess', _32 => _32.role]) !== "assistant")
927
1002
  throw new Error(
928
1003
  "A tool message must be preceded by an assistant message."
929
1004
  );
@@ -999,14 +1074,14 @@ function streamPartDecoderStream() {
999
1074
  controller.enqueue(decodeStreamPart(chunk));
1000
1075
  }
1001
1076
  });
1002
- return new (0, _chunk4LR4BB23js.PipeableTransformStream)((readable) => {
1077
+ return new (0, _chunkCWAZOKEWjs.PipeableTransformStream)((readable) => {
1003
1078
  return readable.pipeThrough(new TextDecoderStream()).pipeThrough(chunkByLineStream()).pipeThrough(decodeStream);
1004
1079
  });
1005
1080
  }
1006
1081
 
1007
1082
  // src/runtimes/edge/streams/utils/index.ts
1008
1083
  var streamUtils = {
1009
- streamPartEncoderStream: _chunk4LR4BB23js.streamPartEncoderStream,
1084
+ streamPartEncoderStream: _chunkCWAZOKEWjs.streamPartEncoderStream,
1010
1085
  streamPartDecoderStream
1011
1086
  };
1012
1087
 
@@ -1115,8 +1190,8 @@ var EdgeChatAdapter = class {
1115
1190
  credentials: _nullishCoalesce(this.options.credentials, () => ( "same-origin")),
1116
1191
  body: JSON.stringify({
1117
1192
  system: config.system,
1118
- messages: _chunk4LR4BB23js.toCoreMessages.call(void 0, messages),
1119
- tools: config.tools ? _chunk4LR4BB23js.toLanguageModelTools.call(void 0, config.tools) : [],
1193
+ messages: _chunkCWAZOKEWjs.toCoreMessages.call(void 0, messages),
1194
+ tools: config.tools ? _chunkCWAZOKEWjs.toLanguageModelTools.call(void 0, config.tools) : [],
1120
1195
  ...config.callSettings,
1121
1196
  ...config.config,
1122
1197
  ...this.options.body
@@ -1126,7 +1201,7 @@ var EdgeChatAdapter = class {
1126
1201
  if (result.status !== 200) {
1127
1202
  throw new Error(`Status ${result.status}: ${await result.text()}`);
1128
1203
  }
1129
- const stream = result.body.pipeThrough(streamPartDecoderStream()).pipeThrough(assistantDecoderStream()).pipeThrough(_chunk4LR4BB23js.toolResultStream.call(void 0, config.tools, abortSignal)).pipeThrough(_chunk4LR4BB23js.runResultStream.call(void 0, ));
1204
+ const stream = result.body.pipeThrough(streamPartDecoderStream()).pipeThrough(assistantDecoderStream()).pipeThrough(_chunkCWAZOKEWjs.toolResultStream.call(void 0, config.tools, abortSignal)).pipeThrough(_chunkCWAZOKEWjs.runResultStream.call(void 0, ));
1130
1205
  let update;
1131
1206
  for await (update of asAsyncIterable(stream)) {
1132
1207
  yield update;
@@ -1152,7 +1227,7 @@ var useEdgeRuntime = ({
1152
1227
  };
1153
1228
 
1154
1229
  // src/runtimes/local/shouldContinue.tsx
1155
- 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);
1230
+ 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);
1156
1231
 
1157
1232
  // src/runtimes/local/LocalThreadRuntime.tsx
1158
1233
  var LocalThreadRuntime = (_class6 = class {
@@ -1198,13 +1273,13 @@ var LocalThreadRuntime = (_class6 = class {
1198
1273
  set options({ initialMessages, ...options }) {
1199
1274
  this._options = options;
1200
1275
  let hasUpdates = false;
1201
- const canSpeak = _optionalChain([options, 'access', _39 => _39.adapters, 'optionalAccess', _40 => _40.speech]) !== void 0;
1276
+ const canSpeak = _optionalChain([options, 'access', _35 => _35.adapters, 'optionalAccess', _36 => _36.speech]) !== void 0;
1202
1277
  if (this.capabilities.speak !== canSpeak) {
1203
1278
  this.capabilities.speak = canSpeak;
1204
1279
  hasUpdates = true;
1205
1280
  }
1206
- this.composer.setAttachmentAdapter(_optionalChain([options, 'access', _41 => _41.adapters, 'optionalAccess', _42 => _42.attachments]));
1207
- const canAttach = _optionalChain([options, 'access', _43 => _43.adapters, 'optionalAccess', _44 => _44.attachments]) !== void 0;
1281
+ this.composer.setAttachmentAdapter(_optionalChain([options, 'access', _37 => _37.adapters, 'optionalAccess', _38 => _38.attachments]));
1282
+ const canAttach = _optionalChain([options, 'access', _39 => _39.adapters, 'optionalAccess', _40 => _40.attachments]) !== void 0;
1208
1283
  if (this.capabilities.attachments !== canAttach) {
1209
1284
  this.capabilities.attachments = canAttach;
1210
1285
  hasUpdates = true;
@@ -1246,18 +1321,18 @@ var LocalThreadRuntime = (_class6 = class {
1246
1321
  }
1247
1322
  async performRoundtrip(parentId, message) {
1248
1323
  const messages = this.repository.getMessages();
1249
- _optionalChain([this, 'access', _45 => _45.abortController, 'optionalAccess', _46 => _46.abort, 'call', _47 => _47()]);
1324
+ _optionalChain([this, 'access', _41 => _41.abortController, 'optionalAccess', _42 => _42.abort, 'call', _43 => _43()]);
1250
1325
  this.abortController = new AbortController();
1251
1326
  const initialContent = message.content;
1252
- const initialRoundtrips = _optionalChain([message, 'access', _48 => _48.metadata, 'optionalAccess', _49 => _49.roundtrips]);
1253
- const initalCustom = _optionalChain([message, 'access', _50 => _50.metadata, 'optionalAccess', _51 => _51.custom]);
1327
+ const initialRoundtrips = _optionalChain([message, 'access', _44 => _44.metadata, 'optionalAccess', _45 => _45.roundtrips]);
1328
+ const initalCustom = _optionalChain([message, 'access', _46 => _46.metadata, 'optionalAccess', _47 => _47.custom]);
1254
1329
  const updateMessage = (m) => {
1255
1330
  message = {
1256
1331
  ...message,
1257
1332
  ...m.content ? { content: [...initialContent, ..._nullishCoalesce(m.content, () => ( []))] } : void 0,
1258
1333
  status: _nullishCoalesce(m.status, () => ( message.status)),
1259
1334
  // TODO deprecated, remove in v0.6
1260
- ..._optionalChain([m, 'access', _52 => _52.metadata, 'optionalAccess', _53 => _53.roundtrips]) ? {
1335
+ ..._optionalChain([m, 'access', _48 => _48.metadata, 'optionalAccess', _49 => _49.roundtrips]) ? {
1261
1336
  roundtrips: [
1262
1337
  ..._nullishCoalesce(initialRoundtrips, () => ( [])),
1263
1338
  ...m.metadata.roundtrips
@@ -1272,7 +1347,7 @@ var LocalThreadRuntime = (_class6 = class {
1272
1347
  ...m.metadata.roundtrips
1273
1348
  ]
1274
1349
  } : void 0,
1275
- ..._optionalChain([m, 'access', _54 => _54.metadata, 'optionalAccess', _55 => _55.custom]) ? {
1350
+ ..._optionalChain([m, 'access', _50 => _50.metadata, 'optionalAccess', _51 => _51.custom]) ? {
1276
1351
  custom: { ..._nullishCoalesce(initalCustom, () => ( {})), ...m.metadata.custom }
1277
1352
  } : void 0
1278
1353
  }
@@ -1282,7 +1357,7 @@ var LocalThreadRuntime = (_class6 = class {
1282
1357
  this.notifySubscribers();
1283
1358
  };
1284
1359
  const maxToolRoundtrips = _nullishCoalesce(this.options.maxToolRoundtrips, () => ( 1));
1285
- const toolRoundtrips = _nullishCoalesce(_optionalChain([message, 'access', _56 => _56.metadata, 'optionalAccess', _57 => _57.roundtrips, 'optionalAccess', _58 => _58.length]), () => ( 0));
1360
+ const toolRoundtrips = _nullishCoalesce(_optionalChain([message, 'access', _52 => _52.metadata, 'optionalAccess', _53 => _53.roundtrips, 'optionalAccess', _54 => _54.length]), () => ( 0));
1286
1361
  if (toolRoundtrips > maxToolRoundtrips) {
1287
1362
  updateMessage({
1288
1363
  status: {
@@ -1350,7 +1425,9 @@ var LocalThreadRuntime = (_class6 = class {
1350
1425
  toolCallId,
1351
1426
  result
1352
1427
  }) {
1353
- let { parentId, message } = this.repository.getMessage(messageId);
1428
+ const messageData = this.repository.getMessage(messageId);
1429
+ const { parentId } = messageData;
1430
+ let { message } = messageData;
1354
1431
  if (message.role !== "assistant")
1355
1432
  throw new Error("Tried to add tool result to non-assistant message");
1356
1433
  let added = false;
@@ -1379,7 +1456,7 @@ var LocalThreadRuntime = (_class6 = class {
1379
1456
  // TODO lift utterance state to thread runtime
1380
1457
 
1381
1458
  speak(messageId) {
1382
- const adapter = _optionalChain([this, 'access', _59 => _59.options, 'access', _60 => _60.adapters, 'optionalAccess', _61 => _61.speech]);
1459
+ const adapter = _optionalChain([this, 'access', _55 => _55.options, 'access', _56 => _56.adapters, 'optionalAccess', _57 => _57.speech]);
1383
1460
  if (!adapter) throw new Error("Speech adapter not configured");
1384
1461
  const { message } = this.repository.getMessage(messageId);
1385
1462
  if (this._utterance) {
@@ -1421,10 +1498,7 @@ var LocalRuntime = class extends BaseAssistantRuntime {
1421
1498
  registerModelConfigProvider(provider) {
1422
1499
  return this._proxyConfigProvider.registerModelConfigProvider(provider);
1423
1500
  }
1424
- switchToThread(threadId) {
1425
- if (threadId) {
1426
- throw new Error("LocalRuntime does not yet support switching threads");
1427
- }
1501
+ switchToNewThread() {
1428
1502
  const { initialMessages, ...options } = this.thread.options;
1429
1503
  return this.thread = new LocalThreadRuntime(
1430
1504
  this._proxyConfigProvider,
@@ -1432,6 +1506,12 @@ var LocalRuntime = class extends BaseAssistantRuntime {
1432
1506
  options
1433
1507
  );
1434
1508
  }
1509
+ switchToThread(threadId) {
1510
+ if (threadId !== null) {
1511
+ throw new Error("LocalRuntime does not yet support switching threads");
1512
+ }
1513
+ this.switchToNewThread();
1514
+ }
1435
1515
  reset({
1436
1516
  initialMessages
1437
1517
  } = {}) {
@@ -1440,7 +1520,7 @@ var LocalRuntime = class extends BaseAssistantRuntime {
1440
1520
  const messages = fromCoreMessages(initialMessages);
1441
1521
  this.thread.import({
1442
1522
  messages: messages.map((m, idx) => ({
1443
- parentId: _nullishCoalesce(_optionalChain([messages, 'access', _62 => _62[idx - 1], 'optionalAccess', _63 => _63.id]), () => ( null)),
1523
+ parentId: _nullishCoalesce(_optionalChain([messages, 'access', _58 => _58[idx - 1], 'optionalAccess', _59 => _59.id]), () => ( null)),
1444
1524
  message: m
1445
1525
  }))
1446
1526
  });
@@ -1569,7 +1649,7 @@ var getThreadMessageText = (message) => {
1569
1649
 
1570
1650
  // src/runtimes/external-store/ExternalStoreThreadRuntime.tsx
1571
1651
  var hasUpcomingMessage = (isRunning, messages) => {
1572
- return isRunning && _optionalChain([messages, 'access', _64 => _64[messages.length - 1], 'optionalAccess', _65 => _65.role]) !== "assistant";
1652
+ return isRunning && _optionalChain([messages, 'access', _60 => _60[messages.length - 1], 'optionalAccess', _61 => _61.role]) !== "assistant";
1573
1653
  };
1574
1654
  var ExternalStoreThreadRuntime = (_class8 = class {
1575
1655
  __init21() {this._subscriptions = /* @__PURE__ */ new Set()}
@@ -1615,11 +1695,11 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1615
1695
  reload: this._store.onReload !== void 0,
1616
1696
  cancel: this._store.onCancel !== void 0,
1617
1697
  speak: this._store.onSpeak !== void 0,
1618
- unstable_copy: _optionalChain([this, 'access', _69 => _69._store, 'access', _70 => _70.unstable_capabilities, 'optionalAccess', _71 => _71.copy]) !== false,
1698
+ unstable_copy: _optionalChain([this, 'access', _65 => _65._store, 'access', _66 => _66.unstable_capabilities, 'optionalAccess', _67 => _67.copy]) !== false,
1619
1699
  // default true
1620
- attachments: !!_optionalChain([this, 'access', _72 => _72.store, 'access', _73 => _73.adapters, 'optionalAccess', _74 => _74.attachments])
1700
+ attachments: !!_optionalChain([this, 'access', _68 => _68.store, 'access', _69 => _69.adapters, 'optionalAccess', _70 => _70.attachments])
1621
1701
  };
1622
- this.composer.setAttachmentAdapter(_optionalChain([this, 'access', _75 => _75._store, 'access', _76 => _76.adapters, 'optionalAccess', _77 => _77.attachments]));
1702
+ this.composer.setAttachmentAdapter(_optionalChain([this, 'access', _71 => _71._store, 'access', _72 => _72.adapters, 'optionalAccess', _73 => _73.attachments]));
1623
1703
  if (oldStore) {
1624
1704
  if (oldStore.convertMessage !== store.convertMessage) {
1625
1705
  this.converter = new ThreadMessageConverter();
@@ -1645,7 +1725,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1645
1725
  for (let i = 0; i < messages.length; i++) {
1646
1726
  const message = messages[i];
1647
1727
  const parent = messages[i - 1];
1648
- this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _78 => _78.id]), () => ( null)), message);
1728
+ this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _74 => _74.id]), () => ( null)), message);
1649
1729
  }
1650
1730
  if (this.assistantOptimisticId) {
1651
1731
  this.repository.deleteMessage(this.assistantOptimisticId);
@@ -1653,7 +1733,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1653
1733
  }
1654
1734
  if (hasUpcomingMessage(isRunning, messages)) {
1655
1735
  this.assistantOptimisticId = this.repository.appendOptimisticMessage(
1656
- _nullishCoalesce(_optionalChain([messages, 'access', _79 => _79.at, 'call', _80 => _80(-1), 'optionalAccess', _81 => _81.id]), () => ( null)),
1736
+ _nullishCoalesce(_optionalChain([messages, 'access', _75 => _75.at, 'call', _76 => _76(-1), 'optionalAccess', _77 => _77.id]), () => ( null)),
1657
1737
  {
1658
1738
  role: "assistant",
1659
1739
  content: []
@@ -1661,7 +1741,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1661
1741
  );
1662
1742
  }
1663
1743
  this.repository.resetHead(
1664
- _nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages, 'access', _82 => _82.at, 'call', _83 => _83(-1), 'optionalAccess', _84 => _84.id]))), () => ( null))
1744
+ _nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages, 'access', _78 => _78.at, 'call', _79 => _79(-1), 'optionalAccess', _80 => _80.id]))), () => ( null))
1665
1745
  );
1666
1746
  this.messages = this.repository.getMessages();
1667
1747
  this.notifySubscribers();
@@ -1679,7 +1759,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1679
1759
  this.updateMessages(this.repository.getMessages());
1680
1760
  }
1681
1761
  async append(message) {
1682
- if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _85 => _85.messages, 'access', _86 => _86.at, 'call', _87 => _87(-1), 'optionalAccess', _88 => _88.id]), () => ( null)))) {
1762
+ if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _81 => _81.messages, 'access', _82 => _82.at, 'call', _83 => _83(-1), 'optionalAccess', _84 => _84.id]), () => ( null)))) {
1683
1763
  if (!this._store.onEdit)
1684
1764
  throw new Error("Runtime does not support editing messages.");
1685
1765
  await this._store.onEdit(message);
@@ -1702,7 +1782,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1702
1782
  }
1703
1783
  let messages = this.repository.getMessages();
1704
1784
  const previousMessage = messages[messages.length - 1];
1705
- if (_optionalChain([previousMessage, 'optionalAccess', _89 => _89.role]) === "user" && previousMessage.id === _optionalChain([messages, 'access', _90 => _90.at, 'call', _91 => _91(-1), 'optionalAccess', _92 => _92.id])) {
1785
+ if (_optionalChain([previousMessage, 'optionalAccess', _85 => _85.role]) === "user" && previousMessage.id === _optionalChain([messages, 'access', _86 => _86.at, 'call', _87 => _87(-1), 'optionalAccess', _88 => _88.id])) {
1706
1786
  this.repository.deleteMessage(previousMessage.id);
1707
1787
  if (!this.composer.text.trim()) {
1708
1788
  this.composer.setText(getThreadMessageText(previousMessage));
@@ -1731,7 +1811,7 @@ var ExternalStoreThreadRuntime = (_class8 = class {
1731
1811
  return () => this._subscriptions.delete(callback);
1732
1812
  }
1733
1813
  __init27() {this.updateMessages = (messages) => {
1734
- _optionalChain([this, 'access', _93 => _93._store, 'access', _94 => _94.setMessages, 'optionalCall', _95 => _95(
1814
+ _optionalChain([this, 'access', _89 => _89._store, 'access', _90 => _90.setMessages, 'optionalCall', _91 => _91(
1735
1815
  messages.flatMap(getExternalStoreMessage).filter((m) => m != null)
1736
1816
  )]);
1737
1817
  }}
@@ -1755,23 +1835,26 @@ var ExternalStoreRuntime = (_class9 = class extends BaseAssistantRuntime {
1755
1835
  registerModelConfigProvider(provider) {
1756
1836
  return this._proxyConfigProvider.registerModelConfigProvider(provider);
1757
1837
  }
1838
+ async switchToNewThread() {
1839
+ if (!this.store.onSwitchToNewThread)
1840
+ throw new Error("Runtime does not support switching to new threads.");
1841
+ this.thread = new ExternalStoreThreadRuntime({
1842
+ messages: [],
1843
+ onNew: this.store.onNew
1844
+ });
1845
+ await this.store.onSwitchToNewThread();
1846
+ }
1758
1847
  async switchToThread(threadId) {
1759
- if (threadId) {
1760
- if (!this.store.onSwitchThread)
1848
+ if (threadId !== null) {
1849
+ if (!this.store.onSwitchToThread)
1761
1850
  throw new Error("Runtime does not support switching threads.");
1762
1851
  this.thread = new ExternalStoreThreadRuntime({
1763
1852
  messages: [],
1764
1853
  onNew: this.store.onNew
1765
1854
  });
1766
- this.store.onSwitchThread(threadId);
1855
+ this.store.onSwitchToThread(threadId);
1767
1856
  } else {
1768
- if (!this.store.onNewThread)
1769
- throw new Error("Runtime does not support switching to new threads.");
1770
- this.thread = new ExternalStoreThreadRuntime({
1771
- messages: [],
1772
- onNew: this.store.onNew
1773
- });
1774
- await this.store.onNewThread();
1857
+ this.switchToNewThread();
1775
1858
  }
1776
1859
  }
1777
1860
  }, _class9);
@@ -1942,18 +2025,18 @@ var DangerousInBrowserAdapter = class {
1942
2025
  this.options = options;
1943
2026
  }
1944
2027
  async *run({ messages, abortSignal, config }) {
1945
- const res = await _chunk4LR4BB23js.getEdgeRuntimeStream.call(void 0, {
2028
+ const res = await _chunkCWAZOKEWjs.getEdgeRuntimeStream.call(void 0, {
1946
2029
  options: this.options,
1947
2030
  abortSignal,
1948
2031
  requestData: {
1949
2032
  system: config.system,
1950
- messages: _chunk4LR4BB23js.toCoreMessages.call(void 0, messages),
1951
- tools: config.tools ? _chunk4LR4BB23js.toLanguageModelTools.call(void 0, config.tools) : [],
2033
+ messages: _chunkCWAZOKEWjs.toCoreMessages.call(void 0, messages),
2034
+ tools: config.tools ? _chunkCWAZOKEWjs.toLanguageModelTools.call(void 0, config.tools) : [],
1952
2035
  ...config.callSettings,
1953
2036
  ...config.config
1954
2037
  }
1955
2038
  });
1956
- const stream = res.pipeThrough(_chunk4LR4BB23js.toolResultStream.call(void 0, config.tools, abortSignal)).pipeThrough(_chunk4LR4BB23js.runResultStream.call(void 0, ));
2039
+ const stream = res.pipeThrough(_chunkCWAZOKEWjs.toolResultStream.call(void 0, config.tools, abortSignal)).pipeThrough(_chunkCWAZOKEWjs.runResultStream.call(void 0, ));
1957
2040
  for await (const update of asAsyncIterable(stream)) {
1958
2041
  yield update;
1959
2042
  }
@@ -2146,11 +2229,6 @@ var CompositeAttachmentAdapter = class {
2146
2229
  }
2147
2230
  };
2148
2231
 
2149
- // src/context/ReadonlyStore.ts
2150
- var writableStore = (store) => {
2151
- return store;
2152
- };
2153
-
2154
2232
  // src/context/providers/ThreadProvider.tsx
2155
2233
 
2156
2234
  var ThreadProvider = ({
@@ -2158,18 +2236,18 @@ var ThreadProvider = ({
2158
2236
  provider
2159
2237
  }) => {
2160
2238
  const [context] = _react.useState.call(void 0, () => {
2161
- const useThreadRuntime = makeThreadRuntimeStore(provider.thread);
2162
- const useThread = makeThreadStore(useThreadRuntime);
2163
- const useThreadMessages = makeThreadMessagesStore(useThreadRuntime);
2164
- const useThreadActions = makeThreadActionStore(useThreadRuntime);
2239
+ const useThreadRuntime2 = makeThreadRuntimeStore(provider.thread);
2240
+ const useThread2 = makeThreadStore(useThreadRuntime2);
2241
+ const useThreadMessages2 = makeThreadMessagesStore(useThreadRuntime2);
2242
+ const useThreadActions2 = makeThreadActionStore(useThreadRuntime2);
2165
2243
  const useViewport = makeThreadViewportStore();
2166
- const useComposer = makeComposerStore(useThreadRuntime);
2244
+ const useComposer2 = makeThreadComposerStore(useThreadRuntime2);
2167
2245
  return {
2168
- useThread,
2169
- useThreadRuntime,
2170
- useThreadMessages,
2171
- useThreadActions,
2172
- useComposer,
2246
+ useThread: useThread2,
2247
+ useThreadRuntime: useThreadRuntime2,
2248
+ useThreadMessages: useThreadMessages2,
2249
+ useThreadActions: useThreadActions2,
2250
+ useComposer: useComposer2,
2173
2251
  useViewport
2174
2252
  };
2175
2253
  });
@@ -2189,10 +2267,11 @@ var ThreadProvider = ({
2189
2267
  );
2190
2268
  }
2191
2269
  const composerState = context.useComposer.getState();
2192
- if (thread.composer.isEmpty !== composerState.isEmpty || thread.composer.text !== composerState.text || thread.composer.attachments !== composerState.attachments || state.capabilities.cancel !== composerState.canCancel) {
2270
+ if (thread.composer.isEmpty !== composerState.isEmpty || thread.composer.text !== composerState.text || thread.composer.attachmentAccept !== composerState.attachmentAccept || thread.composer.attachments !== composerState.attachments || state.capabilities.cancel !== composerState.canCancel) {
2193
2271
  writableStore(context.useComposer).setState({
2194
2272
  isEmpty: thread.composer.isEmpty,
2195
2273
  text: thread.composer.text,
2274
+ attachmentAccept: thread.composer.attachmentAccept,
2196
2275
  attachments: thread.composer.attachments,
2197
2276
  canCancel: state.capabilities.cancel
2198
2277
  });
@@ -2221,6 +2300,8 @@ var ThreadProvider = ({
2221
2300
  var makeAssistantActionsStore = (runtimeRef) => _zustand.create.call(void 0,
2222
2301
  () => Object.freeze({
2223
2302
  switchToThread: () => runtimeRef.current.switchToThread(null),
2303
+ switchToNewThread: () => runtimeRef.current.switchToNewThread(),
2304
+ registerModelConfigProvider: (provider) => runtimeRef.current.registerModelConfigProvider(provider),
2224
2305
  getRuntime: () => runtimeRef.current
2225
2306
  })
2226
2307
  );
@@ -2239,21 +2320,15 @@ var AssistantProvider = ({ children, runtime }) => {
2239
2320
  runtimeRef.current = runtime;
2240
2321
  });
2241
2322
  const [context] = _react.useState.call(void 0, () => {
2242
- const useAssistantRuntime = makeAssistantRuntimeStore(runtime);
2243
- const useModelConfig = makeAssistantModelConfigStore();
2244
- const useToolUIs = makeAssistantToolUIsStore();
2245
- const useAssistantActions = makeAssistantActionsStore(runtimeRef);
2323
+ const useAssistantRuntime2 = makeAssistantRuntimeStore(runtime);
2324
+ const useToolUIs2 = makeAssistantToolUIsStore();
2325
+ const useAssistantActions2 = makeAssistantActionsStore(runtimeRef);
2246
2326
  return {
2247
- useModelConfig,
2248
- useToolUIs,
2249
- useAssistantRuntime,
2250
- useAssistantActions
2327
+ useToolUIs: useToolUIs2,
2328
+ useAssistantRuntime: useAssistantRuntime2,
2329
+ useAssistantActions: useAssistantActions2
2251
2330
  };
2252
2331
  });
2253
- const getModelConfig = context.useModelConfig();
2254
- _react.useEffect.call(void 0, () => {
2255
- return runtime.registerModelConfigProvider(getModelConfig);
2256
- }, [runtime, getModelConfig]);
2257
2332
  _react.useEffect.call(void 0,
2258
2333
  () => writableStore(context.useAssistantRuntime).setState(runtime, true),
2259
2334
  [runtime, context]
@@ -2272,91 +2347,93 @@ var AssistantRuntimeProvider = _react.memo.call(void 0, AssistantRuntimeProvider
2272
2347
 
2273
2348
 
2274
2349
 
2275
- // src/context/react/ContentPartContext.ts
2276
-
2277
- var ContentPartContext = _react.createContext.call(void 0,
2278
- null
2279
- );
2280
- function useContentPartContext(options) {
2281
- const context = _react.useContext.call(void 0, ContentPartContext);
2282
- if (!_optionalChain([options, 'optionalAccess', _96 => _96.optional]) && !context)
2283
- throw new Error(
2284
- "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
2285
- );
2286
- return context;
2287
- }
2288
-
2289
- // src/context/providers/TextContentPartProvider.tsx
2290
-
2291
2350
  var TextContentPartProvider = ({ children, text }) => {
2292
2351
  const [context] = _react.useState.call(void 0, () => {
2293
- const useContentPart = _zustand.create.call(void 0, () => ({
2352
+ const useContentPart2 = _zustand.create.call(void 0, () => ({
2294
2353
  status: { type: "complete" },
2295
2354
  part: { type: "text", text }
2296
2355
  }));
2297
2356
  return {
2298
- useContentPart
2357
+ useContentPart: useContentPart2
2299
2358
  };
2300
2359
  });
2301
2360
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartContext.Provider, { value: context, children });
2302
2361
  };
2303
2362
 
2304
- // src/context/react/ComposerContext.ts
2305
-
2306
-
2307
2363
  // src/context/react/MessageContext.ts
2308
2364
 
2309
2365
  var MessageContext = _react.createContext.call(void 0, null);
2310
- function useMessageContext(options) {
2311
- const context = _react.useContext.call(void 0, MessageContext);
2312
- if (!_optionalChain([options, 'optionalAccess', _97 => _97.optional]) && !context)
2313
- throw new Error(
2314
- "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
2315
- );
2316
- return context;
2317
- }
2366
+ var useMessageContext = createContextHook(
2367
+ MessageContext,
2368
+ "a component passed to <ThreadPrimitive.Messages components={...} />"
2369
+ );
2370
+ var { useMessage, useMessageStore } = createContextStoreHook(
2371
+ useMessageContext,
2372
+ "useMessage"
2373
+ );
2374
+ var { useMessageUtils, useMessageUtilsStore } = createContextStoreHook(
2375
+ useMessageContext,
2376
+ "useMessageUtils"
2377
+ );
2378
+ var { useEditComposer, useEditComposerStore } = createContextStoreHook(
2379
+ useMessageContext,
2380
+ "useEditComposer"
2381
+ );
2318
2382
 
2319
2383
  // src/context/react/ComposerContext.ts
2384
+
2320
2385
  var useComposerContext = () => {
2321
- const { useComposer } = useThreadContext();
2322
- const { useEditComposer } = _nullishCoalesce(useMessageContext({ optional: true }), () => ( {}));
2386
+ const { useComposer: useComposer2 } = useThreadContext();
2387
+ const { useEditComposer: useEditComposer2 } = _nullishCoalesce(useMessageContext({ optional: true }), () => ( {}));
2323
2388
  return _react.useMemo.call(void 0,
2324
2389
  () => ({
2325
- useComposer: _nullishCoalesce(useEditComposer, () => ( useComposer)),
2326
- type: useEditComposer ? "edit" : "new"
2390
+ useComposer: _nullishCoalesce(useEditComposer2, () => ( useComposer2)),
2391
+ type: useEditComposer2 ? "edit" : "new"
2327
2392
  }),
2328
- [useEditComposer, useComposer]
2393
+ [useEditComposer2, useComposer2]
2329
2394
  );
2330
2395
  };
2396
+ var { useComposer, useComposerStore } = createContextStoreHook(
2397
+ useComposerContext,
2398
+ "useComposer"
2399
+ );
2331
2400
 
2332
2401
  // src/hooks/useAppendMessage.tsx
2333
2402
 
2334
- var toAppendMessage = (useThreadMessages, message) => {
2403
+ var toAppendMessage = (useThreadMessages2, message) => {
2335
2404
  if (typeof message === "string") {
2336
2405
  return {
2337
- parentId: _nullishCoalesce(_optionalChain([useThreadMessages, 'access', _98 => _98.getState, 'call', _99 => _99(), 'access', _100 => _100.at, 'call', _101 => _101(-1), 'optionalAccess', _102 => _102.id]), () => ( null)),
2406
+ parentId: _nullishCoalesce(_optionalChain([useThreadMessages2, 'access', _92 => _92.getState, 'call', _93 => _93(), 'access', _94 => _94.at, 'call', _95 => _95(-1), 'optionalAccess', _96 => _96.id]), () => ( null)),
2338
2407
  role: "user",
2339
2408
  content: [{ type: "text", text: message }],
2340
2409
  attachments: []
2341
2410
  };
2342
2411
  }
2343
2412
  return {
2344
- 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)),
2413
+ 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)),
2345
2414
  role: _nullishCoalesce(message.role, () => ( "user")),
2346
2415
  content: message.content,
2347
2416
  attachments: _nullishCoalesce(message.attachments, () => ( []))
2348
2417
  };
2349
2418
  };
2350
2419
  var useAppendMessage = () => {
2351
- const { useThreadMessages, useThreadActions, useViewport, useComposer } = useThreadContext();
2420
+ const threadMessagesStore = useThreadMessagesStore();
2421
+ const threadActionsStore = useThreadActionsStore();
2422
+ const threadViewportStore = useThreadViewportStore();
2423
+ const threadComposerStore = useThreadComposerStore();
2352
2424
  const append = _react.useCallback.call(void 0,
2353
2425
  (message) => {
2354
- const appendMessage = toAppendMessage(useThreadMessages, message);
2355
- useThreadActions.getState().append(appendMessage);
2356
- useViewport.getState().scrollToBottom();
2357
- useComposer.getState().focus();
2426
+ const appendMessage = toAppendMessage(threadMessagesStore, message);
2427
+ threadActionsStore.getState().append(appendMessage);
2428
+ threadViewportStore.getState().scrollToBottom();
2429
+ threadComposerStore.getState().focus();
2358
2430
  },
2359
- [useThreadMessages, useThreadActions, useViewport, useComposer]
2431
+ [
2432
+ threadMessagesStore,
2433
+ threadActionsStore,
2434
+ threadViewportStore,
2435
+ threadComposerStore
2436
+ ]
2360
2437
  );
2361
2438
  return append;
2362
2439
  };
@@ -2364,23 +2441,20 @@ var useAppendMessage = () => {
2364
2441
  // src/hooks/useSwitchToNewThread.tsx
2365
2442
 
2366
2443
  var useSwitchToNewThread = () => {
2367
- const { useAssistantActions } = useAssistantContext();
2368
- const { useComposer } = useThreadContext();
2444
+ const assistantActionsStore = useAssistantActionsStore();
2445
+ const threadComposerStore = useThreadComposerStore();
2369
2446
  const switchToNewThread = _react.useCallback.call(void 0, () => {
2370
- useAssistantActions.getState().switchToThread(null);
2371
- useComposer.getState().focus();
2372
- }, [useAssistantActions, useComposer]);
2447
+ assistantActionsStore.getState().switchToNewThread();
2448
+ threadComposerStore.getState().focus();
2449
+ }, [assistantActionsStore, threadComposerStore]);
2373
2450
  return switchToNewThread;
2374
2451
  };
2375
2452
 
2376
2453
  // src/model-config/useAssistantTool.tsx
2377
2454
 
2378
2455
  var useAssistantTool = (tool) => {
2379
- const { useModelConfig, useToolUIs } = useAssistantContext();
2380
- const registerModelConfigProvider = useModelConfig(
2381
- (s) => s.registerModelConfigProvider
2382
- );
2383
- const setToolUI = useToolUIs((s) => s.setToolUI);
2456
+ const assistantActionsStore = useAssistantActionsStore();
2457
+ const toolUIsStore = useToolUIsStore();
2384
2458
  _react.useEffect.call(void 0, () => {
2385
2459
  const { toolName, render, ...rest } = tool;
2386
2460
  const config = {
@@ -2388,15 +2462,15 @@ var useAssistantTool = (tool) => {
2388
2462
  [tool.toolName]: rest
2389
2463
  }
2390
2464
  };
2391
- const unsub1 = registerModelConfigProvider({
2465
+ const unsub1 = assistantActionsStore.getState().registerModelConfigProvider({
2392
2466
  getModelConfig: () => config
2393
2467
  });
2394
- const unsub2 = render ? setToolUI(toolName, render) : void 0;
2468
+ const unsub2 = render ? toolUIsStore.getState().setToolUI(toolName, render) : void 0;
2395
2469
  return () => {
2396
2470
  unsub1();
2397
- _optionalChain([unsub2, 'optionalCall', _108 => _108()]);
2471
+ _optionalChain([unsub2, 'optionalCall', _102 => _102()]);
2398
2472
  };
2399
- }, [registerModelConfigProvider, setToolUI, tool]);
2473
+ }, [assistantActionsStore, toolUIsStore, tool]);
2400
2474
  };
2401
2475
 
2402
2476
  // src/model-config/makeAssistantTool.tsx
@@ -2412,13 +2486,12 @@ var makeAssistantTool = (tool) => {
2412
2486
  // src/model-config/useAssistantToolUI.tsx
2413
2487
 
2414
2488
  var useAssistantToolUI = (tool) => {
2415
- const { useToolUIs } = useAssistantContext();
2416
- const setToolUI = useToolUIs((s) => s.setToolUI);
2489
+ const toolUIsStore = useToolUIsStore();
2417
2490
  _react.useEffect.call(void 0, () => {
2418
2491
  if (!tool) return;
2419
2492
  const { toolName, render } = tool;
2420
- return setToolUI(toolName, render);
2421
- }, [setToolUI, tool]);
2493
+ return toolUIsStore.getState().setToolUI(toolName, render);
2494
+ }, [toolUIsStore, tool]);
2422
2495
  };
2423
2496
 
2424
2497
  // src/model-config/makeAssistantToolUI.tsx
@@ -2434,16 +2507,13 @@ var makeAssistantToolUI = (tool) => {
2434
2507
  // src/model-config/useAssistantInstructions.tsx
2435
2508
 
2436
2509
  var useAssistantInstructions = (instruction) => {
2437
- const { useModelConfig } = useAssistantContext();
2438
- const registerModelConfigProvider = useModelConfig(
2439
- (s) => s.registerModelConfigProvider
2440
- );
2510
+ const actionsStore = useAssistantActionsStore();
2441
2511
  _react.useEffect.call(void 0, () => {
2442
2512
  const config = {
2443
2513
  system: instruction
2444
2514
  };
2445
- return registerModelConfigProvider({ getModelConfig: () => config });
2446
- }, [registerModelConfigProvider, instruction]);
2515
+ return actionsStore.getState().registerModelConfigProvider({ getModelConfig: () => config });
2516
+ }, [actionsStore, instruction]);
2447
2517
  };
2448
2518
 
2449
2519
  // src/primitive-hooks/actionBar/useActionBarCopy.tsx
@@ -2479,23 +2549,25 @@ var useCombinedStore = (stores, selector) => {
2479
2549
  var useActionBarCopy = ({
2480
2550
  copiedDuration = 3e3
2481
2551
  } = {}) => {
2482
- const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();
2552
+ const messageStore = useMessageStore();
2553
+ const messageUtilsStore = useMessageUtilsStore();
2554
+ const editComposerStore = useEditComposerStore();
2483
2555
  const hasCopyableContent = useCombinedStore(
2484
- [useMessage, useEditComposer],
2556
+ [messageStore, editComposerStore],
2485
2557
  ({ message }, c) => {
2486
2558
  return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
2487
2559
  }
2488
2560
  );
2489
2561
  const callback = _react.useCallback.call(void 0, () => {
2490
- const { message } = useMessage.getState();
2491
- const { setIsCopied } = useMessageUtils.getState();
2492
- const { isEditing, text: composerValue } = useEditComposer.getState();
2562
+ const { message } = messageStore.getState();
2563
+ const { setIsCopied } = messageUtilsStore.getState();
2564
+ const { isEditing, text: composerValue } = editComposerStore.getState();
2493
2565
  const valueToCopy = isEditing ? composerValue : getThreadMessageText(message);
2494
2566
  navigator.clipboard.writeText(valueToCopy).then(() => {
2495
2567
  setIsCopied(true);
2496
2568
  setTimeout(() => setIsCopied(false), copiedDuration);
2497
2569
  });
2498
- }, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);
2570
+ }, [messageStore, messageUtilsStore, editComposerStore, copiedDuration]);
2499
2571
  if (!hasCopyableContent) return null;
2500
2572
  return callback;
2501
2573
  };
@@ -2503,12 +2575,12 @@ var useActionBarCopy = ({
2503
2575
  // src/primitive-hooks/actionBar/useActionBarEdit.tsx
2504
2576
 
2505
2577
  var useActionBarEdit = () => {
2506
- const { useEditComposer } = useMessageContext();
2578
+ const editComposerStore = useEditComposerStore();
2507
2579
  const disabled = useEditComposer((c) => c.isEditing);
2508
2580
  const callback = _react.useCallback.call(void 0, () => {
2509
- const { edit } = useEditComposer.getState();
2581
+ const { edit } = editComposerStore.getState();
2510
2582
  edit();
2511
- }, [useEditComposer]);
2583
+ }, [editComposerStore]);
2512
2584
  if (disabled) return null;
2513
2585
  return callback;
2514
2586
  };
@@ -2516,18 +2588,26 @@ var useActionBarEdit = () => {
2516
2588
  // src/primitive-hooks/actionBar/useActionBarReload.tsx
2517
2589
 
2518
2590
  var useActionBarReload = () => {
2519
- const { useThread, useThreadActions, useComposer, useViewport } = useThreadContext();
2520
- const { useMessage } = useMessageContext();
2591
+ const messageStore = useMessageStore();
2592
+ const threadStore = useThreadStore();
2593
+ const threadActionsStore = useThreadActionsStore();
2594
+ const threadComposerStore = useThreadComposerStore();
2595
+ const threadViewportStore = useThreadViewportStore();
2521
2596
  const disabled = useCombinedStore(
2522
- [useThread, useMessage],
2597
+ [threadStore, messageStore],
2523
2598
  (t, m) => t.isRunning || t.isDisabled || m.message.role !== "assistant"
2524
2599
  );
2525
2600
  const callback = _react.useCallback.call(void 0, () => {
2526
- const { parentId } = useMessage.getState();
2527
- useThreadActions.getState().startRun(parentId);
2528
- useViewport.getState().scrollToBottom();
2529
- useComposer.getState().focus();
2530
- }, [useThreadActions, useComposer, useViewport, useMessage]);
2601
+ const { parentId } = messageStore.getState();
2602
+ threadActionsStore.getState().startRun(parentId);
2603
+ threadViewportStore.getState().scrollToBottom();
2604
+ threadComposerStore.getState().focus();
2605
+ }, [
2606
+ threadActionsStore,
2607
+ threadComposerStore,
2608
+ threadViewportStore,
2609
+ messageStore
2610
+ ]);
2531
2611
  if (disabled) return null;
2532
2612
  return callback;
2533
2613
  };
@@ -2535,19 +2615,21 @@ var useActionBarReload = () => {
2535
2615
  // src/primitive-hooks/actionBar/useActionBarSpeak.tsx
2536
2616
 
2537
2617
  var useActionBarSpeak = () => {
2538
- const { useThreadActions } = useThreadContext();
2539
- const { useMessage, useEditComposer, useMessageUtils } = useMessageContext();
2618
+ const messageStore = useMessageStore();
2619
+ const editComposerStore = useEditComposerStore();
2620
+ const threadActionsStore = useThreadActionsStore();
2621
+ const messageUtilsStore = useMessageUtilsStore();
2540
2622
  const hasSpeakableContent = useCombinedStore(
2541
- [useMessage, useEditComposer],
2623
+ [messageStore, editComposerStore],
2542
2624
  ({ message }, c) => {
2543
2625
  return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
2544
2626
  }
2545
2627
  );
2546
2628
  const callback = _react.useCallback.call(void 0, async () => {
2547
- const { message } = useMessage.getState();
2548
- const utt = useThreadActions.getState().speak(message.id);
2549
- useMessageUtils.getState().addUtterance(utt);
2550
- }, [useThreadActions, useMessage, useMessageUtils]);
2629
+ const { message } = messageStore.getState();
2630
+ const utt = threadActionsStore.getState().speak(message.id);
2631
+ messageUtilsStore.getState().addUtterance(utt);
2632
+ }, [threadActionsStore, messageStore, messageUtilsStore]);
2551
2633
  if (!hasSpeakableContent) return null;
2552
2634
  return callback;
2553
2635
  };
@@ -2555,18 +2637,17 @@ var useActionBarSpeak = () => {
2555
2637
  // src/primitive-hooks/actionBar/useActionBarStopSpeaking.tsx
2556
2638
 
2557
2639
  var useActionBarStopSpeaking = () => {
2558
- const { useMessageUtils } = useMessageContext();
2640
+ const messageUtilsStore = useMessageUtilsStore();
2559
2641
  const isSpeaking = useMessageUtils((u) => u.isSpeaking);
2560
2642
  const callback = _react.useCallback.call(void 0, async () => {
2561
- useMessageUtils.getState().stopSpeaking();
2562
- }, [useMessageUtils]);
2643
+ messageUtilsStore.getState().stopSpeaking();
2644
+ }, [messageUtilsStore]);
2563
2645
  if (!isSpeaking) return null;
2564
2646
  return callback;
2565
2647
  };
2566
2648
 
2567
2649
  // src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
2568
2650
  var useBranchPickerCount = () => {
2569
- const { useMessage } = useMessageContext();
2570
2651
  const branchCount = useMessage((s) => s.branches.length);
2571
2652
  return branchCount;
2572
2653
  };
@@ -2574,23 +2655,23 @@ var useBranchPickerCount = () => {
2574
2655
  // src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
2575
2656
 
2576
2657
  var useBranchPickerNext = () => {
2577
- const { useThreadActions } = useThreadContext();
2578
- const { useMessage, useEditComposer } = useMessageContext();
2658
+ const messageStore = useMessageStore();
2659
+ const editComposerStore = useEditComposerStore();
2660
+ const threadActionsStore = useThreadActionsStore();
2579
2661
  const disabled = useCombinedStore(
2580
- [useMessage, useEditComposer],
2662
+ [messageStore, editComposerStore],
2581
2663
  (m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
2582
2664
  );
2583
2665
  const callback = _react.useCallback.call(void 0, () => {
2584
- const { message, branches } = useMessage.getState();
2585
- useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
2586
- }, [useThreadActions, useMessage]);
2666
+ const { message, branches } = messageStore.getState();
2667
+ threadActionsStore.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
2668
+ }, [threadActionsStore, messageStore]);
2587
2669
  if (disabled) return null;
2588
2670
  return callback;
2589
2671
  };
2590
2672
 
2591
2673
  // src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
2592
2674
  var useBranchPickerNumber = () => {
2593
- const { useMessage } = useMessageContext();
2594
2675
  const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
2595
2676
  return branchIdx + 1;
2596
2677
  };
@@ -2598,16 +2679,17 @@ var useBranchPickerNumber = () => {
2598
2679
  // src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
2599
2680
 
2600
2681
  var useBranchPickerPrevious = () => {
2601
- const { useThreadActions } = useThreadContext();
2602
- const { useMessage, useEditComposer } = useMessageContext();
2682
+ const messageStore = useMessageStore();
2683
+ const editComposerStore = useEditComposerStore();
2684
+ const threadActionsStore = useThreadActionsStore();
2603
2685
  const disabled = useCombinedStore(
2604
- [useMessage, useEditComposer],
2686
+ [messageStore, editComposerStore],
2605
2687
  (m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
2606
2688
  );
2607
2689
  const callback = _react.useCallback.call(void 0, () => {
2608
- const { message, branches } = useMessage.getState();
2609
- useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
2610
- }, [useThreadActions, useMessage]);
2690
+ const { message, branches } = messageStore.getState();
2691
+ threadActionsStore.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
2692
+ }, [threadActionsStore, messageStore]);
2611
2693
  if (disabled) return null;
2612
2694
  return callback;
2613
2695
  };
@@ -2615,19 +2697,18 @@ var useBranchPickerPrevious = () => {
2615
2697
  // src/primitive-hooks/composer/useComposerCancel.tsx
2616
2698
 
2617
2699
  var useComposerCancel = () => {
2618
- const { useComposer } = useComposerContext();
2700
+ const composerStore = useComposerStore();
2619
2701
  const disabled = useComposer((c) => !c.canCancel);
2620
2702
  const callback = _react.useCallback.call(void 0, () => {
2621
- const { cancel } = useComposer.getState();
2703
+ const { cancel } = composerStore.getState();
2622
2704
  cancel();
2623
- }, [useComposer]);
2705
+ }, [composerStore]);
2624
2706
  if (disabled) return null;
2625
2707
  return callback;
2626
2708
  };
2627
2709
 
2628
2710
  // src/primitive-hooks/composer/useComposerIf.tsx
2629
2711
  var useComposerIf = (props) => {
2630
- const { useComposer } = useComposerContext();
2631
2712
  return useComposer((composer) => {
2632
2713
  if (props.editing === true && !composer.isEditing) return false;
2633
2714
  if (props.editing === false && composer.isEditing) return false;
@@ -2638,23 +2719,21 @@ var useComposerIf = (props) => {
2638
2719
  // src/primitive-hooks/composer/useComposerSend.tsx
2639
2720
 
2640
2721
  var useComposerSend = () => {
2641
- const {
2642
- useThread,
2643
- useViewport,
2644
- useComposer: useNewComposer
2645
- } = useThreadContext();
2646
- const { useComposer } = useComposerContext();
2722
+ const threadStore = useThreadStore();
2723
+ const threadViewportStore = useThreadViewportStore();
2724
+ const composerStore = useComposerStore();
2725
+ const threadComposerStore = useThreadComposerStore();
2647
2726
  const disabled = useCombinedStore(
2648
- [useThread, useComposer],
2727
+ [threadStore, composerStore],
2649
2728
  (t, c) => t.isRunning || !c.isEditing || c.isEmpty
2650
2729
  );
2651
2730
  const callback = _react.useCallback.call(void 0, () => {
2652
- const composerState = useComposer.getState();
2731
+ const composerState = composerStore.getState();
2653
2732
  if (!composerState.isEditing) return;
2654
2733
  composerState.send();
2655
- useViewport.getState().scrollToBottom();
2656
- useNewComposer.getState().focus();
2657
- }, [useNewComposer, useComposer, useViewport]);
2734
+ threadViewportStore.getState().scrollToBottom();
2735
+ threadComposerStore.getState().focus();
2736
+ }, [threadComposerStore, composerStore, threadViewportStore]);
2658
2737
  if (disabled) return null;
2659
2738
  return callback;
2660
2739
  };
@@ -2662,30 +2741,30 @@ var useComposerSend = () => {
2662
2741
  // src/primitive-hooks/composer/useComposerAddAttachment.tsx
2663
2742
 
2664
2743
  var useComposerAddAttachment = () => {
2665
- const { useComposer, useThreadRuntime } = useThreadContext();
2666
2744
  const disabled = useComposer((c) => !c.isEditing);
2745
+ const threadComposerStore = useThreadComposerStore();
2746
+ const threadRuntimeStore = useThreadComposerStore();
2667
2747
  const callback = _react.useCallback.call(void 0, () => {
2668
- const { addAttachment } = useComposer.getState();
2669
- const { attachmentAccept } = useThreadRuntime.getState().composer;
2748
+ const { addAttachment } = threadComposerStore.getState();
2749
+ const { attachmentAccept } = threadRuntimeStore.getState();
2670
2750
  const input = document.createElement("input");
2671
2751
  input.type = "file";
2672
2752
  if (attachmentAccept !== "*") {
2673
2753
  input.accept = attachmentAccept;
2674
2754
  }
2675
2755
  input.onchange = (e) => {
2676
- const file = _optionalChain([e, 'access', _109 => _109.target, 'access', _110 => _110.files, 'optionalAccess', _111 => _111[0]]);
2756
+ const file = _optionalChain([e, 'access', _103 => _103.target, 'access', _104 => _104.files, 'optionalAccess', _105 => _105[0]]);
2677
2757
  if (!file) return;
2678
2758
  addAttachment(file);
2679
2759
  };
2680
2760
  input.click();
2681
- }, [useComposer, useThreadRuntime]);
2761
+ }, [threadComposerStore, threadRuntimeStore]);
2682
2762
  if (disabled) return null;
2683
2763
  return callback;
2684
2764
  };
2685
2765
 
2686
2766
  // src/primitive-hooks/contentPart/useContentPartDisplay.tsx
2687
2767
  var useContentPartDisplay = () => {
2688
- const { useContentPart } = useContentPartContext();
2689
2768
  const display = useContentPart((c) => {
2690
2769
  if (c.part.type !== "ui")
2691
2770
  throw new Error(
@@ -2698,7 +2777,6 @@ var useContentPartDisplay = () => {
2698
2777
 
2699
2778
  // src/primitive-hooks/contentPart/useContentPartImage.tsx
2700
2779
  var useContentPartImage = () => {
2701
- const { useContentPart } = useContentPartContext();
2702
2780
  const image = useContentPart((c) => {
2703
2781
  if (c.part.type !== "image")
2704
2782
  throw new Error(
@@ -2711,7 +2789,6 @@ var useContentPartImage = () => {
2711
2789
 
2712
2790
  // src/primitive-hooks/contentPart/useContentPartText.tsx
2713
2791
  var useContentPartText = () => {
2714
- const { useContentPart } = useContentPartContext();
2715
2792
  const text = useContentPart((c) => {
2716
2793
  if (c.part.type !== "text")
2717
2794
  throw new Error(
@@ -2724,9 +2801,10 @@ var useContentPartText = () => {
2724
2801
 
2725
2802
  // src/primitive-hooks/message/useMessageIf.tsx
2726
2803
  var useMessageIf = (props) => {
2727
- const { useMessage, useMessageUtils } = useMessageContext();
2804
+ const messageStore = useMessageStore();
2805
+ const messageUtilsStore = useMessageUtilsStore();
2728
2806
  return useCombinedStore(
2729
- [useMessage, useMessageUtils],
2807
+ [messageStore, messageUtilsStore],
2730
2808
  ({ message, branches, isLast }, { isCopied, isHovering, isSpeaking }) => {
2731
2809
  if (props.hasBranches === true && branches.length < 2) return false;
2732
2810
  if (props.user && message.role !== "user") return false;
@@ -2748,9 +2826,10 @@ var useMessageIf = (props) => {
2748
2826
 
2749
2827
  // src/primitive-hooks/thread/useThreadIf.tsx
2750
2828
  var useThreadIf = (props) => {
2751
- const { useThread, useThreadMessages } = useThreadContext();
2829
+ const threadStore = useThreadStore();
2830
+ const threadMessagesStore = useThreadMessagesStore();
2752
2831
  return useCombinedStore(
2753
- [useThread, useThreadMessages],
2832
+ [threadStore, threadMessagesStore],
2754
2833
  (thread, messages) => {
2755
2834
  if (props.empty === true && messages.length !== 0) return false;
2756
2835
  if (props.empty === false && messages.length === 0) return false;
@@ -2771,12 +2850,13 @@ var useThreadEmpty = () => {
2771
2850
  // src/primitive-hooks/thread/useThreadScrollToBottom.tsx
2772
2851
 
2773
2852
  var useThreadScrollToBottom = () => {
2774
- const { useComposer, useViewport } = useThreadContext();
2775
- const isAtBottom = useViewport((s) => s.isAtBottom);
2853
+ const isAtBottom = useThreadViewport((s) => s.isAtBottom);
2854
+ const threadViewportStore = useThreadViewportStore();
2855
+ const threadComposerStore = useThreadComposerStore();
2776
2856
  const handleScrollToBottom = _react.useCallback.call(void 0, () => {
2777
- useViewport.getState().scrollToBottom();
2778
- useComposer.getState().focus();
2779
- }, [useViewport, useComposer]);
2857
+ threadViewportStore.getState().scrollToBottom();
2858
+ threadComposerStore.getState().focus();
2859
+ }, [threadViewportStore, threadComposerStore]);
2780
2860
  if (isAtBottom) return null;
2781
2861
  return handleScrollToBottom;
2782
2862
  };
@@ -2787,19 +2867,20 @@ var useThreadSuggestion = ({
2787
2867
  prompt,
2788
2868
  autoSend
2789
2869
  }) => {
2790
- const { useThread, useComposer } = useThreadContext();
2870
+ const threadStore = useThreadStore();
2871
+ const composerStore = useThreadComposerStore();
2791
2872
  const append = useAppendMessage();
2792
2873
  const disabled = useThread((t) => t.isDisabled);
2793
2874
  const callback = _react.useCallback.call(void 0, () => {
2794
- const thread = useThread.getState();
2795
- const composer = useComposer.getState();
2875
+ const thread = threadStore.getState();
2876
+ const composer = composerStore.getState();
2796
2877
  if (autoSend && !thread.isRunning) {
2797
2878
  append(prompt);
2798
2879
  composer.setText("");
2799
2880
  } else {
2800
2881
  composer.setText(prompt);
2801
2882
  }
2802
- }, [useThread, useComposer, autoSend, append, prompt]);
2883
+ }, [threadStore, composerStore, autoSend, append, prompt]);
2803
2884
  if (disabled) return null;
2804
2885
  return callback;
2805
2886
  };
@@ -2825,10 +2906,11 @@ var useActionBarFloatStatus = ({
2825
2906
  autohide,
2826
2907
  autohideFloat
2827
2908
  }) => {
2828
- const { useThread } = useThreadContext();
2829
- const { useMessage, useMessageUtils } = useMessageContext();
2909
+ const threadStore = useThreadStore();
2910
+ const messageStore = useMessageStore();
2911
+ const messageUtilsStore = useMessageUtilsStore();
2830
2912
  return useCombinedStore(
2831
- [useThread, useMessage, useMessageUtils],
2913
+ [threadStore, messageStore, messageUtilsStore],
2832
2914
  (t, m, mu) => {
2833
2915
  if (hideWhenRunning && t.isRunning) return "hidden" /* Hidden */;
2834
2916
  const autohideEnabled = autohide === "always" || autohide === "not-last" && !m.isLast;
@@ -2886,7 +2968,7 @@ var createActionButton = (displayName, useActionButton, forwardProps = []) => {
2886
2968
  ref: forwardedRef,
2887
2969
  disabled: primitiveProps.disabled || !callback,
2888
2970
  onClick: _primitive.composeEventHandlers.call(void 0, primitiveProps.onClick, () => {
2889
- _optionalChain([callback, 'optionalCall', _112 => _112()]);
2971
+ _optionalChain([callback, 'optionalCall', _106 => _106()]);
2890
2972
  })
2891
2973
  }
2892
2974
  );
@@ -2942,11 +3024,12 @@ var ActionBarPrimitiveStopSpeaking = _react.forwardRef.call(void 0, (props, ref)
2942
3024
  ...props,
2943
3025
  ref,
2944
3026
  onClick: _primitive.composeEventHandlers.call(void 0, props.onClick, () => {
2945
- _optionalChain([callback, 'optionalCall', _113 => _113()]);
3027
+ _optionalChain([callback, 'optionalCall', _107 => _107()]);
2946
3028
  })
2947
3029
  }
2948
3030
  );
2949
3031
  });
3032
+ ActionBarPrimitiveStopSpeaking.displayName = "ActionBarPrimitive.StopSpeaking";
2950
3033
 
2951
3034
  // src/primitives/assistantModal/index.ts
2952
3035
  var assistantModal_exports = {};
@@ -2967,12 +3050,12 @@ var _reactpopover = require('@radix-ui/react-popover'); var PopoverPrimitive2 =
2967
3050
 
2968
3051
  var useOnComposerFocus = (callback) => {
2969
3052
  const callbackRef = _reactusecallbackref.useCallbackRef.call(void 0, callback);
2970
- const { useComposer } = useThreadContext();
3053
+ const threadComposerStore = useThreadComposerStore();
2971
3054
  _react.useEffect.call(void 0, () => {
2972
- return useComposer.getState().onFocus(() => {
3055
+ return threadComposerStore.getState().onFocus(() => {
2973
3056
  callbackRef();
2974
3057
  });
2975
- }, [useComposer, callbackRef]);
3058
+ }, [threadComposerStore, callbackRef]);
2976
3059
  };
2977
3060
 
2978
3061
  // src/primitives/assistantModal/scope.tsx
@@ -3154,10 +3237,10 @@ var useManagedRef = (callback) => {
3154
3237
  var _reactcomposerefs = require('@radix-ui/react-compose-refs');
3155
3238
 
3156
3239
  var useIsHoveringRef = () => {
3157
- const { useMessageUtils } = useMessageContext();
3240
+ const messageUtilsStore = useMessageUtilsStore();
3158
3241
  const callbackRef = _react.useCallback.call(void 0,
3159
3242
  (el) => {
3160
- const setIsHovering = useMessageUtils.getState().setIsHovering;
3243
+ const setIsHovering = messageUtilsStore.getState().setIsHovering;
3161
3244
  const handleMouseEnter = () => {
3162
3245
  setIsHovering(true);
3163
3246
  };
@@ -3172,14 +3255,14 @@ var useIsHoveringRef = () => {
3172
3255
  setIsHovering(false);
3173
3256
  };
3174
3257
  },
3175
- [useMessageUtils]
3258
+ [messageUtilsStore]
3176
3259
  );
3177
3260
  return useManagedRef(callbackRef);
3178
3261
  };
3179
- var MessagePrimitiveRoot = _react.forwardRef.call(void 0, ({ onMouseEnter, onMouseLeave, ...rest }, forwardRef30) => {
3262
+ var MessagePrimitiveRoot = _react.forwardRef.call(void 0, (props, forwardRef30) => {
3180
3263
  const isHoveringRef = useIsHoveringRef();
3181
3264
  const ref = _reactcomposerefs.useComposedRefs.call(void 0, forwardRef30, isHoveringRef);
3182
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactprimitive.Primitive.div, { ...rest, ref });
3265
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactprimitive.Primitive.div, { ...props, ref });
3183
3266
  });
3184
3267
  MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
3185
3268
 
@@ -3219,7 +3302,7 @@ var toContentPartStatus = (message, partIndex, part) => {
3219
3302
  return message.status;
3220
3303
  };
3221
3304
  var EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });
3222
- var getContentPartState = ({ message }, useContentPart, partIndex) => {
3305
+ var getContentPartState = ({ message }, useContentPart2, partIndex) => {
3223
3306
  let part = message.content[partIndex];
3224
3307
  if (!part) {
3225
3308
  if (message.content.length === 0 && partIndex === 0) {
@@ -3231,18 +3314,18 @@ var getContentPartState = ({ message }, useContentPart, partIndex) => {
3231
3314
  part = EMPTY_CONTENT;
3232
3315
  }
3233
3316
  const status = toContentPartStatus(message, partIndex, part);
3234
- const currentState = _optionalChain([useContentPart, 'optionalAccess', _114 => _114.getState, 'call', _115 => _115()]);
3317
+ const currentState = _optionalChain([useContentPart2, 'optionalAccess', _108 => _108.getState, 'call', _109 => _109()]);
3235
3318
  if (currentState && currentState.part === part && currentState.status === status)
3236
3319
  return null;
3237
3320
  return Object.freeze({ part, status });
3238
3321
  };
3239
3322
  var useContentPartContext2 = (partIndex) => {
3240
- const { useMessage } = useMessageContext();
3323
+ const messageStore = useMessageStore();
3241
3324
  const [context] = _react.useState.call(void 0, () => {
3242
- const useContentPart = _zustand.create.call(void 0,
3243
- () => getContentPartState(useMessage.getState(), void 0, partIndex)
3325
+ const useContentPart2 = _zustand.create.call(void 0,
3326
+ () => getContentPartState(messageStore.getState(), void 0, partIndex)
3244
3327
  );
3245
- return { useContentPart };
3328
+ return { useContentPart: useContentPart2 };
3246
3329
  });
3247
3330
  _react.useEffect.call(void 0, () => {
3248
3331
  const syncContentPart = (message) => {
@@ -3254,9 +3337,9 @@ var useContentPartContext2 = (partIndex) => {
3254
3337
  if (!newState) return;
3255
3338
  writableStore(context.useContentPart).setState(newState, true);
3256
3339
  };
3257
- syncContentPart(useMessage.getState());
3258
- return useMessage.subscribe(syncContentPart);
3259
- }, [context, useMessage, partIndex]);
3340
+ syncContentPart(messageStore.getState());
3341
+ return messageStore.subscribe(syncContentPart);
3342
+ }, [context, messageStore, partIndex]);
3260
3343
  return context;
3261
3344
  };
3262
3345
  var ContentPartProvider = ({
@@ -3304,7 +3387,6 @@ ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
3304
3387
 
3305
3388
  // src/primitives/contentPart/ContentPartInProgress.tsx
3306
3389
  var ContentPartPrimitiveInProgress = ({ children }) => {
3307
- const { useContentPart } = useContentPartContext();
3308
3390
  const isInProgress = useContentPart((c) => c.status.type === "running");
3309
3391
  return isInProgress ? children : null;
3310
3392
  };
@@ -3316,7 +3398,6 @@ var ToolUIDisplay = ({
3316
3398
  UI,
3317
3399
  ...props
3318
3400
  }) => {
3319
- const { useToolUIs } = useAssistantContext();
3320
3401
  const Render = _nullishCoalesce(useToolUIs((s) => s.getToolUI(props.part.toolName)), () => ( UI));
3321
3402
  if (!Render) return null;
3322
3403
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Render, { ...props });
@@ -3338,10 +3419,8 @@ var MessageContentPartComponent = ({
3338
3419
  tools: { by_name = {}, Fallback: Fallback2 = void 0 } = {}
3339
3420
  } = {}
3340
3421
  }) => {
3341
- const { useThreadActions } = useThreadContext();
3342
- const { useMessage } = useMessageContext();
3343
- const addToolResult = useThreadActions((t) => t.addToolResult);
3344
- const { useContentPart } = useContentPartContext();
3422
+ const messageStore = useMessageStore();
3423
+ const threadActionsStore = useThreadActionsStore();
3345
3424
  const { part, status } = useContentPart();
3346
3425
  const type = part.type;
3347
3426
  switch (type) {
@@ -3362,8 +3441,8 @@ var MessageContentPartComponent = ({
3362
3441
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UI, { part, status });
3363
3442
  case "tool-call": {
3364
3443
  const Tool = by_name[part.toolName] || Fallback2;
3365
- const addResult = (result) => addToolResult({
3366
- messageId: useMessage.getState().message.id,
3444
+ const addResult = (result) => threadActionsStore.getState().addToolResult({
3445
+ messageId: messageStore.getState().message.id,
3367
3446
  toolName: part.toolName,
3368
3447
  toolCallId: part.toolCallId,
3369
3448
  result
@@ -3391,12 +3470,11 @@ var MessageContentPartImpl = ({
3391
3470
  };
3392
3471
  var MessageContentPart = _react.memo.call(void 0,
3393
3472
  MessageContentPartImpl,
3394
- (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])
3473
+ (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])
3395
3474
  );
3396
3475
  var MessagePrimitiveContent = ({
3397
3476
  components
3398
3477
  }) => {
3399
- const { useMessage } = useMessageContext();
3400
3478
  const contentLength = useMessage((s) => s.message.content.length) || 1;
3401
3479
  return Array.from({ length: contentLength }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageContentPart, { partIndex: index, components }, index));
3402
3480
  };
@@ -3418,42 +3496,64 @@ var AttachmentContext = _react.createContext.call(void 0,
3418
3496
  );
3419
3497
  function useAttachmentContext(options) {
3420
3498
  const context = _react.useContext.call(void 0, AttachmentContext);
3421
- if (_optionalChain([options, 'optionalAccess', _132 => _132.type]) === "composer" && _optionalChain([context, 'optionalAccess', _133 => _133.type]) !== "composer")
3499
+ if (!_optionalChain([options, 'optionalAccess', _126 => _126.optional]) && !context)
3422
3500
  throw new Error(
3423
- "This component must be used within a ComposerPrimitive.Attachments component."
3501
+ "This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
3424
3502
  );
3425
- if (_optionalChain([options, 'optionalAccess', _134 => _134.type]) === "message" && _optionalChain([context, 'optionalAccess', _135 => _135.type]) !== "message")
3503
+ return context;
3504
+ }
3505
+ function useComposerAttachmentContext(options) {
3506
+ const context = useAttachmentContext(options);
3507
+ if (!context) return null;
3508
+ if (context.type !== "composer")
3426
3509
  throw new Error(
3427
- "This component must be used within a MessagePrimitive.Attachments component."
3510
+ "This component must be used within a ComposerPrimitive.Attachments component."
3428
3511
  );
3429
- if (!_optionalChain([options, 'optionalAccess', _136 => _136.optional]) && !context)
3512
+ return context;
3513
+ }
3514
+ function useMessageAttachmentContext(options) {
3515
+ const context = useAttachmentContext(options);
3516
+ if (!context) return null;
3517
+ if (context.type !== "message")
3430
3518
  throw new Error(
3431
- "This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
3519
+ "This component must be used within a MessagePrimitive.Attachments component."
3432
3520
  );
3433
3521
  return context;
3434
3522
  }
3523
+ var { useAttachment, useAttachmentStore } = createContextStoreHook(
3524
+ useAttachmentContext,
3525
+ "useAttachment"
3526
+ );
3527
+ var {
3528
+ useAttachment: useComposerAttachment,
3529
+ useAttachmentStore: useComposerAttachmentStore
3530
+ } = createContextStoreHook(useComposerAttachmentContext, "useAttachment");
3531
+ var {
3532
+ useAttachment: useMessageAttachment,
3533
+ useAttachmentStore: useMessageAttachmentStore
3534
+ } = createContextStoreHook(useMessageAttachmentContext, "useAttachment");
3435
3535
 
3436
3536
  // src/context/providers/MessageAttachmentProvider.tsx
3437
3537
 
3438
3538
 
3439
3539
 
3440
- var getAttachment = ({ message }, useAttachment, partIndex) => {
3540
+ var getAttachment = ({ message }, useAttachment2, partIndex) => {
3441
3541
  if (message.role !== "user") return null;
3442
3542
  const attachments = message.attachments;
3443
- let attachment = attachments[partIndex];
3543
+ const attachment = attachments[partIndex];
3444
3544
  if (!attachment) return null;
3445
- const currentState = _optionalChain([useAttachment, 'optionalAccess', _137 => _137.getState, 'call', _138 => _138()]);
3545
+ const currentState = _optionalChain([useAttachment2, 'optionalAccess', _127 => _127.getState, 'call', _128 => _128()]);
3446
3546
  if (currentState && currentState.attachment === attachment) return null;
3447
3547
  return Object.freeze({ attachment });
3448
3548
  };
3449
- var useMessageAttachmentContext = (partIndex) => {
3450
- const { useMessage } = useMessageContext();
3549
+ var useMessageAttachmentContext2 = (partIndex) => {
3550
+ const messageStore = useMessageStore();
3451
3551
  const [context] = _react.useState.call(void 0,
3452
3552
  () => {
3453
- const useAttachment = _zustand.create.call(void 0,
3454
- () => getAttachment(useMessage.getState(), void 0, partIndex)
3553
+ const useAttachment2 = _zustand.create.call(void 0,
3554
+ () => getAttachment(messageStore.getState(), void 0, partIndex)
3455
3555
  );
3456
- return { type: "message", useAttachment };
3556
+ return { type: "message", useAttachment: useAttachment2 };
3457
3557
  }
3458
3558
  );
3459
3559
  _react.useEffect.call(void 0, () => {
@@ -3466,16 +3566,16 @@ var useMessageAttachmentContext = (partIndex) => {
3466
3566
  if (!newState) return;
3467
3567
  writableStore(context.useAttachment).setState(newState, true);
3468
3568
  };
3469
- syncAttachment(useMessage.getState());
3470
- return useMessage.subscribe(syncAttachment);
3471
- }, [context, useMessage, partIndex]);
3569
+ syncAttachment(messageStore.getState());
3570
+ return messageStore.subscribe(syncAttachment);
3571
+ }, [context, messageStore, partIndex]);
3472
3572
  return context;
3473
3573
  };
3474
3574
  var MessageAttachmentProvider = ({
3475
3575
  attachmentIndex: partIndex,
3476
3576
  children
3477
3577
  }) => {
3478
- const context = useMessageAttachmentContext(partIndex);
3578
+ const context = useMessageAttachmentContext2(partIndex);
3479
3579
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AttachmentContext.Provider, { value: context, children });
3480
3580
  };
3481
3581
 
@@ -3485,19 +3585,18 @@ var getComponent = (components, attachment) => {
3485
3585
  const type = attachment.type;
3486
3586
  switch (type) {
3487
3587
  case "image":
3488
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _139 => _139.Image]), () => ( _optionalChain([components, 'optionalAccess', _140 => _140.Attachment])));
3588
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _129 => _129.Image]), () => ( _optionalChain([components, 'optionalAccess', _130 => _130.Attachment])));
3489
3589
  case "document":
3490
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _141 => _141.Document]), () => ( _optionalChain([components, 'optionalAccess', _142 => _142.Attachment])));
3590
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _131 => _131.Document]), () => ( _optionalChain([components, 'optionalAccess', _132 => _132.Attachment])));
3491
3591
  case "file":
3492
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _143 => _143.File]), () => ( _optionalChain([components, 'optionalAccess', _144 => _144.Attachment])));
3592
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _133 => _133.File]), () => ( _optionalChain([components, 'optionalAccess', _134 => _134.Attachment])));
3493
3593
  default:
3494
3594
  const _exhaustiveCheck = type;
3495
3595
  throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
3496
3596
  }
3497
3597
  };
3498
3598
  var AttachmentComponent = ({ components }) => {
3499
- const { useAttachment } = useAttachmentContext({ type: "message" });
3500
- const Component = useAttachment(
3599
+ const Component = useMessageAttachment(
3501
3600
  (a) => getComponent(components, a.attachment)
3502
3601
  );
3503
3602
  if (!Component) return null;
@@ -3508,10 +3607,9 @@ var MessageAttachmentImpl = ({ components, attachmentIndex }) => {
3508
3607
  };
3509
3608
  var MessageAttachment = _react.memo.call(void 0,
3510
3609
  MessageAttachmentImpl,
3511
- (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])
3610
+ (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])
3512
3611
  );
3513
3612
  var MessagePrimitiveAttachments = ({ components }) => {
3514
- const { useMessage } = useMessageContext();
3515
3613
  const attachmentsCount = useMessage(({ message }) => {
3516
3614
  if (message.role !== "user") return 0;
3517
3615
  return message.attachments.length;
@@ -3593,8 +3691,8 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
3593
3691
  onKeyDown,
3594
3692
  ...rest
3595
3693
  }, forwardedRef) => {
3596
- const { useThread } = useThreadContext();
3597
- const { useComposer, type } = useComposerContext();
3694
+ const threadStore = useThreadStore();
3695
+ const composerStore = useComposerStore();
3598
3696
  const value = useComposer((c) => {
3599
3697
  if (!c.isEditing) return "";
3600
3698
  return c.text;
@@ -3604,7 +3702,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
3604
3702
  const textareaRef = _react.useRef.call(void 0, null);
3605
3703
  const ref = _reactcomposerefs.useComposedRefs.call(void 0, forwardedRef, textareaRef);
3606
3704
  _reactuseescapekeydown.useEscapeKeydown.call(void 0, (e) => {
3607
- const composer = useComposer.getState();
3705
+ const composer = composerStore.getState();
3608
3706
  if (composer.canCancel) {
3609
3707
  composer.cancel();
3610
3708
  e.preventDefault();
@@ -3614,10 +3712,10 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
3614
3712
  if (isDisabled) return;
3615
3713
  if (e.nativeEvent.isComposing) return;
3616
3714
  if (e.key === "Enter" && e.shiftKey === false) {
3617
- const { isRunning } = useThread.getState();
3715
+ const { isRunning } = threadStore.getState();
3618
3716
  if (!isRunning) {
3619
3717
  e.preventDefault();
3620
- _optionalChain([textareaRef, 'access', _161 => _161.current, 'optionalAccess', _162 => _162.closest, 'call', _163 => _163("form"), 'optionalAccess', _164 => _164.requestSubmit, 'call', _165 => _165()]);
3718
+ _optionalChain([textareaRef, 'access', _151 => _151.current, 'optionalAccess', _152 => _152.closest, 'call', _153 => _153("form"), 'optionalAccess', _154 => _154.requestSubmit, 'call', _155 => _155()]);
3621
3719
  }
3622
3720
  }
3623
3721
  };
@@ -3633,7 +3731,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
3633
3731
  }, [autoFocusEnabled]);
3634
3732
  _react.useEffect.call(void 0, () => focus(), [focus]);
3635
3733
  useOnComposerFocus(() => {
3636
- if (type === "new") {
3734
+ if (composerStore.getState().type === "thread") {
3637
3735
  focus();
3638
3736
  }
3639
3737
  });
@@ -3646,7 +3744,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
3646
3744
  ref,
3647
3745
  disabled: isDisabled,
3648
3746
  onChange: _primitive.composeEventHandlers.call(void 0, onChange, (e) => {
3649
- const composerState = useComposer.getState();
3747
+ const composerState = composerStore.getState();
3650
3748
  if (!composerState.isEditing) return;
3651
3749
  return composerState.setText(e.target.value);
3652
3750
  }),
@@ -3682,21 +3780,21 @@ var ComposerPrimitiveAddAttachment = createActionButton(
3682
3780
 
3683
3781
 
3684
3782
 
3685
- var getAttachment2 = ({ attachments }, useAttachment, partIndex) => {
3686
- let attachment = attachments[partIndex];
3783
+ var getAttachment2 = ({ attachments }, useAttachment2, partIndex) => {
3784
+ const attachment = attachments[partIndex];
3687
3785
  if (!attachment) return null;
3688
- const currentState = _optionalChain([useAttachment, 'optionalAccess', _166 => _166.getState, 'call', _167 => _167()]);
3786
+ const currentState = _optionalChain([useAttachment2, 'optionalAccess', _156 => _156.getState, 'call', _157 => _157()]);
3689
3787
  if (currentState && currentState.attachment === attachment) return null;
3690
3788
  return Object.freeze({ attachment });
3691
3789
  };
3692
- var useComposerAttachmentContext = (partIndex) => {
3693
- const { useComposer } = useThreadContext();
3790
+ var useComposerAttachmentContext2 = (partIndex) => {
3791
+ const threadComposerStore = useThreadComposerStore();
3694
3792
  const [context] = _react.useState.call(void 0,
3695
3793
  () => {
3696
- const useAttachment = _zustand.create.call(void 0,
3697
- () => getAttachment2(useComposer.getState(), void 0, partIndex)
3794
+ const useAttachment2 = _zustand.create.call(void 0,
3795
+ () => getAttachment2(threadComposerStore.getState(), void 0, partIndex)
3698
3796
  );
3699
- return { type: "composer", useAttachment };
3797
+ return { type: "composer", useAttachment: useAttachment2 };
3700
3798
  }
3701
3799
  );
3702
3800
  _react.useEffect.call(void 0, () => {
@@ -3709,13 +3807,13 @@ var useComposerAttachmentContext = (partIndex) => {
3709
3807
  if (!newState) return;
3710
3808
  writableStore(context.useAttachment).setState(newState, true);
3711
3809
  };
3712
- syncAttachment(useComposer.getState());
3713
- return useComposer.subscribe(syncAttachment);
3714
- }, [context, useComposer, partIndex]);
3810
+ syncAttachment(threadComposerStore.getState());
3811
+ return threadComposerStore.subscribe(syncAttachment);
3812
+ }, [context, threadComposerStore, partIndex]);
3715
3813
  return context;
3716
3814
  };
3717
3815
  var ComposerAttachmentProvider = ({ attachmentIndex: partIndex, children }) => {
3718
- const context = useComposerAttachmentContext(partIndex);
3816
+ const context = useComposerAttachmentContext2(partIndex);
3719
3817
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AttachmentContext.Provider, { value: context, children });
3720
3818
  };
3721
3819
 
@@ -3725,19 +3823,18 @@ var getComponent2 = (components, attachment) => {
3725
3823
  const type = attachment.type;
3726
3824
  switch (type) {
3727
3825
  case "image":
3728
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _168 => _168.Image]), () => ( _optionalChain([components, 'optionalAccess', _169 => _169.Attachment])));
3826
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _158 => _158.Image]), () => ( _optionalChain([components, 'optionalAccess', _159 => _159.Attachment])));
3729
3827
  case "document":
3730
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _170 => _170.Document]), () => ( _optionalChain([components, 'optionalAccess', _171 => _171.Attachment])));
3828
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _160 => _160.Document]), () => ( _optionalChain([components, 'optionalAccess', _161 => _161.Attachment])));
3731
3829
  case "file":
3732
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _172 => _172.File]), () => ( _optionalChain([components, 'optionalAccess', _173 => _173.Attachment])));
3830
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _162 => _162.File]), () => ( _optionalChain([components, 'optionalAccess', _163 => _163.Attachment])));
3733
3831
  default:
3734
3832
  const _exhaustiveCheck = type;
3735
3833
  throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
3736
3834
  }
3737
3835
  };
3738
3836
  var AttachmentComponent2 = ({ components }) => {
3739
- const { useAttachment } = useAttachmentContext({ type: "composer" });
3740
- const Component = useAttachment(
3837
+ const Component = useComposerAttachment(
3741
3838
  (a) => getComponent2(components, a.attachment)
3742
3839
  );
3743
3840
  if (!Component) return null;
@@ -3748,11 +3845,10 @@ var ComposerAttachmentImpl = ({ components, attachmentIndex }) => {
3748
3845
  };
3749
3846
  var ComposerAttachment = _react.memo.call(void 0,
3750
3847
  ComposerAttachmentImpl,
3751
- (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])
3848
+ (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])
3752
3849
  );
3753
3850
  var ComposerPrimitiveAttachments = ({ components }) => {
3754
- const { useComposer } = useThreadContext();
3755
- const attachmentsCount = useComposer((s) => s.attachments.length);
3851
+ const attachmentsCount = useThreadComposer((s) => s.attachments.length);
3756
3852
  return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
3757
3853
  ComposerAttachment,
3758
3854
  {
@@ -3877,12 +3973,12 @@ var useOnResizeContent = (callback) => {
3877
3973
 
3878
3974
  var useOnScrollToBottom = (callback) => {
3879
3975
  const callbackRef = _reactusecallbackref.useCallbackRef.call(void 0, callback);
3880
- const { useViewport } = useThreadContext();
3976
+ const threadViewportStore = useThreadViewportStore();
3881
3977
  _react.useEffect.call(void 0, () => {
3882
- return useViewport.getState().onScrollToBottom(() => {
3978
+ return threadViewportStore.getState().onScrollToBottom(() => {
3883
3979
  callbackRef();
3884
3980
  });
3885
- }, [useViewport, callbackRef]);
3981
+ }, [threadViewportStore, callbackRef]);
3886
3982
  };
3887
3983
 
3888
3984
  // src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
@@ -3890,7 +3986,7 @@ var useThreadViewportAutoScroll = ({
3890
3986
  autoScroll = true
3891
3987
  }) => {
3892
3988
  const divRef = _react.useRef.call(void 0, null);
3893
- const { useViewport } = useThreadContext();
3989
+ const threadViewportStore = useThreadViewportStore();
3894
3990
  const lastScrollTop = _react.useRef.call(void 0, 0);
3895
3991
  const isScrollingToBottomRef = _react.useRef.call(void 0, false);
3896
3992
  const scrollToBottom = (behavior) => {
@@ -3902,7 +3998,7 @@ var useThreadViewportAutoScroll = ({
3902
3998
  const handleScroll = () => {
3903
3999
  const div = divRef.current;
3904
4000
  if (!div) return;
3905
- const isAtBottom = useViewport.getState().isAtBottom;
4001
+ const isAtBottom = threadViewportStore.getState().isAtBottom;
3906
4002
  const newIsAtBottom = div.scrollHeight - div.scrollTop <= div.clientHeight + 1;
3907
4003
  if (!newIsAtBottom && lastScrollTop.current < div.scrollTop) {
3908
4004
  } else {
@@ -3910,13 +4006,15 @@ var useThreadViewportAutoScroll = ({
3910
4006
  isScrollingToBottomRef.current = false;
3911
4007
  }
3912
4008
  if (newIsAtBottom !== isAtBottom) {
3913
- writableStore(useViewport).setState({ isAtBottom: newIsAtBottom });
4009
+ writableStore(threadViewportStore).setState({
4010
+ isAtBottom: newIsAtBottom
4011
+ });
3914
4012
  }
3915
4013
  }
3916
4014
  lastScrollTop.current = div.scrollTop;
3917
4015
  };
3918
4016
  const resizeRef = useOnResizeContent(() => {
3919
- if (isScrollingToBottomRef.current || useViewport.getState().isAtBottom) {
4017
+ if (isScrollingToBottomRef.current || threadViewportStore.getState().isAtBottom) {
3920
4018
  scrollToBottom("instant");
3921
4019
  }
3922
4020
  handleScroll();
@@ -3936,7 +4034,7 @@ var useThreadViewportAutoScroll = ({
3936
4034
 
3937
4035
  // src/primitives/thread/ThreadViewport.tsx
3938
4036
 
3939
- var ThreadPrimitiveViewport = _react.forwardRef.call(void 0, ({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
4037
+ var ThreadPrimitiveViewport = _react.forwardRef.call(void 0, ({ autoScroll, children, ...rest }, forwardedRef) => {
3940
4038
  const autoScrollRef = useThreadViewportAutoScroll({
3941
4039
  autoScroll
3942
4040
  });
@@ -3958,6 +4056,7 @@ var makeEditComposerStore = ({
3958
4056
  onEdit,
3959
4057
  onSend
3960
4058
  }) => _zustand.create.call(void 0, )((set, get) => ({
4059
+ type: "edit",
3961
4060
  get value() {
3962
4061
  return get().text;
3963
4062
  },
@@ -4005,7 +4104,7 @@ var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => {
4005
4104
  },
4006
4105
  isSpeaking: false,
4007
4106
  stopSpeaking: () => {
4008
- _optionalChain([utterance, 'optionalAccess', _190 => _190.cancel, 'call', _191 => _191()]);
4107
+ _optionalChain([utterance, 'optionalAccess', _180 => _180.cancel, 'call', _181 => _181()]);
4009
4108
  },
4010
4109
  addUtterance: (utt) => {
4011
4110
  utterance = utt;
@@ -4020,15 +4119,15 @@ var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => {
4020
4119
  // src/context/providers/MessageProvider.tsx
4021
4120
 
4022
4121
  var getIsLast = (messages, message) => {
4023
- return _optionalChain([messages, 'access', _192 => _192[messages.length - 1], 'optionalAccess', _193 => _193.id]) === message.id;
4122
+ return _optionalChain([messages, 'access', _182 => _182[messages.length - 1], 'optionalAccess', _183 => _183.id]) === message.id;
4024
4123
  };
4025
- var getMessageState = (messages, getBranches, useMessage, messageIndex) => {
4026
- const parentId = _nullishCoalesce(_optionalChain([messages, 'access', _194 => _194[messageIndex - 1], 'optionalAccess', _195 => _195.id]), () => ( null));
4124
+ var getMessageState = (messages, getBranches, useMessage2, messageIndex) => {
4125
+ const parentId = _nullishCoalesce(_optionalChain([messages, 'access', _184 => _184[messageIndex - 1], 'optionalAccess', _185 => _185.id]), () => ( null));
4027
4126
  const message = messages[messageIndex];
4028
4127
  if (!message) return null;
4029
4128
  const isLast = getIsLast(messages, message);
4030
4129
  const branches = getBranches(message.id);
4031
- const currentState = _optionalChain([useMessage, 'optionalAccess', _196 => _196.getState, 'call', _197 => _197()]);
4130
+ const currentState = _optionalChain([useMessage2, 'optionalAccess', _186 => _186.getState, 'call', _187 => _187()]);
4032
4131
  if (currentState && currentState.message === message && currentState.parentId === parentId && currentState.branches === branches && currentState.isLast === isLast)
4033
4132
  return null;
4034
4133
  return Object.freeze({
@@ -4039,31 +4138,32 @@ var getMessageState = (messages, getBranches, useMessage, messageIndex) => {
4039
4138
  });
4040
4139
  };
4041
4140
  var useMessageContext2 = (messageIndex) => {
4042
- const { useThreadMessages, useThreadActions } = useThreadContext();
4141
+ const threadMessagesStore = useThreadMessagesStore();
4142
+ const threadActionsStore = useThreadActionsStore();
4043
4143
  const [context] = _react.useState.call(void 0, () => {
4044
- const useMessage = _zustand.create.call(void 0,
4144
+ const useMessage2 = _zustand.create.call(void 0,
4045
4145
  () => getMessageState(
4046
- useThreadMessages.getState(),
4047
- useThreadActions.getState().getBranches,
4146
+ threadMessagesStore.getState(),
4147
+ threadActionsStore.getState().getBranches,
4048
4148
  void 0,
4049
4149
  messageIndex
4050
4150
  )
4051
4151
  );
4052
- const useMessageUtils = makeMessageUtilsStore();
4053
- const useEditComposer = makeEditComposerStore({
4152
+ const useMessageUtils2 = makeMessageUtilsStore();
4153
+ const useEditComposer2 = makeEditComposerStore({
4054
4154
  onEdit: () => {
4055
- const message = useMessage.getState().message;
4155
+ const message = useMessage2.getState().message;
4056
4156
  const text = getThreadMessageText(message);
4057
4157
  return text;
4058
4158
  },
4059
4159
  onSend: (text) => {
4060
- const { message, parentId } = useMessage.getState();
4160
+ const { message, parentId } = useMessage2.getState();
4061
4161
  const previousText = getThreadMessageText(message);
4062
4162
  if (previousText === text) return;
4063
4163
  const nonTextParts = message.content.filter(
4064
4164
  (part) => part.type !== "text" && part.type !== "ui"
4065
4165
  );
4066
- useThreadActions.getState().append({
4166
+ threadActionsStore.getState().append({
4067
4167
  parentId,
4068
4168
  role: message.role,
4069
4169
  content: [{ type: "text", text }, ...nonTextParts],
@@ -4071,22 +4171,22 @@ var useMessageContext2 = (messageIndex) => {
4071
4171
  });
4072
4172
  }
4073
4173
  });
4074
- return { useMessage, useMessageUtils, useEditComposer };
4174
+ return { useMessage: useMessage2, useMessageUtils: useMessageUtils2, useEditComposer: useEditComposer2 };
4075
4175
  });
4076
4176
  _react.useEffect.call(void 0, () => {
4077
4177
  const syncMessage = (thread) => {
4078
4178
  const newState = getMessageState(
4079
4179
  thread,
4080
- useThreadActions.getState().getBranches,
4180
+ threadActionsStore.getState().getBranches,
4081
4181
  context.useMessage,
4082
4182
  messageIndex
4083
4183
  );
4084
4184
  if (!newState) return;
4085
4185
  writableStore(context.useMessage).setState(newState, true);
4086
4186
  };
4087
- syncMessage(useThreadMessages.getState());
4088
- return useThreadMessages.subscribe(syncMessage);
4089
- }, [useThreadMessages, useThreadActions, context, messageIndex]);
4187
+ syncMessage(threadMessagesStore.getState());
4188
+ return threadMessagesStore.subscribe(syncMessage);
4189
+ }, [threadMessagesStore, threadActionsStore, context, messageIndex]);
4090
4190
  return context;
4091
4191
  };
4092
4192
  var MessageProvider = ({
@@ -4131,7 +4231,6 @@ var getComponent3 = (components, role, isEditing) => {
4131
4231
  var ThreadMessageComponent = ({
4132
4232
  components
4133
4233
  }) => {
4134
- const { useMessage, useEditComposer } = useMessageContext();
4135
4234
  const role = useMessage((m) => m.message.role);
4136
4235
  const isEditing = useEditComposer((c) => c.isEditing);
4137
4236
  const Component = getComponent3(components, role, isEditing);
@@ -4150,7 +4249,6 @@ var ThreadMessage = _react.memo.call(void 0,
4150
4249
  var ThreadPrimitiveMessagesImpl = ({
4151
4250
  components
4152
4251
  }) => {
4153
- const { useThreadMessages } = useThreadContext();
4154
4252
  const messagesLength = useThreadMessages((t) => t.length);
4155
4253
  if (messagesLength === 0) return null;
4156
4254
  return Array.from({ length: messagesLength }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadMessage, { messageIndex: index, components }, index));
@@ -4188,10 +4286,10 @@ var ThreadConfigProvider = ({
4188
4286
  children,
4189
4287
  config
4190
4288
  }) => {
4191
- const assistant = useAssistantContext({ optional: true });
4289
+ const hasAssistant = !!useAssistantRuntimeStore({ optional: true });
4192
4290
  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 });
4193
- if (!_optionalChain([config, 'optionalAccess', _198 => _198.runtime])) return configProvider;
4194
- if (assistant) {
4291
+ if (!_optionalChain([config, 'optionalAccess', _188 => _188.runtime])) return configProvider;
4292
+ if (hasAssistant) {
4195
4293
  throw new Error(
4196
4294
  "You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
4197
4295
  );
@@ -4212,19 +4310,16 @@ var _lucidereact = require('lucide-react');
4212
4310
 
4213
4311
  var useAllowCopy = (ensureCapability = false) => {
4214
4312
  const { assistantMessage: { allowCopy = true } = {} } = useThreadConfig();
4215
- const { useThread } = useThreadContext();
4216
4313
  const copySupported = useThread((t) => t.capabilities.unstable_copy);
4217
4314
  return allowCopy && (!ensureCapability || copySupported);
4218
4315
  };
4219
4316
  var useAllowSpeak = (ensureCapability = false) => {
4220
4317
  const { assistantMessage: { allowSpeak = true } = {} } = useThreadConfig();
4221
- const { useThread } = useThreadContext();
4222
4318
  const speakSupported = useThread((t) => t.capabilities.speak);
4223
4319
  return allowSpeak && (!ensureCapability || speakSupported);
4224
4320
  };
4225
4321
  var useAllowReload = (ensureCapability = false) => {
4226
4322
  const { assistantMessage: { allowReload = true } = {} } = useThreadConfig();
4227
- const { useThread } = useThreadContext();
4228
4323
  const reloadSupported = useThread((t) => t.capabilities.reload);
4229
4324
  return allowReload && (!ensureCapability || reloadSupported);
4230
4325
  };
@@ -4324,7 +4419,6 @@ var assistant_action_bar_default = Object.assign(
4324
4419
 
4325
4420
  var useAllowBranchPicker = (ensureCapability = false) => {
4326
4421
  const { branchPicker: { allowBranchPicker = true } = {} } = useThreadConfig();
4327
- const { useThread } = useThreadContext();
4328
4422
  const branchPickerSupported = useThread((t) => t.capabilities.edit);
4329
4423
  return allowBranchPicker && (!ensureCapability || branchPickerSupported);
4330
4424
  };
@@ -4463,7 +4557,7 @@ var AssistantMessageContent = _react.forwardRef.call(void 0, ({ components: comp
4463
4557
  {
4464
4558
  components: {
4465
4559
  ...componentsProp,
4466
- Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _199 => _199.Text]), () => ( components.Text)), () => ( content_part_default.Text)),
4560
+ Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _189 => _189.Text]), () => ( components.Text)), () => ( content_part_default.Text)),
4467
4561
  tools: toolsComponents
4468
4562
  }
4469
4563
  }
@@ -4518,8 +4612,7 @@ var ComposerAttachmentRoot = withDefaults("div", {
4518
4612
  });
4519
4613
  ComposerAttachmentRoot.displayName = "ComposerAttachmentRoot";
4520
4614
  var ComposerAttachment2 = () => {
4521
- const { useAttachment } = useAttachmentContext({ type: "composer" });
4522
- const attachment = useAttachment((a) => a.attachment);
4615
+ const attachment = useComposerAttachment((a) => a.attachment);
4523
4616
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, ComposerAttachmentRoot, { children: [
4524
4617
  ".",
4525
4618
  attachment.name.split(".").pop(),
@@ -4533,10 +4626,10 @@ var ComposerAttachmentRemove = _react.forwardRef.call(void 0, (props, ref) => {
4533
4626
  composer: { removeAttachment: { tooltip = "Remove file" } = {} } = {}
4534
4627
  } = {}
4535
4628
  } = useThreadConfig();
4536
- const { useComposer } = useThreadContext();
4537
- const { useAttachment } = useAttachmentContext();
4629
+ const composerStore = useThreadComposerStore();
4630
+ const attachmentStore = useAttachmentStore();
4538
4631
  const handleRemoveAttachment = () => {
4539
- useComposer.getState().removeAttachment(useAttachment.getState().attachment.id);
4632
+ composerStore.getState().removeAttachment(attachmentStore.getState().attachment.id);
4540
4633
  };
4541
4634
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
4542
4635
  TooltipIconButton,
@@ -4565,7 +4658,6 @@ var composer_attachment_default = Object.assign(
4565
4658
 
4566
4659
  var useAllowAttachments = (ensureCapability = false) => {
4567
4660
  const { composer: { allowAttachments = true } = {} } = useThreadConfig();
4568
- const { useThread } = useThreadContext();
4569
4661
  const attachmentsSupported = useThread((t) => t.capabilities.attachments);
4570
4662
  return allowAttachments && (!ensureCapability || attachmentsSupported);
4571
4663
  };
@@ -4608,7 +4700,7 @@ var ComposerAttachments = ({ components }) => {
4608
4700
  {
4609
4701
  components: {
4610
4702
  ...components,
4611
- Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _200 => _200.Attachment]), () => ( composer_attachment_default))
4703
+ Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _190 => _190.Attachment]), () => ( composer_attachment_default))
4612
4704
  }
4613
4705
  }
4614
4706
  ) });
@@ -4637,7 +4729,6 @@ var ComposerAddAttachment = _react.forwardRef.call(void 0, (props, ref) => {
4637
4729
  });
4638
4730
  ComposerAddAttachment.displayName = "ComposerAddAttachment";
4639
4731
  var useAllowCancel = () => {
4640
- const { useThread } = useThreadContext();
4641
4732
  const cancelSupported = useThread((t) => t.capabilities.cancel);
4642
4733
  return cancelSupported;
4643
4734
  };
@@ -4741,7 +4832,7 @@ var ThreadWelcomeSuggestion = ({
4741
4832
  };
4742
4833
  var ThreadWelcomeSuggestions = () => {
4743
4834
  const { welcome: { suggestions } = {} } = useThreadConfig();
4744
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([suggestions, 'optionalAccess', _201 => _201.map, 'call', _202 => _202((suggestion, idx) => {
4835
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([suggestions, 'optionalAccess', _191 => _191.map, 'call', _192 => _192((suggestion, idx) => {
4745
4836
  const key = `${suggestion.prompt}-${idx}`;
4746
4837
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestion, { suggestion }, key);
4747
4838
  })]) });
@@ -4766,7 +4857,6 @@ var thread_welcome_default = Object.assign(ThreadWelcome, exports7);
4766
4857
 
4767
4858
  var useAllowEdit = (ensureCapability = false) => {
4768
4859
  const { userMessage: { allowEdit = true } = {} } = useThreadConfig();
4769
- const { useThread } = useThreadContext();
4770
4860
  const editSupported = useThread((t) => t.capabilities.edit);
4771
4861
  return allowEdit && (!ensureCapability || editSupported);
4772
4862
  };
@@ -4801,7 +4891,6 @@ var UserMessageAttachmentRoot = withDefaults("div", {
4801
4891
  });
4802
4892
  UserMessageAttachmentRoot.displayName = "UserMessageAttachmentRoot";
4803
4893
  var UserMessageAttachment = () => {
4804
- const { useAttachment } = useAttachmentContext();
4805
4894
  const attachment = useAttachment((a) => a.attachment);
4806
4895
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, UserMessageAttachmentRoot, { children: [
4807
4896
  ".",
@@ -4842,7 +4931,7 @@ var UserMessageContent = _react.forwardRef.call(void 0,
4842
4931
  {
4843
4932
  components: {
4844
4933
  ...components,
4845
- Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _203 => _203.Text]), () => ( content_part_default.Text))
4934
+ Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _193 => _193.Text]), () => ( content_part_default.Text))
4846
4935
  }
4847
4936
  }
4848
4937
  ) });
@@ -4860,7 +4949,7 @@ var UserMessageAttachments = ({
4860
4949
  {
4861
4950
  components: {
4862
4951
  ...components,
4863
- Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _204 => _204.Attachment]), () => ( user_message_attachment_default))
4952
+ Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _194 => _194.Attachment]), () => ( user_message_attachment_default))
4864
4953
  }
4865
4954
  }
4866
4955
  ) }) });
@@ -4961,10 +5050,10 @@ var ThreadMessages = ({ components, ...rest }) => {
4961
5050
  thread_exports.Messages,
4962
5051
  {
4963
5052
  components: {
4964
- UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _205 => _205.UserMessage]), () => ( user_message_default)),
4965
- EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _206 => _206.EditComposer]), () => ( edit_composer_default)),
4966
- AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _207 => _207.AssistantMessage]), () => ( assistant_message_default)),
4967
- SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _208 => _208.SystemMessage]), () => ( SystemMessage))
5053
+ UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _195 => _195.UserMessage]), () => ( user_message_default)),
5054
+ EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _196 => _196.EditComposer]), () => ( edit_composer_default)),
5055
+ AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _197 => _197.AssistantMessage]), () => ( assistant_message_default)),
5056
+ SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _198 => _198.SystemMessage]), () => ( SystemMessage))
4968
5057
  },
4969
5058
  ...rest
4970
5059
  }
@@ -5154,5 +5243,33 @@ var assistant_modal_default = Object.assign(AssistantModal, exports13);
5154
5243
 
5155
5244
 
5156
5245
 
5157
- 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;
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
+
5272
+
5273
+
5274
+ 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;
5158
5275
  //# sourceMappingURL=index.js.map