@assistant-ui/core 0.3.16 → 0.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/attachment.d.ts.map +1 -1
- package/dist/adapters/attachment.js +5 -4
- package/dist/adapters/attachment.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -2
- package/dist/internal.js +4 -2
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +10 -4
- 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 +101 -28
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/interactable-composer-metadata.d.ts.map +1 -1
- package/dist/model-context/interactable-composer-metadata.js +16 -9
- package/dist/model-context/interactable-composer-metadata.js.map +1 -1
- package/dist/model-context/registry.d.ts.map +1 -1
- package/dist/model-context/registry.js +3 -5
- 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/model-context/types.d.ts.map +1 -1
- package/dist/model-context/types.js +5 -4
- package/dist/model-context/types.js.map +1 -1
- 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 +63 -57
- 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 +25 -28
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/RemoteThreadList.d.ts +16 -0
- package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
- package/dist/react/client/RemoteThreadList.js +354 -242
- 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 +24 -18
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/interactables-legacy/Interactables.js +246 -125
- package/dist/react/interactables-legacy/Interactables.js.map +1 -1
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts.map +1 -1
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.js +11 -9
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.js.map +1 -1
- package/dist/react/model-context/makeAssistantTool.d.ts +2 -2
- package/dist/react/model-context/makeAssistantTool.js +1 -1
- package/dist/react/model-context/makeAssistantTool.js.map +1 -1
- 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/useAssistantTool.d.ts +2 -2
- package/dist/react/model-context/useAssistantTool.js +1 -1
- package/dist/react/model-context/useAssistantTool.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/model-context/useToolArgsStatus.d.ts.map +1 -1
- package/dist/react/model-context/useToolArgsStatus.js +2 -1
- package/dist/react/model-context/useToolArgsStatus.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/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 +6 -4
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +59 -29
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +11 -6
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +160 -143
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.d.ts +2 -6
- package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.js +15 -13
- package/dist/react/runtimes/RemoteThreadResource.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 +4 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +424 -52
- 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 +160 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.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/external-message-converter.js +1 -1
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.js +75 -46
- package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +77 -29
- 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/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-item-runtime.d.ts +7 -3
- package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.js +2 -2
- package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +12 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +23 -14
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +5 -1
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.js +1 -1
- 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 +16 -12
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +2 -2
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +8 -7
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/composer-runtime-core.d.ts +12 -5
- package/dist/runtime/interfaces/composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +18 -3
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +15 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/utils/auto-status.d.ts +1 -1
- package/dist/runtime/utils/auto-status.d.ts.map +1 -1
- package/dist/runtime/utils/auto-status.js +6 -2
- package/dist/runtime/utils/auto-status.js.map +1 -1
- package/dist/runtime/utils/external-message-conversion.d.ts +3 -2
- package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -1
- package/dist/runtime/utils/external-message-conversion.js +5 -4
- package/dist/runtime/utils/external-message-conversion.js.map +1 -1
- package/dist/runtime/utils/message-repository.d.ts +1 -0
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.js +15 -6
- package/dist/runtime/utils/message-repository.js.map +1 -1
- 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 +2 -10
- package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.js +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.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +21 -27
- 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 +2 -1
- 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 +34 -28
- 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/internal.d.ts +2 -2
- package/dist/runtimes/internal.js +2 -2
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +3 -1
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +18 -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 +148 -43
- package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/title-generation.d.ts +49 -0
- package/dist/runtimes/remote-thread-list/title-generation.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/title-generation.js +197 -0
- package/dist/runtimes/remote-thread-list/title-generation.js.map +1 -0
- package/dist/runtimes/remote-thread-list/title.d.ts +11 -0
- package/dist/runtimes/remote-thread-list/title.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/title.js +14 -0
- package/dist/runtimes/remote-thread-list/title.js.map +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts +16 -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 +97 -60
- 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 +30 -7
- package/dist/store/clients/external-thread.js.map +1 -1
- package/dist/store/clients/model-context-client.d.ts.map +1 -1
- package/dist/store/clients/model-context-client.js +2 -1
- package/dist/store/clients/model-context-client.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 -1
- 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 +19 -6
- 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 +2 -1
- 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.d.ts +1 -0
- package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +98 -62
- package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts +1 -0
- package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +221 -144
- package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
- 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 +2 -2
- 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 +128 -107
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +194 -122
- package/dist/store/runtime-clients/thread-runtime-client.js.map +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/scopes/composer.d.ts +10 -2
- package/dist/store/scopes/composer.d.ts.map +1 -1
- package/dist/store/scopes/message.d.ts +30 -1
- package/dist/store/scopes/message.d.ts.map +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/thread-list-item.d.ts +2 -2
- package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
- package/dist/store/scopes/thread.d.ts +8 -0
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/store/scopes/threads.d.ts +1 -0
- package/dist/store/scopes/threads.d.ts.map +1 -1
- 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/attachment.d.ts +2 -1
- package/dist/types/attachment.d.ts.map +1 -1
- package/dist/types/attachment.js +2 -1
- package/dist/types/attachment.js.map +1 -1
- package/dist/types/message.d.ts +40 -1
- 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/abortable-iterable.d.ts +19 -0
- package/dist/utils/abortable-iterable.d.ts.map +1 -0
- package/dist/utils/abortable-iterable.js +72 -0
- package/dist/utils/abortable-iterable.js.map +1 -0
- package/dist/utils/composite-context-provider.d.ts.map +1 -1
- package/dist/utils/composite-context-provider.js +20 -2
- package/dist/utils/composite-context-provider.js.map +1 -1
- package/dist/utils/record.d.ts +11 -0
- package/dist/utils/record.d.ts.map +1 -0
- package/dist/utils/record.js +12 -0
- package/dist/utils/record.js.map +1 -0
- package/package.json +12 -17
- package/src/adapters/attachment.test.ts +50 -1
- package/src/adapters/attachment.ts +7 -4
- package/src/index.ts +7 -1
- package/src/internal.ts +12 -0
- package/src/model-context/frame/host.test.ts +24 -0
- package/src/model-context/frame/host.ts +10 -4
- package/src/model-context/frame/provider.test.ts +288 -1
- package/src/model-context/frame/provider.ts +148 -30
- package/src/model-context/interactable-composer-metadata.test.ts +28 -0
- package/src/model-context/interactable-composer-metadata.ts +9 -3
- package/src/model-context/registry.test.ts +12 -0
- package/src/model-context/registry.ts +3 -2
- package/src/model-context/tool-call-text.test.ts +67 -0
- package/src/model-context/tool-call-text.ts +67 -0
- package/src/model-context/types.test.ts +25 -0
- package/src/model-context/types.ts +9 -4
- package/src/react/AssistantRuntimeProvider.test.tsx +66 -2
- package/src/react/RuntimeAdapter.test.ts +34 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +1 -3
- package/src/react/client/InMemoryThreadList.ts +1 -0
- package/src/react/client/Interactables.test.ts +28 -0
- package/src/react/client/Interactables.ts +15 -13
- package/src/react/client/RemoteThreadList.background.test.ts +526 -0
- package/src/react/client/RemoteThreadList.concurrent.test.tsx +315 -0
- package/src/react/client/RemoteThreadList.test.ts +617 -3
- package/src/react/client/RemoteThreadList.ts +433 -167
- package/src/react/client/Tools.ts +29 -12
- package/src/react/index.ts +4 -0
- package/src/react/interactables-legacy/Interactables.ts +16 -16
- package/src/react/interactables-shared/useInteractablePersistenceQueue.ts +9 -10
- package/src/react/model-context/makeAssistantTool.ts +2 -2
- 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/useAssistantTool.ts +2 -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/model-context/useToolArgsStatus.test.tsx +30 -0
- package/src/react/model-context/useToolArgsStatus.ts +2 -1
- 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.destroy.test.tsx +172 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +127 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +7 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +99 -35
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.load-error.test.ts +132 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.switch-delete.test.ts +274 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +223 -152
- package/src/react/runtimes/RemoteThreadResource.test.ts +9 -0
- package/src/react/runtimes/RemoteThreadResource.ts +20 -16
- 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 +546 -5
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +546 -103
- package/src/react/runtimes/cloud/auiV0.ts +5 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +103 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +237 -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.ts +1 -0
- package/src/react/runtimes/useExternalStoreRuntime.lifecycle.test.tsx +41 -0
- package/src/react/runtimes/useExternalStoreRuntime.ts +10 -4
- package/src/react/runtimes/useLocalRuntime.test.tsx +20 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.concurrent.test.tsx +216 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.load-error.test.tsx +108 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +57 -6
- package/src/react/types/MessagePartComponentTypes.ts +7 -3
- package/src/react/types/scopes/tools.ts +2 -0
- package/src/runtime/api/message-part-runtime.ts +3 -3
- package/src/runtime/api/message-runtime.test.ts +75 -0
- package/src/runtime/api/thread-list-item-runtime.ts +10 -3
- package/src/runtime/api/thread-list-runtime.ts +46 -12
- package/src/runtime/api/thread-runtime.test.ts +78 -0
- package/src/runtime/api/thread-runtime.ts +8 -1
- package/src/runtime/base/base-composer-runtime-core.ts +36 -8
- package/src/runtime/base/base-thread-runtime-core.test.ts +149 -4
- package/src/runtime/base/base-thread-runtime-core.ts +16 -8
- package/src/runtime/interfaces/composer-runtime-core.ts +10 -5
- package/src/runtime/interfaces/thread-list-runtime-core.ts +25 -2
- package/src/runtime/interfaces/thread-runtime-core.ts +17 -1
- package/src/runtime/utils/auto-status.test.ts +57 -0
- package/src/runtime/utils/auto-status.ts +13 -1
- package/src/runtime/utils/external-message-conversion.test.ts +165 -0
- package/src/runtime/utils/external-message-conversion.ts +18 -2
- package/src/runtime/utils/message-repository.ts +29 -17
- 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 +3 -11
- 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 +18 -13
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +56 -33
- package/src/runtimes/inert/InertThreadRuntimeCore.ts +1 -1
- package/src/runtimes/internal.ts +1 -0
- package/src/runtimes/local/local-thread-runtime-core.test.ts +29 -3
- package/src/runtimes/local/local-thread-runtime-core.ts +5 -1
- package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +238 -0
- package/src/runtimes/remote-thread-list/remote-thread-state.ts +223 -44
- package/src/runtimes/remote-thread-list/title-generation.test.ts +602 -0
- package/src/runtimes/remote-thread-list/title-generation.ts +329 -0
- package/src/runtimes/remote-thread-list/title.test.ts +62 -0
- package/src/runtimes/remote-thread-list/title.ts +16 -0
- package/src/runtimes/remote-thread-list/types.ts +16 -5
- package/src/runtimes/tool-invocations/EDGE_CASES.md +110 -5
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +750 -136
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +144 -91
- package/src/store/clients/external-thread.ts +62 -11
- package/src/store/clients/model-context-client.ts +5 -1
- package/src/store/clients/single-thread-list.ts +1 -0
- package/src/store/clients/suggestions.test.ts +195 -1
- package/src/store/clients/suggestions.ts +45 -34
- 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/composer-runtime-client.ts +42 -9
- package/src/store/runtime-clients/message-runtime-client.ts +54 -6
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +4 -2
- package/src/store/runtime-clients/thread-list-runtime-client.ts +17 -2
- package/src/store/runtime-clients/thread-runtime-client.ts +58 -10
- package/src/store/runtime-clients/useSubscribable.ts +8 -2
- package/src/store/scopes/composer.ts +16 -4
- package/src/store/scopes/message.ts +14 -0
- package/src/store/scopes/part.ts +6 -3
- package/src/store/scopes/thread-list-item.ts +5 -2
- package/src/store/scopes/thread.ts +4 -0
- package/src/store/scopes/threads.ts +1 -0
- package/src/subscribable/subscribable.test.ts +50 -0
- package/src/subscribable/subscribable.ts +33 -21
- package/src/tests/MessageRepository.test.ts +116 -0
- package/src/tests/OptimisticState-list-race.test.ts +1 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-initialize-adapter-change.test.ts +38 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-load-race.test.ts +158 -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 +89 -0
- package/src/tests/attachment-adapters.test.ts +14 -0
- package/src/tests/base-composer-runtime-core.test.ts +39 -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-list-runtime-core.test.ts +83 -0
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +49 -34
- package/src/tests/external-thread-attachments.test.tsx +224 -1
- package/src/tests/external-thread-parity.test.tsx +23 -0
- package/src/tests/remote-thread-list-adapter-switch.test.ts +66 -1
- package/src/tests/remote-thread-list-isLoading.test.ts +1 -0
- package/src/tests/thread-list-runtime-getLoadThreadsPromise.test.ts +1 -0
- package/src/tests/thread-switch-events.test.tsx +475 -2
- package/src/tests/tools-scope-migration.test.tsx +28 -0
- package/src/types/attachment.ts +4 -0
- package/src/types/message.ts +50 -2
- package/src/utils/abortable-iterable.test.ts +213 -0
- package/src/utils/abortable-iterable.ts +93 -0
- package/src/utils/composite-context-provider.test.ts +25 -0
- package/src/utils/composite-context-provider.ts +23 -2
- package/src/utils/record.test.ts +48 -0
- package/src/utils/record.ts +11 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/utils/record.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Builds a dictionary with no prototype from the own entries of its arguments.
|
|
4
|
+
* Bracket assignment on a plain object routes a `__proto__` key through the
|
|
5
|
+
* `Object.prototype` setter instead of defining an own property, so a record
|
|
6
|
+
* assigned into by a key the app does not control is built this way.
|
|
7
|
+
*/
|
|
8
|
+
declare const nullProtoRecord: <T>(base?: Readonly<Record<string, T>>, ...rest: readonly (Readonly<Record<string, NoInfer<T>>> | undefined)[]) => Record<string, T>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { nullProtoRecord };
|
|
11
|
+
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.d.ts","names":[],"sources":["../../src/utils/record.ts"],"mappings":";;;;;;;cAMa,kBAAmB,GAC9B,OAAO,SAAS,eAAe,QAC5B,gBAAgB,SAAS,eAAe,QAAQ,wBAClD,eAAe"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/utils/record.ts
|
|
2
|
+
/**
|
|
3
|
+
* Builds a dictionary with no prototype from the own entries of its arguments.
|
|
4
|
+
* Bracket assignment on a plain object routes a `__proto__` key through the
|
|
5
|
+
* `Object.prototype` setter instead of defining an own property, so a record
|
|
6
|
+
* assigned into by a key the app does not control is built this way.
|
|
7
|
+
*/
|
|
8
|
+
const nullProtoRecord = (base, ...rest) => Object.assign(Object.create(null), base, ...rest);
|
|
9
|
+
//#endregion
|
|
10
|
+
export { nullProtoRecord };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.js","names":["nullProtoRecord","base","Readonly","Record","T","rest","NoInfer","Object","assign","create"],"sources":["../../src/utils/record.ts"],"sourcesContent":["/**\n * Builds a dictionary with no prototype from the own entries of its arguments.\n * Bracket assignment on a plain object routes a `__proto__` key through the\n * `Object.prototype` setter instead of defining an own property, so a record\n * assigned into by a key the app does not control is built this way.\n */\nexport const nullProtoRecord = <T>(\n base?: Readonly<Record<string, T>>,\n ...rest: readonly (Readonly<Record<string, NoInfer<T>>> | undefined)[]\n): Record<string, T> =>\n Object.assign(Object.create(null) as Record<string, T>, base, ...rest);\n"],"mappings":";;;;;;;AAMA,MAAaA,mBACXC,MACA,GAAGI,SAEHE,OAAOC,OAAOD,OAAOE,OAAO,IAAI,GAAwBR,MAAM,GAAGI,IAAI"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
4
4
|
"description": "Framework-agnostic core runtime for assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"assistant",
|
|
@@ -59,19 +59,18 @@
|
|
|
59
59
|
],
|
|
60
60
|
"sideEffects": false,
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"assistant-stream": "^0.3.
|
|
62
|
+
"assistant-stream": "^0.3.42",
|
|
63
63
|
"nanoid": "^6.0.1"
|
|
64
64
|
},
|
|
65
65
|
"optionalDevDependencies": {
|
|
66
66
|
"@assistant-ui/x-generative-compiler": ">=0.0.3"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@assistant-ui/store": "^0.3.
|
|
70
|
-
"@assistant-ui/tap": "^0.9.
|
|
69
|
+
"@assistant-ui/store": "^0.3.13",
|
|
70
|
+
"@assistant-ui/tap": "^0.9.17",
|
|
71
71
|
"@types/react": "*",
|
|
72
72
|
"react": "^18 || ^19",
|
|
73
|
-
"assistant-cloud": "^0.
|
|
74
|
-
"zustand": "^5.0.11"
|
|
73
|
+
"assistant-cloud": "^0.2.0"
|
|
75
74
|
},
|
|
76
75
|
"peerDependenciesMeta": {
|
|
77
76
|
"@types/react": {
|
|
@@ -82,24 +81,20 @@
|
|
|
82
81
|
},
|
|
83
82
|
"react": {
|
|
84
83
|
"optional": true
|
|
85
|
-
},
|
|
86
|
-
"zustand": {
|
|
87
|
-
"optional": true
|
|
88
84
|
}
|
|
89
85
|
},
|
|
90
86
|
"devDependencies": {
|
|
91
|
-
"@assistant-ui/store": "0.3.
|
|
92
|
-
"@assistant-ui/tap": "0.9.
|
|
93
|
-
"@assistant-ui/vite": "0.0.
|
|
94
|
-
"@assistant-ui/x-buildutils": "0.0.
|
|
95
|
-
"@testing-library/react": "^16.3.
|
|
87
|
+
"@assistant-ui/store": "0.3.13",
|
|
88
|
+
"@assistant-ui/tap": "0.9.17",
|
|
89
|
+
"@assistant-ui/vite": "0.0.17",
|
|
90
|
+
"@assistant-ui/x-buildutils": "0.0.26",
|
|
91
|
+
"@testing-library/react": "^16.3.3",
|
|
96
92
|
"@types/react": "^19.2.18",
|
|
97
|
-
"assistant-cloud": "0.
|
|
93
|
+
"assistant-cloud": "0.2.0",
|
|
98
94
|
"jsdom": "^30.0.1",
|
|
99
95
|
"react": "^19.2.8",
|
|
100
96
|
"react-dom": "^19.2.8",
|
|
101
|
-
"vitest": "^4.1.11"
|
|
102
|
-
"zustand": "^5.0.15"
|
|
97
|
+
"vitest": "^4.1.11"
|
|
103
98
|
},
|
|
104
99
|
"publishConfig": {
|
|
105
100
|
"access": "public",
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
type AttachmentAdapter,
|
|
4
|
+
CompositeAttachmentAdapter,
|
|
5
|
+
getFileDataURL,
|
|
6
|
+
SimpleImageAttachmentAdapter,
|
|
7
|
+
} from "./attachment";
|
|
3
8
|
|
|
4
9
|
const originalFileReader = globalThis.FileReader;
|
|
5
10
|
const originalBuffer = globalThis.Buffer;
|
|
@@ -105,3 +110,47 @@ describe("SimpleImageAttachmentAdapter", () => {
|
|
|
105
110
|
);
|
|
106
111
|
});
|
|
107
112
|
});
|
|
113
|
+
|
|
114
|
+
describe("CompositeAttachmentAdapter", () => {
|
|
115
|
+
it.each(["pending", "complete"])(
|
|
116
|
+
"removes a %s attachment through its matching adapter",
|
|
117
|
+
async (status) => {
|
|
118
|
+
const removed: string[] = [];
|
|
119
|
+
const imageAdapter = {
|
|
120
|
+
accept: "image/*",
|
|
121
|
+
async add({ file }) {
|
|
122
|
+
return {
|
|
123
|
+
id: "image-1",
|
|
124
|
+
type: "image",
|
|
125
|
+
name: file.name,
|
|
126
|
+
file,
|
|
127
|
+
status: { type: "requires-action", reason: "composer-send" },
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
async send(attachment) {
|
|
131
|
+
return {
|
|
132
|
+
id: attachment.id,
|
|
133
|
+
type: attachment.type,
|
|
134
|
+
name: attachment.name,
|
|
135
|
+
contentType: attachment.file.type,
|
|
136
|
+
status: { type: "complete" },
|
|
137
|
+
content: [],
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
async remove(attachment) {
|
|
141
|
+
removed.push(attachment.id);
|
|
142
|
+
},
|
|
143
|
+
} satisfies AttachmentAdapter;
|
|
144
|
+
const composite = new CompositeAttachmentAdapter([imageAdapter]);
|
|
145
|
+
const pending = await imageAdapter.add({
|
|
146
|
+
file: new File(["image bytes"], "photo.png", { type: "image/png" }),
|
|
147
|
+
});
|
|
148
|
+
const attachment =
|
|
149
|
+
status === "pending" ? pending : await composite.send(pending);
|
|
150
|
+
|
|
151
|
+
await composite.remove(attachment);
|
|
152
|
+
|
|
153
|
+
expect(removed).toEqual(["image-1"]);
|
|
154
|
+
},
|
|
155
|
+
);
|
|
156
|
+
});
|
|
@@ -142,11 +142,11 @@ export function fileMatchesAccept(
|
|
|
142
142
|
.split(",")
|
|
143
143
|
.map((type) => type.trim().toLowerCase());
|
|
144
144
|
|
|
145
|
-
const
|
|
145
|
+
const fileName = file.name.toLowerCase();
|
|
146
146
|
const fileMimeType = file.type.split(";", 1)[0]!.trim().toLowerCase();
|
|
147
147
|
|
|
148
148
|
for (const type of allowedTypes) {
|
|
149
|
-
if (type.startsWith(".") && type
|
|
149
|
+
if (type.startsWith(".") && fileName.endsWith(type)) {
|
|
150
150
|
return true;
|
|
151
151
|
}
|
|
152
152
|
|
|
@@ -170,7 +170,10 @@ export function attachmentsEqual(
|
|
|
170
170
|
b: readonly CompleteAttachment[],
|
|
171
171
|
): boolean {
|
|
172
172
|
if (a.length !== b.length) return false;
|
|
173
|
-
|
|
173
|
+
for (let i = 0; i < a.length; i++) {
|
|
174
|
+
if (a[i]?.id !== b[i]?.id) return false;
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
export function partToCompleteAttachment(
|
|
@@ -276,7 +279,7 @@ export class CompositeAttachmentAdapter implements AttachmentAdapter {
|
|
|
276
279
|
for (const adapter of adapters) {
|
|
277
280
|
if (
|
|
278
281
|
fileMatchesAccept(
|
|
279
|
-
{
|
|
282
|
+
attachment.file ?? {
|
|
280
283
|
name: attachment.name,
|
|
281
284
|
type: attachment.contentType ?? "",
|
|
282
285
|
},
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type {
|
|
|
22
22
|
GenerativeUINode,
|
|
23
23
|
GenerativeUISpec,
|
|
24
24
|
Unstable_AudioMessagePart,
|
|
25
|
+
ToolApprovalDisplay,
|
|
25
26
|
ToolApprovalOption,
|
|
26
27
|
ToolApprovalOptionKind,
|
|
27
28
|
ToolApprovalResponse,
|
|
@@ -50,7 +51,11 @@ export type {
|
|
|
50
51
|
AppendMessage,
|
|
51
52
|
} from "./types/message";
|
|
52
53
|
|
|
53
|
-
export {
|
|
54
|
+
export {
|
|
55
|
+
MCP_APP_URI_SCHEME,
|
|
56
|
+
isMcpAppUri,
|
|
57
|
+
toolApprovalAcceptsText,
|
|
58
|
+
} from "./types/message";
|
|
54
59
|
|
|
55
60
|
export type {
|
|
56
61
|
Attachment,
|
|
@@ -256,6 +261,7 @@ export type {
|
|
|
256
261
|
ThreadListItemEventCallback,
|
|
257
262
|
ThreadListItemEventPayload,
|
|
258
263
|
ThreadListItemEventType,
|
|
264
|
+
ThreadListItemGenerateTitleOptions,
|
|
259
265
|
ThreadListItemRuntime,
|
|
260
266
|
} from "./runtime/api/thread-list-item-runtime";
|
|
261
267
|
|
package/src/internal.ts
CHANGED
|
@@ -67,6 +67,10 @@ export {
|
|
|
67
67
|
resolveFilePartSource,
|
|
68
68
|
} from "./utils/data-url";
|
|
69
69
|
export { invokeUserCallback } from "./utils/invoke-user-callback";
|
|
70
|
+
export {
|
|
71
|
+
abortableIterable,
|
|
72
|
+
openAbortableIterable,
|
|
73
|
+
} from "./utils/abortable-iterable";
|
|
70
74
|
export { detectImageMediaType } from "./utils/image-media-type";
|
|
71
75
|
export {
|
|
72
76
|
resolveFileMediaType,
|
|
@@ -77,6 +81,14 @@ export {
|
|
|
77
81
|
createToolCallCancellationStub,
|
|
78
82
|
scanPendingToolCalls,
|
|
79
83
|
} from "./runtime/utils/pending-tool-calls";
|
|
84
|
+
// Nested tool-call traversal, reused by framework adapters so the
|
|
85
|
+
// ToolCallMessagePart.messages tree is walked one way.
|
|
86
|
+
export {
|
|
87
|
+
iterateToolCallParts,
|
|
88
|
+
mapToolCallPartsDeep,
|
|
89
|
+
type ToolCallTreeEntry,
|
|
90
|
+
walkToolCallTree,
|
|
91
|
+
} from "./runtime/utils/tool-call-tree";
|
|
80
92
|
export {
|
|
81
93
|
createAbortableThreadLoad,
|
|
82
94
|
type AbortableThreadLoadPurpose,
|
|
@@ -133,6 +133,30 @@ describe("AssistantFrameHost", () => {
|
|
|
133
133
|
host.dispose();
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
+
it("cleans up tool calls when posting the request fails", async () => {
|
|
137
|
+
const { execute, host, postMessage } = createHost();
|
|
138
|
+
const error = new Error("postMessage failed");
|
|
139
|
+
const abortController = new AbortController();
|
|
140
|
+
const removeEventListener = vi.spyOn(
|
|
141
|
+
abortController.signal,
|
|
142
|
+
"removeEventListener",
|
|
143
|
+
);
|
|
144
|
+
postMessage.mockImplementation((data) => {
|
|
145
|
+
if (data.message.type === "tool-call") throw error;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
await expect(
|
|
149
|
+
execute({}, { ...executionContext, abortSignal: abortController.signal }),
|
|
150
|
+
).rejects.toBe(error);
|
|
151
|
+
|
|
152
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
153
|
+
expect(removeEventListener).toHaveBeenCalledWith(
|
|
154
|
+
"abort",
|
|
155
|
+
expect.any(Function),
|
|
156
|
+
);
|
|
157
|
+
host.dispose();
|
|
158
|
+
});
|
|
159
|
+
|
|
136
160
|
it("rejects tool results that carry an empty error message", async () => {
|
|
137
161
|
const { dispatchMessage, execute, getToolCallId, host } = createHost();
|
|
138
162
|
const result = Promise.resolve(
|
|
@@ -195,10 +195,16 @@ export class AssistantFrameHost implements ModelContextProvider {
|
|
|
195
195
|
}, timeout);
|
|
196
196
|
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
try {
|
|
199
|
+
this._iframeWindow.postMessage(
|
|
200
|
+
{ channel: FRAME_MESSAGE_CHANNEL, message },
|
|
201
|
+
this._targetOrigin,
|
|
202
|
+
);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
const pending = this._pendingRequests.get(message.id);
|
|
205
|
+
this._pendingRequests.delete(message.id);
|
|
206
|
+
pending?.reject(error);
|
|
207
|
+
}
|
|
202
208
|
});
|
|
203
209
|
}
|
|
204
210
|
|
|
@@ -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
|
},
|
|
@@ -119,6 +120,42 @@ describe("AssistantFrameProvider", () => {
|
|
|
119
120
|
await vi.waitFor(() => expect(execute).toHaveBeenCalledOnce());
|
|
120
121
|
});
|
|
121
122
|
|
|
123
|
+
it("does not broadcast from a disposed provider", async () => {
|
|
124
|
+
vi.useFakeTimers();
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
128
|
+
getModelContext: () => ({ system: "disposed context" }),
|
|
129
|
+
});
|
|
130
|
+
AssistantFrameProvider.dispose();
|
|
131
|
+
|
|
132
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
133
|
+
getModelContext: () => ({ system: "current context" }),
|
|
134
|
+
});
|
|
135
|
+
vi.mocked(parentWindow.postMessage).mockClear();
|
|
136
|
+
|
|
137
|
+
await vi.runAllTimersAsync();
|
|
138
|
+
|
|
139
|
+
expect(parentWindow.postMessage).toHaveBeenCalledOnce();
|
|
140
|
+
expect(parentWindow.postMessage).toHaveBeenCalledWith(
|
|
141
|
+
{
|
|
142
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
143
|
+
message: {
|
|
144
|
+
type: "model-context-update",
|
|
145
|
+
context: {
|
|
146
|
+
system: "current context",
|
|
147
|
+
tools: {},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
window.location.origin,
|
|
152
|
+
);
|
|
153
|
+
} finally {
|
|
154
|
+
AssistantFrameProvider.dispose();
|
|
155
|
+
vi.useRealTimers();
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
122
159
|
it("reports a failure even when the thrown error has an empty message", async () => {
|
|
123
160
|
const execute = vi.fn(async () => {
|
|
124
161
|
throw new Error();
|
|
@@ -145,6 +182,41 @@ describe("AssistantFrameProvider", () => {
|
|
|
145
182
|
});
|
|
146
183
|
});
|
|
147
184
|
|
|
185
|
+
it("reports tool results that cannot cross the frame boundary", async () => {
|
|
186
|
+
const consoleError = vi
|
|
187
|
+
.spyOn(console, "error")
|
|
188
|
+
.mockImplementation(() => undefined);
|
|
189
|
+
const execute = vi.fn(async () => () => undefined);
|
|
190
|
+
vi.mocked(parentWindow.postMessage).mockImplementation((data) => {
|
|
191
|
+
structuredClone(data);
|
|
192
|
+
});
|
|
193
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
194
|
+
getModelContext: () => ({
|
|
195
|
+
tools: { sensitiveTool: { execute } },
|
|
196
|
+
}),
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
dispatchToolCall(window.location.origin);
|
|
200
|
+
|
|
201
|
+
await vi.waitFor(() => {
|
|
202
|
+
expect(consoleError).toHaveBeenCalledWith(
|
|
203
|
+
"[assistant-ui] AssistantFrame tool result could not be sent.",
|
|
204
|
+
expect.objectContaining({ name: "DataCloneError" }),
|
|
205
|
+
);
|
|
206
|
+
expect(parentWindow.postMessage).toHaveBeenCalledWith(
|
|
207
|
+
{
|
|
208
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
209
|
+
message: {
|
|
210
|
+
type: "tool-result",
|
|
211
|
+
id: "tool-call-1",
|
|
212
|
+
error: "Tool result could not be sent across the frame boundary",
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
{ targetOrigin: window.location.origin },
|
|
216
|
+
);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
148
220
|
it("aborts in-flight tool calls when the parent cancels them", async () => {
|
|
149
221
|
let toolSignal: AbortSignal | undefined;
|
|
150
222
|
const execute = vi.fn(
|
|
@@ -284,6 +356,179 @@ describe("AssistantFrameProvider", () => {
|
|
|
284
356
|
expect(toolResults).toHaveLength(1);
|
|
285
357
|
});
|
|
286
358
|
|
|
359
|
+
it("aborts in-flight tool calls when their provider is removed", async () => {
|
|
360
|
+
let toolSignal: AbortSignal | undefined;
|
|
361
|
+
const execute = vi.fn(
|
|
362
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
363
|
+
toolSignal = context.abortSignal;
|
|
364
|
+
await new Promise<never>((_resolve, reject) => {
|
|
365
|
+
context.abortSignal.addEventListener(
|
|
366
|
+
"abort",
|
|
367
|
+
() => reject(context.abortSignal.reason),
|
|
368
|
+
{ once: true },
|
|
369
|
+
);
|
|
370
|
+
});
|
|
371
|
+
},
|
|
372
|
+
);
|
|
373
|
+
const removeProvider = AssistantFrameProvider.addModelContextProvider({
|
|
374
|
+
getModelContext: () => ({ tools: { sensitiveTool: { execute } } }),
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
dispatchToolCall(window.location.origin);
|
|
378
|
+
await vi.waitFor(() => expect(toolSignal).toBeDefined());
|
|
379
|
+
|
|
380
|
+
removeProvider();
|
|
381
|
+
|
|
382
|
+
expect(toolSignal?.aborted).toBe(true);
|
|
383
|
+
expect(parentWindow.postMessage).toHaveBeenCalledWith(
|
|
384
|
+
{
|
|
385
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
386
|
+
message: {
|
|
387
|
+
type: "tool-result",
|
|
388
|
+
id: "tool-call-1",
|
|
389
|
+
error: "AssistantFrame tool provider has been removed",
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
{ targetOrigin: window.location.origin },
|
|
393
|
+
);
|
|
394
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
395
|
+
const toolResults = vi
|
|
396
|
+
.mocked(parentWindow.postMessage)
|
|
397
|
+
.mock.calls.filter(
|
|
398
|
+
([data]) =>
|
|
399
|
+
(data as { message?: { type?: string } }).message?.type ===
|
|
400
|
+
"tool-result",
|
|
401
|
+
);
|
|
402
|
+
expect(toolResults).toHaveLength(1);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it("keeps tool calls active while the same provider remains registered", async () => {
|
|
406
|
+
let toolSignal: AbortSignal | undefined;
|
|
407
|
+
const execute = vi.fn(
|
|
408
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
409
|
+
toolSignal = context.abortSignal;
|
|
410
|
+
await new Promise<never>((_resolve, reject) => {
|
|
411
|
+
context.abortSignal.addEventListener(
|
|
412
|
+
"abort",
|
|
413
|
+
() => reject(context.abortSignal.reason),
|
|
414
|
+
{ once: true },
|
|
415
|
+
);
|
|
416
|
+
});
|
|
417
|
+
},
|
|
418
|
+
);
|
|
419
|
+
const provider = {
|
|
420
|
+
getModelContext: () => ({ tools: { sensitiveTool: { execute } } }),
|
|
421
|
+
};
|
|
422
|
+
const removeFirst =
|
|
423
|
+
AssistantFrameProvider.addModelContextProvider(provider);
|
|
424
|
+
const removeSecond =
|
|
425
|
+
AssistantFrameProvider.addModelContextProvider(provider);
|
|
426
|
+
|
|
427
|
+
dispatchToolCall(window.location.origin);
|
|
428
|
+
await vi.waitFor(() => expect(toolSignal).toBeDefined());
|
|
429
|
+
|
|
430
|
+
removeFirst();
|
|
431
|
+
expect(toolSignal?.aborted).toBe(false);
|
|
432
|
+
|
|
433
|
+
removeSecond();
|
|
434
|
+
expect(toolSignal?.aborted).toBe(true);
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
it("cancels only calls owned by the removed provider", async () => {
|
|
438
|
+
const shadowedExecute = vi.fn(async () => "shadowed");
|
|
439
|
+
const removeShadowed = AssistantFrameProvider.addModelContextProvider({
|
|
440
|
+
getModelContext: () => ({
|
|
441
|
+
tools: { sensitiveTool: { execute: shadowedExecute } },
|
|
442
|
+
}),
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
let toolSignal: AbortSignal | undefined;
|
|
446
|
+
const execute = vi.fn(
|
|
447
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
448
|
+
toolSignal = context.abortSignal;
|
|
449
|
+
await new Promise<never>((_resolve, reject) => {
|
|
450
|
+
context.abortSignal.addEventListener(
|
|
451
|
+
"abort",
|
|
452
|
+
() => reject(context.abortSignal.reason),
|
|
453
|
+
{ once: true },
|
|
454
|
+
);
|
|
455
|
+
});
|
|
456
|
+
},
|
|
457
|
+
);
|
|
458
|
+
const removeOwner = AssistantFrameProvider.addModelContextProvider({
|
|
459
|
+
getModelContext: () => ({
|
|
460
|
+
tools: { sensitiveTool: { execute } },
|
|
461
|
+
}),
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
dispatchToolCall(window.location.origin);
|
|
465
|
+
await vi.waitFor(() => expect(toolSignal).toBeDefined());
|
|
466
|
+
expect(shadowedExecute).not.toHaveBeenCalled();
|
|
467
|
+
|
|
468
|
+
removeShadowed();
|
|
469
|
+
expect(toolSignal?.aborted).toBe(false);
|
|
470
|
+
|
|
471
|
+
removeOwner();
|
|
472
|
+
expect(toolSignal?.aborted).toBe(true);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it("keeps other providers' tool calls active when one is removed", async () => {
|
|
476
|
+
const signals = new Map<string, AbortSignal>();
|
|
477
|
+
const execute = vi.fn(
|
|
478
|
+
async (
|
|
479
|
+
_args: unknown,
|
|
480
|
+
context: { toolCallId: string; abortSignal: AbortSignal },
|
|
481
|
+
) => {
|
|
482
|
+
signals.set(context.toolCallId, context.abortSignal);
|
|
483
|
+
await new Promise<never>((_resolve, reject) => {
|
|
484
|
+
context.abortSignal.addEventListener(
|
|
485
|
+
"abort",
|
|
486
|
+
() => reject(context.abortSignal.reason),
|
|
487
|
+
{ once: true },
|
|
488
|
+
);
|
|
489
|
+
});
|
|
490
|
+
},
|
|
491
|
+
);
|
|
492
|
+
const removeFirst = AssistantFrameProvider.addModelContextProvider({
|
|
493
|
+
getModelContext: () => ({ tools: { firstTool: { execute } } }),
|
|
494
|
+
});
|
|
495
|
+
const removeSecond = AssistantFrameProvider.addModelContextProvider({
|
|
496
|
+
getModelContext: () => ({ tools: { secondTool: { execute } } }),
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
dispatchToolCall(
|
|
500
|
+
window.location.origin,
|
|
501
|
+
parentWindow,
|
|
502
|
+
"first-call",
|
|
503
|
+
"firstTool",
|
|
504
|
+
);
|
|
505
|
+
dispatchToolCall(
|
|
506
|
+
window.location.origin,
|
|
507
|
+
parentWindow,
|
|
508
|
+
"second-call",
|
|
509
|
+
"secondTool",
|
|
510
|
+
);
|
|
511
|
+
await vi.waitFor(() => expect(signals.size).toBe(2));
|
|
512
|
+
|
|
513
|
+
removeFirst();
|
|
514
|
+
|
|
515
|
+
expect(signals.get("first-call")?.aborted).toBe(true);
|
|
516
|
+
expect(signals.get("second-call")?.aborted).toBe(false);
|
|
517
|
+
const toolResults = vi
|
|
518
|
+
.mocked(parentWindow.postMessage)
|
|
519
|
+
.mock.calls.filter(
|
|
520
|
+
([data]) =>
|
|
521
|
+
(data as { message?: { type?: string } }).message?.type ===
|
|
522
|
+
"tool-result",
|
|
523
|
+
);
|
|
524
|
+
expect(toolResults).toHaveLength(1);
|
|
525
|
+
expect(toolResults[0]?.[0]).toMatchObject({
|
|
526
|
+
message: { id: "first-call" },
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
removeSecond();
|
|
530
|
+
});
|
|
531
|
+
|
|
287
532
|
it("upgrades a wildcard origin policy when a strict provider registers", async () => {
|
|
288
533
|
AssistantFrameProvider.addModelContextProvider(
|
|
289
534
|
{ getModelContext: () => ({}) },
|
|
@@ -385,6 +630,48 @@ describe("AssistantFrameProvider", () => {
|
|
|
385
630
|
).not.toThrow();
|
|
386
631
|
});
|
|
387
632
|
|
|
633
|
+
it("cancels reentrant tool calls when registration rolls back", async () => {
|
|
634
|
+
let toolSignal: AbortSignal | undefined;
|
|
635
|
+
const execute = vi.fn(
|
|
636
|
+
async (_args: unknown, context: { abortSignal: AbortSignal }) => {
|
|
637
|
+
toolSignal = context.abortSignal;
|
|
638
|
+
await new Promise<never>((_resolve, reject) => {
|
|
639
|
+
context.abortSignal.addEventListener(
|
|
640
|
+
"abort",
|
|
641
|
+
() => reject(context.abortSignal.reason),
|
|
642
|
+
{ once: true },
|
|
643
|
+
);
|
|
644
|
+
});
|
|
645
|
+
},
|
|
646
|
+
);
|
|
647
|
+
|
|
648
|
+
expect(() =>
|
|
649
|
+
AssistantFrameProvider.addModelContextProvider({
|
|
650
|
+
getModelContext: () => ({
|
|
651
|
+
tools: { sensitiveTool: { execute } },
|
|
652
|
+
}),
|
|
653
|
+
subscribe: () => {
|
|
654
|
+
dispatchToolCall(window.location.origin);
|
|
655
|
+
throw new Error("subscribe failed");
|
|
656
|
+
},
|
|
657
|
+
}),
|
|
658
|
+
).toThrow("subscribe failed");
|
|
659
|
+
|
|
660
|
+
expect(toolSignal?.aborted).toBe(true);
|
|
661
|
+
expect(parentWindow.postMessage).toHaveBeenCalledWith(
|
|
662
|
+
{
|
|
663
|
+
channel: FRAME_MESSAGE_CHANNEL,
|
|
664
|
+
message: {
|
|
665
|
+
type: "tool-result",
|
|
666
|
+
id: "tool-call-1",
|
|
667
|
+
error: "AssistantFrame tool provider has been removed",
|
|
668
|
+
},
|
|
669
|
+
},
|
|
670
|
+
{ targetOrigin: window.location.origin },
|
|
671
|
+
);
|
|
672
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
673
|
+
});
|
|
674
|
+
|
|
388
675
|
it("keeps an existing registration when the same provider fails to register again", async () => {
|
|
389
676
|
const execute = vi.fn(async () => "result");
|
|
390
677
|
const firstUnsubscribe = vi.fn();
|