




















@@ -3,7 +3,6 @@ import type { ImageContent } from "@mariozechner/pi-ai";
33import { formatErrorMessage } from "../../../infra/errors.js";
44import { assertNoWindowsNetworkPath, safeFileURLToPath } from "../../../infra/local-file-access.js";
55import type { PromptImageOrderEntry } from "../../../media/prompt-image-order.js";
6-import { resolveMediaBufferPath, getMediaDir } from "../../../media/store.js";
76import { loadWebMedia } from "../../../media/web-media.js";
87import { normalizeLowercaseStringOrEmpty } from "../../../shared/string-coerce.js";
98import { resolveUserPath } from "../../../utils.js";
@@ -12,7 +11,6 @@ import {
1211createSandboxBridgeReadFile,
1312resolveSandboxedBridgeMediaPath,
1413} from "../../sandbox-media-paths.js";
15-import { assertSandboxPath } from "../../sandbox-paths.js";
1614import type { SandboxFsBridge } from "../../sandbox/fs-bridge.js";
1715import { sanitizeImageBlocks } from "../../tool-images.js";
1816import { log } from "../logger.js";
@@ -353,44 +351,6 @@ export async function loadImageFromRef(
353351sandbox?: { root: string; bridge: SandboxFsBridge };
354352},
355353): Promise<ImageContent | null> {
356-// Handle Gateway claim-check URIs (media://inbound/<id>).
357-// These are written by the Gateway's offload path and point to files that
358-// the Gateway has already validated and persisted. They are intentionally
359-// exempt from workspaceOnly checks because they live in the media store
360-// managed by the Gateway, not in the agent workspace.
361-if (ref.type === "media-uri") {
362-const uriMatch = ref.resolved.match(MEDIA_URI_REGEX);
363-if (!uriMatch) {
364-log.debug(`Native image: malformed media URI, skipping: ${ref.resolved}`);
365-return null;
366-}
367-const mediaId = uriMatch[1];
368-try {
369-// resolveMediaBufferPath accepts the media ID (with optional extension
370-// and original-filename prefix) and returns the absolute path of the
371-// persisted file. It applies its own guards against path traversal,
372-// symlinks, and null bytes.
373-const physicalPath = await resolveMediaBufferPath(mediaId, "inbound");
374-const media = await loadWebMedia(physicalPath, {
375-maxBytes: options?.maxBytes,
376-localRoots: [getMediaDir()],
377-});
378-if (media.kind !== "image") {
379-log.debug(`Native image: media store entry is not an image: ${mediaId}`);
380-return null;
381-}
382-const mimeType = media.contentType ?? "image/jpeg";
383-const data = media.buffer.toString("base64");
384-log.debug(`Native image: loaded media-uri ${ref.resolved} -> ${physicalPath}`);
385-return { type: "image", data, mimeType };
386-} catch (err) {
387-log.debug(
388-`Native image: failed to load media-uri ${ref.resolved}: ${formatErrorMessage(err)}`,
389-);
390-return null;
391-}
392-}
393-394354try {
395355let targetPath = ref.resolved;
396356@@ -415,14 +375,6 @@ export async function loadImageFromRef(
415375} else if (!path.isAbsolute(targetPath)) {
416376targetPath = path.resolve(workspaceDir, targetPath);
417377}
418-if (options?.workspaceOnly && !options?.sandbox) {
419-const root = options?.sandbox?.root ?? workspaceDir;
420-await assertSandboxPath({
421-filePath: targetPath,
422-cwd: root,
423- root,
424-});
425-}
426378427379// loadWebMedia handles local file paths (including file:// URLs)
428380const media = options?.sandbox
@@ -431,7 +383,12 @@ export async function loadImageFromRef(
431383sandboxValidated: true,
432384readFile: createSandboxBridgeReadFile({ sandbox: options.sandbox }),
433385})
434- : await loadWebMedia(targetPath, options?.maxBytes);
386+ : await loadWebMedia(
387+targetPath,
388+options?.workspaceOnly
389+ ? { maxBytes: options.maxBytes, localRoots: [workspaceDir] }
390+ : options?.maxBytes,
391+);
435392436393if (media.kind !== "image") {
437394log.debug(`Native image: not an image file: ${targetPath} (got ${media.kind})`);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。