@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
|
@@ -1,43 +1,102 @@
|
|
|
1
|
-
import { generateId } from "../../utils/id.js";
|
|
2
1
|
import { BaseSubscribable } from "../../subscribable/subscribable.js";
|
|
2
|
+
import { generateId } from "../../utils/id.js";
|
|
3
3
|
import { OptimisticState } from "../../runtimes/remote-thread-list/optimistic-state.js";
|
|
4
4
|
import { EMPTY_THREAD_CORE } from "../../runtimes/remote-thread-list/empty-thread-core.js";
|
|
5
5
|
import { classifyThreads, createThreadMappingId, getThreadData, normalizeCursor, updateStatusReducer } from "../../runtimes/remote-thread-list/remote-thread-state.js";
|
|
6
|
+
import { ThreadListAdapterChangedError } from "../../runtimes/remote-thread-list/adapter-changed.js";
|
|
7
|
+
import { useStableRuntimeAdapters } from "./useRuntimeAdapters.js";
|
|
6
8
|
import { RuntimeAdapterProvider } from "./RuntimeAdapterProvider.js";
|
|
9
|
+
import { isTitleSourceMessage } from "./RemoteThreadResource.js";
|
|
7
10
|
import { RemoteThreadListHookInstanceManager } from "./RemoteThreadListHookInstanceManager.js";
|
|
8
11
|
import { AssistantMessageStream } from "assistant-stream";
|
|
9
12
|
import { Fragment, useEffect, useId } from "@assistant-ui/tap/react-shim";
|
|
10
|
-
import {
|
|
13
|
+
import { useAui } from "@assistant-ui/store";
|
|
14
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
15
|
import { create } from "zustand";
|
|
12
16
|
//#region src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx
|
|
13
|
-
const asProviderComponent = (provider) => provider ?? Fragment;
|
|
14
17
|
const threadNotFoundError = (threadIdOrRemoteId, action) => /* @__PURE__ */ new Error(`Thread "${threadIdOrRemoteId}" not found while ${action}.`);
|
|
15
18
|
const threadStatusError = (threadIdOrRemoteId, status, action) => /* @__PURE__ */ new Error(`Thread "${threadIdOrRemoteId}" has status "${status}", so it cannot ${action}.`);
|
|
19
|
+
const EMPTY_REMOTE_STATE = {
|
|
20
|
+
isLoading: true,
|
|
21
|
+
isLoadingMore: false,
|
|
22
|
+
cursor: void 0,
|
|
23
|
+
newThreadId: void 0,
|
|
24
|
+
threadIds: [],
|
|
25
|
+
archivedThreadIds: [],
|
|
26
|
+
threadIdMap: {},
|
|
27
|
+
threadData: {}
|
|
28
|
+
};
|
|
29
|
+
const addNewThread = (state) => {
|
|
30
|
+
let id;
|
|
31
|
+
do
|
|
32
|
+
id = `__LOCALID_${generateId()}`;
|
|
33
|
+
while (state.threadIdMap[id]);
|
|
34
|
+
const mappingId = createThreadMappingId(id);
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
state: {
|
|
38
|
+
...state,
|
|
39
|
+
newThreadId: id,
|
|
40
|
+
threadIdMap: {
|
|
41
|
+
...state.threadIdMap,
|
|
42
|
+
[id]: mappingId
|
|
43
|
+
},
|
|
44
|
+
threadData: {
|
|
45
|
+
...state.threadData,
|
|
46
|
+
[mappingId]: {
|
|
47
|
+
status: "new",
|
|
48
|
+
id,
|
|
49
|
+
remoteId: void 0,
|
|
50
|
+
externalId: void 0,
|
|
51
|
+
title: void 0,
|
|
52
|
+
custom: void 0
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
16
58
|
var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
17
59
|
_options;
|
|
18
60
|
_hookManager;
|
|
61
|
+
_runtimeAdapters;
|
|
19
62
|
_loadThreadsPromise;
|
|
20
63
|
_loadMorePromise;
|
|
21
64
|
_loadGeneration = 0;
|
|
65
|
+
_adapterGeneration = 0;
|
|
66
|
+
_replaceListOnNextLoad = false;
|
|
67
|
+
_staleThreadIdsOnReplace;
|
|
22
68
|
_switchGeneration = 0;
|
|
23
69
|
_switchTask;
|
|
24
70
|
_mainThreadId;
|
|
25
|
-
_state = new OptimisticState(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})
|
|
71
|
+
_state = new OptimisticState(EMPTY_REMOTE_STATE);
|
|
72
|
+
_useAdaptersProvider = ({ children }) => {
|
|
73
|
+
const useAdapters = this._options.adapter.unstable_useAdapters;
|
|
74
|
+
if (useAdapters === void 0) return children;
|
|
75
|
+
return /* @__PURE__ */ jsx(this._SynthesizedAdapters, {
|
|
76
|
+
useAdapters,
|
|
77
|
+
children
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
_SynthesizedAdapters = ({ useAdapters, children }) => {
|
|
81
|
+
const adapters = useStableRuntimeAdapters(useAdapters());
|
|
82
|
+
if (adapters == null) return children;
|
|
83
|
+
return /* @__PURE__ */ jsx(RuntimeAdapterProvider, {
|
|
84
|
+
adapters,
|
|
85
|
+
children
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
resolveProvider(adapter) {
|
|
89
|
+
if (adapter.unstable_Provider !== void 0) return adapter.unstable_Provider;
|
|
90
|
+
if (adapter.unstable_useAdapters === void 0) return Fragment;
|
|
91
|
+
return this._useAdaptersProvider;
|
|
92
|
+
}
|
|
35
93
|
get threadItems() {
|
|
36
94
|
return this._state.value.threadData;
|
|
37
95
|
}
|
|
38
96
|
getLoadThreadsPromise() {
|
|
39
97
|
if (!this._loadThreadsPromise) {
|
|
40
98
|
const generation = this._loadGeneration;
|
|
99
|
+
let replacedList = false;
|
|
41
100
|
this._loadThreadsPromise = this._state.optimisticUpdate({
|
|
42
101
|
execute: () => this._options.adapter.list(),
|
|
43
102
|
loading: (state) => {
|
|
@@ -48,6 +107,11 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
48
107
|
},
|
|
49
108
|
then: (state, l) => {
|
|
50
109
|
if (generation !== this._loadGeneration) return state;
|
|
110
|
+
if (this._replaceListOnNextLoad) {
|
|
111
|
+
this._replaceListOnNextLoad = false;
|
|
112
|
+
replacedList = true;
|
|
113
|
+
return this._replaceWithThreads(state, l.threads, normalizeCursor(l.nextCursor));
|
|
114
|
+
}
|
|
51
115
|
const fresh = classifyThreads(l.threads, {
|
|
52
116
|
threadIds: [],
|
|
53
117
|
archivedThreadIds: [],
|
|
@@ -74,11 +138,23 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
74
138
|
if (generation !== this._loadGeneration) return;
|
|
75
139
|
console.error("[assistant-ui] thread list load failed:", error);
|
|
76
140
|
this._loadThreadsPromise = void 0;
|
|
77
|
-
this.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
141
|
+
if (!this._replaceListOnNextLoad) {
|
|
142
|
+
this._state.update({
|
|
143
|
+
...this._state.baseValue,
|
|
144
|
+
isLoading: false
|
|
145
|
+
});
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
this._replaceListOnNextLoad = false;
|
|
149
|
+
replacedList = true;
|
|
150
|
+
this._state.update(this._replaceWithThreads(this._state.baseValue, [], void 0));
|
|
151
|
+
}).then(() => {
|
|
152
|
+
if (!replacedList) return;
|
|
153
|
+
const threadId = this._options.threadId;
|
|
154
|
+
if (threadId === void 0) return;
|
|
155
|
+
if (this.getItemById(threadId)?.id === this._mainThreadId) return;
|
|
156
|
+
this._switchToThreadFromProp(threadId).catch(() => {});
|
|
157
|
+
});
|
|
82
158
|
}
|
|
83
159
|
return this._loadThreadsPromise;
|
|
84
160
|
}
|
|
@@ -115,6 +191,7 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
115
191
|
};
|
|
116
192
|
}
|
|
117
193
|
}).catch((error) => {
|
|
194
|
+
if (generation !== this._loadGeneration) return;
|
|
118
195
|
console.error("[assistant-ui] thread list loadMore failed:", error);
|
|
119
196
|
}).then(() => {
|
|
120
197
|
if (this._loadMorePromise === dedup) this._loadMorePromise = void 0;
|
|
@@ -122,17 +199,20 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
122
199
|
this._loadMorePromise = dedup;
|
|
123
200
|
return dedup;
|
|
124
201
|
}
|
|
125
|
-
contextProvider;
|
|
126
202
|
constructor(options, contextProvider) {
|
|
127
203
|
super();
|
|
128
|
-
this.contextProvider = contextProvider;
|
|
129
204
|
this._state.subscribe(() => {
|
|
130
205
|
this._notifySubscribers();
|
|
131
206
|
this._notifyThreadIdChange();
|
|
132
207
|
});
|
|
208
|
+
this._runtimeAdapters = { modelContext: contextProvider };
|
|
133
209
|
this._hookManager = new RemoteThreadListHookInstanceManager(options.runtimeHook, this);
|
|
210
|
+
this._hookManager.__internal_setDefaultAdapters(this._runtimeAdapters);
|
|
134
211
|
this._hookManager.__internal_subscribeRunningChanged(() => this._notifySubscribers());
|
|
135
|
-
this.
|
|
212
|
+
this._hookManager.__internal_subscribeRuntimeReplaced(() => {
|
|
213
|
+
queueMicrotask(() => this._notifySubscribers());
|
|
214
|
+
});
|
|
215
|
+
this.useProvider = create(() => ({ Provider: this.resolveProvider(options.adapter) }));
|
|
136
216
|
this.__internal_setOptions(options);
|
|
137
217
|
this.switchToNewThread();
|
|
138
218
|
}
|
|
@@ -143,13 +223,18 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
143
223
|
const adapterChanged = this._options !== void 0 && this._options.adapter !== options.adapter;
|
|
144
224
|
const controlledThreadIdChanged = this._initialThreadLoaded && this._options !== void 0 && this._options.threadId !== options.threadId;
|
|
145
225
|
this._options = options;
|
|
146
|
-
const Provider =
|
|
226
|
+
const Provider = this.resolveProvider(options.adapter);
|
|
147
227
|
if (Provider !== this.useProvider.getState().Provider) this.useProvider.setState({ Provider }, true);
|
|
148
228
|
this._hookManager.setRuntimeHook(options.runtimeHook);
|
|
149
229
|
if (adapterChanged) {
|
|
150
230
|
this._loadGeneration++;
|
|
231
|
+
this._adapterGeneration++;
|
|
232
|
+
this._switchGeneration++;
|
|
233
|
+
this._switchTask = void 0;
|
|
151
234
|
this._loadThreadsPromise = void 0;
|
|
152
235
|
this._loadMorePromise = void 0;
|
|
236
|
+
this._replaceListOnNextLoad = true;
|
|
237
|
+
this._staleThreadIdsOnReplace = new Set(Object.values(this._state.baseValue.threadData).filter((item) => item.status !== "new").map((item) => item.id));
|
|
153
238
|
this._state.update({
|
|
154
239
|
...this._state.baseValue,
|
|
155
240
|
cursor: void 0
|
|
@@ -157,6 +242,71 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
157
242
|
}
|
|
158
243
|
if (controlledThreadIdChanged) this._switchToThreadFromProp(options.threadId).catch(() => {});
|
|
159
244
|
}
|
|
245
|
+
_requireAdapterGeneration(generation) {
|
|
246
|
+
if (generation !== this._adapterGeneration) throw new ThreadListAdapterChangedError();
|
|
247
|
+
}
|
|
248
|
+
_requireAdapterSettled() {
|
|
249
|
+
if (this._replaceListOnNextLoad) throw new ThreadListAdapterChangedError();
|
|
250
|
+
}
|
|
251
|
+
_replaceWithThreads(state, threads, cursor) {
|
|
252
|
+
const fresh = classifyThreads(threads, {
|
|
253
|
+
threadIds: [],
|
|
254
|
+
archivedThreadIds: [],
|
|
255
|
+
threadIdMap: {},
|
|
256
|
+
threadData: {}
|
|
257
|
+
});
|
|
258
|
+
const threadIdMap = { ...fresh.threadIdMap };
|
|
259
|
+
const threadData = { ...fresh.threadData };
|
|
260
|
+
const threadIds = [...fresh.threadIds];
|
|
261
|
+
const archivedThreadIds = [...fresh.archivedThreadIds];
|
|
262
|
+
if (state.newThreadId) {
|
|
263
|
+
const mappingId = state.threadIdMap[state.newThreadId];
|
|
264
|
+
const draft = mappingId ? state.threadData[mappingId] : void 0;
|
|
265
|
+
if (draft?.status === "new") {
|
|
266
|
+
threadIdMap[state.newThreadId] = mappingId;
|
|
267
|
+
threadData[mappingId] = draft;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const stale = this._staleThreadIdsOnReplace;
|
|
271
|
+
if (stale) for (const item of Object.values(state.threadData)) {
|
|
272
|
+
if (stale.has(item.id)) continue;
|
|
273
|
+
if (item.status !== "new" && item.remoteId === void 0) continue;
|
|
274
|
+
const mappingId = createThreadMappingId(item.id);
|
|
275
|
+
if (threadData[mappingId]) continue;
|
|
276
|
+
threadIdMap[item.id] = mappingId;
|
|
277
|
+
if (item.remoteId !== void 0) threadIdMap[item.remoteId] = mappingId;
|
|
278
|
+
threadData[mappingId] = item;
|
|
279
|
+
if (item.remoteId === void 0) continue;
|
|
280
|
+
if (item.status === "regular" && !threadIds.includes(item.remoteId)) threadIds.push(item.remoteId);
|
|
281
|
+
else if (item.status === "archived" && !archivedThreadIds.includes(item.remoteId)) archivedThreadIds.push(item.remoteId);
|
|
282
|
+
}
|
|
283
|
+
this._staleThreadIdsOnReplace = void 0;
|
|
284
|
+
let nextState = {
|
|
285
|
+
...state,
|
|
286
|
+
isLoading: false,
|
|
287
|
+
cursor,
|
|
288
|
+
threadIds,
|
|
289
|
+
archivedThreadIds,
|
|
290
|
+
threadIdMap,
|
|
291
|
+
threadData,
|
|
292
|
+
newThreadId: state.newThreadId !== void 0 && threadIdMap[state.newThreadId] === void 0 ? void 0 : state.newThreadId
|
|
293
|
+
};
|
|
294
|
+
if (getThreadData(nextState, this._mainThreadId) === void 0) {
|
|
295
|
+
const preservedDraft = nextState.newThreadId;
|
|
296
|
+
if (preservedDraft !== void 0) this._mainThreadId = preservedDraft;
|
|
297
|
+
else {
|
|
298
|
+
const seeded = addNewThread(nextState);
|
|
299
|
+
this._mainThreadId = seeded.id;
|
|
300
|
+
nextState = seeded.state;
|
|
301
|
+
}
|
|
302
|
+
if (this._options.threadId === void 0) this._notifyThreadIdChange();
|
|
303
|
+
else this._lastNotifiedThreadId = void 0;
|
|
304
|
+
}
|
|
305
|
+
const nextIds = new Set(Object.values(nextState.threadData).map((item) => item.id));
|
|
306
|
+
for (const item of Object.values(state.threadData)) if (!nextIds.has(item.id)) this._hookManager.stopThreadRuntime(item.id);
|
|
307
|
+
this._hookManager.startThreadRuntime(this._mainThreadId).then(() => this._notifySubscribers(), () => void 0);
|
|
308
|
+
return nextState;
|
|
309
|
+
}
|
|
160
310
|
__internal_load() {
|
|
161
311
|
this.getLoadThreadsPromise();
|
|
162
312
|
if (this._initialThreadLoaded) return;
|
|
@@ -251,6 +401,7 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
251
401
|
return task;
|
|
252
402
|
}
|
|
253
403
|
async _switchToThread(threadIdOrRemoteId, options, generation, emitThreadIdChange) {
|
|
404
|
+
if (this._replaceListOnNextLoad && threadIdOrRemoteId !== this._state.value.newThreadId) throw new ThreadListAdapterChangedError();
|
|
254
405
|
let data = this.getItemById(threadIdOrRemoteId);
|
|
255
406
|
if (!data) {
|
|
256
407
|
const remoteMetadata = await this._options.adapter.fetch(threadIdOrRemoteId);
|
|
@@ -323,41 +474,25 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
323
474
|
await this._state.waitForUpdate();
|
|
324
475
|
if (generation !== this._switchGeneration) return;
|
|
325
476
|
}
|
|
326
|
-
const state = this._state.
|
|
477
|
+
const state = this._state.baseValue;
|
|
327
478
|
let id = this._state.value.newThreadId;
|
|
328
479
|
if (id === void 0) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const mappingId = createThreadMappingId(id);
|
|
333
|
-
this._state.update({
|
|
334
|
-
...state,
|
|
335
|
-
newThreadId: id,
|
|
336
|
-
threadIdMap: {
|
|
337
|
-
...state.threadIdMap,
|
|
338
|
-
[id]: mappingId
|
|
339
|
-
},
|
|
340
|
-
threadData: {
|
|
341
|
-
...state.threadData,
|
|
342
|
-
[mappingId]: {
|
|
343
|
-
status: "new",
|
|
344
|
-
id,
|
|
345
|
-
remoteId: void 0,
|
|
346
|
-
externalId: void 0,
|
|
347
|
-
title: void 0,
|
|
348
|
-
custom: void 0
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
});
|
|
480
|
+
const next = addNewThread(state);
|
|
481
|
+
id = next.id;
|
|
482
|
+
this._state.update(next.state);
|
|
352
483
|
}
|
|
353
484
|
return this._switchToThread(id, void 0, generation, emitThreadIdChange);
|
|
354
485
|
}
|
|
355
486
|
initialize = async (threadId) => {
|
|
487
|
+
const adapter = this._options.adapter;
|
|
488
|
+
const adapterGeneration = this._adapterGeneration;
|
|
356
489
|
if (this._state.value.newThreadId !== threadId) {
|
|
490
|
+
this._requireAdapterSettled();
|
|
357
491
|
const data = this.getItemById(threadId);
|
|
358
492
|
if (!data) throw threadNotFoundError(threadId, "initializing it");
|
|
359
493
|
if (data.status === "new") throw threadStatusError(threadId, data.status, "be initialized here");
|
|
360
494
|
const { remoteId, externalId } = await data.initializeTask;
|
|
495
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
361
496
|
return {
|
|
362
497
|
remoteId,
|
|
363
498
|
externalId
|
|
@@ -365,7 +500,8 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
365
500
|
}
|
|
366
501
|
const { remoteId, externalId } = await this._state.optimisticUpdate({
|
|
367
502
|
execute: () => {
|
|
368
|
-
|
|
503
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
504
|
+
return adapter.initialize(threadId);
|
|
369
505
|
},
|
|
370
506
|
optimistic: (state) => {
|
|
371
507
|
return updateStatusReducer(state, threadId, "regular");
|
|
@@ -384,6 +520,7 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
384
520
|
};
|
|
385
521
|
},
|
|
386
522
|
then: (state, { remoteId, externalId }) => {
|
|
523
|
+
if (adapterGeneration !== this._adapterGeneration) return state;
|
|
387
524
|
const data = getThreadData(state, threadId);
|
|
388
525
|
if (!data) return state;
|
|
389
526
|
const mappingId = createThreadMappingId(threadId);
|
|
@@ -408,22 +545,28 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
408
545
|
};
|
|
409
546
|
}
|
|
410
547
|
});
|
|
548
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
411
549
|
return {
|
|
412
550
|
remoteId,
|
|
413
551
|
externalId
|
|
414
552
|
};
|
|
415
553
|
};
|
|
416
554
|
generateTitle = async (threadId) => {
|
|
555
|
+
this._requireAdapterSettled();
|
|
556
|
+
const adapter = this._options.adapter;
|
|
557
|
+
const adapterGeneration = this._adapterGeneration;
|
|
417
558
|
const data = this.getItemById(threadId);
|
|
418
559
|
if (!data) throw threadNotFoundError(threadId, "generating its title");
|
|
419
560
|
if (data.status === "new") throw threadStatusError(threadId, data.status, "generate a title");
|
|
420
561
|
const { remoteId } = await data.initializeTask;
|
|
562
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
421
563
|
const runtimeCore = this._hookManager.getThreadRuntimeCore(data.id);
|
|
422
564
|
if (!runtimeCore) return;
|
|
423
|
-
const messages = runtimeCore.messages;
|
|
424
|
-
const stream = await
|
|
565
|
+
const messages = runtimeCore.messages.filter(isTitleSourceMessage);
|
|
566
|
+
const stream = await adapter.generateTitle(remoteId, messages);
|
|
425
567
|
const messageStream = AssistantMessageStream.fromAssistantStream(stream);
|
|
426
568
|
for await (const result of messageStream) {
|
|
569
|
+
if (adapterGeneration !== this._adapterGeneration) return;
|
|
427
570
|
const newTitle = result.parts.filter((c) => c.type === "text")[0]?.text;
|
|
428
571
|
const state = this._state.baseValue;
|
|
429
572
|
const currentData = getThreadData(state, data.id);
|
|
@@ -440,14 +583,18 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
440
583
|
});
|
|
441
584
|
}
|
|
442
585
|
};
|
|
443
|
-
rename(threadIdOrRemoteId, newTitle) {
|
|
586
|
+
async rename(threadIdOrRemoteId, newTitle) {
|
|
587
|
+
this._requireAdapterSettled();
|
|
588
|
+
const adapter = this._options.adapter;
|
|
589
|
+
const adapterGeneration = this._adapterGeneration;
|
|
444
590
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
445
591
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "renaming it");
|
|
446
592
|
if (data.status === "new") throw threadStatusError(threadIdOrRemoteId, data.status, "be renamed");
|
|
447
593
|
return this._state.optimisticUpdate({
|
|
448
594
|
execute: async () => {
|
|
449
595
|
const { remoteId } = await data.initializeTask;
|
|
450
|
-
|
|
596
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
597
|
+
return adapter.rename(remoteId, newTitle);
|
|
451
598
|
},
|
|
452
599
|
optimistic: (state) => {
|
|
453
600
|
const data = getThreadData(state, threadIdOrRemoteId);
|
|
@@ -465,15 +612,18 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
465
612
|
}
|
|
466
613
|
});
|
|
467
614
|
}
|
|
468
|
-
updateCustom(threadIdOrRemoteId, custom) {
|
|
615
|
+
async updateCustom(threadIdOrRemoteId, custom) {
|
|
616
|
+
this._requireAdapterSettled();
|
|
617
|
+
const adapter = this._options.adapter;
|
|
618
|
+
const adapterGeneration = this._adapterGeneration;
|
|
469
619
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
470
620
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "updating its custom metadata");
|
|
471
621
|
if (data.status === "new") throw threadStatusError(threadIdOrRemoteId, data.status, "update custom metadata");
|
|
472
|
-
if (!
|
|
622
|
+
if (!adapter.updateCustom) throw new Error("Remote thread list adapter does not support updating custom metadata");
|
|
473
623
|
return this._state.optimisticUpdate({
|
|
474
624
|
execute: async () => {
|
|
475
625
|
const { remoteId } = await data.initializeTask;
|
|
476
|
-
|
|
626
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
477
627
|
if (!adapter.updateCustom) throw new Error("Remote thread list adapter does not support updating custom metadata");
|
|
478
628
|
return adapter.updateCustom(remoteId, custom);
|
|
479
629
|
},
|
|
@@ -509,21 +659,29 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
509
659
|
}
|
|
510
660
|
}
|
|
511
661
|
async archive(threadIdOrRemoteId) {
|
|
662
|
+
this._requireAdapterSettled();
|
|
663
|
+
const adapter = this._options.adapter;
|
|
664
|
+
const adapterGeneration = this._adapterGeneration;
|
|
512
665
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
513
666
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "archiving it");
|
|
514
667
|
if (data.status !== "regular") throw threadStatusError(threadIdOrRemoteId, data.status, "be archived");
|
|
515
668
|
await this._ensureThreadIsNotMain(data.id);
|
|
669
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
516
670
|
return this._state.optimisticUpdate({
|
|
517
671
|
execute: async () => {
|
|
518
672
|
const { remoteId } = await data.initializeTask;
|
|
519
|
-
|
|
673
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
674
|
+
return adapter.archive(remoteId);
|
|
520
675
|
},
|
|
521
676
|
optimistic: (state) => {
|
|
522
677
|
return updateStatusReducer(state, data.id, "archived");
|
|
523
678
|
}
|
|
524
679
|
});
|
|
525
680
|
}
|
|
526
|
-
unarchive(threadIdOrRemoteId) {
|
|
681
|
+
async unarchive(threadIdOrRemoteId) {
|
|
682
|
+
this._requireAdapterSettled();
|
|
683
|
+
const adapter = this._options.adapter;
|
|
684
|
+
const adapterGeneration = this._adapterGeneration;
|
|
527
685
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
528
686
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "unarchiving it");
|
|
529
687
|
if (data.status !== "archived") throw threadStatusError(threadIdOrRemoteId, data.status, "be unarchived");
|
|
@@ -531,9 +689,10 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
531
689
|
execute: async () => {
|
|
532
690
|
try {
|
|
533
691
|
const { remoteId } = await data.initializeTask;
|
|
534
|
-
|
|
692
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
693
|
+
return await adapter.unarchive(remoteId);
|
|
535
694
|
} catch (error) {
|
|
536
|
-
await this._ensureThreadIsNotMain(data.id);
|
|
695
|
+
if (adapterGeneration === this._adapterGeneration) await this._ensureThreadIsNotMain(data.id);
|
|
537
696
|
throw error;
|
|
538
697
|
}
|
|
539
698
|
},
|
|
@@ -543,26 +702,36 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
543
702
|
});
|
|
544
703
|
}
|
|
545
704
|
async delete(threadIdOrRemoteId) {
|
|
705
|
+
this._requireAdapterSettled();
|
|
706
|
+
const adapter = this._options.adapter;
|
|
707
|
+
const adapterGeneration = this._adapterGeneration;
|
|
546
708
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
547
709
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "deleting it");
|
|
548
710
|
if (data.status !== "regular" && data.status !== "archived") throw threadStatusError(threadIdOrRemoteId, data.status, "be deleted");
|
|
549
711
|
await this._ensureThreadIsNotMain(data.id);
|
|
712
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
550
713
|
this._hookManager.stopThreadRuntime(data.id);
|
|
551
714
|
return this._state.optimisticUpdate({
|
|
552
715
|
execute: async () => {
|
|
553
716
|
const { remoteId } = await data.initializeTask;
|
|
554
|
-
|
|
717
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
718
|
+
return await adapter.delete(remoteId);
|
|
555
719
|
},
|
|
556
720
|
optimistic: (state) => {
|
|
557
721
|
return updateStatusReducer(state, data.id, "deleted");
|
|
558
722
|
}
|
|
559
723
|
});
|
|
560
724
|
}
|
|
725
|
+
__internal_dispose() {
|
|
726
|
+
this._hookManager.__internal_dispose();
|
|
727
|
+
}
|
|
561
728
|
async detach(threadIdOrRemoteId) {
|
|
729
|
+
const adapterGeneration = this._adapterGeneration;
|
|
562
730
|
const data = this.getItemById(threadIdOrRemoteId);
|
|
563
731
|
if (!data) throw threadNotFoundError(threadIdOrRemoteId, "detaching it");
|
|
564
732
|
if (data.status !== "regular" && data.status !== "archived") throw threadStatusError(threadIdOrRemoteId, data.status, "be detached");
|
|
565
733
|
await this._ensureThreadIsNotMain(data.id);
|
|
734
|
+
this._requireAdapterGeneration(adapterGeneration);
|
|
566
735
|
this._hookManager.stopThreadRuntime(data.id);
|
|
567
736
|
}
|
|
568
737
|
useBoundIds = create(() => []);
|
|
@@ -576,10 +745,10 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
576
745
|
}, [id]);
|
|
577
746
|
const boundIds = this.useBoundIds();
|
|
578
747
|
const { Provider } = this.useProvider();
|
|
579
|
-
const
|
|
580
|
-
return (boundIds.length === 0 || boundIds[0] === id) && /* @__PURE__ */
|
|
581
|
-
adapters,
|
|
582
|
-
children: /* @__PURE__ */ jsx(this._hookManager.__internal_RenderThreadRuntimes, { provider: Provider })
|
|
748
|
+
const aui = useAui();
|
|
749
|
+
return (boundIds.length === 0 || boundIds[0] === id) && /* @__PURE__ */ jsxs(RuntimeAdapterProvider, {
|
|
750
|
+
adapters: this._runtimeAdapters,
|
|
751
|
+
children: [/* @__PURE__ */ jsx(this._hookManager.__internal_RenderThreadRuntimes, { provider: Provider }), /* @__PURE__ */ jsx(this._hookManager.__internal_Host, { parentClient: aui })]
|
|
583
752
|
});
|
|
584
753
|
};
|
|
585
754
|
};
|