@assistant-ui/core 0.3.15 → 0.3.17
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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +8 -2
- package/dist/internal.js +9 -3
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +3 -2
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/frame/provider.d.ts +5 -0
- package/dist/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +141 -28
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/interactable-composer-metadata.d.ts +1 -1
- package/dist/model-context/interactable-composer-metadata.js +1 -1
- package/dist/model-context/interactable-composer-metadata.js.map +1 -1
- package/dist/model-context/registry.d.ts +2 -2
- package/dist/model-context/registry.d.ts.map +1 -1
- package/dist/model-context/registry.js +9 -28
- package/dist/model-context/registry.js.map +1 -1
- package/dist/model-context/tool-call-text.d.ts +26 -0
- package/dist/model-context/tool-call-text.d.ts.map +1 -0
- package/dist/model-context/tool-call-text.js +18 -0
- package/dist/model-context/tool-call-text.js.map +1 -0
- package/dist/react/RuntimeAdapter.js +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/AdaptedRemoteThread.js +1 -1
- package/dist/react/client/InMemoryThreadList.d.ts.map +1 -1
- package/dist/react/client/InMemoryThreadList.js +25 -21
- package/dist/react/client/InMemoryThreadList.js.map +1 -1
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js +60 -178
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/RemoteThreadList.d.ts +15 -0
- package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
- package/dist/react/client/RemoteThreadList.js +263 -194
- package/dist/react/client/RemoteThreadList.js.map +1 -1
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +6 -2
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +4 -2
- package/dist/react/index.js +2 -1
- package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -1
- package/dist/react/interactables-legacy/Interactables.js +60 -178
- package/dist/react/interactables-legacy/Interactables.js.map +1 -1
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts +24 -0
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts.map +1 -0
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.js +138 -0
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.js.map +1 -0
- package/dist/react/model-context/toolbox.d.ts +2 -14
- package/dist/react/model-context/toolbox.d.ts.map +1 -1
- package/dist/react/model-context/toolbox.js +1 -13
- package/dist/react/model-context/toolbox.js.map +1 -1
- package/dist/react/model-context/useAssistantContext.js +37 -7
- package/dist/react/model-context/useAssistantContext.js.map +1 -1
- package/dist/react/model-context/useAuiToolOverrides.js +31 -5
- package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
- package/dist/react/model-context/useInlineRender.d.ts.map +1 -1
- package/dist/react/model-context/useInlineRender.js +10 -36
- package/dist/react/model-context/useInlineRender.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.js +2 -8
- package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +2 -4
- package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js +4 -3
- package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/react/primitives/composer/ComposerIf.js.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.d.ts +2 -1
- package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js +4 -3
- package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.js +7 -6
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +2 -2
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +3 -3
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.d.ts.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js +5 -4
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +7 -5
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +44 -22
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +7 -6
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +102 -117
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.d.ts +1 -6
- package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.js +3 -3
- package/dist/react/runtimes/RemoteThreadResource.js.map +1 -1
- package/dist/react/runtimes/assistant-transport/runManager.d.ts.map +1 -1
- package/dist/react/runtimes/assistant-transport/runManager.js +2 -12
- package/dist/react/runtimes/assistant-transport/runManager.js.map +1 -1
- package/dist/react/runtimes/assistant-transport/useLatestRef.js +2 -2
- package/dist/react/runtimes/assistant-transport/useLatestRef.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +3 -10
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +43 -85
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +5 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts +29 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js +159 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js.map +1 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts +12 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js +10 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts +1 -9
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +16 -153
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js.map +1 -1
- package/dist/react/runtimes/createMessageConverter.d.ts +2 -1
- package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.d.ts +6 -25
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +33 -233
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +14 -6
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/types/MessagePartComponentTypes.d.ts +7 -3
- package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
- package/dist/react/types/scopes/tools.d.ts +2 -0
- package/dist/react/types/scopes/tools.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.d.ts +1 -1
- package/dist/runtime/api/composer-runtime.js.map +1 -1
- package/dist/runtime/api/message-part-runtime.d.ts +2 -2
- package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-part-runtime.js +1 -1
- package/dist/runtime/api/message-part-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +9 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +5 -0
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +2 -3
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +14 -29
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +4 -6
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +5 -11
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -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 +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/composer-runtime-core.d.ts +1 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +14 -2
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +16 -2
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/internal.d.ts +2 -1
- package/dist/runtime/internal.js +2 -1
- package/dist/runtime/queue/external-thread-queue-adapter.d.ts +1 -1
- package/dist/runtime/queue/message-queue.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.js +1 -1
- package/dist/runtime/queue/message-queue.js.map +1 -1
- package/dist/runtime/queue/queue-item.d.ts +12 -0
- package/dist/runtime/queue/queue-item.d.ts.map +1 -0
- package/dist/runtime/queue/queue-item.js +6 -0
- package/dist/runtime/queue/queue-item.js.map +1 -0
- package/dist/runtime/utils/abortable-thread-load.d.ts +15 -0
- package/dist/runtime/utils/abortable-thread-load.d.ts.map +1 -0
- package/dist/runtime/utils/abortable-thread-load.js +35 -0
- package/dist/runtime/utils/abortable-thread-load.js.map +1 -0
- package/dist/runtime/utils/attachment-add-operations.d.ts +18 -0
- package/dist/runtime/utils/attachment-add-operations.d.ts.map +1 -0
- package/dist/runtime/utils/attachment-add-operations.js +43 -0
- package/dist/runtime/utils/attachment-add-operations.js.map +1 -0
- package/dist/runtime/utils/auto-status.d.ts +7 -2
- package/dist/runtime/utils/auto-status.d.ts.map +1 -1
- package/dist/runtime/utils/auto-status.js +13 -3
- package/dist/runtime/utils/auto-status.js.map +1 -1
- package/dist/runtime/utils/external-message-conversion.d.ts +48 -0
- package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -0
- package/dist/runtime/utils/external-message-conversion.js +222 -0
- package/dist/runtime/utils/external-message-conversion.js.map +1 -0
- package/dist/runtime/utils/external-store-message.d.ts +2 -1
- package/dist/runtime/utils/external-store-message.d.ts.map +1 -1
- package/dist/runtime/utils/external-store-message.js +2 -1
- package/dist/runtime/utils/external-store-message.js.map +1 -1
- package/dist/runtime/utils/message-repository-session.d.ts +30 -0
- package/dist/runtime/utils/message-repository-session.d.ts.map +1 -0
- package/dist/runtime/utils/message-repository-session.js +130 -0
- package/dist/runtime/utils/message-repository-session.js.map +1 -0
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.js +3 -4
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtime/utils/pending-tool-calls.d.ts +20 -0
- package/dist/runtime/utils/pending-tool-calls.d.ts.map +1 -0
- package/dist/runtime/utils/pending-tool-calls.js +22 -0
- package/dist/runtime/utils/pending-tool-calls.js.map +1 -0
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +6 -3
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -1
- package/dist/runtime/utils/resolveToolApprovalResponse.js +12 -3
- package/dist/runtime/utils/resolveToolApprovalResponse.js.map +1 -1
- package/dist/runtime/utils/thread-message-like.d.ts +3 -10
- package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtime/utils/tool-call-tree.d.ts +39 -0
- package/dist/runtime/utils/tool-call-tree.d.ts.map +1 -0
- package/dist/runtime/utils/tool-call-tree.js +85 -0
- package/dist/runtime/utils/tool-call-tree.js.map +1 -0
- package/dist/runtimes/external-store/external-store-adapter.d.ts +29 -2
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +2 -5
- 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 +3 -10
- 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 +21 -2
- 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 +154 -46
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +4 -2
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +23 -3
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +12 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.js +107 -14
- package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/title.d.ts +9 -0
- package/dist/runtimes/remote-thread-list/title.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/title.js +6 -0
- package/dist/runtimes/remote-thread-list/title.js.map +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts +6 -5
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +31 -8
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +98 -59
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/external-thread.d.ts +1 -1
- package/dist/store/clients/external-thread.d.ts.map +1 -1
- package/dist/store/clients/external-thread.js +85 -103
- package/dist/store/clients/external-thread.js.map +1 -1
- package/dist/store/clients/single-thread-list.d.ts.map +1 -1
- package/dist/store/clients/single-thread-list.js +2 -2
- package/dist/store/clients/single-thread-list.js.map +1 -1
- package/dist/store/clients/suggestions.d.ts.map +1 -1
- package/dist/store/clients/suggestions.js +33 -12
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-message-client.js +1 -1
- package/dist/store/clients/thread-selection-events.js +1 -1
- package/dist/store/index.d.ts +6 -3
- package/dist/store/index.js +2 -1
- package/dist/store/internal.d.ts +2 -2
- package/dist/store/internal.js +2 -2
- package/dist/store/primitive-predicates.d.ts +4 -1
- package/dist/store/primitive-predicates.d.ts.map +1 -1
- package/dist/store/primitive-predicates.js +9 -1
- package/dist/store/primitive-predicates.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +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 +124 -105
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +1 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts +3 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts.map +1 -1
- package/dist/store/runtime-clients/useSubscribable.js +1 -1
- package/dist/store/runtime-clients/useSubscribable.js.map +1 -1
- package/dist/store/scope-registration.d.ts +1 -1
- package/dist/store/scopes/composer.d.ts +2 -1
- package/dist/store/scopes/composer.d.ts.map +1 -1
- package/dist/store/scopes/message.d.ts +1 -1
- package/dist/store/scopes/part.d.ts +6 -3
- package/dist/store/scopes/part.d.ts.map +1 -1
- package/dist/store/scopes/queue-item.d.ts +2 -9
- package/dist/store/scopes/queue-item.d.ts.map +1 -1
- package/dist/store/scopes/queue-item.js +0 -6
- package/dist/subscribable/subscribable.d.ts +8 -1
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +24 -16
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/types/message.d.ts +47 -4
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js +7 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/data-url.d.ts +14 -1
- package/dist/utils/data-url.d.ts.map +1 -1
- package/dist/utils/data-url.js +13 -1
- package/dist/utils/data-url.js.map +1 -1
- package/dist/utils/invoke-user-callback.d.ts +5 -0
- package/dist/utils/invoke-user-callback.d.ts.map +1 -0
- package/dist/utils/invoke-user-callback.js +19 -0
- package/dist/utils/invoke-user-callback.js.map +1 -0
- package/dist/utils/normalizePartStatus.js.map +1 -1
- package/package.json +12 -17
- package/src/index.ts +6 -1
- package/src/internal.ts +20 -0
- package/src/model-context/frame/host.test.ts +91 -7
- package/src/model-context/frame/host.ts +7 -2
- package/src/model-context/frame/provider.test.ts +484 -13
- package/src/model-context/frame/provider.ts +205 -35
- package/src/model-context/interactable-composer-metadata.ts +1 -1
- package/src/model-context/registry.test.ts +44 -0
- package/src/model-context/registry.ts +13 -35
- package/src/model-context/tool-call-text.test.ts +67 -0
- package/src/model-context/tool-call-text.ts +67 -0
- package/src/react/AssistantRuntimeProvider.test.tsx +66 -2
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +1 -3
- package/src/react/client/InMemoryThreadList.test.tsx +49 -0
- package/src/react/client/InMemoryThreadList.ts +7 -1
- package/src/react/client/Interactables.ts +19 -178
- package/src/react/client/RemoteThreadList.background.test.ts +384 -0
- package/src/react/client/RemoteThreadList.concurrent.test.tsx +274 -0
- package/src/react/client/RemoteThreadList.test.ts +369 -1
- package/src/react/client/RemoteThreadList.ts +320 -142
- package/src/react/client/Tools.ts +7 -1
- package/src/react/index.ts +4 -0
- package/src/react/interactables-legacy/Interactables.ts +20 -177
- package/src/react/interactables-shared/useInteractablePersistenceQueue.test.tsx +161 -0
- package/src/react/interactables-shared/useInteractablePersistenceQueue.ts +206 -0
- package/src/react/model-context/modelContextHooks.test.tsx +131 -0
- package/src/react/model-context/toolbox.test.ts +9 -9
- package/src/react/model-context/toolbox.ts +9 -36
- package/src/react/model-context/useAssistantContext.ts +4 -2
- package/src/react/model-context/useAuiToolOverrides.ts +4 -2
- package/src/react/model-context/useInlineRender.test.tsx +48 -0
- package/src/react/model-context/useInlineRender.ts +14 -10
- package/src/react/primitive-hooks/useMessageError.ts +2 -19
- package/src/react/primitive-hooks/useThreadListLoadMore.ts +2 -3
- package/src/react/primitives/composer/ComposerAttachments.test.tsx +76 -0
- package/src/react/primitives/composer/ComposerAttachments.tsx +9 -4
- package/src/react/primitives/composer/ComposerQueue.test.tsx +72 -0
- package/src/react/primitives/composer/ComposerQueue.tsx +7 -4
- package/src/react/primitives/message/MessageAttachments.test.tsx +107 -37
- package/src/react/primitives/message/MessageAttachments.tsx +10 -7
- package/src/react/primitives/message/MessageGroupedParts.tsx +2 -2
- package/src/react/primitives/message/MessageParts.tsx +3 -3
- package/src/react/primitives/threadList/ThreadListItems.test.tsx +99 -0
- package/src/react/primitives/threadList/ThreadListItems.tsx +8 -5
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +94 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +72 -31
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.switch-delete.test.ts +169 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +140 -124
- package/src/react/runtimes/RemoteThreadResource.ts +1 -4
- package/src/react/runtimes/assistant-transport/runManager.ts +4 -17
- package/src/react/runtimes/assistant-transport/transport-scheduling.test.ts +51 -2
- package/src/react/runtimes/assistant-transport/useLatestRef.ts +2 -2
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +45 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +157 -1
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +82 -176
- package/src/react/runtimes/cloud/auiV0.ts +5 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +88 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +236 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.test.ts +37 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.ts +18 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +90 -1
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +33 -238
- package/src/react/runtimes/external-message-converter.test.ts +0 -14
- package/src/react/runtimes/external-message-converter.test.tsx +77 -0
- package/src/react/runtimes/external-message-converter.ts +59 -481
- package/src/react/runtimes/useRemoteThreadListRuntime.concurrent.test.tsx +216 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +24 -6
- package/src/react/types/MessagePartComponentTypes.ts +7 -3
- package/src/react/types/scopes/tools.ts +2 -0
- package/src/runtime/api/composer-runtime.ts +1 -1
- package/src/runtime/api/message-part-runtime.ts +3 -3
- package/src/runtime/api/message-runtime.test.ts +28 -1
- package/src/runtime/api/thread-list-runtime.ts +25 -1
- package/src/runtime/base/base-composer-runtime-core.ts +20 -40
- package/src/runtime/base/base-thread-runtime-core.test.ts +110 -3
- package/src/runtime/base/base-thread-runtime-core.ts +16 -15
- package/src/runtime/base/default-thread-composer-runtime-core.ts +1 -4
- package/src/runtime/interfaces/composer-runtime-core.ts +1 -1
- package/src/runtime/interfaces/thread-list-runtime-core.ts +20 -1
- package/src/runtime/interfaces/thread-runtime-core.ts +18 -2
- package/src/runtime/internal.ts +5 -0
- package/src/runtime/queue/external-thread-queue-adapter.ts +1 -1
- package/src/runtime/queue/message-queue.ts +1 -4
- package/src/runtime/queue/queue-item.ts +10 -0
- package/src/runtime/utils/abortable-thread-load.test.ts +87 -0
- package/src/runtime/utils/abortable-thread-load.ts +53 -0
- package/src/runtime/utils/attachment-add-operations.ts +59 -0
- package/src/runtime/utils/auto-status.test.ts +57 -0
- package/src/runtime/utils/auto-status.ts +46 -1
- package/src/runtime/utils/external-message-conversion.test.ts +210 -0
- package/src/runtime/utils/external-message-conversion.ts +510 -0
- package/src/runtime/utils/external-store-message.ts +2 -0
- package/src/runtime/utils/message-repository-session.test.ts +195 -0
- package/src/runtime/utils/message-repository-session.ts +176 -0
- package/src/runtime/utils/message-repository.ts +7 -4
- package/src/runtime/utils/pending-tool-calls.test.ts +57 -0
- package/src/runtime/utils/pending-tool-calls.ts +35 -0
- package/src/runtime/utils/resolveToolApprovalResponse.test.ts +73 -0
- package/src/runtime/utils/resolveToolApprovalResponse.ts +27 -6
- package/src/runtime/utils/thread-message-like.ts +4 -10
- package/src/runtime/utils/tool-call-tree.test.ts +191 -0
- package/src/runtime/utils/tool-call-tree.ts +97 -0
- package/src/runtimes/external-store/external-store-adapter.ts +38 -2
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +6 -14
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +231 -61
- package/src/runtimes/inert/InertThreadRuntimeCore.ts +1 -1
- package/src/runtimes/local/local-thread-runtime-core.test.ts +201 -4
- package/src/runtimes/local/local-thread-runtime-core.ts +53 -4
- package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +149 -0
- package/src/runtimes/remote-thread-list/remote-thread-state.ts +178 -16
- package/src/runtimes/remote-thread-list/title.ts +3 -0
- package/src/runtimes/remote-thread-list/types.ts +6 -5
- package/src/runtimes/tool-invocations/EDGE_CASES.md +125 -3
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +856 -102
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +145 -89
- package/src/store/clients/external-thread.ts +30 -69
- package/src/store/clients/single-thread-list.ts +4 -1
- package/src/store/clients/suggestions.test.ts +185 -0
- package/src/store/clients/suggestions.ts +42 -35
- package/src/store/index.ts +4 -0
- package/src/store/internal.ts +2 -0
- package/src/store/primitive-predicates.ts +35 -0
- package/src/store/runtime-clients/thread-list-runtime-client.ts +16 -2
- package/src/store/runtime-clients/useSubscribable.ts +8 -2
- package/src/store/scopes/message.ts +1 -1
- package/src/store/scopes/part.ts +6 -3
- package/src/store/scopes/queue-item.ts +2 -9
- package/src/subscribable/subscribable.test.ts +50 -0
- package/src/subscribable/subscribable.ts +33 -21
- package/src/tests/MessageRepository.test.ts +77 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-load-race.test.ts +305 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-loadMore.test.ts +78 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-reload.test.ts +52 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-title-race.test.ts +158 -0
- package/src/tests/external-store-optimistic-id.test.ts +79 -0
- package/src/tests/external-store-repository-instance.test.ts +166 -0
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +186 -16
- package/src/tests/external-store-thread-runtime-core.test.ts +642 -0
- package/src/tests/external-thread-attachments.test.tsx +258 -1
- package/src/tests/remote-thread-list-adapter-switch.test.ts +66 -1
- package/src/tests/single-thread-list-item.test.tsx +47 -0
- package/src/tests/thread-message-like.test.ts +39 -1
- package/src/tests/thread-switch-events.test.tsx +397 -2
- package/src/types/message.ts +58 -5
- package/src/utils/data-url.test.ts +52 -1
- package/src/utils/data-url.ts +21 -0
- package/src/utils/invoke-user-callback.test.ts +82 -0
- package/src/utils/invoke-user-callback.ts +31 -0
- package/src/utils/normalizePartStatus.ts +1 -1
- package/dist/store/scopes/queue-item.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseSubscribable } from "../../subscribable/subscribable.js";
|
|
2
2
|
import { invalidateThreadRuntime } from "../../runtime/utils/thread-runtime-lifecycle.js";
|
|
3
3
|
//#region src/runtimes/external-store/external-store-thread-list-runtime-core.ts
|
|
4
4
|
const EMPTY_ARRAY = Object.freeze([]);
|
|
@@ -12,7 +12,7 @@ const DEFAULT_THREAD = Object.freeze({
|
|
|
12
12
|
});
|
|
13
13
|
const RESOLVED_PROMISE = Promise.resolve();
|
|
14
14
|
const DEFAULT_THREAD_DATA = Object.freeze({ [DEFAULT_THREAD_ID]: DEFAULT_THREAD });
|
|
15
|
-
var ExternalStoreThreadListRuntimeCore = class {
|
|
15
|
+
var ExternalStoreThreadListRuntimeCore = class extends BaseSubscribable {
|
|
16
16
|
_mainThreadId = DEFAULT_THREAD_ID;
|
|
17
17
|
_threads = DEFAULT_THREADS;
|
|
18
18
|
_archivedThreads = EMPTY_ARRAY;
|
|
@@ -40,6 +40,7 @@ var ExternalStoreThreadListRuntimeCore = class {
|
|
|
40
40
|
}
|
|
41
41
|
threadFactory;
|
|
42
42
|
constructor(adapter = {}, threadFactory) {
|
|
43
|
+
super();
|
|
43
44
|
this.threadFactory = threadFactory;
|
|
44
45
|
this.__internal_setAdapter(adapter, true);
|
|
45
46
|
}
|
|
@@ -145,14 +146,6 @@ var ExternalStoreThreadListRuntimeCore = class {
|
|
|
145
146
|
generateTitle() {
|
|
146
147
|
throw new Error("Method not implemented.");
|
|
147
148
|
}
|
|
148
|
-
_subscriptions = /* @__PURE__ */ new Set();
|
|
149
|
-
subscribe(callback) {
|
|
150
|
-
this._subscriptions.add(callback);
|
|
151
|
-
return () => this._subscriptions.delete(callback);
|
|
152
|
-
}
|
|
153
|
-
_notifySubscribers() {
|
|
154
|
-
notifySubscribers(this._subscriptions);
|
|
155
|
-
}
|
|
156
149
|
};
|
|
157
150
|
//#endregion
|
|
158
151
|
export { ExternalStoreThreadListRuntimeCore };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-store-thread-list-runtime-core.js","names":["Unsubscribe","ExternalStoreThreadRuntimeCore","ThreadListItemCoreState","ThreadListRuntimeCore","ExternalStoreThreadListAdapter","invalidateThreadRuntime","notifySubscribers","ExternalStoreThreadFactory","EMPTY_ARRAY","Object","freeze","DEFAULT_THREAD_ID","DEFAULT_THREADS","DEFAULT_THREAD","id","remoteId","undefined","externalId","status","RESOLVED_PROMISE","Promise","resolve","DEFAULT_THREAD_DATA","ExternalStoreThreadListRuntimeCore","_mainThreadId","_threads","_archivedThreads","_threadData","Readonly","Record","adapter","isLoading","newThreadId","threadIds","archivedThreadIds","threadItems","getLoadThreadsPromise","_mainThread","mainThreadId","threadFactory","constructor","__internal_setAdapter","getMainThreadRuntimeCore","getThreadRuntimeCore","Error","getItemById","threadId","initialLoad","previousAdapter","newThreads","threads","newArchivedThreads","archivedThreads","previousThreadId","previousThreads","previousArchivedThreads","fromEntries","map","t","_notifySubscribers","reloadMainThread","unstable_refetchThread","switchToThread","_options","unarchive","onSwitchToThread","switchToNewThread","onSwitchToNewThread","rename","newTitle","onRename","updateCustom","custom","onUpdateCustom","detach","archive","onArchive","onUnarchive","delete","onDelete","initialize","generateTitle","_subscriptions","Set","subscribe","callback","add"],"sources":["../../../src/runtimes/external-store/external-store-thread-list-runtime-core.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { ExternalStoreThreadRuntimeCore } from \"./external-store-thread-runtime-core\";\nimport type {\n ThreadListItemCoreState,\n ThreadListRuntimeCore,\n} from \"../../runtime/interfaces/thread-list-runtime-core\";\nimport type { ExternalStoreThreadListAdapter } from \"./external-store-adapter\";\nimport { invalidateThreadRuntime } from \"../../runtime/utils/thread-runtime-lifecycle\";\nimport { notifySubscribers } from \"../../subscribable/subscribable\";\n\nexport type ExternalStoreThreadFactory = () => ExternalStoreThreadRuntimeCore;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst DEFAULT_THREAD_ID = \"DEFAULT_THREAD_ID\";\nconst DEFAULT_THREADS = Object.freeze([DEFAULT_THREAD_ID]);\nconst DEFAULT_THREAD = Object.freeze({\n id: DEFAULT_THREAD_ID,\n remoteId: undefined,\n externalId: undefined,\n status: \"regular\",\n});\nconst RESOLVED_PROMISE = Promise.resolve();\nconst DEFAULT_THREAD_DATA = Object.freeze({\n [DEFAULT_THREAD_ID]: DEFAULT_THREAD,\n});\n\nexport class ExternalStoreThreadListRuntimeCore implements ThreadListRuntimeCore {\n private _mainThreadId: string = DEFAULT_THREAD_ID;\n private _threads: readonly string[] = DEFAULT_THREADS;\n private _archivedThreads: readonly string[] = EMPTY_ARRAY;\n private _threadData: Readonly<Record<string, ThreadListItemCoreState>> =\n DEFAULT_THREAD_DATA;\n private adapter: ExternalStoreThreadListAdapter = {};\n\n public get isLoading() {\n return this.adapter.isLoading ?? false;\n }\n\n public get newThreadId() {\n return undefined;\n }\n\n public get threadIds() {\n return this._threads;\n }\n\n public get archivedThreadIds() {\n return this._archivedThreads;\n }\n\n public get threadItems() {\n return this._threadData;\n }\n\n public getLoadThreadsPromise() {\n return RESOLVED_PROMISE;\n }\n\n private _mainThread!: ExternalStoreThreadRuntimeCore;\n\n public get mainThreadId() {\n return this._mainThreadId;\n }\n\n private threadFactory: ExternalStoreThreadFactory;\n\n constructor(\n adapter: ExternalStoreThreadListAdapter = {},\n threadFactory: ExternalStoreThreadFactory,\n ) {\n this.threadFactory = threadFactory;\n this.__internal_setAdapter(adapter, true);\n }\n\n public getMainThreadRuntimeCore() {\n return this._mainThread;\n }\n\n public getThreadRuntimeCore(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n public getItemById(threadId: string) {\n return this._threadData[threadId];\n }\n\n public __internal_setAdapter(\n adapter: ExternalStoreThreadListAdapter,\n initialLoad = false,\n ) {\n const previousAdapter = this.adapter;\n this.adapter = adapter;\n\n const newThreadId = adapter.threadId ?? DEFAULT_THREAD_ID;\n const newThreads = adapter.threads ?? EMPTY_ARRAY;\n const newArchivedThreads = adapter.archivedThreads ?? EMPTY_ARRAY;\n\n const previousThreadId = previousAdapter.threadId ?? DEFAULT_THREAD_ID;\n const previousThreads = previousAdapter.threads ?? EMPTY_ARRAY;\n const previousArchivedThreads =\n previousAdapter.archivedThreads ?? EMPTY_ARRAY;\n\n if (\n !initialLoad &&\n previousThreadId === newThreadId &&\n previousThreads === newThreads &&\n previousArchivedThreads === newArchivedThreads\n ) {\n return;\n }\n\n if (\n previousThreads !== newThreads ||\n previousArchivedThreads !== newArchivedThreads ||\n previousThreadId !== newThreadId\n ) {\n this._threadData = {\n ...DEFAULT_THREAD_DATA,\n ...Object.fromEntries(\n adapter.threads?.map((t) => [\n t.id,\n {\n ...t,\n remoteId: t.remoteId,\n externalId: t.externalId,\n status: \"regular\",\n },\n ]) ?? [],\n ),\n ...Object.fromEntries(\n adapter.archivedThreads?.map((t) => [\n t.id,\n {\n ...t,\n remoteId: t.remoteId,\n externalId: t.externalId,\n status: \"archived\",\n },\n ]) ?? [],\n ),\n };\n }\n\n if (previousThreads !== newThreads) {\n this._threads = this.adapter.threads?.map((t) => t.id) ?? EMPTY_ARRAY;\n }\n\n if (previousArchivedThreads !== newArchivedThreads) {\n this._archivedThreads =\n this.adapter.archivedThreads?.map((t) => t.id) ?? EMPTY_ARRAY;\n }\n\n // `initialLoad ||`: `_mainThread!` must be assigned on construction.\n if (initialLoad || previousThreadId !== newThreadId) {\n if (!initialLoad) invalidateThreadRuntime(this._mainThread);\n this._mainThreadId = newThreadId;\n this._mainThread = this.threadFactory();\n }\n\n if (!this._threadData[this._mainThreadId]) {\n this._threadData = {\n ...this._threadData,\n [this._mainThreadId]: {\n id: this._mainThreadId,\n remoteId: undefined,\n externalId: undefined,\n status: \"regular\",\n },\n };\n }\n\n this._notifySubscribers();\n }\n\n public async reloadMainThread(): Promise<void> {\n // There is no runtime hook to remount here, so the capability is the only\n // path and an adapter without it has nothing to refetch with.\n if (!this._mainThread.unstable_refetchThread) return;\n // No unsent-thread guard: every entry here is regular or archived, so the\n // \"new\" status the remote thread list has to exclude cannot occur.\n await this._mainThread.unstable_refetchThread();\n }\n\n public async switchToThread(\n threadId: string,\n _options?: { unarchive?: boolean },\n ): Promise<void> {\n if (this._mainThreadId === threadId) return;\n const onSwitchToThread = this.adapter.onSwitchToThread;\n if (!onSwitchToThread)\n throw new Error(\n \"External store adapter does not support switching to thread\",\n );\n await onSwitchToThread(threadId);\n }\n\n public async switchToNewThread(): Promise<void> {\n const onSwitchToNewThread = this.adapter.onSwitchToNewThread;\n if (!onSwitchToNewThread)\n throw new Error(\n \"External store adapter does not support switching to new thread\",\n );\n\n await onSwitchToNewThread();\n }\n\n public async rename(threadId: string, newTitle: string): Promise<void> {\n const onRename = this.adapter.onRename;\n if (!onRename)\n throw new Error(\"External store adapter does not support renaming\");\n\n await onRename(threadId, newTitle);\n }\n\n public async updateCustom(\n threadId: string,\n custom: Record<string, unknown> | undefined,\n ): Promise<void> {\n const onUpdateCustom = this.adapter.onUpdateCustom;\n if (!onUpdateCustom)\n throw new Error(\n \"External store adapter does not support updating custom metadata\",\n );\n\n await onUpdateCustom(threadId, custom);\n }\n\n public async detach(): Promise<void> {\n // no-op\n }\n\n public async archive(threadId: string): Promise<void> {\n const onArchive = this.adapter.onArchive;\n if (!onArchive)\n throw new Error(\"External store adapter does not support archiving\");\n\n await onArchive(threadId);\n }\n\n public async unarchive(threadId: string): Promise<void> {\n const onUnarchive = this.adapter.onUnarchive;\n if (!onUnarchive)\n throw new Error(\"External store adapter does not support unarchiving\");\n\n await onUnarchive(threadId);\n }\n\n public async delete(threadId: string): Promise<void> {\n const onDelete = this.adapter.onDelete;\n if (!onDelete)\n throw new Error(\"External store adapter does not support deleting\");\n\n await onDelete(threadId);\n }\n\n public initialize(\n threadId: string,\n ): Promise<{ remoteId: string; externalId: string | undefined }> {\n return Promise.resolve({ remoteId: threadId, externalId: undefined });\n }\n\n public generateTitle(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscribers() {\n notifySubscribers(this._subscriptions);\n }\n}\n"],"mappings":";;;AAYA,MAAMQ,cAAcC,OAAOC,OAAO,CAAA,CAAE;AACpC,MAAMC,oBAAoB;AAC1B,MAAMC,kBAAkBH,OAAOC,OAAO,CAACC,iBAAiB,CAAC;AACzD,MAAME,iBAAiBJ,OAAOC,OAAO;CACnCI,IAAIH;CACJI,UAAUC,KAAAA;CACVC,YAAYD,KAAAA;CACZE,QAAQ;AACV,CAAC;AACD,MAAMC,mBAAmBC,QAAQC,QAAQ;AACzC,MAAMC,sBAAsBb,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;EAChC,aAAa,KAAKH,eAAeJ,OAAOO,QAAQ;CAClD;CAEA,qBAA6B;EAC3B/E,kBAAkB,KAAK4E,cAAc;CACvC;AACF"}
|
|
1
|
+
{"version":3,"file":"external-store-thread-list-runtime-core.js","names":["ExternalStoreThreadRuntimeCore","ThreadListItemCoreState","ThreadListRuntimeCore","ExternalStoreThreadListAdapter","invalidateThreadRuntime","BaseSubscribable","ExternalStoreThreadFactory","EMPTY_ARRAY","Object","freeze","DEFAULT_THREAD_ID","DEFAULT_THREADS","DEFAULT_THREAD","id","remoteId","undefined","externalId","status","RESOLVED_PROMISE","Promise","resolve","DEFAULT_THREAD_DATA","ExternalStoreThreadListRuntimeCore","_mainThreadId","_threads","_archivedThreads","_threadData","Readonly","Record","adapter","isLoading","newThreadId","threadIds","archivedThreadIds","threadItems","getLoadThreadsPromise","_mainThread","mainThreadId","threadFactory","constructor","__internal_setAdapter","getMainThreadRuntimeCore","getThreadRuntimeCore","Error","getItemById","threadId","initialLoad","previousAdapter","newThreads","threads","newArchivedThreads","archivedThreads","previousThreadId","previousThreads","previousArchivedThreads","fromEntries","map","t","_notifySubscribers","reloadMainThread","unstable_refetchThread","switchToThread","_options","unarchive","onSwitchToThread","switchToNewThread","onSwitchToNewThread","rename","newTitle","onRename","updateCustom","custom","onUpdateCustom","detach","archive","onArchive","onUnarchive","delete","onDelete","initialize","generateTitle"],"sources":["../../../src/runtimes/external-store/external-store-thread-list-runtime-core.ts"],"sourcesContent":["import type { ExternalStoreThreadRuntimeCore } from \"./external-store-thread-runtime-core\";\nimport type {\n ThreadListItemCoreState,\n ThreadListRuntimeCore,\n} from \"../../runtime/interfaces/thread-list-runtime-core\";\nimport type { ExternalStoreThreadListAdapter } from \"./external-store-adapter\";\nimport { invalidateThreadRuntime } from \"../../runtime/utils/thread-runtime-lifecycle\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\n\nexport type ExternalStoreThreadFactory = () => ExternalStoreThreadRuntimeCore;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst DEFAULT_THREAD_ID = \"DEFAULT_THREAD_ID\";\nconst DEFAULT_THREADS = Object.freeze([DEFAULT_THREAD_ID]);\nconst DEFAULT_THREAD = Object.freeze({\n id: DEFAULT_THREAD_ID,\n remoteId: undefined,\n externalId: undefined,\n status: \"regular\",\n});\nconst RESOLVED_PROMISE = Promise.resolve();\nconst DEFAULT_THREAD_DATA = Object.freeze({\n [DEFAULT_THREAD_ID]: DEFAULT_THREAD,\n});\n\nexport class ExternalStoreThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _mainThreadId: string = DEFAULT_THREAD_ID;\n private _threads: readonly string[] = DEFAULT_THREADS;\n private _archivedThreads: readonly string[] = EMPTY_ARRAY;\n private _threadData: Readonly<Record<string, ThreadListItemCoreState>> =\n DEFAULT_THREAD_DATA;\n private adapter: ExternalStoreThreadListAdapter = {};\n\n public get isLoading() {\n return this.adapter.isLoading ?? false;\n }\n\n public get newThreadId() {\n return undefined;\n }\n\n public get threadIds() {\n return this._threads;\n }\n\n public get archivedThreadIds() {\n return this._archivedThreads;\n }\n\n public get threadItems() {\n return this._threadData;\n }\n\n public getLoadThreadsPromise() {\n return RESOLVED_PROMISE;\n }\n\n private _mainThread!: ExternalStoreThreadRuntimeCore;\n\n public get mainThreadId() {\n return this._mainThreadId;\n }\n\n private threadFactory: ExternalStoreThreadFactory;\n\n constructor(\n adapter: ExternalStoreThreadListAdapter = {},\n threadFactory: ExternalStoreThreadFactory,\n ) {\n super();\n this.threadFactory = threadFactory;\n this.__internal_setAdapter(adapter, true);\n }\n\n public getMainThreadRuntimeCore() {\n return this._mainThread;\n }\n\n public getThreadRuntimeCore(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n public getItemById(threadId: string) {\n return this._threadData[threadId];\n }\n\n public __internal_setAdapter(\n adapter: ExternalStoreThreadListAdapter,\n initialLoad = false,\n ) {\n const previousAdapter = this.adapter;\n this.adapter = adapter;\n\n const newThreadId = adapter.threadId ?? DEFAULT_THREAD_ID;\n const newThreads = adapter.threads ?? EMPTY_ARRAY;\n const newArchivedThreads = adapter.archivedThreads ?? EMPTY_ARRAY;\n\n const previousThreadId = previousAdapter.threadId ?? DEFAULT_THREAD_ID;\n const previousThreads = previousAdapter.threads ?? EMPTY_ARRAY;\n const previousArchivedThreads =\n previousAdapter.archivedThreads ?? EMPTY_ARRAY;\n\n if (\n !initialLoad &&\n previousThreadId === newThreadId &&\n previousThreads === newThreads &&\n previousArchivedThreads === newArchivedThreads\n ) {\n return;\n }\n\n if (\n previousThreads !== newThreads ||\n previousArchivedThreads !== newArchivedThreads ||\n previousThreadId !== newThreadId\n ) {\n this._threadData = {\n ...DEFAULT_THREAD_DATA,\n ...Object.fromEntries(\n adapter.threads?.map((t) => [\n t.id,\n {\n ...t,\n remoteId: t.remoteId,\n externalId: t.externalId,\n status: \"regular\",\n },\n ]) ?? [],\n ),\n ...Object.fromEntries(\n adapter.archivedThreads?.map((t) => [\n t.id,\n {\n ...t,\n remoteId: t.remoteId,\n externalId: t.externalId,\n status: \"archived\",\n },\n ]) ?? [],\n ),\n };\n }\n\n if (previousThreads !== newThreads) {\n this._threads = this.adapter.threads?.map((t) => t.id) ?? EMPTY_ARRAY;\n }\n\n if (previousArchivedThreads !== newArchivedThreads) {\n this._archivedThreads =\n this.adapter.archivedThreads?.map((t) => t.id) ?? EMPTY_ARRAY;\n }\n\n // `initialLoad ||`: `_mainThread!` must be assigned on construction.\n if (initialLoad || previousThreadId !== newThreadId) {\n if (!initialLoad) invalidateThreadRuntime(this._mainThread);\n this._mainThreadId = newThreadId;\n this._mainThread = this.threadFactory();\n }\n\n if (!this._threadData[this._mainThreadId]) {\n this._threadData = {\n ...this._threadData,\n [this._mainThreadId]: {\n id: this._mainThreadId,\n remoteId: undefined,\n externalId: undefined,\n status: \"regular\",\n },\n };\n }\n\n this._notifySubscribers();\n }\n\n public async reloadMainThread(): Promise<void> {\n // There is no runtime hook to remount here, so the capability is the only\n // path and an adapter without it has nothing to refetch with.\n if (!this._mainThread.unstable_refetchThread) return;\n // No unsent-thread guard: every entry here is regular or archived, so the\n // \"new\" status the remote thread list has to exclude cannot occur.\n await this._mainThread.unstable_refetchThread();\n }\n\n public async switchToThread(\n threadId: string,\n _options?: { unarchive?: boolean },\n ): Promise<void> {\n if (this._mainThreadId === threadId) return;\n const onSwitchToThread = this.adapter.onSwitchToThread;\n if (!onSwitchToThread)\n throw new Error(\n \"External store adapter does not support switching to thread\",\n );\n await onSwitchToThread(threadId);\n }\n\n public async switchToNewThread(): Promise<void> {\n const onSwitchToNewThread = this.adapter.onSwitchToNewThread;\n if (!onSwitchToNewThread)\n throw new Error(\n \"External store adapter does not support switching to new thread\",\n );\n\n await onSwitchToNewThread();\n }\n\n public async rename(threadId: string, newTitle: string): Promise<void> {\n const onRename = this.adapter.onRename;\n if (!onRename)\n throw new Error(\"External store adapter does not support renaming\");\n\n await onRename(threadId, newTitle);\n }\n\n public async updateCustom(\n threadId: string,\n custom: Record<string, unknown> | undefined,\n ): Promise<void> {\n const onUpdateCustom = this.adapter.onUpdateCustom;\n if (!onUpdateCustom)\n throw new Error(\n \"External store adapter does not support updating custom metadata\",\n );\n\n await onUpdateCustom(threadId, custom);\n }\n\n public async detach(): Promise<void> {\n // no-op\n }\n\n public async archive(threadId: string): Promise<void> {\n const onArchive = this.adapter.onArchive;\n if (!onArchive)\n throw new Error(\"External store adapter does not support archiving\");\n\n await onArchive(threadId);\n }\n\n public async unarchive(threadId: string): Promise<void> {\n const onUnarchive = this.adapter.onUnarchive;\n if (!onUnarchive)\n throw new Error(\"External store adapter does not support unarchiving\");\n\n await onUnarchive(threadId);\n }\n\n public async delete(threadId: string): Promise<void> {\n const onDelete = this.adapter.onDelete;\n if (!onDelete)\n throw new Error(\"External store adapter does not support deleting\");\n\n await onDelete(threadId);\n }\n\n public initialize(\n threadId: string,\n ): Promise<{ remoteId: string; externalId: string | undefined }> {\n return Promise.resolve({ remoteId: threadId, externalId: undefined });\n }\n\n public generateTitle(): never {\n throw new Error(\"Method not implemented.\");\n }\n}\n"],"mappings":";;;AAWA,MAAMO,cAAcC,OAAOC,OAAO,CAAA,CAAE;AACpC,MAAMC,oBAAoB;AAC1B,MAAMC,kBAAkBH,OAAOC,OAAO,CAACC,iBAAiB,CAAC;AACzD,MAAME,iBAAiBJ,OAAOC,OAAO;CACnCI,IAAIH;CACJI,UAAUC,KAAAA;CACVC,YAAYD,KAAAA;CACZE,QAAQ;AACV,CAAC;AACD,MAAMC,mBAAmBC,QAAQC,QAAQ;AACzC,MAAMC,sBAAsBb,OAAOC,OAAO,GACvCC,oBAAoBE,eACvB,CAAC;AAED,IAAaU,qCAAb,cACUjB,iBAEV;CACE,gBAAgCK;CAChC,WAAsCC;CACtC,mBAA8CJ;CAC9C,cACEc;CACF,UAAkD,CAAC;CAEnD,IAAWS,YAAY;EACrB,OAAO,KAAKD,QAAQC,aAAa;CACnC;CAEA,IAAWC,cAAc,CAEzB;CAEA,IAAWC,YAAY;EACrB,OAAO,KAAKR;CACd;CAEA,IAAWS,oBAAoB;EAC7B,OAAO,KAAKR;CACd;CAEA,IAAWS,cAAc;EACvB,OAAO,KAAKR;CACd;CAEA,wBAA+B;EAC7B,OAAOR;CACT;CAEA;CAEA,IAAWmB,eAAe;EACxB,OAAO,KAAKd;CACd;CAEA;CAEAgB,YACEV,UAA0C,CAAC,GAC3CS,eACA;EACA,MAAM;EACN,KAAKA,gBAAgBA;EACrB,KAAKE,sBAAsBX,SAAS,IAAI;CAC1C;CAEA,2BAAkC;EAChC,OAAO,KAAKO;CACd;CAEA,uBAAqC;EACnC,MAAM,IAAIO,MAAM,yBAAyB;CAC3C;CAEA,YAAmBE,UAAkB;EACnC,OAAO,KAAKnB,YAAYmB;CAC1B;CAEA,sBACEhB,SACAiB,cAAc,OACd;EACA,MAAMC,kBAAkB,KAAKlB;EAC7B,KAAKA,UAAUA;EAEf,MAAME,cAAcF,QAAQgB,YAAYnC;EACxC,MAAMsC,aA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,UAAiC;EACnD,MAAMiC,WAAW,KAAKjD,QAAQiD;EAC9B,IAAI,CAACA,UACH,MAAM,IAAInC,MAAM,kDAAkD;EAEpE,MAAMmC,SAASjC,QAAQ;CACzB;CAEA,WACEA,UAC+D;EAC/D,OAAO1B,QAAQC,QAAQ;GAAEN,UAAU+B;GAAU7B,YAAYD,KAAAA;EAAU,CAAC;CACtE;CAEA,gBAA8B;EAC5B,MAAM,IAAI4B,MAAM,yBAAyB;CAC3C;AACF"}
|
|
@@ -6,8 +6,8 @@ import { RealtimeVoiceAdapter } from "../../adapters/voice.js";
|
|
|
6
6
|
import { ModelContextProvider } from "../../model-context/types.js";
|
|
7
7
|
import { ThreadMessageLike } from "../../runtime/utils/thread-message-like.js";
|
|
8
8
|
import { ExportedMessageRepository } from "../../runtime/utils/message-repository.js";
|
|
9
|
+
import { QueueItemState } from "../../runtime/queue/queue-item.js";
|
|
9
10
|
import { QueuePlacement } from "../../runtime/queue/external-thread-queue-adapter.js";
|
|
10
|
-
import { QueueItemState } from "../../store/scopes/queue-item.js";
|
|
11
11
|
import { AddToolResultOptions, RespondToToolApprovalOptions, ResumeRunConfig, ResumeToolCallOptions, RuntimeCapabilities, StartRunConfig, ThreadRuntimeCore, ThreadSuggestion } from "../../runtime/interfaces/thread-runtime-core.js";
|
|
12
12
|
import { BaseThreadRuntimeCore } from "../../runtime/base/base-thread-runtime-core.js";
|
|
13
13
|
import { ExternalStoreAdapter, ExternalStoreThreadListAdapter } from "./external-store-adapter.js";
|
|
@@ -37,6 +37,8 @@ declare class ExternalStoreThreadRuntimeCore extends BaseThreadRuntimeCore imple
|
|
|
37
37
|
suggestions: readonly ThreadSuggestion[];
|
|
38
38
|
extras: unknown;
|
|
39
39
|
private _converter;
|
|
40
|
+
private _pendingDeleteEvictions;
|
|
41
|
+
private _optimistic;
|
|
40
42
|
private _store;
|
|
41
43
|
private _getInitializePromise?;
|
|
42
44
|
__internal_setGetInitializePromise(getPromise: () => Promise<unknown> | undefined): void;
|
|
@@ -46,9 +48,25 @@ declare class ExternalStoreThreadRuntimeCore extends BaseThreadRuntimeCore imple
|
|
|
46
48
|
* snapshot — only when `adapter.unstable_enableToolInvocations === true`.
|
|
47
49
|
*/
|
|
48
50
|
private _toolInvocations;
|
|
51
|
+
private _toolStatuses;
|
|
52
|
+
private _effectiveIsRunning;
|
|
53
|
+
private _inTrackerUpdate;
|
|
54
|
+
private _pendingRunningRefresh;
|
|
55
|
+
/**
|
|
56
|
+
* Tracker mutations initiated by this class (setState, reset) can publish
|
|
57
|
+
* status changes synchronously. Re-entering the snapshot pipeline from
|
|
58
|
+
* inside them would feed the tracker a stale snapshot and consume the
|
|
59
|
+
* restore arming a reset just installed, so the running refresh is
|
|
60
|
+
* deferred until the mutation returns and stays off the tracker.
|
|
61
|
+
*/
|
|
62
|
+
private _runTrackerUpdate;
|
|
63
|
+
private _refreshEffectiveIsRunning;
|
|
64
|
+
private _hasExecutingTools;
|
|
65
|
+
private _getEffectiveIsRunning;
|
|
49
66
|
beginEdit(messageId: string): void;
|
|
50
67
|
constructor(contextProvider: ModelContextProvider, store: ExternalStoreAdapter<any>);
|
|
51
68
|
__internal_setAdapter(store: ExternalStoreAdapter<any>): void;
|
|
69
|
+
private _updateStoreSnapshot;
|
|
52
70
|
/**
|
|
53
71
|
* Feed the current message snapshot into the tool-invocations tracker.
|
|
54
72
|
* Opt-in via `adapter.unstable_enableToolInvocations: true`. The tracker
|
|
@@ -81,6 +99,7 @@ declare class ExternalStoreThreadRuntimeCore extends BaseThreadRuntimeCore imple
|
|
|
81
99
|
private _notifyBranchChange;
|
|
82
100
|
append(rawMessage: AppendMessage): Promise<void>;
|
|
83
101
|
deleteMessage(messageId: string): Promise<void>;
|
|
102
|
+
private _evictDeletedMessage;
|
|
84
103
|
getQueueItems(): readonly QueueItemState[];
|
|
85
104
|
getSteerQueueItems(): readonly QueueItemState[];
|
|
86
105
|
moveQueueItem(queueItemId: string, placement: QueuePlacement): void;
|
|
@@ -99,7 +118,7 @@ declare class ExternalStoreThreadRuntimeCore extends BaseThreadRuntimeCore imple
|
|
|
99
118
|
private dropEmptyOptimisticHead;
|
|
100
119
|
addToolResult(options: AddToolResultOptions): void;
|
|
101
120
|
resumeToolCall(options: ResumeToolCallOptions): void;
|
|
102
|
-
respondToToolApproval(options: RespondToToolApprovalOptions): void
|
|
121
|
+
respondToToolApproval(options: RespondToToolApprovalOptions): Promise<void>;
|
|
103
122
|
reset(initialMessages?: readonly ThreadMessageLike[]): void;
|
|
104
123
|
import(data: ExportedMessageRepository): void;
|
|
105
124
|
private updateMessages;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-store-thread-runtime-core.d.ts","names":[],"sources":["../../../src/runtimes/external-store/external-store-thread-runtime-core.ts"],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"external-store-thread-runtime-core.d.ts","names":[],"sources":["../../../src/runtimes/external-store/external-store-thread-runtime-core.ts"],"mappings":";;;;;;;;;;;;;;;;cAyEa,qBACX,oBACA,mBAAmB;cAKR,uCACH,iCACG;UAEH;MAiBG,gBAAY;UAIf;EACD;EACA;MACI;MAIA;YAKQ,6BAA6B;MAI5B,sEAAK,sDAAA;MAId;kBARqC;;;;;;;MAarC,iCAAiC;EAKrC,sBAAsB;EACtB;UAEC;UAUA;UAKA;UAEA;UAEA;EAED,mCACL,kBAAkB;UAKZ;;;;;UAMA;UACA;UACA;UACA;UACA;;;;;;;;UASA;UAaA;UAQA;UASA;EAIQ,UAAU;EAQxB,YAAA,iBAAiB,sBACjB,OAAO;EAMF,sBAAsB,OAAO;UAM5B;;;;;;;UA4PA;;;;;UAoFA;UACA;;;;;;;UAQA;EAWQ,eAAe;;;;;;;;;UA8BvB;EAaK,OAAO,YAAY,gBAAgB;EAqEnC,cAAc,oBAAoB;UA0CvC;EAkBD,0BA5DwC;EAkExC,+BANa;EAUb,cAAc,qBAAqB,WAAW;EAI9C,gBAAgB;EAIV,SAAS,QAAQ,iBAAiB;EAclC,UAAU,QAAQ,kBAAkB;EAO1C;EAOA,oBAAoB;;;;;;EAqBpB;EAKA;UAmFC;EAOD,cAAc,SAAS;EASvB,eAAe,SAAS;EAoBxB,sBACL,SAAS,+BACR;EAUa,MAAM,2BAA2B;EAMjC,OAAO,MAAM;UAQrB"}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { generateId } from "../../utils/id.js";
|
|
2
2
|
import { getThreadMessageText } from "../../utils/text.js";
|
|
3
3
|
import { fromThreadMessageLike } from "../../runtime/utils/thread-message-like.js";
|
|
4
|
-
import { bindExternalStoreMessage, getExternalStoreMessages } from "../../runtime/utils/external-store-message.js";
|
|
5
|
-
import {
|
|
4
|
+
import { FALLBACK_ID_PREFIX, bindExternalStoreMessage, getExternalStoreMessages } from "../../runtime/utils/external-store-message.js";
|
|
5
|
+
import { getContentAutoStatus, isAutoStatus } from "../../runtime/utils/auto-status.js";
|
|
6
6
|
import { ExportedMessageRepository, MessageRepository } from "../../runtime/utils/message-repository.js";
|
|
7
|
-
import { EMPTY_QUEUE_ITEMS } from "../../
|
|
7
|
+
import { EMPTY_QUEUE_ITEMS } from "../../runtime/queue/queue-item.js";
|
|
8
|
+
import { walkToolCallTree } from "../../runtime/utils/tool-call-tree.js";
|
|
8
9
|
import { BaseThreadRuntimeCore } from "../../runtime/base/base-thread-runtime-core.js";
|
|
9
10
|
import { captureThreadRuntimeGeneration, isThreadRuntimeGenerationCurrent } from "../../runtime/utils/thread-runtime-lifecycle.js";
|
|
10
11
|
import { ThreadMessageConverter } from "./thread-message-converter.js";
|
|
12
|
+
import { shallowArrayEqual } from "../../runtime/utils/external-message-conversion.js";
|
|
11
13
|
import { ToolInvocationTracker } from "../tool-invocations/ToolInvocationTracker.js";
|
|
14
|
+
import { shallowEqual } from "@assistant-ui/store/client";
|
|
12
15
|
//#region src/runtimes/external-store/external-store-thread-runtime-core.ts
|
|
13
16
|
const EMPTY_ARRAY = Object.freeze([]);
|
|
14
17
|
const observeAdapterCallback = (name, result) => {
|
|
@@ -16,12 +19,6 @@ const observeAdapterCallback = (name, result) => {
|
|
|
16
19
|
console.error(`[ExternalStoreThreadRuntimeCore] ${name} callback rejected`, error);
|
|
17
20
|
});
|
|
18
21
|
};
|
|
19
|
-
const shallowEqual = (a, b) => {
|
|
20
|
-
const aKeys = Object.keys(a);
|
|
21
|
-
if (aKeys.length !== Object.keys(b).length) return false;
|
|
22
|
-
for (const key of aKeys) if (a[key] !== b[key]) return false;
|
|
23
|
-
return true;
|
|
24
|
-
};
|
|
25
22
|
const hasUpcomingMessage = (isRunning, messages) => {
|
|
26
23
|
return isRunning && messages[messages.length - 1]?.role !== "assistant";
|
|
27
24
|
};
|
|
@@ -52,6 +49,7 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
52
49
|
return this._store.isLoading ?? false;
|
|
53
50
|
}
|
|
54
51
|
get isRunning() {
|
|
52
|
+
if (this._hasExecutingTools(this._store)) return true;
|
|
55
53
|
return this._store.isRunning;
|
|
56
54
|
}
|
|
57
55
|
_getBaseMessages() {
|
|
@@ -70,6 +68,8 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
70
68
|
suggestions = [];
|
|
71
69
|
extras = void 0;
|
|
72
70
|
_converter = new ThreadMessageConverter();
|
|
71
|
+
_pendingDeleteEvictions = /* @__PURE__ */ new Set();
|
|
72
|
+
_optimistic = null;
|
|
73
73
|
_store;
|
|
74
74
|
_getInitializePromise;
|
|
75
75
|
__internal_setGetInitializePromise(getPromise) {
|
|
@@ -81,6 +81,45 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
81
81
|
* snapshot — only when `adapter.unstable_enableToolInvocations === true`.
|
|
82
82
|
*/
|
|
83
83
|
_toolInvocations = null;
|
|
84
|
+
_toolStatuses = /* @__PURE__ */ new Map();
|
|
85
|
+
_effectiveIsRunning = false;
|
|
86
|
+
_inTrackerUpdate = false;
|
|
87
|
+
_pendingRunningRefresh = false;
|
|
88
|
+
/**
|
|
89
|
+
* Tracker mutations initiated by this class (setState, reset) can publish
|
|
90
|
+
* status changes synchronously. Re-entering the snapshot pipeline from
|
|
91
|
+
* inside them would feed the tracker a stale snapshot and consume the
|
|
92
|
+
* restore arming a reset just installed, so the running refresh is
|
|
93
|
+
* deferred until the mutation returns and stays off the tracker.
|
|
94
|
+
*/
|
|
95
|
+
_runTrackerUpdate(fn) {
|
|
96
|
+
this._inTrackerUpdate = true;
|
|
97
|
+
try {
|
|
98
|
+
fn();
|
|
99
|
+
} finally {
|
|
100
|
+
this._inTrackerUpdate = false;
|
|
101
|
+
}
|
|
102
|
+
if (this._pendingRunningRefresh) {
|
|
103
|
+
this._pendingRunningRefresh = false;
|
|
104
|
+
this._refreshEffectiveIsRunning();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_refreshEffectiveIsRunning() {
|
|
108
|
+
const isRunning = this._getEffectiveIsRunning(this._store);
|
|
109
|
+
if (this._effectiveIsRunning === isRunning) return;
|
|
110
|
+
this._effectiveIsRunning = isRunning;
|
|
111
|
+
this._notifyEventSubscribers(isRunning ? "runStart" : "runEnd", {});
|
|
112
|
+
this._notifySubscribers();
|
|
113
|
+
}
|
|
114
|
+
_hasExecutingTools(store) {
|
|
115
|
+
if (store.unstable_enableToolInvocations !== true) return false;
|
|
116
|
+
if (this._toolInvocations === null) return false;
|
|
117
|
+
for (const status of this._toolStatuses.values()) if (status.type === "executing") return true;
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
_getEffectiveIsRunning(store) {
|
|
121
|
+
return (store.isRunning ?? false) || this._hasExecutingTools(store);
|
|
122
|
+
}
|
|
84
123
|
beginEdit(messageId) {
|
|
85
124
|
if (!this._store.onEdit) throw new Error("Runtime does not support editing.");
|
|
86
125
|
super.beginEdit(messageId);
|
|
@@ -91,11 +130,21 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
91
130
|
}
|
|
92
131
|
__internal_setAdapter(store) {
|
|
93
132
|
if (this._store === store) return;
|
|
94
|
-
|
|
133
|
+
this._updateStoreSnapshot(store);
|
|
134
|
+
}
|
|
135
|
+
_updateStoreSnapshot(store) {
|
|
136
|
+
const previousIsRunning = this._effectiveIsRunning;
|
|
95
137
|
this.isDisabled = store.isDisabled ?? false;
|
|
96
138
|
this.isSendDisabled = store.isSendDisabled ?? false;
|
|
97
139
|
const oldStore = this._store;
|
|
98
140
|
this._store = store;
|
|
141
|
+
const isRunning = this._getEffectiveIsRunning(store);
|
|
142
|
+
const repositoryInstance = store.unstable_messageRepositoryInstance;
|
|
143
|
+
const repositoryChanged = repositoryInstance !== void 0 && repositoryInstance !== this.repository;
|
|
144
|
+
if (repositoryChanged) {
|
|
145
|
+
this.repository = repositoryInstance;
|
|
146
|
+
this._pendingDeleteEvictions.clear();
|
|
147
|
+
}
|
|
99
148
|
if (oldStore?.queue !== store.queue) {
|
|
100
149
|
this._transformedQueue = void 0;
|
|
101
150
|
store.queue?.__internal_setDispatchTransform?.((message) => {
|
|
@@ -129,26 +178,27 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
129
178
|
if (!shallowEqual(this._capabilities, newCapabilities)) this._capabilities = newCapabilities;
|
|
130
179
|
let messages;
|
|
131
180
|
if (store.messageRepository) {
|
|
132
|
-
if (oldStore && oldStore.isRunning === store.isRunning && oldStore.messageRepository === store.messageRepository) {
|
|
181
|
+
if (oldStore && !repositoryChanged && oldStore.isRunning === store.isRunning && oldStore.messageRepository === store.messageRepository && previousIsRunning === isRunning) {
|
|
133
182
|
this._notifySubscribers();
|
|
134
183
|
return;
|
|
135
184
|
}
|
|
136
185
|
const incoming = store.messageRepository.messages;
|
|
137
186
|
const headId = store.messageRepository.headId ?? incoming.at(-1)?.message.id ?? null;
|
|
138
|
-
if (oldStore && oldStore.messageRepository === store.messageRepository) {
|
|
187
|
+
if (oldStore && !repositoryChanged && oldStore.messageRepository === store.messageRepository) {
|
|
139
188
|
this.repository.resetHead(headId);
|
|
140
189
|
messages = this.repository.getMessages();
|
|
141
190
|
} else {
|
|
142
191
|
const incomingIds = new Set(incoming.map(({ message }) => message.id));
|
|
143
192
|
for (const { message, parentId } of incoming) this.repository.addOrUpdateMessage(parentId, message);
|
|
144
193
|
for (const { message } of this.repository.export().messages) if (!incomingIds.has(message.id)) this.repository.deleteMessage(message.id);
|
|
194
|
+
this._pendingDeleteEvictions.clear();
|
|
145
195
|
this.repository.resetHead(headId);
|
|
146
196
|
messages = this.repository.getMessages();
|
|
147
197
|
}
|
|
148
198
|
} else if (store.messages) {
|
|
149
199
|
if (oldStore) {
|
|
150
200
|
if (oldStore.convertMessage !== store.convertMessage) this._converter = new ThreadMessageConverter();
|
|
151
|
-
else if (oldStore.isRunning === store.isRunning && oldStore.messages === store.messages) {
|
|
201
|
+
else if (!repositoryChanged && oldStore.isRunning === store.isRunning && oldStore.messages === store.messages && previousIsRunning === isRunning) {
|
|
152
202
|
this._notifySubscribers();
|
|
153
203
|
return;
|
|
154
204
|
}
|
|
@@ -156,10 +206,20 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
156
206
|
messages = !store.convertMessage ? store.messages : this._converter.convertMessages(store.messages, (cache, m, idx) => {
|
|
157
207
|
if (!store.convertMessage) return m;
|
|
158
208
|
const isLast = idx === (store.messages?.length ?? 0) - 1;
|
|
159
|
-
const
|
|
160
|
-
if (cache && (cache.role !== "assistant" || !isAutoStatus(cache.status) || cache.status ===
|
|
209
|
+
const fallbackId = `${FALLBACK_ID_PREFIX}${idx}`;
|
|
210
|
+
if (cache && (cache.role !== "assistant" || !isAutoStatus(cache.status) || cache.status === getContentAutoStatus(cache.content, isLast, isRunning))) {
|
|
211
|
+
if (cache.id.startsWith("__external_store_fallback_") && cache.id !== fallbackId) {
|
|
212
|
+
const updated = {
|
|
213
|
+
...cache,
|
|
214
|
+
id: fallbackId
|
|
215
|
+
};
|
|
216
|
+
bindExternalStoreMessage(updated, m);
|
|
217
|
+
return updated;
|
|
218
|
+
}
|
|
219
|
+
return cache;
|
|
220
|
+
}
|
|
161
221
|
const messageLike = store.convertMessage(m, idx);
|
|
162
|
-
const newMessage = fromThreadMessageLike(messageLike,
|
|
222
|
+
const newMessage = fromThreadMessageLike(messageLike, fallbackId, getContentAutoStatus(messageLike.content, isLast, isRunning));
|
|
163
223
|
bindExternalStoreMessage(newMessage, m);
|
|
164
224
|
return newMessage;
|
|
165
225
|
});
|
|
@@ -180,24 +240,46 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
180
240
|
const parent = messages[i - 1];
|
|
181
241
|
this.repository.addOrUpdateMessage(parent?.id ?? null, message);
|
|
182
242
|
}
|
|
243
|
+
if (this._pendingDeleteEvictions.size > 0) {
|
|
244
|
+
const incomingIds = new Set(messages.map((m) => m.id));
|
|
245
|
+
for (const id of this._pendingDeleteEvictions) {
|
|
246
|
+
this._pendingDeleteEvictions.delete(id);
|
|
247
|
+
if (incomingIds.has(id)) continue;
|
|
248
|
+
try {
|
|
249
|
+
this.repository.getMessage(id);
|
|
250
|
+
} catch {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
this.repository.deleteMessage(id);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
183
256
|
} else throw new Error("ExternalStoreAdapter must provide either 'messages' or 'messageRepository'");
|
|
184
257
|
if (messages.length > 0) this.ensureInitialized();
|
|
185
|
-
|
|
186
|
-
|
|
258
|
+
this._effectiveIsRunning = isRunning;
|
|
259
|
+
if (previousIsRunning !== isRunning) {
|
|
260
|
+
if (isRunning) this._notifyEventSubscribers("runStart", {});
|
|
187
261
|
else this._notifyEventSubscribers("runEnd", {});
|
|
188
262
|
}
|
|
189
263
|
let optimisticId = null;
|
|
190
264
|
if (hasUpcomingMessage(isRunning, messages)) {
|
|
191
|
-
|
|
192
|
-
this.
|
|
265
|
+
const parentId = messages.at(-1)?.id ?? null;
|
|
266
|
+
if (this._optimistic?.parentId !== parentId) this._optimistic = {
|
|
267
|
+
id: generateId(),
|
|
268
|
+
parentId
|
|
269
|
+
};
|
|
270
|
+
optimisticId = this._optimistic.id;
|
|
271
|
+
this.repository.addOrUpdateMessage(parentId, fromThreadMessageLike({
|
|
193
272
|
role: "assistant",
|
|
194
273
|
content: [],
|
|
195
274
|
metadata: { isOptimistic: true }
|
|
196
275
|
}, optimisticId, { type: "running" }));
|
|
197
276
|
}
|
|
277
|
+
if (optimisticId === null) this._optimistic = null;
|
|
198
278
|
this.repository.resetHead(optimisticId ?? messages.at(-1)?.id ?? null);
|
|
199
|
-
|
|
200
|
-
this.
|
|
279
|
+
const messagesSnapshot = this.repository.getMessages();
|
|
280
|
+
if (!this._messages || !shallowArrayEqual(this._messages, messagesSnapshot)) this._messages = messagesSnapshot;
|
|
281
|
+
if (repositoryChanged) this._runTrackerUpdate(() => this._toolInvocations?.reset());
|
|
282
|
+
this._runTrackerUpdate(() => this._driveToolInvocations());
|
|
201
283
|
this._notifySubscribers();
|
|
202
284
|
}
|
|
203
285
|
/**
|
|
@@ -211,6 +293,7 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
211
293
|
if (this._toolInvocations) {
|
|
212
294
|
this._toolInvocations.reset();
|
|
213
295
|
this._toolInvocations = null;
|
|
296
|
+
this._toolStatuses = /* @__PURE__ */ new Map();
|
|
214
297
|
this._store.setToolStatuses?.({});
|
|
215
298
|
}
|
|
216
299
|
return;
|
|
@@ -234,12 +317,21 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
234
317
|
}
|
|
235
318
|
},
|
|
236
319
|
onStatusesChange: (statuses) => {
|
|
237
|
-
this.
|
|
320
|
+
const hadExecutingTools = this._hasExecutingTools(this._store);
|
|
321
|
+
this._toolStatuses = statuses;
|
|
322
|
+
try {
|
|
323
|
+
this._store.setToolStatuses?.(Object.fromEntries(statuses));
|
|
324
|
+
} finally {
|
|
325
|
+
if (hadExecutingTools !== this._hasExecutingTools(this._store)) {
|
|
326
|
+
if (this._inTrackerUpdate) this._pendingRunningRefresh = true;
|
|
327
|
+
else this._updateStoreSnapshot(this._store);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
238
330
|
}
|
|
239
|
-
});
|
|
331
|
+
}, (toolCall) => this._store.unstable_isClientToolCall?.(toolCall));
|
|
240
332
|
this._toolInvocations.setState({
|
|
241
333
|
messages: this._messages,
|
|
242
|
-
isRunning: this._store
|
|
334
|
+
isRunning: this._getEffectiveIsRunning(this._store),
|
|
243
335
|
...this._store.isLoading !== void 0 && { isLoading: this._store.isLoading }
|
|
244
336
|
});
|
|
245
337
|
}
|
|
@@ -258,27 +350,18 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
258
350
|
_findMessageIdForToolCall(toolCallId) {
|
|
259
351
|
if (this._messagesForToolCallIndex !== this._messages) {
|
|
260
352
|
this._toolCallToMessageId.clear();
|
|
261
|
-
const
|
|
262
|
-
for (const message of messages) {
|
|
263
|
-
if (!Array.isArray(message.content)) continue;
|
|
264
|
-
for (const part of message.content) {
|
|
265
|
-
if (!part || part.type !== "tool-call") continue;
|
|
266
|
-
this._toolCallToMessageId.set(part.toolCallId, message.id);
|
|
267
|
-
if (part.messages) visit(part.messages);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
visit(this._messages);
|
|
353
|
+
for (const { part, messageId } of walkToolCallTree(this._messages)) this._toolCallToMessageId.set(part.toolCallId, messageId);
|
|
272
354
|
this._messagesForToolCallIndex = this._messages;
|
|
273
355
|
}
|
|
274
356
|
return this._toolCallToMessageId.get(toolCallId);
|
|
275
357
|
}
|
|
276
358
|
switchToBranch(branchId) {
|
|
277
359
|
if (!this._store.setMessages) throw new Error("Runtime does not support switching branches.");
|
|
278
|
-
if (this._store
|
|
360
|
+
if (this._getEffectiveIsRunning(this._store)) return;
|
|
279
361
|
const onBranchChange = this._store.unstable_onBranchChange;
|
|
280
362
|
const previousHeadId = onBranchChange ? this.repository.canonicalHeadId : null;
|
|
281
363
|
this.repository.switchToBranch(branchId);
|
|
364
|
+
this._pendingDeleteEvictions.clear();
|
|
282
365
|
this.updateMessages(this.repository.getMessages());
|
|
283
366
|
if (onBranchChange) this._notifyBranchChange(previousHeadId, onBranchChange);
|
|
284
367
|
}
|
|
@@ -307,28 +390,48 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
307
390
|
if (!isEdit && this._store.queue) {
|
|
308
391
|
if (initPromise) await initPromise;
|
|
309
392
|
if (!isThreadRuntimeGenerationCurrent(this, generation)) return;
|
|
310
|
-
if (message.steer ?? this._store
|
|
393
|
+
if (message.steer ?? this._getEffectiveIsRunning(this._store)) this._store.queue.steer(message);
|
|
311
394
|
else this._store.queue.enqueue(message);
|
|
312
395
|
return;
|
|
313
396
|
}
|
|
314
397
|
initPromise?.catch(() => {});
|
|
315
|
-
if (message.startRun ?? message.role === "user") await this._toolInvocations?.abort();
|
|
398
|
+
if (message.startRun ?? message.role === "user") await this._toolInvocations?.abort({ discardPending: true });
|
|
316
399
|
if (!isThreadRuntimeGenerationCurrent(this, generation)) return;
|
|
317
400
|
if (isEdit) {
|
|
318
401
|
if (!this._store.onEdit) throw new Error("Runtime does not support editing messages.");
|
|
402
|
+
this._pendingDeleteEvictions.clear();
|
|
319
403
|
await this._store.onEdit(message);
|
|
320
404
|
} else await this._store.onNew(message);
|
|
321
405
|
}
|
|
322
406
|
async deleteMessage(messageId) {
|
|
323
407
|
if (this._store.onDelete) {
|
|
324
|
-
|
|
408
|
+
if (this.repository.getMessages().some((m) => m.id === messageId)) this._pendingDeleteEvictions.add(messageId);
|
|
409
|
+
try {
|
|
410
|
+
await this._store.onDelete(messageId);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
this._pendingDeleteEvictions.delete(messageId);
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
325
415
|
return;
|
|
326
416
|
}
|
|
327
417
|
if (!this._store.setMessages) throw new Error("Runtime does not support deleting messages.");
|
|
328
|
-
if (this._store
|
|
418
|
+
if (this._getEffectiveIsRunning(this._store)) await this._toolInvocations?.abort();
|
|
329
419
|
const messages = this.repository.getMessages();
|
|
330
420
|
if (messages.findIndex((m) => m.id === messageId) === -1) throw new Error("Message not found.");
|
|
421
|
+
this._pendingDeleteEvictions.clear();
|
|
331
422
|
this.updateMessages(messages.filter((message) => message.id !== messageId));
|
|
423
|
+
this._evictDeletedMessage(messageId);
|
|
424
|
+
}
|
|
425
|
+
_evictDeletedMessage(messageId) {
|
|
426
|
+
if (messageId.startsWith("__external_store_fallback_")) return;
|
|
427
|
+
try {
|
|
428
|
+
this.repository.getMessage(messageId);
|
|
429
|
+
} catch {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
this.repository.deleteMessage(messageId);
|
|
433
|
+
this._messages = this.repository.getMessages();
|
|
434
|
+
this._notifySubscribers();
|
|
332
435
|
}
|
|
333
436
|
getQueueItems() {
|
|
334
437
|
return this._store?.queue?.items ?? EMPTY_QUEUE_ITEMS;
|
|
@@ -344,7 +447,8 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
344
447
|
}
|
|
345
448
|
async startRun(config) {
|
|
346
449
|
if (!this._store.onReload) throw new Error("Runtime does not support reloading messages.");
|
|
347
|
-
|
|
450
|
+
this._pendingDeleteEvictions.clear();
|
|
451
|
+
await this._toolInvocations?.abort({ discardPending: true });
|
|
348
452
|
await this._store.onReload(config.parentId, config);
|
|
349
453
|
}
|
|
350
454
|
async resumeRun(config) {
|
|
@@ -357,7 +461,7 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
357
461
|
}
|
|
358
462
|
importExternalState(state) {
|
|
359
463
|
if (!this._store.onLoadExternalState) throw new Error("Runtime does not support importing external states.");
|
|
360
|
-
this._toolInvocations?.reset();
|
|
464
|
+
this._runTrackerUpdate(() => this._toolInvocations?.reset());
|
|
361
465
|
this._store.onLoadExternalState(state);
|
|
362
466
|
}
|
|
363
467
|
/**
|
|
@@ -366,13 +470,13 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
366
470
|
* without run-cancel semantics (`onCancel`, composer draft restoration).
|
|
367
471
|
*/
|
|
368
472
|
unstable_notifySessionReset() {
|
|
369
|
-
this._toolInvocations?.reset();
|
|
473
|
+
this._runTrackerUpdate(() => this._toolInvocations?.reset());
|
|
370
474
|
this._store.queue?.__internal_notifyCancelled?.();
|
|
371
475
|
}
|
|
372
476
|
cancelRun() {
|
|
373
477
|
if (!this._store.onCancel) throw new Error("Runtime does not support cancelling runs.");
|
|
374
478
|
const generation = captureThreadRuntimeGeneration(this);
|
|
375
|
-
this._toolInvocations?.abort();
|
|
479
|
+
this._toolInvocations?.abort({ discardPending: true });
|
|
376
480
|
this._store.queue?.__internal_notifyCancelled?.();
|
|
377
481
|
observeAdapterCallback("onCancel", this._store.onCancel());
|
|
378
482
|
this.dropEmptyOptimisticHead();
|
|
@@ -424,7 +528,11 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
|
|
|
424
528
|
}
|
|
425
529
|
respondToToolApproval(options) {
|
|
426
530
|
if (!this._store.onRespondToToolApproval) throw new Error("Runtime does not support tool approvals.");
|
|
427
|
-
|
|
531
|
+
try {
|
|
532
|
+
return Promise.resolve(this._store.onRespondToToolApproval(options));
|
|
533
|
+
} catch (error) {
|
|
534
|
+
return Promise.reject(error);
|
|
535
|
+
}
|
|
428
536
|
}
|
|
429
537
|
reset(initialMessages) {
|
|
430
538
|
const repo = new MessageRepository();
|