@assistant-ui/react 0.12.8 → 0.12.10
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/client/ExternalThread.d.ts.map +1 -1
- package/dist/client/ExternalThread.js +10 -0
- package/dist/client/ExternalThread.js.map +1 -1
- package/dist/client/NoOpComposerClient.d.ts.map +1 -1
- package/dist/client/NoOpComposerClient.js +4 -0
- package/dist/client/NoOpComposerClient.js.map +1 -1
- package/dist/context/providers/ChainOfThoughtByIndicesProvider.d.ts.map +1 -1
- package/dist/context/providers/ChainOfThoughtByIndicesProvider.js +1 -1
- package/dist/context/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
- package/dist/context/react/utils/ensureBinding.js +1 -1
- package/dist/context/react/utils/ensureBinding.js.map +1 -1
- package/dist/hooks/useMessageQuote.d.ts +17 -0
- package/dist/hooks/useMessageQuote.d.ts.map +1 -0
- package/dist/hooks/useMessageQuote.js +20 -0
- package/dist/hooks/useMessageQuote.js.map +1 -0
- package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/legacy-runtime/AssistantRuntimeProvider.js +1 -2
- package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
- package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ComposerRuntimeClient.js +2 -0
- package/dist/legacy-runtime/client/ComposerRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/hooks/AssistantContext.d.ts +1 -1
- package/dist/legacy-runtime/hooks/AssistantContext.js +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.js +1 -1
- package/dist/legacy-runtime/hooks/ComposerContext.d.ts +6 -6
- package/dist/legacy-runtime/hooks/ComposerContext.js +4 -4
- package/dist/legacy-runtime/hooks/MessageContext.d.ts +5 -5
- package/dist/legacy-runtime/hooks/MessageContext.js +5 -5
- package/dist/legacy-runtime/hooks/MessagePartContext.d.ts +1 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.js +1 -1
- package/dist/legacy-runtime/hooks/ThreadContext.d.ts +5 -5
- package/dist/legacy-runtime/hooks/ThreadContext.js +4 -4
- package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts +1 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js +1 -1
- package/dist/legacy-runtime/runtime/ComposerRuntime.d.ts +12 -0
- package/dist/legacy-runtime/runtime/ComposerRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime/ComposerRuntime.js +9 -0
- package/dist/legacy-runtime/runtime/ComposerRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts +2 -0
- package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +5 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +36 -26
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js +7 -7
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/composer/BaseComposerRuntimeCore.d.ts +4 -0
- package/dist/legacy-runtime/runtime-cores/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/composer/BaseComposerRuntimeCore.js +16 -2
- package/dist/legacy-runtime/runtime-cores/composer/BaseComposerRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/ComposerRuntimeCore.d.ts +3 -0
- package/dist/legacy-runtime/runtime-cores/core/ComposerRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.js +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.js +1 -1
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js +4 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.js +7 -6
- package/dist/primitives/actionBar/ActionBarCopy.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarEdit.js +1 -1
- package/dist/primitives/actionBar/ActionBarEdit.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js +4 -3
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarSpeak.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarSpeak.js +4 -3
- package/dist/primitives/actionBar/ActionBarSpeak.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarStopSpeaking.js +1 -1
- package/dist/primitives/actionBar/ActionBarStopSpeaking.js.map +1 -1
- package/dist/primitives/actionBar/useActionBarFloatStatus.js +5 -5
- package/dist/primitives/actionBar/useActionBarFloatStatus.js.map +1 -1
- package/dist/primitives/attachment/AttachmentName.js +1 -1
- package/dist/primitives/attachment/AttachmentName.js.map +1 -1
- package/dist/primitives/attachment/AttachmentThumb.js +2 -2
- package/dist/primitives/attachment/AttachmentThumb.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerCount.js +1 -1
- package/dist/primitives/branchPicker/BranchPickerCount.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerNext.js +3 -3
- package/dist/primitives/branchPicker/BranchPickerNext.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerNumber.js +1 -1
- package/dist/primitives/branchPicker/BranchPickerNumber.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerPrevious.js +3 -3
- package/dist/primitives/branchPicker/BranchPickerPrevious.js.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.d.ts.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtParts.d.ts +3 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtParts.d.ts.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtParts.js +5 -7
- package/dist/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.js +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.js.map +1 -1
- package/dist/primitives/composer/ComposerAttachments.js +1 -1
- package/dist/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/primitives/composer/ComposerCancel.js +1 -1
- package/dist/primitives/composer/ComposerCancel.js.map +1 -1
- package/dist/primitives/composer/ComposerDictate.js +3 -3
- package/dist/primitives/composer/ComposerDictate.js.map +1 -1
- package/dist/primitives/composer/ComposerDictationTranscript.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerDictationTranscript.js +1 -1
- package/dist/primitives/composer/ComposerDictationTranscript.js.map +1 -1
- package/dist/primitives/composer/ComposerIf.js +4 -4
- package/dist/primitives/composer/ComposerIf.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.d.ts +35 -45
- package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +25 -9
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerQuote.d.ts +52 -0
- package/dist/primitives/composer/ComposerQuote.d.ts.map +1 -0
- package/dist/primitives/composer/ComposerQuote.js +57 -0
- package/dist/primitives/composer/ComposerQuote.js.map +1 -0
- package/dist/primitives/composer/ComposerStopDictation.js +1 -1
- package/dist/primitives/composer/ComposerStopDictation.js.map +1 -1
- package/dist/primitives/composer/index.d.ts +3 -0
- package/dist/primitives/composer/index.d.ts.map +1 -1
- package/dist/primitives/composer/index.js +3 -0
- package/dist/primitives/composer/index.js.map +1 -1
- package/dist/primitives/error/ErrorMessage.js +4 -4
- package/dist/primitives/error/ErrorMessage.js.map +1 -1
- package/dist/primitives/index.d.ts +2 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/message/MessageAttachments.js +4 -4
- package/dist/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/primitives/message/MessageError.js +2 -2
- package/dist/primitives/message/MessageError.js.map +1 -1
- package/dist/primitives/message/MessageIf.js +3 -3
- package/dist/primitives/message/MessageIf.js.map +1 -1
- package/dist/primitives/message/MessageParts.d.ts +140 -133
- package/dist/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/primitives/message/MessageParts.js +7 -7
- package/dist/primitives/message/MessageParts.js.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.js +5 -5
- package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
- package/dist/primitives/message/MessageRoot.d.ts.map +1 -1
- package/dist/primitives/message/MessageRoot.js +6 -5
- package/dist/primitives/message/MessageRoot.js.map +1 -1
- package/dist/primitives/messagePart/MessagePartInProgress.d.ts.map +1 -1
- package/dist/primitives/messagePart/MessagePartInProgress.js +1 -1
- package/dist/primitives/messagePart/MessagePartInProgress.js.map +1 -1
- package/dist/primitives/messagePart/useMessagePartData.js +3 -3
- package/dist/primitives/messagePart/useMessagePartData.js.map +1 -1
- package/dist/primitives/messagePart/useMessagePartFile.js +3 -3
- package/dist/primitives/messagePart/useMessagePartFile.js.map +1 -1
- package/dist/primitives/messagePart/useMessagePartImage.js +3 -3
- package/dist/primitives/messagePart/useMessagePartImage.js.map +1 -1
- package/dist/primitives/messagePart/useMessagePartReasoning.js +3 -3
- package/dist/primitives/messagePart/useMessagePartReasoning.js.map +1 -1
- package/dist/primitives/messagePart/useMessagePartSource.js +3 -3
- package/dist/primitives/messagePart/useMessagePartSource.js.map +1 -1
- package/dist/primitives/messagePart/useMessagePartText.d.ts.map +1 -1
- package/dist/primitives/messagePart/useMessagePartText.js +3 -3
- package/dist/primitives/messagePart/useMessagePartText.js.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.d.ts +24 -0
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.d.ts.map +1 -0
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js +37 -0
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js.map +1 -0
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.d.ts +31 -0
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.d.ts.map +1 -0
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js +85 -0
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js.map +1 -0
- package/dist/primitives/selectionToolbar/index.d.ts +3 -0
- package/dist/primitives/selectionToolbar/index.d.ts.map +1 -0
- package/dist/primitives/selectionToolbar/index.js +3 -0
- package/dist/primitives/selectionToolbar/index.js.map +1 -0
- package/dist/primitives/suggestion/SuggestionDescription.js +1 -1
- package/dist/primitives/suggestion/SuggestionDescription.js.map +1 -1
- package/dist/primitives/suggestion/SuggestionTitle.js +1 -1
- package/dist/primitives/suggestion/SuggestionTitle.js.map +1 -1
- package/dist/primitives/suggestion/SuggestionTrigger.d.ts.map +1 -1
- package/dist/primitives/suggestion/SuggestionTrigger.js +6 -3
- package/dist/primitives/suggestion/SuggestionTrigger.js.map +1 -1
- package/dist/primitives/thread/ThreadEmpty.js +1 -1
- package/dist/primitives/thread/ThreadEmpty.js.map +1 -1
- package/dist/primitives/thread/ThreadIf.js +7 -7
- package/dist/primitives/thread/ThreadIf.js.map +1 -1
- package/dist/primitives/thread/ThreadMessages.js +3 -3
- package/dist/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/primitives/thread/ThreadSuggestion.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadSuggestion.js +5 -2
- package/dist/primitives/thread/ThreadSuggestion.js.map +1 -1
- package/dist/primitives/thread/ThreadSuggestions.js +1 -1
- package/dist/primitives/thread/ThreadSuggestions.js.map +1 -1
- package/dist/primitives/thread/ThreadViewportSlack.js +4 -4
- package/dist/primitives/thread/ThreadViewportSlack.js.map +1 -1
- package/dist/primitives/threadList/ThreadListItems.js +1 -1
- package/dist/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/primitives/threadList/ThreadListNew.js +1 -1
- package/dist/primitives/threadList/ThreadListNew.js.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemRoot.js +1 -1
- package/dist/primitives/threadListItem/ThreadListItemRoot.js.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemTitle.js +1 -1
- package/dist/primitives/threadListItem/ThreadListItemTitle.js.map +1 -1
- package/dist/types/QuoteTypes.d.ts +5 -0
- package/dist/types/QuoteTypes.d.ts.map +1 -0
- package/dist/types/QuoteTypes.js +2 -0
- package/dist/types/QuoteTypes.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/scopes/composer.d.ts +10 -0
- package/dist/types/scopes/composer.d.ts.map +1 -1
- package/dist/utils/getSelectionMessageId.d.ts +2 -0
- package/dist/utils/getSelectionMessageId.d.ts.map +1 -0
- package/dist/utils/getSelectionMessageId.js +21 -0
- package/dist/utils/getSelectionMessageId.js.map +1 -0
- package/dist/utils/smooth/useSmooth.js +1 -1
- package/dist/utils/smooth/useSmooth.js.map +1 -1
- package/dist/utils/useToolArgsFieldStatus.js +5 -5
- package/dist/utils/useToolArgsFieldStatus.js.map +1 -1
- package/package.json +7 -7
- package/src/client/ExternalThread.ts +12 -0
- package/src/client/NoOpComposerClient.tsx +4 -0
- package/src/context/providers/ChainOfThoughtByIndicesProvider.tsx +3 -2
- package/src/context/react/utils/ensureBinding.ts +1 -1
- package/src/hooks/useMessageQuote.ts +27 -0
- package/src/legacy-runtime/AssistantRuntimeProvider.tsx +1 -4
- package/src/legacy-runtime/client/ComposerRuntimeClient.ts +2 -0
- package/src/legacy-runtime/hooks/AssistantContext.ts +1 -1
- package/src/legacy-runtime/hooks/AttachmentContext.ts +1 -1
- package/src/legacy-runtime/hooks/ComposerContext.ts +6 -6
- package/src/legacy-runtime/hooks/MessageContext.ts +5 -5
- package/src/legacy-runtime/hooks/MessagePartContext.ts +1 -1
- package/src/legacy-runtime/hooks/ThreadContext.ts +5 -5
- package/src/legacy-runtime/hooks/ThreadListItemContext.ts +1 -1
- package/src/legacy-runtime/runtime/ComposerRuntime.ts +22 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +5 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +41 -31
- package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts +8 -8
- package/src/legacy-runtime/runtime-cores/composer/BaseComposerRuntimeCore.tsx +21 -2
- package/src/legacy-runtime/runtime-cores/core/ComposerRuntimeCore.tsx +4 -0
- package/src/legacy-runtime/runtime-cores/external-store/createMessageConverter.tsx +2 -2
- package/src/legacy-runtime/runtime-cores/local/useLocalRuntime.tsx +1 -3
- package/src/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.tsx +6 -0
- package/src/primitives/actionBar/ActionBarCopy.tsx +7 -6
- package/src/primitives/actionBar/ActionBarEdit.tsx +1 -1
- package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +4 -3
- package/src/primitives/actionBar/ActionBarSpeak.tsx +4 -3
- package/src/primitives/actionBar/ActionBarStopSpeaking.tsx +1 -1
- package/src/primitives/actionBar/useActionBarFloatStatus.tsx +5 -5
- package/src/primitives/attachment/AttachmentName.tsx +1 -1
- package/src/primitives/attachment/AttachmentThumb.tsx +2 -2
- package/src/primitives/branchPicker/BranchPickerCount.tsx +1 -1
- package/src/primitives/branchPicker/BranchPickerNext.tsx +3 -3
- package/src/primitives/branchPicker/BranchPickerNumber.tsx +1 -1
- package/src/primitives/branchPicker/BranchPickerPrevious.tsx +3 -3
- package/src/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.tsx +1 -3
- package/src/primitives/chainOfThought/ChainOfThoughtParts.tsx +19 -11
- package/src/primitives/composer/ComposerAddAttachment.tsx +1 -1
- package/src/primitives/composer/ComposerAttachments.tsx +1 -1
- package/src/primitives/composer/ComposerCancel.tsx +1 -1
- package/src/primitives/composer/ComposerDictate.tsx +4 -4
- package/src/primitives/composer/ComposerDictationTranscript.tsx +1 -3
- package/src/primitives/composer/ComposerIf.tsx +4 -4
- package/src/primitives/composer/ComposerInput.tsx +57 -17
- package/src/primitives/composer/ComposerQuote.tsx +109 -0
- package/src/primitives/composer/ComposerStopDictation.tsx +1 -1
- package/src/primitives/composer/index.ts +3 -0
- package/src/primitives/error/ErrorMessage.tsx +4 -4
- package/src/primitives/index.ts +2 -0
- package/src/primitives/message/MessageAttachments.tsx +4 -4
- package/src/primitives/message/MessageError.tsx +3 -3
- package/src/primitives/message/MessageIf.tsx +3 -3
- package/src/primitives/message/MessageParts.tsx +156 -148
- package/src/primitives/message/MessagePartsGrouped.tsx +5 -5
- package/src/primitives/message/MessageRoot.tsx +6 -5
- package/src/primitives/messagePart/MessagePartInProgress.tsx +1 -3
- package/src/primitives/messagePart/useMessagePartData.tsx +3 -3
- package/src/primitives/messagePart/useMessagePartFile.tsx +3 -3
- package/src/primitives/messagePart/useMessagePartImage.tsx +3 -3
- package/src/primitives/messagePart/useMessagePartReasoning.tsx +3 -3
- package/src/primitives/messagePart/useMessagePartSource.tsx +3 -3
- package/src/primitives/messagePart/useMessagePartText.tsx +4 -3
- package/src/primitives/selectionToolbar/SelectionToolbarQuote.tsx +62 -0
- package/src/primitives/selectionToolbar/SelectionToolbarRoot.tsx +131 -0
- package/src/primitives/selectionToolbar/index.ts +8 -0
- package/src/primitives/suggestion/SuggestionDescription.tsx +1 -1
- package/src/primitives/suggestion/SuggestionTitle.tsx +1 -1
- package/src/primitives/suggestion/SuggestionTrigger.tsx +6 -3
- package/src/primitives/thread/ThreadEmpty.tsx +1 -1
- package/src/primitives/thread/ThreadIf.tsx +8 -8
- package/src/primitives/thread/ThreadMessages.tsx +3 -3
- package/src/primitives/thread/ThreadSuggestion.tsx +5 -2
- package/src/primitives/thread/ThreadSuggestions.tsx +1 -1
- package/src/primitives/thread/ThreadViewportSlack.tsx +5 -5
- package/src/primitives/threadList/ThreadListItems.tsx +2 -2
- package/src/primitives/threadList/ThreadListNew.tsx +1 -1
- package/src/primitives/threadListItem/ThreadListItemRoot.tsx +1 -1
- package/src/primitives/threadListItem/ThreadListItemTitle.tsx +1 -1
- package/src/types/QuoteTypes.ts +4 -0
- package/src/types/index.ts +2 -0
- package/src/types/scopes/composer.ts +12 -0
- package/src/utils/getSelectionMessageId.ts +20 -0
- package/src/utils/smooth/useSmooth.tsx +1 -1
- package/src/utils/useToolArgsFieldStatus.tsx +5 -5
- package/src/primitives/chainOfThought/CHAIN_OF_THOUGHT.spec.md +0 -68
|
@@ -145,154 +145,162 @@ const useMessagePartsGroups = (
|
|
|
145
145
|
};
|
|
146
146
|
|
|
147
147
|
export namespace MessagePrimitiveParts {
|
|
148
|
+
type BaseComponents = {
|
|
149
|
+
/** Component for rendering empty messages */
|
|
150
|
+
Empty?: EmptyMessagePartComponent | undefined;
|
|
151
|
+
/** Component for rendering text content */
|
|
152
|
+
Text?: TextMessagePartComponent | undefined;
|
|
153
|
+
/** Component for rendering source content */
|
|
154
|
+
Source?: SourceMessagePartComponent | undefined;
|
|
155
|
+
/** Component for rendering image content */
|
|
156
|
+
Image?: ImageMessagePartComponent | undefined;
|
|
157
|
+
/** Component for rendering file content */
|
|
158
|
+
File?: FileMessagePartComponent | undefined;
|
|
159
|
+
/** Component for rendering audio content (experimental) */
|
|
160
|
+
Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
type ToolsConfig =
|
|
164
|
+
| {
|
|
165
|
+
/** Map of tool names to their specific components */
|
|
166
|
+
by_name?:
|
|
167
|
+
| Record<string, ToolCallMessagePartComponent | undefined>
|
|
168
|
+
| undefined;
|
|
169
|
+
/** Fallback component for unregistered tools */
|
|
170
|
+
Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;
|
|
171
|
+
}
|
|
172
|
+
| {
|
|
173
|
+
/** Override component that handles all tool calls */
|
|
174
|
+
Override: ComponentType<ToolCallMessagePartProps>;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Standard component configuration for rendering reasoning and tool-call parts
|
|
179
|
+
* individually (with optional grouping).
|
|
180
|
+
*
|
|
181
|
+
* Cannot be combined with `ChainOfThought`.
|
|
182
|
+
*/
|
|
183
|
+
type StandardComponents = BaseComponents & {
|
|
184
|
+
/** Component for rendering reasoning content (typically hidden) */
|
|
185
|
+
Reasoning?: ReasoningMessagePartComponent | undefined;
|
|
186
|
+
/** Configuration for tool call rendering */
|
|
187
|
+
tools?: ToolsConfig | undefined;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Component for rendering grouped consecutive tool calls.
|
|
191
|
+
*
|
|
192
|
+
* When provided, this component will automatically wrap consecutive tool-call
|
|
193
|
+
* message parts, allowing you to create collapsible sections, custom styling,
|
|
194
|
+
* or other grouped presentations for multiple tool calls.
|
|
195
|
+
*
|
|
196
|
+
* The component receives:
|
|
197
|
+
* - `startIndex`: The index of the first tool call in the group
|
|
198
|
+
* - `endIndex`: The index of the last tool call in the group
|
|
199
|
+
* - `children`: The rendered tool call components
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```tsx
|
|
203
|
+
* // Collapsible tool group
|
|
204
|
+
* ToolGroup: ({ startIndex, endIndex, children }) => (
|
|
205
|
+
* <details className="tool-group">
|
|
206
|
+
* <summary>
|
|
207
|
+
* {endIndex - startIndex + 1} tool calls
|
|
208
|
+
* </summary>
|
|
209
|
+
* <div className="tool-group-content">
|
|
210
|
+
* {children}
|
|
211
|
+
* </div>
|
|
212
|
+
* </details>
|
|
213
|
+
* )
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @param startIndex - Index of the first tool call in the group
|
|
217
|
+
* @param endIndex - Index of the last tool call in the group
|
|
218
|
+
* @param children - Rendered tool call components to display within the group
|
|
219
|
+
*
|
|
220
|
+
* @deprecated This feature is still experimental and subject to change.
|
|
221
|
+
*/
|
|
222
|
+
ToolGroup?: ComponentType<
|
|
223
|
+
PropsWithChildren<{ startIndex: number; endIndex: number }>
|
|
224
|
+
>;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Component for rendering grouped reasoning parts.
|
|
228
|
+
*
|
|
229
|
+
* When provided, this component will automatically wrap reasoning message parts
|
|
230
|
+
* (one or more consecutive) in a group container. Each reasoning part inside
|
|
231
|
+
* renders its own text independently - no text merging occurs.
|
|
232
|
+
*
|
|
233
|
+
* The component receives:
|
|
234
|
+
* - `startIndex`: The index of the first reasoning part in the group
|
|
235
|
+
* - `endIndex`: The index of the last reasoning part in the group
|
|
236
|
+
* - `children`: The rendered Reasoning components (one per part)
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```tsx
|
|
240
|
+
* // Collapsible reasoning group
|
|
241
|
+
* ReasoningGroup: ({ children }) => (
|
|
242
|
+
* <details className="reasoning-group">
|
|
243
|
+
* <summary>Reasoning</summary>
|
|
244
|
+
* <div className="reasoning-content">
|
|
245
|
+
* {children}
|
|
246
|
+
* </div>
|
|
247
|
+
* </details>
|
|
248
|
+
* )
|
|
249
|
+
* ```
|
|
250
|
+
*
|
|
251
|
+
* @param startIndex - Index of the first reasoning part in the group
|
|
252
|
+
* @param endIndex - Index of the last reasoning part in the group
|
|
253
|
+
* @param children - Rendered reasoning part components
|
|
254
|
+
*/
|
|
255
|
+
ReasoningGroup?: ReasoningGroupComponent;
|
|
256
|
+
|
|
257
|
+
ChainOfThought?: never;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Chain of thought component configuration.
|
|
262
|
+
*
|
|
263
|
+
* When `ChainOfThought` is set, it takes control of rendering ALL reasoning and
|
|
264
|
+
* tool-call parts in the message. The `Reasoning`, `tools`, `ReasoningGroup`, and
|
|
265
|
+
* `ToolGroup` components cannot be used alongside it.
|
|
266
|
+
*
|
|
267
|
+
* The component is automatically wrapped in a ChainOfThoughtByIndicesProvider
|
|
268
|
+
* that sets up the chainOfThought client scope with the correct parts.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```tsx
|
|
272
|
+
* // Chain of thought with accordion
|
|
273
|
+
* ChainOfThought: () => (
|
|
274
|
+
* <ChainOfThoughtPrimitive.Root>
|
|
275
|
+
* <ChainOfThoughtPrimitive.AccordionTrigger>
|
|
276
|
+
* Toggle reasoning
|
|
277
|
+
* </ChainOfThoughtPrimitive.AccordionTrigger>
|
|
278
|
+
* <ChainOfThoughtPrimitive.Parts />
|
|
279
|
+
* </ChainOfThoughtPrimitive.Root>
|
|
280
|
+
* )
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
type ChainOfThoughtComponents = BaseComponents & {
|
|
284
|
+
ChainOfThought: ComponentType;
|
|
285
|
+
|
|
286
|
+
Reasoning?: never;
|
|
287
|
+
tools?: never;
|
|
288
|
+
ToolGroup?: never;
|
|
289
|
+
ReasoningGroup?: never;
|
|
290
|
+
};
|
|
291
|
+
|
|
148
292
|
export type Props = {
|
|
149
293
|
/**
|
|
150
294
|
* Component configuration for rendering different types of message content.
|
|
151
295
|
*
|
|
152
296
|
* You can provide custom components for each content type (text, image, file, etc.)
|
|
153
297
|
* and configure tool rendering behavior. If not provided, default components will be used.
|
|
298
|
+
*
|
|
299
|
+
* Use either `Reasoning`/`tools`/`ToolGroup`/`ReasoningGroup` for standard rendering,
|
|
300
|
+
* or `ChainOfThought` to group all reasoning and tool-call parts into a single
|
|
301
|
+
* collapsible component. These two modes are mutually exclusive.
|
|
154
302
|
*/
|
|
155
|
-
components?:
|
|
156
|
-
| {
|
|
157
|
-
/** Component for rendering empty messages */
|
|
158
|
-
Empty?: EmptyMessagePartComponent | undefined;
|
|
159
|
-
/** Component for rendering text content */
|
|
160
|
-
Text?: TextMessagePartComponent | undefined;
|
|
161
|
-
/** Component for rendering reasoning content (typically hidden) */
|
|
162
|
-
Reasoning?: ReasoningMessagePartComponent | undefined;
|
|
163
|
-
/** Component for rendering source content */
|
|
164
|
-
Source?: SourceMessagePartComponent | undefined;
|
|
165
|
-
/** Component for rendering image content */
|
|
166
|
-
Image?: ImageMessagePartComponent | undefined;
|
|
167
|
-
/** Component for rendering file content */
|
|
168
|
-
File?: FileMessagePartComponent | undefined;
|
|
169
|
-
/** Component for rendering audio content (experimental) */
|
|
170
|
-
Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;
|
|
171
|
-
/** Configuration for tool call rendering */
|
|
172
|
-
tools?:
|
|
173
|
-
| {
|
|
174
|
-
/** Map of tool names to their specific components */
|
|
175
|
-
by_name?:
|
|
176
|
-
| Record<string, ToolCallMessagePartComponent | undefined>
|
|
177
|
-
| undefined;
|
|
178
|
-
/** Fallback component for unregistered tools */
|
|
179
|
-
Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;
|
|
180
|
-
}
|
|
181
|
-
| {
|
|
182
|
-
/** Override component that handles all tool calls */
|
|
183
|
-
Override: ComponentType<ToolCallMessagePartProps>;
|
|
184
|
-
}
|
|
185
|
-
| undefined;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Component for rendering grouped consecutive tool calls.
|
|
189
|
-
*
|
|
190
|
-
* When provided, this component will automatically wrap consecutive tool-call
|
|
191
|
-
* message parts, allowing you to create collapsible sections, custom styling,
|
|
192
|
-
* or other grouped presentations for multiple tool calls.
|
|
193
|
-
*
|
|
194
|
-
* The component receives:
|
|
195
|
-
* - `startIndex`: The index of the first tool call in the group
|
|
196
|
-
* - `endIndex`: The index of the last tool call in the group
|
|
197
|
-
* - `children`: The rendered tool call components
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* ```tsx
|
|
201
|
-
* // Collapsible tool group
|
|
202
|
-
* ToolGroup: ({ startIndex, endIndex, children }) => (
|
|
203
|
-
* <details className="tool-group">
|
|
204
|
-
* <summary>
|
|
205
|
-
* {endIndex - startIndex + 1} tool calls
|
|
206
|
-
* </summary>
|
|
207
|
-
* <div className="tool-group-content">
|
|
208
|
-
* {children}
|
|
209
|
-
* </div>
|
|
210
|
-
* </details>
|
|
211
|
-
* )
|
|
212
|
-
* ```
|
|
213
|
-
*
|
|
214
|
-
* @example
|
|
215
|
-
* ```tsx
|
|
216
|
-
* // Custom styled tool group with header
|
|
217
|
-
* ToolGroup: ({ startIndex, endIndex, children }) => (
|
|
218
|
-
* <div className="border rounded-lg p-4 my-2">
|
|
219
|
-
* <div className="text-sm text-gray-600 mb-2">
|
|
220
|
-
* Tool execution #{startIndex + 1}-{endIndex + 1}
|
|
221
|
-
* </div>
|
|
222
|
-
* <div className="space-y-2">
|
|
223
|
-
* {children}
|
|
224
|
-
* </div>
|
|
225
|
-
* </div>
|
|
226
|
-
* )
|
|
227
|
-
* ```
|
|
228
|
-
*
|
|
229
|
-
* @param startIndex - Index of the first tool call in the group
|
|
230
|
-
* @param endIndex - Index of the last tool call in the group
|
|
231
|
-
* @param children - Rendered tool call components to display within the group
|
|
232
|
-
*
|
|
233
|
-
* @deprecated This feature is still experimental and subject to change.
|
|
234
|
-
*/
|
|
235
|
-
ToolGroup?: ComponentType<
|
|
236
|
-
PropsWithChildren<{ startIndex: number; endIndex: number }>
|
|
237
|
-
>;
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Component for rendering grouped reasoning parts.
|
|
241
|
-
*
|
|
242
|
-
* When provided, this component will automatically wrap reasoning message parts
|
|
243
|
-
* (one or more consecutive) in a group container. Each reasoning part inside
|
|
244
|
-
* renders its own text independently - no text merging occurs.
|
|
245
|
-
*
|
|
246
|
-
* The component receives:
|
|
247
|
-
* - `startIndex`: The index of the first reasoning part in the group
|
|
248
|
-
* - `endIndex`: The index of the last reasoning part in the group
|
|
249
|
-
* - `children`: The rendered Reasoning components (one per part)
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```tsx
|
|
253
|
-
* // Collapsible reasoning group
|
|
254
|
-
* ReasoningGroup: ({ children }) => (
|
|
255
|
-
* <details className="reasoning-group">
|
|
256
|
-
* <summary>Reasoning</summary>
|
|
257
|
-
* <div className="reasoning-content">
|
|
258
|
-
* {children}
|
|
259
|
-
* </div>
|
|
260
|
-
* </details>
|
|
261
|
-
* )
|
|
262
|
-
* ```
|
|
263
|
-
*
|
|
264
|
-
* @param startIndex - Index of the first reasoning part in the group
|
|
265
|
-
* @param endIndex - Index of the last reasoning part in the group
|
|
266
|
-
* @param children - Rendered reasoning part components
|
|
267
|
-
*/
|
|
268
|
-
ReasoningGroup?: ReasoningGroupComponent;
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Component for rendering chain of thought (reasoning + tool-call) parts.
|
|
272
|
-
*
|
|
273
|
-
* When provided, this component takes control of rendering ALL reasoning and
|
|
274
|
-
* tool-call parts in the message. The Reasoning, tools, ReasoningGroup, and
|
|
275
|
-
* ToolGroup components are completely ignored when ChainOfThought is set.
|
|
276
|
-
*
|
|
277
|
-
* The component is automatically wrapped in a ChainOfThoughtByIndicesProvider
|
|
278
|
-
* that sets up the chainOfThought client scope with the correct parts.
|
|
279
|
-
*
|
|
280
|
-
* @example
|
|
281
|
-
* ```tsx
|
|
282
|
-
* // Chain of thought with accordion
|
|
283
|
-
* ChainOfThought: () => (
|
|
284
|
-
* <ChainOfThoughtPrimitive.Root>
|
|
285
|
-
* <ChainOfThoughtPrimitive.AccordionTrigger>
|
|
286
|
-
* Toggle reasoning
|
|
287
|
-
* </ChainOfThoughtPrimitive.AccordionTrigger>
|
|
288
|
-
* <ChainOfThoughtPrimitive.Parts />
|
|
289
|
-
* </ChainOfThoughtPrimitive.Root>
|
|
290
|
-
* )
|
|
291
|
-
* ```
|
|
292
|
-
*/
|
|
293
|
-
ChainOfThought?: ComponentType;
|
|
294
|
-
}
|
|
295
|
-
| undefined;
|
|
303
|
+
components?: StandardComponents | ChainOfThoughtComponents | undefined;
|
|
296
304
|
/**
|
|
297
305
|
* When enabled, shows the Empty component if the last part in the message
|
|
298
306
|
* is anything other than Text or Reasoning.
|
|
@@ -313,8 +321,8 @@ const ToolUIDisplay = ({
|
|
|
313
321
|
}: {
|
|
314
322
|
Fallback: ToolCallMessagePartComponent | undefined;
|
|
315
323
|
} & ToolCallMessagePartProps) => {
|
|
316
|
-
const Render = useAuiState((
|
|
317
|
-
const Render = tools.tools[props.toolName] ?? Fallback;
|
|
324
|
+
const Render = useAuiState((s) => {
|
|
325
|
+
const Render = s.tools.tools[props.toolName] ?? Fallback;
|
|
318
326
|
if (Array.isArray(Render)) return Render[0] ?? Fallback;
|
|
319
327
|
return Render;
|
|
320
328
|
});
|
|
@@ -356,7 +364,7 @@ export const MessagePartComponent: FC<MessagePartComponentProps> = ({
|
|
|
356
364
|
} = {},
|
|
357
365
|
}) => {
|
|
358
366
|
const aui = useAui();
|
|
359
|
-
const part = useAuiState((
|
|
367
|
+
const part = useAuiState((s) => s.part);
|
|
360
368
|
|
|
361
369
|
const type = part.type;
|
|
362
370
|
if (type === "tool-call") {
|
|
@@ -495,11 +503,11 @@ const ConditionalEmptyImpl: FC<{
|
|
|
495
503
|
components: MessagePrimitiveParts.Props["components"];
|
|
496
504
|
enabled: boolean;
|
|
497
505
|
}> = ({ components, enabled }) => {
|
|
498
|
-
const shouldShowEmpty = useAuiState((
|
|
506
|
+
const shouldShowEmpty = useAuiState((s) => {
|
|
499
507
|
if (!enabled) return false;
|
|
500
|
-
if (message.parts.length === 0) return false;
|
|
508
|
+
if (s.message.parts.length === 0) return false;
|
|
501
509
|
|
|
502
|
-
const lastPart = message.parts[message.parts.length - 1];
|
|
510
|
+
const lastPart = s.message.parts[s.message.parts.length - 1];
|
|
503
511
|
return lastPart?.type !== "text" && lastPart?.type !== "reasoning";
|
|
504
512
|
});
|
|
505
513
|
|
|
@@ -543,7 +551,7 @@ export const MessagePrimitiveParts: FC<MessagePrimitiveParts.Props> = ({
|
|
|
543
551
|
components,
|
|
544
552
|
unstable_showEmptyOnNonTextEnd = true,
|
|
545
553
|
}) => {
|
|
546
|
-
const contentLength = useAuiState((
|
|
554
|
+
const contentLength = useAuiState((s) => s.message.parts.length);
|
|
547
555
|
const useChainOfThought = !!components?.ChainOfThought;
|
|
548
556
|
const messageRanges = useMessagePartsGroups(useChainOfThought);
|
|
549
557
|
|
|
@@ -74,7 +74,7 @@ const groupMessagePartsByParentId: GroupingFunction = (
|
|
|
74
74
|
const useMessagePartsGrouped = (
|
|
75
75
|
groupingFunction: GroupingFunction,
|
|
76
76
|
): MessagePartGroup[] => {
|
|
77
|
-
const parts = useAuiState((
|
|
77
|
+
const parts = useAuiState((s) => s.message.parts);
|
|
78
78
|
|
|
79
79
|
return useMemo(() => {
|
|
80
80
|
if (parts.length === 0) {
|
|
@@ -219,8 +219,8 @@ const ToolUIDisplay = ({
|
|
|
219
219
|
}: {
|
|
220
220
|
Fallback: ToolCallMessagePartComponent | undefined;
|
|
221
221
|
} & ToolCallMessagePartProps) => {
|
|
222
|
-
const Render = useAuiState((
|
|
223
|
-
const Render = tools.tools[props.toolName] ?? Fallback;
|
|
222
|
+
const Render = useAuiState((s) => {
|
|
223
|
+
const Render = s.tools.tools[props.toolName] ?? Fallback;
|
|
224
224
|
if (Array.isArray(Render)) return Render[0] ?? Fallback;
|
|
225
225
|
return Render;
|
|
226
226
|
});
|
|
@@ -261,7 +261,7 @@ const MessagePartComponent: FC<MessagePartComponentProps> = ({
|
|
|
261
261
|
} = {},
|
|
262
262
|
}) => {
|
|
263
263
|
const aui = useAui();
|
|
264
|
-
const part = useAuiState((
|
|
264
|
+
const part = useAuiState((s) => s.part);
|
|
265
265
|
|
|
266
266
|
const type = part.type;
|
|
267
267
|
if (type === "tool-call") {
|
|
@@ -426,7 +426,7 @@ const EmptyParts = memo(
|
|
|
426
426
|
export const MessagePrimitiveUnstable_PartsGrouped: FC<
|
|
427
427
|
MessagePrimitiveUnstable_PartsGrouped.Props
|
|
428
428
|
> = ({ groupingFunction, components }) => {
|
|
429
|
-
const contentLength = useAuiState((
|
|
429
|
+
const contentLength = useAuiState((s) => s.message.parts.length);
|
|
430
430
|
const messageGroups = useMessagePartsGrouped(groupingFunction);
|
|
431
431
|
|
|
432
432
|
const partsElements = useMemo(() => {
|
|
@@ -60,11 +60,11 @@ const useMessageViewportRef = () => {
|
|
|
60
60
|
// inset rules:
|
|
61
61
|
// - the previous user message before the last assistant message registers its full height
|
|
62
62
|
const shouldRegisterAsInset = useAuiState(
|
|
63
|
-
(
|
|
63
|
+
(s) =>
|
|
64
64
|
turnAnchor === "top" &&
|
|
65
|
-
message.role === "user" &&
|
|
66
|
-
message.index === thread.messages.length - 2 &&
|
|
67
|
-
thread.messages.at(-1)?.role === "assistant",
|
|
65
|
+
s.message.role === "user" &&
|
|
66
|
+
s.message.index === s.thread.messages.length - 2 &&
|
|
67
|
+
s.thread.messages.at(-1)?.role === "assistant",
|
|
68
68
|
);
|
|
69
69
|
|
|
70
70
|
const getHeight = useCallback((el: HTMLElement) => el.offsetHeight, []);
|
|
@@ -116,10 +116,11 @@ export const MessagePrimitiveRoot = forwardRef<
|
|
|
116
116
|
isHoveringRef,
|
|
117
117
|
anchorUserMessageRef,
|
|
118
118
|
);
|
|
119
|
+
const messageId = useAuiState((s) => s.message.id);
|
|
119
120
|
|
|
120
121
|
return (
|
|
121
122
|
<ThreadPrimitiveViewportSlack>
|
|
122
|
-
<Primitive.div {...props} ref={ref} />
|
|
123
|
+
<Primitive.div {...props} ref={ref} data-message-id={messageId} />
|
|
123
124
|
</ThreadPrimitiveViewportSlack>
|
|
124
125
|
);
|
|
125
126
|
});
|
|
@@ -11,9 +11,7 @@ export namespace MessagePartPrimitiveInProgress {
|
|
|
11
11
|
export const MessagePartPrimitiveInProgress: FC<
|
|
12
12
|
MessagePartPrimitiveInProgress.Props
|
|
13
13
|
> = ({ children }) => {
|
|
14
|
-
const isInProgress = useAuiState(
|
|
15
|
-
({ part }) => part.status.type === "running",
|
|
16
|
-
);
|
|
14
|
+
const isInProgress = useAuiState((s) => s.part.status.type === "running");
|
|
17
15
|
|
|
18
16
|
return isInProgress ? children : null;
|
|
19
17
|
};
|
|
@@ -4,11 +4,11 @@ import { useAuiState } from "@assistant-ui/store";
|
|
|
4
4
|
import { DataMessagePart } from "../../types";
|
|
5
5
|
|
|
6
6
|
export const useMessagePartData = <T = any>(name?: string) => {
|
|
7
|
-
const part = useAuiState((
|
|
8
|
-
if (part.type !== "data") {
|
|
7
|
+
const part = useAuiState((s) => {
|
|
8
|
+
if (s.part.type !== "data") {
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
|
-
return part as DataMessagePart<T>;
|
|
11
|
+
return s.part as DataMessagePart<T>;
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
if (!part) {
|
|
@@ -5,13 +5,13 @@ import { useAuiState } from "@assistant-ui/store";
|
|
|
5
5
|
import { FileMessagePart } from "../../types";
|
|
6
6
|
|
|
7
7
|
export const useMessagePartFile = () => {
|
|
8
|
-
const file = useAuiState((
|
|
9
|
-
if (part.type !== "file")
|
|
8
|
+
const file = useAuiState((s) => {
|
|
9
|
+
if (s.part.type !== "file")
|
|
10
10
|
throw new Error(
|
|
11
11
|
"MessagePartFile can only be used inside file message parts.",
|
|
12
12
|
);
|
|
13
13
|
|
|
14
|
-
return part as MessagePartState & FileMessagePart;
|
|
14
|
+
return s.part as MessagePartState & FileMessagePart;
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
return file;
|
|
@@ -5,13 +5,13 @@ import { useAuiState } from "@assistant-ui/store";
|
|
|
5
5
|
import { ImageMessagePart } from "../../types";
|
|
6
6
|
|
|
7
7
|
export const useMessagePartImage = () => {
|
|
8
|
-
const image = useAuiState((
|
|
9
|
-
if (part.type !== "image")
|
|
8
|
+
const image = useAuiState((s) => {
|
|
9
|
+
if (s.part.type !== "image")
|
|
10
10
|
throw new Error(
|
|
11
11
|
"MessagePartImage can only be used inside image message parts.",
|
|
12
12
|
);
|
|
13
13
|
|
|
14
|
-
return part as MessagePartState & ImageMessagePart;
|
|
14
|
+
return s.part as MessagePartState & ImageMessagePart;
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
return image;
|
|
@@ -5,13 +5,13 @@ import { useAuiState } from "@assistant-ui/store";
|
|
|
5
5
|
import { ReasoningMessagePart } from "../../types";
|
|
6
6
|
|
|
7
7
|
export const useMessagePartReasoning = () => {
|
|
8
|
-
const text = useAuiState((
|
|
9
|
-
if (part.type !== "reasoning")
|
|
8
|
+
const text = useAuiState((s) => {
|
|
9
|
+
if (s.part.type !== "reasoning")
|
|
10
10
|
throw new Error(
|
|
11
11
|
"MessagePartReasoning can only be used inside reasoning message parts.",
|
|
12
12
|
);
|
|
13
13
|
|
|
14
|
-
return part as MessagePartState & ReasoningMessagePart;
|
|
14
|
+
return s.part as MessagePartState & ReasoningMessagePart;
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
return text;
|
|
@@ -5,13 +5,13 @@ import { useAuiState } from "@assistant-ui/store";
|
|
|
5
5
|
import { SourceMessagePart } from "../../types";
|
|
6
6
|
|
|
7
7
|
export const useMessagePartSource = () => {
|
|
8
|
-
const source = useAuiState((
|
|
9
|
-
if (part.type !== "source")
|
|
8
|
+
const source = useAuiState((s) => {
|
|
9
|
+
if (s.part.type !== "source")
|
|
10
10
|
throw new Error(
|
|
11
11
|
"MessagePartSource can only be used inside source message parts.",
|
|
12
12
|
);
|
|
13
13
|
|
|
14
|
-
return part as MessagePartState & SourceMessagePart;
|
|
14
|
+
return s.part as MessagePartState & SourceMessagePart;
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
return source;
|
|
@@ -5,13 +5,14 @@ import { useAuiState } from "@assistant-ui/store";
|
|
|
5
5
|
import { TextMessagePart, ReasoningMessagePart } from "../../types";
|
|
6
6
|
|
|
7
7
|
export const useMessagePartText = () => {
|
|
8
|
-
const text = useAuiState((
|
|
9
|
-
if (part.type !== "text" && part.type !== "reasoning")
|
|
8
|
+
const text = useAuiState((s) => {
|
|
9
|
+
if (s.part.type !== "text" && s.part.type !== "reasoning")
|
|
10
10
|
throw new Error(
|
|
11
11
|
"MessagePartText can only be used inside text or reasoning message parts.",
|
|
12
12
|
);
|
|
13
13
|
|
|
14
|
-
return part as MessagePartState &
|
|
14
|
+
return s.part as MessagePartState &
|
|
15
|
+
(TextMessagePart | ReasoningMessagePart);
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
return text;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Primitive } from "@radix-ui/react-primitive";
|
|
4
|
+
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
5
|
+
import {
|
|
6
|
+
type ComponentPropsWithoutRef,
|
|
7
|
+
type ComponentRef,
|
|
8
|
+
forwardRef,
|
|
9
|
+
useCallback,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { useAui } from "@assistant-ui/store";
|
|
12
|
+
import { useSelectionToolbarInfo } from "./SelectionToolbarRoot";
|
|
13
|
+
|
|
14
|
+
export namespace SelectionToolbarPrimitiveQuote {
|
|
15
|
+
export type Element = ComponentRef<typeof Primitive.button>;
|
|
16
|
+
export type Props = ComponentPropsWithoutRef<typeof Primitive.button>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A button that quotes the currently selected text.
|
|
21
|
+
*
|
|
22
|
+
* Must be placed inside `SelectionToolbarPrimitive.Root`. Reads the
|
|
23
|
+
* selection info from context (captured by the Root), sets it as a
|
|
24
|
+
* quote in the thread composer, and clears the selection.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <SelectionToolbarPrimitive.Quote>
|
|
29
|
+
* <QuoteIcon /> Quote
|
|
30
|
+
* </SelectionToolbarPrimitive.Quote>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const SelectionToolbarPrimitiveQuote = forwardRef<
|
|
34
|
+
SelectionToolbarPrimitiveQuote.Element,
|
|
35
|
+
SelectionToolbarPrimitiveQuote.Props
|
|
36
|
+
>(({ onClick, disabled, ...props }, forwardedRef) => {
|
|
37
|
+
const aui = useAui();
|
|
38
|
+
const info = useSelectionToolbarInfo();
|
|
39
|
+
|
|
40
|
+
const handleClick = useCallback(() => {
|
|
41
|
+
if (!info) return;
|
|
42
|
+
|
|
43
|
+
aui.thread().composer.setQuote({
|
|
44
|
+
text: info.text,
|
|
45
|
+
messageId: info.messageId,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
window.getSelection()?.removeAllRanges();
|
|
49
|
+
}, [aui, info]);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Primitive.button
|
|
53
|
+
type="button"
|
|
54
|
+
{...props}
|
|
55
|
+
ref={forwardedRef}
|
|
56
|
+
disabled={disabled || !info}
|
|
57
|
+
onClick={composeEventHandlers(onClick, handleClick)}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
SelectionToolbarPrimitiveQuote.displayName = "SelectionToolbarPrimitive.Quote";
|