@insmind/cli 1.7.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/contracts/operations/model.get/input.schema.json +5 -0
  2. package/contracts/operations/model.get/output.schema.json +9 -1
  3. package/contracts/operations/tool.call/canvas-input.schema.json +60 -0
  4. package/contracts/operations/tool.call/models/image-edit-smart.schema.json +39 -0
  5. package/contracts/operations/tool.call/models/image-edit-standard.schema.json +31 -0
  6. package/contracts/operations/tool.call/models/image-enhance-smart.schema.json +26 -0
  7. package/contracts/operations/tool.call/models/image-enhance-standard.schema.json +25 -0
  8. package/contracts/operations/tool.call/models/image-expand-smart.schema.json +72 -0
  9. package/contracts/operations/tool.call/models/image-expand-standard.schema.json +58 -0
  10. package/contracts/operations/tool.call/models/image-layers-layout.schema.json +20 -0
  11. package/contracts/operations/tool.call/models/image-layers-smart.schema.json +26 -0
  12. package/contracts/operations/tool.call/models/image-matting-smart.schema.json +34 -0
  13. package/contracts/operations/tool.call/models/image-matting-standard.schema.json +24 -0
  14. package/contracts/operations/tool.call/models/image-ocr.schema.json +20 -0
  15. package/contracts/operations/tool.call/models/image-remove-smart.schema.json +30 -0
  16. package/contracts/operations/tool.call/models/image-remove-standard.schema.json +25 -0
  17. package/contracts/operations/tool.call/models/image-text-edit.schema.json +43 -0
  18. package/contracts/operations/tool.call/models/image-vectorize.schema.json +20 -0
  19. package/contracts/operations/tool.call/models/video-edit-smart.schema.json +68 -0
  20. package/contracts/operations/tool.call/models/video-enhance-smart.schema.json +32 -0
  21. package/contracts/operations/tool.call/models/video-enhance-standard.schema.json +26 -0
  22. package/contracts/operations/tool.call/ocr-payload.schema.json +65 -0
  23. package/contracts/operations/tool.call/output.schema.json +38 -0
  24. package/contracts/operations/tool.call/template-payload.schema.json +95 -0
  25. package/dist/src/bootstrap/create-runtime.js +61 -25
  26. package/dist/src/bootstrap/validators.js +1 -1
  27. package/dist/src/cli/action-binding.js +3 -0
  28. package/dist/src/cli/agent-commands.js +1 -0
  29. package/dist/src/cli/errors.js +43 -10
  30. package/dist/src/cli/model-commands.js +7 -4
  31. package/dist/src/cli/observed-errors.js +13 -5
  32. package/dist/src/cli/task-commands.js +1 -1
  33. package/dist/src/cli/tool-commands.js +3 -1
  34. package/dist/src/contracts/schema.js +4 -1
  35. package/dist/src/features/agent/creative-protocol.js +22 -5
  36. package/dist/src/features/agent/resource-authorizer.js +1 -0
  37. package/dist/src/features/agent/use-cases.js +15 -5
  38. package/dist/src/features/auth/sso-service.js +13 -4
  39. package/dist/src/features/dam/dam-api-adapter.js +1 -0
  40. package/dist/src/features/dam/file-downloader.js +23 -2
  41. package/dist/src/features/task/store.js +8 -4
  42. package/dist/src/features/task/use-cases.js +14 -11
  43. package/dist/src/features/tool/canvas-copy.js +61 -0
  44. package/dist/src/features/tool/canvas-media.js +193 -0
  45. package/dist/src/features/tool/canvas-models.js +109 -0
  46. package/dist/src/features/tool/canvas-pricing.js +81 -0
  47. package/dist/src/features/tool/canvas-recovery.js +68 -0
  48. package/dist/src/features/tool/canvas-results.js +144 -0
  49. package/dist/src/features/tool/canvas-tool-adapter.js +366 -0
  50. package/dist/src/features/tool/canvas-video.js +84 -0
  51. package/dist/src/features/tool/catalog.js +35 -13
  52. package/dist/src/features/tool/dynamic-schema.js +52 -23
  53. package/dist/src/features/tool/matting-billing.js +103 -0
  54. package/dist/src/features/tool/mns-catalog-adapter.js +66 -19
  55. package/dist/src/features/tool/resource-authorizer.js +34 -0
  56. package/dist/src/features/tool/scene-catalog-adapter.js +35 -0
  57. package/dist/src/features/tool/tool-api-adapter.js +24 -5
  58. package/dist/src/features/tool/use-cases.js +28 -3
  59. package/dist/src/features/update/update-service.js +4 -2
  60. package/dist/src/platform/file-lock.js +12 -0
  61. package/dist/src/platform/local-json-file.js +19 -5
  62. package/dist/src/platform/safe-upload-file.js +18 -10
  63. package/dist/src/platform/schema-issues.js +47 -2
  64. package/dist/src/platform/text-output.js +17 -4
  65. package/dist/src/product/config.js +12 -1
  66. package/dist/src/telemetry/failure-summary.js +18 -0
  67. package/package.json +5 -4
  68. package/skills/insmind-cli/SKILL.md +2 -0
  69. package/skills/insmind-cli/references/creation.md +2 -0
  70. package/skills/insmind-cli/references/generation-constraints.md +3 -1
  71. package/skills/insmind-cli/references/matting.md +29 -0
  72. package/skills/insmind-cli/references/media-tools.md +40 -0
  73. package/skills/insmind-cli/references/tool.md +2 -2
@@ -0,0 +1,32 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "VideoEnhanceSmartInput",
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "required": [
7
+ "model",
8
+ "video",
9
+ "prompt",
10
+ "resolution"
11
+ ],
12
+ "properties": {
13
+ "model": {
14
+ "type": "string",
15
+ "const": "video-enhance-smart"
16
+ },
17
+ "video": {
18
+ "type": "string",
19
+ "format": "uri"
20
+ },
21
+ "prompt": {
22
+ "type": "string",
23
+ "minLength": 1,
24
+ "pattern": ".*\\S.*"
25
+ },
26
+ "resolution": {
27
+ "type": "string",
28
+ "minLength": 1,
29
+ "pattern": ".*\\S.*"
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "VideoEnhanceStandardInput",
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "required": [
7
+ "model",
8
+ "video",
9
+ "resolution"
10
+ ],
11
+ "properties": {
12
+ "model": {
13
+ "type": "string",
14
+ "const": "video-enhance-standard"
15
+ },
16
+ "video": {
17
+ "type": "string",
18
+ "format": "uri"
19
+ },
20
+ "resolution": {
21
+ "type": "string",
22
+ "minLength": 1,
23
+ "pattern": ".*\\S.*"
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "OcrPayload",
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "required": [
7
+ "image",
8
+ "blocks"
9
+ ],
10
+ "properties": {
11
+ "image": {
12
+ "type": "object",
13
+ "additionalProperties": false,
14
+ "required": [
15
+ "uri",
16
+ "width",
17
+ "height"
18
+ ],
19
+ "properties": {
20
+ "uri": {
21
+ "type": "string",
22
+ "format": "uri"
23
+ },
24
+ "width": {
25
+ "type": "integer",
26
+ "minimum": 1
27
+ },
28
+ "height": {
29
+ "type": "integer",
30
+ "minimum": 1
31
+ }
32
+ }
33
+ },
34
+ "blocks": {
35
+ "type": "array",
36
+ "items": {
37
+ "type": "object",
38
+ "additionalProperties": false,
39
+ "required": [
40
+ "bbox",
41
+ "category"
42
+ ],
43
+ "properties": {
44
+ "bbox": {
45
+ "type": "array",
46
+ "minItems": 4,
47
+ "maxItems": 4,
48
+ "items": {
49
+ "type": "number",
50
+ "minimum": 0
51
+ }
52
+ },
53
+ "category": {
54
+ "type": "string",
55
+ "minLength": 1,
56
+ "pattern": ".*\\S.*"
57
+ },
58
+ "text": {
59
+ "type": "string"
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
@@ -17,6 +17,9 @@
17
17
  },
18
18
  {
19
19
  "$ref": "#/$defs/ResourceLink"
20
+ },
21
+ {
22
+ "$ref": "#/$defs/EmbeddedJsonResource"
20
23
  }
21
24
  ]
22
25
  }
@@ -110,6 +113,41 @@
110
113
  "pattern": ".*\\S.*"
111
114
  }
112
115
  }
116
+ },
117
+ "EmbeddedJsonResource": {
118
+ "type": "object",
119
+ "additionalProperties": false,
120
+ "required": [
121
+ "type",
122
+ "resource"
123
+ ],
124
+ "properties": {
125
+ "type": {
126
+ "const": "resource"
127
+ },
128
+ "resource": {
129
+ "type": "object",
130
+ "additionalProperties": false,
131
+ "required": [
132
+ "uri",
133
+ "mimeType",
134
+ "text"
135
+ ],
136
+ "properties": {
137
+ "uri": {
138
+ "type": "string",
139
+ "format": "uri"
140
+ },
141
+ "mimeType": {
142
+ "const": "application/json"
143
+ },
144
+ "text": {
145
+ "type": "string",
146
+ "minLength": 1
147
+ }
148
+ }
149
+ }
150
+ }
113
151
  }
114
152
  }
115
153
  }
@@ -0,0 +1,95 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "NativeLayerTemplate",
4
+ "type": "object",
5
+ "required": [
6
+ "pages"
7
+ ],
8
+ "properties": {
9
+ "pages": {
10
+ "type": "array",
11
+ "minItems": 1,
12
+ "items": {
13
+ "type": "object",
14
+ "required": [
15
+ "elements"
16
+ ],
17
+ "properties": {
18
+ "elements": {
19
+ "type": "array",
20
+ "minItems": 1,
21
+ "items": {
22
+ "$ref": "#/$defs/layout"
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ },
29
+ "$defs": {
30
+ "element": {
31
+ "type": "object",
32
+ "required": [
33
+ "type"
34
+ ],
35
+ "properties": {
36
+ "type": {
37
+ "type": "string",
38
+ "minLength": 1
39
+ },
40
+ "elements": {
41
+ "type": "array",
42
+ "items": {
43
+ "$ref": "#/$defs/element"
44
+ }
45
+ },
46
+ "url": {
47
+ "type": "string"
48
+ }
49
+ }
50
+ },
51
+ "layout": {
52
+ "allOf": [
53
+ {
54
+ "$ref": "#/$defs/element"
55
+ },
56
+ {
57
+ "type": "object",
58
+ "required": [
59
+ "width",
60
+ "height",
61
+ "background",
62
+ "elements"
63
+ ],
64
+ "properties": {
65
+ "width": {
66
+ "type": "number",
67
+ "exclusiveMinimum": 0
68
+ },
69
+ "height": {
70
+ "type": "number",
71
+ "exclusiveMinimum": 0
72
+ },
73
+ "background": {
74
+ "type": "object",
75
+ "required": [
76
+ "image"
77
+ ],
78
+ "properties": {
79
+ "image": {
80
+ "type": "object"
81
+ }
82
+ }
83
+ },
84
+ "elements": {
85
+ "type": "array",
86
+ "items": {
87
+ "$ref": "#/$defs/element"
88
+ }
89
+ }
90
+ }
91
+ }
92
+ ]
93
+ }
94
+ }
95
+ }
@@ -7,7 +7,7 @@ import { createTaskBackgroundLauncher } from "../features/task/task-background.j
7
7
  import { createTaskStore } from "../features/task/store.js";
8
8
  import { createTaskUseCases } from "../features/task/use-cases.js";
9
9
  import { readAgentResult } from "../features/agent/result-reader.js";
10
- import { queryToolResult, ToolTaskFailedError } from "../features/tool/tool-api-adapter.js";
10
+ import { queryToolResult, ToolTaskFailedError, ToolTaskCanceledError } from "../features/tool/tool-api-adapter.js";
11
11
  import { randomBytes, randomUUID } from "node:crypto";
12
12
  import { dirname, join } from "node:path";
13
13
  import { setTimeout as delay } from "node:timers/promises";
@@ -32,8 +32,14 @@ import { createEditorSessionStateStore } from "../features/editor/session-state.
32
32
  import { createEditorUseCases } from "../features/editor/use-cases.js";
33
33
  import { createObjectStorageUploader } from "../features/dam/object-storage.js";
34
34
  import { createAgentUseCases } from "../features/agent/use-cases.js";
35
+ import { createSceneCatalogAdapter } from "../features/tool/scene-catalog-adapter.js";
35
36
  import { createMnsCatalogAdapter } from "../features/tool/mns-catalog-adapter.js";
36
37
  import { createToolApiAdapter } from "../features/tool/tool-api-adapter.js";
38
+ import { createCanvasToolAdapter } from "../features/tool/canvas-tool-adapter.js";
39
+ import { recoverCanvasTool } from "../features/tool/canvas-recovery.js";
40
+ import { authorizeToolResources } from "../features/tool/resource-authorizer.js";
41
+ import { createCanvasMedia } from "../features/tool/canvas-media.js";
42
+ import { createStandardMatting } from "../features/tool/matting-billing.js";
37
43
  import { createToolUseCases } from "../features/tool/use-cases.js";
38
44
  import { createOrgUseCases } from "../features/org/use-cases.js";
39
45
  import { createOrgService } from "../features/org/org-service.js";
@@ -100,6 +106,12 @@ export function createProductionRuntime(options = {}) {
100
106
  classifyError: error => classifyTelemetryError(error, { product, operation: telemetry.creationContext().operation, failureStage: telemetry.failureStage(error) }),
101
107
  ...(telemetrySink.enqueue ? { onEvent: (event) => telemetrySink.enqueue([event]) } : {})
102
108
  });
109
+ telemetry.annotate({ installation_owner: installationOwner,
110
+ ...(["workbuddy", "qwenwork"].includes(env.CLI_HOST_APPLICATION ?? "")
111
+ ? { host_application: env.CLI_HOST_APPLICATION } : {}),
112
+ ...(["auth_status", "version_check"].includes(env.CLI_INVOCATION_PURPOSE ?? "")
113
+ ? { invocation_purpose: env.CLI_INVOCATION_PURPOSE } : {}),
114
+ ...(/^[a-f0-9]{32}$/u.test(env.CLI_HOST_INVOCATION_ID ?? "") ? { host_invocation_id: env.CLI_HOST_INVOCATION_ID } : {}) });
103
115
  // Explicit test transport enables SDK tests; test-mode child processes never emit real analytics.
104
116
  const analytics = options.analytics ?? (telemetryEnvironment === "production" || options.windFetch
105
117
  ? createWindAnalytics({ product: product.id, version: options.telemetryVersion ?? primarySkill.version,
@@ -116,7 +128,7 @@ export function createProductionRuntime(options = {}) {
116
128
  stderrTerminal: process.stderr.isTTY === true
117
129
  };
118
130
  const stdout = createTextOutput(rawIo.stdout);
119
- const stderr = createTextOutput(rawIo.stderr);
131
+ const stderr = createTextOutput(rawIo.stderr, "stderr");
120
132
  const io = {
121
133
  writeOut: stdout.write,
122
134
  writeError: stderr.write,
@@ -221,12 +233,13 @@ export function createProductionRuntime(options = {}) {
221
233
  const validators = createContractValidators({
222
234
  organizations: product.exposesOrganizations
223
235
  });
224
- const modelCatalog = createMnsCatalogAdapter({
225
- transport: mnsTransport,
226
- ...(product.id === "insmind"
227
- ? { invalidModelWarning: (count) => `Ignored ${count} invalid model configuration${count === 1 ? "" : "s"}.` }
228
- : {})
229
- });
236
+ const modelCatalog = createSceneCatalogAdapter({ transport: toolTransport, english: product.id === "insmind", catalog: createMnsCatalogAdapter({
237
+ english: product.id === "insmind",
238
+ transport: mnsTransport,
239
+ ...(product.id === "insmind"
240
+ ? { invalidModelWarning: (count) => `Ignored ${count} invalid model configuration${count === 1 ? "" : "s"}.` }
241
+ : {})
242
+ }) });
230
243
  const damApi = createDamApiAdapter({ transport: damTransport });
231
244
  const damRepositories = createDamRepositoryCatalog({ transport: damTransport });
232
245
  const damOperations = createDamOperationExecutor({
@@ -248,7 +261,10 @@ export function createProductionRuntime(options = {}) {
248
261
  now,
249
262
  telemetry
250
263
  }),
251
- downloader: createDamFileDownloader({ fetch }),
264
+ downloader: createDamFileDownloader({ fetch, warn: code => {
265
+ telemetry.annotate({ warning_codes: [code] });
266
+ presenter.warning(text("临时文件未能清理;已下载的文件可以继续使用。", "Temporary files could not be cleaned up; completed downloads remain available."));
267
+ } }),
252
268
  operations: damOperations,
253
269
  sleep: async (milliseconds, signal) => {
254
270
  await delay(milliseconds, undefined, { signal });
@@ -291,6 +307,10 @@ export function createProductionRuntime(options = {}) {
291
307
  });
292
308
  };
293
309
  const authorizeTaskResult = async (result, state, signal, alreadyAuthorized = false) => {
310
+ if ("message" in result)
311
+ validators.agentSendOutput(result);
312
+ else
313
+ validators.toolCallOutput(result);
294
314
  // Bind only if this result actually needs a fresh resource token.
295
315
  const taskAuthorizer = createAgentResourceAuthorizer({ authKeys: {
296
316
  async getAuthKey(access, tokenSignal) {
@@ -302,21 +322,7 @@ export function createProductionRuntime(options = {}) {
302
322
  const access = { credential: state.credential, organizationId: state.organization.id };
303
323
  if ("message" in result)
304
324
  return taskAuthorizer.authorize(result, access, signal);
305
- const links = result.content.filter(part => part.type === "resource_link");
306
- if (links.length === 0)
307
- return result;
308
- const parts = links.map(part => ({ url: part.uri, mediaType: part.mimeType ?? "application/octet-stream" }));
309
- const authorized = await taskAuthorizer.authorize({
310
- message: { contextId: "resource-authorization", parts: [parts[0], ...parts.slice(1)] },
311
- usage: { cost: { unit: "gaodou", amount: 0 }, items: [] }
312
- }, access, signal);
313
- let index = 0;
314
- return { ...result, content: result.content.map(part => {
315
- if (part.type !== "resource_link")
316
- return part;
317
- const authorizedPart = authorized.message.parts[index++];
318
- return authorizedPart && "url" in authorizedPart ? { ...part, uri: authorizedPart.url } : part;
319
- }) };
325
+ return authorizeToolResources(result, taskAuthorizer, access, signal);
320
326
  };
321
327
  const tasks = createTaskUseCases({
322
328
  telemetry,
@@ -363,6 +369,33 @@ export function createProductionRuntime(options = {}) {
363
369
  };
364
370
  },
365
371
  async tool(progress, state, signal) {
372
+ if (progress.toolPipeline) {
373
+ const pipeline = progress.toolPipeline;
374
+ await authorizeTaskAccess(state, signal);
375
+ let recovered;
376
+ try {
377
+ recovered = await telemetry.stage("task.query", () => recoverCanvasTool(progress, {
378
+ access: { credential: state.credential, organizationId: state.organization.id }, signal
379
+ }, { transport: toolTransport, media: canvasMedia, english: product.id === "insmind" }));
380
+ }
381
+ catch (error) {
382
+ if (!(error instanceof ToolTaskFailedError) && !(error instanceof ToolTaskCanceledError))
383
+ throw error;
384
+ const outcome = mapCliError(error, { aborted: false, product, operation: "task.get", failureStage: "task.query" });
385
+ return { state: "failed", note: outcome.failure?.message ?? text("本次处理未能完成。", "This processing could not be completed."), failure: error };
386
+ }
387
+ if (recovered.state === "complete" && progress.toolUsage)
388
+ return { state: "completed", result: await authorizeTaskResult(toolOutputWithBillingUnit({
389
+ content: recovered.content, usage: progress.toolUsage
390
+ }, product.billingUnit), state, signal, true) };
391
+ if (recovered.state === "pending")
392
+ return { state: "running", note: text("任务仍在处理中。", "The task is still processing.") };
393
+ const partialContent = recovered.state === "unknown" ? recovered.content : undefined;
394
+ return { state: "unknown", note: text(`处理停留在 ${pipeline.stage} 阶段,尚未交付完整结果。查询不会重新处理、上传或结算;请保留任务 ID 排查,勿重复提交。`, `Processing reached ${pipeline.stage}; no complete result was delivered. Querying does not process, upload, or settle again. Keep the task ID for diagnosis; do not resubmit.`),
395
+ ...(partialContent && progress.toolUsage ? { partialResult: await authorizeTaskResult(toolOutputWithBillingUnit({
396
+ content: partialContent, usage: progress.toolUsage
397
+ }, product.billingUnit), state, signal, true) } : {}) };
398
+ }
366
399
  if (!progress.remoteTaskId || !progress.toolUsage)
367
400
  return {
368
401
  state: "unknown", note: text("尚未取得任务结果。", "The task result has not been received.")
@@ -409,11 +442,14 @@ export function createProductionRuntime(options = {}) {
409
442
  warn: (message) => { presenter.warning(message); },
410
443
  telemetry
411
444
  }), product.billingUnit);
445
+ const canvasMedia = createCanvasMedia({ fetch, uploader: transientUploader });
412
446
  const tool = withToolBillingUnit(createToolUseCases({
413
447
  catalog: modelCatalog,
414
448
  tools: product.tools,
415
449
  ...(product.id === "insmind" ? { modelDescription: "Model machine identifier from model list." } : {}),
416
- execution: createToolApiAdapter({ transport: toolTransport, telemetry }),
450
+ execution: createCanvasToolAdapter({ transport: toolTransport, recordTransport: damTransport, telemetry, media: canvasMedia, english: product.id === "insmind",
451
+ fallback: createToolApiAdapter({ transport: toolTransport, telemetry }),
452
+ standardMatting: createStandardMatting({ transport: toolTransport, recordTransport: damTransport, media: canvasMedia }) }),
417
453
  uploader: transientUploader,
418
454
  warn: (message) => { presenter.warning(message); },
419
455
  telemetry
@@ -169,6 +169,6 @@ const unavailableValidator = Object.assign(() => false, { errors: null, schema:
169
169
  function assertion(validate, ErrorType) {
170
170
  return (value) => {
171
171
  if (!validate(value))
172
- throw new ErrorType(validationIssues(validate.errors));
172
+ throw new ErrorType(validationIssues(validate.errors, value, validate.schema));
173
173
  };
174
174
  }
@@ -6,6 +6,9 @@ const selectedCommands = new WeakMap();
6
6
  /** Declare the existing fixed JSON contract alongside the command registration. */
7
7
  export function jsonOutput(command) {
8
8
  jsonCommands.add(command);
9
+ if (!command.options.some(option => option.long === "--json")) {
10
+ command.option("--json", "JSON output (default)");
11
+ }
9
12
  }
10
13
  export function errorUsesJson(program, argv) {
11
14
  if (program.opts().jsonErrors === true)
@@ -26,6 +26,7 @@ export function registerAgentCommands(program, runtime) {
26
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
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>.`),
28
28
  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."),
29
+ text(runtime.product, "Generation Constraints 可选 model 来自 model list;先用 model get 查看控制参数。编辑模型只接受 quality、resolution、audioEnabled、targetLongEdge、maxLayers 中模型实际公开的控制项;prompt、素材与选区要求使用独立 Part,精确几何字段使用 tool call。", "Optional Generation Constraints model comes from model list; inspect controls with model get. Editing models accept only their published quality, resolution, audioEnabled, targetLongEdge or maxLayers controls. Supply prompts, assets and selection instructions as separate Parts; use tool call for exact geometry fields."),
29
30
  text(runtime.product, "usage 仅覆盖本次调用,不包含其他命令调用的消耗。", "usage covers this invocation only, excluding other command invocations."),
30
31
  ""
31
32
  ].join("\n"));
@@ -9,7 +9,7 @@ import { SsoRequestError } from "../features/auth/sso-service.js";
9
9
  import { AuthorizedAccountContextMissingError, BrowserOpenError, DeviceAuthorizationExpiredError } from "../features/auth/use-cases.js";
10
10
  import { AgentInputError } from "../features/agent/use-cases.js";
11
11
  import { ToolInputError } from "../features/tool/catalog.js";
12
- import { ToolTaskFailedError } from "../features/tool/tool-api-adapter.js";
12
+ import { ToolTaskFailedError, ToolTaskCanceledError, ToolInsufficientCreditsError } from "../features/tool/tool-api-adapter.js";
13
13
  import { AgentAuditRejectedError } from "../features/agent/creative-protocol.js";
14
14
  import { isContentReviewRejection } from "../features/task/creation-refusal.js";
15
15
  import { ObjectStorageUploadError } from "../features/dam/object-storage.js";
@@ -31,9 +31,12 @@ import { EditorNotReadyError, EditorSessionNotFoundError, EditorTargetError } fr
31
31
  import { UpdateError } from "../features/update/update-service.js";
32
32
  import { WindAnalyticsError } from "../analytics/wind.js";
33
33
  import { safeFailureSummary } from "../telemetry/failure-summary.js";
34
+ import { OutputStreamError } from "../platform/text-output.js";
34
35
  export class CliUsageError extends Error {
35
- constructor() {
36
+ reason;
37
+ constructor(reason = "command_arguments") {
36
38
  super("命令或参数无效。");
39
+ this.reason = reason;
37
40
  this.name = "CliUsageError";
38
41
  }
39
42
  }
@@ -57,8 +60,9 @@ export function mapCliError(error, options) {
57
60
  code: outcome.failure.code, errorType: error instanceof Error ? error.name : undefined,
58
61
  remoteCode: remote?.remoteCode,
59
62
  httpStatus: remote instanceof RemoteRequestError || remote instanceof SsoRequestError ? remote.status : undefined,
60
- diagnosticReason: remote instanceof RemoteRequestError || remote instanceof RemoteProtocolError || remote instanceof ToolTaskFailedError
61
- ? remote.diagnosticReason : undefined
63
+ diagnosticReason: error instanceof UpdateError ? error.diagnosticReason
64
+ : remote instanceof RemoteRequestError || remote instanceof RemoteProtocolError || remote instanceof ToolTaskFailedError || remote instanceof SsoRequestError
65
+ ? remote.diagnosticReason : undefined
62
66
  };
63
67
  const category = observedErrorCategory(evidence);
64
68
  if (!category)
@@ -72,6 +76,9 @@ function mapBaseCliError(error, options) {
72
76
  const insmind = options.product?.id === "insmind";
73
77
  const command = options.product?.commandName ?? "gd-cli";
74
78
  const text = (zh, en) => insmind ? en : zh;
79
+ if (error instanceof ToolTaskCanceledError)
80
+ return { kind: "interrupted", exitCode: 130,
81
+ failure: { code: "INTERRUPTED", message: text("生成任务已取消。", "The creation task was canceled.") } };
75
82
  if (options.aborted)
76
83
  return { kind: "interrupted", exitCode: 130, failure: {
77
84
  code: "INTERRUPTED", message: text("已停止本地等待;已派发的任务或写操作可能仍在继续。", "Local waiting stopped; dispatched tasks or writes may still be active."),
@@ -141,7 +148,9 @@ function mapBaseCliError(error, options) {
141
148
  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 } : {}) });
142
149
  }
143
150
  if (error instanceof LocalFileInputError)
144
- 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) });
151
+ 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: error.reason, system_code: systemErrorCode(error) });
152
+ if (error instanceof CliUsageError && error.reason === "invalid_task_id")
153
+ return failure("USAGE_ERROR", text("任务编号不正确,请使用本机任务列表中的 taskId。", "Invalid Task ID. Use a taskId from the local task list."), 2, [`${command} task list`, `${command} task get <taskId>`], { reason: error.reason });
145
154
  if (error instanceof DamInputError)
146
155
  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 });
147
156
  if (error instanceof OrgUsageError
@@ -151,8 +160,8 @@ function mapBaseCliError(error, options) {
151
160
  return failure("USAGE_ERROR", "Invalid command or arguments. See --help.", 2);
152
161
  return failure("USAGE_ERROR", "命令或参数无效,请查看 --help。", 2);
153
162
  }
154
- if (options.product?.id !== "insmind" && options.operation === "tool.call" && isInsufficientCreditsError(error)) {
155
- return failure("INSUFFICIENT_CREDITS", "当前可用额度不足,本次生成未能完成。", 1);
163
+ if (error instanceof ToolInsufficientCreditsError || options.product?.id !== "insmind" && options.operation === "tool.call" && isInsufficientCreditsError(error)) {
164
+ return failure("INSUFFICIENT_CREDITS", text("当前可用额度不足,本次生成未能完成。", "Available credits are insufficient; this creation could not complete."), 1);
156
165
  }
157
166
  if (isContentReviewRejection(error, { product: options.product?.id ?? "gaoding", operation: options.operation })) {
158
167
  const phase = error instanceof AgentAuditRejectedError ? error.phase : undefined;
@@ -255,6 +264,8 @@ function isInsufficientCreditsError(error) {
255
264
  || error instanceof ToolTaskFailedError) && error.remoteCode === INSUFFICIENT_CREDITS_REMOTE_CODE;
256
265
  }
257
266
  export function classifyTelemetryError(error, options = {}) {
267
+ if (error instanceof ToolTaskCanceledError)
268
+ return { outcome: "interrupted", errorCode: "INTERRUPTED", diagnosticReason: "TASK_CANCELED" };
258
269
  if (error instanceof WindAnalyticsError)
259
270
  return { outcome: "failure", errorCode: error.code,
260
271
  ...(error.status === undefined ? {} : { httpStatus: error.status }) };
@@ -280,8 +291,16 @@ export function classifyTelemetryError(error, options = {}) {
280
291
  catch { /* No safe summary available. */ }
281
292
  }
282
293
  const diagnosticSummary = safeFailureSummary({
294
+ ...localFileSummary(error),
295
+ ...(error instanceof OutputStreamError ? { outputStream: error.outputStream } : {}),
296
+ ...(remoteError instanceof SsoRequestError ? remoteError.diagnosticSummary : {}),
283
297
  ...(summary && typeof summary === "object" && !Array.isArray(summary) ? summary : {}),
284
- systemCode: systemErrorCode(error)
298
+ systemCode: systemErrorCode(error),
299
+ inputReason: error instanceof LocalFileInputError ? error.reason
300
+ : error instanceof JsonInputError ? `json_${error.reason}`
301
+ : error instanceof InputContractError ? "schema_validation"
302
+ : error instanceof CliUsageError || error instanceof ToolInputError || error instanceof AgentInputError ? error.reason
303
+ : error instanceof CommanderError ? error.code : undefined
285
304
  });
286
305
  return {
287
306
  outcome: outcome.kind === "interrupted" ? "interrupted" : "failure",
@@ -296,8 +315,12 @@ export function classifyTelemetryError(error, options = {}) {
296
315
  ...(remoteError?.remoteBody === undefined
297
316
  ? {}
298
317
  : { remoteErrorBody: remoteError.remoteBody }),
299
- ...((remoteError instanceof RemoteRequestError || remoteError instanceof RemoteProtocolError || remoteError instanceof ToolTaskFailedError) && remoteError.diagnosticReason
300
- ? { diagnosticReason: remoteError.diagnosticReason } : {})
318
+ ...(error instanceof DamAssetNotDownloadableError ? { diagnosticReason: error.diagnosticReason }
319
+ : error instanceof DamDownloadError ? { diagnosticReason: `DOWNLOAD_${error.phase.toUpperCase()}_FAILED` }
320
+ : error instanceof OutputStreamError ? { diagnosticReason: "OUTPUT_STREAM_FAILED" }
321
+ : error instanceof UpdateError && error.diagnosticReason ? { diagnosticReason: error.diagnosticReason }
322
+ : (remoteError instanceof RemoteRequestError || remoteError instanceof RemoteProtocolError || remoteError instanceof ToolTaskFailedError || remoteError instanceof SsoRequestError) && remoteError.diagnosticReason
323
+ ? { diagnosticReason: remoteError.diagnosticReason } : {})
301
324
  };
302
325
  }
303
326
  function failure(code, message, exitCode, nextSteps, details) {
@@ -318,6 +341,16 @@ function systemErrorCode(error) {
318
341
  }
319
342
  return undefined;
320
343
  }
344
+ function localFileSummary(error) {
345
+ for (let depth = 0; error instanceof Error && depth < 10; depth++, error = error.cause) {
346
+ if (error instanceof LocalFileError && error.diagnostic)
347
+ return {
348
+ localFileOperation: error.diagnostic.operation,
349
+ localFileStep: error.diagnostic.step
350
+ };
351
+ }
352
+ return undefined;
353
+ }
321
354
  function remoteCause(error) {
322
355
  for (let depth = 0; error instanceof Error && depth < 10; error = error.cause, depth++) {
323
356
  if (error instanceof RemoteRequestError || error instanceof RemoteProtocolError || error instanceof ToolTaskFailedError
@@ -6,7 +6,7 @@ export function registerModelCommands(program, runtime) {
6
6
  .description(text(runtime.product, "创作模型", "Creation models"))
7
7
  .helpCommand(false);
8
8
  const list = model.command("list")
9
- .description(text(runtime.product, "列出图片/视频生成模型(不含独立风格)", "List image/video generation models (excluding standalone styles)"))
9
+ .description(text(runtime.product, "列出当前可用的创作与媒体处理模型(不含独立风格)", "List available creation and media-processing models (excluding standalone styles)"))
10
10
  .option("--tool <tool>", text(runtime.product, "按工具筛选", "filter by tool"))
11
11
  .allowExcessArguments(false);
12
12
  jsonOutput(list);
@@ -32,15 +32,17 @@ export function registerModelCommands(program, runtime) {
32
32
  });
33
33
  }, { operation: "model.list" });
34
34
  const get = model.command("get")
35
- .description(text(runtime.product, "查看模型完整信息", "Show complete model information"))
35
+ .description(text(runtime.product, "查看模型完整信息与输入 Schema", "Show complete model information and input Schema"))
36
36
  .argument("<model>", text(runtime.product, "模型机器标识", "model machine identifier"))
37
+ .option("--tool <tool>", text(runtime.product, "指定模型用途上下文", "select the model's tool context"))
37
38
  .allowExcessArguments(false);
38
39
  get.addHelpText("after", [
39
40
  "",
40
41
  text(runtime.product, "只读查询当前身份可用的 Model,输出 JSON;不提交创作。参数、费用和预估耗时来自实时目录。", "Reads a Model available to the current identity as JSON without submitting creation. Parameters, cost and estimated time come from the live catalog."),
42
+ text(runtime.product, "inputSchema 是选定 Tool + Model 的完整 JSON Schema,包含嵌套对象、数组及约束。同一 Model 用于多个 Tool 时请加 --tool;优先按 inputSchema 构造 Tool 输入。", "inputSchema is the complete JSON Schema for the selected Tool + Model, including nested objects, arrays and constraints. Use --tool when a Model supports multiple Tools; construct Tool input from inputSchema."),
41
43
  text(runtime.product, "parameters 是结构化元数据,不是 JSON Schema:遵守 required/type、minimum/maximum/step,SELECT 使用 options[].value 而非 label。", "parameters is structured metadata, not JSON Schema: follow required/type, minimum/maximum/step, and use SELECT options[].value rather than label."),
42
44
  text(runtime.product, "Tool 调用须显式提供所有 required 字段;用户未指定时显式使用返回的 default。model 标识放入调用参数顶层,与模型参数并列。", "Tool calls explicitly supply every required field, using a returned default when the user omitted it. Include the returned model identifier at the top level alongside its parameters."),
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."),
45
+ text(runtime.product, "usageDescription 说明跨字段组合规则。tool call <tool> --schema 根据 model 校验对应必填字段、可用参数和范围;step 及跨字段规则另见本 Model 元数据。Agent 只传显式生成约束,不照搬 Tool 的完整必填参数。", "usageDescription explains cross-field combinations. tool call <tool> --schema validates required fields, allowed parameters and ranges per model; follow this Model's metadata for step and cross-field rules. For Agent, pass explicit generation constraints rather than copying every Tool-required parameter."),
44
46
  ""
45
47
  ].join("\n"));
46
48
  jsonOutput(get);
@@ -49,7 +51,8 @@ export function registerModelCommands(program, runtime) {
49
51
  if (typeof modelName !== "string" || modelName.trim() === "")
50
52
  throw new CliUsageError();
51
53
  runtime.telemetry.annotate({ model_id: modelName });
52
- const input = { model: modelName };
54
+ const selectedTool = get.opts().tool;
55
+ const input = { model: modelName, ...(selectedTool === undefined ? {} : { tool: selectedTool }) };
53
56
  await runtime.telemetry.stage("input", async () => {
54
57
  runtime.validators.modelGetInput(input);
55
58
  });