@flamingo-stack/openframe-frontend-core 0.0.497 → 0.0.498-1506.4000.1

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 (285) hide show
  1. package/dist/chat-protocol/decode.d.ts +58 -0
  2. package/dist/chat-protocol/decode.d.ts.map +1 -0
  3. package/dist/chat-protocol/encode.d.ts +44 -0
  4. package/dist/chat-protocol/encode.d.ts.map +1 -0
  5. package/dist/chat-protocol/env-flag.d.ts +35 -0
  6. package/dist/chat-protocol/env-flag.d.ts.map +1 -0
  7. package/dist/chat-protocol/events.d.ts +207 -0
  8. package/dist/chat-protocol/events.d.ts.map +1 -0
  9. package/dist/chat-protocol/frames.d.ts +213 -0
  10. package/dist/chat-protocol/frames.d.ts.map +1 -0
  11. package/dist/chat-protocol/index.cjs +500 -0
  12. package/dist/chat-protocol/index.cjs.map +1 -0
  13. package/dist/chat-protocol/index.d.ts +18 -0
  14. package/dist/chat-protocol/index.d.ts.map +1 -0
  15. package/dist/chat-protocol/index.js +484 -0
  16. package/dist/chat-protocol/index.js.map +1 -0
  17. package/dist/chat-protocol/ip-normalize.d.ts +44 -0
  18. package/dist/chat-protocol/ip-normalize.d.ts.map +1 -0
  19. package/dist/chat-protocol/nats-decoder.d.ts +26 -0
  20. package/dist/chat-protocol/nats-decoder.d.ts.map +1 -0
  21. package/dist/{chunk-2DER2JSI.cjs → chunk-242K7LZY.cjs} +11 -11
  22. package/dist/{chunk-2DER2JSI.cjs.map → chunk-242K7LZY.cjs.map} +1 -1
  23. package/dist/{chunk-VBSS4TPV.cjs → chunk-2LYA3RBT.cjs} +37 -37
  24. package/dist/{chunk-VBSS4TPV.cjs.map → chunk-2LYA3RBT.cjs.map} +1 -1
  25. package/dist/{chunk-ZPUCCSYA.js → chunk-34C2JV2C.js} +2 -2
  26. package/dist/{chunk-GWVNRXJU.js → chunk-3VGRZ62V.js} +2 -2
  27. package/dist/{chunk-AAHAVML2.js → chunk-42NYDEHH.js} +2 -2
  28. package/dist/{chunk-ZEHA4IC7.js → chunk-42SMPKGY.js} +2 -2
  29. package/dist/{chunk-RTG5DJWM.cjs → chunk-44C23SSC.cjs} +5 -5
  30. package/dist/{chunk-RTG5DJWM.cjs.map → chunk-44C23SSC.cjs.map} +1 -1
  31. package/dist/{chunk-SL62IZ3I.cjs → chunk-4KKGHPNE.cjs} +9 -9
  32. package/dist/{chunk-SL62IZ3I.cjs.map → chunk-4KKGHPNE.cjs.map} +1 -1
  33. package/dist/{chunk-X2CYUCGL.cjs → chunk-5BQWVNRS.cjs} +62 -62
  34. package/dist/{chunk-X2CYUCGL.cjs.map → chunk-5BQWVNRS.cjs.map} +1 -1
  35. package/dist/{chunk-HRUXC3YN.js → chunk-5QWYIPMH.js} +2 -2
  36. package/dist/{chunk-NT3BKPEC.js → chunk-5ZY5JM4Z.js} +10 -10
  37. package/dist/chunk-5ZY5JM4Z.js.map +1 -0
  38. package/dist/{chunk-4C764VBX.cjs → chunk-62TM2RVZ.cjs} +26 -26
  39. package/dist/{chunk-4C764VBX.cjs.map → chunk-62TM2RVZ.cjs.map} +1 -1
  40. package/dist/{chunk-YBTYHIXA.js → chunk-632XJ2ZT.js} +6 -5
  41. package/dist/chunk-632XJ2ZT.js.map +1 -0
  42. package/dist/{chunk-DGDUOFNY.js → chunk-BUBQEZ5J.js} +2 -2
  43. package/dist/{chunk-ZAAIVSX6.js → chunk-D3LUKR2Y.js} +11964 -9714
  44. package/dist/chunk-D3LUKR2Y.js.map +1 -0
  45. package/dist/{chunk-5KSXMJXF.cjs → chunk-EO35UHFT.cjs} +60 -60
  46. package/dist/chunk-EO35UHFT.cjs.map +1 -0
  47. package/dist/{chunk-5YKUEZIA.cjs → chunk-EORFD5WB.cjs} +15 -15
  48. package/dist/{chunk-5YKUEZIA.cjs.map → chunk-EORFD5WB.cjs.map} +1 -1
  49. package/dist/{chunk-MEIMDHQ2.cjs → chunk-F7XPMG25.cjs} +28 -27
  50. package/dist/chunk-F7XPMG25.cjs.map +1 -0
  51. package/dist/{chunk-I74ADMZS.cjs → chunk-H6GFQ4AO.cjs} +7 -7
  52. package/dist/{chunk-I74ADMZS.cjs.map → chunk-H6GFQ4AO.cjs.map} +1 -1
  53. package/dist/{chunk-EOYFMWDT.cjs → chunk-J3NHQ4JB.cjs} +31 -31
  54. package/dist/{chunk-EOYFMWDT.cjs.map → chunk-J3NHQ4JB.cjs.map} +1 -1
  55. package/dist/{chunk-23QJPSZJ.cjs → chunk-SS3D3DHL.cjs} +7049 -4799
  56. package/dist/chunk-SS3D3DHL.cjs.map +1 -0
  57. package/dist/{chunk-6XQGPFIR.js → chunk-WNXIG6YY.js} +2 -2
  58. package/dist/{chunk-5INZDVGI.js → chunk-WZCQW4MW.js} +4 -4
  59. package/dist/{chunk-B3MRHZNZ.js → chunk-ZHC2BCXK.js} +4 -4
  60. package/dist/components/case-studies/index.cjs +8 -8
  61. package/dist/components/case-studies/index.js +2 -2
  62. package/dist/components/chat/chat-message-enhanced.d.ts.map +1 -1
  63. package/dist/components/chat/chat-message-list.d.ts.map +1 -1
  64. package/dist/components/chat/hooks/index.d.ts +0 -1
  65. package/dist/components/chat/hooks/index.d.ts.map +1 -1
  66. package/dist/components/chat/hooks/use-chat.d.ts.map +1 -1
  67. package/dist/components/chat/hooks/use-chunk-catchup.d.ts.map +1 -1
  68. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts +15 -48
  69. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts.map +1 -1
  70. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts +10 -57
  71. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
  72. package/dist/components/chat/index.cjs +10 -2
  73. package/dist/components/chat/index.cjs.map +1 -1
  74. package/dist/components/chat/index.d.ts +1 -0
  75. package/dist/components/chat/index.d.ts.map +1 -1
  76. package/dist/components/chat/index.js +21 -13
  77. package/dist/components/chat/stream/chat-dialog-store.d.ts +184 -0
  78. package/dist/components/chat/stream/chat-dialog-store.d.ts.map +1 -0
  79. package/dist/components/chat/stream/chat-stream-reducer.d.ts +367 -0
  80. package/dist/components/chat/stream/chat-stream-reducer.d.ts.map +1 -0
  81. package/dist/components/chat/stream/delta-batcher.d.ts +51 -0
  82. package/dist/components/chat/stream/delta-batcher.d.ts.map +1 -0
  83. package/dist/components/chat/stream/index.d.ts +17 -0
  84. package/dist/components/chat/stream/index.d.ts.map +1 -0
  85. package/dist/components/chat/stream/message-mutations.d.ts +77 -0
  86. package/dist/components/chat/stream/message-mutations.d.ts.map +1 -0
  87. package/dist/components/chat/stream/use-chat-stream-reducer.d.ts +22 -0
  88. package/dist/components/chat/stream/use-chat-stream-reducer.d.ts.map +1 -0
  89. package/dist/components/chat/types/api.types.d.ts +1 -81
  90. package/dist/components/chat/types/api.types.d.ts.map +1 -1
  91. package/dist/components/chat/types/processing.types.d.ts +2 -93
  92. package/dist/components/chat/types/processing.types.d.ts.map +1 -1
  93. package/dist/components/chat/utils/extract-incomplete-message-state.d.ts +34 -6
  94. package/dist/components/chat/utils/extract-incomplete-message-state.d.ts.map +1 -1
  95. package/dist/components/chat/utils/index.d.ts +2 -3
  96. package/dist/components/chat/utils/index.d.ts.map +1 -1
  97. package/dist/components/chat/utils/process-historical-messages.d.ts +59 -11
  98. package/dist/components/chat/utils/process-historical-messages.d.ts.map +1 -1
  99. package/dist/components/contact/index.cjs +3 -3
  100. package/dist/components/contact/index.js +2 -2
  101. package/dist/components/docs/index.cjs +5 -5
  102. package/dist/components/docs/index.js +4 -4
  103. package/dist/components/embeds/index.cjs +3 -3
  104. package/dist/components/embeds/index.js +2 -2
  105. package/dist/components/faq/index.cjs +3 -3
  106. package/dist/components/faq/index.js +2 -2
  107. package/dist/components/features/index.cjs +2 -2
  108. package/dist/components/features/index.js +1 -1
  109. package/dist/components/help-center-pages/index.cjs +20 -20
  110. package/dist/components/help-center-pages/index.js +11 -11
  111. package/dist/components/index.cjs +172 -130
  112. package/dist/components/index.cjs.map +1 -1
  113. package/dist/components/index.js +63 -21
  114. package/dist/components/index.js.map +1 -1
  115. package/dist/components/navigation/index.cjs +2 -2
  116. package/dist/components/navigation/index.js +1 -1
  117. package/dist/components/onboarding-guides/index.cjs +5 -5
  118. package/dist/components/onboarding-guides/index.js +4 -4
  119. package/dist/components/onboarding-guides/onboarding-guide-detail-view.d.ts.map +1 -1
  120. package/dist/components/related-content/index.cjs +3 -3
  121. package/dist/components/related-content/index.js +2 -2
  122. package/dist/components/shared/product-release/release-detail-page.d.ts.map +1 -1
  123. package/dist/components/tickets/index.cjs +5 -5
  124. package/dist/components/tickets/index.js +4 -4
  125. package/dist/components/ui/index.cjs +44 -2
  126. package/dist/components/ui/index.cjs.map +1 -1
  127. package/dist/components/ui/index.d.ts +1 -2
  128. package/dist/components/ui/index.d.ts.map +1 -1
  129. package/dist/components/ui/index.js +55 -13
  130. package/dist/components/ui/markdown/base-components.d.ts +51 -0
  131. package/dist/components/ui/markdown/base-components.d.ts.map +1 -0
  132. package/dist/components/ui/markdown/engine.d.ts +99 -0
  133. package/dist/components/ui/markdown/engine.d.ts.map +1 -0
  134. package/dist/components/ui/markdown/heading-ids.d.ts +65 -0
  135. package/dist/components/ui/markdown/heading-ids.d.ts.map +1 -0
  136. package/dist/components/ui/markdown/index.d.ts +18 -0
  137. package/dist/components/ui/markdown/index.d.ts.map +1 -0
  138. package/dist/components/ui/markdown/mermaid-diagram.d.ts +79 -0
  139. package/dist/components/ui/markdown/mermaid-diagram.d.ts.map +1 -0
  140. package/dist/components/ui/markdown/rich/embed-overrides.d.ts +14 -0
  141. package/dist/components/ui/markdown/rich/embed-overrides.d.ts.map +1 -0
  142. package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts +40 -0
  143. package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts.map +1 -0
  144. package/dist/components/ui/markdown/rich/shortcodes.d.ts +8 -0
  145. package/dist/components/ui/markdown/rich/shortcodes.d.ts.map +1 -0
  146. package/dist/components/ui/markdown/sanitize.d.ts +153 -0
  147. package/dist/components/ui/markdown/sanitize.d.ts.map +1 -0
  148. package/dist/components/ui/markdown/simple-markdown-renderer.d.ts +23 -0
  149. package/dist/components/ui/markdown/simple-markdown-renderer.d.ts.map +1 -0
  150. package/dist/components/ui/markdown/streaming.d.ts +78 -0
  151. package/dist/components/ui/markdown/streaming.d.ts.map +1 -0
  152. package/dist/components/ui/markdown/text-size.d.ts +34 -0
  153. package/dist/components/ui/markdown/text-size.d.ts.map +1 -0
  154. package/dist/index.cjs +60 -2
  155. package/dist/index.cjs.map +1 -1
  156. package/dist/index.js +71 -13
  157. package/dist/utils/index.cjs +169 -40
  158. package/dist/utils/index.cjs.map +1 -1
  159. package/dist/utils/index.d.ts +1 -0
  160. package/dist/utils/index.d.ts.map +1 -1
  161. package/dist/utils/index.js +162 -41
  162. package/dist/utils/index.js.map +1 -1
  163. package/dist/utils/markdown-fences.d.ts +42 -0
  164. package/dist/utils/markdown-fences.d.ts.map +1 -0
  165. package/dist/utils/markdown-heading-id.d.ts +85 -0
  166. package/dist/utils/markdown-heading-id.d.ts.map +1 -0
  167. package/dist/utils/markdown-section-extractor.d.ts.map +1 -1
  168. package/package.json +7 -1
  169. package/src/chat-protocol/__tests__/__snapshots__/nats-decoder-golden.test.ts.snap +317 -0
  170. package/src/chat-protocol/__tests__/chat-protocol.test.ts +516 -0
  171. package/src/chat-protocol/__tests__/env-flag.test.ts +52 -0
  172. package/src/chat-protocol/__tests__/ip-normalize.test.ts +136 -0
  173. package/src/chat-protocol/__tests__/nats-decoder-golden.test.ts +232 -0
  174. package/src/chat-protocol/decode.ts +278 -0
  175. package/src/chat-protocol/encode.ts +71 -0
  176. package/src/chat-protocol/env-flag.ts +39 -0
  177. package/src/chat-protocol/events.ts +245 -0
  178. package/src/chat-protocol/frames.ts +245 -0
  179. package/src/chat-protocol/index.ts +21 -0
  180. package/src/chat-protocol/ip-normalize.ts +146 -0
  181. package/src/chat-protocol/nats-decoder.ts +258 -0
  182. package/src/components/chat/__tests__/chat-message-list.test.tsx +381 -6
  183. package/src/components/chat/__tests__/chat-message-streaming-memo.test.tsx +207 -0
  184. package/src/components/chat/__tests__/chat-pending-turn.test.tsx +250 -0
  185. package/src/components/chat/chat-message-enhanced.tsx +122 -20
  186. package/src/components/chat/chat-message-list.tsx +409 -132
  187. package/src/components/chat/embeddable-chat.tsx +6 -0
  188. package/src/components/chat/hooks/.index.md +30 -33
  189. package/src/components/chat/hooks/.use-nats-chat-adapter.md +36 -55
  190. package/src/components/chat/hooks/__tests__/__snapshots__/conversation-id-persistence-golden.test.ts.snap +37 -0
  191. package/src/components/chat/hooks/__tests__/__snapshots__/sse-stream-golden.test.ts.snap +0 -0
  192. package/src/components/chat/hooks/__tests__/chunk-catchup-dialog-staleness.test.ts +92 -0
  193. package/src/components/chat/hooks/__tests__/conversation-id-persistence-golden.test.ts +438 -0
  194. package/src/components/chat/hooks/__tests__/sse-stream-golden.test.ts +318 -0
  195. package/src/components/chat/hooks/index.ts +0 -1
  196. package/src/components/chat/hooks/use-chat.ts +8 -0
  197. package/src/components/chat/hooks/use-chunk-catchup.ts +26 -1
  198. package/src/components/chat/hooks/use-nats-chat-adapter.ts +254 -825
  199. package/src/components/chat/hooks/use-sse-chat-adapter.ts +380 -684
  200. package/src/components/chat/index.ts +5 -0
  201. package/src/components/chat/stream/__tests__/__snapshots__/chat-stream-reducer-golden.test.ts.snap +940 -0
  202. package/src/components/chat/stream/__tests__/chat-dialog-store.test.ts +806 -0
  203. package/src/components/chat/stream/__tests__/chat-stream-reducer-golden.test.ts +467 -0
  204. package/src/components/chat/stream/__tests__/chat-stream-reducer.test.ts +1248 -0
  205. package/src/components/chat/stream/__tests__/delta-batcher.test.ts +255 -0
  206. package/src/components/chat/stream/__tests__/use-chat-stream-reducer.test.ts +105 -0
  207. package/src/components/chat/stream/chat-dialog-store.ts +536 -0
  208. package/src/components/chat/stream/chat-stream-reducer.ts +1876 -0
  209. package/src/components/chat/stream/delta-batcher.ts +168 -0
  210. package/src/components/chat/stream/index.ts +55 -0
  211. package/src/components/chat/stream/message-mutations.ts +340 -0
  212. package/src/components/chat/stream/use-chat-stream-reducer.ts +126 -0
  213. package/src/components/chat/thinking-display.tsx +1 -1
  214. package/src/components/chat/types/.api.types.md +39 -49
  215. package/src/components/chat/types/.processing.types.md +29 -58
  216. package/src/components/chat/types/api.types.ts +6 -73
  217. package/src/components/chat/types/processing.types.ts +11 -53
  218. package/src/components/chat/utils/.index.md +31 -40
  219. package/src/components/chat/utils/__tests__/__snapshots__/process-historical-messages-golden.test.ts.snap +420 -0
  220. package/src/components/chat/utils/__tests__/__snapshots__/segment-accumulator-golden.test.ts.snap +605 -0
  221. package/src/components/chat/utils/__tests__/process-historical-messages-approvals.test.ts +61 -0
  222. package/src/components/chat/utils/__tests__/process-historical-messages-golden.test.ts +394 -0
  223. package/src/components/chat/utils/__tests__/segment-accumulator-golden.test.ts +270 -0
  224. package/src/components/chat/utils/extract-incomplete-message-state.ts +63 -5
  225. package/src/components/chat/utils/index.ts +5 -8
  226. package/src/components/chat/utils/process-historical-messages.ts +358 -386
  227. package/src/components/onboarding-guides/onboarding-guide-detail-view.tsx +22 -4
  228. package/src/components/shared/legal-document/legal-document-page.tsx +1 -1
  229. package/src/components/shared/product-release/release-detail-page.tsx +19 -4
  230. package/src/components/ui/__tests__/__snapshots__/markdown-parity.test.tsx.snap +2420 -0
  231. package/src/components/ui/__tests__/markdown-parity.test.tsx +2540 -0
  232. package/src/components/ui/index.ts +1 -2
  233. package/src/components/ui/markdown/__tests__/mermaid-security.test.ts +176 -0
  234. package/src/components/ui/markdown/__tests__/mermaid-stale-render.test.tsx +151 -0
  235. package/src/components/ui/markdown/__tests__/sanitize-invariant.test.ts +354 -0
  236. package/src/components/ui/markdown/__tests__/sanitize-render.test.tsx +118 -0
  237. package/src/components/ui/markdown/__tests__/streaming.test.tsx +436 -0
  238. package/src/components/ui/markdown/base-components.tsx +360 -0
  239. package/src/components/ui/markdown/engine.tsx +315 -0
  240. package/src/components/ui/markdown/heading-ids.ts +239 -0
  241. package/src/components/ui/markdown/index.ts +49 -0
  242. package/src/components/ui/markdown/mermaid-diagram.tsx +323 -0
  243. package/src/components/ui/markdown/rich/embed-overrides.tsx +199 -0
  244. package/src/components/ui/markdown/rich/rich-markdown-renderer.tsx +184 -0
  245. package/src/components/ui/markdown/rich/shortcodes.ts +170 -0
  246. package/src/components/ui/markdown/sanitize.ts +3584 -0
  247. package/src/components/ui/markdown/simple-markdown-renderer.tsx +28 -0
  248. package/src/components/ui/markdown/streaming.ts +390 -0
  249. package/src/components/ui/markdown/text-size.ts +106 -0
  250. package/src/components/ui/release-changelog-section.tsx +1 -1
  251. package/src/components/ui/ticket-info-section.tsx +1 -1
  252. package/src/utils/index.ts +1 -0
  253. package/src/utils/markdown-fences.ts +127 -0
  254. package/src/utils/markdown-heading-id.ts +348 -0
  255. package/src/utils/markdown-section-extractor.ts +41 -56
  256. package/dist/chunk-23QJPSZJ.cjs.map +0 -1
  257. package/dist/chunk-5KSXMJXF.cjs.map +0 -1
  258. package/dist/chunk-MEIMDHQ2.cjs.map +0 -1
  259. package/dist/chunk-NT3BKPEC.js.map +0 -1
  260. package/dist/chunk-YBTYHIXA.js.map +0 -1
  261. package/dist/chunk-ZAAIVSX6.js.map +0 -1
  262. package/dist/components/chat/hooks/use-realtime-chunk-processor.d.ts +0 -6
  263. package/dist/components/chat/hooks/use-realtime-chunk-processor.d.ts.map +0 -1
  264. package/dist/components/chat/utils/chunk-parser.d.ts +0 -25
  265. package/dist/components/chat/utils/chunk-parser.d.ts.map +0 -1
  266. package/dist/components/ui/rich-markdown-renderer.d.ts +0 -34
  267. package/dist/components/ui/rich-markdown-renderer.d.ts.map +0 -1
  268. package/dist/components/ui/simple-markdown-renderer.d.ts +0 -73
  269. package/dist/components/ui/simple-markdown-renderer.d.ts.map +0 -1
  270. package/src/components/chat/hooks/.use-realtime-chunk-processor.md +0 -77
  271. package/src/components/chat/hooks/use-realtime-chunk-processor.ts +0 -489
  272. package/src/components/chat/utils/.chunk-parser.md +0 -62
  273. package/src/components/chat/utils/chunk-parser.ts +0 -262
  274. package/src/components/ui/.simple-markdown-renderer.md +0 -52
  275. package/src/components/ui/rich-markdown-renderer.tsx +0 -1223
  276. package/src/components/ui/simple-markdown-renderer.tsx +0 -964
  277. /package/dist/{chunk-ZPUCCSYA.js.map → chunk-34C2JV2C.js.map} +0 -0
  278. /package/dist/{chunk-GWVNRXJU.js.map → chunk-3VGRZ62V.js.map} +0 -0
  279. /package/dist/{chunk-AAHAVML2.js.map → chunk-42NYDEHH.js.map} +0 -0
  280. /package/dist/{chunk-ZEHA4IC7.js.map → chunk-42SMPKGY.js.map} +0 -0
  281. /package/dist/{chunk-HRUXC3YN.js.map → chunk-5QWYIPMH.js.map} +0 -0
  282. /package/dist/{chunk-DGDUOFNY.js.map → chunk-BUBQEZ5J.js.map} +0 -0
  283. /package/dist/{chunk-6XQGPFIR.js.map → chunk-WNXIG6YY.js.map} +0 -0
  284. /package/dist/{chunk-5INZDVGI.js.map → chunk-WZCQW4MW.js.map} +0 -0
  285. /package/dist/{chunk-B3MRHZNZ.js.map → chunk-ZHC2BCXK.js.map} +0 -0
@@ -0,0 +1,500 @@
1
+ 'use strict';
2
+
3
+ // src/chat-protocol/frames.ts
4
+ var FRAME_TERMINATOR = "\0";
5
+ var END_OF_LEADING = "";
6
+ var TRAILER_SENTINEL = "";
7
+
8
+ // src/chat-protocol/events.ts
9
+ var CHAT_OWNER_ADMIN = "ADMIN";
10
+
11
+ // src/chat-protocol/encode.ts
12
+ var encoder = new TextEncoder();
13
+ var SENTINEL_BYTES_RE = /[\u0000\u001E\u001F]/g;
14
+ function stripSentinelBytes(text) {
15
+ return text.replace(SENTINEL_BYTES_RE, "");
16
+ }
17
+ function encodeLeadingFrame(frame) {
18
+ return encoder.encode(JSON.stringify(frame) + FRAME_TERMINATOR);
19
+ }
20
+ function encodeEndOfLeading() {
21
+ return encoder.encode(END_OF_LEADING);
22
+ }
23
+ function encodeTextDelta(text) {
24
+ return encoder.encode(stripSentinelBytes(text));
25
+ }
26
+ function encodeTrailingUsageFrame(frame) {
27
+ return encoder.encode(TRAILER_SENTINEL + JSON.stringify(frame));
28
+ }
29
+
30
+ // src/chat-protocol/decode.ts
31
+ function escapeThinkingTags(text) {
32
+ return text.replace(/</g, "&lt;");
33
+ }
34
+ function mapLeadingFrame(meta, out) {
35
+ if (meta.status === "thinking") {
36
+ out.push({ type: "status", phase: "thinking" });
37
+ } else if (meta.kind === "thinking-delta" && typeof meta.text === "string") {
38
+ out.push({ type: "thinking-delta", text: meta.text });
39
+ } else if (meta.kind === "usage" && meta.stage === "start") {
40
+ out.push({
41
+ type: "usage",
42
+ stage: "start",
43
+ input_tokens: meta.input_tokens,
44
+ cache_read_input_tokens: meta.cache_read_input_tokens,
45
+ cache_creation_input_tokens: meta.cache_creation_input_tokens
46
+ });
47
+ } else if (meta.kind === "decision_resolved" && typeof meta.action === "string") {
48
+ const status = meta.action === "rejected" ? "rejected" : "approved";
49
+ const toolName = typeof meta.tool_name === "string" ? meta.tool_name : void 0;
50
+ const result = meta.result ?? null;
51
+ const card = meta.card ?? null;
52
+ out.push({
53
+ type: "approval-resolved",
54
+ status,
55
+ ok: meta.ok === true,
56
+ willAutoContinue: meta.willAutoContinue === true,
57
+ ...toolName ? { toolName } : {},
58
+ ...result ? { result } : {},
59
+ ...card?.marker ? { marker: card.marker } : {},
60
+ ...card?.ref ? { cardRef: card.ref } : {},
61
+ ...card?.type ? { cardType: card.type } : {},
62
+ ...typeof meta.receiptText === "string" ? { receiptText: meta.receiptText } : {},
63
+ requestId: typeof meta.proposalId === "string" ? meta.proposalId : void 0
64
+ });
65
+ } else if (meta.kind === "approval_request" && meta.proposalId) {
66
+ const proposalId = String(meta.proposalId);
67
+ const toolName = String(meta.toolName ?? "tool");
68
+ const headline = typeof meta.title === "string" && meta.title.length > 0 ? meta.title : toolName;
69
+ const rawFields = Array.isArray(meta.fields) ? meta.fields : [];
70
+ const fields = [];
71
+ for (const f of rawFields) {
72
+ if (!f || !f.label || !f.value) continue;
73
+ fields.push({ label: f.label, value: f.value });
74
+ }
75
+ out.push({
76
+ type: "approval-request",
77
+ requestId: proposalId,
78
+ approvalType: toolName,
79
+ command: headline,
80
+ fields,
81
+ status: "pending"
82
+ });
83
+ } else if (meta.kind === "text-leading" && typeof meta.text === "string") {
84
+ out.push({ type: "text-delta", text: meta.text, leading: true });
85
+ } else if (meta.kind === "tool_error") {
86
+ const msg = typeof meta.message === "string" && meta.message.length > 0 ? meta.message : "Could not complete the requested action right now.";
87
+ out.push({ type: "error", title: msg });
88
+ } else if (meta.kind === "routing") {
89
+ if (typeof meta.routedComplexity === "string") {
90
+ out.push({
91
+ type: "metadata",
92
+ routing: {
93
+ routedComplexity: meta.routedComplexity,
94
+ ...typeof meta.routedModel === "string" ? { routedModel: meta.routedModel } : {},
95
+ routedThinkingBudget: typeof meta.routedThinkingBudget === "number" ? meta.routedThinkingBudget : null
96
+ }
97
+ });
98
+ }
99
+ } else {
100
+ out.push({
101
+ type: "metadata",
102
+ sources: meta.sources,
103
+ refs: meta.refs,
104
+ provider: meta.provider,
105
+ modelLabel: meta.modelLabel,
106
+ modelName: meta.model,
107
+ contextWindowMaxTokens: meta.contextWindowMaxTokens,
108
+ scrollAnchor: meta.scrollAnchor,
109
+ conversationId: meta.conversationId
110
+ });
111
+ }
112
+ }
113
+ function createSseFrameDecoder() {
114
+ const textDecoder = new TextDecoder();
115
+ let buffer = "";
116
+ let inText = false;
117
+ let inTrailer = false;
118
+ let trailerBuffer = "";
119
+ let ended = false;
120
+ function push(bytes) {
121
+ const out = [];
122
+ const chunk = textDecoder.decode(bytes, { stream: true });
123
+ if (!inText) {
124
+ buffer += chunk;
125
+ while (!inText) {
126
+ const recIdx = buffer.indexOf(END_OF_LEADING);
127
+ const nullIdx = buffer.indexOf(FRAME_TERMINATOR);
128
+ if (recIdx !== -1 && (nullIdx === -1 || recIdx < nullIdx)) {
129
+ inText = true;
130
+ out.push({ type: "turn-start" });
131
+ const after = buffer.slice(recIdx + 1);
132
+ buffer = "";
133
+ if (after) {
134
+ const unitIdx = after.indexOf(TRAILER_SENTINEL);
135
+ if (unitIdx === -1) {
136
+ out.push({ type: "text-delta", text: after });
137
+ } else {
138
+ const textBefore = after.slice(0, unitIdx);
139
+ const trailerAfter = after.slice(unitIdx + 1);
140
+ if (textBefore) {
141
+ out.push({ type: "text-delta", text: textBefore });
142
+ }
143
+ inTrailer = true;
144
+ trailerBuffer = trailerAfter;
145
+ }
146
+ }
147
+ break;
148
+ }
149
+ if (nullIdx === -1) break;
150
+ const metaStr = buffer.slice(0, nullIdx);
151
+ const remaining = buffer.slice(nullIdx + 1);
152
+ let meta;
153
+ try {
154
+ meta = JSON.parse(metaStr);
155
+ } catch {
156
+ inText = true;
157
+ out.push({ type: "turn-start", implicit: true });
158
+ if (buffer.length > 0) {
159
+ out.push({ type: "text-delta", text: buffer });
160
+ buffer = "";
161
+ }
162
+ break;
163
+ }
164
+ mapLeadingFrame(meta, out);
165
+ buffer = remaining;
166
+ }
167
+ } else if (inTrailer) {
168
+ trailerBuffer += chunk;
169
+ } else {
170
+ const sepIdx = chunk.indexOf(TRAILER_SENTINEL);
171
+ if (sepIdx === -1) {
172
+ out.push({ type: "text-delta", text: chunk });
173
+ } else {
174
+ const before = chunk.slice(0, sepIdx);
175
+ const after = chunk.slice(sepIdx + 1);
176
+ if (before) out.push({ type: "text-delta", text: before });
177
+ inTrailer = true;
178
+ trailerBuffer = after;
179
+ }
180
+ }
181
+ return out;
182
+ }
183
+ function end() {
184
+ if (ended) return [];
185
+ ended = true;
186
+ const out = [];
187
+ if (trailerBuffer.length > 0) {
188
+ const raw = trailerBuffer;
189
+ trailerBuffer = "";
190
+ try {
191
+ const meta = JSON.parse(raw);
192
+ if (meta.kind === "usage" && (meta.stage === "end" || meta.stage === "display")) {
193
+ out.push({
194
+ type: "usage",
195
+ stage: "end",
196
+ input_tokens: meta.input_tokens,
197
+ output_tokens: meta.output_tokens,
198
+ cache_read_input_tokens: meta.cache_read_input_tokens,
199
+ cache_creation_input_tokens: meta.cache_creation_input_tokens,
200
+ hit_rate_pct: meta.hit_rate_pct,
201
+ telemetry: meta.telemetry,
202
+ breakdown: meta.breakdown,
203
+ debug: meta.debug
204
+ });
205
+ }
206
+ } catch {
207
+ }
208
+ }
209
+ return out;
210
+ }
211
+ return { push, end };
212
+ }
213
+
214
+ // src/components/chat/types/message.types.ts
215
+ var MESSAGE_TYPE = {
216
+ TEXT: "TEXT",
217
+ THINKING: "THINKING",
218
+ GUIDE: "GUIDE",
219
+ EXECUTING_TOOL: "EXECUTING_TOOL",
220
+ EXECUTED_TOOL: "EXECUTED_TOOL",
221
+ APPROVAL_REQUEST: "APPROVAL_REQUEST",
222
+ APPROVAL_RESULT: "APPROVAL_RESULT",
223
+ ERROR: "ERROR",
224
+ MESSAGE_START: "MESSAGE_START",
225
+ MESSAGE_END: "MESSAGE_END",
226
+ MESSAGE_REQUEST: "MESSAGE_REQUEST",
227
+ AI_METADATA: "AI_METADATA",
228
+ TOKEN_USAGE: "TOKEN_USAGE",
229
+ CONTEXT_COMPACTION_START: "CONTEXT_COMPACTION_START",
230
+ CONTEXT_COMPACTION_END: "CONTEXT_COMPACTION_END",
231
+ DIRECT_MESSAGE: "DIRECT_MESSAGE",
232
+ SYSTEM: "SYSTEM",
233
+ DIALOG_CLOSED: "DIALOG_CLOSED"
234
+ };
235
+
236
+ // src/chat-protocol/nats-decoder.ts
237
+ function normalizeToolCalls(raw) {
238
+ if (!Array.isArray(raw)) return [];
239
+ return raw.filter((item) => !!item && typeof item === "object").map((item) => ({
240
+ toolExecutionRequestId: String(item.toolExecutionRequestId ?? ""),
241
+ toolName: String(item.toolName ?? ""),
242
+ toolTitle: typeof item.toolTitle === "string" ? item.toolTitle : void 0,
243
+ toolExplanation: typeof item.toolExplanation === "string" ? item.toolExplanation : void 0,
244
+ toolType: typeof item.toolType === "string" ? item.toolType : void 0,
245
+ requiresApproval: item.requiresApproval === true,
246
+ approvalType: typeof item.approvalType === "string" ? item.approvalType : null,
247
+ toolCallArguments: item.toolCallArguments && typeof item.toolCallArguments === "object" ? item.toolCallArguments : null
248
+ }));
249
+ }
250
+ function decodeNatsChunk(chunk) {
251
+ if (!chunk || typeof chunk !== "object") return null;
252
+ const data = chunk;
253
+ const type = String(data.type || "");
254
+ const seq = typeof data.streamSeq === "number" ? { seq: data.streamSeq } : {};
255
+ switch (type) {
256
+ case MESSAGE_TYPE.MESSAGE_START:
257
+ return { type: "turn-start", ...seq };
258
+ case MESSAGE_TYPE.MESSAGE_END:
259
+ return { type: "turn-end", ...seq };
260
+ case MESSAGE_TYPE.AI_METADATA: {
261
+ const providerName = data.providerName || data.provider;
262
+ if (typeof data.modelName === "string" && typeof providerName === "string") {
263
+ return {
264
+ type: "metadata",
265
+ modelLabel: data.modelDisplayName,
266
+ modelName: data.modelName,
267
+ provider: providerName,
268
+ contextWindowMaxTokens: typeof data.contextWindow === "number" ? data.contextWindow : 0,
269
+ ...seq
270
+ };
271
+ }
272
+ return null;
273
+ }
274
+ case MESSAGE_TYPE.TEXT:
275
+ if (typeof data.text === "string") {
276
+ return { type: "text-delta", text: data.text, ...seq };
277
+ }
278
+ return null;
279
+ case MESSAGE_TYPE.THINKING:
280
+ if (typeof data.text === "string") {
281
+ return { type: "thinking-delta", text: data.text, ...seq };
282
+ }
283
+ return null;
284
+ case MESSAGE_TYPE.GUIDE:
285
+ if (typeof data.text === "string") {
286
+ return { type: "guide-delta", text: data.text, ...seq };
287
+ }
288
+ return null;
289
+ case MESSAGE_TYPE.EXECUTING_TOOL:
290
+ return {
291
+ type: "tool-execution",
292
+ data: {
293
+ type: "EXECUTING_TOOL",
294
+ integratedToolType: data.integratedToolType || "",
295
+ toolFunction: data.toolFunction || "",
296
+ toolTitle: typeof data.title === "string" ? data.title : void 0,
297
+ parameters: data.parameters,
298
+ toolExecutionRequestId: typeof data.toolExecutionRequestId === "string" ? data.toolExecutionRequestId : void 0
299
+ },
300
+ ...seq
301
+ };
302
+ case MESSAGE_TYPE.EXECUTED_TOOL:
303
+ return {
304
+ type: "tool-execution",
305
+ data: {
306
+ type: "EXECUTED_TOOL",
307
+ integratedToolType: data.integratedToolType || "",
308
+ toolFunction: data.toolFunction || "",
309
+ toolTitle: typeof data.title === "string" ? data.title : void 0,
310
+ parameters: data.parameters,
311
+ result: data.result,
312
+ success: data.success,
313
+ toolExecutionRequestId: typeof data.toolExecutionRequestId === "string" ? data.toolExecutionRequestId : void 0
314
+ },
315
+ ...seq
316
+ };
317
+ case MESSAGE_TYPE.APPROVAL_REQUEST: {
318
+ const requestId = data.approvalRequestId || data.approval_request_id || "";
319
+ const approvalType = data.approvalType || "USER";
320
+ const toolCalls = normalizeToolCalls(data.toolCalls);
321
+ if (toolCalls.length > 0) {
322
+ return { type: "approval-request", requestId, approvalType, toolCalls, ...seq };
323
+ }
324
+ return {
325
+ type: "approval-request",
326
+ requestId,
327
+ approvalType,
328
+ command: data.command || "",
329
+ explanation: data.explanation,
330
+ ...seq
331
+ };
332
+ }
333
+ case MESSAGE_TYPE.APPROVAL_RESULT: {
334
+ const resolvedByName = typeof data.resolvedByName === "string" ? data.resolvedByName : typeof data.displayName === "string" ? data.displayName : void 0;
335
+ return {
336
+ type: "approval-resolved",
337
+ requestId: data.approvalRequestId || data.approval_request_id || "",
338
+ status: data.approved === true ? "approved" : "rejected",
339
+ approvalType: data.approvalType || "CLIENT",
340
+ resolvedByName,
341
+ ...seq
342
+ };
343
+ }
344
+ case MESSAGE_TYPE.ERROR:
345
+ return {
346
+ type: "error",
347
+ title: data.error || "An error occurred",
348
+ details: data.details,
349
+ ...seq
350
+ };
351
+ case MESSAGE_TYPE.MESSAGE_REQUEST:
352
+ return {
353
+ type: "participant",
354
+ kind: "message-request",
355
+ text: String(data.text || ""),
356
+ ownerType: typeof data.ownerType === "string" ? data.ownerType : void 0,
357
+ displayName: typeof data.displayName === "string" ? data.displayName : void 0,
358
+ userId: typeof data.userId === "string" ? data.userId : void 0,
359
+ // Wire shape carries no label; fall back to the id (parity with
360
+ // the history path in `process-historical-messages.ts`).
361
+ contextItems: Array.isArray(data.contextItems) ? data.contextItems.filter((it) => typeof it?.type === "string" && typeof it?.id === "string").map((it) => ({
362
+ type: it.type,
363
+ id: it.id,
364
+ label: it.id
365
+ })) : void 0,
366
+ ...seq
367
+ };
368
+ case MESSAGE_TYPE.TOKEN_USAGE:
369
+ return {
370
+ type: "token-usage",
371
+ inputTokensSize: data.inputTokensSize ?? 0,
372
+ outputTokensSize: data.outputTokensSize ?? 0,
373
+ totalTokensSize: data.totalTokensSize ?? 0,
374
+ contextSize: data.contextSize ?? 0,
375
+ ...seq
376
+ };
377
+ case MESSAGE_TYPE.CONTEXT_COMPACTION_START:
378
+ return { type: "compaction", phase: "start", ...seq };
379
+ case MESSAGE_TYPE.CONTEXT_COMPACTION_END:
380
+ return {
381
+ type: "compaction",
382
+ phase: "end",
383
+ summary: typeof data.text === "string" ? data.text : void 0,
384
+ ...seq
385
+ };
386
+ case MESSAGE_TYPE.SYSTEM:
387
+ if (typeof data.text === "string") {
388
+ return { type: "participant", kind: "system", text: data.text, ...seq };
389
+ }
390
+ return null;
391
+ case MESSAGE_TYPE.DIRECT_MESSAGE:
392
+ if (typeof data.text === "string") {
393
+ return {
394
+ type: "participant",
395
+ kind: "direct-message",
396
+ text: data.text,
397
+ ownerType: typeof data.ownerType === "string" ? data.ownerType : void 0,
398
+ displayName: typeof data.displayName === "string" ? data.displayName : void 0,
399
+ userId: typeof data.userId === "string" ? data.userId : void 0,
400
+ ...seq
401
+ };
402
+ }
403
+ return null;
404
+ case MESSAGE_TYPE.DIALOG_CLOSED:
405
+ return { type: "dialog-closed", ...seq };
406
+ default:
407
+ return null;
408
+ }
409
+ }
410
+
411
+ // src/chat-protocol/ip-normalize.ts
412
+ var IP_BUCKET_KEY_MAX_LENGTH = 64;
413
+ function isIpv4(value) {
414
+ const parts = value.split(".");
415
+ if (parts.length !== 4) return false;
416
+ for (const part of parts) {
417
+ if (!/^\d{1,3}$/.test(part)) return false;
418
+ if (part.length > 1 && part.startsWith("0")) return false;
419
+ if (Number(part) > 255) return false;
420
+ }
421
+ return true;
422
+ }
423
+ function isIpv6(value) {
424
+ if (!value.includes(":")) return false;
425
+ if (!/^[0-9a-f:.]+$/.test(value)) return false;
426
+ if (value.includes(":::")) return false;
427
+ if (value.endsWith(":") && !value.endsWith("::")) return false;
428
+ if (value.startsWith(":") && !value.startsWith("::")) return false;
429
+ const compressions = value.split("::").length - 1;
430
+ if (compressions > 1) return false;
431
+ const groups = value.split(":");
432
+ if (groups.length > 8) return false;
433
+ for (let i = 0; i < groups.length; i += 1) {
434
+ const group = groups[i];
435
+ if (group === "") continue;
436
+ if (group.includes(".")) {
437
+ if (i !== groups.length - 1) return false;
438
+ if (!isIpv4(group)) return false;
439
+ continue;
440
+ }
441
+ if (!/^[0-9a-f]{1,4}$/.test(group)) return false;
442
+ }
443
+ if (compressions === 0) {
444
+ const embedsIpv4 = groups[groups.length - 1]?.includes(".") ?? false;
445
+ if (groups.length !== (embedsIpv4 ? 7 : 8)) return false;
446
+ }
447
+ return true;
448
+ }
449
+ function normalizeIpForBucketKey(value) {
450
+ if (typeof value !== "string") return null;
451
+ let candidate = value.trim();
452
+ if (candidate === "" || candidate.length > IP_BUCKET_KEY_MAX_LENGTH) return null;
453
+ if (candidate.startsWith("[")) {
454
+ const close = candidate.indexOf("]");
455
+ if (close === -1) return null;
456
+ const trailer = candidate.slice(close + 1);
457
+ if (trailer !== "" && !/^:\d{1,5}$/.test(trailer)) return null;
458
+ candidate = candidate.slice(1, close);
459
+ }
460
+ const zone = candidate.indexOf("%");
461
+ if (zone !== -1) candidate = candidate.slice(0, zone);
462
+ if (candidate === "") return null;
463
+ const portSplit = candidate.lastIndexOf(":");
464
+ if (portSplit > 0 && /^\d{1,5}$/.test(candidate.slice(portSplit + 1))) {
465
+ const head = candidate.slice(0, portSplit);
466
+ if (isIpv4(head)) candidate = head;
467
+ }
468
+ if (isIpv4(candidate)) return candidate;
469
+ const lowered = candidate.toLowerCase();
470
+ const mapped = /^(?:(?:0{1,4}:){5}|::)ffff:(\d{1,3}(?:\.\d{1,3}){3})$/.exec(lowered);
471
+ if (mapped) return isIpv4(mapped[1]) ? mapped[1] : null;
472
+ if (isIpv6(lowered)) return lowered;
473
+ return null;
474
+ }
475
+
476
+ // src/chat-protocol/env-flag.ts
477
+ function envFlagEnabled(name) {
478
+ const raw = process.env[name];
479
+ if (!raw) return false;
480
+ const v = raw.trim().toLowerCase();
481
+ return v !== "" && v !== "0" && v !== "false" && v !== "off";
482
+ }
483
+
484
+ exports.CHAT_OWNER_ADMIN = CHAT_OWNER_ADMIN;
485
+ exports.END_OF_LEADING = END_OF_LEADING;
486
+ exports.FRAME_TERMINATOR = FRAME_TERMINATOR;
487
+ exports.IP_BUCKET_KEY_MAX_LENGTH = IP_BUCKET_KEY_MAX_LENGTH;
488
+ exports.TRAILER_SENTINEL = TRAILER_SENTINEL;
489
+ exports.createSseFrameDecoder = createSseFrameDecoder;
490
+ exports.decodeNatsChunk = decodeNatsChunk;
491
+ exports.encodeEndOfLeading = encodeEndOfLeading;
492
+ exports.encodeLeadingFrame = encodeLeadingFrame;
493
+ exports.encodeTextDelta = encodeTextDelta;
494
+ exports.encodeTrailingUsageFrame = encodeTrailingUsageFrame;
495
+ exports.envFlagEnabled = envFlagEnabled;
496
+ exports.escapeThinkingTags = escapeThinkingTags;
497
+ exports.normalizeIpForBucketKey = normalizeIpForBucketKey;
498
+ exports.stripSentinelBytes = stripSentinelBytes;
499
+ //# sourceMappingURL=index.cjs.map
500
+ //# sourceMappingURL=index.cjs.map