@lingjingai/lj-awb-cli 0.5.15 → 0.5.17
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/package.json +4 -3
- package/packages/awb-cli/package.json +2 -2
- package/packages/awb-core/package.json +3 -2
- package/packages/awb-core/src/api.js +108 -10
- package/packages/awb-core/src/output.js +73 -4
- package/packages/awb-core/src/services.js +119 -26
- package/skills/lj-awb/SKILL.md +2 -2
- package/skills/lj-awb/VERSION +1 -1
- package/skills/lj-awb/compat.json +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingjingai/lj-awb-cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.17",
|
|
4
4
|
"description": "Lingjing AWB CLI monorepo with shared core, standalone CLI, and agent skills",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"chalk": "^5.6.2",
|
|
12
|
-
"cli-table3": "^0.6.5"
|
|
12
|
+
"cli-table3": "^0.6.5",
|
|
13
|
+
"undici": "^6.28.1"
|
|
13
14
|
},
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">=20"
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
"build:pre-publish": "node build/pre-publish.mjs",
|
|
25
26
|
"build:prod": "node build/prod.mjs",
|
|
26
27
|
"check": "npm run check:local && npm run check:real",
|
|
27
|
-
"check:local": "node --check install.mjs && node --check packages/awb-core/src/common.js && node --check packages/awb-core/src/api.js && node --check packages/awb-core/src/auth.js && node --check packages/awb-core/src/output.js && node --check packages/awb-core/src/update.js && node --check packages/awb-core/src/services.js && node --check packages/awb-core/src/commands.js && node --check packages/awb-core/src/standalone.js && sh -n packages/awb-cli/bin/lj-awb && bash -n skills/lj-awb/scripts/resolve-lj-awb-cmd.sh && node --check packages/awb-cli/bin/lj-awb.js && node --check build/build.mjs && node --check build/_shared.mjs && node --check build/pre.mjs && node --check build/volta-pre.mjs && node --check build/pre-publish.mjs && node --check build/prod.mjs && node --check scripts/run-openapi-cli-examples-real.mjs && node --check scripts/validate-cli-schema.mjs && node --check scripts/validate-cli-output-contract.mjs && node --check scripts/validate-cli-command-coverage.mjs && node --check tests/test-model-filters.mjs && node --check tests/test-credits-records.mjs && node --check tests/test-task-status.mjs && node --check tests/test-project-members.mjs && node scripts/validate-skill-meta.mjs && node scripts/validate-cli-schema.mjs && node scripts/validate-cli-command-coverage.mjs && node --test tests/test-model-filters.mjs tests/test-credits-records.mjs tests/test-task-status.mjs tests/test-project-members.mjs",
|
|
28
|
+
"check:local": "node --check install.mjs && node --check packages/awb-core/src/common.js && node --check packages/awb-core/src/api.js && node --check packages/awb-core/src/auth.js && node --check packages/awb-core/src/output.js && node --check packages/awb-core/src/update.js && node --check packages/awb-core/src/services.js && node --check packages/awb-core/src/commands.js && node --check packages/awb-core/src/standalone.js && sh -n packages/awb-cli/bin/lj-awb && bash -n skills/lj-awb/scripts/resolve-lj-awb-cmd.sh && node --check packages/awb-cli/bin/lj-awb.js && node --check build/build.mjs && node --check build/_shared.mjs && node --check build/pre.mjs && node --check build/volta-pre.mjs && node --check build/pre-publish.mjs && node --check build/prod.mjs && node --check scripts/run-openapi-cli-examples-real.mjs && node --check scripts/validate-cli-schema.mjs && node --check scripts/validate-cli-output-contract.mjs && node --check scripts/validate-cli-command-coverage.mjs && node --check tests/test-api.mjs && node --check tests/test-model-filters.mjs && node --check tests/test-credits-records.mjs && node --check tests/test-task-status.mjs && node --check tests/test-project-members.mjs && node scripts/validate-skill-meta.mjs && node scripts/validate-cli-schema.mjs && node scripts/validate-cli-command-coverage.mjs && node --test tests/test-api.mjs tests/test-model-filters.mjs tests/test-credits-records.mjs tests/test-task-status.mjs tests/test-project-members.mjs",
|
|
28
29
|
"check:real": "node scripts/validate-cli-output-contract.mjs && node scripts/validate-openapi-cli-examples.mjs",
|
|
29
30
|
"test:openapi-real": "node scripts/run-openapi-cli-examples-real.mjs",
|
|
30
31
|
"smoke": "packages/awb-cli/bin/lj-awb --help && packages/awb-cli/bin/lj-awb auth status -f json && packages/awb-cli/bin/lj-awb system && packages/awb-cli/bin/lj-awb auth && packages/awb-cli/bin/lj-awb account && packages/awb-cli/bin/lj-awb project && packages/awb-cli/bin/lj-awb credits && packages/awb-cli/bin/lj-awb upload && packages/awb-cli/bin/lj-awb model && packages/awb-cli/bin/lj-awb create && packages/awb-cli/bin/lj-awb task && packages/awb-cli/bin/lj-awb schema -f json >/dev/null",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingjingai/awb-cli-bin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.17",
|
|
4
4
|
"description": "Standalone CLI for Lingjing AWB",
|
|
5
5
|
"private": true,
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
"README.md"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@lingjingai/awb-core": "0.5.
|
|
16
|
+
"@lingjingai/awb-core": "0.5.17"
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingjingai/awb-core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.17",
|
|
4
4
|
"description": "Shared core runtime for Lingjing AWB CLI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"chalk": "^5.6.2",
|
|
22
|
-
"cli-table3": "^0.6.5"
|
|
22
|
+
"cli-table3": "^0.6.5",
|
|
23
|
+
"undici": "^6.28.1"
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -1,6 +1,49 @@
|
|
|
1
|
+
import { Agent } from 'undici';
|
|
1
2
|
import { API_ORIGIN, LingjingAwbCliError } from './common.js';
|
|
2
3
|
import { resolveAuthContext } from './auth.js';
|
|
3
4
|
|
|
5
|
+
export const API_REQUEST_TIMEOUT_MS = 20_000;
|
|
6
|
+
export const API_CONNECT_TIMEOUT_MS = 20_000;
|
|
7
|
+
export const ASSET_REGISTER_TIMEOUT_MS = 60_000;
|
|
8
|
+
|
|
9
|
+
const API_DISPATCHER = new Agent({ connectTimeout: API_CONNECT_TIMEOUT_MS });
|
|
10
|
+
|
|
11
|
+
const SENSITIVE_DIAGNOSTIC_KEY = /(?:access.?key|authorization|cookie|credential|password|redeem(?:ption)?code|secret|session|signature|token)/i;
|
|
12
|
+
|
|
13
|
+
function sanitizeDiagnosticUrl(value) {
|
|
14
|
+
try {
|
|
15
|
+
const url = new URL(value);
|
|
16
|
+
for (const key of url.searchParams.keys()) {
|
|
17
|
+
if (SENSITIVE_DIAGNOSTIC_KEY.test(key)) url.searchParams.set(key, '[REDACTED]');
|
|
18
|
+
}
|
|
19
|
+
return url.toString();
|
|
20
|
+
} catch {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function sanitizeRequestDiagnostics(value, key = '') {
|
|
26
|
+
if (SENSITIVE_DIAGNOSTIC_KEY.test(key)) return '[REDACTED]';
|
|
27
|
+
if (Array.isArray(value)) return value.map((item) => sanitizeRequestDiagnostics(item));
|
|
28
|
+
if (value && typeof value === 'object') {
|
|
29
|
+
return Object.fromEntries(Object.entries(value)
|
|
30
|
+
.map(([itemKey, itemValue]) => [itemKey, sanitizeRequestDiagnostics(itemValue, itemKey)]));
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === 'string' && /^https?:\/\//i.test(value)) return sanitizeDiagnosticUrl(value);
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function requestDiagnostics({ method, url, query, body, timeoutMs, startedAt, extra = {} }) {
|
|
37
|
+
return {
|
|
38
|
+
method,
|
|
39
|
+
url: sanitizeDiagnosticUrl(url.toString()),
|
|
40
|
+
timeoutMs,
|
|
41
|
+
elapsedMs: Date.now() - startedAt,
|
|
42
|
+
request: sanitizeRequestDiagnostics({ query: query || {}, body }),
|
|
43
|
+
...extra,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
4
47
|
function buildHeaders(authContext, extraHeaders = {}) {
|
|
5
48
|
const contextHeaders = {};
|
|
6
49
|
for (const [headerName, envNames] of Object.entries({
|
|
@@ -43,7 +86,9 @@ export async function apiFetch(pathname, options = {}) {
|
|
|
43
86
|
body,
|
|
44
87
|
auth = true,
|
|
45
88
|
headers = {},
|
|
89
|
+
timeoutMs: requestedTimeoutMs = API_REQUEST_TIMEOUT_MS,
|
|
46
90
|
} = options;
|
|
91
|
+
const timeoutMs = Math.max(1, Number(requestedTimeoutMs) || API_REQUEST_TIMEOUT_MS);
|
|
47
92
|
|
|
48
93
|
const authContext = auth ? await resolveAuthContext({ required: true }) : null;
|
|
49
94
|
const url = new URL(pathname, API_ORIGIN);
|
|
@@ -52,29 +97,50 @@ export async function apiFetch(pathname, options = {}) {
|
|
|
52
97
|
url.searchParams.set(key, String(value));
|
|
53
98
|
}
|
|
54
99
|
|
|
100
|
+
const startedAt = Date.now();
|
|
101
|
+
const controller = new AbortController();
|
|
102
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
55
103
|
let response;
|
|
104
|
+
let rawText;
|
|
56
105
|
try {
|
|
57
106
|
response = await fetch(url, {
|
|
58
107
|
method,
|
|
59
108
|
headers: buildHeaders(authContext, headers),
|
|
60
109
|
body: method.toUpperCase() === 'GET' || body === undefined ? undefined : stringifyJsonBody(body),
|
|
110
|
+
dispatcher: API_DISPATCHER,
|
|
111
|
+
signal: controller.signal,
|
|
61
112
|
});
|
|
113
|
+
rawText = await response.text();
|
|
62
114
|
} catch (error) {
|
|
63
|
-
const causeCode = error?.cause?.code;
|
|
115
|
+
const causeCode = error?.cause?.code ?? error?.code;
|
|
116
|
+
const isTimeout = controller.signal.aborted;
|
|
64
117
|
const isTlsIssuerError = causeCode === 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY';
|
|
65
|
-
throw new LingjingAwbCliError(
|
|
118
|
+
throw new LingjingAwbCliError(isTimeout
|
|
119
|
+
? `请求平台接口超时:超过 ${timeoutMs}ms`
|
|
120
|
+
: isTlsIssuerError
|
|
66
121
|
? '请求平台接口失败:本机 Node 无法验证平台 HTTPS 证书链'
|
|
67
122
|
: `请求平台接口失败:${error.message}`, {
|
|
68
|
-
type: 'network_error',
|
|
123
|
+
type: isTimeout ? 'request_timeout' : 'network_error',
|
|
69
124
|
exitCode: 30,
|
|
70
|
-
hint:
|
|
125
|
+
hint: isTimeout
|
|
126
|
+
? '请检查平台、网关和网络状态后重试;创建类请求重试前请先确认是否已生成任务,避免重复扣费。'
|
|
127
|
+
: isTlsIssuerError
|
|
71
128
|
? '请使用全局 lj-awb 命令运行,或设置 NODE_EXTRA_CA_CERTS=/etc/ssl/cert.pem 后重试。'
|
|
72
129
|
: '',
|
|
73
|
-
details: {
|
|
130
|
+
details: requestDiagnostics({
|
|
131
|
+
method,
|
|
132
|
+
url,
|
|
133
|
+
query,
|
|
134
|
+
body,
|
|
135
|
+
timeoutMs,
|
|
136
|
+
startedAt,
|
|
137
|
+
extra: { causeCode },
|
|
138
|
+
}),
|
|
74
139
|
});
|
|
140
|
+
} finally {
|
|
141
|
+
clearTimeout(timeout);
|
|
75
142
|
}
|
|
76
143
|
|
|
77
|
-
const rawText = await response.text();
|
|
78
144
|
let payload = null;
|
|
79
145
|
try {
|
|
80
146
|
payload = rawText ? JSON.parse(rawText) : null;
|
|
@@ -82,7 +148,15 @@ export async function apiFetch(pathname, options = {}) {
|
|
|
82
148
|
throw new LingjingAwbCliError('平台接口返回了无效 JSON', {
|
|
83
149
|
type: 'invalid_json',
|
|
84
150
|
exitCode: 30,
|
|
85
|
-
details: {
|
|
151
|
+
details: requestDiagnostics({
|
|
152
|
+
method,
|
|
153
|
+
url,
|
|
154
|
+
query,
|
|
155
|
+
body,
|
|
156
|
+
timeoutMs,
|
|
157
|
+
startedAt,
|
|
158
|
+
extra: { status: response.status, responseBody: rawText.slice(0, 500) },
|
|
159
|
+
}),
|
|
86
160
|
});
|
|
87
161
|
}
|
|
88
162
|
|
|
@@ -90,7 +164,15 @@ export async function apiFetch(pathname, options = {}) {
|
|
|
90
164
|
throw new LingjingAwbCliError(payload?.msg || payload?.message || `${response.status} ${response.statusText}`, {
|
|
91
165
|
type: response.status === 401 ? 'auth_failed' : 'http_error',
|
|
92
166
|
exitCode: response.status === 401 ? 3 : 30,
|
|
93
|
-
details: {
|
|
167
|
+
details: requestDiagnostics({
|
|
168
|
+
method,
|
|
169
|
+
url,
|
|
170
|
+
query,
|
|
171
|
+
body,
|
|
172
|
+
timeoutMs,
|
|
173
|
+
startedAt,
|
|
174
|
+
extra: { status: response.status, payload },
|
|
175
|
+
}),
|
|
94
176
|
});
|
|
95
177
|
}
|
|
96
178
|
|
|
@@ -98,7 +180,20 @@ export async function apiFetch(pathname, options = {}) {
|
|
|
98
180
|
throw new LingjingAwbCliError(payload.msg || payload.message || '平台接口返回失败', {
|
|
99
181
|
type: String(payload.code) === '401' ? 'auth_failed' : 'api_error',
|
|
100
182
|
exitCode: String(payload.code) === '401' ? 3 : 1,
|
|
101
|
-
details:
|
|
183
|
+
details: requestDiagnostics({
|
|
184
|
+
method,
|
|
185
|
+
url,
|
|
186
|
+
query,
|
|
187
|
+
body,
|
|
188
|
+
timeoutMs,
|
|
189
|
+
startedAt,
|
|
190
|
+
extra: {
|
|
191
|
+
code: payload.code,
|
|
192
|
+
msg: payload.msg ?? payload.message,
|
|
193
|
+
traceId: payload.traceId,
|
|
194
|
+
payload,
|
|
195
|
+
},
|
|
196
|
+
}),
|
|
102
197
|
});
|
|
103
198
|
}
|
|
104
199
|
|
|
@@ -307,7 +402,10 @@ export async function updateAssetGroup(groupId, payload = {}) {
|
|
|
307
402
|
}
|
|
308
403
|
|
|
309
404
|
export async function registerAsset(payload = {}) {
|
|
310
|
-
return await apiFetch('/api/material/assets', {
|
|
405
|
+
return await apiFetch('/api/material/assets', {
|
|
406
|
+
body: payload,
|
|
407
|
+
timeoutMs: ASSET_REGISTER_TIMEOUT_MS,
|
|
408
|
+
});
|
|
311
409
|
}
|
|
312
410
|
|
|
313
411
|
export async function listElements(query = {}) {
|
|
@@ -254,7 +254,15 @@ function normalizeBatchTaskResult(row = {}) {
|
|
|
254
254
|
resultCount: row.resultCount,
|
|
255
255
|
resultUrls: row.resultUrls,
|
|
256
256
|
error: row.error,
|
|
257
|
+
errorType: row.errorType,
|
|
257
258
|
errorMessage: row.errorMessage,
|
|
259
|
+
errorHint: row.errorHint,
|
|
260
|
+
errorDetails: row.errorDetails,
|
|
261
|
+
waitStatus: row.waitStatus,
|
|
262
|
+
waitError: row.waitError,
|
|
263
|
+
waitErrorType: row.waitErrorType,
|
|
264
|
+
waitErrorMessage: row.waitErrorMessage,
|
|
265
|
+
waitErrorHint: row.waitErrorHint,
|
|
258
266
|
nextCommand: rewriteCommandPrefix(row.nextCommand),
|
|
259
267
|
statusCommand: rewriteCommandPrefix(row.statusCommand || submissionStatusCommand('create image', row)),
|
|
260
268
|
});
|
|
@@ -264,6 +272,7 @@ function normalizeBatchTaskSubmission(data = {}) {
|
|
|
264
272
|
const results = Array.isArray(data.results) ? data.results.map((row) => normalizeBatchTaskResult(row)) : [];
|
|
265
273
|
const successCount = data.successCount ?? results.filter((row) => row.status === 'success' || row.taskId).length;
|
|
266
274
|
const failureCount = data.failureCount ?? results.filter((row) => row.status === 'error' || row.error || row.errorMessage).length;
|
|
275
|
+
const waitFailureCount = data.waitFailureCount ?? results.filter((row) => row.waitError).length;
|
|
267
276
|
return compactRecord({
|
|
268
277
|
...data,
|
|
269
278
|
dryRun: data.dryRun,
|
|
@@ -271,12 +280,32 @@ function normalizeBatchTaskSubmission(data = {}) {
|
|
|
271
280
|
count: data.count ?? results.length,
|
|
272
281
|
successCount,
|
|
273
282
|
failureCount,
|
|
283
|
+
waitFailureCount,
|
|
274
284
|
taskRecordFile: data.taskRecordFile,
|
|
275
285
|
nextCommand: rewriteCommandPrefix(data.nextCommand),
|
|
276
286
|
results,
|
|
277
287
|
});
|
|
278
288
|
}
|
|
279
289
|
|
|
290
|
+
function batchTaskErrorDiagnostic(row = {}) {
|
|
291
|
+
const waitError = isPlainObject(row.waitError) ? row.waitError : null;
|
|
292
|
+
const details = isPlainObject(row.errorDetails)
|
|
293
|
+
? row.errorDetails
|
|
294
|
+
: (isPlainObject(waitError?.details) ? waitError.details : null);
|
|
295
|
+
if (!details) return null;
|
|
296
|
+
return compactRecord({
|
|
297
|
+
phase: waitError ? 'wait' : 'create',
|
|
298
|
+
errorType: waitError?.type ?? row.waitErrorType ?? row.errorType,
|
|
299
|
+
errorMessage: waitError?.message ?? row.waitErrorMessage ?? row.errorMessage ?? row.error,
|
|
300
|
+
causeCode: details.causeCode,
|
|
301
|
+
method: details.method,
|
|
302
|
+
url: details.url,
|
|
303
|
+
timeoutMs: details.timeoutMs,
|
|
304
|
+
elapsedMs: details.elapsedMs,
|
|
305
|
+
request: details.request,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
280
309
|
function normalizeSubtitleSubmission(data = {}) {
|
|
281
310
|
return compactRecord({
|
|
282
311
|
submitted: data.submitted,
|
|
@@ -820,6 +849,10 @@ function rowSummary(row) {
|
|
|
820
849
|
'isPrimary',
|
|
821
850
|
'referenceType',
|
|
822
851
|
'resultCount',
|
|
852
|
+
'waitErrorType',
|
|
853
|
+
'waitErrorMessage',
|
|
854
|
+
'errorType',
|
|
855
|
+
'errorMessage',
|
|
823
856
|
'promptSummary',
|
|
824
857
|
'recordedAt',
|
|
825
858
|
'gmtCreate',
|
|
@@ -1470,6 +1503,7 @@ const FIELD_LABELS = {
|
|
|
1470
1503
|
externalId: '外部 ID',
|
|
1471
1504
|
fileCount: '文件数',
|
|
1472
1505
|
failureCount: '失败数',
|
|
1506
|
+
waitFailureCount: '等待失败数',
|
|
1473
1507
|
feeCommand: '估价命令',
|
|
1474
1508
|
format: '格式',
|
|
1475
1509
|
generateNum: '生成数量',
|
|
@@ -1540,6 +1574,7 @@ const FIELD_LABELS = {
|
|
|
1540
1574
|
sourceTaskId: '来源任务 ID',
|
|
1541
1575
|
stateKey: '状态 Key',
|
|
1542
1576
|
status: '状态',
|
|
1577
|
+
waitStatus: '等待状态',
|
|
1543
1578
|
statusCommand: '状态查询命令',
|
|
1544
1579
|
statusCommandTaskType: '状态任务类型',
|
|
1545
1580
|
submitted: '已提交',
|
|
@@ -1608,7 +1643,7 @@ const DETAIL_FIELDS_BY_KIND = {
|
|
|
1608
1643
|
auth_status: ['configured', 'authType', 'accessKey', 'source', 'verified', 'verification', 'verifyCommand', 'userId', 'userName', 'groupId', 'groupName'],
|
|
1609
1644
|
batch_subject_publish_result: ['dryRun', 'submitted', 'count', 'successCount', 'failureCount', 'modelCode', 'projectGroupNo'],
|
|
1610
1645
|
batch_task_status: ['count', 'taskCount', 'successTaskCount', 'resultCount', 'pointTotal', 'timedOut', 'waitedMs'],
|
|
1611
|
-
batch_task_submission: ['dryRun', 'submitted', 'count', 'taskCount', 'successCount', 'failureCount', 'modelGroupCode', 'projectGroupNo', 'pointCost', 'billingPointBalance', 'projectBudgetBalance', 'taskRecordFile', 'nextCommand'],
|
|
1646
|
+
batch_task_submission: ['dryRun', 'submitted', 'count', 'taskCount', 'successCount', 'failureCount', 'waitFailureCount', 'modelGroupCode', 'projectGroupNo', 'pointCost', 'billingPointBalance', 'projectBudgetBalance', 'taskRecordFile', 'nextCommand'],
|
|
1612
1647
|
credit_detail_status: ['detailId', 'status', 'statusText', 'lockTime', 'lockPoint', 'useTime', 'usePoint', 'regetTime', 'regetPoint'],
|
|
1613
1648
|
credits_balance: ['billingPointBalance', 'currentProjectGroupNo', 'currentProjectGroupName', 'projectBudgetBalance', 'projectBudgetMax'],
|
|
1614
1649
|
credits_records: ['remainPoint', 'dataPlanPoint', 'topUpPoint', 'queryType', 'total', 'page', 'size', 'pages'],
|
|
@@ -2088,7 +2123,7 @@ const TABLE_COLUMNS = {
|
|
|
2088
2123
|
column('状态', ['status', 'taskStatus'], { maxWidth: 16 }),
|
|
2089
2124
|
column('任务 ID', 'taskId', { maxWidth: 28 }),
|
|
2090
2125
|
column('模型/主体', ['modelGroupCode', 'modelCode', 'name'], { maxWidth: 30 }),
|
|
2091
|
-
column('说明',
|
|
2126
|
+
column('说明', (row) => row.waitErrorMessage ?? row.errorMessage ?? row.error?.message ?? row.promptSummary ?? row.message ?? row.prompt, { maxWidth: 42 }),
|
|
2092
2127
|
column('状态查询', 'statusCommand', { maxWidth: 48 }),
|
|
2093
2128
|
],
|
|
2094
2129
|
subjects: [
|
|
@@ -2940,6 +2975,18 @@ function formatPrettyGeneric(commandName, data, context = {}) {
|
|
|
2940
2975
|
const limit = listLimitFor(commandName, context, rows);
|
|
2941
2976
|
renderArraySection(lines, namedListTitle(key), rows, key, limit);
|
|
2942
2977
|
}
|
|
2978
|
+
if (kind === 'batch_task_submission' && Array.isArray(normalized.results)) {
|
|
2979
|
+
for (const [index, row] of normalized.results.entries()) {
|
|
2980
|
+
const diagnostic = batchTaskErrorDiagnostic(row);
|
|
2981
|
+
if (!diagnostic) continue;
|
|
2982
|
+
renderDetails(
|
|
2983
|
+
lines,
|
|
2984
|
+
`错误诊断(序号 ${row.inputIndex ?? index})`,
|
|
2985
|
+
diagnostic,
|
|
2986
|
+
['phase', 'errorType', 'errorMessage', 'causeCode', 'method', 'url', 'timeoutMs', 'elapsedMs', 'request'],
|
|
2987
|
+
);
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2943
2990
|
renderUrlLists(lines, normalized);
|
|
2944
2991
|
renderNextActions(lines, collectPrettyActions(commandName, normalized, context), modelListAgentHint(commandName));
|
|
2945
2992
|
return `${lines.join('\n')}\n`;
|
|
@@ -3037,8 +3084,13 @@ export function formatPrettyError(error) {
|
|
|
3037
3084
|
msg: error.details.msg ?? payload.msg ?? payload.message,
|
|
3038
3085
|
traceId: error.details.traceId ?? payload.traceId,
|
|
3039
3086
|
causeCode: error.details.causeCode,
|
|
3087
|
+
method: error.details.method,
|
|
3088
|
+
url: error.details.url,
|
|
3089
|
+
timeoutMs: error.details.timeoutMs,
|
|
3090
|
+
elapsedMs: error.details.elapsedMs,
|
|
3091
|
+
request: error.details.request,
|
|
3040
3092
|
unknownOptions: Array.isArray(error.details.unknownOptions) ? error.details.unknownOptions.join(', ') : undefined,
|
|
3041
|
-
}), ['status', 'code', 'msg', 'traceId', 'causeCode', 'unknownOptions']);
|
|
3093
|
+
}), ['status', 'code', 'msg', 'traceId', 'causeCode', 'method', 'url', 'timeoutMs', 'elapsedMs', 'request', 'unknownOptions']);
|
|
3042
3094
|
}
|
|
3043
3095
|
return `${lines.join('\n')}\n`;
|
|
3044
3096
|
}
|
|
@@ -3166,6 +3218,18 @@ export function formatTextOutput(commandName, data, context = {}) {
|
|
|
3166
3218
|
const summary = rowSummary(row);
|
|
3167
3219
|
if (summary) lines.push(`${list.key}[${index}]: ${summary}`);
|
|
3168
3220
|
if (isPlainObject(row)) {
|
|
3221
|
+
const diagnostic = batchTaskErrorDiagnostic(row);
|
|
3222
|
+
if (diagnostic) {
|
|
3223
|
+
const detailLine = renderRecord(
|
|
3224
|
+
diagnostic,
|
|
3225
|
+
['phase', 'errorType', 'errorMessage', 'causeCode', 'method', 'url', 'timeoutMs', 'elapsedMs'],
|
|
3226
|
+
['request'],
|
|
3227
|
+
);
|
|
3228
|
+
if (detailLine) lines.push(`${list.key}[${index}].errorDetails ${detailLine}`);
|
|
3229
|
+
if (diagnostic.request !== undefined) {
|
|
3230
|
+
lines.push(`${list.key}[${index}].errorRequest=${JSON.stringify(diagnostic.request)}`);
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3169
3233
|
const resultUrls = Array.isArray(row.resultUrls) ? row.resultUrls : [];
|
|
3170
3234
|
const originUrls = !resultUrls.length && Array.isArray(row.originUrls) ? row.originUrls : [];
|
|
3171
3235
|
const urls = resultUrls.length ? resultUrls : originUrls;
|
|
@@ -3204,9 +3268,14 @@ export function formatTextError(error) {
|
|
|
3204
3268
|
msg: error.details.msg ?? payload.msg ?? payload.message,
|
|
3205
3269
|
traceId: error.details.traceId ?? payload.traceId,
|
|
3206
3270
|
causeCode: error.details.causeCode,
|
|
3271
|
+
method: error.details.method,
|
|
3272
|
+
url: error.details.url,
|
|
3273
|
+
timeoutMs: error.details.timeoutMs,
|
|
3274
|
+
elapsedMs: error.details.elapsedMs,
|
|
3207
3275
|
unknownOptions: Array.isArray(error.details.unknownOptions) ? error.details.unknownOptions.join(',') : undefined,
|
|
3208
|
-
}), ['status', 'code', 'msg', 'traceId', 'causeCode', 'unknownOptions']);
|
|
3276
|
+
}), ['status', 'code', 'msg', 'traceId', 'causeCode', 'method', 'url', 'timeoutMs', 'elapsedMs', 'unknownOptions']);
|
|
3209
3277
|
if (detailLine) lines.push(`details ${detailLine}`);
|
|
3278
|
+
if (error.details.request !== undefined) lines.push(`request=${JSON.stringify(error.details.request)}`);
|
|
3210
3279
|
}
|
|
3211
3280
|
return `${lines.join('\n')}\n`;
|
|
3212
3281
|
}
|
|
@@ -50,6 +50,7 @@ const REQUEST_SOURCE_CLI = 'LINGJING_AWB_CLI';
|
|
|
50
50
|
const DEFAULT_TASK_RECORD_FILE_ENV = process.env.LINGJING_AWB_TASK_RECORD_FILE || process.env.AWB_TASK_RECORD_FILE;
|
|
51
51
|
const execFileAsync = promisify(execFile);
|
|
52
52
|
const COMMON_IMAGE_FORMATS = new Set(['jpg', 'jpeg', 'jfif', 'png', 'webp']);
|
|
53
|
+
export const COS_UPLOAD_TIMEOUT_MS = 60_000;
|
|
53
54
|
const REMOTE_IMAGE_DOWNLOAD_TIMEOUT_MS = 30_000;
|
|
54
55
|
const REMOTE_IMAGE_DOWNLOAD_MAX_BYTES = 100 * 1024 * 1024;
|
|
55
56
|
const REMOTE_IMAGE_MIME_TYPES = new Set([
|
|
@@ -4076,22 +4077,62 @@ export async function uploadLocalFile(filePath, options = {}) {
|
|
|
4076
4077
|
startTime: secret.startTime,
|
|
4077
4078
|
expiredTime: secret.expiredTime,
|
|
4078
4079
|
});
|
|
4079
|
-
const
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
'
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4080
|
+
const uploadUrl = `https://${host}/${encodeObjectNamePath(objectName)}`;
|
|
4081
|
+
const startedAt = Date.now();
|
|
4082
|
+
let response;
|
|
4083
|
+
try {
|
|
4084
|
+
response = await fetch(uploadUrl, {
|
|
4085
|
+
method: 'PUT',
|
|
4086
|
+
headers: {
|
|
4087
|
+
authorization,
|
|
4088
|
+
'content-length': String(buffer.length),
|
|
4089
|
+
'content-type': inspected.mimeType || guessMimeType(inspected.filePath),
|
|
4090
|
+
host,
|
|
4091
|
+
'x-cos-security-token': credentials.sessionToken,
|
|
4092
|
+
},
|
|
4093
|
+
body: buffer,
|
|
4094
|
+
signal: AbortSignal.timeout(COS_UPLOAD_TIMEOUT_MS),
|
|
4095
|
+
});
|
|
4096
|
+
} catch (error) {
|
|
4097
|
+
const isTimeout = error?.name === 'TimeoutError';
|
|
4098
|
+
throw new LingjingAwbCliError(isTimeout
|
|
4099
|
+
? `上传 COS 超时:超过 ${COS_UPLOAD_TIMEOUT_MS}ms`
|
|
4100
|
+
: `上传 COS 失败:${error.message}`, {
|
|
4101
|
+
type: isTimeout ? 'request_timeout' : 'network_error',
|
|
4102
|
+
exitCode: 30,
|
|
4103
|
+
hint: isTimeout ? '请检查 COS、公司出口网络和文件大小后重试。' : '',
|
|
4104
|
+
details: {
|
|
4105
|
+
method: 'PUT',
|
|
4106
|
+
url: uploadUrl,
|
|
4107
|
+
timeoutMs: COS_UPLOAD_TIMEOUT_MS,
|
|
4108
|
+
elapsedMs: Date.now() - startedAt,
|
|
4109
|
+
causeCode: isTimeout ? 'TIMEOUT' : (error?.cause?.code ?? error?.code),
|
|
4110
|
+
request: {
|
|
4111
|
+
fileName: inspected.fileName,
|
|
4112
|
+
fileSize: buffer.length,
|
|
4113
|
+
mimeType: inspected.mimeType || guessMimeType(inspected.filePath),
|
|
4114
|
+
objectName,
|
|
4115
|
+
},
|
|
4116
|
+
},
|
|
4117
|
+
});
|
|
4118
|
+
}
|
|
4090
4119
|
if (!response.ok) {
|
|
4091
4120
|
throw new LingjingAwbCliError(`上传 COS 失败:${response.status} ${response.statusText}`, {
|
|
4092
4121
|
type: 'upload_failed',
|
|
4093
4122
|
exitCode: 30,
|
|
4094
|
-
details: {
|
|
4123
|
+
details: {
|
|
4124
|
+
method: 'PUT',
|
|
4125
|
+
url: uploadUrl,
|
|
4126
|
+
timeoutMs: COS_UPLOAD_TIMEOUT_MS,
|
|
4127
|
+
elapsedMs: Date.now() - startedAt,
|
|
4128
|
+
status: response.status,
|
|
4129
|
+
request: {
|
|
4130
|
+
fileName: inspected.fileName,
|
|
4131
|
+
fileSize: buffer.length,
|
|
4132
|
+
mimeType: inspected.mimeType || guessMimeType(inspected.filePath),
|
|
4133
|
+
objectName,
|
|
4134
|
+
},
|
|
4135
|
+
},
|
|
4095
4136
|
});
|
|
4096
4137
|
}
|
|
4097
4138
|
return compactRecord({
|
|
@@ -5444,10 +5485,15 @@ async function runConcurrent(items, limit, worker) {
|
|
|
5444
5485
|
try {
|
|
5445
5486
|
results[index] = await worker(items[index], index);
|
|
5446
5487
|
} catch (error) {
|
|
5488
|
+
const serializedError = serializeCliError(error);
|
|
5447
5489
|
results[index] = {
|
|
5448
5490
|
inputIndex: index,
|
|
5449
5491
|
status: 'error',
|
|
5450
|
-
error:
|
|
5492
|
+
error: serializedError.message,
|
|
5493
|
+
errorType: serializedError.type,
|
|
5494
|
+
errorMessage: serializedError.message,
|
|
5495
|
+
...(serializedError.hint ? { errorHint: serializedError.hint } : {}),
|
|
5496
|
+
...(serializedError.details ? { errorDetails: serializedError.details } : {}),
|
|
5451
5497
|
};
|
|
5452
5498
|
}
|
|
5453
5499
|
}
|
|
@@ -5456,6 +5502,57 @@ async function runConcurrent(items, limit, worker) {
|
|
|
5456
5502
|
return results;
|
|
5457
5503
|
}
|
|
5458
5504
|
|
|
5505
|
+
export function serializeCliError(error) {
|
|
5506
|
+
return compactRecord({
|
|
5507
|
+
type: error?.type || 'error',
|
|
5508
|
+
message: error instanceof Error ? error.message : String(error),
|
|
5509
|
+
hint: error?.hint,
|
|
5510
|
+
details: error?.details,
|
|
5511
|
+
});
|
|
5512
|
+
}
|
|
5513
|
+
|
|
5514
|
+
async function createBatchTask(kind, kwargs, item, index) {
|
|
5515
|
+
const createTask = kind === 'video' ? videoCreate : imageCreate;
|
|
5516
|
+
const taskType = kind === 'video' ? 'VIDEO_GROUP' : 'IMAGE_CREATE';
|
|
5517
|
+
const waitSeconds = Math.max(0, toInt(kwargs.waitSeconds, 0));
|
|
5518
|
+
const result = await createTask({
|
|
5519
|
+
...kwargs,
|
|
5520
|
+
...item,
|
|
5521
|
+
yes: true,
|
|
5522
|
+
dryRun: false,
|
|
5523
|
+
waitSeconds: 0,
|
|
5524
|
+
});
|
|
5525
|
+
const submission = {
|
|
5526
|
+
inputIndex: index,
|
|
5527
|
+
status: 'success',
|
|
5528
|
+
promptSummary: taskPromptSummary(item),
|
|
5529
|
+
...result,
|
|
5530
|
+
};
|
|
5531
|
+
if (!result.taskId || waitSeconds <= 0) return submission;
|
|
5532
|
+
try {
|
|
5533
|
+
return {
|
|
5534
|
+
...submission,
|
|
5535
|
+
waited: await waitTask({
|
|
5536
|
+
taskId: result.taskId,
|
|
5537
|
+
taskType,
|
|
5538
|
+
projectGroupNo: result.projectGroupNo,
|
|
5539
|
+
waitSeconds,
|
|
5540
|
+
pollIntervalMs: kwargs.pollIntervalMs,
|
|
5541
|
+
}),
|
|
5542
|
+
};
|
|
5543
|
+
} catch (error) {
|
|
5544
|
+
return {
|
|
5545
|
+
...submission,
|
|
5546
|
+
status: 'submitted',
|
|
5547
|
+
waitStatus: 'error',
|
|
5548
|
+
waitError: serializeCliError(error),
|
|
5549
|
+
waitErrorType: error?.type || 'error',
|
|
5550
|
+
waitErrorMessage: error instanceof Error ? error.message : String(error),
|
|
5551
|
+
...(error?.hint ? { waitErrorHint: error.hint } : {}),
|
|
5552
|
+
};
|
|
5553
|
+
}
|
|
5554
|
+
}
|
|
5555
|
+
|
|
5459
5556
|
export async function imageCreateBatch(kwargs = {}) {
|
|
5460
5557
|
const items = (await loadBatchItems(kwargs.inputFile, 'image'))
|
|
5461
5558
|
.map((item, index) => normalizeTaskBatchItem(item, 'image', index));
|
|
@@ -5471,12 +5568,9 @@ export async function imageCreateBatch(kwargs = {}) {
|
|
|
5471
5568
|
return summarizeBatchSubmission('image', kwargs, results, { dryRun: true, count: items.length });
|
|
5472
5569
|
}
|
|
5473
5570
|
ensureConfirmed(kwargs, '批量生图会多次消耗积分,需要确认', { action: 'create image-batch', count: items.length });
|
|
5474
|
-
const results = await runConcurrent(items, kwargs.concurrency ?? 1, async (item, index) => (
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
promptSummary: taskPromptSummary(item),
|
|
5478
|
-
...(await imageCreate({ ...kwargs, ...item, yes: true, dryRun: false })),
|
|
5479
|
-
}));
|
|
5571
|
+
const results = await runConcurrent(items, kwargs.concurrency ?? 1, async (item, index) => (
|
|
5572
|
+
await createBatchTask('image', kwargs, item, index)
|
|
5573
|
+
));
|
|
5480
5574
|
return summarizeBatchSubmission('image', kwargs, results, { count: items.length });
|
|
5481
5575
|
}
|
|
5482
5576
|
|
|
@@ -5495,12 +5589,9 @@ export async function videoCreateBatch(kwargs = {}) {
|
|
|
5495
5589
|
return summarizeBatchSubmission('video', kwargs, results, { dryRun: true, count: items.length });
|
|
5496
5590
|
}
|
|
5497
5591
|
ensureConfirmed(kwargs, '批量生视频会多次消耗积分,需要确认', { action: 'create video-batch', count: items.length });
|
|
5498
|
-
const results = await runConcurrent(items, kwargs.concurrency ?? 1, async (item, index) => (
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
promptSummary: taskPromptSummary(item),
|
|
5502
|
-
...(await videoCreate({ ...kwargs, ...item, yes: true, dryRun: false })),
|
|
5503
|
-
}));
|
|
5592
|
+
const results = await runConcurrent(items, kwargs.concurrency ?? 1, async (item, index) => (
|
|
5593
|
+
await createBatchTask('video', kwargs, item, index)
|
|
5594
|
+
));
|
|
5504
5595
|
return summarizeBatchSubmission('video', kwargs, results, { count: items.length });
|
|
5505
5596
|
}
|
|
5506
5597
|
|
|
@@ -5542,13 +5633,15 @@ function summarizeBatchSubmission(kind, kwargs = {}, results = [], options = {})
|
|
|
5542
5633
|
});
|
|
5543
5634
|
});
|
|
5544
5635
|
const successCount = normalizedResults.filter((row) => row.status === 'success' || row.taskId).length;
|
|
5545
|
-
const failureCount = normalizedResults.filter((row) => row.status === 'error'
|
|
5636
|
+
const failureCount = normalizedResults.filter((row) => row.status === 'error' && !row.taskId).length;
|
|
5637
|
+
const waitFailureCount = normalizedResults.filter((row) => row.waitError).length;
|
|
5546
5638
|
return compactRecord({
|
|
5547
5639
|
dryRun: options.dryRun,
|
|
5548
5640
|
submitted: !options.dryRun,
|
|
5549
5641
|
count: options.count ?? normalizedResults.length,
|
|
5550
5642
|
successCount,
|
|
5551
5643
|
failureCount,
|
|
5644
|
+
waitFailureCount,
|
|
5552
5645
|
taskRecordFile,
|
|
5553
5646
|
nextCommand: options.dryRun ? null : taskRecordPollCommand(taskRecordFile),
|
|
5554
5647
|
results: normalizedResults,
|
package/skills/lj-awb/SKILL.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: lj-awb
|
|
3
|
-
version: 0.5.
|
|
3
|
+
version: 0.5.17
|
|
4
4
|
description: "灵境 AWB CLI skill。使用 `lj-awb` 命令调用动漫平台 / AWB 云端能力,覆盖认证、项目组、积分余额/明细/用量(含充值购买与兑换码兑换)、模型发现、上传、统一 create 创建域、任务查询、视频超分。用户说生图、生视频、生成音频、积分明细、积分流水、充值记录、消耗记录、主体、音色、素材加白、去字幕时使用。正式生成、切换项目组、清空认证、兑换码等写入或扣费动作前必须确认。"
|
|
5
5
|
metadata:
|
|
6
6
|
bootstrap:
|
|
7
7
|
package: "@lingjingai/lj-awb-cli"
|
|
8
|
-
version: "0.5.
|
|
8
|
+
version: "0.5.17"
|
|
9
9
|
bin: "lj-awb"
|
|
10
10
|
cliHelp: "lj-awb --help"
|
|
11
11
|
---
|
package/skills/lj-awb/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.5.
|
|
1
|
+
0.5.17
|