@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
|
@@ -13,6 +13,7 @@ describe("AssistantFrameProvider", () => {
|
|
|
13
13
|
origin: string,
|
|
14
14
|
source: Window = parentWindow,
|
|
15
15
|
id = "tool-call-1",
|
|
16
|
+
toolName = "sensitiveTool",
|
|
16
17
|
) => {
|
|
17
18
|
messageHandler?.(
|
|
18
19
|
new MessageEvent("message", {
|
|
@@ -21,7 +22,7 @@ describe("AssistantFrameProvider", () => {
|
|
|
21
22
|
message: {
|
|
22
23
|
type: "tool-call",
|
|
23
24
|
id,
|
|
24
|
-
toolName
|
|
25
|
+
toolName,
|
|
25
26
|
args: {},
|
|
26
27
|
},
|
|
27
28
|
},
|
|
@@ -99,6 +100,52 @@ describe("AssistantFrameProvider", () => {
|
|
|
99
100
|
await vi.waitFor(() => expect(execute).toHaveBeenCalledOnce());
|
|
100
101
|
});
|
|
101
102
|
|
|
103
|
+
it("defaults to the current origin", async () => {
|
|
104
|
+
const execute = vi.fn(async () => "result");
|
|
105
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
106
|
+
getModelContext: () => ({
|
|
107
|
+
tools: { sensitiveTool: { execute } },
|
|
108
|
+
}),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
112
|
+
expect.anything(),
|
|
113
|
+
window.location.origin,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
dispatchToolCall("https://untrusted.example");
|
|
117
|
+
expect(execute).not.toHaveBeenCalled();
|
|
118
|
+
|
|
119
|
+
dispatchToolCall(window.location.origin);
|
|
120
|
+
await vi.waitFor(() => expect(execute).toHaveBeenCalledOnce());
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("reports a failure even when the thrown error has an empty message", async () => {
|
|
124
|
+
const execute = vi.fn(async () => {
|
|
125
|
+
throw new Error();
|
|
126
|
+
});
|
|
127
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
128
|
+
getModelContext: () => ({
|
|
129
|
+
tools: {
|
|
130
|
+
sensitiveTool: { execute },
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
dispatchToolCall(window.location.origin);
|
|
136
|
+
|
|
137
|
+
await vi.waitFor(() => {
|
|
138
|
+
const frame = (
|
|
139
|
+
parentWindow.postMessage as ReturnType<typeof vi.fn>
|
|
140
|
+
).mock.calls
|
|
141
|
+
.map(([data]) => data)
|
|
142
|
+
.find((data) => data?.message?.type === "tool-result");
|
|
143
|
+
expect(frame).toBeDefined();
|
|
144
|
+
expect(frame.message).toHaveProperty("error");
|
|
145
|
+
expect(frame.message).not.toHaveProperty("result");
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
102
149
|
it("aborts in-flight tool calls when the parent cancels them", async () => {
|
|
103
150
|
let toolSignal: AbortSignal | undefined;
|
|
104
151
|
const execute = vi.fn(
|
|
@@ -119,10 +166,10 @@ describe("AssistantFrameProvider", () => {
|
|
|
119
166
|
}),
|
|
120
167
|
});
|
|
121
168
|
|
|
122
|
-
dispatchToolCall(
|
|
169
|
+
dispatchToolCall(window.location.origin);
|
|
123
170
|
await vi.waitFor(() => expect(toolSignal).toBeDefined());
|
|
124
171
|
|
|
125
|
-
dispatchToolCancel(
|
|
172
|
+
dispatchToolCancel(window.location.origin);
|
|
126
173
|
|
|
127
174
|
expect(toolSignal?.aborted).toBe(true);
|
|
128
175
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -155,11 +202,11 @@ describe("AssistantFrameProvider", () => {
|
|
|
155
202
|
getModelContext: () => ({ tools: { sensitiveTool: { execute } } }),
|
|
156
203
|
});
|
|
157
204
|
|
|
158
|
-
dispatchToolCall(
|
|
159
|
-
dispatchToolCall(
|
|
205
|
+
dispatchToolCall(window.location.origin, parentWindow, "tool-a");
|
|
206
|
+
dispatchToolCall(window.location.origin, parentWindow, "tool-b");
|
|
160
207
|
await vi.waitFor(() => expect(signals.size).toBe(2));
|
|
161
208
|
|
|
162
|
-
dispatchToolCancel(
|
|
209
|
+
dispatchToolCancel(window.location.origin, parentWindow, "tool-a");
|
|
163
210
|
|
|
164
211
|
expect(signals.get("tool-a")?.aborted).toBe(true);
|
|
165
212
|
expect(signals.get("tool-b")?.aborted).toBe(false);
|
|
@@ -183,9 +230,9 @@ describe("AssistantFrameProvider", () => {
|
|
|
183
230
|
getModelContext: () => ({ tools: { sensitiveTool: { execute } } }),
|
|
184
231
|
});
|
|
185
232
|
|
|
186
|
-
dispatchToolCall(
|
|
233
|
+
dispatchToolCall(window.location.origin, parentWindow, "duplicate");
|
|
187
234
|
await vi.waitFor(() => expect(signals).toHaveLength(1));
|
|
188
|
-
dispatchToolCall(
|
|
235
|
+
dispatchToolCall(window.location.origin, parentWindow, "duplicate");
|
|
189
236
|
await vi.waitFor(() => expect(signals).toHaveLength(2));
|
|
190
237
|
|
|
191
238
|
expect(signals[0]?.aborted).toBe(true);
|
|
@@ -210,7 +257,7 @@ describe("AssistantFrameProvider", () => {
|
|
|
210
257
|
getModelContext: () => ({ tools: { sensitiveTool: { execute } } }),
|
|
211
258
|
});
|
|
212
259
|
|
|
213
|
-
dispatchToolCall(
|
|
260
|
+
dispatchToolCall(window.location.origin);
|
|
214
261
|
await vi.waitFor(() => expect(toolSignal).toBeDefined());
|
|
215
262
|
|
|
216
263
|
AssistantFrameProvider.dispose();
|
|
@@ -225,7 +272,53 @@ describe("AssistantFrameProvider", () => {
|
|
|
225
272
|
error: "AssistantFrameProvider has been disposed",
|
|
226
273
|
},
|
|
227
274
|
},
|
|
228
|
-
{ targetOrigin:
|
|
275
|
+
{ targetOrigin: window.location.origin },
|
|
276
|
+
);
|
|
277
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
278
|
+
const toolResults = vi
|
|
279
|
+
.mocked(parentWindow.postMessage)
|
|
280
|
+
.mock.calls.filter(
|
|
281
|
+
([data]) =>
|
|
282
|
+
(data as { message?: { type?: string } }).message?.type ===
|
|
283
|
+
"tool-result",
|
|
284
|
+
);
|
|
285
|
+
expect(toolResults).toHaveLength(1);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("aborts in-flight tool calls when their provider is removed", async () => {
|
|
289
|
+
let toolSignal: AbortSignal | undefined;
|
|
290
|
+
const execute = vi.fn(
|
|
291
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
292
|
+
toolSignal = context.abortSignal;
|
|
293
|
+
await new Promise<never>((_resolve, reject) => {
|
|
294
|
+
context.abortSignal.addEventListener(
|
|
295
|
+
"abort",
|
|
296
|
+
() => reject(context.abortSignal.reason),
|
|
297
|
+
{ once: true },
|
|
298
|
+
);
|
|
299
|
+
});
|
|
300
|
+
},
|
|
301
|
+
);
|
|
302
|
+
const removeProvider = AssistantFrameProvider.addModelContextProvider({
|
|
303
|
+
getModelContext: () => ({ tools: { sensitiveTool: { execute } } }),
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
dispatchToolCall(window.location.origin);
|
|
307
|
+
await vi.waitFor(() => expect(toolSignal).toBeDefined());
|
|
308
|
+
|
|
309
|
+
removeProvider();
|
|
310
|
+
|
|
311
|
+
expect(toolSignal?.aborted).toBe(true);
|
|
312
|
+
expect(parentWindow.postMessage).toHaveBeenCalledWith(
|
|
313
|
+
{
|
|
314
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
315
|
+
message: {
|
|
316
|
+
type: "tool-result",
|
|
317
|
+
id: "tool-call-1",
|
|
318
|
+
error: "AssistantFrame tool provider has been removed",
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
{ targetOrigin: window.location.origin },
|
|
229
322
|
);
|
|
230
323
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
231
324
|
const toolResults = vi
|
|
@@ -238,6 +331,133 @@ describe("AssistantFrameProvider", () => {
|
|
|
238
331
|
expect(toolResults).toHaveLength(1);
|
|
239
332
|
});
|
|
240
333
|
|
|
334
|
+
it("keeps tool calls active while the same provider remains registered", async () => {
|
|
335
|
+
let toolSignal: AbortSignal | undefined;
|
|
336
|
+
const execute = vi.fn(
|
|
337
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
338
|
+
toolSignal = context.abortSignal;
|
|
339
|
+
await new Promise<never>((_resolve, reject) => {
|
|
340
|
+
context.abortSignal.addEventListener(
|
|
341
|
+
"abort",
|
|
342
|
+
() => reject(context.abortSignal.reason),
|
|
343
|
+
{ once: true },
|
|
344
|
+
);
|
|
345
|
+
});
|
|
346
|
+
},
|
|
347
|
+
);
|
|
348
|
+
const provider = {
|
|
349
|
+
getModelContext: () => ({ tools: { sensitiveTool: { execute } } }),
|
|
350
|
+
};
|
|
351
|
+
const removeFirst =
|
|
352
|
+
AssistantFrameProvider.addModelContextProvider(provider);
|
|
353
|
+
const removeSecond =
|
|
354
|
+
AssistantFrameProvider.addModelContextProvider(provider);
|
|
355
|
+
|
|
356
|
+
dispatchToolCall(window.location.origin);
|
|
357
|
+
await vi.waitFor(() => expect(toolSignal).toBeDefined());
|
|
358
|
+
|
|
359
|
+
removeFirst();
|
|
360
|
+
expect(toolSignal?.aborted).toBe(false);
|
|
361
|
+
|
|
362
|
+
removeSecond();
|
|
363
|
+
expect(toolSignal?.aborted).toBe(true);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("cancels only calls owned by the removed provider", async () => {
|
|
367
|
+
const shadowedExecute = vi.fn(async () => "shadowed");
|
|
368
|
+
const removeShadowed = AssistantFrameProvider.addModelContextProvider({
|
|
369
|
+
getModelContext: () => ({
|
|
370
|
+
tools: { sensitiveTool: { execute: shadowedExecute } },
|
|
371
|
+
}),
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
let toolSignal: AbortSignal | undefined;
|
|
375
|
+
const execute = vi.fn(
|
|
376
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
377
|
+
toolSignal = context.abortSignal;
|
|
378
|
+
await new Promise<never>((_resolve, reject) => {
|
|
379
|
+
context.abortSignal.addEventListener(
|
|
380
|
+
"abort",
|
|
381
|
+
() => reject(context.abortSignal.reason),
|
|
382
|
+
{ once: true },
|
|
383
|
+
);
|
|
384
|
+
});
|
|
385
|
+
},
|
|
386
|
+
);
|
|
387
|
+
const removeOwner = AssistantFrameProvider.addModelContextProvider({
|
|
388
|
+
getModelContext: () => ({
|
|
389
|
+
tools: { sensitiveTool: { execute } },
|
|
390
|
+
}),
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
dispatchToolCall(window.location.origin);
|
|
394
|
+
await vi.waitFor(() => expect(toolSignal).toBeDefined());
|
|
395
|
+
expect(shadowedExecute).not.toHaveBeenCalled();
|
|
396
|
+
|
|
397
|
+
removeShadowed();
|
|
398
|
+
expect(toolSignal?.aborted).toBe(false);
|
|
399
|
+
|
|
400
|
+
removeOwner();
|
|
401
|
+
expect(toolSignal?.aborted).toBe(true);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it("keeps other providers' tool calls active when one is removed", async () => {
|
|
405
|
+
const signals = new Map<string, AbortSignal>();
|
|
406
|
+
const execute = vi.fn(
|
|
407
|
+
async (
|
|
408
|
+
_args: unknown,
|
|
409
|
+
context: { toolCallId: string; abortSignal: AbortSignal },
|
|
410
|
+
) => {
|
|
411
|
+
signals.set(context.toolCallId, context.abortSignal);
|
|
412
|
+
await new Promise<never>((_resolve, reject) => {
|
|
413
|
+
context.abortSignal.addEventListener(
|
|
414
|
+
"abort",
|
|
415
|
+
() => reject(context.abortSignal.reason),
|
|
416
|
+
{ once: true },
|
|
417
|
+
);
|
|
418
|
+
});
|
|
419
|
+
},
|
|
420
|
+
);
|
|
421
|
+
const removeFirst = AssistantFrameProvider.addModelContextProvider({
|
|
422
|
+
getModelContext: () => ({ tools: { firstTool: { execute } } }),
|
|
423
|
+
});
|
|
424
|
+
const removeSecond = AssistantFrameProvider.addModelContextProvider({
|
|
425
|
+
getModelContext: () => ({ tools: { secondTool: { execute } } }),
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
dispatchToolCall(
|
|
429
|
+
window.location.origin,
|
|
430
|
+
parentWindow,
|
|
431
|
+
"first-call",
|
|
432
|
+
"firstTool",
|
|
433
|
+
);
|
|
434
|
+
dispatchToolCall(
|
|
435
|
+
window.location.origin,
|
|
436
|
+
parentWindow,
|
|
437
|
+
"second-call",
|
|
438
|
+
"secondTool",
|
|
439
|
+
);
|
|
440
|
+
await vi.waitFor(() => expect(signals.size).toBe(2));
|
|
441
|
+
|
|
442
|
+
removeFirst();
|
|
443
|
+
|
|
444
|
+
expect(signals.get("first-call")?.aborted).toBe(true);
|
|
445
|
+
expect(signals.get("second-call")?.aborted).toBe(false);
|
|
446
|
+
const toolResults = vi
|
|
447
|
+
.mocked(parentWindow.postMessage)
|
|
448
|
+
.mock.calls.filter(
|
|
449
|
+
([data]) =>
|
|
450
|
+
(data as { message?: { type?: string } }).message?.type ===
|
|
451
|
+
"tool-result",
|
|
452
|
+
);
|
|
453
|
+
expect(toolResults).toHaveLength(1);
|
|
454
|
+
expect(toolResults[0]?.[0]).toMatchObject({
|
|
455
|
+
message: { id: "first-call" },
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
removeSecond();
|
|
459
|
+
});
|
|
460
|
+
|
|
241
461
|
it("upgrades a wildcard origin policy when a strict provider registers", async () => {
|
|
242
462
|
AssistantFrameProvider.addModelContextProvider(
|
|
243
463
|
{ getModelContext: () => ({}) },
|
|
@@ -312,7 +532,227 @@ describe("AssistantFrameProvider", () => {
|
|
|
312
532
|
);
|
|
313
533
|
});
|
|
314
534
|
|
|
315
|
-
it("
|
|
535
|
+
it("rolls back a provider when registration fails", () => {
|
|
536
|
+
const execute = vi.fn(async () => "result");
|
|
537
|
+
expect(() =>
|
|
538
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
539
|
+
{
|
|
540
|
+
getModelContext: () => ({
|
|
541
|
+
tools: { sensitiveTool: { execute } },
|
|
542
|
+
}),
|
|
543
|
+
subscribe: () => {
|
|
544
|
+
throw new Error("subscribe failed");
|
|
545
|
+
},
|
|
546
|
+
},
|
|
547
|
+
"https://first.example",
|
|
548
|
+
),
|
|
549
|
+
).toThrow("subscribe failed");
|
|
550
|
+
|
|
551
|
+
dispatchToolCall("https://first.example");
|
|
552
|
+
expect(execute).not.toHaveBeenCalled();
|
|
553
|
+
|
|
554
|
+
expect(() =>
|
|
555
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
556
|
+
{ getModelContext: () => ({}) },
|
|
557
|
+
"https://second.example",
|
|
558
|
+
),
|
|
559
|
+
).not.toThrow();
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it("cancels reentrant tool calls when registration rolls back", async () => {
|
|
563
|
+
let toolSignal: AbortSignal | undefined;
|
|
564
|
+
const execute = vi.fn(
|
|
565
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
566
|
+
toolSignal = context.abortSignal;
|
|
567
|
+
await new Promise<never>((_resolve, reject) => {
|
|
568
|
+
context.abortSignal.addEventListener(
|
|
569
|
+
"abort",
|
|
570
|
+
() => reject(context.abortSignal.reason),
|
|
571
|
+
{ once: true },
|
|
572
|
+
);
|
|
573
|
+
});
|
|
574
|
+
},
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
expect(() =>
|
|
578
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
579
|
+
getModelContext: () => ({
|
|
580
|
+
tools: { sensitiveTool: { execute } },
|
|
581
|
+
}),
|
|
582
|
+
subscribe: () => {
|
|
583
|
+
dispatchToolCall(window.location.origin);
|
|
584
|
+
throw new Error("subscribe failed");
|
|
585
|
+
},
|
|
586
|
+
}),
|
|
587
|
+
).toThrow("subscribe failed");
|
|
588
|
+
|
|
589
|
+
expect(toolSignal?.aborted).toBe(true);
|
|
590
|
+
expect(parentWindow.postMessage).toHaveBeenCalledWith(
|
|
591
|
+
{
|
|
592
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
593
|
+
message: {
|
|
594
|
+
type: "tool-result",
|
|
595
|
+
id: "tool-call-1",
|
|
596
|
+
error: "AssistantFrame tool provider has been removed",
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
{ targetOrigin: window.location.origin },
|
|
600
|
+
);
|
|
601
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
it("keeps an existing registration when the same provider fails to register again", async () => {
|
|
605
|
+
const execute = vi.fn(async () => "result");
|
|
606
|
+
const firstUnsubscribe = vi.fn();
|
|
607
|
+
let subscriptionCount = 0;
|
|
608
|
+
const provider = {
|
|
609
|
+
getModelContext: () => ({
|
|
610
|
+
tools: { sensitiveTool: { execute } },
|
|
611
|
+
}),
|
|
612
|
+
subscribe: () => {
|
|
613
|
+
subscriptionCount += 1;
|
|
614
|
+
if (subscriptionCount === 1) return firstUnsubscribe;
|
|
615
|
+
throw new Error("second subscribe failed");
|
|
616
|
+
},
|
|
617
|
+
};
|
|
618
|
+
const releaseFirst = AssistantFrameProvider.addModelContextProvider(
|
|
619
|
+
provider,
|
|
620
|
+
"https://parent.example",
|
|
621
|
+
);
|
|
622
|
+
|
|
623
|
+
expect(() =>
|
|
624
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
625
|
+
provider,
|
|
626
|
+
"https://parent.example",
|
|
627
|
+
),
|
|
628
|
+
).toThrow("second subscribe failed");
|
|
629
|
+
expect(firstUnsubscribe).not.toHaveBeenCalled();
|
|
630
|
+
|
|
631
|
+
dispatchToolCall("https://parent.example");
|
|
632
|
+
|
|
633
|
+
await vi.waitFor(() => expect(execute).toHaveBeenCalledOnce());
|
|
634
|
+
releaseFirst();
|
|
635
|
+
expect(firstUnsubscribe).toHaveBeenCalledOnce();
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
it("merges a provider registered more than once only once", () => {
|
|
639
|
+
const provider = {
|
|
640
|
+
getModelContext: () => ({ system: "shared system" }),
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
AssistantFrameProvider.addModelContextProvider(provider);
|
|
644
|
+
AssistantFrameProvider.addModelContextProvider(provider);
|
|
645
|
+
|
|
646
|
+
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
647
|
+
{
|
|
648
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
649
|
+
message: {
|
|
650
|
+
type: "model-context-update",
|
|
651
|
+
context: {
|
|
652
|
+
system: "shared system",
|
|
653
|
+
tools: {},
|
|
654
|
+
},
|
|
655
|
+
},
|
|
656
|
+
},
|
|
657
|
+
window.location.origin,
|
|
658
|
+
);
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
it("releases a subscription when the initial broadcast fails", () => {
|
|
662
|
+
const unsubscribe = vi.fn();
|
|
663
|
+
expect(() =>
|
|
664
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
665
|
+
{
|
|
666
|
+
getModelContext: () => {
|
|
667
|
+
throw new Error("context failed");
|
|
668
|
+
},
|
|
669
|
+
subscribe: () => unsubscribe,
|
|
670
|
+
},
|
|
671
|
+
"https://first.example",
|
|
672
|
+
),
|
|
673
|
+
).toThrow("context failed");
|
|
674
|
+
|
|
675
|
+
expect(unsubscribe).toHaveBeenCalledOnce();
|
|
676
|
+
expect(() =>
|
|
677
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
678
|
+
{ getModelContext: () => ({}) },
|
|
679
|
+
"https://second.example",
|
|
680
|
+
),
|
|
681
|
+
).not.toThrow();
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
it("reports rollback cleanup failures without replacing the original error", () => {
|
|
685
|
+
const contextError = new Error("context failed");
|
|
686
|
+
const unsubscribeError = new Error("unsubscribe failed");
|
|
687
|
+
const consoleError = vi
|
|
688
|
+
.spyOn(console, "error")
|
|
689
|
+
.mockImplementation(() => undefined);
|
|
690
|
+
|
|
691
|
+
expect(() =>
|
|
692
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
693
|
+
getModelContext: () => {
|
|
694
|
+
throw contextError;
|
|
695
|
+
},
|
|
696
|
+
subscribe: () => () => {
|
|
697
|
+
throw unsubscribeError;
|
|
698
|
+
},
|
|
699
|
+
}),
|
|
700
|
+
).toThrow(contextError);
|
|
701
|
+
|
|
702
|
+
expect(consoleError).toHaveBeenCalledWith(unsubscribeError);
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
it("cleans up provider state when its unsubscribe throws", () => {
|
|
706
|
+
const unsubscribe = vi.fn(() => {
|
|
707
|
+
throw new Error("unsubscribe failed");
|
|
708
|
+
});
|
|
709
|
+
const release = AssistantFrameProvider.addModelContextProvider(
|
|
710
|
+
{
|
|
711
|
+
getModelContext: () => ({}),
|
|
712
|
+
subscribe: () => unsubscribe,
|
|
713
|
+
},
|
|
714
|
+
"https://first.example",
|
|
715
|
+
);
|
|
716
|
+
|
|
717
|
+
expect(release).toThrow("unsubscribe failed");
|
|
718
|
+
expect(unsubscribe).toHaveBeenCalledOnce();
|
|
719
|
+
expect(() =>
|
|
720
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
721
|
+
{ getModelContext: () => ({}) },
|
|
722
|
+
"https://second.example",
|
|
723
|
+
),
|
|
724
|
+
).not.toThrow();
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
it("finishes disposal when a provider unsubscribe throws", () => {
|
|
728
|
+
const error = new Error("unsubscribe failed");
|
|
729
|
+
const firstUnsubscribe = vi.fn(() => {
|
|
730
|
+
throw error;
|
|
731
|
+
});
|
|
732
|
+
const secondUnsubscribe = vi.fn();
|
|
733
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
734
|
+
getModelContext: () => ({}),
|
|
735
|
+
subscribe: () => firstUnsubscribe,
|
|
736
|
+
});
|
|
737
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
738
|
+
getModelContext: () => ({}),
|
|
739
|
+
subscribe: () => secondUnsubscribe,
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
expect(() => AssistantFrameProvider.dispose()).toThrow(error);
|
|
743
|
+
expect(firstUnsubscribe).toHaveBeenCalledOnce();
|
|
744
|
+
expect(secondUnsubscribe).toHaveBeenCalledOnce();
|
|
745
|
+
|
|
746
|
+
expect(() =>
|
|
747
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
748
|
+
{ getModelContext: () => ({}) },
|
|
749
|
+
"https://new.example",
|
|
750
|
+
),
|
|
751
|
+
).not.toThrow();
|
|
752
|
+
expect(window.addEventListener).toHaveBeenCalledTimes(2);
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
it("returns to the same-origin policy after every provider unsubscribes", () => {
|
|
316
756
|
const unsubscribe = AssistantFrameProvider.addModelContextProvider(
|
|
317
757
|
{ getModelContext: () => ({}) },
|
|
318
758
|
"https://first.example",
|
|
@@ -322,7 +762,7 @@ describe("AssistantFrameProvider", () => {
|
|
|
322
762
|
|
|
323
763
|
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
324
764
|
expect.anything(),
|
|
325
|
-
|
|
765
|
+
window.location.origin,
|
|
326
766
|
);
|
|
327
767
|
|
|
328
768
|
expect(() =>
|
|
@@ -360,7 +800,7 @@ describe("AssistantFrameProvider", () => {
|
|
|
360
800
|
|
|
361
801
|
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
362
802
|
expect.anything(),
|
|
363
|
-
|
|
803
|
+
window.location.origin,
|
|
364
804
|
);
|
|
365
805
|
});
|
|
366
806
|
|
|
@@ -382,6 +822,37 @@ describe("AssistantFrameProvider", () => {
|
|
|
382
822
|
);
|
|
383
823
|
});
|
|
384
824
|
|
|
825
|
+
it("returns to the same-origin policy after a wildcard provider unsubscribes", () => {
|
|
826
|
+
const unsubscribe = AssistantFrameProvider.addModelContextProvider(
|
|
827
|
+
{ getModelContext: () => ({}) },
|
|
828
|
+
"*",
|
|
829
|
+
);
|
|
830
|
+
|
|
831
|
+
unsubscribe();
|
|
832
|
+
|
|
833
|
+
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
834
|
+
expect.anything(),
|
|
835
|
+
window.location.origin,
|
|
836
|
+
);
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
it("allows opting back into a wildcard policy after every provider unsubscribes", () => {
|
|
840
|
+
const unsubscribe = AssistantFrameProvider.addModelContextProvider({
|
|
841
|
+
getModelContext: () => ({}),
|
|
842
|
+
});
|
|
843
|
+
unsubscribe();
|
|
844
|
+
|
|
845
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
846
|
+
{ getModelContext: () => ({}) },
|
|
847
|
+
"*",
|
|
848
|
+
);
|
|
849
|
+
|
|
850
|
+
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
851
|
+
expect.anything(),
|
|
852
|
+
"*",
|
|
853
|
+
);
|
|
854
|
+
});
|
|
855
|
+
|
|
385
856
|
it("keeps a shared strict origin after one provider unsubscribes", async () => {
|
|
386
857
|
const unsubscribeFirst = AssistantFrameProvider.addModelContextProvider(
|
|
387
858
|
{ getModelContext: () => ({}) },
|