@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,218 +1,880 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
+
import { expect, fn, waitFor } from 'storybook/test';
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
+
import { EnterIcon } from '@swisper.ai/icons';
|
|
6
|
+
import {
|
|
7
|
+
Banner,
|
|
8
|
+
BannerAction,
|
|
9
|
+
BannerConfirm,
|
|
10
|
+
BannerDescription,
|
|
11
|
+
BannerTitle,
|
|
12
|
+
Button,
|
|
13
|
+
IconButton,
|
|
14
|
+
withTooltip,
|
|
15
|
+
} from '@swisper.ai/ui';
|
|
16
|
+
|
|
17
|
+
import { ParentBlock } from '../../__storybook__/parent-block';
|
|
18
|
+
import {
|
|
19
|
+
CanvasShell,
|
|
20
|
+
CanvasShellCloseTrigger,
|
|
21
|
+
CanvasShellContent,
|
|
22
|
+
CanvasShellFooter,
|
|
23
|
+
CanvasShellHeader,
|
|
24
|
+
CanvasShellTitle,
|
|
25
|
+
canvasShellContentPadding,
|
|
26
|
+
} from '../canvas-shell';
|
|
27
|
+
import { ChatMessage, ChatMessageContent } from '../chat-message';
|
|
28
|
+
import {
|
|
29
|
+
ChatPromptBox,
|
|
30
|
+
ChatPromptBoxActionsRight,
|
|
31
|
+
ChatPromptBoxContent,
|
|
32
|
+
ChatPromptBoxInput,
|
|
33
|
+
} from '../chat-prompt-box';
|
|
5
34
|
|
|
35
|
+
import {
|
|
36
|
+
LISBON_TRIP,
|
|
37
|
+
NEXT_INSTRUCTIONS,
|
|
38
|
+
NEXT_QUESTIONS,
|
|
39
|
+
REPORT_RUN,
|
|
40
|
+
WEEK_AHEAD,
|
|
41
|
+
} from './__stories__/fixtures';
|
|
42
|
+
import { distanceFromEnd, offsetFromTop } from './__stories__/scroll-position';
|
|
43
|
+
import {
|
|
44
|
+
DEFAULT_SOURCE,
|
|
45
|
+
EXAMPLES_SOURCE,
|
|
46
|
+
FOLLOW_MODE_SOURCE,
|
|
47
|
+
SCROLL_COMMANDS_SOURCE,
|
|
48
|
+
STREAMING_SOURCE,
|
|
49
|
+
} from './__stories__/snippets';
|
|
50
|
+
import { ThreadFrame } from './__stories__/thread-frame';
|
|
51
|
+
import { ThreadTurns } from './__stories__/thread-turns';
|
|
52
|
+
import type { Turn } from './__stories__/types';
|
|
53
|
+
import { useTurnStream } from './__stories__/use-turn-stream';
|
|
6
54
|
import {
|
|
7
55
|
ChatThread,
|
|
8
56
|
ChatThreadAnswer,
|
|
9
57
|
ChatThreadGroup,
|
|
10
58
|
ChatThreadProvider,
|
|
11
59
|
ChatThreadQuestion,
|
|
60
|
+
useChatThread,
|
|
12
61
|
type ChatThreadProviderProps,
|
|
62
|
+
type ChatThreadScrollMode,
|
|
13
63
|
} from './chat-thread';
|
|
14
64
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
65
|
+
const meta: Meta<typeof ChatThread> = {
|
|
66
|
+
title: 'Chat/ChatThread',
|
|
67
|
+
component: ChatThread,
|
|
68
|
+
subcomponents: { ChatThreadProvider, ChatThreadGroup, ChatThreadQuestion, ChatThreadAnswer },
|
|
69
|
+
tags: ['autodocs'],
|
|
70
|
+
// The scroll-to-latest button is wrapped in a Tooltip, which needs a TooltipProvider above the thread
|
|
71
|
+
decorators: [withTooltip],
|
|
72
|
+
argTypes: {
|
|
73
|
+
children: {
|
|
74
|
+
control: false,
|
|
75
|
+
description:
|
|
76
|
+
'One `ChatThreadGroup` per turn, each holding a `ChatThreadQuestion` and a `ChatThreadAnswer`.',
|
|
77
|
+
},
|
|
78
|
+
className: {
|
|
79
|
+
control: false,
|
|
80
|
+
description:
|
|
81
|
+
'Classes on the root. The thread needs a definite height from its parent, e.g. `h-full`.',
|
|
82
|
+
},
|
|
83
|
+
viewportClassName: {
|
|
84
|
+
control: false,
|
|
85
|
+
description:
|
|
86
|
+
'Classes on the scrolling viewport, the element between the root and the content.',
|
|
87
|
+
},
|
|
88
|
+
contentClassName: {
|
|
89
|
+
control: false,
|
|
90
|
+
description:
|
|
91
|
+
'Classes on the scrolled content: its padding and the gap between groups (`gap-16` by default).',
|
|
92
|
+
},
|
|
93
|
+
scrollButton: {
|
|
94
|
+
control: 'boolean',
|
|
95
|
+
description: 'Renders the scroll-to-latest button, shown while there is content below.',
|
|
96
|
+
table: { defaultValue: { summary: 'true' } },
|
|
97
|
+
},
|
|
98
|
+
scrollButtonTooltip: {
|
|
99
|
+
control: 'text',
|
|
100
|
+
description:
|
|
101
|
+
'Tooltip of the scroll-to-latest button and its only accessible name. Required when `scrollButton` is on.',
|
|
102
|
+
},
|
|
103
|
+
scrollButtonClassName: {
|
|
104
|
+
control: false,
|
|
105
|
+
description: 'Classes on the wrapper that positions the scroll-to-latest button.',
|
|
106
|
+
},
|
|
107
|
+
isLoading: {
|
|
108
|
+
control: 'boolean',
|
|
109
|
+
description:
|
|
110
|
+
'Sets `data-loading` on the root and hides the error state. It renders nothing itself.',
|
|
111
|
+
table: { defaultValue: { summary: 'false' } },
|
|
112
|
+
},
|
|
113
|
+
hasError: {
|
|
114
|
+
control: 'boolean',
|
|
115
|
+
description: 'Covers the thread with the error state, unless `isLoading` is on.',
|
|
116
|
+
table: { defaultValue: { summary: 'false' } },
|
|
117
|
+
},
|
|
118
|
+
error: {
|
|
119
|
+
control: 'text',
|
|
120
|
+
description:
|
|
121
|
+
'What failed, as an `Error` or a string. Without it the text is "An error occurred".',
|
|
122
|
+
},
|
|
123
|
+
renderError: {
|
|
124
|
+
control: false,
|
|
125
|
+
description: 'Replaces the built-in error text with your own content.',
|
|
126
|
+
},
|
|
127
|
+
viewportRef: {
|
|
128
|
+
control: false,
|
|
129
|
+
description: 'Ref to the scrolling viewport.',
|
|
130
|
+
},
|
|
131
|
+
contentRef: {
|
|
132
|
+
control: false,
|
|
133
|
+
description: 'Ref to the content element inside the viewport.',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export default meta;
|
|
139
|
+
type Story = StoryObj<typeof ChatThread>;
|
|
140
|
+
|
|
141
|
+
/** A loaded conversation: it opens at the latest message, and every group it opens with counts as history. */
|
|
142
|
+
export const Default: Story = {
|
|
143
|
+
args: {
|
|
144
|
+
contentClassName: 'p-12',
|
|
145
|
+
scrollButtonTooltip: 'Scroll to the latest',
|
|
146
|
+
},
|
|
147
|
+
parameters: {
|
|
148
|
+
docs: { source: { code: DEFAULT_SOURCE } },
|
|
149
|
+
},
|
|
150
|
+
render: (args) => (
|
|
151
|
+
<ThreadFrame>
|
|
152
|
+
<ChatThreadProvider
|
|
153
|
+
conversationId={WEEK_AHEAD.id}
|
|
154
|
+
groupIds={WEEK_AHEAD.turns.map((turn) => turn.id)}
|
|
155
|
+
>
|
|
156
|
+
<ChatThread {...args}>
|
|
157
|
+
{WEEK_AHEAD.turns.map((turn) => (
|
|
158
|
+
<ChatThreadGroup key={turn.id} groupId={turn.id}>
|
|
159
|
+
<ChatThreadQuestion messageId={`${turn.id}-question`}>
|
|
160
|
+
<ChatMessage isQuestion>
|
|
161
|
+
<ChatMessageContent>{turn.question}</ChatMessageContent>
|
|
162
|
+
</ChatMessage>
|
|
163
|
+
</ChatThreadQuestion>
|
|
164
|
+
<ChatThreadAnswer messageId={`${turn.id}-answer`}>
|
|
165
|
+
<ChatMessage>
|
|
166
|
+
{turn.answer.map((block, index) => (
|
|
167
|
+
<ChatMessageContent key={index}>{block}</ChatMessageContent>
|
|
168
|
+
))}
|
|
169
|
+
</ChatMessage>
|
|
170
|
+
</ChatThreadAnswer>
|
|
171
|
+
</ChatThreadGroup>
|
|
172
|
+
))}
|
|
173
|
+
</ChatThread>
|
|
174
|
+
</ChatThreadProvider>
|
|
175
|
+
</ThreadFrame>
|
|
176
|
+
),
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
function StreamingThread() {
|
|
180
|
+
const { turns, isStreaming, sendNext } = useTurnStream(WEEK_AHEAD.turns.slice(0, 3), {
|
|
181
|
+
nextTurns: NEXT_QUESTIONS,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<div className="mx-auto flex max-w-105 flex-col gap-12">
|
|
186
|
+
<ThreadFrame>
|
|
187
|
+
<ChatThreadProvider
|
|
188
|
+
conversationId={WEEK_AHEAD.id}
|
|
189
|
+
groupIds={turns.map((turn) => turn.id)}
|
|
190
|
+
isStreaming={isStreaming}
|
|
191
|
+
>
|
|
192
|
+
<ChatThread contentClassName="p-12" scrollButtonTooltip="Scroll to the latest">
|
|
193
|
+
<ThreadTurns turns={turns} />
|
|
194
|
+
</ChatThread>
|
|
195
|
+
</ChatThreadProvider>
|
|
196
|
+
</ThreadFrame>
|
|
197
|
+
<Button className="self-start" isLoading={isStreaming} onClick={sendNext}>
|
|
198
|
+
Ask the next question
|
|
199
|
+
</Button>
|
|
200
|
+
</div>
|
|
201
|
+
);
|
|
19
202
|
}
|
|
20
203
|
|
|
21
|
-
|
|
22
|
-
|
|
204
|
+
/**
|
|
205
|
+
* The default `anchor` mode. Ask a question: it settles at the top of the thread and its answer
|
|
206
|
+
* streams in below without the scroll position moving, so the answer reads from its start.
|
|
207
|
+
*/
|
|
208
|
+
export const Streaming: Story = {
|
|
209
|
+
parameters: {
|
|
210
|
+
controls: { disable: true },
|
|
211
|
+
docs: { source: { code: STREAMING_SOURCE } },
|
|
212
|
+
},
|
|
213
|
+
render: () => <StreamingThread />,
|
|
214
|
+
};
|
|
23
215
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
216
|
+
/** Asks the next question and checks that it settles at the top while its answer streams in below. */
|
|
217
|
+
export const StreamingAnchorsQuestion: Story = {
|
|
218
|
+
tags: ['e2e', '!autodocs'],
|
|
219
|
+
parameters: { controls: { disable: true } },
|
|
220
|
+
render: () => <StreamingThread />,
|
|
221
|
+
play: async ({ canvas, userEvent, step }) => {
|
|
222
|
+
const viewport = canvas.getByRole('region', { name: 'Chat message history' });
|
|
223
|
+
const log = canvas.getByRole('log');
|
|
224
|
+
|
|
225
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Ask the next question' }));
|
|
226
|
+
const question = await canvas.findByText('Summarise my unread emails');
|
|
227
|
+
|
|
228
|
+
await step('Settles the new question at the top of the thread', async () => {
|
|
229
|
+
await waitFor(() => expect(offsetFromTop(question, viewport)).toBeLessThan(48), {
|
|
230
|
+
timeout: 3000,
|
|
231
|
+
});
|
|
232
|
+
await expect(offsetFromTop(question, viewport)).toBeGreaterThanOrEqual(0);
|
|
233
|
+
await expect(log).toHaveAttribute('aria-busy', 'true');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
await step('Keeps the question in place while the answer streams', async () => {
|
|
237
|
+
await canvas.findByText(
|
|
238
|
+
'You have seven unread emails. Three of them need your attention today.',
|
|
239
|
+
undefined,
|
|
240
|
+
{ timeout: 5000 },
|
|
241
|
+
);
|
|
242
|
+
await expect(offsetFromTop(question, viewport)).toBeGreaterThanOrEqual(0);
|
|
243
|
+
await expect(offsetFromTop(question, viewport)).toBeLessThan(48);
|
|
244
|
+
});
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
function AgentRunThread() {
|
|
249
|
+
const { turns, isStreaming, sendNext } = useTurnStream(REPORT_RUN.turns, {
|
|
250
|
+
nextTurns: NEXT_INSTRUCTIONS,
|
|
251
|
+
chunk: 'line',
|
|
252
|
+
intervalMs: 600,
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<div className="mx-auto flex max-w-105 flex-col gap-12">
|
|
257
|
+
<ThreadFrame>
|
|
258
|
+
<ChatThreadProvider
|
|
259
|
+
conversationId={REPORT_RUN.id}
|
|
260
|
+
groupIds={turns.map((turn) => turn.id)}
|
|
261
|
+
isStreaming={isStreaming}
|
|
262
|
+
scrollMode="follow"
|
|
263
|
+
>
|
|
264
|
+
<ChatThread contentClassName="p-12" scrollButtonTooltip="Jump to latest">
|
|
265
|
+
<ThreadTurns turns={turns} />
|
|
266
|
+
</ChatThread>
|
|
267
|
+
</ChatThreadProvider>
|
|
268
|
+
</ThreadFrame>
|
|
269
|
+
<Button className="self-start" isLoading={isStreaming} onClick={sendNext}>
|
|
270
|
+
Run the next step
|
|
271
|
+
</Button>
|
|
272
|
+
</div>
|
|
273
|
+
);
|
|
30
274
|
}
|
|
31
275
|
|
|
32
|
-
|
|
33
|
-
|
|
276
|
+
/**
|
|
277
|
+
* `scrollMode="follow"` for an agent run. Run a step: new output is added at the bottom and the
|
|
278
|
+
* view stays on it, like a terminal. Scroll up while it runs and the view stops following.
|
|
279
|
+
*/
|
|
280
|
+
export const FollowMode: Story = {
|
|
281
|
+
parameters: {
|
|
282
|
+
controls: { disable: true },
|
|
283
|
+
docs: { source: { code: FOLLOW_MODE_SOURCE } },
|
|
284
|
+
},
|
|
285
|
+
render: () => <AgentRunThread />,
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/** Runs the next step and checks that the view stays on the newest output as lines arrive. */
|
|
289
|
+
export const FollowModeFollowsOutput: Story = {
|
|
290
|
+
tags: ['e2e', '!autodocs'],
|
|
291
|
+
parameters: { controls: { disable: true } },
|
|
292
|
+
render: () => <AgentRunThread />,
|
|
293
|
+
play: async ({ canvas, userEvent, step }) => {
|
|
294
|
+
const viewport = canvas.getByRole('region', { name: 'Chat message history' });
|
|
295
|
+
|
|
296
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Run the next step' }));
|
|
297
|
+
|
|
298
|
+
await step('Shows the new instruction at the end of the thread', async () => {
|
|
299
|
+
await expect(
|
|
300
|
+
await canvas.findByText('Compare the totals with the second quarter'),
|
|
301
|
+
).toBeVisible();
|
|
302
|
+
await waitFor(() => expect(distanceFromEnd(viewport)).toBeLessThanOrEqual(8));
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
await step('Follows each line of output', async () => {
|
|
306
|
+
const line = await canvas.findByText('Revenue is up 6% on the second quarter', undefined, {
|
|
307
|
+
timeout: 5000,
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
await waitFor(() => expect(distanceFromEnd(viewport)).toBeLessThanOrEqual(8));
|
|
311
|
+
await expect(line).toBeVisible();
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* The scroll-to-latest button, visible here because the conversation opens at its start
|
|
318
|
+
* (`defaultScrollPosition="start"`). It shows only while there is content below the viewport.
|
|
319
|
+
*/
|
|
320
|
+
export const ScrollButton: Story = {
|
|
321
|
+
parameters: { controls: { disable: true } },
|
|
322
|
+
render: () => (
|
|
323
|
+
<ThreadFrame>
|
|
324
|
+
<ChatThreadProvider
|
|
325
|
+
conversationId={WEEK_AHEAD.id}
|
|
326
|
+
groupIds={WEEK_AHEAD.turns.map((turn) => turn.id)}
|
|
327
|
+
defaultScrollPosition="start"
|
|
328
|
+
>
|
|
329
|
+
<ChatThread contentClassName="p-12" scrollButtonTooltip="Scroll to the latest">
|
|
330
|
+
<ThreadTurns turns={WEEK_AHEAD.turns} />
|
|
331
|
+
</ChatThread>
|
|
332
|
+
</ChatThreadProvider>
|
|
333
|
+
</ThreadFrame>
|
|
334
|
+
),
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
/** Clicks the scroll-to-latest button and checks that the thread reaches its end and the button goes. */
|
|
338
|
+
export const ScrollButtonReturnsToLatest: Story = {
|
|
339
|
+
tags: ['e2e', '!autodocs'],
|
|
340
|
+
parameters: { controls: { disable: true } },
|
|
341
|
+
render: ScrollButton.render,
|
|
342
|
+
play: async ({ canvas, userEvent, step }) => {
|
|
343
|
+
const viewport = canvas.getByRole('region', { name: 'Chat message history' });
|
|
344
|
+
const button = await canvas.findByRole('button', { name: 'Scroll to the latest' });
|
|
345
|
+
|
|
346
|
+
await step('Opens at the start, with content below', async () => {
|
|
347
|
+
await expect(viewport.scrollTop).toBe(0);
|
|
348
|
+
await expect(distanceFromEnd(viewport)).toBeGreaterThan(8);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
await step('Scrolls to the latest message and hides the button', async () => {
|
|
352
|
+
await userEvent.click(button);
|
|
353
|
+
await waitFor(() => expect(distanceFromEnd(viewport)).toBeLessThanOrEqual(8), {
|
|
354
|
+
timeout: 3000,
|
|
355
|
+
});
|
|
356
|
+
await waitFor(() =>
|
|
357
|
+
expect(canvas.queryByRole('button', { name: 'Scroll to the latest' })).toBeNull(),
|
|
358
|
+
);
|
|
359
|
+
});
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
function ConversationSwitcher() {
|
|
364
|
+
const [isTripOpen, setIsTripOpen] = useState(false);
|
|
365
|
+
const conversation = isTripOpen ? LISBON_TRIP : WEEK_AHEAD;
|
|
366
|
+
const other = isTripOpen ? WEEK_AHEAD : LISBON_TRIP;
|
|
367
|
+
|
|
368
|
+
return (
|
|
369
|
+
<div className="mx-auto flex max-w-105 flex-col gap-12">
|
|
370
|
+
<ThreadFrame>
|
|
371
|
+
<ChatThreadProvider
|
|
372
|
+
conversationId={conversation.id}
|
|
373
|
+
groupIds={conversation.turns.map((turn) => turn.id)}
|
|
374
|
+
>
|
|
375
|
+
<ChatThread contentClassName="p-12" scrollButtonTooltip="Scroll to the latest">
|
|
376
|
+
<ThreadTurns turns={conversation.turns} />
|
|
377
|
+
</ChatThread>
|
|
378
|
+
</ChatThreadProvider>
|
|
379
|
+
</ThreadFrame>
|
|
380
|
+
<Button className="self-start" onClick={() => setIsTripOpen((current) => !current)}>
|
|
381
|
+
Open “{other.title}”
|
|
382
|
+
</Button>
|
|
383
|
+
</div>
|
|
384
|
+
);
|
|
34
385
|
}
|
|
35
386
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Changing `conversationId` starts a new session: the other conversation's groups count as history
|
|
389
|
+
* and it opens at its latest message, instead of its groups being treated as new questions.
|
|
390
|
+
*/
|
|
391
|
+
export const SwitchConversation: Story = {
|
|
392
|
+
parameters: { controls: { disable: true } },
|
|
393
|
+
render: () => <ConversationSwitcher />,
|
|
40
394
|
};
|
|
41
395
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
396
|
+
/** Opens the other conversation and checks that it loads as history, at its latest message. */
|
|
397
|
+
export const SwitchConversationOpensAtEnd: Story = {
|
|
398
|
+
tags: ['e2e', '!autodocs'],
|
|
399
|
+
parameters: { controls: { disable: true } },
|
|
400
|
+
render: () => <ConversationSwitcher />,
|
|
401
|
+
play: async ({ canvas, userEvent, step }) => {
|
|
402
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Open “Trip to Lisbon”' }));
|
|
403
|
+
|
|
404
|
+
await step('Replaces the thread with the other conversation', async () => {
|
|
405
|
+
await canvas.findByText('Which flights get me to Lisbon before noon on Friday?');
|
|
406
|
+
await expect(canvas.queryByText('What’s on my calendar tomorrow?')).toBeNull();
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
await step('Opens it at the latest message', async () => {
|
|
410
|
+
const viewport = canvas.getByRole('region', { name: 'Chat message history' });
|
|
411
|
+
|
|
412
|
+
await waitFor(() => expect(distanceFromEnd(viewport)).toBeLessThanOrEqual(8));
|
|
413
|
+
await expect(canvas.getByText('Block Friday to Monday in my calendar.')).toBeVisible();
|
|
414
|
+
});
|
|
415
|
+
},
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
interface ScrollCommandButtonsProps {
|
|
419
|
+
target: Turn;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function ScrollCommandButtons({ target }: ScrollCommandButtonsProps) {
|
|
423
|
+
const { scrollToStart, scrollToMessage, scrollToEnd } = useChatThread();
|
|
424
|
+
|
|
425
|
+
return (
|
|
426
|
+
<div className="flex flex-wrap gap-8">
|
|
427
|
+
<Button size="sm" onClick={() => scrollToStart({ behavior: 'smooth' })}>
|
|
428
|
+
Go to the start
|
|
429
|
+
</Button>
|
|
430
|
+
<Button
|
|
431
|
+
size="sm"
|
|
432
|
+
onClick={() =>
|
|
433
|
+
scrollToMessage(`chat-thread-group-${target.id}`, { align: 'start', behavior: 'smooth' })
|
|
434
|
+
}
|
|
435
|
+
>
|
|
436
|
+
Go to the second question
|
|
437
|
+
</Button>
|
|
438
|
+
<Button size="sm" onClick={() => scrollToEnd({ behavior: 'smooth' })}>
|
|
439
|
+
Go to the latest
|
|
440
|
+
</Button>
|
|
441
|
+
</div>
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* `useChatThread` gives any component inside the provider the scroll commands: to the start, to
|
|
447
|
+
* one group, or to the latest message.
|
|
448
|
+
*/
|
|
449
|
+
export const ScrollCommands: Story = {
|
|
450
|
+
parameters: {
|
|
451
|
+
controls: { disable: true },
|
|
452
|
+
docs: { source: { code: SCROLL_COMMANDS_SOURCE } },
|
|
453
|
+
},
|
|
454
|
+
render: () => (
|
|
455
|
+
<ChatThreadProvider
|
|
456
|
+
conversationId={WEEK_AHEAD.id}
|
|
457
|
+
groupIds={WEEK_AHEAD.turns.map((turn) => turn.id)}
|
|
458
|
+
>
|
|
459
|
+
<div className="mx-auto flex max-w-105 flex-col gap-12">
|
|
460
|
+
<ThreadFrame>
|
|
461
|
+
<ChatThread contentClassName="p-12" scrollButtonTooltip="Scroll to the latest">
|
|
462
|
+
<ThreadTurns turns={WEEK_AHEAD.turns} />
|
|
463
|
+
</ChatThread>
|
|
464
|
+
</ThreadFrame>
|
|
465
|
+
{WEEK_AHEAD.turns[1] && <ScrollCommandButtons target={WEEK_AHEAD.turns[1]} />}
|
|
466
|
+
</div>
|
|
467
|
+
</ChatThreadProvider>
|
|
468
|
+
),
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
/** Drives the three scroll commands from outside the thread: the start, one group, the latest. */
|
|
472
|
+
export const ScrollCommandsMoveTheThread: Story = {
|
|
473
|
+
tags: ['e2e', '!autodocs'],
|
|
474
|
+
parameters: { controls: { disable: true } },
|
|
475
|
+
render: ScrollCommands.render,
|
|
476
|
+
play: async ({ canvas, userEvent, step }) => {
|
|
477
|
+
const viewport = canvas.getByRole('region', { name: 'Chat message history' });
|
|
478
|
+
|
|
479
|
+
await step('Opens at the latest message', async () => {
|
|
480
|
+
await waitFor(() => expect(distanceFromEnd(viewport)).toBeLessThanOrEqual(8));
|
|
481
|
+
// The scroller ignores a command sent while its own opening scroll is still settling
|
|
482
|
+
await waitFor(() => expect(viewport).not.toHaveAttribute('data-autoscrolling'));
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
await step('Goes to the start', async () => {
|
|
486
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Go to the start' }));
|
|
487
|
+
await waitFor(() => expect(viewport.scrollTop).toBe(0), { timeout: 3000 });
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
await step('Brings the second question to the top', async () => {
|
|
491
|
+
const question = canvas.getByText('Can I move the board preparation to Thursday?');
|
|
492
|
+
|
|
493
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Go to the second question' }));
|
|
494
|
+
await waitFor(() => expect(offsetFromTop(question, viewport)).toBeLessThan(48), {
|
|
495
|
+
timeout: 3000,
|
|
496
|
+
});
|
|
497
|
+
await expect(offsetFromTop(question, viewport)).toBeGreaterThanOrEqual(0);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
await step('Goes to the latest message', async () => {
|
|
501
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Go to the latest' }));
|
|
502
|
+
await waitFor(() => expect(distanceFromEnd(viewport)).toBeLessThanOrEqual(8), {
|
|
503
|
+
timeout: 3000,
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
/** The built-in error state: `hasError` covers the thread with the `error` text, announced as an alert. */
|
|
510
|
+
export const ErrorState: Story = {
|
|
511
|
+
parameters: { controls: { disable: true } },
|
|
512
|
+
render: () => (
|
|
513
|
+
<ThreadFrame>
|
|
514
|
+
<ChatThreadProvider conversationId={WEEK_AHEAD.id} groupIds={[]}>
|
|
515
|
+
<ChatThread hasError error="Could not load the conversation" scrollButton={false} />
|
|
516
|
+
</ChatThreadProvider>
|
|
517
|
+
</ThreadFrame>
|
|
518
|
+
),
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
interface RecoverableThreadProps {
|
|
522
|
+
onRetry: () => void;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function RecoverableThread({ onRetry }: RecoverableThreadProps) {
|
|
526
|
+
const [hasError, setHasError] = useState(true);
|
|
527
|
+
const turns = hasError ? [] : WEEK_AHEAD.turns;
|
|
528
|
+
|
|
529
|
+
return (
|
|
530
|
+
<ThreadFrame>
|
|
531
|
+
<ChatThreadProvider conversationId={WEEK_AHEAD.id} groupIds={turns.map((turn) => turn.id)}>
|
|
532
|
+
<ChatThread
|
|
533
|
+
contentClassName="p-12"
|
|
534
|
+
scrollButtonTooltip="Scroll to the latest"
|
|
535
|
+
hasError={hasError}
|
|
536
|
+
renderError={() => (
|
|
537
|
+
<div className="w-full p-12">
|
|
538
|
+
<Banner variant="error">
|
|
539
|
+
<BannerTitle>Could not load the conversation</BannerTitle>
|
|
540
|
+
<BannerDescription>Check your connection, then try again.</BannerDescription>
|
|
541
|
+
<BannerAction>
|
|
542
|
+
<BannerConfirm
|
|
543
|
+
onClick={() => {
|
|
544
|
+
onRetry();
|
|
545
|
+
setHasError(false);
|
|
546
|
+
}}
|
|
547
|
+
>
|
|
548
|
+
Try again
|
|
549
|
+
</BannerConfirm>
|
|
550
|
+
</BannerAction>
|
|
551
|
+
</Banner>
|
|
552
|
+
</div>
|
|
553
|
+
)}
|
|
554
|
+
>
|
|
555
|
+
<ThreadTurns turns={turns} />
|
|
556
|
+
</ChatThread>
|
|
557
|
+
</ChatThreadProvider>
|
|
558
|
+
</ThreadFrame>
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* `renderError` replaces the error text with an error banner that says what failed and offers a
|
|
564
|
+
* way forward. "Try again" loads the conversation.
|
|
565
|
+
*/
|
|
566
|
+
export const CustomError: StoryObj<typeof RecoverableThread> = {
|
|
567
|
+
args: { onRetry: fn() },
|
|
568
|
+
parameters: { controls: { disable: true } },
|
|
569
|
+
render: (args) => <RecoverableThread {...args} />,
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
/** Retries from the error banner and checks that the alert goes and the conversation loads. */
|
|
573
|
+
export const CustomErrorRetry: StoryObj<typeof RecoverableThread> = {
|
|
574
|
+
tags: ['e2e', '!autodocs'],
|
|
575
|
+
args: { onRetry: fn() },
|
|
576
|
+
parameters: { controls: { disable: true } },
|
|
577
|
+
render: (args) => <RecoverableThread {...args} />,
|
|
578
|
+
play: async ({ args, canvas, userEvent, step }) => {
|
|
579
|
+
await step('Announces the failure as an alert', async () => {
|
|
580
|
+
const alert = canvas.getByRole('alert', { name: 'Error loading messages' });
|
|
581
|
+
|
|
582
|
+
await expect(alert).toHaveTextContent('Could not load the conversation');
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
await step('Loads the conversation after a retry', async () => {
|
|
586
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Try again' }));
|
|
587
|
+
|
|
588
|
+
await expect(args.onRetry).toHaveBeenCalledOnce();
|
|
589
|
+
await expect(await canvas.findByText('What’s on my calendar tomorrow?')).toBeVisible();
|
|
590
|
+
await expect(canvas.queryByRole('alert', { name: 'Error loading messages' })).toBeNull();
|
|
591
|
+
});
|
|
592
|
+
},
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
/** The thread in each place it's allowed: a canvas shell, a side panel, a chat page and an agent panel. */
|
|
596
|
+
export const Examples: Story = {
|
|
597
|
+
parameters: {
|
|
598
|
+
controls: { disable: true },
|
|
599
|
+
docs: { source: { code: EXAMPLES_SOURCE } },
|
|
600
|
+
},
|
|
601
|
+
render: () => (
|
|
602
|
+
<div className="flex flex-col gap-24">
|
|
603
|
+
<ParentBlock parent="web-chat-ui/CanvasShellContent">
|
|
604
|
+
<div className="mx-auto h-120 w-full max-w-105 rounded-10 border border-divider-border-base">
|
|
605
|
+
<CanvasShell aria-label={LISBON_TRIP.title}>
|
|
606
|
+
<CanvasShellHeader>
|
|
607
|
+
<CanvasShellTitle>{LISBON_TRIP.title}</CanvasShellTitle>
|
|
608
|
+
<CanvasShellCloseTrigger />
|
|
609
|
+
</CanvasShellHeader>
|
|
610
|
+
<CanvasShellContent hasPadding={false} hasScroll={false}>
|
|
611
|
+
<ChatThreadProvider
|
|
612
|
+
conversationId={LISBON_TRIP.id}
|
|
613
|
+
groupIds={LISBON_TRIP.turns.map((turn) => turn.id)}
|
|
614
|
+
>
|
|
615
|
+
<ChatThread
|
|
616
|
+
className="h-full"
|
|
617
|
+
contentClassName={canvasShellContentPadding}
|
|
618
|
+
scrollButtonTooltip="Scroll to the latest"
|
|
619
|
+
>
|
|
620
|
+
<ThreadTurns turns={LISBON_TRIP.turns} />
|
|
621
|
+
</ChatThread>
|
|
622
|
+
</ChatThreadProvider>
|
|
623
|
+
</CanvasShellContent>
|
|
624
|
+
<CanvasShellFooter className="flex-col items-stretch">
|
|
625
|
+
<ChatPromptBox>
|
|
626
|
+
<ChatPromptBoxContent>
|
|
627
|
+
<ChatPromptBoxInput placeholder="How can I help?" />
|
|
628
|
+
<ChatPromptBoxActionsRight>
|
|
629
|
+
<IconButton
|
|
630
|
+
size="md"
|
|
631
|
+
variant="primary"
|
|
632
|
+
color="primary"
|
|
633
|
+
aria-label="Send message"
|
|
634
|
+
>
|
|
635
|
+
<EnterIcon />
|
|
636
|
+
</IconButton>
|
|
637
|
+
</ChatPromptBoxActionsRight>
|
|
638
|
+
</ChatPromptBoxContent>
|
|
639
|
+
</ChatPromptBox>
|
|
640
|
+
</CanvasShellFooter>
|
|
641
|
+
</CanvasShell>
|
|
642
|
+
</div>
|
|
643
|
+
</ParentBlock>
|
|
644
|
+
|
|
645
|
+
<ParentBlock parent="side panel">
|
|
646
|
+
<aside aria-label="Assistant">
|
|
647
|
+
<ThreadFrame>
|
|
648
|
+
<ChatThreadProvider
|
|
649
|
+
conversationId={WEEK_AHEAD.id}
|
|
650
|
+
groupIds={WEEK_AHEAD.turns.slice(0, 3).map((turn) => turn.id)}
|
|
651
|
+
>
|
|
652
|
+
<ChatThread contentClassName="p-12" scrollButtonTooltip="Scroll to the latest">
|
|
653
|
+
<ThreadTurns turns={WEEK_AHEAD.turns.slice(0, 3)} />
|
|
654
|
+
</ChatThread>
|
|
655
|
+
</ChatThreadProvider>
|
|
656
|
+
</ThreadFrame>
|
|
657
|
+
</aside>
|
|
658
|
+
</ParentBlock>
|
|
659
|
+
|
|
660
|
+
<ParentBlock parent="chat page">
|
|
661
|
+
<section aria-label="Chat page">
|
|
662
|
+
<ThreadFrame className="max-w-none">
|
|
663
|
+
<ChatThreadProvider
|
|
664
|
+
conversationId={WEEK_AHEAD.id}
|
|
665
|
+
groupIds={WEEK_AHEAD.turns.map((turn) => turn.id)}
|
|
666
|
+
>
|
|
667
|
+
<ChatThread contentClassName="p-16" scrollButtonTooltip="Scroll to the latest">
|
|
668
|
+
<ThreadTurns turns={WEEK_AHEAD.turns} groupClassName="max-w-180" />
|
|
669
|
+
</ChatThread>
|
|
670
|
+
</ChatThreadProvider>
|
|
671
|
+
</ThreadFrame>
|
|
672
|
+
</section>
|
|
673
|
+
</ParentBlock>
|
|
674
|
+
|
|
675
|
+
<ParentBlock parent="agent panel">
|
|
676
|
+
<aside aria-label="Agent panel">
|
|
677
|
+
<ThreadFrame>
|
|
678
|
+
<ChatThreadProvider
|
|
679
|
+
conversationId={REPORT_RUN.id}
|
|
680
|
+
groupIds={REPORT_RUN.turns.map((turn) => turn.id)}
|
|
681
|
+
scrollMode="follow"
|
|
682
|
+
>
|
|
683
|
+
<ChatThread contentClassName="p-12" scrollButtonTooltip="Jump to latest">
|
|
684
|
+
<ThreadTurns turns={REPORT_RUN.turns} />
|
|
685
|
+
</ChatThread>
|
|
686
|
+
</ChatThreadProvider>
|
|
687
|
+
</ThreadFrame>
|
|
688
|
+
</aside>
|
|
689
|
+
</ParentBlock>
|
|
690
|
+
</div>
|
|
691
|
+
),
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
/** Answer blocks the playground's "Stream a chunk" button adds, one per click. */
|
|
695
|
+
const STREAM_CHUNKS = NEXT_QUESTIONS.flatMap((turn) => turn.answer);
|
|
696
|
+
|
|
697
|
+
interface ChatThreadPlaygroundProps {
|
|
698
|
+
turnCount: number;
|
|
699
|
+
scrollMode: ChatThreadScrollMode;
|
|
700
|
+
isStreaming: boolean;
|
|
701
|
+
autoScroll?: boolean;
|
|
702
|
+
defaultScrollPosition: NonNullable<ChatThreadProviderProps['defaultScrollPosition']>;
|
|
703
|
+
scrollMargin: number;
|
|
704
|
+
scrollPreviousItemPeek: number;
|
|
705
|
+
scrollEdgeThreshold: number;
|
|
706
|
+
scrollButton: boolean;
|
|
707
|
+
scrollButtonTooltip: string;
|
|
708
|
+
isLoading: boolean;
|
|
709
|
+
hasError: boolean;
|
|
710
|
+
error: string;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function ChatThreadPlayground({
|
|
714
|
+
turnCount,
|
|
715
|
+
scrollButton,
|
|
716
|
+
scrollButtonTooltip,
|
|
717
|
+
isLoading,
|
|
718
|
+
hasError,
|
|
719
|
+
error,
|
|
46
720
|
...providerProps
|
|
47
|
-
}:
|
|
48
|
-
const [
|
|
49
|
-
const
|
|
721
|
+
}: ChatThreadPlaygroundProps) {
|
|
722
|
+
const [isTripOpen, setIsTripOpen] = useState(false);
|
|
723
|
+
const conversation = isTripOpen ? LISBON_TRIP : WEEK_AHEAD;
|
|
724
|
+
const [turns, setTurns] = useState(() => conversation.turns.slice(0, turnCount));
|
|
725
|
+
const [sentCount, setSentCount] = useState(0);
|
|
726
|
+
const [chunkCount, setChunkCount] = useState(0);
|
|
727
|
+
|
|
728
|
+
const sendQuestion = () => {
|
|
729
|
+
const source = NEXT_QUESTIONS[sentCount % NEXT_QUESTIONS.length];
|
|
730
|
+
|
|
731
|
+
if (!source) return;
|
|
732
|
+
|
|
733
|
+
setSentCount(sentCount + 1);
|
|
734
|
+
setTurns((current) => [
|
|
735
|
+
...current,
|
|
736
|
+
{ id: `${source.id}-${sentCount}`, question: source.question, answer: [] },
|
|
737
|
+
]);
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
const streamChunk = () => {
|
|
741
|
+
const chunk = STREAM_CHUNKS[chunkCount % STREAM_CHUNKS.length];
|
|
742
|
+
|
|
743
|
+
if (!chunk) return;
|
|
744
|
+
|
|
745
|
+
setChunkCount(chunkCount + 1);
|
|
746
|
+
setTurns((current) =>
|
|
747
|
+
current.map((turn, index) =>
|
|
748
|
+
index === current.length - 1 ? { ...turn, answer: [...turn.answer, chunk] } : turn,
|
|
749
|
+
),
|
|
750
|
+
);
|
|
751
|
+
};
|
|
50
752
|
|
|
51
753
|
const switchConversation = () => {
|
|
52
|
-
const next =
|
|
754
|
+
const next = isTripOpen ? WEEK_AHEAD : LISBON_TRIP;
|
|
53
755
|
|
|
54
|
-
|
|
55
|
-
setTurns(
|
|
756
|
+
setIsTripOpen(!isTripOpen);
|
|
757
|
+
setTurns(next.turns.slice(0, turnCount));
|
|
56
758
|
};
|
|
57
759
|
|
|
58
760
|
return (
|
|
59
|
-
<div className="flex flex-col gap-12">
|
|
60
|
-
<
|
|
761
|
+
<div className="mx-auto flex max-w-105 flex-col gap-12">
|
|
762
|
+
<ThreadFrame>
|
|
61
763
|
<ChatThreadProvider
|
|
62
|
-
conversationId={
|
|
764
|
+
conversationId={conversation.id}
|
|
63
765
|
groupIds={turns.map((turn) => turn.id)}
|
|
64
766
|
{...providerProps}
|
|
65
767
|
>
|
|
66
768
|
<ChatThread
|
|
67
769
|
contentClassName="p-12"
|
|
68
770
|
scrollButton={scrollButton}
|
|
69
|
-
scrollButtonTooltip=
|
|
771
|
+
scrollButtonTooltip={scrollButtonTooltip}
|
|
772
|
+
isLoading={isLoading}
|
|
70
773
|
hasError={hasError}
|
|
71
|
-
error=
|
|
774
|
+
error={error}
|
|
72
775
|
>
|
|
73
|
-
{turns
|
|
74
|
-
<ChatThreadGroup key={turn.id} groupId={turn.id}>
|
|
75
|
-
<ChatThreadQuestion
|
|
76
|
-
messageId={`${turn.id}-question`}
|
|
77
|
-
className="ml-auto w-fit max-w-[80%] rounded-lg bg-paper-elevation-2 px-12 py-8"
|
|
78
|
-
>
|
|
79
|
-
{turn.question}
|
|
80
|
-
</ChatThreadQuestion>
|
|
81
|
-
<ChatThreadAnswer messageId={`${turn.id}-answer`}>
|
|
82
|
-
<p className="whitespace-pre-line text-sm">{turn.answer}</p>
|
|
83
|
-
</ChatThreadAnswer>
|
|
84
|
-
</ChatThreadGroup>
|
|
85
|
-
))}
|
|
776
|
+
<ThreadTurns turns={turns} />
|
|
86
777
|
</ChatThread>
|
|
87
778
|
</ChatThreadProvider>
|
|
88
|
-
</
|
|
89
|
-
<div className="flex gap-8">
|
|
90
|
-
<
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
])
|
|
98
|
-
}
|
|
99
|
-
>
|
|
100
|
-
Send
|
|
101
|
-
</button>
|
|
102
|
-
<button
|
|
103
|
-
type="button"
|
|
104
|
-
className="flex-1 rounded-md border px-12 py-1.5 text-sm"
|
|
105
|
-
onClick={() =>
|
|
106
|
-
setTurns((current) =>
|
|
107
|
-
current.map((turn, index) =>
|
|
108
|
-
index === current.length - 1
|
|
109
|
-
? { ...turn, answer: `${turn.answer} ${LOREM}` }
|
|
110
|
-
: turn,
|
|
111
|
-
),
|
|
112
|
-
)
|
|
113
|
-
}
|
|
114
|
-
>
|
|
115
|
-
Stream chunk
|
|
116
|
-
</button>
|
|
117
|
-
<button
|
|
118
|
-
type="button"
|
|
119
|
-
className="flex-1 rounded-md border px-12 py-1.5 text-sm"
|
|
120
|
-
onClick={switchConversation}
|
|
121
|
-
>
|
|
779
|
+
</ThreadFrame>
|
|
780
|
+
<div className="flex flex-wrap gap-8">
|
|
781
|
+
<Button size="sm" onClick={sendQuestion}>
|
|
782
|
+
Send a question
|
|
783
|
+
</Button>
|
|
784
|
+
<Button size="sm" onClick={streamChunk}>
|
|
785
|
+
Stream a chunk
|
|
786
|
+
</Button>
|
|
787
|
+
<Button size="sm" variant="tertiary" onClick={switchConversation}>
|
|
122
788
|
Switch conversation
|
|
123
|
-
</
|
|
789
|
+
</Button>
|
|
124
790
|
</div>
|
|
125
791
|
</div>
|
|
126
792
|
);
|
|
127
793
|
}
|
|
128
794
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
795
|
+
/**
|
|
796
|
+
* Every scroll setting on the controls panel. Send a question, then add to its answer one chunk at
|
|
797
|
+
* a time with `isStreaming` on or off, to see what each setting does to the scroll position.
|
|
798
|
+
*/
|
|
799
|
+
export const Playground: StoryObj<typeof ChatThreadPlayground> = {
|
|
800
|
+
tags: ['!autodocs'],
|
|
801
|
+
// The wrapper drives these `ChatThread` props itself, so their controls would do nothing here
|
|
802
|
+
parameters: {
|
|
803
|
+
controls: {
|
|
804
|
+
exclude: [
|
|
805
|
+
'children',
|
|
806
|
+
'className',
|
|
807
|
+
'viewportClassName',
|
|
808
|
+
'contentClassName',
|
|
809
|
+
'scrollButtonClassName',
|
|
810
|
+
'renderError',
|
|
811
|
+
'viewportRef',
|
|
812
|
+
'contentRef',
|
|
813
|
+
],
|
|
814
|
+
},
|
|
815
|
+
},
|
|
142
816
|
args: {
|
|
143
|
-
|
|
817
|
+
turnCount: 3,
|
|
818
|
+
scrollMode: 'anchor',
|
|
144
819
|
isStreaming: false,
|
|
145
|
-
|
|
146
|
-
hasError: false,
|
|
820
|
+
defaultScrollPosition: 'end',
|
|
147
821
|
scrollMargin: 12,
|
|
148
822
|
scrollPreviousItemPeek: 0,
|
|
149
823
|
scrollEdgeThreshold: 8,
|
|
150
|
-
|
|
824
|
+
scrollButton: true,
|
|
825
|
+
scrollButtonTooltip: 'Scroll to the latest',
|
|
826
|
+
isLoading: false,
|
|
827
|
+
hasError: false,
|
|
828
|
+
error: 'Could not load the conversation',
|
|
151
829
|
},
|
|
152
830
|
argTypes: {
|
|
153
|
-
|
|
154
|
-
control: { type: 'number', min: 0, max:
|
|
155
|
-
description: '
|
|
156
|
-
|
|
831
|
+
turnCount: {
|
|
832
|
+
control: { type: 'number', min: 0, max: 5 },
|
|
833
|
+
description: 'Turns the conversation opens with. Changing it reloads the thread.',
|
|
834
|
+
},
|
|
835
|
+
scrollMode: {
|
|
836
|
+
control: 'inline-radio',
|
|
837
|
+
options: ['anchor', 'follow'],
|
|
838
|
+
description:
|
|
839
|
+
'`scrollMode` on `ChatThreadProvider`: `anchor` settles a new question at the top, `follow` keeps the newest output in view.',
|
|
840
|
+
table: { defaultValue: { summary: 'anchor' } },
|
|
157
841
|
},
|
|
158
842
|
isStreaming: {
|
|
159
843
|
control: 'boolean',
|
|
160
|
-
description:
|
|
844
|
+
description:
|
|
845
|
+
'`isStreaming` on `ChatThreadProvider`: marks the content busy and, in `anchor` mode, scrolls smoothly and pauses `autoScroll`.',
|
|
161
846
|
table: { defaultValue: { summary: 'false' } },
|
|
162
847
|
},
|
|
163
|
-
|
|
848
|
+
autoScroll: {
|
|
164
849
|
control: 'boolean',
|
|
165
|
-
description:
|
|
166
|
-
|
|
850
|
+
description:
|
|
851
|
+
'`autoScroll` on `ChatThreadProvider`: follow content that grows at the end until the reader scrolls away. Unset, it follows in `follow` mode and, in `anchor` mode, only while not streaming.',
|
|
167
852
|
},
|
|
168
|
-
|
|
169
|
-
control: '
|
|
170
|
-
|
|
171
|
-
|
|
853
|
+
defaultScrollPosition: {
|
|
854
|
+
control: 'select',
|
|
855
|
+
options: ['start', 'end', 'last-anchor'],
|
|
856
|
+
description:
|
|
857
|
+
'`defaultScrollPosition` on `ChatThreadProvider`: where a conversation opens. Switch conversation to apply it.',
|
|
858
|
+
table: { defaultValue: { summary: 'end' } },
|
|
172
859
|
},
|
|
173
860
|
scrollMargin: {
|
|
174
861
|
control: { type: 'range', min: 0, max: 64, step: 2 },
|
|
175
|
-
description:
|
|
862
|
+
description:
|
|
863
|
+
'`scrollMargin` on `ChatThreadProvider`: the gap in px kept above an anchored group.',
|
|
176
864
|
table: { defaultValue: { summary: '12' } },
|
|
177
865
|
},
|
|
178
866
|
scrollPreviousItemPeek: {
|
|
179
867
|
control: { type: 'range', min: 0, max: 200, step: 4 },
|
|
180
|
-
description:
|
|
868
|
+
description:
|
|
869
|
+
'`scrollPreviousItemPeek` on `ChatThreadProvider`: px of the previous group kept visible above an anchored one.',
|
|
181
870
|
table: { defaultValue: { summary: '0' } },
|
|
182
871
|
},
|
|
183
872
|
scrollEdgeThreshold: {
|
|
184
873
|
control: { type: 'number', min: 0, max: 64 },
|
|
185
874
|
description:
|
|
186
|
-
'
|
|
875
|
+
'`scrollEdgeThreshold` on `ChatThreadProvider`: distance in px from the end within which the reader still counts as at the end, so following continues and the scroll button stays hidden.',
|
|
187
876
|
table: { defaultValue: { summary: '8' } },
|
|
188
877
|
},
|
|
189
|
-
autoScroll: {
|
|
190
|
-
control: 'boolean',
|
|
191
|
-
description:
|
|
192
|
-
'Follow growing content at the live edge until the reader scrolls away. Defaults to following only while not streaming',
|
|
193
|
-
table: { defaultValue: { summary: '!isStreaming' } },
|
|
194
|
-
},
|
|
195
|
-
defaultScrollPosition: {
|
|
196
|
-
control: 'select',
|
|
197
|
-
options: ['start', 'end', 'last-anchor'],
|
|
198
|
-
description: 'Where a conversation opens',
|
|
199
|
-
table: { defaultValue: { summary: 'end' } },
|
|
200
|
-
},
|
|
201
|
-
children: {
|
|
202
|
-
description:
|
|
203
|
-
'Content of the scroller provider. The story renders its own `ChatThread` with the turns, so this is not editable.',
|
|
204
|
-
table: { disable: true },
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
export default meta;
|
|
210
|
-
type Story = StoryObj<typeof Transcript>;
|
|
211
|
-
|
|
212
|
-
export const Default: Story = {};
|
|
213
|
-
|
|
214
|
-
export const Playground: Story = {
|
|
215
|
-
args: {
|
|
216
|
-
initialTurns: 6,
|
|
217
878
|
},
|
|
879
|
+
render: (args) => <ChatThreadPlayground key={args.turnCount} {...args} />,
|
|
218
880
|
};
|