@assistant-ui/react 0.11.5 → 0.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/AssistantClient.d.ts.map +1 -1
- package/dist/client/AssistantClient.js +1 -2
- package/dist/client/AssistantClient.js.map +1 -1
- package/dist/client/ToolUIClient.d.ts +3 -2
- package/dist/client/ToolUIClient.d.ts.map +1 -1
- package/dist/client/ToolUIClient.js +1 -5
- package/dist/client/ToolUIClient.js.map +1 -1
- package/dist/context/providers/AttachmentProvider.js +3 -3
- package/dist/context/providers/AttachmentProvider.js.map +1 -1
- package/dist/context/providers/MessageProvider.js +2 -2
- package/dist/context/providers/MessageProvider.js.map +1 -1
- package/dist/context/providers/PartProvider.js +2 -2
- package/dist/context/providers/PartProvider.js.map +1 -1
- package/dist/context/providers/TextMessagePartProvider.d.ts.map +1 -1
- package/dist/context/providers/TextMessagePartProvider.js +6 -7
- package/dist/context/providers/TextMessagePartProvider.js.map +1 -1
- package/dist/context/providers/ThreadListItemProvider.js +3 -3
- package/dist/context/providers/ThreadListItemProvider.js.map +1 -1
- package/dist/context/react/AssistantApiContext.d.ts +1 -1
- package/dist/context/react/AssistantApiContext.d.ts.map +1 -1
- package/dist/context/react/AssistantApiContext.js +4 -3
- package/dist/context/react/AssistantApiContext.js.map +1 -1
- package/dist/context/react/index.d.ts +1 -0
- package/dist/context/react/index.d.ts.map +1 -1
- package/dist/context/react/index.js +2 -0
- package/dist/context/react/index.js.map +1 -1
- package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/legacy-runtime/AssistantRuntimeProvider.js +1 -5
- package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
- package/dist/legacy-runtime/client/AttachmentRuntimeClient.d.ts +2 -4
- package/dist/legacy-runtime/client/AttachmentRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/AttachmentRuntimeClient.js +10 -10
- package/dist/legacy-runtime/client/AttachmentRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts +3 -2
- package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ComposerRuntimeClient.js +1 -5
- package/dist/legacy-runtime/client/ComposerRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.d.ts +1 -1
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.js +10 -10
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/MessageRuntimeClient.d.ts +3 -3
- package/dist/legacy-runtime/client/MessageRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/MessageRuntimeClient.js +31 -31
- package/dist/legacy-runtime/client/MessageRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.d.ts +2 -2
- package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.js +17 -17
- package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts +3 -2
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.js +1 -5
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/ThreadRuntimeClient.d.ts +3 -2
- package/dist/legacy-runtime/client/ThreadRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ThreadRuntimeClient.js +1 -5
- package/dist/legacy-runtime/client/ThreadRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts +8 -1
- package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime/ThreadRuntime.js +5 -1
- package/dist/legacy-runtime/runtime/ThreadRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.d.ts +12 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.d.ts.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.js +52 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.js.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/index.d.ts +3 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/index.d.ts.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/index.js +6 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/index.js.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts +11 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js +55 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +66 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.js +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.js.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts +7 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +185 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.d.ts +3 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.d.ts.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js +12 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.d.ts +4 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.d.ts.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.js +13 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.js.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts +13 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js +138 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.d.ts +13 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.d.ts.map +1 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.js +32 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.js.map +1 -0
- package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts +2 -1
- package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.d.ts +3 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts +3 -2
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js +9 -2
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ThreadMessageLike.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ThreadMessageLike.js +2 -2
- package/dist/legacy-runtime/runtime-cores/external-store/ThreadMessageLike.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/index.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/index.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/index.js +1 -0
- package/dist/legacy-runtime/runtime-cores/index.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js +5 -0
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js +3 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +2 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +2 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/utils/tap-store/tap-api.d.ts +9 -1
- package/dist/utils/tap-store/tap-api.d.ts.map +1 -1
- package/dist/utils/tap-store/tap-api.js +12 -2
- package/dist/utils/tap-store/tap-api.js.map +1 -1
- package/package.json +1 -1
- package/src/client/AssistantClient.ts +1 -4
- package/src/client/ToolUIClient.ts +1 -6
- package/src/context/providers/AttachmentProvider.tsx +3 -3
- package/src/context/providers/MessageProvider.tsx +2 -2
- package/src/context/providers/PartProvider.tsx +2 -2
- package/src/context/providers/TextMessagePartProvider.tsx +5 -7
- package/src/context/providers/ThreadListItemProvider.tsx +3 -3
- package/src/context/react/AssistantApiContext.tsx +7 -2
- package/src/context/react/index.ts +2 -0
- package/src/legacy-runtime/AssistantRuntimeProvider.tsx +1 -15
- package/src/legacy-runtime/client/AttachmentRuntimeClient.ts +10 -11
- package/src/legacy-runtime/client/ComposerRuntimeClient.ts +1 -6
- package/src/legacy-runtime/client/MessagePartRuntimeClient.ts +13 -14
- package/src/legacy-runtime/client/MessageRuntimeClient.ts +35 -36
- package/src/legacy-runtime/client/ThreadListItemRuntimeClient.ts +17 -18
- package/src/legacy-runtime/client/ThreadListRuntimeClient.ts +1 -6
- package/src/legacy-runtime/client/ThreadRuntimeClient.ts +1 -6
- package/src/legacy-runtime/runtime/ThreadRuntime.ts +14 -2
- package/src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.ts +62 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/index.ts +2 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts +67 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +96 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransport.spec.md +125 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +232 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts +18 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.ts +9 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts +173 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/utils.ts +42 -0
- package/src/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.tsx +1 -0
- package/src/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.tsx +2 -1
- package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.tsx +3 -0
- package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.tsx +13 -2
- package/src/legacy-runtime/runtime-cores/external-store/ThreadMessageLike.tsx +2 -5
- package/src/legacy-runtime/runtime-cores/index.ts +1 -0
- package/src/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.tsx +6 -0
- package/src/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.tsx +4 -0
- package/src/utils/tap-store/tap-api.ts +19 -2
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/runtime/ThreadRuntime.ts"],"sourcesContent":["import {\n ThreadSuggestion,\n RuntimeCapabilities,\n ThreadRuntimeCore,\n SpeechState,\n ThreadRuntimeEventType,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../runtime-cores/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtime-cores/utils/MessageRepository\";\nimport { AppendMessage, ThreadMessage, Unsubscribe } from \"../../types\";\nimport { ThreadMessageLike } from \"../runtime-cores/external-store\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport {\n MessageRuntimePath,\n ThreadListItemRuntimePath,\n ThreadRuntimePath,\n} from \"./RuntimePathTypes\";\nimport type { ThreadListItemState } from \"./RuntimeBindings\";\nimport { RunConfig } from \"../../types/AssistantTypes\";\nimport { EventSubscriptionSubject } from \"./subscribable/EventSubscriptionSubject\";\nimport { symbolInnerMessage } from \"../runtime-cores/external-store/getExternalStoreMessage\";\nimport { ModelContext } from \"../../model-context\";\nimport { ChatModelRunOptions, ChatModelRunResult } from \"../runtime-cores\";\nimport { ReadonlyJSONValue } from \"assistant-stream/utils\";\n\nexport type CreateStartRunConfig = {\n parentId: string | null;\n sourceId?: string | null | undefined;\n runConfig?: RunConfig | undefined;\n};\n\nexport type CreateResumeRunConfig = CreateStartRunConfig & {\n stream: (\n options: ChatModelRunOptions,\n ) => AsyncGenerator<ChatModelRunResult, void, unknown>;\n};\n\nconst toResumeRunConfig = (message: CreateResumeRunConfig): ResumeRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n stream: message.stream,\n };\n};\n\nconst toStartRunConfig = (message: CreateStartRunConfig): StartRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n };\n};\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n sourceId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n metadata?: AppendMessage[\"metadata\"] | undefined;\n createdAt?: Date | undefined;\n runConfig?: AppendMessage[\"runConfig\"] | undefined;\n startRun?: boolean | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n createdAt: new Date(),\n parentId: messages.at(-1)?.id ?? null,\n sourceId: null,\n runConfig: {},\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n metadata: { custom: {} },\n };\n }\n\n return {\n createdAt: message.createdAt ?? new Date(),\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n sourceId: message.sourceId ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n metadata: message.metadata ?? { custom: {} },\n runConfig: message.runConfig ?? {},\n startRun: message.startRun,\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadListItemRuntimeBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport type ThreadState = {\n /**\n * The thread ID.\n * @deprecated This field is deprecated and will be removed in 0.8.0. Use `useThreadListItem().id` instead.\n */\n readonly threadId: string;\n\n /**\n * The thread metadata.\n *\n * @deprecated Use `useThreadListItem()` instead. This field is deprecated and will be removed in 0.8.0.\n */\n readonly metadata: ThreadListItemState;\n\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n readonly isDisabled: boolean;\n\n /**\n * Whether the thread is loading its history.\n */\n readonly isLoading: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n readonly isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n readonly capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n readonly messages: readonly ThreadMessage[];\n\n /**\n * The thread state.\n *\n * @deprecated This feature is experimental\n */\n readonly state: ReadonlyJSONValue;\n\n /**\n * Follow up message suggestions to show the user.\n */\n readonly suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n readonly extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport const getThreadState = (\n runtime: ThreadRuntimeCore,\n threadListItemState: ThreadListItemState,\n): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: threadListItemState.id,\n metadata: threadListItemState,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isLoading: runtime.isLoading,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n state: runtime.state,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = {\n /**\n * The selector for the thread runtime.\n */\n readonly path: ThreadRuntimePath;\n\n /**\n * The thread composer runtime.\n */\n readonly composer: ThreadComposerRuntime;\n\n /**\n * Gets a snapshot of the thread state.\n */\n getState(): ThreadState;\n\n /**\n * Append a new message to the thread.\n *\n * @example ```ts\n * // append a new user message with the text \"Hello, world!\"\n * threadRuntime.append(\"Hello, world!\");\n * ```\n *\n * @example ```ts\n * // append a new assistant message with the text \"Hello, world!\"\n * threadRuntime.append({\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hello, world!\" }],\n * });\n * ```\n */\n append(message: CreateAppendMessage): void;\n\n /**\n * @deprecated pass an object with `parentId` instead. This will be removed in 0.8.0.\n */\n startRun(parentId: string | null): void;\n /**\n * Start a new run with the given configuration.\n * @param config The configuration for starting the run\n */\n startRun(config: CreateStartRunConfig): void;\n\n /**\n * Resume a run with the given configuration.\n * @param config The configuration for resuming the run\n **/\n unstable_resumeRun(config: CreateResumeRunConfig): void;\n\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelContext(): ModelContext;\n\n /**\n * @deprecated This method was renamed to `getModelContext`.\n */\n getModelConfig(): ModelContext;\n\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n\n /**\n * Reset the thread with optional initial messages.\n *\n * @param initialMessages - Optional array of initial messages to populate the thread\n */\n reset(initialMessages?: readonly ThreadMessageLike[]): void;\n\n getMessageByIndex(idx: number): MessageRuntime;\n getMessageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n};\n\nexport class ThreadRuntimeImpl implements ThreadRuntime {\n public get path() {\n return this._threadBinding.path;\n }\n\n public get __internal_threadBinding() {\n return this._threadBinding;\n }\n\n private readonly _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(\n threadBinding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) {\n const stateBinding = new ShallowMemoizeSubject({\n path: threadBinding.path,\n getState: () =>\n getThreadState(\n threadBinding.getState(),\n threadListItemBinding.getState(),\n ),\n subscribe: (callback) => {\n const sub1 = threadBinding.subscribe(callback);\n const sub2 = threadListItemBinding.subscribe(callback);\n return () => {\n sub1();\n sub2();\n };\n },\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.append = this.append.bind(this);\n this.unstable_resumeRun = this.unstable_resumeRun.bind(this);\n this.startRun = this.startRun.bind(this);\n this.cancelRun = this.cancelRun.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.export = this.export.bind(this);\n this.import = this.import.bind(this);\n this.reset = this.reset.bind(this);\n this.getMessageByIndex = this.getMessageByIndex.bind(this);\n this.getMessageById = this.getMessageById.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n this.getModelContext = this.getModelContext.bind(this);\n this.getModelConfig = this.getModelConfig.bind(this);\n this.getState = this.getState.bind(this);\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n public getModelContext() {\n return this._threadBinding.getState().getModelContext();\n }\n\n public getModelConfig() {\n return this.getModelContext();\n }\n\n public startRun(configOrParentId: string | null | CreateStartRunConfig) {\n const config =\n configOrParentId === null || typeof configOrParentId === \"string\"\n ? { parentId: configOrParentId }\n : configOrParentId;\n return this._threadBinding.getState().startRun(toStartRunConfig(config));\n }\n\n public unstable_resumeRun(config: CreateResumeRunConfig) {\n return this._threadBinding.getState().resumeRun(toResumeRunConfig(config));\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public reset(initialMessages?: readonly ThreadMessageLike[]) {\n this._threadBinding.getState().reset(initialMessages);\n }\n\n public getMessageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMessageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n ...{ [symbolInnerMessage]: (message as any)[symbolInnerMessage] },\n\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ThreadRuntimeEventType>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject({\n event: event,\n binding: this._threadBinding,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";AAYA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,mBAAmB;AAQ5B,SAAS,gCAAgC;AACzC,SAAS,0BAA0B;AAiBnC,IAAM,oBAAoB,CAAC,YAAoD;AAC7E,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY;AAAA,IAC9B,UAAU,QAAQ,YAAY;AAAA,IAC9B,WAAW,QAAQ,aAAa,CAAC;AAAA,IACjC,QAAQ,QAAQ;AAAA,EAClB;AACF;AAEA,IAAM,mBAAmB,CAAC,YAAkD;AAC1E,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY;AAAA,IAC9B,UAAU,QAAQ,YAAY;AA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eCapabilities,\n ThreadRuntimeCore,\n SpeechState,\n ThreadRuntimeEventType,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../runtime-cores/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtime-cores/utils/MessageRepository\";\nimport { AppendMessage, ThreadMessage, Unsubscribe } from \"../../types\";\nimport { ThreadMessageLike } from \"../runtime-cores/external-store\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport {\n MessageRuntimePath,\n ThreadListItemRuntimePath,\n ThreadRuntimePath,\n} from \"./RuntimePathTypes\";\nimport type { ThreadListItemState } from \"./RuntimeBindings\";\nimport { RunConfig } from \"../../types/AssistantTypes\";\nimport { EventSubscriptionSubject } from \"./subscribable/EventSubscriptionSubject\";\nimport { symbolInnerMessage } from \"../runtime-cores/external-store/getExternalStoreMessage\";\nimport { ModelContext } from \"../../model-context\";\nimport { ChatModelRunOptions, ChatModelRunResult } from \"../runtime-cores\";\nimport { ReadonlyJSONValue } from \"assistant-stream/utils\";\n\nexport type CreateStartRunConfig = {\n parentId: string | null;\n sourceId?: string | null | undefined;\n runConfig?: RunConfig | undefined;\n};\n\nexport type CreateResumeRunConfig = CreateStartRunConfig & {\n stream?: (\n options: ChatModelRunOptions,\n ) => AsyncGenerator<ChatModelRunResult, void, unknown>;\n};\n\nconst toResumeRunConfig = (message: CreateResumeRunConfig): ResumeRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n ...(message.stream ? { stream: message.stream } : {}),\n };\n};\n\nconst toStartRunConfig = (message: CreateStartRunConfig): StartRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n };\n};\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n sourceId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n metadata?: AppendMessage[\"metadata\"] | undefined;\n createdAt?: Date | undefined;\n runConfig?: AppendMessage[\"runConfig\"] | undefined;\n startRun?: boolean | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n createdAt: new Date(),\n parentId: messages.at(-1)?.id ?? null,\n sourceId: null,\n runConfig: {},\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n metadata: { custom: {} },\n };\n }\n\n return {\n createdAt: message.createdAt ?? new Date(),\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n sourceId: message.sourceId ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n metadata: message.metadata ?? { custom: {} },\n runConfig: message.runConfig ?? {},\n startRun: message.startRun,\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadListItemRuntimeBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport type ThreadState = {\n /**\n * The thread ID.\n * @deprecated This field is deprecated and will be removed in 0.8.0. Use `useThreadListItem().id` instead.\n */\n readonly threadId: string;\n\n /**\n * The thread metadata.\n *\n * @deprecated Use `useThreadListItem()` instead. This field is deprecated and will be removed in 0.8.0.\n */\n readonly metadata: ThreadListItemState;\n\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n readonly isDisabled: boolean;\n\n /**\n * Whether the thread is loading its history.\n */\n readonly isLoading: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n readonly isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n readonly capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n readonly messages: readonly ThreadMessage[];\n\n /**\n * The thread state.\n *\n * @deprecated This feature is experimental\n */\n readonly state: ReadonlyJSONValue;\n\n /**\n * Follow up message suggestions to show the user.\n */\n readonly suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n readonly extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport const getThreadState = (\n runtime: ThreadRuntimeCore,\n threadListItemState: ThreadListItemState,\n): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: threadListItemState.id,\n metadata: threadListItemState,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isLoading: runtime.isLoading,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n state: runtime.state,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = {\n /**\n * The selector for the thread runtime.\n */\n readonly path: ThreadRuntimePath;\n\n /**\n * The thread composer runtime.\n */\n readonly composer: ThreadComposerRuntime;\n\n /**\n * Gets a snapshot of the thread state.\n */\n getState(): ThreadState;\n\n /**\n * Append a new message to the thread.\n *\n * @example ```ts\n * // append a new user message with the text \"Hello, world!\"\n * threadRuntime.append(\"Hello, world!\");\n * ```\n *\n * @example ```ts\n * // append a new assistant message with the text \"Hello, world!\"\n * threadRuntime.append({\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hello, world!\" }],\n * });\n * ```\n */\n append(message: CreateAppendMessage): void;\n\n /**\n * @deprecated pass an object with `parentId` instead. This will be removed in 0.8.0.\n */\n startRun(parentId: string | null): void;\n /**\n * Start a new run with the given configuration.\n * @param config The configuration for starting the run\n */\n startRun(config: CreateStartRunConfig): void;\n\n /**\n * Resume a run with the given configuration.\n * @param config The configuration for resuming the run\n **/\n unstable_resumeRun(config: CreateResumeRunConfig): void;\n\n /**\n * Load external state into the thread.\n * @param state The state to load into the thread\n */\n unstable_loadExternalState(state: any): void;\n\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelContext(): ModelContext;\n\n /**\n * @deprecated This method was renamed to `getModelContext`.\n */\n getModelConfig(): ModelContext;\n\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n\n /**\n * Reset the thread with optional initial messages.\n *\n * @param initialMessages - Optional array of initial messages to populate the thread\n */\n reset(initialMessages?: readonly ThreadMessageLike[]): void;\n\n getMessageByIndex(idx: number): MessageRuntime;\n getMessageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n};\n\nexport class ThreadRuntimeImpl implements ThreadRuntime {\n public get path() {\n return this._threadBinding.path;\n }\n\n public get __internal_threadBinding() {\n return this._threadBinding;\n }\n\n private readonly _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(\n threadBinding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) {\n const stateBinding = new ShallowMemoizeSubject({\n path: threadBinding.path,\n getState: () =>\n getThreadState(\n threadBinding.getState(),\n threadListItemBinding.getState(),\n ),\n subscribe: (callback) => {\n const sub1 = threadBinding.subscribe(callback);\n const sub2 = threadListItemBinding.subscribe(callback);\n return () => {\n sub1();\n sub2();\n };\n },\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.append = this.append.bind(this);\n this.unstable_resumeRun = this.unstable_resumeRun.bind(this);\n this.unstable_loadExternalState =\n this.unstable_loadExternalState.bind(this);\n this.startRun = this.startRun.bind(this);\n this.cancelRun = this.cancelRun.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.export = this.export.bind(this);\n this.import = this.import.bind(this);\n this.reset = this.reset.bind(this);\n this.getMessageByIndex = this.getMessageByIndex.bind(this);\n this.getMessageById = this.getMessageById.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n this.getModelContext = this.getModelContext.bind(this);\n this.getModelConfig = this.getModelConfig.bind(this);\n this.getState = this.getState.bind(this);\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n public getModelContext() {\n return this._threadBinding.getState().getModelContext();\n }\n\n public getModelConfig() {\n return this.getModelContext();\n }\n\n public startRun(configOrParentId: string | null | CreateStartRunConfig) {\n const config =\n configOrParentId === null || typeof configOrParentId === \"string\"\n ? { parentId: configOrParentId }\n : configOrParentId;\n return this._threadBinding.getState().startRun(toStartRunConfig(config));\n }\n\n public unstable_resumeRun(config: CreateResumeRunConfig) {\n return this._threadBinding.getState().resumeRun(toResumeRunConfig(config));\n }\n\n public unstable_loadExternalState(state: any) {\n this._threadBinding.getState().unstable_loadExternalState(state);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public reset(initialMessages?: readonly ThreadMessageLike[]) {\n this._threadBinding.getState().reset(initialMessages);\n }\n\n public getMessageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMessageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n ...{ [symbolInnerMessage]: (message as any)[symbolInnerMessage] },\n\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ThreadRuntimeEventType>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject({\n event: event,\n binding: this._threadBinding,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";AAYA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,mBAAmB;AAQ5B,SAAS,gCAAgC;AACzC,SAAS,0BAA0B;AAiBnC,IAAM,oBAAoB,CAAC,YAAoD;AAC7E,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY;AAAA,IAC9B,UAAU,QAAQ,YAAY;AAAA,IAC9B,WAAW,QAAQ,aAAa,CAAC;AAAA,IACjC,GAAI,QAAQ,SAAS,EAAE,QAAQ,QAAQ,OAAO,IAAI,CAAC;AAAA,EACrD;AACF;AAEA,IAAM,mBAAmB,CAAC,YAAkD;AAC1E,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY;AAAA,IAC9B,UAAU,QAAQ,YAAY;AAAA,IAC9B,WAAW,QAAQ,aAAa,CAAC;AAAA,EACnC;AACF;AAgBA,IAAM,kBAAkB,CACtB,UACA,YACkB;AAClB,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,MACL,WAAW,oBAAI,KAAK;AAAA,MACpB,UAAU,SAAS,GAAG,EAAE,GAAG,MAAM;AAAA,MACjC,UAAU;AAAA,MACV,WAAW,CAAC;AAAA,MACZ,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,C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AAS;AAE/B,cAAI,CAAC,WAAW,aAAa,OAAW,QAAO;AAE/C,gBAAM,SAAS,KAAK,eAAe,SAAS;AAE5C,gBAAM,WAAW,OAAO,YAAY,QAAQ,EAAE;AAC9C,gBAAM,oBAAoB,OAAO,qBAAqB,QAAQ,EAAE;AAEhE,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,GAAG,EAAE,CAAC,kBAAkB,GAAI,QAAgB,kBAAkB,EAAE;AAAA,YAEhE,QAAQ,SAAS,GAAG,EAAE,GAAG,OAAO,QAAQ;AAAA,YACxC;AAAA,YAEA,cAAc,SAAS,QAAQ,QAAQ,EAAE,IAAI;AAAA,YAC7C,aAAa,SAAS;AAAA,YAEtB,QACE,aAAa,cAAc,QAAQ,KAAK,cAAc;AAAA,YAExD;AAAA,UACF;AAAA,QACF;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,UAAUA,SAAQ;AAAA,MACjE,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEQ,6BAA6B,oBAAI,IAGvC;AAAA,EAEK,YACL,OACA,UACa;AACb,QAAI,UAAU,KAAK,2BAA2B,IAAI,KAAK;AACvD,QAAI,CAAC,SAAS;AACZ,gBAAU,IAAI,yBAAyB;AAAA,QACrC;AAAA,QACA,SAAS,KAAK;AAAA,MAChB,CAAC;AACD,WAAK,2BAA2B,IAAI,OAAO,OAAO;AAAA,IACpD;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { AssistantTransportCommand, CommandQueueState, QueuedCommand } from "./types";
|
2
|
+
export declare const createInitialQueueState: () => CommandQueueState;
|
3
|
+
export declare const useCommandQueue: (opts: {
|
4
|
+
onQueue: () => void;
|
5
|
+
}) => {
|
6
|
+
state: CommandQueueState;
|
7
|
+
enqueue: (command: AssistantTransportCommand) => void;
|
8
|
+
flush: () => QueuedCommand[];
|
9
|
+
markDelivered: () => void;
|
10
|
+
reset: () => void;
|
11
|
+
};
|
12
|
+
//# sourceMappingURL=commandQueue.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"commandQueue.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,uBAAuB,QAAO,iBAGzC,CAAC;AAEH,eAAO,MAAM,eAAe,GAAI,MAAM;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE;;uBASjC,yBAAyB;iBAUjC,aAAa,EAAE;;;CA8BlC,CAAC"}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
// src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.ts
|
2
|
+
import { useState, useCallback, useRef, useEffect } from "react";
|
3
|
+
var createInitialQueueState = () => ({
|
4
|
+
queued: [],
|
5
|
+
inTransit: []
|
6
|
+
});
|
7
|
+
var useCommandQueue = (opts) => {
|
8
|
+
const onQueueRef = useRef(opts.onQueue);
|
9
|
+
useEffect(() => {
|
10
|
+
onQueueRef.current = opts.onQueue;
|
11
|
+
});
|
12
|
+
const [, rerender] = useState(0);
|
13
|
+
const queueStateRef = useRef(createInitialQueueState());
|
14
|
+
const enqueue = (command) => {
|
15
|
+
queueStateRef.current = {
|
16
|
+
queued: [...queueStateRef.current.queued, command],
|
17
|
+
inTransit: queueStateRef.current.inTransit
|
18
|
+
};
|
19
|
+
rerender((prev) => prev + 1);
|
20
|
+
onQueueRef.current();
|
21
|
+
};
|
22
|
+
const flush = () => {
|
23
|
+
if (queueStateRef.current.queued.length === 0) return [];
|
24
|
+
const queued = queueStateRef.current.queued;
|
25
|
+
queueStateRef.current = {
|
26
|
+
queued: [],
|
27
|
+
inTransit: [...queueStateRef.current.inTransit, ...queued]
|
28
|
+
};
|
29
|
+
rerender((prev) => prev + 1);
|
30
|
+
return queued;
|
31
|
+
};
|
32
|
+
const markDelivered = () => {
|
33
|
+
queueStateRef.current = { ...queueStateRef.current, inTransit: [] };
|
34
|
+
rerender((prev) => prev + 1);
|
35
|
+
};
|
36
|
+
const reset = useCallback(() => {
|
37
|
+
queueStateRef.current = createInitialQueueState();
|
38
|
+
rerender((prev) => prev + 1);
|
39
|
+
}, []);
|
40
|
+
return {
|
41
|
+
state: queueStateRef.current,
|
42
|
+
enqueue,
|
43
|
+
flush,
|
44
|
+
markDelivered,
|
45
|
+
reset
|
46
|
+
};
|
47
|
+
};
|
48
|
+
export {
|
49
|
+
createInitialQueueState,
|
50
|
+
useCommandQueue
|
51
|
+
};
|
52
|
+
//# sourceMappingURL=commandQueue.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.ts"],"sourcesContent":["import { useState, useCallback, useRef, useEffect } from \"react\";\nimport {\n AssistantTransportCommand,\n CommandQueueState,\n QueuedCommand,\n} from \"./types\";\n\nexport const createInitialQueueState = (): CommandQueueState => ({\n queued: [],\n inTransit: [],\n});\n\nexport const useCommandQueue = (opts: { onQueue: () => void }) => {\n const onQueueRef = useRef(opts.onQueue);\n useEffect(() => {\n onQueueRef.current = opts.onQueue;\n });\n\n const [, rerender] = useState(0);\n const queueStateRef = useRef<CommandQueueState>(createInitialQueueState());\n\n const enqueue = (command: AssistantTransportCommand) => {\n queueStateRef.current = {\n queued: [...queueStateRef.current.queued, command],\n inTransit: queueStateRef.current.inTransit,\n };\n rerender((prev) => prev + 1);\n\n onQueueRef.current();\n };\n\n const flush = (): QueuedCommand[] => {\n if (queueStateRef.current.queued.length === 0) return [];\n\n const queued = queueStateRef.current.queued;\n queueStateRef.current = {\n queued: [],\n inTransit: [...queueStateRef.current.inTransit, ...queued],\n };\n rerender((prev) => prev + 1);\n\n return queued;\n };\n\n const markDelivered = () => {\n queueStateRef.current = { ...queueStateRef.current, inTransit: [] };\n rerender((prev) => prev + 1);\n };\n\n const reset = useCallback(() => {\n queueStateRef.current = createInitialQueueState();\n rerender((prev) => prev + 1);\n }, []);\n\n return {\n state: queueStateRef.current,\n enqueue,\n flush,\n markDelivered,\n reset,\n };\n};\n"],"mappings":";AAAA,SAAS,UAAU,aAAa,QAAQ,iBAAiB;AAOlD,IAAM,0BAA0B,OAA0B;AAAA,EAC/D,QAAQ,CAAC;AAAA,EACT,WAAW,CAAC;AACd;AAEO,IAAM,kBAAkB,CAAC,SAAkC;AAChE,QAAM,aAAa,OAAO,KAAK,OAAO;AACtC,YAAU,MAAM;AACd,eAAW,UAAU,KAAK;AAAA,EAC5B,CAAC;AAED,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC;AAC/B,QAAM,gBAAgB,OAA0B,wBAAwB,CAAC;AAEzE,QAAM,UAAU,CAAC,YAAuC;AACtD,kBAAc,UAAU;AAAA,MACtB,QAAQ,CAAC,GAAG,cAAc,QAAQ,QAAQ,OAAO;AAAA,MACjD,WAAW,cAAc,QAAQ;AAAA,IACnC;AACA,aAAS,CAAC,SAAS,OAAO,CAAC;AAE3B,eAAW,QAAQ;AAAA,EACrB;AAEA,QAAM,QAAQ,MAAuB;AACnC,QAAI,cAAc,QAAQ,OAAO,WAAW,EAAG,QAAO,CAAC;AAEvD,UAAM,SAAS,cAAc,QAAQ;AACrC,kBAAc,UAAU;AAAA,MACtB,QAAQ,CAAC;AAAA,MACT,WAAW,CAAC,GAAG,cAAc,QAAQ,WAAW,GAAG,MAAM;AAAA,IAC3D;AACA,aAAS,CAAC,SAAS,OAAO,CAAC;AAE3B,WAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,MAAM;AAC1B,kBAAc,UAAU,EAAE,GAAG,cAAc,SAAS,WAAW,CAAC,EAAE;AAClE,aAAS,CAAC,SAAS,OAAO,CAAC;AAAA,EAC7B;AAEA,QAAM,QAAQ,YAAY,MAAM;AAC9B,kBAAc,UAAU,wBAAwB;AAChD,aAAS,CAAC,SAAS,OAAO,CAAC;AAAA,EAC7B,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL,OAAO,cAAc;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,YAAY,EAAE,oCAAoC,EAAE,MAAM,SAAS,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/index.ts"],"sourcesContent":["export { useAssistantTransportRuntime } from \"./useAssistantTransportRuntime\";\nexport type { AssistantTransportConnectionMetadata } from \"./types\";\n"],"mappings":";AAAA,SAAS,oCAAoC;","names":[]}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export type RunManager = Readonly<{
|
2
|
+
isRunning: boolean;
|
3
|
+
schedule: () => void;
|
4
|
+
cancel: () => void;
|
5
|
+
}>;
|
6
|
+
export declare function useRunManager(config: {
|
7
|
+
onRun: (signal: AbortSignal) => Promise<void>;
|
8
|
+
onFinish?: (() => void) | undefined;
|
9
|
+
onError?: ((error: Error) => void) | undefined;
|
10
|
+
}): RunManager;
|
11
|
+
//# sourceMappingURL=runManager.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"runManager.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC,CAAC;AAEH,wBAAgB,aAAa,CAAC,MAAM,EAAE;IACpC,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,QAAQ,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACpC,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CAChD,GAAG,UAAU,CAqDb"}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
// src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts
|
2
|
+
import { useCallback, useRef, useState } from "react";
|
3
|
+
import { useLatestRef } from "./useLatestRef.js";
|
4
|
+
function useRunManager(config) {
|
5
|
+
const [isRunning, setIsRunning] = useState(false);
|
6
|
+
const stateRef = useRef({
|
7
|
+
pending: false,
|
8
|
+
abortController: null
|
9
|
+
});
|
10
|
+
const onRunRef = useLatestRef(config.onRun);
|
11
|
+
const onFinishRef = useLatestRef(config.onFinish);
|
12
|
+
const onErrorRef = useLatestRef(config.onError);
|
13
|
+
const startRun = useCallback(() => {
|
14
|
+
setIsRunning(true);
|
15
|
+
stateRef.current.pending = false;
|
16
|
+
const ac = new AbortController();
|
17
|
+
stateRef.current.abortController = ac;
|
18
|
+
queueMicrotask(async () => {
|
19
|
+
try {
|
20
|
+
await onRunRef.current(ac.signal);
|
21
|
+
} catch (error) {
|
22
|
+
stateRef.current.pending = false;
|
23
|
+
onErrorRef.current?.(error);
|
24
|
+
} finally {
|
25
|
+
onFinishRef.current?.();
|
26
|
+
if (stateRef.current.pending) {
|
27
|
+
startRun();
|
28
|
+
} else {
|
29
|
+
setIsRunning(false);
|
30
|
+
stateRef.current.abortController = null;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
});
|
34
|
+
}, [onRunRef, onFinishRef]);
|
35
|
+
const schedule = useCallback(() => {
|
36
|
+
if (stateRef.current.abortController) {
|
37
|
+
stateRef.current.pending = true;
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
startRun();
|
41
|
+
}, [startRun]);
|
42
|
+
const cancel = useCallback(() => {
|
43
|
+
stateRef.current.pending = false;
|
44
|
+
stateRef.current.abortController?.abort();
|
45
|
+
}, []);
|
46
|
+
return {
|
47
|
+
isRunning,
|
48
|
+
schedule,
|
49
|
+
cancel
|
50
|
+
};
|
51
|
+
}
|
52
|
+
export {
|
53
|
+
useRunManager
|
54
|
+
};
|
55
|
+
//# sourceMappingURL=runManager.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts"],"sourcesContent":["import { useCallback, useRef, useState } from \"react\";\nimport { useLatestRef } from \"./useLatestRef\";\n\nexport type RunManager = Readonly<{\n isRunning: boolean;\n schedule: () => void;\n cancel: () => void;\n}>;\n\nexport function useRunManager(config: {\n onRun: (signal: AbortSignal) => Promise<void>;\n onFinish?: (() => void) | undefined;\n onError?: ((error: Error) => void) | undefined;\n}): RunManager {\n const [isRunning, setIsRunning] = useState(false);\n const stateRef = useRef({\n pending: false,\n abortController: null as AbortController | null,\n });\n const onRunRef = useLatestRef(config.onRun);\n const onFinishRef = useLatestRef(config.onFinish);\n const onErrorRef = useLatestRef(config.onError);\n\n const startRun = useCallback(() => {\n setIsRunning(true);\n stateRef.current.pending = false;\n const ac = new AbortController();\n stateRef.current.abortController = ac;\n\n queueMicrotask(async () => {\n try {\n await onRunRef.current(ac.signal);\n } catch (error) {\n stateRef.current.pending = false;\n onErrorRef.current?.(error as Error);\n } finally {\n onFinishRef.current?.();\n if (stateRef.current.pending) {\n startRun();\n } else {\n setIsRunning(false);\n stateRef.current.abortController = null;\n }\n }\n });\n }, [onRunRef, onFinishRef]);\n\n const schedule = useCallback(() => {\n if (stateRef.current.abortController) {\n // Coalesce multiple schedules while running into a single follow-up run.\n stateRef.current.pending = true;\n return;\n }\n startRun();\n }, [startRun]);\n\n const cancel = useCallback(() => {\n stateRef.current.pending = false;\n stateRef.current.abortController?.abort();\n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 -0,0 +1,66 @@
|
|
1
|
+
import { ReadonlyJSONValue } from "assistant-stream/utils";
|
2
|
+
import { ThreadMessage } from "../../../types";
|
3
|
+
import { AttachmentAdapter, ThreadHistoryAdapter } from "..";
|
4
|
+
export type TextPart = {
|
5
|
+
readonly type: "text";
|
6
|
+
readonly text: string;
|
7
|
+
};
|
8
|
+
export type ImagePart = {
|
9
|
+
readonly type: "image";
|
10
|
+
readonly image: string;
|
11
|
+
};
|
12
|
+
export type UserMessagePart = TextPart | ImagePart;
|
13
|
+
export type AddMessageCommand = {
|
14
|
+
readonly type: "add-message";
|
15
|
+
readonly message: {
|
16
|
+
readonly role: "user";
|
17
|
+
readonly parts: readonly UserMessagePart[];
|
18
|
+
};
|
19
|
+
};
|
20
|
+
export type AddToolResultCommand = {
|
21
|
+
readonly type: "add-tool-result";
|
22
|
+
readonly toolCallId: string;
|
23
|
+
readonly toolName: string;
|
24
|
+
readonly result: ReadonlyJSONValue;
|
25
|
+
readonly isError: boolean;
|
26
|
+
readonly artifact?: ReadonlyJSONValue;
|
27
|
+
};
|
28
|
+
export type AssistantTransportCommand = AddMessageCommand | AddToolResultCommand;
|
29
|
+
export type AssistantTransportState = {
|
30
|
+
readonly messages: readonly ThreadMessage[];
|
31
|
+
readonly isRunning: boolean;
|
32
|
+
};
|
33
|
+
export type AssistantTransportConnectionMetadata = {
|
34
|
+
pendingCommands: AssistantTransportCommand[];
|
35
|
+
isSending: boolean;
|
36
|
+
};
|
37
|
+
export type AssistantTransportStateConverter<T> = (state: T, connectionMetadata: AssistantTransportConnectionMetadata) => AssistantTransportState;
|
38
|
+
export type CommandQueueState = {
|
39
|
+
queued: AssistantTransportCommand[];
|
40
|
+
inTransit: AssistantTransportCommand[];
|
41
|
+
};
|
42
|
+
export type QueuedCommand = AssistantTransportCommand;
|
43
|
+
export type HeadersValue = Record<string, string> | Headers;
|
44
|
+
export type AssistantTransportOptions<T> = {
|
45
|
+
initialState: T;
|
46
|
+
api: string;
|
47
|
+
resumeApi?: string;
|
48
|
+
converter: AssistantTransportStateConverter<T>;
|
49
|
+
headers: HeadersValue | (() => Promise<HeadersValue>);
|
50
|
+
body?: object;
|
51
|
+
onResponse?: (response: Response) => void;
|
52
|
+
onFinish?: () => void;
|
53
|
+
onError?: (error: Error, params: {
|
54
|
+
commands: AssistantTransportCommand[];
|
55
|
+
updateState: (updater: (state: T) => T) => void;
|
56
|
+
}) => void;
|
57
|
+
onCancel?: (params: {
|
58
|
+
commands: AssistantTransportCommand[];
|
59
|
+
updateState: (updater: (state: T) => T) => void;
|
60
|
+
}) => void;
|
61
|
+
adapters?: {
|
62
|
+
attachments?: AttachmentAdapter | undefined;
|
63
|
+
history?: ThreadHistoryAdapter | undefined;
|
64
|
+
};
|
65
|
+
};
|
66
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,IAAI,CAAC;AAG7D,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,SAAS,CAAC;AAGnD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE;QAChB,QA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CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,gCAAgC,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO,EAAE,YAAY,GAAG,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,OAAO,CAAC,EAAE,CACR,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE;QACN,QAAQ,EAAE,yBAAyB,EAAE,CAAC;QACtC,WAAW,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;KACjD,KACE,IAAI,CAAC;IACV,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE;QAClB,QAAQ,EAAE,yBAAyB,EAAE,CAAC;QACtC,WAAW,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;KACjD,KAAK,IAAI,CAAC;IACX,QAAQ,CAAC,EAAE;QACT,WAAW,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;QAC5C,OAAO,CAAC,EAAE,oBAAoB,GAAG,SAAS,CAAC;KAC5C,CAAC;CACH,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
import { AssistantRuntime } from "../../runtime/AssistantRuntime";
|
2
|
+
import { AssistantTransportOptions } from "./types";
|
3
|
+
/**
|
4
|
+
* @alpha This is an experimental API that is subject to change.
|
5
|
+
*/
|
6
|
+
export declare const useAssistantTransportRuntime: <T>(options: AssistantTransportOptions<T>) => AssistantRuntime;
|
7
|
+
//# sourceMappingURL=useAssistantTransportRuntime.d.ts.map
|
package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useAssistantTransportRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAQlE,OAAO,EACL,yBAAyB,EAK1B,MAAM,SAAS,CAAC;AAmMjB;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,EAC5C,SAAS,yBAAyB,CAAC,CAAC,CAAC,KACpC,gBAQF,CAAC"}
|
@@ -0,0 +1,185 @@
|
|
1
|
+
"use client";
|
2
|
+
|
3
|
+
// src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx
|
4
|
+
import {
|
5
|
+
asAsyncIterableStream
|
6
|
+
} from "assistant-stream/utils";
|
7
|
+
import { useExternalStoreRuntime } from "../external-store/useExternalStoreRuntime.js";
|
8
|
+
import { useState, useRef, useMemo } from "react";
|
9
|
+
import {
|
10
|
+
AssistantMessageAccumulator,
|
11
|
+
DataStreamDecoder,
|
12
|
+
unstable_createInitialMessage as createInitialMessage
|
13
|
+
} from "assistant-stream";
|
14
|
+
import { useCommandQueue } from "./commandQueue.js";
|
15
|
+
import { useRunManager } from "./runManager.js";
|
16
|
+
import { useConvertedState } from "./useConvertedState.js";
|
17
|
+
import { useToolInvocations } from "./useToolInvocations.js";
|
18
|
+
import { toAISDKTools, getEnabledTools, createRequestHeaders } from "./utils.js";
|
19
|
+
import { useRemoteThreadListRuntime } from "../remote-thread-list/useRemoteThreadListRuntime.js";
|
20
|
+
import { InMemoryThreadListAdapter } from "../remote-thread-list/adapter/in-memory.js";
|
21
|
+
var useAssistantTransportThreadRuntime = (options) => {
|
22
|
+
const agentStateRef = useRef(options.initialState);
|
23
|
+
const [, rerender] = useState(0);
|
24
|
+
const resumeFlagRef = useRef(false);
|
25
|
+
const commandQueue = useCommandQueue({
|
26
|
+
onQueue: () => runManager.schedule()
|
27
|
+
});
|
28
|
+
const runManager = useRunManager({
|
29
|
+
onRun: async (signal) => {
|
30
|
+
const isResume = resumeFlagRef.current;
|
31
|
+
resumeFlagRef.current = false;
|
32
|
+
const commands = isResume ? [] : commandQueue.flush();
|
33
|
+
if (commands.length === 0 && !isResume)
|
34
|
+
throw new Error("No commands to send");
|
35
|
+
const headers = await createRequestHeaders(options.headers);
|
36
|
+
const context = runtime.thread.getModelContext();
|
37
|
+
const response = await fetch(
|
38
|
+
isResume ? options.resumeApi : options.api,
|
39
|
+
{
|
40
|
+
method: "POST",
|
41
|
+
headers,
|
42
|
+
body: JSON.stringify({
|
43
|
+
commands,
|
44
|
+
state: agentStateRef.current,
|
45
|
+
system: context.system,
|
46
|
+
tools: context.tools ? toAISDKTools(getEnabledTools(context.tools)) : void 0,
|
47
|
+
...context.callSettings,
|
48
|
+
...context.config,
|
49
|
+
...options.body
|
50
|
+
}),
|
51
|
+
signal
|
52
|
+
}
|
53
|
+
);
|
54
|
+
options.onResponse?.(response);
|
55
|
+
if (!response.ok) {
|
56
|
+
throw new Error(`Status ${response.status}: ${await response.text()}`);
|
57
|
+
}
|
58
|
+
if (!response.body) {
|
59
|
+
throw new Error("Response body is null");
|
60
|
+
}
|
61
|
+
const stream = response.body.pipeThrough(new DataStreamDecoder()).pipeThrough(
|
62
|
+
new AssistantMessageAccumulator({
|
63
|
+
initialMessage: createInitialMessage({
|
64
|
+
unstable_state: agentStateRef.current ?? null
|
65
|
+
})
|
66
|
+
})
|
67
|
+
);
|
68
|
+
let markedDelivered = false;
|
69
|
+
for await (const chunk of asAsyncIterableStream(stream)) {
|
70
|
+
if (chunk.metadata.unstable_state === agentStateRef.current) continue;
|
71
|
+
if (!markedDelivered) {
|
72
|
+
commandQueue.markDelivered();
|
73
|
+
markedDelivered = true;
|
74
|
+
}
|
75
|
+
agentStateRef.current = chunk.metadata.unstable_state;
|
76
|
+
rerender((prev) => prev + 1);
|
77
|
+
}
|
78
|
+
},
|
79
|
+
onFinish: options.onFinish,
|
80
|
+
onError: (error) => {
|
81
|
+
if (error instanceof Error && error.name === "AbortError") {
|
82
|
+
const cmds = [
|
83
|
+
...commandQueue.state.inTransit,
|
84
|
+
...commandQueue.state.queued
|
85
|
+
];
|
86
|
+
options.onCancel?.({
|
87
|
+
commands: cmds,
|
88
|
+
updateState: (updater) => {
|
89
|
+
agentStateRef.current = updater(agentStateRef.current);
|
90
|
+
rerender((prev) => prev + 1);
|
91
|
+
}
|
92
|
+
});
|
93
|
+
commandQueue.reset();
|
94
|
+
} else {
|
95
|
+
const cmds = [...commandQueue.state.inTransit];
|
96
|
+
options.onError?.(error, {
|
97
|
+
commands: cmds,
|
98
|
+
updateState: (updater) => {
|
99
|
+
agentStateRef.current = updater(agentStateRef.current);
|
100
|
+
rerender((prev) => prev + 1);
|
101
|
+
}
|
102
|
+
});
|
103
|
+
commandQueue.markDelivered();
|
104
|
+
}
|
105
|
+
}
|
106
|
+
});
|
107
|
+
const pendingCommands = useMemo(
|
108
|
+
() => [...commandQueue.state.inTransit, ...commandQueue.state.queued],
|
109
|
+
[commandQueue.state]
|
110
|
+
);
|
111
|
+
const converted = useConvertedState(
|
112
|
+
options.converter,
|
113
|
+
agentStateRef.current,
|
114
|
+
pendingCommands,
|
115
|
+
runManager.isRunning
|
116
|
+
);
|
117
|
+
const runtime = useExternalStoreRuntime({
|
118
|
+
isRunning: converted.isRunning,
|
119
|
+
messages: converted.messages,
|
120
|
+
adapters: options.adapters,
|
121
|
+
onNew: async (message) => {
|
122
|
+
const parts = [];
|
123
|
+
for (const content of message.content) {
|
124
|
+
if (content.type === "text") {
|
125
|
+
parts.push({ type: "text", text: content.text });
|
126
|
+
} else if (content.type === "image") {
|
127
|
+
parts.push({ type: "image", image: content.image });
|
128
|
+
}
|
129
|
+
}
|
130
|
+
const command = {
|
131
|
+
type: "add-message",
|
132
|
+
message: {
|
133
|
+
role: "user",
|
134
|
+
parts
|
135
|
+
}
|
136
|
+
};
|
137
|
+
commandQueue.enqueue(command);
|
138
|
+
},
|
139
|
+
onCancel: async () => {
|
140
|
+
runManager.cancel();
|
141
|
+
toolInvocations.abort();
|
142
|
+
},
|
143
|
+
onResume: async () => {
|
144
|
+
if (!options.resumeApi)
|
145
|
+
throw new Error("Must pass resumeApi to options to resume runs");
|
146
|
+
resumeFlagRef.current = true;
|
147
|
+
runManager.schedule();
|
148
|
+
},
|
149
|
+
onAddToolResult: async (toolOptions) => {
|
150
|
+
const command = {
|
151
|
+
type: "add-tool-result",
|
152
|
+
toolCallId: toolOptions.toolCallId,
|
153
|
+
result: toolOptions.result,
|
154
|
+
toolName: toolOptions.toolName,
|
155
|
+
isError: toolOptions.isError,
|
156
|
+
...toolOptions.artifact && { artifact: toolOptions.artifact }
|
157
|
+
};
|
158
|
+
commandQueue.enqueue(command);
|
159
|
+
},
|
160
|
+
onLoadExternalState: async (state) => {
|
161
|
+
agentStateRef.current = state;
|
162
|
+
toolInvocations.reset();
|
163
|
+
rerender((prev) => prev + 1);
|
164
|
+
}
|
165
|
+
});
|
166
|
+
const toolInvocations = useToolInvocations({
|
167
|
+
state: converted,
|
168
|
+
getTools: () => runtime.thread.getModelContext().tools,
|
169
|
+
onResult: commandQueue.enqueue
|
170
|
+
});
|
171
|
+
return runtime;
|
172
|
+
};
|
173
|
+
var useAssistantTransportRuntime = (options) => {
|
174
|
+
const runtime = useRemoteThreadListRuntime({
|
175
|
+
runtimeHook: function RuntimeHook() {
|
176
|
+
return useAssistantTransportThreadRuntime(options);
|
177
|
+
},
|
178
|
+
adapter: new InMemoryThreadListAdapter()
|
179
|
+
});
|
180
|
+
return runtime;
|
181
|
+
};
|
182
|
+
export {
|
183
|
+
useAssistantTransportRuntime
|
184
|
+
};
|
185
|
+
//# sourceMappingURL=useAssistantTransportRuntime.js.map
|
package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n asAsyncIterableStream,\n} from \"assistant-stream/utils\";\nimport { AppendMessage } from \"../../../types\";\nimport { useExternalStoreRuntime } from \"../external-store/useExternalStoreRuntime\";\nimport { AssistantRuntime } from \"../../runtime/AssistantRuntime\";\nimport { AddToolResultOptions } from \"../core\";\nimport { useState, useRef, useMemo } from \"react\";\nimport {\n AssistantMessageAccumulator,\n DataStreamDecoder,\n unstable_createInitialMessage as createInitialMessage,\n} from \"assistant-stream\";\nimport {\n AssistantTransportOptions,\n AddMessageCommand,\n AddToolResultCommand,\n UserMessagePart,\n QueuedCommand,\n} from \"./types\";\nimport { useCommandQueue } from \"./commandQueue\";\nimport { useRunManager } from \"./runManager\";\nimport { useConvertedState } from \"./useConvertedState\";\nimport { useToolInvocations } from \"./useToolInvocations\";\nimport { toAISDKTools, getEnabledTools, createRequestHeaders } from \"./utils\";\nimport { useRemoteThreadListRuntime } from \"../remote-thread-list/useRemoteThreadListRuntime\";\nimport { InMemoryThreadListAdapter } from \"../remote-thread-list/adapter/in-memory\";\n\nconst useAssistantTransportThreadRuntime = <T,>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const agentStateRef = useRef(options.initialState);\n const [, rerender] = useState(0);\n const resumeFlagRef = useRef(false);\n const commandQueue = useCommandQueue({\n onQueue: () => runManager.schedule(),\n });\n\n const runManager = useRunManager({\n onRun: async (signal: AbortSignal) => {\n const isResume = resumeFlagRef.current;\n resumeFlagRef.current = false;\n const commands: QueuedCommand[] = isResume ? [] : commandQueue.flush();\n if (commands.length === 0 && !isResume)\n throw new Error(\"No commands to send\");\n\n const headers = await createRequestHeaders(options.headers);\n const context = runtime.thread.getModelContext();\n\n const response = await fetch(\n isResume ? options.resumeApi! : options.api,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n commands,\n state: agentStateRef.current,\n system: context.system,\n tools: context.tools\n ? toAISDKTools(getEnabledTools(context.tools))\n : undefined,\n ...context.callSettings,\n ...context.config,\n ...options.body,\n }),\n signal,\n },\n );\n\n options.onResponse?.(response);\n\n if (!response.ok) {\n throw new Error(`Status ${response.status}: ${await response.text()}`);\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n const stream = response.body\n .pipeThrough(new DataStreamDecoder())\n .pipeThrough(\n new AssistantMessageAccumulator({\n initialMessage: createInitialMessage({\n unstable_state:\n (agentStateRef.current as ReadonlyJSONValue) ?? null,\n }),\n }),\n );\n\n let markedDelivered = false;\n\n for await (const chunk of asAsyncIterableStream(stream)) {\n if (chunk.metadata.unstable_state === agentStateRef.current) continue;\n\n if (!markedDelivered) {\n commandQueue.markDelivered();\n markedDelivered = true;\n }\n\n agentStateRef.current = chunk.metadata.unstable_state as T;\n rerender((prev) => prev + 1);\n }\n },\n onFinish: options.onFinish,\n onError: (error) => {\n if (error instanceof Error && error.name === \"AbortError\") {\n const cmds = [\n ...commandQueue.state.inTransit,\n ...commandQueue.state.queued,\n ];\n options.onCancel?.({\n commands: cmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n\n commandQueue.reset();\n } else {\n const cmds = [...commandQueue.state.inTransit];\n options.onError?.(error as Error, {\n commands: cmds,\n updateState: (updater) => {\n agentStateRef.current = updater(agentStateRef.current);\n rerender((prev) => prev + 1);\n },\n });\n commandQueue.markDelivered();\n }\n },\n });\n\n // Reactive conversion of agent state + connection metadata → UI state\n const pendingCommands = useMemo(\n () => [...commandQueue.state.inTransit, ...commandQueue.state.queued],\n [commandQueue.state],\n );\n const converted = useConvertedState(\n options.converter,\n agentStateRef.current,\n pendingCommands,\n runManager.isRunning,\n );\n\n // Create runtime\n const runtime = useExternalStoreRuntime({\n isRunning: converted.isRunning,\n messages: converted.messages,\n adapters: options.adapters,\n onNew: async (message: AppendMessage): Promise<void> => {\n // Convert AppendMessage to AddMessageCommand\n const parts: UserMessagePart[] = [];\n\n for (const content of message.content) {\n if (content.type === \"text\") {\n parts.push({ type: \"text\", text: content.text });\n } else if (content.type === \"image\") {\n parts.push({ type: \"image\", image: content.image });\n }\n }\n\n const command: AddMessageCommand = {\n type: \"add-message\",\n message: {\n role: \"user\",\n parts,\n },\n };\n\n commandQueue.enqueue(command);\n },\n onCancel: async () => {\n runManager.cancel();\n toolInvocations.abort();\n },\n onResume: async () => {\n if (!options.resumeApi)\n throw new Error(\"Must pass resumeApi to options to resume runs\");\n\n resumeFlagRef.current = true;\n runManager.schedule();\n },\n onAddToolResult: async (\n toolOptions: AddToolResultOptions,\n ): Promise<void> => {\n const command: AddToolResultCommand = {\n type: \"add-tool-result\",\n toolCallId: toolOptions.toolCallId,\n result: toolOptions.result as ReadonlyJSONObject,\n toolName: toolOptions.toolName,\n isError: toolOptions.isError,\n ...(toolOptions.artifact && { artifact: toolOptions.artifact }),\n };\n\n commandQueue.enqueue(command);\n },\n onLoadExternalState: async (state) => {\n agentStateRef.current = state as T;\n toolInvocations.reset();\n rerender((prev) => prev + 1);\n },\n });\n\n const toolInvocations = useToolInvocations({\n state: converted,\n getTools: () => runtime.thread.getModelContext().tools,\n onResult: commandQueue.enqueue,\n });\n\n return runtime;\n};\n\n/**\n * @alpha This is an experimental API that is subject to change.\n */\nexport const useAssistantTransportRuntime = <T,>(\n options: AssistantTransportOptions<T>,\n): AssistantRuntime => {\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useAssistantTransportThreadRuntime(options);\n },\n adapter: new InMemoryThreadListAdapter(),\n });\n return runtime;\n};\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,OACK;AAEP,S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AAY;AAAA,QACtB,SAAS,YAAY;AAAA,QACrB,GAAI,YAAY,YAAY,EAAE,UAAU,YAAY,SAAS;AAAA,MAC/D;AAEA,mBAAa,QAAQ,OAAO;AAAA,IAC9B;AAAA,IACA,qBAAqB,OAAO,UAAU;AACpC,oBAAc,UAAU;AACxB,sBAAgB,MAAM;AACtB,eAAS,CAAC,SAAS,OAAO,CAAC;AAAA,IAC7B;AAAA,EACF,CAAC;AAED,QAAM,kBAAkB,mBAAmB;AAAA,IACzC,OAAO;AAAA,IACP,UAAU,MAAM,QAAQ,OAAO,gBAAgB,EAAE;AAAA,IACjD,UAAU,aAAa;AAAA,EACzB,CAAC;AAED,SAAO;AACT;AAKO,IAAM,+BAA+B,CAC1C,YACqB;AACrB,QAAM,UAAU,2BAA2B;AAAA,IACzC,aAAa,SAAS,cAAc;AAClC,aAAO,mCAAmC,OAAO;AAAA,IACnD;AAAA,IACA,SAAS,IAAI,0BAA0B;AAAA,EACzC,CAAC;AACD,SAAO;AACT;","names":[]}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import type { AssistantTransportCommand, AssistantTransportState, AssistantTransportStateConverter } from "./types";
|
2
|
+
export declare function useConvertedState<T>(converter: AssistantTransportStateConverter<T>, agentState: T, pendingCommands: AssistantTransportCommand[], isSending: boolean): AssistantTransportState;
|
3
|
+
//# sourceMappingURL=useConvertedState.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useConvertedState.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,yBAAyB,EACzB,uBAAuB,EACvB,gCAAgC,EACjC,MAAM,SAAS,CAAC;AAEjB,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,SAAS,EAAE,gCAAgC,CAAC,CAAC,CAAC,EAC9C,UAAU,EAAE,CAAC,EACb,eAAe,EAAE,yBAAyB,EAAE,EAC5C,SAAS,EAAE,OAAO,GACjB,uBAAuB,CAKzB"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts
|
2
|
+
import { useMemo } from "react";
|
3
|
+
function useConvertedState(converter, agentState, pendingCommands, isSending) {
|
4
|
+
return useMemo(
|
5
|
+
() => converter(agentState, { pendingCommands, isSending }),
|
6
|
+
[converter, agentState, pendingCommands, isSending]
|
7
|
+
);
|
8
|
+
}
|
9
|
+
export {
|
10
|
+
useConvertedState
|
11
|
+
};
|
12
|
+
//# sourceMappingURL=useConvertedState.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport type {\n AssistantTransportCommand,\n AssistantTransportState,\n AssistantTransportStateConverter,\n} from \"./types\";\n\nexport function useConvertedState<T>(\n converter: AssistantTransportStateConverter<T>,\n agentState: T,\n pendingCommands: AssistantTransportCommand[],\n isSending: boolean,\n): AssistantTransportState {\n return useMemo(\n () => converter(agentState, { pendingCommands, isSending }),\n [converter, agentState, pendingCommands, isSending],\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe;AAOjB,SAAS,kBACd,WACA,YACA,iBACA,WACyB;AACzB,SAAO;AAAA,IACL,MAAM,UAAU,YAAY,EAAE,iBAAiB,UAAU,CAAC;AAAA,IAC1D,CAAC,WAAW,YAAY,iBAAiB,SAAS;AAAA,EACpD;AACF;","names":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useLatestRef.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useLatestRef.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAKxB;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAC7B"}
|