@assistant-ui/react 0.5.24 → 0.5.26
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +75 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -24
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css +11 -4
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/tailwindcss/base-components.css +1 -1
- package/package.json +7 -7
- package/README.md +0 -34
package/dist/index.d.mts
CHANGED
@@ -125,7 +125,6 @@ declare class LocalThreadRuntime implements ThreadRuntime {
|
|
125
125
|
}>;
|
126
126
|
readonly isDisabled = false;
|
127
127
|
get messages(): ThreadMessage[];
|
128
|
-
get isRunning(): boolean;
|
129
128
|
constructor(configProvider: ModelConfigProvider, adapter: ChatModelAdapter, options?: LocalRuntimeOptions | undefined);
|
130
129
|
getBranches(messageId: string): string[];
|
131
130
|
switchToBranch(branchId: string): void;
|
@@ -551,7 +550,6 @@ declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
|
|
551
550
|
};
|
552
551
|
messages: ThreadMessage[];
|
553
552
|
isDisabled: boolean;
|
554
|
-
isRunning: boolean;
|
555
553
|
converter: ThreadMessageConverter;
|
556
554
|
private _store;
|
557
555
|
constructor(store: ExternalStoreAdapter<any>);
|
@@ -603,7 +601,8 @@ type ThreadActionsState = Readonly<{
|
|
603
601
|
addToolResult: (options: AddToolResultOptions) => void;
|
604
602
|
}>;
|
605
603
|
|
606
|
-
type ThreadRuntime = Readonly<
|
604
|
+
type ThreadRuntime = Readonly<Omit<ThreadActionsState, "getRuntime"> & {
|
605
|
+
isDisabled: boolean;
|
607
606
|
messages: readonly ThreadMessage[];
|
608
607
|
subscribe: (callback: () => void) => Unsubscribe;
|
609
608
|
}>;
|
@@ -654,6 +653,7 @@ declare function useAssistantContext(options: {
|
|
654
653
|
type ThreadState = Readonly<{
|
655
654
|
isRunning: boolean;
|
656
655
|
isDisabled: boolean;
|
656
|
+
unstable_canAppendNew: boolean;
|
657
657
|
}>;
|
658
658
|
|
659
659
|
type ThreadViewportState = Readonly<{
|
package/dist/index.d.ts
CHANGED
@@ -125,7 +125,6 @@ declare class LocalThreadRuntime implements ThreadRuntime {
|
|
125
125
|
}>;
|
126
126
|
readonly isDisabled = false;
|
127
127
|
get messages(): ThreadMessage[];
|
128
|
-
get isRunning(): boolean;
|
129
128
|
constructor(configProvider: ModelConfigProvider, adapter: ChatModelAdapter, options?: LocalRuntimeOptions | undefined);
|
130
129
|
getBranches(messageId: string): string[];
|
131
130
|
switchToBranch(branchId: string): void;
|
@@ -551,7 +550,6 @@ declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
|
|
551
550
|
};
|
552
551
|
messages: ThreadMessage[];
|
553
552
|
isDisabled: boolean;
|
554
|
-
isRunning: boolean;
|
555
553
|
converter: ThreadMessageConverter;
|
556
554
|
private _store;
|
557
555
|
constructor(store: ExternalStoreAdapter<any>);
|
@@ -603,7 +601,8 @@ type ThreadActionsState = Readonly<{
|
|
603
601
|
addToolResult: (options: AddToolResultOptions) => void;
|
604
602
|
}>;
|
605
603
|
|
606
|
-
type ThreadRuntime = Readonly<
|
604
|
+
type ThreadRuntime = Readonly<Omit<ThreadActionsState, "getRuntime"> & {
|
605
|
+
isDisabled: boolean;
|
607
606
|
messages: readonly ThreadMessage[];
|
608
607
|
subscribe: (callback: () => void) => Unsubscribe;
|
609
608
|
}>;
|
@@ -654,6 +653,7 @@ declare function useAssistantContext(options: {
|
|
654
653
|
type ThreadState = Readonly<{
|
655
654
|
isRunning: boolean;
|
656
655
|
isDisabled: boolean;
|
656
|
+
unstable_canAppendNew: boolean;
|
657
657
|
}>;
|
658
658
|
|
659
659
|
type ThreadViewportState = Readonly<{
|
package/dist/index.js
CHANGED
@@ -159,11 +159,23 @@ var makeComposerStore = (useThreadMessages, useThreadActions) => {
|
|
159
159
|
|
160
160
|
// src/context/stores/Thread.ts
|
161
161
|
|
162
|
+
var getThreadStateFromRuntime = (runtime) => {
|
163
|
+
const lastMessage = runtime.messages.at(-1);
|
164
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _11 => _11.role]) !== "assistant")
|
165
|
+
return Object.freeze({
|
166
|
+
isDisabled: runtime.isDisabled,
|
167
|
+
isRunning: false,
|
168
|
+
unstable_canAppendNew: !runtime.isDisabled
|
169
|
+
});
|
170
|
+
return Object.freeze({
|
171
|
+
isDisabled: runtime.isDisabled,
|
172
|
+
isRunning: lastMessage.status.type === "running",
|
173
|
+
unstable_canAppendNew: !runtime.isDisabled && lastMessage.status.type !== "running" && lastMessage.status.type !== "requires-action"
|
174
|
+
});
|
175
|
+
};
|
162
176
|
var makeThreadStore = (runtimeRef) => {
|
163
|
-
|
164
|
-
|
165
|
-
isRunning: runtimeRef.getState().isRunning
|
166
|
-
}));
|
177
|
+
const runtime = runtimeRef.getState();
|
178
|
+
return _zustand.create.call(void 0, () => getThreadStateFromRuntime(runtime));
|
167
179
|
};
|
168
180
|
|
169
181
|
// src/context/stores/ThreadViewport.tsx
|
@@ -260,13 +272,11 @@ var ThreadProvider = ({
|
|
260
272
|
_react.useCallback.call(void 0,
|
261
273
|
(thread) => {
|
262
274
|
const onThreadUpdate = () => {
|
263
|
-
const
|
264
|
-
|
275
|
+
const oldState = context.useThread.getState();
|
276
|
+
const state = getThreadStateFromRuntime(thread);
|
277
|
+
if (oldState.isDisabled !== state.isDisabled || oldState.isRunning !== state.isRunning || oldState.unstable_canAppendNew !== state.unstable_canAppendNew) {
|
265
278
|
context.useThread.setState(
|
266
|
-
|
267
|
-
isRunning: thread.isRunning,
|
268
|
-
isDisabled: thread.isDisabled
|
269
|
-
}),
|
279
|
+
getThreadStateFromRuntime(thread),
|
270
280
|
true
|
271
281
|
);
|
272
282
|
}
|
@@ -344,7 +354,7 @@ var AssistantRuntimeProvider = _react.memo.call(void 0, AssistantRuntimeProvider
|
|
344
354
|
var MessageContext = _react.createContext.call(void 0, null);
|
345
355
|
function useMessageContext(options) {
|
346
356
|
const context = _react.useContext.call(void 0, MessageContext);
|
347
|
-
if (!_optionalChain([options, 'optionalAccess',
|
357
|
+
if (!_optionalChain([options, 'optionalAccess', _12 => _12.optional]) && !context)
|
348
358
|
throw new Error(
|
349
359
|
"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
|
350
360
|
);
|
@@ -371,7 +381,7 @@ var ContentPartContext = _react.createContext.call(void 0,
|
|
371
381
|
);
|
372
382
|
function useContentPartContext(options) {
|
373
383
|
const context = _react.useContext.call(void 0, ContentPartContext);
|
374
|
-
if (!_optionalChain([options, 'optionalAccess',
|
384
|
+
if (!_optionalChain([options, 'optionalAccess', _13 => _13.optional]) && !context)
|
375
385
|
throw new Error(
|
376
386
|
"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
|
377
387
|
);
|
@@ -383,13 +393,13 @@ function useContentPartContext(options) {
|
|
383
393
|
var toAppendMessage = (useThreadMessages, message) => {
|
384
394
|
if (typeof message === "string") {
|
385
395
|
return {
|
386
|
-
parentId: _nullishCoalesce(_optionalChain([useThreadMessages, 'access',
|
396
|
+
parentId: _nullishCoalesce(_optionalChain([useThreadMessages, 'access', _14 => _14.getState, 'call', _15 => _15(), 'access', _16 => _16.at, 'call', _17 => _17(-1), 'optionalAccess', _18 => _18.id]), () => ( null)),
|
387
397
|
role: "user",
|
388
398
|
content: [{ type: "text", text: message }]
|
389
399
|
};
|
390
400
|
}
|
391
401
|
return {
|
392
|
-
parentId: _nullishCoalesce(_nullishCoalesce(message.parentId, () => ( _optionalChain([useThreadMessages, 'access',
|
402
|
+
parentId: _nullishCoalesce(_nullishCoalesce(message.parentId, () => ( _optionalChain([useThreadMessages, 'access', _19 => _19.getState, 'call', _20 => _20(), 'access', _21 => _21.at, 'call', _22 => _22(-1), 'optionalAccess', _23 => _23.id]))), () => ( null)),
|
393
403
|
role: _nullishCoalesce(message.role, () => ( "user")),
|
394
404
|
content: message.content
|
395
405
|
};
|
@@ -441,7 +451,7 @@ var useAssistantTool = (tool) => {
|
|
441
451
|
const unsub2 = render ? setToolUI(toolName, render) : void 0;
|
442
452
|
return () => {
|
443
453
|
unsub1();
|
444
|
-
_optionalChain([unsub2, 'optionalCall',
|
454
|
+
_optionalChain([unsub2, 'optionalCall', _24 => _24()]);
|
445
455
|
};
|
446
456
|
}, [registerModelConfigProvider, setToolUI, tool]);
|
447
457
|
};
|
@@ -520,8 +530,8 @@ var useCombinedStore = (stores, selector) => {
|
|
520
530
|
return useCombined(selector);
|
521
531
|
};
|
522
532
|
|
523
|
-
// src/utils/
|
524
|
-
var
|
533
|
+
// src/utils/getThreadMessageText.tsx
|
534
|
+
var getThreadMessageText = (message) => {
|
525
535
|
const textParts = message.content.filter(
|
526
536
|
(part) => part.type === "text"
|
527
537
|
);
|
@@ -543,7 +553,7 @@ var useActionBarCopy = ({
|
|
543
553
|
const { message } = useMessage.getState();
|
544
554
|
const { setIsCopied } = useMessageUtils.getState();
|
545
555
|
const { isEditing, value: composerValue } = useEditComposer.getState();
|
546
|
-
const valueToCopy = isEditing ? composerValue :
|
556
|
+
const valueToCopy = isEditing ? composerValue : getThreadMessageText(message);
|
547
557
|
navigator.clipboard.writeText(valueToCopy).then(() => {
|
548
558
|
setIsCopied(true);
|
549
559
|
setTimeout(() => setIsCopied(false), copiedDuration);
|
@@ -670,7 +680,7 @@ var useComposerSend = () => {
|
|
670
680
|
const { useComposer } = useComposerContext();
|
671
681
|
const disabled = useCombinedStore(
|
672
682
|
[useThread, useComposer],
|
673
|
-
(t, c) => t.
|
683
|
+
(t, c) => !t.unstable_canAppendNew || !c.isEditing || c.value.length === 0
|
674
684
|
);
|
675
685
|
const callback = _react.useCallback.call(void 0, () => {
|
676
686
|
const composerState = useComposer.getState();
|
@@ -878,7 +888,7 @@ var createActionButton = (displayName, useActionButton, forwardProps = []) => {
|
|
878
888
|
...primitiveProps,
|
879
889
|
ref: forwardedRef,
|
880
890
|
onClick: _primitive.composeEventHandlers.call(void 0, primitiveProps.onClick, () => {
|
881
|
-
_optionalChain([callback, 'optionalCall',
|
891
|
+
_optionalChain([callback, 'optionalCall', _25 => _25()]);
|
882
892
|
})
|
883
893
|
}
|
884
894
|
);
|
@@ -1166,7 +1176,7 @@ var getContentPartState = ({ message }, useContentPart, partIndex) => {
|
|
1166
1176
|
}
|
1167
1177
|
}
|
1168
1178
|
const status = toContentPartStatus(message, partIndex, part);
|
1169
|
-
const currentState = _optionalChain([useContentPart, 'optionalAccess',
|
1179
|
+
const currentState = _optionalChain([useContentPart, 'optionalAccess', _26 => _26.getState, 'call', _27 => _27()]);
|
1170
1180
|
if (currentState && currentState.part === part && currentState.status === status)
|
1171
1181
|
return null;
|
1172
1182
|
return Object.freeze({ part, status });
|
@@ -1242,7 +1252,7 @@ var withSmoothContextProvider = (Component) => {
|
|
1242
1252
|
};
|
1243
1253
|
function useSmoothContext(options) {
|
1244
1254
|
const context = _react.useContext.call(void 0, SmoothContext);
|
1245
|
-
if (!_optionalChain([options, 'optionalAccess',
|
1255
|
+
if (!_optionalChain([options, 'optionalAccess', _28 => _28.optional]) && !context)
|
1246
1256
|
throw new Error(
|
1247
1257
|
"This component must be used within a SmoothContextProvider."
|
1248
1258
|
);
|
@@ -1313,7 +1323,7 @@ var useSmooth = (state, smooth = false) => {
|
|
1313
1323
|
const [displayedText, setDisplayedText] = _react.useState.call(void 0, text);
|
1314
1324
|
const setText = _reactusecallbackref.useCallbackRef.call(void 0, (text2) => {
|
1315
1325
|
setDisplayedText(text2);
|
1316
|
-
_optionalChain([useSmoothStatus2, 'optionalAccess',
|
1326
|
+
_optionalChain([useSmoothStatus2, 'optionalAccess', _29 => _29.setState, 'call', _30 => _30(text2 !== state.part.text ? SMOOTH_STATUS : state.status)]);
|
1317
1327
|
});
|
1318
1328
|
const [animatorRef] = _react.useState.call(void 0,
|
1319
1329
|
new TextStreamAnimator(text, setText)
|
@@ -1457,7 +1467,7 @@ var MessageContentPartImpl = ({
|
|
1457
1467
|
};
|
1458
1468
|
var MessageContentPart = _react.memo.call(void 0,
|
1459
1469
|
MessageContentPartImpl,
|
1460
|
-
(prev, next) => prev.partIndex === next.partIndex && _optionalChain([prev, 'access',
|
1470
|
+
(prev, next) => prev.partIndex === next.partIndex && _optionalChain([prev, 'access', _31 => _31.components, 'optionalAccess', _32 => _32.Text]) === _optionalChain([next, 'access', _33 => _33.components, 'optionalAccess', _34 => _34.Text]) && _optionalChain([prev, 'access', _35 => _35.components, 'optionalAccess', _36 => _36.Image]) === _optionalChain([next, 'access', _37 => _37.components, 'optionalAccess', _38 => _38.Image]) && _optionalChain([prev, 'access', _39 => _39.components, 'optionalAccess', _40 => _40.UI]) === _optionalChain([next, 'access', _41 => _41.components, 'optionalAccess', _42 => _42.UI]) && _optionalChain([prev, 'access', _43 => _43.components, 'optionalAccess', _44 => _44.tools]) === _optionalChain([next, 'access', _45 => _45.components, 'optionalAccess', _46 => _46.tools])
|
1461
1471
|
);
|
1462
1472
|
var MessagePrimitiveContent = ({
|
1463
1473
|
components
|
@@ -1568,10 +1578,10 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
|
|
1568
1578
|
const handleKeyPress = (e) => {
|
1569
1579
|
if (isDisabled) return;
|
1570
1580
|
if (e.key === "Enter" && e.shiftKey === false) {
|
1571
|
-
const
|
1572
|
-
if (
|
1581
|
+
const { unstable_canAppendNew } = useThread.getState();
|
1582
|
+
if (unstable_canAppendNew) {
|
1573
1583
|
e.preventDefault();
|
1574
|
-
_optionalChain([textareaRef, 'access',
|
1584
|
+
_optionalChain([textareaRef, 'access', _47 => _47.current, 'optionalAccess', _48 => _48.closest, 'call', _49 => _49("form"), 'optionalAccess', _50 => _50.requestSubmit, 'call', _51 => _51()]);
|
1575
1585
|
}
|
1576
1586
|
}
|
1577
1587
|
};
|
@@ -1865,15 +1875,15 @@ var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => ({
|
|
1865
1875
|
// src/context/providers/MessageProvider.tsx
|
1866
1876
|
|
1867
1877
|
var getIsLast = (messages, message) => {
|
1868
|
-
return _optionalChain([messages, 'access',
|
1878
|
+
return _optionalChain([messages, 'access', _52 => _52[messages.length - 1], 'optionalAccess', _53 => _53.id]) === message.id;
|
1869
1879
|
};
|
1870
1880
|
var getMessageState = (messages, getBranches, useMessage, messageIndex) => {
|
1871
|
-
const parentId = _nullishCoalesce(_optionalChain([messages, 'access',
|
1881
|
+
const parentId = _nullishCoalesce(_optionalChain([messages, 'access', _54 => _54[messageIndex - 1], 'optionalAccess', _55 => _55.id]), () => ( null));
|
1872
1882
|
const message = messages[messageIndex];
|
1873
1883
|
if (!message) return null;
|
1874
1884
|
const isLast = getIsLast(messages, message);
|
1875
1885
|
const branches = getBranches(message.id);
|
1876
|
-
const currentState = _optionalChain([useMessage, 'optionalAccess',
|
1886
|
+
const currentState = _optionalChain([useMessage, 'optionalAccess', _56 => _56.getState, 'call', _57 => _57()]);
|
1877
1887
|
if (currentState && currentState.message === message && currentState.parentId === parentId && currentState.branches === branches && currentState.isLast === isLast)
|
1878
1888
|
return null;
|
1879
1889
|
return Object.freeze({
|
@@ -1902,7 +1912,7 @@ var useMessageContext2 = (messageIndex) => {
|
|
1902
1912
|
throw new Error(
|
1903
1913
|
"Tried to edit a non-user message. Editing is only supported for user messages. This is likely an internal bug in assistant-ui."
|
1904
1914
|
);
|
1905
|
-
const text =
|
1915
|
+
const text = getThreadMessageText(message);
|
1906
1916
|
return text;
|
1907
1917
|
},
|
1908
1918
|
onSend: (text) => {
|
@@ -2000,7 +2010,7 @@ var ThreadPrimitiveMessagesImpl = ({
|
|
2000
2010
|
ThreadPrimitiveMessagesImpl.displayName = "ThreadPrimitive.Messages";
|
2001
2011
|
var ThreadPrimitiveMessages = _react.memo.call(void 0,
|
2002
2012
|
ThreadPrimitiveMessagesImpl,
|
2003
|
-
(prev, next) => _optionalChain([prev, 'access',
|
2013
|
+
(prev, next) => _optionalChain([prev, 'access', _58 => _58.components, 'optionalAccess', _59 => _59.Message]) === _optionalChain([next, 'access', _60 => _60.components, 'optionalAccess', _61 => _61.Message]) && _optionalChain([prev, 'access', _62 => _62.components, 'optionalAccess', _63 => _63.UserMessage]) === _optionalChain([next, 'access', _64 => _64.components, 'optionalAccess', _65 => _65.UserMessage]) && _optionalChain([prev, 'access', _66 => _66.components, 'optionalAccess', _67 => _67.EditComposer]) === _optionalChain([next, 'access', _68 => _68.components, 'optionalAccess', _69 => _69.EditComposer]) && _optionalChain([prev, 'access', _70 => _70.components, 'optionalAccess', _71 => _71.AssistantMessage]) === _optionalChain([next, 'access', _72 => _72.components, 'optionalAccess', _73 => _73.AssistantMessage]) && _optionalChain([prev, 'access', _74 => _74.components, 'optionalAccess', _75 => _75.SystemMessage]) === _optionalChain([next, 'access', _76 => _76.components, 'optionalAccess', _77 => _77.SystemMessage])
|
2004
2014
|
);
|
2005
2015
|
|
2006
2016
|
// src/primitives/thread/ThreadScrollToBottom.tsx
|
@@ -2132,7 +2142,7 @@ var MessageRepository = (_class4 = class {constructor() { _class4.prototype.__in
|
|
2132
2142
|
parentOrRoot.children = parentOrRoot.children.filter(
|
2133
2143
|
(m) => m !== child.current.id
|
2134
2144
|
);
|
2135
|
-
if (_optionalChain([child, 'access',
|
2145
|
+
if (_optionalChain([child, 'access', _78 => _78.prev, 'optionalAccess', _79 => _79.next]) === child) {
|
2136
2146
|
const fallbackId = child.prev.children.at(-1);
|
2137
2147
|
const fallback = fallbackId ? this.messages.get(fallbackId) : null;
|
2138
2148
|
if (fallback === void 0) {
|
@@ -2162,7 +2172,7 @@ var MessageRepository = (_class4 = class {constructor() { _class4.prototype.__in
|
|
2162
2172
|
}
|
2163
2173
|
}
|
2164
2174
|
getMessages() {
|
2165
|
-
const messages = new Array(_nullishCoalesce(_optionalChain([this, 'access',
|
2175
|
+
const messages = new Array(_nullishCoalesce(_optionalChain([this, 'access', _80 => _80.head, 'optionalAccess', _81 => _81.level]), () => ( 0)));
|
2166
2176
|
for (let current = this.head; current; current = current.prev) {
|
2167
2177
|
messages[current.level] = current.current;
|
2168
2178
|
}
|
@@ -2200,7 +2210,7 @@ var MessageRepository = (_class4 = class {constructor() { _class4.prototype.__in
|
|
2200
2210
|
"MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui."
|
2201
2211
|
);
|
2202
2212
|
return {
|
2203
|
-
parentId: _nullishCoalesce(_optionalChain([message, 'access',
|
2213
|
+
parentId: _nullishCoalesce(_optionalChain([message, 'access', _82 => _82.prev, 'optionalAccess', _83 => _83.current, 'access', _84 => _84.id]), () => ( null)),
|
2204
2214
|
message: message.current
|
2205
2215
|
};
|
2206
2216
|
}
|
@@ -2285,11 +2295,11 @@ var MessageRepository = (_class4 = class {constructor() { _class4.prototype.__in
|
|
2285
2295
|
for (const [, message] of this.messages) {
|
2286
2296
|
exportItems.push({
|
2287
2297
|
message: message.current,
|
2288
|
-
parentId: _nullishCoalesce(_optionalChain([message, 'access',
|
2298
|
+
parentId: _nullishCoalesce(_optionalChain([message, 'access', _85 => _85.prev, 'optionalAccess', _86 => _86.current, 'access', _87 => _87.id]), () => ( null))
|
2289
2299
|
});
|
2290
2300
|
}
|
2291
2301
|
return {
|
2292
|
-
headId: _nullishCoalesce(_optionalChain([this, 'access',
|
2302
|
+
headId: _nullishCoalesce(_optionalChain([this, 'access', _88 => _88.head, 'optionalAccess', _89 => _89.current, 'access', _90 => _90.id]), () => ( null)),
|
2293
2303
|
messages: exportItems
|
2294
2304
|
};
|
2295
2305
|
}
|
@@ -2297,7 +2307,7 @@ var MessageRepository = (_class4 = class {constructor() { _class4.prototype.__in
|
|
2297
2307
|
for (const { message, parentId } of messages) {
|
2298
2308
|
this.addOrUpdateMessage(parentId, message);
|
2299
2309
|
}
|
2300
|
-
this.resetHead(_nullishCoalesce(_nullishCoalesce(headId, () => ( _optionalChain([messages, 'access',
|
2310
|
+
this.resetHead(_nullishCoalesce(_nullishCoalesce(headId, () => ( _optionalChain([messages, 'access', _91 => _91.at, 'call', _92 => _92(-1), 'optionalAccess', _93 => _93.message, 'access', _94 => _94.id]))), () => ( null)));
|
2301
2311
|
}
|
2302
2312
|
}, _class4);
|
2303
2313
|
|
@@ -2460,7 +2470,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
2460
2470
|
});
|
2461
2471
|
if (mergeRoundtrips) {
|
2462
2472
|
const previousMessage = messages[messages.length - 1];
|
2463
|
-
if (_optionalChain([previousMessage, 'optionalAccess',
|
2473
|
+
if (_optionalChain([previousMessage, 'optionalAccess', _95 => _95.role]) === "assistant") {
|
2464
2474
|
previousMessage.content.push(...newContent);
|
2465
2475
|
break;
|
2466
2476
|
}
|
@@ -2473,7 +2483,7 @@ var fromLanguageModelMessages = (lm, { mergeRoundtrips }) => {
|
|
2473
2483
|
}
|
2474
2484
|
case "tool": {
|
2475
2485
|
const previousMessage = messages[messages.length - 1];
|
2476
|
-
if (_optionalChain([previousMessage, 'optionalAccess',
|
2486
|
+
if (_optionalChain([previousMessage, 'optionalAccess', _96 => _96.role]) !== "assistant")
|
2477
2487
|
throw new Error(
|
2478
2488
|
"A tool message must be preceded by an assistant message."
|
2479
2489
|
);
|
@@ -2677,7 +2687,7 @@ var useEdgeRuntime = ({
|
|
2677
2687
|
};
|
2678
2688
|
|
2679
2689
|
// src/runtimes/local/shouldContinue.tsx
|
2680
|
-
var shouldContinue = (result) => _optionalChain([result, 'access',
|
2690
|
+
var shouldContinue = (result) => _optionalChain([result, 'access', _97 => _97.status, 'optionalAccess', _98 => _98.type]) === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
|
2681
2691
|
|
2682
2692
|
// src/runtimes/local/LocalThreadRuntime.tsx
|
2683
2693
|
var CAPABILITIES = Object.freeze({
|
@@ -2692,7 +2702,7 @@ var LocalThreadRuntime = (_class5 = class {
|
|
2692
2702
|
this.configProvider = configProvider;
|
2693
2703
|
this.adapter = adapter;
|
2694
2704
|
this.options = options;
|
2695
|
-
if (_optionalChain([options, 'optionalAccess',
|
2705
|
+
if (_optionalChain([options, 'optionalAccess', _99 => _99.initialMessages])) {
|
2696
2706
|
let parentId = null;
|
2697
2707
|
const messages = fromCoreMessages(options.initialMessages);
|
2698
2708
|
for (const message of messages) {
|
@@ -2709,9 +2719,6 @@ var LocalThreadRuntime = (_class5 = class {
|
|
2709
2719
|
get messages() {
|
2710
2720
|
return this.repository.getMessages();
|
2711
2721
|
}
|
2712
|
-
get isRunning() {
|
2713
|
-
return this.abortController != null;
|
2714
|
-
}
|
2715
2722
|
getBranches(messageId) {
|
2716
2723
|
return this.repository.getBranches(messageId);
|
2717
2724
|
}
|
@@ -2750,7 +2757,7 @@ var LocalThreadRuntime = (_class5 = class {
|
|
2750
2757
|
}
|
2751
2758
|
async performRoundtrip(parentId, message) {
|
2752
2759
|
const messages = this.repository.getMessages();
|
2753
|
-
_optionalChain([this, 'access',
|
2760
|
+
_optionalChain([this, 'access', _100 => _100.abortController, 'optionalAccess', _101 => _101.abort, 'call', _102 => _102()]);
|
2754
2761
|
this.abortController = new AbortController();
|
2755
2762
|
const initialContent = message.content;
|
2756
2763
|
const initialRoundtrips = message.roundtrips;
|
@@ -2759,13 +2766,13 @@ var LocalThreadRuntime = (_class5 = class {
|
|
2759
2766
|
...message,
|
2760
2767
|
...m.content ? { content: [...initialContent, ..._nullishCoalesce(m.content, () => ( []))] } : void 0,
|
2761
2768
|
status: _nullishCoalesce(m.status, () => ( message.status)),
|
2762
|
-
..._optionalChain([m, 'access',
|
2769
|
+
..._optionalChain([m, 'access', _103 => _103.roundtrips, 'optionalAccess', _104 => _104.length]) ? { roundtrips: [..._nullishCoalesce(initialRoundtrips, () => ( [])), ...m.roundtrips] } : void 0
|
2763
2770
|
};
|
2764
2771
|
this.repository.addOrUpdateMessage(parentId, message);
|
2765
2772
|
this.notifySubscribers();
|
2766
2773
|
};
|
2767
|
-
const maxToolRoundtrips = _nullishCoalesce(_optionalChain([this, 'access',
|
2768
|
-
const toolRoundtrips = _nullishCoalesce(_optionalChain([message, 'access',
|
2774
|
+
const maxToolRoundtrips = _nullishCoalesce(_optionalChain([this, 'access', _105 => _105.options, 'optionalAccess', _106 => _106.maxToolRoundtrips]), () => ( 1));
|
2775
|
+
const toolRoundtrips = _nullishCoalesce(_optionalChain([message, 'access', _107 => _107.roundtrips, 'optionalAccess', _108 => _108.length]), () => ( 0));
|
2769
2776
|
if (toolRoundtrips > maxToolRoundtrips) {
|
2770
2777
|
updateMessage({
|
2771
2778
|
status: {
|
@@ -2800,8 +2807,6 @@ var LocalThreadRuntime = (_class5 = class {
|
|
2800
2807
|
updateMessage({
|
2801
2808
|
status: { type: "complete", reason: "unknown" }
|
2802
2809
|
});
|
2803
|
-
} else {
|
2804
|
-
this.notifySubscribers();
|
2805
2810
|
}
|
2806
2811
|
} catch (e) {
|
2807
2812
|
this.abortController = null;
|
@@ -2999,7 +3004,7 @@ var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
|
|
2999
3004
|
|
3000
3005
|
// src/runtimes/external-store/ExternalStoreThreadRuntime.tsx
|
3001
3006
|
var hasUpcomingMessage = (isRunning, messages) => {
|
3002
|
-
return isRunning && _optionalChain([messages, 'access',
|
3007
|
+
return isRunning && _optionalChain([messages, 'access', _109 => _109[messages.length - 1], 'optionalAccess', _110 => _110.role]) !== "assistant";
|
3003
3008
|
};
|
3004
3009
|
var ExternalStoreThreadRuntime = (_class7 = class {
|
3005
3010
|
__init17() {this._subscriptions = /* @__PURE__ */ new Set()}
|
@@ -3016,10 +3021,9 @@ var ExternalStoreThreadRuntime = (_class7 = class {
|
|
3016
3021
|
}
|
3017
3022
|
__init20() {this.messages = []}
|
3018
3023
|
__init21() {this.isDisabled = false}
|
3019
|
-
__init22() {this.
|
3020
|
-
__init23() {this.converter = new ThreadMessageConverter()}
|
3024
|
+
__init22() {this.converter = new ThreadMessageConverter()}
|
3021
3025
|
|
3022
|
-
constructor(store) {;_class7.prototype.__init17.call(this);_class7.prototype.__init18.call(this);_class7.prototype.__init19.call(this);_class7.prototype.__init20.call(this);_class7.prototype.__init21.call(this);_class7.prototype.__init22.call(this);_class7.prototype.__init23.call(this);
|
3026
|
+
constructor(store) {;_class7.prototype.__init17.call(this);_class7.prototype.__init18.call(this);_class7.prototype.__init19.call(this);_class7.prototype.__init20.call(this);_class7.prototype.__init21.call(this);_class7.prototype.__init22.call(this);_class7.prototype.__init23.call(this);
|
3023
3027
|
this.store = store;
|
3024
3028
|
}
|
3025
3029
|
set store(store) {
|
@@ -3055,7 +3059,7 @@ var ExternalStoreThreadRuntime = (_class7 = class {
|
|
3055
3059
|
for (let i = 0; i < messages.length; i++) {
|
3056
3060
|
const message = messages[i];
|
3057
3061
|
const parent = messages[i - 1];
|
3058
|
-
this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess',
|
3062
|
+
this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _114 => _114.id]), () => ( null)), message);
|
3059
3063
|
}
|
3060
3064
|
if (this.assistantOptimisticId) {
|
3061
3065
|
this.repository.deleteMessage(this.assistantOptimisticId);
|
@@ -3063,7 +3067,7 @@ var ExternalStoreThreadRuntime = (_class7 = class {
|
|
3063
3067
|
}
|
3064
3068
|
if (hasUpcomingMessage(isRunning, messages)) {
|
3065
3069
|
this.assistantOptimisticId = this.repository.appendOptimisticMessage(
|
3066
|
-
_nullishCoalesce(_optionalChain([messages, 'access',
|
3070
|
+
_nullishCoalesce(_optionalChain([messages, 'access', _115 => _115.at, 'call', _116 => _116(-1), 'optionalAccess', _117 => _117.id]), () => ( null)),
|
3067
3071
|
{
|
3068
3072
|
role: "assistant",
|
3069
3073
|
content: []
|
@@ -3071,11 +3075,10 @@ var ExternalStoreThreadRuntime = (_class7 = class {
|
|
3071
3075
|
);
|
3072
3076
|
}
|
3073
3077
|
this.repository.resetHead(
|
3074
|
-
_nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages, 'access',
|
3078
|
+
_nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages, 'access', _118 => _118.at, 'call', _119 => _119(-1), 'optionalAccess', _120 => _120.id]))), () => ( null))
|
3075
3079
|
);
|
3076
3080
|
this.messages = this.repository.getMessages();
|
3077
3081
|
this.isDisabled = isDisabled;
|
3078
|
-
this.isRunning = isRunning;
|
3079
3082
|
for (const callback of this._subscriptions) callback();
|
3080
3083
|
}
|
3081
3084
|
getBranches(messageId) {
|
@@ -3088,7 +3091,7 @@ var ExternalStoreThreadRuntime = (_class7 = class {
|
|
3088
3091
|
this.updateMessages(this.repository.getMessages());
|
3089
3092
|
}
|
3090
3093
|
async append(message) {
|
3091
|
-
if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access',
|
3094
|
+
if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _121 => _121.messages, 'access', _122 => _122.at, 'call', _123 => _123(-1), 'optionalAccess', _124 => _124.id]), () => ( null)))) {
|
3092
3095
|
if (!this._store.onEdit)
|
3093
3096
|
throw new Error("Runtime does not support editing messages.");
|
3094
3097
|
await this._store.onEdit(message);
|
@@ -3118,8 +3121,8 @@ var ExternalStoreThreadRuntime = (_class7 = class {
|
|
3118
3121
|
this._subscriptions.add(callback);
|
3119
3122
|
return () => this._subscriptions.delete(callback);
|
3120
3123
|
}
|
3121
|
-
|
3122
|
-
_optionalChain([this, 'access',
|
3124
|
+
__init23() {this.updateMessages = (messages) => {
|
3125
|
+
_optionalChain([this, 'access', _125 => _125._store, 'access', _126 => _126.setMessages, 'optionalCall', _127 => _127(
|
3123
3126
|
messages.flatMap(getExternalStoreMessage).filter((m) => m != null)
|
3124
3127
|
)]);
|
3125
3128
|
}}
|
@@ -3132,9 +3135,9 @@ var ExternalStoreThreadRuntime = (_class7 = class {
|
|
3132
3135
|
|
3133
3136
|
// src/runtimes/external-store/ExternalStoreRuntime.tsx
|
3134
3137
|
var ExternalStoreRuntime = (_class8 = class extends BaseAssistantRuntime {
|
3135
|
-
|
3138
|
+
__init24() {this._proxyConfigProvider = new ProxyConfigProvider()}
|
3136
3139
|
constructor(store) {
|
3137
|
-
super(new ExternalStoreThreadRuntime(store));_class8.prototype.
|
3140
|
+
super(new ExternalStoreThreadRuntime(store));_class8.prototype.__init24.call(this);;
|
3138
3141
|
}
|
3139
3142
|
set store(store) {
|
3140
3143
|
this.thread.store = store;
|
@@ -3184,7 +3187,7 @@ var ThreadConfigProvider = ({
|
|
3184
3187
|
}) => {
|
3185
3188
|
const assistant = useAssistantContext({ optional: true });
|
3186
3189
|
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 });
|
3187
|
-
if (!_optionalChain([config, 'optionalAccess',
|
3190
|
+
if (!_optionalChain([config, 'optionalAccess', _128 => _128.runtime])) return configProvider;
|
3188
3191
|
if (assistant) {
|
3189
3192
|
throw new Error(
|
3190
3193
|
"You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
|
@@ -3400,7 +3403,7 @@ var AssistantMessageContent = _react.forwardRef.call(void 0, ({ components: comp
|
|
3400
3403
|
{
|
3401
3404
|
components: {
|
3402
3405
|
...componentsProp,
|
3403
|
-
Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess',
|
3406
|
+
Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _129 => _129.Text]), () => ( components.Text)), () => ( content_part_default.Text))
|
3404
3407
|
}
|
3405
3408
|
}
|
3406
3409
|
) });
|
@@ -3575,7 +3578,7 @@ var ThreadWelcomeSuggestion = ({
|
|
3575
3578
|
};
|
3576
3579
|
var ThreadWelcomeSuggestions = () => {
|
3577
3580
|
const { welcome: { suggestions } = {} } = useThreadConfig();
|
3578
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([suggestions, 'optionalAccess',
|
3581
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([suggestions, 'optionalAccess', _130 => _130.map, 'call', _131 => _131((suggestion, idx) => {
|
3579
3582
|
const key = `${suggestion.prompt}-${idx}`;
|
3580
3583
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestion, { suggestion }, key);
|
3581
3584
|
})]) });
|
@@ -3653,7 +3656,7 @@ var UserMessageContent = _react.forwardRef.call(void 0,
|
|
3653
3656
|
{
|
3654
3657
|
components: {
|
3655
3658
|
...components,
|
3656
|
-
Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
3659
|
+
Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _132 => _132.Text]), () => ( content_part_default.Text))
|
3657
3660
|
}
|
3658
3661
|
}
|
3659
3662
|
) });
|
@@ -3755,10 +3758,10 @@ var ThreadMessages = ({ components, ...rest }) => {
|
|
3755
3758
|
thread_exports.Messages,
|
3756
3759
|
{
|
3757
3760
|
components: {
|
3758
|
-
UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
3759
|
-
EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
3760
|
-
AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
3761
|
-
SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess',
|
3761
|
+
UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _133 => _133.UserMessage]), () => ( user_message_default)),
|
3762
|
+
EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _134 => _134.EditComposer]), () => ( edit_composer_default)),
|
3763
|
+
AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _135 => _135.AssistantMessage]), () => ( assistant_message_default)),
|
3764
|
+
SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _136 => _136.SystemMessage]), () => ( SystemMessage))
|
3762
3765
|
},
|
3763
3766
|
...rest
|
3764
3767
|
}
|