@assistant-ui/react 0.5.66 → 0.5.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{edge-D7ch2oPK.d.mts → edge-BhYWMe-K.d.mts} +26 -6
- package/dist/{edge-D7ch2oPK.d.ts → edge-BhYWMe-K.d.ts} +26 -6
- package/dist/index.d.mts +485 -663
- package/dist/index.d.ts +485 -663
- package/dist/index.js +1208 -962
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1297 -1051
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13;
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17;
|
2
2
|
|
3
3
|
|
4
4
|
|
@@ -144,7 +144,9 @@ var { useThread, useThreadStore } = createContextStoreHook(
|
|
144
144
|
useThreadContext,
|
145
145
|
"useThread"
|
146
146
|
);
|
147
|
-
var
|
147
|
+
var messages = createContextStoreHook(useThreadContext, "useThreadMessages");
|
148
|
+
var useThreadMessages = messages.useThreadMessages;
|
149
|
+
var useThreadMessagesStore = messages.useThreadMessagesStore;
|
148
150
|
var {
|
149
151
|
useComposer: useThreadComposer,
|
150
152
|
useComposerStore: useThreadComposerStore
|
@@ -154,56 +156,6 @@ var {
|
|
154
156
|
useViewportStore: useThreadViewportStore
|
155
157
|
} = createContextStoreHook(useThreadContext, "useViewport");
|
156
158
|
|
157
|
-
// src/context/stores/ThreadComposer.ts
|
158
|
-
|
159
|
-
var makeThreadComposerStore = (runtime) => {
|
160
|
-
const focusListeners = /* @__PURE__ */ new Set();
|
161
|
-
return _zustand.create.call(void 0, )((_, get) => {
|
162
|
-
return {
|
163
|
-
type: "thread",
|
164
|
-
get value() {
|
165
|
-
return get().text;
|
166
|
-
},
|
167
|
-
setValue(value) {
|
168
|
-
get().setText(value);
|
169
|
-
},
|
170
|
-
...runtime.getState(),
|
171
|
-
canCancel: false,
|
172
|
-
// "TODO",
|
173
|
-
isEditing: true,
|
174
|
-
addAttachment: (file) => {
|
175
|
-
runtime.addAttachment(file);
|
176
|
-
},
|
177
|
-
removeAttachment: (attachmentId) => {
|
178
|
-
runtime.removeAttachment(attachmentId);
|
179
|
-
},
|
180
|
-
reset: () => {
|
181
|
-
runtime.reset();
|
182
|
-
},
|
183
|
-
setText: (text) => {
|
184
|
-
runtime.setText(text);
|
185
|
-
},
|
186
|
-
send: () => {
|
187
|
-
runtime.send();
|
188
|
-
},
|
189
|
-
cancel: () => {
|
190
|
-
runtime.cancel();
|
191
|
-
},
|
192
|
-
focus: () => {
|
193
|
-
for (const listener of focusListeners) {
|
194
|
-
listener();
|
195
|
-
}
|
196
|
-
},
|
197
|
-
onFocus: (listener) => {
|
198
|
-
focusListeners.add(listener);
|
199
|
-
return () => {
|
200
|
-
focusListeners.delete(listener);
|
201
|
-
};
|
202
|
-
}
|
203
|
-
};
|
204
|
-
});
|
205
|
-
};
|
206
|
-
|
207
159
|
// src/context/stores/ThreadViewport.tsx
|
208
160
|
|
209
161
|
var makeThreadViewportStore = () => {
|
@@ -258,9 +210,9 @@ var useThreadMessagesStore2 = (runtime) => {
|
|
258
210
|
return store;
|
259
211
|
};
|
260
212
|
var useThreadComposerStore2 = (runtime) => {
|
261
|
-
const [store] = _react.useState.call(void 0, () =>
|
213
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime.getState()));
|
262
214
|
_react.useEffect.call(void 0, () => {
|
263
|
-
const updateState = () => writableStore(store).setState(runtime.getState());
|
215
|
+
const updateState = () => writableStore(store).setState(runtime.getState(), true);
|
264
216
|
updateState();
|
265
217
|
return runtime.subscribe(updateState);
|
266
218
|
}, [runtime, store]);
|
@@ -282,13 +234,7 @@ var ThreadRuntimeProvider = ({ children, runtime }) => {
|
|
282
234
|
useViewport
|
283
235
|
};
|
284
236
|
}, [useThread2, useThreadRuntime2, useThreadMessages2, useThreadComposer2]);
|
285
|
-
|
286
|
-
(t) => t.unstable_synchronizer
|
287
|
-
);
|
288
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, ThreadContext.Provider, { value: context, children: [
|
289
|
-
Synchronizer && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Synchronizer, {}),
|
290
|
-
children
|
291
|
-
] });
|
237
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadContext.Provider, { value: context, children });
|
292
238
|
};
|
293
239
|
|
294
240
|
// src/context/providers/AssistantRuntimeProvider.tsx
|
@@ -331,11 +277,47 @@ var useContentPartContext = createContextHook(
|
|
331
277
|
ContentPartContext,
|
332
278
|
"a component passed to <MessagePrimitive.Content components={...}>"
|
333
279
|
);
|
280
|
+
function useContentPartRuntime(options) {
|
281
|
+
const context = useContentPartContext(options);
|
282
|
+
if (!context) return null;
|
283
|
+
return context.useContentPartRuntime();
|
284
|
+
}
|
334
285
|
var { useContentPart, useContentPartStore } = createContextStoreHook(
|
335
286
|
useContentPartContext,
|
336
287
|
"useContentPart"
|
337
288
|
);
|
338
289
|
|
290
|
+
// src/api/ContentPartRuntime.ts
|
291
|
+
var ContentPartRuntime = class {
|
292
|
+
constructor(contentBinding, messageApi, threadApi) {
|
293
|
+
this.contentBinding = contentBinding;
|
294
|
+
this.messageApi = messageApi;
|
295
|
+
this.threadApi = threadApi;
|
296
|
+
}
|
297
|
+
getState() {
|
298
|
+
return this.contentBinding.getState();
|
299
|
+
}
|
300
|
+
addToolResult(result) {
|
301
|
+
const message = this.messageApi.getState();
|
302
|
+
if (!message) throw new Error("Message is not available");
|
303
|
+
const state = this.contentBinding.getState();
|
304
|
+
if (!state) throw new Error("Content part is not available");
|
305
|
+
if (state.type !== "tool-call")
|
306
|
+
throw new Error("Tried to add tool result to non-tool content part");
|
307
|
+
const toolName = state.toolName;
|
308
|
+
const toolCallId = state.toolCallId;
|
309
|
+
this.threadApi.getState().addToolResult({
|
310
|
+
messageId: message.id,
|
311
|
+
toolName,
|
312
|
+
toolCallId,
|
313
|
+
result
|
314
|
+
});
|
315
|
+
}
|
316
|
+
subscribe(callback) {
|
317
|
+
return this.contentBinding.subscribe(callback);
|
318
|
+
}
|
319
|
+
};
|
320
|
+
|
339
321
|
// src/context/providers/TextContentPartProvider.tsx
|
340
322
|
|
341
323
|
var COMPLETE_STATUS = {
|
@@ -346,18 +328,22 @@ var RUNNING_STATUS = {
|
|
346
328
|
};
|
347
329
|
var TextContentPartProvider = ({ children, text, isRunning }) => {
|
348
330
|
const [context] = _react.useState.call(void 0, () => {
|
331
|
+
const useContentPartRuntime2 = _zustand.create.call(void 0,
|
332
|
+
// TODO
|
333
|
+
() => new ContentPartRuntime(null, null, null)
|
334
|
+
);
|
349
335
|
const useContentPart2 = _zustand.create.call(void 0, () => ({
|
350
336
|
status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,
|
351
|
-
part: { type: "text", text }
|
337
|
+
part: { type: "text", text },
|
338
|
+
type: "text",
|
339
|
+
text
|
352
340
|
}));
|
353
|
-
return {
|
354
|
-
useContentPart: useContentPart2
|
355
|
-
};
|
341
|
+
return { useContentPartRuntime: useContentPartRuntime2, useContentPart: useContentPart2 };
|
356
342
|
});
|
357
343
|
_react.useEffect.call(void 0, () => {
|
358
344
|
const state = context.useContentPart.getState();
|
359
|
-
const textUpdated = state.
|
360
|
-
const targetTextPart = textUpdated ? { type: "text", text } : state
|
345
|
+
const textUpdated = state.text !== text;
|
346
|
+
const targetTextPart = textUpdated ? { type: "text", text } : state;
|
361
347
|
const targetStatus = isRunning ? RUNNING_STATUS : COMPLETE_STATUS;
|
362
348
|
const statusUpdated = state.status !== targetStatus;
|
363
349
|
if (!textUpdated && !statusUpdated) return;
|
@@ -400,20 +386,25 @@ var { useEditComposer, useEditComposerStore } = createContextStoreHook(
|
|
400
386
|
// src/context/react/ComposerContext.ts
|
401
387
|
|
402
388
|
var useComposerContext = () => {
|
403
|
-
const { useComposer:
|
389
|
+
const { useComposer: useThreadComposer2 } = useThreadContext();
|
404
390
|
const { useEditComposer: useEditComposer2 } = _nullishCoalesce(useMessageContext({ optional: true }), () => ( {}));
|
405
391
|
return _react.useMemo.call(void 0,
|
406
392
|
() => ({
|
407
|
-
useComposer: _nullishCoalesce(useEditComposer2, () => (
|
393
|
+
useComposer: _nullishCoalesce(useEditComposer2, () => ( useThreadComposer2)),
|
408
394
|
type: useEditComposer2 ? "edit" : "new"
|
409
395
|
}),
|
410
|
-
[useEditComposer2,
|
396
|
+
[useEditComposer2, useThreadComposer2]
|
411
397
|
);
|
412
398
|
};
|
413
399
|
var { useComposer, useComposerStore } = createContextStoreHook(
|
414
400
|
useComposerContext,
|
415
401
|
"useComposer"
|
416
402
|
);
|
403
|
+
function useComposerRuntime(options) {
|
404
|
+
const messageRuntime = useMessageRuntime({ optional: true });
|
405
|
+
const threadRuntime = useThreadRuntime(options);
|
406
|
+
return messageRuntime ? messageRuntime.composer : _nullishCoalesce(_optionalChain([threadRuntime, 'optionalAccess', _5 => _5.composer]), () => ( null));
|
407
|
+
}
|
417
408
|
|
418
409
|
// src/hooks/useAppendMessage.tsx
|
419
410
|
|
@@ -462,7 +453,7 @@ var useAssistantTool = (tool) => {
|
|
462
453
|
const unsub2 = render ? toolUIsStore.getState().setToolUI(toolName, render) : void 0;
|
463
454
|
return () => {
|
464
455
|
unsub1();
|
465
|
-
_optionalChain([unsub2, 'optionalCall',
|
456
|
+
_optionalChain([unsub2, 'optionalCall', _6 => _6()]);
|
466
457
|
};
|
467
458
|
}, [assistantRuntime, toolUIsStore, tool]);
|
468
459
|
};
|
@@ -579,12 +570,11 @@ var useActionBarCopy = ({
|
|
579
570
|
// src/primitive-hooks/actionBar/useActionBarEdit.tsx
|
580
571
|
|
581
572
|
var useActionBarEdit = () => {
|
582
|
-
const
|
573
|
+
const messageRuntime = useMessageRuntime();
|
583
574
|
const disabled = useEditComposer((c) => c.isEditing);
|
584
575
|
const callback = _react.useCallback.call(void 0, () => {
|
585
|
-
|
586
|
-
|
587
|
-
}, [editComposerStore]);
|
576
|
+
messageRuntime.composer.beginEdit();
|
577
|
+
}, [messageRuntime]);
|
588
578
|
if (disabled) return null;
|
589
579
|
return callback;
|
590
580
|
};
|
@@ -594,7 +584,7 @@ var useActionBarEdit = () => {
|
|
594
584
|
var useActionBarReload = () => {
|
595
585
|
const messageStore = useMessageStore();
|
596
586
|
const threadStore = useThreadStore();
|
597
|
-
const
|
587
|
+
const messageRuntime = useMessageRuntime();
|
598
588
|
const threadComposerStore = useThreadComposerStore();
|
599
589
|
const threadViewportStore = useThreadViewportStore();
|
600
590
|
const disabled = useCombinedStore(
|
@@ -602,11 +592,10 @@ var useActionBarReload = () => {
|
|
602
592
|
(t, m) => t.isRunning || t.isDisabled || m.role !== "assistant"
|
603
593
|
);
|
604
594
|
const callback = _react.useCallback.call(void 0, () => {
|
605
|
-
|
606
|
-
threadRuntime.startRun(parentId);
|
595
|
+
messageRuntime.reload();
|
607
596
|
threadViewportStore.getState().scrollToBottom();
|
608
597
|
threadComposerStore.getState().focus();
|
609
|
-
}, [
|
598
|
+
}, [messageRuntime, threadComposerStore, threadViewportStore]);
|
610
599
|
if (disabled) return null;
|
611
600
|
return callback;
|
612
601
|
};
|
@@ -616,19 +605,18 @@ var useActionBarReload = () => {
|
|
616
605
|
var useActionBarSpeak = () => {
|
617
606
|
const messageStore = useMessageStore();
|
618
607
|
const editComposerStore = useEditComposerStore();
|
619
|
-
const
|
608
|
+
const messageRunime = useMessageRuntime();
|
620
609
|
const messageUtilsStore = useMessageUtilsStore();
|
621
610
|
const hasSpeakableContent = useCombinedStore(
|
622
611
|
[messageStore, editComposerStore],
|
623
|
-
(
|
612
|
+
(message, c) => {
|
624
613
|
return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
|
625
614
|
}
|
626
615
|
);
|
627
616
|
const callback = _react.useCallback.call(void 0, async () => {
|
628
|
-
const
|
629
|
-
const utt = threadRuntime.speak(message.id);
|
617
|
+
const utt = messageRunime.speak();
|
630
618
|
messageUtilsStore.getState().addUtterance(utt);
|
631
|
-
}, [
|
619
|
+
}, [messageRunime, messageUtilsStore]);
|
632
620
|
if (!hasSpeakableContent) return null;
|
633
621
|
return callback;
|
634
622
|
};
|
@@ -648,32 +636,28 @@ var useActionBarStopSpeaking = () => {
|
|
648
636
|
// src/primitive-hooks/actionBar/useActionBarFeedbackPositive.tsx
|
649
637
|
|
650
638
|
var useActionBarFeedbackPositive = () => {
|
651
|
-
const
|
652
|
-
const messageStore = useMessageStore();
|
639
|
+
const messageRuntime = useMessageRuntime();
|
653
640
|
const messageUtilsStore = useMessageUtilsStore();
|
654
641
|
const callback = _react.useCallback.call(void 0, () => {
|
655
|
-
|
656
|
-
messageId: messageStore.getState().id,
|
642
|
+
messageRuntime.submitFeedback({
|
657
643
|
type: "positive"
|
658
644
|
});
|
659
645
|
messageUtilsStore.getState().setSubmittedFeedback("positive");
|
660
|
-
}, [
|
646
|
+
}, [messageUtilsStore, messageRuntime]);
|
661
647
|
return callback;
|
662
648
|
};
|
663
649
|
|
664
650
|
// src/primitive-hooks/actionBar/useActionBarFeedbackNegative.tsx
|
665
651
|
|
666
652
|
var useActionBarFeedbackNegative = () => {
|
667
|
-
const
|
668
|
-
const messageStore = useMessageStore();
|
653
|
+
const messageRuntime = useMessageRuntime();
|
669
654
|
const messageUtilsStore = useMessageUtilsStore();
|
670
655
|
const callback = _react.useCallback.call(void 0, () => {
|
671
|
-
|
672
|
-
messageId: messageStore.getState().id,
|
656
|
+
messageRuntime.submitFeedback({
|
673
657
|
type: "negative"
|
674
658
|
});
|
675
659
|
messageUtilsStore.getState().setSubmittedFeedback("negative");
|
676
|
-
}, [
|
660
|
+
}, [messageUtilsStore, messageRuntime]);
|
677
661
|
return callback;
|
678
662
|
};
|
679
663
|
|
@@ -782,7 +766,7 @@ var useComposerAddAttachment = () => {
|
|
782
766
|
input.accept = attachmentAccept;
|
783
767
|
}
|
784
768
|
input.onchange = (e) => {
|
785
|
-
const file = _optionalChain([e, 'access',
|
769
|
+
const file = _optionalChain([e, 'access', _7 => _7.target, 'access', _8 => _8.files, 'optionalAccess', _9 => _9[0]]);
|
786
770
|
if (!file) return;
|
787
771
|
addAttachment(file);
|
788
772
|
};
|
@@ -795,7 +779,7 @@ var useComposerAddAttachment = () => {
|
|
795
779
|
// src/primitive-hooks/contentPart/useContentPartDisplay.tsx
|
796
780
|
var useContentPartDisplay = () => {
|
797
781
|
const display = useContentPart((c) => {
|
798
|
-
if (c.
|
782
|
+
if (c.type !== "ui")
|
799
783
|
throw new Error(
|
800
784
|
"This component can only be used inside ui content parts."
|
801
785
|
);
|
@@ -807,7 +791,7 @@ var useContentPartDisplay = () => {
|
|
807
791
|
// src/primitive-hooks/contentPart/useContentPartImage.tsx
|
808
792
|
var useContentPartImage = () => {
|
809
793
|
const image = useContentPart((c) => {
|
810
|
-
if (c.
|
794
|
+
if (c.type !== "image")
|
811
795
|
throw new Error(
|
812
796
|
"ContentPartImage can only be used inside image content parts."
|
813
797
|
);
|
@@ -819,7 +803,7 @@ var useContentPartImage = () => {
|
|
819
803
|
// src/primitive-hooks/contentPart/useContentPartText.tsx
|
820
804
|
var useContentPartText = () => {
|
821
805
|
const text = useContentPart((c) => {
|
822
|
-
if (c.
|
806
|
+
if (c.type !== "text")
|
823
807
|
throw new Error(
|
824
808
|
"ContentPartText can only be used inside text content parts."
|
825
809
|
);
|
@@ -857,20 +841,15 @@ var useMessageIf = (props) => {
|
|
857
841
|
|
858
842
|
// src/primitive-hooks/thread/useThreadIf.tsx
|
859
843
|
var useThreadIf = (props) => {
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
(thread
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
if (props.disabled === true && thread.isDisabled) return false;
|
870
|
-
if (props.disabled === false && thread.isDisabled) return false;
|
871
|
-
return true;
|
872
|
-
}
|
873
|
-
);
|
844
|
+
return useThread((thread) => {
|
845
|
+
if (props.empty === true && thread.messages.length !== 0) return false;
|
846
|
+
if (props.empty === false && thread.messages.length === 0) return false;
|
847
|
+
if (props.running === true && !thread.isRunning) return false;
|
848
|
+
if (props.running === false && thread.isRunning) return false;
|
849
|
+
if (props.disabled === true && thread.isDisabled) return false;
|
850
|
+
if (props.disabled === false && thread.isDisabled) return false;
|
851
|
+
return true;
|
852
|
+
});
|
874
853
|
};
|
875
854
|
|
876
855
|
// src/primitive-hooks/thread/useThreadEmpty.tsx
|
@@ -993,7 +972,7 @@ var ActionBarPrimitiveCopy = _react.forwardRef.call(void 0, ({ copiedDuration, o
|
|
993
972
|
ref: forwardedRef,
|
994
973
|
disabled: disabled || !callback,
|
995
974
|
onClick: _primitive.composeEventHandlers.call(void 0, onClick, () => {
|
996
|
-
_optionalChain([callback, 'optionalCall',
|
975
|
+
_optionalChain([callback, 'optionalCall', _10 => _10()]);
|
997
976
|
})
|
998
977
|
}
|
999
978
|
);
|
@@ -1025,7 +1004,7 @@ var createActionButton = (displayName, useActionButton, forwardProps = []) => {
|
|
1025
1004
|
ref: forwardedRef,
|
1026
1005
|
disabled: primitiveProps.disabled || !callback,
|
1027
1006
|
onClick: _primitive.composeEventHandlers.call(void 0, primitiveProps.onClick, () => {
|
1028
|
-
_optionalChain([callback, 'optionalCall',
|
1007
|
+
_optionalChain([callback, 'optionalCall', _11 => _11()]);
|
1029
1008
|
})
|
1030
1009
|
}
|
1031
1010
|
);
|
@@ -1074,7 +1053,7 @@ var ActionBarPrimitiveStopSpeaking = _react.forwardRef.call(void 0, (props, ref)
|
|
1074
1053
|
...props,
|
1075
1054
|
ref,
|
1076
1055
|
onClick: _primitive.composeEventHandlers.call(void 0, props.onClick, () => {
|
1077
|
-
_optionalChain([callback, 'optionalCall',
|
1056
|
+
_optionalChain([callback, 'optionalCall', _12 => _12()]);
|
1078
1057
|
})
|
1079
1058
|
}
|
1080
1059
|
);
|
@@ -1100,7 +1079,7 @@ var ActionBarPrimitiveFeedbackPositive = _react.forwardRef.call(void 0, ({ onCli
|
|
1100
1079
|
ref: forwardedRef,
|
1101
1080
|
disabled: disabled || !callback,
|
1102
1081
|
onClick: _primitive.composeEventHandlers.call(void 0, onClick, () => {
|
1103
|
-
_optionalChain([callback, 'optionalCall',
|
1082
|
+
_optionalChain([callback, 'optionalCall', _13 => _13()]);
|
1104
1083
|
})
|
1105
1084
|
}
|
1106
1085
|
);
|
@@ -1126,7 +1105,7 @@ var ActionBarPrimitiveFeedbackNegative = _react.forwardRef.call(void 0, ({ onCli
|
|
1126
1105
|
ref: forwardedRef,
|
1127
1106
|
disabled: disabled || !callback,
|
1128
1107
|
onClick: _primitive.composeEventHandlers.call(void 0, onClick, () => {
|
1129
|
-
_optionalChain([callback, 'optionalCall',
|
1108
|
+
_optionalChain([callback, 'optionalCall', _14 => _14()]);
|
1130
1109
|
})
|
1131
1110
|
}
|
1132
1111
|
);
|
@@ -1381,74 +1360,35 @@ MessagePrimitiveIf.displayName = "MessagePrimitive.If";
|
|
1381
1360
|
// src/primitives/message/MessageContent.tsx
|
1382
1361
|
|
1383
1362
|
|
1384
|
-
// src/context/providers/
|
1363
|
+
// src/context/providers/ContentPartRuntimeProvider.tsx
|
1385
1364
|
|
1386
1365
|
|
1387
1366
|
|
1388
|
-
var
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
if (part.type !== "tool-call") {
|
1395
|
-
if ("reason" in message.status && message.status.reason === "tool-calls" && isLastPart)
|
1396
|
-
throw new Error(
|
1397
|
-
"Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui."
|
1398
|
-
);
|
1399
|
-
return isLastPart ? message.status : COMPLETE_STATUS2;
|
1400
|
-
}
|
1401
|
-
if (!!part.result) {
|
1402
|
-
return COMPLETE_STATUS2;
|
1403
|
-
}
|
1404
|
-
return message.status;
|
1405
|
-
};
|
1406
|
-
var EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });
|
1407
|
-
var getContentPartState = ({ message }, useContentPart2, partIndex) => {
|
1408
|
-
let part = message.content[partIndex];
|
1409
|
-
if (!part) {
|
1410
|
-
if (message.content.length === 0 && partIndex === 0) {
|
1411
|
-
part = EMPTY_CONTENT;
|
1412
|
-
} else {
|
1413
|
-
return null;
|
1414
|
-
}
|
1415
|
-
} else if (message.content.length === 1 && part.type === "text" && part.text.length === 0) {
|
1416
|
-
part = EMPTY_CONTENT;
|
1417
|
-
}
|
1418
|
-
const status = toContentPartStatus(message, partIndex, part);
|
1419
|
-
const currentState = _optionalChain([useContentPart2, 'optionalAccess', _14 => _14.getState, 'call', _15 => _15()]);
|
1420
|
-
if (currentState && currentState.part === part && currentState.status === status)
|
1421
|
-
return null;
|
1422
|
-
return Object.freeze({ part, status });
|
1367
|
+
var useContentPartRuntimeStore = (runtime) => {
|
1368
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime));
|
1369
|
+
_react.useEffect.call(void 0, () => {
|
1370
|
+
writableStore(store).setState(runtime, true);
|
1371
|
+
}, [runtime, store]);
|
1372
|
+
return store;
|
1423
1373
|
};
|
1424
|
-
var
|
1425
|
-
const
|
1426
|
-
const [context] = _react.useState.call(void 0, () => {
|
1427
|
-
const useContentPart2 = _zustand.create.call(void 0,
|
1428
|
-
() => getContentPartState(messageStore.getState(), void 0, partIndex)
|
1429
|
-
);
|
1430
|
-
return { useContentPart: useContentPart2 };
|
1431
|
-
});
|
1374
|
+
var useContentPartStore2 = (runtime) => {
|
1375
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime.getState()));
|
1432
1376
|
_react.useEffect.call(void 0, () => {
|
1433
|
-
const
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
);
|
1439
|
-
if (!newState) return;
|
1440
|
-
writableStore(context.useContentPart).setState(newState, true);
|
1441
|
-
};
|
1442
|
-
syncContentPart(messageStore.getState());
|
1443
|
-
return messageStore.subscribe(syncContentPart);
|
1444
|
-
}, [context, messageStore, partIndex]);
|
1445
|
-
return context;
|
1377
|
+
const updateState = () => writableStore(store).setState(runtime.getState(), true);
|
1378
|
+
updateState();
|
1379
|
+
return runtime.subscribe(updateState);
|
1380
|
+
}, [runtime, store]);
|
1381
|
+
return store;
|
1446
1382
|
};
|
1447
|
-
var
|
1448
|
-
|
1383
|
+
var ContentPartRuntimeProvider = ({
|
1384
|
+
runtime,
|
1449
1385
|
children
|
1450
1386
|
}) => {
|
1451
|
-
const
|
1387
|
+
const useContentPartRuntime2 = useContentPartRuntimeStore(runtime);
|
1388
|
+
const useContentPart2 = useContentPartStore2(runtime);
|
1389
|
+
const [context] = _react.useState.call(void 0, () => {
|
1390
|
+
return { useContentPartRuntime: useContentPartRuntime2, useContentPart: useContentPart2 };
|
1391
|
+
});
|
1452
1392
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartContext.Provider, { value: context, children });
|
1453
1393
|
};
|
1454
1394
|
|
@@ -1493,7 +1433,7 @@ var withSmoothContextProvider = (Component) => {
|
|
1493
1433
|
};
|
1494
1434
|
function useSmoothContext(options) {
|
1495
1435
|
const context = _react.useContext.call(void 0, SmoothContext);
|
1496
|
-
if (!_optionalChain([options, 'optionalAccess',
|
1436
|
+
if (!_optionalChain([options, 'optionalAccess', _15 => _15.optional]) && !context)
|
1497
1437
|
throw new Error(
|
1498
1438
|
"This component must be used within a SmoothContextProvider."
|
1499
1439
|
);
|
@@ -1553,9 +1493,7 @@ var SMOOTH_STATUS = Object.freeze({
|
|
1553
1493
|
type: "running"
|
1554
1494
|
});
|
1555
1495
|
var useSmooth = (state, smooth = false) => {
|
1556
|
-
const {
|
1557
|
-
part: { text }
|
1558
|
-
} = state;
|
1496
|
+
const { text } = state;
|
1559
1497
|
const id = useMessage({
|
1560
1498
|
optional: true,
|
1561
1499
|
selector: (m) => m.id
|
@@ -1567,17 +1505,17 @@ var useSmooth = (state, smooth = false) => {
|
|
1567
1505
|
setDisplayedText(text2);
|
1568
1506
|
if (smoothStatusStore) {
|
1569
1507
|
writableStore(smoothStatusStore).setState(
|
1570
|
-
text2 !== state.
|
1508
|
+
text2 !== state.text ? SMOOTH_STATUS : state.status
|
1571
1509
|
);
|
1572
1510
|
}
|
1573
1511
|
});
|
1574
1512
|
_react.useEffect.call(void 0, () => {
|
1575
1513
|
if (smoothStatusStore) {
|
1576
1514
|
writableStore(smoothStatusStore).setState(
|
1577
|
-
text !== state.
|
1515
|
+
text !== state.text ? SMOOTH_STATUS : state.status
|
1578
1516
|
);
|
1579
1517
|
}
|
1580
|
-
}, [smoothStatusStore, text, displayedText, state.status, state.
|
1518
|
+
}, [smoothStatusStore, text, displayedText, state.status, state.text]);
|
1581
1519
|
const [animatorRef] = _react.useState.call(void 0,
|
1582
1520
|
new TextStreamAnimator(text, setText)
|
1583
1521
|
);
|
@@ -1604,6 +1542,8 @@ var useSmooth = (state, smooth = false) => {
|
|
1604
1542
|
}, [animatorRef]);
|
1605
1543
|
return _react.useMemo.call(void 0,
|
1606
1544
|
() => smooth ? {
|
1545
|
+
type: "text",
|
1546
|
+
text: displayedText,
|
1607
1547
|
part: { type: "text", text: displayedText },
|
1608
1548
|
status: text === displayedText ? state.status : SMOOTH_STATUS
|
1609
1549
|
} : state,
|
@@ -1614,10 +1554,7 @@ var useSmooth = (state, smooth = false) => {
|
|
1614
1554
|
// src/primitives/contentPart/ContentPartText.tsx
|
1615
1555
|
|
1616
1556
|
var ContentPartPrimitiveText = _react.forwardRef.call(void 0, ({ smooth = true, component: Component = "span", ...rest }, forwardedRef) => {
|
1617
|
-
const {
|
1618
|
-
part: { text },
|
1619
|
-
status
|
1620
|
-
} = useSmooth(useContentPartText(), smooth);
|
1557
|
+
const { text, status } = useSmooth(useContentPartText(), smooth);
|
1621
1558
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Component, { "data-status": status.type, ...rest, ref: forwardedRef, children: text });
|
1622
1559
|
});
|
1623
1560
|
ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
|
@@ -1627,18 +1564,14 @@ ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
|
|
1627
1564
|
|
1628
1565
|
|
1629
1566
|
var ContentPartPrimitiveImage = _react.forwardRef.call(void 0, (props, forwardedRef) => {
|
1630
|
-
const {
|
1631
|
-
part: { image }
|
1632
|
-
} = useContentPartImage();
|
1567
|
+
const { image } = useContentPartImage();
|
1633
1568
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactprimitive.Primitive.img, { src: image, ...props, ref: forwardedRef });
|
1634
1569
|
});
|
1635
1570
|
ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
|
1636
1571
|
|
1637
1572
|
// src/primitives/contentPart/ContentPartDisplay.tsx
|
1638
1573
|
var ContentPartPrimitiveDisplay = () => {
|
1639
|
-
const {
|
1640
|
-
part: { display }
|
1641
|
-
} = useContentPartDisplay();
|
1574
|
+
const { display } = useContentPartDisplay();
|
1642
1575
|
return _nullishCoalesce(display, () => ( null));
|
1643
1576
|
};
|
1644
1577
|
ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
|
@@ -1650,190 +1583,747 @@ var ContentPartPrimitiveInProgress = ({ children }) => {
|
|
1650
1583
|
};
|
1651
1584
|
ContentPartPrimitiveInProgress.displayName = "ContentPartPrimitive.InProgress";
|
1652
1585
|
|
1653
|
-
// src/
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
Text: () => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "p", { style: { whiteSpace: "pre-line" }, children: [
|
1665
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartPrimitiveText, {}),
|
1666
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartPrimitiveInProgress, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { style: { fontFamily: "revert" }, children: " \u25CF" }) })
|
1667
|
-
] }),
|
1668
|
-
Image: () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartPrimitiveImage, {}),
|
1669
|
-
UI: () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartPrimitiveDisplay, {})
|
1586
|
+
// src/api/AttachmentRuntime.ts
|
1587
|
+
var AttachmentRuntime = class {
|
1588
|
+
constructor(_core) {
|
1589
|
+
this._core = _core;
|
1590
|
+
}
|
1591
|
+
getState() {
|
1592
|
+
return this._core.getState();
|
1593
|
+
}
|
1594
|
+
subscribe(callback) {
|
1595
|
+
return this._core.subscribe(callback);
|
1596
|
+
}
|
1670
1597
|
};
|
1671
|
-
var
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
const messageStore = useMessageStore();
|
1681
|
-
const threadRuntime = useThreadRuntime();
|
1682
|
-
const { part, status } = useContentPart();
|
1683
|
-
const type = part.type;
|
1684
|
-
switch (type) {
|
1685
|
-
case "text":
|
1686
|
-
if (status.type === "requires-action")
|
1687
|
-
throw new Error("Encountered unexpected requires-action status");
|
1688
|
-
if (part === EMPTY_CONTENT && !!Empty) {
|
1689
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Empty, { status });
|
1690
|
-
}
|
1691
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Text2, { part, status });
|
1692
|
-
case "image":
|
1693
|
-
if (status.type === "requires-action")
|
1694
|
-
throw new Error("Encountered unexpected requires-action status");
|
1695
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Image2, { part, status });
|
1696
|
-
case "ui":
|
1697
|
-
if (status.type === "requires-action")
|
1698
|
-
throw new Error("Encountered unexpected requires-action status");
|
1699
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UI, { part, status });
|
1700
|
-
case "tool-call": {
|
1701
|
-
const Tool = by_name[part.toolName] || Fallback2;
|
1702
|
-
const addResult = (result) => threadRuntime.addToolResult({
|
1703
|
-
messageId: messageStore.getState().id,
|
1704
|
-
toolName: part.toolName,
|
1705
|
-
toolCallId: part.toolCallId,
|
1706
|
-
result
|
1707
|
-
});
|
1708
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
1709
|
-
ToolUIDisplay,
|
1710
|
-
{
|
1711
|
-
UI: Tool,
|
1712
|
-
part,
|
1713
|
-
status,
|
1714
|
-
addResult
|
1715
|
-
}
|
1716
|
-
);
|
1717
|
-
}
|
1718
|
-
default:
|
1719
|
-
const unhandledType = type;
|
1720
|
-
throw new Error(`Unknown content part type: ${unhandledType}`);
|
1598
|
+
var ComposerAttachmentRuntime = class extends AttachmentRuntime {
|
1599
|
+
constructor(core, _composerApi) {
|
1600
|
+
super(core);
|
1601
|
+
this._composerApi = _composerApi;
|
1602
|
+
}
|
1603
|
+
remove() {
|
1604
|
+
const core = this._composerApi.getState();
|
1605
|
+
if (!core) throw new Error("Composer is not available");
|
1606
|
+
return core.removeAttachment(this.getState().id);
|
1721
1607
|
}
|
1722
1608
|
};
|
1723
|
-
var
|
1724
|
-
|
1725
|
-
|
1726
|
-
}
|
1727
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartProvider, { partIndex, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageContentPartComponent, { components }) });
|
1609
|
+
var ThreadComposerAttachmentRuntime = class extends ComposerAttachmentRuntime {
|
1610
|
+
get source() {
|
1611
|
+
return "thread-composer";
|
1612
|
+
}
|
1728
1613
|
};
|
1729
|
-
var
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
var MessagePrimitiveContent = ({
|
1734
|
-
components
|
1735
|
-
}) => {
|
1736
|
-
const contentLength = useMessage((s) => s.content.length) || 1;
|
1737
|
-
return Array.from({ length: contentLength }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageContentPart, { partIndex: index, components }, index));
|
1614
|
+
var EditComposerAttachmentRuntime = class extends ComposerAttachmentRuntime {
|
1615
|
+
get source() {
|
1616
|
+
return "edit-composer";
|
1617
|
+
}
|
1738
1618
|
};
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1619
|
+
var MessageAttachmentRuntime = class extends AttachmentRuntime {
|
1620
|
+
get source() {
|
1621
|
+
return "message";
|
1622
|
+
}
|
1623
|
+
constructor(core) {
|
1624
|
+
super(core);
|
1625
|
+
}
|
1626
|
+
remove() {
|
1627
|
+
throw new Error("Message attachments cannot be removed");
|
1628
|
+
}
|
1744
1629
|
};
|
1745
|
-
MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
|
1746
|
-
|
1747
|
-
// src/primitives/message/MessageAttachments.tsx
|
1748
1630
|
|
1631
|
+
// src/api/subscribable/BaseSubject.ts
|
1632
|
+
var BaseSubject = (_class2 = class {constructor() { _class2.prototype.__init5.call(this); }
|
1633
|
+
__init5() {this._subscriptions = /* @__PURE__ */ new Set()}
|
1634
|
+
|
1635
|
+
get isConnected() {
|
1636
|
+
return !!this._connection;
|
1637
|
+
}
|
1638
|
+
notifySubscribers() {
|
1639
|
+
for (const callback of this._subscriptions) callback();
|
1640
|
+
}
|
1641
|
+
_updateConnection() {
|
1642
|
+
if (this._subscriptions.size > 0) {
|
1643
|
+
if (this._connection) return;
|
1644
|
+
this._connection = this._connect();
|
1645
|
+
} else {
|
1646
|
+
_optionalChain([this, 'access', _16 => _16._connection, 'optionalCall', _17 => _17()]);
|
1647
|
+
this._connection = void 0;
|
1648
|
+
}
|
1649
|
+
}
|
1650
|
+
subscribe(callback) {
|
1651
|
+
this._subscriptions.add(callback);
|
1652
|
+
this._updateConnection();
|
1653
|
+
return () => {
|
1654
|
+
this._subscriptions.delete(callback);
|
1655
|
+
this._updateConnection();
|
1656
|
+
};
|
1657
|
+
}
|
1658
|
+
}, _class2);
|
1749
1659
|
|
1750
|
-
// src/
|
1660
|
+
// src/api/subscribable/SKIP_UPDATE.ts
|
1661
|
+
var SKIP_UPDATE = Symbol("skip-update");
|
1751
1662
|
|
1752
|
-
|
1753
|
-
|
1754
|
-
)
|
1663
|
+
// src/api/subscribable/LazyMemoizeSubject.ts
|
1664
|
+
var LazyMemoizeSubject = (_class3 = class extends BaseSubject {
|
1665
|
+
constructor(binding) {
|
1666
|
+
super();_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);;
|
1667
|
+
this.binding = binding;
|
1668
|
+
}
|
1669
|
+
__init6() {this._previousStateDirty = true}
|
1670
|
+
|
1671
|
+
__init7() {this.getState = () => {
|
1672
|
+
if (!this.isConnected || this._previousStateDirty) {
|
1673
|
+
const newState = this.binding.getState();
|
1674
|
+
if (newState !== SKIP_UPDATE) {
|
1675
|
+
this._previousState = newState;
|
1676
|
+
}
|
1677
|
+
this._previousStateDirty = false;
|
1678
|
+
}
|
1679
|
+
if (this._previousState === void 0)
|
1680
|
+
throw new Error("Entry not available in the store");
|
1681
|
+
return this._previousState;
|
1682
|
+
}}
|
1683
|
+
_connect() {
|
1684
|
+
const callback = () => {
|
1685
|
+
this._previousStateDirty = true;
|
1686
|
+
this.notifySubscribers();
|
1687
|
+
};
|
1688
|
+
return this.binding.subscribe(callback);
|
1689
|
+
}
|
1690
|
+
}, _class3);
|
1691
|
+
|
1692
|
+
// src/api/subscribable/shallowEqual.ts
|
1693
|
+
function shallowEqual(objA, objB) {
|
1694
|
+
if (objA === void 0 && objB === void 0) return true;
|
1695
|
+
if (objA === void 0) return false;
|
1696
|
+
if (objB === void 0) return false;
|
1697
|
+
for (const key of Object.keys(objA)) {
|
1698
|
+
const valueA = objA[key];
|
1699
|
+
const valueB = objB[key];
|
1700
|
+
if (!Object.is(valueA, valueB)) return false;
|
1701
|
+
}
|
1702
|
+
return true;
|
1703
|
+
}
|
1704
|
+
|
1705
|
+
// src/api/subscribable/ShallowMemoizeSubject.ts
|
1706
|
+
var ShallowMemoizeSubject = (_class4 = class extends BaseSubject {
|
1707
|
+
constructor(binding) {
|
1708
|
+
super();_class4.prototype.__init8.call(this);;
|
1709
|
+
this.binding = binding;
|
1710
|
+
const state = binding.getState();
|
1711
|
+
if (state === SKIP_UPDATE)
|
1712
|
+
throw new Error("Entry not available in the store");
|
1713
|
+
this._previousState = state;
|
1714
|
+
}
|
1715
|
+
|
1716
|
+
__init8() {this.getState = () => {
|
1717
|
+
if (!this.isConnected) this._syncState();
|
1718
|
+
return this._previousState;
|
1719
|
+
}}
|
1720
|
+
_syncState() {
|
1721
|
+
const state = this.binding.getState();
|
1722
|
+
if (state === SKIP_UPDATE) return false;
|
1723
|
+
if (shallowEqual(state, this._previousState)) return false;
|
1724
|
+
this._previousState = state;
|
1725
|
+
return true;
|
1726
|
+
}
|
1727
|
+
_connect() {
|
1728
|
+
const callback = () => {
|
1729
|
+
if (this._syncState()) {
|
1730
|
+
this.notifySubscribers();
|
1731
|
+
}
|
1732
|
+
};
|
1733
|
+
return this.binding.subscribe(callback);
|
1734
|
+
}
|
1735
|
+
}, _class4);
|
1736
|
+
|
1737
|
+
// src/api/ComposerRuntime.ts
|
1738
|
+
var METHOD_NOT_SUPPORTED = () => {
|
1739
|
+
throw new Error("Composer is not available");
|
1740
|
+
};
|
1741
|
+
var EMPTY_ARRAY = Object.freeze([]);
|
1742
|
+
var getThreadComposerState = (runtime, focus, onFocus) => {
|
1743
|
+
return Object.freeze({
|
1744
|
+
type: "thread",
|
1745
|
+
isEditing: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _18 => _18.isEditing]), () => ( false)),
|
1746
|
+
canCancel: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _19 => _19.canCancel]), () => ( false)),
|
1747
|
+
isEmpty: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _20 => _20.isEmpty]), () => ( true)),
|
1748
|
+
text: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _21 => _21.text]), () => ( "")),
|
1749
|
+
attachments: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _22 => _22.attachments]), () => ( EMPTY_ARRAY)),
|
1750
|
+
attachmentAccept: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _23 => _23.attachmentAccept]), () => ( "*")),
|
1751
|
+
value: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _24 => _24.text]), () => ( "")),
|
1752
|
+
setValue: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _25 => _25.setText, 'access', _26 => _26.bind, 'call', _27 => _27(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
|
1753
|
+
setText: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _28 => _28.setText, 'access', _29 => _29.bind, 'call', _30 => _30(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
|
1754
|
+
// edit: beginEdit,
|
1755
|
+
send: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _31 => _31.send, 'access', _32 => _32.bind, 'call', _33 => _33(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
|
1756
|
+
cancel: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _34 => _34.cancel, 'access', _35 => _35.bind, 'call', _36 => _36(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
|
1757
|
+
focus,
|
1758
|
+
onFocus,
|
1759
|
+
reset: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _37 => _37.reset, 'access', _38 => _38.bind, 'call', _39 => _39(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
|
1760
|
+
addAttachment: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _40 => _40.addAttachment, 'access', _41 => _41.bind, 'call', _42 => _42(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
|
1761
|
+
removeAttachment: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _43 => _43.removeAttachment, 'access', _44 => _44.bind, 'call', _45 => _45(runtime)]), () => ( METHOD_NOT_SUPPORTED))
|
1762
|
+
});
|
1763
|
+
};
|
1764
|
+
var getEditComposerState = (runtime, beginEdit) => {
|
1765
|
+
return Object.freeze({
|
1766
|
+
type: "edit",
|
1767
|
+
isEditing: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _46 => _46.isEditing]), () => ( false)),
|
1768
|
+
canCancel: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _47 => _47.canCancel]), () => ( false)),
|
1769
|
+
isEmpty: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _48 => _48.isEmpty]), () => ( true)),
|
1770
|
+
text: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _49 => _49.text]), () => ( "")),
|
1771
|
+
attachments: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _50 => _50.attachments]), () => ( EMPTY_ARRAY)),
|
1772
|
+
attachmentAccept: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _51 => _51.attachmentAccept]), () => ( "*")),
|
1773
|
+
value: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _52 => _52.text]), () => ( "")),
|
1774
|
+
setValue: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _53 => _53.setText, 'access', _54 => _54.bind, 'call', _55 => _55(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
|
1775
|
+
setText: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _56 => _56.setText, 'access', _57 => _57.bind, 'call', _58 => _58(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
|
1776
|
+
edit: beginEdit,
|
1777
|
+
send: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _59 => _59.send, 'access', _60 => _60.bind, 'call', _61 => _61(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
|
1778
|
+
cancel: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _62 => _62.cancel, 'access', _63 => _63.bind, 'call', _64 => _64(runtime)]), () => ( METHOD_NOT_SUPPORTED))
|
1779
|
+
});
|
1780
|
+
};
|
1781
|
+
var ComposerRuntime = class {
|
1782
|
+
constructor(_core) {
|
1783
|
+
this._core = _core;
|
1784
|
+
}
|
1785
|
+
/**
|
1786
|
+
* @deprecated Use `getState().isEditing` instead. This will be removed in 0.6.0.
|
1787
|
+
*/
|
1788
|
+
get isEditing() {
|
1789
|
+
return this.getState().isEditing;
|
1790
|
+
}
|
1791
|
+
/**
|
1792
|
+
* @deprecated Use `getState().isEmpty` instead. This will be removed in 0.6.0.
|
1793
|
+
*/
|
1794
|
+
get isEmpty() {
|
1795
|
+
return this.getState().isEmpty;
|
1796
|
+
}
|
1797
|
+
/**
|
1798
|
+
* @deprecated Use `getState().canCancel` instead. This will be removed in 0.6.0.
|
1799
|
+
*/
|
1800
|
+
get canCancel() {
|
1801
|
+
return this.getState().canCancel;
|
1802
|
+
}
|
1803
|
+
/**
|
1804
|
+
* @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
|
1805
|
+
*/
|
1806
|
+
get text() {
|
1807
|
+
return this.getState().text;
|
1808
|
+
}
|
1809
|
+
/**
|
1810
|
+
* @deprecated Use `getState().attachmentAccept` instead. This will be removed in 0.6.0.
|
1811
|
+
*/
|
1812
|
+
get attachmentAccept() {
|
1813
|
+
return this.getState().attachmentAccept;
|
1814
|
+
}
|
1815
|
+
/**
|
1816
|
+
* @deprecated Use `getState().attachments` instead. This will be removed in 0.6.0.
|
1817
|
+
*/
|
1818
|
+
get attachments() {
|
1819
|
+
return this.getState().attachments;
|
1820
|
+
}
|
1821
|
+
/**
|
1822
|
+
* @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
|
1823
|
+
*/
|
1824
|
+
get value() {
|
1825
|
+
return this.text;
|
1826
|
+
}
|
1827
|
+
setText(text) {
|
1828
|
+
const core = this._core.getState();
|
1829
|
+
if (!core) throw new Error("Composer is not available");
|
1830
|
+
core.setText(text);
|
1831
|
+
}
|
1832
|
+
setValue(text) {
|
1833
|
+
this.setText(text);
|
1834
|
+
}
|
1835
|
+
addAttachment(file) {
|
1836
|
+
const core = this._core.getState();
|
1837
|
+
if (!core) throw new Error("Composer is not available");
|
1838
|
+
return core.addAttachment(file);
|
1839
|
+
}
|
1840
|
+
// /**
|
1841
|
+
// * @deprecated Use `getAttachmentById(id).removeAttachment` instead. This will be removed in 0.6.0.
|
1842
|
+
// */
|
1843
|
+
removeAttachment(attachmentId) {
|
1844
|
+
const core = this._core.getState();
|
1845
|
+
if (!core) throw new Error("Composer is not available");
|
1846
|
+
return core.removeAttachment(attachmentId);
|
1847
|
+
}
|
1848
|
+
/**
|
1849
|
+
* @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.
|
1850
|
+
*/
|
1851
|
+
reset() {
|
1852
|
+
const core = this._core.getState();
|
1853
|
+
if (!core) throw new Error("Composer is not available");
|
1854
|
+
core.reset();
|
1855
|
+
}
|
1856
|
+
send() {
|
1857
|
+
const core = this._core.getState();
|
1858
|
+
if (!core) throw new Error("Composer is not available");
|
1859
|
+
core.send();
|
1860
|
+
}
|
1861
|
+
cancel() {
|
1862
|
+
const core = this._core.getState();
|
1863
|
+
if (!core) throw new Error("Composer is not available");
|
1864
|
+
core.cancel();
|
1865
|
+
}
|
1866
|
+
subscribe(callback) {
|
1867
|
+
return this._core.subscribe(callback);
|
1868
|
+
}
|
1869
|
+
};
|
1870
|
+
var ThreadComposerRuntime = (_class5 = class extends ComposerRuntime {
|
1871
|
+
get type() {
|
1872
|
+
return "thread";
|
1873
|
+
}
|
1874
|
+
|
1875
|
+
constructor(core) {
|
1876
|
+
const stateBinding = new LazyMemoizeSubject({
|
1877
|
+
getState: () => getThreadComposerState(
|
1878
|
+
core.getState(),
|
1879
|
+
this.focus.bind(this),
|
1880
|
+
this.onFocus.bind(this)
|
1881
|
+
),
|
1882
|
+
subscribe: (callback) => core.subscribe(callback)
|
1883
|
+
});
|
1884
|
+
super({
|
1885
|
+
getState: () => core.getState(),
|
1886
|
+
subscribe: (callback) => stateBinding.subscribe(callback)
|
1887
|
+
});_class5.prototype.__init9.call(this);;
|
1888
|
+
this._getState = stateBinding.getState.bind(stateBinding);
|
1889
|
+
}
|
1890
|
+
get attachments() {
|
1891
|
+
return _nullishCoalesce(_optionalChain([this, 'access', _65 => _65.getState, 'call', _66 => _66(), 'optionalAccess', _67 => _67.attachments]), () => ( EMPTY_ARRAY));
|
1892
|
+
}
|
1893
|
+
getState() {
|
1894
|
+
return this._getState();
|
1895
|
+
}
|
1896
|
+
// TODO replace with events
|
1897
|
+
__init9() {this._focusListeners = /* @__PURE__ */ new Set()}
|
1898
|
+
focus() {
|
1899
|
+
this._focusListeners.forEach((callback) => callback());
|
1900
|
+
}
|
1901
|
+
onFocus(callback) {
|
1902
|
+
this._focusListeners.add(callback);
|
1903
|
+
return () => this._focusListeners.delete(callback);
|
1904
|
+
}
|
1905
|
+
unstable_getAttachmentByIndex(idx) {
|
1906
|
+
return new ThreadComposerAttachmentRuntime(
|
1907
|
+
new ShallowMemoizeSubject({
|
1908
|
+
getState: () => {
|
1909
|
+
const attachments = this.getState().attachments;
|
1910
|
+
const attachment = attachments[idx];
|
1911
|
+
if (!attachment) return SKIP_UPDATE;
|
1912
|
+
return {
|
1913
|
+
...attachment,
|
1914
|
+
attachment,
|
1915
|
+
source: "thread-composer"
|
1916
|
+
};
|
1917
|
+
},
|
1918
|
+
subscribe: (callback) => this._core.subscribe(callback)
|
1919
|
+
}),
|
1920
|
+
this._core
|
1921
|
+
);
|
1922
|
+
}
|
1923
|
+
}, _class5);
|
1924
|
+
var EditComposerRuntime = class extends ComposerRuntime {
|
1925
|
+
constructor(core, _beginEdit) {
|
1926
|
+
const stateBinding = new LazyMemoizeSubject({
|
1927
|
+
getState: () => getEditComposerState(core.getState(), this._beginEdit),
|
1928
|
+
subscribe: (callback) => core.subscribe(callback)
|
1929
|
+
});
|
1930
|
+
super({
|
1931
|
+
getState: () => core.getState(),
|
1932
|
+
subscribe: (callback) => stateBinding.subscribe(callback)
|
1933
|
+
});
|
1934
|
+
this._beginEdit = _beginEdit;
|
1935
|
+
this._getState = stateBinding.getState.bind(stateBinding);
|
1936
|
+
}
|
1937
|
+
get type() {
|
1938
|
+
return "edit";
|
1939
|
+
}
|
1940
|
+
|
1941
|
+
getState() {
|
1942
|
+
return this._getState();
|
1943
|
+
}
|
1944
|
+
beginEdit() {
|
1945
|
+
this._beginEdit();
|
1946
|
+
}
|
1947
|
+
/**
|
1948
|
+
* @deprecated Use `beginEdit()` instead. This will be removed in 0.6.0.
|
1949
|
+
*/
|
1950
|
+
edit() {
|
1951
|
+
this.beginEdit();
|
1952
|
+
}
|
1953
|
+
unstable_getAttachmentByIndex(idx) {
|
1954
|
+
return new EditComposerAttachmentRuntime(
|
1955
|
+
new ShallowMemoizeSubject({
|
1956
|
+
getState: () => {
|
1957
|
+
const attachments = this.getState().attachments;
|
1958
|
+
const attachment = attachments[idx];
|
1959
|
+
if (!attachment) return SKIP_UPDATE;
|
1960
|
+
return {
|
1961
|
+
...attachment,
|
1962
|
+
attachment,
|
1963
|
+
source: "edit-composer"
|
1964
|
+
};
|
1965
|
+
},
|
1966
|
+
subscribe: (callback) => this._core.subscribe(callback)
|
1967
|
+
}),
|
1968
|
+
this._core
|
1969
|
+
);
|
1970
|
+
}
|
1971
|
+
};
|
1972
|
+
|
1973
|
+
// src/api/subscribable/NestedSubscriptionSubject.ts
|
1974
|
+
var NestedSubscriptionSubject = class extends BaseSubject {
|
1975
|
+
constructor(binding) {
|
1976
|
+
super();
|
1977
|
+
this.binding = binding;
|
1978
|
+
}
|
1979
|
+
getState() {
|
1980
|
+
return this.binding.getState();
|
1981
|
+
}
|
1982
|
+
_connect() {
|
1983
|
+
const callback = () => {
|
1984
|
+
this.notifySubscribers();
|
1985
|
+
};
|
1986
|
+
let lastState = this.binding.getState();
|
1987
|
+
let innerUnsubscribe = _optionalChain([lastState, 'optionalAccess', _68 => _68.subscribe, 'call', _69 => _69(callback)]);
|
1988
|
+
const onRuntimeUpdate = () => {
|
1989
|
+
const newState = this.binding.getState();
|
1990
|
+
if (newState === lastState) return;
|
1991
|
+
lastState = newState;
|
1992
|
+
_optionalChain([innerUnsubscribe, 'optionalCall', _70 => _70()]);
|
1993
|
+
innerUnsubscribe = _optionalChain([this, 'access', _71 => _71.binding, 'access', _72 => _72.getState, 'call', _73 => _73(), 'optionalAccess', _74 => _74.subscribe, 'call', _75 => _75(callback)]);
|
1994
|
+
callback();
|
1995
|
+
};
|
1996
|
+
const outerUnsubscribe = this.binding.subscribe(onRuntimeUpdate);
|
1997
|
+
return () => {
|
1998
|
+
_optionalChain([outerUnsubscribe, 'optionalCall', _76 => _76()]);
|
1999
|
+
_optionalChain([innerUnsubscribe, 'optionalCall', _77 => _77()]);
|
2000
|
+
};
|
2001
|
+
}
|
2002
|
+
};
|
2003
|
+
|
2004
|
+
// src/api/MessageRuntime.ts
|
2005
|
+
var COMPLETE_STATUS2 = {
|
2006
|
+
type: "complete"
|
2007
|
+
};
|
2008
|
+
var toContentPartStatus = (message, partIndex, part) => {
|
2009
|
+
if (message.role !== "assistant") return COMPLETE_STATUS2;
|
2010
|
+
const isLastPart = partIndex === Math.max(0, message.content.length - 1);
|
2011
|
+
if (part.type !== "tool-call") {
|
2012
|
+
if ("reason" in message.status && message.status.reason === "tool-calls" && isLastPart)
|
2013
|
+
throw new Error(
|
2014
|
+
"Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui."
|
2015
|
+
);
|
2016
|
+
return isLastPart ? message.status : COMPLETE_STATUS2;
|
2017
|
+
}
|
2018
|
+
if (!!part.result) {
|
2019
|
+
return COMPLETE_STATUS2;
|
2020
|
+
}
|
2021
|
+
return message.status;
|
2022
|
+
};
|
2023
|
+
var EMPTY_CONTENT = Object.freeze({ type: "text", text: "" });
|
2024
|
+
var getContentPartState = (message, partIndex) => {
|
2025
|
+
let part = message.content[partIndex];
|
2026
|
+
if (!part) {
|
2027
|
+
if (message.content.length === 0 && partIndex === 0) {
|
2028
|
+
part = EMPTY_CONTENT;
|
2029
|
+
} else {
|
2030
|
+
return SKIP_UPDATE;
|
2031
|
+
}
|
2032
|
+
} else if (message.content.length === 1 && part.type === "text" && part.text.length === 0) {
|
2033
|
+
part = EMPTY_CONTENT;
|
2034
|
+
}
|
2035
|
+
const status = toContentPartStatus(message, partIndex, part);
|
2036
|
+
return Object.freeze({ ...part, part, status });
|
2037
|
+
};
|
2038
|
+
var MessageRuntime = (_class6 = class {
|
2039
|
+
constructor(_core, _threadBinding) {;_class6.prototype.__init10.call(this);
|
2040
|
+
this._core = _core;
|
2041
|
+
this._threadBinding = _threadBinding;
|
2042
|
+
}
|
2043
|
+
__init10() {this.composer = new EditComposerRuntime(
|
2044
|
+
new NestedSubscriptionSubject({
|
2045
|
+
getState: () => this._threadBinding.getState().getEditComposer(this._core.getState().id),
|
2046
|
+
subscribe: (callback) => this._threadBinding.subscribe(callback)
|
2047
|
+
}),
|
2048
|
+
() => this._threadBinding.getState().beginEdit(this._core.getState().id)
|
2049
|
+
)}
|
2050
|
+
getState() {
|
2051
|
+
return this._core.getState();
|
2052
|
+
}
|
2053
|
+
// TODO improve type
|
2054
|
+
unstable_edit(message) {
|
2055
|
+
const state = this._core.getState();
|
2056
|
+
if (!state) throw new Error("Message is not available");
|
2057
|
+
this._threadBinding.getState().append({
|
2058
|
+
...message,
|
2059
|
+
parentId: state.parentId
|
2060
|
+
});
|
2061
|
+
}
|
2062
|
+
reload() {
|
2063
|
+
const state = this._core.getState();
|
2064
|
+
if (!state) throw new Error("Message is not available");
|
2065
|
+
if (state.role !== "assistant")
|
2066
|
+
throw new Error("Can only reload assistant messages");
|
2067
|
+
this._threadBinding.getState().startRun(state.parentId);
|
2068
|
+
}
|
2069
|
+
speak() {
|
2070
|
+
const state = this._core.getState();
|
2071
|
+
if (!state) throw new Error("Message is not available");
|
2072
|
+
return this._threadBinding.getState().speak(state.id);
|
2073
|
+
}
|
2074
|
+
submitFeedback({ type }) {
|
2075
|
+
const state = this._core.getState();
|
2076
|
+
if (!state) throw new Error("Message is not available");
|
2077
|
+
this._threadBinding.getState().submitFeedback({
|
2078
|
+
messageId: state.id,
|
2079
|
+
type
|
2080
|
+
});
|
2081
|
+
}
|
2082
|
+
switchToBranch({
|
2083
|
+
position,
|
2084
|
+
branchId
|
2085
|
+
}) {
|
2086
|
+
const state = this._core.getState();
|
2087
|
+
if (!state) throw new Error("Message is not available");
|
2088
|
+
if (branchId && position) {
|
2089
|
+
throw new Error("May not specify both branchId and position");
|
2090
|
+
} else if (!branchId && !position) {
|
2091
|
+
throw new Error("Must specify either branchId or position");
|
2092
|
+
}
|
2093
|
+
const thread = this._threadBinding.getState();
|
2094
|
+
const branches = thread.getBranches(state.id);
|
2095
|
+
let targetBranch = branchId;
|
2096
|
+
if (position === "previous") {
|
2097
|
+
targetBranch = branches[state.branchNumber - 2];
|
2098
|
+
} else if (position === "next") {
|
2099
|
+
targetBranch = branches[state.branchNumber];
|
2100
|
+
}
|
2101
|
+
if (!targetBranch) throw new Error("Branch not found");
|
2102
|
+
this._threadBinding.getState().switchToBranch(targetBranch);
|
2103
|
+
}
|
2104
|
+
subscribe(callback) {
|
2105
|
+
return this._core.subscribe(callback);
|
2106
|
+
}
|
2107
|
+
unstable_getContentPartByIndex(idx) {
|
2108
|
+
if (idx < 0) throw new Error("Message index must be >= 0");
|
2109
|
+
return new ContentPartRuntime(
|
2110
|
+
new ShallowMemoizeSubject({
|
2111
|
+
getState: () => {
|
2112
|
+
return getContentPartState(this.getState(), idx);
|
2113
|
+
},
|
2114
|
+
subscribe: (callback) => this._core.subscribe(callback)
|
2115
|
+
}),
|
2116
|
+
this._core,
|
2117
|
+
this._threadBinding
|
2118
|
+
);
|
2119
|
+
}
|
2120
|
+
unstable_getAttachmentByIndex(idx) {
|
2121
|
+
return new MessageAttachmentRuntime(
|
2122
|
+
new ShallowMemoizeSubject({
|
2123
|
+
getState: () => {
|
2124
|
+
const attachments = this.getState().attachments;
|
2125
|
+
const attachment = _optionalChain([attachments, 'optionalAccess', _78 => _78[idx]]);
|
2126
|
+
if (!attachment) return SKIP_UPDATE;
|
2127
|
+
return {
|
2128
|
+
...attachment,
|
2129
|
+
attachment,
|
2130
|
+
source: "message"
|
2131
|
+
};
|
2132
|
+
},
|
2133
|
+
subscribe: (callback) => this._core.subscribe(callback)
|
2134
|
+
})
|
2135
|
+
);
|
2136
|
+
}
|
2137
|
+
}, _class6);
|
2138
|
+
|
2139
|
+
// src/primitives/message/MessageContent.tsx
|
2140
|
+
|
2141
|
+
var ToolUIDisplay = ({
|
2142
|
+
UI,
|
2143
|
+
...props
|
2144
|
+
}) => {
|
2145
|
+
const Render = _nullishCoalesce(useToolUIs((s) => s.getToolUI(props.toolName)), () => ( UI));
|
2146
|
+
if (!Render) return null;
|
2147
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Render, { ...props });
|
2148
|
+
};
|
2149
|
+
var defaultComponents = {
|
2150
|
+
Text: () => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "p", { style: { whiteSpace: "pre-line" }, children: [
|
2151
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartPrimitiveText, {}),
|
2152
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartPrimitiveInProgress, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { style: { fontFamily: "revert" }, children: " \u25CF" }) })
|
2153
|
+
] }),
|
2154
|
+
Image: () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartPrimitiveImage, {}),
|
2155
|
+
UI: () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartPrimitiveDisplay, {})
|
2156
|
+
};
|
2157
|
+
var MessageContentPartComponent = ({
|
2158
|
+
components: {
|
2159
|
+
Text: Text2 = defaultComponents.Text,
|
2160
|
+
Empty,
|
2161
|
+
Image: Image2 = defaultComponents.Image,
|
2162
|
+
UI = defaultComponents.UI,
|
2163
|
+
tools: { by_name = {}, Fallback: Fallback2 = void 0 } = {}
|
2164
|
+
} = {}
|
2165
|
+
}) => {
|
2166
|
+
const messageStore = useMessageStore();
|
2167
|
+
const threadRuntime = useThreadRuntime();
|
2168
|
+
const part = useContentPart();
|
2169
|
+
const type = part.type;
|
2170
|
+
switch (type) {
|
2171
|
+
case "text":
|
2172
|
+
if (part.status.type === "requires-action")
|
2173
|
+
throw new Error("Encountered unexpected requires-action status");
|
2174
|
+
if (part.part === EMPTY_CONTENT && !!Empty) {
|
2175
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Empty, { status: part.status });
|
2176
|
+
}
|
2177
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Text2, { ...part, part });
|
2178
|
+
case "image":
|
2179
|
+
if (part.status.type === "requires-action")
|
2180
|
+
throw new Error("Encountered unexpected requires-action status");
|
2181
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Image2, { ...part, part });
|
2182
|
+
case "ui":
|
2183
|
+
if (part.status.type === "requires-action")
|
2184
|
+
throw new Error("Encountered unexpected requires-action status");
|
2185
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UI, { ...part, part });
|
2186
|
+
case "tool-call": {
|
2187
|
+
const Tool = by_name[part.toolName] || Fallback2;
|
2188
|
+
const addResult = (result) => threadRuntime.addToolResult({
|
2189
|
+
messageId: messageStore.getState().id,
|
2190
|
+
toolName: part.toolName,
|
2191
|
+
toolCallId: part.toolCallId,
|
2192
|
+
result
|
2193
|
+
});
|
2194
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ToolUIDisplay, { ...part, part, UI: Tool, addResult });
|
2195
|
+
}
|
2196
|
+
default:
|
2197
|
+
const unhandledType = type;
|
2198
|
+
throw new Error(`Unknown content part type: ${unhandledType}`);
|
2199
|
+
}
|
2200
|
+
};
|
2201
|
+
var MessageContentPartImpl = ({
|
2202
|
+
partIndex,
|
2203
|
+
components
|
2204
|
+
}) => {
|
2205
|
+
const messageRuntime = useMessageRuntime();
|
2206
|
+
const runtime = _react.useMemo.call(void 0,
|
2207
|
+
() => messageRuntime.unstable_getContentPartByIndex(partIndex),
|
2208
|
+
[messageRuntime, partIndex]
|
2209
|
+
);
|
2210
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartRuntimeProvider, { runtime, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageContentPartComponent, { components }) });
|
2211
|
+
};
|
2212
|
+
var MessageContentPart = _react.memo.call(void 0,
|
2213
|
+
MessageContentPartImpl,
|
2214
|
+
(prev, next) => prev.partIndex === next.partIndex && _optionalChain([prev, 'access', _79 => _79.components, 'optionalAccess', _80 => _80.Text]) === _optionalChain([next, 'access', _81 => _81.components, 'optionalAccess', _82 => _82.Text]) && _optionalChain([prev, 'access', _83 => _83.components, 'optionalAccess', _84 => _84.Image]) === _optionalChain([next, 'access', _85 => _85.components, 'optionalAccess', _86 => _86.Image]) && _optionalChain([prev, 'access', _87 => _87.components, 'optionalAccess', _88 => _88.UI]) === _optionalChain([next, 'access', _89 => _89.components, 'optionalAccess', _90 => _90.UI]) && _optionalChain([prev, 'access', _91 => _91.components, 'optionalAccess', _92 => _92.tools]) === _optionalChain([next, 'access', _93 => _93.components, 'optionalAccess', _94 => _94.tools])
|
2215
|
+
);
|
2216
|
+
var MessagePrimitiveContent = ({
|
2217
|
+
components
|
2218
|
+
}) => {
|
2219
|
+
const contentLength = useMessage((s) => s.content.length) || 1;
|
2220
|
+
return Array.from({ length: contentLength }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageContentPart, { partIndex: index, components }, index));
|
2221
|
+
};
|
2222
|
+
MessagePrimitiveContent.displayName = "MessagePrimitive.Content";
|
2223
|
+
|
2224
|
+
// src/primitives/message/MessageInProgress.tsx
|
2225
|
+
var MessagePrimitiveInProgress = () => {
|
2226
|
+
return null;
|
2227
|
+
};
|
2228
|
+
MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
|
2229
|
+
|
2230
|
+
// src/primitives/message/MessageAttachments.tsx
|
2231
|
+
|
2232
|
+
|
2233
|
+
// src/context/react/AttachmentContext.ts
|
2234
|
+
|
2235
|
+
var AttachmentContext = _react.createContext.call(void 0,
|
2236
|
+
null
|
2237
|
+
);
|
1755
2238
|
function useAttachmentContext(options) {
|
1756
2239
|
const context = _react.useContext.call(void 0, AttachmentContext);
|
1757
|
-
if (!_optionalChain([options, 'optionalAccess',
|
2240
|
+
if (!_optionalChain([options, 'optionalAccess', _95 => _95.optional]) && !context)
|
1758
2241
|
throw new Error(
|
1759
2242
|
"This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
|
1760
2243
|
);
|
1761
2244
|
return context;
|
1762
2245
|
}
|
1763
|
-
function
|
2246
|
+
function useThreadComposerAttachmentContext(options) {
|
2247
|
+
const context = useAttachmentContext(options);
|
2248
|
+
if (!context) return null;
|
2249
|
+
if (context.source !== "thread-composer")
|
2250
|
+
throw new Error(
|
2251
|
+
"This component must be used within a thread's ComposerPrimitive.Attachments component."
|
2252
|
+
);
|
2253
|
+
return context;
|
2254
|
+
}
|
2255
|
+
function useEditComposerAttachmentContext(options) {
|
1764
2256
|
const context = useAttachmentContext(options);
|
1765
2257
|
if (!context) return null;
|
1766
|
-
if (context.
|
2258
|
+
if (context.source !== "edit-composer")
|
1767
2259
|
throw new Error(
|
1768
|
-
"This component must be used within a ComposerPrimitive.Attachments component."
|
2260
|
+
"This component must be used within a messages's ComposerPrimitive.Attachments component."
|
1769
2261
|
);
|
1770
2262
|
return context;
|
1771
2263
|
}
|
1772
2264
|
function useMessageAttachmentContext(options) {
|
1773
2265
|
const context = useAttachmentContext(options);
|
1774
2266
|
if (!context) return null;
|
1775
|
-
if (context.
|
2267
|
+
if (context.source !== "message")
|
1776
2268
|
throw new Error(
|
1777
2269
|
"This component must be used within a MessagePrimitive.Attachments component."
|
1778
2270
|
);
|
1779
2271
|
return context;
|
1780
2272
|
}
|
1781
|
-
|
2273
|
+
function useAttachmentRuntime(options) {
|
2274
|
+
const attachmentRuntime = useAttachmentContext(options);
|
2275
|
+
if (!attachmentRuntime) return null;
|
2276
|
+
return attachmentRuntime.useAttachmentRuntime();
|
2277
|
+
}
|
2278
|
+
var { useAttachment } = createContextStoreHook(
|
1782
2279
|
useAttachmentContext,
|
1783
2280
|
"useAttachment"
|
1784
2281
|
);
|
1785
|
-
var {
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
2282
|
+
var { useAttachment: useThreadComposerAttachment } = createContextStoreHook(useThreadComposerAttachmentContext, "useAttachment");
|
2283
|
+
var { useAttachment: useEditComposerAttachment } = createContextStoreHook(useEditComposerAttachmentContext, "useAttachment");
|
2284
|
+
var { useAttachment: useMessageAttachment } = createContextStoreHook(
|
2285
|
+
useMessageAttachmentContext,
|
2286
|
+
"useAttachment"
|
2287
|
+
);
|
2288
|
+
|
2289
|
+
// src/context/providers/AttachmentRuntimeProvider.tsx
|
1793
2290
|
|
1794
|
-
// src/context/providers/MessageAttachmentProvider.tsx
|
1795
2291
|
|
1796
2292
|
|
1797
2293
|
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
2294
|
+
|
2295
|
+
|
2296
|
+
|
2297
|
+
var useAttachmentRuntimeStore = (runtime) => {
|
2298
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime));
|
2299
|
+
_react.useEffect.call(void 0, () => {
|
2300
|
+
writableStore(store).setState(runtime, true);
|
2301
|
+
}, [runtime, store]);
|
2302
|
+
return store;
|
1806
2303
|
};
|
1807
|
-
var
|
1808
|
-
const
|
1809
|
-
const [context] = _react.useState.call(void 0,
|
1810
|
-
() => {
|
1811
|
-
const useAttachment2 = _zustand.create.call(void 0,
|
1812
|
-
() => getAttachment(messageStore.getState(), void 0, partIndex)
|
1813
|
-
);
|
1814
|
-
return { type: "message", useAttachment: useAttachment2 };
|
1815
|
-
}
|
1816
|
-
);
|
2304
|
+
var useAttachmentStore = (runtime) => {
|
2305
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime.getState()));
|
1817
2306
|
_react.useEffect.call(void 0, () => {
|
1818
|
-
const
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
);
|
1824
|
-
if (!newState) return;
|
1825
|
-
writableStore(context.useAttachment).setState(newState, true);
|
1826
|
-
};
|
1827
|
-
syncAttachment(messageStore.getState());
|
1828
|
-
return messageStore.subscribe(syncAttachment);
|
1829
|
-
}, [context, messageStore, partIndex]);
|
1830
|
-
return context;
|
2307
|
+
const updateState = () => writableStore(store).setState(runtime.getState(), true);
|
2308
|
+
updateState();
|
2309
|
+
return runtime.subscribe(updateState);
|
2310
|
+
}, [runtime, store]);
|
2311
|
+
return store;
|
1831
2312
|
};
|
1832
|
-
var
|
1833
|
-
|
2313
|
+
var AttachmentRuntimeProvider = ({
|
2314
|
+
runtime,
|
1834
2315
|
children
|
1835
2316
|
}) => {
|
1836
|
-
const
|
2317
|
+
const useAttachmentRuntime2 = useAttachmentRuntimeStore(runtime);
|
2318
|
+
const useAttachment2 = useAttachmentStore(runtime);
|
2319
|
+
const source = useAttachment2((s) => s.source);
|
2320
|
+
const context = _react.useMemo.call(void 0, () => {
|
2321
|
+
return {
|
2322
|
+
source,
|
2323
|
+
useAttachmentRuntime: useAttachmentRuntime2,
|
2324
|
+
useAttachment: useAttachment2
|
2325
|
+
};
|
2326
|
+
}, [useAttachmentRuntime2, useAttachment2]);
|
1837
2327
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AttachmentContext.Provider, { value: context, children });
|
1838
2328
|
};
|
1839
2329
|
|
@@ -1843,11 +2333,11 @@ var getComponent = (components, attachment) => {
|
|
1843
2333
|
const type = attachment.type;
|
1844
2334
|
switch (type) {
|
1845
2335
|
case "image":
|
1846
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
2336
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _96 => _96.Image]), () => ( _optionalChain([components, 'optionalAccess', _97 => _97.Attachment])));
|
1847
2337
|
case "document":
|
1848
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
2338
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _98 => _98.Document]), () => ( _optionalChain([components, 'optionalAccess', _99 => _99.Attachment])));
|
1849
2339
|
case "file":
|
1850
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
2340
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _100 => _100.File]), () => ( _optionalChain([components, 'optionalAccess', _101 => _101.Attachment])));
|
1851
2341
|
default:
|
1852
2342
|
const _exhaustiveCheck = type;
|
1853
2343
|
throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
|
@@ -1861,11 +2351,16 @@ var AttachmentComponent = ({ components }) => {
|
|
1861
2351
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Component, {});
|
1862
2352
|
};
|
1863
2353
|
var MessageAttachmentImpl = ({ components, attachmentIndex }) => {
|
1864
|
-
|
2354
|
+
const messageRuntime = useMessageRuntime();
|
2355
|
+
const runtime = _react.useMemo.call(void 0,
|
2356
|
+
() => messageRuntime.unstable_getAttachmentByIndex(attachmentIndex),
|
2357
|
+
[messageRuntime, attachmentIndex]
|
2358
|
+
);
|
2359
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AttachmentRuntimeProvider, { runtime, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AttachmentComponent, { components }) });
|
1865
2360
|
};
|
1866
2361
|
var MessageAttachment = _react.memo.call(void 0,
|
1867
2362
|
MessageAttachmentImpl,
|
1868
|
-
(prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access',
|
2363
|
+
(prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _102 => _102.components, 'optionalAccess', _103 => _103.Image]) === _optionalChain([next, 'access', _104 => _104.components, 'optionalAccess', _105 => _105.Image]) && _optionalChain([prev, 'access', _106 => _106.components, 'optionalAccess', _107 => _107.Document]) === _optionalChain([next, 'access', _108 => _108.components, 'optionalAccess', _109 => _109.Document]) && _optionalChain([prev, 'access', _110 => _110.components, 'optionalAccess', _111 => _111.File]) === _optionalChain([next, 'access', _112 => _112.components, 'optionalAccess', _113 => _113.File]) && _optionalChain([prev, 'access', _114 => _114.components, 'optionalAccess', _115 => _115.Attachment]) === _optionalChain([next, 'access', _116 => _116.components, 'optionalAccess', _117 => _117.Attachment])
|
1869
2364
|
);
|
1870
2365
|
var MessagePrimitiveAttachments = ({ components }) => {
|
1871
2366
|
const attachmentsCount = useMessage(({ message }) => {
|
@@ -1976,7 +2471,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
|
|
1976
2471
|
const { isRunning } = threadStore.getState();
|
1977
2472
|
if (!isRunning) {
|
1978
2473
|
e.preventDefault();
|
1979
|
-
_optionalChain([textareaRef, 'access',
|
2474
|
+
_optionalChain([textareaRef, 'access', _118 => _118.current, 'optionalAccess', _119 => _119.closest, 'call', _120 => _120("form"), 'optionalAccess', _121 => _121.requestSubmit, 'call', _122 => _122()]);
|
1980
2475
|
}
|
1981
2476
|
}
|
1982
2477
|
};
|
@@ -2037,79 +2532,41 @@ var ComposerPrimitiveAddAttachment = createActionButton(
|
|
2037
2532
|
// src/primitives/composer/ComposerAttachments.tsx
|
2038
2533
|
|
2039
2534
|
|
2040
|
-
// src/context/providers/ComposerAttachmentProvider.tsx
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
var getAttachment2 = ({ attachments }, useAttachment2, partIndex) => {
|
2045
|
-
const attachment = attachments[partIndex];
|
2046
|
-
if (!attachment) return null;
|
2047
|
-
const currentState = _optionalChain([useAttachment2, 'optionalAccess', _63 => _63.getState, 'call', _64 => _64()]);
|
2048
|
-
if (currentState && currentState.attachment === attachment) return null;
|
2049
|
-
return Object.freeze({ attachment });
|
2050
|
-
};
|
2051
|
-
var useComposerAttachmentContext2 = (partIndex) => {
|
2052
|
-
const threadComposerStore = useThreadComposerStore();
|
2053
|
-
const [context] = _react.useState.call(void 0,
|
2054
|
-
() => {
|
2055
|
-
const useAttachment2 = _zustand.create.call(void 0,
|
2056
|
-
() => getAttachment2(threadComposerStore.getState(), void 0, partIndex)
|
2057
|
-
);
|
2058
|
-
return { type: "composer", useAttachment: useAttachment2 };
|
2059
|
-
}
|
2060
|
-
);
|
2061
|
-
_react.useEffect.call(void 0, () => {
|
2062
|
-
const syncAttachment = (composer) => {
|
2063
|
-
const newState = getAttachment2(
|
2064
|
-
composer,
|
2065
|
-
context.useAttachment,
|
2066
|
-
partIndex
|
2067
|
-
);
|
2068
|
-
if (!newState) return;
|
2069
|
-
writableStore(context.useAttachment).setState(newState, true);
|
2070
|
-
};
|
2071
|
-
syncAttachment(threadComposerStore.getState());
|
2072
|
-
return threadComposerStore.subscribe(syncAttachment);
|
2073
|
-
}, [context, threadComposerStore, partIndex]);
|
2074
|
-
return context;
|
2075
|
-
};
|
2076
|
-
var ComposerAttachmentProvider = ({ attachmentIndex: partIndex, children }) => {
|
2077
|
-
const context = useComposerAttachmentContext2(partIndex);
|
2078
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AttachmentContext.Provider, { value: context, children });
|
2079
|
-
};
|
2080
|
-
|
2081
|
-
// src/primitives/composer/ComposerAttachments.tsx
|
2082
|
-
|
2083
2535
|
var getComponent2 = (components, attachment) => {
|
2084
2536
|
const type = attachment.type;
|
2085
2537
|
switch (type) {
|
2086
2538
|
case "image":
|
2087
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
2539
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _123 => _123.Image]), () => ( _optionalChain([components, 'optionalAccess', _124 => _124.Attachment])));
|
2088
2540
|
case "document":
|
2089
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
2541
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _125 => _125.Document]), () => ( _optionalChain([components, 'optionalAccess', _126 => _126.Attachment])));
|
2090
2542
|
case "file":
|
2091
|
-
return _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
2543
|
+
return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _127 => _127.File]), () => ( _optionalChain([components, 'optionalAccess', _128 => _128.Attachment])));
|
2092
2544
|
default:
|
2093
2545
|
const _exhaustiveCheck = type;
|
2094
2546
|
throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
|
2095
2547
|
}
|
2096
2548
|
};
|
2097
2549
|
var AttachmentComponent2 = ({ components }) => {
|
2098
|
-
const Component =
|
2099
|
-
(a) => getComponent2(components, a
|
2550
|
+
const Component = useThreadComposerAttachment(
|
2551
|
+
(a) => getComponent2(components, a)
|
2100
2552
|
);
|
2101
2553
|
if (!Component) return null;
|
2102
2554
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Component, {});
|
2103
2555
|
};
|
2104
2556
|
var ComposerAttachmentImpl = ({ components, attachmentIndex }) => {
|
2105
|
-
|
2557
|
+
const composerRuntime = useComposerRuntime();
|
2558
|
+
const runtime = _react.useMemo.call(void 0,
|
2559
|
+
() => composerRuntime.unstable_getAttachmentByIndex(attachmentIndex),
|
2560
|
+
[composerRuntime, attachmentIndex]
|
2561
|
+
);
|
2562
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AttachmentRuntimeProvider, { runtime, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AttachmentComponent2, { components }) });
|
2106
2563
|
};
|
2107
2564
|
var ComposerAttachment = _react.memo.call(void 0,
|
2108
2565
|
ComposerAttachmentImpl,
|
2109
|
-
(prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access',
|
2566
|
+
(prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _129 => _129.components, 'optionalAccess', _130 => _130.Image]) === _optionalChain([next, 'access', _131 => _131.components, 'optionalAccess', _132 => _132.Image]) && _optionalChain([prev, 'access', _133 => _133.components, 'optionalAccess', _134 => _134.Document]) === _optionalChain([next, 'access', _135 => _135.components, 'optionalAccess', _136 => _136.Document]) && _optionalChain([prev, 'access', _137 => _137.components, 'optionalAccess', _138 => _138.File]) === _optionalChain([next, 'access', _139 => _139.components, 'optionalAccess', _140 => _140.File]) && _optionalChain([prev, 'access', _141 => _141.components, 'optionalAccess', _142 => _142.Attachment]) === _optionalChain([next, 'access', _143 => _143.components, 'optionalAccess', _144 => _144.Attachment])
|
2110
2567
|
);
|
2111
2568
|
var ComposerPrimitiveAttachments = ({ components }) => {
|
2112
|
-
const attachmentsCount =
|
2569
|
+
const attachmentsCount = useComposer((s) => s.attachments.length);
|
2113
2570
|
return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
2114
2571
|
ComposerAttachment,
|
2115
2572
|
{
|
@@ -2311,45 +2768,6 @@ ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
|
2311
2768
|
|
2312
2769
|
|
2313
2770
|
|
2314
|
-
// src/context/stores/EditComposer.ts
|
2315
|
-
|
2316
|
-
var makeEditComposerStore = ({
|
2317
|
-
onEdit,
|
2318
|
-
onSend
|
2319
|
-
}) => _zustand.create.call(void 0, )((set, get) => ({
|
2320
|
-
type: "edit",
|
2321
|
-
get value() {
|
2322
|
-
return get().text;
|
2323
|
-
},
|
2324
|
-
setValue(value) {
|
2325
|
-
get().setText(value);
|
2326
|
-
},
|
2327
|
-
text: "",
|
2328
|
-
setText: (text) => {
|
2329
|
-
set({ text, isEmpty: text.trim().length === 0 });
|
2330
|
-
},
|
2331
|
-
canCancel: false,
|
2332
|
-
isEditing: false,
|
2333
|
-
isEmpty: true,
|
2334
|
-
edit: () => {
|
2335
|
-
const text = onEdit();
|
2336
|
-
set({
|
2337
|
-
isEditing: true,
|
2338
|
-
canCancel: true,
|
2339
|
-
isEmpty: text.trim().length === 0,
|
2340
|
-
text
|
2341
|
-
});
|
2342
|
-
},
|
2343
|
-
send: () => {
|
2344
|
-
const text = get().text;
|
2345
|
-
set({ isEditing: false, canCancel: false });
|
2346
|
-
onSend(text);
|
2347
|
-
},
|
2348
|
-
cancel: () => {
|
2349
|
-
set({ isEditing: false, canCancel: false });
|
2350
|
-
}
|
2351
|
-
}));
|
2352
|
-
|
2353
2771
|
// src/context/stores/MessageUtils.ts
|
2354
2772
|
|
2355
2773
|
var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => {
|
@@ -2365,7 +2783,7 @@ var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => {
|
|
2365
2783
|
},
|
2366
2784
|
isSpeaking: false,
|
2367
2785
|
stopSpeaking: () => {
|
2368
|
-
_optionalChain([utterance, 'optionalAccess',
|
2786
|
+
_optionalChain([utterance, 'optionalAccess', _145 => _145.cancel, 'call', _146 => _146()]);
|
2369
2787
|
},
|
2370
2788
|
addUtterance: (utt) => {
|
2371
2789
|
utterance = utt;
|
@@ -2404,29 +2822,13 @@ var useMessageUtilsStore2 = () => {
|
|
2404
2822
|
return store;
|
2405
2823
|
};
|
2406
2824
|
var useEditComposerStore2 = (useMessageRuntime2) => {
|
2407
|
-
const
|
2408
|
-
|
2409
|
-
|
2410
|
-
|
2411
|
-
|
2412
|
-
|
2413
|
-
|
2414
|
-
},
|
2415
|
-
onSend: (text) => {
|
2416
|
-
const message = useMessageRuntime2.getState().getState();
|
2417
|
-
const previousText = getThreadMessageText(message);
|
2418
|
-
if (previousText === text) return;
|
2419
|
-
const nonTextParts = message.content.filter(
|
2420
|
-
(part) => part.type !== "text" && part.type !== "ui"
|
2421
|
-
);
|
2422
|
-
useMessageRuntime2.getState().edit({
|
2423
|
-
role: message.role,
|
2424
|
-
content: [{ type: "text", text }, ...nonTextParts],
|
2425
|
-
attachments: _nullishCoalesce(message.attachments, () => ( []))
|
2426
|
-
});
|
2427
|
-
}
|
2428
|
-
})
|
2429
|
-
);
|
2825
|
+
const runtime = useMessageRuntime2.getState().composer;
|
2826
|
+
const [store] = _react.useState.call(void 0, () => _zustand.create.call(void 0, () => runtime.getState()));
|
2827
|
+
_react.useEffect.call(void 0, () => {
|
2828
|
+
const updateState = () => writableStore(store).setState(runtime.getState());
|
2829
|
+
updateState();
|
2830
|
+
return runtime.subscribe(updateState);
|
2831
|
+
}, [runtime, store]);
|
2430
2832
|
return store;
|
2431
2833
|
};
|
2432
2834
|
var MessageRuntimeProvider = ({
|
@@ -2500,7 +2902,7 @@ var ThreadMessage = _react.memo.call(void 0,
|
|
2500
2902
|
var ThreadPrimitiveMessagesImpl = ({
|
2501
2903
|
components
|
2502
2904
|
}) => {
|
2503
|
-
const messagesLength =
|
2905
|
+
const messagesLength = useThread((t) => t.messages.length);
|
2504
2906
|
if (messagesLength === 0) return null;
|
2505
2907
|
return Array.from({ length: messagesLength }, (_, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadMessage, { messageIndex: index, components }, index));
|
2506
2908
|
};
|
@@ -2528,7 +2930,7 @@ var subscribeToMainThread = (runtime, callback) => {
|
|
2528
2930
|
let first = true;
|
2529
2931
|
let cleanup;
|
2530
2932
|
const inner = () => {
|
2531
|
-
_optionalChain([cleanup, 'optionalCall',
|
2933
|
+
_optionalChain([cleanup, 'optionalCall', _147 => _147()]);
|
2532
2934
|
cleanup = runtime.thread.subscribe(callback);
|
2533
2935
|
if (!first) {
|
2534
2936
|
callback();
|
@@ -2539,7 +2941,7 @@ var subscribeToMainThread = (runtime, callback) => {
|
|
2539
2941
|
inner();
|
2540
2942
|
return () => {
|
2541
2943
|
unsubscribe();
|
2542
|
-
_optionalChain([cleanup, 'optionalCall',
|
2944
|
+
_optionalChain([cleanup, 'optionalCall', _148 => _148()]);
|
2543
2945
|
};
|
2544
2946
|
};
|
2545
2947
|
|
@@ -2547,8 +2949,8 @@ var subscribeToMainThread = (runtime, callback) => {
|
|
2547
2949
|
|
2548
2950
|
|
2549
2951
|
// src/runtimes/core/BaseAssistantRuntimeCore.tsx
|
2550
|
-
var BaseAssistantRuntimeCore = (
|
2551
|
-
constructor(_thread) {;
|
2952
|
+
var BaseAssistantRuntimeCore = (_class7 = class {
|
2953
|
+
constructor(_thread) {;_class7.prototype.__init11.call(this);_class7.prototype.__init12.call(this);
|
2552
2954
|
this._thread = _thread;
|
2553
2955
|
this._thread = _thread;
|
2554
2956
|
}
|
@@ -2559,22 +2961,22 @@ var BaseAssistantRuntimeCore = (_class2 = class {
|
|
2559
2961
|
this._thread = thread;
|
2560
2962
|
this.subscriptionHandler();
|
2561
2963
|
}
|
2562
|
-
|
2964
|
+
__init11() {this._subscriptions = /* @__PURE__ */ new Set()}
|
2563
2965
|
subscribe(callback) {
|
2564
2966
|
this._subscriptions.add(callback);
|
2565
2967
|
return () => this._subscriptions.delete(callback);
|
2566
2968
|
}
|
2567
|
-
|
2969
|
+
__init12() {this.subscriptionHandler = () => {
|
2568
2970
|
for (const callback of this._subscriptions) callback();
|
2569
2971
|
}}
|
2570
|
-
},
|
2972
|
+
}, _class7);
|
2571
2973
|
|
2572
2974
|
// src/internal.ts
|
2573
2975
|
var internal_exports = {};
|
2574
2976
|
_chunkPZ5AY32Cjs.__export.call(void 0, internal_exports, {
|
2575
2977
|
AssistantRuntime: () => AssistantRuntime,
|
2576
2978
|
BaseAssistantRuntimeCore: () => BaseAssistantRuntimeCore,
|
2577
|
-
|
2979
|
+
DefaultThreadComposerRuntimeCore: () => DefaultThreadComposerRuntimeCore,
|
2578
2980
|
MessageRepository: () => MessageRepository,
|
2579
2981
|
ProxyConfigProvider: () => ProxyConfigProvider,
|
2580
2982
|
ThreadRuntime: () => ThreadRuntime,
|
@@ -2585,46 +2987,70 @@ _chunkPZ5AY32Cjs.__export.call(void 0, internal_exports, {
|
|
2585
2987
|
withSmoothContextProvider: () => withSmoothContextProvider
|
2586
2988
|
});
|
2587
2989
|
|
2588
|
-
// src/runtimes/
|
2589
|
-
var
|
2590
|
-
|
2591
|
-
|
2592
|
-
|
2990
|
+
// src/runtimes/composer/BaseComposerRuntimeCore.tsx
|
2991
|
+
var isAttachmentComplete = (a) => a.status.type === "complete";
|
2992
|
+
var BaseComposerRuntimeCore = (_class8 = class {constructor() { _class8.prototype.__init13.call(this);_class8.prototype.__init14.call(this);_class8.prototype.__init15.call(this);_class8.prototype.__init16.call(this);_class8.prototype.__init17.call(this); }
|
2993
|
+
__init13() {this.isEditing = true}
|
2994
|
+
__init14() {this.attachmentAccept = "*"}
|
2995
|
+
__init15() {this._attachments = []}
|
2996
|
+
set attachments(value) {
|
2997
|
+
this._attachments = value;
|
2998
|
+
this.notifySubscribers();
|
2999
|
+
}
|
3000
|
+
get attachments() {
|
3001
|
+
return this._attachments;
|
2593
3002
|
}
|
2594
|
-
|
2595
|
-
__init7() {this.attachmentAccept = "*"}
|
2596
3003
|
get isEmpty() {
|
2597
3004
|
return !this.text.trim() && !this.attachments.length;
|
2598
3005
|
}
|
2599
|
-
|
2600
|
-
get
|
2601
|
-
return this.
|
3006
|
+
__init16() {this._text = ""}
|
3007
|
+
get text() {
|
3008
|
+
return this._text;
|
2602
3009
|
}
|
2603
|
-
|
2604
|
-
|
2605
|
-
|
2606
|
-
|
2607
|
-
|
2608
|
-
|
2609
|
-
|
3010
|
+
setText(value) {
|
3011
|
+
this._text = value;
|
3012
|
+
this.notifySubscribers();
|
3013
|
+
}
|
3014
|
+
reset() {
|
3015
|
+
this._text = "";
|
3016
|
+
this._attachments = [];
|
3017
|
+
this.notifySubscribers();
|
2610
3018
|
}
|
3019
|
+
async send() {
|
3020
|
+
const attachments = this._attachmentAdapter ? await Promise.all(
|
3021
|
+
this.attachments.map(async (a) => {
|
3022
|
+
if (isAttachmentComplete(a)) return a;
|
3023
|
+
const result = await this._attachmentAdapter.send(a);
|
3024
|
+
if (_optionalChain([result, 'access', _149 => _149.status, 'optionalAccess', _150 => _150.type]) !== "complete") {
|
3025
|
+
result.status = { type: "complete" };
|
3026
|
+
}
|
3027
|
+
return result;
|
3028
|
+
})
|
3029
|
+
) : [];
|
3030
|
+
const message = {
|
3031
|
+
role: "user",
|
3032
|
+
content: this.text ? [{ type: "text", text: this.text }] : [],
|
3033
|
+
attachments
|
3034
|
+
};
|
3035
|
+
this.reset();
|
3036
|
+
this.handleSend(message);
|
3037
|
+
}
|
3038
|
+
|
2611
3039
|
setAttachmentAdapter(adapter) {
|
2612
3040
|
this._attachmentAdapter = adapter;
|
2613
|
-
const accept = _nullishCoalesce(_optionalChain([adapter, 'optionalAccess',
|
3041
|
+
const accept = _nullishCoalesce(_optionalChain([adapter, 'optionalAccess', _151 => _151.accept]), () => ( "*"));
|
2614
3042
|
if (this.attachmentAccept !== accept) {
|
2615
3043
|
this.attachmentAccept = accept;
|
2616
|
-
|
3044
|
+
this.notifySubscribers();
|
2617
3045
|
}
|
2618
|
-
return false;
|
2619
|
-
}
|
2620
|
-
__init9() {this._attachments = []}
|
2621
|
-
get attachments() {
|
2622
|
-
return this._attachments;
|
2623
3046
|
}
|
2624
3047
|
async addAttachment(file) {
|
2625
3048
|
if (!this._attachmentAdapter)
|
2626
3049
|
throw new Error("Attachments are not supported");
|
2627
3050
|
const attachment = await this._attachmentAdapter.add({ file });
|
3051
|
+
if (attachment.status === void 0) {
|
3052
|
+
attachment.status = { type: "requires-action", reason: "composer-send" };
|
3053
|
+
}
|
2628
3054
|
this._attachments = [...this._attachments, attachment];
|
2629
3055
|
this.notifySubscribers();
|
2630
3056
|
}
|
@@ -2638,49 +3064,52 @@ var BaseThreadComposerRuntimeCore = (_class3 = class {
|
|
2638
3064
|
this._attachments = this._attachments.toSpliced(index, 1);
|
2639
3065
|
this.notifySubscribers();
|
2640
3066
|
}
|
2641
|
-
|
2642
|
-
|
2643
|
-
|
3067
|
+
__init17() {this._subscriptions = /* @__PURE__ */ new Set()}
|
3068
|
+
notifySubscribers() {
|
3069
|
+
for (const callback of this._subscriptions) callback();
|
2644
3070
|
}
|
2645
|
-
|
2646
|
-
this.
|
2647
|
-
this.
|
3071
|
+
subscribe(callback) {
|
3072
|
+
this._subscriptions.add(callback);
|
3073
|
+
return () => this._subscriptions.delete(callback);
|
2648
3074
|
}
|
2649
|
-
|
2650
|
-
|
2651
|
-
|
2652
|
-
|
3075
|
+
}, _class8);
|
3076
|
+
|
3077
|
+
// src/runtimes/composer/DefaultThreadComposerRuntimeCore.tsx
|
3078
|
+
var DefaultThreadComposerRuntimeCore = (_class9 = class extends BaseComposerRuntimeCore {
|
3079
|
+
constructor(runtime) {
|
3080
|
+
super();_class9.prototype.__init18.call(this);;
|
3081
|
+
this.runtime = runtime;
|
3082
|
+
this.connect();
|
2653
3083
|
}
|
2654
|
-
|
2655
|
-
|
2656
|
-
|
2657
|
-
|
2658
|
-
|
2659
|
-
|
3084
|
+
__init18() {this._canCancel = false}
|
3085
|
+
get canCancel() {
|
3086
|
+
return this._canCancel;
|
3087
|
+
}
|
3088
|
+
get attachments() {
|
3089
|
+
return super.attachments;
|
3090
|
+
}
|
3091
|
+
connect() {
|
3092
|
+
return this.runtime.subscribe(() => {
|
3093
|
+
if (this.canCancel !== this.runtime.capabilities.cancel) {
|
3094
|
+
this._canCancel = this.runtime.capabilities.cancel;
|
3095
|
+
this.notifySubscribers();
|
3096
|
+
}
|
3097
|
+
});
|
3098
|
+
}
|
3099
|
+
async handleSend(message) {
|
2660
3100
|
this.runtime.append({
|
2661
|
-
|
2662
|
-
|
2663
|
-
content: this.text ? [{ type: "text", text: this.text }] : [],
|
2664
|
-
attachments
|
3101
|
+
...message,
|
3102
|
+
parentId: _nullishCoalesce(_optionalChain([this, 'access', _152 => _152.runtime, 'access', _153 => _153.messages, 'access', _154 => _154.at, 'call', _155 => _155(-1), 'optionalAccess', _156 => _156.id]), () => ( null))
|
2665
3103
|
});
|
2666
|
-
this.reset();
|
2667
3104
|
}
|
2668
3105
|
async cancel() {
|
2669
3106
|
this.runtime.cancelRun();
|
2670
3107
|
}
|
2671
|
-
|
2672
|
-
notifySubscribers() {
|
2673
|
-
for (const callback of this._subscriptions) callback();
|
2674
|
-
}
|
2675
|
-
subscribe(callback) {
|
2676
|
-
this._subscriptions.add(callback);
|
2677
|
-
return () => this._subscriptions.delete(callback);
|
2678
|
-
}
|
2679
|
-
}, _class3);
|
3108
|
+
}, _class9);
|
2680
3109
|
|
2681
3110
|
// src/utils/ProxyConfigProvider.ts
|
2682
|
-
var ProxyConfigProvider = (
|
2683
|
-
|
3111
|
+
var ProxyConfigProvider = (_class10 = class {constructor() { _class10.prototype.__init19.call(this); }
|
3112
|
+
__init19() {this._providers = /* @__PURE__ */ new Set()}
|
2684
3113
|
getModelConfig() {
|
2685
3114
|
return _chunk5KIEXJRKjs.mergeModelConfigs.call(void 0, this._providers);
|
2686
3115
|
}
|
@@ -2690,7 +3119,7 @@ var ProxyConfigProvider = (_class4 = class {constructor() { _class4.prototype.__
|
|
2690
3119
|
this._providers.delete(provider);
|
2691
3120
|
};
|
2692
3121
|
}
|
2693
|
-
},
|
3122
|
+
}, _class10);
|
2694
3123
|
|
2695
3124
|
// src/utils/idUtils.tsx
|
2696
3125
|
var _nonsecure = require('nanoid/non-secure');
|
@@ -2757,11 +3186,11 @@ var findHead = (message) => {
|
|
2757
3186
|
if ("current" in message) return message;
|
2758
3187
|
return null;
|
2759
3188
|
};
|
2760
|
-
var MessageRepository = (
|
2761
|
-
|
3189
|
+
var MessageRepository = (_class11 = class {constructor() { _class11.prototype.__init20.call(this);_class11.prototype.__init21.call(this);_class11.prototype.__init22.call(this); }
|
3190
|
+
__init20() {this.messages = /* @__PURE__ */ new Map()}
|
2762
3191
|
// message_id -> item
|
2763
|
-
|
2764
|
-
|
3192
|
+
__init21() {this.head = null}
|
3193
|
+
__init22() {this.root = {
|
2765
3194
|
children: [],
|
2766
3195
|
next: null
|
2767
3196
|
}}
|
@@ -2803,11 +3232,11 @@ var MessageRepository = (_class5 = class {constructor() { _class5.prototype.__in
|
|
2803
3232
|
}
|
2804
3233
|
}
|
2805
3234
|
getMessages() {
|
2806
|
-
const
|
3235
|
+
const messages2 = new Array(_nullishCoalesce(_optionalChain([this, 'access', _157 => _157.head, 'optionalAccess', _158 => _158.level]), () => ( 0)));
|
2807
3236
|
for (let current = this.head; current; current = current.prev) {
|
2808
|
-
|
3237
|
+
messages2[current.level] = current.current;
|
2809
3238
|
}
|
2810
|
-
return
|
3239
|
+
return messages2;
|
2811
3240
|
}
|
2812
3241
|
addOrUpdateMessage(parentId, message) {
|
2813
3242
|
const existingItem = this.messages.get(message.id);
|
@@ -2841,7 +3270,7 @@ var MessageRepository = (_class5 = class {constructor() { _class5.prototype.__in
|
|
2841
3270
|
"MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui."
|
2842
3271
|
);
|
2843
3272
|
return {
|
2844
|
-
parentId: _nullishCoalesce(_optionalChain([message, 'access',
|
3273
|
+
parentId: _nullishCoalesce(_optionalChain([message, 'access', _159 => _159.prev, 'optionalAccess', _160 => _160.current, 'access', _161 => _161.id]), () => ( null)),
|
2845
3274
|
message: message.current
|
2846
3275
|
};
|
2847
3276
|
}
|
@@ -2925,21 +3354,21 @@ var MessageRepository = (_class5 = class {constructor() { _class5.prototype.__in
|
|
2925
3354
|
for (const [, message] of this.messages) {
|
2926
3355
|
exportItems.push({
|
2927
3356
|
message: message.current,
|
2928
|
-
parentId: _nullishCoalesce(_optionalChain([message, 'access',
|
3357
|
+
parentId: _nullishCoalesce(_optionalChain([message, 'access', _162 => _162.prev, 'optionalAccess', _163 => _163.current, 'access', _164 => _164.id]), () => ( null))
|
2929
3358
|
});
|
2930
3359
|
}
|
2931
3360
|
return {
|
2932
|
-
headId: _nullishCoalesce(_optionalChain([this, 'access',
|
3361
|
+
headId: _nullishCoalesce(_optionalChain([this, 'access', _165 => _165.head, 'optionalAccess', _166 => _166.current, 'access', _167 => _167.id]), () => ( null)),
|
2933
3362
|
messages: exportItems
|
2934
3363
|
};
|
2935
3364
|
}
|
2936
|
-
import({ headId, messages }) {
|
2937
|
-
for (const { message, parentId } of
|
3365
|
+
import({ headId, messages: messages2 }) {
|
3366
|
+
for (const { message, parentId } of messages2) {
|
2938
3367
|
this.addOrUpdateMessage(parentId, message);
|
2939
3368
|
}
|
2940
|
-
this.resetHead(_nullishCoalesce(_nullishCoalesce(headId, () => ( _optionalChain([
|
3369
|
+
this.resetHead(_nullishCoalesce(_nullishCoalesce(headId, () => ( _optionalChain([messages2, 'access', _168 => _168.at, 'call', _169 => _169(-1), 'optionalAccess', _170 => _170.message, 'access', _171 => _171.id]))), () => ( null)));
|
2941
3370
|
}
|
2942
|
-
},
|
3371
|
+
}, _class11);
|
2943
3372
|
|
2944
3373
|
// src/ui/base/tooltip-icon-button.tsx
|
2945
3374
|
|
@@ -3032,70 +3461,10 @@ var TooltipIconButton = _react.forwardRef.call(void 0, ({ children, tooltip, sid
|
|
3032
3461
|
children,
|
3033
3462
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "aui-sr-only", children: tooltip })
|
3034
3463
|
] }) }),
|
3035
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, TooltipContent, { side, children: tooltip })
|
3036
|
-
] });
|
3037
|
-
});
|
3038
|
-
TooltipIconButton.displayName = "TooltipIconButton";
|
3039
|
-
|
3040
|
-
// src/api/subscribable/BaseSubject.ts
|
3041
|
-
var BaseSubject = (_class6 = class {constructor() { _class6.prototype.__init16.call(this); }
|
3042
|
-
__init16() {this._subscriptions = /* @__PURE__ */ new Set()}
|
3043
|
-
|
3044
|
-
get isConnected() {
|
3045
|
-
return !!this._connection;
|
3046
|
-
}
|
3047
|
-
notifySubscribers() {
|
3048
|
-
for (const callback of this._subscriptions) callback();
|
3049
|
-
}
|
3050
|
-
_updateConnection() {
|
3051
|
-
if (this._subscriptions.size > 0) {
|
3052
|
-
if (this._connection) return;
|
3053
|
-
this._connection = this._connect();
|
3054
|
-
} else {
|
3055
|
-
_optionalChain([this, 'access', _112 => _112._connection, 'optionalCall', _113 => _113()]);
|
3056
|
-
this._connection = void 0;
|
3057
|
-
}
|
3058
|
-
}
|
3059
|
-
subscribe(callback) {
|
3060
|
-
this._subscriptions.add(callback);
|
3061
|
-
this._updateConnection();
|
3062
|
-
return () => {
|
3063
|
-
this._subscriptions.delete(callback);
|
3064
|
-
this._updateConnection();
|
3065
|
-
};
|
3066
|
-
}
|
3067
|
-
}, _class6);
|
3068
|
-
|
3069
|
-
// src/api/subscribable/NestedSubscriptionSubject.ts
|
3070
|
-
var NestedSubscriptionSubject = class extends BaseSubject {
|
3071
|
-
constructor(binding) {
|
3072
|
-
super();
|
3073
|
-
this.binding = binding;
|
3074
|
-
}
|
3075
|
-
getState() {
|
3076
|
-
return this.binding.getState();
|
3077
|
-
}
|
3078
|
-
_connect() {
|
3079
|
-
const callback = () => {
|
3080
|
-
this.notifySubscribers();
|
3081
|
-
};
|
3082
|
-
let lastState = this.binding.getState();
|
3083
|
-
let innerUnsubscribe = lastState.subscribe(callback);
|
3084
|
-
const onRuntimeUpdate = () => {
|
3085
|
-
const newState = this.binding.getState();
|
3086
|
-
if (newState === lastState) return;
|
3087
|
-
lastState = newState;
|
3088
|
-
_optionalChain([innerUnsubscribe, 'optionalCall', _114 => _114()]);
|
3089
|
-
innerUnsubscribe = this.binding.getState().subscribe(callback);
|
3090
|
-
callback();
|
3091
|
-
};
|
3092
|
-
const outerUnsubscribe = this.binding.subscribe(onRuntimeUpdate);
|
3093
|
-
return () => {
|
3094
|
-
_optionalChain([outerUnsubscribe, 'optionalCall', _115 => _115()]);
|
3095
|
-
innerUnsubscribe();
|
3096
|
-
};
|
3097
|
-
}
|
3098
|
-
};
|
3464
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, TooltipContent, { side, children: tooltip })
|
3465
|
+
] });
|
3466
|
+
});
|
3467
|
+
TooltipIconButton.displayName = "TooltipIconButton";
|
3099
3468
|
|
3100
3469
|
// src/api/AssistantRuntime.ts
|
3101
3470
|
var AssistantRuntime = class {
|
@@ -3127,245 +3496,11 @@ var AssistantRuntime = class {
|
|
3127
3496
|
}
|
3128
3497
|
};
|
3129
3498
|
|
3130
|
-
// src/api/ContentPartRuntime.ts
|
3131
|
-
var ContentPartRuntime = class {
|
3132
|
-
constructor(contentBinding, messageApi, threadApi) {
|
3133
|
-
this.contentBinding = contentBinding;
|
3134
|
-
this.messageApi = messageApi;
|
3135
|
-
this.threadApi = threadApi;
|
3136
|
-
}
|
3137
|
-
getState() {
|
3138
|
-
return this.contentBinding.getState();
|
3139
|
-
}
|
3140
|
-
addToolResult(result) {
|
3141
|
-
const message = this.messageApi.getState();
|
3142
|
-
if (!message) throw new Error("Message is not available");
|
3143
|
-
const state = this.contentBinding.getState();
|
3144
|
-
if (!state) throw new Error("Content part is not available");
|
3145
|
-
if (state.part.type !== "tool-call")
|
3146
|
-
throw new Error("Tried to add tool result to non-tool content part");
|
3147
|
-
const toolName = state.part.toolName;
|
3148
|
-
const toolCallId = state.part.toolCallId;
|
3149
|
-
this.threadApi.getState().addToolResult({
|
3150
|
-
messageId: message.id,
|
3151
|
-
toolName,
|
3152
|
-
toolCallId,
|
3153
|
-
result
|
3154
|
-
});
|
3155
|
-
}
|
3156
|
-
};
|
3157
|
-
|
3158
|
-
// src/api/subscribable/shallowEqual.ts
|
3159
|
-
function shallowEqual(objA, objB) {
|
3160
|
-
if (objA === void 0 && objB === void 0) return true;
|
3161
|
-
if (objA === void 0) return false;
|
3162
|
-
if (objB === void 0) return false;
|
3163
|
-
for (const key of Object.keys(objA)) {
|
3164
|
-
const valueA = objA[key];
|
3165
|
-
const valueB = objB[key];
|
3166
|
-
if (!Object.is(valueA, valueB)) return false;
|
3167
|
-
}
|
3168
|
-
return true;
|
3169
|
-
}
|
3170
|
-
|
3171
|
-
// src/api/subscribable/ShallowMemoizeSubject.ts
|
3172
|
-
var ShallowMemoizeSubject = (_class7 = class extends BaseSubject {
|
3173
|
-
constructor(binding) {
|
3174
|
-
super();_class7.prototype.__init17.call(this);;
|
3175
|
-
this.binding = binding;
|
3176
|
-
const state = binding.getState();
|
3177
|
-
if (state === void 0)
|
3178
|
-
throw new Error("Entry not available in the store");
|
3179
|
-
this._previousState = state;
|
3180
|
-
}
|
3181
|
-
|
3182
|
-
__init17() {this.getState = () => {
|
3183
|
-
if (!this.isConnected) this._syncState();
|
3184
|
-
return this._previousState;
|
3185
|
-
}}
|
3186
|
-
_syncState() {
|
3187
|
-
const state = this.binding.getState();
|
3188
|
-
if (state === void 0) return false;
|
3189
|
-
if (shallowEqual(state, this._previousState)) return false;
|
3190
|
-
this._previousState = state;
|
3191
|
-
return true;
|
3192
|
-
}
|
3193
|
-
_connect() {
|
3194
|
-
const callback = () => {
|
3195
|
-
if (this._syncState()) {
|
3196
|
-
this.notifySubscribers();
|
3197
|
-
}
|
3198
|
-
};
|
3199
|
-
return this.binding.subscribe(callback);
|
3200
|
-
}
|
3201
|
-
}, _class7);
|
3202
|
-
|
3203
|
-
// src/api/MessageRuntime.ts
|
3204
|
-
var MessageRuntime = class {
|
3205
|
-
constructor(_core, _threadBinding) {
|
3206
|
-
this._core = _core;
|
3207
|
-
this._threadBinding = _threadBinding;
|
3208
|
-
}
|
3209
|
-
getState() {
|
3210
|
-
return this._core.getState();
|
3211
|
-
}
|
3212
|
-
// TODO improve type
|
3213
|
-
edit(message) {
|
3214
|
-
const state = this._core.getState();
|
3215
|
-
if (!state) throw new Error("Message is not available");
|
3216
|
-
this._threadBinding.getState().append({
|
3217
|
-
...message,
|
3218
|
-
parentId: state.parentId
|
3219
|
-
});
|
3220
|
-
}
|
3221
|
-
reload() {
|
3222
|
-
const state = this._core.getState();
|
3223
|
-
if (!state) throw new Error("Message is not available");
|
3224
|
-
this._threadBinding.getState().startRun(state.parentId);
|
3225
|
-
}
|
3226
|
-
speak() {
|
3227
|
-
const state = this._core.getState();
|
3228
|
-
if (!state) throw new Error("Message is not available");
|
3229
|
-
this._threadBinding.getState().speak(state.id);
|
3230
|
-
}
|
3231
|
-
submitFeedback({ type }) {
|
3232
|
-
const state = this._core.getState();
|
3233
|
-
if (!state) throw new Error("Message is not available");
|
3234
|
-
this._threadBinding.getState().submitFeedback({
|
3235
|
-
messageId: state.id,
|
3236
|
-
type
|
3237
|
-
});
|
3238
|
-
}
|
3239
|
-
switchToBranch({
|
3240
|
-
position,
|
3241
|
-
branchId
|
3242
|
-
}) {
|
3243
|
-
const state = this._core.getState();
|
3244
|
-
if (!state) throw new Error("Message is not available");
|
3245
|
-
if (branchId && position) {
|
3246
|
-
throw new Error("May not specify both branchId and position");
|
3247
|
-
} else if (!branchId && !position) {
|
3248
|
-
throw new Error("Must specify either branchId or position");
|
3249
|
-
}
|
3250
|
-
const thread = this._threadBinding.getState();
|
3251
|
-
const branches = thread.getBranches(state.id);
|
3252
|
-
let targetBranch = branchId;
|
3253
|
-
if (position === "previous") {
|
3254
|
-
targetBranch = branches[state.branchNumber - 2];
|
3255
|
-
} else if (position === "next") {
|
3256
|
-
targetBranch = branches[state.branchNumber];
|
3257
|
-
}
|
3258
|
-
if (!targetBranch) throw new Error("Branch not found");
|
3259
|
-
this._threadBinding.getState().switchToBranch(targetBranch);
|
3260
|
-
}
|
3261
|
-
subscribe(callback) {
|
3262
|
-
return this._core.subscribe(callback);
|
3263
|
-
}
|
3264
|
-
getContentPartByIdx(idx) {
|
3265
|
-
if (idx < 0) throw new Error("Message index must be >= 0");
|
3266
|
-
return new ContentPartRuntime(
|
3267
|
-
new ShallowMemoizeSubject({
|
3268
|
-
getState: () => {
|
3269
|
-
const state = this.getState();
|
3270
|
-
if (!state) return void 0;
|
3271
|
-
const message = state.message;
|
3272
|
-
const part = message.content[idx];
|
3273
|
-
if (!part) return void 0;
|
3274
|
-
return {
|
3275
|
-
part,
|
3276
|
-
status: toContentPartStatus(message, idx, part)
|
3277
|
-
};
|
3278
|
-
},
|
3279
|
-
subscribe: (callback) => this._core.subscribe(callback)
|
3280
|
-
}),
|
3281
|
-
this._core,
|
3282
|
-
this._threadBinding
|
3283
|
-
);
|
3284
|
-
}
|
3285
|
-
};
|
3286
|
-
|
3287
|
-
// src/api/ThreadComposerRuntime.ts
|
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
|
-
});
|
3296
|
-
};
|
3297
|
-
var ThreadComposerRuntime = class {
|
3298
|
-
constructor(_core) {
|
3299
|
-
this._core = _core;
|
3300
|
-
}
|
3301
|
-
/**
|
3302
|
-
* @deprecated Use `getState().isEmpty` instead. This will be removed in 0.6.0.
|
3303
|
-
*/
|
3304
|
-
get isEmpty() {
|
3305
|
-
return this._core.getState().isEmpty;
|
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
|
-
}
|
3313
|
-
/**
|
3314
|
-
* @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
|
3315
|
-
*/
|
3316
|
-
get text() {
|
3317
|
-
return this._core.getState().text;
|
3318
|
-
}
|
3319
|
-
/**
|
3320
|
-
* @deprecated Use `getState().attachmentAccept` instead. This will be removed in 0.6.0.
|
3321
|
-
*/
|
3322
|
-
get attachmentAccept() {
|
3323
|
-
return this._core.getState().attachmentAccept;
|
3324
|
-
}
|
3325
|
-
// TODO should this instead return getAttachmentByIndex([idx]) instead?
|
3326
|
-
/**
|
3327
|
-
* @deprecated Use `getState().attachments` instead. This will be removed in 0.6.0.
|
3328
|
-
*/
|
3329
|
-
get attachments() {
|
3330
|
-
return this._core.getState().attachments;
|
3331
|
-
}
|
3332
|
-
getState() {
|
3333
|
-
return getThreadComposerState(this._core.getState());
|
3334
|
-
}
|
3335
|
-
setText(text) {
|
3336
|
-
this._core.getState().setText(text);
|
3337
|
-
}
|
3338
|
-
addAttachment(file) {
|
3339
|
-
return this._core.getState().addAttachment(file);
|
3340
|
-
}
|
3341
|
-
// /**
|
3342
|
-
// * @deprecated Use `getAttachmentById(id).removeAttachment` instead. This will be removed in 0.6.0.
|
3343
|
-
// */
|
3344
|
-
removeAttachment(attachmentId) {
|
3345
|
-
return this._core.getState().removeAttachment(attachmentId);
|
3346
|
-
}
|
3347
|
-
/**
|
3348
|
-
* @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.
|
3349
|
-
*/
|
3350
|
-
reset() {
|
3351
|
-
this._core.getState().reset();
|
3352
|
-
}
|
3353
|
-
send() {
|
3354
|
-
this._core.getState().send();
|
3355
|
-
}
|
3356
|
-
cancel() {
|
3357
|
-
this._core.getState().cancel();
|
3358
|
-
}
|
3359
|
-
subscribe(callback) {
|
3360
|
-
return this._core.subscribe(callback);
|
3361
|
-
}
|
3362
|
-
};
|
3363
|
-
|
3364
3499
|
// src/api/ThreadRuntime.ts
|
3365
|
-
var toAppendMessage = (
|
3500
|
+
var toAppendMessage = (messages2, message) => {
|
3366
3501
|
if (typeof message === "string") {
|
3367
3502
|
return {
|
3368
|
-
parentId: _nullishCoalesce(_optionalChain([
|
3503
|
+
parentId: _nullishCoalesce(_optionalChain([messages2, 'access', _172 => _172.at, 'call', _173 => _173(-1), 'optionalAccess', _174 => _174.id]), () => ( null)),
|
3369
3504
|
role: "user",
|
3370
3505
|
content: [{ type: "text", text: message }],
|
3371
3506
|
attachments: []
|
@@ -3375,7 +3510,7 @@ var toAppendMessage = (messages, message) => {
|
|
3375
3510
|
return message;
|
3376
3511
|
}
|
3377
3512
|
return {
|
3378
|
-
parentId: _nullishCoalesce(_nullishCoalesce(message.parentId, () => ( _optionalChain([
|
3513
|
+
parentId: _nullishCoalesce(_nullishCoalesce(message.parentId, () => ( _optionalChain([messages2, 'access', _175 => _175.at, 'call', _176 => _176(-1), 'optionalAccess', _177 => _177.id]))), () => ( null)),
|
3379
3514
|
role: _nullishCoalesce(message.role, () => ( "user")),
|
3380
3515
|
content: message.content,
|
3381
3516
|
attachments: _nullishCoalesce(message.attachments, () => ( []))
|
@@ -3387,14 +3522,11 @@ var getThreadState = (runtime) => {
|
|
3387
3522
|
threadId: runtime.threadId,
|
3388
3523
|
capabilities: runtime.capabilities,
|
3389
3524
|
isDisabled: runtime.isDisabled,
|
3390
|
-
isRunning: _optionalChain([lastMessage, 'optionalAccess',
|
3391
|
-
|
3525
|
+
isRunning: _optionalChain([lastMessage, 'optionalAccess', _178 => _178.role]) !== "assistant" ? false : lastMessage.status.type === "running",
|
3526
|
+
messages: runtime.messages
|
3392
3527
|
});
|
3393
3528
|
};
|
3394
|
-
var ThreadRuntime = (
|
3395
|
-
constructor(_threadBinding) {;_class8.prototype.__init18.call(this);
|
3396
|
-
this._threadBinding = _threadBinding;
|
3397
|
-
}
|
3529
|
+
var ThreadRuntime = (_class12 = class {
|
3398
3530
|
// public path = "assistant.threads[main]"; // TODO
|
3399
3531
|
/**
|
3400
3532
|
* @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.
|
@@ -3420,21 +3552,35 @@ var ThreadRuntime = (_class8 = class {
|
|
3420
3552
|
get capabilities() {
|
3421
3553
|
return this.getState().capabilities;
|
3422
3554
|
}
|
3423
|
-
|
3555
|
+
/**
|
3556
|
+
* @deprecated Use `getState().messages` instead. This will be removed in 0.6.0.
|
3557
|
+
*/
|
3424
3558
|
get messages() {
|
3425
3559
|
return this._threadBinding.getState().messages;
|
3426
3560
|
}
|
3427
3561
|
unstable_getCore() {
|
3428
3562
|
return this._threadBinding.getState();
|
3429
3563
|
}
|
3430
|
-
|
3564
|
+
|
3565
|
+
constructor(threadBinding) {;_class12.prototype.__init23.call(this);
|
3566
|
+
const stateBinding = new LazyMemoizeSubject({
|
3567
|
+
getState: () => getThreadState(threadBinding.getState()),
|
3568
|
+
subscribe: (callback) => threadBinding.subscribe(callback)
|
3569
|
+
});
|
3570
|
+
this._threadBinding = {
|
3571
|
+
getState: () => threadBinding.getState(),
|
3572
|
+
getStateState: () => stateBinding.getState(),
|
3573
|
+
subscribe: (callback) => threadBinding.subscribe(callback)
|
3574
|
+
};
|
3575
|
+
}
|
3576
|
+
__init23() {this.composer = new ThreadComposerRuntime(
|
3431
3577
|
new NestedSubscriptionSubject({
|
3432
3578
|
getState: () => this._threadBinding.getState().composer,
|
3433
3579
|
subscribe: (callback) => this._threadBinding.subscribe(callback)
|
3434
3580
|
})
|
3435
3581
|
)}
|
3436
3582
|
getState() {
|
3437
|
-
return
|
3583
|
+
return this._threadBinding.getStateState();
|
3438
3584
|
}
|
3439
3585
|
append(message) {
|
3440
3586
|
this._threadBinding.getState().append(
|
@@ -3483,6 +3629,18 @@ var ThreadRuntime = (_class8 = class {
|
|
3483
3629
|
submitFeedback(options) {
|
3484
3630
|
return this._threadBinding.getState().submitFeedback(options);
|
3485
3631
|
}
|
3632
|
+
/**
|
3633
|
+
* @deprecated Use `getMesssageById(id).unstable_getMessageByIndex(idx).composer` instead. This will be removed in 0.6.0.
|
3634
|
+
*/
|
3635
|
+
getEditComposer(messageId) {
|
3636
|
+
return this._threadBinding.getState().getEditComposer(messageId);
|
3637
|
+
}
|
3638
|
+
/**
|
3639
|
+
* @deprecated Use `getMesssageById(id).unstable_getMessageByIndex(idx).composer.beginEdit()` instead. This will be removed in 0.6.0.
|
3640
|
+
*/
|
3641
|
+
beginEdit(messageId) {
|
3642
|
+
return this._threadBinding.getState().beginEdit(messageId);
|
3643
|
+
}
|
3486
3644
|
export() {
|
3487
3645
|
return this._threadBinding.getState().export();
|
3488
3646
|
}
|
@@ -3494,15 +3652,15 @@ var ThreadRuntime = (_class8 = class {
|
|
3494
3652
|
return new MessageRuntime(
|
3495
3653
|
new ShallowMemoizeSubject({
|
3496
3654
|
getState: () => {
|
3497
|
-
const
|
3498
|
-
const message =
|
3499
|
-
if (!message) return
|
3655
|
+
const messages2 = this.getState().messages;
|
3656
|
+
const message = messages2[idx];
|
3657
|
+
if (!message) return SKIP_UPDATE;
|
3500
3658
|
const branches = this._threadBinding.getState().getBranches(message.id);
|
3501
3659
|
return {
|
3502
3660
|
...message,
|
3503
3661
|
message,
|
3504
|
-
isLast: idx ===
|
3505
|
-
parentId: _nullishCoalesce(_optionalChain([
|
3662
|
+
isLast: idx === messages2.length - 1,
|
3663
|
+
parentId: _nullishCoalesce(_optionalChain([messages2, 'access', _179 => _179[idx - 1], 'optionalAccess', _180 => _180.id]), () => ( null)),
|
3506
3664
|
branches,
|
3507
3665
|
branchNumber: branches.indexOf(message.id) + 1,
|
3508
3666
|
branchCount: branches.length
|
@@ -3513,16 +3671,16 @@ var ThreadRuntime = (_class8 = class {
|
|
3513
3671
|
this._threadBinding
|
3514
3672
|
);
|
3515
3673
|
}
|
3516
|
-
},
|
3674
|
+
}, _class12);
|
3517
3675
|
|
3518
3676
|
// src/runtimes/edge/converters/fromLanguageModelMessages.ts
|
3519
3677
|
var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
3520
|
-
const
|
3678
|
+
const messages2 = [];
|
3521
3679
|
for (const lmMessage of lm) {
|
3522
3680
|
const role = lmMessage.role;
|
3523
3681
|
switch (role) {
|
3524
3682
|
case "system": {
|
3525
|
-
|
3683
|
+
messages2.push({
|
3526
3684
|
role: "system",
|
3527
3685
|
content: [
|
3528
3686
|
{
|
@@ -3534,7 +3692,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
3534
3692
|
break;
|
3535
3693
|
}
|
3536
3694
|
case "user": {
|
3537
|
-
|
3695
|
+
messages2.push({
|
3538
3696
|
role: "user",
|
3539
3697
|
content: lmMessage.content.map((part) => {
|
3540
3698
|
const type = part.type;
|
@@ -3554,6 +3712,9 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
3554
3712
|
}
|
3555
3713
|
throw new Error("Only images with URL data are supported");
|
3556
3714
|
}
|
3715
|
+
case "file": {
|
3716
|
+
throw new Error("File content parts are not supported");
|
3717
|
+
}
|
3557
3718
|
default: {
|
3558
3719
|
const unhandledType = type;
|
3559
3720
|
throw new Error(`Unknown content part type: ${unhandledType}`);
|
@@ -3577,21 +3738,21 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
3577
3738
|
return part;
|
3578
3739
|
});
|
3579
3740
|
if (mergeRoundtrips) {
|
3580
|
-
const previousMessage =
|
3581
|
-
if (_optionalChain([previousMessage, 'optionalAccess',
|
3741
|
+
const previousMessage = messages2[messages2.length - 1];
|
3742
|
+
if (_optionalChain([previousMessage, 'optionalAccess', _181 => _181.role]) === "assistant") {
|
3582
3743
|
previousMessage.content.push(...newContent);
|
3583
3744
|
break;
|
3584
3745
|
}
|
3585
3746
|
}
|
3586
|
-
|
3747
|
+
messages2.push({
|
3587
3748
|
role: "assistant",
|
3588
3749
|
content: newContent
|
3589
3750
|
});
|
3590
3751
|
break;
|
3591
3752
|
}
|
3592
3753
|
case "tool": {
|
3593
|
-
const previousMessage =
|
3594
|
-
if (_optionalChain([previousMessage, 'optionalAccess',
|
3754
|
+
const previousMessage = messages2[messages2.length - 1];
|
3755
|
+
if (_optionalChain([previousMessage, 'optionalAccess', _182 => _182.role]) !== "assistant")
|
3595
3756
|
throw new Error(
|
3596
3757
|
"A tool message must be preceded by an assistant message."
|
3597
3758
|
);
|
@@ -3616,7 +3777,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
3616
3777
|
}
|
3617
3778
|
}
|
3618
3779
|
}
|
3619
|
-
return
|
3780
|
+
return messages2;
|
3620
3781
|
};
|
3621
3782
|
|
3622
3783
|
// src/runtimes/edge/converters/fromLanguageModelTools.ts
|
@@ -3774,7 +3935,7 @@ var EdgeChatAdapter = class {
|
|
3774
3935
|
constructor(options) {
|
3775
3936
|
this.options = options;
|
3776
3937
|
}
|
3777
|
-
async *run({ messages, abortSignal, config }) {
|
3938
|
+
async *run({ messages: messages2, abortSignal, config }) {
|
3778
3939
|
const headers = new Headers(this.options.headers);
|
3779
3940
|
headers.set("Content-Type", "application/json");
|
3780
3941
|
const result = await fetch(this.options.api, {
|
@@ -3783,7 +3944,7 @@ var EdgeChatAdapter = class {
|
|
3783
3944
|
credentials: _nullishCoalesce(this.options.credentials, () => ( "same-origin")),
|
3784
3945
|
body: JSON.stringify({
|
3785
3946
|
system: config.system,
|
3786
|
-
messages: _chunk5KIEXJRKjs.toCoreMessages.call(void 0,
|
3947
|
+
messages: _chunk5KIEXJRKjs.toCoreMessages.call(void 0, messages2),
|
3787
3948
|
tools: config.tools ? _chunk5KIEXJRKjs.toLanguageModelTools.call(void 0, config.tools) : [],
|
3788
3949
|
...config.callSettings,
|
3789
3950
|
...config.config,
|
@@ -3820,28 +3981,65 @@ var useEdgeRuntime = ({
|
|
3820
3981
|
};
|
3821
3982
|
|
3822
3983
|
// src/runtimes/local/shouldContinue.tsx
|
3823
|
-
var shouldContinue = (result) => _optionalChain([result, 'access',
|
3984
|
+
var shouldContinue = (result) => _optionalChain([result, 'access', _183 => _183.status, 'optionalAccess', _184 => _184.type]) === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
|
3985
|
+
|
3986
|
+
// src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx
|
3987
|
+
var DefaultEditComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
3988
|
+
constructor(runtime, endEditCallback, { parentId, message }) {
|
3989
|
+
super();
|
3990
|
+
this.runtime = runtime;
|
3991
|
+
this.endEditCallback = endEditCallback;
|
3992
|
+
this._parentId = parentId;
|
3993
|
+
this._previousText = getThreadMessageText(message);
|
3994
|
+
this.setText(this._previousText);
|
3995
|
+
this._nonTextParts = message.content.filter(
|
3996
|
+
(part) => part.type !== "text" && part.type !== "ui"
|
3997
|
+
);
|
3998
|
+
}
|
3999
|
+
get canCancel() {
|
4000
|
+
return true;
|
4001
|
+
}
|
4002
|
+
|
4003
|
+
|
4004
|
+
|
4005
|
+
async handleSend(message) {
|
4006
|
+
const text = getThreadMessageText(message);
|
4007
|
+
if (text !== this._previousText) {
|
4008
|
+
this.runtime.append({
|
4009
|
+
...message,
|
4010
|
+
content: [...message.content, ...this._nonTextParts],
|
4011
|
+
parentId: this._parentId
|
4012
|
+
});
|
4013
|
+
}
|
4014
|
+
this.endEditCallback();
|
4015
|
+
this.notifySubscribers();
|
4016
|
+
}
|
4017
|
+
async cancel() {
|
4018
|
+
this.endEditCallback();
|
4019
|
+
this.notifySubscribers();
|
4020
|
+
}
|
4021
|
+
};
|
3824
4022
|
|
3825
4023
|
// src/runtimes/local/LocalThreadRuntimeCore.tsx
|
3826
|
-
var LocalThreadRuntimeCore = (
|
3827
|
-
constructor(configProvider, adapter, { initialMessages, ...options }) {;
|
4024
|
+
var LocalThreadRuntimeCore = (_class13 = class {
|
4025
|
+
constructor(configProvider, adapter, { initialMessages, ...options }) {;_class13.prototype.__init24.call(this);_class13.prototype.__init25.call(this);_class13.prototype.__init26.call(this);_class13.prototype.__init27.call(this);_class13.prototype.__init28.call(this);_class13.prototype.__init29.call(this);_class13.prototype.__init30.call(this);
|
3828
4026
|
this.configProvider = configProvider;
|
3829
4027
|
this.adapter = adapter;
|
3830
4028
|
this.threadId = generateId();
|
3831
4029
|
this.options = options;
|
3832
4030
|
if (initialMessages) {
|
3833
4031
|
let parentId = null;
|
3834
|
-
const
|
3835
|
-
for (const message of
|
4032
|
+
const messages2 = fromCoreMessages(initialMessages);
|
4033
|
+
for (const message of messages2) {
|
3836
4034
|
this.repository.addOrUpdateMessage(parentId, message);
|
3837
4035
|
parentId = message.id;
|
3838
4036
|
}
|
3839
4037
|
}
|
3840
4038
|
}
|
3841
|
-
|
3842
|
-
|
3843
|
-
|
3844
|
-
|
4039
|
+
__init24() {this._subscriptions = /* @__PURE__ */ new Set()}
|
4040
|
+
__init25() {this.abortController = null}
|
4041
|
+
__init26() {this.repository = new MessageRepository()}
|
4042
|
+
__init27() {this.capabilities = {
|
3845
4043
|
switchToBranch: true,
|
3846
4044
|
edit: true,
|
3847
4045
|
reload: true,
|
@@ -3852,11 +4050,11 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
3852
4050
|
feedback: false
|
3853
4051
|
}}
|
3854
4052
|
|
3855
|
-
|
4053
|
+
__init28() {this.isDisabled = false}
|
3856
4054
|
get messages() {
|
3857
4055
|
return this.repository.getMessages();
|
3858
4056
|
}
|
3859
|
-
|
4057
|
+
__init29() {this.composer = new DefaultThreadComposerRuntimeCore(this)}
|
3860
4058
|
getModelConfig() {
|
3861
4059
|
return this.configProvider.getModelConfig();
|
3862
4060
|
}
|
@@ -3867,24 +4065,41 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
3867
4065
|
set options({ initialMessages, ...options }) {
|
3868
4066
|
this._options = options;
|
3869
4067
|
let hasUpdates = false;
|
3870
|
-
const canSpeak = _optionalChain([options, 'access',
|
4068
|
+
const canSpeak = _optionalChain([options, 'access', _185 => _185.adapters, 'optionalAccess', _186 => _186.speech]) !== void 0;
|
3871
4069
|
if (this.capabilities.speak !== canSpeak) {
|
3872
4070
|
this.capabilities.speak = canSpeak;
|
3873
4071
|
hasUpdates = true;
|
3874
4072
|
}
|
3875
|
-
this.composer.setAttachmentAdapter(_optionalChain([options, 'access',
|
3876
|
-
const canAttach = _optionalChain([options, 'access',
|
4073
|
+
this.composer.setAttachmentAdapter(_optionalChain([options, 'access', _187 => _187.adapters, 'optionalAccess', _188 => _188.attachments]));
|
4074
|
+
const canAttach = _optionalChain([options, 'access', _189 => _189.adapters, 'optionalAccess', _190 => _190.attachments]) !== void 0;
|
3877
4075
|
if (this.capabilities.attachments !== canAttach) {
|
3878
4076
|
this.capabilities.attachments = canAttach;
|
3879
4077
|
hasUpdates = true;
|
3880
4078
|
}
|
3881
|
-
const canFeedback = _optionalChain([options, 'access',
|
4079
|
+
const canFeedback = _optionalChain([options, 'access', _191 => _191.adapters, 'optionalAccess', _192 => _192.feedback]) !== void 0;
|
3882
4080
|
if (this.capabilities.feedback !== canFeedback) {
|
3883
4081
|
this.capabilities.feedback = canFeedback;
|
3884
4082
|
hasUpdates = true;
|
3885
4083
|
}
|
3886
4084
|
if (hasUpdates) this.notifySubscribers();
|
3887
4085
|
}
|
4086
|
+
__init30() {this._editComposers = /* @__PURE__ */ new Map()}
|
4087
|
+
getEditComposer(messageId) {
|
4088
|
+
return this._editComposers.get(messageId);
|
4089
|
+
}
|
4090
|
+
beginEdit(messageId) {
|
4091
|
+
if (this._editComposers.has(messageId))
|
4092
|
+
throw new Error("Edit already in progress");
|
4093
|
+
this._editComposers.set(
|
4094
|
+
messageId,
|
4095
|
+
new DefaultEditComposerRuntimeCore(
|
4096
|
+
this,
|
4097
|
+
() => this._editComposers.delete(messageId),
|
4098
|
+
this.repository.getMessage(messageId)
|
4099
|
+
)
|
4100
|
+
);
|
4101
|
+
this.notifySubscribers();
|
4102
|
+
}
|
3888
4103
|
getBranches(messageId) {
|
3889
4104
|
return this.repository.getBranches(messageId);
|
3890
4105
|
}
|
@@ -3919,19 +4134,19 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
3919
4134
|
} while (shouldContinue(message));
|
3920
4135
|
}
|
3921
4136
|
async performRoundtrip(parentId, message) {
|
3922
|
-
const
|
3923
|
-
_optionalChain([this, 'access',
|
4137
|
+
const messages2 = this.repository.getMessages();
|
4138
|
+
_optionalChain([this, 'access', _193 => _193.abortController, 'optionalAccess', _194 => _194.abort, 'call', _195 => _195()]);
|
3924
4139
|
this.abortController = new AbortController();
|
3925
4140
|
const initialContent = message.content;
|
3926
|
-
const initialRoundtrips = _optionalChain([message, 'access',
|
3927
|
-
const initalCustom = _optionalChain([message, 'access',
|
4141
|
+
const initialRoundtrips = _optionalChain([message, 'access', _196 => _196.metadata, 'optionalAccess', _197 => _197.roundtrips]);
|
4142
|
+
const initalCustom = _optionalChain([message, 'access', _198 => _198.metadata, 'optionalAccess', _199 => _199.custom]);
|
3928
4143
|
const updateMessage = (m) => {
|
3929
4144
|
message = {
|
3930
4145
|
...message,
|
3931
4146
|
...m.content ? { content: [...initialContent, ..._nullishCoalesce(m.content, () => ( []))] } : void 0,
|
3932
4147
|
status: _nullishCoalesce(m.status, () => ( message.status)),
|
3933
4148
|
// TODO deprecated, remove in v0.6
|
3934
|
-
..._optionalChain([m, 'access',
|
4149
|
+
..._optionalChain([m, 'access', _200 => _200.metadata, 'optionalAccess', _201 => _201.roundtrips]) ? {
|
3935
4150
|
roundtrips: [
|
3936
4151
|
..._nullishCoalesce(initialRoundtrips, () => ( [])),
|
3937
4152
|
...m.metadata.roundtrips
|
@@ -3946,7 +4161,7 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
3946
4161
|
...m.metadata.roundtrips
|
3947
4162
|
]
|
3948
4163
|
} : void 0,
|
3949
|
-
..._optionalChain([m, 'access',
|
4164
|
+
..._optionalChain([m, 'access', _202 => _202.metadata, 'optionalAccess', _203 => _203.custom]) ? {
|
3950
4165
|
custom: { ..._nullishCoalesce(initalCustom, () => ( {})), ...m.metadata.custom }
|
3951
4166
|
} : void 0
|
3952
4167
|
}
|
@@ -3956,7 +4171,7 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
3956
4171
|
this.notifySubscribers();
|
3957
4172
|
};
|
3958
4173
|
const maxToolRoundtrips = _nullishCoalesce(this.options.maxToolRoundtrips, () => ( 1));
|
3959
|
-
const toolRoundtrips = _nullishCoalesce(_optionalChain([message, 'access',
|
4174
|
+
const toolRoundtrips = _nullishCoalesce(_optionalChain([message, 'access', _204 => _204.metadata, 'optionalAccess', _205 => _205.roundtrips, 'optionalAccess', _206 => _206.length]), () => ( 0));
|
3960
4175
|
if (toolRoundtrips > maxToolRoundtrips) {
|
3961
4176
|
updateMessage({
|
3962
4177
|
status: {
|
@@ -3974,7 +4189,7 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
3974
4189
|
}
|
3975
4190
|
try {
|
3976
4191
|
const promiseOrGenerator = this.adapter.run({
|
3977
|
-
messages,
|
4192
|
+
messages: messages2,
|
3978
4193
|
abortSignal: this.abortController.signal,
|
3979
4194
|
config: this.configProvider.getModelConfig(),
|
3980
4195
|
onUpdate: updateMessage
|
@@ -4055,7 +4270,7 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
4055
4270
|
// TODO lift utterance state to thread runtime
|
4056
4271
|
|
4057
4272
|
speak(messageId) {
|
4058
|
-
const adapter = _optionalChain([this, 'access',
|
4273
|
+
const adapter = _optionalChain([this, 'access', _207 => _207.options, 'access', _208 => _208.adapters, 'optionalAccess', _209 => _209.speech]);
|
4059
4274
|
if (!adapter) throw new Error("Speech adapter not configured");
|
4060
4275
|
const { message } = this.repository.getMessage(messageId);
|
4061
4276
|
if (this._utterance) {
|
@@ -4072,7 +4287,7 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
4072
4287
|
return this._utterance;
|
4073
4288
|
}
|
4074
4289
|
submitFeedback({ messageId, type }) {
|
4075
|
-
const adapter = _optionalChain([this, 'access',
|
4290
|
+
const adapter = _optionalChain([this, 'access', _210 => _210.options, 'access', _211 => _211.adapters, 'optionalAccess', _212 => _212.feedback]);
|
4076
4291
|
if (!adapter) throw new Error("Feedback adapter not configured");
|
4077
4292
|
const { message } = this.repository.getMessage(messageId);
|
4078
4293
|
adapter.submit({ message, type });
|
@@ -4084,7 +4299,7 @@ var LocalThreadRuntimeCore = (_class9 = class {
|
|
4084
4299
|
this.repository.import(data);
|
4085
4300
|
this.notifySubscribers();
|
4086
4301
|
}
|
4087
|
-
},
|
4302
|
+
}, _class13);
|
4088
4303
|
|
4089
4304
|
// src/runtimes/local/LocalRuntimeCore.tsx
|
4090
4305
|
var LocalRuntimeCore = class extends BaseAssistantRuntimeCore {
|
@@ -4116,10 +4331,10 @@ var LocalRuntimeCore = class extends BaseAssistantRuntimeCore {
|
|
4116
4331
|
} = {}) {
|
4117
4332
|
this.switchToThread(null);
|
4118
4333
|
if (!initialMessages) return;
|
4119
|
-
const
|
4334
|
+
const messages2 = fromCoreMessages(initialMessages);
|
4120
4335
|
this.thread.import({
|
4121
|
-
messages:
|
4122
|
-
parentId: _nullishCoalesce(_optionalChain([
|
4336
|
+
messages: messages2.map((m, idx) => ({
|
4337
|
+
parentId: _nullishCoalesce(_optionalChain([messages2, 'access', _213 => _213[idx - 1], 'optionalAccess', _214 => _214.id]), () => ( null)),
|
4123
4338
|
message: m
|
4124
4339
|
}))
|
4125
4340
|
});
|
@@ -4155,17 +4370,17 @@ var getExternalStoreMessage = (message) => {
|
|
4155
4370
|
};
|
4156
4371
|
|
4157
4372
|
// src/runtimes/external-store/ThreadMessageConverter.ts
|
4158
|
-
var ThreadMessageConverter = (
|
4159
|
-
|
4160
|
-
convertMessages(
|
4161
|
-
return
|
4373
|
+
var ThreadMessageConverter = (_class14 = class {constructor() { _class14.prototype.__init31.call(this); }
|
4374
|
+
__init31() {this.cache = /* @__PURE__ */ new WeakMap()}
|
4375
|
+
convertMessages(messages2, converter) {
|
4376
|
+
return messages2.map((m, idx) => {
|
4162
4377
|
const cached = this.cache.get(m);
|
4163
4378
|
const newMessage = converter(cached, m, idx);
|
4164
4379
|
this.cache.set(m, newMessage);
|
4165
4380
|
return newMessage;
|
4166
4381
|
});
|
4167
4382
|
}
|
4168
|
-
},
|
4383
|
+
}, _class14);
|
4169
4384
|
|
4170
4385
|
// src/runtimes/external-store/auto-status.tsx
|
4171
4386
|
var AUTO_STATUS_RUNNING = Object.freeze({ type: "running" });
|
@@ -4251,18 +4466,18 @@ var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
|
|
4251
4466
|
};
|
4252
4467
|
|
4253
4468
|
// src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx
|
4254
|
-
var hasUpcomingMessage = (isRunning,
|
4255
|
-
return isRunning && _optionalChain([
|
4469
|
+
var hasUpcomingMessage = (isRunning, messages2) => {
|
4470
|
+
return isRunning && _optionalChain([messages2, 'access', _215 => _215[messages2.length - 1], 'optionalAccess', _216 => _216.role]) !== "assistant";
|
4256
4471
|
};
|
4257
|
-
var ExternalStoreThreadRuntimeCore = (
|
4258
|
-
constructor(configProvider, store) {;
|
4472
|
+
var ExternalStoreThreadRuntimeCore = (_class15 = class {
|
4473
|
+
constructor(configProvider, store) {;_class15.prototype.__init32.call(this);_class15.prototype.__init33.call(this);_class15.prototype.__init34.call(this);_class15.prototype.__init35.call(this);_class15.prototype.__init36.call(this);_class15.prototype.__init37.call(this);_class15.prototype.__init38.call(this);_class15.prototype.__init39.call(this);
|
4259
4474
|
this.configProvider = configProvider;
|
4260
4475
|
this.store = store;
|
4261
4476
|
}
|
4262
|
-
|
4263
|
-
|
4264
|
-
|
4265
|
-
|
4477
|
+
__init32() {this._subscriptions = /* @__PURE__ */ new Set()}
|
4478
|
+
__init33() {this.repository = new MessageRepository()}
|
4479
|
+
__init34() {this.assistantOptimisticId = null}
|
4480
|
+
__init35() {this._capabilities = {
|
4266
4481
|
switchToBranch: false,
|
4267
4482
|
edit: false,
|
4268
4483
|
reload: false,
|
@@ -4278,9 +4493,26 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4278
4493
|
|
4279
4494
|
|
4280
4495
|
|
4281
|
-
|
4496
|
+
__init36() {this.converter = new ThreadMessageConverter()}
|
4282
4497
|
|
4283
|
-
|
4498
|
+
__init37() {this.composer = new DefaultThreadComposerRuntimeCore(this)}
|
4499
|
+
__init38() {this._editComposers = /* @__PURE__ */ new Map()}
|
4500
|
+
getEditComposer(messageId) {
|
4501
|
+
return this._editComposers.get(messageId);
|
4502
|
+
}
|
4503
|
+
beginEdit(messageId) {
|
4504
|
+
if (this._editComposers.has(messageId))
|
4505
|
+
throw new Error("Edit already in progress");
|
4506
|
+
this._editComposers.set(
|
4507
|
+
messageId,
|
4508
|
+
new DefaultEditComposerRuntimeCore(
|
4509
|
+
this,
|
4510
|
+
() => this._editComposers.delete(messageId),
|
4511
|
+
this.repository.getMessage(messageId)
|
4512
|
+
)
|
4513
|
+
);
|
4514
|
+
this.notifySubscribers();
|
4515
|
+
}
|
4284
4516
|
get store() {
|
4285
4517
|
return this._store;
|
4286
4518
|
}
|
@@ -4297,12 +4529,12 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4297
4529
|
reload: this._store.onReload !== void 0,
|
4298
4530
|
cancel: this._store.onCancel !== void 0,
|
4299
4531
|
speak: this._store.onSpeak !== void 0,
|
4300
|
-
unstable_copy: _optionalChain([this, 'access',
|
4532
|
+
unstable_copy: _optionalChain([this, 'access', _220 => _220._store, 'access', _221 => _221.unstable_capabilities, 'optionalAccess', _222 => _222.copy]) !== false,
|
4301
4533
|
// default true
|
4302
|
-
attachments: !!_optionalChain([this, 'access',
|
4303
|
-
feedback: !!_optionalChain([this, 'access',
|
4534
|
+
attachments: !!_optionalChain([this, 'access', _223 => _223.store, 'access', _224 => _224.adapters, 'optionalAccess', _225 => _225.attachments]),
|
4535
|
+
feedback: !!_optionalChain([this, 'access', _226 => _226.store, 'access', _227 => _227.adapters, 'optionalAccess', _228 => _228.feedback])
|
4304
4536
|
};
|
4305
|
-
this.composer.setAttachmentAdapter(_optionalChain([this, 'access',
|
4537
|
+
this.composer.setAttachmentAdapter(_optionalChain([this, 'access', _229 => _229._store, 'access', _230 => _230.adapters, 'optionalAccess', _231 => _231.attachments]));
|
4306
4538
|
if (oldStore) {
|
4307
4539
|
if (oldStore.convertMessage !== store.convertMessage) {
|
4308
4540
|
this.converter = new ThreadMessageConverter();
|
@@ -4311,7 +4543,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4311
4543
|
return;
|
4312
4544
|
}
|
4313
4545
|
}
|
4314
|
-
const
|
4546
|
+
const messages2 = !store.convertMessage ? store.messages : this.converter.convertMessages(store.messages, (cache, m, idx) => {
|
4315
4547
|
if (!store.convertMessage) return m;
|
4316
4548
|
const isLast = idx === store.messages.length - 1;
|
4317
4549
|
const autoStatus = getAutoStatus(isLast, isRunning);
|
@@ -4325,18 +4557,18 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4325
4557
|
newMessage[symbolInnerMessage] = m;
|
4326
4558
|
return newMessage;
|
4327
4559
|
});
|
4328
|
-
for (let i = 0; i <
|
4329
|
-
const message =
|
4330
|
-
const parent =
|
4331
|
-
this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess',
|
4560
|
+
for (let i = 0; i < messages2.length; i++) {
|
4561
|
+
const message = messages2[i];
|
4562
|
+
const parent = messages2[i - 1];
|
4563
|
+
this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _232 => _232.id]), () => ( null)), message);
|
4332
4564
|
}
|
4333
4565
|
if (this.assistantOptimisticId) {
|
4334
4566
|
this.repository.deleteMessage(this.assistantOptimisticId);
|
4335
4567
|
this.assistantOptimisticId = null;
|
4336
4568
|
}
|
4337
|
-
if (hasUpcomingMessage(isRunning,
|
4569
|
+
if (hasUpcomingMessage(isRunning, messages2)) {
|
4338
4570
|
this.assistantOptimisticId = this.repository.appendOptimisticMessage(
|
4339
|
-
_nullishCoalesce(_optionalChain([
|
4571
|
+
_nullishCoalesce(_optionalChain([messages2, 'access', _233 => _233.at, 'call', _234 => _234(-1), 'optionalAccess', _235 => _235.id]), () => ( null)),
|
4340
4572
|
{
|
4341
4573
|
role: "assistant",
|
4342
4574
|
content: []
|
@@ -4344,7 +4576,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4344
4576
|
);
|
4345
4577
|
}
|
4346
4578
|
this.repository.resetHead(
|
4347
|
-
_nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([
|
4579
|
+
_nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages2, 'access', _236 => _236.at, 'call', _237 => _237(-1), 'optionalAccess', _238 => _238.id]))), () => ( null))
|
4348
4580
|
);
|
4349
4581
|
this.messages = this.repository.getMessages();
|
4350
4582
|
this.notifySubscribers();
|
@@ -4365,7 +4597,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4365
4597
|
this.updateMessages(this.repository.getMessages());
|
4366
4598
|
}
|
4367
4599
|
async append(message) {
|
4368
|
-
if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access',
|
4600
|
+
if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _239 => _239.messages, 'access', _240 => _240.at, 'call', _241 => _241(-1), 'optionalAccess', _242 => _242.id]), () => ( null)))) {
|
4369
4601
|
if (!this._store.onEdit)
|
4370
4602
|
throw new Error("Runtime does not support editing messages.");
|
4371
4603
|
await this._store.onEdit(message);
|
@@ -4386,19 +4618,19 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4386
4618
|
this.repository.deleteMessage(this.assistantOptimisticId);
|
4387
4619
|
this.assistantOptimisticId = null;
|
4388
4620
|
}
|
4389
|
-
let
|
4390
|
-
const previousMessage =
|
4391
|
-
if (_optionalChain([previousMessage, 'optionalAccess',
|
4621
|
+
let messages2 = this.repository.getMessages();
|
4622
|
+
const previousMessage = messages2[messages2.length - 1];
|
4623
|
+
if (_optionalChain([previousMessage, 'optionalAccess', _243 => _243.role]) === "user" && previousMessage.id === _optionalChain([messages2, 'access', _244 => _244.at, 'call', _245 => _245(-1), 'optionalAccess', _246 => _246.id])) {
|
4392
4624
|
this.repository.deleteMessage(previousMessage.id);
|
4393
4625
|
if (!this.composer.text.trim()) {
|
4394
4626
|
this.composer.setText(getThreadMessageText(previousMessage));
|
4395
4627
|
}
|
4396
|
-
|
4628
|
+
messages2 = this.repository.getMessages();
|
4397
4629
|
} else {
|
4398
4630
|
this.notifySubscribers();
|
4399
4631
|
}
|
4400
4632
|
setTimeout(() => {
|
4401
|
-
this.updateMessages(
|
4633
|
+
this.updateMessages(messages2);
|
4402
4634
|
}, 0);
|
4403
4635
|
}
|
4404
4636
|
addToolResult(options) {
|
@@ -4413,7 +4645,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4413
4645
|
return this._store.onSpeak(message);
|
4414
4646
|
}
|
4415
4647
|
submitFeedback({ messageId, type }) {
|
4416
|
-
const adapter = _optionalChain([this, 'access',
|
4648
|
+
const adapter = _optionalChain([this, 'access', _247 => _247._store, 'access', _248 => _248.adapters, 'optionalAccess', _249 => _249.feedback]);
|
4417
4649
|
if (!adapter) throw new Error("Feedback adapter not configured");
|
4418
4650
|
const { message } = this.repository.getMessage(messageId);
|
4419
4651
|
adapter.submit({ message, type });
|
@@ -4422,9 +4654,9 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4422
4654
|
this._subscriptions.add(callback);
|
4423
4655
|
return () => this._subscriptions.delete(callback);
|
4424
4656
|
}
|
4425
|
-
|
4426
|
-
_optionalChain([this, 'access',
|
4427
|
-
|
4657
|
+
__init39() {this.updateMessages = (messages2) => {
|
4658
|
+
_optionalChain([this, 'access', _250 => _250._store, 'access', _251 => _251.setMessages, 'optionalCall', _252 => _252(
|
4659
|
+
messages2.flatMap(getExternalStoreMessage).filter((m) => m != null)
|
4428
4660
|
)]);
|
4429
4661
|
}}
|
4430
4662
|
import(repository) {
|
@@ -4433,7 +4665,7 @@ var ExternalStoreThreadRuntimeCore = (_class11 = class {
|
|
4433
4665
|
export() {
|
4434
4666
|
return this.repository.export();
|
4435
4667
|
}
|
4436
|
-
},
|
4668
|
+
}, _class15);
|
4437
4669
|
|
4438
4670
|
// src/runtimes/external-store/ExternalStoreRuntimeCore.tsx
|
4439
4671
|
var ExternalStoreRuntimeCore = class extends BaseAssistantRuntimeCore {
|
@@ -4491,12 +4723,12 @@ var useExternalStoreRuntime = (store) => {
|
|
4491
4723
|
|
4492
4724
|
// src/runtimes/external-store/external-message-converter.tsx
|
4493
4725
|
|
4494
|
-
var joinExternalMessages = (
|
4726
|
+
var joinExternalMessages = (messages2) => {
|
4495
4727
|
const assistantMessage = {
|
4496
4728
|
role: "assistant",
|
4497
4729
|
content: []
|
4498
4730
|
};
|
4499
|
-
for (const output of
|
4731
|
+
for (const output of messages2) {
|
4500
4732
|
if (output.role === "tool") {
|
4501
4733
|
const toolCallIdx = assistantMessage.content.findIndex(
|
4502
4734
|
(c) => c.type === "tool-call" && c.toolCallId === output.toolCallId
|
@@ -4573,7 +4805,7 @@ var chunkExternalMessages = (callbackResults) => {
|
|
4573
4805
|
};
|
4574
4806
|
var useExternalMessageConverter = ({
|
4575
4807
|
callback,
|
4576
|
-
messages,
|
4808
|
+
messages: messages2,
|
4577
4809
|
isRunning
|
4578
4810
|
}) => {
|
4579
4811
|
const state = _react.useMemo.call(void 0,
|
@@ -4587,7 +4819,7 @@ var useExternalMessageConverter = ({
|
|
4587
4819
|
);
|
4588
4820
|
return _react.useMemo.call(void 0, () => {
|
4589
4821
|
const callbackResults = [];
|
4590
|
-
for (const message of
|
4822
|
+
for (const message of messages2) {
|
4591
4823
|
let result = state.callbackCache.get(message);
|
4592
4824
|
if (!result) {
|
4593
4825
|
const output = state.callback(message);
|
@@ -4625,7 +4857,7 @@ var useExternalMessageConverter = ({
|
|
4625
4857
|
return newMessage;
|
4626
4858
|
}
|
4627
4859
|
);
|
4628
|
-
}, [state,
|
4860
|
+
}, [state, messages2, isRunning]);
|
4629
4861
|
};
|
4630
4862
|
var shallowArrayEqual = (a, b) => {
|
4631
4863
|
if (a.length !== b.length) return false;
|
@@ -4643,13 +4875,13 @@ var DangerousInBrowserAdapter = class {
|
|
4643
4875
|
constructor(options) {
|
4644
4876
|
this.options = options;
|
4645
4877
|
}
|
4646
|
-
async *run({ messages, abortSignal, config }) {
|
4878
|
+
async *run({ messages: messages2, abortSignal, config }) {
|
4647
4879
|
const res = await _chunk5KIEXJRKjs.getEdgeRuntimeStream.call(void 0, {
|
4648
4880
|
options: this.options,
|
4649
4881
|
abortSignal,
|
4650
4882
|
requestData: {
|
4651
4883
|
system: config.system,
|
4652
|
-
messages: _chunk5KIEXJRKjs.toCoreMessages.call(void 0,
|
4884
|
+
messages: _chunk5KIEXJRKjs.toCoreMessages.call(void 0, messages2),
|
4653
4885
|
tools: config.tools ? _chunk5KIEXJRKjs.toLanguageModelTools.call(void 0, config.tools) : [],
|
4654
4886
|
...config.callSettings,
|
4655
4887
|
...config.config
|
@@ -4713,19 +4945,22 @@ var WebSpeechSynthesisAdapter = class {
|
|
4713
4945
|
};
|
4714
4946
|
|
4715
4947
|
// src/runtimes/attachment/SimpleImageAttachmentAdapter.ts
|
4716
|
-
var SimpleImageAttachmentAdapter = (
|
4717
|
-
|
4948
|
+
var SimpleImageAttachmentAdapter = (_class16 = class {constructor() { _class16.prototype.__init40.call(this); }
|
4949
|
+
__init40() {this.accept = "image/*"}
|
4718
4950
|
async add(state) {
|
4719
4951
|
return {
|
4720
4952
|
id: state.file.name,
|
4721
4953
|
type: "image",
|
4722
4954
|
name: state.file.name,
|
4723
|
-
|
4955
|
+
contentType: state.file.type,
|
4956
|
+
file: state.file,
|
4957
|
+
status: { type: "requires-action", reason: "composer-send" }
|
4724
4958
|
};
|
4725
4959
|
}
|
4726
4960
|
async send(attachment) {
|
4727
4961
|
return {
|
4728
4962
|
...attachment,
|
4963
|
+
status: { type: "complete" },
|
4729
4964
|
content: [
|
4730
4965
|
{
|
4731
4966
|
type: "image",
|
@@ -4736,7 +4971,7 @@ var SimpleImageAttachmentAdapter = (_class12 = class {constructor() { _class12.p
|
|
4736
4971
|
}
|
4737
4972
|
async remove() {
|
4738
4973
|
}
|
4739
|
-
},
|
4974
|
+
}, _class16);
|
4740
4975
|
var getFileDataURL = (file) => new Promise((resolve, reject) => {
|
4741
4976
|
const reader = new FileReader();
|
4742
4977
|
reader.onload = () => resolve(reader.result);
|
@@ -4745,19 +4980,22 @@ var getFileDataURL = (file) => new Promise((resolve, reject) => {
|
|
4745
4980
|
});
|
4746
4981
|
|
4747
4982
|
// src/runtimes/attachment/SimpleTextAttachmentAdapter.ts
|
4748
|
-
var SimpleTextAttachmentAdapter = (
|
4749
|
-
|
4983
|
+
var SimpleTextAttachmentAdapter = (_class17 = class {constructor() { _class17.prototype.__init41.call(this); }
|
4984
|
+
__init41() {this.accept = "text/plain,text/html,text/markdown,text/csv,text/xml,text/json,text/css"}
|
4750
4985
|
async add(state) {
|
4751
4986
|
return {
|
4752
4987
|
id: state.file.name,
|
4753
4988
|
type: "document",
|
4754
4989
|
name: state.file.name,
|
4755
|
-
|
4990
|
+
contentType: state.file.type,
|
4991
|
+
file: state.file,
|
4992
|
+
status: { type: "requires-action", reason: "composer-send" }
|
4756
4993
|
};
|
4757
4994
|
}
|
4758
4995
|
async send(attachment) {
|
4759
4996
|
return {
|
4760
4997
|
...attachment,
|
4998
|
+
status: { type: "complete" },
|
4761
4999
|
content: [
|
4762
5000
|
{
|
4763
5001
|
type: "text",
|
@@ -4770,7 +5008,7 @@ ${await getFileText(attachment.file)}
|
|
4770
5008
|
}
|
4771
5009
|
async remove() {
|
4772
5010
|
}
|
4773
|
-
},
|
5011
|
+
}, _class17);
|
4774
5012
|
var getFileText = (file) => new Promise((resolve, reject) => {
|
4775
5013
|
const reader = new FileReader();
|
4776
5014
|
reader.onload = () => resolve(reader.result);
|
@@ -4840,7 +5078,14 @@ var CompositeAttachmentAdapter = class {
|
|
4840
5078
|
async remove(attachment) {
|
4841
5079
|
const adapters = this._adapters.slice();
|
4842
5080
|
for (const adapter of adapters) {
|
4843
|
-
if (fileMatchesAccept(
|
5081
|
+
if (fileMatchesAccept(
|
5082
|
+
{
|
5083
|
+
name: attachment.name,
|
5084
|
+
type: _nullishCoalesce(attachment.contentType, () => ( "unknown/unknown"))
|
5085
|
+
// TODO remove after 0.6.0
|
5086
|
+
},
|
5087
|
+
adapter.accept
|
5088
|
+
)) {
|
4844
5089
|
return adapter.remove(attachment);
|
4845
5090
|
}
|
4846
5091
|
}
|
@@ -4864,7 +5109,7 @@ var ThreadConfigProvider = ({
|
|
4864
5109
|
}) => {
|
4865
5110
|
const hasAssistant = !!useAssistantRuntime({ optional: true });
|
4866
5111
|
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 });
|
4867
|
-
if (!_optionalChain([config, 'optionalAccess',
|
5112
|
+
if (!_optionalChain([config, 'optionalAccess', _253 => _253.runtime])) return configProvider;
|
4868
5113
|
if (hasAssistant) {
|
4869
5114
|
throw new Error(
|
4870
5115
|
"You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
|
@@ -5058,7 +5303,7 @@ var useAllowBranchPicker = (ensureCapability = false) => {
|
|
5058
5303
|
return allowBranchPicker && (!ensureCapability || branchPickerSupported);
|
5059
5304
|
};
|
5060
5305
|
var BranchPicker = () => {
|
5061
|
-
const allowBranchPicker = useAllowBranchPicker();
|
5306
|
+
const allowBranchPicker = useAllowBranchPicker(true);
|
5062
5307
|
if (!allowBranchPicker) return null;
|
5063
5308
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, BranchPickerRoot, { hideWhenSingleBranch: true, children: [
|
5064
5309
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, BranchPickerPrevious2, {}),
|
@@ -5192,7 +5437,7 @@ var AssistantMessageContent = _react.forwardRef.call(void 0, ({ components: comp
|
|
5192
5437
|
{
|
5193
5438
|
components: {
|
5194
5439
|
...componentsProp,
|
5195
|
-
Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess',
|
5440
|
+
Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _254 => _254.Text]), () => ( components.Text)), () => ( content_part_default.Text)),
|
5196
5441
|
tools: toolsComponents
|
5197
5442
|
}
|
5198
5443
|
}
|
@@ -5247,7 +5492,7 @@ var ComposerAttachmentRoot = withDefaults("div", {
|
|
5247
5492
|
});
|
5248
5493
|
ComposerAttachmentRoot.displayName = "ComposerAttachmentRoot";
|
5249
5494
|
var ComposerAttachment2 = () => {
|
5250
|
-
const attachment =
|
5495
|
+
const attachment = useThreadComposerAttachment((a) => a.attachment);
|
5251
5496
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, ComposerAttachmentRoot, { children: [
|
5252
5497
|
".",
|
5253
5498
|
attachment.name.split(".").pop(),
|
@@ -5261,10 +5506,9 @@ var ComposerAttachmentRemove = _react.forwardRef.call(void 0, (props, ref) => {
|
|
5261
5506
|
composer: { removeAttachment: { tooltip = "Remove file" } = {} } = {}
|
5262
5507
|
} = {}
|
5263
5508
|
} = useThreadConfig();
|
5264
|
-
const
|
5265
|
-
const attachmentStore = useAttachmentStore();
|
5509
|
+
const attachmentRuntime = useAttachmentRuntime();
|
5266
5510
|
const handleRemoveAttachment = () => {
|
5267
|
-
|
5511
|
+
attachmentRuntime.remove();
|
5268
5512
|
};
|
5269
5513
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
5270
5514
|
TooltipIconButton,
|
@@ -5335,7 +5579,7 @@ var ComposerAttachments = ({ components }) => {
|
|
5335
5579
|
{
|
5336
5580
|
components: {
|
5337
5581
|
...components,
|
5338
|
-
Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5582
|
+
Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _255 => _255.Attachment]), () => ( composer_attachment_default))
|
5339
5583
|
}
|
5340
5584
|
}
|
5341
5585
|
) });
|
@@ -5467,7 +5711,7 @@ var ThreadWelcomeSuggestion = ({
|
|
5467
5711
|
};
|
5468
5712
|
var ThreadWelcomeSuggestions = () => {
|
5469
5713
|
const { welcome: { suggestions } = {} } = useThreadConfig();
|
5470
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([suggestions, 'optionalAccess',
|
5714
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([suggestions, 'optionalAccess', _256 => _256.map, 'call', _257 => _257((suggestion, idx) => {
|
5471
5715
|
const key = `${suggestion.prompt}-${idx}`;
|
5472
5716
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestion, { suggestion }, key);
|
5473
5717
|
})]) });
|
@@ -5566,7 +5810,7 @@ var UserMessageContent = _react.forwardRef.call(void 0,
|
|
5566
5810
|
{
|
5567
5811
|
components: {
|
5568
5812
|
...components,
|
5569
|
-
Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5813
|
+
Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _258 => _258.Text]), () => ( content_part_default.Text))
|
5570
5814
|
}
|
5571
5815
|
}
|
5572
5816
|
) });
|
@@ -5584,7 +5828,7 @@ var UserMessageAttachments = ({
|
|
5584
5828
|
{
|
5585
5829
|
components: {
|
5586
5830
|
...components,
|
5587
|
-
Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5831
|
+
Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _259 => _259.Attachment]), () => ( user_message_attachment_default))
|
5588
5832
|
}
|
5589
5833
|
}
|
5590
5834
|
) }) });
|
@@ -5685,10 +5929,10 @@ var ThreadMessages = ({ components, ...rest }) => {
|
|
5685
5929
|
thread_exports.Messages,
|
5686
5930
|
{
|
5687
5931
|
components: {
|
5688
|
-
UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5689
|
-
EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5690
|
-
AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5691
|
-
SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
5932
|
+
UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _260 => _260.UserMessage]), () => ( user_message_default)),
|
5933
|
+
EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _261 => _261.EditComposer]), () => ( edit_composer_default)),
|
5934
|
+
AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _262 => _262.AssistantMessage]), () => ( assistant_message_default)),
|
5935
|
+
SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _263 => _263.SystemMessage]), () => ( SystemMessage))
|
5692
5936
|
},
|
5693
5937
|
...rest
|
5694
5938
|
}
|
@@ -5908,5 +6152,7 @@ var assistant_modal_default = Object.assign(AssistantModal, exports13);
|
|
5908
6152
|
|
5909
6153
|
|
5910
6154
|
|
5911
|
-
|
6155
|
+
|
6156
|
+
|
6157
|
+
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.useComposerRuntime = useComposerRuntime; exports.useComposerSend = useComposerSend; exports.useComposerStore = useComposerStore; exports.useContentPart = useContentPart; exports.useContentPartContext = useContentPartContext; exports.useContentPartDisplay = useContentPartDisplay; exports.useContentPartImage = useContentPartImage; exports.useContentPartRuntime = useContentPartRuntime; 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;
|
5912
6158
|
//# sourceMappingURL=index.js.map
|