@assistant-ui/core 0.3.15 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +8 -2
- package/dist/internal.js +9 -3
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +3 -2
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/frame/provider.d.ts +5 -0
- package/dist/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +141 -28
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/interactable-composer-metadata.d.ts +1 -1
- package/dist/model-context/interactable-composer-metadata.js +1 -1
- package/dist/model-context/interactable-composer-metadata.js.map +1 -1
- package/dist/model-context/registry.d.ts +2 -2
- package/dist/model-context/registry.d.ts.map +1 -1
- package/dist/model-context/registry.js +9 -28
- package/dist/model-context/registry.js.map +1 -1
- package/dist/model-context/tool-call-text.d.ts +26 -0
- package/dist/model-context/tool-call-text.d.ts.map +1 -0
- package/dist/model-context/tool-call-text.js +18 -0
- package/dist/model-context/tool-call-text.js.map +1 -0
- package/dist/react/RuntimeAdapter.js +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/AdaptedRemoteThread.js +1 -1
- package/dist/react/client/InMemoryThreadList.d.ts.map +1 -1
- package/dist/react/client/InMemoryThreadList.js +25 -21
- package/dist/react/client/InMemoryThreadList.js.map +1 -1
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js +60 -178
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/RemoteThreadList.d.ts +15 -0
- package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
- package/dist/react/client/RemoteThreadList.js +263 -194
- package/dist/react/client/RemoteThreadList.js.map +1 -1
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +6 -2
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +4 -2
- package/dist/react/index.js +2 -1
- package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -1
- package/dist/react/interactables-legacy/Interactables.js +60 -178
- package/dist/react/interactables-legacy/Interactables.js.map +1 -1
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts +24 -0
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.d.ts.map +1 -0
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.js +138 -0
- package/dist/react/interactables-shared/useInteractablePersistenceQueue.js.map +1 -0
- package/dist/react/model-context/toolbox.d.ts +2 -14
- package/dist/react/model-context/toolbox.d.ts.map +1 -1
- package/dist/react/model-context/toolbox.js +1 -13
- package/dist/react/model-context/toolbox.js.map +1 -1
- package/dist/react/model-context/useAssistantContext.js +37 -7
- package/dist/react/model-context/useAssistantContext.js.map +1 -1
- package/dist/react/model-context/useAuiToolOverrides.js +31 -5
- package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
- package/dist/react/model-context/useInlineRender.d.ts.map +1 -1
- package/dist/react/model-context/useInlineRender.js +10 -36
- package/dist/react/model-context/useInlineRender.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.js +2 -8
- package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +2 -4
- package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js +4 -3
- package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/react/primitives/composer/ComposerIf.js.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.d.ts +2 -1
- package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js +4 -3
- package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.js +7 -6
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +2 -2
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +3 -3
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.d.ts.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js +5 -4
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +7 -5
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +44 -22
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +7 -6
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +102 -117
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.d.ts +1 -6
- package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.js +3 -3
- package/dist/react/runtimes/RemoteThreadResource.js.map +1 -1
- package/dist/react/runtimes/assistant-transport/runManager.d.ts.map +1 -1
- package/dist/react/runtimes/assistant-transport/runManager.js +2 -12
- package/dist/react/runtimes/assistant-transport/runManager.js.map +1 -1
- package/dist/react/runtimes/assistant-transport/useLatestRef.js +2 -2
- package/dist/react/runtimes/assistant-transport/useLatestRef.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +3 -10
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +43 -85
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +5 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts +29 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js +159 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js.map +1 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts +12 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js +10 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.js.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts +1 -9
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +16 -153
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js.map +1 -1
- package/dist/react/runtimes/createMessageConverter.d.ts +2 -1
- package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.d.ts +6 -25
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +33 -233
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +14 -6
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/types/MessagePartComponentTypes.d.ts +7 -3
- package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
- package/dist/react/types/scopes/tools.d.ts +2 -0
- package/dist/react/types/scopes/tools.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.d.ts +1 -1
- package/dist/runtime/api/composer-runtime.js.map +1 -1
- package/dist/runtime/api/message-part-runtime.d.ts +2 -2
- package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-part-runtime.js +1 -1
- package/dist/runtime/api/message-part-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +9 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +5 -0
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +2 -3
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +14 -29
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +4 -6
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +5 -11
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/composer-runtime-core.d.ts +1 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +14 -2
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +16 -2
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/internal.d.ts +2 -1
- package/dist/runtime/internal.js +2 -1
- package/dist/runtime/queue/external-thread-queue-adapter.d.ts +1 -1
- package/dist/runtime/queue/message-queue.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.js +1 -1
- package/dist/runtime/queue/message-queue.js.map +1 -1
- package/dist/runtime/queue/queue-item.d.ts +12 -0
- package/dist/runtime/queue/queue-item.d.ts.map +1 -0
- package/dist/runtime/queue/queue-item.js +6 -0
- package/dist/runtime/queue/queue-item.js.map +1 -0
- package/dist/runtime/utils/abortable-thread-load.d.ts +15 -0
- package/dist/runtime/utils/abortable-thread-load.d.ts.map +1 -0
- package/dist/runtime/utils/abortable-thread-load.js +35 -0
- package/dist/runtime/utils/abortable-thread-load.js.map +1 -0
- package/dist/runtime/utils/attachment-add-operations.d.ts +18 -0
- package/dist/runtime/utils/attachment-add-operations.d.ts.map +1 -0
- package/dist/runtime/utils/attachment-add-operations.js +43 -0
- package/dist/runtime/utils/attachment-add-operations.js.map +1 -0
- package/dist/runtime/utils/auto-status.d.ts +7 -2
- package/dist/runtime/utils/auto-status.d.ts.map +1 -1
- package/dist/runtime/utils/auto-status.js +13 -3
- package/dist/runtime/utils/auto-status.js.map +1 -1
- package/dist/runtime/utils/external-message-conversion.d.ts +48 -0
- package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -0
- package/dist/runtime/utils/external-message-conversion.js +222 -0
- package/dist/runtime/utils/external-message-conversion.js.map +1 -0
- package/dist/runtime/utils/external-store-message.d.ts +2 -1
- package/dist/runtime/utils/external-store-message.d.ts.map +1 -1
- package/dist/runtime/utils/external-store-message.js +2 -1
- package/dist/runtime/utils/external-store-message.js.map +1 -1
- package/dist/runtime/utils/message-repository-session.d.ts +30 -0
- package/dist/runtime/utils/message-repository-session.d.ts.map +1 -0
- package/dist/runtime/utils/message-repository-session.js +130 -0
- package/dist/runtime/utils/message-repository-session.js.map +1 -0
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.js +3 -4
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtime/utils/pending-tool-calls.d.ts +20 -0
- package/dist/runtime/utils/pending-tool-calls.d.ts.map +1 -0
- package/dist/runtime/utils/pending-tool-calls.js +22 -0
- package/dist/runtime/utils/pending-tool-calls.js.map +1 -0
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +6 -3
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -1
- package/dist/runtime/utils/resolveToolApprovalResponse.js +12 -3
- package/dist/runtime/utils/resolveToolApprovalResponse.js.map +1 -1
- package/dist/runtime/utils/thread-message-like.d.ts +3 -10
- package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtime/utils/tool-call-tree.d.ts +39 -0
- package/dist/runtime/utils/tool-call-tree.d.ts.map +1 -0
- package/dist/runtime/utils/tool-call-tree.js +85 -0
- package/dist/runtime/utils/tool-call-tree.js.map +1 -0
- package/dist/runtimes/external-store/external-store-adapter.d.ts +29 -2
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +2 -5
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +3 -10
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +21 -2
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +154 -46
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +4 -2
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +23 -3
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +12 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.js +107 -14
- package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/title.d.ts +9 -0
- package/dist/runtimes/remote-thread-list/title.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/title.js +6 -0
- package/dist/runtimes/remote-thread-list/title.js.map +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts +6 -5
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +31 -8
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +98 -59
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/external-thread.d.ts +1 -1
- package/dist/store/clients/external-thread.d.ts.map +1 -1
- package/dist/store/clients/external-thread.js +85 -103
- package/dist/store/clients/external-thread.js.map +1 -1
- package/dist/store/clients/single-thread-list.d.ts.map +1 -1
- package/dist/store/clients/single-thread-list.js +2 -2
- package/dist/store/clients/single-thread-list.js.map +1 -1
- package/dist/store/clients/suggestions.d.ts.map +1 -1
- package/dist/store/clients/suggestions.js +33 -12
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-message-client.js +1 -1
- package/dist/store/clients/thread-selection-events.js +1 -1
- package/dist/store/index.d.ts +6 -3
- package/dist/store/index.js +2 -1
- package/dist/store/internal.d.ts +2 -2
- package/dist/store/internal.js +2 -2
- package/dist/store/primitive-predicates.d.ts +4 -1
- package/dist/store/primitive-predicates.d.ts.map +1 -1
- package/dist/store/primitive-predicates.js +9 -1
- package/dist/store/primitive-predicates.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +124 -105
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +1 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts +3 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts.map +1 -1
- package/dist/store/runtime-clients/useSubscribable.js +1 -1
- package/dist/store/runtime-clients/useSubscribable.js.map +1 -1
- package/dist/store/scope-registration.d.ts +1 -1
- package/dist/store/scopes/composer.d.ts +2 -1
- package/dist/store/scopes/composer.d.ts.map +1 -1
- package/dist/store/scopes/message.d.ts +1 -1
- package/dist/store/scopes/part.d.ts +6 -3
- package/dist/store/scopes/part.d.ts.map +1 -1
- package/dist/store/scopes/queue-item.d.ts +2 -9
- package/dist/store/scopes/queue-item.d.ts.map +1 -1
- package/dist/store/scopes/queue-item.js +0 -6
- package/dist/subscribable/subscribable.d.ts +8 -1
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +24 -16
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/types/message.d.ts +47 -4
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js +7 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/data-url.d.ts +14 -1
- package/dist/utils/data-url.d.ts.map +1 -1
- package/dist/utils/data-url.js +13 -1
- package/dist/utils/data-url.js.map +1 -1
- package/dist/utils/invoke-user-callback.d.ts +5 -0
- package/dist/utils/invoke-user-callback.d.ts.map +1 -0
- package/dist/utils/invoke-user-callback.js +19 -0
- package/dist/utils/invoke-user-callback.js.map +1 -0
- package/dist/utils/normalizePartStatus.js.map +1 -1
- package/package.json +12 -17
- package/src/index.ts +6 -1
- package/src/internal.ts +20 -0
- package/src/model-context/frame/host.test.ts +91 -7
- package/src/model-context/frame/host.ts +7 -2
- package/src/model-context/frame/provider.test.ts +484 -13
- package/src/model-context/frame/provider.ts +205 -35
- package/src/model-context/interactable-composer-metadata.ts +1 -1
- package/src/model-context/registry.test.ts +44 -0
- package/src/model-context/registry.ts +13 -35
- package/src/model-context/tool-call-text.test.ts +67 -0
- package/src/model-context/tool-call-text.ts +67 -0
- package/src/react/AssistantRuntimeProvider.test.tsx +66 -2
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +1 -3
- package/src/react/client/InMemoryThreadList.test.tsx +49 -0
- package/src/react/client/InMemoryThreadList.ts +7 -1
- package/src/react/client/Interactables.ts +19 -178
- package/src/react/client/RemoteThreadList.background.test.ts +384 -0
- package/src/react/client/RemoteThreadList.concurrent.test.tsx +274 -0
- package/src/react/client/RemoteThreadList.test.ts +369 -1
- package/src/react/client/RemoteThreadList.ts +320 -142
- package/src/react/client/Tools.ts +7 -1
- package/src/react/index.ts +4 -0
- package/src/react/interactables-legacy/Interactables.ts +20 -177
- package/src/react/interactables-shared/useInteractablePersistenceQueue.test.tsx +161 -0
- package/src/react/interactables-shared/useInteractablePersistenceQueue.ts +206 -0
- package/src/react/model-context/modelContextHooks.test.tsx +131 -0
- package/src/react/model-context/toolbox.test.ts +9 -9
- package/src/react/model-context/toolbox.ts +9 -36
- package/src/react/model-context/useAssistantContext.ts +4 -2
- package/src/react/model-context/useAuiToolOverrides.ts +4 -2
- package/src/react/model-context/useInlineRender.test.tsx +48 -0
- package/src/react/model-context/useInlineRender.ts +14 -10
- package/src/react/primitive-hooks/useMessageError.ts +2 -19
- package/src/react/primitive-hooks/useThreadListLoadMore.ts +2 -3
- package/src/react/primitives/composer/ComposerAttachments.test.tsx +76 -0
- package/src/react/primitives/composer/ComposerAttachments.tsx +9 -4
- package/src/react/primitives/composer/ComposerQueue.test.tsx +72 -0
- package/src/react/primitives/composer/ComposerQueue.tsx +7 -4
- package/src/react/primitives/message/MessageAttachments.test.tsx +107 -37
- package/src/react/primitives/message/MessageAttachments.tsx +10 -7
- package/src/react/primitives/message/MessageGroupedParts.tsx +2 -2
- package/src/react/primitives/message/MessageParts.tsx +3 -3
- package/src/react/primitives/threadList/ThreadListItems.test.tsx +99 -0
- package/src/react/primitives/threadList/ThreadListItems.tsx +8 -5
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +94 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +72 -31
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.switch-delete.test.ts +169 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +140 -124
- package/src/react/runtimes/RemoteThreadResource.ts +1 -4
- package/src/react/runtimes/assistant-transport/runManager.ts +4 -17
- package/src/react/runtimes/assistant-transport/transport-scheduling.test.ts +51 -2
- package/src/react/runtimes/assistant-transport/useLatestRef.ts +2 -2
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +45 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +157 -1
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +82 -176
- package/src/react/runtimes/cloud/auiV0.ts +5 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +88 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +236 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.test.ts +37 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapterCreateFallback.ts +18 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +90 -1
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +33 -238
- package/src/react/runtimes/external-message-converter.test.ts +0 -14
- package/src/react/runtimes/external-message-converter.test.tsx +77 -0
- package/src/react/runtimes/external-message-converter.ts +59 -481
- package/src/react/runtimes/useRemoteThreadListRuntime.concurrent.test.tsx +216 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +24 -6
- package/src/react/types/MessagePartComponentTypes.ts +7 -3
- package/src/react/types/scopes/tools.ts +2 -0
- package/src/runtime/api/composer-runtime.ts +1 -1
- package/src/runtime/api/message-part-runtime.ts +3 -3
- package/src/runtime/api/message-runtime.test.ts +28 -1
- package/src/runtime/api/thread-list-runtime.ts +25 -1
- package/src/runtime/base/base-composer-runtime-core.ts +20 -40
- package/src/runtime/base/base-thread-runtime-core.test.ts +110 -3
- package/src/runtime/base/base-thread-runtime-core.ts +16 -15
- package/src/runtime/base/default-thread-composer-runtime-core.ts +1 -4
- package/src/runtime/interfaces/composer-runtime-core.ts +1 -1
- package/src/runtime/interfaces/thread-list-runtime-core.ts +20 -1
- package/src/runtime/interfaces/thread-runtime-core.ts +18 -2
- package/src/runtime/internal.ts +5 -0
- package/src/runtime/queue/external-thread-queue-adapter.ts +1 -1
- package/src/runtime/queue/message-queue.ts +1 -4
- package/src/runtime/queue/queue-item.ts +10 -0
- package/src/runtime/utils/abortable-thread-load.test.ts +87 -0
- package/src/runtime/utils/abortable-thread-load.ts +53 -0
- package/src/runtime/utils/attachment-add-operations.ts +59 -0
- package/src/runtime/utils/auto-status.test.ts +57 -0
- package/src/runtime/utils/auto-status.ts +46 -1
- package/src/runtime/utils/external-message-conversion.test.ts +210 -0
- package/src/runtime/utils/external-message-conversion.ts +510 -0
- package/src/runtime/utils/external-store-message.ts +2 -0
- package/src/runtime/utils/message-repository-session.test.ts +195 -0
- package/src/runtime/utils/message-repository-session.ts +176 -0
- package/src/runtime/utils/message-repository.ts +7 -4
- package/src/runtime/utils/pending-tool-calls.test.ts +57 -0
- package/src/runtime/utils/pending-tool-calls.ts +35 -0
- package/src/runtime/utils/resolveToolApprovalResponse.test.ts +73 -0
- package/src/runtime/utils/resolveToolApprovalResponse.ts +27 -6
- package/src/runtime/utils/thread-message-like.ts +4 -10
- package/src/runtime/utils/tool-call-tree.test.ts +191 -0
- package/src/runtime/utils/tool-call-tree.ts +97 -0
- package/src/runtimes/external-store/external-store-adapter.ts +38 -2
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +6 -14
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +231 -61
- package/src/runtimes/inert/InertThreadRuntimeCore.ts +1 -1
- package/src/runtimes/local/local-thread-runtime-core.test.ts +201 -4
- package/src/runtimes/local/local-thread-runtime-core.ts +53 -4
- package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +149 -0
- package/src/runtimes/remote-thread-list/remote-thread-state.ts +178 -16
- package/src/runtimes/remote-thread-list/title.ts +3 -0
- package/src/runtimes/remote-thread-list/types.ts +6 -5
- package/src/runtimes/tool-invocations/EDGE_CASES.md +125 -3
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +856 -102
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +145 -89
- package/src/store/clients/external-thread.ts +30 -69
- package/src/store/clients/single-thread-list.ts +4 -1
- package/src/store/clients/suggestions.test.ts +185 -0
- package/src/store/clients/suggestions.ts +42 -35
- package/src/store/index.ts +4 -0
- package/src/store/internal.ts +2 -0
- package/src/store/primitive-predicates.ts +35 -0
- package/src/store/runtime-clients/thread-list-runtime-client.ts +16 -2
- package/src/store/runtime-clients/useSubscribable.ts +8 -2
- package/src/store/scopes/message.ts +1 -1
- package/src/store/scopes/part.ts +6 -3
- package/src/store/scopes/queue-item.ts +2 -9
- package/src/subscribable/subscribable.test.ts +50 -0
- package/src/subscribable/subscribable.ts +33 -21
- package/src/tests/MessageRepository.test.ts +77 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-load-race.test.ts +305 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-loadMore.test.ts +78 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-reload.test.ts +52 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-title-race.test.ts +158 -0
- package/src/tests/external-store-optimistic-id.test.ts +79 -0
- package/src/tests/external-store-repository-instance.test.ts +166 -0
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +186 -16
- package/src/tests/external-store-thread-runtime-core.test.ts +642 -0
- package/src/tests/external-thread-attachments.test.tsx +258 -1
- package/src/tests/remote-thread-list-adapter-switch.test.ts +66 -1
- package/src/tests/single-thread-list-item.test.tsx +47 -0
- package/src/tests/thread-message-like.test.ts +39 -1
- package/src/tests/thread-switch-events.test.tsx +397 -2
- package/src/types/message.ts +58 -5
- package/src/utils/data-url.test.ts +52 -1
- package/src/utils/data-url.ts +21 -0
- package/src/utils/invoke-user-callback.test.ts +82 -0
- package/src/utils/invoke-user-callback.ts +31 -0
- package/src/utils/normalizePartStatus.ts +1 -1
- package/dist/store/scopes/queue-item.js.map +0 -1
|
@@ -1,198 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { fromThreadMessageLike } from "../../runtime/utils/thread-message-like.js";
|
|
4
|
-
import { bindExternalStoreMessage, getExternalStoreMessages, symbolInnerMessage } from "../../runtime/utils/external-store-message.js";
|
|
5
|
-
import { getAutoStatus, isAutoStatus } from "../../runtime/utils/auto-status.js";
|
|
2
|
+
import { bindExternalStoreMessage } from "../../runtime/utils/external-store-message.js";
|
|
6
3
|
import { ThreadMessageConverter } from "../../runtimes/external-store/thread-message-converter.js";
|
|
4
|
+
import { chunkExternalMessages, completeExternalMessageConversion, convertExternalMessageCallback, convertExternalMessageChunk, convertExternalMessages as convertExternalMessages$1, shallowArrayEqual } from "../../runtime/utils/external-message-conversion.js";
|
|
7
5
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
8
6
|
import { useState } from "@assistant-ui/tap/react-shim";
|
|
9
7
|
//#region src/react/runtimes/external-message-converter.ts
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
if (c.type !== "tool-call" || c.result !== void 0) return false;
|
|
13
|
-
return c.interrupt != null || c.approval != null && c.approval.approved === void 0 && c.approval.resolution === void 0;
|
|
14
|
-
};
|
|
15
|
-
const stringifyForError = (value) => {
|
|
16
|
-
let text;
|
|
17
|
-
try {
|
|
18
|
-
text = value instanceof Error ? String(value) : JSON.stringify(value);
|
|
19
|
-
} catch {}
|
|
20
|
-
text ??= String(value);
|
|
21
|
-
return text.length > 200 ? `${text.slice(0, 200)}…` : text;
|
|
22
|
-
};
|
|
23
|
-
const toCallbackOutputs = (output, input) => {
|
|
24
|
-
const outputs = Array.isArray(output) ? output : [output];
|
|
25
|
-
for (const o of outputs) if (!(typeof o === "object" && o !== null && (o.role === "tool" || (o.role === "assistant" || o.role === "user" || o.role === "system") && (typeof o.content === "string" || Array.isArray(o.content))))) throw new Error(`External message converter: the converter callback returned an invalid message (${stringifyForError(o)}) for input ${stringifyForError(input)}. Return an empty array to skip a message.`);
|
|
26
|
-
return outputs;
|
|
27
|
-
};
|
|
28
|
-
const mergeInnerMessages = (existing, incoming) => ({ [symbolInnerMessage]: [...existing[symbolInnerMessage] ?? [], ...incoming[symbolInnerMessage] ?? []] });
|
|
29
|
-
const joinExternalMessages = (messages) => {
|
|
30
|
-
const assistantMessage = {
|
|
31
|
-
role: "assistant",
|
|
32
|
-
content: []
|
|
33
|
-
};
|
|
34
|
-
for (const output of messages) if (output.role === "tool") {
|
|
35
|
-
const toolCallIdx = assistantMessage.content.findIndex((c) => c.type === "tool-call" && c.toolCallId === output.toolCallId);
|
|
36
|
-
if (toolCallIdx !== -1) {
|
|
37
|
-
const toolCall = assistantMessage.content[toolCallIdx];
|
|
38
|
-
if (output.toolName != null) {
|
|
39
|
-
if (toolCall.toolName !== output.toolName) throw new Error(`Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`);
|
|
40
|
-
}
|
|
41
|
-
assistantMessage.content[toolCallIdx] = {
|
|
42
|
-
...toolCall,
|
|
43
|
-
[symbolInnerMessage]: [...toolCall[symbolInnerMessage] ?? [], output],
|
|
44
|
-
result: output.result,
|
|
45
|
-
artifact: output.artifact,
|
|
46
|
-
isError: output.isError,
|
|
47
|
-
messages: output.messages
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
const role = output.role;
|
|
52
|
-
const content = (typeof output.content === "string" ? [{
|
|
53
|
-
type: "text",
|
|
54
|
-
text: output.content
|
|
55
|
-
}] : output.content).map((c) => ({
|
|
56
|
-
...c,
|
|
57
|
-
[symbolInnerMessage]: [output]
|
|
58
|
-
}));
|
|
59
|
-
switch (role) {
|
|
60
|
-
case "system":
|
|
61
|
-
case "user": return {
|
|
62
|
-
...output,
|
|
63
|
-
content
|
|
64
|
-
};
|
|
65
|
-
case "assistant":
|
|
66
|
-
if (assistantMessage.content.length === 0) {
|
|
67
|
-
assistantMessage.id = output.id;
|
|
68
|
-
assistantMessage.createdAt ??= output.createdAt;
|
|
69
|
-
assistantMessage.status ??= output.status;
|
|
70
|
-
if (output.attachments) assistantMessage.attachments = [...assistantMessage.attachments ?? [], ...output.attachments];
|
|
71
|
-
}
|
|
72
|
-
if (output.metadata) {
|
|
73
|
-
assistantMessage.metadata ??= {};
|
|
74
|
-
if (output.metadata.unstable_state !== void 0) assistantMessage.metadata.unstable_state = output.metadata.unstable_state;
|
|
75
|
-
if (output.metadata.unstable_annotations) assistantMessage.metadata.unstable_annotations = [...assistantMessage.metadata.unstable_annotations ?? [], ...output.metadata.unstable_annotations];
|
|
76
|
-
if (output.metadata.unstable_data) assistantMessage.metadata.unstable_data = [...assistantMessage.metadata.unstable_data ?? [], ...output.metadata.unstable_data];
|
|
77
|
-
if (output.metadata.steps) assistantMessage.metadata.steps = [...assistantMessage.metadata.steps ?? [], ...output.metadata.steps];
|
|
78
|
-
if (output.metadata.custom) assistantMessage.metadata.custom = {
|
|
79
|
-
...assistantMessage.metadata.custom ?? {},
|
|
80
|
-
...output.metadata.custom
|
|
81
|
-
};
|
|
82
|
-
if (output.metadata.timing) assistantMessage.metadata.timing = output.metadata.timing;
|
|
83
|
-
if (output.metadata.submittedFeedback) assistantMessage.metadata.submittedFeedback = output.metadata.submittedFeedback;
|
|
84
|
-
if (output.metadata.isOptimistic) assistantMessage.metadata.isOptimistic = true;
|
|
85
|
-
}
|
|
86
|
-
for (const part of content) {
|
|
87
|
-
if (part.type === "tool-call") {
|
|
88
|
-
const existingIdx = assistantMessage.content.findIndex((c) => c.type === "tool-call" && c.toolCallId === part.toolCallId);
|
|
89
|
-
if (existingIdx !== -1) {
|
|
90
|
-
const existing = assistantMessage.content[existingIdx];
|
|
91
|
-
assistantMessage.content[existingIdx] = {
|
|
92
|
-
...existing,
|
|
93
|
-
...part,
|
|
94
|
-
...mergeInnerMessages(existing, part)
|
|
95
|
-
};
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (part.type === "reasoning" && "parentId" in part && part.parentId) {
|
|
100
|
-
const existingIdx = assistantMessage.content.findIndex((c) => c.type === "reasoning" && "parentId" in c && c.parentId === part.parentId);
|
|
101
|
-
if (existingIdx !== -1) {
|
|
102
|
-
const existing = assistantMessage.content[existingIdx];
|
|
103
|
-
assistantMessage.content[existingIdx] = {
|
|
104
|
-
...existing,
|
|
105
|
-
text: `${existing.text}\n\n${part.text}`,
|
|
106
|
-
...mergeInnerMessages(existing, part)
|
|
107
|
-
};
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
assistantMessage.content.push(part);
|
|
112
|
-
}
|
|
113
|
-
break;
|
|
114
|
-
default: throw new Error(`Unknown message role: ${role}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return assistantMessage;
|
|
118
|
-
};
|
|
119
|
-
const chunkExternalMessages = (callbackResults, joinStrategy) => {
|
|
120
|
-
const results = [];
|
|
121
|
-
let isAssistant = false;
|
|
122
|
-
let pendingNone = false;
|
|
123
|
-
let inputs = [];
|
|
124
|
-
let outputs = [];
|
|
125
|
-
const flush = () => {
|
|
126
|
-
if (outputs.length) results.push({
|
|
127
|
-
inputs,
|
|
128
|
-
outputs
|
|
129
|
-
});
|
|
130
|
-
inputs = [];
|
|
131
|
-
outputs = [];
|
|
132
|
-
isAssistant = false;
|
|
133
|
-
pendingNone = false;
|
|
134
|
-
};
|
|
135
|
-
for (const callbackResult of callbackResults) for (const output of callbackResult.outputs) {
|
|
136
|
-
if (pendingNone && output.role !== "tool" || !isAssistant || output.role === "user" || output.role === "system") flush();
|
|
137
|
-
isAssistant = output.role === "assistant" || output.role === "tool";
|
|
138
|
-
if (inputs.at(-1) !== callbackResult.input) inputs.push(callbackResult.input);
|
|
139
|
-
outputs.push(output);
|
|
140
|
-
if (output.role === "assistant" && (output.convertConfig?.joinStrategy === "none" || joinStrategy === "none")) pendingNone = true;
|
|
141
|
-
}
|
|
142
|
-
flush();
|
|
143
|
-
return results;
|
|
144
|
-
};
|
|
145
|
-
function createErrorAssistantMessage(error) {
|
|
146
|
-
const msg = {
|
|
147
|
-
id: generateErrorMessageId(),
|
|
148
|
-
role: "assistant",
|
|
149
|
-
content: [],
|
|
150
|
-
status: {
|
|
151
|
-
type: "incomplete",
|
|
152
|
-
reason: "error",
|
|
153
|
-
error
|
|
154
|
-
},
|
|
155
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
156
|
-
metadata: {
|
|
157
|
-
unstable_state: null,
|
|
158
|
-
unstable_annotations: [],
|
|
159
|
-
unstable_data: [],
|
|
160
|
-
custom: {},
|
|
161
|
-
steps: []
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
bindExternalStoreMessage(msg, []);
|
|
165
|
-
return msg;
|
|
166
|
-
}
|
|
167
|
-
const convertExternalMessages = (messages, callback, isRunning, metadata) => {
|
|
168
|
-
const callbackResults = [];
|
|
169
|
-
for (const message of messages) {
|
|
170
|
-
const output = callback(message, metadata);
|
|
171
|
-
const result = {
|
|
172
|
-
input: message,
|
|
173
|
-
outputs: toCallbackOutputs(output, message)
|
|
174
|
-
};
|
|
175
|
-
callbackResults.push(result);
|
|
176
|
-
}
|
|
177
|
-
const chunks = chunkExternalMessages(callbackResults);
|
|
178
|
-
const result = chunks.map((message, idx) => {
|
|
179
|
-
const isLast = idx === chunks.length - 1;
|
|
180
|
-
const joined = joinExternalMessages(message.outputs);
|
|
181
|
-
const hasInterruptedToolCalls = typeof joined.content === "object" && joined.content.some(isInterruptedToolCall);
|
|
182
|
-
const hasPendingToolCalls = typeof joined.content === "object" && joined.content.some(isPendingToolCall);
|
|
183
|
-
const autoStatus = getAutoStatus(isLast, isRunning, hasInterruptedToolCalls, hasPendingToolCalls, isLast ? metadata.error : void 0);
|
|
184
|
-
const newMessage = fromThreadMessageLike(joined, idx.toString(), autoStatus);
|
|
185
|
-
bindExternalStoreMessage(newMessage, message.inputs);
|
|
186
|
-
return newMessage;
|
|
187
|
-
});
|
|
188
|
-
if (metadata.error) {
|
|
189
|
-
const lastMessage = result.at(-1);
|
|
190
|
-
if (!lastMessage || lastMessage.role !== "assistant") result.push(createErrorAssistantMessage(metadata.error));
|
|
191
|
-
}
|
|
192
|
-
return result;
|
|
193
|
-
};
|
|
8
|
+
const generatedFallbackMessages = /* @__PURE__ */ new WeakSet();
|
|
9
|
+
const convertExternalMessages = convertExternalMessages$1;
|
|
194
10
|
const useExternalMessageConverter = (t0) => {
|
|
195
|
-
const $ = c(
|
|
11
|
+
const $ = c(17);
|
|
196
12
|
const { callback, messages, isRunning, joinStrategy, metadata } = t0;
|
|
197
13
|
const [caches] = useState(_temp);
|
|
198
14
|
let t1;
|
|
@@ -214,16 +30,14 @@ const useExternalMessageConverter = (t0) => {
|
|
|
214
30
|
$[5] = t2;
|
|
215
31
|
} else t2 = $[5];
|
|
216
32
|
const state = t2;
|
|
217
|
-
let
|
|
218
|
-
if ($[6] !== isRunning || $[7] !== joinStrategy || $[8] !== messages || $[9] !== state) {
|
|
33
|
+
let t3;
|
|
34
|
+
if ($[6] !== isRunning || $[7] !== joinStrategy || $[8] !== messages || $[9] !== state.callback || $[10] !== state.callbackCache || $[11] !== state.chunkCache || $[12] !== state.converterCache || $[13] !== state.metadata) {
|
|
219
35
|
const callbackResults = [];
|
|
220
36
|
for (const message of messages) {
|
|
221
37
|
let result = state.callbackCache.get(message);
|
|
222
38
|
if (!result || result.metadata !== state.metadata || result.callback !== state.callback) {
|
|
223
|
-
const output = state.callback(message, state.metadata);
|
|
224
39
|
result = {
|
|
225
|
-
|
|
226
|
-
outputs: toCallbackOutputs(output, message),
|
|
40
|
+
...convertExternalMessageCallback(message, state.callback, state.metadata),
|
|
227
41
|
metadata: state.metadata,
|
|
228
42
|
callback: state.callback
|
|
229
43
|
};
|
|
@@ -231,51 +45,37 @@ const useExternalMessageConverter = (t0) => {
|
|
|
231
45
|
}
|
|
232
46
|
callbackResults.push(result);
|
|
233
47
|
}
|
|
234
|
-
let
|
|
235
|
-
if ($[
|
|
236
|
-
|
|
237
|
-
const key =
|
|
238
|
-
if (!key) return
|
|
48
|
+
let t4;
|
|
49
|
+
if ($[15] !== state.chunkCache) {
|
|
50
|
+
t4 = (message_0) => {
|
|
51
|
+
const key = message_0.outputs[0];
|
|
52
|
+
if (!key) return message_0;
|
|
239
53
|
const cached = state.chunkCache.get(key);
|
|
240
|
-
if (cached && shallowArrayEqual(cached.outputs,
|
|
241
|
-
state.chunkCache.set(key,
|
|
242
|
-
return
|
|
54
|
+
if (cached && shallowArrayEqual(cached.outputs, message_0.outputs)) return cached;
|
|
55
|
+
state.chunkCache.set(key, message_0);
|
|
56
|
+
return message_0;
|
|
243
57
|
};
|
|
244
|
-
$[
|
|
245
|
-
$[
|
|
246
|
-
} else
|
|
247
|
-
const chunks = chunkExternalMessages(callbackResults, joinStrategy).map(
|
|
248
|
-
threadMessages = state.converterCache.convertMessages(chunks, (cache,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const hasPendingToolCalls = typeof joined.content === "object" && joined.content.some(isPendingToolCall);
|
|
253
|
-
const autoStatus = getAutoStatus(isLast, isRunning, hasInterruptedToolCalls, hasPendingToolCalls, isLast ? state.metadata.error : void 0);
|
|
254
|
-
if (cache && (cache.role !== "assistant" || !isAutoStatus(cache.status) || cache.status === autoStatus)) {
|
|
255
|
-
const inputs = getExternalStoreMessages(cache);
|
|
256
|
-
if (shallowArrayEqual(inputs, message_0.inputs)) return cache;
|
|
257
|
-
}
|
|
258
|
-
const newMessage = fromThreadMessageLike(joined, idx.toString(), autoStatus);
|
|
259
|
-
bindExternalStoreMessage(newMessage, message_0.inputs);
|
|
260
|
-
return newMessage;
|
|
261
|
-
});
|
|
58
|
+
$[15] = state.chunkCache;
|
|
59
|
+
$[16] = t4;
|
|
60
|
+
} else t4 = $[16];
|
|
61
|
+
const chunks = chunkExternalMessages(callbackResults, joinStrategy).map(t4);
|
|
62
|
+
const threadMessages = state.converterCache.convertMessages(chunks, (cache, message_1, idx) => convertExternalMessageChunk(message_1, idx, chunks.length, isRunning, state.metadata.error, {
|
|
63
|
+
message: cache,
|
|
64
|
+
generatedFallbackMessages
|
|
65
|
+
}, state.metadata.cancelledMessageIds));
|
|
262
66
|
bindExternalStoreMessage(threadMessages, messages);
|
|
263
|
-
|
|
264
|
-
const lastMessage = threadMessages.at(-1);
|
|
265
|
-
if (!lastMessage || lastMessage.role !== "assistant") threadMessages.push(createErrorAssistantMessage(state.metadata.error));
|
|
266
|
-
}
|
|
67
|
+
t3 = completeExternalMessageConversion(threadMessages, state.metadata.error);
|
|
267
68
|
$[6] = isRunning;
|
|
268
69
|
$[7] = joinStrategy;
|
|
269
70
|
$[8] = messages;
|
|
270
|
-
$[9] = state;
|
|
271
|
-
$[10] =
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return true;
|
|
71
|
+
$[9] = state.callback;
|
|
72
|
+
$[10] = state.callbackCache;
|
|
73
|
+
$[11] = state.chunkCache;
|
|
74
|
+
$[12] = state.converterCache;
|
|
75
|
+
$[13] = state.metadata;
|
|
76
|
+
$[14] = t3;
|
|
77
|
+
} else t3 = $[14];
|
|
78
|
+
return t3;
|
|
279
79
|
};
|
|
280
80
|
function _temp() {
|
|
281
81
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-message-converter.js","names":["c","_c","useMemo","useState","ThreadMessageConverter","getExternalStoreMessages","symbolInnerMessage","bindExternalStoreMessage","fromThreadMessageLike","ThreadMessageLike","getAutoStatus","isAutoStatus","ToolExecutionStatus","ReadonlyJSONValue","generateErrorMessageId","ThreadAssistantMessage","ThreadMessage","ToolCallMessagePart","MessageTiming","JoinStrategy","ThreadMessageLikeContentItem","Exclude","isPendingToolCall","type","result","undefined","isInterruptedToolCall","interrupt","approval","approved","resolution","useExternalMessageConverter","Message","convertConfig","joinStrategy","role","toolCallId","toolName","artifact","isError","messages","Metadata","toolStatuses","Record","error","messageTiming","Callback","message","T","metadata","CallbackResult","input","outputs","stringifyForError","value","text","Error","String","JSON","stringify","length","slice","toCallbackOutputs","output","Array","isArray","o","valid","content","CallbackCacheEntry","callback","ChunkResult","inputs","Mutable","P","mergeInnerMessages","existing","incoming","joinExternalMessages","assistantMessage","Omit","toolCallIdx","findIndex","toolCall","const","map","id","createdAt","status","attachments","unstable_state","unstable_annotations","unstable_data","steps","custom","timing","submittedFeedback","isOptimistic","part","existingIdx","parentId","push","unsupportedRole","chunkExternalMessages","callbackResults","results","isAssistant","pendingNone","flush","callbackResult","at","createErrorAssistantMessage","msg","reason","Date","convertExternalMessages","WeakKey","isRunning","chunks","idx","isLast","joined","hasInterruptedToolCalls","some","hasPendingToolCalls","autoStatus","newMessage","toString","lastMessage","t0","$","caches","_temp","t1","t2","state","threadMessages","callbackCache","get","set","t3","chunkCache","m","key","cached","shallowArrayEqual","converterCache","convertMessages","cache","message_0","a","b","i","WeakMap"],"sources":["../../../src/react/runtimes/external-message-converter.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport { ThreadMessageConverter } from \"../../runtimes/external-store/thread-message-converter\";\nimport {\n getExternalStoreMessages,\n symbolInnerMessage,\n bindExternalStoreMessage,\n} from \"../../runtime/utils/external-store-message\";\nimport {\n fromThreadMessageLike,\n type ThreadMessageLike,\n} from \"../../runtime/utils/thread-message-like\";\nimport { getAutoStatus, isAutoStatus } from \"../../runtime/utils/auto-status\";\nimport type { ToolExecutionStatus } from \"../../runtimes/tool-invocations/ToolInvocationTracker\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { generateErrorMessageId } from \"../../utils/id\";\nimport type {\n ThreadAssistantMessage,\n ThreadMessage,\n ToolCallMessagePart,\n} from \"../../types/message\";\nimport type { MessageTiming } from \"../../types/message\";\n\nexport type JoinStrategy = \"concat-content\" | \"none\";\n\ntype ThreadMessageLikeContentItem = Exclude<\n ThreadMessageLike[\"content\"],\n string\n>[number];\n\nconst isPendingToolCall = (c: ThreadMessageLikeContentItem): boolean =>\n c.type === \"tool-call\" && c.result === undefined;\n\nconst isInterruptedToolCall = (c: ThreadMessageLikeContentItem): boolean => {\n if (c.type !== \"tool-call\" || c.result !== undefined) return false;\n return (\n c.interrupt != null ||\n (c.approval != null &&\n c.approval.approved === undefined &&\n c.approval.resolution === undefined)\n );\n};\n\nexport namespace useExternalMessageConverter {\n export type Message =\n | (ThreadMessageLike & {\n readonly convertConfig?: {\n readonly joinStrategy?: JoinStrategy;\n };\n })\n | {\n role: \"tool\";\n toolCallId: string;\n toolName?: string | undefined;\n result: any;\n artifact?: any;\n isError?: boolean;\n messages?: readonly ThreadMessage[];\n };\n\n export type Metadata = {\n readonly toolStatuses?: Record<string, ToolExecutionStatus>;\n readonly error?: ReadonlyJSONValue;\n readonly messageTiming?: Record<string, MessageTiming>;\n };\n\n export type Callback<T> = (\n message: T,\n metadata: Metadata,\n ) => Message | Message[];\n}\n\ntype CallbackResult<T> = {\n input: T;\n outputs: useExternalMessageConverter.Message[];\n};\n\nconst stringifyForError = (value: unknown) => {\n let text;\n try {\n text = value instanceof Error ? String(value) : JSON.stringify(value);\n } catch {\n /* circular */\n }\n text ??= String(value);\n return text.length > 200 ? `${text.slice(0, 200)}…` : text;\n};\n\nconst toCallbackOutputs = (\n output:\n | useExternalMessageConverter.Message\n | useExternalMessageConverter.Message[],\n input: unknown,\n): useExternalMessageConverter.Message[] => {\n const outputs = Array.isArray(output) ? output : [output];\n for (const o of outputs) {\n const valid =\n typeof o === \"object\" &&\n o !== null &&\n (o.role === \"tool\" ||\n ((o.role === \"assistant\" || o.role === \"user\" || o.role === \"system\") &&\n (typeof o.content === \"string\" || Array.isArray(o.content))));\n if (!valid)\n throw new Error(\n `External message converter: the converter callback returned an invalid message (${stringifyForError(o)}) for input ${stringifyForError(input)}. Return an empty array to skip a message.`,\n );\n }\n return outputs;\n};\n\ntype CallbackCacheEntry<T> = CallbackResult<T> & {\n metadata: useExternalMessageConverter.Metadata;\n callback: useExternalMessageConverter.Callback<T>;\n};\n\ntype ChunkResult<T> = {\n inputs: T[];\n outputs: useExternalMessageConverter.Message[];\n};\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\nconst mergeInnerMessages = (existing: object, incoming: object) => ({\n [symbolInnerMessage]: [\n ...((existing as any)[symbolInnerMessage] ?? []),\n ...((incoming as any)[symbolInnerMessage] ?? []),\n ],\n});\n\nconst joinExternalMessages = (\n messages: readonly useExternalMessageConverter.Message[],\n): ThreadMessageLike => {\n const assistantMessage: Mutable<Omit<ThreadMessageLike, \"metadata\">> & {\n content: Exclude<ThreadMessageLike[\"content\"][0], string>[];\n metadata?: Mutable<ThreadMessageLike[\"metadata\"]>;\n } = {\n role: \"assistant\",\n content: [],\n };\n for (const output of messages) {\n if (output.role === \"tool\") {\n const toolCallIdx = assistantMessage.content.findIndex(\n (c) => c.type === \"tool-call\" && c.toolCallId === output.toolCallId,\n );\n // Ignore orphaned tool results so one bad tool message does not\n // prevent rendering the rest of the conversation.\n if (toolCallIdx !== -1) {\n const toolCall = assistantMessage.content[\n toolCallIdx\n ]! as ToolCallMessagePart;\n if (output.toolName != null) {\n if (toolCall.toolName !== output.toolName)\n throw new Error(\n `Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`,\n );\n }\n assistantMessage.content[toolCallIdx] = {\n ...toolCall,\n ...{\n [symbolInnerMessage]: [\n ...((toolCall as any)[symbolInnerMessage] ?? []),\n output,\n ],\n },\n result: output.result,\n artifact: output.artifact,\n isError: output.isError,\n messages: output.messages,\n };\n }\n } else {\n const role = output.role;\n const content = (\n typeof output.content === \"string\"\n ? [{ type: \"text\" as const, text: output.content }]\n : output.content\n ).map((c) => ({\n ...c,\n ...{ [symbolInnerMessage]: [output] },\n }));\n switch (role) {\n case \"system\":\n case \"user\":\n return {\n ...output,\n content,\n };\n case \"assistant\":\n if (assistantMessage.content.length === 0) {\n assistantMessage.id = output.id;\n assistantMessage.createdAt ??= output.createdAt;\n assistantMessage.status ??= output.status;\n\n if (output.attachments) {\n assistantMessage.attachments = [\n ...(assistantMessage.attachments ?? []),\n ...output.attachments,\n ];\n }\n }\n\n if (output.metadata) {\n assistantMessage.metadata ??= {};\n if (output.metadata.unstable_state !== undefined) {\n assistantMessage.metadata.unstable_state =\n output.metadata.unstable_state;\n }\n if (output.metadata.unstable_annotations) {\n assistantMessage.metadata.unstable_annotations = [\n ...(assistantMessage.metadata.unstable_annotations ?? []),\n ...output.metadata.unstable_annotations,\n ];\n }\n if (output.metadata.unstable_data) {\n assistantMessage.metadata.unstable_data = [\n ...(assistantMessage.metadata.unstable_data ?? []),\n ...output.metadata.unstable_data,\n ];\n }\n if (output.metadata.steps) {\n assistantMessage.metadata.steps = [\n ...(assistantMessage.metadata.steps ?? []),\n ...output.metadata.steps,\n ];\n }\n if (output.metadata.custom) {\n assistantMessage.metadata.custom = {\n ...(assistantMessage.metadata.custom ?? {}),\n ...output.metadata.custom,\n };\n }\n\n if (output.metadata.timing) {\n assistantMessage.metadata.timing = output.metadata.timing;\n }\n\n if (output.metadata.submittedFeedback) {\n assistantMessage.metadata.submittedFeedback =\n output.metadata.submittedFeedback;\n }\n\n if (output.metadata.isOptimistic) {\n assistantMessage.metadata.isOptimistic = true;\n }\n // TODO keep this in sync with ThreadMessageLike[\"metadata\"] / fromThreadMessageLike\n }\n\n // Add content parts, merging reasoning parts with same parentId\n for (const part of content) {\n if (part.type === \"tool-call\") {\n const existingIdx = assistantMessage.content.findIndex(\n (c) =>\n c.type === \"tool-call\" && c.toolCallId === part.toolCallId,\n );\n if (existingIdx !== -1) {\n const existing = assistantMessage.content[\n existingIdx\n ] as typeof part;\n assistantMessage.content[existingIdx] = {\n ...existing,\n ...part,\n ...mergeInnerMessages(existing, part),\n };\n continue;\n }\n }\n\n if (\n part.type === \"reasoning\" &&\n \"parentId\" in part &&\n part.parentId\n ) {\n const existingIdx = assistantMessage.content.findIndex(\n (c) =>\n c.type === \"reasoning\" &&\n \"parentId\" in c &&\n c.parentId === part.parentId,\n );\n if (existingIdx !== -1) {\n const existing = assistantMessage.content[\n existingIdx\n ] as typeof part;\n assistantMessage.content[existingIdx] = {\n ...existing,\n text: `${existing.text}\\n\\n${part.text}`,\n ...mergeInnerMessages(existing, part),\n };\n continue;\n }\n }\n assistantMessage.content.push(part);\n }\n break;\n default: {\n const unsupportedRole: never = role;\n throw new Error(`Unknown message role: ${unsupportedRole}`);\n }\n }\n }\n }\n return assistantMessage;\n};\n\nconst chunkExternalMessages = <T>(\n callbackResults: CallbackResult<T>[],\n joinStrategy?: JoinStrategy,\n) => {\n const results: ChunkResult<T>[] = [];\n let isAssistant = false;\n let pendingNone = false; // true if the previous assistant message had joinStrategy \"none\"\n let inputs: T[] = [];\n let outputs: useExternalMessageConverter.Message[] = [];\n\n const flush = () => {\n if (outputs.length) {\n results.push({\n inputs,\n outputs,\n });\n }\n inputs = [];\n outputs = [];\n isAssistant = false;\n pendingNone = false;\n };\n\n for (const callbackResult of callbackResults) {\n for (const output of callbackResult.outputs) {\n if (\n (pendingNone && output.role !== \"tool\") ||\n !isAssistant ||\n output.role === \"user\" ||\n output.role === \"system\"\n ) {\n flush();\n }\n isAssistant = output.role === \"assistant\" || output.role === \"tool\";\n\n if (inputs.at(-1) !== callbackResult.input) {\n inputs.push(callbackResult.input);\n }\n outputs.push(output);\n\n if (\n output.role === \"assistant\" &&\n (output.convertConfig?.joinStrategy === \"none\" ||\n joinStrategy === \"none\")\n ) {\n pendingNone = true;\n }\n }\n }\n flush();\n return results;\n};\n\nfunction createErrorAssistantMessage(\n error: ReadonlyJSONValue,\n): ThreadAssistantMessage {\n const msg: ThreadAssistantMessage = {\n id: generateErrorMessageId(),\n role: \"assistant\",\n content: [],\n status: { type: \"incomplete\", reason: \"error\", error },\n createdAt: new Date(),\n metadata: {\n unstable_state: null,\n unstable_annotations: [],\n unstable_data: [],\n custom: {},\n steps: [],\n },\n };\n bindExternalStoreMessage(msg, []);\n return msg;\n}\n\nexport const convertExternalMessages = <T extends WeakKey>(\n messages: T[],\n callback: useExternalMessageConverter.Callback<T>,\n isRunning: boolean,\n metadata: useExternalMessageConverter.Metadata,\n) => {\n const callbackResults: CallbackResult<T>[] = [];\n for (const message of messages) {\n const output = callback(message, metadata);\n const outputs = toCallbackOutputs(output, message);\n const result = { input: message, outputs };\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults);\n\n const result = chunks.map((message, idx) => {\n const isLast = idx === chunks.length - 1;\n const joined = joinExternalMessages(message.outputs);\n const hasInterruptedToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isInterruptedToolCall);\n const hasPendingToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isPendingToolCall);\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n hasInterruptedToolCalls,\n hasPendingToolCalls,\n isLast ? metadata.error : undefined,\n );\n const newMessage = fromThreadMessageLike(\n joined,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, message.inputs);\n return newMessage;\n });\n\n if (metadata.error) {\n const lastMessage = result.at(-1);\n if (!lastMessage || lastMessage.role !== \"assistant\") {\n result.push(createErrorAssistantMessage(metadata.error));\n }\n }\n\n return result;\n};\n\nexport const useExternalMessageConverter = <T extends WeakKey>({\n callback,\n messages,\n isRunning,\n joinStrategy,\n metadata,\n}: {\n callback: useExternalMessageConverter.Callback<T>;\n messages: T[];\n isRunning: boolean;\n joinStrategy?: JoinStrategy | undefined;\n metadata?: useExternalMessageConverter.Metadata | undefined;\n}) => {\n // The caches live for the component lifetime; React Compiler hoists\n // allocations without reactive dependencies out of useMemo, so re-creating\n // them on dependency change would not survive compilation. Staleness is\n // instead tracked per entry via the metadata/callback that produced it,\n // keeping correctness independent of memoization (which React treats as\n // droppable). A \"use no memo\" opt-out would restore the useMemo semantics\n // but leave cache flushing coupled to memo firing.\n const [caches] = useState(() => ({\n callbackCache: new WeakMap<T, CallbackCacheEntry<T>>(),\n chunkCache: new WeakMap<\n useExternalMessageConverter.Message,\n ChunkResult<T>\n >(),\n converterCache: new ThreadMessageConverter(),\n }));\n\n const state = useMemo(\n () => ({\n metadata: metadata ?? {},\n callback,\n ...caches,\n }),\n [callback, metadata, caches],\n );\n\n return useMemo(() => {\n const callbackResults: CallbackResult<T>[] = [];\n for (const message of messages) {\n let result = state.callbackCache.get(message);\n if (\n !result ||\n result.metadata !== state.metadata ||\n result.callback !== state.callback\n ) {\n const output = state.callback(message, state.metadata);\n const outputs = toCallbackOutputs(output, message);\n result = {\n input: message,\n outputs,\n metadata: state.metadata,\n callback: state.callback,\n };\n state.callbackCache.set(message, result);\n }\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults, joinStrategy).map(\n (m) => {\n const key = m.outputs[0];\n if (!key) return m;\n\n const cached = state.chunkCache.get(key);\n if (cached && shallowArrayEqual(cached.outputs, m.outputs))\n return cached;\n state.chunkCache.set(key, m);\n return m;\n },\n );\n\n const threadMessages = state.converterCache.convertMessages(\n chunks,\n (cache, message, idx) => {\n const isLast = idx === chunks.length - 1;\n\n const joined = joinExternalMessages(message.outputs);\n const hasInterruptedToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isInterruptedToolCall);\n const hasPendingToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isPendingToolCall);\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n hasInterruptedToolCalls,\n hasPendingToolCalls,\n isLast ? state.metadata.error : undefined,\n );\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n ) {\n const inputs = getExternalStoreMessages<T>(cache);\n if (shallowArrayEqual(inputs, message.inputs)) {\n return cache;\n }\n }\n\n const newMessage = fromThreadMessageLike(\n joined,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, message.inputs);\n return newMessage;\n },\n );\n\n bindExternalStoreMessage(threadMessages, messages);\n\n if (state.metadata.error) {\n const lastMessage = threadMessages.at(-1);\n if (!lastMessage || lastMessage.role !== \"assistant\") {\n threadMessages.push(createErrorAssistantMessage(state.metadata.error));\n }\n }\n\n return threadMessages;\n }, [state, messages, isRunning, joinStrategy]);\n};\n\nconst shallowArrayEqual = (a: unknown[], b: unknown[]) => {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n};\n"],"mappings":";;;;;;;;;AA+BA,MAAMsB,qBAAqBtB,MACzBA,EAAEuB,SAAS,eAAevB,EAAEwB,WAAWC,KAAAA;AAEzC,MAAMC,yBAAyB1B,MAA6C;CAC1E,IAAIA,EAAEuB,SAAS,eAAevB,EAAEwB,WAAWC,KAAAA,GAAW,OAAO;CAC7D,OACEzB,EAAE2B,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B,MAAO,GAAC,OACpC4E;GACR;GAGH,MAAAtB,aAAmBtH,sBACjBiH,QACAF,IAAGQ,SAAU,GACbF,UACF;GACAtH,yBAAyBuH,YAAY/E,UAAOyB,MAAO;GAAC,OAC7CsD;EAAU,CAErB;EAEAvH,yBAAyBiI,gBAAgBhG,QAAQ;EAEjD,IAAI+F,MAAKtF,SAASL,OAAM;GACtB,MAAAoF,cAAoBQ,eAAc1B,GAAI,EAAE;GACxC,IAAI,CAACkB,eAAeA,YAAW7F,SAAU,aACvCqG,eAAcnC,KAAMU,4BAA4BwB,MAAKtF,SAASL,KAAM,CAAC;EACtE;EACFsF,EAAA,KAAAb;EAAAa,EAAA,KAAAhG;EAAAgG,EAAA,KAAA1F;EAAA0F,EAAA,KAAAK;EAAAL,EAAA,MAAAM;CAAA,OAAAA,iBAAAN,EAAA;CAAA,OAEDM;AAAsB;AAI1B,MAAMS,qBAAqBK,GAAcC,MAAiB;CACxD,IAAID,EAAE1F,WAAW2F,EAAE3F,QAAQ,OAAO;CAClC,KAAK,IAAI4F,IAAI,GAAGA,IAAIF,EAAE1F,QAAQ4F,KAC5B,IAAIF,EAAEE,OAAOD,EAAEC,IAAI,OAAO;CAE5B,OAAO;AACT;AAtI2C,SAAApB,QAAA;CAAA,OAoBR;EAAAK,+BAChB,IAAIgB,QAAkC;EAACZ,4BAC1C,IAAIY,QAGd;EAACP,gBACa,IAAI9I,uBAAuB;CAC7C;AAAC"}
|
|
1
|
+
{"version":3,"file":"external-message-converter.js","names":["c","_c","useMemo","useState","chunkExternalMessages","completeExternalMessageConversion","convertExternalMessageCallback","convertExternalMessageChunk","convertExternalMessages","convertExternalMessagesInternal","shallowArrayEqual","ExternalMessageConverterCallback","ExternalMessageConverterCallbackResult","ExternalMessageConverterChunk","ExternalMessageConverterMessage","ExternalMessageConverterMetadata","JoinStrategy","bindExternalStoreMessage","ThreadMessageConverter","ThreadMessage","generatedFallbackMessages","WeakSet","useExternalMessageConverter","Message","Metadata","Callback","T","WeakKey","messages","callback","isRunning","metadata","CallbackCacheEntry","t0","$","joinStrategy","caches","_temp","t1","t2","state","t3","callbackCache","chunkCache","converterCache","callbackResults","message","result","get","set","push","t4","message_0","key","outputs","cached","chunks","map","threadMessages","convertMessages","cache","message_1","idx","length","error","cancelledMessageIds","WeakMap"],"sources":["../../../src/react/runtimes/external-message-converter.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport {\n chunkExternalMessages,\n completeExternalMessageConversion,\n convertExternalMessageCallback,\n convertExternalMessageChunk,\n convertExternalMessages as convertExternalMessagesInternal,\n shallowArrayEqual,\n type ExternalMessageConverterCallback,\n type ExternalMessageConverterCallbackResult,\n type ExternalMessageConverterChunk,\n type ExternalMessageConverterMessage,\n type ExternalMessageConverterMetadata,\n type JoinStrategy,\n} from \"../../runtime/utils/external-message-conversion\";\nimport { bindExternalStoreMessage } from \"../../runtime/utils/external-store-message\";\nimport { ThreadMessageConverter } from \"../../runtimes/external-store/thread-message-converter\";\nimport type { ThreadMessage } from \"../../types/message\";\n\n// Generatedness is tracked by identity, not by id shape: a caller-supplied id\n// that happens to match the generated pattern must never be rewritten.\nconst generatedFallbackMessages = new WeakSet<object>();\n\nexport type { JoinStrategy };\n\nexport namespace useExternalMessageConverter {\n export type Message = ExternalMessageConverterMessage;\n export type Metadata = ExternalMessageConverterMetadata;\n export type Callback<T> = ExternalMessageConverterCallback<T>;\n}\n\nexport const convertExternalMessages: <T extends WeakKey>(\n messages: T[],\n callback: useExternalMessageConverter.Callback<T>,\n isRunning: boolean,\n metadata: useExternalMessageConverter.Metadata,\n) => ThreadMessage[] = convertExternalMessagesInternal;\n\ntype CallbackCacheEntry<T> = ExternalMessageConverterCallbackResult<T> & {\n metadata: useExternalMessageConverter.Metadata;\n callback: useExternalMessageConverter.Callback<T>;\n};\n\nexport const useExternalMessageConverter = <T extends WeakKey>({\n callback,\n messages,\n isRunning,\n joinStrategy,\n metadata,\n}: {\n callback: useExternalMessageConverter.Callback<T>;\n messages: T[];\n isRunning: boolean;\n joinStrategy?: JoinStrategy | undefined;\n metadata?: useExternalMessageConverter.Metadata | undefined;\n}) => {\n // The caches live for the component lifetime; React Compiler hoists\n // allocations without reactive dependencies out of useMemo, so re-creating\n // them on dependency change would not survive compilation. Staleness is\n // instead tracked per entry via the metadata/callback that produced it,\n // keeping correctness independent of memoization (which React treats as\n // droppable). A \"use no memo\" opt-out would restore the useMemo semantics\n // but leave cache flushing coupled to memo firing.\n const [caches] = useState(() => ({\n callbackCache: new WeakMap<T, CallbackCacheEntry<T>>(),\n chunkCache: new WeakMap<\n ExternalMessageConverterMessage,\n ExternalMessageConverterChunk<T>\n >(),\n converterCache: new ThreadMessageConverter(),\n }));\n\n const state = useMemo(\n () => ({\n metadata: metadata ?? {},\n callback,\n ...caches,\n }),\n [callback, metadata, caches],\n );\n\n return useMemo(() => {\n const callbackResults: ExternalMessageConverterCallbackResult<T>[] = [];\n for (const message of messages) {\n let result = state.callbackCache.get(message);\n if (\n !result ||\n result.metadata !== state.metadata ||\n result.callback !== state.callback\n ) {\n result = {\n ...convertExternalMessageCallback(\n message,\n state.callback,\n state.metadata,\n ),\n metadata: state.metadata,\n callback: state.callback,\n };\n state.callbackCache.set(message, result);\n }\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults, joinStrategy).map(\n (message) => {\n const key = message.outputs[0];\n if (!key) return message;\n\n const cached = state.chunkCache.get(key);\n if (cached && shallowArrayEqual(cached.outputs, message.outputs)) {\n return cached;\n }\n state.chunkCache.set(key, message);\n return message;\n },\n );\n\n const threadMessages = state.converterCache.convertMessages(\n chunks,\n (cache, message, idx) =>\n convertExternalMessageChunk(\n message,\n idx,\n chunks.length,\n isRunning,\n state.metadata.error,\n {\n message: cache,\n generatedFallbackMessages,\n },\n state.metadata.cancelledMessageIds,\n ),\n );\n\n bindExternalStoreMessage(threadMessages, messages);\n return completeExternalMessageConversion(\n threadMessages,\n state.metadata.error,\n );\n }, [state, messages, isRunning,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AC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRemoteThreadListRuntime.d.ts","names":[],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"useRemoteThreadListRuntime.d.ts","names":[],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"mappings":";;;cAiDa,6BACX,SAAS,4BACR"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { WritableSubscribable } from "../../subscribable/subscribable.js";
|
|
1
2
|
import { BaseAssistantRuntimeCore } from "../../runtime/base/base-assistant-runtime-core.js";
|
|
2
3
|
import { AssistantRuntimeImpl } from "../../runtime/api/assistant-runtime.js";
|
|
4
|
+
import { useSubscribable } from "../../store/runtime-clients/useSubscribable.js";
|
|
3
5
|
import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore.js";
|
|
4
6
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
5
7
|
import { useCallback, useEffect, useEffectEvent, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
@@ -51,12 +53,18 @@ const useRemoteThreadListRuntimeImpl = (options) => {
|
|
|
51
53
|
return t3;
|
|
52
54
|
};
|
|
53
55
|
const useRemoteThreadListRuntime = (options) => {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
+
const [runtimeHookStore] = useState(() => new WritableSubscribable(options.runtimeHook));
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
runtimeHookStore.setState(options.runtimeHook);
|
|
59
|
+
}, [runtimeHookStore, options.runtimeHook]);
|
|
56
60
|
const initialThreadIdRef = useRef(options.initialThreadId);
|
|
57
|
-
const stableRuntimeHook = useCallback(()
|
|
58
|
-
return
|
|
59
|
-
|
|
61
|
+
const stableRuntimeHook = useCallback(function useCommittedRuntimeHook() {
|
|
62
|
+
return useSubscribable({
|
|
63
|
+
subscribe: runtimeHookStore.subscribe,
|
|
64
|
+
getState: runtimeHookStore.getState,
|
|
65
|
+
getServerSnapshot: runtimeHookStore.getState
|
|
66
|
+
})();
|
|
67
|
+
}, [runtimeHookStore]);
|
|
60
68
|
const onThreadIdChange = useEffectEvent((threadId) => {
|
|
61
69
|
options.onThreadIdChange?.(threadId);
|
|
62
70
|
});
|
|
@@ -75,7 +83,7 @@ const useRemoteThreadListRuntime = (options) => {
|
|
|
75
83
|
]);
|
|
76
84
|
if (useAui().threadListItem.source !== null) {
|
|
77
85
|
if (!stableOptions.allowNesting) throw new Error("useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. Set allowNesting: true to allow nesting (the inner runtime will become a no-op).");
|
|
78
|
-
return
|
|
86
|
+
return options.runtimeHook();
|
|
79
87
|
}
|
|
80
88
|
return useRemoteThreadListRuntimeImpl(stableOptions);
|
|
81
89
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRemoteThreadListRuntime.js","names":["useState","useEffect","useMemo","useRef","useCallback","useEffectEvent","BaseAssistantRuntimeCore","AssistantRuntimeImpl","RemoteThreadListOptions","AssistantRuntimeCore","AssistantRuntime","RemoteThreadListThreadListRuntimeCore","useAui","RemoteThreadListRuntimeCore","threads","constructor","options","_contextProvider","RenderComponent","__internal_RenderComponent","useRemoteThreadListRuntimeImpl","$","_c","t0","runtime","t1","__internal_setOptions","__internal_load","t2","t3","useRemoteThreadListRuntime","
|
|
1
|
+
{"version":3,"file":"useRemoteThreadListRuntime.js","names":["useState","useEffect","useMemo","useRef","useCallback","useEffectEvent","BaseAssistantRuntimeCore","AssistantRuntimeImpl","RemoteThreadListOptions","AssistantRuntimeCore","AssistantRuntime","RemoteThreadListThreadListRuntimeCore","WritableSubscribable","useSubscribable","useAui","RemoteThreadListRuntimeCore","threads","constructor","options","_contextProvider","RenderComponent","__internal_RenderComponent","useRemoteThreadListRuntimeImpl","$","_c","t0","runtime","t1","__internal_setOptions","__internal_load","t2","t3","useRemoteThreadListRuntime","runtimeHookStore","runtimeHook","setState","initialThreadIdRef","initialThreadId","stableRuntimeHook","useCommittedRuntimeHook","subscribe","getState","getServerSnapshot","onThreadIdChange","threadId","stableOptions","adapter","allowNesting","current","aui","isNested","threadListItem","source","Error"],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"sourcesContent":["import {\n useState,\n useEffect,\n useMemo,\n useRef,\n useCallback,\n useEffectEvent,\n} from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../../runtime/base/base-assistant-runtime-core\";\nimport { AssistantRuntimeImpl } from \"../../runtime/api/assistant-runtime\";\nimport type { RemoteThreadListOptions } from \"../../runtimes/remote-thread-list/types\";\nimport type { AssistantRuntimeCore } from \"../../runtime/interfaces/assistant-runtime-core\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { WritableSubscribable } from \"../../subscribable/subscribable\";\nimport { useSubscribable } from \"../../store/runtime-clients/useSubscribable\";\nimport { useAui } from \"@assistant-ui/store\";\n\nclass RemoteThreadListRuntimeCore\n extends BaseAssistantRuntimeCore\n implements AssistantRuntimeCore\n{\n public readonly threads;\n\n constructor(options: RemoteThreadListOptions) {\n super();\n this.threads = new RemoteThreadListThreadListRuntimeCore(\n options,\n this._contextProvider,\n );\n }\n\n public get RenderComponent() {\n return this.threads.__internal_RenderComponent;\n }\n}\n\nconst useRemoteThreadListRuntimeImpl = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));\n useEffect(() => {\n runtime.threads.__internal_setOptions(options);\n runtime.threads.__internal_load();\n }, [runtime, options]);\n\n return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const useRemoteThreadListRuntime = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const [runtimeHookStore] = useState(\n () => new WritableSubscribable(options.runtimeHook),\n );\n useEffect(() => {\n runtimeHookStore.setState(options.runtimeHook);\n }, [runtimeHookStore, options.runtimeHook]);\n\n const initialThreadIdRef = useRef(options.initialThreadId);\n\n // Thread resources subscribe to the store rather than reading a ref, so a\n // hook published at commit reaches exactly the resources that use it and an\n // abandoned render publishes nothing. The store pins its server snapshot to\n // the constructor value for hydration, which tap reads on any never-mounted\n // fiber, so the live state serves as the server snapshot here.\n const stableRuntimeHook = useCallback(\n function useCommittedRuntimeHook() {\n return useSubscribable({\n subscribe: runtimeHookStore.subscribe,\n getState: runtimeHookStore.getState,\n getServerSnapshot: runtimeHookStore.getState,\n })();\n },\n [runtimeHookStore],\n );\n\n const onThreadIdChange = useEffectEvent((threadId: string | undefined) => {\n options.onThreadIdChange?.(threadId);\n });\n\n const stableOptions = useMemo<RemoteThreadListOptions>(\n () => ({\n adapter: options.adapter,\n allowNesting: options.allowNesting,\n threadId: options.threadId,\n initialThreadId: initialThreadIdRef.current,\n runtimeHook: stableRuntimeHook,\n onThreadIdChange,\n }),\n [\n options.adapter,\n options.allowNesting,\n options.threadId,\n stableRuntimeHook,\n ],\n );\n\n const aui = useAui();\n const isNested = aui.threadListItem.source !== null;\n\n if (isNested) {\n if (!stableOptions.allowNesting) {\n throw new Error(\n \"useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. \" +\n \"Set allowNesting: true to allow nesting (the inner runtime will become a no-op).\",\n );\n }\n\n // If allowNesting is true and already inside a thread list context,\n // just call the runtimeHook directly (no-op behavior)\n return options.runtimeHook();\n }\n\n const runtime = useRemoteThreadListRuntimeImpl(stableOptions);\n\n return runtime;\n};\n"],"mappings":";;;;;;;;;AAkBA,IAAMe,8BAAN,cACUT,yBAEV;CACE;CAEAW,YAAYC,SAAkC;EAC5C,MAAM;EACN,KAAKF,UAAU,IAAIL,sCACjBO,SACA,KAAKC,gBACP;CACF;CAEA,IAAWC,kBAAkB;EAC3B,OAAO,KAAKJ,QAAQK;CACtB;AACF;AAEA,MAAMC,kCAAiCJ,YAAA;CAAA,MAAAK,I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GAC3BC,mBAAmBT,iBAAiBQ;EACtC,CAAC,CAAC,CAAC;CACL,GACA,CAACR,gBAAgB,CACnB;CAEA,MAAMU,mBAAmBtC,gBAAgBuC,aAAiC;EACxE1B,QAAQyB,mBAAmBC,QAAQ;CACrC,CAAC;CAED,MAAMC,gBAAgB3C,eACb;EACL4C,SAAS5B,QAAQ4B;EACjBC,cAAc7B,QAAQ6B;EACtBH,UAAU1B,QAAQ0B;EAClBP,iBAAiBD,mBAAmBY;EACpCd,aAAaI;EACbK;CACF,IACA;EACEzB,QAAQ4B;EACR5B,QAAQ6B;EACR7B,QAAQ0B;EACRN;CAAiB,CAErB;CAKA,IAHYxB,OACKmC,CAAG,CAACE,eAAeC,WAAW,MAEjC;EACZ,IAAI,CAACP,cAAcE,cACjB,MAAM,IAAIM,MACR,sKAEF;EAKF,OAAOnC,QAAQgB,YAAY;CAC7B;CAIA,OAFgBZ,+BAA+BuB,aAExCnB;AACT"}
|
|
@@ -52,10 +52,14 @@ type ToolCallMessagePartProps<TArgs = any, TResult = unknown> = MessagePartState
|
|
|
52
52
|
/**
|
|
53
53
|
* Responds to a server-side tool approval gate. Only valid while
|
|
54
54
|
* `approval` is set on the part, `approval.approved === undefined`, and
|
|
55
|
-
* no `approval.resolution` is recorded. Accepts a boolean decision
|
|
56
|
-
* id of one of `approval.options
|
|
55
|
+
* no `approval.resolution` is recorded. Accepts a boolean decision, the
|
|
56
|
+
* id of one of `approval.options` (option kinds resolve to the boolean),
|
|
57
|
+
* or a free-form answer when the request accepts one.
|
|
58
|
+
*
|
|
59
|
+
* Resolves once the runtime has accepted the response, and rejects when
|
|
60
|
+
* it could not be recorded, so the controls can stay retryable.
|
|
57
61
|
*/
|
|
58
|
-
respondToApproval: (response: ToolApprovalResponse) => void
|
|
62
|
+
respondToApproval: (response: ToolApprovalResponse) => Promise<void>;
|
|
59
63
|
};
|
|
60
64
|
/** Component used to render a tool-call message part. */
|
|
61
65
|
type ToolCallMessagePartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallMessagePartProps<TArgs, TResult>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessagePartComponentTypes.d.ts","names":[],"sources":["../../../src/react/types/MessagePartComponentTypes.ts"],"mappings":";;;;;;;KAmBY;EACV,QAAQ;;KAEE,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;KAEzC,4BAA4B,mBAAmB;KAC/C,gCACV,cAAc;KAEJ,sBAAsB;EAChC;EACA;;KAEU,0BAA0B,cAAc;KAExC,yBAAyB,mBAAmB;KAC5C,6BAA6B,cAAc;KAE3C,wBAAwB,mBAAmB;KAC3C,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;;;;;KAMzC,iCAAiC,mBAC3C;;;;;KAKU,qCACV,cAAc;KAEJ,qBAAqB,WAAW,mBAC1C,gBAAgB;KACN,yBAAyB,WAAW,cAC9C,qBAAqB;KAGX,yBACV,aACA,qBACE,mBACF,oBAAoB,OAAO;;;;;;;EAOzB,YAAY,QAAQ,UAAU,aAAa;;;;;EAK3C,SAAS
|
|
1
|
+
{"version":3,"file":"MessagePartComponentTypes.d.ts","names":[],"sources":["../../../src/react/types/MessagePartComponentTypes.ts"],"mappings":";;;;;;;KAmBY;EACV,QAAQ;;KAEE,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;KAEzC,4BAA4B,mBAAmB;KAC/C,gCACV,cAAc;KAEJ,sBAAsB;EAChC;EACA;;KAEU,0BAA0B,cAAc;KAExC,yBAAyB,mBAAmB;KAC5C,6BAA6B,cAAc;KAE3C,wBAAwB,mBAAmB;KAC3C,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;;;;;KAMzC,iCAAiC,mBAC3C;;;;;KAKU,qCACV,cAAc;KAEJ,qBAAqB,WAAW,mBAC1C,gBAAgB;KACN,yBAAyB,WAAW,cAC9C,qBAAqB;KAGX,yBACV,aACA,qBACE,mBACF,oBAAoB,OAAO;;;;;;;EAOzB,YAAY,QAAQ,UAAU,aAAa;;;;;EAK3C,SAAS;;;;;;;;;;;EAWT,oBAAoB,UAAU,yBAAyB;;;KAI/C,6BACV,aACA,iBACE,cAAc,yBAAyB,OAAO;KAEtC,wBAAwB;KACxB,4BAA4B,cAAc;;;;;;;;;KAU1C,gCAAgC,eAAe;KAE/C,+BAA+B,mBACzC;KACU,mCACV,cAAc;KAEJ;;EAEV,MAAM;;EAEN,YAAY;;EAEZ,WAAW;IAAgB;IAAmB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Unsubscribe } from "../../../types/unsubscribe.js";
|
|
2
|
+
import { ToolCallText } from "../../../model-context/tool-call-text.js";
|
|
2
3
|
import { ToolCallMessagePartComponent } from "../MessagePartComponentTypes.js";
|
|
3
4
|
import "../../../index.js";
|
|
4
5
|
//#region src/react/types/scopes/tools.d.ts
|
|
@@ -12,6 +13,7 @@ type McpAppResourceOutput = {
|
|
|
12
13
|
*/
|
|
13
14
|
type ToolRegistration = {
|
|
14
15
|
readonly render: ToolCallMessagePartComponent;
|
|
16
|
+
readonly renderText?: ToolCallText<any, any, unknown> | undefined;
|
|
15
17
|
/** Whether this UI renders standalone, outside the chain-of-thought trace. */
|
|
16
18
|
readonly standalone: boolean;
|
|
17
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","names":[],"sources":["../../../../src/react/types/scopes/tools.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools.d.ts","names":[],"sources":["../../../../src/react/types/scopes/tools.ts"],"mappings":";;;;;KAIY;WACD,QAAQ;;;;;;;KAQd;WACM,QAAQ;WACR,aAAa;;WAEb;;KAGC;;EAEV,SAAS,wBAAwB;EACjC,SAAS;;KAGC;EACV,YAAY;EACZ,UACE,kBACA,QAAQ,8BACR;IAAY;MACX;;KAGO;EACV,SAAS"}
|
|
@@ -2,8 +2,8 @@ import { MessageRole, RunConfig } from "../../types/message.js";
|
|
|
2
2
|
import { Attachment, CreateAttachment } from "../../types/attachment.js";
|
|
3
3
|
import { Unsubscribe } from "../../types/unsubscribe.js";
|
|
4
4
|
import { QuoteInfo } from "../../types/quote.js";
|
|
5
|
+
import { QueueItemState } from "../queue/queue-item.js";
|
|
5
6
|
import { QueuePlacement } from "../queue/external-thread-queue-adapter.js";
|
|
6
|
-
import { QueueItemState } from "../../store/scopes/queue-item.js";
|
|
7
7
|
import { ComposerRuntimeEventCallback, ComposerRuntimeEventType, DictationState, SendOptions } from "../interfaces/composer-runtime-core.js";
|
|
8
8
|
import { ComposerRuntimePath } from "./paths.js";
|
|
9
9
|
import { ComposerRuntimeCoreBinding, EditComposerRuntimeCoreBinding, ThreadComposerRuntimeCoreBinding } from "./bindings.js";
|