@blockrun/clawrouter 0.12.33 → 0.12.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/dist/cli.js +28 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6399,7 +6399,34 @@ async function startProxy(options) {
|
|
|
6399
6399
|
for await (const chunk of req) {
|
|
6400
6400
|
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
6401
6401
|
}
|
|
6402
|
-
const
|
|
6402
|
+
const rawBody = Buffer.concat(chunks);
|
|
6403
|
+
let reqBody;
|
|
6404
|
+
try {
|
|
6405
|
+
const parsed = JSON.parse(rawBody.toString());
|
|
6406
|
+
for (const field of ["image", "mask"]) {
|
|
6407
|
+
const val = parsed[field];
|
|
6408
|
+
if (typeof val !== "string" || !val) continue;
|
|
6409
|
+
if (val.startsWith("data:")) {
|
|
6410
|
+
} else if (val.startsWith("https://") || val.startsWith("http://")) {
|
|
6411
|
+
const imgResp = await fetch(val);
|
|
6412
|
+
if (!imgResp.ok) throw new Error(`Failed to download ${field} from ${val}: HTTP ${imgResp.status}`);
|
|
6413
|
+
const contentType = imgResp.headers.get("content-type") ?? "image/png";
|
|
6414
|
+
const buf = Buffer.from(await imgResp.arrayBuffer());
|
|
6415
|
+
parsed[field] = `data:${contentType};base64,${buf.toString("base64")}`;
|
|
6416
|
+
console.log(`[ClawRouter] img2img: downloaded ${field} URL \u2192 data URI (${buf.length} bytes)`);
|
|
6417
|
+
} else {
|
|
6418
|
+
parsed[field] = readImageFileAsDataUri(val);
|
|
6419
|
+
console.log(`[ClawRouter] img2img: read ${field} file \u2192 data URI`);
|
|
6420
|
+
}
|
|
6421
|
+
}
|
|
6422
|
+
if (!parsed.model) parsed.model = "openai/gpt-image-1";
|
|
6423
|
+
reqBody = JSON.stringify(parsed);
|
|
6424
|
+
} catch (parseErr) {
|
|
6425
|
+
const msg = parseErr instanceof Error ? parseErr.message : String(parseErr);
|
|
6426
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
6427
|
+
res.end(JSON.stringify({ error: "Invalid request", details: msg }));
|
|
6428
|
+
return;
|
|
6429
|
+
}
|
|
6403
6430
|
try {
|
|
6404
6431
|
const upstream = await payFetch(`${apiBase}/v1/images/image2image`, {
|
|
6405
6432
|
method: "POST",
|