@assistant-ui/react 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +396 -308
- package/dist/index.d.ts +396 -308
- package/dist/index.js +658 -492
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +641 -470
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -44,6 +44,7 @@ __export(src_exports, {
|
|
44
44
|
useActionBarCopy: () => useActionBarCopy,
|
45
45
|
useActionBarEdit: () => useActionBarEdit,
|
46
46
|
useActionBarReload: () => useActionBarReload,
|
47
|
+
useAppendMessage: () => useAppendMessage,
|
47
48
|
useAssistantContext: () => useAssistantContext,
|
48
49
|
useAssistantInstructions: () => useAssistantInstructions,
|
49
50
|
useAssistantTool: () => useAssistantTool,
|
@@ -64,6 +65,7 @@ __export(src_exports, {
|
|
64
65
|
useLocalRuntime: () => useLocalRuntime,
|
65
66
|
useMessageContext: () => useMessageContext,
|
66
67
|
useMessageIf: () => useMessageIf,
|
68
|
+
useSwitchToNewThread: () => useSwitchToNewThread,
|
67
69
|
useThreadContext: () => useThreadContext,
|
68
70
|
useThreadEmpty: () => useThreadEmpty,
|
69
71
|
useThreadIf: () => useThreadIf,
|
@@ -72,192 +74,19 @@ __export(src_exports, {
|
|
72
74
|
});
|
73
75
|
module.exports = __toCommonJS(src_exports);
|
74
76
|
|
75
|
-
// src/primitive-hooks/actionBar/useActionBarCopy.tsx
|
76
|
-
var import_react4 = require("react");
|
77
|
-
|
78
|
-
// src/context/react/MessageContext.ts
|
79
|
-
var import_react = require("react");
|
80
|
-
var MessageContext = (0, import_react.createContext)(null);
|
81
|
-
var useMessageContext = () => {
|
82
|
-
const context = (0, import_react.useContext)(MessageContext);
|
83
|
-
if (!context)
|
84
|
-
throw new Error(
|
85
|
-
"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
|
86
|
-
);
|
87
|
-
return context;
|
88
|
-
};
|
89
|
-
|
90
|
-
// src/utils/combined/useCombinedStore.ts
|
91
|
-
var import_react3 = require("react");
|
92
|
-
|
93
|
-
// src/utils/combined/createCombinedStore.ts
|
94
|
-
var import_react2 = require("react");
|
95
|
-
var createCombinedStore = (stores) => {
|
96
|
-
const subscribe = (callback) => {
|
97
|
-
const unsubscribes = stores.map((store) => store.subscribe(callback));
|
98
|
-
return () => {
|
99
|
-
for (const unsub of unsubscribes) {
|
100
|
-
unsub();
|
101
|
-
}
|
102
|
-
};
|
103
|
-
};
|
104
|
-
return (selector) => {
|
105
|
-
const getSnapshot = () => selector(...stores.map((store) => store.getState()));
|
106
|
-
return (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
107
|
-
};
|
108
|
-
};
|
109
|
-
|
110
|
-
// src/utils/combined/useCombinedStore.ts
|
111
|
-
var useCombinedStore = (stores, selector) => {
|
112
|
-
const useCombined = (0, import_react3.useMemo)(() => createCombinedStore(stores), stores);
|
113
|
-
return useCombined(selector);
|
114
|
-
};
|
115
|
-
|
116
|
-
// src/utils/getMessageText.tsx
|
117
|
-
var getMessageText = (message) => {
|
118
|
-
const textParts = message.content.filter(
|
119
|
-
(part) => part.type === "text"
|
120
|
-
);
|
121
|
-
return textParts.map((part) => part.text).join("\n\n");
|
122
|
-
};
|
123
|
-
|
124
|
-
// src/primitive-hooks/actionBar/useActionBarCopy.tsx
|
125
|
-
var useActionBarCopy = ({
|
126
|
-
copiedDuration = 3e3
|
127
|
-
} = {}) => {
|
128
|
-
const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();
|
129
|
-
const hasCopyableContent = useCombinedStore(
|
130
|
-
[useMessage, useEditComposer],
|
131
|
-
(m, c) => {
|
132
|
-
return !c.isEditing && m.message.content.some((c2) => c2.type === "text");
|
133
|
-
}
|
134
|
-
);
|
135
|
-
const callback = (0, import_react4.useCallback)(() => {
|
136
|
-
const { message } = useMessage.getState();
|
137
|
-
const { setIsCopied } = useMessageUtils.getState();
|
138
|
-
const { isEditing, value: composerValue } = useEditComposer.getState();
|
139
|
-
const valueToCopy = isEditing ? composerValue : getMessageText(message);
|
140
|
-
navigator.clipboard.writeText(valueToCopy);
|
141
|
-
setIsCopied(true);
|
142
|
-
setTimeout(() => setIsCopied(false), copiedDuration);
|
143
|
-
}, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);
|
144
|
-
if (!hasCopyableContent) return null;
|
145
|
-
return callback;
|
146
|
-
};
|
147
|
-
|
148
|
-
// src/primitive-hooks/actionBar/useActionBarEdit.tsx
|
149
|
-
var import_react5 = require("react");
|
150
|
-
var useActionBarEdit = () => {
|
151
|
-
const { useMessage, useEditComposer } = useMessageContext();
|
152
|
-
const disabled = useCombinedStore(
|
153
|
-
[useMessage, useEditComposer],
|
154
|
-
(m, c) => m.message.role !== "user" || c.isEditing
|
155
|
-
);
|
156
|
-
const callback = (0, import_react5.useCallback)(() => {
|
157
|
-
const { edit } = useEditComposer.getState();
|
158
|
-
edit();
|
159
|
-
}, [useEditComposer]);
|
160
|
-
if (disabled) return null;
|
161
|
-
return callback;
|
162
|
-
};
|
163
|
-
|
164
|
-
// src/primitive-hooks/actionBar/useActionBarReload.tsx
|
165
|
-
var import_react7 = require("react");
|
166
|
-
|
167
|
-
// src/context/react/ThreadContext.ts
|
168
|
-
var import_react6 = require("react");
|
169
|
-
var ThreadContext = (0, import_react6.createContext)(null);
|
170
|
-
var useThreadContext = () => {
|
171
|
-
const context = (0, import_react6.useContext)(ThreadContext);
|
172
|
-
if (!context)
|
173
|
-
throw new Error(
|
174
|
-
"This component must be used within an AssistantRuntimeProvider."
|
175
|
-
);
|
176
|
-
return context;
|
177
|
-
};
|
178
|
-
|
179
|
-
// src/primitive-hooks/actionBar/useActionBarReload.tsx
|
180
|
-
var useActionBarReload = () => {
|
181
|
-
const { useThread, useThreadActions, useComposer, useViewport } = useThreadContext();
|
182
|
-
const { useMessage } = useMessageContext();
|
183
|
-
const disabled = useCombinedStore(
|
184
|
-
[useThread, useMessage],
|
185
|
-
(t, m) => t.isRunning || m.message.role !== "assistant"
|
186
|
-
);
|
187
|
-
const callback = (0, import_react7.useCallback)(() => {
|
188
|
-
const { parentId } = useMessage.getState();
|
189
|
-
useThreadActions.getState().startRun(parentId);
|
190
|
-
useViewport.getState().scrollToBottom();
|
191
|
-
useComposer.getState().focus();
|
192
|
-
}, [useThreadActions, useComposer, useViewport, useMessage]);
|
193
|
-
if (disabled) return null;
|
194
|
-
return callback;
|
195
|
-
};
|
196
|
-
|
197
|
-
// src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
|
198
|
-
var useBranchPickerCount = () => {
|
199
|
-
const { useMessage } = useMessageContext();
|
200
|
-
const branchCount = useMessage((s) => s.branches.length);
|
201
|
-
return branchCount;
|
202
|
-
};
|
203
|
-
|
204
|
-
// src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
|
205
|
-
var import_react8 = require("react");
|
206
|
-
var useBranchPickerNext = () => {
|
207
|
-
const { useThreadActions } = useThreadContext();
|
208
|
-
const { useMessage, useEditComposer } = useMessageContext();
|
209
|
-
const disabled = useCombinedStore(
|
210
|
-
[useMessage, useEditComposer],
|
211
|
-
(m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
|
212
|
-
);
|
213
|
-
const callback = (0, import_react8.useCallback)(() => {
|
214
|
-
const { message, branches } = useMessage.getState();
|
215
|
-
useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
|
216
|
-
}, [useThreadActions, useMessage]);
|
217
|
-
if (disabled) return null;
|
218
|
-
return callback;
|
219
|
-
};
|
220
|
-
|
221
|
-
// src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
|
222
|
-
var useBranchPickerNumber = () => {
|
223
|
-
const { useMessage } = useMessageContext();
|
224
|
-
const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
|
225
|
-
return branchIdx + 1;
|
226
|
-
};
|
227
|
-
|
228
|
-
// src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
|
229
|
-
var import_react9 = require("react");
|
230
|
-
var useBranchPickerPrevious = () => {
|
231
|
-
const { useThreadActions } = useThreadContext();
|
232
|
-
const { useMessage, useEditComposer } = useMessageContext();
|
233
|
-
const disabled = useCombinedStore(
|
234
|
-
[useMessage, useEditComposer],
|
235
|
-
(m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
|
236
|
-
);
|
237
|
-
const callback = (0, import_react9.useCallback)(() => {
|
238
|
-
const { message, branches } = useMessage.getState();
|
239
|
-
useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
|
240
|
-
}, [useThreadActions, useMessage]);
|
241
|
-
if (disabled) return null;
|
242
|
-
return callback;
|
243
|
-
};
|
244
|
-
|
245
|
-
// src/primitive-hooks/composer/useComposerCancel.tsx
|
246
|
-
var import_react16 = require("react");
|
247
|
-
|
248
77
|
// src/context/providers/AssistantRuntimeProvider.tsx
|
249
|
-
var
|
78
|
+
var import_react5 = require("react");
|
250
79
|
|
251
80
|
// src/context/providers/AssistantProvider.tsx
|
252
|
-
var
|
81
|
+
var import_react4 = require("react");
|
253
82
|
|
254
83
|
// src/context/react/AssistantContext.ts
|
255
|
-
var
|
256
|
-
var AssistantContext = (0,
|
84
|
+
var import_react = require("react");
|
85
|
+
var AssistantContext = (0, import_react.createContext)(
|
257
86
|
null
|
258
87
|
);
|
259
88
|
var useAssistantContext = () => {
|
260
|
-
const context = (0,
|
89
|
+
const context = (0, import_react.useContext)(AssistantContext);
|
261
90
|
if (!context)
|
262
91
|
throw new Error(
|
263
92
|
"This component must be used within an AssistantRuntimeProvider."
|
@@ -356,7 +185,19 @@ var makeAssistantToolUIsStore = () => (0, import_zustand2.create)((set) => {
|
|
356
185
|
});
|
357
186
|
|
358
187
|
// src/context/providers/ThreadProvider.tsx
|
359
|
-
var
|
188
|
+
var import_react3 = require("react");
|
189
|
+
|
190
|
+
// src/context/react/ThreadContext.ts
|
191
|
+
var import_react2 = require("react");
|
192
|
+
var ThreadContext = (0, import_react2.createContext)(null);
|
193
|
+
var useThreadContext = () => {
|
194
|
+
const context = (0, import_react2.useContext)(ThreadContext);
|
195
|
+
if (!context)
|
196
|
+
throw new Error(
|
197
|
+
"This component must be used within an AssistantRuntimeProvider."
|
198
|
+
);
|
199
|
+
return context;
|
200
|
+
};
|
360
201
|
|
361
202
|
// src/context/stores/Composer.ts
|
362
203
|
var import_zustand3 = require("zustand");
|
@@ -456,11 +297,11 @@ var ThreadProvider = ({
|
|
456
297
|
children,
|
457
298
|
runtime
|
458
299
|
}) => {
|
459
|
-
const runtimeRef = (0,
|
460
|
-
(0,
|
300
|
+
const runtimeRef = (0, import_react3.useRef)(runtime);
|
301
|
+
(0, import_react3.useInsertionEffect)(() => {
|
461
302
|
runtimeRef.current = runtime;
|
462
303
|
});
|
463
|
-
const [context] = (0,
|
304
|
+
const [context] = (0, import_react3.useState)(() => {
|
464
305
|
const useThread = makeThreadStore(runtimeRef);
|
465
306
|
const useThreadActions = makeThreadActionStore(runtimeRef);
|
466
307
|
const useViewport = makeThreadViewportStore();
|
@@ -472,7 +313,7 @@ var ThreadProvider = ({
|
|
472
313
|
useViewport
|
473
314
|
};
|
474
315
|
});
|
475
|
-
(0,
|
316
|
+
(0, import_react3.useEffect)(() => {
|
476
317
|
const onRuntimeUpdate = () => {
|
477
318
|
context.useThread.setState(
|
478
319
|
Object.freeze({
|
@@ -485,27 +326,44 @@ var ThreadProvider = ({
|
|
485
326
|
onRuntimeUpdate();
|
486
327
|
return runtime.subscribe(onRuntimeUpdate);
|
487
328
|
}, [context, runtime]);
|
488
|
-
const
|
329
|
+
const subscribe = (0, import_react3.useCallback)(
|
330
|
+
(c) => runtime.subscribe(c),
|
331
|
+
[runtime]
|
332
|
+
);
|
333
|
+
const RuntimeSynchronizer = (0, import_react3.useSyncExternalStore)(
|
334
|
+
subscribe,
|
335
|
+
() => runtime.unstable_synchronizer,
|
336
|
+
() => void 0
|
337
|
+
);
|
489
338
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ThreadContext.Provider, { value: context, children: [
|
490
339
|
RuntimeSynchronizer && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RuntimeSynchronizer, {}),
|
491
340
|
children
|
492
341
|
] });
|
493
342
|
};
|
494
343
|
|
344
|
+
// src/context/stores/AssistantActions.tsx
|
345
|
+
var import_zustand7 = require("zustand");
|
346
|
+
var makeAssistantActionsStore = (runtimeRef) => (0, import_zustand7.create)(
|
347
|
+
() => Object.freeze({
|
348
|
+
switchToThread: () => runtimeRef.current.switchToThread(null)
|
349
|
+
})
|
350
|
+
);
|
351
|
+
|
495
352
|
// src/context/providers/AssistantProvider.tsx
|
496
353
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
497
354
|
var AssistantProvider = ({ children, runtime }) => {
|
498
|
-
const runtimeRef = (0,
|
499
|
-
(0,
|
355
|
+
const runtimeRef = (0, import_react4.useRef)(runtime);
|
356
|
+
(0, import_react4.useInsertionEffect)(() => {
|
500
357
|
runtimeRef.current = runtime;
|
501
358
|
});
|
502
|
-
const [context] = (0,
|
359
|
+
const [context] = (0, import_react4.useState)(() => {
|
503
360
|
const useModelConfig = makeAssistantModelConfigStore();
|
504
361
|
const useToolUIs = makeAssistantToolUIsStore();
|
505
|
-
|
362
|
+
const useAssistantActions = makeAssistantActionsStore(runtimeRef);
|
363
|
+
return { useModelConfig, useToolUIs, useAssistantActions };
|
506
364
|
});
|
507
365
|
const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
|
508
|
-
(0,
|
366
|
+
(0, import_react4.useEffect)(() => {
|
509
367
|
return runtime.registerModelConfigProvider(getModelCOnfig);
|
510
368
|
}, [runtime, getModelCOnfig]);
|
511
369
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ThreadProvider, { runtime, children }) });
|
@@ -516,14 +374,28 @@ var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
516
374
|
var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
517
375
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AssistantProvider, { runtime, children });
|
518
376
|
};
|
519
|
-
var AssistantRuntimeProvider = (0,
|
377
|
+
var AssistantRuntimeProvider = (0, import_react5.memo)(AssistantRuntimeProviderImpl);
|
378
|
+
|
379
|
+
// src/context/react/ComposerContext.ts
|
380
|
+
var import_react7 = require("react");
|
381
|
+
|
382
|
+
// src/context/react/MessageContext.ts
|
383
|
+
var import_react6 = require("react");
|
384
|
+
var MessageContext = (0, import_react6.createContext)(null);
|
385
|
+
var useMessageContext = () => {
|
386
|
+
const context = (0, import_react6.useContext)(MessageContext);
|
387
|
+
if (!context)
|
388
|
+
throw new Error(
|
389
|
+
"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
|
390
|
+
);
|
391
|
+
return context;
|
392
|
+
};
|
520
393
|
|
521
394
|
// src/context/react/ComposerContext.ts
|
522
|
-
var import_react14 = require("react");
|
523
395
|
var useComposerContext = () => {
|
524
396
|
const { useComposer } = useThreadContext();
|
525
|
-
const { useEditComposer } = (0,
|
526
|
-
return (0,
|
397
|
+
const { useEditComposer } = (0, import_react7.useContext)(MessageContext) ?? {};
|
398
|
+
return (0, import_react7.useMemo)(
|
527
399
|
() => ({
|
528
400
|
useComposer: useEditComposer ?? useComposer,
|
529
401
|
type: useEditComposer ? "edit" : "new"
|
@@ -533,12 +405,12 @@ var useComposerContext = () => {
|
|
533
405
|
};
|
534
406
|
|
535
407
|
// src/context/react/ContentPartContext.ts
|
536
|
-
var
|
537
|
-
var ContentPartContext = (0,
|
408
|
+
var import_react8 = require("react");
|
409
|
+
var ContentPartContext = (0, import_react8.createContext)(
|
538
410
|
null
|
539
411
|
);
|
540
412
|
var useContentPartContext = () => {
|
541
|
-
const context = (0,
|
413
|
+
const context = (0, import_react8.useContext)(ContentPartContext);
|
542
414
|
if (!context)
|
543
415
|
throw new Error(
|
544
416
|
"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
|
@@ -546,11 +418,267 @@ var useContentPartContext = () => {
|
|
546
418
|
return context;
|
547
419
|
};
|
548
420
|
|
421
|
+
// src/hooks/useAppendMessage.tsx
|
422
|
+
var import_react9 = require("react");
|
423
|
+
var toAppendMessage = (useThread, message) => {
|
424
|
+
if (typeof message === "string") {
|
425
|
+
return {
|
426
|
+
parentId: useThread.getState().messages.at(-1)?.id ?? null,
|
427
|
+
role: "user",
|
428
|
+
content: [{ type: "text", text: message }]
|
429
|
+
};
|
430
|
+
}
|
431
|
+
return {
|
432
|
+
parentId: message.parentId ?? useThread.getState().messages.at(-1)?.id ?? null,
|
433
|
+
role: message.role ?? "user",
|
434
|
+
content: message.content
|
435
|
+
};
|
436
|
+
};
|
437
|
+
var useAppendMessage = () => {
|
438
|
+
const { useThread, useThreadActions, useViewport, useComposer } = useThreadContext();
|
439
|
+
const append = (0, import_react9.useCallback)(
|
440
|
+
(message) => {
|
441
|
+
const appendMessage = toAppendMessage(useThread, message);
|
442
|
+
useThreadActions.getState().append(appendMessage);
|
443
|
+
useViewport.getState().scrollToBottom();
|
444
|
+
useComposer.getState().focus();
|
445
|
+
},
|
446
|
+
[useThread, useThreadActions, useViewport, useComposer]
|
447
|
+
);
|
448
|
+
return append;
|
449
|
+
};
|
450
|
+
|
451
|
+
// src/hooks/useSwitchToNewThread.tsx
|
452
|
+
var import_react10 = require("react");
|
453
|
+
var useSwitchToNewThread = () => {
|
454
|
+
const { useAssistantActions } = useAssistantContext();
|
455
|
+
const { useComposer } = useThreadContext();
|
456
|
+
const switchToNewThread = (0, import_react10.useCallback)(() => {
|
457
|
+
useAssistantActions.getState().switchToThread(null);
|
458
|
+
useComposer.getState().focus();
|
459
|
+
}, [useAssistantActions, useComposer]);
|
460
|
+
return switchToNewThread;
|
461
|
+
};
|
462
|
+
|
463
|
+
// src/model-config/useAssistantTool.tsx
|
464
|
+
var import_react11 = require("react");
|
465
|
+
var useAssistantTool = (tool) => {
|
466
|
+
const { useModelConfig, useToolUIs } = useAssistantContext();
|
467
|
+
const registerModelConfigProvider = useModelConfig(
|
468
|
+
(s) => s.registerModelConfigProvider
|
469
|
+
);
|
470
|
+
const setToolUI = useToolUIs((s) => s.setToolUI);
|
471
|
+
(0, import_react11.useEffect)(() => {
|
472
|
+
const { toolName, render, ...rest } = tool;
|
473
|
+
const config = {
|
474
|
+
tools: {
|
475
|
+
[tool.toolName]: rest
|
476
|
+
}
|
477
|
+
};
|
478
|
+
const unsub1 = registerModelConfigProvider(() => config);
|
479
|
+
const unsub2 = render ? setToolUI(toolName, render) : void 0;
|
480
|
+
return () => {
|
481
|
+
unsub1();
|
482
|
+
unsub2?.();
|
483
|
+
};
|
484
|
+
}, [registerModelConfigProvider, setToolUI, tool]);
|
485
|
+
};
|
486
|
+
|
487
|
+
// src/model-config/makeAssistantTool.tsx
|
488
|
+
var makeAssistantTool = (tool) => {
|
489
|
+
const Tool = () => {
|
490
|
+
useAssistantTool(tool);
|
491
|
+
return null;
|
492
|
+
};
|
493
|
+
return Tool;
|
494
|
+
};
|
495
|
+
|
496
|
+
// src/model-config/useAssistantToolUI.tsx
|
497
|
+
var import_react12 = require("react");
|
498
|
+
var useAssistantToolUI = (tool) => {
|
499
|
+
const { useToolUIs } = useAssistantContext();
|
500
|
+
const setToolUI = useToolUIs((s) => s.setToolUI);
|
501
|
+
(0, import_react12.useEffect)(() => {
|
502
|
+
if (!tool) return;
|
503
|
+
const { toolName, render } = tool;
|
504
|
+
return setToolUI(toolName, render);
|
505
|
+
}, [setToolUI, tool]);
|
506
|
+
};
|
507
|
+
|
508
|
+
// src/model-config/makeAssistantToolUI.tsx
|
509
|
+
var makeAssistantToolUI = (tool) => {
|
510
|
+
const ToolUI = () => {
|
511
|
+
useAssistantToolUI(tool);
|
512
|
+
return null;
|
513
|
+
};
|
514
|
+
return ToolUI;
|
515
|
+
};
|
516
|
+
|
517
|
+
// src/model-config/useAssistantInstructions.tsx
|
518
|
+
var import_react13 = require("react");
|
519
|
+
var useAssistantInstructions = (instruction) => {
|
520
|
+
const { useModelConfig } = useAssistantContext();
|
521
|
+
const registerModelConfigProvider = useModelConfig(
|
522
|
+
(s) => s.registerModelConfigProvider
|
523
|
+
);
|
524
|
+
(0, import_react13.useEffect)(() => {
|
525
|
+
const config = {
|
526
|
+
system: instruction
|
527
|
+
};
|
528
|
+
return registerModelConfigProvider(() => config);
|
529
|
+
}, [registerModelConfigProvider, instruction]);
|
530
|
+
};
|
531
|
+
|
532
|
+
// src/primitive-hooks/actionBar/useActionBarCopy.tsx
|
533
|
+
var import_react16 = require("react");
|
534
|
+
|
535
|
+
// src/utils/combined/useCombinedStore.ts
|
536
|
+
var import_react15 = require("react");
|
537
|
+
|
538
|
+
// src/utils/combined/createCombinedStore.ts
|
539
|
+
var import_react14 = require("react");
|
540
|
+
var createCombinedStore = (stores) => {
|
541
|
+
const subscribe = (callback) => {
|
542
|
+
const unsubscribes = stores.map((store) => store.subscribe(callback));
|
543
|
+
return () => {
|
544
|
+
for (const unsub of unsubscribes) {
|
545
|
+
unsub();
|
546
|
+
}
|
547
|
+
};
|
548
|
+
};
|
549
|
+
return (selector) => {
|
550
|
+
const getSnapshot = () => selector(...stores.map((store) => store.getState()));
|
551
|
+
return (0, import_react14.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
552
|
+
};
|
553
|
+
};
|
554
|
+
|
555
|
+
// src/utils/combined/useCombinedStore.ts
|
556
|
+
var useCombinedStore = (stores, selector) => {
|
557
|
+
const useCombined = (0, import_react15.useMemo)(() => createCombinedStore(stores), stores);
|
558
|
+
return useCombined(selector);
|
559
|
+
};
|
560
|
+
|
561
|
+
// src/utils/getMessageText.tsx
|
562
|
+
var getMessageText = (message) => {
|
563
|
+
const textParts = message.content.filter(
|
564
|
+
(part) => part.type === "text"
|
565
|
+
);
|
566
|
+
return textParts.map((part) => part.text).join("\n\n");
|
567
|
+
};
|
568
|
+
|
569
|
+
// src/primitive-hooks/actionBar/useActionBarCopy.tsx
|
570
|
+
var useActionBarCopy = ({
|
571
|
+
copiedDuration = 3e3
|
572
|
+
} = {}) => {
|
573
|
+
const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();
|
574
|
+
const hasCopyableContent = useCombinedStore(
|
575
|
+
[useMessage, useEditComposer],
|
576
|
+
(m, c) => {
|
577
|
+
return !c.isEditing && m.message.content.some((c2) => c2.type === "text");
|
578
|
+
}
|
579
|
+
);
|
580
|
+
const callback = (0, import_react16.useCallback)(() => {
|
581
|
+
const { message } = useMessage.getState();
|
582
|
+
const { setIsCopied } = useMessageUtils.getState();
|
583
|
+
const { isEditing, value: composerValue } = useEditComposer.getState();
|
584
|
+
const valueToCopy = isEditing ? composerValue : getMessageText(message);
|
585
|
+
navigator.clipboard.writeText(valueToCopy);
|
586
|
+
setIsCopied(true);
|
587
|
+
setTimeout(() => setIsCopied(false), copiedDuration);
|
588
|
+
}, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);
|
589
|
+
if (!hasCopyableContent) return null;
|
590
|
+
return callback;
|
591
|
+
};
|
592
|
+
|
593
|
+
// src/primitive-hooks/actionBar/useActionBarEdit.tsx
|
594
|
+
var import_react17 = require("react");
|
595
|
+
var useActionBarEdit = () => {
|
596
|
+
const { useMessage, useEditComposer } = useMessageContext();
|
597
|
+
const disabled = useCombinedStore(
|
598
|
+
[useMessage, useEditComposer],
|
599
|
+
(m, c) => m.message.role !== "user" || c.isEditing
|
600
|
+
);
|
601
|
+
const callback = (0, import_react17.useCallback)(() => {
|
602
|
+
const { edit } = useEditComposer.getState();
|
603
|
+
edit();
|
604
|
+
}, [useEditComposer]);
|
605
|
+
if (disabled) return null;
|
606
|
+
return callback;
|
607
|
+
};
|
608
|
+
|
609
|
+
// src/primitive-hooks/actionBar/useActionBarReload.tsx
|
610
|
+
var import_react18 = require("react");
|
611
|
+
var useActionBarReload = () => {
|
612
|
+
const { useThread, useThreadActions, useComposer, useViewport } = useThreadContext();
|
613
|
+
const { useMessage } = useMessageContext();
|
614
|
+
const disabled = useCombinedStore(
|
615
|
+
[useThread, useMessage],
|
616
|
+
(t, m) => t.isRunning || m.message.role !== "assistant"
|
617
|
+
);
|
618
|
+
const callback = (0, import_react18.useCallback)(() => {
|
619
|
+
const { parentId } = useMessage.getState();
|
620
|
+
useThreadActions.getState().startRun(parentId);
|
621
|
+
useViewport.getState().scrollToBottom();
|
622
|
+
useComposer.getState().focus();
|
623
|
+
}, [useThreadActions, useComposer, useViewport, useMessage]);
|
624
|
+
if (disabled) return null;
|
625
|
+
return callback;
|
626
|
+
};
|
627
|
+
|
628
|
+
// src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
|
629
|
+
var useBranchPickerCount = () => {
|
630
|
+
const { useMessage } = useMessageContext();
|
631
|
+
const branchCount = useMessage((s) => s.branches.length);
|
632
|
+
return branchCount;
|
633
|
+
};
|
634
|
+
|
635
|
+
// src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
|
636
|
+
var import_react19 = require("react");
|
637
|
+
var useBranchPickerNext = () => {
|
638
|
+
const { useThreadActions } = useThreadContext();
|
639
|
+
const { useMessage, useEditComposer } = useMessageContext();
|
640
|
+
const disabled = useCombinedStore(
|
641
|
+
[useMessage, useEditComposer],
|
642
|
+
(m, c) => c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length
|
643
|
+
);
|
644
|
+
const callback = (0, import_react19.useCallback)(() => {
|
645
|
+
const { message, branches } = useMessage.getState();
|
646
|
+
useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) + 1]);
|
647
|
+
}, [useThreadActions, useMessage]);
|
648
|
+
if (disabled) return null;
|
649
|
+
return callback;
|
650
|
+
};
|
651
|
+
|
652
|
+
// src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
|
653
|
+
var useBranchPickerNumber = () => {
|
654
|
+
const { useMessage } = useMessageContext();
|
655
|
+
const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));
|
656
|
+
return branchIdx + 1;
|
657
|
+
};
|
658
|
+
|
659
|
+
// src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
|
660
|
+
var import_react20 = require("react");
|
661
|
+
var useBranchPickerPrevious = () => {
|
662
|
+
const { useThreadActions } = useThreadContext();
|
663
|
+
const { useMessage, useEditComposer } = useMessageContext();
|
664
|
+
const disabled = useCombinedStore(
|
665
|
+
[useMessage, useEditComposer],
|
666
|
+
(m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0
|
667
|
+
);
|
668
|
+
const callback = (0, import_react20.useCallback)(() => {
|
669
|
+
const { message, branches } = useMessage.getState();
|
670
|
+
useThreadActions.getState().switchToBranch(branches[branches.indexOf(message.id) - 1]);
|
671
|
+
}, [useThreadActions, useMessage]);
|
672
|
+
if (disabled) return null;
|
673
|
+
return callback;
|
674
|
+
};
|
675
|
+
|
549
676
|
// src/primitive-hooks/composer/useComposerCancel.tsx
|
677
|
+
var import_react21 = require("react");
|
550
678
|
var useComposerCancel = () => {
|
551
679
|
const { useComposer } = useComposerContext();
|
552
680
|
const disabled = useComposer((c) => !c.isEditing);
|
553
|
-
const callback = (0,
|
681
|
+
const callback = (0, import_react21.useCallback)(() => {
|
554
682
|
const { cancel } = useComposer.getState();
|
555
683
|
cancel();
|
556
684
|
}, [useComposer]);
|
@@ -569,12 +697,12 @@ var useComposerIf = (props) => {
|
|
569
697
|
};
|
570
698
|
|
571
699
|
// src/primitive-hooks/composer/useComposerSend.tsx
|
572
|
-
var
|
700
|
+
var import_react22 = require("react");
|
573
701
|
var useComposerSend = () => {
|
574
702
|
const { useViewport, useComposer: useNewComposer } = useThreadContext();
|
575
703
|
const { useComposer } = useComposerContext();
|
576
704
|
const disabled = useComposer((c) => !c.isEditing || c.value.length === 0);
|
577
|
-
const callback = (0,
|
705
|
+
const callback = (0, import_react22.useCallback)(() => {
|
578
706
|
const composerState = useComposer.getState();
|
579
707
|
if (!composerState.isEditing) return;
|
580
708
|
composerState.send();
|
@@ -670,11 +798,11 @@ var useThreadEmpty = () => {
|
|
670
798
|
};
|
671
799
|
|
672
800
|
// src/primitive-hooks/thread/useThreadScrollToBottom.tsx
|
673
|
-
var
|
801
|
+
var import_react23 = require("react");
|
674
802
|
var useThreadScrollToBottom = () => {
|
675
803
|
const { useComposer, useViewport } = useThreadContext();
|
676
804
|
const isAtBottom = useViewport((s) => s.isAtBottom);
|
677
|
-
const handleScrollToBottom = (0,
|
805
|
+
const handleScrollToBottom = (0, import_react23.useCallback)(() => {
|
678
806
|
useViewport.getState().scrollToBottom();
|
679
807
|
useComposer.getState().focus();
|
680
808
|
}, [useViewport, useComposer]);
|
@@ -683,14 +811,14 @@ var useThreadScrollToBottom = () => {
|
|
683
811
|
};
|
684
812
|
|
685
813
|
// src/primitive-hooks/thread/useThreadSuggestion.tsx
|
686
|
-
var
|
814
|
+
var import_react24 = require("react");
|
687
815
|
var useThreadSuggestion = ({
|
688
816
|
prompt,
|
689
817
|
autoSend
|
690
818
|
}) => {
|
691
819
|
const { useThread, useComposer } = useThreadContext();
|
692
820
|
const disabled = useThread((t) => t.isRunning);
|
693
|
-
const callback = (0,
|
821
|
+
const callback = (0, import_react24.useCallback)(() => {
|
694
822
|
const thread = useThread.getState();
|
695
823
|
const composer = useComposer.getState();
|
696
824
|
composer.setValue(prompt);
|
@@ -705,16 +833,17 @@ var useThreadSuggestion = ({
|
|
705
833
|
// src/primitives/actionBar/index.ts
|
706
834
|
var actionBar_exports = {};
|
707
835
|
__export(actionBar_exports, {
|
708
|
-
Copy: () =>
|
709
|
-
Edit: () =>
|
710
|
-
Reload: () =>
|
711
|
-
Root: () =>
|
836
|
+
Copy: () => ActionBarPrimitiveCopy,
|
837
|
+
Edit: () => ActionBarPrimitiveEdit,
|
838
|
+
Reload: () => ActionBarPrimitiveReload,
|
839
|
+
Root: () => ActionBarPrimitiveRoot
|
712
840
|
});
|
713
841
|
|
714
842
|
// src/primitives/actionBar/ActionBarRoot.tsx
|
715
843
|
var import_react_primitive = require("@radix-ui/react-primitive");
|
716
|
-
var
|
717
|
-
|
844
|
+
var import_react25 = require("react");
|
845
|
+
|
846
|
+
// src/primitives/actionBar/useActionBarFloatStatus.tsx
|
718
847
|
var useActionBarFloatStatus = ({
|
719
848
|
hideWhenRunning,
|
720
849
|
autohide,
|
@@ -735,7 +864,10 @@ var useActionBarFloatStatus = ({
|
|
735
864
|
}
|
736
865
|
);
|
737
866
|
};
|
738
|
-
|
867
|
+
|
868
|
+
// src/primitives/actionBar/ActionBarRoot.tsx
|
869
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
870
|
+
var ActionBarPrimitiveRoot = (0, import_react25.forwardRef)(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {
|
739
871
|
const hideAndfloatStatus = useActionBarFloatStatus({
|
740
872
|
hideWhenRunning,
|
741
873
|
autohide,
|
@@ -751,15 +883,15 @@ var ActionBarRoot = (0, import_react20.forwardRef)(({ hideWhenRunning, autohide,
|
|
751
883
|
}
|
752
884
|
);
|
753
885
|
});
|
754
|
-
|
886
|
+
ActionBarPrimitiveRoot.displayName = "ActionBarPrimitive.Root";
|
755
887
|
|
756
888
|
// src/utils/createActionButton.tsx
|
757
889
|
var import_primitive = require("@radix-ui/primitive");
|
758
890
|
var import_react_primitive2 = require("@radix-ui/react-primitive");
|
759
|
-
var
|
891
|
+
var import_react26 = require("react");
|
760
892
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
761
893
|
var createActionButton = (displayName, useActionButton) => {
|
762
|
-
const ActionButton = (0,
|
894
|
+
const ActionButton = (0, import_react26.forwardRef)((props, forwardedRef) => {
|
763
895
|
const callback = useActionButton(props);
|
764
896
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
765
897
|
import_react_primitive2.Primitive.button,
|
@@ -779,61 +911,64 @@ var createActionButton = (displayName, useActionButton) => {
|
|
779
911
|
};
|
780
912
|
|
781
913
|
// src/primitives/actionBar/ActionBarCopy.tsx
|
782
|
-
var
|
783
|
-
"
|
914
|
+
var ActionBarPrimitiveCopy = createActionButton(
|
915
|
+
"ActionBarPrimitive.Copy",
|
784
916
|
useActionBarCopy
|
785
917
|
);
|
786
918
|
|
787
919
|
// src/primitives/actionBar/ActionBarReload.tsx
|
788
|
-
var
|
789
|
-
"
|
920
|
+
var ActionBarPrimitiveReload = createActionButton(
|
921
|
+
"ActionBarPrimitive.Reload",
|
790
922
|
useActionBarReload
|
791
923
|
);
|
792
924
|
|
793
925
|
// src/primitives/actionBar/ActionBarEdit.tsx
|
794
|
-
var
|
795
|
-
"
|
926
|
+
var ActionBarPrimitiveEdit = createActionButton(
|
927
|
+
"ActionBarPrimitive.Edit",
|
796
928
|
useActionBarEdit
|
797
929
|
);
|
798
930
|
|
799
931
|
// src/primitives/assistantModal/index.ts
|
800
932
|
var assistantModal_exports = {};
|
801
933
|
__export(assistantModal_exports, {
|
802
|
-
Content: () =>
|
803
|
-
Root: () =>
|
804
|
-
Trigger: () =>
|
934
|
+
Content: () => AssistantModalPrimitiveContent,
|
935
|
+
Root: () => AssistantModalPrimitiveRoot,
|
936
|
+
Trigger: () => AssistantModalPrimitiveTrigger
|
805
937
|
});
|
806
938
|
|
807
939
|
// src/primitives/assistantModal/AssistantModalRoot.tsx
|
808
|
-
var
|
809
|
-
var
|
940
|
+
var import_react28 = require("react");
|
941
|
+
var PopoverPrimitive2 = __toESM(require("@radix-ui/react-popover"));
|
810
942
|
var import_primitive2 = require("@radix-ui/primitive");
|
811
943
|
|
812
944
|
// src/utils/hooks/useOnComposerFocus.tsx
|
813
945
|
var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
|
814
|
-
var
|
946
|
+
var import_react27 = require("react");
|
815
947
|
var useOnComposerFocus = (callback) => {
|
816
948
|
const callbackRef = (0, import_react_use_callback_ref.useCallbackRef)(callback);
|
817
949
|
const { useComposer } = useThreadContext();
|
818
|
-
(0,
|
950
|
+
(0, import_react27.useEffect)(() => {
|
819
951
|
return useComposer.getState().onFocus(() => {
|
820
952
|
callbackRef();
|
821
953
|
});
|
822
954
|
}, [useComposer, callbackRef]);
|
823
955
|
};
|
824
956
|
|
957
|
+
// src/primitives/assistantModal/scope.tsx
|
958
|
+
var PopoverPrimitive = __toESM(require("@radix-ui/react-popover"));
|
959
|
+
var usePopoverScope = PopoverPrimitive.createPopoverScope();
|
960
|
+
|
825
961
|
// src/primitives/assistantModal/AssistantModalRoot.tsx
|
826
962
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
827
|
-
var usePopoverScope = PopoverPrimitive.createPopoverScope();
|
828
963
|
var useAssistantModalOpenState = (defaultOpen = false) => {
|
829
|
-
const state = (0,
|
964
|
+
const state = (0, import_react28.useState)(defaultOpen);
|
830
965
|
const [, setOpen] = state;
|
831
966
|
useOnComposerFocus(() => {
|
832
967
|
setOpen(true);
|
833
968
|
});
|
834
969
|
return state;
|
835
970
|
};
|
836
|
-
var
|
971
|
+
var AssistantModalPrimitiveRoot = ({
|
837
972
|
__scopeAssistantModal,
|
838
973
|
defaultOpen,
|
839
974
|
open,
|
@@ -843,7 +978,7 @@ var AssistantModalRoot = ({
|
|
843
978
|
const scope = usePopoverScope(__scopeAssistantModal);
|
844
979
|
const [modalOpen, setOpen] = useAssistantModalOpenState(defaultOpen);
|
845
980
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
846
|
-
|
981
|
+
PopoverPrimitive2.Root,
|
847
982
|
{
|
848
983
|
...scope,
|
849
984
|
open: open === void 0 ? modalOpen : open,
|
@@ -852,26 +987,29 @@ var AssistantModalRoot = ({
|
|
852
987
|
}
|
853
988
|
);
|
854
989
|
};
|
855
|
-
|
990
|
+
AssistantModalPrimitiveRoot.displayName = "AssistantModalPrimitive.Root";
|
856
991
|
|
857
992
|
// src/primitives/assistantModal/AssistantModalTrigger.tsx
|
858
|
-
var
|
859
|
-
var
|
993
|
+
var import_react29 = require("react");
|
994
|
+
var PopoverPrimitive3 = __toESM(require("@radix-ui/react-popover"));
|
860
995
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
861
|
-
var
|
862
|
-
({
|
996
|
+
var AssistantModalPrimitiveTrigger = (0, import_react29.forwardRef)(
|
997
|
+
({
|
998
|
+
__scopeAssistantModal,
|
999
|
+
...rest
|
1000
|
+
}, ref) => {
|
863
1001
|
const scope = usePopoverScope(__scopeAssistantModal);
|
864
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
1002
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PopoverPrimitive3.Trigger, { ...scope, ...rest, ref });
|
865
1003
|
}
|
866
1004
|
);
|
867
|
-
|
1005
|
+
AssistantModalPrimitiveTrigger.displayName = "AssistantModalPrimitive.Trigger";
|
868
1006
|
|
869
1007
|
// src/primitives/assistantModal/AssistantModalContent.tsx
|
870
|
-
var
|
871
|
-
var
|
1008
|
+
var import_react30 = require("react");
|
1009
|
+
var PopoverPrimitive4 = __toESM(require("@radix-ui/react-popover"));
|
872
1010
|
var import_primitive3 = require("@radix-ui/primitive");
|
873
1011
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
874
|
-
var
|
1012
|
+
var AssistantModalPrimitiveContent = (0, import_react30.forwardRef)(
|
875
1013
|
({
|
876
1014
|
__scopeAssistantModal,
|
877
1015
|
side,
|
@@ -881,8 +1019,8 @@ var AssistantModalContent = (0, import_react25.forwardRef)(
|
|
881
1019
|
...props
|
882
1020
|
}, forwardedRef) => {
|
883
1021
|
const scope = usePopoverScope(__scopeAssistantModal);
|
884
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
885
|
-
|
1022
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PopoverPrimitive4.Portal, { ...scope, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
1023
|
+
PopoverPrimitive4.Content,
|
886
1024
|
{
|
887
1025
|
...scope,
|
888
1026
|
...props,
|
@@ -897,97 +1035,101 @@ var AssistantModalContent = (0, import_react25.forwardRef)(
|
|
897
1035
|
) });
|
898
1036
|
}
|
899
1037
|
);
|
900
|
-
|
1038
|
+
AssistantModalPrimitiveContent.displayName = "AssistantModalPrimitive.Content";
|
901
1039
|
|
902
1040
|
// src/primitives/branchPicker/index.ts
|
903
1041
|
var branchPicker_exports = {};
|
904
1042
|
__export(branchPicker_exports, {
|
905
|
-
Count: () =>
|
906
|
-
Next: () =>
|
907
|
-
Number: () =>
|
1043
|
+
Count: () => BranchPickerPrimitiveCount,
|
1044
|
+
Next: () => BranchPickerPrimitiveNext,
|
1045
|
+
Number: () => BranchPickerPrimitiveNumber,
|
908
1046
|
Previous: () => BranchPickerPrevious,
|
909
|
-
Root: () =>
|
1047
|
+
Root: () => BranchPickerPrimitiveRoot
|
910
1048
|
});
|
911
1049
|
|
912
1050
|
// src/primitives/branchPicker/BranchPickerNext.tsx
|
913
|
-
var
|
914
|
-
"
|
1051
|
+
var BranchPickerPrimitiveNext = createActionButton(
|
1052
|
+
"BranchPickerPrimitive.Next",
|
915
1053
|
useBranchPickerNext
|
916
1054
|
);
|
917
1055
|
|
918
1056
|
// src/primitives/branchPicker/BranchPickerPrevious.tsx
|
919
1057
|
var BranchPickerPrevious = createActionButton(
|
920
|
-
"
|
1058
|
+
"BranchPickerPrimitive.Previous",
|
921
1059
|
useBranchPickerPrevious
|
922
1060
|
);
|
923
1061
|
|
924
1062
|
// src/primitives/branchPicker/BranchPickerCount.tsx
|
925
1063
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
926
|
-
var
|
1064
|
+
var BranchPickerPrimitiveCount = () => {
|
927
1065
|
const branchCount = useBranchPickerCount();
|
928
1066
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: branchCount });
|
929
1067
|
};
|
1068
|
+
BranchPickerPrimitiveCount.displayName = "BranchPickerPrimitive.Count";
|
930
1069
|
|
931
1070
|
// src/primitives/branchPicker/BranchPickerNumber.tsx
|
932
1071
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
933
|
-
var
|
1072
|
+
var BranchPickerPrimitiveNumber = () => {
|
934
1073
|
const branchNumber = useBranchPickerNumber();
|
935
1074
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: branchNumber });
|
936
1075
|
};
|
1076
|
+
BranchPickerPrimitiveNumber.displayName = "BranchPickerPrimitive.Number";
|
937
1077
|
|
938
1078
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
939
1079
|
var import_react_primitive6 = require("@radix-ui/react-primitive");
|
940
|
-
var
|
1080
|
+
var import_react36 = require("react");
|
941
1081
|
|
942
1082
|
// src/primitives/message/index.ts
|
943
1083
|
var message_exports = {};
|
944
1084
|
__export(message_exports, {
|
945
|
-
Content: () =>
|
946
|
-
If: () =>
|
947
|
-
InProgress: () =>
|
948
|
-
Root: () =>
|
1085
|
+
Content: () => MessagePrimitiveContent,
|
1086
|
+
If: () => MessagePrimitiveIf,
|
1087
|
+
InProgress: () => MessagePrimitiveInProgress,
|
1088
|
+
Root: () => MessagePrimitiveRoot
|
949
1089
|
});
|
950
1090
|
|
951
1091
|
// src/primitives/message/MessageRoot.tsx
|
952
1092
|
var import_primitive4 = require("@radix-ui/primitive");
|
953
1093
|
var import_react_primitive3 = require("@radix-ui/react-primitive");
|
954
|
-
var
|
1094
|
+
var import_react31 = require("react");
|
955
1095
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
956
|
-
var
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
);
|
977
|
-
MessageRoot.displayName = "MessageRoot";
|
1096
|
+
var MessagePrimitiveRoot = (0, import_react31.forwardRef)(({ onMouseEnter, onMouseLeave, ...rest }, ref) => {
|
1097
|
+
const { useMessageUtils } = useMessageContext();
|
1098
|
+
const setIsHovering = useMessageUtils((s) => s.setIsHovering);
|
1099
|
+
const handleMouseEnter = () => {
|
1100
|
+
setIsHovering(true);
|
1101
|
+
};
|
1102
|
+
const handleMouseLeave = () => {
|
1103
|
+
setIsHovering(false);
|
1104
|
+
};
|
1105
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
1106
|
+
import_react_primitive3.Primitive.div,
|
1107
|
+
{
|
1108
|
+
...rest,
|
1109
|
+
ref,
|
1110
|
+
onMouseEnter: (0, import_primitive4.composeEventHandlers)(onMouseEnter, handleMouseEnter),
|
1111
|
+
onMouseLeave: (0, import_primitive4.composeEventHandlers)(onMouseLeave, handleMouseLeave)
|
1112
|
+
}
|
1113
|
+
);
|
1114
|
+
});
|
1115
|
+
MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
|
978
1116
|
|
979
1117
|
// src/primitives/message/MessageIf.tsx
|
980
|
-
var
|
1118
|
+
var MessagePrimitiveIf = ({
|
1119
|
+
children,
|
1120
|
+
...query
|
1121
|
+
}) => {
|
981
1122
|
const result = useMessageIf(query);
|
982
1123
|
return result ? children : null;
|
983
1124
|
};
|
1125
|
+
MessagePrimitiveIf.displayName = "MessagePrimitive.If";
|
984
1126
|
|
985
1127
|
// src/primitives/message/MessageContent.tsx
|
986
|
-
var
|
1128
|
+
var import_react34 = require("react");
|
987
1129
|
|
988
1130
|
// src/context/providers/ContentPartProvider.tsx
|
989
|
-
var
|
990
|
-
var
|
1131
|
+
var import_react32 = require("react");
|
1132
|
+
var import_zustand8 = require("zustand");
|
991
1133
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
992
1134
|
var syncContentPart = ({ message }, useContentPart, partIndex) => {
|
993
1135
|
const part = message.content[partIndex];
|
@@ -1005,14 +1147,14 @@ var syncContentPart = ({ message }, useContentPart, partIndex) => {
|
|
1005
1147
|
};
|
1006
1148
|
var useContentPartContext2 = (partIndex) => {
|
1007
1149
|
const { useMessage } = useMessageContext();
|
1008
|
-
const [context] = (0,
|
1009
|
-
const useContentPart = (0,
|
1150
|
+
const [context] = (0, import_react32.useState)(() => {
|
1151
|
+
const useContentPart = (0, import_zustand8.create)(
|
1010
1152
|
() => ({})
|
1011
1153
|
);
|
1012
1154
|
syncContentPart(useMessage.getState(), useContentPart, partIndex);
|
1013
1155
|
return { useContentPart };
|
1014
1156
|
});
|
1015
|
-
(0,
|
1157
|
+
(0, import_react32.useEffect)(() => {
|
1016
1158
|
syncContentPart(useMessage.getState(), context.useContentPart, partIndex);
|
1017
1159
|
return useMessage.subscribe((message) => {
|
1018
1160
|
syncContentPart(message, context.useContentPart, partIndex);
|
@@ -1029,36 +1171,38 @@ var ContentPartProvider = ({
|
|
1029
1171
|
};
|
1030
1172
|
|
1031
1173
|
// src/primitives/contentPart/ContentPartDisplay.tsx
|
1032
|
-
var
|
1174
|
+
var ContentPartPrimitiveDisplay = () => {
|
1033
1175
|
const display = useContentPartDisplay();
|
1034
1176
|
return display ?? null;
|
1035
1177
|
};
|
1178
|
+
ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
|
1036
1179
|
|
1037
1180
|
// src/primitives/contentPart/ContentPartInProgressIndicator.tsx
|
1038
|
-
var
|
1181
|
+
var ContentPartPrimitiveInProgressIndicator = () => {
|
1039
1182
|
const indicator = useContentPartInProgressIndicator();
|
1040
1183
|
return indicator;
|
1041
1184
|
};
|
1185
|
+
ContentPartPrimitiveInProgressIndicator.displayName = "ContentPartPrimitive.InProgressIndicator";
|
1042
1186
|
|
1043
1187
|
// src/primitives/contentPart/ContentPartText.tsx
|
1044
1188
|
var import_react_primitive4 = require("@radix-ui/react-primitive");
|
1045
|
-
var
|
1189
|
+
var import_react33 = require("react");
|
1046
1190
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
1047
|
-
var
|
1191
|
+
var ContentPartPrimitiveText = (0, import_react33.forwardRef)((props, forwardedRef) => {
|
1048
1192
|
const text = useContentPartText();
|
1049
1193
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_primitive4.Primitive.p, { ...props, ref: forwardedRef, children: text });
|
1050
1194
|
});
|
1051
|
-
|
1195
|
+
ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
|
1052
1196
|
|
1053
1197
|
// src/primitives/message/MessageContent.tsx
|
1054
1198
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
1055
1199
|
var defaultComponents = {
|
1056
1200
|
Text: () => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
1057
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
1058
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
1201
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ContentPartPrimitiveText, { style: { whiteSpace: "pre-line" } }),
|
1202
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ContentPartPrimitiveInProgressIndicator, {})
|
1059
1203
|
] }),
|
1060
1204
|
Image: () => null,
|
1061
|
-
UI: () => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
1205
|
+
UI: () => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ContentPartPrimitiveDisplay, {}),
|
1062
1206
|
tools: {
|
1063
1207
|
Fallback: (props) => {
|
1064
1208
|
const { useToolUIs } = useAssistantContext();
|
@@ -1103,11 +1247,13 @@ var MessageContentPartImpl = ({
|
|
1103
1247
|
}) => {
|
1104
1248
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ContentPartProvider, { partIndex, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MessageContentPartComponent, { components }) });
|
1105
1249
|
};
|
1106
|
-
var MessageContentPart = (0,
|
1250
|
+
var MessageContentPart = (0, import_react34.memo)(
|
1107
1251
|
MessageContentPartImpl,
|
1108
1252
|
(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
|
1109
1253
|
);
|
1110
|
-
var
|
1254
|
+
var MessagePrimitiveContent = ({
|
1255
|
+
components
|
1256
|
+
}) => {
|
1111
1257
|
const { useMessage } = useMessageContext();
|
1112
1258
|
const contentLength = useMessage((s) => s.message.content.length);
|
1113
1259
|
return new Array(contentLength).fill(null).map((_, idx) => {
|
@@ -1122,71 +1268,73 @@ var MessageContent = ({ components }) => {
|
|
1122
1268
|
);
|
1123
1269
|
});
|
1124
1270
|
};
|
1271
|
+
MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
|
1125
1272
|
|
1126
1273
|
// src/primitives/message/MessageInProgress.tsx
|
1127
1274
|
var import_react_primitive5 = require("@radix-ui/react-primitive");
|
1128
|
-
var
|
1275
|
+
var import_react35 = require("react");
|
1129
1276
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
1130
|
-
var
|
1277
|
+
var MessagePrimitiveInProgress = (0, import_react35.forwardRef)((props, ref) => {
|
1131
1278
|
const { useMessageUtils } = useMessageContext();
|
1132
|
-
(0,
|
1279
|
+
(0, import_react35.useEffect)(() => {
|
1133
1280
|
useMessageUtils.getState().setInProgressIndicator(/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_primitive5.Primitive.span, { ...props, ref }));
|
1281
|
+
return () => {
|
1282
|
+
useMessageUtils.getState().setInProgressIndicator(null);
|
1283
|
+
};
|
1134
1284
|
}, [useMessageUtils, props, ref]);
|
1135
1285
|
return null;
|
1136
1286
|
});
|
1137
|
-
|
1287
|
+
MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
|
1138
1288
|
|
1139
1289
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
1140
1290
|
var import_jsx_runtime16 = require("react/jsx-runtime");
|
1141
|
-
var
|
1142
|
-
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
1291
|
+
var BranchPickerPrimitiveRoot = (0, import_react36.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
|
1292
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_primitive6.Primitive.div, { ...rest, ref }) });
|
1143
1293
|
});
|
1144
|
-
|
1294
|
+
BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
|
1145
1295
|
|
1146
1296
|
// src/primitives/composer/index.ts
|
1147
1297
|
var composer_exports = {};
|
1148
1298
|
__export(composer_exports, {
|
1149
|
-
Cancel: () =>
|
1150
|
-
If: () =>
|
1151
|
-
Input: () =>
|
1152
|
-
Root: () =>
|
1153
|
-
Send: () =>
|
1299
|
+
Cancel: () => ComposerPrimitiveCancel,
|
1300
|
+
If: () => ComposerPrimitiveIf,
|
1301
|
+
Input: () => ComposerPrimitiveInput,
|
1302
|
+
Root: () => ComposerPrimitiveRoot,
|
1303
|
+
Send: () => ComposerPrimitiveSend
|
1154
1304
|
});
|
1155
1305
|
|
1156
1306
|
// src/primitives/composer/ComposerRoot.tsx
|
1157
1307
|
var import_primitive5 = require("@radix-ui/primitive");
|
1158
1308
|
var import_react_primitive7 = require("@radix-ui/react-primitive");
|
1159
|
-
var
|
1309
|
+
var import_react37 = require("react");
|
1160
1310
|
var import_jsx_runtime17 = require("react/jsx-runtime");
|
1161
|
-
var
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
);
|
1179
|
-
ComposerRoot.displayName = "ComposerRoot";
|
1311
|
+
var ComposerPrimitiveRoot = (0, import_react37.forwardRef)(({ onSubmit, ...rest }, forwardedRef) => {
|
1312
|
+
const send = useComposerSend();
|
1313
|
+
const handleSubmit = (e) => {
|
1314
|
+
e.preventDefault();
|
1315
|
+
if (!send) return;
|
1316
|
+
send();
|
1317
|
+
};
|
1318
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
1319
|
+
import_react_primitive7.Primitive.form,
|
1320
|
+
{
|
1321
|
+
...rest,
|
1322
|
+
ref: forwardedRef,
|
1323
|
+
onSubmit: (0, import_primitive5.composeEventHandlers)(onSubmit, handleSubmit)
|
1324
|
+
}
|
1325
|
+
);
|
1326
|
+
});
|
1327
|
+
ComposerPrimitiveRoot.displayName = "ComposerPrimitive.Root";
|
1180
1328
|
|
1181
1329
|
// src/primitives/composer/ComposerInput.tsx
|
1182
1330
|
var import_primitive6 = require("@radix-ui/primitive");
|
1183
1331
|
var import_react_compose_refs = require("@radix-ui/react-compose-refs");
|
1184
1332
|
var import_react_slot = require("@radix-ui/react-slot");
|
1185
|
-
var
|
1333
|
+
var import_react38 = require("react");
|
1186
1334
|
var import_react_textarea_autosize = __toESM(require("react-textarea-autosize"));
|
1187
1335
|
var import_react_use_escape_keydown = require("@radix-ui/react-use-escape-keydown");
|
1188
1336
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
1189
|
-
var
|
1337
|
+
var ComposerPrimitiveInput = (0, import_react38.forwardRef)(
|
1190
1338
|
({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
|
1191
1339
|
const { useThread } = useThreadContext();
|
1192
1340
|
const { useComposer, type } = useComposerContext();
|
@@ -1195,7 +1343,7 @@ var ComposerInput = (0, import_react33.forwardRef)(
|
|
1195
1343
|
return c.value;
|
1196
1344
|
});
|
1197
1345
|
const Component = asChild ? import_react_slot.Slot : import_react_textarea_autosize.default;
|
1198
|
-
const textareaRef = (0,
|
1346
|
+
const textareaRef = (0, import_react38.useRef)(null);
|
1199
1347
|
const ref = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, textareaRef);
|
1200
1348
|
(0, import_react_use_escape_keydown.useEscapeKeydown)((e) => {
|
1201
1349
|
const composer = useComposer.getState();
|
@@ -1214,7 +1362,7 @@ var ComposerInput = (0, import_react33.forwardRef)(
|
|
1214
1362
|
}
|
1215
1363
|
};
|
1216
1364
|
const autoFocusEnabled = autoFocus && !disabled;
|
1217
|
-
const focus = (0,
|
1365
|
+
const focus = (0, import_react38.useCallback)(() => {
|
1218
1366
|
const textarea = textareaRef.current;
|
1219
1367
|
if (!textarea || !autoFocusEnabled) return;
|
1220
1368
|
textarea.focus({ preventScroll: true });
|
@@ -1223,7 +1371,7 @@ var ComposerInput = (0, import_react33.forwardRef)(
|
|
1223
1371
|
textareaRef.current.value.length
|
1224
1372
|
);
|
1225
1373
|
}, [autoFocusEnabled]);
|
1226
|
-
(0,
|
1374
|
+
(0, import_react38.useEffect)(() => focus(), [focus]);
|
1227
1375
|
useOnComposerFocus(() => {
|
1228
1376
|
if (type === "new") {
|
1229
1377
|
focus();
|
@@ -1246,113 +1394,120 @@ var ComposerInput = (0, import_react33.forwardRef)(
|
|
1246
1394
|
);
|
1247
1395
|
}
|
1248
1396
|
);
|
1249
|
-
|
1397
|
+
ComposerPrimitiveInput.displayName = "ComposerPrimitive.Input";
|
1250
1398
|
|
1251
1399
|
// src/primitives/composer/ComposerSend.tsx
|
1252
|
-
var
|
1400
|
+
var import_react39 = require("react");
|
1253
1401
|
var import_react_primitive8 = require("@radix-ui/react-primitive");
|
1254
1402
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
1255
|
-
var
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
);
|
1270
|
-
ComposerSend.displayName = "ComposerSend";
|
1403
|
+
var ComposerPrimitiveSend = (0, import_react39.forwardRef)(({ disabled, ...rest }, ref) => {
|
1404
|
+
const { useComposer } = useComposerContext();
|
1405
|
+
const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
|
1406
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
1407
|
+
import_react_primitive8.Primitive.button,
|
1408
|
+
{
|
1409
|
+
type: "submit",
|
1410
|
+
...rest,
|
1411
|
+
ref,
|
1412
|
+
disabled: disabled || !hasValue
|
1413
|
+
}
|
1414
|
+
);
|
1415
|
+
});
|
1416
|
+
ComposerPrimitiveSend.displayName = "ComposerPrimitive.Send";
|
1271
1417
|
|
1272
1418
|
// src/primitives/composer/ComposerCancel.tsx
|
1273
|
-
var
|
1274
|
-
"
|
1419
|
+
var ComposerPrimitiveCancel = createActionButton(
|
1420
|
+
"ComposerPrimitive.Cancel",
|
1275
1421
|
useComposerCancel
|
1276
1422
|
);
|
1277
1423
|
|
1278
1424
|
// src/primitives/composer/ComposerIf.tsx
|
1279
|
-
var
|
1425
|
+
var ComposerPrimitiveIf = ({
|
1426
|
+
children,
|
1427
|
+
...query
|
1428
|
+
}) => {
|
1280
1429
|
const result = useComposerIf(query);
|
1281
1430
|
return result ? children : null;
|
1282
1431
|
};
|
1432
|
+
ComposerPrimitiveIf.displayName = "ComposerPrimitive.If";
|
1283
1433
|
|
1284
1434
|
// src/primitives/contentPart/index.ts
|
1285
1435
|
var contentPart_exports = {};
|
1286
1436
|
__export(contentPart_exports, {
|
1287
|
-
Display: () =>
|
1288
|
-
Image: () =>
|
1289
|
-
InProgressIndicator: () =>
|
1290
|
-
Text: () =>
|
1437
|
+
Display: () => ContentPartPrimitiveDisplay,
|
1438
|
+
Image: () => ContentPartPrimitiveImage,
|
1439
|
+
InProgressIndicator: () => ContentPartPrimitiveInProgressIndicator,
|
1440
|
+
Text: () => ContentPartPrimitiveText
|
1291
1441
|
});
|
1292
1442
|
|
1293
1443
|
// src/primitives/contentPart/ContentPartImage.tsx
|
1294
1444
|
var import_react_primitive9 = require("@radix-ui/react-primitive");
|
1295
|
-
var
|
1445
|
+
var import_react40 = require("react");
|
1296
1446
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
1297
|
-
var
|
1447
|
+
var ContentPartPrimitiveImage = (0, import_react40.forwardRef)((props, forwardedRef) => {
|
1298
1448
|
const image = useContentPartImage();
|
1299
1449
|
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_react_primitive9.Primitive.img, { src: image, ...props, ref: forwardedRef });
|
1300
1450
|
});
|
1301
|
-
|
1451
|
+
ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
|
1302
1452
|
|
1303
1453
|
// src/primitives/thread/index.ts
|
1304
1454
|
var thread_exports = {};
|
1305
1455
|
__export(thread_exports, {
|
1306
|
-
Empty: () =>
|
1307
|
-
If: () =>
|
1308
|
-
Messages: () =>
|
1309
|
-
Root: () =>
|
1310
|
-
ScrollToBottom: () =>
|
1311
|
-
Suggestion: () =>
|
1312
|
-
Viewport: () =>
|
1456
|
+
Empty: () => ThreadPrimitiveEmpty,
|
1457
|
+
If: () => ThreadPrimitiveIf,
|
1458
|
+
Messages: () => ThreadPrimitiveMessages,
|
1459
|
+
Root: () => ThreadPrimitiveRoot,
|
1460
|
+
ScrollToBottom: () => ThreadPrimitiveScrollToBottom,
|
1461
|
+
Suggestion: () => ThreadPrimitiveSuggestion,
|
1462
|
+
Viewport: () => ThreadPrimitiveViewport
|
1313
1463
|
});
|
1314
1464
|
|
1315
1465
|
// src/primitives/thread/ThreadRoot.tsx
|
1316
1466
|
var import_react_primitive10 = require("@radix-ui/react-primitive");
|
1317
|
-
var
|
1467
|
+
var import_react41 = require("react");
|
1318
1468
|
var import_jsx_runtime21 = require("react/jsx-runtime");
|
1319
|
-
var
|
1320
|
-
(props, ref)
|
1321
|
-
|
1322
|
-
|
1323
|
-
);
|
1324
|
-
ThreadRoot.displayName = "ThreadRoot";
|
1469
|
+
var ThreadPrimitiveRoot = (0, import_react41.forwardRef)((props, ref) => {
|
1470
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react_primitive10.Primitive.div, { ...props, ref });
|
1471
|
+
});
|
1472
|
+
ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
|
1325
1473
|
|
1326
1474
|
// src/primitives/thread/ThreadEmpty.tsx
|
1327
|
-
var
|
1475
|
+
var ThreadPrimitiveEmpty = ({
|
1476
|
+
children
|
1477
|
+
}) => {
|
1328
1478
|
const empty = useThreadEmpty();
|
1329
1479
|
return empty ? children : null;
|
1330
1480
|
};
|
1481
|
+
ThreadPrimitiveEmpty.displayName = "ThreadPrimitive.Empty";
|
1331
1482
|
|
1332
1483
|
// src/primitives/thread/ThreadIf.tsx
|
1333
|
-
var
|
1484
|
+
var ThreadPrimitiveIf = ({
|
1485
|
+
children,
|
1486
|
+
...query
|
1487
|
+
}) => {
|
1334
1488
|
const result = useThreadIf(query);
|
1335
1489
|
return result ? children : null;
|
1336
1490
|
};
|
1491
|
+
ThreadPrimitiveIf.displayName = "ThreadPrimitive.If";
|
1337
1492
|
|
1338
1493
|
// src/primitives/thread/ThreadViewport.tsx
|
1339
1494
|
var import_react_compose_refs3 = require("@radix-ui/react-compose-refs");
|
1340
1495
|
var import_react_primitive11 = require("@radix-ui/react-primitive");
|
1341
|
-
var
|
1496
|
+
var import_react46 = require("react");
|
1342
1497
|
|
1343
1498
|
// src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
|
1344
1499
|
var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
|
1345
|
-
var
|
1500
|
+
var import_react45 = require("react");
|
1346
1501
|
|
1347
1502
|
// src/utils/hooks/useOnResizeContent.tsx
|
1348
1503
|
var import_react_use_callback_ref2 = require("@radix-ui/react-use-callback-ref");
|
1349
|
-
var
|
1504
|
+
var import_react43 = require("react");
|
1350
1505
|
|
1351
1506
|
// src/utils/hooks/useManagedRef.ts
|
1352
|
-
var
|
1507
|
+
var import_react42 = require("react");
|
1353
1508
|
var useManagedRef = (callback) => {
|
1354
|
-
const cleanupRef = (0,
|
1355
|
-
const ref = (0,
|
1509
|
+
const cleanupRef = (0, import_react42.useRef)();
|
1510
|
+
const ref = (0, import_react42.useCallback)(
|
1356
1511
|
(el) => {
|
1357
1512
|
if (cleanupRef.current) {
|
1358
1513
|
cleanupRef.current();
|
@@ -1369,7 +1524,7 @@ var useManagedRef = (callback) => {
|
|
1369
1524
|
// src/utils/hooks/useOnResizeContent.tsx
|
1370
1525
|
var useOnResizeContent = (callback) => {
|
1371
1526
|
const callbackRef = (0, import_react_use_callback_ref2.useCallbackRef)(callback);
|
1372
|
-
const refCallback = (0,
|
1527
|
+
const refCallback = (0, import_react43.useCallback)(
|
1373
1528
|
(el) => {
|
1374
1529
|
const resizeObserver = new ResizeObserver(() => {
|
1375
1530
|
callbackRef();
|
@@ -1406,11 +1561,11 @@ var useOnResizeContent = (callback) => {
|
|
1406
1561
|
|
1407
1562
|
// src/utils/hooks/useOnScrollToBottom.tsx
|
1408
1563
|
var import_react_use_callback_ref3 = require("@radix-ui/react-use-callback-ref");
|
1409
|
-
var
|
1564
|
+
var import_react44 = require("react");
|
1410
1565
|
var useOnScrollToBottom = (callback) => {
|
1411
1566
|
const callbackRef = (0, import_react_use_callback_ref3.useCallbackRef)(callback);
|
1412
1567
|
const { useViewport } = useThreadContext();
|
1413
|
-
(0,
|
1568
|
+
(0, import_react44.useEffect)(() => {
|
1414
1569
|
return useViewport.getState().onScrollToBottom(() => {
|
1415
1570
|
callbackRef();
|
1416
1571
|
});
|
@@ -1421,11 +1576,11 @@ var useOnScrollToBottom = (callback) => {
|
|
1421
1576
|
var useThreadViewportAutoScroll = ({
|
1422
1577
|
autoScroll = true
|
1423
1578
|
}) => {
|
1424
|
-
const divRef = (0,
|
1579
|
+
const divRef = (0, import_react45.useRef)(null);
|
1425
1580
|
const { useViewport } = useThreadContext();
|
1426
|
-
const firstRenderRef = (0,
|
1427
|
-
const lastScrollTop = (0,
|
1428
|
-
const isScrollingToBottomRef = (0,
|
1581
|
+
const firstRenderRef = (0, import_react45.useRef)(true);
|
1582
|
+
const lastScrollTop = (0, import_react45.useRef)(0);
|
1583
|
+
const isScrollingToBottomRef = (0, import_react45.useRef)(false);
|
1429
1584
|
const scrollToBottom = () => {
|
1430
1585
|
const div = divRef.current;
|
1431
1586
|
if (!div || !autoScroll) return;
|
@@ -1472,28 +1627,28 @@ var useThreadViewportAutoScroll = ({
|
|
1472
1627
|
|
1473
1628
|
// src/primitives/thread/ThreadViewport.tsx
|
1474
1629
|
var import_jsx_runtime22 = require("react/jsx-runtime");
|
1475
|
-
var
|
1630
|
+
var ThreadPrimitiveViewport = (0, import_react46.forwardRef)(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
|
1476
1631
|
const autoScrollRef = useThreadViewportAutoScroll({
|
1477
1632
|
autoScroll
|
1478
1633
|
});
|
1479
1634
|
const ref = (0, import_react_compose_refs3.useComposedRefs)(forwardedRef, autoScrollRef);
|
1480
1635
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react_primitive11.Primitive.div, { ...rest, ref, children });
|
1481
1636
|
});
|
1482
|
-
|
1637
|
+
ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
1483
1638
|
|
1484
1639
|
// src/primitives/thread/ThreadMessages.tsx
|
1485
|
-
var
|
1640
|
+
var import_react48 = require("react");
|
1486
1641
|
|
1487
1642
|
// src/context/providers/MessageProvider.tsx
|
1488
|
-
var
|
1489
|
-
var
|
1643
|
+
var import_react47 = require("react");
|
1644
|
+
var import_zustand11 = require("zustand");
|
1490
1645
|
|
1491
1646
|
// src/context/stores/EditComposer.ts
|
1492
|
-
var
|
1647
|
+
var import_zustand9 = require("zustand");
|
1493
1648
|
var makeEditComposerStore = ({
|
1494
1649
|
onEdit,
|
1495
1650
|
onSend
|
1496
|
-
}) => (0,
|
1651
|
+
}) => (0, import_zustand9.create)()((set, get, store) => ({
|
1497
1652
|
...makeBaseComposer(set, get, store),
|
1498
1653
|
isEditing: false,
|
1499
1654
|
edit: () => {
|
@@ -1513,8 +1668,8 @@ var makeEditComposerStore = ({
|
|
1513
1668
|
}));
|
1514
1669
|
|
1515
1670
|
// src/context/stores/MessageUtils.ts
|
1516
|
-
var
|
1517
|
-
var makeMessageUtilsStore = () => (0,
|
1671
|
+
var import_zustand10 = require("zustand");
|
1672
|
+
var makeMessageUtilsStore = () => (0, import_zustand10.create)((set) => ({
|
1518
1673
|
inProgressIndicator: null,
|
1519
1674
|
setInProgressIndicator: (value) => {
|
1520
1675
|
set({ inProgressIndicator: value });
|
@@ -1552,8 +1707,8 @@ var syncMessage = (thread, getBranches, useMessage, messageIndex) => {
|
|
1552
1707
|
};
|
1553
1708
|
var useMessageContext2 = (messageIndex) => {
|
1554
1709
|
const { useThread, useThreadActions } = useThreadContext();
|
1555
|
-
const [context] = (0,
|
1556
|
-
const useMessage = (0,
|
1710
|
+
const [context] = (0, import_react47.useState)(() => {
|
1711
|
+
const useMessage = (0, import_zustand11.create)(() => ({}));
|
1557
1712
|
const useMessageUtils = makeMessageUtilsStore();
|
1558
1713
|
const useEditComposer = makeEditComposerStore({
|
1559
1714
|
onEdit: () => {
|
@@ -1589,7 +1744,7 @@ var useMessageContext2 = (messageIndex) => {
|
|
1589
1744
|
);
|
1590
1745
|
return { useMessage, useMessageUtils, useEditComposer };
|
1591
1746
|
});
|
1592
|
-
(0,
|
1747
|
+
(0, import_react47.useEffect)(() => {
|
1593
1748
|
return useThread.subscribe((thread) => {
|
1594
1749
|
syncMessage(
|
1595
1750
|
thread,
|
@@ -1624,18 +1779,20 @@ var ThreadMessageImpl = ({
|
|
1624
1779
|
}) => {
|
1625
1780
|
const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
|
1626
1781
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(MessageProvider, { messageIndex, children: [
|
1627
|
-
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
1628
|
-
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
1629
|
-
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
1782
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(MessagePrimitiveIf, { user: true, children: [
|
1783
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(UserMessage, {}) }),
|
1784
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(EditComposer, {}) })
|
1630
1785
|
] }),
|
1631
|
-
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
1786
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(AssistantMessage, {}) })
|
1632
1787
|
] });
|
1633
1788
|
};
|
1634
|
-
var ThreadMessage = (0,
|
1789
|
+
var ThreadMessage = (0, import_react48.memo)(
|
1635
1790
|
ThreadMessageImpl,
|
1636
1791
|
(prev, next) => prev.messageIndex === next.messageIndex && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
|
1637
1792
|
);
|
1638
|
-
var
|
1793
|
+
var ThreadPrimitiveMessages = ({
|
1794
|
+
components
|
1795
|
+
}) => {
|
1639
1796
|
const { useThread } = useThreadContext();
|
1640
1797
|
const messagesLength = useThread((t) => t.messages.length);
|
1641
1798
|
if (messagesLength === 0) return null;
|
@@ -1651,21 +1808,22 @@ var ThreadMessages = ({ components }) => {
|
|
1651
1808
|
);
|
1652
1809
|
});
|
1653
1810
|
};
|
1811
|
+
ThreadPrimitiveMessages.displayName = "ThreadPrimitive.Messages";
|
1654
1812
|
|
1655
1813
|
// src/primitives/thread/ThreadScrollToBottom.tsx
|
1656
|
-
var
|
1657
|
-
"
|
1814
|
+
var ThreadPrimitiveScrollToBottom = createActionButton(
|
1815
|
+
"ThreadPrimitive.ScrollToBottom",
|
1658
1816
|
useThreadScrollToBottom
|
1659
1817
|
);
|
1660
1818
|
|
1661
1819
|
// src/primitives/thread/ThreadSuggestion.tsx
|
1662
|
-
var
|
1663
|
-
"
|
1820
|
+
var ThreadPrimitiveSuggestion = createActionButton(
|
1821
|
+
"ThreadPrimitive.Suggestion",
|
1664
1822
|
useThreadSuggestion
|
1665
1823
|
);
|
1666
1824
|
|
1667
1825
|
// src/runtime/local/useLocalRuntime.tsx
|
1668
|
-
var
|
1826
|
+
var import_react49 = require("react");
|
1669
1827
|
|
1670
1828
|
// src/runtime/utils/idUtils.tsx
|
1671
1829
|
var import_non_secure = require("nanoid/non-secure");
|
@@ -1827,13 +1985,91 @@ var MessageRepository = class {
|
|
1827
1985
|
}
|
1828
1986
|
};
|
1829
1987
|
|
1988
|
+
// src/runtime/core/BaseAssistantRuntime.tsx
|
1989
|
+
var BaseAssistantRuntime = class {
|
1990
|
+
constructor(_thread) {
|
1991
|
+
this._thread = _thread;
|
1992
|
+
this._thread = _thread;
|
1993
|
+
this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
|
1994
|
+
}
|
1995
|
+
_unsubscribe;
|
1996
|
+
get thread() {
|
1997
|
+
return this._thread;
|
1998
|
+
}
|
1999
|
+
set thread(thread) {
|
2000
|
+
this._unsubscribe();
|
2001
|
+
this._thread = thread;
|
2002
|
+
this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
|
2003
|
+
this.subscriptionHandler();
|
2004
|
+
}
|
2005
|
+
get messages() {
|
2006
|
+
return this.thread.messages;
|
2007
|
+
}
|
2008
|
+
get isRunning() {
|
2009
|
+
return this.thread.isRunning;
|
2010
|
+
}
|
2011
|
+
getBranches(messageId) {
|
2012
|
+
return this.thread.getBranches(messageId);
|
2013
|
+
}
|
2014
|
+
switchToBranch(branchId) {
|
2015
|
+
return this.thread.switchToBranch(branchId);
|
2016
|
+
}
|
2017
|
+
append(message) {
|
2018
|
+
return this.thread.append(message);
|
2019
|
+
}
|
2020
|
+
startRun(parentId) {
|
2021
|
+
return this.thread.startRun(parentId);
|
2022
|
+
}
|
2023
|
+
cancelRun() {
|
2024
|
+
return this.thread.cancelRun();
|
2025
|
+
}
|
2026
|
+
addToolResult(toolCallId, result) {
|
2027
|
+
return this.thread.addToolResult(toolCallId, result);
|
2028
|
+
}
|
2029
|
+
_subscriptions = /* @__PURE__ */ new Set();
|
2030
|
+
subscribe(callback) {
|
2031
|
+
this._subscriptions.add(callback);
|
2032
|
+
return () => this._subscriptions.delete(callback);
|
2033
|
+
}
|
2034
|
+
subscriptionHandler = () => {
|
2035
|
+
for (const callback of this._subscriptions) callback();
|
2036
|
+
};
|
2037
|
+
get unstable_synchronizer() {
|
2038
|
+
return this.thread.unstable_synchronizer;
|
2039
|
+
}
|
2040
|
+
};
|
2041
|
+
|
1830
2042
|
// src/runtime/local/LocalRuntime.tsx
|
1831
|
-
var LocalRuntime = class {
|
2043
|
+
var LocalRuntime = class extends BaseAssistantRuntime {
|
2044
|
+
_configProviders;
|
1832
2045
|
constructor(adapter) {
|
2046
|
+
const configProviders = /* @__PURE__ */ new Set();
|
2047
|
+
super(new LocalThreadRuntime(configProviders, adapter));
|
2048
|
+
this._configProviders = configProviders;
|
2049
|
+
}
|
2050
|
+
set adapter(adapter) {
|
2051
|
+
this.thread.adapter = adapter;
|
2052
|
+
}
|
2053
|
+
registerModelConfigProvider(provider) {
|
2054
|
+
this._configProviders.add(provider);
|
2055
|
+
return () => this._configProviders.delete(provider);
|
2056
|
+
}
|
2057
|
+
switchToThread(threadId) {
|
2058
|
+
if (threadId) {
|
2059
|
+
throw new Error("LocalRuntime does not yet support switching threads");
|
2060
|
+
}
|
2061
|
+
return this.thread = new LocalThreadRuntime(
|
2062
|
+
this._configProviders,
|
2063
|
+
this.thread.adapter
|
2064
|
+
);
|
2065
|
+
}
|
2066
|
+
};
|
2067
|
+
var LocalThreadRuntime = class {
|
2068
|
+
constructor(_configProviders, adapter) {
|
2069
|
+
this._configProviders = _configProviders;
|
1833
2070
|
this.adapter = adapter;
|
1834
2071
|
}
|
1835
2072
|
_subscriptions = /* @__PURE__ */ new Set();
|
1836
|
-
_configProviders = /* @__PURE__ */ new Set();
|
1837
2073
|
abortController = null;
|
1838
2074
|
repository = new MessageRepository();
|
1839
2075
|
get messages() {
|
@@ -1912,96 +2148,24 @@ var LocalRuntime = class {
|
|
1912
2148
|
this._subscriptions.add(callback);
|
1913
2149
|
return () => this._subscriptions.delete(callback);
|
1914
2150
|
}
|
1915
|
-
registerModelConfigProvider(provider) {
|
1916
|
-
this._configProviders.add(provider);
|
1917
|
-
return () => this._configProviders.delete(provider);
|
1918
|
-
}
|
1919
2151
|
addToolResult() {
|
1920
|
-
throw new Error("LocalRuntime does not yet support tool results");
|
2152
|
+
throw new Error("LocalRuntime does not yet support adding tool results");
|
1921
2153
|
}
|
1922
2154
|
};
|
1923
2155
|
|
1924
2156
|
// src/runtime/local/useLocalRuntime.tsx
|
1925
2157
|
var useLocalRuntime = (adapter) => {
|
1926
|
-
const [runtime] = (0,
|
1927
|
-
(0,
|
2158
|
+
const [runtime] = (0, import_react49.useState)(() => new LocalRuntime(adapter));
|
2159
|
+
(0, import_react49.useInsertionEffect)(() => {
|
1928
2160
|
runtime.adapter = adapter;
|
1929
2161
|
});
|
1930
2162
|
return runtime;
|
1931
2163
|
};
|
1932
2164
|
|
1933
|
-
// src/model-config/useAssistantTool.tsx
|
1934
|
-
var import_react45 = require("react");
|
1935
|
-
var useAssistantTool = (tool) => {
|
1936
|
-
const { useModelConfig, useToolUIs } = useAssistantContext();
|
1937
|
-
const registerModelConfigProvider = useModelConfig(
|
1938
|
-
(s) => s.registerModelConfigProvider
|
1939
|
-
);
|
1940
|
-
const setToolUI = useToolUIs((s) => s.setToolUI);
|
1941
|
-
(0, import_react45.useEffect)(() => {
|
1942
|
-
const { toolName, render, ...rest } = tool;
|
1943
|
-
const config = {
|
1944
|
-
tools: {
|
1945
|
-
[tool.toolName]: rest
|
1946
|
-
}
|
1947
|
-
};
|
1948
|
-
const unsub1 = registerModelConfigProvider(() => config);
|
1949
|
-
const unsub2 = render ? setToolUI(toolName, render) : void 0;
|
1950
|
-
return () => {
|
1951
|
-
unsub1();
|
1952
|
-
unsub2?.();
|
1953
|
-
};
|
1954
|
-
}, [registerModelConfigProvider, setToolUI, tool]);
|
1955
|
-
};
|
1956
|
-
|
1957
|
-
// src/model-config/makeAssistantTool.tsx
|
1958
|
-
var makeAssistantTool = (tool) => {
|
1959
|
-
const Tool = () => {
|
1960
|
-
useAssistantTool(tool);
|
1961
|
-
return null;
|
1962
|
-
};
|
1963
|
-
return Tool;
|
1964
|
-
};
|
1965
|
-
|
1966
|
-
// src/model-config/useAssistantToolUI.tsx
|
1967
|
-
var import_react46 = require("react");
|
1968
|
-
var useAssistantToolUI = (tool) => {
|
1969
|
-
const { useToolUIs } = useAssistantContext();
|
1970
|
-
const setToolUI = useToolUIs((s) => s.setToolUI);
|
1971
|
-
(0, import_react46.useEffect)(() => {
|
1972
|
-
if (!tool) return;
|
1973
|
-
const { toolName, render } = tool;
|
1974
|
-
return setToolUI(toolName, render);
|
1975
|
-
}, [setToolUI, tool]);
|
1976
|
-
};
|
1977
|
-
|
1978
|
-
// src/model-config/makeAssistantToolUI.tsx
|
1979
|
-
var makeAssistantToolUI = (tool) => {
|
1980
|
-
const ToolUI = () => {
|
1981
|
-
useAssistantToolUI(tool);
|
1982
|
-
return null;
|
1983
|
-
};
|
1984
|
-
return ToolUI;
|
1985
|
-
};
|
1986
|
-
|
1987
|
-
// src/model-config/useAssistantInstructions.tsx
|
1988
|
-
var import_react47 = require("react");
|
1989
|
-
var useAssistantInstructions = (instruction) => {
|
1990
|
-
const { useModelConfig } = useAssistantContext();
|
1991
|
-
const registerModelConfigProvider = useModelConfig(
|
1992
|
-
(s) => s.registerModelConfigProvider
|
1993
|
-
);
|
1994
|
-
(0, import_react47.useEffect)(() => {
|
1995
|
-
const config = {
|
1996
|
-
system: instruction
|
1997
|
-
};
|
1998
|
-
return registerModelConfigProvider(() => config);
|
1999
|
-
}, [registerModelConfigProvider, instruction]);
|
2000
|
-
};
|
2001
|
-
|
2002
2165
|
// src/internal.ts
|
2003
2166
|
var internal_exports = {};
|
2004
2167
|
__export(internal_exports, {
|
2168
|
+
BaseAssistantRuntime: () => BaseAssistantRuntime,
|
2005
2169
|
MessageRepository: () => MessageRepository,
|
2006
2170
|
ProxyConfigProvider: () => ProxyConfigProvider
|
2007
2171
|
});
|
@@ -2021,6 +2185,7 @@ __export(internal_exports, {
|
|
2021
2185
|
useActionBarCopy,
|
2022
2186
|
useActionBarEdit,
|
2023
2187
|
useActionBarReload,
|
2188
|
+
useAppendMessage,
|
2024
2189
|
useAssistantContext,
|
2025
2190
|
useAssistantInstructions,
|
2026
2191
|
useAssistantTool,
|
@@ -2041,6 +2206,7 @@ __export(internal_exports, {
|
|
2041
2206
|
useLocalRuntime,
|
2042
2207
|
useMessageContext,
|
2043
2208
|
useMessageIf,
|
2209
|
+
useSwitchToNewThread,
|
2044
2210
|
useThreadContext,
|
2045
2211
|
useThreadEmpty,
|
2046
2212
|
useThreadIf,
|