

























@@ -353,6 +353,68 @@ describe("modelSupportsImages", () => {
353353});
354354355355describe("loadImageFromRef", () => {
356+it("hydrates managed inbound media URIs before workspace path resolution", async () => {
357+const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-native-image-uri-"));
358+const workspaceDir = path.join(stateDir, "workspace-agent");
359+const inboundDir = path.join(stateDir, "media", "inbound");
360+const mediaId = "telegram-photo.png";
361+await fs.mkdir(workspaceDir, { recursive: true });
362+await fs.mkdir(inboundDir, { recursive: true });
363+await fs.writeFile(path.join(inboundDir, mediaId), Buffer.from(TINY_PNG_BASE64, "base64"));
364+vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
365+366+try {
367+const image = await loadImageFromRef(
368+{
369+raw: `media://inbound/${mediaId}`,
370+type: "media-uri",
371+resolved: `media://inbound/${mediaId}`,
372+},
373+workspaceDir,
374+{ workspaceOnly: true },
375+);
376+377+expect(image?.type).toBe("image");
378+expect(image?.mimeType).toBe("image/png");
379+expect(image?.data).toBe(TINY_PNG_BASE64);
380+} finally {
381+vi.unstubAllEnvs();
382+await fs.rm(stateDir, { recursive: true, force: true });
383+}
384+});
385+386+it("hydrates sandbox-staged inbound media URIs", async () => {
387+const sandboxRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-native-image-sbx-uri-"));
388+const inboundDir = path.join(sandboxRoot, "media", "inbound");
389+const mediaId = "telegram-photo.png";
390+await fs.mkdir(inboundDir, { recursive: true });
391+await fs.writeFile(path.join(inboundDir, mediaId), Buffer.from(TINY_PNG_BASE64, "base64"));
392+393+try {
394+const image = await loadImageFromRef(
395+{
396+raw: `media://inbound/${mediaId}`,
397+type: "media-uri",
398+resolved: `media://inbound/${mediaId}`,
399+},
400+sandboxRoot,
401+{
402+workspaceOnly: true,
403+sandbox: {
404+root: sandboxRoot,
405+bridge: createHostSandboxFsBridge(sandboxRoot),
406+},
407+},
408+);
409+410+expect(image?.type).toBe("image");
411+expect(image?.mimeType).toBe("image/png");
412+expect(image?.data).toBe(TINY_PNG_BASE64);
413+} finally {
414+await fs.rm(sandboxRoot, { recursive: true, force: true });
415+}
416+});
417+356418it("allows sandbox-validated host paths outside default media roots", async () => {
357419const homeDir = os.homedir();
358420await fs.mkdir(homeDir, { recursive: true });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。