@assistant-ui/core 0.3.15 → 0.3.17
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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +8 -2
- package/dist/internal.js +9 -3
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +3 -2
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/frame/provider.d.ts +5 -0
- package/dist/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +141 -28
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/interactable-composer-metadata.d.ts +1 -1
- package/dist/model-context/interactable-composer-metadata.js +1 -1
- package/dist/model-context/interactable-composer-metadata.js.map +1 -1
- package/dist/model-context/registry.d.ts +2 -2
- package/dist/model-context/registry.d.ts.map +1 -1
- package/dist/model-context/registry.js +9 -28
- package/dist/model-context/registry.js.map +1 -1
- package/dist/model-context/tool-call-text.d.ts +26 -0
- package/dist/model-context/tool-call-text.d.ts.map +1 -0
- package/dist/model-context/tool-call-text.js +18 -0
- package/dist/model-context/tool-call-text.js.map +1 -0
- package/dist/react/RuntimeAdapter.js +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/AdaptedRemoteThread.js +1 -1
- package/dist/react/client/InMemoryThreadList.d.ts.map +1 -1
- package/dist/react/client/InMemoryThreadList.js +25 -21
- package/dist/react/client/InMemoryThreadList.js.map +1 -1
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js +60 -178
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/RemoteThreadList.d.ts +15 -0
- package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
- package/dist/react/client/RemoteThreadList.js +263 -194
- package/dist/react/client/RemoteThreadList.js.map +1 -1
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +6 -2
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +4 -2
- package/dist/react/index.js +2 -1
- package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -1
- package/dist/react/interactables-legacy/Interactables.js +60 -178
- package/dist/react/interactables-legacy/Interactables.js.map +1 -1
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts +24 -0
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts.map +1 -0
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.js +138 -0
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.js.map +1 -0
- package/dist/react/model-context/toolbox.d.ts +2 -14
- package/dist/react/model-context/toolbox.d.ts.map +1 -1
- package/dist/react/model-context/toolbox.js +1 -13
- package/dist/react/model-context/toolbox.js.map +1 -1
- package/dist/react/model-context/useAssistantContext.js +37 -7
- package/dist/react/model-context/useAssistantContext.js.map +1 -1
- package/dist/react/model-context/useAuiToolOverrides.js +31 -5
- package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
- package/dist/react/model-context/useInlineRender.d.ts.map +1 -1
- package/dist/react/model-context/useInlineRender.js +10 -36
- package/dist/react/model-context/useInlineRender.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.js +2 -8
- package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +2 -4
- package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js +4 -3
- package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/react/primitives/composer/ComposerIf.js.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.d.ts +2 -1
- package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js +4 -3
- package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.js +7 -6
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +2 -2
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +3 -3
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.d.ts.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js +5 -4
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +7 -5
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +44 -22
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +7 -6
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +102 -117
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.d.ts +1 -6
- package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.js +3 -3
- package/dist/react/runtimes/RemoteThreadResource.js.map +1 -1
- package/dist/react/runtimes/assistant-transport/runManager.d.ts.map +1 -1
- package/dist/react/runtimes/assistant-transport/runManager.js +2 -12
- package/dist/react/runtimes/assistant-transport/runManager.js.map +1 -1
- package/dist/react/runtimes/assistant-transport/useLatestRef.js +2 -2
- package/dist/react/runtimes/assistant-transport/useLatestRef.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +3 -10
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +43 -85
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +5 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts +29 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js +159 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js.map +1 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts +12 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js +10 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts +1 -9
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +16 -153
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js.map +1 -1
- package/dist/react/runtimes/createMessageConverter.d.ts +2 -1
- package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.d.ts +6 -25
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +33 -233
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +14 -6
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/types/MessagePartComponentTypes.d.ts +7 -3
- package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
- package/dist/react/types/scopes/tools.d.ts +2 -0
- package/dist/react/types/scopes/tools.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.d.ts +1 -1
- package/dist/runtime/api/composer-runtime.js.map +1 -1
- package/dist/runtime/api/message-part-runtime.d.ts +2 -2
- package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-part-runtime.js +1 -1
- package/dist/runtime/api/message-part-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +9 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +5 -0
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +2 -3
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +14 -29
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +4 -6
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +5 -11
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/composer-runtime-core.d.ts +1 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +14 -2
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +16 -2
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/internal.d.ts +2 -1
- package/dist/runtime/internal.js +2 -1
- package/dist/runtime/queue/external-thread-queue-adapter.d.ts +1 -1
- package/dist/runtime/queue/message-queue.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.js +1 -1
- package/dist/runtime/queue/message-queue.js.map +1 -1
- package/dist/runtime/queue/queue-item.d.ts +12 -0
- package/dist/runtime/queue/queue-item.d.ts.map +1 -0
- package/dist/runtime/queue/queue-item.js +6 -0
- package/dist/runtime/queue/queue-item.js.map +1 -0
- package/dist/runtime/utils/abortable-thread-load.d.ts +15 -0
- package/dist/runtime/utils/abortable-thread-load.d.ts.map +1 -0
- package/dist/runtime/utils/abortable-thread-load.js +35 -0
- package/dist/runtime/utils/abortable-thread-load.js.map +1 -0
- package/dist/runtime/utils/attachment-add-operations.d.ts +18 -0
- package/dist/runtime/utils/attachment-add-operations.d.ts.map +1 -0
- package/dist/runtime/utils/attachment-add-operations.js +43 -0
- package/dist/runtime/utils/attachment-add-operations.js.map +1 -0
- package/dist/runtime/utils/auto-status.d.ts +7 -2
- package/dist/runtime/utils/auto-status.d.ts.map +1 -1
- package/dist/runtime/utils/auto-status.js +13 -3
- package/dist/runtime/utils/auto-status.js.map +1 -1
- package/dist/runtime/utils/external-message-conversion.d.ts +48 -0
- package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -0
- package/dist/runtime/utils/external-message-conversion.js +222 -0
- package/dist/runtime/utils/external-message-conversion.js.map +1 -0
- package/dist/runtime/utils/external-store-message.d.ts +2 -1
- package/dist/runtime/utils/external-store-message.d.ts.map +1 -1
- package/dist/runtime/utils/external-store-message.js +2 -1
- package/dist/runtime/utils/external-store-message.js.map +1 -1
- package/dist/runtime/utils/message-repository-session.d.ts +30 -0
- package/dist/runtime/utils/message-repository-session.d.ts.map +1 -0
- package/dist/runtime/utils/message-repository-session.js +130 -0
- package/dist/runtime/utils/message-repository-session.js.map +1 -0
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.js +3 -4
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtime/utils/pending-tool-calls.d.ts +20 -0
- package/dist/runtime/utils/pending-tool-calls.d.ts.map +1 -0
- package/dist/runtime/utils/pending-tool-calls.js +22 -0
- package/dist/runtime/utils/pending-tool-calls.js.map +1 -0
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +6 -3
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -1
- package/dist/runtime/utils/resolveToolApprovalResponse.js +12 -3
- package/dist/runtime/utils/resolveToolApprovalResponse.js.map +1 -1
- package/dist/runtime/utils/thread-message-like.d.ts +3 -10
- 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/runtime/utils/tool-call-tree.d.ts +39 -0
- package/dist/runtime/utils/tool-call-tree.d.ts.map +1 -0
- package/dist/runtime/utils/tool-call-tree.js +85 -0
- package/dist/runtime/utils/tool-call-tree.js.map +1 -0
- package/dist/runtimes/external-store/external-store-adapter.d.ts +29 -2
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +2 -5
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +3 -10
- 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 +21 -2
- 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 +154 -46
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +4 -2
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +23 -3
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +12 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.js +107 -14
- package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/title.d.ts +9 -0
- package/dist/runtimes/remote-thread-list/title.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/title.js +6 -0
- package/dist/runtimes/remote-thread-list/title.js.map +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts +6 -5
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +31 -8
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +98 -59
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/external-thread.d.ts +1 -1
- package/dist/store/clients/external-thread.d.ts.map +1 -1
- package/dist/store/clients/external-thread.js +85 -103
- package/dist/store/clients/external-thread.js.map +1 -1
- package/dist/store/clients/single-thread-list.d.ts.map +1 -1
- package/dist/store/clients/single-thread-list.js +2 -2
- package/dist/store/clients/single-thread-list.js.map +1 -1
- package/dist/store/clients/suggestions.d.ts.map +1 -1
- package/dist/store/clients/suggestions.js +33 -12
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-message-client.js +1 -1
- package/dist/store/clients/thread-selection-events.js +1 -1
- package/dist/store/index.d.ts +6 -3
- package/dist/store/index.js +2 -1
- package/dist/store/internal.d.ts +2 -2
- package/dist/store/internal.js +2 -2
- package/dist/store/primitive-predicates.d.ts +4 -1
- package/dist/store/primitive-predicates.d.ts.map +1 -1
- package/dist/store/primitive-predicates.js +9 -1
- package/dist/store/primitive-predicates.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +124 -105
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +1 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts +3 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts.map +1 -1
- package/dist/store/runtime-clients/useSubscribable.js +1 -1
- package/dist/store/runtime-clients/useSubscribable.js.map +1 -1
- package/dist/store/scope-registration.d.ts +1 -1
- package/dist/store/scopes/composer.d.ts +2 -1
- package/dist/store/scopes/composer.d.ts.map +1 -1
- package/dist/store/scopes/message.d.ts +1 -1
- package/dist/store/scopes/part.d.ts +6 -3
- package/dist/store/scopes/part.d.ts.map +1 -1
- package/dist/store/scopes/queue-item.d.ts +2 -9
- package/dist/store/scopes/queue-item.d.ts.map +1 -1
- package/dist/store/scopes/queue-item.js +0 -6
- package/dist/subscribable/subscribable.d.ts +8 -1
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +24 -16
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/types/message.d.ts +47 -4
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js +7 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/data-url.d.ts +14 -1
- package/dist/utils/data-url.d.ts.map +1 -1
- package/dist/utils/data-url.js +13 -1
- package/dist/utils/data-url.js.map +1 -1
- package/dist/utils/invoke-user-callback.d.ts +5 -0
- package/dist/utils/invoke-user-callback.d.ts.map +1 -0
- package/dist/utils/invoke-user-callback.js +19 -0
- package/dist/utils/invoke-user-callback.js.map +1 -0
- package/dist/utils/normalizePartStatus.js.map +1 -1
- package/package.json +12 -17
- package/src/index.ts +6 -1
- package/src/internal.ts +20 -0
- package/src/model-context/frame/host.test.ts +91 -7
- package/src/model-context/frame/host.ts +7 -2
- package/src/model-context/frame/provider.test.ts +484 -13
- package/src/model-context/frame/provider.ts +205 -35
- package/src/model-context/interactable-composer-metadata.ts +1 -1
- package/src/model-context/registry.test.ts +44 -0
- package/src/model-context/registry.ts +13 -35
- package/src/model-context/tool-call-text.test.ts +67 -0
- package/src/model-context/tool-call-text.ts +67 -0
- package/src/react/AssistantRuntimeProvider.test.tsx +66 -2
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +1 -3
- package/src/react/client/InMemoryThreadList.test.tsx +49 -0
- package/src/react/client/InMemoryThreadList.ts +7 -1
- package/src/react/client/Interactables.ts +19 -178
- package/src/react/client/RemoteThreadList.background.test.ts +384 -0
- package/src/react/client/RemoteThreadList.concurrent.test.tsx +274 -0
- package/src/react/client/RemoteThreadList.test.ts +369 -1
- package/src/react/client/RemoteThreadList.ts +320 -142
- package/src/react/client/Tools.ts +7 -1
- package/src/react/index.ts +4 -0
- package/src/react/interactables-legacy/Interactables.ts +20 -177
- package/src/react/interactables-shared/useInteractablePersistenceQueue.test.tsx +161 -0
- package/src/react/interactables-shared/useInteractablePersistenceQueue.ts +206 -0
- package/src/react/model-context/modelContextHooks.test.tsx +131 -0
- package/src/react/model-context/toolbox.test.ts +9 -9
- package/src/react/model-context/toolbox.ts +9 -36
- package/src/react/model-context/useAssistantContext.ts +4 -2
- package/src/react/model-context/useAuiToolOverrides.ts +4 -2
- package/src/react/model-context/useInlineRender.test.tsx +48 -0
- package/src/react/model-context/useInlineRender.ts +14 -10
- package/src/react/primitive-hooks/useMessageError.ts +2 -19
- package/src/react/primitive-hooks/useThreadListLoadMore.ts +2 -3
- package/src/react/primitives/composer/ComposerAttachments.test.tsx +76 -0
- package/src/react/primitives/composer/ComposerAttachments.tsx +9 -4
- package/src/react/primitives/composer/ComposerQueue.test.tsx +72 -0
- package/src/react/primitives/composer/ComposerQueue.tsx +7 -4
- package/src/react/primitives/message/MessageAttachments.test.tsx +107 -37
- package/src/react/primitives/message/MessageAttachments.tsx +10 -7
- package/src/react/primitives/message/MessageGroupedParts.tsx +2 -2
- package/src/react/primitives/message/MessageParts.tsx +3 -3
- package/src/react/primitives/threadList/ThreadListItems.test.tsx +99 -0
- package/src/react/primitives/threadList/ThreadListItems.tsx +8 -5
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +94 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +72 -31
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.switch-delete.test.ts +169 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +140 -124
- package/src/react/runtimes/RemoteThreadResource.ts +1 -4
- package/src/react/runtimes/assistant-transport/runManager.ts +4 -17
- package/src/react/runtimes/assistant-transport/transport-scheduling.test.ts +51 -2
- package/src/react/runtimes/assistant-transport/useLatestRef.ts +2 -2
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +45 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +157 -1
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +82 -176
- package/src/react/runtimes/cloud/auiV0.ts +5 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +88 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +236 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.test.ts +37 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.ts +18 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +90 -1
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +33 -238
- package/src/react/runtimes/external-message-converter.test.ts +0 -14
- package/src/react/runtimes/external-message-converter.test.tsx +77 -0
- package/src/react/runtimes/external-message-converter.ts +59 -481
- package/src/react/runtimes/useRemoteThreadListRuntime.concurrent.test.tsx +216 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +24 -6
- package/src/react/types/MessagePartComponentTypes.ts +7 -3
- package/src/react/types/scopes/tools.ts +2 -0
- package/src/runtime/api/composer-runtime.ts +1 -1
- package/src/runtime/api/message-part-runtime.ts +3 -3
- package/src/runtime/api/message-runtime.test.ts +28 -1
- package/src/runtime/api/thread-list-runtime.ts +25 -1
- package/src/runtime/base/base-composer-runtime-core.ts +20 -40
- package/src/runtime/base/base-thread-runtime-core.test.ts +110 -3
- package/src/runtime/base/base-thread-runtime-core.ts +16 -15
- package/src/runtime/base/default-thread-composer-runtime-core.ts +1 -4
- package/src/runtime/interfaces/composer-runtime-core.ts +1 -1
- package/src/runtime/interfaces/thread-list-runtime-core.ts +20 -1
- package/src/runtime/interfaces/thread-runtime-core.ts +18 -2
- package/src/runtime/internal.ts +5 -0
- package/src/runtime/queue/external-thread-queue-adapter.ts +1 -1
- package/src/runtime/queue/message-queue.ts +1 -4
- package/src/runtime/queue/queue-item.ts +10 -0
- package/src/runtime/utils/abortable-thread-load.test.ts +87 -0
- package/src/runtime/utils/abortable-thread-load.ts +53 -0
- package/src/runtime/utils/attachment-add-operations.ts +59 -0
- package/src/runtime/utils/auto-status.test.ts +57 -0
- package/src/runtime/utils/auto-status.ts +46 -1
- package/src/runtime/utils/external-message-conversion.test.ts +210 -0
- package/src/runtime/utils/external-message-conversion.ts +510 -0
- package/src/runtime/utils/external-store-message.ts +2 -0
- package/src/runtime/utils/message-repository-session.test.ts +195 -0
- package/src/runtime/utils/message-repository-session.ts +176 -0
- package/src/runtime/utils/message-repository.ts +7 -4
- package/src/runtime/utils/pending-tool-calls.test.ts +57 -0
- package/src/runtime/utils/pending-tool-calls.ts +35 -0
- package/src/runtime/utils/resolveToolApprovalResponse.test.ts +73 -0
- package/src/runtime/utils/resolveToolApprovalResponse.ts +27 -6
- package/src/runtime/utils/thread-message-like.ts +4 -10
- package/src/runtime/utils/tool-call-tree.test.ts +191 -0
- package/src/runtime/utils/tool-call-tree.ts +97 -0
- package/src/runtimes/external-store/external-store-adapter.ts +38 -2
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +6 -14
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +231 -61
- package/src/runtimes/inert/InertThreadRuntimeCore.ts +1 -1
- package/src/runtimes/local/local-thread-runtime-core.test.ts +201 -4
- package/src/runtimes/local/local-thread-runtime-core.ts +53 -4
- package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +149 -0
- package/src/runtimes/remote-thread-list/remote-thread-state.ts +178 -16
- package/src/runtimes/remote-thread-list/title.ts +3 -0
- package/src/runtimes/remote-thread-list/types.ts +6 -5
- package/src/runtimes/tool-invocations/EDGE_CASES.md +125 -3
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +856 -102
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +145 -89
- package/src/store/clients/external-thread.ts +30 -69
- package/src/store/clients/single-thread-list.ts +4 -1
- package/src/store/clients/suggestions.test.ts +185 -0
- package/src/store/clients/suggestions.ts +42 -35
- package/src/store/index.ts +4 -0
- package/src/store/internal.ts +2 -0
- package/src/store/primitive-predicates.ts +35 -0
- package/src/store/runtime-clients/thread-list-runtime-client.ts +16 -2
- package/src/store/runtime-clients/useSubscribable.ts +8 -2
- package/src/store/scopes/message.ts +1 -1
- package/src/store/scopes/part.ts +6 -3
- package/src/store/scopes/queue-item.ts +2 -9
- package/src/subscribable/subscribable.test.ts +50 -0
- package/src/subscribable/subscribable.ts +33 -21
- package/src/tests/MessageRepository.test.ts +77 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-load-race.test.ts +305 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-loadMore.test.ts +78 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-reload.test.ts +52 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-title-race.test.ts +158 -0
- package/src/tests/external-store-optimistic-id.test.ts +79 -0
- package/src/tests/external-store-repository-instance.test.ts +166 -0
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +186 -16
- package/src/tests/external-store-thread-runtime-core.test.ts +642 -0
- package/src/tests/external-thread-attachments.test.tsx +258 -1
- package/src/tests/remote-thread-list-adapter-switch.test.ts +66 -1
- package/src/tests/single-thread-list-item.test.tsx +47 -0
- package/src/tests/thread-message-like.test.ts +39 -1
- package/src/tests/thread-switch-events.test.tsx +397 -2
- package/src/types/message.ts +58 -5
- package/src/utils/data-url.test.ts +52 -1
- package/src/utils/data-url.ts +21 -0
- package/src/utils/invoke-user-callback.test.ts +82 -0
- package/src/utils/invoke-user-callback.ts +31 -0
- package/src/utils/normalizePartStatus.ts +1 -1
- package/dist/store/scopes/queue-item.js.map +0 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { ThreadMessage } from "../../types/message";
|
|
2
|
+
import {
|
|
3
|
+
MessageRepository,
|
|
4
|
+
type ExportedMessageRepository,
|
|
5
|
+
} from "./message-repository";
|
|
6
|
+
|
|
7
|
+
export type MessageRepositorySessionOptions = {
|
|
8
|
+
decorateExport?: (
|
|
9
|
+
exported: ExportedMessageRepository,
|
|
10
|
+
repository: MessageRepository,
|
|
11
|
+
) => ExportedMessageRepository;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const createMessageRepositorySession = (
|
|
15
|
+
options: MessageRepositorySessionOptions = {},
|
|
16
|
+
) => {
|
|
17
|
+
const repository = new MessageRepository();
|
|
18
|
+
let exportedRepository: ExportedMessageRepository | undefined;
|
|
19
|
+
|
|
20
|
+
const getMessages = (): readonly ThreadMessage[] => {
|
|
21
|
+
return repository.getMessages();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const tryGetMessage = (messageId: string) => {
|
|
25
|
+
try {
|
|
26
|
+
return repository.getMessage(messageId);
|
|
27
|
+
} catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const tryGetMessages = (
|
|
33
|
+
messageId: string,
|
|
34
|
+
): readonly ThreadMessage[] | undefined => {
|
|
35
|
+
try {
|
|
36
|
+
return repository.getMessages(messageId);
|
|
37
|
+
} catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const hasMessage = (messageId: string): boolean => {
|
|
43
|
+
return tryGetMessage(messageId) !== undefined;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const addOrUpdateMessage = (
|
|
47
|
+
parentId: string | null,
|
|
48
|
+
message: ThreadMessage,
|
|
49
|
+
): void => {
|
|
50
|
+
repository.addOrUpdateMessage(parentId, message);
|
|
51
|
+
exportedRepository = undefined;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const deleteMessage = (
|
|
55
|
+
messageId: string,
|
|
56
|
+
replacementId?: string | null,
|
|
57
|
+
): void => {
|
|
58
|
+
repository.deleteMessage(messageId, replacementId);
|
|
59
|
+
exportedRepository = undefined;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const tryDeleteMessage = (messageId: string): boolean => {
|
|
63
|
+
if (!hasMessage(messageId)) return false;
|
|
64
|
+
deleteMessage(messageId);
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const switchToBranch = (messageId: string): void => {
|
|
69
|
+
repository.switchToBranch(messageId);
|
|
70
|
+
exportedRepository = undefined;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const resetHead = (messageId: string | null): void => {
|
|
74
|
+
repository.resetHead(messageId);
|
|
75
|
+
exportedRepository = undefined;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const clear = (): void => {
|
|
79
|
+
repository.clear();
|
|
80
|
+
exportedRepository = undefined;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const updateMessage = (
|
|
84
|
+
messageId: string,
|
|
85
|
+
updater: (message: ThreadMessage) => ThreadMessage,
|
|
86
|
+
): boolean => {
|
|
87
|
+
const item = tryGetMessage(messageId);
|
|
88
|
+
if (!item) return false;
|
|
89
|
+
const message = updater(item.message);
|
|
90
|
+
if (message === item.message) return false;
|
|
91
|
+
addOrUpdateMessage(item.parentId, message);
|
|
92
|
+
return true;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const applyExternalMessageRepository = (
|
|
96
|
+
loaded: ExportedMessageRepository,
|
|
97
|
+
): void => {
|
|
98
|
+
const headId = loaded.headId ?? loaded.messages.at(-1)?.message.id ?? null;
|
|
99
|
+
const ids = new Set<string>();
|
|
100
|
+
let degenerate = false;
|
|
101
|
+
for (const { message } of loaded.messages) {
|
|
102
|
+
if (ids.has(message.id)) {
|
|
103
|
+
degenerate = true;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
ids.add(message.id);
|
|
107
|
+
}
|
|
108
|
+
if (headId !== null && !ids.has(headId)) degenerate = true;
|
|
109
|
+
|
|
110
|
+
if (!degenerate) {
|
|
111
|
+
clear();
|
|
112
|
+
let pending = [...loaded.messages];
|
|
113
|
+
const importedIds = new Set<string>();
|
|
114
|
+
|
|
115
|
+
while (pending.length > 0) {
|
|
116
|
+
const unresolved: typeof pending = [];
|
|
117
|
+
let progressed = false;
|
|
118
|
+
for (const item of pending) {
|
|
119
|
+
if (item.parentId !== null && !importedIds.has(item.parentId)) {
|
|
120
|
+
unresolved.push(item);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
addOrUpdateMessage(item.parentId, item.message);
|
|
124
|
+
importedIds.add(item.message.id);
|
|
125
|
+
progressed = true;
|
|
126
|
+
}
|
|
127
|
+
if (!progressed) {
|
|
128
|
+
degenerate = true;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
pending = unresolved;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (degenerate) {
|
|
136
|
+
clear();
|
|
137
|
+
let previousId: string | null = null;
|
|
138
|
+
for (const { message } of loaded.messages) {
|
|
139
|
+
const existing = tryGetMessage(message.id);
|
|
140
|
+
addOrUpdateMessage(existing ? existing.parentId : previousId, message);
|
|
141
|
+
previousId = message.id;
|
|
142
|
+
}
|
|
143
|
+
resetHead(previousId);
|
|
144
|
+
} else {
|
|
145
|
+
resetHead(headId);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
getMessages,
|
|
151
|
+
get headId() {
|
|
152
|
+
return repository.headId;
|
|
153
|
+
},
|
|
154
|
+
export: (): ExportedMessageRepository => {
|
|
155
|
+
exportedRepository ??= options.decorateExport
|
|
156
|
+
? options.decorateExport(repository.export(), repository)
|
|
157
|
+
: repository.export();
|
|
158
|
+
return exportedRepository;
|
|
159
|
+
},
|
|
160
|
+
tryGetMessage,
|
|
161
|
+
tryGetMessages,
|
|
162
|
+
hasMessage,
|
|
163
|
+
addOrUpdateMessage,
|
|
164
|
+
deleteMessage,
|
|
165
|
+
tryDeleteMessage,
|
|
166
|
+
switchToBranch,
|
|
167
|
+
resetHead,
|
|
168
|
+
clear,
|
|
169
|
+
updateMessage,
|
|
170
|
+
applyExternalMessageRepository,
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export type MessageRepositorySession = ReturnType<
|
|
175
|
+
typeof createMessageRepositorySession
|
|
176
|
+
>;
|
|
@@ -2,7 +2,7 @@ import type { ThreadMessage } from "../../types/message";
|
|
|
2
2
|
import type { RunConfig } from "../../types/message";
|
|
3
3
|
import { generateId } from "../../utils/id";
|
|
4
4
|
import type { ThreadMessageLike } from "./thread-message-like";
|
|
5
|
-
import {
|
|
5
|
+
import { getContentAutoStatus } from "./auto-status";
|
|
6
6
|
import { fromThreadMessageLike } from "./thread-message-like";
|
|
7
7
|
|
|
8
8
|
export type ExportedMessageRepositoryItem = {
|
|
@@ -28,7 +28,7 @@ export const ExportedMessageRepository = {
|
|
|
28
28
|
fromThreadMessageLike(
|
|
29
29
|
m,
|
|
30
30
|
generateId(),
|
|
31
|
-
|
|
31
|
+
getContentAutoStatus(m.content, false, false),
|
|
32
32
|
),
|
|
33
33
|
);
|
|
34
34
|
|
|
@@ -47,7 +47,6 @@ export const ExportedMessageRepository = {
|
|
|
47
47
|
}[],
|
|
48
48
|
options?: { headId?: string | null },
|
|
49
49
|
): ExportedMessageRepository => {
|
|
50
|
-
const fallbackStatus = getAutoStatus(false, false, false, false, undefined);
|
|
51
50
|
return {
|
|
52
51
|
...(options?.headId !== undefined
|
|
53
52
|
? { headId: options.headId }
|
|
@@ -60,7 +59,11 @@ export const ExportedMessageRepository = {
|
|
|
60
59
|
}
|
|
61
60
|
return {
|
|
62
61
|
parentId,
|
|
63
|
-
message: fromThreadMessageLike(
|
|
62
|
+
message: fromThreadMessageLike(
|
|
63
|
+
message,
|
|
64
|
+
message.id,
|
|
65
|
+
getContentAutoStatus(message.content, false, false),
|
|
66
|
+
),
|
|
64
67
|
};
|
|
65
68
|
}),
|
|
66
69
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
createToolCallCancellationStub,
|
|
4
|
+
scanPendingToolCalls,
|
|
5
|
+
} from "./pending-tool-calls";
|
|
6
|
+
|
|
7
|
+
type Message =
|
|
8
|
+
| { type: "assistant"; toolCalls: { id: string; name: string }[] }
|
|
9
|
+
| { type: "tool"; toolCallId: string };
|
|
10
|
+
|
|
11
|
+
const getPendingToolCalls = (messages: readonly Message[]) =>
|
|
12
|
+
scanPendingToolCalls(
|
|
13
|
+
messages,
|
|
14
|
+
(message) =>
|
|
15
|
+
message.type === "assistant"
|
|
16
|
+
? { toolCalls: message.toolCalls }
|
|
17
|
+
: { toolCallId: message.toolCallId },
|
|
18
|
+
(toolCall) => toolCall.id,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
describe("scanPendingToolCalls", () => {
|
|
22
|
+
it("returns tool calls without matching results in history order", () => {
|
|
23
|
+
expect(
|
|
24
|
+
getPendingToolCalls([
|
|
25
|
+
{
|
|
26
|
+
type: "assistant",
|
|
27
|
+
toolCalls: [
|
|
28
|
+
{ id: "call-1", name: "first" },
|
|
29
|
+
{ id: "call-2", name: "second" },
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{ type: "tool", toolCallId: "call-1" },
|
|
33
|
+
{
|
|
34
|
+
type: "assistant",
|
|
35
|
+
toolCalls: [{ id: "call-3", name: "third" }],
|
|
36
|
+
},
|
|
37
|
+
]),
|
|
38
|
+
).toEqual([
|
|
39
|
+
{ id: "call-2", name: "second" },
|
|
40
|
+
{ id: "call-3", name: "third" },
|
|
41
|
+
]);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("createToolCallCancellationStub", () => {
|
|
46
|
+
it("creates an error tool result with the cancellation payload", () => {
|
|
47
|
+
expect(
|
|
48
|
+
createToolCallCancellationStub({ id: "call-1", name: "lookup" }),
|
|
49
|
+
).toEqual({
|
|
50
|
+
type: "tool",
|
|
51
|
+
name: "lookup",
|
|
52
|
+
tool_call_id: "call-1",
|
|
53
|
+
content: JSON.stringify({ cancelled: true }),
|
|
54
|
+
status: "error",
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type PendingToolCallMessage<TToolCall> =
|
|
2
|
+
| { toolCalls: readonly TToolCall[] }
|
|
3
|
+
| { toolCallId: string }
|
|
4
|
+
| undefined;
|
|
5
|
+
|
|
6
|
+
export const scanPendingToolCalls = <TMessage, TToolCall>(
|
|
7
|
+
messages: readonly TMessage[],
|
|
8
|
+
getMessage: (message: TMessage) => PendingToolCallMessage<TToolCall>,
|
|
9
|
+
getToolCallId: (toolCall: TToolCall) => string,
|
|
10
|
+
): TToolCall[] => {
|
|
11
|
+
const pending = new Map<string, TToolCall>();
|
|
12
|
+
for (const message of messages) {
|
|
13
|
+
const value = getMessage(message);
|
|
14
|
+
if (!value) continue;
|
|
15
|
+
if ("toolCalls" in value) {
|
|
16
|
+
for (const toolCall of value.toolCalls) {
|
|
17
|
+
pending.set(getToolCallId(toolCall), toolCall);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
pending.delete(value.toolCallId);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return [...pending.values()];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const createToolCallCancellationStub = (toolCall: {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly name: string;
|
|
29
|
+
}) => ({
|
|
30
|
+
type: "tool" as const,
|
|
31
|
+
name: toolCall.name,
|
|
32
|
+
tool_call_id: toolCall.id,
|
|
33
|
+
content: JSON.stringify({ cancelled: true }),
|
|
34
|
+
status: "error" as const,
|
|
35
|
+
});
|
|
@@ -88,4 +88,77 @@ describe("resolveToolApprovalResponse", () => {
|
|
|
88
88
|
resolveToolApprovalResponse({ id: "a2" }, { optionId: "once" }),
|
|
89
89
|
).toThrow('no option with id "once"');
|
|
90
90
|
});
|
|
91
|
+
|
|
92
|
+
it("resolves a free-form answer as approved and carries the text", () => {
|
|
93
|
+
expect(
|
|
94
|
+
resolveToolApprovalResponse(
|
|
95
|
+
{ id: "q1", display: "text" },
|
|
96
|
+
{ text: "staging" },
|
|
97
|
+
),
|
|
98
|
+
).toEqual({ approvalId: "q1", approved: true, text: "staging" });
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("carries the text alongside a chosen option", () => {
|
|
102
|
+
expect(
|
|
103
|
+
resolveToolApprovalResponse(
|
|
104
|
+
{
|
|
105
|
+
id: "q2",
|
|
106
|
+
display: "select",
|
|
107
|
+
allowFreeform: true,
|
|
108
|
+
options: [{ id: "other", kind: "_other" }],
|
|
109
|
+
},
|
|
110
|
+
{ optionId: "other", approved: true, text: "somewhere else" },
|
|
111
|
+
),
|
|
112
|
+
).toEqual({
|
|
113
|
+
approvalId: "q2",
|
|
114
|
+
approved: true,
|
|
115
|
+
optionId: "other",
|
|
116
|
+
text: "somewhere else",
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("throws when the request does not accept a free-form answer", () => {
|
|
121
|
+
expect(() =>
|
|
122
|
+
resolveToolApprovalResponse(approval, { text: "anything" }),
|
|
123
|
+
).toThrow("does not accept a free-form answer");
|
|
124
|
+
expect(() =>
|
|
125
|
+
resolveToolApprovalResponse(
|
|
126
|
+
{ id: "a4", display: "select" },
|
|
127
|
+
{ approved: true, text: "anything" },
|
|
128
|
+
),
|
|
129
|
+
).toThrow("does not accept a free-form answer");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("refuses to infer approval from a bare answer on a decision", () => {
|
|
133
|
+
expect(() =>
|
|
134
|
+
resolveToolApprovalResponse(
|
|
135
|
+
{ id: "a5", display: "decision", allowFreeform: true },
|
|
136
|
+
{ text: "not this one" },
|
|
137
|
+
),
|
|
138
|
+
).toThrow("is a decision, not a question");
|
|
139
|
+
expect(() =>
|
|
140
|
+
resolveToolApprovalResponse(
|
|
141
|
+
{ id: "a6", allowFreeform: true },
|
|
142
|
+
{ text: "not this one" },
|
|
143
|
+
),
|
|
144
|
+
).toThrow("is a decision, not a question");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("records the answer alongside an explicit decision on a gate", () => {
|
|
148
|
+
expect(
|
|
149
|
+
resolveToolApprovalResponse(
|
|
150
|
+
{ id: "a7", display: "decision", allowFreeform: true },
|
|
151
|
+
{ approved: false, text: "not this one" },
|
|
152
|
+
),
|
|
153
|
+
).toEqual({ approvalId: "a7", approved: false, text: "not this one" });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("keeps a refusal a refusal when the request accepts text", () => {
|
|
157
|
+
expect(
|
|
158
|
+
resolveToolApprovalResponse(
|
|
159
|
+
{ id: "q3", allowFreeform: true },
|
|
160
|
+
{ approved: false, reason: "not answering" },
|
|
161
|
+
),
|
|
162
|
+
).toEqual({ approvalId: "q3", approved: false, reason: "not answering" });
|
|
163
|
+
});
|
|
91
164
|
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
toolApprovalAcceptsText,
|
|
3
|
+
type ToolApprovalDisplay,
|
|
4
|
+
type ToolApprovalOption,
|
|
5
|
+
type ToolApprovalResponse,
|
|
4
6
|
} from "../../types/message";
|
|
5
7
|
import type { RespondToToolApprovalOptions } from "../interfaces/thread-runtime-core";
|
|
6
8
|
|
|
@@ -12,16 +14,25 @@ const APPROVED_BY_KIND: Record<string, boolean> = {
|
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
|
-
* Resolves a renderer-facing approval response (boolean
|
|
16
|
-
* against the approval's
|
|
17
|
+
* Resolves a renderer-facing approval response (boolean, optionId, or
|
|
18
|
+
* free-form answer) against the approval's request shape into the
|
|
19
|
+
* runtime-facing decision shape.
|
|
17
20
|
*/
|
|
18
21
|
export const resolveToolApprovalResponse = (
|
|
19
22
|
approval: {
|
|
20
23
|
readonly id: string;
|
|
24
|
+
readonly display?: ToolApprovalDisplay;
|
|
25
|
+
readonly allowFreeform?: boolean;
|
|
21
26
|
readonly options?: readonly ToolApprovalOption[];
|
|
22
27
|
},
|
|
23
28
|
response: ToolApprovalResponse,
|
|
24
29
|
): RespondToToolApprovalOptions => {
|
|
30
|
+
const text = response.text;
|
|
31
|
+
if (text !== undefined && !toolApprovalAcceptsText(approval))
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Tool approval "${approval.id}" does not accept a free-form answer; the request must declare display "text" or allowFreeform`,
|
|
34
|
+
);
|
|
35
|
+
|
|
25
36
|
let approved: boolean;
|
|
26
37
|
let optionId: string | undefined;
|
|
27
38
|
|
|
@@ -42,14 +53,24 @@ export const resolveToolApprovalResponse = (
|
|
|
42
53
|
approved = APPROVED_BY_KIND[option.kind]!;
|
|
43
54
|
}
|
|
44
55
|
optionId = option.id;
|
|
45
|
-
} else {
|
|
56
|
+
} else if ("approved" in response) {
|
|
46
57
|
approved = response.approved;
|
|
58
|
+
} else {
|
|
59
|
+
// A bare answer resolves a question, where answering is not refusing. On a
|
|
60
|
+
// decision the approval itself is the authorization, so inferring one from
|
|
61
|
+
// a typed note would let the note authorize the call.
|
|
62
|
+
if (approval.display !== "text" && approval.display !== "select")
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Tool approval "${approval.id}" is a decision, not a question; respond with an explicit approved value, optionally alongside the answer`,
|
|
65
|
+
);
|
|
66
|
+
approved = true;
|
|
47
67
|
}
|
|
48
68
|
|
|
49
69
|
return {
|
|
50
70
|
approvalId: approval.id,
|
|
51
71
|
approved,
|
|
52
72
|
...(optionId !== undefined && { optionId }),
|
|
73
|
+
...(text !== undefined && { text }),
|
|
53
74
|
...(response.reason != null && { reason: response.reason }),
|
|
54
75
|
};
|
|
55
76
|
};
|
|
@@ -23,8 +23,9 @@ import type {
|
|
|
23
23
|
MessageTiming,
|
|
24
24
|
PartProviderMetadata,
|
|
25
25
|
TextMessagePart,
|
|
26
|
-
ToolApprovalOption,
|
|
27
26
|
ToolCallTiming,
|
|
27
|
+
ToolCallMessagePart,
|
|
28
|
+
ToolCallMessagePartMcpMetadata,
|
|
28
29
|
} from "../../types/message";
|
|
29
30
|
import type {
|
|
30
31
|
ReadonlyJSONObject,
|
|
@@ -63,16 +64,9 @@ export type ThreadMessageLike = {
|
|
|
63
64
|
readonly messages?: readonly ThreadMessage[] | undefined;
|
|
64
65
|
readonly interrupt?: { type: "human"; payload: unknown };
|
|
65
66
|
readonly timing?: ToolCallTiming;
|
|
67
|
+
readonly mcp?: ToolCallMessagePartMcpMetadata;
|
|
66
68
|
readonly providerMetadata?: PartProviderMetadata;
|
|
67
|
-
readonly approval?:
|
|
68
|
-
readonly id: string;
|
|
69
|
-
readonly approved?: boolean;
|
|
70
|
-
readonly reason?: string;
|
|
71
|
-
readonly isAutomatic?: boolean;
|
|
72
|
-
readonly options?: readonly ToolApprovalOption[];
|
|
73
|
-
readonly optionId?: string;
|
|
74
|
-
readonly resolution?: "cancelled" | "expired";
|
|
75
|
-
};
|
|
69
|
+
readonly approval?: NonNullable<ToolCallMessagePart["approval"]>;
|
|
76
70
|
}
|
|
77
71
|
)[];
|
|
78
72
|
readonly id?: string | undefined;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type {
|
|
3
|
+
ThreadAssistantMessage,
|
|
4
|
+
ThreadAssistantMessagePart,
|
|
5
|
+
ThreadMessage,
|
|
6
|
+
ToolCallMessagePart,
|
|
7
|
+
} from "../../types/message";
|
|
8
|
+
import {
|
|
9
|
+
iterateToolCallParts,
|
|
10
|
+
mapToolCallPartsDeep,
|
|
11
|
+
walkToolCallTree,
|
|
12
|
+
} from "./tool-call-tree";
|
|
13
|
+
|
|
14
|
+
const toolCall = (
|
|
15
|
+
toolCallId: string,
|
|
16
|
+
messages?: readonly ThreadMessage[],
|
|
17
|
+
): ToolCallMessagePart => ({
|
|
18
|
+
type: "tool-call",
|
|
19
|
+
toolCallId,
|
|
20
|
+
toolName: "t",
|
|
21
|
+
argsText: "{}",
|
|
22
|
+
args: {},
|
|
23
|
+
...(messages !== undefined && { messages }),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const assistant = (
|
|
27
|
+
id: string,
|
|
28
|
+
content: readonly ThreadAssistantMessagePart[],
|
|
29
|
+
): ThreadAssistantMessage =>
|
|
30
|
+
({
|
|
31
|
+
id,
|
|
32
|
+
role: "assistant",
|
|
33
|
+
content,
|
|
34
|
+
status: { type: "complete", reason: "unknown" },
|
|
35
|
+
metadata: {
|
|
36
|
+
unstable_state: null,
|
|
37
|
+
unstable_annotations: [],
|
|
38
|
+
unstable_data: [],
|
|
39
|
+
steps: [],
|
|
40
|
+
custom: {},
|
|
41
|
+
},
|
|
42
|
+
createdAt: new Date(0),
|
|
43
|
+
attachments: [],
|
|
44
|
+
}) as unknown as ThreadAssistantMessage;
|
|
45
|
+
|
|
46
|
+
const user = (id: string): ThreadMessage =>
|
|
47
|
+
({
|
|
48
|
+
id,
|
|
49
|
+
role: "user",
|
|
50
|
+
content: [{ type: "text", text: "hi" }],
|
|
51
|
+
metadata: { custom: {} },
|
|
52
|
+
createdAt: new Date(0),
|
|
53
|
+
attachments: [],
|
|
54
|
+
}) as unknown as ThreadMessage;
|
|
55
|
+
|
|
56
|
+
// root
|
|
57
|
+
// └─ a ─ nested message "m2"
|
|
58
|
+
// ├─ b ─ nested message "m3"
|
|
59
|
+
// │ └─ c
|
|
60
|
+
// └─ d
|
|
61
|
+
const tree = () => {
|
|
62
|
+
const c = toolCall("c");
|
|
63
|
+
const b = toolCall("b", [assistant("m3", [c])]);
|
|
64
|
+
const d = toolCall("d");
|
|
65
|
+
const a = toolCall("a", [assistant("m2", [b, d])]);
|
|
66
|
+
return { a, b, c, d };
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
describe("walkToolCallTree", () => {
|
|
70
|
+
it("yields every part in document order, each ahead of its descendants", () => {
|
|
71
|
+
const { a } = tree();
|
|
72
|
+
const entries = [
|
|
73
|
+
...walkToolCallTree([user("m0"), assistant("m1", [a, toolCall("e")])]),
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
expect(entries.map((entry) => entry.part.toolCallId)).toEqual([
|
|
77
|
+
"a",
|
|
78
|
+
"b",
|
|
79
|
+
"c",
|
|
80
|
+
"d",
|
|
81
|
+
"e",
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("reports the message that directly holds each part", () => {
|
|
86
|
+
const { a } = tree();
|
|
87
|
+
const entries = [...walkToolCallTree([assistant("m1", [a])])];
|
|
88
|
+
|
|
89
|
+
expect(
|
|
90
|
+
Object.fromEntries(
|
|
91
|
+
entries.map((entry) => [entry.part.toolCallId, entry.messageId]),
|
|
92
|
+
),
|
|
93
|
+
).toEqual({ a: "m1", b: "m2", c: "m3", d: "m2" });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("skips messages whose content is not an array", () => {
|
|
97
|
+
const malformed = {
|
|
98
|
+
id: "m1",
|
|
99
|
+
role: "assistant",
|
|
100
|
+
} as unknown as ThreadMessage;
|
|
101
|
+
expect([...walkToolCallTree([malformed])]).toEqual([]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("skips a non-assistant message carrying a tool-call part", () => {
|
|
105
|
+
const malformed = {
|
|
106
|
+
...user("m2"),
|
|
107
|
+
content: [toolCall("b")],
|
|
108
|
+
} as unknown as ThreadMessage;
|
|
109
|
+
const a = toolCall("a", [malformed]);
|
|
110
|
+
|
|
111
|
+
expect(
|
|
112
|
+
[...walkToolCallTree([assistant("m1", [a])])].map(
|
|
113
|
+
(entry) => entry.part.toolCallId,
|
|
114
|
+
),
|
|
115
|
+
).toEqual(["a"]);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe("iterateToolCallParts", () => {
|
|
120
|
+
it("matches walkToolCallTree over the same content", () => {
|
|
121
|
+
const { a } = tree();
|
|
122
|
+
const content = [a, toolCall("e")];
|
|
123
|
+
|
|
124
|
+
expect([...iterateToolCallParts(content)].map((p) => p.toolCallId)).toEqual(
|
|
125
|
+
[...walkToolCallTree([assistant("m1", content)])].map(
|
|
126
|
+
(entry) => entry.part.toolCallId,
|
|
127
|
+
),
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("ignores non tool-call parts", () => {
|
|
132
|
+
expect([
|
|
133
|
+
...iterateToolCallParts([
|
|
134
|
+
{ type: "text", text: "hi" } as ThreadAssistantMessagePart,
|
|
135
|
+
toolCall("a"),
|
|
136
|
+
]),
|
|
137
|
+
]).toHaveLength(1);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("mapToolCallPartsDeep", () => {
|
|
142
|
+
it("rewrites nested parts and reports the change", () => {
|
|
143
|
+
const { a } = tree();
|
|
144
|
+
const content = [a];
|
|
145
|
+
const { content: next, changed } = mapToolCallPartsDeep(content, (part) =>
|
|
146
|
+
part.toolCallId === "c" ? { ...part, isError: true } : part,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
expect(changed).toBe(true);
|
|
150
|
+
const parts = [...iterateToolCallParts(next)];
|
|
151
|
+
expect(parts.find((part) => part.toolCallId === "c")?.isError).toBe(true);
|
|
152
|
+
expect(
|
|
153
|
+
parts.find((part) => part.toolCallId === "d")?.isError,
|
|
154
|
+
).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("skips a nested message whose content is not an array", () => {
|
|
158
|
+
const malformed = {
|
|
159
|
+
id: "m2",
|
|
160
|
+
role: "assistant",
|
|
161
|
+
} as unknown as ThreadMessage;
|
|
162
|
+
const a = toolCall("a", [malformed]);
|
|
163
|
+
|
|
164
|
+
expect(() =>
|
|
165
|
+
mapToolCallPartsDeep([a], (part) => ({ ...part, isError: true })),
|
|
166
|
+
).not.toThrow();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("keeps the original content identity when nothing changed", () => {
|
|
170
|
+
const { a } = tree();
|
|
171
|
+
const content = [a, toolCall("e")];
|
|
172
|
+
const result = mapToolCallPartsDeep(content, (part) => part);
|
|
173
|
+
|
|
174
|
+
expect(result.changed).toBe(false);
|
|
175
|
+
expect(result.content).toBe(content);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("preserves untouched sibling messages by identity", () => {
|
|
179
|
+
const nested = assistant("m2", [toolCall("b")]);
|
|
180
|
+
const sibling = user("m3");
|
|
181
|
+
const a = toolCall("a", [nested, sibling]);
|
|
182
|
+
const { content: next } = mapToolCallPartsDeep([a], (part) =>
|
|
183
|
+
part.toolCallId === "b" ? { ...part, isError: true } : part,
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
const mapped = next[0] as ToolCallMessagePart;
|
|
187
|
+
expect(mapped).not.toBe(a);
|
|
188
|
+
expect(mapped.messages?.[1]).toBe(sibling);
|
|
189
|
+
expect(mapped.messages?.[0]).not.toBe(nested);
|
|
190
|
+
});
|
|
191
|
+
});
|