@assistant-ui/core 0.2.9 → 0.2.11
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/adapters/attachment.d.ts.map +1 -1
- package/dist/adapters/attachment.js +22 -12
- package/dist/adapters/attachment.js.map +1 -1
- package/dist/adapters/directive-formatter.js.map +1 -1
- package/dist/adapters/speech.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/registry.js.map +1 -1
- package/dist/model-context/tool.d.ts +1 -1
- package/dist/model-context/tool.js +1 -1
- package/dist/model-context/tool.js.map +1 -1
- package/dist/model-context/types.js +17 -2
- package/dist/model-context/types.js.map +1 -1
- package/dist/react/AssistantProvider.js +1 -1
- package/dist/react/AssistantRuntimeProvider.d.ts +1 -1
- package/dist/react/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/react/AssistantRuntimeProvider.js +1 -1
- package/dist/react/RuntimeAdapter.js +4 -2
- package/dist/react/RuntimeAdapter.js.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +13 -3
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/DataRenderers.d.ts.map +1 -1
- package/dist/react/client/DataRenderers.js +6 -5
- package/dist/react/client/DataRenderers.js.map +1 -1
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js +30 -29
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +19 -12
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +10 -5
- package/dist/react/index.js +7 -2
- package/dist/react/model-context/define-mcp-toolkit.d.ts +12 -0
- package/dist/react/model-context/define-mcp-toolkit.d.ts.map +1 -0
- package/dist/react/model-context/define-mcp-toolkit.js +14 -0
- package/dist/react/model-context/define-mcp-toolkit.js.map +1 -0
- package/dist/react/model-context/define-toolkit.d.ts +10 -12
- package/dist/react/model-context/define-toolkit.d.ts.map +1 -1
- package/dist/react/model-context/define-toolkit.js +2 -15
- package/dist/react/model-context/define-toolkit.js.map +1 -1
- package/dist/react/model-context/external-tool.d.ts +14 -0
- package/dist/react/model-context/external-tool.d.ts.map +1 -0
- package/dist/react/model-context/external-tool.js +17 -0
- package/dist/react/model-context/external-tool.js.map +1 -0
- package/dist/react/model-context/human-tool.d.ts +27 -0
- package/dist/react/model-context/human-tool.d.ts.map +1 -0
- package/dist/react/model-context/human-tool.js +30 -0
- package/dist/react/model-context/human-tool.js.map +1 -0
- package/dist/react/model-context/makeAssistantTool.d.ts +8 -0
- package/dist/react/model-context/makeAssistantTool.d.ts.map +1 -1
- package/dist/react/model-context/makeAssistantTool.js +4 -0
- package/dist/react/model-context/makeAssistantTool.js.map +1 -1
- package/dist/react/model-context/makeAssistantToolUI.d.ts +8 -0
- package/dist/react/model-context/makeAssistantToolUI.d.ts.map +1 -1
- package/dist/react/model-context/makeAssistantToolUI.js +4 -0
- package/dist/react/model-context/makeAssistantToolUI.js.map +1 -1
- package/dist/react/model-context/provider-tool.d.ts +15 -0
- package/dist/react/model-context/provider-tool.d.ts.map +1 -0
- package/dist/react/model-context/provider-tool.js +12 -0
- package/dist/react/model-context/provider-tool.js.map +1 -0
- package/dist/react/model-context/stub-tool.d.ts +12 -0
- package/dist/react/model-context/stub-tool.d.ts.map +1 -0
- package/dist/react/model-context/stub-tool.js +15 -0
- package/dist/react/model-context/stub-tool.js.map +1 -0
- package/dist/react/model-context/toolbox.d.ts +64 -17
- package/dist/react/model-context/toolbox.d.ts.map +1 -1
- package/dist/react/model-context/toolbox.js +19 -1
- package/dist/react/model-context/toolbox.js.map +1 -1
- package/dist/react/model-context/useAssistantContext.js +1 -1
- package/dist/react/model-context/useAssistantContext.js.map +1 -1
- package/dist/react/model-context/useAssistantDataUI.js +1 -1
- package/dist/react/model-context/useAssistantDataUI.js.map +1 -1
- package/dist/react/model-context/useAssistantInstructions.js +1 -1
- package/dist/react/model-context/useAssistantInstructions.js.map +1 -1
- package/dist/react/model-context/useAssistantInteractable.js +1 -1
- package/dist/react/model-context/useAssistantInteractable.js.map +1 -1
- package/dist/react/model-context/useAssistantTool.d.ts +11 -1
- package/dist/react/model-context/useAssistantTool.d.ts.map +1 -1
- package/dist/react/model-context/useAssistantTool.js +12 -6
- package/dist/react/model-context/useAssistantTool.js.map +1 -1
- package/dist/react/model-context/useAssistantToolUI.d.ts +13 -4
- package/dist/react/model-context/useAssistantToolUI.d.ts.map +1 -1
- package/dist/react/model-context/useAssistantToolUI.js +7 -4
- package/dist/react/model-context/useAssistantToolUI.js.map +1 -1
- package/dist/react/model-context/useAuiToolOverrides.d.ts +22 -0
- package/dist/react/model-context/useAuiToolOverrides.d.ts.map +1 -0
- package/dist/react/model-context/useAuiToolOverrides.js +31 -0
- package/dist/react/model-context/useAuiToolOverrides.js.map +1 -0
- package/dist/react/model-context/useInlineRender.js +1 -1
- package/dist/react/model-context/useInlineRender.js.map +1 -1
- package/dist/react/model-context/useInteractableState.js +1 -1
- package/dist/react/model-context/useInteractableState.js.map +1 -1
- package/dist/react/model-context/useToolArgsStatus.js +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.js +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarFeedback.js +1 -1
- package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.js +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarSpeak.js +1 -1
- package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +1 -1
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.js +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.js +1 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.js +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerDictate.js +1 -1
- package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.js +1 -1
- package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerCancel.js +1 -1
- package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerSend.js +1 -1
- package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageBranching.js +1 -1
- package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageReload.js +1 -1
- package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemArchive.js +1 -1
- package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemDelete.js +1 -1
- package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js +1 -1
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +1 -1
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListNew.js +1 -1
- package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
- package/dist/react/primitive-hooks/useVoice.js +1 -1
- package/dist/react/primitive-hooks/useVoice.js.map +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.d.ts +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
- package/dist/react/primitives/generativeUI/GenerativeUI.js +1 -1
- package/dist/react/primitives/generativeUI/GenerativeUI.js.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.js +1 -1
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.d.ts +1 -1
- package/dist/react/primitives/message/MessageParts.js +1 -1
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/message/MessageQuote.js +1 -1
- package/dist/react/primitives/part/PartMessages.d.ts +12 -10
- package/dist/react/primitives/part/PartMessages.d.ts.map +1 -1
- package/dist/react/primitives/part/PartMessages.js +13 -11
- package/dist/react/primitives/part/PartMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadSuggestions.js +1 -1
- package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/react/providers/AttachmentByIndexProvider.js.map +1 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
- package/dist/react/providers/MessageByIndexProvider.js.map +1 -1
- package/dist/react/providers/PartByIndexProvider.js.map +1 -1
- package/dist/react/providers/QueueItemByIndexProvider.js.map +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.js +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.js.map +1 -1
- package/dist/react/providers/SuggestionByIndexProvider.js.map +1 -1
- package/dist/react/providers/TextMessagePartProvider.d.ts.map +1 -1
- package/dist/react/providers/TextMessagePartProvider.js +4 -3
- package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
- package/dist/react/providers/ThreadListItemByIndexProvider.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +7 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +8 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +29 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RuntimeAdapterProvider.js +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +10 -3
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/createMessageConverter.d.ts +2 -2
- package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
- package/dist/react/runtimes/createMessageConverter.js.map +1 -1
- package/dist/react/runtimes/external-message-converter.d.ts +4 -3
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +1 -1
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.js +1 -1
- package/dist/react/runtimes/useExternalStoreSharedOptions.js +1 -1
- package/dist/react/runtimes/useLocalRuntime.d.ts +2 -1
- package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.js +4 -3
- package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/utils/groupParts.d.ts +1 -1
- package/dist/react/utils/groupParts.js.map +1 -1
- package/dist/runtime/api/attachment-runtime.js.map +1 -1
- package/dist/runtime/api/composer-runtime.d.ts +8 -2
- package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.js +14 -0
- package/dist/runtime/api/composer-runtime.js.map +1 -1
- package/dist/runtime/api/message-part-runtime.js.map +1 -1
- package/dist/runtime/api/message-runtime.js +1 -1
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.d.ts +2 -0
- package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.js +6 -0
- package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +7 -0
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +4 -0
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +7 -1
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +4 -0
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js +17 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/composer-runtime-core.d.ts +6 -1
- package/dist/runtime/interfaces/composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +1 -0
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +4 -0
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/queue/external-thread-queue-adapter.d.ts +20 -0
- package/dist/runtime/queue/external-thread-queue-adapter.d.ts.map +1 -0
- package/dist/runtime/queue/external-thread-queue-adapter.js +0 -0
- package/dist/runtime/queue/message-queue.d.ts +20 -0
- package/dist/runtime/queue/message-queue.d.ts.map +1 -0
- package/dist/runtime/queue/message-queue.js +97 -0
- package/dist/runtime/queue/message-queue.js.map +1 -0
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/external-store/external-store-adapter.d.ts +5 -1
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +1 -0
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +5 -0
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +4 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +20 -2
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/local/local-runtime-core.js.map +1 -1
- package/dist/runtimes/local/local-runtime-options.d.ts +5 -0
- package/dist/runtimes/local/local-runtime-options.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +7 -0
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +45 -0
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +3 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +3 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts +1 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js +3 -0
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js +3 -0
- package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.js +6 -5
- package/dist/store/clients/chain-of-thought-client.js.map +1 -1
- package/dist/store/clients/model-context-client.d.ts.map +1 -1
- package/dist/store/clients/model-context-client.js +6 -5
- package/dist/store/clients/model-context-client.js.map +1 -1
- package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
- package/dist/store/clients/no-op-composer-client.js +4 -3
- package/dist/store/clients/no-op-composer-client.js.map +1 -1
- package/dist/store/clients/runtime-adapter.d.ts.map +1 -1
- package/dist/store/clients/runtime-adapter.js +7 -6
- package/dist/store/clients/runtime-adapter.js.map +1 -1
- package/dist/store/clients/suggestions.d.ts.map +1 -1
- package/dist/store/clients/suggestions.js +7 -6
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-message-client.d.ts.map +1 -1
- package/dist/store/clients/thread-message-client.js +13 -12
- package/dist/store/clients/thread-message-client.js.map +1 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.js +3 -3
- package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts +12 -5
- package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +32 -16
- package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-part-runtime-client.js +3 -3
- package/dist/store/runtime-clients/message-part-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts +6 -3
- package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +17 -16
- package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +9 -7
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +11 -10
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +15 -14
- package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts +7 -0
- package/dist/store/runtime-clients/useSubscribable.d.ts.map +1 -0
- package/dist/store/runtime-clients/useSubscribable.js +16 -0
- package/dist/store/runtime-clients/useSubscribable.js.map +1 -0
- package/dist/store/scope-registration.d.ts +1 -1
- package/dist/store/scopes/composer.d.ts +1 -1
- package/dist/store/scopes/queue-item.d.ts +2 -1
- package/dist/store/scopes/queue-item.d.ts.map +1 -1
- package/dist/store/scopes/queue-item.js +6 -0
- package/dist/store/scopes/queue-item.js.map +1 -0
- package/dist/store/scopes/thread-list-item.d.ts +1 -0
- package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
- package/dist/store/scopes/thread.d.ts +1 -1
- package/dist/store/scopes/threads.d.ts +1 -1
- package/dist/types/message.d.ts +2 -1
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/composite-context-provider.d.ts +1 -1
- package/dist/utils/composite-context-provider.js +3 -1
- package/dist/utils/composite-context-provider.js.map +1 -1
- package/dist/utils/json/is-json.js.map +1 -1
- package/dist/utils/text.js.map +1 -1
- package/package.json +15 -11
- package/src/adapters/attachment.ts +24 -4
- package/src/index.ts +8 -0
- package/src/model-context/tool.ts +1 -1
- package/src/model-context/types.ts +21 -3
- package/src/react/RuntimeAdapter.ts +6 -4
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +15 -2
- package/src/react/client/DataRenderers.ts +48 -42
- package/src/react/client/Interactables.ts +263 -267
- package/src/react/client/Tools.ts +123 -115
- package/src/react/index.ts +16 -3
- package/src/react/model-context/define-mcp-toolkit.ts +16 -0
- package/src/react/model-context/define-toolkit.test.ts +101 -6
- package/src/react/model-context/define-toolkit.ts +35 -18
- package/src/react/model-context/external-tool.ts +16 -0
- package/src/react/model-context/human-tool.ts +32 -0
- package/src/react/model-context/makeAssistantTool.ts +8 -0
- package/src/react/model-context/makeAssistantToolUI.ts +8 -0
- package/src/react/model-context/provider-tool.ts +30 -0
- package/src/react/model-context/stub-tool.ts +14 -0
- package/src/react/model-context/toolbox.test.ts +182 -0
- package/src/react/model-context/toolbox.ts +191 -23
- package/src/react/model-context/useAssistantTool.ts +28 -8
- package/src/react/model-context/useAssistantToolUI.ts +13 -4
- package/src/react/model-context/useAuiToolOverrides.ts +38 -0
- package/src/react/primitives/message/MessageGroupedParts.tsx +1 -1
- package/src/react/primitives/part/PartMessages.tsx +12 -10
- package/src/react/providers/TextMessagePartProvider.tsx +31 -32
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +43 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +9 -0
- package/src/react/runtimes/createMessageConverter.ts +2 -1
- package/src/react/runtimes/external-message-converter.ts +5 -3
- package/src/react/runtimes/useLocalRuntime.ts +2 -0
- package/src/runtime/api/composer-runtime.ts +26 -0
- package/src/runtime/api/thread-list-item-runtime.ts +15 -0
- package/src/runtime/base/base-composer-runtime-core.ts +11 -0
- package/src/runtime/base/default-thread-composer-runtime-core.ts +22 -0
- package/src/runtime/interfaces/composer-runtime-core.ts +7 -0
- package/src/runtime/interfaces/thread-list-runtime-core.ts +4 -0
- package/src/runtime/interfaces/thread-runtime-core.ts +5 -0
- package/src/runtime/queue/external-thread-queue-adapter.ts +14 -0
- package/src/runtime/queue/message-queue.ts +128 -0
- package/src/runtimes/external-store/external-store-adapter.ts +10 -0
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +13 -0
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +31 -2
- package/src/runtimes/local/local-runtime-options.ts +6 -0
- package/src/runtimes/local/local-thread-runtime-core.ts +70 -0
- package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +4 -0
- package/src/runtimes/remote-thread-list/adapter/in-memory.ts +4 -0
- package/src/runtimes/remote-thread-list/empty-thread-core.ts +4 -0
- package/src/runtimes/remote-thread-list/types.ts +4 -0
- package/src/store/clients/chain-of-thought-client.ts +24 -25
- package/src/store/clients/model-context-client.test.ts +87 -2
- package/src/store/clients/model-context-client.ts +22 -19
- package/src/store/clients/no-op-composer-client.ts +69 -66
- package/src/store/clients/runtime-adapter.ts +9 -6
- package/src/store/clients/suggestions.ts +41 -40
- package/src/store/clients/thread-message-client.ts +127 -132
- package/src/store/runtime-clients/attachment-runtime-client.ts +7 -3
- package/src/store/runtime-clients/composer-runtime-client.ts +142 -113
- package/src/store/runtime-clients/message-part-runtime-client.ts +16 -14
- package/src/store/runtime-clients/message-runtime-client.ts +124 -122
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +44 -44
- package/src/store/runtime-clients/thread-list-runtime-client.ts +83 -80
- package/src/store/runtime-clients/thread-runtime-client.ts +113 -119
- package/src/store/runtime-clients/{tap-subscribable.ts → useSubscribable.ts} +4 -4
- package/src/store/scopes/queue-item.ts +2 -0
- package/src/store/scopes/thread-list-item.ts +1 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-custom-metadata.test.ts +69 -1
- package/src/tests/attachment-adapters.test.ts +86 -0
- package/src/tests/external-store-thread-runtime-core.test.ts +125 -0
- package/src/tests/message-queue.test.ts +168 -0
- package/src/tests/thread-list-runtime-getLoadThreadsPromise.test.ts +1 -0
- package/src/types/message.ts +2 -0
- package/src/utils/composite-context-provider.ts +3 -1
- package/dist/react/model-context/hitl.d.ts +0 -19
- package/dist/react/model-context/hitl.d.ts.map +0 -1
- package/dist/react/model-context/hitl.js +0 -22
- package/dist/react/model-context/hitl.js.map +0 -1
- package/dist/store/runtime-clients/tap-subscribable.d.ts +0 -7
- package/dist/store/runtime-clients/tap-subscribable.d.ts.map +0 -1
- package/dist/store/runtime-clients/tap-subscribable.js +0 -16
- package/dist/store/runtime-clients/tap-subscribable.js.map +0 -1
- package/src/react/model-context/hitl.ts +0 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-composer-runtime-core.js","names":[],"sources":["../../../src/runtime/base/base-composer-runtime-core.ts"],"sourcesContent":["import type {\n Attachment,\n CompleteAttachment,\n CreateAttachment,\n PendingAttachment,\n} from \"../../types/attachment\";\nimport type { MessageRole, AppendMessage } from \"../../types/message\";\nimport type { QuoteInfo } from \"../../types/quote\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\nimport {\n type AttachmentAdapter,\n fileMatchesAccept,\n} from \"../../adapters/attachment\";\nimport type {\n AttachmentAddErrorReason,\n ComposerRuntimeCore,\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventPayload,\n ComposerRuntimeEventType,\n DictationState,\n SendOptions,\n} from \"../interfaces/composer-runtime-core\";\nimport type { DictationAdapter } from \"../../adapters/speech\";\nimport { generateId } from \"../../utils/id\";\n\nconst isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>\n a.status.type === \"complete\";\n\nexport abstract class BaseComposerRuntimeCore\n extends BaseSubscribable\n implements ComposerRuntimeCore\n{\n public readonly isEditing = true;\n\n protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;\n protected abstract getDictationAdapter(): DictationAdapter | undefined;\n\n public get attachmentAccept(): string {\n return this.getAttachmentAdapter()?.accept ?? \"*\";\n }\n\n private _attachments: readonly Attachment[] = [];\n public get attachments() {\n return this._attachments;\n }\n\n protected setAttachments(value: readonly Attachment[]) {\n this._attachments = value;\n this._notifySubscribers();\n }\n\n public abstract get canCancel(): boolean;\n public abstract get canSend(): boolean;\n\n public get isEmpty() {\n return !this.text.trim() && !this.attachments.length;\n }\n\n private _text = \"\";\n\n get text() {\n return this._text;\n }\n\n private _role: MessageRole = \"user\";\n\n get role() {\n return this._role;\n }\n\n private _runConfig: RunConfig = {};\n\n get runConfig() {\n return this._runConfig;\n }\n\n private _quote: QuoteInfo | undefined = undefined;\n\n get quote() {\n return this._quote;\n }\n\n public setQuote(quote: QuoteInfo | undefined) {\n if (this._quote === quote) return;\n\n this._quote = quote;\n this._notifySubscribers();\n }\n\n public setText(value: string) {\n if (this._text === value) return;\n\n this._text = value;\n if (this._dictation) {\n this._dictationBaseText = value;\n this._currentInterimText = \"\";\n const { status, inputDisabled } = this._dictation;\n this._dictation = inputDisabled ? { status, inputDisabled } : { status };\n }\n this._notifySubscribers();\n }\n\n public setRole(role: MessageRole) {\n if (this._role === role) return;\n\n this._role = role;\n this._notifySubscribers();\n }\n\n public setRunConfig(runConfig: RunConfig) {\n if (this._runConfig === runConfig) return;\n\n this._runConfig = runConfig;\n this._notifySubscribers();\n }\n\n private _emptyTextAndAttachments() {\n this._attachments = [];\n this._text = \"\";\n this._notifySubscribers();\n }\n\n private async _onClearAttachments() {\n const adapter = this.getAttachmentAdapter();\n if (adapter) {\n const pending = this._attachments.filter((a) => !isAttachmentComplete(a));\n await Promise.all(pending.map((a) => adapter.remove(a)));\n }\n }\n\n public async reset() {\n if (\n this._attachments.length === 0 &&\n this._text === \"\" &&\n this._role === \"user\" &&\n Object.keys(this._runConfig).length === 0 &&\n this._quote === undefined\n ) {\n return;\n }\n\n this._role = \"user\";\n this._runConfig = {};\n this._quote = undefined;\n\n const task = this._onClearAttachments();\n this._emptyTextAndAttachments();\n await task;\n }\n\n public async clearAttachments() {\n const task = this._onClearAttachments();\n this.setAttachments([]);\n\n await task;\n }\n\n public async send(options?: SendOptions) {\n if (!this.canSend) return;\n\n if (this._dictationSession) {\n this._dictationSession.cancel();\n this._cleanupDictation();\n }\n\n const adapter = this.getAttachmentAdapter();\n const attachments =\n this.attachments.length > 0\n ? Promise.all(\n this.attachments.map(async (a) => {\n if (isAttachmentComplete(a)) return a;\n if (!adapter) throw new Error(\"Attachments are not supported\");\n const result = await adapter.send(a);\n return result as CompleteAttachment;\n }),\n )\n : [];\n\n const text = this.text;\n const quote = this._quote;\n this._quote = undefined;\n this._emptyTextAndAttachments();\n\n const message: Omit<AppendMessage, \"parentId\" | \"sourceId\"> = {\n createdAt: new Date(),\n role: this.role,\n content: text ? [{ type: \"text\", text }] : [],\n attachments: await attachments,\n runConfig: this.runConfig,\n metadata: { custom: { ...(quote ? { quote } : {}) } },\n };\n\n this.handleSend(message, options);\n this._notifyEventSubscribers(\"send\", {});\n }\n\n public cancel() {\n this.handleCancel();\n }\n\n protected abstract handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n options?: SendOptions,\n ): void;\n protected abstract handleCancel(): void;\n\n async addAttachment(fileOrAttachment: File | CreateAttachment) {\n if (!(fileOrAttachment instanceof File)) {\n const adapter = this.getAttachmentAdapter();\n if (\n adapter &&\n !fileMatchesAccept(\n {\n name: fileOrAttachment.name,\n type: fileOrAttachment.contentType ?? \"\",\n },\n adapter.accept,\n )\n ) {\n const message = `File type ${fileOrAttachment.contentType || \"unknown\"} is not accepted. Accepted types: ${adapter.accept}`;\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\n \"not-accepted\",\n message,\n undefined,\n err,\n );\n throw err;\n }\n\n const a: CompleteAttachment = {\n id: fileOrAttachment.id ?? generateId(),\n type: fileOrAttachment.type ?? \"document\",\n name: fileOrAttachment.name,\n contentType: fileOrAttachment.contentType,\n content: fileOrAttachment.content,\n status: { type: \"complete\" },\n };\n this._attachments = [...this._attachments, a];\n this._notifySubscribers();\n this._notifyEventSubscribers(\"attachmentAdd\", {});\n return;\n }\n\n const upsertAttachment = (a: PendingAttachment) => {\n const idx = this._attachments.findIndex(\n (attachment) => attachment.id === a.id,\n );\n if (idx !== -1)\n this._attachments = [\n ...this._attachments.slice(0, idx),\n a,\n ...this._attachments.slice(idx + 1),\n ];\n else {\n this._attachments = [...this._attachments, a];\n }\n\n this._notifySubscribers();\n };\n\n const adapter = this.getAttachmentAdapter();\n if (!adapter) {\n const message = \"Attachments are not supported\";\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\"no-adapter\", message, undefined, err);\n throw err;\n }\n\n if (\n !fileMatchesAccept(\n { name: fileOrAttachment.name, type: fileOrAttachment.type },\n adapter.accept,\n )\n ) {\n const message = `File type ${fileOrAttachment.type || \"unknown\"} is not accepted. Accepted types: ${adapter.accept}`;\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\"not-accepted\", message, undefined, err);\n throw err;\n }\n\n let lastAttachment: PendingAttachment | undefined;\n try {\n const promiseOrGenerator = adapter.add({ file: fileOrAttachment });\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n lastAttachment = r;\n upsertAttachment(r);\n }\n } else {\n lastAttachment = await promiseOrGenerator;\n upsertAttachment(lastAttachment);\n }\n } catch (e) {\n if (lastAttachment) {\n upsertAttachment({\n ...lastAttachment,\n status: { type: \"incomplete\", reason: \"error\" },\n });\n }\n this._safeEmitAttachmentAddError(\n \"adapter-error\",\n e instanceof Error ? e.message : String(e),\n lastAttachment?.id,\n e instanceof Error ? e : undefined,\n );\n throw e;\n }\n\n const hasError =\n lastAttachment?.status.type === \"incomplete\" &&\n lastAttachment.status.reason === \"error\";\n if (hasError) {\n this._safeEmitAttachmentAddError(\n \"adapter-error\",\n \"Attachment upload did not complete successfully.\",\n lastAttachment?.id,\n );\n } else {\n this._notifyEventSubscribers(\"attachmentAdd\", {});\n }\n }\n\n private _safeEmitAttachmentAddError(\n reason: AttachmentAddErrorReason,\n message: string,\n attachmentId?: string,\n error?: Error,\n ) {\n try {\n this._notifyEventSubscribers(\"attachmentAddError\", {\n reason,\n message,\n ...(attachmentId !== undefined && { attachmentId }),\n ...(error !== undefined && { error }),\n });\n } catch (subscriberError) {\n console.error(\n \"[assistant-ui] attachmentAddError subscriber threw:\",\n subscriberError,\n );\n }\n }\n\n async removeAttachment(attachmentId: string) {\n const index = this._attachments.findIndex((a) => a.id === attachmentId);\n if (index === -1) throw new Error(\"Attachment not found\");\n const attachment = this._attachments[index]!;\n\n if (!isAttachmentComplete(attachment)) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n await adapter.remove(attachment);\n }\n\n this._attachments = this._attachments.filter((a) => a.id !== attachmentId);\n this._notifySubscribers();\n }\n\n private _dictation: DictationState | undefined;\n private _dictationSession: DictationAdapter.Session | undefined;\n private _dictationUnsubscribes: Unsubscribe[] = [];\n private _dictationBaseText = \"\";\n private _currentInterimText = \"\";\n private _dictationSessionIdCounter = 0;\n private _activeDictationSessionId: number | undefined;\n private _isCleaningDictation = false;\n\n public get dictation(): DictationState | undefined {\n return this._dictation;\n }\n\n private _isActiveSession(\n sessionId: number,\n session: DictationAdapter.Session,\n ): boolean {\n return (\n this._activeDictationSessionId === sessionId &&\n this._dictationSession === session\n );\n }\n\n public startDictation(): void {\n const adapter = this.getDictationAdapter();\n if (!adapter) {\n throw new Error(\"Dictation adapter not configured\");\n }\n\n if (this._dictationSession) {\n for (const unsub of this._dictationUnsubscribes) {\n unsub();\n }\n this._dictationUnsubscribes = [];\n const oldSession = this._dictationSession;\n oldSession.stop().catch(() => {});\n this._dictationSession = undefined;\n }\n\n const inputDisabled = adapter.disableInputDuringDictation ?? false;\n\n this._dictationBaseText = this._text;\n this._currentInterimText = \"\";\n\n const session = adapter.listen();\n this._dictationSession = session;\n const sessionId = ++this._dictationSessionIdCounter;\n this._activeDictationSessionId = sessionId;\n this._dictation = { status: session.status, inputDisabled };\n this._notifySubscribers();\n\n const unsubSpeech = session.onSpeech((result) => {\n if (!this._isActiveSession(sessionId, session)) return;\n const isFinal = result.isFinal !== false;\n\n const needsSeparator =\n this._dictationBaseText &&\n !this._dictationBaseText.endsWith(\" \") &&\n result.transcript;\n const separator = needsSeparator ? \" \" : \"\";\n\n if (isFinal) {\n this._dictationBaseText =\n this._dictationBaseText + separator + result.transcript;\n this._currentInterimText = \"\";\n this._text = this._dictationBaseText;\n\n if (this._dictation) {\n const { transcript: _, ...rest } = this._dictation;\n this._dictation = rest;\n }\n this._notifySubscribers();\n } else {\n this._currentInterimText = separator + result.transcript;\n this._text = this._dictationBaseText + this._currentInterimText;\n\n if (this._dictation) {\n this._dictation = {\n ...this._dictation,\n transcript: result.transcript,\n };\n }\n this._notifySubscribers();\n }\n });\n this._dictationUnsubscribes.push(unsubSpeech);\n\n const unsubStart = session.onSpeechStart(() => {\n if (!this._isActiveSession(sessionId, session)) return;\n\n this._dictation = {\n status: { type: \"running\" },\n inputDisabled,\n ...(this._dictation?.transcript && {\n transcript: this._dictation.transcript,\n }),\n };\n this._notifySubscribers();\n });\n this._dictationUnsubscribes.push(unsubStart);\n\n const unsubEnd = session.onSpeechEnd(() => {\n this._cleanupDictation({ sessionId });\n });\n this._dictationUnsubscribes.push(unsubEnd);\n\n const statusInterval = setInterval(() => {\n if (!this._isActiveSession(sessionId, session)) return;\n\n if (session.status.type === \"ended\") {\n this._cleanupDictation({ sessionId });\n }\n }, 100);\n this._dictationUnsubscribes.push(() => clearInterval(statusInterval));\n }\n\n public stopDictation(): void {\n if (!this._dictationSession) return;\n\n const session = this._dictationSession;\n const sessionId = this._activeDictationSessionId;\n session.stop().finally(() => {\n this._cleanupDictation({ sessionId });\n });\n }\n\n private _cleanupDictation(options?: { sessionId: number | undefined }): void {\n const isStaleSession =\n options?.sessionId !== undefined &&\n options.sessionId !== this._activeDictationSessionId;\n if (isStaleSession || this._isCleaningDictation) return;\n\n this._isCleaningDictation = true;\n try {\n for (const unsub of this._dictationUnsubscribes) {\n unsub();\n }\n this._dictationUnsubscribes = [];\n this._dictationSession = undefined;\n this._activeDictationSessionId = undefined;\n this._dictation = undefined;\n this._dictationBaseText = \"\";\n this._currentInterimText = \"\";\n this._notifySubscribers();\n } finally {\n this._isCleaningDictation = false;\n }\n }\n\n private _eventSubscribers = new Map<\n ComposerRuntimeEventType,\n Set<(payload?: unknown) => void>\n >();\n\n protected _notifyEventSubscribers<E extends ComposerRuntimeEventType>(\n event: E,\n payload: ComposerRuntimeEventPayload[E],\n ) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n\n for (const callback of subscribers) callback(payload);\n }\n\n public unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ) {\n const wrapped = callback as (payload?: unknown) => void;\n let subscribers = this._eventSubscribers.get(event);\n if (!subscribers) {\n subscribers = new Set();\n this._eventSubscribers.set(event, subscribers);\n }\n subscribers.add(wrapped);\n\n return () => {\n this._eventSubscribers.get(event)?.delete(wrapped);\n };\n }\n}\n"],"mappings":";;;;AA2BA,MAAM,wBAAwB,MAC5B,EAAE,OAAO,SAAS;AAEpB,IAAsB,0BAAtB,cACU,iBAEV;CACE,YAA4B;CAK5B,IAAW,mBAA2B;EACpC,OAAO,KAAK,qBAAqB,GAAG,UAAU;CAChD;CAEA,eAA8C,CAAC;CAC/C,IAAW,cAAc;EACvB,OAAO,KAAK;CACd;CAEA,eAAyB,OAA8B;EACrD,KAAK,eAAe;EACpB,KAAK,mBAAmB;CAC1B;CAKA,IAAW,UAAU;EACnB,OAAO,CAAC,KAAK,KAAK,KAAK,KAAK,CAAC,KAAK,YAAY;CAChD;CAEA,QAAgB;CAEhB,IAAI,OAAO;EACT,OAAO,KAAK;CACd;CAEA,QAA6B;CAE7B,IAAI,OAAO;EACT,OAAO,KAAK;CACd;CAEA,aAAgC,CAAC;CAEjC,IAAI,YAAY;EACd,OAAO,KAAK;CACd;CAEA,SAAwC,KAAA;CAExC,IAAI,QAAQ;EACV,OAAO,KAAK;CACd;CAEA,SAAgB,OAA8B;EAC5C,IAAI,KAAK,WAAW,OAAO;EAE3B,KAAK,SAAS;EACd,KAAK,mBAAmB;CAC1B;CAEA,QAAe,OAAe;EAC5B,IAAI,KAAK,UAAU,OAAO;EAE1B,KAAK,QAA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K,MAAM,YAAY,aAAa,SAAS,OAAO;CACtD;CAEA,YACE,OACA,UACA;EACA,MAAM,UAAU;EAChB,IAAI,cAAc,KAAK,kBAAkB,IAAI,KAAK;EAClD,IAAI,CAAC,aAAa;GAChB,8BAAc,IAAI,IAAI;GACtB,KAAK,kBAAkB,IAAI,OAAO,WAAW;EAC/C;EACA,YAAY,IAAI,OAAO;EAEvB,aAAa;GACX,KAAK,kBAAkB,IAAI,KAAK,GAAG,OAAO,OAAO;EACnD;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"base-composer-runtime-core.js","names":[],"sources":["../../../src/runtime/base/base-composer-runtime-core.ts"],"sourcesContent":["import type {\n Attachment,\n CompleteAttachment,\n CreateAttachment,\n PendingAttachment,\n} from \"../../types/attachment\";\nimport type { MessageRole, AppendMessage } from \"../../types/message\";\nimport type { QuoteInfo } from \"../../types/quote\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\nimport {\n type AttachmentAdapter,\n fileMatchesAccept,\n} from \"../../adapters/attachment\";\nimport type {\n AttachmentAddErrorReason,\n ComposerRuntimeCore,\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventPayload,\n ComposerRuntimeEventType,\n DictationState,\n SendOptions,\n} from \"../interfaces/composer-runtime-core\";\nimport type { DictationAdapter } from \"../../adapters/speech\";\nimport {\n EMPTY_QUEUE_ITEMS,\n type QueueItemState,\n} from \"../../store/scopes/queue-item\";\nimport { generateId } from \"../../utils/id\";\n\nconst isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>\n a.status.type === \"complete\";\n\nexport abstract class BaseComposerRuntimeCore\n extends BaseSubscribable\n implements ComposerRuntimeCore\n{\n public readonly isEditing = true;\n\n protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;\n protected abstract getDictationAdapter(): DictationAdapter | undefined;\n\n public get attachmentAccept(): string {\n return this.getAttachmentAdapter()?.accept ?? \"*\";\n }\n\n private _attachments: readonly Attachment[] = [];\n public get attachments() {\n return this._attachments;\n }\n\n protected setAttachments(value: readonly Attachment[]) {\n this._attachments = value;\n this._notifySubscribers();\n }\n\n public abstract get canCancel(): boolean;\n public abstract get canSend(): boolean;\n\n public get isEmpty() {\n return !this.text.trim() && !this.attachments.length;\n }\n\n private _text = \"\";\n\n get text() {\n return this._text;\n }\n\n private _role: MessageRole = \"user\";\n\n get role() {\n return this._role;\n }\n\n private _runConfig: RunConfig = {};\n\n get runConfig() {\n return this._runConfig;\n }\n\n private _quote: QuoteInfo | undefined = undefined;\n\n get quote() {\n return this._quote;\n }\n\n public setQuote(quote: QuoteInfo | undefined) {\n if (this._quote === quote) return;\n\n this._quote = quote;\n this._notifySubscribers();\n }\n\n public setText(value: string) {\n if (this._text === value) return;\n\n this._text = value;\n if (this._dictation) {\n this._dictationBaseText = value;\n this._currentInterimText = \"\";\n const { status, inputDisabled } = this._dictation;\n this._dictation = inputDisabled ? { status, inputDisabled } : { status };\n }\n this._notifySubscribers();\n }\n\n public setRole(role: MessageRole) {\n if (this._role === role) return;\n\n this._role = role;\n this._notifySubscribers();\n }\n\n public setRunConfig(runConfig: RunConfig) {\n if (this._runConfig === runConfig) return;\n\n this._runConfig = runConfig;\n this._notifySubscribers();\n }\n\n private _emptyTextAndAttachments() {\n this._attachments = [];\n this._text = \"\";\n this._notifySubscribers();\n }\n\n private async _onClearAttachments() {\n const adapter = this.getAttachmentAdapter();\n if (adapter) {\n const pending = this._attachments.filter((a) => !isAttachmentComplete(a));\n await Promise.all(pending.map((a) => adapter.remove(a)));\n }\n }\n\n public async reset() {\n if (\n this._attachments.length === 0 &&\n this._text === \"\" &&\n this._role === \"user\" &&\n Object.keys(this._runConfig).length === 0 &&\n this._quote === undefined\n ) {\n return;\n }\n\n this._role = \"user\";\n this._runConfig = {};\n this._quote = undefined;\n\n const task = this._onClearAttachments();\n this._emptyTextAndAttachments();\n await task;\n }\n\n public async clearAttachments() {\n const task = this._onClearAttachments();\n this.setAttachments([]);\n\n await task;\n }\n\n public async send(options?: SendOptions) {\n if (!this.canSend) return;\n\n if (this._dictationSession) {\n this._dictationSession.cancel();\n this._cleanupDictation();\n }\n\n const adapter = this.getAttachmentAdapter();\n const attachments =\n this.attachments.length > 0\n ? Promise.all(\n this.attachments.map(async (a) => {\n if (isAttachmentComplete(a)) return a;\n if (!adapter) throw new Error(\"Attachments are not supported\");\n const result = await adapter.send(a);\n return result as CompleteAttachment;\n }),\n )\n : [];\n\n const text = this.text;\n const quote = this._quote;\n this._quote = undefined;\n this._emptyTextAndAttachments();\n\n const message: Omit<AppendMessage, \"parentId\" | \"sourceId\"> = {\n createdAt: new Date(),\n role: this.role,\n content: text ? [{ type: \"text\", text }] : [],\n attachments: await attachments,\n runConfig: this.runConfig,\n metadata: { custom: { ...(quote ? { quote } : {}) } },\n };\n\n this.handleSend(message, options);\n this._notifyEventSubscribers(\"send\", {});\n }\n\n public cancel() {\n this.handleCancel();\n }\n\n public get queue(): readonly QueueItemState[] {\n return EMPTY_QUEUE_ITEMS;\n }\n\n public steerQueueItem(_queueItemId: string): void {}\n public removeQueueItem(_queueItemId: string): void {}\n\n protected abstract handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n options?: SendOptions,\n ): void;\n protected abstract handleCancel(): void;\n\n async addAttachment(fileOrAttachment: File | CreateAttachment) {\n if (!(fileOrAttachment instanceof File)) {\n const adapter = this.getAttachmentAdapter();\n if (\n adapter &&\n !fileMatchesAccept(\n {\n name: fileOrAttachment.name,\n type: fileOrAttachment.contentType ?? \"\",\n },\n adapter.accept,\n )\n ) {\n const message = `File type ${fileOrAttachment.contentType || \"unknown\"} is not accepted. Accepted types: ${adapter.accept}`;\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\n \"not-accepted\",\n message,\n undefined,\n err,\n );\n throw err;\n }\n\n const a: CompleteAttachment = {\n id: fileOrAttachment.id ?? generateId(),\n type: fileOrAttachment.type ?? \"document\",\n name: fileOrAttachment.name,\n contentType: fileOrAttachment.contentType,\n content: fileOrAttachment.content,\n status: { type: \"complete\" },\n };\n this._attachments = [...this._attachments, a];\n this._notifySubscribers();\n this._notifyEventSubscribers(\"attachmentAdd\", {});\n return;\n }\n\n const upsertAttachment = (a: PendingAttachment) => {\n const idx = this._attachments.findIndex(\n (attachment) => attachment.id === a.id,\n );\n if (idx !== -1)\n this._attachments = [\n ...this._attachments.slice(0, idx),\n a,\n ...this._attachments.slice(idx + 1),\n ];\n else {\n this._attachments = [...this._attachments, a];\n }\n\n this._notifySubscribers();\n };\n\n const adapter = this.getAttachmentAdapter();\n if (!adapter) {\n const message = \"Attachments are not supported\";\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\"no-adapter\", message, undefined, err);\n throw err;\n }\n\n if (\n !fileMatchesAccept(\n { name: fileOrAttachment.name, type: fileOrAttachment.type },\n adapter.accept,\n )\n ) {\n const message = `File type ${fileOrAttachment.type || \"unknown\"} is not accepted. Accepted types: ${adapter.accept}`;\n const err = new Error(message);\n this._safeEmitAttachmentAddError(\"not-accepted\", message, undefined, err);\n throw err;\n }\n\n let lastAttachment: PendingAttachment | undefined;\n try {\n const promiseOrGenerator = adapter.add({ file: fileOrAttachment });\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n lastAttachment = r;\n upsertAttachment(r);\n }\n } else {\n lastAttachment = await promiseOrGenerator;\n upsertAttachment(lastAttachment);\n }\n } catch (e) {\n if (lastAttachment) {\n upsertAttachment({\n ...lastAttachment,\n status: { type: \"incomplete\", reason: \"error\" },\n });\n }\n this._safeEmitAttachmentAddError(\n \"adapter-error\",\n e instanceof Error ? e.message : String(e),\n lastAttachment?.id,\n e instanceof Error ? e : undefined,\n );\n throw e;\n }\n\n const hasError =\n lastAttachment?.status.type === \"incomplete\" &&\n lastAttachment.status.reason === \"error\";\n if (hasError) {\n this._safeEmitAttachmentAddError(\n \"adapter-error\",\n \"Attachment upload did not complete successfully.\",\n lastAttachment?.id,\n );\n } else {\n this._notifyEventSubscribers(\"attachmentAdd\", {});\n }\n }\n\n private _safeEmitAttachmentAddError(\n reason: AttachmentAddErrorReason,\n message: string,\n attachmentId?: string,\n error?: Error,\n ) {\n try {\n this._notifyEventSubscribers(\"attachmentAddError\", {\n reason,\n message,\n ...(attachmentId !== undefined && { attachmentId }),\n ...(error !== undefined && { error }),\n });\n } catch (subscriberError) {\n console.error(\n \"[assistant-ui] attachmentAddError subscriber threw:\",\n subscriberError,\n );\n }\n }\n\n async removeAttachment(attachmentId: string) {\n const index = this._attachments.findIndex((a) => a.id === attachmentId);\n if (index === -1) throw new Error(\"Attachment not found\");\n const attachment = this._attachments[index]!;\n\n if (!isAttachmentComplete(attachment)) {\n const adapter = this.getAttachmentAdapter();\n if (!adapter) throw new Error(\"Attachments are not supported\");\n await adapter.remove(attachment);\n }\n\n this._attachments = this._attachments.filter((a) => a.id !== attachmentId);\n this._notifySubscribers();\n }\n\n private _dictation: DictationState | undefined;\n private _dictationSession: DictationAdapter.Session | undefined;\n private _dictationUnsubscribes: Unsubscribe[] = [];\n private _dictationBaseText = \"\";\n private _currentInterimText = \"\";\n private _dictationSessionIdCounter = 0;\n private _activeDictationSessionId: number | undefined;\n private _isCleaningDictation = false;\n\n public get dictation(): DictationState | undefined {\n return this._dictation;\n }\n\n private _isActiveSession(\n sessionId: number,\n session: DictationAdapter.Session,\n ): boolean {\n return (\n this._activeDictationSessionId === sessionId &&\n this._dictationSession === session\n );\n }\n\n public startDictation(): void {\n const adapter = this.getDictationAdapter();\n if (!adapter) {\n throw new Error(\"Dictation adapter not configured\");\n }\n\n if (this._dictationSession) {\n for (const unsub of this._dictationUnsubscribes) {\n unsub();\n }\n this._dictationUnsubscribes = [];\n const oldSession = this._dictationSession;\n oldSession.stop().catch(() => {});\n this._dictationSession = undefined;\n }\n\n const inputDisabled = adapter.disableInputDuringDictation ?? false;\n\n this._dictationBaseText = this._text;\n this._currentInterimText = \"\";\n\n const session = adapter.listen();\n this._dictationSession = session;\n const sessionId = ++this._dictationSessionIdCounter;\n this._activeDictationSessionId = sessionId;\n this._dictation = { status: session.status, inputDisabled };\n this._notifySubscribers();\n\n const unsubSpeech = session.onSpeech((result) => {\n if (!this._isActiveSession(sessionId, session)) return;\n const isFinal = result.isFinal !== false;\n\n const needsSeparator =\n this._dictationBaseText &&\n !this._dictationBaseText.endsWith(\" \") &&\n result.transcript;\n const separator = needsSeparator ? \" \" : \"\";\n\n if (isFinal) {\n this._dictationBaseText =\n this._dictationBaseText + separator + result.transcript;\n this._currentInterimText = \"\";\n this._text = this._dictationBaseText;\n\n if (this._dictation) {\n const { transcript: _, ...rest } = this._dictation;\n this._dictation = rest;\n }\n this._notifySubscribers();\n } else {\n this._currentInterimText = separator + result.transcript;\n this._text = this._dictationBaseText + this._currentInterimText;\n\n if (this._dictation) {\n this._dictation = {\n ...this._dictation,\n transcript: result.transcript,\n };\n }\n this._notifySubscribers();\n }\n });\n this._dictationUnsubscribes.push(unsubSpeech);\n\n const unsubStart = session.onSpeechStart(() => {\n if (!this._isActiveSession(sessionId, session)) return;\n\n this._dictation = {\n status: { type: \"running\" },\n inputDisabled,\n ...(this._dictation?.transcript && {\n transcript: this._dictation.transcript,\n }),\n };\n this._notifySubscribers();\n });\n this._dictationUnsubscribes.push(unsubStart);\n\n const unsubEnd = session.onSpeechEnd(() => {\n this._cleanupDictation({ sessionId });\n });\n this._dictationUnsubscribes.push(unsubEnd);\n\n const statusInterval = setInterval(() => {\n if (!this._isActiveSession(sessionId, session)) return;\n\n if (session.status.type === \"ended\") {\n this._cleanupDictation({ sessionId });\n }\n }, 100);\n this._dictationUnsubscribes.push(() => clearInterval(statusInterval));\n }\n\n public stopDictation(): void {\n if (!this._dictationSession) return;\n\n const session = this._dictationSession;\n const sessionId = this._activeDictationSessionId;\n session.stop().finally(() => {\n this._cleanupDictation({ sessionId });\n });\n }\n\n private _cleanupDictation(options?: { sessionId: number | undefined }): void {\n const isStaleSession =\n options?.sessionId !== undefined &&\n options.sessionId !== this._activeDictationSessionId;\n if (isStaleSession || this._isCleaningDictation) return;\n\n this._isCleaningDictation = true;\n try {\n for (const unsub of this._dictationUnsubscribes) {\n unsub();\n }\n this._dictationUnsubscribes = [];\n this._dictationSession = undefined;\n this._activeDictationSessionId = undefined;\n this._dictation = undefined;\n this._dictationBaseText = \"\";\n this._currentInterimText = \"\";\n this._notifySubscribers();\n } finally {\n this._isCleaningDictation = false;\n }\n }\n\n private _eventSubscribers = new Map<\n ComposerRuntimeEventType,\n Set<(payload?: unknown) => void>\n >();\n\n protected _notifyEventSubscribers<E extends ComposerRuntimeEventType>(\n event: E,\n payload: ComposerRuntimeEventPayload[E],\n ) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n\n for (const callback of subscribers) callback(payload);\n }\n\n public unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ) {\n const wrapped = callback as (payload?: unknown) => void;\n let subscribers = this._eventSubscribers.get(event);\n if (!subscribers) {\n subscribers = new Set();\n this._eventSubscribers.set(event, subscribers);\n }\n subscribers.add(wrapped);\n\n return () => {\n this._eventSubscribers.get(event)?.delete(wrapped);\n };\n }\n}\n"],"mappings":";;;;;AA+BA,MAAM,wBAAwB,MAC5B,EAAE,OAAO,SAAS;AAEpB,IAAsB,0BAAtB,cACU,iBAEV;CACE,YAA4B;CAK5B,IAAW,mBAA2B;EACpC,OAAO,KAAK,qBAAqB,CAAC,EAAE,UAAU;CAChD;CAEA,eAA8C,CAAC;CAC/C,IAAW,cAAc;EACvB,OAAO,KAAK;CACd;CAEA,eAAyB,OAA8B;EACrD,KAAK,eAAe;EACpB,KAAK,mBAAmB;CAC1B;CAKA,IAAW,UAAU;EACnB,OAAO,CAAC,KAAK,KAAK,KAAK,KAAK,CAAC,KAAK,YAAY;CAChD;CAEA,QAAgB;CAEhB,IAAI,OAAO;EACT,OAAO,KAAK;CACd;CAEA,QAA6B;CAE7B,IAAI,OAAO;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B;EAEjD,KAAK,uBAAuB;EAC5B,IAAI;GACF,KAAK,MAAM,SAAS,KAAK,wBACvB,MAAM;GAER,KAAK,yBAAyB,CAAC;GAC/B,KAAK,oBAAoB,KAAA;GACzB,KAAK,4BAA4B,KAAA;GACjC,KAAK,aAAa,KAAA;GAClB,KAAK,qBAAqB;GAC1B,KAAK,sBAAsB;GAC3B,KAAK,mBAAmB;EAC1B,UAAU;GACR,KAAK,uBAAuB;EAC9B;CACF;CAEA,oCAA4B,IAAI,IAG9B;CAEF,wBACE,OACA,SACA;EACA,MAAM,cAAc,KAAK,kBAAkB,IAAI,KAAK;EACpD,IAAI,CAAC,aAAa;EAElB,KAAK,MAAM,YAAY,aAAa,SAAS,OAAO;CACtD;CAEA,YACE,OACA,UACA;EACA,MAAM,UAAU;EAChB,IAAI,cAAc,KAAK,kBAAkB,IAAI,KAAK;EAClD,IAAI,CAAC,aAAa;GAChB,8BAAc,IAAI,IAAI;GACtB,KAAK,kBAAkB,IAAI,OAAO,WAAW;EAC/C;EACA,YAAY,IAAI,OAAO;EAEvB,aAAa;GACX,KAAK,kBAAkB,IAAI,KAAK,CAAC,EAAE,OAAO,OAAO;EACnD;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-thread-runtime-core.js","names":[],"sources":["../../../src/runtime/base/base-thread-runtime-core.ts"],"sourcesContent":["import type {\n AppendMessage,\n ThreadAssistantMessage,\n ThreadMessage,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { generateId } from \"../../utils/id\";\nimport {\n ExportedMessageRepository,\n MessageRepository,\n} from \"../utils/message-repository\";\nimport { DefaultThreadComposerRuntimeCore } from \"./default-thread-composer-runtime-core\";\nimport type {\n AddToolResultOptions,\n ResumeToolCallOptions,\n RespondToToolApprovalOptions,\n ThreadSuggestion,\n SubmitFeedbackOptions,\n ThreadRuntimeCore,\n SpeechState,\n VoiceSessionState,\n RuntimeCapabilities,\n ThreadRuntimeEventCallback,\n ThreadRuntimeEventPayload,\n ThreadRuntimeEventType,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../interfaces/thread-runtime-core\";\nimport { DefaultEditComposerRuntimeCore } from \"./default-edit-composer-runtime-core\";\nimport type { SpeechSynthesisAdapter } from \"../../adapters/speech\";\nimport type { FeedbackAdapter } from \"../../adapters/feedback\";\nimport type { AttachmentAdapter } from \"../../adapters/attachment\";\nimport type { RealtimeVoiceAdapter } from \"../../adapters/voice\";\nimport type { ThreadMessageLike } from \"../utils/thread-message-like\";\n\ntype BaseThreadAdapters = {\n speech?: SpeechSynthesisAdapter | undefined;\n feedback?: FeedbackAdapter | undefined;\n attachments?: AttachmentAdapter | undefined;\n voice?: RealtimeVoiceAdapter | undefined;\n};\n\nexport abstract class BaseThreadRuntimeCore implements ThreadRuntimeCore {\n private _subscriptions = new Set<() => void>();\n private _isInitialized = false;\n\n protected readonly repository = new MessageRepository();\n public abstract get adapters(): BaseThreadAdapters | undefined;\n public abstract get isDisabled(): boolean;\n public abstract get isSendDisabled(): boolean;\n public abstract get isLoading(): boolean;\n public abstract get suggestions(): readonly ThreadSuggestion[];\n public abstract get extras(): unknown;\n\n public abstract get capabilities(): RuntimeCapabilities;\n public abstract append(message: AppendMessage): void;\n public abstract startRun(config: StartRunConfig): void;\n public abstract resumeRun(config: ResumeRunConfig): void;\n public abstract addToolResult(options: AddToolResultOptions): void;\n public abstract resumeToolCall(options: ResumeToolCallOptions): void;\n public abstract respondToToolApproval(\n options: RespondToToolApprovalOptions,\n ): void;\n public abstract cancelRun(): void;\n public abstract exportExternalState(): any;\n public abstract importExternalState(state: any): void;\n\n protected _voiceMessages: ThreadMessage[] = [];\n protected _voiceGeneration = 0;\n private _cachedMergedMessages: readonly ThreadMessage[] | null = null;\n private _cachedVoiceGeneration = -1;\n private _cachedMergedBase: readonly ThreadMessage[] | null = null;\n\n protected _markVoiceMessagesDirty() {\n this._voiceGeneration++;\n this._cachedMergedMessages = null;\n }\n\n protected _getBaseMessages(): readonly ThreadMessage[] {\n return this.repository.getMessages();\n }\n\n public get messages(): readonly ThreadMessage[] {\n if (this._voiceMessages.length === 0) {\n return this._getBaseMessages();\n }\n const base = this._getBaseMessages();\n if (\n this._cachedVoiceGeneration !== this._voiceGeneration ||\n this._cachedMergedBase !== base\n ) {\n this._cachedMergedMessages = [...base, ...this._voiceMessages];\n this._cachedVoiceGeneration = this._voiceGeneration;\n this._cachedMergedBase = base;\n }\n return this._cachedMergedMessages!;\n }\n\n public get state() {\n let mostRecentAssistantMessage: (typeof this.messages)[number] | undefined;\n for (const message of this.messages) {\n if (message.role === \"assistant\") {\n mostRecentAssistantMessage = message;\n }\n }\n\n return mostRecentAssistantMessage?.metadata.unstable_state ?? null;\n }\n\n public readonly composer = new DefaultThreadComposerRuntimeCore(this);\n\n constructor(private readonly _contextProvider: ModelContextProvider) {}\n\n public getModelContext() {\n return this._contextProvider.getModelContext();\n }\n\n private _editComposers = new Map<string, DefaultEditComposerRuntimeCore>();\n public getEditComposer(messageId: string) {\n return this._editComposers.get(messageId);\n }\n public beginEdit(messageId: string) {\n if (this._editComposers.has(messageId))\n throw new Error(\"Edit already in progress\");\n\n this._editComposers.set(\n messageId,\n new DefaultEditComposerRuntimeCore(\n this,\n () => this._editComposers.delete(messageId),\n this.repository.getMessage(messageId),\n ),\n );\n this._notifySubscribers();\n }\n\n public getMessageById(messageId: string) {\n try {\n return this.repository.getMessage(messageId);\n } catch {\n // Check voice messages\n const baseMessages = this.repository.getMessages();\n const voiceIdx = this._voiceMessages.findIndex((m) => m.id === messageId);\n if (voiceIdx !== -1) {\n const parentId =\n voiceIdx > 0\n ? this._voiceMessages[voiceIdx - 1]!.id\n : (baseMessages.at(-1)?.id ?? null);\n return {\n parentId,\n message: this._voiceMessages[voiceIdx]!,\n index: baseMessages.length + voiceIdx,\n };\n }\n return undefined;\n }\n }\n\n public getBranches(messageId: string): string[] {\n if (this._voiceMessages.some((m) => m.id === messageId)) {\n return [];\n }\n return this.repository.getBranches(messageId);\n }\n\n public switchToBranch(branchId: string): void {\n this.repository.switchToBranch(branchId);\n this._notifySubscribers();\n }\n\n protected _notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n\n public _notifyEventSubscribers<E extends ThreadRuntimeEventType>(\n event: E,\n payload: ThreadRuntimeEventPayload[E],\n ) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n\n for (const callback of subscribers) callback(payload);\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n public submitFeedback({ messageId, type }: SubmitFeedbackOptions) {\n const adapter = this.adapters?.feedback;\n if (!adapter) throw new Error(\"Feedback adapter not configured\");\n\n const { message, parentId } = this.repository.getMessage(messageId);\n adapter.submit({ message, type });\n\n if (message.role === \"assistant\") {\n const updatedMessage: ThreadMessage = {\n ...message,\n metadata: {\n ...message.metadata,\n submittedFeedback: { type },\n },\n };\n this.repository.addOrUpdateMessage(parentId, updatedMessage);\n }\n\n this._notifySubscribers();\n }\n\n private _stopSpeaking: Unsubscribe | undefined;\n public speech: SpeechState | undefined;\n\n public speak(messageId: string) {\n const adapter = this.adapters?.speech;\n if (!adapter) throw new Error(\"Speech adapter not configured\");\n\n const { message } = this.repository.getMessage(messageId);\n\n this._stopSpeaking?.();\n\n const utterance = adapter.speak(getThreadMessageText(message));\n const unsub = utterance.subscribe(() => {\n if (utterance.status.type === \"ended\") {\n this._stopSpeaking = undefined;\n this.speech = undefined;\n } else {\n this.speech = { messageId, status: utterance.status };\n }\n this._notifySubscribers();\n });\n\n this.speech = { messageId, status: utterance.status };\n this._notifySubscribers();\n\n this._stopSpeaking = () => {\n utterance.cancel();\n unsub();\n this.speech = undefined;\n this._stopSpeaking = undefined;\n };\n }\n\n public stopSpeaking() {\n if (!this._stopSpeaking) throw new Error(\"No message is being spoken\");\n this._stopSpeaking();\n this._notifySubscribers();\n }\n\n private _voiceSession: RealtimeVoiceAdapter.Session | undefined;\n private _voiceUnsubs: Array<() => void> = [];\n public voice: VoiceSessionState | undefined;\n\n private _voiceVolume = 0;\n private _voiceVolumeSubscribers = new Set<() => void>();\n\n public getVoiceVolume = () => this._voiceVolume;\n\n public subscribeVoiceVolume = (callback: () => void): Unsubscribe => {\n this._voiceVolumeSubscribers.add(callback);\n return () => this._voiceVolumeSubscribers.delete(callback);\n };\n\n public connectVoice() {\n const adapter = this.adapters?.voice;\n if (!adapter) throw new Error(\"Voice adapter not configured\");\n\n this.disconnectVoice();\n\n const session = adapter.connect({});\n this._voiceSession = session;\n const unsubs: Array<() => void> = [];\n\n let currentMode: RealtimeVoiceAdapter.Mode = \"listening\";\n\n this.voice = {\n status: session.status,\n isMuted: session.isMuted,\n mode: currentMode,\n };\n this._voiceVolume = 0;\n this._notifySubscribers();\n\n unsubs.push(\n session.onStatusChange((status) => {\n if (status.type === \"ended\") {\n this._finishVoiceAssistantMessage();\n this._voiceSession = undefined;\n this.voice = undefined;\n } else {\n this.voice = {\n status,\n isMuted: session.isMuted,\n mode: currentMode,\n };\n }\n this._notifySubscribers();\n }),\n );\n\n unsubs.push(\n session.onModeChange((mode) => {\n currentMode = mode;\n if (this.voice) {\n this.voice = { ...this.voice, mode };\n this._notifySubscribers();\n }\n }),\n );\n\n unsubs.push(\n session.onVolumeChange((volume) => {\n this._voiceVolume = volume;\n for (const cb of this._voiceVolumeSubscribers) cb();\n }),\n );\n\n unsubs.push(\n session.onTranscript((transcript) => {\n this._handleVoiceTranscript(transcript);\n }),\n );\n\n this._voiceUnsubs = unsubs;\n }\n\n private _currentAssistantMsg: ThreadAssistantMessage | null = null;\n\n private _handleVoiceTranscript(\n transcript: RealtimeVoiceAdapter.TranscriptItem,\n ) {\n this.ensureInitialized();\n\n if (transcript.role === \"user\") {\n this._finishVoiceAssistantMessage();\n this._currentAssistantMsg = null;\n\n if (transcript.isFinal) {\n this._voiceMessages.push({\n id: generateId(),\n role: \"user\",\n content: [{ type: \"text\", text: transcript.text }],\n metadata: { custom: {} },\n createdAt: new Date(),\n status: { type: \"complete\", reason: \"unknown\" },\n attachments: [],\n });\n this._markVoiceMessagesDirty();\n this._notifySubscribers();\n }\n } else {\n if (!this._currentAssistantMsg) {\n this._currentAssistantMsg = {\n id: generateId(),\n role: \"assistant\",\n content: [{ type: \"text\", text: transcript.text }],\n metadata: {\n unstable_state: this.state,\n unstable_annotations: [],\n unstable_data: [],\n steps: [],\n custom: {},\n },\n status: { type: \"running\" },\n createdAt: new Date(),\n };\n this._voiceMessages.push(this._currentAssistantMsg);\n } else {\n const idx = this._voiceMessages.indexOf(this._currentAssistantMsg);\n if (idx === -1) return;\n const updated: ThreadAssistantMessage = {\n ...this._currentAssistantMsg,\n content: [{ type: \"text\", text: transcript.text }],\n ...(transcript.isFinal\n ? { status: { type: \"complete\", reason: \"stop\" } }\n : {}),\n };\n this._voiceMessages[idx] = updated;\n this._currentAssistantMsg = updated;\n }\n\n if (transcript.isFinal) {\n this._currentAssistantMsg = null;\n }\n\n this._markVoiceMessagesDirty();\n this._notifySubscribers();\n }\n }\n\n private _finishVoiceAssistantMessage() {\n const last = this._voiceMessages.at(-1);\n if (last?.role === \"assistant\" && last.status.type === \"running\") {\n const idx = this._voiceMessages.length - 1;\n this._voiceMessages[idx] = {\n ...(last as ThreadAssistantMessage),\n status: { type: \"complete\", reason: \"stop\" },\n };\n this._markVoiceMessagesDirty();\n this._notifySubscribers();\n }\n }\n\n public disconnectVoice() {\n this._finishVoiceAssistantMessage();\n this._currentAssistantMsg = null;\n for (const unsub of this._voiceUnsubs) unsub();\n this._voiceUnsubs = [];\n this._voiceSession?.disconnect();\n this._voiceSession = undefined;\n this.voice = undefined;\n this._voiceVolume = 0;\n for (const cb of this._voiceVolumeSubscribers) cb();\n this._voiceMessages = [];\n this._markVoiceMessagesDirty();\n this._notifySubscribers();\n }\n\n public muteVoice() {\n if (!this._voiceSession) throw new Error(\"No active voice session\");\n this._voiceSession.mute();\n this.voice = {\n ...this.voice!,\n isMuted: true,\n };\n this._notifySubscribers();\n }\n\n public unmuteVoice() {\n if (!this._voiceSession) throw new Error(\"No active voice session\");\n this._voiceSession.unmute();\n this.voice = {\n ...this.voice!,\n isMuted: false,\n };\n this._notifySubscribers();\n }\n\n protected ensureInitialized() {\n if (!this._isInitialized) {\n this._isInitialized = true;\n this._notifyEventSubscribers(\"initialize\", {});\n }\n }\n\n public export() {\n return this.repository.export();\n }\n\n public import(data: ExportedMessageRepository) {\n this.ensureInitialized();\n this.repository.clear();\n this.repository.import(data);\n this._notifySubscribers();\n }\n\n public reset(initialMessages?: readonly ThreadMessageLike[]) {\n this.import(ExportedMessageRepository.fromArray(initialMessages ?? []));\n }\n\n private _eventSubscribers = new Map<\n ThreadRuntimeEventType,\n Set<(payload?: unknown) => void>\n >();\n\n public unstable_on<E extends ThreadRuntimeEventType>(\n event: E,\n callback: ThreadRuntimeEventCallback<E>,\n ) {\n const wrapped = callback as (payload?: unknown) => void;\n if (event === \"modelContextUpdate\") {\n // provider.subscribe is `() => void`; pump the typed empty payload to the user callback.\n return this._contextProvider.subscribe?.(() => wrapped({})) ?? (() => {});\n }\n\n let subscribers = this._eventSubscribers.get(event);\n if (!subscribers) {\n subscribers = new Set();\n this._eventSubscribers.set(event, subscribers);\n }\n subscribers.add(wrapped);\n\n // `initialize` latches: replay it (deferred) to subscribers that attach\n // after the thread already initialized, mirroring a BehaviorSubject.\n if (event === \"initialize\" && this._isInitialized) {\n queueMicrotask(() => {\n if (subscribers.has(wrapped)) wrapped({});\n });\n }\n\n return () => {\n this._eventSubscribers.get(event)?.delete(wrapped);\n };\n }\n}\n"],"mappings":";;;;;;AA4CA,IAAsB,wBAAtB,MAAyE;CAqE1C;CApE7B,iCAAyB,IAAI,IAAgB;CAC7C,iBAAyB;CAEzB,aAAgC,IAAI,kBAAkB;CAqBtD,iBAA4C,CAAC;CAC7C,mBAA6B;CAC7B,wBAAiE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sources":["../../../src/runtime/base/base-thread-runtime-core.ts"],"sourcesContent":["import type {\n AppendMessage,\n ThreadAssistantMessage,\n ThreadMessage,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { generateId } from \"../../utils/id\";\nimport {\n ExportedMessageRepository,\n MessageRepository,\n} from \"../utils/message-repository\";\nimport { DefaultThreadComposerRuntimeCore } from \"./default-thread-composer-runtime-core\";\nimport type {\n AddToolResultOptions,\n ResumeToolCallOptions,\n RespondToToolApprovalOptions,\n ThreadSuggestion,\n SubmitFeedbackOptions,\n ThreadRuntimeCore,\n SpeechState,\n VoiceSessionState,\n RuntimeCapabilities,\n ThreadRuntimeEventCallback,\n ThreadRuntimeEventPayload,\n ThreadRuntimeEventType,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../interfaces/thread-runtime-core\";\nimport { DefaultEditComposerRuntimeCore } from \"./default-edit-composer-runtime-core\";\nimport type { SpeechSynthesisAdapter } from \"../../adapters/speech\";\nimport type { FeedbackAdapter } from \"../../adapters/feedback\";\nimport type { AttachmentAdapter } from \"../../adapters/attachment\";\nimport type { RealtimeVoiceAdapter } from \"../../adapters/voice\";\nimport type { ThreadMessageLike } from \"../utils/thread-message-like\";\n\ntype BaseThreadAdapters = {\n speech?: SpeechSynthesisAdapter | undefined;\n feedback?: FeedbackAdapter | undefined;\n attachments?: AttachmentAdapter | undefined;\n voice?: RealtimeVoiceAdapter | undefined;\n};\n\nexport abstract class BaseThreadRuntimeCore implements ThreadRuntimeCore {\n private _subscriptions = new Set<() => void>();\n private _isInitialized = false;\n\n protected readonly repository = new MessageRepository();\n public abstract get adapters(): BaseThreadAdapters | undefined;\n public abstract get isDisabled(): boolean;\n public abstract get isSendDisabled(): boolean;\n public abstract get isLoading(): boolean;\n public abstract get suggestions(): readonly ThreadSuggestion[];\n public abstract get extras(): unknown;\n\n public abstract get capabilities(): RuntimeCapabilities;\n public abstract append(message: AppendMessage): void;\n public abstract startRun(config: StartRunConfig): void;\n public abstract resumeRun(config: ResumeRunConfig): void;\n public abstract addToolResult(options: AddToolResultOptions): void;\n public abstract resumeToolCall(options: ResumeToolCallOptions): void;\n public abstract respondToToolApproval(\n options: RespondToToolApprovalOptions,\n ): void;\n public abstract cancelRun(): void;\n public abstract exportExternalState(): any;\n public abstract importExternalState(state: any): void;\n\n protected _voiceMessages: ThreadMessage[] = [];\n protected _voiceGeneration = 0;\n private _cachedMergedMessages: readonly ThreadMessage[] | null = null;\n private _cachedVoiceGeneration = -1;\n private _cachedMergedBase: readonly ThreadMessage[] | null = null;\n\n protected _markVoiceMessagesDirty() {\n this._voiceGeneration++;\n this._cachedMergedMessages = null;\n }\n\n protected _getBaseMessages(): readonly ThreadMessage[] {\n return this.repository.getMessages();\n }\n\n public get messages(): readonly ThreadMessage[] {\n if (this._voiceMessages.length === 0) {\n return this._getBaseMessages();\n }\n const base = this._getBaseMessages();\n if (\n this._cachedVoiceGeneration !== this._voiceGeneration ||\n this._cachedMergedBase !== base\n ) {\n this._cachedMergedMessages = [...base, ...this._voiceMessages];\n this._cachedVoiceGeneration = this._voiceGeneration;\n this._cachedMergedBase = base;\n }\n return this._cachedMergedMessages!;\n }\n\n public get state() {\n let mostRecentAssistantMessage: (typeof this.messages)[number] | undefined;\n for (const message of this.messages) {\n if (message.role === \"assistant\") {\n mostRecentAssistantMessage = message;\n }\n }\n\n return mostRecentAssistantMessage?.metadata.unstable_state ?? null;\n }\n\n public readonly composer = new DefaultThreadComposerRuntimeCore(this);\n\n constructor(private readonly _contextProvider: ModelContextProvider) {}\n\n public getModelContext() {\n return this._contextProvider.getModelContext();\n }\n\n private _editComposers = new Map<string, DefaultEditComposerRuntimeCore>();\n public getEditComposer(messageId: string) {\n return this._editComposers.get(messageId);\n }\n public beginEdit(messageId: string) {\n if (this._editComposers.has(messageId))\n throw new Error(\"Edit already in progress\");\n\n this._editComposers.set(\n messageId,\n new DefaultEditComposerRuntimeCore(\n this,\n () => this._editComposers.delete(messageId),\n this.repository.getMessage(messageId),\n ),\n );\n this._notifySubscribers();\n }\n\n public getMessageById(messageId: string) {\n try {\n return this.repository.getMessage(messageId);\n } catch {\n // Check voice messages\n const baseMessages = this.repository.getMessages();\n const voiceIdx = this._voiceMessages.findIndex((m) => m.id === messageId);\n if (voiceIdx !== -1) {\n const parentId =\n voiceIdx > 0\n ? this._voiceMessages[voiceIdx - 1]!.id\n : (baseMessages.at(-1)?.id ?? null);\n return {\n parentId,\n message: this._voiceMessages[voiceIdx]!,\n index: baseMessages.length + voiceIdx,\n };\n }\n return undefined;\n }\n }\n\n public getBranches(messageId: string): string[] {\n if (this._voiceMessages.some((m) => m.id === messageId)) {\n return [];\n }\n return this.repository.getBranches(messageId);\n }\n\n public switchToBranch(branchId: string): void {\n this.repository.switchToBranch(branchId);\n this._notifySubscribers();\n }\n\n protected _notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n\n public _notifyEventSubscribers<E extends ThreadRuntimeEventType>(\n event: E,\n payload: ThreadRuntimeEventPayload[E],\n ) {\n const subscribers = this._eventSubscribers.get(event);\n if (!subscribers) return;\n\n for (const callback of subscribers) callback(payload);\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n public submitFeedback({ messageId, type }: SubmitFeedbackOptions) {\n const adapter = this.adapters?.feedback;\n if (!adapter) throw new Error(\"Feedback adapter not configured\");\n\n const { message, parentId } = this.repository.getMessage(messageId);\n adapter.submit({ message, type });\n\n if (message.role === \"assistant\") {\n const updatedMessage: ThreadMessage = {\n ...message,\n metadata: {\n ...message.metadata,\n submittedFeedback: { type },\n },\n };\n this.repository.addOrUpdateMessage(parentId, updatedMessage);\n }\n\n this._notifySubscribers();\n }\n\n private _stopSpeaking: Unsubscribe | undefined;\n public speech: SpeechState | undefined;\n\n public speak(messageId: string) {\n const adapter = this.adapters?.speech;\n if (!adapter) throw new Error(\"Speech adapter not configured\");\n\n const { message } = this.repository.getMessage(messageId);\n\n this._stopSpeaking?.();\n\n const utterance = adapter.speak(getThreadMessageText(message));\n const unsub = utterance.subscribe(() => {\n if (utterance.status.type === \"ended\") {\n this._stopSpeaking = undefined;\n this.speech = undefined;\n } else {\n this.speech = { messageId, status: utterance.status };\n }\n this._notifySubscribers();\n });\n\n this.speech = { messageId, status: utterance.status };\n this._notifySubscribers();\n\n this._stopSpeaking = () => {\n utterance.cancel();\n unsub();\n this.speech = undefined;\n this._stopSpeaking = undefined;\n };\n }\n\n public stopSpeaking() {\n if (!this._stopSpeaking) throw new Error(\"No message is being spoken\");\n this._stopSpeaking();\n this._notifySubscribers();\n }\n\n private _voiceSession: RealtimeVoiceAdapter.Session | undefined;\n private _voiceUnsubs: Array<() => void> = [];\n public voice: VoiceSessionState | undefined;\n\n private _voiceVolume = 0;\n private _voiceVolumeSubscribers = new Set<() => void>();\n\n public getVoiceVolume = () => this._voiceVolume;\n\n public subscribeVoiceVolume = (callback: () => void): Unsubscribe => {\n this._voiceVolumeSubscribers.add(callback);\n return () => this._voiceVolumeSubscribers.delete(callback);\n };\n\n public connectVoice() {\n const adapter = this.adapters?.voice;\n if (!adapter) throw new Error(\"Voice adapter not configured\");\n\n this.disconnectVoice();\n\n const session = adapter.connect({});\n this._voiceSession = session;\n const unsubs: Array<() => void> = [];\n\n let currentMode: RealtimeVoiceAdapter.Mode = \"listening\";\n\n this.voice = {\n status: session.status,\n isMuted: session.isMuted,\n mode: currentMode,\n };\n this._voiceVolume = 0;\n this._notifySubscribers();\n\n unsubs.push(\n session.onStatusChange((status) => {\n if (status.type === \"ended\") {\n this._finishVoiceAssistantMessage();\n this._voiceSession = undefined;\n this.voice = undefined;\n } else {\n this.voice = {\n status,\n isMuted: session.isMuted,\n mode: currentMode,\n };\n }\n this._notifySubscribers();\n }),\n );\n\n unsubs.push(\n session.onModeChange((mode) => {\n currentMode = mode;\n if (this.voice) {\n this.voice = { ...this.voice, mode };\n this._notifySubscribers();\n }\n }),\n );\n\n unsubs.push(\n session.onVolumeChange((volume) => {\n this._voiceVolume = volume;\n for (const cb of this._voiceVolumeSubscribers) cb();\n }),\n );\n\n unsubs.push(\n session.onTranscript((transcript) => {\n this._handleVoiceTranscript(transcript);\n }),\n );\n\n this._voiceUnsubs = unsubs;\n }\n\n private _currentAssistantMsg: ThreadAssistantMessage | null = null;\n\n private _handleVoiceTranscript(\n transcript: RealtimeVoiceAdapter.TranscriptItem,\n ) {\n this.ensureInitialized();\n\n if (transcript.role === \"user\") {\n this._finishVoiceAssistantMessage();\n this._currentAssistantMsg = null;\n\n if (transcript.isFinal) {\n this._voiceMessages.push({\n id: generateId(),\n role: \"user\",\n content: [{ type: \"text\", text: transcript.text }],\n metadata: { custom: {} },\n createdAt: new Date(),\n status: { type: \"complete\", reason: \"unknown\" },\n attachments: [],\n });\n this._markVoiceMessagesDirty();\n this._notifySubscribers();\n }\n } else {\n if (!this._currentAssistantMsg) {\n this._currentAssistantMsg = {\n id: generateId(),\n role: \"assistant\",\n content: [{ type: \"text\", text: transcript.text }],\n metadata: {\n unstable_state: this.state,\n unstable_annotations: [],\n unstable_data: [],\n steps: [],\n custom: {},\n },\n status: { type: \"running\" },\n createdAt: new Date(),\n };\n this._voiceMessages.push(this._currentAssistantMsg);\n } else {\n const idx = this._voiceMessages.indexOf(this._currentAssistantMsg);\n if (idx === -1) return;\n const updated: ThreadAssistantMessage = {\n ...this._currentAssistantMsg,\n content: [{ type: \"text\", text: transcript.text }],\n ...(transcript.isFinal\n ? { status: { type: \"complete\", reason: \"stop\" } }\n : {}),\n };\n this._voiceMessages[idx] = updated;\n this._currentAssistantMsg = updated;\n }\n\n if (transcript.isFinal) {\n this._currentAssistantMsg = null;\n }\n\n this._markVoiceMessagesDirty();\n this._notifySubscribers();\n }\n }\n\n private _finishVoiceAssistantMessage() {\n const last = this._voiceMessages.at(-1);\n if (last?.role === \"assistant\" && last.status.type === \"running\") {\n const idx = this._voiceMessages.length - 1;\n this._voiceMessages[idx] = {\n ...(last as ThreadAssistantMessage),\n status: { type: \"complete\", reason: \"stop\" },\n };\n this._markVoiceMessagesDirty();\n this._notifySubscribers();\n }\n }\n\n public disconnectVoice() {\n this._finishVoiceAssistantMessage();\n this._currentAssistantMsg = null;\n for (const unsub of this._voiceUnsubs) unsub();\n this._voiceUnsubs = [];\n this._voiceSession?.disconnect();\n this._voiceSession = undefined;\n this.voice = undefined;\n this._voiceVolume = 0;\n for (const cb of this._voiceVolumeSubscribers) cb();\n this._voiceMessages = [];\n this._markVoiceMessagesDirty();\n this._notifySubscribers();\n }\n\n public muteVoice() {\n if (!this._voiceSession) throw new Error(\"No active voice session\");\n this._voiceSession.mute();\n this.voice = {\n ...this.voice!,\n isMuted: true,\n };\n this._notifySubscribers();\n }\n\n public unmuteVoice() {\n if (!this._voiceSession) throw new Error(\"No active voice session\");\n this._voiceSession.unmute();\n this.voice = {\n ...this.voice!,\n isMuted: false,\n };\n this._notifySubscribers();\n }\n\n protected ensureInitialized() {\n if (!this._isInitialized) {\n this._isInitialized = true;\n this._notifyEventSubscribers(\"initialize\", {});\n }\n }\n\n public export() {\n return this.repository.export();\n }\n\n public import(data: ExportedMessageRepository) {\n this.ensureInitialized();\n this.repository.clear();\n this.repository.import(data);\n this._notifySubscribers();\n }\n\n public reset(initialMessages?: readonly ThreadMessageLike[]) {\n this.import(ExportedMessageRepository.fromArray(initialMessages ?? []));\n }\n\n private _eventSubscribers = new Map<\n ThreadRuntimeEventType,\n Set<(payload?: unknown) => void>\n >();\n\n public unstable_on<E extends ThreadRuntimeEventType>(\n event: E,\n callback: ThreadRuntimeEventCallback<E>,\n ) {\n const wrapped = callback as (payload?: unknown) => void;\n if (event === \"modelContextUpdate\") {\n // provider.subscribe is `() => void`; pump the typed empty payload to the user callback.\n return this._contextProvider.subscribe?.(() => wrapped({})) ?? (() => {});\n }\n\n let subscribers = this._eventSubscribers.get(event);\n if (!subscribers) {\n subscribers = new Set();\n this._eventSubscribers.set(event, subscribers);\n }\n subscribers.add(wrapped);\n\n // `initialize` latches: replay it (deferred) to subscribers that attach\n // after the thread already initialized, mirroring a BehaviorSubject.\n if (event === \"initialize\" && this._isInitialized) {\n queueMicrotask(() => {\n if (subscribers.has(wrapped)) wrapped({});\n });\n }\n\n return () => {\n this._eventSubscribers.get(event)?.delete(wrapped);\n };\n }\n}\n"],"mappings":";;;;;;AA4CA,IAAsB,wBAAtB,MAAyE;CAqE1C;CApE7B,iCAAyB,IAAI,IAAgB;CAC7C,iBAAyB;CAEzB,aAAgC,IAAI,kBAAkB;CAqBtD,iBAA4C,CAAC;CAC7C,mBAA6B;CAC7B,wBAAiE;CACjE,yBAAiC;CACjC,oBAA6D;CAE7D,0BAAoC;EAClC,KAAK;EACL,KAAK,wBAAwB;CAC/B;CAEA,mBAAuD;EACrD,OAAO,KAAK,WAAW,YAAY;CACrC;CAEA,IAAW,WAAqC;EAC9C,IAAI,KAAK,eAAe,WAAW,GACjC,OAAO,KAAK,iBAAiB;EAE/B,MAAM,OAAO,KAAK,iBAAiB;EACnC,IACE,KAAK,2BAA2B,KAAK,oBACrC,KAAK,sBAAsB,MAC3B;GACA,KAAK,wBAAwB,CAAC,GAAG,MAAM,GAAG,KAAK,cAAc;GAC7D,KAAK,yBAAyB,KAAK;GACnC,KAAK,oBAAoB;EAC3B;EACA,OAAO,KAAK;CACd;CAEA,IAAW,QAAQ;EACjB,IAAI;EACJ,KAAK,MAAM,WAAW,KAAK,UACzB,IAAI,QAAQ,SAAS,aACnB,6BAA6B;EAIjC,OAAO,4BAA4B,SAAS,kBAAkB;CAChE;CAEA,WAA2B,IAAI,iCAAiC,IAAI;CAEpE,YAAY,kBAAyD;EAAxC,KAAA,mBAAA;CAAyC;CAEtE,kBAAyB;EACvB,OAAO,KAAK,iBAAiB,gBAAgB;CAC/C;CAEA,iCAAyB,IAAI,IAA4C;CACzE,gBAAuB,WAAmB;EACxC,OAAO,KAAK,eAAe,IAAI,SAAS;CA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AC,CAAC,CAAC,YAAY,CAAC;EAGzE,IAAI,cAAc,KAAK,kBAAkB,IAAI,KAAK;EAClD,IAAI,CAAC,aAAa;GAChB,8BAAc,IAAI,IAAI;GACtB,KAAK,kBAAkB,IAAI,OAAO,WAAW;EAC/C;EACA,YAAY,IAAI,OAAO;EAIvB,IAAI,UAAU,gBAAgB,KAAK,gBACjC,qBAAqB;GACnB,IAAI,YAAY,IAAI,OAAO,GAAG,QAAQ,CAAC,CAAC;EAC1C,CAAC;EAGH,aAAa;GACX,KAAK,kBAAkB,IAAI,KAAK,CAAC,EAAE,OAAO,OAAO;EACnD;CACF;AACF"}
|
|
@@ -2,6 +2,7 @@ import { AppendMessage } from "../../types/message.js";
|
|
|
2
2
|
import { AttachmentAdapter } from "../../adapters/attachment.js";
|
|
3
3
|
import { Unsubscribe } from "../../types/unsubscribe.js";
|
|
4
4
|
import { DictationAdapter } from "../../adapters/speech.js";
|
|
5
|
+
import { QueueItemState } from "../../store/scopes/queue-item.js";
|
|
5
6
|
import { SendOptions, ThreadComposerRuntimeCore } from "../interfaces/composer-runtime-core.js";
|
|
6
7
|
import { ThreadRuntimeCore } from "../interfaces/thread-runtime-core.js";
|
|
7
8
|
import { BaseComposerRuntimeCore } from "./base-composer-runtime-core.js";
|
|
@@ -11,6 +12,9 @@ declare class DefaultThreadComposerRuntimeCore extends BaseComposerRuntimeCore i
|
|
|
11
12
|
private _canCancel;
|
|
12
13
|
get canCancel(): boolean;
|
|
13
14
|
get canSend(): boolean;
|
|
15
|
+
get queue(): readonly QueueItemState[];
|
|
16
|
+
steerQueueItem(queueItemId: string): void;
|
|
17
|
+
removeQueueItem(queueItemId: string): void;
|
|
14
18
|
protected getAttachmentAdapter(): AttachmentAdapter | undefined;
|
|
15
19
|
protected getDictationAdapter(): DictationAdapter | undefined;
|
|
16
20
|
constructor(runtime: Omit<ThreadRuntimeCore, "composer"> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-thread-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/default-thread-composer-runtime-core.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"default-thread-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/default-thread-composer-runtime-core.ts"],"mappings":";;;;;;;;;cAca,gCAAA,SACH,uBAAA,YACG,yBAAA;EAAA,QAgCD,OAAA;EAAA,QA9BF,UAAA;EAAA,IACG,SAAA;EAAA,IAIA,OAAA;EAAA,IAIS,KAAA,aAAkB,cAAA;EAItB,cAAA,CAAe,WAAA;EAIf,eAAA,CAAgB,WAAA;EAAA,UAItB,oBAAA,IAAoB,iBAAA;EAAA,UAIpB,mBAAA,IAAmB,gBAAA;cAKnB,OAAA,EAAS,IAAA,CAAK,iBAAA;IACpB,QAAA;MAEM,WAAA,GAAc,iBAAA;MACd,SAAA,GAAY,gBAAA;IAAA;EAAA;EASf,OAAA,IAT+B,WAAA;EA8BzB,UAAA,CACX,OAAA,EAAS,IAAA,CAAK,aAAA,4BACd,OAAA,GAAU,WAAA,GAAW,OAAA;EAWV,YAAA,IAAY,OAAA;AAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EMPTY_QUEUE_ITEMS } from "../../store/scopes/queue-item.js";
|
|
1
2
|
import { BaseComposerRuntimeCore } from "./base-composer-runtime-core.js";
|
|
2
3
|
//#region src/runtime/base/default-thread-composer-runtime-core.ts
|
|
3
4
|
var DefaultThreadComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
|
@@ -9,6 +10,15 @@ var DefaultThreadComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
|
|
9
10
|
get canSend() {
|
|
10
11
|
return !this.isEmpty && !this.runtime.isSendDisabled;
|
|
11
12
|
}
|
|
13
|
+
get queue() {
|
|
14
|
+
return this.runtime.getQueueItems?.() ?? EMPTY_QUEUE_ITEMS;
|
|
15
|
+
}
|
|
16
|
+
steerQueueItem(queueItemId) {
|
|
17
|
+
this.runtime.steerQueueItem?.(queueItemId);
|
|
18
|
+
}
|
|
19
|
+
removeQueueItem(queueItemId) {
|
|
20
|
+
this.runtime.removeQueueItem?.(queueItemId);
|
|
21
|
+
}
|
|
12
22
|
getAttachmentAdapter() {
|
|
13
23
|
return this.runtime.adapters?.attachments;
|
|
14
24
|
}
|
|
@@ -22,6 +32,7 @@ var DefaultThreadComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
|
|
22
32
|
}
|
|
23
33
|
connect() {
|
|
24
34
|
let lastIsSendDisabled = this.runtime.isSendDisabled;
|
|
35
|
+
let lastQueue = this.queue;
|
|
25
36
|
return this.runtime.subscribe(() => {
|
|
26
37
|
let changed = false;
|
|
27
38
|
if (this.canCancel !== this.runtime.capabilities.cancel) {
|
|
@@ -32,6 +43,10 @@ var DefaultThreadComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
|
|
32
43
|
lastIsSendDisabled = this.runtime.isSendDisabled;
|
|
33
44
|
changed = true;
|
|
34
45
|
}
|
|
46
|
+
if (lastQueue !== this.queue) {
|
|
47
|
+
lastQueue = this.queue;
|
|
48
|
+
changed = true;
|
|
49
|
+
}
|
|
35
50
|
if (changed) this._notifySubscribers();
|
|
36
51
|
});
|
|
37
52
|
}
|
|
@@ -40,7 +55,8 @@ var DefaultThreadComposerRuntimeCore = class extends BaseComposerRuntimeCore {
|
|
|
40
55
|
...message,
|
|
41
56
|
parentId: this.runtime.messages.at(-1)?.id ?? null,
|
|
42
57
|
sourceId: null,
|
|
43
|
-
startRun: options?.startRun
|
|
58
|
+
startRun: options?.startRun,
|
|
59
|
+
steer: options?.steer
|
|
44
60
|
});
|
|
45
61
|
}
|
|
46
62
|
async handleCancel() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-thread-composer-runtime-core.js","names":[],"sources":["../../../src/runtime/base/default-thread-composer-runtime-core.ts"],"sourcesContent":["import type { AppendMessage } from \"../../types/message\";\nimport type { AttachmentAdapter } from \"../../adapters/attachment\";\nimport type { DictationAdapter } from \"../../adapters/speech\";\nimport type {\n SendOptions,\n ThreadComposerRuntimeCore,\n} from \"../interfaces/composer-runtime-core\";\nimport type { ThreadRuntimeCore } from \"../interfaces/thread-runtime-core\";\nimport { BaseComposerRuntimeCore } from \"./base-composer-runtime-core\";\n\nexport class DefaultThreadComposerRuntimeCore\n extends BaseComposerRuntimeCore\n implements ThreadComposerRuntimeCore\n{\n private _canCancel = false;\n public get canCancel() {\n return this._canCancel;\n }\n\n public get canSend() {\n return !this.isEmpty && !this.runtime.isSendDisabled;\n }\n\n protected getAttachmentAdapter() {\n return this.runtime.adapters?.attachments;\n }\n\n protected getDictationAdapter() {\n return this.runtime.adapters?.dictation;\n }\n\n constructor(\n private runtime: Omit<ThreadRuntimeCore, \"composer\"> & {\n adapters?:\n | {\n attachments?: AttachmentAdapter | undefined;\n dictation?: DictationAdapter | undefined;\n }\n | undefined;\n },\n ) {\n super();\n this.connect();\n }\n\n public connect() {\n let lastIsSendDisabled = this.runtime.isSendDisabled;\n return this.runtime.subscribe(() => {\n let changed = false;\n if (this.canCancel !== this.runtime.capabilities.cancel) {\n this._canCancel = this.runtime.capabilities.cancel;\n changed = true;\n }\n if (lastIsSendDisabled !== this.runtime.isSendDisabled) {\n lastIsSendDisabled = this.runtime.isSendDisabled;\n changed = true;\n }\n if (changed) this._notifySubscribers();\n });\n }\n\n public async handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n options?: SendOptions,\n ) {\n this.runtime.append({\n ...(message as AppendMessage),\n parentId: this.runtime.messages.at(-1)?.id ?? null,\n sourceId: null,\n startRun: options?.startRun,\n });\n }\n\n public async handleCancel() {\n this.runtime.cancelRun();\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"default-thread-composer-runtime-core.js","names":[],"sources":["../../../src/runtime/base/default-thread-composer-runtime-core.ts"],"sourcesContent":["import type { AppendMessage } from \"../../types/message\";\nimport type { AttachmentAdapter } from \"../../adapters/attachment\";\nimport type { DictationAdapter } from \"../../adapters/speech\";\nimport type {\n SendOptions,\n ThreadComposerRuntimeCore,\n} from \"../interfaces/composer-runtime-core\";\nimport type { ThreadRuntimeCore } from \"../interfaces/thread-runtime-core\";\nimport {\n EMPTY_QUEUE_ITEMS,\n type QueueItemState,\n} from \"../../store/scopes/queue-item\";\nimport { BaseComposerRuntimeCore } from \"./base-composer-runtime-core\";\n\nexport class DefaultThreadComposerRuntimeCore\n extends BaseComposerRuntimeCore\n implements ThreadComposerRuntimeCore\n{\n private _canCancel = false;\n public get canCancel() {\n return this._canCancel;\n }\n\n public get canSend() {\n return !this.isEmpty && !this.runtime.isSendDisabled;\n }\n\n public override get queue(): readonly QueueItemState[] {\n return this.runtime.getQueueItems?.() ?? EMPTY_QUEUE_ITEMS;\n }\n\n public override steerQueueItem(queueItemId: string): void {\n this.runtime.steerQueueItem?.(queueItemId);\n }\n\n public override removeQueueItem(queueItemId: string): void {\n this.runtime.removeQueueItem?.(queueItemId);\n }\n\n protected getAttachmentAdapter() {\n return this.runtime.adapters?.attachments;\n }\n\n protected getDictationAdapter() {\n return this.runtime.adapters?.dictation;\n }\n\n constructor(\n private runtime: Omit<ThreadRuntimeCore, \"composer\"> & {\n adapters?:\n | {\n attachments?: AttachmentAdapter | undefined;\n dictation?: DictationAdapter | undefined;\n }\n | undefined;\n },\n ) {\n super();\n this.connect();\n }\n\n public connect() {\n let lastIsSendDisabled = this.runtime.isSendDisabled;\n let lastQueue = this.queue;\n return this.runtime.subscribe(() => {\n let changed = false;\n if (this.canCancel !== this.runtime.capabilities.cancel) {\n this._canCancel = this.runtime.capabilities.cancel;\n changed = true;\n }\n if (lastIsSendDisabled !== this.runtime.isSendDisabled) {\n lastIsSendDisabled = this.runtime.isSendDisabled;\n changed = true;\n }\n if (lastQueue !== this.queue) {\n lastQueue = this.queue;\n changed = true;\n }\n if (changed) this._notifySubscribers();\n });\n }\n\n public async handleSend(\n message: Omit<AppendMessage, \"parentId\" | \"sourceId\">,\n options?: SendOptions,\n ) {\n this.runtime.append({\n ...(message as AppendMessage),\n parentId: this.runtime.messages.at(-1)?.id ?? null,\n sourceId: null,\n startRun: options?.startRun,\n steer: options?.steer,\n });\n }\n\n public async handleCancel() {\n this.runtime.cancelRun();\n }\n}\n"],"mappings":";;;AAcA,IAAa,mCAAb,cACU,wBAEV;CA+BY;CA9BV,aAAqB;CACrB,IAAW,YAAY;EACrB,OAAO,KAAK;CACd;CAEA,IAAW,UAAU;EACnB,OAAO,CAAC,KAAK,WAAW,CAAC,KAAK,QAAQ;CACxC;CAEA,IAAoB,QAAmC;EACrD,OAAO,KAAK,QAAQ,gBAAgB,KAAK;CAC3C;CAEA,eAA+B,aAA2B;EACxD,KAAK,QAAQ,iBAAiB,WAAW;CAC3C;CAEA,gBAAgC,aAA2B;EACzD,KAAK,QAAQ,kBAAkB,WAAW;CAC5C;CAEA,uBAAiC;EAC/B,OAAO,KAAK,QAAQ,UAAU;CAChC;CAEA,sBAAgC;EAC9B,OAAO,KAAK,QAAQ,UAAU;CAChC;CAEA,YACE,SAQA;EACA,MAAM;EATE,KAAA,UAAA;EAUR,KAAK,QAAQ;CACf;CAEA,UAAiB;EACf,IAAI,qBAAqB,KAAK,QAAQ;EACtC,IAAI,YAAY,KAAK;EACrB,OAAO,KAAK,QAAQ,gBAAgB;GAClC,IAAI,UAAU;GACd,IAAI,KAAK,cAAc,KAAK,QAAQ,aAAa,QAAQ;IACvD,KAAK,aAAa,KAAK,QAAQ,aAAa;IAC5C,UAAU;GACZ;GACA,IAAI,uBAAuB,KAAK,QAAQ,gBAAgB;IACtD,qBAAqB,KAAK,QAAQ;IAClC,UAAU;GACZ;GACA,IAAI,cAAc,KAAK,OAAO;IAC5B,YAAY,KAAK;IACjB,UAAU;GACZ;GACA,IAAI,SAAS,KAAK,mBAAmB;EACvC,CAAC;CACH;CAEA,MAAa,WACX,SACA,SACA;EACA,KAAK,QAAQ,OAAO;GAClB,GAAI;GACJ,UAAU,KAAK,QAAQ,SAAS,GAAG,EAAE,CAAC,EAAE,MAAM;GAC9C,UAAU;GACV,UAAU,SAAS;GACnB,OAAO,SAAS;EAClB,CAAC;CACH;CAEA,MAAa,eAAe;EAC1B,KAAK,QAAQ,UAAU;CACzB;AACF"}
|
|
@@ -3,6 +3,7 @@ import { Attachment, CreateAttachment } from "../../types/attachment.js";
|
|
|
3
3
|
import { Unsubscribe } from "../../types/unsubscribe.js";
|
|
4
4
|
import { DictationAdapter } from "../../adapters/speech.js";
|
|
5
5
|
import { QuoteInfo } from "../../types/quote.js";
|
|
6
|
+
import { QueueItemState } from "../../store/scopes/queue-item.js";
|
|
6
7
|
|
|
7
8
|
//#region src/runtime/interfaces/composer-runtime-core.d.ts
|
|
8
9
|
type AttachmentAddErrorReason = "no-adapter" | "not-accepted" | "adapter-error";
|
|
@@ -33,7 +34,8 @@ type DictationState = {
|
|
|
33
34
|
readonly inputDisabled?: boolean;
|
|
34
35
|
};
|
|
35
36
|
type SendOptions = {
|
|
36
|
-
startRun?: boolean;
|
|
37
|
+
startRun?: boolean; /** Process this message next; only meaningful with the `queue` capability. */
|
|
38
|
+
steer?: boolean;
|
|
37
39
|
};
|
|
38
40
|
type ComposerRuntimeCore = Readonly<{
|
|
39
41
|
isEditing: boolean;
|
|
@@ -56,6 +58,9 @@ type ComposerRuntimeCore = Readonly<{
|
|
|
56
58
|
clearAttachments: () => Promise<void>;
|
|
57
59
|
send: (options?: SendOptions) => void;
|
|
58
60
|
cancel: () => void;
|
|
61
|
+
queue: readonly QueueItemState[];
|
|
62
|
+
steerQueueItem: (queueItemId: string) => void;
|
|
63
|
+
removeQueueItem: (queueItemId: string) => void;
|
|
59
64
|
dictation: DictationState | undefined;
|
|
60
65
|
startDictation: () => void;
|
|
61
66
|
stopDictation: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/interfaces/composer-runtime-core.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"composer-runtime-core.d.ts","names":[],"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A,SAAA,GAAY,QAAA,iBAAyB,WAAA;EAlDH;;;;AAEZ;EAuDtB,WAAA,aAAwB,wBAAA,EACtB,KAAA,EAAO,CAAA,EACP,QAAA,EAAU,4BAAA,CAA6B,CAAA,MACpC,WAAA;AAAA;AAAA,KAGK,yBAAA,GAA4B,mBAAmB;AAAA,KAE/C,uBAAA,GAA0B,mBAAA,GACpC,QAAQ;EACN,QAAA;EACA,QAAA;AAAA"}
|
|
@@ -33,6 +33,7 @@ type ThreadListRuntimeCore = {
|
|
|
33
33
|
loadMore?(): Promise<void>;
|
|
34
34
|
detach(threadId: string): Promise<void>;
|
|
35
35
|
rename(threadId: string, newTitle: string): Promise<void>;
|
|
36
|
+
updateCustom?(threadId: string, custom: Record<string, unknown> | undefined): Promise<void>;
|
|
36
37
|
archive(threadId: string): Promise<void>;
|
|
37
38
|
unarchive(threadId: string): Promise<void>;
|
|
38
39
|
delete(threadId: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/interfaces/thread-list-runtime-core.ts"],"mappings":";;;;KAGY,oBAAA;AAAA,KAEA,uBAAA;EAAA,SACD,EAAA;EAAA,SACA,QAAA;EAAA,SACA,UAAA;EAAA,SAEA,MAAA,EAAQ,oBAAA;EAAA,SACR,KAAA;EAAA,SACA,MAAA,GAAS,MAAA;EAAA,SAET,OAAA,GAAU,iBAAA;AAAA;AAAA,KAGT,qBAAA;EAAA,SACD,SAAA;EAAA,SACA,aAAA;EAAA,SACA,OAAA;EACT,YAAA;EACA,WAAA;EAEA,SAAA;EACA,iBAAA;EAAA,SAES,WAAA,EAAa,QAAA,CAAS,MAAA,SAAe,uBAAA;EAE9C,wBAAA,IAA4B,iBAAA;EAC5B,oBAAA,CAAqB,QAAA,WAAmB,iBAAA;EAExC,WAAA,CAAY,QAAA,WAAmB,uBAAA;EAE/B,cAAA,CACE,QAAA,UACA,OAAA;IAAY,SAAA;EAAA,IACX,OAAA;EACH,iBAAA,IAAqB,OAAA;EAErB,qBAAA,IAAyB,OAAA;EACzB,MAAA,KAAW,OAAA;EACX,QAAA,KAAa,OAAA;EAEb,MAAA,CAAO,QAAA,WAAmB,OAAA;EAC1B,MAAA,CAAO,QAAA,UAAkB,QAAA,WAAmB,OAAA;EAC5C,OAAA,CAAQ,QAAA,WAAmB,OAAA;EAC3B,SAAA,CAAU,QAAA,WAAmB,OAAA;EAC7B,MAAA,CAAO,QAAA,WAAmB,OAAA;EAE1B,UAAA,CACE,QAAA,WACC,OAAA;IAAU,QAAA;IAAkB,UAAA;EAAA;EAC/B,aAAA,CAAc,QAAA,WAAmB,OAAA;EAEjC,SAAA,CAAU,QAAA,eAAuB,WAAA;AAAA"}
|
|
1
|
+
{"version":3,"file":"thread-list-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/interfaces/thread-list-runtime-core.ts"],"mappings":";;;;KAGY,oBAAA;AAAA,KAEA,uBAAA;EAAA,SACD,EAAA;EAAA,SACA,QAAA;EAAA,SACA,UAAA;EAAA,SAEA,MAAA,EAAQ,oBAAA;EAAA,SACR,KAAA;EAAA,SACA,MAAA,GAAS,MAAA;EAAA,SAET,OAAA,GAAU,iBAAA;AAAA;AAAA,KAGT,qBAAA;EAAA,SACD,SAAA;EAAA,SACA,aAAA;EAAA,SACA,OAAA;EACT,YAAA;EACA,WAAA;EAEA,SAAA;EACA,iBAAA;EAAA,SAES,WAAA,EAAa,QAAA,CAAS,MAAA,SAAe,uBAAA;EAE9C,wBAAA,IAA4B,iBAAA;EAC5B,oBAAA,CAAqB,QAAA,WAAmB,iBAAA;EAExC,WAAA,CAAY,QAAA,WAAmB,uBAAA;EAE/B,cAAA,CACE,QAAA,UACA,OAAA;IAAY,SAAA;EAAA,IACX,OAAA;EACH,iBAAA,IAAqB,OAAA;EAErB,qBAAA,IAAyB,OAAA;EACzB,MAAA,KAAW,OAAA;EACX,QAAA,KAAa,OAAA;EAEb,MAAA,CAAO,QAAA,WAAmB,OAAA;EAC1B,MAAA,CAAO,QAAA,UAAkB,QAAA,WAAmB,OAAA;EAC5C,YAAA,EACE,QAAA,UACA,MAAA,EAAQ,MAAA,gCACP,OAAA;EACH,OAAA,CAAQ,QAAA,WAAmB,OAAA;EAC3B,SAAA,CAAU,QAAA,WAAmB,OAAA;EAC7B,MAAA,CAAO,QAAA,WAAmB,OAAA;EAE1B,UAAA,CACE,QAAA,WACC,OAAA;IAAU,QAAA;IAAkB,UAAA;EAAA;EAC/B,aAAA,CAAc,QAAA,WAAmB,OAAA;EAEjC,SAAA,CAAU,QAAA,eAAuB,WAAA;AAAA"}
|
|
@@ -6,6 +6,7 @@ import { ModelContext } from "../../model-context/types.js";
|
|
|
6
6
|
import { ChatModelRunOptions, ChatModelRunResult } from "../utils/chat-model-adapter.js";
|
|
7
7
|
import { ThreadMessageLike } from "../utils/thread-message-like.js";
|
|
8
8
|
import { ExportedMessageRepository } from "../utils/message-repository.js";
|
|
9
|
+
import { QueueItemState } from "../../store/scopes/queue-item.js";
|
|
9
10
|
import { EditComposerRuntimeCore, ThreadComposerRuntimeCore } from "./composer-runtime-core.js";
|
|
10
11
|
import { ToolModelContentPart } from "assistant-stream";
|
|
11
12
|
import { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
@@ -134,6 +135,9 @@ type ThreadRuntimeCore = Readonly<{
|
|
|
134
135
|
composer: ThreadComposerRuntimeCore;
|
|
135
136
|
getEditComposer: (messageId: string) => EditComposerRuntimeCore | undefined;
|
|
136
137
|
beginEdit: (messageId: string) => void;
|
|
138
|
+
getQueueItems?: () => readonly QueueItemState[];
|
|
139
|
+
steerQueueItem?: (queueItemId: string) => void;
|
|
140
|
+
removeQueueItem?: (queueItemId: string) => void;
|
|
137
141
|
speech: SpeechState | undefined;
|
|
138
142
|
voice: VoiceSessionState | undefined;
|
|
139
143
|
capabilities: Readonly<RuntimeCapabilities>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/interfaces/thread-runtime-core.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"thread-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/interfaces/thread-runtime-core.ts"],"mappings":";;;;;;;;;;;;;;KAoBY,mBAAA;EAAA,SACD,cAAA;EAAA,SACA,qBAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA;EAAA,SACA,MAAA;EAAA,SACA,aAAA;EAAA,SACA,MAAA;EAAA,SACA,SAAA;EAAA,SACA,KAAA;EAAA,SACA,WAAA;EAAA,SACA,QAAA;EAAA,SACA,KAAA;AAAA;AAAA,KAGC,oBAAA;EACV,SAAA;EACA,QAAA;EACA,UAAA;EACA,MAAA,EAAQ,iBAAA;EACR,OAAA;EACA,QAAA,GAAW,iBAAA;;;;;;;EAOX,YAAA,YAAwB,oBAAA;AAAA;AAAA,KAGd,qBAAA;EACV,UAAA;EACA,OAAO;AAAA;AAAA,KAGG,4BAAA;EACV,UAAA;EACA,QAAA;EACA,MAAA;AAAA;AAAA,KAGU,qBAAA;EACV,SAAA;EACA,IAAI;AAAA;AAAA,KAGM,gBAAA;EACV,MAAM;AAAA;AAAA,KAGI,WAAA;EAAA,SACD,SAAA;EAAA,SACA,MAAA,EAAQ,sBAAA,CAAuB,MAAM;AAAA;AAAA,KAGpC,iBAAA;EAAA,SACD,MAAA,EAAQ,oBAAA,CAAqB,MAAA;EAAA,SAC7B,OAAA;EAAA,SACA,IAAA,EAAM,oBAAA,CAAqB,IAAI;AAAA;AAAA,KAG9B,iBAAA;EAAA,SACD,IAAI;AAAA;AAAA,KAGH,yBAAA;EAnBA;;;;AACJ;AAGR;EAsBE,QAAA,EAAU,MAAA;;;;;;;EAOV,MAAA,EAAQ,MAAA;EA3BsC;AAGhD;;;;;;;EAiCE,UAAA,EAAY,MAAA;EA9BH;;;;EAmCT,kBAAA,EAAoB,MAAA;AAAA;AAAA,KAGV,sBAAA,SAA+B,yBAAyB;AAAA,KAExD,0BAAA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,WAAA;EAErC,cAAA;EACA,oBAAA,GAAuB,QAAA,iBAAyB,WAAA;EAEhD,MAAA,CAAO,UAAA,EAAY,yBAAA;EACnB,MAAA,IAAU,yBAAA;EAEV,mBAAA;EACA,mBAAA,CAAoB,KAAA;EAEpB,KAAA,CAAM,eAAA,YAA2B,iBAAA;EAhFK;AAGxC;;;;EAoFE,WAAA,WAAsB,sBAAA,EACpB,KAAA,EAAO,CAAA,EACP,QAAA,EAAU,0BAAA,CAA2B,CAAA,IACpC,WAAA;AAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AppendMessage } from "../../types/message.js";
|
|
2
|
+
import { QueueItemState } from "../../store/scopes/queue-item.js";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/queue/external-thread-queue-adapter.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The queue surface a runtime exposes so the composer can stay usable during a
|
|
7
|
+
* run and render the pending messages.
|
|
8
|
+
*/
|
|
9
|
+
type ExternalThreadQueueAdapter = {
|
|
10
|
+
items: readonly QueueItemState[];
|
|
11
|
+
enqueue: (message: AppendMessage, options: {
|
|
12
|
+
steer: boolean;
|
|
13
|
+
}) => void;
|
|
14
|
+
steer: (queueItemId: string) => void;
|
|
15
|
+
remove: (queueItemId: string) => void;
|
|
16
|
+
clear: (reason: "edit" | "reload" | "cancel-run") => void;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ExternalThreadQueueAdapter };
|
|
20
|
+
//# sourceMappingURL=external-thread-queue-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-thread-queue-adapter.d.ts","names":[],"sources":["../../../src/runtime/queue/external-thread-queue-adapter.ts"],"mappings":";;;;;;AAOA;;KAAY,0BAAA;EACV,KAAA,WAAgB,cAAA;EAChB,OAAA,GAAU,OAAA,EAAS,aAAa,EAAE,OAAA;IAAW,KAAA;EAAA;EAC7C,KAAA,GAAQ,WAAA;EACR,MAAA,GAAS,WAAA;EACT,KAAA,GAAQ,MAAA;AAAA"}
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AppendMessage } from "../../types/message.js";
|
|
2
|
+
import { ExternalThreadQueueAdapter } from "./external-thread-queue-adapter.js";
|
|
3
|
+
|
|
4
|
+
//#region src/runtime/queue/message-queue.d.ts
|
|
5
|
+
type MessageQueueDriver = {
|
|
6
|
+
run: (message: AppendMessage, options: {
|
|
7
|
+
steer: boolean;
|
|
8
|
+
}) => void; /** When omitted, `steer` degrades to "process next" instead of interrupting. */
|
|
9
|
+
cancel?: (() => void) | undefined;
|
|
10
|
+
};
|
|
11
|
+
type MessageQueueController = {
|
|
12
|
+
readonly adapter: ExternalThreadQueueAdapter; /** Mark a run as in flight so concurrent sends buffer; call on the rising edge. */
|
|
13
|
+
notifyBusy: () => void; /** Advances to the next pending message; call on the run's falling edge. */
|
|
14
|
+
notifyIdle: () => void;
|
|
15
|
+
subscribe: (callback: () => void) => () => void;
|
|
16
|
+
};
|
|
17
|
+
declare const createMessageQueue: (driver: MessageQueueDriver) => MessageQueueController;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { MessageQueueController, MessageQueueDriver, createMessageQueue };
|
|
20
|
+
//# sourceMappingURL=message-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-queue.d.ts","names":[],"sources":["../../../src/runtime/queue/message-queue.ts"],"mappings":";;;;KASY,kBAAA;EACV,GAAA,GAAM,OAAA,EAAS,aAAa,EAAE,OAAA;IAAW,KAAA;EAAA;EAEzC,MAAA;AAAA;AAAA,KAGU,sBAAA;EAAA,SACD,OAAA,EAAS,0BAA0B,EANH;EAQzC,UAAA,cANA;EAQA,UAAA;EACA,SAAA,GAAY,QAAA;AAAA;AAAA,cAGD,kBAAA,GACX,MAAA,EAAQ,kBAAA,KACP,sBAqGF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { generateId } from "../../utils/id.js";
|
|
2
|
+
import { EMPTY_QUEUE_ITEMS } from "../../store/scopes/queue-item.js";
|
|
3
|
+
import { getThreadMessageText } from "../../utils/text.js";
|
|
4
|
+
//#region src/runtime/queue/message-queue.ts
|
|
5
|
+
const createMessageQueue = (driver) => {
|
|
6
|
+
let items = EMPTY_QUEUE_ITEMS;
|
|
7
|
+
const messages = /* @__PURE__ */ new Map();
|
|
8
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
9
|
+
let running = false;
|
|
10
|
+
let suppressIdle = 0;
|
|
11
|
+
const notify = () => {
|
|
12
|
+
for (const callback of subscribers) callback();
|
|
13
|
+
};
|
|
14
|
+
const setItems = (next) => {
|
|
15
|
+
items = next;
|
|
16
|
+
adapter.items = next;
|
|
17
|
+
notify();
|
|
18
|
+
};
|
|
19
|
+
const advance = () => {
|
|
20
|
+
if (running || items.length === 0) return;
|
|
21
|
+
const head = items[0];
|
|
22
|
+
const message = messages.get(head.id);
|
|
23
|
+
messages.delete(head.id);
|
|
24
|
+
setItems(items.slice(1));
|
|
25
|
+
if (!message) return;
|
|
26
|
+
running = true;
|
|
27
|
+
driver.run(message, { steer: false });
|
|
28
|
+
};
|
|
29
|
+
const enqueue = (message, { steer }) => {
|
|
30
|
+
const id = generateId();
|
|
31
|
+
const prompt = getThreadMessageText(message);
|
|
32
|
+
messages.set(id, message);
|
|
33
|
+
setItems([...items, {
|
|
34
|
+
id,
|
|
35
|
+
prompt
|
|
36
|
+
}]);
|
|
37
|
+
if (steer) steerItem(id);
|
|
38
|
+
else advance();
|
|
39
|
+
};
|
|
40
|
+
const steerItem = (queueItemId) => {
|
|
41
|
+
if (!messages.has(queueItemId)) return;
|
|
42
|
+
if (driver.cancel && running) {
|
|
43
|
+
const message = messages.get(queueItemId);
|
|
44
|
+
messages.delete(queueItemId);
|
|
45
|
+
setItems(items.filter((item) => item.id !== queueItemId));
|
|
46
|
+
suppressIdle++;
|
|
47
|
+
driver.cancel();
|
|
48
|
+
running = true;
|
|
49
|
+
driver.run(message, { steer: true });
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const target = items.find((item) => item.id === queueItemId);
|
|
53
|
+
if (!target) return;
|
|
54
|
+
setItems([target, ...items.filter((item) => item.id !== queueItemId)]);
|
|
55
|
+
advance();
|
|
56
|
+
};
|
|
57
|
+
const remove = (queueItemId) => {
|
|
58
|
+
if (!messages.delete(queueItemId)) return;
|
|
59
|
+
setItems(items.filter((item) => item.id !== queueItemId));
|
|
60
|
+
};
|
|
61
|
+
const clear = () => {
|
|
62
|
+
if (items.length === 0) return;
|
|
63
|
+
messages.clear();
|
|
64
|
+
setItems(EMPTY_QUEUE_ITEMS);
|
|
65
|
+
};
|
|
66
|
+
const adapter = {
|
|
67
|
+
items,
|
|
68
|
+
enqueue,
|
|
69
|
+
steer: steerItem,
|
|
70
|
+
remove,
|
|
71
|
+
clear
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
adapter,
|
|
75
|
+
notifyBusy: () => {
|
|
76
|
+
running = true;
|
|
77
|
+
},
|
|
78
|
+
notifyIdle: () => {
|
|
79
|
+
if (suppressIdle > 0) {
|
|
80
|
+
suppressIdle--;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
running = false;
|
|
84
|
+
advance();
|
|
85
|
+
},
|
|
86
|
+
subscribe: (callback) => {
|
|
87
|
+
subscribers.add(callback);
|
|
88
|
+
return () => {
|
|
89
|
+
subscribers.delete(callback);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
export { createMessageQueue };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=message-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-queue.js","names":[],"sources":["../../../src/runtime/queue/message-queue.ts"],"sourcesContent":["import type { AppendMessage } from \"../../types/message\";\nimport {\n EMPTY_QUEUE_ITEMS,\n type QueueItemState,\n} from \"../../store/scopes/queue-item\";\nimport { generateId } from \"../../utils/id\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport type { ExternalThreadQueueAdapter } from \"./external-thread-queue-adapter\";\n\nexport type MessageQueueDriver = {\n run: (message: AppendMessage, options: { steer: boolean }) => void;\n /** When omitted, `steer` degrades to \"process next\" instead of interrupting. */\n cancel?: (() => void) | undefined;\n};\n\nexport type MessageQueueController = {\n readonly adapter: ExternalThreadQueueAdapter;\n /** Mark a run as in flight so concurrent sends buffer; call on the rising edge. */\n notifyBusy: () => void;\n /** Advances to the next pending message; call on the run's falling edge. */\n notifyIdle: () => void;\n subscribe: (callback: () => void) => () => void;\n};\n\nexport const createMessageQueue = (\n driver: MessageQueueDriver,\n): MessageQueueController => {\n let items: readonly QueueItemState[] = EMPTY_QUEUE_ITEMS;\n const messages = new Map<string, AppendMessage>();\n const subscribers = new Set<() => void>();\n\n let running = false;\n // swallow the cancelled run's settle when steering so it does not double-advance\n let suppressIdle = 0;\n\n const notify = () => {\n for (const callback of subscribers) callback();\n };\n\n const setItems = (next: readonly QueueItemState[]) => {\n items = next;\n adapter.items = next;\n notify();\n };\n\n const advance = () => {\n if (running || items.length === 0) return;\n const head = items[0]!;\n const message = messages.get(head.id);\n messages.delete(head.id);\n setItems(items.slice(1));\n if (!message) return;\n running = true;\n driver.run(message, { steer: false });\n };\n\n const enqueue = (message: AppendMessage, { steer }: { steer: boolean }) => {\n const id = generateId();\n const prompt = getThreadMessageText(message);\n messages.set(id, message);\n setItems([...items, { id, prompt }]);\n if (steer) {\n steerItem(id);\n } else {\n advance();\n }\n };\n\n const steerItem = (queueItemId: string) => {\n if (!messages.has(queueItemId)) return;\n\n if (driver.cancel && running) {\n const message = messages.get(queueItemId)!;\n messages.delete(queueItemId);\n setItems(items.filter((item) => item.id !== queueItemId));\n suppressIdle++;\n driver.cancel();\n running = true;\n driver.run(message, { steer: true });\n return;\n }\n\n const target = items.find((item) => item.id === queueItemId);\n if (!target) return;\n setItems([target, ...items.filter((item) => item.id !== queueItemId)]);\n advance();\n };\n\n const remove = (queueItemId: string) => {\n if (!messages.delete(queueItemId)) return;\n setItems(items.filter((item) => item.id !== queueItemId));\n };\n\n const clear = () => {\n if (items.length === 0) return;\n messages.clear();\n setItems(EMPTY_QUEUE_ITEMS);\n };\n\n const adapter: ExternalThreadQueueAdapter = {\n items,\n enqueue,\n steer: steerItem,\n remove,\n clear,\n };\n\n return {\n adapter,\n notifyBusy: () => {\n running = true;\n },\n notifyIdle: () => {\n if (suppressIdle > 0) {\n suppressIdle--;\n return;\n }\n running = false;\n advance();\n },\n subscribe: (callback) => {\n subscribers.add(callback);\n return () => {\n subscribers.delete(callback);\n };\n },\n };\n};\n"],"mappings":";;;;AAwBA,MAAa,sBACX,WAC2B;CAC3B,IAAI,QAAmC;CACvC,MAAM,2BAAW,IAAI,IAA2B;CAChD,MAAM,8BAAc,IAAI,IAAgB;CAExC,IAAI,UAAU;CAEd,IAAI,eAAe;CAEnB,MAAM,eAAe;EACnB,KAAK,MAAM,YAAY,aAAa,SAAS;CAC/C;CAEA,MAAM,YAAY,SAAoC;EACpD,QAAQ;EACR,QAAQ,QAAQ;EAChB,OAAO;CACT;CAEA,MAAM,gBAAgB;EACpB,IAAI,WAAW,MAAM,WAAW,GAAG;EACnC,MAAM,OAAO,MAAM;EACnB,MAAM,UAAU,SAAS,IAAI,KAAK,EAAE;EACpC,SAAS,OAAO,KAAK,EAAE;EACvB,SAAS,MAAM,MAAM,CAAC,CAAC;EACvB,IAAI,CAAC,SAAS;EACd,UAAU;EACV,OAAO,IAAI,SAAS,EAAE,OAAO,MAAM,CAAC;CACtC;CAEA,MAAM,WAAW,SAAwB,EAAE,YAAgC;EACzE,MAAM,KAAK,WAAW;EACtB,MAAM,SAAS,qBAAqB,OAAO;EAC3C,SAAS,IAAI,IAAI,OAAO;EACxB,SAAS,CAAC,GAAG,OAAO;GAAE;GAAI;EAAO,CAAC,CAAC;EACnC,IAAI,OACF,UAAU,EAAE;OAEZ,QAAQ;CAEZ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