@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
|
@@ -5,9 +5,13 @@ import type {
|
|
|
5
5
|
ChatModelRunOptions,
|
|
6
6
|
ChatModelRunResult,
|
|
7
7
|
} from "../../runtime/utils/chat-model-adapter";
|
|
8
|
-
import type { AppendMessage } from "../../types/message";
|
|
8
|
+
import type { AppendMessage, ToolCallMessagePart } from "../../types/message";
|
|
9
9
|
import type { LocalRuntimeOptionsBase } from "./local-runtime-options";
|
|
10
|
-
import
|
|
10
|
+
import {
|
|
11
|
+
ExportedMessageRepository,
|
|
12
|
+
type ExportedMessageRepositoryItem,
|
|
13
|
+
} from "../../runtime/utils/message-repository";
|
|
14
|
+
import type { ThreadMessageLike } from "../../runtime/utils/thread-message-like";
|
|
11
15
|
import type { ThreadSuggestion } from "../../runtime/interfaces/thread-runtime-core";
|
|
12
16
|
import { isMessageNotSentError } from "../../types/error";
|
|
13
17
|
|
|
@@ -57,7 +61,7 @@ const userMessage = (text: string): AppendMessage => ({
|
|
|
57
61
|
|
|
58
62
|
const toolCallPart = (
|
|
59
63
|
toolName: string,
|
|
60
|
-
approval?:
|
|
64
|
+
approval?: ToolCallMessagePart["approval"],
|
|
61
65
|
) => ({
|
|
62
66
|
type: "tool-call" as const,
|
|
63
67
|
toolCallId: `call-${toolName}`,
|
|
@@ -69,7 +73,7 @@ const toolCallPart = (
|
|
|
69
73
|
|
|
70
74
|
const toolCallResult = (
|
|
71
75
|
toolName: string,
|
|
72
|
-
approval?:
|
|
76
|
+
approval?: ToolCallMessagePart["approval"],
|
|
73
77
|
): ChatModelRunResult => ({
|
|
74
78
|
content: [toolCallPart(toolName, approval)],
|
|
75
79
|
status: { type: "requires-action", reason: "tool-calls" },
|
|
@@ -481,6 +485,32 @@ describe("LocalThreadRuntimeCore tool approvals", () => {
|
|
|
481
485
|
});
|
|
482
486
|
});
|
|
483
487
|
|
|
488
|
+
it("records a free-form answer alongside the decision", async () => {
|
|
489
|
+
const { thread, runs } = createApprovalThread(
|
|
490
|
+
toolCallResult("send_email", { id: "a1", display: "text" }),
|
|
491
|
+
);
|
|
492
|
+
|
|
493
|
+
await thread.append(userMessage("send an email"));
|
|
494
|
+
await flush();
|
|
495
|
+
|
|
496
|
+
await thread.respondToToolApproval({
|
|
497
|
+
approvalId: "a1",
|
|
498
|
+
approved: true,
|
|
499
|
+
text: "Quarterly update",
|
|
500
|
+
});
|
|
501
|
+
await flush();
|
|
502
|
+
|
|
503
|
+
const toolCall = runs[1]!
|
|
504
|
+
.unstable_getMessage()
|
|
505
|
+
.content.find((part) => part.type === "tool-call");
|
|
506
|
+
expect(toolCall?.approval).toEqual({
|
|
507
|
+
id: "a1",
|
|
508
|
+
display: "text",
|
|
509
|
+
approved: true,
|
|
510
|
+
text: "Quarterly update",
|
|
511
|
+
});
|
|
512
|
+
});
|
|
513
|
+
|
|
484
514
|
it("treats a terminal resolution as non-pending and continues the run", async () => {
|
|
485
515
|
const { thread, runs } = createApprovalThread(
|
|
486
516
|
toolCallResult("deploy", { id: "a1", resolution: "expired" }),
|
|
@@ -2002,3 +2032,170 @@ describe("LocalRuntimeCore composer.canCancel", () => {
|
|
|
2002
2032
|
thread.cancelRun();
|
|
2003
2033
|
});
|
|
2004
2034
|
});
|
|
2035
|
+
|
|
2036
|
+
describe("LocalThreadRuntimeCore imported approvals", () => {
|
|
2037
|
+
const pausedOnApproval = (
|
|
2038
|
+
approval: { id: string } | undefined,
|
|
2039
|
+
extra: Record<string, unknown> = {},
|
|
2040
|
+
): ThreadMessageLike[] => [
|
|
2041
|
+
{ role: "user", content: [{ type: "text", text: "send an email" }] },
|
|
2042
|
+
{
|
|
2043
|
+
role: "assistant",
|
|
2044
|
+
content: [
|
|
2045
|
+
{
|
|
2046
|
+
type: "tool-call",
|
|
2047
|
+
toolCallId: "call-send_email",
|
|
2048
|
+
toolName: "send_email",
|
|
2049
|
+
args: {},
|
|
2050
|
+
argsText: "{}",
|
|
2051
|
+
...(approval !== undefined ? { approval } : {}),
|
|
2052
|
+
...extra,
|
|
2053
|
+
},
|
|
2054
|
+
],
|
|
2055
|
+
},
|
|
2056
|
+
];
|
|
2057
|
+
|
|
2058
|
+
const createImportedThread = (
|
|
2059
|
+
initialMessages: ThreadMessageLike[],
|
|
2060
|
+
history?: LocalRuntimeOptionsBase["adapters"]["history"],
|
|
2061
|
+
) => {
|
|
2062
|
+
const runs: ChatModelRunOptions[] = [];
|
|
2063
|
+
const core = new LocalRuntimeCore(
|
|
2064
|
+
{
|
|
2065
|
+
adapters: {
|
|
2066
|
+
chatModel: {
|
|
2067
|
+
async run(options) {
|
|
2068
|
+
runs.push(options);
|
|
2069
|
+
return { content: [{ type: "text", text: "done" }] };
|
|
2070
|
+
},
|
|
2071
|
+
},
|
|
2072
|
+
...(history !== undefined && { history }),
|
|
2073
|
+
},
|
|
2074
|
+
unstable_humanToolNames: ["send_email"],
|
|
2075
|
+
},
|
|
2076
|
+
initialMessages,
|
|
2077
|
+
);
|
|
2078
|
+
return { thread: core.threads.getMainThreadRuntimeCore(), runs };
|
|
2079
|
+
};
|
|
2080
|
+
|
|
2081
|
+
it("resumes the run after approving an imported pending approval", async () => {
|
|
2082
|
+
const { thread, runs } = createImportedThread(
|
|
2083
|
+
pausedOnApproval({ id: "a1" }),
|
|
2084
|
+
);
|
|
2085
|
+
|
|
2086
|
+
expect(thread.messages.at(-1)?.status).toMatchObject({
|
|
2087
|
+
type: "requires-action",
|
|
2088
|
+
reason: "tool-calls",
|
|
2089
|
+
});
|
|
2090
|
+
|
|
2091
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: true });
|
|
2092
|
+
await flush();
|
|
2093
|
+
|
|
2094
|
+
expect(runs).toHaveLength(1);
|
|
2095
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
2096
|
+
});
|
|
2097
|
+
|
|
2098
|
+
it("keeps the interrupt reason for an imported interrupted tool call", () => {
|
|
2099
|
+
const { thread } = createImportedThread(
|
|
2100
|
+
pausedOnApproval(undefined, {
|
|
2101
|
+
interrupt: { type: "human", payload: { question: "which one?" } },
|
|
2102
|
+
}),
|
|
2103
|
+
);
|
|
2104
|
+
|
|
2105
|
+
expect(thread.messages.at(-1)?.status).toMatchObject({
|
|
2106
|
+
type: "requires-action",
|
|
2107
|
+
reason: "interrupt",
|
|
2108
|
+
});
|
|
2109
|
+
});
|
|
2110
|
+
|
|
2111
|
+
it("resumes the run after approving an approval restored by the history adapter", async () => {
|
|
2112
|
+
const { thread, runs } = createImportedThread([], {
|
|
2113
|
+
async load() {
|
|
2114
|
+
return ExportedMessageRepository.fromArray(
|
|
2115
|
+
pausedOnApproval({ id: "a1" }),
|
|
2116
|
+
);
|
|
2117
|
+
},
|
|
2118
|
+
async append() {},
|
|
2119
|
+
async update() {},
|
|
2120
|
+
});
|
|
2121
|
+
|
|
2122
|
+
thread.__internal_load();
|
|
2123
|
+
await flush();
|
|
2124
|
+
|
|
2125
|
+
expect(thread.messages.at(-1)?.status).toMatchObject({
|
|
2126
|
+
type: "requires-action",
|
|
2127
|
+
reason: "tool-calls",
|
|
2128
|
+
});
|
|
2129
|
+
|
|
2130
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: true });
|
|
2131
|
+
await flush();
|
|
2132
|
+
|
|
2133
|
+
expect(runs).toHaveLength(1);
|
|
2134
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
2135
|
+
});
|
|
2136
|
+
|
|
2137
|
+
it("normalizes a serialized approval pause that lost its auto-status marker", async () => {
|
|
2138
|
+
const { thread, runs } = createImportedThread([]);
|
|
2139
|
+
thread.import(
|
|
2140
|
+
JSON.parse(
|
|
2141
|
+
JSON.stringify(
|
|
2142
|
+
ExportedMessageRepository.fromArray(pausedOnApproval({ id: "a1" })),
|
|
2143
|
+
),
|
|
2144
|
+
),
|
|
2145
|
+
);
|
|
2146
|
+
|
|
2147
|
+
expect(thread.messages.at(-1)?.status).toMatchObject({
|
|
2148
|
+
type: "requires-action",
|
|
2149
|
+
reason: "tool-calls",
|
|
2150
|
+
});
|
|
2151
|
+
|
|
2152
|
+
thread.respondToToolApproval({ approvalId: "a1", approved: true });
|
|
2153
|
+
await flush();
|
|
2154
|
+
|
|
2155
|
+
expect(runs).toHaveLength(1);
|
|
2156
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
2157
|
+
});
|
|
2158
|
+
|
|
2159
|
+
it("completes an imported interrupt that has nothing left to act on", () => {
|
|
2160
|
+
const { thread } = createImportedThread([
|
|
2161
|
+
{ role: "user", content: [{ type: "text", text: "send an email" }] },
|
|
2162
|
+
{
|
|
2163
|
+
role: "assistant",
|
|
2164
|
+
status: { type: "requires-action", reason: "interrupt" },
|
|
2165
|
+
content: [
|
|
2166
|
+
{
|
|
2167
|
+
type: "tool-call",
|
|
2168
|
+
toolCallId: "call-send_email",
|
|
2169
|
+
toolName: "send_email",
|
|
2170
|
+
args: {},
|
|
2171
|
+
argsText: "{}",
|
|
2172
|
+
result: { sent: true },
|
|
2173
|
+
},
|
|
2174
|
+
],
|
|
2175
|
+
} as ThreadMessageLike,
|
|
2176
|
+
]);
|
|
2177
|
+
|
|
2178
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
2179
|
+
});
|
|
2180
|
+
|
|
2181
|
+
it("resumes the run after adding a result to an imported resultless tool call", async () => {
|
|
2182
|
+
const { thread, runs } = createImportedThread(pausedOnApproval(undefined));
|
|
2183
|
+
|
|
2184
|
+
expect(thread.messages.at(-1)?.status).toMatchObject({
|
|
2185
|
+
type: "requires-action",
|
|
2186
|
+
reason: "tool-calls",
|
|
2187
|
+
});
|
|
2188
|
+
|
|
2189
|
+
thread.addToolResult({
|
|
2190
|
+
messageId: thread.messages.at(-1)!.id,
|
|
2191
|
+
toolCallId: "call-send_email",
|
|
2192
|
+
toolName: "send_email",
|
|
2193
|
+
result: { sent: true },
|
|
2194
|
+
isError: false,
|
|
2195
|
+
});
|
|
2196
|
+
await flush();
|
|
2197
|
+
|
|
2198
|
+
expect(runs).toHaveLength(1);
|
|
2199
|
+
expect(thread.messages.at(-1)?.status?.type).toBe("complete");
|
|
2200
|
+
});
|
|
2201
|
+
});
|
|
@@ -5,6 +5,8 @@ import type {
|
|
|
5
5
|
ChatModelRunResult,
|
|
6
6
|
} from "../../runtime/utils/chat-model-adapter";
|
|
7
7
|
import { shouldContinue } from "./should-continue";
|
|
8
|
+
import { getAutoStatus } from "../../runtime/utils/auto-status";
|
|
9
|
+
import type { ExportedMessageRepository } from "../../runtime/utils/message-repository";
|
|
8
10
|
import type { LocalRuntimeOptionsBase } from "./local-runtime-options";
|
|
9
11
|
import { consumeSuggestionResult } from "../../adapters/suggestion";
|
|
10
12
|
import type {
|
|
@@ -21,7 +23,7 @@ import type {
|
|
|
21
23
|
AppendMessage,
|
|
22
24
|
ThreadAssistantMessage,
|
|
23
25
|
} from "../../types/message";
|
|
24
|
-
import type { RunConfig } from "../../types/message";
|
|
26
|
+
import type { RunConfig, ThreadMessage } from "../../types/message";
|
|
25
27
|
import { MessageNotSentError, toAssistantError } from "../../types/error";
|
|
26
28
|
import type { ModelContextProvider } from "../../model-context/types";
|
|
27
29
|
import {
|
|
@@ -32,7 +34,7 @@ import type { QueuePlacement } from "../../runtime/queue/external-thread-queue-a
|
|
|
32
34
|
import {
|
|
33
35
|
EMPTY_QUEUE_ITEMS,
|
|
34
36
|
type QueueItemState,
|
|
35
|
-
} from "../../
|
|
37
|
+
} from "../../runtime/queue/queue-item";
|
|
36
38
|
import {
|
|
37
39
|
captureThreadRuntimeGeneration,
|
|
38
40
|
invalidateThreadRuntime,
|
|
@@ -49,6 +51,45 @@ class AbortError extends Error {
|
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
|
|
54
|
+
// `shouldContinue` resumes only on `tool-calls` and `resumeToolCall` throws, so
|
|
55
|
+
// an imported `interrupt` with no interrupt payload would be stranded here.
|
|
56
|
+
// Provenance cannot gate it: a repository that went through JSON has no marker.
|
|
57
|
+
// The replacement stays content-derived, so a message with nothing resultless
|
|
58
|
+
// left to act on lands on `complete` rather than an unactionable pause.
|
|
59
|
+
const withLocalPauseReason = (message: ThreadMessage): ThreadMessage => {
|
|
60
|
+
if (
|
|
61
|
+
message.role !== "assistant" ||
|
|
62
|
+
message.status.type !== "requires-action" ||
|
|
63
|
+
message.status.reason !== "interrupt" ||
|
|
64
|
+
message.content.some(
|
|
65
|
+
(c) =>
|
|
66
|
+
c.type === "tool-call" && c.result === undefined && c.interrupt != null,
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
return message;
|
|
70
|
+
return {
|
|
71
|
+
...message,
|
|
72
|
+
status: getAutoStatus(
|
|
73
|
+
false,
|
|
74
|
+
false,
|
|
75
|
+
false,
|
|
76
|
+
message.content.some(
|
|
77
|
+
(c) => c.type === "tool-call" && c.result === undefined,
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const withLocalPauseReasons = (
|
|
84
|
+
data: ExportedMessageRepository,
|
|
85
|
+
): ExportedMessageRepository => ({
|
|
86
|
+
...data,
|
|
87
|
+
messages: data.messages.map((item) => ({
|
|
88
|
+
...item,
|
|
89
|
+
message: withLocalPauseReason(item.message),
|
|
90
|
+
})),
|
|
91
|
+
});
|
|
92
|
+
|
|
52
93
|
export class LocalThreadRuntimeCore
|
|
53
94
|
extends BaseThreadRuntimeCore
|
|
54
95
|
implements ThreadRuntimeCore
|
|
@@ -272,7 +313,7 @@ export class LocalThreadRuntimeCore
|
|
|
272
313
|
this._loadPromise = promise
|
|
273
314
|
.then((repo) => {
|
|
274
315
|
if (!repo) return;
|
|
275
|
-
this.repository.import(repo);
|
|
316
|
+
this.repository.import(withLocalPauseReasons(repo));
|
|
276
317
|
if (repo.messages.length > 0) {
|
|
277
318
|
this.ensureInitialized();
|
|
278
319
|
}
|
|
@@ -434,6 +475,10 @@ export class LocalThreadRuntimeCore
|
|
|
434
475
|
throw new Error("Runtime does not support exporting external states.");
|
|
435
476
|
}
|
|
436
477
|
|
|
478
|
+
public override import(data: ExportedMessageRepository) {
|
|
479
|
+
super.import(withLocalPauseReasons(data));
|
|
480
|
+
}
|
|
481
|
+
|
|
437
482
|
public importExternalState(): void {
|
|
438
483
|
throw new Error("Runtime does not support importing external states.");
|
|
439
484
|
}
|
|
@@ -855,8 +900,9 @@ export class LocalThreadRuntimeCore
|
|
|
855
900
|
approvalId,
|
|
856
901
|
approved,
|
|
857
902
|
optionId,
|
|
903
|
+
text,
|
|
858
904
|
reason,
|
|
859
|
-
}: RespondToToolApprovalOptions) {
|
|
905
|
+
}: RespondToToolApprovalOptions): Promise<void> {
|
|
860
906
|
let message = this.repository
|
|
861
907
|
.getMessages()
|
|
862
908
|
.findLast(
|
|
@@ -899,6 +945,7 @@ export class LocalThreadRuntimeCore
|
|
|
899
945
|
...targetApproval,
|
|
900
946
|
approved,
|
|
901
947
|
...(optionId != null && { optionId }),
|
|
948
|
+
...(text != null && { text }),
|
|
902
949
|
...(reason != null && { reason }),
|
|
903
950
|
};
|
|
904
951
|
if (approved) return { ...c, approval };
|
|
@@ -923,5 +970,7 @@ export class LocalThreadRuntimeCore
|
|
|
923
970
|
} else {
|
|
924
971
|
this._persistPausedMessage(parentId, message);
|
|
925
972
|
}
|
|
973
|
+
|
|
974
|
+
return Promise.resolve();
|
|
926
975
|
}
|
|
927
976
|
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
classifyThreads,
|
|
4
|
+
createEmptyRemoteThreadState,
|
|
5
|
+
createThreadMappingId,
|
|
6
|
+
seedNewThread,
|
|
7
|
+
updateStatusReducer,
|
|
8
|
+
} from "./remote-thread-state";
|
|
9
|
+
import type {
|
|
10
|
+
RemoteThreadData,
|
|
11
|
+
RemoteThreadState,
|
|
12
|
+
} from "./remote-thread-state";
|
|
13
|
+
|
|
14
|
+
const initializedDraft = () => {
|
|
15
|
+
const seeded = seedNewThread(createEmptyRemoteThreadState());
|
|
16
|
+
const regular = updateStatusReducer(seeded.state, seeded.id, "regular");
|
|
17
|
+
const mappingId = regular.threadIdMap[seeded.id]!;
|
|
18
|
+
const initializeTask = Promise.resolve({
|
|
19
|
+
remoteId: "remote-1",
|
|
20
|
+
externalId: "remote-1",
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
id: seeded.id,
|
|
24
|
+
mappingId,
|
|
25
|
+
initializeTask,
|
|
26
|
+
state: {
|
|
27
|
+
...regular,
|
|
28
|
+
threadIdMap: { ...regular.threadIdMap, "remote-1": mappingId },
|
|
29
|
+
threadData: {
|
|
30
|
+
...regular.threadData,
|
|
31
|
+
[mappingId]: {
|
|
32
|
+
...regular.threadData[mappingId]!,
|
|
33
|
+
remoteId: "remote-1",
|
|
34
|
+
externalId: "remote-1",
|
|
35
|
+
initializeTask,
|
|
36
|
+
} as RemoteThreadData,
|
|
37
|
+
},
|
|
38
|
+
} as RemoteThreadState,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const expectOneSlotPerIdentity = (state: RemoteThreadState) => {
|
|
43
|
+
const remoteIds = Object.values(state.threadData)
|
|
44
|
+
.map((data) => data.remoteId)
|
|
45
|
+
.filter((remoteId) => remoteId !== undefined);
|
|
46
|
+
expect(new Set(remoteIds).size).toBe(remoteIds.length);
|
|
47
|
+
|
|
48
|
+
for (const id of [...state.threadIds, ...state.archivedThreadIds]) {
|
|
49
|
+
expect(state.threadData[state.threadIdMap[id]!]?.id).toBe(id);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
describe("remote thread state", () => {
|
|
54
|
+
it("creates an empty state", () => {
|
|
55
|
+
expect(createEmptyRemoteThreadState()).toEqual({
|
|
56
|
+
isLoading: true,
|
|
57
|
+
isLoadingMore: false,
|
|
58
|
+
cursor: undefined,
|
|
59
|
+
newThreadId: undefined,
|
|
60
|
+
threadIds: [],
|
|
61
|
+
archivedThreadIds: [],
|
|
62
|
+
threadIdMap: {},
|
|
63
|
+
threadData: {},
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("seeds unique local threads with matching mapping ids", () => {
|
|
68
|
+
const first = seedNewThread(createEmptyRemoteThreadState());
|
|
69
|
+
const second = seedNewThread(first.state);
|
|
70
|
+
|
|
71
|
+
expect(second.id).not.toBe(first.id);
|
|
72
|
+
expect(first.state.newThreadId).toBe(first.id);
|
|
73
|
+
expect(second.state.newThreadId).toBe(second.id);
|
|
74
|
+
expect(first.state.threadIdMap[first.id]).toBe(
|
|
75
|
+
createThreadMappingId(first.id),
|
|
76
|
+
);
|
|
77
|
+
expect(second.state.threadIdMap[second.id]).toBe(
|
|
78
|
+
createThreadMappingId(second.id),
|
|
79
|
+
);
|
|
80
|
+
expect(Object.keys(second.state.threadData)).toEqual([first.id, second.id]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("refreshes the local slot when a listed thread already has a mapping", () => {
|
|
84
|
+
const draft = initializedDraft();
|
|
85
|
+
|
|
86
|
+
const merged = classifyThreads(
|
|
87
|
+
[
|
|
88
|
+
{
|
|
89
|
+
status: "regular",
|
|
90
|
+
remoteId: "remote-1",
|
|
91
|
+
externalId: "remote-1",
|
|
92
|
+
title: "from the server",
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
{
|
|
96
|
+
threadIds: [],
|
|
97
|
+
archivedThreadIds: [],
|
|
98
|
+
threadIdMap: { ...draft.state.threadIdMap },
|
|
99
|
+
threadData: { ...draft.state.threadData },
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(Object.keys(merged.threadData)).toEqual([draft.mappingId]);
|
|
104
|
+
expect(merged.threadIds).toEqual([draft.id]);
|
|
105
|
+
expect(merged.threadIdMap["remote-1"]).toBe(draft.mappingId);
|
|
106
|
+
expect(merged.threadData[draft.mappingId]?.id).toBe(draft.id);
|
|
107
|
+
expect(merged.threadData[draft.mappingId]?.title).toBe("from the server");
|
|
108
|
+
expect(merged.threadData[draft.mappingId]?.localOrigin).toBe(true);
|
|
109
|
+
const refreshed = merged.threadData[draft.mappingId]!;
|
|
110
|
+
expect(
|
|
111
|
+
refreshed.status === "new" ? undefined : refreshed.initializeTask,
|
|
112
|
+
).toBe(draft.initializeTask);
|
|
113
|
+
expectOneSlotPerIdentity({ ...draft.state, ...merged });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("lists a repeated remote id once", () => {
|
|
117
|
+
const listed = classifyThreads(
|
|
118
|
+
[
|
|
119
|
+
{ status: "regular", remoteId: "a", externalId: "a", title: "first" },
|
|
120
|
+
{ status: "regular", remoteId: "a", externalId: "a", title: "second" },
|
|
121
|
+
],
|
|
122
|
+
{
|
|
123
|
+
threadIds: [],
|
|
124
|
+
archivedThreadIds: [],
|
|
125
|
+
threadIdMap: {},
|
|
126
|
+
threadData: {},
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(listed.threadIds).toEqual(["a"]);
|
|
131
|
+
expect(listed.threadData[createThreadMappingId("a")]?.title).toBe("second");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("deletes every alias of an identity, by either id", () => {
|
|
135
|
+
for (const target of ["remote-1", "local"] as const) {
|
|
136
|
+
const draft = initializedDraft();
|
|
137
|
+
const deleted = updateStatusReducer(
|
|
138
|
+
draft.state,
|
|
139
|
+
target === "local" ? draft.id : target,
|
|
140
|
+
"deleted",
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(deleted.threadData).toEqual({});
|
|
144
|
+
expect(deleted.threadIdMap).toEqual({});
|
|
145
|
+
expect(deleted.threadIds).toEqual([]);
|
|
146
|
+
expect(deleted.archivedThreadIds).toEqual([]);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|