@assistant-ui/core 0.3.16 → 0.3.18
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/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -2
- package/dist/internal.js +4 -2
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +10 -4
- 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 +101 -28
- 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 +16 -9
- 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/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/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/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 +63 -57
- 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 +25 -28
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/RemoteThreadList.d.ts +16 -0
- package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
- package/dist/react/client/RemoteThreadList.js +354 -242
- 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 +24 -18
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/interactables-legacy/Interactables.js +246 -125
- package/dist/react/interactables-legacy/Interactables.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/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/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/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/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/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/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 +6 -4
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +59 -29
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +11 -6
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +160 -143
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.d.ts +2 -6
- package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.js +15 -13
- package/dist/react/runtimes/RemoteThreadResource.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 +4 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +424 -52
- 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 +160 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.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/external-message-converter.js +1 -1
- 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 +77 -29
- 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/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-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 +12 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +23 -14
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +5 -1
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.js +1 -1
- package/dist/runtime/api/thread-runtime.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +16 -12
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +2 -2
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +8 -7
- 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 +18 -3
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +15 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/utils/auto-status.d.ts +1 -1
- package/dist/runtime/utils/auto-status.d.ts.map +1 -1
- package/dist/runtime/utils/auto-status.js +6 -2
- package/dist/runtime/utils/auto-status.js.map +1 -1
- package/dist/runtime/utils/external-message-conversion.d.ts +3 -2
- package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -1
- package/dist/runtime/utils/external-message-conversion.js +5 -4
- 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 +15 -6
- package/dist/runtime/utils/message-repository.js.map +1 -1
- 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 +2 -10
- package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.js +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.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 +2 -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 +34 -28
- 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/internal.d.ts +2 -2
- 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 +3 -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 +148 -43
- 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 +11 -0
- package/dist/runtimes/remote-thread-list/title.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/title.js +14 -0
- package/dist/runtimes/remote-thread-list/title.js.map +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts +16 -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 +97 -60
- 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 +30 -7
- 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 +2 -1
- 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 +19 -6
- 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 +2 -1
- 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.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 +98 -62
- 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 +2 -2
- 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 +128 -107
- 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 +194 -122
- package/dist/store/runtime-clients/thread-runtime-client.js.map +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/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/part.d.ts +6 -3
- package/dist/store/scopes/part.d.ts.map +1 -1
- 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 +8 -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 +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/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/message.d.ts +40 -1
- 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/abortable-iterable.d.ts +19 -0
- package/dist/utils/abortable-iterable.d.ts.map +1 -0
- package/dist/utils/abortable-iterable.js +72 -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/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/package.json +12 -17
- package/src/adapters/attachment.test.ts +50 -1
- package/src/adapters/attachment.ts +7 -4
- package/src/index.ts +7 -1
- package/src/internal.ts +12 -0
- package/src/model-context/frame/host.test.ts +24 -0
- package/src/model-context/frame/host.ts +10 -4
- package/src/model-context/frame/provider.test.ts +288 -1
- package/src/model-context/frame/provider.ts +148 -30
- package/src/model-context/interactable-composer-metadata.test.ts +28 -0
- package/src/model-context/interactable-composer-metadata.ts +9 -3
- package/src/model-context/registry.test.ts +12 -0
- package/src/model-context/registry.ts +3 -2
- package/src/model-context/tool-call-text.test.ts +67 -0
- package/src/model-context/tool-call-text.ts +67 -0
- package/src/model-context/types.test.ts +25 -0
- package/src/model-context/types.ts +9 -4
- package/src/react/AssistantRuntimeProvider.test.tsx +66 -2
- package/src/react/RuntimeAdapter.test.ts +34 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +1 -3
- package/src/react/client/InMemoryThreadList.ts +1 -0
- package/src/react/client/Interactables.test.ts +28 -0
- package/src/react/client/Interactables.ts +15 -13
- package/src/react/client/RemoteThreadList.background.test.ts +526 -0
- package/src/react/client/RemoteThreadList.concurrent.test.tsx +315 -0
- package/src/react/client/RemoteThreadList.test.ts +617 -3
- package/src/react/client/RemoteThreadList.ts +433 -167
- package/src/react/client/Tools.ts +29 -12
- package/src/react/index.ts +4 -0
- package/src/react/interactables-legacy/Interactables.ts +16 -16
- package/src/react/interactables-shared/useInteractablePersistenceQueue.ts +9 -10
- package/src/react/model-context/makeAssistantTool.ts +2 -2
- 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/useAssistantTool.ts +2 -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/model-context/useToolArgsStatus.test.tsx +30 -0
- package/src/react/model-context/useToolArgsStatus.ts +2 -1
- 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.destroy.test.tsx +172 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +127 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +7 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +99 -35
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.load-error.test.ts +132 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.switch-delete.test.ts +274 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +223 -152
- package/src/react/runtimes/RemoteThreadResource.test.ts +9 -0
- package/src/react/runtimes/RemoteThreadResource.ts +20 -16
- 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 +546 -5
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +546 -103
- package/src/react/runtimes/cloud/auiV0.ts +5 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +103 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +237 -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.ts +1 -0
- 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.concurrent.test.tsx +216 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.load-error.test.tsx +108 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +57 -6
- package/src/react/types/MessagePartComponentTypes.ts +7 -3
- package/src/react/types/scopes/tools.ts +2 -0
- package/src/runtime/api/message-part-runtime.ts +3 -3
- 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 +46 -12
- package/src/runtime/api/thread-runtime.test.ts +78 -0
- package/src/runtime/api/thread-runtime.ts +8 -1
- package/src/runtime/base/base-composer-runtime-core.ts +36 -8
- package/src/runtime/base/base-thread-runtime-core.test.ts +149 -4
- package/src/runtime/base/base-thread-runtime-core.ts +16 -8
- package/src/runtime/interfaces/composer-runtime-core.ts +10 -5
- package/src/runtime/interfaces/thread-list-runtime-core.ts +25 -2
- package/src/runtime/interfaces/thread-runtime-core.ts +17 -1
- package/src/runtime/utils/auto-status.test.ts +57 -0
- package/src/runtime/utils/auto-status.ts +13 -1
- package/src/runtime/utils/external-message-conversion.test.ts +165 -0
- package/src/runtime/utils/external-message-conversion.ts +18 -2
- package/src/runtime/utils/message-repository.ts +29 -17
- 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 +3 -11
- 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 +18 -13
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +56 -33
- package/src/runtimes/inert/InertThreadRuntimeCore.ts +1 -1
- package/src/runtimes/internal.ts +1 -0
- package/src/runtimes/local/local-thread-runtime-core.test.ts +29 -3
- package/src/runtimes/local/local-thread-runtime-core.ts +5 -1
- package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +238 -0
- package/src/runtimes/remote-thread-list/remote-thread-state.ts +223 -44
- 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 +16 -0
- package/src/runtimes/remote-thread-list/types.ts +16 -5
- package/src/runtimes/tool-invocations/EDGE_CASES.md +110 -5
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +750 -136
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +144 -91
- package/src/store/clients/external-thread.ts +62 -11
- 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 +195 -1
- package/src/store/clients/suggestions.ts +45 -34
- 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/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 +17 -2
- package/src/store/runtime-clients/thread-runtime-client.ts +58 -10
- package/src/store/runtime-clients/useSubscribable.ts +8 -2
- package/src/store/scopes/composer.ts +16 -4
- package/src/store/scopes/message.ts +14 -0
- package/src/store/scopes/part.ts +6 -3
- package/src/store/scopes/thread-list-item.ts +5 -2
- package/src/store/scopes/thread.ts +4 -0
- package/src/store/scopes/threads.ts +1 -0
- package/src/subscribable/subscribable.test.ts +50 -0
- package/src/subscribable/subscribable.ts +33 -21
- package/src/tests/MessageRepository.test.ts +116 -0
- 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 +158 -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 +89 -0
- package/src/tests/attachment-adapters.test.ts +14 -0
- package/src/tests/base-composer-runtime-core.test.ts +39 -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-list-runtime-core.test.ts +83 -0
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +49 -34
- package/src/tests/external-thread-attachments.test.tsx +224 -1
- package/src/tests/external-thread-parity.test.tsx +23 -0
- package/src/tests/remote-thread-list-adapter-switch.test.ts +66 -1
- package/src/tests/remote-thread-list-isLoading.test.ts +1 -0
- package/src/tests/thread-list-runtime-getLoadThreadsPromise.test.ts +1 -0
- package/src/tests/thread-switch-events.test.tsx +475 -2
- package/src/tests/tools-scope-migration.test.tsx +28 -0
- package/src/types/attachment.ts +4 -0
- package/src/types/message.ts +50 -2
- package/src/utils/abortable-iterable.test.ts +213 -0
- package/src/utils/abortable-iterable.ts +93 -0
- package/src/utils/composite-context-provider.test.ts +25 -0
- package/src/utils/composite-context-provider.ts +23 -2
- package/src/utils/record.test.ts +48 -0
- package/src/utils/record.ts +11 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { renderHook } from "@testing-library/react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
const part = vi.hoisted(() => ({
|
|
7
|
+
type: "tool-call" as const,
|
|
8
|
+
status: { type: "complete" as const },
|
|
9
|
+
args: JSON.parse('{"__proto__":"value"}') as Record<string, unknown>,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
vi.mock("@assistant-ui/store", async (importOriginal) => {
|
|
13
|
+
const actual = await importOriginal<typeof import("@assistant-ui/store")>();
|
|
14
|
+
return {
|
|
15
|
+
...actual,
|
|
16
|
+
useAuiState: (selector: (state: { part: typeof part }) => unknown) =>
|
|
17
|
+
selector({ part }),
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
import { useToolArgsStatus } from "./useToolArgsStatus";
|
|
22
|
+
|
|
23
|
+
describe("useToolArgsStatus", () => {
|
|
24
|
+
it("reports status for an argument named __proto__", () => {
|
|
25
|
+
const { result } = renderHook(() => useToolArgsStatus());
|
|
26
|
+
|
|
27
|
+
expect(Object.hasOwn(result.current.propStatus, "__proto__")).toBe(true);
|
|
28
|
+
expect(result.current.propStatus.__proto__).toBe("complete");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
getPartialJsonObjectFieldState,
|
|
5
5
|
getPartialJsonObjectMeta,
|
|
6
6
|
} from "assistant-stream/utils";
|
|
7
|
+
import { nullProtoRecord } from "../../utils/record";
|
|
7
8
|
|
|
8
9
|
type PropFieldStatus = "streaming" | "complete";
|
|
9
10
|
|
|
@@ -60,7 +61,7 @@ export const useToolArgsStatus = <
|
|
|
60
61
|
const isStreaming = statusType === "running";
|
|
61
62
|
const args = part.args as Record<string, unknown>;
|
|
62
63
|
const meta = getPartialJsonObjectMeta(args as Record<symbol, unknown>);
|
|
63
|
-
const propStatus
|
|
64
|
+
const propStatus = nullProtoRecord<PropFieldStatus>();
|
|
64
65
|
|
|
65
66
|
for (const key of Object.keys(args)) {
|
|
66
67
|
if (meta) {
|
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
import { useAuiState } from "@assistant-ui/store";
|
|
2
|
+
import { messageErrorText } from "../../store/primitive-predicates";
|
|
2
3
|
|
|
3
4
|
export const useMessageError = () => {
|
|
4
|
-
return useAuiState(
|
|
5
|
-
if (
|
|
6
|
-
s.message.status?.type !== "incomplete" ||
|
|
7
|
-
s.message.status.reason !== "error"
|
|
8
|
-
) {
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
const error = s.message.status.error;
|
|
12
|
-
if (typeof error === "string") return error;
|
|
13
|
-
if (
|
|
14
|
-
typeof error === "object" &&
|
|
15
|
-
error !== null &&
|
|
16
|
-
"message" in error &&
|
|
17
|
-
typeof error.message === "string"
|
|
18
|
-
) {
|
|
19
|
-
return error.message;
|
|
20
|
-
}
|
|
21
|
-
return error ?? "An error occurred";
|
|
22
|
-
});
|
|
5
|
+
return useAuiState(messageErrorText);
|
|
23
6
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { useAui, useAuiState } from "@assistant-ui/store";
|
|
3
|
+
import { threadListLoadMoreDisabled } from "../../store/primitive-predicates";
|
|
3
4
|
|
|
4
5
|
export const useThreadListLoadMore = () => {
|
|
5
6
|
const aui = useAui();
|
|
6
|
-
const disabled = useAuiState(
|
|
7
|
-
(s) => !s.threads.hasMore || s.threads.isLoading || s.threads.isLoadingMore,
|
|
8
|
-
);
|
|
7
|
+
const disabled = useAuiState(threadListLoadMoreDisabled);
|
|
9
8
|
|
|
10
9
|
const loadMore = useCallback(() => {
|
|
11
10
|
aui.threads.loadMore();
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { useState, type ReactNode } from "react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import type { Attachment } from "../../../types/attachment";
|
|
6
|
+
|
|
7
|
+
const mocks = vi.hoisted(() => ({
|
|
8
|
+
attachments: [] as Attachment[],
|
|
9
|
+
aui: {
|
|
10
|
+
composer: {
|
|
11
|
+
attachment: ({ index }: { index: number }) => ({
|
|
12
|
+
getState: () => mocks.attachments[index],
|
|
13
|
+
}),
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
vi.mock("@assistant-ui/store", async (importOriginal) => ({
|
|
19
|
+
...(await importOriginal<typeof import("@assistant-ui/store")>()),
|
|
20
|
+
useAui: () => mocks.aui,
|
|
21
|
+
useAuiState: (selector: (state: unknown) => unknown) =>
|
|
22
|
+
selector({ composer: { attachments: mocks.attachments } }),
|
|
23
|
+
RenderChildrenWithAccessor: ({
|
|
24
|
+
getItemState,
|
|
25
|
+
children,
|
|
26
|
+
}: {
|
|
27
|
+
getItemState: (aui: typeof mocks.aui) => Attachment;
|
|
28
|
+
children: (getItem: () => Attachment) => ReactNode;
|
|
29
|
+
}) => children(() => getItemState(mocks.aui)),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
vi.mock("../../providers/AttachmentByIndexProvider", () => ({
|
|
33
|
+
ComposerAttachmentByIndexProvider: ({ children }: { children: ReactNode }) =>
|
|
34
|
+
children,
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
import { ComposerPrimitiveAttachments } from "./ComposerAttachments";
|
|
38
|
+
|
|
39
|
+
const attachment = (id: string, name: string): Attachment => ({
|
|
40
|
+
id,
|
|
41
|
+
name,
|
|
42
|
+
type: "file",
|
|
43
|
+
contentType: "text/plain",
|
|
44
|
+
status: { type: "complete" },
|
|
45
|
+
content: [],
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const StatefulAttachment = ({ attachment }: { attachment: Attachment }) => {
|
|
49
|
+
const [initialName] = useState(attachment.name);
|
|
50
|
+
return <span>{initialName}</span>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
describe("ComposerPrimitiveAttachments", () => {
|
|
54
|
+
it("does not reuse component state for a different attachment", () => {
|
|
55
|
+
mocks.attachments = [
|
|
56
|
+
attachment("first", "first.txt"),
|
|
57
|
+
attachment("second", "second.txt"),
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
const view = render(
|
|
61
|
+
<ComposerPrimitiveAttachments>
|
|
62
|
+
{({ attachment }) => <StatefulAttachment attachment={attachment} />}
|
|
63
|
+
</ComposerPrimitiveAttachments>,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
mocks.attachments = [mocks.attachments[1]!];
|
|
67
|
+
view.rerender(
|
|
68
|
+
<ComposerPrimitiveAttachments>
|
|
69
|
+
{({ attachment }) => <StatefulAttachment attachment={attachment} />}
|
|
70
|
+
</ComposerPrimitiveAttachments>,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(screen.queryByText("second.txt")).not.toBeNull();
|
|
74
|
+
expect(screen.queryByText("first.txt")).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useMemo,
|
|
8
8
|
} from "react";
|
|
9
9
|
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
10
|
+
import { useShallowSelector } from "@assistant-ui/store/internal";
|
|
10
11
|
import { ComposerAttachmentByIndexProvider } from "../../providers/AttachmentByIndexProvider";
|
|
11
12
|
|
|
12
13
|
type ComposerAttachmentsComponentConfig = {
|
|
@@ -91,12 +92,16 @@ ComposerPrimitiveAttachmentByIndex.displayName =
|
|
|
91
92
|
const ComposerPrimitiveAttachmentsInner: FC<{
|
|
92
93
|
children: (value: { attachment: Attachment }) => ReactNode;
|
|
93
94
|
}> = ({ children }) => {
|
|
94
|
-
const
|
|
95
|
+
const attachmentIds = useAuiState(
|
|
96
|
+
useShallowSelector((s) =>
|
|
97
|
+
s.composer.attachments.map((attachment) => attachment.id),
|
|
98
|
+
),
|
|
99
|
+
);
|
|
95
100
|
|
|
96
101
|
return useMemo(
|
|
97
102
|
() =>
|
|
98
|
-
|
|
99
|
-
<ComposerAttachmentByIndexProvider key={
|
|
103
|
+
attachmentIds.map((attachmentId, index) => (
|
|
104
|
+
<ComposerAttachmentByIndexProvider key={attachmentId} index={index}>
|
|
100
105
|
<RenderChildrenWithAccessor
|
|
101
106
|
getItemState={(aui) =>
|
|
102
107
|
aui.composer.attachment({ index }).getState()
|
|
@@ -112,7 +117,7 @@ const ComposerPrimitiveAttachmentsInner: FC<{
|
|
|
112
117
|
</RenderChildrenWithAccessor>
|
|
113
118
|
</ComposerAttachmentByIndexProvider>
|
|
114
119
|
)),
|
|
115
|
-
[
|
|
120
|
+
[attachmentIds, children],
|
|
116
121
|
);
|
|
117
122
|
};
|
|
118
123
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { useState, type ReactNode } from "react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import type { QueueItemState } from "../../../runtime/queue/queue-item";
|
|
6
|
+
|
|
7
|
+
const mocks = vi.hoisted(() => ({
|
|
8
|
+
queue: [] as QueueItemState[],
|
|
9
|
+
aui: {
|
|
10
|
+
composer: {
|
|
11
|
+
queueItem: ({ index }: { index: number }) => ({
|
|
12
|
+
getState: () => mocks.queue[index],
|
|
13
|
+
}),
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
vi.mock("@assistant-ui/store", async (importOriginal) => ({
|
|
19
|
+
...(await importOriginal<typeof import("@assistant-ui/store")>()),
|
|
20
|
+
useAui: () => mocks.aui,
|
|
21
|
+
useAuiState: (selector: (state: unknown) => unknown) =>
|
|
22
|
+
selector({ composer: { queue: mocks.queue } }),
|
|
23
|
+
RenderChildrenWithAccessor: ({
|
|
24
|
+
getItemState,
|
|
25
|
+
children,
|
|
26
|
+
}: {
|
|
27
|
+
getItemState: (aui: typeof mocks.aui) => QueueItemState;
|
|
28
|
+
children: (getItem: () => QueueItemState) => ReactNode;
|
|
29
|
+
}) => children(() => getItemState(mocks.aui)),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
vi.mock("../../providers/QueueItemByIndexProvider", () => ({
|
|
33
|
+
QueueItemByIndexProvider: ({ children }: { children: ReactNode }) => children,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
import { ComposerPrimitiveQueue } from "./ComposerQueue";
|
|
37
|
+
|
|
38
|
+
const queueItem = (id: string, prompt: string): QueueItemState => ({
|
|
39
|
+
id,
|
|
40
|
+
prompt,
|
|
41
|
+
parts: [{ type: "text", text: prompt }],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const StatefulQueueItem = ({ queueItem }: { queueItem: QueueItemState }) => {
|
|
45
|
+
const [initialPrompt] = useState(queueItem.prompt);
|
|
46
|
+
return <span>{initialPrompt}</span>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
describe("ComposerPrimitiveQueue", () => {
|
|
50
|
+
it("does not reuse component state for a different queue item", () => {
|
|
51
|
+
mocks.queue = [
|
|
52
|
+
queueItem("first", "first message"),
|
|
53
|
+
queueItem("second", "second message"),
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const view = render(
|
|
57
|
+
<ComposerPrimitiveQueue>
|
|
58
|
+
{({ queueItem }) => <StatefulQueueItem queueItem={queueItem} />}
|
|
59
|
+
</ComposerPrimitiveQueue>,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
mocks.queue = [mocks.queue[1]!];
|
|
63
|
+
view.rerender(
|
|
64
|
+
<ComposerPrimitiveQueue>
|
|
65
|
+
{({ queueItem }) => <StatefulQueueItem queueItem={queueItem} />}
|
|
66
|
+
</ComposerPrimitiveQueue>,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(screen.queryByText("second message")).not.toBeNull();
|
|
70
|
+
expect(screen.queryByText("first message")).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FC, type ReactNode, memo, useMemo } from "react";
|
|
2
2
|
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
3
|
+
import { useShallowSelector } from "@assistant-ui/store/internal";
|
|
3
4
|
import type { QueueItemState } from "../../../store/scopes/queue-item";
|
|
4
5
|
import { QueueItemByIndexProvider } from "../../providers/QueueItemByIndexProvider";
|
|
5
6
|
|
|
@@ -13,12 +14,14 @@ export namespace ComposerPrimitiveQueue {
|
|
|
13
14
|
const ComposerPrimitiveQueueInner: FC<{
|
|
14
15
|
children: (value: { queueItem: QueueItemState }) => ReactNode;
|
|
15
16
|
}> = ({ children }) => {
|
|
16
|
-
const
|
|
17
|
+
const queueItemIds = useAuiState(
|
|
18
|
+
useShallowSelector((s) => s.composer.queue.map((item) => item.id)),
|
|
19
|
+
);
|
|
17
20
|
|
|
18
21
|
return useMemo(
|
|
19
22
|
() =>
|
|
20
|
-
|
|
21
|
-
<QueueItemByIndexProvider key={
|
|
23
|
+
queueItemIds.map((queueItemId, index) => (
|
|
24
|
+
<QueueItemByIndexProvider key={queueItemId} index={index}>
|
|
22
25
|
<RenderChildrenWithAccessor
|
|
23
26
|
getItemState={(aui) => aui.composer.queueItem({ index }).getState()}
|
|
24
27
|
>
|
|
@@ -32,7 +35,7 @@ const ComposerPrimitiveQueueInner: FC<{
|
|
|
32
35
|
</RenderChildrenWithAccessor>
|
|
33
36
|
</QueueItemByIndexProvider>
|
|
34
37
|
)),
|
|
35
|
-
[
|
|
38
|
+
[queueItemIds, children],
|
|
36
39
|
);
|
|
37
40
|
};
|
|
38
41
|
|
|
@@ -1,50 +1,120 @@
|
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { useState, type ReactNode } from "react";
|
|
1
4
|
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type {
|
|
3
|
-
import { MessagePrimitiveAttachments } from "./MessageAttachments";
|
|
5
|
+
import type { CompleteAttachment } from "../../../types/attachment";
|
|
4
6
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
});
|
|
7
|
+
const mocks = vi.hoisted(() => ({
|
|
8
|
+
role: "user" as "user" | "assistant",
|
|
9
|
+
attachments: undefined as CompleteAttachment[] | undefined,
|
|
10
|
+
aui: {
|
|
11
|
+
message: {
|
|
12
|
+
attachment: ({ index }: { index: number }) => ({
|
|
13
|
+
getState: () => mocks.attachments?.[index],
|
|
14
|
+
}),
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
18
|
|
|
19
|
-
vi.mock("@assistant-ui/store", async (importOriginal) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
vi.mock("@assistant-ui/store", async (importOriginal) => ({
|
|
20
|
+
...(await importOriginal<typeof import("@assistant-ui/store")>()),
|
|
21
|
+
useAui: () => mocks.aui,
|
|
22
|
+
useAuiState: (selector: (state: unknown) => unknown) =>
|
|
23
|
+
selector({
|
|
24
|
+
message: {
|
|
25
|
+
role: mocks.role,
|
|
26
|
+
attachments: mocks.attachments,
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
RenderChildrenWithAccessor: ({
|
|
30
|
+
getItemState,
|
|
31
|
+
children,
|
|
32
|
+
}: {
|
|
33
|
+
getItemState: (aui: typeof mocks.aui) => CompleteAttachment;
|
|
34
|
+
children: (getItem: () => CompleteAttachment) => ReactNode;
|
|
35
|
+
}) => children(() => getItemState(mocks.aui)),
|
|
36
|
+
}));
|
|
26
37
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
vi.mock(
|
|
39
|
+
"../../providers/AttachmentByIndexProvider",
|
|
40
|
+
async (importOriginal) => ({
|
|
41
|
+
...(await importOriginal<
|
|
42
|
+
typeof import("../../providers/AttachmentByIndexProvider")
|
|
43
|
+
>()),
|
|
44
|
+
MessageAttachmentByIndexProvider: ({ children }: { children: ReactNode }) =>
|
|
45
|
+
children,
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
31
48
|
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
import { MessagePrimitiveAttachments } from "./MessageAttachments";
|
|
50
|
+
|
|
51
|
+
const attachment = (id: string): CompleteAttachment => ({
|
|
52
|
+
id,
|
|
53
|
+
type: "file",
|
|
54
|
+
name: `${id}.txt`,
|
|
55
|
+
status: { type: "complete" },
|
|
56
|
+
content: [],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const StatefulAttachment = ({
|
|
60
|
+
attachment,
|
|
61
|
+
}: {
|
|
62
|
+
attachment: CompleteAttachment;
|
|
63
|
+
}) => {
|
|
64
|
+
const [initialId] = useState(attachment.id);
|
|
65
|
+
return <span>{initialId}</span>;
|
|
34
66
|
};
|
|
35
67
|
|
|
36
68
|
describe("MessagePrimitiveAttachments", () => {
|
|
37
69
|
it("treats missing user message attachments as empty", () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
70
|
+
mocks.role = "user";
|
|
71
|
+
mocks.attachments = undefined;
|
|
72
|
+
|
|
73
|
+
const view = render(
|
|
74
|
+
<MessagePrimitiveAttachments>{() => null}</MessagePrimitiveAttachments>,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
expect(view.container.childElementCount).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("does not reuse component state for a different attachment", () => {
|
|
81
|
+
mocks.role = "user";
|
|
82
|
+
mocks.attachments = [attachment("first-file"), attachment("second-file")];
|
|
83
|
+
|
|
84
|
+
const view = render(
|
|
85
|
+
<MessagePrimitiveAttachments>
|
|
86
|
+
{({ attachment }) => <StatefulAttachment attachment={attachment} />}
|
|
87
|
+
</MessagePrimitiveAttachments>,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
mocks.attachments = [mocks.attachments[1]!];
|
|
91
|
+
view.rerender(
|
|
92
|
+
<MessagePrimitiveAttachments>
|
|
93
|
+
{({ attachment }) => <StatefulAttachment attachment={attachment} />}
|
|
94
|
+
</MessagePrimitiveAttachments>,
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
expect(screen.queryByText("second-file")).not.toBeNull();
|
|
98
|
+
expect(screen.queryByText("first-file")).toBeNull();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("keeps component state with attachments when they are reordered", () => {
|
|
102
|
+
mocks.role = "user";
|
|
103
|
+
mocks.attachments = [attachment("first-file"), attachment("second-file")];
|
|
104
|
+
|
|
105
|
+
const view = render(
|
|
106
|
+
<MessagePrimitiveAttachments>
|
|
107
|
+
{({ attachment }) => <StatefulAttachment attachment={attachment} />}
|
|
108
|
+
</MessagePrimitiveAttachments>,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
mocks.attachments = [mocks.attachments[1]!, mocks.attachments[0]!];
|
|
112
|
+
view.rerender(
|
|
113
|
+
<MessagePrimitiveAttachments>
|
|
114
|
+
{({ attachment }) => <StatefulAttachment attachment={attachment} />}
|
|
115
|
+
</MessagePrimitiveAttachments>,
|
|
45
116
|
);
|
|
46
117
|
|
|
47
|
-
expect(
|
|
48
|
-
expect(renderAttachmentsInner()).toEqual([]);
|
|
118
|
+
expect(view.container.textContent).toBe("second-filefirst-file");
|
|
49
119
|
});
|
|
50
120
|
});
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useMemo,
|
|
8
8
|
} from "react";
|
|
9
9
|
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
10
|
+
import { useShallowSelector } from "@assistant-ui/store/internal";
|
|
10
11
|
import { MessageAttachmentByIndexProvider } from "../../providers/AttachmentByIndexProvider";
|
|
11
12
|
|
|
12
13
|
type MessageAttachmentsComponentConfig = {
|
|
@@ -91,15 +92,17 @@ MessagePrimitiveAttachmentByIndex.displayName =
|
|
|
91
92
|
const MessagePrimitiveAttachmentsInner: FC<{
|
|
92
93
|
children: (value: { attachment: CompleteAttachment }) => ReactNode;
|
|
93
94
|
}> = ({ children }) => {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
const attachmentIds = useAuiState(
|
|
96
|
+
useShallowSelector((s) => {
|
|
97
|
+
if (s.message.role !== "user") return [];
|
|
98
|
+
return (s.message.attachments ?? []).map((attachment) => attachment.id);
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
98
101
|
|
|
99
102
|
return useMemo(
|
|
100
103
|
() =>
|
|
101
|
-
|
|
102
|
-
<MessageAttachmentByIndexProvider key={
|
|
104
|
+
attachmentIds.map((attachmentId, index) => (
|
|
105
|
+
<MessageAttachmentByIndexProvider key={attachmentId} index={index}>
|
|
103
106
|
<RenderChildrenWithAccessor
|
|
104
107
|
getItemState={(aui) => aui.message.attachment({ index }).getState()}
|
|
105
108
|
>
|
|
@@ -113,7 +116,7 @@ const MessagePrimitiveAttachmentsInner: FC<{
|
|
|
113
116
|
</RenderChildrenWithAccessor>
|
|
114
117
|
</MessageAttachmentByIndexProvider>
|
|
115
118
|
)),
|
|
116
|
-
[
|
|
119
|
+
[attachmentIds, children],
|
|
117
120
|
);
|
|
118
121
|
};
|
|
119
122
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Fragment, type FC, type ReactNode, useMemo } from "react";
|
|
4
4
|
import { useAuiState } from "@assistant-ui/store";
|
|
5
|
-
import {
|
|
5
|
+
import { useShallowSelector } from "@assistant-ui/store/internal";
|
|
6
6
|
import type { PartState } from "../../../store/scopes/part";
|
|
7
7
|
import type {
|
|
8
8
|
MessagePartStatus,
|
|
@@ -251,7 +251,7 @@ export const MessagePrimitiveGroupedParts = <TKey extends `group-${string}`>({
|
|
|
251
251
|
indicator = "no-text",
|
|
252
252
|
children,
|
|
253
253
|
}: MessagePrimitiveGroupedParts.Props<TKey>): ReactNode => {
|
|
254
|
-
const parts = useAuiState(
|
|
254
|
+
const parts = useAuiState(useShallowSelector((s) => s.message.parts));
|
|
255
255
|
// Handed to `groupBy` as its `context` argument (see GroupByContext).
|
|
256
256
|
const toolUIs = useAuiState((s) => s.tools.toolUIs);
|
|
257
257
|
// Subscribe to a boolean, not the status object: the tree only needs to
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
} from "../../../types/message";
|
|
41
41
|
import type { DataRenderersState } from "../../types/scopes/dataRenderers";
|
|
42
42
|
import type { ToolsState } from "../../types/scopes/tools";
|
|
43
|
-
import {
|
|
43
|
+
import { useShallowSelector } from "@assistant-ui/store/internal";
|
|
44
44
|
|
|
45
45
|
type MessagePartRange =
|
|
46
46
|
| { type: "single"; index: number }
|
|
@@ -174,10 +174,10 @@ const useMessagePartsGroups = (
|
|
|
174
174
|
useChainOfThought: boolean,
|
|
175
175
|
): { ranges: MessagePartRange[]; partIds: (string | undefined)[] } => {
|
|
176
176
|
const messageTypes = useAuiState(
|
|
177
|
-
|
|
177
|
+
useShallowSelector((s) => s.message.parts.map((c: any) => c.type)),
|
|
178
178
|
);
|
|
179
179
|
const partIds = useAuiState(
|
|
180
|
-
|
|
180
|
+
useShallowSelector((s) =>
|
|
181
181
|
s.message.parts.map((c: any) =>
|
|
182
182
|
c.type === "tool-call" ? c.toolCallId : undefined,
|
|
183
183
|
),
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { useState, type ReactNode } from "react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import type { ThreadListItemState } from "../../../store/scopes/thread-list-item";
|
|
6
|
+
|
|
7
|
+
const mocks = vi.hoisted(() => ({
|
|
8
|
+
threadItems: [] as ThreadListItemState[],
|
|
9
|
+
archivedThreadItems: [] as ThreadListItemState[],
|
|
10
|
+
aui: {
|
|
11
|
+
threads: {
|
|
12
|
+
item: ({ index, archived }: { index: number; archived?: boolean }) => ({
|
|
13
|
+
getState: () =>
|
|
14
|
+
archived
|
|
15
|
+
? mocks.archivedThreadItems[index]
|
|
16
|
+
: mocks.threadItems[index],
|
|
17
|
+
}),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
vi.mock("@assistant-ui/store", async (importOriginal) => ({
|
|
23
|
+
...(await importOriginal<typeof import("@assistant-ui/store")>()),
|
|
24
|
+
useAui: () => mocks.aui,
|
|
25
|
+
useAuiState: (selector: (state: unknown) => unknown) =>
|
|
26
|
+
selector({
|
|
27
|
+
threads: {
|
|
28
|
+
threadIds: mocks.threadItems.map((item) => item.id),
|
|
29
|
+
archivedThreadIds: mocks.archivedThreadItems.map((item) => item.id),
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
RenderChildrenWithAccessor: ({
|
|
33
|
+
getItemState,
|
|
34
|
+
children,
|
|
35
|
+
}: {
|
|
36
|
+
getItemState: (aui: typeof mocks.aui) => ThreadListItemState;
|
|
37
|
+
children: (getItem: () => ThreadListItemState) => ReactNode;
|
|
38
|
+
}) => children(() => getItemState(mocks.aui)),
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
vi.mock(
|
|
42
|
+
"../../providers/ThreadListItemByIndexProvider",
|
|
43
|
+
async (importOriginal) => ({
|
|
44
|
+
...(await importOriginal<
|
|
45
|
+
typeof import("../../providers/ThreadListItemByIndexProvider")
|
|
46
|
+
>()),
|
|
47
|
+
ThreadListItemByIndexProvider: ({ children }: { children: ReactNode }) =>
|
|
48
|
+
children,
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
import { ThreadListPrimitiveItems } from "./ThreadListItems";
|
|
53
|
+
|
|
54
|
+
const threadItem = (id: string, title: string): ThreadListItemState => ({
|
|
55
|
+
id,
|
|
56
|
+
remoteId: id,
|
|
57
|
+
externalId: undefined,
|
|
58
|
+
title,
|
|
59
|
+
status: "regular",
|
|
60
|
+
isRunning: false,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const StatefulThreadItem = ({
|
|
64
|
+
threadListItem,
|
|
65
|
+
}: {
|
|
66
|
+
threadListItem: ThreadListItemState;
|
|
67
|
+
}) => {
|
|
68
|
+
const [initialTitle] = useState(threadListItem.title);
|
|
69
|
+
return <span>{initialTitle}</span>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
describe("ThreadListPrimitiveItems", () => {
|
|
73
|
+
it("does not reuse component state for a different thread", () => {
|
|
74
|
+
mocks.threadItems = [
|
|
75
|
+
threadItem("first", "First thread"),
|
|
76
|
+
threadItem("second", "Second thread"),
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
const view = render(
|
|
80
|
+
<ThreadListPrimitiveItems>
|
|
81
|
+
{({ threadListItem }) => (
|
|
82
|
+
<StatefulThreadItem threadListItem={threadListItem} />
|
|
83
|
+
)}
|
|
84
|
+
</ThreadListPrimitiveItems>,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
mocks.threadItems = [mocks.threadItems[1]!];
|
|
88
|
+
view.rerender(
|
|
89
|
+
<ThreadListPrimitiveItems>
|
|
90
|
+
{({ threadListItem }) => (
|
|
91
|
+
<StatefulThreadItem threadListItem={threadListItem} />
|
|
92
|
+
)}
|
|
93
|
+
</ThreadListPrimitiveItems>,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
expect(screen.queryByText("Second thread")).not.toBeNull();
|
|
97
|
+
expect(screen.queryByText("First thread")).toBeNull();
|
|
98
|
+
});
|
|
99
|
+
});
|