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