@playcraft/cli 0.0.25 → 0.0.26

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.
@@ -91,36 +91,44 @@ function resolveImageOutputPath(outputPath, wantExt) {
91
91
  }
92
92
  return join(dir, `${name}${wantExt}`);
93
93
  }
94
+ function collectReferenceImagePaths(value, previous) {
95
+ return previous.concat([value]);
96
+ }
97
+ function mimeTypeForImagePath(filePath) {
98
+ const ext = filePath.split('.').pop()?.toLowerCase();
99
+ if (ext === 'png')
100
+ return 'image/png';
101
+ if (ext === 'webp')
102
+ return 'image/webp';
103
+ return 'image/jpeg';
104
+ }
94
105
  export function registerToolsCommands(program) {
95
106
  const tools = program
96
107
  .command('tools')
97
108
  .description('后端 /api/agent/tools;需 PLAYCRAFT_API_URL + PLAYCRAFT_SANDBOX_TOKEN 或 .playcraft.json');
98
109
  // ─── Generation ─────────────────────────────────────────────
99
110
  tools.command('generate-image')
100
- .description('AI 生成图片(支持参考图图生图)')
111
+ .description('AI 生成图片(支持多张参考图图生图)')
101
112
  .requiredOption('--prompt <text>', '图片描述')
102
113
  .option('--aspect-ratio <ratio>', '宽高比 (1:1|16:9|9:16|3:4|4:3)', '1:1')
103
114
  .requiredOption('--output <path>', '保存路径')
104
115
  .option('--image-size <size>', '图片尺寸 (1K|2K|4K)')
105
- .option('--reference-image <path>', '参考图路径(图生图),支持 PNG/JPG/WEBP')
116
+ .option('--reference-image <path>', '参考图路径(可重复多次,最多 8 张),支持 PNG/JPG/WEBP', collectReferenceImagePaths, [])
106
117
  .action(async (opts) => {
107
118
  try {
108
- let referenceImageBase64;
109
- let referenceImageMimeType;
110
- if (opts.referenceImage) {
111
- const imgBuf = readFileSync(opts.referenceImage);
112
- referenceImageBase64 = imgBuf.toString('base64');
113
- const ext = opts.referenceImage.split('.').pop()?.toLowerCase();
114
- referenceImageMimeType =
115
- ext === 'png' ? 'image/png' : ext === 'webp' ? 'image/webp' : 'image/jpeg';
116
- }
119
+ const paths = opts.referenceImage ?? [];
120
+ const referenceImages = paths.length > 0
121
+ ? paths.map((p) => ({
122
+ base64: readFileSync(p).toString('base64'),
123
+ mimeType: mimeTypeForImagePath(p),
124
+ }))
125
+ : undefined;
117
126
  const client = new AgentApiClient();
118
127
  const result = await client.post('/generate-image', {
119
128
  prompt: opts.prompt,
120
129
  aspectRatio: opts.aspectRatio,
121
130
  imageSize: opts.imageSize,
122
- referenceImageBase64,
123
- referenceImageMimeType,
131
+ referenceImages,
124
132
  });
125
133
  const buf = Buffer.from(result.imageBase64, 'base64');
126
134
  const sniffed = sniffImageExtension(buf);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/cli",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,8 +22,8 @@
22
22
  "release": "node scripts/release.js"
23
23
  },
24
24
  "dependencies": {
25
- "@playcraft/build": "^0.0.25",
26
- "@playcraft/common": "^0.0.14",
25
+ "@playcraft/build": "^0.0.26",
26
+ "@playcraft/common": "^0.0.15",
27
27
  "chokidar": "^4.0.3",
28
28
  "commander": "^13.1.0",
29
29
  "cors": "^2.8.6",