@assistant-ui/react 0.5.65 → 0.5.66
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +346 -297
- package/dist/index.d.ts +346 -297
- package/dist/index.js +341 -441
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +470 -570
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -17,9 +17,6 @@ var _chunkPZ5AY32Cjs = require('./chunk-PZ5AY32C.js');
|
|
17
17
|
// src/context/providers/AssistantRuntimeProvider.tsx
|
18
18
|
var _react = require('react');
|
19
19
|
|
20
|
-
// src/context/providers/AssistantProvider.tsx
|
21
|
-
|
22
|
-
|
23
20
|
// src/context/react/AssistantContext.ts
|
24
21
|
|
25
22
|
|
@@ -121,7 +118,7 @@ var makeAssistantToolUIsStore = () => _zustand.create.call(void 0, (set) => {
|
|
121
118
|
});
|
122
119
|
});
|
123
120
|
|
124
|
-
// src/context/providers/
|
121
|
+
// src/context/providers/ThreadRuntimeProvider.tsx
|
125
122
|
|
126
123
|
|
127
124
|
// src/context/react/ThreadContext.ts
|
@@ -159,10 +156,9 @@ var {
|
|
159
156
|
|
160
157
|
// src/context/stores/ThreadComposer.ts
|
161
158
|
|
162
|
-
var makeThreadComposerStore = (
|
159
|
+
var makeThreadComposerStore = (runtime) => {
|
163
160
|
const focusListeners = /* @__PURE__ */ new Set();
|
164
161
|
return _zustand.create.call(void 0, )((_, get) => {
|
165
|
-
const runtime = useThreadRuntime2.getState();
|
166
162
|
return {
|
167
163
|
type: "thread",
|
168
164
|
get value() {
|
@@ -171,30 +167,27 @@ var makeThreadComposerStore = (useThreadRuntime2) => {
|
|
171
167
|
setValue(value) {
|
172
168
|
get().setText(value);
|
173
169
|
},
|
174
|
-
|
175
|
-
|
170
|
+
...runtime.getState(),
|
171
|
+
canCancel: false,
|
172
|
+
// "TODO",
|
173
|
+
isEditing: true,
|
176
174
|
addAttachment: (file) => {
|
177
|
-
|
175
|
+
runtime.addAttachment(file);
|
178
176
|
},
|
179
177
|
removeAttachment: (attachmentId) => {
|
180
|
-
|
178
|
+
runtime.removeAttachment(attachmentId);
|
181
179
|
},
|
182
180
|
reset: () => {
|
183
|
-
|
181
|
+
runtime.reset();
|
184
182
|
},
|
185
|
-
text: runtime.composer.text,
|
186
183
|
setText: (text) => {
|
187
|
-
|
184
|
+
runtime.setText(text);
|
188
185
|
},
|
189
|
-
canCancel: runtime.capabilities.cancel,
|
190
|
-
isEditing: true,
|
191
|
-
isEmpty: runtime.composer.isEmpty,
|
192
186
|
send: () => {
|
193
|
-
|
194
|
-
runtime2.composer.send();
|
187
|
+
runtime.send();
|
195
188
|
},
|
196
189
|
cancel: () => {
|
197
|
-
|
190
|
+
runtime.cancel();
|
198
191
|
},
|
199
192
|
focus: () => {
|
200
193
|
for (const listener of focusListeners) {
|
@@ -211,22 +204,6 @@ var makeThreadComposerStore = (useThreadRuntime2) => {
|
|
211
204
|
});
|
212
205
|
};
|
213
206
|
|
214
|
-
// src/context/stores/Thread.ts
|
215
|
-
|
216
|
-
var getThreadStateFromRuntime = (runtime) => {
|
217
|
-
const lastMessage = runtime.messages.at(-1);
|
218
|
-
return Object.freeze({
|
219
|
-
threadId: runtime.threadId,
|
220
|
-
capabilities: runtime.capabilities,
|
221
|
-
isDisabled: runtime.isDisabled,
|
222
|
-
isRunning: _optionalChain([lastMessage, 'optionalAccess', _5 => _5.role]) !== "assistant" ? false : lastMessage.status.type === "running"
|
223
|
-
});
|
224
|
-
};
|
225
|
-
var makeThreadStore = (runtimeRef) => {
|
226
|
-
const runtime = runtimeRef.getState();
|
227
|
-
return _zustand.create.call(void 0, () => getThreadStateFromRuntime(runtime));
|
228
|
-
};
|
229
|
-
|
230
207
|
// src/context/stores/ThreadViewport.tsx
|
231
208
|
|
232
209
|
var makeThreadViewportStore = () => {
|
@@ -247,85 +224,65 @@ var makeThreadViewportStore = () => {
|
|
247
224
|
}));
|
248
225
|
};
|
249
226
|
|
250
|
-
// src/context/stores/ThreadMessages.ts
|
251
|
-
|
252
|
-
var makeThreadMessagesStore = (runtimeRef) => {
|
253
|
-
return _zustand.create.call(void 0, () => runtimeRef.getState().messages);
|
254
|
-
};
|
255
|
-
|
256
227
|
// src/context/ReadonlyStore.ts
|
257
228
|
var writableStore = (store) => {
|
258
229
|
return store;
|
259
230
|
};
|
260
231
|
|
261
|
-
// src/context/providers/
|
232
|
+
// src/context/providers/ThreadRuntimeProvider.tsx
|
262
233
|
|
263
234
|
var _jsxruntime = require('react/jsx-runtime');
|
264
|
-
var
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
235
|
+
var useThreadRuntimeStore2 = (runtime) => {
|
236
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime));
|
237
|
+
_react.useEffect.call(void 0, () => {
|
238
|
+
writableStore(store).setState(runtime, true);
|
239
|
+
}, [runtime, store]);
|
240
|
+
return store;
|
241
|
+
};
|
242
|
+
var useThreadStore2 = (runtime) => {
|
243
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime.getState()));
|
244
|
+
_react.useEffect.call(void 0, () => {
|
245
|
+
const updateState = () => writableStore(store).setState(runtime.getState(), true);
|
246
|
+
updateState();
|
247
|
+
return runtime.subscribe(updateState);
|
248
|
+
}, [runtime, store]);
|
249
|
+
return store;
|
250
|
+
};
|
251
|
+
var useThreadMessagesStore2 = (runtime) => {
|
252
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime.messages));
|
253
|
+
_react.useEffect.call(void 0, () => {
|
254
|
+
const updateState = () => writableStore(store).setState(runtime.messages, true);
|
255
|
+
updateState();
|
256
|
+
return runtime.subscribe(updateState);
|
257
|
+
}, [runtime, store]);
|
258
|
+
return store;
|
259
|
+
};
|
260
|
+
var useThreadComposerStore2 = (runtime) => {
|
261
|
+
const [store] = _react.useState.call(void 0, () => makeThreadComposerStore(runtime));
|
262
|
+
_react.useEffect.call(void 0, () => {
|
263
|
+
const updateState = () => writableStore(store).setState(runtime.getState());
|
264
|
+
updateState();
|
265
|
+
return runtime.subscribe(updateState);
|
266
|
+
}, [runtime, store]);
|
267
|
+
return store;
|
268
|
+
};
|
269
|
+
var ThreadRuntimeProvider = ({ children, runtime }) => {
|
270
|
+
const useThreadRuntime2 = useThreadRuntimeStore2(runtime);
|
271
|
+
const useThread2 = useThreadStore2(runtime);
|
272
|
+
const useThreadMessages2 = useThreadMessagesStore2(runtime);
|
273
|
+
const useThreadComposer2 = useThreadComposerStore2(runtime.composer);
|
274
|
+
const context = _react.useMemo.call(void 0, () => {
|
272
275
|
const useViewport = makeThreadViewportStore();
|
273
|
-
const useComposer2 = makeThreadComposerStore(useThreadRuntime2);
|
274
276
|
return {
|
275
277
|
useThread: useThread2,
|
276
278
|
useThreadRuntime: useThreadRuntime2,
|
277
279
|
useThreadMessages: useThreadMessages2,
|
278
280
|
useThreadActions: useThreadRuntime2,
|
279
|
-
useComposer:
|
281
|
+
useComposer: useThreadComposer2,
|
280
282
|
useViewport
|
281
283
|
};
|
282
|
-
});
|
283
|
-
|
284
|
-
const onThreadUpdate = () => {
|
285
|
-
const oldState = context.useThread.getState();
|
286
|
-
const state = getThreadStateFromRuntime(thread);
|
287
|
-
if (oldState.threadId !== state.threadId || oldState.isDisabled !== state.isDisabled || oldState.isRunning !== state.isRunning || oldState.capabilities !== state.capabilities) {
|
288
|
-
writableStore(context.useThread).setState(state, true);
|
289
|
-
}
|
290
|
-
if (thread.messages !== context.useThreadMessages.getState()) {
|
291
|
-
writableStore(context.useThreadMessages).setState(
|
292
|
-
thread.messages,
|
293
|
-
true
|
294
|
-
);
|
295
|
-
}
|
296
|
-
const composerState = context.useComposer.getState();
|
297
|
-
if (state.capabilities.cancel !== composerState.canCancel) {
|
298
|
-
writableStore(context.useComposer).setState({
|
299
|
-
canCancel: state.capabilities.cancel
|
300
|
-
});
|
301
|
-
}
|
302
|
-
};
|
303
|
-
onThreadUpdate();
|
304
|
-
return thread.subscribe(onThreadUpdate);
|
305
|
-
}, [thread, context]);
|
306
|
-
_react.useEffect.call(void 0, () => {
|
307
|
-
const onComposerUpdate = () => {
|
308
|
-
const composer = thread.composer;
|
309
|
-
const composerState = context.useComposer.getState();
|
310
|
-
if (composer.isEmpty !== composerState.isEmpty || composer.text !== composerState.text || composer.attachmentAccept !== composerState.attachmentAccept || composer.attachments !== composerState.attachments) {
|
311
|
-
writableStore(context.useComposer).setState({
|
312
|
-
isEmpty: composer.isEmpty,
|
313
|
-
text: composer.text,
|
314
|
-
attachmentAccept: composer.attachmentAccept,
|
315
|
-
attachments: composer.attachments
|
316
|
-
});
|
317
|
-
}
|
318
|
-
};
|
319
|
-
onComposerUpdate();
|
320
|
-
return thread.composer.subscribe(onComposerUpdate);
|
321
|
-
}, [thread, context]);
|
322
|
-
_react.useEffect.call(void 0,
|
323
|
-
() => thread.subscribe(() => {
|
324
|
-
writableStore(context.useThreadRuntime).setState(thread, true);
|
325
|
-
}),
|
326
|
-
[thread, context]
|
327
|
-
);
|
328
|
-
const Synchronizer = context.useThreadRuntime(
|
284
|
+
}, [useThread2, useThreadRuntime2, useThreadMessages2, useThreadComposer2]);
|
285
|
+
const Synchronizer = context.useThread(
|
329
286
|
(t) => t.unstable_synchronizer
|
330
287
|
);
|
331
288
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, ThreadContext.Provider, { value: context, children: [
|
@@ -334,34 +291,30 @@ var ThreadProvider = ({
|
|
334
291
|
] });
|
335
292
|
};
|
336
293
|
|
337
|
-
// src/context/providers/
|
294
|
+
// src/context/providers/AssistantRuntimeProvider.tsx
|
338
295
|
|
339
296
|
|
340
|
-
var
|
341
|
-
const
|
342
|
-
_react.
|
343
|
-
|
344
|
-
});
|
345
|
-
|
346
|
-
|
347
|
-
|
297
|
+
var useAssistantRuntimeStore2 = (runtime) => {
|
298
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime));
|
299
|
+
_react.useEffect.call(void 0, () => {
|
300
|
+
writableStore(store).setState(runtime, true);
|
301
|
+
}, [runtime, store]);
|
302
|
+
return store;
|
303
|
+
};
|
304
|
+
var useAssistantToolUIsStore = () => {
|
305
|
+
return _react.useMemo.call(void 0, () => makeAssistantToolUIsStore(), []);
|
306
|
+
};
|
307
|
+
var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
308
|
+
const useAssistantRuntime2 = useAssistantRuntimeStore2(runtime);
|
309
|
+
const useToolUIs2 = useAssistantToolUIsStore();
|
310
|
+
const context = _react.useMemo.call(void 0, () => {
|
348
311
|
return {
|
349
312
|
useToolUIs: useToolUIs2,
|
350
313
|
useAssistantRuntime: useAssistantRuntime2,
|
351
314
|
useAssistantActions: useAssistantRuntime2
|
352
315
|
};
|
353
|
-
});
|
354
|
-
|
355
|
-
() => writableStore(context.useAssistantRuntime).setState(runtime, true),
|
356
|
-
[runtime, context]
|
357
|
-
);
|
358
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AssistantContext.Provider, { value: context, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadProvider, { provider: runtime.thread, children }) });
|
359
|
-
};
|
360
|
-
|
361
|
-
// src/context/providers/AssistantRuntimeProvider.tsx
|
362
|
-
|
363
|
-
var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
|
364
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AssistantProvider, { runtime, children });
|
316
|
+
}, [useAssistantRuntime2, useToolUIs2]);
|
317
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AssistantContext.Provider, { value: context, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadRuntimeProvider, { runtime: runtime.thread, children }) });
|
365
318
|
};
|
366
319
|
var AssistantRuntimeProvider = _react.memo.call(void 0, AssistantRuntimeProviderImpl);
|
367
320
|
|
@@ -426,6 +379,11 @@ var useMessageContext = createContextHook(
|
|
426
379
|
MessageContext,
|
427
380
|
"a component passed to <ThreadPrimitive.Messages components={...} />"
|
428
381
|
);
|
382
|
+
function useMessageRuntime(options) {
|
383
|
+
const context = useMessageContext(options);
|
384
|
+
if (!context) return null;
|
385
|
+
return context.useMessageRuntime();
|
386
|
+
}
|
429
387
|
var { useMessage, useMessageStore } = createContextStoreHook(
|
430
388
|
useMessageContext,
|
431
389
|
"useMessage"
|
@@ -459,40 +417,17 @@ var { useComposer, useComposerStore } = createContextStoreHook(
|
|
459
417
|
|
460
418
|
// src/hooks/useAppendMessage.tsx
|
461
419
|
|
462
|
-
var toAppendMessage = (useThreadMessages2, message) => {
|
463
|
-
if (typeof message === "string") {
|
464
|
-
return {
|
465
|
-
parentId: _nullishCoalesce(_optionalChain([useThreadMessages2, 'access', _6 => _6.getState, 'call', _7 => _7(), 'access', _8 => _8.at, 'call', _9 => _9(-1), 'optionalAccess', _10 => _10.id]), () => ( null)),
|
466
|
-
role: "user",
|
467
|
-
content: [{ type: "text", text: message }],
|
468
|
-
attachments: []
|
469
|
-
};
|
470
|
-
}
|
471
|
-
return {
|
472
|
-
parentId: _nullishCoalesce(_nullishCoalesce(message.parentId, () => ( _optionalChain([useThreadMessages2, 'access', _11 => _11.getState, 'call', _12 => _12(), 'access', _13 => _13.at, 'call', _14 => _14(-1), 'optionalAccess', _15 => _15.id]))), () => ( null)),
|
473
|
-
role: _nullishCoalesce(message.role, () => ( "user")),
|
474
|
-
content: message.content,
|
475
|
-
attachments: _nullishCoalesce(message.attachments, () => ( []))
|
476
|
-
};
|
477
|
-
};
|
478
420
|
var useAppendMessage = () => {
|
479
|
-
const threadMessagesStore = useThreadMessagesStore();
|
480
421
|
const threadRuntime = useThreadRuntime();
|
481
422
|
const threadViewportStore = useThreadViewportStore();
|
482
423
|
const threadComposerStore = useThreadComposerStore();
|
483
424
|
const append = _react.useCallback.call(void 0,
|
484
425
|
(message) => {
|
485
|
-
|
486
|
-
threadRuntime.append(appendMessage);
|
426
|
+
threadRuntime.append(message);
|
487
427
|
threadViewportStore.getState().scrollToBottom();
|
488
428
|
threadComposerStore.getState().focus();
|
489
429
|
},
|
490
|
-
[
|
491
|
-
threadMessagesStore,
|
492
|
-
threadRuntime,
|
493
|
-
threadViewportStore,
|
494
|
-
threadComposerStore
|
495
|
-
]
|
430
|
+
[threadRuntime, threadViewportStore, threadComposerStore]
|
496
431
|
);
|
497
432
|
return append;
|
498
433
|
};
|
@@ -527,7 +462,7 @@ var useAssistantTool = (tool) => {
|
|
527
462
|
const unsub2 = render ? toolUIsStore.getState().setToolUI(toolName, render) : void 0;
|
528
463
|
return () => {
|
529
464
|
unsub1();
|
530
|
-
_optionalChain([unsub2, 'optionalCall',
|
465
|
+
_optionalChain([unsub2, 'optionalCall', _5 => _5()]);
|
531
466
|
};
|
532
467
|
}, [assistantRuntime, toolUIsStore, tool]);
|
533
468
|
};
|
@@ -623,12 +558,12 @@ var useActionBarCopy = ({
|
|
623
558
|
const editComposerStore = useEditComposerStore();
|
624
559
|
const hasCopyableContent = useCombinedStore(
|
625
560
|
[messageStore, editComposerStore],
|
626
|
-
(
|
561
|
+
(message, c) => {
|
627
562
|
return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
|
628
563
|
}
|
629
564
|
);
|
630
565
|
const callback = _react.useCallback.call(void 0, () => {
|
631
|
-
const
|
566
|
+
const message = messageStore.getState();
|
632
567
|
const { setIsCopied } = messageUtilsStore.getState();
|
633
568
|
const { isEditing, text: composerValue } = editComposerStore.getState();
|
634
569
|
const valueToCopy = isEditing ? composerValue : getThreadMessageText(message);
|
@@ -664,7 +599,7 @@ var useActionBarReload = () => {
|
|
664
599
|
const threadViewportStore = useThreadViewportStore();
|
665
600
|
const disabled = useCombinedStore(
|
666
601
|
[threadStore, messageStore],
|
667
|
-
(t, m) => t.isRunning || t.isDisabled || m.
|
602
|
+
(t, m) => t.isRunning || t.isDisabled || m.role !== "assistant"
|
668
603
|
);
|
669
604
|
const callback = _react.useCallback.call(void 0, () => {
|
670
605
|
const { parentId } = messageStore.getState();
|
@@ -718,7 +653,7 @@ var useActionBarFeedbackPositive = () => {
|
|
718
653
|
const messageUtilsStore = useMessageUtilsStore();
|
719
654
|
const callback = _react.useCallback.call(void 0, () => {
|
720
655
|
threadRuntime.submitFeedback({
|
721
|
-
messageId: messageStore.getState().
|
656
|
+
messageId: messageStore.getState().id,
|
722
657
|
type: "positive"
|
723
658
|
});
|
724
659
|
messageUtilsStore.getState().setSubmittedFeedback("positive");
|
@@ -734,7 +669,7 @@ var useActionBarFeedbackNegative = () => {
|
|
734
669
|
const messageUtilsStore = useMessageUtilsStore();
|
735
670
|
const callback = _react.useCallback.call(void 0, () => {
|
736
671
|
threadRuntime.submitFeedback({
|
737
|
-
messageId: messageStore.getState().
|
672
|
+
messageId: messageStore.getState().id,
|
738
673
|
type: "negative"
|
739
674
|
});
|
740
675
|
messageUtilsStore.getState().setSubmittedFeedback("negative");
|
@@ -744,48 +679,46 @@ var useActionBarFeedbackNegative = () => {
|
|
744
679
|
|
745
680
|
// src/primitive-hooks/branchPicker/useBranchPickerCount.tsx
|
746
681
|
var useBranchPickerCount = () => {
|
747
|
-
const branchCount = useMessage((s) => s.
|
682
|
+
const branchCount = useMessage((s) => s.branchCount);
|
748
683
|
return branchCount;
|
749
684
|
};
|
750
685
|
|
751
686
|
// src/primitive-hooks/branchPicker/useBranchPickerNext.tsx
|
752
687
|
|
753
688
|
var useBranchPickerNext = () => {
|
689
|
+
const messageRuntime = useMessageRuntime();
|
754
690
|
const messageStore = useMessageStore();
|
755
691
|
const editComposerStore = useEditComposerStore();
|
756
|
-
const threadRuntime = useThreadRuntime();
|
757
692
|
const disabled = useCombinedStore(
|
758
693
|
[messageStore, editComposerStore],
|
759
|
-
(m, c) => c.isEditing || m.
|
694
|
+
(m, c) => c.isEditing || m.branchNumber >= m.branchCount
|
760
695
|
);
|
761
696
|
const callback = _react.useCallback.call(void 0, () => {
|
762
|
-
|
763
|
-
|
764
|
-
}, [threadRuntime, messageStore]);
|
697
|
+
messageRuntime.switchToBranch({ position: "next" });
|
698
|
+
}, [messageRuntime]);
|
765
699
|
if (disabled) return null;
|
766
700
|
return callback;
|
767
701
|
};
|
768
702
|
|
769
703
|
// src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx
|
770
704
|
var useBranchPickerNumber = () => {
|
771
|
-
const
|
772
|
-
return
|
705
|
+
const branchNumber = useMessage((s) => s.branchNumber);
|
706
|
+
return branchNumber;
|
773
707
|
};
|
774
708
|
|
775
709
|
// src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx
|
776
710
|
|
777
711
|
var useBranchPickerPrevious = () => {
|
712
|
+
const messageRuntime = useMessageRuntime();
|
778
713
|
const messageStore = useMessageStore();
|
779
714
|
const editComposerStore = useEditComposerStore();
|
780
|
-
const threadRuntime = useThreadRuntime();
|
781
715
|
const disabled = useCombinedStore(
|
782
716
|
[messageStore, editComposerStore],
|
783
|
-
(m, c) => c.isEditing || m.
|
717
|
+
(m, c) => c.isEditing || m.branchNumber <= 1
|
784
718
|
);
|
785
719
|
const callback = _react.useCallback.call(void 0, () => {
|
786
|
-
|
787
|
-
|
788
|
-
}, [threadRuntime, messageStore]);
|
720
|
+
messageRuntime.switchToBranch({ position: "previous" });
|
721
|
+
}, [messageRuntime]);
|
789
722
|
if (disabled) return null;
|
790
723
|
return callback;
|
791
724
|
};
|
@@ -849,7 +782,7 @@ var useComposerAddAttachment = () => {
|
|
849
782
|
input.accept = attachmentAccept;
|
850
783
|
}
|
851
784
|
input.onchange = (e) => {
|
852
|
-
const file = _optionalChain([e, 'access',
|
785
|
+
const file = _optionalChain([e, 'access', _6 => _6.target, 'access', _7 => _7.files, 'optionalAccess', _8 => _8[0]]);
|
853
786
|
if (!file) return;
|
854
787
|
addAttachment(file);
|
855
788
|
};
|
@@ -901,19 +834,19 @@ var useMessageIf = (props) => {
|
|
901
834
|
const messageUtilsStore = useMessageUtilsStore();
|
902
835
|
return useCombinedStore(
|
903
836
|
[messageStore, messageUtilsStore],
|
904
|
-
({
|
905
|
-
if (props.hasBranches === true &&
|
906
|
-
if (props.user &&
|
907
|
-
if (props.assistant &&
|
908
|
-
if (props.system &&
|
837
|
+
({ role, attachments, branchCount, isLast }, { isCopied, isHovering, isSpeaking, submittedFeedback }) => {
|
838
|
+
if (props.hasBranches === true && branchCount < 2) return false;
|
839
|
+
if (props.user && role !== "user") return false;
|
840
|
+
if (props.assistant && role !== "assistant") return false;
|
841
|
+
if (props.system && role !== "system") return false;
|
909
842
|
if (props.lastOrHover === true && !isHovering && !isLast) return false;
|
910
843
|
if (props.copied === true && !isCopied) return false;
|
911
844
|
if (props.copied === false && isCopied) return false;
|
912
845
|
if (props.speaking === true && !isSpeaking) return false;
|
913
846
|
if (props.speaking === false && isSpeaking) return false;
|
914
|
-
if (props.hasAttachments === true && (
|
847
|
+
if (props.hasAttachments === true && (role !== "user" || !attachments.length))
|
915
848
|
return false;
|
916
|
-
if (props.hasAttachments === false &&
|
849
|
+
if (props.hasAttachments === false && role === "user" && !!attachments.length)
|
917
850
|
return false;
|
918
851
|
if (props.submittedFeedback !== void 0 && submittedFeedback !== props.submittedFeedback)
|
919
852
|
return false;
|
@@ -1060,7 +993,7 @@ var ActionBarPrimitiveCopy = _react.forwardRef.call(void 0, ({ copiedDuration, o
|
|
1060
993
|
ref: forwardedRef,
|
1061
994
|
disabled: disabled || !callback,
|
1062
995
|
onClick: _primitive.composeEventHandlers.call(void 0, onClick, () => {
|
1063
|
-
_optionalChain([callback, 'optionalCall',
|
996
|
+
_optionalChain([callback, 'optionalCall', _9 => _9()]);
|
1064
997
|
})
|
1065
998
|
}
|
1066
999
|
);
|
@@ -1092,7 +1025,7 @@ var createActionButton = (displayName, useActionButton, forwardProps = []) => {
|
|
1092
1025
|
ref: forwardedRef,
|
1093
1026
|
disabled: primitiveProps.disabled || !callback,
|
1094
1027
|
onClick: _primitive.composeEventHandlers.call(void 0, primitiveProps.onClick, () => {
|
1095
|
-
_optionalChain([callback, 'optionalCall',
|
1028
|
+
_optionalChain([callback, 'optionalCall', _10 => _10()]);
|
1096
1029
|
})
|
1097
1030
|
}
|
1098
1031
|
);
|
@@ -1141,7 +1074,7 @@ var ActionBarPrimitiveStopSpeaking = _react.forwardRef.call(void 0, (props, ref)
|
|
1141
1074
|
...props,
|
1142
1075
|
ref,
|
1143
1076
|
onClick: _primitive.composeEventHandlers.call(void 0, props.onClick, () => {
|
1144
|
-
_optionalChain([callback, 'optionalCall',
|
1077
|
+
_optionalChain([callback, 'optionalCall', _11 => _11()]);
|
1145
1078
|
})
|
1146
1079
|
}
|
1147
1080
|
);
|
@@ -1167,7 +1100,7 @@ var ActionBarPrimitiveFeedbackPositive = _react.forwardRef.call(void 0, ({ onCli
|
|
1167
1100
|
ref: forwardedRef,
|
1168
1101
|
disabled: disabled || !callback,
|
1169
1102
|
onClick: _primitive.composeEventHandlers.call(void 0, onClick, () => {
|
1170
|
-
_optionalChain([callback, 'optionalCall',
|
1103
|
+
_optionalChain([callback, 'optionalCall', _12 => _12()]);
|
1171
1104
|
})
|
1172
1105
|
}
|
1173
1106
|
);
|
@@ -1193,7 +1126,7 @@ var ActionBarPrimitiveFeedbackNegative = _react.forwardRef.call(void 0, ({ onCli
|
|
1193
1126
|
ref: forwardedRef,
|
1194
1127
|
disabled: disabled || !callback,
|
1195
1128
|
onClick: _primitive.composeEventHandlers.call(void 0, onClick, () => {
|
1196
|
-
_optionalChain([callback, 'optionalCall',
|
1129
|
+
_optionalChain([callback, 'optionalCall', _13 => _13()]);
|
1197
1130
|
})
|
1198
1131
|
}
|
1199
1132
|
);
|
@@ -1483,7 +1416,7 @@ var getContentPartState = ({ message }, useContentPart2, partIndex) => {
|
|
1483
1416
|
part = EMPTY_CONTENT;
|
1484
1417
|
}
|
1485
1418
|
const status = toContentPartStatus(message, partIndex, part);
|
1486
|
-
const currentState = _optionalChain([useContentPart2, 'optionalAccess',
|
1419
|
+
const currentState = _optionalChain([useContentPart2, 'optionalAccess', _14 => _14.getState, 'call', _15 => _15()]);
|
1487
1420
|
if (currentState && currentState.part === part && currentState.status === status)
|
1488
1421
|
return null;
|
1489
1422
|
return Object.freeze({ part, status });
|
@@ -1560,7 +1493,7 @@ var withSmoothContextProvider = (Component) => {
|
|
1560
1493
|
};
|
1561
1494
|
function useSmoothContext(options) {
|
1562
1495
|
const context = _react.useContext.call(void 0, SmoothContext);
|
1563
|
-
if (!_optionalChain([options, 'optionalAccess',
|
1496
|
+
if (!_optionalChain([options, 'optionalAccess', _16 => _16.optional]) && !context)
|
1564
1497
|
throw new Error(
|
1565
1498
|
"This component must be used within a SmoothContextProvider."
|
1566
1499
|
);
|
@@ -1625,7 +1558,7 @@ var useSmooth = (state, smooth = false) => {
|
|
1625
1558
|
} = state;
|
1626
1559
|
const id = useMessage({
|
1627
1560
|
optional: true,
|
1628
|
-
selector: (m) => m.
|
1561
|
+
selector: (m) => m.id
|
1629
1562
|
});
|
1630
1563
|
const idRef = _react.useRef.call(void 0, id);
|
1631
1564
|
const [displayedText, setDisplayedText] = _react.useState.call(void 0, text);
|
@@ -1767,7 +1700,7 @@ var MessageContentPartComponent = ({
|
|
1767
1700
|
case "tool-call": {
|
1768
1701
|
const Tool = by_name[part.toolName] || Fallback2;
|
1769
1702
|
const addResult = (result) => threadRuntime.addToolResult({
|
1770
|
-
messageId: messageStore.getState().
|
1703
|
+
messageId: messageStore.getState().id,
|
1771
1704
|
toolName: part.toolName,
|
1772
1705
|
toolCallId: part.toolCallId,
|
1773
1706
|
result
|
@@ -1795,12 +1728,12 @@ var MessageContentPartImpl = ({
|
|
1795
1728
|
};
|
1796
1729
|
var MessageContentPart = _react.memo.call(void 0,
|
1797
1730
|
MessageContentPartImpl,
|
1798
|
-
(prev, next) => prev.partIndex === next.partIndex && _optionalChain([prev, 'access',
|
1731
|
+
(prev, next) => prev.partIndex === next.partIndex && _optionalChain([prev, 'access', _17 => _17.components, 'optionalAccess', _18 => _18.Text]) === _optionalChain([next, 'access', _19 => _19.components, 'optionalAccess', _20 => _20.Text]) && _optionalChain([prev, 'access', _21 => _21.components, 'optionalAccess', _22 => _22.Image]) === _optionalChain([next, 'access', _23 => _23.components, 'optionalAccess', _24 => _24.Image]) && _optionalChain([prev, 'access', _25 => _25.components, 'optionalAccess', _26 => _26.UI]) === _optionalChain([next, 'access', _27 => _27.components, 'optionalAccess', _28 => _28.UI]) && _optionalChain([prev, 'access', _29 => _29.components, 'optionalAccess', _30 => _30.tools]) === _optionalChain([next, 'access', _31 => _31.components, 'optionalAccess', _32 => _32.tools])
|
1799
1732
|
);
|
1800
1733
|
var MessagePrimitiveContent = ({
|
1801
1734
|
components
|
1802
1735
|
}) => {
|
1803
|
-
const contentLength = useMessage((s) => s.
|
1736
|
+
const contentLength = useMessage((s) => s.content.length) || 1;
|
1804
1737
|
return Array.from({ length: contentLength }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageContentPart, { partIndex: index, components }, index));
|
1805
1738
|
};
|
1806
1739
|
MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
|
@@ -1821,7 +1754,7 @@ var AttachmentContext = _react.createContext.call(void 0,
|
|
1821
1754
|
);
|
1822
1755
|
function useAttachmentContext(options) {
|
1823
1756
|
const context = _react.useContext.call(void 0, AttachmentContext);
|
1824
|
-
if (!_optionalChain([options, 'optionalAccess',
|
1757
|
+
if (!_optionalChain([options, 'optionalAccess', _33 => _33.optional]) && !context)
|
1825
1758
|
throw new Error(
|
1826
1759
|
"This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
|
1827
1760
|
);
|
@@ -1862,12 +1795,12 @@ var {
|
|
1862
1795
|
|
1863
1796
|
|
1864
1797
|
|
1865
|
-
var getAttachment = (
|
1798
|
+
var getAttachment = (message, useAttachment2, partIndex) => {
|
1866
1799
|
if (message.role !== "user") return null;
|
1867
1800
|
const attachments = message.attachments;
|
1868
1801
|
const attachment = attachments[partIndex];
|
1869
1802
|
if (!attachment) return null;
|
1870
|
-
const currentState = _optionalChain([useAttachment2, 'optionalAccess',
|
1803
|
+
const currentState = _optionalChain([useAttachment2, 'optionalAccess', _34 => _34.getState, 'call', _35 => _35()]);
|
1871
1804
|
if (currentState && currentState.attachment === attachment) return null;
|
1872
1805
|
return Object.freeze({ attachment });
|
1873
1806
|
};
|
@@ -1910,11 +1843,11 @@ var getComponent = (components, attachment) => {
|
|
1910
1843
|
const type = attachment.type;
|
1911
1844
|
switch (type) {
|
1912
1845
|
case "image":
|
1913
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
1846
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _36 => _36.Image]), () => ( _optionalChain([components, 'optionalAccess', _37 => _37.Attachment])));
|
1914
1847
|
case "document":
|
1915
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
1848
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _38 => _38.Document]), () => ( _optionalChain([components, 'optionalAccess', _39 => _39.Attachment])));
|
1916
1849
|
case "file":
|
1917
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
1850
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _40 => _40.File]), () => ( _optionalChain([components, 'optionalAccess', _41 => _41.Attachment])));
|
1918
1851
|
default:
|
1919
1852
|
const _exhaustiveCheck = type;
|
1920
1853
|
throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
|
@@ -1932,7 +1865,7 @@ var MessageAttachmentImpl = ({ components, attachmentIndex }) => {
|
|
1932
1865
|
};
|
1933
1866
|
var MessageAttachment = _react.memo.call(void 0,
|
1934
1867
|
MessageAttachmentImpl,
|
1935
|
-
(prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access',
|
1868
|
+
(prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _42 => _42.components, 'optionalAccess', _43 => _43.Image]) === _optionalChain([next, 'access', _44 => _44.components, 'optionalAccess', _45 => _45.Image]) && _optionalChain([prev, 'access', _46 => _46.components, 'optionalAccess', _47 => _47.Document]) === _optionalChain([next, 'access', _48 => _48.components, 'optionalAccess', _49 => _49.Document]) && _optionalChain([prev, 'access', _50 => _50.components, 'optionalAccess', _51 => _51.File]) === _optionalChain([next, 'access', _52 => _52.components, 'optionalAccess', _53 => _53.File]) && _optionalChain([prev, 'access', _54 => _54.components, 'optionalAccess', _55 => _55.Attachment]) === _optionalChain([next, 'access', _56 => _56.components, 'optionalAccess', _57 => _57.Attachment])
|
1936
1869
|
);
|
1937
1870
|
var MessagePrimitiveAttachments = ({ components }) => {
|
1938
1871
|
const attachmentsCount = useMessage(({ message }) => {
|
@@ -2043,7 +1976,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
|
|
2043
1976
|
const { isRunning } = threadStore.getState();
|
2044
1977
|
if (!isRunning) {
|
2045
1978
|
e.preventDefault();
|
2046
|
-
_optionalChain([textareaRef, 'access',
|
1979
|
+
_optionalChain([textareaRef, 'access', _58 => _58.current, 'optionalAccess', _59 => _59.closest, 'call', _60 => _60("form"), 'optionalAccess', _61 => _61.requestSubmit, 'call', _62 => _62()]);
|
2047
1980
|
}
|
2048
1981
|
}
|
2049
1982
|
};
|
@@ -2111,7 +2044,7 @@ var ComposerPrimitiveAddAttachment = createActionButton(
|
|
2111
2044
|
var getAttachment2 = ({ attachments }, useAttachment2, partIndex) => {
|
2112
2045
|
const attachment = attachments[partIndex];
|
2113
2046
|
if (!attachment) return null;
|
2114
|
-
const currentState = _optionalChain([useAttachment2, 'optionalAccess',
|
2047
|
+
const currentState = _optionalChain([useAttachment2, 'optionalAccess', _63 => _63.getState, 'call', _64 => _64()]);
|
2115
2048
|
if (currentState && currentState.attachment === attachment) return null;
|
2116
2049
|
return Object.freeze({ attachment });
|
2117
2050
|
};
|
@@ -2151,11 +2084,11 @@ var getComponent2 = (components, attachment) => {
|
|
2151
2084
|
const type = attachment.type;
|
2152
2085
|
switch (type) {
|
2153
2086
|
case "image":
|
2154
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
2087
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _65 => _65.Image]), () => ( _optionalChain([components, 'optionalAccess', _66 => _66.Attachment])));
|
2155
2088
|
case "document":
|
2156
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
2089
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _67 => _67.Document]), () => ( _optionalChain([components, 'optionalAccess', _68 => _68.Attachment])));
|
2157
2090
|
case "file":
|
2158
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
2091
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _69 => _69.File]), () => ( _optionalChain([components, 'optionalAccess', _70 => _70.Attachment])));
|
2159
2092
|
default:
|
2160
2093
|
const _exhaustiveCheck = type;
|
2161
2094
|
throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
|
@@ -2173,7 +2106,7 @@ var ComposerAttachmentImpl = ({ components, attachmentIndex }) => {
|
|
2173
2106
|
};
|
2174
2107
|
var ComposerAttachment = _react.memo.call(void 0,
|
2175
2108
|
ComposerAttachmentImpl,
|
2176
|
-
(prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access',
|
2109
|
+
(prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _71 => _71.components, 'optionalAccess', _72 => _72.Image]) === _optionalChain([next, 'access', _73 => _73.components, 'optionalAccess', _74 => _74.Image]) && _optionalChain([prev, 'access', _75 => _75.components, 'optionalAccess', _76 => _76.Document]) === _optionalChain([next, 'access', _77 => _77.components, 'optionalAccess', _78 => _78.Document]) && _optionalChain([prev, 'access', _79 => _79.components, 'optionalAccess', _80 => _80.File]) === _optionalChain([next, 'access', _81 => _81.components, 'optionalAccess', _82 => _82.File]) && _optionalChain([prev, 'access', _83 => _83.components, 'optionalAccess', _84 => _84.Attachment]) === _optionalChain([next, 'access', _85 => _85.components, 'optionalAccess', _86 => _86.Attachment])
|
2177
2110
|
);
|
2178
2111
|
var ComposerPrimitiveAttachments = ({ components }) => {
|
2179
2112
|
const attachmentsCount = useThreadComposer((s) => s.attachments.length);
|
@@ -2374,7 +2307,7 @@ ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
|
2374
2307
|
// src/primitives/thread/ThreadMessages.tsx
|
2375
2308
|
|
2376
2309
|
|
2377
|
-
// src/context/providers/
|
2310
|
+
// src/context/providers/MessageRuntimeProvider.tsx
|
2378
2311
|
|
2379
2312
|
|
2380
2313
|
|
@@ -2432,7 +2365,7 @@ var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => {
|
|
2432
2365
|
},
|
2433
2366
|
isSpeaking: false,
|
2434
2367
|
stopSpeaking: () => {
|
2435
|
-
_optionalChain([utterance, 'optionalAccess',
|
2368
|
+
_optionalChain([utterance, 'optionalAccess', _87 => _87.cancel, 'call', _88 => _88()]);
|
2436
2369
|
},
|
2437
2370
|
addUtterance: (utt) => {
|
2438
2371
|
utterance = utt;
|
@@ -2448,84 +2381,65 @@ var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => {
|
|
2448
2381
|
};
|
2449
2382
|
});
|
2450
2383
|
|
2451
|
-
// src/context/providers/
|
2384
|
+
// src/context/providers/MessageRuntimeProvider.tsx
|
2452
2385
|
|
2453
|
-
var
|
2454
|
-
|
2386
|
+
var useMessageRuntimeStore = (runtime) => {
|
2387
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime));
|
2388
|
+
_react.useEffect.call(void 0, () => {
|
2389
|
+
writableStore(store).setState(runtime, true);
|
2390
|
+
}, [runtime, store]);
|
2391
|
+
return store;
|
2455
2392
|
};
|
2456
|
-
var
|
2457
|
-
const
|
2458
|
-
|
2459
|
-
|
2460
|
-
|
2461
|
-
|
2462
|
-
|
2463
|
-
|
2464
|
-
return null;
|
2465
|
-
return Object.freeze({
|
2466
|
-
message,
|
2467
|
-
parentId,
|
2468
|
-
branches,
|
2469
|
-
isLast
|
2470
|
-
});
|
2393
|
+
var useMessageStore2 = (runtime) => {
|
2394
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime.getState()));
|
2395
|
+
_react.useEffect.call(void 0, () => {
|
2396
|
+
const updateState = () => writableStore(store).setState(runtime.getState(), true);
|
2397
|
+
updateState();
|
2398
|
+
return runtime.subscribe(updateState);
|
2399
|
+
}, [runtime, store]);
|
2400
|
+
return store;
|
2471
2401
|
};
|
2472
|
-
var
|
2473
|
-
const
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
threadRuntime.getBranches.bind(threadRuntime),
|
2480
|
-
void 0,
|
2481
|
-
messageIndex
|
2482
|
-
)
|
2483
|
-
);
|
2484
|
-
const useMessageUtils2 = makeMessageUtilsStore();
|
2485
|
-
const useEditComposer2 = makeEditComposerStore({
|
2402
|
+
var useMessageUtilsStore2 = () => {
|
2403
|
+
const [store] = _react.useState.call(void 0, () => makeMessageUtilsStore());
|
2404
|
+
return store;
|
2405
|
+
};
|
2406
|
+
var useEditComposerStore2 = (useMessageRuntime2) => {
|
2407
|
+
const [store] = _react.useState.call(void 0,
|
2408
|
+
() => makeEditComposerStore({
|
2486
2409
|
onEdit: () => {
|
2487
|
-
const
|
2488
|
-
|
2410
|
+
const text = getThreadMessageText(
|
2411
|
+
useMessageRuntime2.getState().getState()
|
2412
|
+
);
|
2489
2413
|
return text;
|
2490
2414
|
},
|
2491
2415
|
onSend: (text) => {
|
2492
|
-
const
|
2416
|
+
const message = useMessageRuntime2.getState().getState();
|
2493
2417
|
const previousText = getThreadMessageText(message);
|
2494
2418
|
if (previousText === text) return;
|
2495
2419
|
const nonTextParts = message.content.filter(
|
2496
2420
|
(part) => part.type !== "text" && part.type !== "ui"
|
2497
2421
|
);
|
2498
|
-
|
2499
|
-
parentId,
|
2422
|
+
useMessageRuntime2.getState().edit({
|
2500
2423
|
role: message.role,
|
2501
2424
|
content: [{ type: "text", text }, ...nonTextParts],
|
2502
|
-
attachments: message.attachments
|
2425
|
+
attachments: _nullishCoalesce(message.attachments, () => ( []))
|
2503
2426
|
});
|
2504
2427
|
}
|
2505
|
-
})
|
2506
|
-
|
2507
|
-
|
2508
|
-
_react.useEffect.call(void 0, () => {
|
2509
|
-
const syncMessage = (thread) => {
|
2510
|
-
const newState = getMessageState(
|
2511
|
-
thread,
|
2512
|
-
threadRuntime.getBranches.bind(threadRuntime),
|
2513
|
-
context.useMessage,
|
2514
|
-
messageIndex
|
2515
|
-
);
|
2516
|
-
if (!newState) return;
|
2517
|
-
writableStore(context.useMessage).setState(newState, true);
|
2518
|
-
};
|
2519
|
-
syncMessage(threadMessagesStore.getState());
|
2520
|
-
return threadMessagesStore.subscribe(syncMessage);
|
2521
|
-
}, [threadMessagesStore, threadRuntime, context, messageIndex]);
|
2522
|
-
return context;
|
2428
|
+
})
|
2429
|
+
);
|
2430
|
+
return store;
|
2523
2431
|
};
|
2524
|
-
var
|
2525
|
-
|
2432
|
+
var MessageRuntimeProvider = ({
|
2433
|
+
runtime,
|
2526
2434
|
children
|
2527
2435
|
}) => {
|
2528
|
-
const
|
2436
|
+
const useMessageRuntime2 = useMessageRuntimeStore(runtime);
|
2437
|
+
const useMessage2 = useMessageStore2(runtime);
|
2438
|
+
const useMessageUtils2 = useMessageUtilsStore2();
|
2439
|
+
const useEditComposer2 = useEditComposerStore2(useMessageRuntime2);
|
2440
|
+
const [context] = _react.useState.call(void 0, () => {
|
2441
|
+
return { useMessageRuntime: useMessageRuntime2, useMessage: useMessage2, useMessageUtils: useMessageUtils2, useEditComposer: useEditComposer2 };
|
2442
|
+
});
|
2529
2443
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageContext.Provider, { value: context, children });
|
2530
2444
|
};
|
2531
2445
|
|
@@ -2563,7 +2477,7 @@ var getComponent3 = (components, role, isEditing) => {
|
|
2563
2477
|
var ThreadMessageComponent = ({
|
2564
2478
|
components
|
2565
2479
|
}) => {
|
2566
|
-
const role = useMessage((m) => m.
|
2480
|
+
const role = useMessage((m) => m.role);
|
2567
2481
|
const isEditing = useEditComposer((c) => c.isEditing);
|
2568
2482
|
const Component = getComponent3(components, role, isEditing);
|
2569
2483
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Component, {});
|
@@ -2572,7 +2486,12 @@ var ThreadMessageImpl = ({
|
|
2572
2486
|
messageIndex,
|
2573
2487
|
components
|
2574
2488
|
}) => {
|
2575
|
-
|
2489
|
+
const threadRuntime = useThreadRuntime();
|
2490
|
+
const runtime = _react.useMemo.call(void 0,
|
2491
|
+
() => threadRuntime.unstable_getMesssageByIndex(messageIndex),
|
2492
|
+
[threadRuntime, messageIndex]
|
2493
|
+
);
|
2494
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageRuntimeProvider, { runtime, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadMessageComponent, { components }) });
|
2576
2495
|
};
|
2577
2496
|
var ThreadMessage = _react.memo.call(void 0,
|
2578
2497
|
ThreadMessageImpl,
|
@@ -2609,7 +2528,7 @@ var subscribeToMainThread = (runtime, callback) => {
|
|
2609
2528
|
let first = true;
|
2610
2529
|
let cleanup;
|
2611
2530
|
const inner = () => {
|
2612
|
-
_optionalChain([cleanup, 'optionalCall',
|
2531
|
+
_optionalChain([cleanup, 'optionalCall', _89 => _89()]);
|
2613
2532
|
cleanup = runtime.thread.subscribe(callback);
|
2614
2533
|
if (!first) {
|
2615
2534
|
callback();
|
@@ -2620,7 +2539,7 @@ var subscribeToMainThread = (runtime, callback) => {
|
|
2620
2539
|
inner();
|
2621
2540
|
return () => {
|
2622
2541
|
unsubscribe();
|
2623
|
-
_optionalChain([cleanup, 'optionalCall',
|
2542
|
+
_optionalChain([cleanup, 'optionalCall', _90 => _90()]);
|
2624
2543
|
};
|
2625
2544
|
};
|
2626
2545
|
|
@@ -2655,7 +2574,7 @@ var internal_exports = {};
|
|
2655
2574
|
_chunkPZ5AY32Cjs.__export.call(void 0, internal_exports, {
|
2656
2575
|
AssistantRuntime: () => AssistantRuntime,
|
2657
2576
|
BaseAssistantRuntimeCore: () => BaseAssistantRuntimeCore,
|
2658
|
-
|
2577
|
+
BaseThreadComposerRuntimeCore: () => BaseThreadComposerRuntimeCore,
|
2659
2578
|
MessageRepository: () => MessageRepository,
|
2660
2579
|
ProxyConfigProvider: () => ProxyConfigProvider,
|
2661
2580
|
ThreadRuntime: () => ThreadRuntime,
|
@@ -2668,24 +2587,37 @@ _chunkPZ5AY32Cjs.__export.call(void 0, internal_exports, {
|
|
2668
2587
|
|
2669
2588
|
// src/runtimes/utils/BaseThreadComposerRuntimeCore.tsx
|
2670
2589
|
var BaseThreadComposerRuntimeCore = (_class3 = class {
|
2671
|
-
constructor(runtime) {;_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);_class3.prototype.__init9.call(this);_class3.prototype.__init10.call(this);
|
2590
|
+
constructor(runtime) {;_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);_class3.prototype.__init9.call(this);_class3.prototype.__init10.call(this);_class3.prototype.__init11.call(this);
|
2672
2591
|
this.runtime = runtime;
|
2592
|
+
this.connect();
|
2673
2593
|
}
|
2674
2594
|
|
2675
2595
|
__init7() {this.attachmentAccept = "*"}
|
2676
2596
|
get isEmpty() {
|
2677
2597
|
return !this.text.trim() && !this.attachments.length;
|
2678
2598
|
}
|
2599
|
+
__init8() {this._canCancel = false}
|
2600
|
+
get canCancel() {
|
2601
|
+
return this._canCancel;
|
2602
|
+
}
|
2603
|
+
connect() {
|
2604
|
+
return this.runtime.subscribe(() => {
|
2605
|
+
if (this.canCancel !== this.runtime.capabilities.cancel) {
|
2606
|
+
this._canCancel = this.runtime.capabilities.cancel;
|
2607
|
+
this.notifySubscribers();
|
2608
|
+
}
|
2609
|
+
});
|
2610
|
+
}
|
2679
2611
|
setAttachmentAdapter(adapter) {
|
2680
2612
|
this._attachmentAdapter = adapter;
|
2681
|
-
const accept = _nullishCoalesce(_optionalChain([adapter, 'optionalAccess',
|
2613
|
+
const accept = _nullishCoalesce(_optionalChain([adapter, 'optionalAccess', _91 => _91.accept]), () => ( "*"));
|
2682
2614
|
if (this.attachmentAccept !== accept) {
|
2683
2615
|
this.attachmentAccept = accept;
|
2684
2616
|
return true;
|
2685
2617
|
}
|
2686
2618
|
return false;
|
2687
2619
|
}
|
2688
|
-
|
2620
|
+
__init9() {this._attachments = []}
|
2689
2621
|
get attachments() {
|
2690
2622
|
return this._attachments;
|
2691
2623
|
}
|
@@ -2706,7 +2638,7 @@ var BaseThreadComposerRuntimeCore = (_class3 = class {
|
|
2706
2638
|
this._attachments = this._attachments.toSpliced(index, 1);
|
2707
2639
|
this.notifySubscribers();
|
2708
2640
|
}
|
2709
|
-
|
2641
|
+
__init10() {this._text = ""}
|
2710
2642
|
get text() {
|
2711
2643
|
return this._text;
|
2712
2644
|
}
|
@@ -2726,14 +2658,17 @@ var BaseThreadComposerRuntimeCore = (_class3 = class {
|
|
2726
2658
|
)
|
2727
2659
|
) : [];
|
2728
2660
|
this.runtime.append({
|
2729
|
-
parentId: _nullishCoalesce(_optionalChain([this, 'access',
|
2661
|
+
parentId: _nullishCoalesce(_optionalChain([this, 'access', _92 => _92.runtime, 'access', _93 => _93.messages, 'access', _94 => _94.at, 'call', _95 => _95(-1), 'optionalAccess', _96 => _96.id]), () => ( null)),
|
2730
2662
|
role: "user",
|
2731
2663
|
content: this.text ? [{ type: "text", text: this.text }] : [],
|
2732
2664
|
attachments
|
2733
2665
|
});
|
2734
2666
|
this.reset();
|
2735
2667
|
}
|
2736
|
-
|
2668
|
+
async cancel() {
|
2669
|
+
this.runtime.cancelRun();
|
2670
|
+
}
|
2671
|
+
__init11() {this._subscriptions = /* @__PURE__ */ new Set()}
|
2737
2672
|
notifySubscribers() {
|
2738
2673
|
for (const callback of this._subscriptions) callback();
|
2739
2674
|
}
|
@@ -2744,8 +2679,8 @@ var BaseThreadComposerRuntimeCore = (_class3 = class {
|
|
2744
2679
|
}, _class3);
|
2745
2680
|
|
2746
2681
|
// src/utils/ProxyConfigProvider.ts
|
2747
|
-
var ProxyConfigProvider = (_class4 = class {constructor() { _class4.prototype.
|
2748
|
-
|
2682
|
+
var ProxyConfigProvider = (_class4 = class {constructor() { _class4.prototype.__init12.call(this); }
|
2683
|
+
__init12() {this._providers = /* @__PURE__ */ new Set()}
|
2749
2684
|
getModelConfig() {
|
2750
2685
|
return _chunk5KIEXJRKjs.mergeModelConfigs.call(void 0, this._providers);
|
2751
2686
|
}
|
@@ -2822,11 +2757,11 @@ var findHead = (message) => {
|
|
2822
2757
|
if ("current" in message) return message;
|
2823
2758
|
return null;
|
2824
2759
|
};
|
2825
|
-
var MessageRepository = (_class5 = class {constructor() { _class5.prototype.
|
2826
|
-
|
2760
|
+
var MessageRepository = (_class5 = class {constructor() { _class5.prototype.__init13.call(this);_class5.prototype.__init14.call(this);_class5.prototype.__init15.call(this); }
|
2761
|
+
__init13() {this.messages = /* @__PURE__ */ new Map()}
|
2827
2762
|
// message_id -> item
|
2828
|
-
|
2829
|
-
|
2763
|
+
__init14() {this.head = null}
|
2764
|
+
__init15() {this.root = {
|
2830
2765
|
children: [],
|
2831
2766
|
next: null
|
2832
2767
|
}}
|
@@ -2868,7 +2803,7 @@ var MessageRepository = (_class5 = class {constructor() { _class5.prototype.__in
|
|
2868
2803
|
}
|
2869
2804
|
}
|
2870
2805
|
getMessages() {
|
2871
|
-
const messages = new Array(_nullishCoalesce(_optionalChain([this, 'access',
|
2806
|
+
const messages = new Array(_nullishCoalesce(_optionalChain([this, 'access', _97 => _97.head, 'optionalAccess', _98 => _98.level]), () => ( 0)));
|
2872
2807
|
for (let current = this.head; current; current = current.prev) {
|
2873
2808
|
messages[current.level] = current.current;
|
2874
2809
|
}
|
@@ -2906,7 +2841,7 @@ var MessageRepository = (_class5 = class {constructor() { _class5.prototype.__in
|
|
2906
2841
|
"MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui."
|
2907
2842
|
);
|
2908
2843
|
return {
|
2909
|
-
parentId: _nullishCoalesce(_optionalChain([message, 'access',
|
2844
|
+
parentId: _nullishCoalesce(_optionalChain([message, 'access', _99 => _99.prev, 'optionalAccess', _100 => _100.current, 'access', _101 => _101.id]), () => ( null)),
|
2910
2845
|
message: message.current
|
2911
2846
|
};
|
2912
2847
|
}
|
@@ -2990,11 +2925,11 @@ var MessageRepository = (_class5 = class {constructor() { _class5.prototype.__in
|
|
2990
2925
|
for (const [, message] of this.messages) {
|
2991
2926
|
exportItems.push({
|
2992
2927
|
message: message.current,
|
2993
|
-
parentId: _nullishCoalesce(_optionalChain([message, 'access',
|
2928
|
+
parentId: _nullishCoalesce(_optionalChain([message, 'access', _102 => _102.prev, 'optionalAccess', _103 => _103.current, 'access', _104 => _104.id]), () => ( null))
|
2994
2929
|
});
|
2995
2930
|
}
|
2996
2931
|
return {
|
2997
|
-
headId: _nullishCoalesce(_optionalChain([this, 'access',
|
2932
|
+
headId: _nullishCoalesce(_optionalChain([this, 'access', _105 => _105.head, 'optionalAccess', _106 => _106.current, 'access', _107 => _107.id]), () => ( null)),
|
2998
2933
|
messages: exportItems
|
2999
2934
|
};
|
3000
2935
|
}
|
@@ -3002,7 +2937,7 @@ var MessageRepository = (_class5 = class {constructor() { _class5.prototype.__in
|
|
3002
2937
|
for (const { message, parentId } of messages) {
|
3003
2938
|
this.addOrUpdateMessage(parentId, message);
|
3004
2939
|
}
|
3005
|
-
this.resetHead(_nullishCoalesce(_nullishCoalesce(headId, () => ( _optionalChain([messages, 'access',
|
2940
|
+
this.resetHead(_nullishCoalesce(_nullishCoalesce(headId, () => ( _optionalChain([messages, 'access', _108 => _108.at, 'call', _109 => _109(-1), 'optionalAccess', _110 => _110.message, 'access', _111 => _111.id]))), () => ( null)));
|
3006
2941
|
}
|
3007
2942
|
}, _class5);
|
3008
2943
|
|
@@ -3103,8 +3038,8 @@ var TooltipIconButton = _react.forwardRef.call(void 0, ({ children, tooltip, sid
|
|
3103
3038
|
TooltipIconButton.displayName = "TooltipIconButton";
|
3104
3039
|
|
3105
3040
|
// src/api/subscribable/BaseSubject.ts
|
3106
|
-
var BaseSubject = (_class6 = class {constructor() { _class6.prototype.
|
3107
|
-
|
3041
|
+
var BaseSubject = (_class6 = class {constructor() { _class6.prototype.__init16.call(this); }
|
3042
|
+
__init16() {this._subscriptions = /* @__PURE__ */ new Set()}
|
3108
3043
|
|
3109
3044
|
get isConnected() {
|
3110
3045
|
return !!this._connection;
|
@@ -3117,7 +3052,7 @@ var BaseSubject = (_class6 = class {constructor() { _class6.prototype.__init15.c
|
|
3117
3052
|
if (this._connection) return;
|
3118
3053
|
this._connection = this._connect();
|
3119
3054
|
} else {
|
3120
|
-
_optionalChain([this, 'access',
|
3055
|
+
_optionalChain([this, 'access', _112 => _112._connection, 'optionalCall', _113 => _113()]);
|
3121
3056
|
this._connection = void 0;
|
3122
3057
|
}
|
3123
3058
|
}
|
@@ -3150,13 +3085,13 @@ var NestedSubscriptionSubject = class extends BaseSubject {
|
|
3150
3085
|
const newState = this.binding.getState();
|
3151
3086
|
if (newState === lastState) return;
|
3152
3087
|
lastState = newState;
|
3153
|
-
_optionalChain([innerUnsubscribe, 'optionalCall',
|
3088
|
+
_optionalChain([innerUnsubscribe, 'optionalCall', _114 => _114()]);
|
3154
3089
|
innerUnsubscribe = this.binding.getState().subscribe(callback);
|
3155
3090
|
callback();
|
3156
3091
|
};
|
3157
3092
|
const outerUnsubscribe = this.binding.subscribe(onRuntimeUpdate);
|
3158
3093
|
return () => {
|
3159
|
-
_optionalChain([outerUnsubscribe, 'optionalCall',
|
3094
|
+
_optionalChain([outerUnsubscribe, 'optionalCall', _115 => _115()]);
|
3160
3095
|
innerUnsubscribe();
|
3161
3096
|
};
|
3162
3097
|
}
|
@@ -3212,7 +3147,7 @@ var ContentPartRuntime = class {
|
|
3212
3147
|
const toolName = state.part.toolName;
|
3213
3148
|
const toolCallId = state.part.toolCallId;
|
3214
3149
|
this.threadApi.getState().addToolResult({
|
3215
|
-
messageId: message.
|
3150
|
+
messageId: message.id,
|
3216
3151
|
toolName,
|
3217
3152
|
toolCallId,
|
3218
3153
|
result
|
@@ -3236,7 +3171,7 @@ function shallowEqual(objA, objB) {
|
|
3236
3171
|
// src/api/subscribable/ShallowMemoizeSubject.ts
|
3237
3172
|
var ShallowMemoizeSubject = (_class7 = class extends BaseSubject {
|
3238
3173
|
constructor(binding) {
|
3239
|
-
super();_class7.prototype.
|
3174
|
+
super();_class7.prototype.__init17.call(this);;
|
3240
3175
|
this.binding = binding;
|
3241
3176
|
const state = binding.getState();
|
3242
3177
|
if (state === void 0)
|
@@ -3244,7 +3179,7 @@ var ShallowMemoizeSubject = (_class7 = class extends BaseSubject {
|
|
3244
3179
|
this._previousState = state;
|
3245
3180
|
}
|
3246
3181
|
|
3247
|
-
|
3182
|
+
__init17() {this.getState = () => {
|
3248
3183
|
if (!this.isConnected) this._syncState();
|
3249
3184
|
return this._previousState;
|
3250
3185
|
}}
|
@@ -3266,60 +3201,13 @@ var ShallowMemoizeSubject = (_class7 = class extends BaseSubject {
|
|
3266
3201
|
}, _class7);
|
3267
3202
|
|
3268
3203
|
// src/api/MessageRuntime.ts
|
3269
|
-
var MessageState = class {
|
3270
|
-
constructor(snapshot) {
|
3271
|
-
this.snapshot = snapshot;
|
3272
|
-
}
|
3273
|
-
/**
|
3274
|
-
* @deprecated Replace `.message.content` with `.content` etc. This will be removed in 0.6.0.
|
3275
|
-
*/
|
3276
|
-
get message() {
|
3277
|
-
return this.snapshot.message;
|
3278
|
-
}
|
3279
|
-
get id() {
|
3280
|
-
return this.snapshot.message.id;
|
3281
|
-
}
|
3282
|
-
get createdAt() {
|
3283
|
-
return this.snapshot.message.createdAt;
|
3284
|
-
}
|
3285
|
-
get role() {
|
3286
|
-
return this.snapshot.message.role;
|
3287
|
-
}
|
3288
|
-
get content() {
|
3289
|
-
return this.snapshot.message.content;
|
3290
|
-
}
|
3291
|
-
get attachments() {
|
3292
|
-
return this.snapshot.message.attachments;
|
3293
|
-
}
|
3294
|
-
get metadata() {
|
3295
|
-
return this.snapshot.message.metadata;
|
3296
|
-
}
|
3297
|
-
get status() {
|
3298
|
-
return this.snapshot.message.status;
|
3299
|
-
}
|
3300
|
-
get parentId() {
|
3301
|
-
return this.snapshot.parentId;
|
3302
|
-
}
|
3303
|
-
get isLast() {
|
3304
|
-
return this.snapshot.isLast;
|
3305
|
-
}
|
3306
|
-
get branches() {
|
3307
|
-
return this.snapshot.branches;
|
3308
|
-
}
|
3309
|
-
get branchNumber() {
|
3310
|
-
return this.snapshot.branchNumber;
|
3311
|
-
}
|
3312
|
-
get branchCount() {
|
3313
|
-
return this.snapshot.branchCount;
|
3314
|
-
}
|
3315
|
-
};
|
3316
3204
|
var MessageRuntime = class {
|
3317
3205
|
constructor(_core, _threadBinding) {
|
3318
3206
|
this._core = _core;
|
3319
3207
|
this._threadBinding = _threadBinding;
|
3320
3208
|
}
|
3321
3209
|
getState() {
|
3322
|
-
return
|
3210
|
+
return this._core.getState();
|
3323
3211
|
}
|
3324
3212
|
// TODO improve type
|
3325
3213
|
edit(message) {
|
@@ -3338,13 +3226,13 @@ var MessageRuntime = class {
|
|
3338
3226
|
speak() {
|
3339
3227
|
const state = this._core.getState();
|
3340
3228
|
if (!state) throw new Error("Message is not available");
|
3341
|
-
this._threadBinding.getState().speak(state.
|
3229
|
+
this._threadBinding.getState().speak(state.id);
|
3342
3230
|
}
|
3343
3231
|
submitFeedback({ type }) {
|
3344
3232
|
const state = this._core.getState();
|
3345
3233
|
if (!state) throw new Error("Message is not available");
|
3346
3234
|
this._threadBinding.getState().submitFeedback({
|
3347
|
-
messageId: state.
|
3235
|
+
messageId: state.id,
|
3348
3236
|
type
|
3349
3237
|
});
|
3350
3238
|
}
|
@@ -3360,7 +3248,7 @@ var MessageRuntime = class {
|
|
3360
3248
|
throw new Error("Must specify either branchId or position");
|
3361
3249
|
}
|
3362
3250
|
const thread = this._threadBinding.getState();
|
3363
|
-
const branches = thread.getBranches(state.
|
3251
|
+
const branches = thread.getBranches(state.id);
|
3364
3252
|
let targetBranch = branchId;
|
3365
3253
|
if (position === "previous") {
|
3366
3254
|
targetBranch = branches[state.branchNumber - 2];
|
@@ -3397,27 +3285,18 @@ var MessageRuntime = class {
|
|
3397
3285
|
};
|
3398
3286
|
|
3399
3287
|
// src/api/ThreadComposerRuntime.ts
|
3400
|
-
var
|
3401
|
-
|
3402
|
-
|
3403
|
-
|
3404
|
-
|
3405
|
-
|
3406
|
-
|
3407
|
-
|
3408
|
-
return this._composerBinding.getState().text;
|
3409
|
-
}
|
3410
|
-
get attachmentAccept() {
|
3411
|
-
return this._composerBinding.getState().attachmentAccept;
|
3412
|
-
}
|
3413
|
-
get attachments() {
|
3414
|
-
return this._composerBinding.getState().attachments;
|
3415
|
-
}
|
3288
|
+
var getThreadComposerState = (runtime) => {
|
3289
|
+
return Object.freeze({
|
3290
|
+
canCancel: runtime.canCancel,
|
3291
|
+
isEmpty: runtime.isEmpty,
|
3292
|
+
text: runtime.text,
|
3293
|
+
attachments: runtime.attachments,
|
3294
|
+
attachmentAccept: runtime.attachmentAccept
|
3295
|
+
});
|
3416
3296
|
};
|
3417
3297
|
var ThreadComposerRuntime = class {
|
3418
3298
|
constructor(_core) {
|
3419
3299
|
this._core = _core;
|
3420
|
-
this._state = new ComposerState(_core);
|
3421
3300
|
}
|
3422
3301
|
/**
|
3423
3302
|
* @deprecated Use `getState().isEmpty` instead. This will be removed in 0.6.0.
|
@@ -3425,6 +3304,12 @@ var ThreadComposerRuntime = class {
|
|
3425
3304
|
get isEmpty() {
|
3426
3305
|
return this._core.getState().isEmpty;
|
3427
3306
|
}
|
3307
|
+
/**
|
3308
|
+
* @deprecated Use `getState().canCancel` instead. This will be removed in 0.6.0.
|
3309
|
+
*/
|
3310
|
+
get canCancel() {
|
3311
|
+
return this._core.getState().canCancel;
|
3312
|
+
}
|
3428
3313
|
/**
|
3429
3314
|
* @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
|
3430
3315
|
*/
|
@@ -3444,9 +3329,8 @@ var ThreadComposerRuntime = class {
|
|
3444
3329
|
get attachments() {
|
3445
3330
|
return this._core.getState().attachments;
|
3446
3331
|
}
|
3447
|
-
|
3448
3332
|
getState() {
|
3449
|
-
return this.
|
3333
|
+
return getThreadComposerState(this._core.getState());
|
3450
3334
|
}
|
3451
3335
|
setText(text) {
|
3452
3336
|
this._core.getState().setText(text);
|
@@ -3469,33 +3353,46 @@ var ThreadComposerRuntime = class {
|
|
3469
3353
|
send() {
|
3470
3354
|
this._core.getState().send();
|
3471
3355
|
}
|
3356
|
+
cancel() {
|
3357
|
+
this._core.getState().cancel();
|
3358
|
+
}
|
3472
3359
|
subscribe(callback) {
|
3473
3360
|
return this._core.subscribe(callback);
|
3474
3361
|
}
|
3475
3362
|
};
|
3476
3363
|
|
3477
3364
|
// src/api/ThreadRuntime.ts
|
3478
|
-
var
|
3479
|
-
|
3480
|
-
|
3481
|
-
|
3482
|
-
|
3483
|
-
|
3484
|
-
|
3485
|
-
|
3486
|
-
return this._core.isDisabled;
|
3487
|
-
}
|
3488
|
-
get isRunning() {
|
3489
|
-
const messages = this._core.messages;
|
3490
|
-
const lastMessage = messages[messages.length - 1];
|
3491
|
-
return _optionalChain([lastMessage, 'optionalAccess', _133 => _133.role]) !== "assistant" ? false : lastMessage.status.type === "running";
|
3365
|
+
var toAppendMessage = (messages, message) => {
|
3366
|
+
if (typeof message === "string") {
|
3367
|
+
return {
|
3368
|
+
parentId: _nullishCoalesce(_optionalChain([messages, 'access', _116 => _116.at, 'call', _117 => _117(-1), 'optionalAccess', _118 => _118.id]), () => ( null)),
|
3369
|
+
role: "user",
|
3370
|
+
content: [{ type: "text", text: message }],
|
3371
|
+
attachments: []
|
3372
|
+
};
|
3492
3373
|
}
|
3493
|
-
|
3494
|
-
return
|
3374
|
+
if (message.role && message.parentId && message.attachments) {
|
3375
|
+
return message;
|
3495
3376
|
}
|
3377
|
+
return {
|
3378
|
+
parentId: _nullishCoalesce(_nullishCoalesce(message.parentId, () => ( _optionalChain([messages, 'access', _119 => _119.at, 'call', _120 => _120(-1), 'optionalAccess', _121 => _121.id]))), () => ( null)),
|
3379
|
+
role: _nullishCoalesce(message.role, () => ( "user")),
|
3380
|
+
content: message.content,
|
3381
|
+
attachments: _nullishCoalesce(message.attachments, () => ( []))
|
3382
|
+
};
|
3383
|
+
};
|
3384
|
+
var getThreadState = (runtime) => {
|
3385
|
+
const lastMessage = runtime.messages.at(-1);
|
3386
|
+
return Object.freeze({
|
3387
|
+
threadId: runtime.threadId,
|
3388
|
+
capabilities: runtime.capabilities,
|
3389
|
+
isDisabled: runtime.isDisabled,
|
3390
|
+
isRunning: _optionalChain([lastMessage, 'optionalAccess', _122 => _122.role]) !== "assistant" ? false : lastMessage.status.type === "running",
|
3391
|
+
unstable_synchronizer: runtime.unstable_synchronizer
|
3392
|
+
});
|
3496
3393
|
};
|
3497
3394
|
var ThreadRuntime = (_class8 = class {
|
3498
|
-
constructor(_threadBinding) {;_class8.prototype.
|
3395
|
+
constructor(_threadBinding) {;_class8.prototype.__init18.call(this);
|
3499
3396
|
this._threadBinding = _threadBinding;
|
3500
3397
|
}
|
3501
3398
|
// public path = "assistant.threads[main]"; // TODO
|
@@ -3530,17 +3427,19 @@ var ThreadRuntime = (_class8 = class {
|
|
3530
3427
|
unstable_getCore() {
|
3531
3428
|
return this._threadBinding.getState();
|
3532
3429
|
}
|
3533
|
-
|
3430
|
+
__init18() {this.composer = new ThreadComposerRuntime(
|
3534
3431
|
new NestedSubscriptionSubject({
|
3535
3432
|
getState: () => this._threadBinding.getState().composer,
|
3536
3433
|
subscribe: (callback) => this._threadBinding.subscribe(callback)
|
3537
3434
|
})
|
3538
3435
|
)}
|
3539
3436
|
getState() {
|
3540
|
-
return
|
3437
|
+
return getThreadState(this._threadBinding.getState());
|
3541
3438
|
}
|
3542
3439
|
append(message) {
|
3543
|
-
this._threadBinding.getState().append(
|
3440
|
+
this._threadBinding.getState().append(
|
3441
|
+
toAppendMessage(this._threadBinding.getState().messages, message)
|
3442
|
+
);
|
3544
3443
|
}
|
3545
3444
|
subscribe(callback) {
|
3546
3445
|
return this._threadBinding.subscribe(callback);
|
@@ -3600,9 +3499,10 @@ var ThreadRuntime = (_class8 = class {
|
|
3600
3499
|
if (!message) return void 0;
|
3601
3500
|
const branches = this._threadBinding.getState().getBranches(message.id);
|
3602
3501
|
return {
|
3502
|
+
...message,
|
3603
3503
|
message,
|
3604
3504
|
isLast: idx === messages.length - 1,
|
3605
|
-
parentId: _nullishCoalesce(_optionalChain([messages, 'access',
|
3505
|
+
parentId: _nullishCoalesce(_optionalChain([messages, 'access', _123 => _123[idx - 1], 'optionalAccess', _124 => _124.id]), () => ( null)),
|
3606
3506
|
branches,
|
3607
3507
|
branchNumber: branches.indexOf(message.id) + 1,
|
3608
3508
|
branchCount: branches.length
|
@@ -3678,7 +3578,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
3678
3578
|
});
|
3679
3579
|
if (mergeRoundtrips) {
|
3680
3580
|
const previousMessage = messages[messages.length - 1];
|
3681
|
-
if (_optionalChain([previousMessage, 'optionalAccess',
|
3581
|
+
if (_optionalChain([previousMessage, 'optionalAccess', _125 => _125.role]) === "assistant") {
|
3682
3582
|
previousMessage.content.push(...newContent);
|
3683
3583
|
break;
|
3684
3584
|
}
|
@@ -3691,7 +3591,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
3691
3591
|
}
|
3692
3592
|
case "tool": {
|
3693
3593
|
const previousMessage = messages[messages.length - 1];
|
3694
|
-
if (_optionalChain([previousMessage, 'optionalAccess',
|
3594
|
+
if (_optionalChain([previousMessage, 'optionalAccess', _126 => _126.role]) !== "assistant")
|
3695
3595
|
throw new Error(
|
3696
3596
|
"A tool message must be preceded by an assistant message."
|
3697
3597
|
);
|
@@ -3920,11 +3820,11 @@ var useEdgeRuntime = ({
|
|
3920
3820
|
};
|
3921
3821
|
|
3922
3822
|
// src/runtimes/local/shouldContinue.tsx
|
3923
|
-
var shouldContinue = (result) => _optionalChain([result, 'access',
|
3823
|
+
var shouldContinue = (result) => _optionalChain([result, 'access', _127 => _127.status, 'optionalAccess', _128 => _128.type]) === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
|
3924
3824
|
|
3925
3825
|
// src/runtimes/local/LocalThreadRuntimeCore.tsx
|
3926
3826
|
var LocalThreadRuntimeCore = (_class9 = class {
|
3927
|
-
constructor(configProvider, adapter, { initialMessages, ...options }) {;_class9.prototype.
|
3827
|
+
constructor(configProvider, adapter, { initialMessages, ...options }) {;_class9.prototype.__init19.call(this);_class9.prototype.__init20.call(this);_class9.prototype.__init21.call(this);_class9.prototype.__init22.call(this);_class9.prototype.__init23.call(this);_class9.prototype.__init24.call(this);
|
3928
3828
|
this.configProvider = configProvider;
|
3929
3829
|
this.adapter = adapter;
|
3930
3830
|
this.threadId = generateId();
|
@@ -3938,10 +3838,10 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
3938
3838
|
}
|
3939
3839
|
}
|
3940
3840
|
}
|
3941
|
-
|
3942
|
-
|
3943
|
-
|
3944
|
-
|
3841
|
+
__init19() {this._subscriptions = /* @__PURE__ */ new Set()}
|
3842
|
+
__init20() {this.abortController = null}
|
3843
|
+
__init21() {this.repository = new MessageRepository()}
|
3844
|
+
__init22() {this.capabilities = {
|
3945
3845
|
switchToBranch: true,
|
3946
3846
|
edit: true,
|
3947
3847
|
reload: true,
|
@@ -3952,11 +3852,11 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
3952
3852
|
feedback: false
|
3953
3853
|
}}
|
3954
3854
|
|
3955
|
-
|
3855
|
+
__init23() {this.isDisabled = false}
|
3956
3856
|
get messages() {
|
3957
3857
|
return this.repository.getMessages();
|
3958
3858
|
}
|
3959
|
-
|
3859
|
+
__init24() {this.composer = new BaseThreadComposerRuntimeCore(this)}
|
3960
3860
|
getModelConfig() {
|
3961
3861
|
return this.configProvider.getModelConfig();
|
3962
3862
|
}
|
@@ -3967,18 +3867,18 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
3967
3867
|
set options({ initialMessages, ...options }) {
|
3968
3868
|
this._options = options;
|
3969
3869
|
let hasUpdates = false;
|
3970
|
-
const canSpeak = _optionalChain([options, 'access',
|
3870
|
+
const canSpeak = _optionalChain([options, 'access', _129 => _129.adapters, 'optionalAccess', _130 => _130.speech]) !== void 0;
|
3971
3871
|
if (this.capabilities.speak !== canSpeak) {
|
3972
3872
|
this.capabilities.speak = canSpeak;
|
3973
3873
|
hasUpdates = true;
|
3974
3874
|
}
|
3975
|
-
this.composer.setAttachmentAdapter(_optionalChain([options, 'access',
|
3976
|
-
const canAttach = _optionalChain([options, 'access',
|
3875
|
+
this.composer.setAttachmentAdapter(_optionalChain([options, 'access', _131 => _131.adapters, 'optionalAccess', _132 => _132.attachments]));
|
3876
|
+
const canAttach = _optionalChain([options, 'access', _133 => _133.adapters, 'optionalAccess', _134 => _134.attachments]) !== void 0;
|
3977
3877
|
if (this.capabilities.attachments !== canAttach) {
|
3978
3878
|
this.capabilities.attachments = canAttach;
|
3979
3879
|
hasUpdates = true;
|
3980
3880
|
}
|
3981
|
-
const canFeedback = _optionalChain([options, 'access',
|
3881
|
+
const canFeedback = _optionalChain([options, 'access', _135 => _135.adapters, 'optionalAccess', _136 => _136.feedback]) !== void 0;
|
3982
3882
|
if (this.capabilities.feedback !== canFeedback) {
|
3983
3883
|
this.capabilities.feedback = canFeedback;
|
3984
3884
|
hasUpdates = true;
|
@@ -4020,18 +3920,18 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
4020
3920
|
}
|
4021
3921
|
async performRoundtrip(parentId, message) {
|
4022
3922
|
const messages = this.repository.getMessages();
|
4023
|
-
_optionalChain([this, 'access',
|
3923
|
+
_optionalChain([this, 'access', _137 => _137.abortController, 'optionalAccess', _138 => _138.abort, 'call', _139 => _139()]);
|
4024
3924
|
this.abortController = new AbortController();
|
4025
3925
|
const initialContent = message.content;
|
4026
|
-
const initialRoundtrips = _optionalChain([message, 'access',
|
4027
|
-
const initalCustom = _optionalChain([message, 'access',
|
3926
|
+
const initialRoundtrips = _optionalChain([message, 'access', _140 => _140.metadata, 'optionalAccess', _141 => _141.roundtrips]);
|
3927
|
+
const initalCustom = _optionalChain([message, 'access', _142 => _142.metadata, 'optionalAccess', _143 => _143.custom]);
|
4028
3928
|
const updateMessage = (m) => {
|
4029
3929
|
message = {
|
4030
3930
|
...message,
|
4031
3931
|
...m.content ? { content: [...initialContent, ..._nullishCoalesce(m.content, () => ( []))] } : void 0,
|
4032
3932
|
status: _nullishCoalesce(m.status, () => ( message.status)),
|
4033
3933
|
// TODO deprecated, remove in v0.6
|
4034
|
-
..._optionalChain([m, 'access',
|
3934
|
+
..._optionalChain([m, 'access', _144 => _144.metadata, 'optionalAccess', _145 => _145.roundtrips]) ? {
|
4035
3935
|
roundtrips: [
|
4036
3936
|
..._nullishCoalesce(initialRoundtrips, () => ( [])),
|
4037
3937
|
...m.metadata.roundtrips
|
@@ -4046,7 +3946,7 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
4046
3946
|
...m.metadata.roundtrips
|
4047
3947
|
]
|
4048
3948
|
} : void 0,
|
4049
|
-
..._optionalChain([m, 'access',
|
3949
|
+
..._optionalChain([m, 'access', _146 => _146.metadata, 'optionalAccess', _147 => _147.custom]) ? {
|
4050
3950
|
custom: { ..._nullishCoalesce(initalCustom, () => ( {})), ...m.metadata.custom }
|
4051
3951
|
} : void 0
|
4052
3952
|
}
|
@@ -4056,7 +3956,7 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
4056
3956
|
this.notifySubscribers();
|
4057
3957
|
};
|
4058
3958
|
const maxToolRoundtrips = _nullishCoalesce(this.options.maxToolRoundtrips, () => ( 1));
|
4059
|
-
const toolRoundtrips = _nullishCoalesce(_optionalChain([message, 'access',
|
3959
|
+
const toolRoundtrips = _nullishCoalesce(_optionalChain([message, 'access', _148 => _148.metadata, 'optionalAccess', _149 => _149.roundtrips, 'optionalAccess', _150 => _150.length]), () => ( 0));
|
4060
3960
|
if (toolRoundtrips > maxToolRoundtrips) {
|
4061
3961
|
updateMessage({
|
4062
3962
|
status: {
|
@@ -4155,7 +4055,7 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
4155
4055
|
// TODO lift utterance state to thread runtime
|
4156
4056
|
|
4157
4057
|
speak(messageId) {
|
4158
|
-
const adapter = _optionalChain([this, 'access',
|
4058
|
+
const adapter = _optionalChain([this, 'access', _151 => _151.options, 'access', _152 => _152.adapters, 'optionalAccess', _153 => _153.speech]);
|
4159
4059
|
if (!adapter) throw new Error("Speech adapter not configured");
|
4160
4060
|
const { message } = this.repository.getMessage(messageId);
|
4161
4061
|
if (this._utterance) {
|
@@ -4172,7 +4072,7 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
4172
4072
|
return this._utterance;
|
4173
4073
|
}
|
4174
4074
|
submitFeedback({ messageId, type }) {
|
4175
|
-
const adapter = _optionalChain([this, 'access',
|
4075
|
+
const adapter = _optionalChain([this, 'access', _154 => _154.options, 'access', _155 => _155.adapters, 'optionalAccess', _156 => _156.feedback]);
|
4176
4076
|
if (!adapter) throw new Error("Feedback adapter not configured");
|
4177
4077
|
const { message } = this.repository.getMessage(messageId);
|
4178
4078
|
adapter.submit({ message, type });
|
@@ -4219,7 +4119,7 @@ var LocalRuntimeCore = class extends BaseAssistantRuntimeCore {
|
|
4219
4119
|
const messages = fromCoreMessages(initialMessages);
|
4220
4120
|
this.thread.import({
|
4221
4121
|
messages: messages.map((m, idx) => ({
|
4222
|
-
parentId: _nullishCoalesce(_optionalChain([messages, 'access',
|
4122
|
+
parentId: _nullishCoalesce(_optionalChain([messages, 'access', _157 => _157[idx - 1], 'optionalAccess', _158 => _158.id]), () => ( null)),
|
4223
4123
|
message: m
|
4224
4124
|
}))
|
4225
4125
|
});
|
@@ -4255,8 +4155,8 @@ var getExternalStoreMessage = (message) => {
|
|
4255
4155
|
};
|
4256
4156
|
|
4257
4157
|
// src/runtimes/external-store/ThreadMessageConverter.ts
|
4258
|
-
var ThreadMessageConverter = (_class10 = class {constructor() { _class10.prototype.
|
4259
|
-
|
4158
|
+
var ThreadMessageConverter = (_class10 = class {constructor() { _class10.prototype.__init25.call(this); }
|
4159
|
+
__init25() {this.cache = /* @__PURE__ */ new WeakMap()}
|
4260
4160
|
convertMessages(messages, converter) {
|
4261
4161
|
return messages.map((m, idx) => {
|
4262
4162
|
const cached = this.cache.get(m);
|
@@ -4352,17 +4252,17 @@ var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
|
|
4352
4252
|
|
4353
4253
|
// src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx
|
4354
4254
|
var hasUpcomingMessage = (isRunning, messages) => {
|
4355
|
-
return isRunning && _optionalChain([messages, 'access',
|
4255
|
+
return isRunning && _optionalChain([messages, 'access', _159 => _159[messages.length - 1], 'optionalAccess', _160 => _160.role]) !== "assistant";
|
4356
4256
|
};
|
4357
4257
|
var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
4358
|
-
constructor(configProvider, store) {;_class11.prototype.
|
4258
|
+
constructor(configProvider, store) {;_class11.prototype.__init26.call(this);_class11.prototype.__init27.call(this);_class11.prototype.__init28.call(this);_class11.prototype.__init29.call(this);_class11.prototype.__init30.call(this);_class11.prototype.__init31.call(this);_class11.prototype.__init32.call(this);
|
4359
4259
|
this.configProvider = configProvider;
|
4360
4260
|
this.store = store;
|
4361
4261
|
}
|
4362
|
-
|
4363
|
-
|
4364
|
-
|
4365
|
-
|
4262
|
+
__init26() {this._subscriptions = /* @__PURE__ */ new Set()}
|
4263
|
+
__init27() {this.repository = new MessageRepository()}
|
4264
|
+
__init28() {this.assistantOptimisticId = null}
|
4265
|
+
__init29() {this._capabilities = {
|
4366
4266
|
switchToBranch: false,
|
4367
4267
|
edit: false,
|
4368
4268
|
reload: false,
|
@@ -4378,9 +4278,9 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4378
4278
|
|
4379
4279
|
|
4380
4280
|
|
4381
|
-
|
4281
|
+
__init30() {this.converter = new ThreadMessageConverter()}
|
4382
4282
|
|
4383
|
-
|
4283
|
+
__init31() {this.composer = new BaseThreadComposerRuntimeCore(this)}
|
4384
4284
|
get store() {
|
4385
4285
|
return this._store;
|
4386
4286
|
}
|
@@ -4397,12 +4297,12 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4397
4297
|
reload: this._store.onReload !== void 0,
|
4398
4298
|
cancel: this._store.onCancel !== void 0,
|
4399
4299
|
speak: this._store.onSpeak !== void 0,
|
4400
|
-
unstable_copy: _optionalChain([this, 'access',
|
4300
|
+
unstable_copy: _optionalChain([this, 'access', _164 => _164._store, 'access', _165 => _165.unstable_capabilities, 'optionalAccess', _166 => _166.copy]) !== false,
|
4401
4301
|
// default true
|
4402
|
-
attachments: !!_optionalChain([this, 'access',
|
4403
|
-
feedback: !!_optionalChain([this, 'access',
|
4302
|
+
attachments: !!_optionalChain([this, 'access', _167 => _167.store, 'access', _168 => _168.adapters, 'optionalAccess', _169 => _169.attachments]),
|
4303
|
+
feedback: !!_optionalChain([this, 'access', _170 => _170.store, 'access', _171 => _171.adapters, 'optionalAccess', _172 => _172.feedback])
|
4404
4304
|
};
|
4405
|
-
this.composer.setAttachmentAdapter(_optionalChain([this, 'access',
|
4305
|
+
this.composer.setAttachmentAdapter(_optionalChain([this, 'access', _173 => _173._store, 'access', _174 => _174.adapters, 'optionalAccess', _175 => _175.attachments]));
|
4406
4306
|
if (oldStore) {
|
4407
4307
|
if (oldStore.convertMessage !== store.convertMessage) {
|
4408
4308
|
this.converter = new ThreadMessageConverter();
|
@@ -4428,7 +4328,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4428
4328
|
for (let i = 0; i < messages.length; i++) {
|
4429
4329
|
const message = messages[i];
|
4430
4330
|
const parent = messages[i - 1];
|
4431
|
-
this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess',
|
4331
|
+
this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _176 => _176.id]), () => ( null)), message);
|
4432
4332
|
}
|
4433
4333
|
if (this.assistantOptimisticId) {
|
4434
4334
|
this.repository.deleteMessage(this.assistantOptimisticId);
|
@@ -4436,7 +4336,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4436
4336
|
}
|
4437
4337
|
if (hasUpcomingMessage(isRunning, messages)) {
|
4438
4338
|
this.assistantOptimisticId = this.repository.appendOptimisticMessage(
|
4439
|
-
_nullishCoalesce(_optionalChain([messages, 'access',
|
4339
|
+
_nullishCoalesce(_optionalChain([messages, 'access', _177 => _177.at, 'call', _178 => _178(-1), 'optionalAccess', _179 => _179.id]), () => ( null)),
|
4440
4340
|
{
|
4441
4341
|
role: "assistant",
|
4442
4342
|
content: []
|
@@ -4444,7 +4344,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4444
4344
|
);
|
4445
4345
|
}
|
4446
4346
|
this.repository.resetHead(
|
4447
|
-
_nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages, 'access',
|
4347
|
+
_nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages, 'access', _180 => _180.at, 'call', _181 => _181(-1), 'optionalAccess', _182 => _182.id]))), () => ( null))
|
4448
4348
|
);
|
4449
4349
|
this.messages = this.repository.getMessages();
|
4450
4350
|
this.notifySubscribers();
|
@@ -4465,7 +4365,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4465
4365
|
this.updateMessages(this.repository.getMessages());
|
4466
4366
|
}
|
4467
4367
|
async append(message) {
|
4468
|
-
if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access',
|
4368
|
+
if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _183 => _183.messages, 'access', _184 => _184.at, 'call', _185 => _185(-1), 'optionalAccess', _186 => _186.id]), () => ( null)))) {
|
4469
4369
|
if (!this._store.onEdit)
|
4470
4370
|
throw new Error("Runtime does not support editing messages.");
|
4471
4371
|
await this._store.onEdit(message);
|
@@ -4488,7 +4388,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4488
4388
|
}
|
4489
4389
|
let messages = this.repository.getMessages();
|
4490
4390
|
const previousMessage = messages[messages.length - 1];
|
4491
|
-
if (_optionalChain([previousMessage, 'optionalAccess',
|
4391
|
+
if (_optionalChain([previousMessage, 'optionalAccess', _187 => _187.role]) === "user" && previousMessage.id === _optionalChain([messages, 'access', _188 => _188.at, 'call', _189 => _189(-1), 'optionalAccess', _190 => _190.id])) {
|
4492
4392
|
this.repository.deleteMessage(previousMessage.id);
|
4493
4393
|
if (!this.composer.text.trim()) {
|
4494
4394
|
this.composer.setText(getThreadMessageText(previousMessage));
|
@@ -4513,7 +4413,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4513
4413
|
return this._store.onSpeak(message);
|
4514
4414
|
}
|
4515
4415
|
submitFeedback({ messageId, type }) {
|
4516
|
-
const adapter = _optionalChain([this, 'access',
|
4416
|
+
const adapter = _optionalChain([this, 'access', _191 => _191._store, 'access', _192 => _192.adapters, 'optionalAccess', _193 => _193.feedback]);
|
4517
4417
|
if (!adapter) throw new Error("Feedback adapter not configured");
|
4518
4418
|
const { message } = this.repository.getMessage(messageId);
|
4519
4419
|
adapter.submit({ message, type });
|
@@ -4522,8 +4422,8 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4522
4422
|
this._subscriptions.add(callback);
|
4523
4423
|
return () => this._subscriptions.delete(callback);
|
4524
4424
|
}
|
4525
|
-
|
4526
|
-
_optionalChain([this, 'access',
|
4425
|
+
__init32() {this.updateMessages = (messages) => {
|
4426
|
+
_optionalChain([this, 'access', _194 => _194._store, 'access', _195 => _195.setMessages, 'optionalCall', _196 => _196(
|
4527
4427
|
messages.flatMap(getExternalStoreMessage).filter((m) => m != null)
|
4528
4428
|
)]);
|
4529
4429
|
}}
|
@@ -4619,19 +4519,18 @@ var joinExternalMessages = (messages) => {
|
|
4619
4519
|
);
|
4620
4520
|
}
|
4621
4521
|
} else {
|
4622
|
-
const content = output.content;
|
4623
4522
|
const role = output.role;
|
4624
4523
|
switch (role) {
|
4625
4524
|
case "system":
|
4626
4525
|
case "user":
|
4627
|
-
return
|
4526
|
+
return output;
|
4628
4527
|
case "assistant":
|
4629
4528
|
if (assistantMessage.content.length === 0) {
|
4630
4529
|
assistantMessage.id = output.id;
|
4631
4530
|
assistantMessage.createdAt ??= output.createdAt;
|
4632
4531
|
assistantMessage.status ??= output.status;
|
4633
4532
|
}
|
4634
|
-
assistantMessage.content.push(...content);
|
4533
|
+
assistantMessage.content.push(...output.content);
|
4635
4534
|
break;
|
4636
4535
|
default: {
|
4637
4536
|
const unsupportedRole = role;
|
@@ -4814,8 +4713,8 @@ var WebSpeechSynthesisAdapter = class {
|
|
4814
4713
|
};
|
4815
4714
|
|
4816
4715
|
// src/runtimes/attachment/SimpleImageAttachmentAdapter.ts
|
4817
|
-
var SimpleImageAttachmentAdapter = (_class12 = class {constructor() { _class12.prototype.
|
4818
|
-
|
4716
|
+
var SimpleImageAttachmentAdapter = (_class12 = class {constructor() { _class12.prototype.__init33.call(this); }
|
4717
|
+
__init33() {this.accept = "image/*"}
|
4819
4718
|
async add(state) {
|
4820
4719
|
return {
|
4821
4720
|
id: state.file.name,
|
@@ -4846,8 +4745,8 @@ var getFileDataURL = (file) => new Promise((resolve, reject) => {
|
|
4846
4745
|
});
|
4847
4746
|
|
4848
4747
|
// src/runtimes/attachment/SimpleTextAttachmentAdapter.ts
|
4849
|
-
var SimpleTextAttachmentAdapter = (_class13 = class {constructor() { _class13.prototype.
|
4850
|
-
|
4748
|
+
var SimpleTextAttachmentAdapter = (_class13 = class {constructor() { _class13.prototype.__init34.call(this); }
|
4749
|
+
__init34() {this.accept = "text/plain,text/html,text/markdown,text/csv,text/xml,text/json,text/css"}
|
4851
4750
|
async add(state) {
|
4852
4751
|
return {
|
4853
4752
|
id: state.file.name,
|
@@ -4965,7 +4864,7 @@ var ThreadConfigProvider = ({
|
|
4965
4864
|
}) => {
|
4966
4865
|
const hasAssistant = !!useAssistantRuntime({ optional: true });
|
4967
4866
|
const configProvider = config && Object.keys(_nullishCoalesce(config, () => ( {}))).length > 0 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children });
|
4968
|
-
if (!_optionalChain([config, 'optionalAccess',
|
4867
|
+
if (!_optionalChain([config, 'optionalAccess', _197 => _197.runtime])) return configProvider;
|
4969
4868
|
if (hasAssistant) {
|
4970
4869
|
throw new Error(
|
4971
4870
|
"You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
|
@@ -5293,7 +5192,7 @@ var AssistantMessageContent = _react.forwardRef.call(void 0, ({ components: comp
|
|
5293
5192
|
{
|
5294
5193
|
components: {
|
5295
5194
|
...componentsProp,
|
5296
|
-
Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess',
|
5195
|
+
Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _198 => _198.Text]), () => ( components.Text)), () => ( content_part_default.Text)),
|
5297
5196
|
tools: toolsComponents
|
5298
5197
|
}
|
5299
5198
|
}
|
@@ -5436,7 +5335,7 @@ var ComposerAttachments = ({ components }) => {
|
|
5436
5335
|
{
|
5437
5336
|
components: {
|
5438
5337
|
...components,
|
5439
|
-
Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5338
|
+
Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _199 => _199.Attachment]), () => ( composer_attachment_default))
|
5440
5339
|
}
|
5441
5340
|
}
|
5442
5341
|
) });
|
@@ -5568,7 +5467,7 @@ var ThreadWelcomeSuggestion = ({
|
|
5568
5467
|
};
|
5569
5468
|
var ThreadWelcomeSuggestions = () => {
|
5570
5469
|
const { welcome: { suggestions } = {} } = useThreadConfig();
|
5571
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([suggestions, 'optionalAccess',
|
5470
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([suggestions, 'optionalAccess', _200 => _200.map, 'call', _201 => _201((suggestion, idx) => {
|
5572
5471
|
const key = `${suggestion.prompt}-${idx}`;
|
5573
5472
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestion, { suggestion }, key);
|
5574
5473
|
})]) });
|
@@ -5667,7 +5566,7 @@ var UserMessageContent = _react.forwardRef.call(void 0,
|
|
5667
5566
|
{
|
5668
5567
|
components: {
|
5669
5568
|
...components,
|
5670
|
-
Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5569
|
+
Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _202 => _202.Text]), () => ( content_part_default.Text))
|
5671
5570
|
}
|
5672
5571
|
}
|
5673
5572
|
) });
|
@@ -5685,7 +5584,7 @@ var UserMessageAttachments = ({
|
|
5685
5584
|
{
|
5686
5585
|
components: {
|
5687
5586
|
...components,
|
5688
|
-
Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5587
|
+
Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _203 => _203.Attachment]), () => ( user_message_attachment_default))
|
5689
5588
|
}
|
5690
5589
|
}
|
5691
5590
|
) }) });
|
@@ -5786,10 +5685,10 @@ var ThreadMessages = ({ components, ...rest }) => {
|
|
5786
5685
|
thread_exports.Messages,
|
5787
5686
|
{
|
5788
5687
|
components: {
|
5789
|
-
UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5790
|
-
EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5791
|
-
AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5792
|
-
SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5688
|
+
UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _204 => _204.UserMessage]), () => ( user_message_default)),
|
5689
|
+
EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _205 => _205.EditComposer]), () => ( edit_composer_default)),
|
5690
|
+
AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _206 => _206.AssistantMessage]), () => ( assistant_message_default)),
|
5691
|
+
SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _207 => _207.SystemMessage]), () => ( SystemMessage))
|
5793
5692
|
},
|
5794
5693
|
...rest
|
5795
5694
|
}
|
@@ -6008,5 +5907,6 @@ var assistant_modal_default = Object.assign(AssistantModal, exports13);
|
|
6008
5907
|
|
6009
5908
|
|
6010
5909
|
|
6011
|
-
|
5910
|
+
|
5911
|
+
exports.ActionBarPrimitive = actionBar_exports; exports.AssistantActionBar = assistant_action_bar_default; exports.AssistantMessage = assistant_message_default; exports.AssistantModal = assistant_modal_default; exports.AssistantModalPrimitive = assistantModal_exports; exports.AssistantRuntimeProvider = AssistantRuntimeProvider; exports.BranchPicker = branch_picker_default; exports.BranchPickerPrimitive = branchPicker_exports; exports.Composer = composer_default; exports.ComposerAttachment = composer_attachment_default; exports.ComposerPrimitive = composer_exports; exports.CompositeAttachmentAdapter = CompositeAttachmentAdapter; exports.ContentPart = content_part_default; exports.ContentPartPrimitive = contentPart_exports; exports.EdgeChatAdapter = EdgeChatAdapter; exports.EditComposer = edit_composer_default; exports.INTERNAL = internal_exports; exports.MessagePrimitive = message_exports; exports.SimpleImageAttachmentAdapter = SimpleImageAttachmentAdapter; exports.SimpleTextAttachmentAdapter = SimpleTextAttachmentAdapter; exports.TextContentPartProvider = TextContentPartProvider; exports.Thread = thread_default; exports.ThreadConfigProvider = ThreadConfigProvider; exports.ThreadPrimitive = thread_exports; exports.ThreadWelcome = thread_welcome_default; exports.UserActionBar = user_action_bar_default; exports.UserMessage = user_message_default; exports.UserMessageAttachment = user_message_attachment_default; exports.WebSpeechSynthesisAdapter = WebSpeechSynthesisAdapter; exports.fromCoreMessage = fromCoreMessage; exports.fromCoreMessages = fromCoreMessages; exports.fromLanguageModelMessages = fromLanguageModelMessages; exports.fromLanguageModelTools = fromLanguageModelTools; exports.getExternalStoreMessage = getExternalStoreMessage; exports.makeAssistantTool = makeAssistantTool; exports.makeAssistantToolUI = makeAssistantToolUI; exports.streamUtils = streamUtils; exports.subscribeToMainThread = subscribeToMainThread; exports.toCoreMessage = _chunk5KIEXJRKjs.toCoreMessage; exports.toCoreMessages = _chunk5KIEXJRKjs.toCoreMessages; exports.toLanguageModelMessages = _chunk5KIEXJRKjs.toLanguageModelMessages; exports.toLanguageModelTools = _chunk5KIEXJRKjs.toLanguageModelTools; exports.useActionBarCopy = useActionBarCopy; exports.useActionBarEdit = useActionBarEdit; exports.useActionBarFeedbackNegative = useActionBarFeedbackNegative; exports.useActionBarFeedbackPositive = useActionBarFeedbackPositive; exports.useActionBarReload = useActionBarReload; exports.useActionBarSpeak = useActionBarSpeak; exports.useActionBarStopSpeaking = useActionBarStopSpeaking; exports.useAppendMessage = useAppendMessage; exports.useAssistantActions = useAssistantActions; exports.useAssistantActionsStore = useAssistantActionsStore; exports.useAssistantContext = useAssistantContext; exports.useAssistantInstructions = useAssistantInstructions; exports.useAssistantRuntime = useAssistantRuntime; exports.useAssistantRuntimeStore = useAssistantRuntimeStore; exports.useAssistantTool = useAssistantTool; exports.useAssistantToolUI = useAssistantToolUI; exports.useBranchPickerCount = useBranchPickerCount; exports.useBranchPickerNext = useBranchPickerNext; exports.useBranchPickerNumber = useBranchPickerNumber; exports.useBranchPickerPrevious = useBranchPickerPrevious; exports.useComposer = useComposer; exports.useComposerAddAttachment = useComposerAddAttachment; exports.useComposerCancel = useComposerCancel; exports.useComposerContext = useComposerContext; exports.useComposerIf = useComposerIf; exports.useComposerSend = useComposerSend; exports.useComposerStore = useComposerStore; exports.useContentPart = useContentPart; exports.useContentPartContext = useContentPartContext; exports.useContentPartDisplay = useContentPartDisplay; exports.useContentPartImage = useContentPartImage; exports.useContentPartStore = useContentPartStore; exports.useContentPartText = useContentPartText; exports.useDangerousInBrowserRuntime = useDangerousInBrowserRuntime; exports.useEdgeRuntime = useEdgeRuntime; exports.useEditComposer = useEditComposer; exports.useEditComposerStore = useEditComposerStore; exports.useExternalMessageConverter = useExternalMessageConverter; exports.useExternalStoreRuntime = useExternalStoreRuntime; exports.useLocalRuntime = useLocalRuntime; exports.useMessage = useMessage; exports.useMessageContext = useMessageContext; exports.useMessageIf = useMessageIf; exports.useMessageRuntime = useMessageRuntime; exports.useMessageStore = useMessageStore; exports.useMessageUtils = useMessageUtils; exports.useMessageUtilsStore = useMessageUtilsStore; exports.useSwitchToNewThread = useSwitchToNewThread; exports.useThread = useThread; exports.useThreadActions = useThreadActions; exports.useThreadActionsStore = useThreadActionsStore; exports.useThreadComposer = useThreadComposer; exports.useThreadComposerStore = useThreadComposerStore; exports.useThreadConfig = useThreadConfig; exports.useThreadContext = useThreadContext; exports.useThreadEmpty = useThreadEmpty; exports.useThreadIf = useThreadIf; exports.useThreadMessages = useThreadMessages; exports.useThreadMessagesStore = useThreadMessagesStore; exports.useThreadRuntime = useThreadRuntime; exports.useThreadRuntimeStore = useThreadRuntimeStore; exports.useThreadScrollToBottom = useThreadScrollToBottom; exports.useThreadStore = useThreadStore; exports.useThreadSuggestion = useThreadSuggestion; exports.useThreadViewport = useThreadViewport; exports.useThreadViewportStore = useThreadViewportStore; exports.useToolUIs = useToolUIs; exports.useToolUIsStore = useToolUIsStore;
|
6012
5912
|
//# sourceMappingURL=index.js.map
|