fix(chat): translate session replay cursors
Memind CI / Test, build, and release guards (pull_request) Successful in 2m55s
Memind CI / Test, build, and release guards (pull_request) Successful in 2m55s
This commit is contained in:
+11
-4
@@ -44,6 +44,7 @@ import {
|
||||
isSessionStreamReplayEnabled,
|
||||
parseSessionSseBlock,
|
||||
parseSessionStreamLastEventId,
|
||||
resolveUpstreamResumeEventId,
|
||||
shouldPersistSessionStreamEvent,
|
||||
shouldSkipUpstreamAfterSessionReplay,
|
||||
} from './session-stream.mjs';
|
||||
@@ -2154,6 +2155,7 @@ export function createTkmindProxy({
|
||||
let clientClosed = false;
|
||||
const replayEnabled = isSessionStreamReplayEnabled() && sessionStreamStore;
|
||||
const initialLastEventId = parseSessionStreamLastEventId(req.get('last-event-id'));
|
||||
let upstreamLastEventId = replayEnabled ? null : initialLastEventId;
|
||||
const abortUpstream = () => {
|
||||
clientClosed = true;
|
||||
upstreamAbort.abort();
|
||||
@@ -2210,17 +2212,22 @@ export function createTkmindProxy({
|
||||
if (!res.writableEnded) res.end();
|
||||
return;
|
||||
}
|
||||
upstreamLastEventId = resolveUpstreamResumeEventId(
|
||||
batch?.events ?? [],
|
||||
batch?.cursorEvent ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
const pathname = `/sessions/${sessionId}/events`;
|
||||
const sessionTarget = await resolveTarget(sessionId);
|
||||
const upstreamHeaders = { Accept: 'text/event-stream' };
|
||||
if (upstreamLastEventId) {
|
||||
upstreamHeaders['Last-Event-ID'] = upstreamLastEventId;
|
||||
}
|
||||
const upstream = await apiFetch(sessionTarget, apiSecret, pathname, {
|
||||
method: 'GET',
|
||||
signal: upstreamAbort.signal,
|
||||
headers: {
|
||||
Accept: 'text/event-stream',
|
||||
'Last-Event-ID': req.get('last-event-id') ?? '',
|
||||
},
|
||||
headers: upstreamHeaders,
|
||||
});
|
||||
if (clientClosed) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user