@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,383 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
createCore,
|
|
4
|
+
deferred,
|
|
5
|
+
makeAdapter,
|
|
6
|
+
setStartThreadRuntime,
|
|
7
|
+
} from "./remote-thread-list-test-helpers";
|
|
8
|
+
|
|
9
|
+
const thread = (remoteId: string) => ({
|
|
10
|
+
remoteId,
|
|
11
|
+
externalId: remoteId,
|
|
12
|
+
status: "regular" as const,
|
|
13
|
+
title: remoteId,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe("RemoteThreadList adapter changes", () => {
|
|
17
|
+
it("clears the selected thread and cached data from the previous adapter", async () => {
|
|
18
|
+
const adapterA = makeAdapter({
|
|
19
|
+
list: async () => ({ threads: [thread("thread-a")] }),
|
|
20
|
+
});
|
|
21
|
+
const listAdapterB = vi.fn(async () => ({
|
|
22
|
+
threads: [thread("thread-b")],
|
|
23
|
+
}));
|
|
24
|
+
const adapterB = makeAdapter({ list: listAdapterB });
|
|
25
|
+
const core = createCore(adapterA);
|
|
26
|
+
const started: string[] = [];
|
|
27
|
+
setStartThreadRuntime(core, async (id) => {
|
|
28
|
+
started.push(id);
|
|
29
|
+
return {};
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
await core.getLoadThreadsPromise();
|
|
33
|
+
await core.switchToThread("thread-a");
|
|
34
|
+
expect(core.getItemById(core.mainThreadId)?.remoteId).toBe("thread-a");
|
|
35
|
+
|
|
36
|
+
core.__internal_setOptions({
|
|
37
|
+
adapter: adapterB,
|
|
38
|
+
runtimeHook: () => ({}) as never,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await core.getLoadThreadsPromise();
|
|
42
|
+
expect(listAdapterB).toHaveBeenCalledTimes(1);
|
|
43
|
+
expect(core.threadIds).toEqual(["thread-b"]);
|
|
44
|
+
expect(core.getItemById("thread-a")).toBeUndefined();
|
|
45
|
+
expect(core.getItemById(core.mainThreadId)?.remoteId).not.toBe("thread-a");
|
|
46
|
+
expect(started).toContain(core.mainThreadId);
|
|
47
|
+
|
|
48
|
+
await expect(core.rename("thread-a", "leaked")).rejects.toThrow(
|
|
49
|
+
'Thread "thread-a" not found',
|
|
50
|
+
);
|
|
51
|
+
expect(adapterB.rename).not.toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("does not resume an old adapter mutation through the new adapter", async () => {
|
|
55
|
+
const adapterA = makeAdapter({
|
|
56
|
+
list: async () => ({ threads: [thread("thread-a")] }),
|
|
57
|
+
});
|
|
58
|
+
const adapterB = makeAdapter();
|
|
59
|
+
const core = createCore(adapterA);
|
|
60
|
+
|
|
61
|
+
await core.getLoadThreadsPromise();
|
|
62
|
+
await core.switchToThread("thread-a");
|
|
63
|
+
|
|
64
|
+
const runtimeStart = deferred<unknown>();
|
|
65
|
+
setStartThreadRuntime(core, () => runtimeStart.promise);
|
|
66
|
+
const archiveTask = core.archive("thread-a");
|
|
67
|
+
|
|
68
|
+
core.__internal_setOptions({
|
|
69
|
+
adapter: adapterB,
|
|
70
|
+
runtimeHook: () => ({}) as never,
|
|
71
|
+
});
|
|
72
|
+
runtimeStart.resolve({});
|
|
73
|
+
|
|
74
|
+
await expect(archiveTask).rejects.toThrow("adapter changed");
|
|
75
|
+
expect(adapterA.archive).not.toHaveBeenCalled();
|
|
76
|
+
expect(adapterB.archive).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("preserves an adapter failure that races an adapter change", async () => {
|
|
80
|
+
const unarchiveRequest = deferred<void>();
|
|
81
|
+
const adapterA = makeAdapter({
|
|
82
|
+
list: async () => ({
|
|
83
|
+
threads: [{ ...thread("thread-a"), status: "archived" as const }],
|
|
84
|
+
}),
|
|
85
|
+
unarchive: vi.fn(() => unarchiveRequest.promise),
|
|
86
|
+
});
|
|
87
|
+
const adapterB = makeAdapter();
|
|
88
|
+
const core = createCore(adapterA);
|
|
89
|
+
|
|
90
|
+
await core.getLoadThreadsPromise();
|
|
91
|
+
const unarchiveTask = core.unarchive("thread-a");
|
|
92
|
+
await vi.waitFor(() => expect(adapterA.unarchive).toHaveBeenCalledOnce());
|
|
93
|
+
|
|
94
|
+
core.__internal_setOptions({
|
|
95
|
+
adapter: adapterB,
|
|
96
|
+
runtimeHook: () => ({}) as never,
|
|
97
|
+
});
|
|
98
|
+
const failure = new Error("network error");
|
|
99
|
+
unarchiveRequest.reject(failure);
|
|
100
|
+
|
|
101
|
+
await expect(unarchiveTask).rejects.toBe(failure);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("does not apply a late initialize to the replacement adapter state", async () => {
|
|
105
|
+
const initializeRequest = deferred<{
|
|
106
|
+
remoteId: string;
|
|
107
|
+
externalId: string;
|
|
108
|
+
}>();
|
|
109
|
+
const adapterA = makeAdapter({
|
|
110
|
+
list: async () => ({ threads: [] }),
|
|
111
|
+
initialize: vi.fn(() => initializeRequest.promise),
|
|
112
|
+
});
|
|
113
|
+
const adapterB = makeAdapter();
|
|
114
|
+
const core = createCore(adapterA);
|
|
115
|
+
|
|
116
|
+
await core.getLoadThreadsPromise();
|
|
117
|
+
const localId = core.newThreadId;
|
|
118
|
+
expect(localId).toBeDefined();
|
|
119
|
+
const initializeTask = core.initialize(localId!);
|
|
120
|
+
|
|
121
|
+
core.__internal_setOptions({
|
|
122
|
+
adapter: adapterB,
|
|
123
|
+
runtimeHook: () => ({}) as never,
|
|
124
|
+
});
|
|
125
|
+
initializeRequest.resolve({
|
|
126
|
+
remoteId: "leaked",
|
|
127
|
+
externalId: "leaked",
|
|
128
|
+
});
|
|
129
|
+
await expect(initializeTask).rejects.toThrow("adapter changed");
|
|
130
|
+
expect(core.getItemById("leaked")).toBeUndefined();
|
|
131
|
+
expect(core.threadIds).not.toContain("leaked");
|
|
132
|
+
|
|
133
|
+
await core.getLoadThreadsPromise();
|
|
134
|
+
expect(core.getItemById(core.mainThreadId)?.status).toBe("new");
|
|
135
|
+
expect(core.getItemById(core.mainThreadId)?.remoteId).toBeUndefined();
|
|
136
|
+
await expect(core.initialize(core.mainThreadId)).resolves.toEqual({
|
|
137
|
+
remoteId: core.mainThreadId,
|
|
138
|
+
externalId: core.mainThreadId,
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("selects a controlled thread that arrives on the replacement page", async () => {
|
|
143
|
+
const adapterA = makeAdapter({
|
|
144
|
+
list: async () => ({ threads: [thread("thread-a")] }),
|
|
145
|
+
});
|
|
146
|
+
const adapterB = makeAdapter({
|
|
147
|
+
list: async () => ({ threads: [thread("thread-b")] }),
|
|
148
|
+
});
|
|
149
|
+
const core = createCore(adapterA, "thread-a");
|
|
150
|
+
|
|
151
|
+
await core.getLoadThreadsPromise();
|
|
152
|
+
core.__internal_load();
|
|
153
|
+
await core.switchToThread("thread-a");
|
|
154
|
+
|
|
155
|
+
core.__internal_setOptions({
|
|
156
|
+
adapter: adapterB,
|
|
157
|
+
runtimeHook: () => ({}) as never,
|
|
158
|
+
threadId: "thread-b",
|
|
159
|
+
});
|
|
160
|
+
await core.getLoadThreadsPromise();
|
|
161
|
+
|
|
162
|
+
expect(core.getItemById(core.mainThreadId)?.remoteId).toBe("thread-b");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("keeps the unsent draft runtime across an empty-list adapter swap", async () => {
|
|
166
|
+
const adapterA = makeAdapter();
|
|
167
|
+
const adapterB = makeAdapter();
|
|
168
|
+
const core = createCore(adapterA);
|
|
169
|
+
const stopped: string[] = [];
|
|
170
|
+
const hookManager = (
|
|
171
|
+
core as unknown as {
|
|
172
|
+
_hookManager: { stopThreadRuntime: (id: string) => void };
|
|
173
|
+
}
|
|
174
|
+
)._hookManager;
|
|
175
|
+
const originalStop = hookManager.stopThreadRuntime.bind(hookManager);
|
|
176
|
+
hookManager.stopThreadRuntime = (id: string) => {
|
|
177
|
+
stopped.push(id);
|
|
178
|
+
originalStop(id);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
await core.getLoadThreadsPromise();
|
|
182
|
+
const draftId = core.mainThreadId;
|
|
183
|
+
expect(core.getItemById(draftId)?.status).toBe("new");
|
|
184
|
+
|
|
185
|
+
core.__internal_setOptions({
|
|
186
|
+
adapter: adapterB,
|
|
187
|
+
runtimeHook: () => ({}) as never,
|
|
188
|
+
});
|
|
189
|
+
await core.getLoadThreadsPromise();
|
|
190
|
+
|
|
191
|
+
expect(core.mainThreadId).toBe(draftId);
|
|
192
|
+
expect(core.getItemById(draftId)?.status).toBe("new");
|
|
193
|
+
expect(stopped).not.toContain(draftId);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("stops runtimes for threads missing from the replacement list", async () => {
|
|
197
|
+
const adapterA = makeAdapter({
|
|
198
|
+
list: async () => ({ threads: [thread("thread-a")] }),
|
|
199
|
+
});
|
|
200
|
+
const adapterB = makeAdapter({
|
|
201
|
+
list: async () => ({ threads: [thread("thread-b")] }),
|
|
202
|
+
});
|
|
203
|
+
const core = createCore(adapterA);
|
|
204
|
+
const stopped: string[] = [];
|
|
205
|
+
const hookManager = (
|
|
206
|
+
core as unknown as {
|
|
207
|
+
_hookManager: { stopThreadRuntime: (id: string) => void };
|
|
208
|
+
}
|
|
209
|
+
)._hookManager;
|
|
210
|
+
const originalStop = hookManager.stopThreadRuntime.bind(hookManager);
|
|
211
|
+
hookManager.stopThreadRuntime = (id: string) => {
|
|
212
|
+
stopped.push(id);
|
|
213
|
+
originalStop(id);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
await core.getLoadThreadsPromise();
|
|
217
|
+
await core.switchToThread("thread-a");
|
|
218
|
+
|
|
219
|
+
core.__internal_setOptions({
|
|
220
|
+
adapter: adapterB,
|
|
221
|
+
runtimeHook: () => ({}) as never,
|
|
222
|
+
});
|
|
223
|
+
await core.getLoadThreadsPromise();
|
|
224
|
+
|
|
225
|
+
expect(core.getItemById("thread-a")).toBeUndefined();
|
|
226
|
+
expect(stopped).toContain("thread-a");
|
|
227
|
+
expect(stopped).not.toContain(core.mainThreadId);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("does not reject when a controlled thread is missing from the replacement adapter", async () => {
|
|
231
|
+
const adapterA = makeAdapter({
|
|
232
|
+
list: async () => ({ threads: [thread("thread-a")] }),
|
|
233
|
+
});
|
|
234
|
+
const adapterB = makeAdapter({
|
|
235
|
+
list: async () => ({ threads: [thread("thread-b")] }),
|
|
236
|
+
fetch: vi.fn(async () => {
|
|
237
|
+
throw new Error("not found");
|
|
238
|
+
}),
|
|
239
|
+
});
|
|
240
|
+
const core = createCore(adapterA, "thread-a");
|
|
241
|
+
|
|
242
|
+
await core.getLoadThreadsPromise();
|
|
243
|
+
await core.switchToThread("thread-a");
|
|
244
|
+
|
|
245
|
+
core.__internal_setOptions({
|
|
246
|
+
adapter: adapterB,
|
|
247
|
+
runtimeHook: () => ({}) as never,
|
|
248
|
+
threadId: "thread-a",
|
|
249
|
+
});
|
|
250
|
+
await expect(core.getLoadThreadsPromise()).resolves.toBeUndefined();
|
|
251
|
+
await vi.waitFor(() => {
|
|
252
|
+
expect(adapterB.fetch).toHaveBeenCalledWith("thread-a");
|
|
253
|
+
});
|
|
254
|
+
expect(core.getItemById("thread-a")).toBeUndefined();
|
|
255
|
+
expect(core.getItemById(core.mainThreadId)?.status).toBe("new");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("reuses the preserved unsent draft when the selected thread is missing after swap", async () => {
|
|
259
|
+
const adapterA = makeAdapter({
|
|
260
|
+
list: async () => ({ threads: [thread("thread-a")] }),
|
|
261
|
+
});
|
|
262
|
+
const adapterB = makeAdapter({
|
|
263
|
+
list: async () => ({ threads: [thread("thread-b")] }),
|
|
264
|
+
});
|
|
265
|
+
const core = createCore(adapterA);
|
|
266
|
+
|
|
267
|
+
await core.getLoadThreadsPromise();
|
|
268
|
+
const draftId = core.newThreadId;
|
|
269
|
+
expect(draftId).toBeDefined();
|
|
270
|
+
await core.switchToThread("thread-a");
|
|
271
|
+
expect(core.mainThreadId).toBe("thread-a");
|
|
272
|
+
expect(core.newThreadId).toBe(draftId);
|
|
273
|
+
|
|
274
|
+
core.__internal_setOptions({
|
|
275
|
+
adapter: adapterB,
|
|
276
|
+
runtimeHook: () => ({}) as never,
|
|
277
|
+
});
|
|
278
|
+
await core.getLoadThreadsPromise();
|
|
279
|
+
|
|
280
|
+
expect(core.mainThreadId).toBe(draftId);
|
|
281
|
+
expect(core.newThreadId).toBe(draftId);
|
|
282
|
+
expect(core.getItemById(draftId!)?.status).toBe("new");
|
|
283
|
+
expect(
|
|
284
|
+
Object.values(core.threadItems).filter((item) => item.status === "new"),
|
|
285
|
+
).toHaveLength(1);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("does not send a rename through the replacement adapter while its list is pending", async () => {
|
|
289
|
+
const adapterA = makeAdapter({
|
|
290
|
+
list: async () => ({ threads: [thread("thread-a")] }),
|
|
291
|
+
});
|
|
292
|
+
const listB = deferred<{ threads: ReturnType<typeof thread>[] }>();
|
|
293
|
+
const adapterB = makeAdapter({
|
|
294
|
+
list: vi.fn(() => listB.promise),
|
|
295
|
+
});
|
|
296
|
+
const core = createCore(adapterA);
|
|
297
|
+
|
|
298
|
+
await core.getLoadThreadsPromise();
|
|
299
|
+
await core.switchToThread("thread-a");
|
|
300
|
+
|
|
301
|
+
core.__internal_setOptions({
|
|
302
|
+
adapter: adapterB,
|
|
303
|
+
runtimeHook: () => ({}) as never,
|
|
304
|
+
});
|
|
305
|
+
await expect(core.rename("thread-a", "leaked")).rejects.toThrow(
|
|
306
|
+
"adapter changed",
|
|
307
|
+
);
|
|
308
|
+
await expect(core.switchToThread("thread-a")).rejects.toThrow(
|
|
309
|
+
"adapter changed",
|
|
310
|
+
);
|
|
311
|
+
expect(adapterB.rename).not.toHaveBeenCalled();
|
|
312
|
+
|
|
313
|
+
listB.resolve({ threads: [thread("thread-b")] });
|
|
314
|
+
await core.getLoadThreadsPromise();
|
|
315
|
+
expect(adapterB.rename).not.toHaveBeenCalled();
|
|
316
|
+
expect(core.getItemById("thread-a")).toBeUndefined();
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("does not freeze mutations when the replacement list fails", async () => {
|
|
320
|
+
const adapterA = makeAdapter({
|
|
321
|
+
list: async () => ({ threads: [thread("thread-a")] }),
|
|
322
|
+
});
|
|
323
|
+
const adapterB = makeAdapter({
|
|
324
|
+
list: vi.fn(async () => {
|
|
325
|
+
throw new Error("network");
|
|
326
|
+
}),
|
|
327
|
+
});
|
|
328
|
+
const core = createCore(adapterA);
|
|
329
|
+
const consoleError = vi
|
|
330
|
+
.spyOn(console, "error")
|
|
331
|
+
.mockImplementation(() => {});
|
|
332
|
+
|
|
333
|
+
await core.getLoadThreadsPromise();
|
|
334
|
+
await core.switchToThread("thread-a");
|
|
335
|
+
|
|
336
|
+
core.__internal_setOptions({
|
|
337
|
+
adapter: adapterB,
|
|
338
|
+
runtimeHook: () => ({}) as never,
|
|
339
|
+
});
|
|
340
|
+
await core.getLoadThreadsPromise();
|
|
341
|
+
|
|
342
|
+
expect(core.getItemById("thread-a")).toBeUndefined();
|
|
343
|
+
expect(core.getItemById(core.mainThreadId)?.status).toBe("new");
|
|
344
|
+
await expect(core.switchToNewThread()).resolves.toBeUndefined();
|
|
345
|
+
expect(consoleError).toHaveBeenCalled();
|
|
346
|
+
consoleError.mockRestore();
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("keeps a thread initialized while the replacement list is pending", async () => {
|
|
350
|
+
const adapterA = makeAdapter({
|
|
351
|
+
list: async () => ({ threads: [thread("thread-a")] }),
|
|
352
|
+
});
|
|
353
|
+
const listB = deferred<{ threads: ReturnType<typeof thread>[] }>();
|
|
354
|
+
const adapterB = makeAdapter({
|
|
355
|
+
list: vi.fn(() => listB.promise),
|
|
356
|
+
initialize: vi.fn(async () => ({
|
|
357
|
+
remoteId: "created-on-b",
|
|
358
|
+
externalId: "created-on-b",
|
|
359
|
+
})),
|
|
360
|
+
});
|
|
361
|
+
const core = createCore(adapterA);
|
|
362
|
+
|
|
363
|
+
await core.getLoadThreadsPromise();
|
|
364
|
+
const draftId = core.newThreadId;
|
|
365
|
+
expect(draftId).toBeDefined();
|
|
366
|
+
|
|
367
|
+
core.__internal_setOptions({
|
|
368
|
+
adapter: adapterB,
|
|
369
|
+
runtimeHook: () => ({}) as never,
|
|
370
|
+
});
|
|
371
|
+
await expect(core.initialize(draftId!)).resolves.toEqual({
|
|
372
|
+
remoteId: "created-on-b",
|
|
373
|
+
externalId: "created-on-b",
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
listB.resolve({ threads: [thread("thread-b")] });
|
|
377
|
+
await core.getLoadThreadsPromise();
|
|
378
|
+
|
|
379
|
+
expect(core.getItemById(draftId!)?.remoteId).toBe("created-on-b");
|
|
380
|
+
expect(core.mainThreadId).toBe(draftId);
|
|
381
|
+
expect(core.threadIds).toContain("created-on-b");
|
|
382
|
+
});
|
|
383
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { ExternalStoreRuntimeCore } from "../runtimes/external-store/external-store-runtime-core";
|
|
3
|
+
import { LocalRuntimeCore } from "../runtimes/local/local-runtime-core";
|
|
4
|
+
import type { ChatModelAdapter } from "../runtime/utils/chat-model-adapter";
|
|
5
|
+
import type { ThreadMessage } from "../types/message";
|
|
6
|
+
|
|
7
|
+
async function waitFor(
|
|
8
|
+
predicate: () => unknown,
|
|
9
|
+
timeoutMs = 500,
|
|
10
|
+
): Promise<void> {
|
|
11
|
+
const start = Date.now();
|
|
12
|
+
while (Date.now() - start < timeoutMs) {
|
|
13
|
+
try {
|
|
14
|
+
await predicate();
|
|
15
|
+
return;
|
|
16
|
+
} catch {
|
|
17
|
+
// retry
|
|
18
|
+
}
|
|
19
|
+
await new Promise((r) => setTimeout(r, 5));
|
|
20
|
+
}
|
|
21
|
+
await predicate();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const trailingUserMessage = {
|
|
25
|
+
id: "u1",
|
|
26
|
+
role: "user",
|
|
27
|
+
createdAt: new Date(),
|
|
28
|
+
content: [{ type: "text", text: "draft in flight" }],
|
|
29
|
+
attachments: [],
|
|
30
|
+
metadata: { custom: {} },
|
|
31
|
+
} as ThreadMessage;
|
|
32
|
+
|
|
33
|
+
const toolCallMessage = {
|
|
34
|
+
id: "a1",
|
|
35
|
+
role: "assistant",
|
|
36
|
+
createdAt: new Date(),
|
|
37
|
+
status: { type: "requires-action", reason: "tool-calls" },
|
|
38
|
+
metadata: {
|
|
39
|
+
unstable_state: null,
|
|
40
|
+
unstable_annotations: [],
|
|
41
|
+
unstable_data: [],
|
|
42
|
+
steps: [],
|
|
43
|
+
custom: {},
|
|
44
|
+
},
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
type: "tool-call",
|
|
48
|
+
toolCallId: "tool-1",
|
|
49
|
+
toolName: "send_email",
|
|
50
|
+
args: { to: "dev@example.com" },
|
|
51
|
+
argsText: '{"to":"dev@example.com"}',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
} as unknown as ThreadMessage;
|
|
55
|
+
|
|
56
|
+
const externalThread = () => {
|
|
57
|
+
const setToolStatuses = vi.fn();
|
|
58
|
+
const setMessages = vi.fn();
|
|
59
|
+
const onCancel = vi.fn();
|
|
60
|
+
const notifyCancelled = vi.fn();
|
|
61
|
+
const store = {
|
|
62
|
+
messages: [trailingUserMessage] as ThreadMessage[],
|
|
63
|
+
onNew: vi.fn(async () => {}),
|
|
64
|
+
onCancel,
|
|
65
|
+
setMessages,
|
|
66
|
+
unstable_enableToolInvocations: true,
|
|
67
|
+
setToolStatuses,
|
|
68
|
+
queue: {
|
|
69
|
+
__internal_notifyCancelled: notifyCancelled,
|
|
70
|
+
} as never,
|
|
71
|
+
};
|
|
72
|
+
const core = new ExternalStoreRuntimeCore(store);
|
|
73
|
+
core.registerModelContextProvider({
|
|
74
|
+
getModelContext: () => ({
|
|
75
|
+
tools: {
|
|
76
|
+
send_email: {
|
|
77
|
+
parameters: { type: "object", properties: {} },
|
|
78
|
+
execute: vi.fn(() => new Promise(() => {})),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
core,
|
|
85
|
+
store,
|
|
86
|
+
thread: core.threads.getMainThreadRuntimeCore(),
|
|
87
|
+
setToolStatuses,
|
|
88
|
+
setMessages,
|
|
89
|
+
onCancel,
|
|
90
|
+
notifyCancelled,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const driveExecutingTool = async (
|
|
95
|
+
harness: ReturnType<typeof externalThread>,
|
|
96
|
+
) => {
|
|
97
|
+
harness.core.setAdapter({
|
|
98
|
+
...harness.store,
|
|
99
|
+
messages: [trailingUserMessage, toolCallMessage],
|
|
100
|
+
});
|
|
101
|
+
await waitFor(() => {
|
|
102
|
+
const statuses = harness.setToolStatuses.mock.lastCall?.[0] as
|
|
103
|
+
| Record<string, { type: string }>
|
|
104
|
+
| undefined;
|
|
105
|
+
expect(statuses?.["tool-1"]?.type).toBe("executing");
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
describe("unstable_notifySessionReset", () => {
|
|
110
|
+
it("clears session-scoped tool state once and parks queued work", async () => {
|
|
111
|
+
const harness = externalThread();
|
|
112
|
+
await driveExecutingTool(harness);
|
|
113
|
+
|
|
114
|
+
harness.setToolStatuses.mockClear();
|
|
115
|
+
harness.thread.unstable_notifySessionReset();
|
|
116
|
+
|
|
117
|
+
expect(harness.setToolStatuses).toHaveBeenCalledTimes(1);
|
|
118
|
+
expect(harness.setToolStatuses).toHaveBeenLastCalledWith({});
|
|
119
|
+
expect(harness.notifyCancelled).toHaveBeenCalledTimes(1);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("carries no run-cancel semantics", async () => {
|
|
123
|
+
const harness = externalThread();
|
|
124
|
+
await driveExecutingTool(harness);
|
|
125
|
+
|
|
126
|
+
harness.thread.unstable_notifySessionReset();
|
|
127
|
+
|
|
128
|
+
expect(harness.onCancel).not.toHaveBeenCalled();
|
|
129
|
+
expect(harness.setMessages).not.toHaveBeenCalled();
|
|
130
|
+
expect(harness.thread.messages.at(-1)?.id).toBe("a1");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("throws on runtimes without a backing session", () => {
|
|
134
|
+
const local = new LocalRuntimeCore(
|
|
135
|
+
{
|
|
136
|
+
adapters: { chatModel: { async *run() {} } satisfies ChatModelAdapter },
|
|
137
|
+
},
|
|
138
|
+
undefined,
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
expect(() =>
|
|
142
|
+
local.threads.getMainThreadRuntimeCore().unstable_notifySessionReset(),
|
|
143
|
+
).toThrow("Runtime does not support resetting sessions.");
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
|
|
3
|
-
import { act, render } from "@testing-library/react";
|
|
3
|
+
import { act, render, waitFor } from "@testing-library/react";
|
|
4
4
|
import { describe, expect, it, vi } from "vitest";
|
|
5
5
|
import { AuiProvider, useAui, useAuiEvent } from "@assistant-ui/store";
|
|
6
|
+
import { AssistantRuntimeProvider } from "../react/AssistantRuntimeProvider";
|
|
7
|
+
import { useExternalStoreRuntime } from "../react/runtimes/useExternalStoreRuntime";
|
|
8
|
+
import { useRemoteThreadListRuntime } from "../react/runtimes/useRemoteThreadListRuntime";
|
|
9
|
+
import { makeAdapter } from "./remote-thread-list-test-helpers";
|
|
6
10
|
import { RuntimeAdapter } from "../react/RuntimeAdapter";
|
|
7
11
|
import { AssistantRuntimeImpl } from "../runtime/api/assistant-runtime";
|
|
8
12
|
import { ExternalStoreRuntimeCore } from "../runtimes/external-store/external-store-runtime-core";
|
|
@@ -10,6 +14,15 @@ import type { ExternalStoreAdapter } from "../runtimes/external-store/external-s
|
|
|
10
14
|
|
|
11
15
|
type DemoMessage = { id: string; role: "user" | "assistant"; text: string };
|
|
12
16
|
|
|
17
|
+
const EMPTY_MESSAGES: readonly never[] = [];
|
|
18
|
+
|
|
19
|
+
const useTestThreadRuntime = () =>
|
|
20
|
+
useExternalStoreRuntime({
|
|
21
|
+
messages: EMPTY_MESSAGES,
|
|
22
|
+
isRunning: false,
|
|
23
|
+
onNew: async () => {},
|
|
24
|
+
});
|
|
25
|
+
|
|
13
26
|
const createRuntime = () => {
|
|
14
27
|
const threads = [
|
|
15
28
|
{
|
|
@@ -110,6 +123,57 @@ describe("thread switch events", () => {
|
|
|
110
123
|
expect(switchedAwayStar).toHaveBeenLastCalledWith({ threadId: "t2" });
|
|
111
124
|
});
|
|
112
125
|
|
|
126
|
+
it("delivers threads.selectionChanged with the new and previous thread ids", async () => {
|
|
127
|
+
const runtime = createRuntime();
|
|
128
|
+
const selectionChanged = vi.fn();
|
|
129
|
+
const auiOn = vi.fn();
|
|
130
|
+
let aui!: ReturnType<typeof useAui>;
|
|
131
|
+
const Consumer = () => {
|
|
132
|
+
useAuiEvent(
|
|
133
|
+
"threads.selectionChanged" as never,
|
|
134
|
+
selectionChanged as never,
|
|
135
|
+
);
|
|
136
|
+
return null;
|
|
137
|
+
};
|
|
138
|
+
const Harness = () => {
|
|
139
|
+
aui = useAui({ threads: RuntimeAdapter(runtime) } as never);
|
|
140
|
+
return (
|
|
141
|
+
<AuiProvider value={aui}>
|
|
142
|
+
<Consumer />
|
|
143
|
+
</AuiProvider>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
render(<Harness />);
|
|
147
|
+
await act(async () => {});
|
|
148
|
+
|
|
149
|
+
aui.on("threads.selectionChanged" as never, auiOn as never);
|
|
150
|
+
|
|
151
|
+
await act(async () => {
|
|
152
|
+
aui.threads.item({ index: 1 }).switchTo();
|
|
153
|
+
});
|
|
154
|
+
await act(async () => {});
|
|
155
|
+
|
|
156
|
+
expect(selectionChanged).toHaveBeenCalledExactlyOnceWith({
|
|
157
|
+
threadId: "t2",
|
|
158
|
+
previousThreadId: "t1",
|
|
159
|
+
});
|
|
160
|
+
expect(auiOn).toHaveBeenCalledExactlyOnceWith({
|
|
161
|
+
threadId: "t2",
|
|
162
|
+
previousThreadId: "t1",
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
await act(async () => {
|
|
166
|
+
aui.threads.item({ index: 0 }).switchTo();
|
|
167
|
+
});
|
|
168
|
+
await act(async () => {});
|
|
169
|
+
|
|
170
|
+
expect(selectionChanged).toHaveBeenCalledTimes(2);
|
|
171
|
+
expect(selectionChanged).toHaveBeenLastCalledWith({
|
|
172
|
+
threadId: "t1",
|
|
173
|
+
previousThreadId: "t2",
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
113
177
|
it("does not emit for the initially selected thread on mount", async () => {
|
|
114
178
|
const runtime = createRuntime();
|
|
115
179
|
const anySwitch = vi.fn();
|
|
@@ -118,6 +182,10 @@ describe("thread switch events", () => {
|
|
|
118
182
|
{ scope: "*", event: "threadListItem.switchedTo" } as never,
|
|
119
183
|
anySwitch as never,
|
|
120
184
|
);
|
|
185
|
+
useAuiEvent(
|
|
186
|
+
{ scope: "*", event: "threads.selectionChanged" } as never,
|
|
187
|
+
anySwitch as never,
|
|
188
|
+
);
|
|
121
189
|
return null;
|
|
122
190
|
};
|
|
123
191
|
const Harness = () => {
|
|
@@ -133,4 +201,34 @@ describe("thread switch events", () => {
|
|
|
133
201
|
|
|
134
202
|
expect(anySwitch).not.toHaveBeenCalled();
|
|
135
203
|
});
|
|
204
|
+
|
|
205
|
+
it("emits when a deep-linked initial thread resolves after mount", async () => {
|
|
206
|
+
const adapter = makeAdapter();
|
|
207
|
+
const selectionChanged = vi.fn();
|
|
208
|
+
const Listener = () => {
|
|
209
|
+
useAuiEvent("threads.selectionChanged", selectionChanged);
|
|
210
|
+
return null;
|
|
211
|
+
};
|
|
212
|
+
const Harness = () => {
|
|
213
|
+
const runtime = useRemoteThreadListRuntime({
|
|
214
|
+
adapter,
|
|
215
|
+
initialThreadId: "thread-a",
|
|
216
|
+
runtimeHook: useTestThreadRuntime,
|
|
217
|
+
});
|
|
218
|
+
return (
|
|
219
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
220
|
+
<Listener />
|
|
221
|
+
</AssistantRuntimeProvider>
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
render(<Harness />);
|
|
225
|
+
|
|
226
|
+
await waitFor(() => expect(selectionChanged).toHaveBeenCalledTimes(1));
|
|
227
|
+
const payload = selectionChanged.mock.calls[0]![0] as {
|
|
228
|
+
threadId: string;
|
|
229
|
+
previousThreadId: string;
|
|
230
|
+
};
|
|
231
|
+
expect(payload.threadId).toBe("thread-a");
|
|
232
|
+
expect(payload.previousThreadId).toMatch(/^__LOCALID_/);
|
|
233
|
+
});
|
|
136
234
|
});
|