@assistant-ui/core 0.1.0 → 0.1.1
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/LICENSE +21 -0
- package/dist/adapters/attachment.js +1 -1
- package/dist/adapters/attachment.js.map +1 -1
- package/dist/react/AssistantProvider.d.ts +10 -0
- package/dist/react/AssistantProvider.d.ts.map +1 -0
- package/dist/react/AssistantProvider.js +13 -0
- package/dist/react/AssistantProvider.js.map +1 -0
- package/dist/react/RuntimeAdapter.d.ts +3 -0
- package/dist/react/RuntimeAdapter.d.ts.map +1 -0
- package/dist/react/RuntimeAdapter.js +13 -0
- package/dist/react/RuntimeAdapter.js.map +1 -0
- package/dist/react/client/DataRenderers.d.ts +3 -0
- package/dist/react/client/DataRenderers.d.ts.map +1 -0
- package/dist/react/client/DataRenderers.js +33 -0
- package/dist/react/client/DataRenderers.js.map +1 -0
- package/dist/react/client/Tools.d.ts +8 -0
- package/dist/react/client/Tools.d.ts.map +1 -0
- package/dist/react/client/Tools.js +68 -0
- package/dist/react/client/Tools.js.map +1 -0
- package/dist/react/client/index.d.ts +3 -0
- package/dist/react/client/index.d.ts.map +1 -0
- package/dist/react/client/index.js +3 -0
- package/dist/react/client/index.js.map +1 -0
- package/dist/react/index.d.ts +17 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +19 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/model-context/index.d.ts +12 -0
- package/dist/react/model-context/index.d.ts.map +1 -0
- package/dist/react/model-context/index.js +11 -0
- package/dist/react/model-context/index.js.map +1 -0
- package/dist/react/model-context/makeAssistantDataUI.d.ts +7 -0
- package/dist/react/model-context/makeAssistantDataUI.d.ts.map +1 -0
- package/dist/react/model-context/makeAssistantDataUI.js +10 -0
- package/dist/react/model-context/makeAssistantDataUI.js.map +1 -0
- package/dist/react/model-context/makeAssistantTool.d.ts +7 -0
- package/dist/react/model-context/makeAssistantTool.d.ts.map +1 -0
- package/dist/react/model-context/makeAssistantTool.js +10 -0
- package/dist/react/model-context/makeAssistantTool.js.map +1 -0
- package/dist/react/model-context/makeAssistantToolUI.d.ts +7 -0
- package/dist/react/model-context/makeAssistantToolUI.d.ts.map +1 -0
- package/dist/react/model-context/makeAssistantToolUI.js +10 -0
- package/dist/react/model-context/makeAssistantToolUI.js.map +1 -0
- package/dist/react/model-context/toolbox.d.ts +10 -0
- package/dist/react/model-context/toolbox.d.ts.map +1 -0
- package/dist/react/model-context/toolbox.js +2 -0
- package/dist/react/model-context/toolbox.js.map +1 -0
- package/dist/react/model-context/useAssistantDataUI.d.ts +7 -0
- package/dist/react/model-context/useAssistantDataUI.d.ts.map +1 -0
- package/dist/react/model-context/useAssistantDataUI.js +11 -0
- package/dist/react/model-context/useAssistantDataUI.js.map +1 -0
- package/dist/react/model-context/useAssistantInstructions.d.ts +4 -0
- package/dist/react/model-context/useAssistantInstructions.d.ts.map +1 -0
- package/dist/react/model-context/useAssistantInstructions.js +22 -0
- package/dist/react/model-context/useAssistantInstructions.js.map +1 -0
- package/dist/react/model-context/useAssistantTool.d.ts +7 -0
- package/dist/react/model-context/useAssistantTool.d.ts.map +1 -0
- package/dist/react/model-context/useAssistantTool.js +22 -0
- package/dist/react/model-context/useAssistantTool.js.map +1 -0
- package/dist/react/model-context/useAssistantToolUI.d.ts +7 -0
- package/dist/react/model-context/useAssistantToolUI.d.ts.map +1 -0
- package/dist/react/model-context/useAssistantToolUI.js +11 -0
- package/dist/react/model-context/useAssistantToolUI.js.map +1 -0
- package/dist/react/model-context/useInlineRender.d.ts +4 -0
- package/dist/react/model-context/useInlineRender.d.ts.map +1 -0
- package/dist/react/model-context/useInlineRender.js +15 -0
- package/dist/react/model-context/useInlineRender.js.map +1 -0
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.d.ts +27 -0
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.d.ts.map +1 -0
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +27 -0
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -0
- package/dist/react/primitives/composer/ComposerAttachments.d.ts +23 -0
- package/dist/react/primitives/composer/ComposerAttachments.d.ts.map +1 -0
- package/dist/react/primitives/composer/ComposerAttachments.js +47 -0
- package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -0
- package/dist/react/primitives/composer/ComposerIf.d.ts +20 -0
- package/dist/react/primitives/composer/ComposerIf.d.ts.map +1 -0
- package/dist/react/primitives/composer/ComposerIf.js +24 -0
- package/dist/react/primitives/composer/ComposerIf.js.map +1 -0
- package/dist/react/primitives/message/MessageAttachments.d.ts +23 -0
- package/dist/react/primitives/message/MessageAttachments.d.ts.map +1 -0
- package/dist/react/primitives/message/MessageAttachments.js +51 -0
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -0
- package/dist/react/primitives/message/MessageParts.d.ts +139 -0
- package/dist/react/primitives/message/MessageParts.d.ts.map +1 -0
- package/dist/react/primitives/message/MessageParts.js +251 -0
- package/dist/react/primitives/message/MessageParts.js.map +1 -0
- package/dist/react/primitives/thread/ThreadMessages.d.ts +95 -0
- package/dist/react/primitives/thread/ThreadMessages.d.ts.map +1 -0
- package/dist/react/primitives/thread/ThreadMessages.js +112 -0
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -0
- package/dist/react/primitives/thread/ThreadSuggestions.d.ts +28 -0
- package/dist/react/primitives/thread/ThreadSuggestions.d.ts.map +1 -0
- package/dist/react/primitives/thread/ThreadSuggestions.js +32 -0
- package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -0
- package/dist/react/primitives/threadList/ThreadListItems.d.ts +22 -0
- package/dist/react/primitives/threadList/ThreadListItems.d.ts.map +1 -0
- package/dist/react/primitives/threadList/ThreadListItems.js +23 -0
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -0
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.d.ts +8 -0
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.d.ts.map +1 -0
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.js +8 -0
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.js.map +1 -0
- package/dist/react/providers/AttachmentByIndexProvider.d.ts +8 -0
- package/dist/react/providers/AttachmentByIndexProvider.d.ts.map +1 -0
- package/dist/react/providers/AttachmentByIndexProvider.js +23 -0
- package/dist/react/providers/AttachmentByIndexProvider.js.map +1 -0
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.d.ts +6 -0
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.d.ts.map +1 -0
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +20 -0
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js.map +1 -0
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts +5 -0
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts.map +1 -0
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +13 -0
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -0
- package/dist/react/providers/MessageByIndexProvider.d.ts +5 -0
- package/dist/react/providers/MessageByIndexProvider.d.ts.map +1 -0
- package/dist/react/providers/MessageByIndexProvider.js +18 -0
- package/dist/react/providers/MessageByIndexProvider.js.map +1 -0
- package/dist/react/providers/PartByIndexProvider.d.ts +5 -0
- package/dist/react/providers/PartByIndexProvider.d.ts.map +1 -0
- package/dist/react/providers/PartByIndexProvider.js +13 -0
- package/dist/react/providers/PartByIndexProvider.js.map +1 -0
- package/dist/react/providers/SuggestionByIndexProvider.d.ts +6 -0
- package/dist/react/providers/SuggestionByIndexProvider.d.ts.map +1 -0
- package/dist/react/providers/SuggestionByIndexProvider.js +13 -0
- package/dist/react/providers/SuggestionByIndexProvider.js.map +1 -0
- package/dist/react/providers/TextMessagePartProvider.d.ts +6 -0
- package/dist/react/providers/TextMessagePartProvider.d.ts.map +1 -0
- package/dist/react/providers/TextMessagePartProvider.js +26 -0
- package/dist/react/providers/TextMessagePartProvider.js.map +1 -0
- package/dist/react/providers/ThreadListItemByIndexProvider.d.ts +6 -0
- package/dist/react/providers/ThreadListItemByIndexProvider.d.ts.map +1 -0
- package/dist/react/providers/ThreadListItemByIndexProvider.js +13 -0
- package/dist/react/providers/ThreadListItemByIndexProvider.js.map +1 -0
- package/dist/react/providers/ThreadListItemRuntimeProvider.d.ts +6 -0
- package/dist/react/providers/ThreadListItemRuntimeProvider.d.ts.map +1 -0
- package/dist/react/providers/ThreadListItemRuntimeProvider.js +10 -0
- package/dist/react/providers/ThreadListItemRuntimeProvider.js.map +1 -0
- package/dist/react/providers/index.d.ts +10 -0
- package/dist/react/providers/index.d.ts.map +1 -0
- package/dist/react/providers/index.js +10 -0
- package/dist/react/providers/index.js.map +1 -0
- package/dist/react/types/MessagePartComponentTypes.d.ts +33 -0
- package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -0
- package/dist/react/types/MessagePartComponentTypes.js +2 -0
- package/dist/react/types/MessagePartComponentTypes.js.map +1 -0
- package/dist/react/types/index.d.ts +3 -0
- package/dist/react/types/index.d.ts.map +1 -0
- package/dist/react/types/index.js +2 -0
- package/dist/react/types/index.js.map +1 -0
- package/dist/react/types/scopes/dataRenderers.d.ts +13 -0
- package/dist/react/types/scopes/dataRenderers.d.ts.map +1 -0
- package/dist/react/types/scopes/dataRenderers.js +2 -0
- package/dist/react/types/scopes/dataRenderers.js.map +1 -0
- package/dist/react/types/scopes/index.d.ts +3 -0
- package/dist/react/types/scopes/index.d.ts.map +1 -0
- package/dist/react/types/scopes/index.js +2 -0
- package/dist/react/types/scopes/index.js.map +1 -0
- package/dist/react/types/scopes/tools.d.ts +13 -0
- package/dist/react/types/scopes/tools.d.ts.map +1 -0
- package/dist/react/types/scopes/tools.js +2 -0
- package/dist/react/types/scopes/tools.js.map +1 -0
- package/dist/react/types/store-augmentation.d.ts +10 -0
- package/dist/react/types/store-augmentation.d.ts.map +1 -0
- package/dist/react/types/store-augmentation.js +2 -0
- package/dist/react/types/store-augmentation.js.map +1 -0
- package/dist/runtime/api/attachment-runtime.d.ts +2 -2
- package/dist/runtime/api/attachment-runtime.d.ts.map +1 -1
- package/dist/runtime/api/attachment-runtime.js.map +1 -1
- package/dist/runtime/api/composer-runtime.d.ts +8 -6
- package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.js +2 -2
- package/dist/runtime/api/composer-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +27 -2
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +2 -2
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +28 -8
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -2
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js +0 -3
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/interfaces/composer-runtime-core.d.ts +3 -5
- package/dist/runtime/interfaces/composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/utils/external-store-message.d.ts +8 -0
- package/dist/runtime/utils/external-store-message.d.ts.map +1 -1
- package/dist/runtime/utils/external-store-message.js +12 -0
- package/dist/runtime/utils/external-store-message.js.map +1 -1
- package/dist/runtime/utils/thread-message-like.d.ts +10 -3
- package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.js +20 -5
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +26 -8
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/model-context-client.d.ts +1 -1
- package/dist/store/clients/model-context-client.d.ts.map +1 -1
- package/dist/store/clients/no-op-composer-client.d.ts +1 -1
- package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
- package/dist/store/clients/runtime-adapter.d.ts +5 -0
- package/dist/store/clients/runtime-adapter.d.ts.map +1 -0
- package/dist/store/clients/runtime-adapter.js +46 -0
- package/dist/store/clients/runtime-adapter.js.map +1 -0
- package/dist/store/clients/suggestions.d.ts +1 -1
- package/dist/store/clients/suggestions.d.ts.map +1 -1
- package/dist/store/clients/suggestions.js +1 -1
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-message-client.d.ts +1 -1
- package/dist/store/clients/thread-message-client.d.ts.map +1 -1
- package/dist/store/clients/thread-message-client.js +1 -1
- package/dist/store/clients/thread-message-client.js.map +1 -1
- package/dist/store/index.d.ts +1 -11
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +2 -9
- package/dist/store/index.js.map +1 -1
- package/dist/store/internal.d.ts +1 -9
- package/dist/store/internal.d.ts.map +1 -1
- package/dist/store/internal.js +1 -10
- package/dist/store/internal.js.map +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts +1 -1
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts +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 +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
- package/dist/store/scope-registration.d.ts +27 -0
- package/dist/store/scope-registration.d.ts.map +1 -0
- package/dist/store/scope-registration.js +2 -0
- package/dist/store/scope-registration.js.map +1 -0
- package/dist/store/scopes/composer.d.ts +2 -2
- package/dist/store/scopes/composer.d.ts.map +1 -1
- package/dist/types/attachment.d.ts +9 -2
- package/dist/types/attachment.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +35 -12
- package/src/adapters/attachment.ts +1 -1
- package/src/react/AssistantProvider.tsx +34 -0
- package/src/react/RuntimeAdapter.ts +22 -0
- package/src/react/client/DataRenderers.ts +42 -0
- package/src/react/client/Tools.ts +97 -0
- package/src/react/client/index.ts +2 -0
- package/src/react/index.ts +50 -0
- package/src/react/model-context/index.ts +25 -0
- package/src/react/model-context/makeAssistantDataUI.ts +20 -0
- package/src/react/model-context/makeAssistantTool.ts +20 -0
- package/src/react/model-context/makeAssistantToolUI.ts +20 -0
- package/src/react/model-context/toolbox.ts +15 -0
- package/src/react/model-context/useAssistantDataUI.ts +16 -0
- package/src/react/model-context/useAssistantInstructions.ts +30 -0
- package/src/react/model-context/useAssistantTool.ts +37 -0
- package/src/react/model-context/useAssistantToolUI.ts +18 -0
- package/src/react/model-context/useInlineRender.ts +25 -0
- package/src/react/primitives/chainOfThought/ChainOfThoughtParts.tsx +73 -0
- package/src/react/primitives/composer/ComposerAttachments.tsx +95 -0
- package/src/react/primitives/composer/ComposerIf.tsx +49 -0
- package/src/react/primitives/message/MessageAttachments.tsx +98 -0
- package/src/react/primitives/message/MessageParts.tsx +561 -0
- package/src/react/primitives/thread/ThreadMessages.tsx +222 -0
- package/src/react/primitives/thread/ThreadSuggestions.tsx +82 -0
- package/src/react/primitives/threadList/ThreadListItems.tsx +66 -0
- package/src/react/primitives/threadListItem/ThreadListItemTitle.tsx +17 -0
- package/src/react/providers/AttachmentByIndexProvider.tsx +34 -0
- package/src/react/providers/ChainOfThoughtByIndicesProvider.tsx +34 -0
- package/src/react/providers/ChainOfThoughtPartByIndexProvider.tsx +18 -0
- package/src/react/providers/MessageByIndexProvider.tsx +23 -0
- package/src/react/providers/PartByIndexProvider.tsx +18 -0
- package/src/react/providers/SuggestionByIndexProvider.tsx +21 -0
- package/src/react/providers/TextMessagePartProvider.tsx +46 -0
- package/src/react/providers/ThreadListItemByIndexProvider.tsx +19 -0
- package/src/react/providers/ThreadListItemRuntimeProvider.tsx +16 -0
- package/src/react/providers/index.ts +15 -0
- package/src/react/types/MessagePartComponentTypes.ts +66 -0
- package/src/react/types/index.ts +31 -0
- package/src/react/types/scopes/dataRenderers.ts +15 -0
- package/src/react/types/scopes/index.ts +6 -0
- package/src/react/types/scopes/tools.ts +18 -0
- package/src/react/types/store-augmentation.ts +11 -0
- package/src/runtime/api/attachment-runtime.ts +2 -7
- package/src/runtime/api/composer-runtime.ts +9 -8
- package/src/runtime/base/base-composer-runtime-core.ts +28 -8
- package/src/runtime/base/default-thread-composer-runtime-core.ts +1 -5
- package/src/runtime/index.ts +1 -0
- package/src/runtime/interfaces/composer-runtime-core.ts +3 -6
- package/src/runtime/utils/external-store-message.ts +15 -0
- package/src/runtime/utils/thread-message-like.ts +40 -7
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +29 -12
- package/src/runtimes/remote-thread-list/empty-thread-core.ts +1 -1
- package/src/store/clients/chain-of-thought-client.ts +1 -1
- package/src/store/clients/model-context-client.ts +1 -1
- package/src/store/clients/no-op-composer-client.ts +1 -1
- package/src/store/clients/runtime-adapter.ts +67 -0
- package/src/store/clients/suggestions.ts +2 -2
- package/src/store/clients/thread-message-client.ts +2 -2
- package/src/store/index.ts +2 -38
- package/src/store/internal.ts +4 -31
- package/src/store/runtime-clients/attachment-runtime-client.ts +1 -1
- package/src/store/runtime-clients/composer-runtime-client.ts +5 -1
- package/src/store/runtime-clients/message-part-runtime-client.ts +1 -1
- package/src/store/runtime-clients/message-runtime-client.ts +5 -1
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +1 -1
- package/src/store/runtime-clients/thread-list-runtime-client.ts +5 -1
- package/src/store/runtime-clients/thread-runtime-client.ts +1 -1
- package/src/store/scope-registration.ts +27 -0
- package/src/store/scopes/composer.ts +2 -1
- package/src/tests/external-store-thread-runtime-core.test.ts +152 -0
- package/src/tests/thread-message-like.test.ts +110 -0
- package/src/types/attachment.ts +10 -2
- package/src/types/index.ts +1 -0
- package/dist/store/types/client.d.ts +0 -137
- package/dist/store/types/client.d.ts.map +0 -1
- package/dist/store/types/client.js +0 -2
- package/dist/store/types/client.js.map +0 -1
- package/dist/store/types/events.d.ts +0 -33
- package/dist/store/types/events.d.ts.map +0 -1
- package/dist/store/types/events.js +0 -8
- package/dist/store/types/events.js.map +0 -1
- package/dist/store/types/index.d.ts +0 -3
- package/dist/store/types/index.d.ts.map +0 -1
- package/dist/store/types/index.js +0 -2
- package/dist/store/types/index.js.map +0 -1
- package/dist/store/utils/attach-transform-scopes.d.ts +0 -11
- package/dist/store/utils/attach-transform-scopes.d.ts.map +0 -1
- package/dist/store/utils/attach-transform-scopes.js +0 -12
- package/dist/store/utils/attach-transform-scopes.js.map +0 -1
- package/dist/store/utils/base-proxy-handler.d.ts +0 -23
- package/dist/store/utils/base-proxy-handler.d.ts.map +0 -1
- package/dist/store/utils/base-proxy-handler.js +0 -46
- package/dist/store/utils/base-proxy-handler.js.map +0 -1
- package/dist/store/utils/derived.d.ts +0 -34
- package/dist/store/utils/derived.d.ts.map +0 -1
- package/dist/store/utils/derived.js +0 -24
- package/dist/store/utils/derived.js.map +0 -1
- package/dist/store/utils/index.d.ts +0 -7
- package/dist/store/utils/index.d.ts.map +0 -1
- package/dist/store/utils/index.js +0 -7
- package/dist/store/utils/index.js.map +0 -1
- package/dist/store/utils/notification-manager.d.ts +0 -11
- package/dist/store/utils/notification-manager.d.ts.map +0 -1
- package/dist/store/utils/notification-manager.js +0 -84
- package/dist/store/utils/notification-manager.js.map +0 -1
- package/dist/store/utils/proxied-assistant-state.d.ts +0 -8
- package/dist/store/utils/proxied-assistant-state.d.ts.map +0 -1
- package/dist/store/utils/proxied-assistant-state.js +0 -33
- package/dist/store/utils/proxied-assistant-state.js.map +0 -1
- package/dist/store/utils/split-clients.d.ts +0 -10
- package/dist/store/utils/split-clients.d.ts.map +0 -1
- package/dist/store/utils/split-clients.js +0 -53
- package/dist/store/utils/split-clients.js.map +0 -1
- package/dist/store/utils/tap-assistant-context.d.ts +0 -19
- package/dist/store/utils/tap-assistant-context.d.ts.map +0 -1
- package/dist/store/utils/tap-assistant-context.js +0 -23
- package/dist/store/utils/tap-assistant-context.js.map +0 -1
- package/dist/store/utils/tap-client-list.d.ts +0 -28
- package/dist/store/utils/tap-client-list.d.ts.map +0 -1
- package/dist/store/utils/tap-client-list.js +0 -68
- package/dist/store/utils/tap-client-list.js.map +0 -1
- package/dist/store/utils/tap-client-lookup.d.ts +0 -15
- package/dist/store/utils/tap-client-lookup.d.ts.map +0 -1
- package/dist/store/utils/tap-client-lookup.js +0 -42
- package/dist/store/utils/tap-client-lookup.js.map +0 -1
- package/dist/store/utils/tap-client-resource.d.ts +0 -13
- package/dist/store/utils/tap-client-resource.d.ts.map +0 -1
- package/dist/store/utils/tap-client-resource.js +0 -114
- package/dist/store/utils/tap-client-resource.js.map +0 -1
- package/dist/store/utils/tap-client-stack-context.d.ts +0 -23
- package/dist/store/utils/tap-client-stack-context.d.ts.map +0 -1
- package/dist/store/utils/tap-client-stack-context.js +0 -28
- package/dist/store/utils/tap-client-stack-context.js.map +0 -1
- package/dist/store/utils/wrapper-resource.d.ts +0 -3
- package/dist/store/utils/wrapper-resource.d.ts.map +0 -1
- package/dist/store/utils/wrapper-resource.js +0 -11
- package/dist/store/utils/wrapper-resource.js.map +0 -1
- package/src/store/types/client.ts +0 -203
- package/src/store/types/events.ts +0 -77
- package/src/store/types/index.ts +0 -23
- package/src/store/utils/attach-transform-scopes.ts +0 -38
- package/src/store/utils/base-proxy-handler.ts +0 -50
- package/src/store/utils/derived.ts +0 -46
- package/src/store/utils/index.ts +0 -28
- package/src/store/utils/notification-manager.ts +0 -114
- package/src/store/utils/proxied-assistant-state.ts +0 -55
- package/src/store/utils/split-clients.ts +0 -82
- package/src/store/utils/tap-assistant-context.ts +0 -58
- package/src/store/utils/tap-client-list.ts +0 -121
- package/src/store/utils/tap-client-lookup.ts +0 -79
- package/src/store/utils/tap-client-resource.ts +0 -187
- package/src/store/utils/tap-client-stack-context.ts +0 -51
- package/src/store/utils/wrapper-resource.ts +0 -17
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ComponentType,
|
|
3
|
+
type FC,
|
|
4
|
+
memo,
|
|
5
|
+
PropsWithChildren,
|
|
6
|
+
useMemo,
|
|
7
|
+
} from "react";
|
|
8
|
+
import { useAuiState, useAui } from "@assistant-ui/store";
|
|
9
|
+
import { PartByIndexProvider, TextMessagePartProvider } from "../../providers";
|
|
10
|
+
import { ChainOfThoughtByIndicesProvider } from "../../providers/ChainOfThoughtByIndicesProvider";
|
|
11
|
+
import type {
|
|
12
|
+
Unstable_AudioMessagePartComponent,
|
|
13
|
+
DataMessagePartComponent,
|
|
14
|
+
DataMessagePartProps,
|
|
15
|
+
EmptyMessagePartComponent,
|
|
16
|
+
TextMessagePartComponent,
|
|
17
|
+
ImageMessagePartComponent,
|
|
18
|
+
SourceMessagePartComponent,
|
|
19
|
+
ToolCallMessagePartComponent,
|
|
20
|
+
ToolCallMessagePartProps,
|
|
21
|
+
FileMessagePartComponent,
|
|
22
|
+
ReasoningMessagePartComponent,
|
|
23
|
+
ReasoningGroupComponent,
|
|
24
|
+
} from "../../types";
|
|
25
|
+
import type { MessagePartStatus } from "../../../types";
|
|
26
|
+
import { useShallow } from "zustand/shallow";
|
|
27
|
+
|
|
28
|
+
type MessagePartRange =
|
|
29
|
+
| { type: "single"; index: number }
|
|
30
|
+
| { type: "toolGroup"; startIndex: number; endIndex: number }
|
|
31
|
+
| { type: "reasoningGroup"; startIndex: number; endIndex: number }
|
|
32
|
+
| { type: "chainOfThoughtGroup"; startIndex: number; endIndex: number };
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Creates a group state manager for a specific part type.
|
|
36
|
+
* Returns functions to start, end, and finalize groups.
|
|
37
|
+
*/
|
|
38
|
+
const createGroupState = <
|
|
39
|
+
T extends "toolGroup" | "reasoningGroup" | "chainOfThoughtGroup",
|
|
40
|
+
>(
|
|
41
|
+
groupType: T,
|
|
42
|
+
) => {
|
|
43
|
+
let start = -1;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
startGroup: (index: number) => {
|
|
47
|
+
if (start === -1) {
|
|
48
|
+
start = index;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
endGroup: (endIndex: number, ranges: MessagePartRange[]) => {
|
|
52
|
+
if (start !== -1) {
|
|
53
|
+
ranges.push({
|
|
54
|
+
type: groupType,
|
|
55
|
+
startIndex: start,
|
|
56
|
+
endIndex,
|
|
57
|
+
} as MessagePartRange);
|
|
58
|
+
start = -1;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
finalize: (endIndex: number, ranges: MessagePartRange[]) => {
|
|
62
|
+
if (start !== -1) {
|
|
63
|
+
ranges.push({
|
|
64
|
+
type: groupType,
|
|
65
|
+
startIndex: start,
|
|
66
|
+
endIndex,
|
|
67
|
+
} as MessagePartRange);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Groups consecutive tool-call and reasoning message parts into ranges.
|
|
75
|
+
* Always groups tool calls and reasoning parts, even if there's only one.
|
|
76
|
+
* When useChainOfThought is true, groups tool-call and reasoning parts together.
|
|
77
|
+
*/
|
|
78
|
+
const groupMessageParts = (
|
|
79
|
+
messageTypes: readonly string[],
|
|
80
|
+
useChainOfThought: boolean,
|
|
81
|
+
): MessagePartRange[] => {
|
|
82
|
+
const ranges: MessagePartRange[] = [];
|
|
83
|
+
|
|
84
|
+
if (useChainOfThought) {
|
|
85
|
+
const chainOfThoughtGroup = createGroupState("chainOfThoughtGroup");
|
|
86
|
+
|
|
87
|
+
for (let i = 0; i < messageTypes.length; i++) {
|
|
88
|
+
const type = messageTypes[i];
|
|
89
|
+
|
|
90
|
+
if (type === "tool-call" || type === "reasoning") {
|
|
91
|
+
chainOfThoughtGroup.startGroup(i);
|
|
92
|
+
} else {
|
|
93
|
+
chainOfThoughtGroup.endGroup(i - 1, ranges);
|
|
94
|
+
ranges.push({ type: "single", index: i });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
chainOfThoughtGroup.finalize(messageTypes.length - 1, ranges);
|
|
99
|
+
} else {
|
|
100
|
+
const toolGroup = createGroupState("toolGroup");
|
|
101
|
+
const reasoningGroup = createGroupState("reasoningGroup");
|
|
102
|
+
|
|
103
|
+
for (let i = 0; i < messageTypes.length; i++) {
|
|
104
|
+
const type = messageTypes[i];
|
|
105
|
+
|
|
106
|
+
if (type === "tool-call") {
|
|
107
|
+
reasoningGroup.endGroup(i - 1, ranges);
|
|
108
|
+
toolGroup.startGroup(i);
|
|
109
|
+
} else if (type === "reasoning") {
|
|
110
|
+
toolGroup.endGroup(i - 1, ranges);
|
|
111
|
+
reasoningGroup.startGroup(i);
|
|
112
|
+
} else {
|
|
113
|
+
toolGroup.endGroup(i - 1, ranges);
|
|
114
|
+
reasoningGroup.endGroup(i - 1, ranges);
|
|
115
|
+
ranges.push({ type: "single", index: i });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
toolGroup.finalize(messageTypes.length - 1, ranges);
|
|
120
|
+
reasoningGroup.finalize(messageTypes.length - 1, ranges);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return ranges;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const useMessagePartsGroups = (
|
|
127
|
+
useChainOfThought: boolean,
|
|
128
|
+
): MessagePartRange[] => {
|
|
129
|
+
const messageTypes = useAuiState(
|
|
130
|
+
useShallow((s) => s.message.parts.map((c: any) => c.type)),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return useMemo(() => {
|
|
134
|
+
if (messageTypes.length === 0) {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
return groupMessageParts(messageTypes, useChainOfThought);
|
|
138
|
+
}, [messageTypes, useChainOfThought]);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export namespace MessagePrimitiveParts {
|
|
142
|
+
type DataConfig = {
|
|
143
|
+
/** Map data event names to specific components */
|
|
144
|
+
by_name?: Record<string, DataMessagePartComponent | undefined> | undefined;
|
|
145
|
+
/** Fallback component for unmatched data events */
|
|
146
|
+
Fallback?: DataMessagePartComponent | undefined;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
type BaseComponents = {
|
|
150
|
+
/** Component for rendering empty messages */
|
|
151
|
+
Empty?: EmptyMessagePartComponent | undefined;
|
|
152
|
+
/** Component for rendering text content */
|
|
153
|
+
Text?: TextMessagePartComponent | undefined;
|
|
154
|
+
/** Component for rendering source content */
|
|
155
|
+
Source?: SourceMessagePartComponent | undefined;
|
|
156
|
+
/** Component for rendering image content */
|
|
157
|
+
Image?: ImageMessagePartComponent | undefined;
|
|
158
|
+
/** Component for rendering file content */
|
|
159
|
+
File?: FileMessagePartComponent | undefined;
|
|
160
|
+
/** Component for rendering audio content (experimental) */
|
|
161
|
+
Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;
|
|
162
|
+
/** Configuration for data part rendering */
|
|
163
|
+
data?: DataConfig | undefined;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
type ToolsConfig =
|
|
167
|
+
| {
|
|
168
|
+
/** Map of tool names to their specific components */
|
|
169
|
+
by_name?:
|
|
170
|
+
| Record<string, ToolCallMessagePartComponent | undefined>
|
|
171
|
+
| undefined;
|
|
172
|
+
/** Fallback component for unregistered tools */
|
|
173
|
+
Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;
|
|
174
|
+
}
|
|
175
|
+
| {
|
|
176
|
+
/** Override component that handles all tool calls */
|
|
177
|
+
Override: ComponentType<ToolCallMessagePartProps>;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Standard component configuration for rendering reasoning and tool-call parts
|
|
182
|
+
* individually (with optional grouping).
|
|
183
|
+
*
|
|
184
|
+
* Cannot be combined with `ChainOfThought`.
|
|
185
|
+
*/
|
|
186
|
+
type StandardComponents = BaseComponents & {
|
|
187
|
+
/** Component for rendering reasoning content (typically hidden) */
|
|
188
|
+
Reasoning?: ReasoningMessagePartComponent | undefined;
|
|
189
|
+
/** Configuration for tool call rendering */
|
|
190
|
+
tools?: ToolsConfig | undefined;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Component for rendering grouped consecutive tool calls.
|
|
194
|
+
*
|
|
195
|
+
* @param startIndex - Index of the first tool call in the group
|
|
196
|
+
* @param endIndex - Index of the last tool call in the group
|
|
197
|
+
* @param children - Rendered tool call components to display within the group
|
|
198
|
+
*
|
|
199
|
+
* @deprecated This feature is still experimental and subject to change.
|
|
200
|
+
*/
|
|
201
|
+
ToolGroup?: ComponentType<
|
|
202
|
+
PropsWithChildren<{ startIndex: number; endIndex: number }>
|
|
203
|
+
>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Component for rendering grouped reasoning parts.
|
|
207
|
+
*
|
|
208
|
+
* @param startIndex - Index of the first reasoning part in the group
|
|
209
|
+
* @param endIndex - Index of the last reasoning part in the group
|
|
210
|
+
* @param children - Rendered reasoning part components
|
|
211
|
+
*/
|
|
212
|
+
ReasoningGroup?: ReasoningGroupComponent;
|
|
213
|
+
|
|
214
|
+
ChainOfThought?: never;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Chain of thought component configuration.
|
|
219
|
+
*
|
|
220
|
+
* When `ChainOfThought` is set, it takes control of rendering ALL reasoning and
|
|
221
|
+
* tool-call parts in the message. The `Reasoning`, `tools`, `ReasoningGroup`, and
|
|
222
|
+
* `ToolGroup` components cannot be used alongside it.
|
|
223
|
+
*/
|
|
224
|
+
type ChainOfThoughtComponents = BaseComponents & {
|
|
225
|
+
ChainOfThought: ComponentType;
|
|
226
|
+
|
|
227
|
+
Reasoning?: never;
|
|
228
|
+
tools?: never;
|
|
229
|
+
ToolGroup?: never;
|
|
230
|
+
ReasoningGroup?: never;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export type Props = {
|
|
234
|
+
/**
|
|
235
|
+
* Component configuration for rendering different types of message content.
|
|
236
|
+
*
|
|
237
|
+
* Use either `Reasoning`/`tools`/`ToolGroup`/`ReasoningGroup` for standard rendering,
|
|
238
|
+
* or `ChainOfThought` to group all reasoning and tool-call parts into a single
|
|
239
|
+
* collapsible component. These two modes are mutually exclusive.
|
|
240
|
+
*/
|
|
241
|
+
components?: StandardComponents | ChainOfThoughtComponents | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* When enabled, shows the Empty component if the last part in the message
|
|
244
|
+
* is anything other than Text or Reasoning.
|
|
245
|
+
*
|
|
246
|
+
* @experimental This API is experimental and may change in future versions.
|
|
247
|
+
* @default true
|
|
248
|
+
*/
|
|
249
|
+
unstable_showEmptyOnNonTextEnd?: boolean | undefined;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const ToolUIDisplay = ({
|
|
254
|
+
Fallback,
|
|
255
|
+
...props
|
|
256
|
+
}: {
|
|
257
|
+
Fallback: ToolCallMessagePartComponent | undefined;
|
|
258
|
+
} & ToolCallMessagePartProps) => {
|
|
259
|
+
const Render = useAuiState((s) => {
|
|
260
|
+
const Render = s.tools.tools[props.toolName] ?? Fallback;
|
|
261
|
+
if (Array.isArray(Render)) return Render[0] ?? Fallback;
|
|
262
|
+
return Render;
|
|
263
|
+
});
|
|
264
|
+
if (!Render) return null;
|
|
265
|
+
return <Render {...props} />;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const DataUIDisplay = ({
|
|
269
|
+
Fallback,
|
|
270
|
+
...props
|
|
271
|
+
}: {
|
|
272
|
+
Fallback: DataMessagePartComponent | undefined;
|
|
273
|
+
} & DataMessagePartProps) => {
|
|
274
|
+
const Render = useAuiState((s) => {
|
|
275
|
+
const Render = s.dataRenderers.renderers[props.name] ?? Fallback;
|
|
276
|
+
if (Array.isArray(Render)) return Render[0] ?? Fallback;
|
|
277
|
+
return Render;
|
|
278
|
+
});
|
|
279
|
+
if (!Render) return null;
|
|
280
|
+
return <Render {...props} />;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Platform-agnostic no-op default components.
|
|
285
|
+
* Each platform (web, RN) wraps MessagePrimitiveParts with its own defaults.
|
|
286
|
+
*/
|
|
287
|
+
export const defaultComponents = {
|
|
288
|
+
Text: () => null,
|
|
289
|
+
Reasoning: () => null,
|
|
290
|
+
Source: () => null,
|
|
291
|
+
Image: () => null,
|
|
292
|
+
File: () => null,
|
|
293
|
+
Unstable_Audio: () => null,
|
|
294
|
+
ToolGroup: ({ children }: PropsWithChildren) => children,
|
|
295
|
+
ReasoningGroup: ({ children }: PropsWithChildren) => children,
|
|
296
|
+
} satisfies MessagePrimitiveParts.Props["components"];
|
|
297
|
+
|
|
298
|
+
type MessagePartComponentProps = {
|
|
299
|
+
components: MessagePrimitiveParts.Props["components"];
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
export const MessagePartComponent: FC<MessagePartComponentProps> = ({
|
|
303
|
+
components: {
|
|
304
|
+
Text = defaultComponents.Text,
|
|
305
|
+
Reasoning = defaultComponents.Reasoning,
|
|
306
|
+
Image = defaultComponents.Image,
|
|
307
|
+
Source = defaultComponents.Source,
|
|
308
|
+
File = defaultComponents.File,
|
|
309
|
+
Unstable_Audio: Audio = defaultComponents.Unstable_Audio,
|
|
310
|
+
tools = {},
|
|
311
|
+
data,
|
|
312
|
+
} = {},
|
|
313
|
+
}) => {
|
|
314
|
+
const aui = useAui();
|
|
315
|
+
const part = useAuiState((s) => s.part);
|
|
316
|
+
|
|
317
|
+
const type = part.type;
|
|
318
|
+
if (type === "tool-call") {
|
|
319
|
+
const addResult = aui.part().addToolResult;
|
|
320
|
+
const resume = aui.part().resumeToolCall;
|
|
321
|
+
if ("Override" in tools)
|
|
322
|
+
return <tools.Override {...part} addResult={addResult} resume={resume} />;
|
|
323
|
+
const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;
|
|
324
|
+
return (
|
|
325
|
+
<ToolUIDisplay
|
|
326
|
+
{...part}
|
|
327
|
+
Fallback={Tool}
|
|
328
|
+
addResult={addResult}
|
|
329
|
+
resume={resume}
|
|
330
|
+
/>
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (part.status?.type === "requires-action")
|
|
335
|
+
throw new Error("Encountered unexpected requires-action status");
|
|
336
|
+
|
|
337
|
+
switch (type) {
|
|
338
|
+
case "text":
|
|
339
|
+
return <Text {...part} />;
|
|
340
|
+
|
|
341
|
+
case "reasoning":
|
|
342
|
+
return <Reasoning {...part} />;
|
|
343
|
+
|
|
344
|
+
case "source":
|
|
345
|
+
return <Source {...part} />;
|
|
346
|
+
|
|
347
|
+
case "image":
|
|
348
|
+
return <Image {...part} />;
|
|
349
|
+
|
|
350
|
+
case "file":
|
|
351
|
+
return <File {...part} />;
|
|
352
|
+
|
|
353
|
+
case "audio":
|
|
354
|
+
return <Audio {...part} />;
|
|
355
|
+
|
|
356
|
+
case "data": {
|
|
357
|
+
const Data = data?.by_name?.[part.name] ?? data?.Fallback;
|
|
358
|
+
return <DataUIDisplay {...part} Fallback={Data} />;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
default:
|
|
362
|
+
console.warn(`Unknown message part type: ${type}`);
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
export namespace MessagePrimitivePartByIndex {
|
|
368
|
+
export type Props = {
|
|
369
|
+
index: number;
|
|
370
|
+
components: MessagePrimitiveParts.Props["components"];
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Renders a single message part at the specified index.
|
|
376
|
+
*/
|
|
377
|
+
export const MessagePrimitivePartByIndex: FC<MessagePrimitivePartByIndex.Props> =
|
|
378
|
+
memo(
|
|
379
|
+
({ index, components }) => {
|
|
380
|
+
return (
|
|
381
|
+
<PartByIndexProvider index={index}>
|
|
382
|
+
<MessagePartComponent components={components} />
|
|
383
|
+
</PartByIndexProvider>
|
|
384
|
+
);
|
|
385
|
+
},
|
|
386
|
+
(prev, next) =>
|
|
387
|
+
prev.index === next.index &&
|
|
388
|
+
prev.components?.Text === next.components?.Text &&
|
|
389
|
+
prev.components?.Reasoning === next.components?.Reasoning &&
|
|
390
|
+
prev.components?.Source === next.components?.Source &&
|
|
391
|
+
prev.components?.Image === next.components?.Image &&
|
|
392
|
+
prev.components?.File === next.components?.File &&
|
|
393
|
+
prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&
|
|
394
|
+
prev.components?.tools === next.components?.tools &&
|
|
395
|
+
prev.components?.data === next.components?.data &&
|
|
396
|
+
prev.components?.ToolGroup === next.components?.ToolGroup &&
|
|
397
|
+
prev.components?.ReasoningGroup === next.components?.ReasoningGroup,
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
MessagePrimitivePartByIndex.displayName = "MessagePrimitive.PartByIndex";
|
|
401
|
+
|
|
402
|
+
const EmptyPartFallback: FC<{
|
|
403
|
+
status: MessagePartStatus;
|
|
404
|
+
component: TextMessagePartComponent;
|
|
405
|
+
}> = ({ status, component: Component }) => {
|
|
406
|
+
return (
|
|
407
|
+
<TextMessagePartProvider text="" isRunning={status.type === "running"}>
|
|
408
|
+
<Component type="text" text="" status={status} />
|
|
409
|
+
</TextMessagePartProvider>
|
|
410
|
+
);
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
const COMPLETE_STATUS: MessagePartStatus = Object.freeze({
|
|
414
|
+
type: "complete",
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const EmptyPartsImpl: FC<MessagePartComponentProps> = ({ components }) => {
|
|
418
|
+
const status = useAuiState(
|
|
419
|
+
(s) => (s.message.status ?? COMPLETE_STATUS) as MessagePartStatus,
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
if (components?.Empty) return <components.Empty status={status} />;
|
|
423
|
+
|
|
424
|
+
return (
|
|
425
|
+
<EmptyPartFallback
|
|
426
|
+
status={status}
|
|
427
|
+
component={components?.Text ?? defaultComponents.Text}
|
|
428
|
+
/>
|
|
429
|
+
);
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
const EmptyParts = memo(
|
|
433
|
+
EmptyPartsImpl,
|
|
434
|
+
(prev, next) =>
|
|
435
|
+
prev.components?.Empty === next.components?.Empty &&
|
|
436
|
+
prev.components?.Text === next.components?.Text,
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
const ConditionalEmptyImpl: FC<{
|
|
440
|
+
components: MessagePrimitiveParts.Props["components"];
|
|
441
|
+
enabled: boolean;
|
|
442
|
+
}> = ({ components, enabled }) => {
|
|
443
|
+
const shouldShowEmpty = useAuiState((s) => {
|
|
444
|
+
if (!enabled) return false;
|
|
445
|
+
if (s.message.parts.length === 0) return false;
|
|
446
|
+
|
|
447
|
+
const lastPart = s.message.parts[s.message.parts.length - 1];
|
|
448
|
+
return lastPart?.type !== "text" && lastPart?.type !== "reasoning";
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
if (!shouldShowEmpty) return null;
|
|
452
|
+
return <EmptyParts components={components} />;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const ConditionalEmpty = memo(
|
|
456
|
+
ConditionalEmptyImpl,
|
|
457
|
+
(prev, next) =>
|
|
458
|
+
prev.enabled === next.enabled &&
|
|
459
|
+
prev.components?.Empty === next.components?.Empty &&
|
|
460
|
+
prev.components?.Text === next.components?.Text,
|
|
461
|
+
);
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Renders the parts of a message with support for multiple content types.
|
|
465
|
+
*
|
|
466
|
+
* This is the platform-agnostic base. Each platform wraps this with its own
|
|
467
|
+
* default components (web uses `<p>`, `<span>`; RN would use `<Text>`, etc.).
|
|
468
|
+
*/
|
|
469
|
+
export const MessagePrimitiveParts: FC<MessagePrimitiveParts.Props> = ({
|
|
470
|
+
components,
|
|
471
|
+
unstable_showEmptyOnNonTextEnd = true,
|
|
472
|
+
}) => {
|
|
473
|
+
const contentLength = useAuiState((s) => s.message.parts.length);
|
|
474
|
+
const useChainOfThought = !!components?.ChainOfThought;
|
|
475
|
+
const messageRanges = useMessagePartsGroups(useChainOfThought);
|
|
476
|
+
|
|
477
|
+
const partsElements = useMemo(() => {
|
|
478
|
+
if (contentLength === 0) {
|
|
479
|
+
return <EmptyParts components={components} />;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return messageRanges.map((range) => {
|
|
483
|
+
if (range.type === "single") {
|
|
484
|
+
return (
|
|
485
|
+
<MessagePrimitivePartByIndex
|
|
486
|
+
key={range.index}
|
|
487
|
+
index={range.index}
|
|
488
|
+
components={components}
|
|
489
|
+
/>
|
|
490
|
+
);
|
|
491
|
+
} else if (range.type === "chainOfThoughtGroup") {
|
|
492
|
+
const ChainOfThoughtComponent = components?.ChainOfThought;
|
|
493
|
+
if (!ChainOfThoughtComponent) return null;
|
|
494
|
+
return (
|
|
495
|
+
<ChainOfThoughtByIndicesProvider
|
|
496
|
+
key={`chainOfThought-${range.startIndex}`}
|
|
497
|
+
startIndex={range.startIndex}
|
|
498
|
+
endIndex={range.endIndex}
|
|
499
|
+
>
|
|
500
|
+
<ChainOfThoughtComponent />
|
|
501
|
+
</ChainOfThoughtByIndicesProvider>
|
|
502
|
+
);
|
|
503
|
+
} else if (range.type === "toolGroup") {
|
|
504
|
+
const ToolGroupComponent =
|
|
505
|
+
components?.ToolGroup ?? defaultComponents.ToolGroup;
|
|
506
|
+
return (
|
|
507
|
+
<ToolGroupComponent
|
|
508
|
+
key={`tool-${range.startIndex}`}
|
|
509
|
+
startIndex={range.startIndex}
|
|
510
|
+
endIndex={range.endIndex}
|
|
511
|
+
>
|
|
512
|
+
{Array.from(
|
|
513
|
+
{ length: range.endIndex - range.startIndex + 1 },
|
|
514
|
+
(_, i) => (
|
|
515
|
+
<MessagePrimitivePartByIndex
|
|
516
|
+
key={i}
|
|
517
|
+
index={range.startIndex + i}
|
|
518
|
+
components={components}
|
|
519
|
+
/>
|
|
520
|
+
),
|
|
521
|
+
)}
|
|
522
|
+
</ToolGroupComponent>
|
|
523
|
+
);
|
|
524
|
+
} else {
|
|
525
|
+
// reasoningGroup
|
|
526
|
+
const ReasoningGroupComponent =
|
|
527
|
+
components?.ReasoningGroup ?? defaultComponents.ReasoningGroup;
|
|
528
|
+
return (
|
|
529
|
+
<ReasoningGroupComponent
|
|
530
|
+
key={`reasoning-${range.startIndex}`}
|
|
531
|
+
startIndex={range.startIndex}
|
|
532
|
+
endIndex={range.endIndex}
|
|
533
|
+
>
|
|
534
|
+
{Array.from(
|
|
535
|
+
{ length: range.endIndex - range.startIndex + 1 },
|
|
536
|
+
(_, i) => (
|
|
537
|
+
<MessagePrimitivePartByIndex
|
|
538
|
+
key={i}
|
|
539
|
+
index={range.startIndex + i}
|
|
540
|
+
components={components}
|
|
541
|
+
/>
|
|
542
|
+
),
|
|
543
|
+
)}
|
|
544
|
+
</ReasoningGroupComponent>
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
}, [messageRanges, components, contentLength]);
|
|
549
|
+
|
|
550
|
+
return (
|
|
551
|
+
<>
|
|
552
|
+
{partsElements}
|
|
553
|
+
<ConditionalEmpty
|
|
554
|
+
components={components}
|
|
555
|
+
enabled={unstable_showEmptyOnNonTextEnd}
|
|
556
|
+
/>
|
|
557
|
+
</>
|
|
558
|
+
);
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
MessagePrimitiveParts.displayName = "MessagePrimitive.Parts";
|