@assistant-ui/core 0.2.22 → 0.3.0
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/thread-history.d.ts +8 -0
- package/dist/adapters/thread-history.d.ts.map +1 -1
- package/dist/internal.d.ts +3 -2
- package/dist/internal.js +3 -2
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +36 -21
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/types.d.ts.map +1 -1
- package/dist/model-context/types.js +13 -4
- package/dist/model-context/types.js.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +3 -2
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +40 -55
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/client/interactable-model-context.js +1 -0
- package/dist/react/client/interactable-model-context.js.map +1 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.js +1 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.js.map +1 -1
- package/dist/react/interactables-legacy/useInteractableState.js +4 -3
- package/dist/react/interactables-legacy/useInteractableState.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/useAssistantTool.js +29 -25
- package/dist/react/model-context/useAssistantTool.js.map +1 -1
- package/dist/react/model-context/useAssistantToolUI.js +1 -1
- package/dist/react/model-context/useAssistantToolUI.js.map +1 -1
- package/dist/react/model-context/useAuiToolOverrides.js +1 -1
- package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
- package/dist/react/model-context/useInteractable.js +1 -1
- package/dist/react/model-context/useInteractable.js.map +1 -1
- package/dist/react/model-context/useInteractableState.js +3 -2
- package/dist/react/model-context/useInteractableState.js.map +1 -1
- package/dist/react/model-context/useInteractableVersions.js +1 -0
- package/dist/react/model-context/useInteractableVersions.js.map +1 -1
- package/dist/react/model-context/useToolArgsStatus.js +1 -0
- package/dist/react/model-context/useToolArgsStatus.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.js +4 -3
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js +2 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarFeedback.js +3 -2
- package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.js +2 -1
- package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarSpeak.js +2 -1
- package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +2 -1
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.js +2 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js +2 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.js +2 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.js +2 -1
- package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerDictate.js +2 -1
- package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.js +2 -1
- package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerCancel.js +2 -1
- package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerSend.js +2 -1
- package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageBranching.js +3 -2
- package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageReload.js +2 -1
- package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +8 -7
- package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemArchive.js +2 -1
- package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemDelete.js +2 -1
- package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js +2 -1
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +2 -1
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +2 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListNew.js +2 -1
- package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
- package/dist/react/primitive-hooks/useVoice.js +5 -13
- package/dist/react/primitive-hooks/useVoice.js.map +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.d.ts.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/message/MessageAttachments.d.ts.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/MessageParts.js +84 -122
- package/dist/react/primitives/message/MessageParts.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 +2 -2
- package/dist/react/providers/AttachmentByIndexProvider.js.map +1 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +1 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +30 -18
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
- package/dist/react/providers/MessageByIdProvider.js +2 -2
- package/dist/react/providers/MessageByIdProvider.js.map +1 -1
- package/dist/react/providers/MessageByIndexProvider.js +2 -2
- package/dist/react/providers/MessageByIndexProvider.js.map +1 -1
- package/dist/react/providers/PartByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/PartByIndexProvider.js +30 -18
- package/dist/react/providers/PartByIndexProvider.js.map +1 -1
- package/dist/react/providers/QueueItemByIndexProvider.js +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 +1 -1
- package/dist/react/providers/SuggestionByIndexProvider.js.map +1 -1
- package/dist/react/providers/TextMessagePartProvider.js +1 -0
- package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
- package/dist/react/providers/ThreadListItemByIndexProvider.js +1 -1
- package/dist/react/providers/ThreadListItemByIndexProvider.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +3 -3
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +6 -4
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +31 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +42 -20
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +12 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +2 -1
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +75 -73
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/createRuntimeExtras.js +1 -1
- package/dist/react/runtimes/createRuntimeExtras.js.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/useExternalStoreSharedOptions.js +1 -0
- package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.d.ts +0 -1
- package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -1
- package/dist/react/types/scopes/tools.d.ts +0 -6
- package/dist/react/types/scopes/tools.d.ts.map +1 -1
- package/dist/react/utils/groupParts.d.ts +1 -3
- package/dist/react/utils/groupParts.d.ts.map +1 -1
- package/dist/react/utils/groupParts.js +1 -3
- package/dist/react/utils/groupParts.js.map +1 -1
- package/dist/runtime/api/assistant-runtime.d.ts +1 -1
- package/dist/runtime/api/assistant-runtime.d.ts.map +1 -1
- package/dist/runtime/api/assistant-runtime.js +1 -1
- package/dist/runtime/api/assistant-runtime.js.map +1 -1
- package/dist/runtime/api/attachment-runtime.d.ts +1 -1
- package/dist/runtime/api/attachment-runtime.d.ts.map +1 -1
- package/dist/runtime/api/attachment-runtime.js +1 -1
- package/dist/runtime/api/attachment-runtime.js.map +1 -1
- package/dist/runtime/api/composer-runtime.d.ts +2 -2
- package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.js +2 -2
- package/dist/runtime/api/composer-runtime.js.map +1 -1
- package/dist/runtime/api/message-part-runtime.d.ts +4 -4
- package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-part-runtime.js +3 -3
- package/dist/runtime/api/message-part-runtime.js.map +1 -1
- package/dist/runtime/api/message-runtime.d.ts +1 -1
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +2 -2
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.d.ts +1 -1
- package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.js +2 -2
- package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +1 -1
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts +2 -2
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.js +2 -2
- package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.js +4 -2
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +1 -1
- 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 +1 -1
- 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.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +12 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/internal.d.ts +2 -1
- package/dist/runtimes/internal.js +2 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +3 -0
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +44 -13
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +32 -27
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +2 -0
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/no-op-composer-client.js +1 -0
- package/dist/store/clients/no-op-composer-client.js.map +1 -1
- package/dist/store/clients/runtime-adapter.js +3 -3
- package/dist/store/clients/runtime-adapter.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +1 -0
- 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 +17 -15
- package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
- package/dist/store/scopes/thread.d.ts +1 -0
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/subscribable/subscribable.d.ts +3 -3
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +3 -3
- package/dist/subscribable/subscribable.js.map +1 -1
- package/package.json +8 -8
- package/src/adapters/thread-history.ts +8 -0
- package/src/internal.ts +1 -1
- package/src/model-context/frame/host.test.ts +47 -0
- package/src/model-context/frame/host.ts +46 -19
- package/src/model-context/types.ts +16 -6
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +17 -7
- package/src/react/client/Tools.ts +0 -7
- package/src/react/interactables-legacy/useAssistantInteractable.ts +1 -1
- package/src/react/interactables-legacy/useInteractableState.ts +3 -3
- package/src/react/model-context/useAssistantContext.ts +1 -1
- package/src/react/model-context/useAssistantDataUI.ts +1 -1
- package/src/react/model-context/useAssistantInstructions.ts +1 -1
- package/src/react/model-context/useAssistantTool.ts +2 -2
- package/src/react/model-context/useAssistantToolUI.ts +1 -1
- package/src/react/model-context/useAuiToolOverrides.ts +1 -1
- package/src/react/model-context/useInteractable.ts +1 -1
- package/src/react/model-context/useInteractableState.ts +2 -2
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +2 -2
- package/src/react/primitive-hooks/useActionBarCopy.ts +3 -3
- package/src/react/primitive-hooks/useActionBarEdit.ts +1 -1
- package/src/react/primitive-hooks/useActionBarFeedback.ts +2 -2
- package/src/react/primitive-hooks/useActionBarReload.ts +1 -1
- package/src/react/primitive-hooks/useActionBarSpeak.ts +1 -1
- package/src/react/primitive-hooks/useActionBarStopSpeaking.ts +1 -1
- package/src/react/primitive-hooks/useBranchPickerNext.ts +1 -1
- package/src/react/primitive-hooks/useBranchPickerPrevious.ts +1 -1
- package/src/react/primitive-hooks/useComposerAddAttachment.ts +1 -1
- package/src/react/primitive-hooks/useComposerCancel.ts +1 -1
- package/src/react/primitive-hooks/useComposerDictate.ts +1 -1
- package/src/react/primitive-hooks/useComposerSend.ts +1 -1
- package/src/react/primitive-hooks/useEditComposerCancel.ts +1 -1
- package/src/react/primitive-hooks/useEditComposerSend.ts +1 -1
- package/src/react/primitive-hooks/useMessageBranching.ts +2 -2
- package/src/react/primitive-hooks/useMessageReload.ts +1 -1
- package/src/react/primitive-hooks/useSuggestionTrigger.ts +9 -9
- package/src/react/primitive-hooks/useThreadListItemArchive.ts +1 -1
- package/src/react/primitive-hooks/useThreadListItemDelete.ts +1 -1
- package/src/react/primitive-hooks/useThreadListItemTrigger.ts +1 -1
- package/src/react/primitive-hooks/useThreadListItemUnarchive.ts +1 -1
- package/src/react/primitive-hooks/useThreadListLoadMore.ts +1 -1
- package/src/react/primitive-hooks/useThreadListNew.ts +1 -1
- package/src/react/primitive-hooks/useVoice.ts +5 -5
- package/src/react/primitives/chainOfThought/ChainOfThoughtParts.tsx +1 -1
- package/src/react/primitives/composer/ComposerAttachments.tsx +1 -1
- package/src/react/primitives/composer/ComposerQueue.tsx +1 -3
- package/src/react/primitives/message/MessageAttachments.tsx +1 -3
- package/src/react/primitives/message/MessageParts.tsx +9 -9
- package/src/react/primitives/thread/ThreadMessages.tsx +1 -1
- package/src/react/primitives/thread/ThreadSuggestions.tsx +1 -1
- package/src/react/primitives/threadList/ThreadListItems.tsx +1 -1
- package/src/react/providers/AttachmentByIndexProvider.tsx +2 -2
- package/src/react/providers/ChainOfThoughtByIndicesProvider.tsx +1 -1
- package/src/react/providers/ChainOfThoughtPartByIndexProvider.tsx +2 -19
- package/src/react/providers/MessageByIdProvider.tsx +2 -2
- package/src/react/providers/MessageByIndexProvider.tsx +2 -2
- package/src/react/providers/PartByIndexProvider.tsx +2 -16
- package/src/react/providers/QueueItemByIndexProvider.tsx +1 -1
- package/src/react/providers/ReadonlyThreadProvider.tsx +1 -1
- package/src/react/providers/SuggestionByIndexProvider.tsx +1 -1
- package/src/react/providers/ThreadListItemByIndexProvider.tsx +1 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +3 -3
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +20 -6
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +34 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +32 -7
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +47 -16
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +5 -1
- package/src/react/runtimes/cloud/auiV0.ts +14 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +90 -88
- package/src/react/runtimes/createRuntimeExtras.test.ts +1 -1
- package/src/react/runtimes/createRuntimeExtras.ts +1 -1
- package/src/react/runtimes/external-message-converter.test.ts +346 -0
- package/src/react/runtimes/external-message-converter.ts +1 -1
- package/src/react/runtimes/useLocalRuntime.test.tsx +43 -0
- package/src/react/types/scopes/tools.ts +0 -6
- package/src/react/utils/groupParts.ts +1 -7
- package/src/runtime/api/assistant-runtime.ts +4 -1
- package/src/runtime/api/attachment-runtime.ts +8 -2
- package/src/runtime/api/composer-runtime.ts +9 -5
- package/src/runtime/api/message-part-runtime.ts +10 -3
- package/src/runtime/api/message-runtime.ts +7 -2
- package/src/runtime/api/thread-list-item-runtime.ts +7 -2
- package/src/runtime/api/thread-list-runtime.ts +10 -2
- package/src/runtime/base/base-thread-runtime-core.ts +5 -1
- package/src/runtime/base/default-edit-composer-runtime-core.ts +14 -2
- package/src/runtime/base/default-thread-composer-runtime-core.ts +11 -1
- package/src/runtime/utils/message-repository.ts +19 -13
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +4 -1
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +15 -0
- package/src/runtimes/internal.ts +3 -0
- package/src/runtimes/local/local-thread-runtime-core.test.ts +596 -0
- package/src/runtimes/local/local-thread-runtime-core.ts +85 -21
- package/src/runtimes/local/should-continue.test.ts +122 -0
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +9 -10
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +38 -32
- package/src/store/clients/model-context-client.test.ts +21 -1
- package/src/store/clients/runtime-adapter.ts +3 -3
- package/src/store/runtime-clients/thread-runtime-client.ts +2 -1
- package/src/store/scopes/thread.ts +1 -0
- package/src/subscribable/subscribable.ts +16 -8
- package/src/tests/MessageRepository.test.ts +12 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-position.test.ts +121 -0
- package/src/tests/auiV0Encode.test.ts +74 -0
- package/src/tests/base-composer-runtime-core.test.ts +422 -0
- package/src/tests/external-store-thread-list-runtime-core.test.ts +6 -6
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +575 -0
- package/src/tests/external-store-thread-runtime-core.test.ts +55 -1
- package/src/tests/groupParts.test.ts +3 -48
- package/src/tests/OptimisticState-delete-crash.test.ts +0 -208
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composer-runtime.js","names":["Attachment","CreateAttachment","MessageRole","QuoteInfo","Unsubscribe","RunConfig","QueueItemState","LazyMemoizeSubject","EventSubscriptionSubject","ShallowMemoizeSubject","SKIP_UPDATE","ComposerRuntimeEventCallback","ComposerRuntimeEventType","DictationState","EditComposerRuntimeCore","SendOptions","ThreadComposerRuntimeCore","ThreadComposerRuntimeCoreBinding","EditComposerRuntimeCoreBinding","ComposerRuntimeCoreBinding","ComposerRuntimePath","AttachmentRuntime","AttachmentState","EditComposerAttachmentRuntimeImpl","ThreadComposerAttachmentRuntimeImpl","BaseComposerState","canCancel","canSend","isEditing","isEmpty","text","role","attachments","runConfig","attachmentAccept","dictation","quote","queue","ThreadComposerState","type","EditComposerState","parentId","sourceId","ComposerState","EMPTY_ARRAY","Object","freeze","EMPTY_OBJECT","getThreadComposerState","runtime","value","getEditComposerState","ComposerRuntime","path","getState","addAttachment","fileOrAttachment","File","Promise","setText","setRole","setRunConfig","reset","clearAttachments","send","options","cancel","steerQueueItem","queueItemId","removeQueueItem","subscribe","callback","getAttachmentByIndex","idx","startDictation","stopDictation","setQuote","unstable_on","event","E","ComposerRuntimeImpl","_core","constructor","__internal_bindMethods","bind","core","Error","_eventSubscriptionSubjects","Map","subject","get","binding","set","payload","ThreadComposerRuntime","Omit","composerSource","source","ThreadComposerRuntimeImpl","const","_getState","stateBinding","attachmentSource","attachmentSelector","index","ref","attachment","EditComposerRuntime","beginEdit","EditComposerRuntimeImpl","_beginEdit"],"sources":["../../../src/runtime/api/composer-runtime.ts"],"sourcesContent":["import type { Attachment, CreateAttachment } from \"../../types/attachment\";\nimport type { MessageRole } from \"../../types/message\";\nimport type { QuoteInfo } from \"../../types/quote\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport type { QueueItemState } from \"../../store/scopes/queue-item\";\nimport {\n LazyMemoizeSubject,\n EventSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n ShallowMemoizeSubject,\n SKIP_UPDATE,\n} from \"../../subscribable/subscribable\";\nimport type {\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventType,\n DictationState,\n EditComposerRuntimeCore,\n SendOptions,\n ThreadComposerRuntimeCore,\n} from \"../interfaces/composer-runtime-core\";\nimport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n} from \"./bindings\";\nimport type { ComposerRuntimePath } from \"./paths\";\n\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n EditComposerAttachmentRuntimeImpl,\n ThreadComposerAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\n\nexport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n};\n\ntype BaseComposerState = {\n readonly canCancel: boolean;\n readonly canSend: boolean;\n readonly isEditing: boolean;\n readonly isEmpty: boolean;\n\n readonly text: string;\n readonly role: MessageRole;\n readonly attachments: readonly Attachment[];\n readonly runConfig: RunConfig;\n\n readonly attachmentAccept: string;\n\n /**\n * The current state of dictation.\n * Undefined when dictation is not active.\n */\n readonly dictation: DictationState | undefined;\n\n /**\n * The currently quoted text, if any.\n * Undefined when no quote is set.\n */\n readonly quote: QuoteInfo | undefined;\n\n /** Messages waiting to be processed. Empty unless the `queue` capability is set. */\n readonly queue: readonly QueueItemState[];\n};\n\nexport type ThreadComposerState = BaseComposerState & {\n readonly type: \"thread\";\n};\n\nexport type EditComposerState = BaseComposerState & {\n readonly type: \"edit\";\n readonly parentId: string | null;\n readonly sourceId: string | null;\n};\n\nexport type ComposerState = ThreadComposerState | EditComposerState;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst EMPTY_OBJECT = Object.freeze({});\nconst getThreadComposerState = (\n runtime: ThreadComposerRuntimeCore | undefined,\n): ThreadComposerState => {\n return Object.freeze({\n type: \"thread\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n canSend: runtime?.canSend ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nconst getEditComposerState = (\n runtime: EditComposerRuntimeCore | undefined,\n): EditComposerState => {\n return Object.freeze({\n type: \"edit\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n canSend: runtime?.canSend ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n parentId: runtime?.parentId ?? null,\n sourceId: runtime?.sourceId ?? null,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nexport type ComposerRuntime = {\n readonly path: ComposerRuntimePath;\n readonly type: \"edit\" | \"thread\";\n\n /**\n * Get the current state of the composer. Includes any data that has been added to the composer.\n */\n getState(): ComposerState;\n\n /**\n * Add an attachment to the composer. Accepts either a standard File object\n * (processed through the AttachmentAdapter) or a CreateAttachment descriptor\n * for external-source attachments (URLs, API data, CMS references). External\n * descriptors bypass the adapter's `add()` step but still respect\n * `adapter.accept` when an adapter is configured; without an adapter they\n * are added as-is.\n * @param fileOrAttachment The file or attachment descriptor to add.\n */\n addAttachment(fileOrAttachment: File | CreateAttachment): Promise<void>;\n\n /**\n * Set the text of the composer.\n * @param text The text to set in the composer.\n */\n setText(text: string): void;\n\n /**\n * Set the role of the composer. For instance, if you'd like a specific message to have the 'assistant' role, you can do so here.\n * @param role The role to set in the composer.\n */\n setRole(role: MessageRole): void;\n\n /**\n * Set the run config of the composer. This is used to send custom configuration data to the model.\n * Within your backend, you can use the `runConfig` object.\n * Example:\n * ```ts\n * composerRuntime.setRunConfig({\n * custom: { customField: \"customValue\" }\n * });\n * ```\n * @param runConfig The run config to set in the composer.\n */\n setRunConfig(runConfig: RunConfig): void;\n\n /**\n * Reset the composer. This will clear the entire state of the composer, including all text and attachments.\n */\n reset(): Promise<void>;\n\n /**\n * Clear all attachments from the composer.\n */\n clearAttachments(): Promise<void>;\n\n /**\n * Send a message. This will send whatever text or attachments are in the composer.\n * @param options Optional send options. Use `{ startRun: true }` to force starting a new run.\n */\n send(options?: SendOptions): void;\n\n /**\n * Cancel the current run. In edit mode, this will exit edit mode.\n */\n cancel(): void;\n\n /** Promote a queued message so it processes next. */\n steerQueueItem(queueItemId: string): void;\n\n /** Remove a queued message. */\n removeQueueItem(queueItemId: string): void;\n\n /**\n * Listens for changes to the composer state.\n * @param callback The callback to call when the composer state changes.\n */\n subscribe(callback: () => void): Unsubscribe;\n\n /**\n * Get an attachment by index.\n * @param idx The index of the attachment to get.\n */\n getAttachmentByIndex(idx: number): AttachmentRuntime;\n\n /**\n * Start dictation to convert voice to text input.\n * Requires a DictationAdapter to be configured.\n */\n startDictation(): void;\n\n /**\n * Stop the current dictation session.\n */\n stopDictation(): void;\n\n /**\n * Set a quote for the next message. Pass undefined to clear.\n * @param quote The quote info to set, or undefined to clear.\n */\n setQuote(quote: QuoteInfo | undefined): void;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe;\n};\n\nexport abstract class ComposerRuntimeImpl implements ComposerRuntime {\n public get path() {\n return this._core.path;\n }\n\n public abstract get type(): \"edit\" | \"thread\";\n\n constructor(protected _core: ComposerRuntimeCoreBinding) {}\n\n protected __internal_bindMethods() {\n this.setText = this.setText.bind(this);\n this.setRunConfig = this.setRunConfig.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.addAttachment = this.addAttachment.bind(this);\n this.reset = this.reset.bind(this);\n this.clearAttachments = this.clearAttachments.bind(this);\n this.send = this.send.bind(this);\n this.cancel = this.cancel.bind(this);\n this.steerQueueItem = this.steerQueueItem.bind(this);\n this.removeQueueItem = this.removeQueueItem.bind(this);\n this.setRole = this.setRole.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.startDictation = this.startDictation.bind(this);\n this.stopDictation = this.stopDictation.bind(this);\n this.setQuote = this.setQuote.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n }\n\n public abstract getState(): ComposerState;\n\n public setText(text: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setText(text);\n }\n\n public setRunConfig(runConfig: RunConfig) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRunConfig(runConfig);\n }\n\n public addAttachment(fileOrAttachment: File | CreateAttachment) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.addAttachment(fileOrAttachment);\n }\n\n public reset() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.reset();\n }\n\n public clearAttachments() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.clearAttachments();\n }\n\n public send(options?: SendOptions) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.send(options);\n }\n\n public cancel() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.cancel();\n }\n\n public steerQueueItem(queueItemId: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.steerQueueItem(queueItemId);\n }\n\n public removeQueueItem(queueItemId: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.removeQueueItem(queueItemId);\n }\n\n public setRole(role: MessageRole) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRole(role);\n }\n\n public startDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.startDictation();\n }\n\n public stopDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.stopDictation();\n }\n\n public setQuote(quote: QuoteInfo | undefined) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setQuote(quote);\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ComposerRuntimeEventType>\n >();\n\n public unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject<ComposerRuntimeEventType>({\n event,\n binding: this._core,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback as (payload?: unknown) => void);\n }\n\n public abstract getAttachmentByIndex(idx: number): AttachmentRuntime;\n}\n\nexport type ThreadComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"thread\" };\n readonly type: \"thread\";\n getState(): ThreadComposerState;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"thread-composer\" };\n};\n\nexport class ThreadComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements ThreadComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & {\n composerSource: \"thread\";\n };\n }\n\n public get type() {\n return \"thread\" as const;\n }\n\n private _getState;\n\n constructor(core: ThreadComposerRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getThreadComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this.__internal_bindMethods();\n }\n\n public override getState(): ThreadComposerState {\n return this._getState();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new ThreadComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"thread-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"thread-composer\",\n } satisfies AttachmentState & { source: \"thread-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n\nexport type EditComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"edit\" };\n readonly type: \"edit\";\n\n getState(): EditComposerState;\n beginEdit(): void;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"edit-composer\" };\n};\n\nexport class EditComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements EditComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & { composerSource: \"edit\" };\n }\n\n public get type() {\n return \"edit\" as const;\n }\n\n private _getState;\n constructor(\n core: EditComposerRuntimeCoreBinding,\n private _beginEdit: () => void,\n ) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getEditComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this.__internal_bindMethods();\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.beginEdit = this.beginEdit.bind(this);\n }\n\n public override getState(): EditComposerState {\n return this._getState();\n }\n\n public beginEdit() {\n this._beginEdit();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new EditComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"edit-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"edit-composer\",\n } satisfies AttachmentState & { source: \"edit-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";;;AAmFA,MAAM4C,cAAcC,OAAOC,OAAO,CAAA,CAAE;AACpC,MAAMC,eAAeF,OAAOC,OAAO,CAAC,CAAC;AACrC,MAAME,0BACJC,YACwB;CACxB,OAAOJ,OAAOC,OAAO;EACnBP,MAAM;EAENX,WAAWqB,SAASrB,aAAa;EACjCF,WAAWuB,SAASvB,aAAa;EACjCC,SAASsB,SAAStB,WAAW;EAC7BE,SAASoB,SAASpB,WAAW;EAE7BG,aAAaiB,SAASjB,eAAeY;EACrCd,MAAMmB,SAASnB,QAAQ;EACvBC,MAAMkB,SAASlB,QAAQ;EACvBE,WAAWgB,SAAShB,aAAac;EACjCb,kBAAkBe,SAASf,oBAAoB;EAC/CC,WAAWc,SAASd;EACpBC,OAAOa,SAASb;EAChBC,OAAOY,SAASZ,SAASO;EAEzBM,OAAOD,SAASnB,QAAQ;CAC1B,CAAC;AACH;AAEA,MAAMqB,wBACJF,YACsB;CACtB,OAAOJ,OAAOC,OAAO;EACnBP,MAAM;EAENX,WAAWqB,SAASrB,aAAa;EACjCF,WAAWuB,SAASvB,aAAa;EACjCC,SAASsB,SAAStB,WAAW;EAC7BE,SAASoB,SAASpB,WAAW;EAE7BC,MAAMmB,SAASnB,QAAQ;EACvBC,MAAMkB,SAASlB,QAAQ;EACvBC,aAAaiB,SAASjB,eAAeY;EACrCX,WAAWgB,SAAShB,aAAac;EACjCb,kBAAkBe,SAASf,oBAAoB;EAC/CC,WAAWc,SAASd;EACpBC,OAAOa,SAASb;EAChBC,OAAOY,SAASZ,SAASO;EAEzB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AC;EAZOuC,KAAAA,aAAAA;EAcR,KAAKV,YAAYC,aAAa/C,SAAS8B,KAAKiB,YAAY;EAExD,KAAKlB,uBAAuB;CAC9B;CAEA,yBAAyC;EACvC,MAAMA,uBAAuB;EAC7B,KAAKyB,YAAY,KAAKA,UAAUxB,KAAK,IAAI;CAC3C;CAEA,WAA8C;EAC5C,OAAO,KAAKgB,UAAU;CACxB;CAEA,YAAmB;EACjB,KAAKU,WAAW;CAClB;CAEA,qBAA4BrC,KAAa;EACvC,OAAO,IAAIlD,kCACT,IAAId,sBAAsB;GACxB4C,MAAM;IACJ,GAAG,KAAKA;IACRiD,kBAAkB;IAClBC,oBAAoB;KAAEhE,MAAM;KAASiE,OAAO/B;IAAI;IAChDgC,KAAK,GAAG,KAAKpD,KAAKoD,IAAG,eAAgBhC,IAAG;GAC1C;GACAnB,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACtB,YACLyC;IAC/B,IAAI,CAACiC,YAAY,OAAOhG;IAExB,OAAO;KACL,GAAGgG;KACHT,QAAQ;IACV;GACF;GACA3B,YAAYC,aAAa,KAAKU,MAAMX,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKU,KACP;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"composer-runtime.js","names":["Attachment","CreateAttachment","MessageRole","QuoteInfo","Unsubscribe","RunConfig","QueueItemState","LazyMemoizeSubject","EventSubscriptionSubject","ShallowMemoizeSubject","SKIP_UPDATE","ComposerRuntimeEventCallback","ComposerRuntimeEventType","DictationState","EditComposerRuntimeCore","SendOptions","ThreadComposerRuntimeCore","ThreadComposerRuntimeCoreBinding","EditComposerRuntimeCoreBinding","ComposerRuntimeCoreBinding","ComposerRuntimePath","AttachmentRuntime","AttachmentState","EditComposerAttachmentRuntimeImpl","ThreadComposerAttachmentRuntimeImpl","BaseComposerState","canCancel","canSend","isEditing","isEmpty","text","role","attachments","runConfig","attachmentAccept","dictation","quote","queue","ThreadComposerState","type","EditComposerState","parentId","sourceId","ComposerState","EMPTY_ARRAY","Object","freeze","EMPTY_OBJECT","getThreadComposerState","runtime","value","getEditComposerState","ComposerRuntime","path","getState","addAttachment","fileOrAttachment","File","Promise","setText","setRole","setRunConfig","reset","clearAttachments","send","options","cancel","steerQueueItem","queueItemId","removeQueueItem","subscribe","callback","getAttachmentByIndex","idx","startDictation","stopDictation","setQuote","unstable_on","event","E","ComposerRuntimeImpl","_core","constructor","__internal_bindMethods","bind","core","Error","_eventSubscriptionSubjects","Map","subject","get","binding","set","payload","ThreadComposerRuntime","Omit","composerSource","source","ThreadComposerRuntimeImpl","const","_getState","stateBinding","attachmentSource","attachmentSelector","index","ref","attachment","EditComposerRuntime","beginEdit","EditComposerRuntimeImpl","_beginEdit"],"sources":["../../../src/runtime/api/composer-runtime.ts"],"sourcesContent":["import type { Attachment, CreateAttachment } from \"../../types/attachment\";\nimport type { MessageRole } from \"../../types/message\";\nimport type { QuoteInfo } from \"../../types/quote\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport type { QueueItemState } from \"../../store/scopes/queue-item\";\nimport {\n LazyMemoizeSubject,\n EventSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n ShallowMemoizeSubject,\n SKIP_UPDATE,\n} from \"../../subscribable/subscribable\";\nimport type {\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventType,\n DictationState,\n EditComposerRuntimeCore,\n SendOptions,\n ThreadComposerRuntimeCore,\n} from \"../interfaces/composer-runtime-core\";\nimport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n} from \"./bindings\";\nimport type { ComposerRuntimePath } from \"./paths\";\n\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n EditComposerAttachmentRuntimeImpl,\n ThreadComposerAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\n\nexport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n};\n\ntype BaseComposerState = {\n readonly canCancel: boolean;\n readonly canSend: boolean;\n readonly isEditing: boolean;\n readonly isEmpty: boolean;\n\n readonly text: string;\n readonly role: MessageRole;\n readonly attachments: readonly Attachment[];\n readonly runConfig: RunConfig;\n\n readonly attachmentAccept: string;\n\n /**\n * The current state of dictation.\n * Undefined when dictation is not active.\n */\n readonly dictation: DictationState | undefined;\n\n /**\n * The currently quoted text, if any.\n * Undefined when no quote is set.\n */\n readonly quote: QuoteInfo | undefined;\n\n /** Messages waiting to be processed. Empty unless the `queue` capability is set. */\n readonly queue: readonly QueueItemState[];\n};\n\nexport type ThreadComposerState = BaseComposerState & {\n readonly type: \"thread\";\n};\n\nexport type EditComposerState = BaseComposerState & {\n readonly type: \"edit\";\n readonly parentId: string | null;\n readonly sourceId: string | null;\n};\n\nexport type ComposerState = ThreadComposerState | EditComposerState;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst EMPTY_OBJECT = Object.freeze({});\nconst getThreadComposerState = (\n runtime: ThreadComposerRuntimeCore | undefined,\n): ThreadComposerState => {\n return Object.freeze({\n type: \"thread\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n canSend: runtime?.canSend ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nconst getEditComposerState = (\n runtime: EditComposerRuntimeCore | undefined,\n): EditComposerState => {\n return Object.freeze({\n type: \"edit\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n canSend: runtime?.canSend ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n parentId: runtime?.parentId ?? null,\n sourceId: runtime?.sourceId ?? null,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nexport type ComposerRuntime = {\n readonly path: ComposerRuntimePath;\n readonly type: \"edit\" | \"thread\";\n\n /**\n * Get the current state of the composer. Includes any data that has been added to the composer.\n */\n getState(): ComposerState;\n\n /**\n * Add an attachment to the composer. Accepts either a standard File object\n * (processed through the AttachmentAdapter) or a CreateAttachment descriptor\n * for external-source attachments (URLs, API data, CMS references). External\n * descriptors bypass the adapter's `add()` step but still respect\n * `adapter.accept` when an adapter is configured; without an adapter they\n * are added as-is.\n * @param fileOrAttachment The file or attachment descriptor to add.\n */\n addAttachment(fileOrAttachment: File | CreateAttachment): Promise<void>;\n\n /**\n * Set the text of the composer.\n * @param text The text to set in the composer.\n */\n setText(text: string): void;\n\n /**\n * Set the role of the composer. For instance, if you'd like a specific message to have the 'assistant' role, you can do so here.\n * @param role The role to set in the composer.\n */\n setRole(role: MessageRole): void;\n\n /**\n * Set the run config of the composer. This is used to send custom configuration data to the model.\n * Within your backend, you can use the `runConfig` object.\n * Example:\n * ```ts\n * composerRuntime.setRunConfig({\n * custom: { customField: \"customValue\" }\n * });\n * ```\n * @param runConfig The run config to set in the composer.\n */\n setRunConfig(runConfig: RunConfig): void;\n\n /**\n * Reset the composer. This will clear the entire state of the composer, including all text and attachments.\n */\n reset(): Promise<void>;\n\n /**\n * Clear all attachments from the composer.\n */\n clearAttachments(): Promise<void>;\n\n /**\n * Send a message. This will send whatever text or attachments are in the composer.\n * @param options Optional send options. Use `{ startRun: true }` to force starting a new run.\n */\n send(options?: SendOptions): void;\n\n /**\n * Cancel the current run. In edit mode, this will exit edit mode.\n */\n cancel(): void;\n\n /** Promote a queued message so it processes next. */\n steerQueueItem(queueItemId: string): void;\n\n /** Remove a queued message. */\n removeQueueItem(queueItemId: string): void;\n\n /**\n * Listens for changes to the composer state.\n * @param callback The callback to call when the composer state changes.\n */\n subscribe(callback: () => void): Unsubscribe;\n\n /**\n * Get an attachment by index.\n * @param idx The index of the attachment to get.\n */\n getAttachmentByIndex(idx: number): AttachmentRuntime;\n\n /**\n * Start dictation to convert voice to text input.\n * Requires a DictationAdapter to be configured.\n */\n startDictation(): void;\n\n /**\n * Stop the current dictation session.\n */\n stopDictation(): void;\n\n /**\n * Set a quote for the next message. Pass undefined to clear.\n * @param quote The quote info to set, or undefined to clear.\n */\n setQuote(quote: QuoteInfo | undefined): void;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe;\n};\n\nexport abstract class ComposerRuntimeImpl implements ComposerRuntime {\n public get path() {\n return this._core.path;\n }\n\n public abstract get type(): \"edit\" | \"thread\";\n\n protected _core: ComposerRuntimeCoreBinding;\n\n constructor(_core: ComposerRuntimeCoreBinding) {\n this._core = _core;\n }\n\n protected __internal_bindMethods() {\n this.setText = this.setText.bind(this);\n this.setRunConfig = this.setRunConfig.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.addAttachment = this.addAttachment.bind(this);\n this.reset = this.reset.bind(this);\n this.clearAttachments = this.clearAttachments.bind(this);\n this.send = this.send.bind(this);\n this.cancel = this.cancel.bind(this);\n this.steerQueueItem = this.steerQueueItem.bind(this);\n this.removeQueueItem = this.removeQueueItem.bind(this);\n this.setRole = this.setRole.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.startDictation = this.startDictation.bind(this);\n this.stopDictation = this.stopDictation.bind(this);\n this.setQuote = this.setQuote.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n }\n\n public abstract getState(): ComposerState;\n\n public setText(text: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setText(text);\n }\n\n public setRunConfig(runConfig: RunConfig) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRunConfig(runConfig);\n }\n\n public addAttachment(fileOrAttachment: File | CreateAttachment) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.addAttachment(fileOrAttachment);\n }\n\n public reset() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.reset();\n }\n\n public clearAttachments() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.clearAttachments();\n }\n\n public send(options?: SendOptions) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.send(options);\n }\n\n public cancel() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.cancel();\n }\n\n public steerQueueItem(queueItemId: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.steerQueueItem(queueItemId);\n }\n\n public removeQueueItem(queueItemId: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.removeQueueItem(queueItemId);\n }\n\n public setRole(role: MessageRole) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRole(role);\n }\n\n public startDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.startDictation();\n }\n\n public stopDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.stopDictation();\n }\n\n public setQuote(quote: QuoteInfo | undefined) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setQuote(quote);\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ComposerRuntimeEventType>\n >();\n\n public unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject<ComposerRuntimeEventType>({\n event,\n binding: this._core,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback as (payload?: unknown) => void);\n }\n\n public abstract getAttachmentByIndex(idx: number): AttachmentRuntime;\n}\n\nexport type ThreadComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"thread\" };\n readonly type: \"thread\";\n getState(): ThreadComposerState;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"thread-composer\" };\n};\n\nexport class ThreadComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements ThreadComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & {\n composerSource: \"thread\";\n };\n }\n\n public get type() {\n return \"thread\" as const;\n }\n\n private _getState;\n\n constructor(core: ThreadComposerRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getThreadComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this.__internal_bindMethods();\n }\n\n public override getState(): ThreadComposerState {\n return this._getState();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new ThreadComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"thread-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"thread-composer\",\n } satisfies AttachmentState & { source: \"thread-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n\nexport type EditComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"edit\" };\n readonly type: \"edit\";\n\n getState(): EditComposerState;\n beginEdit(): void;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"edit-composer\" };\n};\n\nexport class EditComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements EditComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & { composerSource: \"edit\" };\n }\n\n public get type() {\n return \"edit\" as const;\n }\n\n private _getState;\n private _beginEdit: () => void;\n\n constructor(core: EditComposerRuntimeCoreBinding, _beginEdit: () => void) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getEditComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n this._beginEdit = _beginEdit;\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this.__internal_bindMethods();\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.beginEdit = this.beginEdit.bind(this);\n }\n\n public override getState(): EditComposerState {\n return this._getState();\n }\n\n public beginEdit() {\n this._beginEdit();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new EditComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"edit-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"edit-composer\",\n } satisfies AttachmentState & { source: \"edit-composer\" };\n },\n subscribe: (callback) => this._core.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AAU;CACxB;CAEA,YAAmB;EACjB,KAAKU,WAAW;CAClB;CAEA,qBAA4BrC,KAAa;EACvC,OAAO,IAAIlD,kCACT,IAAId,sBAAsB;GACxB4C,MAAM;IACJ,GAAG,KAAKA;IACRiD,kBAAkB;IAClBC,oBAAoB;KAAEhE,MAAM;KAASiE,OAAO/B;IAAI;IAChDgC,KAAK,GAAG,KAAKpD,KAAKoD,IAAG,eAAgBhC,IAAG;GAC1C;GACAnB,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACtB,YACLyC;IAC/B,IAAI,CAACiC,YAAY,OAAOhG;IAExB,OAAO;KACL,GAAGgG;KACHT,QAAQ;IACV;GACF;GACA3B,YAAYC,aAAa,KAAKU,MAAMX,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKU,KACP;CACF;AACF"}
|
|
@@ -19,11 +19,11 @@ type MessagePartRuntime = {
|
|
|
19
19
|
subscribe(callback: () => void): Unsubscribe;
|
|
20
20
|
};
|
|
21
21
|
declare class MessagePartRuntimeImpl implements MessagePartRuntime {
|
|
22
|
-
private contentBinding;
|
|
23
|
-
private messageApi?;
|
|
24
|
-
private threadApi?;
|
|
25
22
|
get path(): MessagePartRuntimePath;
|
|
26
|
-
|
|
23
|
+
private contentBinding;
|
|
24
|
+
private messageApi;
|
|
25
|
+
private threadApi;
|
|
26
|
+
constructor(contentBinding: MessagePartSnapshotBinding, messageApi?: MessageStateBinding, threadApi?: ThreadRuntimeCoreBinding);
|
|
27
27
|
protected __internal_bindMethods(): void;
|
|
28
28
|
getState(): MessagePartState;
|
|
29
29
|
addToolResult(result: any | ToolResponse<any>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-part-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"mappings":";;;;;;;;KAeY,oBACR,wBACA;WAEO,QAAQ,oBAAoB;;KAGlC,6BAA6B,sBAChC,kBACA;KAGU;EACV,cAAc,cAAc;EAC5B,eAAe;EACf,sBAAsB,UAAU;WAEvB,MAAM;EACf,YAAY;EACZ,UAAU,uBAAuB;;cAGtB,kCAAkC;
|
|
1
|
+
{"version":3,"file":"message-part-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"mappings":";;;;;;;;KAeY,oBACR,wBACA;WAEO,QAAQ,oBAAoB;;KAGlC,6BAA6B,sBAChC,kBACA;KAGU;EACV,cAAc,cAAc;EAC5B,eAAe;EACf,sBAAsB,UAAU;WAEvB,MAAM;EACf,YAAY;EACZ,UAAU,uBAAuB;;cAGtB,kCAAkC;MAClC,QAAI;UAIP;UACA;UACA;EAGN,YAAA,gBAAgB,4BAChB,aAAa,qBACb,YAAY;YAQJ;EAQH,YAAQ;EAIR,cAAc,cAAc;EA8B5B,eAAe;EAgBf,sBAAsB,UAAU;EAyBhC,UAAU,uBAAoB"}
|
|
@@ -2,12 +2,12 @@ import { resolveToolApprovalResponse } from "../utils/resolveToolApprovalRespons
|
|
|
2
2
|
import { ToolResponse } from "assistant-stream";
|
|
3
3
|
//#region src/runtime/api/message-part-runtime.ts
|
|
4
4
|
var MessagePartRuntimeImpl = class {
|
|
5
|
-
contentBinding;
|
|
6
|
-
messageApi;
|
|
7
|
-
threadApi;
|
|
8
5
|
get path() {
|
|
9
6
|
return this.contentBinding.path;
|
|
10
7
|
}
|
|
8
|
+
contentBinding;
|
|
9
|
+
messageApi;
|
|
10
|
+
threadApi;
|
|
11
11
|
constructor(contentBinding, messageApi, threadApi) {
|
|
12
12
|
this.contentBinding = contentBinding;
|
|
13
13
|
this.messageApi = messageApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-part-runtime.js","names":["ThreadAssistantMessagePart","ThreadUserMessagePart","ToolApprovalResponse","ToolCallMessagePartStatus","resolveToolApprovalResponse","Unsubscribe","MessagePartStatus","SubscribableWithState","ThreadRuntimeCoreBinding","MessageStateBinding","MessagePartRuntimePath","ToolResponse","MessagePartState","status","MessagePartSnapshotBinding","MessagePartRuntime","addToolResult","result","resumeToolCall","payload","respondToToolApproval","response","path","getState","subscribe","callback","MessagePartRuntimeImpl","contentBinding","
|
|
1
|
+
{"version":3,"file":"message-part-runtime.js","names":["ThreadAssistantMessagePart","ThreadUserMessagePart","ToolApprovalResponse","ToolCallMessagePartStatus","resolveToolApprovalResponse","Unsubscribe","MessagePartStatus","SubscribableWithState","ThreadRuntimeCoreBinding","MessageStateBinding","MessagePartRuntimePath","ToolResponse","MessagePartState","status","MessagePartSnapshotBinding","MessagePartRuntime","addToolResult","result","resumeToolCall","payload","respondToToolApproval","response","path","getState","subscribe","callback","MessagePartRuntimeImpl","contentBinding","messageApi","threadApi","constructor","__internal_bindMethods","bind","state","Error","type","message","toolName","toolCallId","toResponse","messageId","id","artifact","isError","approval","approved","undefined","resolution"],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"sourcesContent":["import type {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ToolApprovalResponse,\n ToolCallMessagePartStatus,\n} from \"../../types/message\";\nimport { resolveToolApprovalResponse } from \"../utils/resolveToolApprovalResponse\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus } from \"../../types/message\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\nimport type { MessagePartRuntimePath } from \"./paths\";\nimport { ToolResponse } from \"assistant-stream\";\n\nexport type MessagePartState = (\n | ThreadUserMessagePart\n | ThreadAssistantMessagePart\n) & {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\ntype MessagePartSnapshotBinding = SubscribableWithState<\n MessagePartState,\n MessagePartRuntimePath\n>;\n\nexport type MessagePartRuntime = {\n addToolResult(result: any | ToolResponse<any>): void;\n resumeToolCall(payload: unknown): void;\n respondToToolApproval(response: ToolApprovalResponse): void;\n\n readonly path: MessagePartRuntimePath;\n getState(): MessagePartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class MessagePartRuntimeImpl implements MessagePartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n private contentBinding: MessagePartSnapshotBinding;\n private messageApi: MessageStateBinding | undefined;\n private threadApi: ThreadRuntimeCoreBinding | undefined;\n\n constructor(\n contentBinding: MessagePartSnapshotBinding,\n messageApi?: MessageStateBinding,\n threadApi?: ThreadRuntimeCoreBinding,\n ) {\n this.contentBinding = contentBinding;\n this.messageApi = messageApi;\n this.threadApi = threadApi;\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.addToolResult = this.addToolResult.bind(this);\n this.resumeToolCall = this.resumeToolCall.bind(this);\n this.respondToToolApproval = this.respondToToolApproval.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n }\n\n public getState() {\n return this.contentBinding.getState();\n }\n\n public addToolResult(result: any | ToolResponse<any>) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool message part\");\n\n if (!this.messageApi)\n throw new Error(\n \"Message API is not available. This is likely a bug in assistant-ui.\",\n );\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const message = this.messageApi.getState();\n if (!message) throw new Error(\"Message is not available\");\n\n const toolName = state.toolName;\n const toolCallId = state.toolCallId;\n\n const response = ToolResponse.toResponse(result);\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result: response.result,\n artifact: response.artifact,\n isError: response.isError,\n });\n }\n\n public resumeToolCall(payload: unknown) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to resume tool call on non-tool message part\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const toolCallId = state.toolCallId;\n this.threadApi.getState().resumeToolCall({\n toolCallId,\n payload,\n });\n }\n\n public respondToToolApproval(response: ToolApprovalResponse) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\n \"Tried to respond to tool approval on non-tool message part\",\n );\n\n if (\n !state.approval ||\n state.approval.approved !== undefined ||\n state.approval.resolution !== undefined\n )\n throw new Error(\"Tool call has no pending approval\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n this.threadApi\n .getState()\n .respondToToolApproval(\n resolveToolApprovalResponse(state.approval, response),\n );\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";;;AAqCA,IAAa0B,yBAAb,MAAkE;CAChE,IAAWJ,OAAO;EAChB,OAAO,KAAKK,eAAeL;CAC7B;CAEA;CACA;CACA;CAEAQ,YACEH,gBACAC,YACAC,WACA;EACA,KAAKF,iBAAiBA;EACtB,KAAKC,aAAaA;EAClB,KAAKC,YAAYA;EACjB,KAAKE,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKf,gBAAgB,KAAKA,cAAcgB,KAAK,IAAI;EACjD,KAAKd,iBAAiB,KAAKA,eAAec,KAAK,IAAI;EACnD,KAAKZ,wBAAwB,KAAKA,sBAAsBY,KAAK,IAAI;EACjE,KAAKT,WAAW,KAAKA,SAASS,KAAK,IAAI;EACvC,KAAKR,YAAY,KAAKA,UAAUQ,KAAK,IAAI;CAC3C;CAEA,WAAkB;EAChB,OAAO,KAAKL,eAAeJ,SAAS;CACtC;CAEA,cAAqBN,QAAiC;EACpD,MAAMgB,QAAQ,KAAKN,eAAeJ,SAAS;EAC3C,IAAI,CAACU,OAAO,MAAM,IAAIC,MAAM,+BAA+B;EAE3D,IAAID,MAAME,SAAS,aACjB,MAAM,IAAID,MAAM,mDAAmD;EAErE,IAAI,CAAC,KAAKN,YACR,MAAM,IAAIM,MACR,qEACF;EACF,IAAI,CAAC,KAAKL,WAAW,MAAM,IAAIK,MAAM,6BAA6B;EAElE,MAAME,UA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9 @@ type MessageRuntime = {
|
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
56
|
declare class MessageRuntimeImpl implements MessageRuntime {
|
|
57
|
+
get path(): MessageRuntimePath;
|
|
57
58
|
private _core;
|
|
58
59
|
private _threadBinding;
|
|
59
|
-
get path(): MessageRuntimePath;
|
|
60
60
|
constructor(_core: MessageStateBinding, _threadBinding: ThreadRuntimeCoreBinding);
|
|
61
61
|
protected __internal_bindMethods(): void;
|
|
62
62
|
readonly composer: EditComposerRuntimeImpl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-runtime.ts"],"mappings":";;;;;;;;;;cAsCa,sBACX,SAAS,eACT,mBACA,MAAM,wBAAwB,+BAC7B;KAkCS,eAAe;WAChB;;WAEA;WACA;WAEA;WACA;;;;WAKA,QAAQ;;KAKd;EACH,YAAY;;KAGF;WACD,MAAM;WAEN,UAAU;EAEnB,YAAY;EACZ,iBAAiB;EACjB,OAAO,SAAS;;;;EAIhB;;;;EAIA;EACA,iBAAiB;IAAU;;EAC3B,iBACE,UACA;IAEA;IACA;;EAEF;EAEA,UAAU,uBAAuB;EAEjC,sBAAsB,cAAc;EACpC,2BAA2B,qBAAqB;EAEhD,qBAAqB,cAAc;IAAsB;;;cAG9C,8BAA8B;
|
|
1
|
+
{"version":3,"file":"message-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-runtime.ts"],"mappings":";;;;;;;;;;cAsCa,sBACX,SAAS,eACT,mBACA,MAAM,wBAAwB,+BAC7B;KAkCS,eAAe;WAChB;;WAEA;WACA;WAEA;WACA;;;;WAKA,QAAQ;;KAKd;EACH,YAAY;;KAGF;WACD,MAAM;WAEN,UAAU;EAEnB,YAAY;EACZ,iBAAiB;EACjB,OAAO,SAAS;;;;EAIhB;;;;EAIA;EACA,iBAAiB;IAAU;;EAC3B,iBACE,UACA;IAEA;IACA;;EAEF;EAEA,UAAU,uBAAuB;EAEjC,sBAAsB,cAAc;EACpC,2BAA2B,qBAAqB;EAEhD,qBAAqB,cAAc;IAAsB;;;cAG9C,8BAA8B;MAC9B,QAAI;UAIP;UACA;EAGN,YAAA,OAAO,qBACP,gBAAgB;YAoBR;WAgBM,UAAQ;UAEhB;EAMD,YAAQ;;;;;;;;EAIR,iBAAM;EAKN,OAAO,eAAc;EAkBrB;EAKA;EAUA,iBAAiB;IAAU;;EAQ3B,iBACL,UACA;IAEA;IACA;;EAsBK;EAIA,UAAU,uBAAoB;EAI9B,sBAAsB,cAAW;EAmBjC,2BAA2B,qBAAkB;EAwB7C,qBAAqB,cAAW"}
|
|
@@ -25,11 +25,11 @@ const getMessagePartState = (message, partIndex) => {
|
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
27
|
var MessageRuntimeImpl = class {
|
|
28
|
-
_core;
|
|
29
|
-
_threadBinding;
|
|
30
28
|
get path() {
|
|
31
29
|
return this._core.path;
|
|
32
30
|
}
|
|
31
|
+
_core;
|
|
32
|
+
_threadBinding;
|
|
33
33
|
constructor(_core, _threadBinding) {
|
|
34
34
|
this._core = _core;
|
|
35
35
|
this._threadBinding = _threadBinding;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-runtime.js","names":["SpeechState","symbolInnerMessage","ToolCallMessagePartStatus","ThreadMessage","ThreadAssistantMessagePart","ThreadUserMessagePart","Unsubscribe","MessagePartStatus","RunConfig","getThreadMessageText","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","AttachmentRuntime","AttachmentState","MessageAttachmentRuntimeImpl","EditComposerRuntime","EditComposerRuntimeImpl","MessagePartRuntime","MessagePartRuntimeImpl","MessagePartState","MessageRuntimePath","ThreadRuntimeCoreBinding","MessageStateBinding","COMPLETE_STATUS","Object","freeze","type","toMessagePartStatus","message","partIndex","part","role","result","status","isLastPart","Math","max","content","length","getMessagePartState","MessageState","parentId","index","isLast","branchNumber","branchCount","speech","ReloadConfig","runConfig","MessageRuntime","path","composer","getState","delete","Promise","reload","config","speak","stopSpeaking","submitFeedback","switchToBranch","position","branchId","unstable_getCopyText","subscribe","callback","getMessagePartByIndex","idx","getMessagePartByToolCallId","toolCallId","getAttachmentByIndex","source","MessageRuntimeImpl","_core","constructor","_threadBinding","ref","composerSource","_getEditComposerRuntimeCore","beginEdit","id","__internal_bindMethods","bind","getEditComposer","state","deleteMessage","reloadConfig","editComposerRuntimeCore","composerRuntimeCore","Error","startRun","sourceId","thread","messageId","branches","getBranches","targetBranch","messagePartSelector","JSON","stringify","findIndex","attachmentSource","attachmentSelector","attachments","attachment"],"sources":["../../../src/runtime/api/message-runtime.ts"],"sourcesContent":["import type { SpeechState } from \"../interfaces/thread-runtime-core\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type {\n ToolCallMessagePartStatus,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus, RunConfig } from \"../../types/message\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\nimport {\n type EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport {\n type MessagePartRuntime,\n MessagePartRuntimeImpl,\n type MessagePartState,\n} from \"./message-part-runtime\";\nimport type { MessageRuntimePath } from \"./paths\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const toMessagePartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserMessagePart | ThreadAssistantMessagePart,\n): ToolCallMessagePartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallMessagePartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as MessagePartStatus) : COMPLETE_STATUS;\n};\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n /** The position of this message in the thread (0 for first message) */\n readonly index: number;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport type { MessageStateBinding } from \"./bindings\";\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n delete(): void | Promise<void>;\n reload(config?: ReloadConfig): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: MessageStateBinding,\n private _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.delete = this.delete.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public delete() {\n const state = this._core.getState();\n return this._threadBinding.getState().deleteMessage(state.id);\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getMessagePartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";;;;;;;AAkCA,MAAMwB,kBAAqCC,OAAOC,OAAO,EACvDC,MAAM,WACR,CAAC;AAED,MAAaC,uBACXC,SACAC,WACAC,SAC8B;CAC9B,IAAIF,QAAQG,SAAS,aAAa,OAAOR;CAEzC,IAAIO,KAAKJ,SAAS,aAChB,IAAI,CAACI,KAAKE,QACR,OAAOJ,QAAQK;MAEf,OAAOV;CAIX,MAAMW,aAAaL,cAAcM,KAAKC,IAAI,GAAGR,QAAQS,QAAQC,SAAS,CAAC;CACvE,IAAIV,QAAQK,OAAOP,SAAS,mBAAmB,OAAOH;CACtD,OAAOW,aAAcN,QAAQK,SAA+BV;AAC9D;AAEA,MAAMgB,uBACJX,SACAC,cACmC;CACnC,MAAMC,OAAOF,QAAQS,QAAQR;CAC7B,IAAI,CAACC,MACH,OAAOpB;CAIT,MAAMuB,SAASN,oBAAoBC,SAASC,WAAWC,IAAI;CAC3D,OAAON,OAAOC,OAAO;EACnB,GAAGK;GACG9B,qBAAsB8B,KAAa9B;EACzCiC;CACF,CAAC;AACH;AAyDA,IAAau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xD;GACAjB,gBAAgB;IACd,MAAMgC,QAAQ,KAAKX,MAAMrB,SAAS;IAClC,MAAMe,MAAMiB,MAAM/C,QAAQ+D,WACvBtE,SACCA,KAAKJ,SAAS,eAAeI,KAAKuC,eAAeA,UACrD;IACA,IAAIF,QAAQ,IAAI,OAAOzD;IACvB,OAAO6B,oBAAoB6C,OAAOjB,GAAG;GACvC;GACAH,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKQ,OACL,KAAKE,cACP;CACF;CAEA,qBAA4BR,KAAa;EACvC,OAAO,IAAIrD,6BACT,IAAIH,sBAAsB;GACxBuC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG,eAAgBT,IAAG;IACxCkC,kBAAkB;IAClBC,oBAAoB;KAAE5E,MAAM;KAASgB,OAAOyB;IAAI;GAClD;GACAf,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACmD,cACHpC;IACjC,IAAI,CAACqC,YAAY,OAAO9F;IAExB,OAAO;KACL,GAAG8F;KACHjC,QAAQ;IACV;GACF;GACAP,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,CACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"message-runtime.js","names":["SpeechState","symbolInnerMessage","ToolCallMessagePartStatus","ThreadMessage","ThreadAssistantMessagePart","ThreadUserMessagePart","Unsubscribe","MessagePartStatus","RunConfig","getThreadMessageText","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","AttachmentRuntime","AttachmentState","MessageAttachmentRuntimeImpl","EditComposerRuntime","EditComposerRuntimeImpl","MessagePartRuntime","MessagePartRuntimeImpl","MessagePartState","MessageRuntimePath","ThreadRuntimeCoreBinding","MessageStateBinding","COMPLETE_STATUS","Object","freeze","type","toMessagePartStatus","message","partIndex","part","role","result","status","isLastPart","Math","max","content","length","getMessagePartState","MessageState","parentId","index","isLast","branchNumber","branchCount","speech","ReloadConfig","runConfig","MessageRuntime","path","composer","getState","delete","Promise","reload","config","speak","stopSpeaking","submitFeedback","switchToBranch","position","branchId","unstable_getCopyText","subscribe","callback","getMessagePartByIndex","idx","getMessagePartByToolCallId","toolCallId","getAttachmentByIndex","source","MessageRuntimeImpl","_core","_threadBinding","constructor","ref","composerSource","_getEditComposerRuntimeCore","beginEdit","id","__internal_bindMethods","bind","getEditComposer","state","deleteMessage","reloadConfig","editComposerRuntimeCore","composerRuntimeCore","Error","startRun","sourceId","thread","messageId","branches","getBranches","targetBranch","messagePartSelector","JSON","stringify","findIndex","attachmentSource","attachmentSelector","attachments","attachment"],"sources":["../../../src/runtime/api/message-runtime.ts"],"sourcesContent":["import type { SpeechState } from \"../interfaces/thread-runtime-core\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type {\n ToolCallMessagePartStatus,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus, RunConfig } from \"../../types/message\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\nimport {\n type EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport {\n type MessagePartRuntime,\n MessagePartRuntimeImpl,\n type MessagePartState,\n} from \"./message-part-runtime\";\nimport type { MessageRuntimePath } from \"./paths\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const toMessagePartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserMessagePart | ThreadAssistantMessagePart,\n): ToolCallMessagePartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallMessagePartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as MessagePartStatus) : COMPLETE_STATUS;\n};\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n /** The position of this message in the thread (0 for first message) */\n readonly index: number;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport type { MessageStateBinding } from \"./bindings\";\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n delete(): void | Promise<void>;\n reload(config?: ReloadConfig): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n private _core: MessageStateBinding;\n private _threadBinding: ThreadRuntimeCoreBinding;\n\n constructor(\n _core: MessageStateBinding,\n _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this._core = _core;\n this._threadBinding = _threadBinding;\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.delete = this.delete.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public delete() {\n const state = this._core.getState();\n return this._threadBinding.getState().deleteMessage(state.id);\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getMessagePartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";;;;;;;AAkCA,MAAMwB,kBAAqCC,OAAOC,OAAO,EACvDC,MAAM,WACR,CAAC;AAED,MAAaC,uBACXC,SACAC,WACAC,SAC8B;CAC9B,IAAIF,QAAQG,SAAS,aAAa,OAAOR;CAEzC,IAAIO,KAAKJ,SAAS,aAChB,IAAI,CAACI,KAAKE,QACR,OAAOJ,QAAQK;MAEf,OAAOV;CAIX,MAAMW,aAAaL,cAAcM,KAAKC,IAAI,GAAGR,QAAQS,QAAQC,SAAS,CAAC;CACvE,IAAIV,QAAQK,OAAOP,SAAS,mBAAmB,OAAOH;CACtD,OAAOW,aAAcN,QAAQK,SAA+BV;AAC9D;AAEA,MAAMgB,uBACJX,SACAC,cACmC;CACnC,MAAMC,OAAOF,QAAQS,QAAQR;CAC7B,IAAI,CAACC,MACH,OAAOpB;CAIT,MAAMuB,SA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KA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG,sBAAuBsB,KAAKC,UAAU9B,UAAU,EAAC;IACtE4B,qBAAqB;KAAEvE,MAAM;KAAc2C;IAAW;GACxD;GACAjB,gBAAgB;IACd,MAAMgC,QAAQ,KAAKX,MAAMrB,SAAS;IAClC,MAAMe,MAAMiB,MAAM/C,QAAQ+D,WACvBtE,SACCA,KAAKJ,SAAS,eAAeI,KAAKuC,eAAeA,UACrD;IACA,IAAIF,QAAQ,IAAI,OAAOzD;IACvB,OAAO6B,oBAAoB6C,OAAOjB,GAAG;GACvC;GACAH,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKQ,OACL,KAAKC,cACP;CACF;CAEA,qBAA4BP,KAAa;EACvC,OAAO,IAAIrD,6BACT,IAAIH,sBAAsB;GACxBuC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG,eAAgBT,IAAG;IACxCkC,kBAAkB;IAClBC,oBAAoB;KAAE5E,MAAM;KAASgB,OAAOyB;IAAI;GAClD;GACAf,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACmD,cACHpC;IACjC,IAAI,CAACqC,YAAY,OAAO9F;IAExB,OAAO;KACL,GAAG8F;KACHjC,QAAQ;IACV;GACF;GACAP,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,CACH;CACF;AACF"}
|
|
@@ -44,9 +44,9 @@ type ThreadListItemRuntime = {
|
|
|
44
44
|
};
|
|
45
45
|
type ThreadListItemStateBinding = SubscribableWithState<ThreadListItemState, ThreadListItemRuntimePath>;
|
|
46
46
|
declare class ThreadListItemRuntimeImpl implements ThreadListItemRuntime {
|
|
47
|
+
get path(): ThreadListItemRuntimePath;
|
|
47
48
|
private _core;
|
|
48
49
|
private _threadListBinding;
|
|
49
|
-
get path(): ThreadListItemRuntimePath;
|
|
50
50
|
constructor(_core: ThreadListItemStateBinding, _threadListBinding: ThreadListRuntimeCoreBinding);
|
|
51
51
|
protected __internal_bindMethods(): void;
|
|
52
52
|
getState(): ThreadListItemState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-item-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-item-runtime.ts"],"mappings":";;;;;;;KAMY;;;;;;EAMV,YAAY;;;;;;EAMZ,cAAc;;KAGJ,gCAAgC;KAEhC,4BAA4B,UAAU,4BAChD,SAAS,2BAA2B;KAQ1B;WACD,MAAM;EACf,YAAY;EAEZ,cAAc;IAAU;IAAkB;;EAC1C,iBAAiB;EAEjB,SAAS;IAAY;MAAwB;EAC7C,OAAO,mBAAmB;EAC1B,aAAa,QAAQ,sCAAsC;EAC3D,WAAW;EACX,aAAa;EACb,UAAU;EAEV;EAEA,UAAU,uBAAuB;EAEjC,YAAY,UAAU,yBACpB,OAAO,GACP,UAAU,4BAA4B,KACrC;EAEH,yBAAyB;;KAGf,6BAA6B,sBACvC,qBACA;cAGW,qCAAqC;
|
|
1
|
+
{"version":3,"file":"thread-list-item-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-item-runtime.ts"],"mappings":";;;;;;;KAMY;;;;;;EAMV,YAAY;;;;;;EAMZ,cAAc;;KAGJ,gCAAgC;KAEhC,4BAA4B,UAAU,4BAChD,SAAS,2BAA2B;KAQ1B;WACD,MAAM;EACf,YAAY;EAEZ,cAAc;IAAU;IAAkB;;EAC1C,iBAAiB;EAEjB,SAAS;IAAY;MAAwB;EAC7C,OAAO,mBAAmB;EAC1B,aAAa,QAAQ,sCAAsC;EAC3D,WAAW;EACX,aAAa;EACb,UAAU;EAEV;EAEA,UAAU,uBAAuB;EAEjC,YAAY,UAAU,yBACpB,OAAO,GACP,UAAU,4BAA4B,KACrC;EAEH,yBAAyB;;KAGf,6BAA6B,sBACvC,qBACA;cAGW,qCAAqC;MACrC,QAAI;UAIP;UACA;EAGN,YAAA,OAAO,4BACP,oBAAoB;YAOZ;EAeH,YAAY;EAIZ,SAAS;IAAY;MAAwB;EAK7C,OAAO,mBAAmB;EAM1B,aACL,QAAQ,sCACP;EAWI,WAAW;EAMX,aAAa;EAMb,UAAU;EAMV,cAAc;IACnB;IACA;;EAMK,iBAAiB;EAKjB,YAAY,UAAU,yBAC3B,OAAO,GACP,UAAU,4BAA4B,KAAE;EAsBnC,UAAU,uBAAuB;EAIjC;EAMA,yBAAyB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { notifyEventListeners } from "../../utils/notify-event-listeners.js";
|
|
2
2
|
//#region src/runtime/api/thread-list-item-runtime.ts
|
|
3
3
|
var ThreadListItemRuntimeImpl = class {
|
|
4
|
-
_core;
|
|
5
|
-
_threadListBinding;
|
|
6
4
|
get path() {
|
|
7
5
|
return this._core.path;
|
|
8
6
|
}
|
|
7
|
+
_core;
|
|
8
|
+
_threadListBinding;
|
|
9
9
|
constructor(_core, _threadListBinding) {
|
|
10
10
|
this._core = _core;
|
|
11
11
|
this._threadListBinding = _threadListBinding;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-item-runtime.js","names":["Unsubscribe","SubscribableWithState","ThreadListItemRuntimePath","ThreadListRuntimeCoreBinding","notifyEventListeners","ThreadListItemEventPayload","switchedTo","Record","switchedAway","ThreadListItemEventType","ThreadListItemEventCallback","payload","E","ThreadListItemState","ThreadListItemStatus","ThreadListItemRuntime","path","getState","initialize","Promise","remoteId","externalId","generateTitle","switchTo","options","unarchive","rename","newTitle","updateCustom","custom","archive","delete","detach","subscribe","callback","unstable_on","event","__internal_getRuntime","ThreadListItemStateBinding","ThreadListItemRuntimeImpl","_core","
|
|
1
|
+
{"version":3,"file":"thread-list-item-runtime.js","names":["Unsubscribe","SubscribableWithState","ThreadListItemRuntimePath","ThreadListRuntimeCoreBinding","notifyEventListeners","ThreadListItemEventPayload","switchedTo","Record","switchedAway","ThreadListItemEventType","ThreadListItemEventCallback","payload","E","ThreadListItemState","ThreadListItemStatus","ThreadListItemRuntime","path","getState","initialize","Promise","remoteId","externalId","generateTitle","switchTo","options","unarchive","rename","newTitle","updateCustom","custom","archive","delete","detach","subscribe","callback","unstable_on","event","__internal_getRuntime","ThreadListItemStateBinding","ThreadListItemRuntimeImpl","_core","_threadListBinding","constructor","__internal_bindMethods","bind","state","switchToThread","id","Error","prevIsMain","isMain","prevThreadId","currentState","newIsMain","newThreadId"],"sources":["../../../src/runtime/api/thread-list-item-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport type { ThreadListItemRuntimePath } from \"./paths\";\nimport type { ThreadListRuntimeCoreBinding } from \"./thread-list-runtime\";\nimport { notifyEventListeners } from \"../../utils/notify-event-listeners\";\n\nexport type ThreadListItemEventPayload = {\n /**\n * @deprecated State-derivable. Compare `s.threads.mainThreadId` against the\n * item's `s.threadListItem.id` via `useAuiState` instead. Kept for backward\n * compatibility.\n */\n switchedTo: Record<string, never>;\n /**\n * @deprecated State-derivable. Compare `s.threads.mainThreadId` against the\n * item's `s.threadListItem.id` via `useAuiState` instead. Kept for backward\n * compatibility.\n */\n switchedAway: Record<string, never>;\n};\n\nexport type ThreadListItemEventType = keyof ThreadListItemEventPayload;\n\nexport type ThreadListItemEventCallback<E extends ThreadListItemEventType> = (\n payload: ThreadListItemEventPayload[E],\n) => void;\n\nimport type { ThreadListItemState } from \"./bindings\";\nimport type { ThreadListItemStatus } from \"../interfaces/thread-list-runtime-core\";\n\nexport type { ThreadListItemState, ThreadListItemStatus };\n\nexport type ThreadListItemRuntime = {\n readonly path: ThreadListItemRuntimePath;\n getState(): ThreadListItemState;\n\n initialize(): Promise<{ remoteId: string; externalId: string | undefined }>;\n generateTitle(): Promise<void>;\n\n switchTo(options?: { unarchive?: boolean }): Promise<void>;\n rename(newTitle: string): Promise<void>;\n updateCustom(custom: Record<string, unknown> | undefined): Promise<void>;\n archive(): Promise<void>;\n unarchive(): Promise<void>;\n delete(): Promise<void>;\n\n detach(): void;\n\n subscribe(callback: () => void): Unsubscribe;\n\n unstable_on<E extends ThreadListItemEventType>(\n event: E,\n callback: ThreadListItemEventCallback<E>,\n ): Unsubscribe;\n\n __internal_getRuntime(): ThreadListItemRuntime;\n};\n\nexport type ThreadListItemStateBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport class ThreadListItemRuntimeImpl implements ThreadListItemRuntime {\n public get path() {\n return this._core.path;\n }\n\n private _core: ThreadListItemStateBinding;\n private _threadListBinding: ThreadListRuntimeCoreBinding;\n\n constructor(\n _core: ThreadListItemStateBinding,\n _threadListBinding: ThreadListRuntimeCoreBinding,\n ) {\n this._core = _core;\n this._threadListBinding = _threadListBinding;\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.switchTo = this.switchTo.bind(this);\n this.rename = this.rename.bind(this);\n this.updateCustom = this.updateCustom.bind(this);\n this.archive = this.archive.bind(this);\n this.unarchive = this.unarchive.bind(this);\n this.delete = this.delete.bind(this);\n this.initialize = this.initialize.bind(this);\n this.generateTitle = this.generateTitle.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n this.getState = this.getState.bind(this);\n this.detach = this.detach.bind(this);\n }\n\n public getState(): ThreadListItemState {\n return this._core.getState();\n }\n\n public switchTo(options?: { unarchive?: boolean }): Promise<void> {\n const state = this._core.getState();\n return this._threadListBinding.switchToThread(state.id, options);\n }\n\n public rename(newTitle: string): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.rename(state.id, newTitle);\n }\n\n public updateCustom(\n custom: Record<string, unknown> | undefined,\n ): Promise<void> {\n const state = this._core.getState();\n if (!this._threadListBinding.updateCustom) {\n throw new Error(\n \"Thread list runtime does not support updating custom metadata\",\n );\n }\n\n return this._threadListBinding.updateCustom(state.id, custom);\n }\n\n public archive(): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.archive(state.id);\n }\n\n public unarchive(): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.unarchive(state.id);\n }\n\n public delete(): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.delete(state.id);\n }\n\n public initialize(): Promise<{\n remoteId: string;\n externalId: string | undefined;\n }> {\n const state = this._core.getState();\n return this._threadListBinding.initialize(state.id);\n }\n\n public generateTitle(): Promise<void> {\n const state = this._core.getState();\n return this._threadListBinding.generateTitle(state.id);\n }\n\n public unstable_on<E extends ThreadListItemEventType>(\n event: E,\n callback: ThreadListItemEventCallback<E>,\n ) {\n let prevIsMain = this._core.getState().isMain;\n let prevThreadId = this._core.getState().id;\n return this.subscribe(() => {\n const currentState = this._core.getState();\n const newIsMain = currentState.isMain;\n const newThreadId = currentState.id;\n if (prevIsMain === newIsMain && prevThreadId === newThreadId) return;\n prevIsMain = newIsMain;\n prevThreadId = newThreadId;\n\n if (event === \"switchedTo\" && !newIsMain) return;\n if (event === \"switchedAway\" && newIsMain) return;\n notifyEventListeners(\n [callback as (payload?: unknown) => void],\n {},\n `Thread list item \"${event}\"`,\n );\n });\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n public detach(): void {\n const state = this._core.getState();\n\n this._threadListBinding.detach(state.id);\n }\n\n public __internal_getRuntime(): ThreadListItemRuntime {\n return this;\n }\n}\n"],"mappings":";;AA+DA,IAAauC,4BAAb,MAAwE;CACtE,IAAWvB,OAAO;EAChB,OAAO,KAAKwB,MAAMxB;CACpB;CAEA;CACA;CAEA0B,YACEF,OACAC,oBACA;EACA,KAAKD,QAAQA;EACb,KAAKC,qBAAqBA;EAC1B,KAAKE,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKpB,WAAW,KAAKA,SAASqB,KAAK,IAAI;EACvC,KAAKlB,SAAS,KAAKA,OAAOkB,KAAK,IAAI;EACnC,KAAKhB,eAAe,KAAKA,aAAagB,KAAK,IAAI;EAC/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,KAAKwB,mBAAmBV,OAAOc,MAAME,EAAE;CAChD;CAEA,aAGG;EACD,MAAMF,QAAQ,KAAKL,MAAMvB,SAAS;EAClC,OAAO,KAAKwB,mBAAmBvB,WAAW2B,MAAME,EAAE;CACpD;CAEA,gBAAsC;EACpC,MAAMF,QAAQ,KAAKL,MAAMvB,SAAS;EAClC,OAAO,KAAKwB,mBAAmBnB,cAAcuB,MAAME,EAAE;CACvD;CAEA,YACEX,OACAF,UACA;EACA,IAAIe,aAAa,KAAKT,MAAMvB,SAAS,CAAC,CAACiC;EACvC,IAAIC,eAAe,KAAKX,MAAMvB,SAAS,CAAC,CAAC8B;EACzC,OAAO,KAAKd,gBAAgB;GAC1B,MAAMmB,eAAe,KAAKZ,MAAMvB,SAAS;GACzC,MAAMoC,YAAYD,aAAaF;GAC/B,MAAMI,cAAcF,aAAaL;GACjC,IAAIE,eAAeI,aAAaF,iBAAiBG,aAAa;GAC9DL,aAAaI;GACbF,eAAeG;GAEf,IAAIlB,UAAU,gBAAgB,CAACiB,WAAW;GAC1C,IAAIjB,UAAU,kBAAkBiB,WAAW;GAC3CjD,qBACE,CAAC8B,QAAuC,GACxC,CAAC,GACD,qBAAqBE,MAAK,EAC5B;EACF,CAAC;CACH;CAEA,UAAiBF,UAAmC;EAClD,OAAO,KAAKM,MAAMP,UAAUC,QAAQ;CACtC;CAEA,SAAsB;EACpB,MAAMW,QAAQ,KAAKL,MAAMvB,SAAS;EAElC,KAAKwB,mBAAmBT,OAAOa,MAAME,EAAE;CACzC;CAEA,wBAAsD;EACpD,OAAO;CACT;AACF"}
|
|
@@ -33,9 +33,9 @@ type ThreadListRuntime = {
|
|
|
33
33
|
};
|
|
34
34
|
type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;
|
|
35
35
|
declare class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
36
|
+
private _getState;
|
|
36
37
|
private _core;
|
|
37
38
|
private _runtimeFactory;
|
|
38
|
-
private _getState;
|
|
39
39
|
constructor(_core: ThreadListRuntimeCoreBinding, _runtimeFactory?: new (binding: ThreadRuntimeCoreBinding, threadListItemBinding: ThreadListItemRuntimeBinding) => ThreadRuntime);
|
|
40
40
|
protected __internal_bindMethods(): void;
|
|
41
41
|
switchToThread(threadId: string, options?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"mappings":";;;;;;KAwBY;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA,aAAa,SACpB,eAAe,KAAK;;KAIZ;EACV,YAAY;EAEZ,UAAU,uBAAuB;WAExB,MAAM;EACf,QAAQ,mBAAmB;WAElB,UAAU;EACnB,YAAY,mBAAmB;EAC/B,eAAe,cAAc;EAC7B,uBAAuB,cAAc;EAErC,eACE,kBACA;IAAY;MACX;EACH,qBAAqB;EAErB,yBAAyB;EACzB,UAAU;EACV,YAAY;;KAsCF,+BAA+B;cAE9B,iCAAiC;
|
|
1
|
+
{"version":3,"file":"thread-list-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"mappings":";;;;;;KAwBY;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA,aAAa,SACpB,eAAe,KAAK;;KAIZ;EACV,YAAY;EAEZ,UAAU,uBAAuB;WAExB,MAAM;EACf,QAAQ,mBAAmB;WAElB,UAAU;EACnB,YAAY,mBAAmB;EAC/B,eAAe,cAAc;EAC7B,uBAAuB,cAAc;EAErC,eACE,kBACA;IAAY;MACX;EACH,qBAAqB;EAErB,yBAAyB;EACzB,UAAU;EACV,YAAY;;KAsCF,+BAA+B;cAE9B,iCAAiC;UACpC;UACA;UACA;EAMN,YAAA,OAAO,8BACP,uBACE,SAAS,0BACT,uBAAuB,iCACpB;YAyCG;EAcH,eACL,kBACA;IAAY;MACX;EAII,qBAAqB;EAIrB,yBAAyB;EAIzB,UAAU;EAIV,YAAY;EAIZ,YAAY;EAIZ,UAAU,uBAAuB;UAIhC;WAEQ,MAAM;MAEX,YAAQ;EAIZ,QAAQ,mBAAgB;EAcxB,eAAe,cAAW;EAgB1B,uBAAuB,cAAW;EAmBlC,YAAY,mBAAgB"}
|
|
@@ -31,9 +31,9 @@ const getThreadListItemState = (threadList, threadId) => {
|
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
33
|
var ThreadListRuntimeImpl = class {
|
|
34
|
+
_getState;
|
|
34
35
|
_core;
|
|
35
36
|
_runtimeFactory;
|
|
36
|
-
_getState;
|
|
37
37
|
constructor(_core, _runtimeFactory = ThreadRuntimeImpl) {
|
|
38
38
|
this._core = _core;
|
|
39
39
|
this._runtimeFactory = _runtimeFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-runtime.js","names":["Unsubscribe","LazyMemoizeSubject","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","ThreadListRuntimeCore","ThreadListItemRuntime","ThreadListItemRuntimeImpl","ThreadListItemState","ThreadListItemRuntimeBinding","ThreadRuntime","ThreadRuntimeCoreBinding","ThreadRuntimeImpl","RESOLVED_PROMISE","Promise","resolve","ThreadListState","mainThreadId","newThreadId","threadIds","archivedThreadIds","isLoading","isLoadingMore","hasMore","threadItems","Readonly","Record","Omit","ThreadListRuntime","getState","subscribe","callback","main","getById","threadId","mainItem","getItemById","getItemByIndex","idx","getArchivedItemByIndex","switchToThread","options","unarchive","switchToNewThread","getLoadThreadsPromise","reload","loadMore","getThreadListState","threadList","getThreadListItemState","undefined","threadData","id","remoteId","externalId","title","status","lastMessageAt","custom","isMain","ThreadListRuntimeCoreBinding","ThreadListRuntimeImpl","_getState","constructor","_core","_runtimeFactory","binding","threadListItemBinding","stateBinding","path","bind","_mainThreadListItemRuntime","ref","threadSelector","type","getMainThreadRuntimeCore","__internal_bindMethods","JSON","stringify","getThreadRuntimeCore","index"],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport {\n LazyMemoizeSubject,\n NestedSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport type { ThreadListRuntimeCore } from \"../interfaces/thread-list-runtime-core\";\nimport {\n type ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n type ThreadListItemState,\n} from \"./thread-list-item-runtime\";\nimport {\n type ThreadListItemRuntimeBinding,\n type ThreadRuntime,\n type ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./thread-runtime\";\n\nconst RESOLVED_PROMISE = Promise.resolve();\n\nexport type ThreadListState = {\n readonly mainThreadId: string;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly isLoading: boolean;\n readonly isLoadingMore: boolean;\n readonly hasMore: boolean;\n readonly threadItems: Readonly<\n Record<string, Omit<ThreadListItemState, \"isMain\" | \"threadId\">>\n >;\n};\n\nexport type ThreadListRuntime = {\n getState(): ThreadListState;\n\n subscribe(callback: () => void): Unsubscribe;\n\n readonly main: ThreadRuntime;\n getById(threadId: string): ThreadRuntime;\n\n readonly mainItem: ThreadListItemRuntime;\n getItemById(threadId: string): ThreadListItemRuntime;\n getItemByIndex(idx: number): ThreadListItemRuntime;\n getArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n\n switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void>;\n switchToNewThread(): Promise<void>;\n\n getLoadThreadsPromise(): Promise<void>;\n reload(): Promise<void>;\n loadMore(): Promise<void>;\n};\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n mainThreadId: threadList.mainThreadId,\n newThreadId: threadList.newThreadId,\n threadIds: threadList.threadIds,\n archivedThreadIds: threadList.archivedThreadIds,\n isLoading: threadList.isLoading,\n isLoadingMore: threadList.isLoadingMore ?? false,\n hasMore: threadList.hasMore ?? false,\n threadItems: threadList.threadItems,\n };\n};\n\nconst getThreadListItemState = (\n threadList: ThreadListRuntimeCore,\n threadId: string | undefined,\n): ThreadListItemState | SKIP_UPDATE => {\n if (threadId === undefined) return SKIP_UPDATE;\n\n const threadData = threadList.getItemById(threadId);\n if (!threadData) return SKIP_UPDATE;\n return {\n id: threadData.id,\n remoteId: threadData.remoteId,\n externalId: threadData.externalId,\n title: threadData.title,\n status: threadData.status,\n lastMessageAt: threadData.lastMessageAt,\n custom: threadData.custom,\n isMain: threadData.id === threadList.mainThreadId,\n };\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n private _getState;\n constructor(\n private _core: ThreadListRuntimeCoreBinding,\n private _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n const stateBinding = new LazyMemoizeSubject({\n path: {},\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[main]`,\n threadSelector: { type: \"main\" },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.mainThreadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n\n this.main = new _runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.getMainThreadRuntimeCore(),\n subscribe: (callback) => _core.subscribe(callback),\n }),\n this._mainThreadListItemRuntime,\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.switchToThread = this.switchToThread.bind(this);\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.getLoadThreadsPromise = this.getLoadThreadsPromise.bind(this);\n this.reload = this.reload.bind(this);\n this.loadMore = this.loadMore.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getById = this.getById.bind(this);\n this.getItemById = this.getItemById.bind(this);\n this.getItemByIndex = this.getItemByIndex.bind(this);\n this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);\n }\n\n public switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void> {\n return this._core.switchToThread(threadId, options);\n }\n\n public switchToNewThread(): Promise<void> {\n return this._core.switchToNewThread();\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return this._core.getLoadThreadsPromise();\n }\n\n public reload(): Promise<void> {\n return this._core.reload?.() ?? RESOLVED_PROMISE;\n }\n\n public loadMore(): Promise<void> {\n return this._core.loadMore?.() ?? RESOLVED_PROMISE;\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n private _mainThreadListItemRuntime;\n\n public readonly main: ThreadRuntime;\n\n public get mainItem() {\n return this._mainThreadListItemRuntime;\n }\n\n public getById(threadId: string) {\n return new this._runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: `threads[threadId=${JSON.stringify(threadId)}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => this._core.getThreadRuntimeCore(threadId),\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this.mainItem,\n );\n }\n\n public getItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.threadIds[idx]);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(\n this._core,\n this._core.archivedThreadIds[idx],\n );\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n return getThreadListItemState(this._core, threadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";;;;AAsBA,MAAMa,mBAAmBC,QAAQC,QAAQ;AAuCzC,MAAMgC,sBACJC,eACoB;CACpB,OAAO;EACL/B,cAAc+B,WAAW/B;EACzBC,aAAa8B,WAAW9B;EACxBC,WAAW6B,WAAW7B;EACtBC,mBAAmB4B,WAAW5B;EAC9BC,WAAW2B,WAAW3B;EACtBC,eAAe0B,WAAW1B,iBAAiB;EAC3CC,SAASyB,WAAWzB,WAAW;EAC/BC,aAAawB,WAAWxB;CAC1B;AACF;AAEA,MAAMyB,0BACJD,YACAd,aACsC;CACtC,IAAIA,aAAagB,KAAAA,GAAW,OAAO/C;CAEnC,MAAMgD,aAAaH,WAAWZ,YAAYF,QAAQ;CAClD,IAAI,CAACiB,YAAY,OAAOhD;CACxB,OAAO;EACLiD,IAAID,WAAWC;EACfC,UAAUF,WAAWE;EACrBC,YAAYH,WAAWG;EACvBC,OAAOJ,WAAWI;EAClBC,QAAQL,WAAWK;EACnBC,eAAeN,WAAWM;EAC1BC,QAAQP,WAAWO;EACnBC,QAAQR,WAAWC,OAAOJ,WAAW/B;CACvC;AACF;AAIA,IAAa4C,wBAAb,MAAgE;CAGpDG;CACAC;CAHV;CACAF,YACE,OACA,kBAGqBnD,mBACrB;EALQoD,KAAAA,QAAAA;EACAC,KAAAA,kBAAAA;EAKR,MAAMG,eAAe,IAAInE,mBAAmB;GAC1CoE,MAAM,CAAC;GACPxC,gBAAgBkB,mBAAmBi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,uBAAuBlC,IAAG;IAC/BmC,gBAAgB;KAAEC,MAAM;KAAgBM,OAAO1C;IAAI;GACrD;GACAT,gBAAgB;IACd,OAAOoB,uBACL,KAAKe,OACL,KAAKA,MAAM5C,kBAAkBkB,IAC/B;GACF;GACAR,YAAYC,aAAa,KAAKiC,MAAMlC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKiC,KACP;CACF;CAEA,YAAmB9B,UAAkB;EACnC,OAAO,IAAI3B,0BACT,IAAIH,sBAAsB;GACxBiE,MAAM;IACJG,KAAK,wBAAwBtC,SAAQ;IACrCuC,gBAAgB;KAAEC,MAAM;KAAYxC;IAAS;GAC/C;GACAL,gBAAgB;IACd,OAAOoB,uBAAuB,KAAKe,OAAO9B,QAAQ;GACpD;GACAJ,YAAYC,aAAa,KAAKiC,MAAMlC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKiC,KACP;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"thread-list-runtime.js","names":["Unsubscribe","LazyMemoizeSubject","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","ThreadListRuntimeCore","ThreadListItemRuntime","ThreadListItemRuntimeImpl","ThreadListItemState","ThreadListItemRuntimeBinding","ThreadRuntime","ThreadRuntimeCoreBinding","ThreadRuntimeImpl","RESOLVED_PROMISE","Promise","resolve","ThreadListState","mainThreadId","newThreadId","threadIds","archivedThreadIds","isLoading","isLoadingMore","hasMore","threadItems","Readonly","Record","Omit","ThreadListRuntime","getState","subscribe","callback","main","getById","threadId","mainItem","getItemById","getItemByIndex","idx","getArchivedItemByIndex","switchToThread","options","unarchive","switchToNewThread","getLoadThreadsPromise","reload","loadMore","getThreadListState","threadList","getThreadListItemState","undefined","threadData","id","remoteId","externalId","title","status","lastMessageAt","custom","isMain","ThreadListRuntimeCoreBinding","ThreadListRuntimeImpl","_getState","_core","_runtimeFactory","binding","threadListItemBinding","constructor","stateBinding","path","bind","_mainThreadListItemRuntime","ref","threadSelector","type","getMainThreadRuntimeCore","__internal_bindMethods","JSON","stringify","getThreadRuntimeCore","index"],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport {\n LazyMemoizeSubject,\n NestedSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport type { ThreadListRuntimeCore } from \"../interfaces/thread-list-runtime-core\";\nimport {\n type ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n type ThreadListItemState,\n} from \"./thread-list-item-runtime\";\nimport {\n type ThreadListItemRuntimeBinding,\n type ThreadRuntime,\n type ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./thread-runtime\";\n\nconst RESOLVED_PROMISE = Promise.resolve();\n\nexport type ThreadListState = {\n readonly mainThreadId: string;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly isLoading: boolean;\n readonly isLoadingMore: boolean;\n readonly hasMore: boolean;\n readonly threadItems: Readonly<\n Record<string, Omit<ThreadListItemState, \"isMain\" | \"threadId\">>\n >;\n};\n\nexport type ThreadListRuntime = {\n getState(): ThreadListState;\n\n subscribe(callback: () => void): Unsubscribe;\n\n readonly main: ThreadRuntime;\n getById(threadId: string): ThreadRuntime;\n\n readonly mainItem: ThreadListItemRuntime;\n getItemById(threadId: string): ThreadListItemRuntime;\n getItemByIndex(idx: number): ThreadListItemRuntime;\n getArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n\n switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void>;\n switchToNewThread(): Promise<void>;\n\n getLoadThreadsPromise(): Promise<void>;\n reload(): Promise<void>;\n loadMore(): Promise<void>;\n};\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n mainThreadId: threadList.mainThreadId,\n newThreadId: threadList.newThreadId,\n threadIds: threadList.threadIds,\n archivedThreadIds: threadList.archivedThreadIds,\n isLoading: threadList.isLoading,\n isLoadingMore: threadList.isLoadingMore ?? false,\n hasMore: threadList.hasMore ?? false,\n threadItems: threadList.threadItems,\n };\n};\n\nconst getThreadListItemState = (\n threadList: ThreadListRuntimeCore,\n threadId: string | undefined,\n): ThreadListItemState | SKIP_UPDATE => {\n if (threadId === undefined) return SKIP_UPDATE;\n\n const threadData = threadList.getItemById(threadId);\n if (!threadData) return SKIP_UPDATE;\n return {\n id: threadData.id,\n remoteId: threadData.remoteId,\n externalId: threadData.externalId,\n title: threadData.title,\n status: threadData.status,\n lastMessageAt: threadData.lastMessageAt,\n custom: threadData.custom,\n isMain: threadData.id === threadList.mainThreadId,\n };\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n private _getState;\n private _core: ThreadListRuntimeCoreBinding;\n private _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime;\n\n constructor(\n _core: ThreadListRuntimeCoreBinding,\n _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n this._core = _core;\n this._runtimeFactory = _runtimeFactory;\n const stateBinding = new LazyMemoizeSubject({\n path: {},\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[main]`,\n threadSelector: { type: \"main\" },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.mainThreadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n\n this.main = new _runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.getMainThreadRuntimeCore(),\n subscribe: (callback) => _core.subscribe(callback),\n }),\n this._mainThreadListItemRuntime,\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.switchToThread = this.switchToThread.bind(this);\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.getLoadThreadsPromise = this.getLoadThreadsPromise.bind(this);\n this.reload = this.reload.bind(this);\n this.loadMore = this.loadMore.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getById = this.getById.bind(this);\n this.getItemById = this.getItemById.bind(this);\n this.getItemByIndex = this.getItemByIndex.bind(this);\n this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);\n }\n\n public switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void> {\n return this._core.switchToThread(threadId, options);\n }\n\n public switchToNewThread(): Promise<void> {\n return this._core.switchToNewThread();\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return this._core.getLoadThreadsPromise();\n }\n\n public reload(): Promise<void> {\n return this._core.reload?.() ?? RESOLVED_PROMISE;\n }\n\n public loadMore(): Promise<void> {\n return this._core.loadMore?.() ?? RESOLVED_PROMISE;\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n private _mainThreadListItemRuntime;\n\n public readonly main: ThreadRuntime;\n\n public get mainItem() {\n return this._mainThreadListItemRuntime;\n }\n\n public getById(threadId: string) {\n return new this._runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: `threads[threadId=${JSON.stringify(threadId)}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => this._core.getThreadRuntimeCore(threadId),\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this.mainItem,\n );\n }\n\n public getItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.threadIds[idx]);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(\n this._core,\n this._core.archivedThreadIds[idx],\n );\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n return getThreadListItemState(this._core, threadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";;;;AAsBA,MAAMa,mBAAmBC,QAAQC,QAAQ;AAuCzC,MAAMgC,sBACJC,eACoB;CACpB,OAAO;EACL/B,cAAc+B,WAAW/B;EACzBC,aAAa8B,WAAW9B;EACxBC,WAAW6B,WAAW7B;EACtBC,mBAAmB4B,WAAW5B;EAC9BC,WAAW2B,WAAW3B;EACtBC,eAAe0B,WAAW1B,iBAAiB;EAC3CC,SAASyB,WAAWzB,WAAW;EAC/BC,aAAawB,WAAWxB;CAC1B;AACF;AAEA,MAAMyB,0BACJD,YACAd,aACsC;CACtC,IAAIA,aAAagB,KAAAA,GAAW,OAAO/C;CAEnC,MAAMgD,aAAaH,WAAWZ,YAAYF,QAAQ;CAClD,IAAI,CAACiB,YAAY,OAAOhD;CACxB,OAAO;EACLiD,IAAID,WAAWC;EACfC,UAAUF,WAAWE;EACrBC,YAAYH,WAAWG;EACvBC,OAAOJ,WAAWI;EAClBC,QAAQL,WAAWK;EACnBC,eAAeN,WAAWM;EAC1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C;IAAI;GAC9C;GACAT,gBAAgB;IACd,OAAOoB,uBAAuB,KAAKc,OAAO,KAAKA,MAAM5C,UAAUmB,IAAI;GACrE;GACAR,YAAYC,aAAa,KAAKgC,MAAMjC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKgC,KACP;CACF;CAEA,uBAA8BzB,KAAa;EACzC,OAAO,IAAI/B,0BACT,IAAIH,sBAAsB;GACxBiE,MAAM;IACJG,KAAK,uBAAuBlC,IAAG;IAC/BmC,gBAAgB;KAAEC,MAAM;KAAgBM,OAAO1C;IAAI;GACrD;GACAT,gBAAgB;IACd,OAAOoB,uBACL,KAAKc,OACL,KAAKA,MAAM3C,kBAAkBkB,IAC/B;GACF;GACAR,YAAYC,aAAa,KAAKgC,MAAMjC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKgC,KACP;CACF;CAEA,YAAmB7B,UAAkB;EACnC,OAAO,IAAI3B,0BACT,IAAIH,sBAAsB;GACxBiE,MAAM;IACJG,KAAK,wBAAwBtC,SAAQ;IACrCuC,gBAAgB;KAAEC,MAAM;KAAYxC;IAAS;GAC/C;GACAL,gBAAgB;IACd,OAAOoB,uBAAuB,KAAKc,OAAO7B,QAAQ;GACpD;GACAJ,YAAYC,aAAa,KAAKgC,MAAMjC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKgC,KACP;CACF;AACF"}
|
|
@@ -19,7 +19,6 @@ type BaseThreadAdapters = {
|
|
|
19
19
|
voice?: RealtimeVoiceAdapter | undefined;
|
|
20
20
|
};
|
|
21
21
|
declare abstract class BaseThreadRuntimeCore implements ThreadRuntimeCore {
|
|
22
|
-
private readonly _contextProvider;
|
|
23
22
|
private _subscriptions;
|
|
24
23
|
private _isInitialized;
|
|
25
24
|
protected readonly repository: MessageRepository;
|
|
@@ -50,6 +49,7 @@ declare abstract class BaseThreadRuntimeCore implements ThreadRuntimeCore {
|
|
|
50
49
|
get messages(): readonly ThreadMessage[];
|
|
51
50
|
get state(): string | number | boolean | import("assistant-stream/utils").ReadonlyJSONObject | import("assistant-stream/utils").ReadonlyJSONArray | null;
|
|
52
51
|
readonly composer: DefaultThreadComposerRuntimeCore;
|
|
52
|
+
private readonly _contextProvider;
|
|
53
53
|
constructor(_contextProvider: ModelContextProvider);
|
|
54
54
|
getModelContext(): ModelContext;
|
|
55
55
|
private _editComposers;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-thread-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/base-thread-runtime-core.ts"],"mappings":";;;;;;;;;;;;;;KAsCK;EACH,SAAS;EACT,WAAW;EACX,cAAc;EACd,QAAQ;;uBAGY,iCAAiC;
|
|
1
|
+
{"version":3,"file":"base-thread-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/base-thread-runtime-core.ts"],"mappings":";;;;;;;;;;;;;;KAsCK;EACH,SAAS;EACT,WAAW;EACX,cAAc;EACd,QAAQ;;uBAGY,iCAAiC;UAC7C;UACA;qBAEW,YAAU;eACT,YAAY;eACZ;eACA;eACA;eACA,wBAAwB;eACxB;eAEA,gBAAgB;WACpB,OAAO,SAAS;WAChB,cAAc,2BAA2B;WACzC,SAAS,QAAQ;WACjB,UAAU,QAAQ;WAClB,cAAc,SAAS;WACvB,eAAe,SAAS;WACxB,sBACd,SAAS;WAEK;WACA;WACA,oBAAoB;YAE1B,gBAAgB;YAChB;UACF;UACA;UACA;YAEE;YAKA,6BAA6B;MAI5B,qBAAqB;MAgBrB,sEAAK,sDAAA;WAWA,UAAQ;mBAEP;EAEL,YAAA,kBAAkB;EAIvB,mBAJuB;UAQtB;EACD,gBAAgB,oBAAiB;EAGjC,UAAU;EAeV,eAAe;;;;;EAsBf,YAAY;EAOZ,eAAe;YAKZ;EAIH,wBAAwB,UAAU,wBACvC,OAAO,GACP,SAAS,0BAA0B;EAQ9B,UAAU,uBAAuB;EAKjC,iBAAiB,WAAW,QAAQ;UAqBnC;EACD,QAAQ;EAER,MAAM;EA8BN;UAMC;UACA;EACD,OAAO;UAEN;UACA;EAED;EAEA,uBAAwB,yBAAuB;EAK/C;UA+DC;UAEA;UA8DA;EAaD;EAeA;EAUA;YAUG;EAOH,UAAM;EAIN,OAAO,MAAM;EAOb,MAAM,2BAA2B;UAIhC;EAKD,YAAY,UAAU,wBAC3B,OAAO,GACP,UAAU,2BAA2B,KAAE"}
|
|
@@ -6,7 +6,6 @@ import { DefaultThreadComposerRuntimeCore } from "./default-thread-composer-runt
|
|
|
6
6
|
import { DefaultEditComposerRuntimeCore } from "./default-edit-composer-runtime-core.js";
|
|
7
7
|
//#region src/runtime/base/base-thread-runtime-core.ts
|
|
8
8
|
var BaseThreadRuntimeCore = class {
|
|
9
|
-
_contextProvider;
|
|
10
9
|
_subscriptions = /* @__PURE__ */ new Set();
|
|
11
10
|
_isInitialized = false;
|
|
12
11
|
repository = new MessageRepository();
|
|
@@ -38,6 +37,7 @@ var BaseThreadRuntimeCore = class {
|
|
|
38
37
|
return mostRecentAssistantMessage?.metadata.unstable_state ?? null;
|
|
39
38
|
}
|
|
40
39
|
composer = new DefaultThreadComposerRuntimeCore(this);
|
|
40
|
+
_contextProvider;
|
|
41
41
|
constructor(_contextProvider) {
|
|
42
42
|
this._contextProvider = _contextProvider;
|
|
43
43
|
}
|