@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,138 +0,0 @@
1
- /**
2
- * Source metadata through the HISTORY path.
3
- *
4
- * The backend persists an answer's metadata as its OWN row, written when the
5
- * remote tool returns — so it arrives as a separate history message, BEFORE the
6
- * answer text, and has to end up on the answer anyway. These pin that regrouping,
7
- * because the failure it prevents is invisible in the live thread and only shows
8
- * up on reload: the chips are simply gone.
9
- */
10
-
11
- import { describe, expect, it } from 'vitest';
12
-
13
- import type { HistoricalMessage } from '../../types';
14
- import { processHistoricalMessages } from '../process-historical-messages';
15
-
16
- const SOURCE = {
17
- index: 1,
18
- name: 'Install the OpenFrame Agent on Windows',
19
- path: 'onboarding-guides/install-the-openframe-agent-on-windows',
20
- documentType: 'onboarding_guide',
21
- id: '88dd40cc',
22
- sourceRepo: 'onboarding-guides',
23
- };
24
-
25
- /** The metadata row, as the backend persists it. */
26
- const metadataRow = (id: string, createdAt: string): HistoricalMessage => ({
27
- id,
28
- chatType: 'ADMIN_AI_CHAT',
29
- createdAt,
30
- owner: { type: 'ASSISTANT' },
31
- messageData: [
32
- {
33
- type: 'GUIDE',
34
- payload: {
35
- sources: [SOURCE],
36
- cards: [{ ref: '[card://onboarding_guide:88dd40cc]', entityType: 'onboarding_guide', entityId: '88dd40cc' }],
37
- },
38
- },
39
- ],
40
- });
41
-
42
- const answerRow = (id: string, createdAt: string, text: string): HistoricalMessage => ({
43
- id,
44
- chatType: 'ADMIN_AI_CHAT',
45
- createdAt,
46
- owner: { type: 'ASSISTANT' },
47
- messageData: [{ type: 'TEXT', text }],
48
- });
49
-
50
- const userRow = (id: string, createdAt: string): HistoricalMessage => ({
51
- id,
52
- chatType: 'ADMIN_AI_CHAT',
53
- createdAt,
54
- owner: { type: 'ADMIN' },
55
- messageData: [{ type: 'TEXT', text: 'How do I install the agent?' }],
56
- });
57
-
58
- describe('processHistoricalMessages — source metadata', () => {
59
- it('attaches a metadata row to the answer it precedes', () => {
60
- const { messages } = processHistoricalMessages([
61
- userRow('u1', '2026-08-26T09:00:00Z'),
62
- metadataRow('m1', '2026-08-26T09:00:01Z'),
63
- answerRow('a1', '2026-08-26T09:00:02Z', 'Use this guide [1].'),
64
- ]);
65
-
66
- const answer = messages[messages.length - 1];
67
- expect(answer.role).toBe('assistant');
68
- expect(answer.sources).toEqual([SOURCE]);
69
- expect(answer.refs).toEqual([
70
- {
71
- type: 'onboarding_guide',
72
- id: '88dd40cc',
73
- // Enriched off the matching source — the card row carries no title.
74
- title: SOURCE.name,
75
- url: null,
76
- sourceRepo: 'onboarding-guides',
77
- metadata: { path: SOURCE.path },
78
- },
79
- ]);
80
- });
81
-
82
- it('does not render a metadata-only row as its own empty bubble', () => {
83
- const { messages } = processHistoricalMessages([
84
- userRow('u1', '2026-08-26T09:00:00Z'),
85
- metadataRow('m1', '2026-08-26T09:00:01Z'),
86
- answerRow('a1', '2026-08-26T09:00:02Z', 'Answer.'),
87
- ]);
88
-
89
- expect(messages.filter(m => m.role === 'assistant')).toHaveLength(1);
90
- });
91
-
92
- it('keeps each answer’s metadata on its own answer', () => {
93
- // The reason this is per-message at all: two turns, two different sets.
94
- const secondSource = { ...SOURCE, index: 1, name: 'Configure Your Tenant Settings', id: 'other' };
95
- const { messages } = processHistoricalMessages([
96
- userRow('u1', '2026-08-26T09:00:00Z'),
97
- metadataRow('m1', '2026-08-26T09:00:01Z'),
98
- answerRow('a1', '2026-08-26T09:00:02Z', 'First answer [1].'),
99
- userRow('u2', '2026-08-26T09:01:00Z'),
100
- {
101
- ...metadataRow('m2', '2026-08-26T09:01:01Z'),
102
- messageData: [{ type: 'GUIDE', payload: { sources: [secondSource] } }],
103
- },
104
- answerRow('a2', '2026-08-26T09:01:02Z', 'Second answer [1].'),
105
- ]);
106
-
107
- const answers = messages.filter(m => m.role === 'assistant');
108
- expect(answers).toHaveLength(2);
109
- expect(answers[0].sources?.[0].name).toBe(SOURCE.name);
110
- expect(answers[1].sources?.[0].name).toBe(secondSource.name);
111
- });
112
-
113
- it('leaves an answer with no metadata untouched', () => {
114
- const { messages } = processHistoricalMessages([
115
- userRow('u1', '2026-08-26T09:00:00Z'),
116
- answerRow('a1', '2026-08-26T09:00:02Z', 'Plain answer.'),
117
- ]);
118
-
119
- const answer = messages[messages.length - 1];
120
- expect(answer).not.toHaveProperty('sources');
121
- expect(answer).not.toHaveProperty('refs');
122
- });
123
-
124
- it('unions metadata from several tool calls in one turn', () => {
125
- const { messages } = processHistoricalMessages([
126
- userRow('u1', '2026-08-26T09:00:00Z'),
127
- metadataRow('m1', '2026-08-26T09:00:01Z'),
128
- {
129
- ...metadataRow('m2', '2026-08-26T09:00:02Z'),
130
- messageData: [{ type: 'GUIDE', payload: { sources: [{ index: 2, name: 'Second tool result' }] } }],
131
- },
132
- answerRow('a1', '2026-08-26T09:00:03Z', 'Both [1] and [2].'),
133
- ]);
134
-
135
- const answer = messages[messages.length - 1];
136
- expect(answer.sources?.map(source => source.index)).toEqual([1, 2]);
137
- });
138
- });
@@ -1,61 +0,0 @@
1
- import type { ChatSource } from '../types/message.types';
2
-
3
- /** How many retrieved sources to show when the answer cited none of them. */
4
- export const FALLBACK_TOP_RETRIEVED = 3;
5
-
6
- export interface CitedSources {
7
- /** Sources the answer referenced, in the order the answer first referenced
8
- * them — NOT in `index` order. */
9
- cited: ChatSource[];
10
- /** Everything retrieved but not referenced, in the order supplied. */
11
- uncited: ChatSource[];
12
- }
13
-
14
- /** `[1]`, `[12]` — a citation marker in the answer body. */
15
- const CITATION = /\[(\d+)\]/g;
16
-
17
- /** Fenced blocks and inline code spans. */
18
- const CODE = /```[\s\S]*?```|~~~[\s\S]*?~~~|`[^`\n]*`/g;
19
-
20
- /**
21
- * Blank out code before looking for citations.
22
- *
23
- * `$items[1]`, `argv[1]`, `matrix[0][1]` — array indexing is not a citation,
24
- * and this assistant answers with scripts constantly. Left in, a snippet marks
25
- * a source as cited that the prose never mentions, and worse, seeds the reading
26
- * order from a position inside a code block.
27
- *
28
- * Replaced with spaces rather than removed so nothing outside the block shifts
29
- * — only whether a marker is inside one is being decided here.
30
- */
31
- function withoutCode(content: string): string {
32
- return content.replace(CODE, block => ' '.repeat(block.length));
33
- }
34
-
35
- /**
36
- * Split an answer's sources into the ones it cited and the ones it did not.
37
- *
38
- * Reading order, not numeric order: the strip is a legend for the sentences
39
- * above it, so the chip for the citation the reader meets first comes first,
40
- * even when the model numbered it `[3]`. A number cited twice is placed once,
41
- * at its first mention.
42
- *
43
- * `content` is the flat answer text. A segmented message has to be flattened by
44
- * the caller — citation markers live in text segments, and this function
45
- * deliberately does not know what a segment is.
46
- */
47
- export function splitCitedSources(sources: ChatSource[] | undefined, content: string): CitedSources {
48
- if (!sources || sources.length === 0) return { cited: [], uncited: [] };
49
-
50
- const firstMentionAt = new Map<number, number>();
51
- for (const match of withoutCode(content).matchAll(CITATION)) {
52
- const index = Number.parseInt(match[1], 10);
53
- if (!firstMentionAt.has(index)) firstMentionAt.set(index, firstMentionAt.size);
54
- }
55
-
56
- const cited = sources
57
- .filter(source => firstMentionAt.has(source.index))
58
- .sort((a, b) => (firstMentionAt.get(a.index) ?? 0) - (firstMentionAt.get(b.index) ?? 0));
59
- const uncited = sources.filter(source => !firstMentionAt.has(source.index));
60
- return { cited, uncited };
61
- }
@@ -1,87 +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
-
22
- import type { Message } from '../types/message.types';
23
- import type { UnifiedChatMessage } from '../types/unified-chat-state.types';
24
-
25
- export interface HostMessageMapOptions {
26
- /** Display name for `user` rows when the host supplies none. */
27
- userName?: string;
28
- /** Avatar for `user` rows when the host supplies none. */
29
- userAvatar?: string;
30
- /**
31
- * Fallback timestamps for rows that carry none, keyed by message id. Mutated:
32
- * a row must keep the SAME fallback across renders, or its bubble re-stamps
33
- * itself on every keystroke elsewhere in the thread.
34
- */
35
- timestampCache: Map<string, Date>;
36
- }
37
-
38
- export function mapHostMessage(m: UnifiedChatMessage, options: HostMessageMapOptions): Message {
39
- const { userName, userAvatar, timestampCache } = options;
40
-
41
- let timestamp: Date;
42
- if (m.timestamp != null) {
43
- timestamp = new Date(m.timestamp);
44
- } else {
45
- const cached = timestampCache.get(m.id);
46
- timestamp = cached ?? new Date();
47
- if (!cached) timestampCache.set(m.id, timestamp);
48
- }
49
-
50
- return {
51
- id: m.id,
52
- role: m.role,
53
- // Host-supplied per-message name/avatar win (e.g. the signed-in user's
54
- // full name + photo on a `user` bubble); fall back to the role default
55
- // when the host doesn't provide them.
56
- name: m.name ?? (m.role === 'assistant' ? 'Mingo' : (userName ?? 'You')),
57
- avatar: m.avatar ?? (m.role === 'user' ? (userAvatar ?? null) : null),
58
- // Forward the host's authorType so user bubbles get the same accent
59
- // name color as the standalone /mingo page (user → 'admin').
60
- ...(m.authorType ? { authorType: m.authorType } : {}),
61
- content: m.segments && m.segments.length > 0 ? m.segments : m.content,
62
- timestamp,
63
- assistantType: m.role === 'assistant' ? ('mingo' as const) : undefined,
64
- // `hidden` is load-bearing, NOT cosmetic: it carries synthetic rows
65
- // (e.g. an auto-continuation directive) that the LLM must see but the
66
- // reader must not. See the module note above.
67
- ...(m.hidden ? { hidden: true } : {}),
68
- ...(m.scrollAnchor ? { scrollAnchor: m.scrollAnchor } : {}),
69
- // Forward attached context items so the user bubble renders its chips.
70
- ...(m.contextItems && m.contextItems.length > 0 ? { contextItems: m.contextItems } : {}),
71
- // Per-answer source metadata: the citation strip under the answer, and the
72
- // descriptions the `[card://…]` markers in its body expand into.
73
- ...(m.sources && m.sources.length > 0 ? { sources: m.sources } : {}),
74
- ...(m.refs && m.refs.length > 0 ? { refs: m.refs } : {}),
75
- };
76
- }
77
-
78
- /**
79
- * Drop cached fallback timestamps for messages no longer in the thread, so the
80
- * map cannot grow unbounded across a long-lived session.
81
- */
82
- export function pruneTimestampCache(timestampCache: Map<string, Date>, liveIds: Set<string>): void {
83
- if (timestampCache.size <= liveIds.size) return;
84
- for (const id of timestampCache.keys()) {
85
- if (!liveIds.has(id)) timestampCache.delete(id);
86
- }
87
- }