@insmind/cli 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/agent-worker.js +2 -1
- package/dist/bin/insmind-cli.js +12 -7
- package/dist/bin/postinstall.js +7 -5
- package/dist/src/bootstrap/create-cli.js +26 -17
- package/dist/src/bootstrap/create-runtime.js +31 -13
- package/dist/src/bootstrap/run-agent-worker.js +2 -1
- package/dist/src/bootstrap/validators.js +10 -5
- package/dist/src/cli/action-binding.js +14 -0
- package/dist/src/cli/agent-commands.js +8 -3
- package/dist/src/cli/auth-commands.js +1 -1
- package/dist/src/cli/credits-command.js +2 -2
- package/dist/src/cli/dam-commands.js +51 -52
- package/dist/src/cli/editor-commands.js +13 -15
- package/dist/src/cli/errors.js +91 -41
- package/dist/src/cli/model-commands.js +6 -4
- package/dist/src/cli/presenter.js +13 -10
- package/dist/src/cli/task-commands.js +13 -5
- package/dist/src/cli/tool-commands.js +9 -3
- package/dist/src/features/agent/use-cases.js +11 -5
- package/dist/src/features/auth/credential-store.js +2 -2
- package/dist/src/features/auth/sso-service.js +3 -2
- package/dist/src/features/auth/state.js +2 -0
- package/dist/src/features/auth/use-cases.js +30 -34
- package/dist/src/features/credits/use-cases.js +2 -0
- package/dist/src/features/dam/file-downloader.js +38 -16
- package/dist/src/features/dam/object-storage.js +23 -11
- package/dist/src/features/dam/operation-executor.js +46 -37
- package/dist/src/features/dam/registered-uploader.js +39 -29
- package/dist/src/features/dam/storage-upload.js +5 -4
- package/dist/src/features/dam/use-cases.js +81 -60
- package/dist/src/features/editor/bridge-client.js +6 -6
- package/dist/src/features/editor/bridge-process.js +2 -1
- package/dist/src/features/editor/session-state.js +6 -4
- package/dist/src/features/editor/session.js +26 -8
- package/dist/src/features/editor/use-cases.js +10 -3
- package/dist/src/features/org/use-cases.js +2 -1
- package/dist/src/features/task/agent-background.js +1 -0
- package/dist/src/features/task/store.js +2 -0
- package/dist/src/features/task/use-cases.js +80 -27
- package/dist/src/features/tool/catalog.js +11 -5
- package/dist/src/features/tool/dynamic-schema.js +9 -7
- package/dist/src/features/tool/mns-catalog-adapter.js +1 -0
- package/dist/src/features/tool/tool-api-adapter.js +8 -7
- package/dist/src/features/tool/use-cases.js +7 -3
- package/dist/src/features/update/update-notification.js +75 -70
- package/dist/src/features/update/update-service.js +24 -20
- package/dist/src/platform/file-lock.js +36 -9
- package/dist/src/platform/interruption.js +13 -0
- package/dist/src/platform/json-input.js +12 -9
- package/dist/src/platform/local-json-file.js +8 -4
- package/dist/src/platform/redact.js +7 -1
- package/dist/src/platform/remote-protocol.js +2 -2
- package/dist/src/platform/safe-upload-file.js +2 -1
- package/dist/src/platform/schema-issues.js +8 -0
- package/dist/src/platform/signed-http-transport.js +8 -7
- package/dist/src/platform/text-output.js +33 -0
- package/dist/src/telemetry/invocation.js +19 -4
- package/dist/src/telemetry/process-errors.js +14 -4
- package/dist/src/telemetry/sanitize.js +4 -2
- package/dist/src/telemetry/sls-sink.js +36 -20
- package/package.json +4 -4
|
@@ -27,7 +27,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
27
27
|
await runtime.telemetry.stage("output", async () => {
|
|
28
28
|
runtime.presenter.result(result, {
|
|
29
29
|
json: repositoryList.opts().json === true,
|
|
30
|
-
view: repositoryListView
|
|
30
|
+
view: value => repositoryListView(value, runtime.product)
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
}, { operation: "dam.repository.list" });
|
|
@@ -64,7 +64,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
64
64
|
await runtime.telemetry.stage("output", async () => {
|
|
65
65
|
runtime.presenter.result(result, {
|
|
66
66
|
json: folderList.opts().json === true,
|
|
67
|
-
view: folderListView
|
|
67
|
+
view: value => folderListView(value, runtime.product)
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
}, { operation: "dam.folder.list" });
|
|
@@ -95,7 +95,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
95
95
|
await runtime.telemetry.stage("output", async () => {
|
|
96
96
|
runtime.presenter.result(result, {
|
|
97
97
|
json: tagList.opts().json === true,
|
|
98
|
-
view: tagListView
|
|
98
|
+
view: value => tagListView(value, runtime.product)
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
}, { operation: "dam.tag.list" });
|
|
@@ -126,7 +126,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
126
126
|
await runtime.telemetry.stage("output", async () => {
|
|
127
127
|
runtime.presenter.result(result, {
|
|
128
128
|
json: download.opts().json === true,
|
|
129
|
-
view: downloadView
|
|
129
|
+
view: value => downloadView(value, runtime.product)
|
|
130
130
|
});
|
|
131
131
|
});
|
|
132
132
|
}, { operation: "dam.download" });
|
|
@@ -159,7 +159,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
159
159
|
await runtime.telemetry.stage("output", async () => {
|
|
160
160
|
runtime.presenter.result(result, {
|
|
161
161
|
json: rename.opts().json === true,
|
|
162
|
-
view: renameView
|
|
162
|
+
view: value => renameView(value, runtime.product)
|
|
163
163
|
});
|
|
164
164
|
});
|
|
165
165
|
}, { operation: "dam.rename" });
|
|
@@ -209,7 +209,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
209
209
|
await runtime.telemetry.stage("output", async () => {
|
|
210
210
|
runtime.presenter.result(result, {
|
|
211
211
|
json: command.opts().json === true,
|
|
212
|
-
view: operation === "move" ? moveView : copyView
|
|
212
|
+
view: value => operation === "move" ? moveView(value, runtime.product) : copyView(value, runtime.product)
|
|
213
213
|
});
|
|
214
214
|
});
|
|
215
215
|
}, { operation: `dam.${operation}` });
|
|
@@ -231,7 +231,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
231
231
|
await runtime.telemetry.stage("output", async () => {
|
|
232
232
|
runtime.presenter.result(result, {
|
|
233
233
|
json: list.opts().json === true,
|
|
234
|
-
view: assetListView
|
|
234
|
+
view: value => assetListView(value, runtime.product)
|
|
235
235
|
});
|
|
236
236
|
});
|
|
237
237
|
}, { operation: "dam.list" });
|
|
@@ -256,7 +256,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
256
256
|
await runtime.telemetry.stage("output", async () => {
|
|
257
257
|
runtime.presenter.result(result, {
|
|
258
258
|
json: search.opts().json === true,
|
|
259
|
-
view: assetListView
|
|
259
|
+
view: value => assetListView(value, runtime.product)
|
|
260
260
|
});
|
|
261
261
|
});
|
|
262
262
|
}, { operation: "dam.search" });
|
|
@@ -279,7 +279,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
279
279
|
await runtime.telemetry.stage("output", async () => {
|
|
280
280
|
runtime.presenter.result(result, {
|
|
281
281
|
json: get.opts().json === true,
|
|
282
|
-
view: assetDetailView
|
|
282
|
+
view: value => assetDetailView(value, runtime.product)
|
|
283
283
|
});
|
|
284
284
|
});
|
|
285
285
|
}, { operation: "dam.get" });
|
|
@@ -317,7 +317,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
317
317
|
await runtime.telemetry.stage("output", async () => {
|
|
318
318
|
runtime.presenter.result(result, {
|
|
319
319
|
json: upload.opts().json === true,
|
|
320
|
-
view: assetDetailView
|
|
320
|
+
view: value => assetDetailView(value, runtime.product)
|
|
321
321
|
});
|
|
322
322
|
});
|
|
323
323
|
}, { operation: "dam.upload" });
|
|
@@ -417,70 +417,69 @@ function organizationAccess(state) {
|
|
|
417
417
|
organizationId: state.organization.id
|
|
418
418
|
};
|
|
419
419
|
}
|
|
420
|
-
function assetListView(value) {
|
|
421
|
-
const
|
|
422
|
-
if (assets.length === 0)
|
|
423
|
-
return "暂无素材。";
|
|
420
|
+
function assetListView(value, product) {
|
|
421
|
+
const result = value;
|
|
424
422
|
return [
|
|
425
|
-
"
|
|
426
|
-
|
|
423
|
+
`${text(product, "资源库", "Repositories")}: ${result.repository_ids.join(", ")}`,
|
|
424
|
+
`${text(product, "本批 / 总数", "This batch / total")}: ${result.assets.length} / ${result.total}`,
|
|
425
|
+
result.finish ? text(product, "已到最后一页。", "Last page.")
|
|
426
|
+
: text(product, `还有下一页;保留筛选条件,使用 --cursor ${result.next_cursor ?? "<cursor>"} 查询。`, `More results; keep the same filters and query with --cursor ${result.next_cursor ?? "<cursor>"}.`),
|
|
427
|
+
...(result.assets.length ? [text(product, "ID\t标题\t类型\t格式", "ID\tTitle\tType\tFormat"), ...result.assets.map(assetRow)]
|
|
428
|
+
: [text(product, "暂无素材。", "No assets.")])
|
|
427
429
|
].join("\n");
|
|
428
430
|
}
|
|
429
431
|
function assetRow(asset) {
|
|
430
432
|
return [asset.asset_id, asset.title ?? "", asset.type ?? "", asset.format ?? ""].join("\t");
|
|
431
433
|
}
|
|
432
|
-
function assetDetailView(value) {
|
|
434
|
+
function assetDetailView(value, product) {
|
|
433
435
|
const asset = value;
|
|
434
436
|
return [
|
|
435
|
-
|
|
436
|
-
`ID
|
|
437
|
-
...(asset.
|
|
438
|
-
...(asset.
|
|
439
|
-
...(asset.
|
|
437
|
+
`${text(product, "素材", "Asset")}: ${asset.title ?? asset.asset_id}`,
|
|
438
|
+
`ID: ${asset.asset_id}`,
|
|
439
|
+
...(asset.repository_id === undefined ? [] : [`${text(product, "资源库", "Repository")}: ${asset.repository_id}`]),
|
|
440
|
+
...(asset.folder_id === undefined ? [] : [`${text(product, "文件夹", "Folder")}: ${asset.folder_id}`]),
|
|
441
|
+
...(asset.type === undefined ? [] : [`${text(product, "类型", "Type")}: ${asset.type}`]),
|
|
442
|
+
...(asset.format === undefined ? [] : [`${text(product, "格式", "Format")}: ${asset.format}`]),
|
|
443
|
+
`${text(product, "分析状态", "Analysis status")}: ${asset.analysis_status ?? text(product, "未提供", "not provided")}`,
|
|
444
|
+
...(asset.url === undefined ? [] : [`URL: ${asset.url}`])
|
|
440
445
|
].join("\n");
|
|
441
446
|
}
|
|
442
|
-
function folderListView(value) {
|
|
443
|
-
const
|
|
444
|
-
if (folders.length === 0)
|
|
445
|
-
return "暂无文件夹。";
|
|
447
|
+
function folderListView(value, product) {
|
|
448
|
+
const result = value;
|
|
446
449
|
return [
|
|
447
|
-
"
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
folder.child_folder_count,
|
|
452
|
-
|
|
453
|
-
].join("\t"))
|
|
450
|
+
`${text(product, "资源库 / 父文件夹", "Repository / parent folder")}: ${result.repository_id} / ${result.parent_id}`,
|
|
451
|
+
`${text(product, "页码 / 分页大小 / 总数", "Page / page size / total")}: ${result.page} / ${result.page_size} / ${result.total}`,
|
|
452
|
+
...(result.page * result.page_size < result.total ? [text(product, `还有下一页;保留筛选条件,使用 --page ${result.page + 1}。`, `More results; keep the same filters and use --page ${result.page + 1}.`)] : []),
|
|
453
|
+
...(result.folders.length ? [text(product, "ID\t名称\t子文件夹数\t素材数", "ID\tName\tChild folders\tAssets"),
|
|
454
|
+
...result.folders.map(folder => [folder.folder_id, folder.title, folder.child_folder_count, folder.asset_count].join("\t"))]
|
|
455
|
+
: [text(product, "暂无文件夹。", "No folders.")])
|
|
454
456
|
].join("\n");
|
|
455
457
|
}
|
|
456
|
-
function tagListView(value) {
|
|
457
|
-
const
|
|
458
|
-
if (tags.length === 0)
|
|
459
|
-
return "暂无标签。";
|
|
458
|
+
function tagListView(value, product) {
|
|
459
|
+
const result = value;
|
|
460
460
|
return [
|
|
461
|
-
"
|
|
462
|
-
...tags.
|
|
461
|
+
`${text(product, "资源库", "Repository")}: ${result.repository_id}`,
|
|
462
|
+
...(result.tags.length ? [text(product, "ID\t名称\t素材数", "ID\tName\tAssets"),
|
|
463
|
+
...result.tags.map(tag => [tag.tag_id, tag.name, tag.asset_count].join("\t"))]
|
|
464
|
+
: [text(product, "暂无标签。", "No tags.")])
|
|
463
465
|
].join("\n");
|
|
464
466
|
}
|
|
465
|
-
function downloadView(value) {
|
|
466
|
-
return value.files
|
|
467
|
-
.map((file) => `已下载:${file.path}`)
|
|
468
|
-
.join("\n");
|
|
467
|
+
function downloadView(value, product) {
|
|
468
|
+
return value.files.map(file => `${text(product, "已下载", "Downloaded")}: ${file.path}`).join("\n");
|
|
469
469
|
}
|
|
470
|
-
function renameView(value) {
|
|
470
|
+
function renameView(value, product) {
|
|
471
471
|
const result = value;
|
|
472
|
-
return
|
|
472
|
+
return `${text(product, "已重命名", "Renamed")}: ${result.title} (${result.entry_id})`;
|
|
473
473
|
}
|
|
474
|
-
function moveView(value) {
|
|
474
|
+
function moveView(value, product) {
|
|
475
475
|
const result = value;
|
|
476
|
-
return
|
|
476
|
+
return `${text(product, "已移动", "Moved")}: ${result.entry_id} → ${result.repository_id} / ${result.folder_id}`;
|
|
477
477
|
}
|
|
478
|
-
function copyView(value) {
|
|
478
|
+
function copyView(value, product) {
|
|
479
479
|
const result = value;
|
|
480
480
|
return [
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
: [`复制条目 ID:${result.copied_entry_id}`])
|
|
481
|
+
`${text(product, "已复制", "Copied")}: ${result.source_entry_id} → ${result.repository_id} / ${result.folder_id}`,
|
|
482
|
+
result.copied_entry_id !== undefined ? `${text(product, "复制条目 ID", "Copied entry ID")}: ${result.copied_entry_id}`
|
|
483
|
+
: text(product, `未返回新 ID;使用 ${product.commandName} dam list --repository-id ${result.repository_id} --folder-id ${result.folder_id} 查询目标位置。`, `No new ID returned; inspect the destination with ${product.commandName} dam list --repository-id ${result.repository_id} --folder-id ${result.folder_id}.`)
|
|
485
484
|
].join("\n");
|
|
486
485
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bindAction, bindPreparedAction } from "./action-binding.js";
|
|
1
|
+
import { jsonOutput, bindAction, bindPreparedAction } from "./action-binding.js";
|
|
2
2
|
import { contractSchema } from "../contracts/schema.js";
|
|
3
3
|
import { CliUsageError } from "./errors.js";
|
|
4
4
|
import { productText as text } from "../product/text.js";
|
|
@@ -27,6 +27,7 @@ export function registerEditorCommands(program, runtime) {
|
|
|
27
27
|
text(runtime.product, "页面切换作品会断开 Session;EDITOR_NOT_READY、EDITOR_SESSION_NOT_FOUND 或 EDITOR_NOT_CONNECTED 时确认目标后重连,不轮询旧 Session。", "Switching works disconnects the Session. On EDITOR_NOT_READY, EDITOR_SESSION_NOT_FOUND or EDITOR_NOT_CONNECTED, verify the target and reconnect instead of polling the old Session."),
|
|
28
28
|
""
|
|
29
29
|
].join("\n"));
|
|
30
|
+
jsonOutput(connect);
|
|
30
31
|
bindPreparedAction(connect, "none", async (signal) => {
|
|
31
32
|
signal.throwIfAborted();
|
|
32
33
|
const target = connect.processedArgs[0];
|
|
@@ -34,14 +35,15 @@ export function registerEditorCommands(program, runtime) {
|
|
|
34
35
|
runtime.validators.editorConnectInput(input);
|
|
35
36
|
return { handled: false, input };
|
|
36
37
|
}, async (_context, input, signal) => {
|
|
37
|
-
const result = await runtime.editor.connect({ input, signal });
|
|
38
|
+
const result = await runtime.telemetry.stage("editor.connect", () => runtime.editor.connect({ input, signal }));
|
|
38
39
|
writeJson(runtime, result);
|
|
39
40
|
});
|
|
40
41
|
const disconnect = leaf(editor.command("disconnect"))
|
|
41
42
|
.description(text(runtime.product, "断开当前 Editor 连接", "Disconnect the current Editor"));
|
|
42
43
|
disconnect.addHelpText("after", `\n${text(runtime.product, "输出 JSON {disconnected};断开连接不保存作品,需先显式执行 editor save。", "Returns JSON {disconnected}. Disconnecting does not save the work; run editor save explicitly first.")}\n`);
|
|
44
|
+
jsonOutput(disconnect);
|
|
43
45
|
bindAction(disconnect, "none", async (_context, signal) => {
|
|
44
|
-
writeJson(runtime, await runtime.editor.disconnect({ signal }));
|
|
46
|
+
writeJson(runtime, await runtime.telemetry.stage("editor.disconnect", () => runtime.editor.disconnect({ signal })));
|
|
45
47
|
});
|
|
46
48
|
const snapshot = leaf(editor.command("snapshot"))
|
|
47
49
|
.description(text(runtime.product, "读取当前作品快照", "Read the current work snapshot"));
|
|
@@ -51,8 +53,9 @@ export function registerEditorCommands(program, runtime) {
|
|
|
51
53
|
text(runtime.product, "修改时以最新 Snapshot 中的完整元素为基础;每次 apply 后重新读取。UNSUPPORTED_PAGE_CONTENT 时停止并保留原作品。", "Base changes on complete elements from the latest Snapshot and read again after every Apply. On UNSUPPORTED_PAGE_CONTENT, stop and preserve the work."),
|
|
52
54
|
""
|
|
53
55
|
].join("\n"));
|
|
56
|
+
jsonOutput(snapshot);
|
|
54
57
|
bindAction(snapshot, "none", async (_context, signal) => {
|
|
55
|
-
writeJson(runtime, await runtime.editor.snapshot({ signal }));
|
|
58
|
+
writeJson(runtime, await runtime.telemetry.stage("editor.snapshot", () => runtime.editor.snapshot({ signal })));
|
|
56
59
|
});
|
|
57
60
|
const apply = leaf(editor.command("apply"))
|
|
58
61
|
.description(text(runtime.product, "按顺序应用元素操作", "Apply element operations in order"))
|
|
@@ -68,6 +71,7 @@ export function registerEditorCommands(program, runtime) {
|
|
|
68
71
|
text(runtime.product, "成功不表示已保存或视觉正确;读取新 Snapshot,涉及布局/文字/连线时查看截图,再显式 save。超时、取消或断连后先检查真实状态,不重复提交。", "Success proves neither persistence nor correct rendering. Read a new Snapshot, view a screenshot for layout/text/connectors, then explicitly save. Inspect real state after timeout, cancellation or disconnection instead of resubmitting."),
|
|
69
72
|
""
|
|
70
73
|
].join("\n"));
|
|
74
|
+
jsonOutput(apply);
|
|
71
75
|
bindPreparedAction(apply, "none", async (signal) => {
|
|
72
76
|
signal.throwIfAborted();
|
|
73
77
|
const options = apply.opts();
|
|
@@ -81,7 +85,7 @@ export function registerEditorCommands(program, runtime) {
|
|
|
81
85
|
runtime.validators.editorApplyInput(input);
|
|
82
86
|
return { handled: false, input };
|
|
83
87
|
}, async (_context, input, signal) => {
|
|
84
|
-
writeJson(runtime, await runtime.editor.apply({ input, signal }));
|
|
88
|
+
writeJson(runtime, await runtime.telemetry.stage("editor.apply", () => runtime.editor.apply({ input, signal })));
|
|
85
89
|
}, {
|
|
86
90
|
operation: "editor.apply",
|
|
87
91
|
mode: () => apply.opts().schema === true ? "schema" : "execute"
|
|
@@ -91,10 +95,10 @@ export function registerEditorCommands(program, runtime) {
|
|
|
91
95
|
.option("--json", text(runtime.product, "输出 JSON", "output JSON"));
|
|
92
96
|
screenshot.addHelpText("after", `\n${text(runtime.product, "将当前作品截图写入本机 PNG;--json 输出 {path},path 为绝对路径。打开实际图片检查文字、布局与连线,不以文件存在代替视觉验收。", "Writes a PNG screenshot locally; --json returns {path} with an absolute path. View the actual image to check text, layout and connectors; file existence is not visual verification.")}\n`);
|
|
93
97
|
bindAction(screenshot, "none", async (_context, signal) => {
|
|
94
|
-
const result = await runtime.editor.screenshot({ signal });
|
|
98
|
+
const result = await runtime.telemetry.stage("editor.screenshot", () => runtime.editor.screenshot({ signal }));
|
|
95
99
|
runtime.presenter.result(result, {
|
|
96
100
|
json: screenshot.opts().json === true,
|
|
97
|
-
view:
|
|
101
|
+
view: value => text(runtime.product, `截图已保存至 ${value.path}`, `Screenshot saved to ${value.path}`)
|
|
98
102
|
});
|
|
99
103
|
});
|
|
100
104
|
const save = leaf(editor.command("save"))
|
|
@@ -108,10 +112,10 @@ export function registerEditorCommands(program, runtime) {
|
|
|
108
112
|
""
|
|
109
113
|
].join("\n"));
|
|
110
114
|
bindAction(save, "none", async (_context, signal) => {
|
|
111
|
-
const result = await runtime.editor.save({ signal });
|
|
115
|
+
const result = await runtime.telemetry.stage("editor.save", () => runtime.editor.save({ signal }));
|
|
112
116
|
runtime.presenter.result(result, {
|
|
113
117
|
json: save.opts().json === true,
|
|
114
|
-
view:
|
|
118
|
+
view: value => text(runtime.product, `作品已保存:${value.url}`, `Work saved: ${value.url}`)
|
|
115
119
|
});
|
|
116
120
|
});
|
|
117
121
|
}
|
|
@@ -121,9 +125,3 @@ function leaf(command) {
|
|
|
121
125
|
function writeJson(runtime, value) {
|
|
122
126
|
runtime.io.writeOut(`${JSON.stringify(value)}\n`);
|
|
123
127
|
}
|
|
124
|
-
function screenshotView(value) {
|
|
125
|
-
return `截图已保存至 ${value.path}`;
|
|
126
|
-
}
|
|
127
|
-
function saveView(value) {
|
|
128
|
-
return `作品已保存:${value.url}`;
|
|
129
|
-
}
|
package/dist/src/cli/errors.js
CHANGED
|
@@ -11,7 +11,7 @@ import { ToolInputError } from "../features/tool/catalog.js";
|
|
|
11
11
|
import { ToolTaskFailedError } from "../features/tool/tool-api-adapter.js";
|
|
12
12
|
import { ObjectStorageUploadError } from "../features/dam/object-storage.js";
|
|
13
13
|
import { DamAssetNotDownloadableError, DamAssetNotFoundError, DamFolderNotFoundError } from "../features/dam/dam-api-adapter.js";
|
|
14
|
-
import { DamDownloadDestinationExistsError } from "../features/dam/file-downloader.js";
|
|
14
|
+
import { DamDownloadError, DamDownloadDestinationExistsError } from "../features/dam/file-downloader.js";
|
|
15
15
|
import { DamOperationFailedError } from "../features/dam/operation-executor.js";
|
|
16
16
|
import { DamInputError, DamOperationUnconfirmedError, DamRepositoryNotFoundError } from "../features/dam/use-cases.js";
|
|
17
17
|
import { OrganizationResponseError } from "../features/org/org-service.js";
|
|
@@ -21,7 +21,9 @@ import { RemoteProtocolError } from "../platform/remote-protocol.js";
|
|
|
21
21
|
import { InputContractError, OutputContractError } from "../bootstrap/validators.js";
|
|
22
22
|
import { JsonInputError } from "../platform/json-input.js";
|
|
23
23
|
import { LocalFileInputError } from "../platform/safe-upload-file.js";
|
|
24
|
-
import { EditorBridgeError } from "../features/editor/bridge-client.js";
|
|
24
|
+
import { EditorBridgeError, EditorBridgeUnavailableError } from "../features/editor/bridge-client.js";
|
|
25
|
+
import { LocalFileError } from "../platform/local-json-file.js";
|
|
26
|
+
import { redactSensitiveText } from "../platform/redact.js";
|
|
25
27
|
import { EditorNotReadyError, EditorSessionNotFoundError, EditorTargetError } from "../features/editor/session.js";
|
|
26
28
|
import { UpdateError } from "../features/update/update-service.js";
|
|
27
29
|
export class CliUsageError extends Error {
|
|
@@ -33,7 +35,7 @@ export class CliUsageError extends Error {
|
|
|
33
35
|
const INSUFFICIENT_CREDITS_REMOTE_CODE = "12020770";
|
|
34
36
|
const INSUFFICIENT_CREDITS_NEXT_STEPS = [
|
|
35
37
|
"前往 https://www.gaoding.art/pricing 购买稿豆",
|
|
36
|
-
"也可以执行 gd-cli org switch 切换到有可用稿豆的组织",
|
|
38
|
+
"也可以执行 gd-cli org list,再用 gd-cli org switch --org <org-id> 切换到有可用稿豆的组织",
|
|
37
39
|
"处理后重新发起本次创作"
|
|
38
40
|
];
|
|
39
41
|
export function isHelpOutcome(error) {
|
|
@@ -44,8 +46,14 @@ export function isHelpOutcome(error) {
|
|
|
44
46
|
export function mapCliError(error, options) {
|
|
45
47
|
const insmind = options.product?.id === "insmind";
|
|
46
48
|
const command = options.product?.commandName ?? "gd-cli";
|
|
49
|
+
const text = (zh, en) => insmind ? en : zh;
|
|
47
50
|
if (options.aborted)
|
|
48
|
-
return { kind: "interrupted", exitCode: 130
|
|
51
|
+
return { kind: "interrupted", exitCode: 130, failure: {
|
|
52
|
+
code: "INTERRUPTED", message: text("已停止本地等待;已派发的任务或写操作可能仍在继续。", "Local waiting stopped; dispatched tasks or writes may still be active."),
|
|
53
|
+
details: { ...(error instanceof DamOperationUnconfirmedError ? { operation: error.operation, ...error.context } : {}),
|
|
54
|
+
...(error instanceof DamDownloadError ? { phase: error.phase, remaining_paths: error.remainingPaths } : {}),
|
|
55
|
+
next_steps: [text(`创作用 ${command} task list 找到原任务,再用 task get <id> 查询;Editor 写入先检查原作品。不要直接重复提交。`, `For creation, find the original task with ${command} task list, then task get <id>. For Editor writes, inspect the original work. Do not resubmit directly.`)] }
|
|
56
|
+
} };
|
|
49
57
|
if (error instanceof AgentBackgroundError)
|
|
50
58
|
return { kind: "failure", failure: error.failure, exitCode: error.exitCode };
|
|
51
59
|
if (error instanceof TaskNotFoundError)
|
|
@@ -53,7 +61,8 @@ export function mapCliError(error, options) {
|
|
|
53
61
|
if (error instanceof TaskStoreError)
|
|
54
62
|
return failure("LOCAL_STATE_ERROR", insmind
|
|
55
63
|
? "Cannot read or write local task records. Check permissions and file integrity in ~/.insmind/tasks."
|
|
56
|
-
: "无法读写本地执行记录;请检查 ~/.gd/tasks 的权限和文件完整性。", 1)
|
|
64
|
+
: "无法读写本地执行记录;请检查 ~/.gd/tasks 的权限和文件完整性。", 1, error.context ? [text("保留已有输出;恢复文件访问后查询原任务,不要重新提交创作。", "Keep any output; restore file access and query the original task without submitting again."),
|
|
65
|
+
`${command} task get ${error.context.cli_task_id}`] : undefined, { ...error.context, reason: "task_storage", system_code: systemErrorCode(error) });
|
|
57
66
|
if (error instanceof AuthRequiredError) {
|
|
58
67
|
if (insmind)
|
|
59
68
|
return failure("AUTH_REQUIRED", `Run ${command} auth login first.`, 1, [`${command} auth login`]);
|
|
@@ -65,31 +74,50 @@ export function mapCliError(error, options) {
|
|
|
65
74
|
return failure("AUTH_EXPIRED", "登录已过期,请退出后重新登录。", 1, ["gd-cli auth logout", "gd-cli auth login"]);
|
|
66
75
|
}
|
|
67
76
|
if (error instanceof AuthStateInvalidError) {
|
|
77
|
+
if (error.reason === "local_io")
|
|
78
|
+
return failure("AUTH_STATE_INVALID", text("无法读写本地凭证,当前无法判断登录是否有效。", "Cannot access local credentials; authentication validity is unknown."), 1, [text("恢复凭证文件的访问权限或宿主文件访问能力;不要执行 logout 或删除凭证。", "Restore access to the credential file or host file permissions; do not log out or delete credentials.")], { reason: error.reason, system_code: systemErrorCode(error) });
|
|
68
79
|
if (insmind)
|
|
69
|
-
return failure("AUTH_STATE_INVALID", "Local authentication state is invalid. Sign out and sign in again.", 1, [`${command} auth logout`, `${command} auth login`]);
|
|
70
|
-
return failure("AUTH_STATE_INVALID", "
|
|
80
|
+
return failure("AUTH_STATE_INVALID", "Local authentication state is invalid. Sign out and sign in again.", 1, [`${command} auth logout`, `${command} auth login`], { reason: error.reason });
|
|
81
|
+
return failure("AUTH_STATE_INVALID", "本地登录状态内容无效,请退出后重新登录。", 1, ["gd-cli auth logout", "gd-cli auth login"], { reason: error.reason });
|
|
71
82
|
}
|
|
72
83
|
if (error instanceof OrganizationInvalidError) {
|
|
73
84
|
if (insmind)
|
|
74
85
|
return failure("AUTH_STATE_INVALID", "The account context is unavailable. Sign out and sign in again.", 1, [`${command} auth logout`, `${command} auth login`]);
|
|
75
|
-
return failure("ORG_INVALID", "所选组织不可用,请重新选择组织。", 1, ["gd-cli org switch"]);
|
|
86
|
+
return failure("ORG_INVALID", "所选组织不可用,请重新选择组织。", 1, ["gd-cli org list", "gd-cli org switch --org <org-id>"]);
|
|
76
87
|
}
|
|
77
88
|
if (error instanceof UpdateError) {
|
|
78
|
-
return failure(error.code, error.message, 1, error.nextSteps);
|
|
89
|
+
return failure(error.code, error.message, 1, error.nextSteps, error.details);
|
|
79
90
|
}
|
|
80
91
|
if (error instanceof EditorTargetError) {
|
|
81
92
|
if (insmind)
|
|
82
93
|
return failure(error.code, "Editor target must be a work ID or a complete trusted insMind Editor URL.", 2);
|
|
83
94
|
return failure(error.code, error.message, 2);
|
|
84
95
|
}
|
|
96
|
+
if (error instanceof JsonInputError)
|
|
97
|
+
return failure("USAGE_ERROR", error.reason === "read"
|
|
98
|
+
? text("无法读取 JSON 输入。", "Cannot read the JSON input.")
|
|
99
|
+
: text("JSON 输入语法无效。", "The input is not valid JSON."), 2, [error.reason === "read" ? text("检查输入文件是否存在、是否可读,或 stdin 是否可用。", "Check that the input file exists and is readable, or that stdin is available.")
|
|
100
|
+
: text("修正 JSON 语法后重新执行;输入尚未提交。", "Correct the JSON syntax and run again; the input has not been submitted.")], { reason: `json_${error.reason}`, system_code: systemErrorCode(error) });
|
|
101
|
+
if (error instanceof InputContractError)
|
|
102
|
+
return failure("USAGE_ERROR", text("输入不符合命令要求,请修正所列字段。", "The input does not match the command requirements; correct the listed fields."), 2, [text("使用该命令 --help 中的 Schema 发现入口核对输入。file URL 请用 pathToFileURL(path).href 生成,中文文件名无需改名。", "Use the Schema discovery described in this command's --help. Generate file URLs with pathToFileURL(path).href; Unicode filenames are supported.")], { reason: "schema_validation", issues: error.issues });
|
|
103
|
+
if (error instanceof ToolInputError || error instanceof AgentInputError) {
|
|
104
|
+
const descriptions = {
|
|
105
|
+
model_not_found: ["指定模型不在当前可用目录中。", "The selected model is not in the current catalog."],
|
|
106
|
+
tool_not_found: ["指定工具不在当前可用目录中。", "The selected tool is not in the current catalog."],
|
|
107
|
+
model_tool_mismatch: ["模型不属于所选工具。", "The model does not belong to the selected tool."],
|
|
108
|
+
model_required: ["缺少 model 字段。", "The model field is required."],
|
|
109
|
+
model_parameters: ["参数不符合所选模型要求。", "The arguments do not match the selected model requirements."],
|
|
110
|
+
invalid_asset_url: ["素材 URL 不符合可访问资源要求。", "The asset URL does not meet the accessible resource requirements."]
|
|
111
|
+
};
|
|
112
|
+
const description = descriptions[error.reason];
|
|
113
|
+
return failure("USAGE_ERROR", description ? text(...description) : text("创作输入不可用,请核对模型与参数。", "Check the model and creation arguments."), 2, [`${command} model list`, text(`使用 ${command} model get <model> 核对模型参数;素材应使用安全的 HTTP(S) URL 或本地 file URL。`, `Use ${command} model get <model> to inspect parameters; assets require safe HTTP(S) URLs or local file URLs.`)], { reason: error.reason, field: error.field, ...(error instanceof ToolInputError ? { issues: error.issues } : {}) });
|
|
114
|
+
}
|
|
115
|
+
if (error instanceof LocalFileInputError)
|
|
116
|
+
return failure("USAGE_ERROR", text("本地素材文件不可用于上传。", "The local asset file cannot be uploaded."), 2, [text("检查文件访问权限、文件类型和声明的 mediaType;受保护路径不可上传。", "Check file access, type and declared mediaType; protected paths cannot be uploaded.")], { reason: "local_asset", system_code: systemErrorCode(error) });
|
|
117
|
+
if (error instanceof DamInputError)
|
|
118
|
+
return failure("USAGE_ERROR", text("素材管理参数无效,请根据字段和原因核对命令 --help。", "Invalid asset-management argument; check the field and reason against the command's --help."), 2, undefined, { reason: error.reason, field: error.field });
|
|
85
119
|
if (error instanceof OrgUsageError
|
|
86
120
|
|| error instanceof CliUsageError
|
|
87
|
-
|| error instanceof JsonInputError
|
|
88
|
-
|| error instanceof InputContractError
|
|
89
|
-
|| error instanceof AgentInputError
|
|
90
|
-
|| error instanceof ToolInputError
|
|
91
|
-
|| error instanceof DamInputError
|
|
92
|
-
|| error instanceof LocalFileInputError
|
|
93
121
|
|| error instanceof CommanderError) {
|
|
94
122
|
if (insmind)
|
|
95
123
|
return failure("USAGE_ERROR", "Invalid command or arguments. See --help.", 2);
|
|
@@ -101,9 +129,7 @@ export function mapCliError(error, options) {
|
|
|
101
129
|
return failure("INSUFFICIENT_CREDITS", "当前组织稿豆不足,无法完成本次创作。", 1, INSUFFICIENT_CREDITS_NEXT_STEPS);
|
|
102
130
|
}
|
|
103
131
|
if (error instanceof RemoteProtocolError) {
|
|
104
|
-
|
|
105
|
-
return failure("REMOTE_PROTOCOL_INCOMPATIBLE", "The insMind service returned a result this CLI cannot safely process; processing stopped to avoid duplicate creation.", 1);
|
|
106
|
-
return failure("REMOTE_PROTOCOL_INCOMPATIBLE", "稿定服务返回了当前 CLI 无法安全处理的结果;为避免重复创作,已停止处理。", 1);
|
|
132
|
+
return failure("REMOTE_PROTOCOL_INCOMPATIBLE", text("稿定服务返回了当前 CLI 无法安全处理的结果;为避免重复创作,已停止处理。", "The insMind service returned a result this CLI cannot safely process; processing stopped to avoid duplicate creation."), 1, [text(`保留诊断 ID。若已有任务 ID,用 ${command} task get <id> 查询原任务;查询异常不能证明生成失败,不要重新提交。`, `Keep the diagnostic ID. If a Task ID is available, use ${command} task get <id>. A query error does not prove generation failed; do not resubmit.`)]);
|
|
107
133
|
}
|
|
108
134
|
if (error instanceof ToolTaskFailedError) {
|
|
109
135
|
return failure("TOOL_TASK_FAILED", insmind ? "The Tool task failed." : "稿定工具任务执行失败。", 1);
|
|
@@ -124,10 +150,13 @@ export function mapCliError(error, options) {
|
|
|
124
150
|
? "The destination file already exists and was not overwritten. Choose another output directory."
|
|
125
151
|
: "目标文件已存在,未覆盖任何文件;请更换输出目录或移走同名文件。", 1);
|
|
126
152
|
}
|
|
153
|
+
if (error instanceof DamDownloadError)
|
|
154
|
+
return failure("DAM_DOWNLOAD_FAILED", text("素材下载未完成;请按失败阶段检查源文件访问或目标目录。", "The asset download did not complete; check source access or the destination for the reported phase."), 1, [text("已有素材无需重新生成;先检查文件状态再决定是否重新下载。", "Do not regenerate the asset; inspect file state before downloading again.")], { phase: error.phase, system_code: systemErrorCode(error), http_status: error.status,
|
|
155
|
+
...(error.remainingPaths.length ? { remaining_paths: error.remainingPaths } : {}) });
|
|
127
156
|
if (error instanceof DamOperationUnconfirmedError) {
|
|
128
157
|
return failure("DAM_OPERATION_UNCONFIRMED", insmind
|
|
129
158
|
? "The operation was submitted, but its final result could not be confirmed. Check the destination before retrying."
|
|
130
|
-
: "操作已提交,但未能确认最终结果;请先查询目标位置,不要立即重复提交。", 1);
|
|
159
|
+
: "操作已提交,但未能确认最终结果;请先查询目标位置,不要立即重复提交。", 1, [text(`查询原素材用 ${command} dam get <asset-id>;查询目标位置用 dam list --repository-id <id> --folder-id <id>。删除结果需在回收站核对,不重复提交。`, `Inspect the original asset with ${command} dam get <asset-id>, or the destination with dam list --repository-id <id> --folder-id <id>. Inspect the recycle bin for deletion outcomes before submitting again.`)], { operation: error.operation, ...error.context });
|
|
131
160
|
}
|
|
132
161
|
if (error instanceof DamOperationFailedError) {
|
|
133
162
|
return failure("DAM_OPERATION_FAILED", insmind
|
|
@@ -136,25 +165,38 @@ export function mapCliError(error, options) {
|
|
|
136
165
|
}
|
|
137
166
|
if (error instanceof DamRepositoryNotFoundError) {
|
|
138
167
|
if (insmind)
|
|
139
|
-
return failure("DAM_REPOSITORY_NOT_FOUND", "No accessible asset repository is available for this account.", 1, [
|
|
168
|
+
return failure("DAM_REPOSITORY_NOT_FOUND", "No accessible asset repository is available for this account.", 1, ["Check asset repository access for this account, then run insmind-cli dam repository list."]);
|
|
140
169
|
return failure("DAM_REPOSITORY_NOT_FOUND", "当前组织没有可用的 DAM 资源库。", 1, ["gd-cli org list", "gd-cli org switch --org <org-id>"]);
|
|
141
170
|
}
|
|
171
|
+
if (error instanceof DeviceAuthorizationExpiredError)
|
|
172
|
+
return failure("REMOTE_REQUEST_FAILED", text("本次登录授权已过期,请重新开始授权。", "This login authorization expired; start authorization again."), 1, [`${command} auth login`], { reason: "authorization_expired" });
|
|
142
173
|
if (error instanceof RemoteRequestError
|
|
143
174
|
|| error instanceof SsoRequestError
|
|
144
|
-
|| error instanceof DeviceAuthorizationExpiredError
|
|
145
175
|
|| error instanceof OrganizationResponseError
|
|
146
176
|
|| error instanceof OrganizationBindFailedError
|
|
147
177
|
|| error instanceof ObjectStorageUploadError
|
|
148
178
|
|| error instanceof AuthorizedAccountContextMissingError) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
179
|
+
const reason = error instanceof OrganizationResponseError ? "organization_response"
|
|
180
|
+
: error instanceof OrganizationBindFailedError ? "organization_binding"
|
|
181
|
+
: error instanceof AuthorizedAccountContextMissingError ? "account_context_missing"
|
|
182
|
+
: error instanceof ObjectStorageUploadError ? "asset_upload" : "request";
|
|
183
|
+
const messages = {
|
|
184
|
+
organization_response: ["组织服务返回的数据无法处理。", "The organization response could not be processed."],
|
|
185
|
+
organization_binding: ["未能完成组织绑定。", "Organization binding did not complete."],
|
|
186
|
+
account_context_missing: ["授权响应缺少必要的账号上下文。", "The authorization response is missing the required account context."],
|
|
187
|
+
asset_upload: ["素材上传未完成。", "The asset upload did not complete."],
|
|
188
|
+
request: ["稿定服务请求失败;是否已受理取决于本次请求阶段。", "The service request failed; acceptance depends on the request phase."]
|
|
189
|
+
};
|
|
190
|
+
return failure("REMOTE_REQUEST_FAILED", text(...messages[reason]), 1, [text("创作或写操作若已派发,先查询原任务或对象;不要直接重复提交。使用诊断 ID 排查原因。", "For dispatched creation or write operations, query the original task or object before submitting again. Use the diagnostic ID to investigate.")], { reason, system_code: systemErrorCode(error),
|
|
191
|
+
...((error instanceof RemoteRequestError || error instanceof SsoRequestError) && error.status !== undefined ? { http_status: error.status } : {}) });
|
|
152
192
|
}
|
|
153
193
|
if (error instanceof OutputContractError) {
|
|
154
|
-
|
|
155
|
-
return failure("INTERNAL_ERROR", "CLI result validation failed.", 1);
|
|
156
|
-
return failure("INTERNAL_ERROR", "CLI 内部结果校验失败。", 1);
|
|
194
|
+
return failure("INTERNAL_ERROR", text("CLI 内部结果校验失败,不能确认可交付结果。", "CLI result validation failed; a deliverable result could not be confirmed."), 1, [text("保留诊断 ID;创作或写入可能已发生,先查询原任务或对象。", "Keep the diagnostic ID; creation or changes may have occurred. Query the original task or object first.")], { phase: "output_validation", issues: error.issues });
|
|
157
195
|
}
|
|
196
|
+
if (error instanceof LocalFileError)
|
|
197
|
+
return failure("LOCAL_STATE_ERROR", text("无法访问或解析本地文件,操作未完成。", "A local file could not be accessed or parsed; the operation did not complete."), 1, [text("先检查所列文件的权限、可用空间和内容;不要删除凭证来处理文件故障。", "Check the file's permissions, available space and contents; do not delete credentials to resolve a file failure.")], { reason: error.reason, file: error.file, system_code: systemErrorCode(error) });
|
|
198
|
+
if (error instanceof EditorBridgeUnavailableError)
|
|
199
|
+
return failure("EDITOR_NOT_READY", text("本地 Editor Bridge 连接不可用。", "The local Editor Bridge connection is unavailable."), 1, [text(`先检查原作品状态,再执行 ${command} editor connect [target];不要直接重复写入。`, `Inspect the original work, then run ${command} editor connect [target]; do not repeat writes directly.`)], { phase: "editor_connection" });
|
|
158
200
|
if (error instanceof EditorBridgeError
|
|
159
201
|
|| error instanceof EditorSessionNotFoundError
|
|
160
202
|
|| error instanceof EditorNotReadyError) {
|
|
@@ -163,9 +205,9 @@ export function mapCliError(error, options) {
|
|
|
163
205
|
return failure(error.code, `No Editor session is available. Run ${command} editor connect [target] again.`, 1);
|
|
164
206
|
if (error instanceof EditorNotReadyError)
|
|
165
207
|
return failure(error.code, "The Editor page did not become ready in time.", 1);
|
|
166
|
-
return failure(error.code, "The Editor
|
|
208
|
+
return failure(error.code, error.code === "EDITOR_BRIDGE_INVALID_RESPONSE" ? "The Editor Bridge returned an invalid response." : `Editor: ${redactSensitiveText(error.message).slice(0, 1024)}`, 1, ["For a failed write, inspect the original work before repeating apply or save. Use editor --help for recovery by error code."]);
|
|
167
209
|
}
|
|
168
|
-
return failure(error.code, error.message, 1);
|
|
210
|
+
return failure(error.code, redactSensitiveText(error.message).slice(0, 1024), 1, ["写入失败时先检查原作品,不直接重复 apply 或 save;按 editor --help 中的对应错误指引处理。"]);
|
|
169
211
|
}
|
|
170
212
|
return failure("INTERNAL_ERROR", insmind ? "The CLI encountered an internal error." : "CLI 发生内部错误。", 1);
|
|
171
213
|
}
|
|
@@ -175,19 +217,20 @@ function isInsufficientCreditsError(error) {
|
|
|
175
217
|
|| error instanceof ToolTaskFailedError) && error.remoteCode === INSUFFICIENT_CREDITS_REMOTE_CODE;
|
|
176
218
|
}
|
|
177
219
|
export function classifyTelemetryError(error, options = {}) {
|
|
178
|
-
const outcome = mapCliError(error, { ...options, aborted: options.aborted === true
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
||
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
220
|
+
const outcome = mapCliError(error, { ...options, aborted: options.aborted === true });
|
|
221
|
+
let remoteError;
|
|
222
|
+
for (let cause = error, depth = 0; cause instanceof Error && depth < 10; cause = cause.cause, depth++) {
|
|
223
|
+
if (cause instanceof RemoteRequestError || cause instanceof RemoteProtocolError || cause instanceof ToolTaskFailedError
|
|
224
|
+
|| cause instanceof SsoRequestError || cause instanceof OrganizationBindFailedError) {
|
|
225
|
+
remoteError = cause;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
186
229
|
return {
|
|
187
230
|
outcome: outcome.kind === "interrupted" ? "interrupted" : "failure",
|
|
188
231
|
...(outcome.kind === "failure" ? { errorCode: outcome.failure.code } : {}),
|
|
189
|
-
...((
|
|
190
|
-
? { httpStatus:
|
|
232
|
+
...((remoteError instanceof RemoteRequestError || remoteError instanceof SsoRequestError) && remoteError.status !== undefined
|
|
233
|
+
? { httpStatus: remoteError.status }
|
|
191
234
|
: {}),
|
|
192
235
|
...(remoteError?.remoteCode === undefined
|
|
193
236
|
? {}
|
|
@@ -197,14 +240,21 @@ export function classifyTelemetryError(error, options = {}) {
|
|
|
197
240
|
: { remoteErrorBody: remoteError.remoteBody })
|
|
198
241
|
};
|
|
199
242
|
}
|
|
200
|
-
function failure(code, message, exitCode, nextSteps) {
|
|
243
|
+
function failure(code, message, exitCode, nextSteps, details) {
|
|
201
244
|
return {
|
|
202
245
|
kind: "failure",
|
|
203
246
|
failure: {
|
|
204
247
|
code,
|
|
205
248
|
message,
|
|
206
|
-
...(nextSteps ? { details: { next_steps: nextSteps } } : {})
|
|
249
|
+
...(nextSteps || details ? { details: { ...details, ...(nextSteps ? { next_steps: nextSteps } : {}) } } : {})
|
|
207
250
|
},
|
|
208
251
|
exitCode
|
|
209
252
|
};
|
|
210
253
|
}
|
|
254
|
+
function systemErrorCode(error) {
|
|
255
|
+
for (let depth = 0; error instanceof Error && depth < 10; depth++, error = error.cause) {
|
|
256
|
+
if ("code" in error && typeof error.code === "string" && /^E[A-Z0-9_]{1,40}$/u.test(error.code))
|
|
257
|
+
return error.code;
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bindAction } from "./action-binding.js";
|
|
1
|
+
import { jsonOutput, bindAction } from "./action-binding.js";
|
|
2
2
|
import { CliUsageError } from "./errors.js";
|
|
3
3
|
import { productText as text } from "../product/text.js";
|
|
4
4
|
export function registerModelCommands(program, runtime) {
|
|
@@ -9,8 +9,11 @@ export function registerModelCommands(program, runtime) {
|
|
|
9
9
|
.description(text(runtime.product, "列出图片/视频生成模型(不含独立风格)", "List image/video generation models (excluding standalone styles)"))
|
|
10
10
|
.option("--tool <tool>", text(runtime.product, "按工具筛选", "filter by tool"))
|
|
11
11
|
.allowExcessArguments(false);
|
|
12
|
+
jsonOutput(list);
|
|
12
13
|
bindAction(list, "organization", async (context, signal) => {
|
|
13
14
|
const selectedTool = list.opts().tool;
|
|
15
|
+
if (selectedTool !== undefined)
|
|
16
|
+
runtime.telemetry.annotate({ tool_name: selectedTool });
|
|
14
17
|
const input = selectedTool === undefined ? {} : { tool: selectedTool };
|
|
15
18
|
await runtime.telemetry.stage("input", async () => {
|
|
16
19
|
runtime.validators.modelListInput(input);
|
|
@@ -23,8 +26,6 @@ export function registerModelCommands(program, runtime) {
|
|
|
23
26
|
},
|
|
24
27
|
signal
|
|
25
28
|
});
|
|
26
|
-
if (selectedTool !== undefined)
|
|
27
|
-
runtime.telemetry.annotate({ tool_name: selectedTool });
|
|
28
29
|
await runtime.telemetry.stage("output", async () => {
|
|
29
30
|
runtime.validators.modelListOutput(result);
|
|
30
31
|
runtime.io.writeOut(`${JSON.stringify(result)}\n`);
|
|
@@ -42,10 +43,12 @@ export function registerModelCommands(program, runtime) {
|
|
|
42
43
|
text(runtime.product, "usageDescription 说明跨字段组合规则。tool call <tool> --schema 是 Tool 级参数并集,不能代替本 Model 的要求。Agent 只传显式生成约束,不照搬 Tool 的完整必填参数。", "usageDescription explains cross-field combinations. tool call <tool> --schema is a tool-wide union, not this Model's exact requirements. For Agent, pass explicit generation constraints rather than copying every Tool-required parameter."),
|
|
43
44
|
""
|
|
44
45
|
].join("\n"));
|
|
46
|
+
jsonOutput(get);
|
|
45
47
|
bindAction(get, "organization", async (context, signal) => {
|
|
46
48
|
const modelName = get.processedArgs[0];
|
|
47
49
|
if (typeof modelName !== "string" || modelName.trim() === "")
|
|
48
50
|
throw new CliUsageError();
|
|
51
|
+
runtime.telemetry.annotate({ model_id: modelName });
|
|
49
52
|
const input = { model: modelName };
|
|
50
53
|
await runtime.telemetry.stage("input", async () => {
|
|
51
54
|
runtime.validators.modelGetInput(input);
|
|
@@ -59,7 +62,6 @@ export function registerModelCommands(program, runtime) {
|
|
|
59
62
|
access,
|
|
60
63
|
signal
|
|
61
64
|
});
|
|
62
|
-
runtime.telemetry.annotate({ model_id: modelName });
|
|
63
65
|
await runtime.telemetry.stage("output", async () => {
|
|
64
66
|
runtime.validators.modelGetOutput(result);
|
|
65
67
|
runtime.io.writeOut(`${JSON.stringify(result)}\n`);
|