refactor(gateway): share rpc attachment normalization

This commit is contained in:
Peter Steinberger
2026-02-15 13:30:37 +00:00
parent abf36ddd5f
commit 9f9978635c
4 changed files with 55 additions and 36 deletions

View File

@@ -48,6 +48,7 @@ import {
import { formatForLog } from "../ws-log.js";
import { waitForAgentJob } from "./agent-job.js";
import { injectTimestamp, timestampOptsFromConfig } from "./agent-timestamp.js";
import { normalizeRpcAttachmentsToChatAttachments } from "./attachment-normalize.js";
import { sessionsHandlers } from "./sessions.js";
const RESET_COMMAND_RE = /^\/(new|reset)(?:\s+([\s\S]*))?$/i;
@@ -213,24 +214,7 @@ export const agentHandlers: GatewayRequestHandlers = {
});
return;
}
const normalizedAttachments =
request.attachments
?.map((a) => ({
type: typeof a?.type === "string" ? a.type : undefined,
mimeType: typeof a?.mimeType === "string" ? a.mimeType : undefined,
fileName: typeof a?.fileName === "string" ? a.fileName : undefined,
content:
typeof a?.content === "string"
? a.content
: ArrayBuffer.isView(a?.content)
? Buffer.from(
a.content.buffer,
a.content.byteOffset,
a.content.byteLength,
).toString("base64")
: undefined,
}))
.filter((a) => a.content) ?? [];
const normalizedAttachments = normalizeRpcAttachmentsToChatAttachments(request.attachments);
let message = request.message.trim();
let images: Array<{ type: "image"; data: string; mimeType: string }> = [];