@insmind/cli 2.1.0 → 2.1.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/README.md +30 -0
- package/contracts/operations/agent.send/input.schema.json +1 -77
- package/contracts/operations/dam.folder.list/input.schema.json +0 -1
- package/contracts/operations/dam.folder.list/output.schema.json +1 -2
- package/contracts/operations/dam.list/input.schema.json +3 -6
- package/contracts/operations/dam.list/output.schema.json +1 -2
- package/contracts/operations/dam.search/input.schema.json +3 -6
- package/contracts/operations/dam.search/output.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-edit-smart.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-expand-smart.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-layers-smart.schema.json +1 -3
- package/contracts/operations/tool.call/models/video-edit-smart.schema.json +0 -3
- package/contracts/operations/tool.call/ocr-payload.schema.json +4 -5
- package/dist/bin/postinstall.js +22 -6
- package/dist/bin/sync-skill.js +33 -0
- package/dist/bin/task-worker.js +2 -2
- package/dist/src/bootstrap/create-cli.js +13 -6
- package/dist/src/bootstrap/create-runtime.js +103 -29
- package/dist/src/bootstrap/run-task-worker.js +6 -2
- package/dist/src/bootstrap/validators.js +87 -151
- package/dist/src/cli/action-binding.js +14 -37
- package/dist/src/cli/agent-commands.js +13 -13
- package/dist/src/cli/auth-commands.js +2 -1
- package/dist/src/cli/creation-help.js +9 -0
- package/dist/src/cli/dam-commands.js +10 -14
- package/dist/src/cli/editor-commands.js +16 -12
- package/dist/src/cli/errors.js +84 -26
- package/dist/src/cli/host-input.js +62 -5
- package/dist/src/cli/model-commands.js +9 -3
- package/dist/src/cli/observed-errors.js +7 -3
- package/dist/src/cli/org-commands.js +3 -1
- package/dist/src/cli/presenter.js +4 -5
- package/dist/src/cli/task-commands.js +6 -2
- package/dist/src/cli/tool-commands.js +12 -11
- package/dist/src/contracts/creation-input.js +20 -17
- package/dist/src/features/agent/creative-agent-adapter.js +6 -2
- package/dist/src/features/agent/creative-protocol.js +8 -29
- package/dist/src/features/agent/resource-authorizer.js +25 -17
- package/dist/src/features/agent/result-reader.js +31 -14
- package/dist/src/features/agent/use-cases.js +6 -31
- package/dist/src/features/auth/credential-store.js +1 -0
- package/dist/src/features/credits/use-cases.js +55 -28
- package/dist/src/features/dam/asset-projection.js +3 -6
- package/dist/src/features/dam/dam-api-adapter.js +30 -15
- package/dist/src/features/dam/object-storage.js +2 -1
- package/dist/src/features/dam/repository-catalog.js +30 -21
- package/dist/src/features/dam/use-cases.js +14 -9
- package/dist/src/features/editor/bridge-client.js +0 -2
- package/dist/src/features/editor/bridge-process.js +3 -2
- package/dist/src/features/editor/public-url.js +1 -36
- package/dist/src/features/editor/session-state.js +1 -0
- package/dist/src/features/editor/session.js +3 -2
- package/dist/src/features/editor/use-cases.js +27 -2
- package/dist/src/features/org/org-service.js +10 -1
- package/dist/src/features/org/use-cases.js +18 -4
- package/dist/src/features/task/process-owner.js +54 -0
- package/dist/src/features/task/store.js +102 -32
- package/dist/src/features/task/task-background.js +8 -4
- package/dist/src/features/task/use-cases.js +184 -84
- package/dist/src/features/tool/argument-paths.js +14 -0
- package/dist/src/features/tool/canvas-copy.js +28 -15
- package/dist/src/features/tool/canvas-matting.js +123 -0
- package/dist/src/features/tool/canvas-media.js +102 -55
- package/dist/src/features/tool/canvas-models.js +66 -33
- package/dist/src/features/tool/canvas-pricing.js +12 -0
- package/dist/src/features/tool/canvas-recovery.js +13 -30
- package/dist/src/features/tool/canvas-results.js +92 -93
- package/dist/src/features/tool/canvas-tool-adapter.js +134 -157
- package/dist/src/features/tool/canvas-video.js +44 -37
- package/dist/src/features/tool/catalog.js +2 -23
- package/dist/src/features/tool/dynamic-schema.js +42 -46
- package/dist/src/features/tool/ffprobe-executable.js +21 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +61 -24
- package/dist/src/features/tool/resource-authorizer.js +11 -3
- package/dist/src/features/tool/tool-api-adapter.js +73 -82
- package/dist/src/features/tool/tool-definitions.js +23 -0
- package/dist/src/features/tool/tool-errors.js +25 -0
- package/dist/src/features/tool/tool-output.js +15 -0
- package/dist/src/features/tool/use-cases.js +74 -98
- package/dist/src/features/update/package-manager.js +124 -0
- package/dist/src/features/update/update-service.js +195 -55
- package/dist/src/platform/detached-spawn.js +9 -0
- package/dist/src/platform/file-lock.js +12 -4
- package/dist/src/platform/input-uri.js +23 -1
- package/dist/src/platform/local-json-file.js +97 -15
- package/dist/src/platform/media-type.js +46 -0
- package/dist/src/platform/open-browser.js +5 -2
- package/dist/src/platform/public-url.js +35 -0
- package/dist/src/platform/remote-error-evidence.js +33 -6
- package/dist/src/platform/resource-auth-key.js +35 -1
- package/dist/src/platform/safe-upload-file.js +38 -44
- package/dist/src/platform/schema-compiler.js +16 -0
- package/dist/src/platform/signature.js +2 -2
- package/dist/src/platform/signed-http-transport.js +4 -1
- package/dist/src/platform/url-safety.js +6 -1
- package/dist/src/platform/webm-header.js +41 -0
- package/dist/src/platform/windows-acl/LICENSE-mingw-w64 +43 -0
- package/dist/src/platform/windows-acl/arm64.node +0 -0
- package/dist/src/platform/windows-acl/ia32.node +0 -0
- package/dist/src/platform/windows-acl/x64.node +0 -0
- package/dist/src/platform/windows-host-job/arm64.exe +0 -0
- package/dist/src/platform/windows-host-job/ia32.exe +0 -0
- package/dist/src/platform/windows-host-job/sha256.json +7 -0
- package/dist/src/platform/windows-host-job/x64.exe +0 -0
- package/dist/src/platform/windows-private-state.js +72 -0
- package/dist/src/product/config.js +1 -1
- package/dist/src/telemetry/command-route.js +38 -0
- package/dist/src/telemetry/command-routes.json +1 -0
- package/dist/src/telemetry/failure-summary.js +3 -3
- package/dist/src/telemetry/invocation.js +1 -2
- package/dist/src/telemetry/process-errors.js +17 -33
- package/dist/src/telemetry/sanitize.js +19 -4
- package/dist/src/telemetry/sls-sink.js +45 -20
- package/package.json +4 -4
- package/skills/insmind-cli/SKILL.md +18 -5
- package/skills/insmind-cli/references/agent.md +9 -4
- package/skills/insmind-cli/references/creation.md +3 -1
- package/skills/insmind-cli/references/editor.md +7 -5
- package/skills/insmind-cli/references/errors.md +20 -9
- package/skills/insmind-cli/references/matting.md +3 -5
- package/skills/insmind-cli/references/media-tools.md +10 -4
- package/skills/insmind-cli/references/tool.md +9 -15
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { identifyInvocation } from "../telemetry/command-route.js";
|
|
1
2
|
import { jsonErrorsRequested } from "../platform/error-output-mode.js";
|
|
2
3
|
const environments = new WeakMap();
|
|
3
4
|
const boundPolicies = new WeakMap();
|
|
@@ -106,44 +107,20 @@ function annotateAccessContext(telemetry, context) {
|
|
|
106
107
|
organization_id: context.state.organization?.id
|
|
107
108
|
});
|
|
108
109
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
let command = program;
|
|
112
|
-
let unknown = false;
|
|
113
|
-
let mode = "execute";
|
|
114
|
-
for (let i = 0; i < argv.length; i++) {
|
|
115
|
-
const token = argv[i];
|
|
116
|
-
if (token === "--")
|
|
117
|
-
break;
|
|
118
|
-
if (token === "-h" || token === "--help") {
|
|
119
|
-
mode = "help";
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (token === "-V" || token === "--version") {
|
|
123
|
-
mode = "version";
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
if (token.startsWith("-")) {
|
|
127
|
-
const flag = token.split("=")[0];
|
|
128
|
-
const option = [...command.options, ...program.options].find(item => item.long === flag || item.short === flag);
|
|
129
|
-
if (option?.long === "--schema" && mode === "execute")
|
|
130
|
-
mode = "schema";
|
|
131
|
-
if (option?.required && !token.includes("="))
|
|
132
|
-
i++;
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
if (command.commands.length) {
|
|
136
|
-
const child = command.commands.find(item => item.name() === token || item.aliases().includes(token));
|
|
137
|
-
if (!child) {
|
|
138
|
-
unknown = true;
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
command = child;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
110
|
+
export function commandRoute(command) {
|
|
111
|
+
const definition = commandDefinitions.get(command);
|
|
144
112
|
const path = commandPath(command).split(" ").slice(1).join(".");
|
|
145
|
-
const
|
|
146
|
-
|
|
113
|
+
const children = Object.create(null);
|
|
114
|
+
for (const child of command.commands) {
|
|
115
|
+
const route = commandRoute(child);
|
|
116
|
+
for (const name of [child.name(), ...child.aliases()])
|
|
117
|
+
children[name] = route;
|
|
118
|
+
}
|
|
119
|
+
return { operation: definition?.operation ?? (path || "unknown"), action: !!definition,
|
|
120
|
+
options: command.options.map(option => option.flags), children };
|
|
121
|
+
}
|
|
122
|
+
export function invocationDefinition(program, argv) {
|
|
123
|
+
return identifyInvocation(commandRoute(program), argv);
|
|
147
124
|
}
|
|
148
125
|
function commandPath(command) {
|
|
149
126
|
const names = [];
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
+
import { creationTaskHelp } from "./creation-help.js";
|
|
1
2
|
import { hostSchema, readHostInput } from "./host-input.js";
|
|
2
|
-
import {
|
|
3
|
+
import { readAgentInputSchema } from "../contracts/creation-input.js";
|
|
3
4
|
import { jsonOutput, bindPreparedAction } from "./action-binding.js";
|
|
4
5
|
import { CliUsageError } from "./errors.js";
|
|
5
6
|
import { productText as text } from "../product/text.js";
|
|
6
7
|
export function registerAgentCommands(program, runtime) {
|
|
7
8
|
const agent = program.command("agent")
|
|
8
|
-
.description(text(runtime.product, "
|
|
9
|
+
.description(text(runtime.product, "业务策划与持续多轮创作", "Business planning and multi-turn creation"))
|
|
9
10
|
.helpCommand(false);
|
|
10
11
|
const send = agent.command("send")
|
|
11
|
-
.description(text(runtime.product, "
|
|
12
|
+
.description(text(runtime.product, "发送创作消息,等待本轮回复、成品或补充问题", "Send a creation message and wait for this turn's reply, assets or questions"))
|
|
12
13
|
.option("--schema", text(runtime.product, "输出输入 Schema", "output the input Schema"))
|
|
13
14
|
.option("--input <file|->", text(runtime.product, "从文件或标准输入读取 JSON", "read JSON from a file or stdin"))
|
|
14
15
|
.option("--async", text(runtime.product, "提交后返回 taskId,通过 task get 查询结果", "return taskId after submission; retrieve results with task get"))
|
|
15
16
|
.allowExcessArguments(false);
|
|
16
17
|
send.addHelpText("after", [
|
|
17
18
|
"",
|
|
19
|
+
text(runtime.product, "用于业务策划、多步骤或持续创作;明确的单次媒体处理也可从 tool list 发现。先保存完整 JSON 再用 --input request.json 执行;--input - 必须在同一条 shell 命令中经管道或重定向提供完整 JSON,不交互填参。", "Use for planning, multiple steps or continuing creation; discover atomic media processing with tool list. Save complete JSON before using --input request.json. With --input -, pipe or redirect complete JSON in the same shell command; input is not an interactive form."),
|
|
18
20
|
text(runtime.product, "完整结果已校验但最终本地记录保存失败时仍返回结果和退出码 0;stderr 警告 task get 可能无法恢复,请保留输出。", "A validated complete result is delivered with exit code 0 even if its final local record cannot be saved; stderr warns that task get may not recover it. Keep the output."),
|
|
19
21
|
text(runtime.product, "最终错误为 stderr 中的 JSON error 对象;stderr 也可能有进度和警告。中断退出码 130 只表示本地停止等待。", "The final error is a JSON error object on stderr, which may also contain progress and warnings. Exit code 130 means local waiting stopped."),
|
|
20
|
-
|
|
21
|
-
text(runtime.product, "
|
|
22
|
-
text(runtime.product, "Agent 异步由本机后台进程继续执行;进程终止或关机可能使状态变为 unknown。", "Agent async continues in a local background process; termination or shutdown may leave its state unknown."),
|
|
23
|
-
text(runtime.product, "中断前台等待不会取消已交接的后台任务;仍用原 taskId 查询。", "Interrupting the foreground wait does not cancel a handed-off task; query the same taskId."),
|
|
24
|
-
text(runtime.product, "默认在当前进程等待最终结果,成功后一次输出 JSON。", "By default, the command waits in the current process and returns the final result as one JSON object."),
|
|
25
|
-
text(runtime.product, "运行中请继续等待原进程;已提交但结果未知时,不要重复提交。", "Wait for the original process. Do not resubmit a creation whose outcome is unknown."),
|
|
26
|
-
text(runtime.product, "默认模式在 stderr 提示任务 ID,stdout 保持原结果 JSON。", "In default mode the Task ID is written to stderr; stdout contains only the original result JSON."),
|
|
27
|
-
text(runtime.product, `结果未收到时执行 ${runtime.product.commandName} task list 找到原调用,再执行 ${runtime.product.commandName} task get <id> 查询。`, `If output is missing, find the original run with ${runtime.product.commandName} task list, then query ${runtime.product.commandName} task get <id>.`),
|
|
22
|
+
...creationTaskHelp(runtime.product),
|
|
23
|
+
text(runtime.product, "本机后台进程终止或关机可能使 Agent 任务变为 unknown。", "If the local background process stops or the machine shuts down, an Agent task may become unknown."),
|
|
28
24
|
text(runtime.product, "首次创作省略 JSON 中的 message.contextId;续聊时传入上次结果的 message.contextId。", "Omit message.contextId for the first creation. Continue a conversation using message.contextId from the previous result."),
|
|
25
|
+
text(runtime.product, "completed 表示本轮 Agent 已完整回复,可能是文本、资源或补充/确认问题,并不保证已生成成品。转述实际回复;需要用户回答时询问用户,收到回答后沿用 contextId 发送下一轮。", "completed means the Agent's turn has fully replied with text, assets or clarification/confirmation questions; it does not guarantee a finished asset. Relay the actual reply, ask the user when an answer is needed, then continue with the same contextId."),
|
|
26
|
+
text(runtime.product, "把本轮实际回复或资源连同 usage.cost.amount 的实际消耗一并交付。同步从输出读取,异步从 completed 的 result 读取。返回 0 就报 0,缺失则说明未取得。汇总按不同 taskId,同一任务重复读取只计一次。Tool minimum/maximum 是目录估价。", "Deliver this turn's reply or assets together with the actual charge in usage.cost.amount. Read it from the synchronous output or the completed task's result. Report 0 when present, and unknown when absent. Count each distinct taskId once. Tool minimum/maximum are catalog estimates."),
|
|
27
|
+
text(runtime.product, "结构化问题位于 message.parts[].data.questions;回答时将 message.messageId 写入 data.questionMessageId,answers 保留 question 原文及用户 values,该 data Part 是本轮 parts 唯一一项。普通文本续聊使用 text Part。", "Structured questions are in message.parts[].data.questions. Reply with message.messageId as data.questionMessageId and answers containing the original question and the user's values; this data Part must be the sole Part. Use a text Part for ordinary follow-up conversation."),
|
|
29
28
|
text(runtime.product, "可用 model 和参数示例见 model list / model get。显式 model 和 arguments 会传给 Agent,编辑模型的已知别名转换为服务字段。文本和素材用独立 Part。", "Discover models and example controls with model list and model get. Explicit model and arguments are sent to the Agent, with known editing aliases mapped to service fields. Supply text and assets as separate Parts."),
|
|
30
|
-
text(runtime.product, "
|
|
29
|
+
text(runtime.product, "交付服务返回的资源时,原样使用完整 URL 及查询参数;不凭记忆重写、拼接或去掉授权参数。诊断凭证脱敏不改变可交付资源链接。", "Deliver service resources using the complete returned URL and query parameters. Do not reconstruct, splice or strip authorization parameters. Diagnostic credential redaction does not alter delivery links."),
|
|
30
|
+
text(runtime.product, "素材用独立 URL Part;本地文件用 Path(path).resolve().as_uri() 或 pathToFileURL(path).href 生成标准 URI,保留顺序和 metadata.role。--input 的 JSON 文件参数仍使用路径。", "Supply assets as separate URL Parts, preserving order and metadata.role. Generate local URIs with Path(path).resolve().as_uri() or pathToFileURL(path).href. The --input JSON file argument remains a path."),
|
|
31
31
|
""
|
|
32
32
|
].join("\n"));
|
|
33
33
|
jsonOutput(send);
|
|
@@ -39,7 +39,7 @@ export function registerAgentCommands(program, runtime) {
|
|
|
39
39
|
throw new CliUsageError();
|
|
40
40
|
if (options.schema === true) {
|
|
41
41
|
await runtime.telemetry.stage("output", async () => {
|
|
42
|
-
runtime.io.writeOut(`${JSON.stringify(hostSchema(runtime,
|
|
42
|
+
runtime.io.writeOut(`${JSON.stringify(hostSchema(runtime, readAgentInputSchema()))}\n`);
|
|
43
43
|
});
|
|
44
44
|
return { handled: true };
|
|
45
45
|
}
|
|
@@ -6,6 +6,7 @@ export function registerAuthCommands(program, runtime) {
|
|
|
6
6
|
const auth = program.command("auth")
|
|
7
7
|
.description(text(runtime.product, "登录与本机凭证", "Authentication and local credentials"))
|
|
8
8
|
.helpCommand(false);
|
|
9
|
+
auth.addHelpText("after", text(runtime.product, "\n管理本机 CLI 登录;不替代 Editor 浏览器登录。status 只读状态,login 等待浏览器授权完成,logout 清除本机共享登录。授权链接不等于登录成功;无需提供或读取 AK/SK、Cookie 等凭证。\n", "\nManages the local CLI identity, separately from Editor browser login. status reads state, login waits for browser authorization, and logout clears the shared local sign-in. An authorization URL is not successful login; do not provide or read credential values.\n"));
|
|
9
10
|
const login = leaf(auth.command("login"))
|
|
10
11
|
.description(text(runtime.product, "登录稿定", "Sign in to insMind"))
|
|
11
12
|
.option("--no-browser", text(runtime.product, "不自动打开浏览器", "do not open a browser automatically"))
|
|
@@ -51,7 +52,7 @@ export function registerAuthCommands(program, runtime) {
|
|
|
51
52
|
});
|
|
52
53
|
});
|
|
53
54
|
}, { operation: "auth.status" });
|
|
54
|
-
const logout = leaf(auth.command("logout")).description(text(runtime.product, "退出登录", "Sign out"));
|
|
55
|
+
const logout = leaf(auth.command("logout")).description(text(runtime.product, "退出登录", "Sign out")).addHelpText("after", text(runtime.product, "\n清除本机 CLI 凭证及当前组织选择,会影响复用这份登录的其他入口;不删除云端素材或作品。\n", "\nClears local CLI credentials and the current identity context, affecting other entry points sharing this sign-in. It does not delete cloud assets or works.\n"));
|
|
55
56
|
bindAction(logout, "none", async () => {
|
|
56
57
|
await runtime.auth.logout();
|
|
57
58
|
await runtime.telemetry.stage("output", async () => {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { productText } from "../product/text.js";
|
|
2
|
+
export function creationTaskHelp(product) {
|
|
3
|
+
return [
|
|
4
|
+
productText(product, "现在要结果时默认同步。保留宿主返回的退出状态和进程句柄,进程仍在运行就继续等待原进程,直到 stdout 给出完整结果或命令报错。", "For a result now, use the default synchronous command. Keep the host's exit status and process handle. While it is running, wait on that process for the complete stdout result or an error."),
|
|
5
|
+
productText(product, "失去进程句柄时,用 stderr 提示的 taskId 执行 task get <taskId>。没有 ID 时用 task list 定位原调用。现在要交付且 state=running 时隔数秒继续查原 ID。", "If the process handle is lost, use task get <taskId> with the ID from stderr, or locate the call with task list. For delivery now, keep checking the same ID every few seconds while state is running."),
|
|
6
|
+
productText(product, "用户明确稍后取回时用 --async。受理后立即向用户返回 taskId 和当前 state,本轮到此结束。用户回来时用同一 ID 取结果。退出码 0 在此表示已受理。", "For later pickup, use --async. As soon as it is accepted, return the taskId and current state to the user and end this turn. When they return, retrieve the result with that ID. Exit 0 here means accepted."),
|
|
7
|
+
productText(product, "异步由本机后台进程继续执行。退出前台不会取消已交接的任务。unknown 或查询超时只能说明结果待确认,请查原任务,勿另发创作。", "Async work continues in a local background process. Leaving the foreground does not cancel accepted work. On unknown or a query timeout, check the original task without resubmitting.")
|
|
8
|
+
];
|
|
9
|
+
}
|
|
@@ -11,6 +11,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
11
11
|
"",
|
|
12
12
|
text(runtime.product, "先通过 repository list、folder list、tag list 或资源查询取得真实 ID,再操作;名称、前端 URL 和旧缓存不能代替 ID。", "Discover real IDs with repository list, folder list, tag list or asset queries before acting; names, frontend URLs and old caches are not IDs."),
|
|
13
13
|
text(runtime.product, "支持的命令以本 help 为准;读取所选子命令的 --help 获取参数、作用范围和输出形式。", "Available commands are listed here; read the selected subcommand's --help for parameters, scope and output mode."),
|
|
14
|
+
text(runtime.product, "资源库 ID 与组织 ID 不同。团队/企业资料显式传查询到的 repository_id;list/search/upload 省略资源库时默认个人库。素材处理使用详情中的资源链接或下载后的本地文件,再从 tool list 发现处理能力。", "Repository IDs differ from organization IDs. Pass a discovered repository_id for team/enterprise assets; list/search/upload default to the personal repository when omitted. To process an asset, use its resource link or downloaded file and discover processing with tool list."),
|
|
14
15
|
text(runtime.product, "写入结果未确认时先查询实际状态,不重复提交。跨资源库查询、受保护路径上传和永久删除须有用户明确授权。", "Inspect actual state before retrying an unconfirmed write. Cross-repository queries, protected-path uploads and permanent deletion require explicit user authorization."),
|
|
15
16
|
""
|
|
16
17
|
].join("\n"));
|
|
@@ -41,7 +42,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
41
42
|
.option("--parent-id <id>", text(runtime.product, "父文件夹 ID", "parent folder ID"))
|
|
42
43
|
.option("--query <text>", text(runtime.product, "按名称筛选", "filter by name"))
|
|
43
44
|
.option("--page <n>", text(runtime.product, "页码", "page number"), positiveInteger)
|
|
44
|
-
.option("--page-size <
|
|
45
|
+
.option("--page-size <number>", text(runtime.product, "分页大小", "page size"), positiveInteger)
|
|
45
46
|
.option("--json", text(runtime.product, "输出 JSON", "output JSON"));
|
|
46
47
|
bindPreparedAction(folderList, "organization", async (signal) => {
|
|
47
48
|
signal.throwIfAborted();
|
|
@@ -294,6 +295,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
294
295
|
.option("--allow-sensitive-path", text(runtime.product, "明确允许受保护路径", "allow a protected local path"))
|
|
295
296
|
.option("--wait-analysis", text(runtime.product, "等待素材分析结束", "wait for asset analysis"))
|
|
296
297
|
.option("--json", text(runtime.product, "输出 JSON", "output JSON"));
|
|
298
|
+
upload.addHelpText("after", text(runtime.product, "\n<file> 是本地文件路径(不是 file URI);路径含空格时按 shell 规则引用。默认上传个人库根目录 0,标题默认取不含扩展名的文件名;团队位置显式传资源库和文件夹 ID。返回素材详情表示已创建;--wait-analysis 额外等待分析,未知写入先查目标位置,不重复上传。\n", "\n<file> is a local path, not a file URI; quote spaces for the shell. Defaults to personal repository root 0 and a title from the filename without its extension. Specify repository/folder IDs for team destinations. Returned asset details confirm creation; --wait-analysis also waits for analysis. Inspect the destination before repeating an unconfirmed upload.\n"));
|
|
297
299
|
bindPreparedAction(upload, "organization", async (signal) => {
|
|
298
300
|
signal.throwIfAborted();
|
|
299
301
|
const options = upload.opts();
|
|
@@ -364,9 +366,10 @@ function browseCommand(command, runtime) {
|
|
|
364
366
|
.option("--type <type>", text(runtime.product, "素材类型", "asset type"))
|
|
365
367
|
.option("--asset-format <csv>", text(runtime.product, "文件格式,逗号分隔", "comma-separated file formats"))
|
|
366
368
|
.option("--tag-ids <csv>", text(runtime.product, "标签 ID,逗号分隔", "comma-separated tag IDs"))
|
|
367
|
-
.option("--page-size <
|
|
368
|
-
.option("--cursor <id>", text(runtime.product, "
|
|
369
|
-
.option("--json", text(runtime.product, "输出 JSON", "output JSON"))
|
|
369
|
+
.option("--page-size <number>", text(runtime.product, "请求分页大小", "request page size"), positiveInteger)
|
|
370
|
+
.option("--cursor <id>", text(runtime.product, "原样使用上一页 next_cursor,并保持相同筛选", "reuse the previous next_cursor unchanged with the same filters"))
|
|
371
|
+
.option("--json", text(runtime.product, "输出 JSON", "output JSON"))
|
|
372
|
+
.addHelpText("after", text(runtime.product, "\n默认个人资源库,每页 20 条,包含子文件夹;finish=false 时用 next_cursor 继续同范围查询,本页不代表全部结果。空结果不证明其他资源库不存在该素材;按用户指定范围核对资源库和筛选。\n", "\nDefaults to the personal repository, 20 items and inclusion of child folders. When finish=false, continue with next_cursor and unchanged scope; one page is not the entire result. An empty page says nothing about other repositories; check the user's intended repository and filters.\n"));
|
|
370
373
|
}
|
|
371
374
|
function browseInput(command) {
|
|
372
375
|
const options = command.opts();
|
|
@@ -388,15 +391,7 @@ function defined(key, value) {
|
|
|
388
391
|
return value === undefined ? {} : { [key]: value };
|
|
389
392
|
}
|
|
390
393
|
function csv(value) {
|
|
391
|
-
return value?.split(",").map((item) => item.trim())
|
|
392
|
-
}
|
|
393
|
-
function pageSize(value) {
|
|
394
|
-
if (!/^\d+$/u.test(value))
|
|
395
|
-
throw new CliUsageError();
|
|
396
|
-
const parsed = Number(value);
|
|
397
|
-
if (!Number.isInteger(parsed) || parsed < 1 || parsed > 100)
|
|
398
|
-
throw new CliUsageError();
|
|
399
|
-
return parsed;
|
|
394
|
+
return value?.split(",").map((item) => item.trim());
|
|
400
395
|
}
|
|
401
396
|
function positiveInteger(value) {
|
|
402
397
|
if (!/^\d+$/u.test(value))
|
|
@@ -424,7 +419,8 @@ function assetListView(value, product) {
|
|
|
424
419
|
`${text(product, "资源库", "Repositories")}: ${result.repository_ids.join(", ")}`,
|
|
425
420
|
`${text(product, "本批 / 总数", "This batch / total")}: ${result.assets.length} / ${result.total}`,
|
|
426
421
|
result.finish ? text(product, "已到最后一页。", "Last page.")
|
|
427
|
-
: text(product,
|
|
422
|
+
: !result.next_cursor ? text(product, "服务提示还有结果,但未返回可用游标,无法续页。", "More results are indicated, but the service supplied no cursor.")
|
|
423
|
+
: text(product, `还有下一页;保留筛选条件,使用 --cursor ${result.next_cursor ?? "<cursor>"} 查询。`, `More results; keep the same filters and query with --cursor ${result.next_cursor ?? "<cursor>"}.`),
|
|
428
424
|
...(result.assets.length ? [text(product, "ID\t标题\t类型\t格式", "ID\tTitle\tType\tFormat"), ...result.assets.map(assetRow)]
|
|
429
425
|
: [text(product, "暂无素材。", "No assets.")])
|
|
430
426
|
].join("\n");
|
|
@@ -3,31 +3,34 @@ import { jsonOutput, bindAction, bindPreparedAction } from "./action-binding.js"
|
|
|
3
3
|
import { contractSchema } from "../contracts/schema.js";
|
|
4
4
|
import { CliUsageError } from "./errors.js";
|
|
5
5
|
import { productText as text } from "../product/text.js";
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.
|
|
11
|
-
}
|
|
6
|
+
function editorApplyInputSchema() {
|
|
7
|
+
const { $defs, ...actionArray } = contractSchema("editor.apply", "input");
|
|
8
|
+
return {
|
|
9
|
+
type: "object", additionalProperties: false, required: ["actions"], properties: { actions: actionArray },
|
|
10
|
+
$defs: Object.fromEntries(Object.entries($defs)
|
|
11
|
+
.map(([name, definition]) => [name, { ...definition, additionalProperties: true }]))
|
|
12
|
+
};
|
|
13
|
+
}
|
|
12
14
|
export function registerEditorCommands(program, runtime) {
|
|
13
15
|
const editor = program.command("editor")
|
|
14
16
|
.description(text(runtime.product, "连接并操作 AI+ Editor", "Connect to and operate insMind Editor"))
|
|
15
17
|
.helpCommand(false);
|
|
16
18
|
editor.addHelpText("after", [
|
|
17
19
|
"",
|
|
20
|
+
text(runtime.product, "对象是已连接作品中的元素。用户提供附件图片/媒体链接并要求改字、分层、矢量化或其他图片处理时,先从 tool list 发现能力;无需为了这些操作新建 Board。", "This group operates elements in a connected work. For attached images or media links needing text replacement, decomposition, vectorization or other processing, discover tool list first; these operations do not require a new Board."),
|
|
18
21
|
text(runtime.product, "操作一个当前 Session、当前 Page 的直属 Shape 和绑定 Connector;单操作者串行执行。", "Operate one current Session and its Page's direct Shapes and bound Connectors, serially with one operator."),
|
|
19
22
|
text(runtime.product, "元素类型与字段以 editor apply --schema 为准;Schema 查询无需登录或连接 Editor。", "Discover element types and fields with editor apply --schema; no login or Editor connection is required."),
|
|
20
23
|
text(runtime.product, "当前不支持嵌套元素、自由/半绑定 Connector、页面或选择修改;UNSUPPORTED_PAGE_CONTENT 时保留原作品并换用空白或专用 Page。", "Nested elements, free/half-bound Connectors, page and selection changes are unsupported. On UNSUPPORTED_PAGE_CONTENT, preserve the work and use a blank or dedicated Page."),
|
|
21
|
-
text(runtime.product, "流程:connect → snapshot → apply → snapshot/screenshot 复查 → save → disconnect。apply 不代替 save
|
|
24
|
+
text(runtime.product, "流程:connect → snapshot → apply → snapshot/screenshot 复查 → 按用户授权 save → disconnect。apply 不代替 save。只预览/暂不保存时停在预览;用户要求断开就执行 disconnect,断开不隐含保存。", "Workflow: connect → snapshot → apply → review snapshot/screenshot → save as authorized → disconnect. Apply does not replace Save. For preview-only requests stop at preview; on a request to disconnect, execute disconnect without implicitly saving."),
|
|
22
25
|
text(runtime.product, "EDITOR_BUSY 时等待原命令结束;写入超时、取消或断连时,先重新连接同一作品并检查真实状态,不直接重试写入。", "On EDITOR_BUSY, wait for the original command. After a write times out, is cancelled or disconnects, reconnect to the same work and inspect its state before deciding what to do."),
|
|
23
26
|
""
|
|
24
27
|
].join("\n"));
|
|
25
28
|
const connect = leaf(editor.command("connect"))
|
|
26
29
|
.description(text(runtime.product, "打开并连接一个 AI+ Editor 作品", "Open and connect to an Editor work"))
|
|
27
|
-
.argument("[target]", text(runtime.product, "
|
|
30
|
+
.argument("[target]", text(runtime.product, "已有作品的 ID 或完整 URL;留空会新建线上 Board", "existing work ID or full URL; omitting it creates a new production Board"));
|
|
28
31
|
connect.addHelpText("after", [
|
|
29
32
|
"",
|
|
30
|
-
text(runtime.product, "
|
|
33
|
+
text(runtime.product, "继续已有作品时,传数字作品 ID 或完整 HTTP(S) URL。还没有目标就先向用户索取作品链接或 ID。用户要求新建时才省略 target。", "To continue an existing work, pass its numeric ID or supported insMind production Editor URL. If the target is missing, ask the user for the link or ID. Omit target only when the user requests a new Board."),
|
|
31
34
|
text(runtime.product, "会打开浏览器并替换旧 Session;浏览器登录、加载、Board 类型、编辑/保存权限与页面内容检查通过后才成功。CLI 登录不能替代浏览器登录。", "Opens the browser and replaces the old Session. Browser login, loading, Board type, edit/save permission and page-content checks must pass. CLI credentials do not replace browser login."),
|
|
32
35
|
text(runtime.product, "输出 JSON {target},不含连接凭证。连接失败时停止写入,让用户在页面处理登录或权限,再重新连接。", "Returns JSON {target} without connection credentials. On failure, stop writing and let the user resolve browser login or permissions before reconnecting."),
|
|
33
36
|
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."),
|
|
@@ -46,7 +49,7 @@ export function registerEditorCommands(program, runtime) {
|
|
|
46
49
|
});
|
|
47
50
|
const disconnect = leaf(editor.command("disconnect"))
|
|
48
51
|
.description(text(runtime.product, "断开当前 Editor 连接", "Disconnect the current Editor"));
|
|
49
|
-
disconnect.addHelpText("after", `\n${text(runtime.product, "输出 JSON {disconnected}
|
|
52
|
+
disconnect.addHelpText("after", `\n${text(runtime.product, "输出 JSON {disconnected},解除当前 CLI 会话连接,不保存作品、不关闭浏览器页面。需要保留修改且已获保存授权时先 save;用户只要求断开或明确不保存时直接断开,并说明未保存状态。", "Returns JSON {disconnected}, ending the CLI session without saving the work or closing its browser page. Save first only when persistence is intended and authorized; if the user requests only disconnection or no save, disconnect and state what remains unsaved.")}\n`);
|
|
50
53
|
jsonOutput(disconnect);
|
|
51
54
|
bindAction(disconnect, "none", async (_context, signal) => {
|
|
52
55
|
writeJson(runtime, await runtime.telemetry.stage("editor.disconnect", () => runtime.editor.disconnect({ signal })));
|
|
@@ -70,11 +73,12 @@ export function registerEditorCommands(program, runtime) {
|
|
|
70
73
|
apply.addHelpText("after", [
|
|
71
74
|
"",
|
|
72
75
|
text(runtime.product, "--schema 与 --input 必须且只能选择一个。Schema 为本地契约,不连接 Editor;执行成功输出 JSON {appliedCount}。", "Choose exactly one of --schema and --input. Schema reads the local contract without connecting to Editor; successful execution returns JSON {appliedCount}."),
|
|
76
|
+
text(runtime.product, "先保存完整 JSON,再用 --input request.json 执行;--input - 必须在同一条 shell 命令中经管道或重定向提供完整 JSON,不交互填参。", "Save complete JSON before using --input request.json. With --input -, pipe or redirect complete JSON in the same shell command; input is not an interactive form."),
|
|
73
77
|
text(runtime.product, "输入对象包含 host_application 和按序执行的 actions 数组;类型、必填字段与可选值见 --schema。使用简短语义 ID;create ID 必须唯一,Connector 可引用本批次更早创建的 Shape。", "Input is an object with host_application and an ordered actions array; discover types, required fields and choices with --schema. Use short semantic IDs. Create IDs must be unique; a Connector may reference a Shape created earlier in the batch."),
|
|
74
78
|
text(runtime.product, "update 提交完整元素而非 patch,不改变 id 或 _type。delete 要求 ID 存在;删除 Shape 同时删除绑定的 Connector。", "Update requires the full element, not a patch, without changing id or _type. Delete requires an existing ID; deleting a Shape also deletes its bound Connectors."),
|
|
75
79
|
text(runtime.product, "Shape 的 x/y 为 Page 左上角坐标,w/h 大于 0;数值必须有限。颜色用 #RRGGBB 或 #RRGGBBAA,仅 stroke 可为 null。Connector 用 fromId/toId 表达有方向的 Shape 关系。", "Shape x/y locate its top-left corner in Page coordinates; w/h must exceed zero and numbers must be finite. Colors use #RRGGBB or #RRGGBBAA; only stroke accepts null. Connector fromId/toId express a directed Shape relationship."),
|
|
76
80
|
text(runtime.product, "整批先预检,再在可回滚事务中应用;INVALID_ACTIONS 时修正输入,APPLY_FAILED 时读 Snapshot 确认回滚。EDITOR_ROLLBACK_FAILED 时停止 apply/save,只读检查并报告。", "The batch is checked before one rollback-capable transaction. Correct INVALID_ACTIONS; on APPLY_FAILED read a Snapshot to confirm rollback. On EDITOR_ROLLBACK_FAILED, stop apply/save, inspect read-only and report."),
|
|
77
|
-
text(runtime.product, "成功不表示已保存或视觉正确;读取新 Snapshot
|
|
81
|
+
text(runtime.product, "成功不表示已保存或视觉正确;读取新 Snapshot,涉及布局/文字/连线时查看截图。只预览时交付截图且不 save;需要持久化并已获授权时再显式 save。超时、取消或断连后先检查真实状态,不重复提交。", "Success proves neither persistence nor correct rendering. Read a new Snapshot and view a screenshot for layout/text/connectors. Deliver preview-only requests without save; explicitly save when persistence is intended and authorized. Inspect real state after timeout, cancellation or disconnection instead of resubmitting."),
|
|
78
82
|
""
|
|
79
83
|
].join("\n"));
|
|
80
84
|
jsonOutput(apply);
|
|
@@ -84,7 +88,7 @@ export function registerEditorCommands(program, runtime) {
|
|
|
84
88
|
if (Number(options.schema === true) + Number(options.input !== undefined) !== 1)
|
|
85
89
|
throw new CliUsageError();
|
|
86
90
|
if (options.schema === true) {
|
|
87
|
-
await runtime.telemetry.stage("output", () => { writeJson(runtime, hostSchema(runtime, editorApplyInputSchema)); });
|
|
91
|
+
await runtime.telemetry.stage("output", () => { writeJson(runtime, hostSchema(runtime, editorApplyInputSchema())); });
|
|
88
92
|
return { handled: true };
|
|
89
93
|
}
|
|
90
94
|
const input = editorActions(readHostInput(runtime, await runtime.jsonInput.read(options.input, signal)));
|
package/dist/src/cli/errors.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { CreditsPageCursorError } from "../features/credits/use-cases.js";
|
|
1
2
|
import { observedErrorCategory, observedErrorMessage } from "./observed-errors.js";
|
|
2
3
|
import { TaskBackgroundError } from "../features/task/task-background.js";
|
|
3
|
-
import { TaskNotFoundError } from "../features/task/use-cases.js";
|
|
4
|
+
import { CreationInputUploadError, TaskNotFoundError } from "../features/task/use-cases.js";
|
|
4
5
|
import { TaskStoreError } from "../features/task/store.js";
|
|
5
6
|
import { CommanderError } from "commander";
|
|
6
7
|
import { AuthExpiredError, AuthRequiredError } from "../features/auth/access-policy.js";
|
|
@@ -9,7 +10,7 @@ import { SsoRequestError } from "../features/auth/sso-service.js";
|
|
|
9
10
|
import { AuthorizedAccountContextMissingError, BrowserOpenError, DeviceAuthorizationExpiredError } from "../features/auth/use-cases.js";
|
|
10
11
|
import { AgentInputError } from "../features/agent/use-cases.js";
|
|
11
12
|
import { ToolInputError } from "../features/tool/catalog.js";
|
|
12
|
-
import { ToolTaskFailedError, ToolTaskCanceledError, ToolInsufficientCreditsError } from "../features/tool/tool-
|
|
13
|
+
import { ToolTaskFailedError, ToolTaskCanceledError, ToolInsufficientCreditsError } from "../features/tool/tool-errors.js";
|
|
13
14
|
import { AgentAuditRejectedError } from "../features/agent/creative-protocol.js";
|
|
14
15
|
import { isContentReviewRejection } from "../features/task/creation-refusal.js";
|
|
15
16
|
import { ObjectStorageUploadError } from "../features/dam/object-storage.js";
|
|
@@ -47,12 +48,18 @@ export function isHelpOutcome(error) {
|
|
|
47
48
|
&& (error.code === "commander.helpDisplayed" || error.code === "commander.version");
|
|
48
49
|
}
|
|
49
50
|
export function mapCliError(error, options) {
|
|
50
|
-
const outcome = mapBaseCliError(error, options);
|
|
51
|
+
const outcome = mapBaseCliError(error instanceof CreationInputUploadError ? error.cause : error, options);
|
|
51
52
|
if (outcome.kind === "interrupted")
|
|
52
53
|
return { ...outcome, failure: { code: "INTERRUPTED",
|
|
53
54
|
message: options.product?.id === "insmind" ? "This operation stopped waiting." : "本次操作已停止等待。",
|
|
54
55
|
...(outcome.failure?.details ? { details: outcome.failure.details } : {}) } };
|
|
55
|
-
if (error instanceof
|
|
56
|
+
if (error instanceof CreationInputUploadError) {
|
|
57
|
+
const en = options.product?.id === "insmind";
|
|
58
|
+
return failure(outcome.failure.code, en ? "An input file could not be uploaded. The creation request has not been sent."
|
|
59
|
+
: "输入素材上传失败,本次创作请求尚未派发。", outcome.exitCode, [en ? "Tell the user which step failed. Once the connection is available, the same request and original files can be used again."
|
|
60
|
+
: "向用户说明失败发生在上传原素材时。网络可用后,可用原需求和原素材再次发起。"], { ...outcome.failure.details, phase: "input_upload_before_dispatch" });
|
|
61
|
+
}
|
|
62
|
+
if (error instanceof UpdateError || error instanceof TaskBackgroundError || (error instanceof ToolTaskFailedError && error.imagePixelRequirement))
|
|
56
63
|
return outcome;
|
|
57
64
|
const remote = remoteCause(error);
|
|
58
65
|
const evidence = {
|
|
@@ -72,13 +79,43 @@ export function mapCliError(error, options) {
|
|
|
72
79
|
return outcome;
|
|
73
80
|
return { ...outcome, failure: { ...outcome.failure, message: observedErrorMessage(category, evidence) } };
|
|
74
81
|
}
|
|
82
|
+
// Project the service's explicit validation error, never its full response or rejected input.
|
|
83
|
+
function toolBusinessDetails(error) {
|
|
84
|
+
const details = {};
|
|
85
|
+
if (error.remoteCode && /^[\w.-]{1,80}$/u.test(error.remoteCode))
|
|
86
|
+
details.remote_code = error.remoteCode;
|
|
87
|
+
let body;
|
|
88
|
+
try {
|
|
89
|
+
body = JSON.parse(error.remoteBody ?? "");
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return details;
|
|
93
|
+
}
|
|
94
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
95
|
+
return details;
|
|
96
|
+
const envelope = body;
|
|
97
|
+
const item = Array.isArray(envelope.detail) ? envelope.detail[0] : undefined;
|
|
98
|
+
const issue = item && typeof item === "object" ? item : undefined;
|
|
99
|
+
const field = Array.isArray(issue?.loc) ? issue.loc.map(String).join(".") : envelope.field;
|
|
100
|
+
if (typeof field === "string" && /^[\w.-]{1,160}$/u.test(field))
|
|
101
|
+
details.field = field;
|
|
102
|
+
const message = issue?.msg ?? envelope.message;
|
|
103
|
+
if (typeof message === "string" && message.trim() && message.length <= 180
|
|
104
|
+
&& !/[\u0000-\u001f\u007f<>/\\]|\[REDACTED\]|(?:bearer|password|prompt|token|secret)\s*[:=\s]/iu.test(message)
|
|
105
|
+
&& redactSensitiveText(message) === message)
|
|
106
|
+
details.remote_message = message;
|
|
107
|
+
return details;
|
|
108
|
+
}
|
|
75
109
|
function mapBaseCliError(error, options) {
|
|
76
110
|
const insmind = options.product?.id === "insmind";
|
|
77
111
|
const command = options.product?.commandName ?? "gd-cli";
|
|
78
112
|
const text = (zh, en) => insmind ? en : zh;
|
|
113
|
+
const refusalSteps = ["agent.send", "tool.call", "task.get"].includes(options.operation ?? "") ? [text("向用户说明本次失败原因和可交付结果。换模型或改参数再做一次属于新创作,须有用户补充的需求或另做一次的明确授权。", "Tell the user why this creation failed and what, if anything, can be delivered. A different model or revised settings start a new creation. Proceed only with a revised request or explicit authorization for another creation.")] : undefined;
|
|
79
114
|
if (error instanceof ToolTaskCanceledError)
|
|
80
115
|
return { kind: "interrupted", exitCode: 130,
|
|
81
116
|
failure: { code: "INTERRUPTED", message: text("生成任务已取消。", "The creation task was canceled.") } };
|
|
117
|
+
if (error instanceof UpdateError)
|
|
118
|
+
return failure(error.code, error.message, 1, error.nextSteps, error.details);
|
|
82
119
|
if (options.aborted)
|
|
83
120
|
return { kind: "interrupted", exitCode: 130, failure: {
|
|
84
121
|
code: "INTERRUPTED", message: text("已停止本地等待;已派发的任务或写操作可能仍在继续。", "Local waiting stopped; dispatched tasks or writes may still be active."),
|
|
@@ -122,9 +159,6 @@ function mapBaseCliError(error, options) {
|
|
|
122
159
|
return failure("AUTH_STATE_INVALID", "The account context is unavailable. Sign out and sign in again.", 1, [`${command} auth logout`, `${command} auth login`]);
|
|
123
160
|
return failure("ORG_INVALID", "所选组织不可用,请重新选择组织。", 1, ["gd-cli org list", "gd-cli org switch --org <org-id>"]);
|
|
124
161
|
}
|
|
125
|
-
if (error instanceof UpdateError) {
|
|
126
|
-
return failure(error.code, error.message, 1, error.nextSteps, error.details);
|
|
127
|
-
}
|
|
128
162
|
if (error instanceof EditorTargetError) {
|
|
129
163
|
if (insmind)
|
|
130
164
|
return failure(error.code, "Editor target must be a work ID or a complete trusted insMind Editor URL.", 2);
|
|
@@ -144,18 +178,20 @@ function mapBaseCliError(error, options) {
|
|
|
144
178
|
model_tool_mismatch: ["模型不属于所选工具。", "The model does not belong to the selected tool."],
|
|
145
179
|
model_required: ["缺少 model 字段。", "The model field is required."],
|
|
146
180
|
model_parameters: ["参数不符合所选模型要求。", "The arguments do not match the selected model requirements."],
|
|
147
|
-
invalid_asset_url: ["素材 URL 不符合可访问资源要求。", "The asset URL does not meet the accessible resource requirements."]
|
|
181
|
+
invalid_asset_url: ["素材 URL 不符合可访问资源要求。", "The asset URL does not meet the accessible resource requirements."],
|
|
182
|
+
mask_geometry_or_format: ["无法转换 mask。请提供可读取的单帧 PNG;叠加选区时需与转正后的原图尺寸一致。", "Could not convert the mask. Supply a readable single-frame PNG. For an overlay, match the auto-oriented source dimensions."]
|
|
148
183
|
};
|
|
149
184
|
const description = descriptions[error.reason];
|
|
150
|
-
return failure("USAGE_ERROR", description ? text(...description) : text("创作输入不可用,请核对模型与参数。", "Check the model and creation arguments."), 2,
|
|
185
|
+
return failure("USAGE_ERROR", description ? text(...description) : text("创作输入不可用,请核对模型与参数。", "Check the model and creation arguments."), 2, error.reason === "mask_geometry_or_format" ? [text(`该选区尚未提交处理。用 ${command} model get <model> 查看 mask 的要求,保留用户选区,修正文件后再调用。`, `This selection has not been submitted. Check the mask requirements with ${command} model get <model>, preserve the user's selection and call again after correcting the file.`)]
|
|
186
|
+
: [`${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 } : {}) });
|
|
151
187
|
}
|
|
152
188
|
if (error instanceof LocalFileInputError) {
|
|
153
189
|
const message = error.reason === "invalid_file_uri"
|
|
154
|
-
? text("本地文件地址格式不正确。Windows
|
|
190
|
+
? text("本地文件地址格式不正确。Windows 盘符用 file:///C:/目录/文件,共享文件用 file://主机/共享名/文件。", "Invalid local file URL. Use file:///C:/folder/file for a Windows drive or file://server/share/file for a share.")
|
|
155
191
|
: error.reason === "file_read_failed" && systemErrorCode(error) === "ENOENT"
|
|
156
192
|
? text("找不到指定的本地文件,请核对完整路径。", "The local file was not found. Check its full path.")
|
|
157
|
-
: error.reason === "
|
|
158
|
-
? text("
|
|
193
|
+
: error.reason === "invalid_media_type_header"
|
|
194
|
+
? text("mediaType 包含无法作为上传请求头发送的字符,请更正。", "The mediaType contains characters that cannot be sent in an upload header. Correct the value.")
|
|
159
195
|
: text("本地素材文件不可用于上传。", "The local asset file cannot be uploaded.");
|
|
160
196
|
return failure("USAGE_ERROR", message, 2, [text("检查文件访问权限、文件类型和声明的 mediaType;受保护路径不可上传。", "Check file access, type and declared mediaType; protected paths cannot be uploaded.")], { reason: error.reason, system_code: systemErrorCode(error) });
|
|
161
197
|
}
|
|
@@ -174,7 +210,7 @@ function mapBaseCliError(error, options) {
|
|
|
174
210
|
return failure("USAGE_ERROR", "命令或参数无效,请查看 --help。", 2);
|
|
175
211
|
}
|
|
176
212
|
if (error instanceof ToolInsufficientCreditsError || options.product?.id !== "insmind" && options.operation === "tool.call" && isInsufficientCreditsError(error)) {
|
|
177
|
-
return failure("INSUFFICIENT_CREDITS", text("当前可用额度不足,本次生成未能完成。", "Available credits are insufficient; this creation could not complete."), 1);
|
|
213
|
+
return failure("INSUFFICIENT_CREDITS", text("当前可用额度不足,本次生成未能完成。", "Available credits are insufficient; this creation could not complete."), 1, refusalSteps);
|
|
178
214
|
}
|
|
179
215
|
if (isContentReviewRejection(error, { product: options.product?.id ?? "gaoding", operation: options.operation })) {
|
|
180
216
|
const phase = error instanceof AgentAuditRejectedError ? error.phase : undefined;
|
|
@@ -184,13 +220,20 @@ function mapBaseCliError(error, options) {
|
|
|
184
220
|
: phase === "output"
|
|
185
221
|
? text("生成内容未通过审核,无法交付本次结果。", "The generated content did not pass review. This result cannot be delivered.")
|
|
186
222
|
: text("本次创作被内容审核拒绝。", "This creation was rejected by content review.");
|
|
187
|
-
return failure(error instanceof ToolTaskFailedError ? "TOOL_TASK_FAILED" : "REMOTE_REQUEST_FAILED", message, 1,
|
|
223
|
+
return failure(error instanceof ToolTaskFailedError ? "TOOL_TASK_FAILED" : "REMOTE_REQUEST_FAILED", message, 1, refusalSteps, { reason });
|
|
188
224
|
}
|
|
225
|
+
if (error instanceof CreditsPageCursorError)
|
|
226
|
+
return failure("REMOTE_PROTOCOL_INCOMPATIBLE", text("已收到本页流水,但服务没有返回可用的下一页游标。已知流水在 details.partial_result,本次无法续页。", "This page was received without a usable cursor. Its records are in details.partial_result; the next page cannot be requested."), 1, undefined, { partial_result: error.partialResult });
|
|
189
227
|
if (error instanceof RemoteProtocolError) {
|
|
190
228
|
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.`)]);
|
|
191
229
|
}
|
|
192
230
|
if (error instanceof ToolTaskFailedError) {
|
|
193
|
-
|
|
231
|
+
if (error.imagePixelRequirement) {
|
|
232
|
+
const { minimumPixels, width, height } = error.imagePixelRequirement;
|
|
233
|
+
return failure("TOOL_TASK_FAILED", text(`服务端收到的图片为 ${width} × ${height} 像素。请换用总像素数至少为 ${minimumPixels} 的图片。`, `The service received a ${width} × ${height} pixel image. Use an image with at least ${minimumPixels} pixels in total.`), 1, refusalSteps, { remote_code: error.remoteCode, field: "image", minimum_pixels: minimumPixels, received_width: width, received_height: height });
|
|
234
|
+
}
|
|
235
|
+
const details = toolBusinessDetails(error);
|
|
236
|
+
return failure("TOOL_TASK_FAILED", insmind ? "The Tool task failed." : "稿定工具任务执行失败。", 1, refusalSteps, Object.keys(details).length ? details : undefined);
|
|
194
237
|
}
|
|
195
238
|
if (error instanceof DamAssetNotFoundError) {
|
|
196
239
|
return failure("DAM_ASSET_NOT_FOUND", insmind ? "The requested asset was not found." : "未找到指定的 DAM 素材。", 1);
|
|
@@ -248,6 +291,8 @@ function mapBaseCliError(error, options) {
|
|
|
248
291
|
request: ["稿定服务请求失败;是否已受理取决于本次请求阶段。", "The service request failed; acceptance depends on the request phase."]
|
|
249
292
|
};
|
|
250
293
|
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),
|
|
294
|
+
...(error instanceof RemoteRequestError && options.operation === "tool.call"
|
|
295
|
+
&& error.status !== undefined && error.status >= 400 && error.status < 500 ? toolBusinessDetails(error) : {}),
|
|
251
296
|
...((error instanceof RemoteRequestError || error instanceof SsoRequestError) && error.status !== undefined ? { http_status: error.status } : {}) });
|
|
252
297
|
}
|
|
253
298
|
if (error instanceof OutputContractError) {
|
|
@@ -255,19 +300,32 @@ function mapBaseCliError(error, options) {
|
|
|
255
300
|
}
|
|
256
301
|
if (error instanceof LocalFileError)
|
|
257
302
|
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) });
|
|
258
|
-
if (error instanceof EditorBridgeUnavailableError
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (
|
|
303
|
+
if (error instanceof EditorBridgeUnavailableError || error instanceof EditorBridgeError
|
|
304
|
+
|| error instanceof EditorSessionNotFoundError || error instanceof EditorNotReadyError) {
|
|
305
|
+
const unavailable = error instanceof EditorBridgeUnavailableError;
|
|
306
|
+
const code = unavailable ? "EDITOR_NOT_READY" : error.code;
|
|
307
|
+
let message = redactSensitiveText(error.message).slice(0, 1024);
|
|
308
|
+
if (unavailable)
|
|
309
|
+
message = text("本地 Editor Bridge 连接不可用。", "The local Editor Bridge connection is unavailable.");
|
|
310
|
+
else if (insmind) {
|
|
264
311
|
if (error instanceof EditorSessionNotFoundError)
|
|
265
|
-
|
|
266
|
-
if (error instanceof EditorNotReadyError)
|
|
267
|
-
|
|
268
|
-
|
|
312
|
+
message = "No Editor session is available.";
|
|
313
|
+
else if (error instanceof EditorNotReadyError)
|
|
314
|
+
message = "The Editor page did not become ready in time.";
|
|
315
|
+
else
|
|
316
|
+
message = code === "EDITOR_BRIDGE_INVALID_RESPONSE" ? "The Editor Bridge returned an invalid response." : `Editor: ${message}`;
|
|
317
|
+
}
|
|
318
|
+
const connectionError = ["EDITOR_SESSION_NOT_FOUND", "EDITOR_NOT_CONNECTED", "EDITOR_DISCONNECTED", "EDITOR_NOT_READY", "EDITOR_RPC_TIMEOUT"].includes(code);
|
|
319
|
+
let nextStep = text(`按 ${command} editor --help 中该错误的说明处理。`, `Follow the instructions for this error in ${command} editor --help.`);
|
|
320
|
+
if (connectionError && (options.operation === "editor.snapshot" || options.operation === "editor.screenshot")) {
|
|
321
|
+
const read = options.operation === "editor.snapshot" ? "snapshot" : "screenshot";
|
|
322
|
+
nextStep = text(`要继续原作品,若还没有作品链接或 ID,先向用户索取。省略目标会新建线上 Board。拿到原作品的链接或 ID 后,用 ${command} editor connect <target> 连接,再执行 ${command} editor ${read}。`, `To continue the original work, ask the user for its link or ID if you don't have it. Omitting the target creates a new production Board. With the link or ID, run ${command} editor connect <target>, then ${command} editor ${read}.`);
|
|
323
|
+
}
|
|
324
|
+
else if ((options.operation === "editor.apply" || options.operation === "editor.save")
|
|
325
|
+
&& (connectionError || ["EDITOR_ROLLBACK_FAILED", "APPLY_FAILED", "SAVE_FAILED", "EDITOR_BRIDGE_INVALID_RESPONSE"].includes(code))) {
|
|
326
|
+
nextStep = text("先检查原作品的实际状态,再决定后续操作。无法确认状态时停止写入,不重复 apply 或 save。", "Inspect the original work before taking further action. If the state is uncertain, stop writing without repeating apply or save.");
|
|
269
327
|
}
|
|
270
|
-
return failure(
|
|
328
|
+
return failure(code, message, 1, [nextStep], unavailable ? { phase: "editor_connection" } : undefined);
|
|
271
329
|
}
|
|
272
330
|
if (systemErrorCode(error) === "ECONNRESET")
|
|
273
331
|
return failure("REMOTE_REQUEST_FAILED", text("连接中断,未能完整收到结果。", "The connection closed before the full result was received."), 1);
|