@flamingo-stack/openframe-frontend-core 0.0.522 → 0.0.523-1663.4375.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/{chunk-RWTD4NQ2.cjs → chunk-43QX3P4G.cjs} +3 -3
- package/dist/{chunk-RWTD4NQ2.cjs.map → chunk-43QX3P4G.cjs.map} +1 -1
- package/dist/{chunk-JL3X7DPB.js → chunk-7EYNWY2N.js} +2 -2
- package/dist/{chunk-UUFE74C7.js → chunk-7LSK5YFW.js} +2 -2
- package/dist/{chunk-FRFXBRST.cjs → chunk-7RIYOJLG.cjs} +26 -26
- package/dist/{chunk-FRFXBRST.cjs.map → chunk-7RIYOJLG.cjs.map} +1 -1
- package/dist/{chunk-MZ2MPY3B.js → chunk-7ZIGB34Y.js} +6 -6
- package/dist/{chunk-IBHUZFIZ.js → chunk-ANKQQTAI.js} +4 -4
- package/dist/{chunk-ZVVEXK44.js → chunk-BPBMHS4U.js} +2 -2
- package/dist/{chunk-FVXRZ474.cjs → chunk-D3PPR2WR.cjs} +14 -14
- package/dist/{chunk-FVXRZ474.cjs.map → chunk-D3PPR2WR.cjs.map} +1 -1
- package/dist/{chunk-GZIJUOER.js → chunk-FP6HEAQC.js} +5 -5
- package/dist/{chunk-XCI5F273.cjs → chunk-H5TAFA4H.cjs} +4 -4
- package/dist/{chunk-XCI5F273.cjs.map → chunk-H5TAFA4H.cjs.map} +1 -1
- package/dist/{chunk-QUPS6IAR.cjs → chunk-HPGBHELQ.cjs} +7 -7
- package/dist/{chunk-QUPS6IAR.cjs.map → chunk-HPGBHELQ.cjs.map} +1 -1
- package/dist/{chunk-VXSGV2VP.js → chunk-ICWQQQTR.js} +2 -2
- package/dist/{chunk-K4ORVGWE.cjs → chunk-J2OPY22M.cjs} +87 -87
- package/dist/{chunk-K4ORVGWE.cjs.map → chunk-J2OPY22M.cjs.map} +1 -1
- package/dist/{chunk-AEDRJEID.cjs → chunk-JGYVXVN6.cjs} +61 -61
- package/dist/{chunk-AEDRJEID.cjs.map → chunk-JGYVXVN6.cjs.map} +1 -1
- package/dist/{chunk-S7BB62B4.cjs → chunk-JKUYXCG2.cjs} +9 -9
- package/dist/{chunk-S7BB62B4.cjs.map → chunk-JKUYXCG2.cjs.map} +1 -1
- package/dist/{chunk-SAAKOLLH.cjs → chunk-KBE7SNFZ.cjs} +5 -5
- package/dist/{chunk-SAAKOLLH.cjs.map → chunk-KBE7SNFZ.cjs.map} +1 -1
- package/dist/{chunk-IO3PCG3Z.js → chunk-L4DKYRHG.js} +2 -2
- package/dist/{chunk-ZVPLTDNE.cjs → chunk-LJCBSJFU.cjs} +26 -26
- package/dist/{chunk-ZVPLTDNE.cjs.map → chunk-LJCBSJFU.cjs.map} +1 -1
- package/dist/{chunk-3T3YTENO.js → chunk-M45XIHZY.js} +2 -2
- package/dist/{chunk-Q74DY577.js → chunk-NBANPQ3N.js} +2 -2
- package/dist/{chunk-SS3AJW6C.js → chunk-NMZ33YWL.js} +4 -4
- package/dist/{chunk-66XVK6ZG.cjs → chunk-OGXZCZSA.cjs} +31 -31
- package/dist/{chunk-66XVK6ZG.cjs.map → chunk-OGXZCZSA.cjs.map} +1 -1
- package/dist/{chunk-GZZG7MTN.js → chunk-OPU5BLBT.js} +2 -2
- package/dist/{chunk-WZR4RNJN.cjs → chunk-PZVYYDFL.cjs} +37 -37
- package/dist/{chunk-WZR4RNJN.cjs.map → chunk-PZVYYDFL.cjs.map} +1 -1
- package/dist/{chunk-HTQBSPHP.js → chunk-QBLLF7VS.js} +2 -2
- package/dist/{chunk-PZGS25UT.cjs → chunk-VYRP7JOD.cjs} +30 -5
- package/dist/chunk-VYRP7JOD.cjs.map +1 -0
- package/dist/{chunk-WEEOC4DQ.js → chunk-YJLQQGLH.js} +134 -109
- package/dist/{chunk-WEEOC4DQ.js.map → chunk-YJLQQGLH.js.map} +1 -1
- package/dist/{chunk-FL4IQO6P.cjs → chunk-ZIIIYUZ5.cjs} +11 -11
- package/dist/{chunk-FL4IQO6P.cjs.map → chunk-ZIIIYUZ5.cjs.map} +1 -1
- package/dist/components/case-studies/index.cjs +8 -8
- package/dist/components/case-studies/index.js +2 -2
- package/dist/components/chat/hooks/use-jetstream-dialog-subscription.d.ts +7 -1
- package/dist/components/chat/hooks/use-jetstream-dialog-subscription.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +4 -2
- package/dist/components/chat/index.cjs.map +1 -1
- package/dist/components/chat/index.js +3 -1
- package/dist/components/chat/types/api.types.d.ts +22 -4
- package/dist/components/chat/types/api.types.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +3 -3
- package/dist/components/contact/index.js +2 -2
- package/dist/components/docs/index.cjs +5 -5
- package/dist/components/docs/index.js +4 -4
- package/dist/components/embeds/index.cjs +3 -3
- package/dist/components/embeds/index.js +2 -2
- package/dist/components/faq/index.cjs +3 -3
- package/dist/components/faq/index.js +2 -2
- package/dist/components/features/index.cjs +2 -2
- package/dist/components/features/index.js +1 -1
- package/dist/components/help-center-pages/index.cjs +22 -22
- package/dist/components/help-center-pages/index.js +13 -13
- package/dist/components/index.cjs +134 -132
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +13 -11
- package/dist/components/index.js.map +1 -1
- package/dist/components/meeting-scheduler/index.cjs +34 -34
- package/dist/components/meeting-scheduler/index.js +3 -3
- package/dist/components/navigation/index.cjs +2 -2
- package/dist/components/navigation/index.js +1 -1
- package/dist/components/onboarding-guides/index.cjs +5 -5
- package/dist/components/onboarding-guides/index.js +4 -4
- package/dist/components/related-content/index.cjs +3 -3
- package/dist/components/related-content/index.js +2 -2
- package/dist/components/tickets/index.cjs +6 -6
- package/dist/components/tickets/index.js +5 -5
- package/dist/components/ui/index.cjs +4 -2
- package/dist/components/ui/index.cjs.map +1 -1
- package/dist/components/ui/index.js +3 -1
- package/dist/index.cjs +4 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/src/components/chat/hooks/.use-jetstream-dialog-subscription.md +11 -4
- package/src/components/chat/hooks/use-jetstream-dialog-subscription.ts +71 -6
- package/src/components/chat/types/api.types.ts +22 -4
- package/src/components/chat/utils/__tests__/history-merge.test.ts +99 -0
- package/dist/chunk-PZGS25UT.cjs.map +0 -1
- /package/dist/{chunk-JL3X7DPB.js.map → chunk-7EYNWY2N.js.map} +0 -0
- /package/dist/{chunk-UUFE74C7.js.map → chunk-7LSK5YFW.js.map} +0 -0
- /package/dist/{chunk-MZ2MPY3B.js.map → chunk-7ZIGB34Y.js.map} +0 -0
- /package/dist/{chunk-IBHUZFIZ.js.map → chunk-ANKQQTAI.js.map} +0 -0
- /package/dist/{chunk-ZVVEXK44.js.map → chunk-BPBMHS4U.js.map} +0 -0
- /package/dist/{chunk-GZIJUOER.js.map → chunk-FP6HEAQC.js.map} +0 -0
- /package/dist/{chunk-VXSGV2VP.js.map → chunk-ICWQQQTR.js.map} +0 -0
- /package/dist/{chunk-IO3PCG3Z.js.map → chunk-L4DKYRHG.js.map} +0 -0
- /package/dist/{chunk-3T3YTENO.js.map → chunk-M45XIHZY.js.map} +0 -0
- /package/dist/{chunk-Q74DY577.js.map → chunk-NBANPQ3N.js.map} +0 -0
- /package/dist/{chunk-SS3AJW6C.js.map → chunk-NMZ33YWL.js.map} +0 -0
- /package/dist/{chunk-GZZG7MTN.js.map → chunk-OPU5BLBT.js.map} +0 -0
- /package/dist/{chunk-HTQBSPHP.js.map → chunk-QBLLF7VS.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useEffect, useRef, useState } from 'react'
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
4
4
|
import {
|
|
5
5
|
acquireClient as acquireSharedClient,
|
|
6
6
|
releaseClient as releaseSharedClient,
|
|
@@ -20,7 +20,24 @@ const DEFAULT_STREAM_NAME = 'CHAT_CHUNKS'
|
|
|
20
20
|
* absence worth resyncing for. Alt-tabbing must not churn the consumer; a
|
|
21
21
|
* window that sat in the tray must not come back showing a stale conversation.
|
|
22
22
|
*/
|
|
23
|
-
const RESYNC_AFTER_HIDDEN_MS = 10_000
|
|
23
|
+
export const RESYNC_AFTER_HIDDEN_MS = 10_000
|
|
24
|
+
/**
|
|
25
|
+
* How long resync requests are gathered before one is acted on.
|
|
26
|
+
*
|
|
27
|
+
* A single reveal can be reported twice: the page sees `visibilitychange`, and
|
|
28
|
+
* a host that knows the window was away reports it too (`resyncSignal`),
|
|
29
|
+
* neither able to tell whether the other noticed. Both land within a frame or
|
|
30
|
+
* two of each other, being driven by the same OS event, and acting on both
|
|
31
|
+
* rebuilds the consumer and refetches history twice for one reveal.
|
|
32
|
+
*
|
|
33
|
+
* Gathered on the TRAILING edge, so a request is deferred and never dropped.
|
|
34
|
+
* Two reports of one reveal collapse into one rebuild; two genuinely different
|
|
35
|
+
* signals — a notification reply landing just before the user opens the window
|
|
36
|
+
* — also collapse into one, which is correct, because a single refetch after
|
|
37
|
+
* the last of them covers both. The cost is a second of latency on a path whose
|
|
38
|
+
* next step is a network round trip.
|
|
39
|
+
*/
|
|
40
|
+
const RESYNC_COALESCE_MS = 1_000
|
|
24
41
|
/**
|
|
25
42
|
* Floor between two reported recoveries. Every recovery costs the caller a
|
|
26
43
|
* history refetch, and a consumer that cannot hold its sequence — gap, reset,
|
|
@@ -60,6 +77,7 @@ export function useJetStreamDialogSubscription({
|
|
|
60
77
|
clientConfig = {},
|
|
61
78
|
reconnectionBackoff,
|
|
62
79
|
inactiveThresholdMs,
|
|
80
|
+
resyncSignal = 0,
|
|
63
81
|
}: UseJetStreamDialogSubscriptionOptions): UseJetStreamDialogSubscriptionReturn {
|
|
64
82
|
const [isConnected, setIsConnected] = useState(false)
|
|
65
83
|
const [isSubscribed, setIsSubscribed] = useState(false)
|
|
@@ -73,6 +91,8 @@ export function useJetStreamDialogSubscription({
|
|
|
73
91
|
const [currentStreamSeq, setCurrentStreamSeq] = useState<number | null>(null)
|
|
74
92
|
|
|
75
93
|
const lastRecoveryReportRef = useRef(0)
|
|
94
|
+
const resyncTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
95
|
+
const lastResyncSignalRef = useRef(resyncSignal)
|
|
76
96
|
const clientRef = useRef<NatsClient | null>(null)
|
|
77
97
|
const subscriptionRef = useRef<JetStreamSubscriptionHandle | null>(null)
|
|
78
98
|
const highestStreamSeqRef = useRef<number | null>(null)
|
|
@@ -245,7 +265,26 @@ export function useJetStreamDialogSubscription({
|
|
|
245
265
|
// ignoring optStartSeq).
|
|
246
266
|
useEffect(() => {
|
|
247
267
|
highestStreamSeqRef.current = null
|
|
268
|
+
// A host's signal counts per dialog (it can carry a per-conversation term),
|
|
269
|
+
// so the baseline has to move with the dialog or a switch to one with a
|
|
270
|
+
// LOWER count would swallow every later resync for it.
|
|
271
|
+
lastResyncSignalRef.current = resyncSignal
|
|
248
272
|
setCurrentStreamSeq(null)
|
|
273
|
+
// A resync gathered for the previous dialog must not land on this one: the
|
|
274
|
+
// counter says nothing about which conversation it meant, so callers would
|
|
275
|
+
// refetch the wrong one. The dialog change supersedes it — the new dialog
|
|
276
|
+
// loads its own history regardless. As cleanup, so it covers unmount too,
|
|
277
|
+
// which is the same rule.
|
|
278
|
+
return () => {
|
|
279
|
+
if (resyncTimerRef.current !== null) {
|
|
280
|
+
clearTimeout(resyncTimerRef.current)
|
|
281
|
+
resyncTimerRef.current = null
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
// `resyncSignal` is read as the new baseline, not depended on: reacting to
|
|
285
|
+
// it here would reset the baseline on the very change meant to trigger a
|
|
286
|
+
// resync, and the effect below owns that.
|
|
287
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
249
288
|
}, [dialogId])
|
|
250
289
|
|
|
251
290
|
// Coming back into view after a real absence is treated exactly like a
|
|
@@ -256,8 +295,20 @@ export function useJetStreamDialogSubscription({
|
|
|
256
295
|
// report that: the tail simply stays quiet, and the conversation on screen
|
|
257
296
|
// stays frozen at whatever was there when the window went away (the user's
|
|
258
297
|
// manual fix is a page refresh, which is exactly the history refetch this
|
|
259
|
-
// triggers).
|
|
260
|
-
//
|
|
298
|
+
// triggers). Rebuilds the consumer from the last sequence seen AND tells
|
|
299
|
+
// callers to refetch history.
|
|
300
|
+
//
|
|
301
|
+
// Every source funnels through here (see `RESYNC_COALESCE_MS`). Restarting
|
|
302
|
+
// the timer rather than dropping is what makes that safe: a request is only
|
|
303
|
+
// ever folded into the one that follows it, never discarded.
|
|
304
|
+
const requestResync = useCallback(() => {
|
|
305
|
+
if (resyncTimerRef.current !== null) clearTimeout(resyncTimerRef.current)
|
|
306
|
+
resyncTimerRef.current = setTimeout(() => {
|
|
307
|
+
resyncTimerRef.current = null
|
|
308
|
+
setReconnectionCount((c) => c + 1)
|
|
309
|
+
}, RESYNC_COALESCE_MS)
|
|
310
|
+
}, [])
|
|
311
|
+
|
|
261
312
|
useEffect(() => {
|
|
262
313
|
if (!enabled) return
|
|
263
314
|
let hiddenSince = document.visibilityState === 'hidden' ? Date.now() : 0
|
|
@@ -270,13 +321,27 @@ export function useJetStreamDialogSubscription({
|
|
|
270
321
|
const awayMs = hiddenSince === 0 ? 0 : Date.now() - hiddenSince
|
|
271
322
|
hiddenSince = 0
|
|
272
323
|
if (awayMs >= RESYNC_AFTER_HIDDEN_MS) {
|
|
273
|
-
|
|
324
|
+
requestResync()
|
|
274
325
|
}
|
|
275
326
|
}
|
|
276
327
|
|
|
277
328
|
document.addEventListener('visibilitychange', onVisibilityChange)
|
|
278
329
|
return () => document.removeEventListener('visibilitychange', onVisibilityChange)
|
|
279
|
-
}, [enabled])
|
|
330
|
+
}, [enabled, requestResync])
|
|
331
|
+
|
|
332
|
+
useEffect(() => {
|
|
333
|
+
// Held, not consumed, while disabled: it fires once on enable instead.
|
|
334
|
+
// A host reports a signal against the conversation, not against this hook's
|
|
335
|
+
// readiness, so one arriving while the caller is still assembling the
|
|
336
|
+
// subscription describes a gap in the history the caller is fetching right
|
|
337
|
+
// now. Dropping it would leave that fetch's result stale with nothing left
|
|
338
|
+
// to say so.
|
|
339
|
+
if (!enabled) return
|
|
340
|
+
// The mount value is a baseline, not a signal.
|
|
341
|
+
if (resyncSignal <= lastResyncSignalRef.current) return
|
|
342
|
+
lastResyncSignalRef.current = resyncSignal
|
|
343
|
+
requestResync()
|
|
344
|
+
}, [enabled, resyncSignal, requestResync])
|
|
280
345
|
|
|
281
346
|
// Subscription lifecycle: (re)create the ephemeral JetStream consumer whenever
|
|
282
347
|
// we transition into a connected state for a dialog, and whenever the dialog
|
|
@@ -131,6 +131,22 @@ export interface UseJetStreamDialogSubscriptionOptions {
|
|
|
131
131
|
/** Consumer inactivity threshold in ms before NATS auto-cleans it. Defaults to the
|
|
132
132
|
* client's, and applies only to the first consumer — recreations use nats.ws's. */
|
|
133
133
|
inactiveThresholdMs?: number
|
|
134
|
+
/**
|
|
135
|
+
* A counter the host bumps when it knows, from outside the page, that the tail
|
|
136
|
+
* may have missed something.
|
|
137
|
+
*
|
|
138
|
+
* The hook's own detector is `visibilitychange`, which a browser tab reports
|
|
139
|
+
* honestly and an embedding shell may not — and which says nothing at all
|
|
140
|
+
* about a write made on the page's behalf while it was away. A host holding
|
|
141
|
+
* either kind of knowledge bumps this instead of hoping the page noticed.
|
|
142
|
+
*
|
|
143
|
+
* Treated exactly like a reconnect: the consumer is rebuilt from the highest
|
|
144
|
+
* sequence already seen, and `reconnectionCount` moves so callers refetch
|
|
145
|
+
* persisted history. Any increase counts; the value itself means nothing, and
|
|
146
|
+
* an increase arriving alongside a `visibilitychange` costs one rebuild, not
|
|
147
|
+
* two.
|
|
148
|
+
*/
|
|
149
|
+
resyncSignal?: number
|
|
134
150
|
}
|
|
135
151
|
|
|
136
152
|
export interface UseJetStreamDialogSubscriptionReturn {
|
|
@@ -138,10 +154,12 @@ export interface UseJetStreamDialogSubscriptionReturn {
|
|
|
138
154
|
isSubscribed: boolean
|
|
139
155
|
/**
|
|
140
156
|
* Incremented each time the live tail is re-established: a NATS reconnect, a
|
|
141
|
-
* JetStream ordered-consumer recreation,
|
|
142
|
-
* being hidden long enough to have missed something
|
|
143
|
-
*
|
|
144
|
-
* history has to be
|
|
157
|
+
* JetStream ordered-consumer recreation, the page returning to view after
|
|
158
|
+
* being hidden long enough to have missed something, or a host reporting the
|
|
159
|
+
* same via `resyncSignal`. All of them mean the same thing to the caller —
|
|
160
|
+
* the tail may have skipped messages, so persisted history has to be
|
|
161
|
+
* refetched. One absence counts once even when two sources report it.
|
|
162
|
+
* Starts at 0.
|
|
145
163
|
*/
|
|
146
164
|
reconnectionCount: number
|
|
147
165
|
/** Highest JetStream stream sequence observed so far (null before first delivery). */
|
|
@@ -930,3 +930,102 @@ describe('mid-stream refetch (turn partially persisted)', () => {
|
|
|
930
930
|
expect(ids(merged)).toEqual([U0.id, A0.id, PERSISTED_PARTIAL.id, unrelatedLive.id])
|
|
931
931
|
})
|
|
932
932
|
})
|
|
933
|
+
|
|
934
|
+
describe('ordering of surviving realtime messages', () => {
|
|
935
|
+
// The merge concatenates: all persisted history, then every realtime message
|
|
936
|
+
// the coverage rules kept, each side in its own order. These pin that
|
|
937
|
+
// contract, which nothing asserted before — the suite tested only WHICH
|
|
938
|
+
// messages survive, never where they land — and which an attempt to
|
|
939
|
+
// chronologically interleave the two sides repeatedly broke.
|
|
940
|
+
const H_U0: TestMessage = { ...U0, streamSeq: 5 }
|
|
941
|
+
const H_A0: TestMessage = { ...A0, streamSeq: 10 }
|
|
942
|
+
/**
|
|
943
|
+
* Sent from a notification while the window was away, and persisted. NO
|
|
944
|
+
* `streamSeq`: the backend does not stamp user MESSAGE_REQUEST rows, which is
|
|
945
|
+
* the missing signal that makes interleaving guesswork.
|
|
946
|
+
*/
|
|
947
|
+
const AWAY_U: TestMessage = {
|
|
948
|
+
id: 'bbbb0001',
|
|
949
|
+
role: 'user',
|
|
950
|
+
content: 'replied from a notification',
|
|
951
|
+
timestamp: t(3000),
|
|
952
|
+
}
|
|
953
|
+
/** Mingo's answer to it. Assistant rows DO carry a sequence. */
|
|
954
|
+
const AWAY_A: TestMessage = {
|
|
955
|
+
id: 'bbbb0002',
|
|
956
|
+
role: 'assistant',
|
|
957
|
+
content: txt('answered while the window was away'),
|
|
958
|
+
timestamp: t(3100),
|
|
959
|
+
streamSeq: 80,
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
it('appends surviving realtime messages after all persisted history', () => {
|
|
963
|
+
// A technician direct message the snapshot has not caught up with. Its own
|
|
964
|
+
// role's persisted max (H_U0, seq 5) is below it, so coverage keeps it.
|
|
965
|
+
const unpersistedDirect: TestMessage = {
|
|
966
|
+
id: 'direct-1500-old',
|
|
967
|
+
role: 'user',
|
|
968
|
+
content: 'a direct message history has not persisted yet',
|
|
969
|
+
timestamp: t(1500),
|
|
970
|
+
streamSeq: 40,
|
|
971
|
+
}
|
|
972
|
+
const merged = mergeHistoryWithRealtime({
|
|
973
|
+
processedHistory: [H_U0, H_A0, AWAY_U, AWAY_A],
|
|
974
|
+
existingMessages: [H_U0, H_A0, unpersistedDirect],
|
|
975
|
+
streamingMessageId: null,
|
|
976
|
+
historyFetchedAt: 9000,
|
|
977
|
+
historyMaxStreamSeq: 80,
|
|
978
|
+
realtimeSeenStreamSeq: 40,
|
|
979
|
+
})
|
|
980
|
+
|
|
981
|
+
expect(ids(merged)).toEqual([H_U0.id, H_A0.id, AWAY_U.id, AWAY_A.id, unpersistedDirect.id])
|
|
982
|
+
})
|
|
983
|
+
|
|
984
|
+
it('keeps survivors in store order, sequence or no sequence', () => {
|
|
985
|
+
// The guard against reordering the two kinds against each other: an
|
|
986
|
+
// optimistic bubble carries no sequence and a replayed direct message does,
|
|
987
|
+
// and sorting by sequence would render the user's question below the reply
|
|
988
|
+
// that came after it.
|
|
989
|
+
const optimistic: TestMessage = {
|
|
990
|
+
id: 'optimistic-9400-x',
|
|
991
|
+
role: 'user',
|
|
992
|
+
content: 'just typed, no seq of its own',
|
|
993
|
+
timestamp: t(9400),
|
|
994
|
+
}
|
|
995
|
+
const laterDirect: TestMessage = {
|
|
996
|
+
id: 'direct-9500-x',
|
|
997
|
+
role: 'user',
|
|
998
|
+
content: 'and a direct message after it',
|
|
999
|
+
timestamp: t(9500),
|
|
1000
|
+
streamSeq: 40,
|
|
1001
|
+
}
|
|
1002
|
+
const merged = mergeHistoryWithRealtime({
|
|
1003
|
+
processedHistory: [H_U0, H_A0, AWAY_U, AWAY_A],
|
|
1004
|
+
existingMessages: [H_U0, H_A0, optimistic, laterDirect],
|
|
1005
|
+
streamingMessageId: null,
|
|
1006
|
+
// Before either was minted, so neither can be in the snapshot.
|
|
1007
|
+
historyFetchedAt: 9000,
|
|
1008
|
+
historyMaxStreamSeq: 80,
|
|
1009
|
+
realtimeSeenStreamSeq: 40,
|
|
1010
|
+
})
|
|
1011
|
+
|
|
1012
|
+
expect(ids(merged)).toEqual([H_U0.id, H_A0.id, AWAY_U.id, AWAY_A.id, optimistic.id, laterDirect.id])
|
|
1013
|
+
})
|
|
1014
|
+
|
|
1015
|
+
it('keeps history in snapshot order even when its sequences do not climb', () => {
|
|
1016
|
+
// The snapshot is the server's account of the conversation; the merge is
|
|
1017
|
+
// not entitled to second-guess it from a `streamSeq` that looks out of
|
|
1018
|
+
// order, which is what any sort of the two sides together would do.
|
|
1019
|
+
const outOfOrder: TestMessage = { ...H_A0, id: 'aaaa0009', streamSeq: 3 }
|
|
1020
|
+
const merged = mergeHistoryWithRealtime({
|
|
1021
|
+
processedHistory: [H_U0, outOfOrder, AWAY_U, AWAY_A],
|
|
1022
|
+
existingMessages: [H_U0],
|
|
1023
|
+
streamingMessageId: null,
|
|
1024
|
+
historyFetchedAt: 9000,
|
|
1025
|
+
historyMaxStreamSeq: 80,
|
|
1026
|
+
realtimeSeenStreamSeq: 0,
|
|
1027
|
+
})
|
|
1028
|
+
|
|
1029
|
+
expect(ids(merged)).toEqual([H_U0.id, outOfOrder.id, AWAY_U.id, AWAY_A.id])
|
|
1030
|
+
})
|
|
1031
|
+
})
|