fix(gateway): sanitize bounded SSE refresh + deduplicate constant

- Bounded/cursor SSE refresh path now sanitizes through
  sanitizeChatHistoryMessages before paginating, matching the
  unbounded path and initial history load.
- Export DEFAULT_CHAT_HISTORY_TEXT_MAX_CHARS from chat.ts and
  import in sessions-history-http.ts instead of duplicating.
This commit is contained in:
Eva
2026-04-06 03:40:42 +07:00
committed by Peter Steinberger
parent 7634bdeb2c
commit b099427570
3 changed files with 7 additions and 5 deletions

View File

@@ -289,7 +289,6 @@ export function handleMessageUpdate(
assistantRecord?.partial && typeof assistantRecord.partial === "object"
? (assistantRecord.partial as AssistantMessage)
: msg;
const phaseAwareVisibleText = coerceText(extractAssistantVisibleText(partialAssistant)).trim();
const deliveryPhase = resolveAssistantMessagePhase(partialAssistant);
if (deliveryPhase === "commentary") {
return;

View File

@@ -102,7 +102,7 @@ type ChatAbortRequester = {
isAdmin: boolean;
};
const DEFAULT_CHAT_HISTORY_TEXT_MAX_CHARS = 12_000;
export const DEFAULT_CHAT_HISTORY_TEXT_MAX_CHARS = 12_000;
const CHAT_HISTORY_MAX_SINGLE_MESSAGE_BYTES = 128 * 1024;
const CHAT_HISTORY_OVERSIZED_PLACEHOLDER = "[chat.history omitted: message too large]";
let chatHistoryPlaceholderEmitCount = 0;

View File

@@ -25,10 +25,10 @@ import {
resolveGatewaySessionStoreTarget,
resolveSessionTranscriptCandidates,
} from "./session-utils.js";
import { sanitizeChatHistoryMessages } from "./server-methods/chat.js";
import { DEFAULT_CHAT_HISTORY_TEXT_MAX_CHARS, sanitizeChatHistoryMessages } from "./server-methods/chat.js";
const MAX_SESSION_HISTORY_LIMIT = 1000;
const DEFAULT_CHAT_HISTORY_TEXT_MAX_CHARS = 12_000;
function resolveSessionHistoryPath(req: IncomingMessage): string | null {
const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
const match = url.pathname.match(/^\/sessions\/([^/]+)\/history$/);
@@ -295,7 +295,10 @@ export async function handleSessionHistoryHttpRequest(
}
}
sentHistory = paginateSessionMessages(
readSessionMessages(entry.sessionId, target.storePath, entry.sessionFile),
sanitizeChatHistoryMessages(
readSessionMessages(entry.sessionId, target.storePath, entry.sessionFile),
effectiveMaxChars,
),
limit,
cursor,
);