



















@@ -2,6 +2,7 @@ import type { ImageContent } from "@earendil-works/pi-ai";
22import type { OpenClawConfig } from "../../config/types.openclaw.js";
33import { logVerbose } from "../../globals.js";
44import { formatErrorMessage } from "../../infra/errors.js";
5+import { mimeTypeFromFilePath } from "../../media/mime.js";
56import type { PromptImageOrderEntry } from "../../media/prompt-image-order.js";
67import { normalizeOptionalString } from "../../shared/string-coerce.js";
78import type { MsgContext } from "../templating.js";
@@ -13,6 +14,30 @@ type CurrentImageAttachment = {
1314mediaType: string;
1415};
151617+function isGenericMediaType(mediaType: string | undefined): boolean {
18+if (!mediaType) {
19+return true;
20+}
21+const normalized = mediaType.split(";")[0]?.trim().toLowerCase();
22+return normalized === "application/octet-stream" || normalized === "binary/octet-stream";
23+}
24+25+function resolveCurrentImageMediaType(pathValue: unknown, mediaType?: unknown): string | undefined {
26+const mediaPath = normalizeOptionalString(pathValue);
27+if (!mediaPath) {
28+return undefined;
29+}
30+const normalizedMediaType = normalizeOptionalString(mediaType);
31+if (normalizedMediaType?.startsWith("image/")) {
32+return normalizedMediaType;
33+}
34+if (!isGenericMediaType(normalizedMediaType)) {
35+return undefined;
36+}
37+const inferredType = mimeTypeFromFilePath(mediaPath);
38+return inferredType?.startsWith("image/") ? inferredType : undefined;
39+}
40+1641function collectCurrentImageAttachments(ctx: MsgContext): CurrentImageAttachment[] {
1742const pathsFromArray = Array.isArray(ctx.MediaPaths) ? ctx.MediaPaths : undefined;
1843const paths =
@@ -31,8 +56,8 @@ function collectCurrentImageAttachments(ctx: MsgContext): CurrentImageAttachment
3156const attachments: CurrentImageAttachment[] = [];
3257for (const [index, pathValue] of paths.entries()) {
3358const mediaPath = normalizeOptionalString(pathValue);
34-const mediaType = normalizeOptionalString(types?.[index] ?? ctx.MediaType);
35-if (mediaPath && mediaType?.startsWith("image/")) {
59+const mediaType = resolveCurrentImageMediaType(pathValue, types?.[index] ?? ctx.MediaType);
60+if (mediaPath && mediaType) {
3661attachments.push({ index, path: mediaPath, mediaType });
3762}
3863}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。