@insmind/cli 1.5.0 → 1.5.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/dist/bin/agent-worker.js +2 -1
- package/dist/bin/insmind-cli.js +12 -7
- package/dist/bin/postinstall.js +7 -5
- package/dist/src/bootstrap/create-cli.js +26 -17
- package/dist/src/bootstrap/create-runtime.js +31 -13
- package/dist/src/bootstrap/run-agent-worker.js +2 -1
- package/dist/src/bootstrap/validators.js +10 -5
- package/dist/src/cli/action-binding.js +14 -0
- package/dist/src/cli/agent-commands.js +8 -3
- package/dist/src/cli/auth-commands.js +1 -1
- package/dist/src/cli/credits-command.js +2 -2
- package/dist/src/cli/dam-commands.js +51 -52
- package/dist/src/cli/editor-commands.js +13 -15
- package/dist/src/cli/errors.js +91 -41
- package/dist/src/cli/model-commands.js +7 -5
- package/dist/src/cli/presenter.js +13 -10
- package/dist/src/cli/task-commands.js +13 -5
- package/dist/src/cli/tool-commands.js +9 -3
- package/dist/src/features/agent/use-cases.js +11 -5
- package/dist/src/features/auth/credential-store.js +2 -2
- package/dist/src/features/auth/sso-service.js +3 -2
- package/dist/src/features/auth/state.js +2 -0
- package/dist/src/features/auth/use-cases.js +30 -34
- package/dist/src/features/credits/use-cases.js +2 -0
- package/dist/src/features/dam/file-downloader.js +38 -16
- package/dist/src/features/dam/object-storage.js +23 -11
- package/dist/src/features/dam/operation-executor.js +46 -37
- package/dist/src/features/dam/registered-uploader.js +39 -29
- package/dist/src/features/dam/storage-upload.js +5 -4
- package/dist/src/features/dam/use-cases.js +81 -60
- package/dist/src/features/editor/bridge-client.js +6 -6
- package/dist/src/features/editor/bridge-process.js +2 -1
- package/dist/src/features/editor/session-state.js +6 -4
- package/dist/src/features/editor/session.js +26 -8
- package/dist/src/features/editor/use-cases.js +10 -3
- package/dist/src/features/org/use-cases.js +2 -1
- package/dist/src/features/task/agent-background.js +1 -0
- package/dist/src/features/task/store.js +2 -0
- package/dist/src/features/task/use-cases.js +80 -27
- package/dist/src/features/tool/catalog.js +11 -5
- package/dist/src/features/tool/dynamic-schema.js +9 -7
- package/dist/src/features/tool/mns-catalog-adapter.js +7 -23
- package/dist/src/features/tool/tool-api-adapter.js +8 -7
- package/dist/src/features/tool/use-cases.js +7 -3
- package/dist/src/features/update/update-notification.js +75 -70
- package/dist/src/features/update/update-service.js +24 -20
- package/dist/src/platform/file-lock.js +36 -9
- package/dist/src/platform/interruption.js +13 -0
- package/dist/src/platform/json-input.js +12 -9
- package/dist/src/platform/local-json-file.js +8 -4
- package/dist/src/platform/redact.js +7 -1
- package/dist/src/platform/remote-protocol.js +2 -2
- package/dist/src/platform/safe-upload-file.js +2 -1
- package/dist/src/platform/schema-issues.js +8 -0
- package/dist/src/platform/signed-http-transport.js +8 -7
- package/dist/src/platform/text-output.js +33 -0
- package/dist/src/telemetry/invocation.js +19 -4
- package/dist/src/telemetry/process-errors.js +14 -4
- package/dist/src/telemetry/sanitize.js +4 -2
- package/dist/src/telemetry/sls-sink.js +36 -20
- package/package.json +4 -4
|
@@ -7,9 +7,11 @@ export class DamOperationFailedError extends Error {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
export class DamOperationUnconfirmedError extends Error {
|
|
10
|
+
context;
|
|
10
11
|
operation;
|
|
11
|
-
constructor(operation) {
|
|
12
|
-
super(
|
|
12
|
+
constructor(operation, context = {}, cause) {
|
|
13
|
+
super(`DAM ${operation} was submitted; final outcome is unconfirmed (phase: ${String(context.phase ?? "verify")}).`, { cause });
|
|
14
|
+
this.context = context;
|
|
13
15
|
this.name = "DamOperationUnconfirmedError";
|
|
14
16
|
this.operation = operation;
|
|
15
17
|
}
|
|
@@ -24,48 +26,55 @@ export function createDamOperationExecutor(dependencies) {
|
|
|
24
26
|
input.signal.throwIfAborted();
|
|
25
27
|
const startedAt = dependencies.now();
|
|
26
28
|
const submission = await input.submit();
|
|
27
|
-
input.signal.throwIfAborted();
|
|
28
29
|
const taskId = submission.task_id;
|
|
29
|
-
|
|
30
|
-
const copied = input.operation === "copy"
|
|
31
|
-
? copiedEntryId(submission.result_ids)
|
|
32
|
-
: undefined;
|
|
33
|
-
return copied === undefined ? {} : { copied_entry_id: copied };
|
|
34
|
-
}
|
|
35
|
-
dependencies.annotate({ task_id: taskId });
|
|
36
|
-
let delayMilliseconds = 1_000;
|
|
37
|
-
const deadline = startedAt + 180_000;
|
|
38
|
-
while (true) {
|
|
30
|
+
try {
|
|
39
31
|
input.signal.throwIfAborted();
|
|
40
|
-
if (
|
|
41
|
-
|
|
32
|
+
if (taskId === undefined) {
|
|
33
|
+
const copied = input.operation === "copy"
|
|
34
|
+
? copiedEntryId(submission.result_ids)
|
|
35
|
+
: undefined;
|
|
36
|
+
return copied === undefined ? {} : { copied_entry_id: copied };
|
|
42
37
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (
|
|
38
|
+
dependencies.annotate({ task_id: taskId });
|
|
39
|
+
let delayMilliseconds = 1_000;
|
|
40
|
+
const deadline = startedAt + 180_000;
|
|
41
|
+
while (true) {
|
|
42
|
+
input.signal.throwIfAborted();
|
|
43
|
+
if (dependencies.now() >= deadline) {
|
|
44
|
+
throw new DamOperationUnconfirmedError(input.operation);
|
|
45
|
+
}
|
|
46
|
+
const task = await input.getTask(taskId, input.signal);
|
|
47
|
+
input.signal.throwIfAborted();
|
|
48
|
+
if (task === null)
|
|
49
|
+
throw new DamOperationUnconfirmedError(input.operation);
|
|
50
|
+
if (task.status === 2) {
|
|
51
|
+
if (task.fail_count !== null && task.fail_count > 0) {
|
|
52
|
+
throw new DamOperationFailedError(input.operation);
|
|
53
|
+
}
|
|
54
|
+
if (input.operation !== "copy" || input.inspectResult === undefined)
|
|
55
|
+
return {};
|
|
56
|
+
const result = await input.inspectResult(taskId, input.signal);
|
|
57
|
+
input.signal.throwIfAborted();
|
|
58
|
+
const copied = copiedEntryId(result.result_ids);
|
|
59
|
+
return copied === undefined ? {} : { copied_entry_id: copied };
|
|
60
|
+
}
|
|
61
|
+
if (task.status === 3)
|
|
49
62
|
throw new DamOperationFailedError(input.operation);
|
|
63
|
+
if (task.status !== 0 && task.status !== 1) {
|
|
64
|
+
throw new DamOperationUnconfirmedError(input.operation);
|
|
50
65
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
const remaining = deadline - dependencies.now();
|
|
67
|
+
if (remaining <= 0)
|
|
68
|
+
throw new DamOperationUnconfirmedError(input.operation);
|
|
69
|
+
await dependencies.sleep(Math.min(delayMilliseconds, remaining), input.signal);
|
|
54
70
|
input.signal.throwIfAborted();
|
|
55
|
-
|
|
56
|
-
return copied === undefined ? {} : { copied_entry_id: copied };
|
|
71
|
+
delayMilliseconds = Math.min(delayMilliseconds + 500, 3_000);
|
|
57
72
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
throw
|
|
62
|
-
}
|
|
63
|
-
const remaining = deadline - dependencies.now();
|
|
64
|
-
if (remaining <= 0)
|
|
65
|
-
throw new DamOperationUnconfirmedError(input.operation);
|
|
66
|
-
await dependencies.sleep(Math.min(delayMilliseconds, remaining), input.signal);
|
|
67
|
-
input.signal.throwIfAborted();
|
|
68
|
-
delayMilliseconds = Math.min(delayMilliseconds + 500, 3_000);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (error instanceof DamOperationFailedError)
|
|
76
|
+
throw error;
|
|
77
|
+
throw new DamOperationUnconfirmedError(input.operation, { ...input.context, phase: "verify", accepted: true, ...(taskId ? { task_id: taskId } : {}) }, error);
|
|
69
78
|
}
|
|
70
79
|
}
|
|
71
80
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { isInterruption } from "../../platform/interruption.js";
|
|
1
2
|
import { createHash } from "node:crypto";
|
|
2
3
|
import { createReadStream } from "node:fs";
|
|
3
4
|
import { setTimeout as delay } from "node:timers/promises";
|
|
4
5
|
import sharp from "sharp";
|
|
5
6
|
import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
6
7
|
import { projectDamAssetDetail } from "./asset-projection.js";
|
|
8
|
+
import { DamOperationUnconfirmedError } from "./operation-executor.js";
|
|
7
9
|
const imageFormats = new Set([
|
|
8
10
|
"png", "jpg", "jpeg", "gif", "svg", "webp", "jfif", "bmp", "tiff", "tif", "heic", "avif"
|
|
9
11
|
]);
|
|
@@ -58,7 +60,7 @@ async function hashes(filePath, signal) {
|
|
|
58
60
|
return { md5: md5.digest("hex"), sha1: sha1.digest("hex") };
|
|
59
61
|
}
|
|
60
62
|
catch (error) {
|
|
61
|
-
if (signal
|
|
63
|
+
if (isInterruption(error, signal))
|
|
62
64
|
throw signal.reason;
|
|
63
65
|
throw error;
|
|
64
66
|
}
|
|
@@ -77,7 +79,7 @@ async function defaultSleep(milliseconds, signal) {
|
|
|
77
79
|
await delay(milliseconds, undefined, { signal });
|
|
78
80
|
}
|
|
79
81
|
catch (error) {
|
|
80
|
-
if (signal
|
|
82
|
+
if (isInterruption(error, signal))
|
|
81
83
|
throw signal.reason;
|
|
82
84
|
throw error;
|
|
83
85
|
}
|
|
@@ -105,8 +107,8 @@ export function createDamRegisteredUploader(dependencies) {
|
|
|
105
107
|
: {})
|
|
106
108
|
};
|
|
107
109
|
}
|
|
108
|
-
catch {
|
|
109
|
-
if (signal
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (isInterruption(error, signal))
|
|
110
112
|
throw signal.reason;
|
|
111
113
|
return {};
|
|
112
114
|
}
|
|
@@ -119,11 +121,11 @@ export function createDamRegisteredUploader(dependencies) {
|
|
|
119
121
|
return await run();
|
|
120
122
|
}
|
|
121
123
|
catch (error) {
|
|
122
|
-
if (input.signal
|
|
124
|
+
if (isInterruption(error, input.signal))
|
|
123
125
|
throw input.signal.reason;
|
|
124
126
|
if (error instanceof RemoteRequestError)
|
|
125
127
|
throw error;
|
|
126
|
-
throw new RemoteRequestError();
|
|
128
|
+
throw new RemoteRequestError(undefined, false, {}, error);
|
|
127
129
|
}
|
|
128
130
|
}));
|
|
129
131
|
input.signal.throwIfAborted();
|
|
@@ -212,35 +214,43 @@ export function createDamRegisteredUploader(dependencies) {
|
|
|
212
214
|
if (input.input.waitAnalysis !== true || terminalAnalysisStatus(latest.analysis_status)) {
|
|
213
215
|
return latest;
|
|
214
216
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
217
|
+
try {
|
|
218
|
+
return await stage("wait", async () => {
|
|
219
|
+
const deadline = now().getTime() + 180_000;
|
|
220
|
+
while (true) {
|
|
221
|
+
input.signal.throwIfAborted();
|
|
222
|
+
const current = await dependencies.api.getBatchStatus({
|
|
223
|
+
assetId: latest.asset_id,
|
|
224
|
+
fallback: latest,
|
|
225
|
+
access: input.access,
|
|
226
|
+
signal: input.signal
|
|
227
|
+
});
|
|
228
|
+
if (current !== null)
|
|
229
|
+
latest = current;
|
|
230
|
+
if (terminalAnalysisStatus(latest.analysis_status))
|
|
231
|
+
return latest;
|
|
232
|
+
const remaining = deadline - now().getTime();
|
|
233
|
+
if (remaining <= 0) {
|
|
234
|
+
dependencies.warn(dependencies.analysisPendingMessage ?? "素材分析仍在处理中,已返回当前结果。");
|
|
235
|
+
return latest;
|
|
236
|
+
}
|
|
237
|
+
await sleep(Math.min(3000, remaining), input.signal);
|
|
233
238
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
throw new DamOperationUnconfirmedError("upload", { phase: "analysis", registered: true,
|
|
243
|
+
asset_id: latest.asset_id, repository_id: input.repository.id, folder_id: folderId }, error);
|
|
244
|
+
}
|
|
237
245
|
}
|
|
238
246
|
catch (error) {
|
|
239
|
-
if (
|
|
247
|
+
if (error instanceof DamOperationUnconfirmedError)
|
|
248
|
+
throw error;
|
|
249
|
+
if (isInterruption(error, input.signal))
|
|
240
250
|
throw input.signal.reason;
|
|
241
251
|
if (error instanceof RemoteRequestError)
|
|
242
252
|
throw error;
|
|
243
|
-
throw new RemoteRequestError();
|
|
253
|
+
throw new RemoteRequestError(undefined, false, {}, error);
|
|
244
254
|
}
|
|
245
255
|
}
|
|
246
256
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isInterruption } from "../../platform/interruption.js";
|
|
1
2
|
import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
2
3
|
import { inspectUploadFile } from "../../platform/safe-upload-file.js";
|
|
3
4
|
function isRecord(value) {
|
|
@@ -110,11 +111,11 @@ export function createDamStorageUploader(dependencies) {
|
|
|
110
111
|
url = publicAssetUrl(token);
|
|
111
112
|
}
|
|
112
113
|
catch (error) {
|
|
113
|
-
if (signal
|
|
114
|
+
if (isInterruption(error, signal))
|
|
114
115
|
throw signal.reason;
|
|
115
116
|
if (error instanceof RemoteRequestError)
|
|
116
117
|
throw error;
|
|
117
|
-
throw new RemoteRequestError();
|
|
118
|
+
throw new RemoteRequestError(undefined, false, {}, error);
|
|
118
119
|
}
|
|
119
120
|
try {
|
|
120
121
|
await dependencies.storage.upload({
|
|
@@ -130,11 +131,11 @@ export function createDamStorageUploader(dependencies) {
|
|
|
130
131
|
};
|
|
131
132
|
}
|
|
132
133
|
catch (error) {
|
|
133
|
-
if (signal
|
|
134
|
+
if (isInterruption(error, signal))
|
|
134
135
|
throw signal.reason;
|
|
135
136
|
if (error instanceof RemoteRequestError)
|
|
136
137
|
throw error;
|
|
137
|
-
throw new RemoteRequestError();
|
|
138
|
+
throw new RemoteRequestError(undefined, false, {}, error);
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
};
|
|
@@ -2,8 +2,12 @@ import { resolve } from "node:path";
|
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import { DamOperationUnconfirmedError } from "./operation-executor.js";
|
|
4
4
|
export class DamInputError extends Error {
|
|
5
|
-
|
|
5
|
+
reason;
|
|
6
|
+
field;
|
|
7
|
+
constructor(reason = "invalid_value", field) {
|
|
6
8
|
super("DAM 输入不可用。");
|
|
9
|
+
this.reason = reason;
|
|
10
|
+
this.field = field;
|
|
7
11
|
this.name = "DamInputError";
|
|
8
12
|
}
|
|
9
13
|
}
|
|
@@ -14,33 +18,33 @@ export class DamRepositoryNotFoundError extends Error {
|
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
export { DamOperationUnconfirmedError } from "./operation-executor.js";
|
|
17
|
-
function invalid() {
|
|
18
|
-
throw new DamInputError();
|
|
21
|
+
function invalid(reason, field) {
|
|
22
|
+
throw new DamInputError(reason, field);
|
|
19
23
|
}
|
|
20
24
|
function nonblank(value) {
|
|
21
25
|
return value !== undefined && value.trim() !== "";
|
|
22
26
|
}
|
|
23
27
|
function assertPageSize(value) {
|
|
24
28
|
if (value !== undefined && (!Number.isInteger(value) || value < 1 || value > 100))
|
|
25
|
-
invalid();
|
|
29
|
+
invalid("integer_1_to_100", "pageSize");
|
|
26
30
|
}
|
|
27
31
|
function assertPage(value) {
|
|
28
32
|
if (value !== undefined && (!Number.isInteger(value) || value < 1))
|
|
29
|
-
invalid();
|
|
33
|
+
invalid("positive_integer", "page");
|
|
30
34
|
}
|
|
31
|
-
function assertOptionalNonblank(value) {
|
|
35
|
+
function assertOptionalNonblank(value, field) {
|
|
32
36
|
if (value !== undefined && !nonblank(value))
|
|
33
|
-
invalid();
|
|
37
|
+
invalid("nonblank", field);
|
|
34
38
|
}
|
|
35
|
-
function assertAssetId(value) {
|
|
39
|
+
function assertAssetId(value, field = "asset_id") {
|
|
36
40
|
if (value.trim() === "" || /^https?:\/\//iu.test(value))
|
|
37
|
-
invalid();
|
|
41
|
+
invalid("id_required_not_url", field);
|
|
38
42
|
}
|
|
39
43
|
function assertRepositorySelection(input) {
|
|
40
44
|
if (input.repositoryId !== undefined && !nonblank(input.repositoryId))
|
|
41
|
-
invalid();
|
|
45
|
+
invalid("nonblank", "repositoryId");
|
|
42
46
|
if (input.repositoryId !== undefined && input.allRepositories === true)
|
|
43
|
-
invalid();
|
|
47
|
+
invalid("conflicts_with_all_repositories", "repositoryId");
|
|
44
48
|
}
|
|
45
49
|
function searchRequest(input, keyword, repositoryIds) {
|
|
46
50
|
return {
|
|
@@ -93,15 +97,15 @@ export function createDamUseCases(dependencies) {
|
|
|
93
97
|
return { repositoryId: detail.repository_id, folderId: detail.folder_id };
|
|
94
98
|
}
|
|
95
99
|
function assertEntryOperationInput(input) {
|
|
96
|
-
assertAssetId(input.entry_id);
|
|
100
|
+
assertAssetId(input.entry_id, "entry_id");
|
|
97
101
|
if (input.kind !== "asset" && input.kind !== "folder")
|
|
98
|
-
invalid();
|
|
102
|
+
invalid("asset_or_folder", "kind");
|
|
99
103
|
if (!nonblank(input.targetFolderId))
|
|
100
|
-
invalid();
|
|
101
|
-
assertOptionalNonblank(input.repositoryId);
|
|
102
|
-
assertOptionalNonblank(input.targetRepositoryId);
|
|
104
|
+
invalid("nonblank", "targetFolderId");
|
|
105
|
+
assertOptionalNonblank(input.repositoryId, "repositoryId");
|
|
106
|
+
assertOptionalNonblank(input.targetRepositoryId, "targetRepositoryId");
|
|
103
107
|
if (input.kind === "folder" && input.entry_id === input.targetFolderId)
|
|
104
|
-
invalid();
|
|
108
|
+
invalid("cannot_target_self", "targetFolderId");
|
|
105
109
|
}
|
|
106
110
|
async function entryOperation(input) {
|
|
107
111
|
assertEntryOperationInput(input.request);
|
|
@@ -124,9 +128,10 @@ export function createDamUseCases(dependencies) {
|
|
|
124
128
|
if (input.operation === "move"
|
|
125
129
|
&& current.repositoryId === targetRepositoryId
|
|
126
130
|
&& current.folderId === input.request.targetFolderId)
|
|
127
|
-
invalid();
|
|
131
|
+
invalid("already_in_target", "targetFolderId");
|
|
128
132
|
const execution = await dependencies.telemetry.stage("wait", () => (dependencies.operations.execute({
|
|
129
133
|
operation: input.operation,
|
|
134
|
+
context: { entry_id: input.request.entry_id, repository_id: targetRepositoryId, folder_id: input.request.targetFolderId },
|
|
130
135
|
submit: () => dependencies.telemetry.stage("submit", () => (dependencies.api.submitEntryOperation({
|
|
131
136
|
entryId: input.request.entry_id,
|
|
132
137
|
kind: input.request.kind,
|
|
@@ -208,7 +213,7 @@ export function createDamUseCases(dependencies) {
|
|
|
208
213
|
async search({ input, access, signal }) {
|
|
209
214
|
signal.throwIfAborted();
|
|
210
215
|
if (!nonblank(input.query))
|
|
211
|
-
invalid();
|
|
216
|
+
invalid("nonblank", "query");
|
|
212
217
|
assertPageSize(input.pageSize);
|
|
213
218
|
const repositories = await dependencies.telemetry.stage("repository", () => (resolveRepositories(input, access, signal)));
|
|
214
219
|
return dependencies.telemetry.stage("request", async () => {
|
|
@@ -224,8 +229,8 @@ export function createDamUseCases(dependencies) {
|
|
|
224
229
|
},
|
|
225
230
|
async folderList({ input, access, signal }) {
|
|
226
231
|
signal.throwIfAborted();
|
|
227
|
-
assertOptionalNonblank(input.parentId);
|
|
228
|
-
assertOptionalNonblank(input.query);
|
|
232
|
+
assertOptionalNonblank(input.parentId, "parentId");
|
|
233
|
+
assertOptionalNonblank(input.query, "query");
|
|
229
234
|
assertPage(input.page);
|
|
230
235
|
assertPageSize(input.pageSize);
|
|
231
236
|
const [repository] = await dependencies.telemetry.stage("repository", () => (resolveRepositories({
|
|
@@ -250,7 +255,7 @@ export function createDamUseCases(dependencies) {
|
|
|
250
255
|
},
|
|
251
256
|
async tagList({ input, access, signal }) {
|
|
252
257
|
signal.throwIfAborted();
|
|
253
|
-
assertOptionalNonblank(input.query);
|
|
258
|
+
assertOptionalNonblank(input.query, "query");
|
|
254
259
|
const [repository] = await dependencies.telemetry.stage("repository", () => (resolveRepositories({
|
|
255
260
|
...(input.repositoryId === undefined ? {} : { repositoryId: input.repositoryId })
|
|
256
261
|
}, access, signal)));
|
|
@@ -271,7 +276,7 @@ export function createDamUseCases(dependencies) {
|
|
|
271
276
|
async download({ input, access, signal }) {
|
|
272
277
|
signal.throwIfAborted();
|
|
273
278
|
assertAssetId(input.asset_id);
|
|
274
|
-
assertOptionalNonblank(input.outputDir);
|
|
279
|
+
assertOptionalNonblank(input.outputDir, "outputDir");
|
|
275
280
|
const [repository] = await dependencies.telemetry.stage("repository", () => (resolveRepositories({
|
|
276
281
|
...(input.repositoryId === undefined ? {} : { repositoryId: input.repositoryId })
|
|
277
282
|
}, access, signal)));
|
|
@@ -300,11 +305,11 @@ export function createDamUseCases(dependencies) {
|
|
|
300
305
|
},
|
|
301
306
|
async rename({ input, access, signal }) {
|
|
302
307
|
signal.throwIfAborted();
|
|
303
|
-
assertAssetId(input.entry_id);
|
|
308
|
+
assertAssetId(input.entry_id, "entry_id");
|
|
304
309
|
if (input.kind !== "asset" && input.kind !== "folder")
|
|
305
|
-
invalid();
|
|
310
|
+
invalid("asset_or_folder", "kind");
|
|
306
311
|
if (!nonblank(input.title) || input.title.length > 100)
|
|
307
|
-
invalid();
|
|
312
|
+
invalid("nonblank_max_100", "title");
|
|
308
313
|
const [repository] = await dependencies.telemetry.stage("repository", () => (resolveRepositories({
|
|
309
314
|
...(input.repositoryId === undefined ? {} : { repositoryId: input.repositoryId })
|
|
310
315
|
}, access, signal)));
|
|
@@ -339,16 +344,21 @@ export function createDamUseCases(dependencies) {
|
|
|
339
344
|
validate.rename(result);
|
|
340
345
|
return result;
|
|
341
346
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
347
|
+
try {
|
|
348
|
+
await dependencies.telemetry.stage("verify", async () => {
|
|
349
|
+
for (let attempt = 0; attempt <= 30; attempt += 1) {
|
|
350
|
+
signal.throwIfAborted();
|
|
351
|
+
if (await entryTitle(request) === input.title)
|
|
352
|
+
return;
|
|
353
|
+
if (attempt < 30)
|
|
354
|
+
await dependencies.sleep(2_000, signal);
|
|
355
|
+
}
|
|
356
|
+
throw new DamOperationUnconfirmedError("rename");
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
throw new DamOperationUnconfirmedError("rename", { phase: "verify", entry_id: input.entry_id, repository_id: repository.id, accepted: true }, error);
|
|
361
|
+
}
|
|
352
362
|
const result = {
|
|
353
363
|
entry_id: input.entry_id,
|
|
354
364
|
kind: input.kind,
|
|
@@ -361,24 +371,30 @@ export function createDamUseCases(dependencies) {
|
|
|
361
371
|
async move({ input, access, signal }) {
|
|
362
372
|
signal.throwIfAborted();
|
|
363
373
|
const operation = await entryOperation({ operation: "move", request: input, access, signal });
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
374
|
+
try {
|
|
375
|
+
await dependencies.telemetry.stage("verify", async () => {
|
|
376
|
+
for (let attempt = 0; attempt <= 30; attempt += 1) {
|
|
377
|
+
signal.throwIfAborted();
|
|
378
|
+
const location = await entryLocation({
|
|
379
|
+
entryId: input.entry_id,
|
|
380
|
+
kind: input.kind,
|
|
381
|
+
repositoryId: operation.targetRepositoryId,
|
|
382
|
+
access,
|
|
383
|
+
signal
|
|
384
|
+
});
|
|
385
|
+
if (location.repositoryId === operation.targetRepositoryId
|
|
386
|
+
&& location.folderId === operation.targetFolderId)
|
|
387
|
+
return;
|
|
388
|
+
if (attempt < 30)
|
|
389
|
+
await dependencies.sleep(2_000, signal);
|
|
390
|
+
}
|
|
391
|
+
throw new DamOperationUnconfirmedError("move");
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
throw new DamOperationUnconfirmedError("move", { phase: "verify", accepted: true,
|
|
396
|
+
entry_id: input.entry_id, repository_id: operation.targetRepositoryId, folder_id: operation.targetFolderId }, error);
|
|
397
|
+
}
|
|
382
398
|
const result = {
|
|
383
399
|
entry_id: input.entry_id,
|
|
384
400
|
kind: input.kind,
|
|
@@ -420,7 +436,7 @@ export function createDamUseCases(dependencies) {
|
|
|
420
436
|
async upload({ input, access, signal }) {
|
|
421
437
|
signal.throwIfAborted();
|
|
422
438
|
if (!nonblank(input.file))
|
|
423
|
-
invalid();
|
|
439
|
+
invalid("nonblank", "file");
|
|
424
440
|
const file = await dependencies.telemetry.stage("inspect", () => (dependencies.storage.inspect({
|
|
425
441
|
url: pathToFileURL(resolve(process.cwd(), input.file)).href,
|
|
426
442
|
...(input.allowSensitivePath === undefined
|
|
@@ -459,12 +475,17 @@ export function createDamUseCases(dependencies) {
|
|
|
459
475
|
signal
|
|
460
476
|
};
|
|
461
477
|
await dependencies.telemetry.stage("recycle", () => dependencies.api.recycle(request));
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
478
|
+
try {
|
|
479
|
+
signal.throwIfAborted();
|
|
480
|
+
if (input.permanent === true) {
|
|
481
|
+
await dependencies.telemetry.stage("delete", () => dependencies.api.deleteRecycled(request));
|
|
482
|
+
}
|
|
483
|
+
signal.throwIfAborted();
|
|
484
|
+
validate.delete(null);
|
|
485
|
+
}
|
|
486
|
+
catch (error) {
|
|
487
|
+
throw new DamOperationUnconfirmedError("delete", { phase: "delete", asset_id: input.asset_id, repository_id: repository.id, recycled: true }, error);
|
|
465
488
|
}
|
|
466
|
-
signal.throwIfAborted();
|
|
467
|
-
validate.delete(null);
|
|
468
489
|
}
|
|
469
490
|
};
|
|
470
491
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export class EditorBridgeError extends Error {
|
|
2
2
|
code;
|
|
3
|
-
constructor(code, message) {
|
|
4
|
-
super(message);
|
|
3
|
+
constructor(code, message, options) {
|
|
4
|
+
super(message, options);
|
|
5
5
|
this.name = "EditorBridgeError";
|
|
6
6
|
this.code = code;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
export class EditorBridgeUnavailableError extends Error {
|
|
10
|
-
constructor() {
|
|
11
|
-
super("Editor Bridge is unavailable.");
|
|
10
|
+
constructor(cause) {
|
|
11
|
+
super("Editor Bridge is unavailable.", { cause });
|
|
12
12
|
this.name = "EditorBridgeUnavailableError";
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -63,9 +63,9 @@ export function createEditorBridgeClient(options) {
|
|
|
63
63
|
...(body === undefined ? {} : { body: JSON.stringify(body) })
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
-
catch {
|
|
66
|
+
catch (error) {
|
|
67
67
|
signal.throwIfAborted();
|
|
68
|
-
throw new EditorBridgeUnavailableError();
|
|
68
|
+
throw new EditorBridgeUnavailableError(error);
|
|
69
69
|
}
|
|
70
70
|
let value;
|
|
71
71
|
try {
|
|
@@ -213,10 +213,11 @@ function hasExactKeys(value, keys) {
|
|
|
213
213
|
}
|
|
214
214
|
const ownPath = fileURLToPath(import.meta.url);
|
|
215
215
|
if (process.argv[1] && resolve(process.argv[1]) === resolve(ownPath)) {
|
|
216
|
+
const startedAt = Date.now();
|
|
216
217
|
const targetOrigin = process.argv[2];
|
|
217
218
|
const homeDirectory = process.argv[3] || undefined;
|
|
218
219
|
const stateDirectory = process.argv[4];
|
|
219
|
-
const reportError = (error) => reportProcessError(error, { operation: "editor.bridge", processRole: "editor_bridge",
|
|
220
|
+
const reportError = (error) => reportProcessError(error, { operation: "editor.bridge", processRole: "editor_bridge", startedAt,
|
|
220
221
|
...(stateDirectory ? { stateDirectory } : {}), ...(homeDirectory ? { homeDirectory } : {}) });
|
|
221
222
|
if (!targetOrigin) {
|
|
222
223
|
void reportError(new Error("Editor Bridge target missing."));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { createLocalJsonFile } from "../../platform/local-json-file.js";
|
|
3
|
+
import { createLocalJsonFile, LocalFileError } from "../../platform/local-json-file.js";
|
|
4
4
|
export function createEditorSessionStateStore(options = {}) {
|
|
5
5
|
const file = options.file ?? createLocalJsonFile({
|
|
6
6
|
directory: join(options.homeDirectory ?? homedir(), options.stateDirectory ?? ".gd"),
|
|
@@ -14,10 +14,12 @@ export function createEditorSessionStateStore(options = {}) {
|
|
|
14
14
|
try {
|
|
15
15
|
value = JSON.parse(text);
|
|
16
16
|
}
|
|
17
|
-
catch {
|
|
18
|
-
|
|
17
|
+
catch (cause) {
|
|
18
|
+
throw new LocalFileError(cause, "editor-session.json", "invalid_data");
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
if (!isEditorSessionState(value))
|
|
21
|
+
throw new LocalFileError(new Error("Invalid Editor session structure."), "editor-session.json", "invalid_data");
|
|
22
|
+
return value;
|
|
21
23
|
};
|
|
22
24
|
return {
|
|
23
25
|
read,
|