guanghulab/video-ai-system/engines/image-api-bridge.js
冰朔 8b5db50e70 D144 · 主角资产包图片适配器桥接完成 · Python↔Node打通
- 新建 image-api-bridge.js: Node CLI桥接,stdin JSON in → stdout JSON out,日志重定向stderr
- 新建 image_api_adapter.py: Python端桥接封装,subprocess调用Node
- char-hero-design-packer.py 成功 import generate_image,不再因JS-only适配器崩溃
- 实测生成苏白正面半身参考图到JZAO成功 (2048x2048, Seedream 4.0)

铸渊 ICE-GL-ZY001 · D144 · 2026-06-24
冰朔 TCS-0002∞ · 国作登字-2026-A-00037559
⊢ CHAR-HERO-DESIGN-PACKER: NOT_READY → 图片适配器已接通
2026-06-24 13:53:14 +08:00

65 lines
2.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* image-api-bridge.js · Python ↔ Node 图片API桥接
* D144 · 铸渊 ICE-GL-ZY001
*
* Python 通过 subprocess 调用本脚本stdin 输入 JSON 命令stdout 输出 JSON 结果。
* 解决 char-hero-design-packer.py 依赖 JS image-api-adapter 的问题。
*
* 用法:
* echo '{"action":"generate_character_ref","charId":"CHAR-003","l0":"...","l1":"..."}' | node image-api-bridge.js
* echo '{"action":"generate_image","prompt":"...","size":"2048x2048","filename":"test.png"}' | node image-api-bridge.js
*/
// 桥接模式:所有日志输出到 stderrstdout 只输出最终 JSON 结果
console.log = (...args) => process.stderr.write(args.join(' ') + '\n');
console.warn = (...args) => process.stderr.write(args.join(' ') + '\n');
console.error = (...args) => process.stderr.write(args.join(' ') + '\n');
const { generateImage, generateCharacterRef } = require('./image-api-adapter');
let input = '';
process.stdin.setEncoding('utf8');
process.stdin.on('data', chunk => input += chunk);
process.stdin.on('end', async () => {
try {
const req = JSON.parse(input || '{}');
let result;
switch (req.action) {
case 'generate_character_ref': {
const { charId, l0, l1 } = req;
if (!charId) throw new Error('缺少 charId');
result = await generateCharacterRef({
charId,
l0Descriptor: l0 || '中国古代修仙少年16岁亚洲面孔',
l1Config: l1 ? { clothing: l1 } : undefined,
});
break;
}
case 'generate_image': {
const { prompt, size, filename, outputPath } = req;
if (!prompt) throw new Error('缺少 prompt');
result = await generateImage({ prompt, size, filename, outputPath });
break;
}
default:
throw new Error(`未知操作: ${req.action}`);
}
process.stdout.write(JSON.stringify({ ok: true, data: result }) + '\n');
process.exit(0);
} catch (err) {
process.stdout.write(JSON.stringify({ ok: false, error: err.message }) + '\n');
process.exit(1);
}
});
// stdin 已关闭pipe 模式),直接触发 end
if (process.stdin.isTTY) {
process.stderr.write('用法: echo \'{"action":"..."}\' | node image-api-bridge.js\n');
process.exit(1);
}