@djangocfg/ui-tools 2.1.335 → 2.1.337

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 (194) hide show
  1. package/README.md +68 -2
  2. package/dist/ChatRoot-PNNGQCYF.css +7 -0
  3. package/dist/ChatRoot-PNNGQCYF.css.map +1 -0
  4. package/dist/ChatRoot-XV2QXMV4.mjs +5 -0
  5. package/dist/ChatRoot-XV2QXMV4.mjs.map +1 -0
  6. package/dist/ChatRoot-YX4RLHQX.cjs +14 -0
  7. package/dist/ChatRoot-YX4RLHQX.cjs.map +1 -0
  8. package/dist/{CronScheduler.client-3O3VU4CI.mjs → CronScheduler.client-DLMXCPAJ.mjs} +4 -4
  9. package/dist/{CronScheduler.client-3O3VU4CI.mjs.map → CronScheduler.client-DLMXCPAJ.mjs.map} +1 -1
  10. package/dist/{CronScheduler.client-A4GO6YBY.cjs → CronScheduler.client-WEJF4PWQ.cjs} +14 -14
  11. package/dist/{CronScheduler.client-A4GO6YBY.cjs.map → CronScheduler.client-WEJF4PWQ.cjs.map} +1 -1
  12. package/dist/{DocsLayout-XLDB6CJ2.cjs → DocsLayout-N5ZJZPBY.cjs} +200 -199
  13. package/dist/DocsLayout-N5ZJZPBY.cjs.map +1 -0
  14. package/dist/{DocsLayout-CTJINVBM.mjs → DocsLayout-VFPPNKSQ.mjs} +7 -6
  15. package/dist/DocsLayout-VFPPNKSQ.mjs.map +1 -0
  16. package/dist/JsonSchemaForm-DD7CLRIG.cjs +13 -0
  17. package/dist/{JsonSchemaForm-6WMS4CIY.cjs.map → JsonSchemaForm-DD7CLRIG.cjs.map} +1 -1
  18. package/dist/JsonSchemaForm-XKUIVELK.mjs +4 -0
  19. package/dist/{JsonSchemaForm-KX4JT3M4.mjs.map → JsonSchemaForm-XKUIVELK.mjs.map} +1 -1
  20. package/dist/JsonTree-55625VVH.mjs +5 -0
  21. package/dist/{JsonTree-F27RMYSI.cjs.map → JsonTree-55625VVH.mjs.map} +1 -1
  22. package/dist/JsonTree-DCM5QGWF.cjs +11 -0
  23. package/dist/{JsonTree-QTJYSHCV.mjs.map → JsonTree-DCM5QGWF.cjs.map} +1 -1
  24. package/dist/{LottiePlayer.client-6WVWDO75.cjs → LottiePlayer.client-2S7ISJ2S.cjs} +6 -6
  25. package/dist/{LottiePlayer.client-6WVWDO75.cjs.map → LottiePlayer.client-2S7ISJ2S.cjs.map} +1 -1
  26. package/dist/{LottiePlayer.client-B4I6WNZM.mjs → LottiePlayer.client-5LDSSJWS.mjs} +4 -4
  27. package/dist/{LottiePlayer.client-B4I6WNZM.mjs.map → LottiePlayer.client-5LDSSJWS.mjs.map} +1 -1
  28. package/dist/{MapContainer-RYG4HPH4.cjs → MapContainer-76YL2JXL.cjs} +8 -8
  29. package/dist/{MapContainer-RYG4HPH4.cjs.map → MapContainer-76YL2JXL.cjs.map} +1 -1
  30. package/dist/{MapContainer-GXQLP5WY.mjs → MapContainer-7HXBI3OH.mjs} +3 -3
  31. package/dist/{MapContainer-GXQLP5WY.mjs.map → MapContainer-7HXBI3OH.mjs.map} +1 -1
  32. package/dist/{Mermaid.client-SXRRI2YW.mjs → Mermaid.client-NL4SVR7F.mjs} +4 -4
  33. package/dist/{Mermaid.client-SXRRI2YW.mjs.map → Mermaid.client-NL4SVR7F.mjs.map} +1 -1
  34. package/dist/{Mermaid.client-W76R5AKJ.cjs → Mermaid.client-NNTI6DFX.cjs} +26 -26
  35. package/dist/{Mermaid.client-W76R5AKJ.cjs.map → Mermaid.client-NNTI6DFX.cjs.map} +1 -1
  36. package/dist/Player-BRV7XTWR.mjs +4 -0
  37. package/dist/{Player-M3GC3VPE.mjs.map → Player-BRV7XTWR.mjs.map} +1 -1
  38. package/dist/Player-PM7F7DD7.cjs +13 -0
  39. package/dist/{Player-ZL2X5LGG.cjs.map → Player-PM7F7DD7.cjs.map} +1 -1
  40. package/dist/{PrettyCode.client-RPDIE5CH.cjs → PrettyCode.client-KOHDVPPN.cjs} +13 -13
  41. package/dist/{PrettyCode.client-RPDIE5CH.cjs.map → PrettyCode.client-KOHDVPPN.cjs.map} +1 -1
  42. package/dist/{PrettyCode.client-SPMTQEG4.mjs → PrettyCode.client-ZGYGKE7G.mjs} +4 -4
  43. package/dist/{PrettyCode.client-SPMTQEG4.mjs.map → PrettyCode.client-ZGYGKE7G.mjs.map} +1 -1
  44. package/dist/TreeRoot-N72OYKXU.cjs +19 -0
  45. package/dist/{TreeRoot-A3J65L6F.mjs.map → TreeRoot-N72OYKXU.cjs.map} +1 -1
  46. package/dist/TreeRoot-VGAIXCUA.mjs +4 -0
  47. package/dist/{TreeRoot-DSK5JILT.cjs.map → TreeRoot-VGAIXCUA.mjs.map} +1 -1
  48. package/dist/chunk-2ZLKZ5VR.mjs +631 -0
  49. package/dist/chunk-2ZLKZ5VR.mjs.map +1 -0
  50. package/dist/{chunk-LFWQ36LJ.mjs → chunk-5G5YBFS6.mjs} +4 -4
  51. package/dist/{chunk-LFWQ36LJ.mjs.map → chunk-5G5YBFS6.mjs.map} +1 -1
  52. package/dist/{chunk-IHAY6FO6.cjs → chunk-5I5QNGUG.cjs} +17 -17
  53. package/dist/{chunk-IHAY6FO6.cjs.map → chunk-5I5QNGUG.cjs.map} +1 -1
  54. package/dist/{chunk-F2CMIIOH.cjs → chunk-76NNDZH6.cjs} +42 -42
  55. package/dist/{chunk-F2CMIIOH.cjs.map → chunk-76NNDZH6.cjs.map} +1 -1
  56. package/dist/chunk-B5AWZOHJ.cjs +649 -0
  57. package/dist/chunk-B5AWZOHJ.cjs.map +1 -0
  58. package/dist/{chunk-KR6B3LVY.mjs → chunk-B6IR5KSC.mjs} +3 -3
  59. package/dist/{chunk-KR6B3LVY.mjs.map → chunk-B6IR5KSC.mjs.map} +1 -1
  60. package/dist/{chunk-5LBDYFWH.mjs → chunk-C6GXVH5J.mjs} +3 -3
  61. package/dist/{chunk-5LBDYFWH.mjs.map → chunk-C6GXVH5J.mjs.map} +1 -1
  62. package/dist/{chunk-NRKD4F5X.cjs → chunk-FEN5S772.cjs} +36 -36
  63. package/dist/{chunk-NRKD4F5X.cjs.map → chunk-FEN5S772.cjs.map} +1 -1
  64. package/dist/{chunk-2SMCH62O.cjs → chunk-FP2RLYQZ.cjs} +11 -11
  65. package/dist/{chunk-2SMCH62O.cjs.map → chunk-FP2RLYQZ.cjs.map} +1 -1
  66. package/dist/{chunk-MOME6KYD.mjs → chunk-G5IEC7SR.mjs} +3 -3
  67. package/dist/{chunk-MOME6KYD.mjs.map → chunk-G5IEC7SR.mjs.map} +1 -1
  68. package/dist/{chunk-SE5IERVH.mjs → chunk-GYIO7W7M.mjs} +3 -3
  69. package/dist/{chunk-SE5IERVH.mjs.map → chunk-GYIO7W7M.mjs.map} +1 -1
  70. package/dist/{chunk-3Z3A7FHA.cjs → chunk-IEEAENLX.cjs} +48 -48
  71. package/dist/{chunk-3Z3A7FHA.cjs.map → chunk-IEEAENLX.cjs.map} +1 -1
  72. package/dist/{chunk-DFTVB66S.cjs → chunk-KNDLV4PI.cjs} +85 -85
  73. package/dist/{chunk-DFTVB66S.cjs.map → chunk-KNDLV4PI.cjs.map} +1 -1
  74. package/dist/{chunk-SSUOENAZ.mjs → chunk-KNEQRUBA.mjs} +3 -3
  75. package/dist/{chunk-SSUOENAZ.mjs.map → chunk-KNEQRUBA.mjs.map} +1 -1
  76. package/dist/{chunk-CGILA3WO.mjs → chunk-N2XQF2OL.mjs} +5 -3
  77. package/dist/{chunk-CGILA3WO.mjs.map → chunk-N2XQF2OL.mjs.map} +1 -1
  78. package/dist/{chunk-EUADAUBQ.mjs → chunk-N4MZYNR4.mjs} +4 -4
  79. package/dist/{chunk-EUADAUBQ.mjs.map → chunk-N4MZYNR4.mjs.map} +1 -1
  80. package/dist/{chunk-GGKGH5PM.mjs → chunk-OBRSGM64.mjs} +4 -4
  81. package/dist/{chunk-GGKGH5PM.mjs.map → chunk-OBRSGM64.mjs.map} +1 -1
  82. package/dist/{chunk-6JTB2X72.mjs → chunk-ODO4GMW7.mjs} +3 -3
  83. package/dist/{chunk-6JTB2X72.mjs.map → chunk-ODO4GMW7.mjs.map} +1 -1
  84. package/dist/{chunk-WGEGR3DF.cjs → chunk-OLISEQHS.cjs} +5 -2
  85. package/dist/{chunk-WGEGR3DF.cjs.map → chunk-OLISEQHS.cjs.map} +1 -1
  86. package/dist/{chunk-PZKAH7WQ.mjs → chunk-PVAX67JG.mjs} +3 -3
  87. package/dist/{chunk-PZKAH7WQ.mjs.map → chunk-PVAX67JG.mjs.map} +1 -1
  88. package/dist/{chunk-PRPG2T2E.cjs → chunk-QJ6GTUCO.cjs} +6 -6
  89. package/dist/{chunk-PRPG2T2E.cjs.map → chunk-QJ6GTUCO.cjs.map} +1 -1
  90. package/dist/chunk-QW4RBGHN.cjs +961 -0
  91. package/dist/chunk-QW4RBGHN.cjs.map +1 -0
  92. package/dist/{chunk-33AMWFBZ.cjs → chunk-SGP7V2UW.cjs} +15 -15
  93. package/dist/{chunk-33AMWFBZ.cjs.map → chunk-SGP7V2UW.cjs.map} +1 -1
  94. package/dist/{chunk-FX2QFYWF.mjs → chunk-VWQ5WOIL.mjs} +3 -3
  95. package/dist/{chunk-FX2QFYWF.mjs.map → chunk-VWQ5WOIL.mjs.map} +1 -1
  96. package/dist/{chunk-ZLQHUZDU.cjs → chunk-YDPDTOSP.cjs} +139 -139
  97. package/dist/{chunk-ZLQHUZDU.cjs.map → chunk-YDPDTOSP.cjs.map} +1 -1
  98. package/dist/{chunk-77HQWEQ6.cjs → chunk-YW5IVWHQ.cjs} +33 -33
  99. package/dist/{chunk-77HQWEQ6.cjs.map → chunk-YW5IVWHQ.cjs.map} +1 -1
  100. package/dist/chunk-YWSQDBNU.mjs +2339 -0
  101. package/dist/chunk-YWSQDBNU.mjs.map +1 -0
  102. package/dist/{chunk-YXBOAGIM.cjs → chunk-YXZ6GU7H.cjs} +7 -7
  103. package/dist/{chunk-YXBOAGIM.cjs.map → chunk-YXZ6GU7H.cjs.map} +1 -1
  104. package/dist/{chunk-62Y65TGK.mjs → chunk-ZUFTH5IR.mjs} +8 -631
  105. package/dist/chunk-ZUFTH5IR.mjs.map +1 -0
  106. package/dist/chunk-ZWPBBAR2.cjs +2379 -0
  107. package/dist/chunk-ZWPBBAR2.cjs.map +1 -0
  108. package/dist/components-EHOGXATG.cjs +22 -0
  109. package/dist/{components-5UXYNAKR.cjs.map → components-EHOGXATG.cjs.map} +1 -1
  110. package/dist/components-MQ6DR7TX.cjs +26 -0
  111. package/dist/{components-CFXOEVPN.mjs.map → components-MQ6DR7TX.cjs.map} +1 -1
  112. package/dist/components-XRX7QGLB.mjs +5 -0
  113. package/dist/{components-WYEZL5TE.cjs.map → components-XRX7QGLB.mjs.map} +1 -1
  114. package/dist/components-YATKRWLH.mjs +5 -0
  115. package/dist/{components-ZAGG2PBO.mjs.map → components-YATKRWLH.mjs.map} +1 -1
  116. package/dist/file-icon/index.cjs +6 -6
  117. package/dist/file-icon/index.mjs +1 -1
  118. package/dist/index.cjs +739 -215
  119. package/dist/index.cjs.map +1 -1
  120. package/dist/index.d.cts +1025 -39
  121. package/dist/index.d.ts +1025 -39
  122. package/dist/index.mjs +387 -31
  123. package/dist/index.mjs.map +1 -1
  124. package/dist/tree/index.cjs +38 -38
  125. package/dist/tree/index.d.cts +2 -2
  126. package/dist/tree/index.d.ts +2 -2
  127. package/dist/tree/index.mjs +3 -3
  128. package/package.json +6 -6
  129. package/src/index.ts +5 -0
  130. package/src/stories/index.ts +3 -1
  131. package/src/tools/Chat/Chat.story.tsx +1006 -0
  132. package/src/tools/Chat/README.md +528 -0
  133. package/src/tools/Chat/components/Attachments.tsx +192 -0
  134. package/src/tools/Chat/components/ChatRoot.tsx +208 -0
  135. package/src/tools/Chat/components/Composer.tsx +134 -0
  136. package/src/tools/Chat/components/EmptyState.tsx +47 -0
  137. package/src/tools/Chat/components/ErrorBanner.tsx +47 -0
  138. package/src/tools/Chat/components/JumpToLatest.tsx +30 -0
  139. package/src/tools/Chat/components/MessageActions.tsx +72 -0
  140. package/src/tools/Chat/components/MessageBubble.tsx +228 -0
  141. package/src/tools/Chat/components/MessageList.tsx +82 -0
  142. package/src/tools/Chat/components/Sources.tsx +55 -0
  143. package/src/tools/Chat/components/StreamingIndicator.tsx +29 -0
  144. package/src/tools/Chat/components/ToolCalls.tsx +172 -0
  145. package/src/tools/Chat/components/index.ts +24 -0
  146. package/src/tools/Chat/config.ts +55 -0
  147. package/src/tools/Chat/context/ChatProvider.tsx +126 -0
  148. package/src/tools/Chat/context/index.ts +9 -0
  149. package/src/tools/Chat/core/audio/audioBus.ts +172 -0
  150. package/src/tools/Chat/core/audio/index.ts +8 -0
  151. package/src/tools/Chat/core/audio/preferences.ts +68 -0
  152. package/src/tools/Chat/core/audio/types.ts +49 -0
  153. package/src/tools/Chat/core/ids.ts +16 -0
  154. package/src/tools/Chat/core/index.ts +5 -0
  155. package/src/tools/Chat/core/logger.ts +73 -0
  156. package/src/tools/Chat/core/markdown.ts +56 -0
  157. package/src/tools/Chat/core/payload-dispatch.ts +54 -0
  158. package/src/tools/Chat/core/persona.ts +35 -0
  159. package/src/tools/Chat/core/reducer.ts +335 -0
  160. package/src/tools/Chat/core/transport/http.ts +167 -0
  161. package/src/tools/Chat/core/transport/index.ts +13 -0
  162. package/src/tools/Chat/core/transport/mock.ts +134 -0
  163. package/src/tools/Chat/core/transport/sse.ts +116 -0
  164. package/src/tools/Chat/core/transport/types.ts +24 -0
  165. package/src/tools/Chat/hooks/index.ts +26 -0
  166. package/src/tools/Chat/hooks/useChat.ts +555 -0
  167. package/src/tools/Chat/hooks/useChatAudio.ts +191 -0
  168. package/src/tools/Chat/hooks/useChatComposer.ts +227 -0
  169. package/src/tools/Chat/hooks/useChatHistory.ts +59 -0
  170. package/src/tools/Chat/hooks/useChatLayout.ts +111 -0
  171. package/src/tools/Chat/hooks/useChatLightbox.ts +34 -0
  172. package/src/tools/Chat/hooks/useChatScroll.ts +132 -0
  173. package/src/tools/Chat/index.ts +161 -0
  174. package/src/tools/Chat/lazy.tsx +14 -0
  175. package/src/tools/Chat/types.ts +237 -0
  176. package/src/tools/Chat/utils/collectImageAttachments.ts +13 -0
  177. package/src/tools/Map/README.md +384 -0
  178. package/dist/DocsLayout-CTJINVBM.mjs.map +0 -1
  179. package/dist/DocsLayout-XLDB6CJ2.cjs.map +0 -1
  180. package/dist/JsonSchemaForm-6WMS4CIY.cjs +0 -13
  181. package/dist/JsonSchemaForm-KX4JT3M4.mjs +0 -4
  182. package/dist/JsonTree-F27RMYSI.cjs +0 -11
  183. package/dist/JsonTree-QTJYSHCV.mjs +0 -5
  184. package/dist/Player-M3GC3VPE.mjs +0 -4
  185. package/dist/Player-ZL2X5LGG.cjs +0 -13
  186. package/dist/TreeRoot-A3J65L6F.mjs +0 -4
  187. package/dist/TreeRoot-DSK5JILT.cjs +0 -19
  188. package/dist/chunk-62Y65TGK.mjs.map +0 -1
  189. package/dist/chunk-TKSFZHCG.cjs +0 -1597
  190. package/dist/chunk-TKSFZHCG.cjs.map +0 -1
  191. package/dist/components-5UXYNAKR.cjs +0 -22
  192. package/dist/components-CFXOEVPN.mjs +0 -5
  193. package/dist/components-WYEZL5TE.cjs +0 -26
  194. package/dist/components-ZAGG2PBO.mjs +0 -5
@@ -0,0 +1,649 @@
1
+ 'use strict';
2
+
3
+ var chunkOLISEQHS_cjs = require('./chunk-OLISEQHS.cjs');
4
+ var React6 = require('react');
5
+ require('@djangocfg/ui-core/styles/palette');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+ var ReactMarkdown = require('react-markdown');
8
+ var rehypeExternalLinks = require('rehype-external-links');
9
+ var rehypeRaw = require('rehype-raw');
10
+ var rehypeSanitize = require('rehype-sanitize');
11
+ var remarkBreaks = require('remark-breaks');
12
+ var remarkEmoji = require('remark-emoji');
13
+ var remarkGfm = require('remark-gfm');
14
+ var remarkSmartypants = require('remark-smartypants');
15
+ var components = require('@djangocfg/ui-core/components');
16
+ var hooks = require('@djangocfg/ui-core/hooks');
17
+
18
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
+
20
+ var React6__default = /*#__PURE__*/_interopDefault(React6);
21
+ var ReactMarkdown__default = /*#__PURE__*/_interopDefault(ReactMarkdown);
22
+ var rehypeExternalLinks__default = /*#__PURE__*/_interopDefault(rehypeExternalLinks);
23
+ var rehypeRaw__default = /*#__PURE__*/_interopDefault(rehypeRaw);
24
+ var rehypeSanitize__default = /*#__PURE__*/_interopDefault(rehypeSanitize);
25
+ var remarkBreaks__default = /*#__PURE__*/_interopDefault(remarkBreaks);
26
+ var remarkEmoji__default = /*#__PURE__*/_interopDefault(remarkEmoji);
27
+ var remarkGfm__default = /*#__PURE__*/_interopDefault(remarkGfm);
28
+ var remarkSmartypants__default = /*#__PURE__*/_interopDefault(remarkSmartypants);
29
+
30
+ function smartTruncate(content, maxLength) {
31
+ if (content.length <= maxLength) {
32
+ return content;
33
+ }
34
+ let breakPoint = maxLength;
35
+ while (breakPoint > maxLength - 50 && breakPoint > 0) {
36
+ const char = content[breakPoint];
37
+ if (char === " " || char === "\n" || char === " ") {
38
+ break;
39
+ }
40
+ breakPoint--;
41
+ }
42
+ if (breakPoint <= maxLength - 50) {
43
+ breakPoint = maxLength;
44
+ }
45
+ let truncated = content.slice(0, breakPoint).trimEnd();
46
+ truncated = fixUnclosedMarkdown(truncated);
47
+ return truncated;
48
+ }
49
+ chunkOLISEQHS_cjs.__name(smartTruncate, "smartTruncate");
50
+ function truncateByLines(content, maxLines) {
51
+ const lines = content.split("\n");
52
+ if (lines.length <= maxLines) {
53
+ return content;
54
+ }
55
+ let truncated = lines.slice(0, maxLines).join("\n").trimEnd();
56
+ truncated = fixUnclosedMarkdown(truncated);
57
+ return truncated;
58
+ }
59
+ chunkOLISEQHS_cjs.__name(truncateByLines, "truncateByLines");
60
+ function fixUnclosedMarkdown(content) {
61
+ let result = content;
62
+ const countOccurrences = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((str, marker) => {
63
+ const escaped = marker.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
64
+ const matches = str.match(new RegExp(escaped, "g"));
65
+ return matches ? matches.length : 0;
66
+ }, "countOccurrences");
67
+ const boldCount = countOccurrences(result, "**");
68
+ if (boldCount % 2 !== 0) {
69
+ result += "**";
70
+ }
71
+ const withoutBold = result.replace(/\*\*/g, "");
72
+ const italicCount = countOccurrences(withoutBold, "*");
73
+ if (italicCount % 2 !== 0) {
74
+ result += "*";
75
+ }
76
+ const codeCount = countOccurrences(result, "`");
77
+ const tripleCount = countOccurrences(result, "```");
78
+ const singleCodeCount = codeCount - tripleCount * 3;
79
+ if (singleCodeCount % 2 !== 0) {
80
+ result += "`";
81
+ }
82
+ if (tripleCount % 2 !== 0) {
83
+ result += "\n```";
84
+ }
85
+ const strikeCount = countOccurrences(result, "~~");
86
+ if (strikeCount % 2 !== 0) {
87
+ result += "~~";
88
+ }
89
+ const underlineBoldCount = countOccurrences(result, "__");
90
+ if (underlineBoldCount % 2 !== 0) {
91
+ result += "__";
92
+ }
93
+ const withoutUnderlineBold = result.replace(/__/g, "");
94
+ const underlineItalicCount = countOccurrences(withoutUnderlineBold, "_");
95
+ if (underlineItalicCount % 2 !== 0) {
96
+ result += "_";
97
+ }
98
+ return result;
99
+ }
100
+ chunkOLISEQHS_cjs.__name(fixUnclosedMarkdown, "fixUnclosedMarkdown");
101
+ function useCollapsibleContent(content, options = {}) {
102
+ const { maxLength, maxLines, defaultExpanded = false } = options;
103
+ const [isCollapsed, setIsCollapsed] = React6.useState(!defaultExpanded);
104
+ const originalLength = content.length;
105
+ const originalLineCount = content.split("\n").length;
106
+ const { shouldCollapse, truncatedContent } = React6.useMemo(() => {
107
+ if (maxLength === void 0 && maxLines === void 0) {
108
+ return { shouldCollapse: false, truncatedContent: content };
109
+ }
110
+ let needsCollapse = false;
111
+ let result = content;
112
+ if (maxLines !== void 0 && originalLineCount > maxLines) {
113
+ needsCollapse = true;
114
+ result = truncateByLines(result, maxLines);
115
+ }
116
+ if (maxLength !== void 0 && result.length > maxLength) {
117
+ needsCollapse = true;
118
+ result = smartTruncate(result, maxLength);
119
+ }
120
+ return { shouldCollapse: needsCollapse, truncatedContent: result };
121
+ }, [content, maxLength, maxLines, originalLineCount]);
122
+ const displayContent = React6.useMemo(() => {
123
+ if (!shouldCollapse || !isCollapsed) {
124
+ return content;
125
+ }
126
+ return truncatedContent;
127
+ }, [content, truncatedContent, shouldCollapse, isCollapsed]);
128
+ const toggleCollapsed = React6.useCallback(() => {
129
+ setIsCollapsed((prev) => !prev);
130
+ }, []);
131
+ const setCollapsed = React6.useCallback((collapsed) => {
132
+ setIsCollapsed(collapsed);
133
+ }, []);
134
+ return {
135
+ isCollapsed,
136
+ toggleCollapsed,
137
+ setCollapsed,
138
+ displayContent,
139
+ shouldCollapse,
140
+ originalLength,
141
+ originalLineCount
142
+ };
143
+ }
144
+ chunkOLISEQHS_cjs.__name(useCollapsibleContent, "useCollapsibleContent");
145
+ function extractTextFromChildren(children) {
146
+ if (typeof children === "string") return children;
147
+ if (typeof children === "number") return String(children);
148
+ if (React6__default.default.isValidElement(children)) {
149
+ const props = children.props;
150
+ return extractTextFromChildren(props.children);
151
+ }
152
+ if (Array.isArray(children)) {
153
+ return children.map(extractTextFromChildren).join("");
154
+ }
155
+ return "";
156
+ }
157
+ chunkOLISEQHS_cjs.__name(extractTextFromChildren, "extractTextFromChildren");
158
+ function looksLikePlainProse(text) {
159
+ const trimmed = text.trim();
160
+ if (trimmed.length === 0) return true;
161
+ if (trimmed.length > 500) return false;
162
+ if (/\n\s*\n/.test(trimmed)) return false;
163
+ const newlineCount = (trimmed.match(/\n/g) || []).length;
164
+ if (newlineCount > 4) return false;
165
+ if (hasMarkdownSyntax(trimmed)) return false;
166
+ return true;
167
+ }
168
+ chunkOLISEQHS_cjs.__name(looksLikePlainProse, "looksLikePlainProse");
169
+ function hasMarkdownSyntax(text) {
170
+ if (text.trim().includes("\n")) return true;
171
+ if (/<\/?[a-zA-Z][a-zA-Z0-9-]*(\s[^>]*)?\/?>/.test(text)) return true;
172
+ const patterns = [
173
+ /^#{1,6}\s/m,
174
+ // Headers
175
+ /\*\*[^*]+\*\*/,
176
+ // Bold
177
+ /\*[^*]+\*/,
178
+ // Italic
179
+ /__[^_]+__/,
180
+ // Bold (underscore)
181
+ /_[^_]+_/,
182
+ // Italic (underscore)
183
+ /\[.+\]\(.+\)/,
184
+ // Links
185
+ /!\[.*\]\(.+\)/,
186
+ // Images
187
+ /```[\s\S]*```/,
188
+ // Code blocks
189
+ /`[^`]+`/,
190
+ // Inline code
191
+ /^\s*[-*+]\s/m,
192
+ // Unordered lists
193
+ /^\s*\d+\.\s/m,
194
+ // Ordered lists
195
+ /^\s*>/m,
196
+ // Blockquotes
197
+ /\|.+\|/,
198
+ // Tables
199
+ /^---+$/m,
200
+ // Horizontal rules
201
+ /~~[^~]+~~/
202
+ // Strikethrough
203
+ ];
204
+ return patterns.some((p) => p.test(text));
205
+ }
206
+ chunkOLISEQHS_cjs.__name(hasMarkdownSyntax, "hasMarkdownSyntax");
207
+ var MermaidClient = React6.lazy(() => import('./Mermaid.client-NNTI6DFX.cjs'));
208
+ var LoadingFallback = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center items-center min-h-[100px]", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-spin rounded-full h-6 w-6 border-b-2 border-primary" }) }), "LoadingFallback");
209
+ var Mermaid = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((props) => {
210
+ return /* @__PURE__ */ jsxRuntime.jsx(React6.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(LoadingFallback, {}), children: /* @__PURE__ */ jsxRuntime.jsx(MermaidClient, { ...props }) });
211
+ }, "Mermaid");
212
+ var Mermaid_default = Mermaid;
213
+ var PrettyCodeClient = React6.lazy(() => import('./PrettyCode.client-KOHDVPPN.cjs'));
214
+ var LoadingFallback2 = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative rounded-sm border border-border overflow-hidden bg-muted dark:bg-zinc-900", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
215
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-pulse h-4 w-4 rounded-full bg-muted-foreground/20" }),
216
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-muted-foreground", children: "Loading code..." })
217
+ ] }) }) }), "LoadingFallback");
218
+ var PrettyCode = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((props) => {
219
+ return /* @__PURE__ */ jsxRuntime.jsx(React6.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(LoadingFallback2, {}), children: /* @__PURE__ */ jsxRuntime.jsx(PrettyCodeClient, { ...props }) });
220
+ }, "PrettyCode");
221
+ var PrettyCode_default = PrettyCode;
222
+ var HTML_SCHEMA_BASE = {
223
+ ...rehypeSanitize.defaultSchema,
224
+ tagNames: [
225
+ ...rehypeSanitize.defaultSchema.tagNames ?? [],
226
+ "br",
227
+ "b",
228
+ "i",
229
+ "u",
230
+ "s",
231
+ "sub",
232
+ "sup",
233
+ "small",
234
+ "mark",
235
+ "kbd",
236
+ "code",
237
+ "pre",
238
+ "details",
239
+ "summary"
240
+ ]
241
+ };
242
+ function buildSchema(extraProtocols) {
243
+ if (!extraProtocols || extraProtocols.length === 0) return HTML_SCHEMA_BASE;
244
+ const baseProtocols = HTML_SCHEMA_BASE.protocols ?? rehypeSanitize.defaultSchema.protocols ?? {};
245
+ const baseHref = baseProtocols.href ?? ["http", "https", "mailto", "xmpp", "irc", "ircs"];
246
+ return {
247
+ ...HTML_SCHEMA_BASE,
248
+ protocols: {
249
+ ...baseProtocols,
250
+ href: [...baseHref, ...extraProtocols]
251
+ }
252
+ };
253
+ }
254
+ chunkOLISEQHS_cjs.__name(buildSchema, "buildSchema");
255
+ function buildUrlTransform(extraProtocols) {
256
+ if (!extraProtocols || extraProtocols.length === 0) return void 0;
257
+ const lower = extraProtocols.map((p) => p.toLowerCase() + ":");
258
+ return (url) => {
259
+ const u = url.trim().toLowerCase();
260
+ for (const p of lower) {
261
+ if (u.startsWith(p)) return url;
262
+ }
263
+ if (/^(https?:|mailto:|tel:|xmpp:|irc:|ircs:|#|\/|\.\/|\.\.\/|\?)/i.test(u) || /^[a-z0-9._~!$&'()*+,;=:@%-]+$/i.test(u)) {
264
+ return url;
265
+ }
266
+ return "";
267
+ };
268
+ }
269
+ chunkOLISEQHS_cjs.__name(buildUrlTransform, "buildUrlTransform");
270
+ var CodeBlock = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ code, language }) => {
271
+ const theme = hooks.useResolvedTheme();
272
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "my-2", children: /* @__PURE__ */ jsxRuntime.jsx(
273
+ PrettyCode_default,
274
+ {
275
+ data: code,
276
+ language,
277
+ className: "text-xs",
278
+ customBg: "bg-code",
279
+ mode: theme,
280
+ isCompact: true,
281
+ scrollIsolation: false
282
+ }
283
+ ) });
284
+ }, "CodeBlock");
285
+ var CodeBlockFallback = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ code, isUser }) => {
286
+ const copyHoverClass = isUser ? "hover:bg-white/20 text-white" : "hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground";
287
+ const copyButtonClass = `absolute top-2 right-2 z-10 opacity-0 group-hover:opacity-100 transition-opacity h-8 w-8 ${copyHoverClass}`;
288
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative group my-3", children: [
289
+ /* @__PURE__ */ jsxRuntime.jsx(
290
+ components.CopyButton,
291
+ {
292
+ value: code,
293
+ variant: "ghost",
294
+ className: copyButtonClass,
295
+ title: "Copy code"
296
+ }
297
+ ),
298
+ /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "p-3 rounded text-xs font-mono overflow-x-auto bg-code text-code-foreground border border-code-border", children: /* @__PURE__ */ jsxRuntime.jsx("code", { children: code }) })
299
+ ] });
300
+ }, "CodeBlockFallback");
301
+ function createMarkdownComponents(isUser = false, isCompact = false) {
302
+ const textSize = isCompact ? "text-xs" : "text-sm";
303
+ const headingBase = isCompact ? "text-sm" : "text-base";
304
+ const headingSm = isCompact ? "text-xs" : "text-sm";
305
+ return {
306
+ h1: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h1", { className: `${headingBase} font-semibold mb-2 mt-3 first:mt-0`, children }), "h1"),
307
+ h2: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h2", { className: `${headingSm} font-semibold mb-2 mt-3 first:mt-0`, children }), "h2"),
308
+ h3: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h3", { className: `${headingSm} font-semibold mb-1 mt-2 first:mt-0`, children }), "h3"),
309
+ h4: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h4", { className: `${headingSm} font-semibold mb-1 mt-2 first:mt-0`, children }), "h4"),
310
+ h5: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h5", { className: `${headingSm} font-medium mb-1 mt-2 first:mt-0`, children }), "h5"),
311
+ h6: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h6", { className: `${headingSm} font-medium mb-1 mt-2 first:mt-0`, children }), "h6"),
312
+ p: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("p", { className: `${textSize} mb-4 last:mb-0 leading-relaxed break-words`, children }), "p"),
313
+ ul: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("ul", { className: `list-disc list-inside mb-2 space-y-1 ${textSize}`, children }), "ul"),
314
+ ol: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("ol", { className: `list-decimal list-inside mb-2 space-y-1 ${textSize}`, children }), "ol"),
315
+ li: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "break-words", children }), "li"),
316
+ // `target` / `rel` for external links are NOT set here — the
317
+ // rehype-external-links plugin tags them on the rehype side, so
318
+ // every `<a>` that sanitize let through gets the same security
319
+ // treatment regardless of which renderer (default vs linkRules
320
+ // override) emitted it. Doing it twice here would just duplicate
321
+ // attributes; doing it only here would miss the linkRules path.
322
+ a: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ href, children, ...rest }) => /* @__PURE__ */ jsxRuntime.jsx(
323
+ "a",
324
+ {
325
+ ...rest,
326
+ href,
327
+ className: `${textSize} ${isUser ? "text-white/90 underline hover:text-white" : "text-primary underline hover:text-primary/80"} transition-colors break-all`,
328
+ children
329
+ }
330
+ ), "a"),
331
+ pre: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => {
332
+ let codeContent = "";
333
+ let language = "plaintext";
334
+ if (React6__default.default.isValidElement(children)) {
335
+ const child = children;
336
+ if (child.type === "code" || typeof child.type === "function" && child.type.name === "code") {
337
+ const codeProps = child.props;
338
+ const rawClassName = codeProps.className;
339
+ language = rawClassName?.replace(/language-/, "").trim() || "plaintext";
340
+ codeContent = extractTextFromChildren(codeProps.children).trim();
341
+ } else {
342
+ codeContent = extractTextFromChildren(children).trim();
343
+ }
344
+ } else {
345
+ codeContent = extractTextFromChildren(children).trim();
346
+ }
347
+ if (!codeContent) {
348
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "my-3 p-3 bg-muted rounded text-sm text-muted-foreground", children: "No content available" });
349
+ }
350
+ if (language === "mermaid") {
351
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "my-3 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(Mermaid_default, { chart: codeContent, isCompact }) });
352
+ }
353
+ try {
354
+ return /* @__PURE__ */ jsxRuntime.jsx(CodeBlock, { code: codeContent, language, isUser, isCompact });
355
+ } catch (error) {
356
+ console.warn("CodeBlock failed, using fallback:", error);
357
+ return /* @__PURE__ */ jsxRuntime.jsx(CodeBlockFallback, { code: codeContent, language, isUser, isCompact });
358
+ }
359
+ }, "pre"),
360
+ code: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children, className }) => {
361
+ if (className?.includes("language-")) {
362
+ return /* @__PURE__ */ jsxRuntime.jsx("code", { className, children });
363
+ }
364
+ const inlineCodeClass = isUser ? "bg-primary-foreground/15 text-primary-foreground" : "bg-code-inline text-code-inline-foreground";
365
+ return /* @__PURE__ */ jsxRuntime.jsx("code", { className: `px-1 py-0.5 rounded font-mono text-[0.875em] ${inlineCodeClass} break-all`, children: extractTextFromChildren(children) });
366
+ }, "code"),
367
+ // Modern chat convention drops italic on blockquotes — italic +
368
+ // tight bubble = hard to read. Border-left at 2px (4px reads
369
+ // heavy in a 320–480px bubble). On the saturated user bubble we
370
+ // use a primary-foreground tint; on the assistant bubble we use
371
+ // the muted-foreground role for de-emphasis.
372
+ blockquote: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => {
373
+ const cls = isUser ? "border-primary-foreground/40 text-primary-foreground/80" : "border-border text-muted-foreground";
374
+ return /* @__PURE__ */ jsxRuntime.jsx("blockquote", { className: `${textSize} border-l-2 pl-3 my-3 break-words ${cls}`, children });
375
+ }, "blockquote"),
376
+ // Tables: outer wrapper handles overflow, inner `<table>`
377
+ // inherits the chat-density text size. Borders / header use
378
+ // semantic tokens — `border-code-border` for the assistant
379
+ // (matches the code-fence panel for visual cohesion when both
380
+ // appear in the same reply); primary-foreground/N for the user
381
+ // bubble so lines read against the saturated `bg-primary`.
382
+ table: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-x-auto my-3", children: /* @__PURE__ */ jsxRuntime.jsx("table", { className: `min-w-full ${textSize} border-collapse`, children }) }), "table"),
383
+ thead: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("thead", { className: isUser ? "bg-primary-foreground/10" : "bg-muted/40", children }), "thead"),
384
+ tbody: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("tbody", { children }), "tbody"),
385
+ tr: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("tr", { className: isUser ? "border-b border-primary-foreground/15" : "border-b border-border", children }), "tr"),
386
+ th: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => {
387
+ const borderCls = isUser ? "border-primary-foreground/25" : "border-border";
388
+ return /* @__PURE__ */ jsxRuntime.jsx("th", { className: `px-2 py-1.5 text-left font-semibold border-b ${borderCls} break-words`, children });
389
+ }, "th"),
390
+ td: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-2 py-1.5 break-words", children }), "td"),
391
+ // Soft separator. ChatGPT / Slack / Linear strip the visible
392
+ // line, Claude.ai keeps a hairline. We follow Claude — present
393
+ // but quiet. Palette switches by role so the hairline reads on
394
+ // both surfaces.
395
+ hr: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => /* @__PURE__ */ jsxRuntime.jsx(
396
+ "hr",
397
+ {
398
+ className: `my-4 border-0 h-px ${isUser ? "bg-primary-foreground/20" : "bg-border"}`
399
+ }
400
+ ), "hr"),
401
+ strong: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("strong", { className: "font-semibold", children }), "strong"),
402
+ em: /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children }) => /* @__PURE__ */ jsxRuntime.jsx("em", { className: "italic", children }), "em")
403
+ };
404
+ }
405
+ chunkOLISEQHS_cjs.__name(createMarkdownComponents, "createMarkdownComponents");
406
+ var CollapseToggle = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({
407
+ isCollapsed,
408
+ onClick,
409
+ readMoreLabel,
410
+ showLessLabel,
411
+ isUser,
412
+ isCompact
413
+ }) => {
414
+ const textSize = isCompact ? "text-xs" : "text-sm";
415
+ return /* @__PURE__ */ jsxRuntime.jsx(
416
+ "button",
417
+ {
418
+ type: "button",
419
+ onClick,
420
+ className: `
421
+ ${textSize} font-medium cursor-pointer
422
+ transition-colors duration-200
423
+ ${isUser ? "text-white/80 hover:text-white" : "text-primary hover:text-primary/80"}
424
+ inline-flex items-center gap-1
425
+ mt-1
426
+ `,
427
+ children: isCollapsed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
428
+ readMoreLabel,
429
+ /* @__PURE__ */ jsxRuntime.jsx(Chevron, { direction: "down" })
430
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
431
+ showLessLabel,
432
+ /* @__PURE__ */ jsxRuntime.jsx(Chevron, { direction: "up" })
433
+ ] })
434
+ }
435
+ );
436
+ }, "CollapseToggle");
437
+ function Chevron({ direction }) {
438
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { className: "w-3 h-3", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsxRuntime.jsx(
439
+ "path",
440
+ {
441
+ strokeLinecap: "round",
442
+ strokeLinejoin: "round",
443
+ strokeWidth: 2,
444
+ d: direction === "down" ? "M19 9l-7 7-7-7" : "M5 15l7-7 7 7"
445
+ }
446
+ ) });
447
+ }
448
+ chunkOLISEQHS_cjs.__name(Chevron, "Chevron");
449
+ function applyPreprocess(source, rules) {
450
+ if (!rules || rules.length === 0) return source;
451
+ let s = source;
452
+ for (const rule of rules) {
453
+ if (!rule.preprocess) continue;
454
+ try {
455
+ s = rule.preprocess(s);
456
+ } catch (err) {
457
+ console.warn(
458
+ `[MarkdownMessage] linkRule "${rule.name ?? "(anonymous)"}" preprocess threw; skipping`,
459
+ err
460
+ );
461
+ }
462
+ }
463
+ return s;
464
+ }
465
+ chunkOLISEQHS_cjs.__name(applyPreprocess, "applyPreprocess");
466
+ function collectProtocols(extraHrefProtocols, rules) {
467
+ const set = /* @__PURE__ */ new Set();
468
+ if (extraHrefProtocols) for (const p of extraHrefProtocols) set.add(p);
469
+ if (rules) {
470
+ for (const r of rules) {
471
+ if (r.protocols) for (const p of r.protocols) set.add(p);
472
+ }
473
+ }
474
+ return set.size === 0 ? void 0 : Array.from(set);
475
+ }
476
+ chunkOLISEQHS_cjs.__name(collectProtocols, "collectProtocols");
477
+ function buildLinkRulesComponent(rules, isUser, callerA) {
478
+ const Renderer = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((props) => {
479
+ const { href, children } = props;
480
+ if (typeof href === "string") {
481
+ for (const rule of rules) {
482
+ if (rule.match(href)) {
483
+ return React6__default.default.createElement(
484
+ React6__default.default.Fragment,
485
+ null,
486
+ rule.render({ href, children, isUser })
487
+ );
488
+ }
489
+ }
490
+ }
491
+ if (callerA && typeof callerA === "function") {
492
+ const Caller = callerA;
493
+ return React6__default.default.createElement(Caller, props);
494
+ }
495
+ return React6__default.default.createElement("a", props, children);
496
+ }, "Renderer");
497
+ return Renderer;
498
+ }
499
+ chunkOLISEQHS_cjs.__name(buildLinkRulesComponent, "buildLinkRulesComponent");
500
+ var MarkdownMessage = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({
501
+ content,
502
+ className = "",
503
+ isUser = false,
504
+ isCompact = false,
505
+ plainText,
506
+ customComponents,
507
+ extraHrefProtocols,
508
+ linkRules,
509
+ collapsible = false,
510
+ maxLength,
511
+ maxLines,
512
+ readMoreLabel = "Read more...",
513
+ showLessLabel = "Show less",
514
+ defaultExpanded = false,
515
+ onCollapseChange
516
+ }) => {
517
+ const preprocessed = React6__default.default.useMemo(
518
+ () => applyPreprocess(content, linkRules),
519
+ [content, linkRules]
520
+ );
521
+ const effectiveProtocols = React6__default.default.useMemo(
522
+ () => collectProtocols(extraHrefProtocols, linkRules),
523
+ [extraHrefProtocols, linkRules]
524
+ );
525
+ const effectiveCustomComponents = React6__default.default.useMemo(() => {
526
+ if (!linkRules || linkRules.length === 0) return customComponents;
527
+ const callerA = customComponents?.a;
528
+ const aRenderer = buildLinkRulesComponent(linkRules, isUser, callerA);
529
+ return { ...customComponents ?? {}, a: aRenderer };
530
+ }, [customComponents, linkRules, isUser]);
531
+ const trimmedContent = preprocessed.trim();
532
+ const collapsibleOptions = React6__default.default.useMemo(() => {
533
+ if (!collapsible) return {};
534
+ return {
535
+ maxLength: maxLength ?? 1e3,
536
+ maxLines: maxLines ?? 10,
537
+ defaultExpanded
538
+ };
539
+ }, [collapsible, maxLength, maxLines, defaultExpanded]);
540
+ const { isCollapsed, toggleCollapsed, displayContent, shouldCollapse } = useCollapsibleContent(trimmedContent, collapsible ? collapsibleOptions : {});
541
+ React6__default.default.useEffect(() => {
542
+ if (collapsible && shouldCollapse && onCollapseChange) {
543
+ onCollapseChange(isCollapsed);
544
+ }
545
+ }, [isCollapsed, collapsible, shouldCollapse, onCollapseChange]);
546
+ const components = React6__default.default.useMemo(() => {
547
+ const base = createMarkdownComponents(isUser, isCompact);
548
+ return effectiveCustomComponents ? { ...base, ...effectiveCustomComponents } : base;
549
+ }, [isUser, isCompact, effectiveCustomComponents]);
550
+ const schema = React6__default.default.useMemo(() => buildSchema(effectiveProtocols), [effectiveProtocols]);
551
+ const urlTransform = React6__default.default.useMemo(
552
+ () => buildUrlTransform(effectiveProtocols),
553
+ [effectiveProtocols]
554
+ );
555
+ const textSizeClass = isCompact ? "text-xs" : "text-sm";
556
+ const proseClass = isCompact ? "prose-xs" : "prose-sm";
557
+ const customComponentsBeyondLinks = React6__default.default.useMemo(() => {
558
+ if (!customComponents) return false;
559
+ return Object.keys(customComponents).some((k) => k !== "a");
560
+ }, [customComponents]);
561
+ const isPlainText = plainText !== void 0 ? plainText : !customComponentsBeyondLinks && looksLikePlainProse(displayContent);
562
+ if (isPlainText) {
563
+ return /* @__PURE__ */ jsxRuntime.jsxs(
564
+ "div",
565
+ {
566
+ className: `${textSizeClass} font-normal antialiased leading-snug break-words whitespace-pre-wrap ${className}`,
567
+ children: [
568
+ displayContent,
569
+ collapsible && shouldCollapse && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
570
+ isCollapsed && "... ",
571
+ /* @__PURE__ */ jsxRuntime.jsx(
572
+ CollapseToggle,
573
+ {
574
+ isCollapsed,
575
+ onClick: toggleCollapsed,
576
+ readMoreLabel,
577
+ showLessLabel,
578
+ isUser,
579
+ isCompact
580
+ }
581
+ )
582
+ ] })
583
+ ]
584
+ }
585
+ );
586
+ }
587
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
588
+ /* @__PURE__ */ jsxRuntime.jsx(
589
+ "div",
590
+ {
591
+ className: `
592
+ prose ${proseClass} max-w-none break-words overflow-hidden ${textSizeClass} font-normal antialiased
593
+ ${isUser ? "prose-invert" : "dark:prose-invert"}
594
+ [&>*]:leading-relaxed
595
+ [&>*:first-child]:mt-0 [&>*:last-child]:mb-0
596
+ [&_p]:my-2
597
+ [&_ul]:my-2 [&_ol]:my-2 [&_ul]:pl-5 [&_ol]:pl-5
598
+ [&_li]:my-1 [&_li>p]:my-0
599
+ [&_h1]:mt-4 [&_h1]:mb-2 [&_h1]:text-base [&_h1]:font-semibold
600
+ [&_h2]:mt-3.5 [&_h2]:mb-1.5 [&_h2]:text-[15px] [&_h2]:font-semibold
601
+ [&_h3]:mt-3 [&_h3]:mb-1 [&_h3]:text-sm [&_h3]:font-medium
602
+ [&_h4]:mt-3 [&_h4]:mb-1 [&_h4]:text-sm [&_h4]:font-medium
603
+ `,
604
+ style: {
605
+ // Inherit colors from parent — fixes issues with external
606
+ // CSS variables overriding prose tokens.
607
+ "--tw-prose-body": "inherit",
608
+ "--tw-prose-headings": "inherit",
609
+ "--tw-prose-bold": "inherit",
610
+ "--tw-prose-links": "inherit",
611
+ color: "inherit"
612
+ },
613
+ children: /* @__PURE__ */ jsxRuntime.jsx(
614
+ ReactMarkdown__default.default,
615
+ {
616
+ remarkPlugins: [remarkGfm__default.default, remarkBreaks__default.default, remarkSmartypants__default.default, remarkEmoji__default.default],
617
+ rehypePlugins: [
618
+ rehypeRaw__default.default,
619
+ [rehypeSanitize__default.default, schema],
620
+ [rehypeExternalLinks__default.default, { target: "_blank", rel: ["noopener", "noreferrer"] }]
621
+ ],
622
+ components,
623
+ urlTransform,
624
+ children: displayContent
625
+ }
626
+ )
627
+ }
628
+ ),
629
+ collapsible && shouldCollapse && /* @__PURE__ */ jsxRuntime.jsx(
630
+ CollapseToggle,
631
+ {
632
+ isCollapsed,
633
+ onClick: toggleCollapsed,
634
+ readMoreLabel,
635
+ showLessLabel,
636
+ isUser,
637
+ isCompact
638
+ }
639
+ )
640
+ ] });
641
+ }, "MarkdownMessage");
642
+
643
+ exports.MarkdownMessage = MarkdownMessage;
644
+ exports.Mermaid_default = Mermaid_default;
645
+ exports.PrettyCode_default = PrettyCode_default;
646
+ exports.extractTextFromChildren = extractTextFromChildren;
647
+ exports.useCollapsibleContent = useCollapsibleContent;
648
+ //# sourceMappingURL=chunk-B5AWZOHJ.cjs.map
649
+ //# sourceMappingURL=chunk-B5AWZOHJ.cjs.map