@assistant-ui/react 0.0.23 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +7 -6
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +68 -26
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +68 -26
- package/dist/index.mjs.map +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# `assistant-ui`
|
2
2
|
|
3
|
-
|
3
|
+
`assistant-ui` is a set of React components for AI chat.
|
4
4
|
|
5
|
+
- [Discord](https://discord.gg/S9dwgCNEFs)
|
5
6
|
- [Website](https://assistant-ui.com/)
|
6
7
|
- [Demo](https://assistant-ui-rsc-example.vercel.app/)
|
7
8
|
|
@@ -12,21 +13,21 @@
|
|
12
13
|
## Minimal Example with Vercel AI SDK
|
13
14
|
|
14
15
|
```sh
|
15
|
-
npx
|
16
|
+
npx assistant-ui add thread
|
16
17
|
```
|
17
18
|
|
18
19
|
```tsx
|
19
20
|
"use client";
|
20
21
|
|
21
22
|
import { useChat } from "@ai-sdk/react";
|
22
|
-
import { AssistantRuntimeProvider,
|
23
|
+
import { AssistantRuntimeProvider, useVercelUseChatRuntime } from "@assistant-ui/react";
|
23
24
|
import { Thread } from "@/components/ui/assistant-ui/thread";
|
24
25
|
|
25
|
-
const MyApp = () => {
|
26
|
+
export default const MyApp = () => {
|
26
27
|
const chat = useChat({
|
27
28
|
api: "/api/chat" // your backend route
|
28
29
|
});
|
29
|
-
const runtime =
|
30
|
+
const runtime = useVercelUseChatRuntime(chat);
|
30
31
|
|
31
32
|
return (
|
32
33
|
<AssistantRuntimeProvider runtime={runtime}>
|
package/dist/index.d.mts
CHANGED
@@ -364,7 +364,7 @@ declare const useVercelUseChatRuntime: (chatHelpers: UseChatHelpers) => VercelAI
|
|
364
364
|
|
365
365
|
declare const useVercelUseAssistantRuntime: (assistantHelpers: UseAssistantHelpers) => VercelAIRuntime;
|
366
366
|
|
367
|
-
declare const getVercelAIMessage: (message: ThreadMessage) => Message | undefined;
|
367
|
+
declare const getVercelAIMessage: (message: ThreadMessage) => Message[] | undefined;
|
368
368
|
|
369
369
|
/**
|
370
370
|
* @deprecated Will be removed in 0.1.0.
|
package/dist/index.d.ts
CHANGED
@@ -364,7 +364,7 @@ declare const useVercelUseChatRuntime: (chatHelpers: UseChatHelpers) => VercelAI
|
|
364
364
|
|
365
365
|
declare const useVercelUseAssistantRuntime: (assistantHelpers: UseAssistantHelpers) => VercelAIRuntime;
|
366
366
|
|
367
|
-
declare const getVercelAIMessage: (message: ThreadMessage) => Message | undefined;
|
367
|
+
declare const getVercelAIMessage: (message: ThreadMessage) => Message[] | undefined;
|
368
368
|
|
369
369
|
/**
|
370
370
|
* @deprecated Will be removed in 0.1.0.
|
package/dist/index.js
CHANGED
@@ -1053,11 +1053,12 @@ var import_react29 = require("react");
|
|
1053
1053
|
// src/runtime/vercel-ai/utils/ThreadMessageConverter.ts
|
1054
1054
|
var ThreadMessageConverter = class {
|
1055
1055
|
cache = /* @__PURE__ */ new WeakMap();
|
1056
|
-
convertMessages(converter,
|
1056
|
+
convertMessages(messages, converter, keyMapper = (key) => key) {
|
1057
1057
|
return messages.map((m) => {
|
1058
|
-
const
|
1058
|
+
const key = keyMapper(m);
|
1059
|
+
const cached = this.cache.get(key);
|
1059
1060
|
const newMessage = converter(m, cached);
|
1060
|
-
this.cache.set(
|
1061
|
+
this.cache.set(key, newMessage);
|
1061
1062
|
return newMessage;
|
1062
1063
|
});
|
1063
1064
|
}
|
@@ -1091,7 +1092,7 @@ var useVercelRSCSync = (adapter, updateData) => {
|
|
1091
1092
|
return [new ThreadMessageConverter(), convertCallback2];
|
1092
1093
|
}, [adapter.convertMessage]);
|
1093
1094
|
(0, import_react29.useEffect)(() => {
|
1094
|
-
updateData(converter.convertMessages(
|
1095
|
+
updateData(converter.convertMessages(adapter.messages, convertCallback));
|
1095
1096
|
}, [updateData, converter, convertCallback, adapter.messages]);
|
1096
1097
|
};
|
1097
1098
|
|
@@ -1354,11 +1355,14 @@ var getVercelAIMessage = (message) => {
|
|
1354
1355
|
// src/runtime/vercel-ai/ui/utils/sliceMessagesUntil.tsx
|
1355
1356
|
var sliceMessagesUntil = (messages, messageId) => {
|
1356
1357
|
if (messageId == null) return [];
|
1357
|
-
|
1358
|
+
let messageIdx = messages.findIndex((m) => m.id === messageId);
|
1358
1359
|
if (messageIdx === -1)
|
1359
1360
|
throw new Error(
|
1360
1361
|
"useVercelAIThreadState: Message not found. This is liekly an internal bug in assistant-ui."
|
1361
1362
|
);
|
1363
|
+
while (messages[messageIdx + 1]?.role === "assistant") {
|
1364
|
+
messageIdx++;
|
1365
|
+
}
|
1362
1366
|
return messages.slice(0, messageIdx + 1);
|
1363
1367
|
};
|
1364
1368
|
|
@@ -1380,24 +1384,31 @@ var getIsRunning = (vercel) => {
|
|
1380
1384
|
if ("isLoading" in vercel) return vercel.isLoading;
|
1381
1385
|
return vercel.status === "in_progress";
|
1382
1386
|
};
|
1383
|
-
var vercelToThreadMessage2 = (
|
1387
|
+
var vercelToThreadMessage2 = (messages, status) => {
|
1388
|
+
const firstMessage = messages[0];
|
1389
|
+
if (!firstMessage) throw new Error("No messages found");
|
1384
1390
|
const common = {
|
1385
|
-
id:
|
1386
|
-
createdAt:
|
1387
|
-
[symbolInnerAIMessage]:
|
1391
|
+
id: firstMessage.id,
|
1392
|
+
createdAt: firstMessage.createdAt ?? /* @__PURE__ */ new Date(),
|
1393
|
+
[symbolInnerAIMessage]: messages
|
1388
1394
|
};
|
1389
|
-
switch (
|
1395
|
+
switch (firstMessage.role) {
|
1390
1396
|
case "user":
|
1397
|
+
if (messages.length > 1) {
|
1398
|
+
throw new Error(
|
1399
|
+
"Multiple user messages found. This is likely an internal bug in assistant-ui."
|
1400
|
+
);
|
1401
|
+
}
|
1391
1402
|
return {
|
1392
1403
|
...common,
|
1393
1404
|
role: "user",
|
1394
|
-
content: [{ type: "text", text:
|
1405
|
+
content: [{ type: "text", text: firstMessage.content }]
|
1395
1406
|
};
|
1396
1407
|
case "assistant":
|
1397
1408
|
return {
|
1398
1409
|
...common,
|
1399
1410
|
role: "assistant",
|
1400
|
-
content: [
|
1411
|
+
content: messages.flatMap((message) => [
|
1401
1412
|
...message.content ? [{ type: "text", text: message.content }] : [],
|
1402
1413
|
...message.toolInvocations?.map(
|
1403
1414
|
(t) => ({
|
@@ -1407,29 +1418,57 @@ var vercelToThreadMessage2 = (message, status) => {
|
|
1407
1418
|
result: "result" in t ? t.result : void 0
|
1408
1419
|
})
|
1409
1420
|
) ?? []
|
1410
|
-
],
|
1421
|
+
]),
|
1411
1422
|
status
|
1412
1423
|
};
|
1413
1424
|
default:
|
1414
1425
|
throw new Error(
|
1415
|
-
`You have a message with an unsupported role. The role ${
|
1426
|
+
`You have a message with an unsupported role. The role ${firstMessage.role} is not supported.`
|
1416
1427
|
);
|
1417
1428
|
}
|
1418
1429
|
};
|
1430
|
+
var hasItems = (messages) => messages.length > 0;
|
1431
|
+
var chunkedMessages = (messages) => {
|
1432
|
+
const chunks = [];
|
1433
|
+
let currentChunk = [];
|
1434
|
+
for (const message of messages) {
|
1435
|
+
if (message.role === "assistant") {
|
1436
|
+
currentChunk.push(message);
|
1437
|
+
} else {
|
1438
|
+
if (hasItems(currentChunk)) {
|
1439
|
+
chunks.push(currentChunk);
|
1440
|
+
currentChunk = [];
|
1441
|
+
}
|
1442
|
+
chunks.push([message]);
|
1443
|
+
}
|
1444
|
+
}
|
1445
|
+
if (hasItems(currentChunk)) {
|
1446
|
+
chunks.push(currentChunk);
|
1447
|
+
}
|
1448
|
+
return chunks;
|
1449
|
+
};
|
1450
|
+
var shallowArrayEqual = (a, b) => {
|
1451
|
+
if (a.length !== b.length) return false;
|
1452
|
+
for (let i = 0; i < a.length; i++) {
|
1453
|
+
if (a[i] !== b[i]) return false;
|
1454
|
+
}
|
1455
|
+
return true;
|
1456
|
+
};
|
1419
1457
|
var useVercelAIThreadSync = (vercel, updateData) => {
|
1420
1458
|
const isRunning = getIsRunning(vercel);
|
1421
1459
|
const converter = (0, import_react32.useMemo)(() => new ThreadMessageConverter(), []);
|
1422
1460
|
(0, import_react32.useEffect)(() => {
|
1423
1461
|
const lastMessageId = vercel.messages.at(-1)?.id;
|
1424
|
-
const convertCallback = (
|
1425
|
-
const status = lastMessageId ===
|
1426
|
-
if (cache && (cache.role === "user" || cache.status === status))
|
1462
|
+
const convertCallback = (messages2, cache) => {
|
1463
|
+
const status = lastMessageId === messages2[0].id && isRunning ? "in_progress" : "done";
|
1464
|
+
if (cache && shallowArrayEqual(cache.content, messages2) && (cache.role === "user" || cache.status === status))
|
1427
1465
|
return cache;
|
1428
|
-
return vercelToThreadMessage2(
|
1466
|
+
return vercelToThreadMessage2(messages2, status);
|
1429
1467
|
};
|
1430
1468
|
const messages = converter.convertMessages(
|
1469
|
+
chunkedMessages(vercel.messages),
|
1431
1470
|
convertCallback,
|
1432
|
-
|
1471
|
+
(m) => m[0]
|
1433
1472
|
);
|
1434
1473
|
updateData(isRunning, messages);
|
1435
1474
|
}, [updateData, isRunning, vercel.messages, converter]);
|
@@ -1505,7 +1544,7 @@ var VercelAIRuntime = class {
|
|
1505
1544
|
}
|
1506
1545
|
updateVercelMessages = (messages) => {
|
1507
1546
|
this.vercel.setMessages(
|
1508
|
-
messages.
|
1547
|
+
messages.flatMap(getVercelAIMessage).filter((m) => m != null)
|
1509
1548
|
);
|
1510
1549
|
};
|
1511
1550
|
onVercelUpdated() {
|
@@ -1773,15 +1812,17 @@ var LocalRuntime = class {
|
|
1773
1812
|
this.abortController = new AbortController();
|
1774
1813
|
this.notifySubscribers();
|
1775
1814
|
try {
|
1776
|
-
|
1815
|
+
const updateHandler = ({ content }) => {
|
1816
|
+
message.content = content;
|
1817
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1818
|
+
this.notifySubscribers();
|
1819
|
+
};
|
1820
|
+
const result = await this.adapter.run({
|
1777
1821
|
messages,
|
1778
1822
|
abortSignal: this.abortController.signal,
|
1779
|
-
onUpdate:
|
1780
|
-
message.content = content;
|
1781
|
-
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1782
|
-
this.notifySubscribers();
|
1783
|
-
}
|
1823
|
+
onUpdate: updateHandler
|
1784
1824
|
});
|
1825
|
+
updateHandler(result);
|
1785
1826
|
message.status = "done";
|
1786
1827
|
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1787
1828
|
} catch (e) {
|
@@ -1886,3 +1927,4 @@ var VercelModelAdapter = class {
|
|
1886
1927
|
useVercelUseAssistantRuntime,
|
1887
1928
|
useVercelUseChatRuntime
|
1888
1929
|
});
|
1930
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/actions/useCopyMessage.tsx","../src/context/MessageContext.ts","../src/utils/combined/useCombinedStore.ts","../src/utils/combined/createCombinedStore.ts","../src/utils/getMessageText.tsx","../src/actions/useReloadMessage.tsx","../src/context/ThreadContext.ts","../src/actions/useBeginMessageEdit.tsx","../src/actions/useGoToNextBranch.tsx","../src/actions/useGoToPreviousBranch.tsx","../src/primitives/thread/index.ts","../src/primitives/thread/ThreadRoot.tsx","../src/primitives/thread/ThreadIf.tsx","../src/primitives/thread/ThreadEmpty.tsx","../src/primitives/thread/ThreadViewport.tsx","../src/utils/hooks/useOnResizeContent.tsx","../src/utils/hooks/useOnScrollToBottom.tsx","../src/context/providers/MessageProvider.tsx","../src/context/stores/MessageComposer.ts","../src/context/stores/BaseComposer.ts","../src/context/ComposerContext.ts","../src/primitives/composer/ComposerIf.tsx","../src/primitives/message/MessageIf.tsx","../src/primitives/thread/ThreadMessages.tsx","../src/primitives/thread/ThreadScrollToBottom.tsx","../src/primitives/thread/ThreadSuggestion.tsx","../src/primitives/composer/index.ts","../src/primitives/composer/ComposerRoot.tsx","../src/primitives/composer/ComposerInput.tsx","../src/primitives/composer/ComposerSend.tsx","../src/primitives/composer/ComposerCancel.tsx","../src/primitives/message/index.ts","../src/primitives/message/MessageRoot.tsx","../src/context/providers/ContentPartProvider.tsx","../src/context/ContentPartContext.ts","../src/primitives/contentPart/ContentPartInProgressIndicator.tsx","../src/primitives/message/MessageContent.tsx","../src/primitives/message/MessageInProgress.tsx","../src/primitives/branchPicker/index.ts","../src/utils/createActionButton.tsx","../src/primitives/branchPicker/BranchPickerNext.tsx","../src/primitives/branchPicker/BranchPickerPrevious.tsx","../src/primitives/branchPicker/BranchPickerCount.tsx","../src/primitives/branchPicker/BranchPickerNumber.tsx","../src/primitives/branchPicker/BranchPickerRoot.tsx","../src/primitives/actionBar/index.ts","../src/primitives/actionBar/ActionBarRoot.tsx","../src/primitives/actionBar/ActionBarCopy.tsx","../src/primitives/actionBar/ActionBarReload.tsx","../src/primitives/actionBar/ActionBarEdit.tsx","../src/primitives/contentPart/index.ts","../src/runtime/vercel-ai/rsc/useVercelRSCRuntime.tsx","../src/runtime/vercel-ai/rsc/VercelRSCRuntime.tsx","../src/runtime/vercel-ai/rsc/useVercelRSCSync.tsx","../src/runtime/vercel-ai/utils/ThreadMessageConverter.ts","../src/runtime/vercel-ai/rsc/getVercelRSCMessage.tsx","../src/runtime/vercel-ai/ui/use-chat/useVercelUseChatRuntime.tsx","../src/runtime/vercel-ai/ui/VercelAIRuntime.tsx","../src/runtime/utils/idUtils.tsx","../src/runtime/utils/MessageRepository.tsx","../src/runtime/vercel-ai/ui/getVercelAIMessage.tsx","../src/runtime/vercel-ai/ui/utils/sliceMessagesUntil.tsx","../src/runtime/vercel-ai/ui/utils/useVercelAIComposerSync.tsx","../src/runtime/vercel-ai/ui/utils/useVercelAIThreadSync.tsx","../src/runtime/vercel-ai/ui/use-assistant/useVercelUseAssistantRuntime.tsx","../src/context/providers/AssistantRuntimeProvider.tsx","../src/context/providers/ThreadProvider.tsx","../src/context/stores/Composer.ts","../src/context/stores/Thread.ts","../src/context/stores/ThreadViewport.tsx","../src/runtime/vercel-deprecated/VercelAIAssistantProvider.tsx","../src/runtime/vercel-deprecated/VercelRSCAssistantProvider.tsx","../src/runtime/local/useLocalRuntime.tsx","../src/runtime/local/LocalRuntime.tsx","../src/runtime/local/vercel/VercelModelAdapter.tsx"],"sourcesContent":["export * from \"./actions\";\nexport * from \"./primitives\";\nexport * from \"./runtime\";\n\n// deprecated\nexport {\n VercelAIAssistantProvider,\n type VercelAIAssistantProviderProps,\n VercelRSCAssistantProvider,\n type VercelRSCAssistantProviderProps,\n} from \"./runtime/vercel-deprecated\";\n\n/**\n * @deprecated This type was renamed to `VercelRSCMessage`. Please use that import. Will be removed in 0.1.0.\n */\nexport type { VercelRSCMessage as RSCMessage } from \"./runtime/vercel-ai/rsc/VercelRSCMessage\";\n\n// experimental\nexport type {\n ThreadMessage,\n AssistantMessage,\n UserMessage,\n AppendMessage,\n AssistantContentPart,\n UserContentPart,\n AppendContentPart,\n TextContentPart,\n ImageContentPart as unstable_ImageContentPart,\n ToolCallContentPart as unstable_ToolCallContentPart,\n UIContentPart as unstable_UIContentPart,\n} from \"./utils/AssistantTypes\";\n\nexport { useLocalRuntime as unstable_useLocalRuntime } from \"./runtime/local/useLocalRuntime\";\nexport type {\n ChatModelAdapter as unstable_ChatModelAdapter,\n ChatModelRunOptions as unstable_ChatModelRunOptions,\n} from \"./runtime/local/ChatModelAdapter\";\nexport { VercelModelAdapter as unstable_VercelModelAdapter } from \"./runtime/local/vercel/VercelModelAdapter\";\n\nexport { AssistantRuntimeProvider } from \"./context/providers/AssistantRuntimeProvider\";\nexport {\n // context\n useThreadContext as unstable_useThreadContext,\n type ThreadContextValue as unstable_ThreadContextValue,\n useMessageContext as unstable_useMessageContext,\n type MessageContextValue as unstable_MessageContextValue,\n useComposerContext as unstable_useComposerContext,\n type ComposerContextValue as unstable_ComposerContextValue,\n useContentPartContext as unstable_useContentPartContext,\n type ContentPartContextValue as unstable_ContentPartContextValue,\n // stores\n type ThreadState as unstable_ThreadState,\n type ComposerState as unstable_ComposerState,\n type ThreadViewportState as unstable_ThreadViewportState,\n type MessageState as unstable_MessageState,\n type EditComposerState as unstable_EditComposerState,\n type ContentPartState as unstable_ContentPartState,\n} from \"./context\";\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../context/MessageContext\";\nimport { useCombinedStore } from \"../utils/combined/useCombinedStore\";\nimport { getMessageText } from \"../utils/getMessageText\";\n\nexport const useCopyMessage = ({ copiedDuration = 3000 }) => {\n const { useMessage, useComposer } = useMessageContext();\n\n const hasCopyableContent = useCombinedStore(\n [useMessage, useComposer],\n (m, c) => {\n return c.isEditing || m.message.content.some((c) => c.type === \"text\");\n },\n );\n\n const callback = useCallback(() => {\n const { isEditing, value: composerValue } = useComposer.getState();\n const { message, setIsCopied } = useMessage.getState();\n\n const valueToCopy = isEditing ? composerValue : getMessageText(message);\n\n navigator.clipboard.writeText(valueToCopy);\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n }, [useComposer, useMessage, copiedDuration]);\n\n if (!hasCopyableContent) return null;\n return callback;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type MessageContextValue = {\n useMessage: UseBoundStore<StoreApi<MessageState>>;\n useComposer: UseBoundStore<StoreApi<EditComposerState>>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nexport const useMessageContext = () => {\n const context = useContext(MessageContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />.\",\n );\n return context;\n};\n","\"use client\";\nimport { useMemo } from \"react\";\nimport type { StoreApi } from \"zustand\";\nimport {\n type CombinedSelector,\n createCombinedStore,\n} from \"./createCombinedStore\";\n\nexport const useCombinedStore = <T extends Array<unknown>, R>(\n stores: { [K in keyof T]: StoreApi<T[K]> },\n selector: CombinedSelector<T, R>,\n): R => {\n // biome-ignore lint/correctness/useExhaustiveDependencies: shallow-compare the store array\n const useCombined = useMemo(() => createCombinedStore<T, R>(stores), stores);\n return useCombined(selector);\n};\n","import { useSyncExternalStore } from \"react\";\nimport type { StoreApi } from \"zustand\";\n\nexport type CombinedSelector<T extends Array<unknown>, R> = (...args: T) => R;\n\nexport const createCombinedStore = <T extends Array<unknown>, R>(\n stores: { [K in keyof T]: StoreApi<T[K]> },\n) => {\n const subscribe = (callback: () => void): (() => void) => {\n const unsubscribes = stores.map((store) => store.subscribe(callback));\n return () => {\n for (const unsub of unsubscribes) {\n unsub();\n }\n };\n };\n\n return (selector: CombinedSelector<T, R>): R => {\n const getSnapshot = (): R =>\n selector(...(stores.map((store) => store.getState()) as T));\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n };\n};\n","\"use client\";\nimport type { TextContentPart, ThreadMessage } from \"./AssistantTypes\";\n\nexport const getMessageText = (message: ThreadMessage) => {\n const textParts = message.content.filter(\n (part) => part.type === \"text\",\n ) as TextContentPart[];\n\n return textParts.map((part) => part.text).join(\"\\n\\n\");\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../context/MessageContext\";\nimport { useThreadContext } from \"../context/ThreadContext\";\nimport { useCombinedStore } from \"../utils/combined/useCombinedStore\";\n\nexport const useReloadMessage = () => {\n const { useThread, useViewport } = useThreadContext();\n const { useMessage } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useThread, useMessage],\n (t, m) => t.isRunning || m.message.role !== \"assistant\",\n );\n\n const callback = useCallback(() => {\n const { parentId } = useMessage.getState();\n useThread.getState().startRun(parentId);\n useViewport.getState().scrollToBottom();\n }, [useMessage, useThread, useViewport]);\n\n if (disabled) return null;\n return callback;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\n\nexport type ThreadContextValue = {\n useThread: UseBoundStore<StoreApi<ThreadState>>;\n useComposer: UseBoundStore<StoreApi<ComposerState>>;\n useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nexport const useThreadContext = (): ThreadContextValue => {\n const context = useContext(ThreadContext);\n if (!context)\n throw new Error(\"This component must be used within an AssistantProvider.\");\n return context;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../context/MessageContext\";\nimport { useCombinedStore } from \"../utils/combined/useCombinedStore\";\n\nexport const useBeginMessageEdit = () => {\n const { useMessage, useComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useComposer],\n (m, c) => m.message.role !== \"user\" || c.isEditing,\n );\n\n const callback = useCallback(() => {\n const { edit } = useComposer.getState();\n edit();\n }, [useComposer]);\n\n if (disabled) return null;\n return callback;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../context/MessageContext\";\nimport { useThreadContext } from \"../context/ThreadContext\";\nimport { useCombinedStore } from \"../utils/combined/useCombinedStore\";\n\nexport const useGoToNextBranch = () => {\n const { useThread } = useThreadContext();\n const { useMessage, useComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useComposer],\n (m, c) =>\n c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length,\n );\n\n const callback = useCallback(() => {\n const { message, branches } = useMessage.getState();\n useThread\n .getState()\n .switchToBranch(branches[branches.indexOf(message.id) + 1]!);\n }, [useMessage, useThread]);\n\n if (disabled) return null;\n return callback;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../context/MessageContext\";\nimport { useThreadContext } from \"../context/ThreadContext\";\nimport { useCombinedStore } from \"../utils/combined/useCombinedStore\";\n\nexport const useGoToPreviousBranch = () => {\n const { useThread } = useThreadContext();\n const { useMessage, useComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useComposer],\n (m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0,\n );\n\n const callback = useCallback(() => {\n const { message, branches } = useMessage.getState();\n useThread\n .getState()\n .switchToBranch(branches[branches.indexOf(message.id) - 1]!);\n }, [useMessage, useThread]);\n\n if (disabled) return null;\n return callback;\n};\n","export { ThreadRoot as Root } from \"./ThreadRoot\";\nexport { ThreadEmpty as Empty } from \"./ThreadEmpty\";\nexport { ThreadIf as If } from \"./ThreadIf\";\nexport { ThreadViewport as Viewport } from \"./ThreadViewport\";\nexport { ThreadMessages as Messages } from \"./ThreadMessages\";\nexport { ThreadScrollToBottom as ScrollToBottom } from \"./ThreadScrollToBottom\";\nexport { ThreadSuggestion as Suggestion } from \"./ThreadSuggestion\";\n","\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\n\ntype ThreadRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\ntype ThreadRootProps = PrimitiveDivProps;\n\nexport const ThreadRoot = forwardRef<ThreadRootElement, ThreadRootProps>(\n (props, ref) => {\n return <Primitive.div {...props} ref={ref} />;\n },\n);\n","\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype ThreadIfFilters = {\n empty: boolean | undefined;\n running: boolean | undefined;\n};\n\ntype ThreadIfProps = PropsWithChildren<RequireAtLeastOne<ThreadIfFilters>>;\n\nconst useThreadIf = (props: RequireAtLeastOne<ThreadIfFilters>) => {\n const { useThread } = useThreadContext();\n return useThread((thread) => {\n if (props.empty === true && thread.messages.length !== 0) return false;\n if (props.empty === false && thread.messages.length === 0) return false;\n if (props.running === true && !thread.isRunning) return false;\n if (props.running === false && thread.isRunning) return false;\n\n return true;\n });\n};\n\nexport const ThreadIf: FC<ThreadIfProps> = ({ children, ...query }) => {\n const result = useThreadIf(query);\n return result ? children : null;\n};\n","\"use client\";\n\nimport type { FC, ReactNode } from \"react\";\nimport { ThreadIf } from \"./ThreadIf\";\n\ntype ThreadEmptyProps = {\n children: ReactNode;\n};\n\nexport const ThreadEmpty: FC<ThreadEmptyProps> = ({ children }) => {\n return <ThreadIf empty>{children}</ThreadIf>;\n};\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, useRef } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\nimport { useOnResizeContent } from \"../../utils/hooks/useOnResizeContent\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\n\ntype ThreadViewportElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\ntype ThreadViewportProps = PrimitiveDivProps & {\n autoScroll?: boolean;\n};\n\nexport const ThreadViewport = forwardRef<\n ThreadViewportElement,\n ThreadViewportProps\n>(({ autoScroll = true, onScroll, children, ...rest }, forwardedRef) => {\n const messagesEndRef = useRef<HTMLDivElement>(null);\n\n const divRef = useRef<HTMLDivElement>(null);\n const ref = useComposedRefs(forwardedRef, divRef);\n\n const { useViewport } = useThreadContext();\n\n // TODO find a more elegant implementation for this\n\n const firstRenderRef = useRef(true);\n const isScrollingToBottomRef = useRef(false);\n const lastScrollTop = useRef<number>(0);\n\n const scrollToBottom = () => {\n const div = messagesEndRef.current;\n if (!div || !autoScroll) return;\n\n const behavior = firstRenderRef.current ? \"instant\" : \"auto\";\n firstRenderRef.current = false;\n\n isScrollingToBottomRef.current = true;\n div.scrollIntoView({ behavior });\n };\n\n useOnResizeContent(divRef, () => {\n if (!isScrollingToBottomRef.current && !useViewport.getState().isAtBottom) {\n handleScroll();\n } else {\n scrollToBottom();\n }\n });\n\n useOnScrollToBottom(() => {\n scrollToBottom();\n });\n\n const handleScroll = () => {\n const div = divRef.current;\n if (!div) return;\n\n const isAtBottom = useViewport.getState().isAtBottom;\n const newIsAtBottom = div.scrollHeight - div.scrollTop <= div.clientHeight;\n\n if (!newIsAtBottom && lastScrollTop.current < div.scrollTop) {\n // ignore scroll down\n } else if (newIsAtBottom !== isAtBottom) {\n isScrollingToBottomRef.current = false;\n useViewport.setState({ isAtBottom: newIsAtBottom });\n }\n\n lastScrollTop.current = div.scrollTop;\n };\n\n return (\n <Primitive.div\n {...rest}\n onScroll={composeEventHandlers(onScroll, handleScroll)}\n ref={ref}\n >\n {children}\n <div ref={messagesEndRef} />\n </Primitive.div>\n );\n});\n","\"use client\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { type MutableRefObject, useEffect } from \"react\";\n\nexport const useOnResizeContent = (\n ref: MutableRefObject<HTMLElement | null>,\n callback: () => void,\n) => {\n const callbackRef = useCallbackRef(callback);\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n\n const resizeObserver = new ResizeObserver(() => {\n callbackRef();\n });\n\n const mutationObserver = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n for (const node of mutation.addedNodes) {\n if (node instanceof Element) {\n resizeObserver.observe(node);\n }\n }\n\n for (const node of mutation.removedNodes) {\n if (node instanceof Element) {\n resizeObserver.unobserve(node);\n }\n }\n }\n\n callbackRef();\n });\n\n resizeObserver.observe(el);\n mutationObserver.observe(el, { childList: true });\n\n // Observe existing children\n for (const child of el.children) {\n resizeObserver.observe(child);\n }\n\n return () => {\n resizeObserver.disconnect();\n mutationObserver.disconnect();\n };\n }, [ref.current, callbackRef]);\n};\n","\"use client\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useEffect } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\n\nexport const useOnScrollToBottom = (callback: () => void) => {\n const callbackRef = useCallbackRef(callback);\n\n const { useViewport } = useThreadContext();\n useEffect(() => {\n return useViewport.getState().onScrollToBottom(() => {\n callbackRef();\n });\n }, [useViewport, callbackRef]);\n};\n","\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport type {\n AppendContentPart,\n ThreadMessage,\n} from \"../../utils/AssistantTypes\";\nimport { getMessageText } from \"../../utils/getMessageText\";\nimport { MessageContext } from \"../MessageContext\";\nimport type { MessageContextValue } from \"../MessageContext\";\nimport { useThreadContext } from \"../ThreadContext\";\nimport type { MessageState } from \"../stores/Message\";\nimport { makeEditComposerStore } from \"../stores/MessageComposer\";\nimport type { ThreadState } from \"../stores/Thread\";\n\ntype MessageProviderProps = PropsWithChildren<{\n messageIndex: number;\n}>;\n\nconst getIsLast = (thread: ThreadState, message: ThreadMessage) => {\n return thread.messages[thread.messages.length - 1]?.id === message.id;\n};\n\nconst syncMessage = (\n thread: ThreadState,\n useMessage: MessageContextValue[\"useMessage\"],\n messageIndex: number,\n) => {\n const parentId = thread.messages[messageIndex - 1]?.id ?? null;\n const message = thread.messages[messageIndex];\n\n // TODO check if this can happen\n if (!message) return;\n\n const isLast = getIsLast(thread, message);\n const branches = thread.getBranches(message.id);\n\n // if the message is the same, don't update\n const currentState = useMessage.getState();\n if (\n currentState.message === message &&\n currentState.parentId === parentId &&\n currentState.branches === branches &&\n currentState.isLast === isLast\n )\n return;\n\n // sync useMessage\n useMessage.setState({\n message,\n parentId,\n branches,\n isLast,\n });\n};\n\nconst useMessageContext = (messageIndex: number) => {\n const { useThread } = useThreadContext();\n\n const [context] = useState<MessageContextValue>(() => {\n const useMessage = create<MessageState>((set) => ({\n message: null as unknown as ThreadMessage,\n parentId: null,\n branches: [],\n isLast: false,\n inProgressIndicator: null,\n isCopied: false,\n isHovering: false,\n setInProgressIndicator: (value) => {\n set({ inProgressIndicator: value });\n },\n setIsCopied: (value) => {\n set({ isCopied: value });\n },\n setIsHovering: (value) => {\n set({ isHovering: value });\n },\n }));\n\n const useComposer = makeEditComposerStore({\n onEdit: () => {\n const message = useMessage.getState().message;\n if (message.role !== \"user\")\n throw new Error(\n \"Tried to edit a non-user message. Editing is only supported for user messages. This is likely an internal bug in assistant-ui.\",\n );\n\n const text = getMessageText(message);\n\n return text;\n },\n onSend: (text) => {\n const { message, parentId } = useMessage.getState();\n if (message.role !== \"user\")\n throw new Error(\n \"Tried to edit a non-user message. Editing is only supported for user messages. This is likely an internal bug in assistant-ui.\",\n );\n\n const nonTextParts = message.content.filter(\n (part): part is AppendContentPart =>\n part.type !== \"text\" && part.type !== \"ui\",\n );\n useThread.getState().append({\n parentId,\n content: [{ type: \"text\", text }, ...nonTextParts],\n });\n },\n });\n\n syncMessage(useThread.getState(), useMessage, messageIndex);\n\n return { useMessage, useComposer };\n });\n\n useEffect(() => {\n return useThread.subscribe((thread) => {\n syncMessage(thread, context.useMessage, messageIndex);\n });\n }, [context, useThread, messageIndex]);\n\n return context;\n};\n\nexport const MessageProvider: FC<MessageProviderProps> = ({\n messageIndex,\n children,\n}) => {\n const context = useMessageContext(messageIndex);\n\n return (\n <MessageContext.Provider value={context}>\n {children}\n </MessageContext.Provider>\n );\n};\n","import { type StoreApi, type UseBoundStore, create } from \"zustand\";\nimport { type BaseComposerState, makeBaseComposer } from \"./BaseComposer\";\n\nexport type EditComposerState = BaseComposerState &\n Readonly<{\n isEditing: boolean;\n\n edit: () => void;\n send: () => void;\n cancel: () => boolean;\n }>;\n\nexport const makeEditComposerStore = ({\n onEdit,\n onSend,\n}: {\n onEdit: () => string;\n onSend: (value: string) => void;\n}): UseBoundStore<StoreApi<EditComposerState>> =>\n create<EditComposerState>()((set, get, store) => ({\n ...makeBaseComposer(set, get, store),\n\n isEditing: false,\n\n edit: () => {\n const value = onEdit();\n set({ isEditing: true, value });\n },\n send: () => {\n const value = get().value;\n set({ isEditing: false });\n onSend(value);\n },\n cancel: () => {\n if (!get().isEditing) return false;\n set({ isEditing: false });\n return true;\n },\n }));\n","import type { StateCreator } from \"zustand\";\n\nexport type BaseComposerState = Readonly<{\n value: string;\n setValue: (value: string) => void;\n}>;\n\nexport const makeBaseComposer: StateCreator<\n BaseComposerState,\n [],\n [],\n BaseComposerState\n> = (set) => ({\n value: \"\",\n setValue: (value) => {\n set({ value });\n },\n});\n","import { useContext, useMemo } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as UseBoundStore<\n StoreApi<EditComposerState | ComposerState>\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useComposerContext } from \"../../context/ComposerContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype ComposerIfFilters = {\n editing: boolean | undefined;\n};\n\ntype ComposerIfProps = PropsWithChildren<RequireAtLeastOne<ComposerIfFilters>>;\n\nconst useComposerIf = (props: RequireAtLeastOne<ComposerIfFilters>) => {\n const { useComposer } = useComposerContext();\n return useComposer((composer) => {\n if (props.editing === true && !composer.isEditing) return false;\n if (props.editing === false && composer.isEditing) return false;\n\n return true;\n });\n};\n\nexport const ComposerIf: FC<ComposerIfProps> = ({ children, ...query }) => {\n const result = useComposerIf(query);\n return result ? children : null;\n};\n","\"use client\";\n\nimport type { FC, ReactNode } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype MessageIfFilters = {\n user: boolean | undefined;\n assistant: boolean | undefined;\n hasBranches: boolean | undefined;\n copied: boolean | undefined;\n lastOrHover: boolean | undefined;\n};\n\ntype MessageIfProps = RequireAtLeastOne<MessageIfFilters> & {\n children: ReactNode;\n};\n\nexport const useMessageIf = (props: RequireAtLeastOne<MessageIfFilters>) => {\n const { useMessage } = useMessageContext();\n\n return useMessage(({ message, branches, isLast, isCopied, isHovering }) => {\n if (props.hasBranches === true && branches.length < 2) return false;\n\n if (props.user && message.role !== \"user\") return false;\n if (props.assistant && message.role !== \"assistant\") return false;\n\n if (props.lastOrHover === true && !isHovering && !isLast) return false;\n\n if (props.copied === true && !isCopied) return false;\n if (props.copied === false && isCopied) return false;\n\n return true;\n });\n};\n\nexport const MessageIf: FC<MessageIfProps> = ({ children, ...query }) => {\n const result = useMessageIf(query);\n return result ? children : null;\n};\n","\"use client\";\n\nimport type { ComponentType, FC } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\nimport { MessageProvider } from \"../../context/providers/MessageProvider\";\nimport { ComposerIf } from \"../composer/ComposerIf\";\nimport { MessageIf } from \"../message/MessageIf\";\n\ntype ThreadMessagesProps = {\n components:\n | {\n Message: ComponentType;\n UserMessage?: ComponentType;\n EditComposer?: ComponentType;\n AssistantMessage?: ComponentType;\n }\n | {\n Message?: ComponentType;\n UserMessage: ComponentType;\n EditComposer?: ComponentType;\n AssistantMessage: ComponentType;\n };\n};\n\nconst getComponents = (components: ThreadMessagesProps[\"components\"]) => {\n return {\n EditComposer:\n components.EditComposer ??\n components.UserMessage ??\n (components.Message as ComponentType),\n UserMessage:\n components.UserMessage ?? (components.Message as ComponentType),\n AssistantMessage:\n components.AssistantMessage ?? (components.Message as ComponentType),\n };\n};\n\nexport const ThreadMessages: FC<ThreadMessagesProps> = ({ components }) => {\n const { useThread } = useThreadContext();\n const messagesLength = useThread((t) => t.messages.length);\n\n const { UserMessage, EditComposer, AssistantMessage } =\n getComponents(components);\n\n if (messagesLength === 0) return null;\n\n return (\n <>\n {new Array(messagesLength).fill(null).map((_, idx) => {\n const messageIndex = idx;\n // TODO avoid rerendering on messageLength change\n return (\n <MessageProvider\n key={messageIndex} // keep the same key when switching branches for better a11y support\n messageIndex={messageIndex}\n >\n <MessageIf user>\n <ComposerIf editing={false}>\n <UserMessage />\n </ComposerIf>\n <ComposerIf editing>\n <EditComposer />\n </ComposerIf>\n </MessageIf>\n <MessageIf assistant>\n <AssistantMessage />\n </MessageIf>\n </MessageProvider>\n );\n })}\n </>\n );\n};\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\n\ntype ThreadScrollToBottomElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\ntype ThreadScrollToBottomProps = PrimitiveButtonProps;\n\nexport const ThreadScrollToBottom = forwardRef<\n ThreadScrollToBottomElement,\n ThreadScrollToBottomProps\n>(({ onClick, ...rest }, ref) => {\n const { useViewport } = useThreadContext();\n\n const isAtBottom = useViewport((s) => s.isAtBottom);\n const handleScrollToBottom = () => {\n useViewport.getState().scrollToBottom();\n };\n\n return (\n <Primitive.button\n {...rest}\n disabled={isAtBottom}\n ref={ref}\n onClick={composeEventHandlers(onClick, handleScrollToBottom)}\n />\n );\n});\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\n\ntype ThreadSuggestionElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\ntype ThreadSuggestionProps = PrimitiveButtonProps & {\n prompt: string;\n method: \"replace\";\n autoSend?: boolean;\n};\n\nexport const ThreadSuggestion = forwardRef<\n ThreadSuggestionElement,\n ThreadSuggestionProps\n>(({ onClick, prompt, method, autoSend: send, ...rest }, ref) => {\n const { useThread, useComposer } = useThreadContext();\n\n const isDisabled = useThread((t) => t.isRunning);\n const handleApplySuggestion = () => {\n const thread = useThread.getState();\n const composer = useComposer.getState();\n composer.setValue(prompt);\n\n if (send && !thread.isRunning) {\n composer.send();\n }\n };\n\n return (\n <Primitive.button\n {...rest}\n disabled={isDisabled}\n ref={ref}\n onClick={composeEventHandlers(onClick, handleApplySuggestion)}\n />\n );\n});\n","export { ComposerRoot as Root } from \"./ComposerRoot\";\nexport { ComposerInput as Input } from \"./ComposerInput\";\nexport { ComposerSend as Send } from \"./ComposerSend\";\nexport { ComposerCancel as Cancel } from \"./ComposerCancel\";\nexport { ComposerIf as If } from \"./ComposerIf\";\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, type FormEvent, forwardRef, useRef } from \"react\";\nimport { useComposerContext } from \"../../context/ComposerContext\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\n\ntype ComposerRootElement = ElementRef<typeof Primitive.form>;\ntype PrimitiveFormProps = ComponentPropsWithoutRef<typeof Primitive.form>;\n\ntype ComposerRootProps = PrimitiveFormProps;\n\nexport const ComposerRoot = forwardRef<ComposerRootElement, ComposerRootProps>(\n ({ onSubmit, ...rest }, forwardedRef) => {\n const { useViewport } = useThreadContext();\n const { useComposer } = useComposerContext();\n\n const formRef = useRef<HTMLFormElement>(null);\n const ref = useComposedRefs(forwardedRef, formRef);\n\n const handleSubmit = (e: FormEvent) => {\n const composerState = useComposer.getState();\n if (!composerState.isEditing) return;\n\n e.preventDefault();\n composerState.send();\n\n useViewport.getState().scrollToBottom();\n };\n\n return (\n <Primitive.form\n {...rest}\n ref={ref}\n onSubmit={composeEventHandlers(onSubmit, handleSubmit)}\n />\n );\n },\n);\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n type KeyboardEvent,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n} from \"react-textarea-autosize\";\nimport { useComposerContext } from \"../../context/ComposerContext\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\n\ntype ComposerInputProps = TextareaAutosizeProps & {\n asChild?: boolean;\n};\n\nexport const ComposerInput = forwardRef<\n HTMLTextAreaElement,\n ComposerInputProps\n>(\n (\n { autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest },\n forwardedRef,\n ) => {\n const { useThread, useViewport } = useThreadContext();\n const { useComposer, type } = useComposerContext();\n\n const value = useComposer((c) => {\n if (!c.isEditing) return \"\";\n return c.value;\n });\n\n const Component = asChild ? Slot : TextareaAutosize;\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (disabled) return;\n\n const composer = useComposer.getState();\n if (e.key === \"Escape\") {\n if (useComposer.getState().cancel()) {\n e.preventDefault();\n }\n } else if (e.key === \"Enter\" && e.shiftKey === false) {\n const isRunning = useThread.getState().isRunning;\n if (!isRunning) {\n e.preventDefault();\n composer.send();\n\n useViewport.getState().scrollToBottom();\n }\n }\n };\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n\n const autoFocusEnabled = autoFocus && !disabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus();\n textarea.setSelectionRange(\n textareaRef.current.value.length,\n textareaRef.current.value.length,\n );\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnScrollToBottom(() => {\n if (type === \"new\") {\n focus();\n }\n });\n\n return (\n <Component\n value={value}\n {...rest}\n ref={ref}\n disabled={disabled}\n onChange={composeEventHandlers(onChange, (e) => {\n const composerState = useComposer.getState();\n if (!composerState.isEditing) return;\n return composerState.setValue(e.target.value);\n })}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyPress)}\n />\n );\n },\n);\n","\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useComposerContext } from \"../../context/ComposerContext\";\n\ntype ComposerSendElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveFormProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\ntype ComposerSendProps = PrimitiveFormProps;\n\nexport const ComposerSend = forwardRef<ComposerSendElement, ComposerSendProps>(\n ({ disabled, ...rest }, ref) => {\n const { useComposer } = useComposerContext();\n const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);\n\n return (\n <Primitive.button\n type=\"submit\"\n {...rest}\n ref={ref}\n disabled={disabled || !hasValue}\n />\n );\n },\n);\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useComposerContext } from \"../../context/ComposerContext\";\n\ntype ComposerCancelElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveFormProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\ntype ComposerCancelProps = PrimitiveFormProps;\n\nexport const ComposerCancel = forwardRef<\n ComposerCancelElement,\n ComposerCancelProps\n>(({ onClick, ...rest }, ref) => {\n const { useComposer } = useComposerContext();\n\n const handleCancel = () => {\n useComposer.getState().cancel();\n };\n\n return (\n <Primitive.button\n type=\"button\"\n {...rest}\n ref={ref}\n onClick={composeEventHandlers(onClick, handleCancel)}\n />\n );\n});\n","export { MessageRoot as Root } from \"./MessageRoot\";\nexport { MessageIf as If } from \"./MessageIf\";\nexport { MessageContent as Content } from \"./MessageContent\";\nexport { MessageInProgress as InProgress } from \"./MessageInProgress\";\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\n\ntype MessageRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\ntype MessageRootProps = PrimitiveDivProps;\n\nexport const MessageRoot = forwardRef<MessageRootElement, MessageRootProps>(\n ({ onMouseEnter, onMouseLeave, ...rest }, ref) => {\n const { useMessage } = useMessageContext();\n const setIsHovering = useMessage((s) => s.setIsHovering);\n\n const handleMouseEnter = () => {\n setIsHovering(true);\n };\n const handleMouseLeave = () => {\n setIsHovering(false);\n };\n\n return (\n <Primitive.div\n {...rest}\n ref={ref}\n onMouseEnter={composeEventHandlers(onMouseEnter, handleMouseEnter)}\n onMouseLeave={composeEventHandlers(onMouseLeave, handleMouseLeave)}\n />\n );\n },\n);\n","\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { ContentPartContext } from \"../ContentPartContext\";\nimport type { ContentPartContextValue } from \"../ContentPartContext\";\nimport { useMessageContext } from \"../MessageContext\";\nimport type { MessageState } from \"../stores\";\nimport type { ContentPartState } from \"../stores/ContentPart\";\n\ntype ContentPartProviderProps = PropsWithChildren<{\n partIndex: number;\n}>;\n\nconst syncContentPart = (\n { message }: MessageState,\n useContentPart: ContentPartContextValue[\"useContentPart\"],\n partIndex: number,\n) => {\n const part = message.content[partIndex];\n // TODO check if this can happen\n if (!part) return;\n\n const messageStatus = message.role === \"assistant\" ? message.status : \"done\";\n const status =\n partIndex === message.content.length - 1 ? messageStatus : \"done\";\n\n useContentPart.setState({ part, status });\n};\n\nconst useContentPartContext = (partIndex: number) => {\n const { useMessage } = useMessageContext();\n const [context] = useState<ContentPartContextValue>(() => {\n const useContentPart = create<ContentPartState>(() => ({\n part: { type: \"text\", text: \"\" },\n status: \"done\",\n }));\n\n syncContentPart(useMessage.getState(), useContentPart, partIndex);\n\n return { useContentPart };\n });\n\n useEffect(() => {\n return useMessage.subscribe((message) => {\n syncContentPart(message, context.useContentPart, partIndex);\n });\n }, [context, useMessage, partIndex]);\n\n return context;\n};\n\nexport const ContentPartProvider: FC<ContentPartProviderProps> = ({\n partIndex,\n children,\n}) => {\n const context = useContentPartContext(partIndex);\n\n return (\n <ContentPartContext.Provider value={context}>\n {children}\n </ContentPartContext.Provider>\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\n\nexport type ContentPartContextValue = {\n useContentPart: UseBoundStore<StoreApi<ContentPartState>>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nexport const useContentPartContext = (): ContentPartContextValue => {\n const context = useContext(ContentPartContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >.\",\n );\n return context;\n};\n","import type { FC } from \"react\";\nimport { useContentPartContext } from \"../../context/ContentPartContext\";\nimport { useMessageContext } from \"../../context/MessageContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport const ContentPartInProgressIndicator: FC = () => {\n const { useMessage } = useMessageContext();\n const { useContentPart } = useContentPartContext();\n\n const indicator = useCombinedStore([useMessage, useContentPart], (m, c) =>\n c.status === \"in_progress\" ? m.inProgressIndicator : null,\n );\n return indicator;\n};\n","\"use client\";\n\nimport type { ComponentType, FC, ReactNode } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\nimport { ContentPartProvider } from \"../../context/providers/ContentPartProvider\";\nimport type {\n ImageContentPart,\n TextContentPart,\n ToolCallContentPart,\n UIContentPart,\n} from \"../../utils/AssistantTypes\";\nimport { ContentPartInProgressIndicator } from \"../contentPart/ContentPartInProgressIndicator\";\n\ntype MessageContentProps = {\n components?: {\n Text?: ComponentType<{ part: TextContentPart }>;\n Image?: ComponentType<{ part: ImageContentPart }>;\n UI?: ComponentType<{ part: UIContentPart }>;\n tools?: {\n by_name?: Record<string, ComponentType<{ part: ToolCallContentPart }>>;\n Fallback?: ComponentType<{ part: ToolCallContentPart }>;\n };\n };\n};\n\nconst defaultComponents = {\n Text: ({ part }) => (\n <>\n {part.text}\n <ContentPartInProgressIndicator />\n </>\n ),\n Image: () => null,\n UI: ({ part }) => part.display,\n tools: {\n Fallback: () => null,\n },\n} satisfies MessageContentProps[\"components\"];\n\nexport const MessageContent: FC<MessageContentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Image = defaultComponents.Image,\n UI = defaultComponents.UI,\n tools: { by_name = {}, Fallback = defaultComponents.tools.Fallback } = {},\n } = {},\n}) => {\n const { useMessage } = useMessageContext();\n\n const message = useMessage((s) => s.message);\n const content = message.content;\n\n return (\n <>\n {content.map((part, i) => {\n const partIndex = i; // use the index as key, as message is generally append only\n\n const type = part.type;\n let component: ReactNode | null = null;\n switch (type) {\n case \"text\":\n component = <Text part={part} />;\n break;\n\n case \"image\":\n component = <Image part={part} />;\n break;\n case \"ui\":\n component = <UI part={part} />;\n break;\n case \"tool-call\": {\n const Tool = by_name[part.name] || Fallback;\n component = <Tool part={part} />;\n break;\n }\n default:\n throw new Error(`Unknown content part type: ${type}`);\n }\n\n return (\n <ContentPartProvider key={partIndex} partIndex={partIndex}>\n {component}\n </ContentPartProvider>\n );\n })}\n </>\n );\n};\n","\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, useMemo } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\n\ntype MessageInProgressElement = ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.span>;\n\ntype MessageInProgressProps = PrimitiveSpanProps;\n\nexport const MessageInProgress = forwardRef<\n MessageInProgressElement,\n MessageInProgressProps\n>((props, ref) => {\n const { useMessage } = useMessageContext();\n\n useMemo(() => {\n useMessage\n .getState()\n .setInProgressIndicator(<Primitive.span {...props} ref={ref} />);\n }, [useMessage, props, ref]);\n\n return null;\n});\n","export { BranchPickerNext as Next } from \"./BranchPickerNext\";\nexport { BranchPickerPrevious as Previous } from \"./BranchPickerPrevious\";\nexport { BranchPickerCount as Count } from \"./BranchPickerCount\";\nexport { BranchPickerNumber as Number } from \"./BranchPickerNumber\";\nexport { BranchPickerRoot as Root } from \"./BranchPickerRoot\";\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\n\ntype ActionButtonCallback<TProps> = (props: TProps) => null | (() => void);\n\nexport const createActionButton = <TProps,>(\n useActionButton: ActionButtonCallback<TProps>,\n) => {\n type PrimitiveButtonElement = ElementRef<typeof Primitive.button>;\n type PrimitiveButtonProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\n return forwardRef<PrimitiveButtonElement, PrimitiveButtonProps & TProps>(\n (props, forwardedRef) => {\n const onClick = useActionButton(props);\n\n return (\n <Primitive.button\n type=\"button\"\n disabled={!onClick}\n {...props}\n ref={forwardedRef}\n onClick={composeEventHandlers(props.onClick, onClick ?? undefined)}\n />\n );\n },\n );\n};\n","\"use client\";\n\nimport { useGoToNextBranch } from \"../../actions/useGoToNextBranch\";\nimport { createActionButton } from \"../../utils/createActionButton\";\n\nexport const BranchPickerNext = createActionButton(useGoToNextBranch);\n","\"use client\";\n\nimport { useGoToPreviousBranch } from \"../../actions/useGoToPreviousBranch\";\nimport { createActionButton } from \"../../utils/createActionButton\";\n\nexport const BranchPickerPrevious = createActionButton(useGoToPreviousBranch);\n","\"use client\";\n\nimport type { FC } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\n\nexport const BranchPickerCount: FC = () => {\n const { useMessage } = useMessageContext();\n const branchCount = useMessage((s) => s.branches.length);\n return <>{branchCount}</>;\n};\n","\"use client\";\n\nimport type { FC } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\n\nexport const BranchPickerNumber: FC = () => {\n const { useMessage } = useMessageContext();\n const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));\n return <>{branchIdx + 1}</>;\n};\n","\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { If } from \"../message\";\n\ntype BranchPickerRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\ntype BranchPickerRootProps = PrimitiveDivProps & {\n hideWhenSingleBranch?: boolean;\n};\n\nexport const BranchPickerRoot = forwardRef<\n BranchPickerRootElement,\n BranchPickerRootProps\n>(({ hideWhenSingleBranch, ...rest }, ref) => {\n return (\n <If hasBranches={hideWhenSingleBranch ? true : undefined}>\n <Primitive.div {...rest} ref={ref} />\n </If>\n );\n});\n","export { ActionBarRoot as Root } from \"./ActionBarRoot\";\nexport { ActionBarCopy as Copy } from \"./ActionBarCopy\";\nexport { ActionBarReload as Reload } from \"./ActionBarReload\";\nexport { ActionBarEdit as Edit } from \"./ActionBarEdit\";\n","\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\ntype ActionBarRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nenum HideAndFloatStatus {\n Hidden = \"hidden\",\n Floating = \"floating\",\n Normal = \"normal\",\n}\n\nexport type ActionBarRootProps = PrimitiveDivProps & {\n hideWhenRunning?: boolean;\n autohide?: \"always\" | \"not-last\" | \"never\";\n autohideFloat?: \"always\" | \"single-branch\" | \"never\";\n};\n\nexport const ActionBarRoot = forwardRef<\n ActionBarRootElement,\n ActionBarRootProps\n>(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {\n const { useThread } = useThreadContext();\n const { useMessage } = useMessageContext();\n\n const hideAndfloatStatus = useCombinedStore(\n [useThread, useMessage],\n (t, m) => {\n if (hideWhenRunning && t.isRunning) return HideAndFloatStatus.Hidden;\n\n const autohideEnabled =\n autohide === \"always\" || (autohide === \"not-last\" && !m.isLast);\n\n // normal status\n if (!autohideEnabled) return HideAndFloatStatus.Normal;\n\n // hidden status\n if (!m.isHovering) return HideAndFloatStatus.Hidden;\n\n // floating status\n if (\n autohideFloat === \"always\" ||\n (autohideFloat === \"single-branch\" && m.branches.length <= 1)\n )\n return HideAndFloatStatus.Floating;\n\n return HideAndFloatStatus.Normal;\n },\n );\n\n if (hideAndfloatStatus === HideAndFloatStatus.Hidden) return null;\n\n return (\n <Primitive.div\n data-floating={hideAndfloatStatus === HideAndFloatStatus.Floating}\n {...rest}\n ref={ref}\n />\n );\n});\n","\"use client\";\n\nimport { useCopyMessage } from \"../../actions/useCopyMessage\";\nimport { createActionButton } from \"../../utils/createActionButton\";\n\ntype ActionBarCopyProps = {\n copiedDuration?: number;\n};\n\nexport const ActionBarCopy =\n createActionButton<ActionBarCopyProps>(useCopyMessage);\n","\"use client\";\n\nimport { useReloadMessage } from \"../../actions/useReloadMessage\";\nimport { createActionButton } from \"../../utils/createActionButton\";\n\nexport const ActionBarReload = createActionButton(useReloadMessage);\n","\"use client\";\n\nimport { useBeginMessageEdit } from \"../../actions/useBeginMessageEdit\";\nimport { createActionButton } from \"../../utils/createActionButton\";\n\nexport const ActionBarEdit = createActionButton(useBeginMessageEdit);\n","export { ContentPartInProgressIndicator as InProgressIndicator } from \"./ContentPartInProgressIndicator\";\n","\"use client\";\n\nimport { useEffect, useInsertionEffect, useState } from \"react\";\nimport type { VercelRSCAdapter } from \"./VercelRSCAdapter\";\nimport { VercelRSCRuntime } from \"./VercelRSCRuntime\";\n\nexport const useVercelRSCRuntime = <T extends WeakKey>(\n adapter: VercelRSCAdapter<T>,\n) => {\n const [runtime] = useState(() => new VercelRSCRuntime(adapter));\n\n useInsertionEffect(() => {\n runtime.adapter = adapter;\n });\n useEffect(() => {\n runtime.onAdapterUpdated();\n });\n\n return runtime;\n};\n","\"use client\";\n\nimport { type StoreApi, type UseBoundStore, create } from \"zustand\";\nimport type {\n AppendMessage,\n ThreadMessage,\n} from \"../../../utils/AssistantTypes\";\nimport type { AssistantRuntime } from \"../../core/AssistantRuntime\";\nimport type { ReactThreadRuntime, Unsubscribe } from \"../../core/ThreadRuntime\";\nimport type { VercelRSCAdapter } from \"./VercelRSCAdapter\";\nimport type { VercelRSCMessage } from \"./VercelRSCMessage\";\nimport { useVercelRSCSync } from \"./useVercelRSCSync\";\n\nconst EMPTY_BRANCHES: readonly never[] = Object.freeze([]);\n\nexport class VercelRSCRuntime<T extends WeakKey = VercelRSCMessage>\n implements AssistantRuntime, ReactThreadRuntime\n{\n private useAdapter: UseBoundStore<StoreApi<{ adapter: VercelRSCAdapter<T> }>>;\n\n private _subscriptions = new Set<() => void>();\n\n public isRunning = false;\n public messages: ThreadMessage[] = [];\n\n constructor(public adapter: VercelRSCAdapter<T>) {\n this.useAdapter = create(() => ({\n adapter,\n }));\n }\n\n private withRunning = (callback: Promise<unknown>) => {\n this.isRunning = true;\n return callback.finally(() => {\n this.isRunning = false;\n });\n };\n\n public getBranches(): readonly string[] {\n return EMPTY_BRANCHES;\n }\n\n public switchToBranch(): void {\n throw new Error(\n \"Branch switching is not supported by VercelRSCAssistantProvider.\",\n );\n }\n\n public async append(message: AppendMessage): Promise<void> {\n if (message.parentId !== (this.messages.at(-1)?.id ?? null)) {\n if (!this.adapter.edit)\n throw new Error(\n \"Message editing is not enabled, please provide an edit callback to VercelRSCAssistantProvider.\",\n );\n await this.withRunning(this.adapter.edit(message));\n } else {\n await this.withRunning(this.adapter.append(message));\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n if (!this.adapter.reload)\n throw new Error(\n \"Message reloading is not enabled, please provide a reload callback to VercelRSCAssistantProvider.\",\n );\n await this.withRunning(this.adapter.reload(parentId));\n }\n\n cancelRun(): void {\n // in dev mode, log a warning\n if (process.env[\"NODE_ENV\"] === \"development\") {\n console.warn(\n \"Run cancellation is not supported by VercelRSCAssistantProvider.\",\n );\n }\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n public onAdapterUpdated() {\n if (this.useAdapter.getState().adapter !== this.adapter) {\n this.useAdapter.setState({ adapter: this.adapter });\n }\n }\n\n private updateData = (messages: ThreadMessage[]) => {\n this.messages = messages;\n for (const callback of this._subscriptions) callback();\n };\n\n unstable_synchronizer = () => {\n const { adapter } = this.useAdapter();\n\n useVercelRSCSync(adapter, this.updateData);\n\n return null;\n };\n}\n","import { useEffect, useMemo } from \"react\";\nimport type {\n ThreadMessage,\n VercelRSCAdapter,\n VercelRSCMessage,\n} from \"../../../../dist\";\nimport {\n type ConverterCallback,\n ThreadMessageConverter,\n} from \"../utils/ThreadMessageConverter\";\nimport {\n type VercelRSCThreadMessage,\n symbolInnerRSCMessage,\n} from \"./getVercelRSCMessage\";\n\nconst vercelToThreadMessage = <T,>(\n converter: (message: T) => VercelRSCMessage,\n rawMessage: T,\n): VercelRSCThreadMessage<T> => {\n const message = converter(rawMessage);\n\n return {\n id: message.id,\n role: message.role,\n content: [{ type: \"ui\", display: message.display }],\n createdAt: message.createdAt ?? new Date(),\n ...{ status: \"done\" },\n [symbolInnerRSCMessage]: rawMessage,\n };\n};\n\ntype UpdateDataCallback = (messages: ThreadMessage[]) => void;\n\nexport const useVercelRSCSync = <T extends WeakKey>(\n adapter: VercelRSCAdapter<T>,\n updateData: UpdateDataCallback,\n) => {\n // flush the converter cache when the convertMessage prop changes\n const [converter, convertCallback] = useMemo(() => {\n const rscConverter =\n adapter.convertMessage ?? ((m: T) => m as VercelRSCMessage);\n const convertCallback: ConverterCallback<T> = (m, cache) => {\n if (cache) return cache;\n return vercelToThreadMessage(rscConverter, m);\n };\n return [new ThreadMessageConverter(), convertCallback];\n }, [adapter.convertMessage]);\n\n useEffect(() => {\n updateData(converter.convertMessages(adapter.messages, convertCallback));\n }, [updateData, converter, convertCallback, adapter.messages]);\n};\n","\"use client\";\n\nimport type { ThreadMessage } from \"../../../utils/AssistantTypes\";\n\nexport type ConverterCallback<TIn> = (\n message: TIn,\n cache: ThreadMessage | undefined,\n) => ThreadMessage;\n\nexport class ThreadMessageConverter {\n private readonly cache = new WeakMap<WeakKey, ThreadMessage>();\n\n convertMessages<TIn extends WeakKey>(\n messages: TIn[],\n converter: ConverterCallback<TIn>,\n keyMapper: (m: TIn) => WeakKey = (key) => key,\n ): ThreadMessage[] {\n return messages.map((m) => {\n const key = keyMapper(m);\n const cached = this.cache.get(key);\n const newMessage = converter(m, cached);\n this.cache.set(key, newMessage);\n return newMessage;\n });\n }\n}\n","import type { ThreadMessage } from \"../../../utils/AssistantTypes\";\n\nexport const symbolInnerRSCMessage = Symbol(\"innerVercelRSCMessage\");\n\nexport type VercelRSCThreadMessage<T> = ThreadMessage & {\n [symbolInnerRSCMessage]?: T;\n};\n\nexport const getVercelRSCMessage = <T,>(message: ThreadMessage) => {\n return (message as VercelRSCThreadMessage<T>)[symbolInnerRSCMessage];\n};\n","import type { UseChatHelpers } from \"@ai-sdk/react\";\nimport { useEffect, useInsertionEffect, useState } from \"react\";\nimport { VercelAIRuntime } from \"../VercelAIRuntime\";\n\nexport const useVercelUseChatRuntime = (chatHelpers: UseChatHelpers) => {\n const [runtime] = useState(() => new VercelAIRuntime(chatHelpers));\n\n useInsertionEffect(() => {\n runtime.vercel = chatHelpers;\n });\n useEffect(() => {\n runtime.onVercelUpdated();\n });\n\n return runtime;\n};\n","import type { Message } from \"ai\";\nimport { type StoreApi, type UseBoundStore, create } from \"zustand\";\nimport type {\n AppendMessage,\n ThreadMessage,\n} from \"../../../utils/AssistantTypes\";\nimport type { AssistantRuntime } from \"../../core/AssistantRuntime\";\nimport type { ReactThreadRuntime, Unsubscribe } from \"../../core/ThreadRuntime\";\nimport { MessageRepository } from \"../../utils/MessageRepository\";\nimport { getVercelAIMessage } from \"./getVercelAIMessage\";\nimport type { VercelHelpers } from \"./utils/VercelHelpers\";\nimport { sliceMessagesUntil } from \"./utils/sliceMessagesUntil\";\nimport { useVercelAIComposerSync } from \"./utils/useVercelAIComposerSync\";\nimport { useVercelAIThreadSync } from \"./utils/useVercelAIThreadSync\";\n\nconst hasUpcomingMessage = (isRunning: boolean, messages: ThreadMessage[]) => {\n return isRunning && messages[messages.length - 1]?.role !== \"assistant\";\n};\n\nexport class VercelAIRuntime implements AssistantRuntime, ReactThreadRuntime {\n private _subscriptions = new Set<() => void>();\n private repository = new MessageRepository();\n private assistantOptimisticId: string | null = null;\n\n private useVercel: UseBoundStore<StoreApi<{ vercel: VercelHelpers }>>;\n\n public messages: ThreadMessage[] = [];\n public isRunning = false;\n\n constructor(public vercel: VercelHelpers) {\n this.useVercel = create(() => ({\n vercel,\n }));\n }\n\n public getBranches(messageId: string): string[] {\n return this.repository.getBranches(messageId);\n }\n\n public switchToBranch(branchId: string): void {\n this.repository.switchToBranch(branchId);\n this.updateVercelMessages(this.repository.getMessages());\n }\n\n public async append(message: AppendMessage): Promise<void> {\n // add user message\n if (message.content.length !== 1 || message.content[0]?.type !== \"text\")\n throw new Error(\"Only text content is supported by Vercel AI SDK.\");\n\n const newMessages = sliceMessagesUntil(\n this.vercel.messages,\n message.parentId,\n );\n this.vercel.setMessages(newMessages);\n\n await this.vercel.append({\n role: \"user\",\n content: message.content[0].text,\n });\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n const reloadMaybe =\n \"reload\" in this.vercel ? this.vercel.reload : undefined;\n if (!reloadMaybe)\n throw new Error(\n \"Reload is not supported by Vercel AI SDK's useAssistant.\",\n );\n\n const newMessages = sliceMessagesUntil(this.vercel.messages, parentId);\n this.vercel.setMessages(newMessages);\n\n await reloadMaybe();\n }\n\n public cancelRun(): void {\n const previousMessage = this.vercel.messages.at(-1);\n\n this.vercel.stop();\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n let messages = this.repository.getMessages();\n if (\n previousMessage?.role === \"user\" &&\n previousMessage.id === messages.at(-1)?.id // ensure the previous message is a leaf node\n ) {\n this.vercel.setInput(previousMessage.content);\n this.repository.deleteMessage(previousMessage.id);\n\n messages = this.repository.getMessages();\n }\n\n // resync messages\n setTimeout(() => {\n this.updateVercelMessages(messages);\n }, 0);\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private updateVercelMessages = (messages: ThreadMessage[]) => {\n this.vercel.setMessages(\n messages\n .flatMap(getVercelAIMessage)\n .filter((m): m is Message => m != null),\n );\n };\n\n public onVercelUpdated() {\n if (this.useVercel.getState().vercel !== this.vercel) {\n this.useVercel.setState({ vercel: this.vercel });\n }\n }\n\n private updateData = (isRunning: boolean, vm: ThreadMessage[]) => {\n for (let i = 0; i < vm.length; i++) {\n const message = vm[i]!;\n const parent = vm[i - 1];\n this.repository.addOrUpdateMessage(parent?.id ?? null, message);\n }\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n if (hasUpcomingMessage(isRunning, vm)) {\n this.assistantOptimisticId = this.repository.appendOptimisticMessage(\n vm.at(-1)?.id ?? null,\n {\n role: \"assistant\",\n content: [{ type: \"text\", text: \"\" }],\n },\n );\n }\n\n this.repository.resetHead(\n this.assistantOptimisticId ?? vm.at(-1)?.id ?? null,\n );\n\n this.messages = this.repository.getMessages();\n this.isRunning = isRunning;\n\n for (const callback of this._subscriptions) callback();\n };\n\n unstable_synchronizer = () => {\n const { vercel } = this.useVercel();\n\n useVercelAIThreadSync(vercel, this.updateData);\n useVercelAIComposerSync(vercel);\n\n return null;\n };\n}\n","\"use client\";\nimport { customAlphabet } from \"nanoid/non-secure\";\n\nexport const generateId = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n);\n\nconst optimisticPrefix = \"__optimistic__\";\nexport const generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;\nexport const isOptimisticId = (id: string) => id.startsWith(optimisticPrefix);\n","\"use client\";\n\nimport type { ThreadMessage } from \"../../utils/AssistantTypes\";\nimport { generateOptimisticId } from \"./idUtils\";\n\ntype RepositoryParent = {\n children: string[];\n};\n\ntype RepositoryMessage = RepositoryParent & {\n prev: RepositoryMessage | null;\n current: ThreadMessage;\n next: RepositoryMessage | null;\n level: number;\n};\n\nconst findHead = (message: RepositoryMessage): RepositoryMessage => {\n if (message.next) return findHead(message.next);\n return message;\n};\n\nexport class MessageRepository {\n private messages = new Map<string, RepositoryMessage>(); // message_id -> item\n private head: RepositoryMessage | null = null;\n private root: RepositoryParent = {\n children: [],\n };\n\n private performOp(\n newParent: RepositoryMessage | null,\n child: RepositoryMessage,\n operation: \"cut\" | \"link\" | \"relink\",\n ) {\n const parentOrRoot = child.prev ?? this.root;\n const newParentOrRoot = newParent ?? this.root;\n\n if (operation === \"relink\" && parentOrRoot === newParentOrRoot) return;\n\n // cut\n if (operation !== \"link\") {\n parentOrRoot.children = parentOrRoot.children.filter(\n (m) => m !== child.current.id,\n );\n\n if (child.prev?.next === child) {\n const fallbackId = child.prev.children.at(-1);\n const fallback = fallbackId ? this.messages.get(fallbackId) : null;\n if (fallback === undefined) {\n throw new Error(\n \"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.\",\n );\n }\n child.prev.next = fallback;\n }\n }\n\n // link\n if (operation !== \"cut\") {\n newParentOrRoot.children = [\n ...newParentOrRoot.children,\n child.current.id,\n ];\n\n if (\n newParent &&\n (findHead(child) === this.head || newParent.next === null)\n ) {\n newParent.next = child;\n }\n\n child.prev = newParent;\n }\n }\n getMessages() {\n const messages = new Array<ThreadMessage>(this.head?.level ?? 0);\n for (let current = this.head; current; current = current.prev) {\n messages[current.level] = current.current;\n }\n return messages;\n }\n\n addOrUpdateMessage(parentId: string | null, message: ThreadMessage) {\n const existingItem = this.messages.get(message.id);\n const prev = parentId ? this.messages.get(parentId) : null;\n if (prev === undefined)\n throw new Error(\n \"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n // update existing message\n if (existingItem) {\n existingItem.current = message;\n this.performOp(prev, existingItem, \"relink\");\n return;\n }\n\n // create a new message\n const newItem: RepositoryMessage = {\n prev,\n current: message,\n next: null,\n children: [],\n level: prev ? prev.level + 1 : 0,\n };\n\n this.messages.set(message.id, newItem);\n this.performOp(prev, newItem, \"link\");\n\n if (this.head === prev) {\n this.head = newItem;\n }\n }\n\n appendOptimisticMessage(\n parentId: string | null,\n message: Omit<ThreadMessage, \"id\" | \"createdAt\">,\n ) {\n let optimisticId: string;\n do {\n optimisticId = generateOptimisticId();\n } while (this.messages.has(optimisticId));\n\n this.addOrUpdateMessage(parentId, {\n ...message,\n id: optimisticId,\n createdAt: new Date(),\n ...(message.role === \"assistant\" ? { status: \"in_progress\" } : undefined),\n } as ThreadMessage);\n\n return optimisticId;\n }\n\n deleteMessage(messageId: string, replacementId?: string | null | undefined) {\n const message = this.messages.get(messageId);\n\n if (!message)\n throw new Error(\n \"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const replacement =\n replacementId === undefined\n ? message.prev // if no replacementId is provided, use the parent\n : replacementId === null\n ? null\n : this.messages.get(replacementId);\n if (replacement === undefined)\n throw new Error(\n \"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.\",\n );\n\n for (const child of message.children) {\n const childMessage = this.messages.get(child);\n if (!childMessage)\n throw new Error(\n \"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.\",\n );\n this.performOp(replacement, childMessage, \"relink\");\n }\n\n this.performOp(null, message, \"cut\");\n this.messages.delete(messageId);\n\n if (this.head === message) {\n this.head = replacement ? findHead(replacement) : null;\n }\n }\n\n getBranches(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const { children } = message.prev ?? this.root;\n return children;\n }\n\n switchToBranch(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n if (message.prev) {\n message.prev.next = message;\n }\n\n this.head = findHead(message);\n }\n\n resetHead(messageId: string | null) {\n if (messageId === null) {\n this.head = null;\n return;\n }\n\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n this.head = message;\n for (\n let current: RepositoryMessage | null = message;\n current;\n current = current.prev\n ) {\n if (current.prev) {\n current.prev.next = current;\n }\n }\n }\n}\n","import type { Message } from \"ai\";\nimport type { ThreadMessage } from \"../../../utils/AssistantTypes\";\n\nexport const symbolInnerAIMessage = Symbol(\"innerVercelAIUIMessage\");\n\nexport type VercelAIThreadMessage = ThreadMessage & {\n [symbolInnerAIMessage]?: Message[];\n};\n\nexport const getVercelAIMessage = (message: ThreadMessage) => {\n return (message as VercelAIThreadMessage)[symbolInnerAIMessage];\n};\n","import type { Message } from \"ai\";\n\nexport const sliceMessagesUntil = (\n messages: Message[],\n messageId: string | null,\n) => {\n if (messageId == null) return [];\n\n let messageIdx = messages.findIndex((m) => m.id === messageId);\n if (messageIdx === -1)\n throw new Error(\n \"useVercelAIThreadState: Message not found. This is liekly an internal bug in assistant-ui.\",\n );\n\n while (messages[messageIdx + 1]?.role === \"assistant\") {\n messageIdx++;\n }\n\n return messages.slice(0, messageIdx + 1);\n};\n","import { useEffect } from \"react\";\nimport { useThreadContext } from \"../../../../context\";\nimport type { VercelHelpers } from \"./VercelHelpers\";\n\n// two way sync between vercel helpers input state and composer text state\nexport const useVercelAIComposerSync = (vercel: VercelHelpers) => {\n const { useComposer } = useThreadContext();\n\n useEffect(() => {\n useComposer.setState({\n value: vercel.input,\n setValue: vercel.setInput,\n });\n }, [useComposer, vercel.input, vercel.setInput]);\n};\n","import type { Message } from \"ai\";\nimport { useEffect, useMemo } from \"react\";\nimport type {\n TextContentPart,\n ThreadMessage,\n ToolCallContentPart,\n} from \"../../../../utils/AssistantTypes\";\nimport {\n type ConverterCallback,\n ThreadMessageConverter,\n} from \"../../utils/ThreadMessageConverter\";\nimport {\n type VercelAIThreadMessage,\n symbolInnerAIMessage,\n} from \"../getVercelAIMessage\";\nimport type { VercelHelpers } from \"./VercelHelpers\";\n\nconst getIsRunning = (vercel: VercelHelpers) => {\n if (\"isLoading\" in vercel) return vercel.isLoading;\n return vercel.status === \"in_progress\";\n};\n\nconst vercelToThreadMessage = (\n messages: Message[],\n status: \"in_progress\" | \"done\" | \"error\",\n): VercelAIThreadMessage => {\n const firstMessage = messages[0];\n if (!firstMessage) throw new Error(\"No messages found\");\n\n const common = {\n id: firstMessage.id,\n createdAt: firstMessage.createdAt ?? new Date(),\n [symbolInnerAIMessage]: messages,\n };\n\n switch (firstMessage.role) {\n case \"user\":\n if (messages.length > 1) {\n throw new Error(\n \"Multiple user messages found. This is likely an internal bug in assistant-ui.\",\n );\n }\n\n return {\n ...common,\n role: \"user\",\n content: [{ type: \"text\", text: firstMessage.content }],\n };\n case \"assistant\":\n return {\n ...common,\n role: \"assistant\",\n content: messages.flatMap((message) => [\n ...(message.content\n ? [{ type: \"text\", text: message.content } as TextContentPart]\n : []),\n ...(message.toolInvocations?.map(\n (t) =>\n ({\n type: \"tool-call\",\n name: t.toolName,\n args: t.args,\n result: \"result\" in t ? t.result : undefined,\n }) as ToolCallContentPart,\n ) ?? []),\n ]),\n status,\n };\n default:\n throw new Error(\n `You have a message with an unsupported role. The role ${firstMessage.role} is not supported.`,\n );\n }\n};\n\ntype Chunk = [Message, ...Message[]];\nconst hasItems = (messages: Message[]): messages is Chunk =>\n messages.length > 0;\n\nconst chunkedMessages = (messages: Message[]): Chunk[] => {\n const chunks: Chunk[] = [];\n let currentChunk: Message[] = [];\n\n for (const message of messages) {\n if (message.role === \"assistant\") {\n currentChunk.push(message);\n } else {\n if (hasItems(currentChunk)) {\n chunks.push(currentChunk);\n currentChunk = [];\n }\n chunks.push([message]);\n }\n }\n\n if (hasItems(currentChunk)) {\n chunks.push(currentChunk);\n }\n\n return chunks;\n};\n\nconst shallowArrayEqual = (a: unknown[], b: unknown[]) => {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n};\n\ntype UpdateDataCallback = (isRunning: boolean, vm: ThreadMessage[]) => void;\n\nexport const useVercelAIThreadSync = (\n vercel: VercelHelpers,\n updateData: UpdateDataCallback,\n) => {\n const isRunning = getIsRunning(vercel);\n\n const converter = useMemo(() => new ThreadMessageConverter(), []);\n\n useEffect(() => {\n const lastMessageId = vercel.messages.at(-1)?.id;\n const convertCallback: ConverterCallback<Chunk> = (messages, cache) => {\n const status =\n lastMessageId === messages[0].id && isRunning ? \"in_progress\" : \"done\";\n\n if (\n cache &&\n shallowArrayEqual(cache.content, messages) &&\n (cache.role === \"user\" || cache.status === status)\n )\n return cache;\n\n return vercelToThreadMessage(messages, status);\n };\n\n const messages = converter.convertMessages(\n chunkedMessages(vercel.messages),\n convertCallback,\n (m) => m[0],\n );\n\n updateData(isRunning, messages);\n }, [updateData, isRunning, vercel.messages, converter]);\n};\n","import type { UseAssistantHelpers } from \"@ai-sdk/react\";\nimport { useEffect, useInsertionEffect, useState } from \"react\";\nimport { VercelAIRuntime } from \"../VercelAIRuntime\";\n\nexport const useVercelUseAssistantRuntime = (\n assistantHelpers: UseAssistantHelpers,\n) => {\n const [runtime] = useState(() => new VercelAIRuntime(assistantHelpers));\n\n useInsertionEffect(() => {\n runtime.vercel = assistantHelpers;\n });\n useEffect(() => {\n runtime.onVercelUpdated();\n });\n\n return runtime;\n};\n","import type { FC, PropsWithChildren } from \"react\";\nimport { memo } from \"react\";\nimport type { AssistantRuntime } from \"../../runtime/core/AssistantRuntime\";\nimport { ThreadProvider } from \"./ThreadProvider\";\n\ntype AssistantRuntimeProviderProps = {\n runtime: AssistantRuntime;\n};\n\nconst AssistantRuntimeProviderImpl: FC<\n PropsWithChildren<AssistantRuntimeProviderProps>\n> = ({ children, runtime }) => {\n return <ThreadProvider runtime={runtime}>{children}</ThreadProvider>;\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n","import type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useInsertionEffect, useRef, useState } from \"react\";\nimport type {\n ReactThreadRuntime,\n ThreadRuntime,\n} from \"../../runtime/core/ThreadRuntime\";\nimport type { ThreadContextValue } from \"../ThreadContext\";\nimport { ThreadContext } from \"../ThreadContext\";\nimport { makeComposerStore } from \"../stores/Composer\";\nimport { makeThreadStore } from \"../stores/Thread\";\nimport { makeThreadViewportStore } from \"../stores/ThreadViewport\";\n\ntype ThreadProviderProps = {\n runtime: ThreadRuntime;\n};\n\nexport const ThreadProvider: FC<PropsWithChildren<ThreadProviderProps>> = ({\n children,\n runtime,\n}) => {\n const runtimeRef = useRef(runtime);\n useInsertionEffect(() => {\n runtimeRef.current = runtime;\n });\n\n const [{ context, onRuntimeUpdate }] = useState(() => {\n const { useThread, onRuntimeUpdate } = makeThreadStore(runtimeRef);\n const useViewport = makeThreadViewportStore();\n const useComposer = makeComposerStore(useThread);\n\n return {\n context: {\n useViewport,\n useThread,\n useComposer,\n } satisfies ThreadContextValue,\n onRuntimeUpdate,\n };\n });\n\n useEffect(() => {\n // whenever the runtime changes\n onRuntimeUpdate();\n\n // subscribe to runtime updates\n return runtime.subscribe(onRuntimeUpdate);\n }, [onRuntimeUpdate, runtime]);\n\n const RuntimeSynchronizer = (runtime as ReactThreadRuntime)\n .unstable_synchronizer;\n\n return (\n <ThreadContext.Provider value={context}>\n {RuntimeSynchronizer && <RuntimeSynchronizer />}\n {children}\n </ThreadContext.Provider>\n );\n};\n","import { type StoreApi, type UseBoundStore, create } from \"zustand\";\nimport { type BaseComposerState, makeBaseComposer } from \"./BaseComposer\";\nimport type { ThreadState } from \"./Thread\";\n\nexport type ComposerState = BaseComposerState &\n Readonly<{\n isEditing: true;\n\n send: () => void;\n cancel: () => boolean;\n }>;\n\nexport const makeComposerStore = (\n useThread: StoreApi<ThreadState>,\n): UseBoundStore<StoreApi<ComposerState>> =>\n create<ComposerState>()((set, get, store) => {\n return {\n ...makeBaseComposer(set, get, store),\n\n isEditing: true,\n\n send: () => {\n const { setValue, value } = get();\n setValue(\"\");\n\n useThread.getState().append({\n parentId: useThread.getState().messages.at(-1)?.id ?? null,\n content: [{ type: \"text\", text: value }],\n });\n },\n cancel: () => {\n const thread = useThread.getState();\n if (!thread.isRunning) return false;\n\n useThread.getState().cancelRun();\n return true;\n },\n };\n });\n","import type { MutableRefObject } from \"react\";\nimport { create } from \"zustand\";\nimport type { AppendMessage, ThreadMessage } from \"../../utils/AssistantTypes\";\n\nexport type ThreadState = {\n messages: ThreadMessage[];\n isRunning: boolean;\n\n getBranches: (messageId: string) => readonly string[];\n switchToBranch: (branchId: string) => void;\n\n append: (message: AppendMessage) => void;\n startRun: (parentId: string | null) => void;\n cancelRun: () => void;\n};\n\nexport const makeThreadStore = (runtimeRef: MutableRefObject<ThreadState>) => {\n const useThread = create<ThreadState>(() => ({\n messages: runtimeRef.current.messages,\n isRunning: runtimeRef.current.isRunning,\n getBranches: (messageId) => runtimeRef.current.getBranches(messageId),\n switchToBranch: (branchId) => runtimeRef.current.switchToBranch(branchId),\n startRun: (parentId) => runtimeRef.current.startRun(parentId),\n append: (message) => runtimeRef.current.append(message),\n cancelRun: () => runtimeRef.current.cancelRun(),\n }));\n\n const onRuntimeUpdate = () => {\n useThread.setState({\n messages: runtimeRef.current.messages,\n isRunning: runtimeRef.current.isRunning,\n });\n };\n\n return {\n useThread,\n onRuntimeUpdate,\n };\n};\n","\"use client\";\nimport { create } from \"zustand\";\n\nexport type ThreadViewportState = {\n isAtBottom: boolean;\n scrollToBottom: () => void;\n onScrollToBottom: (callback: () => void) => () => void;\n};\n\nexport const makeThreadViewportStore = () => {\n const scrollToBottomListeners = new Set<() => void>();\n\n return create<ThreadViewportState>(() => ({\n isAtBottom: true,\n scrollToBottom: () => {\n for (const listener of scrollToBottomListeners) {\n listener();\n }\n },\n onScrollToBottom: (callback) => {\n scrollToBottomListeners.add(callback);\n return () => {\n scrollToBottomListeners.delete(callback);\n };\n },\n }));\n};\n","\"use client\";\n\nimport type { UseAssistantHelpers, UseChatHelpers } from \"@ai-sdk/react\";\nimport type { FC, PropsWithChildren } from \"react\";\nimport { AssistantRuntimeProvider } from \"../../context/providers/AssistantRuntimeProvider\";\nimport {\n useVercelUseAssistantRuntime,\n useVercelUseChatRuntime,\n} from \"../vercel-ai\";\n\ntype VercelUseChatRuntimeProps = PropsWithChildren<{\n chat: UseChatHelpers;\n}>;\n\nconst VercelUseChatRuntimeProvider: FC<VercelUseChatRuntimeProps> = ({\n chat,\n children,\n}) => {\n const runtime = useVercelUseChatRuntime(chat);\n\n return (\n <AssistantRuntimeProvider runtime={runtime}>\n {children}\n </AssistantRuntimeProvider>\n );\n};\n\ntype VercelUseAssistantRuntimeProps = PropsWithChildren<{\n assistant: UseAssistantHelpers;\n}>;\n\nconst VercelUseAssistantRuntimeProvider: FC<VercelUseAssistantRuntimeProps> = ({\n assistant,\n children,\n}) => {\n const runtime = useVercelUseAssistantRuntime(assistant);\n\n return (\n <AssistantRuntimeProvider runtime={runtime}>\n {children}\n </AssistantRuntimeProvider>\n );\n};\n\n/**\n * @deprecated Will be removed in 0.1.0.\n */\nexport type VercelAIAssistantProviderProps = PropsWithChildren<\n | {\n chat: UseChatHelpers;\n }\n | {\n assistant: UseAssistantHelpers;\n }\n>;\n\n/**\n * @deprecated `const runtime = useVercelUseChatRuntime(chat)` and `<AssistantRuntimeProvider runtime={...} />`. Will be removed in 0.1.0.\n */\nexport const VercelAIAssistantProvider: FC<VercelAIAssistantProviderProps> = ({\n children,\n ...rest\n}) => {\n if (\"chat\" in rest) {\n return (\n <VercelUseChatRuntimeProvider chat={rest.chat}>\n {children}\n </VercelUseChatRuntimeProvider>\n );\n }\n\n return (\n <VercelUseAssistantRuntimeProvider assistant={rest.assistant}>\n {children}\n </VercelUseAssistantRuntimeProvider>\n );\n};\n","\"use client\";\n\nimport type { PropsWithChildren } from \"react\";\nimport { AssistantRuntimeProvider } from \"../../context/providers/AssistantRuntimeProvider\";\nimport type { VercelRSCAdapter } from \"../vercel-ai/rsc/VercelRSCAdapter\";\nimport type { VercelRSCMessage } from \"../vercel-ai/rsc/VercelRSCMessage\";\nimport { useVercelRSCRuntime } from \"../vercel-ai/rsc/useVercelRSCRuntime\";\n\n/**\n * @deprecated Will be removed in 0.1.0.\n */\nexport type VercelRSCAssistantProviderProps<T> = PropsWithChildren<\n VercelRSCAdapter<T>\n>;\n\n/**\n * @deprecated Replaced with `const runtime = useVercelRSCRuntime({ messages, append })` and `<AssistantRuntimeProvider runtime={runtime} />`. Will be removed in 0.1.0.\n */\nexport const VercelRSCAssistantProvider = <\n T extends WeakKey = VercelRSCMessage,\n>({\n children,\n ...adapter\n}: VercelRSCAssistantProviderProps<T>) => {\n const runtime = useVercelRSCRuntime<T>(adapter as VercelRSCAdapter<T>);\n return (\n <AssistantRuntimeProvider runtime={runtime}>\n {children}\n </AssistantRuntimeProvider>\n );\n};\n","\"use client\";\n\nimport { useInsertionEffect, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntime } from \"./LocalRuntime\";\n\nexport const useLocalRuntime = (adapter: ChatModelAdapter) => {\n const [runtime] = useState(() => new LocalRuntime(adapter));\n\n useInsertionEffect(() => {\n runtime.adapter = adapter;\n });\n\n return runtime;\n};\n","import type {\n AppendMessage,\n AssistantMessage,\n UserMessage,\n} from \"../../utils/AssistantTypes\";\nimport type { AssistantRuntime } from \"../core/AssistantRuntime\";\nimport type { Unsubscribe } from \"../core/ThreadRuntime\";\nimport { MessageRepository } from \"../utils/MessageRepository\";\nimport { generateId } from \"../utils/idUtils\";\nimport type { ChatModelAdapter, ChatModelRunResult } from \"./ChatModelAdapter\";\n\nexport class LocalRuntime implements AssistantRuntime {\n private _subscriptions = new Set<() => void>();\n\n private abortController: AbortController | null = null;\n private repository = new MessageRepository();\n\n public get messages() {\n return this.repository.getMessages();\n }\n public get isRunning() {\n return this.abortController != null;\n }\n\n constructor(public adapter: ChatModelAdapter) {}\n\n public getBranches(messageId: string): string[] {\n return this.repository.getBranches(messageId);\n }\n\n public switchToBranch(branchId: string): void {\n this.repository.switchToBranch(branchId);\n this.notifySubscribers();\n }\n\n public async append(message: AppendMessage): Promise<void> {\n // add user message\n const userMessageId = generateId();\n const userMessage: UserMessage = {\n id: userMessageId,\n role: \"user\",\n content: message.content,\n createdAt: new Date(),\n };\n this.repository.addOrUpdateMessage(message.parentId, userMessage);\n\n await this.startRun(userMessageId);\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n const id = generateId();\n\n this.repository.resetHead(parentId);\n const messages = this.repository.getMessages();\n\n // add assistant message\n const message: AssistantMessage = {\n id,\n role: \"assistant\",\n status: \"in_progress\",\n content: [{ type: \"text\", text: \"\" }],\n createdAt: new Date(),\n };\n this.repository.addOrUpdateMessage(parentId, { ...message });\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n this.notifySubscribers();\n\n try {\n const updateHandler = ({ content }: ChatModelRunResult) => {\n message.content = content;\n this.repository.addOrUpdateMessage(parentId, { ...message });\n this.notifySubscribers();\n };\n const result = await this.adapter.run({\n messages,\n abortSignal: this.abortController.signal,\n onUpdate: updateHandler,\n });\n updateHandler(result);\n\n message.status = \"done\";\n this.repository.addOrUpdateMessage(parentId, { ...message });\n } catch (e) {\n message.status = \"error\";\n this.repository.addOrUpdateMessage(parentId, { ...message });\n console.error(e);\n } finally {\n this.abortController = null;\n this.notifySubscribers();\n }\n }\n\n cancelRun(): void {\n if (!this.abortController) return;\n\n this.abortController.abort();\n this.abortController = null;\n this.notifySubscribers();\n }\n\n private notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n}\n","\"use client\";\nimport { type LanguageModel, streamText } from \"ai\";\nimport type {\n AssistantContentPart,\n TextContentPart,\n} from \"../../../utils/AssistantTypes\";\nimport type {\n ChatModelAdapter,\n ChatModelRunOptions,\n} from \"../ChatModelAdapter\";\n\nexport class VercelModelAdapter implements ChatModelAdapter {\n constructor(private readonly model: LanguageModel) {}\n\n async run({ messages, abortSignal, onUpdate }: ChatModelRunOptions) {\n const { fullStream } = await streamText({\n model: this.model,\n abortSignal,\n messages: messages.map((m) => ({\n role: m.role,\n content: m.content.filter((c): c is TextContentPart => c.type !== \"ui\"),\n })),\n });\n\n const content: AssistantContentPart[] = [];\n for await (const aiPart of fullStream) {\n switch (aiPart.type) {\n case \"text-delta\": {\n let part = content.at(-1);\n if (!part || part.type !== \"text\") {\n part = { type: \"text\", text: \"\" };\n content.push(part);\n }\n part.text += aiPart.textDelta;\n break;\n }\n // TODO tool results\n case \"tool-call\": {\n content.push({\n type: \"tool-call\",\n name: aiPart.toolName,\n args: aiPart.args,\n });\n break;\n }\n }\n\n onUpdate({ content });\n }\n\n return { content };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AAiB,UAAU,YAAY;AACrC,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,cAAc;AACjB,cAAI,OAAO,QAAQ,GAAG,EAAE;AACxB,cAAI,CAAC,QAAQ,KAAK,SAAS,QAAQ;AACjC,mBAAO,EAAE,MAAM,QAAQ,MAAM,GAAG;AAChC,oBAAQ,KAAK,IAAI;AAAA,UACnB;AACA,eAAK,QAAQ,OAAO;AACpB;AAAA,QACF;AAAA,QAEA,KAAK,aAAa;AAChB,kBAAQ,KAAK;AAAA,YACX,MAAM;AAAA,YACN,MAAM,OAAO;AAAA,YACb,MAAM,OAAO;AAAA,UACf,CAAC;AACD;AAAA,QACF;AAAA,MACF;AAEA,eAAS,EAAE,QAAQ,CAAC;AAAA,IACtB;AAEA,WAAO,EAAE,QAAQ;AAAA,EACnB;AACF;","names":["import_react","import_react","import_react","c","import_react","import_react","import_react","import_react","import_react","import_react","import_jsx_runtime","import_react_primitive","import_react","import_react","import_react_use_callback_ref","import_react","import_jsx_runtime","import_react","import_zustand","import_jsx_runtime","useMessageContext","import_react","import_jsx_runtime","import_primitive","import_react_primitive","import_react","import_jsx_runtime","import_primitive","import_react_primitive","import_react","import_jsx_runtime","import_primitive","import_react_compose_refs","import_react_primitive","import_react","import_jsx_runtime","import_primitive","import_react_compose_refs","import_react","import_jsx_runtime","TextareaAutosize","import_react_primitive","import_react","import_jsx_runtime","import_primitive","import_react_primitive","import_react","import_jsx_runtime","import_primitive","import_react_primitive","import_react","import_jsx_runtime","import_react","import_zustand","import_react","import_jsx_runtime","useContentPartContext","import_jsx_runtime","import_react_primitive","import_react","import_jsx_runtime","import_primitive","import_react_primitive","import_react","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_react_primitive","import_react","import_jsx_runtime","import_react_primitive","import_react","import_jsx_runtime","import_react","import_zustand","import_react","convertCallback","import_react","import_zustand","import_react","import_react","vercelToThreadMessage","messages","import_react","import_react","import_react","import_zustand","import_zustand","import_zustand","import_jsx_runtime","onRuntimeUpdate","import_jsx_runtime","import_jsx_runtime","import_jsx_runtime","import_react"]}
|
package/dist/index.mjs
CHANGED
@@ -1028,11 +1028,12 @@ import { useEffect as useEffect6, useMemo as useMemo4 } from "react";
|
|
1028
1028
|
// src/runtime/vercel-ai/utils/ThreadMessageConverter.ts
|
1029
1029
|
var ThreadMessageConverter = class {
|
1030
1030
|
cache = /* @__PURE__ */ new WeakMap();
|
1031
|
-
convertMessages(converter,
|
1031
|
+
convertMessages(messages, converter, keyMapper = (key) => key) {
|
1032
1032
|
return messages.map((m) => {
|
1033
|
-
const
|
1033
|
+
const key = keyMapper(m);
|
1034
|
+
const cached = this.cache.get(key);
|
1034
1035
|
const newMessage = converter(m, cached);
|
1035
|
-
this.cache.set(
|
1036
|
+
this.cache.set(key, newMessage);
|
1036
1037
|
return newMessage;
|
1037
1038
|
});
|
1038
1039
|
}
|
@@ -1066,7 +1067,7 @@ var useVercelRSCSync = (adapter, updateData) => {
|
|
1066
1067
|
return [new ThreadMessageConverter(), convertCallback2];
|
1067
1068
|
}, [adapter.convertMessage]);
|
1068
1069
|
useEffect6(() => {
|
1069
|
-
updateData(converter.convertMessages(
|
1070
|
+
updateData(converter.convertMessages(adapter.messages, convertCallback));
|
1070
1071
|
}, [updateData, converter, convertCallback, adapter.messages]);
|
1071
1072
|
};
|
1072
1073
|
|
@@ -1329,11 +1330,14 @@ var getVercelAIMessage = (message) => {
|
|
1329
1330
|
// src/runtime/vercel-ai/ui/utils/sliceMessagesUntil.tsx
|
1330
1331
|
var sliceMessagesUntil = (messages, messageId) => {
|
1331
1332
|
if (messageId == null) return [];
|
1332
|
-
|
1333
|
+
let messageIdx = messages.findIndex((m) => m.id === messageId);
|
1333
1334
|
if (messageIdx === -1)
|
1334
1335
|
throw new Error(
|
1335
1336
|
"useVercelAIThreadState: Message not found. This is liekly an internal bug in assistant-ui."
|
1336
1337
|
);
|
1338
|
+
while (messages[messageIdx + 1]?.role === "assistant") {
|
1339
|
+
messageIdx++;
|
1340
|
+
}
|
1337
1341
|
return messages.slice(0, messageIdx + 1);
|
1338
1342
|
};
|
1339
1343
|
|
@@ -1355,24 +1359,31 @@ var getIsRunning = (vercel) => {
|
|
1355
1359
|
if ("isLoading" in vercel) return vercel.isLoading;
|
1356
1360
|
return vercel.status === "in_progress";
|
1357
1361
|
};
|
1358
|
-
var vercelToThreadMessage2 = (
|
1362
|
+
var vercelToThreadMessage2 = (messages, status) => {
|
1363
|
+
const firstMessage = messages[0];
|
1364
|
+
if (!firstMessage) throw new Error("No messages found");
|
1359
1365
|
const common = {
|
1360
|
-
id:
|
1361
|
-
createdAt:
|
1362
|
-
[symbolInnerAIMessage]:
|
1366
|
+
id: firstMessage.id,
|
1367
|
+
createdAt: firstMessage.createdAt ?? /* @__PURE__ */ new Date(),
|
1368
|
+
[symbolInnerAIMessage]: messages
|
1363
1369
|
};
|
1364
|
-
switch (
|
1370
|
+
switch (firstMessage.role) {
|
1365
1371
|
case "user":
|
1372
|
+
if (messages.length > 1) {
|
1373
|
+
throw new Error(
|
1374
|
+
"Multiple user messages found. This is likely an internal bug in assistant-ui."
|
1375
|
+
);
|
1376
|
+
}
|
1366
1377
|
return {
|
1367
1378
|
...common,
|
1368
1379
|
role: "user",
|
1369
|
-
content: [{ type: "text", text:
|
1380
|
+
content: [{ type: "text", text: firstMessage.content }]
|
1370
1381
|
};
|
1371
1382
|
case "assistant":
|
1372
1383
|
return {
|
1373
1384
|
...common,
|
1374
1385
|
role: "assistant",
|
1375
|
-
content: [
|
1386
|
+
content: messages.flatMap((message) => [
|
1376
1387
|
...message.content ? [{ type: "text", text: message.content }] : [],
|
1377
1388
|
...message.toolInvocations?.map(
|
1378
1389
|
(t) => ({
|
@@ -1382,29 +1393,57 @@ var vercelToThreadMessage2 = (message, status) => {
|
|
1382
1393
|
result: "result" in t ? t.result : void 0
|
1383
1394
|
})
|
1384
1395
|
) ?? []
|
1385
|
-
],
|
1396
|
+
]),
|
1386
1397
|
status
|
1387
1398
|
};
|
1388
1399
|
default:
|
1389
1400
|
throw new Error(
|
1390
|
-
`You have a message with an unsupported role. The role ${
|
1401
|
+
`You have a message with an unsupported role. The role ${firstMessage.role} is not supported.`
|
1391
1402
|
);
|
1392
1403
|
}
|
1393
1404
|
};
|
1405
|
+
var hasItems = (messages) => messages.length > 0;
|
1406
|
+
var chunkedMessages = (messages) => {
|
1407
|
+
const chunks = [];
|
1408
|
+
let currentChunk = [];
|
1409
|
+
for (const message of messages) {
|
1410
|
+
if (message.role === "assistant") {
|
1411
|
+
currentChunk.push(message);
|
1412
|
+
} else {
|
1413
|
+
if (hasItems(currentChunk)) {
|
1414
|
+
chunks.push(currentChunk);
|
1415
|
+
currentChunk = [];
|
1416
|
+
}
|
1417
|
+
chunks.push([message]);
|
1418
|
+
}
|
1419
|
+
}
|
1420
|
+
if (hasItems(currentChunk)) {
|
1421
|
+
chunks.push(currentChunk);
|
1422
|
+
}
|
1423
|
+
return chunks;
|
1424
|
+
};
|
1425
|
+
var shallowArrayEqual = (a, b) => {
|
1426
|
+
if (a.length !== b.length) return false;
|
1427
|
+
for (let i = 0; i < a.length; i++) {
|
1428
|
+
if (a[i] !== b[i]) return false;
|
1429
|
+
}
|
1430
|
+
return true;
|
1431
|
+
};
|
1394
1432
|
var useVercelAIThreadSync = (vercel, updateData) => {
|
1395
1433
|
const isRunning = getIsRunning(vercel);
|
1396
1434
|
const converter = useMemo5(() => new ThreadMessageConverter(), []);
|
1397
1435
|
useEffect9(() => {
|
1398
1436
|
const lastMessageId = vercel.messages.at(-1)?.id;
|
1399
|
-
const convertCallback = (
|
1400
|
-
const status = lastMessageId ===
|
1401
|
-
if (cache && (cache.role === "user" || cache.status === status))
|
1437
|
+
const convertCallback = (messages2, cache) => {
|
1438
|
+
const status = lastMessageId === messages2[0].id && isRunning ? "in_progress" : "done";
|
1439
|
+
if (cache && shallowArrayEqual(cache.content, messages2) && (cache.role === "user" || cache.status === status))
|
1402
1440
|
return cache;
|
1403
|
-
return vercelToThreadMessage2(
|
1441
|
+
return vercelToThreadMessage2(messages2, status);
|
1404
1442
|
};
|
1405
1443
|
const messages = converter.convertMessages(
|
1444
|
+
chunkedMessages(vercel.messages),
|
1406
1445
|
convertCallback,
|
1407
|
-
|
1446
|
+
(m) => m[0]
|
1408
1447
|
);
|
1409
1448
|
updateData(isRunning, messages);
|
1410
1449
|
}, [updateData, isRunning, vercel.messages, converter]);
|
@@ -1480,7 +1519,7 @@ var VercelAIRuntime = class {
|
|
1480
1519
|
}
|
1481
1520
|
updateVercelMessages = (messages) => {
|
1482
1521
|
this.vercel.setMessages(
|
1483
|
-
messages.
|
1522
|
+
messages.flatMap(getVercelAIMessage).filter((m) => m != null)
|
1484
1523
|
);
|
1485
1524
|
};
|
1486
1525
|
onVercelUpdated() {
|
@@ -1748,15 +1787,17 @@ var LocalRuntime = class {
|
|
1748
1787
|
this.abortController = new AbortController();
|
1749
1788
|
this.notifySubscribers();
|
1750
1789
|
try {
|
1751
|
-
|
1790
|
+
const updateHandler = ({ content }) => {
|
1791
|
+
message.content = content;
|
1792
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1793
|
+
this.notifySubscribers();
|
1794
|
+
};
|
1795
|
+
const result = await this.adapter.run({
|
1752
1796
|
messages,
|
1753
1797
|
abortSignal: this.abortController.signal,
|
1754
|
-
onUpdate:
|
1755
|
-
message.content = content;
|
1756
|
-
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1757
|
-
this.notifySubscribers();
|
1758
|
-
}
|
1798
|
+
onUpdate: updateHandler
|
1759
1799
|
});
|
1800
|
+
updateHandler(result);
|
1760
1801
|
message.status = "done";
|
1761
1802
|
this.repository.addOrUpdateMessage(parentId, { ...message });
|
1762
1803
|
} catch (e) {
|
@@ -1860,3 +1901,4 @@ export {
|
|
1860
1901
|
useVercelUseAssistantRuntime,
|
1861
1902
|
useVercelUseChatRuntime
|
1862
1903
|
};
|
1904
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/actions/useCopyMessage.tsx","../src/context/MessageContext.ts","../src/utils/combined/useCombinedStore.ts","../src/utils/combined/createCombinedStore.ts","../src/utils/getMessageText.tsx","../src/actions/useReloadMessage.tsx","../src/context/ThreadContext.ts","../src/actions/useBeginMessageEdit.tsx","../src/actions/useGoToNextBranch.tsx","../src/actions/useGoToPreviousBranch.tsx","../src/primitives/thread/index.ts","../src/primitives/thread/ThreadRoot.tsx","../src/primitives/thread/ThreadIf.tsx","../src/primitives/thread/ThreadEmpty.tsx","../src/primitives/thread/ThreadViewport.tsx","../src/utils/hooks/useOnResizeContent.tsx","../src/utils/hooks/useOnScrollToBottom.tsx","../src/context/providers/MessageProvider.tsx","../src/context/stores/MessageComposer.ts","../src/context/stores/BaseComposer.ts","../src/context/ComposerContext.ts","../src/primitives/composer/ComposerIf.tsx","../src/primitives/message/MessageIf.tsx","../src/primitives/thread/ThreadMessages.tsx","../src/primitives/thread/ThreadScrollToBottom.tsx","../src/primitives/thread/ThreadSuggestion.tsx","../src/primitives/composer/index.ts","../src/primitives/composer/ComposerRoot.tsx","../src/primitives/composer/ComposerInput.tsx","../src/primitives/composer/ComposerSend.tsx","../src/primitives/composer/ComposerCancel.tsx","../src/primitives/message/index.ts","../src/primitives/message/MessageRoot.tsx","../src/context/providers/ContentPartProvider.tsx","../src/context/ContentPartContext.ts","../src/primitives/contentPart/ContentPartInProgressIndicator.tsx","../src/primitives/message/MessageContent.tsx","../src/primitives/message/MessageInProgress.tsx","../src/primitives/branchPicker/index.ts","../src/utils/createActionButton.tsx","../src/primitives/branchPicker/BranchPickerNext.tsx","../src/primitives/branchPicker/BranchPickerPrevious.tsx","../src/primitives/branchPicker/BranchPickerCount.tsx","../src/primitives/branchPicker/BranchPickerNumber.tsx","../src/primitives/branchPicker/BranchPickerRoot.tsx","../src/primitives/actionBar/index.ts","../src/primitives/actionBar/ActionBarRoot.tsx","../src/primitives/actionBar/ActionBarCopy.tsx","../src/primitives/actionBar/ActionBarReload.tsx","../src/primitives/actionBar/ActionBarEdit.tsx","../src/primitives/contentPart/index.ts","../src/runtime/vercel-ai/rsc/useVercelRSCRuntime.tsx","../src/runtime/vercel-ai/rsc/VercelRSCRuntime.tsx","../src/runtime/vercel-ai/rsc/useVercelRSCSync.tsx","../src/runtime/vercel-ai/utils/ThreadMessageConverter.ts","../src/runtime/vercel-ai/rsc/getVercelRSCMessage.tsx","../src/runtime/vercel-ai/ui/use-chat/useVercelUseChatRuntime.tsx","../src/runtime/vercel-ai/ui/VercelAIRuntime.tsx","../src/runtime/utils/idUtils.tsx","../src/runtime/utils/MessageRepository.tsx","../src/runtime/vercel-ai/ui/getVercelAIMessage.tsx","../src/runtime/vercel-ai/ui/utils/sliceMessagesUntil.tsx","../src/runtime/vercel-ai/ui/utils/useVercelAIComposerSync.tsx","../src/runtime/vercel-ai/ui/utils/useVercelAIThreadSync.tsx","../src/runtime/vercel-ai/ui/use-assistant/useVercelUseAssistantRuntime.tsx","../src/context/providers/AssistantRuntimeProvider.tsx","../src/context/providers/ThreadProvider.tsx","../src/context/stores/Composer.ts","../src/context/stores/Thread.ts","../src/context/stores/ThreadViewport.tsx","../src/runtime/vercel-deprecated/VercelAIAssistantProvider.tsx","../src/runtime/vercel-deprecated/VercelRSCAssistantProvider.tsx","../src/runtime/local/useLocalRuntime.tsx","../src/runtime/local/LocalRuntime.tsx","../src/runtime/local/vercel/VercelModelAdapter.tsx"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useMessageContext } from \"../context/MessageContext\";\nimport { useCombinedStore } from \"../utils/combined/useCombinedStore\";\nimport { getMessageText } from \"../utils/getMessageText\";\n\nexport const useCopyMessage = ({ copiedDuration = 3000 }) => {\n const { useMessage, useComposer } = useMessageContext();\n\n const hasCopyableContent = useCombinedStore(\n [useMessage, useComposer],\n (m, c) => {\n return c.isEditing || m.message.content.some((c) => c.type === \"text\");\n },\n );\n\n const callback = useCallback(() => {\n const { isEditing, value: composerValue } = useComposer.getState();\n const { message, setIsCopied } = useMessage.getState();\n\n const valueToCopy = isEditing ? composerValue : getMessageText(message);\n\n navigator.clipboard.writeText(valueToCopy);\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n }, [useComposer, useMessage, copiedDuration]);\n\n if (!hasCopyableContent) return null;\n return callback;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { MessageState } from \"./stores/Message\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type MessageContextValue = {\n useMessage: UseBoundStore<StoreApi<MessageState>>;\n useComposer: UseBoundStore<StoreApi<EditComposerState>>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nexport const useMessageContext = () => {\n const context = useContext(MessageContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />.\",\n );\n return context;\n};\n","\"use client\";\nimport { useMemo } from \"react\";\nimport type { StoreApi } from \"zustand\";\nimport {\n type CombinedSelector,\n createCombinedStore,\n} from \"./createCombinedStore\";\n\nexport const useCombinedStore = <T extends Array<unknown>, R>(\n stores: { [K in keyof T]: StoreApi<T[K]> },\n selector: CombinedSelector<T, R>,\n): R => {\n // biome-ignore lint/correctness/useExhaustiveDependencies: shallow-compare the store array\n const useCombined = useMemo(() => createCombinedStore<T, R>(stores), stores);\n return useCombined(selector);\n};\n","import { useSyncExternalStore } from \"react\";\nimport type { StoreApi } from \"zustand\";\n\nexport type CombinedSelector<T extends Array<unknown>, R> = (...args: T) => R;\n\nexport const createCombinedStore = <T extends Array<unknown>, R>(\n stores: { [K in keyof T]: StoreApi<T[K]> },\n) => {\n const subscribe = (callback: () => void): (() => void) => {\n const unsubscribes = stores.map((store) => store.subscribe(callback));\n return () => {\n for (const unsub of unsubscribes) {\n unsub();\n }\n };\n };\n\n return (selector: CombinedSelector<T, R>): R => {\n const getSnapshot = (): R =>\n selector(...(stores.map((store) => store.getState()) as T));\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n };\n};\n","\"use client\";\nimport type { TextContentPart, ThreadMessage } from \"./AssistantTypes\";\n\nexport const getMessageText = (message: ThreadMessage) => {\n const textParts = message.content.filter(\n (part) => part.type === \"text\",\n ) as TextContentPart[];\n\n return textParts.map((part) => part.text).join(\"\\n\\n\");\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../context/MessageContext\";\nimport { useThreadContext } from \"../context/ThreadContext\";\nimport { useCombinedStore } from \"../utils/combined/useCombinedStore\";\n\nexport const useReloadMessage = () => {\n const { useThread, useViewport } = useThreadContext();\n const { useMessage } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useThread, useMessage],\n (t, m) => t.isRunning || m.message.role !== \"assistant\",\n );\n\n const callback = useCallback(() => {\n const { parentId } = useMessage.getState();\n useThread.getState().startRun(parentId);\n useViewport.getState().scrollToBottom();\n }, [useMessage, useThread, useViewport]);\n\n if (disabled) return null;\n return callback;\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { ThreadState } from \"./stores/Thread\";\nimport type { ThreadViewportState } from \"./stores/ThreadViewport\";\n\nexport type ThreadContextValue = {\n useThread: UseBoundStore<StoreApi<ThreadState>>;\n useComposer: UseBoundStore<StoreApi<ComposerState>>;\n useViewport: UseBoundStore<StoreApi<ThreadViewportState>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nexport const useThreadContext = (): ThreadContextValue => {\n const context = useContext(ThreadContext);\n if (!context)\n throw new Error(\"This component must be used within an AssistantProvider.\");\n return context;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../context/MessageContext\";\nimport { useCombinedStore } from \"../utils/combined/useCombinedStore\";\n\nexport const useBeginMessageEdit = () => {\n const { useMessage, useComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useComposer],\n (m, c) => m.message.role !== \"user\" || c.isEditing,\n );\n\n const callback = useCallback(() => {\n const { edit } = useComposer.getState();\n edit();\n }, [useComposer]);\n\n if (disabled) return null;\n return callback;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../context/MessageContext\";\nimport { useThreadContext } from \"../context/ThreadContext\";\nimport { useCombinedStore } from \"../utils/combined/useCombinedStore\";\n\nexport const useGoToNextBranch = () => {\n const { useThread } = useThreadContext();\n const { useMessage, useComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useComposer],\n (m, c) =>\n c.isEditing || m.branches.indexOf(m.message.id) + 1 >= m.branches.length,\n );\n\n const callback = useCallback(() => {\n const { message, branches } = useMessage.getState();\n useThread\n .getState()\n .switchToBranch(branches[branches.indexOf(message.id) + 1]!);\n }, [useMessage, useThread]);\n\n if (disabled) return null;\n return callback;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../context/MessageContext\";\nimport { useThreadContext } from \"../context/ThreadContext\";\nimport { useCombinedStore } from \"../utils/combined/useCombinedStore\";\n\nexport const useGoToPreviousBranch = () => {\n const { useThread } = useThreadContext();\n const { useMessage, useComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useComposer],\n (m, c) => c.isEditing || m.branches.indexOf(m.message.id) <= 0,\n );\n\n const callback = useCallback(() => {\n const { message, branches } = useMessage.getState();\n useThread\n .getState()\n .switchToBranch(branches[branches.indexOf(message.id) - 1]!);\n }, [useMessage, useThread]);\n\n if (disabled) return null;\n return callback;\n};\n","export { ThreadRoot as Root } from \"./ThreadRoot\";\nexport { ThreadEmpty as Empty } from \"./ThreadEmpty\";\nexport { ThreadIf as If } from \"./ThreadIf\";\nexport { ThreadViewport as Viewport } from \"./ThreadViewport\";\nexport { ThreadMessages as Messages } from \"./ThreadMessages\";\nexport { ThreadScrollToBottom as ScrollToBottom } from \"./ThreadScrollToBottom\";\nexport { ThreadSuggestion as Suggestion } from \"./ThreadSuggestion\";\n","\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\n\ntype ThreadRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\ntype ThreadRootProps = PrimitiveDivProps;\n\nexport const ThreadRoot = forwardRef<ThreadRootElement, ThreadRootProps>(\n (props, ref) => {\n return <Primitive.div {...props} ref={ref} />;\n },\n);\n","\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype ThreadIfFilters = {\n empty: boolean | undefined;\n running: boolean | undefined;\n};\n\ntype ThreadIfProps = PropsWithChildren<RequireAtLeastOne<ThreadIfFilters>>;\n\nconst useThreadIf = (props: RequireAtLeastOne<ThreadIfFilters>) => {\n const { useThread } = useThreadContext();\n return useThread((thread) => {\n if (props.empty === true && thread.messages.length !== 0) return false;\n if (props.empty === false && thread.messages.length === 0) return false;\n if (props.running === true && !thread.isRunning) return false;\n if (props.running === false && thread.isRunning) return false;\n\n return true;\n });\n};\n\nexport const ThreadIf: FC<ThreadIfProps> = ({ children, ...query }) => {\n const result = useThreadIf(query);\n return result ? children : null;\n};\n","\"use client\";\n\nimport type { FC, ReactNode } from \"react\";\nimport { ThreadIf } from \"./ThreadIf\";\n\ntype ThreadEmptyProps = {\n children: ReactNode;\n};\n\nexport const ThreadEmpty: FC<ThreadEmptyProps> = ({ children }) => {\n return <ThreadIf empty>{children}</ThreadIf>;\n};\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, useRef } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\nimport { useOnResizeContent } from \"../../utils/hooks/useOnResizeContent\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\n\ntype ThreadViewportElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\ntype ThreadViewportProps = PrimitiveDivProps & {\n autoScroll?: boolean;\n};\n\nexport const ThreadViewport = forwardRef<\n ThreadViewportElement,\n ThreadViewportProps\n>(({ autoScroll = true, onScroll, children, ...rest }, forwardedRef) => {\n const messagesEndRef = useRef<HTMLDivElement>(null);\n\n const divRef = useRef<HTMLDivElement>(null);\n const ref = useComposedRefs(forwardedRef, divRef);\n\n const { useViewport } = useThreadContext();\n\n // TODO find a more elegant implementation for this\n\n const firstRenderRef = useRef(true);\n const isScrollingToBottomRef = useRef(false);\n const lastScrollTop = useRef<number>(0);\n\n const scrollToBottom = () => {\n const div = messagesEndRef.current;\n if (!div || !autoScroll) return;\n\n const behavior = firstRenderRef.current ? \"instant\" : \"auto\";\n firstRenderRef.current = false;\n\n isScrollingToBottomRef.current = true;\n div.scrollIntoView({ behavior });\n };\n\n useOnResizeContent(divRef, () => {\n if (!isScrollingToBottomRef.current && !useViewport.getState().isAtBottom) {\n handleScroll();\n } else {\n scrollToBottom();\n }\n });\n\n useOnScrollToBottom(() => {\n scrollToBottom();\n });\n\n const handleScroll = () => {\n const div = divRef.current;\n if (!div) return;\n\n const isAtBottom = useViewport.getState().isAtBottom;\n const newIsAtBottom = div.scrollHeight - div.scrollTop <= div.clientHeight;\n\n if (!newIsAtBottom && lastScrollTop.current < div.scrollTop) {\n // ignore scroll down\n } else if (newIsAtBottom !== isAtBottom) {\n isScrollingToBottomRef.current = false;\n useViewport.setState({ isAtBottom: newIsAtBottom });\n }\n\n lastScrollTop.current = div.scrollTop;\n };\n\n return (\n <Primitive.div\n {...rest}\n onScroll={composeEventHandlers(onScroll, handleScroll)}\n ref={ref}\n >\n {children}\n <div ref={messagesEndRef} />\n </Primitive.div>\n );\n});\n","\"use client\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { type MutableRefObject, useEffect } from \"react\";\n\nexport const useOnResizeContent = (\n ref: MutableRefObject<HTMLElement | null>,\n callback: () => void,\n) => {\n const callbackRef = useCallbackRef(callback);\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n\n const resizeObserver = new ResizeObserver(() => {\n callbackRef();\n });\n\n const mutationObserver = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n for (const node of mutation.addedNodes) {\n if (node instanceof Element) {\n resizeObserver.observe(node);\n }\n }\n\n for (const node of mutation.removedNodes) {\n if (node instanceof Element) {\n resizeObserver.unobserve(node);\n }\n }\n }\n\n callbackRef();\n });\n\n resizeObserver.observe(el);\n mutationObserver.observe(el, { childList: true });\n\n // Observe existing children\n for (const child of el.children) {\n resizeObserver.observe(child);\n }\n\n return () => {\n resizeObserver.disconnect();\n mutationObserver.disconnect();\n };\n }, [ref.current, callbackRef]);\n};\n","\"use client\";\nimport { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useEffect } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\n\nexport const useOnScrollToBottom = (callback: () => void) => {\n const callbackRef = useCallbackRef(callback);\n\n const { useViewport } = useThreadContext();\n useEffect(() => {\n return useViewport.getState().onScrollToBottom(() => {\n callbackRef();\n });\n }, [useViewport, callbackRef]);\n};\n","\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport type {\n AppendContentPart,\n ThreadMessage,\n} from \"../../utils/AssistantTypes\";\nimport { getMessageText } from \"../../utils/getMessageText\";\nimport { MessageContext } from \"../MessageContext\";\nimport type { MessageContextValue } from \"../MessageContext\";\nimport { useThreadContext } from \"../ThreadContext\";\nimport type { MessageState } from \"../stores/Message\";\nimport { makeEditComposerStore } from \"../stores/MessageComposer\";\nimport type { ThreadState } from \"../stores/Thread\";\n\ntype MessageProviderProps = PropsWithChildren<{\n messageIndex: number;\n}>;\n\nconst getIsLast = (thread: ThreadState, message: ThreadMessage) => {\n return thread.messages[thread.messages.length - 1]?.id === message.id;\n};\n\nconst syncMessage = (\n thread: ThreadState,\n useMessage: MessageContextValue[\"useMessage\"],\n messageIndex: number,\n) => {\n const parentId = thread.messages[messageIndex - 1]?.id ?? null;\n const message = thread.messages[messageIndex];\n\n // TODO check if this can happen\n if (!message) return;\n\n const isLast = getIsLast(thread, message);\n const branches = thread.getBranches(message.id);\n\n // if the message is the same, don't update\n const currentState = useMessage.getState();\n if (\n currentState.message === message &&\n currentState.parentId === parentId &&\n currentState.branches === branches &&\n currentState.isLast === isLast\n )\n return;\n\n // sync useMessage\n useMessage.setState({\n message,\n parentId,\n branches,\n isLast,\n });\n};\n\nconst useMessageContext = (messageIndex: number) => {\n const { useThread } = useThreadContext();\n\n const [context] = useState<MessageContextValue>(() => {\n const useMessage = create<MessageState>((set) => ({\n message: null as unknown as ThreadMessage,\n parentId: null,\n branches: [],\n isLast: false,\n inProgressIndicator: null,\n isCopied: false,\n isHovering: false,\n setInProgressIndicator: (value) => {\n set({ inProgressIndicator: value });\n },\n setIsCopied: (value) => {\n set({ isCopied: value });\n },\n setIsHovering: (value) => {\n set({ isHovering: value });\n },\n }));\n\n const useComposer = makeEditComposerStore({\n onEdit: () => {\n const message = useMessage.getState().message;\n if (message.role !== \"user\")\n throw new Error(\n \"Tried to edit a non-user message. Editing is only supported for user messages. This is likely an internal bug in assistant-ui.\",\n );\n\n const text = getMessageText(message);\n\n return text;\n },\n onSend: (text) => {\n const { message, parentId } = useMessage.getState();\n if (message.role !== \"user\")\n throw new Error(\n \"Tried to edit a non-user message. Editing is only supported for user messages. This is likely an internal bug in assistant-ui.\",\n );\n\n const nonTextParts = message.content.filter(\n (part): part is AppendContentPart =>\n part.type !== \"text\" && part.type !== \"ui\",\n );\n useThread.getState().append({\n parentId,\n content: [{ type: \"text\", text }, ...nonTextParts],\n });\n },\n });\n\n syncMessage(useThread.getState(), useMessage, messageIndex);\n\n return { useMessage, useComposer };\n });\n\n useEffect(() => {\n return useThread.subscribe((thread) => {\n syncMessage(thread, context.useMessage, messageIndex);\n });\n }, [context, useThread, messageIndex]);\n\n return context;\n};\n\nexport const MessageProvider: FC<MessageProviderProps> = ({\n messageIndex,\n children,\n}) => {\n const context = useMessageContext(messageIndex);\n\n return (\n <MessageContext.Provider value={context}>\n {children}\n </MessageContext.Provider>\n );\n};\n","import { type StoreApi, type UseBoundStore, create } from \"zustand\";\nimport { type BaseComposerState, makeBaseComposer } from \"./BaseComposer\";\n\nexport type EditComposerState = BaseComposerState &\n Readonly<{\n isEditing: boolean;\n\n edit: () => void;\n send: () => void;\n cancel: () => boolean;\n }>;\n\nexport const makeEditComposerStore = ({\n onEdit,\n onSend,\n}: {\n onEdit: () => string;\n onSend: (value: string) => void;\n}): UseBoundStore<StoreApi<EditComposerState>> =>\n create<EditComposerState>()((set, get, store) => ({\n ...makeBaseComposer(set, get, store),\n\n isEditing: false,\n\n edit: () => {\n const value = onEdit();\n set({ isEditing: true, value });\n },\n send: () => {\n const value = get().value;\n set({ isEditing: false });\n onSend(value);\n },\n cancel: () => {\n if (!get().isEditing) return false;\n set({ isEditing: false });\n return true;\n },\n }));\n","import type { StateCreator } from \"zustand\";\n\nexport type BaseComposerState = Readonly<{\n value: string;\n setValue: (value: string) => void;\n}>;\n\nexport const makeBaseComposer: StateCreator<\n BaseComposerState,\n [],\n [],\n BaseComposerState\n> = (set) => ({\n value: \"\",\n setValue: (value) => {\n set({ value });\n },\n});\n","import { useContext, useMemo } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"./stores/Composer\";\nimport type { EditComposerState } from \"./stores/MessageComposer\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<StoreApi<EditComposerState | ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useComposer: useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as UseBoundStore<\n StoreApi<EditComposerState | ComposerState>\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useComposerContext } from \"../../context/ComposerContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype ComposerIfFilters = {\n editing: boolean | undefined;\n};\n\ntype ComposerIfProps = PropsWithChildren<RequireAtLeastOne<ComposerIfFilters>>;\n\nconst useComposerIf = (props: RequireAtLeastOne<ComposerIfFilters>) => {\n const { useComposer } = useComposerContext();\n return useComposer((composer) => {\n if (props.editing === true && !composer.isEditing) return false;\n if (props.editing === false && composer.isEditing) return false;\n\n return true;\n });\n};\n\nexport const ComposerIf: FC<ComposerIfProps> = ({ children, ...query }) => {\n const result = useComposerIf(query);\n return result ? children : null;\n};\n","\"use client\";\n\nimport type { FC, ReactNode } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype MessageIfFilters = {\n user: boolean | undefined;\n assistant: boolean | undefined;\n hasBranches: boolean | undefined;\n copied: boolean | undefined;\n lastOrHover: boolean | undefined;\n};\n\ntype MessageIfProps = RequireAtLeastOne<MessageIfFilters> & {\n children: ReactNode;\n};\n\nexport const useMessageIf = (props: RequireAtLeastOne<MessageIfFilters>) => {\n const { useMessage } = useMessageContext();\n\n return useMessage(({ message, branches, isLast, isCopied, isHovering }) => {\n if (props.hasBranches === true && branches.length < 2) return false;\n\n if (props.user && message.role !== \"user\") return false;\n if (props.assistant && message.role !== \"assistant\") return false;\n\n if (props.lastOrHover === true && !isHovering && !isLast) return false;\n\n if (props.copied === true && !isCopied) return false;\n if (props.copied === false && isCopied) return false;\n\n return true;\n });\n};\n\nexport const MessageIf: FC<MessageIfProps> = ({ children, ...query }) => {\n const result = useMessageIf(query);\n return result ? children : null;\n};\n","\"use client\";\n\nimport type { ComponentType, FC } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\nimport { MessageProvider } from \"../../context/providers/MessageProvider\";\nimport { ComposerIf } from \"../composer/ComposerIf\";\nimport { MessageIf } from \"../message/MessageIf\";\n\ntype ThreadMessagesProps = {\n components:\n | {\n Message: ComponentType;\n UserMessage?: ComponentType;\n EditComposer?: ComponentType;\n AssistantMessage?: ComponentType;\n }\n | {\n Message?: ComponentType;\n UserMessage: ComponentType;\n EditComposer?: ComponentType;\n AssistantMessage: ComponentType;\n };\n};\n\nconst getComponents = (components: ThreadMessagesProps[\"components\"]) => {\n return {\n EditComposer:\n components.EditComposer ??\n components.UserMessage ??\n (components.Message as ComponentType),\n UserMessage:\n components.UserMessage ?? (components.Message as ComponentType),\n AssistantMessage:\n components.AssistantMessage ?? (components.Message as ComponentType),\n };\n};\n\nexport const ThreadMessages: FC<ThreadMessagesProps> = ({ components }) => {\n const { useThread } = useThreadContext();\n const messagesLength = useThread((t) => t.messages.length);\n\n const { UserMessage, EditComposer, AssistantMessage } =\n getComponents(components);\n\n if (messagesLength === 0) return null;\n\n return (\n <>\n {new Array(messagesLength).fill(null).map((_, idx) => {\n const messageIndex = idx;\n // TODO avoid rerendering on messageLength change\n return (\n <MessageProvider\n key={messageIndex} // keep the same key when switching branches for better a11y support\n messageIndex={messageIndex}\n >\n <MessageIf user>\n <ComposerIf editing={false}>\n <UserMessage />\n </ComposerIf>\n <ComposerIf editing>\n <EditComposer />\n </ComposerIf>\n </MessageIf>\n <MessageIf assistant>\n <AssistantMessage />\n </MessageIf>\n </MessageProvider>\n );\n })}\n </>\n );\n};\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\n\ntype ThreadScrollToBottomElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\ntype ThreadScrollToBottomProps = PrimitiveButtonProps;\n\nexport const ThreadScrollToBottom = forwardRef<\n ThreadScrollToBottomElement,\n ThreadScrollToBottomProps\n>(({ onClick, ...rest }, ref) => {\n const { useViewport } = useThreadContext();\n\n const isAtBottom = useViewport((s) => s.isAtBottom);\n const handleScrollToBottom = () => {\n useViewport.getState().scrollToBottom();\n };\n\n return (\n <Primitive.button\n {...rest}\n disabled={isAtBottom}\n ref={ref}\n onClick={composeEventHandlers(onClick, handleScrollToBottom)}\n />\n );\n});\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\n\ntype ThreadSuggestionElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\ntype ThreadSuggestionProps = PrimitiveButtonProps & {\n prompt: string;\n method: \"replace\";\n autoSend?: boolean;\n};\n\nexport const ThreadSuggestion = forwardRef<\n ThreadSuggestionElement,\n ThreadSuggestionProps\n>(({ onClick, prompt, method, autoSend: send, ...rest }, ref) => {\n const { useThread, useComposer } = useThreadContext();\n\n const isDisabled = useThread((t) => t.isRunning);\n const handleApplySuggestion = () => {\n const thread = useThread.getState();\n const composer = useComposer.getState();\n composer.setValue(prompt);\n\n if (send && !thread.isRunning) {\n composer.send();\n }\n };\n\n return (\n <Primitive.button\n {...rest}\n disabled={isDisabled}\n ref={ref}\n onClick={composeEventHandlers(onClick, handleApplySuggestion)}\n />\n );\n});\n","export { ComposerRoot as Root } from \"./ComposerRoot\";\nexport { ComposerInput as Input } from \"./ComposerInput\";\nexport { ComposerSend as Send } from \"./ComposerSend\";\nexport { ComposerCancel as Cancel } from \"./ComposerCancel\";\nexport { ComposerIf as If } from \"./ComposerIf\";\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, type FormEvent, forwardRef, useRef } from \"react\";\nimport { useComposerContext } from \"../../context/ComposerContext\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\n\ntype ComposerRootElement = ElementRef<typeof Primitive.form>;\ntype PrimitiveFormProps = ComponentPropsWithoutRef<typeof Primitive.form>;\n\ntype ComposerRootProps = PrimitiveFormProps;\n\nexport const ComposerRoot = forwardRef<ComposerRootElement, ComposerRootProps>(\n ({ onSubmit, ...rest }, forwardedRef) => {\n const { useViewport } = useThreadContext();\n const { useComposer } = useComposerContext();\n\n const formRef = useRef<HTMLFormElement>(null);\n const ref = useComposedRefs(forwardedRef, formRef);\n\n const handleSubmit = (e: FormEvent) => {\n const composerState = useComposer.getState();\n if (!composerState.isEditing) return;\n\n e.preventDefault();\n composerState.send();\n\n useViewport.getState().scrollToBottom();\n };\n\n return (\n <Primitive.form\n {...rest}\n ref={ref}\n onSubmit={composeEventHandlers(onSubmit, handleSubmit)}\n />\n );\n },\n);\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n type KeyboardEvent,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n} from \"react-textarea-autosize\";\nimport { useComposerContext } from \"../../context/ComposerContext\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\n\ntype ComposerInputProps = TextareaAutosizeProps & {\n asChild?: boolean;\n};\n\nexport const ComposerInput = forwardRef<\n HTMLTextAreaElement,\n ComposerInputProps\n>(\n (\n { autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest },\n forwardedRef,\n ) => {\n const { useThread, useViewport } = useThreadContext();\n const { useComposer, type } = useComposerContext();\n\n const value = useComposer((c) => {\n if (!c.isEditing) return \"\";\n return c.value;\n });\n\n const Component = asChild ? Slot : TextareaAutosize;\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (disabled) return;\n\n const composer = useComposer.getState();\n if (e.key === \"Escape\") {\n if (useComposer.getState().cancel()) {\n e.preventDefault();\n }\n } else if (e.key === \"Enter\" && e.shiftKey === false) {\n const isRunning = useThread.getState().isRunning;\n if (!isRunning) {\n e.preventDefault();\n composer.send();\n\n useViewport.getState().scrollToBottom();\n }\n }\n };\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n\n const autoFocusEnabled = autoFocus && !disabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus();\n textarea.setSelectionRange(\n textareaRef.current.value.length,\n textareaRef.current.value.length,\n );\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnScrollToBottom(() => {\n if (type === \"new\") {\n focus();\n }\n });\n\n return (\n <Component\n value={value}\n {...rest}\n ref={ref}\n disabled={disabled}\n onChange={composeEventHandlers(onChange, (e) => {\n const composerState = useComposer.getState();\n if (!composerState.isEditing) return;\n return composerState.setValue(e.target.value);\n })}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyPress)}\n />\n );\n },\n);\n","\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useComposerContext } from \"../../context/ComposerContext\";\n\ntype ComposerSendElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveFormProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\ntype ComposerSendProps = PrimitiveFormProps;\n\nexport const ComposerSend = forwardRef<ComposerSendElement, ComposerSendProps>(\n ({ disabled, ...rest }, ref) => {\n const { useComposer } = useComposerContext();\n const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);\n\n return (\n <Primitive.button\n type=\"submit\"\n {...rest}\n ref={ref}\n disabled={disabled || !hasValue}\n />\n );\n },\n);\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useComposerContext } from \"../../context/ComposerContext\";\n\ntype ComposerCancelElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveFormProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\ntype ComposerCancelProps = PrimitiveFormProps;\n\nexport const ComposerCancel = forwardRef<\n ComposerCancelElement,\n ComposerCancelProps\n>(({ onClick, ...rest }, ref) => {\n const { useComposer } = useComposerContext();\n\n const handleCancel = () => {\n useComposer.getState().cancel();\n };\n\n return (\n <Primitive.button\n type=\"button\"\n {...rest}\n ref={ref}\n onClick={composeEventHandlers(onClick, handleCancel)}\n />\n );\n});\n","export { MessageRoot as Root } from \"./MessageRoot\";\nexport { MessageIf as If } from \"./MessageIf\";\nexport { MessageContent as Content } from \"./MessageContent\";\nexport { MessageInProgress as InProgress } from \"./MessageInProgress\";\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\n\ntype MessageRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\ntype MessageRootProps = PrimitiveDivProps;\n\nexport const MessageRoot = forwardRef<MessageRootElement, MessageRootProps>(\n ({ onMouseEnter, onMouseLeave, ...rest }, ref) => {\n const { useMessage } = useMessageContext();\n const setIsHovering = useMessage((s) => s.setIsHovering);\n\n const handleMouseEnter = () => {\n setIsHovering(true);\n };\n const handleMouseLeave = () => {\n setIsHovering(false);\n };\n\n return (\n <Primitive.div\n {...rest}\n ref={ref}\n onMouseEnter={composeEventHandlers(onMouseEnter, handleMouseEnter)}\n onMouseLeave={composeEventHandlers(onMouseLeave, handleMouseLeave)}\n />\n );\n },\n);\n","\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { create } from \"zustand\";\nimport { ContentPartContext } from \"../ContentPartContext\";\nimport type { ContentPartContextValue } from \"../ContentPartContext\";\nimport { useMessageContext } from \"../MessageContext\";\nimport type { MessageState } from \"../stores\";\nimport type { ContentPartState } from \"../stores/ContentPart\";\n\ntype ContentPartProviderProps = PropsWithChildren<{\n partIndex: number;\n}>;\n\nconst syncContentPart = (\n { message }: MessageState,\n useContentPart: ContentPartContextValue[\"useContentPart\"],\n partIndex: number,\n) => {\n const part = message.content[partIndex];\n // TODO check if this can happen\n if (!part) return;\n\n const messageStatus = message.role === \"assistant\" ? message.status : \"done\";\n const status =\n partIndex === message.content.length - 1 ? messageStatus : \"done\";\n\n useContentPart.setState({ part, status });\n};\n\nconst useContentPartContext = (partIndex: number) => {\n const { useMessage } = useMessageContext();\n const [context] = useState<ContentPartContextValue>(() => {\n const useContentPart = create<ContentPartState>(() => ({\n part: { type: \"text\", text: \"\" },\n status: \"done\",\n }));\n\n syncContentPart(useMessage.getState(), useContentPart, partIndex);\n\n return { useContentPart };\n });\n\n useEffect(() => {\n return useMessage.subscribe((message) => {\n syncContentPart(message, context.useContentPart, partIndex);\n });\n }, [context, useMessage, partIndex]);\n\n return context;\n};\n\nexport const ContentPartProvider: FC<ContentPartProviderProps> = ({\n partIndex,\n children,\n}) => {\n const context = useContentPartContext(partIndex);\n\n return (\n <ContentPartContext.Provider value={context}>\n {children}\n </ContentPartContext.Provider>\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport type { ContentPartState } from \"./stores/ContentPart\";\n\nexport type ContentPartContextValue = {\n useContentPart: UseBoundStore<StoreApi<ContentPartState>>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nexport const useContentPartContext = (): ContentPartContextValue => {\n const context = useContext(ContentPartContext);\n if (!context)\n throw new Error(\n \"This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >.\",\n );\n return context;\n};\n","import type { FC } from \"react\";\nimport { useContentPartContext } from \"../../context/ContentPartContext\";\nimport { useMessageContext } from \"../../context/MessageContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport const ContentPartInProgressIndicator: FC = () => {\n const { useMessage } = useMessageContext();\n const { useContentPart } = useContentPartContext();\n\n const indicator = useCombinedStore([useMessage, useContentPart], (m, c) =>\n c.status === \"in_progress\" ? m.inProgressIndicator : null,\n );\n return indicator;\n};\n","\"use client\";\n\nimport type { ComponentType, FC, ReactNode } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\nimport { ContentPartProvider } from \"../../context/providers/ContentPartProvider\";\nimport type {\n ImageContentPart,\n TextContentPart,\n ToolCallContentPart,\n UIContentPart,\n} from \"../../utils/AssistantTypes\";\nimport { ContentPartInProgressIndicator } from \"../contentPart/ContentPartInProgressIndicator\";\n\ntype MessageContentProps = {\n components?: {\n Text?: ComponentType<{ part: TextContentPart }>;\n Image?: ComponentType<{ part: ImageContentPart }>;\n UI?: ComponentType<{ part: UIContentPart }>;\n tools?: {\n by_name?: Record<string, ComponentType<{ part: ToolCallContentPart }>>;\n Fallback?: ComponentType<{ part: ToolCallContentPart }>;\n };\n };\n};\n\nconst defaultComponents = {\n Text: ({ part }) => (\n <>\n {part.text}\n <ContentPartInProgressIndicator />\n </>\n ),\n Image: () => null,\n UI: ({ part }) => part.display,\n tools: {\n Fallback: () => null,\n },\n} satisfies MessageContentProps[\"components\"];\n\nexport const MessageContent: FC<MessageContentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Image = defaultComponents.Image,\n UI = defaultComponents.UI,\n tools: { by_name = {}, Fallback = defaultComponents.tools.Fallback } = {},\n } = {},\n}) => {\n const { useMessage } = useMessageContext();\n\n const message = useMessage((s) => s.message);\n const content = message.content;\n\n return (\n <>\n {content.map((part, i) => {\n const partIndex = i; // use the index as key, as message is generally append only\n\n const type = part.type;\n let component: ReactNode | null = null;\n switch (type) {\n case \"text\":\n component = <Text part={part} />;\n break;\n\n case \"image\":\n component = <Image part={part} />;\n break;\n case \"ui\":\n component = <UI part={part} />;\n break;\n case \"tool-call\": {\n const Tool = by_name[part.name] || Fallback;\n component = <Tool part={part} />;\n break;\n }\n default:\n throw new Error(`Unknown content part type: ${type}`);\n }\n\n return (\n <ContentPartProvider key={partIndex} partIndex={partIndex}>\n {component}\n </ContentPartProvider>\n );\n })}\n </>\n );\n};\n","\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, useMemo } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\n\ntype MessageInProgressElement = ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.span>;\n\ntype MessageInProgressProps = PrimitiveSpanProps;\n\nexport const MessageInProgress = forwardRef<\n MessageInProgressElement,\n MessageInProgressProps\n>((props, ref) => {\n const { useMessage } = useMessageContext();\n\n useMemo(() => {\n useMessage\n .getState()\n .setInProgressIndicator(<Primitive.span {...props} ref={ref} />);\n }, [useMessage, props, ref]);\n\n return null;\n});\n","export { BranchPickerNext as Next } from \"./BranchPickerNext\";\nexport { BranchPickerPrevious as Previous } from \"./BranchPickerPrevious\";\nexport { BranchPickerCount as Count } from \"./BranchPickerCount\";\nexport { BranchPickerNumber as Number } from \"./BranchPickerNumber\";\nexport { BranchPickerRoot as Root } from \"./BranchPickerRoot\";\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\n\ntype ActionButtonCallback<TProps> = (props: TProps) => null | (() => void);\n\nexport const createActionButton = <TProps,>(\n useActionButton: ActionButtonCallback<TProps>,\n) => {\n type PrimitiveButtonElement = ElementRef<typeof Primitive.button>;\n type PrimitiveButtonProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\n return forwardRef<PrimitiveButtonElement, PrimitiveButtonProps & TProps>(\n (props, forwardedRef) => {\n const onClick = useActionButton(props);\n\n return (\n <Primitive.button\n type=\"button\"\n disabled={!onClick}\n {...props}\n ref={forwardedRef}\n onClick={composeEventHandlers(props.onClick, onClick ?? undefined)}\n />\n );\n },\n );\n};\n","\"use client\";\n\nimport { useGoToNextBranch } from \"../../actions/useGoToNextBranch\";\nimport { createActionButton } from \"../../utils/createActionButton\";\n\nexport const BranchPickerNext = createActionButton(useGoToNextBranch);\n","\"use client\";\n\nimport { useGoToPreviousBranch } from \"../../actions/useGoToPreviousBranch\";\nimport { createActionButton } from \"../../utils/createActionButton\";\n\nexport const BranchPickerPrevious = createActionButton(useGoToPreviousBranch);\n","\"use client\";\n\nimport type { FC } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\n\nexport const BranchPickerCount: FC = () => {\n const { useMessage } = useMessageContext();\n const branchCount = useMessage((s) => s.branches.length);\n return <>{branchCount}</>;\n};\n","\"use client\";\n\nimport type { FC } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\n\nexport const BranchPickerNumber: FC = () => {\n const { useMessage } = useMessageContext();\n const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));\n return <>{branchIdx + 1}</>;\n};\n","\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { If } from \"../message\";\n\ntype BranchPickerRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\ntype BranchPickerRootProps = PrimitiveDivProps & {\n hideWhenSingleBranch?: boolean;\n};\n\nexport const BranchPickerRoot = forwardRef<\n BranchPickerRootElement,\n BranchPickerRootProps\n>(({ hideWhenSingleBranch, ...rest }, ref) => {\n return (\n <If hasBranches={hideWhenSingleBranch ? true : undefined}>\n <Primitive.div {...rest} ref={ref} />\n </If>\n );\n});\n","export { ActionBarRoot as Root } from \"./ActionBarRoot\";\nexport { ActionBarCopy as Copy } from \"./ActionBarCopy\";\nexport { ActionBarReload as Reload } from \"./ActionBarReload\";\nexport { ActionBarEdit as Edit } from \"./ActionBarEdit\";\n","\"use client\";\n\nimport {\n type ComponentPropsWithoutRef,\n Primitive,\n} from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef } from \"react\";\nimport { useMessageContext } from \"../../context/MessageContext\";\nimport { useThreadContext } from \"../../context/ThreadContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\ntype ActionBarRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nenum HideAndFloatStatus {\n Hidden = \"hidden\",\n Floating = \"floating\",\n Normal = \"normal\",\n}\n\nexport type ActionBarRootProps = PrimitiveDivProps & {\n hideWhenRunning?: boolean;\n autohide?: \"always\" | \"not-last\" | \"never\";\n autohideFloat?: \"always\" | \"single-branch\" | \"never\";\n};\n\nexport const ActionBarRoot = forwardRef<\n ActionBarRootElement,\n ActionBarRootProps\n>(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {\n const { useThread } = useThreadContext();\n const { useMessage } = useMessageContext();\n\n const hideAndfloatStatus = useCombinedStore(\n [useThread, useMessage],\n (t, m) => {\n if (hideWhenRunning && t.isRunning) return HideAndFloatStatus.Hidden;\n\n const autohideEnabled =\n autohide === \"always\" || (autohide === \"not-last\" && !m.isLast);\n\n // normal status\n if (!autohideEnabled) return HideAndFloatStatus.Normal;\n\n // hidden status\n if (!m.isHovering) return HideAndFloatStatus.Hidden;\n\n // floating status\n if (\n autohideFloat === \"always\" ||\n (autohideFloat === \"single-branch\" && m.branches.length <= 1)\n )\n return HideAndFloatStatus.Floating;\n\n return HideAndFloatStatus.Normal;\n },\n );\n\n if (hideAndfloatStatus === HideAndFloatStatus.Hidden) return null;\n\n return (\n <Primitive.div\n data-floating={hideAndfloatStatus === HideAndFloatStatus.Floating}\n {...rest}\n ref={ref}\n />\n );\n});\n","\"use client\";\n\nimport { useCopyMessage } from \"../../actions/useCopyMessage\";\nimport { createActionButton } from \"../../utils/createActionButton\";\n\ntype ActionBarCopyProps = {\n copiedDuration?: number;\n};\n\nexport const ActionBarCopy =\n createActionButton<ActionBarCopyProps>(useCopyMessage);\n","\"use client\";\n\nimport { useReloadMessage } from \"../../actions/useReloadMessage\";\nimport { createActionButton } from \"../../utils/createActionButton\";\n\nexport const ActionBarReload = createActionButton(useReloadMessage);\n","\"use client\";\n\nimport { useBeginMessageEdit } from \"../../actions/useBeginMessageEdit\";\nimport { createActionButton } from \"../../utils/createActionButton\";\n\nexport const ActionBarEdit = createActionButton(useBeginMessageEdit);\n","export { ContentPartInProgressIndicator as InProgressIndicator } from \"./ContentPartInProgressIndicator\";\n","\"use client\";\n\nimport { useEffect, useInsertionEffect, useState } from \"react\";\nimport type { VercelRSCAdapter } from \"./VercelRSCAdapter\";\nimport { VercelRSCRuntime } from \"./VercelRSCRuntime\";\n\nexport const useVercelRSCRuntime = <T extends WeakKey>(\n adapter: VercelRSCAdapter<T>,\n) => {\n const [runtime] = useState(() => new VercelRSCRuntime(adapter));\n\n useInsertionEffect(() => {\n runtime.adapter = adapter;\n });\n useEffect(() => {\n runtime.onAdapterUpdated();\n });\n\n return runtime;\n};\n","\"use client\";\n\nimport { type StoreApi, type UseBoundStore, create } from \"zustand\";\nimport type {\n AppendMessage,\n ThreadMessage,\n} from \"../../../utils/AssistantTypes\";\nimport type { AssistantRuntime } from \"../../core/AssistantRuntime\";\nimport type { ReactThreadRuntime, Unsubscribe } from \"../../core/ThreadRuntime\";\nimport type { VercelRSCAdapter } from \"./VercelRSCAdapter\";\nimport type { VercelRSCMessage } from \"./VercelRSCMessage\";\nimport { useVercelRSCSync } from \"./useVercelRSCSync\";\n\nconst EMPTY_BRANCHES: readonly never[] = Object.freeze([]);\n\nexport class VercelRSCRuntime<T extends WeakKey = VercelRSCMessage>\n implements AssistantRuntime, ReactThreadRuntime\n{\n private useAdapter: UseBoundStore<StoreApi<{ adapter: VercelRSCAdapter<T> }>>;\n\n private _subscriptions = new Set<() => void>();\n\n public isRunning = false;\n public messages: ThreadMessage[] = [];\n\n constructor(public adapter: VercelRSCAdapter<T>) {\n this.useAdapter = create(() => ({\n adapter,\n }));\n }\n\n private withRunning = (callback: Promise<unknown>) => {\n this.isRunning = true;\n return callback.finally(() => {\n this.isRunning = false;\n });\n };\n\n public getBranches(): readonly string[] {\n return EMPTY_BRANCHES;\n }\n\n public switchToBranch(): void {\n throw new Error(\n \"Branch switching is not supported by VercelRSCAssistantProvider.\",\n );\n }\n\n public async append(message: AppendMessage): Promise<void> {\n if (message.parentId !== (this.messages.at(-1)?.id ?? null)) {\n if (!this.adapter.edit)\n throw new Error(\n \"Message editing is not enabled, please provide an edit callback to VercelRSCAssistantProvider.\",\n );\n await this.withRunning(this.adapter.edit(message));\n } else {\n await this.withRunning(this.adapter.append(message));\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n if (!this.adapter.reload)\n throw new Error(\n \"Message reloading is not enabled, please provide a reload callback to VercelRSCAssistantProvider.\",\n );\n await this.withRunning(this.adapter.reload(parentId));\n }\n\n cancelRun(): void {\n // in dev mode, log a warning\n if (process.env[\"NODE_ENV\"] === \"development\") {\n console.warn(\n \"Run cancellation is not supported by VercelRSCAssistantProvider.\",\n );\n }\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n public onAdapterUpdated() {\n if (this.useAdapter.getState().adapter !== this.adapter) {\n this.useAdapter.setState({ adapter: this.adapter });\n }\n }\n\n private updateData = (messages: ThreadMessage[]) => {\n this.messages = messages;\n for (const callback of this._subscriptions) callback();\n };\n\n unstable_synchronizer = () => {\n const { adapter } = this.useAdapter();\n\n useVercelRSCSync(adapter, this.updateData);\n\n return null;\n };\n}\n","import { useEffect, useMemo } from \"react\";\nimport type {\n ThreadMessage,\n VercelRSCAdapter,\n VercelRSCMessage,\n} from \"../../../../dist\";\nimport {\n type ConverterCallback,\n ThreadMessageConverter,\n} from \"../utils/ThreadMessageConverter\";\nimport {\n type VercelRSCThreadMessage,\n symbolInnerRSCMessage,\n} from \"./getVercelRSCMessage\";\n\nconst vercelToThreadMessage = <T,>(\n converter: (message: T) => VercelRSCMessage,\n rawMessage: T,\n): VercelRSCThreadMessage<T> => {\n const message = converter(rawMessage);\n\n return {\n id: message.id,\n role: message.role,\n content: [{ type: \"ui\", display: message.display }],\n createdAt: message.createdAt ?? new Date(),\n ...{ status: \"done\" },\n [symbolInnerRSCMessage]: rawMessage,\n };\n};\n\ntype UpdateDataCallback = (messages: ThreadMessage[]) => void;\n\nexport const useVercelRSCSync = <T extends WeakKey>(\n adapter: VercelRSCAdapter<T>,\n updateData: UpdateDataCallback,\n) => {\n // flush the converter cache when the convertMessage prop changes\n const [converter, convertCallback] = useMemo(() => {\n const rscConverter =\n adapter.convertMessage ?? ((m: T) => m as VercelRSCMessage);\n const convertCallback: ConverterCallback<T> = (m, cache) => {\n if (cache) return cache;\n return vercelToThreadMessage(rscConverter, m);\n };\n return [new ThreadMessageConverter(), convertCallback];\n }, [adapter.convertMessage]);\n\n useEffect(() => {\n updateData(converter.convertMessages(adapter.messages, convertCallback));\n }, [updateData, converter, convertCallback, adapter.messages]);\n};\n","\"use client\";\n\nimport type { ThreadMessage } from \"../../../utils/AssistantTypes\";\n\nexport type ConverterCallback<TIn> = (\n message: TIn,\n cache: ThreadMessage | undefined,\n) => ThreadMessage;\n\nexport class ThreadMessageConverter {\n private readonly cache = new WeakMap<WeakKey, ThreadMessage>();\n\n convertMessages<TIn extends WeakKey>(\n messages: TIn[],\n converter: ConverterCallback<TIn>,\n keyMapper: (m: TIn) => WeakKey = (key) => key,\n ): ThreadMessage[] {\n return messages.map((m) => {\n const key = keyMapper(m);\n const cached = this.cache.get(key);\n const newMessage = converter(m, cached);\n this.cache.set(key, newMessage);\n return newMessage;\n });\n }\n}\n","import type { ThreadMessage } from \"../../../utils/AssistantTypes\";\n\nexport const symbolInnerRSCMessage = Symbol(\"innerVercelRSCMessage\");\n\nexport type VercelRSCThreadMessage<T> = ThreadMessage & {\n [symbolInnerRSCMessage]?: T;\n};\n\nexport const getVercelRSCMessage = <T,>(message: ThreadMessage) => {\n return (message as VercelRSCThreadMessage<T>)[symbolInnerRSCMessage];\n};\n","import type { UseChatHelpers } from \"@ai-sdk/react\";\nimport { useEffect, useInsertionEffect, useState } from \"react\";\nimport { VercelAIRuntime } from \"../VercelAIRuntime\";\n\nexport const useVercelUseChatRuntime = (chatHelpers: UseChatHelpers) => {\n const [runtime] = useState(() => new VercelAIRuntime(chatHelpers));\n\n useInsertionEffect(() => {\n runtime.vercel = chatHelpers;\n });\n useEffect(() => {\n runtime.onVercelUpdated();\n });\n\n return runtime;\n};\n","import type { Message } from \"ai\";\nimport { type StoreApi, type UseBoundStore, create } from \"zustand\";\nimport type {\n AppendMessage,\n ThreadMessage,\n} from \"../../../utils/AssistantTypes\";\nimport type { AssistantRuntime } from \"../../core/AssistantRuntime\";\nimport type { ReactThreadRuntime, Unsubscribe } from \"../../core/ThreadRuntime\";\nimport { MessageRepository } from \"../../utils/MessageRepository\";\nimport { getVercelAIMessage } from \"./getVercelAIMessage\";\nimport type { VercelHelpers } from \"./utils/VercelHelpers\";\nimport { sliceMessagesUntil } from \"./utils/sliceMessagesUntil\";\nimport { useVercelAIComposerSync } from \"./utils/useVercelAIComposerSync\";\nimport { useVercelAIThreadSync } from \"./utils/useVercelAIThreadSync\";\n\nconst hasUpcomingMessage = (isRunning: boolean, messages: ThreadMessage[]) => {\n return isRunning && messages[messages.length - 1]?.role !== \"assistant\";\n};\n\nexport class VercelAIRuntime implements AssistantRuntime, ReactThreadRuntime {\n private _subscriptions = new Set<() => void>();\n private repository = new MessageRepository();\n private assistantOptimisticId: string | null = null;\n\n private useVercel: UseBoundStore<StoreApi<{ vercel: VercelHelpers }>>;\n\n public messages: ThreadMessage[] = [];\n public isRunning = false;\n\n constructor(public vercel: VercelHelpers) {\n this.useVercel = create(() => ({\n vercel,\n }));\n }\n\n public getBranches(messageId: string): string[] {\n return this.repository.getBranches(messageId);\n }\n\n public switchToBranch(branchId: string): void {\n this.repository.switchToBranch(branchId);\n this.updateVercelMessages(this.repository.getMessages());\n }\n\n public async append(message: AppendMessage): Promise<void> {\n // add user message\n if (message.content.length !== 1 || message.content[0]?.type !== \"text\")\n throw new Error(\"Only text content is supported by Vercel AI SDK.\");\n\n const newMessages = sliceMessagesUntil(\n this.vercel.messages,\n message.parentId,\n );\n this.vercel.setMessages(newMessages);\n\n await this.vercel.append({\n role: \"user\",\n content: message.content[0].text,\n });\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n const reloadMaybe =\n \"reload\" in this.vercel ? this.vercel.reload : undefined;\n if (!reloadMaybe)\n throw new Error(\n \"Reload is not supported by Vercel AI SDK's useAssistant.\",\n );\n\n const newMessages = sliceMessagesUntil(this.vercel.messages, parentId);\n this.vercel.setMessages(newMessages);\n\n await reloadMaybe();\n }\n\n public cancelRun(): void {\n const previousMessage = this.vercel.messages.at(-1);\n\n this.vercel.stop();\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n let messages = this.repository.getMessages();\n if (\n previousMessage?.role === \"user\" &&\n previousMessage.id === messages.at(-1)?.id // ensure the previous message is a leaf node\n ) {\n this.vercel.setInput(previousMessage.content);\n this.repository.deleteMessage(previousMessage.id);\n\n messages = this.repository.getMessages();\n }\n\n // resync messages\n setTimeout(() => {\n this.updateVercelMessages(messages);\n }, 0);\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private updateVercelMessages = (messages: ThreadMessage[]) => {\n this.vercel.setMessages(\n messages\n .flatMap(getVercelAIMessage)\n .filter((m): m is Message => m != null),\n );\n };\n\n public onVercelUpdated() {\n if (this.useVercel.getState().vercel !== this.vercel) {\n this.useVercel.setState({ vercel: this.vercel });\n }\n }\n\n private updateData = (isRunning: boolean, vm: ThreadMessage[]) => {\n for (let i = 0; i < vm.length; i++) {\n const message = vm[i]!;\n const parent = vm[i - 1];\n this.repository.addOrUpdateMessage(parent?.id ?? null, message);\n }\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n if (hasUpcomingMessage(isRunning, vm)) {\n this.assistantOptimisticId = this.repository.appendOptimisticMessage(\n vm.at(-1)?.id ?? null,\n {\n role: \"assistant\",\n content: [{ type: \"text\", text: \"\" }],\n },\n );\n }\n\n this.repository.resetHead(\n this.assistantOptimisticId ?? vm.at(-1)?.id ?? null,\n );\n\n this.messages = this.repository.getMessages();\n this.isRunning = isRunning;\n\n for (const callback of this._subscriptions) callback();\n };\n\n unstable_synchronizer = () => {\n const { vercel } = this.useVercel();\n\n useVercelAIThreadSync(vercel, this.updateData);\n useVercelAIComposerSync(vercel);\n\n return null;\n };\n}\n","\"use client\";\nimport { customAlphabet } from \"nanoid/non-secure\";\n\nexport const generateId = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n);\n\nconst optimisticPrefix = \"__optimistic__\";\nexport const generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;\nexport const isOptimisticId = (id: string) => id.startsWith(optimisticPrefix);\n","\"use client\";\n\nimport type { ThreadMessage } from \"../../utils/AssistantTypes\";\nimport { generateOptimisticId } from \"./idUtils\";\n\ntype RepositoryParent = {\n children: string[];\n};\n\ntype RepositoryMessage = RepositoryParent & {\n prev: RepositoryMessage | null;\n current: ThreadMessage;\n next: RepositoryMessage | null;\n level: number;\n};\n\nconst findHead = (message: RepositoryMessage): RepositoryMessage => {\n if (message.next) return findHead(message.next);\n return message;\n};\n\nexport class MessageRepository {\n private messages = new Map<string, RepositoryMessage>(); // message_id -> item\n private head: RepositoryMessage | null = null;\n private root: RepositoryParent = {\n children: [],\n };\n\n private performOp(\n newParent: RepositoryMessage | null,\n child: RepositoryMessage,\n operation: \"cut\" | \"link\" | \"relink\",\n ) {\n const parentOrRoot = child.prev ?? this.root;\n const newParentOrRoot = newParent ?? this.root;\n\n if (operation === \"relink\" && parentOrRoot === newParentOrRoot) return;\n\n // cut\n if (operation !== \"link\") {\n parentOrRoot.children = parentOrRoot.children.filter(\n (m) => m !== child.current.id,\n );\n\n if (child.prev?.next === child) {\n const fallbackId = child.prev.children.at(-1);\n const fallback = fallbackId ? this.messages.get(fallbackId) : null;\n if (fallback === undefined) {\n throw new Error(\n \"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.\",\n );\n }\n child.prev.next = fallback;\n }\n }\n\n // link\n if (operation !== \"cut\") {\n newParentOrRoot.children = [\n ...newParentOrRoot.children,\n child.current.id,\n ];\n\n if (\n newParent &&\n (findHead(child) === this.head || newParent.next === null)\n ) {\n newParent.next = child;\n }\n\n child.prev = newParent;\n }\n }\n getMessages() {\n const messages = new Array<ThreadMessage>(this.head?.level ?? 0);\n for (let current = this.head; current; current = current.prev) {\n messages[current.level] = current.current;\n }\n return messages;\n }\n\n addOrUpdateMessage(parentId: string | null, message: ThreadMessage) {\n const existingItem = this.messages.get(message.id);\n const prev = parentId ? this.messages.get(parentId) : null;\n if (prev === undefined)\n throw new Error(\n \"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n // update existing message\n if (existingItem) {\n existingItem.current = message;\n this.performOp(prev, existingItem, \"relink\");\n return;\n }\n\n // create a new message\n const newItem: RepositoryMessage = {\n prev,\n current: message,\n next: null,\n children: [],\n level: prev ? prev.level + 1 : 0,\n };\n\n this.messages.set(message.id, newItem);\n this.performOp(prev, newItem, \"link\");\n\n if (this.head === prev) {\n this.head = newItem;\n }\n }\n\n appendOptimisticMessage(\n parentId: string | null,\n message: Omit<ThreadMessage, \"id\" | \"createdAt\">,\n ) {\n let optimisticId: string;\n do {\n optimisticId = generateOptimisticId();\n } while (this.messages.has(optimisticId));\n\n this.addOrUpdateMessage(parentId, {\n ...message,\n id: optimisticId,\n createdAt: new Date(),\n ...(message.role === \"assistant\" ? { status: \"in_progress\" } : undefined),\n } as ThreadMessage);\n\n return optimisticId;\n }\n\n deleteMessage(messageId: string, replacementId?: string | null | undefined) {\n const message = this.messages.get(messageId);\n\n if (!message)\n throw new Error(\n \"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const replacement =\n replacementId === undefined\n ? message.prev // if no replacementId is provided, use the parent\n : replacementId === null\n ? null\n : this.messages.get(replacementId);\n if (replacement === undefined)\n throw new Error(\n \"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.\",\n );\n\n for (const child of message.children) {\n const childMessage = this.messages.get(child);\n if (!childMessage)\n throw new Error(\n \"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.\",\n );\n this.performOp(replacement, childMessage, \"relink\");\n }\n\n this.performOp(null, message, \"cut\");\n this.messages.delete(messageId);\n\n if (this.head === message) {\n this.head = replacement ? findHead(replacement) : null;\n }\n }\n\n getBranches(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const { children } = message.prev ?? this.root;\n return children;\n }\n\n switchToBranch(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n if (message.prev) {\n message.prev.next = message;\n }\n\n this.head = findHead(message);\n }\n\n resetHead(messageId: string | null) {\n if (messageId === null) {\n this.head = null;\n return;\n }\n\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n this.head = message;\n for (\n let current: RepositoryMessage | null = message;\n current;\n current = current.prev\n ) {\n if (current.prev) {\n current.prev.next = current;\n }\n }\n }\n}\n","import type { Message } from \"ai\";\nimport type { ThreadMessage } from \"../../../utils/AssistantTypes\";\n\nexport const symbolInnerAIMessage = Symbol(\"innerVercelAIUIMessage\");\n\nexport type VercelAIThreadMessage = ThreadMessage & {\n [symbolInnerAIMessage]?: Message[];\n};\n\nexport const getVercelAIMessage = (message: ThreadMessage) => {\n return (message as VercelAIThreadMessage)[symbolInnerAIMessage];\n};\n","import type { Message } from \"ai\";\n\nexport const sliceMessagesUntil = (\n messages: Message[],\n messageId: string | null,\n) => {\n if (messageId == null) return [];\n\n let messageIdx = messages.findIndex((m) => m.id === messageId);\n if (messageIdx === -1)\n throw new Error(\n \"useVercelAIThreadState: Message not found. This is liekly an internal bug in assistant-ui.\",\n );\n\n while (messages[messageIdx + 1]?.role === \"assistant\") {\n messageIdx++;\n }\n\n return messages.slice(0, messageIdx + 1);\n};\n","import { useEffect } from \"react\";\nimport { useThreadContext } from \"../../../../context\";\nimport type { VercelHelpers } from \"./VercelHelpers\";\n\n// two way sync between vercel helpers input state and composer text state\nexport const useVercelAIComposerSync = (vercel: VercelHelpers) => {\n const { useComposer } = useThreadContext();\n\n useEffect(() => {\n useComposer.setState({\n value: vercel.input,\n setValue: vercel.setInput,\n });\n }, [useComposer, vercel.input, vercel.setInput]);\n};\n","import type { Message } from \"ai\";\nimport { useEffect, useMemo } from \"react\";\nimport type {\n TextContentPart,\n ThreadMessage,\n ToolCallContentPart,\n} from \"../../../../utils/AssistantTypes\";\nimport {\n type ConverterCallback,\n ThreadMessageConverter,\n} from \"../../utils/ThreadMessageConverter\";\nimport {\n type VercelAIThreadMessage,\n symbolInnerAIMessage,\n} from \"../getVercelAIMessage\";\nimport type { VercelHelpers } from \"./VercelHelpers\";\n\nconst getIsRunning = (vercel: VercelHelpers) => {\n if (\"isLoading\" in vercel) return vercel.isLoading;\n return vercel.status === \"in_progress\";\n};\n\nconst vercelToThreadMessage = (\n messages: Message[],\n status: \"in_progress\" | \"done\" | \"error\",\n): VercelAIThreadMessage => {\n const firstMessage = messages[0];\n if (!firstMessage) throw new Error(\"No messages found\");\n\n const common = {\n id: firstMessage.id,\n createdAt: firstMessage.createdAt ?? new Date(),\n [symbolInnerAIMessage]: messages,\n };\n\n switch (firstMessage.role) {\n case \"user\":\n if (messages.length > 1) {\n throw new Error(\n \"Multiple user messages found. This is likely an internal bug in assistant-ui.\",\n );\n }\n\n return {\n ...common,\n role: \"user\",\n content: [{ type: \"text\", text: firstMessage.content }],\n };\n case \"assistant\":\n return {\n ...common,\n role: \"assistant\",\n content: messages.flatMap((message) => [\n ...(message.content\n ? [{ type: \"text\", text: message.content } as TextContentPart]\n : []),\n ...(message.toolInvocations?.map(\n (t) =>\n ({\n type: \"tool-call\",\n name: t.toolName,\n args: t.args,\n result: \"result\" in t ? t.result : undefined,\n }) as ToolCallContentPart,\n ) ?? []),\n ]),\n status,\n };\n default:\n throw new Error(\n `You have a message with an unsupported role. The role ${firstMessage.role} is not supported.`,\n );\n }\n};\n\ntype Chunk = [Message, ...Message[]];\nconst hasItems = (messages: Message[]): messages is Chunk =>\n messages.length > 0;\n\nconst chunkedMessages = (messages: Message[]): Chunk[] => {\n const chunks: Chunk[] = [];\n let currentChunk: Message[] = [];\n\n for (const message of messages) {\n if (message.role === \"assistant\") {\n currentChunk.push(message);\n } else {\n if (hasItems(currentChunk)) {\n chunks.push(currentChunk);\n currentChunk = [];\n }\n chunks.push([message]);\n }\n }\n\n if (hasItems(currentChunk)) {\n chunks.push(currentChunk);\n }\n\n return chunks;\n};\n\nconst shallowArrayEqual = (a: unknown[], b: unknown[]) => {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n};\n\ntype UpdateDataCallback = (isRunning: boolean, vm: ThreadMessage[]) => void;\n\nexport const useVercelAIThreadSync = (\n vercel: VercelHelpers,\n updateData: UpdateDataCallback,\n) => {\n const isRunning = getIsRunning(vercel);\n\n const converter = useMemo(() => new ThreadMessageConverter(), []);\n\n useEffect(() => {\n const lastMessageId = vercel.messages.at(-1)?.id;\n const convertCallback: ConverterCallback<Chunk> = (messages, cache) => {\n const status =\n lastMessageId === messages[0].id && isRunning ? \"in_progress\" : \"done\";\n\n if (\n cache &&\n shallowArrayEqual(cache.content, messages) &&\n (cache.role === \"user\" || cache.status === status)\n )\n return cache;\n\n return vercelToThreadMessage(messages, status);\n };\n\n const messages = converter.convertMessages(\n chunkedMessages(vercel.messages),\n convertCallback,\n (m) => m[0],\n );\n\n updateData(isRunning, messages);\n }, [updateData, isRunning, vercel.messages, converter]);\n};\n","import type { UseAssistantHelpers } from \"@ai-sdk/react\";\nimport { useEffect, useInsertionEffect, useState } from \"react\";\nimport { VercelAIRuntime } from \"../VercelAIRuntime\";\n\nexport const useVercelUseAssistantRuntime = (\n assistantHelpers: UseAssistantHelpers,\n) => {\n const [runtime] = useState(() => new VercelAIRuntime(assistantHelpers));\n\n useInsertionEffect(() => {\n runtime.vercel = assistantHelpers;\n });\n useEffect(() => {\n runtime.onVercelUpdated();\n });\n\n return runtime;\n};\n","import type { FC, PropsWithChildren } from \"react\";\nimport { memo } from \"react\";\nimport type { AssistantRuntime } from \"../../runtime/core/AssistantRuntime\";\nimport { ThreadProvider } from \"./ThreadProvider\";\n\ntype AssistantRuntimeProviderProps = {\n runtime: AssistantRuntime;\n};\n\nconst AssistantRuntimeProviderImpl: FC<\n PropsWithChildren<AssistantRuntimeProviderProps>\n> = ({ children, runtime }) => {\n return <ThreadProvider runtime={runtime}>{children}</ThreadProvider>;\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n","import type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useInsertionEffect, useRef, useState } from \"react\";\nimport type {\n ReactThreadRuntime,\n ThreadRuntime,\n} from \"../../runtime/core/ThreadRuntime\";\nimport type { ThreadContextValue } from \"../ThreadContext\";\nimport { ThreadContext } from \"../ThreadContext\";\nimport { makeComposerStore } from \"../stores/Composer\";\nimport { makeThreadStore } from \"../stores/Thread\";\nimport { makeThreadViewportStore } from \"../stores/ThreadViewport\";\n\ntype ThreadProviderProps = {\n runtime: ThreadRuntime;\n};\n\nexport const ThreadProvider: FC<PropsWithChildren<ThreadProviderProps>> = ({\n children,\n runtime,\n}) => {\n const runtimeRef = useRef(runtime);\n useInsertionEffect(() => {\n runtimeRef.current = runtime;\n });\n\n const [{ context, onRuntimeUpdate }] = useState(() => {\n const { useThread, onRuntimeUpdate } = makeThreadStore(runtimeRef);\n const useViewport = makeThreadViewportStore();\n const useComposer = makeComposerStore(useThread);\n\n return {\n context: {\n useViewport,\n useThread,\n useComposer,\n } satisfies ThreadContextValue,\n onRuntimeUpdate,\n };\n });\n\n useEffect(() => {\n // whenever the runtime changes\n onRuntimeUpdate();\n\n // subscribe to runtime updates\n return runtime.subscribe(onRuntimeUpdate);\n }, [onRuntimeUpdate, runtime]);\n\n const RuntimeSynchronizer = (runtime as ReactThreadRuntime)\n .unstable_synchronizer;\n\n return (\n <ThreadContext.Provider value={context}>\n {RuntimeSynchronizer && <RuntimeSynchronizer />}\n {children}\n </ThreadContext.Provider>\n );\n};\n","import { type StoreApi, type UseBoundStore, create } from \"zustand\";\nimport { type BaseComposerState, makeBaseComposer } from \"./BaseComposer\";\nimport type { ThreadState } from \"./Thread\";\n\nexport type ComposerState = BaseComposerState &\n Readonly<{\n isEditing: true;\n\n send: () => void;\n cancel: () => boolean;\n }>;\n\nexport const makeComposerStore = (\n useThread: StoreApi<ThreadState>,\n): UseBoundStore<StoreApi<ComposerState>> =>\n create<ComposerState>()((set, get, store) => {\n return {\n ...makeBaseComposer(set, get, store),\n\n isEditing: true,\n\n send: () => {\n const { setValue, value } = get();\n setValue(\"\");\n\n useThread.getState().append({\n parentId: useThread.getState().messages.at(-1)?.id ?? null,\n content: [{ type: \"text\", text: value }],\n });\n },\n cancel: () => {\n const thread = useThread.getState();\n if (!thread.isRunning) return false;\n\n useThread.getState().cancelRun();\n return true;\n },\n };\n });\n","import type { MutableRefObject } from \"react\";\nimport { create } from \"zustand\";\nimport type { AppendMessage, ThreadMessage } from \"../../utils/AssistantTypes\";\n\nexport type ThreadState = {\n messages: ThreadMessage[];\n isRunning: boolean;\n\n getBranches: (messageId: string) => readonly string[];\n switchToBranch: (branchId: string) => void;\n\n append: (message: AppendMessage) => void;\n startRun: (parentId: string | null) => void;\n cancelRun: () => void;\n};\n\nexport const makeThreadStore = (runtimeRef: MutableRefObject<ThreadState>) => {\n const useThread = create<ThreadState>(() => ({\n messages: runtimeRef.current.messages,\n isRunning: runtimeRef.current.isRunning,\n getBranches: (messageId) => runtimeRef.current.getBranches(messageId),\n switchToBranch: (branchId) => runtimeRef.current.switchToBranch(branchId),\n startRun: (parentId) => runtimeRef.current.startRun(parentId),\n append: (message) => runtimeRef.current.append(message),\n cancelRun: () => runtimeRef.current.cancelRun(),\n }));\n\n const onRuntimeUpdate = () => {\n useThread.setState({\n messages: runtimeRef.current.messages,\n isRunning: runtimeRef.current.isRunning,\n });\n };\n\n return {\n useThread,\n onRuntimeUpdate,\n };\n};\n","\"use client\";\nimport { create } from \"zustand\";\n\nexport type ThreadViewportState = {\n isAtBottom: boolean;\n scrollToBottom: () => void;\n onScrollToBottom: (callback: () => void) => () => void;\n};\n\nexport const makeThreadViewportStore = () => {\n const scrollToBottomListeners = new Set<() => void>();\n\n return create<ThreadViewportState>(() => ({\n isAtBottom: true,\n scrollToBottom: () => {\n for (const listener of scrollToBottomListeners) {\n listener();\n }\n },\n onScrollToBottom: (callback) => {\n scrollToBottomListeners.add(callback);\n return () => {\n scrollToBottomListeners.delete(callback);\n };\n },\n }));\n};\n","\"use client\";\n\nimport type { UseAssistantHelpers, UseChatHelpers } from \"@ai-sdk/react\";\nimport type { FC, PropsWithChildren } from \"react\";\nimport { AssistantRuntimeProvider } from \"../../context/providers/AssistantRuntimeProvider\";\nimport {\n useVercelUseAssistantRuntime,\n useVercelUseChatRuntime,\n} from \"../vercel-ai\";\n\ntype VercelUseChatRuntimeProps = PropsWithChildren<{\n chat: UseChatHelpers;\n}>;\n\nconst VercelUseChatRuntimeProvider: FC<VercelUseChatRuntimeProps> = ({\n chat,\n children,\n}) => {\n const runtime = useVercelUseChatRuntime(chat);\n\n return (\n <AssistantRuntimeProvider runtime={runtime}>\n {children}\n </AssistantRuntimeProvider>\n );\n};\n\ntype VercelUseAssistantRuntimeProps = PropsWithChildren<{\n assistant: UseAssistantHelpers;\n}>;\n\nconst VercelUseAssistantRuntimeProvider: FC<VercelUseAssistantRuntimeProps> = ({\n assistant,\n children,\n}) => {\n const runtime = useVercelUseAssistantRuntime(assistant);\n\n return (\n <AssistantRuntimeProvider runtime={runtime}>\n {children}\n </AssistantRuntimeProvider>\n );\n};\n\n/**\n * @deprecated Will be removed in 0.1.0.\n */\nexport type VercelAIAssistantProviderProps = PropsWithChildren<\n | {\n chat: UseChatHelpers;\n }\n | {\n assistant: UseAssistantHelpers;\n }\n>;\n\n/**\n * @deprecated `const runtime = useVercelUseChatRuntime(chat)` and `<AssistantRuntimeProvider runtime={...} />`. Will be removed in 0.1.0.\n */\nexport const VercelAIAssistantProvider: FC<VercelAIAssistantProviderProps> = ({\n children,\n ...rest\n}) => {\n if (\"chat\" in rest) {\n return (\n <VercelUseChatRuntimeProvider chat={rest.chat}>\n {children}\n </VercelUseChatRuntimeProvider>\n );\n }\n\n return (\n <VercelUseAssistantRuntimeProvider assistant={rest.assistant}>\n {children}\n </VercelUseAssistantRuntimeProvider>\n );\n};\n","\"use client\";\n\nimport type { PropsWithChildren } from \"react\";\nimport { AssistantRuntimeProvider } from \"../../context/providers/AssistantRuntimeProvider\";\nimport type { VercelRSCAdapter } from \"../vercel-ai/rsc/VercelRSCAdapter\";\nimport type { VercelRSCMessage } from \"../vercel-ai/rsc/VercelRSCMessage\";\nimport { useVercelRSCRuntime } from \"../vercel-ai/rsc/useVercelRSCRuntime\";\n\n/**\n * @deprecated Will be removed in 0.1.0.\n */\nexport type VercelRSCAssistantProviderProps<T> = PropsWithChildren<\n VercelRSCAdapter<T>\n>;\n\n/**\n * @deprecated Replaced with `const runtime = useVercelRSCRuntime({ messages, append })` and `<AssistantRuntimeProvider runtime={runtime} />`. Will be removed in 0.1.0.\n */\nexport const VercelRSCAssistantProvider = <\n T extends WeakKey = VercelRSCMessage,\n>({\n children,\n ...adapter\n}: VercelRSCAssistantProviderProps<T>) => {\n const runtime = useVercelRSCRuntime<T>(adapter as VercelRSCAdapter<T>);\n return (\n <AssistantRuntimeProvider runtime={runtime}>\n {children}\n </AssistantRuntimeProvider>\n );\n};\n","\"use client\";\n\nimport { useInsertionEffect, useState } from \"react\";\nimport type { ChatModelAdapter } from \"./ChatModelAdapter\";\nimport { LocalRuntime } from \"./LocalRuntime\";\n\nexport const useLocalRuntime = (adapter: ChatModelAdapter) => {\n const [runtime] = useState(() => new LocalRuntime(adapter));\n\n useInsertionEffect(() => {\n runtime.adapter = adapter;\n });\n\n return runtime;\n};\n","import type {\n AppendMessage,\n AssistantMessage,\n UserMessage,\n} from \"../../utils/AssistantTypes\";\nimport type { AssistantRuntime } from \"../core/AssistantRuntime\";\nimport type { Unsubscribe } from \"../core/ThreadRuntime\";\nimport { MessageRepository } from \"../utils/MessageRepository\";\nimport { generateId } from \"../utils/idUtils\";\nimport type { ChatModelAdapter, ChatModelRunResult } from \"./ChatModelAdapter\";\n\nexport class LocalRuntime implements AssistantRuntime {\n private _subscriptions = new Set<() => void>();\n\n private abortController: AbortController | null = null;\n private repository = new MessageRepository();\n\n public get messages() {\n return this.repository.getMessages();\n }\n public get isRunning() {\n return this.abortController != null;\n }\n\n constructor(public adapter: ChatModelAdapter) {}\n\n public getBranches(messageId: string): string[] {\n return this.repository.getBranches(messageId);\n }\n\n public switchToBranch(branchId: string): void {\n this.repository.switchToBranch(branchId);\n this.notifySubscribers();\n }\n\n public async append(message: AppendMessage): Promise<void> {\n // add user message\n const userMessageId = generateId();\n const userMessage: UserMessage = {\n id: userMessageId,\n role: \"user\",\n content: message.content,\n createdAt: new Date(),\n };\n this.repository.addOrUpdateMessage(message.parentId, userMessage);\n\n await this.startRun(userMessageId);\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n const id = generateId();\n\n this.repository.resetHead(parentId);\n const messages = this.repository.getMessages();\n\n // add assistant message\n const message: AssistantMessage = {\n id,\n role: \"assistant\",\n status: \"in_progress\",\n content: [{ type: \"text\", text: \"\" }],\n createdAt: new Date(),\n };\n this.repository.addOrUpdateMessage(parentId, { ...message });\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n this.notifySubscribers();\n\n try {\n const updateHandler = ({ content }: ChatModelRunResult) => {\n message.content = content;\n this.repository.addOrUpdateMessage(parentId, { ...message });\n this.notifySubscribers();\n };\n const result = await this.adapter.run({\n messages,\n abortSignal: this.abortController.signal,\n onUpdate: updateHandler,\n });\n updateHandler(result);\n\n message.status = \"done\";\n this.repository.addOrUpdateMessage(parentId, { ...message });\n } catch (e) {\n message.status = \"error\";\n this.repository.addOrUpdateMessage(parentId, { ...message });\n console.error(e);\n } finally {\n this.abortController = null;\n this.notifySubscribers();\n }\n }\n\n cancelRun(): void {\n if (!this.abortController) return;\n\n this.abortController.abort();\n this.abortController = null;\n this.notifySubscribers();\n }\n\n private notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n}\n","\"use client\";\nimport { type LanguageModel, streamText } from \"ai\";\nimport type {\n AssistantContentPart,\n TextContentPart,\n} from \"../../../utils/AssistantTypes\";\nimport type {\n ChatModelAdapter,\n ChatModelRunOptions,\n} from \"../ChatModelAdapter\";\n\nexport class VercelModelAdapter implements ChatModelAdapter {\n constructor(private readonly model: LanguageModel) {}\n\n async run({ messages, abortSignal, onUpdate }: ChatModelRunOptions) {\n const { fullStream } = await streamText({\n model: this.model,\n abortSignal,\n messages: messages.map((m) => ({\n role: m.role,\n content: m.content.filter((c): c is TextContentPart => c.type !== \"ui\"),\n })),\n });\n\n const content: AssistantContentPart[] = [];\n for await (const aiPart of fullStream) {\n switch (aiPart.type) {\n case \"text-delta\": {\n let part = content.at(-1);\n if (!part || part.type !== \"text\") {\n part = { type: \"text\", text: \"\" };\n content.push(part);\n }\n part.text += aiPart.textDelta;\n break;\n }\n // TODO tool results\n case \"tool-call\": {\n content.push({\n type: \"tool-call\",\n name: aiPart.toolName,\n args: aiPart.args,\n });\n break;\n }\n }\n\n onUpdate({ content });\n }\n\n return { content };\n }\n}\n"],"mappings":";;;;;;;AAAA,SAAS,mBAAmB;;;ACA5B,SAAS,eAAe,kBAAkB;AAUnC,IAAM,iBAAiB,cAA0C,IAAI;AAErE,IAAM,oBAAoB,MAAM;AACrC,QAAM,UAAU,WAAW,cAAc;AACzC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;AClBA,SAAS,eAAe;;;ACDxB,SAAS,4BAA4B;AAK9B,IAAM,sBAAsB,CACjC,WACG;AACH,QAAM,YAAY,CAAC,aAAuC;AACxD,UAAM,eAAe,OAAO,IAAI,CAAC,UAAU,MAAM,UAAU,QAAQ,CAAC;AACpE,WAAO,MAAM;AACX,iBAAW,SAAS,cAAc;AAChC,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,CAAC,aAAwC;AAC9C,UAAM,cAAc,MAClB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WAAO,EAAE,QAAQ;AAAA,EACnB;AACF;","names":["c","useCallback","createContext","useContext","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","jsx","Primitive","forwardRef","useCallbackRef","useEffect","useCallbackRef","useEffect","jsx","forwardRef","Primitive","useEffect","create","jsx","useMessageContext","create","useEffect","useContext","useMemo","useContext","useMemo","jsx","jsxs","composeEventHandlers","Primitive","forwardRef","jsx","forwardRef","Primitive","composeEventHandlers","composeEventHandlers","Primitive","forwardRef","jsx","forwardRef","Primitive","composeEventHandlers","composeEventHandlers","useComposedRefs","Primitive","forwardRef","useRef","jsx","forwardRef","useRef","useComposedRefs","Primitive","composeEventHandlers","composeEventHandlers","useComposedRefs","forwardRef","useCallback","useEffect","useRef","jsx","forwardRef","useRef","useComposedRefs","useCallback","useEffect","composeEventHandlers","Primitive","forwardRef","jsx","forwardRef","Primitive","composeEventHandlers","Primitive","forwardRef","jsx","forwardRef","Primitive","composeEventHandlers","composeEventHandlers","Primitive","forwardRef","jsx","forwardRef","Primitive","composeEventHandlers","useEffect","useState","create","createContext","useContext","jsx","useContentPartContext","useState","create","useEffect","Fragment","jsx","jsxs","Primitive","forwardRef","useMemo","jsx","forwardRef","useMemo","Primitive","composeEventHandlers","Primitive","forwardRef","jsx","Fragment","jsx","Fragment","jsx","Primitive","forwardRef","jsx","forwardRef","Primitive","Primitive","forwardRef","jsx","forwardRef","jsx","Primitive","useEffect","useState","create","useEffect","useMemo","useMemo","convertCallback","useEffect","create","useState","useEffect","useEffect","useInsertionEffect","useState","create","useEffect","useEffect","useEffect","useMemo","vercelToThreadMessage","useMemo","useEffect","messages","create","useState","useInsertionEffect","useEffect","useEffect","useInsertionEffect","useState","useState","useInsertionEffect","useEffect","useEffect","useInsertionEffect","useRef","useState","create","create","create","create","jsx","jsxs","useRef","useInsertionEffect","useState","onRuntimeUpdate","useEffect","jsx","jsx","jsx","useInsertionEffect","useState","useState","useInsertionEffect"]}
|
package/package.json
CHANGED
@@ -29,7 +29,7 @@
|
|
29
29
|
"conversational-ui",
|
30
30
|
"conversational-ai"
|
31
31
|
],
|
32
|
-
"version": "0.0.
|
32
|
+
"version": "0.0.26",
|
33
33
|
"license": "MIT",
|
34
34
|
"exports": {
|
35
35
|
".": {
|
@@ -65,7 +65,7 @@
|
|
65
65
|
"peerDependencies": {
|
66
66
|
"@ai-sdk/react": "^0.0.x",
|
67
67
|
"@types/react": "*",
|
68
|
-
"ai": "^3.1.
|
68
|
+
"ai": "^3.1.x",
|
69
69
|
"react": "^18"
|
70
70
|
},
|
71
71
|
"peerDependenciesMeta": {
|
@@ -96,7 +96,7 @@
|
|
96
96
|
"url": "https://github.com/Yonom/assistant-ui/issues"
|
97
97
|
},
|
98
98
|
"scripts": {
|
99
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
99
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --sourcemap",
|
100
100
|
"prepublish": "cp ../../README.md ./README.md"
|
101
101
|
}
|
102
102
|
}
|