mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-23 14:45:46 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user