@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composer-runtime.js","names":["Attachment","CreateAttachment","MessageRole","QuoteInfo","Unsubscribe","RunConfig","QueueItemState","QueuePlacement","LazyMemoizeSubject","EventSubscriptionSubject","ShallowMemoizeSubject","SKIP_UPDATE","ComposerRuntimeEventCallback","ComposerRuntimeEventType","DictationState","EditComposerRuntimeCore","SendOptions","ThreadComposerRuntimeCore","ThreadComposerRuntimeCoreBinding","EditComposerRuntimeCoreBinding","ComposerRuntimeCoreBinding","ComposerRuntimePath","AttachmentRuntime","AttachmentState","EditComposerAttachmentRuntimeImpl","ThreadComposerAttachmentRuntimeImpl","BaseComposerState","canCancel","canSend","isEditing","isEmpty","text","role","attachments","runConfig","attachmentAccept","dictation","quote","queue","ThreadComposerState","type","EditComposerState","parentId","sourceId","ComposerState","EMPTY_ARRAY","Object","freeze","EMPTY_OBJECT","getThreadComposerState","runtime","value","getEditComposerState","ComposerRuntime","path","getState","addAttachment","fileOrAttachment","File","Promise","setText","setRole","setRunConfig","reset","clearAttachments","send","options","cancel","steerQueueItem","queueItemId","moveQueueItem","placement","removeQueueItem","subscribe","callback","getAttachmentByIndex","idx","startDictation","stopDictation","setQuote","unstable_on","event","E","ComposerRuntimeImpl","_core","constructor","__internal_bindMethods","bind","core","Error","lane","insertAfter","_eventSubscriptionSubjects","Map","subject","get","binding","set","payload","ThreadComposerRuntime","Omit","composerSource","source","ThreadComposerRuntimeImpl","const","_getState","stateBinding","attachmentSource","attachmentSelector","index","ref","attachment","EditComposerRuntime","beginEdit","EditComposerRuntimeImpl","_beginEdit"],"sources":["../../../src/runtime/api/composer-runtime.ts"],"sourcesContent":["import type { Attachment, CreateAttachment } from \"../../types/attachment\";\nimport type { MessageRole } from \"../../types/message\";\nimport type { QuoteInfo } from \"../../types/quote\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport type { QueueItemState } from \"../../store/scopes/queue-item\";\nimport type { QueuePlacement } from \"../queue/external-thread-queue-adapter\";\nimport {\n LazyMemoizeSubject,\n EventSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n ShallowMemoizeSubject,\n SKIP_UPDATE,\n} from \"../../subscribable/subscribable\";\nimport type {\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventType,\n DictationState,\n EditComposerRuntimeCore,\n SendOptions,\n ThreadComposerRuntimeCore,\n} from \"../interfaces/composer-runtime-core\";\nimport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n} from \"./bindings\";\nimport type { ComposerRuntimePath } from \"./paths\";\n\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n EditComposerAttachmentRuntimeImpl,\n ThreadComposerAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\n\nexport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n};\n\ntype BaseComposerState = {\n /**\n * Whether the composer can cancel the current run. `true` when the runtime\n * supports cancel and a run is in flight, not merely when cancel is a\n * capability.\n */\n readonly canCancel: boolean;\n readonly canSend: boolean;\n readonly isEditing: boolean;\n readonly isEmpty: boolean;\n\n readonly text: string;\n readonly role: MessageRole;\n readonly attachments: readonly Attachment[];\n readonly runConfig: RunConfig;\n\n readonly attachmentAccept: string;\n\n /**\n * The current state of dictation.\n * Undefined when dictation is not active.\n */\n readonly dictation: DictationState | undefined;\n\n /**\n * The currently quoted text, if any.\n * Undefined when no quote is set.\n */\n readonly quote: QuoteInfo | undefined;\n\n /** Messages waiting to be processed. Empty unless the `queue` capability is set. */\n readonly queue: readonly QueueItemState[];\n};\n\nexport type ThreadComposerState = BaseComposerState & {\n readonly type: \"thread\";\n};\n\nexport type EditComposerState = BaseComposerState & {\n readonly type: \"edit\";\n readonly parentId: string | null;\n readonly sourceId: string | null;\n};\n\nexport type ComposerState = ThreadComposerState | EditComposerState;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst EMPTY_OBJECT = Object.freeze({});\nconst getThreadComposerState = (\n runtime: ThreadComposerRuntimeCore | undefined,\n): ThreadComposerState => {\n return Object.freeze({\n type: \"thread\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n canSend: runtime?.canSend ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nconst getEditComposerState = (\n runtime: EditComposerRuntimeCore | undefined,\n): EditComposerState => {\n return Object.freeze({\n type: \"edit\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n canSend: runtime?.canSend ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n parentId: runtime?.parentId ?? null,\n sourceId: runtime?.sourceId ?? null,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nexport type ComposerRuntime = {\n readonly path: ComposerRuntimePath;\n readonly type: \"edit\" | \"thread\";\n\n /**\n * Get the current state of the composer. Includes any data that has been added to the composer.\n */\n getState(): ComposerState;\n\n /**\n * Add an attachment to the composer. Accepts either a standard File object\n * (processed through the AttachmentAdapter) or a CreateAttachment descriptor\n * for external-source attachments (URLs, API data, CMS references). External\n * descriptors bypass the adapter's `add()` step but still respect\n * `adapter.accept` when an adapter is configured; without an adapter they\n * are added as-is.\n * @param fileOrAttachment The file or attachment descriptor to add.\n */\n addAttachment(fileOrAttachment: File | CreateAttachment): Promise<void>;\n\n /**\n * Set the text of the composer.\n * @param text The text to set in the composer.\n */\n setText(text: string): void;\n\n /**\n * Set the role of the composer. For instance, if you'd like a specific message to have the 'assistant' role, you can do so here.\n * @param role The role to set in the composer.\n */\n setRole(role: MessageRole): void;\n\n /**\n * Set the run config of the composer. This is used to send custom configuration data to the model.\n * Within your backend, you can use the `runConfig` object.\n * Example:\n * ```ts\n * composerRuntime.setRunConfig({\n * custom: { customField: \"customValue\" }\n * });\n * ```\n * @param runConfig The run config to set in the composer.\n */\n setRunConfig(runConfig: RunConfig): void;\n\n /**\n * Reset the composer. This will clear the entire state of the composer, including all text and attachments.\n */\n reset(): Promise<void>;\n\n /**\n * Clear all attachments from the composer.\n */\n clearAttachments(): Promise<void>;\n\n /**\n * Send a message. This will send whatever text or attachments are in the composer.\n * @param options Optional send options. Use `{ startRun: true }` to force starting a new run.\n */\n send(options?: SendOptions): void;\n\n /**\n * Cancel the current run. In edit mode, this will exit edit mode.\n */\n cancel(): void;\n\n /** @deprecated Use `moveQueueItem(queueItemId, { lane: \"steer\", insertAfter: null })` instead. Removal after 2026-11-05. */\n steerQueueItem(queueItemId: string): void;\n\n /** Move a queued message between lanes or within a lane. */\n moveQueueItem(queueItemId: string, placement: QueuePlacement): void;\n\n /** Remove a queued message. */\n removeQueueItem(queueItemId: string): void;\n\n /**\n * Listens for changes to the composer state.\n * @param callback The callback to call when the composer state changes.\n */\n subscribe(callback: () => void): Unsubscribe;\n\n /**\n * Get an attachment by index.\n * @param idx The index of the attachment to get.\n */\n getAttachmentByIndex(idx: number): AttachmentRuntime;\n\n /**\n * Start dictation to convert voice to text input.\n * Requires a DictationAdapter to be configured.\n */\n startDictation(): void;\n\n /**\n * Stop the current dictation session.\n */\n stopDictation(): void;\n\n /**\n * Set a quote for the next message. Pass undefined to clear.\n * @param quote The quote info to set, or undefined to clear.\n */\n setQuote(quote: QuoteInfo | undefined): void;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe;\n};\n\nexport abstract class ComposerRuntimeImpl implements ComposerRuntime {\n public get path() {\n return this._core.path;\n }\n\n public abstract get type(): \"edit\" | \"thread\";\n\n protected _core: ComposerRuntimeCoreBinding;\n\n constructor(_core: ComposerRuntimeCoreBinding) {\n this._core = _core;\n }\n\n protected __internal_bindMethods() {\n this.setText = this.setText.bind(this);\n this.setRunConfig = this.setRunConfig.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.addAttachment = this.addAttachment.bind(this);\n this.reset = this.reset.bind(this);\n this.clearAttachments = this.clearAttachments.bind(this);\n this.send = this.send.bind(this);\n this.cancel = this.cancel.bind(this);\n this.steerQueueItem = this.steerQueueItem.bind(this);\n this.moveQueueItem = this.moveQueueItem.bind(this);\n this.removeQueueItem = this.removeQueueItem.bind(this);\n this.setRole = this.setRole.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.startDictation = this.startDictation.bind(this);\n this.stopDictation = this.stopDictation.bind(this);\n this.setQuote = this.setQuote.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n }\n\n public abstract getState(): ComposerState;\n\n public setText(text: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setText(text);\n }\n\n public setRunConfig(runConfig: RunConfig) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRunConfig(runConfig);\n }\n\n public addAttachment(fileOrAttachment: File | CreateAttachment) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.addAttachment(fileOrAttachment);\n }\n\n public reset() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.reset();\n }\n\n public clearAttachments() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.clearAttachments();\n }\n\n public send(options?: SendOptions) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.send(options);\n }\n\n public cancel() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.cancel();\n }\n\n public steerQueueItem(queueItemId: string) {\n this.moveQueueItem(queueItemId, { lane: \"steer\", insertAfter: null });\n }\n\n public moveQueueItem(queueItemId: string, placement: QueuePlacement) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.moveQueueItem(queueItemId, placement);\n }\n\n public removeQueueItem(queueItemId: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.removeQueueItem(queueItemId);\n }\n\n public setRole(role: MessageRole) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRole(role);\n }\n\n public startDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.startDictation();\n }\n\n public stopDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.stopDictation();\n }\n\n public setQuote(quote: QuoteInfo | undefined) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setQuote(quote);\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ComposerRuntimeEventType>\n >();\n\n public unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject<ComposerRuntimeEventType>({\n event,\n binding: this._core,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback as (payload?: unknown) => void);\n }\n\n public abstract getAttachmentByIndex(idx: number): AttachmentRuntime;\n}\n\nexport type ThreadComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"thread\" };\n readonly type: \"thread\";\n getState(): ThreadComposerState;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"thread-composer\" };\n};\n\nexport class ThreadComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements ThreadComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & {\n composerSource: \"thread\";\n };\n }\n\n public get type() {\n return \"thread\" as const;\n }\n\n private _getState;\n\n constructor(core: ThreadComposerRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getThreadComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this.__internal_bindMethods();\n }\n\n public override getState(): ThreadComposerState {\n return this._getState();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new ThreadComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"thread-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"thread-composer\",\n } satisfies AttachmentState & { source: \"thread-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n\nexport type EditComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"edit\" };\n readonly type: \"edit\";\n\n getState(): EditComposerState;\n beginEdit(): void;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"edit-composer\" };\n};\n\nexport class EditComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements EditComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & { composerSource: \"edit\" };\n }\n\n public get type() {\n return \"edit\" as const;\n }\n\n private _getState;\n private _beginEdit: () => void;\n\n constructor(core: EditComposerRuntimeCoreBinding, _beginEdit: () => void) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getEditComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n this._beginEdit = _beginEdit;\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this.__internal_bindMethods();\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.beginEdit = this.beginEdit.bind(this);\n }\n\n public override getState(): EditComposerState {\n return this._getState();\n }\n\n public beginEdit() {\n this._beginEdit();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new EditComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"edit-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"edit-composer\",\n } satisfies AttachmentState & { source: \"edit-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";;;AAyFA,MAAM6C,cAAcC,OAAOC,OAAO,CAAA,CAAE;AACpC,MAAMC,eAAeF,OAAOC,OAAO,CAAC,CAAC;AACrC,MAAME,0BACJC,YACwB;CACxB,OAAOJ,OAAOC,OAAO;EACnBP,MAAM;EAENX,WAAWqB,SAASrB,aAAa;EACjCF,WAAWuB,SAASvB,aAAa;EACjCC,SAASsB,SAAStB,WAAW;EAC7BE,SAASoB,SAASpB,WAAW;EAE7BG,aAAaiB,SAASjB,eAAeY;EACrCd,MAAMmB,SAASnB,QAAQ;EACvBC,MAAMkB,SAASlB,QAAQ;EACvBE,WAAWgB,SAAShB,aAAac;EACjCb,kBAAkBe,SAASf,oBAAoB;EAC/CC,WAAWc,SAASd;EACpBC,OAAOa,SAASb;EAChBC,OAAOY,SAASZ,SAASO;EAEzBM,OAAOD,SAASnB,QAAQ;CAC1B,CAAC;AACH;AAEA,MAAMqB,wBACJF,YACsB;CACtB,OAAOJ,OAAOC,OAAO;EACnBP,MAAM;EAENX,WAAWqB,SAASrB,aAAa;EACjCF,WAAWuB,SAASvB,aAAa;EACjCC,SAASsB,SAAStB,WAAW;EAC7BE,SAASoB,SAASpB,WAAW;EAE7BC,MAAMmB,SAASnB,QAAQ;EACvBC,MAAMkB,SAASlB,QAAQ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,MAAsC2B,YAAwB;EACxE,MAAMT,eAAe,IAAIlG,mBAAmB;GAC1C8C,MAAMkC,KAAKlC;GACXC,gBAAgBH,qBAAqBoC,KAAKjC,SAAS,CAAC;GACpDkB,YAAYC,aAAac,KAAKf,UAAUC,QAAQ;EAClD,CAAC;EAED,MAAM;GACJpB,MAAMkC,KAAKlC;GACXC,gBAAgBiC,KAAKjC,SAAS;GAC9BkB,YAAYC,aAAagC,aAAajC,UAAUC,QAAQ;EAC1D,CAAC;EACD,KAAKyC,aAAaA;EAElB,KAAKV,YAAYC,aAAanD,SAASgC,KAAKmB,YAAY;EAExD,KAAKpB,uBAAuB;CAC9B;CAEA,yBAAyC;EACvC,MAAMA,uBAAuB;EAC7B,KAAK2B,YAAY,KAAKA,UAAU1B,KAAK,IAAI;CAC3C;CAEA,WAA8C;EAC5C,OAAO,KAAKkB,UAAU;CACxB;CAEA,YAAmB;EACjB,KAAKU,WAAW;CAClB;CAEA,qBAA4BvC,KAAa;EACvC,OAAO,IAAIpD,kCACT,IAAId,sBAAsB;GACxB4C,MAAM;IACJ,GAAG,KAAKA;IACRqD,kBAAkB;IAClBC,oBAAoB;KAAEpE,MAAM;KAASqE,OAAOjC;IAAI;IAChDkC,KAAK,GAAG,KAAKxD,KAAKwD,IAAG,eAAgBlC,IAAG;GAC1C;GACArB,gBAAgB;IAEd,MAAMwD,aADc,KAAKxD,SAAS,CAAC,CAACtB,YACL2C;IAC/B,IAAI,CAACmC,YAAY,OAAOpG;IAExB,OAAO;KACL,GAAGoG;KACHT,QAAQ;IACV;GACF;GACA7B,YAAYC,aAAa,KAAKU,MAAMX,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKU,KACP;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"composer-runtime.js","names":["Attachment","CreateAttachment","MessageRole","QuoteInfo","Unsubscribe","RunConfig","QueueItemState","QueuePlacement","LazyMemoizeSubject","EventSubscriptionSubject","ShallowMemoizeSubject","SKIP_UPDATE","ComposerRuntimeEventCallback","ComposerRuntimeEventType","DictationState","EditComposerRuntimeCore","SendOptions","ThreadComposerRuntimeCore","ThreadComposerRuntimeCoreBinding","EditComposerRuntimeCoreBinding","ComposerRuntimeCoreBinding","ComposerRuntimePath","AttachmentRuntime","AttachmentState","EditComposerAttachmentRuntimeImpl","ThreadComposerAttachmentRuntimeImpl","BaseComposerState","canCancel","canSend","isEditing","isEmpty","text","role","attachments","runConfig","attachmentAccept","dictation","quote","queue","ThreadComposerState","type","EditComposerState","parentId","sourceId","ComposerState","EMPTY_ARRAY","Object","freeze","EMPTY_OBJECT","getThreadComposerState","runtime","value","getEditComposerState","ComposerRuntime","path","getState","addAttachment","fileOrAttachment","File","Promise","setText","setRole","setRunConfig","reset","clearAttachments","send","options","cancel","steerQueueItem","queueItemId","moveQueueItem","placement","removeQueueItem","subscribe","callback","getAttachmentByIndex","idx","startDictation","stopDictation","setQuote","unstable_on","event","E","ComposerRuntimeImpl","_core","constructor","__internal_bindMethods","bind","core","Error","lane","insertAfter","_eventSubscriptionSubjects","Map","subject","get","binding","set","payload","ThreadComposerRuntime","Omit","composerSource","source","ThreadComposerRuntimeImpl","const","_getState","stateBinding","attachmentSource","attachmentSelector","index","ref","attachment","EditComposerRuntime","beginEdit","EditComposerRuntimeImpl","_beginEdit"],"sources":["../../../src/runtime/api/composer-runtime.ts"],"sourcesContent":["import type { Attachment, CreateAttachment } from \"../../types/attachment\";\nimport type { MessageRole } from \"../../types/message\";\nimport type { QuoteInfo } from \"../../types/quote\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport type { QueueItemState } from \"../queue/queue-item\";\nimport type { QueuePlacement } from \"../queue/external-thread-queue-adapter\";\nimport {\n LazyMemoizeSubject,\n EventSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n ShallowMemoizeSubject,\n SKIP_UPDATE,\n} from \"../../subscribable/subscribable\";\nimport type {\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventType,\n DictationState,\n EditComposerRuntimeCore,\n SendOptions,\n ThreadComposerRuntimeCore,\n} from \"../interfaces/composer-runtime-core\";\nimport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n} from \"./bindings\";\nimport type { ComposerRuntimePath } from \"./paths\";\n\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n EditComposerAttachmentRuntimeImpl,\n ThreadComposerAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\n\nexport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n};\n\ntype BaseComposerState = {\n /**\n * Whether the composer can cancel the current run. `true` when the runtime\n * supports cancel and a run is in flight, not merely when cancel is a\n * capability.\n */\n readonly canCancel: boolean;\n readonly canSend: boolean;\n readonly isEditing: boolean;\n readonly isEmpty: boolean;\n\n readonly text: string;\n readonly role: MessageRole;\n readonly attachments: readonly Attachment[];\n readonly runConfig: RunConfig;\n\n readonly attachmentAccept: string;\n\n /**\n * The current state of dictation.\n * Undefined when dictation is not active.\n */\n readonly dictation: DictationState | undefined;\n\n /**\n * The currently quoted text, if any.\n * Undefined when no quote is set.\n */\n readonly quote: QuoteInfo | undefined;\n\n /** Messages waiting to be processed. Empty unless the `queue` capability is set. */\n readonly queue: readonly QueueItemState[];\n};\n\nexport type ThreadComposerState = BaseComposerState & {\n readonly type: \"thread\";\n};\n\nexport type EditComposerState = BaseComposerState & {\n readonly type: \"edit\";\n readonly parentId: string | null;\n readonly sourceId: string | null;\n};\n\nexport type ComposerState = ThreadComposerState | EditComposerState;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst EMPTY_OBJECT = Object.freeze({});\nconst getThreadComposerState = (\n runtime: ThreadComposerRuntimeCore | undefined,\n): ThreadComposerState => {\n return Object.freeze({\n type: \"thread\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n canSend: runtime?.canSend ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nconst getEditComposerState = (\n runtime: EditComposerRuntimeCore | undefined,\n): EditComposerState => {\n return Object.freeze({\n type: \"edit\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n canSend: runtime?.canSend ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n parentId: runtime?.parentId ?? null,\n sourceId: runtime?.sourceId ?? null,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nexport type ComposerRuntime = {\n readonly path: ComposerRuntimePath;\n readonly type: \"edit\" | \"thread\";\n\n /**\n * Get the current state of the composer. Includes any data that has been added to the composer.\n */\n getState(): ComposerState;\n\n /**\n * Add an attachment to the composer. Accepts either a standard File object\n * (processed through the AttachmentAdapter) or a CreateAttachment descriptor\n * for external-source attachments (URLs, API data, CMS references). External\n * descriptors bypass the adapter's `add()` step but still respect\n * `adapter.accept` when an adapter is configured; without an adapter they\n * are added as-is.\n * @param fileOrAttachment The file or attachment descriptor to add.\n */\n addAttachment(fileOrAttachment: File | CreateAttachment): Promise<void>;\n\n /**\n * Set the text of the composer.\n * @param text The text to set in the composer.\n */\n setText(text: string): void;\n\n /**\n * Set the role of the composer. For instance, if you'd like a specific message to have the 'assistant' role, you can do so here.\n * @param role The role to set in the composer.\n */\n setRole(role: MessageRole): void;\n\n /**\n * Set the run config of the composer. This is used to send custom configuration data to the model.\n * Within your backend, you can use the `runConfig` object.\n * Example:\n * ```ts\n * composerRuntime.setRunConfig({\n * custom: { customField: \"customValue\" }\n * });\n * ```\n * @param runConfig The run config to set in the composer.\n */\n setRunConfig(runConfig: RunConfig): void;\n\n /**\n * Reset the composer. This will clear the entire state of the composer, including all text and attachments.\n */\n reset(): Promise<void>;\n\n /**\n * Clear all attachments from the composer.\n */\n clearAttachments(): Promise<void>;\n\n /**\n * Send a message. This will send whatever text or attachments are in the composer.\n * @param options Optional send options. Use `{ startRun: true }` to force starting a new run.\n */\n send(options?: SendOptions): void;\n\n /**\n * Cancel the current run. In edit mode, this will exit edit mode.\n */\n cancel(): void;\n\n /** @deprecated Use `moveQueueItem(queueItemId, { lane: \"steer\", insertAfter: null })` instead. Removal after 2026-11-05. */\n steerQueueItem(queueItemId: string): void;\n\n /** Move a queued message between lanes or within a lane. */\n moveQueueItem(queueItemId: string, placement: QueuePlacement): void;\n\n /** Remove a queued message. */\n removeQueueItem(queueItemId: string): void;\n\n /**\n * Listens for changes to the composer state.\n * @param callback The callback to call when the composer state changes.\n */\n subscribe(callback: () => void): Unsubscribe;\n\n /**\n * Get an attachment by index.\n * @param idx The index of the attachment to get.\n */\n getAttachmentByIndex(idx: number): AttachmentRuntime;\n\n /**\n * Start dictation to convert voice to text input.\n * Requires a DictationAdapter to be configured.\n */\n startDictation(): void;\n\n /**\n * Stop the current dictation session.\n */\n stopDictation(): void;\n\n /**\n * Set a quote for the next message. Pass undefined to clear.\n * @param quote The quote info to set, or undefined to clear.\n */\n setQuote(quote: QuoteInfo | undefined): void;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe;\n};\n\nexport abstract class ComposerRuntimeImpl implements ComposerRuntime {\n public get path() {\n return this._core.path;\n }\n\n public abstract get type(): \"edit\" | \"thread\";\n\n protected _core: ComposerRuntimeCoreBinding;\n\n constructor(_core: ComposerRuntimeCoreBinding) {\n this._core = _core;\n }\n\n protected __internal_bindMethods() {\n this.setText = this.setText.bind(this);\n this.setRunConfig = this.setRunConfig.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.addAttachment = this.addAttachment.bind(this);\n this.reset = this.reset.bind(this);\n this.clearAttachments = this.clearAttachments.bind(this);\n this.send = this.send.bind(this);\n this.cancel = this.cancel.bind(this);\n this.steerQueueItem = this.steerQueueItem.bind(this);\n this.moveQueueItem = this.moveQueueItem.bind(this);\n this.removeQueueItem = this.removeQueueItem.bind(this);\n this.setRole = this.setRole.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.startDictation = this.startDictation.bind(this);\n this.stopDictation = this.stopDictation.bind(this);\n this.setQuote = this.setQuote.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n }\n\n public abstract getState(): ComposerState;\n\n public setText(text: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setText(text);\n }\n\n public setRunConfig(runConfig: RunConfig) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRunConfig(runConfig);\n }\n\n public addAttachment(fileOrAttachment: File | CreateAttachment) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.addAttachment(fileOrAttachment);\n }\n\n public reset() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.reset();\n }\n\n public clearAttachments() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.clearAttachments();\n }\n\n public send(options?: SendOptions) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.send(options);\n }\n\n public cancel() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.cancel();\n }\n\n public steerQueueItem(queueItemId: string) {\n this.moveQueueItem(queueItemId, { lane: \"steer\", insertAfter: null });\n }\n\n public moveQueueItem(queueItemId: string, placement: QueuePlacement) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.moveQueueItem(queueItemId, placement);\n }\n\n public removeQueueItem(queueItemId: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.removeQueueItem(queueItemId);\n }\n\n public setRole(role: MessageRole) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRole(role);\n }\n\n public startDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.startDictation();\n }\n\n public stopDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.stopDictation();\n }\n\n public setQuote(quote: QuoteInfo | undefined) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setQuote(quote);\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ComposerRuntimeEventType>\n >();\n\n public unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject<ComposerRuntimeEventType>({\n event,\n binding: this._core,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback as (payload?: unknown) => void);\n }\n\n public abstract getAttachmentByIndex(idx: number): AttachmentRuntime;\n}\n\nexport type ThreadComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"thread\" };\n readonly type: \"thread\";\n getState(): ThreadComposerState;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"thread-composer\" };\n};\n\nexport class ThreadComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements ThreadComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & {\n composerSource: \"thread\";\n };\n }\n\n public get type() {\n return \"thread\" as const;\n }\n\n private _getState;\n\n constructor(core: ThreadComposerRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getThreadComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this.__internal_bindMethods();\n }\n\n public override getState(): ThreadComposerState {\n return this._getState();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new ThreadComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"thread-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"thread-composer\",\n } satisfies AttachmentState & { source: \"thread-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n\nexport type EditComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"edit\" };\n readonly type: \"edit\";\n\n getState(): EditComposerState;\n beginEdit(): void;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"edit-composer\" };\n};\n\nexport class EditComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements EditComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & { composerSource: \"edit\" };\n }\n\n public get type() {\n return \"edit\" as const;\n }\n\n private _getState;\n private _beginEdit: () => void;\n\n constructor(core: EditComposerRuntimeCoreBinding, _beginEdit: () => void) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getEditComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n this._beginEdit = _beginEdit;\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this.__internal_bindMethods();\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.beginEdit = this.beginEdit.bind(this);\n }\n\n public override getState(): EditComposerState {\n return this._getState();\n }\n\n public beginEdit() {\n this._beginEdit();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new EditComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"edit-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"edit-composer\",\n } satisfies AttachmentState & { source: \"edit-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";;;AAyFA,MAAM6C,cAAcC,OAAOC,OAAO,CAAA,CAAE;AACpC,MAAMC,eAAeF,OAAOC,OAAO,CAAC,CAAC;AACrC,MAAME,0BACJC,YACwB;CACxB,OAAOJ,OAAOC,OAAO;EACnBP,MAAM;EAENX,WAAWqB,SAASrB,aAAa;EACjCF,WAAWuB,SAASvB,aAAa;EACjCC,SAASsB,SAAStB,WAAW;EAC7BE,SAASoB,SAASpB,WAAW;EAE7BG,aAAaiB,SAASjB,eAAeY;EACrCd,MAAMmB,SAASnB,QAAQ;EACvBC,MAAMkB,SAASlB,QAAQ;EACvBE,WAAWgB,SAAShB,aAAac;EACjCb,kBAAkBe,SAASf,oBAAoB;EAC/CC,WAAWc,SAASd;EACpBC,OAAOa,SAASb;EAChBC,OAAOY,SAASZ,SAASO;EAEzBM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T,QAAQ;IACV;GACF;GACA7B,YAAYC,aAAa,KAAKU,MAAMX,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKU,KACP;CACF;AACF"}
|
|
@@ -13,7 +13,7 @@ type MessagePartSnapshotBinding = SubscribableWithState<MessagePartState, Messag
|
|
|
13
13
|
type MessagePartRuntime = {
|
|
14
14
|
addToolResult(result: any | ToolResponse<any>): void;
|
|
15
15
|
resumeToolCall(payload: unknown): void;
|
|
16
|
-
respondToToolApproval(response: ToolApprovalResponse): void
|
|
16
|
+
respondToToolApproval(response: ToolApprovalResponse): Promise<void>;
|
|
17
17
|
readonly path: MessagePartRuntimePath;
|
|
18
18
|
getState(): MessagePartState;
|
|
19
19
|
subscribe(callback: () => void): Unsubscribe;
|
|
@@ -28,7 +28,7 @@ declare class MessagePartRuntimeImpl implements MessagePartRuntime {
|
|
|
28
28
|
getState(): MessagePartState;
|
|
29
29
|
addToolResult(result: any | ToolResponse<any>): void;
|
|
30
30
|
resumeToolCall(payload: unknown): void;
|
|
31
|
-
respondToToolApproval(response: ToolApprovalResponse): void
|
|
31
|
+
respondToToolApproval(response: ToolApprovalResponse): Promise<void>;
|
|
32
32
|
subscribe(callback: () => void): Unsubscribe;
|
|
33
33
|
}
|
|
34
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-part-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"mappings":";;;;;;;;KAeY,oBACR,wBACA;WAEO,QAAQ,oBAAoB;;KAGlC,6BAA6B,sBAChC,kBACA;KAGU;EACV,cAAc,cAAc;EAC5B,eAAe;EACf,sBAAsB,UAAU;
|
|
1
|
+
{"version":3,"file":"message-part-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"mappings":";;;;;;;;KAeY,oBACR,wBACA;WAEO,QAAQ,oBAAoB;;KAGlC,6BAA6B,sBAChC,kBACA;KAGU;EACV,cAAc,cAAc;EAC5B,eAAe;EACf,sBAAsB,UAAU,uBAAuB;WAE9C,MAAM;EACf,YAAY;EACZ,UAAU,uBAAuB;;cAGtB,kCAAkC;MAClC,QAAI;UAIP;UACA;UACA;EAGN,YAAA,gBAAgB,4BAChB,aAAa,qBACb,YAAY;YAQJ;EAQH,YAAQ;EAIR,cAAc,cAAc;EA8B5B,eAAe;EAgBf,sBAAsB,UAAU,uBAAuB;EAyBvD,UAAU,uBAAoB"}
|
|
@@ -61,7 +61,7 @@ var MessagePartRuntimeImpl = class {
|
|
|
61
61
|
if (state.type !== "tool-call") throw new Error("Tried to respond to tool approval on non-tool message part");
|
|
62
62
|
if (!state.approval || state.approval.approved !== void 0 || state.approval.resolution !== void 0) throw new Error("Tool call has no pending approval");
|
|
63
63
|
if (!this.threadApi) throw new Error("Thread API is not available");
|
|
64
|
-
this.threadApi.getState().respondToToolApproval(resolveToolApprovalResponse(state.approval, response));
|
|
64
|
+
return this.threadApi.getState().respondToToolApproval(resolveToolApprovalResponse(state.approval, response));
|
|
65
65
|
}
|
|
66
66
|
subscribe(callback) {
|
|
67
67
|
return this.contentBinding.subscribe(callback);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-part-runtime.js","names":["ThreadAssistantMessagePart","ThreadUserMessagePart","ToolApprovalResponse","ToolCallMessagePartStatus","resolveToolApprovalResponse","Unsubscribe","MessagePartStatus","SubscribableWithState","ThreadRuntimeCoreBinding","MessageStateBinding","MessagePartRuntimePath","ToolResponse","MessagePartState","status","MessagePartSnapshotBinding","MessagePartRuntime","addToolResult","result","resumeToolCall","payload","respondToToolApproval","response","path","getState","subscribe","callback","MessagePartRuntimeImpl","contentBinding","messageApi","threadApi","constructor","__internal_bindMethods","bind","state","Error","type","message","toolName","toolCallId","toResponse","messageId","id","artifact","isError","approval","approved","undefined","resolution"],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"sourcesContent":["import type {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ToolApprovalResponse,\n ToolCallMessagePartStatus,\n} from \"../../types/message\";\nimport { resolveToolApprovalResponse } from \"../utils/resolveToolApprovalResponse\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus } from \"../../types/message\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\nimport type { MessagePartRuntimePath } from \"./paths\";\nimport { ToolResponse } from \"assistant-stream\";\n\nexport type MessagePartState = (\n | ThreadUserMessagePart\n | ThreadAssistantMessagePart\n) & {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\ntype MessagePartSnapshotBinding = SubscribableWithState<\n MessagePartState,\n MessagePartRuntimePath\n>;\n\nexport type MessagePartRuntime = {\n addToolResult(result: any | ToolResponse<any>): void;\n resumeToolCall(payload: unknown): void;\n respondToToolApproval(response: ToolApprovalResponse): void
|
|
1
|
+
{"version":3,"file":"message-part-runtime.js","names":["ThreadAssistantMessagePart","ThreadUserMessagePart","ToolApprovalResponse","ToolCallMessagePartStatus","resolveToolApprovalResponse","Unsubscribe","MessagePartStatus","SubscribableWithState","ThreadRuntimeCoreBinding","MessageStateBinding","MessagePartRuntimePath","ToolResponse","MessagePartState","status","MessagePartSnapshotBinding","MessagePartRuntime","addToolResult","result","resumeToolCall","payload","respondToToolApproval","response","Promise","path","getState","subscribe","callback","MessagePartRuntimeImpl","contentBinding","messageApi","threadApi","constructor","__internal_bindMethods","bind","state","Error","type","message","toolName","toolCallId","toResponse","messageId","id","artifact","isError","approval","approved","undefined","resolution"],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"sourcesContent":["import type {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ToolApprovalResponse,\n ToolCallMessagePartStatus,\n} from \"../../types/message\";\nimport { resolveToolApprovalResponse } from \"../utils/resolveToolApprovalResponse\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus } from \"../../types/message\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\nimport type { MessagePartRuntimePath } from \"./paths\";\nimport { ToolResponse } from \"assistant-stream\";\n\nexport type MessagePartState = (\n | ThreadUserMessagePart\n | ThreadAssistantMessagePart\n) & {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\ntype MessagePartSnapshotBinding = SubscribableWithState<\n MessagePartState,\n MessagePartRuntimePath\n>;\n\nexport type MessagePartRuntime = {\n addToolResult(result: any | ToolResponse<any>): void;\n resumeToolCall(payload: unknown): void;\n respondToToolApproval(response: ToolApprovalResponse): Promise<void>;\n\n readonly path: MessagePartRuntimePath;\n getState(): MessagePartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class MessagePartRuntimeImpl implements MessagePartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n private contentBinding: MessagePartSnapshotBinding;\n private messageApi: MessageStateBinding | undefined;\n private threadApi: ThreadRuntimeCoreBinding | undefined;\n\n constructor(\n contentBinding: MessagePartSnapshotBinding,\n messageApi?: MessageStateBinding,\n threadApi?: ThreadRuntimeCoreBinding,\n ) {\n this.contentBinding = contentBinding;\n this.messageApi = messageApi;\n this.threadApi = threadApi;\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.addToolResult = this.addToolResult.bind(this);\n this.resumeToolCall = this.resumeToolCall.bind(this);\n this.respondToToolApproval = this.respondToToolApproval.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n }\n\n public getState() {\n return this.contentBinding.getState();\n }\n\n public addToolResult(result: any | ToolResponse<any>) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool message part\");\n\n if (!this.messageApi)\n throw new Error(\n \"Message API is not available. This is likely a bug in assistant-ui.\",\n );\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const message = this.messageApi.getState();\n if (!message) throw new Error(\"Message is not available\");\n\n const toolName = state.toolName;\n const toolCallId = state.toolCallId;\n\n const response = ToolResponse.toResponse(result);\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result: response.result,\n artifact: response.artifact,\n isError: response.isError,\n });\n }\n\n public resumeToolCall(payload: unknown) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to resume tool call on non-tool message part\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const toolCallId = state.toolCallId;\n this.threadApi.getState().resumeToolCall({\n toolCallId,\n payload,\n });\n }\n\n public respondToToolApproval(response: ToolApprovalResponse): Promise<void> {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\n \"Tried to respond to tool approval on non-tool message part\",\n );\n\n if (\n !state.approval ||\n state.approval.approved !== undefined ||\n state.approval.resolution !== undefined\n )\n throw new Error(\"Tool call has no pending approval\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n return this.threadApi\n .getState()\n .respondToToolApproval(\n resolveToolApprovalResponse(state.approval, response),\n );\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";;;AAqCA,IAAa2B,yBAAb,MAAkE;CAChE,IAAWJ,OAAO;EAChB,OAAO,KAAKK,eAAeL;CAC7B;CAEA;CACA;CACA;CAEAQ,YACEH,gBACAC,YACAC,WACA;EACA,KAAKF,iBAAiBA;EACtB,KAAKC,aAAaA;EAClB,KAAKC,YAAYA;EACjB,KAAKE,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKhB,gBAAgB,KAAKA,cAAciB,KAAK,IAAI;EACjD,KAAKf,iBAAiB,KAAKA,eAAee,KAAK,IAAI;EACnD,KAAKb,w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,SAAS;EAC3C,IAAI,CAACU,OAAO,MAAM,IAAIC,MAAM,+BAA+B;EAE3D,IAAID,MAAME,SAAS,aACjB,MAAM,IAAID,MACR,4DACF;EAEF,IACE,CAACD,MAAMW,YACPX,MAAMW,SAASC,aAAaC,KAAAA,KAC5Bb,MAAMW,SAASG,eAAeD,KAAAA,GAE9B,MAAM,IAAIZ,MAAM,mCAAmC;EAErD,IAAI,CAAC,KAAKL,WAAW,MAAM,IAAIK,MAAM,6BAA6B;EAElE,OAAO,KAAKL,UACTN,SAAS,CAAC,CACVJ,sBACChB,4BAA4B8B,MAAMW,UAAUxB,QAAQ,CACtD;CACJ;CAEA,UAAiBK,UAAsB;EACrC,OAAO,KAAKE,eAAeH,UAAUC,QAAQ;CAC/C;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Unsubscribe } from "../../types/unsubscribe.js";
|
|
2
|
-
import { ThreadListRuntimeCore } from "../interfaces/thread-list-runtime-core.js";
|
|
2
|
+
import { ThreadListRuntimeCore, ThreadListRuntimeEvent } from "../interfaces/thread-list-runtime-core.js";
|
|
3
3
|
import { ThreadListItemState } from "./bindings.js";
|
|
4
4
|
import { ThreadListItemRuntime, ThreadListItemRuntimeImpl } from "./thread-list-item-runtime.js";
|
|
5
5
|
import { ThreadListItemRuntimeBinding, ThreadRuntime, ThreadRuntimeCoreBinding } from "./thread-runtime.js";
|
|
@@ -27,6 +27,13 @@ type ThreadListRuntime = {
|
|
|
27
27
|
unarchive?: boolean;
|
|
28
28
|
}): Promise<void>;
|
|
29
29
|
switchToNewThread(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Observes lifecycle events on every thread this list keeps alive, so an
|
|
32
|
+
* event that fires while its thread is not selected stays observable. Thread
|
|
33
|
+
* lists that mount only the main thread never emit; their main thread's
|
|
34
|
+
* runtime is observed directly.
|
|
35
|
+
*/
|
|
36
|
+
unstable_subscribeThreadEvents(callback: (event: ThreadListRuntimeEvent) => void): Unsubscribe;
|
|
30
37
|
getLoadThreadsPromise(): Promise<void>;
|
|
31
38
|
reload(): Promise<void>;
|
|
32
39
|
/**
|
|
@@ -55,6 +62,7 @@ declare class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
|
55
62
|
unarchive?: boolean;
|
|
56
63
|
}): Promise<void>;
|
|
57
64
|
switchToNewThread(): Promise<void>;
|
|
65
|
+
unstable_subscribeThreadEvents(callback: (event: ThreadListRuntimeEvent) => void): Unsubscribe;
|
|
58
66
|
getLoadThreadsPromise(): Promise<void>;
|
|
59
67
|
reload(): Promise<void>;
|
|
60
68
|
reloadMainThread(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"thread-list-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"mappings":";;;;;;KA4BY;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA,aAAa,SACpB,eAEE,KAAK;;KAKC;EACV,YAAY;EAEZ,UAAU,uBAAuB;WAExB,MAAM;EACf,QAAQ,mBAAmB;WAElB,UAAU;EACnB,YAAY,mBAAmB;EAC/B,eAAe,cAAc;EAC7B,uBAAuB,cAAc;EAErC,eACE,kBACA;IAAY;MACX;EACH,qBAAqB;;;;;;;EAQrB,+BACE,WAAW,OAAO,kCACjB;EAEH,yBAAyB;EACzB,UAAU;;;;;;;;;;;;EAYV,oBAAoB;EACpB,YAAY;;KAuCF,+BAA+B;cAE9B,iCAAiC;UACpC;UACA;UACA;UACA;EAMN,YAAA,OAAO,8BACP,uBACE,SAAS,0BACT,uBAAuB,iCACpB;YA0CG;EAiBH,eACL,kBACA;IAAY;MACX;EAII,qBAAqB;EAIrB,+BACL,WAAW,OAAO,kCACjB;EAMI,yBAAyB;EAIzB,UAAU;EAIV,oBAAoB;EAIpB,YAAY;EAIZ,YAAY;EAIZ,UAAU,uBAAuB;UAIhC;WAEQ,MAAM;MAEX,YAAQ;EAIZ,QAAQ,mBAAgB;EAcxB,eAAe,cAAW;EAgB1B,uBAAuB,cAAW;EAmBlC,YAAY,mBAAgB"}
|
|
@@ -3,6 +3,7 @@ import { ThreadRuntimeImpl } from "./thread-runtime.js";
|
|
|
3
3
|
import { ThreadListItemRuntimeImpl } from "./thread-list-item-runtime.js";
|
|
4
4
|
//#region src/runtime/api/thread-list-runtime.ts
|
|
5
5
|
const RESOLVED_PROMISE = Promise.resolve();
|
|
6
|
+
const NOOP_UNSUBSCRIBE = () => {};
|
|
6
7
|
const getThreadListState = (threadList) => {
|
|
7
8
|
return {
|
|
8
9
|
mainThreadId: threadList.mainThreadId,
|
|
@@ -69,6 +70,7 @@ var ThreadListRuntimeImpl = class {
|
|
|
69
70
|
__internal_bindMethods() {
|
|
70
71
|
this.switchToThread = this.switchToThread.bind(this);
|
|
71
72
|
this.switchToNewThread = this.switchToNewThread.bind(this);
|
|
73
|
+
this.unstable_subscribeThreadEvents = this.unstable_subscribeThreadEvents.bind(this);
|
|
72
74
|
this.getLoadThreadsPromise = this.getLoadThreadsPromise.bind(this);
|
|
73
75
|
this.reload = this.reload.bind(this);
|
|
74
76
|
this.reloadMainThread = this.reloadMainThread.bind(this);
|
|
@@ -86,6 +88,9 @@ var ThreadListRuntimeImpl = class {
|
|
|
86
88
|
switchToNewThread() {
|
|
87
89
|
return this._core.switchToNewThread();
|
|
88
90
|
}
|
|
91
|
+
unstable_subscribeThreadEvents(callback) {
|
|
92
|
+
return this._core.unstable_subscribeThreadEvents?.(callback) ?? NOOP_UNSUBSCRIBE;
|
|
93
|
+
}
|
|
89
94
|
getLoadThreadsPromise() {
|
|
90
95
|
return this._core.getLoadThreadsPromise();
|
|
91
96
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-runtime.js","names":["Unsubscribe","LazyMemoizeSubject","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","ThreadListRuntimeCore","ThreadListItemRuntime","ThreadListItemRuntimeImpl","ThreadListItemState","ThreadListItemRuntimeBinding","ThreadRuntime","ThreadRuntimeCoreBinding","ThreadRuntimeImpl","RESOLVED_PROMISE","Promise","resolve","ThreadListState","mainThreadId","newThreadId","threadIds","archivedThreadIds","isLoading","isLoadingMore","hasMore","threadItems","Readonly","Record","Omit","ThreadListRuntime","getState","subscribe","callback","main","getById","threadId","mainItem","getItemById","getItemByIndex","idx","getArchivedItemByIndex","switchToThread","options","unarchive","switchToNewThread","getLoadThreadsPromise","reload","reloadMainThread","loadMore","getThreadListState","threadList","getThreadListItemState","undefined","threadData","id","remoteId","externalId","title","status","lastMessageAt","custom","isMain","isRunning","unstable_isThreadRunning","ThreadListRuntimeCoreBinding","ThreadListRuntimeImpl","_getState","_stateBinding","_core","_runtimeFactory","binding","threadListItemBinding","constructor","stateBinding","path","bind","_mainThreadListItemRuntime","ref","threadSelector","type","getMainThreadRuntimeCore","__internal_bindMethods","JSON","stringify","getThreadRuntimeCore","index"],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport {\n LazyMemoizeSubject,\n NestedSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport type { ThreadListRuntimeCore } from \"../interfaces/thread-list-runtime-core\";\nimport {\n type ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n type ThreadListItemState,\n} from \"./thread-list-item-runtime\";\nimport {\n type ThreadListItemRuntimeBinding,\n type ThreadRuntime,\n type ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./thread-runtime\";\n\nconst RESOLVED_PROMISE = Promise.resolve();\n\nexport type ThreadListState = {\n readonly mainThreadId: string;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly isLoading: boolean;\n readonly isLoadingMore: boolean;\n readonly hasMore: boolean;\n readonly threadItems: Readonly<\n Record<\n string,\n Omit<ThreadListItemState, \"isMain\" | \"threadId\" | \"isRunning\">\n >\n >;\n};\n\nexport type ThreadListRuntime = {\n getState(): ThreadListState;\n\n subscribe(callback: () => void): Unsubscribe;\n\n readonly main: ThreadRuntime;\n getById(threadId: string): ThreadRuntime;\n\n readonly mainItem: ThreadListItemRuntime;\n getItemById(threadId: string): ThreadListItemRuntime;\n getItemByIndex(idx: number): ThreadListItemRuntime;\n getArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n\n switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void>;\n switchToNewThread(): Promise<void>;\n\n getLoadThreadsPromise(): Promise<void>;\n reload(): Promise<void>;\n /**\n * Refetches the open thread's remote state, for state that changed out of\n * band and so never reached the stream. When the runtime declares the\n * in-place capability (`unstable_refetchThread`), composer drafts survive,\n * existing messages stay rendered during the refetch, and the promise\n * settles with the refetch, rejecting if it fails; that runtime also owns\n * what happens to a run in progress, since this does not stop one. Runtimes\n * without the capability have their hook remounted instead, which discards\n * unsent composer input and ends any run, and the promise resolves once the\n * new runtime attaches. A thread that has not been sent yet is left alone.\n */\n reloadMainThread(): Promise<void>;\n loadMore(): Promise<void>;\n};\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n mainThreadId: threadList.mainThreadId,\n newThreadId: threadList.newThreadId,\n threadIds: threadList.threadIds,\n archivedThreadIds: threadList.archivedThreadIds,\n isLoading: threadList.isLoading,\n isLoadingMore: threadList.isLoadingMore ?? false,\n hasMore: threadList.hasMore ?? false,\n threadItems: threadList.threadItems,\n };\n};\n\nconst getThreadListItemState = (\n threadList: ThreadListRuntimeCore,\n threadId: string | undefined,\n): ThreadListItemState | SKIP_UPDATE => {\n if (threadId === undefined) return SKIP_UPDATE;\n\n const threadData = threadList.getItemById(threadId);\n if (!threadData) return SKIP_UPDATE;\n return {\n id: threadData.id,\n remoteId: threadData.remoteId,\n externalId: threadData.externalId,\n title: threadData.title,\n status: threadData.status,\n lastMessageAt: threadData.lastMessageAt,\n custom: threadData.custom,\n isMain: threadData.id === threadList.mainThreadId,\n isRunning: threadList.unstable_isThreadRunning?.(threadData.id) ?? false,\n };\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n private _getState;\n private _stateBinding: LazyMemoizeSubject<ThreadListState, object>;\n private _core: ThreadListRuntimeCoreBinding;\n private _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime;\n\n constructor(\n _core: ThreadListRuntimeCoreBinding,\n _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n this._core = _core;\n this._runtimeFactory = _runtimeFactory;\n const stateBinding = new LazyMemoizeSubject({\n path: {},\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n this._stateBinding = stateBinding;\n\n this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[main]`,\n threadSelector: { type: \"main\" },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.mainThreadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n\n this.main = new _runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.getMainThreadRuntimeCore(),\n subscribe: (callback) => _core.subscribe(callback),\n }),\n this._mainThreadListItemRuntime,\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.switchToThread = this.switchToThread.bind(this);\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.getLoadThreadsPromise = this.getLoadThreadsPromise.bind(this);\n this.reload = this.reload.bind(this);\n this.reloadMainThread = this.reloadMainThread.bind(this);\n this.loadMore = this.loadMore.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getById = this.getById.bind(this);\n this.getItemById = this.getItemById.bind(this);\n this.getItemByIndex = this.getItemByIndex.bind(this);\n this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);\n }\n\n public switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void> {\n return this._core.switchToThread(threadId, options);\n }\n\n public switchToNewThread(): Promise<void> {\n return this._core.switchToNewThread();\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return this._core.getLoadThreadsPromise();\n }\n\n public reload(): Promise<void> {\n return this._core.reload?.() ?? RESOLVED_PROMISE;\n }\n\n public reloadMainThread(): Promise<void> {\n return this._core.reloadMainThread?.() ?? RESOLVED_PROMISE;\n }\n\n public loadMore(): Promise<void> {\n return this._core.loadMore?.() ?? RESOLVED_PROMISE;\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._stateBinding.subscribe(callback);\n }\n\n private _mainThreadListItemRuntime;\n\n public readonly main: ThreadRuntime;\n\n public get mainItem() {\n return this._mainThreadListItemRuntime;\n }\n\n public getById(threadId: string) {\n return new this._runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: `threads[threadId=${JSON.stringify(threadId)}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => this._core.getThreadRuntimeCore(threadId),\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this.mainItem,\n );\n }\n\n public getItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.threadIds[idx]);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(\n this._core,\n this._core.archivedThreadIds[idx],\n );\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n return getThreadListItemState(this._core, threadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";;;;AAsBA,MAAMa,mBAAmBC,QAAQC,QAAQ;AAsDzC,MAAMiC,sBACJC,eACoB;CACpB,OAAO;EACLhC,cAAcgC,WAAWhC;EACzBC,aAAa+B,WAAW/B;EACxBC,WAAW8B,WAAW9B;EACtBC,mBAAmB6B,WAAW7B;EAC9BC,WAAW4B,WAAW5B;EACtBC,eAAe2B,WAAW3B,iBAAiB;EAC3CC,SAAS0B,WAAW1B,WAAW;EAC/BC,aAAayB,WAAWzB;CAC1B;AACF;AAEA,MAAM0B,0BACJD,YACAf,aACsC;CACtC,IAAIA,aAAaiB,KAAAA,GAAW,OAAOhD;CAEnC,MAAMiD,aAAaH,WAAWb,YAAYF,QAAQ;CAClD,IAAI,CAACkB,YAAY,OAAOjD;CACxB,OAAO;EACLkD,IAAID,WAAWC;EACfC,UAAUF,WAAWE;EACrBC,YAAYH,WAAWG;EACvBC,OAAOJ,WAAWI;EAClBC,QAAQL,WAAWK;EACnBC,eAAeN,WAAWM;EAC1BC,QAAQP,WAAWO;EACnBC,QAAQR,WAAWC,OAAOJ,WAAWhC;EACrC4C,WAAWZ,WAAWa,2BAA2BV,WAAWC,EAAE,KAAK;CACrE;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H,sBAAsB;GACxBqE,MAAM;IACJG,KAAK,eAAetC,IAAG;IACvBuC,gBAAgB;KAAEC,MAAM;KAASM,OAAO9C;IAAI;GAC9C;GACAT,gBAAgB;IACd,OAAOqB,uBAAuB,KAAKiB,OAAO,KAAKA,MAAMhD,UAAUmB,IAAI;GACrE;GACAR,YAAYC,aAAa,KAAKoC,MAAMrC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKoC,KACP;CACF;CAEA,uBAA8B7B,KAAa;EACzC,OAAO,IAAI/B,0BACT,IAAIH,sBAAsB;GACxBqE,MAAM;IACJG,KAAK,uBAAuBtC,IAAG;IAC/BuC,gBAAgB;KAAEC,MAAM;KAAgBM,OAAO9C;IAAI;GACrD;GACAT,gBAAgB;IACd,OAAOqB,uBACL,KAAKiB,OACL,KAAKA,MAAM/C,kBAAkBkB,IAC/B;GACF;GACAR,YAAYC,aAAa,KAAKoC,MAAMrC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKoC,KACP;CACF;CAEA,YAAmBjC,UAAkB;EACnC,OAAO,IAAI3B,0BACT,IAAIH,sBAAsB;GACxBqE,MAAM;IACJG,KAAK,wBAAwB1C,SAAQ;IACrC2C,gBAAgB;KAAEC,MAAM;KAAY5C;IAAS;GAC/C;GACAL,gBAAgB;IACd,OAAOqB,uBAAuB,KAAKiB,OAAOjC,QAAQ;GACpD;GACAJ,YAAYC,aAAa,KAAKoC,MAAMrC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKoC,KACP;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"thread-list-runtime.js","names":["Unsubscribe","LazyMemoizeSubject","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","ThreadListRuntimeCore","ThreadListRuntimeEvent","ThreadListItemRuntime","ThreadListItemRuntimeImpl","ThreadListItemState","ThreadListItemRuntimeBinding","ThreadRuntime","ThreadRuntimeCoreBinding","ThreadRuntimeImpl","RESOLVED_PROMISE","Promise","resolve","NOOP_UNSUBSCRIBE","ThreadListState","mainThreadId","newThreadId","threadIds","archivedThreadIds","isLoading","isLoadingMore","hasMore","threadItems","Readonly","Record","Omit","ThreadListRuntime","getState","subscribe","callback","main","getById","threadId","mainItem","getItemById","getItemByIndex","idx","getArchivedItemByIndex","switchToThread","options","unarchive","switchToNewThread","unstable_subscribeThreadEvents","event","getLoadThreadsPromise","reload","reloadMainThread","loadMore","getThreadListState","threadList","getThreadListItemState","undefined","threadData","id","remoteId","externalId","title","status","lastMessageAt","custom","isMain","isRunning","unstable_isThreadRunning","ThreadListRuntimeCoreBinding","ThreadListRuntimeImpl","_getState","_stateBinding","_core","_runtimeFactory","binding","threadListItemBinding","constructor","stateBinding","path","bind","_mainThreadListItemRuntime","ref","threadSelector","type","getMainThreadRuntimeCore","__internal_bindMethods","JSON","stringify","getThreadRuntimeCore","index"],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport {\n LazyMemoizeSubject,\n NestedSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport type {\n ThreadListRuntimeCore,\n ThreadListRuntimeEvent,\n} from \"../interfaces/thread-list-runtime-core\";\nimport {\n type ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n type ThreadListItemState,\n} from \"./thread-list-item-runtime\";\nimport {\n type ThreadListItemRuntimeBinding,\n type ThreadRuntime,\n type ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./thread-runtime\";\n\nconst RESOLVED_PROMISE = Promise.resolve();\nconst NOOP_UNSUBSCRIBE = () => {};\n\nexport type ThreadListState = {\n readonly mainThreadId: string;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly isLoading: boolean;\n readonly isLoadingMore: boolean;\n readonly hasMore: boolean;\n readonly threadItems: Readonly<\n Record<\n string,\n Omit<ThreadListItemState, \"isMain\" | \"threadId\" | \"isRunning\">\n >\n >;\n};\n\nexport type ThreadListRuntime = {\n getState(): ThreadListState;\n\n subscribe(callback: () => void): Unsubscribe;\n\n readonly main: ThreadRuntime;\n getById(threadId: string): ThreadRuntime;\n\n readonly mainItem: ThreadListItemRuntime;\n getItemById(threadId: string): ThreadListItemRuntime;\n getItemByIndex(idx: number): ThreadListItemRuntime;\n getArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n\n switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void>;\n switchToNewThread(): Promise<void>;\n\n /**\n * Observes lifecycle events on every thread this list keeps alive, so an\n * event that fires while its thread is not selected stays observable. Thread\n * lists that mount only the main thread never emit; their main thread's\n * runtime is observed directly.\n */\n unstable_subscribeThreadEvents(\n callback: (event: ThreadListRuntimeEvent) => void,\n ): Unsubscribe;\n\n getLoadThreadsPromise(): Promise<void>;\n reload(): Promise<void>;\n /**\n * Refetches the open thread's remote state, for state that changed out of\n * band and so never reached the stream. When the runtime declares the\n * in-place capability (`unstable_refetchThread`), composer drafts survive,\n * existing messages stay rendered during the refetch, and the promise\n * settles with the refetch, rejecting if it fails; that runtime also owns\n * what happens to a run in progress, since this does not stop one. Runtimes\n * without the capability have their hook remounted instead, which discards\n * unsent composer input and ends any run, and the promise resolves once the\n * new runtime attaches. A thread that has not been sent yet is left alone.\n */\n reloadMainThread(): Promise<void>;\n loadMore(): Promise<void>;\n};\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n mainThreadId: threadList.mainThreadId,\n newThreadId: threadList.newThreadId,\n threadIds: threadList.threadIds,\n archivedThreadIds: threadList.archivedThreadIds,\n isLoading: threadList.isLoading,\n isLoadingMore: threadList.isLoadingMore ?? false,\n hasMore: threadList.hasMore ?? false,\n threadItems: threadList.threadItems,\n };\n};\n\nconst getThreadListItemState = (\n threadList: ThreadListRuntimeCore,\n threadId: string | undefined,\n): ThreadListItemState | SKIP_UPDATE => {\n if (threadId === undefined) return SKIP_UPDATE;\n\n const threadData = threadList.getItemById(threadId);\n if (!threadData) return SKIP_UPDATE;\n return {\n id: threadData.id,\n remoteId: threadData.remoteId,\n externalId: threadData.externalId,\n title: threadData.title,\n status: threadData.status,\n lastMessageAt: threadData.lastMessageAt,\n custom: threadData.custom,\n isMain: threadData.id === threadList.mainThreadId,\n isRunning: threadList.unstable_isThreadRunning?.(threadData.id) ?? false,\n };\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n private _getState;\n private _stateBinding: LazyMemoizeSubject<ThreadListState, object>;\n private _core: ThreadListRuntimeCoreBinding;\n private _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime;\n\n constructor(\n _core: ThreadListRuntimeCoreBinding,\n _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n this._core = _core;\n this._runtimeFactory = _runtimeFactory;\n const stateBinding = new LazyMemoizeSubject({\n path: {},\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n this._stateBinding = stateBinding;\n\n this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[main]`,\n threadSelector: { type: \"main\" },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.mainThreadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n\n this.main = new _runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.getMainThreadRuntimeCore(),\n subscribe: (callback) => _core.subscribe(callback),\n }),\n this._mainThreadListItemRuntime,\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.switchToThread = this.switchToThread.bind(this);\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.unstable_subscribeThreadEvents =\n this.unstable_subscribeThreadEvents.bind(this);\n this.getLoadThreadsPromise = this.getLoadThreadsPromise.bind(this);\n this.reload = this.reload.bind(this);\n this.reloadMainThread = this.reloadMainThread.bind(this);\n this.loadMore = this.loadMore.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getById = this.getById.bind(this);\n this.getItemById = this.getItemById.bind(this);\n this.getItemByIndex = this.getItemByIndex.bind(this);\n this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);\n }\n\n public switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void> {\n return this._core.switchToThread(threadId, options);\n }\n\n public switchToNewThread(): Promise<void> {\n return this._core.switchToNewThread();\n }\n\n public unstable_subscribeThreadEvents(\n callback: (event: ThreadListRuntimeEvent) => void,\n ): Unsubscribe {\n return (\n this._core.unstable_subscribeThreadEvents?.(callback) ?? NOOP_UNSUBSCRIBE\n );\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return this._core.getLoadThreadsPromise();\n }\n\n public reload(): Promise<void> {\n return this._core.reload?.() ?? RESOLVED_PROMISE;\n }\n\n public reloadMainThread(): Promise<void> {\n return this._core.reloadMainThread?.() ?? RESOLVED_PROMISE;\n }\n\n public loadMore(): Promise<void> {\n return this._core.loadMore?.() ?? RESOLVED_PROMISE;\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._stateBinding.subscribe(callback);\n }\n\n private _mainThreadListItemRuntime;\n\n public readonly main: ThreadRuntime;\n\n public get mainItem() {\n return this._mainThreadListItemRuntime;\n }\n\n public getById(threadId: string) {\n return new this._runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: `threads[threadId=${JSON.stringify(threadId)}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => this._core.getThreadRuntimeCore(threadId),\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this.mainItem,\n );\n }\n\n public getItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.threadIds[idx]);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(\n this._core,\n this._core.archivedThreadIds[idx],\n );\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n return getThreadListItemState(this._core, threadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";;;;AAyBA,MAAMc,mBAAmBC,QAAQC,QAAQ;AACzC,MAAMC,yBAAyB,CAAC;AAgEhC,MAAMmC,sBACJC,eACoB;CACpB,OAAO;EACLlC,cAAckC,WAAWlC;EACzBC,aAAaiC,WAAWjC;EACxBC,WAAWgC,WAAWhC;EACtBC,mBAAmB+B,WAAW/B;EAC9BC,WAAW8B,WAAW9B;EACtBC,eAAe6B,WAAW7B,iBAAiB;EAC3CC,SAAS4B,WAAW5B,WAAW;EAC/BC,aAAa2B,WAAW3B;CAC1B;AACF;AAEA,MAAM4B,0BACJD,YACAjB,aACsC;CACtC,IAAIA,aAAamB,KAAAA,GAAW,OAAOpD;CAEnC,MAAMqD,aAAaH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BAAgB;IACd,OAAOuB,uBAAuB,KAAKiB,OAAOnC,QAAQ;GACpD;GACAJ,YAAYC,aAAa,KAAKsC,MAAMvC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKsC,KACP;CACF;AACF"}
|
|
@@ -6,8 +6,8 @@ import { ChatModelRunOptions, ChatModelRunResult } from "../utils/chat-model-ada
|
|
|
6
6
|
import { ThreadMessageLike } from "../utils/thread-message-like.js";
|
|
7
7
|
import { ExportedMessageRepository } from "../utils/message-repository.js";
|
|
8
8
|
import { QuoteInfo } from "../../types/quote.js";
|
|
9
|
+
import { QueueItemState } from "../queue/queue-item.js";
|
|
9
10
|
import { QueuePlacement } from "../queue/external-thread-queue-adapter.js";
|
|
10
|
-
import { QueueItemState } from "../../store/scopes/queue-item.js";
|
|
11
11
|
import { ComposerRuntimeEventCallback, ComposerRuntimeEventType, DictationState, EditComposerRuntimeCore, SendOptions } from "../interfaces/composer-runtime-core.js";
|
|
12
12
|
import { AddToolResultOptions, RespondToToolApprovalOptions, ResumeRunConfig, ResumeToolCallOptions, RuntimeCapabilities, SpeechState, StartRunConfig, SubmitFeedbackOptions, ThreadRuntimeCore, ThreadRuntimeEventCallback, ThreadRuntimeEventType, ThreadSuggestion, VoiceSessionState } from "../interfaces/thread-runtime-core.js";
|
|
13
13
|
import { ThreadListItemRuntimePath, ThreadRuntimePath } from "./paths.js";
|
|
@@ -15,7 +15,6 @@ import { Subscribable, SubscribableWithState } from "../../subscribable/subscrib
|
|
|
15
15
|
import { ThreadListItemState } from "./bindings.js";
|
|
16
16
|
import { ThreadComposerRuntime, ThreadComposerRuntimeImpl } from "./composer-runtime.js";
|
|
17
17
|
import { MessageRuntime, MessageRuntimeImpl } from "./message-runtime.js";
|
|
18
|
-
import "../../store/index.js";
|
|
19
18
|
import "../../internal.js";
|
|
20
19
|
import "../../index.js";
|
|
21
20
|
import { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
@@ -208,7 +207,7 @@ declare class ThreadRuntimeImpl implements ThreadRuntime {
|
|
|
208
207
|
unstable_notifySessionReset: () => void;
|
|
209
208
|
addToolResult: (options: AddToolResultOptions) => void;
|
|
210
209
|
resumeToolCall: (options: ResumeToolCallOptions) => void;
|
|
211
|
-
respondToToolApproval: (options: RespondToToolApprovalOptions) => void
|
|
210
|
+
respondToToolApproval: (options: RespondToToolApprovalOptions) => Promise<void>;
|
|
212
211
|
speak: (messageId: string) => void;
|
|
213
212
|
stopSpeaking: () => void;
|
|
214
213
|
connectVoice: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-runtime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"thread-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-runtime.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KA+CY;EACV;EACA;EACA,YAAY;;KAGF,wBAAwB;EAClC,UACE,SAAS,wBACN,eAAe;;KAoBV;EAGN;EACA;EACA,OAAO;EACP,SAAS;EACT,cAAc;EACd,WAAW;EACX,YAAY;EACZ,YAAY;EACZ;;KAiCM,2BAA2B,sBACrC,mBACA;EAEA,eAAe,uBAAuB;;KAG5B,+BAA+B,sBACzC,qBACA;KAGU;;;;;WAKD;;;;;;WAOA,UAAU;;;;WAKV;;;;WAKA;;;;WAKA;;;;WAKA,cAAc;;;;WAKd,mBAAmB;;;;;;WAOnB,OAAO;;;;WAKP,sBAAsB;;;;WAKtB;;;;WAKA,QAAQ;WAER,OAAO;;;;;;cAOL,gCACX,SAAS,KAAK;cASH,iBACX,SAAS,mBACT,qBAAqB,wBACpB;KAiBS;;;;WAID,MAAM;;;;WAKN,UAAU;;;;EAKnB,YAAY;;;;;;;;;;;;;;;;;EAkBZ,OAAO,SAAS;EAEhB,cAAc,2BAA2B;;;;;EAMzC,SAAS,QAAQ;;;;;EAMjB,UAAU,QAAQ;;;;;;;EAQlB;;;;;;;EAQA,oBAAoB;EAEpB,UAAU,uBAAuB;EACjC;;;;;;;EAOA;EACA,mBAAmB;EAEnB,UAAU;EACV,OAAO,YAAY;;;;;;EAOnB,MAAM,2BAA2B;EAEjC,kBAAkB,cAAc;EAChC,eAAe,oBAAoB;;;;EAKnC;EAEA;EACA;EACA;EACA,qBAAqB,uBAAuB;EAC5C;EACA;EAEA,YAAY,UAAU,wBACpB,OAAO,GACP,UAAU,2BAA2B,KACpC;;cAGQ,6BAA6B;MAC7B,QAAI;MAIJ,4BAJI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QArQA,OAAA;;wBAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgDS,eAAA,uBAAa;;IA8NnB,iBAAA;;mBADF;mBAGA;EAMf,YAAA,eAAe,0BACf,uBAAuB;YA2Cf;WA4BM,UAAQ;EAEjB,YAAQ;EAIR,OAAO,SAAS;EAchB,cAAc,2BAAiB;EAI/B,UAAU;EAIV,mBAAe;EAIf,SAAS,QAAQ;EAIjB,UAAU,QAAQ;EAIlB;EAIA,oBAAoB;EAIpB;EAIA;EAIA;EAIA;EAIA;EAIA;EAIA,qBAAqB,uBAAoB;EAIzC;EAIA;EAIA,UAAM;EAIN,OAAO,MAAM;EAIb,MAAM,2BAA2B;EAIjC,kBAAkB,cAAW;EAsB7B,eAAe,oBAAiB;UAW/B;UA2CA;EAKD,YAAY,UAAU,wBAC3B,OAAO,GACP,UAAU,2BAA2B,KACpC"}
|
|
@@ -3,8 +3,8 @@ import { Attachment, CreateAttachment } from "../../types/attachment.js";
|
|
|
3
3
|
import { AttachmentAdapter } from "../../adapters/attachment.js";
|
|
4
4
|
import { DictationAdapter } from "../../adapters/speech.js";
|
|
5
5
|
import { QuoteInfo } from "../../types/quote.js";
|
|
6
|
+
import { QueueItemState } from "../queue/queue-item.js";
|
|
6
7
|
import { QueuePlacement } from "../queue/external-thread-queue-adapter.js";
|
|
7
|
-
import { QueueItemState } from "../../store/scopes/queue-item.js";
|
|
8
8
|
import { ComposerRuntimeCore, ComposerRuntimeEventCallback, ComposerRuntimeEventPayload, ComposerRuntimeEventType, DictationState, SendOptions } from "../interfaces/composer-runtime-core.js";
|
|
9
9
|
import { BaseSubscribable } from "../../subscribable/subscribable.js";
|
|
10
10
|
//#region src/runtime/base/base-composer-runtime-core.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/base-composer-runtime-core.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"base-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/base-composer-runtime-core.ts"],"mappings":";;;;;;;;;;uBAuCsB,gCACZ,4BACG;WAEK;qBAEG,wBAAwB;qBACxB,uBAAuB;YAEhC,2BACR;IAAY;MAAa,SAAS;;KAClC,SAAS,GAAG,kBAAkB,sCAAsC;MAW3D;UAIH;MACG,wBAAW;YAIZ,eAAe,gBAAgB;eAKrB;eACA;MAET;UAIH;MAEJ;UAII;MAEJ;UAII;MAEJ,aAAS;UAIL;MAEJ,SAAK;EAIF,SAAS,OAAO;EAOhB,QAAQ;UAWP;EASD,QAAQ,MAAM;EAOd,aAAa,WAAW;YAOrB;UACF;UACA;UACA;UAEA;UAIA;UAIA;UAMM;EAQD,SAAK;EA8BL,oBAAgB;EAQhB,KAAK,UAAU,cAAW;;;;;;;;;EAsGhC,aAAa;IAClB;IACA,QAAQ;IACR,uBAAuB;;;;;;;EAsBlB,aAAa;IAClB;IACA,QAAQ;IACR,uBAAuB;;UAuBjB;EAcD;MAII,kBAAkB;EAItB,cACL,sBACA,YAAY;EAEP,gBAAgB;qBAEJ,WACjB,SAAS,KAAK,yCACd,UAAU,qBACF;qBACS;EAEb,cAAc,kBAAkB,OAAO,mBAAgB;UA8HrD;EAqBF,iBAAiB,uBAAoB;UAmCnC;UACA;UACA;UACA;UACA;UACA;UACA;UACA;MAEG,aAAa;UAIhB;EAUD;EA6FA;UASC;UAuBA;YAKE,wBAAwB,UAAU,0BAC1C,OAAO,GACP,SAAS,4BAA4B;EAQhC,YAAY,UAAU,0BAC3B,OAAO,GACP,UAAU,6BAA6B"}
|
|
@@ -3,8 +3,9 @@ import { BaseSubscribable } from "../../subscribable/subscribable.js";
|
|
|
3
3
|
import { generateId } from "../../utils/id.js";
|
|
4
4
|
import { fileMatchesAccept } from "../../adapters/attachment.js";
|
|
5
5
|
import { isMessageNotSentError } from "../../types/error.js";
|
|
6
|
-
import { EMPTY_QUEUE_ITEMS } from "
|
|
6
|
+
import { EMPTY_QUEUE_ITEMS } from "../queue/queue-item.js";
|
|
7
7
|
import { isCreateAttachment } from "../../types/attachment.js";
|
|
8
|
+
import { AttachmentAddOperations, drainAttachmentAdd } from "../utils/attachment-add-operations.js";
|
|
8
9
|
//#region src/runtime/base/base-composer-runtime-core.ts
|
|
9
10
|
const isAttachmentComplete = (a) => a.status.type === "complete";
|
|
10
11
|
var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
@@ -86,17 +87,12 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
86
87
|
_isSending = false;
|
|
87
88
|
_removedDuringSend = /* @__PURE__ */ new Set();
|
|
88
89
|
_sendGeneration = 0;
|
|
89
|
-
_attachmentAddOperations =
|
|
90
|
+
_attachmentAddOperations = new AttachmentAddOperations();
|
|
90
91
|
_cancelAttachmentAdd(attachmentId) {
|
|
91
|
-
|
|
92
|
-
if (!operation.attachmentIds.has(attachmentId)) continue;
|
|
93
|
-
operation.cancelled = true;
|
|
94
|
-
this._attachmentAddOperations.delete(operation);
|
|
95
|
-
}
|
|
92
|
+
this._attachmentAddOperations.cancel(attachmentId);
|
|
96
93
|
}
|
|
97
94
|
_cancelAllAttachmentAdds() {
|
|
98
|
-
|
|
99
|
-
this._attachmentAddOperations.clear();
|
|
95
|
+
this._attachmentAddOperations.cancelAll();
|
|
100
96
|
}
|
|
101
97
|
_emptyTextAndAttachments() {
|
|
102
98
|
this._attachments = [];
|
|
@@ -291,15 +287,9 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
291
287
|
this._safeEmitAttachmentAddError("not-accepted", message, void 0, err);
|
|
292
288
|
throw err;
|
|
293
289
|
}
|
|
294
|
-
const operation =
|
|
295
|
-
cancelled: false,
|
|
296
|
-
attachmentIds: /* @__PURE__ */ new Set()
|
|
297
|
-
};
|
|
298
|
-
const operations = this._attachmentAddOperations;
|
|
299
|
-
operations.add(operation);
|
|
290
|
+
const operation = this._attachmentAddOperations.start();
|
|
300
291
|
const upsertAttachment = (a) => {
|
|
301
|
-
if (operation.
|
|
302
|
-
operation.attachmentIds.add(a.id);
|
|
292
|
+
if (!this._attachmentAddOperations.accept(operation, a.id)) return false;
|
|
303
293
|
const idx = this._attachments.findIndex((attachment) => attachment.id === a.id);
|
|
304
294
|
if (idx !== -1) this._attachments = [
|
|
305
295
|
...this._attachments.slice(0, idx),
|
|
@@ -312,17 +302,12 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
312
302
|
};
|
|
313
303
|
let lastAttachment;
|
|
314
304
|
try {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
lastAttachment = await promiseOrGenerator;
|
|
322
|
-
upsertAttachment(lastAttachment);
|
|
323
|
-
}
|
|
305
|
+
await drainAttachmentAdd(adapter.add({ file: fileOrAttachment }), (attachment) => {
|
|
306
|
+
lastAttachment = attachment;
|
|
307
|
+
return upsertAttachment(attachment);
|
|
308
|
+
});
|
|
324
309
|
} catch (e) {
|
|
325
|
-
if (operation
|
|
310
|
+
if (this._attachmentAddOperations.isCancelled(operation)) return;
|
|
326
311
|
if (lastAttachment) upsertAttachment({
|
|
327
312
|
...lastAttachment,
|
|
328
313
|
status: {
|
|
@@ -334,9 +319,9 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
334
319
|
this._safeEmitAttachmentAddError("adapter-error", e instanceof Error ? e.message : String(e), lastAttachment?.id, e instanceof Error ? e : void 0);
|
|
335
320
|
throw e;
|
|
336
321
|
} finally {
|
|
337
|
-
|
|
322
|
+
this._attachmentAddOperations.finish(operation);
|
|
338
323
|
}
|
|
339
|
-
if (operation
|
|
324
|
+
if (this._attachmentAddOperations.isCancelled(operation)) return;
|
|
340
325
|
if (lastAttachment?.status.type === "incomplete" && lastAttachment.status.reason === "error") this._safeEmitAttachmentAddError("adapter-error", lastAttachment.status.message ?? "Attachment upload did not complete successfully.", lastAttachment.id);
|
|
341
326
|
else this._notifyEventSubscribers("attachmentAdd", {});
|
|
342
327
|
}
|