@assistant-ui/react 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/context/providers/AssistantRuntimeProvider.tsx","../src/context/providers/AssistantProvider.tsx","../src/context/react/AssistantContext.ts","../src/context/stores/AssistantModelConfig.ts","../src/types/ModelConfigTypes.ts","../src/utils/ProxyConfigProvider.ts","../src/context/stores/AssistantToolUIs.ts","../src/context/providers/ThreadProvider.tsx","../src/context/react/ThreadContext.ts","../src/context/stores/Composer.ts","../src/context/stores/BaseComposer.ts","../src/context/stores/Thread.ts","../src/context/stores/ThreadViewport.tsx","../src/context/stores/ThreadActions.ts","../src/context/stores/ThreadMessages.ts","../src/context/stores/AssistantActions.tsx","../src/context/react/ComposerContext.ts","../src/context/react/MessageContext.ts","../src/context/react/ContentPartContext.ts","../src/hooks/useAppendMessage.tsx","../src/hooks/useSwitchToNewThread.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/makeAssistantTool.tsx","../src/model-config/useAssistantToolUI.tsx","../src/model-config/makeAssistantToolUI.tsx","../src/model-config/useAssistantInstructions.tsx","../src/primitive-hooks/actionBar/useActionBarCopy.tsx","../src/utils/combined/useCombinedStore.ts","../src/utils/combined/createCombinedStore.ts","../src/utils/getMessageText.tsx","../src/primitive-hooks/actionBar/useActionBarEdit.tsx","../src/primitive-hooks/actionBar/useActionBarReload.tsx","../src/primitive-hooks/branchPicker/useBranchPickerCount.tsx","../src/primitive-hooks/branchPicker/useBranchPickerNext.tsx","../src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx","../src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx","../src/primitive-hooks/composer/useComposerCancel.tsx","../src/primitive-hooks/composer/useComposerIf.tsx","../src/primitive-hooks/composer/useComposerSend.tsx","../src/primitive-hooks/contentPart/useContentPartDisplay.tsx","../src/primitive-hooks/contentPart/useContentPartImage.tsx","../src/primitive-hooks/contentPart/useContentPartText.tsx","../src/primitive-hooks/message/useMessageIf.tsx","../src/primitive-hooks/thread/useThreadIf.tsx","../src/primitive-hooks/thread/useThreadEmpty.tsx","../src/primitive-hooks/thread/useThreadScrollToBottom.tsx","../src/primitive-hooks/thread/useThreadSuggestion.tsx","../src/primitives/actionBar/index.ts","../src/primitives/actionBar/ActionBarRoot.tsx","../src/primitives/actionBar/useActionBarFloatStatus.tsx","../src/utils/createActionButton.tsx","../src/primitives/actionBar/ActionBarCopy.tsx","../src/primitives/actionBar/ActionBarReload.tsx","../src/primitives/actionBar/ActionBarEdit.tsx","../src/primitives/assistantModal/index.ts","../src/primitives/assistantModal/AssistantModalRoot.tsx","../src/utils/hooks/useOnComposerFocus.tsx","../src/primitives/assistantModal/scope.tsx","../src/primitives/assistantModal/AssistantModalTrigger.tsx","../src/primitives/assistantModal/AssistantModalContent.tsx","../src/primitives/assistantModal/AssistantModalAnchor.tsx","../src/primitives/branchPicker/index.ts","../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/message/index.ts","../src/primitives/message/MessageRoot.tsx","../src/utils/hooks/useManagedRef.ts","../src/primitives/message/MessageIf.tsx","../src/primitives/message/MessageContent.tsx","../src/context/providers/ContentPartProvider.tsx","../src/primitives/contentPart/ContentPartText.tsx","../src/primitives/contentPart/ContentPartImage.tsx","../src/primitives/contentPart/ContentPartDisplay.tsx","../src/primitives/contentPart/ContentPartInProgress.tsx","../src/primitives/message/MessageInProgress.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/composer/ComposerIf.tsx","../src/primitives/contentPart/index.ts","../src/primitives/thread/index.ts","../src/primitives/thread/ThreadRoot.tsx","../src/primitives/thread/ThreadEmpty.tsx","../src/primitives/thread/ThreadIf.tsx","../src/primitives/thread/ThreadViewport.tsx","../src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx","../src/utils/hooks/useOnResizeContent.tsx","../src/utils/hooks/useOnScrollToBottom.tsx","../src/primitives/thread/ThreadMessages.tsx","../src/context/providers/MessageProvider.tsx","../src/context/stores/EditComposer.ts","../src/context/stores/MessageUtils.ts","../src/primitives/thread/ThreadScrollToBottom.tsx","../src/primitives/thread/ThreadSuggestion.tsx","../src/runtime/local/useLocalRuntime.tsx","../src/runtime/utils/idUtils.tsx","../src/runtime/utils/MessageRepository.tsx","../src/runtime/core/BaseAssistantRuntime.tsx","../src/runtime/local/LocalRuntime.tsx","../src/internal.ts"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { memo } from \"react\";\nimport type { AssistantRuntime } from \"../../runtime/core/AssistantRuntime\";\nimport { AssistantProvider } from \"./AssistantProvider\";\n\ntype AssistantRuntimeProviderProps = {\n runtime: AssistantRuntime;\n};\n\nconst AssistantRuntimeProviderImpl: FC<\n PropsWithChildren<AssistantRuntimeProviderProps>\n> = ({ children, runtime }) => {\n return <AssistantProvider runtime={runtime}>{children}</AssistantProvider>;\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n","import type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useInsertionEffect, useRef, useState } from \"react\";\nimport type { AssistantRuntime } from \"../../runtime\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantModelConfigStore } from \"../stores/AssistantModelConfig\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadProvider } from \"./ThreadProvider\";\nimport { makeAssistantActionsStore } from \"../stores/AssistantActions\";\n\ntype AssistantProviderProps = {\n runtime: AssistantRuntime;\n};\n\nexport const AssistantProvider: FC<\n PropsWithChildren<AssistantProviderProps>\n> = ({ children, runtime }) => {\n const runtimeRef = useRef(runtime);\n useInsertionEffect(() => {\n runtimeRef.current = runtime;\n });\n\n const [context] = useState(() => {\n const useModelConfig = makeAssistantModelConfigStore();\n const useToolUIs = makeAssistantToolUIsStore();\n const useAssistantActions = makeAssistantActionsStore(runtimeRef);\n\n return { useModelConfig, useToolUIs, useAssistantActions };\n });\n\n const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);\n useEffect(() => {\n return runtime.registerModelConfigProvider(getModelCOnfig);\n }, [runtime, getModelCOnfig]);\n\n return (\n <AssistantContext.Provider value={context}>\n <ThreadProvider runtime={runtime}>{children}</ThreadProvider>\n </AssistantContext.Provider>\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { AssistantModelConfigState } from \"../stores/AssistantModelConfig\";\nimport type { AssistantToolUIsState } from \"../stores/AssistantToolUIs\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { AssistantActionsState } from \"../stores/AssistantActions\";\n\nexport type AssistantContextValue = {\n useModelConfig: ReadonlyStore<AssistantModelConfigState>;\n useToolUIs: ReadonlyStore<AssistantToolUIsState>;\n useAssistantActions: ReadonlyStore<AssistantActionsState>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = (): AssistantContextValue => {\n const context = useContext(AssistantContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","\"use client\";\n\nimport { create } from \"zustand\";\nimport type { ModelConfigProvider } from \"../../types/ModelConfigTypes\";\nimport { ProxyConfigProvider } from \"../../utils/ProxyConfigProvider\";\n\nexport type AssistantModelConfigState = Readonly<{\n getModelConfig: ModelConfigProvider;\n registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;\n}>;\n\nexport const makeAssistantModelConfigStore = () =>\n create<AssistantModelConfigState>(() => {\n const proxy = new ProxyConfigProvider();\n\n return Object.freeze({\n getModelConfig: () => {\n return proxy.getModelConfig();\n },\n registerModelConfigProvider: (provider: ModelConfigProvider) => {\n return proxy.registerModelConfigProvider(provider);\n },\n }) satisfies AssistantModelConfigState;\n });\n","import type { z } from \"zod\";\n\ntype ToolExecuteFunction<TArgs, TResult> = (\n args: TArgs,\n) => TResult | Promise<TResult>;\n\nexport type Tool<TArgs = unknown, TResult = unknown> = {\n description?: string | undefined;\n parameters: z.ZodSchema<TArgs>;\n execute: ToolExecuteFunction<TArgs, TResult>;\n};\n\nexport type ModelConfig = {\n priority?: number | undefined;\n system?: string | undefined;\n tools?: Record<string, Tool<any, any>> | undefined;\n};\n\nexport type ModelConfigProvider = () => ModelConfig;\n\nexport const mergeModelConfigs = (\n configSet: Set<ModelConfigProvider>,\n): ModelConfig => {\n const configs = Array.from(configSet)\n .map((c) => c())\n .sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));\n\n return configs.reduce((acc, config) => {\n if (config.system) {\n if (acc.system) {\n // TODO should the separator be configurable?\n acc.system += `\\n\\n${config.system}`;\n } else {\n acc.system = config.system;\n }\n }\n if (config.tools) {\n for (const [name, tool] of Object.entries(config.tools)) {\n if (acc.tools?.[name]) {\n throw new Error(\n `You tried to define a tool with the name ${name}, but it already exists.`,\n );\n }\n if (!acc.tools) acc.tools = {};\n acc.tools[name] = tool;\n }\n }\n return acc;\n }, {} as ModelConfig);\n};\n","\"use client\";\nimport {\n type ModelConfigProvider,\n mergeModelConfigs,\n} from \"../types/ModelConfigTypes\";\n\nexport class ProxyConfigProvider {\n private _providers = new Set<ModelConfigProvider>();\n\n getModelConfig() {\n return mergeModelConfigs(this._providers);\n }\n\n registerModelConfigProvider(provider: ModelConfigProvider) {\n this._providers.add(provider);\n return () => {\n this._providers.delete(provider);\n };\n }\n}\n","\"use client\";\n\nimport { create } from \"zustand\";\nimport type { ToolCallContentPartComponent } from \"../../types/ContentPartComponentTypes\";\n\nexport type AssistantToolUIsState = Readonly<{\n getToolUI: (toolName: string) => ToolCallContentPartComponent | null;\n setToolUI: (\n toolName: string,\n render: ToolCallContentPartComponent,\n ) => () => void;\n}>;\n\nexport const makeAssistantToolUIsStore = () =>\n create<AssistantToolUIsState>((set) => {\n const renderers = new Map<string, ToolCallContentPartComponent[]>();\n\n return Object.freeze({\n getToolUI: (name) => {\n const arr = renderers.get(name);\n const last = arr?.at(-1);\n if (last) return last;\n return null;\n },\n setToolUI: (name, render) => {\n let arr = renderers.get(name);\n if (!arr) {\n arr = [];\n renderers.set(name, arr);\n }\n arr.push(render);\n set({}); // notify the store listeners\n\n return () => {\n const index = arr.indexOf(render);\n if (index !== -1) {\n arr.splice(index, 1);\n }\n if (index === arr.length) {\n set({}); // notify the store listeners\n }\n };\n },\n }) satisfies AssistantToolUIsState;\n });\n","import type { FC, PropsWithChildren } from \"react\";\nimport {\n useCallback,\n useEffect,\n useInsertionEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport type { ReactThreadRuntime } from \"../../runtime/core/ReactThreadRuntime\";\nimport type { ThreadRuntime } from \"../../runtime/core/ThreadRuntime\";\nimport type { ThreadContextValue } from \"../react/ThreadContext\";\nimport { ThreadContext } from \"../react/ThreadContext\";\nimport { makeComposerStore } from \"../stores/Composer\";\nimport { ThreadState, makeThreadStore } from \"../stores/Thread\";\nimport { makeThreadViewportStore } from \"../stores/ThreadViewport\";\nimport { makeThreadActionStore } from \"../stores/ThreadActions\";\nimport { StoreApi } from \"zustand\";\nimport {\n ThreadMessagesState,\n makeThreadMessagesStore,\n} from \"../stores/ThreadMessages\";\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] = useState<ThreadContextValue>(() => {\n const useThread = makeThreadStore(runtimeRef);\n const useThreadMessages = makeThreadMessagesStore(runtimeRef);\n const useThreadActions = makeThreadActionStore(runtimeRef);\n const useViewport = makeThreadViewportStore();\n const useComposer = makeComposerStore(useThreadMessages, useThreadActions);\n\n return {\n useThread,\n useThreadMessages,\n useThreadActions,\n useComposer,\n useViewport,\n };\n });\n\n // subscribe to runtime updates\n useEffect(() => {\n const onRuntimeUpdate = () => {\n (context.useThread as unknown as StoreApi<ThreadState>).setState(\n Object.freeze({\n isRunning: runtimeRef.current.isRunning,\n }) satisfies ThreadState,\n true,\n );\n (\n context.useThreadMessages as unknown as StoreApi<ThreadMessagesState>\n ).setState(Object.freeze(runtimeRef.current.messages), true);\n };\n onRuntimeUpdate();\n return runtime.subscribe(onRuntimeUpdate);\n }, [context, runtime]);\n\n const subscribe = useCallback(\n (c: () => void) => runtime.subscribe(c),\n [runtime],\n );\n\n const RuntimeSynchronizer = useSyncExternalStore(\n subscribe,\n () => (runtime as ReactThreadRuntime).unstable_synchronizer,\n () => undefined,\n );\n\n return (\n <ThreadContext.Provider value={context}>\n {RuntimeSynchronizer && <RuntimeSynchronizer />}\n {children}\n </ThreadContext.Provider>\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { ComposerState } from \"../stores/Composer\";\nimport type { ThreadState } from \"../stores/Thread\";\nimport type { ThreadViewportState } from \"../stores/ThreadViewport\";\nimport { ThreadActionsState } from \"../stores/ThreadActions\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { ThreadMessagesState } from \"../stores/ThreadMessages\";\n\nexport type ThreadContextValue = {\n useThread: ReadonlyStore<ThreadState>;\n useThreadMessages: ReadonlyStore<ThreadMessagesState>;\n useThreadActions: ReadonlyStore<ThreadActionsState>;\n useComposer: ReadonlyStore<ComposerState>;\n useViewport: ReadonlyStore<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(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { create } from \"zustand\";\nimport { type BaseComposerState, makeBaseComposer } from \"./BaseComposer\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { Unsubscribe } from \"../../types/Unsubscribe\";\nimport { ThreadContextValue } from \"../react\";\n\nexport type ComposerState = BaseComposerState &\n Readonly<{\n canCancel: boolean;\n isEditing: true;\n\n send: () => void;\n cancel: () => void;\n focus: () => void;\n onFocus: (listener: () => void) => Unsubscribe;\n }>;\n\nexport const makeComposerStore = (\n useThreadMessages: ThreadContextValue[\"useThreadMessages\"],\n useThreadActions: ThreadContextValue[\"useThreadActions\"],\n): ReadonlyStore<ComposerState> => {\n const focusListeners = new Set<() => void>();\n return create<ComposerState>()((set, get, store) => {\n return {\n ...makeBaseComposer(set, get, store),\n\n get canCancel() {\n return useThreadActions.getState().capabilities.cancel;\n },\n isEditing: true,\n\n send: () => {\n const { setValue, value } = get();\n setValue(\"\");\n\n useThreadActions.getState().append({\n parentId: useThreadMessages.getState().at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: value }],\n });\n },\n cancel: () => {\n useThreadActions.getState().cancelRun();\n },\n focus: () => {\n for (const listener of focusListeners) {\n listener();\n }\n },\n onFocus: (listener) => {\n focusListeners.add(listener);\n return () => {\n focusListeners.delete(listener);\n };\n },\n };\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 type { MutableRefObject } from \"react\";\nimport { create } from \"zustand\";\nimport { ThreadRuntime } from \"../../runtime\";\n\nexport type ThreadState = Readonly<{\n isRunning: boolean;\n}>;\n\nexport const makeThreadStore = (\n runtimeRef: MutableRefObject<ThreadRuntime>,\n) => {\n return create<ThreadState>(() => ({\n isRunning: runtimeRef.current.isRunning,\n }));\n};\n","\"use client\";\nimport { create } from \"zustand\";\nimport type { Unsubscribe } from \"../../types/Unsubscribe\";\n\nexport type ThreadViewportState = Readonly<{\n isAtBottom: boolean;\n scrollToBottom: () => void;\n onScrollToBottom: (callback: () => void) => Unsubscribe;\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","import type { MutableRefObject } from \"react\";\nimport { create } from \"zustand\";\nimport type { AppendMessage } from \"../../types/AssistantTypes\";\nimport { ThreadRuntime } from \"../../runtime\";\n\nexport type ThreadActionsState = Readonly<{\n capabilities: Readonly<{\n edit: boolean;\n reload: boolean;\n cancel: boolean;\n copy: 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 addToolResult: (toolCallId: string, result: any) => void;\n}>;\n\nexport const makeThreadActionStore = (\n runtimeRef: MutableRefObject<ThreadRuntime>,\n) => {\n return create<ThreadActionsState>(() =>\n Object.freeze({\n get capabilities() {\n return runtimeRef.current.capabilities;\n },\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 addToolResult: (toolCallId, result) =>\n runtimeRef.current.addToolResult(toolCallId, result),\n }),\n );\n};\n","import type { MutableRefObject } from \"react\";\nimport { create } from \"zustand\";\nimport type { ThreadMessage } from \"../../types/AssistantTypes\";\nimport { ThreadRuntime } from \"../../runtime\";\n\nexport type ThreadMessagesState = readonly ThreadMessage[];\n\nexport const makeThreadMessagesStore = (\n runtimeRef: MutableRefObject<ThreadRuntime>,\n) => {\n return create<ThreadMessagesState>(() => runtimeRef.current.messages);\n};\n","import { create } from \"zustand\";\nimport { AssistantRuntime } from \"../../runtime\";\nimport { MutableRefObject } from \"react\";\n\nexport type AssistantActionsState = Readonly<{\n switchToThread: (threadId: string | null) => void;\n}>;\n\nexport const makeAssistantActionsStore = (\n runtimeRef: MutableRefObject<AssistantRuntime>,\n) =>\n create<AssistantActionsState>(() =>\n Object.freeze({\n switchToThread: () => runtimeRef.current.switchToThread(null),\n }),\n );\n","import { useContext, useMemo } from \"react\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"../stores/Composer\";\nimport type { EditComposerState } from \"../stores/EditComposer\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\n\nexport type ComposerContextValue = {\n useComposer: ReadonlyStore<EditComposerState | ComposerState>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as ReadonlyStore<\n EditComposerState | ComposerState\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { MessageState } from \"../stores/Message\";\nimport type { EditComposerState } from \"../stores/EditComposer\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { MessageUtilsState } from \"../stores/MessageUtils\";\n\nexport type MessageContextValue = {\n useMessage: ReadonlyStore<MessageState>;\n useMessageUtils: ReadonlyStore<MessageUtilsState>;\n useEditComposer: ReadonlyStore<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","import { createContext, useContext } from \"react\";\nimport type { ContentPartState } from \"../stores/ContentPart\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\n\nexport type ContentPartContextValue = {\n useContentPart: ReadonlyStore<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 { useCallback } from \"react\";\nimport { ThreadContextValue, useThreadContext } from \"../context\";\nimport { AppendMessage } from \"../types\";\n\ntype CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n };\n\nconst toAppendMessage = (\n useThreadMessages: ThreadContextValue[\"useThreadMessages\"],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: useThreadMessages.getState().at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n };\n }\n\n return {\n parentId:\n message.parentId ?? useThreadMessages.getState().at(-1)?.id ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n };\n};\n\nexport const useAppendMessage = () => {\n const { useThreadMessages, useThreadActions, useViewport, useComposer } =\n useThreadContext();\n\n const append = useCallback(\n (message: CreateAppendMessage) => {\n const appendMessage = toAppendMessage(useThreadMessages, message);\n useThreadActions.getState().append(appendMessage);\n\n useViewport.getState().scrollToBottom();\n useComposer.getState().focus();\n },\n [useThreadMessages, useThreadActions, useViewport, useComposer],\n );\n\n return append;\n};\n","import { useCallback } from \"react\";\nimport { useAssistantContext, useThreadContext } from \"../context\";\n\nexport const useSwitchToNewThread = () => {\n const { useAssistantActions } = useAssistantContext();\n const { useComposer } = useThreadContext();\n\n const switchToNewThread = useCallback(() => {\n useAssistantActions.getState().switchToThread(null);\n useComposer.getState().focus();\n }, [useAssistantActions, useComposer]);\n\n return switchToNewThread;\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/ContentPartComponentTypes\";\nimport type { Tool } from \"../types/ModelConfigTypes\";\n\nexport type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {\n toolName: string;\n render?: ToolCallContentPartComponent<TArgs, TResult> | undefined;\n};\n\nexport const useAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const { useModelConfig, useToolUIs } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n const { toolName, render, ...rest } = tool;\n const config = {\n tools: {\n [tool.toolName]: rest,\n },\n };\n const unsub1 = registerModelConfigProvider(() => config);\n const unsub2 = render ? setToolUI(toolName, render) : undefined;\n return () => {\n unsub1();\n unsub2?.();\n };\n }, [registerModelConfigProvider, setToolUI, tool]);\n};\n","\"use client\";\nimport { type AssistantToolProps, useAssistantTool } from \"./useAssistantTool\";\n\nexport const makeAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const Tool = () => {\n useAssistantTool(tool);\n return null;\n };\n return Tool;\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const { useToolUIs } = useAssistantContext();\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n if (!tool) return;\n const { toolName, render } = tool;\n return setToolUI(toolName, render);\n }, [setToolUI, tool]);\n};\n","\"use client\";\nimport {\n type AssistantToolUIProps,\n useAssistantToolUI,\n} from \"./useAssistantToolUI\";\n\nexport const makeAssistantToolUI = <TArgs, TResult>(\n tool: AssistantToolUIProps<TArgs, TResult>,\n) => {\n const ToolUI = () => {\n useAssistantToolUI(tool);\n return null;\n };\n return ToolUI;\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/react/AssistantContext\";\n\nexport const useAssistantInstructions = (instruction: string) => {\n const { useModelConfig } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n useEffect(() => {\n const config = {\n system: instruction,\n };\n return registerModelConfigProvider(() => config);\n }, [registerModelConfigProvider, instruction]);\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\nimport { getMessageText } from \"../../utils/getMessageText\";\n\nexport type UseActionBarCopyProps = {\n copiedDuration?: number | undefined;\n};\n\nexport const useActionBarCopy = ({\n copiedDuration = 3000,\n}: UseActionBarCopyProps = {}) => {\n const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();\n\n const hasCopyableContent = useCombinedStore(\n [useMessage, useEditComposer],\n (m, c) => {\n return (\n !c.isEditing &&\n m.message.content.some((c) => c.type === \"text\" && c.text.length > 0)\n );\n },\n );\n\n const callback = useCallback(() => {\n const { message } = useMessage.getState();\n const { setIsCopied } = useMessageUtils.getState();\n const { isEditing, value: composerValue } = useEditComposer.getState();\n\n const valueToCopy = isEditing ? composerValue : getMessageText(message);\n\n navigator.clipboard.writeText(valueToCopy);\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n }, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);\n\n if (!hasCopyableContent) return null;\n return callback;\n};\n","import { useMemo } from \"react\";\nimport {\n type CombinedSelector,\n createCombinedStore,\n} from \"./createCombinedStore\";\nimport { ReadonlyStore } from \"../../context/ReadonlyStore\";\n\nexport const useCombinedStore = <T extends Array<unknown>, R>(\n stores: { [K in keyof T]: ReadonlyStore<T[K]> },\n selector: CombinedSelector<T, R>,\n): R => {\n // eslint-disable-next-line react-hooks/exhaustive-deps -- 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 { Unsubscribe } from \"../../types/Unsubscribe\";\nimport { ReadonlyStore } from \"../../context/ReadonlyStore\";\n\nexport type CombinedSelector<T extends Array<unknown>, R> = (...args: T) => R;\n\nexport const createCombinedStore = <T extends Array<unknown>, R>(stores: {\n [K in keyof T]: ReadonlyStore<T[K]>;\n}) => {\n const subscribe = (callback: () => void): Unsubscribe => {\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","import type { TextContentPart, ThreadMessage } from \"../types/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/react/MessageContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport const useActionBarEdit = () => {\n const { useMessage, useEditComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useEditComposer],\n (m, c) => m.message.role !== \"user\" || c.isEditing,\n );\n\n const callback = useCallback(() => {\n const { edit } = useEditComposer.getState();\n edit();\n }, [useEditComposer]);\n\n if (disabled) return null;\n return callback;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport const useActionBarReload = () => {\n const { useThread, useThreadActions, useComposer, useViewport } =\n 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 useThreadActions.getState().startRun(parentId);\n useViewport.getState().scrollToBottom();\n useComposer.getState().focus();\n }, [useThreadActions, useComposer, useViewport, useMessage]);\n\n if (disabled) return null;\n return callback;\n};\n","\"use client\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\n\nexport const useBranchPickerCount = () => {\n const { useMessage } = useMessageContext();\n const branchCount = useMessage((s) => s.branches.length);\n return branchCount;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport const useBranchPickerNext = () => {\n const { useThreadActions } = useThreadContext();\n const { useMessage, useEditComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useEditComposer],\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 useThreadActions\n .getState()\n .switchToBranch(branches[branches.indexOf(message.id) + 1]!);\n }, [useThreadActions, useMessage]);\n\n if (disabled) return null;\n return callback;\n};\n","\"use client\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\n\nexport const useBranchPickerNumber = () => {\n const { useMessage } = useMessageContext();\n const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));\n return branchIdx + 1;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport const useBranchPickerPrevious = () => {\n const { useThreadActions } = useThreadContext();\n const { useMessage, useEditComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useEditComposer],\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 useThreadActions\n .getState()\n .switchToBranch(branches[branches.indexOf(message.id) - 1]!);\n }, [useThreadActions, useMessage]);\n\n if (disabled) return null;\n return callback;\n};\n","import { useCallback } from \"react\";\nimport { useComposerContext } from \"../../context\";\n\nexport const useComposerCancel = () => {\n const { useComposer } = useComposerContext();\n\n const disabled = useComposer((c) => !c.canCancel);\n\n const callback = useCallback(() => {\n const { cancel } = useComposer.getState();\n cancel();\n }, [useComposer]);\n\n if (disabled) return null;\n return callback;\n};\n","\"use client\";\nimport { useComposerContext } from \"../../context/react/ComposerContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype ComposerIfFilters = {\n editing: boolean | undefined;\n};\n\nexport type UseComposerIfProps = RequireAtLeastOne<ComposerIfFilters>;\n\nexport const useComposerIf = (props: UseComposerIfProps) => {\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","import { useCallback } from \"react\";\nimport { useComposerContext, useThreadContext } from \"../../context\";\n\nexport const useComposerSend = () => {\n const { useViewport, useComposer: useNewComposer } = useThreadContext();\n const { useComposer } = useComposerContext();\n\n const disabled = useComposer((c) => !c.isEditing || c.value.length === 0);\n\n const callback = useCallback(() => {\n const composerState = useComposer.getState();\n if (!composerState.isEditing) return;\n\n composerState.send();\n\n useViewport.getState().scrollToBottom();\n useNewComposer.getState().focus();\n }, [useNewComposer, useComposer, useViewport]);\n\n if (disabled) return null;\n return callback;\n};\n","import { useContentPartContext } from \"../../context/react/ContentPartContext\";\n\nexport const useContentPartDisplay = () => {\n const { useContentPart } = useContentPartContext();\n\n const display = useContentPart((c) => {\n if (c.part.type !== \"ui\")\n throw new Error(\n \"This component can only be used inside ui content parts.\",\n );\n\n return c.part.display;\n });\n\n return display;\n};\n","import { useContentPartContext } from \"../../context/react/ContentPartContext\";\n\nexport const useContentPartImage = () => {\n const { useContentPart } = useContentPartContext();\n\n const image = useContentPart((c) => {\n if (c.part.type !== \"image\")\n throw new Error(\n \"ContentPartImage can only be used inside image content parts.\",\n );\n\n return c.part.image;\n });\n\n return image;\n};\n","import { useContentPartContext } from \"../../context/react/ContentPartContext\";\nimport { TextContentPartState } from \"../../context/stores/ContentPart\";\n\nexport const useContentPartText = () => {\n const { useContentPart } = useContentPartContext();\n\n const text = useContentPart((c) => {\n if (c.part.type !== \"text\")\n throw new Error(\n \"ContentPartText can only be used inside text content parts.\",\n );\n\n return c as TextContentPartState;\n });\n\n return text;\n};\n","\"use client\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\ntype MessageIfFilters = {\n user: boolean | undefined;\n assistant: boolean | undefined;\n hasBranches: boolean | undefined;\n copied: boolean | undefined;\n lastOrHover: boolean | undefined;\n};\nexport type UseMessageIfProps = RequireAtLeastOne<MessageIfFilters>;\n\nexport const useMessageIf = (props: UseMessageIfProps) => {\n const { useMessage, useMessageUtils } = useMessageContext();\n\n return useCombinedStore(\n [useMessage, useMessageUtils],\n ({ 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};\n","\"use client\";\n\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\ntype ThreadIfFilters = {\n empty: boolean | undefined;\n running: boolean | undefined;\n};\n\nexport type UseThreadIfProps = RequireAtLeastOne<ThreadIfFilters>;\n\nexport const useThreadIf = (props: UseThreadIfProps) => {\n const { useThread, useThreadMessages } = useThreadContext();\n return useCombinedStore(\n [useThread, useThreadMessages],\n (thread, messages) => {\n if (props.empty === true && messages.length !== 0) return false;\n if (props.empty === false && 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};\n","import { useThreadIf } from \"./useThreadIf\";\n\nexport const useThreadEmpty = () => {\n return useThreadIf({ empty: true });\n};\n","import { useCallback } from \"react\";\nimport { useThreadContext } from \"../../context\";\n\nexport const useThreadScrollToBottom = () => {\n const { useComposer, useViewport } = useThreadContext();\n\n const isAtBottom = useViewport((s) => s.isAtBottom);\n\n const handleScrollToBottom = useCallback(() => {\n useViewport.getState().scrollToBottom();\n useComposer.getState().focus();\n }, [useViewport, useComposer]);\n\n if (isAtBottom) return null;\n return handleScrollToBottom;\n};\n","import { useCallback } from \"react\";\nimport { useThreadContext } from \"../../context\";\nimport { useAppendMessage } from \"../../hooks\";\n\nexport type UseApplyThreadSuggestionProps = {\n prompt: string;\n method: \"replace\";\n autoSend?: boolean | undefined;\n};\n\nexport const useThreadSuggestion = ({\n prompt,\n autoSend,\n}: UseApplyThreadSuggestionProps) => {\n const { useThread, useComposer } = useThreadContext();\n\n const append = useAppendMessage();\n const disabled = useThread((t) => t.isRunning);\n const callback = useCallback(() => {\n const thread = useThread.getState();\n const composer = useComposer.getState();\n if (autoSend && !thread.isRunning) {\n append(prompt);\n composer.setValue(\"\");\n } else {\n composer.setValue(prompt);\n }\n }, [useThread, useComposer, autoSend, append, prompt]);\n\n if (disabled) return null;\n return callback;\n};\n","export { ActionBarPrimitiveRoot as Root } from \"./ActionBarRoot\";\nexport { ActionBarPrimitiveCopy as Copy } from \"./ActionBarCopy\";\nexport { ActionBarPrimitiveReload as Reload } from \"./ActionBarReload\";\nexport { ActionBarPrimitiveEdit as Edit } from \"./ActionBarEdit\";\n","\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport {\n useActionBarFloatStatus,\n HideAndFloatStatus,\n UseActionBarFloatStatusProps,\n} from \"./useActionBarFloatStatus\";\n\ntype ActionBarPrimitiveRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type ActionBarPrimitiveRootProps = PrimitiveDivProps &\n UseActionBarFloatStatusProps;\n\nexport const ActionBarPrimitiveRoot = forwardRef<\n ActionBarPrimitiveRootElement,\n ActionBarPrimitiveRootProps\n>(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {\n const hideAndfloatStatus = useActionBarFloatStatus({\n hideWhenRunning,\n autohide,\n autohideFloat,\n });\n\n if (hideAndfloatStatus === HideAndFloatStatus.Hidden) return null;\n\n return (\n <Primitive.div\n {...(hideAndfloatStatus === HideAndFloatStatus.Floating\n ? { \"data-floating\": \"true\" }\n : null)}\n {...rest}\n ref={ref}\n />\n );\n});\n\nActionBarPrimitiveRoot.displayName = \"ActionBarPrimitive.Root\";\n","\"use client\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport enum HideAndFloatStatus {\n Hidden = \"hidden\",\n Floating = \"floating\",\n Normal = \"normal\",\n}\n\nexport type UseActionBarFloatStatusProps = {\n hideWhenRunning?: boolean | undefined;\n autohide?: \"always\" | \"not-last\" | \"never\" | undefined;\n autohideFloat?: \"always\" | \"single-branch\" | \"never\" | undefined;\n};\n\nexport const useActionBarFloatStatus = ({\n hideWhenRunning,\n autohide,\n autohideFloat,\n}: UseActionBarFloatStatusProps) => {\n const { useThread } = useThreadContext();\n const { useMessage, useMessageUtils } = useMessageContext();\n\n return useCombinedStore(\n [useThread, useMessage, useMessageUtils],\n (t, m, mu) => {\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 (!mu.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","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\n\ntype ActionButtonCallback<TProps> = (props: TProps) => null | (() => void);\n\ntype PrimitiveButtonElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\nexport type ActionButtonProps<THook> = PrimitiveButtonProps &\n (THook extends (props: infer TProps) => unknown ? TProps : never);\n\nexport const createActionButton = <TProps,>(\n displayName: string,\n useActionButton: ActionButtonCallback<TProps>,\n) => {\n const ActionButton = forwardRef<\n PrimitiveButtonElement,\n PrimitiveButtonProps & TProps\n >((props, forwardedRef) => {\n const callback = useActionButton(props);\n\n return (\n <Primitive.button\n type=\"button\"\n disabled={!callback}\n {...props}\n ref={forwardedRef}\n onClick={composeEventHandlers(props.onClick, () => {\n callback?.();\n })}\n />\n );\n });\n\n ActionButton.displayName = displayName;\n\n return ActionButton;\n};\n","\"use client\";\n\nimport { useActionBarCopy } from \"../../primitive-hooks/actionBar/useActionBarCopy\";\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\n\nexport type ActionBarPrimitiveCopyProps = ActionButtonProps<\n typeof useActionBarCopy\n>;\n\nexport const ActionBarPrimitiveCopy = createActionButton(\n \"ActionBarPrimitive.Copy\",\n useActionBarCopy,\n);\n","\"use client\";\n\nimport { useActionBarReload } from \"../../primitive-hooks/actionBar/useActionBarReload\";\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\n\nexport type ActionBarPrimitiveReloadProps = ActionButtonProps<\n typeof useActionBarReload\n>;\n\nexport const ActionBarPrimitiveReload = createActionButton(\n \"ActionBarPrimitive.Reload\",\n useActionBarReload,\n);\n","\"use client\";\n\nimport { useActionBarEdit } from \"../../primitive-hooks/actionBar/useActionBarEdit\";\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\n\nexport type ActionBarPrimitiveEditProps = ActionButtonProps<\n typeof useActionBarEdit\n>;\n\nexport const ActionBarPrimitiveEdit = createActionButton(\n \"ActionBarPrimitive.Edit\",\n useActionBarEdit,\n);\n","export { AssistantModalPrimitiveRoot as Root } from \"./AssistantModalRoot\";\nexport { AssistantModalPrimitiveTrigger as Trigger } from \"./AssistantModalTrigger\";\nexport { AssistantModalPrimitiveContent as Content } from \"./AssistantModalContent\";\nexport { AssistantModalPrimitiveAnchor as Anchor } from \"./AssistantModalAnchor\";\n","\"use client\";\n\nimport { FC, useState } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useOnComposerFocus } from \"../../utils/hooks/useOnComposerFocus\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\n\nexport type AssistantModalPrimitiveRootProps = PopoverPrimitive.PopoverProps;\n\nconst useAssistantModalOpenState = (defaultOpen = false) => {\n const state = useState(defaultOpen);\n\n const [, setOpen] = state;\n useOnComposerFocus(() => {\n setOpen(true);\n });\n\n return state;\n};\n\nexport const AssistantModalPrimitiveRoot: FC<\n AssistantModalPrimitiveRootProps\n> = ({\n __scopeAssistantModal,\n defaultOpen,\n open,\n onOpenChange,\n ...rest\n}: ScopedProps<AssistantModalPrimitiveRootProps>) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n const [modalOpen, setOpen] = useAssistantModalOpenState(defaultOpen);\n\n return (\n <PopoverPrimitive.Root\n {...scope}\n open={open === undefined ? modalOpen : open}\n onOpenChange={composeEventHandlers(onOpenChange, setOpen)}\n {...rest}\n />\n );\n};\n\nAssistantModalPrimitiveRoot.displayName = \"AssistantModalPrimitive.Root\";\n","import { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useEffect } from \"react\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\n\nexport const useOnComposerFocus = (callback: () => void) => {\n const callbackRef = useCallbackRef(callback);\n\n const { useComposer } = useThreadContext();\n useEffect(() => {\n return useComposer.getState().onFocus(() => {\n callbackRef();\n });\n }, [useComposer, callbackRef]);\n};\n","import * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport type { Scope } from \"@radix-ui/react-context\";\n\nexport type ScopedProps<P> = P & { __scopeAssistantModal?: Scope };\nexport const usePopoverScope = PopoverPrimitive.createPopoverScope();\n","\"use client\";\n\nimport { ComponentPropsWithoutRef, ElementRef, forwardRef } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\n\ntype AssistantModalPrimitiveTriggerElement = ElementRef<\n typeof PopoverPrimitive.Trigger\n>;\nexport type AssistantModalPrimitiveTriggerProps = ComponentPropsWithoutRef<\n typeof PopoverPrimitive.Trigger\n>;\n\nexport const AssistantModalPrimitiveTrigger = forwardRef<\n AssistantModalPrimitiveTriggerElement,\n AssistantModalPrimitiveTriggerProps\n>(\n (\n {\n __scopeAssistantModal,\n ...rest\n }: ScopedProps<AssistantModalPrimitiveTriggerProps>,\n ref,\n ) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n return <PopoverPrimitive.Trigger {...scope} {...rest} ref={ref} />;\n },\n);\n\nAssistantModalPrimitiveTrigger.displayName = \"AssistantModalPrimitive.Trigger\";\n","\"use client\";\n\nimport { ComponentPropsWithoutRef, ElementRef, forwardRef } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\n\ntype AssistantModalPrimitiveContentElement = ElementRef<\n typeof PopoverPrimitive.Content\n>;\nexport type AssistantModalPrimitiveContentProps = ComponentPropsWithoutRef<\n typeof PopoverPrimitive.Content\n> & {\n dissmissOnInteractOutside?: boolean | undefined;\n};\n\nexport const AssistantModalPrimitiveContent = forwardRef<\n AssistantModalPrimitiveContentElement,\n AssistantModalPrimitiveContentProps\n>(\n (\n {\n __scopeAssistantModal,\n side,\n align,\n onInteractOutside,\n dissmissOnInteractOutside = false,\n ...props\n }: ScopedProps<AssistantModalPrimitiveContentProps>,\n forwardedRef,\n ) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n return (\n <PopoverPrimitive.Portal {...scope}>\n <PopoverPrimitive.Content\n {...scope}\n {...props}\n ref={forwardedRef}\n side={side ?? \"top\"}\n align={align ?? \"end\"}\n onInteractOutside={composeEventHandlers(\n onInteractOutside,\n dissmissOnInteractOutside ? undefined : (e) => e.preventDefault(),\n )}\n />\n </PopoverPrimitive.Portal>\n );\n },\n);\n\nAssistantModalPrimitiveContent.displayName = \"AssistantModalPrimitive.Content\";\n","\"use client\";\nimport { ComponentPropsWithoutRef, ElementRef, forwardRef } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\n\ntype AssistantModalPrimitiveAnchorElement = ElementRef<\n typeof PopoverPrimitive.Anchor\n>;\ntype AssistantModalPrimitiveAnchorProps = ComponentPropsWithoutRef<\n typeof PopoverPrimitive.Anchor\n>;\n\nexport const AssistantModalPrimitiveAnchor = forwardRef<\n AssistantModalPrimitiveAnchorElement,\n AssistantModalPrimitiveAnchorProps\n>(\n (\n {\n __scopeAssistantModal,\n ...rest\n }: ScopedProps<AssistantModalPrimitiveAnchorProps>,\n ref,\n ) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n return <PopoverPrimitive.Anchor {...scope} {...rest} ref={ref} />;\n },\n);\nAssistantModalPrimitiveAnchor.displayName = \"AssistantModalPrimitive.Anchor\";\n","export { BranchPickerPrimitiveNext as Next } from \"./BranchPickerNext\";\nexport { BranchPickerPrevious as Previous } from \"./BranchPickerPrevious\";\nexport { BranchPickerPrimitiveCount as Count } from \"./BranchPickerCount\";\nexport { BranchPickerPrimitiveNumber as Number } from \"./BranchPickerNumber\";\nexport { BranchPickerPrimitiveRoot as Root } from \"./BranchPickerRoot\";\n","\"use client\";\n\nimport { useBranchPickerNext } from \"../../primitive-hooks/branchPicker/useBranchPickerNext\";\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\n\nexport type BranchPickerPrimitiveNextProps = ActionButtonProps<\n typeof useBranchPickerNext\n>;\n\nexport const BranchPickerPrimitiveNext = createActionButton(\n \"BranchPickerPrimitive.Next\",\n useBranchPickerNext,\n);\n","\"use client\";\n\nimport { useBranchPickerPrevious } from \"../../primitive-hooks/branchPicker/useBranchPickerPrevious\";\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\n\nexport type BranchPickerPrimitivePreviousProps = ActionButtonProps<\n typeof useBranchPickerPrevious\n>;\n\nexport const BranchPickerPrevious = createActionButton(\n \"BranchPickerPrimitive.Previous\",\n useBranchPickerPrevious,\n);\n","\"use client\";\n\nimport type { FC } from \"react\";\nimport { useBranchPickerCount } from \"../../primitive-hooks/branchPicker/useBranchPickerCount\";\n\nexport type BranchPickerPrimitiveCountProps = {};\n\nexport const BranchPickerPrimitiveCount: FC<\n BranchPickerPrimitiveCountProps\n> = () => {\n const branchCount = useBranchPickerCount();\n return <>{branchCount}</>;\n};\n\nBranchPickerPrimitiveCount.displayName = \"BranchPickerPrimitive.Count\";\n","\"use client\";\n\nimport type { FC } from \"react\";\nimport { useBranchPickerNumber } from \"../../primitive-hooks/branchPicker/useBranchPickerNumber\";\n\nexport type BranchPickerPrimitiveNumberProps = {};\n\nexport const BranchPickerPrimitiveNumber: FC<\n BranchPickerPrimitiveNumberProps\n> = () => {\n const branchNumber = useBranchPickerNumber();\n return <>{branchNumber}</>;\n};\n\nBranchPickerPrimitiveNumber.displayName = \"BranchPickerPrimitive.Number\";\n","\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport { If } from \"../message\";\n\ntype BranchPickerPrimitiveRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type BranchPickerPrimitiveRootProps = PrimitiveDivProps & {\n hideWhenSingleBranch?: boolean | undefined;\n};\n\nexport const BranchPickerPrimitiveRoot = forwardRef<\n BranchPickerPrimitiveRootElement,\n BranchPickerPrimitiveRootProps\n>(({ hideWhenSingleBranch, ...rest }, ref) => {\n return (\n <If hasBranches={hideWhenSingleBranch ? true : undefined}>\n <Primitive.div {...rest} ref={ref} />\n </If>\n );\n});\n\nBranchPickerPrimitiveRoot.displayName = \"BranchPickerPrimitive.Root\";\n","export { MessagePrimitiveRoot as Root } from \"./MessageRoot\";\nexport { MessagePrimitiveIf as If } from \"./MessageIf\";\nexport { MessagePrimitiveContent as Content } from \"./MessageContent\";\nexport { MessagePrimitiveInProgress as InProgress } from \"./MessageInProgress\";\n","\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ElementRef,\n forwardRef,\n ComponentPropsWithoutRef,\n useCallback,\n} from \"react\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\n\ntype MessagePrimitiveRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nconst useIsHoveringRef = () => {\n const { useMessageUtils } = useMessageContext();\n\n const callbackRef = useCallback(\n (el: HTMLElement) => {\n const setIsHovering = useMessageUtils.getState().setIsHovering;\n\n const handleMouseEnter = () => {\n setIsHovering(true);\n };\n const handleMouseLeave = () => {\n setIsHovering(false);\n };\n\n el.addEventListener(\"mouseenter\", handleMouseEnter);\n el.addEventListener(\"mouseleave\", handleMouseLeave);\n\n return () => {\n el.removeEventListener(\"mouseenter\", handleMouseEnter);\n el.removeEventListener(\"mouseleave\", handleMouseLeave);\n setIsHovering(false);\n };\n },\n [useMessageUtils],\n );\n\n return useManagedRef(callbackRef);\n};\n\nexport type MessagePrimitiveRootProps = PrimitiveDivProps;\n\nexport const MessagePrimitiveRoot = forwardRef<\n MessagePrimitiveRootElement,\n MessagePrimitiveRootProps\n>(({ onMouseEnter, onMouseLeave, ...rest }, forwardRef) => {\n const isHoveringRef = useIsHoveringRef();\n const ref = useComposedRefs<HTMLDivElement>(forwardRef, isHoveringRef);\n\n return <Primitive.div {...rest} ref={ref} />;\n});\n\nMessagePrimitiveRoot.displayName = \"MessagePrimitive.Root\";\n","import { useCallback, useRef } from \"react\";\n\nexport const useManagedRef = <TNode>(\n callback: (node: TNode) => (() => void) | void,\n) => {\n const cleanupRef = useRef<(() => void) | void>();\n\n const ref = useCallback(\n (el: TNode | null) => {\n // Call the previous cleanup function\n if (cleanupRef.current) {\n cleanupRef.current();\n }\n\n // Call the new callback and store its cleanup function\n if (el) {\n cleanupRef.current = callback(el);\n }\n },\n [callback],\n );\n\n return ref;\n};\n","\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport {\n UseMessageIfProps,\n useMessageIf,\n} from \"../../primitive-hooks/message/useMessageIf\";\n\nexport type MessagePrimitiveIfProps = PropsWithChildren<UseMessageIfProps>;\n\nexport const MessagePrimitiveIf: FC<MessagePrimitiveIfProps> = ({\n children,\n ...query\n}) => {\n const result = useMessageIf(query);\n return result ? children : null;\n};\n\nMessagePrimitiveIf.displayName = \"MessagePrimitive.If\";\n","\"use client\";\n\nimport { type ComponentType, type FC, memo } from \"react\";\nimport {\n useAssistantContext,\n useContentPartContext,\n useThreadContext,\n} from \"../../context\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { ContentPartProvider } from \"../../context/providers/ContentPartProvider\";\nimport { ContentPartPrimitiveText } from \"../contentPart/ContentPartText\";\nimport { ContentPartPrimitiveImage } from \"../contentPart/ContentPartImage\";\nimport { ContentPartPrimitiveDisplay } from \"../contentPart/ContentPartDisplay\";\nimport type {\n ImageContentPartComponent,\n TextContentPartComponent,\n ToolCallContentPartComponent,\n ToolCallContentPartProps,\n UIContentPartComponent,\n} from \"../../types/ContentPartComponentTypes\";\nimport { ContentPartPrimitiveInProgress } from \"../contentPart/ContentPartInProgress\";\n\nexport type MessagePrimitiveContentProps = {\n components?:\n | {\n Text?: TextContentPartComponent | undefined;\n Image?: ImageContentPartComponent | undefined;\n UI?: UIContentPartComponent | undefined;\n tools?: {\n by_name?:\n | Record<string, ToolCallContentPartComponent | undefined>\n | undefined;\n Fallback?: ComponentType<ToolCallContentPartProps> | undefined;\n };\n }\n | undefined;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <ContentPartPrimitiveText />\n <ContentPartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </ContentPartPrimitiveInProgress>\n </p>\n ),\n Image: () => <ContentPartPrimitiveImage />,\n UI: () => <ContentPartPrimitiveDisplay />,\n tools: {\n Fallback: (props) => {\n const { useToolUIs } = useAssistantContext();\n const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));\n if (!Render) return null;\n return <Render {...props} />;\n },\n },\n} satisfies MessagePrimitiveContentProps[\"components\"];\n\ntype MessageContentPartComponentProps = {\n components: MessagePrimitiveContentProps[\"components\"];\n};\n\nconst MessageContentPartComponent: FC<MessageContentPartComponentProps> = ({\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 { useThreadActions } = useThreadContext();\n const addToolResult = useThreadActions((t) => t.addToolResult);\n\n const { useContentPart } = useContentPartContext();\n const { part, status } = useContentPart();\n\n const type = part.type;\n switch (type) {\n case \"text\":\n return <Text part={part} status={status} />;\n\n case \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text -- not a real image\n return <Image part={part} status={status} />;\n\n case \"ui\":\n return <UI part={part} status={status} />;\n\n case \"tool-call\": {\n const Tool = by_name[part.toolName] || Fallback;\n const addResult = (result: any) => addToolResult(part.toolCallId, result);\n return <Tool part={part} status={status} addResult={addResult} />;\n }\n default:\n throw new Error(`Unknown content part type: ${type}`);\n }\n};\n\ntype MessageContentPartProps = {\n partIndex: number;\n components: MessagePrimitiveContentProps[\"components\"];\n};\n\nconst MessageContentPartImpl: FC<MessageContentPartProps> = ({\n partIndex,\n components,\n}) => {\n return (\n <ContentPartProvider partIndex={partIndex}>\n <MessageContentPartComponent components={components} />\n </ContentPartProvider>\n );\n};\n\nconst MessageContentPart = memo(\n MessageContentPartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.UI === next.components?.UI &&\n prev.components?.tools === next.components?.tools,\n);\n\nexport const MessagePrimitiveContent: FC<MessagePrimitiveContentProps> = ({\n components,\n}) => {\n const { useMessage } = useMessageContext();\n\n const contentLength = useMessage((s) => s.message.content.length);\n\n return new Array(contentLength).fill(null).map((_, idx) => {\n const partIndex = idx; // use the index as key, as message is generally append only\n return (\n <MessageContentPart\n key={partIndex}\n partIndex={partIndex}\n components={components}\n />\n );\n });\n};\n\nMessagePrimitiveContent.displayName = \"MessagePrimitive.Content\";\n","\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { StoreApi, create } from \"zustand\";\nimport { ContentPartContext } from \"../react/ContentPartContext\";\nimport type { ContentPartContextValue } from \"../react/ContentPartContext\";\nimport { useMessageContext } from \"../react/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 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 // if the content part is the same, don't update\n const currentState = useContentPart.getState();\n if (currentState.part === part && currentState.status === status) return;\n\n // sync useContentPart\n (useContentPart as unknown as StoreApi<ContentPartState>).setState(\n Object.freeze({\n part,\n status,\n }),\n );\n};\n\nconst useContentPartContext = (partIndex: number) => {\n const { useMessage } = useMessageContext();\n const [context] = useState<ContentPartContextValue>(() => {\n const useContentPart = create<ContentPartState>(\n () => ({}) as ContentPartState,\n );\n\n syncContentPart(useMessage.getState(), useContentPart, partIndex);\n\n return { useContentPart };\n });\n\n useEffect(() => {\n syncContentPart(useMessage.getState(), context.useContentPart, partIndex);\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 { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport { useContentPartText } from \"../../primitive-hooks/contentPart/useContentPartText\";\n\ntype ContentPartPrimitiveTextElement = ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.span>;\n\nexport type ContentPartPrimitiveTextProps = Omit<\n PrimitiveSpanProps,\n \"children\"\n>;\n\nexport const ContentPartPrimitiveText = forwardRef<\n ContentPartPrimitiveTextElement,\n ContentPartPrimitiveTextProps\n>((props, forwardedRef) => {\n const {\n part: { text },\n status,\n } = useContentPartText();\n\n return (\n <Primitive.span data-status={status} {...props} ref={forwardedRef}>\n {text}\n </Primitive.span>\n );\n});\n\nContentPartPrimitiveText.displayName = \"ContentPartPrimitive.Text\";\n","import { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport { useContentPartImage } from \"../../primitive-hooks/contentPart/useContentPartImage\";\n\ntype ContentPartPrimitiveImageElement = ElementRef<typeof Primitive.img>;\ntype PrimitiveImageProps = ComponentPropsWithoutRef<typeof Primitive.img>;\n\nexport type ContentPartPrimitiveImageProps = PrimitiveImageProps;\n\nexport const ContentPartPrimitiveImage = forwardRef<\n ContentPartPrimitiveImageElement,\n ContentPartPrimitiveImageProps\n>((props, forwardedRef) => {\n const image = useContentPartImage();\n return <Primitive.img src={image} {...props} ref={forwardedRef} />;\n});\n\nContentPartPrimitiveImage.displayName = \"ContentPartPrimitive.Image\";\n","import type { FC } from \"react\";\nimport { useContentPartDisplay } from \"../../primitive-hooks/contentPart/useContentPartDisplay\";\n\nexport type ContentPartPrimitiveDisplayProps = {};\n\nexport const ContentPartPrimitiveDisplay: FC<\n ContentPartPrimitiveDisplayProps\n> = () => {\n const display = useContentPartDisplay();\n return display ?? null;\n};\n\nContentPartPrimitiveDisplay.displayName = \"ContentPartPrimitive.Display\";\n","import { FC, PropsWithChildren } from \"react\";\nimport { useContentPartContext } from \"../../context\";\n\nexport type ContentPartPrimitiveInProgressProps = PropsWithChildren;\n\nexport const ContentPartPrimitiveInProgress: FC<ContentPartPrimitiveInProgressProps> = ({\n children,\n}) => {\n const { useContentPart } = useContentPartContext();\n const isInProgress = useContentPart((c) => c.status === \"in_progress\");\n\n return isInProgress ? children : null;\n};\n\nContentPartPrimitiveInProgress.displayName = \"ContentPartPrimitive.InProgress\";\n","\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { ComponentPropsWithoutRef, FC } from \"react\";\n\ntype PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.span>;\n\nexport type MessagePrimitiveInProgressProps = PrimitiveSpanProps;\n\n/**\n * @deprecated Define a custom Text renderer via ContentPartPrimitiveInProgress instead.\n */\nexport const MessagePrimitiveInProgress: FC<\n MessagePrimitiveInProgressProps\n> = () => {\n return null;\n};\n\nMessagePrimitiveInProgress.displayName = \"MessagePrimitive.InProgress\";\n","export { ComposerPrimitiveRoot as Root } from \"./ComposerRoot\";\nexport { ComposerPrimitiveInput as Input } from \"./ComposerInput\";\nexport { ComposerPrimitiveSend as Send } from \"./ComposerSend\";\nexport { ComposerPrimitiveCancel as Cancel } from \"./ComposerCancel\";\nexport { ComposerPrimitiveIf as If } from \"./ComposerIf\";\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ElementRef,\n type FormEvent,\n forwardRef,\n ComponentPropsWithoutRef,\n} from \"react\";\nimport { useComposerSend } from \"../../primitive-hooks\";\n\ntype ComposerPrimitiveRootElement = ElementRef<typeof Primitive.form>;\ntype PrimitiveFormProps = ComponentPropsWithoutRef<typeof Primitive.form>;\n\nexport type ComposerPrimitiveRootProps = PrimitiveFormProps;\n\nexport const ComposerPrimitiveRoot = forwardRef<\n ComposerPrimitiveRootElement,\n ComposerPrimitiveRootProps\n>(({ onSubmit, ...rest }, forwardedRef) => {\n const send = useComposerSend();\n\n const handleSubmit = (e: FormEvent) => {\n e.preventDefault();\n\n if (!send) return;\n send();\n };\n\n return (\n <Primitive.form\n {...rest}\n ref={forwardedRef}\n onSubmit={composeEventHandlers(onSubmit, handleSubmit)}\n />\n );\n});\n\nComposerPrimitiveRoot.displayName = \"ComposerPrimitive.Root\";\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/react/ComposerContext\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useEscapeKeydown } from \"@radix-ui/react-use-escape-keydown\";\nimport { useOnComposerFocus } from \"../../utils/hooks/useOnComposerFocus\";\n\nexport type ComposerPrimitiveInputProps = TextareaAutosizeProps & {\n asChild?: boolean | undefined;\n};\n\nexport const ComposerPrimitiveInput = forwardRef<\n HTMLTextAreaElement,\n ComposerPrimitiveInputProps\n>(\n (\n { autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest },\n forwardedRef,\n ) => {\n const { useThread } = 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 textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n\n useEscapeKeydown((e) => {\n const composer = useComposer.getState();\n if (composer.canCancel) {\n composer.cancel();\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (disabled) return;\n\n if (e.key === \"Enter\" && e.shiftKey === false) {\n const isRunning = useThread.getState().isRunning;\n if (!isRunning) {\n e.preventDefault();\n\n textareaRef.current?.closest(\"form\")?.requestSubmit();\n }\n }\n };\n\n const autoFocusEnabled = autoFocus && !disabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus({ preventScroll: true });\n textarea.setSelectionRange(\n textareaRef.current.value.length,\n textareaRef.current.value.length,\n );\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnComposerFocus(() => {\n if (type === \"new\") {\n focus();\n }\n });\n\n return (\n <Component\n name=\"input\"\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\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n","\"use client\";\n\nimport { ComponentPropsWithoutRef, ElementRef, forwardRef } from \"react\";\nimport { useComposerContext } from \"../../context\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\n\ntype ComposerPrimitiveSendElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\nexport type ComposerPrimitiveSendProps = PrimitiveButtonProps;\n\nexport const ComposerPrimitiveSend = forwardRef<\n ComposerPrimitiveSendElement,\n ComposerPrimitiveSendProps\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\nComposerPrimitiveSend.displayName = \"ComposerPrimitive.Send\";\n","\"use client\";\n\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useComposerCancel } from \"../../primitive-hooks/composer/useComposerCancel\";\n\nexport type ComposerPrimitiveCancelProps = ActionButtonProps<\n typeof useComposerCancel\n>;\n\nexport const ComposerPrimitiveCancel = createActionButton(\n \"ComposerPrimitive.Cancel\",\n useComposerCancel,\n);\n","\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport {\n UseComposerIfProps,\n useComposerIf,\n} from \"../../primitive-hooks/composer/useComposerIf\";\n\nexport type ComposerPrimitiveIfProps = PropsWithChildren<UseComposerIfProps>;\n\nexport const ComposerPrimitiveIf: FC<ComposerPrimitiveIfProps> = ({\n children,\n ...query\n}) => {\n const result = useComposerIf(query);\n return result ? children : null;\n};\n\nComposerPrimitiveIf.displayName = \"ComposerPrimitive.If\";\n","export { ContentPartPrimitiveText as Text } from \"./ContentPartText\";\nexport { ContentPartPrimitiveImage as Image } from \"./ContentPartImage\";\nexport { ContentPartPrimitiveDisplay as Display } from \"./ContentPartDisplay\";\nexport { ContentPartPrimitiveInProgress as InProgress } from \"./ContentPartInProgress\";\n","export { ThreadPrimitiveRoot as Root } from \"./ThreadRoot\";\nexport { ThreadPrimitiveEmpty as Empty } from \"./ThreadEmpty\";\nexport { ThreadPrimitiveIf as If } from \"./ThreadIf\";\nexport { ThreadPrimitiveViewport as Viewport } from \"./ThreadViewport\";\nexport { ThreadPrimitiveMessages as Messages } from \"./ThreadMessages\";\nexport { ThreadPrimitiveScrollToBottom as ScrollToBottom } from \"./ThreadScrollToBottom\";\nexport { ThreadPrimitiveSuggestion as Suggestion } from \"./ThreadSuggestion\";\n","\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\n\ntype ThreadPrimitiveRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type ThreadPrimitiveRootProps = PrimitiveDivProps;\n\nexport const ThreadPrimitiveRoot = forwardRef<\n ThreadPrimitiveRootElement,\n ThreadPrimitiveRootProps\n>((props, ref) => {\n return <Primitive.div {...props} ref={ref} />;\n});\n\nThreadPrimitiveRoot.displayName = \"ThreadPrimitive.Root\";\n","\"use client\";\n\nimport type { FC, ReactNode } from \"react\";\nimport { useThreadEmpty } from \"../../primitive-hooks\";\n\nexport type ThreadPrimitiveEmptyProps = {\n children: ReactNode;\n};\n\nexport const ThreadPrimitiveEmpty: FC<ThreadPrimitiveEmptyProps> = ({\n children,\n}) => {\n const empty = useThreadEmpty();\n return empty ? children : null;\n};\n\nThreadPrimitiveEmpty.displayName = \"ThreadPrimitive.Empty\";\n","\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport {\n UseThreadIfProps,\n useThreadIf,\n} from \"../../primitive-hooks/thread/useThreadIf\";\n\nexport type ThreadPrimitiveIfProps = PropsWithChildren<UseThreadIfProps>;\n\nexport const ThreadPrimitiveIf: FC<ThreadPrimitiveIfProps> = ({\n children,\n ...query\n}) => {\n const result = useThreadIf(query);\n return result ? children : null;\n};\n\nThreadPrimitiveIf.displayName = \"ThreadPrimitive.If\";\n","\"use client\";\n\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport {\n UseThreadViewportAutoScrollProps,\n useThreadViewportAutoScroll,\n} from \"../../primitive-hooks/thread/useThreadViewportAutoScroll\";\n\ntype ThreadPrimitiveViewportElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type ThreadPrimitiveViewportProps = PrimitiveDivProps &\n UseThreadViewportAutoScrollProps;\n\nexport const ThreadPrimitiveViewport = forwardRef<\n ThreadPrimitiveViewportElement,\n ThreadPrimitiveViewportProps\n>(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {\n const autoScrollRef = useThreadViewportAutoScroll<HTMLDivElement>({\n autoScroll,\n });\n\n const ref = useComposedRefs(forwardedRef, autoScrollRef);\n\n return (\n <Primitive.div {...rest} ref={ref}>\n {children}\n </Primitive.div>\n );\n});\n\nThreadPrimitiveViewport.displayName = \"ThreadPrimitive.Viewport\";\n","\"use client\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { useRef } from \"react\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useOnResizeContent } from \"../../utils/hooks/useOnResizeContent\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { StoreApi } from \"zustand\";\nimport { ThreadViewportState } from \"../../context\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\n\nexport type UseThreadViewportAutoScrollProps = {\n autoScroll?: boolean | undefined;\n};\n\nexport const useThreadViewportAutoScroll = <TElement extends HTMLElement>({\n autoScroll = true,\n}: UseThreadViewportAutoScrollProps) => {\n const divRef = useRef<TElement>(null);\n\n const { useViewport } = useThreadContext();\n\n const firstRenderRef = useRef(true);\n const lastScrollTop = useRef<number>(0);\n\n // bug: when ScrollToBottom's button changes its disabled state, the scroll stops\n // fix: delay the state change until the scroll is done\n const isScrollingToBottomRef = useRef(false);\n\n const scrollToBottom = () => {\n const div = divRef.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.scrollTo({ top: div.scrollHeight, behavior });\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 {\n isScrollingToBottomRef.current = newIsAtBottom;\n\n if (newIsAtBottom !== isAtBottom) {\n (useViewport as unknown as StoreApi<ThreadViewportState>).setState({\n isAtBottom: newIsAtBottom,\n });\n }\n }\n\n lastScrollTop.current = div.scrollTop;\n };\n\n const resizeRef = useOnResizeContent(() => {\n if (\n !isScrollingToBottomRef.current &&\n !useViewport.getState().isAtBottom &&\n !firstRenderRef.current\n ) {\n handleScroll();\n } else {\n scrollToBottom();\n }\n });\n\n const scrollRef = useManagedRef<HTMLElement>((el) => {\n el.addEventListener(\"scroll\", handleScroll);\n return () => {\n el.removeEventListener(\"scroll\", handleScroll);\n };\n });\n\n const autoScrollRef = useComposedRefs<TElement>(resizeRef, scrollRef, divRef);\n\n useOnScrollToBottom(() => {\n scrollToBottom();\n });\n\n return autoScrollRef;\n};\n","import { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useCallback } from \"react\";\nimport { useManagedRef } from \"./useManagedRef\";\n\nexport const useOnResizeContent = (callback: () => void) => {\n const callbackRef = useCallbackRef(callback);\n\n const refCallback = useCallback(\n (el: HTMLElement) => {\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 },\n [callbackRef],\n );\n\n return useManagedRef(refCallback);\n};\n","import { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useEffect } from \"react\";\nimport { useThreadContext } from \"../../context/react/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 ComponentType, type FC, memo } from \"react\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { MessageProvider } from \"../../context/providers/MessageProvider\";\nimport { ComposerPrimitiveIf } from \"../composer/ComposerIf\";\nimport { MessagePrimitiveIf } from \"../message/MessageIf\";\n\nexport type ThreadPrimitiveMessagesProps = {\n components:\n | {\n Message: ComponentType;\n UserMessage?: ComponentType | undefined;\n EditComposer?: ComponentType | undefined;\n AssistantMessage?: ComponentType | undefined;\n }\n | {\n Message?: ComponentType | undefined;\n UserMessage: ComponentType;\n EditComposer?: ComponentType | undefined;\n AssistantMessage: ComponentType;\n };\n};\n\nconst getComponents = (\n components: ThreadPrimitiveMessagesProps[\"components\"],\n) => {\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\ntype ThreadMessageProps = {\n messageIndex: number;\n components: ThreadPrimitiveMessagesProps[\"components\"];\n};\n\nconst ThreadMessageImpl: FC<ThreadMessageProps> = ({\n messageIndex,\n components,\n}) => {\n const { UserMessage, EditComposer, AssistantMessage } =\n getComponents(components);\n return (\n <MessageProvider messageIndex={messageIndex}>\n <MessagePrimitiveIf user>\n <ComposerPrimitiveIf editing={false}>\n <UserMessage />\n </ComposerPrimitiveIf>\n <ComposerPrimitiveIf editing>\n <EditComposer />\n </ComposerPrimitiveIf>\n </MessagePrimitiveIf>\n <MessagePrimitiveIf assistant>\n <AssistantMessage />\n </MessagePrimitiveIf>\n </MessageProvider>\n );\n};\n\nconst ThreadMessage = memo(\n ThreadMessageImpl,\n (prev, next) =>\n prev.messageIndex === next.messageIndex &&\n prev.components.Message === next.components.Message &&\n prev.components.UserMessage === next.components.UserMessage &&\n prev.components.EditComposer === next.components.EditComposer &&\n prev.components.AssistantMessage === next.components.AssistantMessage,\n);\n\nexport const ThreadPrimitiveMessagesImpl: FC<ThreadPrimitiveMessagesProps> = ({\n components,\n}) => {\n const { useThreadMessages } = useThreadContext();\n\n const messagesLength = useThreadMessages((t) => t.length);\n if (messagesLength === 0) return null;\n\n return new Array(messagesLength).fill(null).map((_, idx) => {\n const messageIndex = idx; // keep the same key when switching branches for better a11y support\n return (\n <ThreadMessage\n key={messageIndex}\n messageIndex={messageIndex}\n components={components}\n />\n );\n });\n};\n\nThreadPrimitiveMessagesImpl.displayName = \"ThreadPrimitive.Messages\";\n\nexport const ThreadPrimitiveMessages = memo(\n ThreadPrimitiveMessagesImpl,\n (prev, next) =>\n prev.components?.Message === next.components?.Message &&\n prev.components?.UserMessage === next.components?.UserMessage &&\n prev.components?.EditComposer === next.components?.EditComposer &&\n prev.components?.AssistantMessage === next.components?.AssistantMessage,\n);\n","\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { StoreApi, create } from \"zustand\";\nimport type {\n AppendContentPart,\n ThreadMessage,\n} from \"../../types/AssistantTypes\";\nimport { getMessageText } from \"../../utils/getMessageText\";\nimport { MessageContext } from \"../react/MessageContext\";\nimport type { MessageContextValue } from \"../react/MessageContext\";\nimport { useThreadContext } from \"../react/ThreadContext\";\nimport type { MessageState } from \"../stores/Message\";\nimport { makeEditComposerStore } from \"../stores/EditComposer\";\nimport { makeMessageUtilsStore } from \"../stores/MessageUtils\";\nimport { ThreadMessagesState } from \"../stores/ThreadMessages\";\n\ntype MessageProviderProps = PropsWithChildren<{\n messageIndex: number;\n}>;\n\nconst getIsLast = (messages: ThreadMessagesState, message: ThreadMessage) => {\n return messages[messages.length - 1]?.id === message.id;\n};\n\nconst syncMessage = (\n messages: ThreadMessagesState,\n getBranches: (messageId: string) => readonly string[],\n useMessage: MessageContextValue[\"useMessage\"],\n messageIndex: number,\n) => {\n const parentId = messages[messageIndex - 1]?.id ?? null;\n const message = messages[messageIndex];\n if (!message) return;\n\n const isLast = getIsLast(messages, message);\n const branches = 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 as unknown as StoreApi<MessageState>).setState({\n message,\n parentId,\n branches,\n isLast,\n });\n};\n\nconst useMessageContext = (messageIndex: number) => {\n const { useThreadMessages, useThreadActions } = useThreadContext();\n\n const [context] = useState<MessageContextValue>(() => {\n const useMessage = create<MessageState>(() => ({}) as MessageState);\n const useMessageUtils = makeMessageUtilsStore();\n const useEditComposer = 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 useThreadActions.getState().append({\n parentId,\n role: \"user\",\n content: [{ type: \"text\", text }, ...nonTextParts],\n });\n },\n });\n\n syncMessage(\n useThreadMessages.getState(),\n useThreadActions.getState().getBranches,\n useMessage,\n messageIndex,\n );\n\n return { useMessage, useMessageUtils, useEditComposer };\n });\n\n useEffect(() => {\n return useThreadMessages.subscribe((thread) => {\n syncMessage(\n thread,\n useThreadActions.getState().getBranches,\n context.useMessage,\n messageIndex,\n );\n });\n }, [useThreadMessages, useThreadActions, context, 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 { create } from \"zustand\";\nimport { type BaseComposerState, makeBaseComposer } from \"./BaseComposer\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\n\nexport type EditComposerState = BaseComposerState &\n Readonly<{\n canCancel: boolean;\n isEditing: boolean;\n\n edit: () => void;\n send: () => void;\n cancel: () => void;\n }>;\n\nexport const makeEditComposerStore = ({\n onEdit,\n onSend,\n}: {\n onEdit: () => string;\n onSend: (value: string) => void;\n}): ReadonlyStore<EditComposerState> =>\n create<EditComposerState>()((set, get, store) => ({\n ...makeBaseComposer(set, get, store),\n\n canCancel: false,\n isEditing: false,\n\n edit: () => {\n const value = onEdit();\n set({ isEditing: true, canCancel: true, value });\n },\n send: () => {\n const value = get().value;\n set({ isEditing: false, canCancel: false });\n onSend(value);\n },\n cancel: () => {\n set({ isEditing: false, canCancel: false });\n },\n }));\n","import { create } from \"zustand\";\n\nexport type MessageUtilsState = Readonly<{\n isCopied: boolean;\n setIsCopied: (value: boolean) => void;\n isHovering: boolean;\n setIsHovering: (value: boolean) => void;\n}>;\n\nexport const makeMessageUtilsStore = () =>\n create<MessageUtilsState>((set) => ({\n isCopied: false,\n setIsCopied: (value) => {\n set({ isCopied: value });\n },\n isHovering: false,\n setIsHovering: (value) => {\n set({ isHovering: value });\n },\n }));\n","\"use client\";\n\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useThreadScrollToBottom } from \"../../primitive-hooks/thread/useThreadScrollToBottom\";\n\nexport type ThreadPrimitiveScrollToBottomProps = ActionButtonProps<\n typeof useThreadScrollToBottom\n>;\n\nexport const ThreadPrimitiveScrollToBottom = createActionButton(\n \"ThreadPrimitive.ScrollToBottom\",\n useThreadScrollToBottom,\n);\n","\"use client\";\n\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useThreadSuggestion } from \"../../primitive-hooks/thread/useThreadSuggestion\";\n\nexport type ThreadPrimitiveSuggestionProps = ActionButtonProps<\n typeof useThreadSuggestion\n>;\n\nexport const ThreadPrimitiveSuggestion = createActionButton(\n \"ThreadPrimitive.Suggestion\",\n useThreadSuggestion,\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 { 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","import type { ThreadMessage } from \"../../types/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 { AppendMessage } from \"../../types/AssistantTypes\";\nimport { type ModelConfigProvider } from \"../../types/ModelConfigTypes\";\nimport type { Unsubscribe } from \"../../types/Unsubscribe\";\nimport type { AssistantRuntime } from \"./AssistantRuntime\";\nimport { ReactThreadRuntime } from \"./ReactThreadRuntime\";\n\nexport abstract class BaseAssistantRuntime<\n TThreadRuntime extends ReactThreadRuntime,\n> implements AssistantRuntime\n{\n public get capabilities() {\n return this._thread.capabilities;\n }\n\n constructor(private _thread: TThreadRuntime) {\n this._thread = _thread;\n this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);\n }\n\n private _unsubscribe: Unsubscribe;\n\n get thread() {\n return this._thread;\n }\n\n set thread(thread: TThreadRuntime) {\n this._unsubscribe();\n this._thread = thread;\n this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);\n this.subscriptionHandler();\n }\n\n public abstract registerModelConfigProvider(\n provider: ModelConfigProvider,\n ): Unsubscribe;\n public abstract switchToThread(threadId: string | null): void;\n\n public get messages() {\n return this.thread.messages;\n }\n\n public get isRunning() {\n return this.thread.isRunning;\n }\n\n public getBranches(messageId: string): readonly string[] {\n return this.thread.getBranches(messageId);\n }\n\n public switchToBranch(branchId: string): void {\n return this.thread.switchToBranch(branchId);\n }\n\n public append(message: AppendMessage): void {\n return this.thread.append(message);\n }\n\n public startRun(parentId: string | null): void {\n return this.thread.startRun(parentId);\n }\n\n public cancelRun(): void {\n return this.thread.cancelRun();\n }\n\n public addToolResult(toolCallId: string, result: any) {\n return this.thread.addToolResult(toolCallId, result);\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private subscriptionHandler = () => {\n for (const callback of this._subscriptions) callback();\n };\n\n public get unstable_synchronizer() {\n return this.thread.unstable_synchronizer;\n }\n}\n","import type {\n AppendMessage,\n AssistantMessage,\n UserMessage,\n} from \"../../types/AssistantTypes\";\nimport {\n type ModelConfigProvider,\n mergeModelConfigs,\n} from \"../../types/ModelConfigTypes\";\nimport type { Unsubscribe } from \"../../types/Unsubscribe\";\nimport { ThreadRuntime } from \"../core\";\nimport { MessageRepository } from \"../utils/MessageRepository\";\nimport { generateId } from \"../utils/idUtils\";\nimport { BaseAssistantRuntime } from \"../core/BaseAssistantRuntime\";\nimport type { ChatModelAdapter, ChatModelRunResult } from \"./ChatModelAdapter\";\n\nexport class LocalRuntime extends BaseAssistantRuntime<LocalThreadRuntime> {\n private readonly _configProviders: Set<ModelConfigProvider>;\n\n constructor(adapter: ChatModelAdapter) {\n const configProviders = new Set<ModelConfigProvider>();\n super(new LocalThreadRuntime(configProviders, adapter));\n this._configProviders = configProviders;\n }\n\n public set adapter(adapter: ChatModelAdapter) {\n this.thread.adapter = adapter;\n }\n\n registerModelConfigProvider(provider: ModelConfigProvider) {\n this._configProviders.add(provider);\n return () => this._configProviders.delete(provider);\n }\n\n public switchToThread(threadId: string | null) {\n if (threadId) {\n throw new Error(\"LocalRuntime does not yet support switching threads\");\n }\n\n return (this.thread = new LocalThreadRuntime(\n this._configProviders,\n this.thread.adapter,\n ));\n }\n}\n\nconst CAPABILITIES = Object.freeze({\n edit: true,\n reload: true,\n cancel: true,\n copy: true,\n});\n\nclass LocalThreadRuntime implements ThreadRuntime {\n private _subscriptions = new Set<() => void>();\n\n private abortController: AbortController | null = null;\n private readonly repository = new MessageRepository();\n\n public readonly capabilities = CAPABILITIES;\n\n public get messages() {\n return this.repository.getMessages();\n }\n public get isRunning() {\n return this.abortController != null;\n }\n\n constructor(\n private _configProviders: Set<ModelConfigProvider>,\n public adapter: ChatModelAdapter,\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.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 config: mergeModelConfigs(this._configProviders),\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 addToolResult() {\n throw new Error(\"LocalRuntime does not yet support adding tool results\");\n }\n}\n","export { ProxyConfigProvider } from \"./utils/ProxyConfigProvider\";\nexport { MessageRepository } from \"./runtime/utils/MessageRepository\";\nexport { BaseAssistantRuntime } from \"./runtime/core/BaseAssistantRuntime\";\n"],"mappings":";;;;;;;AACA,SAAS,YAAY;;;ACArB,SAAS,aAAAA,YAAW,sBAAAC,qBAAoB,UAAAC,SAAQ,YAAAC,iBAAgB;;;ACDhE,SAAS,eAAe,kBAAkB;AAYnC,IAAM,mBAAmB;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB,MAA6B;AAC9D,QAAM,UAAU,WAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACrBA,SAAS,cAAc;;;ACkBhB,IAAM,oBAAoB,CAC/B,cACgB;AAChB,QAAM,UAAU,MAAM,KAAK,SAAS,EACjC,IAAI,CAAC,MAAM,EAAE,CAAC,EACd,KAAK,CAAC,GAAG,OAAO,EAAE,YAAY,MAAM,EAAE,YAAY,EAAE;AAEvD,SAAO,QAAQ,OAAO,CAAC,KAAK,WAAW;AACrC,QAAI,OAAO,QAAQ;AACjB,UAAI,IAAI,QAAQ;AAEd,YAAI,UAAU;AAAA;AAAA,EAAO,OAAO,MAAM;AAAA,MACpC,OAAO;AACL,YAAI,SAAS,OAAO;AAAA,MACtB;AAAA,IACF;AACA,QAAI,OAAO,OAAO;AAChB,iBAAW,CAAC,MAAM,IAAI,KAAK,OAAO,QAAQ,OAAO,KAAK,GAAG;AACvD,YAAI,IAAI,QAAQ,IAAI,GAAG;AACrB,gBAAM,IAAI;AAAA,YACR,4CAA4C,IAAI;AA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AAED,SAAO;AACT;;;AKdA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":["useEffect","useInsertionEffect","useRef","useState","create","createContext","useContext","create","create","create","create","create","create","create","jsx","useRef","useInsertionEffect","useState","useEffect","jsx","useContext","createContext","useContext","useContext","createContext","useContext","useCallback","useCallback","useCallback","useCallback","useEffect","useEffect","useEffect","useEffect","useEffect","useEffect","useCallback","useMemo","useSyncExternalStore","useMemo","c","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","jsx","Primitive","forwardRef","jsx","useState","PopoverPrimitive","composeEventHandlers","useEffect","useEffect","jsx","useState","composeEventHandlers","forwardRef","PopoverPrimitive","jsx","forwardRef","forwardRef","PopoverPrimitive","composeEventHandlers","jsx","forwardRef","forwardRef","PopoverPrimitive","jsx","forwardRef","jsx","Fragment","jsx","Primitive","forwardRef","Primitive","forwardRef","useCallback","useCallback","useRef","jsx","useCallback","forwardRef","Primitive","memo","useEffect","useState","create","jsx","useContentPartContext","useState","create","useEffect","Primitive","forwardRef","jsx","forwardRef","Primitive","Primitive","forwardRef","jsx","forwardRef","Primitive","jsx","jsxs","memo","jsx","forwardRef","Primitive","composeEventHandlers","Primitive","forwardRef","jsx","forwardRef","Primitive","composeEventHandlers","composeEventHandlers","useComposedRefs","forwardRef","useCallback","useEffect","useRef","jsx","forwardRef","useRef","useComposedRefs","useCallback","useEffect","composeEventHandlers","forwardRef","Primitive","jsx","forwardRef","Primitive","forwardRef","jsx","useComposedRefs","Primitive","forwardRef","useComposedRefs","useRef","useCallbackRef","useCallback","useCallbackRef","useCallback","useCallbackRef","useEffect","useCallbackRef","useEffect","useRef","useComposedRefs","jsx","forwardRef","useComposedRefs","Primitive","memo","useEffect","useState","create","create","create","create","jsx","useMessageContext","useState","create","useEffect","jsx","jsxs","memo","useInsertionEffect","useState","useState","useInsertionEffect"]}
1
+ {"version":3,"sources":["../src/context/providers/AssistantRuntimeProvider.tsx","../src/context/providers/AssistantProvider.tsx","../src/context/react/AssistantContext.ts","../src/context/stores/AssistantModelConfig.ts","../src/types/ModelConfigTypes.ts","../src/utils/ProxyConfigProvider.ts","../src/context/stores/AssistantToolUIs.ts","../src/context/providers/ThreadProvider.tsx","../src/context/react/ThreadContext.ts","../src/context/stores/Composer.ts","../src/context/stores/BaseComposer.ts","../src/context/stores/Thread.ts","../src/context/stores/ThreadViewport.tsx","../src/context/stores/ThreadActions.ts","../src/context/stores/ThreadMessages.ts","../src/context/stores/AssistantActions.tsx","../src/context/react/ComposerContext.ts","../src/context/react/MessageContext.ts","../src/context/react/ContentPartContext.ts","../src/hooks/useAppendMessage.tsx","../src/hooks/useSwitchToNewThread.tsx","../src/model-config/useAssistantTool.tsx","../src/model-config/makeAssistantTool.tsx","../src/model-config/useAssistantToolUI.tsx","../src/model-config/makeAssistantToolUI.tsx","../src/model-config/useAssistantInstructions.tsx","../src/primitive-hooks/actionBar/useActionBarCopy.tsx","../src/utils/combined/useCombinedStore.ts","../src/utils/combined/createCombinedStore.ts","../src/utils/getMessageText.tsx","../src/primitive-hooks/actionBar/useActionBarEdit.tsx","../src/primitive-hooks/actionBar/useActionBarReload.tsx","../src/primitive-hooks/branchPicker/useBranchPickerCount.tsx","../src/primitive-hooks/branchPicker/useBranchPickerNext.tsx","../src/primitive-hooks/branchPicker/useBranchPickerNumber.tsx","../src/primitive-hooks/branchPicker/useBranchPickerPrevious.tsx","../src/primitive-hooks/composer/useComposerCancel.tsx","../src/primitive-hooks/composer/useComposerIf.tsx","../src/primitive-hooks/composer/useComposerSend.tsx","../src/primitive-hooks/contentPart/useContentPartDisplay.tsx","../src/primitive-hooks/contentPart/useContentPartImage.tsx","../src/primitive-hooks/contentPart/useContentPartText.tsx","../src/primitive-hooks/message/useMessageIf.tsx","../src/primitive-hooks/thread/useThreadIf.tsx","../src/primitive-hooks/thread/useThreadEmpty.tsx","../src/primitive-hooks/thread/useThreadScrollToBottom.tsx","../src/primitive-hooks/thread/useThreadSuggestion.tsx","../src/primitives/actionBar/index.ts","../src/primitives/actionBar/ActionBarRoot.tsx","../src/primitives/actionBar/useActionBarFloatStatus.tsx","../src/utils/createActionButton.tsx","../src/primitives/actionBar/ActionBarCopy.tsx","../src/primitives/actionBar/ActionBarReload.tsx","../src/primitives/actionBar/ActionBarEdit.tsx","../src/primitives/assistantModal/index.ts","../src/primitives/assistantModal/AssistantModalRoot.tsx","../src/utils/hooks/useOnComposerFocus.tsx","../src/primitives/assistantModal/scope.tsx","../src/primitives/assistantModal/AssistantModalTrigger.tsx","../src/primitives/assistantModal/AssistantModalContent.tsx","../src/primitives/assistantModal/AssistantModalAnchor.tsx","../src/primitives/branchPicker/index.ts","../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/message/index.ts","../src/primitives/message/MessageRoot.tsx","../src/utils/hooks/useManagedRef.ts","../src/primitives/message/MessageIf.tsx","../src/primitives/message/MessageContent.tsx","../src/context/providers/ContentPartProvider.tsx","../src/primitives/contentPart/ContentPartText.tsx","../src/utils/hooks/useSmooth.tsx","../src/primitives/contentPart/ContentPartImage.tsx","../src/primitives/contentPart/ContentPartDisplay.tsx","../src/primitives/contentPart/ContentPartInProgress.tsx","../src/primitives/message/MessageInProgress.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/composer/ComposerIf.tsx","../src/primitives/contentPart/index.ts","../src/primitives/thread/index.ts","../src/primitives/thread/ThreadRoot.tsx","../src/primitives/thread/ThreadEmpty.tsx","../src/primitives/thread/ThreadIf.tsx","../src/primitives/thread/ThreadViewport.tsx","../src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx","../src/utils/hooks/useOnResizeContent.tsx","../src/utils/hooks/useOnScrollToBottom.tsx","../src/primitives/thread/ThreadMessages.tsx","../src/context/providers/MessageProvider.tsx","../src/context/stores/EditComposer.ts","../src/context/stores/MessageUtils.ts","../src/primitives/thread/ThreadScrollToBottom.tsx","../src/primitives/thread/ThreadSuggestion.tsx","../src/runtime/local/useLocalRuntime.tsx","../src/runtime/utils/idUtils.tsx","../src/runtime/utils/MessageRepository.tsx","../src/runtime/core/BaseAssistantRuntime.tsx","../src/runtime/local/LocalRuntime.tsx","../src/internal.ts"],"sourcesContent":["import type { FC, PropsWithChildren } from \"react\";\nimport { memo } from \"react\";\nimport type { AssistantRuntime } from \"../../runtime/core/AssistantRuntime\";\nimport { AssistantProvider } from \"./AssistantProvider\";\n\ntype AssistantRuntimeProviderProps = {\n runtime: AssistantRuntime;\n};\n\nconst AssistantRuntimeProviderImpl: FC<\n PropsWithChildren<AssistantRuntimeProviderProps>\n> = ({ children, runtime }) => {\n return <AssistantProvider runtime={runtime}>{children}</AssistantProvider>;\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n","import type { FC, PropsWithChildren } from \"react\";\nimport { useEffect, useInsertionEffect, useRef, useState } from \"react\";\nimport type { AssistantRuntime } from \"../../runtime\";\nimport { AssistantContext } from \"../react/AssistantContext\";\nimport { makeAssistantModelConfigStore } from \"../stores/AssistantModelConfig\";\nimport { makeAssistantToolUIsStore } from \"../stores/AssistantToolUIs\";\nimport { ThreadProvider } from \"./ThreadProvider\";\nimport { makeAssistantActionsStore } from \"../stores/AssistantActions\";\n\ntype AssistantProviderProps = {\n runtime: AssistantRuntime;\n};\n\nexport const AssistantProvider: FC<\n PropsWithChildren<AssistantProviderProps>\n> = ({ children, runtime }) => {\n const runtimeRef = useRef(runtime);\n useInsertionEffect(() => {\n runtimeRef.current = runtime;\n });\n\n const [context] = useState(() => {\n const useModelConfig = makeAssistantModelConfigStore();\n const useToolUIs = makeAssistantToolUIsStore();\n const useAssistantActions = makeAssistantActionsStore(runtimeRef);\n\n return { useModelConfig, useToolUIs, useAssistantActions };\n });\n\n const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);\n useEffect(() => {\n return runtime.registerModelConfigProvider(getModelCOnfig);\n }, [runtime, getModelCOnfig]);\n\n return (\n <AssistantContext.Provider value={context}>\n <ThreadProvider runtime={runtime}>{children}</ThreadProvider>\n </AssistantContext.Provider>\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { AssistantModelConfigState } from \"../stores/AssistantModelConfig\";\nimport type { AssistantToolUIsState } from \"../stores/AssistantToolUIs\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { AssistantActionsState } from \"../stores/AssistantActions\";\n\nexport type AssistantContextValue = {\n useModelConfig: ReadonlyStore<AssistantModelConfigState>;\n useToolUIs: ReadonlyStore<AssistantToolUIsState>;\n useAssistantActions: ReadonlyStore<AssistantActionsState>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = (): AssistantContextValue => {\n const context = useContext(AssistantContext);\n if (!context)\n throw new Error(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","\"use client\";\n\nimport { create } from \"zustand\";\nimport type { ModelConfigProvider } from \"../../types/ModelConfigTypes\";\nimport { ProxyConfigProvider } from \"../../utils/ProxyConfigProvider\";\n\nexport type AssistantModelConfigState = Readonly<{\n getModelConfig: ModelConfigProvider;\n registerModelConfigProvider: (provider: ModelConfigProvider) => () => void;\n}>;\n\nexport const makeAssistantModelConfigStore = () =>\n create<AssistantModelConfigState>(() => {\n const proxy = new ProxyConfigProvider();\n\n return Object.freeze({\n getModelConfig: () => {\n return proxy.getModelConfig();\n },\n registerModelConfigProvider: (provider: ModelConfigProvider) => {\n return proxy.registerModelConfigProvider(provider);\n },\n }) satisfies AssistantModelConfigState;\n });\n","import type { z } from \"zod\";\n\ntype ToolExecuteFunction<TArgs, TResult> = (\n args: TArgs,\n) => TResult | Promise<TResult>;\n\nexport type Tool<TArgs = unknown, TResult = unknown> = {\n description?: string | undefined;\n parameters: z.ZodSchema<TArgs>;\n execute: ToolExecuteFunction<TArgs, TResult>;\n};\n\nexport type ModelConfig = {\n priority?: number | undefined;\n system?: string | undefined;\n tools?: Record<string, Tool<any, any>> | undefined;\n};\n\nexport type ModelConfigProvider = () => ModelConfig;\n\nexport const mergeModelConfigs = (\n configSet: Set<ModelConfigProvider>,\n): ModelConfig => {\n const configs = Array.from(configSet)\n .map((c) => c())\n .sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));\n\n return configs.reduce((acc, config) => {\n if (config.system) {\n if (acc.system) {\n // TODO should the separator be configurable?\n acc.system += `\\n\\n${config.system}`;\n } else {\n acc.system = config.system;\n }\n }\n if (config.tools) {\n for (const [name, tool] of Object.entries(config.tools)) {\n if (acc.tools?.[name]) {\n throw new Error(\n `You tried to define a tool with the name ${name}, but it already exists.`,\n );\n }\n if (!acc.tools) acc.tools = {};\n acc.tools[name] = tool;\n }\n }\n return acc;\n }, {} as ModelConfig);\n};\n","\"use client\";\nimport {\n type ModelConfigProvider,\n mergeModelConfigs,\n} from \"../types/ModelConfigTypes\";\n\nexport class ProxyConfigProvider {\n private _providers = new Set<ModelConfigProvider>();\n\n getModelConfig() {\n return mergeModelConfigs(this._providers);\n }\n\n registerModelConfigProvider(provider: ModelConfigProvider) {\n this._providers.add(provider);\n return () => {\n this._providers.delete(provider);\n };\n }\n}\n","\"use client\";\n\nimport { create } from \"zustand\";\nimport type { ToolCallContentPartComponent } from \"../../types/ContentPartComponentTypes\";\n\nexport type AssistantToolUIsState = Readonly<{\n getToolUI: (toolName: string) => ToolCallContentPartComponent | null;\n setToolUI: (\n toolName: string,\n render: ToolCallContentPartComponent,\n ) => () => void;\n}>;\n\nexport const makeAssistantToolUIsStore = () =>\n create<AssistantToolUIsState>((set) => {\n const renderers = new Map<string, ToolCallContentPartComponent[]>();\n\n return Object.freeze({\n getToolUI: (name) => {\n const arr = renderers.get(name);\n const last = arr?.at(-1);\n if (last) return last;\n return null;\n },\n setToolUI: (name, render) => {\n let arr = renderers.get(name);\n if (!arr) {\n arr = [];\n renderers.set(name, arr);\n }\n arr.push(render);\n set({}); // notify the store listeners\n\n return () => {\n const index = arr.indexOf(render);\n if (index !== -1) {\n arr.splice(index, 1);\n }\n if (index === arr.length) {\n set({}); // notify the store listeners\n }\n };\n },\n }) satisfies AssistantToolUIsState;\n });\n","import type { FC, PropsWithChildren } from \"react\";\nimport {\n useCallback,\n useEffect,\n useInsertionEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport type { ReactThreadRuntime } from \"../../runtime/core/ReactThreadRuntime\";\nimport type { ThreadRuntime } from \"../../runtime/core/ThreadRuntime\";\nimport type { ThreadContextValue } from \"../react/ThreadContext\";\nimport { ThreadContext } from \"../react/ThreadContext\";\nimport { makeComposerStore } from \"../stores/Composer\";\nimport { ThreadState, makeThreadStore } from \"../stores/Thread\";\nimport { makeThreadViewportStore } from \"../stores/ThreadViewport\";\nimport { makeThreadActionStore } from \"../stores/ThreadActions\";\nimport { StoreApi } from \"zustand\";\nimport {\n ThreadMessagesState,\n makeThreadMessagesStore,\n} from \"../stores/ThreadMessages\";\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] = useState<ThreadContextValue>(() => {\n const useThread = makeThreadStore(runtimeRef);\n const useThreadMessages = makeThreadMessagesStore(runtimeRef);\n const useThreadActions = makeThreadActionStore(runtimeRef);\n const useViewport = makeThreadViewportStore();\n const useComposer = makeComposerStore(useThreadMessages, useThreadActions);\n\n return {\n useThread,\n useThreadMessages,\n useThreadActions,\n useComposer,\n useViewport,\n };\n });\n\n // subscribe to runtime updates\n useEffect(() => {\n const onRuntimeUpdate = () => {\n (context.useThread as unknown as StoreApi<ThreadState>).setState(\n Object.freeze({\n isRunning: runtimeRef.current.isRunning,\n }) satisfies ThreadState,\n true,\n );\n (\n context.useThreadMessages as unknown as StoreApi<ThreadMessagesState>\n ).setState(Object.freeze(runtimeRef.current.messages), true);\n };\n onRuntimeUpdate();\n return runtime.subscribe(onRuntimeUpdate);\n }, [context, runtime]);\n\n const subscribe = useCallback(\n (c: () => void) => runtime.subscribe(c),\n [runtime],\n );\n\n const RuntimeSynchronizer = useSyncExternalStore(\n subscribe,\n () => (runtime as ReactThreadRuntime).unstable_synchronizer,\n () => undefined,\n );\n\n return (\n <ThreadContext.Provider value={context}>\n {RuntimeSynchronizer && <RuntimeSynchronizer />}\n {children}\n </ThreadContext.Provider>\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { ComposerState } from \"../stores/Composer\";\nimport type { ThreadState } from \"../stores/Thread\";\nimport type { ThreadViewportState } from \"../stores/ThreadViewport\";\nimport { ThreadActionsState } from \"../stores/ThreadActions\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { ThreadMessagesState } from \"../stores/ThreadMessages\";\n\nexport type ThreadContextValue = {\n useThread: ReadonlyStore<ThreadState>;\n useThreadMessages: ReadonlyStore<ThreadMessagesState>;\n useThreadActions: ReadonlyStore<ThreadActionsState>;\n useComposer: ReadonlyStore<ComposerState>;\n useViewport: ReadonlyStore<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(\n \"This component must be used within an AssistantRuntimeProvider.\",\n );\n return context;\n};\n","import { create } from \"zustand\";\nimport { type BaseComposerState, makeBaseComposer } from \"./BaseComposer\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { Unsubscribe } from \"../../types/Unsubscribe\";\nimport { ThreadContextValue } from \"../react\";\n\nexport type ComposerState = BaseComposerState &\n Readonly<{\n canCancel: boolean;\n isEditing: true;\n\n send: () => void;\n cancel: () => void;\n focus: () => void;\n onFocus: (listener: () => void) => Unsubscribe;\n }>;\n\nexport const makeComposerStore = (\n useThreadMessages: ThreadContextValue[\"useThreadMessages\"],\n useThreadActions: ThreadContextValue[\"useThreadActions\"],\n): ReadonlyStore<ComposerState> => {\n const focusListeners = new Set<() => void>();\n return create<ComposerState>()((set, get, store) => {\n return {\n ...makeBaseComposer(set, get, store),\n\n get canCancel() {\n return useThreadActions.getState().capabilities.cancel;\n },\n isEditing: true,\n\n send: () => {\n const { setValue, value } = get();\n setValue(\"\");\n\n useThreadActions.getState().append({\n parentId: useThreadMessages.getState().at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: value }],\n });\n },\n cancel: () => {\n useThreadActions.getState().cancelRun();\n },\n focus: () => {\n for (const listener of focusListeners) {\n listener();\n }\n },\n onFocus: (listener) => {\n focusListeners.add(listener);\n return () => {\n focusListeners.delete(listener);\n };\n },\n };\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 type { MutableRefObject } from \"react\";\nimport { create } from \"zustand\";\nimport { ThreadRuntime } from \"../../runtime\";\n\nexport type ThreadState = Readonly<{\n isRunning: boolean;\n}>;\n\nexport const makeThreadStore = (\n runtimeRef: MutableRefObject<ThreadRuntime>,\n) => {\n return create<ThreadState>(() => ({\n isRunning: runtimeRef.current.isRunning,\n }));\n};\n","\"use client\";\nimport { create } from \"zustand\";\nimport type { Unsubscribe } from \"../../types/Unsubscribe\";\n\nexport type ThreadViewportState = Readonly<{\n isAtBottom: boolean;\n scrollToBottom: () => void;\n onScrollToBottom: (callback: () => void) => Unsubscribe;\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","import type { MutableRefObject } from \"react\";\nimport { create } from \"zustand\";\nimport type { AppendMessage } from \"../../types/AssistantTypes\";\nimport { ThreadRuntime } from \"../../runtime\";\n\nexport type ThreadActionsState = Readonly<{\n capabilities: Readonly<{\n edit: boolean;\n reload: boolean;\n cancel: boolean;\n copy: 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 addToolResult: (toolCallId: string, result: any) => void;\n}>;\n\nexport const makeThreadActionStore = (\n runtimeRef: MutableRefObject<ThreadRuntime>,\n) => {\n return create<ThreadActionsState>(() =>\n Object.freeze({\n get capabilities() {\n return runtimeRef.current.capabilities;\n },\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 addToolResult: (toolCallId, result) =>\n runtimeRef.current.addToolResult(toolCallId, result),\n }),\n );\n};\n","import type { MutableRefObject } from \"react\";\nimport { create } from \"zustand\";\nimport type { ThreadMessage } from \"../../types/AssistantTypes\";\nimport { ThreadRuntime } from \"../../runtime\";\n\nexport type ThreadMessagesState = readonly ThreadMessage[];\n\nexport const makeThreadMessagesStore = (\n runtimeRef: MutableRefObject<ThreadRuntime>,\n) => {\n return create<ThreadMessagesState>(() => runtimeRef.current.messages);\n};\n","import { create } from \"zustand\";\nimport { AssistantRuntime } from \"../../runtime\";\nimport { MutableRefObject } from \"react\";\n\nexport type AssistantActionsState = Readonly<{\n switchToThread: (threadId: string | null) => void;\n}>;\n\nexport const makeAssistantActionsStore = (\n runtimeRef: MutableRefObject<AssistantRuntime>,\n) =>\n create<AssistantActionsState>(() =>\n Object.freeze({\n switchToThread: () => runtimeRef.current.switchToThread(null),\n }),\n );\n","import { useContext, useMemo } from \"react\";\nimport { MessageContext } from \"./MessageContext\";\nimport { useThreadContext } from \"./ThreadContext\";\nimport type { ComposerState } from \"../stores/Composer\";\nimport type { EditComposerState } from \"../stores/EditComposer\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\n\nexport type ComposerContextValue = {\n useComposer: ReadonlyStore<EditComposerState | ComposerState>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer } = useThreadContext();\n const { useEditComposer } = useContext(MessageContext) ?? {};\n return useMemo(\n () => ({\n useComposer: (useEditComposer ?? useComposer) as ReadonlyStore<\n EditComposerState | ComposerState\n >,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useComposer],\n );\n};\n","import { createContext, useContext } from \"react\";\nimport type { MessageState } from \"../stores/Message\";\nimport type { EditComposerState } from \"../stores/EditComposer\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { MessageUtilsState } from \"../stores/MessageUtils\";\n\nexport type MessageContextValue = {\n useMessage: ReadonlyStore<MessageState>;\n useMessageUtils: ReadonlyStore<MessageUtilsState>;\n useEditComposer: ReadonlyStore<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","import { createContext, useContext } from \"react\";\nimport type { ContentPartState } from \"../stores/ContentPart\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\n\nexport type ContentPartContextValue = {\n useContentPart: ReadonlyStore<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 { useCallback } from \"react\";\nimport { ThreadContextValue, useThreadContext } from \"../context\";\nimport { AppendMessage } from \"../types\";\n\ntype CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n };\n\nconst toAppendMessage = (\n useThreadMessages: ThreadContextValue[\"useThreadMessages\"],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n parentId: useThreadMessages.getState().at(-1)?.id ?? null,\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n };\n }\n\n return {\n parentId:\n message.parentId ?? useThreadMessages.getState().at(-1)?.id ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n };\n};\n\nexport const useAppendMessage = () => {\n const { useThreadMessages, useThreadActions, useViewport, useComposer } =\n useThreadContext();\n\n const append = useCallback(\n (message: CreateAppendMessage) => {\n const appendMessage = toAppendMessage(useThreadMessages, message);\n useThreadActions.getState().append(appendMessage);\n\n useViewport.getState().scrollToBottom();\n useComposer.getState().focus();\n },\n [useThreadMessages, useThreadActions, useViewport, useComposer],\n );\n\n return append;\n};\n","import { useCallback } from \"react\";\nimport { useAssistantContext, useThreadContext } from \"../context\";\n\nexport const useSwitchToNewThread = () => {\n const { useAssistantActions } = useAssistantContext();\n const { useComposer } = useThreadContext();\n\n const switchToNewThread = useCallback(() => {\n useAssistantActions.getState().switchToThread(null);\n useComposer.getState().focus();\n }, [useAssistantActions, useComposer]);\n\n return switchToNewThread;\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/ContentPartComponentTypes\";\nimport type { Tool } from \"../types/ModelConfigTypes\";\n\nexport type AssistantToolProps<TArgs, TResult> = Tool<TArgs, TResult> & {\n toolName: string;\n render?: ToolCallContentPartComponent<TArgs, TResult> | undefined;\n};\n\nexport const useAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const { useModelConfig, useToolUIs } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n const { toolName, render, ...rest } = tool;\n const config = {\n tools: {\n [tool.toolName]: rest,\n },\n };\n const unsub1 = registerModelConfigProvider(() => config);\n const unsub2 = render ? setToolUI(toolName, render) : undefined;\n return () => {\n unsub1();\n unsub2?.();\n };\n }, [registerModelConfigProvider, setToolUI, tool]);\n};\n","\"use client\";\nimport { type AssistantToolProps, useAssistantTool } from \"./useAssistantTool\";\n\nexport const makeAssistantTool = <TArgs, TResult>(\n tool: AssistantToolProps<TArgs, TResult>,\n) => {\n const Tool = () => {\n useAssistantTool(tool);\n return null;\n };\n return Tool;\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/react/AssistantContext\";\nimport type { ToolCallContentPartComponent } from \"../types/ContentPartComponentTypes\";\n\nexport type AssistantToolUIProps<TArgs, TResult> = {\n toolName: string;\n render: ToolCallContentPartComponent<TArgs, TResult>;\n};\n\nexport const useAssistantToolUI = (\n tool: AssistantToolUIProps<any, any> | null,\n) => {\n const { useToolUIs } = useAssistantContext();\n const setToolUI = useToolUIs((s) => s.setToolUI);\n useEffect(() => {\n if (!tool) return;\n const { toolName, render } = tool;\n return setToolUI(toolName, render);\n }, [setToolUI, tool]);\n};\n","\"use client\";\nimport {\n type AssistantToolUIProps,\n useAssistantToolUI,\n} from \"./useAssistantToolUI\";\n\nexport const makeAssistantToolUI = <TArgs, TResult>(\n tool: AssistantToolUIProps<TArgs, TResult>,\n) => {\n const ToolUI = () => {\n useAssistantToolUI(tool);\n return null;\n };\n return ToolUI;\n};\n","\"use client\";\n\nimport { useEffect } from \"react\";\nimport { useAssistantContext } from \"../context/react/AssistantContext\";\n\nexport const useAssistantInstructions = (instruction: string) => {\n const { useModelConfig } = useAssistantContext();\n const registerModelConfigProvider = useModelConfig(\n (s) => s.registerModelConfigProvider,\n );\n useEffect(() => {\n const config = {\n system: instruction,\n };\n return registerModelConfigProvider(() => config);\n }, [registerModelConfigProvider, instruction]);\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\nimport { getMessageText } from \"../../utils/getMessageText\";\n\nexport type UseActionBarCopyProps = {\n copiedDuration?: number | undefined;\n};\n\nexport const useActionBarCopy = ({\n copiedDuration = 3000,\n}: UseActionBarCopyProps = {}) => {\n const { useMessage, useMessageUtils, useEditComposer } = useMessageContext();\n\n const hasCopyableContent = useCombinedStore(\n [useMessage, useEditComposer],\n (m, c) => {\n return (\n !c.isEditing &&\n m.message.content.some((c) => c.type === \"text\" && c.text.length > 0)\n );\n },\n );\n\n const callback = useCallback(() => {\n const { message } = useMessage.getState();\n const { setIsCopied } = useMessageUtils.getState();\n const { isEditing, value: composerValue } = useEditComposer.getState();\n\n const valueToCopy = isEditing ? composerValue : getMessageText(message);\n\n navigator.clipboard.writeText(valueToCopy);\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n }, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);\n\n if (!hasCopyableContent) return null;\n return callback;\n};\n","import { useMemo } from \"react\";\nimport {\n type CombinedSelector,\n createCombinedStore,\n} from \"./createCombinedStore\";\nimport { ReadonlyStore } from \"../../context/ReadonlyStore\";\n\nexport const useCombinedStore = <T extends Array<unknown>, R>(\n stores: { [K in keyof T]: ReadonlyStore<T[K]> },\n selector: CombinedSelector<T, R>,\n): R => {\n // eslint-disable-next-line react-hooks/exhaustive-deps -- 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 { Unsubscribe } from \"../../types/Unsubscribe\";\nimport { ReadonlyStore } from \"../../context/ReadonlyStore\";\n\nexport type CombinedSelector<T extends Array<unknown>, R> = (...args: T) => R;\n\nexport const createCombinedStore = <T extends Array<unknown>, R>(stores: {\n [K in keyof T]: ReadonlyStore<T[K]>;\n}) => {\n const subscribe = (callback: () => void): Unsubscribe => {\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","import type { TextContentPart, ThreadMessage } from \"../types/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/react/MessageContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport const useActionBarEdit = () => {\n const { useMessage, useEditComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useEditComposer],\n (m, c) => m.message.role !== \"user\" || c.isEditing,\n );\n\n const callback = useCallback(() => {\n const { edit } = useEditComposer.getState();\n edit();\n }, [useEditComposer]);\n\n if (disabled) return null;\n return callback;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport const useActionBarReload = () => {\n const { useThread, useThreadActions, useComposer, useViewport } =\n 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 useThreadActions.getState().startRun(parentId);\n useViewport.getState().scrollToBottom();\n useComposer.getState().focus();\n }, [useThreadActions, useComposer, useViewport, useMessage]);\n\n if (disabled) return null;\n return callback;\n};\n","\"use client\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\n\nexport const useBranchPickerCount = () => {\n const { useMessage } = useMessageContext();\n const branchCount = useMessage((s) => s.branches.length);\n return branchCount;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport const useBranchPickerNext = () => {\n const { useThreadActions } = useThreadContext();\n const { useMessage, useEditComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useEditComposer],\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 useThreadActions\n .getState()\n .switchToBranch(branches[branches.indexOf(message.id) + 1]!);\n }, [useThreadActions, useMessage]);\n\n if (disabled) return null;\n return callback;\n};\n","\"use client\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\n\nexport const useBranchPickerNumber = () => {\n const { useMessage } = useMessageContext();\n const branchIdx = useMessage((s) => s.branches.indexOf(s.message.id));\n return branchIdx + 1;\n};\n","import { useCallback } from \"react\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport const useBranchPickerPrevious = () => {\n const { useThreadActions } = useThreadContext();\n const { useMessage, useEditComposer } = useMessageContext();\n\n const disabled = useCombinedStore(\n [useMessage, useEditComposer],\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 useThreadActions\n .getState()\n .switchToBranch(branches[branches.indexOf(message.id) - 1]!);\n }, [useThreadActions, useMessage]);\n\n if (disabled) return null;\n return callback;\n};\n","import { useCallback } from \"react\";\nimport { useComposerContext } from \"../../context\";\n\nexport const useComposerCancel = () => {\n const { useComposer } = useComposerContext();\n\n const disabled = useComposer((c) => !c.canCancel);\n\n const callback = useCallback(() => {\n const { cancel } = useComposer.getState();\n cancel();\n }, [useComposer]);\n\n if (disabled) return null;\n return callback;\n};\n","\"use client\";\nimport { useComposerContext } from \"../../context/react/ComposerContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype ComposerIfFilters = {\n editing: boolean | undefined;\n};\n\nexport type UseComposerIfProps = RequireAtLeastOne<ComposerIfFilters>;\n\nexport const useComposerIf = (props: UseComposerIfProps) => {\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","import { useCallback } from \"react\";\nimport { useComposerContext, useThreadContext } from \"../../context\";\n\nexport const useComposerSend = () => {\n const { useViewport, useComposer: useNewComposer } = useThreadContext();\n const { useComposer } = useComposerContext();\n\n const disabled = useComposer((c) => !c.isEditing || c.value.length === 0);\n\n const callback = useCallback(() => {\n const composerState = useComposer.getState();\n if (!composerState.isEditing) return;\n\n composerState.send();\n\n useViewport.getState().scrollToBottom();\n useNewComposer.getState().focus();\n }, [useNewComposer, useComposer, useViewport]);\n\n if (disabled) return null;\n return callback;\n};\n","import { useContentPartContext } from \"../../context/react/ContentPartContext\";\nimport { UIContentPartState } from \"../../context/stores/ContentPart\";\n\nexport const useContentPartDisplay = () => {\n const { useContentPart } = useContentPartContext();\n\n const display = useContentPart((c) => {\n if (c.part.type !== \"ui\")\n throw new Error(\n \"This component can only be used inside ui content parts.\",\n );\n\n return c as UIContentPartState;\n });\n\n return display;\n};\n","import { useContentPartContext } from \"../../context/react/ContentPartContext\";\nimport { ImageContentPartState } from \"../../context/stores/ContentPart\";\n\nexport const useContentPartImage = () => {\n const { useContentPart } = useContentPartContext();\n\n const image = useContentPart((c) => {\n if (c.part.type !== \"image\")\n throw new Error(\n \"ContentPartImage can only be used inside image content parts.\",\n );\n\n return c as ImageContentPartState;\n });\n\n return image;\n};\n","import { useContentPartContext } from \"../../context/react/ContentPartContext\";\nimport { TextContentPartState } from \"../../context/stores/ContentPart\";\n\nexport const useContentPartText = () => {\n const { useContentPart } = useContentPartContext();\n\n const text = useContentPart((c) => {\n if (c.part.type !== \"text\")\n throw new Error(\n \"ContentPartText can only be used inside text content parts.\",\n );\n\n return c as TextContentPartState;\n });\n\n return text;\n};\n","\"use client\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\ntype MessageIfFilters = {\n user: boolean | undefined;\n assistant: boolean | undefined;\n hasBranches: boolean | undefined;\n copied: boolean | undefined;\n lastOrHover: boolean | undefined;\n};\nexport type UseMessageIfProps = RequireAtLeastOne<MessageIfFilters>;\n\nexport const useMessageIf = (props: UseMessageIfProps) => {\n const { useMessage, useMessageUtils } = useMessageContext();\n\n return useCombinedStore(\n [useMessage, useMessageUtils],\n ({ 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};\n","\"use client\";\n\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\ntype ThreadIfFilters = {\n empty: boolean | undefined;\n running: boolean | undefined;\n};\n\nexport type UseThreadIfProps = RequireAtLeastOne<ThreadIfFilters>;\n\nexport const useThreadIf = (props: UseThreadIfProps) => {\n const { useThread, useThreadMessages } = useThreadContext();\n return useCombinedStore(\n [useThread, useThreadMessages],\n (thread, messages) => {\n if (props.empty === true && messages.length !== 0) return false;\n if (props.empty === false && 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};\n","import { useThreadIf } from \"./useThreadIf\";\n\nexport const useThreadEmpty = () => {\n return useThreadIf({ empty: true });\n};\n","import { useCallback } from \"react\";\nimport { useThreadContext } from \"../../context\";\n\nexport const useThreadScrollToBottom = () => {\n const { useComposer, useViewport } = useThreadContext();\n\n const isAtBottom = useViewport((s) => s.isAtBottom);\n\n const handleScrollToBottom = useCallback(() => {\n useViewport.getState().scrollToBottom();\n useComposer.getState().focus();\n }, [useViewport, useComposer]);\n\n if (isAtBottom) return null;\n return handleScrollToBottom;\n};\n","import { useCallback } from \"react\";\nimport { useThreadContext } from \"../../context\";\nimport { useAppendMessage } from \"../../hooks\";\n\nexport type UseApplyThreadSuggestionProps = {\n prompt: string;\n method: \"replace\";\n autoSend?: boolean | undefined;\n};\n\nexport const useThreadSuggestion = ({\n prompt,\n autoSend,\n}: UseApplyThreadSuggestionProps) => {\n const { useThread, useComposer } = useThreadContext();\n\n const append = useAppendMessage();\n const disabled = useThread((t) => t.isRunning);\n const callback = useCallback(() => {\n const thread = useThread.getState();\n const composer = useComposer.getState();\n if (autoSend && !thread.isRunning) {\n append(prompt);\n composer.setValue(\"\");\n } else {\n composer.setValue(prompt);\n }\n }, [useThread, useComposer, autoSend, append, prompt]);\n\n if (disabled) return null;\n return callback;\n};\n","export { ActionBarPrimitiveRoot as Root } from \"./ActionBarRoot\";\nexport { ActionBarPrimitiveCopy as Copy } from \"./ActionBarCopy\";\nexport { ActionBarPrimitiveReload as Reload } from \"./ActionBarReload\";\nexport { ActionBarPrimitiveEdit as Edit } from \"./ActionBarEdit\";\n","\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport {\n useActionBarFloatStatus,\n HideAndFloatStatus,\n UseActionBarFloatStatusProps,\n} from \"./useActionBarFloatStatus\";\n\ntype ActionBarPrimitiveRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type ActionBarPrimitiveRootProps = PrimitiveDivProps &\n UseActionBarFloatStatusProps;\n\nexport const ActionBarPrimitiveRoot = forwardRef<\n ActionBarPrimitiveRootElement,\n ActionBarPrimitiveRootProps\n>(({ hideWhenRunning, autohide, autohideFloat, ...rest }, ref) => {\n const hideAndfloatStatus = useActionBarFloatStatus({\n hideWhenRunning,\n autohide,\n autohideFloat,\n });\n\n if (hideAndfloatStatus === HideAndFloatStatus.Hidden) return null;\n\n return (\n <Primitive.div\n {...(hideAndfloatStatus === HideAndFloatStatus.Floating\n ? { \"data-floating\": \"true\" }\n : null)}\n {...rest}\n ref={ref}\n />\n );\n});\n\nActionBarPrimitiveRoot.displayName = \"ActionBarPrimitive.Root\";\n","\"use client\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useCombinedStore } from \"../../utils/combined/useCombinedStore\";\n\nexport enum HideAndFloatStatus {\n Hidden = \"hidden\",\n Floating = \"floating\",\n Normal = \"normal\",\n}\n\nexport type UseActionBarFloatStatusProps = {\n hideWhenRunning?: boolean | undefined;\n autohide?: \"always\" | \"not-last\" | \"never\" | undefined;\n autohideFloat?: \"always\" | \"single-branch\" | \"never\" | undefined;\n};\n\nexport const useActionBarFloatStatus = ({\n hideWhenRunning,\n autohide,\n autohideFloat,\n}: UseActionBarFloatStatusProps) => {\n const { useThread } = useThreadContext();\n const { useMessage, useMessageUtils } = useMessageContext();\n\n return useCombinedStore(\n [useThread, useMessage, useMessageUtils],\n (t, m, mu) => {\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 (!mu.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","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\n\ntype ActionButtonCallback<TProps> = (props: TProps) => null | (() => void);\n\ntype PrimitiveButtonElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\nexport type ActionButtonProps<THook> = PrimitiveButtonProps &\n (THook extends (props: infer TProps) => unknown ? TProps : never);\n\nexport const createActionButton = <TProps,>(\n displayName: string,\n useActionButton: ActionButtonCallback<TProps>,\n) => {\n const ActionButton = forwardRef<\n PrimitiveButtonElement,\n PrimitiveButtonProps & TProps\n >((props, forwardedRef) => {\n const callback = useActionButton(props);\n\n return (\n <Primitive.button\n type=\"button\"\n disabled={!callback}\n {...props}\n ref={forwardedRef}\n onClick={composeEventHandlers(props.onClick, () => {\n callback?.();\n })}\n />\n );\n });\n\n ActionButton.displayName = displayName;\n\n return ActionButton;\n};\n","\"use client\";\n\nimport { useActionBarCopy } from \"../../primitive-hooks/actionBar/useActionBarCopy\";\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\n\nexport type ActionBarPrimitiveCopyProps = ActionButtonProps<\n typeof useActionBarCopy\n>;\n\nexport const ActionBarPrimitiveCopy = createActionButton(\n \"ActionBarPrimitive.Copy\",\n useActionBarCopy,\n);\n","\"use client\";\n\nimport { useActionBarReload } from \"../../primitive-hooks/actionBar/useActionBarReload\";\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\n\nexport type ActionBarPrimitiveReloadProps = ActionButtonProps<\n typeof useActionBarReload\n>;\n\nexport const ActionBarPrimitiveReload = createActionButton(\n \"ActionBarPrimitive.Reload\",\n useActionBarReload,\n);\n","\"use client\";\n\nimport { useActionBarEdit } from \"../../primitive-hooks/actionBar/useActionBarEdit\";\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\n\nexport type ActionBarPrimitiveEditProps = ActionButtonProps<\n typeof useActionBarEdit\n>;\n\nexport const ActionBarPrimitiveEdit = createActionButton(\n \"ActionBarPrimitive.Edit\",\n useActionBarEdit,\n);\n","export { AssistantModalPrimitiveRoot as Root } from \"./AssistantModalRoot\";\nexport { AssistantModalPrimitiveTrigger as Trigger } from \"./AssistantModalTrigger\";\nexport { AssistantModalPrimitiveContent as Content } from \"./AssistantModalContent\";\nexport { AssistantModalPrimitiveAnchor as Anchor } from \"./AssistantModalAnchor\";\n","\"use client\";\n\nimport { FC, useState } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useOnComposerFocus } from \"../../utils/hooks/useOnComposerFocus\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\n\nexport type AssistantModalPrimitiveRootProps = PopoverPrimitive.PopoverProps;\n\nconst useAssistantModalOpenState = (defaultOpen = false) => {\n const state = useState(defaultOpen);\n\n const [, setOpen] = state;\n useOnComposerFocus(() => {\n setOpen(true);\n });\n\n return state;\n};\n\nexport const AssistantModalPrimitiveRoot: FC<\n AssistantModalPrimitiveRootProps\n> = ({\n __scopeAssistantModal,\n defaultOpen,\n open,\n onOpenChange,\n ...rest\n}: ScopedProps<AssistantModalPrimitiveRootProps>) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n const [modalOpen, setOpen] = useAssistantModalOpenState(defaultOpen);\n\n return (\n <PopoverPrimitive.Root\n {...scope}\n open={open === undefined ? modalOpen : open}\n onOpenChange={composeEventHandlers(onOpenChange, setOpen)}\n {...rest}\n />\n );\n};\n\nAssistantModalPrimitiveRoot.displayName = \"AssistantModalPrimitive.Root\";\n","import { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useEffect } from \"react\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\n\nexport const useOnComposerFocus = (callback: () => void) => {\n const callbackRef = useCallbackRef(callback);\n\n const { useComposer } = useThreadContext();\n useEffect(() => {\n return useComposer.getState().onFocus(() => {\n callbackRef();\n });\n }, [useComposer, callbackRef]);\n};\n","import * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport type { Scope } from \"@radix-ui/react-context\";\n\nexport type ScopedProps<P> = P & { __scopeAssistantModal?: Scope };\nexport const usePopoverScope = PopoverPrimitive.createPopoverScope();\n","\"use client\";\n\nimport { ComponentPropsWithoutRef, ElementRef, forwardRef } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\n\ntype AssistantModalPrimitiveTriggerElement = ElementRef<\n typeof PopoverPrimitive.Trigger\n>;\nexport type AssistantModalPrimitiveTriggerProps = ComponentPropsWithoutRef<\n typeof PopoverPrimitive.Trigger\n>;\n\nexport const AssistantModalPrimitiveTrigger = forwardRef<\n AssistantModalPrimitiveTriggerElement,\n AssistantModalPrimitiveTriggerProps\n>(\n (\n {\n __scopeAssistantModal,\n ...rest\n }: ScopedProps<AssistantModalPrimitiveTriggerProps>,\n ref,\n ) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n return <PopoverPrimitive.Trigger {...scope} {...rest} ref={ref} />;\n },\n);\n\nAssistantModalPrimitiveTrigger.displayName = \"AssistantModalPrimitive.Trigger\";\n","\"use client\";\n\nimport { ComponentPropsWithoutRef, ElementRef, forwardRef } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\n\ntype AssistantModalPrimitiveContentElement = ElementRef<\n typeof PopoverPrimitive.Content\n>;\nexport type AssistantModalPrimitiveContentProps = ComponentPropsWithoutRef<\n typeof PopoverPrimitive.Content\n> & {\n dissmissOnInteractOutside?: boolean | undefined;\n};\n\nexport const AssistantModalPrimitiveContent = forwardRef<\n AssistantModalPrimitiveContentElement,\n AssistantModalPrimitiveContentProps\n>(\n (\n {\n __scopeAssistantModal,\n side,\n align,\n onInteractOutside,\n dissmissOnInteractOutside = false,\n ...props\n }: ScopedProps<AssistantModalPrimitiveContentProps>,\n forwardedRef,\n ) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n return (\n <PopoverPrimitive.Portal {...scope}>\n <PopoverPrimitive.Content\n {...scope}\n {...props}\n ref={forwardedRef}\n side={side ?? \"top\"}\n align={align ?? \"end\"}\n onInteractOutside={composeEventHandlers(\n onInteractOutside,\n dissmissOnInteractOutside ? undefined : (e) => e.preventDefault(),\n )}\n />\n </PopoverPrimitive.Portal>\n );\n },\n);\n\nAssistantModalPrimitiveContent.displayName = \"AssistantModalPrimitive.Content\";\n","\"use client\";\nimport { ComponentPropsWithoutRef, ElementRef, forwardRef } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { ScopedProps, usePopoverScope } from \"./scope\";\n\ntype AssistantModalPrimitiveAnchorElement = ElementRef<\n typeof PopoverPrimitive.Anchor\n>;\ntype AssistantModalPrimitiveAnchorProps = ComponentPropsWithoutRef<\n typeof PopoverPrimitive.Anchor\n>;\n\nexport const AssistantModalPrimitiveAnchor = forwardRef<\n AssistantModalPrimitiveAnchorElement,\n AssistantModalPrimitiveAnchorProps\n>(\n (\n {\n __scopeAssistantModal,\n ...rest\n }: ScopedProps<AssistantModalPrimitiveAnchorProps>,\n ref,\n ) => {\n const scope = usePopoverScope(__scopeAssistantModal);\n\n return <PopoverPrimitive.Anchor {...scope} {...rest} ref={ref} />;\n },\n);\nAssistantModalPrimitiveAnchor.displayName = \"AssistantModalPrimitive.Anchor\";\n","export { BranchPickerPrimitiveNext as Next } from \"./BranchPickerNext\";\nexport { BranchPickerPrevious as Previous } from \"./BranchPickerPrevious\";\nexport { BranchPickerPrimitiveCount as Count } from \"./BranchPickerCount\";\nexport { BranchPickerPrimitiveNumber as Number } from \"./BranchPickerNumber\";\nexport { BranchPickerPrimitiveRoot as Root } from \"./BranchPickerRoot\";\n","\"use client\";\n\nimport { useBranchPickerNext } from \"../../primitive-hooks/branchPicker/useBranchPickerNext\";\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\n\nexport type BranchPickerPrimitiveNextProps = ActionButtonProps<\n typeof useBranchPickerNext\n>;\n\nexport const BranchPickerPrimitiveNext = createActionButton(\n \"BranchPickerPrimitive.Next\",\n useBranchPickerNext,\n);\n","\"use client\";\n\nimport { useBranchPickerPrevious } from \"../../primitive-hooks/branchPicker/useBranchPickerPrevious\";\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\n\nexport type BranchPickerPrimitivePreviousProps = ActionButtonProps<\n typeof useBranchPickerPrevious\n>;\n\nexport const BranchPickerPrevious = createActionButton(\n \"BranchPickerPrimitive.Previous\",\n useBranchPickerPrevious,\n);\n","\"use client\";\n\nimport type { FC } from \"react\";\nimport { useBranchPickerCount } from \"../../primitive-hooks/branchPicker/useBranchPickerCount\";\n\nexport type BranchPickerPrimitiveCountProps = {};\n\nexport const BranchPickerPrimitiveCount: FC<\n BranchPickerPrimitiveCountProps\n> = () => {\n const branchCount = useBranchPickerCount();\n return <>{branchCount}</>;\n};\n\nBranchPickerPrimitiveCount.displayName = \"BranchPickerPrimitive.Count\";\n","\"use client\";\n\nimport type { FC } from \"react\";\nimport { useBranchPickerNumber } from \"../../primitive-hooks/branchPicker/useBranchPickerNumber\";\n\nexport type BranchPickerPrimitiveNumberProps = {};\n\nexport const BranchPickerPrimitiveNumber: FC<\n BranchPickerPrimitiveNumberProps\n> = () => {\n const branchNumber = useBranchPickerNumber();\n return <>{branchNumber}</>;\n};\n\nBranchPickerPrimitiveNumber.displayName = \"BranchPickerPrimitive.Number\";\n","\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport { If } from \"../message\";\n\ntype BranchPickerPrimitiveRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type BranchPickerPrimitiveRootProps = PrimitiveDivProps & {\n hideWhenSingleBranch?: boolean | undefined;\n};\n\nexport const BranchPickerPrimitiveRoot = forwardRef<\n BranchPickerPrimitiveRootElement,\n BranchPickerPrimitiveRootProps\n>(({ hideWhenSingleBranch, ...rest }, ref) => {\n return (\n <If hasBranches={hideWhenSingleBranch ? true : undefined}>\n <Primitive.div {...rest} ref={ref} />\n </If>\n );\n});\n\nBranchPickerPrimitiveRoot.displayName = \"BranchPickerPrimitive.Root\";\n","export { MessagePrimitiveRoot as Root } from \"./MessageRoot\";\nexport { MessagePrimitiveIf as If } from \"./MessageIf\";\nexport { MessagePrimitiveContent as Content } from \"./MessageContent\";\nexport { MessagePrimitiveInProgress as InProgress } from \"./MessageInProgress\";\n","\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ElementRef,\n forwardRef,\n ComponentPropsWithoutRef,\n useCallback,\n} from \"react\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\n\ntype MessagePrimitiveRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nconst useIsHoveringRef = () => {\n const { useMessageUtils } = useMessageContext();\n\n const callbackRef = useCallback(\n (el: HTMLElement) => {\n const setIsHovering = useMessageUtils.getState().setIsHovering;\n\n const handleMouseEnter = () => {\n setIsHovering(true);\n };\n const handleMouseLeave = () => {\n setIsHovering(false);\n };\n\n el.addEventListener(\"mouseenter\", handleMouseEnter);\n el.addEventListener(\"mouseleave\", handleMouseLeave);\n\n return () => {\n el.removeEventListener(\"mouseenter\", handleMouseEnter);\n el.removeEventListener(\"mouseleave\", handleMouseLeave);\n setIsHovering(false);\n };\n },\n [useMessageUtils],\n );\n\n return useManagedRef(callbackRef);\n};\n\nexport type MessagePrimitiveRootProps = PrimitiveDivProps;\n\nexport const MessagePrimitiveRoot = forwardRef<\n MessagePrimitiveRootElement,\n MessagePrimitiveRootProps\n>(({ onMouseEnter, onMouseLeave, ...rest }, forwardRef) => {\n const isHoveringRef = useIsHoveringRef();\n const ref = useComposedRefs<HTMLDivElement>(forwardRef, isHoveringRef);\n\n return <Primitive.div {...rest} ref={ref} />;\n});\n\nMessagePrimitiveRoot.displayName = \"MessagePrimitive.Root\";\n","import { useCallback, useRef } from \"react\";\n\nexport const useManagedRef = <TNode>(\n callback: (node: TNode) => (() => void) | void,\n) => {\n const cleanupRef = useRef<(() => void) | void>();\n\n const ref = useCallback(\n (el: TNode | null) => {\n // Call the previous cleanup function\n if (cleanupRef.current) {\n cleanupRef.current();\n }\n\n // Call the new callback and store its cleanup function\n if (el) {\n cleanupRef.current = callback(el);\n }\n },\n [callback],\n );\n\n return ref;\n};\n","\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport {\n UseMessageIfProps,\n useMessageIf,\n} from \"../../primitive-hooks/message/useMessageIf\";\n\nexport type MessagePrimitiveIfProps = PropsWithChildren<UseMessageIfProps>;\n\nexport const MessagePrimitiveIf: FC<MessagePrimitiveIfProps> = ({\n children,\n ...query\n}) => {\n const result = useMessageIf(query);\n return result ? children : null;\n};\n\nMessagePrimitiveIf.displayName = \"MessagePrimitive.If\";\n","\"use client\";\n\nimport { type ComponentType, type FC, memo } from \"react\";\nimport {\n useAssistantContext,\n useContentPartContext,\n useThreadContext,\n} from \"../../context\";\nimport { useMessageContext } from \"../../context/react/MessageContext\";\nimport { ContentPartProvider } from \"../../context/providers/ContentPartProvider\";\nimport { ContentPartPrimitiveText } from \"../contentPart/ContentPartText\";\nimport { ContentPartPrimitiveImage } from \"../contentPart/ContentPartImage\";\nimport { ContentPartPrimitiveDisplay } from \"../contentPart/ContentPartDisplay\";\nimport type {\n ImageContentPartComponent,\n TextContentPartComponent,\n ToolCallContentPartComponent,\n ToolCallContentPartProps,\n UIContentPartComponent,\n} from \"../../types/ContentPartComponentTypes\";\nimport { ContentPartPrimitiveInProgress } from \"../contentPart/ContentPartInProgress\";\n\nexport type MessagePrimitiveContentProps = {\n components?:\n | {\n Text?: TextContentPartComponent | undefined;\n Image?: ImageContentPartComponent | undefined;\n UI?: UIContentPartComponent | undefined;\n tools?: {\n by_name?:\n | Record<string, ToolCallContentPartComponent | undefined>\n | undefined;\n Fallback?: ComponentType<ToolCallContentPartProps> | undefined;\n };\n }\n | undefined;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <ContentPartPrimitiveText />\n <ContentPartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </ContentPartPrimitiveInProgress>\n </p>\n ),\n Image: () => <ContentPartPrimitiveImage />,\n UI: () => <ContentPartPrimitiveDisplay />,\n tools: {\n Fallback: (props) => {\n const { useToolUIs } = useAssistantContext();\n const Render = useToolUIs((s) => s.getToolUI(props.part.toolName));\n if (!Render) return null;\n return <Render {...props} />;\n },\n },\n} satisfies MessagePrimitiveContentProps[\"components\"];\n\ntype MessageContentPartComponentProps = {\n components: MessagePrimitiveContentProps[\"components\"];\n};\n\nconst MessageContentPartComponent: FC<MessageContentPartComponentProps> = ({\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 { useThreadActions } = useThreadContext();\n const addToolResult = useThreadActions((t) => t.addToolResult);\n\n const { useContentPart } = useContentPartContext();\n const { part, status } = useContentPart();\n\n const type = part.type;\n switch (type) {\n case \"text\":\n return <Text part={part} status={status} />;\n\n case \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text -- not a real image\n return <Image part={part} status={status} />;\n\n case \"ui\":\n return <UI part={part} status={status} />;\n\n case \"tool-call\": {\n const Tool = by_name[part.toolName] || Fallback;\n const addResult = (result: any) => addToolResult(part.toolCallId, result);\n return <Tool part={part} status={status} addResult={addResult} />;\n }\n default:\n throw new Error(`Unknown content part type: ${type}`);\n }\n};\n\ntype MessageContentPartProps = {\n partIndex: number;\n components: MessagePrimitiveContentProps[\"components\"];\n};\n\nconst MessageContentPartImpl: FC<MessageContentPartProps> = ({\n partIndex,\n components,\n}) => {\n return (\n <ContentPartProvider partIndex={partIndex}>\n <MessageContentPartComponent components={components} />\n </ContentPartProvider>\n );\n};\n\nconst MessageContentPart = memo(\n MessageContentPartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.UI === next.components?.UI &&\n prev.components?.tools === next.components?.tools,\n);\n\nexport const MessagePrimitiveContent: FC<MessagePrimitiveContentProps> = ({\n components,\n}) => {\n const { useMessage } = useMessageContext();\n\n const contentLength = useMessage((s) => s.message.content.length);\n\n return new Array(contentLength).fill(null).map((_, idx) => {\n const partIndex = idx; // use the index as key, as message is generally append only\n return (\n <MessageContentPart\n key={partIndex}\n partIndex={partIndex}\n components={components}\n />\n );\n });\n};\n\nMessagePrimitiveContent.displayName = \"MessagePrimitive.Content\";\n","\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { StoreApi, create } from \"zustand\";\nimport { ContentPartContext } from \"../react/ContentPartContext\";\nimport type { ContentPartContextValue } from \"../react/ContentPartContext\";\nimport { useMessageContext } from \"../react/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 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 // if the content part is the same, don't update\n const currentState = useContentPart.getState();\n if (currentState.part === part && currentState.status === status) return;\n\n // sync useContentPart\n (useContentPart as unknown as StoreApi<ContentPartState>).setState(\n Object.freeze({\n part,\n status,\n }),\n );\n};\n\nconst useContentPartContext = (partIndex: number) => {\n const { useMessage } = useMessageContext();\n const [context] = useState<ContentPartContextValue>(() => {\n const useContentPart = create<ContentPartState>(\n () => ({}) as ContentPartState,\n );\n\n syncContentPart(useMessage.getState(), useContentPart, partIndex);\n\n return { useContentPart };\n });\n\n useEffect(() => {\n syncContentPart(useMessage.getState(), context.useContentPart, partIndex);\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 { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport { useContentPartText } from \"../../primitive-hooks/contentPart/useContentPartText\";\nimport { useSmooth } from \"../../utils/hooks/useSmooth\";\n\ntype ContentPartPrimitiveTextElement = ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.span>;\n\nexport type ContentPartPrimitiveTextProps = Omit<\n PrimitiveSpanProps,\n \"children\"\n> & { smooth?: boolean };\n\nexport const ContentPartPrimitiveText = forwardRef<\n ContentPartPrimitiveTextElement,\n ContentPartPrimitiveTextProps\n>(({ smooth = true, ...rest }, forwardedRef) => {\n const {\n status,\n part: { text },\n } = useContentPartText();\n const smoothText = useSmooth(text, smooth);\n\n return (\n <Primitive.span data-status={status} {...rest} ref={forwardedRef}>\n {smoothText}\n </Primitive.span>\n );\n});\n\nContentPartPrimitiveText.displayName = \"ContentPartPrimitive.Text\";\n","import { useEffect, useState } from \"react\";\n\nclass TextStreamAnimator {\n private animationFrameId: number | null = null;\n private lastUpdateTime: number = Date.now();\n\n public targetText: string = \"\";\n\n constructor(\n private setText: (callback: (prevText: string) => string) => void,\n ) {}\n\n start() {\n if (this.animationFrameId !== null) return;\n this.lastUpdateTime = Date.now();\n this.animate();\n }\n\n stop() {\n if (this.animationFrameId !== null) {\n cancelAnimationFrame(this.animationFrameId);\n this.animationFrameId = null;\n }\n }\n\n private animate = () => {\n const currentTime = Date.now();\n const deltaTime = currentTime - this.lastUpdateTime;\n let timeToConsume = deltaTime;\n\n this.setText((currentText) => {\n const targetText = this.targetText;\n\n if (currentText === targetText) {\n this.animationFrameId = null;\n return currentText;\n }\n\n const remainingChars = targetText.length - currentText.length;\n const baseTimePerChar = Math.min(5, 250 / remainingChars);\n\n let charsToAdd = 0;\n while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {\n charsToAdd++;\n timeToConsume -= baseTimePerChar;\n }\n\n this.animationFrameId = requestAnimationFrame(this.animate);\n\n if (charsToAdd === 0) {\n return currentText;\n }\n\n const newText = targetText.slice(0, currentText.length + charsToAdd);\n this.lastUpdateTime = currentTime - timeToConsume;\n return newText;\n });\n };\n}\n\nexport const useSmooth = (text: string, smooth: boolean = false) => {\n const [displayedText, setDisplayedText] = useState(text);\n const [animatorRef] = useState<TextStreamAnimator>(\n new TextStreamAnimator(setDisplayedText),\n );\n\n useEffect(() => {\n console.log(\"smooth\", smooth);\n if (!smooth) {\n animatorRef.stop();\n return;\n }\n\n if (!text.startsWith(animatorRef.targetText)) {\n setDisplayedText(text);\n animatorRef.targetText = text;\n animatorRef.stop();\n return;\n }\n\n animatorRef.targetText = text;\n animatorRef.start();\n console.log(\"animating\");\n }, [animatorRef, smooth, text]);\n\n useEffect(() => {\n return () => {\n animatorRef.stop();\n };\n }, [animatorRef]);\n\n return smooth ? displayedText : text;\n};\n","import { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport { useContentPartImage } from \"../../primitive-hooks/contentPart/useContentPartImage\";\n\ntype ContentPartPrimitiveImageElement = ElementRef<typeof Primitive.img>;\ntype PrimitiveImageProps = ComponentPropsWithoutRef<typeof Primitive.img>;\n\nexport type ContentPartPrimitiveImageProps = PrimitiveImageProps;\n\nexport const ContentPartPrimitiveImage = forwardRef<\n ContentPartPrimitiveImageElement,\n ContentPartPrimitiveImageProps\n>((props, forwardedRef) => {\n const {\n part: { image },\n } = useContentPartImage();\n return <Primitive.img src={image} {...props} ref={forwardedRef} />;\n});\n\nContentPartPrimitiveImage.displayName = \"ContentPartPrimitive.Image\";\n","import type { FC } from \"react\";\nimport { useContentPartDisplay } from \"../../primitive-hooks/contentPart/useContentPartDisplay\";\n\nexport type ContentPartPrimitiveDisplayProps = {};\n\nexport const ContentPartPrimitiveDisplay: FC<\n ContentPartPrimitiveDisplayProps\n> = () => {\n const {\n part: { display },\n } = useContentPartDisplay();\n return display ?? null;\n};\n\nContentPartPrimitiveDisplay.displayName = \"ContentPartPrimitive.Display\";\n","import { FC, PropsWithChildren } from \"react\";\nimport { useContentPartContext } from \"../../context\";\n\nexport type ContentPartPrimitiveInProgressProps = PropsWithChildren;\n\nexport const ContentPartPrimitiveInProgress: FC<ContentPartPrimitiveInProgressProps> = ({\n children,\n}) => {\n const { useContentPart } = useContentPartContext();\n const isInProgress = useContentPart((c) => c.status === \"in_progress\");\n\n return isInProgress ? children : null;\n};\n\nContentPartPrimitiveInProgress.displayName = \"ContentPartPrimitive.InProgress\";\n","\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { ComponentPropsWithoutRef, FC } from \"react\";\n\ntype PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.span>;\n\nexport type MessagePrimitiveInProgressProps = PrimitiveSpanProps;\n\n/**\n * @deprecated Define a custom Text renderer via ContentPartPrimitiveInProgress instead.\n */\nexport const MessagePrimitiveInProgress: FC<\n MessagePrimitiveInProgressProps\n> = () => {\n return null;\n};\n\nMessagePrimitiveInProgress.displayName = \"MessagePrimitive.InProgress\";\n","export { ComposerPrimitiveRoot as Root } from \"./ComposerRoot\";\nexport { ComposerPrimitiveInput as Input } from \"./ComposerInput\";\nexport { ComposerPrimitiveSend as Send } from \"./ComposerSend\";\nexport { ComposerPrimitiveCancel as Cancel } from \"./ComposerCancel\";\nexport { ComposerPrimitiveIf as If } from \"./ComposerIf\";\n","\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ElementRef,\n type FormEvent,\n forwardRef,\n ComponentPropsWithoutRef,\n} from \"react\";\nimport { useComposerSend } from \"../../primitive-hooks\";\n\ntype ComposerPrimitiveRootElement = ElementRef<typeof Primitive.form>;\ntype PrimitiveFormProps = ComponentPropsWithoutRef<typeof Primitive.form>;\n\nexport type ComposerPrimitiveRootProps = PrimitiveFormProps;\n\nexport const ComposerPrimitiveRoot = forwardRef<\n ComposerPrimitiveRootElement,\n ComposerPrimitiveRootProps\n>(({ onSubmit, ...rest }, forwardedRef) => {\n const send = useComposerSend();\n\n const handleSubmit = (e: FormEvent) => {\n e.preventDefault();\n\n if (!send) return;\n send();\n };\n\n return (\n <Primitive.form\n {...rest}\n ref={forwardedRef}\n onSubmit={composeEventHandlers(onSubmit, handleSubmit)}\n />\n );\n});\n\nComposerPrimitiveRoot.displayName = \"ComposerPrimitive.Root\";\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/react/ComposerContext\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useEscapeKeydown } from \"@radix-ui/react-use-escape-keydown\";\nimport { useOnComposerFocus } from \"../../utils/hooks/useOnComposerFocus\";\n\nexport type ComposerPrimitiveInputProps = TextareaAutosizeProps & {\n asChild?: boolean | undefined;\n};\n\nexport const ComposerPrimitiveInput = forwardRef<\n HTMLTextAreaElement,\n ComposerPrimitiveInputProps\n>(\n (\n { autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest },\n forwardedRef,\n ) => {\n const { useThread } = 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 textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n\n useEscapeKeydown((e) => {\n const composer = useComposer.getState();\n if (composer.canCancel) {\n composer.cancel();\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (disabled) return;\n\n if (e.key === \"Enter\" && e.shiftKey === false) {\n const isRunning = useThread.getState().isRunning;\n if (!isRunning) {\n e.preventDefault();\n\n textareaRef.current?.closest(\"form\")?.requestSubmit();\n }\n }\n };\n\n const autoFocusEnabled = autoFocus && !disabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus({ preventScroll: true });\n textarea.setSelectionRange(\n textareaRef.current.value.length,\n textareaRef.current.value.length,\n );\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnComposerFocus(() => {\n if (type === \"new\") {\n focus();\n }\n });\n\n return (\n <Component\n name=\"input\"\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\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n","\"use client\";\n\nimport { ComponentPropsWithoutRef, ElementRef, forwardRef } from \"react\";\nimport { useComposerContext } from \"../../context\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\n\ntype ComposerPrimitiveSendElement = ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = ComponentPropsWithoutRef<typeof Primitive.button>;\n\nexport type ComposerPrimitiveSendProps = PrimitiveButtonProps;\n\nexport const ComposerPrimitiveSend = forwardRef<\n ComposerPrimitiveSendElement,\n ComposerPrimitiveSendProps\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\nComposerPrimitiveSend.displayName = \"ComposerPrimitive.Send\";\n","\"use client\";\n\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useComposerCancel } from \"../../primitive-hooks/composer/useComposerCancel\";\n\nexport type ComposerPrimitiveCancelProps = ActionButtonProps<\n typeof useComposerCancel\n>;\n\nexport const ComposerPrimitiveCancel = createActionButton(\n \"ComposerPrimitive.Cancel\",\n useComposerCancel,\n);\n","\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport {\n UseComposerIfProps,\n useComposerIf,\n} from \"../../primitive-hooks/composer/useComposerIf\";\n\nexport type ComposerPrimitiveIfProps = PropsWithChildren<UseComposerIfProps>;\n\nexport const ComposerPrimitiveIf: FC<ComposerPrimitiveIfProps> = ({\n children,\n ...query\n}) => {\n const result = useComposerIf(query);\n return result ? children : null;\n};\n\nComposerPrimitiveIf.displayName = \"ComposerPrimitive.If\";\n","export { ContentPartPrimitiveText as Text } from \"./ContentPartText\";\nexport { ContentPartPrimitiveImage as Image } from \"./ContentPartImage\";\nexport { ContentPartPrimitiveDisplay as Display } from \"./ContentPartDisplay\";\nexport { ContentPartPrimitiveInProgress as InProgress } from \"./ContentPartInProgress\";\n","export { ThreadPrimitiveRoot as Root } from \"./ThreadRoot\";\nexport { ThreadPrimitiveEmpty as Empty } from \"./ThreadEmpty\";\nexport { ThreadPrimitiveIf as If } from \"./ThreadIf\";\nexport { ThreadPrimitiveViewport as Viewport } from \"./ThreadViewport\";\nexport { ThreadPrimitiveMessages as Messages } from \"./ThreadMessages\";\nexport { ThreadPrimitiveScrollToBottom as ScrollToBottom } from \"./ThreadScrollToBottom\";\nexport { ThreadPrimitiveSuggestion as Suggestion } from \"./ThreadSuggestion\";\n","\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\n\ntype ThreadPrimitiveRootElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type ThreadPrimitiveRootProps = PrimitiveDivProps;\n\nexport const ThreadPrimitiveRoot = forwardRef<\n ThreadPrimitiveRootElement,\n ThreadPrimitiveRootProps\n>((props, ref) => {\n return <Primitive.div {...props} ref={ref} />;\n});\n\nThreadPrimitiveRoot.displayName = \"ThreadPrimitive.Root\";\n","\"use client\";\n\nimport type { FC, ReactNode } from \"react\";\nimport { useThreadEmpty } from \"../../primitive-hooks\";\n\nexport type ThreadPrimitiveEmptyProps = {\n children: ReactNode;\n};\n\nexport const ThreadPrimitiveEmpty: FC<ThreadPrimitiveEmptyProps> = ({\n children,\n}) => {\n const empty = useThreadEmpty();\n return empty ? children : null;\n};\n\nThreadPrimitiveEmpty.displayName = \"ThreadPrimitive.Empty\";\n","\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport {\n UseThreadIfProps,\n useThreadIf,\n} from \"../../primitive-hooks/thread/useThreadIf\";\n\nexport type ThreadPrimitiveIfProps = PropsWithChildren<UseThreadIfProps>;\n\nexport const ThreadPrimitiveIf: FC<ThreadPrimitiveIfProps> = ({\n children,\n ...query\n}) => {\n const result = useThreadIf(query);\n return result ? children : null;\n};\n\nThreadPrimitiveIf.displayName = \"ThreadPrimitive.If\";\n","\"use client\";\n\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { type ElementRef, forwardRef, ComponentPropsWithoutRef } from \"react\";\nimport {\n UseThreadViewportAutoScrollProps,\n useThreadViewportAutoScroll,\n} from \"../../primitive-hooks/thread/useThreadViewportAutoScroll\";\n\ntype ThreadPrimitiveViewportElement = ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;\n\nexport type ThreadPrimitiveViewportProps = PrimitiveDivProps &\n UseThreadViewportAutoScrollProps;\n\nexport const ThreadPrimitiveViewport = forwardRef<\n ThreadPrimitiveViewportElement,\n ThreadPrimitiveViewportProps\n>(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {\n const autoScrollRef = useThreadViewportAutoScroll<HTMLDivElement>({\n autoScroll,\n });\n\n const ref = useComposedRefs(forwardedRef, autoScrollRef);\n\n return (\n <Primitive.div {...rest} ref={ref}>\n {children}\n </Primitive.div>\n );\n});\n\nThreadPrimitiveViewport.displayName = \"ThreadPrimitive.Viewport\";\n","\"use client\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { useRef } from \"react\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { useOnResizeContent } from \"../../utils/hooks/useOnResizeContent\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { StoreApi } from \"zustand\";\nimport { ThreadViewportState } from \"../../context\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\n\nexport type UseThreadViewportAutoScrollProps = {\n autoScroll?: boolean | undefined;\n};\n\nexport const useThreadViewportAutoScroll = <TElement extends HTMLElement>({\n autoScroll = true,\n}: UseThreadViewportAutoScrollProps) => {\n const divRef = useRef<TElement>(null);\n\n const { useViewport } = useThreadContext();\n\n const firstRenderRef = useRef(true);\n const lastScrollTop = useRef<number>(0);\n\n // bug: when ScrollToBottom's button changes its disabled state, the scroll stops\n // fix: delay the state change until the scroll is done\n const isScrollingToBottomRef = useRef(false);\n\n const scrollToBottom = () => {\n const div = divRef.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.scrollTo({ top: div.scrollHeight, behavior });\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 {\n isScrollingToBottomRef.current = newIsAtBottom;\n\n if (newIsAtBottom !== isAtBottom) {\n (useViewport as unknown as StoreApi<ThreadViewportState>).setState({\n isAtBottom: newIsAtBottom,\n });\n }\n }\n\n lastScrollTop.current = div.scrollTop;\n };\n\n const resizeRef = useOnResizeContent(() => {\n if (\n !isScrollingToBottomRef.current &&\n !useViewport.getState().isAtBottom &&\n !firstRenderRef.current\n ) {\n handleScroll();\n } else {\n scrollToBottom();\n }\n });\n\n const scrollRef = useManagedRef<HTMLElement>((el) => {\n el.addEventListener(\"scroll\", handleScroll);\n return () => {\n el.removeEventListener(\"scroll\", handleScroll);\n };\n });\n\n const autoScrollRef = useComposedRefs<TElement>(resizeRef, scrollRef, divRef);\n\n useOnScrollToBottom(() => {\n scrollToBottom();\n });\n\n return autoScrollRef;\n};\n","import { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useCallback } from \"react\";\nimport { useManagedRef } from \"./useManagedRef\";\n\nexport const useOnResizeContent = (callback: () => void) => {\n const callbackRef = useCallbackRef(callback);\n\n const refCallback = useCallback(\n (el: HTMLElement) => {\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 },\n [callbackRef],\n );\n\n return useManagedRef(refCallback);\n};\n","import { useCallbackRef } from \"@radix-ui/react-use-callback-ref\";\nimport { useEffect } from \"react\";\nimport { useThreadContext } from \"../../context/react/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 ComponentType, type FC, memo } from \"react\";\nimport { useThreadContext } from \"../../context/react/ThreadContext\";\nimport { MessageProvider } from \"../../context/providers/MessageProvider\";\nimport { ComposerPrimitiveIf } from \"../composer/ComposerIf\";\nimport { MessagePrimitiveIf } from \"../message/MessageIf\";\n\nexport type ThreadPrimitiveMessagesProps = {\n components:\n | {\n Message: ComponentType;\n UserMessage?: ComponentType | undefined;\n EditComposer?: ComponentType | undefined;\n AssistantMessage?: ComponentType | undefined;\n }\n | {\n Message?: ComponentType | undefined;\n UserMessage: ComponentType;\n EditComposer?: ComponentType | undefined;\n AssistantMessage: ComponentType;\n };\n};\n\nconst getComponents = (\n components: ThreadPrimitiveMessagesProps[\"components\"],\n) => {\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\ntype ThreadMessageProps = {\n messageIndex: number;\n components: ThreadPrimitiveMessagesProps[\"components\"];\n};\n\nconst ThreadMessageImpl: FC<ThreadMessageProps> = ({\n messageIndex,\n components,\n}) => {\n const { UserMessage, EditComposer, AssistantMessage } =\n getComponents(components);\n return (\n <MessageProvider messageIndex={messageIndex}>\n <MessagePrimitiveIf user>\n <ComposerPrimitiveIf editing={false}>\n <UserMessage />\n </ComposerPrimitiveIf>\n <ComposerPrimitiveIf editing>\n <EditComposer />\n </ComposerPrimitiveIf>\n </MessagePrimitiveIf>\n <MessagePrimitiveIf assistant>\n <AssistantMessage />\n </MessagePrimitiveIf>\n </MessageProvider>\n );\n};\n\nconst ThreadMessage = memo(\n ThreadMessageImpl,\n (prev, next) =>\n prev.messageIndex === next.messageIndex &&\n prev.components.Message === next.components.Message &&\n prev.components.UserMessage === next.components.UserMessage &&\n prev.components.EditComposer === next.components.EditComposer &&\n prev.components.AssistantMessage === next.components.AssistantMessage,\n);\n\nexport const ThreadPrimitiveMessagesImpl: FC<ThreadPrimitiveMessagesProps> = ({\n components,\n}) => {\n const { useThreadMessages } = useThreadContext();\n\n const messagesLength = useThreadMessages((t) => t.length);\n if (messagesLength === 0) return null;\n\n return new Array(messagesLength).fill(null).map((_, idx) => {\n const messageIndex = idx; // keep the same key when switching branches for better a11y support\n return (\n <ThreadMessage\n key={messageIndex}\n messageIndex={messageIndex}\n components={components}\n />\n );\n });\n};\n\nThreadPrimitiveMessagesImpl.displayName = \"ThreadPrimitive.Messages\";\n\nexport const ThreadPrimitiveMessages = memo(\n ThreadPrimitiveMessagesImpl,\n (prev, next) =>\n prev.components?.Message === next.components?.Message &&\n prev.components?.UserMessage === next.components?.UserMessage &&\n prev.components?.EditComposer === next.components?.EditComposer &&\n prev.components?.AssistantMessage === next.components?.AssistantMessage,\n);\n","\"use client\";\n\nimport { type FC, type PropsWithChildren, useEffect, useState } from \"react\";\nimport { StoreApi, create } from \"zustand\";\nimport type {\n AppendContentPart,\n ThreadMessage,\n} from \"../../types/AssistantTypes\";\nimport { getMessageText } from \"../../utils/getMessageText\";\nimport { MessageContext } from \"../react/MessageContext\";\nimport type { MessageContextValue } from \"../react/MessageContext\";\nimport { useThreadContext } from \"../react/ThreadContext\";\nimport type { MessageState } from \"../stores/Message\";\nimport { makeEditComposerStore } from \"../stores/EditComposer\";\nimport { makeMessageUtilsStore } from \"../stores/MessageUtils\";\nimport { ThreadMessagesState } from \"../stores/ThreadMessages\";\n\ntype MessageProviderProps = PropsWithChildren<{\n messageIndex: number;\n}>;\n\nconst getIsLast = (messages: ThreadMessagesState, message: ThreadMessage) => {\n return messages[messages.length - 1]?.id === message.id;\n};\n\nconst syncMessage = (\n messages: ThreadMessagesState,\n getBranches: (messageId: string) => readonly string[],\n useMessage: MessageContextValue[\"useMessage\"],\n messageIndex: number,\n) => {\n const parentId = messages[messageIndex - 1]?.id ?? null;\n const message = messages[messageIndex];\n if (!message) return;\n\n const isLast = getIsLast(messages, message);\n const branches = 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 as unknown as StoreApi<MessageState>).setState({\n message,\n parentId,\n branches,\n isLast,\n });\n};\n\nconst useMessageContext = (messageIndex: number) => {\n const { useThreadMessages, useThreadActions } = useThreadContext();\n\n const [context] = useState<MessageContextValue>(() => {\n const useMessage = create<MessageState>(() => ({}) as MessageState);\n const useMessageUtils = makeMessageUtilsStore();\n const useEditComposer = 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 useThreadActions.getState().append({\n parentId,\n role: \"user\",\n content: [{ type: \"text\", text }, ...nonTextParts],\n });\n },\n });\n\n syncMessage(\n useThreadMessages.getState(),\n useThreadActions.getState().getBranches,\n useMessage,\n messageIndex,\n );\n\n return { useMessage, useMessageUtils, useEditComposer };\n });\n\n useEffect(() => {\n return useThreadMessages.subscribe((thread) => {\n syncMessage(\n thread,\n useThreadActions.getState().getBranches,\n context.useMessage,\n messageIndex,\n );\n });\n }, [useThreadMessages, useThreadActions, context, 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 { create } from \"zustand\";\nimport { type BaseComposerState, makeBaseComposer } from \"./BaseComposer\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\n\nexport type EditComposerState = BaseComposerState &\n Readonly<{\n canCancel: boolean;\n isEditing: boolean;\n\n edit: () => void;\n send: () => void;\n cancel: () => void;\n }>;\n\nexport const makeEditComposerStore = ({\n onEdit,\n onSend,\n}: {\n onEdit: () => string;\n onSend: (value: string) => void;\n}): ReadonlyStore<EditComposerState> =>\n create<EditComposerState>()((set, get, store) => ({\n ...makeBaseComposer(set, get, store),\n\n canCancel: false,\n isEditing: false,\n\n edit: () => {\n const value = onEdit();\n set({ isEditing: true, canCancel: true, value });\n },\n send: () => {\n const value = get().value;\n set({ isEditing: false, canCancel: false });\n onSend(value);\n },\n cancel: () => {\n set({ isEditing: false, canCancel: false });\n },\n }));\n","import { create } from \"zustand\";\n\nexport type MessageUtilsState = Readonly<{\n isCopied: boolean;\n setIsCopied: (value: boolean) => void;\n isHovering: boolean;\n setIsHovering: (value: boolean) => void;\n}>;\n\nexport const makeMessageUtilsStore = () =>\n create<MessageUtilsState>((set) => ({\n isCopied: false,\n setIsCopied: (value) => {\n set({ isCopied: value });\n },\n isHovering: false,\n setIsHovering: (value) => {\n set({ isHovering: value });\n },\n }));\n","\"use client\";\n\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useThreadScrollToBottom } from \"../../primitive-hooks/thread/useThreadScrollToBottom\";\n\nexport type ThreadPrimitiveScrollToBottomProps = ActionButtonProps<\n typeof useThreadScrollToBottom\n>;\n\nexport const ThreadPrimitiveScrollToBottom = createActionButton(\n \"ThreadPrimitive.ScrollToBottom\",\n useThreadScrollToBottom,\n);\n","\"use client\";\n\nimport {\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useThreadSuggestion } from \"../../primitive-hooks/thread/useThreadSuggestion\";\n\nexport type ThreadPrimitiveSuggestionProps = ActionButtonProps<\n typeof useThreadSuggestion\n>;\n\nexport const ThreadPrimitiveSuggestion = createActionButton(\n \"ThreadPrimitive.Suggestion\",\n useThreadSuggestion,\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 { 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","import type { ThreadMessage } from \"../../types/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 { AppendMessage } from \"../../types/AssistantTypes\";\nimport { type ModelConfigProvider } from \"../../types/ModelConfigTypes\";\nimport type { Unsubscribe } from \"../../types/Unsubscribe\";\nimport type { AssistantRuntime } from \"./AssistantRuntime\";\nimport { ReactThreadRuntime } from \"./ReactThreadRuntime\";\n\nexport abstract class BaseAssistantRuntime<\n TThreadRuntime extends ReactThreadRuntime,\n> implements AssistantRuntime\n{\n public get capabilities() {\n return this._thread.capabilities;\n }\n\n constructor(private _thread: TThreadRuntime) {\n this._thread = _thread;\n this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);\n }\n\n private _unsubscribe: Unsubscribe;\n\n get thread() {\n return this._thread;\n }\n\n set thread(thread: TThreadRuntime) {\n this._unsubscribe();\n this._thread = thread;\n this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);\n this.subscriptionHandler();\n }\n\n public abstract registerModelConfigProvider(\n provider: ModelConfigProvider,\n ): Unsubscribe;\n public abstract switchToThread(threadId: string | null): void;\n\n public get messages() {\n return this.thread.messages;\n }\n\n public get isRunning() {\n return this.thread.isRunning;\n }\n\n public getBranches(messageId: string): readonly string[] {\n return this.thread.getBranches(messageId);\n }\n\n public switchToBranch(branchId: string): void {\n return this.thread.switchToBranch(branchId);\n }\n\n public append(message: AppendMessage): void {\n return this.thread.append(message);\n }\n\n public startRun(parentId: string | null): void {\n return this.thread.startRun(parentId);\n }\n\n public cancelRun(): void {\n return this.thread.cancelRun();\n }\n\n public addToolResult(toolCallId: string, result: any) {\n return this.thread.addToolResult(toolCallId, result);\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private subscriptionHandler = () => {\n for (const callback of this._subscriptions) callback();\n };\n\n public get unstable_synchronizer() {\n return this.thread.unstable_synchronizer;\n }\n}\n","import type {\n AppendMessage,\n AssistantMessage,\n UserMessage,\n} from \"../../types/AssistantTypes\";\nimport {\n type ModelConfigProvider,\n mergeModelConfigs,\n} from \"../../types/ModelConfigTypes\";\nimport type { Unsubscribe } from \"../../types/Unsubscribe\";\nimport { ThreadRuntime } from \"../core\";\nimport { MessageRepository } from \"../utils/MessageRepository\";\nimport { generateId } from \"../utils/idUtils\";\nimport { BaseAssistantRuntime } from \"../core/BaseAssistantRuntime\";\nimport type { ChatModelAdapter, ChatModelRunResult } from \"./ChatModelAdapter\";\n\nexport class LocalRuntime extends BaseAssistantRuntime<LocalThreadRuntime> {\n private readonly _configProviders: Set<ModelConfigProvider>;\n\n constructor(adapter: ChatModelAdapter) {\n const configProviders = new Set<ModelConfigProvider>();\n super(new LocalThreadRuntime(configProviders, adapter));\n this._configProviders = configProviders;\n }\n\n public set adapter(adapter: ChatModelAdapter) {\n this.thread.adapter = adapter;\n }\n\n registerModelConfigProvider(provider: ModelConfigProvider) {\n this._configProviders.add(provider);\n return () => this._configProviders.delete(provider);\n }\n\n public switchToThread(threadId: string | null) {\n if (threadId) {\n throw new Error(\"LocalRuntime does not yet support switching threads\");\n }\n\n return (this.thread = new LocalThreadRuntime(\n this._configProviders,\n this.thread.adapter,\n ));\n }\n}\n\nconst CAPABILITIES = Object.freeze({\n edit: true,\n reload: true,\n cancel: true,\n copy: true,\n});\n\nclass LocalThreadRuntime implements ThreadRuntime {\n private _subscriptions = new Set<() => void>();\n\n private abortController: AbortController | null = null;\n private readonly repository = new MessageRepository();\n\n public readonly capabilities = CAPABILITIES;\n\n public get messages() {\n return this.repository.getMessages();\n }\n public get isRunning() {\n return this.abortController != null;\n }\n\n constructor(\n private _configProviders: Set<ModelConfigProvider>,\n public adapter: ChatModelAdapter,\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.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 config: mergeModelConfigs(this._configProviders),\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 addToolResult() {\n throw new Error(\"LocalRuntime does not yet support adding tool results\");\n }\n}\n","export { ProxyConfigProvider } from \"./utils/ProxyConfigProvider\";\nexport { MessageRepository } from \"./runtime/utils/MessageRepository\";\nexport { BaseAssistantRuntime } from \"./runtime/core/BaseAssistantRuntime\";\nexport { useSmooth } from \"./utils/hooks/useSmooth\";\n"],"mappings":";;;;;;;AACA,SAAS,YAAY;;;ACArB,SAAS,aAAAA,YAAW,sBAAAC,qBAAoB,UAAAC,SAAQ,YAAAC,iBAAgB;;;ACDhE,SAAS,eAAe,kBAAkB;AAYnC,IAAM,mBAAmB;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB,MAA6B;AAC9D,QAAM,UAAU,WAAW,gBAAgB;AAC3C,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;;;ACrBA,SAAS,cAAc;;;ACkBhB,IAAM,oBAAoB,CAC/B,cACgB;AAChB,QAAM,UAAU,MAAM,KAAK,SAAS,EACjC,IAAI,CAAC,MAAM,EAAE,CAAC,EACd,KAAK,CAAC,GAAG,OAAO,EAAE,YAAY,MAAM,EAAE,YAAY,EAAE;AAEvD,SAAO,QAAQ,OAAO,CAAC,KAAK,WAAW;AACrC,QAAI,OAAO,QAAQ;AACjB,UAAI,IAAI,QAAQ;AAEd,YAAI,UAAU;AAAA;AAAA,EAAO,OAAO,MAAM;AAAA,MACpC,OAAO;AACL,YAAI,SAAS,OAAO;AAAA,MACtB;AAAA,IACF;AACA,QAAI,OAAO,OAAO;AAChB,iBAAW,CAAC,MAAM,IAAI,KAAK,OAAO,Q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,SAAS;AACjB,WAAK,WAAW,mBAAmB,UAAU,EAAE,GAAG,QAAQ,CAAC;AAC3D,cAAQ,MAAM,CAAC;AAAA,IACjB,UAAE;AACA,WAAK,kBAAkB;AACvB,WAAK,kBAAkB;AAAA,IACzB;AAAA,EACF;AAAA,EAEA,YAAkB;AAChB,QAAI,CAAC,KAAK,gBAAiB;AAE3B,SAAK,gBAAgB,MAAM;AAC3B,SAAK,kBAAkB;AACvB,SAAK,kBAAkB;AAAA,EACzB;AAAA,EAEQ,oBAAoB;AAC1B,eAAW,YAAY,KAAK,eAAgB,UAAS;AAAA,EACvD;AAAA,EAEO,UAAU,UAAmC;AAClD,SAAK,eAAe,IAAI,QAAQ;AAChC,WAAO,MAAM,KAAK,eAAe,OAAO,QAAQ;AAAA,EAClD;AAAA,EAEA,gBAAgB;AACd,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACF;;;AJ9JO,IAAM,kBAAkB,CAAC,YAA8B;AAC5D,QAAM,CAAC,OAAO,IAAIC,UAAS,MAAM,IAAI,aAAa,OAAO,CAAC;AAE1D,EAAAC,oBAAmB,MAAM;AACvB,YAAQ,UAAU;AAAA,EACpB,CAAC;AAED,SAAO;AACT;;;AKdA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":["useEffect","useInsertionEffect","useRef","useState","create","createContext","useContext","create","create","create","create","create","create","create","jsx","useRef","useInsertionEffect","useState","useEffect","jsx","useContext","createContext","useContext","useContext","createContext","useContext","useCallback","useCallback","useCallback","useCallback","useEffect","useEffect","useEffect","useEffect","useEffect","useEffect","useCallback","useMemo","useSyncExternalStore","useMemo","c","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","jsx","Primitive","forwardRef","jsx","useState","PopoverPrimitive","composeEventHandlers","useEffect","useEffect","jsx","useState","composeEventHandlers","forwardRef","PopoverPrimitive","jsx","forwardRef","forwardRef","PopoverPrimitive","composeEventHandlers","jsx","forwardRef","forwardRef","PopoverPrimitive","jsx","forwardRef","jsx","Fragment","jsx","Primitive","forwardRef","Primitive","forwardRef","useCallback","useCallback","useRef","jsx","useCallback","forwardRef","Primitive","memo","useEffect","useState","create","jsx","useContentPartContext","useState","create","useEffect","Primitive","forwardRef","useEffect","useState","jsx","forwardRef","Primitive","Primitive","forwardRef","jsx","forwardRef","Primitive","jsx","jsxs","memo","jsx","forwardRef","Primitive","composeEventHandlers","Primitive","forwardRef","jsx","forwardRef","Primitive","composeEventHandlers","composeEventHandlers","useComposedRefs","forwardRef","useCallback","useEffect","useRef","jsx","forwardRef","useRef","useComposedRefs","useCallback","useEffect","composeEventHandlers","forwardRef","Primitive","jsx","forwardRef","Primitive","forwardRef","jsx","useComposedRefs","Primitive","forwardRef","useComposedRefs","useRef","useCallbackRef","useCallback","useCallbackRef","useCallback","useCallbackRef","useEffect","useCallbackRef","useEffect","useRef","useComposedRefs","jsx","forwardRef","useComposedRefs","Primitive","memo","useEffect","useState","create","create","create","create","jsx","useMessageContext","useState","create","useEffect","jsx","jsxs","memo","useInsertionEffect","useState","useState","useInsertionEffect"]}