@playcraft/cli 0.0.22 → 0.0.23
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/dist/commands/tools.js +20 -3
- package/package.json +3 -3
package/dist/commands/tools.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { writeFileSync, mkdirSync } from 'fs';
|
|
1
|
+
import { writeFileSync, mkdirSync, readFileSync } from 'fs';
|
|
2
2
|
import { dirname, join } from 'path';
|
|
3
3
|
import { tmpdir } from 'os';
|
|
4
4
|
import { AgentApiClient } from '../utils/agent-api-client.js';
|
|
@@ -26,18 +26,30 @@ export function registerToolsCommands(program) {
|
|
|
26
26
|
.description('后端 /api/agent/tools;需 PLAYCRAFT_API_URL + PLAYCRAFT_SANDBOX_TOKEN 或 .playcraft.json');
|
|
27
27
|
// ─── Generation ─────────────────────────────────────────────
|
|
28
28
|
tools.command('generate-image')
|
|
29
|
-
.description('AI
|
|
29
|
+
.description('AI 生成图片(支持参考图图生图)')
|
|
30
30
|
.requiredOption('--prompt <text>', '图片描述')
|
|
31
31
|
.option('--aspect-ratio <ratio>', '宽高比 (1:1|16:9|9:16|3:4|4:3)', '1:1')
|
|
32
32
|
.requiredOption('--output <path>', '保存路径')
|
|
33
33
|
.option('--image-size <size>', '图片尺寸 (1K|2K|4K)')
|
|
34
|
+
.option('--reference-image <path>', '参考图路径(图生图),支持 PNG/JPG/WEBP')
|
|
34
35
|
.action(async (opts) => {
|
|
35
36
|
try {
|
|
37
|
+
let referenceImageBase64;
|
|
38
|
+
let referenceImageMimeType;
|
|
39
|
+
if (opts.referenceImage) {
|
|
40
|
+
const imgBuf = readFileSync(opts.referenceImage);
|
|
41
|
+
referenceImageBase64 = imgBuf.toString('base64');
|
|
42
|
+
const ext = opts.referenceImage.split('.').pop()?.toLowerCase();
|
|
43
|
+
referenceImageMimeType =
|
|
44
|
+
ext === 'png' ? 'image/png' : ext === 'webp' ? 'image/webp' : 'image/jpeg';
|
|
45
|
+
}
|
|
36
46
|
const client = new AgentApiClient();
|
|
37
47
|
const result = await client.post('/generate-image', {
|
|
38
48
|
prompt: opts.prompt,
|
|
39
49
|
aspectRatio: opts.aspectRatio,
|
|
40
50
|
imageSize: opts.imageSize,
|
|
51
|
+
referenceImageBase64,
|
|
52
|
+
referenceImageMimeType,
|
|
41
53
|
});
|
|
42
54
|
mkdirSync(dirname(opts.output), { recursive: true });
|
|
43
55
|
const buf = Buffer.from(result.imageBase64, 'base64');
|
|
@@ -200,8 +212,13 @@ export function registerToolsCommands(program) {
|
|
|
200
212
|
.action(async (opts) => {
|
|
201
213
|
try {
|
|
202
214
|
const client = new AgentApiClient();
|
|
215
|
+
const projectId = Number(opts.projectId);
|
|
216
|
+
if (!Number.isInteger(projectId) || projectId <= 0) {
|
|
217
|
+
console.error(`Error: --project-id must be a positive integer, got: ${opts.projectId}`);
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
203
220
|
const result = await client.post('/create-remix', {
|
|
204
|
-
projectId
|
|
221
|
+
projectId,
|
|
205
222
|
sourceBranch: opts.sourceBranch,
|
|
206
223
|
name: opts.name,
|
|
207
224
|
description: opts.description,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playcraft/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
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.
|
|
26
|
-
"@playcraft/common": "^0.0.
|
|
25
|
+
"@playcraft/build": "^0.0.23",
|
|
26
|
+
"@playcraft/common": "^0.0.12",
|
|
27
27
|
"chokidar": "^4.0.3",
|
|
28
28
|
"commander": "^13.1.0",
|
|
29
29
|
"cors": "^2.8.6",
|