feat(agent): implement local image handling and enhance generated image integration in canvas

This commit is contained in:
HouYunFei
2026-07-29 17:19:20 +08:00
parent 7a48f441cf
commit 2afe2f3898
6 changed files with 71 additions and 5 deletions
+2 -1
View File
@@ -61,7 +61,8 @@ function initializeWorkspace(workspacePath: string) {
if (initializedWorkspaces.has(workspacePath)) return;
fs.mkdirSync(workspacePath, { recursive: true });
const instructionsFile = path.join(workspacePath, "AGENTS.md");
if (!fs.existsSync(instructionsFile)) fs.writeFileSync(instructionsFile, AGENT_PROMPT);
const current = fs.existsSync(instructionsFile) ? fs.readFileSync(instructionsFile, "utf8") : "";
if (!current || current.startsWith("# Infinite Canvas Agent")) fs.writeFileSync(instructionsFile, AGENT_PROMPT);
initializedWorkspaces.add(workspacePath);
}
+9 -1
View File
@@ -1,5 +1,5 @@
import { spawn } from "node:child_process";
import { stat } from "node:fs/promises";
import { readFile, stat } from "node:fs/promises";
import path from "node:path";
import express, { type NextFunction, type Request, type Response } from "express";
@@ -82,6 +82,14 @@ export function startHttpServer() {
await revealLocalFile(filePath, file.isDirectory());
res.json({ ok: true });
}));
app.post("/agent/local-image", route(async (req, res) => {
const filePath = String(req.body?.path || "");
if (!path.isAbsolute(filePath) || !/\.(?:avif|gif|jpe?g|png|webp)$/i.test(filePath)) return res.status(400).json({ ok: false, error: "图片路径无效" });
const file = await stat(filePath);
if (!file.isFile()) return res.status(400).json({ ok: false, error: "图片文件无效" });
res.setHeader("Cache-Control", "no-store");
res.type(path.extname(filePath)).send(await readFile(filePath));
}));
app.post("/api/tools", route(async (req, res) => res.json({ ok: true, result: await session.callTool(req.body?.name, req.body?.input || {}) })));
app.get("/agent/codex/workspace", (_req, res) => {
const workspace = ensureSiteWorkspace(config);