@insmind/cli 1.8.0 → 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.
- package/contracts/operations/model.get/input.schema.json +5 -0
- package/contracts/operations/model.get/output.schema.json +9 -1
- package/contracts/operations/tool.call/canvas-input.schema.json +60 -0
- package/contracts/operations/tool.call/models/image-edit-smart.schema.json +39 -0
- package/contracts/operations/tool.call/models/image-edit-standard.schema.json +31 -0
- package/contracts/operations/tool.call/models/image-enhance-smart.schema.json +26 -0
- package/contracts/operations/tool.call/models/image-enhance-standard.schema.json +25 -0
- package/contracts/operations/tool.call/models/image-expand-smart.schema.json +72 -0
- package/contracts/operations/tool.call/models/image-expand-standard.schema.json +58 -0
- package/contracts/operations/tool.call/models/image-layers-layout.schema.json +20 -0
- package/contracts/operations/tool.call/models/image-layers-smart.schema.json +26 -0
- package/contracts/operations/tool.call/models/image-matting-smart.schema.json +34 -0
- package/contracts/operations/tool.call/models/image-matting-standard.schema.json +24 -0
- package/contracts/operations/tool.call/models/image-ocr.schema.json +20 -0
- package/contracts/operations/tool.call/models/image-remove-smart.schema.json +30 -0
- package/contracts/operations/tool.call/models/image-remove-standard.schema.json +25 -0
- package/contracts/operations/tool.call/models/image-text-edit.schema.json +43 -0
- package/contracts/operations/tool.call/models/image-vectorize.schema.json +20 -0
- package/contracts/operations/tool.call/models/video-edit-smart.schema.json +68 -0
- package/contracts/operations/tool.call/models/video-enhance-smart.schema.json +32 -0
- package/contracts/operations/tool.call/models/video-enhance-standard.schema.json +26 -0
- package/contracts/operations/tool.call/ocr-payload.schema.json +65 -0
- package/contracts/operations/tool.call/output.schema.json +38 -0
- package/contracts/operations/tool.call/template-payload.schema.json +95 -0
- package/dist/src/bootstrap/create-runtime.js +50 -23
- package/dist/src/cli/agent-commands.js +1 -0
- package/dist/src/cli/errors.js +3 -3
- package/dist/src/cli/model-commands.js +6 -3
- package/dist/src/cli/tool-commands.js +2 -0
- package/dist/src/contracts/schema.js +4 -1
- package/dist/src/features/agent/creative-protocol.js +22 -5
- package/dist/src/features/agent/resource-authorizer.js +1 -0
- package/dist/src/features/agent/use-cases.js +15 -5
- package/dist/src/features/task/use-cases.js +4 -3
- package/dist/src/features/tool/canvas-copy.js +61 -0
- package/dist/src/features/tool/canvas-media.js +193 -0
- package/dist/src/features/tool/canvas-models.js +109 -0
- package/dist/src/features/tool/canvas-pricing.js +81 -0
- package/dist/src/features/tool/canvas-recovery.js +68 -0
- package/dist/src/features/tool/canvas-results.js +144 -0
- package/dist/src/features/tool/canvas-tool-adapter.js +366 -0
- package/dist/src/features/tool/canvas-video.js +84 -0
- package/dist/src/features/tool/catalog.js +35 -13
- package/dist/src/features/tool/dynamic-schema.js +48 -22
- package/dist/src/features/tool/matting-billing.js +103 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +66 -19
- package/dist/src/features/tool/resource-authorizer.js +34 -0
- package/dist/src/features/tool/scene-catalog-adapter.js +35 -0
- package/dist/src/features/tool/tool-api-adapter.js +13 -4
- package/dist/src/features/tool/use-cases.js +28 -3
- package/dist/src/product/config.js +12 -1
- package/package.json +5 -4
- package/skills/insmind-cli/SKILL.md +2 -0
- package/skills/insmind-cli/references/creation.md +2 -0
- package/skills/insmind-cli/references/generation-constraints.md +3 -1
- package/skills/insmind-cli/references/matting.md +29 -0
- package/skills/insmind-cli/references/media-tools.md +40 -0
- 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
|
+
}
|
|
@@ -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";
|
|
@@ -227,12 +233,13 @@ export function createProductionRuntime(options = {}) {
|
|
|
227
233
|
const validators = createContractValidators({
|
|
228
234
|
organizations: product.exposesOrganizations
|
|
229
235
|
});
|
|
230
|
-
const modelCatalog = createMnsCatalogAdapter({
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
+
}) });
|
|
236
243
|
const damApi = createDamApiAdapter({ transport: damTransport });
|
|
237
244
|
const damRepositories = createDamRepositoryCatalog({ transport: damTransport });
|
|
238
245
|
const damOperations = createDamOperationExecutor({
|
|
@@ -300,6 +307,10 @@ export function createProductionRuntime(options = {}) {
|
|
|
300
307
|
});
|
|
301
308
|
};
|
|
302
309
|
const authorizeTaskResult = async (result, state, signal, alreadyAuthorized = false) => {
|
|
310
|
+
if ("message" in result)
|
|
311
|
+
validators.agentSendOutput(result);
|
|
312
|
+
else
|
|
313
|
+
validators.toolCallOutput(result);
|
|
303
314
|
// Bind only if this result actually needs a fresh resource token.
|
|
304
315
|
const taskAuthorizer = createAgentResourceAuthorizer({ authKeys: {
|
|
305
316
|
async getAuthKey(access, tokenSignal) {
|
|
@@ -311,21 +322,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
311
322
|
const access = { credential: state.credential, organizationId: state.organization.id };
|
|
312
323
|
if ("message" in result)
|
|
313
324
|
return taskAuthorizer.authorize(result, access, signal);
|
|
314
|
-
|
|
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
|
-
}) };
|
|
325
|
+
return authorizeToolResources(result, taskAuthorizer, access, signal);
|
|
329
326
|
};
|
|
330
327
|
const tasks = createTaskUseCases({
|
|
331
328
|
telemetry,
|
|
@@ -372,6 +369,33 @@ export function createProductionRuntime(options = {}) {
|
|
|
372
369
|
};
|
|
373
370
|
},
|
|
374
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
|
+
}
|
|
375
399
|
if (!progress.remoteTaskId || !progress.toolUsage)
|
|
376
400
|
return {
|
|
377
401
|
state: "unknown", note: text("尚未取得任务结果。", "The task result has not been received.")
|
|
@@ -418,11 +442,14 @@ export function createProductionRuntime(options = {}) {
|
|
|
418
442
|
warn: (message) => { presenter.warning(message); },
|
|
419
443
|
telemetry
|
|
420
444
|
}), product.billingUnit);
|
|
445
|
+
const canvasMedia = createCanvasMedia({ fetch, uploader: transientUploader });
|
|
421
446
|
const tool = withToolBillingUnit(createToolUseCases({
|
|
422
447
|
catalog: modelCatalog,
|
|
423
448
|
tools: product.tools,
|
|
424
449
|
...(product.id === "insmind" ? { modelDescription: "Model machine identifier from model list." } : {}),
|
|
425
|
-
execution:
|
|
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 }) }),
|
|
426
453
|
uploader: transientUploader,
|
|
427
454
|
warn: (message) => { presenter.warning(message); },
|
|
428
455
|
telemetry
|
|
@@ -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"));
|
package/dist/src/cli/errors.js
CHANGED
|
@@ -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, ToolTaskCanceledError } 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";
|
|
@@ -160,8 +160,8 @@ function mapBaseCliError(error, options) {
|
|
|
160
160
|
return failure("USAGE_ERROR", "Invalid command or arguments. See --help.", 2);
|
|
161
161
|
return failure("USAGE_ERROR", "命令或参数无效,请查看 --help。", 2);
|
|
162
162
|
}
|
|
163
|
-
if (options.product?.id !== "insmind" && options.operation === "tool.call" && isInsufficientCreditsError(error)) {
|
|
164
|
-
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);
|
|
165
165
|
}
|
|
166
166
|
if (isContentReviewRejection(error, { product: options.product?.id ?? "gaoding", operation: options.operation })) {
|
|
167
167
|
const phase = error instanceof AgentAuditRejectedError ? error.phase : undefined;
|
|
@@ -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, "
|
|
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,12 +32,14 @@ export function registerModelCommands(program, runtime) {
|
|
|
32
32
|
});
|
|
33
33
|
}, { operation: "model.list" });
|
|
34
34
|
const get = model.command("get")
|
|
35
|
-
.description(text(runtime.product, "
|
|
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
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."),
|
|
@@ -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
|
|
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
|
});
|
|
@@ -37,7 +37,9 @@ export function registerToolCommands(program, runtime) {
|
|
|
37
37
|
text(runtime.product, "异步任务由本机后台进程继续等待结果;进程终止或关机可能使状态变为 unknown。", "Async work continues in a local background process; termination or shutdown may leave its state unknown."),
|
|
38
38
|
text(runtime.product, "用 task get <taskId> 查询原任务;completed 时 result 为完整结果,running/unknown 或查询超时不应重新提交。", "Query the same taskId with task get; completed includes result. Do not resubmit on running, unknown, or a query timeout."),
|
|
39
39
|
text(runtime.product, "默认等待原 Tool 结果;任务 ID 写入 stderr,stdout 保持原 JSON。", "By default, the command waits for the original Tool result; stderr shows the Task ID and stdout keeps the result JSON."),
|
|
40
|
+
text(runtime.product, "媒体 URI 字段支持 HTTP(S) 与本地 file:// URI;CLI 会按调用上传本地素材,可直接用于原图、参考素材和选区。", "Media URI fields accept HTTP(S) and local file:// URIs; the CLI uploads local inputs for the call, including source media, references and masks."),
|
|
40
41
|
text(runtime.product, `结果未收到时用 ${runtime.product.commandName} task list 找到调用,再用 ${runtime.product.commandName} task get <id> 查询,不重复生成。`, `If output is missing, use ${runtime.product.commandName} task list and ${runtime.product.commandName} task get <id> to recover it without generating again.`),
|
|
42
|
+
text(runtime.product, "完整结果为 {content,usage}。content 项为 text、resource_link(uri/name/mimeType)或 resource(resource.uri/mimeType/text);OCR 的 resource.text 是 JSON。分层返回原生模板 JSON 链接,不是 PSD;视频处理需检查实际音轨。", "Complete results are {content,usage}. Content items are text, resource_link (uri/name/mimeType), or resource (resource.uri/mimeType/text); OCR resource.text contains JSON. Layer decomposition returns a native template JSON link, not PSD; verify actual audio after video processing."),
|
|
41
43
|
text(runtime.product, "查询返回同一份 usage;Tool usage.cost 为当次目录预估价格。", "Queries return the same usage; Tool usage.cost is the catalog price estimate for that invocation."),
|
|
42
44
|
""
|
|
43
45
|
].join("\n"));
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
export function contractSchema(operation, direction) {
|
|
3
|
-
return
|
|
3
|
+
return contractDocument(`${operation}/${direction}.schema.json`);
|
|
4
|
+
}
|
|
5
|
+
export function contractDocument(path) {
|
|
6
|
+
return JSON.parse(readFileSync(new URL(`../../../contracts/operations/${path}`, import.meta.url), "utf8"));
|
|
4
7
|
}
|
|
@@ -203,8 +203,25 @@ function inferMediaType(url) {
|
|
|
203
203
|
webp: "image/webp"
|
|
204
204
|
}[extension ?? ""] ?? "application/octet-stream";
|
|
205
205
|
}
|
|
206
|
-
function
|
|
207
|
-
|
|
206
|
+
function isBillingMetadataText(text, message) {
|
|
207
|
+
if (message.role !== "function")
|
|
208
|
+
return false;
|
|
209
|
+
const extra = record(message.extra);
|
|
210
|
+
const amount = extra?.deduct_points;
|
|
211
|
+
if (nonEmptyString(extra?.task_id) === undefined
|
|
212
|
+
|| nonEmptyString(extra?.scene_code) === undefined
|
|
213
|
+
|| typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
214
|
+
return false;
|
|
215
|
+
// The Agent appends this exact metadata mirror as tool text. Require matching
|
|
216
|
+
// structured billing evidence; ordinary JSON and assistant text remain intact.
|
|
217
|
+
const fields = record(parseJson(text));
|
|
218
|
+
return fields !== undefined && Object.keys(fields).length === 2
|
|
219
|
+
&& fields.deduct_points === amount
|
|
220
|
+
&& typeof fields.balance_points === "number"
|
|
221
|
+
&& Number.isFinite(fields.balance_points) && fields.balance_points >= 0;
|
|
222
|
+
}
|
|
223
|
+
function functionResponseParts(message) {
|
|
224
|
+
const parsed = parseJson(contentOf(message)?.text);
|
|
208
225
|
const values = Array.isArray(parsed) ? parsed : parsed === undefined ? [] : [parsed];
|
|
209
226
|
const parts = [];
|
|
210
227
|
for (const value of values) {
|
|
@@ -212,7 +229,7 @@ function functionResponseParts(raw) {
|
|
|
212
229
|
if (item === undefined)
|
|
213
230
|
continue;
|
|
214
231
|
const text = nonEmptyString(item.text);
|
|
215
|
-
if (text !== undefined)
|
|
232
|
+
if (text !== undefined && !isBillingMetadataText(text, message))
|
|
216
233
|
parts.push({ text });
|
|
217
234
|
const url = nonEmptyString(item.uri ?? item.url);
|
|
218
235
|
if (url === undefined)
|
|
@@ -255,7 +272,7 @@ export function restoreCreativeResourceUrls(messages, streamed) {
|
|
|
255
272
|
const content = contentOf(message);
|
|
256
273
|
if (content?.type !== "function_response")
|
|
257
274
|
continue;
|
|
258
|
-
for (const part of functionResponseParts(
|
|
275
|
+
for (const part of functionResponseParts(message)) {
|
|
259
276
|
if (!("url" in part) || !hasAuthKey(part.url))
|
|
260
277
|
continue;
|
|
261
278
|
const identity = resourceUrlIdentity(part.url);
|
|
@@ -402,7 +419,7 @@ export function normalizeCreativeMessages(messages) {
|
|
|
402
419
|
parts.push({ text });
|
|
403
420
|
}
|
|
404
421
|
else if (content.type === "function_response") {
|
|
405
|
-
parts.push(...functionResponseParts(
|
|
422
|
+
parts.push(...functionResponseParts(message));
|
|
406
423
|
}
|
|
407
424
|
}
|
|
408
425
|
else {
|
|
@@ -8,6 +8,7 @@ function unsignedPrivateUrl(value) {
|
|
|
8
8
|
throw new RemoteProtocolError();
|
|
9
9
|
}
|
|
10
10
|
const isPrivate = /^gd-ai-[a-z0-9-]+\.dancf\.com$/iu.test(url.hostname)
|
|
11
|
+
|| /^gdesign-dam(?:-[a-z0-9-]+)?\.dancf\.com$/iu.test(url.hostname)
|
|
11
12
|
|| url.hostname === "dify-grsai.dancf.com"
|
|
12
13
|
|| url.hostname === "dify-aiznt.dancf.com";
|
|
13
14
|
if (!isPrivate || url.searchParams.get("auth_key")?.trim())
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { findModel, ToolInputError } from "../tool/catalog.js";
|
|
2
2
|
import { modelControlArgumentsAreValid } from "../tool/dynamic-schema.js";
|
|
3
|
+
import { canvasRemoteControlArguments } from "../tool/canvas-models.js";
|
|
3
4
|
import { parseSafeRemoteAssetUrl, UrlSafetyError } from "../../platform/url-safety.js";
|
|
4
5
|
export class AgentInputError extends Error {
|
|
5
6
|
reason;
|
|
@@ -50,6 +51,7 @@ export function createAgentUseCases(dependencies) {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
if (generation?.model !== undefined) {
|
|
54
|
+
const requested = generation;
|
|
53
55
|
dependencies.telemetry.annotate({ model_id: generation.model });
|
|
54
56
|
const catalog = await dependencies.telemetry.stage("catalog", () => (dependencies.catalog.load({ access, signal })));
|
|
55
57
|
signal.throwIfAborted();
|
|
@@ -60,15 +62,23 @@ export function createAgentUseCases(dependencies) {
|
|
|
60
62
|
await dependencies.telemetry.stage("input", async () => {
|
|
61
63
|
let model;
|
|
62
64
|
try {
|
|
63
|
-
model = findModel(catalog,
|
|
65
|
+
model = findModel(catalog, requested.model);
|
|
64
66
|
}
|
|
65
67
|
catch (error) {
|
|
66
68
|
if (error instanceof ToolInputError)
|
|
67
69
|
throw new AgentInputError(error.reason, "/generation/model", error);
|
|
68
70
|
throw error;
|
|
69
71
|
}
|
|
70
|
-
if (!modelControlArgumentsAreValid(model,
|
|
72
|
+
if (!modelControlArgumentsAreValid(model, requested.arguments ?? {}))
|
|
71
73
|
throw new AgentInputError("model_parameters", "/generation/arguments");
|
|
74
|
+
if (model.execution?.kind === "canvas") {
|
|
75
|
+
generation = {
|
|
76
|
+
model: model.execution.code,
|
|
77
|
+
...(requested.arguments === undefined ? {} : {
|
|
78
|
+
arguments: canvasRemoteControlArguments(model.model, requested.arguments)
|
|
79
|
+
})
|
|
80
|
+
};
|
|
81
|
+
}
|
|
72
82
|
});
|
|
73
83
|
}
|
|
74
84
|
const prepare = async () => {
|
|
@@ -128,10 +138,10 @@ export function createAgentUseCases(dependencies) {
|
|
|
128
138
|
prepared.push({
|
|
129
139
|
kind: "generation",
|
|
130
140
|
data: {
|
|
131
|
-
...(
|
|
132
|
-
...(
|
|
141
|
+
...(generation?.model === undefined ? {} : { model: generation.model }),
|
|
142
|
+
...(generation?.arguments === undefined
|
|
133
143
|
? {}
|
|
134
|
-
: { arguments: { ...
|
|
144
|
+
: { arguments: { ...generation.arguments } })
|
|
135
145
|
}
|
|
136
146
|
});
|
|
137
147
|
}
|
|
@@ -159,8 +159,8 @@ export function createTaskUseCases(dependencies) {
|
|
|
159
159
|
let details;
|
|
160
160
|
if (input.operation === "agent.send")
|
|
161
161
|
details = { tool_type: "agent", tool_name: "agent" };
|
|
162
|
-
else if (generation?.model && (generation.tool
|
|
163
|
-
const name = generation.tool
|
|
162
|
+
else if (generation?.model && (generation.tool.startsWith("image.") || generation.tool.startsWith("video."))) {
|
|
163
|
+
const name = generation.tool.startsWith("image.") ? "AI绘图" : "AI视频生成";
|
|
164
164
|
details = { tool_type: name, tool_name: name, model_name: generation.model };
|
|
165
165
|
}
|
|
166
166
|
else
|
|
@@ -222,7 +222,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
222
222
|
await analyticsFact("started");
|
|
223
223
|
return;
|
|
224
224
|
}
|
|
225
|
-
Object.assign(record.progress, progress);
|
|
225
|
+
Object.assign(record.progress, withoutResourceKeys(progress));
|
|
226
226
|
if (progress.contextId)
|
|
227
227
|
record.task.contextId = progress.contextId;
|
|
228
228
|
try {
|
|
@@ -327,6 +327,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
327
327
|
stored.task = { ...stored.task, state: "unknown", note: text("尚未取得任务结果。", "The task result has not been received.") };
|
|
328
328
|
}));
|
|
329
329
|
}
|
|
330
|
+
record = withoutResourceKeys(record);
|
|
330
331
|
telemetry?.annotate({ cli_task_id: id, result_state: record.task.state });
|
|
331
332
|
if (record.task.state === "completed" && record.task.result) {
|
|
332
333
|
const result = { ...record.task, result: await stage("task.authorize", () => dependencies.recovery.authorize(record.task.result, state, signal)) };
|