@insmind/cli 1.5.1 → 1.5.3
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/auth.status/output.schema.json +3 -4
- package/dist/bin/insmind-cli.js +12 -7
- package/dist/bin/postinstall.js +7 -5
- package/dist/bin/{agent-worker.js → task-worker.js} +5 -4
- package/dist/src/analytics/device.js +23 -0
- package/dist/src/analytics/wind.js +54 -0
- package/dist/src/bootstrap/create-cli.js +33 -19
- package/dist/src/bootstrap/create-runtime.js +45 -16
- package/dist/src/bootstrap/{run-agent-worker.js → run-task-worker.js} +20 -10
- package/dist/src/bootstrap/validators.js +10 -5
- package/dist/src/cli/action-binding.js +14 -0
- package/dist/src/cli/agent-commands.js +9 -4
- package/dist/src/cli/auth-commands.js +5 -3
- 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 +97 -44
- package/dist/src/cli/model-commands.js +6 -4
- package/dist/src/cli/presenter.js +13 -10
- package/dist/src/cli/task-commands.js +13 -5
- package/dist/src/cli/tool-commands.js +11 -5
- package/dist/src/features/agent/use-cases.js +11 -5
- package/dist/src/features/auth/access-policy.js +2 -0
- package/dist/src/features/auth/credential-store.js +2 -2
- package/dist/src/features/auth/sso-service.js +5 -4
- package/dist/src/features/auth/state.js +11 -1
- package/dist/src/features/auth/use-cases.js +43 -40
- 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/store.js +4 -0
- package/dist/src/features/task/{agent-background.js → task-background.js} +5 -4
- package/dist/src/features/task/use-cases.js +123 -28
- 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 +1 -0
- package/dist/src/features/tool/tool-api-adapter.js +8 -7
- package/dist/src/features/tool/use-cases.js +8 -4
- 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/dist/vendor/README.md +10 -0
- package/dist/vendor/gd-tracker-node.mjs +1175 -0
- package/package.json +4 -4
|
@@ -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,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isInterruption } from "../../platform/interruption.js";
|
|
2
|
+
import { createEditorBridgeClient, EditorBridgeError, EditorBridgeUnavailableError } from "./bridge-client.js";
|
|
2
3
|
import { startEditorBridgeProcess } from "./bridge-process.js";
|
|
3
4
|
import { toPublicEditorUrl } from "./public-url.js";
|
|
4
5
|
const DEFAULT_CREATE_URL = new URL("https://www.gaoding.art/editor/canvas?mode=create&type=board");
|
|
@@ -14,8 +15,8 @@ export class EditorTargetError extends Error {
|
|
|
14
15
|
}
|
|
15
16
|
export class EditorSessionNotFoundError extends Error {
|
|
16
17
|
code = "EDITOR_SESSION_NOT_FOUND";
|
|
17
|
-
constructor(commandName = "gd-cli") {
|
|
18
|
-
super(`当前没有可用的 Editor 会话,请重新执行 ${commandName} editor connect [target]
|
|
18
|
+
constructor(commandName = "gd-cli", cause) {
|
|
19
|
+
super(`当前没有可用的 Editor 会话,请重新执行 ${commandName} editor connect [target]。`, { cause });
|
|
19
20
|
this.name = "EditorSessionNotFoundError";
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -49,11 +50,19 @@ export function createEditorSession(dependencies) {
|
|
|
49
50
|
? {}
|
|
50
51
|
: { stateDirectory: dependencies.stateDirectory }),
|
|
51
52
|
signal
|
|
53
|
+
}).catch(cause => {
|
|
54
|
+
if (isInterruption(cause, signal))
|
|
55
|
+
throw signal.reason;
|
|
56
|
+
throw new EditorBridgeError("EDITOR_NOT_READY", dependencies.commandName === "insmind-cli" ? "Cannot start the local Editor Bridge." : "无法启动本地 Editor Bridge,请检查本地进程环境后重新连接。", { cause });
|
|
52
57
|
});
|
|
53
58
|
const handoffUrl = buildHandoffUrl(targetUrl, state);
|
|
54
59
|
try {
|
|
55
60
|
signal.throwIfAborted();
|
|
56
|
-
await dependencies.browser.open(handoffUrl)
|
|
61
|
+
await dependencies.browser.open(handoffUrl).catch(cause => {
|
|
62
|
+
if (isInterruption(cause, signal))
|
|
63
|
+
throw signal.reason;
|
|
64
|
+
throw new EditorBridgeError("EDITOR_NOT_READY", dependencies.commandName === "insmind-cli" ? "Cannot open the Editor browser. Check the local browser configuration and reconnect." : "无法打开 Editor 浏览器,请检查浏览器配置后重新连接。", { cause });
|
|
65
|
+
});
|
|
57
66
|
const client = createClient(state);
|
|
58
67
|
await waitForPage(client, signal);
|
|
59
68
|
await client.rpc("preflight", undefined, signal);
|
|
@@ -74,10 +83,18 @@ export function createEditorSession(dependencies) {
|
|
|
74
83
|
await client.health(signal);
|
|
75
84
|
}
|
|
76
85
|
catch (cause) {
|
|
77
|
-
signal
|
|
86
|
+
if (isInterruption(cause, signal))
|
|
87
|
+
throw signal.reason;
|
|
88
|
+
await throwUnavailableSession(cause, state);
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
await client.disconnect(signal);
|
|
92
|
+
}
|
|
93
|
+
catch (cause) {
|
|
94
|
+
if (isInterruption(cause, signal))
|
|
95
|
+
throw signal.reason;
|
|
78
96
|
await throwUnavailableSession(cause, state);
|
|
79
97
|
}
|
|
80
|
-
await client.disconnect(signal);
|
|
81
98
|
await dependencies.store.removeIfOwned(state.token);
|
|
82
99
|
return { disconnected: true };
|
|
83
100
|
},
|
|
@@ -90,7 +107,8 @@ export function createEditorSession(dependencies) {
|
|
|
90
107
|
return await createClient(state).rpc(method, payload, signal);
|
|
91
108
|
}
|
|
92
109
|
catch (cause) {
|
|
93
|
-
signal
|
|
110
|
+
if (isInterruption(cause, signal))
|
|
111
|
+
throw signal.reason;
|
|
94
112
|
await throwUnavailableSession(cause, state);
|
|
95
113
|
}
|
|
96
114
|
}
|
|
@@ -99,7 +117,7 @@ export function createEditorSession(dependencies) {
|
|
|
99
117
|
if (!(cause instanceof EditorBridgeUnavailableError))
|
|
100
118
|
throw cause;
|
|
101
119
|
await dependencies.store.removeIfOwned(state.token);
|
|
102
|
-
throw new EditorSessionNotFoundError(dependencies.commandName);
|
|
120
|
+
throw new EditorSessionNotFoundError(dependencies.commandName, cause);
|
|
103
121
|
}
|
|
104
122
|
async function replaceCurrentSession(signal) {
|
|
105
123
|
const current = await dependencies.store.read();
|
|
@@ -2,6 +2,7 @@ import { mkdtemp, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { OutputContractError } from "../../bootstrap/validators.js";
|
|
5
|
+
import { LocalFileError } from "../../platform/local-json-file.js";
|
|
5
6
|
import { toPublicEditorUrl } from "./public-url.js";
|
|
6
7
|
const PNG_DATA_URL_PREFIX = "data:image/png;base64,";
|
|
7
8
|
const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
@@ -35,9 +36,15 @@ export function createEditorUseCases(dependencies) {
|
|
|
35
36
|
const data = await dependencies.session.rpc("screenshot", undefined, signal);
|
|
36
37
|
const bytes = decodePngDataUrl(data);
|
|
37
38
|
signal.throwIfAborted();
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
let result;
|
|
40
|
+
try {
|
|
41
|
+
const directory = await mkdtemp(join(temporaryDirectory, "gd-cli-editor-"));
|
|
42
|
+
result = { path: join(directory, "screenshot.png") };
|
|
43
|
+
await writeFile(result.path, bytes);
|
|
44
|
+
}
|
|
45
|
+
catch (cause) {
|
|
46
|
+
throw new LocalFileError(cause, "Editor screenshot");
|
|
47
|
+
}
|
|
41
48
|
validate.screenshot(result);
|
|
42
49
|
return result;
|
|
43
50
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isInterruption } from "../../platform/interruption.js";
|
|
1
2
|
import { remoteErrorEvidence } from "../../platform/remote-error-evidence.js";
|
|
2
3
|
import { classifyBindOutcome, SsoRequestError } from "../auth/sso-service.js";
|
|
3
4
|
import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
@@ -122,7 +123,7 @@ export function createOrgUseCases(dependencies) {
|
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
125
|
catch (error) {
|
|
125
|
-
if (input.signal
|
|
126
|
+
if (isInterruption(error, input.signal))
|
|
126
127
|
throw input.signal.reason;
|
|
127
128
|
if (isExpectedAuthorizationFailure(error))
|
|
128
129
|
return null;
|
|
@@ -5,6 +5,8 @@ import { homedir } from "node:os";
|
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { createLocalJsonFile, LocalFileError } from "../../platform/local-json-file.js";
|
|
7
7
|
export class TaskStoreError extends LocalFileError {
|
|
8
|
+
context;
|
|
9
|
+
constructor(cause) { super(cause); this.name = "TaskStoreError"; }
|
|
8
10
|
}
|
|
9
11
|
export const validTaskId = (id) => /^[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}$/iu.test(id);
|
|
10
12
|
export function taskScope(state) {
|
|
@@ -68,6 +70,8 @@ export function createTaskStore(options) {
|
|
|
68
70
|
}
|
|
69
71
|
if (previous.task.state === "completed" || (previous.task.state === "failed" && record.task.state !== "completed"))
|
|
70
72
|
record.task = previous.task;
|
|
73
|
+
if (previous.analytics)
|
|
74
|
+
record.analytics = { ...record.analytics, ...previous.analytics };
|
|
71
75
|
if (previous.telemetry)
|
|
72
76
|
record.telemetry = {
|
|
73
77
|
...record.telemetry, ...previous.telemetry,
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { fork } from "node:child_process";
|
|
2
|
-
export class
|
|
2
|
+
export class TaskBackgroundError extends Error {
|
|
3
3
|
failure;
|
|
4
4
|
exitCode;
|
|
5
5
|
constructor(failure, exitCode = 1) {
|
|
6
6
|
super(failure.message);
|
|
7
7
|
this.failure = failure;
|
|
8
8
|
this.exitCode = exitCode;
|
|
9
|
+
this.name = "TaskBackgroundError";
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
|
-
export function
|
|
12
|
+
export function createTaskBackgroundLauncher(options) {
|
|
12
13
|
return {
|
|
13
14
|
submit(job, signal, started) {
|
|
14
15
|
signal.throwIfAborted();
|
|
@@ -35,7 +36,7 @@ export function createAgentBackgroundLauncher(options) {
|
|
|
35
36
|
else
|
|
36
37
|
resolve(result);
|
|
37
38
|
};
|
|
38
|
-
const unavailable = () => finish(new
|
|
39
|
+
const unavailable = () => finish(new TaskBackgroundError({
|
|
39
40
|
code: "TASK_WORKER_UNAVAILABLE",
|
|
40
41
|
message: job.product === "insmind"
|
|
41
42
|
? "The background process did not return a receipt. Check task list/get before submitting again."
|
|
@@ -52,7 +53,7 @@ export function createAgentBackgroundLauncher(options) {
|
|
|
52
53
|
else if (message.type === "accepted")
|
|
53
54
|
finish(message.task);
|
|
54
55
|
else if (message.type === "error")
|
|
55
|
-
finish(new
|
|
56
|
+
finish(new TaskBackgroundError(message.failure, message.exitCode));
|
|
56
57
|
});
|
|
57
58
|
signal.addEventListener("abort", aborted, { once: true });
|
|
58
59
|
child.send(job, error => { if (error)
|