@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,44 +1,53 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type FC,
|
|
3
3
|
type RefObject,
|
|
4
|
-
useCallback,
|
|
5
|
-
useRef,
|
|
6
4
|
useEffect,
|
|
7
|
-
useEffectEvent,
|
|
8
5
|
useLayoutEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
9
8
|
memo,
|
|
10
9
|
type PropsWithChildren,
|
|
11
10
|
type ComponentType,
|
|
12
|
-
useMemo,
|
|
13
11
|
Fragment,
|
|
14
12
|
} from "react";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
13
|
+
import { create } from "zustand";
|
|
14
|
+
import { useResources, withKey } from "@assistant-ui/tap";
|
|
15
|
+
import type { AssistantClient } from "@assistant-ui/store";
|
|
17
16
|
import { ThreadListItemRuntimeProvider } from "../providers/ThreadListItemRuntimeProvider";
|
|
18
17
|
import type { ThreadRuntimeCore } from "../../runtime/interfaces/thread-runtime-core";
|
|
19
18
|
import type { ThreadListRuntimeCore } from "../../runtime/interfaces/thread-list-runtime-core";
|
|
20
|
-
import type { AssistantRuntime } from "../../runtime/api/assistant-runtime";
|
|
21
19
|
import type { Unsubscribe } from "../../types/unsubscribe";
|
|
22
20
|
import { BaseSubscribable } from "../../subscribable/subscribable";
|
|
23
|
-
import {
|
|
24
|
-
getThreadRuntimeCoreIsRunning,
|
|
25
|
-
type ThreadRuntimeImpl,
|
|
26
|
-
} from "../../runtime/api/thread-runtime";
|
|
21
|
+
import { getThreadRuntimeCoreIsRunning } from "../../runtime/api/thread-runtime";
|
|
27
22
|
import { ThreadListRuntimeImpl } from "../../runtime/api/thread-list-runtime";
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
import { invalidateThreadRuntime } from "../../runtime/utils/thread-runtime-lifecycle";
|
|
24
|
+
import {
|
|
25
|
+
useRuntimeAdapters,
|
|
26
|
+
type RuntimeAdapters,
|
|
27
|
+
} from "./RuntimeAdapterProvider";
|
|
28
|
+
import {
|
|
29
|
+
RemoteThreadResource,
|
|
30
|
+
type RemoteThreadListHook,
|
|
31
|
+
} from "./RemoteThreadResource";
|
|
30
32
|
|
|
31
33
|
type RemoteThreadListHookInstance = {
|
|
32
34
|
runtime?: ThreadRuntimeCore | undefined;
|
|
33
|
-
// A runtime riding across a restart stays readable, but only counts as
|
|
34
|
-
// attached once a binder of the current generation re-publishes it.
|
|
35
35
|
publishedGeneration?: number | undefined;
|
|
36
|
-
// Part of the binder's React key, so only a bump remounts the hook.
|
|
37
36
|
generation: number;
|
|
38
37
|
isRunning: boolean;
|
|
39
38
|
unsubscribeRunning?: Unsubscribe | undefined;
|
|
40
39
|
};
|
|
41
40
|
|
|
41
|
+
type AdapterSnapshot = {
|
|
42
|
+
defaultAdapters: RuntimeAdapters | null;
|
|
43
|
+
threadAdapters: ReadonlyMap<string, RuntimeAdapters | null>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type HostSnapshot = {
|
|
47
|
+
threads: readonly { id: string; generation: number }[];
|
|
48
|
+
hookEpoch: number;
|
|
49
|
+
};
|
|
50
|
+
|
|
42
51
|
const ProviderRenderDetector: FC<{
|
|
43
52
|
detectorRef: RefObject<boolean>;
|
|
44
53
|
}> = ({ detectorRef }) => {
|
|
@@ -47,15 +56,23 @@ const ProviderRenderDetector: FC<{
|
|
|
47
56
|
}, [detectorRef]);
|
|
48
57
|
return null;
|
|
49
58
|
};
|
|
59
|
+
|
|
50
60
|
export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
51
|
-
private
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
private runtimeHook: RemoteThreadListHook;
|
|
62
|
+
private readonly adapterStore = create<AdapterSnapshot>(() => ({
|
|
63
|
+
defaultAdapters: null,
|
|
64
|
+
threadAdapters: new Map(),
|
|
65
|
+
}));
|
|
66
|
+
private readonly hostStore = create<HostSnapshot>(() => ({
|
|
67
|
+
threads: [],
|
|
68
|
+
hookEpoch: 0,
|
|
69
|
+
}));
|
|
70
|
+
private readonly pendingThreadAdapters = new Map<
|
|
71
|
+
string,
|
|
72
|
+
RuntimeAdapters | null
|
|
73
|
+
>();
|
|
54
74
|
private instances = new Map<string, RemoteThreadListHookInstance>();
|
|
55
|
-
// Manager-wide so it survives instance deletion: a stop and start within one
|
|
56
|
-
// React commit must not reuse a binder key.
|
|
57
75
|
private nextGeneration = 0;
|
|
58
|
-
private useAliveThreadsKeysChanged = create(() => ({}));
|
|
59
76
|
private parent: ThreadListRuntimeCore;
|
|
60
77
|
|
|
61
78
|
constructor(
|
|
@@ -64,7 +81,7 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
64
81
|
) {
|
|
65
82
|
super();
|
|
66
83
|
this.parent = parent;
|
|
67
|
-
this.
|
|
84
|
+
this.runtimeHook = runtimeHook;
|
|
68
85
|
}
|
|
69
86
|
|
|
70
87
|
private _whenRuntimeAttached(threadId: string) {
|
|
@@ -78,7 +95,7 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
78
95
|
!instance.runtime ||
|
|
79
96
|
instance.publishedGeneration !== instance.generation
|
|
80
97
|
) {
|
|
81
|
-
return;
|
|
98
|
+
return;
|
|
82
99
|
} else {
|
|
83
100
|
dispose();
|
|
84
101
|
resolve(instance.runtime);
|
|
@@ -91,11 +108,12 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
91
108
|
|
|
92
109
|
public startThreadRuntime(threadId: string) {
|
|
93
110
|
if (!this.instances.has(threadId)) {
|
|
111
|
+
const generation = this.nextGeneration++;
|
|
94
112
|
this.instances.set(threadId, {
|
|
95
|
-
generation
|
|
113
|
+
generation,
|
|
96
114
|
isRunning: false,
|
|
97
115
|
});
|
|
98
|
-
this.
|
|
116
|
+
this._syncHostThreads();
|
|
99
117
|
}
|
|
100
118
|
|
|
101
119
|
return this._whenRuntimeAttached(threadId);
|
|
@@ -105,8 +123,9 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
105
123
|
const instance = this.instances.get(threadId);
|
|
106
124
|
if (!instance) return this.startThreadRuntime(threadId);
|
|
107
125
|
|
|
126
|
+
if (instance.runtime) invalidateThreadRuntime(instance.runtime);
|
|
108
127
|
instance.generation = this.nextGeneration++;
|
|
109
|
-
this.
|
|
128
|
+
this._syncHostThreads();
|
|
110
129
|
this._notifySubscribers();
|
|
111
130
|
|
|
112
131
|
return this._whenRuntimeAttached(threadId);
|
|
@@ -124,29 +143,27 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
124
143
|
|
|
125
144
|
private runningSubscribers = new Set<() => void>();
|
|
126
145
|
|
|
127
|
-
/**
|
|
128
|
-
* Fires when any thread crosses the running boundary. Separate from the
|
|
129
|
-
* general subscription so a run does not push the thread list through the
|
|
130
|
-
* channel that resolves pending runtime attachments.
|
|
131
|
-
*/
|
|
132
146
|
public __internal_subscribeRunningChanged(callback: () => void): Unsubscribe {
|
|
133
147
|
this.runningSubscribers.add(callback);
|
|
134
148
|
return () => this.runningSubscribers.delete(callback);
|
|
135
149
|
}
|
|
136
150
|
|
|
151
|
+
private _publish = (
|
|
152
|
+
threadId: string,
|
|
153
|
+
runtime: ThreadRuntimeCore,
|
|
154
|
+
generation: number,
|
|
155
|
+
) => {
|
|
156
|
+
this._publishThreadRuntime(threadId, runtime, generation);
|
|
157
|
+
};
|
|
158
|
+
|
|
137
159
|
private _publishThreadRuntime(
|
|
138
160
|
threadId: string,
|
|
139
161
|
runtime: ThreadRuntimeCore,
|
|
140
162
|
generation: number,
|
|
141
163
|
) {
|
|
142
164
|
const instance = this.instances.get(threadId);
|
|
143
|
-
if (!instance)
|
|
144
|
-
throw new Error(
|
|
145
|
-
`Thread "${threadId}" runtime binding not found. This is a bug in assistant-ui.`,
|
|
146
|
-
);
|
|
165
|
+
if (!instance) return;
|
|
147
166
|
|
|
148
|
-
// An outgoing binder outlives its generation until React commits the key
|
|
149
|
-
// change, and must not publish over the incoming one.
|
|
150
167
|
if (instance.generation !== generation) return;
|
|
151
168
|
|
|
152
169
|
const previousRuntime = instance.runtime;
|
|
@@ -156,10 +173,20 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
156
173
|
this._trackRunning(instance);
|
|
157
174
|
}
|
|
158
175
|
this._notifySubscribers();
|
|
176
|
+
if (previousRuntime !== undefined && previousRuntime !== runtime) {
|
|
177
|
+
for (const callback of this.replacedSubscribers) callback();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private replacedSubscribers = new Set<() => void>();
|
|
182
|
+
|
|
183
|
+
public __internal_subscribeRuntimeReplaced(
|
|
184
|
+
callback: () => void,
|
|
185
|
+
): Unsubscribe {
|
|
186
|
+
this.replacedSubscribers.add(callback);
|
|
187
|
+
return () => this.replacedSubscribers.delete(callback);
|
|
159
188
|
}
|
|
160
189
|
|
|
161
|
-
// Run state changes far more often than the thread list does, so the list is
|
|
162
|
-
// only notified when a thread crosses the running boundary.
|
|
163
190
|
private _trackRunning(instance: RemoteThreadListHookInstance) {
|
|
164
191
|
instance.unsubscribeRunning?.();
|
|
165
192
|
|
|
@@ -186,90 +213,111 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
186
213
|
}
|
|
187
214
|
|
|
188
215
|
public stopThreadRuntime(threadId: string) {
|
|
189
|
-
this.instances.get(threadId)
|
|
216
|
+
const instance = this.instances.get(threadId);
|
|
217
|
+
if (instance?.runtime) invalidateThreadRuntime(instance.runtime);
|
|
218
|
+
instance?.unsubscribeRunning?.();
|
|
190
219
|
this.instances.delete(threadId);
|
|
191
|
-
this.
|
|
220
|
+
this.pendingThreadAdapters.delete(threadId);
|
|
221
|
+
this._syncHostThreads();
|
|
192
222
|
this._notifySubscribers();
|
|
193
223
|
}
|
|
194
224
|
|
|
195
225
|
public setRuntimeHook(newRuntimeHook: RemoteThreadListHook) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
226
|
+
if (this.runtimeHook === newRuntimeHook) return;
|
|
227
|
+
this.runtimeHook = newRuntimeHook;
|
|
228
|
+
this.hostStore.setState(
|
|
229
|
+
(state) => ({ ...state, hookEpoch: state.hookEpoch + 1 }),
|
|
230
|
+
true,
|
|
231
|
+
);
|
|
200
232
|
}
|
|
201
233
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const { useRuntime } = this.useRuntimeHook();
|
|
208
|
-
const runtime = useRuntime();
|
|
209
|
-
|
|
210
|
-
const threadBinding = (runtime.thread as ThreadRuntimeImpl)
|
|
211
|
-
.__internal_threadBinding;
|
|
212
|
-
|
|
213
|
-
const updateRuntime = useCallback(() => {
|
|
214
|
-
this._publishThreadRuntime(
|
|
215
|
-
threadId,
|
|
216
|
-
threadBinding.getState(),
|
|
217
|
-
generation,
|
|
218
|
-
);
|
|
219
|
-
}, [threadId, generation, threadBinding]);
|
|
220
|
-
|
|
221
|
-
const isMounted = useRef(false);
|
|
222
|
-
if (!isMounted.current) {
|
|
223
|
-
updateRuntime();
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
useEffect(() => {
|
|
227
|
-
isMounted.current = true;
|
|
228
|
-
updateRuntime();
|
|
229
|
-
return threadBinding.outerSubscribe(updateRuntime);
|
|
230
|
-
}, [threadBinding, updateRuntime]);
|
|
231
|
-
|
|
232
|
-
const aui = useAui();
|
|
233
|
-
const initPromiseRef = useRef<Promise<unknown> | undefined>(undefined);
|
|
234
|
-
const hasInitializedRef = useRef(false);
|
|
234
|
+
public __internal_setDefaultAdapters(adapters: RuntimeAdapters | null) {
|
|
235
|
+
const current = this.adapterStore.getState();
|
|
236
|
+
if (current.defaultAdapters === adapters) return;
|
|
237
|
+
this.adapterStore.setState({ ...current, defaultAdapters: adapters }, true);
|
|
238
|
+
}
|
|
235
239
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
240
|
+
public __internal_setThreadAdapters(
|
|
241
|
+
threadId: string,
|
|
242
|
+
adapters: RuntimeAdapters | null,
|
|
243
|
+
) {
|
|
244
|
+
const current = this.adapterStore.getState();
|
|
245
|
+
const next = new Map(current.threadAdapters);
|
|
246
|
+
if (adapters === null) next.delete(threadId);
|
|
247
|
+
else next.set(threadId, adapters);
|
|
248
|
+
this.adapterStore.setState({ ...current, threadAdapters: next }, true);
|
|
249
|
+
}
|
|
244
250
|
|
|
245
|
-
|
|
246
|
-
|
|
251
|
+
public __internal_dispose() {
|
|
252
|
+
for (const threadId of [...this.instances.keys()]) {
|
|
253
|
+
this.stopThreadRuntime(threadId);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
247
256
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
257
|
+
private _syncHostThreads() {
|
|
258
|
+
this.hostStore.setState(
|
|
259
|
+
(state) => ({
|
|
260
|
+
...state,
|
|
261
|
+
threads: Array.from(this.instances.entries()).map(
|
|
262
|
+
([id, { generation }]) => ({ id, generation }),
|
|
263
|
+
),
|
|
264
|
+
}),
|
|
265
|
+
true,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
251
268
|
|
|
252
|
-
|
|
269
|
+
public __internal_useHost(parentClient: AssistantClient) {
|
|
270
|
+
const { threads, hookEpoch } = this.hostStore();
|
|
271
|
+
const adapters = this.adapterStore();
|
|
272
|
+
const runtimeHook = this.runtimeHook;
|
|
273
|
+
return useResources(
|
|
274
|
+
threads.map(({ id, generation }) => {
|
|
275
|
+
const threadAdapters = this.pendingThreadAdapters.has(id)
|
|
276
|
+
? this.pendingThreadAdapters.get(id)!
|
|
277
|
+
: (adapters.threadAdapters.get(id) ?? adapters.defaultAdapters);
|
|
278
|
+
return withKey(
|
|
279
|
+
`${id}:${generation}:${hookEpoch}`,
|
|
280
|
+
RemoteThreadResource({
|
|
281
|
+
threadId: id,
|
|
282
|
+
generation,
|
|
283
|
+
parentList: this.parent,
|
|
284
|
+
runtimeHook,
|
|
285
|
+
parentClient,
|
|
286
|
+
adapters: threadAdapters,
|
|
287
|
+
publish: this._publish,
|
|
288
|
+
}),
|
|
289
|
+
);
|
|
290
|
+
}),
|
|
291
|
+
);
|
|
292
|
+
}
|
|
253
293
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
});
|
|
294
|
+
public __internal_RenderThreadRuntimes: FC<{
|
|
295
|
+
provider: ComponentType<PropsWithChildren>;
|
|
296
|
+
}> = ({ provider }) => {
|
|
297
|
+
this.hostStore();
|
|
259
298
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
299
|
+
return Array.from(this.instances.entries()).map(
|
|
300
|
+
([threadId, { generation }]) => (
|
|
301
|
+
<this._OuterActiveThreadProvider
|
|
302
|
+
key={`${threadId}:${generation}`}
|
|
303
|
+
threadId={threadId}
|
|
304
|
+
provider={provider}
|
|
305
|
+
/>
|
|
306
|
+
),
|
|
307
|
+
);
|
|
308
|
+
};
|
|
264
309
|
|
|
265
|
-
|
|
310
|
+
public __internal_Host: FC<{ parentClient: AssistantClient }> = ({
|
|
311
|
+
parentClient,
|
|
312
|
+
}) => {
|
|
313
|
+
this.__internal_useHost(parentClient);
|
|
314
|
+
return null;
|
|
266
315
|
};
|
|
267
316
|
|
|
268
317
|
private _OuterActiveThreadProvider: FC<{
|
|
269
318
|
threadId: string;
|
|
270
|
-
generation: number;
|
|
271
319
|
provider: ComponentType<PropsWithChildren>;
|
|
272
|
-
}> = memo(({ threadId,
|
|
320
|
+
}> = memo(({ threadId, provider: Provider }) => {
|
|
273
321
|
const runtime = useMemo(
|
|
274
322
|
() => new ThreadListRuntimeImpl(this.parent).getItemById(threadId),
|
|
275
323
|
[threadId],
|
|
@@ -283,7 +331,7 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
283
331
|
console.warn(
|
|
284
332
|
"RemoteThreadListAdapter.unstable_Provider did not render its `children` synchronously. " +
|
|
285
333
|
"Render `children` on first commit; deferring them behind a loading state, Suspense boundary, " +
|
|
286
|
-
"or `useEffect` gate strands the runtime
|
|
334
|
+
"or `useEffect` gate strands the runtime host and leaves the thread without context.",
|
|
287
335
|
);
|
|
288
336
|
}
|
|
289
337
|
}, 100);
|
|
@@ -295,28 +343,27 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
295
343
|
return (
|
|
296
344
|
<ThreadListItemRuntimeProvider runtime={runtime}>
|
|
297
345
|
<Provider>
|
|
298
|
-
<this.
|
|
299
|
-
<ProviderRenderDetector detectorRef={detectorRef} />
|
|
300
|
-
</this._RuntimeBinder>
|
|
346
|
+
<this._AdapterSink threadId={threadId} detectorRef={detectorRef} />
|
|
301
347
|
</Provider>
|
|
302
348
|
</ThreadListItemRuntimeProvider>
|
|
303
349
|
);
|
|
304
350
|
});
|
|
305
351
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
);
|
|
352
|
+
private _AdapterSink: FC<{
|
|
353
|
+
threadId: string;
|
|
354
|
+
detectorRef: RefObject<boolean>;
|
|
355
|
+
}> = ({ threadId, detectorRef }) => {
|
|
356
|
+
const adapters = useRuntimeAdapters();
|
|
357
|
+
this.pendingThreadAdapters.set(threadId, adapters);
|
|
358
|
+
useLayoutEffect(() => {
|
|
359
|
+
this.__internal_setThreadAdapters(threadId, adapters);
|
|
360
|
+
return () => {
|
|
361
|
+
if (this.pendingThreadAdapters.get(threadId) === adapters) {
|
|
362
|
+
this.pendingThreadAdapters.delete(threadId);
|
|
363
|
+
}
|
|
364
|
+
this.__internal_setThreadAdapters(threadId, null);
|
|
365
|
+
};
|
|
366
|
+
}, [threadId, adapters]);
|
|
367
|
+
return <ProviderRenderDetector detectorRef={detectorRef} />;
|
|
321
368
|
};
|
|
322
369
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore";
|
|
3
|
+
import { ThreadListRuntimeImpl } from "../../runtime/api/thread-list-runtime";
|
|
4
|
+
import { ReadonlyThreadRuntimeCore } from "../../runtimes/readonly/ReadonlyThreadRuntimeCore";
|
|
5
|
+
import {
|
|
6
|
+
contextProvider,
|
|
7
|
+
makeAdapter,
|
|
8
|
+
} from "../../tests/remote-thread-list-test-helpers";
|
|
9
|
+
import type { ThreadMessage } from "../../types/message";
|
|
10
|
+
|
|
11
|
+
const message = (id: string): ThreadMessage =>
|
|
12
|
+
({
|
|
13
|
+
id,
|
|
14
|
+
role: "user",
|
|
15
|
+
content: [{ type: "text", text: id }],
|
|
16
|
+
createdAt: new Date(0),
|
|
17
|
+
attachments: [],
|
|
18
|
+
metadata: { custom: {} },
|
|
19
|
+
}) as unknown as ThreadMessage;
|
|
20
|
+
|
|
21
|
+
const setup = () => {
|
|
22
|
+
const core = new RemoteThreadListThreadListRuntimeCore(
|
|
23
|
+
{ adapter: makeAdapter(), runtimeHook: () => ({}) as never },
|
|
24
|
+
contextProvider,
|
|
25
|
+
);
|
|
26
|
+
const hookManager = (
|
|
27
|
+
core as unknown as {
|
|
28
|
+
_hookManager: {
|
|
29
|
+
_publishThreadRuntime: (
|
|
30
|
+
id: string,
|
|
31
|
+
runtime: ReadonlyThreadRuntimeCore,
|
|
32
|
+
generation: number,
|
|
33
|
+
) => void;
|
|
34
|
+
instances: Map<string, { generation: number }>;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
)._hookManager;
|
|
38
|
+
const threadId = core.mainThreadId!;
|
|
39
|
+
const publish = (runtime: ReadonlyThreadRuntimeCore) =>
|
|
40
|
+
hookManager._publishThreadRuntime(
|
|
41
|
+
threadId,
|
|
42
|
+
runtime,
|
|
43
|
+
hookManager.instances.get(threadId)!.generation,
|
|
44
|
+
);
|
|
45
|
+
return { core, publish };
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
describe("RemoteThreadListThreadListRuntimeCore republish", () => {
|
|
49
|
+
it("keeps the subscribed main thread state on the republished core", async () => {
|
|
50
|
+
const { core, publish } = setup();
|
|
51
|
+
const first = new ReadonlyThreadRuntimeCore();
|
|
52
|
+
first.setMessages([message("m1")]);
|
|
53
|
+
publish(first);
|
|
54
|
+
|
|
55
|
+
const thread = new ThreadListRuntimeImpl(core).main;
|
|
56
|
+
thread.subscribe(() => {});
|
|
57
|
+
expect(thread.getState().messages.map((m) => m.id)).toEqual(["m1"]);
|
|
58
|
+
|
|
59
|
+
const second = new ReadonlyThreadRuntimeCore();
|
|
60
|
+
second.setMessages([message("m2")]);
|
|
61
|
+
publish(second);
|
|
62
|
+
await Promise.resolve();
|
|
63
|
+
|
|
64
|
+
const ids = thread.getState().messages.map((m) => m.id);
|
|
65
|
+
expect(ids).toEqual(["m2"]);
|
|
66
|
+
for (const id of ids) {
|
|
67
|
+
expect(() => thread.getMessageById(id).getState()).not.toThrow();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("notifies thread subscribers when the core is republished", async () => {
|
|
72
|
+
const { core, publish } = setup();
|
|
73
|
+
publish(new ReadonlyThreadRuntimeCore());
|
|
74
|
+
|
|
75
|
+
const thread = new ThreadListRuntimeImpl(core).main;
|
|
76
|
+
let notified = 0;
|
|
77
|
+
thread.subscribe(() => notified++);
|
|
78
|
+
|
|
79
|
+
const next = new ReadonlyThreadRuntimeCore();
|
|
80
|
+
next.setMessages([message("m1")]);
|
|
81
|
+
publish(next);
|
|
82
|
+
await Promise.resolve();
|
|
83
|
+
|
|
84
|
+
expect(notified).toBeGreaterThan(0);
|
|
85
|
+
expect(thread.getState().messages.map((m) => m.id)).toEqual(["m1"]);
|
|
86
|
+
});
|
|
87
|
+
});
|