@assistant-ui/react 0.1.12 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/experimental.d.mts +1 -115
- package/dist/experimental.d.ts +1 -115
- package/dist/experimental.js +0 -183
- package/dist/experimental.js.map +1 -1
- package/dist/experimental.mjs +0 -88
- package/dist/experimental.mjs.map +1 -1
- package/dist/index.d.mts +396 -106
- package/dist/index.d.ts +396 -106
- package/dist/index.js +888 -633
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +865 -552
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/ThreadActions-BLcKtagX.d.mts +0 -98
- package/dist/ThreadActions-BLcKtagX.d.ts +0 -98
- package/dist/chunk-KUACYNLE.mjs +0 -85
- package/dist/chunk-KUACYNLE.mjs.map +0 -1
package/dist/index.mjs
CHANGED
@@ -1,24 +1,479 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __export = (target, all) => {
|
3
|
+
for (var name in all)
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
5
|
+
};
|
6
|
+
|
7
|
+
// src/context/providers/AssistantRuntimeProvider.tsx
|
8
|
+
import { memo } from "react";
|
9
|
+
|
10
|
+
// src/context/providers/AssistantProvider.tsx
|
11
|
+
import { useEffect as useEffect2, useInsertionEffect as useInsertionEffect2, useRef as useRef2, useState as useState2 } from "react";
|
12
|
+
|
13
|
+
// src/context/react/AssistantContext.ts
|
14
|
+
import { createContext, useContext } from "react";
|
15
|
+
var AssistantContext = createContext(
|
16
|
+
null
|
17
|
+
);
|
18
|
+
var useAssistantContext = () => {
|
19
|
+
const context = useContext(AssistantContext);
|
20
|
+
if (!context)
|
21
|
+
throw new Error(
|
22
|
+
"This component must be used within an AssistantRuntimeProvider."
|
23
|
+
);
|
24
|
+
return context;
|
25
|
+
};
|
26
|
+
|
27
|
+
// src/context/stores/AssistantModelConfig.ts
|
28
|
+
import { create } from "zustand";
|
29
|
+
|
30
|
+
// src/types/ModelConfigTypes.ts
|
31
|
+
var mergeModelConfigs = (configSet) => {
|
32
|
+
const configs = Array.from(configSet).map((c) => c()).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
33
|
+
return configs.reduce((acc, config) => {
|
34
|
+
if (config.system) {
|
35
|
+
if (acc.system) {
|
36
|
+
acc.system += `
|
37
|
+
|
38
|
+
${config.system}`;
|
39
|
+
} else {
|
40
|
+
acc.system = config.system;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
if (config.tools) {
|
44
|
+
for (const [name, tool] of Object.entries(config.tools)) {
|
45
|
+
if (acc.tools?.[name]) {
|
46
|
+
throw new Error(
|
47
|
+
`You tried to define a tool with the name ${name}, but it already exists.`
|
48
|
+
);
|
49
|
+
}
|
50
|
+
if (!acc.tools) acc.tools = {};
|
51
|
+
acc.tools[name] = tool;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
return acc;
|
55
|
+
}, {});
|
56
|
+
};
|
57
|
+
|
58
|
+
// src/utils/ProxyConfigProvider.ts
|
59
|
+
var ProxyConfigProvider = class {
|
60
|
+
_providers = /* @__PURE__ */ new Set();
|
61
|
+
getModelConfig() {
|
62
|
+
return mergeModelConfigs(this._providers);
|
63
|
+
}
|
64
|
+
registerModelConfigProvider(provider) {
|
65
|
+
this._providers.add(provider);
|
66
|
+
return () => {
|
67
|
+
this._providers.delete(provider);
|
68
|
+
};
|
69
|
+
}
|
70
|
+
};
|
71
|
+
|
72
|
+
// src/context/stores/AssistantModelConfig.ts
|
73
|
+
var makeAssistantModelConfigStore = () => create(() => {
|
74
|
+
const proxy = new ProxyConfigProvider();
|
75
|
+
return Object.freeze({
|
76
|
+
getModelConfig: () => {
|
77
|
+
return proxy.getModelConfig();
|
78
|
+
},
|
79
|
+
registerModelConfigProvider: (provider) => {
|
80
|
+
return proxy.registerModelConfigProvider(provider);
|
81
|
+
}
|
82
|
+
});
|
83
|
+
});
|
84
|
+
|
85
|
+
// src/context/stores/AssistantToolUIs.ts
|
86
|
+
import { create as create2 } from "zustand";
|
87
|
+
var makeAssistantToolUIsStore = () => create2((set) => {
|
88
|
+
const renderers = /* @__PURE__ */ new Map();
|
89
|
+
return Object.freeze({
|
90
|
+
getToolUI: (name) => {
|
91
|
+
const arr = renderers.get(name);
|
92
|
+
const last = arr?.at(-1);
|
93
|
+
if (last) return last;
|
94
|
+
return null;
|
95
|
+
},
|
96
|
+
setToolUI: (name, render) => {
|
97
|
+
let arr = renderers.get(name);
|
98
|
+
if (!arr) {
|
99
|
+
arr = [];
|
100
|
+
renderers.set(name, arr);
|
101
|
+
}
|
102
|
+
arr.push(render);
|
103
|
+
set({});
|
104
|
+
return () => {
|
105
|
+
const index = arr.indexOf(render);
|
106
|
+
if (index !== -1) {
|
107
|
+
arr.splice(index, 1);
|
108
|
+
}
|
109
|
+
if (index === arr.length) {
|
110
|
+
set({});
|
111
|
+
}
|
112
|
+
};
|
113
|
+
}
|
114
|
+
});
|
115
|
+
});
|
116
|
+
|
117
|
+
// src/context/providers/ThreadProvider.tsx
|
1
118
|
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
119
|
+
useCallback,
|
120
|
+
useEffect,
|
121
|
+
useInsertionEffect,
|
122
|
+
useRef,
|
123
|
+
useState,
|
124
|
+
useSyncExternalStore
|
125
|
+
} from "react";
|
126
|
+
|
127
|
+
// src/context/react/ThreadContext.ts
|
128
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
129
|
+
var ThreadContext = createContext2(null);
|
130
|
+
var useThreadContext = () => {
|
131
|
+
const context = useContext2(ThreadContext);
|
132
|
+
if (!context)
|
133
|
+
throw new Error(
|
134
|
+
"This component must be used within an AssistantRuntimeProvider."
|
135
|
+
);
|
136
|
+
return context;
|
137
|
+
};
|
138
|
+
|
139
|
+
// src/context/stores/Composer.ts
|
140
|
+
import { create as create3 } from "zustand";
|
141
|
+
|
142
|
+
// src/context/stores/BaseComposer.ts
|
143
|
+
var makeBaseComposer = (set) => ({
|
144
|
+
value: "",
|
145
|
+
setValue: (value) => {
|
146
|
+
set({ value });
|
147
|
+
}
|
148
|
+
});
|
149
|
+
|
150
|
+
// src/context/stores/Composer.ts
|
151
|
+
var makeComposerStore = (useThread, useThreadActions) => {
|
152
|
+
const focusListeners = /* @__PURE__ */ new Set();
|
153
|
+
return create3()((set, get, store) => {
|
154
|
+
return {
|
155
|
+
...makeBaseComposer(set, get, store),
|
156
|
+
isEditing: true,
|
157
|
+
send: () => {
|
158
|
+
const { setValue, value } = get();
|
159
|
+
setValue("");
|
160
|
+
useThreadActions.getState().append({
|
161
|
+
parentId: useThread.getState().messages.at(-1)?.id ?? null,
|
162
|
+
role: "user",
|
163
|
+
content: [{ type: "text", text: value }]
|
164
|
+
});
|
165
|
+
},
|
166
|
+
cancel: () => {
|
167
|
+
const thread = useThread.getState();
|
168
|
+
if (!thread.isRunning) return false;
|
169
|
+
useThreadActions.getState().cancelRun();
|
170
|
+
return true;
|
171
|
+
},
|
172
|
+
focus: () => {
|
173
|
+
for (const listener of focusListeners) {
|
174
|
+
listener();
|
175
|
+
}
|
176
|
+
},
|
177
|
+
onFocus: (listener) => {
|
178
|
+
focusListeners.add(listener);
|
179
|
+
return () => {
|
180
|
+
focusListeners.delete(listener);
|
181
|
+
};
|
182
|
+
}
|
183
|
+
};
|
184
|
+
});
|
185
|
+
};
|
186
|
+
|
187
|
+
// src/context/stores/Thread.ts
|
188
|
+
import { create as create4 } from "zustand";
|
189
|
+
var makeThreadStore = (runtimeRef) => {
|
190
|
+
return create4(() => ({
|
191
|
+
messages: runtimeRef.current.messages,
|
192
|
+
isRunning: runtimeRef.current.isRunning
|
193
|
+
}));
|
194
|
+
};
|
195
|
+
|
196
|
+
// src/context/stores/ThreadViewport.tsx
|
197
|
+
import { create as create5 } from "zustand";
|
198
|
+
var makeThreadViewportStore = () => {
|
199
|
+
const scrollToBottomListeners = /* @__PURE__ */ new Set();
|
200
|
+
return create5(() => ({
|
201
|
+
isAtBottom: true,
|
202
|
+
scrollToBottom: () => {
|
203
|
+
for (const listener of scrollToBottomListeners) {
|
204
|
+
listener();
|
205
|
+
}
|
206
|
+
},
|
207
|
+
onScrollToBottom: (callback) => {
|
208
|
+
scrollToBottomListeners.add(callback);
|
209
|
+
return () => {
|
210
|
+
scrollToBottomListeners.delete(callback);
|
211
|
+
};
|
212
|
+
}
|
213
|
+
}));
|
214
|
+
};
|
215
|
+
|
216
|
+
// src/context/stores/ThreadActions.ts
|
217
|
+
import { create as create6 } from "zustand";
|
218
|
+
var makeThreadActionStore = (runtimeRef) => {
|
219
|
+
return create6(
|
220
|
+
() => Object.freeze({
|
221
|
+
getBranches: (messageId) => runtimeRef.current.getBranches(messageId),
|
222
|
+
switchToBranch: (branchId) => runtimeRef.current.switchToBranch(branchId),
|
223
|
+
startRun: (parentId) => runtimeRef.current.startRun(parentId),
|
224
|
+
append: (message) => runtimeRef.current.append(message),
|
225
|
+
cancelRun: () => runtimeRef.current.cancelRun(),
|
226
|
+
addToolResult: (toolCallId, result) => runtimeRef.current.addToolResult(toolCallId, result)
|
227
|
+
})
|
228
|
+
);
|
229
|
+
};
|
230
|
+
|
231
|
+
// src/context/providers/ThreadProvider.tsx
|
232
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
233
|
+
var ThreadProvider = ({
|
234
|
+
children,
|
235
|
+
runtime
|
236
|
+
}) => {
|
237
|
+
const runtimeRef = useRef(runtime);
|
238
|
+
useInsertionEffect(() => {
|
239
|
+
runtimeRef.current = runtime;
|
240
|
+
});
|
241
|
+
const [context] = useState(() => {
|
242
|
+
const useThread = makeThreadStore(runtimeRef);
|
243
|
+
const useThreadActions = makeThreadActionStore(runtimeRef);
|
244
|
+
const useViewport = makeThreadViewportStore();
|
245
|
+
const useComposer = makeComposerStore(useThread, useThreadActions);
|
246
|
+
return {
|
247
|
+
useThread,
|
248
|
+
useThreadActions,
|
249
|
+
useComposer,
|
250
|
+
useViewport
|
251
|
+
};
|
252
|
+
});
|
253
|
+
useEffect(() => {
|
254
|
+
const onRuntimeUpdate = () => {
|
255
|
+
context.useThread.setState(
|
256
|
+
Object.freeze({
|
257
|
+
messages: runtimeRef.current.messages,
|
258
|
+
isRunning: runtimeRef.current.isRunning
|
259
|
+
}),
|
260
|
+
true
|
261
|
+
);
|
262
|
+
};
|
263
|
+
onRuntimeUpdate();
|
264
|
+
return runtime.subscribe(onRuntimeUpdate);
|
265
|
+
}, [context, runtime]);
|
266
|
+
const subscribe = useCallback(
|
267
|
+
(c) => runtime.subscribe(c),
|
268
|
+
[runtime]
|
269
|
+
);
|
270
|
+
const RuntimeSynchronizer = useSyncExternalStore(
|
271
|
+
subscribe,
|
272
|
+
() => runtime.unstable_synchronizer,
|
273
|
+
() => void 0
|
274
|
+
);
|
275
|
+
return /* @__PURE__ */ jsxs(ThreadContext.Provider, { value: context, children: [
|
276
|
+
RuntimeSynchronizer && /* @__PURE__ */ jsx(RuntimeSynchronizer, {}),
|
277
|
+
children
|
278
|
+
] });
|
279
|
+
};
|
280
|
+
|
281
|
+
// src/context/stores/AssistantActions.tsx
|
282
|
+
import { create as create7 } from "zustand";
|
283
|
+
var makeAssistantActionsStore = (runtimeRef) => create7(
|
284
|
+
() => Object.freeze({
|
285
|
+
switchToThread: () => runtimeRef.current.switchToThread(null)
|
286
|
+
})
|
287
|
+
);
|
288
|
+
|
289
|
+
// src/context/providers/AssistantProvider.tsx
|
290
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
291
|
+
var AssistantProvider = ({ children, runtime }) => {
|
292
|
+
const runtimeRef = useRef2(runtime);
|
293
|
+
useInsertionEffect2(() => {
|
294
|
+
runtimeRef.current = runtime;
|
295
|
+
});
|
296
|
+
const [context] = useState2(() => {
|
297
|
+
const useModelConfig = makeAssistantModelConfigStore();
|
298
|
+
const useToolUIs = makeAssistantToolUIsStore();
|
299
|
+
const useAssistantActions = makeAssistantActionsStore(runtimeRef);
|
300
|
+
return { useModelConfig, useToolUIs, useAssistantActions };
|
301
|
+
});
|
302
|
+
const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
|
303
|
+
useEffect2(() => {
|
304
|
+
return runtime.registerModelConfigProvider(getModelCOnfig);
|
305
|
+
}, [runtime, getModelCOnfig]);
|
306
|
+
return /* @__PURE__ */ jsx2(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ jsx2(ThreadProvider, { runtime, children }) });
|
307
|
+
};
|
308
|
+
|
309
|
+
// src/context/providers/AssistantRuntimeProvider.tsx
|
310
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
311
|
+
var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
312
|
+
return /* @__PURE__ */ jsx3(AssistantProvider, { runtime, children });
|
313
|
+
};
|
314
|
+
var AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
|
315
|
+
|
316
|
+
// src/context/react/ComposerContext.ts
|
317
|
+
import { useContext as useContext4, useMemo } from "react";
|
318
|
+
|
319
|
+
// src/context/react/MessageContext.ts
|
320
|
+
import { createContext as createContext3, useContext as useContext3 } from "react";
|
321
|
+
var MessageContext = createContext3(null);
|
322
|
+
var useMessageContext = () => {
|
323
|
+
const context = useContext3(MessageContext);
|
324
|
+
if (!context)
|
325
|
+
throw new Error(
|
326
|
+
"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
|
327
|
+
);
|
328
|
+
return context;
|
329
|
+
};
|
330
|
+
|
331
|
+
// src/context/react/ComposerContext.ts
|
332
|
+
var useComposerContext = () => {
|
333
|
+
const { useComposer } = useThreadContext();
|
334
|
+
const { useEditComposer } = useContext4(MessageContext) ?? {};
|
335
|
+
return useMemo(
|
336
|
+
() => ({
|
337
|
+
useComposer: useEditComposer ?? useComposer,
|
338
|
+
type: useEditComposer ? "edit" : "new"
|
339
|
+
}),
|
340
|
+
[useEditComposer, useComposer]
|
341
|
+
);
|
342
|
+
};
|
343
|
+
|
344
|
+
// src/context/react/ContentPartContext.ts
|
345
|
+
import { createContext as createContext4, useContext as useContext5 } from "react";
|
346
|
+
var ContentPartContext = createContext4(
|
347
|
+
null
|
348
|
+
);
|
349
|
+
var useContentPartContext = () => {
|
350
|
+
const context = useContext5(ContentPartContext);
|
351
|
+
if (!context)
|
352
|
+
throw new Error(
|
353
|
+
"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
|
354
|
+
);
|
355
|
+
return context;
|
356
|
+
};
|
357
|
+
|
358
|
+
// src/hooks/useAppendMessage.tsx
|
359
|
+
import { useCallback as useCallback2 } from "react";
|
360
|
+
var toAppendMessage = (useThread, message) => {
|
361
|
+
if (typeof message === "string") {
|
362
|
+
return {
|
363
|
+
parentId: useThread.getState().messages.at(-1)?.id ?? null,
|
364
|
+
role: "user",
|
365
|
+
content: [{ type: "text", text: message }]
|
366
|
+
};
|
367
|
+
}
|
368
|
+
return {
|
369
|
+
parentId: message.parentId ?? useThread.getState().messages.at(-1)?.id ?? null,
|
370
|
+
role: message.role ?? "user",
|
371
|
+
content: message.content
|
372
|
+
};
|
373
|
+
};
|
374
|
+
var useAppendMessage = () => {
|
375
|
+
const { useThread, useThreadActions, useViewport, useComposer } = useThreadContext();
|
376
|
+
const append = useCallback2(
|
377
|
+
(message) => {
|
378
|
+
const appendMessage = toAppendMessage(useThread, message);
|
379
|
+
useThreadActions.getState().append(appendMessage);
|
380
|
+
useViewport.getState().scrollToBottom();
|
381
|
+
useComposer.getState().focus();
|
382
|
+
},
|
383
|
+
[useThread, useThreadActions, useViewport, useComposer]
|
384
|
+
);
|
385
|
+
return append;
|
386
|
+
};
|
387
|
+
|
388
|
+
// src/hooks/useSwitchToNewThread.tsx
|
389
|
+
import { useCallback as useCallback3 } from "react";
|
390
|
+
var useSwitchToNewThread = () => {
|
391
|
+
const { useAssistantActions } = useAssistantContext();
|
392
|
+
const { useComposer } = useThreadContext();
|
393
|
+
const switchToNewThread = useCallback3(() => {
|
394
|
+
useAssistantActions.getState().switchToThread(null);
|
395
|
+
useComposer.getState().focus();
|
396
|
+
}, [useAssistantActions, useComposer]);
|
397
|
+
return switchToNewThread;
|
398
|
+
};
|
399
|
+
|
400
|
+
// src/model-config/useAssistantTool.tsx
|
401
|
+
import { useEffect as useEffect3 } from "react";
|
402
|
+
var useAssistantTool = (tool) => {
|
403
|
+
const { useModelConfig, useToolUIs } = useAssistantContext();
|
404
|
+
const registerModelConfigProvider = useModelConfig(
|
405
|
+
(s) => s.registerModelConfigProvider
|
406
|
+
);
|
407
|
+
const setToolUI = useToolUIs((s) => s.setToolUI);
|
408
|
+
useEffect3(() => {
|
409
|
+
const { toolName, render, ...rest } = tool;
|
410
|
+
const config = {
|
411
|
+
tools: {
|
412
|
+
[tool.toolName]: rest
|
413
|
+
}
|
414
|
+
};
|
415
|
+
const unsub1 = registerModelConfigProvider(() => config);
|
416
|
+
const unsub2 = render ? setToolUI(toolName, render) : void 0;
|
417
|
+
return () => {
|
418
|
+
unsub1();
|
419
|
+
unsub2?.();
|
420
|
+
};
|
421
|
+
}, [registerModelConfigProvider, setToolUI, tool]);
|
422
|
+
};
|
423
|
+
|
424
|
+
// src/model-config/makeAssistantTool.tsx
|
425
|
+
var makeAssistantTool = (tool) => {
|
426
|
+
const Tool = () => {
|
427
|
+
useAssistantTool(tool);
|
428
|
+
return null;
|
429
|
+
};
|
430
|
+
return Tool;
|
431
|
+
};
|
432
|
+
|
433
|
+
// src/model-config/useAssistantToolUI.tsx
|
434
|
+
import { useEffect as useEffect4 } from "react";
|
435
|
+
var useAssistantToolUI = (tool) => {
|
436
|
+
const { useToolUIs } = useAssistantContext();
|
437
|
+
const setToolUI = useToolUIs((s) => s.setToolUI);
|
438
|
+
useEffect4(() => {
|
439
|
+
if (!tool) return;
|
440
|
+
const { toolName, render } = tool;
|
441
|
+
return setToolUI(toolName, render);
|
442
|
+
}, [setToolUI, tool]);
|
443
|
+
};
|
444
|
+
|
445
|
+
// src/model-config/makeAssistantToolUI.tsx
|
446
|
+
var makeAssistantToolUI = (tool) => {
|
447
|
+
const ToolUI = () => {
|
448
|
+
useAssistantToolUI(tool);
|
449
|
+
return null;
|
450
|
+
};
|
451
|
+
return ToolUI;
|
452
|
+
};
|
453
|
+
|
454
|
+
// src/model-config/useAssistantInstructions.tsx
|
455
|
+
import { useEffect as useEffect5 } from "react";
|
456
|
+
var useAssistantInstructions = (instruction) => {
|
457
|
+
const { useModelConfig } = useAssistantContext();
|
458
|
+
const registerModelConfigProvider = useModelConfig(
|
459
|
+
(s) => s.registerModelConfigProvider
|
460
|
+
);
|
461
|
+
useEffect5(() => {
|
462
|
+
const config = {
|
463
|
+
system: instruction
|
464
|
+
};
|
465
|
+
return registerModelConfigProvider(() => config);
|
466
|
+
}, [registerModelConfigProvider, instruction]);
|
467
|
+
};
|
13
468
|
|
14
469
|
// src/primitive-hooks/actionBar/useActionBarCopy.tsx
|
15
|
-
import { useCallback } from "react";
|
470
|
+
import { useCallback as useCallback4 } from "react";
|
16
471
|
|
17
472
|
// src/utils/combined/useCombinedStore.ts
|
18
|
-
import { useMemo } from "react";
|
473
|
+
import { useMemo as useMemo2 } from "react";
|
19
474
|
|
20
475
|
// src/utils/combined/createCombinedStore.ts
|
21
|
-
import { useSyncExternalStore } from "react";
|
476
|
+
import { useSyncExternalStore as useSyncExternalStore2 } from "react";
|
22
477
|
var createCombinedStore = (stores) => {
|
23
478
|
const subscribe = (callback) => {
|
24
479
|
const unsubscribes = stores.map((store) => store.subscribe(callback));
|
@@ -30,13 +485,13 @@ var createCombinedStore = (stores) => {
|
|
30
485
|
};
|
31
486
|
return (selector) => {
|
32
487
|
const getSnapshot = () => selector(...stores.map((store) => store.getState()));
|
33
|
-
return
|
488
|
+
return useSyncExternalStore2(subscribe, getSnapshot, getSnapshot);
|
34
489
|
};
|
35
490
|
};
|
36
491
|
|
37
492
|
// src/utils/combined/useCombinedStore.ts
|
38
493
|
var useCombinedStore = (stores, selector) => {
|
39
|
-
const useCombined =
|
494
|
+
const useCombined = useMemo2(() => createCombinedStore(stores), stores);
|
40
495
|
return useCombined(selector);
|
41
496
|
};
|
42
497
|
|
@@ -59,7 +514,7 @@ var useActionBarCopy = ({
|
|
59
514
|
return !c.isEditing && m.message.content.some((c2) => c2.type === "text");
|
60
515
|
}
|
61
516
|
);
|
62
|
-
const callback =
|
517
|
+
const callback = useCallback4(() => {
|
63
518
|
const { message } = useMessage.getState();
|
64
519
|
const { setIsCopied } = useMessageUtils.getState();
|
65
520
|
const { isEditing, value: composerValue } = useEditComposer.getState();
|
@@ -73,14 +528,14 @@ var useActionBarCopy = ({
|
|
73
528
|
};
|
74
529
|
|
75
530
|
// src/primitive-hooks/actionBar/useActionBarEdit.tsx
|
76
|
-
import { useCallback as
|
531
|
+
import { useCallback as useCallback5 } from "react";
|
77
532
|
var useActionBarEdit = () => {
|
78
533
|
const { useMessage, useEditComposer } = useMessageContext();
|
79
534
|
const disabled = useCombinedStore(
|
80
535
|
[useMessage, useEditComposer],
|
81
536
|
(m, c) => m.message.role !== "user" || c.isEditing
|
82
537
|
);
|
83
|
-
const callback =
|
538
|
+
const callback = useCallback5(() => {
|
84
539
|
const { edit } = useEditComposer.getState();
|
85
540
|
edit();
|
86
541
|
}, [useEditComposer]);
|
@@ -89,7 +544,7 @@ var useActionBarEdit = () => {
|
|
89
544
|
};
|
90
545
|
|
91
546
|
// src/primitive-hooks/actionBar/useActionBarReload.tsx
|
92
|
-
import { useCallback as
|
547
|
+
import { useCallback as useCallback6 } from "react";
|
93
548
|
var useActionBarReload = () => {
|
94
549
|
const { useThread, useThreadActions, useComposer, useViewport } = useThreadContext();
|
95
550
|
const { useMessage } = useMessageContext();
|
@@ -97,7 +552,7 @@ var useActionBarReload = () => {
|
|
97
552
|
[useThread, useMessage],
|
98
553
|
(t, m) => t.isRunning || m.message.role !== "assistant"
|
99
554
|
);
|
100
|
-
const callback =
|
555
|
+
const callback = useCallback6(() => {
|
101
556
|
const { parentId } = useMessage.getState();
|
102
557
|
useThreadActions.getState().startRun(parentId);
|
103
558
|
useViewport.getState().scrollToBottom();
|
@@ -115,7 +570,7 @@ var useBranchPickerCount = () => {
|
|
115
570
|
};
|
116
571
|
|
117
572
|
// src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
|
118
|
-
import { useCallback as
|
573
|
+
import { useCallback as useCallback7 } from "react";
|
119
574
|
var useBranchPickerNext = () => {
|
120
575
|
const { useThreadActions } = useThreadContext();
|
121
576
|
const { useMessage, useEditComposer } = useMessageContext();
|
@@ -123,7 +578,7 @@ var useBranchPickerNext = () => {
|
|
123
578
|
[useMessage, useEditComposer],
|
124
579
|
(m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
|
125
580
|
);
|
126
|
-
const callback =
|
581
|
+
const callback = useCallback7(() => {
|
127
582
|
const { message, branches } = useMessage.getState();
|
128
583
|
useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
|
129
584
|
}, [useThreadActions, useMessage]);
|
@@ -139,7 +594,7 @@ var useBranchPickerNumber = () => {
|
|
139
594
|
};
|
140
595
|
|
141
596
|
// src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
|
142
|
-
import { useCallback as
|
597
|
+
import { useCallback as useCallback8 } from "react";
|
143
598
|
var useBranchPickerPrevious = () => {
|
144
599
|
const { useThreadActions } = useThreadContext();
|
145
600
|
const { useMessage, useEditComposer } = useMessageContext();
|
@@ -147,7 +602,7 @@ var useBranchPickerPrevious = () => {
|
|
147
602
|
[useMessage, useEditComposer],
|
148
603
|
(m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
|
149
604
|
);
|
150
|
-
const callback =
|
605
|
+
const callback = useCallback8(() => {
|
151
606
|
const { message, branches } = useMessage.getState();
|
152
607
|
useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
|
153
608
|
}, [useThreadActions, useMessage]);
|
@@ -156,11 +611,11 @@ var useBranchPickerPrevious = () => {
|
|
156
611
|
};
|
157
612
|
|
158
613
|
// src/primitive-hooks/composer/useComposerCancel.tsx
|
159
|
-
import { useCallback as
|
614
|
+
import { useCallback as useCallback9 } from "react";
|
160
615
|
var useComposerCancel = () => {
|
161
616
|
const { useComposer } = useComposerContext();
|
162
617
|
const disabled = useComposer((c) => !c.isEditing);
|
163
|
-
const callback =
|
618
|
+
const callback = useCallback9(() => {
|
164
619
|
const { cancel } = useComposer.getState();
|
165
620
|
cancel();
|
166
621
|
}, [useComposer]);
|
@@ -179,12 +634,12 @@ var useComposerIf = (props) => {
|
|
179
634
|
};
|
180
635
|
|
181
636
|
// src/primitive-hooks/composer/useComposerSend.tsx
|
182
|
-
import { useCallback as
|
637
|
+
import { useCallback as useCallback10 } from "react";
|
183
638
|
var useComposerSend = () => {
|
184
639
|
const { useViewport, useComposer: useNewComposer } = useThreadContext();
|
185
640
|
const { useComposer } = useComposerContext();
|
186
641
|
const disabled = useComposer((c) => !c.isEditing || c.value.length === 0);
|
187
|
-
const callback =
|
642
|
+
const callback = useCallback10(() => {
|
188
643
|
const composerState = useComposer.getState();
|
189
644
|
if (!composerState.isEditing) return;
|
190
645
|
composerState.send();
|
@@ -280,11 +735,11 @@ var useThreadEmpty = () => {
|
|
280
735
|
};
|
281
736
|
|
282
737
|
// src/primitive-hooks/thread/useThreadScrollToBottom.tsx
|
283
|
-
import { useCallback as
|
738
|
+
import { useCallback as useCallback11 } from "react";
|
284
739
|
var useThreadScrollToBottom = () => {
|
285
740
|
const { useComposer, useViewport } = useThreadContext();
|
286
741
|
const isAtBottom = useViewport((s) => s.isAtBottom);
|
287
|
-
const handleScrollToBottom =
|
742
|
+
const handleScrollToBottom = useCallback11(() => {
|
288
743
|
useViewport.getState().scrollToBottom();
|
289
744
|
useComposer.getState().focus();
|
290
745
|
}, [useViewport, useComposer]);
|
@@ -293,14 +748,14 @@ var useThreadScrollToBottom = () => {
|
|
293
748
|
};
|
294
749
|
|
295
750
|
// src/primitive-hooks/thread/useThreadSuggestion.tsx
|
296
|
-
import { useCallback as
|
751
|
+
import { useCallback as useCallback12 } from "react";
|
297
752
|
var useThreadSuggestion = ({
|
298
753
|
prompt,
|
299
754
|
autoSend
|
300
755
|
}) => {
|
301
756
|
const { useThread, useComposer } = useThreadContext();
|
302
757
|
const disabled = useThread((t) => t.isRunning);
|
303
|
-
const callback =
|
758
|
+
const callback = useCallback12(() => {
|
304
759
|
const thread = useThread.getState();
|
305
760
|
const composer = useComposer.getState();
|
306
761
|
composer.setValue(prompt);
|
@@ -315,16 +770,17 @@ var useThreadSuggestion = ({
|
|
315
770
|
// src/primitives/actionBar/index.ts
|
316
771
|
var actionBar_exports = {};
|
317
772
|
__export(actionBar_exports, {
|
318
|
-
Copy: () =>
|
319
|
-
Edit: () =>
|
320
|
-
Reload: () =>
|
321
|
-
Root: () =>
|
773
|
+
Copy: () => ActionBarPrimitiveCopy,
|
774
|
+
Edit: () => ActionBarPrimitiveEdit,
|
775
|
+
Reload: () => ActionBarPrimitiveReload,
|
776
|
+
Root: () => ActionBarPrimitiveRoot
|
322
777
|
});
|
323
778
|
|
324
779
|
// src/primitives/actionBar/ActionBarRoot.tsx
|
325
780
|
import { Primitive } from "@radix-ui/react-primitive";
|
326
781
|
import { forwardRef } from "react";
|
327
|
-
|
782
|
+
|
783
|
+
// src/primitives/actionBar/useActionBarFloatStatus.tsx
|
328
784
|
var useActionBarFloatStatus = ({
|
329
785
|
hideWhenRunning,
|
330
786
|
autohide,
|
@@ -345,14 +801,17 @@ var useActionBarFloatStatus = ({
|
|
345
801
|
}
|
346
802
|
);
|
347
803
|
};
|
348
|
-
|
804
|
+
|
805
|
+
// src/primitives/actionBar/ActionBarRoot.tsx
|
806
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
807
|
+
var ActionBarPrimitiveRoot = forwardRef(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
|
349
808
|
const hideAndfloatStatus = useActionBarFloatStatus({
|
350
809
|
hideWhenRunning,
|
351
810
|
autohide,
|
352
811
|
autohideFloat
|
353
812
|
});
|
354
813
|
if (hideAndfloatStatus === "hidden" /* Hidden */) return null;
|
355
|
-
return /* @__PURE__ */
|
814
|
+
return /* @__PURE__ */ jsx4(
|
356
815
|
Primitive.div,
|
357
816
|
{
|
358
817
|
...hideAndfloatStatus === "floating" /* Floating */ ? { "data-floating": "true" } : null,
|
@@ -361,17 +820,17 @@ var ActionBarRoot = forwardRef(({ hideWhenRunning, autohide, autohideFloat, ...r
|
|
361
820
|
}
|
362
821
|
);
|
363
822
|
});
|
364
|
-
|
823
|
+
ActionBarPrimitiveRoot.displayName = "ActionBarPrimitive.Root";
|
365
824
|
|
366
825
|
// src/utils/createActionButton.tsx
|
367
826
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
368
827
|
import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
|
369
828
|
import { forwardRef as forwardRef2 } from "react";
|
370
|
-
import { jsx as
|
829
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
371
830
|
var createActionButton = (displayName, useActionButton) => {
|
372
831
|
const ActionButton = forwardRef2((props, forwardedRef) => {
|
373
832
|
const callback = useActionButton(props);
|
374
|
-
return /* @__PURE__ */
|
833
|
+
return /* @__PURE__ */ jsx5(
|
375
834
|
Primitive2.button,
|
376
835
|
{
|
377
836
|
type: "button",
|
@@ -389,61 +848,64 @@ var createActionButton = (displayName, useActionButton) => {
|
|
389
848
|
};
|
390
849
|
|
391
850
|
// src/primitives/actionBar/ActionBarCopy.tsx
|
392
|
-
var
|
393
|
-
"
|
851
|
+
var ActionBarPrimitiveCopy = createActionButton(
|
852
|
+
"ActionBarPrimitive.Copy",
|
394
853
|
useActionBarCopy
|
395
854
|
);
|
396
855
|
|
397
856
|
// src/primitives/actionBar/ActionBarReload.tsx
|
398
|
-
var
|
399
|
-
"
|
857
|
+
var ActionBarPrimitiveReload = createActionButton(
|
858
|
+
"ActionBarPrimitive.Reload",
|
400
859
|
useActionBarReload
|
401
860
|
);
|
402
861
|
|
403
862
|
// src/primitives/actionBar/ActionBarEdit.tsx
|
404
|
-
var
|
405
|
-
"
|
863
|
+
var ActionBarPrimitiveEdit = createActionButton(
|
864
|
+
"ActionBarPrimitive.Edit",
|
406
865
|
useActionBarEdit
|
407
866
|
);
|
408
867
|
|
409
868
|
// src/primitives/assistantModal/index.ts
|
410
869
|
var assistantModal_exports = {};
|
411
870
|
__export(assistantModal_exports, {
|
412
|
-
Content: () =>
|
413
|
-
Root: () =>
|
414
|
-
Trigger: () =>
|
871
|
+
Content: () => AssistantModalPrimitiveContent,
|
872
|
+
Root: () => AssistantModalPrimitiveRoot,
|
873
|
+
Trigger: () => AssistantModalPrimitiveTrigger
|
415
874
|
});
|
416
875
|
|
417
876
|
// src/primitives/assistantModal/AssistantModalRoot.tsx
|
418
|
-
import { useState } from "react";
|
419
|
-
import * as
|
877
|
+
import { useState as useState3 } from "react";
|
878
|
+
import * as PopoverPrimitive2 from "@radix-ui/react-popover";
|
420
879
|
import { composeEventHandlers as composeEventHandlers2 } from "@radix-ui/primitive";
|
421
880
|
|
422
881
|
// src/utils/hooks/useOnComposerFocus.tsx
|
423
882
|
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
424
|
-
import { useEffect } from "react";
|
883
|
+
import { useEffect as useEffect6 } from "react";
|
425
884
|
var useOnComposerFocus = (callback) => {
|
426
885
|
const callbackRef = useCallbackRef(callback);
|
427
886
|
const { useComposer } = useThreadContext();
|
428
|
-
|
887
|
+
useEffect6(() => {
|
429
888
|
return useComposer.getState().onFocus(() => {
|
430
889
|
callbackRef();
|
431
890
|
});
|
432
891
|
}, [useComposer, callbackRef]);
|
433
892
|
};
|
434
893
|
|
435
|
-
// src/primitives/assistantModal/
|
436
|
-
import
|
894
|
+
// src/primitives/assistantModal/scope.tsx
|
895
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
437
896
|
var usePopoverScope = PopoverPrimitive.createPopoverScope();
|
897
|
+
|
898
|
+
// src/primitives/assistantModal/AssistantModalRoot.tsx
|
899
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
438
900
|
var useAssistantModalOpenState = (defaultOpen = false) => {
|
439
|
-
const state =
|
901
|
+
const state = useState3(defaultOpen);
|
440
902
|
const [, setOpen] = state;
|
441
903
|
useOnComposerFocus(() => {
|
442
904
|
setOpen(true);
|
443
905
|
});
|
444
906
|
return state;
|
445
907
|
};
|
446
|
-
var
|
908
|
+
var AssistantModalPrimitiveRoot = ({
|
447
909
|
__scopeAssistantModal,
|
448
910
|
defaultOpen,
|
449
911
|
open,
|
@@ -452,8 +914,8 @@ var AssistantModalRoot = ({
|
|
452
914
|
}) => {
|
453
915
|
const scope = usePopoverScope(__scopeAssistantModal);
|
454
916
|
const [modalOpen, setOpen] = useAssistantModalOpenState(defaultOpen);
|
455
|
-
return /* @__PURE__ */
|
456
|
-
|
917
|
+
return /* @__PURE__ */ jsx6(
|
918
|
+
PopoverPrimitive2.Root,
|
457
919
|
{
|
458
920
|
...scope,
|
459
921
|
open: open === void 0 ? modalOpen : open,
|
@@ -462,26 +924,29 @@ var AssistantModalRoot = ({
|
|
462
924
|
}
|
463
925
|
);
|
464
926
|
};
|
465
|
-
|
927
|
+
AssistantModalPrimitiveRoot.displayName = "AssistantModalPrimitive.Root";
|
466
928
|
|
467
929
|
// src/primitives/assistantModal/AssistantModalTrigger.tsx
|
468
930
|
import { forwardRef as forwardRef3 } from "react";
|
469
|
-
import * as
|
470
|
-
import { jsx as
|
471
|
-
var
|
472
|
-
({
|
931
|
+
import * as PopoverPrimitive3 from "@radix-ui/react-popover";
|
932
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
933
|
+
var AssistantModalPrimitiveTrigger = forwardRef3(
|
934
|
+
({
|
935
|
+
__scopeAssistantModal,
|
936
|
+
...rest
|
937
|
+
}, ref) => {
|
473
938
|
const scope = usePopoverScope(__scopeAssistantModal);
|
474
|
-
return /* @__PURE__ */
|
939
|
+
return /* @__PURE__ */ jsx7(PopoverPrimitive3.Trigger, { ...scope, ...rest, ref });
|
475
940
|
}
|
476
941
|
);
|
477
|
-
|
942
|
+
AssistantModalPrimitiveTrigger.displayName = "AssistantModalPrimitive.Trigger";
|
478
943
|
|
479
944
|
// src/primitives/assistantModal/AssistantModalContent.tsx
|
480
945
|
import { forwardRef as forwardRef4 } from "react";
|
481
|
-
import * as
|
946
|
+
import * as PopoverPrimitive4 from "@radix-ui/react-popover";
|
482
947
|
import { composeEventHandlers as composeEventHandlers3 } from "@radix-ui/primitive";
|
483
|
-
import { jsx as
|
484
|
-
var
|
948
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
949
|
+
var AssistantModalPrimitiveContent = forwardRef4(
|
485
950
|
({
|
486
951
|
__scopeAssistantModal,
|
487
952
|
side,
|
@@ -491,8 +956,8 @@ var AssistantModalContent = forwardRef4(
|
|
491
956
|
...props
|
492
957
|
}, forwardedRef) => {
|
493
958
|
const scope = usePopoverScope(__scopeAssistantModal);
|
494
|
-
return /* @__PURE__ */
|
495
|
-
|
959
|
+
return /* @__PURE__ */ jsx8(PopoverPrimitive4.Portal, { ...scope, children: /* @__PURE__ */ jsx8(
|
960
|
+
PopoverPrimitive4.Content,
|
496
961
|
{
|
497
962
|
...scope,
|
498
963
|
...props,
|
@@ -507,43 +972,45 @@ var AssistantModalContent = forwardRef4(
|
|
507
972
|
) });
|
508
973
|
}
|
509
974
|
);
|
510
|
-
|
975
|
+
AssistantModalPrimitiveContent.displayName = "AssistantModalPrimitive.Content";
|
511
976
|
|
512
977
|
// src/primitives/branchPicker/index.ts
|
513
978
|
var branchPicker_exports = {};
|
514
979
|
__export(branchPicker_exports, {
|
515
|
-
Count: () =>
|
516
|
-
Next: () =>
|
517
|
-
Number: () =>
|
980
|
+
Count: () => BranchPickerPrimitiveCount,
|
981
|
+
Next: () => BranchPickerPrimitiveNext,
|
982
|
+
Number: () => BranchPickerPrimitiveNumber,
|
518
983
|
Previous: () => BranchPickerPrevious,
|
519
|
-
Root: () =>
|
984
|
+
Root: () => BranchPickerPrimitiveRoot
|
520
985
|
});
|
521
986
|
|
522
987
|
// src/primitives/branchPicker/BranchPickerNext.tsx
|
523
|
-
var
|
524
|
-
"
|
988
|
+
var BranchPickerPrimitiveNext = createActionButton(
|
989
|
+
"BranchPickerPrimitive.Next",
|
525
990
|
useBranchPickerNext
|
526
991
|
);
|
527
992
|
|
528
993
|
// src/primitives/branchPicker/BranchPickerPrevious.tsx
|
529
994
|
var BranchPickerPrevious = createActionButton(
|
530
|
-
"
|
995
|
+
"BranchPickerPrimitive.Previous",
|
531
996
|
useBranchPickerPrevious
|
532
997
|
);
|
533
998
|
|
534
999
|
// src/primitives/branchPicker/BranchPickerCount.tsx
|
535
|
-
import { Fragment, jsx as
|
536
|
-
var
|
1000
|
+
import { Fragment, jsx as jsx9 } from "react/jsx-runtime";
|
1001
|
+
var BranchPickerPrimitiveCount = () => {
|
537
1002
|
const branchCount = useBranchPickerCount();
|
538
|
-
return /* @__PURE__ */
|
1003
|
+
return /* @__PURE__ */ jsx9(Fragment, { children: branchCount });
|
539
1004
|
};
|
1005
|
+
BranchPickerPrimitiveCount.displayName = "BranchPickerPrimitive.Count";
|
540
1006
|
|
541
1007
|
// src/primitives/branchPicker/BranchPickerNumber.tsx
|
542
|
-
import { Fragment as Fragment2, jsx as
|
543
|
-
var
|
1008
|
+
import { Fragment as Fragment2, jsx as jsx10 } from "react/jsx-runtime";
|
1009
|
+
var BranchPickerPrimitiveNumber = () => {
|
544
1010
|
const branchNumber = useBranchPickerNumber();
|
545
|
-
return /* @__PURE__ */
|
1011
|
+
return /* @__PURE__ */ jsx10(Fragment2, { children: branchNumber });
|
546
1012
|
};
|
1013
|
+
BranchPickerPrimitiveNumber.displayName = "BranchPickerPrimitive.Number";
|
547
1014
|
|
548
1015
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
549
1016
|
import { Primitive as Primitive6 } from "@radix-ui/react-primitive";
|
@@ -552,53 +1019,55 @@ import { forwardRef as forwardRef8 } from "react";
|
|
552
1019
|
// src/primitives/message/index.ts
|
553
1020
|
var message_exports = {};
|
554
1021
|
__export(message_exports, {
|
555
|
-
Content: () =>
|
556
|
-
If: () =>
|
557
|
-
InProgress: () =>
|
558
|
-
Root: () =>
|
1022
|
+
Content: () => MessagePrimitiveContent,
|
1023
|
+
If: () => MessagePrimitiveIf,
|
1024
|
+
InProgress: () => MessagePrimitiveInProgress,
|
1025
|
+
Root: () => MessagePrimitiveRoot
|
559
1026
|
});
|
560
1027
|
|
561
1028
|
// src/primitives/message/MessageRoot.tsx
|
562
1029
|
import { composeEventHandlers as composeEventHandlers4 } from "@radix-ui/primitive";
|
563
1030
|
import { Primitive as Primitive3 } from "@radix-ui/react-primitive";
|
564
1031
|
import { forwardRef as forwardRef5 } from "react";
|
565
|
-
import { jsx as
|
566
|
-
var
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
);
|
587
|
-
MessageRoot.displayName = "MessageRoot";
|
1032
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
1033
|
+
var MessagePrimitiveRoot = forwardRef5(({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
|
1034
|
+
const { useMessageUtils } = useMessageContext();
|
1035
|
+
const setIsHovering = useMessageUtils((s) => s.setIsHovering);
|
1036
|
+
const handleMouseEnter = () => {
|
1037
|
+
setIsHovering(true);
|
1038
|
+
};
|
1039
|
+
const handleMouseLeave = () => {
|
1040
|
+
setIsHovering(false);
|
1041
|
+
};
|
1042
|
+
return /* @__PURE__ */ jsx11(
|
1043
|
+
Primitive3.div,
|
1044
|
+
{
|
1045
|
+
...rest,
|
1046
|
+
ref,
|
1047
|
+
onMouseEnter: composeEventHandlers4(onMouseEnter, handleMouseEnter),
|
1048
|
+
onMouseLeave: composeEventHandlers4(onMouseLeave, handleMouseLeave)
|
1049
|
+
}
|
1050
|
+
);
|
1051
|
+
});
|
1052
|
+
MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
|
588
1053
|
|
589
1054
|
// src/primitives/message/MessageIf.tsx
|
590
|
-
var
|
1055
|
+
var MessagePrimitiveIf = ({
|
1056
|
+
children,
|
1057
|
+
...query
|
1058
|
+
}) => {
|
591
1059
|
const result = useMessageIf(query);
|
592
1060
|
return result ? children : null;
|
593
1061
|
};
|
1062
|
+
MessagePrimitiveIf.displayName = "MessagePrimitive.If";
|
594
1063
|
|
595
1064
|
// src/primitives/message/MessageContent.tsx
|
596
|
-
import { memo } from "react";
|
1065
|
+
import { memo as memo2 } from "react";
|
597
1066
|
|
598
1067
|
// src/context/providers/ContentPartProvider.tsx
|
599
|
-
import { useEffect as
|
600
|
-
import { create } from "zustand";
|
601
|
-
import { jsx as
|
1068
|
+
import { useEffect as useEffect7, useState as useState4 } from "react";
|
1069
|
+
import { create as create8 } from "zustand";
|
1070
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
602
1071
|
var syncContentPart = ({ message }, useContentPart, partIndex) => {
|
603
1072
|
const part = message.content[partIndex];
|
604
1073
|
if (!part) return;
|
@@ -615,14 +1084,14 @@ var syncContentPart = ({ message }, useContentPart, partIndex) => {
|
|
615
1084
|
};
|
616
1085
|
var useContentPartContext2 = (partIndex) => {
|
617
1086
|
const { useMessage } = useMessageContext();
|
618
|
-
const [context] =
|
619
|
-
const useContentPart =
|
1087
|
+
const [context] = useState4(() => {
|
1088
|
+
const useContentPart = create8(
|
620
1089
|
() => ({})
|
621
1090
|
);
|
622
1091
|
syncContentPart(useMessage.getState(), useContentPart, partIndex);
|
623
1092
|
return { useContentPart };
|
624
1093
|
});
|
625
|
-
|
1094
|
+
useEffect7(() => {
|
626
1095
|
syncContentPart(useMessage.getState(), context.useContentPart, partIndex);
|
627
1096
|
return useMessage.subscribe((message) => {
|
628
1097
|
syncContentPart(message, context.useContentPart, partIndex);
|
@@ -635,46 +1104,48 @@ var ContentPartProvider = ({
|
|
635
1104
|
children
|
636
1105
|
}) => {
|
637
1106
|
const context = useContentPartContext2(partIndex);
|
638
|
-
return /* @__PURE__ */
|
1107
|
+
return /* @__PURE__ */ jsx12(ContentPartContext.Provider, { value: context, children });
|
639
1108
|
};
|
640
1109
|
|
641
1110
|
// src/primitives/contentPart/ContentPartDisplay.tsx
|
642
|
-
var
|
1111
|
+
var ContentPartPrimitiveDisplay = () => {
|
643
1112
|
const display = useContentPartDisplay();
|
644
1113
|
return display ?? null;
|
645
1114
|
};
|
1115
|
+
ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
|
646
1116
|
|
647
1117
|
// src/primitives/contentPart/ContentPartInProgressIndicator.tsx
|
648
|
-
var
|
1118
|
+
var ContentPartPrimitiveInProgressIndicator = () => {
|
649
1119
|
const indicator = useContentPartInProgressIndicator();
|
650
1120
|
return indicator;
|
651
1121
|
};
|
1122
|
+
ContentPartPrimitiveInProgressIndicator.displayName = "ContentPartPrimitive.InProgressIndicator";
|
652
1123
|
|
653
1124
|
// src/primitives/contentPart/ContentPartText.tsx
|
654
1125
|
import { Primitive as Primitive4 } from "@radix-ui/react-primitive";
|
655
1126
|
import { forwardRef as forwardRef6 } from "react";
|
656
|
-
import { jsx as
|
657
|
-
var
|
1127
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
1128
|
+
var ContentPartPrimitiveText = forwardRef6((props, forwardedRef) => {
|
658
1129
|
const text = useContentPartText();
|
659
|
-
return /* @__PURE__ */
|
1130
|
+
return /* @__PURE__ */ jsx13(Primitive4.p, { ...props, ref: forwardedRef, children: text });
|
660
1131
|
});
|
661
|
-
|
1132
|
+
ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
|
662
1133
|
|
663
1134
|
// src/primitives/message/MessageContent.tsx
|
664
|
-
import { Fragment as Fragment3, jsx as
|
1135
|
+
import { Fragment as Fragment3, jsx as jsx14, jsxs as jsxs2 } from "react/jsx-runtime";
|
665
1136
|
var defaultComponents = {
|
666
|
-
Text: () => /* @__PURE__ */
|
667
|
-
/* @__PURE__ */
|
668
|
-
/* @__PURE__ */
|
1137
|
+
Text: () => /* @__PURE__ */ jsxs2(Fragment3, { children: [
|
1138
|
+
/* @__PURE__ */ jsx14(ContentPartPrimitiveText, { style: { whiteSpace: "pre-line" } }),
|
1139
|
+
/* @__PURE__ */ jsx14(ContentPartPrimitiveInProgressIndicator, {})
|
669
1140
|
] }),
|
670
1141
|
Image: () => null,
|
671
|
-
UI: () => /* @__PURE__ */
|
1142
|
+
UI: () => /* @__PURE__ */ jsx14(ContentPartPrimitiveDisplay, {}),
|
672
1143
|
tools: {
|
673
1144
|
Fallback: (props) => {
|
674
1145
|
const { useToolUIs } = useAssistantContext();
|
675
1146
|
const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));
|
676
1147
|
if (!Render) return null;
|
677
|
-
return /* @__PURE__ */
|
1148
|
+
return /* @__PURE__ */ jsx14(Render, { ...props });
|
678
1149
|
}
|
679
1150
|
}
|
680
1151
|
};
|
@@ -693,15 +1164,15 @@ var MessageContentPartComponent = ({
|
|
693
1164
|
const type = part.type;
|
694
1165
|
switch (type) {
|
695
1166
|
case "text":
|
696
|
-
return /* @__PURE__ */
|
1167
|
+
return /* @__PURE__ */ jsx14(Text, { part, status });
|
697
1168
|
case "image":
|
698
|
-
return /* @__PURE__ */
|
1169
|
+
return /* @__PURE__ */ jsx14(Image, { part, status });
|
699
1170
|
case "ui":
|
700
|
-
return /* @__PURE__ */
|
1171
|
+
return /* @__PURE__ */ jsx14(UI, { part, status });
|
701
1172
|
case "tool-call": {
|
702
1173
|
const Tool = by_name[part.toolName] || Fallback;
|
703
1174
|
const addResult = (result) => addToolResult(part.toolCallId, result);
|
704
|
-
return /* @__PURE__ */
|
1175
|
+
return /* @__PURE__ */ jsx14(Tool, { part, status, addResult });
|
705
1176
|
}
|
706
1177
|
default:
|
707
1178
|
throw new Error(`Unknown content part type: ${type}`);
|
@@ -711,18 +1182,20 @@ var MessageContentPartImpl = ({
|
|
711
1182
|
partIndex,
|
712
1183
|
components
|
713
1184
|
}) => {
|
714
|
-
return /* @__PURE__ */
|
1185
|
+
return /* @__PURE__ */ jsx14(ContentPartProvider, { partIndex, children: /* @__PURE__ */ jsx14(MessageContentPartComponent, { components }) });
|
715
1186
|
};
|
716
|
-
var MessageContentPart =
|
1187
|
+
var MessageContentPart = memo2(
|
717
1188
|
MessageContentPartImpl,
|
718
1189
|
(prev, next) => prev.partIndex === next.partIndex && prev.components?.Text === next.components?.Text && prev.components?.Image === next.components?.Image && prev.components?.UI === next.components?.UI && prev.components?.tools === next.components?.tools
|
719
1190
|
);
|
720
|
-
var
|
1191
|
+
var MessagePrimitiveContent = ({
|
1192
|
+
components
|
1193
|
+
}) => {
|
721
1194
|
const { useMessage } = useMessageContext();
|
722
1195
|
const contentLength = useMessage((s) => s.message.content.length);
|
723
1196
|
return new Array(contentLength).fill(null).map((_, idx) => {
|
724
1197
|
const partIndex = idx;
|
725
|
-
return /* @__PURE__ */
|
1198
|
+
return /* @__PURE__ */ jsx14(
|
726
1199
|
MessageContentPart,
|
727
1200
|
{
|
728
1201
|
partIndex,
|
@@ -732,38 +1205,42 @@ var MessageContent = ({ components }) => {
|
|
732
1205
|
);
|
733
1206
|
});
|
734
1207
|
};
|
1208
|
+
MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
|
735
1209
|
|
736
1210
|
// src/primitives/message/MessageInProgress.tsx
|
737
1211
|
import { Primitive as Primitive5 } from "@radix-ui/react-primitive";
|
738
1212
|
import {
|
739
1213
|
forwardRef as forwardRef7,
|
740
|
-
|
1214
|
+
useEffect as useEffect8
|
741
1215
|
} from "react";
|
742
|
-
import { jsx as
|
743
|
-
var
|
1216
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
1217
|
+
var MessagePrimitiveInProgress = forwardRef7((props, ref) => {
|
744
1218
|
const { useMessageUtils } = useMessageContext();
|
745
|
-
|
746
|
-
useMessageUtils.getState().setInProgressIndicator(/* @__PURE__ */
|
1219
|
+
useEffect8(() => {
|
1220
|
+
useMessageUtils.getState().setInProgressIndicator(/* @__PURE__ */ jsx15(Primitive5.span, { ...props, ref }));
|
1221
|
+
return () => {
|
1222
|
+
useMessageUtils.getState().setInProgressIndicator(null);
|
1223
|
+
};
|
747
1224
|
}, [useMessageUtils, props, ref]);
|
748
1225
|
return null;
|
749
1226
|
});
|
750
|
-
|
1227
|
+
MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
|
751
1228
|
|
752
1229
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
753
|
-
import { jsx as
|
754
|
-
var
|
755
|
-
return /* @__PURE__ */
|
1230
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
1231
|
+
var BranchPickerPrimitiveRoot = forwardRef8(({ hideWhenSingleBranch, ...rest }, ref) => {
|
1232
|
+
return /* @__PURE__ */ jsx16(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ jsx16(Primitive6.div, { ...rest, ref }) });
|
756
1233
|
});
|
757
|
-
|
1234
|
+
BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
|
758
1235
|
|
759
1236
|
// src/primitives/composer/index.ts
|
760
1237
|
var composer_exports = {};
|
761
1238
|
__export(composer_exports, {
|
762
|
-
Cancel: () =>
|
763
|
-
If: () =>
|
764
|
-
Input: () =>
|
765
|
-
Root: () =>
|
766
|
-
Send: () =>
|
1239
|
+
Cancel: () => ComposerPrimitiveCancel,
|
1240
|
+
If: () => ComposerPrimitiveIf,
|
1241
|
+
Input: () => ComposerPrimitiveInput,
|
1242
|
+
Root: () => ComposerPrimitiveRoot,
|
1243
|
+
Send: () => ComposerPrimitiveSend
|
767
1244
|
});
|
768
1245
|
|
769
1246
|
// src/primitives/composer/ComposerRoot.tsx
|
@@ -772,26 +1249,24 @@ import { Primitive as Primitive7 } from "@radix-ui/react-primitive";
|
|
772
1249
|
import {
|
773
1250
|
forwardRef as forwardRef9
|
774
1251
|
} from "react";
|
775
|
-
import { jsx as
|
776
|
-
var
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
);
|
794
|
-
ComposerRoot.displayName = "ComposerRoot";
|
1252
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
1253
|
+
var ComposerPrimitiveRoot = forwardRef9(({ onSubmit, ...rest }, forwardedRef) => {
|
1254
|
+
const send = useComposerSend();
|
1255
|
+
const handleSubmit = (e) => {
|
1256
|
+
e.preventDefault();
|
1257
|
+
if (!send) return;
|
1258
|
+
send();
|
1259
|
+
};
|
1260
|
+
return /* @__PURE__ */ jsx17(
|
1261
|
+
Primitive7.form,
|
1262
|
+
{
|
1263
|
+
...rest,
|
1264
|
+
ref: forwardedRef,
|
1265
|
+
onSubmit: composeEventHandlers5(onSubmit, handleSubmit)
|
1266
|
+
}
|
1267
|
+
);
|
1268
|
+
});
|
1269
|
+
ComposerPrimitiveRoot.displayName = "ComposerPrimitive.Root";
|
795
1270
|
|
796
1271
|
// src/primitives/composer/ComposerInput.tsx
|
797
1272
|
import { composeEventHandlers as composeEventHandlers6 } from "@radix-ui/primitive";
|
@@ -799,14 +1274,14 @@ import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
799
1274
|
import { Slot } from "@radix-ui/react-slot";
|
800
1275
|
import {
|
801
1276
|
forwardRef as forwardRef10,
|
802
|
-
useCallback as
|
803
|
-
useEffect as
|
804
|
-
useRef
|
1277
|
+
useCallback as useCallback13,
|
1278
|
+
useEffect as useEffect9,
|
1279
|
+
useRef as useRef3
|
805
1280
|
} from "react";
|
806
1281
|
import TextareaAutosize from "react-textarea-autosize";
|
807
1282
|
import { useEscapeKeydown } from "@radix-ui/react-use-escape-keydown";
|
808
|
-
import { jsx as
|
809
|
-
var
|
1283
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
1284
|
+
var ComposerPrimitiveInput = forwardRef10(
|
810
1285
|
({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
|
811
1286
|
const { useThread } = useThreadContext();
|
812
1287
|
const { useComposer, type } = useComposerContext();
|
@@ -815,7 +1290,7 @@ var ComposerInput = forwardRef10(
|
|
815
1290
|
return c.value;
|
816
1291
|
});
|
817
1292
|
const Component = asChild ? Slot : TextareaAutosize;
|
818
|
-
const textareaRef =
|
1293
|
+
const textareaRef = useRef3(null);
|
819
1294
|
const ref = useComposedRefs(forwardedRef, textareaRef);
|
820
1295
|
useEscapeKeydown((e) => {
|
821
1296
|
const composer = useComposer.getState();
|
@@ -834,7 +1309,7 @@ var ComposerInput = forwardRef10(
|
|
834
1309
|
}
|
835
1310
|
};
|
836
1311
|
const autoFocusEnabled = autoFocus && !disabled;
|
837
|
-
const focus =
|
1312
|
+
const focus = useCallback13(() => {
|
838
1313
|
const textarea = textareaRef.current;
|
839
1314
|
if (!textarea || !autoFocusEnabled) return;
|
840
1315
|
textarea.focus({ preventScroll: true });
|
@@ -843,13 +1318,13 @@ var ComposerInput = forwardRef10(
|
|
843
1318
|
textareaRef.current.value.length
|
844
1319
|
);
|
845
1320
|
}, [autoFocusEnabled]);
|
846
|
-
|
1321
|
+
useEffect9(() => focus(), [focus]);
|
847
1322
|
useOnComposerFocus(() => {
|
848
1323
|
if (type === "new") {
|
849
1324
|
focus();
|
850
1325
|
}
|
851
1326
|
});
|
852
|
-
return /* @__PURE__ */
|
1327
|
+
return /* @__PURE__ */ jsx18(
|
853
1328
|
Component,
|
854
1329
|
{
|
855
1330
|
value,
|
@@ -866,94 +1341,101 @@ var ComposerInput = forwardRef10(
|
|
866
1341
|
);
|
867
1342
|
}
|
868
1343
|
);
|
869
|
-
|
1344
|
+
ComposerPrimitiveInput.displayName = "ComposerPrimitive.Input";
|
870
1345
|
|
871
1346
|
// src/primitives/composer/ComposerSend.tsx
|
872
1347
|
import { forwardRef as forwardRef11 } from "react";
|
873
1348
|
import { Primitive as Primitive8 } from "@radix-ui/react-primitive";
|
874
|
-
import { jsx as
|
875
|
-
var
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
);
|
890
|
-
ComposerSend.displayName = "ComposerSend";
|
1349
|
+
import { jsx as jsx19 } from "react/jsx-runtime";
|
1350
|
+
var ComposerPrimitiveSend = forwardRef11(({ disabled, ...rest }, ref) => {
|
1351
|
+
const { useComposer } = useComposerContext();
|
1352
|
+
const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
|
1353
|
+
return /* @__PURE__ */ jsx19(
|
1354
|
+
Primitive8.button,
|
1355
|
+
{
|
1356
|
+
type: "submit",
|
1357
|
+
...rest,
|
1358
|
+
ref,
|
1359
|
+
disabled: disabled || !hasValue
|
1360
|
+
}
|
1361
|
+
);
|
1362
|
+
});
|
1363
|
+
ComposerPrimitiveSend.displayName = "ComposerPrimitive.Send";
|
891
1364
|
|
892
1365
|
// src/primitives/composer/ComposerCancel.tsx
|
893
|
-
var
|
894
|
-
"
|
1366
|
+
var ComposerPrimitiveCancel = createActionButton(
|
1367
|
+
"ComposerPrimitive.Cancel",
|
895
1368
|
useComposerCancel
|
896
1369
|
);
|
897
1370
|
|
898
1371
|
// src/primitives/composer/ComposerIf.tsx
|
899
|
-
var
|
1372
|
+
var ComposerPrimitiveIf = ({
|
1373
|
+
children,
|
1374
|
+
...query
|
1375
|
+
}) => {
|
900
1376
|
const result = useComposerIf(query);
|
901
1377
|
return result ? children : null;
|
902
1378
|
};
|
1379
|
+
ComposerPrimitiveIf.displayName = "ComposerPrimitive.If";
|
903
1380
|
|
904
1381
|
// src/primitives/contentPart/index.ts
|
905
1382
|
var contentPart_exports = {};
|
906
1383
|
__export(contentPart_exports, {
|
907
|
-
Display: () =>
|
908
|
-
Image: () =>
|
909
|
-
InProgressIndicator: () =>
|
910
|
-
Text: () =>
|
1384
|
+
Display: () => ContentPartPrimitiveDisplay,
|
1385
|
+
Image: () => ContentPartPrimitiveImage,
|
1386
|
+
InProgressIndicator: () => ContentPartPrimitiveInProgressIndicator,
|
1387
|
+
Text: () => ContentPartPrimitiveText
|
911
1388
|
});
|
912
1389
|
|
913
1390
|
// src/primitives/contentPart/ContentPartImage.tsx
|
914
1391
|
import { Primitive as Primitive9 } from "@radix-ui/react-primitive";
|
915
1392
|
import { forwardRef as forwardRef12 } from "react";
|
916
|
-
import { jsx as
|
917
|
-
var
|
1393
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
1394
|
+
var ContentPartPrimitiveImage = forwardRef12((props, forwardedRef) => {
|
918
1395
|
const image = useContentPartImage();
|
919
|
-
return /* @__PURE__ */
|
1396
|
+
return /* @__PURE__ */ jsx20(Primitive9.img, { src: image, ...props, ref: forwardedRef });
|
920
1397
|
});
|
921
|
-
|
1398
|
+
ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
|
922
1399
|
|
923
1400
|
// src/primitives/thread/index.ts
|
924
1401
|
var thread_exports = {};
|
925
1402
|
__export(thread_exports, {
|
926
|
-
Empty: () =>
|
927
|
-
If: () =>
|
928
|
-
Messages: () =>
|
929
|
-
Root: () =>
|
930
|
-
ScrollToBottom: () =>
|
931
|
-
Suggestion: () =>
|
932
|
-
Viewport: () =>
|
1403
|
+
Empty: () => ThreadPrimitiveEmpty,
|
1404
|
+
If: () => ThreadPrimitiveIf,
|
1405
|
+
Messages: () => ThreadPrimitiveMessages,
|
1406
|
+
Root: () => ThreadPrimitiveRoot,
|
1407
|
+
ScrollToBottom: () => ThreadPrimitiveScrollToBottom,
|
1408
|
+
Suggestion: () => ThreadPrimitiveSuggestion,
|
1409
|
+
Viewport: () => ThreadPrimitiveViewport
|
933
1410
|
});
|
934
1411
|
|
935
1412
|
// src/primitives/thread/ThreadRoot.tsx
|
936
1413
|
import { Primitive as Primitive10 } from "@radix-ui/react-primitive";
|
937
1414
|
import { forwardRef as forwardRef13 } from "react";
|
938
|
-
import { jsx as
|
939
|
-
var
|
940
|
-
(props, ref)
|
941
|
-
|
942
|
-
|
943
|
-
);
|
944
|
-
ThreadRoot.displayName = "ThreadRoot";
|
1415
|
+
import { jsx as jsx21 } from "react/jsx-runtime";
|
1416
|
+
var ThreadPrimitiveRoot = forwardRef13((props, ref) => {
|
1417
|
+
return /* @__PURE__ */ jsx21(Primitive10.div, { ...props, ref });
|
1418
|
+
});
|
1419
|
+
ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
|
945
1420
|
|
946
1421
|
// src/primitives/thread/ThreadEmpty.tsx
|
947
|
-
var
|
1422
|
+
var ThreadPrimitiveEmpty = ({
|
1423
|
+
children
|
1424
|
+
}) => {
|
948
1425
|
const empty = useThreadEmpty();
|
949
1426
|
return empty ? children : null;
|
950
1427
|
};
|
1428
|
+
ThreadPrimitiveEmpty.displayName = "ThreadPrimitive.Empty";
|
951
1429
|
|
952
1430
|
// src/primitives/thread/ThreadIf.tsx
|
953
|
-
var
|
1431
|
+
var ThreadPrimitiveIf = ({
|
1432
|
+
children,
|
1433
|
+
...query
|
1434
|
+
}) => {
|
954
1435
|
const result = useThreadIf(query);
|
955
1436
|
return result ? children : null;
|
956
1437
|
};
|
1438
|
+
ThreadPrimitiveIf.displayName = "ThreadPrimitive.If";
|
957
1439
|
|
958
1440
|
// src/primitives/thread/ThreadViewport.tsx
|
959
1441
|
import { useComposedRefs as useComposedRefs3 } from "@radix-ui/react-compose-refs";
|
@@ -962,17 +1444,17 @@ import { forwardRef as forwardRef14 } from "react";
|
|
962
1444
|
|
963
1445
|
// src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
|
964
1446
|
import { useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
|
965
|
-
import { useRef as
|
1447
|
+
import { useRef as useRef5 } from "react";
|
966
1448
|
|
967
1449
|
// src/utils/hooks/useOnResizeContent.tsx
|
968
1450
|
import { useCallbackRef as useCallbackRef2 } from "@radix-ui/react-use-callback-ref";
|
969
|
-
import { useCallback as
|
1451
|
+
import { useCallback as useCallback15 } from "react";
|
970
1452
|
|
971
1453
|
// src/utils/hooks/useManagedRef.ts
|
972
|
-
import { useCallback as
|
1454
|
+
import { useCallback as useCallback14, useRef as useRef4 } from "react";
|
973
1455
|
var useManagedRef = (callback) => {
|
974
|
-
const cleanupRef =
|
975
|
-
const ref =
|
1456
|
+
const cleanupRef = useRef4();
|
1457
|
+
const ref = useCallback14(
|
976
1458
|
(el) => {
|
977
1459
|
if (cleanupRef.current) {
|
978
1460
|
cleanupRef.current();
|
@@ -989,7 +1471,7 @@ var useManagedRef = (callback) => {
|
|
989
1471
|
// src/utils/hooks/useOnResizeContent.tsx
|
990
1472
|
var useOnResizeContent = (callback) => {
|
991
1473
|
const callbackRef = useCallbackRef2(callback);
|
992
|
-
const refCallback =
|
1474
|
+
const refCallback = useCallback15(
|
993
1475
|
(el) => {
|
994
1476
|
const resizeObserver = new ResizeObserver(() => {
|
995
1477
|
callbackRef();
|
@@ -1026,11 +1508,11 @@ var useOnResizeContent = (callback) => {
|
|
1026
1508
|
|
1027
1509
|
// src/utils/hooks/useOnScrollToBottom.tsx
|
1028
1510
|
import { useCallbackRef as useCallbackRef3 } from "@radix-ui/react-use-callback-ref";
|
1029
|
-
import { useEffect as
|
1511
|
+
import { useEffect as useEffect10 } from "react";
|
1030
1512
|
var useOnScrollToBottom = (callback) => {
|
1031
1513
|
const callbackRef = useCallbackRef3(callback);
|
1032
1514
|
const { useViewport } = useThreadContext();
|
1033
|
-
|
1515
|
+
useEffect10(() => {
|
1034
1516
|
return useViewport.getState().onScrollToBottom(() => {
|
1035
1517
|
callbackRef();
|
1036
1518
|
});
|
@@ -1041,11 +1523,11 @@ var useOnScrollToBottom = (callback) => {
|
|
1041
1523
|
var useThreadViewportAutoScroll = ({
|
1042
1524
|
autoScroll = true
|
1043
1525
|
}) => {
|
1044
|
-
const divRef =
|
1526
|
+
const divRef = useRef5(null);
|
1045
1527
|
const { useViewport } = useThreadContext();
|
1046
|
-
const firstRenderRef =
|
1047
|
-
const lastScrollTop =
|
1048
|
-
const isScrollingToBottomRef =
|
1528
|
+
const firstRenderRef = useRef5(true);
|
1529
|
+
const lastScrollTop = useRef5(0);
|
1530
|
+
const isScrollingToBottomRef = useRef5(false);
|
1049
1531
|
const scrollToBottom = () => {
|
1050
1532
|
const div = divRef.current;
|
1051
1533
|
if (!div || !autoScroll) return;
|
@@ -1091,39 +1573,29 @@ var useThreadViewportAutoScroll = ({
|
|
1091
1573
|
};
|
1092
1574
|
|
1093
1575
|
// src/primitives/thread/ThreadViewport.tsx
|
1094
|
-
import { jsx as
|
1095
|
-
var
|
1576
|
+
import { jsx as jsx22 } from "react/jsx-runtime";
|
1577
|
+
var ThreadPrimitiveViewport = forwardRef14(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
|
1096
1578
|
const autoScrollRef = useThreadViewportAutoScroll({
|
1097
1579
|
autoScroll
|
1098
1580
|
});
|
1099
1581
|
const ref = useComposedRefs3(forwardedRef, autoScrollRef);
|
1100
|
-
return /* @__PURE__ */
|
1582
|
+
return /* @__PURE__ */ jsx22(Primitive11.div, { ...rest, ref, children });
|
1101
1583
|
});
|
1102
|
-
|
1584
|
+
ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
1103
1585
|
|
1104
1586
|
// src/primitives/thread/ThreadMessages.tsx
|
1105
|
-
import { memo as
|
1587
|
+
import { memo as memo3 } from "react";
|
1106
1588
|
|
1107
1589
|
// src/context/providers/MessageProvider.tsx
|
1108
|
-
import { useEffect as
|
1109
|
-
import { create as
|
1110
|
-
|
1111
|
-
// src/context/stores/EditComposer.ts
|
1112
|
-
import { create as create2 } from "zustand";
|
1113
|
-
|
1114
|
-
// src/context/stores/BaseComposer.ts
|
1115
|
-
var makeBaseComposer = (set) => ({
|
1116
|
-
value: "",
|
1117
|
-
setValue: (value) => {
|
1118
|
-
set({ value });
|
1119
|
-
}
|
1120
|
-
});
|
1590
|
+
import { useEffect as useEffect11, useState as useState5 } from "react";
|
1591
|
+
import { create as create11 } from "zustand";
|
1121
1592
|
|
1122
1593
|
// src/context/stores/EditComposer.ts
|
1594
|
+
import { create as create9 } from "zustand";
|
1123
1595
|
var makeEditComposerStore = ({
|
1124
1596
|
onEdit,
|
1125
1597
|
onSend
|
1126
|
-
}) =>
|
1598
|
+
}) => create9()((set, get, store) => ({
|
1127
1599
|
...makeBaseComposer(set, get, store),
|
1128
1600
|
isEditing: false,
|
1129
1601
|
edit: () => {
|
@@ -1143,8 +1615,8 @@ var makeEditComposerStore = ({
|
|
1143
1615
|
}));
|
1144
1616
|
|
1145
1617
|
// src/context/stores/MessageUtils.ts
|
1146
|
-
import { create as
|
1147
|
-
var makeMessageUtilsStore = () =>
|
1618
|
+
import { create as create10 } from "zustand";
|
1619
|
+
var makeMessageUtilsStore = () => create10((set) => ({
|
1148
1620
|
inProgressIndicator: null,
|
1149
1621
|
setInProgressIndicator: (value) => {
|
1150
1622
|
set({ inProgressIndicator: value });
|
@@ -1160,7 +1632,7 @@ var makeMessageUtilsStore = () => create3((set) => ({
|
|
1160
1632
|
}));
|
1161
1633
|
|
1162
1634
|
// src/context/providers/MessageProvider.tsx
|
1163
|
-
import { jsx as
|
1635
|
+
import { jsx as jsx23 } from "react/jsx-runtime";
|
1164
1636
|
var getIsLast = (thread, message) => {
|
1165
1637
|
return thread.messages[thread.messages.length - 1]?.id === message.id;
|
1166
1638
|
};
|
@@ -1182,8 +1654,8 @@ var syncMessage = (thread, getBranches, useMessage, messageIndex) => {
|
|
1182
1654
|
};
|
1183
1655
|
var useMessageContext2 = (messageIndex) => {
|
1184
1656
|
const { useThread, useThreadActions } = useThreadContext();
|
1185
|
-
const [context] =
|
1186
|
-
const useMessage =
|
1657
|
+
const [context] = useState5(() => {
|
1658
|
+
const useMessage = create11(() => ({}));
|
1187
1659
|
const useMessageUtils = makeMessageUtilsStore();
|
1188
1660
|
const useEditComposer = makeEditComposerStore({
|
1189
1661
|
onEdit: () => {
|
@@ -1219,7 +1691,7 @@ var useMessageContext2 = (messageIndex) => {
|
|
1219
1691
|
);
|
1220
1692
|
return { useMessage, useMessageUtils, useEditComposer };
|
1221
1693
|
});
|
1222
|
-
|
1694
|
+
useEffect11(() => {
|
1223
1695
|
return useThread.subscribe((thread) => {
|
1224
1696
|
syncMessage(
|
1225
1697
|
thread,
|
@@ -1236,11 +1708,11 @@ var MessageProvider = ({
|
|
1236
1708
|
children
|
1237
1709
|
}) => {
|
1238
1710
|
const context = useMessageContext2(messageIndex);
|
1239
|
-
return /* @__PURE__ */
|
1711
|
+
return /* @__PURE__ */ jsx23(MessageContext.Provider, { value: context, children });
|
1240
1712
|
};
|
1241
1713
|
|
1242
1714
|
// src/primitives/thread/ThreadMessages.tsx
|
1243
|
-
import { jsx as
|
1715
|
+
import { jsx as jsx24, jsxs as jsxs3 } from "react/jsx-runtime";
|
1244
1716
|
var getComponents = (components) => {
|
1245
1717
|
return {
|
1246
1718
|
EditComposer: components.EditComposer ?? components.UserMessage ?? components.Message,
|
@@ -1253,25 +1725,27 @@ var ThreadMessageImpl = ({
|
|
1253
1725
|
components
|
1254
1726
|
}) => {
|
1255
1727
|
const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
|
1256
|
-
return /* @__PURE__ */
|
1257
|
-
/* @__PURE__ */
|
1258
|
-
/* @__PURE__ */
|
1259
|
-
/* @__PURE__ */
|
1728
|
+
return /* @__PURE__ */ jsxs3(MessageProvider, { messageIndex, children: [
|
1729
|
+
/* @__PURE__ */ jsxs3(MessagePrimitiveIf, { user: true, children: [
|
1730
|
+
/* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ jsx24(UserMessage, {}) }),
|
1731
|
+
/* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ jsx24(EditComposer, {}) })
|
1260
1732
|
] }),
|
1261
|
-
/* @__PURE__ */
|
1733
|
+
/* @__PURE__ */ jsx24(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ jsx24(AssistantMessage, {}) })
|
1262
1734
|
] });
|
1263
1735
|
};
|
1264
|
-
var ThreadMessage =
|
1736
|
+
var ThreadMessage = memo3(
|
1265
1737
|
ThreadMessageImpl,
|
1266
1738
|
(prev, next) => prev.messageIndex === next.messageIndex && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
|
1267
1739
|
);
|
1268
|
-
var
|
1740
|
+
var ThreadPrimitiveMessages = ({
|
1741
|
+
components
|
1742
|
+
}) => {
|
1269
1743
|
const { useThread } = useThreadContext();
|
1270
1744
|
const messagesLength = useThread((t) => t.messages.length);
|
1271
1745
|
if (messagesLength === 0) return null;
|
1272
1746
|
return new Array(messagesLength).fill(null).map((_, idx) => {
|
1273
1747
|
const messageIndex = idx;
|
1274
|
-
return /* @__PURE__ */
|
1748
|
+
return /* @__PURE__ */ jsx24(
|
1275
1749
|
ThreadMessage,
|
1276
1750
|
{
|
1277
1751
|
messageIndex,
|
@@ -1281,49 +1755,22 @@ var ThreadMessages = ({ components }) => {
|
|
1281
1755
|
);
|
1282
1756
|
});
|
1283
1757
|
};
|
1758
|
+
ThreadPrimitiveMessages.displayName = "ThreadPrimitive.Messages";
|
1284
1759
|
|
1285
|
-
// src/primitives/thread/ThreadScrollToBottom.tsx
|
1286
|
-
var
|
1287
|
-
"
|
1288
|
-
useThreadScrollToBottom
|
1289
|
-
);
|
1290
|
-
|
1291
|
-
// src/primitives/thread/ThreadSuggestion.tsx
|
1292
|
-
var
|
1293
|
-
"
|
1294
|
-
useThreadSuggestion
|
1295
|
-
);
|
1296
|
-
|
1297
|
-
// src/runtime/local/useLocalRuntime.tsx
|
1298
|
-
import { useInsertionEffect, useState as
|
1299
|
-
|
1300
|
-
// src/utils/ModelConfigTypes.ts
|
1301
|
-
var mergeModelConfigs = (configSet) => {
|
1302
|
-
const configs = Array.from(configSet).map((c) => c()).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
1303
|
-
return configs.reduce((acc, config) => {
|
1304
|
-
if (config.system) {
|
1305
|
-
if (acc.system) {
|
1306
|
-
acc.system += `
|
1307
|
-
|
1308
|
-
${config.system}`;
|
1309
|
-
} else {
|
1310
|
-
acc.system = config.system;
|
1311
|
-
}
|
1312
|
-
}
|
1313
|
-
if (config.tools) {
|
1314
|
-
for (const [name, tool] of Object.entries(config.tools)) {
|
1315
|
-
if (acc.tools?.[name]) {
|
1316
|
-
throw new Error(
|
1317
|
-
`You tried to define a tool with the name ${name}, but it already exists.`
|
1318
|
-
);
|
1319
|
-
}
|
1320
|
-
if (!acc.tools) acc.tools = {};
|
1321
|
-
acc.tools[name] = tool;
|
1322
|
-
}
|
1323
|
-
}
|
1324
|
-
return acc;
|
1325
|
-
}, {});
|
1326
|
-
};
|
1760
|
+
// src/primitives/thread/ThreadScrollToBottom.tsx
|
1761
|
+
var ThreadPrimitiveScrollToBottom = createActionButton(
|
1762
|
+
"ThreadPrimitive.ScrollToBottom",
|
1763
|
+
useThreadScrollToBottom
|
1764
|
+
);
|
1765
|
+
|
1766
|
+
// src/primitives/thread/ThreadSuggestion.tsx
|
1767
|
+
var ThreadPrimitiveSuggestion = createActionButton(
|
1768
|
+
"ThreadPrimitive.Suggestion",
|
1769
|
+
useThreadSuggestion
|
1770
|
+
);
|
1771
|
+
|
1772
|
+
// src/runtime/local/useLocalRuntime.tsx
|
1773
|
+
import { useInsertionEffect as useInsertionEffect3, useState as useState6 } from "react";
|
1327
1774
|
|
1328
1775
|
// src/runtime/utils/idUtils.tsx
|
1329
1776
|
import { customAlphabet } from "nanoid/non-secure";
|
@@ -1485,13 +1932,91 @@ var MessageRepository = class {
|
|
1485
1932
|
}
|
1486
1933
|
};
|
1487
1934
|
|
1935
|
+
// src/runtime/core/BaseAssistantRuntime.tsx
|
1936
|
+
var BaseAssistantRuntime = class {
|
1937
|
+
constructor(_thread) {
|
1938
|
+
this._thread = _thread;
|
1939
|
+
this._thread = _thread;
|
1940
|
+
this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
|
1941
|
+
}
|
1942
|
+
_unsubscribe;
|
1943
|
+
get thread() {
|
1944
|
+
return this._thread;
|
1945
|
+
}
|
1946
|
+
set thread(thread) {
|
1947
|
+
this._unsubscribe();
|
1948
|
+
this._thread = thread;
|
1949
|
+
this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
|
1950
|
+
this.subscriptionHandler();
|
1951
|
+
}
|
1952
|
+
get messages() {
|
1953
|
+
return this.thread.messages;
|
1954
|
+
}
|
1955
|
+
get isRunning() {
|
1956
|
+
return this.thread.isRunning;
|
1957
|
+
}
|
1958
|
+
getBranches(messageId) {
|
1959
|
+
return this.thread.getBranches(messageId);
|
1960
|
+
}
|
1961
|
+
switchToBranch(branchId) {
|
1962
|
+
return this.thread.switchToBranch(branchId);
|
1963
|
+
}
|
1964
|
+
append(message) {
|
1965
|
+
return this.thread.append(message);
|
1966
|
+
}
|
1967
|
+
startRun(parentId) {
|
1968
|
+
return this.thread.startRun(parentId);
|
1969
|
+
}
|
1970
|
+
cancelRun() {
|
1971
|
+
return this.thread.cancelRun();
|
1972
|
+
}
|
1973
|
+
addToolResult(toolCallId, result) {
|
1974
|
+
return this.thread.addToolResult(toolCallId, result);
|
1975
|
+
}
|
1976
|
+
_subscriptions = /* @__PURE__ */ new Set();
|
1977
|
+
subscribe(callback) {
|
1978
|
+
this._subscriptions.add(callback);
|
1979
|
+
return () => this._subscriptions.delete(callback);
|
1980
|
+
}
|
1981
|
+
subscriptionHandler = () => {
|
1982
|
+
for (const callback of this._subscriptions) callback();
|
1983
|
+
};
|
1984
|
+
get unstable_synchronizer() {
|
1985
|
+
return this.thread.unstable_synchronizer;
|
1986
|
+
}
|
1987
|
+
};
|
1988
|
+
|
1488
1989
|
// src/runtime/local/LocalRuntime.tsx
|
1489
|
-
var LocalRuntime = class {
|
1990
|
+
var LocalRuntime = class extends BaseAssistantRuntime {
|
1991
|
+
_configProviders;
|
1490
1992
|
constructor(adapter) {
|
1993
|
+
const configProviders = /* @__PURE__ */ new Set();
|
1994
|
+
super(new LocalThreadRuntime(configProviders, adapter));
|
1995
|
+
this._configProviders = configProviders;
|
1996
|
+
}
|
1997
|
+
set adapter(adapter) {
|
1998
|
+
this.thread.adapter = adapter;
|
1999
|
+
}
|
2000
|
+
registerModelConfigProvider(provider) {
|
2001
|
+
this._configProviders.add(provider);
|
2002
|
+
return () => this._configProviders.delete(provider);
|
2003
|
+
}
|
2004
|
+
switchToThread(threadId) {
|
2005
|
+
if (threadId) {
|
2006
|
+
throw new Error("LocalRuntime does not yet support switching threads");
|
2007
|
+
}
|
2008
|
+
return this.thread = new LocalThreadRuntime(
|
2009
|
+
this._configProviders,
|
2010
|
+
this.thread.adapter
|
2011
|
+
);
|
2012
|
+
}
|
2013
|
+
};
|
2014
|
+
var LocalThreadRuntime = class {
|
2015
|
+
constructor(_configProviders, adapter) {
|
2016
|
+
this._configProviders = _configProviders;
|
1491
2017
|
this.adapter = adapter;
|
1492
2018
|
}
|
1493
2019
|
_subscriptions = /* @__PURE__ */ new Set();
|
1494
|
-
_configProviders = /* @__PURE__ */ new Set();
|
1495
2020
|
abortController = null;
|
1496
2021
|
repository = new MessageRepository();
|
1497
2022
|
get messages() {
|
@@ -1570,248 +2095,24 @@ var LocalRuntime = class {
|
|
1570
2095
|
this._subscriptions.add(callback);
|
1571
2096
|
return () => this._subscriptions.delete(callback);
|
1572
2097
|
}
|
1573
|
-
registerModelConfigProvider(provider) {
|
1574
|
-
this._configProviders.add(provider);
|
1575
|
-
return () => this._configProviders.delete(provider);
|
1576
|
-
}
|
1577
2098
|
addToolResult() {
|
1578
|
-
throw new Error("LocalRuntime does not yet support tool results");
|
2099
|
+
throw new Error("LocalRuntime does not yet support adding tool results");
|
1579
2100
|
}
|
1580
2101
|
};
|
1581
2102
|
|
1582
2103
|
// src/runtime/local/useLocalRuntime.tsx
|
1583
2104
|
var useLocalRuntime = (adapter) => {
|
1584
|
-
const [runtime] =
|
1585
|
-
|
2105
|
+
const [runtime] = useState6(() => new LocalRuntime(adapter));
|
2106
|
+
useInsertionEffect3(() => {
|
1586
2107
|
runtime.adapter = adapter;
|
1587
2108
|
});
|
1588
2109
|
return runtime;
|
1589
2110
|
};
|
1590
2111
|
|
1591
|
-
// src/context/providers/AssistantRuntimeProvider.tsx
|
1592
|
-
import { memo as memo3 } from "react";
|
1593
|
-
|
1594
|
-
// src/context/providers/AssistantProvider.tsx
|
1595
|
-
import { useEffect as useEffect7, useInsertionEffect as useInsertionEffect3, useRef as useRef5, useState as useState6 } from "react";
|
1596
|
-
|
1597
|
-
// src/context/stores/AssistantModelConfig.ts
|
1598
|
-
import { create as create5 } from "zustand";
|
1599
|
-
|
1600
|
-
// src/utils/ProxyConfigProvider.ts
|
1601
|
-
var ProxyConfigProvider = class {
|
1602
|
-
_providers = /* @__PURE__ */ new Set();
|
1603
|
-
getModelConfig() {
|
1604
|
-
return mergeModelConfigs(this._providers);
|
1605
|
-
}
|
1606
|
-
registerModelConfigProvider(provider) {
|
1607
|
-
this._providers.add(provider);
|
1608
|
-
return () => {
|
1609
|
-
this._providers.delete(provider);
|
1610
|
-
};
|
1611
|
-
}
|
1612
|
-
};
|
1613
|
-
|
1614
|
-
// src/context/stores/AssistantModelConfig.ts
|
1615
|
-
var makeAssistantModelConfigStore = () => create5(() => {
|
1616
|
-
const proxy = new ProxyConfigProvider();
|
1617
|
-
return Object.freeze({
|
1618
|
-
getModelConfig: () => {
|
1619
|
-
return proxy.getModelConfig();
|
1620
|
-
},
|
1621
|
-
registerModelConfigProvider: (provider) => {
|
1622
|
-
return proxy.registerModelConfigProvider(provider);
|
1623
|
-
}
|
1624
|
-
});
|
1625
|
-
});
|
1626
|
-
|
1627
|
-
// src/context/stores/AssistantToolUIs.ts
|
1628
|
-
import { create as create6 } from "zustand";
|
1629
|
-
var makeAssistantToolUIsStore = () => create6((set) => {
|
1630
|
-
const renderers = /* @__PURE__ */ new Map();
|
1631
|
-
return Object.freeze({
|
1632
|
-
getToolUI: (name) => {
|
1633
|
-
const arr = renderers.get(name);
|
1634
|
-
const last = arr?.at(-1);
|
1635
|
-
if (last) return last;
|
1636
|
-
return null;
|
1637
|
-
},
|
1638
|
-
setToolUI: (name, render) => {
|
1639
|
-
let arr = renderers.get(name);
|
1640
|
-
if (!arr) {
|
1641
|
-
arr = [];
|
1642
|
-
renderers.set(name, arr);
|
1643
|
-
}
|
1644
|
-
arr.push(render);
|
1645
|
-
set({});
|
1646
|
-
return () => {
|
1647
|
-
const index = arr.indexOf(render);
|
1648
|
-
if (index !== -1) {
|
1649
|
-
arr.splice(index, 1);
|
1650
|
-
}
|
1651
|
-
if (index === arr.length) {
|
1652
|
-
set({});
|
1653
|
-
}
|
1654
|
-
};
|
1655
|
-
}
|
1656
|
-
});
|
1657
|
-
});
|
1658
|
-
|
1659
|
-
// src/context/providers/ThreadProvider.tsx
|
1660
|
-
import { useEffect as useEffect6, useInsertionEffect as useInsertionEffect2, useRef as useRef4, useState as useState5 } from "react";
|
1661
|
-
|
1662
|
-
// src/context/stores/Composer.ts
|
1663
|
-
import { create as create7 } from "zustand";
|
1664
|
-
var makeComposerStore = (useThread, useThreadActions) => {
|
1665
|
-
const focusListeners = /* @__PURE__ */ new Set();
|
1666
|
-
return create7()((set, get, store) => {
|
1667
|
-
return {
|
1668
|
-
...makeBaseComposer(set, get, store),
|
1669
|
-
isEditing: true,
|
1670
|
-
send: () => {
|
1671
|
-
const { setValue, value } = get();
|
1672
|
-
setValue("");
|
1673
|
-
useThreadActions.getState().append({
|
1674
|
-
parentId: useThread.getState().messages.at(-1)?.id ?? null,
|
1675
|
-
role: "user",
|
1676
|
-
content: [{ type: "text", text: value }]
|
1677
|
-
});
|
1678
|
-
},
|
1679
|
-
cancel: () => {
|
1680
|
-
const thread = useThread.getState();
|
1681
|
-
if (!thread.isRunning) return false;
|
1682
|
-
useThreadActions.getState().cancelRun();
|
1683
|
-
return true;
|
1684
|
-
},
|
1685
|
-
focus: () => {
|
1686
|
-
for (const listener of focusListeners) {
|
1687
|
-
listener();
|
1688
|
-
}
|
1689
|
-
},
|
1690
|
-
onFocus: (listener) => {
|
1691
|
-
focusListeners.add(listener);
|
1692
|
-
return () => {
|
1693
|
-
focusListeners.delete(listener);
|
1694
|
-
};
|
1695
|
-
}
|
1696
|
-
};
|
1697
|
-
});
|
1698
|
-
};
|
1699
|
-
|
1700
|
-
// src/context/stores/Thread.ts
|
1701
|
-
import { create as create8 } from "zustand";
|
1702
|
-
var makeThreadStore = (runtimeRef) => {
|
1703
|
-
return create8(() => ({
|
1704
|
-
messages: runtimeRef.current.messages,
|
1705
|
-
isRunning: runtimeRef.current.isRunning
|
1706
|
-
}));
|
1707
|
-
};
|
1708
|
-
|
1709
|
-
// src/context/stores/ThreadViewport.tsx
|
1710
|
-
import { create as create9 } from "zustand";
|
1711
|
-
var makeThreadViewportStore = () => {
|
1712
|
-
const scrollToBottomListeners = /* @__PURE__ */ new Set();
|
1713
|
-
return create9(() => ({
|
1714
|
-
isAtBottom: true,
|
1715
|
-
scrollToBottom: () => {
|
1716
|
-
for (const listener of scrollToBottomListeners) {
|
1717
|
-
listener();
|
1718
|
-
}
|
1719
|
-
},
|
1720
|
-
onScrollToBottom: (callback) => {
|
1721
|
-
scrollToBottomListeners.add(callback);
|
1722
|
-
return () => {
|
1723
|
-
scrollToBottomListeners.delete(callback);
|
1724
|
-
};
|
1725
|
-
}
|
1726
|
-
}));
|
1727
|
-
};
|
1728
|
-
|
1729
|
-
// src/context/stores/ThreadActions.ts
|
1730
|
-
import { create as create10 } from "zustand";
|
1731
|
-
var makeThreadActionStore = (runtimeRef) => {
|
1732
|
-
return create10(
|
1733
|
-
() => Object.freeze({
|
1734
|
-
getBranches: (messageId) => runtimeRef.current.getBranches(messageId),
|
1735
|
-
switchToBranch: (branchId) => runtimeRef.current.switchToBranch(branchId),
|
1736
|
-
startRun: (parentId) => runtimeRef.current.startRun(parentId),
|
1737
|
-
append: (message) => runtimeRef.current.append(message),
|
1738
|
-
cancelRun: () => runtimeRef.current.cancelRun(),
|
1739
|
-
addToolResult: (toolCallId, result) => runtimeRef.current.addToolResult(toolCallId, result)
|
1740
|
-
})
|
1741
|
-
);
|
1742
|
-
};
|
1743
|
-
|
1744
|
-
// src/context/providers/ThreadProvider.tsx
|
1745
|
-
import { jsx as jsx22, jsxs as jsxs3 } from "react/jsx-runtime";
|
1746
|
-
var ThreadProvider = ({
|
1747
|
-
children,
|
1748
|
-
runtime
|
1749
|
-
}) => {
|
1750
|
-
const runtimeRef = useRef4(runtime);
|
1751
|
-
useInsertionEffect2(() => {
|
1752
|
-
runtimeRef.current = runtime;
|
1753
|
-
});
|
1754
|
-
const [context] = useState5(() => {
|
1755
|
-
const useThread = makeThreadStore(runtimeRef);
|
1756
|
-
const useThreadActions = makeThreadActionStore(runtimeRef);
|
1757
|
-
const useViewport = makeThreadViewportStore();
|
1758
|
-
const useComposer = makeComposerStore(useThread, useThreadActions);
|
1759
|
-
return {
|
1760
|
-
useThread,
|
1761
|
-
useThreadActions,
|
1762
|
-
useComposer,
|
1763
|
-
useViewport
|
1764
|
-
};
|
1765
|
-
});
|
1766
|
-
useEffect6(() => {
|
1767
|
-
const onRuntimeUpdate = () => {
|
1768
|
-
context.useThread.setState(
|
1769
|
-
Object.freeze({
|
1770
|
-
messages: runtimeRef.current.messages,
|
1771
|
-
isRunning: runtimeRef.current.isRunning
|
1772
|
-
}),
|
1773
|
-
true
|
1774
|
-
);
|
1775
|
-
};
|
1776
|
-
onRuntimeUpdate();
|
1777
|
-
return runtime.subscribe(onRuntimeUpdate);
|
1778
|
-
}, [context, runtime]);
|
1779
|
-
const RuntimeSynchronizer = runtime.unstable_synchronizer;
|
1780
|
-
return /* @__PURE__ */ jsxs3(ThreadContext.Provider, { value: context, children: [
|
1781
|
-
RuntimeSynchronizer && /* @__PURE__ */ jsx22(RuntimeSynchronizer, {}),
|
1782
|
-
children
|
1783
|
-
] });
|
1784
|
-
};
|
1785
|
-
|
1786
|
-
// src/context/providers/AssistantProvider.tsx
|
1787
|
-
import { jsx as jsx23 } from "react/jsx-runtime";
|
1788
|
-
var AssistantProvider = ({ children, runtime }) => {
|
1789
|
-
const runtimeRef = useRef5(runtime);
|
1790
|
-
useInsertionEffect3(() => {
|
1791
|
-
runtimeRef.current = runtime;
|
1792
|
-
});
|
1793
|
-
const [context] = useState6(() => {
|
1794
|
-
const useModelConfig = makeAssistantModelConfigStore();
|
1795
|
-
const useToolUIs = makeAssistantToolUIsStore();
|
1796
|
-
return { useModelConfig, useToolUIs };
|
1797
|
-
});
|
1798
|
-
const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
|
1799
|
-
useEffect7(() => {
|
1800
|
-
return runtime.registerModelConfigProvider(getModelCOnfig);
|
1801
|
-
}, [runtime, getModelCOnfig]);
|
1802
|
-
return /* @__PURE__ */ jsx23(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ jsx23(ThreadProvider, { runtime, children }) });
|
1803
|
-
};
|
1804
|
-
|
1805
|
-
// src/context/providers/AssistantRuntimeProvider.tsx
|
1806
|
-
import { jsx as jsx24 } from "react/jsx-runtime";
|
1807
|
-
var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
1808
|
-
return /* @__PURE__ */ jsx24(AssistantProvider, { runtime, children });
|
1809
|
-
};
|
1810
|
-
var AssistantRuntimeProvider = memo3(AssistantRuntimeProviderImpl);
|
1811
|
-
|
1812
2112
|
// src/internal.ts
|
1813
2113
|
var internal_exports = {};
|
1814
2114
|
__export(internal_exports, {
|
2115
|
+
BaseAssistantRuntime: () => BaseAssistantRuntime,
|
1815
2116
|
MessageRepository: () => MessageRepository,
|
1816
2117
|
ProxyConfigProvider: () => ProxyConfigProvider
|
1817
2118
|
});
|
@@ -1825,22 +2126,34 @@ export {
|
|
1825
2126
|
internal_exports as INTERNAL,
|
1826
2127
|
message_exports as MessagePrimitive,
|
1827
2128
|
thread_exports as ThreadPrimitive,
|
2129
|
+
makeAssistantTool,
|
2130
|
+
makeAssistantToolUI,
|
1828
2131
|
useActionBarCopy,
|
1829
2132
|
useActionBarEdit,
|
1830
2133
|
useActionBarReload,
|
2134
|
+
useAppendMessage,
|
2135
|
+
useAssistantContext,
|
2136
|
+
useAssistantInstructions,
|
2137
|
+
useAssistantTool,
|
2138
|
+
useAssistantToolUI,
|
1831
2139
|
useBranchPickerCount,
|
1832
2140
|
useBranchPickerNext,
|
1833
2141
|
useBranchPickerNumber,
|
1834
2142
|
useBranchPickerPrevious,
|
1835
2143
|
useComposerCancel,
|
2144
|
+
useComposerContext,
|
1836
2145
|
useComposerIf,
|
1837
2146
|
useComposerSend,
|
2147
|
+
useContentPartContext,
|
1838
2148
|
useContentPartDisplay,
|
1839
2149
|
useContentPartImage,
|
1840
2150
|
useContentPartInProgressIndicator,
|
1841
2151
|
useContentPartText,
|
1842
2152
|
useLocalRuntime,
|
2153
|
+
useMessageContext,
|
1843
2154
|
useMessageIf,
|
2155
|
+
useSwitchToNewThread,
|
2156
|
+
useThreadContext,
|
1844
2157
|
useThreadEmpty,
|
1845
2158
|
useThreadIf,
|
1846
2159
|
useThreadScrollToBottom,
|