@insmind/cli 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/contracts/operations/agent.send/input.schema.json +1 -77
- package/contracts/operations/dam.folder.list/input.schema.json +0 -1
- package/contracts/operations/dam.folder.list/output.schema.json +1 -2
- package/contracts/operations/dam.list/input.schema.json +3 -6
- package/contracts/operations/dam.list/output.schema.json +1 -2
- package/contracts/operations/dam.search/input.schema.json +3 -6
- package/contracts/operations/dam.search/output.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-edit-smart.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-expand-smart.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-layers-smart.schema.json +1 -3
- package/contracts/operations/tool.call/models/video-edit-smart.schema.json +0 -3
- package/contracts/operations/tool.call/ocr-payload.schema.json +4 -5
- package/dist/bin/postinstall.js +22 -6
- package/dist/bin/sync-skill.js +33 -0
- package/dist/bin/task-worker.js +2 -2
- package/dist/src/bootstrap/create-cli.js +13 -6
- package/dist/src/bootstrap/create-runtime.js +103 -29
- package/dist/src/bootstrap/run-task-worker.js +6 -2
- package/dist/src/bootstrap/validators.js +87 -151
- package/dist/src/cli/action-binding.js +14 -37
- package/dist/src/cli/agent-commands.js +13 -13
- package/dist/src/cli/auth-commands.js +2 -1
- package/dist/src/cli/creation-help.js +9 -0
- package/dist/src/cli/dam-commands.js +10 -14
- package/dist/src/cli/editor-commands.js +16 -12
- package/dist/src/cli/errors.js +84 -26
- package/dist/src/cli/host-input.js +62 -5
- package/dist/src/cli/model-commands.js +9 -3
- package/dist/src/cli/observed-errors.js +7 -3
- package/dist/src/cli/org-commands.js +3 -1
- package/dist/src/cli/presenter.js +4 -5
- package/dist/src/cli/task-commands.js +6 -2
- package/dist/src/cli/tool-commands.js +12 -11
- package/dist/src/contracts/creation-input.js +20 -17
- package/dist/src/features/agent/creative-agent-adapter.js +6 -2
- package/dist/src/features/agent/creative-protocol.js +8 -29
- package/dist/src/features/agent/resource-authorizer.js +25 -17
- package/dist/src/features/agent/result-reader.js +31 -14
- package/dist/src/features/agent/use-cases.js +6 -31
- package/dist/src/features/auth/credential-store.js +1 -0
- package/dist/src/features/credits/use-cases.js +55 -28
- package/dist/src/features/dam/asset-projection.js +3 -6
- package/dist/src/features/dam/dam-api-adapter.js +30 -15
- package/dist/src/features/dam/object-storage.js +2 -1
- package/dist/src/features/dam/repository-catalog.js +30 -21
- package/dist/src/features/dam/use-cases.js +14 -9
- package/dist/src/features/editor/bridge-client.js +0 -2
- package/dist/src/features/editor/bridge-process.js +3 -2
- package/dist/src/features/editor/public-url.js +1 -36
- package/dist/src/features/editor/session-state.js +1 -0
- package/dist/src/features/editor/session.js +3 -2
- package/dist/src/features/editor/use-cases.js +27 -2
- package/dist/src/features/org/org-service.js +10 -1
- package/dist/src/features/org/use-cases.js +18 -4
- package/dist/src/features/task/process-owner.js +54 -0
- package/dist/src/features/task/store.js +102 -32
- package/dist/src/features/task/task-background.js +8 -4
- package/dist/src/features/task/use-cases.js +184 -84
- package/dist/src/features/tool/argument-paths.js +14 -0
- package/dist/src/features/tool/canvas-copy.js +28 -15
- package/dist/src/features/tool/canvas-matting.js +123 -0
- package/dist/src/features/tool/canvas-media.js +102 -55
- package/dist/src/features/tool/canvas-models.js +66 -33
- package/dist/src/features/tool/canvas-pricing.js +12 -0
- package/dist/src/features/tool/canvas-recovery.js +13 -30
- package/dist/src/features/tool/canvas-results.js +92 -93
- package/dist/src/features/tool/canvas-tool-adapter.js +134 -157
- package/dist/src/features/tool/canvas-video.js +44 -37
- package/dist/src/features/tool/catalog.js +2 -23
- package/dist/src/features/tool/dynamic-schema.js +42 -46
- package/dist/src/features/tool/ffprobe-executable.js +21 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +61 -24
- package/dist/src/features/tool/resource-authorizer.js +11 -3
- package/dist/src/features/tool/tool-api-adapter.js +73 -82
- package/dist/src/features/tool/tool-definitions.js +23 -0
- package/dist/src/features/tool/tool-errors.js +25 -0
- package/dist/src/features/tool/tool-output.js +15 -0
- package/dist/src/features/tool/use-cases.js +74 -98
- package/dist/src/features/update/package-manager.js +124 -0
- package/dist/src/features/update/update-service.js +195 -55
- package/dist/src/platform/detached-spawn.js +9 -0
- package/dist/src/platform/file-lock.js +12 -4
- package/dist/src/platform/input-uri.js +23 -1
- package/dist/src/platform/local-json-file.js +97 -15
- package/dist/src/platform/media-type.js +46 -0
- package/dist/src/platform/open-browser.js +5 -2
- package/dist/src/platform/public-url.js +35 -0
- package/dist/src/platform/remote-error-evidence.js +33 -6
- package/dist/src/platform/resource-auth-key.js +35 -1
- package/dist/src/platform/safe-upload-file.js +38 -44
- package/dist/src/platform/schema-compiler.js +16 -0
- package/dist/src/platform/signature.js +2 -2
- package/dist/src/platform/signed-http-transport.js +4 -1
- package/dist/src/platform/url-safety.js +6 -1
- package/dist/src/platform/webm-header.js +41 -0
- package/dist/src/platform/windows-acl/LICENSE-mingw-w64 +43 -0
- package/dist/src/platform/windows-acl/arm64.node +0 -0
- package/dist/src/platform/windows-acl/ia32.node +0 -0
- package/dist/src/platform/windows-acl/x64.node +0 -0
- package/dist/src/platform/windows-host-job/arm64.exe +0 -0
- package/dist/src/platform/windows-host-job/ia32.exe +0 -0
- package/dist/src/platform/windows-host-job/sha256.json +7 -0
- package/dist/src/platform/windows-host-job/x64.exe +0 -0
- package/dist/src/platform/windows-private-state.js +72 -0
- package/dist/src/product/config.js +1 -1
- package/dist/src/telemetry/command-route.js +38 -0
- package/dist/src/telemetry/command-routes.json +1 -0
- package/dist/src/telemetry/failure-summary.js +3 -3
- package/dist/src/telemetry/invocation.js +1 -2
- package/dist/src/telemetry/process-errors.js +17 -33
- package/dist/src/telemetry/sanitize.js +19 -4
- package/dist/src/telemetry/sls-sink.js +45 -20
- package/package.json +4 -4
- package/skills/insmind-cli/SKILL.md +18 -5
- package/skills/insmind-cli/references/agent.md +9 -4
- package/skills/insmind-cli/references/creation.md +3 -1
- package/skills/insmind-cli/references/editor.md +7 -5
- package/skills/insmind-cli/references/errors.md +20 -9
- package/skills/insmind-cli/references/matting.md +3 -5
- package/skills/insmind-cli/references/media-tools.md +10 -4
- package/skills/insmind-cli/references/tool.md +9 -15
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { canvasModelBindings } from "./canvas-models.js";
|
|
2
|
-
import { canvasContent,
|
|
3
|
-
import {
|
|
2
|
+
import { canvasContent, ocrResult, templateResult } from "./canvas-results.js";
|
|
3
|
+
import { presentToolContent } from "./tool-output.js";
|
|
4
4
|
import { queryToolkitResult } from "./canvas-tool-adapter.js";
|
|
5
5
|
import { queryToolResult } from "./tool-api-adapter.js";
|
|
6
6
|
import { createMattingRights } from "./matting-billing.js";
|
|
@@ -10,59 +10,42 @@ export async function recoverCanvasTool(progress, context, dependencies) {
|
|
|
10
10
|
const pipeline = progress.toolPipeline;
|
|
11
11
|
if (!canvasModelBindings.some(binding => binding[1] === pipeline.model))
|
|
12
12
|
throw new RemoteProtocolError();
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const saved = pipeline.partialContent ? { content: pipeline.partialContent, fromCheckpoint: true } : {};
|
|
14
|
+
const unknown = () => ({ state: "unknown", ...saved });
|
|
15
15
|
if (pipeline.stage === "complete" && pipeline.partialContent)
|
|
16
|
-
return { state: "complete", content: pipeline.partialContent };
|
|
16
|
+
return { state: "complete", content: pipeline.partialContent, fromCheckpoint: true };
|
|
17
|
+
if (!["dify", "toolkit", "sync"].includes(pipeline.protocol))
|
|
18
|
+
return unknown();
|
|
17
19
|
if (pipeline.model === "image-matting-standard") {
|
|
18
20
|
if (pipeline.settlement && pipeline.partialContent) {
|
|
19
21
|
const { contentId, refIds } = pipeline.settlement;
|
|
20
22
|
const result = await createMattingRights(dependencies)("/open/editor/mattings/check-deducted/v2", `content_id=${encodeURIComponent(contentId)}&ref_ids=${encodeURIComponent(refIds.join(","))}&image_quality=standard`, context);
|
|
21
23
|
// Zero outstanding rights confirms this record is deliverable; it says nothing about the actual debit.
|
|
22
24
|
if (result.used_count === 0)
|
|
23
|
-
return { state: "complete", content: pipeline.partialContent };
|
|
25
|
+
return { state: "complete", content: pipeline.partialContent, fromCheckpoint: true };
|
|
24
26
|
}
|
|
25
27
|
return unknown();
|
|
26
28
|
}
|
|
27
29
|
if (!progress.remoteTaskId || pipeline.protocol === "sync")
|
|
28
30
|
return unknown();
|
|
29
31
|
const response = pipeline.protocol === "toolkit"
|
|
30
|
-
? await queryToolkitResult(dependencies.transport, progress.remoteTaskId, context)
|
|
31
|
-
: await queryToolResult(dependencies.transport, { ...context.access, signal: context.signal, taskId: progress.remoteTaskId, normalize: canvasContent });
|
|
32
|
+
? await queryToolkitResult(dependencies.transport, progress.remoteTaskId, context, dependencies.onUnrepresented)
|
|
33
|
+
: await queryToolResult(dependencies.transport, { ...context.access, signal: context.signal, taskId: progress.remoteTaskId, normalize: canvasContent, onUnrepresented: dependencies.onUnrepresented });
|
|
32
34
|
if (response.state === "failed")
|
|
33
35
|
throw response.error;
|
|
34
36
|
if (response.state === "pending")
|
|
35
37
|
return { state: "pending" };
|
|
36
38
|
// A smart matting generation is only intermediate; recovery must not submit its segmentation.
|
|
37
39
|
if (pipeline.requiresFinalization)
|
|
38
|
-
return unknown
|
|
40
|
+
return { state: "unknown", content: response.content };
|
|
39
41
|
const { model, verification } = pipeline;
|
|
40
42
|
let content;
|
|
41
43
|
if (model === "image-ocr") {
|
|
42
|
-
|
|
43
|
-
throw new RemoteProtocolError();
|
|
44
|
-
content = ocrResult(response.content, verification.ocr);
|
|
44
|
+
content = verification?.ocr ? ocrResult(response.content, verification.ocr) : response.content;
|
|
45
45
|
}
|
|
46
46
|
else if (model.startsWith("image-layers-"))
|
|
47
47
|
content = await templateResult(response.content, dependencies.media, context.signal, dependencies.english);
|
|
48
|
-
else if (model === "image-vectorize")
|
|
49
|
-
content = await vectorResult(response.content, dependencies.media, context.signal);
|
|
50
|
-
else if (model.startsWith("video-")) {
|
|
51
|
-
const resource = response.content.find(item => item.type === "resource_link");
|
|
52
|
-
if (!resource || resource.type !== "resource_link")
|
|
53
|
-
throw new RemoteProtocolError();
|
|
54
|
-
let output;
|
|
55
|
-
try {
|
|
56
|
-
output = await createCanvasVideo(dependencies.media)(resource.uri, context.signal);
|
|
57
|
-
}
|
|
58
|
-
catch (cause) {
|
|
59
|
-
if (context.signal.aborted)
|
|
60
|
-
throw context.signal.reason;
|
|
61
|
-
throw new RemoteProtocolError({}, cause, "VIDEO_OUTPUT_INVALID");
|
|
62
|
-
}
|
|
63
|
-
content = link(resource.uri, `result.${output.format}`, output.format === "mov" ? "video/quicktime" : `video/${output.format}`);
|
|
64
|
-
}
|
|
65
48
|
else
|
|
66
|
-
content =
|
|
49
|
+
content = presentToolContent(response.content, model.startsWith("video-") ? "video" : "image", dependencies.onMissingMedia);
|
|
67
50
|
return { state: "complete", content };
|
|
68
51
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
import addFormatsImport, {} from "ajv-formats";
|
|
2
|
+
import { lazySchemaCompiler } from "../../platform/schema-compiler.js";
|
|
4
3
|
import { contractDocument } from "../../contracts/schema.js";
|
|
4
|
+
import { parseHttpAssetUrl, parseSafeRemoteAssetUrl } from "../../platform/url-safety.js";
|
|
5
5
|
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
6
6
|
import { normalizeToolContent } from "./tool-api-adapter.js";
|
|
7
|
+
import { readOutputMedia } from "./canvas-media.js";
|
|
7
8
|
export function record(value) {
|
|
8
9
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
9
10
|
}
|
|
@@ -12,36 +13,46 @@ export function canvasContent(value) {
|
|
|
12
13
|
const resource = value.resource;
|
|
13
14
|
// Real RPC resources include nullable text/image/task slots. URI wins for media;
|
|
14
15
|
// OCR's inline JSON has text rather than a usable media URI.
|
|
15
|
-
if (typeof resource.uri === "string" && resource.uri.trim()
|
|
16
|
-
return normalizeToolContent(
|
|
17
|
-
...(typeof resource.mimeType === "string" && resource.mimeType ? { mimeType: resource.mimeType } : {}) } });
|
|
18
|
-
}
|
|
16
|
+
if (typeof resource.uri === "string" && resource.uri.trim())
|
|
17
|
+
return normalizeToolContent(value);
|
|
19
18
|
if (typeof resource.text === "string" && resource.text.trim())
|
|
20
19
|
return { type: "text", text: resource.text };
|
|
21
20
|
}
|
|
22
21
|
return normalizeToolContent(value);
|
|
23
22
|
}
|
|
23
|
+
function outputUri(value) {
|
|
24
|
+
try {
|
|
25
|
+
parseSafeRemoteAssetUrl(value);
|
|
26
|
+
}
|
|
27
|
+
catch (cause) {
|
|
28
|
+
throw new RemoteProtocolError({}, cause, "TOOL_RESOURCE_URI_INVALID");
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
24
32
|
export function oneResource(content) {
|
|
25
33
|
const resources = content.filter(item => item.type === "resource_link");
|
|
26
34
|
if (resources.length !== 1)
|
|
27
35
|
throw new RemoteProtocolError({}, undefined, "TOOL_SINGLE_RESOURCE_EXPECTED");
|
|
28
|
-
return resources[0].uri;
|
|
36
|
+
return outputUri(resources[0].uri);
|
|
29
37
|
}
|
|
30
38
|
export function link(uri, name, mimeType) {
|
|
31
39
|
return [{ type: "resource_link", uri, name, mimeType }];
|
|
32
40
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
41
|
+
// A version or login-state query also imports this module through the command
|
|
42
|
+
// graph. Compile each media contract only when that actual result needs it.
|
|
43
|
+
const canvasCompiler = lazySchemaCompiler({ strict: true, allErrors: true });
|
|
44
|
+
function canvasContract(file) {
|
|
45
|
+
let validate;
|
|
46
|
+
return (value) => {
|
|
47
|
+
validate ??= canvasCompiler().compile(contractDocument(file));
|
|
48
|
+
return validate(value);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const validateTemplate = canvasContract("tool.call/template-payload.schema.json");
|
|
52
|
+
const validateOcr = canvasContract("tool.call/ocr-payload.schema.json");
|
|
37
53
|
function assertOcrPayload(payload) {
|
|
38
54
|
if (!validateOcr(payload))
|
|
39
55
|
throw new RemoteProtocolError({}, undefined, "OCR_PAYLOAD_INVALID");
|
|
40
|
-
for (const block of payload.blocks) {
|
|
41
|
-
const [l, t, r, b] = block.bbox;
|
|
42
|
-
if (l > r || t > b || r > payload.image.width || b > payload.image.height)
|
|
43
|
-
throw new RemoteProtocolError({}, undefined, "OCR_COORDINATES_INVALID");
|
|
44
|
-
}
|
|
45
56
|
}
|
|
46
57
|
export function readOcrPayload(text) {
|
|
47
58
|
let payload;
|
|
@@ -55,90 +66,78 @@ export function readOcrPayload(text) {
|
|
|
55
66
|
return payload;
|
|
56
67
|
}
|
|
57
68
|
export function ocrResult(content, image, id = randomUUID()) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
const result = [];
|
|
70
|
+
for (const part of content) {
|
|
71
|
+
if (part.type === "resource_link") {
|
|
72
|
+
result.push(part);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
let blocks;
|
|
76
|
+
try {
|
|
77
|
+
blocks = JSON.parse(part.type === "text" ? part.text : part.resource.text);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
result.push(part);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const payload = { image, blocks };
|
|
84
|
+
if (!Array.isArray(blocks) || !validateOcr(payload)) {
|
|
85
|
+
result.push(part);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
result.push({ type: "resource", resource: { uri: part.type === "resource" ? part.resource.uri : `urn:uuid:${result.some(item => item.type === "resource") ? randomUUID() : id}`,
|
|
89
|
+
mimeType: "application/json", text: JSON.stringify(payload) } });
|
|
79
90
|
}
|
|
80
|
-
|
|
81
|
-
await sharp(bytes).stats();
|
|
82
|
-
return link(uri, `result.${metadata.format === "jpeg" ? "jpg" : metadata.format}`, `image/${metadata.format}`);
|
|
83
|
-
}
|
|
84
|
-
export async function vectorResult(content, media, signal) {
|
|
85
|
-
const { default: sharp } = await import("sharp");
|
|
86
|
-
const uri = oneResource(content);
|
|
87
|
-
const bytes = await media.read(uri, signal);
|
|
88
|
-
if ((await sharp(bytes).metadata()).format !== "svg")
|
|
89
|
-
throw new RemoteProtocolError({}, undefined, "SVG_INVALID");
|
|
90
|
-
return link(uri, "result.svg", "image/svg+xml");
|
|
91
|
+
return result;
|
|
91
92
|
}
|
|
92
93
|
export async function templateResult(content, media, signal, english = false) {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
const explicit = content.flatMap((part, i) => part.type === "resource_link" &&
|
|
95
|
+
(part.mimeType === "application/json" || part.name.toLowerCase().endsWith(".json")) ? [i] : []);
|
|
96
|
+
const candidates = explicit.length ? explicit : content.flatMap((part, i) => {
|
|
97
|
+
if (part.type !== "text")
|
|
98
|
+
return [];
|
|
99
|
+
try {
|
|
100
|
+
parseHttpAssetUrl(part.text.trim());
|
|
101
|
+
return /\s/u.test(part.text.trim()) ? [] : [i];
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
if (candidates.length !== 1)
|
|
108
|
+
return content;
|
|
109
|
+
const index = candidates[0];
|
|
110
|
+
const selected = content[index];
|
|
111
|
+
const uri = selected.type === "text" ? selected.text.trim() : selected.type === "resource_link" ? selected.uri : "";
|
|
112
|
+
const result = [...content];
|
|
113
|
+
if (selected.type === "text")
|
|
114
|
+
result[index] = link(uri, "template.json", "application/json")[0];
|
|
98
115
|
try {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
const bytes = await readOutputMedia(media, outputUri(uri), signal);
|
|
117
|
+
const resolved = media.deliveryUri?.(uri) ?? uri;
|
|
118
|
+
const part = result[index];
|
|
119
|
+
if (part?.type === "resource_link" && resolved !== uri)
|
|
120
|
+
result[index] = { ...part, uri: resolved };
|
|
121
|
+
const template = JSON.parse(bytes.toString("utf8"));
|
|
122
|
+
if (!validateTemplate(template) || !record(template) || !Array.isArray(template.pages))
|
|
123
|
+
throw new RemoteProtocolError();
|
|
124
|
+
const types = new Map();
|
|
125
|
+
const stack = template.pages.flatMap((page) => page.elements);
|
|
126
|
+
while (stack.length) {
|
|
127
|
+
const element = stack.pop();
|
|
110
128
|
if (!record(element) || typeof element.type !== "string")
|
|
111
|
-
|
|
129
|
+
continue;
|
|
112
130
|
types.set(element.type, (types.get(element.type) ?? 0) + 1);
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
if (record(element.background) && record(element.background.image) && typeof element.background.image.url === "string" && element.background.image.url)
|
|
116
|
-
assets.add(element.background.image.url);
|
|
117
|
-
if (element.elements !== undefined) {
|
|
118
|
-
if (!Array.isArray(element.elements))
|
|
119
|
-
throw new RemoteProtocolError();
|
|
120
|
-
inspectElements(element.elements);
|
|
121
|
-
}
|
|
131
|
+
if (Array.isArray(element.elements))
|
|
132
|
+
stack.push(...element.elements);
|
|
122
133
|
}
|
|
134
|
+
const counts = [...types].map(([type, count]) => `${type}: ${count}`).join("; ");
|
|
135
|
+
result.push({ type: "text", text: english ? `Native template, ${counts}. The editor matches fonts and may substitute missing fonts.`
|
|
136
|
+
: `原生模板,${counts}。字体由编辑器匹配,缺失字体可能替换。` });
|
|
123
137
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
for (const layout of page.elements) {
|
|
128
|
-
if (!record(layout) || typeof layout.width !== "number" || layout.width <= 0
|
|
129
|
-
|| typeof layout.height !== "number" || layout.height <= 0 || !record(layout.background)
|
|
130
|
-
|| !record(layout.background.image) || !Array.isArray(layout.elements))
|
|
131
|
-
throw new RemoteProtocolError({}, undefined, "TEMPLATE_LAYOUT_INVALID");
|
|
132
|
-
}
|
|
133
|
-
inspectElements(page.elements);
|
|
134
|
-
}
|
|
135
|
-
for (const asset of assets) {
|
|
136
|
-
const bytes = await media.read(asset, signal);
|
|
137
|
-
if (bytes.length === 0)
|
|
138
|
-
throw new RemoteProtocolError();
|
|
138
|
+
catch {
|
|
139
|
+
signal.throwIfAborted();
|
|
140
|
+
result.push({ type: "text", text: english ? "The template link is included. Its layer summary is unavailable." : "已返回模板链接,暂未取得图层摘要。" });
|
|
139
141
|
}
|
|
140
|
-
|
|
141
|
-
return [...link(uri, "template.json", "application/json"), { type: "text", text: english
|
|
142
|
-
? `Native template, ${counts}. The editor matches fonts and may substitute missing fonts.`
|
|
143
|
-
: `原生模板,${counts}。字体由编辑器匹配,缺失字体可能替换。` }];
|
|
142
|
+
return result;
|
|
144
143
|
}
|