@swisper.ai/web-chat-ui 0.0.2
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 +202 -0
- package/README.md +251 -0
- package/dist/components/canvas-shell/canvas-shell.d.ts +64 -0
- package/dist/components/canvas-shell/canvas-shell.d.ts.map +1 -0
- package/dist/components/canvas-shell/canvas-shell.stories.d.ts +26 -0
- package/dist/components/canvas-shell/canvas-shell.stories.d.ts.map +1 -0
- package/dist/components/canvas-shell/index.d.ts +2 -0
- package/dist/components/canvas-shell/index.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-context.d.ts +21 -0
- package/dist/components/card-item-picker/card-item-picker-context.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-list.d.ts +24 -0
- package/dist/components/card-item-picker/card-item-picker-list.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts +28 -0
- package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker-row.d.ts +12 -0
- package/dist/components/card-item-picker/card-item-picker-row.d.ts.map +1 -0
- package/dist/components/card-item-picker/card-item-picker.stories.d.ts +19 -0
- package/dist/components/card-item-picker/card-item-picker.stories.d.ts.map +1 -0
- package/dist/components/card-item-picker/index.d.ts +9 -0
- package/dist/components/card-item-picker/index.d.ts.map +1 -0
- package/dist/components/chat-card/chat-card.d.ts +4 -0
- package/dist/components/chat-card/chat-card.d.ts.map +1 -0
- package/dist/components/chat-card/chat-card.stories.d.ts +11 -0
- package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-body.d.ts +22 -0
- package/dist/components/chat-card/components/chat-card-body.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-footer.d.ts +20 -0
- package/dist/components/chat-card/components/chat-card-footer.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-form.d.ts +28 -0
- package/dist/components/chat-card/components/chat-card-form.d.ts.map +1 -0
- package/dist/components/chat-card/components/chat-card-header.d.ts +36 -0
- package/dist/components/chat-card/components/chat-card-header.d.ts.map +1 -0
- package/dist/components/chat-card/components/index.d.ts +5 -0
- package/dist/components/chat-card/components/index.d.ts.map +1 -0
- package/dist/components/chat-card/context.d.ts +13 -0
- package/dist/components/chat-card/context.d.ts.map +1 -0
- package/dist/components/chat-card/contexts.d.ts +16 -0
- package/dist/components/chat-card/contexts.d.ts.map +1 -0
- package/dist/components/chat-card/hooks.d.ts +13 -0
- package/dist/components/chat-card/hooks.d.ts.map +1 -0
- package/dist/components/chat-card/index.d.ts +6 -0
- package/dist/components/chat-card/index.d.ts.map +1 -0
- package/dist/components/chat-card/types.d.ts +21 -0
- package/dist/components/chat-card/types.d.ts.map +1 -0
- package/dist/components/chat-card-container/chat-card-container.d.ts +43 -0
- package/dist/components/chat-card-container/chat-card-container.d.ts.map +1 -0
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts +17 -0
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -0
- package/dist/components/chat-card-container/index.d.ts +3 -0
- package/dist/components/chat-card-container/index.d.ts.map +1 -0
- package/dist/components/chat-container/chat-container.d.ts +51 -0
- package/dist/components/chat-container/chat-container.d.ts.map +1 -0
- package/dist/components/chat-container/chat-container.stories.d.ts +21 -0
- package/dist/components/chat-container/chat-container.stories.d.ts.map +1 -0
- package/dist/components/chat-container/index.d.ts +3 -0
- package/dist/components/chat-container/index.d.ts.map +1 -0
- package/dist/components/chat-input/chat-input.d.ts +35 -0
- package/dist/components/chat-input/chat-input.d.ts.map +1 -0
- package/dist/components/chat-input/chat-input.stories.d.ts +14 -0
- package/dist/components/chat-input/chat-input.stories.d.ts.map +1 -0
- package/dist/components/chat-input/index.d.ts +3 -0
- package/dist/components/chat-input/index.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/auto-focus-plugin.d.ts +8 -0
- package/dist/components/chat-input/plugins/auto-focus-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/disabled-plugin.d.ts +7 -0
- package/dist/components/chat-input/plugins/disabled-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/focus-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/focus-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/has-value-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/has-value-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/hooks.d.ts +2 -0
- package/dist/components/chat-input/plugins/hooks.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/index.d.ts +8 -0
- package/dist/components/chat-input/plugins/index.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/markdown-plain-paste-plugin.d.ts +2 -0
- package/dist/components/chat-input/plugins/markdown-plain-paste-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/utils.d.ts +4 -0
- package/dist/components/chat-input/plugins/utils.d.ts.map +1 -0
- package/dist/components/chat-input/plugins/value-plugin.d.ts +6 -0
- package/dist/components/chat-input/plugins/value-plugin.d.ts.map +1 -0
- package/dist/components/chat-input/transformers.d.ts +3 -0
- package/dist/components/chat-input/transformers.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list-item.d.ts +8 -0
- package/dist/components/chat-list/chat-list-item.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list-items.d.ts +11 -0
- package/dist/components/chat-list/chat-list-items.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list.d.ts +63 -0
- package/dist/components/chat-list/chat-list.d.ts.map +1 -0
- package/dist/components/chat-list/chat-list.stories.d.ts +13 -0
- package/dist/components/chat-list/chat-list.stories.d.ts.map +1 -0
- package/dist/components/chat-list/index.d.ts +4 -0
- package/dist/components/chat-list/index.d.ts.map +1 -0
- package/dist/components/chat-message/chat-message.d.ts +17 -0
- package/dist/components/chat-message/chat-message.d.ts.map +1 -0
- package/dist/components/chat-message/chat-message.stories.d.ts +11 -0
- package/dist/components/chat-message/chat-message.stories.d.ts.map +1 -0
- package/dist/components/chat-message/index.d.ts +2 -0
- package/dist/components/chat-message/index.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts +9 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts +30 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +11 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/index.d.ts +4 -0
- package/dist/components/chat-message-attachment-card/index.d.ts.map +1 -0
- package/dist/components/chat-message-attachment-card/utils.d.ts +5 -0
- package/dist/components/chat-message-attachment-card/utils.d.ts.map +1 -0
- package/dist/components/chat-message-history/chat-message-history.d.ts +48 -0
- package/dist/components/chat-message-history/chat-message-history.d.ts.map +1 -0
- package/dist/components/chat-message-history/chat-message-history.stories.d.ts +7 -0
- package/dist/components/chat-message-history/chat-message-history.stories.d.ts.map +1 -0
- package/dist/components/chat-message-history/index.d.ts +2 -0
- package/dist/components/chat-message-history/index.d.ts.map +1 -0
- package/dist/components/chat-message-response/chat-message-response.d.ts +7 -0
- package/dist/components/chat-message-response/chat-message-response.d.ts.map +1 -0
- package/dist/components/chat-message-response/chat-message-response.stories.d.ts +7 -0
- package/dist/components/chat-message-response/chat-message-response.stories.d.ts.map +1 -0
- package/dist/components/chat-message-response/index.d.ts +2 -0
- package/dist/components/chat-message-response/index.d.ts.map +1 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts +25 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts.map +1 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts +7 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts.map +1 -0
- package/dist/components/chat-message-toolbar/index.d.ts +2 -0
- package/dist/components/chat-message-toolbar/index.d.ts.map +1 -0
- package/dist/components/chat-messages/chat-messages.d.ts +24 -0
- package/dist/components/chat-messages/chat-messages.d.ts.map +1 -0
- package/dist/components/chat-messages/chat-messages.stories.d.ts +8 -0
- package/dist/components/chat-messages/chat-messages.stories.d.ts.map +1 -0
- package/dist/components/chat-messages/index.d.ts +2 -0
- package/dist/components/chat-messages/index.d.ts.map +1 -0
- package/dist/components/chat-notification-card/chat-notification-card.d.ts +114 -0
- package/dist/components/chat-notification-card/chat-notification-card.d.ts.map +1 -0
- package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts +10 -0
- package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts.map +1 -0
- package/dist/components/chat-notification-card/index.d.ts +4 -0
- package/dist/components/chat-notification-card/index.d.ts.map +1 -0
- package/dist/components/chat-notification-card/types.d.ts +2 -0
- package/dist/components/chat-notification-card/types.d.ts.map +1 -0
- package/dist/components/chat-notification-card/utils.d.ts +3 -0
- package/dist/components/chat-notification-card/utils.d.ts.map +1 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.d.ts +12 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.d.ts.map +1 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts +8 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts.map +1 -0
- package/dist/components/chat-notification-popup/index.d.ts +2 -0
- package/dist/components/chat-notification-popup/index.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-context.d.ts +17 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-context.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-focus-plugin.d.ts +2 -0
- package/dist/components/chat-prompt-box/chat-prompt-box-focus-plugin.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.d.ts +27 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts +9 -0
- package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts.map +1 -0
- package/dist/components/chat-prompt-box/index.d.ts +3 -0
- package/dist/components/chat-prompt-box/index.d.ts.map +1 -0
- package/dist/components/chat-reply/chat-reply.d.ts +23 -0
- package/dist/components/chat-reply/chat-reply.d.ts.map +1 -0
- package/dist/components/chat-reply/chat-reply.stories.d.ts +7 -0
- package/dist/components/chat-reply/chat-reply.stories.d.ts.map +1 -0
- package/dist/components/chat-reply/index.d.ts +2 -0
- package/dist/components/chat-reply/index.d.ts.map +1 -0
- package/dist/components/chat-suggestion/chat-suggestion.d.ts +37 -0
- package/dist/components/chat-suggestion/chat-suggestion.d.ts.map +1 -0
- package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts +9 -0
- package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts.map +1 -0
- package/dist/components/chat-suggestion/index.d.ts +2 -0
- package/dist/components/chat-suggestion/index.d.ts.map +1 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +47 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +10 -0
- package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -0
- package/dist/components/chat-thinking-process/index.d.ts +2 -0
- package/dist/components/chat-thinking-process/index.d.ts.map +1 -0
- package/dist/components/chat-thread/chat-thread.d.ts +78 -0
- package/dist/components/chat-thread/chat-thread.d.ts.map +1 -0
- package/dist/components/chat-thread/chat-thread.stories.d.ts +14 -0
- package/dist/components/chat-thread/chat-thread.stories.d.ts.map +1 -0
- package/dist/components/chat-thread/index.d.ts +2 -0
- package/dist/components/chat-thread/index.d.ts.map +1 -0
- package/dist/components/deprecated-empty-state.d.ts +22 -0
- package/dist/components/deprecated-empty-state.d.ts.map +1 -0
- package/dist/components/index.d.ts +27 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/markdown-viewer/hooks.d.ts +9 -0
- package/dist/components/markdown-viewer/hooks.d.ts.map +1 -0
- package/dist/components/markdown-viewer/index.d.ts +3 -0
- package/dist/components/markdown-viewer/index.d.ts.map +1 -0
- package/dist/components/markdown-viewer/markdown-viewer.d.ts +10 -0
- package/dist/components/markdown-viewer/markdown-viewer.d.ts.map +1 -0
- package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts +9 -0
- package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts.map +1 -0
- package/dist/components/markdown-viewer/types.d.ts +9 -0
- package/dist/components/markdown-viewer/types.d.ts.map +1 -0
- package/dist/components/markdown-viewer/utils.d.ts +3 -0
- package/dist/components/markdown-viewer/utils.d.ts.map +1 -0
- package/dist/components/new-chat-trigger/index.d.ts +2 -0
- package/dist/components/new-chat-trigger/index.d.ts.map +1 -0
- package/dist/components/new-chat-trigger/new-chat-trigger.d.ts +8 -0
- package/dist/components/new-chat-trigger/new-chat-trigger.d.ts.map +1 -0
- package/dist/components/rich-text-area/constants/index.d.ts +3 -0
- package/dist/components/rich-text-area/constants/index.d.ts.map +1 -0
- package/dist/components/rich-text-area/hooks.d.ts +3 -0
- package/dist/components/rich-text-area/hooks.d.ts.map +1 -0
- package/dist/components/rich-text-area/html-config.d.ts +4 -0
- package/dist/components/rich-text-area/html-config.d.ts.map +1 -0
- package/dist/components/rich-text-area/index.d.ts +7 -0
- package/dist/components/rich-text-area/index.d.ts.map +1 -0
- package/dist/components/rich-text-area/nodes/div-block-node.d.ts +18 -0
- package/dist/components/rich-text-area/nodes/div-block-node.d.ts.map +1 -0
- package/dist/components/rich-text-area/nodes/image-node.d.ts +24 -0
- package/dist/components/rich-text-area/nodes/image-node.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/blur-plugin.d.ts +6 -0
- package/dist/components/rich-text-area/plugins/blur-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/controlled-plugin.d.ts +7 -0
- package/dist/components/rich-text-area/plugins/controlled-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts +7 -0
- package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/disabled-plugin.d.ts +6 -0
- package/dist/components/rich-text-area/plugins/disabled-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/file-attachment-plugin.d.ts +10 -0
- package/dist/components/rich-text-area/plugins/file-attachment-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/focus-plugin.d.ts +6 -0
- package/dist/components/rich-text-area/plugins/focus-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/html-paste-plugin.d.ts +19 -0
- package/dist/components/rich-text-area/plugins/html-paste-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/image-drop-plugin.d.ts +12 -0
- package/dist/components/rich-text-area/plugins/image-drop-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/index.d.ts +11 -0
- package/dist/components/rich-text-area/plugins/index.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/markdown-plain-paste-plugin.d.ts +2 -0
- package/dist/components/rich-text-area/plugins/markdown-plain-paste-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/plugins/value-plugin.d.ts +7 -0
- package/dist/components/rich-text-area/plugins/value-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-area/rich-text-area.d.ts +20 -0
- package/dist/components/rich-text-area/rich-text-area.d.ts.map +1 -0
- package/dist/components/rich-text-area/rich-text-area.stories.d.ts +7 -0
- package/dist/components/rich-text-area/rich-text-area.stories.d.ts.map +1 -0
- package/dist/components/rich-text-area/styled.d.ts +3 -0
- package/dist/components/rich-text-area/styled.d.ts.map +1 -0
- package/dist/components/rich-text-area/transformers.d.ts +16 -0
- package/dist/components/rich-text-area/transformers.d.ts.map +1 -0
- package/dist/components/rich-text-area/types.d.ts +8 -0
- package/dist/components/rich-text-area/types.d.ts.map +1 -0
- package/dist/components/rich-text-area/utils/index.d.ts +6 -0
- package/dist/components/rich-text-area/utils/index.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/alignment-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/alignment-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/attachment-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/attachment-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/bold-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/bold-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/clean-format-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/clean-format-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts +11 -0
- package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/image-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/image-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/index.d.ts +14 -0
- package/dist/components/rich-text-field/components/index.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/italic-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/italic-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/link-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/link-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/size-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/size-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/text-color-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/text-color-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/toolbar-button.d.ts +6 -0
- package/dist/components/rich-text-field/components/toolbar-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/toolbar-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/toolbar-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/typography-select.d.ts +5 -0
- package/dist/components/rich-text-field/components/typography-select.d.ts.map +1 -0
- package/dist/components/rich-text-field/components/underline-button.d.ts +3 -0
- package/dist/components/rich-text-field/components/underline-button.d.ts.map +1 -0
- package/dist/components/rich-text-field/constants.d.ts +57 -0
- package/dist/components/rich-text-field/constants.d.ts.map +1 -0
- package/dist/components/rich-text-field/context.d.ts +26 -0
- package/dist/components/rich-text-field/context.d.ts.map +1 -0
- package/dist/components/rich-text-field/index.d.ts +3 -0
- package/dist/components/rich-text-field/index.d.ts.map +1 -0
- package/dist/components/rich-text-field/rich-text-field.d.ts +17 -0
- package/dist/components/rich-text-field/rich-text-field.d.ts.map +1 -0
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts +10 -0
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -0
- package/dist/components/rich-text-field/utils.d.ts +1759 -0
- package/dist/components/rich-text-field/utils.d.ts.map +1 -0
- package/dist/components/spinner/index.d.ts +2 -0
- package/dist/components/spinner/index.d.ts.map +1 -0
- package/dist/components/spinner/spinner.d.ts +9 -0
- package/dist/components/spinner/spinner.d.ts.map +1 -0
- package/dist/components/spinner/spinner.stories.d.ts +8 -0
- package/dist/components/spinner/spinner.stories.d.ts.map +1 -0
- package/dist/contexts/chat-context/chat-context.d.ts +20 -0
- package/dist/contexts/chat-context/chat-context.d.ts.map +1 -0
- package/dist/contexts/chat-context/index.d.ts +2 -0
- package/dist/contexts/chat-context/index.d.ts.map +1 -0
- package/dist/contexts/chat-context/utils.d.ts +3 -0
- package/dist/contexts/chat-context/utils.d.ts.map +1 -0
- package/dist/contexts/chat-conversation-context/chat-conversation-context.d.ts +20 -0
- package/dist/contexts/chat-conversation-context/chat-conversation-context.d.ts.map +1 -0
- package/dist/contexts/chat-conversation-context/index.d.ts +2 -0
- package/dist/contexts/chat-conversation-context/index.d.ts.map +1 -0
- package/dist/contexts/index.d.ts +3 -0
- package/dist/contexts/index.d.ts.map +1 -0
- package/dist/docs/agent.stories.d.ts +41 -0
- package/dist/docs/agent.stories.d.ts.map +1 -0
- package/dist/docs/chat-panel.d.ts +33 -0
- package/dist/docs/chat-panel.d.ts.map +1 -0
- package/dist/docs/chatbot-panel.d.ts +20 -0
- package/dist/docs/chatbot-panel.d.ts.map +1 -0
- package/dist/docs/chatbot.stories.d.ts +11 -0
- package/dist/docs/chatbot.stories.d.ts.map +1 -0
- package/dist/domain/actions/constants.d.ts +2 -0
- package/dist/domain/actions/constants.d.ts.map +1 -0
- package/dist/domain/actions/hooks/index.d.ts +3 -0
- package/dist/domain/actions/hooks/index.d.ts.map +1 -0
- package/dist/domain/actions/index.d.ts +5 -0
- package/dist/domain/actions/index.d.ts.map +1 -0
- package/dist/domain/actions/types.d.ts +7 -0
- package/dist/domain/actions/types.d.ts.map +1 -0
- package/dist/domain/actions/utils/index.d.ts +11 -0
- package/dist/domain/actions/utils/index.d.ts.map +1 -0
- package/dist/domain/index.d.ts +2 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/use-chat-prompt-placeholder.d.ts +6 -0
- package/dist/hooks/use-chat-prompt-placeholder.d.ts.map +1 -0
- package/dist/hooks/use-chat-stream-message.d.ts +42 -0
- package/dist/hooks/use-chat-stream-message.d.ts.map +1 -0
- package/dist/hooks/use-current-chat-id.d.ts +2 -0
- package/dist/hooks/use-current-chat-id.d.ts.map +1 -0
- package/dist/hooks/use-is-current-chat-new.d.ts +2 -0
- package/dist/hooks/use-is-current-chat-new.d.ts.map +1 -0
- package/dist/hooks/use-loaded-chat-ids.d.ts +9 -0
- package/dist/hooks/use-loaded-chat-ids.d.ts.map +1 -0
- package/dist/hooks/use-on-chat-changed.d.ts +9 -0
- package/dist/hooks/use-on-chat-changed.d.ts.map +1 -0
- package/dist/index.css +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +4404 -0
- package/dist/index.es.js.map +1 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +95 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +1 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +24 -0
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +1 -0
- package/dist/layouts/chat-card-list-layout/index.d.ts +3 -0
- package/dist/layouts/chat-card-list-layout/index.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts +84 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts +45 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +37 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts +81 -0
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.d.ts.map +1 -0
- package/dist/layouts/chat-card-three-column-layout/index.d.ts +5 -0
- package/dist/layouts/chat-card-three-column-layout/index.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +31 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts +12 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +19 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts +35 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.d.ts.map +1 -0
- package/dist/layouts/chat-card-two-column-layout/index.d.ts +4 -0
- package/dist/layouts/chat-card-two-column-layout/index.d.ts.map +1 -0
- package/dist/layouts/index.d.ts +4 -0
- package/dist/layouts/index.d.ts.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/use-streaming-markdown.d.ts +18 -0
- package/dist/utils/use-streaming-markdown.d.ts.map +1 -0
- package/package.json +155 -0
- package/src/__tests__/setup.ts +5 -0
- package/src/components/canvas-shell/canvas-shell.json +126 -0
- package/src/components/canvas-shell/canvas-shell.stories.tsx +194 -0
- package/src/components/canvas-shell/canvas-shell.test.tsx +205 -0
- package/src/components/canvas-shell/canvas-shell.tsx +250 -0
- package/src/components/canvas-shell/index.ts +19 -0
- package/src/components/card-item-picker/__tests__/card-item-picker.spec.tsx +279 -0
- package/src/components/card-item-picker/card-item-picker-context.tsx +44 -0
- package/src/components/card-item-picker/card-item-picker-list.tsx +95 -0
- package/src/components/card-item-picker/card-item-picker-row-parts.tsx +96 -0
- package/src/components/card-item-picker/card-item-picker-row.tsx +109 -0
- package/src/components/card-item-picker/card-item-picker.json +147 -0
- package/src/components/card-item-picker/card-item-picker.stories.tsx +158 -0
- package/src/components/card-item-picker/index.ts +24 -0
- package/src/components/chat-card/__tests__/chat-card.spec.tsx +118 -0
- package/src/components/chat-card/chat-card.json +162 -0
- package/src/components/chat-card/chat-card.stories.tsx +349 -0
- package/src/components/chat-card/chat-card.tsx +106 -0
- package/src/components/chat-card/components/chat-card-body.tsx +115 -0
- package/src/components/chat-card/components/chat-card-footer.tsx +95 -0
- package/src/components/chat-card/components/chat-card-form.tsx +120 -0
- package/src/components/chat-card/components/chat-card-header.tsx +240 -0
- package/src/components/chat-card/components/index.ts +4 -0
- package/src/components/chat-card/context.tsx +34 -0
- package/src/components/chat-card/contexts.tsx +42 -0
- package/src/components/chat-card/hooks.ts +51 -0
- package/src/components/chat-card/index.ts +5 -0
- package/src/components/chat-card/types.ts +23 -0
- package/src/components/chat-card-container/chat-card-container.json +84 -0
- package/src/components/chat-card-container/chat-card-container.stories.tsx +149 -0
- package/src/components/chat-card-container/chat-card-container.tsx +75 -0
- package/src/components/chat-card-container/index.ts +2 -0
- package/src/components/chat-container/chat-container.json +93 -0
- package/src/components/chat-container/chat-container.stories.tsx +179 -0
- package/src/components/chat-container/chat-container.tsx +231 -0
- package/src/components/chat-container/index.ts +2 -0
- package/src/components/chat-input/chat-input.json +106 -0
- package/src/components/chat-input/chat-input.stories.tsx +291 -0
- package/src/components/chat-input/chat-input.tsx +220 -0
- package/src/components/chat-input/index.ts +2 -0
- package/src/components/chat-input/plugins/auto-focus-plugin.tsx +43 -0
- package/src/components/chat-input/plugins/controlled-value-plugin.tsx +47 -0
- package/src/components/chat-input/plugins/disabled-plugin.tsx +18 -0
- package/src/components/chat-input/plugins/focus-plugin.tsx +44 -0
- package/src/components/chat-input/plugins/has-value-plugin.tsx +51 -0
- package/src/components/chat-input/plugins/hooks.ts +7 -0
- package/src/components/chat-input/plugins/index.ts +7 -0
- package/src/components/chat-input/plugins/markdown-plain-paste-plugin.tsx +63 -0
- package/src/components/chat-input/plugins/utils.ts +48 -0
- package/src/components/chat-input/plugins/value-plugin.tsx +35 -0
- package/src/components/chat-input/transformers.ts +4 -0
- package/src/components/chat-list/chat-list-item.tsx +33 -0
- package/src/components/chat-list/chat-list-items.tsx +144 -0
- package/src/components/chat-list/chat-list.json +117 -0
- package/src/components/chat-list/chat-list.stories.tsx +332 -0
- package/src/components/chat-list/chat-list.tsx +278 -0
- package/src/components/chat-list/index.ts +18 -0
- package/src/components/chat-message/chat-message.json +105 -0
- package/src/components/chat-message/chat-message.stories.tsx +95 -0
- package/src/components/chat-message/chat-message.tsx +66 -0
- package/src/components/chat-message/index.ts +1 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card-icon.tsx +74 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.json +110 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +131 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.tsx +142 -0
- package/src/components/chat-message-attachment-card/index.ts +12 -0
- package/src/components/chat-message-attachment-card/utils.ts +41 -0
- package/src/components/chat-message-history/chat-message-history.json +99 -0
- package/src/components/chat-message-history/chat-message-history.stories.tsx +136 -0
- package/src/components/chat-message-history/chat-message-history.tsx +277 -0
- package/src/components/chat-message-history/index.ts +13 -0
- package/src/components/chat-message-response/chat-message-response.json +68 -0
- package/src/components/chat-message-response/chat-message-response.stories.tsx +63 -0
- package/src/components/chat-message-response/chat-message-response.tsx +24 -0
- package/src/components/chat-message-response/index.ts +1 -0
- package/src/components/chat-message-toolbar/chat-message-toolbar.json +100 -0
- package/src/components/chat-message-toolbar/chat-message-toolbar.stories.tsx +62 -0
- package/src/components/chat-message-toolbar/chat-message-toolbar.tsx +97 -0
- package/src/components/chat-message-toolbar/index.ts +6 -0
- package/src/components/chat-messages/chat-messages.json +95 -0
- package/src/components/chat-messages/chat-messages.stories.tsx +284 -0
- package/src/components/chat-messages/chat-messages.tsx +264 -0
- package/src/components/chat-messages/index.ts +10 -0
- package/src/components/chat-notification-card/chat-notification-card.json +135 -0
- package/src/components/chat-notification-card/chat-notification-card.stories.tsx +290 -0
- package/src/components/chat-notification-card/chat-notification-card.tsx +684 -0
- package/src/components/chat-notification-card/index.ts +3 -0
- package/src/components/chat-notification-card/types.ts +1 -0
- package/src/components/chat-notification-card/utils.ts +34 -0
- package/src/components/chat-notification-popup/chat-notification-popup.json +97 -0
- package/src/components/chat-notification-popup/chat-notification-popup.stories.tsx +80 -0
- package/src/components/chat-notification-popup/chat-notification-popup.tsx +36 -0
- package/src/components/chat-notification-popup/index.ts +1 -0
- package/src/components/chat-prompt-box/chat-prompt-box-context.tsx +62 -0
- package/src/components/chat-prompt-box/chat-prompt-box-focus-plugin.tsx +22 -0
- package/src/components/chat-prompt-box/chat-prompt-box.json +106 -0
- package/src/components/chat-prompt-box/chat-prompt-box.stories.tsx +117 -0
- package/src/components/chat-prompt-box/chat-prompt-box.tsx +296 -0
- package/src/components/chat-prompt-box/index.ts +16 -0
- package/src/components/chat-reply/chat-reply.json +79 -0
- package/src/components/chat-reply/chat-reply.stories.tsx +72 -0
- package/src/components/chat-reply/chat-reply.tsx +103 -0
- package/src/components/chat-reply/index.ts +1 -0
- package/src/components/chat-suggestion/chat-suggestion.json +108 -0
- package/src/components/chat-suggestion/chat-suggestion.stories.tsx +147 -0
- package/src/components/chat-suggestion/chat-suggestion.tsx +184 -0
- package/src/components/chat-suggestion/index.ts +8 -0
- package/src/components/chat-thinking-process/chat-thinking-process.json +110 -0
- package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +202 -0
- package/src/components/chat-thinking-process/chat-thinking-process.tsx +268 -0
- package/src/components/chat-thinking-process/index.ts +9 -0
- package/src/components/chat-thread/__tests__/chat-thread.spec.tsx +385 -0
- package/src/components/chat-thread/chat-thread.json +120 -0
- package/src/components/chat-thread/chat-thread.stories.tsx +218 -0
- package/src/components/chat-thread/chat-thread.tsx +549 -0
- package/src/components/chat-thread/index.ts +18 -0
- package/src/components/deprecated-empty-state.ts +39 -0
- package/src/components/index.ts +26 -0
- package/src/components/markdown-viewer/hooks.ts +59 -0
- package/src/components/markdown-viewer/index.ts +2 -0
- package/src/components/markdown-viewer/markdown-viewer.json +84 -0
- package/src/components/markdown-viewer/markdown-viewer.stories.tsx +110 -0
- package/src/components/markdown-viewer/markdown-viewer.tsx +95 -0
- package/src/components/markdown-viewer/types.ts +10 -0
- package/src/components/markdown-viewer/utils.ts +5 -0
- package/src/components/new-chat-trigger/index.ts +1 -0
- package/src/components/new-chat-trigger/new-chat-trigger.tsx +29 -0
- package/src/components/rich-text-area/constants/index.ts +10 -0
- package/src/components/rich-text-area/hooks.ts +24 -0
- package/src/components/rich-text-area/html-config.ts +195 -0
- package/src/components/rich-text-area/index.ts +6 -0
- package/src/components/rich-text-area/nodes/div-block-node.tsx +145 -0
- package/src/components/rich-text-area/nodes/image-node.tsx +100 -0
- package/src/components/rich-text-area/plugins/blur-plugin.tsx +36 -0
- package/src/components/rich-text-area/plugins/controlled-plugin.tsx +23 -0
- package/src/components/rich-text-area/plugins/controlled-value-plugin.tsx +101 -0
- package/src/components/rich-text-area/plugins/disabled-plugin.tsx +17 -0
- package/src/components/rich-text-area/plugins/file-attachment-plugin.tsx +57 -0
- package/src/components/rich-text-area/plugins/focus-plugin.tsx +44 -0
- package/src/components/rich-text-area/plugins/html-paste-plugin.tsx +104 -0
- package/src/components/rich-text-area/plugins/image-drop-plugin.tsx +56 -0
- package/src/components/rich-text-area/plugins/index.ts +10 -0
- package/src/components/rich-text-area/plugins/markdown-plain-paste-plugin.tsx +63 -0
- package/src/components/rich-text-area/plugins/value-plugin.tsx +46 -0
- package/src/components/rich-text-area/rich-text-area.json +102 -0
- package/src/components/rich-text-area/rich-text-area.stories.tsx +140 -0
- package/src/components/rich-text-area/rich-text-area.tsx +156 -0
- package/src/components/rich-text-area/styled.tsx +20 -0
- package/src/components/rich-text-area/transformers.ts +175 -0
- package/src/components/rich-text-area/types.ts +8 -0
- package/src/components/rich-text-area/utils/index.ts +77 -0
- package/src/components/rich-text-field/components/alignment-select.tsx +103 -0
- package/src/components/rich-text-field/components/attachment-button.tsx +25 -0
- package/src/components/rich-text-field/components/bold-button.tsx +21 -0
- package/src/components/rich-text-field/components/clean-format-button.tsx +44 -0
- package/src/components/rich-text-field/components/formatting-toolbar-plugin.tsx +69 -0
- package/src/components/rich-text-field/components/image-button.tsx +11 -0
- package/src/components/rich-text-field/components/index.ts +14 -0
- package/src/components/rich-text-field/components/italic-button.tsx +21 -0
- package/src/components/rich-text-field/components/link-button.tsx +11 -0
- package/src/components/rich-text-field/components/size-select.tsx +27 -0
- package/src/components/rich-text-field/components/text-color-button.tsx +41 -0
- package/src/components/rich-text-field/components/toolbar-button.tsx +27 -0
- package/src/components/rich-text-field/components/toolbar-select.tsx +19 -0
- package/src/components/rich-text-field/components/typography-select.tsx +27 -0
- package/src/components/rich-text-field/components/underline-button.tsx +21 -0
- package/src/components/rich-text-field/constants.ts +33 -0
- package/src/components/rich-text-field/context.tsx +251 -0
- package/src/components/rich-text-field/index.tsx +6 -0
- package/src/components/rich-text-field/rich-text-field.json +118 -0
- package/src/components/rich-text-field/rich-text-field.stories.tsx +218 -0
- package/src/components/rich-text-field/rich-text-field.tsx +93 -0
- package/src/components/rich-text-field/utils.ts +532 -0
- package/src/components/spinner/index.ts +1 -0
- package/src/components/spinner/spinner.json +73 -0
- package/src/components/spinner/spinner.stories.tsx +41 -0
- package/src/components/spinner/spinner.tsx +32 -0
- package/src/contexts/chat-context/chat-context.tsx +97 -0
- package/src/contexts/chat-context/index.ts +1 -0
- package/src/contexts/chat-context/utils.ts +7 -0
- package/src/contexts/chat-conversation-context/chat-conversation-context.tsx +608 -0
- package/src/contexts/chat-conversation-context/index.ts +1 -0
- package/src/contexts/index.ts +2 -0
- package/src/docs/agent.stories.tsx +567 -0
- package/src/docs/chat-panel.tsx +174 -0
- package/src/docs/chatbot-panel.tsx +381 -0
- package/src/docs/chatbot.mdx +144 -0
- package/src/docs/chatbot.stories.tsx +63 -0
- package/src/domain/actions/constants.ts +1 -0
- package/src/domain/actions/hooks/index.ts +22 -0
- package/src/domain/actions/index.ts +4 -0
- package/src/domain/actions/types.ts +6 -0
- package/src/domain/actions/utils/index.ts +112 -0
- package/src/domain/index.ts +1 -0
- package/src/hooks/index.tsx +10 -0
- package/src/hooks/use-chat-prompt-placeholder.ts +7 -0
- package/src/hooks/use-chat-stream-message.ts +189 -0
- package/src/hooks/use-current-chat-id.ts +6 -0
- package/src/hooks/use-is-current-chat-new.ts +6 -0
- package/src/hooks/use-loaded-chat-ids.ts +32 -0
- package/src/hooks/use-on-chat-changed.ts +33 -0
- package/src/index.css +1 -0
- package/src/index.ts +6 -0
- package/src/layouts/chat-card-list-layout/__tests__/chat-card-list-layout.spec.tsx +204 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +116 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +190 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +250 -0
- package/src/layouts/chat-card-list-layout/index.ts +11 -0
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.sizing.test.ts +73 -0
- package/src/layouts/chat-card-three-column-layout/__tests__/chat-card-three-column-layout.spec.tsx +282 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +131 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.sizing.ts +78 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +273 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.tsx +291 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.variants.ts +135 -0
- package/src/layouts/chat-card-three-column-layout/index.ts +24 -0
- package/src/layouts/chat-card-two-column-layout/__tests__/chat-card-two-column-layout.spec.tsx +109 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +97 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.sizing.ts +21 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +138 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +132 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.variants.ts +65 -0
- package/src/layouts/chat-card-two-column-layout/index.ts +17 -0
- package/src/layouts/index.ts +3 -0
- package/src/types.ts +29 -0
- package/src/utils/use-streaming-markdown.ts +113 -0
- package/tailwind.css +7 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MessageScroller as MessageScrollerPrimitive,
|
|
3
|
+
useMessageScroller,
|
|
4
|
+
useMessageScrollerScrollable,
|
|
5
|
+
} from '@shadcn/react/message-scroller';
|
|
6
|
+
import {
|
|
7
|
+
createContext,
|
|
8
|
+
forwardRef,
|
|
9
|
+
useCallback,
|
|
10
|
+
useContext,
|
|
11
|
+
useLayoutEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
type ComponentProps,
|
|
16
|
+
type ComponentPropsWithoutRef,
|
|
17
|
+
type MutableRefObject,
|
|
18
|
+
type ReactElement,
|
|
19
|
+
type ReactNode,
|
|
20
|
+
type Ref,
|
|
21
|
+
} from 'react';
|
|
22
|
+
|
|
23
|
+
import { ChevronDownIcon } from '@swisper.ai/icons';
|
|
24
|
+
import { IconButton, Tooltip } from '@swisper.ai/ui';
|
|
25
|
+
import { cn } from '@swisper.ai/web-core';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `@shadcn/react` reads `ref` from props (React 19 style), but React 18 strips `ref` before props reach
|
|
29
|
+
* a component. Calling the primitive directly from a `forwardRef` render puts `ref` back into its props.
|
|
30
|
+
* Not used for Root: it spreads props after its own internal ref, so any `ref` prop (even `null`) replaces it.
|
|
31
|
+
*/
|
|
32
|
+
function withForwardedRef<TProps>(
|
|
33
|
+
Primitive: (props: TProps) => ReactElement | null,
|
|
34
|
+
displayName: string,
|
|
35
|
+
) {
|
|
36
|
+
const Component = forwardRef<HTMLDivElement, Omit<TProps, 'ref'>>((props, ref) =>
|
|
37
|
+
Primitive({ ...props, ref: ref } as TProps),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
Component.displayName = displayName;
|
|
41
|
+
|
|
42
|
+
return Component;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const ViewportPrimitive = withForwardedRef(
|
|
46
|
+
MessageScrollerPrimitive.Viewport,
|
|
47
|
+
'ChatThreadViewportPrimitive',
|
|
48
|
+
);
|
|
49
|
+
const ContentPrimitive = withForwardedRef(
|
|
50
|
+
MessageScrollerPrimitive.Content,
|
|
51
|
+
'ChatThreadContentPrimitive',
|
|
52
|
+
);
|
|
53
|
+
const ItemPrimitive = withForwardedRef(MessageScrollerPrimitive.Item, 'ChatThreadItemPrimitive');
|
|
54
|
+
|
|
55
|
+
function assignRef<T>(ref: Ref<T> | undefined, value: T | null) {
|
|
56
|
+
if (typeof ref === 'function') {
|
|
57
|
+
ref(value);
|
|
58
|
+
} else if (ref) {
|
|
59
|
+
(ref as MutableRefObject<T | null>).current = value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const DEFAULT_SCROLL_MARGIN = 12;
|
|
64
|
+
|
|
65
|
+
/** CSS variable holding the height the latest group needs to fill the viewport once anchored at its top */
|
|
66
|
+
const GROUP_MIN_HEIGHT_VAR = '--chat-thread-group-min-height';
|
|
67
|
+
|
|
68
|
+
// Commands
|
|
69
|
+
|
|
70
|
+
export type ChatThreadCommands = ReturnType<typeof useMessageScroller>;
|
|
71
|
+
|
|
72
|
+
const NOOP_COMMANDS: ChatThreadCommands = {
|
|
73
|
+
scrollToEnd: () => false,
|
|
74
|
+
scrollToMessage: () => false,
|
|
75
|
+
scrollToStart: () => false,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const ChatThreadCommandsContext = createContext<ChatThreadCommands | null>(null);
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Scroll commands of the nearest `ChatThreadProvider`.
|
|
82
|
+
* Safe outside a provider: commands become no-ops returning `false`.
|
|
83
|
+
*/
|
|
84
|
+
export function useChatThread(): ChatThreadCommands {
|
|
85
|
+
return useContext(ChatThreadCommandsContext) ?? NOOP_COMMANDS;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function ChatThreadCommandsBridge({ children }: { children?: ReactNode }) {
|
|
89
|
+
const { scrollToEnd, scrollToMessage, scrollToStart } = useMessageScroller();
|
|
90
|
+
|
|
91
|
+
const commands = useMemo<ChatThreadCommands>(
|
|
92
|
+
() => ({ scrollToEnd, scrollToMessage, scrollToStart }),
|
|
93
|
+
[scrollToEnd, scrollToMessage, scrollToStart],
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<ChatThreadCommandsContext.Provider value={commands}>
|
|
98
|
+
{children}
|
|
99
|
+
</ChatThreadCommandsContext.Provider>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Session
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* How the thread scrolls as messages arrive.
|
|
107
|
+
* - `anchor`: question and answer chat. A new question settles at the top of the viewport and its answer
|
|
108
|
+
* grows below it, so the reader reads each answer from its start.
|
|
109
|
+
* - `follow`: terminal-style, for agent transcripts, tool runs and logs. New output is appended at the
|
|
110
|
+
* bottom and pushes older content up; the view follows the latest output until the reader scrolls away,
|
|
111
|
+
* and a new group brings it back to the end. A short thread sits at the bottom, next to the input.
|
|
112
|
+
*/
|
|
113
|
+
export type ChatThreadScrollMode = 'anchor' | 'follow';
|
|
114
|
+
|
|
115
|
+
interface ChatThreadSession {
|
|
116
|
+
isStreaming: boolean;
|
|
117
|
+
scrollMargin: number;
|
|
118
|
+
scrollMode: ChatThreadScrollMode;
|
|
119
|
+
/**
|
|
120
|
+
* Ids of the groups the session opened with — history. Any other group is a new message and anchors.
|
|
121
|
+
* `null` while the thread is empty.
|
|
122
|
+
*/
|
|
123
|
+
knownGroupIds: ReadonlySet<string> | null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const ChatThreadSessionContext = createContext<ChatThreadSession | null>(null);
|
|
127
|
+
|
|
128
|
+
function useChatThreadSession(component: string) {
|
|
129
|
+
const session = useContext(ChatThreadSessionContext);
|
|
130
|
+
|
|
131
|
+
if (!session) {
|
|
132
|
+
throw new Error(`[web-chat-ui] <${component}> must be rendered inside <ChatThreadProvider>`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return session;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
type ScrollerProviderProps = ComponentProps<typeof MessageScrollerPrimitive.Provider>;
|
|
139
|
+
|
|
140
|
+
export type ChatThreadProviderProps = ScrollerProviderProps & {
|
|
141
|
+
/** Identity of the conversation; changing it resets the thread so the new conversation opens at the end */
|
|
142
|
+
conversationId?: string | null;
|
|
143
|
+
/** Ids of the rendered groups, matching each `ChatThreadGroup`'s `groupId` */
|
|
144
|
+
groupIds: readonly string[];
|
|
145
|
+
/** Whether an answer is streaming into the thread */
|
|
146
|
+
isStreaming?: boolean;
|
|
147
|
+
/** How the thread scrolls as messages arrive; see `ChatThreadScrollMode`. Defaults to `anchor` */
|
|
148
|
+
scrollMode?: ChatThreadScrollMode;
|
|
149
|
+
/**
|
|
150
|
+
* Keep following content that grows at the end (late cards, reply chips, images) until the reader scrolls
|
|
151
|
+
* away. In `anchor` mode it defaults to following only while no answer is streaming, so a stream never
|
|
152
|
+
* drags the view down; in `follow` mode it defaults to always following.
|
|
153
|
+
*/
|
|
154
|
+
autoScroll?: boolean;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
interface ThreadSessionState {
|
|
158
|
+
id: number;
|
|
159
|
+
conversationId: string | null;
|
|
160
|
+
knownGroupIds: ReadonlySet<string> | null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function createSessionState(
|
|
164
|
+
id: number,
|
|
165
|
+
conversationId: string | null | undefined,
|
|
166
|
+
groupIds: readonly string[],
|
|
167
|
+
): ThreadSessionState {
|
|
168
|
+
return {
|
|
169
|
+
id,
|
|
170
|
+
conversationId: conversationId ?? null,
|
|
171
|
+
knownGroupIds: groupIds.length === 0 ? null : new Set(groupIds),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function ChatThreadProvider({
|
|
176
|
+
children,
|
|
177
|
+
conversationId,
|
|
178
|
+
groupIds,
|
|
179
|
+
isStreaming = false,
|
|
180
|
+
scrollMode = 'anchor',
|
|
181
|
+
autoScroll = scrollMode === 'follow' || !isStreaming,
|
|
182
|
+
defaultScrollPosition = 'end',
|
|
183
|
+
scrollPreviousItemPeek = 0,
|
|
184
|
+
scrollMargin = DEFAULT_SCROLL_MARGIN,
|
|
185
|
+
...rest
|
|
186
|
+
}: ChatThreadProviderProps) {
|
|
187
|
+
const [sessionState, setSessionState] = useState(() =>
|
|
188
|
+
createSessionState(0, conversationId, groupIds),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
// A new session per conversation, and whenever the thread empties or fills again: a chat switch renders
|
|
192
|
+
// the old groups under the new id, clears them, then loads the new history — which must open at the end
|
|
193
|
+
if (
|
|
194
|
+
sessionState.conversationId !== (conversationId ?? null) ||
|
|
195
|
+
(sessionState.knownGroupIds === null) !== (groupIds.length === 0)
|
|
196
|
+
) {
|
|
197
|
+
setSessionState(createSessionState(sessionState.id + 1, conversationId, groupIds));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const { knownGroupIds } = sessionState;
|
|
201
|
+
|
|
202
|
+
const session = useMemo<ChatThreadSession>(
|
|
203
|
+
() => ({ isStreaming, scrollMargin, scrollMode, knownGroupIds }),
|
|
204
|
+
[isStreaming, scrollMargin, scrollMode, knownGroupIds],
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
// Keyed on the session so the scroller remounts and applies its opening position again
|
|
208
|
+
return (
|
|
209
|
+
<MessageScrollerPrimitive.Provider
|
|
210
|
+
key={sessionState.id}
|
|
211
|
+
autoScroll={autoScroll}
|
|
212
|
+
scrollPreviousItemPeek={scrollPreviousItemPeek}
|
|
213
|
+
scrollMargin={scrollMargin}
|
|
214
|
+
defaultScrollPosition={defaultScrollPosition}
|
|
215
|
+
{...rest}
|
|
216
|
+
>
|
|
217
|
+
<ChatThreadSessionContext.Provider value={session}>
|
|
218
|
+
{scrollMode === 'follow' && (
|
|
219
|
+
<FollowNewGroups groupIds={groupIds} knownGroupIds={knownGroupIds} />
|
|
220
|
+
)}
|
|
221
|
+
<ChatThreadCommandsBridge>{children}</ChatThreadCommandsBridge>
|
|
222
|
+
</ChatThreadSessionContext.Provider>
|
|
223
|
+
</MessageScrollerPrimitive.Provider>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* In `follow` mode, a new group (the reader sent a prompt) returns the view to the end and resumes following,
|
|
229
|
+
* even when the reader had scrolled up to read earlier output.
|
|
230
|
+
*/
|
|
231
|
+
function FollowNewGroups({
|
|
232
|
+
groupIds,
|
|
233
|
+
knownGroupIds,
|
|
234
|
+
}: {
|
|
235
|
+
groupIds: readonly string[];
|
|
236
|
+
knownGroupIds: ReadonlySet<string> | null;
|
|
237
|
+
}) {
|
|
238
|
+
const { scrollToEnd } = useMessageScroller();
|
|
239
|
+
const lastGroupId = groupIds.at(-1);
|
|
240
|
+
|
|
241
|
+
useLayoutEffect(() => {
|
|
242
|
+
if (lastGroupId === undefined || knownGroupIds === null || knownGroupIds.has(lastGroupId))
|
|
243
|
+
return;
|
|
244
|
+
|
|
245
|
+
scrollToEnd({ behavior: 'auto' });
|
|
246
|
+
}, [lastGroupId, knownGroupIds, scrollToEnd]);
|
|
247
|
+
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Thread
|
|
252
|
+
|
|
253
|
+
export type ChatThreadError = Error | string;
|
|
254
|
+
|
|
255
|
+
export interface ChatThreadProps extends Omit<ComponentPropsWithoutRef<'div'>, 'children'> {
|
|
256
|
+
children?: ReactNode;
|
|
257
|
+
contentClassName?: string;
|
|
258
|
+
viewportRef?: Ref<HTMLDivElement>;
|
|
259
|
+
contentRef?: Ref<HTMLDivElement>;
|
|
260
|
+
/** Renders the scroll-to-latest button */
|
|
261
|
+
scrollButton?: boolean;
|
|
262
|
+
scrollButtonClassName?: string;
|
|
263
|
+
scrollButtonTooltip?: string;
|
|
264
|
+
isLoading?: boolean;
|
|
265
|
+
hasError?: boolean;
|
|
266
|
+
error?: ChatThreadError;
|
|
267
|
+
/** Replaces the built-in error message */
|
|
268
|
+
renderError?: (error?: ChatThreadError) => ReactNode;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export const ChatThread = forwardRef<HTMLDivElement, ChatThreadProps>(function ChatThread(
|
|
272
|
+
{
|
|
273
|
+
children,
|
|
274
|
+
className,
|
|
275
|
+
contentClassName,
|
|
276
|
+
viewportRef,
|
|
277
|
+
contentRef,
|
|
278
|
+
scrollButton = true,
|
|
279
|
+
scrollButtonClassName,
|
|
280
|
+
scrollButtonTooltip,
|
|
281
|
+
isLoading = false,
|
|
282
|
+
hasError = false,
|
|
283
|
+
error,
|
|
284
|
+
renderError,
|
|
285
|
+
...rest
|
|
286
|
+
},
|
|
287
|
+
ref,
|
|
288
|
+
) {
|
|
289
|
+
const { isStreaming, scrollMargin, scrollMode } = useChatThreadSession('ChatThread');
|
|
290
|
+
const isAnchored = scrollMode === 'anchor';
|
|
291
|
+
|
|
292
|
+
const viewportElementRef = useRef<HTMLDivElement | null>(null);
|
|
293
|
+
const contentElementRef = useRef<HTMLDivElement | null>(null);
|
|
294
|
+
|
|
295
|
+
const setViewport = useCallback(
|
|
296
|
+
(element: HTMLDivElement | null) => {
|
|
297
|
+
viewportElementRef.current = element;
|
|
298
|
+
assignRef(viewportRef, element);
|
|
299
|
+
// Root can't take `ref` without losing its internal one; the viewport is always its direct child
|
|
300
|
+
assignRef(ref, (element?.parentElement as HTMLDivElement | null | undefined) ?? null);
|
|
301
|
+
},
|
|
302
|
+
[viewportRef, ref],
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
const setContent = useCallback(
|
|
306
|
+
(element: HTMLDivElement | null) => {
|
|
307
|
+
contentElementRef.current = element;
|
|
308
|
+
assignRef(contentRef, element);
|
|
309
|
+
},
|
|
310
|
+
[contentRef],
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
useGroupMinHeight(viewportElementRef, contentElementRef, scrollMargin, isAnchored);
|
|
314
|
+
|
|
315
|
+
return (
|
|
316
|
+
<MessageScrollerPrimitive.Root
|
|
317
|
+
data-testid="chat-thread"
|
|
318
|
+
data-scroll-mode={scrollMode}
|
|
319
|
+
data-loading={isLoading}
|
|
320
|
+
data-error={hasError}
|
|
321
|
+
className={cn('relative flex flex-col flex-1 min-h-0 overflow-hidden', className)}
|
|
322
|
+
{...rest}
|
|
323
|
+
>
|
|
324
|
+
<ViewportPrimitive
|
|
325
|
+
ref={setViewport}
|
|
326
|
+
aria-label="Chat message history"
|
|
327
|
+
className={cn(
|
|
328
|
+
'size-full overflow-x-hidden overflow-y-auto outline-none',
|
|
329
|
+
'will-change-scroll transform-gpu',
|
|
330
|
+
// A continuous stream outruns smooth scrolling, so following jumps instead
|
|
331
|
+
isAnchored && isStreaming && 'scroll-smooth',
|
|
332
|
+
)}
|
|
333
|
+
style={{
|
|
334
|
+
scrollbarGutter: 'stable both-edges',
|
|
335
|
+
scrollbarWidth: 'thin',
|
|
336
|
+
scrollbarColor: 'var(--color-scrollbar-thumb) transparent',
|
|
337
|
+
}}
|
|
338
|
+
>
|
|
339
|
+
<ContentPrimitive
|
|
340
|
+
ref={setContent}
|
|
341
|
+
aria-busy={isStreaming}
|
|
342
|
+
data-testid="chat-thread-content"
|
|
343
|
+
className={cn(
|
|
344
|
+
'relative flex flex-col gap-16',
|
|
345
|
+
isAnchored
|
|
346
|
+
? // The primitive always appends its spacer, so the latest group is the second-to-last child
|
|
347
|
+
'[&>[data-chat-thread-group]:nth-last-child(2)]:min-h-(--chat-thread-group-min-height)'
|
|
348
|
+
: // Terminal-style: a short thread sits at the bottom, next to the input
|
|
349
|
+
'min-h-full justify-end',
|
|
350
|
+
contentClassName,
|
|
351
|
+
)}
|
|
352
|
+
>
|
|
353
|
+
{children}
|
|
354
|
+
</ContentPrimitive>
|
|
355
|
+
</ViewportPrimitive>
|
|
356
|
+
|
|
357
|
+
{hasError && !isLoading && (
|
|
358
|
+
<ChatThreadErrorState error={error}>{renderError?.(error)}</ChatThreadErrorState>
|
|
359
|
+
)}
|
|
360
|
+
|
|
361
|
+
{scrollButton && (
|
|
362
|
+
<ChatThreadScrollButton className={scrollButtonClassName} tooltip={scrollButtonTooltip} />
|
|
363
|
+
)}
|
|
364
|
+
</MessageScrollerPrimitive.Root>
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Keeps the latest group at least as tall as the room below its anchored position, so a new message can
|
|
370
|
+
* settle at the top of the viewport and the answer streams in without the scroll position jumping.
|
|
371
|
+
* Only `anchor` mode needs it.
|
|
372
|
+
*/
|
|
373
|
+
function useGroupMinHeight(
|
|
374
|
+
viewportRef: MutableRefObject<HTMLDivElement | null>,
|
|
375
|
+
contentRef: MutableRefObject<HTMLDivElement | null>,
|
|
376
|
+
scrollMargin: number,
|
|
377
|
+
isEnabled: boolean,
|
|
378
|
+
) {
|
|
379
|
+
useLayoutEffect(() => {
|
|
380
|
+
const viewport = viewportRef.current;
|
|
381
|
+
const content = contentRef.current;
|
|
382
|
+
|
|
383
|
+
if (!viewport || !content) return;
|
|
384
|
+
|
|
385
|
+
if (!isEnabled) {
|
|
386
|
+
content.style.removeProperty(GROUP_MIN_HEIGHT_VAR);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const update = () => {
|
|
391
|
+
const { paddingTop, paddingBottom } = window.getComputedStyle(content);
|
|
392
|
+
const minHeight =
|
|
393
|
+
viewport.clientHeight -
|
|
394
|
+
(Number.parseFloat(paddingTop) || 0) -
|
|
395
|
+
(Number.parseFloat(paddingBottom) || 0) -
|
|
396
|
+
scrollMargin;
|
|
397
|
+
|
|
398
|
+
content.style.setProperty(GROUP_MIN_HEIGHT_VAR, `${Math.max(0, minHeight)}px`);
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
update();
|
|
402
|
+
|
|
403
|
+
if (typeof ResizeObserver === 'undefined') return;
|
|
404
|
+
|
|
405
|
+
const observer = new ResizeObserver(update);
|
|
406
|
+
observer.observe(viewport);
|
|
407
|
+
observer.observe(content);
|
|
408
|
+
|
|
409
|
+
return () => observer.disconnect();
|
|
410
|
+
}, [viewportRef, contentRef, scrollMargin, isEnabled]);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// Groups
|
|
414
|
+
|
|
415
|
+
export interface ChatThreadGroupProps extends ComponentPropsWithoutRef<'div'> {
|
|
416
|
+
groupId: string;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* One question with its answer. Groups the session opened with are history; in `anchor` mode any other
|
|
421
|
+
* group is a new message and becomes the scroll anchor, settling at the top of the viewport. In `follow`
|
|
422
|
+
* mode no group anchors.
|
|
423
|
+
*/
|
|
424
|
+
export const ChatThreadGroup = forwardRef<HTMLDivElement, ChatThreadGroupProps>(
|
|
425
|
+
function ChatThreadGroup({ groupId, className, ...rest }, ref) {
|
|
426
|
+
const { knownGroupIds, scrollMode } = useChatThreadSession('ChatThreadGroup');
|
|
427
|
+
const isNew = scrollMode === 'anchor' && knownGroupIds !== null && !knownGroupIds.has(groupId);
|
|
428
|
+
|
|
429
|
+
return (
|
|
430
|
+
<ItemPrimitive
|
|
431
|
+
ref={ref}
|
|
432
|
+
// Namespaced: `data-message-id` is also how consumers find message bubbles
|
|
433
|
+
messageId={`chat-thread-group-${groupId}`}
|
|
434
|
+
scrollAnchor={isNew}
|
|
435
|
+
data-chat-thread-group=""
|
|
436
|
+
className={cn('flex flex-col gap-16 w-full min-h-px mx-auto', className)}
|
|
437
|
+
{...rest}
|
|
438
|
+
/>
|
|
439
|
+
);
|
|
440
|
+
},
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
export interface ChatThreadMessageProps extends ComponentPropsWithoutRef<'div'> {
|
|
444
|
+
messageId: string;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export const ChatThreadQuestion = forwardRef<HTMLDivElement, ChatThreadMessageProps>(
|
|
448
|
+
function ChatThreadQuestion({ messageId, ...rest }, ref) {
|
|
449
|
+
return (
|
|
450
|
+
<div
|
|
451
|
+
ref={ref}
|
|
452
|
+
data-chat-thread-question=""
|
|
453
|
+
data-chat-thread-message-id={messageId}
|
|
454
|
+
{...rest}
|
|
455
|
+
/>
|
|
456
|
+
);
|
|
457
|
+
},
|
|
458
|
+
);
|
|
459
|
+
|
|
460
|
+
export const ChatThreadAnswer = forwardRef<HTMLDivElement, ChatThreadMessageProps>(
|
|
461
|
+
function ChatThreadAnswer({ messageId, ...rest }, ref) {
|
|
462
|
+
return (
|
|
463
|
+
<div ref={ref} data-chat-thread-answer="" data-chat-thread-message-id={messageId} {...rest} />
|
|
464
|
+
);
|
|
465
|
+
},
|
|
466
|
+
);
|
|
467
|
+
|
|
468
|
+
// Parts
|
|
469
|
+
|
|
470
|
+
interface ChatThreadScrollButtonProps {
|
|
471
|
+
className?: string;
|
|
472
|
+
tooltip?: string;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function ChatThreadScrollButton({ className, tooltip }: ChatThreadScrollButtonProps) {
|
|
476
|
+
const { end: hasContentBelow } = useMessageScrollerScrollable();
|
|
477
|
+
|
|
478
|
+
return (
|
|
479
|
+
<div
|
|
480
|
+
data-testid="chat-message-history-scroll-button"
|
|
481
|
+
data-hidden={!hasContentBelow}
|
|
482
|
+
aria-hidden={hasContentBelow ? undefined : true}
|
|
483
|
+
className={cn(
|
|
484
|
+
'absolute',
|
|
485
|
+
'px-[12px]',
|
|
486
|
+
'bottom-0',
|
|
487
|
+
'right-0 -translate-x-[12px]',
|
|
488
|
+
'md:right-auto md:left-1/2 md:-translate-x-1/2',
|
|
489
|
+
'-translate-y-[12px]',
|
|
490
|
+
'flex items-center justify-center',
|
|
491
|
+
'transition-opacity duration-200 ease-in-out',
|
|
492
|
+
'data-[hidden=true]:pointer-events-none',
|
|
493
|
+
'data-[hidden=true]:opacity-0 data-[hidden=false]:opacity-100',
|
|
494
|
+
className,
|
|
495
|
+
)}
|
|
496
|
+
>
|
|
497
|
+
<MessageScrollerPrimitive.Button
|
|
498
|
+
direction="end"
|
|
499
|
+
// Render function (not element) so Tooltip's trigger gets IconButton's forwarded ref on React 18
|
|
500
|
+
render={({ inert, children: _children, ...props }) => (
|
|
501
|
+
<Tooltip tooltip={tooltip} side="top">
|
|
502
|
+
<IconButton
|
|
503
|
+
{...props}
|
|
504
|
+
// React 18 doesn't know the boolean `inert` prop
|
|
505
|
+
{...{ inert: inert ? '' : undefined }}
|
|
506
|
+
className="bg-paper-elevation-2"
|
|
507
|
+
color="primary"
|
|
508
|
+
size="md"
|
|
509
|
+
tabIndex={-1}
|
|
510
|
+
aria-label={tooltip}
|
|
511
|
+
>
|
|
512
|
+
<ChevronDownIcon />
|
|
513
|
+
</IconButton>
|
|
514
|
+
</Tooltip>
|
|
515
|
+
)}
|
|
516
|
+
/>
|
|
517
|
+
</div>
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
export interface ChatThreadErrorStateProps {
|
|
522
|
+
children?: ReactNode;
|
|
523
|
+
error?: ChatThreadError;
|
|
524
|
+
className?: string;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Covers the thread with an alert when its messages failed to load. Shows `children` when given,
|
|
529
|
+
* otherwise the error's message.
|
|
530
|
+
*/
|
|
531
|
+
export function ChatThreadErrorState({ children, error, className }: ChatThreadErrorStateProps) {
|
|
532
|
+
return (
|
|
533
|
+
<div
|
|
534
|
+
data-testid="chat-message-history-error-state"
|
|
535
|
+
role="alert"
|
|
536
|
+
aria-live="assertive"
|
|
537
|
+
aria-label="Error loading messages"
|
|
538
|
+
className={cn('absolute inset-0 flex items-center justify-center', className)}
|
|
539
|
+
>
|
|
540
|
+
{children || (
|
|
541
|
+
<div className="text-text-error-main">
|
|
542
|
+
{error instanceof Error ? error.message : error || 'An error occurred'}
|
|
543
|
+
</div>
|
|
544
|
+
)}
|
|
545
|
+
</div>
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export { useMessageScrollerScrollable as useChatThreadScrollable };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export {
|
|
2
|
+
useChatThread,
|
|
3
|
+
useChatThreadScrollable,
|
|
4
|
+
ChatThread,
|
|
5
|
+
ChatThreadAnswer,
|
|
6
|
+
ChatThreadErrorState,
|
|
7
|
+
ChatThreadGroup,
|
|
8
|
+
ChatThreadProvider,
|
|
9
|
+
ChatThreadQuestion,
|
|
10
|
+
type ChatThreadCommands,
|
|
11
|
+
type ChatThreadError,
|
|
12
|
+
type ChatThreadErrorStateProps,
|
|
13
|
+
type ChatThreadGroupProps,
|
|
14
|
+
type ChatThreadMessageProps,
|
|
15
|
+
type ChatThreadProps,
|
|
16
|
+
type ChatThreadProviderProps,
|
|
17
|
+
type ChatThreadScrollMode,
|
|
18
|
+
} from './chat-thread';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// EmptyState moved to @swisper.ai/ui, so apps without the chat surface can use it too. These aliases
|
|
2
|
+
// keep existing `@swisper.ai/web-chat-ui` imports compiling; the editor strikes them through.
|
|
3
|
+
// A plain `export { … } from` would work at runtime but carries no @deprecated tag per symbol.
|
|
4
|
+
// Kept as a flat file, not a component folder, so the echo-design reference build doesn't list
|
|
5
|
+
// EmptyState under web-chat-ui as well.
|
|
6
|
+
import {
|
|
7
|
+
EmptyState as UiEmptyState,
|
|
8
|
+
EmptyStateActionRow as UiEmptyStateActionRow,
|
|
9
|
+
EmptyStateDescription as UiEmptyStateDescription,
|
|
10
|
+
EmptyStateIcon as UiEmptyStateIcon,
|
|
11
|
+
EmptyStateTitle as UiEmptyStateTitle,
|
|
12
|
+
type EmptyStateActionRowProps as UiEmptyStateActionRowProps,
|
|
13
|
+
type EmptyStateDescriptionProps as UiEmptyStateDescriptionProps,
|
|
14
|
+
type EmptyStateIconProps as UiEmptyStateIconProps,
|
|
15
|
+
type EmptyStateProps as UiEmptyStateProps,
|
|
16
|
+
type EmptyStateTitleProps as UiEmptyStateTitleProps,
|
|
17
|
+
} from '@swisper.ai/ui';
|
|
18
|
+
|
|
19
|
+
/** @deprecated Import `EmptyState` from `@swisper.ai/ui`. */
|
|
20
|
+
export const EmptyState = UiEmptyState;
|
|
21
|
+
/** @deprecated Import `EmptyStateIcon` from `@swisper.ai/ui`. */
|
|
22
|
+
export const EmptyStateIcon = UiEmptyStateIcon;
|
|
23
|
+
/** @deprecated Import `EmptyStateTitle` from `@swisper.ai/ui`. */
|
|
24
|
+
export const EmptyStateTitle = UiEmptyStateTitle;
|
|
25
|
+
/** @deprecated Import `EmptyStateDescription` from `@swisper.ai/ui`. */
|
|
26
|
+
export const EmptyStateDescription = UiEmptyStateDescription;
|
|
27
|
+
/** @deprecated Import `EmptyStateActionRow` from `@swisper.ai/ui`. */
|
|
28
|
+
export const EmptyStateActionRow = UiEmptyStateActionRow;
|
|
29
|
+
|
|
30
|
+
/** @deprecated Import `EmptyStateProps` from `@swisper.ai/ui`. */
|
|
31
|
+
export type EmptyStateProps = UiEmptyStateProps;
|
|
32
|
+
/** @deprecated Import `EmptyStateIconProps` from `@swisper.ai/ui`. */
|
|
33
|
+
export type EmptyStateIconProps = UiEmptyStateIconProps;
|
|
34
|
+
/** @deprecated Import `EmptyStateTitleProps` from `@swisper.ai/ui`. */
|
|
35
|
+
export type EmptyStateTitleProps = UiEmptyStateTitleProps;
|
|
36
|
+
/** @deprecated Import `EmptyStateDescriptionProps` from `@swisper.ai/ui`. */
|
|
37
|
+
export type EmptyStateDescriptionProps = UiEmptyStateDescriptionProps;
|
|
38
|
+
/** @deprecated Import `EmptyStateActionRowProps` from `@swisper.ai/ui`. */
|
|
39
|
+
export type EmptyStateActionRowProps = UiEmptyStateActionRowProps;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from './chat-card';
|
|
2
|
+
export * from './chat-card-container';
|
|
3
|
+
export * from './chat-container';
|
|
4
|
+
export * from './chat-input';
|
|
5
|
+
export * from './chat-list';
|
|
6
|
+
export * from './chat-prompt-box';
|
|
7
|
+
export * from './chat-message';
|
|
8
|
+
export * from './chat-messages';
|
|
9
|
+
export * from './chat-message-attachment-card';
|
|
10
|
+
export * from './chat-message-response';
|
|
11
|
+
export * from './chat-message-history';
|
|
12
|
+
export * from './chat-message-toolbar';
|
|
13
|
+
export * from './chat-notification-card';
|
|
14
|
+
export * from './chat-notification-popup';
|
|
15
|
+
export * from './chat-reply';
|
|
16
|
+
export * from './chat-suggestion';
|
|
17
|
+
export * from './chat-thread';
|
|
18
|
+
export * from './canvas-shell';
|
|
19
|
+
export * from './card-item-picker';
|
|
20
|
+
export * from './new-chat-trigger';
|
|
21
|
+
export * from './chat-thinking-process';
|
|
22
|
+
export * from './deprecated-empty-state';
|
|
23
|
+
export * from './markdown-viewer';
|
|
24
|
+
export * from './rich-text-area';
|
|
25
|
+
export * from './rich-text-field';
|
|
26
|
+
export * from './spinner';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
|
|
3
|
+
import { defaultRehypePlugins, defaultRemarkPlugins, type StreamdownProps } from 'streamdown';
|
|
4
|
+
import { type PluggableList } from 'unified';
|
|
5
|
+
|
|
6
|
+
import type { SwiTagName } from '../../types';
|
|
7
|
+
|
|
8
|
+
import type { CustomMarkdownViewerComponents, MarkdownViewerComponents } from './types';
|
|
9
|
+
import { isCustomComponentTag } from './utils';
|
|
10
|
+
|
|
11
|
+
export interface UseMarkdownViewerHookProps {
|
|
12
|
+
customComponents: CustomMarkdownViewerComponents;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type UseMarkdownViewerHook = Pick<
|
|
16
|
+
StreamdownProps,
|
|
17
|
+
'components' | 'remarkPlugins' | 'rehypePlugins'
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export function useMarkdownViewer({
|
|
21
|
+
customComponents,
|
|
22
|
+
}: UseMarkdownViewerHookProps): UseMarkdownViewerHook {
|
|
23
|
+
const swiTags = useMemo<SwiTagName[]>(
|
|
24
|
+
() =>
|
|
25
|
+
Object.keys(customComponents).filter((key): key is SwiTagName => {
|
|
26
|
+
if (!isCustomComponentTag(key)) {
|
|
27
|
+
console.warn(`[MarkdownViewer] Invalid custom component tag: ${key}`);
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return true;
|
|
32
|
+
}),
|
|
33
|
+
[customComponents],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const remarkPlugins = useMemo<PluggableList>(() => [...Object.values(defaultRemarkPlugins)], []);
|
|
37
|
+
const rehypePlugins = useMemo<PluggableList>(() => {
|
|
38
|
+
return [
|
|
39
|
+
...Object.values(defaultRehypePlugins),
|
|
40
|
+
[
|
|
41
|
+
rehypeSanitize,
|
|
42
|
+
{
|
|
43
|
+
...defaultSchema,
|
|
44
|
+
tagNames: [...(defaultSchema?.tagNames || []), ...swiTags],
|
|
45
|
+
protocols: {
|
|
46
|
+
...defaultSchema?.protocols,
|
|
47
|
+
href: [...(defaultSchema?.protocols?.href ?? []), 'swisper', 'swisper://'],
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
];
|
|
52
|
+
}, [swiTags]);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
components: customComponents satisfies MarkdownViewerComponents,
|
|
56
|
+
remarkPlugins,
|
|
57
|
+
rehypePlugins,
|
|
58
|
+
};
|
|
59
|
+
}
|