@insmind/cli 1.8.0 → 1.9.1

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 (92) 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/bin/insmind-cli.js +31 -24
  26. package/dist/bin/task-worker.js +4 -1
  27. package/dist/src/analytics/device.js +2 -2
  28. package/dist/src/bootstrap/create-cli.js +7 -0
  29. package/dist/src/bootstrap/create-runtime.js +53 -30
  30. package/dist/src/bootstrap/run-task-worker.js +5 -1
  31. package/dist/src/bootstrap/validators.js +11 -4
  32. package/dist/src/cli/agent-commands.js +1 -0
  33. package/dist/src/cli/dam-commands.js +3 -3
  34. package/dist/src/cli/errors.js +63 -15
  35. package/dist/src/cli/model-commands.js +6 -3
  36. package/dist/src/cli/observed-errors.js +3 -1
  37. package/dist/src/cli/tool-commands.js +2 -0
  38. package/dist/src/contracts/schema.js +4 -1
  39. package/dist/src/features/agent/creative-agent-adapter.js +37 -11
  40. package/dist/src/features/agent/creative-protocol.js +31 -10
  41. package/dist/src/features/agent/creative-stream.js +54 -6
  42. package/dist/src/features/agent/resource-authorizer.js +1 -0
  43. package/dist/src/features/agent/result-reader.js +3 -1
  44. package/dist/src/features/agent/use-cases.js +15 -5
  45. package/dist/src/features/auth/credential-store.js +6 -10
  46. package/dist/src/features/auth/sso-service.js +22 -6
  47. package/dist/src/features/auth/state.js +6 -0
  48. package/dist/src/features/auth/use-cases.js +90 -32
  49. package/dist/src/features/dam/asset-projection.js +10 -1
  50. package/dist/src/features/dam/dam-api-adapter.js +30 -15
  51. package/dist/src/features/dam/input.js +23 -0
  52. package/dist/src/features/dam/use-cases.js +32 -22
  53. package/dist/src/features/task/store.js +5 -5
  54. package/dist/src/features/task/task-background.js +67 -19
  55. package/dist/src/features/task/use-cases.js +38 -9
  56. package/dist/src/features/tool/canvas-copy.js +61 -0
  57. package/dist/src/features/tool/canvas-media.js +248 -0
  58. package/dist/src/features/tool/canvas-models.js +109 -0
  59. package/dist/src/features/tool/canvas-pricing.js +81 -0
  60. package/dist/src/features/tool/canvas-recovery.js +68 -0
  61. package/dist/src/features/tool/canvas-results.js +144 -0
  62. package/dist/src/features/tool/canvas-tool-adapter.js +366 -0
  63. package/dist/src/features/tool/canvas-video.js +84 -0
  64. package/dist/src/features/tool/catalog.js +35 -13
  65. package/dist/src/features/tool/dynamic-schema.js +55 -25
  66. package/dist/src/features/tool/matting-billing.js +115 -0
  67. package/dist/src/features/tool/mns-catalog-adapter.js +66 -19
  68. package/dist/src/features/tool/resource-authorizer.js +34 -0
  69. package/dist/src/features/tool/scene-catalog-adapter.js +35 -0
  70. package/dist/src/features/tool/tool-api-adapter.js +29 -17
  71. package/dist/src/features/tool/use-cases.js +28 -3
  72. package/dist/src/platform/file-lock.js +58 -15
  73. package/dist/src/platform/input-uri.js +105 -0
  74. package/dist/src/platform/local-json-file.js +7 -4
  75. package/dist/src/platform/remote-error-evidence.js +23 -1
  76. package/dist/src/platform/safe-upload-file.js +18 -4
  77. package/dist/src/platform/schema-issues.js +18 -0
  78. package/dist/src/platform/signed-http-transport.js +77 -16
  79. package/dist/src/platform/text-output.js +55 -13
  80. package/dist/src/product/config.js +12 -1
  81. package/dist/src/telemetry/failure-summary.js +53 -2
  82. package/dist/src/telemetry/host-diagnostics.js +95 -0
  83. package/dist/src/telemetry/invocation.js +24 -3
  84. package/dist/src/telemetry/process-errors.js +2 -1
  85. package/dist/src/telemetry/sls-sink.js +66 -18
  86. package/package.json +5 -4
  87. package/skills/insmind-cli/SKILL.md +2 -0
  88. package/skills/insmind-cli/references/creation.md +2 -0
  89. package/skills/insmind-cli/references/generation-constraints.md +3 -1
  90. package/skills/insmind-cli/references/matting.md +29 -0
  91. package/skills/insmind-cli/references/media-tools.md +40 -0
  92. package/skills/insmind-cli/references/tool.md +1 -1
@@ -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
+ }
@@ -15,30 +15,37 @@ let runtime;
15
15
  let mapCliError;
16
16
  let redact;
17
17
  try {
18
- const [cliModule, runtimeModule, errorsModule, redactModule] = await Promise.all([
19
- import("../src/bootstrap/create-cli.js"),
20
- import("../src/bootstrap/create-runtime.js"),
21
- import("../src/cli/errors.js"),
22
- import("../src/platform/redact.js")
23
- ]);
24
- mapCliError = errorsModule.mapCliError;
25
- redact = redactModule.redact;
26
- const selectedLocale = localeOption(process.argv.slice(2));
27
- runtime = runtimeModule.createProductionRuntime({
28
- product: insmindProduct,
29
- ...(selectedLocale === undefined ? {} : { locale: selectedLocale })
30
- });
31
- const program = cliModule.createCli(runtime, { signal: controller.signal });
32
- process.exitCode = await cliModule.executeCli({
33
- program,
34
- argv: process.argv.slice(2),
35
- presenter: runtime.presenter,
36
- signal: controller.signal,
37
- telemetry: runtime.telemetry,
38
- telemetrySink: runtime.telemetrySink,
39
- updateNotification: runtime.updateNotification,
40
- product: runtime.product
41
- });
18
+ if (process.env.CLI_INTERNAL_HOST_DIAGNOSTIC === "1" && process.argv.length === 3 && process.argv[2] === "--version") {
19
+ await import("../src/telemetry/host-diagnostics.js")
20
+ .then(({ runHostDiagnosticReporter }) => runHostDiagnosticReporter({ product: insmindProduct }))
21
+ .catch(() => undefined);
22
+ }
23
+ else {
24
+ const [cliModule, runtimeModule, errorsModule, redactModule] = await Promise.all([
25
+ import("../src/bootstrap/create-cli.js"),
26
+ import("../src/bootstrap/create-runtime.js"),
27
+ import("../src/cli/errors.js"),
28
+ import("../src/platform/redact.js")
29
+ ]);
30
+ mapCliError = errorsModule.mapCliError;
31
+ redact = redactModule.redact;
32
+ const selectedLocale = localeOption(process.argv.slice(2));
33
+ runtime = runtimeModule.createProductionRuntime({
34
+ product: insmindProduct,
35
+ ...(selectedLocale === undefined ? {} : { locale: selectedLocale })
36
+ });
37
+ const program = cliModule.createCli(runtime, { signal: controller.signal });
38
+ process.exitCode = await cliModule.executeCli({
39
+ program,
40
+ argv: process.argv.slice(2),
41
+ presenter: runtime.presenter,
42
+ signal: controller.signal,
43
+ telemetry: runtime.telemetry,
44
+ telemetrySink: runtime.telemetrySink,
45
+ updateNotification: runtime.updateNotification,
46
+ product: runtime.product
47
+ });
48
+ }
42
49
  }
43
50
  catch (error) {
44
51
  const traceId = runtime?.telemetry.traceId ?? bootstrapTraceId;
@@ -2,6 +2,7 @@
2
2
  import { reportProcessError } from "../src/telemetry/process-errors.js";
3
3
  import { once } from "node:events";
4
4
  import { Readable } from "node:stream";
5
+ import { taskWorkerUnavailableError } from "../src/features/task/task-background.js";
5
6
  import { gaodingProduct, insmindProduct } from "../src/product/config.js";
6
7
  import { createProductionRuntime } from "../src/bootstrap/create-runtime.js";
7
8
  import { runTaskWorker } from "../src/bootstrap/run-task-worker.js";
@@ -42,7 +43,9 @@ else {
42
43
  ...(currentJob?.telemetryTrackingUrl ? { trackingUrl: new URL(currentJob.telemetryTrackingUrl) } : {}),
43
44
  ...(currentJob?.telemetryEnvironment ? { environment: currentJob.telemetryEnvironment } : {}),
44
45
  ...(currentJob?.homeDirectory ? { homeDirectory: currentJob.homeDirectory } : {}) });
45
- send({ type: "error", failure: { code: "TASK_WORKER_UNAVAILABLE", message: "The background task could not start. Check task list/get before submitting again." }, exitCode: 1 });
46
+ const unavailable = taskWorkerUnavailableError({ product: currentJob?.product === "insmind" ? "insmind" : "gaoding",
47
+ phase: "bootstrap", cause: error, pid: process.pid });
48
+ send({ type: "error", failure: unavailable.failure, ...(unavailable.diagnostics ? { diagnostics: unavailable.diagnostics } : {}), exitCode: 1 });
46
49
  process.exitCode = 1;
47
50
  }
48
51
  finally {
@@ -3,7 +3,7 @@ import { join } from "node:path";
3
3
  import { withFileLock } from "../platform/file-lock.js";
4
4
  import { createLocalJsonFile } from "../platform/local-json-file.js";
5
5
  export async function loadAnalyticsDevice(directory, now) {
6
- const file = createLocalJsonFile({ directory, filename: "analytics-device.json" });
6
+ const file = createLocalJsonFile({ directory, filename: "analytics-device.json", role: "analytics_device" });
7
7
  async function read() {
8
8
  const text = await file.readText();
9
9
  if (text !== null) {
@@ -26,7 +26,7 @@ export async function loadAnalyticsDevice(directory, now) {
26
26
  const device = { id: randomUUID(), createdAt: now() };
27
27
  await file.writeTextAtomically(`${JSON.stringify(device)}\n`);
28
28
  return device;
29
- });
29
+ }, { action: "analytics_device" });
30
30
  }
31
31
  export function isFirstDay(createdAt, now) {
32
32
  return new Date(createdAt).setHours(23, 59, 59, 999) >= now ? 1 : 0;
@@ -66,6 +66,12 @@ export function createCli(runtime, options) {
66
66
  }
67
67
  export async function executeCli(options) {
68
68
  let helpOnly = false;
69
+ // Commander handles version before action selection. Preserve the real
70
+ // operation if writing that version to a closed host pipe fails.
71
+ if (options.argv.some(argument => argument === "--version" || argument === "-V")
72
+ && options.argv.every(argument => ["--version", "-V", "--json-errors"].includes(argument))) {
73
+ options.telemetry.select({ operation: "version" });
74
+ }
69
75
  try {
70
76
  try {
71
77
  await options.program.parseAsync(options.argv, { from: "user" });
@@ -157,6 +163,7 @@ async function checkUpdateNotification(updateNotification, signal) {
157
163
  }
158
164
  async function sendFinished(options, completion) {
159
165
  await analyticsShutdown.get(options.program)?.().catch(() => undefined);
166
+ await options.telemetrySink.refreshDiagnostics?.().catch(() => undefined);
160
167
  options.telemetry.annotate(options.telemetrySink.diagnostics?.() ?? {});
161
168
  const events = options.telemetry.finish(completion);
162
169
  if (events.length > 0)
@@ -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";
@@ -48,7 +54,7 @@ import { loadBundledSkills } from "../features/skill/bundled-skills.js";
48
54
  import { createUpdateService } from "../features/update/update-service.js";
49
55
  import { createUpdateNotificationService } from "../features/update/update-notification.js";
50
56
  import { classifyTelemetryError, mapCliError } from "../cli/errors.js";
51
- import { createTelemetryInvocation } from "../telemetry/invocation.js";
57
+ import { createTelemetryInvocation, hostTelemetryContext } from "../telemetry/invocation.js";
52
58
  import { createSlsTelemetrySink } from "../telemetry/sls-sink.js";
53
59
  import { gaodingProduct } from "../product/config.js";
54
60
  import { resolveProductLocale, systemLocale } from "../product/locale.js";
@@ -100,12 +106,7 @@ 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
  });
103
- telemetry.annotate({ installation_owner: installationOwner,
104
- ...(["workbuddy", "qwenwork"].includes(env.CLI_HOST_APPLICATION ?? "")
105
- ? { host_application: env.CLI_HOST_APPLICATION } : {}),
106
- ...(["auth_status", "version_check"].includes(env.CLI_INVOCATION_PURPOSE ?? "")
107
- ? { invocation_purpose: env.CLI_INVOCATION_PURPOSE } : {}),
108
- ...(/^[a-f0-9]{32}$/u.test(env.CLI_HOST_INVOCATION_ID ?? "") ? { host_invocation_id: env.CLI_HOST_INVOCATION_ID } : {}) });
109
+ telemetry.annotate({ installation_owner: installationOwner, ...hostTelemetryContext(env) });
109
110
  // Explicit test transport enables SDK tests; test-mode child processes never emit real analytics.
110
111
  const analytics = options.analytics ?? (telemetryEnvironment === "production" || options.windFetch
111
112
  ? createWindAnalytics({ product: product.id, version: options.telemetryVersion ?? primarySkill.version,
@@ -227,12 +228,13 @@ export function createProductionRuntime(options = {}) {
227
228
  const validators = createContractValidators({
228
229
  organizations: product.exposesOrganizations
229
230
  });
230
- const modelCatalog = createMnsCatalogAdapter({
231
- transport: mnsTransport,
232
- ...(product.id === "insmind"
233
- ? { invalidModelWarning: (count) => `Ignored ${count} invalid model configuration${count === 1 ? "" : "s"}.` }
234
- : {})
235
- });
231
+ const modelCatalog = createSceneCatalogAdapter({ transport: toolTransport, english: product.id === "insmind", catalog: createMnsCatalogAdapter({
232
+ english: product.id === "insmind",
233
+ transport: mnsTransport,
234
+ ...(product.id === "insmind"
235
+ ? { invalidModelWarning: (count) => `Ignored ${count} invalid model configuration${count === 1 ? "" : "s"}.` }
236
+ : {})
237
+ }) });
236
238
  const damApi = createDamApiAdapter({ transport: damTransport });
237
239
  const damRepositories = createDamRepositoryCatalog({ transport: damTransport });
238
240
  const damOperations = createDamOperationExecutor({
@@ -300,6 +302,10 @@ export function createProductionRuntime(options = {}) {
300
302
  });
301
303
  };
302
304
  const authorizeTaskResult = async (result, state, signal, alreadyAuthorized = false) => {
305
+ if ("message" in result)
306
+ validators.agentSendOutput(result);
307
+ else
308
+ validators.toolCallOutput(result);
303
309
  // Bind only if this result actually needs a fresh resource token.
304
310
  const taskAuthorizer = createAgentResourceAuthorizer({ authKeys: {
305
311
  async getAuthKey(access, tokenSignal) {
@@ -311,21 +317,7 @@ export function createProductionRuntime(options = {}) {
311
317
  const access = { credential: state.credential, organizationId: state.organization.id };
312
318
  if ("message" in result)
313
319
  return taskAuthorizer.authorize(result, access, signal);
314
- const links = result.content.filter(part => part.type === "resource_link");
315
- if (links.length === 0)
316
- return result;
317
- const parts = links.map(part => ({ url: part.uri, mediaType: part.mimeType ?? "application/octet-stream" }));
318
- const authorized = await taskAuthorizer.authorize({
319
- message: { contextId: "resource-authorization", parts: [parts[0], ...parts.slice(1)] },
320
- usage: { cost: { unit: "gaodou", amount: 0 }, items: [] }
321
- }, access, signal);
322
- let index = 0;
323
- return { ...result, content: result.content.map(part => {
324
- if (part.type !== "resource_link")
325
- return part;
326
- const authorizedPart = authorized.message.parts[index++];
327
- return authorizedPart && "url" in authorizedPart ? { ...part, uri: authorizedPart.url } : part;
328
- }) };
320
+ return authorizeToolResources(result, taskAuthorizer, access, signal);
329
321
  };
330
322
  const tasks = createTaskUseCases({
331
323
  telemetry,
@@ -365,6 +357,7 @@ export function createProductionRuntime(options = {}) {
365
357
  credential: state.credential, organizationId: state.organization.id, signal
366
358
  });
367
359
  return { state: "unknown",
360
+ ...(snapshot.usageModelMissing ? { usageModelMissing: true } : {}),
368
361
  note: snapshot.partialResult
369
362
  ? text("已找到部分内容,尚未取得完整结果。", "Some content was found, but the complete result has not been received.")
370
363
  : text("尚未取得任务结果。", "The task result has not been received."),
@@ -372,6 +365,33 @@ export function createProductionRuntime(options = {}) {
372
365
  };
373
366
  },
374
367
  async tool(progress, state, signal) {
368
+ if (progress.toolPipeline) {
369
+ const pipeline = progress.toolPipeline;
370
+ await authorizeTaskAccess(state, signal);
371
+ let recovered;
372
+ try {
373
+ recovered = await telemetry.stage("task.query", () => recoverCanvasTool(progress, {
374
+ access: { credential: state.credential, organizationId: state.organization.id }, signal
375
+ }, { transport: toolTransport, media: canvasMedia, english: product.id === "insmind" }));
376
+ }
377
+ catch (error) {
378
+ if (!(error instanceof ToolTaskFailedError) && !(error instanceof ToolTaskCanceledError))
379
+ throw error;
380
+ const outcome = mapCliError(error, { aborted: false, product, operation: "task.get", failureStage: "task.query" });
381
+ return { state: "failed", note: outcome.failure?.message ?? text("本次处理未能完成。", "This processing could not be completed."), failure: error };
382
+ }
383
+ if (recovered.state === "complete" && progress.toolUsage)
384
+ return { state: "completed", result: await authorizeTaskResult(toolOutputWithBillingUnit({
385
+ content: recovered.content, usage: progress.toolUsage
386
+ }, product.billingUnit), state, signal, true) };
387
+ if (recovered.state === "pending")
388
+ return { state: "running", note: text("任务仍在处理中。", "The task is still processing.") };
389
+ const partialContent = recovered.state === "unknown" ? recovered.content : undefined;
390
+ 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.`),
391
+ ...(partialContent && progress.toolUsage ? { partialResult: await authorizeTaskResult(toolOutputWithBillingUnit({
392
+ content: partialContent, usage: progress.toolUsage
393
+ }, product.billingUnit), state, signal, true) } : {}) };
394
+ }
375
395
  if (!progress.remoteTaskId || !progress.toolUsage)
376
396
  return {
377
397
  state: "unknown", note: text("尚未取得任务结果。", "The task result has not been received.")
@@ -418,11 +438,14 @@ export function createProductionRuntime(options = {}) {
418
438
  warn: (message) => { presenter.warning(message); },
419
439
  telemetry
420
440
  }), product.billingUnit);
441
+ const canvasMedia = createCanvasMedia({ fetch, uploader: transientUploader });
421
442
  const tool = withToolBillingUnit(createToolUseCases({
422
443
  catalog: modelCatalog,
423
444
  tools: product.tools,
424
445
  ...(product.id === "insmind" ? { modelDescription: "Model machine identifier from model list." } : {}),
425
- execution: createToolApiAdapter({ transport: toolTransport, telemetry }),
446
+ execution: createCanvasToolAdapter({ transport: toolTransport, recordTransport: damTransport, telemetry, media: canvasMedia, english: product.id === "insmind",
447
+ fallback: createToolApiAdapter({ transport: toolTransport, telemetry }),
448
+ standardMatting: createStandardMatting({ transport: toolTransport, recordTransport: damTransport, media: canvasMedia }) }),
426
449
  uploader: transientUploader,
427
450
  warn: (message) => { presenter.warning(message); },
428
451
  telemetry
@@ -49,10 +49,14 @@ export async function runTaskWorker(options) {
49
49
  : { outcome: "failure", error, errorCode: outcome.failure.code, errorMessage: outcome.failure.message };
50
50
  if (outcome.kind === "failure")
51
51
  send({ type: "error", failure: outcome.failure, exitCode: outcome.exitCode,
52
- diagnostics: taskWorkerDiagnostics(error, classifyTelemetryError(error, { product: runtime.product, operation: job.operation, failureStage: runtime.telemetry.failureStage(error) }), runtime.telemetry.failureStage(error)) });
52
+ diagnostics: taskWorkerDiagnostics(error, {
53
+ ...classifyTelemetryError(error, { product: runtime.product, operation: job.operation, failureStage: runtime.telemetry.failureStage(error) }),
54
+ diagnosticSummary: runtime.telemetry.taskFailure(error).diagnostic_summary ?? {}
55
+ }, runtime.telemetry.failureStage(error)) });
53
56
  }
54
57
  finally {
55
58
  await runtime.analytics?.shutdown().catch(() => undefined);
59
+ await runtime.telemetrySink.refreshDiagnostics?.().catch(() => undefined);
56
60
  runtime.telemetry.annotate(runtime.telemetrySink.diagnostics?.() ?? {});
57
61
  await runtime.telemetrySink.send(runtime.telemetry.finish(completion)).catch(() => undefined);
58
62
  }
@@ -1,4 +1,5 @@
1
- import { validationIssues } from "../platform/schema-issues.js";
1
+ import { inputValidationSummary, validationIssues } from "../platform/schema-issues.js";
2
+ import { canonicalizeInputFileUris } from "../platform/input-uri.js";
2
3
  import { Ajv2020 } from "ajv/dist/2020.js";
3
4
  import addFormatsImport, {} from "ajv-formats";
4
5
  import { contractSchema } from "../contracts/schema.js";
@@ -45,9 +46,11 @@ const toolCallOutputSchema = contractSchema("tool.call", "output");
45
46
  const toolListOutputSchema = contractSchema("tool.list", "output");
46
47
  export class InputContractError extends Error {
47
48
  issues;
48
- constructor(issues = []) {
49
+ diagnosticSummary;
50
+ constructor(issues = [], diagnosticSummary = {}) {
49
51
  super(`输入不符合命令契约。${issues.length ? ` ${JSON.stringify(issues)}` : ""}`);
50
52
  this.issues = issues;
53
+ this.diagnosticSummary = diagnosticSummary;
51
54
  this.name = "InputContractError";
52
55
  }
53
56
  }
@@ -168,7 +171,11 @@ export function createContractValidators(options = {}) {
168
171
  const unavailableValidator = Object.assign(() => false, { errors: null, schema: false, schemaEnv: undefined });
169
172
  function assertion(validate, ErrorType) {
170
173
  return (value) => {
171
- if (!validate(value))
172
- throw new ErrorType(validationIssues(validate.errors, value, validate.schema));
174
+ if (ErrorType === InputContractError)
175
+ canonicalizeInputFileUris(value, validate.schema);
176
+ if (!validate(value)) {
177
+ const issues = validationIssues(validate.errors, value, validate.schema);
178
+ throw new ErrorType(issues, inputValidationSummary(issues, value));
179
+ }
173
180
  };
174
181
  }
@@ -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"));
@@ -100,12 +100,12 @@ export function registerDamCommands(program, runtime) {
100
100
  });
101
101
  }, { operation: "dam.tag.list" });
102
102
  const download = leaf(dam.command("download"))
103
- .description(text(runtime.product, "下载一个素材", "Download an asset"))
103
+ .description(text(runtime.product, "下载一个素材的源文件", "Download an asset's source file"))
104
104
  .argument("<asset>", text(runtime.product, "素材 ID", "asset ID"))
105
105
  .option("--repository-id <id>", text(runtime.product, "所属资源库 ID", "repository ID"))
106
- .option("--output-dir <directory>", text(runtime.product, "输出目录", "output directory"))
106
+ .option("--output-dir <directory>", text(runtime.product, "输出目录,默认当前目录", "output directory; defaults to the current directory"))
107
107
  .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
108
- download.addHelpText("after", `\n${text(runtime.product, "只下载一个素材,不支持文件夹;写入本机目录,不覆盖已有同名文件。--json 返回 files 中的路径、字节数与摘要。", "Downloads one asset, not a folder, to a local directory without overwriting same-named files. --json returns paths, byte counts and digests in files.")}\n`);
108
+ download.addHelpText("after", `\n${text(runtime.product, "下载单个素材的源文件,不支持文件夹,也不会自动导出作品。--output-dir 指定目录;已有同名文件时选择其他目录或先处理该文件。--json 返回 files 中的路径、字节数与摘要。", "Downloads one asset's source file; folders and automatic design export are not supported. --output-dir selects a directory. If a same-named file exists, choose another directory or handle the existing file first. --json returns paths, byte counts and digests in files.")}\n`);
109
109
  bindPreparedAction(download, "organization", async (signal) => {
110
110
  signal.throwIfAborted();
111
111
  const options = download.opts();