fix: restore required imports and fix SSE sequence tracking

This commit is contained in:
Eva
2026-04-06 02:26:46 +07:00
committed by Peter Steinberger
parent 6f95fd448f
commit 7634bdeb2c
2 changed files with 8 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
import { extractTextFromChatContent } from "../../shared/chat-content.js";
import { sanitizeUserFacingText } from "../pi-embedded-helpers.js";
import {
stripDowngradedToolCallText,

View File

@@ -25,8 +25,10 @@ import {
resolveGatewaySessionStoreTarget,
resolveSessionTranscriptCandidates,
} from "./session-utils.js";
import { 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$/);
@@ -273,16 +275,16 @@ export async function handleSessionHistoryHttpRequest(
: readSessionMessages(entry.sessionId, target.storePath, entry.sessionFile).length,
});
if (limit === undefined && cursor === undefined) {
sentHistory = {
items: [...sentHistory.items, nextMessage],
messages: [...sentHistory.items, nextMessage],
hasMore: false,
};
const sanitized = sanitizeChatHistoryMessages([nextMessage], effectiveMaxChars);
if (sanitized.length === 0) {
return;
}
const sanitizedMessage = sanitized[0];
sentHistory = {
items: [...sentHistory.items, sanitizedMessage],
messages: [...sentHistory.items, sanitizedMessage],
hasMore: false,
};
sseWrite(res, "message", {
sessionKey: target.canonicalKey,
message: sanitizedMessage,