@assistant-ui/core 0.2.20 → 0.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/attachment.d.ts +2 -2
- package/dist/adapters/attachment.d.ts.map +1 -1
- package/dist/adapters/attachment.js +14 -7
- package/dist/adapters/attachment.js.map +1 -1
- package/dist/adapters/directive-formatter.d.ts +0 -1
- package/dist/adapters/directive-formatter.d.ts.map +1 -1
- package/dist/adapters/feedback.d.ts +0 -1
- package/dist/adapters/feedback.d.ts.map +1 -1
- package/dist/adapters/index.d.ts +2 -2
- package/dist/adapters/index.js +2 -1
- package/dist/adapters/speech.d.ts +0 -1
- package/dist/adapters/speech.d.ts.map +1 -1
- package/dist/adapters/speech.js +9 -2
- package/dist/adapters/speech.js.map +1 -1
- package/dist/adapters/suggestion.d.ts +16 -2
- package/dist/adapters/suggestion.d.ts.map +1 -1
- package/dist/adapters/suggestion.js +36 -0
- package/dist/adapters/suggestion.js.map +1 -0
- package/dist/adapters/thread-history.d.ts +2 -2
- package/dist/adapters/thread-history.d.ts.map +1 -1
- package/dist/adapters/trigger.d.ts +5 -3
- package/dist/adapters/trigger.d.ts.map +1 -1
- package/dist/adapters/voice.d.ts +0 -1
- package/dist/adapters/voice.d.ts.map +1 -1
- package/dist/adapters/voice.js +13 -5
- package/dist/adapters/voice.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/duplicate-detection.d.ts.map +1 -1
- package/dist/internal.d.ts +9 -1
- package/dist/internal.js +8 -2
- package/dist/model-context/frame/host.d.ts +1 -1
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +5 -0
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/frame/provider.d.ts +0 -1
- package/dist/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +1 -0
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/frame/types.d.ts.map +1 -1
- package/dist/model-context/interactable-composer-metadata.d.ts +4 -2
- package/dist/model-context/interactable-composer-metadata.d.ts.map +1 -1
- package/dist/model-context/interactable-composer-metadata.js.map +1 -1
- package/dist/model-context/registry-handles.d.ts +0 -1
- package/dist/model-context/registry-handles.d.ts.map +1 -1
- package/dist/model-context/registry.d.ts +0 -1
- package/dist/model-context/registry.d.ts.map +1 -1
- package/dist/model-context/tool.d.ts +23 -9
- package/dist/model-context/tool.d.ts.map +1 -1
- package/dist/model-context/tool.js +0 -25
- package/dist/model-context/tool.js.map +1 -1
- package/dist/model-context/types.d.ts +0 -1
- package/dist/model-context/types.d.ts.map +1 -1
- package/dist/react/AssistantProvider.d.ts +0 -1
- package/dist/react/AssistantProvider.d.ts.map +1 -1
- package/dist/react/AssistantProvider.js.map +1 -1
- package/dist/react/AssistantRuntimeProvider.d.ts +1 -6
- package/dist/react/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/react/RuntimeAdapter.d.ts +1 -0
- package/dist/react/RuntimeAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts +13 -2
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +196 -54
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/adapters/TitleGenerationAdapter.d.ts +0 -1
- package/dist/react/adapters/TitleGenerationAdapter.d.ts.map +1 -1
- package/dist/react/client/DataRenderers.d.ts +0 -1
- package/dist/react/client/DataRenderers.d.ts.map +1 -1
- package/dist/react/client/Interactables.d.ts +0 -1
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/Tools.d.ts +3 -2
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/interactable-model-context.d.ts +0 -1
- package/dist/react/client/interactable-model-context.d.ts.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/interactables-legacy/Interactables.d.ts +0 -1
- package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -1
- package/dist/react/interactables-legacy/interactable-model-context.d.ts +0 -1
- package/dist/react/interactables-legacy/interactable-model-context.d.ts.map +1 -1
- package/dist/react/interactables-legacy/scopes.d.ts +4 -2
- package/dist/react/interactables-legacy/scopes.d.ts.map +1 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.d.ts +0 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.d.ts.map +1 -1
- package/dist/react/interactables-legacy/useInteractableState.d.ts.map +1 -1
- package/dist/react/model-context/define-mcp-toolkit.d.ts +19 -4
- package/dist/react/model-context/define-mcp-toolkit.d.ts.map +1 -1
- package/dist/react/model-context/define-mcp-toolkit.js +17 -5
- package/dist/react/model-context/define-mcp-toolkit.js.map +1 -1
- package/dist/react/model-context/define-toolkit.d.ts +1 -2
- package/dist/react/model-context/define-toolkit.d.ts.map +1 -1
- package/dist/react/model-context/external-tool.d.ts.map +1 -1
- package/dist/react/model-context/human-tool.d.ts.map +1 -1
- package/dist/react/model-context/interactableTool.d.ts +2 -2
- package/dist/react/model-context/interactableTool.d.ts.map +1 -1
- package/dist/react/model-context/makeAssistantDataUI.d.ts +2 -2
- package/dist/react/model-context/makeAssistantDataUI.d.ts.map +1 -1
- package/dist/react/model-context/makeAssistantTool.d.ts +2 -2
- package/dist/react/model-context/makeAssistantTool.d.ts.map +1 -1
- package/dist/react/model-context/makeAssistantToolUI.d.ts +2 -2
- package/dist/react/model-context/makeAssistantToolUI.d.ts.map +1 -1
- package/dist/react/model-context/provider-tool.d.ts +0 -1
- package/dist/react/model-context/provider-tool.d.ts.map +1 -1
- package/dist/react/model-context/stub-tool.d.ts.map +1 -1
- package/dist/react/model-context/toolbox.d.ts +5 -5
- package/dist/react/model-context/toolbox.d.ts.map +1 -1
- package/dist/react/model-context/useAssistantContext.d.ts +1 -0
- package/dist/react/model-context/useAssistantContext.d.ts.map +1 -1
- package/dist/react/model-context/useAssistantDataUI.d.ts +3 -2
- package/dist/react/model-context/useAssistantDataUI.d.ts.map +1 -1
- package/dist/react/model-context/useAssistantInstructions.d.ts +1 -0
- package/dist/react/model-context/useAssistantInstructions.d.ts.map +1 -1
- package/dist/react/model-context/useAssistantTool.d.ts +4 -2
- package/dist/react/model-context/useAssistantTool.d.ts.map +1 -1
- package/dist/react/model-context/useAssistantToolUI.d.ts +3 -2
- package/dist/react/model-context/useAssistantToolUI.d.ts.map +1 -1
- package/dist/react/model-context/useAuiToolOverrides.d.ts +0 -1
- package/dist/react/model-context/useAuiToolOverrides.d.ts.map +1 -1
- package/dist/react/model-context/useInlineRender.d.ts +0 -1
- package/dist/react/model-context/useInlineRender.d.ts.map +1 -1
- package/dist/react/model-context/useInteractable.d.ts +7 -4
- package/dist/react/model-context/useInteractable.d.ts.map +1 -1
- package/dist/react/model-context/useInteractable.js.map +1 -1
- package/dist/react/model-context/useInteractableState.d.ts.map +1 -1
- package/dist/react/model-context/useInteractableVersions.d.ts +0 -1
- package/dist/react/model-context/useInteractableVersions.d.ts.map +1 -1
- package/dist/react/model-context/useToolArgsStatus.d.ts +3 -1
- package/dist/react/model-context/useToolArgsStatus.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.d.ts +1 -4
- package/dist/react/primitive-hooks/useActionBarCopy.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.js +13 -13
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarFeedback.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarSpeak.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.d.ts +0 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerDictate.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.d.ts +0 -1
- package/dist/react/primitive-hooks/useComposerSend.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerCancel.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerSend.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useMessageBranching.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.js +5 -1
- package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageReload.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.d.ts +1 -5
- package/dist/react/primitive-hooks/useSuggestionTrigger.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadIsRunning.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemArchive.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemDelete.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemTrigger.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadListNew.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadMessageIds.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadMessages.d.ts +0 -1
- package/dist/react/primitive-hooks/useThreadMessages.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useVoice.d.ts +0 -1
- package/dist/react/primitive-hooks/useVoice.d.ts.map +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.d.ts +7 -4
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.d.ts.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.d.ts +4 -3
- package/dist/react/primitives/composer/ComposerAttachments.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/react/primitives/composer/ComposerIf.d.ts +4 -3
- package/dist/react/primitives/composer/ComposerIf.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.d.ts +2 -2
- package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
- package/dist/react/primitives/generativeUI/GenerativeUI.d.ts +2 -2
- package/dist/react/primitives/generativeUI/GenerativeUI.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.d.ts +4 -3
- package/dist/react/primitives/message/MessageAttachments.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.d.ts +1 -6
- package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.d.ts +44 -25
- package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +48 -37
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/message/MessageQuote.d.ts +2 -2
- package/dist/react/primitives/message/MessageQuote.d.ts.map +1 -1
- package/dist/react/primitives/messagePart/MessagePartInProgress.d.ts +0 -1
- package/dist/react/primitives/messagePart/MessagePartInProgress.d.ts.map +1 -1
- package/dist/react/primitives/part/PartMessages.d.ts +2 -2
- package/dist/react/primitives/part/PartMessages.d.ts.map +1 -1
- package/dist/react/primitives/part/PartMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.d.ts +35 -17
- package/dist/react/primitives/thread/ThreadMessages.d.ts.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadSuggestions.d.ts +6 -4
- package/dist/react/primitives/thread/ThreadSuggestions.d.ts.map +1 -1
- package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.d.ts +4 -3
- package/dist/react/primitives/threadList/ThreadListItems.d.ts.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.d.ts +0 -1
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.d.ts.map +1 -1
- package/dist/react/providers/AttachmentByIndexProvider.d.ts +0 -1
- package/dist/react/providers/AttachmentByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.d.ts +0 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.d.ts.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts +0 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +18 -30
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
- package/dist/react/providers/MessageByIdProvider.d.ts +0 -1
- package/dist/react/providers/MessageByIdProvider.d.ts.map +1 -1
- package/dist/react/providers/MessageByIndexProvider.d.ts +0 -1
- package/dist/react/providers/MessageByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/PartByIndexProvider.d.ts +0 -1
- package/dist/react/providers/PartByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/PartByIndexProvider.js +18 -30
- package/dist/react/providers/PartByIndexProvider.js.map +1 -1
- package/dist/react/providers/QueueItemByIndexProvider.d.ts +0 -1
- package/dist/react/providers/QueueItemByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.d.ts +0 -1
- package/dist/react/providers/ReadonlyThreadProvider.d.ts.map +1 -1
- package/dist/react/providers/SuggestionByIndexProvider.d.ts +0 -1
- package/dist/react/providers/SuggestionByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/TextMessagePartProvider.d.ts +0 -1
- package/dist/react/providers/TextMessagePartProvider.d.ts.map +1 -1
- package/dist/react/providers/ThreadListItemByIndexProvider.d.ts +0 -1
- package/dist/react/providers/ThreadListItemByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/ThreadListItemRuntimeProvider.d.ts +1 -1
- package/dist/react/providers/ThreadListItemRuntimeProvider.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +2 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +2 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +12 -3
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +70 -27
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts +0 -1
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +0 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +1 -4
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +8 -4
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +12 -2
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +30 -1
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts +0 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/createMessageConverter.d.ts +1 -7
- package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
- package/dist/react/runtimes/createRuntimeExtras.d.ts +0 -1
- package/dist/react/runtimes/createRuntimeExtras.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.d.ts +1 -8
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +43 -45
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.d.ts +0 -1
- package/dist/react/runtimes/useExternalStoreRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useExternalStoreSharedOptions.d.ts +0 -1
- package/dist/react/runtimes/useExternalStoreSharedOptions.d.ts.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.d.ts +3 -5
- package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.js +9 -1
- package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts +0 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useStreamingTiming.d.ts +0 -1
- package/dist/react/runtimes/useStreamingTiming.d.ts.map +1 -1
- package/dist/react/types/MessagePartComponentTypes.d.ts +6 -3
- package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
- package/dist/react/types/scopes/dataRenderers.d.ts +1 -1
- package/dist/react/types/scopes/dataRenderers.d.ts.map +1 -1
- package/dist/react/types/scopes/interactables.d.ts +4 -2
- package/dist/react/types/scopes/interactables.d.ts.map +1 -1
- package/dist/react/types/scopes/tools.d.ts +5 -3
- package/dist/react/types/scopes/tools.d.ts.map +1 -1
- package/dist/react/types/store-augmentation.d.ts +1 -2
- package/dist/react/types/store-augmentation.d.ts.map +1 -1
- package/dist/react/utils/getMessageQuote.d.ts +0 -1
- package/dist/react/utils/getMessageQuote.d.ts.map +1 -1
- package/dist/react/utils/groupParts.d.ts +2 -2
- package/dist/react/utils/groupParts.d.ts.map +1 -1
- package/dist/react/utils/useJSONEqual.d.ts.map +1 -1
- package/dist/runtime/api/assistant-runtime.d.ts +0 -1
- package/dist/runtime/api/assistant-runtime.d.ts.map +1 -1
- package/dist/runtime/api/attachment-runtime.d.ts +0 -1
- package/dist/runtime/api/attachment-runtime.d.ts.map +1 -1
- package/dist/runtime/api/bindings.d.ts +0 -1
- package/dist/runtime/api/bindings.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.d.ts +6 -4
- package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-part-runtime.d.ts +0 -1
- package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.d.ts +6 -16
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +5 -5
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/api/paths.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.d.ts +0 -1
- package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.js +2 -1
- package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +0 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +3 -1
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/base/base-assistant-runtime-core.d.ts +0 -1
- package/dist/runtime/base/base-assistant-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +4 -2
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +51 -10
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +2 -4
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +3 -2
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts +1 -5
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.js +4 -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 -0
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js +2 -2
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/branch/external-thread-branch-adapter.d.ts.map +1 -1
- package/dist/runtime/interfaces/assistant-runtime-core.d.ts +0 -1
- package/dist/runtime/interfaces/assistant-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/composer-runtime-core.d.ts +2 -2
- package/dist/runtime/interfaces/composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +0 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +2 -2
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/queue/external-thread-queue-adapter.d.ts +0 -1
- package/dist/runtime/queue/external-thread-queue-adapter.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.d.ts +6 -4
- package/dist/runtime/queue/message-queue.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.js +1 -1
- package/dist/runtime/utils/auto-status.d.ts +0 -1
- package/dist/runtime/utils/auto-status.d.ts.map +1 -1
- package/dist/runtime/utils/chat-model-adapter.d.ts +0 -1
- package/dist/runtime/utils/chat-model-adapter.d.ts.map +1 -1
- package/dist/runtime/utils/external-store-message.d.ts +0 -1
- package/dist/runtime/utils/external-store-message.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.d.ts +1 -5
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.js +3 -1
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +0 -1
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -1
- package/dist/runtime/utils/streaming-timing.d.ts +5 -3
- package/dist/runtime/utils/streaming-timing.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.d.ts +2 -2
- package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.js +4 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/assistant-transport/utils.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-adapter.d.ts +2 -2
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-runtime-core.d.ts +0 -1
- package/dist/runtimes/external-store/external-store-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-shared-options.d.ts +0 -1
- package/dist/runtimes/external-store/external-store-shared-options.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +0 -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-runtime-core.d.ts +2 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/thread-message-converter.d.ts +0 -1
- package/dist/runtimes/external-store/thread-message-converter.d.ts.map +1 -1
- package/dist/runtimes/local/local-runtime-core.d.ts +0 -1
- package/dist/runtimes/local/local-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-runtime-options.d.ts +0 -1
- package/dist/runtimes/local/local-runtime-options.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-list-runtime-core.d.ts +0 -1
- package/dist/runtimes/local/local-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +5 -21
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +29 -17
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/local/should-continue.d.ts +0 -1
- package/dist/runtimes/local/should-continue.d.ts.map +1 -1
- package/dist/runtimes/local/should-continue.js +2 -2
- package/dist/runtimes/local/should-continue.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +0 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts +1 -2
- package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js +5 -3
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts +0 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/optimistic-state.d.ts +10 -8
- package/dist/runtimes/remote-thread-list/optimistic-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/optimistic-state.js +22 -9
- package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +0 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +1 -2
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +2 -2
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +1 -2
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts +0 -1
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/model-context-client.d.ts +0 -1
- package/dist/store/clients/model-context-client.d.ts.map +1 -1
- package/dist/store/clients/no-op-composer-client.d.ts +0 -1
- package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
- package/dist/store/clients/runtime-adapter.d.ts +0 -1
- package/dist/store/clients/runtime-adapter.d.ts.map +1 -1
- package/dist/store/clients/suggestions.d.ts +0 -1
- package/dist/store/clients/suggestions.d.ts.map +1 -1
- package/dist/store/clients/thread-message-client.d.ts +0 -1
- package/dist/store/clients/thread-message-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts +0 -1
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts +0 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/liveRef.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts +0 -1
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts +0 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts +0 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts +0 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts +0 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts +0 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts.map +1 -1
- package/dist/store/scope-registration.d.ts +1 -2
- package/dist/store/scope-registration.d.ts.map +1 -1
- package/dist/store/scopes/attachment.d.ts +0 -1
- package/dist/store/scopes/attachment.d.ts.map +1 -1
- package/dist/store/scopes/chain-of-thought.d.ts +0 -1
- package/dist/store/scopes/chain-of-thought.d.ts.map +1 -1
- package/dist/store/scopes/composer.d.ts +0 -1
- package/dist/store/scopes/composer.d.ts.map +1 -1
- package/dist/store/scopes/message.d.ts +6 -4
- package/dist/store/scopes/message.d.ts.map +1 -1
- package/dist/store/scopes/model-context.d.ts +0 -1
- package/dist/store/scopes/model-context.d.ts.map +1 -1
- package/dist/store/scopes/part.d.ts +0 -1
- package/dist/store/scopes/part.d.ts.map +1 -1
- package/dist/store/scopes/queue-item.d.ts.map +1 -1
- package/dist/store/scopes/suggestion.d.ts.map +1 -1
- package/dist/store/scopes/suggestions.d.ts +0 -1
- package/dist/store/scopes/suggestions.d.ts.map +1 -1
- package/dist/store/scopes/thread-list-item.d.ts +0 -1
- package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
- package/dist/store/scopes/thread.d.ts +4 -3
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/store/scopes/threads.d.ts +0 -1
- package/dist/store/scopes/threads.d.ts.map +1 -1
- package/dist/subscribable/subscribable.d.ts +1 -2
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +11 -3
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/tests/remote-thread-list-test-helpers.d.ts +2 -2
- package/dist/tests/remote-thread-list-test-helpers.d.ts.map +1 -1
- package/dist/tests/remote-thread-list-test-helpers.js +5 -2
- package/dist/tests/remote-thread-list-test-helpers.js.map +1 -1
- package/dist/types/attachment.d.ts +3 -2
- package/dist/types/attachment.d.ts.map +1 -1
- package/dist/types/attachment.js +6 -0
- package/dist/types/attachment.js.map +1 -0
- package/dist/types/directive.d.ts +3 -2
- package/dist/types/directive.d.ts.map +1 -1
- package/dist/types/error.d.ts +15 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/error.js +46 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/message.d.ts +71 -33
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/types/trigger.d.ts +0 -1
- package/dist/types/trigger.d.ts.map +1 -1
- package/dist/types/unsubscribe.d.ts.map +1 -1
- package/dist/utils/composite-context-provider.d.ts +1 -0
- package/dist/utils/composite-context-provider.d.ts.map +1 -1
- package/dist/utils/data-url.d.ts +9 -0
- package/dist/utils/data-url.d.ts.map +1 -0
- package/dist/utils/data-url.js +14 -0
- package/dist/utils/data-url.js.map +1 -0
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/json/is-json-equal.d.ts.map +1 -1
- package/dist/utils/json/is-json.d.ts +0 -1
- package/dist/utils/json/is-json.d.ts.map +1 -1
- package/dist/utils/json/is-json.js +1 -1
- package/dist/utils/json/is-json.js.map +1 -1
- package/dist/utils/json/stable-stringify-tool-args.d.ts +7 -0
- package/dist/utils/json/stable-stringify-tool-args.d.ts.map +1 -0
- package/dist/utils/json/stable-stringify-tool-args.js +32 -0
- package/dist/utils/json/stable-stringify-tool-args.js.map +1 -0
- package/dist/utils/notify-event-listeners.d.ts +6 -0
- package/dist/utils/notify-event-listeners.d.ts.map +1 -0
- package/dist/utils/notify-event-listeners.js +16 -0
- package/dist/utils/notify-event-listeners.js.map +1 -0
- package/dist/utils/text.d.ts +0 -1
- package/dist/utils/text.d.ts.map +1 -1
- package/package.json +14 -10
- package/src/adapters/attachment.test.ts +107 -0
- package/src/adapters/attachment.ts +20 -10
- package/src/adapters/index.ts +6 -1
- package/src/adapters/speech.test.ts +88 -0
- package/src/adapters/speech.ts +17 -2
- package/src/adapters/suggestion.test.ts +187 -0
- package/src/adapters/suggestion.ts +75 -1
- package/src/adapters/voice.test.ts +130 -0
- package/src/adapters/voice.ts +26 -6
- package/src/index.ts +15 -1
- package/src/internal.ts +21 -0
- package/src/model-context/frame/host.test.ts +100 -0
- package/src/model-context/frame/host.ts +10 -0
- package/src/model-context/frame/provider.test.ts +83 -0
- package/src/model-context/frame/provider.ts +1 -0
- package/src/model-context/tool.test.ts +110 -0
- package/src/model-context/tool.ts +31 -9
- package/src/react/adapters/LocalStorageThreadListAdapter.test.ts +304 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +307 -60
- package/src/react/index.ts +2 -0
- package/src/react/model-context/define-mcp-toolkit.ts +39 -6
- package/src/react/model-context/define-toolkit.test.ts +107 -0
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +79 -0
- package/src/react/primitive-hooks/useActionBarCopy.ts +4 -3
- package/src/react/primitive-hooks/useMessageError.test.ts +64 -0
- package/src/react/primitive-hooks/useMessageError.ts +19 -6
- package/src/react/primitives/chainOfThought/ChainOfThoughtParts.tsx +1 -3
- package/src/react/primitives/message/MessageParts.tsx +48 -35
- package/src/react/providers/ChainOfThoughtPartByIndexProvider.tsx +19 -2
- package/src/react/providers/PartByIndexProvider.tsx +16 -2
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +18 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +4 -1
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +96 -26
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +69 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +1 -1
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.test.ts +127 -0
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +15 -4
- package/src/react/runtimes/cloud/auiV0.ts +71 -2
- package/src/react/runtimes/external-message-converter.test.tsx +123 -0
- package/src/react/runtimes/external-message-converter.ts +36 -11
- package/src/react/runtimes/useLocalRuntime.test.tsx +56 -0
- package/src/react/runtimes/useLocalRuntime.ts +13 -1
- package/src/runtime/api/message-runtime.test.ts +81 -0
- package/src/runtime/api/message-runtime.ts +4 -6
- package/src/runtime/api/thread-list-item-runtime.ts +6 -1
- package/src/runtime/base/base-composer-runtime-core.ts +95 -30
- package/src/runtime/base/base-thread-runtime-core.ts +2 -1
- package/src/runtime/base/default-edit-composer-runtime-core.ts +4 -2
- package/src/runtime/base/default-thread-composer-runtime-core.ts +2 -2
- package/src/runtime/utils/message-repository.ts +8 -3
- package/src/runtime/utils/thread-message-like.ts +3 -0
- package/src/runtimes/local/local-thread-runtime-core.test.ts +276 -3
- package/src/runtimes/local/local-thread-runtime-core.ts +29 -25
- package/src/runtimes/local/should-continue.ts +5 -2
- package/src/runtimes/remote-thread-list/adapter/in-memory.test.ts +14 -0
- package/src/runtimes/remote-thread-list/adapter/in-memory.ts +13 -5
- package/src/runtimes/remote-thread-list/optimistic-state.test.ts +63 -0
- package/src/runtimes/remote-thread-list/optimistic-state.ts +49 -17
- package/src/runtimes/remote-thread-list/types.ts +1 -1
- package/src/runtimes/tool-invocations/EDGE_CASES.md +13 -19
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +127 -6
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +4 -2
- package/src/subscribable/subscribable.test.ts +58 -0
- package/src/subscribable/subscribable.ts +13 -3
- package/src/tests/MessageRepository.test.ts +26 -0
- package/src/tests/OptimisticState-list-race.test.ts +33 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-errors.test.ts +42 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-order.test.ts +223 -0
- package/src/tests/attachment-adapters.test.ts +14 -2
- package/src/tests/auiV0Encode.test.ts +134 -1
- package/src/tests/base-composer-runtime-core-addAttachment.test.ts +123 -5
- package/src/tests/base-composer-runtime-core-send.test.ts +573 -0
- package/src/tests/default-edit-composer-runtime-core.test.ts +43 -5
- package/src/tests/event-subscription-listener-errors.test.ts +205 -0
- package/src/tests/remote-thread-list-test-helpers.ts +14 -7
- package/src/tests/thread-message-like.test.ts +97 -0
- package/src/types/attachment.ts +6 -0
- package/src/types/error.test.ts +122 -0
- package/src/types/error.ts +74 -0
- package/src/types/index.ts +1 -0
- package/src/types/message.ts +12 -3
- package/src/utils/data-url.test.ts +50 -0
- package/src/utils/data-url.ts +9 -0
- package/src/utils/json/is-json-equal.test.ts +84 -0
- package/src/utils/json/is-json.test.ts +123 -0
- package/src/utils/json/is-json.ts +1 -1
- package/src/utils/json/stable-stringify-tool-args.test.ts +105 -0
- package/src/utils/json/stable-stringify-tool-args.ts +70 -0
- package/src/utils/notify-event-listeners.ts +30 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
const mocks = vi.hoisted(() => {
|
|
4
|
+
const setIsCopied = vi.fn();
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
setIsCopied,
|
|
8
|
+
state: {
|
|
9
|
+
message: {
|
|
10
|
+
role: "assistant",
|
|
11
|
+
status: { type: "complete", reason: "stop" },
|
|
12
|
+
parts: [{ type: "text", text: "Hello" }],
|
|
13
|
+
isCopied: false,
|
|
14
|
+
},
|
|
15
|
+
composer: {
|
|
16
|
+
isEditing: false,
|
|
17
|
+
text: "",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
aui: {
|
|
21
|
+
message: () => ({
|
|
22
|
+
getCopyText: () => "Hello",
|
|
23
|
+
setIsCopied,
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
vi.mock("react", async (importOriginal) => ({
|
|
30
|
+
...(await importOriginal<typeof import("react")>()),
|
|
31
|
+
useCallback: ((callback: unknown) =>
|
|
32
|
+
callback) as typeof import("react").useCallback,
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
vi.mock("@assistant-ui/store", async (importOriginal) => ({
|
|
36
|
+
...(await importOriginal<typeof import("@assistant-ui/store")>()),
|
|
37
|
+
useAui: () => mocks.aui,
|
|
38
|
+
useAuiState: ((selector: (state: typeof mocks.state) => unknown) =>
|
|
39
|
+
selector(mocks.state)) as typeof import("@assistant-ui/store").useAuiState,
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
import { useActionBarCopy } from "./useActionBarCopy";
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
vi.clearAllMocks();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("useActionBarCopy", () => {
|
|
49
|
+
it("does not report copy success without a clipboard handler", async () => {
|
|
50
|
+
const { copy, disabled } = useActionBarCopy();
|
|
51
|
+
|
|
52
|
+
copy();
|
|
53
|
+
await Promise.resolve();
|
|
54
|
+
|
|
55
|
+
expect(disabled).toBe(true);
|
|
56
|
+
expect(mocks.setIsCopied).not.toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("reports copy success after the clipboard handler resolves", async () => {
|
|
60
|
+
const copyToClipboard = vi.fn();
|
|
61
|
+
const { copy } = useActionBarCopy({ copyToClipboard });
|
|
62
|
+
|
|
63
|
+
copy();
|
|
64
|
+
await Promise.resolve();
|
|
65
|
+
|
|
66
|
+
expect(copyToClipboard).toHaveBeenCalledWith("Hello");
|
|
67
|
+
expect(mocks.setIsCopied).toHaveBeenCalledWith(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("does not report copy success when the clipboard handler rejects", async () => {
|
|
71
|
+
const copyToClipboard = vi.fn().mockRejectedValue(new Error("denied"));
|
|
72
|
+
const { copy } = useActionBarCopy({ copyToClipboard });
|
|
73
|
+
|
|
74
|
+
copy();
|
|
75
|
+
await Promise.resolve();
|
|
76
|
+
|
|
77
|
+
expect(mocks.setIsCopied).not.toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -23,13 +23,14 @@ export const useActionBarCopy = ({
|
|
|
23
23
|
const composerValue = useAuiState((s) => s.composer.text);
|
|
24
24
|
|
|
25
25
|
const copy = useCallback(() => {
|
|
26
|
+
if (!copyToClipboard) return;
|
|
27
|
+
|
|
26
28
|
const valueToCopy = isEditing ? composerValue : aui.message().getCopyText();
|
|
27
29
|
if (!valueToCopy) return;
|
|
28
30
|
|
|
29
|
-
const write = copyToClipboard ?? (() => {});
|
|
30
31
|
// The rejection handler swallows clipboard write failures (permission denied,
|
|
31
32
|
// API unavailable) so they don't surface as unhandled promise rejections.
|
|
32
|
-
Promise.resolve(
|
|
33
|
+
Promise.resolve(copyToClipboard(valueToCopy)).then(
|
|
33
34
|
() => {
|
|
34
35
|
aui.message().setIsCopied(true);
|
|
35
36
|
setTimeout(() => aui.message().setIsCopied(false), copiedDuration);
|
|
@@ -38,5 +39,5 @@ export const useActionBarCopy = ({
|
|
|
38
39
|
);
|
|
39
40
|
}, [aui, isEditing, composerValue, copiedDuration, copyToClipboard]);
|
|
40
41
|
|
|
41
|
-
return { copy, disabled, isCopied };
|
|
42
|
+
return { copy, disabled: disabled || !copyToClipboard, isCopied };
|
|
42
43
|
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
const { mockUseAuiState } = vi.hoisted(() => ({ mockUseAuiState: vi.fn() }));
|
|
4
|
+
|
|
5
|
+
vi.mock("@assistant-ui/store", async (importOriginal) => ({
|
|
6
|
+
...(await importOriginal<typeof import("@assistant-ui/store")>()),
|
|
7
|
+
useAuiState: ((selector: (s: unknown) => unknown) =>
|
|
8
|
+
mockUseAuiState(
|
|
9
|
+
selector,
|
|
10
|
+
)) as typeof import("@assistant-ui/store").useAuiState,
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
import { useMessageError } from "./useMessageError";
|
|
14
|
+
|
|
15
|
+
const against = (message: unknown) =>
|
|
16
|
+
mockUseAuiState.mockImplementationOnce((selector: (s: unknown) => unknown) =>
|
|
17
|
+
selector({ message }),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
describe("useMessageError", () => {
|
|
21
|
+
it("returns the message from a structured AssistantError", () => {
|
|
22
|
+
against({
|
|
23
|
+
status: {
|
|
24
|
+
type: "incomplete",
|
|
25
|
+
reason: "error",
|
|
26
|
+
error: { code: "network", message: "offline" },
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
expect(useMessageError()).toBe("offline");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("passes a legacy string error through", () => {
|
|
33
|
+
against({
|
|
34
|
+
status: {
|
|
35
|
+
type: "incomplete",
|
|
36
|
+
reason: "error",
|
|
37
|
+
error: "legacy failure",
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
expect(useMessageError()).toBe("legacy failure");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("returns message from an object that fails the full guard", () => {
|
|
44
|
+
against({
|
|
45
|
+
status: {
|
|
46
|
+
type: "incomplete",
|
|
47
|
+
reason: "error",
|
|
48
|
+
error: {
|
|
49
|
+
code: "unknown",
|
|
50
|
+
message: "foreign severity stream",
|
|
51
|
+
severity: "fatal",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
expect(useMessageError()).toBe("foreign severity stream");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("returns undefined when there is no error status", () => {
|
|
59
|
+
against({
|
|
60
|
+
status: { type: "complete", reason: "stop" },
|
|
61
|
+
});
|
|
62
|
+
expect(useMessageError()).toBeUndefined();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { useAuiState } from "@assistant-ui/store";
|
|
2
2
|
|
|
3
3
|
export const useMessageError = () => {
|
|
4
|
-
return useAuiState((s) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
return useAuiState((s) => {
|
|
5
|
+
if (
|
|
6
|
+
s.message.status?.type !== "incomplete" ||
|
|
7
|
+
s.message.status.reason !== "error"
|
|
8
|
+
) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
const error = s.message.status.error;
|
|
12
|
+
if (typeof error === "string") return error;
|
|
13
|
+
if (
|
|
14
|
+
typeof error === "object" &&
|
|
15
|
+
error !== null &&
|
|
16
|
+
"message" in error &&
|
|
17
|
+
typeof error.message === "string"
|
|
18
|
+
) {
|
|
19
|
+
return error.message;
|
|
20
|
+
}
|
|
21
|
+
return error ?? "An error occurred";
|
|
22
|
+
});
|
|
10
23
|
};
|
|
@@ -51,9 +51,7 @@ const ChainOfThoughtPrimitivePartsInner: FC<{
|
|
|
51
51
|
Array.from({ length: partsLength }, (_, index) => (
|
|
52
52
|
<ChainOfThoughtPartByIndexProvider key={index} index={index}>
|
|
53
53
|
<RenderChildrenWithAccessor
|
|
54
|
-
getItemState={(aui) =>
|
|
55
|
-
aui.chainOfThought().part({ index }).getState()
|
|
56
|
-
}
|
|
54
|
+
getItemState={(aui) => aui.part().getState()}
|
|
57
55
|
>
|
|
58
56
|
{(getItem) =>
|
|
59
57
|
children({
|
|
@@ -728,50 +728,63 @@ const EMPTY_RUNNING_TEXT_PART: Extract<EnrichedPartState, { type: "text" }> =
|
|
|
728
728
|
* `<MessagePrimitive.GroupedParts>`. Returns whatever `children`
|
|
729
729
|
* returns — callers decide how to handle a `null` return.
|
|
730
730
|
*/
|
|
731
|
-
|
|
731
|
+
type MessagePartChildrenProps = {
|
|
732
732
|
index: number;
|
|
733
733
|
children: (value: { part: EnrichedPartState }) => ReactNode;
|
|
734
|
-
}
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
const MessagePartChildrenInner: FC<
|
|
737
|
+
Pick<MessagePartChildrenProps, "children">
|
|
738
|
+
> = ({ children }) => {
|
|
735
739
|
const aui = useAui();
|
|
736
740
|
// Subscribed (not snapshotted like `tools`) so fallbacks registered
|
|
737
741
|
// after the first render trigger a re-render and `hasUI` re-evaluates.
|
|
738
742
|
const dataRenderers = useAuiState((s) => s.dataRenderers);
|
|
739
743
|
|
|
744
|
+
return (
|
|
745
|
+
<RenderChildrenWithAccessor
|
|
746
|
+
getItemState={(client) => client.part().getState()}
|
|
747
|
+
>
|
|
748
|
+
{(getItem) =>
|
|
749
|
+
children({
|
|
750
|
+
get part() {
|
|
751
|
+
const state = getItem();
|
|
752
|
+
if (state.type === "tool-call") {
|
|
753
|
+
const toolsState = aui.tools().getState();
|
|
754
|
+
const hasUI = resolveToolRender(toolsState, state) !== null;
|
|
755
|
+
const partMethods = aui.part();
|
|
756
|
+
return {
|
|
757
|
+
...state,
|
|
758
|
+
toolUI: hasUI ? <RegisteredToolUI /> : null,
|
|
759
|
+
addResult: partMethods.addToolResult,
|
|
760
|
+
resume: partMethods.resumeToolCall,
|
|
761
|
+
respondToApproval: partMethods.respondToToolApproval,
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
if (state.type === "data") {
|
|
765
|
+
const hasUI =
|
|
766
|
+
getDataRenderer(dataRenderers, state.name, undefined) !==
|
|
767
|
+
undefined;
|
|
768
|
+
return {
|
|
769
|
+
...state,
|
|
770
|
+
dataRendererUI: hasUI ? <RegisteredDataRendererUI /> : null,
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
return state;
|
|
774
|
+
},
|
|
775
|
+
})
|
|
776
|
+
}
|
|
777
|
+
</RenderChildrenWithAccessor>
|
|
778
|
+
);
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
export const MessagePartChildren: FC<MessagePartChildrenProps> = ({
|
|
782
|
+
index,
|
|
783
|
+
children,
|
|
784
|
+
}) => {
|
|
740
785
|
return (
|
|
741
786
|
<PartByIndexProvider index={index}>
|
|
742
|
-
<
|
|
743
|
-
getItemState={(aui) => aui.message().part({ index }).getState()}
|
|
744
|
-
>
|
|
745
|
-
{(getItem) =>
|
|
746
|
-
children({
|
|
747
|
-
get part() {
|
|
748
|
-
const state = getItem();
|
|
749
|
-
if (state.type === "tool-call") {
|
|
750
|
-
const toolsState = aui.tools().getState();
|
|
751
|
-
const hasUI = resolveToolRender(toolsState, state) !== null;
|
|
752
|
-
const partMethods = aui.message().part({ index });
|
|
753
|
-
return {
|
|
754
|
-
...state,
|
|
755
|
-
toolUI: hasUI ? <RegisteredToolUI /> : null,
|
|
756
|
-
addResult: partMethods.addToolResult,
|
|
757
|
-
resume: partMethods.resumeToolCall,
|
|
758
|
-
respondToApproval: partMethods.respondToToolApproval,
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
if (state.type === "data") {
|
|
762
|
-
const hasUI =
|
|
763
|
-
getDataRenderer(dataRenderers, state.name, undefined) !==
|
|
764
|
-
undefined;
|
|
765
|
-
return {
|
|
766
|
-
...state,
|
|
767
|
-
dataRendererUI: hasUI ? <RegisteredDataRendererUI /> : null,
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
return state;
|
|
771
|
-
},
|
|
772
|
-
})
|
|
773
|
-
}
|
|
774
|
-
</RenderChildrenWithAccessor>
|
|
787
|
+
<MessagePartChildrenInner>{children}</MessagePartChildrenInner>
|
|
775
788
|
</PartByIndexProvider>
|
|
776
789
|
);
|
|
777
790
|
};
|
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { useMemo, type FC, type PropsWithChildren } from "react";
|
|
2
2
|
import { useAui, AuiProvider, Derived } from "@assistant-ui/store";
|
|
3
|
+
import type { PartMethods } from "../../store/scopes/part";
|
|
3
4
|
|
|
4
5
|
export const ChainOfThoughtPartByIndexProvider: FC<
|
|
5
6
|
PropsWithChildren<{
|
|
6
7
|
index: number;
|
|
7
8
|
}>
|
|
8
9
|
> = ({ index, children }) => {
|
|
10
|
+
const lastPartRef = useMemo(
|
|
11
|
+
() => ({ index, current: null as PartMethods | null }),
|
|
12
|
+
[index],
|
|
13
|
+
);
|
|
9
14
|
const aui = useAui({
|
|
10
15
|
part: Derived({
|
|
11
16
|
source: "chainOfThought",
|
|
12
17
|
query: { type: "index", index },
|
|
13
|
-
get: (aui) =>
|
|
18
|
+
get: (aui) => {
|
|
19
|
+
const chainOfThought = aui.chainOfThought();
|
|
20
|
+
if (
|
|
21
|
+
index >= chainOfThought.getState().parts.length &&
|
|
22
|
+
lastPartRef.current
|
|
23
|
+
) {
|
|
24
|
+
return lastPartRef.current;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const part = chainOfThought.part({ index });
|
|
28
|
+
lastPartRef.current = part;
|
|
29
|
+
return part;
|
|
30
|
+
},
|
|
14
31
|
}),
|
|
15
32
|
});
|
|
16
33
|
|
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { useMemo, type FC, type PropsWithChildren } from "react";
|
|
2
2
|
import { useAui, AuiProvider, Derived } from "@assistant-ui/store";
|
|
3
|
+
import type { PartMethods } from "../../store/scopes/part";
|
|
3
4
|
|
|
4
5
|
export const PartByIndexProvider: FC<
|
|
5
6
|
PropsWithChildren<{
|
|
6
7
|
index: number;
|
|
7
8
|
}>
|
|
8
9
|
> = ({ index, children }) => {
|
|
10
|
+
const lastPartRef = useMemo(
|
|
11
|
+
() => ({ index, current: null as PartMethods | null }),
|
|
12
|
+
[index],
|
|
13
|
+
);
|
|
9
14
|
const aui = useAui({
|
|
10
15
|
part: Derived({
|
|
11
16
|
source: "message",
|
|
12
17
|
query: { type: "index", index },
|
|
13
|
-
get: (aui) =>
|
|
18
|
+
get: (aui) => {
|
|
19
|
+
const message = aui.message();
|
|
20
|
+
if (index >= message.getState().parts.length && lastPartRef.current) {
|
|
21
|
+
return lastPartRef.current;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const part = message.part({ index });
|
|
25
|
+
lastPartRef.current = part;
|
|
26
|
+
return part;
|
|
27
|
+
},
|
|
14
28
|
}),
|
|
15
29
|
});
|
|
16
30
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type { ThreadListRuntimeCore } from "../../runtime/interfaces/thread-list-runtime-core";
|
|
3
|
+
import { RemoteThreadListHookInstanceManager } from "./RemoteThreadListHookInstanceManager";
|
|
4
|
+
|
|
5
|
+
describe("RemoteThreadListHookInstanceManager", () => {
|
|
6
|
+
it("rejects a pending start when the thread runtime is stopped", async () => {
|
|
7
|
+
const manager = new RemoteThreadListHookInstanceManager(() => {
|
|
8
|
+
throw new Error("Runtime hook should not render during this test");
|
|
9
|
+
}, {} as ThreadListRuntimeCore);
|
|
10
|
+
|
|
11
|
+
const startPromise = manager.startThreadRuntime("thread-1");
|
|
12
|
+
manager.stopThreadRuntime("thread-1");
|
|
13
|
+
|
|
14
|
+
await expect(startPromise).rejects.toThrow(
|
|
15
|
+
"Thread was deleted before runtime was started",
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -85,6 +85,7 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
85
85
|
public stopThreadRuntime(threadId: string) {
|
|
86
86
|
this.instances.delete(threadId);
|
|
87
87
|
this.useAliveThreadsKeysChanged.setState({}, true);
|
|
88
|
+
this._notifySubscribers();
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
public setRuntimeHook(newRuntimeHook: RemoteThreadListHook) {
|
|
@@ -109,7 +110,9 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
109
110
|
const updateRuntime = useCallback(() => {
|
|
110
111
|
const aliveThread = this.instances.get(threadId);
|
|
111
112
|
if (!aliveThread)
|
|
112
|
-
throw new Error(
|
|
113
|
+
throw new Error(
|
|
114
|
+
`Thread "${threadId}" runtime binding not found. This is a bug in assistant-ui.`,
|
|
115
|
+
);
|
|
113
116
|
|
|
114
117
|
aliveThread.runtime = threadBinding.getState();
|
|
115
118
|
this._notifySubscribers();
|
|
@@ -22,6 +22,18 @@ import { AssistantMessageStream } from "assistant-stream";
|
|
|
22
22
|
import type { ModelContextProvider } from "../../model-context/types";
|
|
23
23
|
import { RuntimeAdapterProvider } from "./RuntimeAdapterProvider";
|
|
24
24
|
|
|
25
|
+
const threadNotFoundError = (threadIdOrRemoteId: string, action: string) =>
|
|
26
|
+
new Error(`Thread "${threadIdOrRemoteId}" not found while ${action}.`);
|
|
27
|
+
|
|
28
|
+
const threadStatusError = (
|
|
29
|
+
threadIdOrRemoteId: string,
|
|
30
|
+
status: RemoteThreadData["status"],
|
|
31
|
+
action: string,
|
|
32
|
+
) =>
|
|
33
|
+
new Error(
|
|
34
|
+
`Thread "${threadIdOrRemoteId}" has status "${status}", so it cannot ${action}.`,
|
|
35
|
+
);
|
|
36
|
+
|
|
25
37
|
export class RemoteThreadListThreadListRuntimeCore
|
|
26
38
|
extends BaseSubscribable
|
|
27
39
|
implements ThreadListRuntimeCore
|
|
@@ -32,6 +44,8 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
32
44
|
private _loadThreadsPromise: Promise<void> | undefined;
|
|
33
45
|
private _loadMorePromise: Promise<void> | undefined;
|
|
34
46
|
private _loadGeneration = 0;
|
|
47
|
+
private _switchGeneration = 0;
|
|
48
|
+
private _switchTask: Promise<void> | undefined;
|
|
35
49
|
|
|
36
50
|
private _mainThreadId!: string;
|
|
37
51
|
private readonly _state = new OptimisticState<RemoteThreadState>({
|
|
@@ -280,10 +294,14 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
280
294
|
|
|
281
295
|
public getThreadRuntimeCore(threadIdOrRemoteId: string) {
|
|
282
296
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
283
|
-
if (!data)
|
|
297
|
+
if (!data)
|
|
298
|
+
throw threadNotFoundError(threadIdOrRemoteId, "getting its runtime");
|
|
284
299
|
|
|
285
300
|
const result = this._hookManager.getThreadRuntimeCore(data.id);
|
|
286
|
-
if (!result)
|
|
301
|
+
if (!result)
|
|
302
|
+
throw new Error(
|
|
303
|
+
`Runtime for thread "${threadIdOrRemoteId}" not found while getting its runtime.`,
|
|
304
|
+
);
|
|
287
305
|
return result;
|
|
288
306
|
}
|
|
289
307
|
|
|
@@ -291,15 +309,28 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
291
309
|
return getThreadData(this._state.value, threadIdOrRemoteId);
|
|
292
310
|
}
|
|
293
311
|
|
|
294
|
-
public
|
|
312
|
+
public switchToThread(
|
|
295
313
|
threadIdOrRemoteId: string,
|
|
296
314
|
options?: { unarchive?: boolean },
|
|
315
|
+
): Promise<void> {
|
|
316
|
+
const generation = ++this._switchGeneration;
|
|
317
|
+
const task = this._switchToThread(threadIdOrRemoteId, options, generation);
|
|
318
|
+
this._switchTask = task;
|
|
319
|
+
return task;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
private async _switchToThread(
|
|
323
|
+
threadIdOrRemoteId: string,
|
|
324
|
+
options: { unarchive?: boolean } | undefined,
|
|
325
|
+
generation: number,
|
|
297
326
|
): Promise<void> {
|
|
298
327
|
let data = this.getItemById(threadIdOrRemoteId);
|
|
299
328
|
|
|
300
329
|
if (!data) {
|
|
301
330
|
const remoteMetadata =
|
|
302
331
|
await this._options.adapter.fetch(threadIdOrRemoteId);
|
|
332
|
+
if (generation !== this._switchGeneration) return;
|
|
333
|
+
|
|
303
334
|
const state = this._state.value;
|
|
304
335
|
const mappingId = createThreadMappingId(remoteMetadata.remoteId);
|
|
305
336
|
|
|
@@ -354,7 +385,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
354
385
|
data = this.getItemById(threadIdOrRemoteId);
|
|
355
386
|
}
|
|
356
387
|
|
|
357
|
-
if (!data) throw
|
|
388
|
+
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "switching to it");
|
|
358
389
|
if (this._mainThreadId === data.id) return;
|
|
359
390
|
|
|
360
391
|
const task = this._hookManager.startThreadRuntime(data.id);
|
|
@@ -364,8 +395,11 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
364
395
|
task.then(() => this._notifySubscribers());
|
|
365
396
|
}
|
|
366
397
|
|
|
398
|
+
if (generation !== this._switchGeneration) return;
|
|
399
|
+
|
|
367
400
|
if (data.status === "archived" && options?.unarchive !== false) {
|
|
368
401
|
await this.unarchive(data.id);
|
|
402
|
+
if (generation !== this._switchGeneration) return;
|
|
369
403
|
}
|
|
370
404
|
this._mainThreadId = data.id;
|
|
371
405
|
|
|
@@ -373,13 +407,21 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
373
407
|
this._notifyThreadIdChange();
|
|
374
408
|
}
|
|
375
409
|
|
|
376
|
-
public
|
|
410
|
+
public switchToNewThread(): Promise<void> {
|
|
411
|
+
const generation = ++this._switchGeneration;
|
|
412
|
+
const task = this._switchToNewThread(generation);
|
|
413
|
+
this._switchTask = task;
|
|
414
|
+
return task;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
private async _switchToNewThread(generation: number): Promise<void> {
|
|
377
418
|
// an initialization transaction is in progress, wait for it to settle
|
|
378
419
|
while (
|
|
379
420
|
this._state.baseValue.newThreadId !== undefined &&
|
|
380
421
|
this._state.value.newThreadId === undefined
|
|
381
422
|
) {
|
|
382
423
|
await this._state.waitForUpdate();
|
|
424
|
+
if (generation !== this._switchGeneration) return;
|
|
383
425
|
}
|
|
384
426
|
|
|
385
427
|
const state = this._state.value;
|
|
@@ -411,18 +453,20 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
411
453
|
});
|
|
412
454
|
}
|
|
413
455
|
|
|
414
|
-
return this.
|
|
456
|
+
return this._switchToThread(id, undefined, generation);
|
|
415
457
|
}
|
|
416
458
|
|
|
417
459
|
public initialize = async (threadId: string) => {
|
|
418
460
|
if (this._state.value.newThreadId !== threadId) {
|
|
419
461
|
const data = this.getItemById(threadId);
|
|
420
|
-
if (!data) throw
|
|
421
|
-
if (data.status === "new")
|
|
422
|
-
|
|
462
|
+
if (!data) throw threadNotFoundError(threadId, "initializing it");
|
|
463
|
+
if (data.status === "new")
|
|
464
|
+
throw threadStatusError(threadId, data.status, "be initialized here");
|
|
465
|
+
const { remoteId, externalId } = await data.initializeTask;
|
|
466
|
+
return { remoteId, externalId };
|
|
423
467
|
}
|
|
424
468
|
|
|
425
|
-
|
|
469
|
+
const { remoteId, externalId } = await this._state.optimisticUpdate({
|
|
426
470
|
execute: () => {
|
|
427
471
|
return this._options.adapter.initialize(threadId);
|
|
428
472
|
},
|
|
@@ -465,12 +509,14 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
465
509
|
};
|
|
466
510
|
},
|
|
467
511
|
});
|
|
512
|
+
return { remoteId, externalId };
|
|
468
513
|
};
|
|
469
514
|
|
|
470
515
|
public generateTitle = async (threadId: string) => {
|
|
471
516
|
const data = this.getItemById(threadId);
|
|
472
|
-
if (!data) throw
|
|
473
|
-
if (data.status === "new")
|
|
517
|
+
if (!data) throw threadNotFoundError(threadId, "generating its title");
|
|
518
|
+
if (data.status === "new")
|
|
519
|
+
throw threadStatusError(threadId, data.status, "generate a title");
|
|
474
520
|
|
|
475
521
|
const { remoteId } = await data.initializeTask;
|
|
476
522
|
|
|
@@ -503,8 +549,9 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
503
549
|
|
|
504
550
|
public rename(threadIdOrRemoteId: string, newTitle: string): Promise<void> {
|
|
505
551
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
506
|
-
if (!data) throw
|
|
507
|
-
if (data.status === "new")
|
|
552
|
+
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "renaming it");
|
|
553
|
+
if (data.status === "new")
|
|
554
|
+
throw threadStatusError(threadIdOrRemoteId, data.status, "be renamed");
|
|
508
555
|
|
|
509
556
|
return this._state.optimisticUpdate({
|
|
510
557
|
execute: async () => {
|
|
@@ -534,8 +581,17 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
534
581
|
custom: Record<string, unknown> | undefined,
|
|
535
582
|
): Promise<void> {
|
|
536
583
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
537
|
-
if (!data)
|
|
538
|
-
|
|
584
|
+
if (!data)
|
|
585
|
+
throw threadNotFoundError(
|
|
586
|
+
threadIdOrRemoteId,
|
|
587
|
+
"updating its custom metadata",
|
|
588
|
+
);
|
|
589
|
+
if (data.status === "new")
|
|
590
|
+
throw threadStatusError(
|
|
591
|
+
threadIdOrRemoteId,
|
|
592
|
+
data.status,
|
|
593
|
+
"update custom metadata",
|
|
594
|
+
);
|
|
539
595
|
|
|
540
596
|
if (!this._options.adapter.updateCustom) {
|
|
541
597
|
throw new Error(
|
|
@@ -576,16 +632,29 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
576
632
|
if (threadId === this.newThreadId)
|
|
577
633
|
throw new Error("Cannot ensure new thread is not main");
|
|
578
634
|
|
|
579
|
-
|
|
580
|
-
|
|
635
|
+
let lastAwaitedTask: Promise<void> | undefined;
|
|
636
|
+
|
|
637
|
+
while (threadId === this._mainThreadId) {
|
|
638
|
+
let switchTask = this._switchTask;
|
|
639
|
+
const startedFallback = !switchTask || switchTask === lastAwaitedTask;
|
|
640
|
+
if (startedFallback) switchTask = this.switchToNewThread();
|
|
641
|
+
lastAwaitedTask = switchTask;
|
|
642
|
+
|
|
643
|
+
try {
|
|
644
|
+
await switchTask;
|
|
645
|
+
} catch (error) {
|
|
646
|
+
if (startedFallback && this._switchTask === switchTask) {
|
|
647
|
+
throw error;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
581
650
|
}
|
|
582
651
|
}
|
|
583
652
|
|
|
584
653
|
public async archive(threadIdOrRemoteId: string) {
|
|
585
654
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
586
|
-
if (!data) throw
|
|
655
|
+
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "archiving it");
|
|
587
656
|
if (data.status !== "regular")
|
|
588
|
-
throw
|
|
657
|
+
throw threadStatusError(threadIdOrRemoteId, data.status, "be archived");
|
|
589
658
|
|
|
590
659
|
await this._ensureThreadIsNotMain(data.id);
|
|
591
660
|
|
|
@@ -602,8 +671,9 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
602
671
|
|
|
603
672
|
public unarchive(threadIdOrRemoteId: string): Promise<void> {
|
|
604
673
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
605
|
-
if (!data) throw
|
|
606
|
-
if (data.status !== "archived")
|
|
674
|
+
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "unarchiving it");
|
|
675
|
+
if (data.status !== "archived")
|
|
676
|
+
throw threadStatusError(threadIdOrRemoteId, data.status, "be unarchived");
|
|
607
677
|
|
|
608
678
|
return this._state.optimisticUpdate({
|
|
609
679
|
execute: async () => {
|
|
@@ -623,9 +693,9 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
623
693
|
|
|
624
694
|
public async delete(threadIdOrRemoteId: string) {
|
|
625
695
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
626
|
-
if (!data) throw
|
|
696
|
+
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "deleting it");
|
|
627
697
|
if (data.status !== "regular" && data.status !== "archived")
|
|
628
|
-
throw
|
|
698
|
+
throw threadStatusError(threadIdOrRemoteId, data.status, "be deleted");
|
|
629
699
|
|
|
630
700
|
await this._ensureThreadIsNotMain(data.id);
|
|
631
701
|
this._hookManager.stopThreadRuntime(data.id);
|
|
@@ -643,9 +713,9 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
643
713
|
|
|
644
714
|
public async detach(threadIdOrRemoteId: string): Promise<void> {
|
|
645
715
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
646
|
-
if (!data) throw
|
|
716
|
+
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "detaching it");
|
|
647
717
|
if (data.status !== "regular" && data.status !== "archived")
|
|
648
|
-
throw
|
|
718
|
+
throw threadStatusError(threadIdOrRemoteId, data.status, "be detached");
|
|
649
719
|
|
|
650
720
|
await this._ensureThreadIsNotMain(data.id);
|
|
651
721
|
this._hookManager.stopThreadRuntime(data.id);
|