@flamingo-stack/openframe-frontend-core 0.0.457 → 0.0.458-snapshot.20260720215024

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