@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
|
@@ -15,10 +15,13 @@ import {
|
|
|
15
15
|
updateStatusReducer,
|
|
16
16
|
} from "../../runtimes/remote-thread-list/remote-thread-state";
|
|
17
17
|
import type {
|
|
18
|
+
RemoteThreadListAdapter,
|
|
18
19
|
RemoteThreadListOptions,
|
|
19
|
-
|
|
20
|
+
RemoteThreadMetadata,
|
|
20
21
|
} from "../../runtimes/remote-thread-list/types";
|
|
22
|
+
import { ThreadListAdapterChangedError } from "../../runtimes/remote-thread-list/adapter-changed";
|
|
21
23
|
import { RemoteThreadListHookInstanceManager } from "./RemoteThreadListHookInstanceManager";
|
|
24
|
+
import { isTitleSourceMessage } from "./RemoteThreadResource";
|
|
22
25
|
import {
|
|
23
26
|
type ComponentType,
|
|
24
27
|
type FC,
|
|
@@ -27,15 +30,12 @@ import {
|
|
|
27
30
|
useEffect,
|
|
28
31
|
useId,
|
|
29
32
|
} from "react";
|
|
33
|
+
import { useAui } from "@assistant-ui/store";
|
|
30
34
|
import { create } from "zustand";
|
|
31
35
|
import { AssistantMessageStream } from "assistant-stream";
|
|
32
36
|
import type { ModelContextProvider } from "../../model-context/types";
|
|
33
37
|
import { RuntimeAdapterProvider } from "./RuntimeAdapterProvider";
|
|
34
|
-
|
|
35
|
-
const asProviderComponent = (
|
|
36
|
-
provider: RemoteThreadListProviderComponent | undefined,
|
|
37
|
-
): ComponentType<PropsWithChildren> =>
|
|
38
|
-
(provider ?? Fragment) as ComponentType<PropsWithChildren>;
|
|
38
|
+
import { useStableRuntimeAdapters } from "./useRuntimeAdapters";
|
|
39
39
|
|
|
40
40
|
const threadNotFoundError = (threadIdOrRemoteId: string, action: string) =>
|
|
41
41
|
new Error(`Thread "${threadIdOrRemoteId}" not found while ${action}.`);
|
|
@@ -49,30 +49,105 @@ const threadStatusError = (
|
|
|
49
49
|
`Thread "${threadIdOrRemoteId}" has status "${status}", so it cannot ${action}.`,
|
|
50
50
|
);
|
|
51
51
|
|
|
52
|
+
const EMPTY_REMOTE_STATE: RemoteThreadState = {
|
|
53
|
+
isLoading: true,
|
|
54
|
+
isLoadingMore: false,
|
|
55
|
+
cursor: undefined,
|
|
56
|
+
newThreadId: undefined,
|
|
57
|
+
threadIds: [],
|
|
58
|
+
archivedThreadIds: [],
|
|
59
|
+
threadIdMap: {},
|
|
60
|
+
threadData: {},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const addNewThread = (state: RemoteThreadState) => {
|
|
64
|
+
let id: string;
|
|
65
|
+
do {
|
|
66
|
+
id = `__LOCALID_${generateId()}`;
|
|
67
|
+
} while (state.threadIdMap[id]);
|
|
68
|
+
|
|
69
|
+
const mappingId = createThreadMappingId(id);
|
|
70
|
+
return {
|
|
71
|
+
id,
|
|
72
|
+
state: {
|
|
73
|
+
...state,
|
|
74
|
+
newThreadId: id,
|
|
75
|
+
threadIdMap: {
|
|
76
|
+
...state.threadIdMap,
|
|
77
|
+
[id]: mappingId,
|
|
78
|
+
},
|
|
79
|
+
threadData: {
|
|
80
|
+
...state.threadData,
|
|
81
|
+
[mappingId]: {
|
|
82
|
+
status: "new",
|
|
83
|
+
id,
|
|
84
|
+
remoteId: undefined,
|
|
85
|
+
externalId: undefined,
|
|
86
|
+
title: undefined,
|
|
87
|
+
custom: undefined,
|
|
88
|
+
} satisfies RemoteThreadData,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
52
94
|
export class RemoteThreadListThreadListRuntimeCore
|
|
53
95
|
extends BaseSubscribable
|
|
54
96
|
implements ThreadListRuntimeCore
|
|
55
97
|
{
|
|
56
98
|
private _options!: RemoteThreadListOptions;
|
|
57
99
|
private readonly _hookManager: RemoteThreadListHookInstanceManager;
|
|
100
|
+
private readonly _runtimeAdapters: { modelContext: ModelContextProvider };
|
|
58
101
|
|
|
59
102
|
private _loadThreadsPromise: Promise<void> | undefined;
|
|
60
103
|
private _loadMorePromise: Promise<void> | undefined;
|
|
61
104
|
private _loadGeneration = 0;
|
|
105
|
+
private _adapterGeneration = 0;
|
|
106
|
+
private _replaceListOnNextLoad = false;
|
|
107
|
+
private _staleThreadIdsOnReplace: ReadonlySet<string> | undefined;
|
|
62
108
|
private _switchGeneration = 0;
|
|
63
109
|
private _switchTask: Promise<void> | undefined;
|
|
64
110
|
|
|
65
111
|
private _mainThreadId!: string;
|
|
66
|
-
private readonly _state = new OptimisticState<RemoteThreadState>(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
112
|
+
private readonly _state = new OptimisticState<RemoteThreadState>(
|
|
113
|
+
EMPTY_REMOTE_STATE,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
private readonly _useAdaptersProvider: FC<PropsWithChildren> = ({
|
|
117
|
+
children,
|
|
118
|
+
}) => {
|
|
119
|
+
const useAdapters = this._options.adapter.unstable_useAdapters;
|
|
120
|
+
if (useAdapters === undefined) return children;
|
|
121
|
+
return (
|
|
122
|
+
<this._SynthesizedAdapters useAdapters={useAdapters}>
|
|
123
|
+
{children}
|
|
124
|
+
</this._SynthesizedAdapters>
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
private readonly _SynthesizedAdapters: FC<
|
|
129
|
+
PropsWithChildren<{
|
|
130
|
+
useAdapters: NonNullable<RemoteThreadListAdapter["unstable_useAdapters"]>;
|
|
131
|
+
}>
|
|
132
|
+
> = ({ useAdapters, children }) => {
|
|
133
|
+
const adapters = useStableRuntimeAdapters(useAdapters());
|
|
134
|
+
if (adapters == null) return children;
|
|
135
|
+
return (
|
|
136
|
+
<RuntimeAdapterProvider adapters={adapters}>
|
|
137
|
+
{children}
|
|
138
|
+
</RuntimeAdapterProvider>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
private resolveProvider(
|
|
143
|
+
adapter: RemoteThreadListAdapter,
|
|
144
|
+
): ComponentType<PropsWithChildren> {
|
|
145
|
+
if (adapter.unstable_Provider !== undefined) {
|
|
146
|
+
return adapter.unstable_Provider as ComponentType<PropsWithChildren>;
|
|
147
|
+
}
|
|
148
|
+
if (adapter.unstable_useAdapters === undefined) return Fragment;
|
|
149
|
+
return this._useAdaptersProvider;
|
|
150
|
+
}
|
|
76
151
|
|
|
77
152
|
public get threadItems() {
|
|
78
153
|
return this._state.value.threadData;
|
|
@@ -82,6 +157,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
82
157
|
// TODO this needs to be cached in case this promise is loaded during suspense
|
|
83
158
|
if (!this._loadThreadsPromise) {
|
|
84
159
|
const generation = this._loadGeneration;
|
|
160
|
+
let replacedList = false;
|
|
85
161
|
this._loadThreadsPromise = this._state
|
|
86
162
|
.optimisticUpdate({
|
|
87
163
|
execute: () => this._options.adapter.list(),
|
|
@@ -93,27 +169,31 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
93
169
|
},
|
|
94
170
|
then: (state, l) => {
|
|
95
171
|
if (generation !== this._loadGeneration) return state;
|
|
172
|
+
const replaceList = this._replaceListOnNextLoad;
|
|
173
|
+
if (replaceList) {
|
|
174
|
+
this._replaceListOnNextLoad = false;
|
|
175
|
+
replacedList = true;
|
|
176
|
+
return this._replaceWithThreads(
|
|
177
|
+
state,
|
|
178
|
+
l.threads,
|
|
179
|
+
normalizeCursor(l.nextCursor),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
96
183
|
const fresh = classifyThreads(l.threads, {
|
|
97
184
|
threadIds: [],
|
|
98
185
|
archivedThreadIds: [],
|
|
99
186
|
threadIdMap: {},
|
|
100
187
|
threadData: {},
|
|
101
188
|
});
|
|
102
|
-
|
|
103
189
|
return {
|
|
104
190
|
...state,
|
|
105
191
|
isLoading: false,
|
|
106
192
|
cursor: normalizeCursor(l.nextCursor),
|
|
107
193
|
threadIds: fresh.threadIds,
|
|
108
194
|
archivedThreadIds: fresh.archivedThreadIds,
|
|
109
|
-
threadIdMap: {
|
|
110
|
-
|
|
111
|
-
...fresh.threadIdMap,
|
|
112
|
-
},
|
|
113
|
-
threadData: {
|
|
114
|
-
...state.threadData,
|
|
115
|
-
...fresh.threadData,
|
|
116
|
-
},
|
|
195
|
+
threadIdMap: { ...state.threadIdMap, ...fresh.threadIdMap },
|
|
196
|
+
threadData: { ...state.threadData, ...fresh.threadData },
|
|
117
197
|
};
|
|
118
198
|
},
|
|
119
199
|
})
|
|
@@ -121,12 +201,26 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
121
201
|
if (generation !== this._loadGeneration) return;
|
|
122
202
|
console.error("[assistant-ui] thread list load failed:", error);
|
|
123
203
|
this._loadThreadsPromise = undefined;
|
|
124
|
-
this.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
204
|
+
if (!this._replaceListOnNextLoad) {
|
|
205
|
+
this._state.update({
|
|
206
|
+
...this._state.baseValue,
|
|
207
|
+
isLoading: false,
|
|
208
|
+
});
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
this._replaceListOnNextLoad = false;
|
|
212
|
+
replacedList = true;
|
|
213
|
+
this._state.update(
|
|
214
|
+
this._replaceWithThreads(this._state.baseValue, [], undefined),
|
|
215
|
+
);
|
|
128
216
|
})
|
|
129
|
-
.then(() => {
|
|
217
|
+
.then(() => {
|
|
218
|
+
if (!replacedList) return;
|
|
219
|
+
const threadId = this._options.threadId;
|
|
220
|
+
if (threadId === undefined) return;
|
|
221
|
+
if (this.getItemById(threadId)?.id === this._mainThreadId) return;
|
|
222
|
+
this._switchToThreadFromProp(threadId).catch(() => {});
|
|
223
|
+
});
|
|
130
224
|
}
|
|
131
225
|
|
|
132
226
|
return this._loadThreadsPromise;
|
|
@@ -171,6 +265,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
171
265
|
},
|
|
172
266
|
})
|
|
173
267
|
.catch((error: unknown) => {
|
|
268
|
+
if (generation !== this._loadGeneration) return;
|
|
174
269
|
console.error("[assistant-ui] thread list loadMore failed:", error);
|
|
175
270
|
})
|
|
176
271
|
.then(() => {
|
|
@@ -183,28 +278,32 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
183
278
|
return dedup;
|
|
184
279
|
}
|
|
185
280
|
|
|
186
|
-
private readonly contextProvider: ModelContextProvider;
|
|
187
|
-
|
|
188
281
|
constructor(
|
|
189
282
|
options: RemoteThreadListOptions,
|
|
190
283
|
contextProvider: ModelContextProvider,
|
|
191
284
|
) {
|
|
192
285
|
super();
|
|
193
|
-
this.contextProvider = contextProvider;
|
|
194
286
|
|
|
195
287
|
this._state.subscribe(() => {
|
|
196
288
|
this._notifySubscribers();
|
|
197
289
|
this._notifyThreadIdChange();
|
|
198
290
|
});
|
|
291
|
+
this._runtimeAdapters = { modelContext: contextProvider };
|
|
199
292
|
this._hookManager = new RemoteThreadListHookInstanceManager(
|
|
200
293
|
options.runtimeHook,
|
|
201
294
|
this,
|
|
202
295
|
);
|
|
296
|
+
this._hookManager.__internal_setDefaultAdapters(this._runtimeAdapters);
|
|
203
297
|
this._hookManager.__internal_subscribeRunningChanged(() =>
|
|
204
298
|
this._notifySubscribers(),
|
|
205
299
|
);
|
|
300
|
+
this._hookManager.__internal_subscribeRuntimeReplaced(() => {
|
|
301
|
+
// A republish can land during the thread resource's render, where a
|
|
302
|
+
// synchronous notify would re-enter store consumers mid-render.
|
|
303
|
+
queueMicrotask(() => this._notifySubscribers());
|
|
304
|
+
});
|
|
206
305
|
this.useProvider = create(() => ({
|
|
207
|
-
Provider:
|
|
306
|
+
Provider: this.resolveProvider(options.adapter),
|
|
208
307
|
}));
|
|
209
308
|
this.__internal_setOptions(options);
|
|
210
309
|
this.switchToNewThread();
|
|
@@ -225,7 +324,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
225
324
|
|
|
226
325
|
this._options = options;
|
|
227
326
|
|
|
228
|
-
const Provider =
|
|
327
|
+
const Provider = this.resolveProvider(options.adapter);
|
|
229
328
|
if (Provider !== this.useProvider.getState().Provider) {
|
|
230
329
|
this.useProvider.setState({ Provider }, true);
|
|
231
330
|
}
|
|
@@ -234,8 +333,17 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
234
333
|
|
|
235
334
|
if (adapterChanged) {
|
|
236
335
|
this._loadGeneration++;
|
|
336
|
+
this._adapterGeneration++;
|
|
337
|
+
this._switchGeneration++;
|
|
338
|
+
this._switchTask = undefined;
|
|
237
339
|
this._loadThreadsPromise = undefined;
|
|
238
340
|
this._loadMorePromise = undefined;
|
|
341
|
+
this._replaceListOnNextLoad = true;
|
|
342
|
+
this._staleThreadIdsOnReplace = new Set(
|
|
343
|
+
Object.values(this._state.baseValue.threadData)
|
|
344
|
+
.filter((item) => item.status !== "new")
|
|
345
|
+
.map((item) => item.id),
|
|
346
|
+
);
|
|
239
347
|
this._state.update({
|
|
240
348
|
...this._state.baseValue,
|
|
241
349
|
cursor: undefined,
|
|
@@ -247,6 +355,115 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
247
355
|
}
|
|
248
356
|
}
|
|
249
357
|
|
|
358
|
+
private _requireAdapterGeneration(generation: number) {
|
|
359
|
+
if (generation !== this._adapterGeneration) {
|
|
360
|
+
throw new ThreadListAdapterChangedError();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
private _requireAdapterSettled() {
|
|
365
|
+
if (this._replaceListOnNextLoad) {
|
|
366
|
+
throw new ThreadListAdapterChangedError();
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
private _replaceWithThreads(
|
|
371
|
+
state: RemoteThreadState,
|
|
372
|
+
threads: readonly RemoteThreadMetadata[],
|
|
373
|
+
cursor: string | undefined,
|
|
374
|
+
): RemoteThreadState {
|
|
375
|
+
const fresh = classifyThreads(threads, {
|
|
376
|
+
threadIds: [],
|
|
377
|
+
archivedThreadIds: [],
|
|
378
|
+
threadIdMap: {},
|
|
379
|
+
threadData: {},
|
|
380
|
+
});
|
|
381
|
+
const threadIdMap = { ...fresh.threadIdMap };
|
|
382
|
+
const threadData = { ...fresh.threadData };
|
|
383
|
+
const threadIds = [...fresh.threadIds];
|
|
384
|
+
const archivedThreadIds = [...fresh.archivedThreadIds];
|
|
385
|
+
|
|
386
|
+
if (state.newThreadId) {
|
|
387
|
+
const mappingId = state.threadIdMap[state.newThreadId];
|
|
388
|
+
const draft = mappingId ? state.threadData[mappingId] : undefined;
|
|
389
|
+
if (draft?.status === "new") {
|
|
390
|
+
threadIdMap[state.newThreadId] = mappingId!;
|
|
391
|
+
threadData[mappingId!] = draft;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const stale = this._staleThreadIdsOnReplace;
|
|
396
|
+
if (stale) {
|
|
397
|
+
for (const item of Object.values(state.threadData)) {
|
|
398
|
+
if (stale.has(item.id)) continue;
|
|
399
|
+
if (item.status !== "new" && item.remoteId === undefined) continue;
|
|
400
|
+
const mappingId = createThreadMappingId(item.id);
|
|
401
|
+
if (threadData[mappingId]) continue;
|
|
402
|
+
threadIdMap[item.id] = mappingId;
|
|
403
|
+
if (item.remoteId !== undefined) {
|
|
404
|
+
threadIdMap[item.remoteId] = mappingId;
|
|
405
|
+
}
|
|
406
|
+
threadData[mappingId] = item;
|
|
407
|
+
if (item.remoteId === undefined) continue;
|
|
408
|
+
if (item.status === "regular" && !threadIds.includes(item.remoteId)) {
|
|
409
|
+
threadIds.push(item.remoteId);
|
|
410
|
+
} else if (
|
|
411
|
+
item.status === "archived" &&
|
|
412
|
+
!archivedThreadIds.includes(item.remoteId)
|
|
413
|
+
) {
|
|
414
|
+
archivedThreadIds.push(item.remoteId);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
this._staleThreadIdsOnReplace = undefined;
|
|
419
|
+
|
|
420
|
+
let nextState: RemoteThreadState = {
|
|
421
|
+
...state,
|
|
422
|
+
isLoading: false,
|
|
423
|
+
cursor,
|
|
424
|
+
threadIds,
|
|
425
|
+
archivedThreadIds,
|
|
426
|
+
threadIdMap,
|
|
427
|
+
threadData,
|
|
428
|
+
newThreadId:
|
|
429
|
+
state.newThreadId !== undefined &&
|
|
430
|
+
threadIdMap[state.newThreadId] === undefined
|
|
431
|
+
? undefined
|
|
432
|
+
: state.newThreadId,
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
if (getThreadData(nextState, this._mainThreadId) === undefined) {
|
|
436
|
+
const preservedDraft = nextState.newThreadId;
|
|
437
|
+
if (preservedDraft !== undefined) {
|
|
438
|
+
this._mainThreadId = preservedDraft;
|
|
439
|
+
} else {
|
|
440
|
+
const seeded = addNewThread(nextState);
|
|
441
|
+
this._mainThreadId = seeded.id;
|
|
442
|
+
nextState = seeded.state;
|
|
443
|
+
}
|
|
444
|
+
if (this._options.threadId === undefined) {
|
|
445
|
+
this._notifyThreadIdChange();
|
|
446
|
+
} else {
|
|
447
|
+
this._lastNotifiedThreadId = undefined;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const nextIds = new Set(
|
|
452
|
+
Object.values(nextState.threadData).map((item) => item.id),
|
|
453
|
+
);
|
|
454
|
+
for (const item of Object.values(state.threadData)) {
|
|
455
|
+
if (!nextIds.has(item.id)) {
|
|
456
|
+
this._hookManager.stopThreadRuntime(item.id);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
void this._hookManager.startThreadRuntime(this._mainThreadId).then(
|
|
460
|
+
() => this._notifySubscribers(),
|
|
461
|
+
() => undefined,
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
return nextState;
|
|
465
|
+
}
|
|
466
|
+
|
|
250
467
|
public __internal_load() {
|
|
251
468
|
this.getLoadThreadsPromise(); // begin loading on initial bind
|
|
252
469
|
if (this._initialThreadLoaded) return;
|
|
@@ -406,6 +623,12 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
406
623
|
generation: number,
|
|
407
624
|
emitThreadIdChange: boolean,
|
|
408
625
|
): Promise<void> {
|
|
626
|
+
if (
|
|
627
|
+
this._replaceListOnNextLoad &&
|
|
628
|
+
threadIdOrRemoteId !== this._state.value.newThreadId
|
|
629
|
+
) {
|
|
630
|
+
throw new ThreadListAdapterChangedError();
|
|
631
|
+
}
|
|
409
632
|
let data = this.getItemById(threadIdOrRemoteId);
|
|
410
633
|
|
|
411
634
|
if (!data) {
|
|
@@ -536,51 +759,35 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
536
759
|
if (generation !== this._switchGeneration) return;
|
|
537
760
|
}
|
|
538
761
|
|
|
539
|
-
const state = this._state.
|
|
762
|
+
const state = this._state.baseValue;
|
|
540
763
|
let id: string | undefined = this._state.value.newThreadId;
|
|
541
764
|
if (id === undefined) {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
const mappingId = createThreadMappingId(id);
|
|
547
|
-
this._state.update({
|
|
548
|
-
...state,
|
|
549
|
-
newThreadId: id,
|
|
550
|
-
threadIdMap: {
|
|
551
|
-
...state.threadIdMap,
|
|
552
|
-
[id]: mappingId,
|
|
553
|
-
},
|
|
554
|
-
threadData: {
|
|
555
|
-
...state.threadData,
|
|
556
|
-
[mappingId]: {
|
|
557
|
-
status: "new",
|
|
558
|
-
id,
|
|
559
|
-
remoteId: undefined,
|
|
560
|
-
externalId: undefined,
|
|
561
|
-
title: undefined,
|
|
562
|
-
custom: undefined,
|
|
563
|
-
} satisfies RemoteThreadData,
|
|
564
|
-
},
|
|
565
|
-
});
|
|
765
|
+
const next = addNewThread(state);
|
|
766
|
+
id = next.id;
|
|
767
|
+
this._state.update(next.state);
|
|
566
768
|
}
|
|
567
769
|
|
|
568
770
|
return this._switchToThread(id, undefined, generation, emitThreadIdChange);
|
|
569
771
|
}
|
|
570
772
|
|
|
571
773
|
public initialize = async (threadId: string) => {
|
|
774
|
+
const adapter = this._options.adapter;
|
|
775
|
+
const adapterGeneration = this._adapterGeneration;
|
|
572
776
|
if (this._state.value.newThreadId !== threadId) {
|
|
777
|
+
this._requireAdapterSettled();
|
|
573
778
|
const data = this.getItemById(threadId);
|
|
574
779
|
if (!data) throw threadNotFoundError(threadId, "initializing it");
|
|
575
780
|
if (data.status === "new")
|
|
576
781
|
throw threadStatusError(threadId, data.status, "be initialized here");
|
|
577
782
|
const { remoteId, externalId } = await data.initializeTask;
|
|
783
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
578
784
|
return { remoteId, externalId };
|
|
579
785
|
}
|
|
580
786
|
|
|
581
787
|
const { remoteId, externalId } = await this._state.optimisticUpdate({
|
|
582
788
|
execute: () => {
|
|
583
|
-
|
|
789
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
790
|
+
return adapter.initialize(threadId);
|
|
584
791
|
},
|
|
585
792
|
optimistic: (state) => {
|
|
586
793
|
return updateStatusReducer(state, threadId, "regular");
|
|
@@ -599,6 +806,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
599
806
|
};
|
|
600
807
|
},
|
|
601
808
|
then: (state, { remoteId, externalId }) => {
|
|
809
|
+
if (adapterGeneration !== this._adapterGeneration) return state;
|
|
602
810
|
const data = getThreadData(state, threadId);
|
|
603
811
|
if (!data) return state;
|
|
604
812
|
|
|
@@ -621,27 +829,33 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
621
829
|
};
|
|
622
830
|
},
|
|
623
831
|
});
|
|
832
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
624
833
|
return { remoteId, externalId };
|
|
625
834
|
};
|
|
626
835
|
|
|
627
836
|
public generateTitle = async (threadId: string) => {
|
|
837
|
+
this._requireAdapterSettled();
|
|
838
|
+
const adapter = this._options.adapter;
|
|
839
|
+
const adapterGeneration = this._adapterGeneration;
|
|
628
840
|
const data = this.getItemById(threadId);
|
|
629
841
|
if (!data) throw threadNotFoundError(threadId, "generating its title");
|
|
630
842
|
if (data.status === "new")
|
|
631
843
|
throw threadStatusError(threadId, data.status, "generate a title");
|
|
632
844
|
|
|
633
845
|
const { remoteId } = await data.initializeTask;
|
|
846
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
634
847
|
|
|
635
848
|
const runtimeCore = this._hookManager.getThreadRuntimeCore(data.id);
|
|
636
849
|
if (!runtimeCore) return; // thread is no longer running
|
|
637
850
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
);
|
|
851
|
+
// Incomplete assistant turns (running status, possibly empty content)
|
|
852
|
+
// would make the payload race-dependent; the title reads settled
|
|
853
|
+
// messages only, matching the trigger's readiness gate.
|
|
854
|
+
const messages = runtimeCore.messages.filter(isTitleSourceMessage);
|
|
855
|
+
const stream = await adapter.generateTitle(remoteId, messages);
|
|
643
856
|
const messageStream = AssistantMessageStream.fromAssistantStream(stream);
|
|
644
857
|
for await (const result of messageStream) {
|
|
858
|
+
if (adapterGeneration !== this._adapterGeneration) return;
|
|
645
859
|
const newTitle = result.parts.filter((c) => c.type === "text")[0]?.text;
|
|
646
860
|
const state = this._state.baseValue;
|
|
647
861
|
const currentData = getThreadData(state, data.id);
|
|
@@ -659,7 +873,13 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
659
873
|
}
|
|
660
874
|
};
|
|
661
875
|
|
|
662
|
-
public rename(
|
|
876
|
+
public async rename(
|
|
877
|
+
threadIdOrRemoteId: string,
|
|
878
|
+
newTitle: string,
|
|
879
|
+
): Promise<void> {
|
|
880
|
+
this._requireAdapterSettled();
|
|
881
|
+
const adapter = this._options.adapter;
|
|
882
|
+
const adapterGeneration = this._adapterGeneration;
|
|
663
883
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
664
884
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "renaming it");
|
|
665
885
|
if (data.status === "new")
|
|
@@ -668,7 +888,8 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
668
888
|
return this._state.optimisticUpdate({
|
|
669
889
|
execute: async () => {
|
|
670
890
|
const { remoteId } = await data.initializeTask;
|
|
671
|
-
|
|
891
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
892
|
+
return adapter.rename(remoteId, newTitle);
|
|
672
893
|
},
|
|
673
894
|
optimistic: (state) => {
|
|
674
895
|
const data = getThreadData(state, threadIdOrRemoteId);
|
|
@@ -688,10 +909,13 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
688
909
|
});
|
|
689
910
|
}
|
|
690
911
|
|
|
691
|
-
public updateCustom(
|
|
912
|
+
public async updateCustom(
|
|
692
913
|
threadIdOrRemoteId: string,
|
|
693
914
|
custom: Record<string, unknown> | undefined,
|
|
694
915
|
): Promise<void> {
|
|
916
|
+
this._requireAdapterSettled();
|
|
917
|
+
const adapter = this._options.adapter;
|
|
918
|
+
const adapterGeneration = this._adapterGeneration;
|
|
695
919
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
696
920
|
if (!data)
|
|
697
921
|
throw threadNotFoundError(
|
|
@@ -705,7 +929,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
705
929
|
"update custom metadata",
|
|
706
930
|
);
|
|
707
931
|
|
|
708
|
-
if (!
|
|
932
|
+
if (!adapter.updateCustom) {
|
|
709
933
|
throw new Error(
|
|
710
934
|
"Remote thread list adapter does not support updating custom metadata",
|
|
711
935
|
);
|
|
@@ -714,7 +938,7 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
714
938
|
return this._state.optimisticUpdate({
|
|
715
939
|
execute: async () => {
|
|
716
940
|
const { remoteId } = await data.initializeTask;
|
|
717
|
-
|
|
941
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
718
942
|
if (!adapter.updateCustom) {
|
|
719
943
|
throw new Error(
|
|
720
944
|
"Remote thread list adapter does not support updating custom metadata",
|
|
@@ -763,17 +987,22 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
763
987
|
}
|
|
764
988
|
|
|
765
989
|
public async archive(threadIdOrRemoteId: string) {
|
|
990
|
+
this._requireAdapterSettled();
|
|
991
|
+
const adapter = this._options.adapter;
|
|
992
|
+
const adapterGeneration = this._adapterGeneration;
|
|
766
993
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
767
994
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "archiving it");
|
|
768
995
|
if (data.status !== "regular")
|
|
769
996
|
throw threadStatusError(threadIdOrRemoteId, data.status, "be archived");
|
|
770
997
|
|
|
771
998
|
await this._ensureThreadIsNotMain(data.id);
|
|
999
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
772
1000
|
|
|
773
1001
|
return this._state.optimisticUpdate({
|
|
774
1002
|
execute: async () => {
|
|
775
1003
|
const { remoteId } = await data.initializeTask;
|
|
776
|
-
|
|
1004
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
1005
|
+
return adapter.archive(remoteId);
|
|
777
1006
|
},
|
|
778
1007
|
optimistic: (state) => {
|
|
779
1008
|
return updateStatusReducer(state, data.id, "archived");
|
|
@@ -781,7 +1010,10 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
781
1010
|
});
|
|
782
1011
|
}
|
|
783
1012
|
|
|
784
|
-
public unarchive(threadIdOrRemoteId: string): Promise<void> {
|
|
1013
|
+
public async unarchive(threadIdOrRemoteId: string): Promise<void> {
|
|
1014
|
+
this._requireAdapterSettled();
|
|
1015
|
+
const adapter = this._options.adapter;
|
|
1016
|
+
const adapterGeneration = this._adapterGeneration;
|
|
785
1017
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
786
1018
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "unarchiving it");
|
|
787
1019
|
if (data.status !== "archived")
|
|
@@ -791,9 +1023,12 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
791
1023
|
execute: async () => {
|
|
792
1024
|
try {
|
|
793
1025
|
const { remoteId } = await data.initializeTask;
|
|
794
|
-
|
|
1026
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
1027
|
+
return await adapter.unarchive(remoteId);
|
|
795
1028
|
} catch (error) {
|
|
796
|
-
|
|
1029
|
+
if (adapterGeneration === this._adapterGeneration) {
|
|
1030
|
+
await this._ensureThreadIsNotMain(data.id);
|
|
1031
|
+
}
|
|
797
1032
|
throw error;
|
|
798
1033
|
}
|
|
799
1034
|
},
|
|
@@ -804,18 +1039,23 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
804
1039
|
}
|
|
805
1040
|
|
|
806
1041
|
public async delete(threadIdOrRemoteId: string) {
|
|
1042
|
+
this._requireAdapterSettled();
|
|
1043
|
+
const adapter = this._options.adapter;
|
|
1044
|
+
const adapterGeneration = this._adapterGeneration;
|
|
807
1045
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
808
1046
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "deleting it");
|
|
809
1047
|
if (data.status !== "regular" && data.status !== "archived")
|
|
810
1048
|
throw threadStatusError(threadIdOrRemoteId, data.status, "be deleted");
|
|
811
1049
|
|
|
812
1050
|
await this._ensureThreadIsNotMain(data.id);
|
|
1051
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
813
1052
|
this._hookManager.stopThreadRuntime(data.id);
|
|
814
1053
|
|
|
815
1054
|
return this._state.optimisticUpdate({
|
|
816
1055
|
execute: async () => {
|
|
817
1056
|
const { remoteId } = await data.initializeTask;
|
|
818
|
-
|
|
1057
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
1058
|
+
return await adapter.delete(remoteId);
|
|
819
1059
|
},
|
|
820
1060
|
optimistic: (state) => {
|
|
821
1061
|
return updateStatusReducer(state, data.id, "deleted");
|
|
@@ -823,13 +1063,19 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
823
1063
|
});
|
|
824
1064
|
}
|
|
825
1065
|
|
|
1066
|
+
public __internal_dispose() {
|
|
1067
|
+
this._hookManager.__internal_dispose();
|
|
1068
|
+
}
|
|
1069
|
+
|
|
826
1070
|
public async detach(threadIdOrRemoteId: string): Promise<void> {
|
|
1071
|
+
const adapterGeneration = this._adapterGeneration;
|
|
827
1072
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
828
1073
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "detaching it");
|
|
829
1074
|
if (data.status !== "regular" && data.status !== "archived")
|
|
830
1075
|
throw threadStatusError(threadIdOrRemoteId, data.status, "be detached");
|
|
831
1076
|
|
|
832
1077
|
await this._ensureThreadIsNotMain(data.id);
|
|
1078
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
833
1079
|
this._hookManager.stopThreadRuntime(data.id);
|
|
834
1080
|
}
|
|
835
1081
|
|
|
@@ -846,18 +1092,16 @@ export class RemoteThreadListThreadListRuntimeCore
|
|
|
846
1092
|
|
|
847
1093
|
const boundIds = this.useBoundIds();
|
|
848
1094
|
const { Provider } = this.useProvider();
|
|
849
|
-
|
|
850
|
-
const
|
|
851
|
-
modelContext: this.contextProvider,
|
|
852
|
-
};
|
|
1095
|
+
const aui = useAui();
|
|
1096
|
+
const enabled = boundIds.length === 0 || boundIds[0] === id;
|
|
853
1097
|
|
|
854
1098
|
return (
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
<RuntimeAdapterProvider adapters={adapters}>
|
|
1099
|
+
enabled && (
|
|
1100
|
+
<RuntimeAdapterProvider adapters={this._runtimeAdapters}>
|
|
858
1101
|
<this._hookManager.__internal_RenderThreadRuntimes
|
|
859
1102
|
provider={Provider}
|
|
860
1103
|
/>
|
|
1104
|
+
<this._hookManager.__internal_Host parentClient={aui} />
|
|
861
1105
|
</RuntimeAdapterProvider>
|
|
862
1106
|
)
|
|
863
1107
|
);
|