@swisper.ai/web-chat-ui 0.0.2 → 0.0.5
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/README.md +9 -12
- package/dist/components/canvas-shell/canvas-shell.d.ts +32 -10
- package/dist/components/canvas-shell/canvas-shell.d.ts.map +1 -1
- package/dist/components/canvas-shell/canvas-shell.stories.d.ts +49 -17
- package/dist/components/canvas-shell/canvas-shell.stories.d.ts.map +1 -1
- package/dist/components/chat-card/chat-card.d.ts +1 -0
- package/dist/components/chat-card/chat-card.d.ts.map +1 -1
- package/dist/components/chat-card/chat-card.stories.d.ts +47 -1
- package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -1
- package/dist/components/chat-card/components/chat-card-body.d.ts +8 -0
- package/dist/components/chat-card/components/chat-card-body.d.ts.map +1 -1
- package/dist/components/chat-card/components/chat-card-footer.d.ts +8 -0
- package/dist/components/chat-card/components/chat-card-footer.d.ts.map +1 -1
- package/dist/components/chat-card/components/chat-card-form.d.ts +15 -2
- package/dist/components/chat-card/components/chat-card-form.d.ts.map +1 -1
- package/dist/components/chat-card/components/chat-card-header.d.ts +23 -2
- package/dist/components/chat-card/components/chat-card-header.d.ts.map +1 -1
- package/dist/components/chat-card/contexts.d.ts +2 -0
- package/dist/components/chat-card/contexts.d.ts.map +1 -1
- package/dist/components/chat-card/hooks.d.ts +1 -0
- package/dist/components/chat-card/hooks.d.ts.map +1 -1
- package/dist/components/chat-card/types.d.ts +3 -0
- package/dist/components/chat-card/types.d.ts.map +1 -1
- package/dist/components/chat-card-container/chat-card-container.d.ts +4 -0
- package/dist/components/chat-card-container/chat-card-container.d.ts.map +1 -1
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts +12 -1
- package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
- package/dist/components/chat-container/chat-container.d.ts.map +1 -1
- package/dist/components/chat-container/chat-container.stories.d.ts +36 -11
- package/dist/components/chat-container/chat-container.stories.d.ts.map +1 -1
- package/dist/components/chat-input/chat-input.d.ts +30 -2
- package/dist/components/chat-input/chat-input.d.ts.map +1 -1
- package/dist/components/chat-input/chat-input.stories.d.ts +63 -3
- package/dist/components/chat-input/chat-input.stories.d.ts.map +1 -1
- package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts +4 -1
- package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts.map +1 -1
- package/dist/components/chat-input/plugins/value-plugin.d.ts +4 -1
- package/dist/components/chat-input/plugins/value-plugin.d.ts.map +1 -1
- package/dist/components/chat-list/chat-list-item.d.ts +6 -0
- package/dist/components/chat-list/chat-list-item.d.ts.map +1 -1
- package/dist/components/chat-list/chat-list-items.d.ts +12 -1
- package/dist/components/chat-list/chat-list-items.d.ts.map +1 -1
- package/dist/components/chat-list/chat-list.d.ts +36 -2
- package/dist/components/chat-list/chat-list.d.ts.map +1 -1
- package/dist/components/chat-list/chat-list.stories.d.ts +67 -9
- package/dist/components/chat-list/chat-list.stories.d.ts.map +1 -1
- package/dist/components/chat-message/chat-message.d.ts +12 -1
- package/dist/components/chat-message/chat-message.d.ts.map +1 -1
- package/dist/components/chat-message/chat-message.stories.d.ts +31 -0
- package/dist/components/chat-message/chat-message.stories.d.ts.map +1 -1
- package/dist/components/chat-message/index.d.ts +1 -1
- package/dist/components/chat-message/index.d.ts.map +1 -1
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts +3 -0
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts.map +1 -1
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts +25 -5
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts.map +1 -1
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +32 -1
- package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -1
- package/dist/components/chat-message-attachment-card/index.d.ts +2 -2
- package/dist/components/chat-message-attachment-card/index.d.ts.map +1 -1
- package/dist/components/chat-message-attachment-card/utils.d.ts +1 -0
- package/dist/components/chat-message-attachment-card/utils.d.ts.map +1 -1
- package/dist/components/chat-message-response/chat-message-response.stories.d.ts +13 -0
- package/dist/components/chat-message-response/chat-message-response.stories.d.ts.map +1 -1
- package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts +22 -5
- package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts.map +1 -1
- package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts +42 -0
- package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts.map +1 -1
- package/dist/components/chat-message-toolbar/index.d.ts +1 -1
- package/dist/components/chat-message-toolbar/index.d.ts.map +1 -1
- package/dist/components/chat-messages/chat-messages.d.ts +34 -2
- package/dist/components/chat-messages/chat-messages.d.ts.map +1 -1
- package/dist/components/chat-messages/chat-messages.stories.d.ts +33 -2
- package/dist/components/chat-messages/chat-messages.stories.d.ts.map +1 -1
- package/dist/components/chat-notification-card/chat-notification-card.d.ts +56 -4
- package/dist/components/chat-notification-card/chat-notification-card.d.ts.map +1 -1
- package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts +50 -1
- package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts.map +1 -1
- package/dist/components/chat-notification-popup/chat-notification-popup.d.ts +6 -0
- package/dist/components/chat-notification-popup/chat-notification-popup.d.ts.map +1 -1
- package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts +43 -1
- package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts.map +1 -1
- package/dist/components/chat-prompt-box/chat-prompt-box.d.ts +37 -17
- package/dist/components/chat-prompt-box/chat-prompt-box.d.ts.map +1 -1
- package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts +53 -1
- package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts.map +1 -1
- package/dist/components/chat-reply/chat-reply.d.ts +11 -0
- package/dist/components/chat-reply/chat-reply.d.ts.map +1 -1
- package/dist/components/chat-reply/chat-reply.stories.d.ts +23 -0
- package/dist/components/chat-reply/chat-reply.stories.d.ts.map +1 -1
- package/dist/components/chat-reply/index.d.ts +1 -1
- package/dist/components/chat-reply/index.d.ts.map +1 -1
- package/dist/components/chat-suggestion/chat-suggestion.d.ts +36 -10
- package/dist/components/chat-suggestion/chat-suggestion.d.ts.map +1 -1
- package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts +66 -2
- package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts.map +1 -1
- package/dist/components/chat-suggestion/index.d.ts +2 -1
- package/dist/components/chat-suggestion/index.d.ts.map +1 -1
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +26 -1
- package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
- package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +25 -1
- package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -1
- package/dist/components/chat-thread/chat-thread.d.ts +17 -2
- package/dist/components/chat-thread/chat-thread.d.ts.map +1 -1
- package/dist/components/chat-thread/chat-thread.stories.d.ts +75 -10
- package/dist/components/chat-thread/chat-thread.stories.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -3
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/markdown-viewer/markdown-viewer.d.ts +8 -1
- package/dist/components/markdown-viewer/markdown-viewer.d.ts.map +1 -1
- package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts +18 -1
- package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts.map +1 -1
- package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts +4 -1
- package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts.map +1 -1
- package/dist/components/rich-text-area/plugins/value-plugin.d.ts +4 -1
- package/dist/components/rich-text-area/plugins/value-plugin.d.ts.map +1 -1
- package/dist/components/rich-text-area/rich-text-area.d.ts +17 -0
- package/dist/components/rich-text-area/rich-text-area.d.ts.map +1 -1
- package/dist/components/rich-text-area/rich-text-area.stories.d.ts +52 -0
- package/dist/components/rich-text-area/rich-text-area.stories.d.ts.map +1 -1
- package/dist/components/rich-text-area/styled.d.ts +6 -2
- package/dist/components/rich-text-area/styled.d.ts.map +1 -1
- package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts +9 -2
- package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts.map +1 -1
- package/dist/components/rich-text-field/components/index.d.ts +5 -5
- package/dist/components/rich-text-field/components/index.d.ts.map +1 -1
- package/dist/components/rich-text-field/components/text-color-button.d.ts +12 -1
- package/dist/components/rich-text-field/components/text-color-button.d.ts.map +1 -1
- package/dist/components/rich-text-field/rich-text-field.d.ts +22 -0
- package/dist/components/rich-text-field/rich-text-field.d.ts.map +1 -1
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts +28 -1
- package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
- package/dist/components/topmenu/index.d.ts +2 -0
- package/dist/components/topmenu/index.d.ts.map +1 -0
- package/dist/components/topmenu/topmenu.d.ts +22 -0
- package/dist/components/topmenu/topmenu.d.ts.map +1 -0
- package/dist/components/topmenu/topmenu.stories.d.ts +31 -0
- package/dist/components/topmenu/topmenu.stories.d.ts.map +1 -0
- package/dist/docs/agent.stories.d.ts.map +1 -1
- package/dist/docs/chat-panel.d.ts +7 -5
- package/dist/docs/chat-panel.d.ts.map +1 -1
- package/dist/docs/chatbot-panel.d.ts.map +1 -1
- package/dist/docs/chatbot.stories.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.es.js +1801 -1806
- package/dist/index.es.js.map +1 -1
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +9 -7
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +1 -1
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +37 -9
- package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +1 -1
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +41 -16
- package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +6 -0
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +1 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +22 -1
- package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +1 -1
- package/package.json +16 -10
- package/src/__storybook__/parent-block.tsx +21 -0
- package/src/components/canvas-shell/__stories__/canvas-panel.tsx +25 -0
- package/src/components/canvas-shell/__stories__/document-list.tsx +29 -0
- package/src/components/canvas-shell/__stories__/fixtures.ts +222 -0
- package/src/components/canvas-shell/__stories__/holdings-table.tsx +56 -0
- package/src/components/canvas-shell/__stories__/types.ts +47 -0
- package/src/components/canvas-shell/{canvas-shell.test.tsx → __tests__/canvas-shell.spec.tsx} +1 -1
- package/src/components/canvas-shell/canvas-shell.json +24 -0
- package/src/components/canvas-shell/canvas-shell.stories.tsx +581 -122
- package/src/components/canvas-shell/canvas-shell.tsx +44 -17
- package/src/components/chat-card/__stories__/fixtures.ts +119 -0
- package/src/components/chat-card/__stories__/types.ts +44 -0
- package/src/components/chat-card/chat-card.json +67 -3
- package/src/components/chat-card/chat-card.stories.tsx +872 -148
- package/src/components/chat-card/chat-card.tsx +2 -0
- package/src/components/chat-card/components/chat-card-body.tsx +12 -0
- package/src/components/chat-card/components/chat-card-footer.tsx +11 -0
- package/src/components/chat-card/components/chat-card-form.tsx +21 -2
- package/src/components/chat-card/components/chat-card-header.tsx +39 -2
- package/src/components/chat-card/contexts.tsx +2 -0
- package/src/components/chat-card/hooks.ts +1 -0
- package/src/components/chat-card/types.ts +3 -0
- package/src/components/chat-card-container/__stories__/fixtures.ts +54 -0
- package/src/components/chat-card-container/__stories__/resizable-chat-window.tsx +19 -0
- package/src/components/chat-card-container/__stories__/result-card.tsx +31 -0
- package/src/components/chat-card-container/__stories__/types.ts +16 -0
- package/src/components/chat-card-container/chat-card-container.json +7 -0
- package/src/components/chat-card-container/chat-card-container.stories.tsx +209 -56
- package/src/components/chat-card-container/chat-card-container.tsx +5 -0
- package/src/components/chat-container/__stories__/chat-composer.tsx +67 -0
- package/src/components/chat-container/__stories__/fixtures.ts +27 -0
- package/src/components/chat-container/__stories__/measure.ts +22 -0
- package/src/components/chat-container/__stories__/types.ts +7 -0
- package/src/components/chat-container/__stories__/variable-readout.tsx +64 -0
- package/src/components/chat-container/chat-container.json +9 -1
- package/src/components/chat-container/chat-container.stories.tsx +538 -106
- package/src/components/chat-container/chat-container.tsx +3 -0
- package/src/components/chat-input/__stories__/fixtures.ts +31 -0
- package/src/components/chat-input/__tests__/chat-input.spec.tsx +100 -0
- package/src/components/chat-input/chat-input.json +11 -2
- package/src/components/chat-input/chat-input.stories.tsx +660 -197
- package/src/components/chat-input/chat-input.tsx +39 -5
- package/src/components/chat-input/plugins/controlled-value-plugin.tsx +16 -3
- package/src/components/chat-input/plugins/value-plugin.tsx +19 -4
- package/src/components/chat-list/__stories__/chat-row.tsx +41 -0
- package/src/components/chat-list/__stories__/fixtures.ts +94 -0
- package/src/components/chat-list/__stories__/types.ts +13 -0
- package/src/components/chat-list/chat-list-item.tsx +6 -0
- package/src/components/chat-list/chat-list-items.tsx +16 -0
- package/src/components/chat-list/chat-list.json +24 -2
- package/src/components/chat-list/chat-list.stories.tsx +631 -215
- package/src/components/chat-list/chat-list.tsx +51 -4
- package/src/components/chat-message/__stories__/fixtures.ts +53 -0
- package/src/components/chat-message/__stories__/sent-attachment.tsx +22 -0
- package/src/components/chat-message/__stories__/tool-steps.tsx +37 -0
- package/src/components/chat-message/chat-message.json +10 -1
- package/src/components/chat-message/chat-message.stories.tsx +282 -20
- package/src/components/chat-message/chat-message.tsx +16 -1
- package/src/components/chat-message/index.ts +8 -1
- package/src/components/chat-message-attachment-card/__stories__/fixtures.ts +30 -0
- package/src/components/chat-message-attachment-card/__stories__/types.ts +14 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card-icon.tsx +4 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.json +20 -0
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +266 -51
- package/src/components/chat-message-attachment-card/chat-message-attachment-card.tsx +37 -4
- package/src/components/chat-message-attachment-card/index.ts +6 -0
- package/src/components/chat-message-attachment-card/utils.ts +1 -0
- package/src/components/chat-message-response/__stories__/fixtures.ts +50 -0
- package/src/components/chat-message-response/chat-message-response.json +5 -0
- package/src/components/chat-message-response/chat-message-response.stories.tsx +135 -26
- package/src/components/chat-message-toolbar/chat-message-toolbar.json +21 -3
- package/src/components/chat-message-toolbar/chat-message-toolbar.stories.tsx +377 -6
- package/src/components/chat-message-toolbar/chat-message-toolbar.tsx +47 -12
- package/src/components/chat-message-toolbar/index.ts +4 -0
- package/src/components/chat-messages/__stories__/conversation-frame.tsx +25 -0
- package/src/components/chat-messages/__stories__/conversation-group.tsx +22 -0
- package/src/components/chat-messages/__stories__/fixtures.ts +70 -0
- package/src/components/chat-messages/__stories__/types.ts +5 -0
- package/src/components/chat-messages/chat-messages.json +30 -12
- package/src/components/chat-messages/chat-messages.stories.tsx +439 -212
- package/src/components/chat-messages/chat-messages.tsx +46 -3
- package/src/components/chat-notification-card/__stories__/fixtures.ts +38 -0
- package/src/components/chat-notification-card/__stories__/types.ts +13 -0
- package/src/components/chat-notification-card/chat-notification-card.json +52 -2
- package/src/components/chat-notification-card/chat-notification-card.stories.tsx +542 -62
- package/src/components/chat-notification-card/chat-notification-card.tsx +97 -6
- package/src/components/chat-notification-popup/__stories__/fixtures.ts +36 -0
- package/src/components/chat-notification-popup/__stories__/notification-item.tsx +93 -0
- package/src/components/chat-notification-popup/__stories__/types.ts +14 -0
- package/src/components/chat-notification-popup/chat-notification-popup.json +14 -1
- package/src/components/chat-notification-popup/chat-notification-popup.stories.tsx +467 -17
- package/src/components/chat-notification-popup/chat-notification-popup.tsx +18 -3
- package/src/components/chat-prompt-box/__stories__/fixtures.ts +16 -0
- package/src/components/chat-prompt-box/__stories__/types.ts +8 -0
- package/src/components/chat-prompt-box/chat-prompt-box.json +25 -2
- package/src/components/chat-prompt-box/chat-prompt-box.stories.tsx +535 -43
- package/src/components/chat-prompt-box/chat-prompt-box.tsx +73 -19
- package/src/components/chat-reply/chat-reply.json +10 -0
- package/src/components/chat-reply/chat-reply.stories.tsx +264 -21
- package/src/components/chat-reply/chat-reply.tsx +15 -0
- package/src/components/chat-reply/index.ts +10 -1
- package/src/components/chat-suggestion/__stories__/fixtures.ts +16 -0
- package/src/components/chat-suggestion/__tests__/chat-suggestion.spec.tsx +185 -0
- package/src/components/chat-suggestion/chat-suggestion.json +62 -20
- package/src/components/chat-suggestion/chat-suggestion.stories.tsx +542 -58
- package/src/components/chat-suggestion/chat-suggestion.tsx +154 -65
- package/src/components/chat-suggestion/index.ts +9 -0
- package/src/components/chat-thinking-process/__stories__/fixtures.ts +56 -0
- package/src/components/chat-thinking-process/chat-thinking-process.json +28 -3
- package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +354 -78
- package/src/components/chat-thinking-process/chat-thinking-process.tsx +55 -4
- package/src/components/chat-thread/__stories__/fixtures.ts +171 -0
- package/src/components/chat-thread/__stories__/scroll-position.ts +9 -0
- package/src/components/chat-thread/__stories__/snippets.ts +129 -0
- package/src/components/chat-thread/__stories__/thread-frame.tsx +22 -0
- package/src/components/chat-thread/__stories__/thread-turns.tsx +35 -0
- package/src/components/chat-thread/__stories__/types.ts +12 -0
- package/src/components/chat-thread/__stories__/use-turn-stream.ts +78 -0
- package/src/components/chat-thread/chat-thread.json +23 -3
- package/src/components/chat-thread/chat-thread.stories.tsx +804 -142
- package/src/components/chat-thread/chat-thread.tsx +64 -16
- package/src/components/index.ts +1 -3
- package/src/components/markdown-viewer/__stories__/fixtures.ts +67 -0
- package/src/components/markdown-viewer/markdown-viewer.json +7 -1
- package/src/components/markdown-viewer/markdown-viewer.stories.tsx +219 -50
- package/src/components/markdown-viewer/markdown-viewer.tsx +9 -0
- package/src/components/rich-text-area/__stories__/fixtures.ts +30 -0
- package/src/components/rich-text-area/__tests__/rich-text-area.spec.tsx +114 -0
- package/src/components/rich-text-area/plugins/controlled-value-plugin.tsx +20 -3
- package/src/components/rich-text-area/plugins/value-plugin.tsx +16 -3
- package/src/components/rich-text-area/rich-text-area.json +7 -4
- package/src/components/rich-text-area/rich-text-area.stories.tsx +597 -41
- package/src/components/rich-text-area/rich-text-area.tsx +27 -4
- package/src/components/rich-text-area/styled.tsx +11 -5
- package/src/components/rich-text-field/__stories__/fixtures.ts +29 -0
- package/src/components/rich-text-field/components/formatting-toolbar-plugin.tsx +10 -1
- package/src/components/rich-text-field/components/index.ts +8 -5
- package/src/components/rich-text-field/components/text-color-button.tsx +16 -2
- package/src/components/rich-text-field/rich-text-field.json +3 -1
- package/src/components/rich-text-field/rich-text-field.stories.tsx +452 -61
- package/src/components/rich-text-field/rich-text-field.tsx +23 -0
- package/src/components/topmenu/index.ts +1 -0
- package/src/components/topmenu/topmenu.json +107 -0
- package/src/components/topmenu/topmenu.stories.tsx +334 -0
- package/src/components/topmenu/topmenu.tsx +71 -0
- package/src/docs/agent.stories.tsx +16 -16
- package/src/docs/chat-panel.tsx +37 -32
- package/src/docs/chatbot-panel.tsx +11 -2
- package/src/docs/chatbot.mdx +17 -12
- package/src/docs/chatbot.stories.tsx +7 -8
- package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +112 -0
- package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +36 -0
- package/src/layouts/chat-card-list-layout/__stories__/types.ts +31 -0
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +14 -1
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +316 -84
- package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +11 -7
- package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +117 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +18 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +85 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +50 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +44 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +61 -0
- package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +35 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +16 -0
- package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +603 -182
- package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +51 -0
- package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +83 -0
- package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +24 -0
- package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +15 -0
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +13 -1
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +368 -67
- package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +11 -2
- package/dist/components/card-item-picker/card-item-picker-context.d.ts +0 -21
- package/dist/components/card-item-picker/card-item-picker-context.d.ts.map +0 -1
- package/dist/components/card-item-picker/card-item-picker-list.d.ts +0 -24
- package/dist/components/card-item-picker/card-item-picker-list.d.ts.map +0 -1
- package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts +0 -28
- package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts.map +0 -1
- package/dist/components/card-item-picker/card-item-picker-row.d.ts +0 -12
- package/dist/components/card-item-picker/card-item-picker-row.d.ts.map +0 -1
- package/dist/components/card-item-picker/card-item-picker.stories.d.ts +0 -19
- package/dist/components/card-item-picker/card-item-picker.stories.d.ts.map +0 -1
- package/dist/components/card-item-picker/index.d.ts +0 -9
- package/dist/components/card-item-picker/index.d.ts.map +0 -1
- package/dist/components/chat-message-history/chat-message-history.d.ts +0 -48
- package/dist/components/chat-message-history/chat-message-history.d.ts.map +0 -1
- package/dist/components/chat-message-history/chat-message-history.stories.d.ts +0 -7
- package/dist/components/chat-message-history/chat-message-history.stories.d.ts.map +0 -1
- package/dist/components/chat-message-history/index.d.ts +0 -2
- package/dist/components/chat-message-history/index.d.ts.map +0 -1
- package/dist/components/spinner/index.d.ts +0 -2
- package/dist/components/spinner/index.d.ts.map +0 -1
- package/dist/components/spinner/spinner.d.ts +0 -9
- package/dist/components/spinner/spinner.d.ts.map +0 -1
- package/dist/components/spinner/spinner.stories.d.ts +0 -8
- package/dist/components/spinner/spinner.stories.d.ts.map +0 -1
- package/src/components/card-item-picker/__tests__/card-item-picker.spec.tsx +0 -279
- package/src/components/card-item-picker/card-item-picker-context.tsx +0 -44
- package/src/components/card-item-picker/card-item-picker-list.tsx +0 -95
- package/src/components/card-item-picker/card-item-picker-row-parts.tsx +0 -96
- package/src/components/card-item-picker/card-item-picker-row.tsx +0 -109
- package/src/components/card-item-picker/card-item-picker.json +0 -147
- package/src/components/card-item-picker/card-item-picker.stories.tsx +0 -158
- package/src/components/card-item-picker/index.ts +0 -24
- package/src/components/chat-message-history/chat-message-history.json +0 -99
- package/src/components/chat-message-history/chat-message-history.stories.tsx +0 -136
- package/src/components/chat-message-history/chat-message-history.tsx +0 -277
- package/src/components/chat-message-history/index.ts +0 -13
- package/src/components/spinner/index.ts +0 -1
- package/src/components/spinner/spinner.json +0 -73
- package/src/components/spinner/spinner.stories.tsx +0 -41
- package/src/components/spinner/spinner.tsx +0 -32
|
@@ -1,90 +1,45 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
-
import { useEffect,
|
|
2
|
+
import { useEffect, useState, type ReactNode } from 'react';
|
|
3
|
+
import { expect, fn, waitFor, within } from 'storybook/test';
|
|
3
4
|
|
|
4
5
|
import { ChatConversationProvider } from '@/contexts';
|
|
6
|
+
import { ArrowDownIcon } from '@swisper.ai/icons';
|
|
7
|
+
import { Button, Typography, withTooltip } from '@swisper.ai/ui';
|
|
5
8
|
|
|
9
|
+
import { ParentBlock } from '../../__storybook__/parent-block';
|
|
10
|
+
import {
|
|
11
|
+
CanvasShell,
|
|
12
|
+
CanvasShellCloseTrigger,
|
|
13
|
+
CanvasShellContent,
|
|
14
|
+
CanvasShellHeader,
|
|
15
|
+
CanvasShellTitle,
|
|
16
|
+
} from '../canvas-shell';
|
|
6
17
|
import { ChatMessage, ChatMessageContent } from '../chat-message';
|
|
7
18
|
|
|
19
|
+
import { ConversationFrame } from './__stories__/conversation-frame';
|
|
20
|
+
import { ConversationGroup } from './__stories__/conversation-group';
|
|
21
|
+
import { ALL_TURNS, CONVERSATION, FOLLOW_UP_TURNS, SCROLL_TOOLTIP } from './__stories__/fixtures';
|
|
22
|
+
import type { ConversationTurn } from './__stories__/types';
|
|
8
23
|
import {
|
|
9
24
|
ChatMessageListGroup,
|
|
10
25
|
ChatMessages,
|
|
11
26
|
ChatMessagesList,
|
|
12
27
|
ChatMessagesScrollButton,
|
|
28
|
+
type ChatMessagesProps,
|
|
13
29
|
} from './chat-messages';
|
|
14
30
|
|
|
15
|
-
interface DemoMessage {
|
|
16
|
-
isQuestion: boolean;
|
|
17
|
-
text: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const defaultMessages: DemoMessage[] = [
|
|
21
|
-
{ isQuestion: true, text: 'What are my recent transactions?' },
|
|
22
|
-
{ isQuestion: false, text: 'Here is the history of your recent transactions.' },
|
|
23
|
-
{ isQuestion: true, text: 'Can you show the largest one?' },
|
|
24
|
-
{
|
|
25
|
-
isQuestion: false,
|
|
26
|
-
text: 'Your largest transaction this month was $1,240.50 at Acme Corp on May 12.',
|
|
27
|
-
},
|
|
28
|
-
{ isQuestion: true, text: 'How does that compare to last month?' },
|
|
29
|
-
{
|
|
30
|
-
isQuestion: false,
|
|
31
|
-
text: 'Last month your largest transaction was $980.20, so spending is up about 27%.',
|
|
32
|
-
},
|
|
33
|
-
{ isQuestion: true, text: 'Break down my spending by category this month.' },
|
|
34
|
-
{
|
|
35
|
-
isQuestion: false,
|
|
36
|
-
text: 'Groceries: $412.30, Dining: $286.15, Transport: $154.00, Subscriptions: $89.99.',
|
|
37
|
-
},
|
|
38
|
-
{ isQuestion: true, text: 'Which subscriptions am I paying for?' },
|
|
39
|
-
{
|
|
40
|
-
isQuestion: false,
|
|
41
|
-
text: 'You have four active subscriptions: StreamPlus, Cloud Storage, Fitness App, and News Daily.',
|
|
42
|
-
},
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
const addedMessages: DemoMessage[] = [
|
|
46
|
-
{ isQuestion: true, text: 'Can I set a budget alert for dining?' },
|
|
47
|
-
{ isQuestion: false, text: 'Yes. What monthly cap would you like?' },
|
|
48
|
-
{ isQuestion: true, text: 'Set it to $300.' },
|
|
49
|
-
{ isQuestion: false, text: 'Done. You will get an alert when dining spending hits $300.' },
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
const loremIpsumParagraph =
|
|
53
|
-
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
|
|
54
|
-
|
|
55
|
-
const streamingAnswers = [
|
|
56
|
-
Array.from({ length: 8 }, () => loremIpsumParagraph).join(' '),
|
|
57
|
-
Array.from({ length: 10 }, () => loremIpsumParagraph).join(' '),
|
|
58
|
-
Array.from({ length: 12 }, () => loremIpsumParagraph).join(' '),
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
const streamingQuestions = [
|
|
62
|
-
'Summarize my financial activity.',
|
|
63
|
-
'What are my largest expenses this month?',
|
|
64
|
-
'How can I reduce my subscription spending?',
|
|
65
|
-
'Break down my cash flow for the last quarter.',
|
|
66
|
-
'What is the weather in Tokyo?',
|
|
67
|
-
'Compare my dining spend to last month.',
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
function pickRandomItem<T>(items: T[]): T {
|
|
71
|
-
return items[Math.floor(Math.random() * items.length)];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
31
|
const meta: Meta<typeof ChatMessages> = {
|
|
75
|
-
title: '
|
|
32
|
+
title: 'Chat/ChatMessages',
|
|
76
33
|
component: ChatMessages,
|
|
77
|
-
parameters: {
|
|
34
|
+
parameters: {
|
|
35
|
+
layout: 'padded',
|
|
36
|
+
// Each story scrolls its last row into view, which would also scroll the docs page; an
|
|
37
|
+
// iframe per story keeps that scrolling inside the story.
|
|
38
|
+
docs: { story: { inline: false, height: '560px' } },
|
|
39
|
+
},
|
|
78
40
|
tags: ['autodocs'],
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<ChatConversationProvider chatId="storybook-chat">
|
|
82
|
-
<div className="relative h-[480px] w-[700px] bg-paper-1">
|
|
83
|
-
<Story />
|
|
84
|
-
</div>
|
|
85
|
-
</ChatConversationProvider>
|
|
86
|
-
),
|
|
87
|
-
],
|
|
41
|
+
// `ChatMessagesScrollButton` renders a tooltip, which needs a `TooltipProvider` above it.
|
|
42
|
+
decorators: [withTooltip],
|
|
88
43
|
argTypes: {
|
|
89
44
|
messageCount: {
|
|
90
45
|
control: 'number',
|
|
@@ -107,178 +62,450 @@ const meta: Meta<typeof ChatMessages> = {
|
|
|
107
62
|
description: 'Extra classes merged onto the root.',
|
|
108
63
|
},
|
|
109
64
|
},
|
|
110
|
-
args: {
|
|
111
|
-
messageCount: 0,
|
|
112
|
-
gap: 16,
|
|
113
|
-
},
|
|
114
65
|
};
|
|
115
66
|
|
|
116
|
-
function useGroupMessages(messages: DemoMessage[]) {
|
|
117
|
-
return useMemo(() => {
|
|
118
|
-
const groups: DemoMessage[][] = [];
|
|
119
|
-
|
|
120
|
-
for (let i = 0; i < messages.length; i += 2) {
|
|
121
|
-
groups.push(messages.slice(i, i + 2));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return groups;
|
|
125
|
-
}, [messages]);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
67
|
export default meta;
|
|
129
68
|
type Story = StoryObj<typeof ChatMessages>;
|
|
130
69
|
|
|
70
|
+
/** A finished conversation in a fixed-height panel: one row per question with its answer, opened at the latest one. Raise `messageCount` to add the next question. */
|
|
131
71
|
export const Default: Story = {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
<ChatMessageListGroup>
|
|
152
|
-
{group.map((message, messageIndex) => (
|
|
153
|
-
<ChatMessage
|
|
154
|
-
key={`${groupIndex}-${messageIndex}`}
|
|
155
|
-
isQuestion={message.isQuestion}
|
|
156
|
-
>
|
|
157
|
-
<ChatMessageContent>{message.text}</ChatMessageContent>
|
|
158
|
-
</ChatMessage>
|
|
159
|
-
))}
|
|
160
|
-
</ChatMessageListGroup>
|
|
161
|
-
);
|
|
162
|
-
}}
|
|
72
|
+
args: { messageCount: 4, gap: 16 },
|
|
73
|
+
argTypes: {
|
|
74
|
+
messageCount: { control: { type: 'number', min: 0, max: CONVERSATION.length } },
|
|
75
|
+
},
|
|
76
|
+
render: (args) => (
|
|
77
|
+
<ChatConversationProvider chatId="chat_spending_may">
|
|
78
|
+
<ConversationFrame>
|
|
79
|
+
<ChatMessages {...args}>
|
|
80
|
+
<ChatMessagesList className="p-16">
|
|
81
|
+
{(index) => (
|
|
82
|
+
<ChatMessageListGroup>
|
|
83
|
+
<ChatMessage isQuestion>
|
|
84
|
+
<ChatMessageContent>{CONVERSATION[index]?.question}</ChatMessageContent>
|
|
85
|
+
</ChatMessage>
|
|
86
|
+
<ChatMessage>
|
|
87
|
+
<ChatMessageContent>{CONVERSATION[index]?.answer}</ChatMessageContent>
|
|
88
|
+
</ChatMessage>
|
|
89
|
+
</ChatMessageListGroup>
|
|
90
|
+
)}
|
|
163
91
|
</ChatMessagesList>
|
|
164
|
-
<ChatMessagesScrollButton />
|
|
92
|
+
<ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
|
|
165
93
|
</ChatMessages>
|
|
94
|
+
</ConversationFrame>
|
|
95
|
+
</ChatConversationProvider>
|
|
96
|
+
),
|
|
97
|
+
};
|
|
166
98
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
99
|
+
/** The viewport that scrolls the `role="log"` list. */
|
|
100
|
+
function getViewport(log: HTMLElement): HTMLElement {
|
|
101
|
+
const viewport = log.closest<HTMLElement>('[data-slot="chat-messages-viewport"]');
|
|
102
|
+
|
|
103
|
+
if (!viewport) {
|
|
104
|
+
throw new Error('The message list is not inside a chat-messages-viewport');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return viewport;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function distanceFromBottom(viewport: HTMLElement): number {
|
|
111
|
+
return viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Scrolls up through the history, which shows the scroll button, then clicks it to return to the end. */
|
|
115
|
+
export const DefaultScrollToLatest: Story = {
|
|
116
|
+
...Default,
|
|
117
|
+
tags: ['e2e', '!autodocs'],
|
|
118
|
+
play: async ({ canvas, userEvent, step }) => {
|
|
119
|
+
const log = canvas.getByRole('log', { name: 'Message list' });
|
|
120
|
+
const viewport = getViewport(log);
|
|
121
|
+
|
|
122
|
+
await step('Opens at the latest question with the button hidden', async () => {
|
|
123
|
+
await waitFor(() => expect(distanceFromBottom(viewport)).toBeLessThanOrEqual(1));
|
|
124
|
+
await expect(within(log).getAllByRole('listitem')).toHaveLength(4);
|
|
125
|
+
await expect(canvas.getByText('Which subscriptions am I paying for?')).toBeVisible();
|
|
126
|
+
await expect(canvas.queryByRole('button', { name: SCROLL_TOOLTIP })).toBeNull();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
await step('Scrolling up shows the button', async () => {
|
|
130
|
+
// A wheel event is what tells the list the reader took over; the scroll alone could be its own.
|
|
131
|
+
viewport.dispatchEvent(new WheelEvent('wheel', { deltaY: -240, bubbles: true }));
|
|
132
|
+
viewport.scrollTop = 0;
|
|
133
|
+
|
|
134
|
+
const button = await canvas.findByRole('button', { name: SCROLL_TOOLTIP });
|
|
135
|
+
await waitFor(() => expect(button).toBeVisible());
|
|
136
|
+
await expect(viewport.scrollTop).toBe(0);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await step('Clicking it returns to the end and hides it again', async () => {
|
|
140
|
+
await userEvent.click(canvas.getByRole('button', { name: SCROLL_TOOLTIP }));
|
|
141
|
+
await waitFor(() => expect(distanceFromBottom(viewport)).toBeLessThanOrEqual(1), {
|
|
142
|
+
timeout: 3000,
|
|
143
|
+
});
|
|
144
|
+
await waitFor(() =>
|
|
145
|
+
expect(canvas.queryByRole('button', { name: SCROLL_TOOLTIP })).toBeNull(),
|
|
146
|
+
);
|
|
147
|
+
});
|
|
172
148
|
},
|
|
173
149
|
};
|
|
174
150
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const [messages, setMessages] = useState<DemoMessage[]>([
|
|
178
|
-
{ isQuestion: true, text: streamingQuestions[0] },
|
|
179
|
-
{ isQuestion: false, text: streamingAnswers[0] },
|
|
180
|
-
]);
|
|
181
|
-
const [activeAnswer, setActiveAnswer] = useState('');
|
|
182
|
-
const streamIndexRef = useRef(0);
|
|
183
|
-
const answerIndexRef = useRef(0);
|
|
184
|
-
const activeAnswerRef = useRef('');
|
|
185
|
-
const intervalRef = useRef<number | null>(null);
|
|
186
|
-
|
|
187
|
-
function clearStreamInterval() {
|
|
188
|
-
if (intervalRef.current === null) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
151
|
+
const STREAM_STEP = 4;
|
|
152
|
+
const STREAM_INTERVAL_MS = 40;
|
|
191
153
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
154
|
+
interface AssistantConversationProps {
|
|
155
|
+
initialTurns: ConversationTurn[];
|
|
156
|
+
followUps: ConversationTurn[];
|
|
157
|
+
onAsk: (question: string) => void;
|
|
158
|
+
}
|
|
197
159
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
160
|
+
function AssistantConversation({ initialTurns, followUps, onAsk }: AssistantConversationProps) {
|
|
161
|
+
const [turns, setTurns] = useState(initialTurns);
|
|
162
|
+
const lastIndex = turns.length - 1;
|
|
163
|
+
const lastAnswer = turns[lastIndex]?.answer ?? '';
|
|
164
|
+
// How much of the last answer has arrived; earlier answers are complete.
|
|
165
|
+
const [streamedLength, setStreamedLength] = useState(lastAnswer.length);
|
|
166
|
+
const isStreaming = streamedLength < lastAnswer.length;
|
|
167
|
+
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (!isStreaming) {
|
|
170
|
+
return undefined;
|
|
201
171
|
}
|
|
202
172
|
|
|
203
|
-
|
|
204
|
-
|
|
173
|
+
const interval = window.setInterval(() => {
|
|
174
|
+
setStreamedLength((length) => length + STREAM_STEP);
|
|
175
|
+
}, STREAM_INTERVAL_MS);
|
|
205
176
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
setStreamingAnswer(answer.slice(0, streamIndexRef.current));
|
|
177
|
+
return () => window.clearInterval(interval);
|
|
178
|
+
}, [isStreaming]);
|
|
209
179
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const nextValue = answer.slice(0, streamIndexRef.current);
|
|
180
|
+
function handleAsk() {
|
|
181
|
+
const next = followUps[(turns.length - initialTurns.length) % followUps.length];
|
|
213
182
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (nextValue.length >= answer.length) {
|
|
217
|
-
clearStreamInterval();
|
|
218
|
-
}
|
|
219
|
-
}, 40);
|
|
183
|
+
if (!next) {
|
|
184
|
+
return;
|
|
220
185
|
}
|
|
221
186
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
187
|
+
setTurns((currentTurns) => [...currentTurns, next]);
|
|
188
|
+
setStreamedLength(0);
|
|
189
|
+
onAsk(next.question);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<ChatConversationProvider chatId="chat_spending_may">
|
|
194
|
+
<div className="flex flex-col items-start gap-12">
|
|
195
|
+
<ConversationFrame>
|
|
196
|
+
<ChatMessages messageCount={turns.length}>
|
|
197
|
+
<ChatMessagesList className="p-16">
|
|
198
|
+
{(index) => {
|
|
199
|
+
const turn = turns[index];
|
|
200
|
+
|
|
201
|
+
if (!turn) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<ConversationGroup
|
|
207
|
+
turn={
|
|
208
|
+
index === lastIndex
|
|
209
|
+
? { ...turn, answer: turn.answer.slice(0, streamedLength) }
|
|
210
|
+
: turn
|
|
211
|
+
}
|
|
212
|
+
/>
|
|
213
|
+
);
|
|
214
|
+
}}
|
|
215
|
+
</ChatMessagesList>
|
|
216
|
+
<ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
|
|
217
|
+
</ChatMessages>
|
|
218
|
+
</ConversationFrame>
|
|
219
|
+
|
|
220
|
+
<Button variant="secondary" onClick={handleAsk}>
|
|
221
|
+
Ask a follow-up
|
|
222
|
+
</Button>
|
|
223
|
+
</div>
|
|
224
|
+
</ChatConversationProvider>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
226
227
|
|
|
227
|
-
|
|
228
|
+
type StreamingStory = StoryObj<typeof AssistantConversation>;
|
|
228
229
|
|
|
229
|
-
|
|
230
|
+
/** A new question settles at the top of the view and its answer streams in below it, past the end of the viewport. */
|
|
231
|
+
export const Streaming: StreamingStory = {
|
|
232
|
+
args: {
|
|
233
|
+
initialTurns: CONVERSATION.slice(0, 1),
|
|
234
|
+
followUps: FOLLOW_UP_TURNS,
|
|
235
|
+
onAsk: fn(),
|
|
236
|
+
},
|
|
237
|
+
argTypes: {
|
|
238
|
+
initialTurns: { control: 'object', description: 'The turns the conversation opens with.' },
|
|
239
|
+
followUps: {
|
|
240
|
+
control: 'object',
|
|
241
|
+
description: 'The questions "Ask a follow-up" sends, in order, with their streamed answers.',
|
|
242
|
+
},
|
|
243
|
+
onAsk: { description: 'Called with the question that was sent.' },
|
|
244
|
+
},
|
|
245
|
+
render: (args) => <AssistantConversation {...args} />,
|
|
246
|
+
};
|
|
230
247
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
248
|
+
/** Sends a follow-up and checks that the new question's group fills the viewport and settles at its top. */
|
|
249
|
+
export const StreamingNewQuestion: StreamingStory = {
|
|
250
|
+
...Streaming,
|
|
251
|
+
tags: ['e2e', '!autodocs'],
|
|
252
|
+
args: {
|
|
253
|
+
initialTurns: CONVERSATION.slice(0, 1),
|
|
254
|
+
followUps: FOLLOW_UP_TURNS,
|
|
255
|
+
onAsk: fn(),
|
|
256
|
+
},
|
|
257
|
+
play: async ({ args, canvas, userEvent, step }) => {
|
|
258
|
+
const log = canvas.getByRole('log', { name: 'Message list' });
|
|
259
|
+
const viewport = getViewport(log);
|
|
260
|
+
const question = 'Why was May so much more expensive than April?';
|
|
261
|
+
|
|
262
|
+
await step('Starts with one row', async () => {
|
|
263
|
+
await expect(within(log).getAllByRole('listitem')).toHaveLength(1);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
await step('A follow-up adds a row for the new question', async () => {
|
|
267
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Ask a follow-up' }));
|
|
268
|
+
await expect(args.onAsk).toHaveBeenCalledWith(question);
|
|
269
|
+
await expect(within(log).getAllByRole('listitem')).toHaveLength(2);
|
|
270
|
+
await expect(await canvas.findByText(question)).toBeVisible();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
await step('The new group is as tall as the viewport and settles at its top', async () => {
|
|
274
|
+
const group = canvas.getByText(question).closest('[data-slot="chat-message-list-group"]');
|
|
275
|
+
|
|
276
|
+
if (!group) {
|
|
277
|
+
throw new Error('The question is not inside a ChatMessageListGroup');
|
|
278
|
+
}
|
|
236
279
|
|
|
237
|
-
|
|
238
|
-
|
|
280
|
+
await expect(group).toHaveAttribute('data-is-last', 'true');
|
|
281
|
+
// The group's minimum height is the viewport's height minus one 16px gap.
|
|
282
|
+
await expect(group.getBoundingClientRect().height).toBeGreaterThanOrEqual(
|
|
283
|
+
viewport.clientHeight - 17,
|
|
284
|
+
);
|
|
285
|
+
await waitFor(
|
|
286
|
+
() =>
|
|
287
|
+
expect(
|
|
288
|
+
Math.abs(group.getBoundingClientRect().top - viewport.getBoundingClientRect().top),
|
|
289
|
+
).toBeLessThanOrEqual(2),
|
|
290
|
+
{ timeout: 3000 },
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
await step('The answer streams in below the question', async () => {
|
|
295
|
+
await expect(await canvas.findByText(/^May came to CHF 4,218\.40/)).toBeVisible();
|
|
296
|
+
});
|
|
297
|
+
},
|
|
298
|
+
};
|
|
239
299
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
300
|
+
/** The conversation in each place it's allowed: under its provider, in a canvas shell, in an assistant side panel and on a full-page chat. */
|
|
301
|
+
export const Examples: Story = {
|
|
302
|
+
parameters: {
|
|
303
|
+
controls: { disable: true },
|
|
304
|
+
docs: { story: { height: '860px' } },
|
|
305
|
+
},
|
|
306
|
+
render: () => (
|
|
307
|
+
<div className="grid gap-24 md:grid-cols-2">
|
|
308
|
+
<ParentBlock parent="web-chat-ui/ChatConversationProvider">
|
|
309
|
+
<ChatConversationProvider chatId="chat_spending_may">
|
|
310
|
+
<ConversationFrame className="h-90 max-w-none">
|
|
311
|
+
<ChatMessages messageCount={2}>
|
|
312
|
+
<ChatMessagesList className="p-16">
|
|
313
|
+
{(index) => {
|
|
314
|
+
const turn = CONVERSATION[index];
|
|
315
|
+
|
|
316
|
+
return turn ? <ConversationGroup turn={turn} /> : null;
|
|
317
|
+
}}
|
|
318
|
+
</ChatMessagesList>
|
|
319
|
+
<ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
|
|
320
|
+
</ChatMessages>
|
|
321
|
+
</ConversationFrame>
|
|
322
|
+
</ChatConversationProvider>
|
|
323
|
+
</ParentBlock>
|
|
324
|
+
|
|
325
|
+
<ParentBlock parent="web-chat-ui/CanvasShellContent">
|
|
326
|
+
<ChatConversationProvider chatId="chat_subscriptions">
|
|
327
|
+
<div className="h-90 rounded-10 border border-divider-border-base">
|
|
328
|
+
<CanvasShell>
|
|
329
|
+
<CanvasShellHeader>
|
|
330
|
+
<CanvasShellTitle>Subscriptions</CanvasShellTitle>
|
|
331
|
+
<CanvasShellCloseTrigger onClick={fn()} />
|
|
332
|
+
</CanvasShellHeader>
|
|
333
|
+
{/* The list scrolls itself and pads itself, so the shell does neither. */}
|
|
334
|
+
<CanvasShellContent hasScroll={false} hasPadding={false}>
|
|
335
|
+
<ChatMessages messageCount={FOLLOW_UP_TURNS.length - 1} className="h-full">
|
|
336
|
+
<ChatMessagesList className="px-16">
|
|
337
|
+
{(index) => {
|
|
338
|
+
const turn = FOLLOW_UP_TURNS[index + 1];
|
|
339
|
+
|
|
340
|
+
return turn ? <ConversationGroup turn={turn} /> : null;
|
|
341
|
+
}}
|
|
342
|
+
</ChatMessagesList>
|
|
343
|
+
<ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
|
|
344
|
+
</ChatMessages>
|
|
345
|
+
</CanvasShellContent>
|
|
346
|
+
</CanvasShell>
|
|
347
|
+
</div>
|
|
348
|
+
</ChatConversationProvider>
|
|
349
|
+
</ParentBlock>
|
|
350
|
+
|
|
351
|
+
<ParentBlock parent="assistant side panel">
|
|
352
|
+
<ChatConversationProvider chatId="chat_assistant_panel">
|
|
353
|
+
<aside
|
|
354
|
+
aria-label="Assistant"
|
|
355
|
+
className="flex h-90 max-w-90 flex-col border-l border-divider-border-base"
|
|
356
|
+
>
|
|
357
|
+
<Typography
|
|
358
|
+
variant="body-small-high"
|
|
359
|
+
fontWeight="medium"
|
|
360
|
+
className="border-b border-divider-border-base px-12 py-8"
|
|
361
|
+
>
|
|
362
|
+
Assistant
|
|
363
|
+
</Typography>
|
|
364
|
+
<ChatMessages messageCount={3} gap={12}>
|
|
365
|
+
<ChatMessagesList className="p-12">
|
|
366
|
+
{(index) => {
|
|
367
|
+
const turn = CONVERSATION[index + 2];
|
|
368
|
+
|
|
369
|
+
return turn ? <ConversationGroup turn={turn} /> : null;
|
|
370
|
+
}}
|
|
371
|
+
</ChatMessagesList>
|
|
372
|
+
<ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
|
|
373
|
+
</ChatMessages>
|
|
374
|
+
</aside>
|
|
375
|
+
</ChatConversationProvider>
|
|
376
|
+
</ParentBlock>
|
|
377
|
+
|
|
378
|
+
<ParentBlock parent="full-page chat">
|
|
379
|
+
<ChatConversationProvider chatId="chat_full_page">
|
|
380
|
+
<section aria-label="Chat" className="flex h-90 flex-col">
|
|
381
|
+
<ChatMessages messageCount={CONVERSATION.length} gap={24}>
|
|
382
|
+
{/* The list spans the page so the scrollbar sits at its edge; the column is centred. */}
|
|
383
|
+
<ChatMessagesList className="mx-auto w-full max-w-120 px-16 py-24">
|
|
384
|
+
{(index) => {
|
|
385
|
+
const turn = CONVERSATION[index];
|
|
386
|
+
|
|
387
|
+
return turn ? <ConversationGroup turn={turn} /> : null;
|
|
388
|
+
}}
|
|
389
|
+
</ChatMessagesList>
|
|
390
|
+
<ChatMessagesScrollButton tooltip={SCROLL_TOOLTIP} />
|
|
391
|
+
</ChatMessages>
|
|
392
|
+
</section>
|
|
393
|
+
</ChatConversationProvider>
|
|
394
|
+
</ParentBlock>
|
|
395
|
+
</div>
|
|
396
|
+
),
|
|
397
|
+
};
|
|
244
398
|
|
|
245
|
-
|
|
246
|
-
|
|
399
|
+
interface ChatMessagesPlaygroundProps extends Omit<ChatMessagesProps, 'children'> {
|
|
400
|
+
listClassName: string;
|
|
401
|
+
scrollAreaClassName: string;
|
|
402
|
+
viewportClassName: string;
|
|
403
|
+
bottomTriggerClassName: string;
|
|
404
|
+
hasScrollButton: boolean;
|
|
405
|
+
tooltip: string;
|
|
406
|
+
scrollButtonClassName: string;
|
|
407
|
+
buttonClassName: string;
|
|
408
|
+
icon: ReactNode;
|
|
409
|
+
}
|
|
247
410
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
411
|
+
function ChatMessagesPlayground({
|
|
412
|
+
listClassName,
|
|
413
|
+
scrollAreaClassName,
|
|
414
|
+
viewportClassName,
|
|
415
|
+
bottomTriggerClassName,
|
|
416
|
+
hasScrollButton,
|
|
417
|
+
tooltip,
|
|
418
|
+
scrollButtonClassName,
|
|
419
|
+
buttonClassName,
|
|
420
|
+
icon,
|
|
421
|
+
...rest
|
|
422
|
+
}: ChatMessagesPlaygroundProps) {
|
|
423
|
+
return (
|
|
424
|
+
<ChatConversationProvider chatId="chat_playground">
|
|
425
|
+
<ConversationFrame>
|
|
426
|
+
<ChatMessages {...rest}>
|
|
427
|
+
<ChatMessagesList
|
|
428
|
+
className={listClassName}
|
|
429
|
+
scrollAreaClassName={scrollAreaClassName}
|
|
430
|
+
viewportClassName={viewportClassName}
|
|
431
|
+
bottomTriggerClassName={bottomTriggerClassName}
|
|
432
|
+
>
|
|
433
|
+
{(index) => {
|
|
434
|
+
const turn = ALL_TURNS[index];
|
|
435
|
+
|
|
436
|
+
return turn ? <ConversationGroup turn={turn} /> : null;
|
|
273
437
|
}}
|
|
274
438
|
</ChatMessagesList>
|
|
275
|
-
|
|
439
|
+
{hasScrollButton && (
|
|
440
|
+
<ChatMessagesScrollButton
|
|
441
|
+
tooltip={tooltip}
|
|
442
|
+
className={scrollButtonClassName}
|
|
443
|
+
buttonClassName={buttonClassName}
|
|
444
|
+
>
|
|
445
|
+
{icon}
|
|
446
|
+
</ChatMessagesScrollButton>
|
|
447
|
+
)}
|
|
276
448
|
</ChatMessages>
|
|
449
|
+
</ConversationFrame>
|
|
450
|
+
</ChatConversationProvider>
|
|
451
|
+
);
|
|
452
|
+
}
|
|
277
453
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
454
|
+
/** Every part at once, with each prop of the root, the list and the scroll button on the Controls panel. */
|
|
455
|
+
export const Playground: StoryObj<typeof ChatMessagesPlayground> = {
|
|
456
|
+
tags: ['!autodocs'],
|
|
457
|
+
args: {
|
|
458
|
+
messageCount: ALL_TURNS.length,
|
|
459
|
+
gap: 16,
|
|
460
|
+
className: '',
|
|
461
|
+
listClassName: 'p-16',
|
|
462
|
+
scrollAreaClassName: '',
|
|
463
|
+
viewportClassName: '',
|
|
464
|
+
bottomTriggerClassName: '',
|
|
465
|
+
hasScrollButton: true,
|
|
466
|
+
tooltip: SCROLL_TOOLTIP,
|
|
467
|
+
scrollButtonClassName: '',
|
|
468
|
+
buttonClassName: '',
|
|
469
|
+
icon: 'Chevron (default)',
|
|
470
|
+
},
|
|
471
|
+
argTypes: {
|
|
472
|
+
messageCount: { control: { type: 'number', min: 0, max: ALL_TURNS.length } },
|
|
473
|
+
listClassName: {
|
|
474
|
+
control: 'text',
|
|
475
|
+
description: '`className` on `ChatMessagesList`: the padding and width of the list.',
|
|
476
|
+
},
|
|
477
|
+
scrollAreaClassName: {
|
|
478
|
+
control: 'text',
|
|
479
|
+
description: '`scrollAreaClassName` on `ChatMessagesList`: the scroll container.',
|
|
480
|
+
},
|
|
481
|
+
viewportClassName: {
|
|
482
|
+
control: 'text',
|
|
483
|
+
description: '`viewportClassName` on `ChatMessagesList`: the scrolling viewport.',
|
|
484
|
+
},
|
|
485
|
+
bottomTriggerClassName: {
|
|
486
|
+
control: 'text',
|
|
487
|
+
description:
|
|
488
|
+
'`bottomTriggerClassName` on `ChatMessagesList`: the hidden sentinel after the last row, e.g. `h-24` to count as "at the bottom" sooner.',
|
|
489
|
+
},
|
|
490
|
+
hasScrollButton: { control: 'boolean', description: 'Renders `ChatMessagesScrollButton`.' },
|
|
491
|
+
tooltip: {
|
|
492
|
+
control: 'text',
|
|
493
|
+
description: '`tooltip` on `ChatMessagesScrollButton`: its tooltip and accessible name.',
|
|
494
|
+
},
|
|
495
|
+
scrollButtonClassName: {
|
|
496
|
+
control: 'text',
|
|
497
|
+
description: '`className` on `ChatMessagesScrollButton`: the wrapper that positions it.',
|
|
498
|
+
},
|
|
499
|
+
buttonClassName: {
|
|
500
|
+
control: 'text',
|
|
501
|
+
description: '`buttonClassName` on `ChatMessagesScrollButton`: the icon button itself.',
|
|
502
|
+
},
|
|
503
|
+
icon: {
|
|
504
|
+
control: 'select',
|
|
505
|
+
options: ['Chevron (default)', 'Arrow'],
|
|
506
|
+
mapping: { 'Chevron (default)': undefined, Arrow: <ArrowDownIcon /> },
|
|
507
|
+
description: 'Children of `ChatMessagesScrollButton`; they replace the chevron.',
|
|
508
|
+
},
|
|
283
509
|
},
|
|
510
|
+
render: (args) => <ChatMessagesPlayground {...args} />,
|
|
284
511
|
};
|