@assistant-ui/core 0.3.17 → 0.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/attachment.d.ts.map +1 -1
- package/dist/adapters/attachment.js +5 -4
- package/dist/adapters/attachment.js.map +1 -1
- package/dist/adapters/speech.d.ts.map +1 -1
- package/dist/adapters/speech.js +13 -3
- package/dist/adapters/speech.js.map +1 -1
- package/dist/adapters/thread-history.d.ts +4 -0
- package/dist/adapters/thread-history.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -3
- package/dist/internal.js +3 -2
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +35 -14
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/frame/provider.d.ts +2 -0
- package/dist/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +30 -7
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/interactable-composer-metadata.d.ts.map +1 -1
- package/dist/model-context/interactable-composer-metadata.js +27 -18
- package/dist/model-context/interactable-composer-metadata.js.map +1 -1
- package/dist/model-context/registry.d.ts.map +1 -1
- package/dist/model-context/registry.js +3 -5
- package/dist/model-context/registry.js.map +1 -1
- package/dist/model-context/types.d.ts.map +1 -1
- package/dist/model-context/types.js +5 -4
- package/dist/model-context/types.js.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +45 -7
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/DataRenderers.d.ts.map +1 -1
- package/dist/react/client/DataRenderers.js +20 -15
- package/dist/react/client/DataRenderers.js.map +1 -1
- package/dist/react/client/InMemoryThreadList.d.ts.map +1 -1
- package/dist/react/client/InMemoryThreadList.js +62 -56
- 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 +35 -32
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/RemoteThreadList.d.ts +1 -0
- package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
- package/dist/react/client/RemoteThreadList.js +154 -143
- 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 +18 -16
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/client/interactable-model-context.d.ts.map +1 -1
- package/dist/react/client/interactable-model-context.js +3 -2
- package/dist/react/client/interactable-model-context.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +2 -2
- package/dist/react/interactables-legacy/Interactables.js +242 -121
- package/dist/react/interactables-legacy/Interactables.js.map +1 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.d.ts.map +1 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.js +3 -0
- package/dist/react/interactables-legacy/useAssistantInteractable.js.map +1 -1
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts.map +1 -1
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.js +11 -9
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.js.map +1 -1
- package/dist/react/model-context/makeAssistantTool.d.ts +2 -2
- package/dist/react/model-context/makeAssistantTool.js +1 -1
- package/dist/react/model-context/makeAssistantTool.js.map +1 -1
- package/dist/react/model-context/useAssistantTool.d.ts +2 -2
- package/dist/react/model-context/useAssistantTool.js +1 -1
- package/dist/react/model-context/useAssistantTool.js.map +1 -1
- package/dist/react/model-context/useInteractable.d.ts.map +1 -1
- package/dist/react/model-context/useInteractable.js +4 -1
- package/dist/react/model-context/useInteractable.js.map +1 -1
- package/dist/react/model-context/useInteractableVersions.js +1 -1
- package/dist/react/model-context/useToolArgsStatus.d.ts.map +1 -1
- package/dist/react/model-context/useToolArgsStatus.js +2 -1
- package/dist/react/model-context/useToolArgsStatus.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.d.ts +11 -2
- package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +3 -2
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/part/PartMessages.d.ts +1 -0
- package/dist/react/primitives/part/PartMessages.d.ts.map +1 -1
- package/dist/react/primitives/part/PartMessages.js +1 -0
- package/dist/react/primitives/part/PartMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.d.ts.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js +6 -5
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +16 -8
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +5 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +105 -104
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.d.ts +1 -0
- package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.js +13 -11
- package/dist/react/runtimes/RemoteThreadResource.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +5 -24
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +354 -226
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +1 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +22 -2
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +40 -15
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +62 -15
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts +2 -1
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js +6 -1
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/sdkIdentity.d.ts +6 -0
- package/dist/react/runtimes/cloud/sdkIdentity.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/sdkIdentity.js +9 -0
- package/dist/react/runtimes/cloud/sdkIdentity.js.map +1 -0
- package/dist/react/runtimes/external-message-converter.d.ts +12 -2
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +26 -61
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.js +75 -46
- package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +64 -24
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/utils/groupParts.d.ts +6 -1
- package/dist/react/utils/groupParts.d.ts.map +1 -1
- package/dist/react/utils/groupParts.js +6 -0
- package/dist/react/utils/groupParts.js.map +1 -1
- package/dist/react/utils/useJSONEqual.d.ts +3 -1
- package/dist/react/utils/useJSONEqual.d.ts.map +1 -1
- package/dist/react/utils/useJSONEqual.js +6 -1
- package/dist/react/utils/useJSONEqual.js.map +1 -1
- package/dist/react/utils/useJSONSchemaDependency.d.ts +7 -0
- package/dist/react/utils/useJSONSchemaDependency.d.ts.map +1 -0
- package/dist/react/utils/useJSONSchemaDependency.js +20 -0
- package/dist/react/utils/useJSONSchemaDependency.js.map +1 -0
- package/dist/runtime/api/thread-list-item-runtime.d.ts +7 -3
- package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.js +2 -2
- package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +3 -0
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +18 -14
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +4 -0
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.js +3 -6
- package/dist/runtime/api/thread-runtime.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -0
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +62 -22
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +2 -0
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +161 -69
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/composer-runtime-core.d.ts +12 -5
- package/dist/runtime/interfaces/composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +4 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +6 -0
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.d.ts +5 -0
- package/dist/runtime/queue/message-queue.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.js +61 -6
- package/dist/runtime/queue/message-queue.js.map +1 -1
- package/dist/runtime/utils/auto-status.d.ts +6 -2
- package/dist/runtime/utils/auto-status.d.ts.map +1 -1
- package/dist/runtime/utils/auto-status.js +12 -4
- package/dist/runtime/utils/auto-status.js.map +1 -1
- package/dist/runtime/utils/external-message-conversion.d.ts +16 -4
- package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -1
- package/dist/runtime/utils/external-message-conversion.js +49 -13
- package/dist/runtime/utils/external-message-conversion.js.map +1 -1
- package/dist/runtime/utils/message-repository.d.ts +1 -0
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.js +18 -9
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtime/utils/thread-message-like.d.ts +2 -1
- package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.js +5 -3
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +21 -27
- 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.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +8 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/internal.d.ts +3 -3
- package/dist/runtimes/internal.js +2 -2
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +4 -1
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +18 -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 +130 -42
- package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/title-generation.d.ts +49 -0
- package/dist/runtimes/remote-thread-list/title-generation.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/title-generation.js +197 -0
- package/dist/runtimes/remote-thread-list/title-generation.js.map +1 -0
- package/dist/runtimes/remote-thread-list/title.d.ts +3 -1
- package/dist/runtimes/remote-thread-list/title.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/title.js +9 -1
- package/dist/runtimes/remote-thread-list/title.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +10 -0
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +2 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/external-thread.d.ts.map +1 -1
- package/dist/store/clients/external-thread.js +260 -203
- package/dist/store/clients/external-thread.js.map +1 -1
- package/dist/store/clients/model-context-client.d.ts.map +1 -1
- package/dist/store/clients/model-context-client.js +2 -1
- package/dist/store/clients/model-context-client.js.map +1 -1
- package/dist/store/clients/single-thread-list.d.ts.map +1 -1
- package/dist/store/clients/single-thread-list.js +1 -0
- 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 +5 -4
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-tasks.d.ts +13 -0
- package/dist/store/clients/thread-tasks.d.ts.map +1 -0
- package/dist/store/clients/thread-tasks.js +69 -0
- package/dist/store/clients/thread-tasks.js.map +1 -0
- package/dist/store/index.d.ts +3 -2
- package/dist/store/index.js +3 -3
- package/dist/store/primitive-predicates.d.ts.map +1 -1
- package/dist/store/primitive-predicates.js +4 -4
- package/dist/store/primitive-predicates.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts +1 -0
- package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +97 -61
- package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts +1 -0
- package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +221 -144
- package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +54 -52
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +246 -126
- package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
- package/dist/store/scope-registration.d.ts +2 -0
- package/dist/store/scope-registration.d.ts.map +1 -1
- package/dist/store/scopes/composer.d.ts +10 -2
- package/dist/store/scopes/composer.d.ts.map +1 -1
- package/dist/store/scopes/message.d.ts +30 -1
- package/dist/store/scopes/message.d.ts.map +1 -1
- package/dist/store/scopes/task.d.ts +36 -0
- package/dist/store/scopes/task.d.ts.map +1 -0
- package/dist/store/scopes/task.js +0 -0
- package/dist/store/scopes/thread-list-item.d.ts +2 -2
- package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
- package/dist/store/scopes/thread.d.ts +28 -0
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/store/scopes/threads.d.ts +1 -0
- package/dist/store/scopes/threads.d.ts.map +1 -1
- package/dist/subscribable/subscribable.d.ts +2 -1
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +23 -15
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/types/attachment.d.ts +2 -1
- package/dist/types/attachment.d.ts.map +1 -1
- package/dist/types/attachment.js +2 -1
- package/dist/types/attachment.js.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/message.d.ts +8 -1
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/abortable-iterable.d.ts +19 -0
- package/dist/utils/abortable-iterable.d.ts.map +1 -0
- package/dist/utils/abortable-iterable.js +88 -0
- package/dist/utils/abortable-iterable.js.map +1 -0
- package/dist/utils/composite-context-provider.d.ts.map +1 -1
- package/dist/utils/composite-context-provider.js +20 -2
- package/dist/utils/composite-context-provider.js.map +1 -1
- package/dist/utils/getGroupStatus.d.ts +18 -2
- package/dist/utils/getGroupStatus.d.ts.map +1 -1
- package/dist/utils/getGroupStatus.js +32 -7
- package/dist/utils/getGroupStatus.js.map +1 -1
- package/dist/utils/record.d.ts +11 -0
- package/dist/utils/record.d.ts.map +1 -0
- package/dist/utils/record.js +12 -0
- package/dist/utils/record.js.map +1 -0
- package/dist/utils/wire-media.d.ts.map +1 -1
- package/dist/utils/wire-media.js +2 -2
- package/dist/utils/wire-media.js.map +1 -1
- package/package.json +11 -11
- package/src/adapters/attachment.test.ts +50 -1
- package/src/adapters/attachment.ts +7 -4
- package/src/adapters/speech.test.ts +236 -0
- package/src/adapters/speech.ts +17 -10
- package/src/adapters/thread-history.ts +3 -0
- package/src/index.ts +2 -0
- package/src/internal.ts +4 -0
- package/src/model-context/frame/host.test.ts +137 -1
- package/src/model-context/frame/host.ts +49 -16
- package/src/model-context/frame/provider.test.ts +71 -0
- package/src/model-context/frame/provider.ts +37 -7
- package/src/model-context/interactable-composer-metadata.test.ts +58 -0
- package/src/model-context/interactable-composer-metadata.ts +19 -13
- package/src/model-context/registry.test.ts +12 -0
- package/src/model-context/registry.ts +3 -2
- package/src/model-context/types.test.ts +25 -0
- package/src/model-context/types.ts +9 -4
- package/src/react/RuntimeAdapter.test.ts +34 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.test.ts +244 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +104 -7
- package/src/react/client/DataRenderers.test.tsx +45 -0
- package/src/react/client/DataRenderers.ts +13 -9
- package/src/react/client/InMemoryThreadList.ts +1 -0
- package/src/react/client/Interactables.test.ts +72 -1
- package/src/react/client/Interactables.ts +22 -14
- package/src/react/client/RemoteThreadList.background.test.ts +148 -6
- package/src/react/client/RemoteThreadList.concurrent.test.tsx +42 -1
- package/src/react/client/RemoteThreadList.test.ts +386 -4
- package/src/react/client/RemoteThreadList.ts +181 -112
- package/src/react/client/Tools.ts +22 -11
- package/src/react/client/interactable-model-context.test.ts +44 -0
- package/src/react/client/interactable-model-context.ts +3 -2
- package/src/react/index.ts +5 -1
- package/src/react/interactables-legacy/Interactables.ts +16 -16
- package/src/react/interactables-legacy/useAssistantInteractable.test.tsx +132 -0
- package/src/react/interactables-legacy/useAssistantInteractable.ts +10 -1
- package/src/react/interactables-shared/useInteractablePersistenceQueue.ts +9 -10
- package/src/react/model-context/makeAssistantTool.ts +2 -2
- package/src/react/model-context/useAssistantTool.ts +2 -2
- package/src/react/model-context/useInteractable.test.tsx +177 -0
- package/src/react/model-context/useInteractable.ts +3 -0
- package/src/react/model-context/useToolArgsStatus.test.tsx +30 -0
- package/src/react/model-context/useToolArgsStatus.ts +2 -1
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +0 -1
- package/src/react/primitive-hooks/useSuggestionTrigger.test.ts +0 -1
- package/src/react/primitives/message/MessageGroupedParts.test.tsx +96 -0
- package/src/react/primitives/message/MessageGroupedParts.tsx +15 -4
- package/src/react/primitives/part/PartMessages.test.tsx +104 -1
- package/src/react/primitives/part/PartMessages.tsx +1 -0
- package/src/react/primitives/thread/ThreadMessages.test.tsx +142 -0
- package/src/react/primitives/thread/ThreadMessages.tsx +8 -5
- package/src/react/providers/ReadonlyThreadProvider.test.tsx +56 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.destroy.test.tsx +172 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +33 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +7 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +28 -5
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.load-error.test.ts +132 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.switch-delete.test.ts +105 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +143 -112
- package/src/react/runtimes/RemoteThreadResource.test.ts +9 -0
- package/src/react/runtimes/RemoteThreadResource.ts +19 -12
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +20 -14
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +703 -6
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +492 -402
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.test.ts +77 -0
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +27 -1
- package/src/react/runtimes/cloud/auiV0.ts +160 -25
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +36 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +8 -1
- package/src/react/runtimes/cloud/sdkIdentity.ts +9 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +18 -4
- package/src/react/runtimes/external-message-converter.test.ts +136 -1
- package/src/react/runtimes/external-message-converter.ts +39 -93
- package/src/react/runtimes/useExternalStoreRuntime.lifecycle.test.tsx +41 -0
- package/src/react/runtimes/useExternalStoreRuntime.ts +10 -4
- package/src/react/runtimes/useLocalRuntime.test.tsx +20 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.load-error.test.tsx +108 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +34 -1
- package/src/react/utils/groupParts.ts +12 -1
- package/src/react/utils/useJSONEqual.ts +9 -0
- package/src/react/utils/useJSONSchemaDependency.ts +22 -0
- package/src/runtime/api/message-runtime.test.ts +75 -0
- package/src/runtime/api/thread-list-item-runtime.ts +10 -3
- package/src/runtime/api/thread-list-runtime.ts +21 -11
- package/src/runtime/api/thread-runtime.test.ts +136 -0
- package/src/runtime/api/thread-runtime.ts +10 -5
- package/src/runtime/base/base-composer-runtime-core.ts +105 -24
- package/src/runtime/base/base-thread-runtime-core.test.ts +1063 -2
- package/src/runtime/base/base-thread-runtime-core.ts +228 -87
- package/src/runtime/interfaces/composer-runtime-core.ts +10 -5
- package/src/runtime/interfaces/thread-list-runtime-core.ts +5 -1
- package/src/runtime/interfaces/thread-runtime-core.ts +6 -0
- package/src/runtime/queue/message-queue.ts +68 -6
- package/src/runtime/utils/auto-status.test.ts +112 -1
- package/src/runtime/utils/auto-status.ts +31 -5
- package/src/runtime/utils/external-message-conversion.test.ts +202 -0
- package/src/runtime/utils/external-message-conversion.ts +123 -32
- package/src/runtime/utils/message-repository.test.ts +49 -0
- package/src/runtime/utils/message-repository.ts +32 -20
- package/src/runtime/utils/thread-message-like.test.ts +52 -0
- package/src/runtime/utils/thread-message-like.ts +5 -1
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +18 -13
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +31 -1
- package/src/runtimes/internal.ts +1 -0
- package/src/runtimes/local/local-thread-runtime-core.test.ts +21 -0
- package/src/runtimes/local/local-thread-runtime-core.ts +11 -1
- package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +128 -2
- package/src/runtimes/remote-thread-list/remote-thread-state.ts +182 -42
- package/src/runtimes/remote-thread-list/title-generation.test.ts +602 -0
- package/src/runtimes/remote-thread-list/title-generation.ts +329 -0
- package/src/runtimes/remote-thread-list/title.test.ts +62 -0
- package/src/runtimes/remote-thread-list/title.ts +13 -0
- package/src/runtimes/remote-thread-list/types.ts +10 -0
- package/src/runtimes/tool-invocations/EDGE_CASES.md +2 -6
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +133 -0
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +10 -6
- package/src/store/clients/external-thread.ts +67 -4
- package/src/store/clients/model-context-client.ts +5 -1
- package/src/store/clients/single-thread-list.ts +1 -0
- package/src/store/clients/suggestions.test.ts +40 -0
- package/src/store/clients/suggestions.ts +13 -10
- package/src/store/clients/thread-tasks.test.ts +274 -0
- package/src/store/clients/thread-tasks.ts +138 -0
- package/src/store/index.ts +8 -0
- package/src/store/primitive-predicates.test.ts +48 -5
- package/src/store/primitive-predicates.ts +7 -2
- package/src/store/runtime-clients/composer-runtime-client.ts +42 -9
- package/src/store/runtime-clients/message-runtime-client.ts +54 -6
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +4 -2
- package/src/store/runtime-clients/thread-list-runtime-client.ts +1 -0
- package/src/store/runtime-clients/thread-runtime-client.ts +89 -11
- package/src/store/scope-registration.ts +2 -0
- package/src/store/scopes/composer.ts +16 -4
- package/src/store/scopes/message.ts +14 -0
- package/src/store/scopes/task.ts +34 -0
- package/src/store/scopes/thread-list-item.ts +5 -2
- package/src/store/scopes/thread.ts +20 -0
- package/src/store/scopes/threads.ts +1 -0
- package/src/store/thread-tasks.test.tsx +209 -0
- package/src/subscribable/subscribable.test.ts +156 -1
- package/src/subscribable/subscribable.ts +25 -15
- package/src/tests/MessageRepository.test.ts +117 -5
- package/src/tests/OptimisticState-list-race.test.ts +1 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-initialize-adapter-change.test.ts +38 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-load-race.test.ts +47 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-title-race.test.ts +89 -0
- package/src/tests/attachment-adapters.test.ts +14 -0
- package/src/tests/auiV0Encode.test.ts +300 -0
- package/src/tests/base-composer-runtime-core-send.test.ts +51 -0
- package/src/tests/base-composer-runtime-core.test.ts +353 -2
- package/src/tests/external-store-thread-list-runtime-core.test.ts +83 -0
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +178 -18
- package/src/tests/external-thread-attachments.test.tsx +208 -0
- package/src/tests/external-thread-parity.test.tsx +57 -0
- package/src/tests/groupParts.test.ts +71 -0
- package/src/tests/message-queue.test.ts +253 -0
- package/src/tests/remote-thread-list-isLoading.test.ts +1 -0
- package/src/tests/remote-thread-list-reactive-threadId.test.ts +51 -0
- package/src/tests/thread-list-runtime-getLoadThreadsPromise.test.ts +1 -0
- package/src/tests/thread-switch-events.test.tsx +78 -0
- package/src/tests/tools-scope-migration.test.tsx +28 -0
- package/src/tests/useRemoteThreadListRuntime-controlled.test.tsx +43 -0
- package/src/types/attachment.ts +4 -0
- package/src/types/index.ts +1 -0
- package/src/types/message.ts +8 -0
- package/src/utils/abortable-iterable.test.ts +328 -0
- package/src/utils/abortable-iterable.ts +104 -0
- package/src/utils/composite-context-provider.test.ts +25 -0
- package/src/utils/composite-context-provider.ts +23 -2
- package/src/utils/getGroupStatus.test.ts +70 -4
- package/src/utils/getGroupStatus.ts +35 -12
- package/src/utils/record.test.ts +48 -0
- package/src/utils/record.ts +11 -0
- package/src/utils/wire-media.test.ts +10 -0
- package/src/utils/wire-media.ts +6 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageGroupedParts.js","names":["Fragment","FC","ReactNode","useMemo","useAuiState","useShallowSelector","PartState","MessagePartStatus","ToolCallMessagePartStatus","getGroupStatus","buildGroupTree","GROUPBY_MEMO_KEY","GroupByContext","GroupNode","MessagePartChildren","EnrichedPartState","MessagePrimitiveGroupedParts","GroupPart","type","TKey","status","indices","IndicatorPart","IndicatorMode","RenderInfo","part","children","Props","groupBy","context","indicator","info","shouldShowIndicator","mode","parts","isRunning","length","last","undefined","PartChildrenSentinel","Error","renderNode","node","render","idKey","index","groupPart","key","nodeKey","map","child","s","message","toolUIs","tools","memoKey","memoDep","tree","toolCallId","displayName"],"sources":["../../../../src/react/primitives/message/MessageGroupedParts.tsx"],"sourcesContent":["\"use client\";\n\nimport { Fragment, type FC, type ReactNode, useMemo } from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\nimport { useShallowSelector } from \"@assistant-ui/store/internal\";\nimport type { PartState } from \"../../../store/scopes/part\";\nimport type {\n MessagePartStatus,\n ToolCallMessagePartStatus,\n} from \"../../../types/message\";\nimport { getGroupStatus } from \"../../../utils/getGroupStatus\";\nimport {\n buildGroupTree,\n GROUPBY_MEMO_KEY,\n type GroupByContext,\n type GroupNode,\n} from \"../../utils/groupParts\";\nimport { MessagePartChildren, type EnrichedPartState } from \"./MessageParts\";\n\nexport namespace MessagePrimitiveGroupedParts {\n /**\n * A coalesced group of adjacent parts. Surfaced through the same\n * `{ part }` channel as a leaf {@link EnrichedPartState} so consumers\n * dispatch on a single `switch (part.type)`. `type` is the group key\n * (always `\"group-…\"`); `status` is running when any contained part runs,\n * otherwise it mirrors the last contained part.\n */\n export type GroupPart<TKey extends `group-${string}` = `group-${string}`> = {\n readonly type: TKey;\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n readonly indices: readonly number[];\n };\n\n /**\n * Synthetic trailing slot for a streaming/loading affordance (a\n * \"thinking…\" dot, etc.). Surfaced through the same `{ part }` channel\n * as groups and leaf parts so a single `switch (part.type)` renders it\n * via `case \"indicator\"`.\n *\n * It is only ever emitted while the message is running, so its presence\n * alone means \"render your loading UI here\" — there's no `status` to\n * branch on.\n */\n export type IndicatorPart = {\n readonly type: \"indicator\";\n };\n\n /**\n * When to emit the synthetic {@link IndicatorPart}. It is **only** emitted\n * while the message is running (streaming); the mode further restricts\n * which running states qualify:\n * - `\"never\"` — never.\n * - `\"empty\"` — only when the message has no parts yet.\n * - `\"no-text\"` (default) — when the message has no parts yet or the last\n * part isn't `text`/`reasoning` (e.g. it ended on a tool call, so the\n * assistant likely isn't done).\n * - `\"always\"` — whenever the message is running, regardless of parts.\n */\n export type IndicatorMode = \"never\" | \"empty\" | \"no-text\" | \"always\";\n\n export type RenderInfo<TKey extends `group-${string}` = `group-${string}`> = {\n /**\n * Either a coalesced group ({@link GroupPart}, identified by a\n * `group-…` `type`), a single enriched leaf part, or the synthetic\n * {@link IndicatorPart} (`type: \"indicator\"`). Use one switch over\n * `part.type` to handle all three.\n */\n readonly part: GroupPart<TKey> | EnrichedPartState | IndicatorPart;\n /**\n * For group nodes: the recursively-rendered subtree (subgroups +\n * leaf parts). For leaf parts: a sentinel that throws when rendered\n * — accidental fall-through (`default: return children;`) errors\n * loudly instead of silently rendering nothing.\n */\n readonly children: ReactNode;\n };\n\n export type Props<TKey extends `group-${string}` = `group-${string}`> = {\n /**\n * Maps each part to a group-key path. Adjacent parts that share a\n * prefix coalesce into the same group. Return `[]` (or `null`) to\n * leave a part ungrouped.\n *\n * Group keys must start with `\"group-\"` so the renderer's\n * `switch (part.type)` can tell groups apart from real part types.\n *\n * **Prefer {@link groupPartByType}** for the common case of mapping by\n * `part.type` — it ships a stable memo fingerprint so the tree\n * survives unrelated re-renders. Use an inline function only when\n * the helper isn't expressive enough (e.g. branching on\n * `part.toolName` or part metadata).\n *\n * The second argument is a {@link GroupByContext} carrying the tool-UI\n * registry, for grouping that depends on it (e.g. standalone tool calls).\n *\n * @example\n * ```tsx\n * import { groupPartByType } from \"@assistant-ui/react\";\n *\n * <MessagePrimitive.GroupedParts\n * groupBy={groupPartByType({\n * reasoning: [\"group-thought\", \"group-reasoning\"],\n * \"tool-call\": [\"group-thought\", \"group-tool\"],\n * })}\n * >\n * ```\n */\n readonly groupBy: (\n part: PartState,\n context: GroupByContext,\n ) => readonly TKey[] | null;\n\n /**\n * Controls emission of the synthetic {@link IndicatorPart} — a\n * trailing `{ part: { type: \"indicator\", status } }` render call you\n * handle with `case \"indicator\"` to show loading/status UI.\n *\n * @default \"no-text\"\n * @see IndicatorMode\n */\n readonly indicator?: IndicatorMode;\n\n /**\n * Render function called once per group node, once per leaf part, and\n * (when the `indicator` condition is met) once for the trailing\n * {@link IndicatorPart}. Switch on `part.type`: `\"group-…\"` cases wrap\n * `children`; real part types (`\"text\"`, `\"tool-call\"`, …) render the\n * part directly; `\"indicator\"` renders status/loading UI.\n *\n * Leaf parts receive the same {@link EnrichedPartState} that\n * `<MessagePrimitive.Parts>` would produce (`toolUI`, `addResult`,\n * `resume`, `respondToApproval`, `dataRendererUI`).\n */\n readonly children: (info: RenderInfo<TKey>) => ReactNode;\n };\n}\n\nconst shouldShowIndicator = (\n mode: MessagePrimitiveGroupedParts.IndicatorMode,\n parts: readonly PartState[],\n isRunning: boolean,\n): boolean => {\n // The indicator is a streaming affordance — never show it on a settled\n // message, whatever the mode.\n if (!isRunning) return false;\n\n switch (mode) {\n case \"never\":\n return false;\n case \"always\":\n return true;\n case \"empty\":\n return parts.length === 0;\n case \"no-text\": {\n const last = parts[parts.length - 1];\n return (\n last === undefined ||\n (last.type !== \"text\" && last.type !== \"reasoning\")\n );\n }\n }\n};\n\n/**\n * `children` placeholder passed for leaf-part renders. Leaf parts have no\n * inner subtree; rendering this sentinel signals the consumer wrote\n * `default: return children;` and accidentally fell through for a part —\n * surface the bug loudly instead of silently rendering nothing.\n */\nconst PartChildrenSentinel: FC = () => {\n throw new Error(\n \"MessagePrimitive.GroupedParts: rendered `children` under a leaf \" +\n \"part. `children` is only meaningful for `group-…` cases — add a \" +\n \"matching case for the part type or return `null` to skip it.\",\n );\n};\n\nconst renderNode = <TKey extends `group-${string}`>(\n node: GroupNode,\n parts: readonly PartState[],\n render: (info: MessagePrimitiveGroupedParts.RenderInfo<TKey>) => ReactNode,\n): ReactNode => {\n if (node.type === \"part\") {\n // Key by part identity when available, else absolute part index — never\n // the structural nodeKey, which leaves zombie fiber subscriptions when\n // parts reshape (#4051).\n return (\n <MessagePartChildren\n key={node.idKey ? `part-${node.idKey}` : `part-${node.index}`}\n index={node.index}\n >\n {({ part }) => render({ part, children: <PartChildrenSentinel /> })}\n </MessagePartChildren>\n );\n }\n\n const status = getGroupStatus(parts, node.indices);\n const groupPart: MessagePrimitiveGroupedParts.GroupPart<TKey> = {\n type: node.key as TKey,\n status,\n indices: node.indices,\n };\n\n return (\n <Fragment key={node.idKey ?? node.nodeKey}>\n {render({\n part: groupPart,\n children: (\n <>{node.children.map((child) => renderNode(child, parts, render))}</>\n ),\n })}\n </Fragment>\n );\n};\n\n/**\n * Groups adjacent message parts into a tree of coalesced runs and\n * renders each node — group or part — through a single `children`\n * function.\n *\n * The render function receives `{ part, children }` where `part.type`\n * is either a `\"group-…\"` literal (for a group, `children` is the\n * recursively-rendered subtree) or a real part type (`\"text\"`,\n * `\"tool-call\"`, …) for a leaf (`children` is a sentinel that throws\n * if rendered — use `part.type` to distinguish).\n *\n * @example\n * ```tsx\n * <MessagePrimitive.GroupedParts\n * groupBy={groupPartByType({\n * reasoning: [\"group-thought\", \"group-reasoning\"],\n * \"tool-call\": [\"group-thought\", \"group-tool\"],\n * })}\n * >\n * {({ part, children }) => {\n * switch (part.type) {\n * case \"group-thought\": return <Thought>{children}</Thought>;\n * case \"group-reasoning\": return <Reasoning>{children}</Reasoning>;\n * case \"group-tool\": return <ToolStack>{children}</ToolStack>;\n * case \"text\": return <MarkdownText />;\n * case \"tool-call\": return part.toolUI ?? <ToolFallback {...part} />;\n * case \"indicator\": return <LoadingDots />;\n * default: return null;\n * }\n * }}\n * </MessagePrimitive.GroupedParts>\n * ```\n */\nexport const MessagePrimitiveGroupedParts = <TKey extends `group-${string}`>({\n groupBy,\n indicator = \"no-text\",\n children,\n}: MessagePrimitiveGroupedParts.Props<TKey>): ReactNode => {\n const parts = useAuiState(useShallowSelector((s) => s.message.parts));\n // Handed to `groupBy` as its `context` argument (see GroupByContext).\n const toolUIs = useAuiState((s) => s.tools.toolUIs);\n // Subscribe to a boolean, not the status object: the tree only needs to\n // re-render when running-ness flips, and `\"never\"` opts out entirely.\n const isRunning = useAuiState((s) =>\n indicator === \"never\" ? false : s.message.status?.type === \"running\",\n );\n\n // Helpers like `groupPartByType` tag the function with `GROUPBY_MEMO_KEY`\n // (a stable string fingerprint of the helper config). When present,\n // memo on `[parts, memoKey]` so the tree survives unrelated renders.\n // For inline `groupBy`, fall back to recomputing each render — O(n)\n // and cheap.\n const memoKey = (groupBy as { [GROUPBY_MEMO_KEY]?: string })[\n GROUPBY_MEMO_KEY\n ];\n const memoDep = memoKey ?? groupBy;\n const tree = useMemo(() => {\n const context: GroupByContext = { toolUIs };\n return buildGroupTree(\n parts.map((part) => groupBy(part, context) ?? []),\n parts.map((part) =>\n part.type === \"tool-call\" ? part.toolCallId : undefined,\n ),\n );\n // oxlint-disable-next-line react/exhaustive-deps -- groupBy is captured via memoDep (either its identity or the helper's memoKey fingerprint); listing it directly would defeat the helper-tagged memo path\n }, [parts, memoDep, toolUIs]);\n\n return (\n <>\n {tree.map((node) => renderNode(node, parts, children))}\n {shouldShowIndicator(indicator, parts, isRunning) &&\n children({\n part: { type: \"indicator\" },\n children: <PartChildrenSentinel />,\n })}\n </>\n );\n};\n\nMessagePrimitiveGroupedParts.displayName = \"MessagePrimitive.GroupedParts\";\n"],"mappings":";;;;;;;;;AAyIA,MAAMgC,uBACJC,MACAC,OACAC,cACY;CAGZ,IAAI,CAACA,WAAW,OAAO;CAEvB,QAAQF,MAAR;EACE,KAAK,SACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,SACH,OAAOC,MAAME,WAAW;EAC1B,KAAK,WAAW;GACd,MAAMC,OAAOH,MAAMA,MAAME,SAAS;GAClC,OACEC,SAASC,KAAAA,KACRD,KAAKnB,SAAS,UAAUmB,KAAKnB,SAAS;EAE3C;CACF;AACF;;;;;;;AAQA,MAAMqB,6BAAiC;CACrC,MAAM,IAAIC,MACR,8LAGF;AACF;AAEA,MAAMC,cACJC,MACAR,OACAS,WACc;CACd,IAAID,KAAKxB,SAAS,QAIhB,OACE,oBAAC,qBAAD;EAEE,OAAOwB,KAAKG;EAEV,WAAA,EAAEpB,WAAWkB,OAAO;GAAElB;GAAMC,UAAU,oBAAC,sBAAD,CAAqB,CAAA;EAAI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AS,KAC9CT,SAAS;EACPD,MAAM,EAAEP,MAAM,YAAY;EAC1BQ,UAAU,oBAAC,sBAAD,CAAqB,CAAA;CACjC,CAAC,CACL,EAAA,CAAA;AAEJ;AAEAV,6BAA6B2C,cAAc"}
|
|
1
|
+
{"version":3,"file":"MessageGroupedParts.js","names":["Fragment","FC","ReactNode","useMemo","useAuiState","useShallowSelector","PartState","MessagePartStatus","ToolCallMessagePartStatus","getGroupSummary","buildGroupTree","GROUPBY_MEMO_KEY","GroupByContext","GroupNode","MessagePartChildren","EnrichedPartState","MessagePrimitiveGroupedParts","GroupCounts","running","complete","incomplete","requiresAction","GroupPart","type","TKey","status","counts","indices","IndicatorPart","IndicatorMode","RenderInfo","part","children","Props","groupBy","context","indicator","info","shouldShowIndicator","mode","parts","isRunning","length","last","undefined","PartChildrenSentinel","Error","renderNode","node","render","idKey","index","groupPart","key","nodeKey","map","child","s","message","toolUIs","tools","memoKey","memoDep","tree","toolCallId","displayName"],"sources":["../../../../src/react/primitives/message/MessageGroupedParts.tsx"],"sourcesContent":["\"use client\";\n\nimport { Fragment, type FC, type ReactNode, useMemo } from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\nimport { useShallowSelector } from \"@assistant-ui/store/internal\";\nimport type { PartState } from \"../../../store/scopes/part\";\nimport type {\n MessagePartStatus,\n ToolCallMessagePartStatus,\n} from \"../../../types/message\";\nimport { getGroupSummary } from \"../../../utils/getGroupStatus\";\nimport {\n buildGroupTree,\n GROUPBY_MEMO_KEY,\n type GroupByContext,\n type GroupNode,\n} from \"../../utils/groupParts\";\nimport { MessagePartChildren, type EnrichedPartState } from \"./MessageParts\";\n\nexport namespace MessagePrimitiveGroupedParts {\n /** Per status tallies over the group's `indices`; they sum to `indices.length`. */\n export type GroupCounts = {\n readonly running: number;\n readonly complete: number;\n readonly incomplete: number;\n readonly requiresAction: number;\n };\n\n /**\n * A coalesced group of adjacent parts. Surfaced through the same\n * `{ part }` channel as a leaf {@link EnrichedPartState} so consumers\n * dispatch on a single `switch (part.type)`. `type` is the group key\n * (always `\"group-…\"`); `status` is running when any contained part runs,\n * otherwise it mirrors the last contained part.\n */\n export type GroupPart<TKey extends `group-${string}` = `group-${string}`> = {\n readonly type: TKey;\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n /** Per status tallies over `indices`. */\n readonly counts: GroupCounts;\n readonly indices: readonly number[];\n };\n\n /**\n * Synthetic trailing slot for a streaming/loading affordance (a\n * \"thinking…\" dot, etc.). Surfaced through the same `{ part }` channel\n * as groups and leaf parts so a single `switch (part.type)` renders it\n * via `case \"indicator\"`.\n *\n * It is only ever emitted while the message is running, so its presence\n * alone means \"render your loading UI here\" — there's no `status` to\n * branch on.\n */\n export type IndicatorPart = {\n readonly type: \"indicator\";\n };\n\n /**\n * When to emit the synthetic {@link IndicatorPart}. It is **only** emitted\n * while the message is running (streaming); the mode further restricts\n * which running states qualify:\n * - `\"never\"` — never.\n * - `\"empty\"` — only when the message has no parts yet.\n * - `\"no-text\"` (default) — when the message has no parts yet or the last\n * part isn't `text`/`reasoning` (e.g. it ended on a tool call, so the\n * assistant likely isn't done).\n * - `\"always\"` — whenever the message is running, regardless of parts.\n */\n export type IndicatorMode = \"never\" | \"empty\" | \"no-text\" | \"always\";\n\n export type RenderInfo<TKey extends `group-${string}` = `group-${string}`> = {\n /**\n * Either a coalesced group ({@link GroupPart}, identified by a\n * `group-…` `type`), a single enriched leaf part, or the synthetic\n * {@link IndicatorPart} (`type: \"indicator\"`). Use one switch over\n * `part.type` to handle all three.\n */\n readonly part: GroupPart<TKey> | EnrichedPartState | IndicatorPart;\n /**\n * For group nodes: the recursively-rendered subtree (subgroups +\n * leaf parts). For leaf parts: a sentinel that throws when rendered\n * — accidental fall-through (`default: return children;`) errors\n * loudly instead of silently rendering nothing.\n */\n readonly children: ReactNode;\n };\n\n export type Props<TKey extends `group-${string}` = `group-${string}`> = {\n /**\n * Maps each part to a group-key path. Adjacent parts that share a\n * prefix coalesce into the same group. Return `[]` (or `null`) to\n * leave a part ungrouped.\n *\n * Group keys must start with `\"group-\"` so the renderer's\n * `switch (part.type)` can tell groups apart from real part types.\n *\n * **Prefer {@link groupPartByType}** for the common case of mapping by\n * `part.type` or tool name — it ships a stable memo fingerprint so the tree\n * survives unrelated re-renders. Use an inline function only when\n * the helper isn't expressive enough (e.g. branching on\n * `part.parentId` or part metadata).\n *\n * The second argument is a {@link GroupByContext} carrying the tool-UI\n * registry, for grouping that depends on it (e.g. standalone tool calls).\n *\n * @example\n * ```tsx\n * import { groupPartByType } from \"@assistant-ui/react\";\n *\n * <MessagePrimitive.GroupedParts\n * groupBy={groupPartByType({\n * reasoning: [\"group-thought\", \"group-reasoning\"],\n * \"tool-call\": [\"group-thought\", \"group-tool\"],\n * })}\n * >\n * ```\n */\n readonly groupBy: (\n part: PartState,\n context: GroupByContext,\n ) => readonly TKey[] | null;\n\n /**\n * Controls emission of the synthetic {@link IndicatorPart} — a\n * trailing `{ part: { type: \"indicator\", status } }` render call you\n * handle with `case \"indicator\"` to show loading/status UI.\n *\n * @default \"no-text\"\n * @see IndicatorMode\n */\n readonly indicator?: IndicatorMode;\n\n /**\n * Render function called once per group node, once per leaf part, and\n * (when the `indicator` condition is met) once for the trailing\n * {@link IndicatorPart}. Switch on `part.type`: `\"group-…\"` cases wrap\n * `children`; real part types (`\"text\"`, `\"tool-call\"`, …) render the\n * part directly; `\"indicator\"` renders status/loading UI.\n *\n * Leaf parts receive the same {@link EnrichedPartState} that\n * `<MessagePrimitive.Parts>` would produce (`toolUI`, `addResult`,\n * `resume`, `respondToApproval`, `dataRendererUI`).\n */\n readonly children: (info: RenderInfo<TKey>) => ReactNode;\n };\n}\n\nconst shouldShowIndicator = (\n mode: MessagePrimitiveGroupedParts.IndicatorMode,\n parts: readonly PartState[],\n isRunning: boolean,\n): boolean => {\n // The indicator is a streaming affordance — never show it on a settled\n // message, whatever the mode.\n if (!isRunning) return false;\n\n switch (mode) {\n case \"never\":\n return false;\n case \"always\":\n return true;\n case \"empty\":\n return parts.length === 0;\n case \"no-text\": {\n const last = parts[parts.length - 1];\n return (\n last === undefined ||\n (last.type !== \"text\" && last.type !== \"reasoning\")\n );\n }\n }\n};\n\n/**\n * `children` placeholder passed for leaf-part renders. Leaf parts have no\n * inner subtree; rendering this sentinel signals the consumer wrote\n * `default: return children;` and accidentally fell through for a part —\n * surface the bug loudly instead of silently rendering nothing.\n */\nconst PartChildrenSentinel: FC = () => {\n throw new Error(\n \"MessagePrimitive.GroupedParts: rendered `children` under a leaf \" +\n \"part. `children` is only meaningful for `group-…` cases — add a \" +\n \"matching case for the part type or return `null` to skip it.\",\n );\n};\n\nconst renderNode = <TKey extends `group-${string}`>(\n node: GroupNode,\n parts: readonly PartState[],\n render: (info: MessagePrimitiveGroupedParts.RenderInfo<TKey>) => ReactNode,\n): ReactNode => {\n if (node.type === \"part\") {\n // Key by part identity when available, else absolute part index — never\n // the structural nodeKey, which leaves zombie fiber subscriptions when\n // parts reshape (#4051).\n return (\n <MessagePartChildren\n key={node.idKey ? `part-${node.idKey}` : `part-${node.index}`}\n index={node.index}\n >\n {({ part }) => render({ part, children: <PartChildrenSentinel /> })}\n </MessagePartChildren>\n );\n }\n\n const { status, counts } = getGroupSummary(parts, node.indices);\n const groupPart: MessagePrimitiveGroupedParts.GroupPart<TKey> = {\n type: node.key as TKey,\n status,\n counts,\n indices: node.indices,\n };\n\n return (\n <Fragment key={node.idKey ?? node.nodeKey}>\n {render({\n part: groupPart,\n children: (\n <>{node.children.map((child) => renderNode(child, parts, render))}</>\n ),\n })}\n </Fragment>\n );\n};\n\n/**\n * Groups adjacent message parts into a tree of coalesced runs and\n * renders each node — group or part — through a single `children`\n * function.\n *\n * The render function receives `{ part, children }` where `part.type`\n * is either a `\"group-…\"` literal (for a group, `children` is the\n * recursively-rendered subtree) or a real part type (`\"text\"`,\n * `\"tool-call\"`, …) for a leaf (`children` is a sentinel that throws\n * if rendered — use `part.type` to distinguish).\n *\n * @example\n * ```tsx\n * <MessagePrimitive.GroupedParts\n * groupBy={groupPartByType({\n * reasoning: [\"group-thought\", \"group-reasoning\"],\n * \"tool-call\": [\"group-thought\", \"group-tool\"],\n * })}\n * >\n * {({ part, children }) => {\n * switch (part.type) {\n * case \"group-thought\": return <Thought>{children}</Thought>;\n * case \"group-reasoning\": return <Reasoning>{children}</Reasoning>;\n * case \"group-tool\": return <ToolStack>{children}</ToolStack>;\n * case \"text\": return <MarkdownText />;\n * case \"tool-call\": return part.toolUI ?? <ToolFallback {...part} />;\n * case \"indicator\": return <LoadingDots />;\n * default: return null;\n * }\n * }}\n * </MessagePrimitive.GroupedParts>\n * ```\n */\nexport const MessagePrimitiveGroupedParts = <TKey extends `group-${string}`>({\n groupBy,\n indicator = \"no-text\",\n children,\n}: MessagePrimitiveGroupedParts.Props<TKey>): ReactNode => {\n const parts = useAuiState(useShallowSelector((s) => s.message.parts));\n // Handed to `groupBy` as its `context` argument (see GroupByContext).\n const toolUIs = useAuiState((s) => s.tools.toolUIs);\n // Subscribe to a boolean, not the status object: the tree only needs to\n // re-render when running-ness flips, and `\"never\"` opts out entirely.\n const isRunning = useAuiState((s) =>\n indicator === \"never\" ? false : s.message.status?.type === \"running\",\n );\n\n // Helpers like `groupPartByType` tag the function with `GROUPBY_MEMO_KEY`\n // (a stable string fingerprint of the helper config). When present,\n // memo on `[parts, memoKey]` so the tree survives unrelated renders.\n // For inline `groupBy`, fall back to recomputing each render — O(n)\n // and cheap.\n const memoKey = (groupBy as { [GROUPBY_MEMO_KEY]?: string })[\n GROUPBY_MEMO_KEY\n ];\n const memoDep = memoKey ?? groupBy;\n const tree = useMemo(() => {\n const context: GroupByContext = { toolUIs };\n return buildGroupTree(\n parts.map((part) => groupBy(part, context) ?? []),\n parts.map((part) =>\n part.type === \"tool-call\" ? part.toolCallId : undefined,\n ),\n );\n // oxlint-disable-next-line react/exhaustive-deps -- groupBy is captured via memoDep (either its identity or the helper's memoKey fingerprint); listing it directly would defeat the helper-tagged memo path\n }, [parts, memoDep, toolUIs]);\n\n return (\n <>\n {tree.map((node) => renderNode(node, parts, children))}\n {shouldShowIndicator(indicator, parts, isRunning) &&\n children({\n part: { type: \"indicator\" },\n children: <PartChildrenSentinel />,\n })}\n </>\n );\n};\n\nMessagePrimitiveGroupedParts.displayName = \"MessagePrimitive.GroupedParts\";\n"],"mappings":";;;;;;;;;AAmJA,MAAMsC,uBACJC,MACAC,OACAC,cACY;CAGZ,IAAI,CAACA,WAAW,OAAO;CAEvB,QAAQF,MAAR;EACE,KAAK,SACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,SACH,OAAOC,MAAME,WAAW;EAC1B,KAAK,WAAW;GACd,MAAMC,OAAOH,MAAMA,MAAME,SAAS;GAClC,OACEC,SAASC,KAAAA,KACRD,KAAKpB,SAAS,UAAUoB,KAAKpB,SAAS;EAE3C;CACF;AACF;;;;;;;AAQA,MAAMsB,6BAAiC;CACrC,MAAM,IAAIC,MACR,8LAGF;AACF;AAEA,MAAMC,cACJC,MACAR,OACAS,WACc;CACd,IAAID,KAAKzB,SAAS,QAIhB,OACE,oBAAC,qBAAD;EAEE,OAAOyB,KAAKG;EAEV,WAAA,EAAEpB,WAAWkB,OAAO;GAAElB;GAAMC,UAAU,oBAAC,sBAAD,CAAqB,CAAA;EAAI,CAAC;CAC/C,GAJdgB,KAAKE,QAAQ,QAAQF,KAAKE,UAAU,QAAQF,KAAKG,OAInC;CAIzB,MAAM,EAAE1B,QAAQC,WAAWjB,gBAAgB+B,OAAOQ,KAAKrB,OAAO;CAC9D,MAAMyB,YAA0D;EAC9D7B,MAAMyB,KAAKK;EACX5B;EACAC;EACAC,SAASqB,KAAKrB;CAChB;CAEA,OACE,oBAAC,UAAD,EAAA,UACGsB,OAAO;EACNlB,MAAMqB;EACNpB,UACE,oBAAA,YAAA,EAAA,UAAGgB,KAAKhB,SAASuB,KAAKC,UAAUT,WAAWS,OAAOhB,OAAOS,MAAM,CAAC,EAAE,CAAA;CAEtE,CAAC,EACO,GAPKD,KAAKE,SAASF,KAAKM,OAOxB;AAEd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAatC,gCAAgE,EAC3EkB,SACAE,YAAY,WACZJ,eACyD;CACzD,MAAMQ,QAAQpC,YAAYC,oBAAoBoD,MAAMA,EAAEC,QAAQlB,KAAK,CAAC;CAEpE,MAAMmB,UAAUvD,aAAaqD,QAAMA,IAAEG,MAAMD,OAAO;CAGlD,MAAMlB,YAAYrC,aAAaqD,QAC7BrB,cAAc,UAAU,QAAQqB,IAAEC,QAAQjC,QAAQF,SAAS,SAC7D;CAUA,MAAMuC,UAHW5B,QACfvB,qBAEyBuB;CAC3B,MAAM6B,OAAO5D,cAAc;EACzB,MAAMgC,UAA0B,EAAEwB,QAAQ;EAC1C,OAAOjD,eACL8B,MAAMe,KAAKxB,SAASG,QAAQH,MAAMI,OAAO,KAAK,CAAA,CAAE,GAChDK,MAAMe,KAAKxB,WACTA,OAAKR,SAAS,cAAcQ,OAAKiC,aAAapB,KAAAA,CAChD,CACF;CAEF,GAAG;EAACJ;EAAOsB;EAASH;CAAO,CAAC;CAE5B,OACE,qBAAA,YAAA,EAAA,UAAA,CACGI,KAAKR,KAAKP,SAASD,WAAWC,MAAMR,OAAOR,QAAQ,CAAC,GACpDM,oBAAoBF,WAAWI,OAAOC,SAAS,KAC9CT,SAAS;EACPD,MAAM,EAAER,MAAM,YAAY;EAC1BS,UAAU,oBAAC,sBAAD,CAAqB,CAAA;CACjC,CAAC,CACL,EAAA,CAAA;AAEJ;AAEAhB,6BAA6BiD,cAAc"}
|
|
@@ -20,6 +20,7 @@ declare namespace PartPrimitiveMessages {
|
|
|
20
20
|
* This primitive reads `messages` from the current tool call part in the PartScope
|
|
21
21
|
* and renders them using a readonly thread context. All existing message and part
|
|
22
22
|
* primitives work inside, and parent tool UI registrations are inherited.
|
|
23
|
+
* The nested thread reports `isRunning` while its trailing assistant message is running.
|
|
23
24
|
*
|
|
24
25
|
* @example
|
|
25
26
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PartMessages.d.ts","names":[],"sources":["../../../../src/react/primitives/part/PartMessages.tsx"],"mappings":";;;;kBASiB;OACH;IAEN,YAAY,YAAY,wBAAwB;IAChD;;;IAIA,WAAW;MAAS,SAAS;UAAoB;IACjD
|
|
1
|
+
{"version":3,"file":"PartMessages.d.ts","names":[],"sources":["../../../../src/react/primitives/part/PartMessages.tsx"],"mappings":";;;;kBASiB;OACH;IAEN,YAAY,YAAY,wBAAwB;IAChD;;;IAIA,WAAW;MAAS,SAAS;UAAoB;IACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAuCK,2BAA2B,GAAG,sBAAsB;cAyBpD,uCAAqB,qBAAA,sBAAA"}
|
|
@@ -14,6 +14,7 @@ const usePartMessages = () => {
|
|
|
14
14
|
* This primitive reads `messages` from the current tool call part in the PartScope
|
|
15
15
|
* and renders them using a readonly thread context. All existing message and part
|
|
16
16
|
* primitives work inside, and parent tool UI registrations are inherited.
|
|
17
|
+
* The nested thread reports `isRunning` while its trailing assistant message is running.
|
|
17
18
|
*
|
|
18
19
|
* @example
|
|
19
20
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PartMessages.js","names":["FC","ReactNode","memo","useAuiState","ThreadMessage","ReadonlyThreadProvider","ThreadPrimitiveMessages","ThreadPrimitiveMessagesImpl","PartPrimitiveMessages","Props","components","NonNullable","children","value","message","usePartMessages","_temp","PartPrimitiveMessagesImpl","t0","$","_c","messages","length","t1","t2","displayName","s","part","type","undefined"],"sources":["../../../../src/react/primitives/part/PartMessages.tsx"],"sourcesContent":["import { type FC, type ReactNode, memo } from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\nimport type { ThreadMessage } from \"../../../types/message\";\nimport { ReadonlyThreadProvider } from \"../../providers/ReadonlyThreadProvider\";\nimport {\n type ThreadPrimitiveMessages,\n ThreadPrimitiveMessagesImpl,\n} from \"../thread/ThreadMessages\";\n\nexport namespace PartPrimitiveMessages {\n export type Props =\n | {\n components: NonNullable<ThreadPrimitiveMessages.Props[\"components\"]>;\n children?: never;\n }\n | {\n /** Render function called for each message. Receives the message. */\n children: (value: { message: ThreadMessage }) => ReactNode;\n components?: never;\n };\n}\n\nconst usePartMessages = (): readonly ThreadMessage[] | undefined => {\n return useAuiState((s) => {\n const part = s.part;\n if (part.type !== \"tool-call\") return undefined;\n return \"messages\" in part\n ? (part.messages as readonly ThreadMessage[] | undefined)\n : undefined;\n });\n};\n\n/**\n * Renders the nested messages of a tool call part (e.g. sub-agent conversation).\n *\n * This primitive reads `messages` from the current tool call part in the PartScope\n * and renders them using a readonly thread context. All existing message and part\n * primitives work inside, and parent tool UI registrations are inherited.\n *\n * @example\n * ```tsx\n * const toolkit = defineToolkit({\n * invoke_sub_agent: {\n * type: \"backend\",\n * render: () => (\n * <PartPrimitive.Messages>\n * {({ message }) => {\n * if (message.role === \"user\") return <MyUserMessage />;\n * return <MyAssistantMessage />;\n * }}\n * </PartPrimitive.Messages>\n * ),\n * },\n * });\n * ```\n */\nexport const PartPrimitiveMessagesImpl: FC<PartPrimitiveMessages.Props> = ({\n components,\n children,\n}) => {\n const messages = usePartMessages();\n\n if (!messages?.length) return null;\n\n if (components) {\n return (\n <ReadonlyThreadProvider messages={messages}>\n <ThreadPrimitiveMessagesImpl components={components} />\n </ReadonlyThreadProvider>\n );\n }\n\n return (\n <ReadonlyThreadProvider messages={messages}>\n <ThreadPrimitiveMessagesImpl>{children}</ThreadPrimitiveMessagesImpl>\n </ReadonlyThreadProvider>\n );\n};\n\nPartPrimitiveMessagesImpl.displayName = \"PartPrimitive.Messages\";\n\nexport const PartPrimitiveMessages = memo(PartPrimitiveMessagesImpl);\n"],"mappings":";;;;;;;AAsBA,MAAMe,wBAAkB;CAAA,OACfZ,YAAYa,KAMlB;AAAC
|
|
1
|
+
{"version":3,"file":"PartMessages.js","names":["FC","ReactNode","memo","useAuiState","ThreadMessage","ReadonlyThreadProvider","ThreadPrimitiveMessages","ThreadPrimitiveMessagesImpl","PartPrimitiveMessages","Props","components","NonNullable","children","value","message","usePartMessages","_temp","PartPrimitiveMessagesImpl","t0","$","_c","messages","length","t1","t2","displayName","s","part","type","undefined"],"sources":["../../../../src/react/primitives/part/PartMessages.tsx"],"sourcesContent":["import { type FC, type ReactNode, memo } from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\nimport type { ThreadMessage } from \"../../../types/message\";\nimport { ReadonlyThreadProvider } from \"../../providers/ReadonlyThreadProvider\";\nimport {\n type ThreadPrimitiveMessages,\n ThreadPrimitiveMessagesImpl,\n} from \"../thread/ThreadMessages\";\n\nexport namespace PartPrimitiveMessages {\n export type Props =\n | {\n components: NonNullable<ThreadPrimitiveMessages.Props[\"components\"]>;\n children?: never;\n }\n | {\n /** Render function called for each message. Receives the message. */\n children: (value: { message: ThreadMessage }) => ReactNode;\n components?: never;\n };\n}\n\nconst usePartMessages = (): readonly ThreadMessage[] | undefined => {\n return useAuiState((s) => {\n const part = s.part;\n if (part.type !== \"tool-call\") return undefined;\n return \"messages\" in part\n ? (part.messages as readonly ThreadMessage[] | undefined)\n : undefined;\n });\n};\n\n/**\n * Renders the nested messages of a tool call part (e.g. sub-agent conversation).\n *\n * This primitive reads `messages` from the current tool call part in the PartScope\n * and renders them using a readonly thread context. All existing message and part\n * primitives work inside, and parent tool UI registrations are inherited.\n * The nested thread reports `isRunning` while its trailing assistant message is running.\n *\n * @example\n * ```tsx\n * const toolkit = defineToolkit({\n * invoke_sub_agent: {\n * type: \"backend\",\n * render: () => (\n * <PartPrimitive.Messages>\n * {({ message }) => {\n * if (message.role === \"user\") return <MyUserMessage />;\n * return <MyAssistantMessage />;\n * }}\n * </PartPrimitive.Messages>\n * ),\n * },\n * });\n * ```\n */\nexport const PartPrimitiveMessagesImpl: FC<PartPrimitiveMessages.Props> = ({\n components,\n children,\n}) => {\n const messages = usePartMessages();\n\n if (!messages?.length) return null;\n\n if (components) {\n return (\n <ReadonlyThreadProvider messages={messages}>\n <ThreadPrimitiveMessagesImpl components={components} />\n </ReadonlyThreadProvider>\n );\n }\n\n return (\n <ReadonlyThreadProvider messages={messages}>\n <ThreadPrimitiveMessagesImpl>{children}</ThreadPrimitiveMessagesImpl>\n </ReadonlyThreadProvider>\n );\n};\n\nPartPrimitiveMessagesImpl.displayName = \"PartPrimitive.Messages\";\n\nexport const PartPrimitiveMessages = memo(PartPrimitiveMessagesImpl);\n"],"mappings":";;;;;;;AAsBA,MAAMe,wBAAkB;CAAA,OACfZ,YAAYa,KAMlB;AAAC;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BJ,MAAaC,6BAA6DC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAC,MAAA,EAAAV,YAAAE,aAAAM;CAIzE,MAAAG,WAAiBN,gBAAgB;CAEjC,IAAI,CAACM,UAAQC,QAAQ,OAAS;CAE9B,IAAIZ,YAAU;EAAA,IAAAa;EAAA,IAAAJ,EAAA,OAAAT,YAAA;GAGRa,KAAA,oBAAC,6BAAD,EAAyCb,WAAU,CAAA;GAAIS,EAAA,KAAAT;GAAAS,EAAA,KAAAI;EAAA,OAAAA,KAAAJ,EAAA;EAAA,IAAAK;EAAA,IAAAL,EAAA,OAAAE,YAAAF,EAAA,OAAAI,IAAA;GADzDC,KAAA,oBAAC,wBAAD;IAAkCH;IAChCE,UAAAA;GADqB,CAAA;GAEEJ,EAAA,KAAAE;GAAAF,EAAA,KAAAI;GAAAJ,EAAA,KAAAK;EAAA,OAAAA,KAAAL,EAAA;EAAA,OAFzBK;CAEyB;CAE5B,IAAAD;CAAA,IAAAJ,EAAA,OAAAP,UAAA;EAIGW,KAAA,oBAAC,6BAAD,EAA8BX,SAAF,CAAA;EAAyCO,EAAA,KAAAP;EAAAO,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,IAAAK;CAAA,IAAAL,EAAA,OAAAE,YAAAF,EAAA,OAAAI,IAAA;EADvEC,KAAA,oBAAC,wBAAD;GAAkCH;GAChCE,UAAAA;EADqB,CAAA;EAEEJ,EAAA,KAAAE;EAAAF,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAAA,OAFzBK;AAEyB;AAI7BP,0BAA0BQ,cAAc;AAExC,MAAajB,wBAAwBN,KAAKe,yBAAyB;AA5D3C,SAAAD,MAAAU,GAAA;CAEpB,MAAAC,OAAaD,EAACC;CACd,IAAIA,KAAIC,SAAU,aAAW;CAAmB,OACzC,cAAcD,OAChBA,KAAIN,WADFQ,KAAAA;AAEM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThreadMessages.d.ts","names":[],"sources":["../../../../src/react/primitives/thread/ThreadMessages.tsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"ThreadMessages.d.ts","names":[],"sources":["../../../../src/react/primitives/thread/ThreadMessages.tsx"],"mappings":";;;;KAaK;;EAGC,SAAS;;EAET,eAAe;;EAEf,mBAAmB;;EAEnB,wBAAwB;;EAExB,qBAAqB;;EAErB,cAAc;;EAEd,mBAAmB;;EAEnB,gBAAgB;;;EAIhB,UAAU;;EAEV,eAAe;;EAEf,mBAAmB;;EAEnB,wBAAwB;;EAExB,qBAAqB;;EAErB,aAAa;;EAEb,kBAAkB;;EAElB,gBAAgB;;kBAGL;OACH;;IAGN,YAAY;IACZ;;;IAIA,WAAW;MAAS,SAAS;UAAmB;IAChD;;;kBAsGS;OACH;IACV;IACA,YAAY;;;;;;cAOH,+BAA+B,GAAG,8BAA8B;kBAgB5D;OACH;IACV;IACA,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;cA2BH,qCAAqC,GAAG,oCAAoC;;;;;;;;;;;;;;cA8D5E,6BAA6B,GAAG,wBAAwB;cAkBxD,yCAAuB,qBAAA,wBAAA"}
|
|
@@ -3,6 +3,7 @@ import { MessageByIdProvider } from "../../providers/MessageByIdProvider.js";
|
|
|
3
3
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
4
4
|
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
5
5
|
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
6
|
+
import { useShallowSelector } from "@assistant-ui/store/internal";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
8
|
//#region src/react/primitives/thread/ThreadMessages.tsx
|
|
8
9
|
const isComponentsSame = (prev, next) => {
|
|
@@ -129,10 +130,10 @@ const ThreadPrimitiveUnstable_MessageById = memo((t0) => {
|
|
|
129
130
|
}, (prev, next) => prev.messageId === next.messageId && isComponentsSame(prev.components, next.components));
|
|
130
131
|
ThreadPrimitiveUnstable_MessageById.displayName = "ThreadPrimitive.Unstable_MessageById";
|
|
131
132
|
const ThreadPrimitiveMessagesInner = ({ children }) => {
|
|
132
|
-
const
|
|
133
|
+
const messageIds = useAuiState(useShallowSelector((s) => s.thread.messages.map((message) => message.id)));
|
|
133
134
|
return useMemo(() => {
|
|
134
|
-
if (
|
|
135
|
-
return
|
|
135
|
+
if (messageIds.length === 0) return null;
|
|
136
|
+
return messageIds.map((messageId, index) => /* @__PURE__ */ jsx(MessageByIndexProvider, {
|
|
136
137
|
index,
|
|
137
138
|
children: /* @__PURE__ */ jsx(RenderChildrenWithAccessor, {
|
|
138
139
|
getItemState: (aui) => aui.thread.message({ index }).getState(),
|
|
@@ -140,8 +141,8 @@ const ThreadPrimitiveMessagesInner = ({ children }) => {
|
|
|
140
141
|
return getItem();
|
|
141
142
|
} })
|
|
142
143
|
})
|
|
143
|
-
},
|
|
144
|
-
}, [
|
|
144
|
+
}, messageId));
|
|
145
|
+
}, [messageIds, children]);
|
|
145
146
|
};
|
|
146
147
|
/**
|
|
147
148
|
* Renders all messages in the current thread.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThreadMessages.js","names":["ComponentType","FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","MessageByIndexProvider","MessageByIdProvider","MessageState","MessagesComponentConfig","Message","EditComposer","UserEditComposer","AssistantEditComposer","SystemEditComposer","UserMessage","AssistantMessage","SystemMessage","ThreadPrimitiveMessages","Props","components","children","value","message","isComponentsSame","prev","next","DEFAULT_SYSTEM_MESSAGE","messageIdSetCache","WeakMap","ReadonlySet","hasMessageId","messages","messageId","ids","get","Set","map","m","id","set","has","getComponent","role","isEditing","_exhaustiveCheck","Error","ThreadMessageComponentProps","ThreadMessageComponent","t0","$","_c","_temp","_temp2","t1","Component","t2","ThreadPrimitiveMessageByIndex","index","displayName","ThreadPrimitiveUnstable_MessageById","s","thread","exists","t3","ThreadPrimitiveMessagesInner","messagesLength","length","Array","from","_","aui","getState","getItem","ThreadPrimitiveMessagesImpl","s_0","composer"],"sources":["../../../../src/react/primitives/thread/ThreadMessages.tsx"],"sourcesContent":["import {\n type ComponentType,\n type FC,\n type ReactNode,\n memo,\n useMemo,\n} from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { MessageByIndexProvider } from \"../../providers/MessageByIndexProvider\";\nimport { MessageByIdProvider } from \"../../providers/MessageByIdProvider\";\nimport type { MessageState } from \"../../../store\";\n\ntype MessagesComponentConfig =\n | {\n /** Component used to render all message types */\n Message: ComponentType;\n /** Component used when editing any message type */\n EditComposer?: ComponentType | undefined;\n /** Component used when editing user messages specifically */\n UserEditComposer?: ComponentType | undefined;\n /** Component used when editing assistant messages specifically */\n AssistantEditComposer?: ComponentType | undefined;\n /** Component used when editing system messages specifically */\n SystemEditComposer?: ComponentType | undefined;\n /** Component used to render user messages specifically */\n UserMessage?: ComponentType | undefined;\n /** Component used to render assistant messages specifically */\n AssistantMessage?: ComponentType | undefined;\n /** Component used to render system messages specifically */\n SystemMessage?: ComponentType | undefined;\n }\n | {\n /** Component used to render all message types (fallback) */\n Message?: ComponentType | undefined;\n /** Component used when editing any message type */\n EditComposer?: ComponentType | undefined;\n /** Component used when editing user messages specifically */\n UserEditComposer?: ComponentType | undefined;\n /** Component used when editing assistant messages specifically */\n AssistantEditComposer?: ComponentType | undefined;\n /** Component used when editing system messages specifically */\n SystemEditComposer?: ComponentType | undefined;\n /** Component used to render user messages */\n UserMessage: ComponentType;\n /** Component used to render assistant messages */\n AssistantMessage: ComponentType;\n /** Component used to render system messages */\n SystemMessage?: ComponentType | undefined;\n };\n\nexport namespace ThreadPrimitiveMessages {\n export type Props =\n | {\n /** @deprecated Use the children render function instead. */\n components: MessagesComponentConfig;\n children?: never;\n }\n | {\n /** Render function called for each message. Receives the message. */\n children: (value: { message: MessageState }) => ReactNode;\n components?: never;\n };\n}\n\nconst isComponentsSame = (\n prev: MessagesComponentConfig,\n next: MessagesComponentConfig,\n) => {\n return (\n prev.Message === next.Message &&\n prev.EditComposer === next.EditComposer &&\n prev.UserEditComposer === next.UserEditComposer &&\n prev.AssistantEditComposer === next.AssistantEditComposer &&\n prev.SystemEditComposer === next.SystemEditComposer &&\n prev.UserMessage === next.UserMessage &&\n prev.AssistantMessage === next.AssistantMessage &&\n prev.SystemMessage === next.SystemMessage\n );\n};\n\nconst DEFAULT_SYSTEM_MESSAGE = () => null;\n\nconst messageIdSetCache = new WeakMap<\n readonly MessageState[],\n ReadonlySet<string>\n>();\n\nconst hasMessageId = (messages: readonly MessageState[], messageId: string) => {\n let ids = messageIdSetCache.get(messages);\n if (!ids) {\n ids = new Set(messages.map((m) => m.id));\n messageIdSetCache.set(messages, ids);\n }\n return ids.has(messageId);\n};\n\nconst getComponent = (\n components: MessagesComponentConfig,\n role: MessageState[\"role\"],\n isEditing: boolean,\n) => {\n switch (role) {\n case \"user\":\n if (isEditing) {\n return (\n components.UserEditComposer ??\n components.EditComposer ??\n components.UserMessage ??\n (components.Message as ComponentType)\n );\n } else {\n return components.UserMessage ?? (components.Message as ComponentType);\n }\n case \"assistant\":\n if (isEditing) {\n return (\n components.AssistantEditComposer ??\n components.EditComposer ??\n components.AssistantMessage ??\n (components.Message as ComponentType)\n );\n } else {\n return (\n components.AssistantMessage ?? (components.Message as ComponentType)\n );\n }\n case \"system\":\n if (isEditing) {\n return (\n components.SystemEditComposer ??\n components.EditComposer ??\n components.SystemMessage ??\n (components.Message as ComponentType) ??\n DEFAULT_SYSTEM_MESSAGE\n );\n } else {\n return (\n components.SystemMessage ??\n (components.Message as ComponentType) ??\n DEFAULT_SYSTEM_MESSAGE\n );\n }\n default: {\n const _exhaustiveCheck: never = role;\n throw new Error(`Unknown message role: ${_exhaustiveCheck}`);\n }\n }\n};\n\ntype ThreadMessageComponentProps = {\n components: MessagesComponentConfig;\n};\n\nconst ThreadMessageComponent: FC<ThreadMessageComponentProps> = ({\n components,\n}) => {\n const role = useAuiState((s) => s.message.role);\n const isEditing = useAuiState((s) => s.message.composer.isEditing);\n const Component = getComponent(components, role, isEditing);\n\n return <Component />;\n};\nexport namespace ThreadPrimitiveMessageByIndex {\n export type Props = {\n index: number;\n components: MessagesComponentConfig;\n };\n}\n\n/**\n * Renders a single message at the specified index in the current thread.\n */\nexport const ThreadPrimitiveMessageByIndex: FC<ThreadPrimitiveMessageByIndex.Props> =\n memo(\n ({ index, components }) => {\n return (\n <MessageByIndexProvider index={index}>\n <ThreadMessageComponent components={components} />\n </MessageByIndexProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\n isComponentsSame(prev.components, next.components),\n );\n\nThreadPrimitiveMessageByIndex.displayName = \"ThreadPrimitive.MessageByIndex\";\n\nexport namespace ThreadPrimitiveUnstable_MessageById {\n export type Props = {\n messageId: string;\n components: MessagesComponentConfig;\n };\n}\n\n/**\n * Renders the message with the given id in the current thread.\n *\n * Unlike {@link ThreadPrimitiveMessageByIndex}, this keys off the message id,\n * so it stays attached to the same message across reordering and windowing -\n * the shape needed to drive a virtualized or custom message list together with\n * `unstable_useThreadMessageIds`. A missing or removed id renders `null` rather\n * than throwing.\n *\n * @deprecated Unstable / Experimental - may change in any release.\n *\n * @example\n * ```tsx\n * const messageIds = unstable_useThreadMessageIds();\n * return messageIds.map((messageId) => (\n * <ThreadPrimitive.Unstable_MessageById\n * key={messageId}\n * messageId={messageId}\n * components={MESSAGE_COMPONENTS}\n * />\n * ));\n * ```\n */\nexport const ThreadPrimitiveUnstable_MessageById: FC<ThreadPrimitiveUnstable_MessageById.Props> =\n memo(\n ({ messageId, components }) => {\n const exists = useAuiState((s) =>\n hasMessageId(s.thread.messages, messageId),\n );\n if (!exists) return null;\n\n return (\n <MessageByIdProvider id={messageId}>\n <ThreadMessageComponent components={components} />\n </MessageByIdProvider>\n );\n },\n (prev, next) =>\n prev.messageId === next.messageId &&\n isComponentsSame(prev.components, next.components),\n );\n\nThreadPrimitiveUnstable_MessageById.displayName =\n \"ThreadPrimitive.Unstable_MessageById\";\n\nconst ThreadPrimitiveMessagesInner: FC<{\n children: (value: { message: MessageState }) => ReactNode;\n}> = ({ children }) => {\n const messagesLength = useAuiState((s) => s.thread.messages.length);\n\n return useMemo(() => {\n if (messagesLength === 0) return null;\n return Array.from({ length: messagesLength }, (_, index) => (\n <MessageByIndexProvider key={index} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) => aui.thread.message({ index }).getState()}\n >\n {(getItem) =>\n children({\n get message() {\n return getItem();\n },\n })\n }\n </RenderChildrenWithAccessor>\n </MessageByIndexProvider>\n ));\n }, [messagesLength, children]);\n};\n\n/**\n * Renders all messages in the current thread.\n *\n * @example\n * ```tsx\n * <ThreadPrimitive.Messages>\n * {({ message }) => {\n * if (message.role === \"user\") return <MyUserMessage />;\n * return <MyAssistantMessage />;\n * }}\n * </ThreadPrimitive.Messages>\n * ```\n */\nexport const ThreadPrimitiveMessagesImpl: FC<ThreadPrimitiveMessages.Props> = ({\n components,\n children,\n}) => {\n if (components) {\n return (\n <ThreadPrimitiveMessagesInner>\n {() => <ThreadMessageComponent components={components} />}\n </ThreadPrimitiveMessagesInner>\n );\n }\n return (\n <ThreadPrimitiveMessagesInner>{children}</ThreadPrimitiveMessagesInner>\n );\n};\n\nThreadPrimitiveMessagesImpl.displayName = \"ThreadPrimitive.Messages\";\n\nexport const ThreadPrimitiveMessages = memo(\n ThreadPrimitiveMessagesImpl,\n (prev, next) => {\n if (prev.children || next.children) {\n return prev.children === next.children;\n }\n return isComponentsSame(prev.components!, next.components!);\n },\n);\n"],"mappings":";;;;;;;AAgEA,MAAMyB,oBACJC,MACAC,SACG;CACH,OACED,KAAKf,YAAYgB,KAAKhB,WACtBe,KAAKd,iBAAiBe,KAAKf,gBAC3Bc,KAAKb,qBAAqBc,KAAKd,oBAC/Ba,KAAKZ,0BAA0Ba,KAAKb,yBACpCY,KAAKX,uBAAuBY,KAAKZ,sBACjCW,KAAKV,gBAAgBW,KAAKX,eAC1BU,KAAKT,qBAAqBU,KAAKV,oBAC/BS,KAAKR,kBAAkBS,KAAKT;AAEhC;AAEA,MAAMU,+BAA+B;AAErC,MAAMC,oCAAoB,IAAIC,QAG5B;AAEF,MAAME,gBAAgBC,UAAmCC,cAAsB;CAC7E,IAAIC,MAAMN,kBAAkBO,IAAIH,QAAQ;CACxC,IAAI,CAACE,KAAK;EACRA,MAAM,IAAIE,IAAIJ,SAASK,KAAKC,MAAMA,EAAEC,EAAE,CAAC;EACvCX,kBAAkBY,IAAIR,UAAUE,GAAG;CACrC;CACA,OAAOA,IAAIO,IAAIR,SAAS;AAC1B;AAEA,MAAMS,gBACJtB,YACAuB,MACAC,cACG;CACH,QAAQD,MAAR;EACE,KAAK,QACH,IAAIC,WACF,OACExB,WAAWR,oBACXQ,WAAWT,gBACXS,WAAWL,eACVK,WAAWV;OAGd,OAAOU,WAAWL,eAAgBK,WAAWV;EAEjD,KAAK,aACH,IAAIkC,WACF,OACExB,WAAWP,yBACXO,WAAWT,gBACXS,WAAWJ,oBACVI,WAAWV;OAGd,OACEU,WAAWJ,oBAAqBI,WAAWV;EAGjD,KAAK,UACH,IAAIkC,WACF,OACExB,WAAWN,sBACXM,WAAWT,gBACXS,WAAWH,iBACVG,WAAWV,WACZiB;OAGF,OACEP,WAAWH,iBACVG,WAAWV,WACZiB;EAGN,SAEE,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ComponentType","FC","ReactNode","memo","useMemo","RenderChildrenWithAccessor","useAuiState","useShallowSelector","MessageByIndexProvider","MessageByIdProvider","MessageState","MessagesComponentConfig","Message","EditComposer","UserEditComposer","AssistantEditComposer","SystemEditComposer","UserMessage","AssistantMessage","SystemMessage","ThreadPrimitiveMessages","Props","components","children","value","message","isComponentsSame","prev","next","DEFAULT_SYSTEM_MESSAGE","messageIdSetCache","WeakMap","ReadonlySet","hasMessageId","messages","messageId","ids","get","Set","map","m","id","set","has","getComponent","role","isEditing","_exhaustiveCheck","Error","ThreadMessageComponentProps","ThreadMessageComponent","t0","$","_c","_temp","_temp2","t1","Component","t2","ThreadPrimitiveMessageByIndex","index","displayName","ThreadPrimitiveUnstable_MessageById","s","thread","exists","t3","ThreadPrimitiveMessagesInner","messageIds","length","aui","getState","getItem","ThreadPrimitiveMessagesImpl","s_0","composer"],"sources":["../../../../src/react/primitives/thread/ThreadMessages.tsx"],"sourcesContent":["import {\n type ComponentType,\n type FC,\n type ReactNode,\n memo,\n useMemo,\n} from \"react\";\nimport { RenderChildrenWithAccessor, useAuiState } from \"@assistant-ui/store\";\nimport { useShallowSelector } from \"@assistant-ui/store/internal\";\nimport { MessageByIndexProvider } from \"../../providers/MessageByIndexProvider\";\nimport { MessageByIdProvider } from \"../../providers/MessageByIdProvider\";\nimport type { MessageState } from \"../../../store\";\n\ntype MessagesComponentConfig =\n | {\n /** Component used to render all message types */\n Message: ComponentType;\n /** Component used when editing any message type */\n EditComposer?: ComponentType | undefined;\n /** Component used when editing user messages specifically */\n UserEditComposer?: ComponentType | undefined;\n /** Component used when editing assistant messages specifically */\n AssistantEditComposer?: ComponentType | undefined;\n /** Component used when editing system messages specifically */\n SystemEditComposer?: ComponentType | undefined;\n /** Component used to render user messages specifically */\n UserMessage?: ComponentType | undefined;\n /** Component used to render assistant messages specifically */\n AssistantMessage?: ComponentType | undefined;\n /** Component used to render system messages specifically */\n SystemMessage?: ComponentType | undefined;\n }\n | {\n /** Component used to render all message types (fallback) */\n Message?: ComponentType | undefined;\n /** Component used when editing any message type */\n EditComposer?: ComponentType | undefined;\n /** Component used when editing user messages specifically */\n UserEditComposer?: ComponentType | undefined;\n /** Component used when editing assistant messages specifically */\n AssistantEditComposer?: ComponentType | undefined;\n /** Component used when editing system messages specifically */\n SystemEditComposer?: ComponentType | undefined;\n /** Component used to render user messages */\n UserMessage: ComponentType;\n /** Component used to render assistant messages */\n AssistantMessage: ComponentType;\n /** Component used to render system messages */\n SystemMessage?: ComponentType | undefined;\n };\n\nexport namespace ThreadPrimitiveMessages {\n export type Props =\n | {\n /** @deprecated Use the children render function instead. */\n components: MessagesComponentConfig;\n children?: never;\n }\n | {\n /** Render function called for each message. Receives the message. */\n children: (value: { message: MessageState }) => ReactNode;\n components?: never;\n };\n}\n\nconst isComponentsSame = (\n prev: MessagesComponentConfig,\n next: MessagesComponentConfig,\n) => {\n return (\n prev.Message === next.Message &&\n prev.EditComposer === next.EditComposer &&\n prev.UserEditComposer === next.UserEditComposer &&\n prev.AssistantEditComposer === next.AssistantEditComposer &&\n prev.SystemEditComposer === next.SystemEditComposer &&\n prev.UserMessage === next.UserMessage &&\n prev.AssistantMessage === next.AssistantMessage &&\n prev.SystemMessage === next.SystemMessage\n );\n};\n\nconst DEFAULT_SYSTEM_MESSAGE = () => null;\n\nconst messageIdSetCache = new WeakMap<\n readonly MessageState[],\n ReadonlySet<string>\n>();\n\nconst hasMessageId = (messages: readonly MessageState[], messageId: string) => {\n let ids = messageIdSetCache.get(messages);\n if (!ids) {\n ids = new Set(messages.map((m) => m.id));\n messageIdSetCache.set(messages, ids);\n }\n return ids.has(messageId);\n};\n\nconst getComponent = (\n components: MessagesComponentConfig,\n role: MessageState[\"role\"],\n isEditing: boolean,\n) => {\n switch (role) {\n case \"user\":\n if (isEditing) {\n return (\n components.UserEditComposer ??\n components.EditComposer ??\n components.UserMessage ??\n (components.Message as ComponentType)\n );\n } else {\n return components.UserMessage ?? (components.Message as ComponentType);\n }\n case \"assistant\":\n if (isEditing) {\n return (\n components.AssistantEditComposer ??\n components.EditComposer ??\n components.AssistantMessage ??\n (components.Message as ComponentType)\n );\n } else {\n return (\n components.AssistantMessage ?? (components.Message as ComponentType)\n );\n }\n case \"system\":\n if (isEditing) {\n return (\n components.SystemEditComposer ??\n components.EditComposer ??\n components.SystemMessage ??\n (components.Message as ComponentType) ??\n DEFAULT_SYSTEM_MESSAGE\n );\n } else {\n return (\n components.SystemMessage ??\n (components.Message as ComponentType) ??\n DEFAULT_SYSTEM_MESSAGE\n );\n }\n default: {\n const _exhaustiveCheck: never = role;\n throw new Error(`Unknown message role: ${_exhaustiveCheck}`);\n }\n }\n};\n\ntype ThreadMessageComponentProps = {\n components: MessagesComponentConfig;\n};\n\nconst ThreadMessageComponent: FC<ThreadMessageComponentProps> = ({\n components,\n}) => {\n const role = useAuiState((s) => s.message.role);\n const isEditing = useAuiState((s) => s.message.composer.isEditing);\n const Component = getComponent(components, role, isEditing);\n\n return <Component />;\n};\nexport namespace ThreadPrimitiveMessageByIndex {\n export type Props = {\n index: number;\n components: MessagesComponentConfig;\n };\n}\n\n/**\n * Renders a single message at the specified index in the current thread.\n */\nexport const ThreadPrimitiveMessageByIndex: FC<ThreadPrimitiveMessageByIndex.Props> =\n memo(\n ({ index, components }) => {\n return (\n <MessageByIndexProvider index={index}>\n <ThreadMessageComponent components={components} />\n </MessageByIndexProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\n isComponentsSame(prev.components, next.components),\n );\n\nThreadPrimitiveMessageByIndex.displayName = \"ThreadPrimitive.MessageByIndex\";\n\nexport namespace ThreadPrimitiveUnstable_MessageById {\n export type Props = {\n messageId: string;\n components: MessagesComponentConfig;\n };\n}\n\n/**\n * Renders the message with the given id in the current thread.\n *\n * Unlike {@link ThreadPrimitiveMessageByIndex}, this keys off the message id,\n * so it stays attached to the same message across reordering and windowing -\n * the shape needed to drive a virtualized or custom message list together with\n * `unstable_useThreadMessageIds`. A missing or removed id renders `null` rather\n * than throwing.\n *\n * @deprecated Unstable / Experimental - may change in any release.\n *\n * @example\n * ```tsx\n * const messageIds = unstable_useThreadMessageIds();\n * return messageIds.map((messageId) => (\n * <ThreadPrimitive.Unstable_MessageById\n * key={messageId}\n * messageId={messageId}\n * components={MESSAGE_COMPONENTS}\n * />\n * ));\n * ```\n */\nexport const ThreadPrimitiveUnstable_MessageById: FC<ThreadPrimitiveUnstable_MessageById.Props> =\n memo(\n ({ messageId, components }) => {\n const exists = useAuiState((s) =>\n hasMessageId(s.thread.messages, messageId),\n );\n if (!exists) return null;\n\n return (\n <MessageByIdProvider id={messageId}>\n <ThreadMessageComponent components={components} />\n </MessageByIdProvider>\n );\n },\n (prev, next) =>\n prev.messageId === next.messageId &&\n isComponentsSame(prev.components, next.components),\n );\n\nThreadPrimitiveUnstable_MessageById.displayName =\n \"ThreadPrimitive.Unstable_MessageById\";\n\nconst ThreadPrimitiveMessagesInner: FC<{\n children: (value: { message: MessageState }) => ReactNode;\n}> = ({ children }) => {\n const messageIds = useAuiState(\n useShallowSelector((s) => s.thread.messages.map((message) => message.id)),\n );\n\n return useMemo(() => {\n if (messageIds.length === 0) return null;\n return messageIds.map((messageId, index) => (\n <MessageByIndexProvider key={messageId} index={index}>\n <RenderChildrenWithAccessor\n getItemState={(aui) => aui.thread.message({ index }).getState()}\n >\n {(getItem) =>\n children({\n get message() {\n return getItem();\n },\n })\n }\n </RenderChildrenWithAccessor>\n </MessageByIndexProvider>\n ));\n }, [messageIds, children]);\n};\n\n/**\n * Renders all messages in the current thread.\n *\n * @example\n * ```tsx\n * <ThreadPrimitive.Messages>\n * {({ message }) => {\n * if (message.role === \"user\") return <MyUserMessage />;\n * return <MyAssistantMessage />;\n * }}\n * </ThreadPrimitive.Messages>\n * ```\n */\nexport const ThreadPrimitiveMessagesImpl: FC<ThreadPrimitiveMessages.Props> = ({\n components,\n children,\n}) => {\n if (components) {\n return (\n <ThreadPrimitiveMessagesInner>\n {() => <ThreadMessageComponent components={components} />}\n </ThreadPrimitiveMessagesInner>\n );\n }\n return (\n <ThreadPrimitiveMessagesInner>{children}</ThreadPrimitiveMessagesInner>\n );\n};\n\nThreadPrimitiveMessagesImpl.displayName = \"ThreadPrimitive.Messages\";\n\nexport const ThreadPrimitiveMessages = memo(\n ThreadPrimitiveMessagesImpl,\n (prev, next) => {\n if (prev.children || next.children) {\n return prev.children === next.children;\n }\n return isComponentsSame(prev.components!, next.components!);\n },\n);\n"],"mappings":";;;;;;;;AAiEA,MAAM0B,oBACJC,MACAC,SACG;CACH,OACED,KAAKf,YAAYgB,KAAKhB,WACtBe,KAAKd,iBAAiBe,KAAKf,gBAC3Bc,KAAKb,qBAAqBc,KAAKd,oBAC/Ba,KAAKZ,0BAA0Ba,KAAKb,yBACpCY,KAAKX,uBAAuBY,KAAKZ,sBACjCW,KAAKV,gBAAgBW,KAAKX,eAC1BU,KAAKT,qBAAqBU,KAAKV,oBAC/BS,KAAKR,kBAAkBS,KAAKT;AAEhC;AAEA,MAAMU,+BAA+B;AAErC,MAAMC,oCAAoB,IAAIC,QAG5B;AAEF,MAAME,gBAAgBC,UAAmCC,cAAsB;CAC7E,IAAIC,MAAMN,kBAAkBO,IAAIH,QAAQ;CACxC,IAAI,CAACE,KAAK;EACRA,MAAM,IAAIE,IAAIJ,SAASK,KAAKC,MAAMA,EAAEC,EAAE,CAAC;EACvCX,kBAAkBY,IAAIR,UAAUE,GAAG;CACrC;CACA,OAAOA,IAAIO,IAAIR,SAAS;AAC1B;AAEA,MAAMS,gBACJtB,YACAuB,MACAC,cACG;CACH,QAAQD,MAAR;EACE,KAAK,QACH,IAAIC,WACF,OACExB,WAAWR,oBACXQ,WAAWT,gBACXS,WAAWL,eACVK,WAAWV;OAGd,OAAOU,WAAWL,eAAgBK,WAAWV;EAEjD,KAAK,aACH,IAAIkC,WACF,OACExB,WAAWP,yBACXO,WAAWT,gBACXS,WAAWJ,oBACVI,WAAWV;OAGd,OACEU,WAAWJ,oBAAqBI,WAAWV;EAGjD,KAAK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AAAS,GAAA;CAAA,OAG9BA,EAACtC,QAAQoB;AAAK;AAHgB,SAAAU,OAAAmB,KAAA;CAAA,OAIzBX,IAACtC,QAAQkD,SAAS7B;AAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListHookInstanceManager.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"RemoteThreadListHookInstanceManager.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;cAoFa,4CAA4C;UAC/C;mBACS;mBAIA;mBAIA;UAIT;UACA;UACA;EAGN,YAAA,aAAa,sBACb,QAAQ;UAOF;EAsBD,mBAAmB,mBAAgB,QAAA;;;eA7BhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2CH,gCAAgC,mBAAgB,QAAA;;;eAdb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCnC,qBAAqB,mBAAgB;;;eApBW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BhD,2BAA2B;UAI1B;EAED,mCAAmC,uBAAuB;UAKzD;EAID,iCACL,WAAW,OAAO,kCACjB;UAKK;UAQA;UAsBA;EAED,oCACL,uBACC;UAKK;UAiCA;EASD,kBAAkB;EAWlB,eAAe,gBAAgB;EAO/B,8BAA8B,UAAU;EAMxC,6BACL,kBACA,UAAU;EASL;UAMC;EAcD,mBAAmB,cAAc,kBAAA;EA0BjC,iCAAiC;IACtC,UAAU,cAAc;;EAenB,iBAAiB;IAAK,cAAc;;UAOnC;UAmCA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { notifyEventListeners } from "../../utils/notify-event-listeners.js";
|
|
2
|
-
import { BaseSubscribable, WritableSubscribable } from "../../subscribable/subscribable.js";
|
|
2
|
+
import { BaseSubscribable, WritableSubscribable, notifySubscribers } from "../../subscribable/subscribable.js";
|
|
3
3
|
import { getThreadRuntimeCoreIsRunning } from "../../runtime/api/thread-runtime.js";
|
|
4
4
|
import { ThreadListRuntimeImpl } from "../../runtime/api/thread-list-runtime.js";
|
|
5
5
|
import { invalidateThreadRuntime } from "../../runtime/utils/thread-runtime-lifecycle.js";
|
|
@@ -79,7 +79,8 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
79
79
|
const generation = this.nextGeneration++;
|
|
80
80
|
this.instances.set(threadId, {
|
|
81
81
|
generation,
|
|
82
|
-
isRunning: false
|
|
82
|
+
isRunning: false,
|
|
83
|
+
destroy: new AbortController()
|
|
83
84
|
});
|
|
84
85
|
this._syncHostThreads();
|
|
85
86
|
}
|
|
@@ -89,6 +90,10 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
89
90
|
const instance = this.instances.get(threadId);
|
|
90
91
|
if (!instance) return this.startThreadRuntime(threadId);
|
|
91
92
|
if (instance.runtime) invalidateThreadRuntime(instance.runtime);
|
|
93
|
+
instance.unsubscribeRunning?.();
|
|
94
|
+
instance.unsubscribeRunning = void 0;
|
|
95
|
+
instance.destroy.abort();
|
|
96
|
+
instance.destroy = new AbortController();
|
|
92
97
|
instance.generation = this.nextGeneration++;
|
|
93
98
|
this._syncHostThreads();
|
|
94
99
|
this._notifySubscribers();
|
|
@@ -124,7 +129,7 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
124
129
|
instance.publishedGeneration = generation;
|
|
125
130
|
if (previousRuntime !== runtime) this._trackRunning(threadId, instance);
|
|
126
131
|
this._notifySubscribers();
|
|
127
|
-
if (previousRuntime !== void 0 && previousRuntime !== runtime)
|
|
132
|
+
if (previousRuntime !== void 0 && previousRuntime !== runtime) notifySubscribers(this.replacedSubscribers);
|
|
128
133
|
}
|
|
129
134
|
replacedSubscribers = /* @__PURE__ */ new Set();
|
|
130
135
|
__internal_subscribeRuntimeReplaced(callback) {
|
|
@@ -155,12 +160,13 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
155
160
|
_setRunning(instance, isRunning) {
|
|
156
161
|
if (instance.isRunning === isRunning) return;
|
|
157
162
|
instance.isRunning = isRunning;
|
|
158
|
-
|
|
163
|
+
notifySubscribers(this.runningSubscribers);
|
|
159
164
|
}
|
|
160
165
|
stopThreadRuntime(threadId) {
|
|
161
166
|
const instance = this.instances.get(threadId);
|
|
162
167
|
if (instance?.runtime) invalidateThreadRuntime(instance.runtime);
|
|
163
168
|
instance?.unsubscribeRunning?.();
|
|
169
|
+
instance?.destroy.abort();
|
|
164
170
|
this.instances.delete(threadId);
|
|
165
171
|
this.pendingThreadAdapters.delete(threadId);
|
|
166
172
|
this._syncHostThreads();
|
|
@@ -200,9 +206,10 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
200
206
|
const host = this.hostStore.getState();
|
|
201
207
|
this.hostStore.setState({
|
|
202
208
|
...host,
|
|
203
|
-
threads: Array.from(this.instances.entries()).map(([id, { generation }]) => ({
|
|
209
|
+
threads: Array.from(this.instances.entries()).map(([id, { generation, destroy }]) => ({
|
|
204
210
|
id,
|
|
205
|
-
generation
|
|
211
|
+
generation,
|
|
212
|
+
destroySignal: destroy.signal
|
|
206
213
|
}))
|
|
207
214
|
});
|
|
208
215
|
}
|
|
@@ -210,7 +217,7 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
210
217
|
const { threads, hookEpoch } = useSubscribable(this.hostStore);
|
|
211
218
|
const adapters = useSubscribable(this.adapterStore);
|
|
212
219
|
const runtimeHook = this.runtimeHook;
|
|
213
|
-
return useResources(threads.map(({ id, generation }) => {
|
|
220
|
+
return useResources(threads.map(({ id, generation, destroySignal }) => {
|
|
214
221
|
const threadAdapters = this.pendingThreadAdapters.has(id) ? this.pendingThreadAdapters.get(id) : adapters.threadAdapters.get(id) ?? adapters.defaultAdapters;
|
|
215
222
|
return withKey(`${id}:${generation}:${hookEpoch}`, RemoteThreadResource({
|
|
216
223
|
threadId: id,
|
|
@@ -219,7 +226,8 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
219
226
|
runtimeHook,
|
|
220
227
|
parentClient,
|
|
221
228
|
adapters: threadAdapters,
|
|
222
|
-
publish: this._publish
|
|
229
|
+
publish: this._publish,
|
|
230
|
+
destroySignal
|
|
223
231
|
}));
|
|
224
232
|
}));
|
|
225
233
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListHookInstanceManager.js","names":["FC","RefObject","useEffect","useLayoutEffect","useMemo","useRef","memo","PropsWithChildren","ComponentType","Fragment","useResources","withKey","AssistantClient","ThreadListItemRuntimeProvider","ThreadRuntimeCore","ThreadRuntimeEventType","ThreadListRuntimeCore","ThreadListRuntimeEvent","Unsubscribe","BaseSubscribable","WritableSubscribable","useSubscribable","getThreadRuntimeCoreIsRunning","ThreadListRuntimeImpl","invalidateThreadRuntime","notifyEventListeners","useRuntimeAdapters","RuntimeAdapters","RemoteThreadResource","RemoteThreadListHook","THREAD_EVENTS","const","RemoteThreadListHookInstance","runtime","publishedGeneration","generation","isRunning","unsubscribeRunning","AdapterSnapshot","defaultAdapters","threadAdapters","ReadonlyMap","HostSnapshot","threads","id","hookEpoch","ProviderRenderDetector","detectorRef","t0","$","_c","t1","t2","current","RemoteThreadListHookInstanceManager","runtimeHook","adapterStore","Map","hostStore","pendingThreadAdapters","instances","nextGeneration","parent","constructor","_whenRuntimeAttached","threadId","Promise","resolve","reject","callback","instance","get","dispose","Error","subscribe","startThreadRuntime","has","set","_syncHostThreads","__internal_restartThreadRuntime","_notifySubscribers","getThreadRuntimeCore","undefined","__internal_isThreadRunning","runningSubscribers","Set","__internal_subscribeRunningChanged","add","delete","threadEventSubscribers","event","__internal_subscribeThreadEvents","_publish","_publishThreadRuntime","previousRuntime","_trackRunning","replacedSubscribers","__internal_subscribeRuntimeReplaced","_setRunning","unsubscribers","map","type","unstable_on","unsubscribe","stopThreadRuntime","setRuntimeHook","newRuntimeHook","host","getState","setState","__internal_setDefaultAdapters","adapters","__internal_setThreadAdapters","next","__internal_dispose","keys","Array","from","entries","__internal_useHost","parentClient","parentList","publish","__internal_RenderThreadRuntimes","provider","__internal_Host","_OuterActiveThreadProvider","Provider","getItemById","process","env","NODE_ENV","setTimeout","console","warn","clearTimeout","_AdapterSink"],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"sourcesContent":["import {\n type FC,\n type RefObject,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n memo,\n type PropsWithChildren,\n type ComponentType,\n Fragment,\n} from \"react\";\nimport { useResources, withKey } from \"@assistant-ui/tap\";\nimport type { AssistantClient } from \"@assistant-ui/store\";\nimport { ThreadListItemRuntimeProvider } from \"../providers/ThreadListItemRuntimeProvider\";\nimport type {\n ThreadRuntimeCore,\n ThreadRuntimeEventType,\n} from \"../../runtime/interfaces/thread-runtime-core\";\nimport type {\n ThreadListRuntimeCore,\n ThreadListRuntimeEvent,\n} from \"../../runtime/interfaces/thread-list-runtime-core\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport {\n BaseSubscribable,\n WritableSubscribable,\n} from \"../../subscribable/subscribable\";\nimport { useSubscribable } from \"../../store/runtime-clients/useSubscribable\";\nimport { getThreadRuntimeCoreIsRunning } from \"../../runtime/api/thread-runtime\";\nimport { ThreadListRuntimeImpl } from \"../../runtime/api/thread-list-runtime\";\nimport { invalidateThreadRuntime } from \"../../runtime/utils/thread-runtime-lifecycle\";\nimport { notifyEventListeners } from \"../../utils/notify-event-listeners\";\nimport {\n useRuntimeAdapters,\n type RuntimeAdapters,\n} from \"./RuntimeAdapterProvider\";\nimport {\n RemoteThreadResource,\n type RemoteThreadListHook,\n} from \"./RemoteThreadResource\";\n\nconst THREAD_EVENTS = [\n \"runStart\",\n \"runEnd\",\n \"initialize\",\n \"modelContextUpdate\",\n] as const satisfies readonly ThreadRuntimeEventType[];\n\ntype RemoteThreadListHookInstance = {\n runtime?: ThreadRuntimeCore | undefined;\n publishedGeneration?: number | undefined;\n generation: number;\n isRunning: boolean;\n unsubscribeRunning?: Unsubscribe | undefined;\n};\n\ntype AdapterSnapshot = {\n defaultAdapters: RuntimeAdapters | null;\n threadAdapters: ReadonlyMap<string, RuntimeAdapters | null>;\n};\n\ntype HostSnapshot = {\n threads: readonly { id: string; generation: number }[];\n hookEpoch: number;\n};\n\nconst ProviderRenderDetector: FC<{\n detectorRef: RefObject<boolean>;\n}> = ({ detectorRef }) => {\n useLayoutEffect(() => {\n detectorRef.current = true;\n }, [detectorRef]);\n return null;\n};\n\nexport class RemoteThreadListHookInstanceManager extends BaseSubscribable {\n private runtimeHook: RemoteThreadListHook;\n private readonly adapterStore = new WritableSubscribable<AdapterSnapshot>({\n defaultAdapters: null,\n threadAdapters: new Map(),\n });\n private readonly hostStore = new WritableSubscribable<HostSnapshot>({\n threads: [],\n hookEpoch: 0,\n });\n private readonly pendingThreadAdapters = new Map<\n string,\n RuntimeAdapters | null\n >();\n private instances = new Map<string, RemoteThreadListHookInstance>();\n private nextGeneration = 0;\n private parent: ThreadListRuntimeCore;\n\n constructor(\n runtimeHook: RemoteThreadListHook,\n parent: ThreadListRuntimeCore,\n ) {\n super();\n this.parent = parent;\n this.runtimeHook = runtimeHook;\n }\n\n private _whenRuntimeAttached(threadId: string) {\n return new Promise<ThreadRuntimeCore>((resolve, reject) => {\n const callback = () => {\n const instance = this.instances.get(threadId);\n if (!instance) {\n dispose();\n reject(new Error(\"Thread was deleted before runtime was started\"));\n } else if (\n !instance.runtime ||\n instance.publishedGeneration !== instance.generation\n ) {\n return;\n } else {\n dispose();\n resolve(instance.runtime);\n }\n };\n const dispose = this.subscribe(callback);\n callback();\n });\n }\n\n public startThreadRuntime(threadId: string) {\n if (!this.instances.has(threadId)) {\n const generation = this.nextGeneration++;\n this.instances.set(threadId, {\n generation,\n isRunning: false,\n });\n this._syncHostThreads();\n }\n\n return this._whenRuntimeAttached(threadId);\n }\n\n public __internal_restartThreadRuntime(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return this.startThreadRuntime(threadId);\n\n if (instance.runtime) invalidateThreadRuntime(instance.runtime);\n instance.generation = this.nextGeneration++;\n this._syncHostThreads();\n this._notifySubscribers();\n\n return this._whenRuntimeAttached(threadId);\n }\n\n public getThreadRuntimeCore(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return undefined;\n return instance.runtime;\n }\n\n public __internal_isThreadRunning(threadId: string) {\n return this.instances.get(threadId)?.isRunning ?? false;\n }\n\n private runningSubscribers = new Set<() => void>();\n\n public __internal_subscribeRunningChanged(callback: () => void): Unsubscribe {\n this.runningSubscribers.add(callback);\n return () => this.runningSubscribers.delete(callback);\n }\n\n private threadEventSubscribers = new Set<\n (event: ThreadListRuntimeEvent) => void\n >();\n\n public __internal_subscribeThreadEvents(\n callback: (event: ThreadListRuntimeEvent) => void,\n ): Unsubscribe {\n this.threadEventSubscribers.add(callback);\n return () => this.threadEventSubscribers.delete(callback);\n }\n\n private _publish = (\n threadId: string,\n runtime: ThreadRuntimeCore,\n generation: number,\n ) => {\n this._publishThreadRuntime(threadId, runtime, generation);\n };\n\n private _publishThreadRuntime(\n threadId: string,\n runtime: ThreadRuntimeCore,\n generation: number,\n ) {\n const instance = this.instances.get(threadId);\n if (!instance) return;\n\n if (instance.generation !== generation) return;\n\n const previousRuntime = instance.runtime;\n instance.runtime = runtime;\n instance.publishedGeneration = generation;\n if (previousRuntime !== runtime) {\n this._trackRunning(threadId, instance);\n }\n this._notifySubscribers();\n if (previousRuntime !== undefined && previousRuntime !== runtime) {\n for (const callback of this.replacedSubscribers) callback();\n }\n }\n\n private replacedSubscribers = new Set<() => void>();\n\n public __internal_subscribeRuntimeReplaced(\n callback: () => void,\n ): Unsubscribe {\n this.replacedSubscribers.add(callback);\n return () => this.replacedSubscribers.delete(callback);\n }\n\n private _trackRunning(\n threadId: string,\n instance: RemoteThreadListHookInstance,\n ) {\n instance.unsubscribeRunning?.();\n\n const runtime = instance.runtime;\n if (!runtime) {\n instance.unsubscribeRunning = undefined;\n this._setRunning(instance, false);\n return;\n }\n\n this._setRunning(instance, getThreadRuntimeCoreIsRunning(runtime));\n const unsubscribers = [\n runtime.subscribe(() => {\n this._setRunning(instance, getThreadRuntimeCoreIsRunning(runtime));\n }),\n ...THREAD_EVENTS.map((type) =>\n runtime.unstable_on(type, () => {\n notifyEventListeners(\n this.threadEventSubscribers,\n { threadId, type },\n `Thread event \"${type}\"`,\n );\n }),\n ),\n ];\n instance.unsubscribeRunning = () => {\n for (const unsubscribe of unsubscribers) unsubscribe();\n };\n }\n\n private _setRunning(\n instance: RemoteThreadListHookInstance,\n isRunning: boolean,\n ) {\n if (instance.isRunning === isRunning) return;\n instance.isRunning = isRunning;\n for (const callback of this.runningSubscribers) callback();\n }\n\n public stopThreadRuntime(threadId: string) {\n const instance = this.instances.get(threadId);\n if (instance?.runtime) invalidateThreadRuntime(instance.runtime);\n instance?.unsubscribeRunning?.();\n this.instances.delete(threadId);\n this.pendingThreadAdapters.delete(threadId);\n this._syncHostThreads();\n this._notifySubscribers();\n }\n\n public setRuntimeHook(newRuntimeHook: RemoteThreadListHook) {\n if (this.runtimeHook === newRuntimeHook) return;\n this.runtimeHook = newRuntimeHook;\n const host = this.hostStore.getState();\n this.hostStore.setState({ ...host, hookEpoch: host.hookEpoch + 1 });\n }\n\n public __internal_setDefaultAdapters(adapters: RuntimeAdapters | null) {\n const current = this.adapterStore.getState();\n if (current.defaultAdapters === adapters) return;\n this.adapterStore.setState({ ...current, defaultAdapters: adapters });\n }\n\n public __internal_setThreadAdapters(\n threadId: string,\n adapters: RuntimeAdapters | null,\n ) {\n const current = this.adapterStore.getState();\n const next = new Map(current.threadAdapters);\n if (adapters === null) next.delete(threadId);\n else next.set(threadId, adapters);\n this.adapterStore.setState({ ...current, threadAdapters: next });\n }\n\n public __internal_dispose() {\n for (const threadId of [...this.instances.keys()]) {\n this.stopThreadRuntime(threadId);\n }\n }\n\n private _syncHostThreads() {\n const host = this.hostStore.getState();\n this.hostStore.setState({\n ...host,\n threads: Array.from(this.instances.entries()).map(\n ([id, { generation }]) => ({ id, generation }),\n ),\n });\n }\n\n public __internal_useHost(parentClient: AssistantClient) {\n const { threads, hookEpoch } = useSubscribable(this.hostStore);\n const adapters = useSubscribable(this.adapterStore);\n const runtimeHook = this.runtimeHook;\n return useResources(\n threads.map(({ id, generation }) => {\n const threadAdapters = this.pendingThreadAdapters.has(id)\n ? this.pendingThreadAdapters.get(id)!\n : (adapters.threadAdapters.get(id) ?? adapters.defaultAdapters);\n return withKey(\n `${id}:${generation}:${hookEpoch}`,\n RemoteThreadResource({\n threadId: id,\n generation,\n parentList: this.parent,\n runtimeHook,\n parentClient,\n adapters: threadAdapters,\n publish: this._publish,\n }),\n );\n }),\n );\n }\n\n public __internal_RenderThreadRuntimes: FC<{\n provider: ComponentType<PropsWithChildren>;\n }> = ({ provider }) => {\n useSubscribable(this.hostStore);\n\n return Array.from(this.instances.entries()).map(\n ([threadId, { generation }]) => (\n <this._OuterActiveThreadProvider\n key={`${threadId}:${generation}`}\n threadId={threadId}\n provider={provider}\n />\n ),\n );\n };\n\n public __internal_Host: FC<{ parentClient: AssistantClient }> = ({\n parentClient,\n }) => {\n this.__internal_useHost(parentClient);\n return null;\n };\n\n private _OuterActiveThreadProvider: FC<{\n threadId: string;\n provider: ComponentType<PropsWithChildren>;\n }> = memo(({ threadId, provider: Provider }) => {\n const runtime = useMemo(\n () => new ThreadListRuntimeImpl(this.parent).getItemById(threadId),\n [threadId],\n );\n\n const detectorRef = useRef(false);\n useEffect(() => {\n if (process.env.NODE_ENV !== \"production\" && Provider !== Fragment) {\n const id = setTimeout(() => {\n if (!detectorRef.current) {\n console.warn(\n \"RemoteThreadListAdapter.unstable_Provider did not render its `children` synchronously. \" +\n \"Render `children` on first commit; deferring them behind a loading state, Suspense boundary, \" +\n \"or `useEffect` gate strands the runtime host and leaves the thread without context.\",\n );\n }\n }, 100);\n return () => clearTimeout(id);\n }\n return undefined;\n }, [Provider]);\n\n return (\n <ThreadListItemRuntimeProvider runtime={runtime}>\n <Provider>\n <this._AdapterSink threadId={threadId} detectorRef={detectorRef} />\n </Provider>\n </ThreadListItemRuntimeProvider>\n );\n });\n\n private _AdapterSink: FC<{\n threadId: string;\n detectorRef: RefObject<boolean>;\n }> = ({ threadId, detectorRef }) => {\n const adapters = useRuntimeAdapters();\n this.pendingThreadAdapters.set(threadId, adapters);\n useLayoutEffect(() => {\n this.__internal_setThreadAdapters(threadId, adapters);\n return () => {\n if (this.pendingThreadAdapters.get(threadId) === adapters) {\n this.pendingThreadAdapters.delete(threadId);\n }\n this.__internal_setThreadAdapters(threadId, null);\n };\n }, [threadId, adapters]);\n return <ProviderRenderDetector detectorRef={detectorRef} />;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAM8B,gBAAgB;CACpB;CACA;CACA;CACA;AAAoB;AAqBtB,MAAMgB,0BAEDE,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAH,gBAAAC;CAAe,IAAAG;CAAA,IAAAC;CAAA,IAAAH,EAAA,OAAAF,aAAA;EACHI,WAAA;GACdJ,YAAWM,UAAW;EAAH;EAClBD,KAAA,CAACL,WAAW;EAACE,EAAA,KAAAF;EAAAE,EAAA,KAAAE;EAAAF,EAAA,KAAAG;CAAA,OAAA;EAAAD,KAAAF,EAAA;EAAAG,KAAAH,EAAA;CAAA;CAFhB9C,gBAAgBgD,IAEbC,EAAa;CAAC,OACV;AAAI;AAGb,IAAaE,sCAAb,cAAyDnC,iBAAiB;CACxE;CACA,eAAgC,IAAIC,qBAAsC;EACxEmB,iBAAiB;EACjBC,gCAAgB,IAAIiB,IAAI;CAC1B,CAAC;CACD,YAA6B,IAAIrC,qBAAmC;EAClEuB,SAA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6BAA6B/C,UAAU,IAAI;GAClD;EACF,GAAG,CAACA,UAAU8C,QAAQ,CAAC;EACvB,OAAO,oBAAC,wBAAD,EAAqChE,YAAY,CAAA;CAC1D;AACF"}
|
|
1
|
+
{"version":3,"file":"RemoteThreadListHookInstanceManager.js","names":["FC","RefObject","useEffect","useLayoutEffect","useMemo","useRef","memo","PropsWithChildren","ComponentType","Fragment","useResources","withKey","AssistantClient","ThreadListItemRuntimeProvider","ThreadRuntimeCore","ThreadRuntimeEventType","ThreadListRuntimeCore","ThreadListRuntimeEvent","Unsubscribe","BaseSubscribable","notifySubscribers","WritableSubscribable","useSubscribable","getThreadRuntimeCoreIsRunning","ThreadListRuntimeImpl","invalidateThreadRuntime","notifyEventListeners","useRuntimeAdapters","RuntimeAdapters","RemoteThreadResource","RemoteThreadListHook","THREAD_EVENTS","const","RemoteThreadListHookInstance","runtime","publishedGeneration","generation","isRunning","unsubscribeRunning","destroy","AbortController","AdapterSnapshot","defaultAdapters","threadAdapters","ReadonlyMap","HostSnapshot","threads","id","destroySignal","AbortSignal","hookEpoch","ProviderRenderDetector","detectorRef","t0","$","_c","t1","t2","current","RemoteThreadListHookInstanceManager","runtimeHook","adapterStore","Map","hostStore","pendingThreadAdapters","instances","nextGeneration","parent","constructor","_whenRuntimeAttached","threadId","Promise","resolve","reject","callback","instance","get","dispose","Error","subscribe","startThreadRuntime","has","set","_syncHostThreads","__internal_restartThreadRuntime","undefined","abort","_notifySubscribers","getThreadRuntimeCore","__internal_isThreadRunning","runningSubscribers","Set","__internal_subscribeRunningChanged","add","delete","threadEventSubscribers","event","__internal_subscribeThreadEvents","_publish","_publishThreadRuntime","previousRuntime","_trackRunning","replacedSubscribers","__internal_subscribeRuntimeReplaced","_setRunning","unsubscribers","map","type","unstable_on","unsubscribe","stopThreadRuntime","setRuntimeHook","newRuntimeHook","host","getState","setState","__internal_setDefaultAdapters","adapters","__internal_setThreadAdapters","next","__internal_dispose","keys","Array","from","entries","signal","__internal_useHost","parentClient","parentList","publish","__internal_RenderThreadRuntimes","provider","__internal_Host","_OuterActiveThreadProvider","Provider","getItemById","process","env","NODE_ENV","setTimeout","console","warn","clearTimeout","_AdapterSink"],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"sourcesContent":["import {\n type FC,\n type RefObject,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n memo,\n type PropsWithChildren,\n type ComponentType,\n Fragment,\n} from \"react\";\nimport { useResources, withKey } from \"@assistant-ui/tap\";\nimport type { AssistantClient } from \"@assistant-ui/store\";\nimport { ThreadListItemRuntimeProvider } from \"../providers/ThreadListItemRuntimeProvider\";\nimport type {\n ThreadRuntimeCore,\n ThreadRuntimeEventType,\n} from \"../../runtime/interfaces/thread-runtime-core\";\nimport type {\n ThreadListRuntimeCore,\n ThreadListRuntimeEvent,\n} from \"../../runtime/interfaces/thread-list-runtime-core\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport {\n BaseSubscribable,\n notifySubscribers,\n WritableSubscribable,\n} from \"../../subscribable/subscribable\";\nimport { useSubscribable } from \"../../store/runtime-clients/useSubscribable\";\nimport { getThreadRuntimeCoreIsRunning } from \"../../runtime/api/thread-runtime\";\nimport { ThreadListRuntimeImpl } from \"../../runtime/api/thread-list-runtime\";\nimport { invalidateThreadRuntime } from \"../../runtime/utils/thread-runtime-lifecycle\";\nimport { notifyEventListeners } from \"../../utils/notify-event-listeners\";\nimport {\n useRuntimeAdapters,\n type RuntimeAdapters,\n} from \"./RuntimeAdapterProvider\";\nimport {\n RemoteThreadResource,\n type RemoteThreadListHook,\n} from \"./RemoteThreadResource\";\n\nconst THREAD_EVENTS = [\n \"runStart\",\n \"runEnd\",\n \"initialize\",\n \"modelContextUpdate\",\n] as const satisfies readonly ThreadRuntimeEventType[];\n\ntype RemoteThreadListHookInstance = {\n runtime?: ThreadRuntimeCore | undefined;\n publishedGeneration?: number | undefined;\n generation: number;\n isRunning: boolean;\n unsubscribeRunning?: Unsubscribe | undefined;\n // Permanent teardown of the thread's runtime, aborted when the thread is\n // stopped or its runtime restarted. A soft unmount leaves it armed.\n destroy: AbortController;\n};\n\ntype AdapterSnapshot = {\n defaultAdapters: RuntimeAdapters | null;\n threadAdapters: ReadonlyMap<string, RuntimeAdapters | null>;\n};\n\ntype HostSnapshot = {\n threads: readonly {\n id: string;\n generation: number;\n destroySignal: AbortSignal;\n }[];\n hookEpoch: number;\n};\n\nconst ProviderRenderDetector: FC<{\n detectorRef: RefObject<boolean>;\n}> = ({ detectorRef }) => {\n useLayoutEffect(() => {\n detectorRef.current = true;\n }, [detectorRef]);\n return null;\n};\n\nexport class RemoteThreadListHookInstanceManager extends BaseSubscribable {\n private runtimeHook: RemoteThreadListHook;\n private readonly adapterStore = new WritableSubscribable<AdapterSnapshot>({\n defaultAdapters: null,\n threadAdapters: new Map(),\n });\n private readonly hostStore = new WritableSubscribable<HostSnapshot>({\n threads: [],\n hookEpoch: 0,\n });\n private readonly pendingThreadAdapters = new Map<\n string,\n RuntimeAdapters | null\n >();\n private instances = new Map<string, RemoteThreadListHookInstance>();\n private nextGeneration = 0;\n private parent: ThreadListRuntimeCore;\n\n constructor(\n runtimeHook: RemoteThreadListHook,\n parent: ThreadListRuntimeCore,\n ) {\n super();\n this.parent = parent;\n this.runtimeHook = runtimeHook;\n }\n\n private _whenRuntimeAttached(threadId: string) {\n return new Promise<ThreadRuntimeCore>((resolve, reject) => {\n const callback = () => {\n const instance = this.instances.get(threadId);\n if (!instance) {\n dispose();\n reject(new Error(\"Thread was deleted before runtime was started\"));\n } else if (\n !instance.runtime ||\n instance.publishedGeneration !== instance.generation\n ) {\n return;\n } else {\n dispose();\n resolve(instance.runtime);\n }\n };\n const dispose = this.subscribe(callback);\n callback();\n });\n }\n\n public startThreadRuntime(threadId: string) {\n if (!this.instances.has(threadId)) {\n const generation = this.nextGeneration++;\n this.instances.set(threadId, {\n generation,\n isRunning: false,\n destroy: new AbortController(),\n });\n this._syncHostThreads();\n }\n\n return this._whenRuntimeAttached(threadId);\n }\n\n public __internal_restartThreadRuntime(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return this.startThreadRuntime(threadId);\n\n if (instance.runtime) invalidateThreadRuntime(instance.runtime);\n // Detach before aborting, as stopThreadRuntime does: the abort runs the\n // destroy listeners synchronously, and a listener that stops the outgoing\n // runtime would otherwise emit that generation's terminal events through\n // the subscription the next generation is about to reuse.\n instance.unsubscribeRunning?.();\n instance.unsubscribeRunning = undefined;\n instance.destroy.abort();\n instance.destroy = new AbortController();\n instance.generation = this.nextGeneration++;\n this._syncHostThreads();\n this._notifySubscribers();\n\n return this._whenRuntimeAttached(threadId);\n }\n\n public getThreadRuntimeCore(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return undefined;\n return instance.runtime;\n }\n\n public __internal_isThreadRunning(threadId: string) {\n return this.instances.get(threadId)?.isRunning ?? false;\n }\n\n private runningSubscribers = new Set<() => void>();\n\n public __internal_subscribeRunningChanged(callback: () => void): Unsubscribe {\n this.runningSubscribers.add(callback);\n return () => this.runningSubscribers.delete(callback);\n }\n\n private threadEventSubscribers = new Set<\n (event: ThreadListRuntimeEvent) => void\n >();\n\n public __internal_subscribeThreadEvents(\n callback: (event: ThreadListRuntimeEvent) => void,\n ): Unsubscribe {\n this.threadEventSubscribers.add(callback);\n return () => this.threadEventSubscribers.delete(callback);\n }\n\n private _publish = (\n threadId: string,\n runtime: ThreadRuntimeCore,\n generation: number,\n ) => {\n this._publishThreadRuntime(threadId, runtime, generation);\n };\n\n private _publishThreadRuntime(\n threadId: string,\n runtime: ThreadRuntimeCore,\n generation: number,\n ) {\n const instance = this.instances.get(threadId);\n if (!instance) return;\n\n if (instance.generation !== generation) return;\n\n const previousRuntime = instance.runtime;\n instance.runtime = runtime;\n instance.publishedGeneration = generation;\n if (previousRuntime !== runtime) {\n this._trackRunning(threadId, instance);\n }\n this._notifySubscribers();\n if (previousRuntime !== undefined && previousRuntime !== runtime) {\n notifySubscribers(this.replacedSubscribers);\n }\n }\n\n private replacedSubscribers = new Set<() => void>();\n\n public __internal_subscribeRuntimeReplaced(\n callback: () => void,\n ): Unsubscribe {\n this.replacedSubscribers.add(callback);\n return () => this.replacedSubscribers.delete(callback);\n }\n\n private _trackRunning(\n threadId: string,\n instance: RemoteThreadListHookInstance,\n ) {\n instance.unsubscribeRunning?.();\n\n const runtime = instance.runtime;\n if (!runtime) {\n instance.unsubscribeRunning = undefined;\n this._setRunning(instance, false);\n return;\n }\n\n this._setRunning(instance, getThreadRuntimeCoreIsRunning(runtime));\n const unsubscribers = [\n runtime.subscribe(() => {\n this._setRunning(instance, getThreadRuntimeCoreIsRunning(runtime));\n }),\n ...THREAD_EVENTS.map((type) =>\n runtime.unstable_on(type, () => {\n notifyEventListeners(\n this.threadEventSubscribers,\n { threadId, type },\n `Thread event \"${type}\"`,\n );\n }),\n ),\n ];\n instance.unsubscribeRunning = () => {\n for (const unsubscribe of unsubscribers) unsubscribe();\n };\n }\n\n private _setRunning(\n instance: RemoteThreadListHookInstance,\n isRunning: boolean,\n ) {\n if (instance.isRunning === isRunning) return;\n instance.isRunning = isRunning;\n notifySubscribers(this.runningSubscribers);\n }\n\n public stopThreadRuntime(threadId: string) {\n const instance = this.instances.get(threadId);\n if (instance?.runtime) invalidateThreadRuntime(instance.runtime);\n instance?.unsubscribeRunning?.();\n instance?.destroy.abort();\n this.instances.delete(threadId);\n this.pendingThreadAdapters.delete(threadId);\n this._syncHostThreads();\n this._notifySubscribers();\n }\n\n public setRuntimeHook(newRuntimeHook: RemoteThreadListHook) {\n if (this.runtimeHook === newRuntimeHook) return;\n this.runtimeHook = newRuntimeHook;\n const host = this.hostStore.getState();\n this.hostStore.setState({ ...host, hookEpoch: host.hookEpoch + 1 });\n }\n\n public __internal_setDefaultAdapters(adapters: RuntimeAdapters | null) {\n const current = this.adapterStore.getState();\n if (current.defaultAdapters === adapters) return;\n this.adapterStore.setState({ ...current, defaultAdapters: adapters });\n }\n\n public __internal_setThreadAdapters(\n threadId: string,\n adapters: RuntimeAdapters | null,\n ) {\n const current = this.adapterStore.getState();\n const next = new Map(current.threadAdapters);\n if (adapters === null) next.delete(threadId);\n else next.set(threadId, adapters);\n this.adapterStore.setState({ ...current, threadAdapters: next });\n }\n\n public __internal_dispose() {\n for (const threadId of [...this.instances.keys()]) {\n this.stopThreadRuntime(threadId);\n }\n }\n\n private _syncHostThreads() {\n const host = this.hostStore.getState();\n this.hostStore.setState({\n ...host,\n threads: Array.from(this.instances.entries()).map(\n ([id, { generation, destroy }]) => ({\n id,\n generation,\n destroySignal: destroy.signal,\n }),\n ),\n });\n }\n\n public __internal_useHost(parentClient: AssistantClient) {\n const { threads, hookEpoch } = useSubscribable(this.hostStore);\n const adapters = useSubscribable(this.adapterStore);\n const runtimeHook = this.runtimeHook;\n return useResources(\n threads.map(({ id, generation, destroySignal }) => {\n const threadAdapters = this.pendingThreadAdapters.has(id)\n ? this.pendingThreadAdapters.get(id)!\n : (adapters.threadAdapters.get(id) ?? adapters.defaultAdapters);\n return withKey(\n `${id}:${generation}:${hookEpoch}`,\n RemoteThreadResource({\n threadId: id,\n generation,\n parentList: this.parent,\n runtimeHook,\n parentClient,\n adapters: threadAdapters,\n publish: this._publish,\n destroySignal,\n }),\n );\n }),\n );\n }\n\n public __internal_RenderThreadRuntimes: FC<{\n provider: ComponentType<PropsWithChildren>;\n }> = ({ provider }) => {\n useSubscribable(this.hostStore);\n\n return Array.from(this.instances.entries()).map(\n ([threadId, { generation }]) => (\n <this._OuterActiveThreadProvider\n key={`${threadId}:${generation}`}\n threadId={threadId}\n provider={provider}\n />\n ),\n );\n };\n\n public __internal_Host: FC<{ parentClient: AssistantClient }> = ({\n parentClient,\n }) => {\n this.__internal_useHost(parentClient);\n return null;\n };\n\n private _OuterActiveThreadProvider: FC<{\n threadId: string;\n provider: ComponentType<PropsWithChildren>;\n }> = memo(({ threadId, provider: Provider }) => {\n const runtime = useMemo(\n () => new ThreadListRuntimeImpl(this.parent).getItemById(threadId),\n [threadId],\n );\n\n const detectorRef = useRef(false);\n useEffect(() => {\n if (process.env.NODE_ENV !== \"production\" && Provider !== Fragment) {\n const id = setTimeout(() => {\n if (!detectorRef.current) {\n console.warn(\n \"RemoteThreadListAdapter.unstable_Provider did not render its `children` synchronously. \" +\n \"Render `children` on first commit; deferring them behind a loading state, Suspense boundary, \" +\n \"or `useEffect` gate strands the runtime host and leaves the thread without context.\",\n );\n }\n }, 100);\n return () => clearTimeout(id);\n }\n return undefined;\n }, [Provider]);\n\n return (\n <ThreadListItemRuntimeProvider runtime={runtime}>\n <Provider>\n <this._AdapterSink threadId={threadId} detectorRef={detectorRef} />\n </Provider>\n </ThreadListItemRuntimeProvider>\n );\n });\n\n private _AdapterSink: FC<{\n threadId: string;\n detectorRef: RefObject<boolean>;\n }> = ({ threadId, detectorRef }) => {\n const adapters = useRuntimeAdapters();\n this.pendingThreadAdapters.set(threadId, adapters);\n useLayoutEffect(() => {\n this.__internal_setThreadAdapters(threadId, adapters);\n return () => {\n if (this.pendingThreadAdapters.get(threadId) === adapters) {\n this.pendingThreadAdapters.delete(threadId);\n }\n this.__internal_setThreadAdapters(threadId, null);\n };\n }, [threadId, adapters]);\n return <ProviderRenderDetector detectorRef={detectorRef} />;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AA2CA,MAAM+B,gBAAgB;CACpB;CACA;CACA;CACA;AAAoB;AA4BtB,MAAMoB,0BAEDE,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAH,gBAAAC;CAAe,IAAAG;CAAA,IAAAC;CAAA,IAAAH,EAAA,OAAAF,aAAA;EACHI,WAAA;GACdJ,YAAWM,UAAW;EAAH;EAClBD,KAAA,CAACL,WAAW;EAACE,EAAA,KAAAF;EAAAE,EAAA,KAAAE;EAAAF,EAAA,KAAAG;CAAA,OAAA;EAAAD,KAAAF,EAAA;EAAAG,KAAAH,EAAA;CAAA;CAFhBnD,gBAAgBqD,IAEbC,EAAa;CAAC,OACV;AAA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AN;IAA6BoC;IAAuBlB;GAAY,CAAA,EACxD,CAAA;EACmB,CAAA;CAEnC,CAAC;CAED,gBAGM,EAAEkB,UAAUlB,kBAAkB;EAClC,MAAMiE,WAAW1F,mBAAmB;EACpC,KAAKqC,sBAAsBkB,IAAIZ,UAAU+C,QAAQ;EACjDlH,sBAAsB;GACpB,KAAKmH,6BAA6BhD,UAAU+C,QAAQ;GACpD,aAAa;IACX,IAAI,KAAKrD,sBAAsBY,IAAIN,QAAQ,MAAM+C,UAC/C,KAAKrD,sBAAsB8B,OAAOxB,QAAQ;IAE5C,KAAKgD,6BAA6BhD,UAAU,IAAI;GAClD;EACF,GAAG,CAACA,UAAU+C,QAAQ,CAAC;EACvB,OAAO,oBAAC,wBAAD,EAAqCjE,YAAY,CAAA;CAC1D;AACF"}
|
|
@@ -28,6 +28,7 @@ declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscribable imp
|
|
|
28
28
|
private _staleThreadIdsOnReplace;
|
|
29
29
|
private _switchGeneration;
|
|
30
30
|
private _switchTask;
|
|
31
|
+
private readonly _titleStates;
|
|
31
32
|
private _mainThreadId;
|
|
32
33
|
private readonly _state;
|
|
33
34
|
private readonly _useAdaptersProvider;
|
|
@@ -47,6 +48,7 @@ declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscribable imp
|
|
|
47
48
|
reloadMainThread(): Promise<void>;
|
|
48
49
|
reload(): Promise<void>;
|
|
49
50
|
get isLoading(): boolean;
|
|
51
|
+
get loadError(): unknown;
|
|
50
52
|
get isLoadingMore(): boolean;
|
|
51
53
|
get hasMore(): boolean;
|
|
52
54
|
get threadIds(): readonly string[];
|
|
@@ -180,7 +182,9 @@ declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscribable imp
|
|
|
180
182
|
remoteId: string;
|
|
181
183
|
externalId: string | undefined;
|
|
182
184
|
}>;
|
|
183
|
-
generateTitle: (threadId: string
|
|
185
|
+
generateTitle: (threadId: string, options?: {
|
|
186
|
+
automatic?: boolean;
|
|
187
|
+
}) => Promise<void>;
|
|
184
188
|
rename(threadIdOrRemoteId: string, newTitle: string): Promise<void>;
|
|
185
189
|
updateCustom(threadIdOrRemoteId: string, custom: Record<string, unknown> | undefined): Promise<void>;
|
|
186
190
|
private _ensureThreadIsNotMain;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx"],"mappings":";;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx"],"mappings":";;;;;;;;;;;;;;;;;;cA4Ea,8CACH,4BACG;UAEH;mBACS;mBACA;UAET;UACA;UACA;UACA;UACA;UACA;UACA;UACA;mBACS;UAET;mBACS;mBAIA;mBAYA;UAcT;MAUG,eAAW,SAAA,OA3DX,mBA2DW;EAIf,yBAAqB;EAmFrB,YAAY;EAwDjB,YAAA,SAAS,yBACT,iBAAiB;UA6BX;UACA;EAED,sBAAsB,SAAS;UA0C9B;UAMA;UAMA;EA8GD;EAgBM,oBAAoB;EA4B1B,UAAM;MAWF;MAIA;MAIA;MAIA;MAIA;MAIA;MAIA;MAIA;cAMC;UAKJ;UAEA;EAcD,4BAAwB;;;eAlElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwEN,qBAAqB,6BAA0B;;;eANvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBxB,yBAAyB;EAMzB,+BACL,WAAW,OAAO,kCAAA;EAKb,YAAY,6BAA0B;EAItC,eACL,4BACA;IAAY;MACX;UAIK;UAgBM;EA0HP,qBAAqB;UAIpB;UAMA;UAOM;EAwBP,aAAoB,qBAAgB;;;;EA4CpC,gBACL,kBACA;IAAY;QAAqB;EAwDtB,OACX,4BACA,mBACC;EAyCU,aACX,4BACA,QAAQ,sCACP;UAoDW;EAsBD,QAAQ,6BAA0B;EAwBlC,UAAU,6BAA6B;EA4BvC,OAAO,6BAA0B;EA6BvC;EAIM,OAAO,6BAA6B;UAYzC;EAED,4BAA4B"}
|