@assistant-ui/react 0.5.53 → 0.5.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{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 +983 -74
- package/dist/index.d.ts +983 -74
- package/dist/index.js +555 -438
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +522 -405
- 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.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
toLanguageModelMessages,
|
|
11
11
|
toLanguageModelTools,
|
|
12
12
|
toolResultStream
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-33TPUWEZ.mjs";
|
|
14
14
|
import {
|
|
15
15
|
__export
|
|
16
16
|
} from "./chunk-BJPOCE4O.mjs";
|
|
@@ -22,52 +22,72 @@ import { memo } from "react";
|
|
|
22
22
|
import { useEffect as useEffect4, useInsertionEffect as useInsertionEffect3, useRef as useRef2, useState as useState8 } from "react";
|
|
23
23
|
|
|
24
24
|
// src/context/react/AssistantContext.ts
|
|
25
|
-
import { createContext
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
import { createContext } from "react";
|
|
26
|
+
|
|
27
|
+
// src/context/react/utils/createContextHook.ts
|
|
28
|
+
import { useContext } from "react";
|
|
29
|
+
function createContextHook(context, providerName) {
|
|
30
|
+
function useContextHook(options) {
|
|
31
|
+
const contextValue = useContext(context);
|
|
32
|
+
if (!options?.optional && !contextValue) {
|
|
33
|
+
throw new Error(`This component must be used within ${providerName}.`);
|
|
34
|
+
}
|
|
35
|
+
return contextValue;
|
|
36
|
+
}
|
|
37
|
+
return useContextHook;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
// src/context/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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 (!options?.optional) {
|
|
46
|
+
throw new Error(`This component must be used within a ${contextKey}.`);
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return context[contextKey];
|
|
46
51
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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();
|
|
52
66
|
}
|
|
53
|
-
|
|
67
|
+
return {
|
|
68
|
+
[contextKey]: useStoreHook,
|
|
69
|
+
[`${contextKey}Store`]: useStoreStoreHook
|
|
70
|
+
};
|
|
71
|
+
}
|
|
54
72
|
|
|
55
|
-
// src/context/
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
// src/context/react/AssistantContext.ts
|
|
74
|
+
var AssistantContext = createContext(
|
|
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");
|
|
67
87
|
|
|
68
88
|
// src/context/stores/AssistantToolUIs.ts
|
|
69
|
-
import { create
|
|
70
|
-
var makeAssistantToolUIsStore = () =>
|
|
89
|
+
import { create } from "zustand";
|
|
90
|
+
var makeAssistantToolUIsStore = () => create((set) => {
|
|
71
91
|
const renderers = /* @__PURE__ */ new Map();
|
|
72
92
|
return Object.freeze({
|
|
73
93
|
getToolUI: (name) => {
|
|
@@ -101,53 +121,66 @@ var makeAssistantToolUIsStore = () => create2((set) => {
|
|
|
101
121
|
import { useEffect as useEffect3, useInsertionEffect as useInsertionEffect2, useState as useState7 } from "react";
|
|
102
122
|
|
|
103
123
|
// src/context/react/ThreadContext.ts
|
|
104
|
-
import { createContext as createContext2
|
|
124
|
+
import { createContext as createContext2 } from "react";
|
|
105
125
|
var ThreadContext = createContext2(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
|
+
import { create as create2 } from "zustand";
|
|
148
|
+
var makeThreadComposerStore = (useThreadRuntime2) => {
|
|
118
149
|
const focusListeners = /* @__PURE__ */ new Set();
|
|
119
|
-
return
|
|
120
|
-
const runtime =
|
|
150
|
+
return create2()((_, get) => {
|
|
151
|
+
const runtime = useThreadRuntime2.getState();
|
|
121
152
|
return {
|
|
153
|
+
type: "thread",
|
|
122
154
|
get value() {
|
|
123
155
|
return get().text;
|
|
124
156
|
},
|
|
125
157
|
setValue(value) {
|
|
126
158
|
get().setText(value);
|
|
127
159
|
},
|
|
160
|
+
attachmentAccept: runtime.composer.attachmentAccept,
|
|
128
161
|
attachments: runtime.composer.attachments,
|
|
129
162
|
addAttachment: (file) => {
|
|
130
|
-
|
|
163
|
+
useThreadRuntime2.getState().composer.addAttachment(file);
|
|
131
164
|
},
|
|
132
165
|
removeAttachment: (attachmentId) => {
|
|
133
|
-
|
|
166
|
+
useThreadRuntime2.getState().composer.removeAttachment(attachmentId);
|
|
134
167
|
},
|
|
135
168
|
reset: () => {
|
|
136
|
-
|
|
169
|
+
useThreadRuntime2.getState().composer.reset();
|
|
137
170
|
},
|
|
138
171
|
text: runtime.composer.text,
|
|
139
172
|
setText: (text) => {
|
|
140
|
-
|
|
173
|
+
useThreadRuntime2.getState().composer.setText(text);
|
|
141
174
|
},
|
|
142
175
|
canCancel: runtime.capabilities.cancel,
|
|
143
176
|
isEditing: true,
|
|
144
177
|
isEmpty: runtime.composer.isEmpty,
|
|
145
178
|
send: () => {
|
|
146
|
-
const runtime2 =
|
|
179
|
+
const runtime2 = useThreadRuntime2.getState();
|
|
147
180
|
runtime2.composer.send();
|
|
148
181
|
},
|
|
149
182
|
cancel: () => {
|
|
150
|
-
|
|
183
|
+
useThreadRuntime2.getState().cancelRun();
|
|
151
184
|
},
|
|
152
185
|
focus: () => {
|
|
153
186
|
for (const listener of focusListeners) {
|
|
@@ -165,7 +198,7 @@ var makeComposerStore = (useThreadRuntime) => {
|
|
|
165
198
|
};
|
|
166
199
|
|
|
167
200
|
// src/context/stores/Thread.ts
|
|
168
|
-
import { create as
|
|
201
|
+
import { create as create3 } from "zustand";
|
|
169
202
|
var getThreadStateFromRuntime = (runtime) => {
|
|
170
203
|
const lastMessage = runtime.messages.at(-1);
|
|
171
204
|
return Object.freeze({
|
|
@@ -177,14 +210,14 @@ var getThreadStateFromRuntime = (runtime) => {
|
|
|
177
210
|
};
|
|
178
211
|
var makeThreadStore = (runtimeRef) => {
|
|
179
212
|
const runtime = runtimeRef.getState();
|
|
180
|
-
return
|
|
213
|
+
return create3(() => getThreadStateFromRuntime(runtime));
|
|
181
214
|
};
|
|
182
215
|
|
|
183
216
|
// src/context/stores/ThreadViewport.tsx
|
|
184
|
-
import { create as
|
|
217
|
+
import { create as create4 } from "zustand";
|
|
185
218
|
var makeThreadViewportStore = () => {
|
|
186
219
|
const scrollToBottomListeners = /* @__PURE__ */ new Set();
|
|
187
|
-
return
|
|
220
|
+
return create4(() => ({
|
|
188
221
|
isAtBottom: true,
|
|
189
222
|
scrollToBottom: () => {
|
|
190
223
|
for (const listener of scrollToBottomListeners) {
|
|
@@ -201,9 +234,9 @@ var makeThreadViewportStore = () => {
|
|
|
201
234
|
};
|
|
202
235
|
|
|
203
236
|
// src/context/stores/ThreadActions.ts
|
|
204
|
-
import { create as
|
|
237
|
+
import { create as create5 } from "zustand";
|
|
205
238
|
var makeThreadActionStore = (runtimeStore) => {
|
|
206
|
-
return
|
|
239
|
+
return create5(
|
|
207
240
|
() => Object.freeze({
|
|
208
241
|
getBranches: (messageId) => runtimeStore.getState().getBranches(messageId),
|
|
209
242
|
switchToBranch: (branchId) => runtimeStore.getState().switchToBranch(branchId),
|
|
@@ -217,15 +250,15 @@ var makeThreadActionStore = (runtimeStore) => {
|
|
|
217
250
|
};
|
|
218
251
|
|
|
219
252
|
// src/context/stores/ThreadMessages.ts
|
|
220
|
-
import { create as
|
|
253
|
+
import { create as create6 } from "zustand";
|
|
221
254
|
var makeThreadMessagesStore = (runtimeRef) => {
|
|
222
|
-
return
|
|
255
|
+
return create6(() => runtimeRef.getState().messages);
|
|
223
256
|
};
|
|
224
257
|
|
|
225
258
|
// src/context/stores/ThreadRuntime.tsx
|
|
226
|
-
import { create as
|
|
259
|
+
import { create as create7 } from "zustand";
|
|
227
260
|
var makeThreadRuntimeStore = (runtime) => {
|
|
228
|
-
return
|
|
261
|
+
return create7(() => runtime);
|
|
229
262
|
};
|
|
230
263
|
|
|
231
264
|
// src/runtimes/core/subscribeToMainThread.ts
|
|
@@ -358,6 +391,20 @@ var ThreadRuntimeComposer = class {
|
|
|
358
391
|
}
|
|
359
392
|
};
|
|
360
393
|
|
|
394
|
+
// src/utils/ProxyConfigProvider.ts
|
|
395
|
+
var ProxyConfigProvider = class {
|
|
396
|
+
_providers = /* @__PURE__ */ new Set();
|
|
397
|
+
getModelConfig() {
|
|
398
|
+
return mergeModelConfigs(this._providers);
|
|
399
|
+
}
|
|
400
|
+
registerModelConfigProvider(provider) {
|
|
401
|
+
this._providers.add(provider);
|
|
402
|
+
return () => {
|
|
403
|
+
this._providers.delete(provider);
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
|
|
361
408
|
// src/utils/idUtils.tsx
|
|
362
409
|
import { customAlphabet } from "nanoid/non-secure";
|
|
363
410
|
var generateId = customAlphabet(
|
|
@@ -609,26 +656,43 @@ var MessageRepository = class {
|
|
|
609
656
|
|
|
610
657
|
// src/utils/smooth/useSmooth.tsx
|
|
611
658
|
import { useEffect, useMemo, useRef, useState as useState2 } from "react";
|
|
659
|
+
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
|
612
660
|
|
|
613
661
|
// src/utils/smooth/SmoothContext.tsx
|
|
614
662
|
import {
|
|
615
|
-
createContext as
|
|
663
|
+
createContext as createContext4,
|
|
616
664
|
forwardRef,
|
|
617
|
-
useContext as
|
|
665
|
+
useContext as useContext2,
|
|
618
666
|
useState
|
|
619
667
|
} from "react";
|
|
620
|
-
import { create as
|
|
668
|
+
import { create as create8 } from "zustand";
|
|
669
|
+
|
|
670
|
+
// src/context/react/ContentPartContext.ts
|
|
671
|
+
import { createContext as createContext3 } from "react";
|
|
672
|
+
var ContentPartContext = createContext3(
|
|
673
|
+
null
|
|
674
|
+
);
|
|
675
|
+
var useContentPartContext = createContextHook(
|
|
676
|
+
ContentPartContext,
|
|
677
|
+
"a component passed to <MessagePrimitive.Content components={...}>"
|
|
678
|
+
);
|
|
679
|
+
var { useContentPart, useContentPartStore } = createContextStoreHook(
|
|
680
|
+
useContentPartContext,
|
|
681
|
+
"useContentPart"
|
|
682
|
+
);
|
|
683
|
+
|
|
684
|
+
// src/utils/smooth/SmoothContext.tsx
|
|
621
685
|
import { jsx } from "react/jsx-runtime";
|
|
622
|
-
var SmoothContext =
|
|
686
|
+
var SmoothContext = createContext4(null);
|
|
623
687
|
var makeSmoothContext = (initialState) => {
|
|
624
|
-
const useSmoothStatus2 =
|
|
688
|
+
const useSmoothStatus2 = create8(() => initialState);
|
|
625
689
|
return { useSmoothStatus: useSmoothStatus2 };
|
|
626
690
|
};
|
|
627
691
|
var SmoothContextProvider = ({ children }) => {
|
|
628
692
|
const outer = useSmoothContext({ optional: true });
|
|
629
|
-
const
|
|
693
|
+
const contentPartStore = useContentPartStore();
|
|
630
694
|
const [context] = useState(
|
|
631
|
-
() => makeSmoothContext(
|
|
695
|
+
() => makeSmoothContext(contentPartStore.getState().status)
|
|
632
696
|
);
|
|
633
697
|
if (outer) return children;
|
|
634
698
|
return /* @__PURE__ */ jsx(SmoothContext.Provider, { value: context, children });
|
|
@@ -641,20 +705,24 @@ var withSmoothContextProvider = (Component) => {
|
|
|
641
705
|
return Wrapped;
|
|
642
706
|
};
|
|
643
707
|
function useSmoothContext(options) {
|
|
644
|
-
const context =
|
|
708
|
+
const context = useContext2(SmoothContext);
|
|
645
709
|
if (!options?.optional && !context)
|
|
646
710
|
throw new Error(
|
|
647
711
|
"This component must be used within a SmoothContextProvider."
|
|
648
712
|
);
|
|
649
713
|
return context;
|
|
650
714
|
}
|
|
651
|
-
var useSmoothStatus = (
|
|
652
|
-
|
|
653
|
-
|
|
715
|
+
var { useSmoothStatus, useSmoothStatusStore } = createContextStoreHook(
|
|
716
|
+
useSmoothContext,
|
|
717
|
+
"useSmoothStatus"
|
|
718
|
+
);
|
|
719
|
+
|
|
720
|
+
// src/context/ReadonlyStore.ts
|
|
721
|
+
var writableStore = (store) => {
|
|
722
|
+
return store;
|
|
654
723
|
};
|
|
655
724
|
|
|
656
725
|
// src/utils/smooth/useSmooth.tsx
|
|
657
|
-
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
|
658
726
|
var TextStreamAnimator = class {
|
|
659
727
|
constructor(currentText, setText) {
|
|
660
728
|
this.currentText = currentText;
|
|
@@ -703,21 +771,28 @@ var SMOOTH_STATUS = Object.freeze({
|
|
|
703
771
|
type: "running"
|
|
704
772
|
});
|
|
705
773
|
var useSmooth = (state, smooth = false) => {
|
|
706
|
-
const { useSmoothStatus: useSmoothStatus2 } = useSmoothContext({ optional: true }) ?? {};
|
|
707
774
|
const {
|
|
708
775
|
part: { text }
|
|
709
776
|
} = state;
|
|
710
|
-
const { useMessage } = useMessageContext();
|
|
711
777
|
const id = useMessage((m) => m.message.id);
|
|
712
778
|
const idRef = useRef(id);
|
|
713
779
|
const [displayedText, setDisplayedText] = useState2(text);
|
|
780
|
+
const smoothStatusStore = useSmoothStatusStore({ optional: true });
|
|
714
781
|
const setText = useCallbackRef((text2) => {
|
|
715
782
|
setDisplayedText(text2);
|
|
716
|
-
|
|
783
|
+
if (smoothStatusStore) {
|
|
784
|
+
writableStore(smoothStatusStore).setState(
|
|
785
|
+
text2 !== state.part.text ? SMOOTH_STATUS : state.status
|
|
786
|
+
);
|
|
787
|
+
}
|
|
717
788
|
});
|
|
718
789
|
useEffect(() => {
|
|
719
|
-
|
|
720
|
-
|
|
790
|
+
if (smoothStatusStore) {
|
|
791
|
+
writableStore(smoothStatusStore).setState(
|
|
792
|
+
text !== state.part.text ? SMOOTH_STATUS : state.status
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
}, [smoothStatusStore, text, displayedText, state.status, state.part.text]);
|
|
721
796
|
const [animatorRef] = useState2(
|
|
722
797
|
new TextStreamAnimator(text, setText)
|
|
723
798
|
);
|
|
@@ -1350,7 +1425,9 @@ var LocalThreadRuntime = class {
|
|
|
1350
1425
|
toolCallId,
|
|
1351
1426
|
result
|
|
1352
1427
|
}) {
|
|
1353
|
-
|
|
1428
|
+
const messageData = this.repository.getMessage(messageId);
|
|
1429
|
+
const { parentId } = messageData;
|
|
1430
|
+
let { message } = messageData;
|
|
1354
1431
|
if (message.role !== "assistant")
|
|
1355
1432
|
throw new Error("Tried to add tool result to non-assistant message");
|
|
1356
1433
|
let added = false;
|
|
@@ -1421,10 +1498,7 @@ var LocalRuntime = class extends BaseAssistantRuntime {
|
|
|
1421
1498
|
registerModelConfigProvider(provider) {
|
|
1422
1499
|
return this._proxyConfigProvider.registerModelConfigProvider(provider);
|
|
1423
1500
|
}
|
|
1424
|
-
|
|
1425
|
-
if (threadId) {
|
|
1426
|
-
throw new Error("LocalRuntime does not yet support switching threads");
|
|
1427
|
-
}
|
|
1501
|
+
switchToNewThread() {
|
|
1428
1502
|
const { initialMessages, ...options } = this.thread.options;
|
|
1429
1503
|
return this.thread = new LocalThreadRuntime(
|
|
1430
1504
|
this._proxyConfigProvider,
|
|
@@ -1432,6 +1506,12 @@ var LocalRuntime = class extends BaseAssistantRuntime {
|
|
|
1432
1506
|
options
|
|
1433
1507
|
);
|
|
1434
1508
|
}
|
|
1509
|
+
switchToThread(threadId) {
|
|
1510
|
+
if (threadId !== null) {
|
|
1511
|
+
throw new Error("LocalRuntime does not yet support switching threads");
|
|
1512
|
+
}
|
|
1513
|
+
this.switchToNewThread();
|
|
1514
|
+
}
|
|
1435
1515
|
reset({
|
|
1436
1516
|
initialMessages
|
|
1437
1517
|
} = {}) {
|
|
@@ -1755,23 +1835,26 @@ var ExternalStoreRuntime = class extends BaseAssistantRuntime {
|
|
|
1755
1835
|
registerModelConfigProvider(provider) {
|
|
1756
1836
|
return this._proxyConfigProvider.registerModelConfigProvider(provider);
|
|
1757
1837
|
}
|
|
1838
|
+
async switchToNewThread() {
|
|
1839
|
+
if (!this.store.onSwitchToNewThread)
|
|
1840
|
+
throw new Error("Runtime does not support switching to new threads.");
|
|
1841
|
+
this.thread = new ExternalStoreThreadRuntime({
|
|
1842
|
+
messages: [],
|
|
1843
|
+
onNew: this.store.onNew
|
|
1844
|
+
});
|
|
1845
|
+
await this.store.onSwitchToNewThread();
|
|
1846
|
+
}
|
|
1758
1847
|
async switchToThread(threadId) {
|
|
1759
|
-
if (threadId) {
|
|
1760
|
-
if (!this.store.
|
|
1848
|
+
if (threadId !== null) {
|
|
1849
|
+
if (!this.store.onSwitchToThread)
|
|
1761
1850
|
throw new Error("Runtime does not support switching threads.");
|
|
1762
1851
|
this.thread = new ExternalStoreThreadRuntime({
|
|
1763
1852
|
messages: [],
|
|
1764
1853
|
onNew: this.store.onNew
|
|
1765
1854
|
});
|
|
1766
|
-
this.store.
|
|
1855
|
+
this.store.onSwitchToThread(threadId);
|
|
1767
1856
|
} 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();
|
|
1857
|
+
this.switchToNewThread();
|
|
1775
1858
|
}
|
|
1776
1859
|
}
|
|
1777
1860
|
};
|
|
@@ -2146,11 +2229,6 @@ var CompositeAttachmentAdapter = class {
|
|
|
2146
2229
|
}
|
|
2147
2230
|
};
|
|
2148
2231
|
|
|
2149
|
-
// src/context/ReadonlyStore.ts
|
|
2150
|
-
var writableStore = (store) => {
|
|
2151
|
-
return store;
|
|
2152
|
-
};
|
|
2153
|
-
|
|
2154
2232
|
// src/context/providers/ThreadProvider.tsx
|
|
2155
2233
|
import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2156
2234
|
var ThreadProvider = ({
|
|
@@ -2158,18 +2236,18 @@ var ThreadProvider = ({
|
|
|
2158
2236
|
provider
|
|
2159
2237
|
}) => {
|
|
2160
2238
|
const [context] = useState7(() => {
|
|
2161
|
-
const
|
|
2162
|
-
const
|
|
2163
|
-
const
|
|
2164
|
-
const
|
|
2239
|
+
const useThreadRuntime2 = makeThreadRuntimeStore(provider.thread);
|
|
2240
|
+
const useThread2 = makeThreadStore(useThreadRuntime2);
|
|
2241
|
+
const useThreadMessages2 = makeThreadMessagesStore(useThreadRuntime2);
|
|
2242
|
+
const useThreadActions2 = makeThreadActionStore(useThreadRuntime2);
|
|
2165
2243
|
const useViewport = makeThreadViewportStore();
|
|
2166
|
-
const
|
|
2244
|
+
const useComposer2 = makeThreadComposerStore(useThreadRuntime2);
|
|
2167
2245
|
return {
|
|
2168
|
-
useThread,
|
|
2169
|
-
useThreadRuntime,
|
|
2170
|
-
useThreadMessages,
|
|
2171
|
-
useThreadActions,
|
|
2172
|
-
useComposer,
|
|
2246
|
+
useThread: useThread2,
|
|
2247
|
+
useThreadRuntime: useThreadRuntime2,
|
|
2248
|
+
useThreadMessages: useThreadMessages2,
|
|
2249
|
+
useThreadActions: useThreadActions2,
|
|
2250
|
+
useComposer: useComposer2,
|
|
2173
2251
|
useViewport
|
|
2174
2252
|
};
|
|
2175
2253
|
});
|
|
@@ -2189,10 +2267,11 @@ var ThreadProvider = ({
|
|
|
2189
2267
|
);
|
|
2190
2268
|
}
|
|
2191
2269
|
const composerState = context.useComposer.getState();
|
|
2192
|
-
if (thread.composer.isEmpty !== composerState.isEmpty || thread.composer.text !== composerState.text || thread.composer.attachments !== composerState.attachments || state.capabilities.cancel !== composerState.canCancel) {
|
|
2270
|
+
if (thread.composer.isEmpty !== composerState.isEmpty || thread.composer.text !== composerState.text || thread.composer.attachmentAccept !== composerState.attachmentAccept || thread.composer.attachments !== composerState.attachments || state.capabilities.cancel !== composerState.canCancel) {
|
|
2193
2271
|
writableStore(context.useComposer).setState({
|
|
2194
2272
|
isEmpty: thread.composer.isEmpty,
|
|
2195
2273
|
text: thread.composer.text,
|
|
2274
|
+
attachmentAccept: thread.composer.attachmentAccept,
|
|
2196
2275
|
attachments: thread.composer.attachments,
|
|
2197
2276
|
canCancel: state.capabilities.cancel
|
|
2198
2277
|
});
|
|
@@ -2217,18 +2296,20 @@ var ThreadProvider = ({
|
|
|
2217
2296
|
};
|
|
2218
2297
|
|
|
2219
2298
|
// src/context/stores/AssistantActions.tsx
|
|
2220
|
-
import { create as
|
|
2221
|
-
var makeAssistantActionsStore = (runtimeRef) =>
|
|
2299
|
+
import { create as create9 } from "zustand";
|
|
2300
|
+
var makeAssistantActionsStore = (runtimeRef) => create9(
|
|
2222
2301
|
() => Object.freeze({
|
|
2223
2302
|
switchToThread: () => runtimeRef.current.switchToThread(null),
|
|
2303
|
+
switchToNewThread: () => runtimeRef.current.switchToNewThread(),
|
|
2304
|
+
registerModelConfigProvider: (provider) => runtimeRef.current.registerModelConfigProvider(provider),
|
|
2224
2305
|
getRuntime: () => runtimeRef.current
|
|
2225
2306
|
})
|
|
2226
2307
|
);
|
|
2227
2308
|
|
|
2228
2309
|
// src/context/stores/AssistantRuntime.tsx
|
|
2229
|
-
import { create as
|
|
2310
|
+
import { create as create10 } from "zustand";
|
|
2230
2311
|
var makeAssistantRuntimeStore = (runtime) => {
|
|
2231
|
-
return
|
|
2312
|
+
return create10(() => runtime);
|
|
2232
2313
|
};
|
|
2233
2314
|
|
|
2234
2315
|
// src/context/providers/AssistantProvider.tsx
|
|
@@ -2239,21 +2320,15 @@ var AssistantProvider = ({ children, runtime }) => {
|
|
|
2239
2320
|
runtimeRef.current = runtime;
|
|
2240
2321
|
});
|
|
2241
2322
|
const [context] = useState8(() => {
|
|
2242
|
-
const
|
|
2243
|
-
const
|
|
2244
|
-
const
|
|
2245
|
-
const useAssistantActions = makeAssistantActionsStore(runtimeRef);
|
|
2323
|
+
const useAssistantRuntime2 = makeAssistantRuntimeStore(runtime);
|
|
2324
|
+
const useToolUIs2 = makeAssistantToolUIsStore();
|
|
2325
|
+
const useAssistantActions2 = makeAssistantActionsStore(runtimeRef);
|
|
2246
2326
|
return {
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
useAssistantActions
|
|
2327
|
+
useToolUIs: useToolUIs2,
|
|
2328
|
+
useAssistantRuntime: useAssistantRuntime2,
|
|
2329
|
+
useAssistantActions: useAssistantActions2
|
|
2251
2330
|
};
|
|
2252
2331
|
});
|
|
2253
|
-
const getModelConfig = context.useModelConfig();
|
|
2254
|
-
useEffect4(() => {
|
|
2255
|
-
return runtime.registerModelConfigProvider(getModelConfig);
|
|
2256
|
-
}, [runtime, getModelConfig]);
|
|
2257
2332
|
useEffect4(
|
|
2258
2333
|
() => writableStore(context.useAssistantRuntime).setState(runtime, true),
|
|
2259
2334
|
[runtime, context]
|
|
@@ -2270,93 +2345,95 @@ var AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
|
|
|
2270
2345
|
|
|
2271
2346
|
// src/context/providers/TextContentPartProvider.tsx
|
|
2272
2347
|
import { useState as useState9 } from "react";
|
|
2273
|
-
import { create as
|
|
2274
|
-
|
|
2275
|
-
// src/context/react/ContentPartContext.ts
|
|
2276
|
-
import { createContext as createContext4, useContext as useContext4 } from "react";
|
|
2277
|
-
var ContentPartContext = createContext4(
|
|
2278
|
-
null
|
|
2279
|
-
);
|
|
2280
|
-
function useContentPartContext(options) {
|
|
2281
|
-
const context = useContext4(ContentPartContext);
|
|
2282
|
-
if (!options?.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
|
|
2348
|
+
import { create as create11 } from "zustand";
|
|
2290
2349
|
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
2291
2350
|
var TextContentPartProvider = ({ children, text }) => {
|
|
2292
2351
|
const [context] = useState9(() => {
|
|
2293
|
-
const
|
|
2352
|
+
const useContentPart2 = create11(() => ({
|
|
2294
2353
|
status: { type: "complete" },
|
|
2295
2354
|
part: { type: "text", text }
|
|
2296
2355
|
}));
|
|
2297
2356
|
return {
|
|
2298
|
-
useContentPart
|
|
2357
|
+
useContentPart: useContentPart2
|
|
2299
2358
|
};
|
|
2300
2359
|
});
|
|
2301
2360
|
return /* @__PURE__ */ jsx9(ContentPartContext.Provider, { value: context, children });
|
|
2302
2361
|
};
|
|
2303
2362
|
|
|
2304
|
-
// src/context/react/ComposerContext.ts
|
|
2305
|
-
import { useMemo as useMemo3 } from "react";
|
|
2306
|
-
|
|
2307
2363
|
// src/context/react/MessageContext.ts
|
|
2308
|
-
import { createContext as createContext5
|
|
2364
|
+
import { createContext as createContext5 } from "react";
|
|
2309
2365
|
var MessageContext = createContext5(null);
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2366
|
+
var useMessageContext = createContextHook(
|
|
2367
|
+
MessageContext,
|
|
2368
|
+
"a component passed to <ThreadPrimitive.Messages components={...} />"
|
|
2369
|
+
);
|
|
2370
|
+
var { useMessage, useMessageStore } = createContextStoreHook(
|
|
2371
|
+
useMessageContext,
|
|
2372
|
+
"useMessage"
|
|
2373
|
+
);
|
|
2374
|
+
var { useMessageUtils, useMessageUtilsStore } = createContextStoreHook(
|
|
2375
|
+
useMessageContext,
|
|
2376
|
+
"useMessageUtils"
|
|
2377
|
+
);
|
|
2378
|
+
var { useEditComposer, useEditComposerStore } = createContextStoreHook(
|
|
2379
|
+
useMessageContext,
|
|
2380
|
+
"useEditComposer"
|
|
2381
|
+
);
|
|
2318
2382
|
|
|
2319
2383
|
// src/context/react/ComposerContext.ts
|
|
2384
|
+
import { useMemo as useMemo3 } from "react";
|
|
2320
2385
|
var useComposerContext = () => {
|
|
2321
|
-
const { useComposer } = useThreadContext();
|
|
2322
|
-
const { useEditComposer } = useMessageContext({ optional: true }) ?? {};
|
|
2386
|
+
const { useComposer: useComposer2 } = useThreadContext();
|
|
2387
|
+
const { useEditComposer: useEditComposer2 } = useMessageContext({ optional: true }) ?? {};
|
|
2323
2388
|
return useMemo3(
|
|
2324
2389
|
() => ({
|
|
2325
|
-
useComposer:
|
|
2326
|
-
type:
|
|
2390
|
+
useComposer: useEditComposer2 ?? useComposer2,
|
|
2391
|
+
type: useEditComposer2 ? "edit" : "new"
|
|
2327
2392
|
}),
|
|
2328
|
-
[
|
|
2393
|
+
[useEditComposer2, useComposer2]
|
|
2329
2394
|
);
|
|
2330
2395
|
};
|
|
2396
|
+
var { useComposer, useComposerStore } = createContextStoreHook(
|
|
2397
|
+
useComposerContext,
|
|
2398
|
+
"useComposer"
|
|
2399
|
+
);
|
|
2331
2400
|
|
|
2332
2401
|
// src/hooks/useAppendMessage.tsx
|
|
2333
2402
|
import { useCallback } from "react";
|
|
2334
|
-
var toAppendMessage = (
|
|
2403
|
+
var toAppendMessage = (useThreadMessages2, message) => {
|
|
2335
2404
|
if (typeof message === "string") {
|
|
2336
2405
|
return {
|
|
2337
|
-
parentId:
|
|
2406
|
+
parentId: useThreadMessages2.getState().at(-1)?.id ?? null,
|
|
2338
2407
|
role: "user",
|
|
2339
2408
|
content: [{ type: "text", text: message }],
|
|
2340
2409
|
attachments: []
|
|
2341
2410
|
};
|
|
2342
2411
|
}
|
|
2343
2412
|
return {
|
|
2344
|
-
parentId: message.parentId ??
|
|
2413
|
+
parentId: message.parentId ?? useThreadMessages2.getState().at(-1)?.id ?? null,
|
|
2345
2414
|
role: message.role ?? "user",
|
|
2346
2415
|
content: message.content,
|
|
2347
2416
|
attachments: message.attachments ?? []
|
|
2348
2417
|
};
|
|
2349
2418
|
};
|
|
2350
2419
|
var useAppendMessage = () => {
|
|
2351
|
-
const
|
|
2420
|
+
const threadMessagesStore = useThreadMessagesStore();
|
|
2421
|
+
const threadActionsStore = useThreadActionsStore();
|
|
2422
|
+
const threadViewportStore = useThreadViewportStore();
|
|
2423
|
+
const threadComposerStore = useThreadComposerStore();
|
|
2352
2424
|
const append = useCallback(
|
|
2353
2425
|
(message) => {
|
|
2354
|
-
const appendMessage = toAppendMessage(
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2426
|
+
const appendMessage = toAppendMessage(threadMessagesStore, message);
|
|
2427
|
+
threadActionsStore.getState().append(appendMessage);
|
|
2428
|
+
threadViewportStore.getState().scrollToBottom();
|
|
2429
|
+
threadComposerStore.getState().focus();
|
|
2358
2430
|
},
|
|
2359
|
-
[
|
|
2431
|
+
[
|
|
2432
|
+
threadMessagesStore,
|
|
2433
|
+
threadActionsStore,
|
|
2434
|
+
threadViewportStore,
|
|
2435
|
+
threadComposerStore
|
|
2436
|
+
]
|
|
2360
2437
|
);
|
|
2361
2438
|
return append;
|
|
2362
2439
|
};
|
|
@@ -2364,23 +2441,20 @@ var useAppendMessage = () => {
|
|
|
2364
2441
|
// src/hooks/useSwitchToNewThread.tsx
|
|
2365
2442
|
import { useCallback as useCallback2 } from "react";
|
|
2366
2443
|
var useSwitchToNewThread = () => {
|
|
2367
|
-
const
|
|
2368
|
-
const
|
|
2444
|
+
const assistantActionsStore = useAssistantActionsStore();
|
|
2445
|
+
const threadComposerStore = useThreadComposerStore();
|
|
2369
2446
|
const switchToNewThread = useCallback2(() => {
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
}, [
|
|
2447
|
+
assistantActionsStore.getState().switchToNewThread();
|
|
2448
|
+
threadComposerStore.getState().focus();
|
|
2449
|
+
}, [assistantActionsStore, threadComposerStore]);
|
|
2373
2450
|
return switchToNewThread;
|
|
2374
2451
|
};
|
|
2375
2452
|
|
|
2376
2453
|
// src/model-config/useAssistantTool.tsx
|
|
2377
2454
|
import { useEffect as useEffect5 } from "react";
|
|
2378
2455
|
var useAssistantTool = (tool) => {
|
|
2379
|
-
const
|
|
2380
|
-
const
|
|
2381
|
-
(s) => s.registerModelConfigProvider
|
|
2382
|
-
);
|
|
2383
|
-
const setToolUI = useToolUIs((s) => s.setToolUI);
|
|
2456
|
+
const assistantActionsStore = useAssistantActionsStore();
|
|
2457
|
+
const toolUIsStore = useToolUIsStore();
|
|
2384
2458
|
useEffect5(() => {
|
|
2385
2459
|
const { toolName, render, ...rest } = tool;
|
|
2386
2460
|
const config = {
|
|
@@ -2388,15 +2462,15 @@ var useAssistantTool = (tool) => {
|
|
|
2388
2462
|
[tool.toolName]: rest
|
|
2389
2463
|
}
|
|
2390
2464
|
};
|
|
2391
|
-
const unsub1 = registerModelConfigProvider({
|
|
2465
|
+
const unsub1 = assistantActionsStore.getState().registerModelConfigProvider({
|
|
2392
2466
|
getModelConfig: () => config
|
|
2393
2467
|
});
|
|
2394
|
-
const unsub2 = render ? setToolUI(toolName, render) : void 0;
|
|
2468
|
+
const unsub2 = render ? toolUIsStore.getState().setToolUI(toolName, render) : void 0;
|
|
2395
2469
|
return () => {
|
|
2396
2470
|
unsub1();
|
|
2397
2471
|
unsub2?.();
|
|
2398
2472
|
};
|
|
2399
|
-
}, [
|
|
2473
|
+
}, [assistantActionsStore, toolUIsStore, tool]);
|
|
2400
2474
|
};
|
|
2401
2475
|
|
|
2402
2476
|
// src/model-config/makeAssistantTool.tsx
|
|
@@ -2412,13 +2486,12 @@ var makeAssistantTool = (tool) => {
|
|
|
2412
2486
|
// src/model-config/useAssistantToolUI.tsx
|
|
2413
2487
|
import { useEffect as useEffect6 } from "react";
|
|
2414
2488
|
var useAssistantToolUI = (tool) => {
|
|
2415
|
-
const
|
|
2416
|
-
const setToolUI = useToolUIs((s) => s.setToolUI);
|
|
2489
|
+
const toolUIsStore = useToolUIsStore();
|
|
2417
2490
|
useEffect6(() => {
|
|
2418
2491
|
if (!tool) return;
|
|
2419
2492
|
const { toolName, render } = tool;
|
|
2420
|
-
return setToolUI(toolName, render);
|
|
2421
|
-
}, [
|
|
2493
|
+
return toolUIsStore.getState().setToolUI(toolName, render);
|
|
2494
|
+
}, [toolUIsStore, tool]);
|
|
2422
2495
|
};
|
|
2423
2496
|
|
|
2424
2497
|
// src/model-config/makeAssistantToolUI.tsx
|
|
@@ -2434,16 +2507,13 @@ var makeAssistantToolUI = (tool) => {
|
|
|
2434
2507
|
// src/model-config/useAssistantInstructions.tsx
|
|
2435
2508
|
import { useEffect as useEffect7 } from "react";
|
|
2436
2509
|
var useAssistantInstructions = (instruction) => {
|
|
2437
|
-
const
|
|
2438
|
-
const registerModelConfigProvider = useModelConfig(
|
|
2439
|
-
(s) => s.registerModelConfigProvider
|
|
2440
|
-
);
|
|
2510
|
+
const actionsStore = useAssistantActionsStore();
|
|
2441
2511
|
useEffect7(() => {
|
|
2442
2512
|
const config = {
|
|
2443
2513
|
system: instruction
|
|
2444
2514
|
};
|
|
2445
|
-
return registerModelConfigProvider({ getModelConfig: () => config });
|
|
2446
|
-
}, [
|
|
2515
|
+
return actionsStore.getState().registerModelConfigProvider({ getModelConfig: () => config });
|
|
2516
|
+
}, [actionsStore, instruction]);
|
|
2447
2517
|
};
|
|
2448
2518
|
|
|
2449
2519
|
// src/primitive-hooks/actionBar/useActionBarCopy.tsx
|
|
@@ -2479,23 +2549,25 @@ var useCombinedStore = (stores, selector) => {
|
|
|
2479
2549
|
var useActionBarCopy = ({
|
|
2480
2550
|
copiedDuration = 3e3
|
|
2481
2551
|
} = {}) => {
|
|
2482
|
-
const
|
|
2552
|
+
const messageStore = useMessageStore();
|
|
2553
|
+
const messageUtilsStore = useMessageUtilsStore();
|
|
2554
|
+
const editComposerStore = useEditComposerStore();
|
|
2483
2555
|
const hasCopyableContent = useCombinedStore(
|
|
2484
|
-
[
|
|
2556
|
+
[messageStore, editComposerStore],
|
|
2485
2557
|
({ message }, c) => {
|
|
2486
2558
|
return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
|
|
2487
2559
|
}
|
|
2488
2560
|
);
|
|
2489
2561
|
const callback = useCallback3(() => {
|
|
2490
|
-
const { message } =
|
|
2491
|
-
const { setIsCopied } =
|
|
2492
|
-
const { isEditing, text: composerValue } =
|
|
2562
|
+
const { message } = messageStore.getState();
|
|
2563
|
+
const { setIsCopied } = messageUtilsStore.getState();
|
|
2564
|
+
const { isEditing, text: composerValue } = editComposerStore.getState();
|
|
2493
2565
|
const valueToCopy = isEditing ? composerValue : getThreadMessageText(message);
|
|
2494
2566
|
navigator.clipboard.writeText(valueToCopy).then(() => {
|
|
2495
2567
|
setIsCopied(true);
|
|
2496
2568
|
setTimeout(() => setIsCopied(false), copiedDuration);
|
|
2497
2569
|
});
|
|
2498
|
-
}, [
|
|
2570
|
+
}, [messageStore, messageUtilsStore, editComposerStore, copiedDuration]);
|
|
2499
2571
|
if (!hasCopyableContent) return null;
|
|
2500
2572
|
return callback;
|
|
2501
2573
|
};
|
|
@@ -2503,12 +2575,12 @@ var useActionBarCopy = ({
|
|
|
2503
2575
|
// src/primitive-hooks/actionBar/useActionBarEdit.tsx
|
|
2504
2576
|
import { useCallback as useCallback4 } from "react";
|
|
2505
2577
|
var useActionBarEdit = () => {
|
|
2506
|
-
const
|
|
2578
|
+
const editComposerStore = useEditComposerStore();
|
|
2507
2579
|
const disabled = useEditComposer((c) => c.isEditing);
|
|
2508
2580
|
const callback = useCallback4(() => {
|
|
2509
|
-
const { edit } =
|
|
2581
|
+
const { edit } = editComposerStore.getState();
|
|
2510
2582
|
edit();
|
|
2511
|
-
}, [
|
|
2583
|
+
}, [editComposerStore]);
|
|
2512
2584
|
if (disabled) return null;
|
|
2513
2585
|
return callback;
|
|
2514
2586
|
};
|
|
@@ -2516,18 +2588,26 @@ var useActionBarEdit = () => {
|
|
|
2516
2588
|
// src/primitive-hooks/actionBar/useActionBarReload.tsx
|
|
2517
2589
|
import { useCallback as useCallback5 } from "react";
|
|
2518
2590
|
var useActionBarReload = () => {
|
|
2519
|
-
const
|
|
2520
|
-
const
|
|
2591
|
+
const messageStore = useMessageStore();
|
|
2592
|
+
const threadStore = useThreadStore();
|
|
2593
|
+
const threadActionsStore = useThreadActionsStore();
|
|
2594
|
+
const threadComposerStore = useThreadComposerStore();
|
|
2595
|
+
const threadViewportStore = useThreadViewportStore();
|
|
2521
2596
|
const disabled = useCombinedStore(
|
|
2522
|
-
[
|
|
2597
|
+
[threadStore, messageStore],
|
|
2523
2598
|
(t, m) => t.isRunning || t.isDisabled || m.message.role !== "assistant"
|
|
2524
2599
|
);
|
|
2525
2600
|
const callback = useCallback5(() => {
|
|
2526
|
-
const { parentId } =
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
}, [
|
|
2601
|
+
const { parentId } = messageStore.getState();
|
|
2602
|
+
threadActionsStore.getState().startRun(parentId);
|
|
2603
|
+
threadViewportStore.getState().scrollToBottom();
|
|
2604
|
+
threadComposerStore.getState().focus();
|
|
2605
|
+
}, [
|
|
2606
|
+
threadActionsStore,
|
|
2607
|
+
threadComposerStore,
|
|
2608
|
+
threadViewportStore,
|
|
2609
|
+
messageStore
|
|
2610
|
+
]);
|
|
2531
2611
|
if (disabled) return null;
|
|
2532
2612
|
return callback;
|
|
2533
2613
|
};
|
|
@@ -2535,19 +2615,21 @@ var useActionBarReload = () => {
|
|
|
2535
2615
|
// src/primitive-hooks/actionBar/useActionBarSpeak.tsx
|
|
2536
2616
|
import { useCallback as useCallback6 } from "react";
|
|
2537
2617
|
var useActionBarSpeak = () => {
|
|
2538
|
-
const
|
|
2539
|
-
const
|
|
2618
|
+
const messageStore = useMessageStore();
|
|
2619
|
+
const editComposerStore = useEditComposerStore();
|
|
2620
|
+
const threadActionsStore = useThreadActionsStore();
|
|
2621
|
+
const messageUtilsStore = useMessageUtilsStore();
|
|
2540
2622
|
const hasSpeakableContent = useCombinedStore(
|
|
2541
|
-
[
|
|
2623
|
+
[messageStore, editComposerStore],
|
|
2542
2624
|
({ message }, c) => {
|
|
2543
2625
|
return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
|
|
2544
2626
|
}
|
|
2545
2627
|
);
|
|
2546
2628
|
const callback = useCallback6(async () => {
|
|
2547
|
-
const { message } =
|
|
2548
|
-
const utt =
|
|
2549
|
-
|
|
2550
|
-
}, [
|
|
2629
|
+
const { message } = messageStore.getState();
|
|
2630
|
+
const utt = threadActionsStore.getState().speak(message.id);
|
|
2631
|
+
messageUtilsStore.getState().addUtterance(utt);
|
|
2632
|
+
}, [threadActionsStore, messageStore, messageUtilsStore]);
|
|
2551
2633
|
if (!hasSpeakableContent) return null;
|
|
2552
2634
|
return callback;
|
|
2553
2635
|
};
|
|
@@ -2555,18 +2637,17 @@ var useActionBarSpeak = () => {
|
|
|
2555
2637
|
// src/primitive-hooks/actionBar/useActionBarStopSpeaking.tsx
|
|
2556
2638
|
import { useCallback as useCallback7 } from "react";
|
|
2557
2639
|
var useActionBarStopSpeaking = () => {
|
|
2558
|
-
const
|
|
2640
|
+
const messageUtilsStore = useMessageUtilsStore();
|
|
2559
2641
|
const isSpeaking = useMessageUtils((u) => u.isSpeaking);
|
|
2560
2642
|
const callback = useCallback7(async () => {
|
|
2561
|
-
|
|
2562
|
-
}, [
|
|
2643
|
+
messageUtilsStore.getState().stopSpeaking();
|
|
2644
|
+
}, [messageUtilsStore]);
|
|
2563
2645
|
if (!isSpeaking) return null;
|
|
2564
2646
|
return callback;
|
|
2565
2647
|
};
|
|
2566
2648
|
|
|
2567
2649
|
// src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
|
|
2568
2650
|
var useBranchPickerCount = () => {
|
|
2569
|
-
const { useMessage } = useMessageContext();
|
|
2570
2651
|
const branchCount = useMessage((s) => s.branches.length);
|
|
2571
2652
|
return branchCount;
|
|
2572
2653
|
};
|
|
@@ -2574,23 +2655,23 @@ var useBranchPickerCount = () => {
|
|
|
2574
2655
|
// src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
|
|
2575
2656
|
import { useCallback as useCallback8 } from "react";
|
|
2576
2657
|
var useBranchPickerNext = () => {
|
|
2577
|
-
const
|
|
2578
|
-
const
|
|
2658
|
+
const messageStore = useMessageStore();
|
|
2659
|
+
const editComposerStore = useEditComposerStore();
|
|
2660
|
+
const threadActionsStore = useThreadActionsStore();
|
|
2579
2661
|
const disabled = useCombinedStore(
|
|
2580
|
-
[
|
|
2662
|
+
[messageStore, editComposerStore],
|
|
2581
2663
|
(m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
|
|
2582
2664
|
);
|
|
2583
2665
|
const callback = useCallback8(() => {
|
|
2584
|
-
const { message, branches } =
|
|
2585
|
-
|
|
2586
|
-
}, [
|
|
2666
|
+
const { message, branches } = messageStore.getState();
|
|
2667
|
+
threadActionsStore.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
|
|
2668
|
+
}, [threadActionsStore, messageStore]);
|
|
2587
2669
|
if (disabled) return null;
|
|
2588
2670
|
return callback;
|
|
2589
2671
|
};
|
|
2590
2672
|
|
|
2591
2673
|
// src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
|
|
2592
2674
|
var useBranchPickerNumber = () => {
|
|
2593
|
-
const { useMessage } = useMessageContext();
|
|
2594
2675
|
const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
|
|
2595
2676
|
return branchIdx + 1;
|
|
2596
2677
|
};
|
|
@@ -2598,16 +2679,17 @@ var useBranchPickerNumber = () => {
|
|
|
2598
2679
|
// src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
|
|
2599
2680
|
import { useCallback as useCallback9 } from "react";
|
|
2600
2681
|
var useBranchPickerPrevious = () => {
|
|
2601
|
-
const
|
|
2602
|
-
const
|
|
2682
|
+
const messageStore = useMessageStore();
|
|
2683
|
+
const editComposerStore = useEditComposerStore();
|
|
2684
|
+
const threadActionsStore = useThreadActionsStore();
|
|
2603
2685
|
const disabled = useCombinedStore(
|
|
2604
|
-
[
|
|
2686
|
+
[messageStore, editComposerStore],
|
|
2605
2687
|
(m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
|
|
2606
2688
|
);
|
|
2607
2689
|
const callback = useCallback9(() => {
|
|
2608
|
-
const { message, branches } =
|
|
2609
|
-
|
|
2610
|
-
}, [
|
|
2690
|
+
const { message, branches } = messageStore.getState();
|
|
2691
|
+
threadActionsStore.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
|
|
2692
|
+
}, [threadActionsStore, messageStore]);
|
|
2611
2693
|
if (disabled) return null;
|
|
2612
2694
|
return callback;
|
|
2613
2695
|
};
|
|
@@ -2615,19 +2697,18 @@ var useBranchPickerPrevious = () => {
|
|
|
2615
2697
|
// src/primitive-hooks/composer/useComposerCancel.tsx
|
|
2616
2698
|
import { useCallback as useCallback10 } from "react";
|
|
2617
2699
|
var useComposerCancel = () => {
|
|
2618
|
-
const
|
|
2700
|
+
const composerStore = useComposerStore();
|
|
2619
2701
|
const disabled = useComposer((c) => !c.canCancel);
|
|
2620
2702
|
const callback = useCallback10(() => {
|
|
2621
|
-
const { cancel } =
|
|
2703
|
+
const { cancel } = composerStore.getState();
|
|
2622
2704
|
cancel();
|
|
2623
|
-
}, [
|
|
2705
|
+
}, [composerStore]);
|
|
2624
2706
|
if (disabled) return null;
|
|
2625
2707
|
return callback;
|
|
2626
2708
|
};
|
|
2627
2709
|
|
|
2628
2710
|
// src/primitive-hooks/composer/useComposerIf.tsx
|
|
2629
2711
|
var useComposerIf = (props) => {
|
|
2630
|
-
const { useComposer } = useComposerContext();
|
|
2631
2712
|
return useComposer((composer) => {
|
|
2632
2713
|
if (props.editing === true && !composer.isEditing) return false;
|
|
2633
2714
|
if (props.editing === false && composer.isEditing) return false;
|
|
@@ -2638,23 +2719,21 @@ var useComposerIf = (props) => {
|
|
|
2638
2719
|
// src/primitive-hooks/composer/useComposerSend.tsx
|
|
2639
2720
|
import { useCallback as useCallback11 } from "react";
|
|
2640
2721
|
var useComposerSend = () => {
|
|
2641
|
-
const
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
} = useThreadContext();
|
|
2646
|
-
const { useComposer } = useComposerContext();
|
|
2722
|
+
const threadStore = useThreadStore();
|
|
2723
|
+
const threadViewportStore = useThreadViewportStore();
|
|
2724
|
+
const composerStore = useComposerStore();
|
|
2725
|
+
const threadComposerStore = useThreadComposerStore();
|
|
2647
2726
|
const disabled = useCombinedStore(
|
|
2648
|
-
[
|
|
2727
|
+
[threadStore, composerStore],
|
|
2649
2728
|
(t, c) => t.isRunning || !c.isEditing || c.isEmpty
|
|
2650
2729
|
);
|
|
2651
2730
|
const callback = useCallback11(() => {
|
|
2652
|
-
const composerState =
|
|
2731
|
+
const composerState = composerStore.getState();
|
|
2653
2732
|
if (!composerState.isEditing) return;
|
|
2654
2733
|
composerState.send();
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
}, [
|
|
2734
|
+
threadViewportStore.getState().scrollToBottom();
|
|
2735
|
+
threadComposerStore.getState().focus();
|
|
2736
|
+
}, [threadComposerStore, composerStore, threadViewportStore]);
|
|
2658
2737
|
if (disabled) return null;
|
|
2659
2738
|
return callback;
|
|
2660
2739
|
};
|
|
@@ -2662,11 +2741,12 @@ var useComposerSend = () => {
|
|
|
2662
2741
|
// src/primitive-hooks/composer/useComposerAddAttachment.tsx
|
|
2663
2742
|
import { useCallback as useCallback12 } from "react";
|
|
2664
2743
|
var useComposerAddAttachment = () => {
|
|
2665
|
-
const { useComposer, useThreadRuntime } = useThreadContext();
|
|
2666
2744
|
const disabled = useComposer((c) => !c.isEditing);
|
|
2745
|
+
const threadComposerStore = useThreadComposerStore();
|
|
2746
|
+
const threadRuntimeStore = useThreadComposerStore();
|
|
2667
2747
|
const callback = useCallback12(() => {
|
|
2668
|
-
const { addAttachment } =
|
|
2669
|
-
const { attachmentAccept } =
|
|
2748
|
+
const { addAttachment } = threadComposerStore.getState();
|
|
2749
|
+
const { attachmentAccept } = threadRuntimeStore.getState();
|
|
2670
2750
|
const input = document.createElement("input");
|
|
2671
2751
|
input.type = "file";
|
|
2672
2752
|
if (attachmentAccept !== "*") {
|
|
@@ -2678,14 +2758,13 @@ var useComposerAddAttachment = () => {
|
|
|
2678
2758
|
addAttachment(file);
|
|
2679
2759
|
};
|
|
2680
2760
|
input.click();
|
|
2681
|
-
}, [
|
|
2761
|
+
}, [threadComposerStore, threadRuntimeStore]);
|
|
2682
2762
|
if (disabled) return null;
|
|
2683
2763
|
return callback;
|
|
2684
2764
|
};
|
|
2685
2765
|
|
|
2686
2766
|
// src/primitive-hooks/contentPart/useContentPartDisplay.tsx
|
|
2687
2767
|
var useContentPartDisplay = () => {
|
|
2688
|
-
const { useContentPart } = useContentPartContext();
|
|
2689
2768
|
const display = useContentPart((c) => {
|
|
2690
2769
|
if (c.part.type !== "ui")
|
|
2691
2770
|
throw new Error(
|
|
@@ -2698,7 +2777,6 @@ var useContentPartDisplay = () => {
|
|
|
2698
2777
|
|
|
2699
2778
|
// src/primitive-hooks/contentPart/useContentPartImage.tsx
|
|
2700
2779
|
var useContentPartImage = () => {
|
|
2701
|
-
const { useContentPart } = useContentPartContext();
|
|
2702
2780
|
const image = useContentPart((c) => {
|
|
2703
2781
|
if (c.part.type !== "image")
|
|
2704
2782
|
throw new Error(
|
|
@@ -2711,7 +2789,6 @@ var useContentPartImage = () => {
|
|
|
2711
2789
|
|
|
2712
2790
|
// src/primitive-hooks/contentPart/useContentPartText.tsx
|
|
2713
2791
|
var useContentPartText = () => {
|
|
2714
|
-
const { useContentPart } = useContentPartContext();
|
|
2715
2792
|
const text = useContentPart((c) => {
|
|
2716
2793
|
if (c.part.type !== "text")
|
|
2717
2794
|
throw new Error(
|
|
@@ -2724,9 +2801,10 @@ var useContentPartText = () => {
|
|
|
2724
2801
|
|
|
2725
2802
|
// src/primitive-hooks/message/useMessageIf.tsx
|
|
2726
2803
|
var useMessageIf = (props) => {
|
|
2727
|
-
const
|
|
2804
|
+
const messageStore = useMessageStore();
|
|
2805
|
+
const messageUtilsStore = useMessageUtilsStore();
|
|
2728
2806
|
return useCombinedStore(
|
|
2729
|
-
[
|
|
2807
|
+
[messageStore, messageUtilsStore],
|
|
2730
2808
|
({ message, branches, isLast }, { isCopied, isHovering, isSpeaking }) => {
|
|
2731
2809
|
if (props.hasBranches === true && branches.length < 2) return false;
|
|
2732
2810
|
if (props.user && message.role !== "user") return false;
|
|
@@ -2748,9 +2826,10 @@ var useMessageIf = (props) => {
|
|
|
2748
2826
|
|
|
2749
2827
|
// src/primitive-hooks/thread/useThreadIf.tsx
|
|
2750
2828
|
var useThreadIf = (props) => {
|
|
2751
|
-
const
|
|
2829
|
+
const threadStore = useThreadStore();
|
|
2830
|
+
const threadMessagesStore = useThreadMessagesStore();
|
|
2752
2831
|
return useCombinedStore(
|
|
2753
|
-
[
|
|
2832
|
+
[threadStore, threadMessagesStore],
|
|
2754
2833
|
(thread, messages) => {
|
|
2755
2834
|
if (props.empty === true && messages.length !== 0) return false;
|
|
2756
2835
|
if (props.empty === false && messages.length === 0) return false;
|
|
@@ -2771,12 +2850,13 @@ var useThreadEmpty = () => {
|
|
|
2771
2850
|
// src/primitive-hooks/thread/useThreadScrollToBottom.tsx
|
|
2772
2851
|
import { useCallback as useCallback13 } from "react";
|
|
2773
2852
|
var useThreadScrollToBottom = () => {
|
|
2774
|
-
const
|
|
2775
|
-
const
|
|
2853
|
+
const isAtBottom = useThreadViewport((s) => s.isAtBottom);
|
|
2854
|
+
const threadViewportStore = useThreadViewportStore();
|
|
2855
|
+
const threadComposerStore = useThreadComposerStore();
|
|
2776
2856
|
const handleScrollToBottom = useCallback13(() => {
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
}, [
|
|
2857
|
+
threadViewportStore.getState().scrollToBottom();
|
|
2858
|
+
threadComposerStore.getState().focus();
|
|
2859
|
+
}, [threadViewportStore, threadComposerStore]);
|
|
2780
2860
|
if (isAtBottom) return null;
|
|
2781
2861
|
return handleScrollToBottom;
|
|
2782
2862
|
};
|
|
@@ -2787,19 +2867,20 @@ var useThreadSuggestion = ({
|
|
|
2787
2867
|
prompt,
|
|
2788
2868
|
autoSend
|
|
2789
2869
|
}) => {
|
|
2790
|
-
const
|
|
2870
|
+
const threadStore = useThreadStore();
|
|
2871
|
+
const composerStore = useThreadComposerStore();
|
|
2791
2872
|
const append = useAppendMessage();
|
|
2792
2873
|
const disabled = useThread((t) => t.isDisabled);
|
|
2793
2874
|
const callback = useCallback14(() => {
|
|
2794
|
-
const thread =
|
|
2795
|
-
const composer =
|
|
2875
|
+
const thread = threadStore.getState();
|
|
2876
|
+
const composer = composerStore.getState();
|
|
2796
2877
|
if (autoSend && !thread.isRunning) {
|
|
2797
2878
|
append(prompt);
|
|
2798
2879
|
composer.setText("");
|
|
2799
2880
|
} else {
|
|
2800
2881
|
composer.setText(prompt);
|
|
2801
2882
|
}
|
|
2802
|
-
}, [
|
|
2883
|
+
}, [threadStore, composerStore, autoSend, append, prompt]);
|
|
2803
2884
|
if (disabled) return null;
|
|
2804
2885
|
return callback;
|
|
2805
2886
|
};
|
|
@@ -2825,10 +2906,11 @@ var useActionBarFloatStatus = ({
|
|
|
2825
2906
|
autohide,
|
|
2826
2907
|
autohideFloat
|
|
2827
2908
|
}) => {
|
|
2828
|
-
const
|
|
2829
|
-
const
|
|
2909
|
+
const threadStore = useThreadStore();
|
|
2910
|
+
const messageStore = useMessageStore();
|
|
2911
|
+
const messageUtilsStore = useMessageUtilsStore();
|
|
2830
2912
|
return useCombinedStore(
|
|
2831
|
-
[
|
|
2913
|
+
[threadStore, messageStore, messageUtilsStore],
|
|
2832
2914
|
(t, m, mu) => {
|
|
2833
2915
|
if (hideWhenRunning && t.isRunning) return "hidden" /* Hidden */;
|
|
2834
2916
|
const autohideEnabled = autohide === "always" || autohide === "not-last" && !m.isLast;
|
|
@@ -2947,6 +3029,7 @@ var ActionBarPrimitiveStopSpeaking = forwardRef7((props, ref) => {
|
|
|
2947
3029
|
}
|
|
2948
3030
|
);
|
|
2949
3031
|
});
|
|
3032
|
+
ActionBarPrimitiveStopSpeaking.displayName = "ActionBarPrimitive.StopSpeaking";
|
|
2950
3033
|
|
|
2951
3034
|
// src/primitives/assistantModal/index.ts
|
|
2952
3035
|
var assistantModal_exports = {};
|
|
@@ -2967,12 +3050,12 @@ import { useCallbackRef as useCallbackRef2 } from "@radix-ui/react-use-callback-
|
|
|
2967
3050
|
import { useEffect as useEffect8 } from "react";
|
|
2968
3051
|
var useOnComposerFocus = (callback) => {
|
|
2969
3052
|
const callbackRef = useCallbackRef2(callback);
|
|
2970
|
-
const
|
|
3053
|
+
const threadComposerStore = useThreadComposerStore();
|
|
2971
3054
|
useEffect8(() => {
|
|
2972
|
-
return
|
|
3055
|
+
return threadComposerStore.getState().onFocus(() => {
|
|
2973
3056
|
callbackRef();
|
|
2974
3057
|
});
|
|
2975
|
-
}, [
|
|
3058
|
+
}, [threadComposerStore, callbackRef]);
|
|
2976
3059
|
};
|
|
2977
3060
|
|
|
2978
3061
|
// src/primitives/assistantModal/scope.tsx
|
|
@@ -3154,10 +3237,10 @@ var useManagedRef = (callback) => {
|
|
|
3154
3237
|
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
3155
3238
|
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
3156
3239
|
var useIsHoveringRef = () => {
|
|
3157
|
-
const
|
|
3240
|
+
const messageUtilsStore = useMessageUtilsStore();
|
|
3158
3241
|
const callbackRef = useCallback16(
|
|
3159
3242
|
(el) => {
|
|
3160
|
-
const setIsHovering =
|
|
3243
|
+
const setIsHovering = messageUtilsStore.getState().setIsHovering;
|
|
3161
3244
|
const handleMouseEnter = () => {
|
|
3162
3245
|
setIsHovering(true);
|
|
3163
3246
|
};
|
|
@@ -3172,14 +3255,14 @@ var useIsHoveringRef = () => {
|
|
|
3172
3255
|
setIsHovering(false);
|
|
3173
3256
|
};
|
|
3174
3257
|
},
|
|
3175
|
-
[
|
|
3258
|
+
[messageUtilsStore]
|
|
3176
3259
|
);
|
|
3177
3260
|
return useManagedRef(callbackRef);
|
|
3178
3261
|
};
|
|
3179
|
-
var MessagePrimitiveRoot = forwardRef11((
|
|
3262
|
+
var MessagePrimitiveRoot = forwardRef11((props, forwardRef30) => {
|
|
3180
3263
|
const isHoveringRef = useIsHoveringRef();
|
|
3181
3264
|
const ref = useComposedRefs(forwardRef30, isHoveringRef);
|
|
3182
|
-
return /* @__PURE__ */ jsx19(Primitive5.div, { ...
|
|
3265
|
+
return /* @__PURE__ */ jsx19(Primitive5.div, { ...props, ref });
|
|
3183
3266
|
});
|
|
3184
3267
|
MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
|
|
3185
3268
|
|
|
@@ -3198,7 +3281,7 @@ import { memo as memo2 } from "react";
|
|
|
3198
3281
|
|
|
3199
3282
|
// src/context/providers/ContentPartProvider.tsx
|
|
3200
3283
|
import { useEffect as useEffect9, useState as useState11 } from "react";
|
|
3201
|
-
import { create as
|
|
3284
|
+
import { create as create12 } from "zustand";
|
|
3202
3285
|
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
3203
3286
|
var COMPLETE_STATUS = {
|
|
3204
3287
|
type: "complete"
|
|
@@ -3219,7 +3302,7 @@ var toContentPartStatus = (message, partIndex, part) => {
|
|
|
3219
3302
|
return message.status;
|
|
3220
3303
|
};
|
|
3221
3304
|
var EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });
|
|
3222
|
-
var getContentPartState = ({ message },
|
|
3305
|
+
var getContentPartState = ({ message }, useContentPart2, partIndex) => {
|
|
3223
3306
|
let part = message.content[partIndex];
|
|
3224
3307
|
if (!part) {
|
|
3225
3308
|
if (message.content.length === 0 && partIndex === 0) {
|
|
@@ -3231,18 +3314,18 @@ var getContentPartState = ({ message }, useContentPart, partIndex) => {
|
|
|
3231
3314
|
part = EMPTY_CONTENT;
|
|
3232
3315
|
}
|
|
3233
3316
|
const status = toContentPartStatus(message, partIndex, part);
|
|
3234
|
-
const currentState =
|
|
3317
|
+
const currentState = useContentPart2?.getState();
|
|
3235
3318
|
if (currentState && currentState.part === part && currentState.status === status)
|
|
3236
3319
|
return null;
|
|
3237
3320
|
return Object.freeze({ part, status });
|
|
3238
3321
|
};
|
|
3239
3322
|
var useContentPartContext2 = (partIndex) => {
|
|
3240
|
-
const
|
|
3323
|
+
const messageStore = useMessageStore();
|
|
3241
3324
|
const [context] = useState11(() => {
|
|
3242
|
-
const
|
|
3243
|
-
() => getContentPartState(
|
|
3325
|
+
const useContentPart2 = create12(
|
|
3326
|
+
() => getContentPartState(messageStore.getState(), void 0, partIndex)
|
|
3244
3327
|
);
|
|
3245
|
-
return { useContentPart };
|
|
3328
|
+
return { useContentPart: useContentPart2 };
|
|
3246
3329
|
});
|
|
3247
3330
|
useEffect9(() => {
|
|
3248
3331
|
const syncContentPart = (message) => {
|
|
@@ -3254,9 +3337,9 @@ var useContentPartContext2 = (partIndex) => {
|
|
|
3254
3337
|
if (!newState) return;
|
|
3255
3338
|
writableStore(context.useContentPart).setState(newState, true);
|
|
3256
3339
|
};
|
|
3257
|
-
syncContentPart(
|
|
3258
|
-
return
|
|
3259
|
-
}, [context,
|
|
3340
|
+
syncContentPart(messageStore.getState());
|
|
3341
|
+
return messageStore.subscribe(syncContentPart);
|
|
3342
|
+
}, [context, messageStore, partIndex]);
|
|
3260
3343
|
return context;
|
|
3261
3344
|
};
|
|
3262
3345
|
var ContentPartProvider = ({
|
|
@@ -3304,7 +3387,6 @@ ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
|
|
|
3304
3387
|
|
|
3305
3388
|
// src/primitives/contentPart/ContentPartInProgress.tsx
|
|
3306
3389
|
var ContentPartPrimitiveInProgress = ({ children }) => {
|
|
3307
|
-
const { useContentPart } = useContentPartContext();
|
|
3308
3390
|
const isInProgress = useContentPart((c) => c.status.type === "running");
|
|
3309
3391
|
return isInProgress ? children : null;
|
|
3310
3392
|
};
|
|
@@ -3316,7 +3398,6 @@ var ToolUIDisplay = ({
|
|
|
3316
3398
|
UI,
|
|
3317
3399
|
...props
|
|
3318
3400
|
}) => {
|
|
3319
|
-
const { useToolUIs } = useAssistantContext();
|
|
3320
3401
|
const Render = useToolUIs((s) => s.getToolUI(props.part.toolName)) ?? UI;
|
|
3321
3402
|
if (!Render) return null;
|
|
3322
3403
|
return /* @__PURE__ */ jsx23(Render, { ...props });
|
|
@@ -3338,10 +3419,8 @@ var MessageContentPartComponent = ({
|
|
|
3338
3419
|
tools: { by_name = {}, Fallback: Fallback2 = void 0 } = {}
|
|
3339
3420
|
} = {}
|
|
3340
3421
|
}) => {
|
|
3341
|
-
const
|
|
3342
|
-
const
|
|
3343
|
-
const addToolResult = useThreadActions((t) => t.addToolResult);
|
|
3344
|
-
const { useContentPart } = useContentPartContext();
|
|
3422
|
+
const messageStore = useMessageStore();
|
|
3423
|
+
const threadActionsStore = useThreadActionsStore();
|
|
3345
3424
|
const { part, status } = useContentPart();
|
|
3346
3425
|
const type = part.type;
|
|
3347
3426
|
switch (type) {
|
|
@@ -3362,8 +3441,8 @@ var MessageContentPartComponent = ({
|
|
|
3362
3441
|
return /* @__PURE__ */ jsx23(UI, { part, status });
|
|
3363
3442
|
case "tool-call": {
|
|
3364
3443
|
const Tool = by_name[part.toolName] || Fallback2;
|
|
3365
|
-
const addResult = (result) => addToolResult({
|
|
3366
|
-
messageId:
|
|
3444
|
+
const addResult = (result) => threadActionsStore.getState().addToolResult({
|
|
3445
|
+
messageId: messageStore.getState().message.id,
|
|
3367
3446
|
toolName: part.toolName,
|
|
3368
3447
|
toolCallId: part.toolCallId,
|
|
3369
3448
|
result
|
|
@@ -3396,7 +3475,6 @@ var MessageContentPart = memo2(
|
|
|
3396
3475
|
var MessagePrimitiveContent = ({
|
|
3397
3476
|
components
|
|
3398
3477
|
}) => {
|
|
3399
|
-
const { useMessage } = useMessageContext();
|
|
3400
3478
|
const contentLength = useMessage((s) => s.message.content.length) || 1;
|
|
3401
3479
|
return Array.from({ length: contentLength }, (_, index) => /* @__PURE__ */ jsx23(MessageContentPart, { partIndex: index, components }, index));
|
|
3402
3480
|
};
|
|
@@ -3412,48 +3490,70 @@ MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
|
|
|
3412
3490
|
import { memo as memo3 } from "react";
|
|
3413
3491
|
|
|
3414
3492
|
// src/context/react/AttachmentContext.ts
|
|
3415
|
-
import { createContext as createContext6, useContext as
|
|
3493
|
+
import { createContext as createContext6, useContext as useContext3 } from "react";
|
|
3416
3494
|
var AttachmentContext = createContext6(
|
|
3417
3495
|
null
|
|
3418
3496
|
);
|
|
3419
3497
|
function useAttachmentContext(options) {
|
|
3420
|
-
const context =
|
|
3421
|
-
if (options?.
|
|
3498
|
+
const context = useContext3(AttachmentContext);
|
|
3499
|
+
if (!options?.optional && !context)
|
|
3422
3500
|
throw new Error(
|
|
3423
|
-
"This component must be used within a ComposerPrimitive.Attachments component."
|
|
3501
|
+
"This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
|
|
3424
3502
|
);
|
|
3425
|
-
|
|
3503
|
+
return context;
|
|
3504
|
+
}
|
|
3505
|
+
function useComposerAttachmentContext(options) {
|
|
3506
|
+
const context = useAttachmentContext(options);
|
|
3507
|
+
if (!context) return null;
|
|
3508
|
+
if (context.type !== "composer")
|
|
3426
3509
|
throw new Error(
|
|
3427
|
-
"This component must be used within a
|
|
3510
|
+
"This component must be used within a ComposerPrimitive.Attachments component."
|
|
3428
3511
|
);
|
|
3429
|
-
|
|
3512
|
+
return context;
|
|
3513
|
+
}
|
|
3514
|
+
function useMessageAttachmentContext(options) {
|
|
3515
|
+
const context = useAttachmentContext(options);
|
|
3516
|
+
if (!context) return null;
|
|
3517
|
+
if (context.type !== "message")
|
|
3430
3518
|
throw new Error(
|
|
3431
|
-
"This component must be used within a
|
|
3519
|
+
"This component must be used within a MessagePrimitive.Attachments component."
|
|
3432
3520
|
);
|
|
3433
3521
|
return context;
|
|
3434
3522
|
}
|
|
3523
|
+
var { useAttachment, useAttachmentStore } = createContextStoreHook(
|
|
3524
|
+
useAttachmentContext,
|
|
3525
|
+
"useAttachment"
|
|
3526
|
+
);
|
|
3527
|
+
var {
|
|
3528
|
+
useAttachment: useComposerAttachment,
|
|
3529
|
+
useAttachmentStore: useComposerAttachmentStore
|
|
3530
|
+
} = createContextStoreHook(useComposerAttachmentContext, "useAttachment");
|
|
3531
|
+
var {
|
|
3532
|
+
useAttachment: useMessageAttachment,
|
|
3533
|
+
useAttachmentStore: useMessageAttachmentStore
|
|
3534
|
+
} = createContextStoreHook(useMessageAttachmentContext, "useAttachment");
|
|
3435
3535
|
|
|
3436
3536
|
// src/context/providers/MessageAttachmentProvider.tsx
|
|
3437
3537
|
import { useEffect as useEffect10, useState as useState12 } from "react";
|
|
3438
|
-
import { create as
|
|
3538
|
+
import { create as create13 } from "zustand";
|
|
3439
3539
|
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
3440
|
-
var getAttachment = ({ message },
|
|
3540
|
+
var getAttachment = ({ message }, useAttachment2, partIndex) => {
|
|
3441
3541
|
if (message.role !== "user") return null;
|
|
3442
3542
|
const attachments = message.attachments;
|
|
3443
|
-
|
|
3543
|
+
const attachment = attachments[partIndex];
|
|
3444
3544
|
if (!attachment) return null;
|
|
3445
|
-
const currentState =
|
|
3545
|
+
const currentState = useAttachment2?.getState();
|
|
3446
3546
|
if (currentState && currentState.attachment === attachment) return null;
|
|
3447
3547
|
return Object.freeze({ attachment });
|
|
3448
3548
|
};
|
|
3449
|
-
var
|
|
3450
|
-
const
|
|
3549
|
+
var useMessageAttachmentContext2 = (partIndex) => {
|
|
3550
|
+
const messageStore = useMessageStore();
|
|
3451
3551
|
const [context] = useState12(
|
|
3452
3552
|
() => {
|
|
3453
|
-
const
|
|
3454
|
-
() => getAttachment(
|
|
3553
|
+
const useAttachment2 = create13(
|
|
3554
|
+
() => getAttachment(messageStore.getState(), void 0, partIndex)
|
|
3455
3555
|
);
|
|
3456
|
-
return { type: "message", useAttachment };
|
|
3556
|
+
return { type: "message", useAttachment: useAttachment2 };
|
|
3457
3557
|
}
|
|
3458
3558
|
);
|
|
3459
3559
|
useEffect10(() => {
|
|
@@ -3466,16 +3566,16 @@ var useMessageAttachmentContext = (partIndex) => {
|
|
|
3466
3566
|
if (!newState) return;
|
|
3467
3567
|
writableStore(context.useAttachment).setState(newState, true);
|
|
3468
3568
|
};
|
|
3469
|
-
syncAttachment(
|
|
3470
|
-
return
|
|
3471
|
-
}, [context,
|
|
3569
|
+
syncAttachment(messageStore.getState());
|
|
3570
|
+
return messageStore.subscribe(syncAttachment);
|
|
3571
|
+
}, [context, messageStore, partIndex]);
|
|
3472
3572
|
return context;
|
|
3473
3573
|
};
|
|
3474
3574
|
var MessageAttachmentProvider = ({
|
|
3475
3575
|
attachmentIndex: partIndex,
|
|
3476
3576
|
children
|
|
3477
3577
|
}) => {
|
|
3478
|
-
const context =
|
|
3578
|
+
const context = useMessageAttachmentContext2(partIndex);
|
|
3479
3579
|
return /* @__PURE__ */ jsx24(AttachmentContext.Provider, { value: context, children });
|
|
3480
3580
|
};
|
|
3481
3581
|
|
|
@@ -3496,8 +3596,7 @@ var getComponent = (components, attachment) => {
|
|
|
3496
3596
|
}
|
|
3497
3597
|
};
|
|
3498
3598
|
var AttachmentComponent = ({ components }) => {
|
|
3499
|
-
const
|
|
3500
|
-
const Component = useAttachment(
|
|
3599
|
+
const Component = useMessageAttachment(
|
|
3501
3600
|
(a) => getComponent(components, a.attachment)
|
|
3502
3601
|
);
|
|
3503
3602
|
if (!Component) return null;
|
|
@@ -3511,7 +3610,6 @@ var MessageAttachment = memo3(
|
|
|
3511
3610
|
(prev, next) => prev.attachmentIndex === next.attachmentIndex && prev.components?.Image === next.components?.Image && prev.components?.Document === next.components?.Document && prev.components?.File === next.components?.File && prev.components?.Attachment === next.components?.Attachment
|
|
3512
3611
|
);
|
|
3513
3612
|
var MessagePrimitiveAttachments = ({ components }) => {
|
|
3514
|
-
const { useMessage } = useMessageContext();
|
|
3515
3613
|
const attachmentsCount = useMessage(({ message }) => {
|
|
3516
3614
|
if (message.role !== "user") return 0;
|
|
3517
3615
|
return message.attachments.length;
|
|
@@ -3593,8 +3691,8 @@ var ComposerPrimitiveInput = forwardRef16(
|
|
|
3593
3691
|
onKeyDown,
|
|
3594
3692
|
...rest
|
|
3595
3693
|
}, forwardedRef) => {
|
|
3596
|
-
const
|
|
3597
|
-
const
|
|
3694
|
+
const threadStore = useThreadStore();
|
|
3695
|
+
const composerStore = useComposerStore();
|
|
3598
3696
|
const value = useComposer((c) => {
|
|
3599
3697
|
if (!c.isEditing) return "";
|
|
3600
3698
|
return c.text;
|
|
@@ -3604,7 +3702,7 @@ var ComposerPrimitiveInput = forwardRef16(
|
|
|
3604
3702
|
const textareaRef = useRef4(null);
|
|
3605
3703
|
const ref = useComposedRefs2(forwardedRef, textareaRef);
|
|
3606
3704
|
useEscapeKeydown2((e) => {
|
|
3607
|
-
const composer =
|
|
3705
|
+
const composer = composerStore.getState();
|
|
3608
3706
|
if (composer.canCancel) {
|
|
3609
3707
|
composer.cancel();
|
|
3610
3708
|
e.preventDefault();
|
|
@@ -3614,7 +3712,7 @@ var ComposerPrimitiveInput = forwardRef16(
|
|
|
3614
3712
|
if (isDisabled) return;
|
|
3615
3713
|
if (e.nativeEvent.isComposing) return;
|
|
3616
3714
|
if (e.key === "Enter" && e.shiftKey === false) {
|
|
3617
|
-
const { isRunning } =
|
|
3715
|
+
const { isRunning } = threadStore.getState();
|
|
3618
3716
|
if (!isRunning) {
|
|
3619
3717
|
e.preventDefault();
|
|
3620
3718
|
textareaRef.current?.closest("form")?.requestSubmit();
|
|
@@ -3633,7 +3731,7 @@ var ComposerPrimitiveInput = forwardRef16(
|
|
|
3633
3731
|
}, [autoFocusEnabled]);
|
|
3634
3732
|
useEffect11(() => focus(), [focus]);
|
|
3635
3733
|
useOnComposerFocus(() => {
|
|
3636
|
-
if (type === "
|
|
3734
|
+
if (composerStore.getState().type === "thread") {
|
|
3637
3735
|
focus();
|
|
3638
3736
|
}
|
|
3639
3737
|
});
|
|
@@ -3646,7 +3744,7 @@ var ComposerPrimitiveInput = forwardRef16(
|
|
|
3646
3744
|
ref,
|
|
3647
3745
|
disabled: isDisabled,
|
|
3648
3746
|
onChange: composeEventHandlers6(onChange, (e) => {
|
|
3649
|
-
const composerState =
|
|
3747
|
+
const composerState = composerStore.getState();
|
|
3650
3748
|
if (!composerState.isEditing) return;
|
|
3651
3749
|
return composerState.setText(e.target.value);
|
|
3652
3750
|
}),
|
|
@@ -3680,23 +3778,23 @@ import { memo as memo4 } from "react";
|
|
|
3680
3778
|
|
|
3681
3779
|
// src/context/providers/ComposerAttachmentProvider.tsx
|
|
3682
3780
|
import { useEffect as useEffect12, useState as useState13 } from "react";
|
|
3683
|
-
import { create as
|
|
3781
|
+
import { create as create14 } from "zustand";
|
|
3684
3782
|
import { jsx as jsx29 } from "react/jsx-runtime";
|
|
3685
|
-
var getAttachment2 = ({ attachments },
|
|
3686
|
-
|
|
3783
|
+
var getAttachment2 = ({ attachments }, useAttachment2, partIndex) => {
|
|
3784
|
+
const attachment = attachments[partIndex];
|
|
3687
3785
|
if (!attachment) return null;
|
|
3688
|
-
const currentState =
|
|
3786
|
+
const currentState = useAttachment2?.getState();
|
|
3689
3787
|
if (currentState && currentState.attachment === attachment) return null;
|
|
3690
3788
|
return Object.freeze({ attachment });
|
|
3691
3789
|
};
|
|
3692
|
-
var
|
|
3693
|
-
const
|
|
3790
|
+
var useComposerAttachmentContext2 = (partIndex) => {
|
|
3791
|
+
const threadComposerStore = useThreadComposerStore();
|
|
3694
3792
|
const [context] = useState13(
|
|
3695
3793
|
() => {
|
|
3696
|
-
const
|
|
3697
|
-
() => getAttachment2(
|
|
3794
|
+
const useAttachment2 = create14(
|
|
3795
|
+
() => getAttachment2(threadComposerStore.getState(), void 0, partIndex)
|
|
3698
3796
|
);
|
|
3699
|
-
return { type: "composer", useAttachment };
|
|
3797
|
+
return { type: "composer", useAttachment: useAttachment2 };
|
|
3700
3798
|
}
|
|
3701
3799
|
);
|
|
3702
3800
|
useEffect12(() => {
|
|
@@ -3709,13 +3807,13 @@ var useComposerAttachmentContext = (partIndex) => {
|
|
|
3709
3807
|
if (!newState) return;
|
|
3710
3808
|
writableStore(context.useAttachment).setState(newState, true);
|
|
3711
3809
|
};
|
|
3712
|
-
syncAttachment(
|
|
3713
|
-
return
|
|
3714
|
-
}, [context,
|
|
3810
|
+
syncAttachment(threadComposerStore.getState());
|
|
3811
|
+
return threadComposerStore.subscribe(syncAttachment);
|
|
3812
|
+
}, [context, threadComposerStore, partIndex]);
|
|
3715
3813
|
return context;
|
|
3716
3814
|
};
|
|
3717
3815
|
var ComposerAttachmentProvider = ({ attachmentIndex: partIndex, children }) => {
|
|
3718
|
-
const context =
|
|
3816
|
+
const context = useComposerAttachmentContext2(partIndex);
|
|
3719
3817
|
return /* @__PURE__ */ jsx29(AttachmentContext.Provider, { value: context, children });
|
|
3720
3818
|
};
|
|
3721
3819
|
|
|
@@ -3736,8 +3834,7 @@ var getComponent2 = (components, attachment) => {
|
|
|
3736
3834
|
}
|
|
3737
3835
|
};
|
|
3738
3836
|
var AttachmentComponent2 = ({ components }) => {
|
|
3739
|
-
const
|
|
3740
|
-
const Component = useAttachment(
|
|
3837
|
+
const Component = useComposerAttachment(
|
|
3741
3838
|
(a) => getComponent2(components, a.attachment)
|
|
3742
3839
|
);
|
|
3743
3840
|
if (!Component) return null;
|
|
@@ -3751,8 +3848,7 @@ var ComposerAttachment = memo4(
|
|
|
3751
3848
|
(prev, next) => prev.attachmentIndex === next.attachmentIndex && prev.components?.Image === next.components?.Image && prev.components?.Document === next.components?.Document && prev.components?.File === next.components?.File && prev.components?.Attachment === next.components?.Attachment
|
|
3752
3849
|
);
|
|
3753
3850
|
var ComposerPrimitiveAttachments = ({ components }) => {
|
|
3754
|
-
const
|
|
3755
|
-
const attachmentsCount = useComposer((s) => s.attachments.length);
|
|
3851
|
+
const attachmentsCount = useThreadComposer((s) => s.attachments.length);
|
|
3756
3852
|
return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ jsx30(
|
|
3757
3853
|
ComposerAttachment,
|
|
3758
3854
|
{
|
|
@@ -3877,12 +3973,12 @@ import { useCallbackRef as useCallbackRef4 } from "@radix-ui/react-use-callback-
|
|
|
3877
3973
|
import { useEffect as useEffect13 } from "react";
|
|
3878
3974
|
var useOnScrollToBottom = (callback) => {
|
|
3879
3975
|
const callbackRef = useCallbackRef4(callback);
|
|
3880
|
-
const
|
|
3976
|
+
const threadViewportStore = useThreadViewportStore();
|
|
3881
3977
|
useEffect13(() => {
|
|
3882
|
-
return
|
|
3978
|
+
return threadViewportStore.getState().onScrollToBottom(() => {
|
|
3883
3979
|
callbackRef();
|
|
3884
3980
|
});
|
|
3885
|
-
}, [
|
|
3981
|
+
}, [threadViewportStore, callbackRef]);
|
|
3886
3982
|
};
|
|
3887
3983
|
|
|
3888
3984
|
// src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
|
|
@@ -3890,7 +3986,7 @@ var useThreadViewportAutoScroll = ({
|
|
|
3890
3986
|
autoScroll = true
|
|
3891
3987
|
}) => {
|
|
3892
3988
|
const divRef = useRef5(null);
|
|
3893
|
-
const
|
|
3989
|
+
const threadViewportStore = useThreadViewportStore();
|
|
3894
3990
|
const lastScrollTop = useRef5(0);
|
|
3895
3991
|
const isScrollingToBottomRef = useRef5(false);
|
|
3896
3992
|
const scrollToBottom = (behavior) => {
|
|
@@ -3902,7 +3998,7 @@ var useThreadViewportAutoScroll = ({
|
|
|
3902
3998
|
const handleScroll = () => {
|
|
3903
3999
|
const div = divRef.current;
|
|
3904
4000
|
if (!div) return;
|
|
3905
|
-
const isAtBottom =
|
|
4001
|
+
const isAtBottom = threadViewportStore.getState().isAtBottom;
|
|
3906
4002
|
const newIsAtBottom = div.scrollHeight - div.scrollTop <= div.clientHeight + 1;
|
|
3907
4003
|
if (!newIsAtBottom && lastScrollTop.current < div.scrollTop) {
|
|
3908
4004
|
} else {
|
|
@@ -3910,13 +4006,15 @@ var useThreadViewportAutoScroll = ({
|
|
|
3910
4006
|
isScrollingToBottomRef.current = false;
|
|
3911
4007
|
}
|
|
3912
4008
|
if (newIsAtBottom !== isAtBottom) {
|
|
3913
|
-
writableStore(
|
|
4009
|
+
writableStore(threadViewportStore).setState({
|
|
4010
|
+
isAtBottom: newIsAtBottom
|
|
4011
|
+
});
|
|
3914
4012
|
}
|
|
3915
4013
|
}
|
|
3916
4014
|
lastScrollTop.current = div.scrollTop;
|
|
3917
4015
|
};
|
|
3918
4016
|
const resizeRef = useOnResizeContent(() => {
|
|
3919
|
-
if (isScrollingToBottomRef.current ||
|
|
4017
|
+
if (isScrollingToBottomRef.current || threadViewportStore.getState().isAtBottom) {
|
|
3920
4018
|
scrollToBottom("instant");
|
|
3921
4019
|
}
|
|
3922
4020
|
handleScroll();
|
|
@@ -3936,7 +4034,7 @@ var useThreadViewportAutoScroll = ({
|
|
|
3936
4034
|
|
|
3937
4035
|
// src/primitives/thread/ThreadViewport.tsx
|
|
3938
4036
|
import { jsx as jsx32 } from "react/jsx-runtime";
|
|
3939
|
-
var ThreadPrimitiveViewport = forwardRef18(({ autoScroll,
|
|
4037
|
+
var ThreadPrimitiveViewport = forwardRef18(({ autoScroll, children, ...rest }, forwardedRef) => {
|
|
3940
4038
|
const autoScrollRef = useThreadViewportAutoScroll({
|
|
3941
4039
|
autoScroll
|
|
3942
4040
|
});
|
|
@@ -3950,14 +4048,15 @@ import { memo as memo5 } from "react";
|
|
|
3950
4048
|
|
|
3951
4049
|
// src/context/providers/MessageProvider.tsx
|
|
3952
4050
|
import { useEffect as useEffect14, useState as useState14 } from "react";
|
|
3953
|
-
import { create as
|
|
4051
|
+
import { create as create17 } from "zustand";
|
|
3954
4052
|
|
|
3955
4053
|
// src/context/stores/EditComposer.ts
|
|
3956
|
-
import { create as
|
|
4054
|
+
import { create as create15 } from "zustand";
|
|
3957
4055
|
var makeEditComposerStore = ({
|
|
3958
4056
|
onEdit,
|
|
3959
4057
|
onSend
|
|
3960
|
-
}) =>
|
|
4058
|
+
}) => create15()((set, get) => ({
|
|
4059
|
+
type: "edit",
|
|
3961
4060
|
get value() {
|
|
3962
4061
|
return get().text;
|
|
3963
4062
|
},
|
|
@@ -3991,8 +4090,8 @@ var makeEditComposerStore = ({
|
|
|
3991
4090
|
}));
|
|
3992
4091
|
|
|
3993
4092
|
// src/context/stores/MessageUtils.ts
|
|
3994
|
-
import { create as
|
|
3995
|
-
var makeMessageUtilsStore = () =>
|
|
4093
|
+
import { create as create16 } from "zustand";
|
|
4094
|
+
var makeMessageUtilsStore = () => create16((set) => {
|
|
3996
4095
|
let utterance = null;
|
|
3997
4096
|
return {
|
|
3998
4097
|
isCopied: false,
|
|
@@ -4022,13 +4121,13 @@ import { jsx as jsx33 } from "react/jsx-runtime";
|
|
|
4022
4121
|
var getIsLast = (messages, message) => {
|
|
4023
4122
|
return messages[messages.length - 1]?.id === message.id;
|
|
4024
4123
|
};
|
|
4025
|
-
var getMessageState = (messages, getBranches,
|
|
4124
|
+
var getMessageState = (messages, getBranches, useMessage2, messageIndex) => {
|
|
4026
4125
|
const parentId = messages[messageIndex - 1]?.id ?? null;
|
|
4027
4126
|
const message = messages[messageIndex];
|
|
4028
4127
|
if (!message) return null;
|
|
4029
4128
|
const isLast = getIsLast(messages, message);
|
|
4030
4129
|
const branches = getBranches(message.id);
|
|
4031
|
-
const currentState =
|
|
4130
|
+
const currentState = useMessage2?.getState();
|
|
4032
4131
|
if (currentState && currentState.message === message && currentState.parentId === parentId && currentState.branches === branches && currentState.isLast === isLast)
|
|
4033
4132
|
return null;
|
|
4034
4133
|
return Object.freeze({
|
|
@@ -4039,31 +4138,32 @@ var getMessageState = (messages, getBranches, useMessage, messageIndex) => {
|
|
|
4039
4138
|
});
|
|
4040
4139
|
};
|
|
4041
4140
|
var useMessageContext2 = (messageIndex) => {
|
|
4042
|
-
const
|
|
4141
|
+
const threadMessagesStore = useThreadMessagesStore();
|
|
4142
|
+
const threadActionsStore = useThreadActionsStore();
|
|
4043
4143
|
const [context] = useState14(() => {
|
|
4044
|
-
const
|
|
4144
|
+
const useMessage2 = create17(
|
|
4045
4145
|
() => getMessageState(
|
|
4046
|
-
|
|
4047
|
-
|
|
4146
|
+
threadMessagesStore.getState(),
|
|
4147
|
+
threadActionsStore.getState().getBranches,
|
|
4048
4148
|
void 0,
|
|
4049
4149
|
messageIndex
|
|
4050
4150
|
)
|
|
4051
4151
|
);
|
|
4052
|
-
const
|
|
4053
|
-
const
|
|
4152
|
+
const useMessageUtils2 = makeMessageUtilsStore();
|
|
4153
|
+
const useEditComposer2 = makeEditComposerStore({
|
|
4054
4154
|
onEdit: () => {
|
|
4055
|
-
const message =
|
|
4155
|
+
const message = useMessage2.getState().message;
|
|
4056
4156
|
const text = getThreadMessageText(message);
|
|
4057
4157
|
return text;
|
|
4058
4158
|
},
|
|
4059
4159
|
onSend: (text) => {
|
|
4060
|
-
const { message, parentId } =
|
|
4160
|
+
const { message, parentId } = useMessage2.getState();
|
|
4061
4161
|
const previousText = getThreadMessageText(message);
|
|
4062
4162
|
if (previousText === text) return;
|
|
4063
4163
|
const nonTextParts = message.content.filter(
|
|
4064
4164
|
(part) => part.type !== "text" && part.type !== "ui"
|
|
4065
4165
|
);
|
|
4066
|
-
|
|
4166
|
+
threadActionsStore.getState().append({
|
|
4067
4167
|
parentId,
|
|
4068
4168
|
role: message.role,
|
|
4069
4169
|
content: [{ type: "text", text }, ...nonTextParts],
|
|
@@ -4071,22 +4171,22 @@ var useMessageContext2 = (messageIndex) => {
|
|
|
4071
4171
|
});
|
|
4072
4172
|
}
|
|
4073
4173
|
});
|
|
4074
|
-
return { useMessage, useMessageUtils, useEditComposer };
|
|
4174
|
+
return { useMessage: useMessage2, useMessageUtils: useMessageUtils2, useEditComposer: useEditComposer2 };
|
|
4075
4175
|
});
|
|
4076
4176
|
useEffect14(() => {
|
|
4077
4177
|
const syncMessage = (thread) => {
|
|
4078
4178
|
const newState = getMessageState(
|
|
4079
4179
|
thread,
|
|
4080
|
-
|
|
4180
|
+
threadActionsStore.getState().getBranches,
|
|
4081
4181
|
context.useMessage,
|
|
4082
4182
|
messageIndex
|
|
4083
4183
|
);
|
|
4084
4184
|
if (!newState) return;
|
|
4085
4185
|
writableStore(context.useMessage).setState(newState, true);
|
|
4086
4186
|
};
|
|
4087
|
-
syncMessage(
|
|
4088
|
-
return
|
|
4089
|
-
}, [
|
|
4187
|
+
syncMessage(threadMessagesStore.getState());
|
|
4188
|
+
return threadMessagesStore.subscribe(syncMessage);
|
|
4189
|
+
}, [threadMessagesStore, threadActionsStore, context, messageIndex]);
|
|
4090
4190
|
return context;
|
|
4091
4191
|
};
|
|
4092
4192
|
var MessageProvider = ({
|
|
@@ -4131,7 +4231,6 @@ var getComponent3 = (components, role, isEditing) => {
|
|
|
4131
4231
|
var ThreadMessageComponent = ({
|
|
4132
4232
|
components
|
|
4133
4233
|
}) => {
|
|
4134
|
-
const { useMessage, useEditComposer } = useMessageContext();
|
|
4135
4234
|
const role = useMessage((m) => m.message.role);
|
|
4136
4235
|
const isEditing = useEditComposer((c) => c.isEditing);
|
|
4137
4236
|
const Component = getComponent3(components, role, isEditing);
|
|
@@ -4150,7 +4249,6 @@ var ThreadMessage = memo5(
|
|
|
4150
4249
|
var ThreadPrimitiveMessagesImpl = ({
|
|
4151
4250
|
components
|
|
4152
4251
|
}) => {
|
|
4153
|
-
const { useThreadMessages } = useThreadContext();
|
|
4154
4252
|
const messagesLength = useThreadMessages((t) => t.length);
|
|
4155
4253
|
if (messagesLength === 0) return null;
|
|
4156
4254
|
return Array.from({ length: messagesLength }, (_, index) => /* @__PURE__ */ jsx34(ThreadMessage, { messageIndex: index, components }, index));
|
|
@@ -4177,21 +4275,21 @@ var ThreadPrimitiveSuggestion = createActionButton(
|
|
|
4177
4275
|
// src/ui/thread-config.tsx
|
|
4178
4276
|
import {
|
|
4179
4277
|
createContext as createContext7,
|
|
4180
|
-
useContext as
|
|
4278
|
+
useContext as useContext4
|
|
4181
4279
|
} from "react";
|
|
4182
4280
|
import { Fragment as Fragment3, jsx as jsx35 } from "react/jsx-runtime";
|
|
4183
4281
|
var ThreadConfigContext = createContext7({});
|
|
4184
4282
|
var useThreadConfig = () => {
|
|
4185
|
-
return
|
|
4283
|
+
return useContext4(ThreadConfigContext);
|
|
4186
4284
|
};
|
|
4187
4285
|
var ThreadConfigProvider = ({
|
|
4188
4286
|
children,
|
|
4189
4287
|
config
|
|
4190
4288
|
}) => {
|
|
4191
|
-
const
|
|
4289
|
+
const hasAssistant = !!useAssistantRuntimeStore({ optional: true });
|
|
4192
4290
|
const configProvider = config && Object.keys(config ?? {}).length > 0 ? /* @__PURE__ */ jsx35(ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ jsx35(Fragment3, { children });
|
|
4193
4291
|
if (!config?.runtime) return configProvider;
|
|
4194
|
-
if (
|
|
4292
|
+
if (hasAssistant) {
|
|
4195
4293
|
throw new Error(
|
|
4196
4294
|
"You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
|
|
4197
4295
|
);
|
|
@@ -4212,19 +4310,16 @@ import {
|
|
|
4212
4310
|
import { Fragment as Fragment4, jsx as jsx36, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
4213
4311
|
var useAllowCopy = (ensureCapability = false) => {
|
|
4214
4312
|
const { assistantMessage: { allowCopy = true } = {} } = useThreadConfig();
|
|
4215
|
-
const { useThread } = useThreadContext();
|
|
4216
4313
|
const copySupported = useThread((t) => t.capabilities.unstable_copy);
|
|
4217
4314
|
return allowCopy && (!ensureCapability || copySupported);
|
|
4218
4315
|
};
|
|
4219
4316
|
var useAllowSpeak = (ensureCapability = false) => {
|
|
4220
4317
|
const { assistantMessage: { allowSpeak = true } = {} } = useThreadConfig();
|
|
4221
|
-
const { useThread } = useThreadContext();
|
|
4222
4318
|
const speakSupported = useThread((t) => t.capabilities.speak);
|
|
4223
4319
|
return allowSpeak && (!ensureCapability || speakSupported);
|
|
4224
4320
|
};
|
|
4225
4321
|
var useAllowReload = (ensureCapability = false) => {
|
|
4226
4322
|
const { assistantMessage: { allowReload = true } = {} } = useThreadConfig();
|
|
4227
|
-
const { useThread } = useThreadContext();
|
|
4228
4323
|
const reloadSupported = useThread((t) => t.capabilities.reload);
|
|
4229
4324
|
return allowReload && (!ensureCapability || reloadSupported);
|
|
4230
4325
|
};
|
|
@@ -4324,7 +4419,6 @@ import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
|
|
4324
4419
|
import { jsx as jsx37, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
4325
4420
|
var useAllowBranchPicker = (ensureCapability = false) => {
|
|
4326
4421
|
const { branchPicker: { allowBranchPicker = true } = {} } = useThreadConfig();
|
|
4327
|
-
const { useThread } = useThreadContext();
|
|
4328
4422
|
const branchPickerSupported = useThread((t) => t.capabilities.edit);
|
|
4329
4423
|
return allowBranchPicker && (!ensureCapability || branchPickerSupported);
|
|
4330
4424
|
};
|
|
@@ -4518,8 +4612,7 @@ var ComposerAttachmentRoot = withDefaults("div", {
|
|
|
4518
4612
|
});
|
|
4519
4613
|
ComposerAttachmentRoot.displayName = "ComposerAttachmentRoot";
|
|
4520
4614
|
var ComposerAttachment2 = () => {
|
|
4521
|
-
const
|
|
4522
|
-
const attachment = useAttachment((a) => a.attachment);
|
|
4615
|
+
const attachment = useComposerAttachment((a) => a.attachment);
|
|
4523
4616
|
return /* @__PURE__ */ jsxs8(ComposerAttachmentRoot, { children: [
|
|
4524
4617
|
".",
|
|
4525
4618
|
attachment.name.split(".").pop(),
|
|
@@ -4533,10 +4626,10 @@ var ComposerAttachmentRemove = forwardRef22((props, ref) => {
|
|
|
4533
4626
|
composer: { removeAttachment: { tooltip = "Remove file" } = {} } = {}
|
|
4534
4627
|
} = {}
|
|
4535
4628
|
} = useThreadConfig();
|
|
4536
|
-
const
|
|
4537
|
-
const
|
|
4629
|
+
const composerStore = useThreadComposerStore();
|
|
4630
|
+
const attachmentStore = useAttachmentStore();
|
|
4538
4631
|
const handleRemoveAttachment = () => {
|
|
4539
|
-
|
|
4632
|
+
composerStore.getState().removeAttachment(attachmentStore.getState().attachment.id);
|
|
4540
4633
|
};
|
|
4541
4634
|
return /* @__PURE__ */ jsx42(
|
|
4542
4635
|
TooltipIconButton,
|
|
@@ -4565,7 +4658,6 @@ var composer_attachment_default = Object.assign(
|
|
|
4565
4658
|
import { Fragment as Fragment5, jsx as jsx43, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
4566
4659
|
var useAllowAttachments = (ensureCapability = false) => {
|
|
4567
4660
|
const { composer: { allowAttachments = true } = {} } = useThreadConfig();
|
|
4568
|
-
const { useThread } = useThreadContext();
|
|
4569
4661
|
const attachmentsSupported = useThread((t) => t.capabilities.attachments);
|
|
4570
4662
|
return allowAttachments && (!ensureCapability || attachmentsSupported);
|
|
4571
4663
|
};
|
|
@@ -4637,7 +4729,6 @@ var ComposerAddAttachment = forwardRef23((props, ref) => {
|
|
|
4637
4729
|
});
|
|
4638
4730
|
ComposerAddAttachment.displayName = "ComposerAddAttachment";
|
|
4639
4731
|
var useAllowCancel = () => {
|
|
4640
|
-
const { useThread } = useThreadContext();
|
|
4641
4732
|
const cancelSupported = useThread((t) => t.capabilities.cancel);
|
|
4642
4733
|
return cancelSupported;
|
|
4643
4734
|
};
|
|
@@ -4766,7 +4857,6 @@ import { PencilIcon } from "lucide-react";
|
|
|
4766
4857
|
import { jsx as jsx45 } from "react/jsx-runtime";
|
|
4767
4858
|
var useAllowEdit = (ensureCapability = false) => {
|
|
4768
4859
|
const { userMessage: { allowEdit = true } = {} } = useThreadConfig();
|
|
4769
|
-
const { useThread } = useThreadContext();
|
|
4770
4860
|
const editSupported = useThread((t) => t.capabilities.edit);
|
|
4771
4861
|
return allowEdit && (!ensureCapability || editSupported);
|
|
4772
4862
|
};
|
|
@@ -4801,7 +4891,6 @@ var UserMessageAttachmentRoot = withDefaults("div", {
|
|
|
4801
4891
|
});
|
|
4802
4892
|
UserMessageAttachmentRoot.displayName = "UserMessageAttachmentRoot";
|
|
4803
4893
|
var UserMessageAttachment = () => {
|
|
4804
|
-
const { useAttachment } = useAttachmentContext();
|
|
4805
4894
|
const attachment = useAttachment((a) => a.attachment);
|
|
4806
4895
|
return /* @__PURE__ */ jsxs11(UserMessageAttachmentRoot, { children: [
|
|
4807
4896
|
".",
|
|
@@ -5123,36 +5212,64 @@ export {
|
|
|
5123
5212
|
useActionBarSpeak,
|
|
5124
5213
|
useActionBarStopSpeaking,
|
|
5125
5214
|
useAppendMessage,
|
|
5215
|
+
useAssistantActions,
|
|
5216
|
+
useAssistantActionsStore,
|
|
5126
5217
|
useAssistantContext,
|
|
5127
5218
|
useAssistantInstructions,
|
|
5219
|
+
useAssistantRuntime,
|
|
5220
|
+
useAssistantRuntimeStore,
|
|
5128
5221
|
useAssistantTool,
|
|
5129
5222
|
useAssistantToolUI,
|
|
5130
5223
|
useBranchPickerCount,
|
|
5131
5224
|
useBranchPickerNext,
|
|
5132
5225
|
useBranchPickerNumber,
|
|
5133
5226
|
useBranchPickerPrevious,
|
|
5227
|
+
useComposer,
|
|
5134
5228
|
useComposerAddAttachment,
|
|
5135
5229
|
useComposerCancel,
|
|
5136
5230
|
useComposerContext,
|
|
5137
5231
|
useComposerIf,
|
|
5138
5232
|
useComposerSend,
|
|
5233
|
+
useComposerStore,
|
|
5234
|
+
useContentPart,
|
|
5139
5235
|
useContentPartContext,
|
|
5140
5236
|
useContentPartDisplay,
|
|
5141
5237
|
useContentPartImage,
|
|
5238
|
+
useContentPartStore,
|
|
5142
5239
|
useContentPartText,
|
|
5143
5240
|
useDangerousInBrowserRuntime,
|
|
5144
5241
|
useEdgeRuntime,
|
|
5242
|
+
useEditComposer,
|
|
5243
|
+
useEditComposerStore,
|
|
5145
5244
|
useExternalMessageConverter,
|
|
5146
5245
|
useExternalStoreRuntime,
|
|
5147
5246
|
useLocalRuntime,
|
|
5247
|
+
useMessage,
|
|
5148
5248
|
useMessageContext,
|
|
5149
5249
|
useMessageIf,
|
|
5250
|
+
useMessageStore,
|
|
5251
|
+
useMessageUtils,
|
|
5252
|
+
useMessageUtilsStore,
|
|
5150
5253
|
useSwitchToNewThread,
|
|
5254
|
+
useThread,
|
|
5255
|
+
useThreadActions,
|
|
5256
|
+
useThreadActionsStore,
|
|
5257
|
+
useThreadComposer,
|
|
5258
|
+
useThreadComposerStore,
|
|
5151
5259
|
useThreadConfig,
|
|
5152
5260
|
useThreadContext,
|
|
5153
5261
|
useThreadEmpty,
|
|
5154
5262
|
useThreadIf,
|
|
5263
|
+
useThreadMessages,
|
|
5264
|
+
useThreadMessagesStore,
|
|
5265
|
+
useThreadRuntime,
|
|
5266
|
+
useThreadRuntimeStore,
|
|
5155
5267
|
useThreadScrollToBottom,
|
|
5156
|
-
|
|
5268
|
+
useThreadStore,
|
|
5269
|
+
useThreadSuggestion,
|
|
5270
|
+
useThreadViewport,
|
|
5271
|
+
useThreadViewportStore,
|
|
5272
|
+
useToolUIs,
|
|
5273
|
+
useToolUIsStore
|
|
5157
5274
|
};
|
|
5158
5275
|
//# sourceMappingURL=index.mjs.map
|