@harnessio/ai-chat-core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/LICENSE +201 -0
  2. package/dist/core/PluginRegistry.d.ts +12 -0
  3. package/dist/core/index.d.ts +1 -0
  4. package/dist/index.d.ts +5 -0
  5. package/dist/index.js +1051 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/react/hooks/index.d.ts +7 -0
  8. package/dist/react/hooks/useAssistantRuntime.d.ts +2 -0
  9. package/dist/react/hooks/useComposer.d.ts +3 -0
  10. package/dist/react/hooks/useContentFocus.d.ts +17 -0
  11. package/dist/react/hooks/useContentRenderer.d.ts +16 -0
  12. package/dist/react/hooks/useCurrentThread.d.ts +2 -0
  13. package/dist/react/hooks/useMessages.d.ts +2 -0
  14. package/dist/react/hooks/useThreadList.d.ts +9 -0
  15. package/dist/react/index.d.ts +2 -0
  16. package/dist/react/providers/AssistantRuntimeProvider.d.ts +8 -0
  17. package/dist/react/providers/index.d.ts +1 -0
  18. package/dist/runtime/AssistantRuntime/AssistantRuntime.d.ts +33 -0
  19. package/dist/runtime/ComposerRuntime/ComposerRuntime.d.ts +16 -0
  20. package/dist/runtime/ContentFocusRuntime/ContentFocusRuntime.d.ts +27 -0
  21. package/dist/runtime/ThreadListItemRuntime/ThreadListItemRuntime.d.ts +20 -0
  22. package/dist/runtime/ThreadListRuntime/ThreadListRuntime.d.ts +35 -0
  23. package/dist/runtime/ThreadRuntime/ThreadRuntime.d.ts +21 -0
  24. package/dist/runtime/ThreadRuntime/ThreadRuntimeCore.d.ts +32 -0
  25. package/dist/runtime/index.d.ts +10 -0
  26. package/dist/types/adapters.d.ts +48 -0
  27. package/dist/types/index.d.ts +5 -0
  28. package/dist/types/message.d.ts +56 -0
  29. package/dist/types/plugin.d.ts +55 -0
  30. package/dist/types/thread.d.ts +31 -0
  31. package/dist/utils/BaseSSEStreamAdapter.d.ts +25 -0
  32. package/dist/utils/Subscribable.d.ts +7 -0
  33. package/dist/utils/groupContentByParentId.d.ts +9 -0
  34. package/dist/utils/idGenerator.d.ts +3 -0
  35. package/dist/utils/index.d.ts +4 -0
  36. package/package.json +57 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/core/PluginRegistry.ts","../src/utils/Subscribable.ts","../src/runtime/ContentFocusRuntime/ContentFocusRuntime.ts","../src/utils/idGenerator.ts","../src/runtime/ThreadListItemRuntime/ThreadListItemRuntime.ts","../src/runtime/ComposerRuntime/ComposerRuntime.ts","../src/runtime/ThreadRuntime/ThreadRuntime.ts","../src/runtime/ThreadRuntime/ThreadRuntimeCore.ts","../src/runtime/ThreadListRuntime/ThreadListRuntime.tsx","../src/runtime/AssistantRuntime/AssistantRuntime.tsx","../../../node_modules/.pnpm/object-assign@4.1.1/node_modules/object-assign/index.js","../../../node_modules/.pnpm/react@17.0.2/node_modules/react/cjs/react-jsx-runtime.production.min.js","../../../node_modules/.pnpm/react@17.0.2/node_modules/react/jsx-runtime.js","../src/react/providers/AssistantRuntimeProvider.tsx","../src/react/hooks/useAssistantRuntime.ts","../src/react/hooks/useThreadList.ts","../src/react/hooks/useCurrentThread.ts","../../../node_modules/.pnpm/use-sync-external-store@1.5.0_react@17.0.2/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js","../../../node_modules/.pnpm/use-sync-external-store@1.5.0_react@17.0.2/node_modules/use-sync-external-store/shim/index.js","../src/react/hooks/useMessages.ts","../src/react/hooks/useComposer.ts","../src/react/hooks/useContentRenderer.ts","../src/react/hooks/useContentFocus.ts","../src/utils/groupContentByParentId.ts","../src/utils/BaseSSEStreamAdapter.ts"],"sourcesContent":["import { ChatPlugin, MessageRenderer } from '../types/plugin'\n\nexport class PluginRegistry {\n private plugins = new Map<string, ChatPlugin>()\n private renderersByType = new Map<string, MessageRenderer[]>()\n\n public registerPlugin(plugin: ChatPlugin): void {\n if (this.plugins.has(plugin.id)) {\n // handle duplicate plugin registration\n // show a warning / error\n }\n\n this.plugins.set(plugin.id, plugin)\n\n plugin.renderers.forEach(renderer => {\n const renderers = this.renderersByType.get(renderer.type) || []\n renderers.push(renderer)\n renderers.sort((a, b) => (b?.priority ?? 0) - (a?.priority ?? 0))\n this.renderersByType.set(renderer.type, renderers)\n })\n }\n\n public unregisterPlugin(pluginId: string): boolean {\n const plugin = this.plugins.get(pluginId)\n if (!plugin) {\n return false\n }\n\n plugin.renderers.forEach(renderer => {\n const renderers = this.renderersByType.get(renderer.type) || []\n const filteredRenderers = renderers.filter(r => !plugin.renderers.includes(r))\n\n if (filteredRenderers.length === 0) {\n this.renderersByType.delete(renderer.type)\n } else {\n this.renderersByType.set(renderer.type, filteredRenderers)\n }\n })\n\n return this.plugins.delete(pluginId)\n }\n\n public getPlugin(pluginId: string): ChatPlugin | undefined {\n return this.plugins.get(pluginId)\n }\n\n public getAllPlugins(): ChatPlugin[] {\n return Array.from(this.plugins.values())\n }\n\n public getRenderersByType(type: string): MessageRenderer[] {\n return this.renderersByType.get(type) || []\n }\n\n public getBestRendererForType(type: string): MessageRenderer | undefined {\n const renderers = this.getRenderersByType(type)\n return renderers[0]\n }\n\n public clear(): void {\n this.plugins.clear()\n this.renderersByType.clear()\n }\n}\n","export type Unsubscribe = () => void\n\nexport abstract class BaseSubscribable {\n private _subscriptions = new Set<() => void>()\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback)\n return () => {\n this._subscriptions.delete(callback)\n }\n }\n\n protected notifySubscribers(): void {\n for (const callback of this._subscriptions) {\n callback()\n }\n }\n\n protected getSubscriberCount(): number {\n return this._subscriptions.size\n }\n}\n","import { Message, MessageContent } from '../../types/message'\nimport { BaseSubscribable } from '../../utils/Subscribable'\n\nexport type FocusContext = 'detail'\n\nexport interface ContentFocusState {\n isActive: boolean\n context: FocusContext | null\n focusedContent: MessageContent | null\n focusedMessage: Message | null\n focusedMessageId: string | null\n focusedContentIndex: number | null\n}\n\nexport class ContentFocusRuntime extends BaseSubscribable {\n private _state: ContentFocusState = {\n isActive: false,\n context: null,\n focusedContent: null,\n focusedMessage: null,\n focusedMessageId: null,\n focusedContentIndex: null\n }\n\n public get state(): ContentFocusState {\n return this._state\n }\n\n public get isActive(): boolean {\n return this._state.isActive\n }\n\n public get context(): FocusContext | null {\n return this._state.context\n }\n\n public get focusedContent(): MessageContent | null {\n return this._state.focusedContent\n }\n\n public get focusedMessage(): Message | null {\n return this._state.focusedMessage\n }\n\n public get focusedMessageId(): string | null {\n return this._state.focusedMessageId\n }\n\n public get focusedContentIndex(): number | null {\n return this._state.focusedContentIndex\n }\n\n public focus(\n content: MessageContent,\n message: Message,\n contentIndex: number,\n context: FocusContext = 'detail'\n ): void {\n this._state = {\n isActive: true,\n context,\n focusedContent: content,\n focusedMessage: message,\n focusedMessageId: message.id,\n focusedContentIndex: contentIndex\n }\n this.notifySubscribers()\n }\n\n public blur(): void {\n this._state = {\n isActive: false,\n context: null,\n focusedContent: null,\n focusedMessage: null,\n focusedMessageId: null,\n focusedContentIndex: null\n }\n this.notifySubscribers()\n }\n\n public toggle(\n content: MessageContent,\n message: Message,\n contentIndex: number,\n context: FocusContext = 'detail'\n ): void {\n if (\n this._state.isActive &&\n this._state.focusedMessageId === message.id &&\n this._state.focusedContentIndex === contentIndex &&\n this._state.context === context\n ) {\n this.blur()\n } else {\n this.focus(content, message, contentIndex, context)\n }\n }\n\n public switchContext(context: FocusContext): void {\n if (this._state.isActive && this._state.focusedContent) {\n this._state = {\n ...this._state,\n context\n }\n this.notifySubscribers()\n }\n }\n\n public focusNext(messages: readonly Message[]): void {\n if (!this._state.focusedMessageId || !messages.length) return\n\n const currentMsgIndex = messages.findIndex(m => m.id === this._state.focusedMessageId)\n if (currentMsgIndex === -1) return\n\n const currentMsg = messages[currentMsgIndex]\n const currentContentIndex = this._state.focusedContentIndex ?? 0\n\n if (currentContentIndex + 1 < currentMsg.content.length) {\n const nextContent = currentMsg.content[currentContentIndex + 1]\n this.focus(nextContent, currentMsg, currentContentIndex + 1, this._state.context || 'detail')\n return\n }\n\n // Try first content in next message\n if (currentMsgIndex + 1 < messages.length) {\n const nextMsg = messages[currentMsgIndex + 1]\n if (nextMsg.content.length > 0) {\n this.focus(nextMsg.content[0], nextMsg, 0, this._state.context || 'detail')\n }\n }\n }\n\n public focusPrevious(messages: readonly Message[]): void {\n if (!this._state.focusedMessageId || !messages.length) return\n\n const currentMsgIndex = messages.findIndex(m => m.id === this._state.focusedMessageId)\n if (currentMsgIndex === -1) return\n\n const currentMsg = messages[currentMsgIndex]\n const currentContentIndex = this._state.focusedContentIndex ?? 0\n\n if (currentContentIndex > 0) {\n const prevContent = currentMsg.content[currentContentIndex - 1]\n this.focus(prevContent, currentMsg, currentContentIndex - 1, this._state.context || 'detail')\n return\n }\n\n // Try last content in previous message\n if (currentMsgIndex > 0) {\n const prevMsg = messages[currentMsgIndex - 1]\n if (prevMsg.content.length > 0) {\n const lastIndex = prevMsg.content.length - 1\n this.focus(prevMsg.content[lastIndex], prevMsg, lastIndex, this._state.context || 'detail')\n }\n }\n }\n}\n","let messageIdCounter = 0\nlet threadIdCounter = 0\n\nexport function generateMessageId(): string {\n return `msg-${Date.now()}-${++messageIdCounter}`\n}\n\nexport function generateThreadId(): string {\n return `thread-${Date.now()}-${++threadIdCounter}`\n}\n\nexport function generateId(prefix = 'id'): string {\n return `${prefix}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`\n}\n","import { ThreadListItemState } from '../../types/thread'\nimport { BaseSubscribable, Unsubscribe } from '../../utils/Subscribable'\n\nexport interface ThreadListItemRuntimeConfig {\n state: ThreadListItemState\n onSwitchTo: (threadId: string) => Promise<void>\n onRename: (threadId: string, title: string) => Promise<void>\n onDelete: (threadId: string) => Promise<void>\n}\n\nexport class ThreadListItemRuntime extends BaseSubscribable {\n private _state: ThreadListItemState\n\n constructor(private config: ThreadListItemRuntimeConfig) {\n super()\n this._state = config.state\n }\n\n public get state(): ThreadListItemState {\n return this._state\n }\n\n public getState(): ThreadListItemState {\n return this._state\n }\n\n public updateState(state: ThreadListItemState): void {\n this._state = state\n this.notifySubscribers()\n }\n\n public async switchTo(): Promise<void> {\n await this.config.onSwitchTo(this._state.id)\n }\n\n public async rename(newTitle: string): Promise<void> {\n await this.config.onRename(this._state.id, newTitle)\n }\n\n public async delete(): Promise<void> {\n await this.config.onDelete(this._state.id)\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return super.subscribe(callback)\n }\n}\n","import { BaseSubscribable } from '../../utils/Subscribable'\n\nexport interface ComposerState {\n text: string\n isSubmitting: boolean\n}\n\nexport class ComposerRuntime extends BaseSubscribable {\n private _text: string = ''\n private _isSubmitting: boolean = false\n\n public get text(): string {\n return this._text\n }\n\n public get isSubmitting(): boolean {\n return this._isSubmitting\n }\n\n public getState(): ComposerState {\n return {\n text: this._text,\n isSubmitting: this._isSubmitting\n }\n }\n\n public setText(text: string): void {\n this._text = text\n this.notifySubscribers()\n }\n\n public clear(): void {\n this._text = ''\n this.notifySubscribers()\n }\n\n public setSubmitting(isSubmitting: boolean): void {\n this._isSubmitting = isSubmitting\n this.notifySubscribers()\n }\n}\n\nexport default ComposerRuntime\n","import { AppendMessage, Message, TextContent } from '../../types/message'\nimport { RuntimeCapabilities, ThreadState } from '../../types/thread'\nimport { BaseSubscribable, Unsubscribe } from '../../utils/Subscribable'\nimport ComposerRuntime from '../ComposerRuntime/ComposerRuntime'\nimport { ThreadRuntimeCore } from './ThreadRuntimeCore'\n\nexport class ThreadRuntime extends BaseSubscribable {\n public readonly composer: ComposerRuntime\n\n constructor(private _core: ThreadRuntimeCore) {\n super()\n this.composer = new ComposerRuntime()\n\n // Subscribe to core changes and propagate\n this._core.subscribe(() => {\n this.notifySubscribers()\n })\n }\n\n public get messages(): readonly Message[] {\n return this._core.messages\n }\n\n public get isRunning(): boolean {\n return this._core.isRunning\n }\n\n public get isDisabled(): boolean {\n return this._core.isDisabled\n }\n\n public get capabilities(): RuntimeCapabilities {\n return this._core.capabilities\n }\n\n public getState(): ThreadState {\n return {\n threadId: 'main', // Will be set by ThreadListRuntime\n isDisabled: this._core.isDisabled,\n isRunning: this._core.isRunning,\n capabilities: this._core.capabilities\n }\n }\n\n public append(message: AppendMessage): void {\n this._core.append(message)\n }\n\n public async send(text: string): Promise<void> {\n if (!text.trim()) return\n\n this.composer.setSubmitting(true)\n\n try {\n this.composer.clear()\n await this._core.startRun({\n role: 'user',\n content: [{ type: 'text', data: text } as TextContent]\n })\n } catch (e) {\n // TODO: Handle error\n } finally {\n this.composer.setSubmitting(false)\n }\n }\n\n public cancelRun(): void {\n this._core.cancelRun()\n }\n\n public clear(): void {\n this._core.clear()\n }\n\n public reset(messages: Message[] = []): void {\n this._core.reset(messages)\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return super.subscribe(callback)\n }\n}\n","import { StreamAdapter, StreamEvent } from '../../types/adapters'\nimport { AppendMessage, Message, MessageContent, MessageStatus } from '../../types/message'\nimport { RuntimeCapabilities } from '../../types/thread'\nimport { generateMessageId } from '../../utils/idGenerator'\nimport { BaseSubscribable } from '../../utils/Subscribable'\n\nexport interface ThreadRuntimeCoreConfig {\n streamAdapter: StreamAdapter\n initialMessages?: Message[]\n onMessagesChange?: (messages: Message[]) => void\n}\n\nexport class ThreadRuntimeCore extends BaseSubscribable {\n private _messages: Message[] = []\n private _isRunning = false\n private _isDisabled = false\n private _abortController: AbortController | null = null\n\n // Track current part being accumulated\n private _currentPart: {\n messageId: string\n contentIndex: number\n type: string\n parentId?: string\n } | null = null\n\n constructor(private config: ThreadRuntimeCoreConfig) {\n super()\n if (config.initialMessages) {\n this._messages = [...config.initialMessages]\n }\n }\n\n public get messages(): readonly Message[] {\n return this._messages\n }\n\n public get isRunning(): boolean {\n return this._isRunning\n }\n\n public get isDisabled(): boolean {\n return this._isDisabled\n }\n\n public get capabilities(): RuntimeCapabilities {\n return {\n cancel: true,\n edit: false,\n reload: false,\n speech: false,\n attachments: false,\n feedback: false\n }\n }\n\n public append(message: AppendMessage): void {\n const newMessage: Message = {\n id: message.id || generateMessageId(),\n parentId: message.parentId,\n role: message.role,\n content: message.content,\n status: message.status || { type: 'complete' },\n timestamp: message.timestamp || Date.now(),\n metadata: message.metadata\n }\n\n this._messages.push(newMessage)\n this.config.onMessagesChange?.(this._messages)\n this.notifySubscribers()\n }\n\n public async startRun(userMessage: AppendMessage): Promise<void> {\n if (this._isRunning) {\n throw new Error('A run is already in progress')\n }\n\n this.append(userMessage)\n this._isRunning = true\n this._abortController = new AbortController()\n this._currentPart = null // Reset current part\n this.notifySubscribers()\n\n const assistantMessageId = generateMessageId()\n const assistantMessage: Message = {\n id: assistantMessageId,\n role: 'assistant',\n content: [],\n status: { type: 'running' },\n timestamp: Date.now()\n }\n\n this._messages.push(assistantMessage)\n this.config.onMessagesChange?.(this._messages)\n this.notifySubscribers()\n\n try {\n const stream = this.config.streamAdapter.stream({\n messages: this._messages,\n signal: this._abortController.signal\n })\n\n for await (const event of stream) {\n if (this._abortController.signal.aborted) {\n break\n }\n\n this.handleStreamEvent(assistantMessageId, event.event)\n }\n\n this.updateMessageStatus(assistantMessageId, { type: 'complete' })\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n this.updateMessageStatus(assistantMessageId, { type: 'cancelled' })\n } else {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n this.updateMessageStatus(assistantMessageId, {\n type: 'error',\n error: errorMessage\n })\n }\n } finally {\n this._isRunning = false\n this._abortController = null\n this._currentPart = null // Clean up\n this.notifySubscribers()\n }\n }\n\n private handleStreamEvent(messageId: string, event: StreamEvent): void {\n const messageIndex = this._messages.findIndex(m => m.id === messageId)\n if (messageIndex === -1) return\n\n const message = this._messages[messageIndex]\n\n // Handle core events with type guards\n if (event.type === 'part-start') {\n this.handlePartStart(message, event as Extract<StreamEvent, { type: 'part-start' }>)\n } else if (event.type === 'text-delta') {\n this.handleTextDelta(message, event as Extract<StreamEvent, { type: 'text-delta' }>)\n } else if (event.type === 'part-finish') {\n this.handlePartFinish()\n } else if (event.type === 'metadata') {\n const metadataEvent = event as Extract<StreamEvent, { type: 'metadata' }>\n message.metadata = {\n ...message.metadata,\n conversationId: metadataEvent.conversationId,\n interactionId: metadataEvent.interactionId\n }\n } else if (event.type === 'error') {\n const errorEvent = event as Extract<StreamEvent, { type: 'error' }>\n message.content.push({\n type: 'error',\n data: errorEvent.error\n })\n } else {\n // Handle custom events\n const customEvent = event as Extract<StreamEvent, { data?: any }>\n message.content.push({\n type: customEvent.type,\n data: customEvent.data,\n parentId: customEvent.parentId\n })\n }\n\n // Update message\n this._messages = [\n ...this._messages.slice(0, messageIndex),\n { ...message, timestamp: Date.now() },\n ...this._messages.slice(messageIndex + 1)\n ]\n this.config.onMessagesChange?.(this._messages)\n this.notifySubscribers()\n }\n\n private handlePartStart(message: Message, event: Extract<StreamEvent, { type: 'part-start' }>): void {\n const contentIndex = message.content.length\n\n // Create initial content based on type\n let initialContent: MessageContent\n\n switch (event.part.type) {\n case 'assistant_thought':\n // Initialize as array for assistant thoughts\n initialContent = {\n type: event.part.type,\n data: [],\n parentId: event.part.parentId\n } as any\n break\n\n case 'text':\n // Initialize as empty string for text\n initialContent = {\n type: event.part.type,\n data: '',\n parentId: event.part.parentId\n } as any\n break\n\n default:\n initialContent = {\n type: event.part.type,\n parentId: event.part.parentId\n } as any\n }\n\n // Add to message\n message.content.push(initialContent)\n\n // Track current part\n this._currentPart = {\n messageId: message.id,\n contentIndex,\n type: event.part.type,\n parentId: event.part.parentId\n }\n }\n\n private handleTextDelta(message: Message, event: Extract<StreamEvent, { type: 'text-delta' }>): void {\n if (!this._currentPart) {\n console.warn('Received text-delta without part-start')\n return\n }\n\n const content = message.content[this._currentPart.contentIndex] as any\n\n if (content.type === 'assistant_thought') {\n // For assistant thoughts, push each delta as a new array item\n if (!Array.isArray(content.data)) {\n content.data = []\n }\n if (event.delta.trim()) {\n content.data.push(event.delta.trim())\n }\n } else {\n // For text and other types, concatenate into a single string\n content.data = (content.data || '') + event.delta\n }\n }\n\n private handlePartFinish(): void {\n if (!this._currentPart) {\n console.warn('Received part-finish without part-start')\n return\n }\n\n // Part is complete, clear tracking\n this._currentPart = null\n }\n\n private updateMessageStatus(messageId: string, status: MessageStatus): void {\n const messageIndex = this._messages.findIndex(m => m.id === messageId)\n if (messageIndex === -1) return\n\n this._messages[messageIndex] = {\n ...this._messages[messageIndex],\n status\n }\n\n this.config.onMessagesChange?.(this._messages)\n this.notifySubscribers()\n }\n\n public clear(): void {\n this._messages = []\n this.config.onMessagesChange?.(this._messages)\n this.notifySubscribers()\n }\n\n public cancelRun(): void {\n if (!this._isRunning || !this._abortController) {\n return\n }\n\n this._abortController.abort()\n }\n\n public reset(messages: Message[] = []): void {\n this._messages = [...messages]\n this.config.onMessagesChange?.(this._messages)\n this.notifySubscribers()\n }\n}\n","import { StreamAdapter, ThreadListAdapter } from '../../types/adapters'\nimport { ThreadListItemState } from '../../types/thread'\nimport { generateThreadId } from '../../utils/idGenerator'\nimport { BaseSubscribable } from '../../utils/Subscribable'\nimport { ThreadListItemRuntime } from '../ThreadListItemRuntime/ThreadListItemRuntime'\nimport { ThreadRuntime } from '../ThreadRuntime/ThreadRuntime'\nimport { ThreadRuntimeCore } from '../ThreadRuntime/ThreadRuntimeCore'\n\nexport interface ThreadListState {\n mainThreadId: string\n threads: readonly string[]\n isLoading: boolean\n threadItems: Record<string, ThreadListItemState>\n}\n\nexport interface ThreadListRuntimeConfig {\n streamAdapter: StreamAdapter\n threadListAdapter?: ThreadListAdapter\n}\n\nexport class ThreadListRuntime extends BaseSubscribable {\n private _mainThreadId: string\n private _threads = new Map<string, ThreadRuntime>()\n private _threadItems = new Map<string, ThreadListItemRuntime>()\n private _threadStates = new Map<string, ThreadListItemState>()\n private _isLoading = false\n public readonly main: ThreadRuntime\n\n constructor(private config: ThreadListRuntimeConfig) {\n super()\n\n // Create main thread\n this._mainThreadId = generateThreadId()\n const mainCore = new ThreadRuntimeCore({\n streamAdapter: config.streamAdapter\n })\n this.main = new ThreadRuntime(mainCore)\n this._threads.set(this._mainThreadId, this.main)\n\n // Create main thread state\n const mainState: ThreadListItemState = {\n id: this._mainThreadId,\n title: 'New Chat',\n status: { type: 'regular' },\n isMain: true,\n createdAt: Date.now(),\n updatedAt: Date.now()\n }\n this._threadStates.set(this._mainThreadId, mainState)\n\n // Create main thread item\n const mainItem = new ThreadListItemRuntime({\n state: mainState,\n onSwitchTo: this.switchToThread.bind(this),\n onRename: this.renameThread.bind(this),\n onDelete: this.deleteThread.bind(this)\n })\n this._threadItems.set(this._mainThreadId, mainItem)\n }\n\n public get isLoading(): boolean {\n return this._isLoading\n }\n\n /**\n * Get the currently active main thread\n */\n public getMainThread(): ThreadRuntime {\n const mainThread = this._threads.get(this._mainThreadId)\n if (!mainThread) {\n return this.main\n }\n return mainThread\n }\n\n public getState(): ThreadListState {\n const threads: string[] = []\n const threadItems: Record<string, ThreadListItemState> = {}\n\n for (const [id, state] of this._threadStates) {\n threadItems[id] = state\n if (state.status.type === 'regular') {\n threads.push(id)\n }\n }\n\n return {\n mainThreadId: this._mainThreadId,\n threads,\n isLoading: this._isLoading,\n threadItems\n }\n }\n\n public async switchToThread(threadId: string): Promise<void> {\n const thread = this._threads.get(threadId)\n if (!thread) {\n throw new Error(`Thread ${threadId} not found`)\n }\n\n // Update old main thread\n const oldMainState = this._threadStates.get(this._mainThreadId)\n if (oldMainState) {\n oldMainState.isMain = false\n this._threadStates.set(this._mainThreadId, oldMainState)\n this._threadItems.get(this._mainThreadId)?.updateState(oldMainState)\n }\n\n // Update new main thread\n this._mainThreadId = threadId\n const newMainState = this._threadStates.get(threadId)\n if (newMainState) {\n newMainState.isMain = true\n this._threadStates.set(threadId, newMainState)\n this._threadItems.get(threadId)?.updateState(newMainState)\n }\n\n // Load thread messages if adapter exists\n if (this.config.threadListAdapter && newMainState?.conversationId) {\n this._isLoading = true\n this.notifySubscribers()\n\n try {\n const messages = await this.config.threadListAdapter.loadThread(threadId)\n thread.reset(messages)\n } catch (error) {\n console.error('Failed to load thread:', error)\n } finally {\n this._isLoading = false\n }\n }\n\n this.notifySubscribers()\n }\n\n public async switchToNewThread(): Promise<void> {\n const newThreadId = generateThreadId()\n const newCore = new ThreadRuntimeCore({\n streamAdapter: this.config.streamAdapter\n })\n const newThread = new ThreadRuntime(newCore)\n\n this._threads.set(newThreadId, newThread)\n\n // Create new thread state\n const newState: ThreadListItemState = {\n id: newThreadId,\n title: 'New Chat',\n status: { type: 'regular' },\n isMain: false,\n createdAt: Date.now(),\n updatedAt: Date.now()\n }\n this._threadStates.set(newThreadId, newState)\n\n // Create new thread item\n const newItem = new ThreadListItemRuntime({\n state: newState,\n onSwitchTo: this.switchToThread.bind(this),\n onRename: this.renameThread.bind(this),\n onDelete: this.deleteThread.bind(this)\n })\n this._threadItems.set(newThreadId, newItem)\n\n // Subscribe to new thread changes\n newThread.subscribe(() => {\n this.notifySubscribers()\n })\n\n // Create thread via adapter if exists\n if (this.config.threadListAdapter) {\n try {\n const createdState = await this.config.threadListAdapter.createThread()\n newState.conversationId = createdState.conversationId\n this._threadStates.set(newThreadId, newState)\n newItem.updateState(newState)\n } catch (error) {\n console.error('Failed to create thread:', error)\n }\n }\n\n await this.switchToThread(newThreadId)\n }\n\n public async loadThreads(): Promise<void> {\n if (!this.config.threadListAdapter) {\n console.warn('No threadListAdapter configured')\n return\n }\n\n this._isLoading = true\n this.notifySubscribers()\n\n try {\n const threadStates = await this.config.threadListAdapter.loadThreads()\n\n for (const state of threadStates) {\n if (this._threadStates.has(state.id)) {\n continue\n }\n\n const threadCore = new ThreadRuntimeCore({\n streamAdapter: this.config.streamAdapter\n })\n const thread = new ThreadRuntime(threadCore)\n this._threads.set(state.id, thread)\n\n this._threadStates.set(state.id, state)\n\n // Create thread item\n const threadItem = new ThreadListItemRuntime({\n state,\n onSwitchTo: this.switchToThread.bind(this),\n onRename: this.renameThread.bind(this),\n onDelete: this.deleteThread.bind(this)\n })\n this._threadItems.set(state.id, threadItem)\n\n // Subscribe to thread changes\n thread.subscribe(() => {\n this.notifySubscribers()\n })\n }\n } catch (error) {\n console.error('Failed to load threads:', error)\n } finally {\n this._isLoading = false\n this.notifySubscribers()\n }\n }\n\n private async renameThread(threadId: string, newTitle: string): Promise<void> {\n const state = this._threadStates.get(threadId)\n if (!state) return\n\n state.title = newTitle\n state.updatedAt = Date.now()\n this._threadStates.set(threadId, state)\n this._threadItems.get(threadId)?.updateState(state)\n\n if (this.config.threadListAdapter) {\n try {\n await this.config.threadListAdapter.updateThread(threadId, { title: newTitle })\n } catch (error) {\n console.error('Failed to rename thread:', error)\n }\n }\n\n this.notifySubscribers()\n }\n\n private async deleteThread(threadId: string): Promise<void> {\n if (threadId === this._mainThreadId && this._threads.size === 1) {\n throw new Error('Cannot delete the last thread')\n }\n\n // If deleting main thread, switch to another thread first\n if (threadId === this._mainThreadId) {\n const otherThreadId = Array.from(this._threads.keys()).find(id => id !== threadId)\n if (otherThreadId) {\n await this.switchToThread(otherThreadId)\n }\n }\n\n this._threads.delete(threadId)\n this._threadItems.delete(threadId)\n this._threadStates.delete(threadId)\n\n if (this.config.threadListAdapter) {\n try {\n await this.config.threadListAdapter.deleteThread(threadId)\n } catch (error) {\n console.error('Failed to delete thread:', error)\n }\n }\n\n this.notifySubscribers()\n }\n}\n","import { PluginRegistry } from '../../core/PluginRegistry'\nimport { Message } from '../../types/message'\nimport { ChatPlugin } from '../../types/plugin'\nimport { BaseSubscribable } from '../../utils/Subscribable'\nimport { ContentFocusRuntime } from '../ContentFocusRuntime/ContentFocusRuntime'\nimport { ThreadListRuntime, ThreadListRuntimeConfig } from '../ThreadListRuntime/ThreadListRuntime'\nimport { ThreadRuntime } from '../ThreadRuntime/ThreadRuntime'\n\nexport interface AssistantRuntimeConfig extends ThreadListRuntimeConfig {\n plugins?: ChatPlugin[]\n}\n\nexport class AssistantRuntime extends BaseSubscribable {\n public readonly threads: ThreadListRuntime\n public readonly pluginRegistry: PluginRegistry\n private _contentFocusRuntime: ContentFocusRuntime\n private _currentThreadUnsubscribe?: () => void\n\n constructor(config: AssistantRuntimeConfig) {\n super()\n\n // Initialize plugin registry\n this.pluginRegistry = new PluginRegistry()\n if (config.plugins) {\n config.plugins.forEach(plugin => {\n this.pluginRegistry.registerPlugin(plugin)\n })\n }\n\n // Initialize thread list\n this.threads = new ThreadListRuntime({\n streamAdapter: config.streamAdapter,\n threadListAdapter: config.threadListAdapter\n })\n\n this._contentFocusRuntime = new ContentFocusRuntime()\n\n // Subscribe to content focus changes\n this._contentFocusRuntime.subscribe(() => {\n this.notifySubscribers()\n })\n\n // Subscribe to thread list changes (including thread switches)\n this.threads.subscribe(() => {\n // Re-subscribe to the new main thread when it changes\n this.subscribeToCurrentThread()\n this.notifySubscribers()\n })\n\n // Initial subscription to main thread\n this.subscribeToCurrentThread()\n }\n\n public get thread(): ThreadRuntime {\n return this.threads.getMainThread()\n }\n\n public get contentFocus(): ContentFocusRuntime {\n return this._contentFocusRuntime\n }\n\n /**\n * Register a plugin\n */\n public registerPlugin(plugin: ChatPlugin): void {\n this.pluginRegistry.registerPlugin(plugin)\n\n plugin.init?.({\n streamingEnabled: true,\n feedbackEnabled: false,\n detailPanelEnabled: true\n })\n }\n\n /**\n * Unregister a plugin\n */\n public unregisterPlugin(pluginId: string): boolean {\n return this.pluginRegistry.unregisterPlugin(pluginId)\n }\n\n /**\n * Subscribe to the current main thread\n * Called when thread switches to ensure we listen to the right thread\n */\n private subscribeToCurrentThread(): void {\n // Unsubscribe from previous thread\n if (this._currentThreadUnsubscribe) {\n this._currentThreadUnsubscribe()\n }\n\n // Subscribe to new main thread\n this._currentThreadUnsubscribe = this.thread.subscribe(() => {\n this.handleMessagesChange(this.thread.messages)\n this.notifySubscribers()\n })\n }\n\n private handleMessagesChange(messages: readonly Message[]): void {\n if (messages.length === 0) return\n\n // Only auto-focus when a new assistant message completes\n const lastMessage = messages[messages.length - 1]\n\n if (lastMessage.role === 'assistant' && lastMessage.status.type === 'complete') {\n this.autoFocusLastContent(messages)\n }\n }\n\n private autoFocusLastContent(messages: readonly Message[]): void {\n if (messages.length === 0) return\n if (this._contentFocusRuntime.isActive) return // Don't override existing focus\n\n // Find last assistant message\n for (let i = messages.length - 1; i >= 0; i--) {\n const message = messages[i]\n if (message.role !== 'assistant') continue\n\n // Find last content with focus capability\n for (let j = message.content.length - 1; j >= 0; j--) {\n const content = message.content[j]\n const renderer = this.pluginRegistry.getRenderersByType(content.type)\n\n if (renderer.length > 0 && renderer[0].capabilities?.supportsFocus) {\n this._contentFocusRuntime.focus(content, message, j, 'detail')\n return\n }\n }\n }\n }\n}\n","/*\nobject-assign\n(c) Sindre Sorhus\n@license MIT\n*/\n\n'use strict';\n/* eslint-disable no-unused-vars */\nvar getOwnPropertySymbols = Object.getOwnPropertySymbols;\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nvar propIsEnumerable = Object.prototype.propertyIsEnumerable;\n\nfunction toObject(val) {\n\tif (val === null || val === undefined) {\n\t\tthrow new TypeError('Object.assign cannot be called with null or undefined');\n\t}\n\n\treturn Object(val);\n}\n\nfunction shouldUseNative() {\n\ttry {\n\t\tif (!Object.assign) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Detect buggy property enumeration order in older V8 versions.\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=4118\n\t\tvar test1 = new String('abc'); // eslint-disable-line no-new-wrappers\n\t\ttest1[5] = 'de';\n\t\tif (Object.getOwnPropertyNames(test1)[0] === '5') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test2 = {};\n\t\tfor (var i = 0; i < 10; i++) {\n\t\t\ttest2['_' + String.fromCharCode(i)] = i;\n\t\t}\n\t\tvar order2 = Object.getOwnPropertyNames(test2).map(function (n) {\n\t\t\treturn test2[n];\n\t\t});\n\t\tif (order2.join('') !== '0123456789') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test3 = {};\n\t\t'abcdefghijklmnopqrst'.split('').forEach(function (letter) {\n\t\t\ttest3[letter] = letter;\n\t\t});\n\t\tif (Object.keys(Object.assign({}, test3)).join('') !==\n\t\t\t\t'abcdefghijklmnopqrst') {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (err) {\n\t\t// We don't expect any of the above to throw, but better to be safe.\n\t\treturn false;\n\t}\n}\n\nmodule.exports = shouldUseNative() ? Object.assign : function (target, source) {\n\tvar from;\n\tvar to = toObject(target);\n\tvar symbols;\n\n\tfor (var s = 1; s < arguments.length; s++) {\n\t\tfrom = Object(arguments[s]);\n\n\t\tfor (var key in from) {\n\t\t\tif (hasOwnProperty.call(from, key)) {\n\t\t\t\tto[key] = from[key];\n\t\t\t}\n\t\t}\n\n\t\tif (getOwnPropertySymbols) {\n\t\t\tsymbols = getOwnPropertySymbols(from);\n\t\t\tfor (var i = 0; i < symbols.length; i++) {\n\t\t\t\tif (propIsEnumerable.call(from, symbols[i])) {\n\t\t\t\t\tto[symbols[i]] = from[symbols[i]];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn to;\n};\n","/** @license React v17.0.2\n * react-jsx-runtime.production.min.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict';require(\"object-assign\");var f=require(\"react\"),g=60103;exports.Fragment=60107;if(\"function\"===typeof Symbol&&Symbol.for){var h=Symbol.for;g=h(\"react.element\");exports.Fragment=h(\"react.fragment\")}var m=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,n=Object.prototype.hasOwnProperty,p={key:!0,ref:!0,__self:!0,__source:!0};\nfunction q(c,a,k){var b,d={},e=null,l=null;void 0!==k&&(e=\"\"+k);void 0!==a.key&&(e=\"\"+a.key);void 0!==a.ref&&(l=a.ref);for(b in a)n.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:g,type:c,key:e,ref:l,props:d,_owner:m.current}}exports.jsx=q;exports.jsxs=q;\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/react-jsx-runtime.production.min.js');\n} else {\n module.exports = require('./cjs/react-jsx-runtime.development.js');\n}\n","import { createContext, ReactNode, useContext } from 'react'\n\nimport { AssistantRuntime } from '../../runtime/AssistantRuntime/AssistantRuntime'\n\nconst AssistantRuntimeContext = createContext<AssistantRuntime | null>(null)\n\nexport interface AssistantRuntimeProviderProps {\n runtime: AssistantRuntime\n children: ReactNode\n}\n\nexport function AssistantRuntimeProvider({ runtime, children }: AssistantRuntimeProviderProps): JSX.Element {\n return <AssistantRuntimeContext.Provider value={runtime}>{children}</AssistantRuntimeContext.Provider>\n}\n\nexport function useAssistantRuntimeContext(): AssistantRuntime {\n const runtime = useContext(AssistantRuntimeContext)\n if (!runtime) {\n throw new Error('useAssistantRuntimeContext must be used within AssistantRuntimeProvider')\n }\n return runtime\n}\n","import { AssistantRuntime } from '../../runtime/AssistantRuntime/AssistantRuntime'\nimport { useAssistantRuntimeContext } from '../providers/AssistantRuntimeProvider'\n\nexport function useAssistantRuntime(): AssistantRuntime {\n return useAssistantRuntimeContext()\n}\n","import { useEffect, useState } from 'react'\n\nimport { ThreadListState } from '../../runtime/ThreadListRuntime/ThreadListRuntime'\nimport { useAssistantRuntime } from './useAssistantRuntime'\n\nexport function useThreadList() {\n const runtime = useAssistantRuntime()\n\n return {\n switchToThread: (threadId: string) => runtime.threads.switchToThread(threadId),\n switchToNewThread: () => runtime.threads.switchToNewThread(),\n loadThreads: () => runtime.threads.loadThreads?.(),\n renameThread: (threadId: string, title: string) => runtime.threads['renameThread']?.(threadId, title),\n deleteThread: (threadId: string) => runtime.threads['deleteThread']?.(threadId)\n }\n}\n\nexport function useThreadListState() {\n const runtime = useAssistantRuntime()\n const [state, setState] = useState<ThreadListState>(runtime.threads.getState())\n\n useEffect(() => {\n const unsubscribe = runtime.threads.subscribe(() => {\n setState(runtime.threads.getState())\n })\n return unsubscribe\n }, [runtime])\n\n return state\n}\n","import { ThreadRuntime } from '../../runtime/ThreadRuntime/ThreadRuntime'\nimport { useAssistantRuntime } from './useAssistantRuntime'\n\nexport function useCurrentThread(): ThreadRuntime {\n const mainThread = useAssistantRuntime().threads.getMainThread()\n return mainThread\n}\n","/**\n * @license React\n * use-sync-external-store-shim.production.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\nvar React = require(\"react\");\nfunction is(x, y) {\n return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);\n}\nvar objectIs = \"function\" === typeof Object.is ? Object.is : is,\n useState = React.useState,\n useEffect = React.useEffect,\n useLayoutEffect = React.useLayoutEffect,\n useDebugValue = React.useDebugValue;\nfunction useSyncExternalStore$2(subscribe, getSnapshot) {\n var value = getSnapshot(),\n _useState = useState({ inst: { value: value, getSnapshot: getSnapshot } }),\n inst = _useState[0].inst,\n forceUpdate = _useState[1];\n useLayoutEffect(\n function () {\n inst.value = value;\n inst.getSnapshot = getSnapshot;\n checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });\n },\n [subscribe, value, getSnapshot]\n );\n useEffect(\n function () {\n checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });\n return subscribe(function () {\n checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });\n });\n },\n [subscribe]\n );\n useDebugValue(value);\n return value;\n}\nfunction checkIfSnapshotChanged(inst) {\n var latestGetSnapshot = inst.getSnapshot;\n inst = inst.value;\n try {\n var nextValue = latestGetSnapshot();\n return !objectIs(inst, nextValue);\n } catch (error) {\n return !0;\n }\n}\nfunction useSyncExternalStore$1(subscribe, getSnapshot) {\n return getSnapshot();\n}\nvar shim =\n \"undefined\" === typeof window ||\n \"undefined\" === typeof window.document ||\n \"undefined\" === typeof window.document.createElement\n ? useSyncExternalStore$1\n : useSyncExternalStore$2;\nexports.useSyncExternalStore =\n void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim;\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('../cjs/use-sync-external-store-shim.production.js');\n} else {\n module.exports = require('../cjs/use-sync-external-store-shim.development.js');\n}\n","import { useSyncExternalStore } from 'use-sync-external-store/shim'\n\nimport { Message } from '../../types/message'\nimport { useAssistantRuntime } from './useAssistantRuntime'\n\nexport function useMessages(): readonly Message[] {\n const runtime = useAssistantRuntime()\n\n return useSyncExternalStore(\n callback => {\n // Subscribe to runtime, which notifies when thread switches\n // or when the current thread's messages change\n return runtime.subscribe(() => {\n callback()\n })\n },\n\n () => {\n // Always get messages from the current main thread\n return runtime.thread.messages\n },\n () => runtime.thread.messages\n )\n}\n","import { useSyncExternalStore } from 'use-sync-external-store/shim'\n\nimport ComposerRuntime, { ComposerState } from '../../runtime/ComposerRuntime/ComposerRuntime'\nimport { useCurrentThread } from './useCurrentThread'\n\nexport function useComposer(): ComposerRuntime {\n const thread = useCurrentThread()\n return thread.composer\n}\n\nexport function useComposerState(): ComposerState {\n const composer = useComposer()\n\n return useSyncExternalStore(\n callback => composer.subscribe(callback),\n () => composer.getState(),\n () => composer.getState()\n )\n}\n","import { FocusContext } from '../../runtime/ContentFocusRuntime/ContentFocusRuntime'\nimport { useAssistantRuntime } from './useAssistantRuntime'\n\nexport function useContentRenderer(contentType: string, context?: FocusContext) {\n const runtime = useAssistantRuntime()\n const renderer = runtime.pluginRegistry.getBestRendererForType(contentType)\n\n if (!renderer) {\n return {\n component: null,\n auxiliaryComponent: null,\n supportsFocus: false,\n supportsPreview: false,\n supportsFullscreen: false\n }\n }\n\n // Get auxiliary component for specific context\n const auxiliaryComponent = context ? renderer.auxiliary?.[context] : null\n\n return {\n component: renderer.component,\n auxiliaryComponent,\n supportsFocus: renderer.capabilities?.supportsFocus ?? false,\n supportsPreview: renderer.capabilities?.supportsPreview ?? false,\n supportsFullscreen: renderer.capabilities?.supportsFullscreen ?? false\n }\n}\n\nexport function useHasAuxiliaryView(contentType: string, context: FocusContext): boolean {\n const runtime = useAssistantRuntime()\n const renderer = runtime.pluginRegistry.getBestRendererForType(contentType)\n return !!renderer?.auxiliary?.[context]\n}\n\nexport function useSupportsFocus(contentType: string): boolean {\n const runtime = useAssistantRuntime()\n const renderer = runtime.pluginRegistry.getBestRendererForType(contentType)\n return renderer?.capabilities?.supportsFocus ?? false\n}\n","import { useEffect, useState } from 'react'\n\nimport { ContentFocusState, FocusContext } from '../../runtime/ContentFocusRuntime/ContentFocusRuntime'\nimport { Message, MessageContent } from '../../types/message'\nimport { useAssistantRuntime } from './useAssistantRuntime'\n\nexport function useContentFocus() {\n const runtime = useAssistantRuntime()\n const [state, setState] = useState<ContentFocusState>(runtime.contentFocus.state)\n\n useEffect(() => {\n const unsubscribe = runtime.contentFocus.subscribe(() => {\n setState(runtime.contentFocus.state)\n })\n return unsubscribe\n }, [runtime])\n\n return {\n ...state,\n focus: (content: MessageContent, message: Message, contentIndex: number, context?: FocusContext) =>\n runtime.contentFocus.focus(content, message, contentIndex, context),\n blur: () => runtime.contentFocus.blur(),\n toggle: (content: MessageContent, message: Message, contentIndex: number, context?: FocusContext) =>\n runtime.contentFocus.toggle(content, message, contentIndex, context),\n switchContext: (context: FocusContext) => runtime.contentFocus.switchContext(context),\n focusNext: () => runtime.contentFocus.focusNext(runtime.thread.messages),\n focusPrevious: () => runtime.contentFocus.focusPrevious(runtime.thread.messages)\n }\n}\n\nexport function useContentFocusState() {\n const runtime = useAssistantRuntime()\n const [state, setState] = useState<ContentFocusState>(runtime.contentFocus.state)\n\n useEffect(() => {\n const unsubscribe = runtime.contentFocus.subscribe(() => {\n setState(runtime.contentFocus.state)\n })\n return unsubscribe\n }, [runtime])\n\n return state\n}\n","import { MessageContent } from '../types/message'\n\nexport interface ContentGroup {\n groupKey: string | undefined\n indices: number[]\n items: MessageContent[]\n groupType: 'code' | 'tool-calls' | 'reasoning' | 'mixed' | 'single-type'\n primaryType: string\n}\n\nexport function groupContentByParentId(content: MessageContent[]): ContentGroup[] {\n const groupMap = new Map<string, number[]>()\n\n // Group by parentId\n for (let i = 0; i < content.length; i++) {\n const item = content[i]\n const parentId = item.parentId\n const groupId = parentId ?? `__ungrouped_${i}`\n\n const indices = groupMap.get(groupId) ?? []\n indices.push(i)\n groupMap.set(groupId, indices)\n }\n\n // Convert to groups with type detection\n const groups: ContentGroup[] = []\n for (const [groupId, indices] of groupMap) {\n const groupKey = groupId.startsWith('__ungrouped_') ? undefined : groupId\n const items = indices.map(i => content[i])\n const groupType = detectGroupType(items)\n const primaryType = getPrimaryType(items)\n\n groups.push({ groupKey, indices, items, groupType, primaryType })\n }\n\n return groups\n}\n\nfunction detectGroupType(items: MessageContent[]): ContentGroup['groupType'] {\n if (items.length === 1) return 'single-type'\n\n const types = new Set(items.map(item => item.type))\n\n // All same type\n if (types.size === 1) {\n const type = items[0].type\n\n if (type === 'tool_call') {\n return 'tool-calls'\n }\n\n if (type === 'assistant_thought') {\n return 'reasoning'\n }\n\n return 'single-type'\n }\n\n // Mixed types\n return 'mixed'\n}\n\nfunction getPrimaryType(items: MessageContent[]): string {\n const typeCounts = new Map<string, number>()\n\n for (const item of items) {\n typeCounts.set(item.type, (typeCounts.get(item.type) || 0) + 1)\n }\n\n let maxCount = 0\n let primaryType = items[0].type\n\n for (const [type, count] of typeCounts) {\n if (count > maxCount) {\n maxCount = count\n primaryType = type\n }\n }\n\n return primaryType\n}\n","import { StreamAdapter, StreamChunk } from '../types/adapters'\nimport { Message } from '../types/message'\n\nexport interface SSEEvent {\n event: string\n data: any\n}\n\nexport abstract class BaseSSEStreamAdapter<TAllowedEvents extends readonly string[] = readonly string[]>\n implements StreamAdapter\n{\n protected abstract prepareRequest(params: { messages: Message[]; signal?: AbortSignal }): {\n url: string\n options: RequestInit\n }\n\n protected abstract convertEvent(event: SSEEvent & { event: TAllowedEvents[number] }): StreamChunk | null\n\n protected getAllowedEvents(): TAllowedEvents | null {\n return null\n }\n\n protected shouldProcessEvent(eventType: string): boolean {\n const allowedEvents = this.getAllowedEvents()\n if (!allowedEvents) return true\n return allowedEvents.includes(eventType)\n }\n\n async *stream(params: { messages: Message[]; signal?: AbortSignal }): AsyncGenerator<StreamChunk, void, unknown> {\n const { signal } = params\n const { url, options } = this.prepareRequest(params)\n\n const response = await fetch(url, { ...options, signal })\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`)\n }\n\n if (!response.body) {\n throw new Error('Response body is null')\n }\n\n yield* this.parseSSEStream(response.body, signal)\n }\n\n private async *parseSSEStream(\n body: ReadableStream<Uint8Array>,\n signal?: AbortSignal\n ): AsyncGenerator<StreamChunk, void, unknown> {\n const reader = body.getReader()\n const decoder = new TextDecoder()\n let buffer = ''\n let currentEvent: string | null = null\n\n try {\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const { done, value } = await reader.read()\n\n if (done) break\n if (signal?.aborted) break\n\n buffer += decoder.decode(value, { stream: true })\n const lines = buffer.split('\\n')\n buffer = lines.pop() || ''\n\n for (const line of lines) {\n const trimmedLine = line.trim()\n\n if (!trimmedLine) {\n currentEvent = null\n continue\n }\n\n if (trimmedLine === ': ping') {\n continue\n }\n\n if (trimmedLine.startsWith('event:')) {\n currentEvent = trimmedLine.substring(6).trim()\n continue\n }\n\n if (trimmedLine.startsWith('data:')) {\n const dataStr = trimmedLine.substring(5).trim()\n\n if (dataStr === 'eof' || trimmedLine === 'eof') {\n break\n }\n\n try {\n const data = JSON.parse(dataStr)\n\n if (currentEvent && this.shouldProcessEvent(currentEvent)) {\n const chunk = this.convertEvent({\n event: currentEvent as TAllowedEvents[number],\n data\n })\n if (chunk) {\n yield chunk\n }\n }\n } catch (e) {\n // handle error\n }\n\n currentEvent = null\n }\n }\n }\n } finally {\n reader.releaseLock()\n }\n }\n}\n"],"names":["PluginRegistry","__publicField","plugin","renderer","renderers","a","b","pluginId","filteredRenderers","r","type","BaseSubscribable","callback","ContentFocusRuntime","content","message","contentIndex","context","messages","currentMsgIndex","m","currentMsg","currentContentIndex","nextContent","nextMsg","prevContent","prevMsg","lastIndex","messageIdCounter","threadIdCounter","generateMessageId","generateThreadId","generateId","prefix","ThreadListItemRuntime","config","state","newTitle","ComposerRuntime","text","isSubmitting","ThreadRuntime","_core","ThreadRuntimeCore","newMessage","_b","_a","userMessage","assistantMessageId","assistantMessage","stream","event","error","errorMessage","messageId","messageIndex","metadataEvent","errorEvent","customEvent","initialContent","status","ThreadListRuntime","mainCore","mainState","mainItem","mainThread","threads","threadItems","id","threadId","thread","oldMainState","newMainState","newThreadId","newCore","newThread","newState","newItem","createdState","threadStates","threadCore","threadItem","otherThreadId","AssistantRuntime","lastMessage","i","j","getOwnPropertySymbols","hasOwnProperty","propIsEnumerable","toObject","val","shouldUseNative","test1","test2","order2","n","test3","letter","objectAssign","target","source","from","to","symbols","s","key","require$$0","f","require$$1","g","reactJsxRuntime_production_min","h","p","q","c","k","d","e","l","jsxRuntimeModule","AssistantRuntimeContext","createContext","AssistantRuntimeProvider","runtime","children","useAssistantRuntimeContext","useContext","useAssistantRuntime","useThreadList","title","useThreadListState","setState","useState","useEffect","useCurrentThread","React","is","x","y","objectIs","useLayoutEffect","useDebugValue","useSyncExternalStore$2","subscribe","getSnapshot","value","_useState","inst","forceUpdate","checkIfSnapshotChanged","latestGetSnapshot","nextValue","useSyncExternalStore$1","shim","useSyncExternalStoreShim_production","shimModule","useMessages","useSyncExternalStore","useComposer","useComposerState","composer","useContentRenderer","contentType","auxiliaryComponent","_c","_d","useContentFocus","groupContentByParentId","groupMap","groupId","indices","groups","groupKey","items","groupType","detectGroupType","primaryType","getPrimaryType","item","typeCounts","maxCount","count","BaseSSEStreamAdapter","eventType","allowedEvents","params","signal","url","options","response","body","reader","decoder","buffer","currentEvent","done","lines","line","trimmedLine","dataStr","data","chunk"],"mappings":";;;;AAE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AssistantRuntime } from './useAssistantRuntime';
2
+ export { useThreadList, useThreadListState } from './useThreadList';
3
+ export { useCurrentThread } from './useCurrentThread';
4
+ export { useMessages } from './useMessages';
5
+ export { useComposer, useComposerState } from './useComposer';
6
+ export { useContentRenderer } from './useContentRenderer';
7
+ export { useContentFocus } from './useContentFocus';
@@ -0,0 +1,2 @@
1
+ import { AssistantRuntime } from '../../runtime/AssistantRuntime/AssistantRuntime';
2
+ export declare function useAssistantRuntime(): AssistantRuntime;
@@ -0,0 +1,3 @@
1
+ import { default as ComposerRuntime, ComposerState } from '../../runtime/ComposerRuntime/ComposerRuntime';
2
+ export declare function useComposer(): ComposerRuntime;
3
+ export declare function useComposerState(): ComposerState;
@@ -0,0 +1,17 @@
1
+ import { ContentFocusState, FocusContext } from '../../runtime/ContentFocusRuntime/ContentFocusRuntime';
2
+ import { Message, MessageContent } from '../../types/message';
3
+ export declare function useContentFocus(): {
4
+ focus: (content: MessageContent, message: Message, contentIndex: number, context?: FocusContext) => void;
5
+ blur: () => void;
6
+ toggle: (content: MessageContent, message: Message, contentIndex: number, context?: FocusContext) => void;
7
+ switchContext: (context: FocusContext) => void;
8
+ focusNext: () => void;
9
+ focusPrevious: () => void;
10
+ isActive: boolean;
11
+ context: FocusContext | null;
12
+ focusedContent: MessageContent | null;
13
+ focusedMessage: Message | null;
14
+ focusedMessageId: string | null;
15
+ focusedContentIndex: number | null;
16
+ };
17
+ export declare function useContentFocusState(): ContentFocusState;
@@ -0,0 +1,16 @@
1
+ import { FocusContext } from '../../runtime/ContentFocusRuntime/ContentFocusRuntime';
2
+ export declare function useContentRenderer(contentType: string, context?: FocusContext): {
3
+ component: null;
4
+ auxiliaryComponent: null;
5
+ supportsFocus: boolean;
6
+ supportsPreview: boolean;
7
+ supportsFullscreen: boolean;
8
+ } | {
9
+ component: import('react').ComponentType<import('../..').MessageRendererProps<any>>;
10
+ auxiliaryComponent: import('react').ComponentType<import('../../types/plugin').AuxiliaryRendererProps> | null | undefined;
11
+ supportsFocus: boolean;
12
+ supportsPreview: boolean;
13
+ supportsFullscreen: boolean;
14
+ };
15
+ export declare function useHasAuxiliaryView(contentType: string, context: FocusContext): boolean;
16
+ export declare function useSupportsFocus(contentType: string): boolean;
@@ -0,0 +1,2 @@
1
+ import { ThreadRuntime } from '../../runtime/ThreadRuntime/ThreadRuntime';
2
+ export declare function useCurrentThread(): ThreadRuntime;
@@ -0,0 +1,2 @@
1
+ import { Message } from '../../types/message';
2
+ export declare function useMessages(): readonly Message[];
@@ -0,0 +1,9 @@
1
+ import { ThreadListState } from '../../runtime/ThreadListRuntime/ThreadListRuntime';
2
+ export declare function useThreadList(): {
3
+ switchToThread: (threadId: string) => Promise<void>;
4
+ switchToNewThread: () => Promise<void>;
5
+ loadThreads: () => Promise<void>;
6
+ renameThread: (threadId: string, title: string) => Promise<void>;
7
+ deleteThread: (threadId: string) => Promise<void>;
8
+ };
9
+ export declare function useThreadListState(): ThreadListState;
@@ -0,0 +1,2 @@
1
+ export * from './hooks';
2
+ export * from './providers';
@@ -0,0 +1,8 @@
1
+ import { ReactNode } from 'react';
2
+ import { AssistantRuntime } from '../../runtime/AssistantRuntime/AssistantRuntime';
3
+ export interface AssistantRuntimeProviderProps {
4
+ runtime: AssistantRuntime;
5
+ children: ReactNode;
6
+ }
7
+ export declare function AssistantRuntimeProvider({ runtime, children }: AssistantRuntimeProviderProps): JSX.Element;
8
+ export declare function useAssistantRuntimeContext(): AssistantRuntime;
@@ -0,0 +1 @@
1
+ export { AssistantRuntimeProvider } from './AssistantRuntimeProvider';
@@ -0,0 +1,33 @@
1
+ import { PluginRegistry } from '../../core/PluginRegistry';
2
+ import { ChatPlugin } from '../../types/plugin';
3
+ import { BaseSubscribable } from '../../utils/Subscribable';
4
+ import { ContentFocusRuntime } from '../ContentFocusRuntime/ContentFocusRuntime';
5
+ import { ThreadListRuntime, ThreadListRuntimeConfig } from '../ThreadListRuntime/ThreadListRuntime';
6
+ import { ThreadRuntime } from '../ThreadRuntime/ThreadRuntime';
7
+ export interface AssistantRuntimeConfig extends ThreadListRuntimeConfig {
8
+ plugins?: ChatPlugin[];
9
+ }
10
+ export declare class AssistantRuntime extends BaseSubscribable {
11
+ readonly threads: ThreadListRuntime;
12
+ readonly pluginRegistry: PluginRegistry;
13
+ private _contentFocusRuntime;
14
+ private _currentThreadUnsubscribe?;
15
+ constructor(config: AssistantRuntimeConfig);
16
+ get thread(): ThreadRuntime;
17
+ get contentFocus(): ContentFocusRuntime;
18
+ /**
19
+ * Register a plugin
20
+ */
21
+ registerPlugin(plugin: ChatPlugin): void;
22
+ /**
23
+ * Unregister a plugin
24
+ */
25
+ unregisterPlugin(pluginId: string): boolean;
26
+ /**
27
+ * Subscribe to the current main thread
28
+ * Called when thread switches to ensure we listen to the right thread
29
+ */
30
+ private subscribeToCurrentThread;
31
+ private handleMessagesChange;
32
+ private autoFocusLastContent;
33
+ }
@@ -0,0 +1,16 @@
1
+ import { BaseSubscribable } from '../../utils/Subscribable';
2
+ export interface ComposerState {
3
+ text: string;
4
+ isSubmitting: boolean;
5
+ }
6
+ export declare class ComposerRuntime extends BaseSubscribable {
7
+ private _text;
8
+ private _isSubmitting;
9
+ get text(): string;
10
+ get isSubmitting(): boolean;
11
+ getState(): ComposerState;
12
+ setText(text: string): void;
13
+ clear(): void;
14
+ setSubmitting(isSubmitting: boolean): void;
15
+ }
16
+ export default ComposerRuntime;
@@ -0,0 +1,27 @@
1
+ import { Message, MessageContent } from '../../types/message';
2
+ import { BaseSubscribable } from '../../utils/Subscribable';
3
+ export type FocusContext = 'detail';
4
+ export interface ContentFocusState {
5
+ isActive: boolean;
6
+ context: FocusContext | null;
7
+ focusedContent: MessageContent | null;
8
+ focusedMessage: Message | null;
9
+ focusedMessageId: string | null;
10
+ focusedContentIndex: number | null;
11
+ }
12
+ export declare class ContentFocusRuntime extends BaseSubscribable {
13
+ private _state;
14
+ get state(): ContentFocusState;
15
+ get isActive(): boolean;
16
+ get context(): FocusContext | null;
17
+ get focusedContent(): MessageContent | null;
18
+ get focusedMessage(): Message | null;
19
+ get focusedMessageId(): string | null;
20
+ get focusedContentIndex(): number | null;
21
+ focus(content: MessageContent, message: Message, contentIndex: number, context?: FocusContext): void;
22
+ blur(): void;
23
+ toggle(content: MessageContent, message: Message, contentIndex: number, context?: FocusContext): void;
24
+ switchContext(context: FocusContext): void;
25
+ focusNext(messages: readonly Message[]): void;
26
+ focusPrevious(messages: readonly Message[]): void;
27
+ }
@@ -0,0 +1,20 @@
1
+ import { ThreadListItemState } from '../../types/thread';
2
+ import { BaseSubscribable, Unsubscribe } from '../../utils/Subscribable';
3
+ export interface ThreadListItemRuntimeConfig {
4
+ state: ThreadListItemState;
5
+ onSwitchTo: (threadId: string) => Promise<void>;
6
+ onRename: (threadId: string, title: string) => Promise<void>;
7
+ onDelete: (threadId: string) => Promise<void>;
8
+ }
9
+ export declare class ThreadListItemRuntime extends BaseSubscribable {
10
+ private config;
11
+ private _state;
12
+ constructor(config: ThreadListItemRuntimeConfig);
13
+ get state(): ThreadListItemState;
14
+ getState(): ThreadListItemState;
15
+ updateState(state: ThreadListItemState): void;
16
+ switchTo(): Promise<void>;
17
+ rename(newTitle: string): Promise<void>;
18
+ delete(): Promise<void>;
19
+ subscribe(callback: () => void): Unsubscribe;
20
+ }
@@ -0,0 +1,35 @@
1
+ import { StreamAdapter, ThreadListAdapter } from '../../types/adapters';
2
+ import { ThreadListItemState } from '../../types/thread';
3
+ import { BaseSubscribable } from '../../utils/Subscribable';
4
+ import { ThreadRuntime } from '../ThreadRuntime/ThreadRuntime';
5
+ export interface ThreadListState {
6
+ mainThreadId: string;
7
+ threads: readonly string[];
8
+ isLoading: boolean;
9
+ threadItems: Record<string, ThreadListItemState>;
10
+ }
11
+ export interface ThreadListRuntimeConfig {
12
+ streamAdapter: StreamAdapter;
13
+ threadListAdapter?: ThreadListAdapter;
14
+ }
15
+ export declare class ThreadListRuntime extends BaseSubscribable {
16
+ private config;
17
+ private _mainThreadId;
18
+ private _threads;
19
+ private _threadItems;
20
+ private _threadStates;
21
+ private _isLoading;
22
+ readonly main: ThreadRuntime;
23
+ constructor(config: ThreadListRuntimeConfig);
24
+ get isLoading(): boolean;
25
+ /**
26
+ * Get the currently active main thread
27
+ */
28
+ getMainThread(): ThreadRuntime;
29
+ getState(): ThreadListState;
30
+ switchToThread(threadId: string): Promise<void>;
31
+ switchToNewThread(): Promise<void>;
32
+ loadThreads(): Promise<void>;
33
+ private renameThread;
34
+ private deleteThread;
35
+ }
@@ -0,0 +1,21 @@
1
+ import { AppendMessage, Message } from '../../types/message';
2
+ import { RuntimeCapabilities, ThreadState } from '../../types/thread';
3
+ import { BaseSubscribable, Unsubscribe } from '../../utils/Subscribable';
4
+ import { default as ComposerRuntime } from '../ComposerRuntime/ComposerRuntime';
5
+ import { ThreadRuntimeCore } from './ThreadRuntimeCore';
6
+ export declare class ThreadRuntime extends BaseSubscribable {
7
+ private _core;
8
+ readonly composer: ComposerRuntime;
9
+ constructor(_core: ThreadRuntimeCore);
10
+ get messages(): readonly Message[];
11
+ get isRunning(): boolean;
12
+ get isDisabled(): boolean;
13
+ get capabilities(): RuntimeCapabilities;
14
+ getState(): ThreadState;
15
+ append(message: AppendMessage): void;
16
+ send(text: string): Promise<void>;
17
+ cancelRun(): void;
18
+ clear(): void;
19
+ reset(messages?: Message[]): void;
20
+ subscribe(callback: () => void): Unsubscribe;
21
+ }
@@ -0,0 +1,32 @@
1
+ import { StreamAdapter } from '../../types/adapters';
2
+ import { AppendMessage, Message } from '../../types/message';
3
+ import { RuntimeCapabilities } from '../../types/thread';
4
+ import { BaseSubscribable } from '../../utils/Subscribable';
5
+ export interface ThreadRuntimeCoreConfig {
6
+ streamAdapter: StreamAdapter;
7
+ initialMessages?: Message[];
8
+ onMessagesChange?: (messages: Message[]) => void;
9
+ }
10
+ export declare class ThreadRuntimeCore extends BaseSubscribable {
11
+ private config;
12
+ private _messages;
13
+ private _isRunning;
14
+ private _isDisabled;
15
+ private _abortController;
16
+ private _currentPart;
17
+ constructor(config: ThreadRuntimeCoreConfig);
18
+ get messages(): readonly Message[];
19
+ get isRunning(): boolean;
20
+ get isDisabled(): boolean;
21
+ get capabilities(): RuntimeCapabilities;
22
+ append(message: AppendMessage): void;
23
+ startRun(userMessage: AppendMessage): Promise<void>;
24
+ private handleStreamEvent;
25
+ private handlePartStart;
26
+ private handleTextDelta;
27
+ private handlePartFinish;
28
+ private updateMessageStatus;
29
+ clear(): void;
30
+ cancelRun(): void;
31
+ reset(messages?: Message[]): void;
32
+ }
@@ -0,0 +1,10 @@
1
+ export { AssistantRuntime } from './AssistantRuntime/AssistantRuntime';
2
+ export type { AssistantRuntimeConfig } from './AssistantRuntime/AssistantRuntime';
3
+ export { ThreadListRuntime } from './ThreadListRuntime/ThreadListRuntime';
4
+ export type { ThreadListState, ThreadListRuntimeConfig } from './ThreadListRuntime/ThreadListRuntime';
5
+ export { ThreadListItemRuntime } from './ThreadListItemRuntime/ThreadListItemRuntime';
6
+ export { ThreadRuntime } from './ThreadRuntime/ThreadRuntime';
7
+ export { ComposerRuntime } from './ComposerRuntime/ComposerRuntime';
8
+ export type { ComposerState } from './ComposerRuntime/ComposerRuntime';
9
+ export { ThreadRuntimeCore } from './ThreadRuntime/ThreadRuntimeCore';
10
+ export type { ThreadRuntimeCoreConfig } from './ThreadRuntime/ThreadRuntimeCore';
@@ -0,0 +1,48 @@
1
+ import { Message } from './message';
2
+ import { ThreadListItemState } from './thread';
3
+ export interface StreamAdapter {
4
+ stream(request: StreamRequest): AsyncIterable<StreamChunk>;
5
+ }
6
+ export type StreamEvent = {
7
+ readonly type: 'part-start';
8
+ readonly part: {
9
+ readonly type: 'text' | 'assistant_thought';
10
+ readonly parentId?: string;
11
+ readonly toolCallId?: string;
12
+ readonly toolName?: string;
13
+ readonly language?: string;
14
+ };
15
+ } | {
16
+ readonly type: 'text-delta';
17
+ readonly delta: string;
18
+ } | {
19
+ readonly type: 'part-finish';
20
+ } | {
21
+ readonly type: 'metadata';
22
+ readonly conversationId?: string;
23
+ readonly interactionId?: string;
24
+ } | {
25
+ readonly type: 'error';
26
+ readonly error: string;
27
+ } | {
28
+ readonly type: string;
29
+ readonly data?: any;
30
+ readonly parentId?: string;
31
+ [key: string]: any;
32
+ };
33
+ export interface StreamRequest {
34
+ messages: Message[];
35
+ signal?: AbortSignal;
36
+ config?: Record<string, unknown>;
37
+ }
38
+ export interface StreamChunk {
39
+ event: StreamEvent;
40
+ }
41
+ export interface ThreadListAdapter {
42
+ listThreads(): Promise<ThreadListItemState[]>;
43
+ loadThreads(): Promise<ThreadListItemState[]>;
44
+ loadThread(threadId: string): Promise<Message[]>;
45
+ createThread(initialMessage?: string): Promise<ThreadListItemState>;
46
+ deleteThread(threadId: string): Promise<void>;
47
+ updateThread(threadId: string, updates: Partial<ThreadListItemState>): Promise<void>;
48
+ }
@@ -0,0 +1,5 @@
1
+ export type { Message, MessageContent, MessageRole, MessageStatus, AppendMessage } from './message';
2
+ export type { ThreadListItemState, ThreadState, RuntimeCapabilities } from './thread';
3
+ export type { ChatPlugin, MessageRenderer, MessageRendererProps, GroupRenderer, GroupRendererProps, PluginConfig } from './plugin';
4
+ export type { StreamAdapter, ThreadListAdapter, StreamEvent, StreamRequest, StreamChunk } from './adapters';
5
+ export type { SSEEvent } from '../utils/BaseSSEStreamAdapter';
@@ -0,0 +1,56 @@
1
+ export type MessageRole = 'user' | 'assistant';
2
+ export type MessageStatus = {
3
+ type: 'pending';
4
+ } | {
5
+ type: 'running';
6
+ } | {
7
+ type: 'complete';
8
+ } | {
9
+ type: 'error';
10
+ error: string;
11
+ } | {
12
+ type: 'cancelled';
13
+ };
14
+ export interface MessageMetadata {
15
+ interactionId?: string;
16
+ conversationId?: string;
17
+ [key: string]: string | number | boolean | undefined;
18
+ }
19
+ export interface Message {
20
+ id: string;
21
+ parentId?: string;
22
+ role: MessageRole;
23
+ content: MessageContent[];
24
+ status: MessageStatus;
25
+ timestamp: number;
26
+ metadata?: MessageMetadata;
27
+ }
28
+ export interface TextContent extends MessageContent<string> {
29
+ type: 'text';
30
+ }
31
+ export interface ErrorContent extends MessageContent<string> {
32
+ type: 'error';
33
+ }
34
+ export interface MetadataContent extends MessageContent {
35
+ type: 'metadata';
36
+ conversationId?: string;
37
+ interactionId?: string;
38
+ }
39
+ export interface AssistantThoughtContent extends MessageContent {
40
+ type: 'assistant_thought';
41
+ text: string;
42
+ }
43
+ export interface CustomContent extends MessageContent {
44
+ type: string;
45
+ data: Record<string, unknown>;
46
+ }
47
+ export interface MessageContent<T = any> {
48
+ type: string;
49
+ parentId?: string;
50
+ data?: T;
51
+ }
52
+ export type AppendMessage = Omit<Message, 'id' | 'timestamp' | 'status'> & {
53
+ id?: string;
54
+ timestamp?: number;
55
+ status?: MessageStatus;
56
+ };