@lingjingai/lj-awb-cli 0.3.14 → 0.4.0
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 +36 -28
- package/build/_shared.mjs +130 -0
- package/build/build.mjs +3 -0
- package/build/pre-publish.mjs +57 -0
- package/build/pre.mjs +15 -51
- package/build/prod.mjs +25 -68
- package/install.mjs +1 -0
- package/package.json +10 -3
- package/packages/awb-cli/README.md +0 -3
- package/packages/awb-cli/package.json +2 -2
- package/packages/awb-core/package.json +7 -2
- package/packages/awb-core/src/api.js +33 -64
- package/packages/awb-core/src/artifact.js +936 -0
- package/packages/awb-core/src/auth.js +1 -1
- package/packages/awb-core/src/commands.js +668 -97
- package/packages/awb-core/src/common.js +3 -2
- package/packages/awb-core/src/output.js +2380 -106
- package/packages/awb-core/src/services.js +868 -114
- package/packages/awb-core/src/standalone.js +985 -235
- package/skills/lj-awb/SKILL.md +84 -73
- package/skills/lj-awb/VERSION +1 -1
- package/skills/lj-awb/compat.json +3 -3
- package/skills/lj-awb/modules/account.md +20 -7
- package/skills/lj-awb/modules/artifact/asset.md +64 -0
- package/skills/lj-awb/modules/artifact/clip.md +65 -0
- package/skills/lj-awb/modules/artifact/script.md +37 -0
- package/skills/lj-awb/modules/artifact/video.md +65 -0
- package/skills/lj-awb/modules/artifact.md +65 -0
- package/skills/lj-awb/modules/asset.md +50 -11
- package/skills/lj-awb/modules/auth.md +12 -5
- package/skills/lj-awb/modules/create-contract.md +23 -14
- package/skills/lj-awb/modules/create.md +37 -0
- package/skills/lj-awb/modules/credits.md +6 -0
- package/skills/lj-awb/modules/driver.md +125 -0
- package/skills/lj-awb/modules/evals.md +84 -36
- package/skills/lj-awb/modules/image.md +19 -10
- package/skills/lj-awb/modules/model.md +31 -31
- package/skills/lj-awb/modules/project.md +7 -0
- package/skills/lj-awb/modules/subject.md +28 -7
- package/skills/lj-awb/modules/task-manual.md +40 -28
- package/skills/lj-awb/modules/task.md +70 -8
- package/skills/lj-awb/modules/upload.md +18 -2
- package/skills/lj-awb/modules/video.md +30 -26
- package/skills/lj-awb/modules/workflows.md +274 -145
- package/skills/lj-awb/references/error-codes.md +109 -0
- package/skills/lj-awb/references/model-options-read.md +19 -12
- package/skills/lj-awb/references/output-fields.md +118 -0
|
@@ -3,7 +3,15 @@ import path from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { LingjingAwbCliError, createEnvelope, toBool, toInt } from './common.js';
|
|
5
5
|
import { registerAwbCommands } from './commands.js';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
formatCsvOutput,
|
|
8
|
+
formatPrettyError,
|
|
9
|
+
formatPrettyOutput,
|
|
10
|
+
formatTextError,
|
|
11
|
+
formatTextOutput,
|
|
12
|
+
formatYamlEnvelope,
|
|
13
|
+
normalizeJsonData,
|
|
14
|
+
} from './output.js';
|
|
7
15
|
|
|
8
16
|
function normalizeKey(value) {
|
|
9
17
|
return String(value || '').replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
@@ -13,6 +21,81 @@ function formatOptionName(value) {
|
|
|
13
21
|
return `--${String(value || '').replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`)}`;
|
|
14
22
|
}
|
|
15
23
|
|
|
24
|
+
const OPTION_SYNONYMS = {
|
|
25
|
+
timeout: ['waitSeconds'],
|
|
26
|
+
deadline: ['waitSeconds'],
|
|
27
|
+
maxWait: ['waitSeconds'],
|
|
28
|
+
wait: ['waitSeconds'],
|
|
29
|
+
parallel: ['concurrency'],
|
|
30
|
+
workers: ['concurrency'],
|
|
31
|
+
jobs: ['concurrency'],
|
|
32
|
+
threads: ['concurrency'],
|
|
33
|
+
output: ['format'],
|
|
34
|
+
json: ['format'],
|
|
35
|
+
keyword: ['model'],
|
|
36
|
+
input: ['inputFile'],
|
|
37
|
+
in: ['inputFile'],
|
|
38
|
+
dry: ['dryRun'],
|
|
39
|
+
force: ['yes'],
|
|
40
|
+
remoteTaskId: ['taskId'],
|
|
41
|
+
publicId: ['taskId'],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function levenshtein(a, b) {
|
|
45
|
+
if (a === b) return 0;
|
|
46
|
+
const m = a.length;
|
|
47
|
+
const n = b.length;
|
|
48
|
+
if (!m) return n;
|
|
49
|
+
if (!n) return m;
|
|
50
|
+
let prev = Array.from({ length: n + 1 }, (_, j) => j);
|
|
51
|
+
let curr = new Array(n + 1);
|
|
52
|
+
for (let i = 1; i <= m; i++) {
|
|
53
|
+
curr[0] = i;
|
|
54
|
+
for (let j = 1; j <= n; j++) {
|
|
55
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
56
|
+
curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost);
|
|
57
|
+
}
|
|
58
|
+
[prev, curr] = [curr, prev];
|
|
59
|
+
}
|
|
60
|
+
return prev[n];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function suggestSimilarOptions(unknownKey, allowedKeys) {
|
|
64
|
+
const scored = new Map();
|
|
65
|
+
const record = (key, score) => {
|
|
66
|
+
if (!scored.has(key) || scored.get(key) > score) scored.set(key, score);
|
|
67
|
+
};
|
|
68
|
+
const synonyms = OPTION_SYNONYMS[unknownKey] || [];
|
|
69
|
+
for (const syn of synonyms) {
|
|
70
|
+
if (allowedKeys.includes(syn)) record(syn, -1);
|
|
71
|
+
}
|
|
72
|
+
if (unknownKey.length === 1) {
|
|
73
|
+
const ch = unknownKey.toLowerCase();
|
|
74
|
+
for (const allowed of allowedKeys) {
|
|
75
|
+
if (allowed.toLowerCase().startsWith(ch)) record(allowed, 1);
|
|
76
|
+
}
|
|
77
|
+
return [...scored.entries()]
|
|
78
|
+
.sort((x, y) => x[1] - y[1])
|
|
79
|
+
.slice(0, 3)
|
|
80
|
+
.map(([key]) => formatOptionName(key));
|
|
81
|
+
}
|
|
82
|
+
for (const allowed of allowedKeys) {
|
|
83
|
+
const a = unknownKey.toLowerCase();
|
|
84
|
+
const b = allowed.toLowerCase();
|
|
85
|
+
if (b.includes(a) || a.includes(b)) {
|
|
86
|
+
record(allowed, 0);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const d = levenshtein(a, b);
|
|
90
|
+
const threshold = Math.max(2, Math.ceil(Math.min(a.length, b.length) / 3));
|
|
91
|
+
if (d <= threshold) record(allowed, d);
|
|
92
|
+
}
|
|
93
|
+
return [...scored.entries()]
|
|
94
|
+
.sort((x, y) => x[1] - y[1])
|
|
95
|
+
.slice(0, 3)
|
|
96
|
+
.map(([key]) => formatOptionName(key));
|
|
97
|
+
}
|
|
98
|
+
|
|
16
99
|
function commandPrefix() {
|
|
17
100
|
return process.env.LINGJING_AWB_COMMAND_PREFIX || 'lj-awb';
|
|
18
101
|
}
|
|
@@ -21,6 +104,57 @@ function renderCliText(value) {
|
|
|
21
104
|
return String(value ?? '').replace(/\blj-awb\b/g, commandPrefix());
|
|
22
105
|
}
|
|
23
106
|
|
|
107
|
+
function shouldColorOutput() {
|
|
108
|
+
if (String(process.env.LINGJING_AWB_COLOR || '').toLowerCase() === '0') return false;
|
|
109
|
+
if (String(process.env.LINGJING_AWB_COLOR || '').toLowerCase() === 'false') return false;
|
|
110
|
+
if (String(process.env.FORCE_COLOR || '').trim() && process.env.FORCE_COLOR !== '0') return true;
|
|
111
|
+
if (String(process.env.LINGJING_AWB_COLOR || '').toLowerCase() === '1') return true;
|
|
112
|
+
if (String(process.env.LINGJING_AWB_COLOR || '').toLowerCase() === 'true') return true;
|
|
113
|
+
if (process.env.NO_COLOR) return false;
|
|
114
|
+
return Boolean(process.stdout.isTTY);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function colorText(value, code) {
|
|
118
|
+
const text = String(value ?? '');
|
|
119
|
+
return shouldColorOutput() && text ? `\u001b[${code}m${text}\u001b[0m` : text;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const HELP_COLOR = {
|
|
123
|
+
title: '1;38;5;39',
|
|
124
|
+
accent: '1;38;5;208',
|
|
125
|
+
heading: '1;38;5;75',
|
|
126
|
+
command: '38;5;82',
|
|
127
|
+
group: '38;5;215',
|
|
128
|
+
muted: '2;38;5;245',
|
|
129
|
+
option: '38;5;111',
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
function helpTitle(value) {
|
|
133
|
+
if (!shouldColorOutput()) return String(value ?? '');
|
|
134
|
+
return `${colorText('◆', HELP_COLOR.accent)} ${colorText(value, HELP_COLOR.title)}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function helpHeading(value) {
|
|
138
|
+
if (!shouldColorOutput()) return String(value ?? '');
|
|
139
|
+
return `${colorText('▸', HELP_COLOR.accent)} ${colorText(value, HELP_COLOR.heading)}`;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function helpCommand(value) {
|
|
143
|
+
return colorText(value, HELP_COLOR.command);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function helpGroup(value) {
|
|
147
|
+
return colorText(value, HELP_COLOR.group);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function helpMuted(value) {
|
|
151
|
+
return colorText(value, HELP_COLOR.muted);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function helpOption(value) {
|
|
155
|
+
return colorText(value, HELP_COLOR.option);
|
|
156
|
+
}
|
|
157
|
+
|
|
24
158
|
function shellArg(value) {
|
|
25
159
|
const text = String(value ?? '');
|
|
26
160
|
return /^[A-Za-z0-9_./:=@,+-]+$/.test(text) ? text : JSON.stringify(text);
|
|
@@ -54,7 +188,7 @@ function commandInvocation(commandName, kwargs = {}, options = {}) {
|
|
|
54
188
|
|
|
55
189
|
function buildOutputContext(command, kwargs = {}) {
|
|
56
190
|
const optionKeys = new Set((command.args || []).map((arg) => normalizeKey(arg.name)));
|
|
57
|
-
const canSuggestDryRunExecution = command.name !== 'auth login
|
|
191
|
+
const canSuggestDryRunExecution = command.name !== 'auth login';
|
|
58
192
|
const withoutDryRun = { omit: ['dryRun'] };
|
|
59
193
|
const isModelList = command.name === 'model image-models' || command.name === 'model video-models';
|
|
60
194
|
const modelListAll = isModelList && toBool(kwargs.all);
|
|
@@ -66,6 +200,8 @@ function buildOutputContext(command, kwargs = {}) {
|
|
|
66
200
|
: null;
|
|
67
201
|
return {
|
|
68
202
|
jsonCommand: `${commandInvocation(command.name, kwargs)} -f json`,
|
|
203
|
+
textCommand: `${commandInvocation(command.name, kwargs)} -f text`,
|
|
204
|
+
outputKind: buildCommandWorkflow(command).outputKind,
|
|
69
205
|
executeCommand: canSuggestDryRunExecution && toBool(kwargs.dryRun) ? commandInvocation(command.name, kwargs, withoutDryRun) : null,
|
|
70
206
|
confirmCommand: canSuggestDryRunExecution && toBool(kwargs.dryRun) && optionKeys.has('yes')
|
|
71
207
|
? commandInvocation(command.name, kwargs, { omit: ['dryRun'], set: { yes: true } })
|
|
@@ -74,6 +210,28 @@ function buildOutputContext(command, kwargs = {}) {
|
|
|
74
210
|
};
|
|
75
211
|
}
|
|
76
212
|
|
|
213
|
+
const OUTPUT_FORMAT_ALIASES = {
|
|
214
|
+
agent: 'text',
|
|
215
|
+
table: 'pretty',
|
|
216
|
+
human: 'pretty',
|
|
217
|
+
compact: 'text',
|
|
218
|
+
'compact-text': 'text',
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const SUPPORTED_OUTPUT_FORMATS = new Set(['auto', 'pretty', 'text', 'json', 'yaml', 'csv']);
|
|
222
|
+
|
|
223
|
+
function resolveOutputFormat(format) {
|
|
224
|
+
const raw = String(format || 'pretty').trim().toLowerCase();
|
|
225
|
+
const normalized = OUTPUT_FORMAT_ALIASES[raw] || raw;
|
|
226
|
+
if (normalized === 'auto') return process.stdout.isTTY ? 'pretty' : 'text';
|
|
227
|
+
if (SUPPORTED_OUTPUT_FORMATS.has(normalized)) return normalized;
|
|
228
|
+
throw new LingjingAwbCliError(`未知输出格式:${format}`, {
|
|
229
|
+
type: 'argument_error',
|
|
230
|
+
exitCode: 2,
|
|
231
|
+
hint: '可用格式:pretty、text、json、yaml、csv、auto。Agent 建议使用 -f text;严格脚本解析再用 -f json。',
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
77
235
|
function assignKwarg(kwargs, key, value) {
|
|
78
236
|
if (kwargs[key] === undefined) {
|
|
79
237
|
kwargs[key] = value;
|
|
@@ -89,7 +247,8 @@ function assignKwarg(kwargs, key, value) {
|
|
|
89
247
|
function parseArgv(argv) {
|
|
90
248
|
const commandParts = [];
|
|
91
249
|
const kwargs = {};
|
|
92
|
-
|
|
250
|
+
const kwargRawFlags = {};
|
|
251
|
+
let format = 'pretty';
|
|
93
252
|
|
|
94
253
|
for (let index = 0; index < argv.length; index += 1) {
|
|
95
254
|
const token = argv[index];
|
|
@@ -118,10 +277,27 @@ function parseArgv(argv) {
|
|
|
118
277
|
}
|
|
119
278
|
continue;
|
|
120
279
|
}
|
|
280
|
+
if (token.length > 1 && token.startsWith('-') && /^-[A-Za-z]/.test(token)) {
|
|
281
|
+
const raw = token.slice(1);
|
|
282
|
+
const eqIndex = raw.indexOf('=');
|
|
283
|
+
const keyPart = eqIndex >= 0 ? raw.slice(0, eqIndex) : raw;
|
|
284
|
+
const inlineValue = eqIndex >= 0 ? raw.slice(eqIndex + 1) : undefined;
|
|
285
|
+
const key = normalizeKey(keyPart);
|
|
286
|
+
if (!(key in kwargRawFlags)) kwargRawFlags[key] = token;
|
|
287
|
+
if (inlineValue !== undefined) {
|
|
288
|
+
assignKwarg(kwargs, key, inlineValue);
|
|
289
|
+
} else if (argv[index + 1] && !argv[index + 1].startsWith('-')) {
|
|
290
|
+
assignKwarg(kwargs, key, argv[index + 1]);
|
|
291
|
+
index += 1;
|
|
292
|
+
} else {
|
|
293
|
+
assignKwarg(kwargs, key, true);
|
|
294
|
+
}
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
121
297
|
commandParts.push(token);
|
|
122
298
|
}
|
|
123
299
|
|
|
124
|
-
return { commandName: commandParts.join(' '), kwargs, format };
|
|
300
|
+
return { commandName: commandParts.join(' '), kwargs, kwargRawFlags, format };
|
|
125
301
|
}
|
|
126
302
|
|
|
127
303
|
async function readVersion() {
|
|
@@ -139,20 +315,49 @@ const VIRTUAL_COMMANDS = [
|
|
|
139
315
|
'输出机器可读命令 schema,供 Agent / 脚本理解命令、参数和示例',
|
|
140
316
|
'',
|
|
141
317
|
'Examples:',
|
|
318
|
+
' lj-awb schema --brief -f json',
|
|
142
319
|
' lj-awb schema -f json',
|
|
143
|
-
' lj-awb schema --domain
|
|
144
|
-
' lj-awb schema --domain
|
|
320
|
+
' lj-awb schema --domain create -f json',
|
|
321
|
+
' lj-awb schema --domain create --command image -f json',
|
|
145
322
|
'',
|
|
146
|
-
'Hint: Agent
|
|
323
|
+
'Hint: Agent 先读 --brief 掌握能力地图;执行具体命令前再读精确 schema。',
|
|
147
324
|
].join('\n'),
|
|
148
325
|
args: [
|
|
149
|
-
{ name: '
|
|
150
|
-
{ name: '
|
|
326
|
+
{ name: 'brief', description: '输出面向 Agent 的轻量能力摘要,不展开每个参数' },
|
|
327
|
+
{ name: 'domain', valueName: 'name', description: '按命令域过滤,如 create / task / artifact / system' },
|
|
328
|
+
{ name: 'command', valueName: 'name', description: '按子命令过滤,如 image / video / wait / doctor' },
|
|
151
329
|
],
|
|
152
330
|
},
|
|
153
331
|
];
|
|
154
332
|
|
|
155
333
|
const RENAMED_COMMAND_HINTS = {
|
|
334
|
+
image: 'create image',
|
|
335
|
+
'image fee': 'create image-fee',
|
|
336
|
+
'image create': 'create image',
|
|
337
|
+
'image create-batch': 'create image-batch',
|
|
338
|
+
'image status': 'task image-status',
|
|
339
|
+
video: 'create video',
|
|
340
|
+
'video fee': 'create video-fee',
|
|
341
|
+
'video create': 'create video',
|
|
342
|
+
'video create-batch': 'create video-batch',
|
|
343
|
+
'video status': 'task video-status',
|
|
344
|
+
'video subtitle-remove': 'create video-subtitle-removal',
|
|
345
|
+
'video subtitle-status': 'task video-subtitle-status',
|
|
346
|
+
asset: 'create asset',
|
|
347
|
+
'asset match-actor': 'create asset-match-actor',
|
|
348
|
+
'asset groups': 'create asset-groups',
|
|
349
|
+
'asset group': 'create asset-group-get',
|
|
350
|
+
'asset group-create': 'create asset-group',
|
|
351
|
+
'asset group-update': 'create asset-group-update',
|
|
352
|
+
'asset register': 'create asset',
|
|
353
|
+
subject: 'create subject',
|
|
354
|
+
'subject list': 'create subject-list',
|
|
355
|
+
'subject publish': 'create subject',
|
|
356
|
+
'subject wait': 'create subject-wait',
|
|
357
|
+
'subject publish-batch': 'create subject-batch',
|
|
358
|
+
'subject voice list': 'create subject-voice-list',
|
|
359
|
+
'subject voice create': 'create subject-voice',
|
|
360
|
+
'subject voice wait': 'create subject-voice-wait',
|
|
156
361
|
'workspace me': 'account info',
|
|
157
362
|
'workspace teams': 'account teams',
|
|
158
363
|
'workspace team-select': 'account switch-team',
|
|
@@ -167,6 +372,16 @@ const RENAMED_COMMAND_HINTS = {
|
|
|
167
372
|
'billing usage-summary': 'credits usage',
|
|
168
373
|
};
|
|
169
374
|
|
|
375
|
+
const MODEL_LIST_GUESS_HINT = `按任务类型分开查询:生图候选用 ${'`'}lj-awb model image-models${'`'},生视频候选用 ${'`'}lj-awb model video-models${'`'}。运行 lj-awb model -h 查看 model 域全部命令。`;
|
|
376
|
+
const COMMAND_GUESS_HINTS = {
|
|
377
|
+
'model list': MODEL_LIST_GUESS_HINT,
|
|
378
|
+
'model models': MODEL_LIST_GUESS_HINT,
|
|
379
|
+
'model ls': MODEL_LIST_GUESS_HINT,
|
|
380
|
+
'model image': MODEL_LIST_GUESS_HINT,
|
|
381
|
+
'model video': MODEL_LIST_GUESS_HINT,
|
|
382
|
+
'models': MODEL_LIST_GUESS_HINT,
|
|
383
|
+
};
|
|
384
|
+
|
|
170
385
|
function buildRegistry() {
|
|
171
386
|
const commands = [];
|
|
172
387
|
registerAwbCommands((spec) => commands.push(spec));
|
|
@@ -187,6 +402,23 @@ function isCommandGroupName(commandName, commands) {
|
|
|
187
402
|
return Boolean(commandName && commands.some((command) => commandGroup(command) === commandName));
|
|
188
403
|
}
|
|
189
404
|
|
|
405
|
+
function commandSubgroupTokens(command) {
|
|
406
|
+
const parts = String(command.name || '').split(' ').filter(Boolean);
|
|
407
|
+
if (parts.length < 3) return null;
|
|
408
|
+
return [parts[0], parts[1]];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function isCommandSubgroupName(commandName, commands) {
|
|
412
|
+
const parts = String(commandName || '').split(' ').filter(Boolean);
|
|
413
|
+
if (parts.length !== 2) return false;
|
|
414
|
+
const [group, subgroup] = parts;
|
|
415
|
+
if (!SUBGROUP_DESCRIPTIONS[group]?.[subgroup]) return false;
|
|
416
|
+
return commands.some((command) => {
|
|
417
|
+
const tokens = commandSubgroupTokens(command);
|
|
418
|
+
return tokens && tokens[0] === group && tokens[1] === subgroup;
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
|
|
190
422
|
function resolveCommandName(commandName, commands) {
|
|
191
423
|
const exact = commands.find((command) => command.name === commandName);
|
|
192
424
|
if (exact) return commandName;
|
|
@@ -206,25 +438,57 @@ const GROUP_DESCRIPTIONS = {
|
|
|
206
438
|
project: '项目:查看、切换、创建和更新项目组',
|
|
207
439
|
credits: '积分:查询可扣积分余额、项目组预算和用量统计',
|
|
208
440
|
model: '模型:查询生图 / 生视频模型、参数约束和创建用法',
|
|
441
|
+
create: '创建:统一提交图片、视频、主体、音色、素材和视频去字幕任务',
|
|
209
442
|
upload: '上传:把本地文件上传为平台可访问素材',
|
|
210
|
-
image: '图片:估价、提交、批量提交和查询生图任务',
|
|
211
|
-
video: '视频:估价、提交、批量提交、查询和去字幕',
|
|
212
443
|
task: '任务:任务列表、等待和本地任务台账',
|
|
213
|
-
|
|
214
|
-
|
|
444
|
+
artifact: '最终产物:剧本、资产、视频、剪辑 CRUD 与本地 JSON 导入',
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
const SUBGROUP_DESCRIPTIONS = {
|
|
448
|
+
artifact: {
|
|
449
|
+
script: '剧本:document / asset / state / speaker / episode / scene / action 行 CRUD 与 script.json 批量导入',
|
|
450
|
+
asset: '资产:角色 / 道具 / 场景 及其状态 CRUD,actors/props/locations JSON 批量导入',
|
|
451
|
+
video: '视频:集 / 场 / clip 三级最终产物 CRUD 与 storyboard 批量导入',
|
|
452
|
+
clip: '剪辑:按集组织的剪辑宽表 CRUD 与状态更新',
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const SUBGROUP_EXAMPLES = {
|
|
457
|
+
'artifact script': [
|
|
458
|
+
'lj-awb artifact script import --project-id <projectId> --input-file 1_script/output/script.json --dry-run',
|
|
459
|
+
'lj-awb artifact script get --project-id <projectId>',
|
|
460
|
+
'lj-awb artifact script rows --project-id <projectId> --row-kind scene',
|
|
461
|
+
],
|
|
462
|
+
'artifact asset': [
|
|
463
|
+
'lj-awb artifact asset import --project-id <projectId> --input-dir 2_asset/output --dry-run',
|
|
464
|
+
'lj-awb artifact asset actors --project-id <projectId> --include-states true',
|
|
465
|
+
'lj-awb artifact asset props --project-id <projectId>',
|
|
466
|
+
],
|
|
467
|
+
'artifact video': [
|
|
468
|
+
'lj-awb artifact video import-storyboard --project-id <projectId> --input-file 3_footage/output/ep001/ep001_storyboard.json --dry-run',
|
|
469
|
+
'lj-awb artifact video episodes --project-id <projectId>',
|
|
470
|
+
'lj-awb artifact video clips --project-id <projectId> --episode-id ep_001 --scene-id scn_001',
|
|
471
|
+
],
|
|
472
|
+
'artifact clip': [
|
|
473
|
+
'lj-awb artifact clip upsert-episode --project-id <projectId> --input-file 4_clip/output/ep001_clip_output.json --dry-run',
|
|
474
|
+
'lj-awb artifact clip episodes --project-id <projectId>',
|
|
475
|
+
'lj-awb artifact clip episode-by-id --project-id <projectId> --episode-id ep_001',
|
|
476
|
+
],
|
|
215
477
|
};
|
|
216
478
|
|
|
217
479
|
const GROUP_EXAMPLES = {
|
|
218
480
|
system: [
|
|
219
481
|
'lj-awb doctor',
|
|
220
482
|
'lj-awb doctor --verify',
|
|
483
|
+
'lj-awb schema --brief -f json',
|
|
221
484
|
'lj-awb schema -f json',
|
|
222
|
-
'lj-awb schema --domain
|
|
485
|
+
'lj-awb schema --domain create -f json',
|
|
223
486
|
],
|
|
224
487
|
auth: [
|
|
225
488
|
'lj-awb auth status',
|
|
226
|
-
'lj-awb auth
|
|
227
|
-
'
|
|
489
|
+
'lj-awb auth verify',
|
|
490
|
+
'lj-awb auth login --access-key <access-key>',
|
|
491
|
+
'LINGJING_AWB_ACCESS_KEY=<access-key> lj-awb auth login',
|
|
228
492
|
'lj-awb auth clear --dry-run',
|
|
229
493
|
],
|
|
230
494
|
account: [
|
|
@@ -245,6 +509,7 @@ const GROUP_EXAMPLES = {
|
|
|
245
509
|
model: [
|
|
246
510
|
'lj-awb model image-models --model Banana',
|
|
247
511
|
'lj-awb model video-models --model Seedance',
|
|
512
|
+
'lj-awb model asset-review-models --platform JIMENG',
|
|
248
513
|
'lj-awb model input-guide',
|
|
249
514
|
'lj-awb model options --model-group-code <code>',
|
|
250
515
|
'lj-awb model create-spec --model-group-code <code>',
|
|
@@ -252,29 +517,29 @@ const GROUP_EXAMPLES = {
|
|
|
252
517
|
upload: [
|
|
253
518
|
'lj-awb upload files --files ./a.png,./b.mp4 --dry-run',
|
|
254
519
|
],
|
|
255
|
-
|
|
256
|
-
'lj-awb image
|
|
257
|
-
'lj-awb image
|
|
258
|
-
'lj-awb
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
'lj-awb
|
|
262
|
-
'lj-awb
|
|
263
|
-
'lj-awb
|
|
264
|
-
'lj-awb video subtitle-status --remote-task-id <id>',
|
|
520
|
+
create: [
|
|
521
|
+
'lj-awb create image --model-group-code <code> --prompt "一只小狗" --dry-run',
|
|
522
|
+
'lj-awb create image-fee --model-group-code <code> --prompt "一只小狗"',
|
|
523
|
+
'lj-awb create video --model-group-code <code> --prompt "镜头推进" --resource image:first_frame=./actor.png --dry-run',
|
|
524
|
+
'lj-awb create video-fee --model-group-code <code> --prompt "雨夜奔跑" --duration 5',
|
|
525
|
+
'lj-awb create subject --model-code tx --name 女主 --resource primary:./three-view.png --dry-run',
|
|
526
|
+
'lj-awb create subject-wait --element-id <elementId> --wait-seconds 300',
|
|
527
|
+
'lj-awb create asset --group-id <id> --platform JIMENG --file ./actor.png --name "女主正面" --dry-run',
|
|
528
|
+
'lj-awb create asset-groups --platform JIMENG --name "女主"',
|
|
265
529
|
],
|
|
266
530
|
task: [
|
|
267
531
|
'lj-awb task list --task-type IMAGE_CREATE --project-group-no <no>',
|
|
532
|
+
'lj-awb task image-status --task-id <imageTaskId>',
|
|
533
|
+
'lj-awb task video-status --task-id <videoTaskId>',
|
|
534
|
+
'lj-awb task video-subtitle-status --task-id <subtitleTaskId>',
|
|
268
535
|
'lj-awb task wait --task-id <id> --task-type IMAGE_CREATE --wait-seconds 180',
|
|
269
536
|
'lj-awb task records --task-record-file .awb/tasks.jsonl',
|
|
270
537
|
],
|
|
271
|
-
|
|
272
|
-
'lj-awb
|
|
273
|
-
'lj-awb asset
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
'lj-awb subject list --name "女主"',
|
|
277
|
-
'lj-awb subject publish --name 女主 --primary-file ./three-view.png --dry-run',
|
|
538
|
+
artifact: [
|
|
539
|
+
'lj-awb artifact script import --project-id <projectId> --input-file 1_script/output/script.json --dry-run',
|
|
540
|
+
'lj-awb artifact asset import --project-id <projectId> --input-dir 2_asset/output --dry-run',
|
|
541
|
+
'lj-awb artifact video import-storyboard --project-id <projectId> --input-file 3_footage/output/ep001/ep001_storyboard.json --dry-run',
|
|
542
|
+
'lj-awb artifact clip upsert-episode --project-id <projectId> --input-file 4_clip/output/ep001_clip_output.json --dry-run',
|
|
278
543
|
],
|
|
279
544
|
};
|
|
280
545
|
|
|
@@ -284,37 +549,118 @@ const COMMAND_REQUIRED_OPTIONS = {
|
|
|
284
549
|
'project ensure': ['name'],
|
|
285
550
|
'model options': ['modelGroupCode'],
|
|
286
551
|
'model create-spec': ['modelGroupCode'],
|
|
287
|
-
'image
|
|
288
|
-
'image
|
|
289
|
-
'image
|
|
290
|
-
'image
|
|
291
|
-
'video
|
|
292
|
-
'video
|
|
293
|
-
'video
|
|
294
|
-
'video
|
|
295
|
-
'video
|
|
552
|
+
'create image-fee': ['modelGroupCode', 'prompt'],
|
|
553
|
+
'create image': ['modelGroupCode', 'prompt'],
|
|
554
|
+
'create image-batch': ['inputFile', 'modelGroupCode'],
|
|
555
|
+
'task image-status': ['taskId'],
|
|
556
|
+
'create video-fee': ['modelGroupCode'],
|
|
557
|
+
'create video': ['modelGroupCode'],
|
|
558
|
+
'create video-batch': ['inputFile', 'modelGroupCode'],
|
|
559
|
+
'task video-status': ['taskId'],
|
|
560
|
+
'task video-subtitle-status': ['taskId'],
|
|
296
561
|
'task wait': ['taskId', 'taskType'],
|
|
297
|
-
'asset
|
|
298
|
-
'asset
|
|
299
|
-
'asset
|
|
300
|
-
'asset
|
|
301
|
-
'asset
|
|
302
|
-
'
|
|
303
|
-
'
|
|
304
|
-
'
|
|
562
|
+
'create asset-match-actor': ['description'],
|
|
563
|
+
'create asset-groups': ['platform'],
|
|
564
|
+
'create asset-group-get': ['groupId', 'platform'],
|
|
565
|
+
'create asset-group': ['name', 'platform'],
|
|
566
|
+
'create asset-group-update': ['groupId', 'platform'],
|
|
567
|
+
'create asset': ['groupId', 'name', 'platform'],
|
|
568
|
+
'artifact script row': ['rowKind', 'entityKey'],
|
|
569
|
+
'artifact script children': ['parentKey'],
|
|
570
|
+
'artifact script delete-row': ['rowKind', 'entityKey'],
|
|
571
|
+
'artifact asset actor': ['actorKey'],
|
|
572
|
+
'artifact asset prop': ['propKey'],
|
|
573
|
+
'artifact asset location': ['locationKey'],
|
|
574
|
+
'artifact asset upsert-actor-state': ['actorKey'],
|
|
575
|
+
'artifact asset upsert-prop-state': ['propKey'],
|
|
576
|
+
'artifact asset upsert-location-state': ['locationKey'],
|
|
577
|
+
'artifact asset delete-actor': ['actorKey'],
|
|
578
|
+
'artifact asset delete-prop': ['propKey'],
|
|
579
|
+
'artifact asset delete-location': ['locationKey'],
|
|
580
|
+
'artifact asset delete-actor-state': ['actorKey', 'stateKey'],
|
|
581
|
+
'artifact asset delete-prop-state': ['propKey', 'stateKey'],
|
|
582
|
+
'artifact asset delete-location-state': ['locationKey', 'stateKey'],
|
|
583
|
+
'artifact video episode': ['episodeId'],
|
|
584
|
+
'artifact video scenes': ['episodeId'],
|
|
585
|
+
'artifact video scene': ['episodeId', 'sceneId'],
|
|
586
|
+
'artifact video clips': ['episodeId', 'sceneId'],
|
|
587
|
+
'artifact video clip': ['episodeId', 'sceneId', 'clipId'],
|
|
588
|
+
'artifact video upsert-scene': ['episodeId'],
|
|
589
|
+
'artifact video upsert-clip': ['episodeId', 'sceneId'],
|
|
590
|
+
'artifact video update-clip-urls': ['episodeId', 'sceneId', 'clipId', 'videoUrlsJson'],
|
|
591
|
+
'artifact video delete-episode': ['episodeId'],
|
|
592
|
+
'artifact video delete-scene': ['episodeId', 'sceneId'],
|
|
593
|
+
'artifact video delete-clip': ['episodeId', 'sceneId', 'clipId'],
|
|
594
|
+
'artifact video import-storyboard': ['inputFile'],
|
|
595
|
+
'artifact clip episode': ['videoEpisodeId'],
|
|
596
|
+
'artifact clip episode-by-id': ['episodeId'],
|
|
597
|
+
'artifact clip update-status': ['videoEpisodeId', 'status'],
|
|
598
|
+
'artifact clip delete-episode': ['videoEpisodeId'],
|
|
599
|
+
'create subject': ['name'],
|
|
600
|
+
'create subject-wait': ['elementId'],
|
|
601
|
+
'create subject-voice': ['name'],
|
|
602
|
+
'create subject-batch': ['inputFile'],
|
|
305
603
|
};
|
|
306
604
|
|
|
307
605
|
const COMMAND_REQUIRED_ANY_OPTIONS = {
|
|
308
|
-
'auth login-key': [['accessKey', 'fromEnv']],
|
|
309
606
|
'project update': [['name', 'point']],
|
|
310
607
|
'upload files': [['file', 'files', 'filesJson']],
|
|
311
|
-
'video
|
|
312
|
-
'video
|
|
313
|
-
'
|
|
314
|
-
'asset
|
|
315
|
-
'
|
|
608
|
+
'create video-fee': [['prompt', 'resource', 'resourcesJson']],
|
|
609
|
+
'create video': [['prompt', 'resource', 'resourcesJson']],
|
|
610
|
+
'create video-subtitle-removal': [['sourceTaskId']],
|
|
611
|
+
'create asset-group-update': [['name', 'description', 'projectName']],
|
|
612
|
+
'create asset': [['file', 'url', 'backendPath']],
|
|
613
|
+
'artifact script upsert-row': [['bodyJson', 'inputFile']],
|
|
614
|
+
'artifact asset upsert-actor': [['bodyJson', 'inputFile']],
|
|
615
|
+
'artifact asset upsert-prop': [['bodyJson', 'inputFile']],
|
|
616
|
+
'artifact asset upsert-location': [['bodyJson', 'inputFile']],
|
|
617
|
+
'artifact asset upsert-actor-state': [['bodyJson', 'inputFile']],
|
|
618
|
+
'artifact asset upsert-prop-state': [['bodyJson', 'inputFile']],
|
|
619
|
+
'artifact asset upsert-location-state': [['bodyJson', 'inputFile']],
|
|
620
|
+
'artifact video upsert-episode': [['bodyJson', 'inputFile']],
|
|
621
|
+
'artifact video upsert-scene': [['bodyJson', 'inputFile']],
|
|
622
|
+
'artifact video upsert-clip': [['bodyJson', 'inputFile']],
|
|
623
|
+
'artifact clip upsert-episode': [['bodyJson', 'inputFile']],
|
|
624
|
+
'artifact clip upsert-batch': [['bodyJson', 'inputFile']],
|
|
625
|
+
'create subject': [['resource'], ['modelCode']],
|
|
626
|
+
'create subject-batch': [['modelCode']],
|
|
627
|
+
'create subject-voice': [['file', 'voiceUrl', 'audioUrl', 'videoId']],
|
|
628
|
+
'create subject-voice-wait': [['voiceRecordId', 'reqTaskId']],
|
|
316
629
|
};
|
|
317
630
|
|
|
631
|
+
const ARTIFACT_WRITE_COMMANDS = [
|
|
632
|
+
'artifact script upsert-row',
|
|
633
|
+
'artifact script delete-row',
|
|
634
|
+
'artifact script import',
|
|
635
|
+
'artifact asset upsert-actor',
|
|
636
|
+
'artifact asset upsert-prop',
|
|
637
|
+
'artifact asset upsert-location',
|
|
638
|
+
'artifact asset upsert-actor-state',
|
|
639
|
+
'artifact asset upsert-prop-state',
|
|
640
|
+
'artifact asset upsert-location-state',
|
|
641
|
+
'artifact asset delete-actor',
|
|
642
|
+
'artifact asset delete-prop',
|
|
643
|
+
'artifact asset delete-location',
|
|
644
|
+
'artifact asset delete-actor-state',
|
|
645
|
+
'artifact asset delete-prop-state',
|
|
646
|
+
'artifact asset delete-location-state',
|
|
647
|
+
'artifact asset import',
|
|
648
|
+
'artifact video upsert-episode',
|
|
649
|
+
'artifact video upsert-scene',
|
|
650
|
+
'artifact video upsert-clip',
|
|
651
|
+
'artifact video update-clip-urls',
|
|
652
|
+
'artifact video delete-episode',
|
|
653
|
+
'artifact video delete-scene',
|
|
654
|
+
'artifact video delete-clip',
|
|
655
|
+
'artifact video import-storyboard',
|
|
656
|
+
'artifact clip upsert-episode',
|
|
657
|
+
'artifact clip upsert-batch',
|
|
658
|
+
'artifact clip update-status',
|
|
659
|
+
'artifact clip delete-episode',
|
|
660
|
+
];
|
|
661
|
+
|
|
662
|
+
const ARTIFACT_DELETE_COMMANDS = ARTIFACT_WRITE_COMMANDS.filter((name) => name.includes(' delete-'));
|
|
663
|
+
|
|
318
664
|
const CONFIRMATION_COMMANDS = new Set([
|
|
319
665
|
'auth clear',
|
|
320
666
|
'account switch-team',
|
|
@@ -322,23 +668,26 @@ const CONFIRMATION_COMMANDS = new Set([
|
|
|
322
668
|
'project create',
|
|
323
669
|
'project update',
|
|
324
670
|
'project ensure',
|
|
325
|
-
'image
|
|
326
|
-
'image
|
|
327
|
-
'video
|
|
328
|
-
'video
|
|
329
|
-
'video
|
|
330
|
-
'asset
|
|
331
|
-
'asset
|
|
332
|
-
'asset
|
|
333
|
-
|
|
334
|
-
'subject
|
|
671
|
+
'create image',
|
|
672
|
+
'create image-batch',
|
|
673
|
+
'create video',
|
|
674
|
+
'create video-batch',
|
|
675
|
+
'create video-subtitle-removal',
|
|
676
|
+
'create asset-group',
|
|
677
|
+
'create asset-group-update',
|
|
678
|
+
'create asset',
|
|
679
|
+
...ARTIFACT_WRITE_COMMANDS,
|
|
680
|
+
'create subject',
|
|
681
|
+
'create subject-voice',
|
|
682
|
+
'create subject-batch',
|
|
335
683
|
]);
|
|
336
684
|
|
|
337
685
|
const COST_COMMANDS = new Set([
|
|
338
|
-
'image
|
|
339
|
-
'image
|
|
340
|
-
'video
|
|
341
|
-
'video
|
|
686
|
+
'create image',
|
|
687
|
+
'create image-batch',
|
|
688
|
+
'create video',
|
|
689
|
+
'create video-batch',
|
|
690
|
+
'create video-subtitle-removal',
|
|
342
691
|
]);
|
|
343
692
|
|
|
344
693
|
const REMOTE_WRITE_COMMANDS = new Set([
|
|
@@ -348,36 +697,39 @@ const REMOTE_WRITE_COMMANDS = new Set([
|
|
|
348
697
|
'project update',
|
|
349
698
|
'project ensure',
|
|
350
699
|
'upload files',
|
|
351
|
-
'image
|
|
352
|
-
'image
|
|
353
|
-
'video
|
|
354
|
-
'video
|
|
355
|
-
'video
|
|
356
|
-
'asset
|
|
357
|
-
'asset
|
|
358
|
-
'asset
|
|
359
|
-
|
|
360
|
-
'subject
|
|
700
|
+
'create image',
|
|
701
|
+
'create image-batch',
|
|
702
|
+
'create video',
|
|
703
|
+
'create video-batch',
|
|
704
|
+
'create video-subtitle-removal',
|
|
705
|
+
'create asset-group',
|
|
706
|
+
'create asset-group-update',
|
|
707
|
+
'create asset',
|
|
708
|
+
...ARTIFACT_WRITE_COMMANDS,
|
|
709
|
+
'create subject',
|
|
710
|
+
'create subject-voice',
|
|
711
|
+
'create subject-batch',
|
|
361
712
|
]);
|
|
362
713
|
|
|
363
714
|
const LOCAL_STATE_WRITE_COMMANDS = new Set([
|
|
364
|
-
'auth login
|
|
715
|
+
'auth login',
|
|
365
716
|
'auth clear',
|
|
366
717
|
'project use',
|
|
367
718
|
'project create',
|
|
368
719
|
'project ensure',
|
|
369
720
|
]);
|
|
370
721
|
|
|
371
|
-
const DESTRUCTIVE_COMMANDS = new Set(['auth clear']);
|
|
372
|
-
const LONG_RUNNING_COMMANDS = new Set(['task wait', 'task record-poll', 'subject wait']);
|
|
722
|
+
const DESTRUCTIVE_COMMANDS = new Set(['auth clear', ...ARTIFACT_DELETE_COMMANDS]);
|
|
723
|
+
const LONG_RUNNING_COMMANDS = new Set(['task wait', 'task record-poll', 'create subject-wait', 'create subject-voice-wait']);
|
|
373
724
|
const NETWORK_NONE_COMMANDS = new Set(['schema', 'auth status', 'auth clear', 'model input-guide', 'task records']);
|
|
374
|
-
const NETWORK_CONDITIONAL_COMMANDS = new Set(['doctor', 'auth login
|
|
725
|
+
const NETWORK_CONDITIONAL_COMMANDS = new Set(['doctor', 'auth login']);
|
|
375
726
|
|
|
376
727
|
const OUTPUT_KIND_BY_COMMAND = {
|
|
377
728
|
doctor: 'environment_report',
|
|
378
729
|
schema: 'command_schema',
|
|
379
730
|
'auth status': 'auth_status',
|
|
380
|
-
'auth
|
|
731
|
+
'auth verify': 'auth_status',
|
|
732
|
+
'auth login': 'auth_result',
|
|
381
733
|
'account info': 'account_summary',
|
|
382
734
|
'account teams': 'team_list',
|
|
383
735
|
'project list': 'project_list',
|
|
@@ -387,47 +739,102 @@ const OUTPUT_KIND_BY_COMMAND = {
|
|
|
387
739
|
'credits usage': 'credits_usage',
|
|
388
740
|
'model image-models': 'model_list',
|
|
389
741
|
'model video-models': 'model_list',
|
|
742
|
+
'model asset-review-models': 'asset_review_model_list',
|
|
390
743
|
'model options': 'model_options',
|
|
391
744
|
'model create-spec': 'model_create_spec',
|
|
392
745
|
'model input-guide': 'model_input_guide',
|
|
393
746
|
'upload files': 'upload_result',
|
|
394
|
-
'image
|
|
395
|
-
'image
|
|
396
|
-
'image
|
|
397
|
-
'image
|
|
398
|
-
'video
|
|
399
|
-
'video
|
|
400
|
-
'video
|
|
401
|
-
'video
|
|
402
|
-
'video
|
|
403
|
-
'video
|
|
747
|
+
'create image-fee': 'fee_estimate',
|
|
748
|
+
'create image': 'task_submission',
|
|
749
|
+
'create image-batch': 'batch_task_submission',
|
|
750
|
+
'task image-status': 'task_status',
|
|
751
|
+
'create video-fee': 'fee_estimate',
|
|
752
|
+
'create video': 'task_submission',
|
|
753
|
+
'create video-batch': 'batch_task_submission',
|
|
754
|
+
'task video-status': 'task_status',
|
|
755
|
+
'create video-subtitle-removal': 'subtitle_task_submission',
|
|
756
|
+
'task video-subtitle-status': 'subtitle_task_status',
|
|
404
757
|
'task list': 'task_list',
|
|
405
758
|
'task wait': 'task_status',
|
|
406
759
|
'task records': 'local_task_records',
|
|
407
760
|
'task record-poll': 'batch_task_status',
|
|
408
|
-
'asset
|
|
409
|
-
'asset
|
|
410
|
-
'asset
|
|
411
|
-
'asset
|
|
412
|
-
'asset
|
|
413
|
-
'asset
|
|
414
|
-
'subject
|
|
415
|
-
'subject
|
|
416
|
-
'subject
|
|
417
|
-
'subject
|
|
761
|
+
'create asset-match-actor': 'asset_match_list',
|
|
762
|
+
'create asset-groups': 'asset_group_list',
|
|
763
|
+
'create asset-group-get': 'asset_group_detail',
|
|
764
|
+
'create asset-group': 'asset_group_write_result',
|
|
765
|
+
'create asset-group-update': 'asset_group_write_result',
|
|
766
|
+
'create asset': 'asset_register_result',
|
|
767
|
+
'create subject-list': 'subject_list',
|
|
768
|
+
'create subject': 'subject_publish_result',
|
|
769
|
+
'create subject-wait': 'subject_status',
|
|
770
|
+
'create subject-voice-list': 'subject_voice_list',
|
|
771
|
+
'create subject-voice': 'subject_voice_create_result',
|
|
772
|
+
'create subject-voice-wait': 'subject_voice_status',
|
|
773
|
+
'create subject-batch': 'batch_subject_publish_result',
|
|
774
|
+
'artifact script get': 'artifact_full',
|
|
775
|
+
'artifact script document': 'artifact_record',
|
|
776
|
+
'artifact script rows': 'artifact_list',
|
|
777
|
+
'artifact script row': 'artifact_record',
|
|
778
|
+
'artifact script children': 'artifact_list',
|
|
779
|
+
'artifact script upsert-row': 'artifact_write_result',
|
|
780
|
+
'artifact script delete-row': 'artifact_delete_result',
|
|
781
|
+
'artifact script import': 'artifact_import_result',
|
|
782
|
+
'artifact asset get': 'artifact_full',
|
|
783
|
+
'artifact asset actors': 'artifact_list',
|
|
784
|
+
'artifact asset actor': 'artifact_record',
|
|
785
|
+
'artifact asset props': 'artifact_list',
|
|
786
|
+
'artifact asset prop': 'artifact_record',
|
|
787
|
+
'artifact asset locations': 'artifact_list',
|
|
788
|
+
'artifact asset location': 'artifact_record',
|
|
789
|
+
'artifact asset upsert-actor': 'artifact_write_result',
|
|
790
|
+
'artifact asset upsert-prop': 'artifact_write_result',
|
|
791
|
+
'artifact asset upsert-location': 'artifact_write_result',
|
|
792
|
+
'artifact asset upsert-actor-state': 'artifact_write_result',
|
|
793
|
+
'artifact asset upsert-prop-state': 'artifact_write_result',
|
|
794
|
+
'artifact asset upsert-location-state': 'artifact_write_result',
|
|
795
|
+
'artifact asset delete-actor': 'artifact_delete_result',
|
|
796
|
+
'artifact asset delete-prop': 'artifact_delete_result',
|
|
797
|
+
'artifact asset delete-location': 'artifact_delete_result',
|
|
798
|
+
'artifact asset delete-actor-state': 'artifact_delete_result',
|
|
799
|
+
'artifact asset delete-prop-state': 'artifact_delete_result',
|
|
800
|
+
'artifact asset delete-location-state': 'artifact_delete_result',
|
|
801
|
+
'artifact asset import': 'artifact_import_result',
|
|
802
|
+
'artifact video get': 'artifact_full',
|
|
803
|
+
'artifact video episodes': 'artifact_list',
|
|
804
|
+
'artifact video episode': 'artifact_record',
|
|
805
|
+
'artifact video scenes': 'artifact_list',
|
|
806
|
+
'artifact video scene': 'artifact_record',
|
|
807
|
+
'artifact video clips': 'artifact_list',
|
|
808
|
+
'artifact video clip': 'artifact_record',
|
|
809
|
+
'artifact video upsert-episode': 'artifact_write_result',
|
|
810
|
+
'artifact video upsert-scene': 'artifact_write_result',
|
|
811
|
+
'artifact video upsert-clip': 'artifact_write_result',
|
|
812
|
+
'artifact video update-clip-urls': 'artifact_write_result',
|
|
813
|
+
'artifact video delete-episode': 'artifact_delete_result',
|
|
814
|
+
'artifact video delete-scene': 'artifact_delete_result',
|
|
815
|
+
'artifact video delete-clip': 'artifact_delete_result',
|
|
816
|
+
'artifact video import-storyboard': 'artifact_import_result',
|
|
817
|
+
'artifact clip get': 'artifact_full',
|
|
818
|
+
'artifact clip episodes': 'artifact_list',
|
|
819
|
+
'artifact clip episode': 'artifact_record',
|
|
820
|
+
'artifact clip episode-by-id': 'artifact_record',
|
|
821
|
+
'artifact clip upsert-episode': 'artifact_write_result',
|
|
822
|
+
'artifact clip upsert-batch': 'artifact_import_result',
|
|
823
|
+
'artifact clip update-status': 'artifact_status_update',
|
|
824
|
+
'artifact clip delete-episode': 'artifact_delete_result',
|
|
418
825
|
};
|
|
419
826
|
|
|
420
827
|
const PREFLIGHTS_BY_COMMAND = {
|
|
421
|
-
'image
|
|
422
|
-
'image
|
|
423
|
-
'video
|
|
424
|
-
'video
|
|
425
|
-
'subject
|
|
426
|
-
'subject
|
|
427
|
-
'video
|
|
428
|
-
'asset
|
|
429
|
-
'asset
|
|
430
|
-
'asset
|
|
828
|
+
'create image': ['doctor --verify', 'model image-models', 'model options', 'model create-spec', 'confirm missing key params', 'create image-fee', 'create image --dry-run'],
|
|
829
|
+
'create image-batch': ['doctor --verify', 'model image-models', 'model options', 'model create-spec', 'prepare JSONL input', 'create image-batch --dry-run'],
|
|
830
|
+
'create video': ['doctor --verify', 'model video-models', 'model options', 'model create-spec', 'confirm missing key params', 'create video-fee', 'create video --dry-run'],
|
|
831
|
+
'create video-batch': ['doctor --verify', 'model video-models', 'model options', 'model create-spec', 'prepare JSONL input', 'create video-batch --dry-run'],
|
|
832
|
+
'create subject': ['doctor --verify', 'create subject --model-code tx|vidu --dry-run'],
|
|
833
|
+
'create subject-batch': ['doctor --verify', 'prepare JSONL input with modelCode', 'create subject-batch --dry-run'],
|
|
834
|
+
'create video-subtitle-removal': ['doctor --verify', 'create video-subtitle-removal --source-task-id <videoTaskId> --dry-run'],
|
|
835
|
+
'create asset-group': ['model asset-review-models', 'create asset-group --platform <platform> --dry-run'],
|
|
836
|
+
'create asset-group-update': ['create asset-group-update --platform <platform> --dry-run'],
|
|
837
|
+
'create asset': ['model asset-review-models', 'create asset --platform <platform> --dry-run'],
|
|
431
838
|
'upload files': ['upload files --dry-run'],
|
|
432
839
|
};
|
|
433
840
|
|
|
@@ -468,6 +875,8 @@ function commandNetworkMode(commandName) {
|
|
|
468
875
|
function unknownCommandHint(commandName) {
|
|
469
876
|
const replacement = RENAMED_COMMAND_HINTS[commandName];
|
|
470
877
|
if (replacement) return `该命令已产品化命名为 ${commandPrefix()} ${replacement}。运行 ${commandPrefix()} ${replacement.split(' ')[0]} -h 查看同组命令。`;
|
|
878
|
+
const guess = COMMAND_GUESS_HINTS[commandName];
|
|
879
|
+
if (guess) return guess;
|
|
471
880
|
const group = String(commandName || '').split(' ').filter(Boolean)[0];
|
|
472
881
|
if (group === 'workspace') return `账号用 ${commandPrefix()} account ...,项目组用 ${commandPrefix()} project ...。运行 ${commandPrefix()} --help 查看可用命令。`;
|
|
473
882
|
if (group === 'billing') return `积分查询用 ${commandPrefix()} credits ...。运行 ${commandPrefix()} credits -h 查看可用命令。`;
|
|
@@ -500,33 +909,254 @@ function buildCommandSafety(command, optionKeys) {
|
|
|
500
909
|
function buildCommandWorkflow(command) {
|
|
501
910
|
const outputKind = OUTPUT_KIND_BY_COMMAND[command.name] || 'generic';
|
|
502
911
|
const next = [];
|
|
503
|
-
if (
|
|
504
|
-
next.push('读取 data.taskId 和 data.nextCommand', '
|
|
912
|
+
if (command.name === 'create image') {
|
|
913
|
+
next.push('读取 data.taskId 和 data.nextCommand', '立即运行响应里的 nextCommand,或 task wait --task-type IMAGE_CREATE 等待结果');
|
|
914
|
+
}
|
|
915
|
+
if (command.name === 'create video') {
|
|
916
|
+
next.push('读取 data.taskId 和 data.nextCommand', '立即运行响应里的 nextCommand,或 task wait --task-type VIDEO_GROUP 等待结果');
|
|
917
|
+
}
|
|
918
|
+
if (command.name === 'create video-subtitle-removal') {
|
|
919
|
+
next.push('读取 data.taskId 和 data.nextCommand', '运行 task video-subtitle-status 或响应里的 nextCommand 等待结果');
|
|
920
|
+
}
|
|
921
|
+
if (command.name === 'create subject') {
|
|
922
|
+
next.push('读取 data.elementId / data.externalId', 'externalId 为空时立刻运行 create subject-wait 获取 nextRefSubject');
|
|
923
|
+
}
|
|
924
|
+
if (command.name === 'create subject-voice') {
|
|
925
|
+
next.push('读取 data.voiceRecordId / data.externalId', 'externalId 为空时立刻运行 create subject-voice-wait 获取 nextVoiceArg');
|
|
926
|
+
}
|
|
927
|
+
if (command.name === 'create asset') {
|
|
928
|
+
next.push('读取 data.assetPath', '若后端返回审核 taskId,再运行 task wait --task-type ASSET_REGISTER');
|
|
929
|
+
}
|
|
930
|
+
if (command.name === 'model image-models' || command.name === 'model video-models') {
|
|
931
|
+
next.push('读取 data.models[] 得到全部候选;用户给了模型口语名时保留同族全部候选,不只取第一个');
|
|
932
|
+
next.push('对每个候选运行 model options --model-group-code <modelGroupCode> 查看真实参数和素材约束');
|
|
933
|
+
next.push('向用户展示候选模型 + 参数取值 + 资源能力后 STOP;等待用户选择或明确授权默认,未确认不得进入 create-spec/fee/dry-run/create');
|
|
505
934
|
}
|
|
506
|
-
if (command.name === '
|
|
507
|
-
next.push('读取 data.
|
|
935
|
+
if (command.name === 'model asset-review-models') {
|
|
936
|
+
next.push('读取 data.models[].platform', '用 create asset-groups --platform <platform> 查重或创建素材组');
|
|
508
937
|
}
|
|
509
|
-
if (
|
|
938
|
+
if (command.name === 'model options') {
|
|
939
|
+
next.push('读取 params/resources/constraints 确认参数与素材约束', '运行 model create-spec --model-group-code <code> 查看创建写法和示例');
|
|
940
|
+
}
|
|
941
|
+
if (command.name === 'model create-spec') {
|
|
942
|
+
next.push('按 examples / supportedIntents 组装命令', '用户确认关键参数后先运行 create image-fee 或 create video-fee,再 dry-run');
|
|
943
|
+
}
|
|
944
|
+
if (command.name === 'model input-guide') {
|
|
945
|
+
next.push('运行 model image-models 或 model video-models 选择模型', '选定模型后运行 model options --model-group-code <code>');
|
|
946
|
+
}
|
|
947
|
+
if (['create image-batch', 'create video-batch', 'create subject-batch'].includes(command.name)) {
|
|
510
948
|
next.push('读取每项 status / taskId / error', '使用 task record-poll 或对应 wait 命令恢复批量结果');
|
|
511
949
|
}
|
|
512
950
|
return {
|
|
513
951
|
outputKind,
|
|
514
|
-
recommendedPreflight: PREFLIGHTS_BY_COMMAND[command.name] || [],
|
|
952
|
+
recommendedPreflight: PREFLIGHTS_BY_COMMAND[command.name] || (ARTIFACT_WRITE_COMMANDS.includes(command.name) ? [`${command.name} --dry-run`] : []),
|
|
515
953
|
nextActions: next,
|
|
516
954
|
};
|
|
517
955
|
}
|
|
518
956
|
|
|
957
|
+
function buildDomainSummaries(commands) {
|
|
958
|
+
const domains = new Map();
|
|
959
|
+
for (const command of commands) {
|
|
960
|
+
const group = commandGroup(command);
|
|
961
|
+
domains.set(group, {
|
|
962
|
+
name: group,
|
|
963
|
+
description: GROUP_DESCRIPTIONS[group] || '',
|
|
964
|
+
commandCount: (domains.get(group)?.commandCount || 0) + 1,
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
return Array.from(domains.values()).sort((a, b) => a.name.localeCompare(b.name));
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
function requiredOptionsForCommand(command) {
|
|
971
|
+
const requiredOptions = new Set();
|
|
972
|
+
if (commandGroup(command) === 'artifact') requiredOptions.add('projectId');
|
|
973
|
+
for (const key of COMMAND_REQUIRED_OPTIONS[command.name] || []) requiredOptions.add(key);
|
|
974
|
+
return [...requiredOptions];
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
function requiredAnyOptionsForCommand(command) {
|
|
978
|
+
return COMMAND_REQUIRED_ANY_OPTIONS[command.name] || [];
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function buildCommandSchemaEntry(command) {
|
|
982
|
+
const requiredOptions = requiredOptionsForCommand(command);
|
|
983
|
+
const requiredAnyOptions = requiredAnyOptionsForCommand(command);
|
|
984
|
+
const optionKeys = new Set((command.args || []).map((arg) => normalizeKey(arg.name)));
|
|
985
|
+
return {
|
|
986
|
+
name: command.name,
|
|
987
|
+
domain: commandGroup(command),
|
|
988
|
+
command: commandSubcommand(command),
|
|
989
|
+
invocation: `${commandPrefix()} ${command.name}`,
|
|
990
|
+
helpCommand: `${commandPrefix()} ${command.name} -h`,
|
|
991
|
+
summary: summaryOf(command),
|
|
992
|
+
description: renderCliText(summaryOf(command)),
|
|
993
|
+
examples: extractExamples(command).map(renderCliText),
|
|
994
|
+
jsonExamples: extractExamples(command).map(asJsonExample),
|
|
995
|
+
requiredOptions,
|
|
996
|
+
requiredAnyOptions,
|
|
997
|
+
safety: buildCommandSafety(command, optionKeys),
|
|
998
|
+
workflow: buildCommandWorkflow(command),
|
|
999
|
+
options: (command.args || []).map((arg) => {
|
|
1000
|
+
const key = normalizeKey(arg.name);
|
|
1001
|
+
return {
|
|
1002
|
+
name: arg.name,
|
|
1003
|
+
key,
|
|
1004
|
+
flag: formatOptionName(arg.name),
|
|
1005
|
+
valueName: arg.valueName || null,
|
|
1006
|
+
required: requiredOptions.includes(key),
|
|
1007
|
+
requiredAnyGroup: requiredAnyOptions.find((group) => group.includes(key)) || null,
|
|
1008
|
+
description: arg.description || '',
|
|
1009
|
+
};
|
|
1010
|
+
}),
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
function namesWhere(entries, predicate) {
|
|
1015
|
+
return entries.filter(predicate).map((entry) => entry.name);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function buildAgentBrief(commands, version = 'unknown') {
|
|
1019
|
+
const contract = buildAgentContract();
|
|
1020
|
+
const entries = commands.map(buildCommandSchemaEntry);
|
|
1021
|
+
const domains = buildDomainSummaries(commands).map((domain) => ({
|
|
1022
|
+
...domain,
|
|
1023
|
+
commands: entries
|
|
1024
|
+
.filter((entry) => entry.domain === domain.name)
|
|
1025
|
+
.map((entry) => entry.name),
|
|
1026
|
+
}));
|
|
1027
|
+
return {
|
|
1028
|
+
schemaVersion: 1,
|
|
1029
|
+
kind: 'agent_brief',
|
|
1030
|
+
cli: {
|
|
1031
|
+
name: 'lj-awb',
|
|
1032
|
+
version,
|
|
1033
|
+
commandPrefix: commandPrefix(),
|
|
1034
|
+
},
|
|
1035
|
+
commandCount: entries.length,
|
|
1036
|
+
domains,
|
|
1037
|
+
outputPolicy: {
|
|
1038
|
+
agentRecommendedOutputFormat: contract.agentRecommendedOutputFormat,
|
|
1039
|
+
scriptRecommendedOutputFormat: contract.scriptRecommendedOutputFormat,
|
|
1040
|
+
textFlag: contract.textFlag,
|
|
1041
|
+
jsonFlag: contract.jsonFlag,
|
|
1042
|
+
policy: contract.outputPolicy,
|
|
1043
|
+
},
|
|
1044
|
+
statePolicy: contract.statePolicy,
|
|
1045
|
+
workflowPolicy: contract.workflowPolicy,
|
|
1046
|
+
safetyPolicy: {
|
|
1047
|
+
confirmationPolicy: contract.confirmationPolicy,
|
|
1048
|
+
dryRunPolicy: contract.dryRunPolicy,
|
|
1049
|
+
remoteWriteCount: namesWhere(entries, (entry) => entry.safety.remoteWrite).length,
|
|
1050
|
+
costsPointsCount: namesWhere(entries, (entry) => entry.safety.costsPoints).length,
|
|
1051
|
+
localStateWriteCount: namesWhere(entries, (entry) => entry.safety.localStateWrite).length,
|
|
1052
|
+
destructiveCount: namesWhere(entries, (entry) => entry.safety.destructive).length,
|
|
1053
|
+
longRunningCount: namesWhere(entries, (entry) => entry.safety.longRunning).length,
|
|
1054
|
+
},
|
|
1055
|
+
commandClasses: {
|
|
1056
|
+
costsPoints: namesWhere(entries, (entry) => entry.safety.costsPoints),
|
|
1057
|
+
remoteWrite: namesWhere(entries, (entry) => entry.safety.remoteWrite),
|
|
1058
|
+
localStateWrite: namesWhere(entries, (entry) => entry.safety.localStateWrite),
|
|
1059
|
+
destructive: namesWhere(entries, (entry) => entry.safety.destructive),
|
|
1060
|
+
longRunning: namesWhere(entries, (entry) => entry.safety.longRunning),
|
|
1061
|
+
safeRead: namesWhere(entries, (entry) => entry.safety.safeToAutoRun && entry.safety.network !== 'none'),
|
|
1062
|
+
offlineRead: namesWhere(entries, (entry) => entry.safety.safeToAutoRun && entry.safety.network === 'none'),
|
|
1063
|
+
},
|
|
1064
|
+
routing: [
|
|
1065
|
+
{
|
|
1066
|
+
intent: '环境、认证、账号、团队、项目组、积分',
|
|
1067
|
+
start: ['doctor --verify', 'account info', 'project current', 'credits balance'],
|
|
1068
|
+
rule: '只读查询可自动运行;切换团队、切换/创建/更新项目组和清空认证按 safety dry-run/confirm 处理。',
|
|
1069
|
+
},
|
|
1070
|
+
{
|
|
1071
|
+
intent: '模型发现和创作任务',
|
|
1072
|
+
start: ['model image-models', 'model video-models', 'model options', 'model create-spec'],
|
|
1073
|
+
rule: '先展示候选模型、真实参数和资源能力并 STOP;用户选择或明确授权默认后,关键参数确认,再只跑一次 fee、dry-run 和最终 --yes。',
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
intent: '上传、主体、音色、素材加白',
|
|
1077
|
+
start: ['upload files', 'create subject-list', 'create subject-voice-list', 'model asset-review-models'],
|
|
1078
|
+
rule: '复用已上传 backendPath、已有主体/音色/素材组;素材加白平台来自 model asset-review-models 或用户明确选择。',
|
|
1079
|
+
},
|
|
1080
|
+
{
|
|
1081
|
+
intent: '异步任务和批量恢复',
|
|
1082
|
+
start: ['task wait', 'task record-poll', 'task records'],
|
|
1083
|
+
rule: '优先复用 create 返回的 nextCommand;批量任务使用 task-record-file,失败项单独重试。',
|
|
1084
|
+
},
|
|
1085
|
+
{
|
|
1086
|
+
intent: '最终产物 artifact',
|
|
1087
|
+
start: ['artifact script', 'artifact asset', 'artifact video', 'artifact clip'],
|
|
1088
|
+
rule: 'artifact 使用 project-id,不是 project-group-no;写入/删除/导入先 dry-run,再一次性确认写入面。',
|
|
1089
|
+
},
|
|
1090
|
+
],
|
|
1091
|
+
lookup: {
|
|
1092
|
+
preciseSchema: `${commandPrefix()} schema --domain <domain> --command <command> -f json`,
|
|
1093
|
+
fullSchema: `${commandPrefix()} schema -f json`,
|
|
1094
|
+
commandHelp: `${commandPrefix()} <domain> <command> -h`,
|
|
1095
|
+
modelInputGuide: contract.modelInputGuide.textCommand,
|
|
1096
|
+
schemaPolicy: contract.schemaPolicy,
|
|
1097
|
+
},
|
|
1098
|
+
canonicalFields: contract.canonicalFields,
|
|
1099
|
+
resourceShortcut: contract.resourceShortcut,
|
|
1100
|
+
resourcesJson: contract.resourcesJson,
|
|
1101
|
+
modelCandidatePresentation: contract.modelCandidatePresentation,
|
|
1102
|
+
taskTypes: contract.taskTypes,
|
|
1103
|
+
exitCodes: contract.exitCodes,
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
|
|
519
1107
|
function buildAgentContract() {
|
|
520
1108
|
return {
|
|
521
|
-
defaultOutputFormat: '
|
|
1109
|
+
defaultOutputFormat: 'pretty',
|
|
1110
|
+
humanDefaultOutputFormat: 'pretty',
|
|
1111
|
+
agentRecommendedOutputFormat: 'text',
|
|
1112
|
+
agentCompactOutputFormat: 'text',
|
|
1113
|
+
scriptRecommendedOutputFormat: 'json',
|
|
522
1114
|
jsonFlag: '-f json',
|
|
523
|
-
|
|
524
|
-
|
|
1115
|
+
textFlag: '-f text',
|
|
1116
|
+
outputFormats: ['pretty', 'text', 'json', 'yaml', 'csv', 'auto'],
|
|
1117
|
+
outputPolicy: '默认输出 pretty 人类友好视图,包含标题、摘要表格、列表表格和下一步建议;Agent 推荐显式传 -f text 读取稳定的分区 key=value 输出;脚本严格解析或需要完整嵌套结构时再传 -f json 或 --json。JSON envelope 字段已做归一化,见 canonicalFields。',
|
|
1118
|
+
statePolicy: {
|
|
1119
|
+
purpose: 'Agent 应在同一轮 / 同一项目中维护 AWB 上下文账本,减少重复查询和重复提交。',
|
|
1120
|
+
cacheKeys: [
|
|
1121
|
+
'schema version / domains / commands',
|
|
1122
|
+
'auth / account / team / current projectGroup',
|
|
1123
|
+
'modelCandidates by taskKind + keyword',
|
|
1124
|
+
'assetReviewModels by modelGroupCode / platform',
|
|
1125
|
+
'modelOptions / modelCreateSpec by modelGroupCode',
|
|
1126
|
+
'uploaded backendPath by local file path or remote URL',
|
|
1127
|
+
'taskId -> taskType / projectGroupNo / resultUrls / errorMessage',
|
|
1128
|
+
'subject name + modelCode -> elementId / externalId / nextRefSubject',
|
|
1129
|
+
'subject voice name + source -> voiceRecordId / externalId / nextVoiceArg',
|
|
1130
|
+
'artifact projectId and imported file paths',
|
|
1131
|
+
],
|
|
1132
|
+
invalidation: '用户切换账号、团队、项目组、模型、素材、prompt 或关键参数后,只刷新受影响的缓存;不要重复跑未变化的 model options / create-spec / fee。',
|
|
1133
|
+
},
|
|
1134
|
+
workflowPolicy: [
|
|
1135
|
+
'模型口语名命中后必须先展示候选模型、真实参数取值和资源能力,并在清单后 STOP 等用户选择或明确授权默认;没有完成用户可见候选清单和确认前,不得代选默认模型 / 参数,也不得进入 create-spec、fee、dry-run 或 create。',
|
|
1136
|
+
'模型探索阶段只读 model list / options / create-spec;fee 只在用户确认关键参数后跑一次。',
|
|
1137
|
+
'supportsDryRun=true 的写入 / 扣费命令先 dry-run,确认后 yes;不要把 dry-run 当参数探索工具反复跑。',
|
|
1138
|
+
'用户给出多条同模型同参数任务时优先 batch + task-record-file,不要单条循环 create。',
|
|
1139
|
+
'命令返回 nextCommand / nextRefSubject / nextVoiceArg 时优先复用返回值,不手拼等价命令。',
|
|
1140
|
+
'素材加白平台先通过 model asset-review-models 或用户明确输入确定;create asset-* 必须显式传 --platform,不要依赖默认平台。',
|
|
1141
|
+
'旧根域 image / video / asset / subject 已移除;只使用 create / task / artifact 等 schema 暴露的 domain。',
|
|
1142
|
+
],
|
|
1143
|
+
canonicalFields: {
|
|
1144
|
+
purpose: 'CLI 输出对上游平台多版本字段做了归一化。Agent 只识别 canonical 列,遇到 aliases 列出的旧字段名时说明是上游原始返回,CLI 已在 text / 归一化层做了 fallback。不要把旧名当成独立新字段对外报告。',
|
|
1145
|
+
fields: [
|
|
1146
|
+
{ canonical: 'billingPointBalance', aliases: ['teamPointBalance'], meaning: '实际可扣积分余额(/api/anime/member/benefits/queryGroupPoint)' },
|
|
1147
|
+
{ canonical: 'billingPointRemainingAfter', aliases: ['teamPointRemainingAfter'], meaning: '本次任务后预计可扣积分余额' },
|
|
1148
|
+
{ canonical: 'projectBudgetBalance', aliases: ['projectPointBalance'], meaning: '项目组预算 / ROI 余额(不是积分)' },
|
|
1149
|
+
{ canonical: 'projectBudgetMax', aliases: ['projectPointMax'], meaning: '项目组预算上限' },
|
|
1150
|
+
{ canonical: 'projectBudgetRemainingAfter', aliases: ['projectPointRemainingAfter'], meaning: '本次任务后预计项目组预算余额' },
|
|
1151
|
+
{ canonical: 'pointCost', aliases: ['points', 'point', 'costPoint', 'estimatePoint'], meaning: '本次任务预计 / 实际消耗积分' },
|
|
1152
|
+
],
|
|
1153
|
+
},
|
|
1154
|
+
schemaPolicy: 'Agent 先读 schema --brief 建立能力地图;执行具体命令前再读精确 schema --domain <domain> --command <command>。完整 schema -f json 只用于覆盖校验、脚本生成或调试 schema 本身;查看长帮助用 schema.commands[].helpCommand 或 lj-awb <domain> <command> -h。',
|
|
525
1155
|
confirmationPolicy: 'schema.commands[].safety.requiresConfirmation=true 的命令,Agent 必须先向用户确认,再追加 --yes。',
|
|
526
1156
|
dryRunPolicy: 'schema.commands[].safety.supportsDryRun=true 的写入 / 扣费命令,正式执行前优先跑 --dry-run。',
|
|
527
1157
|
resourceShortcut: {
|
|
528
1158
|
flag: '--resource',
|
|
529
|
-
syntax: 'type:usage[:reference_key]=path|url|asset:<id>; image
|
|
1159
|
+
syntax: 'type:usage[:reference_key]=path|url|asset:<id>; create image uses image:reference=... without key',
|
|
530
1160
|
examples: [
|
|
531
1161
|
'image:reference=./ref.png',
|
|
532
1162
|
'image:first_frame=./hero.png',
|
|
@@ -540,34 +1170,48 @@ function buildAgentContract() {
|
|
|
540
1170
|
{
|
|
541
1171
|
type: 'image|video|audio|subject',
|
|
542
1172
|
usage: 'reference|first_frame|last_frame|keyframe',
|
|
543
|
-
reference_key: 'video reference placeholder key; not used by
|
|
1173
|
+
reference_key: 'video reference placeholder key; not used by create image image:reference',
|
|
544
1174
|
source: { kind: 'url|asset_id', value: '<local-file-or-http-url-or-material-backendPath-or-asset-id>' },
|
|
545
1175
|
},
|
|
546
1176
|
],
|
|
547
1177
|
},
|
|
1178
|
+
modelCandidatePresentation: {
|
|
1179
|
+
purpose: '把 model image-models / video-models 与每个候选的 model options 转成用户可见清单,避免 Agent 内部看完 options 后直接代选。',
|
|
1180
|
+
trigger: '用户问有哪些模型、给出口语名、或模型列表返回候选时都触发;即使只有一个候选也要展示真实可选项。',
|
|
1181
|
+
gateType: 'hard_stop',
|
|
1182
|
+
stopAfterPresentation: true,
|
|
1183
|
+
resumeCondition: '用户选择模型和关键参数,或明确说“按默认 / 你来选”。',
|
|
1184
|
+
requiredVisibleFields: ['displayName', 'modelDesc', 'taskQueueNum', 'quality values/default', 'ratio values/default', 'duration or generateNum values/default', 'resource modes/media/usages', 'channel or fast/pro differences'],
|
|
1185
|
+
blockedBeforePresentation: ['model create-spec', 'create image-fee', 'create video-fee', 'create image-batch --dry-run', 'create video-batch --dry-run', 'create image --dry-run', 'create video --dry-run', 'create image', 'create video', 'default model recommendation', 'default quality/ratio/duration choice'],
|
|
1186
|
+
},
|
|
548
1187
|
modelOptions: {
|
|
549
1188
|
command: `${commandPrefix()} model options --model-group-code <code>`,
|
|
1189
|
+
textCommand: `${commandPrefix()} model options --model-group-code <code> -f text`,
|
|
550
1190
|
jsonCommand: `${commandPrefix()} model options --model-group-code <code> -f json`,
|
|
551
|
-
purpose: '查询指定模型支持的 CLI 参数、枚举值、默认值、素材约束和条件约束。',
|
|
552
|
-
useBefore: ['model create-spec', 'image
|
|
1191
|
+
purpose: '查询指定模型支持的 CLI 参数、枚举值、默认值、素材约束和条件约束。Agent 默认读 textCommand;只有程序化校验完整嵌套结构时读 jsonCommand。',
|
|
1192
|
+
useBefore: ['model create-spec', 'create image-fee', 'create image', 'create video-fee', 'create video'],
|
|
553
1193
|
keyFields: ['params[].values', 'params[].defaultValue', 'resources[].mediaType', 'resources[].usage', 'resources[].fileTypes', 'resources[].maxFiles', 'resources[].supportLastFrameOnly', 'resources[].minDurationMs', 'resources[].maxDurationMs', 'constraints[].target', 'constraints[].conditions', 'constraints[].effect'],
|
|
554
1194
|
},
|
|
555
1195
|
modelCreateSpec: {
|
|
556
1196
|
command: `${commandPrefix()} model create-spec --model-group-code <code>`,
|
|
1197
|
+
textCommand: `${commandPrefix()} model create-spec --model-group-code <code> -f text`,
|
|
557
1198
|
jsonCommand: `${commandPrefix()} model create-spec --model-group-code <code> -f json`,
|
|
558
|
-
purpose: '查看指定模型如何组织 create 命令:输入模式、素材绑定规则、示例和创建前检查项。',
|
|
559
|
-
useBefore: ['image
|
|
1199
|
+
purpose: '查看指定模型如何组织 create 命令:输入模式、素材绑定规则、示例和创建前检查项。Agent 默认读 textCommand;只有程序化校验完整嵌套结构时读 jsonCommand。',
|
|
1200
|
+
useBefore: ['create image-fee', 'create image', 'create video-fee', 'create video'],
|
|
560
1201
|
keyFields: ['inputRequirement', 'supportedIntents', 'validationRules', 'agentGuidance', 'preflight', 'examples'],
|
|
561
1202
|
},
|
|
562
1203
|
modelInputGuide: {
|
|
563
1204
|
command: `${commandPrefix()} model input-guide`,
|
|
1205
|
+
textCommand: `${commandPrefix()} model input-guide -f text`,
|
|
564
1206
|
jsonCommand: `${commandPrefix()} model input-guide -f json`,
|
|
565
|
-
purpose: '查看跨模型统一创建参数、resources 字段和素材绑定规则。',
|
|
1207
|
+
purpose: '查看跨模型统一创建参数、resources 字段和素材绑定规则。Agent 默认读 textCommand;脚本严格解析时读 jsonCommand。',
|
|
566
1208
|
useBefore: ['model options', 'model create-spec'],
|
|
567
1209
|
},
|
|
568
1210
|
taskTypes: {
|
|
569
1211
|
image: 'IMAGE_CREATE',
|
|
570
1212
|
video: 'VIDEO_GROUP',
|
|
1213
|
+
subtitleRemoval: 'VIDEO_SUBTITLE_REMOVAL',
|
|
1214
|
+
assetRegister: 'ASSET_REGISTER',
|
|
571
1215
|
},
|
|
572
1216
|
exitCodes: [
|
|
573
1217
|
{ code: 0, type: 'success', meaning: '命令成功' },
|
|
@@ -575,24 +1219,21 @@ function buildAgentContract() {
|
|
|
575
1219
|
{ code: 2, type: 'argument_error|unknown_command|unknown_option', meaning: '参数或命令错误' },
|
|
576
1220
|
{ code: 3, type: 'auth_required|auth_failed', meaning: '缺少认证或认证失败' },
|
|
577
1221
|
{ code: 10, type: 'confirmation_required', meaning: '需要用户确认后追加 --yes' },
|
|
578
|
-
{ code:
|
|
1222
|
+
{ code: 1, type: 'subject_failed', meaning: '主体创建任务已失败(error.type=subject_failed)。查看 error.details.errorMessage 后调整参考资源或模型重新创建。' },
|
|
1223
|
+
{ code: 1, type: 'subject_voice_failed', meaning: '主体音色创建任务已失败(error.type=subject_voice_failed)。查看 error.details.errorMessage 后调整音频或视频来源重新创建。' },
|
|
1224
|
+
{ code: 20, type: 'task_still_running', meaning: '生图 / 生视频任务仍在运行,本轮等待窗口结束(error.type=task_still_running)。可继续 task wait 或 record-poll 续等。' },
|
|
1225
|
+
{ code: 20, type: 'subject_still_pending', meaning: '主体 externalId 尚未回填,本轮等待窗口结束(error.type=subject_still_pending)。可继续 create subject-wait 续等。' },
|
|
1226
|
+
{ code: 20, type: 'subject_voice_still_pending', meaning: '主体音色 externalId 尚未回填,本轮等待窗口结束(error.type=subject_voice_still_pending)。可继续 create subject-voice-wait 续等。' },
|
|
579
1227
|
{ code: 30, type: 'network_error', meaning: '网络、TLS、HTTP 或外部平台不可用' },
|
|
580
1228
|
],
|
|
581
1229
|
};
|
|
582
1230
|
}
|
|
583
1231
|
|
|
584
1232
|
function buildCommandSchema(commands, kwargs = {}, version = 'unknown') {
|
|
1233
|
+
if (toBool(kwargs.brief)) return buildAgentBrief(commands, version);
|
|
585
1234
|
const domainFilter = String(kwargs.domain ?? '').trim();
|
|
586
1235
|
const commandFilter = String(kwargs.command ?? '').trim();
|
|
587
|
-
const domains =
|
|
588
|
-
for (const command of commands) {
|
|
589
|
-
const group = commandGroup(command);
|
|
590
|
-
domains.set(group, {
|
|
591
|
-
name: group,
|
|
592
|
-
description: GROUP_DESCRIPTIONS[group] || '',
|
|
593
|
-
commandCount: (domains.get(group)?.commandCount || 0) + 1,
|
|
594
|
-
});
|
|
595
|
-
}
|
|
1236
|
+
const domains = buildDomainSummaries(commands);
|
|
596
1237
|
const filteredCommands = commands
|
|
597
1238
|
.filter((command) => !domainFilter || commandGroup(command) === domainFilter)
|
|
598
1239
|
.filter((command) => !commandFilter || command.name === commandFilter || commandSubcommand(command) === commandFilter);
|
|
@@ -616,47 +1257,16 @@ function buildCommandSchema(commands, kwargs = {}, version = 'unknown') {
|
|
|
616
1257
|
`${commandPrefix()} <domain> <command> -h`,
|
|
617
1258
|
],
|
|
618
1259
|
globalOptions: [
|
|
619
|
-
{ flag: '-f, --format
|
|
1260
|
+
{ flag: '-f, --format <format>', key: 'format', description: '输出格式:pretty(默认)、text、json、yaml、csv、auto' },
|
|
620
1261
|
{ flag: '--json', key: 'format', value: 'json', description: '等同于 -f json' },
|
|
621
1262
|
{ flag: '-h, --help', key: 'help', description: '查看帮助' },
|
|
622
1263
|
{ flag: '-v, --version', key: 'version', description: '查看版本' },
|
|
623
1264
|
],
|
|
624
1265
|
agentContract: buildAgentContract(),
|
|
625
|
-
domains:
|
|
1266
|
+
domains: domains
|
|
626
1267
|
.filter((domain) => !shouldFilterDomains || matchedDomains.has(domain.name))
|
|
627
1268
|
.sort((a, b) => a.name.localeCompare(b.name)),
|
|
628
|
-
commands: filteredCommands.map(
|
|
629
|
-
const requiredOptions = new Set(COMMAND_REQUIRED_OPTIONS[command.name] || []);
|
|
630
|
-
const requiredAnyOptions = COMMAND_REQUIRED_ANY_OPTIONS[command.name] || [];
|
|
631
|
-
const optionKeys = new Set((command.args || []).map((arg) => normalizeKey(arg.name)));
|
|
632
|
-
return {
|
|
633
|
-
name: command.name,
|
|
634
|
-
domain: commandGroup(command),
|
|
635
|
-
command: commandSubcommand(command),
|
|
636
|
-
invocation: `${commandPrefix()} ${command.name}`,
|
|
637
|
-
helpCommand: `${commandPrefix()} ${command.name} -h`,
|
|
638
|
-
summary: summaryOf(command),
|
|
639
|
-
description: renderCliText(summaryOf(command)),
|
|
640
|
-
examples: extractExamples(command).map(renderCliText),
|
|
641
|
-
jsonExamples: extractExamples(command).map(asJsonExample),
|
|
642
|
-
requiredOptions: [...requiredOptions],
|
|
643
|
-
requiredAnyOptions,
|
|
644
|
-
safety: buildCommandSafety(command, optionKeys),
|
|
645
|
-
workflow: buildCommandWorkflow(command),
|
|
646
|
-
options: (command.args || []).map((arg) => {
|
|
647
|
-
const key = normalizeKey(arg.name);
|
|
648
|
-
return {
|
|
649
|
-
name: arg.name,
|
|
650
|
-
key,
|
|
651
|
-
flag: formatOptionName(arg.name),
|
|
652
|
-
valueName: arg.valueName || null,
|
|
653
|
-
required: requiredOptions.has(key),
|
|
654
|
-
requiredAnyGroup: requiredAnyOptions.find((group) => group.includes(key)) || null,
|
|
655
|
-
description: arg.description || '',
|
|
656
|
-
};
|
|
657
|
-
}),
|
|
658
|
-
};
|
|
659
|
-
}),
|
|
1269
|
+
commands: filteredCommands.map(buildCommandSchemaEntry),
|
|
660
1270
|
};
|
|
661
1271
|
}
|
|
662
1272
|
|
|
@@ -669,128 +1279,252 @@ function printRootHelp(commands, version) {
|
|
|
669
1279
|
}
|
|
670
1280
|
|
|
671
1281
|
const lines = [
|
|
672
|
-
`lj-awb v${version}
|
|
1282
|
+
helpTitle(`lj-awb v${version}`),
|
|
673
1283
|
'',
|
|
674
|
-
'灵境 AWB
|
|
1284
|
+
'灵境 AWB 命令行工具。默认输出人类友好的 pretty 视图;Agent 建议显式传 -f text,脚本严格解析用 -f json。',
|
|
675
1285
|
'',
|
|
676
|
-
'Usage:',
|
|
677
|
-
` ${commandPrefix()} <domain> <command> [options]
|
|
678
|
-
` ${commandPrefix()} <command> [options]
|
|
679
|
-
` ${commandPrefix()} <domain> -h
|
|
680
|
-
` ${commandPrefix()} <domain> <command> -h
|
|
1286
|
+
helpHeading('Usage:'),
|
|
1287
|
+
helpCommand(` ${commandPrefix()} <domain> <command> [options]`),
|
|
1288
|
+
helpCommand(` ${commandPrefix()} <command> [options]`),
|
|
1289
|
+
helpCommand(` ${commandPrefix()} <domain> -h`),
|
|
1290
|
+
helpCommand(` ${commandPrefix()} <domain> <command> -h`),
|
|
681
1291
|
'',
|
|
682
|
-
'Quick start:',
|
|
683
|
-
` ${commandPrefix()} auth status
|
|
684
|
-
` ${commandPrefix()} auth login
|
|
685
|
-
` ${commandPrefix()} model image-models --model Banana
|
|
686
|
-
` ${commandPrefix()} model input-guide
|
|
687
|
-
` ${commandPrefix()} model options --model-group-code <code
|
|
688
|
-
` ${commandPrefix()} model create-spec --model-group-code <code
|
|
689
|
-
` ${commandPrefix()} image
|
|
1292
|
+
helpHeading('Quick start:'),
|
|
1293
|
+
helpCommand(` ${commandPrefix()} auth status`),
|
|
1294
|
+
helpCommand(` ${commandPrefix()} auth login --access-key <access-key>`),
|
|
1295
|
+
helpCommand(` ${commandPrefix()} model image-models --model Banana`),
|
|
1296
|
+
helpCommand(` ${commandPrefix()} model input-guide`),
|
|
1297
|
+
helpCommand(` ${commandPrefix()} model options --model-group-code <code>`),
|
|
1298
|
+
helpCommand(` ${commandPrefix()} model create-spec --model-group-code <code>`),
|
|
1299
|
+
helpCommand(` ${commandPrefix()} create image --model-group-code <code> --prompt "一只小狗" --dry-run`),
|
|
690
1300
|
'',
|
|
691
|
-
'Command groups:',
|
|
1301
|
+
helpHeading('Command groups:'),
|
|
692
1302
|
];
|
|
693
1303
|
for (const [group] of groups.entries()) {
|
|
694
|
-
lines.push(` ${group.padEnd(12)} ${GROUP_DESCRIPTIONS[group] || ''}`);
|
|
1304
|
+
lines.push(` ${helpGroup(group.padEnd(12))} ${GROUP_DESCRIPTIONS[group] || ''}`);
|
|
695
1305
|
}
|
|
696
1306
|
lines.push(
|
|
697
1307
|
'',
|
|
698
|
-
'More help:',
|
|
699
|
-
` ${commandPrefix()} <domain> -h
|
|
700
|
-
` ${commandPrefix()} <domain> <command> -h
|
|
701
|
-
` ${commandPrefix()} schema -f json
|
|
702
|
-
` ${commandPrefix()}
|
|
1308
|
+
helpHeading('More help:'),
|
|
1309
|
+
helpCommand(` ${commandPrefix()} <domain> -h`),
|
|
1310
|
+
helpCommand(` ${commandPrefix()} <domain> <command> -h`),
|
|
1311
|
+
helpCommand(` ${commandPrefix()} schema --brief -f json`),
|
|
1312
|
+
helpCommand(` ${commandPrefix()} schema -f json`),
|
|
1313
|
+
helpCommand(` ${commandPrefix()} doctor -h`),
|
|
703
1314
|
'',
|
|
704
|
-
'Global options:',
|
|
705
|
-
'
|
|
706
|
-
'
|
|
707
|
-
'
|
|
708
|
-
'
|
|
1315
|
+
helpHeading('Global options:'),
|
|
1316
|
+
` ${helpOption('-f, --format <format>')} 输出格式:pretty(默认)、text、json、yaml、csv、auto`,
|
|
1317
|
+
` ${helpOption('--json'.padEnd(22))} 等同于 -f json`,
|
|
1318
|
+
` ${helpOption('-h, --help'.padEnd(22))} 查看帮助`,
|
|
1319
|
+
` ${helpOption('-v, --version'.padEnd(22))} 查看版本`,
|
|
709
1320
|
);
|
|
710
1321
|
process.stdout.write(`${lines.join('\n')}\n`);
|
|
711
1322
|
}
|
|
712
1323
|
|
|
713
1324
|
function printGroupHelp(group, commands, version) {
|
|
714
1325
|
const items = commands.filter((command) => commandGroup(command) === group);
|
|
1326
|
+
const subgroupMap = SUBGROUP_DESCRIPTIONS[group];
|
|
1327
|
+
const hasSubgroups = Boolean(subgroupMap && Object.keys(subgroupMap).length);
|
|
1328
|
+
const directItems = hasSubgroups ? items.filter((command) => !commandSubgroupTokens(command)) : [];
|
|
1329
|
+
|
|
715
1330
|
const lines = [
|
|
716
|
-
`lj-awb v${version}
|
|
1331
|
+
helpTitle(`lj-awb v${version}`),
|
|
717
1332
|
'',
|
|
718
1333
|
GROUP_DESCRIPTIONS[group] || `${group} 命令组`,
|
|
719
1334
|
'',
|
|
720
|
-
'Usage:',
|
|
721
|
-
group === 'system' ? ` ${commandPrefix()} <command> [options]` : ` ${commandPrefix()} ${group} <command> [options]`,
|
|
722
|
-
'',
|
|
723
|
-
group === 'system'
|
|
724
|
-
? `提示:system 是命令组;下面的命令可直接运行,例如 ${commandPrefix()} doctor。`
|
|
725
|
-
: `提示:${group} 是命令组;请选择下面的子命令运行。`,
|
|
726
|
-
'',
|
|
727
|
-
'Commands:',
|
|
1335
|
+
helpHeading('Usage:'),
|
|
728
1336
|
];
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
1337
|
+
if (group === 'system') {
|
|
1338
|
+
lines.push(helpCommand(` ${commandPrefix()} <command> [options]`));
|
|
1339
|
+
} else if (hasSubgroups) {
|
|
1340
|
+
if (directItems.length) lines.push(helpCommand(` ${commandPrefix()} ${group} <command> [options]`));
|
|
1341
|
+
lines.push(helpCommand(` ${commandPrefix()} ${group} <subdomain> <command> [options]`));
|
|
1342
|
+
} else {
|
|
1343
|
+
lines.push(helpCommand(` ${commandPrefix()} ${group} <command> [options]`));
|
|
1344
|
+
}
|
|
1345
|
+
lines.push('');
|
|
1346
|
+
if (group === 'system') {
|
|
1347
|
+
lines.push(helpMuted(`提示:system 是命令组;下面的命令可直接运行,例如 ${commandPrefix()} doctor。`));
|
|
1348
|
+
} else if (hasSubgroups) {
|
|
1349
|
+
lines.push(helpMuted(`提示:${group} 下按子领域分组;先选子领域再看具体命令。`));
|
|
1350
|
+
} else {
|
|
1351
|
+
lines.push(helpMuted(`提示:${group} 是命令组;请选择下面的子命令运行。`));
|
|
1352
|
+
}
|
|
1353
|
+
lines.push('');
|
|
1354
|
+
|
|
1355
|
+
if (hasSubgroups) {
|
|
1356
|
+
const presentSubgroups = new Set(
|
|
1357
|
+
items
|
|
1358
|
+
.map((command) => commandSubgroupTokens(command))
|
|
1359
|
+
.filter(Boolean)
|
|
1360
|
+
.map(([, subgroup]) => subgroup),
|
|
1361
|
+
);
|
|
1362
|
+
lines.push(helpHeading('Subdomains:'));
|
|
1363
|
+
for (const [subgroup, description] of Object.entries(subgroupMap)) {
|
|
1364
|
+
if (!presentSubgroups.has(subgroup)) continue;
|
|
1365
|
+
lines.push(` ${helpGroup(subgroup.padEnd(10))} ${description}`);
|
|
1366
|
+
}
|
|
1367
|
+
if (directItems.length) {
|
|
1368
|
+
lines.push('', helpHeading('Commands:'));
|
|
1369
|
+
for (const command of directItems) {
|
|
1370
|
+
const subcommand = commandSubcommand(command);
|
|
1371
|
+
lines.push(` ${helpCommand(subcommand.padEnd(28))} ${summaryOf(command)}`);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
} else {
|
|
1375
|
+
lines.push(helpHeading('Commands:'));
|
|
1376
|
+
for (const command of items) {
|
|
1377
|
+
const subcommand = commandSubcommand(command);
|
|
1378
|
+
lines.push(` ${helpCommand(subcommand.padEnd(28))} ${summaryOf(command)}`);
|
|
1379
|
+
}
|
|
732
1380
|
}
|
|
1381
|
+
|
|
733
1382
|
if (GROUP_EXAMPLES[group]?.length) {
|
|
734
|
-
lines.push('', 'Examples:');
|
|
1383
|
+
lines.push('', helpHeading('Examples:'));
|
|
735
1384
|
for (const example of GROUP_EXAMPLES[group]) {
|
|
736
|
-
lines.push(` ${renderCliText(example)}`);
|
|
1385
|
+
lines.push(helpCommand(` ${renderCliText(example)}`));
|
|
737
1386
|
}
|
|
738
1387
|
}
|
|
739
|
-
lines.push('', 'More help:');
|
|
1388
|
+
lines.push('', helpHeading('More help:'));
|
|
740
1389
|
if (group === 'system') {
|
|
741
|
-
for (const command of items) lines.push(` ${commandPrefix()} ${command.name} -h`);
|
|
1390
|
+
for (const command of items) lines.push(helpCommand(` ${commandPrefix()} ${command.name} -h`));
|
|
1391
|
+
} else if (hasSubgroups) {
|
|
1392
|
+
lines.push(helpCommand(` ${commandPrefix()} ${group} <subdomain> -h`));
|
|
1393
|
+
lines.push(helpCommand(` ${commandPrefix()} ${group} <subdomain> <command> -h`));
|
|
742
1394
|
} else {
|
|
743
|
-
lines.push(` ${commandPrefix()} ${group} <command> -h`);
|
|
1395
|
+
lines.push(helpCommand(` ${commandPrefix()} ${group} <command> -h`));
|
|
1396
|
+
}
|
|
1397
|
+
process.stdout.write(`${lines.join('\n')}\n`);
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
function printSubgroupHelp(group, subgroup, commands, version) {
|
|
1401
|
+
const items = commands.filter((command) => {
|
|
1402
|
+
const tokens = commandSubgroupTokens(command);
|
|
1403
|
+
return tokens && tokens[0] === group && tokens[1] === subgroup;
|
|
1404
|
+
});
|
|
1405
|
+
const description = SUBGROUP_DESCRIPTIONS[group]?.[subgroup] || `${group} ${subgroup} 子领域`;
|
|
1406
|
+
const lines = [
|
|
1407
|
+
helpTitle(`lj-awb v${version}`),
|
|
1408
|
+
'',
|
|
1409
|
+
description,
|
|
1410
|
+
'',
|
|
1411
|
+
helpHeading('Usage:'),
|
|
1412
|
+
helpCommand(` ${commandPrefix()} ${group} ${subgroup} <command> [options]`),
|
|
1413
|
+
'',
|
|
1414
|
+
helpHeading('Commands:'),
|
|
1415
|
+
];
|
|
1416
|
+
for (const command of items) {
|
|
1417
|
+
const parts = String(command.name || '').split(' ').filter(Boolean);
|
|
1418
|
+
const tail = parts.slice(2).join(' ');
|
|
1419
|
+
lines.push(` ${helpCommand(tail.padEnd(28))} ${summaryOf(command)}`);
|
|
1420
|
+
}
|
|
1421
|
+
const examples = SUBGROUP_EXAMPLES[`${group} ${subgroup}`];
|
|
1422
|
+
if (examples?.length) {
|
|
1423
|
+
lines.push('', helpHeading('Examples:'));
|
|
1424
|
+
for (const example of examples) {
|
|
1425
|
+
lines.push(helpCommand(` ${renderCliText(example)}`));
|
|
1426
|
+
}
|
|
744
1427
|
}
|
|
1428
|
+
lines.push('', helpHeading('More help:'));
|
|
1429
|
+
lines.push(helpCommand(` ${commandPrefix()} ${group} ${subgroup} <command> -h`));
|
|
745
1430
|
process.stdout.write(`${lines.join('\n')}\n`);
|
|
746
1431
|
}
|
|
747
1432
|
|
|
748
1433
|
function printCommandHelp(command) {
|
|
749
|
-
const lines = [`Usage: ${commandPrefix()} ${command.name} [options]
|
|
1434
|
+
const lines = [helpHeading(`Usage: ${commandPrefix()} ${command.name} [options]`), '', renderCliText(command.description || '')];
|
|
750
1435
|
if (command.args?.length) {
|
|
751
|
-
lines.push('', 'Options:');
|
|
1436
|
+
lines.push('', helpHeading('Options:'));
|
|
752
1437
|
for (const arg of command.args) {
|
|
753
1438
|
const value = arg.valueName ? ` <${arg.valueName}>` : '';
|
|
754
1439
|
const description = arg.description ? ` ${arg.description}` : '';
|
|
755
|
-
lines.push(`
|
|
1440
|
+
lines.push(` ${helpOption(`--${arg.name}${value}`)}${description}`);
|
|
756
1441
|
}
|
|
757
1442
|
}
|
|
758
|
-
lines.push(
|
|
1443
|
+
lines.push(
|
|
1444
|
+
'',
|
|
1445
|
+
helpHeading('Global options:'),
|
|
1446
|
+
` ${helpOption('-f, --format <format>')} 输出格式:pretty(默认)、text、json、yaml、csv、auto`,
|
|
1447
|
+
` ${helpOption('--json'.padEnd(22))} 等同于 -f json`,
|
|
1448
|
+
);
|
|
759
1449
|
process.stdout.write(`${lines.join('\n')}\n`);
|
|
760
1450
|
}
|
|
761
1451
|
|
|
762
|
-
function validateCommandOptions(command, kwargs) {
|
|
763
|
-
const
|
|
1452
|
+
function validateCommandOptions(command, kwargs, kwargRawFlags = {}) {
|
|
1453
|
+
const allowedKeys = (command.args || []).map((arg) => normalizeKey(arg.name));
|
|
1454
|
+
const allowed = new Set(allowedKeys);
|
|
764
1455
|
const unknown = Object.keys(kwargs).filter((key) => !allowed.has(key));
|
|
765
1456
|
if (!unknown.length) return;
|
|
766
|
-
|
|
1457
|
+
const displayFlag = (key) => kwargRawFlags[key] || formatOptionName(key);
|
|
1458
|
+
const suggestions = {};
|
|
1459
|
+
for (const unk of unknown) {
|
|
1460
|
+
const matches = suggestSimilarOptions(unk, allowedKeys);
|
|
1461
|
+
if (matches.length) suggestions[displayFlag(unk)] = matches;
|
|
1462
|
+
}
|
|
1463
|
+
const usedShortForm = unknown.some((key) => {
|
|
1464
|
+
const flag = kwargRawFlags[key];
|
|
1465
|
+
return flag && flag.startsWith('-') && !flag.startsWith('--');
|
|
1466
|
+
});
|
|
1467
|
+
const baseHint = `运行 ${commandPrefix()} ${command.name} -h 查看可用参数。`;
|
|
1468
|
+
const shortHint = usedShortForm
|
|
1469
|
+
? `本 CLI 仅支持 -f / -h / -v 等少数短选项,业务参数请使用 --xxx 长形式。`
|
|
1470
|
+
: '';
|
|
1471
|
+
const suggestionParts = Object.entries(suggestions).map(([opt, matches]) => `${opt} → ${matches.join(' / ')}`);
|
|
1472
|
+
const hintParts = [];
|
|
1473
|
+
if (suggestionParts.length) hintParts.push(`你是不是想用:${suggestionParts.join(';')}?`);
|
|
1474
|
+
if (shortHint) hintParts.push(shortHint);
|
|
1475
|
+
hintParts.push(baseHint);
|
|
1476
|
+
throw new LingjingAwbCliError(`未知参数:${unknown.map(displayFlag).join(', ')}`, {
|
|
767
1477
|
type: 'unknown_option',
|
|
768
1478
|
exitCode: 2,
|
|
769
|
-
hint:
|
|
1479
|
+
hint: hintParts.join(' '),
|
|
770
1480
|
details: {
|
|
771
1481
|
command: command.name,
|
|
772
|
-
unknownOptions: unknown.map(
|
|
1482
|
+
unknownOptions: unknown.map(displayFlag),
|
|
1483
|
+
...(Object.keys(suggestions).length ? { suggestions } : {}),
|
|
773
1484
|
},
|
|
774
1485
|
});
|
|
775
1486
|
}
|
|
776
1487
|
|
|
777
1488
|
function printData(data, format, meta = {}, context = {}) {
|
|
778
|
-
|
|
1489
|
+
const outputFormat = resolveOutputFormat(format);
|
|
1490
|
+
if (outputFormat === 'json') {
|
|
779
1491
|
process.stdout.write(`${JSON.stringify(createEnvelope({ status: 'success', data: normalizeJsonData(meta.command, data), meta }), null, 2)}\n`);
|
|
780
1492
|
return;
|
|
781
1493
|
}
|
|
782
|
-
|
|
1494
|
+
if (outputFormat === 'yaml') {
|
|
1495
|
+
process.stdout.write(formatYamlEnvelope(createEnvelope({ status: 'success', data: normalizeJsonData(meta.command, data), meta })));
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
if (outputFormat === 'csv') {
|
|
1499
|
+
process.stdout.write(formatCsvOutput(meta.command, data, context));
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1502
|
+
if (outputFormat === 'text') {
|
|
1503
|
+
process.stdout.write(formatTextOutput(meta.command, data, context));
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
process.stdout.write(formatPrettyOutput(meta.command, data, context));
|
|
783
1507
|
}
|
|
784
1508
|
|
|
785
1509
|
function printError(error, format, meta = {}) {
|
|
1510
|
+
let outputFormat = 'text';
|
|
1511
|
+
try {
|
|
1512
|
+
outputFormat = resolveOutputFormat(format);
|
|
1513
|
+
} catch {
|
|
1514
|
+
outputFormat = 'text';
|
|
1515
|
+
}
|
|
786
1516
|
const payload = {
|
|
787
1517
|
type: error.type || 'error',
|
|
788
1518
|
message: error.message || String(error),
|
|
789
1519
|
...(error.hint ? { hint: error.hint } : {}),
|
|
790
1520
|
...(error.details ? { details: error.details } : {}),
|
|
791
1521
|
};
|
|
792
|
-
if (
|
|
1522
|
+
if (outputFormat === 'json') {
|
|
793
1523
|
process.stderr.write(`${JSON.stringify(createEnvelope({ status: 'error', error: payload, meta }), null, 2)}\n`);
|
|
1524
|
+
} else if (outputFormat === 'yaml') {
|
|
1525
|
+
process.stderr.write(formatYamlEnvelope(createEnvelope({ status: 'error', error: payload, meta })));
|
|
1526
|
+
} else if (outputFormat === 'pretty') {
|
|
1527
|
+
process.stderr.write(formatPrettyError(payload));
|
|
794
1528
|
} else {
|
|
795
1529
|
process.stderr.write(formatTextError(payload));
|
|
796
1530
|
}
|
|
@@ -807,10 +1541,20 @@ export async function runStandaloneCli(argv = process.argv.slice(2)) {
|
|
|
807
1541
|
const command = commands.find((item) => item.name === resolvedCommandName);
|
|
808
1542
|
if (command) {
|
|
809
1543
|
printCommandHelp(command);
|
|
1544
|
+
} else if (isCommandSubgroupName(parsed.commandName, commands)) {
|
|
1545
|
+
const [group, subgroup] = parsed.commandName.split(' ');
|
|
1546
|
+
printSubgroupHelp(group, subgroup, commands, version);
|
|
810
1547
|
} else if (isCommandGroupName(parsed.commandName, commands)) {
|
|
811
1548
|
printGroupHelp(parsed.commandName, commands, version);
|
|
812
|
-
} else {
|
|
1549
|
+
} else if (!parsed.commandName) {
|
|
813
1550
|
printRootHelp(commands, version);
|
|
1551
|
+
} else {
|
|
1552
|
+
printError(new LingjingAwbCliError(`未知命令: ${parsed.commandName}`, {
|
|
1553
|
+
type: 'unknown_command',
|
|
1554
|
+
exitCode: 2,
|
|
1555
|
+
hint: unknownCommandHint(parsed.commandName),
|
|
1556
|
+
}), parsed.format, { command: parsed.commandName });
|
|
1557
|
+
process.exitCode = 2;
|
|
814
1558
|
}
|
|
815
1559
|
return;
|
|
816
1560
|
}
|
|
@@ -820,10 +1564,15 @@ export async function runStandaloneCli(argv = process.argv.slice(2)) {
|
|
|
820
1564
|
return;
|
|
821
1565
|
}
|
|
822
1566
|
|
|
823
|
-
const { commandName: rawCommandName, kwargs, format } = parseArgv(argv);
|
|
1567
|
+
const { commandName: rawCommandName, kwargs, kwargRawFlags, format } = parseArgv(argv);
|
|
824
1568
|
const commandName = resolveCommandName(rawCommandName, commands);
|
|
825
1569
|
const command = commands.find((item) => item.name === commandName);
|
|
826
1570
|
if (!command) {
|
|
1571
|
+
if (isCommandSubgroupName(rawCommandName, commands)) {
|
|
1572
|
+
const [group, subgroup] = rawCommandName.split(' ');
|
|
1573
|
+
printSubgroupHelp(group, subgroup, commands, version);
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
827
1576
|
if (isCommandGroupName(rawCommandName, commands)) {
|
|
828
1577
|
printGroupHelp(rawCommandName, commands, version);
|
|
829
1578
|
return;
|
|
@@ -839,11 +1588,12 @@ export async function runStandaloneCli(argv = process.argv.slice(2)) {
|
|
|
839
1588
|
|
|
840
1589
|
const startedAt = Date.now();
|
|
841
1590
|
try {
|
|
842
|
-
|
|
1591
|
+
const outputFormat = resolveOutputFormat(format);
|
|
1592
|
+
validateCommandOptions(command, kwargs, kwargRawFlags);
|
|
843
1593
|
const data = command.virtual === 'schema'
|
|
844
1594
|
? buildCommandSchema(commands, kwargs, version)
|
|
845
1595
|
: await command.func({ command }, kwargs);
|
|
846
|
-
printData(data,
|
|
1596
|
+
printData(data, outputFormat, { command: command.name, elapsedMs: Date.now() - startedAt }, buildOutputContext(command, kwargs));
|
|
847
1597
|
} catch (error) {
|
|
848
1598
|
const cliError = error instanceof LingjingAwbCliError
|
|
849
1599
|
? error
|