@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,5 +1,6 @@
|
|
|
1
|
+
import { mediaFilename, mediaTypeFromFilename } from "../../platform/media-type.js";
|
|
1
2
|
import { canvasModelBindings, canvasRemoteControlArguments } from "../tool/canvas-models.js";
|
|
2
|
-
import {
|
|
3
|
+
import { parseHttpAssetUrl, UrlSafetyError } from "../../platform/url-safety.js";
|
|
3
4
|
export class AgentInputError extends Error {
|
|
4
5
|
reason;
|
|
5
6
|
field;
|
|
@@ -10,33 +11,6 @@ export class AgentInputError extends Error {
|
|
|
10
11
|
this.name = "AgentInputError";
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
const mediaTypes = {
|
|
14
|
-
avif: "image/avif",
|
|
15
|
-
gif: "image/gif",
|
|
16
|
-
heic: "image/heic",
|
|
17
|
-
jpeg: "image/jpeg",
|
|
18
|
-
jpg: "image/jpeg",
|
|
19
|
-
mp4: "video/mp4",
|
|
20
|
-
png: "image/png",
|
|
21
|
-
webp: "image/webp"
|
|
22
|
-
};
|
|
23
|
-
function pathnameFilename(url) {
|
|
24
|
-
const segment = url.pathname.split("/").filter(Boolean).at(-1);
|
|
25
|
-
if (segment === undefined)
|
|
26
|
-
return "creative-media";
|
|
27
|
-
try {
|
|
28
|
-
return decodeURIComponent(segment) || "creative-media";
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return segment;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function inferMediaType(filename) {
|
|
35
|
-
const extension = filename.split(".").at(-1)?.toLowerCase();
|
|
36
|
-
return extension === undefined || extension === filename.toLowerCase()
|
|
37
|
-
? "application/octet-stream"
|
|
38
|
-
: mediaTypes[extension] ?? "application/octet-stream";
|
|
39
|
-
}
|
|
40
14
|
export function createAgentUseCases(dependencies) {
|
|
41
15
|
async function prepare({ input, access, signal }) {
|
|
42
16
|
signal.throwIfAborted();
|
|
@@ -77,19 +51,20 @@ export function createAgentUseCases(dependencies) {
|
|
|
77
51
|
}
|
|
78
52
|
let url;
|
|
79
53
|
try {
|
|
80
|
-
url =
|
|
54
|
+
url = parseHttpAssetUrl(part.url);
|
|
81
55
|
}
|
|
82
56
|
catch (error) {
|
|
83
57
|
if (error instanceof UrlSafetyError)
|
|
84
58
|
throw new AgentInputError("invalid_asset_url", `/message/parts/${input.message.parts.indexOf(part)}/url`, error);
|
|
85
59
|
throw error;
|
|
86
60
|
}
|
|
87
|
-
const
|
|
61
|
+
const urlFilename = mediaFilename(url);
|
|
62
|
+
const filename = part.filename ?? urlFilename;
|
|
88
63
|
prepared.push({
|
|
89
64
|
kind: "asset",
|
|
90
65
|
asset: {
|
|
91
66
|
url: part.url,
|
|
92
|
-
mediaType: part.mediaType ??
|
|
67
|
+
mediaType: part.mediaType ?? mediaTypeFromFilename(filename) ?? mediaTypeFromFilename(urlFilename) ?? "application/octet-stream",
|
|
93
68
|
filename,
|
|
94
69
|
fromUserUpload: false
|
|
95
70
|
},
|
|
@@ -5,6 +5,7 @@ import { AuthStateInvalidError, AuthStateUnavailableError, parseStoredAuthState
|
|
|
5
5
|
export function createLocalCredentialStore(options = {}) {
|
|
6
6
|
const file = options.file ?? createLocalJsonFile({
|
|
7
7
|
directory: join(options.homeDirectory ?? homedir(), options.stateDirectory ?? ".gd"),
|
|
8
|
+
protectWindowsAcl: true,
|
|
8
9
|
filename: "credentials.json",
|
|
9
10
|
role: "credentials"
|
|
10
11
|
});
|
|
@@ -2,6 +2,31 @@ import { withResponseDiagnostics } from "../../platform/signed-http-transport.js
|
|
|
2
2
|
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
3
3
|
import { availableCreditAmount, creditAmountNumber, readCreditAmount, sumCreditAmounts } from "./amount.js";
|
|
4
4
|
import { parseCreditsResponse } from "./response.js";
|
|
5
|
+
export class CreditsPageCursorError extends RemoteProtocolError {
|
|
6
|
+
partialResult;
|
|
7
|
+
constructor(partialResult) {
|
|
8
|
+
super({}, undefined, "CREDITS_NEXT_CURSOR_MISSING");
|
|
9
|
+
this.partialResult = partialResult;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function readableRows(values, project, warning) {
|
|
13
|
+
const kept = [];
|
|
14
|
+
for (const row of values) {
|
|
15
|
+
try {
|
|
16
|
+
kept.push(project(row));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (!(error instanceof RemoteProtocolError))
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (kept.length !== values.length) {
|
|
24
|
+
if (!kept.length)
|
|
25
|
+
throw new RemoteProtocolError({}, undefined, "CREDITS_NO_READABLE_ROWS");
|
|
26
|
+
warning?.();
|
|
27
|
+
}
|
|
28
|
+
return kept;
|
|
29
|
+
}
|
|
5
30
|
export function createCreditsUseCases(options) {
|
|
6
31
|
return {
|
|
7
32
|
async get(input) {
|
|
@@ -18,7 +43,7 @@ export function createCreditsUseCases(options) {
|
|
|
18
43
|
const total = readCreditAmount(source.total);
|
|
19
44
|
const used = readCreditAmount(source.used);
|
|
20
45
|
const pending = readCreditAmount(source.wait);
|
|
21
|
-
const identifier = optionalString(source.identifier);
|
|
46
|
+
const identifier = optionalString(source.identifier, options.onPartial);
|
|
22
47
|
const memberPeriodLimit = source.member_period_limit == null ? undefined : amount(source.member_period_limit);
|
|
23
48
|
return { ...(identifier === undefined ? {} : { identifier }), total, used, pending,
|
|
24
49
|
...(memberPeriodLimit === undefined ? {} : { memberPeriodLimit }) };
|
|
@@ -51,16 +76,14 @@ export function createCreditsUseCases(options) {
|
|
|
51
76
|
});
|
|
52
77
|
if (!isRecord(body) || !Array.isArray(body.items) || typeof body.has_more !== "boolean")
|
|
53
78
|
throw new RemoteProtocolError();
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
nextCursor: body.has_more ? cursor : null
|
|
63
|
-
};
|
|
79
|
+
const page = { unit: options.billingUnit, range: { from: normalized.from, to: normalized.to },
|
|
80
|
+
items: readableRows(body.items, item => readUsageRecord(item, options.onPartial), options.onPartial), hasMore: body.has_more };
|
|
81
|
+
if (!body.has_more)
|
|
82
|
+
return { ...page, nextCursor: null };
|
|
83
|
+
const cursor = body.next_cursor;
|
|
84
|
+
if (typeof cursor !== "string" || !cursor.trim())
|
|
85
|
+
throw new CreditsPageCursorError(page);
|
|
86
|
+
return { ...page, nextCursor: cursor };
|
|
64
87
|
});
|
|
65
88
|
},
|
|
66
89
|
async getUsage({ input, ...access }) {
|
|
@@ -77,14 +100,14 @@ export function createCreditsUseCases(options) {
|
|
|
77
100
|
return {
|
|
78
101
|
id: input.id,
|
|
79
102
|
unit: options.billingUnit,
|
|
80
|
-
breakdown: body.usage_logs
|
|
103
|
+
breakdown: readableRows(body.usage_logs, value => {
|
|
81
104
|
if (!isRecord(value))
|
|
82
105
|
throw new RemoteProtocolError();
|
|
83
|
-
const usageType = optionalNumber(value.usage_type);
|
|
84
|
-
const sourceType = optionalString(value.source_type);
|
|
106
|
+
const usageType = optionalNumber(value.usage_type, options.onPartial);
|
|
107
|
+
const sourceType = optionalString(value.source_type, options.onPartial);
|
|
85
108
|
return { amount: amount(value.usage), ...(usageType === undefined ? {} : { usageType }),
|
|
86
109
|
...(sourceType === undefined ? {} : { sourceType }) };
|
|
87
|
-
})
|
|
110
|
+
}, options.onPartial)
|
|
88
111
|
};
|
|
89
112
|
});
|
|
90
113
|
}
|
|
@@ -118,7 +141,7 @@ function findCreditsRecords(value) {
|
|
|
118
141
|
throw new RemoteProtocolError();
|
|
119
142
|
return [record];
|
|
120
143
|
}
|
|
121
|
-
function readUsageRecord(value) {
|
|
144
|
+
function readUsageRecord(value, warn) {
|
|
122
145
|
if (!isRecord(value))
|
|
123
146
|
throw new RemoteProtocolError();
|
|
124
147
|
let recordedAt;
|
|
@@ -128,12 +151,12 @@ function readUsageRecord(value) {
|
|
|
128
151
|
catch {
|
|
129
152
|
throw new RemoteProtocolError();
|
|
130
153
|
}
|
|
131
|
-
const recordMode = optionalString(value.record_mode);
|
|
132
|
-
const description = optionalString(value.consume_desc);
|
|
133
|
-
const scene = optionalNumber(value.consume_scene);
|
|
134
|
-
const referenceId = optionalString(value.reference_id);
|
|
135
|
-
const userId = optionalString(value.uc_id);
|
|
136
|
-
const userName = optionalString(value.user_name);
|
|
154
|
+
const recordMode = optionalString(value.record_mode, warn);
|
|
155
|
+
const description = optionalString(value.consume_desc, warn);
|
|
156
|
+
const scene = optionalNumber(value.consume_scene, warn);
|
|
157
|
+
const referenceId = optionalString(value.reference_id, warn);
|
|
158
|
+
const userId = optionalString(value.uc_id, warn);
|
|
159
|
+
const userName = optionalString(value.user_name, warn);
|
|
137
160
|
return {
|
|
138
161
|
id: requiredString(value.record_id), changeType: requiredString(value.change_type),
|
|
139
162
|
amount: amount(value.usage), recordedAt,
|
|
@@ -152,18 +175,22 @@ function requiredString(value) {
|
|
|
152
175
|
throw new RemoteProtocolError();
|
|
153
176
|
return value;
|
|
154
177
|
}
|
|
155
|
-
function optionalString(value) {
|
|
178
|
+
function optionalString(value, warn) {
|
|
156
179
|
if (value == null)
|
|
157
180
|
return undefined;
|
|
158
|
-
if (typeof value !== "string")
|
|
159
|
-
|
|
181
|
+
if (typeof value !== "string") {
|
|
182
|
+
warn?.();
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
160
185
|
return value;
|
|
161
186
|
}
|
|
162
|
-
function optionalNumber(value) {
|
|
187
|
+
function optionalNumber(value, warn) {
|
|
163
188
|
if (value == null)
|
|
164
189
|
return undefined;
|
|
165
|
-
if (typeof value !== "number" || !Number.isFinite(value))
|
|
166
|
-
|
|
190
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
191
|
+
warn?.();
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
167
194
|
return value;
|
|
168
195
|
}
|
|
169
196
|
function timestamp(value) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { filterUrlParameters } from "../../platform/public-url.js";
|
|
2
2
|
import { parseSafeRemoteAssetUrl } from "../../platform/url-safety.js";
|
|
3
3
|
const sourcePresence = new WeakMap();
|
|
4
4
|
/** Internal presence evidence survives public URL safety filtering without exposing the URL. */
|
|
@@ -91,11 +91,8 @@ function safePublicUrl(value) {
|
|
|
91
91
|
return undefined;
|
|
92
92
|
try {
|
|
93
93
|
const url = parseSafeRemoteAssetUrl(raw);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
url.searchParams.delete(key);
|
|
97
|
-
}
|
|
98
|
-
return url.href;
|
|
94
|
+
const publicUrl = filterUrlParameters(url);
|
|
95
|
+
return publicUrl.href === url.href ? raw : publicUrl.href;
|
|
99
96
|
}
|
|
100
97
|
catch {
|
|
101
98
|
return undefined;
|
|
@@ -45,6 +45,8 @@ function nonblank(value) {
|
|
|
45
45
|
function finiteNumber(value) {
|
|
46
46
|
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
47
47
|
}
|
|
48
|
+
// 2.1.x promises numeric tag/folder counts. An omitted count deliberately remains 0 for compatibility.
|
|
49
|
+
// This exception does not apply to prices, usage, or balances.
|
|
48
50
|
function nonnegativeInteger(value) {
|
|
49
51
|
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : 0;
|
|
50
52
|
}
|
|
@@ -61,10 +63,16 @@ function optionalString(value) {
|
|
|
61
63
|
const projected = String(value);
|
|
62
64
|
return projected.trim() === "" ? undefined : projected;
|
|
63
65
|
}
|
|
64
|
-
function
|
|
66
|
+
function warnSkipped(total, kept, warn) {
|
|
67
|
+
if (total > 0 && !kept)
|
|
68
|
+
throw new RemoteProtocolError({}, undefined, "DAM_NO_READABLE_ROWS");
|
|
69
|
+
if (total > kept)
|
|
70
|
+
warn?.(total - kept);
|
|
71
|
+
}
|
|
72
|
+
function folderRows(value, warn) {
|
|
65
73
|
if (!Array.isArray(value))
|
|
66
74
|
throw new RemoteProtocolError();
|
|
67
|
-
|
|
75
|
+
const result = value.flatMap((candidate) => {
|
|
68
76
|
const item = record(candidate);
|
|
69
77
|
const folderId = nonblank(item?.id);
|
|
70
78
|
const title = nonblank(item?.title);
|
|
@@ -92,6 +100,8 @@ function folderRows(value) {
|
|
|
92
100
|
...(updatedAt === undefined ? {} : { updated_at: updatedAt })
|
|
93
101
|
}];
|
|
94
102
|
});
|
|
103
|
+
warnSkipped(value.length, result.length, warn);
|
|
104
|
+
return result;
|
|
95
105
|
}
|
|
96
106
|
function folderPagination(headers) {
|
|
97
107
|
const raw = headers.get("x-pagination");
|
|
@@ -109,16 +119,16 @@ function folderPagination(headers) {
|
|
|
109
119
|
const pageSize = pagination?.size;
|
|
110
120
|
const total = pagination?.total;
|
|
111
121
|
if (!Number.isInteger(page) || page < 1
|
|
112
|
-
|| !Number.isInteger(pageSize) || pageSize < 1
|
|
122
|
+
|| !Number.isInteger(pageSize) || pageSize < 1
|
|
113
123
|
|| !Number.isInteger(total) || total < 0) {
|
|
114
124
|
throw new RemoteProtocolError();
|
|
115
125
|
}
|
|
116
126
|
return { page: page, pageSize: pageSize, total: total };
|
|
117
127
|
}
|
|
118
|
-
function tagRows(value) {
|
|
128
|
+
function tagRows(value, warn) {
|
|
119
129
|
if (!Array.isArray(value))
|
|
120
130
|
throw new RemoteProtocolError();
|
|
121
|
-
|
|
131
|
+
const result = value.flatMap((candidate) => {
|
|
122
132
|
const item = record(candidate);
|
|
123
133
|
const tagId = nonblank(item?.id);
|
|
124
134
|
const name = nonblank(item?.name);
|
|
@@ -132,6 +142,8 @@ function tagRows(value) {
|
|
|
132
142
|
asset_count: nonnegativeInteger(item?.file_count)
|
|
133
143
|
}];
|
|
134
144
|
});
|
|
145
|
+
warnSkipped(value.length, result.length, warn);
|
|
146
|
+
return result;
|
|
135
147
|
}
|
|
136
148
|
function downloadUrls(value, headers, status) {
|
|
137
149
|
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
@@ -321,7 +333,7 @@ function firstValue(response, keys) {
|
|
|
321
333
|
}
|
|
322
334
|
return undefined;
|
|
323
335
|
}
|
|
324
|
-
function searchResult(response, input) {
|
|
336
|
+
function searchResult(response, input, warn, warnPagination) {
|
|
325
337
|
const items = searchItems(response);
|
|
326
338
|
if (items === undefined)
|
|
327
339
|
throw new RemoteRequestError();
|
|
@@ -329,13 +341,16 @@ function searchResult(response, input) {
|
|
|
329
341
|
const asset = projectDamAssetSummary(item);
|
|
330
342
|
return asset === undefined ? [] : [asset];
|
|
331
343
|
});
|
|
344
|
+
warnSkipped(items.length, assets.length, warn);
|
|
332
345
|
const suppliedTotal = finiteNumber(firstValue(response, ["total", "count"]));
|
|
333
|
-
const
|
|
346
|
+
const knownTotal = suppliedTotal !== undefined && suppliedTotal >= 0;
|
|
347
|
+
const total = knownTotal ? suppliedTotal : items.length;
|
|
334
348
|
const suppliedFinish = firstValue(response, ["finish"]);
|
|
335
|
-
const finish = typeof suppliedFinish === "boolean"
|
|
336
|
-
? suppliedFinish
|
|
337
|
-
: items.length >= total;
|
|
338
349
|
const cursor = nonblank(firstValue(response, ["query_id", "cursor"]));
|
|
350
|
+
const finish = typeof suppliedFinish === "boolean" ? suppliedFinish
|
|
351
|
+
: knownTotal ? items.length >= total : cursor === undefined;
|
|
352
|
+
if (!knownTotal || typeof suppliedFinish !== "boolean")
|
|
353
|
+
warnPagination?.();
|
|
339
354
|
return {
|
|
340
355
|
repository_ids: input.repositoryIds,
|
|
341
356
|
page_size: input.pageSize,
|
|
@@ -378,16 +393,16 @@ export function createDamApiAdapter(dependencies) {
|
|
|
378
393
|
...(input.type === undefined
|
|
379
394
|
? {}
|
|
380
395
|
: { content_format_list: contentFormats[input.type] }),
|
|
381
|
-
...(input.assetFormats === undefined
|
|
396
|
+
...(input.assetFormats === undefined
|
|
382
397
|
? {}
|
|
383
398
|
: { format: input.assetFormats }),
|
|
384
|
-
...(input.tagIds === undefined
|
|
399
|
+
...(input.tagIds === undefined
|
|
385
400
|
? {}
|
|
386
401
|
: { tag_ids: input.tagIds })
|
|
387
402
|
},
|
|
388
403
|
...requestContext(input)
|
|
389
404
|
});
|
|
390
|
-
return searchResult(response, input);
|
|
405
|
+
return searchResult(response, input, dependencies.onPartial, dependencies.onPaginationFallback);
|
|
391
406
|
},
|
|
392
407
|
async listFolders(input) {
|
|
393
408
|
const response = await dependencies.transport.getJsonResponse({
|
|
@@ -411,7 +426,7 @@ export function createDamApiAdapter(dependencies) {
|
|
|
411
426
|
page: pagination.page,
|
|
412
427
|
page_size: pagination.pageSize,
|
|
413
428
|
total: pagination.total,
|
|
414
|
-
folders: folderRows(response.body)
|
|
429
|
+
folders: folderRows(response.body, dependencies.onPartial)
|
|
415
430
|
};
|
|
416
431
|
},
|
|
417
432
|
async listTags(input) {
|
|
@@ -424,7 +439,7 @@ export function createDamApiAdapter(dependencies) {
|
|
|
424
439
|
},
|
|
425
440
|
...requestContext(input)
|
|
426
441
|
});
|
|
427
|
-
return { repository_id: input.repositoryId, tags: tagRows(response) };
|
|
442
|
+
return { repository_id: input.repositoryId, tags: tagRows(response, dependencies.onPartial) };
|
|
428
443
|
},
|
|
429
444
|
async getDownloadUrls(input) {
|
|
430
445
|
const assetId = normalizeDamAssetId(input.assetId);
|
|
@@ -3,7 +3,6 @@ import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
|
3
3
|
import { createHmac } from "node:crypto";
|
|
4
4
|
import { createReadStream } from "node:fs";
|
|
5
5
|
import { stat } from "node:fs/promises";
|
|
6
|
-
import OSS from "ali-oss";
|
|
7
6
|
export class ObjectStorageUploadError extends Error {
|
|
8
7
|
constructor(cause) {
|
|
9
8
|
super("素材上传失败。", { cause });
|
|
@@ -63,6 +62,8 @@ function sleepWithSignal(milliseconds, signal) {
|
|
|
63
62
|
});
|
|
64
63
|
}
|
|
65
64
|
const defaultPutOss = async (input) => {
|
|
65
|
+
input.signal.throwIfAborted();
|
|
66
|
+
const { default: OSS } = await import("ali-oss");
|
|
66
67
|
input.signal.throwIfAborted();
|
|
67
68
|
const client = new OSS({
|
|
68
69
|
accessKeyId: input.token.accessKeyId,
|
|
@@ -77,12 +77,18 @@ function enterpriseRepositories(value) {
|
|
|
77
77
|
}];
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
-
export function normalizeRepositoryCatalog(privateRows, teamRows, enterpriseRows) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
export function normalizeRepositoryCatalog(privateRows, teamRows, enterpriseRows, onUnrepresented) {
|
|
81
|
+
const personal = privateRepositories(privateRows), teams = teamRepositories(teamRows), enterprise = enterpriseRepositories(enterpriseRows);
|
|
82
|
+
const groups = [
|
|
83
|
+
["personal", rows(privateRows).filter(row => record(row)?.type !== 8).length, personal.length],
|
|
84
|
+
["team", rows(teamRows).length, teams.length], ["enterprise", rows(enterpriseRows).length, enterprise.length]
|
|
85
85
|
];
|
|
86
|
+
const incomplete = groups.filter(([, total, count]) => total > count);
|
|
87
|
+
const merged = [...personal, ...teams, ...enterprise];
|
|
88
|
+
if (incomplete.length && !merged.length)
|
|
89
|
+
throw new RemoteProtocolError({}, undefined, "DAM_NO_READABLE_REPOSITORIES");
|
|
90
|
+
for (const [source] of incomplete)
|
|
91
|
+
onUnrepresented?.(source);
|
|
86
92
|
const seen = new Set();
|
|
87
93
|
const unique = merged.filter((repository) => {
|
|
88
94
|
if (seen.has(repository.repository_id))
|
|
@@ -91,7 +97,7 @@ export function normalizeRepositoryCatalog(privateRows, teamRows, enterpriseRows
|
|
|
91
97
|
return true;
|
|
92
98
|
});
|
|
93
99
|
const defaultIndex = unique.findIndex((repository) => repository.type === "personal");
|
|
94
|
-
const selectedIndex = defaultIndex === -1 && unique.length > 0 ? 0 : defaultIndex;
|
|
100
|
+
const selectedIndex = defaultIndex === -1 && !incomplete.length && unique.length > 0 ? 0 : defaultIndex;
|
|
95
101
|
return unique.map((repository, index) => ({
|
|
96
102
|
...repository,
|
|
97
103
|
is_default: index === selectedIndex
|
|
@@ -107,21 +113,24 @@ function requestContext(input) {
|
|
|
107
113
|
export function createDamRepositoryCatalog(dependencies) {
|
|
108
114
|
return {
|
|
109
115
|
async list(input) {
|
|
110
|
-
const [
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
const sources = ["/tb-dam/repositories", "/tb-dam/teams", "/dam/org-repositories"];
|
|
117
|
+
const results = await Promise.allSettled(sources.map(async (path) => rows(await dependencies.transport.getJson({
|
|
118
|
+
path, ...requestContext(input)
|
|
119
|
+
}))));
|
|
120
|
+
input.signal.throwIfAborted();
|
|
121
|
+
const failures = results.flatMap((r, i) => r.status === "rejected" ? [{ i, error: r.reason }] : []);
|
|
122
|
+
const [p, t, e] = results.map(r => r.status === "fulfilled" ? r.value : []);
|
|
123
|
+
const repositories = normalizeRepositoryCatalog(p, t, e, dependencies.onPartial);
|
|
124
|
+
if (failures.length && !repositories.length)
|
|
125
|
+
throw failures[0].error;
|
|
126
|
+
for (const failure of failures)
|
|
127
|
+
dependencies.onPartial?.(["personal", "team", "enterprise"][failure.i]);
|
|
128
|
+
if (failures.length && !repositories.some(r => r.type === "personal")) {
|
|
129
|
+
if (!input.allowPartial)
|
|
130
|
+
throw failures[0].error;
|
|
131
|
+
return repositories.map(r => ({ ...r, is_default: false }));
|
|
132
|
+
}
|
|
133
|
+
return repositories;
|
|
125
134
|
}
|
|
126
135
|
};
|
|
127
136
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
|
-
import {
|
|
2
|
+
import { fileUriFromLocalPath } from "../../platform/input-uri.js";
|
|
3
|
+
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
3
4
|
import { DamAssetNotDownloadableError } from "./dam-api-adapter.js";
|
|
4
5
|
import { DamInputError, normalizeDamAssetId } from "./input.js";
|
|
5
6
|
import { damAssetSourcePresent } from "./asset-projection.js";
|
|
@@ -19,8 +20,8 @@ function nonblank(value) {
|
|
|
19
20
|
return value !== undefined && value.trim() !== "";
|
|
20
21
|
}
|
|
21
22
|
function assertPageSize(value) {
|
|
22
|
-
if (value !== undefined && (!Number.
|
|
23
|
-
invalid("
|
|
23
|
+
if (value !== undefined && (!Number.isSafeInteger(value) || value < 1))
|
|
24
|
+
invalid("positive_integer", "pageSize");
|
|
24
25
|
}
|
|
25
26
|
function assertPage(value) {
|
|
26
27
|
if (value !== undefined && (!Number.isInteger(value) || value < 1))
|
|
@@ -97,8 +98,6 @@ export function createDamUseCases(dependencies) {
|
|
|
97
98
|
invalid("nonblank", "targetFolderId");
|
|
98
99
|
assertOptionalNonblank(input.repositoryId, "repositoryId");
|
|
99
100
|
assertOptionalNonblank(input.targetRepositoryId, "targetRepositoryId");
|
|
100
|
-
if (input.kind === "folder" && input.entry_id === input.targetFolderId)
|
|
101
|
-
invalid("cannot_target_self", "targetFolderId");
|
|
102
101
|
}
|
|
103
102
|
async function entryOperation(input) {
|
|
104
103
|
assertEntryOperationInput(input.request);
|
|
@@ -110,6 +109,9 @@ export function createDamUseCases(dependencies) {
|
|
|
110
109
|
if (sourceRepository === undefined)
|
|
111
110
|
throw new DamRepositoryNotFoundError();
|
|
112
111
|
const targetRepositoryId = input.request.targetRepositoryId ?? sourceRepository.id;
|
|
112
|
+
if (input.request.kind === "folder" && input.request.entry_id === input.request.targetFolderId
|
|
113
|
+
&& targetRepositoryId === sourceRepository.id)
|
|
114
|
+
invalid("cannot_target_self", "targetFolderId");
|
|
113
115
|
const locationRequest = {
|
|
114
116
|
entryId: input.request.entry_id,
|
|
115
117
|
kind: input.request.kind,
|
|
@@ -165,13 +167,16 @@ export function createDamUseCases(dependencies) {
|
|
|
165
167
|
if (input.repositoryId !== undefined)
|
|
166
168
|
return [{ id: input.repositoryId }];
|
|
167
169
|
signal.throwIfAborted();
|
|
168
|
-
const available = await dependencies.repositories.list({ access, signal });
|
|
170
|
+
const available = await dependencies.repositories.list({ access, signal, allowPartial: input.allRepositories === true });
|
|
169
171
|
signal.throwIfAborted();
|
|
170
172
|
if (available.length === 0)
|
|
171
173
|
throw new DamRepositoryNotFoundError();
|
|
174
|
+
const preferred = available.find(repository => repository.is_default);
|
|
175
|
+
if (!input.allRepositories && !preferred)
|
|
176
|
+
throw new RemoteProtocolError({}, undefined, "DAM_DEFAULT_REPOSITORY_UNKNOWN");
|
|
172
177
|
const selected = input.allRepositories === true
|
|
173
178
|
? available
|
|
174
|
-
: [
|
|
179
|
+
: [preferred];
|
|
175
180
|
return selected.map((repository) => ({
|
|
176
181
|
id: repository.repository_id,
|
|
177
182
|
...(repository.name === undefined ? {} : { name: repository.name })
|
|
@@ -180,7 +185,7 @@ export function createDamUseCases(dependencies) {
|
|
|
180
185
|
return {
|
|
181
186
|
async repositoryList({ access, signal }) {
|
|
182
187
|
signal.throwIfAborted();
|
|
183
|
-
const repositories = await dependencies.repositories.list({ access, signal });
|
|
188
|
+
const repositories = await dependencies.repositories.list({ access, signal, allowPartial: true });
|
|
184
189
|
signal.throwIfAborted();
|
|
185
190
|
if (repositories.length === 0)
|
|
186
191
|
throw new DamRepositoryNotFoundError();
|
|
@@ -448,7 +453,7 @@ export function createDamUseCases(dependencies) {
|
|
|
448
453
|
if (!nonblank(input.file))
|
|
449
454
|
invalid("nonblank", "file");
|
|
450
455
|
const file = await dependencies.telemetry.stage("inspect", () => (dependencies.storage.inspect({
|
|
451
|
-
url:
|
|
456
|
+
url: fileUriFromLocalPath(resolve(process.cwd(), input.file)),
|
|
452
457
|
...(input.allowSensitivePath === undefined
|
|
453
458
|
? {}
|
|
454
459
|
: { allowSensitivePath: input.allowSensitivePath })
|
|
@@ -19,7 +19,6 @@ export function createEditorBridgeClient(options) {
|
|
|
19
19
|
async health(signal) {
|
|
20
20
|
const value = await request("/health", "GET", undefined, signal);
|
|
21
21
|
if (!isRecord(value) ||
|
|
22
|
-
!hasExactKeys(value, ["status", "pageConnected", "protocolVersion"]) ||
|
|
23
22
|
value.status !== "ok" ||
|
|
24
23
|
typeof value.pageConnected !== "boolean" ||
|
|
25
24
|
typeof value.protocolVersion !== "number") {
|
|
@@ -42,7 +41,6 @@ export function createEditorBridgeClient(options) {
|
|
|
42
41
|
async disconnect(signal) {
|
|
43
42
|
const value = await request("/disconnect", "POST", {}, signal);
|
|
44
43
|
if (!isRecord(value) ||
|
|
45
|
-
!hasExactKeys(value, ["status"]) ||
|
|
46
44
|
value.status !== "disconnected") {
|
|
47
45
|
throw invalidResponse();
|
|
48
46
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { startDetached } from "../../platform/detached-spawn.js";
|
|
1
2
|
import { reportProcessError } from "../../telemetry/process-errors.js";
|
|
2
3
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
3
4
|
import { resolve } from "node:path";
|
|
@@ -53,7 +54,7 @@ export function startEditorBridgeProcess(input) {
|
|
|
53
54
|
return Promise.reject(abortReason(input.signal));
|
|
54
55
|
let child;
|
|
55
56
|
try {
|
|
56
|
-
child = (input.spawn ?? nodeSpawn)(process.execPath, [
|
|
57
|
+
child = startDetached(() => (input.spawn ?? nodeSpawn)(process.execPath, [
|
|
57
58
|
fileURLToPath(new URL("./bridge-process.js", import.meta.url)),
|
|
58
59
|
input.targetOrigin,
|
|
59
60
|
...(input.stateDirectory === undefined
|
|
@@ -62,7 +63,7 @@ export function startEditorBridgeProcess(input) {
|
|
|
62
63
|
], {
|
|
63
64
|
detached: true,
|
|
64
65
|
stdio: ["ignore", "ignore", "ignore", "ipc"]
|
|
65
|
-
});
|
|
66
|
+
}));
|
|
66
67
|
}
|
|
67
68
|
catch (cause) {
|
|
68
69
|
return Promise.reject(cause);
|
|
@@ -1,36 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const PRIVATE_SEGMENTS = new Set([
|
|
3
|
-
"token",
|
|
4
|
-
"signature",
|
|
5
|
-
"secret",
|
|
6
|
-
"password",
|
|
7
|
-
"credential",
|
|
8
|
-
"credentials"
|
|
9
|
-
]);
|
|
10
|
-
const PRIVATE_FOCUSED_KEYS = new Set([
|
|
11
|
-
"focused-editor-token",
|
|
12
|
-
"focused-editor-port"
|
|
13
|
-
]);
|
|
14
|
-
export function toPublicEditorUrl(input) {
|
|
15
|
-
const output = new URL(input.href);
|
|
16
|
-
removePrivateParameters(output.searchParams);
|
|
17
|
-
const fragment = output.hash.slice(1);
|
|
18
|
-
if (fragment.includes("=") || fragment.includes("&")) {
|
|
19
|
-
const parameters = new URLSearchParams(fragment);
|
|
20
|
-
removePrivateParameters(parameters);
|
|
21
|
-
output.hash = parameters.toString();
|
|
22
|
-
}
|
|
23
|
-
return output;
|
|
24
|
-
}
|
|
25
|
-
function removePrivateParameters(parameters) {
|
|
26
|
-
for (const key of new Set(parameters.keys())) {
|
|
27
|
-
if (isPrivateKey(key))
|
|
28
|
-
parameters.delete(key);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function isPrivateKey(key) {
|
|
32
|
-
const lower = key.toLowerCase();
|
|
33
|
-
if (isSensitiveKey(key) || PRIVATE_FOCUSED_KEYS.has(lower))
|
|
34
|
-
return true;
|
|
35
|
-
return lower.split(/[-_.]+/u).some((part) => PRIVATE_SEGMENTS.has(part));
|
|
36
|
-
}
|
|
1
|
+
export { filterUrlParameters as toPublicEditorUrl } from "../../platform/public-url.js";
|
|
@@ -4,6 +4,7 @@ import { createLocalJsonFile, LocalFileError } from "../../platform/local-json-f
|
|
|
4
4
|
export function createEditorSessionStateStore(options = {}) {
|
|
5
5
|
const file = options.file ?? createLocalJsonFile({
|
|
6
6
|
directory: join(options.homeDirectory ?? homedir(), options.stateDirectory ?? ".gd"),
|
|
7
|
+
protectWindowsAcl: true,
|
|
7
8
|
filename: "editor-session.json"
|
|
8
9
|
});
|
|
9
10
|
const read = async () => {
|
|
@@ -206,11 +206,12 @@ function resolveTarget(value, createUrl, workUrl, restrictTargets) {
|
|
|
206
206
|
return url;
|
|
207
207
|
}
|
|
208
208
|
function buildHandoffUrl(target, state) {
|
|
209
|
-
const url = new
|
|
210
|
-
|
|
209
|
+
const url = toPublicEditorUrl(target, new Set(["focused-editor-token", "focused-editor-port"]));
|
|
210
|
+
const handshake = new URLSearchParams({
|
|
211
211
|
"focused-editor-port": String(state.port),
|
|
212
212
|
"focused-editor-token": state.token
|
|
213
213
|
}).toString();
|
|
214
|
+
url.hash = url.hash ? url.hash.slice(1) + "&" + handshake : handshake;
|
|
214
215
|
return url;
|
|
215
216
|
}
|
|
216
217
|
function abortableSleep(milliseconds, signal) {
|