@flamingo-stack/openframe-frontend-core 0.0.467 → 0.0.468-snapshot.20260723140929

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 (289) 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-BIDOIPIT.js → chunk-2BJSRTKU.js} +2 -2
  22. package/dist/{chunk-4DFPQKKJ.js → chunk-33FDAZDB.js} +2 -2
  23. package/dist/{chunk-LOWJWKM5.js → chunk-4QDFNDVW.js} +4 -4
  24. package/dist/{chunk-72NEN4G4.cjs → chunk-4UFRQT7Z.cjs} +15 -15
  25. package/dist/{chunk-72NEN4G4.cjs.map → chunk-4UFRQT7Z.cjs.map} +1 -1
  26. package/dist/{chunk-WWC75D3J.cjs → chunk-4W54HUP7.cjs} +6853 -4609
  27. package/dist/chunk-4W54HUP7.cjs.map +1 -0
  28. package/dist/{chunk-6DZ5QOUM.cjs → chunk-5HUTT3FD.cjs} +11 -11
  29. package/dist/{chunk-6DZ5QOUM.cjs.map → chunk-5HUTT3FD.cjs.map} +1 -1
  30. package/dist/{chunk-GXXLJHQX.js → chunk-7I2QMUEZ.js} +2 -2
  31. package/dist/{chunk-QJ7NIL6A.js → chunk-AJSNF5YF.js} +6 -5
  32. package/dist/chunk-AJSNF5YF.js.map +1 -0
  33. package/dist/{chunk-NYOQNYSI.js → chunk-AW3LVWVV.js} +2 -2
  34. package/dist/{chunk-25YYEVSE.js → chunk-DG7TX763.js} +2 -2
  35. package/dist/{chunk-CZFPPNYV.js → chunk-E6O6XATC.js} +11899 -9655
  36. package/dist/chunk-E6O6XATC.js.map +1 -0
  37. package/dist/{chunk-ZYPHZ3R3.cjs → chunk-GLKULDQN.cjs} +9 -9
  38. package/dist/{chunk-ZYPHZ3R3.cjs.map → chunk-GLKULDQN.cjs.map} +1 -1
  39. package/dist/{chunk-TZSPLSDU.js → chunk-GYEZV4GK.js} +2 -2
  40. package/dist/{chunk-G5D7NRH5.cjs → chunk-LRESZO4L.cjs} +26 -26
  41. package/dist/{chunk-G5D7NRH5.cjs.map → chunk-LRESZO4L.cjs.map} +1 -1
  42. package/dist/{chunk-ABU37QSG.js → chunk-MMF6HJB7.js} +4 -4
  43. package/dist/{chunk-O7LQYYUA.cjs → chunk-MTLBBSLP.cjs} +5 -5
  44. package/dist/{chunk-O7LQYYUA.cjs.map → chunk-MTLBBSLP.cjs.map} +1 -1
  45. package/dist/{chunk-UWW4PQQS.cjs → chunk-OVIUQJ2H.cjs} +28 -27
  46. package/dist/chunk-OVIUQJ2H.cjs.map +1 -0
  47. package/dist/{chunk-3L44PPMF.js → chunk-RPAOSHBN.js} +2 -2
  48. package/dist/{chunk-VERK32MO.cjs → chunk-TOFOK7G5.cjs} +37 -37
  49. package/dist/{chunk-VERK32MO.cjs.map → chunk-TOFOK7G5.cjs.map} +1 -1
  50. package/dist/{chunk-QITN43HN.cjs → chunk-U2KPMWO6.cjs} +7 -7
  51. package/dist/{chunk-QITN43HN.cjs.map → chunk-U2KPMWO6.cjs.map} +1 -1
  52. package/dist/{chunk-YGW7T57C.cjs → chunk-V5YWOQBP.cjs} +31 -31
  53. package/dist/{chunk-YGW7T57C.cjs.map → chunk-V5YWOQBP.cjs.map} +1 -1
  54. package/dist/{chunk-ILZ66CS6.js → chunk-VUCYS36H.js} +10 -10
  55. package/dist/chunk-VUCYS36H.js.map +1 -0
  56. package/dist/{chunk-SGDXS7VT.cjs → chunk-WHWDGCQV.cjs} +60 -60
  57. package/dist/chunk-WHWDGCQV.cjs.map +1 -0
  58. package/dist/{chunk-G2H4AKL3.cjs → chunk-YXNWEVER.cjs} +62 -62
  59. package/dist/{chunk-G2H4AKL3.cjs.map → chunk-YXNWEVER.cjs.map} +1 -1
  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-composer.d.ts +8 -1
  63. package/dist/components/chat/chat-composer.d.ts.map +1 -1
  64. package/dist/components/chat/chat-context-memory-bar.d.ts +37 -0
  65. package/dist/components/chat/chat-context-memory-bar.d.ts.map +1 -0
  66. package/dist/components/chat/chat-message-enhanced.d.ts.map +1 -1
  67. package/dist/components/chat/chat-message-list.d.ts.map +1 -1
  68. package/dist/components/chat/embeddable-chat.d.ts +14 -6
  69. package/dist/components/chat/embeddable-chat.d.ts.map +1 -1
  70. package/dist/components/chat/hooks/index.d.ts +0 -1
  71. package/dist/components/chat/hooks/index.d.ts.map +1 -1
  72. package/dist/components/chat/hooks/use-chat.d.ts.map +1 -1
  73. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts +15 -48
  74. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts.map +1 -1
  75. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts +3 -47
  76. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
  77. package/dist/components/chat/index.cjs +12 -2
  78. package/dist/components/chat/index.cjs.map +1 -1
  79. package/dist/components/chat/index.d.ts +2 -0
  80. package/dist/components/chat/index.d.ts.map +1 -1
  81. package/dist/components/chat/index.js +23 -13
  82. package/dist/components/chat/stream/chat-dialog-store.d.ts +184 -0
  83. package/dist/components/chat/stream/chat-dialog-store.d.ts.map +1 -0
  84. package/dist/components/chat/stream/chat-stream-reducer.d.ts +367 -0
  85. package/dist/components/chat/stream/chat-stream-reducer.d.ts.map +1 -0
  86. package/dist/components/chat/stream/delta-batcher.d.ts +51 -0
  87. package/dist/components/chat/stream/delta-batcher.d.ts.map +1 -0
  88. package/dist/components/chat/stream/index.d.ts +17 -0
  89. package/dist/components/chat/stream/index.d.ts.map +1 -0
  90. package/dist/components/chat/stream/message-mutations.d.ts +77 -0
  91. package/dist/components/chat/stream/message-mutations.d.ts.map +1 -0
  92. package/dist/components/chat/stream/use-chat-stream-reducer.d.ts +22 -0
  93. package/dist/components/chat/stream/use-chat-stream-reducer.d.ts.map +1 -0
  94. package/dist/components/chat/types/api.types.d.ts +1 -81
  95. package/dist/components/chat/types/api.types.d.ts.map +1 -1
  96. package/dist/components/chat/types/processing.types.d.ts +2 -90
  97. package/dist/components/chat/types/processing.types.d.ts.map +1 -1
  98. package/dist/components/chat/utils/extract-incomplete-message-state.d.ts +34 -6
  99. package/dist/components/chat/utils/extract-incomplete-message-state.d.ts.map +1 -1
  100. package/dist/components/chat/utils/index.d.ts +2 -3
  101. package/dist/components/chat/utils/index.d.ts.map +1 -1
  102. package/dist/components/chat/utils/process-historical-messages.d.ts +59 -11
  103. package/dist/components/chat/utils/process-historical-messages.d.ts.map +1 -1
  104. package/dist/components/contact/index.cjs +3 -3
  105. package/dist/components/contact/index.js +2 -2
  106. package/dist/components/docs/index.cjs +5 -5
  107. package/dist/components/docs/index.js +4 -4
  108. package/dist/components/embeds/index.cjs +3 -3
  109. package/dist/components/embeds/index.js +2 -2
  110. package/dist/components/faq/index.cjs +3 -3
  111. package/dist/components/faq/index.js +2 -2
  112. package/dist/components/features/index.cjs +2 -2
  113. package/dist/components/features/index.js +1 -1
  114. package/dist/components/help-center-pages/index.cjs +20 -20
  115. package/dist/components/help-center-pages/index.js +11 -11
  116. package/dist/components/index.cjs +174 -130
  117. package/dist/components/index.cjs.map +1 -1
  118. package/dist/components/index.js +65 -21
  119. package/dist/components/index.js.map +1 -1
  120. package/dist/components/navigation/index.cjs +2 -2
  121. package/dist/components/navigation/index.js +1 -1
  122. package/dist/components/onboarding-guides/index.cjs +5 -5
  123. package/dist/components/onboarding-guides/index.js +4 -4
  124. package/dist/components/onboarding-guides/onboarding-guide-detail-view.d.ts.map +1 -1
  125. package/dist/components/related-content/index.cjs +3 -3
  126. package/dist/components/related-content/index.js +2 -2
  127. package/dist/components/shared/product-release/release-detail-page.d.ts.map +1 -1
  128. package/dist/components/tickets/index.cjs +5 -5
  129. package/dist/components/tickets/index.js +4 -4
  130. package/dist/components/ui/index.cjs +46 -2
  131. package/dist/components/ui/index.cjs.map +1 -1
  132. package/dist/components/ui/index.d.ts +1 -2
  133. package/dist/components/ui/index.d.ts.map +1 -1
  134. package/dist/components/ui/index.js +57 -13
  135. package/dist/components/ui/markdown/base-components.d.ts +56 -0
  136. package/dist/components/ui/markdown/base-components.d.ts.map +1 -0
  137. package/dist/components/ui/markdown/engine.d.ts +99 -0
  138. package/dist/components/ui/markdown/engine.d.ts.map +1 -0
  139. package/dist/components/ui/markdown/heading-ids.d.ts +65 -0
  140. package/dist/components/ui/markdown/heading-ids.d.ts.map +1 -0
  141. package/dist/components/ui/markdown/index.d.ts +18 -0
  142. package/dist/components/ui/markdown/index.d.ts.map +1 -0
  143. package/dist/components/ui/markdown/mermaid-diagram.d.ts +79 -0
  144. package/dist/components/ui/markdown/mermaid-diagram.d.ts.map +1 -0
  145. package/dist/components/ui/markdown/rich/embed-overrides.d.ts +14 -0
  146. package/dist/components/ui/markdown/rich/embed-overrides.d.ts.map +1 -0
  147. package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts +40 -0
  148. package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts.map +1 -0
  149. package/dist/components/ui/markdown/rich/shortcodes.d.ts +8 -0
  150. package/dist/components/ui/markdown/rich/shortcodes.d.ts.map +1 -0
  151. package/dist/components/ui/markdown/sanitize.d.ts +153 -0
  152. package/dist/components/ui/markdown/sanitize.d.ts.map +1 -0
  153. package/dist/components/ui/markdown/simple-markdown-renderer.d.ts +23 -0
  154. package/dist/components/ui/markdown/simple-markdown-renderer.d.ts.map +1 -0
  155. package/dist/components/ui/markdown/streaming.d.ts +78 -0
  156. package/dist/components/ui/markdown/streaming.d.ts.map +1 -0
  157. package/dist/components/ui/markdown/text-size.d.ts +34 -0
  158. package/dist/components/ui/markdown/text-size.d.ts.map +1 -0
  159. package/dist/index.cjs +62 -2
  160. package/dist/index.cjs.map +1 -1
  161. package/dist/index.js +73 -13
  162. package/dist/utils/index.cjs +169 -40
  163. package/dist/utils/index.cjs.map +1 -1
  164. package/dist/utils/index.d.ts +1 -0
  165. package/dist/utils/index.d.ts.map +1 -1
  166. package/dist/utils/index.js +162 -41
  167. package/dist/utils/index.js.map +1 -1
  168. package/dist/utils/markdown-fences.d.ts +42 -0
  169. package/dist/utils/markdown-fences.d.ts.map +1 -0
  170. package/dist/utils/markdown-heading-id.d.ts +85 -0
  171. package/dist/utils/markdown-heading-id.d.ts.map +1 -0
  172. package/dist/utils/markdown-section-extractor.d.ts.map +1 -1
  173. package/package.json +7 -1
  174. package/src/chat-protocol/__tests__/__snapshots__/nats-decoder-golden.test.ts.snap +307 -0
  175. package/src/chat-protocol/__tests__/chat-protocol.test.ts +515 -0
  176. package/src/chat-protocol/__tests__/env-flag.test.ts +52 -0
  177. package/src/chat-protocol/__tests__/ip-normalize.test.ts +136 -0
  178. package/src/chat-protocol/__tests__/nats-decoder-golden.test.ts +228 -0
  179. package/src/chat-protocol/decode.ts +277 -0
  180. package/src/chat-protocol/encode.ts +71 -0
  181. package/src/chat-protocol/env-flag.ts +39 -0
  182. package/src/chat-protocol/events.ts +228 -0
  183. package/src/chat-protocol/frames.ts +238 -0
  184. package/src/chat-protocol/index.ts +21 -0
  185. package/src/chat-protocol/ip-normalize.ts +146 -0
  186. package/src/chat-protocol/nats-decoder.ts +252 -0
  187. package/src/components/chat/__tests__/chat-message-list.test.tsx +293 -5
  188. package/src/components/chat/__tests__/chat-message-streaming-memo.test.tsx +207 -0
  189. package/src/components/chat/__tests__/chat-pending-turn.test.tsx +209 -0
  190. package/src/components/chat/chat-composer.tsx +32 -5
  191. package/src/components/chat/chat-context-memory-bar.tsx +159 -0
  192. package/src/components/chat/chat-message-enhanced.tsx +111 -17
  193. package/src/components/chat/chat-message-list.tsx +358 -109
  194. package/src/components/chat/embeddable-chat.tsx +23 -15
  195. package/src/components/chat/hooks/.index.md +1 -1
  196. package/src/components/chat/hooks/.use-nats-chat-adapter.md +1 -1
  197. package/src/components/chat/hooks/__tests__/__snapshots__/persisted-state-v1-golden.test.ts.snap +297 -0
  198. package/src/components/chat/hooks/__tests__/__snapshots__/sse-stream-golden.test.ts.snap +0 -0
  199. package/src/components/chat/hooks/__tests__/persisted-state-v1-golden.test.ts +272 -0
  200. package/src/components/chat/hooks/__tests__/sse-stream-golden.test.ts +318 -0
  201. package/src/components/chat/hooks/index.ts +0 -1
  202. package/src/components/chat/hooks/use-chat.ts +8 -0
  203. package/src/components/chat/hooks/use-nats-chat-adapter.ts +243 -822
  204. package/src/components/chat/hooks/use-sse-chat-adapter.ts +318 -666
  205. package/src/components/chat/index.ts +6 -0
  206. package/src/components/chat/stream/__tests__/__snapshots__/chat-stream-reducer-golden.test.ts.snap +937 -0
  207. package/src/components/chat/stream/__tests__/chat-dialog-store.test.ts +756 -0
  208. package/src/components/chat/stream/__tests__/chat-stream-reducer-golden.test.ts +460 -0
  209. package/src/components/chat/stream/__tests__/chat-stream-reducer.test.ts +894 -0
  210. package/src/components/chat/stream/__tests__/delta-batcher.test.ts +255 -0
  211. package/src/components/chat/stream/__tests__/use-chat-stream-reducer.test.ts +98 -0
  212. package/src/components/chat/stream/chat-dialog-store.ts +536 -0
  213. package/src/components/chat/stream/chat-stream-reducer.ts +1796 -0
  214. package/src/components/chat/stream/delta-batcher.ts +159 -0
  215. package/src/components/chat/stream/index.ts +55 -0
  216. package/src/components/chat/stream/message-mutations.ts +338 -0
  217. package/src/components/chat/stream/use-chat-stream-reducer.ts +126 -0
  218. package/src/components/chat/thinking-display.tsx +1 -1
  219. package/src/components/chat/types/.api.types.md +1 -3
  220. package/src/components/chat/types/.processing.types.md +6 -23
  221. package/src/components/chat/types/api.types.ts +6 -73
  222. package/src/components/chat/types/processing.types.ts +11 -52
  223. package/src/components/chat/utils/.index.md +0 -5
  224. package/src/components/chat/utils/__tests__/__snapshots__/process-historical-messages-golden.test.ts.snap +418 -0
  225. package/src/components/chat/utils/__tests__/__snapshots__/segment-accumulator-golden.test.ts.snap +599 -0
  226. package/src/components/chat/utils/__tests__/process-historical-messages-golden.test.ts +317 -0
  227. package/src/components/chat/utils/__tests__/segment-accumulator-golden.test.ts +270 -0
  228. package/src/components/chat/utils/extract-incomplete-message-state.ts +63 -5
  229. package/src/components/chat/utils/index.ts +5 -8
  230. package/src/components/chat/utils/process-historical-messages.ts +352 -383
  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/release-changelog-section.tsx +1 -1
  254. package/src/components/ui/tab-selector.tsx +8 -8
  255. package/src/components/ui/ticket-info-section.tsx +1 -1
  256. package/src/utils/index.ts +1 -0
  257. package/src/utils/markdown-fences.ts +127 -0
  258. package/src/utils/markdown-heading-id.ts +348 -0
  259. package/src/utils/markdown-section-extractor.ts +41 -56
  260. package/dist/chunk-CZFPPNYV.js.map +0 -1
  261. package/dist/chunk-ILZ66CS6.js.map +0 -1
  262. package/dist/chunk-QJ7NIL6A.js.map +0 -1
  263. package/dist/chunk-SGDXS7VT.cjs.map +0 -1
  264. package/dist/chunk-UWW4PQQS.cjs.map +0 -1
  265. package/dist/chunk-WWC75D3J.cjs.map +0 -1
  266. package/dist/components/chat/hooks/use-realtime-chunk-processor.d.ts +0 -6
  267. package/dist/components/chat/hooks/use-realtime-chunk-processor.d.ts.map +0 -1
  268. package/dist/components/chat/utils/chunk-parser.d.ts +0 -25
  269. package/dist/components/chat/utils/chunk-parser.d.ts.map +0 -1
  270. package/dist/components/ui/rich-markdown-renderer.d.ts +0 -34
  271. package/dist/components/ui/rich-markdown-renderer.d.ts.map +0 -1
  272. package/dist/components/ui/simple-markdown-renderer.d.ts +0 -73
  273. package/dist/components/ui/simple-markdown-renderer.d.ts.map +0 -1
  274. package/src/components/chat/hooks/.use-realtime-chunk-processor.md +0 -50
  275. package/src/components/chat/hooks/use-realtime-chunk-processor.ts +0 -479
  276. package/src/components/chat/utils/.chunk-parser.md +0 -51
  277. package/src/components/chat/utils/chunk-parser.ts +0 -255
  278. package/src/components/ui/.simple-markdown-renderer.md +0 -40
  279. package/src/components/ui/rich-markdown-renderer.tsx +0 -1223
  280. package/src/components/ui/simple-markdown-renderer.tsx +0 -965
  281. /package/dist/{chunk-BIDOIPIT.js.map → chunk-2BJSRTKU.js.map} +0 -0
  282. /package/dist/{chunk-4DFPQKKJ.js.map → chunk-33FDAZDB.js.map} +0 -0
  283. /package/dist/{chunk-LOWJWKM5.js.map → chunk-4QDFNDVW.js.map} +0 -0
  284. /package/dist/{chunk-GXXLJHQX.js.map → chunk-7I2QMUEZ.js.map} +0 -0
  285. /package/dist/{chunk-NYOQNYSI.js.map → chunk-AW3LVWVV.js.map} +0 -0
  286. /package/dist/{chunk-25YYEVSE.js.map → chunk-DG7TX763.js.map} +0 -0
  287. /package/dist/{chunk-TZSPLSDU.js.map → chunk-GYEZV4GK.js.map} +0 -0
  288. /package/dist/{chunk-ABU37QSG.js.map → chunk-MMF6HJB7.js.map} +0 -0
  289. /package/dist/{chunk-3L44PPMF.js.map → chunk-RPAOSHBN.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