@assistant-ui/core 0.3.13 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/speech.d.ts.map +1 -1
- package/dist/adapters/speech.js +9 -15
- package/dist/adapters/speech.js.map +1 -1
- package/dist/adapters/thread-history.d.ts +2 -0
- package/dist/adapters/thread-history.d.ts.map +1 -1
- package/dist/adapters/voice.d.ts.map +1 -1
- package/dist/adapters/voice.js +38 -15
- package/dist/adapters/voice.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +3 -2
- package/dist/internal.js +8 -7
- package/dist/model-context/frame/host.d.ts +1 -1
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +19 -4
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/frame/provider.d.ts +4 -0
- package/dist/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +50 -3
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/frame/types.d.ts +4 -1
- package/dist/model-context/frame/types.d.ts.map +1 -1
- package/dist/model-context/frame/types.js.map +1 -1
- package/dist/model-context/registry.d.ts.map +1 -1
- package/dist/model-context/registry.js +16 -4
- package/dist/model-context/registry.js.map +1 -1
- package/dist/react/RuntimeAdapter.d.ts +8 -1
- package/dist/react/RuntimeAdapter.d.ts.map +1 -1
- package/dist/react/RuntimeAdapter.js +23 -18
- package/dist/react/RuntimeAdapter.js.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +28 -12
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/AdaptedRemoteThread.d.ts +11 -0
- package/dist/react/client/AdaptedRemoteThread.d.ts.map +1 -0
- package/dist/react/client/AdaptedRemoteThread.js +27 -0
- package/dist/react/client/AdaptedRemoteThread.js.map +1 -0
- package/dist/react/client/InMemoryThreadList.d.ts +19 -0
- package/dist/react/client/InMemoryThreadList.d.ts.map +1 -0
- package/dist/react/client/InMemoryThreadList.js +418 -0
- package/dist/react/client/InMemoryThreadList.js.map +1 -0
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js +159 -102
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/RemoteThreadList.d.ts +34 -0
- package/dist/react/client/RemoteThreadList.d.ts.map +1 -0
- package/dist/react/client/RemoteThreadList.js +898 -0
- package/dist/react/client/RemoteThreadList.js.map +1 -0
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +38 -27
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +7 -2
- package/dist/react/index.js +5 -2
- package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -1
- package/dist/react/interactables-legacy/Interactables.js +145 -110
- package/dist/react/interactables-legacy/Interactables.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.js +20 -19
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js +2 -4
- package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.js +2 -4
- package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.js +2 -6
- package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js +2 -6
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.js +2 -4
- package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.js +2 -4
- package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +6 -2
- package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts +3 -0
- package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadIsEmpty.js +3 -0
- package/dist/react/primitive-hooks/useThreadIsEmpty.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadIsRunning.d.ts +3 -0
- package/dist/react/primitive-hooks/useThreadIsRunning.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadIsRunning.js +3 -0
- package/dist/react/primitive-hooks/useThreadIsRunning.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.d.ts +13 -0
- package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.d.ts.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +24 -10
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +115 -71
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +14 -2
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +232 -63
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.d.ts +30 -0
- package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -0
- package/dist/react/runtimes/RemoteThreadResource.js +136 -0
- package/dist/react/runtimes/RemoteThreadResource.js.map +1 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts +3 -10
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts.map +1 -1
- package/dist/react/runtimes/RuntimeAdapterProvider.js +3 -6
- package/dist/react/runtimes/RuntimeAdapterProvider.js.map +1 -1
- package/dist/react/runtimes/assistant-transport/commandQueue.d.ts +17 -0
- package/dist/react/runtimes/assistant-transport/commandQueue.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/commandQueue.js +55 -0
- package/dist/react/runtimes/assistant-transport/commandQueue.js.map +1 -0
- package/dist/react/runtimes/assistant-transport/replayBoundaryStream.d.ts +11 -0
- package/dist/react/runtimes/assistant-transport/replayBoundaryStream.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/replayBoundaryStream.js +165 -0
- package/dist/react/runtimes/assistant-transport/replayBoundaryStream.js.map +1 -0
- package/dist/react/runtimes/assistant-transport/runManager.d.ts +15 -0
- package/dist/react/runtimes/assistant-transport/runManager.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/runManager.js +86 -0
- package/dist/react/runtimes/assistant-transport/runManager.js.map +1 -0
- package/dist/react/runtimes/assistant-transport/types.d.ts +130 -0
- package/dist/react/runtimes/assistant-transport/types.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/types.js +0 -0
- package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.d.ts +14 -0
- package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.js +296 -0
- package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.js.map +1 -0
- package/dist/react/runtimes/assistant-transport/useConvertedState.d.ts +7 -0
- package/dist/react/runtimes/assistant-transport/useConvertedState.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/useConvertedState.js +25 -0
- package/dist/react/runtimes/assistant-transport/useConvertedState.js.map +1 -0
- package/dist/react/runtimes/assistant-transport/useLatestRef.d.ts +7 -0
- package/dist/react/runtimes/assistant-transport/useLatestRef.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/useLatestRef.js +27 -0
- package/dist/react/runtimes/assistant-transport/useLatestRef.js.map +1 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +39 -13
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +2 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +3 -3
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +4 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +7 -0
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +60 -17
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.d.ts +16 -0
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js +36 -0
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js.map +1 -0
- package/dist/react/runtimes/external-message-converter.js +14 -14
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.js +44 -28
- package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.js +1 -1
- package/dist/react/runtimes/useRuntimeAdapters.d.ts +9 -0
- package/dist/react/runtimes/useRuntimeAdapters.d.ts.map +1 -0
- package/dist/react/runtimes/useRuntimeAdapters.js +20 -0
- package/dist/react/runtimes/useRuntimeAdapters.js.map +1 -0
- package/dist/runtime/api/composer-runtime.d.ts +5 -0
- package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.js.map +1 -1
- package/dist/runtime/api/message-runtime.js +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +1 -0
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +4 -2
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +12 -2
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.js +8 -2
- package/dist/runtime/api/thread-runtime.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +8 -7
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -0
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +3 -3
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +0 -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 +10 -4
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +6 -0
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/internal.js +5 -5
- package/dist/runtime/queue/message-queue.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.js +2 -1
- package/dist/runtime/queue/message-queue.js.map +1 -1
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.js +27 -18
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtime/utils/thread-runtime-lifecycle.d.ts +8 -0
- package/dist/runtime/utils/thread-runtime-lifecycle.d.ts.map +1 -0
- package/dist/runtime/utils/thread-runtime-lifecycle.js +11 -0
- package/dist/runtime/utils/thread-runtime-lifecycle.js.map +1 -0
- package/dist/runtimes/external-store/external-store-shared-options.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +4 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +8 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +37 -13
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts +102 -0
- package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts.map +1 -0
- package/dist/runtimes/inert/InertThreadRuntimeCore.js +156 -0
- package/dist/runtimes/inert/InertThreadRuntimeCore.js.map +1 -0
- package/dist/runtimes/internal.d.ts +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +3 -0
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +78 -19
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +12 -59
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +10 -142
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter-changed.d.ts +9 -0
- package/dist/runtimes/remote-thread-list/adapter-changed.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/adapter-changed.js +13 -0
- package/dist/runtimes/remote-thread-list/adapter-changed.js.map +1 -0
- package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js +16 -152
- package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/optimistic-state.d.ts +2 -0
- package/dist/runtimes/remote-thread-list/optimistic-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/optimistic-state.js +11 -0
- package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +32 -1
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +1 -12
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +67 -38
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/external-thread.js +1 -1
- package/dist/store/clients/external-thread.js.map +1 -1
- package/dist/store/clients/suggestions.js +2 -2
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-selection-events.d.ts +10 -0
- package/dist/store/clients/thread-selection-events.d.ts.map +1 -0
- package/dist/store/clients/thread-selection-events.js +40 -0
- package/dist/store/clients/thread-selection-events.js.map +1 -0
- package/dist/store/env.d.ts +5 -0
- package/dist/store/env.d.ts.map +1 -0
- package/dist/store/env.js +12 -0
- package/dist/store/env.js.map +1 -0
- package/dist/store/index.d.ts +5 -3
- package/dist/store/index.js +4 -2
- package/dist/store/internal.d.ts +4 -1
- package/dist/store/internal.js +4 -1
- package/dist/store/primitive-predicates.d.ts +19 -0
- package/dist/store/primitive-predicates.d.ts.map +1 -0
- package/dist/store/primitive-predicates.js +19 -0
- package/dist/store/primitive-predicates.js.map +1 -0
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.js +18 -11
- package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/handle-runtime-action.d.ts +5 -0
- package/dist/store/runtime-clients/handle-runtime-action.d.ts.map +1 -0
- package/dist/store/runtime-clients/handle-runtime-action.js +14 -0
- package/dist/store/runtime-clients/handle-runtime-action.js.map +1 -0
- package/dist/store/runtime-clients/handle-thread-list-action.d.ts +5 -0
- package/dist/store/runtime-clients/handle-thread-list-action.d.ts.map +1 -0
- package/dist/store/runtime-clients/handle-thread-list-action.js +7 -0
- package/dist/store/runtime-clients/handle-thread-list-action.js.map +1 -0
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +62 -29
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +5 -6
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/scopes/composer.d.ts +9 -4
- package/dist/store/scopes/composer.d.ts.map +1 -1
- package/dist/store/scopes/thread-list-item.d.ts +7 -6
- package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
- package/dist/store/scopes/thread.d.ts +8 -7
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/store/scopes/threads.d.ts +17 -1
- package/dist/store/scopes/threads.d.ts.map +1 -1
- package/dist/subscribable/subscribable.d.ts +2 -1
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +23 -18
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/types/message.d.ts +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/composite-context-provider.d.ts +1 -0
- package/dist/utils/composite-context-provider.d.ts.map +1 -1
- package/dist/utils/composite-context-provider.js +25 -9
- package/dist/utils/composite-context-provider.js.map +1 -1
- package/dist/utils/notify-event-listeners.d.ts +2 -2
- package/dist/utils/notify-event-listeners.d.ts.map +1 -1
- package/dist/utils/notify-event-listeners.js +2 -2
- package/dist/utils/notify-event-listeners.js.map +1 -1
- package/dist/utils/silent-runtime-action.d.ts +6 -0
- package/dist/utils/silent-runtime-action.d.ts.map +1 -0
- package/dist/utils/silent-runtime-action.js +7 -0
- package/dist/utils/silent-runtime-action.js.map +1 -0
- package/package.json +8 -8
- package/src/adapters/speech.test.ts +118 -1
- package/src/adapters/speech.ts +21 -22
- package/src/adapters/thread-history.ts +2 -0
- package/src/adapters/voice.test.ts +134 -0
- package/src/adapters/voice.ts +35 -27
- package/src/index.ts +1 -0
- package/src/internal.ts +1 -0
- package/src/model-context/frame/host.test.ts +87 -5
- package/src/model-context/frame/host.ts +18 -4
- package/src/model-context/frame/provider.test.ts +347 -20
- package/src/model-context/frame/provider.ts +58 -2
- package/src/model-context/frame/types.ts +5 -0
- package/src/model-context/registry.test.ts +131 -0
- package/src/model-context/registry.ts +16 -6
- package/src/react/RuntimeAdapter.test.ts +2 -0
- package/src/react/RuntimeAdapter.ts +20 -8
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +34 -17
- package/src/react/client/AdaptedRemoteThread.ts +41 -0
- package/src/react/client/InMemoryThreadList.test.tsx +148 -0
- package/src/react/client/InMemoryThreadList.ts +290 -0
- package/src/react/client/Interactables.test.ts +326 -2
- package/src/react/client/Interactables.ts +227 -110
- package/src/react/client/RemoteThreadList.test.ts +1222 -0
- package/src/react/client/RemoteThreadList.ts +1136 -0
- package/src/react/client/Tools.ts +36 -29
- package/src/react/index.ts +13 -0
- package/src/react/interactables-legacy/Interactables.test.ts +317 -0
- package/src/react/interactables-legacy/Interactables.ts +204 -128
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +15 -0
- package/src/react/primitive-hooks/useActionBarCopy.ts +15 -10
- package/src/react/primitive-hooks/useActionBarEdit.ts +2 -1
- package/src/react/primitive-hooks/useActionBarReload.ts +2 -6
- package/src/react/primitive-hooks/useBranchPickerNext.ts +2 -7
- package/src/react/primitive-hooks/useBranchPickerPrevious.ts +2 -7
- package/src/react/primitive-hooks/useComposerCancel.ts +2 -1
- package/src/react/primitive-hooks/useComposerSend.ts +2 -5
- package/src/react/primitive-hooks/useSuggestionTrigger.test.ts +11 -0
- package/src/react/primitive-hooks/useSuggestionTrigger.ts +4 -5
- package/src/react/primitive-hooks/useThreadIsEmpty.ts +3 -0
- package/src/react/primitive-hooks/useThreadIsRunning.ts +3 -0
- package/src/react/primitives/message/MessageParts.tsx +0 -1
- package/src/react/primitives/thread/ThreadMessages.tsx +2 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.retry.test.tsx +116 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +1 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +57 -6
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.title.test.tsx +272 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +171 -124
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.republish.test.ts +87 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +327 -83
- package/src/react/runtimes/RemoteThreadResource.test.ts +141 -0
- package/src/react/runtimes/RemoteThreadResource.ts +233 -0
- package/src/react/runtimes/RuntimeAdapterProvider.tsx +8 -20
- package/src/react/runtimes/assistant-transport/commandQueue.ts +68 -0
- package/src/react/runtimes/assistant-transport/replayBoundaryStream.test.ts +455 -0
- package/src/react/runtimes/assistant-transport/replayBoundaryStream.ts +172 -0
- package/src/react/runtimes/assistant-transport/runManager.ts +124 -0
- package/src/react/runtimes/assistant-transport/transport-delivery.test.tsx +79 -0
- package/src/react/runtimes/assistant-transport/transport-parentid.test.tsx +97 -0
- package/src/react/runtimes/assistant-transport/transport-scheduling.test.ts +414 -0
- package/src/react/runtimes/assistant-transport/types.ts +170 -0
- package/src/react/runtimes/assistant-transport/useAssistantTransport.spec.md +141 -0
- package/src/react/runtimes/assistant-transport/useAssistantTransportRuntime.test.tsx +683 -0
- package/src/react/runtimes/assistant-transport/useAssistantTransportRuntime.ts +483 -0
- package/src/react/runtimes/assistant-transport/useConvertedState.ts +20 -0
- package/src/react/runtimes/assistant-transport/useLatestRef.ts +9 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +131 -6
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +61 -15
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +6 -4
- package/src/react/runtimes/cloud/auiV0.ts +17 -1
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +98 -3
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +104 -27
- package/src/react/runtimes/cloud/useCloudThreadListRuntime.test.tsx +56 -0
- package/src/react/runtimes/cloud/useCloudThreadListRuntime.ts +31 -0
- package/src/react/runtimes/external-message-converter.test.ts +143 -0
- package/src/react/runtimes/external-message-converter.ts +41 -41
- package/src/react/runtimes/remote-thread-hook-on-tap.test.ts +58 -0
- package/src/react/runtimes/useExternalStoreRuntime.lifecycle.test.tsx +83 -0
- package/src/react/runtimes/useExternalStoreRuntime.suggestions.test.tsx +13 -3
- package/src/react/runtimes/useExternalStoreRuntime.ts +7 -0
- package/src/react/runtimes/useExternalStoreSharedOptions.ts +3 -1
- package/src/react/runtimes/useLocalRuntime.test.tsx +134 -8
- package/src/react/runtimes/useRuntimeAdapters.test.tsx +62 -0
- package/src/react/runtimes/useRuntimeAdapters.ts +28 -0
- package/src/runtime/api/composer-runtime.ts +5 -0
- package/src/runtime/api/thread-list-runtime.ts +3 -1
- package/src/runtime/api/thread-runtime.ts +20 -2
- package/src/runtime/base/base-composer-runtime-core.ts +6 -5
- package/src/runtime/base/base-thread-runtime-core.test.ts +191 -0
- package/src/runtime/base/base-thread-runtime-core.ts +11 -2
- package/src/runtime/base/default-thread-composer-runtime-core.ts +12 -4
- package/src/runtime/interfaces/thread-runtime-core.ts +6 -0
- package/src/runtime/queue/message-queue.ts +2 -1
- package/src/runtime/utils/message-repository.ts +26 -18
- package/src/runtime/utils/thread-runtime-lifecycle.ts +18 -0
- package/src/runtimes/external-store/external-store-shared-options.ts +3 -1
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +4 -1
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +103 -34
- package/src/runtimes/inert/InertThreadRuntimeCore.test.ts +253 -0
- package/src/runtimes/inert/InertThreadRuntimeCore.ts +232 -0
- package/src/runtimes/local/local-thread-runtime-core.test.ts +692 -4
- package/src/runtimes/local/local-thread-runtime-core.ts +117 -22
- package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +17 -205
- package/src/runtimes/remote-thread-list/adapter-changed.ts +10 -0
- package/src/runtimes/remote-thread-list/empty-thread-core.ts +28 -217
- package/src/runtimes/remote-thread-list/optimistic-state.test.ts +18 -0
- package/src/runtimes/remote-thread-list/optimistic-state.ts +13 -0
- package/src/runtimes/remote-thread-list/types.ts +34 -0
- package/src/runtimes/tool-invocations/EDGE_CASES.md +17 -6
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +243 -0
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +127 -61
- package/src/store/clients/external-thread.ts +1 -1
- package/src/store/clients/model-context-client.test.ts +16 -8
- package/src/store/clients/suggestions.ts +2 -2
- package/src/store/clients/thread-selection-events.ts +21 -0
- package/src/store/env.ts +11 -0
- package/src/store/index.ts +14 -1
- package/src/store/internal.ts +13 -0
- package/src/store/primitive-predicates.test.ts +184 -0
- package/src/store/primitive-predicates.ts +43 -0
- package/src/store/runtime-clients/attachment-runtime-client.test.ts +41 -0
- package/src/store/runtime-clients/attachment-runtime-client.ts +2 -1
- package/src/store/runtime-clients/handle-runtime-action.test.ts +40 -0
- package/src/store/runtime-clients/handle-runtime-action.ts +14 -0
- package/src/store/runtime-clients/handle-thread-list-action.test.ts +69 -0
- package/src/store/runtime-clients/handle-thread-list-action.ts +6 -0
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +15 -7
- package/src/store/runtime-clients/thread-list-runtime-client.ts +9 -6
- package/src/store/scopes/composer.ts +9 -4
- package/src/store/scopes/thread-list-item.ts +7 -6
- package/src/store/scopes/thread.ts +8 -7
- package/src/store/scopes/threads.ts +14 -0
- package/src/subscribable/subscribable.test.ts +77 -1
- package/src/subscribable/subscribable.ts +38 -23
- package/src/tests/MessageRepository.test.ts +48 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-errors.test.ts +2 -2
- package/src/tests/RemoteThreadListThreadListRuntimeCore-loadMore.test.ts +8 -6
- package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-unarchive.test.ts +25 -0
- package/src/tests/auiV0Encode.test.ts +66 -0
- package/src/tests/base-composer-runtime-core-send.test.ts +30 -0
- package/src/tests/base-composer-runtime-core.test.ts +28 -0
- package/src/tests/composer-can-cancel.test.ts +101 -0
- package/src/tests/empty-thread-core.test.ts +6 -0
- package/src/tests/external-store-thread-list-runtime-core.test.ts +101 -0
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +211 -1
- package/src/tests/external-store-thread-runtime-core.test.ts +124 -0
- package/src/tests/external-thread-isEmpty.test.tsx +100 -0
- package/src/tests/interactables-toolui-migration.test.tsx +66 -0
- package/src/tests/message-queue.test.ts +28 -0
- package/src/tests/remote-thread-list-adapter-switch.test.ts +383 -0
- package/src/tests/session-reset-notification.test.ts +145 -0
- package/src/tests/thread-switch-events.test.tsx +99 -1
- package/src/tests/tools-scope-migration.test.tsx +58 -0
- package/src/tests/useRemoteThreadListRuntime-controlled.test.tsx +67 -0
- package/src/types/message.ts +1 -1
- package/src/utils/composite-context-provider.test.ts +139 -0
- package/src/utils/composite-context-provider.ts +26 -8
- package/src/utils/notify-event-listeners.ts +10 -5
- package/src/utils/silent-runtime-action.ts +6 -0
|
@@ -9,6 +9,45 @@ describe("AssistantFrameProvider", () => {
|
|
|
9
9
|
let messageHandler: ((event: MessageEvent) => void) | undefined;
|
|
10
10
|
let parentWindow: Window;
|
|
11
11
|
|
|
12
|
+
const dispatchToolCall = (
|
|
13
|
+
origin: string,
|
|
14
|
+
source: Window = parentWindow,
|
|
15
|
+
id = "tool-call-1",
|
|
16
|
+
) => {
|
|
17
|
+
messageHandler?.(
|
|
18
|
+
new MessageEvent("message", {
|
|
19
|
+
data: {
|
|
20
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
21
|
+
message: {
|
|
22
|
+
type: "tool-call",
|
|
23
|
+
id,
|
|
24
|
+
toolName: "sensitiveTool",
|
|
25
|
+
args: {},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
origin,
|
|
29
|
+
source,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const dispatchToolCancel = (
|
|
35
|
+
origin: string,
|
|
36
|
+
source: Window = parentWindow,
|
|
37
|
+
id = "tool-call-1",
|
|
38
|
+
) => {
|
|
39
|
+
messageHandler?.(
|
|
40
|
+
new MessageEvent("message", {
|
|
41
|
+
data: {
|
|
42
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
43
|
+
message: { type: "tool-cancel", id },
|
|
44
|
+
},
|
|
45
|
+
origin,
|
|
46
|
+
source,
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
12
51
|
beforeEach(() => {
|
|
13
52
|
parentWindow = {
|
|
14
53
|
postMessage: vi.fn(),
|
|
@@ -47,37 +86,325 @@ describe("AssistantFrameProvider", () => {
|
|
|
47
86
|
"https://parent.example",
|
|
48
87
|
);
|
|
49
88
|
|
|
50
|
-
const toolCall = {
|
|
51
|
-
channel: FRAME_MESSAGE_CHANNEL,
|
|
52
|
-
message: {
|
|
53
|
-
type: "tool-call",
|
|
54
|
-
id: "tool-call-1",
|
|
55
|
-
toolName: "sensitiveTool",
|
|
56
|
-
args: {},
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
89
|
const otherWindow = {
|
|
60
90
|
postMessage: vi.fn(),
|
|
61
91
|
} as unknown as Window;
|
|
62
92
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
93
|
+
dispatchToolCall("https://parent.example", otherWindow);
|
|
94
|
+
|
|
95
|
+
expect(execute).not.toHaveBeenCalled();
|
|
96
|
+
|
|
97
|
+
dispatchToolCall("https://parent.example");
|
|
98
|
+
|
|
99
|
+
await vi.waitFor(() => expect(execute).toHaveBeenCalledOnce());
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("aborts in-flight tool calls when the parent cancels them", async () => {
|
|
103
|
+
let toolSignal: AbortSignal | undefined;
|
|
104
|
+
const execute = vi.fn(
|
|
105
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
106
|
+
toolSignal = context.abortSignal;
|
|
107
|
+
await new Promise<never>((_resolve, reject) => {
|
|
108
|
+
context.abortSignal.addEventListener(
|
|
109
|
+
"abort",
|
|
110
|
+
() => reject(context.abortSignal.reason),
|
|
111
|
+
{ once: true },
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
117
|
+
getModelContext: () => ({
|
|
118
|
+
tools: { sensitiveTool: { execute } },
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
dispatchToolCall("*");
|
|
123
|
+
await vi.waitFor(() => expect(toolSignal).toBeDefined());
|
|
124
|
+
|
|
125
|
+
dispatchToolCancel("*");
|
|
126
|
+
|
|
127
|
+
expect(toolSignal?.aborted).toBe(true);
|
|
128
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
129
|
+
expect(parentWindow.postMessage).not.toHaveBeenCalledWith(
|
|
130
|
+
expect.objectContaining({
|
|
131
|
+
message: expect.objectContaining({ type: "tool-result" }),
|
|
68
132
|
}),
|
|
133
|
+
expect.anything(),
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("cancels only the matching in-flight tool call", async () => {
|
|
138
|
+
const signals = new Map<string, AbortSignal>();
|
|
139
|
+
const execute = vi.fn(
|
|
140
|
+
async (
|
|
141
|
+
_args: unknown,
|
|
142
|
+
context: { toolCallId: string; abortSignal: AbortSignal },
|
|
143
|
+
) => {
|
|
144
|
+
signals.set(context.toolCallId, context.abortSignal);
|
|
145
|
+
await new Promise<never>((_resolve, reject) => {
|
|
146
|
+
context.abortSignal.addEventListener(
|
|
147
|
+
"abort",
|
|
148
|
+
() => reject(context.abortSignal.reason),
|
|
149
|
+
{ once: true },
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
155
|
+
getModelContext: () => ({ tools: { sensitiveTool: { execute } } }),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
dispatchToolCall("*", parentWindow, "tool-a");
|
|
159
|
+
dispatchToolCall("*", parentWindow, "tool-b");
|
|
160
|
+
await vi.waitFor(() => expect(signals.size).toBe(2));
|
|
161
|
+
|
|
162
|
+
dispatchToolCancel("*", parentWindow, "tool-a");
|
|
163
|
+
|
|
164
|
+
expect(signals.get("tool-a")?.aborted).toBe(true);
|
|
165
|
+
expect(signals.get("tool-b")?.aborted).toBe(false);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("aborts an earlier call when a duplicate ID arrives", async () => {
|
|
169
|
+
const signals: AbortSignal[] = [];
|
|
170
|
+
const execute = vi.fn(
|
|
171
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
172
|
+
signals.push(context.abortSignal);
|
|
173
|
+
await new Promise<never>((_resolve, reject) => {
|
|
174
|
+
context.abortSignal.addEventListener(
|
|
175
|
+
"abort",
|
|
176
|
+
() => reject(context.abortSignal.reason),
|
|
177
|
+
{ once: true },
|
|
178
|
+
);
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
);
|
|
182
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
183
|
+
getModelContext: () => ({ tools: { sensitiveTool: { execute } } }),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
dispatchToolCall("*", parentWindow, "duplicate");
|
|
187
|
+
await vi.waitFor(() => expect(signals).toHaveLength(1));
|
|
188
|
+
dispatchToolCall("*", parentWindow, "duplicate");
|
|
189
|
+
await vi.waitFor(() => expect(signals).toHaveLength(2));
|
|
190
|
+
|
|
191
|
+
expect(signals[0]?.aborted).toBe(true);
|
|
192
|
+
expect(signals[1]?.aborted).toBe(false);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("aborts in-flight tool calls when the provider is disposed", async () => {
|
|
196
|
+
let toolSignal: AbortSignal | undefined;
|
|
197
|
+
const execute = vi.fn(
|
|
198
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
199
|
+
toolSignal = context.abortSignal;
|
|
200
|
+
await new Promise<never>((_resolve, reject) => {
|
|
201
|
+
context.abortSignal.addEventListener(
|
|
202
|
+
"abort",
|
|
203
|
+
() => reject(context.abortSignal.reason),
|
|
204
|
+
{ once: true },
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
210
|
+
getModelContext: () => ({ tools: { sensitiveTool: { execute } } }),
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
dispatchToolCall("*");
|
|
214
|
+
await vi.waitFor(() => expect(toolSignal).toBeDefined());
|
|
215
|
+
|
|
216
|
+
AssistantFrameProvider.dispose();
|
|
217
|
+
|
|
218
|
+
expect(toolSignal?.aborted).toBe(true);
|
|
219
|
+
expect(parentWindow.postMessage).toHaveBeenCalledWith(
|
|
220
|
+
{
|
|
221
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
222
|
+
message: {
|
|
223
|
+
type: "tool-result",
|
|
224
|
+
id: "tool-call-1",
|
|
225
|
+
error: "AssistantFrameProvider has been disposed",
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
{ targetOrigin: "*" },
|
|
229
|
+
);
|
|
230
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
231
|
+
const toolResults = vi
|
|
232
|
+
.mocked(parentWindow.postMessage)
|
|
233
|
+
.mock.calls.filter(
|
|
234
|
+
([data]) =>
|
|
235
|
+
(data as { message?: { type?: string } }).message?.type ===
|
|
236
|
+
"tool-result",
|
|
237
|
+
);
|
|
238
|
+
expect(toolResults).toHaveLength(1);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("upgrades a wildcard origin policy when a strict provider registers", async () => {
|
|
242
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
243
|
+
{ getModelContext: () => ({}) },
|
|
244
|
+
"*",
|
|
69
245
|
);
|
|
70
246
|
|
|
247
|
+
const execute = vi.fn(async () => "result");
|
|
248
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
249
|
+
{
|
|
250
|
+
getModelContext: () => ({
|
|
251
|
+
tools: {
|
|
252
|
+
sensitiveTool: { execute },
|
|
253
|
+
},
|
|
254
|
+
}),
|
|
255
|
+
},
|
|
256
|
+
"https://parent.example",
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
260
|
+
expect.anything(),
|
|
261
|
+
"https://parent.example",
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
dispatchToolCall("https://untrusted.example");
|
|
265
|
+
|
|
71
266
|
expect(execute).not.toHaveBeenCalled();
|
|
72
267
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
268
|
+
dispatchToolCall("https://parent.example");
|
|
269
|
+
|
|
270
|
+
await vi.waitFor(() => expect(execute).toHaveBeenCalledOnce());
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("does not downgrade a strict origin policy for a wildcard provider", async () => {
|
|
274
|
+
const execute = vi.fn(async () => "result");
|
|
275
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
276
|
+
{
|
|
277
|
+
getModelContext: () => ({
|
|
278
|
+
tools: {
|
|
279
|
+
sensitiveTool: { execute },
|
|
280
|
+
},
|
|
281
|
+
}),
|
|
282
|
+
},
|
|
283
|
+
"https://parent.example",
|
|
284
|
+
);
|
|
285
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
286
|
+
{ getModelContext: () => ({}) },
|
|
287
|
+
"*",
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
dispatchToolCall("https://untrusted.example");
|
|
291
|
+
|
|
292
|
+
expect(execute).not.toHaveBeenCalled();
|
|
293
|
+
|
|
294
|
+
dispatchToolCall("https://parent.example");
|
|
295
|
+
|
|
296
|
+
await vi.waitFor(() => expect(execute).toHaveBeenCalledOnce());
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("rejects conflicting strict origin policies", () => {
|
|
300
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
301
|
+
{ getModelContext: () => ({}) },
|
|
302
|
+
"https://first.example",
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
expect(() =>
|
|
306
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
307
|
+
{ getModelContext: () => ({}) },
|
|
308
|
+
"https://second.example",
|
|
309
|
+
),
|
|
310
|
+
).toThrow(
|
|
311
|
+
'AssistantFrameProvider cannot register conflicting target origins: "https://first.example" and "https://second.example"',
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("resets the origin policy after every provider unsubscribes", () => {
|
|
316
|
+
const unsubscribe = AssistantFrameProvider.addModelContextProvider(
|
|
317
|
+
{ getModelContext: () => ({}) },
|
|
318
|
+
"https://first.example",
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
unsubscribe();
|
|
322
|
+
|
|
323
|
+
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
324
|
+
expect.anything(),
|
|
325
|
+
"*",
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
expect(() =>
|
|
329
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
330
|
+
{ getModelContext: () => ({}) },
|
|
331
|
+
"https://second.example",
|
|
332
|
+
),
|
|
333
|
+
).not.toThrow();
|
|
334
|
+
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
335
|
+
expect.anything(),
|
|
336
|
+
"https://second.example",
|
|
79
337
|
);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it("treats a second unsubscribe as a no-op", () => {
|
|
341
|
+
const unsubscribe = AssistantFrameProvider.addModelContextProvider(
|
|
342
|
+
{ getModelContext: () => ({}) },
|
|
343
|
+
"https://first.example",
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
unsubscribe();
|
|
347
|
+
unsubscribe();
|
|
348
|
+
|
|
349
|
+
const unsubscribeSecond = AssistantFrameProvider.addModelContextProvider(
|
|
350
|
+
{ getModelContext: () => ({}) },
|
|
351
|
+
"https://second.example",
|
|
352
|
+
);
|
|
353
|
+
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
354
|
+
expect.anything(),
|
|
355
|
+
"https://second.example",
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
unsubscribeSecond();
|
|
359
|
+
unsubscribeSecond();
|
|
360
|
+
|
|
361
|
+
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
362
|
+
expect.anything(),
|
|
363
|
+
"*",
|
|
364
|
+
);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it("recomputes the origin policy from providers that remain", () => {
|
|
368
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
369
|
+
{ getModelContext: () => ({}) },
|
|
370
|
+
"*",
|
|
371
|
+
);
|
|
372
|
+
const unsubscribeStrict = AssistantFrameProvider.addModelContextProvider(
|
|
373
|
+
{ getModelContext: () => ({}) },
|
|
374
|
+
"https://parent.example",
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
unsubscribeStrict();
|
|
378
|
+
|
|
379
|
+
expect(parentWindow.postMessage).toHaveBeenLastCalledWith(
|
|
380
|
+
expect.anything(),
|
|
381
|
+
"*",
|
|
382
|
+
);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("keeps a shared strict origin after one provider unsubscribes", async () => {
|
|
386
|
+
const unsubscribeFirst = AssistantFrameProvider.addModelContextProvider(
|
|
387
|
+
{ getModelContext: () => ({}) },
|
|
388
|
+
"https://parent.example",
|
|
389
|
+
);
|
|
390
|
+
const execute = vi.fn(async () => "result");
|
|
391
|
+
AssistantFrameProvider.addModelContextProvider(
|
|
392
|
+
{
|
|
393
|
+
getModelContext: () => ({
|
|
394
|
+
tools: {
|
|
395
|
+
sensitiveTool: { execute },
|
|
396
|
+
},
|
|
397
|
+
}),
|
|
398
|
+
},
|
|
399
|
+
"https://parent.example",
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
unsubscribeFirst();
|
|
403
|
+
|
|
404
|
+
dispatchToolCall("https://untrusted.example");
|
|
405
|
+
expect(execute).not.toHaveBeenCalled();
|
|
80
406
|
|
|
407
|
+
dispatchToolCall("https://parent.example");
|
|
81
408
|
await vi.waitFor(() => expect(execute).toHaveBeenCalledOnce());
|
|
82
409
|
});
|
|
83
410
|
});
|
|
@@ -37,7 +37,12 @@ export class AssistantFrameProvider {
|
|
|
37
37
|
ModelContextProvider,
|
|
38
38
|
Unsubscribe | undefined
|
|
39
39
|
>();
|
|
40
|
+
private _activeToolCalls = new Map<
|
|
41
|
+
string,
|
|
42
|
+
{ abortController: AbortController; event: MessageEvent }
|
|
43
|
+
>();
|
|
40
44
|
private _targetOrigin: string;
|
|
45
|
+
private _strictRegistrations = 0;
|
|
41
46
|
|
|
42
47
|
private constructor(targetOrigin: string = "*") {
|
|
43
48
|
this._targetOrigin = targetOrigin;
|
|
@@ -52,10 +57,25 @@ export class AssistantFrameProvider {
|
|
|
52
57
|
AssistantFrameProvider._instance = new AssistantFrameProvider(
|
|
53
58
|
targetOrigin,
|
|
54
59
|
);
|
|
60
|
+
} else {
|
|
61
|
+
AssistantFrameProvider._instance.reconcileTargetOrigin(targetOrigin);
|
|
55
62
|
}
|
|
56
63
|
return AssistantFrameProvider._instance;
|
|
57
64
|
}
|
|
58
65
|
|
|
66
|
+
private reconcileTargetOrigin(targetOrigin: string = "*") {
|
|
67
|
+
if (targetOrigin === "*" || targetOrigin === this._targetOrigin) return;
|
|
68
|
+
|
|
69
|
+
if (this._targetOrigin === "*") {
|
|
70
|
+
this._targetOrigin = targetOrigin;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throw new Error(
|
|
75
|
+
`AssistantFrameProvider cannot register conflicting target origins: "${this._targetOrigin}" and "${targetOrigin}"`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
59
79
|
private handleMessage(event: MessageEvent) {
|
|
60
80
|
if (this._targetOrigin !== "*" && event.origin !== this._targetOrigin)
|
|
61
81
|
return;
|
|
@@ -75,6 +95,10 @@ export class AssistantFrameProvider {
|
|
|
75
95
|
case "tool-call":
|
|
76
96
|
this.handleToolCall(message, event);
|
|
77
97
|
break;
|
|
98
|
+
|
|
99
|
+
case "tool-cancel":
|
|
100
|
+
this.cancelToolCall(message.id);
|
|
101
|
+
break;
|
|
78
102
|
}
|
|
79
103
|
}
|
|
80
104
|
|
|
@@ -83,6 +107,10 @@ export class AssistantFrameProvider {
|
|
|
83
107
|
event: MessageEvent,
|
|
84
108
|
) {
|
|
85
109
|
const tool = this.getModelContext().tools?.[message.toolName];
|
|
110
|
+
const abortController = new AbortController();
|
|
111
|
+
this._activeToolCalls.get(message.id)?.abortController.abort();
|
|
112
|
+
const activeCall = { abortController, event };
|
|
113
|
+
this._activeToolCalls.set(message.id, activeCall);
|
|
86
114
|
|
|
87
115
|
let result: any;
|
|
88
116
|
let error: string | undefined;
|
|
@@ -94,7 +122,7 @@ export class AssistantFrameProvider {
|
|
|
94
122
|
result = tool.execute
|
|
95
123
|
? await tool.execute(message.args, {
|
|
96
124
|
toolCallId: message.id,
|
|
97
|
-
abortSignal:
|
|
125
|
+
abortSignal: abortController.signal,
|
|
98
126
|
human: async () => {
|
|
99
127
|
throw new Error(
|
|
100
128
|
"Tool human input is not supported in frame context",
|
|
@@ -107,6 +135,9 @@ export class AssistantFrameProvider {
|
|
|
107
135
|
}
|
|
108
136
|
}
|
|
109
137
|
|
|
138
|
+
if (this._activeToolCalls.get(message.id) !== activeCall) return;
|
|
139
|
+
this._activeToolCalls.delete(message.id);
|
|
140
|
+
|
|
110
141
|
this.sendMessage(event, {
|
|
111
142
|
type: "tool-result",
|
|
112
143
|
id: message.id,
|
|
@@ -114,6 +145,13 @@ export class AssistantFrameProvider {
|
|
|
114
145
|
});
|
|
115
146
|
}
|
|
116
147
|
|
|
148
|
+
private cancelToolCall(id: string) {
|
|
149
|
+
const activeCall = this._activeToolCalls.get(id);
|
|
150
|
+
if (!activeCall) return;
|
|
151
|
+
this._activeToolCalls.delete(id);
|
|
152
|
+
activeCall.abortController.abort();
|
|
153
|
+
}
|
|
154
|
+
|
|
117
155
|
private sendMessage(event: MessageEvent, message: FrameMessage) {
|
|
118
156
|
event.source?.postMessage(
|
|
119
157
|
{ channel: FRAME_MESSAGE_CHANNEL, message },
|
|
@@ -157,8 +195,10 @@ export class AssistantFrameProvider {
|
|
|
157
195
|
provider: ModelContextProvider,
|
|
158
196
|
targetOrigin?: string,
|
|
159
197
|
): Unsubscribe {
|
|
160
|
-
const
|
|
198
|
+
const origin = targetOrigin ?? "*";
|
|
199
|
+
const instance = AssistantFrameProvider.getInstance(origin);
|
|
161
200
|
instance._providers.add(provider);
|
|
201
|
+
if (origin !== "*") instance._strictRegistrations += 1;
|
|
162
202
|
|
|
163
203
|
const unsubscribe = provider.subscribe?.(() => instance.broadcastUpdate());
|
|
164
204
|
if (unsubscribe) {
|
|
@@ -167,10 +207,17 @@ export class AssistantFrameProvider {
|
|
|
167
207
|
|
|
168
208
|
instance.broadcastUpdate();
|
|
169
209
|
|
|
210
|
+
let released = false;
|
|
170
211
|
return () => {
|
|
212
|
+
if (released) return;
|
|
213
|
+
released = true;
|
|
171
214
|
instance._providers.delete(provider);
|
|
172
215
|
instance._providerUnsubscribes.get(provider)?.();
|
|
173
216
|
instance._providerUnsubscribes.delete(provider);
|
|
217
|
+
if (origin !== "*") {
|
|
218
|
+
instance._strictRegistrations -= 1;
|
|
219
|
+
if (instance._strictRegistrations === 0) instance._targetOrigin = "*";
|
|
220
|
+
}
|
|
174
221
|
instance.broadcastUpdate();
|
|
175
222
|
};
|
|
176
223
|
}
|
|
@@ -183,6 +230,15 @@ export class AssistantFrameProvider {
|
|
|
183
230
|
instance._providerUnsubscribes.forEach((unsubscribe) => unsubscribe?.());
|
|
184
231
|
instance._providerUnsubscribes.clear();
|
|
185
232
|
instance._providers.clear();
|
|
233
|
+
instance._activeToolCalls.forEach(({ abortController, event }, id) => {
|
|
234
|
+
abortController.abort();
|
|
235
|
+
instance.sendMessage(event, {
|
|
236
|
+
type: "tool-result",
|
|
237
|
+
id,
|
|
238
|
+
error: "AssistantFrameProvider has been disposed",
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
instance._activeToolCalls.clear();
|
|
186
242
|
|
|
187
243
|
AssistantFrameProvider._instance = null;
|
|
188
244
|
}
|
|
@@ -14,6 +14,7 @@ export type FrameMessageType =
|
|
|
14
14
|
| "model-context-request"
|
|
15
15
|
| "model-context-update"
|
|
16
16
|
| "tool-call"
|
|
17
|
+
| "tool-cancel"
|
|
17
18
|
| "tool-result";
|
|
18
19
|
|
|
19
20
|
export type FrameMessage =
|
|
@@ -30,6 +31,10 @@ export type FrameMessage =
|
|
|
30
31
|
toolName: string;
|
|
31
32
|
args: unknown;
|
|
32
33
|
}
|
|
34
|
+
| {
|
|
35
|
+
type: "tool-cancel";
|
|
36
|
+
id: string;
|
|
37
|
+
}
|
|
33
38
|
| {
|
|
34
39
|
type: "tool-result";
|
|
35
40
|
id: string;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { ModelContextRegistry } from "./registry";
|
|
3
|
+
|
|
4
|
+
describe("ModelContextRegistry", () => {
|
|
5
|
+
it("notifies every subscriber and rethrows when a registration subscriber throws", () => {
|
|
6
|
+
const registry = new ModelContextRegistry();
|
|
7
|
+
const error = new Error("subscriber failed");
|
|
8
|
+
const laterSubscriber = vi.fn();
|
|
9
|
+
|
|
10
|
+
registry.subscribe(() => {
|
|
11
|
+
throw error;
|
|
12
|
+
});
|
|
13
|
+
registry.subscribe(laterSubscriber);
|
|
14
|
+
|
|
15
|
+
expect(() => registry.addTool({ toolName: "search" })).toThrow(error);
|
|
16
|
+
|
|
17
|
+
expect(registry.getModelContext().tools).toHaveProperty("search");
|
|
18
|
+
expect(laterSubscriber).toHaveBeenCalledTimes(1);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("keeps a provider registered when a registration subscriber throws", () => {
|
|
22
|
+
const registry = new ModelContextRegistry();
|
|
23
|
+
const error = new Error("subscriber failed");
|
|
24
|
+
const laterSubscriber = vi.fn();
|
|
25
|
+
|
|
26
|
+
registry.subscribe(() => {
|
|
27
|
+
throw error;
|
|
28
|
+
});
|
|
29
|
+
registry.subscribe(laterSubscriber);
|
|
30
|
+
|
|
31
|
+
expect(() =>
|
|
32
|
+
registry.addProvider({
|
|
33
|
+
getModelContext: () => ({ system: "provider instructions" }),
|
|
34
|
+
}),
|
|
35
|
+
).toThrow(error);
|
|
36
|
+
|
|
37
|
+
expect(registry.getModelContext().system).toBe("provider instructions");
|
|
38
|
+
expect(laterSubscriber).toHaveBeenCalledTimes(1);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("notifies every subscriber and rethrows when registering instructions", () => {
|
|
42
|
+
const registry = new ModelContextRegistry();
|
|
43
|
+
const error = new Error("subscriber failed");
|
|
44
|
+
const laterSubscriber = vi.fn();
|
|
45
|
+
|
|
46
|
+
registry.subscribe(() => {
|
|
47
|
+
throw error;
|
|
48
|
+
});
|
|
49
|
+
registry.subscribe(laterSubscriber);
|
|
50
|
+
|
|
51
|
+
expect(() => registry.addInstruction("be concise")).toThrow(error);
|
|
52
|
+
|
|
53
|
+
expect(registry.getModelContext().system).toContain("be concise");
|
|
54
|
+
expect(laterSubscriber).toHaveBeenCalledTimes(1);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("rethrows the provider subscription failure when a rollback subscriber throws", () => {
|
|
58
|
+
const registry = new ModelContextRegistry();
|
|
59
|
+
const subscriptionError = new Error("subscription failed");
|
|
60
|
+
const subscriberError = new Error("subscriber failed");
|
|
61
|
+
const consoleError = vi
|
|
62
|
+
.spyOn(console, "error")
|
|
63
|
+
.mockImplementation(() => {});
|
|
64
|
+
|
|
65
|
+
registry.subscribe(() => {
|
|
66
|
+
throw subscriberError;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
expect(() =>
|
|
71
|
+
registry.addProvider({
|
|
72
|
+
getModelContext: () => ({ system: "provider instructions" }),
|
|
73
|
+
subscribe: () => {
|
|
74
|
+
throw subscriptionError;
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
).toThrow(subscriptionError);
|
|
78
|
+
|
|
79
|
+
expect(registry.getModelContext().system).toBeUndefined();
|
|
80
|
+
expect(consoleError).toHaveBeenCalledWith(subscriberError);
|
|
81
|
+
} finally {
|
|
82
|
+
consoleError.mockRestore();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("rolls back providers that fail to subscribe", () => {
|
|
87
|
+
const registry = new ModelContextRegistry();
|
|
88
|
+
const error = new Error("subscription failed");
|
|
89
|
+
const observedSystems: Array<string | undefined> = [];
|
|
90
|
+
|
|
91
|
+
registry.subscribe(() => {
|
|
92
|
+
observedSystems.push(registry.getModelContext().system);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
expect(() =>
|
|
96
|
+
registry.addProvider({
|
|
97
|
+
getModelContext: () => ({ system: "provider instructions" }),
|
|
98
|
+
subscribe: (callback) => {
|
|
99
|
+
callback();
|
|
100
|
+
throw error;
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
).toThrow(error);
|
|
104
|
+
|
|
105
|
+
expect(registry.getModelContext().system).toBeUndefined();
|
|
106
|
+
expect(observedSystems).toEqual(["provider instructions", undefined]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("notifies every subscriber and rethrows on provider updates", () => {
|
|
110
|
+
const registry = new ModelContextRegistry();
|
|
111
|
+
const error = new Error("subscriber failed");
|
|
112
|
+
const laterSubscriber = vi.fn();
|
|
113
|
+
let publishUpdate = () => {};
|
|
114
|
+
|
|
115
|
+
registry.addProvider({
|
|
116
|
+
getModelContext: () => ({ system: "provider instructions" }),
|
|
117
|
+
subscribe: (callback) => {
|
|
118
|
+
publishUpdate = callback;
|
|
119
|
+
return () => {};
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
registry.subscribe(() => {
|
|
124
|
+
throw error;
|
|
125
|
+
});
|
|
126
|
+
registry.subscribe(laterSubscriber);
|
|
127
|
+
|
|
128
|
+
expect(() => publishUpdate()).toThrow(error);
|
|
129
|
+
expect(laterSubscriber).toHaveBeenCalledTimes(1);
|
|
130
|
+
});
|
|
131
|
+
});
|