fix: stabilize media paths and logs

This commit is contained in:
Peter Steinberger
2026-01-08 04:40:50 +00:00
parent 9c9d191d6f
commit 5b45a143a1
3 changed files with 11 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ const normalizeText = (value?: string) =>
(value ?? "") (value ?? "")
.replace(/\r\n/g, "\n") .replace(/\r\n/g, "\n")
.replace(/\r/g, "\n") .replace(/\r/g, "\n")
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, "")
.split("\n") .split("\n")
.map((line) => line.replace(/\s+$/u, "")) .map((line) => line.replace(/\s+$/u, ""))
.join("\n") .join("\n")

View File

@@ -18,9 +18,13 @@ function formatMediaAttachedLine(params: {
} }
export function buildInboundMediaNote(ctx: MsgContext): string | undefined { export function buildInboundMediaNote(ctx: MsgContext): string | undefined {
const hasPathsArray = Array.isArray(ctx.MediaPaths) && ctx.MediaPaths.length > 0; const hasPathsArray =
const paths = hasPathsArray Array.isArray(ctx.MediaPaths) && ctx.MediaPaths.length > 0;
const pathsFromArray = Array.isArray(ctx.MediaPaths)
? ctx.MediaPaths ? ctx.MediaPaths
: undefined;
const paths = pathsFromArray && pathsFromArray.length > 0
? pathsFromArray
: ctx.MediaPath?.trim() : ctx.MediaPath?.trim()
? [ctx.MediaPath.trim()] ? [ctx.MediaPath.trim()]
: []; : [];
@@ -58,4 +62,3 @@ export function buildInboundMediaNote(ctx: MsgContext): string | undefined {
} }
return lines.join("\n"); return lines.join("\n");
} }

View File

@@ -857,8 +857,11 @@ async function stageSandboxMedia(params: {
}) { }) {
const { ctx, sessionCtx, cfg, sessionKey, workspaceDir } = params; const { ctx, sessionCtx, cfg, sessionKey, workspaceDir } = params;
const hasPathsArray = Array.isArray(ctx.MediaPaths) && ctx.MediaPaths.length > 0; const hasPathsArray = Array.isArray(ctx.MediaPaths) && ctx.MediaPaths.length > 0;
const rawPaths = hasPathsArray const pathsFromArray = Array.isArray(ctx.MediaPaths)
? ctx.MediaPaths ? ctx.MediaPaths
: undefined;
const rawPaths = pathsFromArray && pathsFromArray.length > 0
? pathsFromArray
: ctx.MediaPath?.trim() : ctx.MediaPath?.trim()
? [ctx.MediaPath.trim()] ? [ctx.MediaPath.trim()]
: []; : [];