@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { LocalRuntimeCore } from "./local-runtime-core";
|
|
3
3
|
import type {
|
|
4
4
|
ChatModelAdapter,
|
|
@@ -6,13 +6,28 @@ import type {
|
|
|
6
6
|
ChatModelRunResult,
|
|
7
7
|
} from "../../runtime/utils/chat-model-adapter";
|
|
8
8
|
import type { AppendMessage } from "../../types/message";
|
|
9
|
+
import type { LocalRuntimeOptionsBase } from "./local-runtime-options";
|
|
9
10
|
|
|
10
11
|
const flush = () => new Promise((resolve) => setTimeout(resolve, 10));
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.restoreAllMocks();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const createThread = (
|
|
18
|
+
adapter: ChatModelAdapter,
|
|
19
|
+
options?: {
|
|
20
|
+
suggestion?: LocalRuntimeOptionsBase["adapters"]["suggestion"];
|
|
21
|
+
},
|
|
22
|
+
) => {
|
|
13
23
|
const core = new LocalRuntimeCore(
|
|
14
24
|
{
|
|
15
|
-
adapters: {
|
|
25
|
+
adapters: {
|
|
26
|
+
chatModel: adapter,
|
|
27
|
+
...(options?.suggestion !== undefined && {
|
|
28
|
+
suggestion: options.suggestion,
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
16
31
|
unstable_humanToolNames: ["send_email"],
|
|
17
32
|
},
|
|
18
33
|
undefined,
|
|
@@ -63,6 +78,64 @@ const createApprovalThread = (firstResult: ChatModelRunResult) => {
|
|
|
63
78
|
return { thread, runs };
|
|
64
79
|
};
|
|
65
80
|
|
|
81
|
+
describe("LocalThreadRuntimeCore events", () => {
|
|
82
|
+
it("isolates runEnd listener errors", async () => {
|
|
83
|
+
const listenerError = new Error("telemetry failed");
|
|
84
|
+
const consoleError = vi
|
|
85
|
+
.spyOn(console, "error")
|
|
86
|
+
.mockImplementation(() => {});
|
|
87
|
+
const laterListener = vi.fn();
|
|
88
|
+
const thread = createThread({
|
|
89
|
+
async run() {
|
|
90
|
+
return { content: [{ type: "text", text: "done" }] };
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
thread.unstable_on("runEnd", () => {
|
|
95
|
+
throw listenerError;
|
|
96
|
+
});
|
|
97
|
+
thread.unstable_on("runEnd", laterListener);
|
|
98
|
+
|
|
99
|
+
await expect(thread.append(userMessage("hello"))).resolves.toBeUndefined();
|
|
100
|
+
|
|
101
|
+
expect(laterListener).toHaveBeenCalledOnce();
|
|
102
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
103
|
+
expect(consoleError).toHaveBeenCalledWith(
|
|
104
|
+
'[assistant-ui] Thread runtime "runEnd" listener threw an error',
|
|
105
|
+
listenerError,
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("isolates async runEnd listener rejections", async () => {
|
|
110
|
+
const listenerError = new Error("async telemetry failed");
|
|
111
|
+
const consoleError = vi
|
|
112
|
+
.spyOn(console, "error")
|
|
113
|
+
.mockImplementation(() => {});
|
|
114
|
+
const laterListener = vi.fn();
|
|
115
|
+
const thread = createThread({
|
|
116
|
+
async run() {
|
|
117
|
+
return { content: [{ type: "text", text: "done" }] };
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
thread.unstable_on("runEnd", async () => {
|
|
122
|
+
throw listenerError;
|
|
123
|
+
});
|
|
124
|
+
thread.unstable_on("runEnd", laterListener);
|
|
125
|
+
|
|
126
|
+
await expect(thread.append(userMessage("hello"))).resolves.toBeUndefined();
|
|
127
|
+
|
|
128
|
+
expect(laterListener).toHaveBeenCalledOnce();
|
|
129
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
130
|
+
await vi.waitFor(() => {
|
|
131
|
+
expect(consoleError).toHaveBeenCalledWith(
|
|
132
|
+
'[assistant-ui] Thread runtime "runEnd" listener threw an error',
|
|
133
|
+
listenerError,
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
66
139
|
describe("LocalThreadRuntimeCore human-in-the-loop tools", () => {
|
|
67
140
|
it("pauses on requires-action while a listed tool call has no result", async () => {
|
|
68
141
|
const { thread, runs } = createApprovalThread(toolCallResult("send_email"));
|
|
@@ -117,6 +190,53 @@ describe("LocalThreadRuntimeCore human-in-the-loop tools", () => {
|
|
|
117
190
|
"text",
|
|
118
191
|
]);
|
|
119
192
|
});
|
|
193
|
+
|
|
194
|
+
it.each([
|
|
195
|
+
["false", false],
|
|
196
|
+
["zero", 0],
|
|
197
|
+
["an empty string", ""],
|
|
198
|
+
["null", null],
|
|
199
|
+
])("resumes when the tool result is %s", async (_label, result) => {
|
|
200
|
+
const { thread, runs } = createApprovalThread(toolCallResult("send_email"));
|
|
201
|
+
|
|
202
|
+
await thread.append(userMessage("send an email"));
|
|
203
|
+
await flush();
|
|
204
|
+
|
|
205
|
+
thread.addToolResult({
|
|
206
|
+
messageId: thread.messages.at(-1)!.id,
|
|
207
|
+
toolCallId: "call-send_email",
|
|
208
|
+
toolName: "send_email",
|
|
209
|
+
result,
|
|
210
|
+
isError: false,
|
|
211
|
+
});
|
|
212
|
+
await flush();
|
|
213
|
+
|
|
214
|
+
expect(runs).toHaveLength(2);
|
|
215
|
+
const toolCall = runs[1]!
|
|
216
|
+
.unstable_getMessage()
|
|
217
|
+
.content.find((part) => part.type === "tool-call");
|
|
218
|
+
expect(toolCall?.result).toEqual(result);
|
|
219
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
describe("LocalThreadRuntimeCore state", () => {
|
|
224
|
+
it.each([
|
|
225
|
+
["false", false],
|
|
226
|
+
["zero", 0],
|
|
227
|
+
["an empty string", ""],
|
|
228
|
+
])("preserves %s model state", async (_label, state) => {
|
|
229
|
+
const thread = createThread({
|
|
230
|
+
async run() {
|
|
231
|
+
return { metadata: { unstable_state: state } };
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
await thread.append(userMessage("update state"));
|
|
236
|
+
await flush();
|
|
237
|
+
|
|
238
|
+
expect(thread.messages.at(-1)?.metadata.unstable_state).toBe(state);
|
|
239
|
+
});
|
|
120
240
|
});
|
|
121
241
|
|
|
122
242
|
describe("LocalThreadRuntimeCore tool approvals", () => {
|
|
@@ -368,3 +488,156 @@ describe("LocalThreadRuntimeCore tool approvals", () => {
|
|
|
368
488
|
).toThrowError(/unstable_humanToolNames/);
|
|
369
489
|
});
|
|
370
490
|
});
|
|
491
|
+
|
|
492
|
+
describe("LocalThreadRuntimeCore cancellation", () => {
|
|
493
|
+
it("marks the message cancelled when a streaming adapter returns after abort", async () => {
|
|
494
|
+
let released!: () => void;
|
|
495
|
+
const streaming = new Promise<void>((resolve) => {
|
|
496
|
+
released = resolve;
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
const thread = createThread({
|
|
500
|
+
async *run({ abortSignal }) {
|
|
501
|
+
yield { content: [{ type: "text", text: "partial" }] };
|
|
502
|
+
await streaming;
|
|
503
|
+
if (abortSignal.aborted) return;
|
|
504
|
+
yield { content: [{ type: "text", text: "partial answer" }] };
|
|
505
|
+
},
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
const appendPromise = thread.append(userMessage("hi"));
|
|
509
|
+
await flush();
|
|
510
|
+
|
|
511
|
+
thread.cancelRun();
|
|
512
|
+
released();
|
|
513
|
+
await appendPromise;
|
|
514
|
+
|
|
515
|
+
expect(thread.messages.at(-1)?.status).toEqual({
|
|
516
|
+
type: "incomplete",
|
|
517
|
+
reason: "cancelled",
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it("marks the message cancelled when a non-streaming adapter resolves after abort", async () => {
|
|
522
|
+
let released!: () => void;
|
|
523
|
+
const pending = new Promise<void>((resolve) => {
|
|
524
|
+
released = resolve;
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
const thread = createThread({
|
|
528
|
+
async run() {
|
|
529
|
+
await pending;
|
|
530
|
+
return { content: [{ type: "text", text: "hello" }] };
|
|
531
|
+
},
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
const appendPromise = thread.append(userMessage("hi"));
|
|
535
|
+
await flush();
|
|
536
|
+
|
|
537
|
+
thread.cancelRun();
|
|
538
|
+
released();
|
|
539
|
+
await appendPromise;
|
|
540
|
+
|
|
541
|
+
expect(thread.messages.at(-1)?.status).toEqual({
|
|
542
|
+
type: "incomplete",
|
|
543
|
+
reason: "cancelled",
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
it("keeps a completed run complete", async () => {
|
|
548
|
+
const thread = createThread({
|
|
549
|
+
async *run() {
|
|
550
|
+
yield { content: [{ type: "text", text: "hello" }] };
|
|
551
|
+
},
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
await thread.append(userMessage("hi"));
|
|
555
|
+
|
|
556
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
describe("LocalThreadRuntimeCore suggestions", () => {
|
|
561
|
+
it("cancelRun aborts pending suggestion generation", async () => {
|
|
562
|
+
const generate = vi.fn().mockImplementation(
|
|
563
|
+
({ signal }: { signal?: AbortSignal }) =>
|
|
564
|
+
new Promise<readonly { prompt: string }[]>((resolve) => {
|
|
565
|
+
signal?.addEventListener("abort", () => {
|
|
566
|
+
resolve([{ prompt: "stale" }]);
|
|
567
|
+
});
|
|
568
|
+
}),
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
const thread = createThread(
|
|
572
|
+
{
|
|
573
|
+
async run() {
|
|
574
|
+
return { content: [{ type: "text", text: "hello" }] };
|
|
575
|
+
},
|
|
576
|
+
},
|
|
577
|
+
{ suggestion: { generate } },
|
|
578
|
+
);
|
|
579
|
+
|
|
580
|
+
const appendPromise = thread.append(userMessage("hi"));
|
|
581
|
+
await appendPromise;
|
|
582
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
583
|
+
|
|
584
|
+
expect(generate).toHaveBeenCalledTimes(1);
|
|
585
|
+
const signal = generate.mock.calls[0]![0].signal as AbortSignal;
|
|
586
|
+
expect(signal.aborted).toBe(false);
|
|
587
|
+
|
|
588
|
+
thread.cancelRun();
|
|
589
|
+
expect(signal.aborted).toBe(true);
|
|
590
|
+
expect(thread.suggestions).toEqual([]);
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
it("completes the run when suggestion generation rejects", async () => {
|
|
594
|
+
const generate = vi.fn().mockRejectedValue(new Error("suggestion failed"));
|
|
595
|
+
|
|
596
|
+
const thread = createThread(
|
|
597
|
+
{
|
|
598
|
+
async run() {
|
|
599
|
+
return { content: [{ type: "text", text: "hello" }] };
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
{ suggestion: { generate } },
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
await thread.append(userMessage("hi"));
|
|
606
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
607
|
+
|
|
608
|
+
expect(generate).toHaveBeenCalledTimes(1);
|
|
609
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
610
|
+
expect(thread.suggestions).toEqual([]);
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it("resolves append before suggestion generation completes", async () => {
|
|
614
|
+
let resolveSuggestions!: (value: readonly { prompt: string }[]) => void;
|
|
615
|
+
const suggestionsDeferred = new Promise<readonly { prompt: string }[]>(
|
|
616
|
+
(resolve) => {
|
|
617
|
+
resolveSuggestions = resolve;
|
|
618
|
+
},
|
|
619
|
+
);
|
|
620
|
+
const generate = vi.fn().mockReturnValue(suggestionsDeferred);
|
|
621
|
+
|
|
622
|
+
const thread = createThread(
|
|
623
|
+
{
|
|
624
|
+
async run() {
|
|
625
|
+
return { content: [{ type: "text", text: "hello" }] };
|
|
626
|
+
},
|
|
627
|
+
},
|
|
628
|
+
{ suggestion: { generate } },
|
|
629
|
+
);
|
|
630
|
+
|
|
631
|
+
await thread.append(userMessage("hi"));
|
|
632
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
633
|
+
expect(thread.suggestions).toEqual([]);
|
|
634
|
+
|
|
635
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
636
|
+
expect(generate).toHaveBeenCalledTimes(1);
|
|
637
|
+
expect(thread.suggestions).toEqual([]);
|
|
638
|
+
|
|
639
|
+
resolveSuggestions([{ prompt: "follow up" }]);
|
|
640
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
641
|
+
expect(thread.suggestions).toEqual([{ prompt: "follow up" }]);
|
|
642
|
+
});
|
|
643
|
+
});
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
} from "../../runtime/utils/chat-model-adapter";
|
|
7
7
|
import { shouldContinue } from "./should-continue";
|
|
8
8
|
import type { LocalRuntimeOptionsBase } from "./local-runtime-options";
|
|
9
|
+
import { consumeSuggestionResult } from "../../adapters/suggestion";
|
|
9
10
|
import type {
|
|
10
11
|
AddToolResultOptions,
|
|
11
12
|
ResumeToolCallOptions,
|
|
@@ -21,6 +22,7 @@ import type {
|
|
|
21
22
|
ThreadAssistantMessage,
|
|
22
23
|
} from "../../types/message";
|
|
23
24
|
import type { RunConfig } from "../../types/message";
|
|
25
|
+
import { toAssistantError } from "../../types/error";
|
|
24
26
|
import type { ModelContextProvider } from "../../model-context/types";
|
|
25
27
|
import {
|
|
26
28
|
createMessageQueue,
|
|
@@ -375,28 +377,28 @@ export class LocalThreadRuntimeCore
|
|
|
375
377
|
}
|
|
376
378
|
}
|
|
377
379
|
|
|
378
|
-
this._suggestionsController = new AbortController();
|
|
379
|
-
const signal = this._suggestionsController.signal;
|
|
380
380
|
if (
|
|
381
381
|
this.adapters.suggestion &&
|
|
382
382
|
message.status?.type !== "requires-action"
|
|
383
383
|
) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
384
|
+
this._suggestionsController = new AbortController();
|
|
385
|
+
const signal = this._suggestionsController.signal;
|
|
386
|
+
const adapter = this.adapters.suggestion;
|
|
387
|
+
void (async () => {
|
|
388
|
+
try {
|
|
389
|
+
const promiseOrGenerator = adapter.generate({
|
|
390
|
+
messages: this.messages,
|
|
391
|
+
signal,
|
|
392
|
+
});
|
|
393
|
+
await consumeSuggestionResult(promiseOrGenerator, {
|
|
394
|
+
signal,
|
|
395
|
+
onUpdate: (r) => {
|
|
396
|
+
this._suggestions = r;
|
|
397
|
+
this._notifySubscribers();
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
} catch {}
|
|
401
|
+
})();
|
|
400
402
|
}
|
|
401
403
|
}
|
|
402
404
|
|
|
@@ -440,7 +442,7 @@ export class LocalThreadRuntimeCore
|
|
|
440
442
|
? {
|
|
441
443
|
metadata: {
|
|
442
444
|
...message.metadata,
|
|
443
|
-
...(m.metadata.unstable_state
|
|
445
|
+
...(m.metadata.unstable_state !== undefined
|
|
444
446
|
? { unstable_state: m.metadata.unstable_state }
|
|
445
447
|
: undefined),
|
|
446
448
|
...(annotations
|
|
@@ -535,11 +537,12 @@ export class LocalThreadRuntimeCore
|
|
|
535
537
|
|
|
536
538
|
if (message.status.type === "running") {
|
|
537
539
|
updateMessage({
|
|
538
|
-
status:
|
|
540
|
+
status: abortSignal.aborted
|
|
541
|
+
? { type: "incomplete", reason: "cancelled" }
|
|
542
|
+
: { type: "complete", reason: "unknown" },
|
|
539
543
|
});
|
|
540
544
|
}
|
|
541
545
|
} catch (e) {
|
|
542
|
-
// TODO this should be handled by the run result stream
|
|
543
546
|
if (e instanceof AbortError) {
|
|
544
547
|
updateMessage({
|
|
545
548
|
status: { type: "incomplete", reason: "cancelled" },
|
|
@@ -553,10 +556,7 @@ export class LocalThreadRuntimeCore
|
|
|
553
556
|
status: {
|
|
554
557
|
type: "incomplete",
|
|
555
558
|
reason: "error",
|
|
556
|
-
error:
|
|
557
|
-
e instanceof Error
|
|
558
|
-
? e.message
|
|
559
|
-
: `[${typeof e}] ${new String(e).toString()}`,
|
|
559
|
+
error: toAssistantError(e),
|
|
560
560
|
},
|
|
561
561
|
});
|
|
562
562
|
|
|
@@ -584,6 +584,8 @@ export class LocalThreadRuntimeCore
|
|
|
584
584
|
const error = new AbortError(true);
|
|
585
585
|
this.abortController?.abort(error);
|
|
586
586
|
this.abortController = null;
|
|
587
|
+
this._suggestionsController?.abort();
|
|
588
|
+
this._suggestionsController = null;
|
|
587
589
|
}
|
|
588
590
|
|
|
589
591
|
public cancelRun() {
|
|
@@ -591,6 +593,8 @@ export class LocalThreadRuntimeCore
|
|
|
591
593
|
const error = new AbortError(false);
|
|
592
594
|
this.abortController?.abort(error);
|
|
593
595
|
this.abortController = null;
|
|
596
|
+
this._suggestionsController?.abort();
|
|
597
|
+
this._suggestionsController = null;
|
|
594
598
|
}
|
|
595
599
|
|
|
596
600
|
public addToolResult({
|
|
@@ -23,14 +23,17 @@ export const shouldContinue = (
|
|
|
23
23
|
// TODO legacy behavior -- make specifying human tool names required
|
|
24
24
|
if (humanToolNames === undefined) {
|
|
25
25
|
return result.content.every(
|
|
26
|
-
(c) =>
|
|
26
|
+
(c) =>
|
|
27
|
+
c.type !== "tool-call" ||
|
|
28
|
+
c.result !== undefined ||
|
|
29
|
+
c.approval !== undefined,
|
|
27
30
|
);
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
return result.content.every(
|
|
31
34
|
(c) =>
|
|
32
35
|
c.type !== "tool-call" ||
|
|
33
|
-
|
|
36
|
+
c.result !== undefined ||
|
|
34
37
|
c.approval !== undefined ||
|
|
35
38
|
!humanToolNames.includes(c.toolName),
|
|
36
39
|
);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { InMemoryThreadListAdapter } from "./in-memory";
|
|
3
|
+
|
|
4
|
+
describe("InMemoryThreadListAdapter", () => {
|
|
5
|
+
it("closes its title stream when title generation is unsupported", async () => {
|
|
6
|
+
const adapter = new InMemoryThreadListAdapter();
|
|
7
|
+
const stream = await adapter.generateTitle();
|
|
8
|
+
|
|
9
|
+
await expect(stream.getReader().read()).resolves.toEqual({
|
|
10
|
+
done: true,
|
|
11
|
+
value: undefined,
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -38,10 +38,18 @@ export class InMemoryThreadListAdapter implements RemoteThreadListAdapter {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
generateTitle(): Promise<AssistantStream> {
|
|
41
|
-
return Promise.resolve(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
return Promise.resolve(
|
|
42
|
+
new ReadableStream<AssistantStreamChunk>({
|
|
43
|
+
start(controller) {
|
|
44
|
+
controller.close();
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fetch(threadId: string): Promise<RemoteThreadMetadata> {
|
|
51
|
+
return Promise.reject(
|
|
52
|
+
new Error(`Thread "${threadId}" not found in in-memory thread list.`),
|
|
53
|
+
);
|
|
46
54
|
}
|
|
47
55
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { OptimisticState } from "./optimistic-state";
|
|
3
|
+
|
|
4
|
+
const deferred = () => {
|
|
5
|
+
let resolve!: () => void;
|
|
6
|
+
const promise = new Promise<void>((resolvePromise) => {
|
|
7
|
+
resolve = resolvePromise;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
return { promise, resolve };
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
describe("OptimisticState", () => {
|
|
14
|
+
it("preserves invocation order when optimistic updates resolve in order", async () => {
|
|
15
|
+
const state = new OptimisticState({ title: "Untitled" });
|
|
16
|
+
const firstRequest = deferred();
|
|
17
|
+
const secondRequest = deferred();
|
|
18
|
+
|
|
19
|
+
const firstUpdate = state.optimisticUpdate({
|
|
20
|
+
execute: () => firstRequest.promise,
|
|
21
|
+
optimistic: (value) => ({ ...value, title: "Project Alpha" }),
|
|
22
|
+
});
|
|
23
|
+
const secondUpdate = state.optimisticUpdate({
|
|
24
|
+
execute: () => secondRequest.promise,
|
|
25
|
+
optimistic: (value) => ({ ...value, title: "Project Beta" }),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(state.value.title).toBe("Project Beta");
|
|
29
|
+
|
|
30
|
+
firstRequest.resolve();
|
|
31
|
+
await firstUpdate;
|
|
32
|
+
expect(state.value.title).toBe("Project Beta");
|
|
33
|
+
|
|
34
|
+
secondRequest.resolve();
|
|
35
|
+
await secondUpdate;
|
|
36
|
+
|
|
37
|
+
expect(state.value.title).toBe("Project Beta");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("preserves invocation order when optimistic updates resolve out of order", async () => {
|
|
41
|
+
const state = new OptimisticState({ title: "Untitled" });
|
|
42
|
+
const firstRequest = deferred();
|
|
43
|
+
const secondRequest = deferred();
|
|
44
|
+
|
|
45
|
+
const firstUpdate = state.optimisticUpdate({
|
|
46
|
+
execute: () => firstRequest.promise,
|
|
47
|
+
optimistic: (value) => ({ ...value, title: "Project Alpha" }),
|
|
48
|
+
});
|
|
49
|
+
const secondUpdate = state.optimisticUpdate({
|
|
50
|
+
execute: () => secondRequest.promise,
|
|
51
|
+
optimistic: (value) => ({ ...value, title: "Project Beta" }),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
secondRequest.resolve();
|
|
55
|
+
await secondUpdate;
|
|
56
|
+
expect(state.value.title).toBe("Project Beta");
|
|
57
|
+
|
|
58
|
+
firstRequest.resolve();
|
|
59
|
+
await firstUpdate;
|
|
60
|
+
|
|
61
|
+
expect(state.value.title).toBe("Project Beta");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -14,9 +14,15 @@ type Transform<TState, TResult> = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
type PendingTransform<TState, TResult> = Transform<TState, TResult> & {
|
|
17
|
+
order: number;
|
|
17
18
|
task: Promise<TResult>;
|
|
18
19
|
};
|
|
19
20
|
|
|
21
|
+
type CompletedOptimistic<TState> = {
|
|
22
|
+
order: number;
|
|
23
|
+
optimistic: (state: TState) => TState;
|
|
24
|
+
};
|
|
25
|
+
|
|
20
26
|
const pipeTransforms = <TState, TExtra>(
|
|
21
27
|
initialState: TState,
|
|
22
28
|
extraParam: TExtra,
|
|
@@ -32,14 +38,16 @@ export class OptimisticState<TState> extends BaseSubscribable {
|
|
|
32
38
|
[];
|
|
33
39
|
|
|
34
40
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* (e.g. delete). Cleared when no pending transforms remain.
|
|
41
|
+
* Completed optimistic callbacks remain active while any transform is
|
|
42
|
+
* pending, so later state replacements cannot erase them. Invocation order
|
|
43
|
+
* determines which overlapping optimistic update wins.
|
|
39
44
|
*
|
|
40
45
|
* Correctness requirement: `optimistic` callbacks must be idempotent.
|
|
41
46
|
*/
|
|
42
|
-
private readonly _completedOptimistics: Array<
|
|
47
|
+
private readonly _completedOptimistics: Array<CompletedOptimistic<TState>> =
|
|
48
|
+
[];
|
|
49
|
+
|
|
50
|
+
private _nextTransformOrder = 0;
|
|
43
51
|
|
|
44
52
|
private _baseValue: TState;
|
|
45
53
|
private _cachedValue: TState;
|
|
@@ -51,12 +59,25 @@ export class OptimisticState<TState> extends BaseSubscribable {
|
|
|
51
59
|
}
|
|
52
60
|
|
|
53
61
|
private _updateState(): void {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
transform.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
const activeTransforms = [
|
|
63
|
+
...this._pendingTransforms.map((transform) => ({
|
|
64
|
+
order: transform.order,
|
|
65
|
+
apply: (state: TState) =>
|
|
66
|
+
pipeTransforms(state, transform.task, [
|
|
67
|
+
transform.loading,
|
|
68
|
+
transform.optimistic,
|
|
69
|
+
]),
|
|
70
|
+
})),
|
|
71
|
+
...this._completedOptimistics.map(({ order, optimistic }) => ({
|
|
72
|
+
order,
|
|
73
|
+
apply: optimistic,
|
|
74
|
+
})),
|
|
75
|
+
].sort((a, b) => a.order - b.order);
|
|
76
|
+
|
|
77
|
+
this._cachedValue = activeTransforms.reduce(
|
|
78
|
+
(state, transform) => transform.apply(state),
|
|
79
|
+
this._baseValue,
|
|
80
|
+
);
|
|
60
81
|
|
|
61
82
|
this._notifySubscribers();
|
|
62
83
|
}
|
|
@@ -77,8 +98,13 @@ export class OptimisticState<TState> extends BaseSubscribable {
|
|
|
77
98
|
public async optimisticUpdate<TResult>(
|
|
78
99
|
transform: Transform<TState, TResult>,
|
|
79
100
|
): Promise<TResult> {
|
|
101
|
+
const order = this._nextTransformOrder++;
|
|
80
102
|
const task = transform.execute();
|
|
81
|
-
const pendingTransform = {
|
|
103
|
+
const pendingTransform = {
|
|
104
|
+
...transform,
|
|
105
|
+
order,
|
|
106
|
+
task,
|
|
107
|
+
};
|
|
82
108
|
try {
|
|
83
109
|
this._pendingTransforms.push(pendingTransform);
|
|
84
110
|
this._updateState();
|
|
@@ -89,14 +115,20 @@ export class OptimisticState<TState> extends BaseSubscribable {
|
|
|
89
115
|
transform.then,
|
|
90
116
|
]);
|
|
91
117
|
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
for (const
|
|
95
|
-
|
|
118
|
+
// `then` can replace state with a stale snapshot, so replay every
|
|
119
|
+
// completed effect; otherwise replay only newer overlapping effects.
|
|
120
|
+
for (const completed of this._completedOptimistics) {
|
|
121
|
+
if (transform.then || completed.order > pendingTransform.order) {
|
|
122
|
+
this._baseValue = completed.optimistic(this._baseValue);
|
|
123
|
+
}
|
|
96
124
|
}
|
|
97
125
|
|
|
98
126
|
if (transform.optimistic) {
|
|
99
|
-
this._completedOptimistics.push(
|
|
127
|
+
this._completedOptimistics.push({
|
|
128
|
+
order: pendingTransform.order,
|
|
129
|
+
optimistic: transform.optimistic,
|
|
130
|
+
});
|
|
131
|
+
this._completedOptimistics.sort((a, b) => a.order - b.order);
|
|
100
132
|
}
|
|
101
133
|
|
|
102
134
|
return result;
|