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