@assistant-ui/core 0.2.12 → 0.2.15
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.js.map +1 -1
- package/dist/adapters/directive-formatter.js.map +1 -1
- package/dist/adapters/speech.js.map +1 -1
- package/dist/adapters/thread-history.d.ts +3 -1
- package/dist/adapters/thread-history.d.ts.map +1 -1
- package/dist/adapters/voice.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/duplicate-detection.js.map +1 -1
- package/dist/internal.d.ts +2 -1
- package/dist/internal.js +2 -1
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/frame/types.js.map +1 -1
- package/dist/model-context/registry.js.map +1 -1
- package/dist/model-context/tool.js.map +1 -1
- package/dist/model-context/types.d.ts +1 -0
- package/dist/model-context/types.d.ts.map +1 -1
- package/dist/model-context/types.js.map +1 -1
- package/dist/react/AssistantProvider.js +7 -1
- package/dist/react/AssistantProvider.js.map +1 -1
- package/dist/react/AssistantRuntimeProvider.js +18 -6
- package/dist/react/AssistantRuntimeProvider.js.map +1 -1
- package/dist/react/RuntimeAdapter.d.ts +1 -1
- package/dist/react/RuntimeAdapter.d.ts.map +1 -1
- package/dist/react/RuntimeAdapter.js +35 -6
- package/dist/react/RuntimeAdapter.js.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +29 -7
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/adapters/TitleGenerationAdapter.js.map +1 -1
- package/dist/react/client/DataRenderers.d.ts +1 -8
- package/dist/react/client/DataRenderers.d.ts.map +1 -1
- package/dist/react/client/DataRenderers.js +56 -36
- package/dist/react/client/DataRenderers.js.map +1 -1
- package/dist/react/client/Interactables.d.ts +1 -1
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js +71 -70
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/Tools.d.ts +2 -13
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +121 -57
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/client/interactable-model-context.js.map +1 -1
- package/dist/react/model-context/define-mcp-toolkit.js.map +1 -1
- package/dist/react/model-context/define-toolkit.js.map +1 -1
- package/dist/react/model-context/external-tool.js.map +1 -1
- package/dist/react/model-context/human-tool.js.map +1 -1
- package/dist/react/model-context/makeAssistantDataUI.js.map +1 -1
- package/dist/react/model-context/makeAssistantTool.js.map +1 -1
- package/dist/react/model-context/makeAssistantToolUI.js.map +1 -1
- package/dist/react/model-context/provider-tool.js.map +1 -1
- package/dist/react/model-context/stub-tool.js.map +1 -1
- package/dist/react/model-context/toolbox.js.map +1 -1
- package/dist/react/model-context/useAssistantContext.js.map +1 -1
- package/dist/react/model-context/useAssistantDataUI.js +27 -8
- package/dist/react/model-context/useAssistantDataUI.js.map +1 -1
- package/dist/react/model-context/useAssistantInstructions.js +33 -10
- package/dist/react/model-context/useAssistantInstructions.js.map +1 -1
- package/dist/react/model-context/useAssistantInteractable.js.map +1 -1
- package/dist/react/model-context/useAssistantTool.js +59 -17
- package/dist/react/model-context/useAssistantTool.js.map +1 -1
- package/dist/react/model-context/useAssistantToolUI.js +30 -9
- package/dist/react/model-context/useAssistantToolUI.js.map +1 -1
- package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
- package/dist/react/model-context/useInlineRender.js +35 -8
- package/dist/react/model-context/useInlineRender.js.map +1 -1
- package/dist/react/model-context/useInteractableState.js +65 -19
- package/dist/react/model-context/useInteractableState.js.map +1 -1
- package/dist/react/model-context/useToolArgsStatus.js +42 -14
- package/dist/react/model-context/useToolArgsStatus.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.js +59 -22
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js +25 -7
- package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarFeedback.js +49 -13
- package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.js +25 -7
- package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarSpeak.js +28 -9
- package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +25 -7
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.js +27 -11
- package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js +27 -11
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.js +24 -8
- package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.js +25 -7
- package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerDictate.js +25 -7
- package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.js +25 -7
- package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerCancel.js +18 -4
- package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerSend.js +25 -7
- package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageBranching.js +41 -9
- package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.js +4 -1
- package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageReload.js +25 -7
- package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +31 -13
- package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadIsEmpty.js +4 -1
- package/dist/react/primitive-hooks/useThreadIsEmpty.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadIsRunning.js +4 -1
- package/dist/react/primitive-hooks/useThreadIsRunning.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemArchive.js +18 -4
- package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemDelete.js +18 -4
- package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js +18 -4
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +18 -4
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +25 -7
- package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListNew.js +18 -4
- package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadMessages.js +4 -1
- package/dist/react/primitive-hooks/useThreadMessages.js.map +1 -1
- package/dist/react/primitive-hooks/useVoice.js +63 -13
- package/dist/react/primitive-hooks/useVoice.js.map +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +42 -7
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js +67 -16
- package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/react/primitives/composer/ComposerIf.js +30 -9
- package/dist/react/primitives/composer/ComposerIf.js.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
- package/dist/react/primitives/generativeUI/GenerativeUI.js +55 -13
- package/dist/react/primitives/generativeUI/GenerativeUI.js.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.js +68 -16
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.d.ts +3 -2
- package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +6 -6
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.d.ts +28 -1
- package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +665 -163
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/message/MessageQuote.js +18 -2
- package/dist/react/primitives/message/MessageQuote.js.map +1 -1
- package/dist/react/primitives/messagePart/MessagePartInProgress.js +6 -2
- package/dist/react/primitives/messagePart/MessagePartInProgress.js.map +1 -1
- package/dist/react/primitives/part/PartMessages.js +46 -14
- package/dist/react/primitives/part/PartMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js +67 -10
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadSuggestions.js +50 -10
- package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js +55 -14
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.js +15 -2
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.js.map +1 -1
- package/dist/react/providers/AttachmentByIndexProvider.js +57 -12
- package/dist/react/providers/AttachmentByIndexProvider.js.map +1 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +33 -11
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +29 -6
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
- package/dist/react/providers/MessageByIndexProvider.js +49 -19
- package/dist/react/providers/MessageByIndexProvider.js.map +1 -1
- package/dist/react/providers/PartByIndexProvider.js +29 -6
- package/dist/react/providers/PartByIndexProvider.js.map +1 -1
- package/dist/react/providers/QueueItemByIndexProvider.js +29 -6
- package/dist/react/providers/QueueItemByIndexProvider.js.map +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.js +83 -28
- package/dist/react/providers/ReadonlyThreadProvider.js.map +1 -1
- package/dist/react/providers/SuggestionByIndexProvider.js +29 -6
- package/dist/react/providers/SuggestionByIndexProvider.js.map +1 -1
- package/dist/react/providers/TextMessagePartProvider.d.ts.map +1 -1
- package/dist/react/providers/TextMessagePartProvider.js +75 -26
- package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
- package/dist/react/providers/ThreadListItemByIndexProvider.js +30 -6
- package/dist/react/providers/ThreadListItemByIndexProvider.js.map +1 -1
- package/dist/react/providers/ThreadListItemRuntimeProvider.js +28 -5
- package/dist/react/providers/ThreadListItemRuntimeProvider.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +2 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +19 -4
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +2 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +1 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RuntimeAdapterProvider.js +27 -10
- package/dist/react/runtimes/RuntimeAdapterProvider.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +16 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +19 -17
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/createMessageConverter.js.map +1 -1
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +67 -30
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.js +44 -10
- package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreSharedOptions.js +17 -12
- package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +34 -6
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/types/MessagePartComponentTypes.d.ts +5 -6
- package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
- package/dist/react/utils/getMessageQuote.js.map +1 -1
- package/dist/react/utils/groupParts.d.ts +13 -1
- package/dist/react/utils/groupParts.d.ts.map +1 -1
- package/dist/react/utils/groupParts.js +17 -5
- package/dist/react/utils/groupParts.js.map +1 -1
- package/dist/runtime/api/assistant-runtime.js.map +1 -1
- package/dist/runtime/api/attachment-runtime.js.map +1 -1
- package/dist/runtime/api/bindings.d.ts +1 -0
- package/dist/runtime/api/bindings.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.js.map +1 -1
- package/dist/runtime/api/message-part-runtime.d.ts +3 -9
- package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-part-runtime.js +3 -6
- package/dist/runtime/api/message-part-runtime.js.map +1 -1
- package/dist/runtime/api/message-runtime.d.ts +2 -0
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +5 -0
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +1 -0
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +3 -0
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.js +4 -0
- package/dist/runtime/api/thread-runtime.js.map +1 -1
- package/dist/runtime/base/base-assistant-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -0
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/branch/external-thread-branch-adapter.d.ts +30 -0
- package/dist/runtime/branch/external-thread-branch-adapter.d.ts.map +1 -0
- package/dist/runtime/branch/external-thread-branch-adapter.js +0 -0
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +1 -0
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +4 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.js.map +1 -1
- package/dist/runtime/utils/auto-status.js.map +1 -1
- package/dist/runtime/utils/external-store-message.js.map +1 -1
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +15 -0
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -0
- package/dist/runtime/utils/resolveToolApprovalResponse.js +35 -0
- package/dist/runtime/utils/resolveToolApprovalResponse.js.map +1 -0
- package/dist/runtime/utils/thread-message-like.d.ts +5 -1
- package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/assistant-transport/utils.js.map +1 -1
- package/dist/runtimes/external-store/external-store-adapter.d.ts +1 -0
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/external-store-shared-options.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +1 -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 +13 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/thread-message-converter.js.map +1 -1
- package/dist/runtimes/local/local-runtime-core.js.map +1 -1
- package/dist/runtimes/local/local-runtime-options.d.ts +1 -1
- package/dist/runtimes/local/local-thread-list-runtime-core.js.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +9 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +65 -5
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/local/should-continue.js +4 -2
- package/dist/runtimes/local/should-continue.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +2 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +4 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js +4 -0
- package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +1 -0
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.js +1 -0
- package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts +2 -7
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.js +39 -20
- package/dist/store/clients/chain-of-thought-client.js.map +1 -1
- package/dist/store/clients/model-context-client.d.ts +1 -1
- package/dist/store/clients/model-context-client.d.ts.map +1 -1
- package/dist/store/clients/model-context-client.js +67 -16
- package/dist/store/clients/model-context-client.js.map +1 -1
- package/dist/store/clients/no-op-composer-client.d.ts +2 -4
- package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
- package/dist/store/clients/no-op-composer-client.js +96 -54
- package/dist/store/clients/no-op-composer-client.js.map +1 -1
- package/dist/store/clients/runtime-adapter.d.ts +1 -3
- package/dist/store/clients/runtime-adapter.d.ts.map +1 -1
- package/dist/store/clients/runtime-adapter.js +2 -15
- package/dist/store/clients/runtime-adapter.js.map +1 -1
- package/dist/store/clients/suggestions.d.ts +1 -4
- package/dist/store/clients/suggestions.d.ts.map +1 -1
- package/dist/store/clients/suggestions.js +63 -23
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-message-client.d.ts +1 -1
- package/dist/store/clients/thread-message-client.d.ts.map +1 -1
- package/dist/store/clients/thread-message-client.js +184 -73
- package/dist/store/clients/thread-message-client.js.map +1 -1
- package/dist/store/internal.d.ts +2 -2
- package/dist/store/internal.js +2 -2
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts +2 -4
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.js +31 -7
- package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts +2 -10
- package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +195 -72
- package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/liveRef.d.ts +7 -0
- package/dist/store/runtime-clients/liveRef.d.ts.map +1 -0
- package/dist/store/runtime-clients/liveRef.js +8 -0
- package/dist/store/runtime-clients/liveRef.js.map +1 -0
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts +2 -4
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-part-runtime-client.js +49 -9
- package/dist/store/runtime-clients/message-part-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts +2 -7
- package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +220 -54
- package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts +2 -4
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +71 -26
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts +2 -5
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +141 -36
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts +2 -4
- package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +196 -72
- package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/useSubscribable.js +2 -9
- package/dist/store/runtime-clients/useSubscribable.js.map +1 -1
- package/dist/store/scopes/message.d.ts +1 -0
- package/dist/store/scopes/message.d.ts.map +1 -1
- package/dist/store/scopes/part.d.ts +5 -6
- package/dist/store/scopes/part.d.ts.map +1 -1
- package/dist/store/scopes/queue-item.js.map +1 -1
- package/dist/store/scopes/thread-list-item.d.ts +1 -0
- package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
- package/dist/store/scopes/thread.d.ts +1 -0
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/tests/remote-thread-list-test-helpers.js.map +1 -1
- package/dist/types/message.d.ts +38 -5
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/composite-context-provider.js.map +1 -1
- package/dist/utils/id.js.map +1 -1
- package/dist/utils/json/is-json-equal.js.map +1 -1
- package/dist/utils/json/is-json.js.map +1 -1
- package/dist/utils/text.js.map +1 -1
- package/package.json +6 -6
- package/src/adapters/thread-history.ts +2 -0
- package/src/index.ts +5 -0
- package/src/internal.ts +1 -0
- package/src/model-context/types.ts +1 -0
- package/src/react/AssistantProvider.tsx +10 -1
- package/src/react/RuntimeAdapter.ts +25 -8
- package/src/react/client/DataRenderers.ts +42 -45
- package/src/react/client/Interactables.ts +261 -261
- package/src/react/client/Tools.ts +9 -9
- package/src/react/primitives/message/MessageGroupedParts.tsx +19 -7
- package/src/react/primitives/message/MessageParts.tsx +64 -13
- package/src/react/providers/TextMessagePartProvider.tsx +5 -3
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +1 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +11 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +6 -0
- package/src/react/runtimes/external-message-converter.ts +3 -1
- package/src/react/types/MessagePartComponentTypes.ts +5 -5
- package/src/react/utils/groupParts.ts +27 -0
- package/src/runtime/api/bindings.ts +1 -0
- package/src/runtime/api/message-part-runtime.ts +14 -11
- package/src/runtime/api/message-runtime.ts +7 -0
- package/src/runtime/api/thread-list-runtime.ts +1 -0
- package/src/runtime/api/thread-runtime.ts +7 -0
- package/src/runtime/base/base-thread-runtime-core.ts +1 -0
- package/src/runtime/branch/external-thread-branch-adapter.ts +26 -0
- package/src/runtime/interfaces/thread-list-runtime-core.ts +1 -0
- package/src/runtime/interfaces/thread-runtime-core.ts +4 -0
- package/src/runtime/utils/resolveToolApprovalResponse.test.ts +91 -0
- package/src/runtime/utils/resolveToolApprovalResponse.ts +55 -0
- package/src/runtime/utils/thread-message-like.ts +10 -1
- package/src/runtimes/external-store/external-store-adapter.ts +1 -0
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +24 -0
- package/src/runtimes/local/local-runtime-options.ts +1 -1
- package/src/runtimes/local/local-thread-runtime-core.test.ts +370 -0
- package/src/runtimes/local/local-thread-runtime-core.ts +113 -7
- package/src/runtimes/local/should-continue.ts +24 -13
- package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +5 -0
- package/src/runtimes/remote-thread-list/empty-thread-core.ts +5 -0
- package/src/runtimes/remote-thread-list/remote-thread-state.ts +2 -0
- package/src/runtimes/remote-thread-list/types.ts +1 -0
- package/src/store/clients/chain-of-thought-client.ts +5 -3
- package/src/store/clients/model-context-client.test.ts +5 -4
- package/src/store/clients/model-context-client.ts +21 -21
- package/src/store/clients/no-op-composer-client.ts +5 -3
- package/src/store/clients/runtime-adapter.ts +0 -24
- package/src/store/clients/suggestions.ts +12 -23
- package/src/store/clients/thread-message-client.ts +42 -40
- package/src/store/internal.ts +1 -4
- package/src/store/runtime-clients/attachment-runtime-client.ts +14 -14
- package/src/store/runtime-clients/composer-runtime-client.ts +48 -45
- package/src/store/runtime-clients/liveRef.ts +5 -0
- package/src/store/runtime-clients/message-part-runtime-client.ts +5 -3
- package/src/store/runtime-clients/message-runtime-client.ts +42 -40
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +5 -3
- package/src/store/runtime-clients/thread-list-runtime-client.ts +13 -11
- package/src/store/runtime-clients/thread-runtime-client.ts +20 -16
- package/src/store/runtime-clients/useSubscribable.ts +2 -10
- package/src/store/scopes/message.ts +1 -0
- package/src/store/scopes/part.ts +5 -2
- package/src/store/scopes/thread-list-item.ts +1 -0
- package/src/store/scopes/thread.ts +1 -0
- package/src/tests/external-store-thread-runtime-core.test.ts +57 -0
- package/src/tests/groupMessageParts.test.ts +84 -0
- package/src/tests/groupParts.test.ts +55 -0
- package/src/types/message.ts +45 -3
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { resolveToolApprovalResponse } from "./resolveToolApprovalResponse";
|
|
3
|
+
|
|
4
|
+
const approval = {
|
|
5
|
+
id: "a1",
|
|
6
|
+
options: [
|
|
7
|
+
{ id: "once", kind: "allow-once" as const },
|
|
8
|
+
{ id: "always", kind: "allow-always" as const, grants: ["git *"] },
|
|
9
|
+
{ id: "deny", kind: "reject-once" as const },
|
|
10
|
+
{ id: "never", kind: "reject-always" as const },
|
|
11
|
+
{ id: "edit", kind: "_modify" },
|
|
12
|
+
],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe("resolveToolApprovalResponse", () => {
|
|
16
|
+
it("passes through boolean responses", () => {
|
|
17
|
+
expect(resolveToolApprovalResponse(approval, { approved: true })).toEqual({
|
|
18
|
+
approvalId: "a1",
|
|
19
|
+
approved: true,
|
|
20
|
+
});
|
|
21
|
+
expect(
|
|
22
|
+
resolveToolApprovalResponse(approval, {
|
|
23
|
+
approved: false,
|
|
24
|
+
reason: "nope",
|
|
25
|
+
}),
|
|
26
|
+
).toEqual({ approvalId: "a1", approved: false, reason: "nope" });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("resolves allow kinds to approved: true", () => {
|
|
30
|
+
expect(resolveToolApprovalResponse(approval, { optionId: "once" })).toEqual(
|
|
31
|
+
{ approvalId: "a1", approved: true, optionId: "once" },
|
|
32
|
+
);
|
|
33
|
+
expect(
|
|
34
|
+
resolveToolApprovalResponse(approval, { optionId: "always" }),
|
|
35
|
+
).toEqual({ approvalId: "a1", approved: true, optionId: "always" });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("resolves reject kinds to approved: false and keeps the reason", () => {
|
|
39
|
+
expect(
|
|
40
|
+
resolveToolApprovalResponse(approval, {
|
|
41
|
+
optionId: "deny",
|
|
42
|
+
reason: "not now",
|
|
43
|
+
}),
|
|
44
|
+
).toEqual({
|
|
45
|
+
approvalId: "a1",
|
|
46
|
+
approved: false,
|
|
47
|
+
optionId: "deny",
|
|
48
|
+
reason: "not now",
|
|
49
|
+
});
|
|
50
|
+
expect(
|
|
51
|
+
resolveToolApprovalResponse(approval, { optionId: "never" }),
|
|
52
|
+
).toEqual({ approvalId: "a1", approved: false, optionId: "never" });
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("throws for an unknown option id", () => {
|
|
56
|
+
expect(() =>
|
|
57
|
+
resolveToolApprovalResponse(approval, { optionId: "missing" }),
|
|
58
|
+
).toThrow('no option with id "missing"');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("throws for custom kinds instead of guessing a boolean", () => {
|
|
62
|
+
expect(() =>
|
|
63
|
+
resolveToolApprovalResponse(approval, { optionId: "edit" }),
|
|
64
|
+
).toThrow('custom kind "_modify"');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("accepts an explicit approved alongside the optionId for custom kinds", () => {
|
|
68
|
+
expect(
|
|
69
|
+
resolveToolApprovalResponse(approval, {
|
|
70
|
+
optionId: "edit",
|
|
71
|
+
approved: true,
|
|
72
|
+
}),
|
|
73
|
+
).toEqual({ approvalId: "a1", approved: true, optionId: "edit" });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("does not resolve kinds named after Object.prototype members", () => {
|
|
77
|
+
const trap = {
|
|
78
|
+
id: "a3",
|
|
79
|
+
options: [{ id: "x", kind: "constructor" }],
|
|
80
|
+
};
|
|
81
|
+
expect(() => resolveToolApprovalResponse(trap, { optionId: "x" })).toThrow(
|
|
82
|
+
'custom kind "constructor"',
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("throws for option responses when the approval has no options", () => {
|
|
87
|
+
expect(() =>
|
|
88
|
+
resolveToolApprovalResponse({ id: "a2" }, { optionId: "once" }),
|
|
89
|
+
).toThrow('no option with id "once"');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ToolApprovalOption,
|
|
3
|
+
ToolApprovalResponse,
|
|
4
|
+
} from "../../types/message";
|
|
5
|
+
import type { RespondToToolApprovalOptions } from "../interfaces/thread-runtime-core";
|
|
6
|
+
|
|
7
|
+
const APPROVED_BY_KIND: Record<string, boolean> = {
|
|
8
|
+
"allow-once": true,
|
|
9
|
+
"allow-always": true,
|
|
10
|
+
"reject-once": false,
|
|
11
|
+
"reject-always": false,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Resolves a renderer-facing approval response (boolean or optionId form)
|
|
16
|
+
* against the approval's option list into the runtime-facing decision shape.
|
|
17
|
+
*/
|
|
18
|
+
export const resolveToolApprovalResponse = (
|
|
19
|
+
approval: {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly options?: readonly ToolApprovalOption[];
|
|
22
|
+
},
|
|
23
|
+
response: ToolApprovalResponse,
|
|
24
|
+
): RespondToToolApprovalOptions => {
|
|
25
|
+
let approved: boolean;
|
|
26
|
+
let optionId: string | undefined;
|
|
27
|
+
|
|
28
|
+
if ("optionId" in response) {
|
|
29
|
+
const option = approval.options?.find((o) => o.id === response.optionId);
|
|
30
|
+
if (!option)
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Tool approval has no option with id "${response.optionId}"`,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if ("approved" in response) {
|
|
36
|
+
approved = response.approved;
|
|
37
|
+
} else {
|
|
38
|
+
if (!Object.hasOwn(APPROVED_BY_KIND, option.kind))
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Tool approval option "${option.id}" has a custom kind "${option.kind}"; respond with an explicit approved value instead`,
|
|
41
|
+
);
|
|
42
|
+
approved = APPROVED_BY_KIND[option.kind]!;
|
|
43
|
+
}
|
|
44
|
+
optionId = option.id;
|
|
45
|
+
} else {
|
|
46
|
+
approved = response.approved;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
approvalId: approval.id,
|
|
51
|
+
approved,
|
|
52
|
+
...(optionId !== undefined && { optionId }),
|
|
53
|
+
...(response.reason != null && { reason: response.reason }),
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -18,7 +18,12 @@ import type {
|
|
|
18
18
|
Unstable_AudioMessagePart,
|
|
19
19
|
} from "../../types/message";
|
|
20
20
|
import type { CompleteAttachment } from "../../types/attachment";
|
|
21
|
-
import type {
|
|
21
|
+
import type {
|
|
22
|
+
MessageTiming,
|
|
23
|
+
TextMessagePart,
|
|
24
|
+
ToolApprovalOption,
|
|
25
|
+
ToolCallTiming,
|
|
26
|
+
} from "../../types/message";
|
|
22
27
|
import type {
|
|
23
28
|
ReadonlyJSONObject,
|
|
24
29
|
ReadonlyJSONValue,
|
|
@@ -55,11 +60,15 @@ export type ThreadMessageLike = {
|
|
|
55
60
|
readonly parentId?: string | undefined;
|
|
56
61
|
readonly messages?: readonly ThreadMessage[] | undefined;
|
|
57
62
|
readonly interrupt?: { type: "human"; payload: unknown };
|
|
63
|
+
readonly timing?: ToolCallTiming;
|
|
58
64
|
readonly approval?: {
|
|
59
65
|
readonly id: string;
|
|
60
66
|
readonly approved?: boolean;
|
|
61
67
|
readonly reason?: string;
|
|
62
68
|
readonly isAutomatic?: boolean;
|
|
69
|
+
readonly options?: readonly ToolApprovalOption[];
|
|
70
|
+
readonly optionId?: string;
|
|
71
|
+
readonly resolution?: "cancelled" | "expired";
|
|
63
72
|
};
|
|
64
73
|
}
|
|
65
74
|
)[];
|
|
@@ -109,6 +109,7 @@ type ExternalStoreAdapterBase<T> = {
|
|
|
109
109
|
/** Opt in to message queuing. Typically produced by `createMessageQueue`. */
|
|
110
110
|
queue?: ExternalThreadQueueAdapter | undefined;
|
|
111
111
|
onEdit?: ((message: AppendMessage) => Promise<void>) | undefined;
|
|
112
|
+
onDelete?: ((messageId: string) => Promise<void> | void) | undefined;
|
|
112
113
|
onReload?: // TODO: remove parentId in 0.12.0
|
|
113
114
|
| ((parentId: string | null, config: StartRunConfig) => Promise<void>)
|
|
114
115
|
| undefined;
|
|
@@ -60,6 +60,7 @@ export class ExternalStoreThreadRuntimeCore
|
|
|
60
60
|
switchToBranch: false,
|
|
61
61
|
switchBranchDuringRun: false,
|
|
62
62
|
edit: false,
|
|
63
|
+
delete: false,
|
|
63
64
|
reload: false,
|
|
64
65
|
cancel: false,
|
|
65
66
|
unstable_copy: false,
|
|
@@ -148,6 +149,9 @@ export class ExternalStoreThreadRuntimeCore
|
|
|
148
149
|
switchToBranch: this._store.setMessages !== undefined,
|
|
149
150
|
switchBranchDuringRun: false,
|
|
150
151
|
edit: this._store.onEdit !== undefined,
|
|
152
|
+
delete:
|
|
153
|
+
this._store.onDelete !== undefined ||
|
|
154
|
+
this._store.setMessages !== undefined,
|
|
151
155
|
reload: this._store.onReload !== undefined,
|
|
152
156
|
cancel: this._store.onCancel !== undefined,
|
|
153
157
|
speech: this._store.adapters?.speech !== undefined,
|
|
@@ -419,6 +423,26 @@ export class ExternalStoreThreadRuntimeCore
|
|
|
419
423
|
}
|
|
420
424
|
}
|
|
421
425
|
|
|
426
|
+
public async deleteMessage(messageId: string): Promise<void> {
|
|
427
|
+
if (this._store.onDelete) {
|
|
428
|
+
await this._store.onDelete(messageId);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (!this._store.setMessages)
|
|
433
|
+
throw new Error("Runtime does not support deleting messages.");
|
|
434
|
+
|
|
435
|
+
if (this._store.isRunning) {
|
|
436
|
+
await this._toolInvocations?.abort();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const messages = this.repository.getMessages();
|
|
440
|
+
const messageIndex = messages.findIndex((m) => m.id === messageId);
|
|
441
|
+
if (messageIndex === -1) throw new Error("Message not found.");
|
|
442
|
+
|
|
443
|
+
this.updateMessages(messages.filter((message) => message.id !== messageId));
|
|
444
|
+
}
|
|
445
|
+
|
|
422
446
|
public getQueueItems() {
|
|
423
447
|
// The composer reads this during base-thread construction, before the
|
|
424
448
|
// constructor assigns `_store`, so guard against the unset field.
|
|
@@ -23,7 +23,7 @@ export type LocalRuntimeOptionsBase = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* Names of tools that
|
|
26
|
+
* Names of tools that pause the run until a result is supplied via `addToolResult`.
|
|
27
27
|
*/
|
|
28
28
|
unstable_humanToolNames?: string[] | undefined;
|
|
29
29
|
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { LocalRuntimeCore } from "./local-runtime-core";
|
|
3
|
+
import type {
|
|
4
|
+
ChatModelAdapter,
|
|
5
|
+
ChatModelRunOptions,
|
|
6
|
+
ChatModelRunResult,
|
|
7
|
+
} from "../../runtime/utils/chat-model-adapter";
|
|
8
|
+
import type { AppendMessage } from "../../types/message";
|
|
9
|
+
|
|
10
|
+
const flush = () => new Promise((resolve) => setTimeout(resolve, 10));
|
|
11
|
+
|
|
12
|
+
const createThread = (adapter: ChatModelAdapter) => {
|
|
13
|
+
const core = new LocalRuntimeCore(
|
|
14
|
+
{
|
|
15
|
+
adapters: { chatModel: adapter },
|
|
16
|
+
unstable_humanToolNames: ["send_email"],
|
|
17
|
+
},
|
|
18
|
+
undefined,
|
|
19
|
+
);
|
|
20
|
+
return core.threads.getMainThreadRuntimeCore();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const userMessage = (text: string): AppendMessage => ({
|
|
24
|
+
parentId: null,
|
|
25
|
+
sourceId: null,
|
|
26
|
+
runConfig: {},
|
|
27
|
+
role: "user",
|
|
28
|
+
content: [{ type: "text", text }],
|
|
29
|
+
attachments: [],
|
|
30
|
+
metadata: { custom: {} },
|
|
31
|
+
createdAt: new Date(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const toolCallPart = (
|
|
35
|
+
toolName: string,
|
|
36
|
+
approval?: { id: string; resolution?: "cancelled" | "expired" },
|
|
37
|
+
) => ({
|
|
38
|
+
type: "tool-call" as const,
|
|
39
|
+
toolCallId: `call-${toolName}`,
|
|
40
|
+
toolName,
|
|
41
|
+
args: {},
|
|
42
|
+
argsText: "{}",
|
|
43
|
+
...(approval !== undefined ? { approval } : {}),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const toolCallResult = (
|
|
47
|
+
toolName: string,
|
|
48
|
+
approval?: { id: string; resolution?: "cancelled" | "expired" },
|
|
49
|
+
): ChatModelRunResult => ({
|
|
50
|
+
content: [toolCallPart(toolName, approval)],
|
|
51
|
+
status: { type: "requires-action", reason: "tool-calls" },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const createApprovalThread = (firstResult: ChatModelRunResult) => {
|
|
55
|
+
const runs: ChatModelRunOptions[] = [];
|
|
56
|
+
const thread = createThread({
|
|
57
|
+
async run(options) {
|
|
58
|
+
runs.push(options);
|
|
59
|
+
if (runs.length === 1) return firstResult;
|
|
60
|
+
return { content: [{ type: "text", text: "done" }] };
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return { thread, runs };
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
describe("LocalThreadRuntimeCore human-in-the-loop tools", () => {
|
|
67
|
+
it("pauses on requires-action while a listed tool call has no result", async () => {
|
|
68
|
+
const { thread, runs } = createApprovalThread(toolCallResult("send_email"));
|
|
69
|
+
|
|
70
|
+
await thread.append(userMessage("send an email"));
|
|
71
|
+
await flush();
|
|
72
|
+
|
|
73
|
+
expect(runs).toHaveLength(1);
|
|
74
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("requires-action");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("does not hold the run for unlisted tool calls", async () => {
|
|
78
|
+
const { thread, runs } = createApprovalThread(
|
|
79
|
+
toolCallResult("lookup_weather"),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
await thread.append(userMessage("what is the weather"));
|
|
83
|
+
await flush();
|
|
84
|
+
|
|
85
|
+
expect(runs).toHaveLength(2);
|
|
86
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("resumes via addToolResult and exposes the result to the adapter", async () => {
|
|
90
|
+
const { thread, runs } = createApprovalThread(toolCallResult("send_email"));
|
|
91
|
+
|
|
92
|
+
await thread.append(userMessage("send an email"));
|
|
93
|
+
await flush();
|
|
94
|
+
|
|
95
|
+
const assistantMessage = thread.messages.at(-1)!;
|
|
96
|
+
thread.addToolResult({
|
|
97
|
+
messageId: assistantMessage.id,
|
|
98
|
+
toolCallId: "call-send_email",
|
|
99
|
+
toolName: "send_email",
|
|
100
|
+
result: { approved: true },
|
|
101
|
+
isError: false,
|
|
102
|
+
});
|
|
103
|
+
await flush();
|
|
104
|
+
|
|
105
|
+
expect(runs).toHaveLength(2);
|
|
106
|
+
const resumed = runs[1]!;
|
|
107
|
+
expect(resumed.messages.at(-1)?.role).toBe("user");
|
|
108
|
+
const toolCall = resumed
|
|
109
|
+
.unstable_getMessage()
|
|
110
|
+
.content.find((part) => part.type === "tool-call");
|
|
111
|
+
expect(toolCall?.result).toEqual({ approved: true });
|
|
112
|
+
|
|
113
|
+
const finalMessage = thread.messages.at(-1)!;
|
|
114
|
+
expect(finalMessage.status?.type).toBe("complete");
|
|
115
|
+
expect(finalMessage.content.map((part) => part.type)).toEqual([
|
|
116
|
+
"tool-call",
|
|
117
|
+
"text",
|
|
118
|
+
]);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("LocalThreadRuntimeCore tool approvals", () => {
|
|
123
|
+
it("pauses the run while an approval is pending, even for unlisted tools", async () => {
|
|
124
|
+
const { thread, runs } = createApprovalThread(
|
|
125
|
+
toolCallResult("deploy", { id: "a1" }),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
await thread.append(userMessage("deploy the app"));
|
|
129
|
+
await flush();
|
|
130
|
+
|
|
131
|
+
expect(runs).toHaveLength(1);
|
|
132
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("requires-action");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("records an approval and resumes, exempting the gated tool from the human tool result requirement", async () => {
|
|
136
|
+
const { thread, runs } = createApprovalThread(
|
|
137
|
+
toolCallResult("send_email", { id: "a1" }),
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
await thread.append(userMessage("send an email"));
|
|
141
|
+
await flush();
|
|
142
|
+
|
|
143
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: true });
|
|
144
|
+
await flush();
|
|
145
|
+
|
|
146
|
+
expect(runs).toHaveLength(2);
|
|
147
|
+
const toolCall = runs[1]!
|
|
148
|
+
.unstable_getMessage()
|
|
149
|
+
.content.find((part) => part.type === "tool-call");
|
|
150
|
+
expect(toolCall?.approval).toEqual({ id: "a1", approved: true });
|
|
151
|
+
expect(toolCall?.result).toBeUndefined();
|
|
152
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("records the chosen optionId alongside the decision", async () => {
|
|
156
|
+
const { thread, runs } = createApprovalThread(
|
|
157
|
+
toolCallResult("send_email", { id: "a1" }),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
await thread.append(userMessage("send an email"));
|
|
161
|
+
await flush();
|
|
162
|
+
|
|
163
|
+
thread.respondToToolApproval({
|
|
164
|
+
approvalId: "a1",
|
|
165
|
+
approved: true,
|
|
166
|
+
optionId: "always",
|
|
167
|
+
});
|
|
168
|
+
await flush();
|
|
169
|
+
|
|
170
|
+
expect(runs).toHaveLength(2);
|
|
171
|
+
const toolCall = runs[1]!
|
|
172
|
+
.unstable_getMessage()
|
|
173
|
+
.content.find((part) => part.type === "tool-call");
|
|
174
|
+
expect(toolCall?.approval).toEqual({
|
|
175
|
+
id: "a1",
|
|
176
|
+
approved: true,
|
|
177
|
+
optionId: "always",
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("treats a terminal resolution as non-pending and continues the run", async () => {
|
|
182
|
+
const { thread, runs } = createApprovalThread(
|
|
183
|
+
toolCallResult("deploy", { id: "a1", resolution: "expired" }),
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
await thread.append(userMessage("deploy the app"));
|
|
187
|
+
await flush();
|
|
188
|
+
|
|
189
|
+
expect(runs).toHaveLength(2);
|
|
190
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("rejects responses to approvals with a terminal resolution", async () => {
|
|
194
|
+
const { thread } = createApprovalThread({
|
|
195
|
+
content: [
|
|
196
|
+
toolCallPart("deploy", { id: "a1", resolution: "expired" }),
|
|
197
|
+
toolCallPart("send_email"),
|
|
198
|
+
],
|
|
199
|
+
status: { type: "requires-action", reason: "tool-calls" },
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
await thread.append(userMessage("deploy and email"));
|
|
203
|
+
await flush();
|
|
204
|
+
|
|
205
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("requires-action");
|
|
206
|
+
expect(() =>
|
|
207
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: true }),
|
|
208
|
+
).toThrow("cancelled or expired");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("continues multi-step turns after an approval resume", async () => {
|
|
212
|
+
const runs: ChatModelRunOptions[] = [];
|
|
213
|
+
const thread = createThread({
|
|
214
|
+
async run(options) {
|
|
215
|
+
runs.push(options);
|
|
216
|
+
if (runs.length === 1) return toolCallResult("deploy", { id: "a1" });
|
|
217
|
+
if (runs.length === 2) return toolCallResult("lookup_weather");
|
|
218
|
+
return { content: [{ type: "text", text: "done" }] };
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
await thread.append(userMessage("deploy the app"));
|
|
223
|
+
await flush();
|
|
224
|
+
|
|
225
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: true });
|
|
226
|
+
await flush();
|
|
227
|
+
|
|
228
|
+
expect(runs).toHaveLength(3);
|
|
229
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("resumes when a result is added to an approval-gated tool call", async () => {
|
|
233
|
+
const { thread, runs } = createApprovalThread(
|
|
234
|
+
toolCallResult("deploy", { id: "a1" }),
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
await thread.append(userMessage("deploy the app"));
|
|
238
|
+
await flush();
|
|
239
|
+
|
|
240
|
+
thread.addToolResult({
|
|
241
|
+
messageId: thread.messages.at(-1)!.id,
|
|
242
|
+
toolCallId: "call-deploy",
|
|
243
|
+
toolName: "deploy",
|
|
244
|
+
result: "done manually",
|
|
245
|
+
isError: false,
|
|
246
|
+
});
|
|
247
|
+
await flush();
|
|
248
|
+
|
|
249
|
+
expect(runs).toHaveLength(2);
|
|
250
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("records a denial and synthesizes an error result", async () => {
|
|
254
|
+
const { thread, runs } = createApprovalThread(
|
|
255
|
+
toolCallResult("deploy", { id: "a1" }),
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
await thread.append(userMessage("deploy the app"));
|
|
259
|
+
await flush();
|
|
260
|
+
|
|
261
|
+
thread.respondToToolApproval({
|
|
262
|
+
approvalId: "a1",
|
|
263
|
+
approved: false,
|
|
264
|
+
reason: "not today",
|
|
265
|
+
});
|
|
266
|
+
await flush();
|
|
267
|
+
|
|
268
|
+
expect(runs).toHaveLength(2);
|
|
269
|
+
const toolCall = thread.messages
|
|
270
|
+
.at(-1)!
|
|
271
|
+
.content.find((part) => part.type === "tool-call");
|
|
272
|
+
expect(toolCall?.approval).toEqual({
|
|
273
|
+
id: "a1",
|
|
274
|
+
approved: false,
|
|
275
|
+
reason: "not today",
|
|
276
|
+
});
|
|
277
|
+
expect(toolCall?.result).toEqual({ error: "not today" });
|
|
278
|
+
expect(toolCall?.isError).toBe(true);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("synthesizes a default denial reason", async () => {
|
|
282
|
+
const { thread } = createApprovalThread(
|
|
283
|
+
toolCallResult("deploy", { id: "a1" }),
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
await thread.append(userMessage("deploy the app"));
|
|
287
|
+
await flush();
|
|
288
|
+
|
|
289
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: false });
|
|
290
|
+
await flush();
|
|
291
|
+
|
|
292
|
+
const toolCall = thread.messages
|
|
293
|
+
.at(-1)!
|
|
294
|
+
.content.find((part) => part.type === "tool-call");
|
|
295
|
+
expect(toolCall?.result).toEqual({ error: "Tool approval denied" });
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("waits until every pending approval is decided before resuming", async () => {
|
|
299
|
+
const { thread, runs } = createApprovalThread({
|
|
300
|
+
content: [
|
|
301
|
+
toolCallPart("deploy", { id: "a1" }),
|
|
302
|
+
toolCallPart("send_invoice", { id: "a2" }),
|
|
303
|
+
],
|
|
304
|
+
status: { type: "requires-action", reason: "tool-calls" },
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
await thread.append(userMessage("deploy and bill"));
|
|
308
|
+
await flush();
|
|
309
|
+
|
|
310
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: true });
|
|
311
|
+
await flush();
|
|
312
|
+
expect(runs).toHaveLength(1);
|
|
313
|
+
|
|
314
|
+
expect(() =>
|
|
315
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: false }),
|
|
316
|
+
).toThrowError(/already decided/);
|
|
317
|
+
|
|
318
|
+
thread.respondToToolApproval({ approvalId: "a2", approved: false });
|
|
319
|
+
await flush();
|
|
320
|
+
expect(runs).toHaveLength(2);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("throws while the run is still in flight, even if the message already reads requires-action", async () => {
|
|
324
|
+
let release!: () => void;
|
|
325
|
+
const gate = new Promise<void>((resolve) => (release = resolve));
|
|
326
|
+
const runs: ChatModelRunOptions[] = [];
|
|
327
|
+
const thread = createThread({
|
|
328
|
+
async *run(options) {
|
|
329
|
+
runs.push(options);
|
|
330
|
+
if (runs.length === 1) {
|
|
331
|
+
yield toolCallResult("deploy", { id: "a1" });
|
|
332
|
+
await gate;
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
yield { content: [{ type: "text", text: "done" }] };
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
const appendPromise = thread.append(userMessage("deploy the app"));
|
|
340
|
+
await flush();
|
|
341
|
+
|
|
342
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("requires-action");
|
|
343
|
+
expect(() =>
|
|
344
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: true }),
|
|
345
|
+
).toThrowError(/run is in progress/);
|
|
346
|
+
|
|
347
|
+
release();
|
|
348
|
+
await appendPromise;
|
|
349
|
+
|
|
350
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: true });
|
|
351
|
+
await flush();
|
|
352
|
+
|
|
353
|
+
expect(runs).toHaveLength(2);
|
|
354
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("throws for unknown approvals and unsupported tool call resumption", async () => {
|
|
358
|
+
const { thread } = createApprovalThread(toolCallResult("send_email"));
|
|
359
|
+
|
|
360
|
+
await thread.append(userMessage("send an email"));
|
|
361
|
+
await flush();
|
|
362
|
+
|
|
363
|
+
expect(() =>
|
|
364
|
+
thread.respondToToolApproval({ approvalId: "nope", approved: true }),
|
|
365
|
+
).toThrowError(/non-existing tool approval/);
|
|
366
|
+
expect(() =>
|
|
367
|
+
thread.resumeToolCall({ toolCallId: "call-send_email", payload: {} }),
|
|
368
|
+
).toThrowError(/unstable_humanToolNames/);
|
|
369
|
+
});
|
|
370
|
+
});
|