@flamingo-stack/openframe-frontend-core 0.0.249 → 0.0.251-snapshot.20260610152056
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/{chunk-VAKBNCV6.js → chunk-4AVACC2J.js} +41 -28
- package/dist/chunk-4AVACC2J.js.map +1 -0
- package/dist/{chunk-PCXI7ZB2.js → chunk-D2BC3NZ2.js} +135 -30
- package/dist/chunk-D2BC3NZ2.js.map +1 -0
- package/dist/{chunk-5ZVPKTXM.js → chunk-DZJ53RX6.js} +2 -2
- package/dist/{chunk-4EED3YEI.cjs → chunk-NCXHTQH2.cjs} +663 -558
- package/dist/chunk-NCXHTQH2.cjs.map +1 -0
- package/dist/{chunk-3DZ7QYNA.cjs → chunk-PDKBCCCD.cjs} +11 -11
- package/dist/{chunk-3DZ7QYNA.cjs.map → chunk-PDKBCCCD.cjs.map} +1 -1
- package/dist/{chunk-PVAYXHYF.js → chunk-PSG7H4KG.js} +2 -2
- package/dist/{chunk-3VTHSACO.cjs → chunk-UMH4RR2F.cjs} +25 -25
- package/dist/{chunk-3VTHSACO.cjs.map → chunk-UMH4RR2F.cjs.map} +1 -1
- package/dist/{chunk-LHZYI23D.cjs → chunk-UXDWRC5Y.cjs} +63 -50
- package/dist/chunk-UXDWRC5Y.cjs.map +1 -0
- package/dist/components/chat/chat-message-list.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +12 -2
- package/dist/components/chat/index.cjs.map +1 -1
- package/dist/components/chat/index.js +11 -1
- package/dist/components/chat/utils/history-merge.d.ts +92 -0
- package/dist/components/chat/utils/history-merge.d.ts.map +1 -0
- package/dist/components/chat/utils/index.d.ts +1 -0
- package/dist/components/chat/utils/index.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +3 -3
- package/dist/components/contact/index.js +2 -2
- package/dist/components/features/index.cjs +2 -2
- package/dist/components/features/index.js +1 -1
- package/dist/components/features/policy-configuration-panel.d.ts.map +1 -1
- package/dist/components/index.cjs +59 -49
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +13 -3
- package/dist/components/index.js.map +1 -1
- package/dist/components/navigation/index.cjs +2 -2
- package/dist/components/navigation/index.js +1 -1
- package/dist/components/related-content/index.cjs +3 -3
- package/dist/components/related-content/index.js +2 -2
- package/dist/components/related-content/related-content-section.d.ts.map +1 -1
- package/dist/components/tickets/index.cjs +55 -55
- package/dist/components/tickets/index.js +3 -3
- package/dist/components/ui/index.cjs +12 -2
- package/dist/components/ui/index.cjs.map +1 -1
- package/dist/components/ui/index.js +11 -1
- package/dist/index.cjs +12 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -1
- package/package.json +1 -1
- package/src/components/chat/__tests__/chat-message-list.test.tsx +92 -0
- package/src/components/chat/chat-message-list.tsx +74 -49
- package/src/components/chat/utils/__tests__/history-merge.test.ts +339 -0
- package/src/components/chat/utils/history-merge.ts +255 -0
- package/src/components/chat/utils/index.ts +12 -0
- package/src/components/features/policy-configuration-panel.tsx +1 -0
- package/src/components/related-content/related-content-section.tsx +59 -33
- package/dist/chunk-4EED3YEI.cjs.map +0 -1
- package/dist/chunk-LHZYI23D.cjs.map +0 -1
- package/dist/chunk-PCXI7ZB2.js.map +0 -1
- package/dist/chunk-VAKBNCV6.js.map +0 -1
- /package/dist/{chunk-5ZVPKTXM.js.map → chunk-DZJ53RX6.js.map} +0 -0
- /package/dist/{chunk-PVAYXHYF.js.map → chunk-PSG7H4KG.js.map} +0 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { ApprovalBatchSegment, MessageContent } from '../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reconciliation between persisted dialog history (processed GraphQL pages)
|
|
5
|
+
* and the realtime messages a chat client accumulated from streaming chunks.
|
|
6
|
+
*
|
|
7
|
+
* This is the missing middle piece of the chat pipeline this lib already
|
|
8
|
+
* owns: `processHistoricalMessages*` produces one stream, the realtime chunk
|
|
9
|
+
* processor / segment accumulator produces the other, and every host (Mingo,
|
|
10
|
+
* tickets, openframe-chat) needs to merge them whenever history is (re)fetched.
|
|
11
|
+
* Hand-rolled versions of this merge have produced both duplicated turns
|
|
12
|
+
* (synthetic kept alongside its persisted twin) and lost turns (synthetic
|
|
13
|
+
* trimmed against a stale snapshot that didn't contain its persisted twin
|
|
14
|
+
* yet) — the freshness rule below is the invariant that prevents both.
|
|
15
|
+
*
|
|
16
|
+
* Pure on purpose: the host owns WHEN to merge (react-query wiring, store
|
|
17
|
+
* writes), this module owns HOW.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** Minimal structural shape the merge needs — hosts pass their own message
|
|
21
|
+
* type and get it back. */
|
|
22
|
+
export interface MergeableChatMessage {
|
|
23
|
+
id: string
|
|
24
|
+
role: string
|
|
25
|
+
content: MessageContent
|
|
26
|
+
timestamp?: Date
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Ids minted client-side by realtime chunk processors
|
|
30
|
+
* (`assistant-<ts>-…` placeholder bubbles, `user-<ts>-…` peer messages,
|
|
31
|
+
* `error-<ts>` stream errors). They never match the Mongo ObjectIds history
|
|
32
|
+
* returns for the same turns. This is the cross-host contract every minting
|
|
33
|
+
* site (lib `use-chat`, Mingo / tickets chunk processors, openframe-chat)
|
|
34
|
+
* must keep matching — exported so it lives in exactly one place.
|
|
35
|
+
* `welcome-` and `optimistic-` ids are intentionally NOT listed: welcome
|
|
36
|
+
* bubbles are never persisted server-side, and optimistic user messages are
|
|
37
|
+
* deduped by content below. */
|
|
38
|
+
export const SYNTHETIC_REALTIME_ID_PREFIXES = ['assistant-', 'user-', 'error-'] as const
|
|
39
|
+
|
|
40
|
+
function isSyntheticRealtimeId(id: string): boolean {
|
|
41
|
+
return SYNTHETIC_REALTIME_ID_PREFIXES.some((prefix) => id.startsWith(prefix))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Flattens DESC-sorted message pages (newest page first, newest message
|
|
45
|
+
* first within a page) into one chronological list. */
|
|
46
|
+
export function flattenMessagePagesChronological<T>(pages: readonly { messages: readonly T[] }[] | undefined): T[] {
|
|
47
|
+
if (!pages) return []
|
|
48
|
+
return [...pages].reverse().flatMap((page) => [...page.messages].reverse())
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Max `lastChunkStreamSeq` across history pages — the history half of the
|
|
52
|
+
* merge's seq-coverage signal (`HistoryMergeInput.historyMaxStreamSeq`),
|
|
53
|
+
* also used by hosts as the JetStream replay start offset. 0 = unstamped. */
|
|
54
|
+
export function maxPersistedStreamSeq(
|
|
55
|
+
pages: readonly { messages: readonly { lastChunkStreamSeq?: number | null }[] }[] | undefined,
|
|
56
|
+
): number {
|
|
57
|
+
let max = 0
|
|
58
|
+
if (!pages) return max
|
|
59
|
+
for (const page of pages) {
|
|
60
|
+
for (const msg of page.messages) {
|
|
61
|
+
const seq = msg.lastChunkStreamSeq
|
|
62
|
+
if (typeof seq === 'number' && seq > max) max = seq
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return max
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface HistoryMergeInput<M extends MergeableChatMessage> {
|
|
69
|
+
/** Processed history in chronological order (all fetched pages). */
|
|
70
|
+
processedHistory: M[]
|
|
71
|
+
/** Raw history message ids across all fetched pages, when they can differ
|
|
72
|
+
* from processed ids (processing may merge/rename). Optional — pass when
|
|
73
|
+
* available so raw-id duplicates are filtered too. */
|
|
74
|
+
rawHistoryIds?: ReadonlySet<string>
|
|
75
|
+
/** Messages currently in the host store for this dialog (realtime + prior merges). */
|
|
76
|
+
existingMessages: M[]
|
|
77
|
+
/** Id of the in-flight streaming synthetic, if any. Never dropped.
|
|
78
|
+
* IMPORTANT: hosts must not pass a STALE id here (e.g. a streaming entry
|
|
79
|
+
* left behind by unmounting mid-stream) — gate it on the server-side
|
|
80
|
+
* stream state when available, or the synthetic will be exempted forever. */
|
|
81
|
+
streamingMessageId: string | null
|
|
82
|
+
/** Epoch ms when the history pages were fetched (react-query `dataUpdatedAt`).
|
|
83
|
+
* Wall-clock freshness fallback used when seq coverage (below) is unknown:
|
|
84
|
+
* a synthetic created AFTER this instant cannot be represented in the
|
|
85
|
+
* snapshot, so it must be kept. NOTE this heuristic is blind to chunk
|
|
86
|
+
* REPLAY, which re-mints synthetics for old turns with fresh timestamps —
|
|
87
|
+
* pass the seq fields whenever the host tracks them. */
|
|
88
|
+
historyFetchedAt: number
|
|
89
|
+
/** Max `lastChunkStreamSeq` across the raw history pages, when the backend
|
|
90
|
+
* stamps it (see `maxPersistedStreamSeq`). Together with
|
|
91
|
+
* `realtimeSeenStreamSeq` this gives an exact coverage signal that
|
|
92
|
+
* replaces the wall-clock heuristic. */
|
|
93
|
+
historyMaxStreamSeq?: number
|
|
94
|
+
/** Highest stream seq this client has consumed for the dialog (live or
|
|
95
|
+
* replayed chunks). */
|
|
96
|
+
realtimeSeenStreamSeq?: number
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function mergeHistoryWithRealtime<M extends MergeableChatMessage>(input: HistoryMergeInput<M>): M[] {
|
|
100
|
+
const {
|
|
101
|
+
processedHistory,
|
|
102
|
+
rawHistoryIds,
|
|
103
|
+
existingMessages,
|
|
104
|
+
streamingMessageId,
|
|
105
|
+
historyFetchedAt,
|
|
106
|
+
historyMaxStreamSeq = 0,
|
|
107
|
+
realtimeSeenStreamSeq = 0,
|
|
108
|
+
} = input
|
|
109
|
+
|
|
110
|
+
// An empty snapshot can't dedupe anything — merging would only let the
|
|
111
|
+
// freshness rules below wipe completed realtime messages (e.g. persistence
|
|
112
|
+
// lag on a fresh dialog). The realtime side stays the source of truth.
|
|
113
|
+
if (processedHistory.length === 0) return existingMessages
|
|
114
|
+
|
|
115
|
+
const processedIds = new Set(processedHistory.map((m) => m.id))
|
|
116
|
+
|
|
117
|
+
// Seq-based coverage: every synthetic is derived from consumed chunks, so
|
|
118
|
+
// when history's max persisted seq reaches the highest seq this client has
|
|
119
|
+
// consumed, ALL synthetics are represented in history (drop them); when it
|
|
120
|
+
// hasn't, history is provably behind (keep them ALL — even ones that look
|
|
121
|
+
// old by wall-clock, e.g. re-minted by a chunk replay). `null` = signal
|
|
122
|
+
// unavailable (legacy transport / backend without seq stamps) → fall back
|
|
123
|
+
// to the per-message wall-clock rule.
|
|
124
|
+
const seqCoverageKnown = realtimeSeenStreamSeq > 0 && historyMaxStreamSeq > 0
|
|
125
|
+
const historyCoversRealtime = seqCoverageKnown ? historyMaxStreamSeq >= realtimeSeenStreamSeq : null
|
|
126
|
+
|
|
127
|
+
// Persistence is asynchronous per-chunk: an assistant turn ending in an
|
|
128
|
+
// approval can have its APPROVAL_REQUEST document persisted before the
|
|
129
|
+
// leading THINKING/TEXT documents, so history can return a partial trailing
|
|
130
|
+
// assistant (just `[approval_batch]`) while the realtime store already has
|
|
131
|
+
// the full `[thinking, text, approval_batch]` synthetic. Resolve by
|
|
132
|
+
// `approval_batch.approvalRequestId`:
|
|
133
|
+
// - if the existing twin is the LIVE streaming message, or has more
|
|
134
|
+
// segments — drop the history assistant and pin the twin (realtime is
|
|
135
|
+
// the more complete / still-growing copy).
|
|
136
|
+
// - else (history is at least as complete) — drop the twin.
|
|
137
|
+
const trailing = processedHistory[processedHistory.length - 1]
|
|
138
|
+
const historyTrailingAssistant = trailing?.role === 'assistant' ? trailing : null
|
|
139
|
+
const historyBatchId =
|
|
140
|
+
historyTrailingAssistant && Array.isArray(historyTrailingAssistant.content)
|
|
141
|
+
? ((historyTrailingAssistant.content.find((s) => s.type === 'approval_batch') as ApprovalBatchSegment | undefined)
|
|
142
|
+
?.data?.approvalRequestId ?? null)
|
|
143
|
+
: null
|
|
144
|
+
|
|
145
|
+
let processedToUse = processedHistory
|
|
146
|
+
const pinnedSyntheticIds = new Set<string>()
|
|
147
|
+
const droppedSyntheticIds = new Set<string>()
|
|
148
|
+
|
|
149
|
+
if (historyBatchId) {
|
|
150
|
+
const batchTwins = existingMessages.filter(
|
|
151
|
+
(m) =>
|
|
152
|
+
m.role === 'assistant' &&
|
|
153
|
+
Array.isArray(m.content) &&
|
|
154
|
+
m.content.some(
|
|
155
|
+
(s) => s.type === 'approval_batch' && (s as ApprovalBatchSegment).data?.approvalRequestId === historyBatchId,
|
|
156
|
+
),
|
|
157
|
+
)
|
|
158
|
+
// Prefer the live streaming twin; otherwise the most recent one (a stale
|
|
159
|
+
// replay-minted duplicate may precede it).
|
|
160
|
+
const existingWithSameBatch = batchTwins.find((m) => m.id === streamingMessageId) ?? batchTwins[batchTwins.length - 1]
|
|
161
|
+
if (existingWithSameBatch && Array.isArray(existingWithSameBatch.content)) {
|
|
162
|
+
const histSize = Array.isArray(historyTrailingAssistant?.content) ? historyTrailingAssistant.content.length : 0
|
|
163
|
+
const realtimeSize = existingWithSameBatch.content.length
|
|
164
|
+
if (existingWithSameBatch.id === streamingMessageId || realtimeSize > histSize) {
|
|
165
|
+
processedToUse = processedHistory.slice(0, -1)
|
|
166
|
+
pinnedSyntheticIds.add(existingWithSameBatch.id)
|
|
167
|
+
} else {
|
|
168
|
+
droppedSyntheticIds.add(existingWithSameBatch.id)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const realtimeMessages = existingMessages.filter((m) => {
|
|
174
|
+
// Pin wins over everything: the twin may carry a persisted Mongo id (the
|
|
175
|
+
// chunk processors ADOPT an in-progress trailing assistant after a prior
|
|
176
|
+
// merge), in which case `processedIds`/`rawHistoryIds` would drop it even
|
|
177
|
+
// though the pin branch above already removed history's copy — vanishing
|
|
178
|
+
// the whole turn.
|
|
179
|
+
if (pinnedSyntheticIds.has(m.id)) return true
|
|
180
|
+
if (droppedSyntheticIds.has(m.id)) return false
|
|
181
|
+
if (processedIds.has(m.id)) return false
|
|
182
|
+
if (rawHistoryIds?.has(m.id)) return false
|
|
183
|
+
if (m.role === 'user' && m.id.startsWith('optimistic-') && typeof m.content === 'string') {
|
|
184
|
+
// Content-dedup only when the message predates the snapshot — a
|
|
185
|
+
// just-sent message whose text repeats an earlier turn ("yes", "ok")
|
|
186
|
+
// must not vanish against stale history. Wall-clock, not seq coverage:
|
|
187
|
+
// optimistic messages are minted on send, never by chunk replay, so
|
|
188
|
+
// their timestamps are trustworthy.
|
|
189
|
+
const canBeInSnapshot = (m.timestamp?.getTime() ?? 0) <= historyFetchedAt
|
|
190
|
+
return !(canBeInSnapshot && processedToUse.some((pm) => pm.role === 'user' && pm.content === m.content))
|
|
191
|
+
}
|
|
192
|
+
// Freshness rule: a synthetic whose turn is represented in the snapshot
|
|
193
|
+
// (under its persisted Mongo id) must be dropped or the turn renders
|
|
194
|
+
// twice; one the snapshot cannot contain yet must be kept or a message
|
|
195
|
+
// the user already saw is lost, with no realtime replay to restore it
|
|
196
|
+
// (JetStream resumes after the highest seq this client has consumed).
|
|
197
|
+
// Decided by seq coverage when known, wall-clock otherwise.
|
|
198
|
+
if (isSyntheticRealtimeId(m.id) && m.id !== streamingMessageId) {
|
|
199
|
+
const covered =
|
|
200
|
+
historyCoversRealtime !== null ? historyCoversRealtime : (m.timestamp?.getTime() ?? 0) <= historyFetchedAt
|
|
201
|
+
if (covered) return false
|
|
202
|
+
}
|
|
203
|
+
return true
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
return [...processedToUse, ...realtimeMessages]
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface HistoryPrependResult<M extends MergeableChatMessage> {
|
|
210
|
+
newMessages: M[]
|
|
211
|
+
boundaryMessageId?: string
|
|
212
|
+
boundaryUpdates?: { content: MessageContent }
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Pagination path (an older page arrived via fetchNextPage): everything on
|
|
216
|
+
* screen stays; collect only the messages above the first already-known id,
|
|
217
|
+
* plus a content refresh for that boundary message if it changed. Returns
|
|
218
|
+
* null when there is nothing to apply. */
|
|
219
|
+
export function computeHistoryPrepend<M extends MergeableChatMessage>(
|
|
220
|
+
processedHistory: M[],
|
|
221
|
+
existingMessages: M[],
|
|
222
|
+
): HistoryPrependResult<M> | null {
|
|
223
|
+
const existingIds = new Set(existingMessages.map((m) => m.id))
|
|
224
|
+
const newMessages: M[] = []
|
|
225
|
+
let boundaryMessageIndex = -1
|
|
226
|
+
|
|
227
|
+
for (let i = 0; i < processedHistory.length; i++) {
|
|
228
|
+
if (existingIds.has(processedHistory[i].id)) {
|
|
229
|
+
boundaryMessageIndex = i
|
|
230
|
+
break
|
|
231
|
+
}
|
|
232
|
+
newMessages.push(processedHistory[i])
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
let boundaryMessageId: string | undefined
|
|
236
|
+
let boundaryUpdates: { content: MessageContent } | undefined
|
|
237
|
+
|
|
238
|
+
if (boundaryMessageIndex >= 0) {
|
|
239
|
+
const boundaryMessage = processedHistory[boundaryMessageIndex]
|
|
240
|
+
const existingBoundary = existingMessages.find((m) => m.id === boundaryMessage.id)
|
|
241
|
+
|
|
242
|
+
if (existingBoundary) {
|
|
243
|
+
const existingContent = JSON.stringify(existingBoundary.content)
|
|
244
|
+
const newContent = JSON.stringify(boundaryMessage.content)
|
|
245
|
+
|
|
246
|
+
if (existingContent !== newContent) {
|
|
247
|
+
boundaryMessageId = boundaryMessage.id
|
|
248
|
+
boundaryUpdates = { content: boundaryMessage.content }
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (newMessages.length === 0 && !boundaryUpdates) return null
|
|
254
|
+
return { newMessages, boundaryMessageId, boundaryUpdates }
|
|
255
|
+
}
|
|
@@ -31,6 +31,18 @@ export {
|
|
|
31
31
|
extractIncompleteMessageState,
|
|
32
32
|
} from './extract-incomplete-message-state'
|
|
33
33
|
|
|
34
|
+
// History <-> realtime reconciliation
|
|
35
|
+
export {
|
|
36
|
+
mergeHistoryWithRealtime,
|
|
37
|
+
computeHistoryPrepend,
|
|
38
|
+
flattenMessagePagesChronological,
|
|
39
|
+
maxPersistedStreamSeq,
|
|
40
|
+
SYNTHETIC_REALTIME_ID_PREFIXES,
|
|
41
|
+
type MergeableChatMessage,
|
|
42
|
+
type HistoryMergeInput,
|
|
43
|
+
type HistoryPrependResult,
|
|
44
|
+
} from './history-merge'
|
|
45
|
+
|
|
34
46
|
// Tool call helpers
|
|
35
47
|
export { getCommandText } from './tool-call-helpers'
|
|
36
48
|
|
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
} from '../../utils/content-ref-groups';
|
|
52
52
|
import type { ContentRef, ContentRefWithReason } from '../../types/content-ref';
|
|
53
53
|
import { useSelfFetch } from '../../hooks/use-self-fetch';
|
|
54
|
-
import { extractItems } from '../../utils/extract-items';
|
|
54
|
+
import { extractItems, extractItemId } from '../../utils/extract-items';
|
|
55
55
|
import { buildListUrl as libBuildListUrl, canonicalContentRefType } from '../../utils/list-url';
|
|
56
56
|
import { buildSuggestionUrl } from '../../utils/suggestion-url';
|
|
57
57
|
import { decideNewTab } from '../chat/utils/decide-new-tab';
|
|
@@ -200,7 +200,6 @@ function CardForType({
|
|
|
200
200
|
}: {
|
|
201
201
|
type: string;
|
|
202
202
|
item: any;
|
|
203
|
-
contentRef: ContentRef;
|
|
204
203
|
size: CardSize;
|
|
205
204
|
href: string;
|
|
206
205
|
targetPlatform: string | null;
|
|
@@ -352,6 +351,7 @@ function ContentGroup({
|
|
|
352
351
|
LinkProvider,
|
|
353
352
|
extras,
|
|
354
353
|
adminCampaignCard,
|
|
354
|
+
heading,
|
|
355
355
|
}: {
|
|
356
356
|
type: string;
|
|
357
357
|
refs: ContentRef[];
|
|
@@ -361,6 +361,10 @@ function ContentGroup({
|
|
|
361
361
|
LinkProvider: CardLinkProvider;
|
|
362
362
|
extras?: ChatCardDispatchExtras;
|
|
363
363
|
adminCampaignCard?: AdminCampaignCardSlot;
|
|
364
|
+
/** Group heading, rendered INSIDE the group so a group that resolves to
|
|
365
|
+
* nothing (fetch miss / unsupported type / missing program config) drops
|
|
366
|
+
* its heading too — no orphaned titles. */
|
|
367
|
+
heading: React.ReactNode;
|
|
364
368
|
}) {
|
|
365
369
|
const { items, isLoading } = useGroupItems(type, refs, buildUrl);
|
|
366
370
|
const config = resolveGroupConfig(type);
|
|
@@ -374,10 +378,15 @@ function ContentGroup({
|
|
|
374
378
|
const skeletons = refs.map((r) => (
|
|
375
379
|
<div key={r.id}>{renderSkeletonForType(type, cardSize, adminCampaignCard)}</div>
|
|
376
380
|
));
|
|
377
|
-
return
|
|
378
|
-
<div className="space-y-4">
|
|
379
|
-
|
|
380
|
-
|
|
381
|
+
return (
|
|
382
|
+
<div className="space-y-4">
|
|
383
|
+
{heading}
|
|
384
|
+
{isListLayout ? (
|
|
385
|
+
<div className="space-y-4">{skeletons}</div>
|
|
386
|
+
) : (
|
|
387
|
+
<div className={gridClassFor(columns)}>{skeletons}</div>
|
|
388
|
+
)}
|
|
389
|
+
</div>
|
|
381
390
|
);
|
|
382
391
|
}
|
|
383
392
|
|
|
@@ -389,7 +398,11 @@ function ContentGroup({
|
|
|
389
398
|
// display_order). The list APIs return rows date-sorted, which would
|
|
390
399
|
// otherwise scramble that ordering (same-platform items sinking below
|
|
391
400
|
// newer cross-platform ones).
|
|
392
|
-
|
|
401
|
+
// Shared extractor (NOT raw `.id`) — some API shapes key items differently
|
|
402
|
+
// (e.g. external_id types); raw access would silently drop valid items.
|
|
403
|
+
const itemById = new Map(
|
|
404
|
+
(items as any[]).map((it) => [extractItemId(type, it) ?? String((it as any)?.id), it]),
|
|
405
|
+
);
|
|
393
406
|
|
|
394
407
|
const cards = refs
|
|
395
408
|
.map((contentRef) => {
|
|
@@ -409,7 +422,6 @@ function ContentGroup({
|
|
|
409
422
|
<CardForType
|
|
410
423
|
type={type}
|
|
411
424
|
item={item}
|
|
412
|
-
contentRef={contentRef}
|
|
413
425
|
size={cardSize}
|
|
414
426
|
href={href}
|
|
415
427
|
targetPlatform={targetPlatform}
|
|
@@ -426,10 +438,15 @@ function ContentGroup({
|
|
|
426
438
|
|
|
427
439
|
if (cards.length === 0) return null;
|
|
428
440
|
|
|
429
|
-
return
|
|
430
|
-
<div className="space-y-4">
|
|
431
|
-
|
|
432
|
-
|
|
441
|
+
return (
|
|
442
|
+
<div className="space-y-4">
|
|
443
|
+
{heading}
|
|
444
|
+
{isListLayout ? (
|
|
445
|
+
<div className="space-y-4">{cards}</div>
|
|
446
|
+
) : (
|
|
447
|
+
<div className={gridClassFor(columns)}>{cards}</div>
|
|
448
|
+
)}
|
|
449
|
+
</div>
|
|
433
450
|
);
|
|
434
451
|
}
|
|
435
452
|
|
|
@@ -536,14 +553,15 @@ export function RelatedContentSection({
|
|
|
536
553
|
// even []) or when the entity scope is incomplete.
|
|
537
554
|
// `includeTypes: []` is an explicit "nothing participates" — skip the fetch
|
|
538
555
|
// entirely (an empty-string `types=` param would be dropped by the URL
|
|
539
|
-
// builder and read server-side as "all candidates").
|
|
556
|
+
// builder and read server-side as "all candidates") AND ignore SSR refs.
|
|
557
|
+
const suggestionsDisabled = includeTypes?.length === 0;
|
|
540
558
|
const suggestUrl =
|
|
541
559
|
contentRefs === undefined &&
|
|
542
560
|
entityType &&
|
|
543
561
|
entityId !== undefined &&
|
|
544
562
|
entityId !== null &&
|
|
545
563
|
entityId !== '' &&
|
|
546
|
-
|
|
564
|
+
!suggestionsDisabled
|
|
547
565
|
? buildSuggestionUrl('/api/related-content', {
|
|
548
566
|
apiBaseUrl,
|
|
549
567
|
entityType,
|
|
@@ -560,8 +578,11 @@ export function RelatedContentSection({
|
|
|
560
578
|
// and a fresh per-render object would loop setState under re-rendering
|
|
561
579
|
// parents (the latent FaqSection bug, fixed there in the same change).
|
|
562
580
|
const initialData = useMemo<RelatedContentResponse | undefined>(
|
|
563
|
-
|
|
564
|
-
|
|
581
|
+
// An explicitly disabled rail (includeTypes: []) must ignore SSR-hydrated
|
|
582
|
+
// refs too — otherwise useSelfFetch(null, {initialData}) keeps serving
|
|
583
|
+
// initialItems and the "nothing participates" contract silently breaks.
|
|
584
|
+
() => (!suggestionsDisabled && initialItems ? { refs: initialItems } : undefined),
|
|
585
|
+
[initialItems, suggestionsDisabled],
|
|
565
586
|
);
|
|
566
587
|
const { data } = useSelfFetch<RelatedContentResponse>(suggestUrl, { initialData });
|
|
567
588
|
|
|
@@ -599,9 +620,13 @@ export function RelatedContentSection({
|
|
|
599
620
|
// the shared alias canonicalizer (blog_post_existing ↔ blog_post).
|
|
600
621
|
let orderedTypes = orderContentRefTypes(Object.keys(grouped));
|
|
601
622
|
if (entityType) {
|
|
602
|
-
|
|
623
|
+
// Canonicalize BOTH sides — hosts pass registry vocab ('blog_post') but
|
|
624
|
+
// rail-vocab aliases ('blog_post_existing') are also legal inputs; a raw
|
|
625
|
+
// comparison would silently lose the same-type-first hoist for aliases.
|
|
626
|
+
const canonicalEntityType = canonicalContentRefType(entityType);
|
|
627
|
+
const sameType = orderedTypes.filter((t) => canonicalContentRefType(t) === canonicalEntityType);
|
|
603
628
|
if (sameType.length > 0) {
|
|
604
|
-
orderedTypes = [...sameType, ...orderedTypes.filter((t) => canonicalContentRefType(t) !==
|
|
629
|
+
orderedTypes = [...sameType, ...orderedTypes.filter((t) => canonicalContentRefType(t) !== canonicalEntityType)];
|
|
605
630
|
}
|
|
606
631
|
}
|
|
607
632
|
|
|
@@ -609,21 +634,22 @@ export function RelatedContentSection({
|
|
|
609
634
|
<div className="space-y-8">
|
|
610
635
|
<h2 className="text-2xl font-bold text-ods-text-primary">{title}</h2>
|
|
611
636
|
{orderedTypes.map((type) => (
|
|
612
|
-
<
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
637
|
+
<ContentGroup
|
|
638
|
+
key={type}
|
|
639
|
+
type={type}
|
|
640
|
+
refs={grouped[type]}
|
|
641
|
+
columns={columns}
|
|
642
|
+
buildUrl={effectiveBuildListUrl}
|
|
643
|
+
resolveHref={resolveHref}
|
|
644
|
+
LinkProvider={LinkProvider}
|
|
645
|
+
extras={extras}
|
|
646
|
+
adminCampaignCard={adminCampaignCard}
|
|
647
|
+
heading={
|
|
648
|
+
<h3 className="font-['Azeret_Mono'] text-[14px] font-semibold uppercase text-ods-text-secondary tracking-wider">
|
|
649
|
+
{getContentRefLabelOrTitleCase(type)}
|
|
650
|
+
</h3>
|
|
651
|
+
}
|
|
652
|
+
/>
|
|
627
653
|
))}
|
|
628
654
|
</div>
|
|
629
655
|
);
|