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

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 (280) hide show
  1. package/dist/{chunk-TOFOK7G5.cjs → chunk-2WZAR2MB.cjs} +37 -37
  2. package/dist/{chunk-TOFOK7G5.cjs.map → chunk-2WZAR2MB.cjs.map} +1 -1
  3. package/dist/{chunk-YXNWEVER.cjs → chunk-3I34MUEG.cjs} +62 -62
  4. package/dist/{chunk-YXNWEVER.cjs.map → chunk-3I34MUEG.cjs.map} +1 -1
  5. package/dist/{chunk-4W54HUP7.cjs → chunk-3PLQWO4H.cjs} +4896 -7014
  6. package/dist/chunk-3PLQWO4H.cjs.map +1 -0
  7. package/dist/{chunk-33FDAZDB.js → chunk-3TU6QURP.js} +2 -2
  8. package/dist/{chunk-2BJSRTKU.js → chunk-AEM7ADDG.js} +2 -2
  9. package/dist/{chunk-VUCYS36H.js → chunk-CLW2S55N.js} +10 -10
  10. package/dist/chunk-CLW2S55N.js.map +1 -0
  11. package/dist/{chunk-LRESZO4L.cjs → chunk-ELIY4AO2.cjs} +26 -26
  12. package/dist/{chunk-LRESZO4L.cjs.map → chunk-ELIY4AO2.cjs.map} +1 -1
  13. package/dist/{chunk-MMF6HJB7.js → chunk-EZESVVIM.js} +4 -4
  14. package/dist/{chunk-AW3LVWVV.js → chunk-HTSWLPMU.js} +2 -2
  15. package/dist/{chunk-MTLBBSLP.cjs → chunk-HVLMAT4T.cjs} +5 -5
  16. package/dist/{chunk-MTLBBSLP.cjs.map → chunk-HVLMAT4T.cjs.map} +1 -1
  17. package/dist/{chunk-RPAOSHBN.js → chunk-IUMPVRSH.js} +2 -2
  18. package/dist/{chunk-5HUTT3FD.cjs → chunk-J6CE6HZS.cjs} +11 -11
  19. package/dist/{chunk-5HUTT3FD.cjs.map → chunk-J6CE6HZS.cjs.map} +1 -1
  20. package/dist/{chunk-7I2QMUEZ.js → chunk-JW3UNHGW.js} +2 -2
  21. package/dist/{chunk-4UFRQT7Z.cjs → chunk-L3BWGFHT.cjs} +15 -15
  22. package/dist/{chunk-4UFRQT7Z.cjs.map → chunk-L3BWGFHT.cjs.map} +1 -1
  23. package/dist/{chunk-WHWDGCQV.cjs → chunk-MULVIGIN.cjs} +60 -60
  24. package/dist/chunk-MULVIGIN.cjs.map +1 -0
  25. package/dist/{chunk-AJSNF5YF.js → chunk-O2QOC5FA.js} +5 -6
  26. package/dist/chunk-O2QOC5FA.js.map +1 -0
  27. package/dist/{chunk-E6O6XATC.js → chunk-P5SLNM3C.js} +9699 -11817
  28. package/dist/chunk-P5SLNM3C.js.map +1 -0
  29. package/dist/{chunk-GYEZV4GK.js → chunk-QTGYQ2U7.js} +2 -2
  30. package/dist/{chunk-4QDFNDVW.js → chunk-QZJN5OHK.js} +4 -4
  31. package/dist/{chunk-U2KPMWO6.cjs → chunk-TISXEAGH.cjs} +7 -7
  32. package/dist/{chunk-U2KPMWO6.cjs.map → chunk-TISXEAGH.cjs.map} +1 -1
  33. package/dist/{chunk-V5YWOQBP.cjs → chunk-VHFH3BG6.cjs} +31 -31
  34. package/dist/{chunk-V5YWOQBP.cjs.map → chunk-VHFH3BG6.cjs.map} +1 -1
  35. package/dist/{chunk-OVIUQJ2H.cjs → chunk-VRJXY6TM.cjs} +27 -28
  36. package/dist/chunk-VRJXY6TM.cjs.map +1 -0
  37. package/dist/{chunk-DG7TX763.js → chunk-VYUEOKI6.js} +2 -2
  38. package/dist/{chunk-GLKULDQN.cjs → chunk-X77X3RKH.cjs} +9 -9
  39. package/dist/{chunk-GLKULDQN.cjs.map → chunk-X77X3RKH.cjs.map} +1 -1
  40. package/dist/components/case-studies/index.cjs +8 -8
  41. package/dist/components/case-studies/index.js +2 -2
  42. package/dist/components/chat/chat-message-enhanced.d.ts.map +1 -1
  43. package/dist/components/chat/chat-message-list.d.ts.map +1 -1
  44. package/dist/components/chat/hooks/index.d.ts +1 -0
  45. package/dist/components/chat/hooks/index.d.ts.map +1 -1
  46. package/dist/components/chat/hooks/use-chat.d.ts.map +1 -1
  47. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts +48 -15
  48. package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts.map +1 -1
  49. package/dist/components/chat/hooks/use-realtime-chunk-processor.d.ts +6 -0
  50. package/dist/components/chat/hooks/use-realtime-chunk-processor.d.ts.map +1 -0
  51. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts +47 -3
  52. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
  53. package/dist/components/chat/index.cjs +2 -10
  54. package/dist/components/chat/index.cjs.map +1 -1
  55. package/dist/components/chat/index.d.ts +0 -1
  56. package/dist/components/chat/index.d.ts.map +1 -1
  57. package/dist/components/chat/index.js +13 -21
  58. package/dist/components/chat/types/api.types.d.ts +81 -1
  59. package/dist/components/chat/types/api.types.d.ts.map +1 -1
  60. package/dist/components/chat/types/processing.types.d.ts +90 -2
  61. package/dist/components/chat/types/processing.types.d.ts.map +1 -1
  62. package/dist/components/chat/utils/chunk-parser.d.ts +25 -0
  63. package/dist/components/chat/utils/chunk-parser.d.ts.map +1 -0
  64. package/dist/components/chat/utils/extract-incomplete-message-state.d.ts +6 -34
  65. package/dist/components/chat/utils/extract-incomplete-message-state.d.ts.map +1 -1
  66. package/dist/components/chat/utils/index.d.ts +3 -2
  67. package/dist/components/chat/utils/index.d.ts.map +1 -1
  68. package/dist/components/chat/utils/process-historical-messages.d.ts +11 -59
  69. package/dist/components/chat/utils/process-historical-messages.d.ts.map +1 -1
  70. package/dist/components/contact/index.cjs +3 -3
  71. package/dist/components/contact/index.js +2 -2
  72. package/dist/components/docs/index.cjs +5 -5
  73. package/dist/components/docs/index.js +4 -4
  74. package/dist/components/embeds/index.cjs +3 -3
  75. package/dist/components/embeds/index.js +2 -2
  76. package/dist/components/faq/index.cjs +3 -3
  77. package/dist/components/faq/index.js +2 -2
  78. package/dist/components/features/index.cjs +2 -2
  79. package/dist/components/features/index.js +1 -1
  80. package/dist/components/help-center-pages/index.cjs +20 -20
  81. package/dist/components/help-center-pages/index.js +11 -11
  82. package/dist/components/index.cjs +130 -172
  83. package/dist/components/index.cjs.map +1 -1
  84. package/dist/components/index.js +21 -63
  85. package/dist/components/index.js.map +1 -1
  86. package/dist/components/navigation/index.cjs +2 -2
  87. package/dist/components/navigation/index.js +1 -1
  88. package/dist/components/onboarding-guides/index.cjs +5 -5
  89. package/dist/components/onboarding-guides/index.js +4 -4
  90. package/dist/components/onboarding-guides/onboarding-guide-detail-view.d.ts.map +1 -1
  91. package/dist/components/related-content/index.cjs +3 -3
  92. package/dist/components/related-content/index.js +2 -2
  93. package/dist/components/shared/product-release/release-detail-page.d.ts.map +1 -1
  94. package/dist/components/tickets/index.cjs +5 -5
  95. package/dist/components/tickets/index.js +4 -4
  96. package/dist/components/ui/index.cjs +2 -44
  97. package/dist/components/ui/index.cjs.map +1 -1
  98. package/dist/components/ui/index.d.ts +2 -1
  99. package/dist/components/ui/index.d.ts.map +1 -1
  100. package/dist/components/ui/index.js +13 -55
  101. package/dist/components/ui/rich-markdown-renderer.d.ts +34 -0
  102. package/dist/components/ui/rich-markdown-renderer.d.ts.map +1 -0
  103. package/dist/components/ui/simple-markdown-renderer.d.ts +73 -0
  104. package/dist/components/ui/simple-markdown-renderer.d.ts.map +1 -0
  105. package/dist/index.cjs +2 -60
  106. package/dist/index.cjs.map +1 -1
  107. package/dist/index.js +13 -71
  108. package/dist/utils/index.cjs +40 -169
  109. package/dist/utils/index.cjs.map +1 -1
  110. package/dist/utils/index.d.ts +0 -1
  111. package/dist/utils/index.d.ts.map +1 -1
  112. package/dist/utils/index.js +41 -162
  113. package/dist/utils/index.js.map +1 -1
  114. package/dist/utils/markdown-section-extractor.d.ts.map +1 -1
  115. package/package.json +1 -7
  116. package/src/components/chat/__tests__/chat-message-list.test.tsx +5 -293
  117. package/src/components/chat/chat-message-enhanced.tsx +17 -111
  118. package/src/components/chat/chat-message-list.tsx +109 -358
  119. package/src/components/chat/embeddable-chat.tsx +0 -6
  120. package/src/components/chat/hooks/.index.md +1 -1
  121. package/src/components/chat/hooks/.use-nats-chat-adapter.md +1 -1
  122. package/src/components/chat/hooks/.use-realtime-chunk-processor.md +50 -0
  123. package/src/components/chat/hooks/index.ts +1 -0
  124. package/src/components/chat/hooks/use-chat.ts +0 -8
  125. package/src/components/chat/hooks/use-nats-chat-adapter.ts +822 -243
  126. package/src/components/chat/hooks/use-realtime-chunk-processor.ts +479 -0
  127. package/src/components/chat/hooks/use-sse-chat-adapter.ts +666 -318
  128. package/src/components/chat/index.ts +0 -5
  129. package/src/components/chat/thinking-display.tsx +1 -1
  130. package/src/components/chat/types/.api.types.md +3 -1
  131. package/src/components/chat/types/.processing.types.md +23 -6
  132. package/src/components/chat/types/api.types.ts +73 -6
  133. package/src/components/chat/types/processing.types.ts +52 -11
  134. package/src/components/chat/utils/.chunk-parser.md +51 -0
  135. package/src/components/chat/utils/.index.md +5 -0
  136. package/src/components/chat/utils/chunk-parser.ts +255 -0
  137. package/src/components/chat/utils/extract-incomplete-message-state.ts +5 -63
  138. package/src/components/chat/utils/index.ts +8 -5
  139. package/src/components/chat/utils/process-historical-messages.ts +383 -352
  140. package/src/components/onboarding-guides/onboarding-guide-detail-view.tsx +4 -22
  141. package/src/components/shared/legal-document/legal-document-page.tsx +1 -1
  142. package/src/components/shared/product-release/release-detail-page.tsx +4 -19
  143. package/src/components/ui/.simple-markdown-renderer.md +40 -0
  144. package/src/components/ui/index.ts +2 -1
  145. package/src/components/ui/release-changelog-section.tsx +1 -1
  146. package/src/components/ui/rich-markdown-renderer.tsx +1223 -0
  147. package/src/components/ui/simple-markdown-renderer.tsx +965 -0
  148. package/src/components/ui/ticket-info-section.tsx +1 -1
  149. package/src/utils/index.ts +0 -1
  150. package/src/utils/markdown-section-extractor.ts +56 -41
  151. package/dist/chat-protocol/decode.d.ts +0 -58
  152. package/dist/chat-protocol/decode.d.ts.map +0 -1
  153. package/dist/chat-protocol/encode.d.ts +0 -44
  154. package/dist/chat-protocol/encode.d.ts.map +0 -1
  155. package/dist/chat-protocol/env-flag.d.ts +0 -35
  156. package/dist/chat-protocol/env-flag.d.ts.map +0 -1
  157. package/dist/chat-protocol/events.d.ts +0 -192
  158. package/dist/chat-protocol/events.d.ts.map +0 -1
  159. package/dist/chat-protocol/frames.d.ts +0 -206
  160. package/dist/chat-protocol/frames.d.ts.map +0 -1
  161. package/dist/chat-protocol/index.cjs +0 -493
  162. package/dist/chat-protocol/index.cjs.map +0 -1
  163. package/dist/chat-protocol/index.d.ts +0 -18
  164. package/dist/chat-protocol/index.d.ts.map +0 -1
  165. package/dist/chat-protocol/index.js +0 -477
  166. package/dist/chat-protocol/index.js.map +0 -1
  167. package/dist/chat-protocol/ip-normalize.d.ts +0 -44
  168. package/dist/chat-protocol/ip-normalize.d.ts.map +0 -1
  169. package/dist/chat-protocol/nats-decoder.d.ts +0 -26
  170. package/dist/chat-protocol/nats-decoder.d.ts.map +0 -1
  171. package/dist/chunk-4W54HUP7.cjs.map +0 -1
  172. package/dist/chunk-AJSNF5YF.js.map +0 -1
  173. package/dist/chunk-E6O6XATC.js.map +0 -1
  174. package/dist/chunk-OVIUQJ2H.cjs.map +0 -1
  175. package/dist/chunk-VUCYS36H.js.map +0 -1
  176. package/dist/chunk-WHWDGCQV.cjs.map +0 -1
  177. package/dist/components/chat/stream/chat-dialog-store.d.ts +0 -184
  178. package/dist/components/chat/stream/chat-dialog-store.d.ts.map +0 -1
  179. package/dist/components/chat/stream/chat-stream-reducer.d.ts +0 -367
  180. package/dist/components/chat/stream/chat-stream-reducer.d.ts.map +0 -1
  181. package/dist/components/chat/stream/delta-batcher.d.ts +0 -51
  182. package/dist/components/chat/stream/delta-batcher.d.ts.map +0 -1
  183. package/dist/components/chat/stream/index.d.ts +0 -17
  184. package/dist/components/chat/stream/index.d.ts.map +0 -1
  185. package/dist/components/chat/stream/message-mutations.d.ts +0 -77
  186. package/dist/components/chat/stream/message-mutations.d.ts.map +0 -1
  187. package/dist/components/chat/stream/use-chat-stream-reducer.d.ts +0 -22
  188. package/dist/components/chat/stream/use-chat-stream-reducer.d.ts.map +0 -1
  189. package/dist/components/ui/markdown/base-components.d.ts +0 -56
  190. package/dist/components/ui/markdown/base-components.d.ts.map +0 -1
  191. package/dist/components/ui/markdown/engine.d.ts +0 -99
  192. package/dist/components/ui/markdown/engine.d.ts.map +0 -1
  193. package/dist/components/ui/markdown/heading-ids.d.ts +0 -65
  194. package/dist/components/ui/markdown/heading-ids.d.ts.map +0 -1
  195. package/dist/components/ui/markdown/index.d.ts +0 -18
  196. package/dist/components/ui/markdown/index.d.ts.map +0 -1
  197. package/dist/components/ui/markdown/mermaid-diagram.d.ts +0 -79
  198. package/dist/components/ui/markdown/mermaid-diagram.d.ts.map +0 -1
  199. package/dist/components/ui/markdown/rich/embed-overrides.d.ts +0 -14
  200. package/dist/components/ui/markdown/rich/embed-overrides.d.ts.map +0 -1
  201. package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts +0 -40
  202. package/dist/components/ui/markdown/rich/rich-markdown-renderer.d.ts.map +0 -1
  203. package/dist/components/ui/markdown/rich/shortcodes.d.ts +0 -8
  204. package/dist/components/ui/markdown/rich/shortcodes.d.ts.map +0 -1
  205. package/dist/components/ui/markdown/sanitize.d.ts +0 -153
  206. package/dist/components/ui/markdown/sanitize.d.ts.map +0 -1
  207. package/dist/components/ui/markdown/simple-markdown-renderer.d.ts +0 -23
  208. package/dist/components/ui/markdown/simple-markdown-renderer.d.ts.map +0 -1
  209. package/dist/components/ui/markdown/streaming.d.ts +0 -78
  210. package/dist/components/ui/markdown/streaming.d.ts.map +0 -1
  211. package/dist/components/ui/markdown/text-size.d.ts +0 -34
  212. package/dist/components/ui/markdown/text-size.d.ts.map +0 -1
  213. package/dist/utils/markdown-fences.d.ts +0 -42
  214. package/dist/utils/markdown-fences.d.ts.map +0 -1
  215. package/dist/utils/markdown-heading-id.d.ts +0 -85
  216. package/dist/utils/markdown-heading-id.d.ts.map +0 -1
  217. package/src/chat-protocol/__tests__/__snapshots__/nats-decoder-golden.test.ts.snap +0 -307
  218. package/src/chat-protocol/__tests__/chat-protocol.test.ts +0 -515
  219. package/src/chat-protocol/__tests__/env-flag.test.ts +0 -52
  220. package/src/chat-protocol/__tests__/ip-normalize.test.ts +0 -136
  221. package/src/chat-protocol/__tests__/nats-decoder-golden.test.ts +0 -228
  222. package/src/chat-protocol/decode.ts +0 -277
  223. package/src/chat-protocol/encode.ts +0 -71
  224. package/src/chat-protocol/env-flag.ts +0 -39
  225. package/src/chat-protocol/events.ts +0 -228
  226. package/src/chat-protocol/frames.ts +0 -238
  227. package/src/chat-protocol/index.ts +0 -21
  228. package/src/chat-protocol/ip-normalize.ts +0 -146
  229. package/src/chat-protocol/nats-decoder.ts +0 -252
  230. package/src/components/chat/__tests__/chat-message-streaming-memo.test.tsx +0 -207
  231. package/src/components/chat/__tests__/chat-pending-turn.test.tsx +0 -209
  232. package/src/components/chat/hooks/__tests__/__snapshots__/persisted-state-v1-golden.test.ts.snap +0 -297
  233. package/src/components/chat/hooks/__tests__/__snapshots__/sse-stream-golden.test.ts.snap +0 -0
  234. package/src/components/chat/hooks/__tests__/persisted-state-v1-golden.test.ts +0 -272
  235. package/src/components/chat/hooks/__tests__/sse-stream-golden.test.ts +0 -318
  236. package/src/components/chat/stream/__tests__/__snapshots__/chat-stream-reducer-golden.test.ts.snap +0 -937
  237. package/src/components/chat/stream/__tests__/chat-dialog-store.test.ts +0 -756
  238. package/src/components/chat/stream/__tests__/chat-stream-reducer-golden.test.ts +0 -460
  239. package/src/components/chat/stream/__tests__/chat-stream-reducer.test.ts +0 -894
  240. package/src/components/chat/stream/__tests__/delta-batcher.test.ts +0 -255
  241. package/src/components/chat/stream/__tests__/use-chat-stream-reducer.test.ts +0 -98
  242. package/src/components/chat/stream/chat-dialog-store.ts +0 -536
  243. package/src/components/chat/stream/chat-stream-reducer.ts +0 -1796
  244. package/src/components/chat/stream/delta-batcher.ts +0 -159
  245. package/src/components/chat/stream/index.ts +0 -55
  246. package/src/components/chat/stream/message-mutations.ts +0 -338
  247. package/src/components/chat/stream/use-chat-stream-reducer.ts +0 -126
  248. package/src/components/chat/utils/__tests__/__snapshots__/process-historical-messages-golden.test.ts.snap +0 -418
  249. package/src/components/chat/utils/__tests__/__snapshots__/segment-accumulator-golden.test.ts.snap +0 -599
  250. package/src/components/chat/utils/__tests__/process-historical-messages-golden.test.ts +0 -317
  251. package/src/components/chat/utils/__tests__/segment-accumulator-golden.test.ts +0 -270
  252. package/src/components/ui/__tests__/__snapshots__/markdown-parity.test.tsx.snap +0 -2420
  253. package/src/components/ui/__tests__/markdown-parity.test.tsx +0 -2528
  254. package/src/components/ui/markdown/__tests__/mermaid-security.test.ts +0 -115
  255. package/src/components/ui/markdown/__tests__/mermaid-stale-render.test.tsx +0 -95
  256. package/src/components/ui/markdown/__tests__/sanitize-invariant.test.ts +0 -309
  257. package/src/components/ui/markdown/__tests__/streaming.test.tsx +0 -388
  258. package/src/components/ui/markdown/base-components.tsx +0 -341
  259. package/src/components/ui/markdown/engine.tsx +0 -315
  260. package/src/components/ui/markdown/heading-ids.ts +0 -239
  261. package/src/components/ui/markdown/index.ts +0 -49
  262. package/src/components/ui/markdown/mermaid-diagram.tsx +0 -291
  263. package/src/components/ui/markdown/rich/embed-overrides.tsx +0 -199
  264. package/src/components/ui/markdown/rich/rich-markdown-renderer.tsx +0 -184
  265. package/src/components/ui/markdown/rich/shortcodes.ts +0 -170
  266. package/src/components/ui/markdown/sanitize.ts +0 -3499
  267. package/src/components/ui/markdown/simple-markdown-renderer.tsx +0 -28
  268. package/src/components/ui/markdown/streaming.ts +0 -362
  269. package/src/components/ui/markdown/text-size.ts +0 -106
  270. package/src/utils/markdown-fences.ts +0 -127
  271. package/src/utils/markdown-heading-id.ts +0 -348
  272. /package/dist/{chunk-33FDAZDB.js.map → chunk-3TU6QURP.js.map} +0 -0
  273. /package/dist/{chunk-2BJSRTKU.js.map → chunk-AEM7ADDG.js.map} +0 -0
  274. /package/dist/{chunk-MMF6HJB7.js.map → chunk-EZESVVIM.js.map} +0 -0
  275. /package/dist/{chunk-AW3LVWVV.js.map → chunk-HTSWLPMU.js.map} +0 -0
  276. /package/dist/{chunk-RPAOSHBN.js.map → chunk-IUMPVRSH.js.map} +0 -0
  277. /package/dist/{chunk-7I2QMUEZ.js.map → chunk-JW3UNHGW.js.map} +0 -0
  278. /package/dist/{chunk-GYEZV4GK.js.map → chunk-QTGYQ2U7.js.map} +0 -0
  279. /package/dist/{chunk-4QDFNDVW.js.map → chunk-QZJN5OHK.js.map} +0 -0
  280. /package/dist/{chunk-DG7TX763.js.map → chunk-VYUEOKI6.js.map} +0 -0
@@ -1,477 +0,0 @@
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