@flamingo-stack/openframe-frontend-core 0.0.607 → 0.0.608-snapshot.20260908153450
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-7ZAPPBFT.cjs → chunk-3N4FXBVJ.cjs} +3 -3
- package/dist/{chunk-7ZAPPBFT.cjs.map → chunk-3N4FXBVJ.cjs.map} +1 -1
- package/dist/{chunk-PS4WZ7YL.cjs → chunk-3XNMDLGB.cjs} +9 -9
- package/dist/{chunk-PS4WZ7YL.cjs.map → chunk-3XNMDLGB.cjs.map} +1 -1
- package/dist/{chunk-UJ64PL7A.cjs → chunk-45XXK2VU.cjs} +10 -10
- package/dist/{chunk-UJ64PL7A.cjs.map → chunk-45XXK2VU.cjs.map} +1 -1
- package/dist/{chunk-ANHHTB32.js → chunk-6MLRFM3T.js} +5 -5
- package/dist/{chunk-ZYEAIBWA.js → chunk-B3UXNGVM.js} +3 -3
- package/dist/{chunk-2V3PJ5X5.js → chunk-B7LYKBCD.js} +5 -5
- package/dist/{chunk-JGSEBZYO.js → chunk-BSMPCPOZ.js} +155 -38
- package/dist/{chunk-JGSEBZYO.js.map → chunk-BSMPCPOZ.js.map} +1 -1
- package/dist/{chunk-3J73ZG3V.js → chunk-BUXGWBTF.js} +2 -2
- package/dist/{chunk-63AGD45L.js → chunk-C7CTEUU7.js} +2 -2
- package/dist/{chunk-XOQI3AH7.cjs → chunk-CZTOSG7Q.cjs} +22 -22
- package/dist/{chunk-XOQI3AH7.cjs.map → chunk-CZTOSG7Q.cjs.map} +1 -1
- package/dist/{chunk-Y6MYIJTK.cjs → chunk-D3DTC7SZ.cjs} +15 -15
- package/dist/{chunk-Y6MYIJTK.cjs.map → chunk-D3DTC7SZ.cjs.map} +1 -1
- package/dist/{chunk-YUDYFA6H.cjs → chunk-DKNXAJMP.cjs} +183 -163
- package/dist/chunk-DKNXAJMP.cjs.map +1 -0
- package/dist/{chunk-XRNILWKL.cjs → chunk-FYG7QNAO.cjs} +5 -5
- package/dist/{chunk-XRNILWKL.cjs.map → chunk-FYG7QNAO.cjs.map} +1 -1
- package/dist/{chunk-IXXMNATN.cjs → chunk-GMOBT5NP.cjs} +70 -70
- package/dist/{chunk-IXXMNATN.cjs.map → chunk-GMOBT5NP.cjs.map} +1 -1
- package/dist/{chunk-CCY47QKL.js → chunk-HGVW7OHI.js} +2 -2
- package/dist/{chunk-7CQA7DAB.js → chunk-JKM5FH63.js} +3 -3
- package/dist/{chunk-RVCLDXCR.js → chunk-JOCVQZGT.js} +5 -5
- package/dist/{chunk-GPIPJOOV.js → chunk-JR7I2AGL.js} +3 -3
- package/dist/{chunk-SWC5LOGS.cjs → chunk-L2JWC5VS.cjs} +43 -43
- package/dist/{chunk-SWC5LOGS.cjs.map → chunk-L2JWC5VS.cjs.map} +1 -1
- package/dist/{chunk-TF6FCNKU.js → chunk-LA2W5L6K.js} +2 -2
- package/dist/{chunk-XJKNJJYO.js → chunk-MVBRMQGU.js} +26 -6
- package/dist/{chunk-XJKNJJYO.js.map → chunk-MVBRMQGU.js.map} +1 -1
- package/dist/{chunk-G7ZK3Q5B.cjs → chunk-NJUSDREV.cjs} +22 -22
- package/dist/{chunk-G7ZK3Q5B.cjs.map → chunk-NJUSDREV.cjs.map} +1 -1
- package/dist/{chunk-Q6ZFTDRR.cjs → chunk-O2M4T34Q.cjs} +4 -4
- package/dist/{chunk-Q6ZFTDRR.cjs.map → chunk-O2M4T34Q.cjs.map} +1 -1
- package/dist/{chunk-PSGHIQXU.js → chunk-OTYV6SDN.js} +3 -3
- package/dist/{chunk-YCOXI5CH.js → chunk-QX4ANESW.js} +6 -6
- package/dist/{chunk-JLVIGGUF.cjs → chunk-RZM6FPOT.cjs} +25 -25
- package/dist/{chunk-JLVIGGUF.cjs.map → chunk-RZM6FPOT.cjs.map} +1 -1
- package/dist/{chunk-WR23DZLT.cjs → chunk-SEW25Y2W.cjs} +10 -10
- package/dist/{chunk-WR23DZLT.cjs.map → chunk-SEW25Y2W.cjs.map} +1 -1
- package/dist/{chunk-25XSOCZK.cjs → chunk-TCEALWE3.cjs} +33 -33
- package/dist/{chunk-25XSOCZK.cjs.map → chunk-TCEALWE3.cjs.map} +1 -1
- package/dist/{chunk-Z2NXXA27.js → chunk-TJ3GFULR.js} +3 -3
- package/dist/{chunk-3FC4DPRX.js → chunk-VCYRJY7J.js} +4 -4
- package/dist/{chunk-VK743MVL.cjs → chunk-XNDTYTVT.cjs} +188 -71
- package/dist/chunk-XNDTYTVT.cjs.map +1 -0
- package/dist/{chunk-BEDMOEAM.cjs → chunk-ZRLFBLME.cjs} +3 -3
- package/dist/{chunk-BEDMOEAM.cjs.map → chunk-ZRLFBLME.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/index.cjs +2 -2
- package/dist/components/chat/index.js +1 -1
- package/dist/components/chat/utils/history-merge.d.ts +4 -2
- package/dist/components/chat/utils/history-merge.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/board/index.d.ts +1 -1
- package/dist/components/features/board/index.d.ts.map +1 -1
- package/dist/components/features/board/ticket-card.d.ts.map +1 -1
- package/dist/components/features/board/types.d.ts +18 -0
- package/dist/components/features/board/types.d.ts.map +1 -1
- 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/package.json +1 -1
- package/src/components/chat/utils/__tests__/history-merge.test.ts +292 -0
- package/src/components/chat/utils/history-merge.ts +276 -56
- package/src/components/features/board/index.ts +2 -0
- package/src/components/features/board/ticket-card.tsx +31 -2
- package/src/components/features/board/types.ts +20 -0
- package/src/stories/TicketCard.stories.tsx +40 -1
- package/dist/chunk-VK743MVL.cjs.map +0 -1
- package/dist/chunk-YUDYFA6H.cjs.map +0 -1
- /package/dist/{chunk-ANHHTB32.js.map → chunk-6MLRFM3T.js.map} +0 -0
- /package/dist/{chunk-ZYEAIBWA.js.map → chunk-B3UXNGVM.js.map} +0 -0
- /package/dist/{chunk-2V3PJ5X5.js.map → chunk-B7LYKBCD.js.map} +0 -0
- /package/dist/{chunk-3J73ZG3V.js.map → chunk-BUXGWBTF.js.map} +0 -0
- /package/dist/{chunk-63AGD45L.js.map → chunk-C7CTEUU7.js.map} +0 -0
- /package/dist/{chunk-CCY47QKL.js.map → chunk-HGVW7OHI.js.map} +0 -0
- /package/dist/{chunk-7CQA7DAB.js.map → chunk-JKM5FH63.js.map} +0 -0
- /package/dist/{chunk-RVCLDXCR.js.map → chunk-JOCVQZGT.js.map} +0 -0
- /package/dist/{chunk-GPIPJOOV.js.map → chunk-JR7I2AGL.js.map} +0 -0
- /package/dist/{chunk-TF6FCNKU.js.map → chunk-LA2W5L6K.js.map} +0 -0
- /package/dist/{chunk-PSGHIQXU.js.map → chunk-OTYV6SDN.js.map} +0 -0
- /package/dist/{chunk-YCOXI5CH.js.map → chunk-QX4ANESW.js.map} +0 -0
- /package/dist/{chunk-Z2NXXA27.js.map → chunk-TJ3GFULR.js.map} +0 -0
- /package/dist/{chunk-3FC4DPRX.js.map → chunk-VCYRJY7J.js.map} +0 -0
|
@@ -63,6 +63,33 @@ function isSyntheticRealtimeId(id: string): boolean {
|
|
|
63
63
|
return SYNTHETIC_REALTIME_ID_PREFIXES.some(prefix => id.startsWith(prefix));
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/** Host-minted user bubble of a send in flight. Deliberately NOT one of the
|
|
67
|
+
* synthetic-realtime prefixes — see the note above them. */
|
|
68
|
+
function isOptimisticId(id: string): boolean {
|
|
69
|
+
return id.startsWith('optimistic-');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Peer `MESSAGE_REQUEST` echo (another session's send). Its persisted twin is
|
|
73
|
+
* the one row kind the backend never stamps with a `lastChunkStreamSeq`, so
|
|
74
|
+
* seq can never prove it in or out of a snapshot — every site that treats
|
|
75
|
+
* `user-` specially exists for that, and all of them go when the backend
|
|
76
|
+
* starts stamping user rows. */
|
|
77
|
+
function isUserRequestSyntheticId(id: string): boolean {
|
|
78
|
+
return id.startsWith('user-');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** A row this client made up and never fetched. Everything else (`welcome-`
|
|
82
|
+
* included) reads as a persisted row where the thread's own shape cannot say
|
|
83
|
+
* otherwise. */
|
|
84
|
+
function isClientMintedId(id: string): boolean {
|
|
85
|
+
return isSyntheticRealtimeId(id) || isOptimisticId(id);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The host's greeting on a fresh dialog: never persisted, belongs at the top. */
|
|
89
|
+
function isWelcomeId(id: string): boolean {
|
|
90
|
+
return id.startsWith('welcome-');
|
|
91
|
+
}
|
|
92
|
+
|
|
66
93
|
/** Rendered answer text of an assistant message (TEXT segments, or a plain string). Used to
|
|
67
94
|
* recognise a replayed synthetic as the twin of an already-persisted turn when the stream-seq
|
|
68
95
|
* signal can't prove it (see the trailing-turn fallback below). Empty for tool/approval-only
|
|
@@ -118,15 +145,73 @@ function turnRequestKeys(content: MessageContent): Set<string> {
|
|
|
118
145
|
return keys;
|
|
119
146
|
}
|
|
120
147
|
|
|
121
|
-
/** Whether
|
|
122
|
-
function sharesRequestKey(
|
|
123
|
-
if (keys.size === 0) return false;
|
|
124
|
-
for (const key of
|
|
125
|
-
if (
|
|
148
|
+
/** Whether any of a turn's `keys` (see `turnRequestKeys`) is in `others`. */
|
|
149
|
+
function sharesRequestKey(keys: ReadonlySet<string>, others: ReadonlySet<string>): boolean {
|
|
150
|
+
if (keys.size === 0 || others.size === 0) return false;
|
|
151
|
+
for (const key of keys) {
|
|
152
|
+
if (others.has(key)) return true;
|
|
126
153
|
}
|
|
127
154
|
return false;
|
|
128
155
|
}
|
|
129
156
|
|
|
157
|
+
/** A user row's identity is its text; empty text is no identity (system rows
|
|
158
|
+
* persist with `content: ''`). `''` for any other row. */
|
|
159
|
+
function userText(m: MergeableChatMessage): string {
|
|
160
|
+
return m.role === 'user' && typeof m.content === 'string' ? m.content : '';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** What a set of rows says about the turns they render, so another copy of one
|
|
164
|
+
* of those turns can be recognised under a DIFFERENT id: the backend request
|
|
165
|
+
* ids their segments carry, their answer texts and their user texts. The text
|
|
166
|
+
* maps count occurrences for the callers that pair copies positionally (a
|
|
167
|
+
* repeated prompt twins the NEWEST unclaimed same-text row); `twinVerdict`
|
|
168
|
+
* itself reads them as presence. Empty user text carries no identity (system
|
|
169
|
+
* rows persist with `content: ''`) and is left out. */
|
|
170
|
+
interface TwinSignals {
|
|
171
|
+
requestKeys: Set<string>;
|
|
172
|
+
assistantTexts: Map<string, number>;
|
|
173
|
+
userContents: Map<string, number>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function collectTwinSignals(rows: readonly MergeableChatMessage[]): TwinSignals {
|
|
177
|
+
const signals: TwinSignals = { requestKeys: new Set(), assistantTexts: new Map(), userContents: new Map() };
|
|
178
|
+
for (const row of rows) {
|
|
179
|
+
for (const key of turnRequestKeys(row.content)) signals.requestKeys.add(key);
|
|
180
|
+
if (row.role === 'assistant') {
|
|
181
|
+
const text = assistantAnswerText(row.content);
|
|
182
|
+
if (text !== '') signals.assistantTexts.set(text, (signals.assistantTexts.get(text) ?? 0) + 1);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const text = userText(row);
|
|
186
|
+
if (text !== '') signals.userContents.set(text, (signals.userContents.get(text) ?? 0) + 1);
|
|
187
|
+
}
|
|
188
|
+
return signals;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
type TwinVerdict = 'twin' | 'distinct' | 'unknown';
|
|
192
|
+
|
|
193
|
+
/** Whether `m` renders one of the turns `signals` describe. 'twin': a shared
|
|
194
|
+
* request id, a user text held verbatim, or an answer text that is a prefix
|
|
195
|
+
* either way of one held — streaming only appends, so a copy cut short, or a
|
|
196
|
+
* persisted row still being written, is a prefix of the full one. 'unknown':
|
|
197
|
+
* the row carries nothing a twin could be recognised by (no user text, no
|
|
198
|
+
* request id, no answer text), so "no match" says nothing about it. */
|
|
199
|
+
function twinVerdict(signals: TwinSignals, m: MergeableChatMessage): TwinVerdict {
|
|
200
|
+
if (m.role !== 'assistant') {
|
|
201
|
+
const text = userText(m);
|
|
202
|
+
if (text === '') return 'unknown';
|
|
203
|
+
return signals.userContents.has(text) ? 'twin' : 'distinct';
|
|
204
|
+
}
|
|
205
|
+
const keys = turnRequestKeys(m.content);
|
|
206
|
+
if (keys.size > 0) return sharesRequestKey(keys, signals.requestKeys) ? 'twin' : 'distinct';
|
|
207
|
+
const text = assistantAnswerText(m.content);
|
|
208
|
+
if (text === '') return 'unknown';
|
|
209
|
+
for (const other of signals.assistantTexts.keys()) {
|
|
210
|
+
if (other.startsWith(text) || text.startsWith(other)) return 'twin';
|
|
211
|
+
}
|
|
212
|
+
return 'distinct';
|
|
213
|
+
}
|
|
214
|
+
|
|
130
215
|
/** Flattens DESC-sorted message pages (newest page first, newest message
|
|
131
216
|
* first within a page) into one chronological list. */
|
|
132
217
|
export function flattenMessagePagesChronological<T>(pages: readonly { messages: readonly T[] }[] | undefined): T[] {
|
|
@@ -308,7 +393,7 @@ export function mergeHistoryWithRealtime<M extends MergeableChatMessage>(input:
|
|
|
308
393
|
// `approvalRequestId`, widened to tool calls.
|
|
309
394
|
const trailingKeys = turnRequestKeys(historyTrailingAssistant.content);
|
|
310
395
|
const isSameTurn = (m: M): boolean =>
|
|
311
|
-
m.id === historyTrailingAssistant.id ||
|
|
396
|
+
m.id === historyTrailingAssistant.id || sharesRequestKey(turnRequestKeys(m.content), trailingKeys);
|
|
312
397
|
const richerTwin = existingMessages.find(
|
|
313
398
|
m =>
|
|
314
399
|
m !== historyTrailingAssistant &&
|
|
@@ -339,42 +424,112 @@ export function mergeHistoryWithRealtime<M extends MergeableChatMessage>(input:
|
|
|
339
424
|
const trailingAssistantText =
|
|
340
425
|
lastProcessed && lastProcessed.role === 'assistant' ? assistantAnswerText(lastProcessed.content) : '';
|
|
341
426
|
|
|
342
|
-
//
|
|
343
|
-
//
|
|
344
|
-
//
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
//
|
|
349
|
-
//
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
|
|
427
|
+
// Content identity of the window, for recognising copies of its turns under
|
|
428
|
+
// other ids; its `userContents` multiset is also what the `user-` branch of
|
|
429
|
+
// `keepRealtime` pairs echoes against positionally (rationale there).
|
|
430
|
+
const windowSignals = collectTwinSignals(processedToUse);
|
|
431
|
+
const seenUserSyntheticByContent = new Map<string, number>();
|
|
432
|
+
|
|
433
|
+
// The window boundary. `processedHistory` is what the host FETCHED, and hosts
|
|
434
|
+
// fetch newest-first with a fixed page count: once the thread has grown, the
|
|
435
|
+
// same fetch returns the newest N×limit rows and the head of what is on
|
|
436
|
+
// screen is no longer in it. Those rows have no twin the window could hold,
|
|
437
|
+
// so the dedup rules below must never see them — coverage read a synthetic
|
|
438
|
+
// older than the window as "a persisted row reached this seq" and DROPPED it,
|
|
439
|
+
// and an unordered keep appended a persisted row AFTER the newest reply. Both
|
|
440
|
+
// were the reported "conversation reverts to an earlier state after a
|
|
441
|
+
// refresh". Rows older than the window are kept verbatim, in their existing
|
|
442
|
+
// order, in FRONT of it.
|
|
443
|
+
//
|
|
444
|
+
// `existingMessages` is chronological (every write path appends, prepends an
|
|
445
|
+
// older page, or is this merge), so the thread's own shape decides first:
|
|
446
|
+
// - where it holds window rows, the first of them is the boundary. Rows
|
|
447
|
+
// from it on are the window and its live tail, whatever their id or
|
|
448
|
+
// clock says — a host-minted tail row such as a ticket preview must not
|
|
449
|
+
// be pulled to the top. One exception before it: a client-minted row
|
|
450
|
+
// that shares a request id with a window row IS that row's copy, placed
|
|
451
|
+
// by a previous merge while the row's stamp was missing, and goes back to
|
|
452
|
+
// coverage so the placement heals instead of being cemented.
|
|
453
|
+
// - where it holds none (every window row is the persisted twin of a
|
|
454
|
+
// synthetic, or the store was empty), the window IS the newest persisted
|
|
455
|
+
// rows, so a persisted id absent from it is older by construction — and
|
|
456
|
+
// so is everything before the last such row. "Persisted" needs the row
|
|
457
|
+
// to predate the fetch: a host-minted row newer than it (a ticket
|
|
458
|
+
// preview) is not history, whatever its id. Unless the thread holds no
|
|
459
|
+
// client-minted row at all: then nothing bridges those rows to the
|
|
460
|
+
// window, the gap is rows this client never saw, and the next older page
|
|
461
|
+
// would be prepended above them out of order — the window alone is the
|
|
462
|
+
// thread, the rest is refetchable (a `welcome-` bubble is not, and stays).
|
|
463
|
+
// Only rows past both anchors are judged on their own:
|
|
464
|
+
// - a seq-stamped synthetic below every stamped window row: seq is
|
|
465
|
+
// monotonic per dialog, but a copy CUT SHORT carries its last consumed
|
|
466
|
+
// chunk's seq, below its twin's stamp — so `twinVerdict` decides where it
|
|
467
|
+
// has a signal, and seq decides an 'unknown' only where it cannot
|
|
468
|
+
// mislead: not for a `user-` / optimistic copy (twin never stamped), nor
|
|
469
|
+
// for an assistant copy while the window holds an unstamped assistant
|
|
470
|
+
// row. A `direct-` / `system-` copy has a stamped twin, so seq is exact.
|
|
471
|
+
// - an unstamped synthetic / optimistic row: minted BEFORE the fetch
|
|
472
|
+
// (`historyFetchedAt`, client clock like the row's own stamp, so a send
|
|
473
|
+
// after the fetch never qualifies), timestamped before the window's
|
|
474
|
+
// oldest row (server clock — a client clock behind the server can still
|
|
475
|
+
// misread a pre-fetch row, hence the verdict too) and 'distinct'.
|
|
476
|
+
// Replay-minted synthetics carry fresh timestamps and never qualify.
|
|
477
|
+
const isInWindow = (m: M): boolean => processedIds.has(m.id) || (rawHistoryIds?.has(m.id) ?? false);
|
|
478
|
+
const firstWindowIndex = existingMessages.findIndex(isInWindow);
|
|
479
|
+
const isPersistedOlder = (m: M): boolean =>
|
|
480
|
+
!isClientMintedId(m.id) && (m.timestamp?.getTime() ?? 0) <= historyFetchedAt;
|
|
481
|
+
let lastOlderPersistedIndex = -1;
|
|
482
|
+
if (firstWindowIndex < 0) {
|
|
483
|
+
for (const [index, m] of existingMessages.entries()) {
|
|
484
|
+
if (isPersistedOlder(m) && !pinnedSyntheticIds.has(m.id) && !droppedSyntheticIds.has(m.id)) {
|
|
485
|
+
lastOlderPersistedIndex = index;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
let windowMinSeq = Number.POSITIVE_INFINITY;
|
|
490
|
+
let windowMinTime = Number.POSITIVE_INFINITY;
|
|
491
|
+
let windowHasUnstampedAssistant = false;
|
|
353
492
|
for (const pm of processedToUse) {
|
|
354
|
-
if (
|
|
355
|
-
|
|
493
|
+
if (typeof pm.streamSeq === 'number') {
|
|
494
|
+
if (pm.streamSeq < windowMinSeq) windowMinSeq = pm.streamSeq;
|
|
495
|
+
} else if (pm.role === 'assistant') {
|
|
496
|
+
windowHasUnstampedAssistant = true;
|
|
356
497
|
}
|
|
498
|
+
const time = pm.timestamp?.getTime();
|
|
499
|
+
if (typeof time === 'number' && time < windowMinTime) windowMinTime = time;
|
|
357
500
|
}
|
|
358
|
-
const
|
|
501
|
+
const threadHasClientMintedRow = existingMessages.some(m => isClientMintedId(m.id));
|
|
502
|
+
const seqCanMislead = (m: M): boolean =>
|
|
503
|
+
m.role === 'assistant' ? windowHasUnstampedAssistant : isUserRequestSyntheticId(m.id) || isOptimisticId(m.id);
|
|
504
|
+
const isOlderThanWindow = (m: M, index: number): boolean => {
|
|
505
|
+
if (m.id === streamingMessageId) return false;
|
|
506
|
+
if (firstWindowIndex >= 0) {
|
|
507
|
+
if (index >= firstWindowIndex) return false;
|
|
508
|
+
return !(isClientMintedId(m.id) && sharesRequestKey(turnRequestKeys(m.content), windowSignals.requestKeys));
|
|
509
|
+
}
|
|
510
|
+
if (index < lastOlderPersistedIndex) return true;
|
|
511
|
+
if (!isClientMintedId(m.id)) return isPersistedOlder(m);
|
|
512
|
+
if (typeof m.streamSeq === 'number') {
|
|
513
|
+
if (!Number.isFinite(windowMinSeq) || m.streamSeq >= windowMinSeq) return false;
|
|
514
|
+
const verdict = twinVerdict(windowSignals, m);
|
|
515
|
+
return verdict === 'unknown' ? !seqCanMislead(m) : verdict === 'distinct';
|
|
516
|
+
}
|
|
517
|
+
const time = m.timestamp?.getTime();
|
|
518
|
+
if (typeof time !== 'number' || time > historyFetchedAt) return false;
|
|
519
|
+
if (!Number.isFinite(windowMinTime) || time >= windowMinTime) return false;
|
|
520
|
+
return twinVerdict(windowSignals, m) === 'distinct';
|
|
521
|
+
};
|
|
359
522
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
// merge), in which case `processedIds`/`rawHistoryIds` would drop it even
|
|
364
|
-
// though the pin branch above already removed history's copy — vanishing
|
|
365
|
-
// the whole turn.
|
|
366
|
-
if (pinnedSyntheticIds.has(m.id)) return true;
|
|
367
|
-
if (droppedSyntheticIds.has(m.id)) return false;
|
|
368
|
-
if (processedIds.has(m.id)) return false;
|
|
369
|
-
if (rawHistoryIds?.has(m.id)) return false;
|
|
370
|
-
if (m.role === 'user' && m.id.startsWith('optimistic-') && typeof m.content === 'string') {
|
|
523
|
+
// The dedup rules for a row at or after the window boundary.
|
|
524
|
+
const keepRealtime = (m: M): boolean => {
|
|
525
|
+
if (m.role === 'user' && isOptimisticId(m.id) && typeof m.content === 'string') {
|
|
371
526
|
// Content-dedup only when the message predates the snapshot — a
|
|
372
527
|
// just-sent message whose text repeats an earlier turn ("yes", "ok")
|
|
373
528
|
// must not vanish against stale history. Wall-clock, not seq coverage:
|
|
374
529
|
// optimistic messages are minted on send, never by chunk replay, so
|
|
375
530
|
// their timestamps are trustworthy.
|
|
376
531
|
const canBeInSnapshot = (m.timestamp?.getTime() ?? 0) <= historyFetchedAt;
|
|
377
|
-
return !(canBeInSnapshot &&
|
|
532
|
+
return !(canBeInSnapshot && windowSignals.userContents.has(m.content));
|
|
378
533
|
}
|
|
379
534
|
// Freshness rule: a synthetic whose turn is represented in the snapshot
|
|
380
535
|
// (under its persisted Mongo id) must be dropped or the turn renders
|
|
@@ -394,7 +549,7 @@ export function mergeHistoryWithRealtime<M extends MergeableChatMessage>(input:
|
|
|
394
549
|
// which carry the chunk seq), so seq coverage can NEVER see them (the twin
|
|
395
550
|
// adds 0 to every seq max) and wall-clock can't either (replay re-mints a
|
|
396
551
|
// fresh timestamp). Dedup them purely by TEXT, matched positionally
|
|
397
|
-
// against persisted user rows (
|
|
552
|
+
// against persisted user rows (`windowSignals.userContents`): drop the
|
|
398
553
|
// synthetic once its own row is in the snapshot — trailing twin or not,
|
|
399
554
|
// killing the client→viewer duplicate — while keeping a later same-text
|
|
400
555
|
// turn whose row hasn't persisted yet. `direct-` / `system-` synthetics
|
|
@@ -404,11 +559,11 @@ export function mergeHistoryWithRealtime<M extends MergeableChatMessage>(input:
|
|
|
404
559
|
// `lastChunkStreamSeq`; the durable fix is the backend stamping it (as it
|
|
405
560
|
// already does for DIRECT/SYSTEM), which also stops the replay at the
|
|
406
561
|
// source via a correct `optStartSeq`.
|
|
407
|
-
if (m.role === 'user' && m.id
|
|
562
|
+
if (m.role === 'user' && isUserRequestSyntheticId(m.id) && typeof m.content === 'string') {
|
|
408
563
|
const seen = (seenUserSyntheticByContent.get(m.content) ?? 0) + 1;
|
|
409
564
|
seenUserSyntheticByContent.set(m.content, seen);
|
|
410
565
|
// No persisted row for THIS occurrence slot → keep (nothing renders it).
|
|
411
|
-
if ((
|
|
566
|
+
if ((windowSignals.userContents.get(m.content) ?? 0) < seen) return true;
|
|
412
567
|
// A same-text persisted twin exists for this slot. User rows carry no
|
|
413
568
|
// persisted seq, so that twin may be THIS message's OWN row (drop — it
|
|
414
569
|
// renders the message) OR an OLDER identical-text turn while this is a
|
|
@@ -471,9 +626,32 @@ export function mergeHistoryWithRealtime<M extends MergeableChatMessage>(input:
|
|
|
471
626
|
if (covered) return false;
|
|
472
627
|
}
|
|
473
628
|
return true;
|
|
474
|
-
}
|
|
629
|
+
};
|
|
475
630
|
|
|
476
|
-
|
|
631
|
+
const olderThanWindowMessages: M[] = [];
|
|
632
|
+
const realtimeMessages: M[] = [];
|
|
633
|
+
for (const [index, m] of existingMessages.entries()) {
|
|
634
|
+
// Pin wins over everything: the twin may carry a persisted Mongo id (the
|
|
635
|
+
// chunk processors ADOPT an in-progress trailing assistant after a prior
|
|
636
|
+
// merge), in which case `processedIds`/`rawHistoryIds` would drop it even
|
|
637
|
+
// though the pin branch above already removed history's copy — vanishing
|
|
638
|
+
// the whole turn.
|
|
639
|
+
if (pinnedSyntheticIds.has(m.id)) {
|
|
640
|
+
realtimeMessages.push(m);
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
if (droppedSyntheticIds.has(m.id) || isInWindow(m)) continue;
|
|
644
|
+
// Persisted rows disjoint from the window with nothing live between — see
|
|
645
|
+
// the boundary note: the gap is rows this client never saw.
|
|
646
|
+
if (firstWindowIndex < 0 && !threadHasClientMintedRow && isPersistedOlder(m) && !isWelcomeId(m.id)) continue;
|
|
647
|
+
if (isOlderThanWindow(m, index)) {
|
|
648
|
+
olderThanWindowMessages.push(m);
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
if (keepRealtime(m)) realtimeMessages.push(m);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
return [...olderThanWindowMessages, ...processedToUse, ...realtimeMessages];
|
|
477
655
|
}
|
|
478
656
|
|
|
479
657
|
export interface HistoryPrependResult<M extends MergeableChatMessage> {
|
|
@@ -484,39 +662,81 @@ export interface HistoryPrependResult<M extends MergeableChatMessage> {
|
|
|
484
662
|
|
|
485
663
|
/** Pagination path (an older page arrived via fetchNextPage): everything on
|
|
486
664
|
* screen stays; collect only the messages above the first already-known id,
|
|
487
|
-
* plus a content refresh for that boundary message if it changed.
|
|
488
|
-
*
|
|
665
|
+
* plus a content refresh for that boundary message if it changed. Persisted
|
|
666
|
+
* twins of client-minted rows the thread still shows above that boundary are
|
|
667
|
+
* left out (see the note in the body). Returns null when there is nothing to
|
|
668
|
+
* apply. */
|
|
489
669
|
export function computeHistoryPrepend<M extends MergeableChatMessage>(
|
|
490
670
|
processedHistory: M[],
|
|
491
671
|
existingMessages: M[],
|
|
492
672
|
): HistoryPrependResult<M> | null {
|
|
493
673
|
const existingIds = new Set(existingMessages.map(m => m.id));
|
|
494
|
-
const
|
|
495
|
-
|
|
674
|
+
const boundaryMessageIndex = processedHistory.findIndex(m => existingIds.has(m.id));
|
|
675
|
+
const newEnd = boundaryMessageIndex >= 0 ? boundaryMessageIndex : processedHistory.length;
|
|
676
|
+
const boundaryIndexInExisting =
|
|
677
|
+
boundaryMessageIndex >= 0
|
|
678
|
+
? existingMessages.findIndex(m => m.id === processedHistory[boundaryMessageIndex].id)
|
|
679
|
+
: -1;
|
|
496
680
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
681
|
+
// Turns the thread still shows under client-minted ids ABOVE the boundary
|
|
682
|
+
// streamed live and fell out of the refetch window before any snapshot
|
|
683
|
+
// replaced them (the window boundary in `mergeHistoryWithRealtime`). The
|
|
684
|
+
// older page carries their persisted twins; prepending those would render
|
|
685
|
+
// each such turn twice, so they are left out — the persisted copy takes over
|
|
686
|
+
// at the next full merge, whose window then reaches them. Matched from the
|
|
687
|
+
// boundary backwards and one claim per live row, because the live rows are
|
|
688
|
+
// the NEWEST turns before it: a repeated prompt or a shared opener further up
|
|
689
|
+
// the page is a different turn and stays. The page is persisted in full, so
|
|
690
|
+
// an answer text twins only in the cut-short direction (the live copy is a
|
|
691
|
+
// prefix of the persisted one).
|
|
692
|
+
const liveAboveBoundary =
|
|
693
|
+
boundaryIndexInExisting > 0
|
|
694
|
+
? existingMessages.slice(0, boundaryIndexInExisting).filter(m => isClientMintedId(m.id))
|
|
695
|
+
: [];
|
|
696
|
+
const twinIndices = new Set<number>();
|
|
697
|
+
if (liveAboveBoundary.length > 0) {
|
|
698
|
+
const liveSignals = collectTwinSignals(liveAboveBoundary);
|
|
699
|
+
const userTwinsLeft = new Map(liveSignals.userContents);
|
|
700
|
+
const assistantTwinsLeft = new Map(liveSignals.assistantTexts);
|
|
701
|
+
for (let i = newEnd - 1; i >= 0; i--) {
|
|
702
|
+
const pm = processedHistory[i];
|
|
703
|
+
if (pm.role === 'user') {
|
|
704
|
+
const text = userText(pm);
|
|
705
|
+
const left = text === '' ? 0 : (userTwinsLeft.get(text) ?? 0);
|
|
706
|
+
if (left === 0) continue;
|
|
707
|
+
userTwinsLeft.set(text, left - 1);
|
|
708
|
+
twinIndices.add(i);
|
|
709
|
+
} else if (pm.role === 'assistant') {
|
|
710
|
+
const keys = turnRequestKeys(pm.content);
|
|
711
|
+
if (keys.size > 0) {
|
|
712
|
+
if (sharesRequestKey(keys, liveSignals.requestKeys)) twinIndices.add(i);
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
const text = assistantAnswerText(pm.content);
|
|
716
|
+
if (text === '') continue;
|
|
717
|
+
for (const [liveText, left] of assistantTwinsLeft) {
|
|
718
|
+
if (left === 0 || !text.startsWith(liveText)) continue;
|
|
719
|
+
assistantTwinsLeft.set(liveText, left - 1);
|
|
720
|
+
twinIndices.add(i);
|
|
721
|
+
break;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
501
724
|
}
|
|
502
|
-
newMessages.push(processedHistory[i]);
|
|
503
725
|
}
|
|
726
|
+
const newMessages = processedHistory.slice(0, newEnd).filter((_, i) => !twinIndices.has(i));
|
|
504
727
|
|
|
505
728
|
let boundaryMessageId: string | undefined;
|
|
506
729
|
let boundaryUpdates: { content: MessageContent } | undefined;
|
|
507
730
|
|
|
508
|
-
if (
|
|
731
|
+
if (boundaryIndexInExisting >= 0) {
|
|
509
732
|
const boundaryMessage = processedHistory[boundaryMessageIndex];
|
|
510
|
-
const existingBoundary = existingMessages
|
|
733
|
+
const existingBoundary = existingMessages[boundaryIndexInExisting];
|
|
734
|
+
const existingContent = JSON.stringify(existingBoundary.content);
|
|
735
|
+
const newContent = JSON.stringify(boundaryMessage.content);
|
|
511
736
|
|
|
512
|
-
if (
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
if (existingContent !== newContent) {
|
|
517
|
-
boundaryMessageId = boundaryMessage.id;
|
|
518
|
-
boundaryUpdates = { content: boundaryMessage.content };
|
|
519
|
-
}
|
|
737
|
+
if (existingContent !== newContent) {
|
|
738
|
+
boundaryMessageId = boundaryMessage.id;
|
|
739
|
+
boundaryUpdates = { content: boundaryMessage.content };
|
|
520
740
|
}
|
|
521
741
|
}
|
|
522
742
|
|
|
@@ -21,7 +21,14 @@ import { cn } from '../../../utils/cn';
|
|
|
21
21
|
import { formatTicketRelativeTime, formatTicketFullTimestamp } from '../../../utils/date-utils';
|
|
22
22
|
import { holdMoveDragEffect } from '../../../utils/drag-effect';
|
|
23
23
|
import { getReadableTextColor } from '../../../utils/ods-color-utils';
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
ClockIcon,
|
|
26
|
+
DotsLoaderIcon,
|
|
27
|
+
LaptopIcon,
|
|
28
|
+
Flag02Icon,
|
|
29
|
+
MessagesIcon,
|
|
30
|
+
UserCheckIcon,
|
|
31
|
+
} from '../../icons-v2-generated';
|
|
25
32
|
import { DeletedUserAvatar } from '../../ui/deleted-user-avatar';
|
|
26
33
|
import { SquareAvatar } from '../../ui/square-avatar';
|
|
27
34
|
import { Tag } from '../../ui/tag';
|
|
@@ -30,7 +37,7 @@ import { BoardTicketApproval } from './board-ticket-approval';
|
|
|
30
37
|
import { useBoardLift, useDropAim } from './drop-aim';
|
|
31
38
|
import { DROP_LINE_ATTRIBUTE } from './lane-geometry';
|
|
32
39
|
import { useIsLanding } from './pending-move';
|
|
33
|
-
import type { BoardPriority, BoardTicket } from './types';
|
|
40
|
+
import type { BoardPriority, BoardTicket, BoardTicketActivityKind } from './types';
|
|
34
41
|
import { TICKET_ID_ATTRIBUTE } from './use-lane-scroll-anchor';
|
|
35
42
|
|
|
36
43
|
const PRIORITY_COLOR_CLASS: Record<BoardPriority, string> = {
|
|
@@ -50,6 +57,13 @@ export const DRAG_PREVIEW_OPACITY = 0.9;
|
|
|
50
57
|
const MAX_VISIBLE_TAGS = 2;
|
|
51
58
|
const MAX_VISIBLE_ASSIGNEES = 3;
|
|
52
59
|
|
|
60
|
+
const ACTIVITY_DEFAULT_LABEL: Record<BoardTicketActivityKind, string> = {
|
|
61
|
+
'ai-working': 'AI assistant is working',
|
|
62
|
+
'user-typing': 'User typing',
|
|
63
|
+
'waiting-external': 'Waiting for client response',
|
|
64
|
+
stale: 'No activity',
|
|
65
|
+
};
|
|
66
|
+
|
|
53
67
|
/** Shared card shell (border / padding / bg). Same footprint for the draggable
|
|
54
68
|
* board card and the static {@link TicketCardView}. */
|
|
55
69
|
const TICKET_CARD_SHELL =
|
|
@@ -158,6 +172,21 @@ export function TicketCardBody({ ticket, columnColor, renderAssignSlot, onApprov
|
|
|
158
172
|
<span className="truncate">Escalated by User</span>
|
|
159
173
|
</div>
|
|
160
174
|
)}
|
|
175
|
+
{ticket.activity && (
|
|
176
|
+
<div
|
|
177
|
+
className={cn(
|
|
178
|
+
'flex items-center gap-[var(--spacing-system-xxs)] text-h6',
|
|
179
|
+
ticket.activity.kind === 'stale' ? 'text-ods-open-yellow' : 'text-ods-text-secondary',
|
|
180
|
+
)}
|
|
181
|
+
>
|
|
182
|
+
{ticket.activity.kind === 'stale' ? (
|
|
183
|
+
<ClockIcon className="size-4 shrink-0" />
|
|
184
|
+
) : (
|
|
185
|
+
<DotsLoaderIcon className="size-4 shrink-0" />
|
|
186
|
+
)}
|
|
187
|
+
<span className="truncate">{ticket.activity.label ?? ACTIVITY_DEFAULT_LABEL[ticket.activity.kind]}</span>
|
|
188
|
+
</div>
|
|
189
|
+
)}
|
|
161
190
|
{showNewMessage && (
|
|
162
191
|
<Tag
|
|
163
192
|
label="New Message"
|
|
@@ -22,6 +22,24 @@ export interface BoardTicketAssignee {
|
|
|
22
22
|
deleted?: boolean;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Live-activity footer indicator on a board card. Indicators are mutually
|
|
27
|
+
* exclusive by design — the consumer decides which single one a ticket shows
|
|
28
|
+
* (staleness has the lowest priority and must be suppressed when any other
|
|
29
|
+
* signal — new message, approval, escalation — is present).
|
|
30
|
+
*/
|
|
31
|
+
export type BoardTicketActivityKind = 'ai-working' | 'user-typing' | 'waiting-external' | 'stale';
|
|
32
|
+
|
|
33
|
+
export interface BoardTicketActivity {
|
|
34
|
+
kind: BoardTicketActivityKind;
|
|
35
|
+
/**
|
|
36
|
+
* Overrides the built-in label for the kind. Required in practice for
|
|
37
|
+
* 'stale', whose label carries the computed duration ("No activity for
|
|
38
|
+
* 2 hours") that only the consumer can know — and tick over time.
|
|
39
|
+
*/
|
|
40
|
+
label?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
25
43
|
export interface BoardTicket {
|
|
26
44
|
id: string;
|
|
27
45
|
title: string;
|
|
@@ -43,6 +61,8 @@ export interface BoardTicket {
|
|
|
43
61
|
* technician should pick it up.
|
|
44
62
|
*/
|
|
45
63
|
escalatedByUser?: boolean;
|
|
64
|
+
/** Single live-activity indicator rendered as the card's footer row. */
|
|
65
|
+
activity?: BoardTicketActivity;
|
|
46
66
|
}
|
|
47
67
|
|
|
48
68
|
export interface BoardColumnDef {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/nextjs-vite';
|
|
2
2
|
import type { PendingToolCallData } from '../components/chat/types';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
TicketCard,
|
|
5
|
+
type TicketCardProps,
|
|
6
|
+
type BoardTicket,
|
|
7
|
+
type BoardTicketActivityKind,
|
|
8
|
+
} from '../components/features/board';
|
|
4
9
|
|
|
5
10
|
// =============================================================================
|
|
6
11
|
// Harness — the card registers its own drag behaviour against the DOM and needs
|
|
@@ -149,6 +154,40 @@ export const EscalatedByUser: Story = {
|
|
|
149
154
|
},
|
|
150
155
|
};
|
|
151
156
|
|
|
157
|
+
/**
|
|
158
|
+
* The `activity` footer row, one card per kind. The three live kinds (animated
|
|
159
|
+
* dots loader + grey text) fall back to their built-in labels; `stale` (clock +
|
|
160
|
+
* amber text) carries a consumer-computed duration label, since only the
|
|
161
|
+
* consumer knows the ticket's idle time — and keeps it ticking.
|
|
162
|
+
*/
|
|
163
|
+
export const ActivityIndicators: Story = {
|
|
164
|
+
render: () => {
|
|
165
|
+
const activities: { kind: BoardTicketActivityKind; label?: string }[] = [
|
|
166
|
+
{ kind: 'ai-working' },
|
|
167
|
+
{ kind: 'user-typing' },
|
|
168
|
+
{ kind: 'waiting-external' },
|
|
169
|
+
{ kind: 'stale', label: 'No activity for 2 hours' },
|
|
170
|
+
];
|
|
171
|
+
return (
|
|
172
|
+
<div className="flex w-[320px] flex-col gap-[var(--spacing-system-sf)] rounded-lg bg-ods-card p-[var(--spacing-system-sf)]">
|
|
173
|
+
{activities.map(activity => (
|
|
174
|
+
<TicketCard
|
|
175
|
+
key={activity.kind}
|
|
176
|
+
columnId="ACTIVE"
|
|
177
|
+
ticket={{
|
|
178
|
+
...BASE_TICKET,
|
|
179
|
+
id: `ticket-activity-${activity.kind}`,
|
|
180
|
+
priority: undefined,
|
|
181
|
+
tags: undefined,
|
|
182
|
+
activity,
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
))}
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
152
191
|
/**
|
|
153
192
|
* Pending CLIENT approval — collapsed grey "Pending client approval" row with a
|
|
154
193
|
* loader glyph. Expand it to reach the shared approve/reject affordance.
|