@flamingo-stack/openframe-frontend-core 0.0.609 → 0.0.610-2115.5924.1
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/card-marker.d.ts +31 -0
- package/dist/chat-protocol/card-marker.d.ts.map +1 -0
- package/dist/chat-protocol/events.d.ts +21 -2
- package/dist/chat-protocol/events.d.ts.map +1 -1
- package/dist/chat-protocol/index.cjs +211 -9
- package/dist/chat-protocol/index.cjs.map +1 -1
- package/dist/chat-protocol/index.js +211 -9
- package/dist/chat-protocol/index.js.map +1 -1
- package/dist/chat-protocol/nats-decoder.d.ts.map +1 -1
- package/dist/chat-protocol/source-metadata.d.ts +56 -0
- package/dist/chat-protocol/source-metadata.d.ts.map +1 -0
- package/dist/{chunk-LA2W5L6K.js → chunk-25YIHMZ6.js} +2 -2
- package/dist/{chunk-6MLRFM3T.js → chunk-2QBXG74C.js} +5 -5
- package/dist/{chunk-3N4FXBVJ.cjs → chunk-2YMDDD5V.cjs} +3 -3
- package/dist/{chunk-3N4FXBVJ.cjs.map → chunk-2YMDDD5V.cjs.map} +1 -1
- package/dist/{chunk-JOCVQZGT.js → chunk-37CAZTLP.js} +5 -5
- package/dist/{chunk-D3DTC7SZ.cjs → chunk-C4KQ2XPK.cjs} +15 -15
- package/dist/{chunk-D3DTC7SZ.cjs.map → chunk-C4KQ2XPK.cjs.map} +1 -1
- package/dist/{chunk-CZTOSG7Q.cjs → chunk-EANAFFAD.cjs} +22 -22
- package/dist/{chunk-CZTOSG7Q.cjs.map → chunk-EANAFFAD.cjs.map} +1 -1
- package/dist/{chunk-BSMPCPOZ.js → chunk-F2C2U7CP.js} +590 -299
- package/dist/chunk-F2C2U7CP.js.map +1 -0
- package/dist/{chunk-O2M4T34Q.cjs → chunk-FASOANK7.cjs} +4 -4
- package/dist/{chunk-O2M4T34Q.cjs.map → chunk-FASOANK7.cjs.map} +1 -1
- package/dist/{chunk-JKM5FH63.js → chunk-FS3CTGIR.js} +3 -3
- package/dist/{chunk-45XXK2VU.cjs → chunk-GFAHCXIL.cjs} +10 -10
- package/dist/{chunk-45XXK2VU.cjs.map → chunk-GFAHCXIL.cjs.map} +1 -1
- package/dist/{chunk-SEW25Y2W.cjs → chunk-GNLV326I.cjs} +10 -10
- package/dist/{chunk-SEW25Y2W.cjs.map → chunk-GNLV326I.cjs.map} +1 -1
- package/dist/{chunk-DKNXAJMP.cjs → chunk-HKJ3WKGW.cjs} +159 -159
- package/dist/{chunk-DKNXAJMP.cjs.map → chunk-HKJ3WKGW.cjs.map} +1 -1
- package/dist/{chunk-HGVW7OHI.js → chunk-HQSCJYCF.js} +2 -2
- package/dist/{chunk-QX4ANESW.js → chunk-HZS4TV34.js} +6 -6
- package/dist/{chunk-B3UXNGVM.js → chunk-IBMHEOBV.js} +3 -3
- package/dist/{chunk-BUXGWBTF.js → chunk-MGXSJI23.js} +2 -2
- package/dist/{chunk-B7LYKBCD.js → chunk-O6PO5BHE.js} +5 -5
- package/dist/{chunk-C7CTEUU7.js → chunk-OIKZDXNW.js} +2 -2
- package/dist/{chunk-TJ3GFULR.js → chunk-OJZW3GE2.js} +3 -3
- package/dist/{chunk-L2JWC5VS.cjs → chunk-OVVKVIMH.cjs} +43 -43
- package/dist/{chunk-L2JWC5VS.cjs.map → chunk-OVVKVIMH.cjs.map} +1 -1
- package/dist/{chunk-VCYRJY7J.js → chunk-Q2CNCBMK.js} +4 -4
- package/dist/{chunk-NJUSDREV.cjs → chunk-Q3APHZK5.cjs} +22 -22
- package/dist/{chunk-NJUSDREV.cjs.map → chunk-Q3APHZK5.cjs.map} +1 -1
- package/dist/{chunk-TCEALWE3.cjs → chunk-QE2Z6WME.cjs} +33 -33
- package/dist/{chunk-TCEALWE3.cjs.map → chunk-QE2Z6WME.cjs.map} +1 -1
- package/dist/{chunk-OTYV6SDN.js → chunk-R2UDEMKK.js} +3 -3
- package/dist/{chunk-JR7I2AGL.js → chunk-ROOIHDLS.js} +3 -3
- package/dist/{chunk-3XNMDLGB.cjs → chunk-THCB7NHV.cjs} +9 -9
- package/dist/{chunk-3XNMDLGB.cjs.map → chunk-THCB7NHV.cjs.map} +1 -1
- package/dist/{chunk-GMOBT5NP.cjs → chunk-THCSSPXU.cjs} +70 -70
- package/dist/{chunk-GMOBT5NP.cjs.map → chunk-THCSSPXU.cjs.map} +1 -1
- package/dist/{chunk-FYG7QNAO.cjs → chunk-UFFVMZDL.cjs} +5 -5
- package/dist/{chunk-FYG7QNAO.cjs.map → chunk-UFFVMZDL.cjs.map} +1 -1
- package/dist/{chunk-MVBRMQGU.js → chunk-V6TINNLD.js} +2 -2
- package/dist/{chunk-ZRLFBLME.cjs → chunk-WJQOYSR3.cjs} +3 -3
- package/dist/{chunk-ZRLFBLME.cjs.map → chunk-WJQOYSR3.cjs.map} +1 -1
- package/dist/{chunk-XNDTYTVT.cjs → chunk-YXTAV2E3.cjs} +974 -683
- package/dist/chunk-YXTAV2E3.cjs.map +1 -0
- package/dist/{chunk-RZM6FPOT.cjs → chunk-ZDLCWNM6.cjs} +25 -25
- package/dist/{chunk-RZM6FPOT.cjs.map → chunk-ZDLCWNM6.cjs.map} +1 -1
- package/dist/components/case-studies/index.cjs +9 -9
- package/dist/components/case-studies/index.js +3 -3
- 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/embeddable-chat.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts +5 -28
- package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +2 -2
- package/dist/components/chat/index.js +1 -1
- package/dist/components/chat/remark-card-links.d.ts +5 -4
- package/dist/components/chat/remark-card-links.d.ts.map +1 -1
- package/dist/components/chat/stream/chat-stream-reducer.d.ts.map +1 -1
- package/dist/components/chat/tool-execution-display.d.ts.map +1 -1
- package/dist/components/chat/types/component.types.d.ts +27 -0
- package/dist/components/chat/types/component.types.d.ts.map +1 -1
- package/dist/components/chat/types/message.types.d.ts +81 -1
- package/dist/components/chat/types/message.types.d.ts.map +1 -1
- package/dist/components/chat/types/unified-chat-state.types.d.ts +12 -3
- package/dist/components/chat/types/unified-chat-state.types.d.ts.map +1 -1
- package/dist/components/chat/utils/cited-sources.d.ts +24 -0
- package/dist/components/chat/utils/cited-sources.d.ts.map +1 -0
- package/dist/components/chat/utils/host-message.d.ts +41 -0
- package/dist/components/chat/utils/host-message.d.ts.map +1 -0
- package/dist/components/chat/utils/process-historical-messages.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +4 -4
- package/dist/components/contact/index.js +3 -3
- package/dist/components/docs/index.cjs +7 -7
- package/dist/components/docs/index.js +6 -6
- package/dist/components/embeds/index.cjs +4 -4
- package/dist/components/embeds/index.js +3 -3
- package/dist/components/faq/index.cjs +4 -4
- package/dist/components/faq/index.js +3 -3
- package/dist/components/features/index.cjs +3 -3
- package/dist/components/features/index.js +2 -2
- package/dist/components/help-center-pages/index.cjs +23 -23
- package/dist/components/help-center-pages/index.js +14 -14
- package/dist/components/index.cjs +38 -38
- package/dist/components/index.js +13 -13
- package/dist/components/meeting-scheduler/index.cjs +24 -24
- package/dist/components/meeting-scheduler/index.js +2 -2
- package/dist/components/navigation/index.cjs +6 -6
- package/dist/components/navigation/index.js +5 -5
- package/dist/components/onboarding-guides/index.cjs +6 -6
- package/dist/components/onboarding-guides/index.js +5 -5
- package/dist/components/tickets/index.cjs +7 -7
- package/dist/components/tickets/index.js +6 -6
- package/dist/components/ui/index.cjs +3 -3
- package/dist/components/ui/index.js +2 -2
- package/dist/index.cjs +7 -7
- package/dist/index.js +6 -6
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/chat-protocol/__tests__/card-marker.test.ts +63 -0
- package/src/chat-protocol/__tests__/source-metadata.test.ts +243 -0
- package/src/chat-protocol/card-marker.ts +40 -0
- package/src/chat-protocol/events.ts +22 -1
- package/src/chat-protocol/nats-decoder.ts +12 -0
- package/src/chat-protocol/source-metadata.ts +336 -0
- package/src/components/chat/__tests__/tool-execution-display.test.tsx +70 -0
- package/src/components/chat/chat-message-enhanced.tsx +37 -12
- package/src/components/chat/chat-message-list.tsx +14 -1
- package/src/components/chat/embeddable-chat.tsx +47 -87
- package/src/components/chat/hooks/use-sse-chat-adapter.ts +5 -28
- package/src/components/chat/remark-card-links.ts +14 -12
- package/src/components/chat/stream/chat-stream-reducer.ts +48 -3
- package/src/components/chat/tool-execution-display.tsx +18 -4
- package/src/components/chat/types/component.types.ts +27 -0
- package/src/components/chat/types/message.types.ts +83 -0
- package/src/components/chat/types/unified-chat-state.types.ts +12 -3
- package/src/components/chat/utils/__tests__/cited-sources.test.ts +80 -0
- package/src/components/chat/utils/__tests__/host-message.test.ts +92 -0
- package/src/components/chat/utils/__tests__/process-historical-messages-sources.test.ts +138 -0
- package/src/components/chat/utils/cited-sources.ts +61 -0
- package/src/components/chat/utils/host-message.ts +87 -0
- package/src/components/chat/utils/process-historical-messages.ts +25 -0
- package/dist/chunk-BSMPCPOZ.js.map +0 -1
- package/dist/chunk-XNDTYTVT.cjs.map +0 -1
- /package/dist/{chunk-LA2W5L6K.js.map → chunk-25YIHMZ6.js.map} +0 -0
- /package/dist/{chunk-6MLRFM3T.js.map → chunk-2QBXG74C.js.map} +0 -0
- /package/dist/{chunk-JOCVQZGT.js.map → chunk-37CAZTLP.js.map} +0 -0
- /package/dist/{chunk-JKM5FH63.js.map → chunk-FS3CTGIR.js.map} +0 -0
- /package/dist/{chunk-HGVW7OHI.js.map → chunk-HQSCJYCF.js.map} +0 -0
- /package/dist/{chunk-QX4ANESW.js.map → chunk-HZS4TV34.js.map} +0 -0
- /package/dist/{chunk-B3UXNGVM.js.map → chunk-IBMHEOBV.js.map} +0 -0
- /package/dist/{chunk-BUXGWBTF.js.map → chunk-MGXSJI23.js.map} +0 -0
- /package/dist/{chunk-B7LYKBCD.js.map → chunk-O6PO5BHE.js.map} +0 -0
- /package/dist/{chunk-C7CTEUU7.js.map → chunk-OIKZDXNW.js.map} +0 -0
- /package/dist/{chunk-TJ3GFULR.js.map → chunk-OJZW3GE2.js.map} +0 -0
- /package/dist/{chunk-VCYRJY7J.js.map → chunk-Q2CNCBMK.js.map} +0 -0
- /package/dist/{chunk-OTYV6SDN.js.map → chunk-R2UDEMKK.js.map} +0 -0
- /package/dist/{chunk-JR7I2AGL.js.map → chunk-ROOIHDLS.js.map} +0 -0
- /package/dist/{chunk-MVBRMQGU.js.map → chunk-V6TINNLD.js.map} +0 -0
package/package.json
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,243 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
}
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
// rows straight to the accumulator, so restating them here would be two
|
|
13
13
|
// declarations of one wire contract. Type-only import from a React-free
|
|
14
14
|
// module; `nats-decoder.ts` already depends on the same file for MESSAGE_TYPE.
|
|
15
|
-
import type {
|
|
15
|
+
import type { ChatRef } from '../components/chat/chat-ref.types';
|
|
16
|
+
import type { AskOptionData, ChatSource } from '../components/chat/types/message.types';
|
|
16
17
|
// The wire-frame shapes these events carry through are defined ONCE in
|
|
17
18
|
// `./frames.ts` — reuse them here rather than restating their fields.
|
|
18
19
|
import type { ApprovalRequestField, DecisionResolvedFrame, UsageTelemetry } from './frames';
|
|
@@ -217,6 +218,25 @@ export interface TicketEventEvent extends ChatStreamEventBase {
|
|
|
217
218
|
targetStatusKind?: string;
|
|
218
219
|
}
|
|
219
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Per-answer source metadata — the documents an answer cited, plus the video
|
|
223
|
+
* and entity-card references its `[card://type:id]` markers expand with.
|
|
224
|
+
*
|
|
225
|
+
* Unlike `ChatMetadataEvent`, this one is DECODED, not passthrough: the payload
|
|
226
|
+
* comes from a remote MCP server's tool output rather than from our own
|
|
227
|
+
* backend's frame, so it is validated at the protocol boundary (see
|
|
228
|
+
* `source-metadata.ts`) and never reaches a consumer half-checked.
|
|
229
|
+
*
|
|
230
|
+
* Both fields are optional and never both absent — the decoder returns `null`
|
|
231
|
+
* instead of emitting an empty event, so applying one can't blank metadata an
|
|
232
|
+
* earlier chunk of the same turn already supplied.
|
|
233
|
+
*/
|
|
234
|
+
export interface SourcesEvent extends ChatStreamEventBase {
|
|
235
|
+
type: 'sources';
|
|
236
|
+
sources?: ChatSource[];
|
|
237
|
+
refs?: ChatRef[];
|
|
238
|
+
}
|
|
239
|
+
|
|
220
240
|
/** Per-turn metadata. Raw wire values pass through UNVALIDATED — the
|
|
221
241
|
* consumer replicates the legacy truthiness/typeof gates (so a
|
|
222
242
|
* malformed frame degrades identically to the pre-SSOT parser). */
|
|
@@ -362,6 +382,7 @@ export type ChatStreamEvent =
|
|
|
362
382
|
| TicketEscalatedEvent
|
|
363
383
|
| TicketEventEvent
|
|
364
384
|
| ChatMetadataEvent
|
|
385
|
+
| SourcesEvent
|
|
365
386
|
| UsageEvent
|
|
366
387
|
| TokenUsageEvent
|
|
367
388
|
| CompactionEvent
|
|
@@ -20,6 +20,7 @@ import { MESSAGE_TYPE } from '../components/chat/types/message.types';
|
|
|
20
20
|
import type { AskOptionData } from '../components/chat/types/message.types';
|
|
21
21
|
import { ESCALATION_STATE, escalationResolvedStatus } from './events';
|
|
22
22
|
import type { ApprovalToolCall, ChatStreamEvent } from './events';
|
|
23
|
+
import { sourceMetadataEvent } from './source-metadata';
|
|
23
24
|
import { isRecord } from './wire-narrow';
|
|
24
25
|
|
|
25
26
|
/** Minimal structural view of a NATS chunk (see `ChunkData` in
|
|
@@ -121,6 +122,17 @@ export function decodeNatsChunk(chunk: unknown): ChatStreamEvent | null {
|
|
|
121
122
|
}
|
|
122
123
|
return null;
|
|
123
124
|
|
|
125
|
+
// Two chunk names, one payload and one decoder. `SOURCES` is the contract
|
|
126
|
+
// the backend is moving to; `GUIDE` is the v2 envelope it ships in during
|
|
127
|
+
// the rollout (see `MESSAGE_TYPE.GUIDE`). The chunk arrives BEFORE or
|
|
128
|
+
// between the answer's text deltas, so the reducer — not this decoder —
|
|
129
|
+
// owns attaching it to the right turn.
|
|
130
|
+
case MESSAGE_TYPE.GUIDE:
|
|
131
|
+
case MESSAGE_TYPE.SOURCES: {
|
|
132
|
+
const event = sourceMetadataEvent(data.payload);
|
|
133
|
+
return event ? { ...event, ...seq } : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
124
136
|
// An ask card is only an ask card with something to pick: a question and at
|
|
125
137
|
// least one option. Anything less is dropped rather than rendered as an
|
|
126
138
|
// empty card the user can't answer — the backend already falls back to a
|