@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,69 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { renderHook } from "@testing-library/react";
|
|
4
|
+
import type { AssistantCloud } from "assistant-cloud";
|
|
5
|
+
import { describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { useAssistantCloudThreadHistoryAdapter } from "./AssistantCloudThreadHistoryAdapter";
|
|
7
|
+
|
|
8
|
+
const mocks = vi.hoisted(() => {
|
|
9
|
+
const threadListItem = {
|
|
10
|
+
getState: () => ({ remoteId: "thread-1" }),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
assistantClient: {
|
|
15
|
+
threadListItem: () => threadListItem,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
vi.mock("@assistant-ui/store", async (importOriginal) => ({
|
|
21
|
+
...(await importOriginal<typeof import("@assistant-ui/store")>()),
|
|
22
|
+
useAui: () => mocks.assistantClient,
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const makeCloud = () =>
|
|
26
|
+
({
|
|
27
|
+
threads: {
|
|
28
|
+
messages: {
|
|
29
|
+
list: vi.fn().mockResolvedValue({ messages: [] }),
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}) as unknown as AssistantCloud;
|
|
33
|
+
|
|
34
|
+
describe("useAssistantCloudThreadHistoryAdapter", () => {
|
|
35
|
+
it("refreshes formatted persistence when the Cloud client changes", async () => {
|
|
36
|
+
const firstCloud = makeCloud();
|
|
37
|
+
const secondCloud = makeCloud();
|
|
38
|
+
const cloudRef = { current: firstCloud };
|
|
39
|
+
const { result } = renderHook(() =>
|
|
40
|
+
useAssistantCloudThreadHistoryAdapter(cloudRef),
|
|
41
|
+
);
|
|
42
|
+
const formatted = result.current.withFormat<
|
|
43
|
+
{ id: string },
|
|
44
|
+
Record<string, unknown>
|
|
45
|
+
>({
|
|
46
|
+
format: "test",
|
|
47
|
+
encode: ({ message }) => message,
|
|
48
|
+
decode: ({ parent_id, content }) => ({
|
|
49
|
+
parentId: parent_id,
|
|
50
|
+
message: content as { id: string },
|
|
51
|
+
}),
|
|
52
|
+
getId: (message) => message.id,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await formatted.load();
|
|
56
|
+
await formatted.load();
|
|
57
|
+
|
|
58
|
+
expect(firstCloud.threads.messages.list).toHaveBeenCalledTimes(2);
|
|
59
|
+
|
|
60
|
+
cloudRef.current = secondCloud;
|
|
61
|
+
await formatted.load();
|
|
62
|
+
|
|
63
|
+
expect(firstCloud.threads.messages.list).toHaveBeenCalledTimes(2);
|
|
64
|
+
expect(secondCloud.threads.messages.list).toHaveBeenCalledOnce();
|
|
65
|
+
expect(secondCloud.threads.messages.list).toHaveBeenCalledWith("thread-1", {
|
|
66
|
+
format: "test",
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -32,7 +32,7 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
|
|
|
32
32
|
if (!globalPersistence.has(key)) {
|
|
33
33
|
globalPersistence.set(
|
|
34
34
|
key,
|
|
35
|
-
new CloudMessagePersistence(this.cloudRef.current),
|
|
35
|
+
new CloudMessagePersistence(() => this.cloudRef.current),
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
return globalPersistence.get(key)!;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import type { AssistantCloud } from "assistant-cloud";
|
|
3
|
+
import type { PendingAttachment } from "../../../types/attachment";
|
|
4
|
+
import { CloudFileAttachmentAdapter } from "./CloudFileAttachmentAdapter";
|
|
5
|
+
|
|
6
|
+
const makeCloud = () =>
|
|
7
|
+
({
|
|
8
|
+
files: {
|
|
9
|
+
generatePresignedUploadUrl: vi.fn().mockResolvedValue({
|
|
10
|
+
signedUrl: "https://storage.example/upload",
|
|
11
|
+
publicUrl: "https://cdn.example/file.png",
|
|
12
|
+
}),
|
|
13
|
+
},
|
|
14
|
+
}) as unknown as AssistantCloud;
|
|
15
|
+
|
|
16
|
+
const makeFile = () =>
|
|
17
|
+
new File([new Uint8Array([1, 2, 3])], "pixel.png", { type: "image/png" });
|
|
18
|
+
|
|
19
|
+
const drain = async (adapter: CloudFileAttachmentAdapter) => {
|
|
20
|
+
const yields: PendingAttachment[] = [];
|
|
21
|
+
for await (const value of adapter.add({ file: makeFile() })) {
|
|
22
|
+
yields.push(value);
|
|
23
|
+
}
|
|
24
|
+
return yields;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe("CloudFileAttachmentAdapter", () => {
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
vi.unstubAllGlobals();
|
|
30
|
+
vi.restoreAllMocks();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("marks the attachment ready when the upload succeeds", async () => {
|
|
34
|
+
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true }));
|
|
35
|
+
const adapter = new CloudFileAttachmentAdapter(makeCloud());
|
|
36
|
+
|
|
37
|
+
const yields = await drain(adapter);
|
|
38
|
+
|
|
39
|
+
expect(yields.at(0)?.status).toEqual({
|
|
40
|
+
type: "running",
|
|
41
|
+
reason: "uploading",
|
|
42
|
+
progress: 0,
|
|
43
|
+
});
|
|
44
|
+
expect(yields.at(-1)?.status).toEqual({
|
|
45
|
+
type: "requires-action",
|
|
46
|
+
reason: "composer-send",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const complete = await adapter.send(yields.at(-1)!);
|
|
50
|
+
expect(complete.status).toEqual({ type: "complete" });
|
|
51
|
+
expect(complete.content).toEqual([
|
|
52
|
+
{
|
|
53
|
+
type: "image",
|
|
54
|
+
image: "https://cdn.example/file.png",
|
|
55
|
+
filename: "pixel.png",
|
|
56
|
+
},
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("uploads when Web Crypto is unavailable", async () => {
|
|
61
|
+
vi.stubGlobal("crypto", undefined);
|
|
62
|
+
vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true }));
|
|
63
|
+
const adapter = new CloudFileAttachmentAdapter(makeCloud());
|
|
64
|
+
|
|
65
|
+
const yields = await drain(adapter);
|
|
66
|
+
|
|
67
|
+
expect(yields).toHaveLength(2);
|
|
68
|
+
expect(yields[0]?.id).toBeTruthy();
|
|
69
|
+
expect(yields[1]?.id).toBe(yields[0]?.id);
|
|
70
|
+
expect(yields.at(-1)?.status).toEqual({
|
|
71
|
+
type: "requires-action",
|
|
72
|
+
reason: "composer-send",
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("marks the attachment incomplete when the upload returns an HTTP error", async () => {
|
|
77
|
+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
78
|
+
vi.stubGlobal(
|
|
79
|
+
"fetch",
|
|
80
|
+
vi.fn().mockResolvedValue({
|
|
81
|
+
ok: false,
|
|
82
|
+
status: 403,
|
|
83
|
+
statusText: "Forbidden",
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
const adapter = new CloudFileAttachmentAdapter(makeCloud());
|
|
87
|
+
|
|
88
|
+
const yields = await drain(adapter);
|
|
89
|
+
|
|
90
|
+
expect(yields.at(-1)?.status).toEqual({
|
|
91
|
+
type: "incomplete",
|
|
92
|
+
reason: "error",
|
|
93
|
+
message: "Failed to upload file: 403 Forbidden",
|
|
94
|
+
});
|
|
95
|
+
expect(errorSpy).toHaveBeenCalledWith(
|
|
96
|
+
"[assistant-ui] Failed to upload attachment:",
|
|
97
|
+
expect.objectContaining({
|
|
98
|
+
message: "Failed to upload file: 403 Forbidden",
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
await expect(adapter.send(yields.at(-1)!)).rejects.toThrow(
|
|
102
|
+
"Attachment not uploaded",
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("marks the attachment incomplete when the upload throws", async () => {
|
|
107
|
+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
108
|
+
const uploadError = new Error("network down");
|
|
109
|
+
vi.stubGlobal("fetch", vi.fn().mockRejectedValue(uploadError));
|
|
110
|
+
const adapter = new CloudFileAttachmentAdapter(makeCloud());
|
|
111
|
+
|
|
112
|
+
const yields = await drain(adapter);
|
|
113
|
+
|
|
114
|
+
expect(yields.at(-1)?.status).toEqual({
|
|
115
|
+
type: "incomplete",
|
|
116
|
+
reason: "error",
|
|
117
|
+
message: "network down",
|
|
118
|
+
});
|
|
119
|
+
expect(errorSpy).toHaveBeenCalledWith(
|
|
120
|
+
"[assistant-ui] Failed to upload attachment:",
|
|
121
|
+
uploadError,
|
|
122
|
+
);
|
|
123
|
+
await expect(adapter.send(yields.at(-1)!)).rejects.toThrow(
|
|
124
|
+
"Attachment not uploaded",
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
} from "../../../types/attachment";
|
|
7
7
|
import type { ThreadUserMessagePart } from "../../../types/message";
|
|
8
8
|
import type { AttachmentAdapter } from "../../../adapters/attachment";
|
|
9
|
+
import { generateId } from "../../../utils/id";
|
|
9
10
|
|
|
10
11
|
const guessAttachmentType = (
|
|
11
12
|
contentType: string,
|
|
@@ -27,7 +28,7 @@ export class CloudFileAttachmentAdapter implements AttachmentAdapter {
|
|
|
27
28
|
}: {
|
|
28
29
|
file: File;
|
|
29
30
|
}): AsyncGenerator<PendingAttachment, void> {
|
|
30
|
-
const id =
|
|
31
|
+
const id = generateId();
|
|
31
32
|
const type = guessAttachmentType(file.type);
|
|
32
33
|
let attachment: PendingAttachment = {
|
|
33
34
|
id,
|
|
@@ -44,7 +45,7 @@ export class CloudFileAttachmentAdapter implements AttachmentAdapter {
|
|
|
44
45
|
await this.cloud.files.generatePresignedUploadUrl({
|
|
45
46
|
filename: file.name,
|
|
46
47
|
});
|
|
47
|
-
await fetch(signedUrl, {
|
|
48
|
+
const res = await fetch(signedUrl, {
|
|
48
49
|
method: "PUT",
|
|
49
50
|
body: file,
|
|
50
51
|
headers: {
|
|
@@ -52,16 +53,26 @@ export class CloudFileAttachmentAdapter implements AttachmentAdapter {
|
|
|
52
53
|
},
|
|
53
54
|
mode: "cors",
|
|
54
55
|
});
|
|
56
|
+
if (!res.ok) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Failed to upload file: ${res.status} ${res.statusText}`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
55
61
|
this.uploadedUrls.set(id, publicUrl);
|
|
56
62
|
attachment = {
|
|
57
63
|
...attachment,
|
|
58
64
|
status: { type: "requires-action", reason: "composer-send" },
|
|
59
65
|
};
|
|
60
66
|
yield attachment;
|
|
61
|
-
} catch {
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("[assistant-ui] Failed to upload attachment:", error);
|
|
62
69
|
attachment = {
|
|
63
70
|
...attachment,
|
|
64
|
-
status: {
|
|
71
|
+
status: {
|
|
72
|
+
type: "incomplete",
|
|
73
|
+
reason: "error",
|
|
74
|
+
message: error instanceof Error ? error.message : String(error),
|
|
75
|
+
},
|
|
65
76
|
};
|
|
66
77
|
yield attachment;
|
|
67
78
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
DataMessagePart,
|
|
3
|
+
FileMessagePart,
|
|
4
|
+
ImageMessagePart,
|
|
2
5
|
MessageStatus,
|
|
3
6
|
SourceProviderMetadata,
|
|
4
7
|
ThreadMessage,
|
|
8
|
+
TextMessagePart,
|
|
9
|
+
Unstable_AudioMessagePart,
|
|
5
10
|
} from "../../../types/message";
|
|
11
|
+
import type { CompleteAttachment } from "../../../types/attachment";
|
|
6
12
|
import { fromThreadMessageLike } from "../../../runtime/utils/thread-message-like";
|
|
7
13
|
import type { CloudMessage } from "assistant-cloud";
|
|
8
14
|
import { isJSONValue } from "../../../utils/json/is-json";
|
|
@@ -65,10 +71,27 @@ type AuiV0MessagePart =
|
|
|
65
71
|
readonly filename?: string;
|
|
66
72
|
};
|
|
67
73
|
|
|
74
|
+
type AuiV0AttachmentPart =
|
|
75
|
+
| TextMessagePart
|
|
76
|
+
| ImageMessagePart
|
|
77
|
+
| FileMessagePart
|
|
78
|
+
| Unstable_AudioMessagePart
|
|
79
|
+
| DataMessagePart<ReadonlyJSONValue>;
|
|
80
|
+
|
|
81
|
+
type AuiV0Attachment = {
|
|
82
|
+
readonly id: string;
|
|
83
|
+
readonly type: CompleteAttachment["type"];
|
|
84
|
+
readonly name: string;
|
|
85
|
+
readonly contentType?: string;
|
|
86
|
+
readonly status: CompleteAttachment["status"];
|
|
87
|
+
readonly content: readonly AuiV0AttachmentPart[];
|
|
88
|
+
};
|
|
89
|
+
|
|
68
90
|
type AuiV0Message = {
|
|
69
91
|
readonly role: "assistant" | "user" | "system";
|
|
70
92
|
readonly status?: MessageStatus;
|
|
71
93
|
readonly content: readonly AuiV0MessagePart[];
|
|
94
|
+
readonly attachments?: readonly AuiV0Attachment[];
|
|
72
95
|
readonly metadata: {
|
|
73
96
|
readonly unstable_state?: ReadonlyJSONValue;
|
|
74
97
|
readonly unstable_annotations: readonly ReadonlyJSONValue[];
|
|
@@ -83,14 +106,59 @@ type AuiV0Message = {
|
|
|
83
106
|
};
|
|
84
107
|
};
|
|
85
108
|
|
|
109
|
+
const encodeAttachmentPart = (
|
|
110
|
+
part: CompleteAttachment["content"][number],
|
|
111
|
+
): AuiV0AttachmentPart => {
|
|
112
|
+
const type = part.type;
|
|
113
|
+
switch (type) {
|
|
114
|
+
case "text":
|
|
115
|
+
case "image":
|
|
116
|
+
case "file":
|
|
117
|
+
case "audio":
|
|
118
|
+
return part;
|
|
119
|
+
|
|
120
|
+
case "data": {
|
|
121
|
+
if (!isJSONValue(part.data)) {
|
|
122
|
+
console.warn(`attachment data is not JSON! ${JSON.stringify(part)}`);
|
|
123
|
+
}
|
|
124
|
+
return { ...part, data: part.data as ReadonlyJSONValue };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
default: {
|
|
128
|
+
const unhandledType: never = type;
|
|
129
|
+
throw new Error(
|
|
130
|
+
`Attachment part type not supported by aui/v0: ${unhandledType}`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const encodeAttachments = (
|
|
137
|
+
message: ThreadMessage,
|
|
138
|
+
): readonly AuiV0Attachment[] | undefined => {
|
|
139
|
+
if (message.role !== "user" || message.attachments.length === 0) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return message.attachments.map(
|
|
144
|
+
({ id, type, name, contentType, status, content }) => ({
|
|
145
|
+
id,
|
|
146
|
+
type,
|
|
147
|
+
name,
|
|
148
|
+
status,
|
|
149
|
+
...(contentType != null ? { contentType } : undefined),
|
|
150
|
+
content: content.map(encodeAttachmentPart),
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
86
155
|
export function auiV0Encode(message: ThreadMessage): AuiV0Message {
|
|
87
|
-
// TODO attachments are currently intentionally ignored
|
|
88
156
|
// info: ID and createdAt are ignored (we use the server value instead)
|
|
89
|
-
|
|
90
157
|
const status: MessageStatus | undefined =
|
|
91
158
|
message.status?.type === "running"
|
|
92
159
|
? { type: "incomplete", reason: "cancelled" }
|
|
93
160
|
: message.status;
|
|
161
|
+
const attachments = encodeAttachments(message);
|
|
94
162
|
|
|
95
163
|
return {
|
|
96
164
|
role: message.role,
|
|
@@ -172,6 +240,7 @@ export function auiV0Encode(message: ThreadMessage): AuiV0Message {
|
|
|
172
240
|
}),
|
|
173
241
|
metadata: message.metadata as AuiV0Message["metadata"],
|
|
174
242
|
...(status ? { status } : undefined),
|
|
243
|
+
...(attachments ? { attachments } : undefined),
|
|
175
244
|
};
|
|
176
245
|
}
|
|
177
246
|
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { renderHook } from "@testing-library/react";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { useExternalMessageConverter } from "./external-message-converter";
|
|
6
|
+
|
|
7
|
+
type TestMessage = {
|
|
8
|
+
id: string;
|
|
9
|
+
role: "user" | "assistant";
|
|
10
|
+
text: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type TestMetadata = useExternalMessageConverter.Metadata & {
|
|
14
|
+
optimisticMessageId?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const convert: useExternalMessageConverter.Callback<TestMessage> = (
|
|
18
|
+
message,
|
|
19
|
+
metadata,
|
|
20
|
+
) => ({
|
|
21
|
+
role: message.role,
|
|
22
|
+
id: message.id,
|
|
23
|
+
content: [{ type: "text", text: message.text }],
|
|
24
|
+
metadata: {
|
|
25
|
+
...(message.role === "assistant" &&
|
|
26
|
+
message.id === (metadata as TestMetadata).optimisticMessageId && {
|
|
27
|
+
isOptimistic: true,
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const MESSAGES: TestMessage[] = [
|
|
33
|
+
{ id: "u1", role: "user", text: "hi" },
|
|
34
|
+
{ id: "a1", role: "assistant", text: "hello" },
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const EMPTY: TestMetadata = {};
|
|
38
|
+
|
|
39
|
+
type Props = {
|
|
40
|
+
callback?: useExternalMessageConverter.Callback<TestMessage>;
|
|
41
|
+
metadata?: TestMetadata;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const renderConverter = (initialProps: Props = {}) =>
|
|
45
|
+
renderHook(
|
|
46
|
+
({ callback = convert, metadata = EMPTY }: Props) =>
|
|
47
|
+
useExternalMessageConverter<TestMessage>({
|
|
48
|
+
callback,
|
|
49
|
+
messages: MESSAGES,
|
|
50
|
+
isRunning: false,
|
|
51
|
+
metadata,
|
|
52
|
+
}),
|
|
53
|
+
{ initialProps },
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
describe("useExternalMessageConverter", () => {
|
|
57
|
+
it("reuses converted messages across rerenders when inputs are unchanged", () => {
|
|
58
|
+
const { result, rerender } = renderConverter();
|
|
59
|
+
|
|
60
|
+
const first = result.current;
|
|
61
|
+
rerender({});
|
|
62
|
+
|
|
63
|
+
expect(result.current[0]).toBe(first[0]);
|
|
64
|
+
expect(result.current[1]).toBe(first[1]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("re-converts cached messages when metadata changes", () => {
|
|
68
|
+
const { result, rerender } = renderConverter({
|
|
69
|
+
metadata: { optimisticMessageId: "a1" },
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(result.current.at(-1)?.metadata.isOptimistic).toBe(true);
|
|
73
|
+
|
|
74
|
+
rerender({ metadata: {} });
|
|
75
|
+
|
|
76
|
+
expect(result.current.at(-1)?.metadata.isOptimistic).toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("re-converts cached messages when the callback changes", () => {
|
|
80
|
+
const upper: useExternalMessageConverter.Callback<TestMessage> = (
|
|
81
|
+
message,
|
|
82
|
+
) => ({
|
|
83
|
+
role: message.role,
|
|
84
|
+
id: message.id,
|
|
85
|
+
content: [{ type: "text", text: message.text.toUpperCase() }],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const { result, rerender } = renderConverter();
|
|
89
|
+
|
|
90
|
+
expect(result.current[1]?.content[0]).toMatchObject({
|
|
91
|
+
type: "text",
|
|
92
|
+
text: "hello",
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
rerender({ callback: upper });
|
|
96
|
+
|
|
97
|
+
expect(result.current[1]?.content[0]).toMatchObject({
|
|
98
|
+
type: "text",
|
|
99
|
+
text: "HELLO",
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it.each([
|
|
104
|
+
["false", false],
|
|
105
|
+
["zero", 0],
|
|
106
|
+
["an empty string", ""],
|
|
107
|
+
])("preserves %s assistant state", (_label, state) => {
|
|
108
|
+
const callback: useExternalMessageConverter.Callback<TestMessage> = (
|
|
109
|
+
message,
|
|
110
|
+
) => ({
|
|
111
|
+
role: message.role,
|
|
112
|
+
id: message.id,
|
|
113
|
+
content: [{ type: "text", text: message.text }],
|
|
114
|
+
...(message.role === "assistant"
|
|
115
|
+
? { metadata: { unstable_state: state } }
|
|
116
|
+
: undefined),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const { result } = renderConverter({ callback });
|
|
120
|
+
|
|
121
|
+
expect(result.current[1]?.metadata.unstable_state).toBe(state);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useMemo } from "react";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
4
|
import { ThreadMessageConverter } from "../../runtimes/external-store/thread-message-converter";
|
|
5
5
|
import {
|
|
6
6
|
getExternalStoreMessages,
|
|
@@ -76,6 +76,11 @@ type CallbackResult<T> = {
|
|
|
76
76
|
outputs: useExternalMessageConverter.Message[];
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
+
type CallbackCacheEntry<T> = CallbackResult<T> & {
|
|
80
|
+
metadata: useExternalMessageConverter.Metadata;
|
|
81
|
+
callback: useExternalMessageConverter.Callback<T>;
|
|
82
|
+
};
|
|
83
|
+
|
|
79
84
|
type ChunkResult<T> = {
|
|
80
85
|
inputs: T[];
|
|
81
86
|
outputs: useExternalMessageConverter.Message[];
|
|
@@ -165,7 +170,7 @@ const joinExternalMessages = (
|
|
|
165
170
|
|
|
166
171
|
if (output.metadata) {
|
|
167
172
|
assistantMessage.metadata ??= {};
|
|
168
|
-
if (output.metadata.unstable_state) {
|
|
173
|
+
if (output.metadata.unstable_state !== undefined) {
|
|
169
174
|
assistantMessage.metadata.unstable_state =
|
|
170
175
|
output.metadata.unstable_state;
|
|
171
176
|
}
|
|
@@ -404,28 +409,48 @@ export const useExternalMessageConverter = <T extends WeakKey>({
|
|
|
404
409
|
joinStrategy?: JoinStrategy | undefined;
|
|
405
410
|
metadata?: useExternalMessageConverter.Metadata | undefined;
|
|
406
411
|
}) => {
|
|
412
|
+
// The caches live for the component lifetime; React Compiler hoists
|
|
413
|
+
// allocations without reactive dependencies out of useMemo, so re-creating
|
|
414
|
+
// them on dependency change would not survive compilation. Staleness is
|
|
415
|
+
// instead tracked per entry via the metadata/callback that produced it,
|
|
416
|
+
// keeping correctness independent of memoization (which React treats as
|
|
417
|
+
// droppable). A "use no memo" opt-out would restore the useMemo semantics
|
|
418
|
+
// but leave cache flushing coupled to memo firing.
|
|
419
|
+
const [caches] = useState(() => ({
|
|
420
|
+
callbackCache: new WeakMap<T, CallbackCacheEntry<T>>(),
|
|
421
|
+
chunkCache: new WeakMap<
|
|
422
|
+
useExternalMessageConverter.Message,
|
|
423
|
+
ChunkResult<T>
|
|
424
|
+
>(),
|
|
425
|
+
converterCache: new ThreadMessageConverter(),
|
|
426
|
+
}));
|
|
427
|
+
|
|
407
428
|
const state = useMemo(
|
|
408
429
|
() => ({
|
|
409
430
|
metadata: metadata ?? {},
|
|
410
431
|
callback,
|
|
411
|
-
|
|
412
|
-
chunkCache: new WeakMap<
|
|
413
|
-
useExternalMessageConverter.Message,
|
|
414
|
-
ChunkResult<T>
|
|
415
|
-
>(),
|
|
416
|
-
converterCache: new ThreadMessageConverter(),
|
|
432
|
+
...caches,
|
|
417
433
|
}),
|
|
418
|
-
[callback, metadata],
|
|
434
|
+
[callback, metadata, caches],
|
|
419
435
|
);
|
|
420
436
|
|
|
421
437
|
return useMemo(() => {
|
|
422
438
|
const callbackResults: CallbackResult<T>[] = [];
|
|
423
439
|
for (const message of messages) {
|
|
424
440
|
let result = state.callbackCache.get(message);
|
|
425
|
-
if (
|
|
441
|
+
if (
|
|
442
|
+
!result ||
|
|
443
|
+
result.metadata !== state.metadata ||
|
|
444
|
+
result.callback !== state.callback
|
|
445
|
+
) {
|
|
426
446
|
const output = state.callback(message, state.metadata);
|
|
427
447
|
const outputs = Array.isArray(output) ? output : [output];
|
|
428
|
-
result = {
|
|
448
|
+
result = {
|
|
449
|
+
input: message,
|
|
450
|
+
outputs,
|
|
451
|
+
metadata: state.metadata,
|
|
452
|
+
callback: state.callback,
|
|
453
|
+
};
|
|
429
454
|
state.callbackCache.set(message, result);
|
|
430
455
|
}
|
|
431
456
|
callbackResults.push(result);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { render, waitFor } from "@testing-library/react";
|
|
4
|
+
import { StrictMode } from "react";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import type { ChatModelAdapter } from "../../runtime/utils/chat-model-adapter";
|
|
7
|
+
import { AssistantRuntimeProvider } from "../AssistantRuntimeProvider";
|
|
8
|
+
import { useLocalRuntime } from "./useLocalRuntime";
|
|
9
|
+
|
|
10
|
+
const chatModel: ChatModelAdapter = {
|
|
11
|
+
run: async () => ({ content: [] }),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
vi.restoreAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("useLocalRuntime", () => {
|
|
19
|
+
it("handles rejected history loads", async () => {
|
|
20
|
+
const error = new Error("history unavailable");
|
|
21
|
+
const consoleError = vi
|
|
22
|
+
.spyOn(console, "error")
|
|
23
|
+
.mockImplementation(() => {});
|
|
24
|
+
const history = {
|
|
25
|
+
load: vi.fn().mockRejectedValue(error),
|
|
26
|
+
append: vi.fn().mockResolvedValue(undefined),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const App = () => {
|
|
30
|
+
const runtime = useLocalRuntime(chatModel, { adapters: { history } });
|
|
31
|
+
return (
|
|
32
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
33
|
+
<div />
|
|
34
|
+
</AssistantRuntimeProvider>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const renderApp = () => (
|
|
39
|
+
<StrictMode>
|
|
40
|
+
<App />
|
|
41
|
+
</StrictMode>
|
|
42
|
+
);
|
|
43
|
+
const { rerender } = render(renderApp());
|
|
44
|
+
|
|
45
|
+
await waitFor(() => {
|
|
46
|
+
expect(consoleError).toHaveBeenCalledWith(
|
|
47
|
+
"[assistant-ui] local thread history load failed:",
|
|
48
|
+
error,
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
rerender(renderApp());
|
|
53
|
+
expect(history.load).toHaveBeenCalledTimes(1);
|
|
54
|
+
expect(consoleError).toHaveBeenCalledTimes(1);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -35,6 +35,7 @@ const useLocalThreadRuntime = (
|
|
|
35
35
|
const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));
|
|
36
36
|
|
|
37
37
|
const threadIdRef = useRef<string | undefined>(undefined);
|
|
38
|
+
const historyLoadPromiseRef = useRef<Promise<void> | undefined>(undefined);
|
|
38
39
|
threadIdRef.current = useAuiState((s) => s.threadListItem.remoteId);
|
|
39
40
|
|
|
40
41
|
useEffect(() => {
|
|
@@ -51,9 +52,20 @@ const useLocalThreadRuntime = (
|
|
|
51
52
|
|
|
52
53
|
useEffect(() => {
|
|
53
54
|
runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);
|
|
54
|
-
runtime.threads.getMainThreadRuntimeCore().__internal_load();
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const loadPromise = runtime.threads
|
|
59
|
+
.getMainThreadRuntimeCore()
|
|
60
|
+
.__internal_load();
|
|
61
|
+
if (historyLoadPromiseRef.current === loadPromise) return;
|
|
62
|
+
|
|
63
|
+
historyLoadPromiseRef.current = loadPromise;
|
|
64
|
+
void loadPromise.catch((error: unknown) => {
|
|
65
|
+
console.error("[assistant-ui] local thread history load failed:", error);
|
|
66
|
+
});
|
|
67
|
+
}, [runtime]);
|
|
68
|
+
|
|
57
69
|
useEffect(() => {
|
|
58
70
|
if (!modelContext) return undefined;
|
|
59
71
|
return runtime.registerModelContextProvider(modelContext);
|