@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,349 @@
1
+ import { API_ORIGIN, LingjingAwbCliError } from './common.js';
2
+ import { resolveAuthContext } from './auth.js';
3
+
4
+ export const ASSET_EDIT_ORIGIN = (
5
+ process.env.LINGJING_AWB_ASSET_EDIT_ORIGIN
6
+ || process.env.ASSET_EDIT_ORIGIN
7
+ || 'https://asset-edit.lingjingai.cn'
8
+ ).replace(/\/+$/, '');
9
+
10
+ function buildHeaders(authContext, extraHeaders = {}) {
11
+ const contextHeaders = {};
12
+ for (const [headerName, envNames] of Object.entries({
13
+ userId: ['LINGJING_AWB_USER_ID', 'AWB_USER_ID'],
14
+ groupId: ['LINGJING_AWB_GROUP_ID', 'AWB_GROUP_ID'],
15
+ userName: ['LINGJING_AWB_USER_NAME', 'AWB_USER_NAME'],
16
+ groupName: ['LINGJING_AWB_GROUP_NAME', 'AWB_GROUP_NAME'],
17
+ role: ['LINGJING_AWB_ROLE', 'AWB_ROLE'],
18
+ groupRole: ['LINGJING_AWB_GROUP_ROLE', 'AWB_GROUP_ROLE'],
19
+ })) {
20
+ const value = envNames.map((name) => process.env[name]).find((item) => item !== undefined && item !== '');
21
+ if (value !== undefined) contextHeaders[headerName] = value;
22
+ }
23
+ const headers = {
24
+ 'content-type': 'application/json',
25
+ productcode: '1004',
26
+ source: 'pc',
27
+ timestamp: String(Date.now()),
28
+ ...contextHeaders,
29
+ ...extraHeaders,
30
+ };
31
+ if (authContext?.accessKey) {
32
+ headers['X-Access-Key'] = authContext.accessKey;
33
+ }
34
+ return headers;
35
+ }
36
+
37
+ function stringifyJsonBody(body) {
38
+ return JSON.stringify(body).replace(/[<>&]/g, (char) => ({
39
+ '<': '\\u003c',
40
+ '>': '\\u003e',
41
+ '&': '\\u0026',
42
+ }[char]));
43
+ }
44
+
45
+ export async function apiFetch(pathname, options = {}) {
46
+ const {
47
+ method = 'POST',
48
+ query,
49
+ body,
50
+ auth = true,
51
+ headers = {},
52
+ } = options;
53
+
54
+ const authContext = auth ? await resolveAuthContext({ required: true }) : null;
55
+ const url = new URL(pathname, API_ORIGIN);
56
+ for (const [key, value] of Object.entries(query || {})) {
57
+ if (value === undefined || value === null || value === '') continue;
58
+ url.searchParams.set(key, String(value));
59
+ }
60
+
61
+ let response;
62
+ try {
63
+ response = await fetch(url, {
64
+ method,
65
+ headers: buildHeaders(authContext, headers),
66
+ body: method.toUpperCase() === 'GET' || body === undefined ? undefined : stringifyJsonBody(body),
67
+ });
68
+ } catch (error) {
69
+ const causeCode = error?.cause?.code;
70
+ const isTlsIssuerError = causeCode === 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY';
71
+ throw new LingjingAwbCliError(isTlsIssuerError
72
+ ? '请求平台接口失败:本机 Node 无法验证平台 HTTPS 证书链'
73
+ : `请求平台接口失败:${error.message}`, {
74
+ type: 'network_error',
75
+ exitCode: 30,
76
+ hint: isTlsIssuerError
77
+ ? '请使用全局 lj-awb 命令运行,或设置 NODE_EXTRA_CA_CERTS=/etc/ssl/cert.pem 后重试。'
78
+ : '',
79
+ details: { url: url.toString(), causeCode },
80
+ });
81
+ }
82
+
83
+ const rawText = await response.text();
84
+ let payload = null;
85
+ try {
86
+ payload = rawText ? JSON.parse(rawText) : null;
87
+ } catch {
88
+ throw new LingjingAwbCliError('平台接口返回了无效 JSON', {
89
+ type: 'invalid_json',
90
+ exitCode: 30,
91
+ details: { status: response.status, body: rawText.slice(0, 500) },
92
+ });
93
+ }
94
+
95
+ if (!response.ok) {
96
+ throw new LingjingAwbCliError(payload?.msg || payload?.message || `${response.status} ${response.statusText}`, {
97
+ type: response.status === 401 ? 'auth_failed' : 'http_error',
98
+ exitCode: response.status === 401 ? 3 : 30,
99
+ details: { status: response.status, payload },
100
+ });
101
+ }
102
+
103
+ if (payload && typeof payload === 'object' && 'code' in payload && String(payload.code) !== '200') {
104
+ throw new LingjingAwbCliError(payload.msg || payload.message || '平台接口返回失败', {
105
+ type: String(payload.code) === '401' ? 'auth_failed' : 'api_error',
106
+ exitCode: String(payload.code) === '401' ? 3 : 1,
107
+ details: payload,
108
+ });
109
+ }
110
+
111
+ return payload && typeof payload === 'object' && 'data' in payload ? payload.data : payload;
112
+ }
113
+
114
+ export async function fetchUserInfo() {
115
+ return await apiFetch('/api/anime/user/account/userInfo', { body: {} });
116
+ }
117
+
118
+ export async function fetchTeams() {
119
+ return await apiFetch('/api/anime/user/group/getOwnGroupList', { body: {} });
120
+ }
121
+
122
+ export async function fetchProjectGroups() {
123
+ return await apiFetch('/api/anime/workbench/projectGroup/getProjectGroup', { method: 'GET' });
124
+ }
125
+
126
+ export async function fetchCurrentProjectGroup() {
127
+ return await apiFetch('/api/anime/workbench/projectGroup/getLastProjectGroup', { method: 'GET' });
128
+ }
129
+
130
+ export async function fetchPoints() {
131
+ return await apiFetch('/api/anime/member/benefits/queryGroupPoint', { body: {} });
132
+ }
133
+
134
+ export async function selectProjectGroup(projectGroupNo) {
135
+ return await apiFetch('/api/anime/workbench/projectGroup/setLastProjectGroup', {
136
+ body: { projectGroupNo },
137
+ });
138
+ }
139
+
140
+ export async function updateCurrentTeam(groupId) {
141
+ return await apiFetch('/api/anime/user/group/updateCurrentGroup', {
142
+ body: { groupId },
143
+ });
144
+ }
145
+
146
+ export async function fetchProjectGroupUsers() {
147
+ return await apiFetch('/api/anime/workbench/projectGroup/getGroupAllUser', { method: 'GET' });
148
+ }
149
+
150
+ export async function fetchProjectGroupIntegral(projectGroupNo) {
151
+ return await apiFetch('/api/anime/workbench/projectGroup/getProjectGroupIntegral', {
152
+ body: { projectGroupNo },
153
+ });
154
+ }
155
+
156
+ export async function createProjectGroup(payload) {
157
+ return await apiFetch('/api/anime/workbench/projectGroup/createProjectGroup', { body: payload });
158
+ }
159
+
160
+ export async function updateProjectGroup(payload) {
161
+ return await apiFetch('/api/anime/workbench/projectGroup/modify', { body: payload });
162
+ }
163
+
164
+ export async function fetchProjectManagementList(payload = {}) {
165
+ return await apiFetch('/api/anime/workbench/project/management/list', {
166
+ body: {
167
+ pageNo: 1,
168
+ pageSize: 20,
169
+ ...payload,
170
+ },
171
+ });
172
+ }
173
+
174
+ export async function fetchModelsByUsage(usage, body = {}) {
175
+ return await apiFetch(`/api/resource/model/list/usage/${encodeURIComponent(usage)}`, { body });
176
+ }
177
+
178
+ export async function fetchModelOptions(payload = {}) {
179
+ return await apiFetch('/api/resource/model/config/options', { body: payload });
180
+ }
181
+
182
+ export async function fetchModelGroupInfoAll(modelGroupCode) {
183
+ return await apiFetch(`/api/resource/model/info/group/${encodeURIComponent(modelGroupCode)}/all`, { method: 'GET' });
184
+ }
185
+
186
+ export async function fetchUploadSecret(payload = {}) {
187
+ return await apiFetch('/api/anime/workbench/TencentCloud/getSecret', { body: payload });
188
+ }
189
+
190
+ export async function fetchObjectSignUrl(objectName) {
191
+ return await apiFetch('/api/anime/workbench/TencentCloud/getObjectSignUrl', {
192
+ method: 'GET',
193
+ query: { objectName },
194
+ });
195
+ }
196
+
197
+ export async function fetchImageFee(payload = {}) {
198
+ return await apiFetch('/api/material/creation/imageCreateFeeCalc', { body: payload });
199
+ }
200
+
201
+ export async function createImageTask(payload = {}) {
202
+ return await apiFetch('/api/material/creation/imageCreate', { body: payload });
203
+ }
204
+
205
+ export async function fetchImageTask(taskId) {
206
+ return await apiFetch('/api/material/creation/imageCreateGet', {
207
+ method: 'GET',
208
+ query: { taskId },
209
+ });
210
+ }
211
+
212
+ export async function fetchVideoFee(payload = {}) {
213
+ return await apiFetch('/api/material/creation/videoCreateFeeCalc', { body: payload });
214
+ }
215
+
216
+ export async function createVideoTask(payload = {}) {
217
+ return await apiFetch('/api/material/creation/videoCreate', { body: payload });
218
+ }
219
+
220
+ export async function fetchVideoTask(taskId) {
221
+ return await apiFetch('/api/material/creation/videoCreateGet', {
222
+ method: 'GET',
223
+ query: { taskId },
224
+ });
225
+ }
226
+
227
+ export async function fetchTaskFeed(payload = {}) {
228
+ return await apiFetch('/api/material/creation/task/feedPull', {
229
+ query: payload,
230
+ body: payload,
231
+ });
232
+ }
233
+
234
+ export async function matchAssetMaterial(payload = {}) {
235
+ return await apiFetch('/api/admin/asset-material/match', { body: payload });
236
+ }
237
+
238
+ export async function listAssetGroups(payload = {}) {
239
+ return await apiFetch('/api/material/asset-groups/list', { body: payload });
240
+ }
241
+
242
+ export async function getAssetGroup(groupId) {
243
+ return await apiFetch(`/api/material/asset-groups/${encodeURIComponent(groupId)}`, { method: 'GET' });
244
+ }
245
+
246
+ export async function createAssetGroup(payload = {}) {
247
+ return await apiFetch('/api/material/asset-groups', { body: payload });
248
+ }
249
+
250
+ export async function updateAssetGroup(groupId, payload = {}) {
251
+ return await apiFetch(`/api/material/asset-groups/${encodeURIComponent(groupId)}`, {
252
+ method: 'PUT',
253
+ body: payload,
254
+ });
255
+ }
256
+
257
+ export async function registerAsset(payload = {}) {
258
+ return await apiFetch('/api/material/assets', { body: payload });
259
+ }
260
+
261
+ export async function listElements(query = {}) {
262
+ return await apiFetch('/api/material/creation/listElements', {
263
+ method: 'GET',
264
+ query,
265
+ });
266
+ }
267
+
268
+ export async function createElement(payload = {}) {
269
+ return await apiFetch('/api/material/creation/createElement', { body: payload });
270
+ }
271
+
272
+ export async function getElementByReqTaskId(reqTaskId) {
273
+ return await apiFetch('/api/material/creation/getElementByReqTaskId', {
274
+ method: 'GET',
275
+ query: { reqTaskId },
276
+ });
277
+ }
278
+
279
+ export async function listElementsByName(elementName) {
280
+ return await apiFetch('/api/material/creation/listElementsByName', {
281
+ method: 'GET',
282
+ query: { elementName },
283
+ });
284
+ }
285
+
286
+ export async function assetEditFetch(pathname, options = {}) {
287
+ const {
288
+ method = 'GET',
289
+ body,
290
+ query,
291
+ headers = {},
292
+ } = options;
293
+ const url = new URL(pathname, ASSET_EDIT_ORIGIN);
294
+ for (const [key, value] of Object.entries(query || {})) {
295
+ if (value === undefined || value === null || value === '') continue;
296
+ url.searchParams.set(key, String(value));
297
+ }
298
+ let response;
299
+ try {
300
+ response = await fetch(url, {
301
+ method,
302
+ headers: {
303
+ 'content-type': 'application/json',
304
+ ...headers,
305
+ },
306
+ body: method.toUpperCase() === 'GET' || body === undefined ? undefined : stringifyJsonBody(body),
307
+ });
308
+ } catch (error) {
309
+ throw new LingjingAwbCliError(`请求去字幕服务失败:${error.message}`, {
310
+ type: 'network_error',
311
+ exitCode: 30,
312
+ details: { url: url.toString() },
313
+ });
314
+ }
315
+ const rawText = await response.text();
316
+ let payload = null;
317
+ try {
318
+ payload = rawText ? JSON.parse(rawText) : null;
319
+ } catch {
320
+ throw new LingjingAwbCliError('去字幕服务返回了无效 JSON', {
321
+ type: 'invalid_json',
322
+ exitCode: 30,
323
+ details: { status: response.status, body: rawText.slice(0, 500) },
324
+ });
325
+ }
326
+ if (!response.ok) {
327
+ throw new LingjingAwbCliError(payload?.message || payload?.msg || `${response.status} ${response.statusText}`, {
328
+ type: 'http_error',
329
+ exitCode: 30,
330
+ details: { status: response.status, payload },
331
+ });
332
+ }
333
+ return payload && typeof payload === 'object' && 'data' in payload ? payload.data : payload;
334
+ }
335
+
336
+ export async function createSubtitleRemoveTask(payload = {}) {
337
+ return await assetEditFetch('/api/watermark/tasks', {
338
+ method: 'POST',
339
+ body: payload,
340
+ });
341
+ }
342
+
343
+ export async function fetchSubtitleTaskByPublicId(publicId) {
344
+ return await assetEditFetch(`/api/watermark/tasks/${encodeURIComponent(publicId)}`);
345
+ }
346
+
347
+ export async function fetchSubtitleTaskByRemoteId(remoteTaskId) {
348
+ return await assetEditFetch(`/api/watermark/remote/${encodeURIComponent(remoteTaskId)}`);
349
+ }
@@ -0,0 +1,80 @@
1
+ import {
2
+ LingjingAwbCliError,
3
+ AUTH_PATH,
4
+ maskSecret,
5
+ nowIso,
6
+ readJson,
7
+ resolveRuntimeAccessKey,
8
+ trimSecret,
9
+ writeJson,
10
+ } from './common.js';
11
+
12
+ export async function loadAuth() {
13
+ return await readJson(AUTH_PATH, {});
14
+ }
15
+
16
+ export async function saveAuth(auth) {
17
+ const stored = {
18
+ ...auth,
19
+ updatedAt: Date.now(),
20
+ updatedAtText: nowIso(),
21
+ };
22
+ await writeJson(AUTH_PATH, stored, { secure: true });
23
+ return stored;
24
+ }
25
+
26
+ export async function clearAuth() {
27
+ await writeJson(AUTH_PATH, {}, { secure: true });
28
+ }
29
+
30
+ export async function resolveAuthContext({ required = true } = {}) {
31
+ const savedAuth = await loadAuth();
32
+ const accessKeyInfo = resolveRuntimeAccessKey(savedAuth);
33
+ if (!accessKeyInfo) {
34
+ if (!required) {
35
+ return { authenticated: false, auth: savedAuth, accessKeyInfo: null };
36
+ }
37
+ throw new LingjingAwbCliError('缺少 access key', {
38
+ type: 'auth_required',
39
+ exitCode: 3,
40
+ hint: '请设置 LINGJING_AWB_ACCESS_KEY / AWB_ACCESS_KEY,或运行 lj-awb auth login-key。',
41
+ });
42
+ }
43
+ return {
44
+ authenticated: true,
45
+ auth: savedAuth,
46
+ accessKeyInfo,
47
+ accessKey: accessKeyInfo.accessKey,
48
+ };
49
+ }
50
+
51
+ export function summarizeAuth(auth, accessKeyInfo = null) {
52
+ const info = accessKeyInfo || resolveRuntimeAccessKey(auth);
53
+ return {
54
+ loginState: info ? '已配置' : '未配置',
55
+ authType: info ? 'access_key' : null,
56
+ accessKey: info ? maskSecret(info.accessKey) : null,
57
+ accessKeySource: info?.source ?? null,
58
+ accessKeySourceName: info?.sourceName ?? null,
59
+ authPath: AUTH_PATH,
60
+ updatedAt: auth?.updatedAt ?? null,
61
+ updatedAtText: auth?.updatedAtText ?? null,
62
+ };
63
+ }
64
+
65
+ export async function saveAccessKey(rawAccessKey, options = {}) {
66
+ const accessKey = trimSecret(rawAccessKey);
67
+ if (!accessKey) {
68
+ throw new LingjingAwbCliError('access key 不能为空', {
69
+ type: 'argument_error',
70
+ exitCode: 2,
71
+ });
72
+ }
73
+ const auth = await saveAuth({
74
+ accessKey,
75
+ awbCode: accessKey,
76
+ authType: 'access_key',
77
+ verified: Boolean(options.verified),
78
+ });
79
+ return { auth, accessKey };
80
+ }