@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
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { act, render, waitFor } from "@testing-library/react";
|
|
4
|
+
import type { FC } from "react";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { useAui } from "@assistant-ui/store";
|
|
7
|
+
import { ToolResponse } from "assistant-stream";
|
|
8
|
+
import { AssistantRuntimeProvider } from "../../AssistantRuntimeProvider";
|
|
9
|
+
import {
|
|
10
|
+
useAssistantTransportRuntime,
|
|
11
|
+
useAssistantTransportSendCommand,
|
|
12
|
+
} from "./useAssistantTransportRuntime";
|
|
13
|
+
import type {
|
|
14
|
+
AssistantTransportCommand,
|
|
15
|
+
AssistantTransportOptions,
|
|
16
|
+
AssistantTransportStateConverter,
|
|
17
|
+
} from "./types";
|
|
18
|
+
|
|
19
|
+
const converter: AssistantTransportStateConverter<unknown> = (
|
|
20
|
+
_state,
|
|
21
|
+
meta,
|
|
22
|
+
) => ({
|
|
23
|
+
messages: [],
|
|
24
|
+
isRunning: meta.isSending,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const createMessageCommand = (text: string): AssistantTransportCommand => ({
|
|
28
|
+
type: "add-message",
|
|
29
|
+
message: {
|
|
30
|
+
role: "user",
|
|
31
|
+
parts: [{ type: "text", text }],
|
|
32
|
+
},
|
|
33
|
+
parentId: null,
|
|
34
|
+
sourceId: null,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const createStreamResponse = () => {
|
|
38
|
+
let controller!: ReadableStreamDefaultController<Uint8Array>;
|
|
39
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
40
|
+
start(c) {
|
|
41
|
+
controller = c;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
response: new Response(stream, { status: 200 }),
|
|
46
|
+
close: () => controller.close(),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type StreamResponse = ReturnType<typeof createStreamResponse>;
|
|
51
|
+
|
|
52
|
+
type RecordedRequest = {
|
|
53
|
+
url: string;
|
|
54
|
+
init: RequestInit;
|
|
55
|
+
body: Record<string, any>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const installFetch = () => {
|
|
59
|
+
const requests: RecordedRequest[] = [];
|
|
60
|
+
const servers: StreamResponse[] = [];
|
|
61
|
+
|
|
62
|
+
vi.stubGlobal(
|
|
63
|
+
"fetch",
|
|
64
|
+
async (url: RequestInfo | URL, init: RequestInit = {}) => {
|
|
65
|
+
requests.push({
|
|
66
|
+
url: String(url),
|
|
67
|
+
init,
|
|
68
|
+
body: JSON.parse(init.body as string),
|
|
69
|
+
});
|
|
70
|
+
const server = createStreamResponse();
|
|
71
|
+
servers.push(server);
|
|
72
|
+
return server.response;
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return { requests, servers };
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const installPendingFetch = () => {
|
|
80
|
+
const requests: RecordedRequest[] = [];
|
|
81
|
+
const pending: {
|
|
82
|
+
resolve: (response: Response) => void;
|
|
83
|
+
reject: (reason: unknown) => void;
|
|
84
|
+
}[] = [];
|
|
85
|
+
|
|
86
|
+
vi.stubGlobal("fetch", (url: RequestInfo | URL, init: RequestInit = {}) => {
|
|
87
|
+
requests.push({
|
|
88
|
+
url: String(url),
|
|
89
|
+
init,
|
|
90
|
+
body: JSON.parse(init.body as string),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return new Promise<Response>((resolve, reject) => {
|
|
94
|
+
pending.push({ resolve, reject });
|
|
95
|
+
init.signal?.addEventListener(
|
|
96
|
+
"abort",
|
|
97
|
+
() => reject(init.signal?.reason),
|
|
98
|
+
{
|
|
99
|
+
once: true,
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return { requests, pending };
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const mountRuntime = (
|
|
109
|
+
options?: Partial<AssistantTransportOptions<unknown>>,
|
|
110
|
+
) => {
|
|
111
|
+
const captured: {
|
|
112
|
+
aui?: ReturnType<typeof useAui>;
|
|
113
|
+
sendCommand?: (command: AssistantTransportCommand) => void;
|
|
114
|
+
} = {};
|
|
115
|
+
const Capture: FC = () => {
|
|
116
|
+
captured.aui = useAui();
|
|
117
|
+
captured.sendCommand = useAssistantTransportSendCommand();
|
|
118
|
+
return null;
|
|
119
|
+
};
|
|
120
|
+
const App: FC = () => {
|
|
121
|
+
const runtime = useAssistantTransportRuntime({
|
|
122
|
+
initialState: {},
|
|
123
|
+
api: "https://example.com/api",
|
|
124
|
+
headers: {},
|
|
125
|
+
converter,
|
|
126
|
+
...options,
|
|
127
|
+
});
|
|
128
|
+
return (
|
|
129
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
130
|
+
<Capture />
|
|
131
|
+
</AssistantRuntimeProvider>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
const utils = render(<App />);
|
|
135
|
+
return {
|
|
136
|
+
aui: () => captured.aui!,
|
|
137
|
+
sendCommand: (command: AssistantTransportCommand) =>
|
|
138
|
+
captured.sendCommand!(command),
|
|
139
|
+
...utils,
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
afterEach(() => {
|
|
144
|
+
vi.unstubAllGlobals();
|
|
145
|
+
vi.restoreAllMocks();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("useAssistantTransportRuntime", () => {
|
|
149
|
+
it.each([false, 0, "", null])(
|
|
150
|
+
"preserves the falsy tool artifact %j",
|
|
151
|
+
async (artifact) => {
|
|
152
|
+
const fetchMock = installFetch();
|
|
153
|
+
const { aui } = mountRuntime({
|
|
154
|
+
converter: (_state, meta) => ({
|
|
155
|
+
messages: [
|
|
156
|
+
{
|
|
157
|
+
id: "a1",
|
|
158
|
+
role: "assistant",
|
|
159
|
+
content: [
|
|
160
|
+
{
|
|
161
|
+
type: "tool-call",
|
|
162
|
+
toolCallId: "tc1",
|
|
163
|
+
toolName: "probe",
|
|
164
|
+
args: {},
|
|
165
|
+
argsText: "{}",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
createdAt: new Date(0),
|
|
169
|
+
status: { type: "requires-action", reason: "tool-calls" },
|
|
170
|
+
metadata: { custom: {} },
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
isRunning: meta.isSending,
|
|
174
|
+
}),
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
await waitFor(() =>
|
|
178
|
+
expect(
|
|
179
|
+
aui()
|
|
180
|
+
.thread.message({ id: "a1" })
|
|
181
|
+
.part({ toolCallId: "tc1" })
|
|
182
|
+
.getState().type,
|
|
183
|
+
).toBe("tool-call"),
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
act(() => {
|
|
187
|
+
aui()
|
|
188
|
+
.thread.message({ id: "a1" })
|
|
189
|
+
.part({ toolCallId: "tc1" })
|
|
190
|
+
.addToolResult(new ToolResponse({ result: "ok", artifact }));
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(1));
|
|
194
|
+
expect(fetchMock.requests[0]!.body["commands"][0]).toHaveProperty(
|
|
195
|
+
"artifact",
|
|
196
|
+
artifact,
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
act(() => fetchMock.servers[0]!.close());
|
|
200
|
+
await waitFor(() =>
|
|
201
|
+
expect(aui().thread.getState().isRunning).toBe(false),
|
|
202
|
+
);
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
it.each(["throws", "rejects"] as const)(
|
|
207
|
+
"cancels the response body when onResponse %s",
|
|
208
|
+
async (failureMode) => {
|
|
209
|
+
const callbackError = new Error("response callback failed");
|
|
210
|
+
const cancel = vi.fn().mockRejectedValue(new Error("cancel failed"));
|
|
211
|
+
const onError = vi.fn();
|
|
212
|
+
vi.stubGlobal(
|
|
213
|
+
"fetch",
|
|
214
|
+
vi.fn().mockResolvedValue(
|
|
215
|
+
new Response(
|
|
216
|
+
new ReadableStream({
|
|
217
|
+
cancel,
|
|
218
|
+
}),
|
|
219
|
+
),
|
|
220
|
+
),
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const { aui, sendCommand } = mountRuntime({
|
|
224
|
+
onResponse: () => {
|
|
225
|
+
if (failureMode === "throws") throw callbackError;
|
|
226
|
+
return Promise.reject(callbackError);
|
|
227
|
+
},
|
|
228
|
+
onError,
|
|
229
|
+
});
|
|
230
|
+
await waitFor(() =>
|
|
231
|
+
expect(
|
|
232
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
233
|
+
?.sendCommand,
|
|
234
|
+
).toBeTypeOf("function"),
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
act(() => sendCommand(createMessageCommand("hello")));
|
|
238
|
+
|
|
239
|
+
await waitFor(() =>
|
|
240
|
+
expect(onError).toHaveBeenCalledWith(callbackError, expect.anything()),
|
|
241
|
+
);
|
|
242
|
+
expect(cancel).toHaveBeenCalledOnce();
|
|
243
|
+
},
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
it("no-ops a follow-up run that finds an empty queue", async () => {
|
|
247
|
+
const fetchMock = installFetch();
|
|
248
|
+
const onError = vi.fn();
|
|
249
|
+
const { aui, sendCommand } = mountRuntime({ onError });
|
|
250
|
+
await waitFor(() =>
|
|
251
|
+
expect(
|
|
252
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
253
|
+
?.sendCommand,
|
|
254
|
+
).toBeTypeOf("function"),
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
// Two synchronous sends coalesce into one request plus one follow-up run.
|
|
258
|
+
act(() => {
|
|
259
|
+
sendCommand(createMessageCommand("a"));
|
|
260
|
+
sendCommand(createMessageCommand("b"));
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(1));
|
|
264
|
+
expect(
|
|
265
|
+
fetchMock.requests[0]!.body["commands"].map((c: any) => c.type),
|
|
266
|
+
).toEqual(["add-message", "add-message"]);
|
|
267
|
+
expect(fetchMock.requests[0]!.body["state"]).toEqual({});
|
|
268
|
+
|
|
269
|
+
act(() => fetchMock.servers[0]!.close());
|
|
270
|
+
|
|
271
|
+
await waitFor(() => expect(aui().thread.getState().isRunning).toBe(false));
|
|
272
|
+
await act(async () => {});
|
|
273
|
+
expect(onError).not.toHaveBeenCalled();
|
|
274
|
+
expect(fetchMock.requests).toHaveLength(1);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("skips add-message commands with no supported parts", async () => {
|
|
278
|
+
const fetchMock = installFetch();
|
|
279
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
280
|
+
const { aui, sendCommand } = mountRuntime();
|
|
281
|
+
await waitFor(() =>
|
|
282
|
+
expect(
|
|
283
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
284
|
+
?.sendCommand,
|
|
285
|
+
).toBeTypeOf("function"),
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
act(() =>
|
|
289
|
+
aui().thread.append({
|
|
290
|
+
role: "user",
|
|
291
|
+
content: [{ type: "audio", audio: { data: "", format: "mp3" } }],
|
|
292
|
+
}),
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
await act(async () => {});
|
|
296
|
+
expect(warn).toHaveBeenCalledWith(
|
|
297
|
+
"[assistant-ui] Skipped add-message command with no supported parts",
|
|
298
|
+
);
|
|
299
|
+
expect(fetchMock.requests).toHaveLength(0);
|
|
300
|
+
|
|
301
|
+
// The skipped message must not leak its parentId into later batches.
|
|
302
|
+
act(() => sendCommand(createMessageCommand("follow-up")));
|
|
303
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(1));
|
|
304
|
+
expect(fetchMock.requests[0]!.body).not.toHaveProperty("parentId");
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("flushes commands enqueued during a resume run in a follow-up run", async () => {
|
|
308
|
+
const fetchMock = installFetch();
|
|
309
|
+
const { aui, sendCommand } = mountRuntime({
|
|
310
|
+
resumeApi: "https://example.com/resume",
|
|
311
|
+
});
|
|
312
|
+
await waitFor(() =>
|
|
313
|
+
expect(
|
|
314
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
315
|
+
?.sendCommand,
|
|
316
|
+
).toBeTypeOf("function"),
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
act(() => sendCommand(createMessageCommand("a")));
|
|
320
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(1));
|
|
321
|
+
|
|
322
|
+
// Both land while the first run is active and coalesce into one follow-up.
|
|
323
|
+
act(() => {
|
|
324
|
+
sendCommand(createMessageCommand("b"));
|
|
325
|
+
aui().thread.resumeRun({ parentId: null });
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
act(() => fetchMock.servers[0]!.close());
|
|
329
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(2));
|
|
330
|
+
expect(fetchMock.requests[1]!.url).toBe("https://example.com/resume");
|
|
331
|
+
expect(fetchMock.requests[1]!.body["commands"]).toEqual([]);
|
|
332
|
+
expect(fetchMock.requests[1]!.body).toHaveProperty("state");
|
|
333
|
+
|
|
334
|
+
// "b" coalesced into the resume run and must not starve in the queue.
|
|
335
|
+
act(() => fetchMock.servers[1]!.close());
|
|
336
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(3));
|
|
337
|
+
expect(fetchMock.requests[2]!.url).toBe("https://example.com/api");
|
|
338
|
+
expect(fetchMock.requests[2]!.body["commands"]).toEqual([
|
|
339
|
+
createMessageCommand("b"),
|
|
340
|
+
]);
|
|
341
|
+
|
|
342
|
+
act(() => fetchMock.servers[2]!.close());
|
|
343
|
+
await waitFor(() => expect(aui().thread.getState().isRunning).toBe(false));
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it.each(["error", "cancellation"] as const)(
|
|
347
|
+
"does not apply a dropped resume after run %s",
|
|
348
|
+
async (settlement) => {
|
|
349
|
+
const fetchMock = installPendingFetch();
|
|
350
|
+
const onError = vi.fn();
|
|
351
|
+
const { aui, sendCommand } = mountRuntime({
|
|
352
|
+
resumeApi: "https://example.com/resume",
|
|
353
|
+
onError,
|
|
354
|
+
});
|
|
355
|
+
await waitFor(() =>
|
|
356
|
+
expect(
|
|
357
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
358
|
+
?.sendCommand,
|
|
359
|
+
).toBeTypeOf("function"),
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
act(() => sendCommand(createMessageCommand("a")));
|
|
363
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(1));
|
|
364
|
+
|
|
365
|
+
await act(async () => {
|
|
366
|
+
await aui().thread.resumeRun({ parentId: null });
|
|
367
|
+
});
|
|
368
|
+
if (settlement === "cancellation") {
|
|
369
|
+
act(() => aui().thread.cancelRun());
|
|
370
|
+
} else {
|
|
371
|
+
await act(async () => {
|
|
372
|
+
fetchMock.pending[0]!.reject(new Error("request failed"));
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
await waitFor(() =>
|
|
376
|
+
expect(aui().thread.getState().isRunning).toBe(false),
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
act(() => sendCommand(createMessageCommand("b")));
|
|
380
|
+
await waitFor(() => expect(fetchMock.requests).toHaveLength(2));
|
|
381
|
+
expect(fetchMock.requests[1]!.url).toBe("https://example.com/api");
|
|
382
|
+
expect(fetchMock.requests[1]!.body["commands"]).toEqual([
|
|
383
|
+
createMessageCommand("b"),
|
|
384
|
+
]);
|
|
385
|
+
|
|
386
|
+
await act(async () => {
|
|
387
|
+
fetchMock.pending[1]!.resolve(new Response("", { status: 200 }));
|
|
388
|
+
});
|
|
389
|
+
await waitFor(() =>
|
|
390
|
+
expect(aui().thread.getState().isRunning).toBe(false),
|
|
391
|
+
);
|
|
392
|
+
expect(onError).toHaveBeenCalledTimes(settlement === "error" ? 1 : 0);
|
|
393
|
+
},
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
it("applies resumed operations to the retained initial state", async () => {
|
|
397
|
+
const requests: RecordedRequest[] = [];
|
|
398
|
+
vi.stubGlobal(
|
|
399
|
+
"fetch",
|
|
400
|
+
async (url: RequestInfo | URL, init: RequestInit = {}) => {
|
|
401
|
+
requests.push({
|
|
402
|
+
url: String(url),
|
|
403
|
+
init,
|
|
404
|
+
body: JSON.parse(init.body as string),
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
if (String(url) === "https://example.com/resume-state") {
|
|
408
|
+
return Response.json({
|
|
409
|
+
runId: "run-1",
|
|
410
|
+
state: { message: "Hello" },
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return new Response(
|
|
415
|
+
'aui-state:[{"type":"append-text","path":["message"],"value":" world"}]\n',
|
|
416
|
+
{ status: 200 },
|
|
417
|
+
);
|
|
418
|
+
},
|
|
419
|
+
);
|
|
420
|
+
const { aui } = mountRuntime({
|
|
421
|
+
resumeApi: "https://example.com/resume",
|
|
422
|
+
resumeStateApi: "https://example.com/resume-state",
|
|
423
|
+
});
|
|
424
|
+
await waitFor(() =>
|
|
425
|
+
expect(
|
|
426
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
427
|
+
?.sendCommand,
|
|
428
|
+
).toBeTypeOf("function"),
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
act(() => {
|
|
432
|
+
aui().thread.importExternalState({ message: "Wrong" });
|
|
433
|
+
});
|
|
434
|
+
await act(async () => {
|
|
435
|
+
await aui().thread.resumeRun({ parentId: null });
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
await waitFor(() =>
|
|
439
|
+
expect(
|
|
440
|
+
(aui().thread.getState().extras as { state: unknown }).state,
|
|
441
|
+
).toEqual({ message: "Hello world" }),
|
|
442
|
+
);
|
|
443
|
+
expect(requests.map((request) => request.url)).toEqual([
|
|
444
|
+
"https://example.com/resume-state",
|
|
445
|
+
"https://example.com/resume",
|
|
446
|
+
]);
|
|
447
|
+
expect(requests[1]!.body).toMatchObject({ runId: "run-1" });
|
|
448
|
+
expect(requests[1]!.body).not.toHaveProperty("state");
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("rejects malformed resume state responses before replay", async () => {
|
|
452
|
+
const fetchMock = vi.fn(async () => Response.json({ state: {} }));
|
|
453
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
454
|
+
const onError = vi.fn();
|
|
455
|
+
const { aui } = mountRuntime({
|
|
456
|
+
resumeApi: "https://example.com/resume",
|
|
457
|
+
resumeStateApi: "https://example.com/resume-state",
|
|
458
|
+
onError,
|
|
459
|
+
});
|
|
460
|
+
await waitFor(() =>
|
|
461
|
+
expect(
|
|
462
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
463
|
+
?.sendCommand,
|
|
464
|
+
).toBeTypeOf("function"),
|
|
465
|
+
);
|
|
466
|
+
|
|
467
|
+
await act(async () => {
|
|
468
|
+
await aui().thread.resumeRun({ parentId: null });
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
await waitFor(() =>
|
|
472
|
+
expect(onError).toHaveBeenCalledWith(
|
|
473
|
+
expect.objectContaining({
|
|
474
|
+
message: "Resume state response must contain state and runId",
|
|
475
|
+
}),
|
|
476
|
+
expect.anything(),
|
|
477
|
+
),
|
|
478
|
+
);
|
|
479
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it("commits a retained null state locally and omits state from the resume request", async () => {
|
|
483
|
+
const requests: RecordedRequest[] = [];
|
|
484
|
+
vi.stubGlobal(
|
|
485
|
+
"fetch",
|
|
486
|
+
async (url: RequestInfo | URL, init: RequestInit = {}) => {
|
|
487
|
+
requests.push({
|
|
488
|
+
url: String(url),
|
|
489
|
+
init,
|
|
490
|
+
body: JSON.parse(init.body as string),
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
if (String(url) === "https://example.com/resume-state") {
|
|
494
|
+
return Response.json({ runId: "run-1", state: null });
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
return new Response("", { status: 200 });
|
|
498
|
+
},
|
|
499
|
+
);
|
|
500
|
+
const { aui } = mountRuntime({
|
|
501
|
+
resumeApi: "https://example.com/resume",
|
|
502
|
+
resumeStateApi: "https://example.com/resume-state",
|
|
503
|
+
});
|
|
504
|
+
await waitFor(() =>
|
|
505
|
+
expect(
|
|
506
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
507
|
+
?.sendCommand,
|
|
508
|
+
).toBeTypeOf("function"),
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
act(() => {
|
|
512
|
+
aui().thread.importExternalState({ message: "Wrong" });
|
|
513
|
+
});
|
|
514
|
+
await act(async () => {
|
|
515
|
+
await aui().thread.resumeRun({ parentId: null });
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
expect(requests[1]!.body).toMatchObject({ runId: "run-1" });
|
|
519
|
+
expect(requests[1]!.body).not.toHaveProperty("state");
|
|
520
|
+
await waitFor(() =>
|
|
521
|
+
expect(
|
|
522
|
+
(aui().thread.getState().extras as { state: unknown }).state,
|
|
523
|
+
).toBeNull(),
|
|
524
|
+
);
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
it("skips the resume without error when the state endpoint reports no active run", async () => {
|
|
528
|
+
const fetchMock = vi.fn(async () => new Response(null, { status: 204 }));
|
|
529
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
530
|
+
const onError = vi.fn();
|
|
531
|
+
const { aui } = mountRuntime({
|
|
532
|
+
resumeApi: "https://example.com/resume",
|
|
533
|
+
resumeStateApi: "https://example.com/resume-state",
|
|
534
|
+
onError,
|
|
535
|
+
});
|
|
536
|
+
await waitFor(() =>
|
|
537
|
+
expect(
|
|
538
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
539
|
+
?.sendCommand,
|
|
540
|
+
).toBeTypeOf("function"),
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
act(() => {
|
|
544
|
+
aui().thread.importExternalState({ message: "Kept" });
|
|
545
|
+
});
|
|
546
|
+
await act(async () => {
|
|
547
|
+
await aui().thread.resumeRun({ parentId: null });
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
await waitFor(() => expect(aui().thread.getState().isRunning).toBe(false));
|
|
551
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
552
|
+
expect(onError).not.toHaveBeenCalled();
|
|
553
|
+
expect(
|
|
554
|
+
(aui().thread.getState().extras as { state: unknown }).state,
|
|
555
|
+
).toEqual({ message: "Kept" });
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it("keeps the retained runId over body overrides in the resume request", async () => {
|
|
559
|
+
const requests: RecordedRequest[] = [];
|
|
560
|
+
vi.stubGlobal(
|
|
561
|
+
"fetch",
|
|
562
|
+
async (url: RequestInfo | URL, init: RequestInit = {}) => {
|
|
563
|
+
requests.push({
|
|
564
|
+
url: String(url),
|
|
565
|
+
init,
|
|
566
|
+
body: JSON.parse(init.body as string),
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
if (String(url) === "https://example.com/resume-state") {
|
|
570
|
+
return Response.json({
|
|
571
|
+
runId: "run-1",
|
|
572
|
+
state: { message: "Hello" },
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
return new Response("", { status: 200 });
|
|
577
|
+
},
|
|
578
|
+
);
|
|
579
|
+
const { aui } = mountRuntime({
|
|
580
|
+
resumeApi: "https://example.com/resume",
|
|
581
|
+
resumeStateApi: "https://example.com/resume-state",
|
|
582
|
+
body: { state: { message: "Injected" }, runId: "bogus" },
|
|
583
|
+
});
|
|
584
|
+
await waitFor(() =>
|
|
585
|
+
expect(
|
|
586
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
587
|
+
?.sendCommand,
|
|
588
|
+
).toBeTypeOf("function"),
|
|
589
|
+
);
|
|
590
|
+
|
|
591
|
+
await act(async () => {
|
|
592
|
+
await aui().thread.resumeRun({ parentId: null });
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
expect(requests[1]!.body["runId"]).toBe("run-1");
|
|
596
|
+
expect(requests[1]!.body).not.toHaveProperty("state");
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
it("re-attaches runId and strips substituted state when prepareSendCommandsRequest rebuilds the body", async () => {
|
|
600
|
+
const requests: RecordedRequest[] = [];
|
|
601
|
+
vi.stubGlobal(
|
|
602
|
+
"fetch",
|
|
603
|
+
async (url: RequestInfo | URL, init: RequestInit = {}) => {
|
|
604
|
+
requests.push({
|
|
605
|
+
url: String(url),
|
|
606
|
+
init,
|
|
607
|
+
body: JSON.parse(init.body as string),
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
if (String(url) === "https://example.com/resume-state") {
|
|
611
|
+
return Response.json({
|
|
612
|
+
runId: "run-1",
|
|
613
|
+
state: { message: "Hello" },
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
return new Response("", { status: 200 });
|
|
618
|
+
},
|
|
619
|
+
);
|
|
620
|
+
const { aui } = mountRuntime({
|
|
621
|
+
resumeApi: "https://example.com/resume",
|
|
622
|
+
resumeStateApi: "https://example.com/resume-state",
|
|
623
|
+
prepareSendCommandsRequest: (body) => ({
|
|
624
|
+
commands: body.commands,
|
|
625
|
+
state: { message: "Substituted" },
|
|
626
|
+
rebuilt: true,
|
|
627
|
+
}),
|
|
628
|
+
});
|
|
629
|
+
await waitFor(() =>
|
|
630
|
+
expect(
|
|
631
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
632
|
+
?.sendCommand,
|
|
633
|
+
).toBeTypeOf("function"),
|
|
634
|
+
);
|
|
635
|
+
|
|
636
|
+
await act(async () => {
|
|
637
|
+
await aui().thread.resumeRun({ parentId: null });
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
expect(requests[1]!.body).toMatchObject({ runId: "run-1", rebuilt: true });
|
|
641
|
+
expect(requests[1]!.body).not.toHaveProperty("state");
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
it("keeps local state when the matching resume stream is rejected", async () => {
|
|
645
|
+
const fetchMock = vi
|
|
646
|
+
.fn()
|
|
647
|
+
.mockResolvedValueOnce(
|
|
648
|
+
Response.json({ runId: "run-1", state: { message: "Hello" } }),
|
|
649
|
+
)
|
|
650
|
+
.mockResolvedValueOnce(new Response("run mismatch", { status: 409 }));
|
|
651
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
652
|
+
const onError = vi.fn();
|
|
653
|
+
const { aui } = mountRuntime({
|
|
654
|
+
resumeApi: "https://example.com/resume",
|
|
655
|
+
resumeStateApi: "https://example.com/resume-state",
|
|
656
|
+
onError,
|
|
657
|
+
});
|
|
658
|
+
await waitFor(() =>
|
|
659
|
+
expect(
|
|
660
|
+
(aui().thread.getState().extras as { sendCommand?: unknown })
|
|
661
|
+
?.sendCommand,
|
|
662
|
+
).toBeTypeOf("function"),
|
|
663
|
+
);
|
|
664
|
+
|
|
665
|
+
act(() => {
|
|
666
|
+
aui().thread.importExternalState({ message: "Wrong" });
|
|
667
|
+
});
|
|
668
|
+
await act(async () => {
|
|
669
|
+
await aui().thread.resumeRun({ parentId: null });
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
await waitFor(() =>
|
|
673
|
+
expect(onError).toHaveBeenCalledWith(
|
|
674
|
+
expect.objectContaining({ message: "Status 409: run mismatch" }),
|
|
675
|
+
expect.anything(),
|
|
676
|
+
),
|
|
677
|
+
);
|
|
678
|
+
expect(
|
|
679
|
+
(aui().thread.getState().extras as { state: unknown }).state,
|
|
680
|
+
).toEqual({ message: "Wrong" });
|
|
681
|
+
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
682
|
+
});
|
|
683
|
+
});
|