@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,130 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
createVoiceSession,
|
|
4
|
+
type VoiceSessionControls,
|
|
5
|
+
type VoiceSessionHelpers,
|
|
6
|
+
} from "./voice";
|
|
7
|
+
|
|
8
|
+
const createTestSession = () => {
|
|
9
|
+
let helpers: VoiceSessionHelpers | undefined;
|
|
10
|
+
const session = createVoiceSession({}, async (sessionHelpers) => {
|
|
11
|
+
helpers = sessionHelpers;
|
|
12
|
+
return {
|
|
13
|
+
disconnect: vi.fn(),
|
|
14
|
+
mute: vi.fn(),
|
|
15
|
+
unmute: vi.fn(),
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (!helpers) throw new Error("Voice session setup did not start");
|
|
20
|
+
return { helpers, session };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const createPendingTestSession = () => {
|
|
24
|
+
let resolveControls!: (controls: VoiceSessionControls) => void;
|
|
25
|
+
const controlsPromise = new Promise<VoiceSessionControls>((resolve) => {
|
|
26
|
+
resolveControls = resolve;
|
|
27
|
+
});
|
|
28
|
+
const controls = {
|
|
29
|
+
disconnect: vi.fn(),
|
|
30
|
+
mute: vi.fn(),
|
|
31
|
+
unmute: vi.fn(),
|
|
32
|
+
};
|
|
33
|
+
const session = createVoiceSession({}, () => controlsPromise);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
controls,
|
|
37
|
+
controlsPromise,
|
|
38
|
+
resolveControls: () => resolveControls(controls),
|
|
39
|
+
session,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
vi.restoreAllMocks();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("createVoiceSession", () => {
|
|
48
|
+
it("applies mute requested while setup is pending", async () => {
|
|
49
|
+
const { controls, controlsPromise, resolveControls, session } =
|
|
50
|
+
createPendingTestSession();
|
|
51
|
+
|
|
52
|
+
session.mute();
|
|
53
|
+
|
|
54
|
+
expect(session.isMuted).toBe(true);
|
|
55
|
+
expect(controls.mute).not.toHaveBeenCalled();
|
|
56
|
+
|
|
57
|
+
resolveControls();
|
|
58
|
+
await controlsPromise;
|
|
59
|
+
|
|
60
|
+
expect(controls.mute).toHaveBeenCalledOnce();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("does not apply stale mute after unmuting during setup", async () => {
|
|
64
|
+
const { controls, controlsPromise, resolveControls, session } =
|
|
65
|
+
createPendingTestSession();
|
|
66
|
+
|
|
67
|
+
session.mute();
|
|
68
|
+
session.unmute();
|
|
69
|
+
resolveControls();
|
|
70
|
+
await controlsPromise;
|
|
71
|
+
|
|
72
|
+
expect(session.isMuted).toBe(false);
|
|
73
|
+
expect(controls.mute).not.toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("continues notifying listeners when one throws", () => {
|
|
77
|
+
const listenerError = new Error("listener failed");
|
|
78
|
+
const consoleError = vi
|
|
79
|
+
.spyOn(console, "error")
|
|
80
|
+
.mockImplementation(() => {});
|
|
81
|
+
const { helpers, session } = createTestSession();
|
|
82
|
+
|
|
83
|
+
const transcriptListener = vi.fn();
|
|
84
|
+
session.onTranscript(() => {
|
|
85
|
+
throw listenerError;
|
|
86
|
+
});
|
|
87
|
+
session.onTranscript(transcriptListener);
|
|
88
|
+
|
|
89
|
+
const modeListener = vi.fn();
|
|
90
|
+
session.onModeChange(() => {
|
|
91
|
+
throw listenerError;
|
|
92
|
+
});
|
|
93
|
+
session.onModeChange(modeListener);
|
|
94
|
+
|
|
95
|
+
const volumeListener = vi.fn();
|
|
96
|
+
session.onVolumeChange(() => {
|
|
97
|
+
throw listenerError;
|
|
98
|
+
});
|
|
99
|
+
session.onVolumeChange(volumeListener);
|
|
100
|
+
|
|
101
|
+
const statusListener = vi.fn();
|
|
102
|
+
session.onStatusChange(() => {
|
|
103
|
+
throw listenerError;
|
|
104
|
+
});
|
|
105
|
+
session.onStatusChange(statusListener);
|
|
106
|
+
|
|
107
|
+
helpers.emitTranscript({ role: "assistant", text: "hello" });
|
|
108
|
+
helpers.emitMode("speaking");
|
|
109
|
+
helpers.emitVolume(0.5);
|
|
110
|
+
helpers.end("finished");
|
|
111
|
+
|
|
112
|
+
expect(transcriptListener).toHaveBeenCalledWith({
|
|
113
|
+
role: "assistant",
|
|
114
|
+
text: "hello",
|
|
115
|
+
});
|
|
116
|
+
expect(modeListener).toHaveBeenCalledWith("speaking");
|
|
117
|
+
expect(volumeListener).toHaveBeenCalledWith(0.5);
|
|
118
|
+
expect(statusListener).toHaveBeenCalledWith({
|
|
119
|
+
type: "ended",
|
|
120
|
+
reason: "finished",
|
|
121
|
+
error: undefined,
|
|
122
|
+
});
|
|
123
|
+
expect(helpers.isDisposed()).toBe(true);
|
|
124
|
+
expect(consoleError).toHaveBeenCalledTimes(4);
|
|
125
|
+
expect(consoleError).toHaveBeenCalledWith(
|
|
126
|
+
"[assistant-ui] Voice session listener threw an error",
|
|
127
|
+
listenerError,
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
});
|
package/src/adapters/voice.ts
CHANGED
|
@@ -57,6 +57,22 @@ export type VoiceSessionHelpers = {
|
|
|
57
57
|
isDisposed: () => boolean;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
+
const notifyListeners = <T>(
|
|
61
|
+
listeners: ReadonlySet<(value: T) => void>,
|
|
62
|
+
value: T,
|
|
63
|
+
) => {
|
|
64
|
+
for (const listener of listeners) {
|
|
65
|
+
try {
|
|
66
|
+
listener(value);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(
|
|
69
|
+
"[assistant-ui] Voice session listener threw an error",
|
|
70
|
+
error,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
60
76
|
export function createVoiceSession(
|
|
61
77
|
options: { abortSignal?: AbortSignal },
|
|
62
78
|
setup: (helpers: VoiceSessionHelpers) => Promise<VoiceSessionControls>,
|
|
@@ -85,25 +101,25 @@ export function createVoiceSession(
|
|
|
85
101
|
setStatus: (status) => {
|
|
86
102
|
if (disposed) return;
|
|
87
103
|
currentStatus = status;
|
|
88
|
-
|
|
104
|
+
notifyListeners(statusCbs, status);
|
|
89
105
|
},
|
|
90
106
|
end: (reason, error?) => {
|
|
91
107
|
if (disposed) return;
|
|
92
108
|
currentStatus = { type: "ended", reason, error };
|
|
93
|
-
|
|
109
|
+
notifyListeners(statusCbs, currentStatus);
|
|
94
110
|
cleanup();
|
|
95
111
|
},
|
|
96
112
|
emitTranscript: (item) => {
|
|
97
113
|
if (disposed) return;
|
|
98
|
-
|
|
114
|
+
notifyListeners(transcriptCbs, item);
|
|
99
115
|
},
|
|
100
116
|
emitMode: (mode) => {
|
|
101
117
|
if (disposed) return;
|
|
102
|
-
|
|
118
|
+
notifyListeners(modeCbs, mode);
|
|
103
119
|
},
|
|
104
120
|
emitVolume: (volume) => {
|
|
105
121
|
if (disposed) return;
|
|
106
|
-
|
|
122
|
+
notifyListeners(volumeCbs, volume);
|
|
107
123
|
},
|
|
108
124
|
isDisposed: () => disposed,
|
|
109
125
|
};
|
|
@@ -155,7 +171,11 @@ export function createVoiceSession(
|
|
|
155
171
|
try {
|
|
156
172
|
if (disposed) return;
|
|
157
173
|
controls = await setup(helpers);
|
|
158
|
-
if (disposed)
|
|
174
|
+
if (disposed) {
|
|
175
|
+
controls.disconnect();
|
|
176
|
+
} else if (isMuted) {
|
|
177
|
+
controls.mute();
|
|
178
|
+
}
|
|
159
179
|
} catch (error) {
|
|
160
180
|
helpers.end("error", error);
|
|
161
181
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type {
|
|
|
12
12
|
// Message parts
|
|
13
13
|
TextMessagePart,
|
|
14
14
|
ReasoningMessagePart,
|
|
15
|
+
PartProviderMetadata,
|
|
15
16
|
SourceProviderMetadata,
|
|
16
17
|
SourceMessagePart,
|
|
17
18
|
ImageMessagePart,
|
|
@@ -149,7 +150,12 @@ export type {
|
|
|
149
150
|
export type { FeedbackAdapter } from "./adapters/feedback";
|
|
150
151
|
|
|
151
152
|
// Suggestion adapter
|
|
152
|
-
export type {
|
|
153
|
+
export type {
|
|
154
|
+
SuggestionAdapter,
|
|
155
|
+
SuggestionAdapterGenerateOptions,
|
|
156
|
+
CreateSuggestionAdapterOptions,
|
|
157
|
+
} from "./adapters/suggestion";
|
|
158
|
+
export { createSuggestionAdapter } from "./adapters/suggestion";
|
|
153
159
|
|
|
154
160
|
// Directive formatter
|
|
155
161
|
export { unstable_defaultDirectiveFormatter } from "./adapters/directive-formatter";
|
|
@@ -188,6 +194,14 @@ export type {
|
|
|
188
194
|
ThreadComposerRuntimeCore,
|
|
189
195
|
} from "./runtime/interfaces/composer-runtime-core";
|
|
190
196
|
|
|
197
|
+
export type {
|
|
198
|
+
ErrorSeverity,
|
|
199
|
+
ErrorDisplay,
|
|
200
|
+
AssistantErrorCode,
|
|
201
|
+
AssistantError,
|
|
202
|
+
} from "./types/error";
|
|
203
|
+
export { toAssistantError, isAssistantError } from "./types/error";
|
|
204
|
+
|
|
191
205
|
export type {
|
|
192
206
|
RuntimeCapabilities,
|
|
193
207
|
AddToolResultOptions,
|
package/src/internal.ts
CHANGED
|
@@ -33,10 +33,31 @@ export {
|
|
|
33
33
|
// Message utilities
|
|
34
34
|
export { getThreadMessageText } from "./utils/text";
|
|
35
35
|
export { resolveToolApprovalResponse } from "./runtime/utils/resolveToolApprovalResponse";
|
|
36
|
+
export { consumeSuggestionResult } from "./adapters/suggestion";
|
|
36
37
|
|
|
37
38
|
// Composite context provider
|
|
38
39
|
export { CompositeContextProvider } from "./utils/composite-context-provider";
|
|
39
40
|
|
|
41
|
+
// Shared attachment data-URL encoder, reused by framework adapters so the
|
|
42
|
+
// FileReader fallback lives in one place.
|
|
43
|
+
export { getFileDataURL } from "./adapters/attachment";
|
|
44
|
+
export { isCreateAttachment } from "./types/attachment";
|
|
45
|
+
|
|
46
|
+
// Streaming-stable tool-args stringifier, reused by framework adapters so the
|
|
47
|
+
// key-order stabilization lives in one place.
|
|
48
|
+
export {
|
|
49
|
+
stableStringifyToolArgs,
|
|
50
|
+
trackToolArgsKeyOrder,
|
|
51
|
+
} from "./utils/json/stable-stringify-tool-args";
|
|
52
|
+
|
|
53
|
+
// JSON type guards, reused by framework bindings so the depth-guarded
|
|
54
|
+
// validation lives in one place.
|
|
55
|
+
export { isJSONValue, isRecord } from "./utils/json/is-json";
|
|
56
|
+
|
|
57
|
+
// Data-URL decoder and http(s) matcher, reused by framework adapters so the
|
|
58
|
+
// outbound part conversion lives in one place.
|
|
59
|
+
export { httpUrlPattern, parseDataUrl } from "./utils/data-url";
|
|
60
|
+
|
|
40
61
|
// Runtime extras helper for external-store adapters. Internal because the
|
|
41
62
|
// tap-native runtime path replaces the `thread.extras` side-channel it wraps.
|
|
42
63
|
export {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { AssistantFrameHost } from "./host";
|
|
3
|
+
import { type FrameMessage, FRAME_MESSAGE_CHANNEL } from "./types";
|
|
4
|
+
|
|
5
|
+
const executionContext = {
|
|
6
|
+
toolCallId: "tool-call",
|
|
7
|
+
abortSignal: new AbortController().signal,
|
|
8
|
+
human: async () => undefined,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const createHost = () => {
|
|
12
|
+
let handleMessage: ((event: MessageEvent) => void) | undefined;
|
|
13
|
+
const addEventListener = vi.fn(
|
|
14
|
+
(_type: string, listener: EventListenerOrEventListenerObject) => {
|
|
15
|
+
handleMessage = listener as (event: MessageEvent) => void;
|
|
16
|
+
},
|
|
17
|
+
);
|
|
18
|
+
const removeEventListener = vi.fn();
|
|
19
|
+
vi.stubGlobal("window", { addEventListener, removeEventListener });
|
|
20
|
+
|
|
21
|
+
const postMessage = vi.fn();
|
|
22
|
+
const iframeWindow = { postMessage } as unknown as Window;
|
|
23
|
+
const host = new AssistantFrameHost(iframeWindow);
|
|
24
|
+
|
|
25
|
+
const dispatchMessage = (message: FrameMessage) =>
|
|
26
|
+
handleMessage?.({
|
|
27
|
+
source: iframeWindow,
|
|
28
|
+
data: {
|
|
29
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
30
|
+
message,
|
|
31
|
+
},
|
|
32
|
+
} as unknown as MessageEvent);
|
|
33
|
+
|
|
34
|
+
dispatchMessage({
|
|
35
|
+
type: "model-context-update",
|
|
36
|
+
context: {
|
|
37
|
+
tools: {
|
|
38
|
+
search: {
|
|
39
|
+
type: "frontend",
|
|
40
|
+
parameters: { type: "object", properties: {} },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const execute = host.getModelContext().tools?.search?.execute;
|
|
47
|
+
if (!execute) throw new Error("Expected the search tool to be available");
|
|
48
|
+
|
|
49
|
+
return { dispatchMessage, execute, host, postMessage };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
vi.useFakeTimers();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
vi.useRealTimers();
|
|
58
|
+
vi.unstubAllGlobals();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("AssistantFrameHost", () => {
|
|
62
|
+
it("resolves tool calls from frame results", async () => {
|
|
63
|
+
const { dispatchMessage, execute, host } = createHost();
|
|
64
|
+
const result = Promise.resolve(
|
|
65
|
+
execute({ query: "weather" }, executionContext),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
dispatchMessage({
|
|
69
|
+
type: "tool-result",
|
|
70
|
+
id: "tool-0",
|
|
71
|
+
result: "sunny",
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await expect(result).resolves.toBe("sunny");
|
|
75
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
76
|
+
host.dispose();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("rejects pending tool calls when disposed", async () => {
|
|
80
|
+
const { execute, host } = createHost();
|
|
81
|
+
const result = Promise.resolve(execute({}, executionContext));
|
|
82
|
+
|
|
83
|
+
host.dispose();
|
|
84
|
+
|
|
85
|
+
await expect(result).rejects.toThrow(
|
|
86
|
+
"AssistantFrameHost has been disposed",
|
|
87
|
+
);
|
|
88
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("rejects tool calls made after disposal without posting a request", async () => {
|
|
92
|
+
const { execute, host, postMessage } = createHost();
|
|
93
|
+
host.dispose();
|
|
94
|
+
|
|
95
|
+
await expect(execute({}, executionContext)).rejects.toThrow(
|
|
96
|
+
"AssistantFrameHost has been disposed",
|
|
97
|
+
);
|
|
98
|
+
expect(postMessage).toHaveBeenCalledOnce();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -53,6 +53,7 @@ export class AssistantFrameHost implements ModelContextProvider {
|
|
|
53
53
|
private _requestCounter = 0;
|
|
54
54
|
private _iframeWindow: Window;
|
|
55
55
|
private _targetOrigin: string;
|
|
56
|
+
private _disposed = false;
|
|
56
57
|
|
|
57
58
|
constructor(iframeWindow: Window, targetOrigin: string = "*") {
|
|
58
59
|
this._iframeWindow = iframeWindow;
|
|
@@ -130,6 +131,10 @@ export class AssistantFrameHost implements ModelContextProvider {
|
|
|
130
131
|
timeout = 30000,
|
|
131
132
|
timeoutMessage = "Request timed out",
|
|
132
133
|
): Promise<any> {
|
|
134
|
+
if (this._disposed) {
|
|
135
|
+
return Promise.reject(new Error("AssistantFrameHost has been disposed"));
|
|
136
|
+
}
|
|
137
|
+
|
|
133
138
|
return new Promise((resolve, reject) => {
|
|
134
139
|
this._pendingRequests.set(message.id, { resolve, reject });
|
|
135
140
|
|
|
@@ -188,8 +193,13 @@ export class AssistantFrameHost implements ModelContextProvider {
|
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
dispose() {
|
|
196
|
+
this._disposed = true;
|
|
191
197
|
window.removeEventListener("message", this.handleMessage);
|
|
192
198
|
this._subscribers.clear();
|
|
199
|
+
const error = new Error("AssistantFrameHost has been disposed");
|
|
200
|
+
for (const pending of this._pendingRequests.values()) {
|
|
201
|
+
pending.reject(error);
|
|
202
|
+
}
|
|
193
203
|
this._pendingRequests.clear();
|
|
194
204
|
}
|
|
195
205
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { AssistantFrameProvider } from "./provider";
|
|
6
|
+
import { FRAME_MESSAGE_CHANNEL } from "./types";
|
|
7
|
+
|
|
8
|
+
describe("AssistantFrameProvider", () => {
|
|
9
|
+
let messageHandler: ((event: MessageEvent) => void) | undefined;
|
|
10
|
+
let parentWindow: Window;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
parentWindow = {
|
|
14
|
+
postMessage: vi.fn(),
|
|
15
|
+
} as unknown as Window;
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(window, "parent", {
|
|
18
|
+
value: parentWindow,
|
|
19
|
+
configurable: true,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
vi.spyOn(window, "addEventListener").mockImplementation(
|
|
23
|
+
(event, listener) => {
|
|
24
|
+
if (event === "message" && typeof listener === "function") {
|
|
25
|
+
messageHandler = listener as (event: MessageEvent) => void;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
vi.spyOn(window, "removeEventListener").mockImplementation(() => {});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
AssistantFrameProvider.dispose();
|
|
34
|
+
vi.restoreAllMocks();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("only accepts tool calls from the parent window", async () => {
|
|
38
|
+
const execute = vi.fn(async () => "result");
|
|
39
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
40
|
+
{
|
|
41
|
+
getModelContext: () => ({
|
|
42
|
+
tools: {
|
|
43
|
+
sensitiveTool: { execute },
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
"https://parent.example",
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const toolCall = {
|
|
51
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
52
|
+
message: {
|
|
53
|
+
type: "tool-call",
|
|
54
|
+
id: "tool-call-1",
|
|
55
|
+
toolName: "sensitiveTool",
|
|
56
|
+
args: {},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const otherWindow = {
|
|
60
|
+
postMessage: vi.fn(),
|
|
61
|
+
} as unknown as Window;
|
|
62
|
+
|
|
63
|
+
messageHandler?.(
|
|
64
|
+
new MessageEvent("message", {
|
|
65
|
+
data: toolCall,
|
|
66
|
+
origin: "https://parent.example",
|
|
67
|
+
source: otherWindow,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(execute).not.toHaveBeenCalled();
|
|
72
|
+
|
|
73
|
+
messageHandler?.(
|
|
74
|
+
new MessageEvent("message", {
|
|
75
|
+
data: toolCall,
|
|
76
|
+
origin: "https://parent.example",
|
|
77
|
+
source: parentWindow,
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
await vi.waitFor(() => expect(execute).toHaveBeenCalledOnce());
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -59,6 +59,7 @@ export class AssistantFrameProvider {
|
|
|
59
59
|
private handleMessage(event: MessageEvent) {
|
|
60
60
|
if (this._targetOrigin !== "*" && event.origin !== this._targetOrigin)
|
|
61
61
|
return;
|
|
62
|
+
if (event.source !== window.parent) return;
|
|
62
63
|
if (event.data?.channel !== FRAME_MESSAGE_CHANNEL) return;
|
|
63
64
|
|
|
64
65
|
const message = event.data.message as FrameMessage;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { describe, expect, expectTypeOf, it } from "vitest";
|
|
2
|
+
import type { Tool } from "assistant-stream";
|
|
3
|
+
import type { AsyncIterableStream } from "assistant-stream/utils";
|
|
4
|
+
import { tool } from "./tool";
|
|
5
|
+
|
|
6
|
+
type TestStandardSchema<TInput> = {
|
|
7
|
+
readonly "~standard": {
|
|
8
|
+
readonly version: 1;
|
|
9
|
+
readonly vendor: "test";
|
|
10
|
+
readonly types?: {
|
|
11
|
+
readonly input: TInput;
|
|
12
|
+
readonly output: TInput;
|
|
13
|
+
};
|
|
14
|
+
readonly validate: (value: unknown) => { readonly value: TInput };
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const checkStandardSchemaInference = () => {
|
|
19
|
+
const weatherSchema = {} as TestStandardSchema<{
|
|
20
|
+
city: string;
|
|
21
|
+
unit?: "c" | "f";
|
|
22
|
+
tags: string[];
|
|
23
|
+
}>;
|
|
24
|
+
|
|
25
|
+
const getWeather = tool({
|
|
26
|
+
type: "frontend",
|
|
27
|
+
parameters: weatherSchema,
|
|
28
|
+
execute: async (args) => {
|
|
29
|
+
expectTypeOf(args.city).toEqualTypeOf<string>();
|
|
30
|
+
expectTypeOf(args.unit).toEqualTypeOf<"c" | "f" | undefined>();
|
|
31
|
+
expectTypeOf(args.tags).toEqualTypeOf<string[]>();
|
|
32
|
+
// @ts-expect-error unknown schema fields should not be accepted
|
|
33
|
+
void args.missing;
|
|
34
|
+
|
|
35
|
+
return `Weather in ${args.city}`;
|
|
36
|
+
},
|
|
37
|
+
streamCall: async (reader) => {
|
|
38
|
+
const city = await reader.args.get("city");
|
|
39
|
+
expectTypeOf(city).toEqualTypeOf<string>();
|
|
40
|
+
expectTypeOf(reader.args.forEach("tags")).toEqualTypeOf<
|
|
41
|
+
AsyncIterableStream<string>
|
|
42
|
+
>();
|
|
43
|
+
// @ts-expect-error unknown argument paths should not be accepted
|
|
44
|
+
reader.args.get("missing");
|
|
45
|
+
},
|
|
46
|
+
toModelOutput: ({ input }) => {
|
|
47
|
+
expectTypeOf(input.city).toEqualTypeOf<string>();
|
|
48
|
+
expectTypeOf(input.unit).toEqualTypeOf<"c" | "f" | undefined>();
|
|
49
|
+
return [{ type: "text", text: input.city }];
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expectTypeOf(getWeather).toEqualTypeOf<
|
|
54
|
+
Tool<
|
|
55
|
+
{
|
|
56
|
+
city: string;
|
|
57
|
+
unit?: "c" | "f";
|
|
58
|
+
tags: string[];
|
|
59
|
+
},
|
|
60
|
+
string
|
|
61
|
+
>
|
|
62
|
+
>();
|
|
63
|
+
};
|
|
64
|
+
expectTypeOf(checkStandardSchemaInference).toEqualTypeOf<() => void>();
|
|
65
|
+
|
|
66
|
+
const checkUnknownStandardSchemaInputFallsBackToRecord = () => {
|
|
67
|
+
const unknownSchema = {} as TestStandardSchema<unknown>;
|
|
68
|
+
|
|
69
|
+
const passthrough = tool({
|
|
70
|
+
type: "frontend",
|
|
71
|
+
parameters: unknownSchema,
|
|
72
|
+
execute: async (args) => {
|
|
73
|
+
expectTypeOf(args).toEqualTypeOf<Record<string, unknown>>();
|
|
74
|
+
return args;
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expectTypeOf(passthrough).toEqualTypeOf<
|
|
79
|
+
Tool<Record<string, unknown>, Record<string, unknown>>
|
|
80
|
+
>();
|
|
81
|
+
};
|
|
82
|
+
expectTypeOf(checkUnknownStandardSchemaInputFallsBackToRecord).toEqualTypeOf<
|
|
83
|
+
() => void
|
|
84
|
+
>();
|
|
85
|
+
|
|
86
|
+
const checkExplicitJsonSchemaTypesStillWork = () => {
|
|
87
|
+
const getWeather = tool<{ city: string }, string>({
|
|
88
|
+
type: "frontend",
|
|
89
|
+
parameters: {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: { city: { type: "string" } },
|
|
92
|
+
required: ["city"],
|
|
93
|
+
},
|
|
94
|
+
execute: async ({ city }) => city,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
expectTypeOf(getWeather).toEqualTypeOf<Tool<{ city: string }, string>>();
|
|
98
|
+
};
|
|
99
|
+
expectTypeOf(checkExplicitJsonSchemaTypesStillWork).toEqualTypeOf<() => void>();
|
|
100
|
+
|
|
101
|
+
describe("tool", () => {
|
|
102
|
+
it("returns the tool definition at runtime", () => {
|
|
103
|
+
const definition = {
|
|
104
|
+
type: "frontend" as const,
|
|
105
|
+
parameters: { type: "object" as const, properties: {} },
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
expect(tool(definition)).toBe(definition);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type { Tool } from "assistant-stream";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type StandardSchemaInput<TSchema> = TSchema extends {
|
|
4
|
+
readonly "~standard": {
|
|
5
|
+
readonly types?: { readonly input: infer TInput } | undefined;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
? TInput extends Record<string, unknown>
|
|
9
|
+
? TInput
|
|
10
|
+
: Record<string, unknown>
|
|
11
|
+
: Record<string, unknown>;
|
|
12
|
+
|
|
13
|
+
type StandardSchemaParameters = Extract<
|
|
14
|
+
NonNullable<Extract<Tool<any>, { parameters: unknown }>["parameters"]>,
|
|
15
|
+
{ readonly "~standard": unknown }
|
|
16
|
+
>;
|
|
4
17
|
|
|
5
18
|
/**
|
|
6
19
|
* Defines a model tool with its argument schema, execution behavior, and
|
|
@@ -8,25 +21,34 @@ import type { Tool } from "assistant-stream";
|
|
|
8
21
|
*
|
|
9
22
|
* This helper keeps reusable tool definitions type-checked and convenient to
|
|
10
23
|
* export for a {@link Toolkit} registered with {@link Tools}.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
24
|
+
* When `parameters` is a Standard Schema (for example Zod v4), its input type
|
|
25
|
+
* is inferred for `execute`, `streamCall`, and model-output callbacks. Plain
|
|
26
|
+
* JSON Schema objects do not carry TypeScript input types, so provide generic
|
|
27
|
+
* arguments or annotate callbacks when you need precise args for JSON Schema.
|
|
13
28
|
*
|
|
14
29
|
* @param tool - Tool definition to expose to the assistant model.
|
|
15
30
|
*
|
|
16
31
|
* @example
|
|
17
32
|
* ```ts
|
|
18
|
-
*
|
|
33
|
+
* import { z } from "zod";
|
|
34
|
+
*
|
|
35
|
+
* const getWeather = tool({
|
|
19
36
|
* type: "frontend",
|
|
20
37
|
* description: "Get the weather for a city.",
|
|
21
|
-
* parameters: {
|
|
22
|
-
* type: "object",
|
|
23
|
-
* properties: { city: { type: "string" } },
|
|
24
|
-
* required: ["city"],
|
|
25
|
-
* },
|
|
38
|
+
* parameters: z.object({ city: z.string() }),
|
|
26
39
|
* execute: async ({ city }) => `Sunny in ${city}`,
|
|
27
40
|
* });
|
|
28
41
|
* ```
|
|
29
42
|
*/
|
|
43
|
+
export function tool<
|
|
44
|
+
const TSchema extends StandardSchemaParameters,
|
|
45
|
+
TResult = any,
|
|
46
|
+
>(
|
|
47
|
+
tool: Tool<StandardSchemaInput<TSchema>, TResult> & { parameters: TSchema },
|
|
48
|
+
): Tool<StandardSchemaInput<TSchema>, TResult>;
|
|
49
|
+
export function tool<TArgs extends Record<string, unknown>, TResult = any>(
|
|
50
|
+
tool: Tool<TArgs, TResult>,
|
|
51
|
+
): Tool<TArgs, TResult>;
|
|
30
52
|
export function tool<TArgs extends Record<string, unknown>, TResult = any>(
|
|
31
53
|
tool: Tool<TArgs, TResult>,
|
|
32
54
|
): Tool<TArgs, TResult> {
|