@insmind/cli 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/insmind-cli.js +32 -25
- package/dist/bin/task-worker.js +4 -1
- package/dist/src/analytics/device.js +2 -2
- package/dist/src/bootstrap/create-cli.js +10 -8
- package/dist/src/bootstrap/create-runtime.js +29 -23
- package/dist/src/bootstrap/run-task-worker.js +7 -2
- package/dist/src/bootstrap/validators.js +15 -6
- package/dist/src/cli/action-binding.js +39 -0
- package/dist/src/cli/agent-commands.js +8 -12
- package/dist/src/cli/dam-commands.js +6 -5
- package/dist/src/cli/editor-commands.js +10 -5
- package/dist/src/cli/errors.js +60 -12
- package/dist/src/cli/host-input.js +34 -0
- package/dist/src/cli/model-commands.js +4 -3
- package/dist/src/cli/observed-errors.js +3 -1
- package/dist/src/cli/tool-commands.js +7 -9
- package/dist/src/contracts/creation-input.js +20 -0
- package/dist/src/features/agent/creative-agent-adapter.js +37 -11
- package/dist/src/features/agent/creative-protocol.js +21 -19
- package/dist/src/features/agent/creative-stream.js +54 -6
- package/dist/src/features/agent/result-reader.js +3 -1
- package/dist/src/features/agent/use-cases.js +6 -31
- package/dist/src/features/auth/access-policy.js +1 -3
- package/dist/src/features/auth/credential-store.js +6 -10
- package/dist/src/features/auth/sso-service.js +28 -10
- package/dist/src/features/auth/state.js +6 -0
- package/dist/src/features/auth/use-cases.js +91 -32
- package/dist/src/features/credits/use-cases.js +1 -1
- package/dist/src/features/dam/asset-projection.js +10 -1
- package/dist/src/features/dam/dam-api-adapter.js +30 -15
- package/dist/src/features/dam/file-downloader.js +2 -1
- package/dist/src/features/dam/input.js +23 -0
- package/dist/src/features/dam/use-cases.js +39 -29
- package/dist/src/features/editor/bridge-client.js +1 -1
- package/dist/src/features/editor/use-cases.js +6 -8
- package/dist/src/features/org/use-cases.js +3 -3
- package/dist/src/features/skill/installer.js +24 -22
- package/dist/src/features/task/store.js +31 -17
- package/dist/src/features/task/task-background.js +67 -19
- package/dist/src/features/task/use-cases.js +131 -88
- package/dist/src/features/tool/canvas-media.js +82 -27
- package/dist/src/features/tool/canvas-models.js +21 -4
- package/dist/src/features/tool/canvas-tool-adapter.js +29 -20
- package/dist/src/features/tool/canvas-video.js +2 -4
- package/dist/src/features/tool/dynamic-schema.js +32 -63
- package/dist/src/features/tool/matting-billing.js +38 -26
- package/dist/src/features/tool/mns-catalog-adapter.js +9 -2
- package/dist/src/features/tool/scene-catalog-adapter.js +0 -1
- package/dist/src/features/tool/tool-api-adapter.js +19 -16
- package/dist/src/features/tool/use-cases.js +24 -35
- package/dist/src/platform/file-lock.js +58 -15
- package/dist/src/platform/input-uri.js +105 -0
- package/dist/src/platform/json-input.js +1 -1
- package/dist/src/platform/local-json-file.js +7 -4
- package/dist/src/platform/remote-error-evidence.js +23 -1
- package/dist/src/platform/safe-upload-file.js +24 -4
- package/dist/src/platform/schema-issues.js +18 -0
- package/dist/src/platform/signed-http-transport.js +95 -37
- package/dist/src/platform/text-output.js +55 -13
- package/dist/src/telemetry/failure-summary.js +53 -2
- package/dist/src/telemetry/host-diagnostics.js +95 -0
- package/dist/src/telemetry/invocation.js +107 -23
- package/dist/src/telemetry/process-errors.js +38 -4
- package/dist/src/telemetry/sls-sink.js +71 -26
- package/package.json +4 -4
- package/skills/insmind-cli/SKILL.md +1 -0
- package/skills/insmind-cli/references/editor.md +1 -1
- package/skills/insmind-cli/references/generation-constraints.md +3 -1
- package/skills/insmind-cli/references/tool.md +2 -3
package/dist/bin/insmind-cli.js
CHANGED
|
@@ -15,36 +15,43 @@ let runtime;
|
|
|
15
15
|
let mapCliError;
|
|
16
16
|
let redact;
|
|
17
17
|
try {
|
|
18
|
-
|
|
19
|
-
import("../src/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
18
|
+
if (process.env.CLI_INTERNAL_HOST_DIAGNOSTIC === "1" && process.argv.length === 3 && process.argv[2] === "--version") {
|
|
19
|
+
await import("../src/telemetry/host-diagnostics.js")
|
|
20
|
+
.then(({ runHostDiagnosticReporter }) => runHostDiagnosticReporter({ product: insmindProduct }))
|
|
21
|
+
.catch(() => undefined);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const [cliModule, runtimeModule, errorsModule, redactModule] = await Promise.all([
|
|
25
|
+
import("../src/bootstrap/create-cli.js"),
|
|
26
|
+
import("../src/bootstrap/create-runtime.js"),
|
|
27
|
+
import("../src/cli/errors.js"),
|
|
28
|
+
import("../src/platform/redact.js")
|
|
29
|
+
]);
|
|
30
|
+
mapCliError = errorsModule.mapCliError;
|
|
31
|
+
redact = redactModule.redact;
|
|
32
|
+
const selectedLocale = localeOption(process.argv.slice(2));
|
|
33
|
+
runtime = runtimeModule.createProductionRuntime({
|
|
34
|
+
product: insmindProduct, invocationStartedAt: startedAt, invocationTraceId: bootstrapTraceId,
|
|
35
|
+
...(selectedLocale === undefined ? {} : { locale: selectedLocale })
|
|
36
|
+
});
|
|
37
|
+
const program = cliModule.createCli(runtime, { signal: controller.signal });
|
|
38
|
+
process.exitCode = await cliModule.executeCli({
|
|
39
|
+
program,
|
|
40
|
+
argv: process.argv.slice(2),
|
|
41
|
+
presenter: runtime.presenter,
|
|
42
|
+
signal: controller.signal,
|
|
43
|
+
telemetry: runtime.telemetry,
|
|
44
|
+
telemetrySink: runtime.telemetrySink,
|
|
45
|
+
updateNotification: runtime.updateNotification,
|
|
46
|
+
product: runtime.product
|
|
47
|
+
});
|
|
48
|
+
}
|
|
42
49
|
}
|
|
43
50
|
catch (error) {
|
|
44
51
|
const traceId = runtime?.telemetry.traceId ?? bootstrapTraceId;
|
|
45
52
|
try {
|
|
46
53
|
const { reportProcessError } = await import("../src/telemetry/process-errors.js");
|
|
47
|
-
await reportProcessError(error, { operation: "bootstrap", startedAt, traceId, signal: controller.signal, stateDirectory: ".insmind" });
|
|
54
|
+
await reportProcessError(error, { operation: "bootstrap", argv: process.argv.slice(2), startedAt, traceId, signal: controller.signal, stateDirectory: ".insmind" });
|
|
48
55
|
}
|
|
49
56
|
catch { /* Retain startup error output even if diagnostic modules cannot load. */ }
|
|
50
57
|
if (mapCliError === undefined || redact === undefined) {
|
package/dist/bin/task-worker.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { reportProcessError } from "../src/telemetry/process-errors.js";
|
|
3
3
|
import { once } from "node:events";
|
|
4
4
|
import { Readable } from "node:stream";
|
|
5
|
+
import { taskWorkerUnavailableError } from "../src/features/task/task-background.js";
|
|
5
6
|
import { gaodingProduct, insmindProduct } from "../src/product/config.js";
|
|
6
7
|
import { createProductionRuntime } from "../src/bootstrap/create-runtime.js";
|
|
7
8
|
import { runTaskWorker } from "../src/bootstrap/run-task-worker.js";
|
|
@@ -42,7 +43,9 @@ else {
|
|
|
42
43
|
...(currentJob?.telemetryTrackingUrl ? { trackingUrl: new URL(currentJob.telemetryTrackingUrl) } : {}),
|
|
43
44
|
...(currentJob?.telemetryEnvironment ? { environment: currentJob.telemetryEnvironment } : {}),
|
|
44
45
|
...(currentJob?.homeDirectory ? { homeDirectory: currentJob.homeDirectory } : {}) });
|
|
45
|
-
|
|
46
|
+
const unavailable = taskWorkerUnavailableError({ product: currentJob?.product === "insmind" ? "insmind" : "gaoding",
|
|
47
|
+
phase: "bootstrap", cause: error, pid: process.pid });
|
|
48
|
+
send({ type: "error", failure: unavailable.failure, ...(unavailable.diagnostics ? { diagnostics: unavailable.diagnostics } : {}), exitCode: 1 });
|
|
46
49
|
process.exitCode = 1;
|
|
47
50
|
}
|
|
48
51
|
finally {
|
|
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { withFileLock } from "../platform/file-lock.js";
|
|
4
4
|
import { createLocalJsonFile } from "../platform/local-json-file.js";
|
|
5
5
|
export async function loadAnalyticsDevice(directory, now) {
|
|
6
|
-
const file = createLocalJsonFile({ directory, filename: "analytics-device.json" });
|
|
6
|
+
const file = createLocalJsonFile({ directory, filename: "analytics-device.json", role: "analytics_device" });
|
|
7
7
|
async function read() {
|
|
8
8
|
const text = await file.readText();
|
|
9
9
|
if (text !== null) {
|
|
@@ -26,7 +26,7 @@ export async function loadAnalyticsDevice(directory, now) {
|
|
|
26
26
|
const device = { id: randomUUID(), createdAt: now() };
|
|
27
27
|
await file.writeTextAtomically(`${JSON.stringify(device)}\n`);
|
|
28
28
|
return device;
|
|
29
|
-
});
|
|
29
|
+
}, { action: "analytics_device" });
|
|
30
30
|
}
|
|
31
31
|
export function isFirstDay(createdAt, now) {
|
|
32
32
|
return new Date(createdAt).setHours(23, 59, 59, 999) >= now ? 1 : 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isInterruption } from "../platform/interruption.js";
|
|
2
2
|
import { registerTaskCommands } from "../cli/task-commands.js";
|
|
3
3
|
import { Command, CommanderError } from "commander";
|
|
4
|
-
import { assertAllLeafCommandsBound, errorUsesJson, configureActionEnvironment } from "../cli/action-binding.js";
|
|
4
|
+
import { assertAllLeafCommandsBound, errorUsesJson, invocationDefinition, configureActionEnvironment } from "../cli/action-binding.js";
|
|
5
5
|
import { registerAgentCommands } from "../cli/agent-commands.js";
|
|
6
6
|
import { registerAuthCommands } from "../cli/auth-commands.js";
|
|
7
7
|
import { classifyTelemetryError, isHelpOutcome, mapCliError } from "../cli/errors.js";
|
|
@@ -65,7 +65,7 @@ export function createCli(runtime, options) {
|
|
|
65
65
|
return program;
|
|
66
66
|
}
|
|
67
67
|
export async function executeCli(options) {
|
|
68
|
-
|
|
68
|
+
await options.telemetry.issue(invocationDefinition(options.program, options.argv));
|
|
69
69
|
try {
|
|
70
70
|
try {
|
|
71
71
|
await options.program.parseAsync(options.argv, { from: "user" });
|
|
@@ -73,15 +73,13 @@ export async function executeCli(options) {
|
|
|
73
73
|
catch (error) {
|
|
74
74
|
if (!isHelpOutcome(error))
|
|
75
75
|
throw error;
|
|
76
|
-
helpOnly = true;
|
|
77
76
|
if (options.argv[0] !== "update")
|
|
78
77
|
await checkUpdateNotification(options.updateNotification, options.signal);
|
|
79
78
|
options.signal.throwIfAborted();
|
|
80
79
|
}
|
|
81
80
|
await options.telemetry.stage("output", async () => { await outputs.get(options.program)?.io.flush?.(); });
|
|
82
81
|
await outputs.get(options.program)?.tasks.outputCompleted();
|
|
83
|
-
|
|
84
|
-
await sendFinished(options, { outcome: "success" });
|
|
82
|
+
await sendFinished(options, { outcome: "success" });
|
|
85
83
|
return 0;
|
|
86
84
|
}
|
|
87
85
|
catch (error) {
|
|
@@ -117,16 +115,20 @@ export async function executeCli(options) {
|
|
|
117
115
|
const traceId = options.telemetry.selected
|
|
118
116
|
? options.telemetry.traceId
|
|
119
117
|
: undefined;
|
|
118
|
+
let errorDelivered = false;
|
|
120
119
|
try {
|
|
121
120
|
options.presenter.error(outcome, {
|
|
122
121
|
json: errorUsesJson(options.program, options.argv),
|
|
123
122
|
...(traceId ? { traceId } : {})
|
|
124
123
|
});
|
|
124
|
+
await outputs.get(options.program)?.io.flush?.();
|
|
125
|
+
errorDelivered = true;
|
|
125
126
|
}
|
|
126
127
|
catch (presenterError) {
|
|
127
128
|
await options.telemetry.stage("output", () => { throw presenterError; }).catch(() => undefined);
|
|
128
129
|
}
|
|
129
|
-
|
|
130
|
+
if (errorDelivered)
|
|
131
|
+
await outputs.get(options.program)?.tasks.outputCompleted(error);
|
|
130
132
|
await sendFinished(options, outcome.kind === "interrupted"
|
|
131
133
|
? { outcome: "interrupted", error }
|
|
132
134
|
: {
|
|
@@ -157,8 +159,8 @@ async function checkUpdateNotification(updateNotification, signal) {
|
|
|
157
159
|
}
|
|
158
160
|
async function sendFinished(options, completion) {
|
|
159
161
|
await analyticsShutdown.get(options.program)?.().catch(() => undefined);
|
|
162
|
+
await options.telemetrySink.refreshDiagnostics?.().catch(() => undefined);
|
|
160
163
|
options.telemetry.annotate(options.telemetrySink.diagnostics?.() ?? {});
|
|
161
164
|
const events = options.telemetry.finish(completion);
|
|
162
|
-
|
|
163
|
-
await options.telemetrySink.send(events).catch(() => undefined);
|
|
165
|
+
await options.telemetrySink.send(events).catch(() => undefined);
|
|
164
166
|
}
|
|
@@ -3,7 +3,7 @@ import { taskScope } from "../features/task/store.js";
|
|
|
3
3
|
import { createTextOutput } from "../platform/text-output.js";
|
|
4
4
|
import { TaskNotFoundError } from "../features/task/use-cases.js";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
|
-
import { createTaskBackgroundLauncher } from "../features/task/task-background.js";
|
|
6
|
+
import { createTaskBackgroundLauncher, TaskBackgroundError } from "../features/task/task-background.js";
|
|
7
7
|
import { createTaskStore } from "../features/task/store.js";
|
|
8
8
|
import { createTaskUseCases } from "../features/task/use-cases.js";
|
|
9
9
|
import { readAgentResult } from "../features/agent/result-reader.js";
|
|
@@ -54,7 +54,7 @@ import { loadBundledSkills } from "../features/skill/bundled-skills.js";
|
|
|
54
54
|
import { createUpdateService } from "../features/update/update-service.js";
|
|
55
55
|
import { createUpdateNotificationService } from "../features/update/update-notification.js";
|
|
56
56
|
import { classifyTelemetryError, mapCliError } from "../cli/errors.js";
|
|
57
|
-
import { createTelemetryInvocation } from "../telemetry/invocation.js";
|
|
57
|
+
import { createTelemetryInvocation, hostTelemetryContext } from "../telemetry/invocation.js";
|
|
58
58
|
import { createSlsTelemetrySink } from "../telemetry/sls-sink.js";
|
|
59
59
|
import { gaodingProduct } from "../product/config.js";
|
|
60
60
|
import { resolveProductLocale, systemLocale } from "../product/locale.js";
|
|
@@ -93,25 +93,21 @@ export function createProductionRuntime(options = {}) {
|
|
|
93
93
|
const telemetrySink = options.telemetrySink ?? createSlsTelemetrySink({
|
|
94
94
|
fetch, trackingUrl: options.telemetryTrackingUrl ?? product.telemetryUrl,
|
|
95
95
|
background: options.telemetryBackground ?? true,
|
|
96
|
-
directory: join(options.homeDirectory ?? homedir(), product.stateDirectory, "telemetry"),
|
|
96
|
+
directory: join(options.homeDirectory ?? homedir(), product.stateDirectory, "telemetry", "v6"),
|
|
97
97
|
now: () => now().getTime()
|
|
98
98
|
});
|
|
99
99
|
const telemetry = createTelemetryInvocation({
|
|
100
|
-
|
|
100
|
+
...(options.invocationStartedAt === undefined ? {} : { startedAt: options.invocationStartedAt }),
|
|
101
|
+
cliVersion: options.telemetryVersion ?? primarySkill.version, cliName: product.commandName, env: telemetryEnvironment,
|
|
101
102
|
processRole: options.processRole ?? "cli",
|
|
102
103
|
now: () => now().getTime(),
|
|
103
|
-
traceIdFactory: () => randomBytes(16).toString("hex"),
|
|
104
|
+
traceIdFactory: () => options.invocationTraceId ?? randomBytes(16).toString("hex"),
|
|
104
105
|
spanIdFactory: () => randomBytes(8).toString("hex"),
|
|
105
106
|
runtime: { os: process.platform, arch: process.arch, nodeMajor: Number.parseInt(process.versions.node, 10) },
|
|
106
107
|
classifyError: error => classifyTelemetryError(error, { product, operation: telemetry.creationContext().operation, failureStage: telemetry.failureStage(error) }),
|
|
107
108
|
...(telemetrySink.enqueue ? { onEvent: (event) => telemetrySink.enqueue([event]) } : {})
|
|
108
109
|
});
|
|
109
|
-
telemetry.annotate({ installation_owner: installationOwner,
|
|
110
|
-
...(["workbuddy", "qwenwork"].includes(env.CLI_HOST_APPLICATION ?? "")
|
|
111
|
-
? { host_application: env.CLI_HOST_APPLICATION } : {}),
|
|
112
|
-
...(["auth_status", "version_check"].includes(env.CLI_INVOCATION_PURPOSE ?? "")
|
|
113
|
-
? { invocation_purpose: env.CLI_INVOCATION_PURPOSE } : {}),
|
|
114
|
-
...(/^[a-f0-9]{32}$/u.test(env.CLI_HOST_INVOCATION_ID ?? "") ? { host_invocation_id: env.CLI_HOST_INVOCATION_ID } : {}) });
|
|
110
|
+
telemetry.annotate({ installation_owner: installationOwner, ...hostTelemetryContext(env) });
|
|
115
111
|
// Explicit test transport enables SDK tests; test-mode child processes never emit real analytics.
|
|
116
112
|
const analytics = options.analytics ?? (telemetryEnvironment === "production" || options.windFetch
|
|
117
113
|
? createWindAnalytics({ product: product.id, version: options.telemetryVersion ?? primarySkill.version,
|
|
@@ -337,6 +333,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
337
333
|
store: createTaskStore({
|
|
338
334
|
...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {}),
|
|
339
335
|
stateDirectory: product.stateDirectory,
|
|
336
|
+
validateSummary: task => validators.taskListResult({ tasks: [task] }),
|
|
340
337
|
validate: validators.taskResult
|
|
341
338
|
}),
|
|
342
339
|
idFactory: randomUUID,
|
|
@@ -362,6 +359,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
362
359
|
credential: state.credential, organizationId: state.organization.id, signal
|
|
363
360
|
});
|
|
364
361
|
return { state: "unknown",
|
|
362
|
+
...(snapshot.usageModelMissing ? { usageModelMissing: true } : {}),
|
|
365
363
|
note: snapshot.partialResult
|
|
366
364
|
? text("已找到部分内容,尚未取得完整结果。", "Some content was found, but the complete result has not been received.")
|
|
367
365
|
: text("尚未取得任务结果。", "The task result has not been received."),
|
|
@@ -431,7 +429,6 @@ export function createProductionRuntime(options = {}) {
|
|
|
431
429
|
}
|
|
432
430
|
});
|
|
433
431
|
const agent = withAgentBillingUnit(createAgentUseCases({
|
|
434
|
-
catalog: modelCatalog,
|
|
435
432
|
uploader: transientUploader,
|
|
436
433
|
completion: createCreativeAgentAdapter({
|
|
437
434
|
transport: agentTransport,
|
|
@@ -439,7 +436,6 @@ export function createProductionRuntime(options = {}) {
|
|
|
439
436
|
idFactory: randomUUID,
|
|
440
437
|
telemetry
|
|
441
438
|
}),
|
|
442
|
-
warn: (message) => { presenter.warning(message); },
|
|
443
439
|
telemetry
|
|
444
440
|
}), product.billingUnit);
|
|
445
441
|
const canvasMedia = createCanvasMedia({ fetch, uploader: transientUploader });
|
|
@@ -526,16 +522,26 @@ export function createProductionRuntime(options = {}) {
|
|
|
526
522
|
org,
|
|
527
523
|
agent,
|
|
528
524
|
tasks,
|
|
529
|
-
startBackgroundTask
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
525
|
+
async startBackgroundTask(input, signal) {
|
|
526
|
+
let startedId;
|
|
527
|
+
const launcher = options.taskBackground ?? createTaskBackgroundLauncher({ workerPath: join(packageRoot, "dist", "bin", "task-worker.js"), env });
|
|
528
|
+
try {
|
|
529
|
+
return await launcher.submit({ ...input, product: product.id, homeDirectory: options.homeDirectory ?? homedir(),
|
|
530
|
+
telemetryEnvironment, telemetryVersion: options.telemetryVersion ?? primarySkill.version, origin: telemetry.creationContext(),
|
|
531
|
+
telemetryTrackingUrl: String(options.telemetryTrackingUrl ?? product.telemetryUrl),
|
|
532
|
+
locale: locale.locale, endpoints: Object.fromEntries(Object.entries(endpoints).map(([key, value]) => [key, String(value)]))
|
|
533
|
+
}, signal, task => {
|
|
534
|
+
startedId = task.taskId;
|
|
535
|
+
telemetry.annotate({ cli_task_id: task.taskId, execution_mode: "async", result_state: task.state });
|
|
536
|
+
presenter.notice(text(`任务 ID: ${task.taskId};结果未收到时执行 ${product.commandName} task get ${task.taskId}`, `Task ID: ${task.taskId}; retrieve missing output with ${product.commandName} task get ${task.taskId}`));
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
catch (error) {
|
|
540
|
+
if (startedId)
|
|
541
|
+
await tasks.workerStopped(input.state, startedId, error, error instanceof TaskBackgroundError).catch(() => undefined);
|
|
542
|
+
throw error;
|
|
543
|
+
}
|
|
544
|
+
},
|
|
539
545
|
editor,
|
|
540
546
|
dam,
|
|
541
547
|
tool,
|
|
@@ -8,7 +8,7 @@ export async function runTaskWorker(options) {
|
|
|
8
8
|
const { job, signal, send } = options;
|
|
9
9
|
runtime.telemetry.useSignal(signal);
|
|
10
10
|
runtime.telemetry.select({ operation: job.operation, mode: () => "execute" });
|
|
11
|
-
runtime.telemetry.annotate({ account_id: job.state.account?.id, organization_id: job.state.organization.id,
|
|
11
|
+
runtime.telemetry.annotate({ ...(job.origin ? { creation_trace_id: job.origin.trace_id, host_application: job.origin.host_application ?? "unknown" } : {}), account_id: job.state.account?.id, organization_id: job.state.organization.id,
|
|
12
12
|
parameters: { ...job.input }, execution_mode: "async" });
|
|
13
13
|
let completion = { outcome: "success" };
|
|
14
14
|
let started = false;
|
|
@@ -24,6 +24,7 @@ export async function runTaskWorker(options) {
|
|
|
24
24
|
operation: job.operation,
|
|
25
25
|
label: job.label,
|
|
26
26
|
executionMode: "async",
|
|
27
|
+
...(job.origin ? { origin: job.origin } : {}),
|
|
27
28
|
onUpdate(task, progress) {
|
|
28
29
|
if (!started) {
|
|
29
30
|
started = true;
|
|
@@ -49,10 +50,14 @@ export async function runTaskWorker(options) {
|
|
|
49
50
|
: { outcome: "failure", error, errorCode: outcome.failure.code, errorMessage: outcome.failure.message };
|
|
50
51
|
if (outcome.kind === "failure")
|
|
51
52
|
send({ type: "error", failure: outcome.failure, exitCode: outcome.exitCode,
|
|
52
|
-
diagnostics: taskWorkerDiagnostics(error,
|
|
53
|
+
diagnostics: taskWorkerDiagnostics(error, {
|
|
54
|
+
...classifyTelemetryError(error, { product: runtime.product, operation: job.operation, failureStage: runtime.telemetry.failureStage(error) }),
|
|
55
|
+
diagnosticSummary: runtime.telemetry.taskFailure(error).diagnostic_summary ?? {}
|
|
56
|
+
}, runtime.telemetry.failureStage(error)) });
|
|
53
57
|
}
|
|
54
58
|
finally {
|
|
55
59
|
await runtime.analytics?.shutdown().catch(() => undefined);
|
|
60
|
+
await runtime.telemetrySink.refreshDiagnostics?.().catch(() => undefined);
|
|
56
61
|
runtime.telemetry.annotate(runtime.telemetrySink.diagnostics?.() ?? {});
|
|
57
62
|
await runtime.telemetrySink.send(runtime.telemetry.finish(completion)).catch(() => undefined);
|
|
58
63
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { validationIssues } from "../platform/schema-issues.js";
|
|
1
|
+
import { inputValidationSummary, validationIssues } from "../platform/schema-issues.js";
|
|
2
|
+
import { canonicalizeInputFileUris } from "../platform/input-uri.js";
|
|
2
3
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
3
4
|
import addFormatsImport, {} from "ajv-formats";
|
|
5
|
+
import { agentInputSchema } from "../contracts/creation-input.js";
|
|
4
6
|
import { contractSchema } from "../contracts/schema.js";
|
|
5
|
-
const agentSendInputSchema = contractSchema("agent.send", "input");
|
|
6
7
|
const agentSendOutputSchema = contractSchema("agent.send", "output");
|
|
7
8
|
const authStatusSchema = contractSchema("auth.status", "output");
|
|
8
9
|
const damDeleteInputSchema = contractSchema("dam.delete", "input");
|
|
@@ -21,6 +22,8 @@ const damMoveInputSchema = contractSchema("dam.move", "input");
|
|
|
21
22
|
const damMoveOutputSchema = contractSchema("dam.move", "output");
|
|
22
23
|
const damRepositoryListOutputSchema = contractSchema("dam.repository.list", "output");
|
|
23
24
|
const damRenameInputSchema = contractSchema("dam.rename", "input");
|
|
25
|
+
// The service owns the character limit. The CLI only needs a title to send.
|
|
26
|
+
delete (damRenameInputSchema.properties.title).maxLength;
|
|
24
27
|
const damRenameOutputSchema = contractSchema("dam.rename", "output");
|
|
25
28
|
const damSearchInputSchema = contractSchema("dam.search", "input");
|
|
26
29
|
const damSearchOutputSchema = contractSchema("dam.search", "output");
|
|
@@ -45,9 +48,11 @@ const toolCallOutputSchema = contractSchema("tool.call", "output");
|
|
|
45
48
|
const toolListOutputSchema = contractSchema("tool.list", "output");
|
|
46
49
|
export class InputContractError extends Error {
|
|
47
50
|
issues;
|
|
48
|
-
|
|
51
|
+
diagnosticSummary;
|
|
52
|
+
constructor(issues = [], diagnosticSummary = {}) {
|
|
49
53
|
super(`输入不符合命令契约。${issues.length ? ` ${JSON.stringify(issues)}` : ""}`);
|
|
50
54
|
this.issues = issues;
|
|
55
|
+
this.diagnosticSummary = diagnosticSummary;
|
|
51
56
|
this.name = "InputContractError";
|
|
52
57
|
}
|
|
53
58
|
}
|
|
@@ -63,7 +68,7 @@ export function createContractValidators(options = {}) {
|
|
|
63
68
|
const ajv = new Ajv2020({ allErrors: true, strict: true });
|
|
64
69
|
const addFormats = addFormatsImport;
|
|
65
70
|
addFormats(ajv);
|
|
66
|
-
const agentSendInput = ajv.compile(
|
|
71
|
+
const agentSendInput = ajv.compile(agentInputSchema);
|
|
67
72
|
const agentSendOutput = ajv.compile(agentSendOutputSchema);
|
|
68
73
|
const authStatus = ajv.compile(authStatusSchema);
|
|
69
74
|
const damFolderListInput = ajv.compile(damFolderListInputSchema);
|
|
@@ -168,7 +173,11 @@ export function createContractValidators(options = {}) {
|
|
|
168
173
|
const unavailableValidator = Object.assign(() => false, { errors: null, schema: false, schemaEnv: undefined });
|
|
169
174
|
function assertion(validate, ErrorType) {
|
|
170
175
|
return (value) => {
|
|
171
|
-
if (
|
|
172
|
-
|
|
176
|
+
if (ErrorType === InputContractError)
|
|
177
|
+
canonicalizeInputFileUris(value, validate.schema);
|
|
178
|
+
if (!validate(value)) {
|
|
179
|
+
const issues = validationIssues(validate.errors, value, validate.schema);
|
|
180
|
+
throw new ErrorType(issues, inputValidationSummary(issues, value));
|
|
181
|
+
}
|
|
173
182
|
};
|
|
174
183
|
}
|
|
@@ -116,6 +116,45 @@ function annotateAccessContext(telemetry, context) {
|
|
|
116
116
|
organization_id: context.state.organization?.id
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
|
+
/** Identify the invocation before Commander can read stdin, reject arguments or exit for help. */
|
|
120
|
+
export function invocationDefinition(program, argv) {
|
|
121
|
+
let command = program;
|
|
122
|
+
let unknown = false;
|
|
123
|
+
let mode = "execute";
|
|
124
|
+
for (let i = 0; i < argv.length; i++) {
|
|
125
|
+
const token = argv[i];
|
|
126
|
+
if (token === "--")
|
|
127
|
+
break;
|
|
128
|
+
if (token === "-h" || token === "--help") {
|
|
129
|
+
mode = "help";
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (token === "-V" || token === "--version") {
|
|
133
|
+
mode = "version";
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (token.startsWith("-")) {
|
|
137
|
+
const flag = token.split("=")[0];
|
|
138
|
+
const option = [...command.options, ...program.options].find(item => item.long === flag || item.short === flag);
|
|
139
|
+
if (option?.long === "--schema" && mode === "execute")
|
|
140
|
+
mode = "schema";
|
|
141
|
+
if (option?.required && !token.includes("="))
|
|
142
|
+
i++;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (command.commands.length) {
|
|
146
|
+
const child = command.commands.find(item => item.name() === token || item.aliases().includes(token));
|
|
147
|
+
if (!child) {
|
|
148
|
+
unknown = true;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
command = child;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const path = commandPath(command).split(" ").slice(1).join(".");
|
|
155
|
+
const operation = mode === "version" ? "version" : unknown ? "unknown" : path || (mode === "help" ? "help" : "unknown");
|
|
156
|
+
return { operation, mode: () => mode };
|
|
157
|
+
}
|
|
119
158
|
function commandPath(command) {
|
|
120
159
|
const names = [];
|
|
121
160
|
let current = command;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hostSchema, readHostInput } from "./host-input.js";
|
|
2
|
+
import { agentInputSchema } from "../contracts/creation-input.js";
|
|
2
3
|
import { jsonOutput, bindPreparedAction } from "./action-binding.js";
|
|
3
4
|
import { CliUsageError } from "./errors.js";
|
|
4
5
|
import { productText as text } from "../product/text.js";
|
|
5
|
-
const agentSendInputSchema = contractSchema("agent.send", "input");
|
|
6
6
|
export function registerAgentCommands(program, runtime) {
|
|
7
7
|
const agent = program.command("agent")
|
|
8
8
|
.description(text(runtime.product, "稿定 Agent", "insMind Agent"))
|
|
@@ -26,7 +26,7 @@ export function registerAgentCommands(program, runtime) {
|
|
|
26
26
|
text(runtime.product, "默认模式在 stderr 提示任务 ID,stdout 保持原结果 JSON。", "In default mode the Task ID is written to stderr; stdout contains only the original result JSON."),
|
|
27
27
|
text(runtime.product, `结果未收到时执行 ${runtime.product.commandName} task list 找到原调用,再执行 ${runtime.product.commandName} task get <id> 查询。`, `If output is missing, find the original run with ${runtime.product.commandName} task list, then query ${runtime.product.commandName} task get <id>.`),
|
|
28
28
|
text(runtime.product, "首次创作省略 JSON 中的 message.contextId;续聊时传入上次结果的 message.contextId。", "Omit message.contextId for the first creation. Continue a conversation using message.contextId from the previous result."),
|
|
29
|
-
text(runtime.product, "
|
|
29
|
+
text(runtime.product, "可用 model 和参数示例见 model list / model get。显式 model 和 arguments 会传给 Agent,编辑模型的已知别名转换为服务字段。文本和素材用独立 Part。", "Discover models and example controls with model list and model get. Explicit model and arguments are sent to the Agent, with known editing aliases mapped to service fields. Supply text and assets as separate Parts."),
|
|
30
30
|
text(runtime.product, "usage 仅覆盖本次调用,不包含其他命令调用的消耗。", "usage covers this invocation only, excluding other command invocations."),
|
|
31
31
|
""
|
|
32
32
|
].join("\n"));
|
|
@@ -39,11 +39,11 @@ export function registerAgentCommands(program, runtime) {
|
|
|
39
39
|
throw new CliUsageError();
|
|
40
40
|
if (options.schema === true) {
|
|
41
41
|
await runtime.telemetry.stage("output", async () => {
|
|
42
|
-
runtime.io.writeOut(`${JSON.stringify(
|
|
42
|
+
runtime.io.writeOut(`${JSON.stringify(hostSchema(runtime, agentInputSchema))}\n`);
|
|
43
43
|
});
|
|
44
44
|
return { handled: true };
|
|
45
45
|
}
|
|
46
|
-
const input = await runtime.jsonInput.read(options.input, signal);
|
|
46
|
+
const input = readHostInput(runtime, await runtime.jsonInput.read(options.input, signal));
|
|
47
47
|
runtime.validators.agentSendInput(input);
|
|
48
48
|
runtime.telemetry.annotate({ parameters: { ...input } });
|
|
49
49
|
return { handled: false, input };
|
|
@@ -61,13 +61,9 @@ export function registerAgentCommands(program, runtime) {
|
|
|
61
61
|
});
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
const run =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
access: { credential: context.state.credential, organizationId: context.state.organization.id }, signal });
|
|
68
|
-
runtime.validators.agentSendOutput(result);
|
|
69
|
-
return result;
|
|
70
|
-
};
|
|
64
|
+
const run = (observe) => runtime.agent.send({ input,
|
|
65
|
+
...(observe ? { observe } : {}),
|
|
66
|
+
access: { credential: context.state.credential, organizationId: context.state.organization.id }, signal });
|
|
71
67
|
const result = await runtime.tasks.track({ ...task, run });
|
|
72
68
|
await runtime.telemetry.stage("output", async () => {
|
|
73
69
|
runtime.io.writeOut(`${JSON.stringify(result)}\n`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeDamAssetId } from "../features/dam/input.js";
|
|
1
2
|
import { bindAction, bindPreparedAction } from "./action-binding.js";
|
|
2
3
|
import { CliUsageError } from "./errors.js";
|
|
3
4
|
import { repositoryListView } from "./presenter.js";
|
|
@@ -100,12 +101,12 @@ export function registerDamCommands(program, runtime) {
|
|
|
100
101
|
});
|
|
101
102
|
}, { operation: "dam.tag.list" });
|
|
102
103
|
const download = leaf(dam.command("download"))
|
|
103
|
-
.description(text(runtime.product, "
|
|
104
|
+
.description(text(runtime.product, "下载一个素材的源文件", "Download an asset's source file"))
|
|
104
105
|
.argument("<asset>", text(runtime.product, "素材 ID", "asset ID"))
|
|
105
106
|
.option("--repository-id <id>", text(runtime.product, "所属资源库 ID", "repository ID"))
|
|
106
|
-
.option("--output-dir <directory>", text(runtime.product, "
|
|
107
|
+
.option("--output-dir <directory>", text(runtime.product, "输出目录,默认当前目录", "output directory; defaults to the current directory"))
|
|
107
108
|
.option("--json", text(runtime.product, "输出 JSON", "output JSON"));
|
|
108
|
-
download.addHelpText("after", `\n${text(runtime.product, "
|
|
109
|
+
download.addHelpText("after", `\n${text(runtime.product, "下载单个素材的源文件,不支持文件夹,也不会自动导出作品。--output-dir 指定目录;已有同名文件时选择其他目录或先处理该文件。--json 返回 files 中的路径、字节数与摘要。", "Downloads one asset's source file; folders and automatic design export are not supported. --output-dir selects a directory. If a same-named file exists, choose another directory or handle the existing file first. --json returns paths, byte counts and digests in files.")}\n`);
|
|
109
110
|
bindPreparedAction(download, "organization", async (signal) => {
|
|
110
111
|
signal.throwIfAborted();
|
|
111
112
|
const options = download.opts();
|
|
@@ -266,7 +267,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
266
267
|
.option("--json", text(runtime.product, "输出 JSON", "output JSON"));
|
|
267
268
|
bindPreparedAction(get, "organization", async (signal) => {
|
|
268
269
|
signal.throwIfAborted();
|
|
269
|
-
const input = { asset_id: position(get, 0) };
|
|
270
|
+
const input = { asset_id: normalizeDamAssetId(position(get, 0)) };
|
|
270
271
|
runtime.validators.damGetInput(input);
|
|
271
272
|
runtime.telemetry.annotate({ parameters: { ...input } });
|
|
272
273
|
return { handled: false, input };
|
|
@@ -331,7 +332,7 @@ export function registerDamCommands(program, runtime) {
|
|
|
331
332
|
signal.throwIfAborted();
|
|
332
333
|
const options = deleteCommand.opts();
|
|
333
334
|
const input = {
|
|
334
|
-
asset_id: position(deleteCommand, 0),
|
|
335
|
+
asset_id: normalizeDamAssetId(position(deleteCommand, 0)),
|
|
335
336
|
...defined("repositoryId", options.repositoryId),
|
|
336
337
|
...(options.permanent === true ? { permanent: true } : {})
|
|
337
338
|
};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { hostSchema, readHostInput, editorActions } from "./host-input.js";
|
|
1
2
|
import { jsonOutput, bindAction, bindPreparedAction } from "./action-binding.js";
|
|
2
3
|
import { contractSchema } from "../contracts/schema.js";
|
|
3
4
|
import { CliUsageError } from "./errors.js";
|
|
4
5
|
import { productText as text } from "../product/text.js";
|
|
5
|
-
const
|
|
6
|
+
const { $defs, ...actionArray } = contractSchema("editor.apply", "input");
|
|
7
|
+
const editorApplyInputSchema = {
|
|
8
|
+
type: "object", additionalProperties: false, required: ["actions"], properties: { actions: actionArray },
|
|
9
|
+
$defs: Object.fromEntries(Object.entries($defs)
|
|
10
|
+
.map(([name, definition]) => [name, { ...definition, additionalProperties: true }]))
|
|
11
|
+
};
|
|
6
12
|
export function registerEditorCommands(program, runtime) {
|
|
7
13
|
const editor = program.command("editor")
|
|
8
14
|
.description(text(runtime.product, "连接并操作 AI+ Editor", "Connect to and operate insMind Editor"))
|
|
@@ -64,7 +70,7 @@ export function registerEditorCommands(program, runtime) {
|
|
|
64
70
|
apply.addHelpText("after", [
|
|
65
71
|
"",
|
|
66
72
|
text(runtime.product, "--schema 与 --input 必须且只能选择一个。Schema 为本地契约,不连接 Editor;执行成功输出 JSON {appliedCount}。", "Choose exactly one of --schema and --input. Schema reads the local contract without connecting to Editor; successful execution returns JSON {appliedCount}."),
|
|
67
|
-
text(runtime.product, "
|
|
73
|
+
text(runtime.product, "输入对象包含 host_application 和按序执行的 actions 数组;类型、必填字段与可选值见 --schema。使用简短语义 ID;create ID 必须唯一,Connector 可引用本批次更早创建的 Shape。", "Input is an object with host_application and an ordered actions array; discover types, required fields and choices with --schema. Use short semantic IDs. Create IDs must be unique; a Connector may reference a Shape created earlier in the batch."),
|
|
68
74
|
text(runtime.product, "update 提交完整元素而非 patch,不改变 id 或 _type。delete 要求 ID 存在;删除 Shape 同时删除绑定的 Connector。", "Update requires the full element, not a patch, without changing id or _type. Delete requires an existing ID; deleting a Shape also deletes its bound Connectors."),
|
|
69
75
|
text(runtime.product, "Shape 的 x/y 为 Page 左上角坐标,w/h 大于 0;数值必须有限。颜色用 #RRGGBB 或 #RRGGBBAA,仅 stroke 可为 null。Connector 用 fromId/toId 表达有方向的 Shape 关系。", "Shape x/y locate its top-left corner in Page coordinates; w/h must exceed zero and numbers must be finite. Colors use #RRGGBB or #RRGGBBAA; only stroke accepts null. Connector fromId/toId express a directed Shape relationship."),
|
|
70
76
|
text(runtime.product, "整批先预检,再在可回滚事务中应用;INVALID_ACTIONS 时修正输入,APPLY_FAILED 时读 Snapshot 确认回滚。EDITOR_ROLLBACK_FAILED 时停止 apply/save,只读检查并报告。", "The batch is checked before one rollback-capable transaction. Correct INVALID_ACTIONS; on APPLY_FAILED read a Snapshot to confirm rollback. On EDITOR_ROLLBACK_FAILED, stop apply/save, inspect read-only and report."),
|
|
@@ -78,11 +84,10 @@ export function registerEditorCommands(program, runtime) {
|
|
|
78
84
|
if (Number(options.schema === true) + Number(options.input !== undefined) !== 1)
|
|
79
85
|
throw new CliUsageError();
|
|
80
86
|
if (options.schema === true) {
|
|
81
|
-
await runtime.telemetry.stage("output", () => { writeJson(runtime, editorApplyInputSchema); });
|
|
87
|
+
await runtime.telemetry.stage("output", () => { writeJson(runtime, hostSchema(runtime, editorApplyInputSchema)); });
|
|
82
88
|
return { handled: true };
|
|
83
89
|
}
|
|
84
|
-
const input = await runtime.jsonInput.read(options.input, signal);
|
|
85
|
-
runtime.validators.editorApplyInput(input);
|
|
90
|
+
const input = editorActions(readHostInput(runtime, await runtime.jsonInput.read(options.input, signal)));
|
|
86
91
|
return { handled: false, input };
|
|
87
92
|
}, async (_context, input, signal) => {
|
|
88
93
|
writeJson(runtime, await runtime.telemetry.stage("editor.apply", () => runtime.editor.apply({ input, signal })));
|