@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
|
@@ -41,8 +41,8 @@ var CHAT_OWNER_ADMIN = "ADMIN";
|
|
|
41
41
|
// src/chat-protocol/encode.ts
|
|
42
42
|
var encoder = new TextEncoder();
|
|
43
43
|
var SENTINEL_BYTES_RE = /[\u0000\u001E\u001F]/g;
|
|
44
|
-
function stripSentinelBytes(
|
|
45
|
-
return
|
|
44
|
+
function stripSentinelBytes(text2) {
|
|
45
|
+
return text2.replace(SENTINEL_BYTES_RE, "");
|
|
46
46
|
}
|
|
47
47
|
function encodeLeadingFrame(frame) {
|
|
48
48
|
return encoder.encode(JSON.stringify(frame) + FRAME_TERMINATOR);
|
|
@@ -50,16 +50,16 @@ function encodeLeadingFrame(frame) {
|
|
|
50
50
|
function encodeEndOfLeading() {
|
|
51
51
|
return encoder.encode(END_OF_LEADING);
|
|
52
52
|
}
|
|
53
|
-
function encodeTextDelta(
|
|
54
|
-
return encoder.encode(stripSentinelBytes(
|
|
53
|
+
function encodeTextDelta(text2) {
|
|
54
|
+
return encoder.encode(stripSentinelBytes(text2));
|
|
55
55
|
}
|
|
56
56
|
function encodeTrailingUsageFrame(frame) {
|
|
57
57
|
return encoder.encode(TRAILER_SENTINEL + JSON.stringify(frame));
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// src/chat-protocol/leading-frames.ts
|
|
61
|
-
function escapeThinkingTags(
|
|
62
|
-
return
|
|
61
|
+
function escapeThinkingTags(text2) {
|
|
62
|
+
return text2.replace(/</g, "<");
|
|
63
63
|
}
|
|
64
64
|
function frameStr(value) {
|
|
65
65
|
return typeof value === "string" ? value : void 0;
|
|
@@ -170,11 +170,11 @@ function isFrameObject(value) {
|
|
|
170
170
|
}
|
|
171
171
|
function frameTelemetry(value) {
|
|
172
172
|
if (!isFrameObject(value)) return void 0;
|
|
173
|
-
const { cards, chips, sentences, answerLen } = value;
|
|
174
|
-
if (typeof
|
|
173
|
+
const { cards: cards2, chips, sentences, answerLen } = value;
|
|
174
|
+
if (typeof cards2 !== "number" || typeof chips !== "number" || typeof sentences !== "number" || typeof answerLen !== "number") {
|
|
175
175
|
return void 0;
|
|
176
176
|
}
|
|
177
|
-
return { cards, chips, sentences, answerLen };
|
|
177
|
+
return { cards: cards2, chips, sentences, answerLen };
|
|
178
178
|
}
|
|
179
179
|
function createSseFrameDecoder() {
|
|
180
180
|
const textDecoder = new TextDecoder();
|
|
@@ -285,6 +285,15 @@ var MESSAGE_TYPE = {
|
|
|
285
285
|
TEXT: "TEXT",
|
|
286
286
|
THINKING: "THINKING",
|
|
287
287
|
ASK: "ASK",
|
|
288
|
+
/** Per-answer source metadata (documents, videos, entity cards).
|
|
289
|
+
*
|
|
290
|
+
* TWO names for ONE payload, on purpose. `SOURCES` is the contract the
|
|
291
|
+
* backend is moving to; `GUIDE` is the envelope it ships in today, reused
|
|
292
|
+
* from Guide Mode v2 so a released frontend keeps working during the v2→v3
|
|
293
|
+
* rollout. Both decode through the same path, so dropping `GUIDE` later is a
|
|
294
|
+
* deletion here and nothing else. */
|
|
295
|
+
GUIDE: "GUIDE",
|
|
296
|
+
SOURCES: "SOURCES",
|
|
288
297
|
EXECUTING_TOOL: "EXECUTING_TOOL",
|
|
289
298
|
EXECUTED_TOOL: "EXECUTED_TOOL",
|
|
290
299
|
APPROVAL_REQUEST: "APPROVAL_REQUEST",
|
|
@@ -305,6 +314,11 @@ var MESSAGE_TYPE = {
|
|
|
305
314
|
DIALOG_CLOSED: "DIALOG_CLOSED"
|
|
306
315
|
};
|
|
307
316
|
|
|
317
|
+
// src/chat-protocol/card-marker.ts
|
|
318
|
+
var CARD_TYPE = "[a-zA-Z0-9_-]+";
|
|
319
|
+
var CARD_ID = "[^\\]\\r\\n)]+";
|
|
320
|
+
var CARD_REFERENCE = new RegExp(`^\\[card://(${CARD_TYPE}):(${CARD_ID})\\]$`);
|
|
321
|
+
|
|
308
322
|
// src/chat-protocol/wire-narrow.ts
|
|
309
323
|
function isRecord(value) {
|
|
310
324
|
return typeof value === "object" && value !== null;
|
|
@@ -313,6 +327,184 @@ function unwrapEnvelope(payload) {
|
|
|
313
327
|
return isRecord(payload) && "data" in payload ? payload.data : payload;
|
|
314
328
|
}
|
|
315
329
|
|
|
330
|
+
// src/chat-protocol/source-metadata.ts
|
|
331
|
+
var YOUTUBE_ID = /^[A-Za-z0-9_-]{11}$/;
|
|
332
|
+
var VIDEO_URL_KEYS = ["videoUrl", "highlightVideoUrl", "videoPoster", "highlightVideoPoster"];
|
|
333
|
+
function text(value) {
|
|
334
|
+
if (typeof value !== "string") return void 0;
|
|
335
|
+
const trimmed = value.trim();
|
|
336
|
+
return trimmed || void 0;
|
|
337
|
+
}
|
|
338
|
+
function nullableText(value) {
|
|
339
|
+
return value === null ? null : text(value);
|
|
340
|
+
}
|
|
341
|
+
function httpsUrl(value) {
|
|
342
|
+
const candidate = text(value);
|
|
343
|
+
if (!candidate) return void 0;
|
|
344
|
+
try {
|
|
345
|
+
return new URL(candidate).protocol === "https:" ? candidate : void 0;
|
|
346
|
+
} catch {
|
|
347
|
+
return void 0;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function youtubeVideoId(value) {
|
|
351
|
+
const candidate = text(value);
|
|
352
|
+
if (!candidate) return void 0;
|
|
353
|
+
if (YOUTUBE_ID.test(candidate)) return candidate;
|
|
354
|
+
const url = httpsUrl(candidate);
|
|
355
|
+
if (!url) return void 0;
|
|
356
|
+
const parsed = new URL(url);
|
|
357
|
+
const hostname = parsed.hostname.toLowerCase();
|
|
358
|
+
const isYoutubeHost = hostname === "youtu.be" || hostname === "youtube.com" || hostname.endsWith(".youtube.com");
|
|
359
|
+
if (!isYoutubeHost) return void 0;
|
|
360
|
+
const fromPath = hostname === "youtu.be" ? parsed.pathname.split("/").filter(Boolean)[0] : /^\/(?:embed|v|shorts)\/([A-Za-z0-9_-]{11})(?:\/|$)/.exec(parsed.pathname)?.[1];
|
|
361
|
+
const id = fromPath ?? parsed.searchParams.get("v") ?? void 0;
|
|
362
|
+
return id && YOUTUBE_ID.test(id) ? id : void 0;
|
|
363
|
+
}
|
|
364
|
+
function sourceItems(value) {
|
|
365
|
+
if (!Array.isArray(value)) return void 0;
|
|
366
|
+
const items = value.filter(isRecord).flatMap((item) => {
|
|
367
|
+
const id = text(item.id);
|
|
368
|
+
const documentType = text(item.documentType);
|
|
369
|
+
const name = text(item.name);
|
|
370
|
+
if (!id || !documentType || !name) return [];
|
|
371
|
+
const externalUrl = httpsUrl(item.externalUrl);
|
|
372
|
+
const targetPlatform = nullableText(item.targetPlatform);
|
|
373
|
+
const path = nullableText(item.path);
|
|
374
|
+
return [
|
|
375
|
+
{
|
|
376
|
+
id,
|
|
377
|
+
documentType,
|
|
378
|
+
name,
|
|
379
|
+
...externalUrl ? { externalUrl } : {},
|
|
380
|
+
...targetPlatform !== void 0 ? { targetPlatform } : {},
|
|
381
|
+
...path !== void 0 ? { path } : {}
|
|
382
|
+
}
|
|
383
|
+
];
|
|
384
|
+
});
|
|
385
|
+
return items.length > 0 ? items : void 0;
|
|
386
|
+
}
|
|
387
|
+
function sources(value) {
|
|
388
|
+
if (!Array.isArray(value)) return [];
|
|
389
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
390
|
+
const decoded = [];
|
|
391
|
+
for (const candidate of value) {
|
|
392
|
+
if (!isRecord(candidate)) continue;
|
|
393
|
+
const index = candidate.index;
|
|
394
|
+
const name = text(candidate.name);
|
|
395
|
+
const isUsableIndex = typeof index === "number" && Number.isInteger(index) && index > 0 && !claimed.has(index);
|
|
396
|
+
if (!isUsableIndex || !name) continue;
|
|
397
|
+
claimed.add(index);
|
|
398
|
+
const path = text(candidate.path);
|
|
399
|
+
const documentType = text(candidate.documentType);
|
|
400
|
+
const externalUrl = httpsUrl(candidate.externalUrl);
|
|
401
|
+
const targetPlatform = nullableText(candidate.targetPlatform);
|
|
402
|
+
const id = text(candidate.id);
|
|
403
|
+
const sourceRepo = text(candidate.sourceRepo);
|
|
404
|
+
const label = text(candidate.label);
|
|
405
|
+
const items = sourceItems(candidate.items);
|
|
406
|
+
decoded.push({
|
|
407
|
+
index,
|
|
408
|
+
name,
|
|
409
|
+
// Both are typed non-optional on `ChatSource` and predate this decoder;
|
|
410
|
+
// '' is the established "no value" for them across the SSE path.
|
|
411
|
+
path: path ?? "",
|
|
412
|
+
documentType: documentType ?? "",
|
|
413
|
+
...externalUrl ? { externalUrl } : {},
|
|
414
|
+
...targetPlatform !== void 0 ? { targetPlatform } : {},
|
|
415
|
+
...id ? { id } : {},
|
|
416
|
+
...sourceRepo ? { sourceRepo } : {},
|
|
417
|
+
...label ? { label } : {},
|
|
418
|
+
...items ? { items } : {}
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return decoded;
|
|
422
|
+
}
|
|
423
|
+
function videoMetadata(value, url) {
|
|
424
|
+
const metadata = {};
|
|
425
|
+
if (isRecord(value)) {
|
|
426
|
+
for (const key of VIDEO_URL_KEYS) {
|
|
427
|
+
const validated = httpsUrl(value[key]);
|
|
428
|
+
if (validated) metadata[key] = validated;
|
|
429
|
+
}
|
|
430
|
+
const declaredId = youtubeVideoId(value.youtubeUrl);
|
|
431
|
+
if (declaredId) metadata.youtubeUrl = declaredId;
|
|
432
|
+
}
|
|
433
|
+
if (url) {
|
|
434
|
+
const idFromUrl = youtubeVideoId(url);
|
|
435
|
+
if (idFromUrl) {
|
|
436
|
+
metadata.youtubeUrl = idFromUrl;
|
|
437
|
+
delete metadata.videoUrl;
|
|
438
|
+
} else {
|
|
439
|
+
metadata.videoUrl = url;
|
|
440
|
+
delete metadata.youtubeUrl;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return metadata;
|
|
444
|
+
}
|
|
445
|
+
function videos(value) {
|
|
446
|
+
if (!Array.isArray(value)) return [];
|
|
447
|
+
return value.filter(isRecord).flatMap((video) => {
|
|
448
|
+
const match = typeof video.ref === "string" ? CARD_REFERENCE.exec(video.ref) : null;
|
|
449
|
+
if (!match || match[1] !== "video") return [];
|
|
450
|
+
const id = match[2];
|
|
451
|
+
const url = httpsUrl(video.url) ?? null;
|
|
452
|
+
const sourceRepo = text(video.sourceRepo);
|
|
453
|
+
const metadata = videoMetadata(video.metadata, url);
|
|
454
|
+
return [
|
|
455
|
+
{
|
|
456
|
+
type: "video",
|
|
457
|
+
id,
|
|
458
|
+
title: text(video.title) ?? id,
|
|
459
|
+
url,
|
|
460
|
+
...sourceRepo ? { sourceRepo } : {},
|
|
461
|
+
...Object.keys(metadata).length > 0 ? { metadata } : {}
|
|
462
|
+
}
|
|
463
|
+
];
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
function cards(value, decodedSources) {
|
|
467
|
+
if (!Array.isArray(value)) return [];
|
|
468
|
+
return value.filter(isRecord).flatMap((card) => {
|
|
469
|
+
const match = typeof card.ref === "string" ? CARD_REFERENCE.exec(card.ref) : null;
|
|
470
|
+
if (!match || match[1] === "video") return [];
|
|
471
|
+
const type = text(card.entityType);
|
|
472
|
+
const id = text(card.entityId);
|
|
473
|
+
if (!type || !id || type !== match[1] || id !== match[2]) return [];
|
|
474
|
+
const source = decodedSources.find((candidate) => candidate.id === id && candidate.documentType === type);
|
|
475
|
+
return [
|
|
476
|
+
{
|
|
477
|
+
type,
|
|
478
|
+
id,
|
|
479
|
+
title: source?.name ?? id,
|
|
480
|
+
url: source?.externalUrl ?? null,
|
|
481
|
+
...source?.sourceRepo ? { sourceRepo: source.sourceRepo } : {},
|
|
482
|
+
...source?.targetPlatform !== void 0 ? { targetPlatform: source.targetPlatform } : {},
|
|
483
|
+
...source?.path ? { metadata: { path: source.path } } : {}
|
|
484
|
+
}
|
|
485
|
+
];
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
function deduplicateRefs(refs) {
|
|
489
|
+
const byIdentity = /* @__PURE__ */ new Map();
|
|
490
|
+
for (const ref of refs) {
|
|
491
|
+
const identity = `${ref.type}:${ref.id}`;
|
|
492
|
+
if (!byIdentity.has(identity)) byIdentity.set(identity, ref);
|
|
493
|
+
}
|
|
494
|
+
return [...byIdentity.values()];
|
|
495
|
+
}
|
|
496
|
+
function sourceMetadataEvent(payload) {
|
|
497
|
+
if (!isRecord(payload)) return null;
|
|
498
|
+
const decodedSources = sources(payload.sources);
|
|
499
|
+
const refs = deduplicateRefs([...videos(payload.videos), ...cards(payload.cards, decodedSources)]);
|
|
500
|
+
if (decodedSources.length === 0 && refs.length === 0) return null;
|
|
501
|
+
return {
|
|
502
|
+
type: "sources",
|
|
503
|
+
...decodedSources.length > 0 ? { sources: decodedSources } : {},
|
|
504
|
+
...refs.length > 0 ? { refs } : {}
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
316
508
|
// src/chat-protocol/nats-decoder.ts
|
|
317
509
|
function str(value) {
|
|
318
510
|
return typeof value === "string" ? value : void 0;
|
|
@@ -378,6 +570,16 @@ function decodeNatsChunk(chunk) {
|
|
|
378
570
|
return { type: "thinking-delta", text: data.text, ...seq };
|
|
379
571
|
}
|
|
380
572
|
return null;
|
|
573
|
+
// Two chunk names, one payload and one decoder. `SOURCES` is the contract
|
|
574
|
+
// the backend is moving to; `GUIDE` is the v2 envelope it ships in during
|
|
575
|
+
// the rollout (see `MESSAGE_TYPE.GUIDE`). The chunk arrives BEFORE or
|
|
576
|
+
// between the answer's text deltas, so the reducer — not this decoder —
|
|
577
|
+
// owns attaching it to the right turn.
|
|
578
|
+
case MESSAGE_TYPE.GUIDE:
|
|
579
|
+
case MESSAGE_TYPE.SOURCES: {
|
|
580
|
+
const event = sourceMetadataEvent(data.payload);
|
|
581
|
+
return event ? { ...event, ...seq } : null;
|
|
582
|
+
}
|
|
381
583
|
// An ask card is only an ask card with something to pick: a question and at
|
|
382
584
|
// least one option. Anything less is dropped rather than rendered as an
|
|
383
585
|
// empty card the user can't answer — the backend already falls back to a
|