@lingjingai/lj-awb-cli 0.3.11

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.
Files changed (36) hide show
  1. package/README.md +314 -0
  2. package/install.mjs +41 -0
  3. package/package.json +40 -0
  4. package/packages/awb-cli/README.md +19 -0
  5. package/packages/awb-cli/bin/lj-awb +19 -0
  6. package/packages/awb-cli/bin/lj-awb.js +11 -0
  7. package/packages/awb-cli/package.json +18 -0
  8. package/packages/awb-core/README.md +12 -0
  9. package/packages/awb-core/package.json +20 -0
  10. package/packages/awb-core/src/api.js +349 -0
  11. package/packages/awb-core/src/auth.js +80 -0
  12. package/packages/awb-core/src/commands.js +817 -0
  13. package/packages/awb-core/src/common.js +508 -0
  14. package/packages/awb-core/src/output.js +758 -0
  15. package/packages/awb-core/src/services.js +2966 -0
  16. package/packages/awb-core/src/standalone.js +820 -0
  17. package/skills/lj-awb/SKILL.md +97 -0
  18. package/skills/lj-awb/VERSION +1 -0
  19. package/skills/lj-awb/compat.json +6 -0
  20. package/skills/lj-awb/modules/account.md +17 -0
  21. package/skills/lj-awb/modules/asset.md +21 -0
  22. package/skills/lj-awb/modules/auth.md +23 -0
  23. package/skills/lj-awb/modules/create-contract.md +112 -0
  24. package/skills/lj-awb/modules/credits.md +20 -0
  25. package/skills/lj-awb/modules/evals.md +152 -0
  26. package/skills/lj-awb/modules/image.md +58 -0
  27. package/skills/lj-awb/modules/model.md +96 -0
  28. package/skills/lj-awb/modules/project.md +24 -0
  29. package/skills/lj-awb/modules/subject.md +22 -0
  30. package/skills/lj-awb/modules/task-manual.md +142 -0
  31. package/skills/lj-awb/modules/task.md +19 -0
  32. package/skills/lj-awb/modules/upload.md +18 -0
  33. package/skills/lj-awb/modules/video.md +81 -0
  34. package/skills/lj-awb/modules/workflows.md +223 -0
  35. package/skills/lj-awb/references/model-options-read.md +43 -0
  36. package/skills/lj-awb/scripts/resolve-lj-awb-cmd.sh +10 -0
@@ -0,0 +1,758 @@
1
+ function isPlainObject(value) {
2
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
3
+ }
4
+
5
+ function compactRecord(record) {
6
+ const result = {};
7
+ for (const [key, value] of Object.entries(record || {})) {
8
+ if (value === undefined || value === null || value === '') continue;
9
+ result[key] = value;
10
+ }
11
+ return result;
12
+ }
13
+
14
+ function commandPrefix() {
15
+ return process.env.LINGJING_AWB_COMMAND_PREFIX || 'lj-awb';
16
+ }
17
+
18
+ function rewriteCommandPrefix(value) {
19
+ if (typeof value !== 'string') return value;
20
+ return value.replace(/\blj-awb\b/g, commandPrefix());
21
+ }
22
+
23
+ function cleanNested(value) {
24
+ if (Array.isArray(value)) return value.map((item) => cleanNested(item));
25
+ if (!isPlainObject(value)) return rewriteCommandPrefix(value);
26
+ const result = {};
27
+ for (const [key, item] of Object.entries(value)) {
28
+ if (['updatedAt', 'updatedAtText'].includes(key)) continue;
29
+ if (item === undefined) continue;
30
+ result[key] = cleanNested(item);
31
+ }
32
+ return result;
33
+ }
34
+
35
+ function rewriteNested(value) {
36
+ if (Array.isArray(value)) return value.map((item) => rewriteNested(item));
37
+ if (!isPlainObject(value)) return rewriteCommandPrefix(value);
38
+ const result = {};
39
+ for (const [key, item] of Object.entries(value)) {
40
+ if (item === undefined) continue;
41
+ result[key] = rewriteNested(item);
42
+ }
43
+ return result;
44
+ }
45
+
46
+ function requestSummary(request = {}) {
47
+ const promptParams = request.promptParams || {};
48
+ return compactRecord({
49
+ requestSource: request.requestSource,
50
+ modelGroupCode: request.modelGroupCode,
51
+ projectGroupNo: request.projectGroupNo,
52
+ customBizId: request.customBizId,
53
+ prompt: promptParams.prompt,
54
+ ratio: promptParams.ratio,
55
+ quality: promptParams.quality,
56
+ duration: promptParams.duration,
57
+ needAudio: promptParams.need_audio,
58
+ generateNum: promptParams.generate_num,
59
+ resourceCount: Array.isArray(promptParams.resources) ? promptParams.resources.length : undefined,
60
+ });
61
+ }
62
+
63
+ function scalarRequestSummary(request = {}) {
64
+ if (!isPlainObject(request)) return {};
65
+ const result = {};
66
+ for (const [key, value] of Object.entries(request)) {
67
+ if (value === undefined || value === null || value === '') continue;
68
+ if (Array.isArray(value) || isPlainObject(value)) continue;
69
+ result[key] = value;
70
+ }
71
+ return result;
72
+ }
73
+
74
+ function scalarDataSummary(data = {}) {
75
+ if (!isPlainObject(data)) return {};
76
+ const excluded = new Set([
77
+ 'request',
78
+ 'files',
79
+ 'assets',
80
+ 'localFile',
81
+ 'localFiles',
82
+ 'results',
83
+ 'raw',
84
+ 'subject',
85
+ 'upload',
86
+ 'uploads',
87
+ 'waited',
88
+ 'data',
89
+ ]);
90
+ const result = {};
91
+ for (const [key, value] of Object.entries(data)) {
92
+ if (excluded.has(key)) continue;
93
+ if (value === undefined || value === null || value === '') continue;
94
+ if (Array.isArray(value) || isPlainObject(value)) continue;
95
+ result[key] = value;
96
+ }
97
+ return result;
98
+ }
99
+
100
+ function normalizeAuthStatus(data = {}) {
101
+ return compactRecord({
102
+ configured: data.loginState === '已配置',
103
+ authType: data.authType,
104
+ accessKey: data.accessKey,
105
+ source: [data.accessKeySource, data.accessKeySourceName].filter(Boolean).join('/'),
106
+ verified: data.verified,
107
+ user: data.user,
108
+ });
109
+ }
110
+
111
+ function normalizeAuthLogin(data = {}) {
112
+ return compactRecord({
113
+ saved: data.saved ?? Boolean(data.auth || data.accessKey),
114
+ verified: data.verified,
115
+ accessKey: data.accessKey || data.auth?.accessKey,
116
+ source: data.auth ? [data.auth.accessKeySource, data.auth.accessKeySourceName].filter(Boolean).join('/') : undefined,
117
+ user: data.user,
118
+ dryRun: data.dryRun,
119
+ });
120
+ }
121
+
122
+ function normalizeDryRunResult(row = {}) {
123
+ if (!isPlainObject(row) || !row.dryRun) return cleanNested(row);
124
+ const localFiles = Array.isArray(row.localFiles) ? row.localFiles : (row.localFile ? [row.localFile] : []);
125
+ return compactRecord({
126
+ ...scalarDataSummary(row),
127
+ ...scalarRequestSummary(row.request),
128
+ ...requestSummary(row.request),
129
+ localFileCount: localFiles.length || undefined,
130
+ fileCount: Array.isArray(row.files) ? row.files.length : undefined,
131
+ assetCount: Array.isArray(row.assets) ? row.assets.length : undefined,
132
+ });
133
+ }
134
+
135
+ function normalizeDryRun(data = {}) {
136
+ const localFiles = Array.isArray(data.localFiles) ? data.localFiles : (data.localFile ? [data.localFile] : undefined);
137
+ return compactRecord({
138
+ dryRun: true,
139
+ action: data.action,
140
+ ...scalarDataSummary(data),
141
+ ...scalarRequestSummary(data.request),
142
+ ...requestSummary(data.request),
143
+ localFileCount: Array.isArray(localFiles) ? localFiles.length : undefined,
144
+ fileCount: Array.isArray(data.files) ? data.files.length : undefined,
145
+ assetCount: Array.isArray(data.assets) ? data.assets.length : undefined,
146
+ files: data.files,
147
+ assets: data.assets,
148
+ localFiles,
149
+ results: Array.isArray(data.results) ? data.results.map((row) => normalizeDryRunResult(row)) : data.results,
150
+ nextRefSubject: data.nextRefSubject,
151
+ });
152
+ }
153
+
154
+ function normalizeTaskSubmission(data = {}) {
155
+ return compactRecord({
156
+ taskId: data.taskId,
157
+ taskType: data.taskType,
158
+ modelGroupCode: data.modelGroupCode,
159
+ projectGroupNo: data.projectGroupNo,
160
+ pointNo: data.pointNo,
161
+ points: data.points ?? data.point ?? data.costPoint ?? data.estimatePoint,
162
+ uploadCount: Array.isArray(data.uploads) ? data.uploads.length : undefined,
163
+ nextCommand: rewriteCommandPrefix(data.nextCommand),
164
+ waited: data.waited ? normalizeTaskStatus(data.waited) : undefined,
165
+ });
166
+ }
167
+
168
+ function normalizeSubtitleSubmission(data = {}) {
169
+ return compactRecord({
170
+ submitted: data.submitted,
171
+ remoteTaskId: data.remoteTaskId,
172
+ publicId: data.publicId,
173
+ });
174
+ }
175
+
176
+ function normalizeFee(data = {}) {
177
+ return compactRecord({
178
+ modelGroupCode: data.modelGroupCode,
179
+ projectGroupNo: data.projectGroupNo,
180
+ pointCost: data.pointCost,
181
+ teamPointBalance: data.teamPointBalance,
182
+ projectPointBalance: data.projectPointBalance,
183
+ projectPointMax: data.projectPointMax,
184
+ teamPointRemainingAfter: data.teamPointRemainingAfter,
185
+ projectPointRemainingAfter: data.projectPointRemainingAfter,
186
+ });
187
+ }
188
+
189
+ function normalizeAccountInfo(data = {}) {
190
+ return compactRecord({
191
+ userId: data.userId,
192
+ userName: data.userName,
193
+ groupId: data.groupId,
194
+ groupName: data.groupName,
195
+ currentProjectGroupNo: data.currentProjectGroupNo,
196
+ currentProjectGroupName: data.currentProjectGroupName,
197
+ teamPointBalance: data.teamPointBalance,
198
+ projectPointBalance: data.projectPointBalance,
199
+ projectPointMax: data.projectPointMax,
200
+ });
201
+ }
202
+
203
+ function normalizeCredits(data = {}) {
204
+ return compactRecord({
205
+ teamPointBalance: data.teamPointBalance,
206
+ currentProjectGroupNo: data.currentProjectGroupNo,
207
+ currentProjectGroupName: data.currentProjectGroupName,
208
+ projectPointBalance: data.projectPointBalance,
209
+ projectPointMax: data.projectPointMax,
210
+ });
211
+ }
212
+
213
+ function normalizeCreditsUsage(data = {}) {
214
+ const buckets = isPlainObject(data.buckets)
215
+ ? Object.entries(data.buckets).map(([taskType, bucket]) => compactRecord({
216
+ taskType,
217
+ taskCount: bucket?.taskCount,
218
+ successTaskCount: bucket?.successTaskCount,
219
+ resultCount: bucket?.resultCount,
220
+ pointTotal: bucket?.pointTotal,
221
+ }))
222
+ : undefined;
223
+ return compactRecord({
224
+ projectGroupNo: data.projectGroupNo,
225
+ sinceMs: data.sinceMs,
226
+ sinceText: data.sinceText,
227
+ untilMs: data.untilMs,
228
+ untilText: data.untilText,
229
+ scannedTaskCount: data.scannedTaskCount,
230
+ pointTotal: data.pointTotal,
231
+ buckets,
232
+ tasks: data.tasks,
233
+ });
234
+ }
235
+
236
+ function normalizeTaskStatus(data = {}) {
237
+ return compactRecord({
238
+ taskId: data.taskId,
239
+ publicId: data.publicId,
240
+ remoteTaskId: data.remoteTaskId,
241
+ taskType: data.taskType,
242
+ taskStatus: data.taskStatus,
243
+ isTerminal: data.isTerminal,
244
+ modelGroupCode: data.modelGroupCode,
245
+ projectGroupNo: data.projectGroupNo,
246
+ pointNo: data.pointNo,
247
+ gmtCreate: data.gmtCreate,
248
+ resultCount: data.resultCount,
249
+ resultUrls: data.resultUrls,
250
+ originUrls: data.originUrls,
251
+ errorMessage: data.errorMessage,
252
+ timedOut: data.timedOut,
253
+ waitedMs: data.waitedMs,
254
+ });
255
+ }
256
+
257
+ function normalizeSubject(data = {}) {
258
+ return compactRecord({
259
+ created: data.created,
260
+ name: data.name,
261
+ elementId: data.elementId,
262
+ subjectId: data.subjectId,
263
+ externalId: data.externalId,
264
+ status: data.status,
265
+ nextRefSubject: data.nextRefSubject,
266
+ });
267
+ }
268
+
269
+ function normalizeAsset(data = {}) {
270
+ return compactRecord({
271
+ created: data.created,
272
+ updated: data.updated,
273
+ registered: data.registered,
274
+ groupId: data.groupId,
275
+ assetId: data.assetId,
276
+ name: data.name,
277
+ projectName: data.projectName,
278
+ assetPath: data.assetPath,
279
+ uploadBackendPath: data.upload?.backendPath,
280
+ uploadUrl: data.upload?.url,
281
+ });
282
+ }
283
+
284
+ function normalizeList(data = {}, keys) {
285
+ const key = keys.find((item) => Array.isArray(data[item]));
286
+ if (!key) return cleanNested(data);
287
+ return compactRecord({
288
+ count: data.count ?? data[key].length,
289
+ [key]: data[key],
290
+ ...Object.fromEntries(Object.entries(data).filter(([item]) => ![key, 'raw'].includes(item))),
291
+ });
292
+ }
293
+
294
+ export function normalizeOutputData(commandName, data) {
295
+ if (!isPlainObject(data)) return cleanNested(data);
296
+ switch (commandName) {
297
+ case 'auth status':
298
+ return normalizeAuthStatus(data);
299
+ case 'auth login-key':
300
+ return normalizeAuthLogin(data);
301
+ default:
302
+ break;
303
+ }
304
+ if (data.dryRun) return normalizeDryRun(data);
305
+ switch (commandName) {
306
+ case 'image create':
307
+ case 'video create':
308
+ return normalizeTaskSubmission(data);
309
+ case 'video subtitle-remove':
310
+ return normalizeSubtitleSubmission(data);
311
+ case 'image fee':
312
+ case 'video fee':
313
+ return normalizeFee(data);
314
+ case 'account info':
315
+ return normalizeAccountInfo(data);
316
+ case 'credits balance':
317
+ return normalizeCredits(data);
318
+ case 'credits usage':
319
+ return normalizeCreditsUsage(data);
320
+ case 'image status':
321
+ case 'video status':
322
+ case 'task wait':
323
+ case 'video subtitle-status':
324
+ return normalizeTaskStatus(data);
325
+ case 'subject publish':
326
+ case 'subject wait':
327
+ return normalizeSubject(data);
328
+ case 'asset group-create':
329
+ case 'asset group-update':
330
+ case 'asset register':
331
+ return normalizeAsset(data);
332
+ case 'model image-models':
333
+ case 'model video-models':
334
+ return normalizeList(data, ['models', 'items', 'rows']);
335
+ case 'account teams':
336
+ return normalizeList(data, ['teams']);
337
+ case 'project list':
338
+ return normalizeList(data, ['projectGroups']);
339
+ case 'project users':
340
+ return normalizeList(data, ['users']);
341
+ case 'task list':
342
+ return normalizeList(data, ['tasks']);
343
+ case 'task records':
344
+ return normalizeList(data, ['records']);
345
+ case 'asset group-list':
346
+ return normalizeList(data, ['groups']);
347
+ case 'asset match-actor':
348
+ return normalizeList(data, ['matches']);
349
+ case 'subject list':
350
+ return normalizeList(data, ['subjects']);
351
+ default:
352
+ return cleanNested(data);
353
+ }
354
+ }
355
+
356
+ export function normalizeJsonData(commandName, data) {
357
+ if (!isPlainObject(data)) return rewriteNested(data);
358
+ switch (commandName) {
359
+ case 'auth status':
360
+ return normalizeAuthStatus(data);
361
+ case 'auth login-key':
362
+ return normalizeAuthLogin(data);
363
+ default:
364
+ return rewriteNested(data);
365
+ }
366
+ }
367
+
368
+ function shortValue(value) {
369
+ if (Array.isArray(value)) {
370
+ if (value.every((item) => !isPlainObject(item) && !Array.isArray(item))) return valueList(value, 8) || '[]';
371
+ return `[${value.length}]`;
372
+ }
373
+ if (isPlainObject(value)) return '{...}';
374
+ const text = String(value);
375
+ if (/\s/.test(text)) return JSON.stringify(text.length > 96 ? `${text.slice(0, 93)}...` : text);
376
+ return text.length > 120 ? `${text.slice(0, 117)}...` : text;
377
+ }
378
+
379
+ function valueList(values, limit = 12) {
380
+ if (!Array.isArray(values) || !values.length) return undefined;
381
+ const items = values
382
+ .map((item) => {
383
+ if (!isPlainObject(item)) return item;
384
+ return item.enumValue ?? item.value ?? item.label ?? item.enumName ?? item.name;
385
+ })
386
+ .filter((item) => item !== undefined && item !== null && item !== '');
387
+ if (!items.length) return undefined;
388
+ const visible = items.slice(0, limit).join('|');
389
+ return items.length > limit ? `${visible}|...(+${items.length - limit})` : visible;
390
+ }
391
+
392
+ function renderRecord(record, preferredKeys = [], excludedKeys = []) {
393
+ const excluded = new Set(excludedKeys);
394
+ const keys = [
395
+ ...preferredKeys.filter((key) => !excluded.has(key) && record[key] !== undefined),
396
+ ...Object.keys(record).filter((key) => !excluded.has(key) && !preferredKeys.includes(key) && !Array.isArray(record[key]) && !isPlainObject(record[key])),
397
+ ];
398
+ return keys.map((key) => `${key}=${shortValue(record[key])}`).join(' ');
399
+ }
400
+
401
+ function firstList(data) {
402
+ for (const [key, value] of Object.entries(data || {})) {
403
+ if (['resultUrls', 'originUrls'].includes(key)) continue;
404
+ if (Array.isArray(value)) return { key, rows: value };
405
+ }
406
+ return null;
407
+ }
408
+
409
+ function rowSummary(row) {
410
+ if (!isPlainObject(row)) return shortValue(row);
411
+ const keys = [
412
+ 'id',
413
+ 'taskId',
414
+ 'publicId',
415
+ 'remoteTaskId',
416
+ 'taskType',
417
+ 'modelGroupCode',
418
+ 'provider',
419
+ 'displayName',
420
+ 'modelStatus',
421
+ 'taskQueueNum',
422
+ 'feeCalcType',
423
+ 'inputModes',
424
+ 'params',
425
+ 'name',
426
+ 'status',
427
+ 'message',
428
+ 'title',
429
+ 'description',
430
+ 'groupId',
431
+ 'groupName',
432
+ 'projectGroupNo',
433
+ 'projectGroupName',
434
+ 'isSelected',
435
+ 'userId',
436
+ 'userName',
437
+ 'role',
438
+ 'isCheck',
439
+ 'currentGroup',
440
+ 'dryRun',
441
+ 'action',
442
+ 'created',
443
+ 'updated',
444
+ 'registered',
445
+ 'submitted',
446
+ 'selected',
447
+ 'reused',
448
+ 'cleared',
449
+ 'memberCount',
450
+ 'taskStatus',
451
+ 'taskCount',
452
+ 'successTaskCount',
453
+ 'pointTotal',
454
+ 'projectPointBalance',
455
+ 'projectPointMax',
456
+ 'teamPointBalance',
457
+ 'assetId',
458
+ 'partType',
459
+ 'score',
460
+ 'imageUrl',
461
+ 'subjectId',
462
+ 'elementId',
463
+ 'externalId',
464
+ 'label',
465
+ 'assetPath',
466
+ 'isPrimary',
467
+ 'referenceType',
468
+ 'resultCount',
469
+ 'promptSummary',
470
+ 'recordedAt',
471
+ 'gmtCreate',
472
+ 'gmtModified',
473
+ 'createdAt',
474
+ 'filePath',
475
+ 'fileName',
476
+ 'exists',
477
+ 'size',
478
+ 'mime',
479
+ 'mimeType',
480
+ 'width',
481
+ 'height',
482
+ 'format',
483
+ 'backendPath',
484
+ 'url',
485
+ 'sceneType',
486
+ 'projectName',
487
+ 'inputIndex',
488
+ 'key',
489
+ 'requestSource',
490
+ 'prompt',
491
+ 'ratio',
492
+ 'quality',
493
+ 'duration',
494
+ 'needAudio',
495
+ 'generateNum',
496
+ 'resourceCount',
497
+ 'paramKey',
498
+ 'cliArg',
499
+ 'paramName',
500
+ 'paramType',
501
+ 'meaning',
502
+ ];
503
+ return keys
504
+ .filter((key) => {
505
+ const value = row[key];
506
+ if (value === undefined || value === null || value === '') return false;
507
+ if (Array.isArray(value) && value.length === 0) return false;
508
+ return true;
509
+ })
510
+ .map((key) => `${key}=${shortValue(row[key])}`)
511
+ .join(' ');
512
+ }
513
+
514
+ function textSources(values = []) {
515
+ const names = {
516
+ local_file: 'file',
517
+ http_url: 'url',
518
+ backendPath: 'platformPath',
519
+ asset_id: 'asset',
520
+ };
521
+ return valueList((Array.isArray(values) ? values : []).map((item) => names[item] || item));
522
+ }
523
+
524
+ function textFileCount(item = {}) {
525
+ if (item.minFiles != null && item.maxFiles != null && item.minFiles === item.maxFiles) return String(item.maxFiles);
526
+ if (item.minFiles != null && item.maxFiles != null) return `${item.minFiles}..${item.maxFiles}`;
527
+ if (item.maxFiles != null) return `<=${item.maxFiles}`;
528
+ if (item.minFiles != null) return `>=${item.minFiles}`;
529
+ return undefined;
530
+ }
531
+
532
+ function textDurationRange(item = {}) {
533
+ if (item.minDurationMs != null && item.maxDurationMs != null) return `${item.minDurationMs}..${item.maxDurationMs}`;
534
+ if (item.maxDurationMs != null) return `<=${item.maxDurationMs}`;
535
+ if (item.minDurationMs != null) return `>=${item.minDurationMs}`;
536
+ return undefined;
537
+ }
538
+
539
+ function textItemCount(item = {}) {
540
+ if (item.minItems != null && item.maxItems != null && item.minItems === item.maxItems) return String(item.maxItems);
541
+ if (item.minItems != null && item.maxItems != null) return `${item.minItems}..${item.maxItems}`;
542
+ if (item.maxItems != null) return `<=${item.maxItems}`;
543
+ if (item.minItems != null) return `>=${item.minItems}`;
544
+ return undefined;
545
+ }
546
+
547
+ function formatModelOptionsOutput(data = {}) {
548
+ const params = Array.isArray(data.params) ? data.params : [];
549
+ const resources = Array.isArray(data.resources) ? data.resources : [];
550
+ const lines = ['ok model options'];
551
+ lines.push(renderRecord(compactRecord({
552
+ modelGroupCode: data.modelGroupCode,
553
+ taskKind: data.taskKind,
554
+ }), ['modelGroupCode', 'taskKind']));
555
+ lines.push(`params.count=${params.length}`);
556
+ for (const [index, param] of params.entries()) {
557
+ lines.push(`param[${index}]: ${renderRecord(compactRecord({
558
+ key: param.key,
559
+ type: param.valueType,
560
+ values: valueList(param.values),
561
+ default: param.defaultValue,
562
+ maxLength: param.maxLength,
563
+ required: param.required,
564
+ }), ['key', 'type', 'values', 'default', 'maxLength', 'required'])}`);
565
+ }
566
+ if (resources.length) {
567
+ lines.push(`resources.count=${resources.length}`);
568
+ for (const [index, item] of resources.entries()) {
569
+ lines.push(`resource[${index}]: ${renderRecord(compactRecord({
570
+ mode: item.mode,
571
+ media: item.mediaType,
572
+ usage: item.usage,
573
+ sources: textSources(item.sources),
574
+ formats: valueList(item.fileTypes),
575
+ files: textFileCount(item),
576
+ maxSizeKB: item.maxSizeKB,
577
+ durationMs: textDurationRange(item),
578
+ totalDurationMs: item.maxTotalDurationMs != null ? `<=${item.maxTotalDurationMs}` : undefined,
579
+ items: textItemCount(item),
580
+ maxPromptLength: item.maxPromptLength,
581
+ supportLastFrame: item.supportLastFrame,
582
+ }), [
583
+ 'mode',
584
+ 'media',
585
+ 'usage',
586
+ 'sources',
587
+ 'formats',
588
+ 'files',
589
+ 'maxSizeKB',
590
+ 'durationMs',
591
+ 'totalDurationMs',
592
+ 'items',
593
+ 'maxPromptLength',
594
+ 'supportLastFrame',
595
+ ])}`);
596
+ }
597
+ }
598
+ return `${lines.join('\n')}\n`;
599
+ }
600
+
601
+ function textKeyBinding(value) {
602
+ if (value === 'key_required') return 'required';
603
+ if (value === 'optional_key') return 'optional';
604
+ if (value === 'none') return 'none';
605
+ return value;
606
+ }
607
+
608
+ function formatModelCreateSpecOutput(data = {}) {
609
+ const intents = Array.isArray(data.supportedIntents) ? data.supportedIntents : [];
610
+ const examples = Array.isArray(data.examples) ? data.examples : [];
611
+ const lines = ['ok model create-spec'];
612
+ lines.push(renderRecord(compactRecord({
613
+ modelGroupCode: data.modelGroupCode,
614
+ taskKind: data.taskKind,
615
+ create: data.createCommand,
616
+ fee: data.feeCommand,
617
+ statusTaskType: data.statusCommandTaskType,
618
+ }), ['modelGroupCode', 'taskKind', 'create', 'fee', 'statusTaskType']));
619
+ lines.push(renderRecord(compactRecord({
620
+ input: data.inputRequirement?.summary,
621
+ acceptedModes: valueList(data.inputRequirement?.acceptedModes),
622
+ }), ['input', 'acceptedModes']));
623
+ lines.push(`intents.count=${intents.length}`);
624
+ for (const [index, intent] of intents.entries()) {
625
+ lines.push(`intent[${index}]: ${renderRecord(compactRecord({
626
+ mode: intent.mode,
627
+ intent: intent.intent,
628
+ args: valueList(intent.requiredArgs),
629
+ resources: valueList(intent.resourceSyntax),
630
+ key: textKeyBinding(intent.promptBinding),
631
+ }), ['mode', 'intent', 'args', 'resources', 'key'])}`);
632
+ }
633
+ if (examples.length) {
634
+ lines.push(`examples.count=${examples.length}`);
635
+ for (const [index, example] of examples.entries()) lines.push(`example[${index}]=${example}`);
636
+ }
637
+ if (data.optionsCommand) lines.push(`options=${commandPrefix()} ${data.optionsCommand}`);
638
+ return `${lines.join('\n')}\n`;
639
+ }
640
+
641
+ function defaultJsonCommand(commandName) {
642
+ return `${commandPrefix()} ${commandName} -f json`;
643
+ }
644
+
645
+ function modelListNextCommand(commandName) {
646
+ if (commandName === 'model image-models' || commandName === 'model video-models') {
647
+ return `${commandPrefix()} model options --model-group-code <modelGroupCode>`;
648
+ }
649
+ return null;
650
+ }
651
+
652
+ function statusNextCommand(commandName, normalized) {
653
+ if (!isPlainObject(normalized) || normalized.isTerminal !== false || !normalized.taskId) return null;
654
+ const taskType = normalized.taskType || (commandName === 'video status' ? 'VIDEO_GROUP' : 'IMAGE_CREATE');
655
+ return `${commandPrefix()} task wait --task-id ${normalized.taskId} --task-type ${taskType} --wait-seconds 180`;
656
+ }
657
+
658
+ function subtitleRemoveNextCommand(commandName, normalized) {
659
+ if (commandName !== 'video status' && commandName !== 'task wait') return null;
660
+ if (!Array.isArray(normalized.originUrls) || !normalized.originUrls.length) return null;
661
+ return `${commandPrefix()} video subtitle-remove --video-url <originUrl[0]> --dry-run`;
662
+ }
663
+
664
+ export function formatTextOutput(commandName, data, context = {}) {
665
+ if (commandName === 'model options') return formatModelOptionsOutput(data);
666
+ if (commandName === 'model create-spec') return formatModelCreateSpecOutput(data);
667
+ const normalized = normalizeOutputData(commandName, data);
668
+ if (!isPlainObject(normalized)) return `ok ${commandName}\nvalue=${shortValue(normalized)}\n`;
669
+ const lines = [`ok ${commandName}`];
670
+ const list = firstList(normalized);
671
+ const isModelList = commandName === 'model image-models' || commandName === 'model video-models';
672
+ const scalarLine = renderRecord(
673
+ normalized,
674
+ [
675
+ 'configured',
676
+ 'accessKey',
677
+ 'doctorStatus',
678
+ 'taskId',
679
+ 'publicId',
680
+ 'remoteTaskId',
681
+ 'taskType',
682
+ 'taskStatus',
683
+ 'modelGroupCode',
684
+ 'projectGroupNo',
685
+ 'groupId',
686
+ 'assetId',
687
+ 'elementId',
688
+ 'externalId',
689
+ 'status',
690
+ 'count',
691
+ 'resultCount',
692
+ 'pointCost',
693
+ 'pointTotal',
694
+ 'dryRun',
695
+ 'action',
696
+ ],
697
+ ['nextCommand', 'nextRefSubject', ...(list ? ['count'] : []), ...(isModelList ? ['usage'] : [])],
698
+ );
699
+ if (scalarLine) lines.push(scalarLine);
700
+ if (list) {
701
+ const total = list.rows.length;
702
+ lines.push(`${list.key}.count=${total}`);
703
+ const configuredLimit = context.listLimit === Number.POSITIVE_INFINITY
704
+ ? list.rows.length
705
+ : (Number.isFinite(context.listLimit) ? context.listLimit : 8);
706
+ const visibleLimit = Math.max(0, configuredLimit);
707
+ const visibleRows = list.rows.slice(0, visibleLimit);
708
+ for (const [index, row] of visibleRows.entries()) {
709
+ const summary = rowSummary(row);
710
+ if (summary) lines.push(`${list.key}[${index}]: ${summary}`);
711
+ if (isPlainObject(row) && Array.isArray(row.resultUrls)) {
712
+ for (const [urlIndex, url] of row.resultUrls.slice(0, 2).entries()) lines.push(`${list.key}[${index}].resultUrl[${urlIndex}]=${url}`);
713
+ }
714
+ if (isPlainObject(row) && Array.isArray(row.originUrls)) {
715
+ for (const [urlIndex, url] of row.originUrls.slice(0, 2).entries()) lines.push(`${list.key}[${index}].originUrl[${urlIndex}]=${url}`);
716
+ }
717
+ }
718
+ if (total > visibleRows.length) {
719
+ lines.push(`${list.key}.more=${total - visibleRows.length}`);
720
+ lines.push(`moreCommand=${context.moreCommand || context.jsonCommand || defaultJsonCommand(commandName)}`);
721
+ }
722
+ }
723
+ if (normalized.nextCommand) lines.push(`next=${normalized.nextCommand}`);
724
+ if (normalized.nextRefSubject) lines.push(`nextRefSubject=${normalized.nextRefSubject}`);
725
+ if (normalized.dryRun && context.confirmCommand) lines.push(`nextAfterConfirm=${context.confirmCommand}`);
726
+ if (normalized.dryRun && !context.confirmCommand && context.executeCommand) lines.push(`next=${context.executeCommand}`);
727
+ const modelNext = modelListNextCommand(commandName);
728
+ if (modelNext) lines.push(`next=${modelNext}`);
729
+ const waitNext = statusNextCommand(commandName, normalized);
730
+ if (waitNext) lines.push(`next=${waitNext}`);
731
+ const subtitleNext = subtitleRemoveNextCommand(commandName, normalized);
732
+ if (subtitleNext) lines.push(`nextSubtitleRemove=${subtitleNext}`);
733
+ if (Array.isArray(normalized.resultUrls)) {
734
+ for (const [index, url] of normalized.resultUrls.slice(0, 3).entries()) lines.push(`resultUrl[${index}]=${url}`);
735
+ }
736
+ if (Array.isArray(normalized.originUrls)) {
737
+ for (const [index, url] of normalized.originUrls.slice(0, 3).entries()) lines.push(`originUrl[${index}]=${url}`);
738
+ }
739
+ return `${lines.join('\n')}\n`;
740
+ }
741
+
742
+ export function formatTextError(error) {
743
+ const lines = [`error type=${error.type || 'error'}`, `message=${JSON.stringify(error.message || String(error))}`];
744
+ if (error.hint) lines.push(`hint=${JSON.stringify(rewriteCommandPrefix(error.hint))}`);
745
+ if (isPlainObject(error.details)) {
746
+ const payload = isPlainObject(error.details.payload) ? error.details.payload : {};
747
+ const detailLine = renderRecord(compactRecord({
748
+ status: error.details.status ?? payload.status,
749
+ code: error.details.code ?? payload.code,
750
+ msg: error.details.msg ?? payload.msg ?? payload.message,
751
+ traceId: error.details.traceId ?? payload.traceId,
752
+ causeCode: error.details.causeCode,
753
+ unknownOptions: Array.isArray(error.details.unknownOptions) ? error.details.unknownOptions.join(',') : undefined,
754
+ }), ['status', 'code', 'msg', 'traceId', 'causeCode', 'unknownOptions']);
755
+ if (detailLine) lines.push(`details ${detailLine}`);
756
+ }
757
+ return `${lines.join('\n')}\n`;
758
+ }