@flamingo-stack/openframe-frontend-core 0.0.609-snapshot.20260908170120 → 0.0.609

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 (153) hide show
  1. package/dist/chat-protocol/events.d.ts +2 -21
  2. package/dist/chat-protocol/events.d.ts.map +1 -1
  3. package/dist/chat-protocol/index.cjs +9 -211
  4. package/dist/chat-protocol/index.cjs.map +1 -1
  5. package/dist/chat-protocol/index.js +9 -211
  6. package/dist/chat-protocol/index.js.map +1 -1
  7. package/dist/chat-protocol/nats-decoder.d.ts.map +1 -1
  8. package/dist/{chunk-2YMDDD5V.cjs → chunk-3N4FXBVJ.cjs} +3 -3
  9. package/dist/{chunk-2YMDDD5V.cjs.map → chunk-3N4FXBVJ.cjs.map} +1 -1
  10. package/dist/{chunk-THCB7NHV.cjs → chunk-3XNMDLGB.cjs} +9 -9
  11. package/dist/{chunk-THCB7NHV.cjs.map → chunk-3XNMDLGB.cjs.map} +1 -1
  12. package/dist/{chunk-GFAHCXIL.cjs → chunk-45XXK2VU.cjs} +10 -10
  13. package/dist/{chunk-GFAHCXIL.cjs.map → chunk-45XXK2VU.cjs.map} +1 -1
  14. package/dist/{chunk-2QBXG74C.js → chunk-6MLRFM3T.js} +5 -5
  15. package/dist/{chunk-IBMHEOBV.js → chunk-B3UXNGVM.js} +3 -3
  16. package/dist/{chunk-O6PO5BHE.js → chunk-B7LYKBCD.js} +5 -5
  17. package/dist/{chunk-F2C2U7CP.js → chunk-BSMPCPOZ.js} +299 -590
  18. package/dist/chunk-BSMPCPOZ.js.map +1 -0
  19. package/dist/{chunk-MGXSJI23.js → chunk-BUXGWBTF.js} +2 -2
  20. package/dist/{chunk-OIKZDXNW.js → chunk-C7CTEUU7.js} +2 -2
  21. package/dist/{chunk-EANAFFAD.cjs → chunk-CZTOSG7Q.cjs} +22 -22
  22. package/dist/{chunk-EANAFFAD.cjs.map → chunk-CZTOSG7Q.cjs.map} +1 -1
  23. package/dist/{chunk-C4KQ2XPK.cjs → chunk-D3DTC7SZ.cjs} +15 -15
  24. package/dist/{chunk-C4KQ2XPK.cjs.map → chunk-D3DTC7SZ.cjs.map} +1 -1
  25. package/dist/{chunk-HKJ3WKGW.cjs → chunk-DKNXAJMP.cjs} +159 -159
  26. package/dist/{chunk-HKJ3WKGW.cjs.map → chunk-DKNXAJMP.cjs.map} +1 -1
  27. package/dist/{chunk-UFFVMZDL.cjs → chunk-FYG7QNAO.cjs} +5 -5
  28. package/dist/{chunk-UFFVMZDL.cjs.map → chunk-FYG7QNAO.cjs.map} +1 -1
  29. package/dist/{chunk-THCSSPXU.cjs → chunk-GMOBT5NP.cjs} +70 -70
  30. package/dist/{chunk-THCSSPXU.cjs.map → chunk-GMOBT5NP.cjs.map} +1 -1
  31. package/dist/{chunk-HQSCJYCF.js → chunk-HGVW7OHI.js} +2 -2
  32. package/dist/{chunk-FS3CTGIR.js → chunk-JKM5FH63.js} +3 -3
  33. package/dist/{chunk-37CAZTLP.js → chunk-JOCVQZGT.js} +5 -5
  34. package/dist/{chunk-ROOIHDLS.js → chunk-JR7I2AGL.js} +3 -3
  35. package/dist/{chunk-OVVKVIMH.cjs → chunk-L2JWC5VS.cjs} +43 -43
  36. package/dist/{chunk-OVVKVIMH.cjs.map → chunk-L2JWC5VS.cjs.map} +1 -1
  37. package/dist/{chunk-25YIHMZ6.js → chunk-LA2W5L6K.js} +2 -2
  38. package/dist/{chunk-V6TINNLD.js → chunk-MVBRMQGU.js} +2 -2
  39. package/dist/{chunk-Q3APHZK5.cjs → chunk-NJUSDREV.cjs} +22 -22
  40. package/dist/{chunk-Q3APHZK5.cjs.map → chunk-NJUSDREV.cjs.map} +1 -1
  41. package/dist/{chunk-FASOANK7.cjs → chunk-O2M4T34Q.cjs} +4 -4
  42. package/dist/{chunk-FASOANK7.cjs.map → chunk-O2M4T34Q.cjs.map} +1 -1
  43. package/dist/{chunk-R2UDEMKK.js → chunk-OTYV6SDN.js} +3 -3
  44. package/dist/{chunk-HZS4TV34.js → chunk-QX4ANESW.js} +6 -6
  45. package/dist/{chunk-ZDLCWNM6.cjs → chunk-RZM6FPOT.cjs} +25 -25
  46. package/dist/{chunk-ZDLCWNM6.cjs.map → chunk-RZM6FPOT.cjs.map} +1 -1
  47. package/dist/{chunk-GNLV326I.cjs → chunk-SEW25Y2W.cjs} +10 -10
  48. package/dist/{chunk-GNLV326I.cjs.map → chunk-SEW25Y2W.cjs.map} +1 -1
  49. package/dist/{chunk-QE2Z6WME.cjs → chunk-TCEALWE3.cjs} +33 -33
  50. package/dist/{chunk-QE2Z6WME.cjs.map → chunk-TCEALWE3.cjs.map} +1 -1
  51. package/dist/{chunk-OJZW3GE2.js → chunk-TJ3GFULR.js} +3 -3
  52. package/dist/{chunk-Q2CNCBMK.js → chunk-VCYRJY7J.js} +4 -4
  53. package/dist/{chunk-YXTAV2E3.cjs → chunk-XNDTYTVT.cjs} +683 -974
  54. package/dist/chunk-XNDTYTVT.cjs.map +1 -0
  55. package/dist/{chunk-WJQOYSR3.cjs → chunk-ZRLFBLME.cjs} +3 -3
  56. package/dist/{chunk-WJQOYSR3.cjs.map → chunk-ZRLFBLME.cjs.map} +1 -1
  57. package/dist/components/case-studies/index.cjs +9 -9
  58. package/dist/components/case-studies/index.js +3 -3
  59. package/dist/components/chat/chat-message-enhanced.d.ts.map +1 -1
  60. package/dist/components/chat/chat-message-list.d.ts.map +1 -1
  61. package/dist/components/chat/embeddable-chat.d.ts.map +1 -1
  62. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts +28 -5
  63. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
  64. package/dist/components/chat/index.cjs +2 -2
  65. package/dist/components/chat/index.js +1 -1
  66. package/dist/components/chat/remark-card-links.d.ts +4 -5
  67. package/dist/components/chat/remark-card-links.d.ts.map +1 -1
  68. package/dist/components/chat/stream/chat-stream-reducer.d.ts.map +1 -1
  69. package/dist/components/chat/tool-execution-display.d.ts.map +1 -1
  70. package/dist/components/chat/types/component.types.d.ts +0 -27
  71. package/dist/components/chat/types/component.types.d.ts.map +1 -1
  72. package/dist/components/chat/types/message.types.d.ts +1 -81
  73. package/dist/components/chat/types/message.types.d.ts.map +1 -1
  74. package/dist/components/chat/types/unified-chat-state.types.d.ts +3 -12
  75. package/dist/components/chat/types/unified-chat-state.types.d.ts.map +1 -1
  76. package/dist/components/chat/utils/process-historical-messages.d.ts.map +1 -1
  77. package/dist/components/contact/index.cjs +4 -4
  78. package/dist/components/contact/index.js +3 -3
  79. package/dist/components/docs/index.cjs +7 -7
  80. package/dist/components/docs/index.js +6 -6
  81. package/dist/components/embeds/index.cjs +4 -4
  82. package/dist/components/embeds/index.js +3 -3
  83. package/dist/components/faq/index.cjs +4 -4
  84. package/dist/components/faq/index.js +3 -3
  85. package/dist/components/features/index.cjs +3 -3
  86. package/dist/components/features/index.js +2 -2
  87. package/dist/components/help-center-pages/index.cjs +23 -23
  88. package/dist/components/help-center-pages/index.js +14 -14
  89. package/dist/components/index.cjs +38 -38
  90. package/dist/components/index.js +13 -13
  91. package/dist/components/meeting-scheduler/index.cjs +24 -24
  92. package/dist/components/meeting-scheduler/index.js +2 -2
  93. package/dist/components/navigation/index.cjs +6 -6
  94. package/dist/components/navigation/index.js +5 -5
  95. package/dist/components/onboarding-guides/index.cjs +6 -6
  96. package/dist/components/onboarding-guides/index.js +5 -5
  97. package/dist/components/tickets/index.cjs +7 -7
  98. package/dist/components/tickets/index.js +6 -6
  99. package/dist/components/ui/index.cjs +3 -3
  100. package/dist/components/ui/index.js +2 -2
  101. package/dist/index.cjs +7 -7
  102. package/dist/index.js +6 -6
  103. package/dist/utils/index.cjs.map +1 -1
  104. package/dist/utils/index.js.map +1 -1
  105. package/package.json +1 -1
  106. package/src/chat-protocol/events.ts +1 -22
  107. package/src/chat-protocol/nats-decoder.ts +0 -12
  108. package/src/components/chat/chat-message-enhanced.tsx +12 -37
  109. package/src/components/chat/chat-message-list.tsx +1 -14
  110. package/src/components/chat/embeddable-chat.tsx +87 -47
  111. package/src/components/chat/hooks/use-sse-chat-adapter.ts +28 -5
  112. package/src/components/chat/remark-card-links.ts +12 -14
  113. package/src/components/chat/stream/chat-stream-reducer.ts +3 -48
  114. package/src/components/chat/tool-execution-display.tsx +4 -18
  115. package/src/components/chat/types/component.types.ts +0 -27
  116. package/src/components/chat/types/message.types.ts +0 -83
  117. package/src/components/chat/types/unified-chat-state.types.ts +3 -12
  118. package/src/components/chat/utils/process-historical-messages.ts +0 -25
  119. package/dist/chat-protocol/card-marker.d.ts +0 -31
  120. package/dist/chat-protocol/card-marker.d.ts.map +0 -1
  121. package/dist/chat-protocol/source-metadata.d.ts +0 -56
  122. package/dist/chat-protocol/source-metadata.d.ts.map +0 -1
  123. package/dist/chunk-F2C2U7CP.js.map +0 -1
  124. package/dist/chunk-YXTAV2E3.cjs.map +0 -1
  125. package/dist/components/chat/utils/cited-sources.d.ts +0 -24
  126. package/dist/components/chat/utils/cited-sources.d.ts.map +0 -1
  127. package/dist/components/chat/utils/host-message.d.ts +0 -41
  128. package/dist/components/chat/utils/host-message.d.ts.map +0 -1
  129. package/src/chat-protocol/__tests__/card-marker.test.ts +0 -63
  130. package/src/chat-protocol/__tests__/source-metadata.test.ts +0 -243
  131. package/src/chat-protocol/card-marker.ts +0 -40
  132. package/src/chat-protocol/source-metadata.ts +0 -336
  133. package/src/components/chat/__tests__/tool-execution-display.test.tsx +0 -70
  134. package/src/components/chat/utils/__tests__/cited-sources.test.ts +0 -80
  135. package/src/components/chat/utils/__tests__/host-message.test.ts +0 -92
  136. package/src/components/chat/utils/__tests__/process-historical-messages-sources.test.ts +0 -138
  137. package/src/components/chat/utils/cited-sources.ts +0 -61
  138. package/src/components/chat/utils/host-message.ts +0 -87
  139. /package/dist/{chunk-2QBXG74C.js.map → chunk-6MLRFM3T.js.map} +0 -0
  140. /package/dist/{chunk-IBMHEOBV.js.map → chunk-B3UXNGVM.js.map} +0 -0
  141. /package/dist/{chunk-O6PO5BHE.js.map → chunk-B7LYKBCD.js.map} +0 -0
  142. /package/dist/{chunk-MGXSJI23.js.map → chunk-BUXGWBTF.js.map} +0 -0
  143. /package/dist/{chunk-OIKZDXNW.js.map → chunk-C7CTEUU7.js.map} +0 -0
  144. /package/dist/{chunk-HQSCJYCF.js.map → chunk-HGVW7OHI.js.map} +0 -0
  145. /package/dist/{chunk-FS3CTGIR.js.map → chunk-JKM5FH63.js.map} +0 -0
  146. /package/dist/{chunk-37CAZTLP.js.map → chunk-JOCVQZGT.js.map} +0 -0
  147. /package/dist/{chunk-ROOIHDLS.js.map → chunk-JR7I2AGL.js.map} +0 -0
  148. /package/dist/{chunk-25YIHMZ6.js.map → chunk-LA2W5L6K.js.map} +0 -0
  149. /package/dist/{chunk-V6TINNLD.js.map → chunk-MVBRMQGU.js.map} +0 -0
  150. /package/dist/{chunk-R2UDEMKK.js.map → chunk-OTYV6SDN.js.map} +0 -0
  151. /package/dist/{chunk-HZS4TV34.js.map → chunk-QX4ANESW.js.map} +0 -0
  152. /package/dist/{chunk-OJZW3GE2.js.map → chunk-TJ3GFULR.js.map} +0 -0
  153. /package/dist/{chunk-Q2CNCBMK.js.map → chunk-VCYRJY7J.js.map} +0 -0
@@ -1,24 +0,0 @@
1
- import type { ChatSource } from '../types/message.types';
2
- /** How many retrieved sources to show when the answer cited none of them. */
3
- export declare const FALLBACK_TOP_RETRIEVED = 3;
4
- export interface CitedSources {
5
- /** Sources the answer referenced, in the order the answer first referenced
6
- * them — NOT in `index` order. */
7
- cited: ChatSource[];
8
- /** Everything retrieved but not referenced, in the order supplied. */
9
- uncited: ChatSource[];
10
- }
11
- /**
12
- * Split an answer's sources into the ones it cited and the ones it did not.
13
- *
14
- * Reading order, not numeric order: the strip is a legend for the sentences
15
- * above it, so the chip for the citation the reader meets first comes first,
16
- * even when the model numbered it `[3]`. A number cited twice is placed once,
17
- * at its first mention.
18
- *
19
- * `content` is the flat answer text. A segmented message has to be flattened by
20
- * the caller — citation markers live in text segments, and this function
21
- * deliberately does not know what a segment is.
22
- */
23
- export declare function splitCitedSources(sources: ChatSource[] | undefined, content: string): CitedSources;
24
- //# sourceMappingURL=cited-sources.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cited-sources.d.ts","sourceRoot":"","sources":["../../../../src/components/chat/utils/cited-sources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,6EAA6E;AAC7E,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,MAAM,WAAW,YAAY;IAC3B;uCACmC;IACnC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,sEAAsE;IACtE,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAuBD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CAclG"}
@@ -1,41 +0,0 @@
1
- /**
2
- * `UnifiedChatMessage` (what the chat state produces, and what a host like
3
- * Mingo hands in) → `Message` (what the thread renders).
4
- *
5
- * The two types overlap but are not the same: this step resolves the role's
6
- * default name and avatar, folds `segments` back into `content`, and stamps a
7
- * timestamp for rows that arrived without one. So it is a REBUILD, and a
8
- * rebuild names every field it keeps — which makes "a new field was added
9
- * upstream" a silent data loss by default, not a compile error.
10
- *
11
- * It has cost us that twice already. `hidden` was dropped here, and a synthetic
12
- * directive the reader was never meant to see rendered as an ordinary bubble.
13
- * Then Guide Mode's `sources` / `refs` were dropped here, and every answer lost
14
- * its citation strip while its cards fell back to being titled by their own id
15
- * — with the decoder, the reducer and the renderer all working correctly, which
16
- * is exactly why it took a screenshot diff to find.
17
- *
18
- * Hence this module: pure, cheap to render-free test, and the one place the
19
- * pass-through list is pinned.
20
- */
21
- import type { Message } from '../types/message.types';
22
- import type { UnifiedChatMessage } from '../types/unified-chat-state.types';
23
- export interface HostMessageMapOptions {
24
- /** Display name for `user` rows when the host supplies none. */
25
- userName?: string;
26
- /** Avatar for `user` rows when the host supplies none. */
27
- userAvatar?: string;
28
- /**
29
- * Fallback timestamps for rows that carry none, keyed by message id. Mutated:
30
- * a row must keep the SAME fallback across renders, or its bubble re-stamps
31
- * itself on every keystroke elsewhere in the thread.
32
- */
33
- timestampCache: Map<string, Date>;
34
- }
35
- export declare function mapHostMessage(m: UnifiedChatMessage, options: HostMessageMapOptions): Message;
36
- /**
37
- * Drop cached fallback timestamps for messages no longer in the thread, so the
38
- * map cannot grow unbounded across a long-lived session.
39
- */
40
- export declare function pruneTimestampCache(timestampCache: Map<string, Date>, liveIds: Set<string>): void;
41
- //# sourceMappingURL=host-message.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"host-message.d.ts","sourceRoot":"","sources":["../../../../src/components/chat/utils/host-message.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAE5E,MAAM,WAAW,qBAAqB;IACpC,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CACnC;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,kBAAkB,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAsC7F;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAKjG"}
@@ -1,63 +0,0 @@
1
- /**
2
- * The `[card://…]` grammar has THREE readers, and they only work as a set:
3
- *
4
- * 1. `remarkCardLinks` — turns a marker in the body into a card node;
5
- * 2. the pre-scan in `chat-message-enhanced.tsx` — splits the text at it and
6
- * places the card's block payload;
7
- * 3. `source-metadata.ts` — validates the `ref` field describing it.
8
- *
9
- * A marker one accepts and another rejects fails silently and asymmetrically:
10
- * the pre-scan splitting a marker the plugin will not convert leaves the reader
11
- * looking at a literal `[card://…]` mid-sentence, and a decoder stricter than
12
- * the body drops the title of a card the answer explicitly points at.
13
- *
14
- * So this pins the grammar itself, including the punctuation the backend allows
15
- * in an id — which is what made the three diverge in the first place.
16
- */
17
-
18
- import { describe, expect, it } from 'vitest';
19
- import { CARD_REFERENCE, createCardMarkerScanner } from '../card-marker';
20
-
21
- /** The id half as the backend validates it: anything but `]` and newlines. */
22
- const PUNCTUATED_IDS = [
23
- '88dd40cc-66f5-4175-be60-6f34b054a5f1',
24
- 'docs/setup.v2.md',
25
- 'customer_interview.2026',
26
- 'MdFJNoJeqZQ',
27
- ];
28
-
29
- describe('card marker grammar', () => {
30
- it.each(PUNCTUATED_IDS)('matches an id the backend accepts: %s', id => {
31
- const marker = `[card://markdown:${id}]`;
32
- const scanner = createCardMarkerScanner();
33
-
34
- expect(scanner.exec(marker)?.[2]).toBe(id);
35
- expect(CARD_REFERENCE.exec(marker)?.[2]).toBe(id);
36
- });
37
-
38
- it('stops the id at the marker’s own closer, not the next one', () => {
39
- // Greedy without this and two adjacent markers read as one.
40
- const scanner = createCardMarkerScanner();
41
- const found = [...'[card://faq:a] and [card://faq:b]'.matchAll(scanner)].map(m => m[2]);
42
-
43
- expect(found).toEqual(['a', 'b']);
44
- });
45
-
46
- it('accepts `)` as a closer in the body but not in a `ref` field', () => {
47
- // The LLM drifts to `)` after long opaque ids, so the body tolerates it.
48
- // A `ref` is machine-written and has no such excuse.
49
- const drifted = '[card://podcast:9b2f)';
50
-
51
- expect(createCardMarkerScanner().exec(drifted)?.[2]).toBe('9b2f');
52
- expect(CARD_REFERENCE.exec(drifted)).toBeNull();
53
- });
54
-
55
- it('rejects a marker whose id is empty or spans a line break', () => {
56
- expect(createCardMarkerScanner().exec('[card://faq:]')).toBeNull();
57
- expect(createCardMarkerScanner().exec('[card://faq:a\nb]')).toBeNull();
58
- });
59
-
60
- it('anchors `CARD_REFERENCE`, so a ref cannot carry trailing text', () => {
61
- expect(CARD_REFERENCE.exec('[card://faq:a] plus a note')).toBeNull();
62
- });
63
- });
@@ -1,243 +0,0 @@
1
- /**
2
- * The source-metadata decoder is the ONE parse point for both arrival paths —
3
- * the live `GUIDE`/`SOURCES` chunk and the persisted row of the same name — so
4
- * what it accepts is exactly what a reloaded answer will show. These pin the
5
- * accept/reject line, because every rejection here is a chip, card or video the
6
- * reader silently does not get.
7
- */
8
-
9
- import { describe, expect, it } from 'vitest';
10
- import { decodeNatsChunk } from '../nats-decoder';
11
- import { mergeSourceMetadata, sourceMetadataEvent, youtubeVideoId } from '../source-metadata';
12
-
13
- const AGENT_GUIDE = {
14
- index: 1,
15
- name: 'Install the OpenFrame Agent on Windows',
16
- path: 'onboarding-guides/install-the-openframe-agent-on-windows',
17
- documentType: 'onboarding_guide',
18
- externalUrl: 'https://hub.openframe.ai/onboarding-guides/install-the-openframe-agent-on-windows',
19
- targetPlatform: 'openframe',
20
- id: '88dd40cc-66f5-4175-be60-6f34b054a5f1',
21
- sourceRepo: 'onboarding-guides',
22
- };
23
-
24
- describe('sourceMetadataEvent', () => {
25
- it('decodes the documented payload into sources and refs', () => {
26
- const event = sourceMetadataEvent({
27
- sources: [AGENT_GUIDE],
28
- videos: [
29
- {
30
- ref: '[card://video:MdFJNoJeqZQ]',
31
- id: 'MdFJNoJeqZQ',
32
- title: 'Install the OpenFrame agent on Windows',
33
- url: 'https://www.youtube.com/watch?v=MdFJNoJeqZQ',
34
- sourceRepo: 'embedded-videos',
35
- },
36
- ],
37
- cards: [
38
- {
39
- ref: '[card://onboarding_guide:88dd40cc-66f5-4175-be60-6f34b054a5f1]',
40
- entityType: 'onboarding_guide',
41
- entityId: '88dd40cc-66f5-4175-be60-6f34b054a5f1',
42
- },
43
- ],
44
- });
45
-
46
- expect(event?.sources).toEqual([AGENT_GUIDE]);
47
- expect(event?.refs).toEqual([
48
- {
49
- type: 'video',
50
- id: 'MdFJNoJeqZQ',
51
- title: 'Install the OpenFrame agent on Windows',
52
- url: 'https://www.youtube.com/watch?v=MdFJNoJeqZQ',
53
- sourceRepo: 'embedded-videos',
54
- metadata: { youtubeUrl: 'MdFJNoJeqZQ' },
55
- },
56
- {
57
- // Enriched from the matching source: the card itself carries only
58
- // type + id, so without this the reader sees a UUID for a title.
59
- type: 'onboarding_guide',
60
- id: '88dd40cc-66f5-4175-be60-6f34b054a5f1',
61
- title: 'Install the OpenFrame Agent on Windows',
62
- url: AGENT_GUIDE.externalUrl,
63
- sourceRepo: 'onboarding-guides',
64
- targetPlatform: 'openframe',
65
- metadata: { path: AGENT_GUIDE.path },
66
- },
67
- ]);
68
- });
69
-
70
- it('keeps a card whose source is missing, titled by its id', () => {
71
- // Dropping it would leave the `[card://…]` marker in the answer text with
72
- // nothing to expand — a visibly broken sentence beats a plain-looking card.
73
- const event = sourceMetadataEvent({
74
- cards: [{ ref: '[card://device:device-42]', entityType: 'device', entityId: 'device-42' }],
75
- });
76
- expect(event?.refs).toEqual([{ type: 'device', id: 'device-42', title: 'device-42', url: null }]);
77
- });
78
-
79
- it('accepts an id the backend accepts, even with punctuation in it', () => {
80
- // The backend validates the id half as "anything but ] and newlines". A
81
- // stricter rule here drops metadata for a marker already written into the body.
82
- const event = sourceMetadataEvent({
83
- cards: [{ ref: '[card://markdown:docs/setup.v2.md]', entityType: 'markdown', entityId: 'docs/setup.v2.md' }],
84
- });
85
- expect(event?.refs?.[0]).toMatchObject({ type: 'markdown', id: 'docs/setup.v2.md' });
86
- });
87
-
88
- it('keeps a source that has no path', () => {
89
- // `path` is one of several ways a chip resolves a destination, not a
90
- // precondition for showing the citation at all.
91
- const event = sourceMetadataEvent({ sources: [{ index: 1, name: 'Release notes', documentType: 'blog_post' }] });
92
- expect(event?.sources).toEqual([{ index: 1, name: 'Release notes', path: '', documentType: 'blog_post' }]);
93
- });
94
-
95
- it('drops a source with no citation number or no name', () => {
96
- const event = sourceMetadataEvent({
97
- sources: [{ name: 'No index' }, { index: 2 }, { index: 0, name: 'Zero' }, { index: 3, name: 'Kept' }],
98
- });
99
- expect(event?.sources).toEqual([{ index: 3, name: 'Kept', path: '', documentType: '' }]);
100
- });
101
-
102
- it('keeps the first source claiming a citation number', () => {
103
- const event = sourceMetadataEvent({
104
- sources: [
105
- { index: 1, name: 'First' },
106
- { index: 1, name: 'Second' },
107
- ],
108
- });
109
- expect(event?.sources).toHaveLength(1);
110
- expect(event?.sources?.[0].name).toBe('First');
111
- });
112
-
113
- it('drops a non-https external URL but keeps the source', () => {
114
- const event = sourceMetadataEvent({
115
- sources: [{ index: 1, name: 'Doc', path: 'docs/x', documentType: 'markdown', externalUrl: 'http://x.test/x' }],
116
- });
117
- expect(event?.sources?.[0]).not.toHaveProperty('externalUrl');
118
- });
119
-
120
- it('preserves an explicit null targetPlatform, which means "no destination"', () => {
121
- const event = sourceMetadataEvent({
122
- sources: [{ index: 1, name: 'Doc', path: 'docs/x', documentType: 'markdown', targetPlatform: null }],
123
- });
124
- expect(event?.sources?.[0].targetPlatform).toBeNull();
125
- });
126
-
127
- it('drops malformed video and card rows', () => {
128
- const event = sourceMetadataEvent({
129
- videos: [{ ref: 'card://video:x' }, { id: 'no-ref' }, { ref: '[card://video:ok]' }],
130
- cards: [
131
- // entityType disagrees with the parsed ref — the row was built wrongly.
132
- { ref: '[card://faq:a]', entityType: 'blog_post', entityId: 'a' },
133
- // a card must not claim the video type: it would render without a player
134
- { ref: '[card://video:b]', entityType: 'video', entityId: 'b' },
135
- ],
136
- });
137
- expect(event?.refs).toEqual([{ type: 'video', id: 'ok', title: 'ok', url: null }]);
138
- });
139
-
140
- it('keeps the first ref per type:id', () => {
141
- const event = sourceMetadataEvent({
142
- videos: [
143
- { ref: '[card://video:a]', title: 'First' },
144
- { ref: '[card://video:a]', title: 'Second' },
145
- ],
146
- });
147
- expect(event?.refs).toHaveLength(1);
148
- expect(event?.refs?.[0].title).toBe('First');
149
- });
150
-
151
- it('carries a YouTube video as a bare id under the dispatcher’s key', () => {
152
- // `youtubeUrl` holding an ID is the lib's existing vocabulary — see the
153
- // note on `videoMetadata`. The card dispatcher reads exactly this key.
154
- const event = sourceMetadataEvent({
155
- videos: [{ ref: '[card://video:MdFJNoJeqZQ]', url: 'https://youtu.be/MdFJNoJeqZQ' }],
156
- });
157
- expect(event?.refs?.[0].metadata).toEqual({ youtubeUrl: 'MdFJNoJeqZQ' });
158
- });
159
-
160
- it('routes a non-YouTube video URL to the plain player', () => {
161
- // Mux/HLS and direct mp4 are played as a video source, not an embed.
162
- const hls = sourceMetadataEvent({
163
- videos: [{ ref: '[card://video:mux-9b]', url: 'https://stream.mux.com/install-agent.m3u8' }],
164
- });
165
- expect(hls?.refs?.[0].metadata).toEqual({ videoUrl: 'https://stream.mux.com/install-agent.m3u8' });
166
-
167
- const mp4 = sourceMetadataEvent({ videos: [{ ref: '[card://video:v1]', url: 'https://cdn.test/a.mp4' }] });
168
- expect(mp4?.refs?.[0].metadata).toEqual({ videoUrl: 'https://cdn.test/a.mp4' });
169
- });
170
-
171
- it('returns null when nothing survives, so it cannot blank earlier metadata', () => {
172
- expect(sourceMetadataEvent({ sources: [], videos: [], cards: [] })).toBeNull();
173
- expect(sourceMetadataEvent({ sources: [{ name: 'no index' }] })).toBeNull();
174
- expect(sourceMetadataEvent(null)).toBeNull();
175
- expect(sourceMetadataEvent('nope')).toBeNull();
176
- });
177
- });
178
-
179
- describe('youtubeVideoId', () => {
180
- it.each([
181
- ['MdFJNoJeqZQ', 'a bare id'],
182
- ['https://www.youtube.com/watch?v=MdFJNoJeqZQ', 'a watch URL'],
183
- ['https://youtu.be/MdFJNoJeqZQ', 'a short link'],
184
- ['https://www.youtube.com/shorts/MdFJNoJeqZQ', 'a shorts URL'],
185
- ['https://www.youtube.com/embed/MdFJNoJeqZQ', 'an embed URL'],
186
- ])('reads %s (%s)', value => {
187
- expect(youtubeVideoId(value)).toBe('MdFJNoJeqZQ');
188
- });
189
-
190
- it.each([
191
- ['https://vimeo.com/12345', 'another host'],
192
- ['http://www.youtube.com/watch?v=MdFJNoJeqZQ', 'plain http'],
193
- ['https://www.youtube.com/watch?v=short', 'an id of the wrong length'],
194
- ['', 'nothing'],
195
- ])('rejects %s (%s)', value => {
196
- expect(youtubeVideoId(value)).toBeUndefined();
197
- });
198
- });
199
-
200
- describe('decodeNatsChunk — source metadata', () => {
201
- it('decodes both chunk names through the same path', () => {
202
- const payload = { sources: [{ index: 1, name: 'Doc', path: 'docs/x', documentType: 'markdown' }] };
203
- const guide = decodeNatsChunk({ type: 'GUIDE', payload, streamSeq: 7 });
204
- const sources = decodeNatsChunk({ type: 'SOURCES', payload, streamSeq: 7 });
205
-
206
- expect(guide).toEqual({ type: 'sources', sources: payload.sources, seq: 7 });
207
- expect(sources).toEqual(guide);
208
- });
209
-
210
- it('drops a chunk with an empty payload rather than emitting an empty event', () => {
211
- expect(decodeNatsChunk({ type: 'GUIDE', payload: {} })).toBeNull();
212
- expect(decodeNatsChunk({ type: 'GUIDE' })).toBeNull();
213
- });
214
- });
215
-
216
- describe('mergeSourceMetadata', () => {
217
- const first = { type: 'sources' as const, sources: [{ index: 1, name: 'First', path: '', documentType: '' }] };
218
-
219
- it('unions the metadata of several tool calls in one turn', () => {
220
- const merged = mergeSourceMetadata(mergeSourceMetadata(null, first), {
221
- type: 'sources',
222
- sources: [{ index: 2, name: 'Second', path: '', documentType: '' }],
223
- refs: [{ type: 'video', id: 'v1', title: 'V', url: null }],
224
- });
225
-
226
- expect(merged.sources?.map(s => s.index)).toEqual([1, 2]);
227
- expect(merged.refs).toHaveLength(1);
228
- });
229
-
230
- it('keeps the first claimant of a citation number', () => {
231
- // Numbers are assigned per tool result, so two calls can both claim [1].
232
- // The text already says [1]; renumbering would re-point the sentence.
233
- const merged = mergeSourceMetadata(mergeSourceMetadata(null, first), {
234
- type: 'sources',
235
- sources: [{ index: 1, name: 'Collides', path: '', documentType: '' }],
236
- });
237
- expect(merged.sources).toEqual(first.sources);
238
- });
239
-
240
- it('starts from nothing without inventing empty arrays', () => {
241
- expect(mergeSourceMetadata(null, { type: 'sources' })).toEqual({});
242
- });
243
- });
@@ -1,40 +0,0 @@
1
- /**
2
- * The `[card://<type>:<id>]` marker grammar — ONE definition, two readers.
3
- *
4
- * The model writes these markers into the answer body, and the metadata frame
5
- * describes the same references separately. Two parsers therefore have to agree
6
- * on what counts as a marker: the payload decoder (`source-metadata.ts`) and the
7
- * body renderer (`chat-message-enhanced.tsx`). When they disagree the failure is
8
- * silent and one-sided — the stricter side drops a reference the other accepted,
9
- * and the reader is left looking at raw `[card://…]` text in a sentence.
10
- *
11
- * The id half is deliberately permissive: the backend validates it as "anything
12
- * but `]` and newlines", and a client that narrows that is the side that breaks.
13
- * `)` is excluded on top because the body form also terminates on it (a marker
14
- * written as a markdown link target).
15
- *
16
- * Server-safe: no React, no browser APIs.
17
- */
18
-
19
- /** Entity-type half. A closed vocabulary of slug-shaped names. */
20
- const CARD_TYPE = '[a-zA-Z0-9_-]+';
21
-
22
- /** Id half — see the permissiveness note above. */
23
- const CARD_ID = '[^\\]\\r\\n)]+';
24
-
25
- /**
26
- * A marker standing ALONE, anchored — for validating a `ref` field in the
27
- * metadata payload, where the whole string must be the marker and nothing else.
28
- */
29
- export const CARD_REFERENCE = new RegExp(`^\\[card://(${CARD_TYPE}):(${CARD_ID})\\]$`);
30
-
31
- /**
32
- * A marker EMBEDDED in answer text, unanchored and global.
33
- *
34
- * Terminates on `]` or `)` so a marker used as a markdown link target
35
- * (`[card://x:y](…)`) is matched too. Being global, it carries `lastIndex`
36
- * state — reset it before each scan.
37
- */
38
- export function createCardMarkerScanner(): RegExp {
39
- return new RegExp(`\\[card://(${CARD_TYPE}):(${CARD_ID})[\\])]`, 'g');
40
- }