@assistant-ui/core 0.3.12 → 0.3.14
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 +27 -15
- package/dist/adapters/voice.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +6 -6
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +2 -1
- package/dist/model-context/frame/host.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 +826 -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/client/interactable-model-context.d.ts.map +1 -1
- package/dist/react/client/interactable-model-context.js +5 -1
- package/dist/react/client/interactable-model-context.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 +13 -18
- 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/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 +22 -10
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +109 -71
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +8 -2
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +40 -13
- 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 +134 -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 +22 -12
- 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 +13 -3
- package/dist/runtime/api/thread-runtime.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +25 -0
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +72 -18
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +15 -0
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +34 -3
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.js +1 -6
- package/dist/runtime/base/default-edit-composer-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 +11 -8
- 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/external-thread-queue-adapter.d.ts +15 -0
- package/dist/runtime/queue/external-thread-queue-adapter.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.js +25 -11
- package/dist/runtime/queue/message-queue.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-adapter.d.ts +7 -0
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- 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 +11 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +78 -20
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- 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 +55 -14
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +1 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +3 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js +3 -0
- package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +29 -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.d.ts +7 -0
- package/dist/store/clients/external-thread.d.ts.map +1 -1
- package/dist/store/clients/external-thread.js +460 -369
- package/dist/store/clients/external-thread.js.map +1 -1
- package/dist/store/clients/runtime-adapter.d.ts.map +1 -1
- package/dist/store/clients/runtime-adapter.js +5 -2
- package/dist/store/clients/runtime-adapter.js.map +1 -1
- package/dist/store/clients/single-thread-list.d.ts.map +1 -1
- package/dist/store/clients/single-thread-list.js +31 -27
- package/dist/store/clients/single-thread-list.js.map +1 -1
- package/dist/store/clients/suggestions.d.ts +3 -1
- package/dist/store/clients/suggestions.d.ts.map +1 -1
- package/dist/store/clients/suggestions.js +65 -37
- 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 +6 -4
- package/dist/store/index.js +5 -3
- 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 +12 -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 +104 -57
- 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/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +98 -82
- package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
- package/dist/store/scope-registration.d.ts +2 -2
- package/dist/store/scopes/composer.d.ts +9 -4
- package/dist/store/scopes/composer.d.ts.map +1 -1
- package/dist/store/scopes/suggestions.d.ts +6 -1
- package/dist/store/scopes/suggestions.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 +25 -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/error.d.ts +15 -1
- package/dist/types/error.d.ts.map +1 -1
- package/dist/types/error.js +18 -1
- package/dist/types/error.js.map +1 -1
- package/dist/types/message.d.ts +2 -0
- package/dist/types/message.d.ts.map +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/package.json +7 -7
- 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 +69 -0
- package/src/adapters/voice.ts +27 -27
- package/src/index.ts +2 -0
- package/src/model-context/frame/host.test.ts +23 -0
- package/src/model-context/frame/host.ts +2 -1
- 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 +1026 -0
- package/src/react/client/RemoteThreadList.ts +1067 -0
- package/src/react/client/Tools.ts +36 -29
- package/src/react/client/interactable-model-context.ts +6 -1
- 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.ts +2 -7
- 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/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 +159 -124
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +59 -20
- package/src/react/runtimes/RemoteThreadResource.test.ts +141 -0
- package/src/react/runtimes/RemoteThreadResource.ts +231 -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 +625 -0
- package/src/react/runtimes/assistant-transport/useAssistantTransportRuntime.ts +481 -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.tsx +36 -21
- 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 +124 -0
- package/src/react/runtimes/useExternalStoreRuntime.ts +7 -0
- package/src/react/runtimes/useExternalStoreSharedOptions.ts +3 -1
- package/src/react/runtimes/useLocalRuntime.test.tsx +130 -4
- 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 +28 -3
- package/src/runtime/base/base-composer-runtime-core.ts +106 -13
- package/src/runtime/base/base-thread-runtime-core.test.ts +191 -0
- package/src/runtime/base/base-thread-runtime-core.ts +47 -2
- package/src/runtime/base/default-edit-composer-runtime-core.ts +1 -15
- package/src/runtime/base/default-thread-composer-runtime-core.ts +13 -15
- package/src/runtime/interfaces/thread-runtime-core.ts +6 -0
- package/src/runtime/queue/external-thread-queue-adapter.ts +17 -0
- package/src/runtime/queue/message-queue.ts +28 -10
- package/src/runtime/utils/thread-runtime-lifecycle.ts +18 -0
- package/src/runtimes/external-store/external-store-adapter.ts +7 -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 +187 -48
- package/src/runtimes/local/local-thread-runtime-core.test.ts +373 -4
- package/src/runtimes/local/local-thread-runtime-core.ts +83 -15
- package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +4 -0
- package/src/runtimes/remote-thread-list/empty-thread-core.ts +4 -0
- package/src/runtimes/remote-thread-list/types.ts +30 -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 +119 -16
- package/src/store/clients/model-context-client.test.ts +16 -8
- package/src/store/clients/runtime-adapter.ts +5 -2
- package/src/store/clients/single-thread-list.ts +2 -1
- package/src/store/clients/suggestions.ts +39 -13
- 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.ts +11 -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 +28 -35
- package/src/store/runtime-clients/thread-list-runtime-client.ts +9 -6
- package/src/store/runtime-clients/thread-runtime-client.ts +5 -0
- package/src/store/scopes/composer.ts +9 -4
- package/src/store/scopes/suggestions.ts +6 -0
- package/src/store/scopes/thread-list-item.ts +7 -6
- package/src/store/scopes/thread.ts +25 -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/RemoteThreadListThreadListRuntimeCore-switchToThread-unarchive.test.ts +25 -0
- package/src/tests/append-interactable-snapshots.test.ts +350 -0
- package/src/tests/auiV0Encode.test.ts +66 -0
- package/src/tests/base-composer-runtime-core-send.test.ts +156 -0
- package/src/tests/base-composer-runtime-core.test.ts +136 -1
- package/src/tests/composer-can-cancel.test.ts +101 -0
- package/src/tests/default-edit-composer-runtime-core.test.ts +0 -68
- package/src/tests/external-store-thread-list-runtime-core.test.ts +101 -0
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +491 -1
- package/src/tests/external-store-thread-runtime-core.test.ts +124 -0
- package/src/tests/external-thread-attachments.test.tsx +214 -0
- package/src/tests/external-thread-parity.test.tsx +54 -0
- package/src/tests/external-thread-refetch.test.tsx +117 -0
- package/src/tests/external-thread-suggestions.test.tsx +59 -0
- package/src/tests/interactables-toolui-migration.test.tsx +66 -0
- package/src/tests/message-queue.test.ts +54 -0
- package/src/tests/session-reset-notification.test.ts +145 -0
- package/src/tests/thread-message-like.test.ts +39 -0
- package/src/tests/thread-switch-events.test.tsx +234 -0
- package/src/tests/tools-scope-migration.test.tsx +58 -0
- package/src/types/error.ts +24 -0
- package/src/types/message.ts +2 -0
- 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/tests/default-thread-composer-runtime-core.test.ts +0 -82
|
@@ -9,6 +9,10 @@ import type {
|
|
|
9
9
|
ExternalThreadProps,
|
|
10
10
|
} from "../store/clients/external-thread";
|
|
11
11
|
import { ExternalThread } from "../store/clients/external-thread";
|
|
12
|
+
import type {
|
|
13
|
+
CompleteAttachment,
|
|
14
|
+
PendingAttachment,
|
|
15
|
+
} from "../types/attachment";
|
|
12
16
|
|
|
13
17
|
const renderThreadWithProps = (props: Partial<ExternalThreadProps>) => {
|
|
14
18
|
const captured: { aui?: ReturnType<typeof useAui> } = {};
|
|
@@ -215,6 +219,59 @@ describe("ExternalThread attachments", () => {
|
|
|
215
219
|
);
|
|
216
220
|
});
|
|
217
221
|
|
|
222
|
+
it("preserves composer state while attachments are prepared for send", async () => {
|
|
223
|
+
let resolveSend!: (attachment: CompleteAttachment) => void;
|
|
224
|
+
const onNew = vi.fn();
|
|
225
|
+
const file = new File(["data"], "notes.txt", { type: "text/plain" });
|
|
226
|
+
const adapter = {
|
|
227
|
+
accept: "*",
|
|
228
|
+
add: async () => ({
|
|
229
|
+
id: "att-1",
|
|
230
|
+
type: "file" as const,
|
|
231
|
+
name: file.name,
|
|
232
|
+
contentType: file.type,
|
|
233
|
+
file,
|
|
234
|
+
status: {
|
|
235
|
+
type: "requires-action" as const,
|
|
236
|
+
reason: "composer-send" as const,
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
send: () =>
|
|
240
|
+
new Promise<CompleteAttachment>((resolve) => {
|
|
241
|
+
resolveSend = resolve;
|
|
242
|
+
}),
|
|
243
|
+
remove: async () => {},
|
|
244
|
+
};
|
|
245
|
+
const aui = renderThreadWithProps({ attachmentAdapter: adapter, onNew });
|
|
246
|
+
const composer = () => aui().thread.composer();
|
|
247
|
+
|
|
248
|
+
await act(() => composer().addAttachment(file));
|
|
249
|
+
act(() => {
|
|
250
|
+
composer().setText("first message");
|
|
251
|
+
composer().setRole("assistant");
|
|
252
|
+
composer().setRunConfig({ model: "model-a" });
|
|
253
|
+
composer().send();
|
|
254
|
+
composer().setRole("system");
|
|
255
|
+
composer().setRunConfig({ model: "model-b" });
|
|
256
|
+
});
|
|
257
|
+
await act(async () => {
|
|
258
|
+
resolveSend({
|
|
259
|
+
id: "att-1",
|
|
260
|
+
type: "file",
|
|
261
|
+
name: file.name,
|
|
262
|
+
contentType: file.type,
|
|
263
|
+
status: { type: "complete" },
|
|
264
|
+
content: [],
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
await waitFor(() => expect(onNew).toHaveBeenCalledTimes(1));
|
|
269
|
+
expect(onNew.mock.calls[0]![0]).toMatchObject({
|
|
270
|
+
role: "assistant",
|
|
271
|
+
runConfig: { model: "model-a" },
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
218
275
|
it.each([
|
|
219
276
|
[
|
|
220
277
|
"clearAttachments",
|
|
@@ -263,6 +320,163 @@ describe("ExternalThread attachments", () => {
|
|
|
263
320
|
},
|
|
264
321
|
);
|
|
265
322
|
|
|
323
|
+
it.each([
|
|
324
|
+
[
|
|
325
|
+
"clearAttachments",
|
|
326
|
+
(c: { clearAttachments(): Promise<void> }) => c.clearAttachments(),
|
|
327
|
+
],
|
|
328
|
+
["reset", (c: { reset(): Promise<void> }) => c.reset()],
|
|
329
|
+
] as const)(
|
|
330
|
+
"does not restore an attachment that resolves after %s",
|
|
331
|
+
async (_name, invoke) => {
|
|
332
|
+
let resolveAdd!: (attachment: PendingAttachment) => void;
|
|
333
|
+
const add = vi.fn(
|
|
334
|
+
() =>
|
|
335
|
+
new Promise<PendingAttachment>((resolve) => {
|
|
336
|
+
resolveAdd = resolve;
|
|
337
|
+
}),
|
|
338
|
+
);
|
|
339
|
+
const aui = renderThreadWithProps({
|
|
340
|
+
attachmentAdapter: {
|
|
341
|
+
accept: "*",
|
|
342
|
+
add,
|
|
343
|
+
send: async () => ({}) as never,
|
|
344
|
+
remove: async () => {},
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
const file = new File(["data"], "notes.txt", { type: "text/plain" });
|
|
348
|
+
|
|
349
|
+
let addPromise!: Promise<void>;
|
|
350
|
+
act(() => {
|
|
351
|
+
addPromise = aui().thread.composer().addAttachment(file);
|
|
352
|
+
});
|
|
353
|
+
await act(() => invoke(aui().thread.composer()));
|
|
354
|
+
await act(async () => {
|
|
355
|
+
resolveAdd({
|
|
356
|
+
id: "att-1",
|
|
357
|
+
type: "file",
|
|
358
|
+
name: file.name,
|
|
359
|
+
contentType: file.type,
|
|
360
|
+
file,
|
|
361
|
+
status: { type: "requires-action", reason: "composer-send" },
|
|
362
|
+
});
|
|
363
|
+
await addPromise;
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
expect(aui().thread.composer().getState().attachments).toHaveLength(0);
|
|
367
|
+
},
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
it("stops attachment generator updates after removal", async () => {
|
|
371
|
+
let resumeAdd!: () => void;
|
|
372
|
+
const drainedAfterRemoval = vi.fn();
|
|
373
|
+
const file = new File(["data"], "notes.txt", { type: "text/plain" });
|
|
374
|
+
const pendingAttachment: PendingAttachment = {
|
|
375
|
+
id: "att-1",
|
|
376
|
+
type: "file",
|
|
377
|
+
name: file.name,
|
|
378
|
+
contentType: file.type,
|
|
379
|
+
file,
|
|
380
|
+
status: { type: "requires-action", reason: "composer-send" },
|
|
381
|
+
};
|
|
382
|
+
const add = vi.fn(async function* () {
|
|
383
|
+
yield pendingAttachment;
|
|
384
|
+
await new Promise<void>((resolve) => {
|
|
385
|
+
resumeAdd = resolve;
|
|
386
|
+
});
|
|
387
|
+
yield {
|
|
388
|
+
...pendingAttachment,
|
|
389
|
+
status: { type: "running", reason: "uploading", progress: 1 },
|
|
390
|
+
} satisfies PendingAttachment;
|
|
391
|
+
drainedAfterRemoval();
|
|
392
|
+
});
|
|
393
|
+
const aui = renderThreadWithProps({
|
|
394
|
+
attachmentAdapter: {
|
|
395
|
+
accept: "*",
|
|
396
|
+
add,
|
|
397
|
+
send: async () => ({}) as never,
|
|
398
|
+
remove: async () => {},
|
|
399
|
+
},
|
|
400
|
+
});
|
|
401
|
+
const composer = () => aui().thread.composer();
|
|
402
|
+
|
|
403
|
+
let addPromise!: Promise<void>;
|
|
404
|
+
act(() => {
|
|
405
|
+
addPromise = composer().addAttachment(file);
|
|
406
|
+
});
|
|
407
|
+
await waitFor(() =>
|
|
408
|
+
expect(composer().getState().attachments).toHaveLength(1),
|
|
409
|
+
);
|
|
410
|
+
await act(() => composer().attachment({ id: "att-1" }).remove());
|
|
411
|
+
await act(async () => {
|
|
412
|
+
resumeAdd();
|
|
413
|
+
await addPromise;
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
expect(composer().getState().attachments).toHaveLength(0);
|
|
417
|
+
expect(drainedAfterRemoval).not.toHaveBeenCalled();
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it("does not restore attachment generator updates after send", async () => {
|
|
421
|
+
let resumeAdd!: () => void;
|
|
422
|
+
const drainedAfterSend = vi.fn();
|
|
423
|
+
const onNew = vi.fn();
|
|
424
|
+
const file = new File(["data"], "notes.txt", { type: "text/plain" });
|
|
425
|
+
const pendingAttachment: PendingAttachment = {
|
|
426
|
+
id: "att-1",
|
|
427
|
+
type: "file",
|
|
428
|
+
name: file.name,
|
|
429
|
+
contentType: file.type,
|
|
430
|
+
file,
|
|
431
|
+
status: { type: "requires-action", reason: "composer-send" },
|
|
432
|
+
};
|
|
433
|
+
const add = vi.fn(async function* () {
|
|
434
|
+
yield pendingAttachment;
|
|
435
|
+
await new Promise<void>((resolve) => {
|
|
436
|
+
resumeAdd = resolve;
|
|
437
|
+
});
|
|
438
|
+
yield {
|
|
439
|
+
...pendingAttachment,
|
|
440
|
+
status: { type: "running", reason: "uploading", progress: 1 },
|
|
441
|
+
} satisfies PendingAttachment;
|
|
442
|
+
drainedAfterSend();
|
|
443
|
+
});
|
|
444
|
+
const aui = renderThreadWithProps({
|
|
445
|
+
attachmentAdapter: {
|
|
446
|
+
accept: "*",
|
|
447
|
+
add,
|
|
448
|
+
send: async (attachment) => ({
|
|
449
|
+
...attachment,
|
|
450
|
+
status: { type: "complete" },
|
|
451
|
+
content: [],
|
|
452
|
+
}),
|
|
453
|
+
remove: async () => {},
|
|
454
|
+
},
|
|
455
|
+
onNew,
|
|
456
|
+
});
|
|
457
|
+
const composer = () => aui().thread.composer();
|
|
458
|
+
|
|
459
|
+
let addPromise!: Promise<void>;
|
|
460
|
+
act(() => {
|
|
461
|
+
addPromise = composer().addAttachment(file);
|
|
462
|
+
});
|
|
463
|
+
await waitFor(() =>
|
|
464
|
+
expect(composer().getState().attachments).toHaveLength(1),
|
|
465
|
+
);
|
|
466
|
+
act(() => {
|
|
467
|
+
composer().setText("hello");
|
|
468
|
+
composer().send();
|
|
469
|
+
});
|
|
470
|
+
await waitFor(() => expect(onNew).toHaveBeenCalledTimes(1));
|
|
471
|
+
await act(async () => {
|
|
472
|
+
resumeAdd();
|
|
473
|
+
await addPromise;
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
expect(composer().getState().attachments).toHaveLength(0);
|
|
477
|
+
expect(drainedAfterSend).not.toHaveBeenCalled();
|
|
478
|
+
});
|
|
479
|
+
|
|
266
480
|
it("routes edit-composer attachments through the adapter", async () => {
|
|
267
481
|
const add = vi.fn(async ({ file }: { file: File }) => ({
|
|
268
482
|
id: "att-edit",
|
|
@@ -279,6 +279,60 @@ describe("ExternalThread composer", () => {
|
|
|
279
279
|
expect(enqueue).not.toHaveBeenCalled();
|
|
280
280
|
});
|
|
281
281
|
|
|
282
|
+
it("pauses the queue on cancel", async () => {
|
|
283
|
+
const notifyCancelled = vi.fn();
|
|
284
|
+
const onCancel = vi.fn();
|
|
285
|
+
const { aui } = renderThread({
|
|
286
|
+
messages: [],
|
|
287
|
+
isRunning: true,
|
|
288
|
+
onCancel,
|
|
289
|
+
queue: {
|
|
290
|
+
items: [],
|
|
291
|
+
steerItems: [],
|
|
292
|
+
enqueue: vi.fn(),
|
|
293
|
+
steer: vi.fn(),
|
|
294
|
+
move: vi.fn(),
|
|
295
|
+
edit: vi.fn(),
|
|
296
|
+
remove: vi.fn(),
|
|
297
|
+
__internal_notifyCancelled: notifyCancelled,
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
aui().thread.cancelRun();
|
|
302
|
+
|
|
303
|
+
expect(notifyCancelled).toHaveBeenCalledTimes(1);
|
|
304
|
+
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
305
|
+
expect(notifyCancelled.mock.invocationCallOrder[0]!).toBeLessThan(
|
|
306
|
+
onCancel.mock.invocationCallOrder[0]!,
|
|
307
|
+
);
|
|
308
|
+
expect(aui().thread.getState().capabilities.cancel).toBe(true);
|
|
309
|
+
expect(aui().thread.composer().getState().canCancel).toBe(true);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("leaves the queue alone when the host cannot cancel", async () => {
|
|
313
|
+
const notifyCancelled = vi.fn();
|
|
314
|
+
const { aui } = renderThread({
|
|
315
|
+
messages: [],
|
|
316
|
+
isRunning: true,
|
|
317
|
+
queue: {
|
|
318
|
+
items: [],
|
|
319
|
+
steerItems: [],
|
|
320
|
+
enqueue: vi.fn(),
|
|
321
|
+
steer: vi.fn(),
|
|
322
|
+
move: vi.fn(),
|
|
323
|
+
edit: vi.fn(),
|
|
324
|
+
remove: vi.fn(),
|
|
325
|
+
__internal_notifyCancelled: notifyCancelled,
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
aui().thread.cancelRun();
|
|
330
|
+
|
|
331
|
+
expect(notifyCancelled).not.toHaveBeenCalled();
|
|
332
|
+
expect(aui().thread.getState().capabilities.cancel).toBe(false);
|
|
333
|
+
expect(aui().thread.composer().getState().canCancel).toBe(false);
|
|
334
|
+
});
|
|
335
|
+
|
|
282
336
|
it("routes edit-composer sends to onEdit with sourceId, bypassing the queue", async () => {
|
|
283
337
|
const onEdit = vi.fn();
|
|
284
338
|
const enqueue = vi.fn();
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { cleanup, render, waitFor } from "@testing-library/react";
|
|
4
|
+
import type { FC } from "react";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { AuiProvider, useAui } from "@assistant-ui/store";
|
|
8
|
+
import { ExternalThread } from "../store/clients/external-thread";
|
|
9
|
+
import type { ThreadMessage } from "../types/message";
|
|
10
|
+
|
|
11
|
+
const message = (id: string, role: "user" | "assistant"): ThreadMessage =>
|
|
12
|
+
({
|
|
13
|
+
id,
|
|
14
|
+
role,
|
|
15
|
+
content: [{ type: "text", text: `text of ${id}` }],
|
|
16
|
+
createdAt: new Date(1718000000000),
|
|
17
|
+
...(role === "assistant"
|
|
18
|
+
? { status: { type: "complete", reason: "stop" } }
|
|
19
|
+
: { attachments: [] }),
|
|
20
|
+
metadata: { custom: {} },
|
|
21
|
+
}) as ThreadMessage;
|
|
22
|
+
|
|
23
|
+
let aui!: ReturnType<typeof useAui>;
|
|
24
|
+
|
|
25
|
+
const Capture: FC = () => {
|
|
26
|
+
aui = useAui();
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const renderThread = (props: Parameters<typeof ExternalThread>[0]) => {
|
|
31
|
+
const App: FC = () => {
|
|
32
|
+
const value = useAui({ thread: ExternalThread(props) });
|
|
33
|
+
return (
|
|
34
|
+
<AuiProvider value={value}>
|
|
35
|
+
<Capture />
|
|
36
|
+
</AuiProvider>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
render(<App />);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
cleanup();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("ExternalThread refetch", () => {
|
|
47
|
+
it("routes reloadMainThread to onRefetchThread and reports the capability", async () => {
|
|
48
|
+
const onRefetchThread = vi.fn(async () => {});
|
|
49
|
+
renderThread({ messages: [], onRefetchThread });
|
|
50
|
+
|
|
51
|
+
await waitFor(() =>
|
|
52
|
+
expect(
|
|
53
|
+
aui.threads.thread("main").getState().capabilities.refetchThread,
|
|
54
|
+
).toBe(true),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
await aui.threads.reloadMainThread();
|
|
58
|
+
expect(onRefetchThread).toHaveBeenCalledTimes(1);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("resolves reloadMainThread without a callback and reports the capability off", async () => {
|
|
62
|
+
renderThread({ messages: [] });
|
|
63
|
+
|
|
64
|
+
await waitFor(() =>
|
|
65
|
+
expect(
|
|
66
|
+
aui.threads.thread("main").getState().capabilities.refetchThread,
|
|
67
|
+
).toBe(false),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
await expect(aui.threads.reloadMainThread()).resolves.toBeUndefined();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("propagates a refetch rejection to the caller", async () => {
|
|
74
|
+
const onRefetchThread = vi.fn(async () => {
|
|
75
|
+
throw new Error("refetch failed");
|
|
76
|
+
});
|
|
77
|
+
renderThread({ messages: [], onRefetchThread });
|
|
78
|
+
|
|
79
|
+
await waitFor(() =>
|
|
80
|
+
expect(
|
|
81
|
+
aui.threads.thread("main").getState().capabilities.refetchThread,
|
|
82
|
+
).toBe(true),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
await expect(aui.threads.reloadMainThread()).rejects.toThrow(
|
|
86
|
+
"refetch failed",
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("applies refetched messages in place with the composer draft intact", async () => {
|
|
91
|
+
const App: FC = () => {
|
|
92
|
+
const [messages, setMessages] = useState<readonly ThreadMessage[]>([]);
|
|
93
|
+
const value = useAui({
|
|
94
|
+
thread: ExternalThread({
|
|
95
|
+
messages,
|
|
96
|
+
onRefetchThread: async () => {
|
|
97
|
+
setMessages([message("a1", "assistant")]);
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
return (
|
|
102
|
+
<AuiProvider value={value}>
|
|
103
|
+
<Capture />
|
|
104
|
+
</AuiProvider>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
render(<App />);
|
|
108
|
+
|
|
109
|
+
aui.thread.composer().setText("draft");
|
|
110
|
+
await aui.threads.reloadMainThread();
|
|
111
|
+
|
|
112
|
+
await waitFor(() =>
|
|
113
|
+
expect(aui.thread.getState().messages.map((m) => m.id)).toEqual(["a1"]),
|
|
114
|
+
);
|
|
115
|
+
expect(aui.thread.composer().getState().text).toBe("draft");
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { cleanup, render } from "@testing-library/react";
|
|
4
|
+
import type { FC, ReactNode } from "react";
|
|
5
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
6
|
+
import { AuiProvider, useAui } from "@assistant-ui/store";
|
|
7
|
+
import { ExternalThread } from "../store/clients/external-thread";
|
|
8
|
+
import { SingleThreadList } from "../store/clients/single-thread-list";
|
|
9
|
+
|
|
10
|
+
let childAui!: ReturnType<typeof useAui>;
|
|
11
|
+
|
|
12
|
+
const CaptureChild: FC = () => {
|
|
13
|
+
childAui = useAui();
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const Child: FC = () => {
|
|
18
|
+
const aui = useAui({ thread: ExternalThread({ messages: [] }) });
|
|
19
|
+
return (
|
|
20
|
+
<AuiProvider value={aui}>
|
|
21
|
+
<CaptureChild />
|
|
22
|
+
</AuiProvider>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const Parent: FC<{ children: ReactNode }> = ({ children }) => {
|
|
27
|
+
const aui = useAui({
|
|
28
|
+
threads: SingleThreadList({ thread: ExternalThread({ messages: [] }) }),
|
|
29
|
+
});
|
|
30
|
+
return <AuiProvider value={aui}>{children}</AuiProvider>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
cleanup();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("ExternalThread suggestions scope", () => {
|
|
38
|
+
it("derives the scope from its own thread when standalone", () => {
|
|
39
|
+
render(<Child />);
|
|
40
|
+
|
|
41
|
+
expect(childAui.suggestions.getState()).toEqual({ suggestions: [] });
|
|
42
|
+
expect(childAui.suggestions.getState()).toBe(
|
|
43
|
+
childAui.thread.suggestions().getState(),
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("derives the scope from its own thread when nested under a threads parent", () => {
|
|
48
|
+
render(
|
|
49
|
+
<Parent>
|
|
50
|
+
<Child />
|
|
51
|
+
</Parent>,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(childAui.suggestions.getState()).toEqual({ suggestions: [] });
|
|
55
|
+
expect(childAui.suggestions.getState()).toBe(
|
|
56
|
+
childAui.thread.suggestions().getState(),
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { act, cleanup, render } from "@testing-library/react";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { withKey } from "@assistant-ui/tap";
|
|
6
|
+
import { useAui } from "@assistant-ui/store";
|
|
7
|
+
import { Tools } from "../react/client/Tools";
|
|
8
|
+
import { unstable_Interactables } from "../react/client/Interactables";
|
|
9
|
+
|
|
10
|
+
type AnyClient = Record<string, any>;
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
cleanup();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe("interactables update-tool UI registration", () => {
|
|
17
|
+
it("migrates to a structurally replaced tools scope", async () => {
|
|
18
|
+
let aui!: AnyClient;
|
|
19
|
+
const Harness = ({ generation }: { generation: number }) => {
|
|
20
|
+
aui = useAui({
|
|
21
|
+
tools: withKey(String(generation), Tools({})),
|
|
22
|
+
unstable_interactables: unstable_Interactables({}),
|
|
23
|
+
} as never);
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
const view = render(<Harness generation={0} />);
|
|
27
|
+
|
|
28
|
+
const toolUIs = () =>
|
|
29
|
+
(aui.tools().getState().toolUIs ?? {}) as Record<string, unknown[]>;
|
|
30
|
+
// setToolUI lands after the tap scheduler drains its macrotask
|
|
31
|
+
await act(async () => {
|
|
32
|
+
aui.unstable_interactables.register({
|
|
33
|
+
id: "call-1",
|
|
34
|
+
name: "note",
|
|
35
|
+
description: "a note",
|
|
36
|
+
stateSchema: { type: "object", properties: {} },
|
|
37
|
+
initialState: {},
|
|
38
|
+
updateRender: () => null,
|
|
39
|
+
});
|
|
40
|
+
await vi.waitFor(() => expect(Object.keys(toolUIs())).toHaveLength(1));
|
|
41
|
+
});
|
|
42
|
+
const [toolName] = Object.keys(toolUIs());
|
|
43
|
+
const firstRegistration = toolUIs()[toolName!]![0];
|
|
44
|
+
|
|
45
|
+
// A rerender inside an outer act would not land until that act exits,
|
|
46
|
+
// so the swap happens first and only the scheduler wait is wrapped
|
|
47
|
+
view.rerender(<Harness generation={1} />);
|
|
48
|
+
|
|
49
|
+
// The remounted tools scope starts from fresh state; a registration
|
|
50
|
+
// object distinct from the pre-swap one proves the retained entry was
|
|
51
|
+
// re-applied on the replacement instance rather than read stale. It
|
|
52
|
+
// lands one scheduler macrotask after the swap, once the tap scheduler
|
|
53
|
+
// drains.
|
|
54
|
+
await act(async () => {
|
|
55
|
+
await vi.waitFor(() => {
|
|
56
|
+
const registration = toolUIs()[toolName!]?.[0];
|
|
57
|
+
expect(registration).toBeDefined();
|
|
58
|
+
expect(registration).not.toBe(firstRegistration);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Post-settle cardinality: a duplicate re-apply would leave a second
|
|
63
|
+
// registration whose disposer was dropped
|
|
64
|
+
expect(toolUIs()[toolName!]).toHaveLength(1);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -612,6 +612,34 @@ describe("createMessageQueue", () => {
|
|
|
612
612
|
expect(cb).toHaveBeenCalled();
|
|
613
613
|
});
|
|
614
614
|
|
|
615
|
+
it("isolates subscriber errors while enqueueing", () => {
|
|
616
|
+
const run = vi.fn();
|
|
617
|
+
const { adapter, subscribe } = createMessageQueue({ run });
|
|
618
|
+
const error = new Error("subscriber failed");
|
|
619
|
+
const laterSubscriber = vi.fn();
|
|
620
|
+
const consoleError = vi
|
|
621
|
+
.spyOn(console, "error")
|
|
622
|
+
.mockImplementation(() => {});
|
|
623
|
+
|
|
624
|
+
subscribe(() => {
|
|
625
|
+
throw error;
|
|
626
|
+
});
|
|
627
|
+
subscribe(laterSubscriber);
|
|
628
|
+
|
|
629
|
+
try {
|
|
630
|
+
expect(() => adapter.enqueue(msg("a"), { steer: false })).not.toThrow();
|
|
631
|
+
expect(run).toHaveBeenCalledTimes(1);
|
|
632
|
+
expect(adapter.items).toHaveLength(0);
|
|
633
|
+
expect(laterSubscriber).toHaveBeenCalledTimes(2);
|
|
634
|
+
expect(consoleError).toHaveBeenCalledWith(
|
|
635
|
+
"[assistant-ui] Message queue listener threw an error",
|
|
636
|
+
error,
|
|
637
|
+
);
|
|
638
|
+
} finally {
|
|
639
|
+
consoleError.mockRestore();
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
|
|
615
643
|
it("buffers when a run started outside the queue is marked busy", () => {
|
|
616
644
|
const run = vi.fn();
|
|
617
645
|
const { adapter, notifyBusy, notifyIdle } = createMessageQueue({ run });
|
|
@@ -626,3 +654,29 @@ describe("createMessageQueue", () => {
|
|
|
626
654
|
expect(adapter.items).toHaveLength(0);
|
|
627
655
|
});
|
|
628
656
|
});
|
|
657
|
+
|
|
658
|
+
describe("createMessageQueue interrupt with a runtime-routed cancel", () => {
|
|
659
|
+
it("keeps draining when the driver's cancel notifies back", () => {
|
|
660
|
+
const runs: string[] = [];
|
|
661
|
+
const controller = createMessageQueue({
|
|
662
|
+
run: (message) => {
|
|
663
|
+
runs.push(
|
|
664
|
+
message.content[0]!.type === "text" ? message.content[0].text : "",
|
|
665
|
+
);
|
|
666
|
+
},
|
|
667
|
+
cancel: () => controller.notifyCancelled(),
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
controller.adapter.enqueue(msg("first"));
|
|
671
|
+
controller.adapter.enqueue(msg("second"));
|
|
672
|
+
controller.adapter.steer(msg("steered"));
|
|
673
|
+
|
|
674
|
+
expect(runs).toEqual(["first", "steered"]);
|
|
675
|
+
|
|
676
|
+
// the interrupted run and the steer run each settle once
|
|
677
|
+
controller.notifyIdle();
|
|
678
|
+
controller.notifyIdle();
|
|
679
|
+
|
|
680
|
+
expect(runs).toEqual(["first", "steered", "second"]);
|
|
681
|
+
});
|
|
682
|
+
});
|