@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.
Files changed (369) hide show
  1. package/README.md +9 -12
  2. package/dist/components/canvas-shell/canvas-shell.d.ts +32 -10
  3. package/dist/components/canvas-shell/canvas-shell.d.ts.map +1 -1
  4. package/dist/components/canvas-shell/canvas-shell.stories.d.ts +49 -17
  5. package/dist/components/canvas-shell/canvas-shell.stories.d.ts.map +1 -1
  6. package/dist/components/chat-card/chat-card.d.ts +1 -0
  7. package/dist/components/chat-card/chat-card.d.ts.map +1 -1
  8. package/dist/components/chat-card/chat-card.stories.d.ts +47 -1
  9. package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -1
  10. package/dist/components/chat-card/components/chat-card-body.d.ts +8 -0
  11. package/dist/components/chat-card/components/chat-card-body.d.ts.map +1 -1
  12. package/dist/components/chat-card/components/chat-card-footer.d.ts +8 -0
  13. package/dist/components/chat-card/components/chat-card-footer.d.ts.map +1 -1
  14. package/dist/components/chat-card/components/chat-card-form.d.ts +15 -2
  15. package/dist/components/chat-card/components/chat-card-form.d.ts.map +1 -1
  16. package/dist/components/chat-card/components/chat-card-header.d.ts +23 -2
  17. package/dist/components/chat-card/components/chat-card-header.d.ts.map +1 -1
  18. package/dist/components/chat-card/contexts.d.ts +2 -0
  19. package/dist/components/chat-card/contexts.d.ts.map +1 -1
  20. package/dist/components/chat-card/hooks.d.ts +1 -0
  21. package/dist/components/chat-card/hooks.d.ts.map +1 -1
  22. package/dist/components/chat-card/types.d.ts +3 -0
  23. package/dist/components/chat-card/types.d.ts.map +1 -1
  24. package/dist/components/chat-card-container/chat-card-container.d.ts +4 -0
  25. package/dist/components/chat-card-container/chat-card-container.d.ts.map +1 -1
  26. package/dist/components/chat-card-container/chat-card-container.stories.d.ts +12 -1
  27. package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
  28. package/dist/components/chat-container/chat-container.d.ts.map +1 -1
  29. package/dist/components/chat-container/chat-container.stories.d.ts +36 -11
  30. package/dist/components/chat-container/chat-container.stories.d.ts.map +1 -1
  31. package/dist/components/chat-input/chat-input.d.ts +30 -2
  32. package/dist/components/chat-input/chat-input.d.ts.map +1 -1
  33. package/dist/components/chat-input/chat-input.stories.d.ts +63 -3
  34. package/dist/components/chat-input/chat-input.stories.d.ts.map +1 -1
  35. package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts +4 -1
  36. package/dist/components/chat-input/plugins/controlled-value-plugin.d.ts.map +1 -1
  37. package/dist/components/chat-input/plugins/value-plugin.d.ts +4 -1
  38. package/dist/components/chat-input/plugins/value-plugin.d.ts.map +1 -1
  39. package/dist/components/chat-list/chat-list-item.d.ts +6 -0
  40. package/dist/components/chat-list/chat-list-item.d.ts.map +1 -1
  41. package/dist/components/chat-list/chat-list-items.d.ts +12 -1
  42. package/dist/components/chat-list/chat-list-items.d.ts.map +1 -1
  43. package/dist/components/chat-list/chat-list.d.ts +36 -2
  44. package/dist/components/chat-list/chat-list.d.ts.map +1 -1
  45. package/dist/components/chat-list/chat-list.stories.d.ts +67 -9
  46. package/dist/components/chat-list/chat-list.stories.d.ts.map +1 -1
  47. package/dist/components/chat-message/chat-message.d.ts +12 -1
  48. package/dist/components/chat-message/chat-message.d.ts.map +1 -1
  49. package/dist/components/chat-message/chat-message.stories.d.ts +31 -0
  50. package/dist/components/chat-message/chat-message.stories.d.ts.map +1 -1
  51. package/dist/components/chat-message/index.d.ts +1 -1
  52. package/dist/components/chat-message/index.d.ts.map +1 -1
  53. package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts +3 -0
  54. package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts.map +1 -1
  55. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts +25 -5
  56. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts.map +1 -1
  57. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +32 -1
  58. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -1
  59. package/dist/components/chat-message-attachment-card/index.d.ts +2 -2
  60. package/dist/components/chat-message-attachment-card/index.d.ts.map +1 -1
  61. package/dist/components/chat-message-attachment-card/utils.d.ts +1 -0
  62. package/dist/components/chat-message-attachment-card/utils.d.ts.map +1 -1
  63. package/dist/components/chat-message-response/chat-message-response.stories.d.ts +13 -0
  64. package/dist/components/chat-message-response/chat-message-response.stories.d.ts.map +1 -1
  65. package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts +22 -5
  66. package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts.map +1 -1
  67. package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts +42 -0
  68. package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts.map +1 -1
  69. package/dist/components/chat-message-toolbar/index.d.ts +1 -1
  70. package/dist/components/chat-message-toolbar/index.d.ts.map +1 -1
  71. package/dist/components/chat-messages/chat-messages.d.ts +34 -2
  72. package/dist/components/chat-messages/chat-messages.d.ts.map +1 -1
  73. package/dist/components/chat-messages/chat-messages.stories.d.ts +33 -2
  74. package/dist/components/chat-messages/chat-messages.stories.d.ts.map +1 -1
  75. package/dist/components/chat-notification-card/chat-notification-card.d.ts +56 -4
  76. package/dist/components/chat-notification-card/chat-notification-card.d.ts.map +1 -1
  77. package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts +50 -1
  78. package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts.map +1 -1
  79. package/dist/components/chat-notification-popup/chat-notification-popup.d.ts +6 -0
  80. package/dist/components/chat-notification-popup/chat-notification-popup.d.ts.map +1 -1
  81. package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts +43 -1
  82. package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts.map +1 -1
  83. package/dist/components/chat-prompt-box/chat-prompt-box.d.ts +37 -17
  84. package/dist/components/chat-prompt-box/chat-prompt-box.d.ts.map +1 -1
  85. package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts +53 -1
  86. package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts.map +1 -1
  87. package/dist/components/chat-reply/chat-reply.d.ts +11 -0
  88. package/dist/components/chat-reply/chat-reply.d.ts.map +1 -1
  89. package/dist/components/chat-reply/chat-reply.stories.d.ts +23 -0
  90. package/dist/components/chat-reply/chat-reply.stories.d.ts.map +1 -1
  91. package/dist/components/chat-reply/index.d.ts +1 -1
  92. package/dist/components/chat-reply/index.d.ts.map +1 -1
  93. package/dist/components/chat-suggestion/chat-suggestion.d.ts +36 -10
  94. package/dist/components/chat-suggestion/chat-suggestion.d.ts.map +1 -1
  95. package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts +66 -2
  96. package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts.map +1 -1
  97. package/dist/components/chat-suggestion/index.d.ts +2 -1
  98. package/dist/components/chat-suggestion/index.d.ts.map +1 -1
  99. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +26 -1
  100. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
  101. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +25 -1
  102. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -1
  103. package/dist/components/chat-thread/chat-thread.d.ts +17 -2
  104. package/dist/components/chat-thread/chat-thread.d.ts.map +1 -1
  105. package/dist/components/chat-thread/chat-thread.stories.d.ts +75 -10
  106. package/dist/components/chat-thread/chat-thread.stories.d.ts.map +1 -1
  107. package/dist/components/index.d.ts +1 -3
  108. package/dist/components/index.d.ts.map +1 -1
  109. package/dist/components/markdown-viewer/markdown-viewer.d.ts +8 -1
  110. package/dist/components/markdown-viewer/markdown-viewer.d.ts.map +1 -1
  111. package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts +18 -1
  112. package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts.map +1 -1
  113. package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts +4 -1
  114. package/dist/components/rich-text-area/plugins/controlled-value-plugin.d.ts.map +1 -1
  115. package/dist/components/rich-text-area/plugins/value-plugin.d.ts +4 -1
  116. package/dist/components/rich-text-area/plugins/value-plugin.d.ts.map +1 -1
  117. package/dist/components/rich-text-area/rich-text-area.d.ts +17 -0
  118. package/dist/components/rich-text-area/rich-text-area.d.ts.map +1 -1
  119. package/dist/components/rich-text-area/rich-text-area.stories.d.ts +52 -0
  120. package/dist/components/rich-text-area/rich-text-area.stories.d.ts.map +1 -1
  121. package/dist/components/rich-text-area/styled.d.ts +6 -2
  122. package/dist/components/rich-text-area/styled.d.ts.map +1 -1
  123. package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts +9 -2
  124. package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts.map +1 -1
  125. package/dist/components/rich-text-field/components/index.d.ts +5 -5
  126. package/dist/components/rich-text-field/components/index.d.ts.map +1 -1
  127. package/dist/components/rich-text-field/components/text-color-button.d.ts +12 -1
  128. package/dist/components/rich-text-field/components/text-color-button.d.ts.map +1 -1
  129. package/dist/components/rich-text-field/rich-text-field.d.ts +22 -0
  130. package/dist/components/rich-text-field/rich-text-field.d.ts.map +1 -1
  131. package/dist/components/rich-text-field/rich-text-field.stories.d.ts +28 -1
  132. package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
  133. package/dist/components/topmenu/index.d.ts +2 -0
  134. package/dist/components/topmenu/index.d.ts.map +1 -0
  135. package/dist/components/topmenu/topmenu.d.ts +22 -0
  136. package/dist/components/topmenu/topmenu.d.ts.map +1 -0
  137. package/dist/components/topmenu/topmenu.stories.d.ts +31 -0
  138. package/dist/components/topmenu/topmenu.stories.d.ts.map +1 -0
  139. package/dist/docs/agent.stories.d.ts.map +1 -1
  140. package/dist/docs/chat-panel.d.ts +7 -5
  141. package/dist/docs/chat-panel.d.ts.map +1 -1
  142. package/dist/docs/chatbot-panel.d.ts.map +1 -1
  143. package/dist/docs/chatbot.stories.d.ts.map +1 -1
  144. package/dist/index.css +1 -1
  145. package/dist/index.es.js +1801 -1806
  146. package/dist/index.es.js.map +1 -1
  147. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +9 -7
  148. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +1 -1
  149. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +37 -9
  150. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +1 -1
  151. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +41 -16
  152. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -1
  153. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +6 -0
  154. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +1 -1
  155. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +22 -1
  156. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +1 -1
  157. package/package.json +16 -10
  158. package/src/__storybook__/parent-block.tsx +21 -0
  159. package/src/components/canvas-shell/__stories__/canvas-panel.tsx +25 -0
  160. package/src/components/canvas-shell/__stories__/document-list.tsx +29 -0
  161. package/src/components/canvas-shell/__stories__/fixtures.ts +222 -0
  162. package/src/components/canvas-shell/__stories__/holdings-table.tsx +56 -0
  163. package/src/components/canvas-shell/__stories__/types.ts +47 -0
  164. package/src/components/canvas-shell/{canvas-shell.test.tsx → __tests__/canvas-shell.spec.tsx} +1 -1
  165. package/src/components/canvas-shell/canvas-shell.json +24 -0
  166. package/src/components/canvas-shell/canvas-shell.stories.tsx +581 -122
  167. package/src/components/canvas-shell/canvas-shell.tsx +44 -17
  168. package/src/components/chat-card/__stories__/fixtures.ts +119 -0
  169. package/src/components/chat-card/__stories__/types.ts +44 -0
  170. package/src/components/chat-card/chat-card.json +67 -3
  171. package/src/components/chat-card/chat-card.stories.tsx +872 -148
  172. package/src/components/chat-card/chat-card.tsx +2 -0
  173. package/src/components/chat-card/components/chat-card-body.tsx +12 -0
  174. package/src/components/chat-card/components/chat-card-footer.tsx +11 -0
  175. package/src/components/chat-card/components/chat-card-form.tsx +21 -2
  176. package/src/components/chat-card/components/chat-card-header.tsx +39 -2
  177. package/src/components/chat-card/contexts.tsx +2 -0
  178. package/src/components/chat-card/hooks.ts +1 -0
  179. package/src/components/chat-card/types.ts +3 -0
  180. package/src/components/chat-card-container/__stories__/fixtures.ts +54 -0
  181. package/src/components/chat-card-container/__stories__/resizable-chat-window.tsx +19 -0
  182. package/src/components/chat-card-container/__stories__/result-card.tsx +31 -0
  183. package/src/components/chat-card-container/__stories__/types.ts +16 -0
  184. package/src/components/chat-card-container/chat-card-container.json +7 -0
  185. package/src/components/chat-card-container/chat-card-container.stories.tsx +209 -56
  186. package/src/components/chat-card-container/chat-card-container.tsx +5 -0
  187. package/src/components/chat-container/__stories__/chat-composer.tsx +67 -0
  188. package/src/components/chat-container/__stories__/fixtures.ts +27 -0
  189. package/src/components/chat-container/__stories__/measure.ts +22 -0
  190. package/src/components/chat-container/__stories__/types.ts +7 -0
  191. package/src/components/chat-container/__stories__/variable-readout.tsx +64 -0
  192. package/src/components/chat-container/chat-container.json +9 -1
  193. package/src/components/chat-container/chat-container.stories.tsx +538 -106
  194. package/src/components/chat-container/chat-container.tsx +3 -0
  195. package/src/components/chat-input/__stories__/fixtures.ts +31 -0
  196. package/src/components/chat-input/__tests__/chat-input.spec.tsx +100 -0
  197. package/src/components/chat-input/chat-input.json +11 -2
  198. package/src/components/chat-input/chat-input.stories.tsx +660 -197
  199. package/src/components/chat-input/chat-input.tsx +39 -5
  200. package/src/components/chat-input/plugins/controlled-value-plugin.tsx +16 -3
  201. package/src/components/chat-input/plugins/value-plugin.tsx +19 -4
  202. package/src/components/chat-list/__stories__/chat-row.tsx +41 -0
  203. package/src/components/chat-list/__stories__/fixtures.ts +94 -0
  204. package/src/components/chat-list/__stories__/types.ts +13 -0
  205. package/src/components/chat-list/chat-list-item.tsx +6 -0
  206. package/src/components/chat-list/chat-list-items.tsx +16 -0
  207. package/src/components/chat-list/chat-list.json +24 -2
  208. package/src/components/chat-list/chat-list.stories.tsx +631 -215
  209. package/src/components/chat-list/chat-list.tsx +51 -4
  210. package/src/components/chat-message/__stories__/fixtures.ts +53 -0
  211. package/src/components/chat-message/__stories__/sent-attachment.tsx +22 -0
  212. package/src/components/chat-message/__stories__/tool-steps.tsx +37 -0
  213. package/src/components/chat-message/chat-message.json +10 -1
  214. package/src/components/chat-message/chat-message.stories.tsx +282 -20
  215. package/src/components/chat-message/chat-message.tsx +16 -1
  216. package/src/components/chat-message/index.ts +8 -1
  217. package/src/components/chat-message-attachment-card/__stories__/fixtures.ts +30 -0
  218. package/src/components/chat-message-attachment-card/__stories__/types.ts +14 -0
  219. package/src/components/chat-message-attachment-card/chat-message-attachment-card-icon.tsx +4 -0
  220. package/src/components/chat-message-attachment-card/chat-message-attachment-card.json +20 -0
  221. package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +266 -51
  222. package/src/components/chat-message-attachment-card/chat-message-attachment-card.tsx +37 -4
  223. package/src/components/chat-message-attachment-card/index.ts +6 -0
  224. package/src/components/chat-message-attachment-card/utils.ts +1 -0
  225. package/src/components/chat-message-response/__stories__/fixtures.ts +50 -0
  226. package/src/components/chat-message-response/chat-message-response.json +5 -0
  227. package/src/components/chat-message-response/chat-message-response.stories.tsx +135 -26
  228. package/src/components/chat-message-toolbar/chat-message-toolbar.json +21 -3
  229. package/src/components/chat-message-toolbar/chat-message-toolbar.stories.tsx +377 -6
  230. package/src/components/chat-message-toolbar/chat-message-toolbar.tsx +47 -12
  231. package/src/components/chat-message-toolbar/index.ts +4 -0
  232. package/src/components/chat-messages/__stories__/conversation-frame.tsx +25 -0
  233. package/src/components/chat-messages/__stories__/conversation-group.tsx +22 -0
  234. package/src/components/chat-messages/__stories__/fixtures.ts +70 -0
  235. package/src/components/chat-messages/__stories__/types.ts +5 -0
  236. package/src/components/chat-messages/chat-messages.json +30 -12
  237. package/src/components/chat-messages/chat-messages.stories.tsx +439 -212
  238. package/src/components/chat-messages/chat-messages.tsx +46 -3
  239. package/src/components/chat-notification-card/__stories__/fixtures.ts +38 -0
  240. package/src/components/chat-notification-card/__stories__/types.ts +13 -0
  241. package/src/components/chat-notification-card/chat-notification-card.json +52 -2
  242. package/src/components/chat-notification-card/chat-notification-card.stories.tsx +542 -62
  243. package/src/components/chat-notification-card/chat-notification-card.tsx +97 -6
  244. package/src/components/chat-notification-popup/__stories__/fixtures.ts +36 -0
  245. package/src/components/chat-notification-popup/__stories__/notification-item.tsx +93 -0
  246. package/src/components/chat-notification-popup/__stories__/types.ts +14 -0
  247. package/src/components/chat-notification-popup/chat-notification-popup.json +14 -1
  248. package/src/components/chat-notification-popup/chat-notification-popup.stories.tsx +467 -17
  249. package/src/components/chat-notification-popup/chat-notification-popup.tsx +18 -3
  250. package/src/components/chat-prompt-box/__stories__/fixtures.ts +16 -0
  251. package/src/components/chat-prompt-box/__stories__/types.ts +8 -0
  252. package/src/components/chat-prompt-box/chat-prompt-box.json +25 -2
  253. package/src/components/chat-prompt-box/chat-prompt-box.stories.tsx +535 -43
  254. package/src/components/chat-prompt-box/chat-prompt-box.tsx +73 -19
  255. package/src/components/chat-reply/chat-reply.json +10 -0
  256. package/src/components/chat-reply/chat-reply.stories.tsx +264 -21
  257. package/src/components/chat-reply/chat-reply.tsx +15 -0
  258. package/src/components/chat-reply/index.ts +10 -1
  259. package/src/components/chat-suggestion/__stories__/fixtures.ts +16 -0
  260. package/src/components/chat-suggestion/__tests__/chat-suggestion.spec.tsx +185 -0
  261. package/src/components/chat-suggestion/chat-suggestion.json +62 -20
  262. package/src/components/chat-suggestion/chat-suggestion.stories.tsx +542 -58
  263. package/src/components/chat-suggestion/chat-suggestion.tsx +154 -65
  264. package/src/components/chat-suggestion/index.ts +9 -0
  265. package/src/components/chat-thinking-process/__stories__/fixtures.ts +56 -0
  266. package/src/components/chat-thinking-process/chat-thinking-process.json +28 -3
  267. package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +354 -78
  268. package/src/components/chat-thinking-process/chat-thinking-process.tsx +55 -4
  269. package/src/components/chat-thread/__stories__/fixtures.ts +171 -0
  270. package/src/components/chat-thread/__stories__/scroll-position.ts +9 -0
  271. package/src/components/chat-thread/__stories__/snippets.ts +129 -0
  272. package/src/components/chat-thread/__stories__/thread-frame.tsx +22 -0
  273. package/src/components/chat-thread/__stories__/thread-turns.tsx +35 -0
  274. package/src/components/chat-thread/__stories__/types.ts +12 -0
  275. package/src/components/chat-thread/__stories__/use-turn-stream.ts +78 -0
  276. package/src/components/chat-thread/chat-thread.json +23 -3
  277. package/src/components/chat-thread/chat-thread.stories.tsx +804 -142
  278. package/src/components/chat-thread/chat-thread.tsx +64 -16
  279. package/src/components/index.ts +1 -3
  280. package/src/components/markdown-viewer/__stories__/fixtures.ts +67 -0
  281. package/src/components/markdown-viewer/markdown-viewer.json +7 -1
  282. package/src/components/markdown-viewer/markdown-viewer.stories.tsx +219 -50
  283. package/src/components/markdown-viewer/markdown-viewer.tsx +9 -0
  284. package/src/components/rich-text-area/__stories__/fixtures.ts +30 -0
  285. package/src/components/rich-text-area/__tests__/rich-text-area.spec.tsx +114 -0
  286. package/src/components/rich-text-area/plugins/controlled-value-plugin.tsx +20 -3
  287. package/src/components/rich-text-area/plugins/value-plugin.tsx +16 -3
  288. package/src/components/rich-text-area/rich-text-area.json +7 -4
  289. package/src/components/rich-text-area/rich-text-area.stories.tsx +597 -41
  290. package/src/components/rich-text-area/rich-text-area.tsx +27 -4
  291. package/src/components/rich-text-area/styled.tsx +11 -5
  292. package/src/components/rich-text-field/__stories__/fixtures.ts +29 -0
  293. package/src/components/rich-text-field/components/formatting-toolbar-plugin.tsx +10 -1
  294. package/src/components/rich-text-field/components/index.ts +8 -5
  295. package/src/components/rich-text-field/components/text-color-button.tsx +16 -2
  296. package/src/components/rich-text-field/rich-text-field.json +3 -1
  297. package/src/components/rich-text-field/rich-text-field.stories.tsx +452 -61
  298. package/src/components/rich-text-field/rich-text-field.tsx +23 -0
  299. package/src/components/topmenu/index.ts +1 -0
  300. package/src/components/topmenu/topmenu.json +107 -0
  301. package/src/components/topmenu/topmenu.stories.tsx +334 -0
  302. package/src/components/topmenu/topmenu.tsx +71 -0
  303. package/src/docs/agent.stories.tsx +16 -16
  304. package/src/docs/chat-panel.tsx +37 -32
  305. package/src/docs/chatbot-panel.tsx +11 -2
  306. package/src/docs/chatbot.mdx +17 -12
  307. package/src/docs/chatbot.stories.tsx +7 -8
  308. package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +112 -0
  309. package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +36 -0
  310. package/src/layouts/chat-card-list-layout/__stories__/types.ts +31 -0
  311. package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +14 -1
  312. package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +316 -84
  313. package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +11 -7
  314. package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +117 -0
  315. package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +18 -0
  316. package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +85 -0
  317. package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +50 -0
  318. package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +44 -0
  319. package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +61 -0
  320. package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +35 -0
  321. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +16 -0
  322. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +603 -182
  323. package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +51 -0
  324. package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +83 -0
  325. package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +24 -0
  326. package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +15 -0
  327. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +13 -1
  328. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +368 -67
  329. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +11 -2
  330. package/dist/components/card-item-picker/card-item-picker-context.d.ts +0 -21
  331. package/dist/components/card-item-picker/card-item-picker-context.d.ts.map +0 -1
  332. package/dist/components/card-item-picker/card-item-picker-list.d.ts +0 -24
  333. package/dist/components/card-item-picker/card-item-picker-list.d.ts.map +0 -1
  334. package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts +0 -28
  335. package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts.map +0 -1
  336. package/dist/components/card-item-picker/card-item-picker-row.d.ts +0 -12
  337. package/dist/components/card-item-picker/card-item-picker-row.d.ts.map +0 -1
  338. package/dist/components/card-item-picker/card-item-picker.stories.d.ts +0 -19
  339. package/dist/components/card-item-picker/card-item-picker.stories.d.ts.map +0 -1
  340. package/dist/components/card-item-picker/index.d.ts +0 -9
  341. package/dist/components/card-item-picker/index.d.ts.map +0 -1
  342. package/dist/components/chat-message-history/chat-message-history.d.ts +0 -48
  343. package/dist/components/chat-message-history/chat-message-history.d.ts.map +0 -1
  344. package/dist/components/chat-message-history/chat-message-history.stories.d.ts +0 -7
  345. package/dist/components/chat-message-history/chat-message-history.stories.d.ts.map +0 -1
  346. package/dist/components/chat-message-history/index.d.ts +0 -2
  347. package/dist/components/chat-message-history/index.d.ts.map +0 -1
  348. package/dist/components/spinner/index.d.ts +0 -2
  349. package/dist/components/spinner/index.d.ts.map +0 -1
  350. package/dist/components/spinner/spinner.d.ts +0 -9
  351. package/dist/components/spinner/spinner.d.ts.map +0 -1
  352. package/dist/components/spinner/spinner.stories.d.ts +0 -8
  353. package/dist/components/spinner/spinner.stories.d.ts.map +0 -1
  354. package/src/components/card-item-picker/__tests__/card-item-picker.spec.tsx +0 -279
  355. package/src/components/card-item-picker/card-item-picker-context.tsx +0 -44
  356. package/src/components/card-item-picker/card-item-picker-list.tsx +0 -95
  357. package/src/components/card-item-picker/card-item-picker-row-parts.tsx +0 -96
  358. package/src/components/card-item-picker/card-item-picker-row.tsx +0 -109
  359. package/src/components/card-item-picker/card-item-picker.json +0 -147
  360. package/src/components/card-item-picker/card-item-picker.stories.tsx +0 -158
  361. package/src/components/card-item-picker/index.ts +0 -24
  362. package/src/components/chat-message-history/chat-message-history.json +0 -99
  363. package/src/components/chat-message-history/chat-message-history.stories.tsx +0 -136
  364. package/src/components/chat-message-history/chat-message-history.tsx +0 -277
  365. package/src/components/chat-message-history/index.ts +0 -13
  366. package/src/components/spinner/index.ts +0 -1
  367. package/src/components/spinner/spinner.json +0 -73
  368. package/src/components/spinner/spinner.stories.tsx +0 -41
  369. package/src/components/spinner/spinner.tsx +0 -32
@@ -85,7 +85,11 @@ export function useChatThread(): ChatThreadCommands {
85
85
  return useContext(ChatThreadCommandsContext) ?? NOOP_COMMANDS;
86
86
  }
87
87
 
88
- function ChatThreadCommandsBridge({ children }: { children?: ReactNode }) {
88
+ interface ChatThreadCommandsBridgeProps {
89
+ children?: ReactNode;
90
+ }
91
+
92
+ function ChatThreadCommandsBridge({ children }: ChatThreadCommandsBridgeProps) {
89
93
  const { scrollToEnd, scrollToMessage, scrollToStart } = useMessageScroller();
90
94
 
91
95
  const commands = useMemo<ChatThreadCommands>(
@@ -137,7 +141,7 @@ function useChatThreadSession(component: string) {
137
141
 
138
142
  type ScrollerProviderProps = ComponentProps<typeof MessageScrollerPrimitive.Provider>;
139
143
 
140
- export type ChatThreadProviderProps = ScrollerProviderProps & {
144
+ export interface ChatThreadProviderProps extends ScrollerProviderProps {
141
145
  /** Identity of the conversation; changing it resets the thread so the new conversation opens at the end */
142
146
  conversationId?: string | null;
143
147
  /** Ids of the rendered groups, matching each `ChatThreadGroup`'s `groupId` */
@@ -152,7 +156,7 @@ export type ChatThreadProviderProps = ScrollerProviderProps & {
152
156
  * drags the view down; in `follow` mode it defaults to always following.
153
157
  */
154
158
  autoScroll?: boolean;
155
- };
159
+ }
156
160
 
157
161
  interface ThreadSessionState {
158
162
  id: number;
@@ -172,6 +176,11 @@ function createSessionState(
172
176
  };
173
177
  }
174
178
 
179
+ /**
180
+ * Holds the scroll session of one conversation: which groups are history and which are new, the scroll
181
+ * mode, and the scroll commands `useChatThread` returns. Renders no element; wrap `ChatThread` and
182
+ * anything that scrolls it.
183
+ */
175
184
  export function ChatThreadProvider({
176
185
  children,
177
186
  conversationId,
@@ -224,17 +233,16 @@ export function ChatThreadProvider({
224
233
  );
225
234
  }
226
235
 
236
+ interface FollowNewGroupsProps {
237
+ groupIds: readonly string[];
238
+ knownGroupIds: ReadonlySet<string> | null;
239
+ }
240
+
227
241
  /**
228
242
  * In `follow` mode, a new group (the reader sent a prompt) returns the view to the end and resumes following,
229
243
  * even when the reader had scrolled up to read earlier output.
230
244
  */
231
- function FollowNewGroups({
232
- groupIds,
233
- knownGroupIds,
234
- }: {
235
- groupIds: readonly string[];
236
- knownGroupIds: ReadonlySet<string> | null;
237
- }) {
245
+ function FollowNewGroups({ groupIds, knownGroupIds }: FollowNewGroupsProps) {
238
246
  const { scrollToEnd } = useMessageScroller();
239
247
  const lastGroupId = groupIds.at(-1);
240
248
 
@@ -254,11 +262,15 @@ export type ChatThreadError = Error | string;
254
262
 
255
263
  export interface ChatThreadProps extends Omit<ComponentPropsWithoutRef<'div'>, 'children'> {
256
264
  children?: ReactNode;
265
+ /** Classes on the scrolling viewport, the element between the root and the content */
266
+ viewportClassName?: string;
267
+ /** Classes on the scrolled content: its padding and the gap between groups */
257
268
  contentClassName?: string;
258
269
  viewportRef?: Ref<HTMLDivElement>;
259
270
  contentRef?: Ref<HTMLDivElement>;
260
271
  /** Renders the scroll-to-latest button */
261
272
  scrollButton?: boolean;
273
+ /** Classes on the wrapper that positions the scroll-to-latest button */
262
274
  scrollButtonClassName?: string;
263
275
  scrollButtonTooltip?: string;
264
276
  isLoading?: boolean;
@@ -268,10 +280,15 @@ export interface ChatThreadProps extends Omit<ComponentPropsWithoutRef<'div'>, '
268
280
  renderError?: (error?: ChatThreadError) => ReactNode;
269
281
  }
270
282
 
283
+ /**
284
+ * The scroller of a conversation: a viewport that scrolls the groups, the scroll-to-latest button and
285
+ * the error state. Fills its parent, so the parent needs a definite height.
286
+ */
271
287
  export const ChatThread = forwardRef<HTMLDivElement, ChatThreadProps>(function ChatThread(
272
288
  {
273
289
  children,
274
290
  className,
291
+ viewportClassName,
275
292
  contentClassName,
276
293
  viewportRef,
277
294
  contentRef,
@@ -314,8 +331,10 @@ export const ChatThread = forwardRef<HTMLDivElement, ChatThreadProps>(function C
314
331
 
315
332
  return (
316
333
  <MessageScrollerPrimitive.Root
334
+ data-slot="chat-thread"
317
335
  data-testid="chat-thread"
318
336
  data-scroll-mode={scrollMode}
337
+ data-streaming={isStreaming}
319
338
  data-loading={isLoading}
320
339
  data-error={hasError}
321
340
  className={cn('relative flex flex-col flex-1 min-h-0 overflow-hidden', className)}
@@ -323,12 +342,14 @@ export const ChatThread = forwardRef<HTMLDivElement, ChatThreadProps>(function C
323
342
  >
324
343
  <ViewportPrimitive
325
344
  ref={setViewport}
345
+ data-slot="chat-thread-viewport"
326
346
  aria-label="Chat message history"
327
347
  className={cn(
328
348
  'size-full overflow-x-hidden overflow-y-auto outline-none',
329
349
  'will-change-scroll transform-gpu',
330
350
  // A continuous stream outruns smooth scrolling, so following jumps instead
331
351
  isAnchored && isStreaming && 'scroll-smooth',
352
+ viewportClassName,
332
353
  )}
333
354
  style={{
334
355
  scrollbarGutter: 'stable both-edges',
@@ -338,6 +359,7 @@ export const ChatThread = forwardRef<HTMLDivElement, ChatThreadProps>(function C
338
359
  >
339
360
  <ContentPrimitive
340
361
  ref={setContent}
362
+ data-slot="chat-thread-content"
341
363
  aria-busy={isStreaming}
342
364
  data-testid="chat-thread-content"
343
365
  className={cn(
@@ -365,6 +387,8 @@ export const ChatThread = forwardRef<HTMLDivElement, ChatThreadProps>(function C
365
387
  );
366
388
  });
367
389
 
390
+ ChatThread.displayName = 'ChatThread';
391
+
368
392
  /**
369
393
  * Keeps the latest group at least as tall as the room below its anchored position, so a new message can
370
394
  * settle at the top of the viewport and the answer streams in without the scroll position jumping.
@@ -422,7 +446,7 @@ export interface ChatThreadGroupProps extends ComponentPropsWithoutRef<'div'> {
422
446
  * mode no group anchors.
423
447
  */
424
448
  export const ChatThreadGroup = forwardRef<HTMLDivElement, ChatThreadGroupProps>(
425
- function ChatThreadGroup({ groupId, className, ...rest }, ref) {
449
+ function ChatThreadGroup({ groupId, className, children, ...rest }, ref) {
426
450
  const { knownGroupIds, scrollMode } = useChatThreadSession('ChatThreadGroup');
427
451
  const isNew = scrollMode === 'anchor' && knownGroupIds !== null && !knownGroupIds.has(groupId);
428
452
 
@@ -432,39 +456,61 @@ export const ChatThreadGroup = forwardRef<HTMLDivElement, ChatThreadGroupProps>(
432
456
  // Namespaced: `data-message-id` is also how consumers find message bubbles
433
457
  messageId={`chat-thread-group-${groupId}`}
434
458
  scrollAnchor={isNew}
459
+ data-slot="chat-thread-group"
435
460
  data-chat-thread-group=""
436
461
  className={cn('flex flex-col gap-16 w-full min-h-px mx-auto', className)}
437
462
  {...rest}
438
- />
463
+ >
464
+ {children}
465
+ </ItemPrimitive>
439
466
  );
440
467
  },
441
468
  );
442
469
 
470
+ ChatThreadGroup.displayName = 'ChatThreadGroup';
471
+
443
472
  export interface ChatThreadMessageProps extends ComponentPropsWithoutRef<'div'> {
444
473
  messageId: string;
445
474
  }
446
475
 
476
+ /** Marks the question of a group with its message id. Adds no styling. */
447
477
  export const ChatThreadQuestion = forwardRef<HTMLDivElement, ChatThreadMessageProps>(
448
- function ChatThreadQuestion({ messageId, ...rest }, ref) {
478
+ function ChatThreadQuestion({ messageId, children, ...rest }, ref) {
449
479
  return (
450
480
  <div
451
481
  ref={ref}
482
+ data-slot="chat-thread-question"
452
483
  data-chat-thread-question=""
453
484
  data-chat-thread-message-id={messageId}
454
485
  {...rest}
455
- />
486
+ >
487
+ {children}
488
+ </div>
456
489
  );
457
490
  },
458
491
  );
459
492
 
493
+ ChatThreadQuestion.displayName = 'ChatThreadQuestion';
494
+
495
+ /** Marks the answer of a group with its message id. Adds no styling. */
460
496
  export const ChatThreadAnswer = forwardRef<HTMLDivElement, ChatThreadMessageProps>(
461
- function ChatThreadAnswer({ messageId, ...rest }, ref) {
497
+ function ChatThreadAnswer({ messageId, children, ...rest }, ref) {
462
498
  return (
463
- <div ref={ref} data-chat-thread-answer="" data-chat-thread-message-id={messageId} {...rest} />
499
+ <div
500
+ ref={ref}
501
+ data-slot="chat-thread-answer"
502
+ data-chat-thread-answer=""
503
+ data-chat-thread-message-id={messageId}
504
+ {...rest}
505
+ >
506
+ {children}
507
+ </div>
464
508
  );
465
509
  },
466
510
  );
467
511
 
512
+ ChatThreadAnswer.displayName = 'ChatThreadAnswer';
513
+
468
514
  // Parts
469
515
 
470
516
  interface ChatThreadScrollButtonProps {
@@ -477,6 +523,7 @@ function ChatThreadScrollButton({ className, tooltip }: ChatThreadScrollButtonPr
477
523
 
478
524
  return (
479
525
  <div
526
+ data-slot="chat-thread-scroll-button"
480
527
  data-testid="chat-message-history-scroll-button"
481
528
  data-hidden={!hasContentBelow}
482
529
  aria-hidden={hasContentBelow ? undefined : true}
@@ -531,6 +578,7 @@ export interface ChatThreadErrorStateProps {
531
578
  export function ChatThreadErrorState({ children, error, className }: ChatThreadErrorStateProps) {
532
579
  return (
533
580
  <div
581
+ data-slot="chat-thread-error-state"
534
582
  data-testid="chat-message-history-error-state"
535
583
  role="alert"
536
584
  aria-live="assertive"
@@ -8,7 +8,6 @@ export * from './chat-message';
8
8
  export * from './chat-messages';
9
9
  export * from './chat-message-attachment-card';
10
10
  export * from './chat-message-response';
11
- export * from './chat-message-history';
12
11
  export * from './chat-message-toolbar';
13
12
  export * from './chat-notification-card';
14
13
  export * from './chat-notification-popup';
@@ -16,11 +15,10 @@ export * from './chat-reply';
16
15
  export * from './chat-suggestion';
17
16
  export * from './chat-thread';
18
17
  export * from './canvas-shell';
19
- export * from './card-item-picker';
20
18
  export * from './new-chat-trigger';
21
19
  export * from './chat-thinking-process';
22
20
  export * from './deprecated-empty-state';
23
21
  export * from './markdown-viewer';
24
22
  export * from './rich-text-area';
25
23
  export * from './rich-text-field';
26
- export * from './spinner';
24
+ export * from './topmenu';
@@ -0,0 +1,67 @@
1
+ import type { Markdown } from '../../../types';
2
+
3
+ /** A typical short answer: one lead-in line and a list with inline emphasis. */
4
+ export const DAY_AT_A_GLANCE: Markdown = [
5
+ "Here's your day at a glance:",
6
+ '',
7
+ '- **09:30** Stand-up with the product team',
8
+ '- **12:00** Lunch with Anna at Hiltl',
9
+ '- **15:00** Quarterly review, *slides still in draft*',
10
+ ].join('\n');
11
+
12
+ export const QUESTION = 'What does my week look like?';
13
+
14
+ /** The answer the welcome screen streams: a greeting, then a hidden block of reply suggestions. */
15
+ export const GREETING: Markdown = `Good evening! Great to see you! I'm ready to help with whatever's on your mind - whether it's research, planning, writing, or just thinking something through.
16
+
17
+ <swi-reply style="display:none" version="0.0.1">
18
+ What can you help me with?|Check my calendar for today|Search for something
19
+ </swi-reply>`;
20
+
21
+ /** `GREETING` cut off inside the suggestions, as it looks part-way through the stream. */
22
+ export const GREETING_CUT_IN_SUGGESTIONS: Markdown = `Good evening! Great to see you!
23
+
24
+ <swi-reply style="display:none" version="0.0.1">
25
+ What can you help me with?|Check my calendar`;
26
+
27
+ /** `GREETING` cut off inside the opening tag, before its attributes have arrived. */
28
+ export const GREETING_CUT_IN_TAG: Markdown = `Good evening! Great to see you!
29
+
30
+ <swi-reply style="disp`;
31
+
32
+ /** One tag the app renders and one it does not know. */
33
+ export const KNOWN_AND_UNKNOWN_TAGS: Markdown = `You're welcome! Is there anything else I can help you with today?
34
+
35
+ <swi-reply style="display:none" version="1.0.0">
36
+ Check my calendar|Send another email|Show me the news
37
+ </swi-reply>
38
+
39
+ <swi-seat-map>Seat map is not available in this app</swi-seat-map>
40
+ `;
41
+
42
+ /** A link that opens a screen of the app, next to an ordinary web link. */
43
+ export const ANSWER_WITH_APP_LINK: Markdown =
44
+ 'Your trip to Lugano is booked. [Open the itinerary](swisper://trips/trip_01) or read the [SBB travel conditions](https://www.sbb.ch/en).';
45
+
46
+ /** The longest kind of answer: a heading, a table, a quote, code and reply suggestions. */
47
+ export const WEEK_SUMMARY: Markdown = `## Your week at a glance
48
+
49
+ You have **7 meetings** and *two open deadlines*. Wednesday is the busiest day.
50
+
51
+ | Day | Meetings | Focus time |
52
+ | --- | --- | --- |
53
+ | Monday | 2 | 4 h |
54
+ | Wednesday | 4 | 1 h |
55
+ | Friday | 1 | 6 h |
56
+
57
+ 1. Send the quarterly review slides by **Tuesday 17:00**
58
+ 2. Confirm the Lugano offsite with the team
59
+ 3. Renew the SBB half-fare travelcard, which expires on 1 November
60
+
61
+ > Thursday afternoon is still free: a good slot for the review rehearsal.
62
+
63
+ To block that slot yourself, send \`/focus thu 14:00-16:00\` or add it in the [calendar settings](https://example.com/settings/calendar).
64
+
65
+ <swi-reply style="display:none" version="1.0.0">
66
+ Block Thursday afternoon|Show Wednesday in detail|Draft the offsite invite
67
+ </swi-reply>`;
@@ -2,6 +2,11 @@
2
2
  "$schema": "../../../../int-eslint-config/schemas/component.schema.json",
3
3
  "component": "markdown-viewer",
4
4
  "purpose": "Renders an assistant's markdown (GitHub-flavoured, with sanitised inline HTML) through Streamdown, repairs half-received syntax while it streams, and renders <swi-*> tags with caller-supplied React components.",
5
+ "anatomy": [
6
+ "import { MarkdownViewer } from '@swisper.ai/web-chat-ui';",
7
+ "",
8
+ "<MarkdownViewer />"
9
+ ],
5
10
  "useWhen": [
6
11
  "Rendering an assistant answer or any model-generated markdown in the chat",
7
12
  "The text is still streaming in and must render cleanly at every partial step",
@@ -40,7 +45,8 @@
40
45
  "isStreaming tells Streamdown the last block is still arriving (isAnimating); hasCaret shows a block caret after the last character only while isStreaming is true",
41
46
  "customComponents maps tag names to React components: <swi-*> keys render those tags, and standard element keys (p, a, code) override Streamdown's renderers but log a console warning",
42
47
  "A <swi-*> tag with no entry in customComponents is stripped by the sanitiser and only its text is kept",
43
- "Inline HTML is parsed and sanitised with rehype-sanitize, whose allow-list is extended with the mapped <swi-*> tags; links may use the swisper: protocol, and they render without Streamdown's link-safety confirmation"
48
+ "Inline HTML is parsed and sanitised with rehype-sanitize, whose allow-list is extended with the mapped <swi-*> tags; links may use the swisper: protocol, and they render without Streamdown's link-safety confirmation",
49
+ "className is merged last onto the root element, the block that stacks the rendered markdown; that element carries no data-slot, and the rendered blocks are styled through customComponents"
44
50
  ]
45
51
  },
46
52
  "composition": {
@@ -1,12 +1,28 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite';
2
- import { expect, within } from 'storybook/test';
2
+ import type { Element, ElementContent } from 'hast';
3
+ import { expect } from 'storybook/test';
3
4
 
5
+ import { Button } from '@swisper.ai/ui';
6
+
7
+ import { ParentBlock } from '../../__storybook__/parent-block';
4
8
  import { useStreamingMarkdown } from '../../utils/use-streaming-markdown';
9
+ import { ChatMessage, ChatMessageContent } from '../chat-message';
5
10
 
6
- import { MarkdownViewer } from './markdown-viewer';
11
+ import {
12
+ ANSWER_WITH_APP_LINK,
13
+ DAY_AT_A_GLANCE,
14
+ GREETING,
15
+ GREETING_CUT_IN_SUGGESTIONS,
16
+ GREETING_CUT_IN_TAG,
17
+ KNOWN_AND_UNKNOWN_TAGS,
18
+ QUESTION,
19
+ WEEK_SUMMARY,
20
+ } from './__stories__/fixtures';
21
+ import { MarkdownViewer, type MarkdownViewerProps } from './markdown-viewer';
22
+ import type { CustomMarkdownViewerComponents } from './types';
7
23
 
8
24
  const meta: Meta<typeof MarkdownViewer> = {
9
- title: 'Chatbot/MarkdownViewer',
25
+ title: 'Chat/MarkdownViewer',
10
26
  component: MarkdownViewer,
11
27
  parameters: {
12
28
  layout: 'padded',
@@ -18,6 +34,11 @@ const meta: Meta<typeof MarkdownViewer> = {
18
34
  description:
19
35
  'Markdown to render: GFM, math and `<swi-*>` tags. Pass the accumulated text so far while streaming.',
20
36
  },
37
+ className: {
38
+ control: 'text',
39
+ description:
40
+ 'Classes merged last onto the root element, e.g. `text-text-secondary` for a muted body.',
41
+ },
21
42
  isStreaming: {
22
43
  control: 'boolean',
23
44
  description:
@@ -26,7 +47,7 @@ const meta: Meta<typeof MarkdownViewer> = {
26
47
  },
27
48
  hasCaret: {
28
49
  control: 'boolean',
29
- description: 'Shows a block caret after the last character, typically while streaming.',
50
+ description: 'Shows a block caret after the last character while `isStreaming` is true.',
30
51
  table: { defaultValue: { summary: 'false' } },
31
52
  },
32
53
  customComponents: {
@@ -37,8 +58,7 @@ const meta: Meta<typeof MarkdownViewer> = {
37
58
  },
38
59
  },
39
60
  args: {
40
- markdown:
41
- "Here's your day at a glance:\n\n- **09:30** Stand-up with the product team\n- **12:00** Lunch with Anna at Hiltl\n- **15:00** Quarterly review, *slides still in draft*",
61
+ markdown: DAY_AT_A_GLANCE,
42
62
  isStreaming: false,
43
63
  hasCaret: false,
44
64
  },
@@ -47,64 +67,213 @@ const meta: Meta<typeof MarkdownViewer> = {
47
67
  export default meta;
48
68
  type Story = StoryObj<typeof MarkdownViewer>;
49
69
 
50
- const sampleMarkdown = `Welcome to MarkdownViewer!`;
70
+ /** A finished assistant answer: a lead-in line and a list with inline emphasis. */
71
+ export const Default: Story = {};
51
72
 
52
- const GREETING_EXAMPLE = `Good evening! Great to see you! I'm ready to help with whatever's on your mind - whether it's research, planning, writing, or just thinking something through.
73
+ function textOf(nodes: ElementContent[]): string {
74
+ return nodes
75
+ .map((node) => {
76
+ if (node.type === 'text') return node.value;
77
+ if (node.type === 'element') return textOf(node.children);
78
+ return '';
79
+ })
80
+ .join('');
81
+ }
53
82
 
54
- <swi-reply style="display:none" version="0.0.1">
55
- What can you help me with?|Check my calendar for today|Search for something
56
- </swi-reply>`;
83
+ interface ReplySuggestionsProps {
84
+ /** The `<swi-reply>` element: its text is the suggestions, separated by `|`. */
85
+ node?: Element;
86
+ }
57
87
 
58
- export const Default: Story = {
59
- args: {
60
- markdown: sampleMarkdown,
61
- isStreaming: false,
62
- },
63
- argTypes: {
64
- markdown: {
65
- control: 'text',
66
- description: 'Markdown content to render',
67
- },
68
- isStreaming: {
69
- control: 'boolean',
70
- description: 'Whether the content is currently streaming',
71
- },
72
- },
88
+ /** Renders a `<swi-reply>` tag as one button per suggested reply. */
89
+ function ReplySuggestions({ node }: ReplySuggestionsProps) {
90
+ const suggestions = textOf(node?.children ?? [])
91
+ .split('|')
92
+ .map((suggestion) => suggestion.trim())
93
+ .filter(Boolean);
94
+
95
+ if (suggestions.length === 0) return null;
96
+
97
+ return (
98
+ <div role="group" aria-label="Suggested replies" className="flex flex-wrap gap-8">
99
+ {suggestions.map((suggestion) => (
100
+ <Button key={suggestion} variant="secondary" size="sm">
101
+ {suggestion}
102
+ </Button>
103
+ ))}
104
+ </div>
105
+ );
106
+ }
107
+
108
+ // Created once at module scope: its identity is a memo dependency of the viewer.
109
+ const REPLY_COMPONENTS: CustomMarkdownViewerComponents = {
110
+ 'swi-reply': ReplySuggestions,
73
111
  };
74
112
 
113
+ /** A `<swi-reply>` tag rendered by the app's own component, and an unknown `<swi-*>` tag reduced to its text. */
75
114
  export const CustomComponents: Story = {
115
+ tags: ['e2e'],
76
116
  args: {
77
- markdown: `<swi-reply style="display:none" version="0.0.1">
78
- What can you help me with?|Check my calendar for today|Search for something
79
- </swi-reply>
80
- <swi-unsupported>Not supported(just text)</swi-unsupported>
81
- `,
82
- customComponents: {
83
- 'swi-reply': () => <div data-testid="swi-reply">[custom component: swi-reply!]</div>,
84
- },
117
+ markdown: KNOWN_AND_UNKNOWN_TAGS,
118
+ customComponents: REPLY_COMPONENTS,
85
119
  isStreaming: false,
86
120
  },
87
- play: async ({ canvasElement }) => {
88
- const canvas = within(canvasElement);
89
-
90
- // Verify swi-reply custom component renders correctly
91
- const customComponent = canvas.getByText('[custom component: swi-reply!]');
92
- expect(canvas.getByTestId('swi-reply')).toBeInTheDocument();
93
- expect(customComponent).toBeInTheDocument();
94
- expect(customComponent.tagName).toBe('DIV');
95
-
96
- // Verify swi-unsupported is completely removed
97
- const htmlContent = canvasElement.innerHTML;
98
- expect(htmlContent).not.toContain('swi-unsupported');
99
- expect(canvas.queryByText('swi-unsupported')).not.toBeInTheDocument();
100
- expect(canvas.queryByText('Not supported(just text)')).toBeInTheDocument();
121
+ play: async ({ canvas, canvasElement, step }) => {
122
+ await step('Renders the mapped tag with its component', async () => {
123
+ const replies = canvas.getByRole('group', { name: 'Suggested replies' });
124
+ await expect(replies.tagName).toBe('DIV');
125
+ await expect(canvas.getAllByRole('button')).toHaveLength(3);
126
+ await expect(canvas.getByRole('button', { name: 'Check my calendar' })).toBeVisible();
127
+ await expect(canvasElement.innerHTML).not.toContain('swi-reply');
128
+ });
129
+
130
+ await step('Strips the unmapped tag and keeps its text', async () => {
131
+ await expect(canvasElement.innerHTML).not.toContain('swi-seat-map');
132
+ await expect(canvas.queryByText('swi-seat-map')).not.toBeInTheDocument();
133
+ await expect(canvas.getByText('Seat map is not available in this app')).toBeInTheDocument();
134
+ });
101
135
  },
102
136
  };
103
137
 
138
+ /** The greeting arriving character by character, with the caret after the last one until the stream ends. */
104
139
  export const Streaming: Story = {
140
+ parameters: { controls: { disable: true } },
105
141
  render: () => {
106
- const { markdown, isStreaming } = useStreamingMarkdown(GREETING_EXAMPLE, 30);
142
+ const { markdown, isStreaming } = useStreamingMarkdown(GREETING, 30);
143
+
144
+ return (
145
+ <MarkdownViewer
146
+ markdown={markdown}
147
+ isStreaming={isStreaming}
148
+ hasCaret={isStreaming}
149
+ customComponents={REPLY_COMPONENTS}
150
+ />
151
+ );
152
+ },
153
+ };
154
+
155
+ /** The viewer where it is allowed: the content of an assistant message, alone and in a chat thread. */
156
+ export const Examples: Story = {
157
+ parameters: { controls: { disable: true } },
158
+ render: () => (
159
+ <div className="flex max-w-180 flex-col gap-24">
160
+ <ParentBlock parent="web-chat-ui/ChatMessageContent">
161
+ <ChatMessage>
162
+ <ChatMessageContent>
163
+ <MarkdownViewer markdown={DAY_AT_A_GLANCE} />
164
+ </ChatMessageContent>
165
+ </ChatMessage>
166
+ </ParentBlock>
167
+
168
+ <ParentBlock parent="assistant message in a chat thread">
169
+ <section aria-label="Chat thread" className="flex flex-col gap-16">
170
+ <ChatMessage isQuestion>
171
+ <ChatMessageContent>{QUESTION}</ChatMessageContent>
172
+ </ChatMessage>
173
+ <ChatMessage>
174
+ <ChatMessageContent>
175
+ <MarkdownViewer markdown={WEEK_SUMMARY} customComponents={REPLY_COMPONENTS} />
176
+ </ChatMessageContent>
177
+ </ChatMessage>
178
+ </section>
179
+ </ParentBlock>
180
+ </div>
181
+ ),
182
+ };
107
183
 
108
- return <MarkdownViewer markdown={markdown} isStreaming={isStreaming} />;
184
+ /** A stream cut off inside a `<swi-reply>` tag still renders the suggestions received so far. */
185
+ export const StreamCutInsideTag: Story = {
186
+ tags: ['e2e', '!autodocs'],
187
+ args: {
188
+ markdown: GREETING_CUT_IN_SUGGESTIONS,
189
+ isStreaming: true,
190
+ customComponents: REPLY_COMPONENTS,
191
+ },
192
+ play: async ({ canvas, canvasElement, step }) => {
193
+ await step('Closes the unclosed tag so its renderer gets the text so far', async () => {
194
+ await expect(canvas.getByText('Good evening! Great to see you!')).toBeVisible();
195
+ await expect(
196
+ canvas.getByRole('button', { name: 'What can you help me with?' }),
197
+ ).toBeVisible();
198
+ await expect(canvas.getByRole('button', { name: 'Check my calendar' })).toBeVisible();
199
+ });
200
+
201
+ await step('Shows no raw tag', async () => {
202
+ await expect(canvasElement.textContent).not.toContain('swi-reply');
203
+ });
204
+ },
205
+ };
206
+
207
+ /** A stream cut off inside the opening `<swi-reply` tag prints none of the half-received tag. */
208
+ export const StreamCutInsideOpeningTag: Story = {
209
+ tags: ['e2e', '!autodocs'],
210
+ args: {
211
+ markdown: GREETING_CUT_IN_TAG,
212
+ isStreaming: true,
213
+ customComponents: REPLY_COMPONENTS,
214
+ },
215
+ play: async ({ canvas, canvasElement, step }) => {
216
+ await step('Completes the cut-off opening tag instead of printing it', async () => {
217
+ await expect(canvas.getByText('Good evening! Great to see you!')).toBeVisible();
218
+ await expect(canvasElement.textContent).not.toContain('swi-reply');
219
+ await expect(canvasElement.textContent).not.toContain('disp');
220
+ await expect(canvas.queryByRole('button')).not.toBeInTheDocument();
221
+ });
222
+ },
223
+ };
224
+
225
+ /** A `swisper:` link survives sanitising and renders as a plain link, like a web link. */
226
+ export const AppLink: Story = {
227
+ tags: ['e2e', '!autodocs'],
228
+ args: {
229
+ markdown: ANSWER_WITH_APP_LINK,
230
+ },
231
+ play: async ({ canvas, step }) => {
232
+ await step('Keeps a swisper: link next to a web link', async () => {
233
+ await expect(canvas.getByRole('link', { name: 'Open the itinerary' })).toHaveAttribute(
234
+ 'href',
235
+ 'swisper://trips/trip_01',
236
+ );
237
+ await expect(canvas.getByRole('link', { name: 'SBB travel conditions' })).toHaveAttribute(
238
+ 'href',
239
+ 'https://www.sbb.ch/en',
240
+ );
241
+ });
242
+ },
243
+ };
244
+
245
+ interface MarkdownViewerPlaygroundProps extends Omit<MarkdownViewerProps, 'customComponents'> {
246
+ hasReplySuggestions: boolean;
247
+ }
248
+
249
+ function MarkdownViewerPlayground({
250
+ hasReplySuggestions,
251
+ ...viewerProps
252
+ }: MarkdownViewerPlaygroundProps) {
253
+ return (
254
+ <MarkdownViewer
255
+ {...viewerProps}
256
+ customComponents={hasReplySuggestions ? REPLY_COMPONENTS : undefined}
257
+ />
258
+ );
259
+ }
260
+
261
+ /** Every prop on the Controls panel, starting from a long answer that ends in reply suggestions. */
262
+ export const Playground: StoryObj<typeof MarkdownViewerPlayground> = {
263
+ tags: ['!autodocs'],
264
+ args: {
265
+ markdown: WEEK_SUMMARY,
266
+ className: '',
267
+ isStreaming: false,
268
+ hasCaret: false,
269
+ hasReplySuggestions: true,
270
+ },
271
+ argTypes: {
272
+ hasReplySuggestions: {
273
+ control: 'boolean',
274
+ description:
275
+ 'Passes `customComponents` with a `swi-reply` renderer. When off, the tag is unmapped and only its text is kept.',
276
+ },
109
277
  },
278
+ render: (args) => <MarkdownViewerPlayground {...args} />,
110
279
  };