@insmind/cli 1.9.1 → 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 +2 -2
- package/dist/src/bootstrap/create-cli.js +9 -14
- package/dist/src/bootstrap/create-runtime.js +26 -16
- package/dist/src/bootstrap/run-task-worker.js +2 -1
- package/dist/src/bootstrap/validators.js +4 -2
- 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 +3 -2
- package/dist/src/cli/editor-commands.js +10 -5
- package/dist/src/cli/host-input.js +34 -0
- package/dist/src/cli/model-commands.js +4 -3
- package/dist/src/cli/tool-commands.js +7 -9
- package/dist/src/contracts/creation-input.js +20 -0
- package/dist/src/features/agent/creative-protocol.js +12 -14
- 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/sso-service.js +6 -4
- package/dist/src/features/auth/use-cases.js +2 -1
- package/dist/src/features/credits/use-cases.js +1 -1
- package/dist/src/features/dam/file-downloader.js +2 -1
- package/dist/src/features/dam/use-cases.js +7 -7
- 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 +26 -12
- package/dist/src/features/task/use-cases.js +97 -82
- 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 +29 -64
- 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 +2 -2
- package/dist/src/features/tool/use-cases.js +24 -35
- package/dist/src/platform/json-input.js +1 -1
- package/dist/src/platform/safe-upload-file.js +6 -0
- package/dist/src/platform/signed-http-transport.js +24 -27
- package/dist/src/telemetry/host-diagnostics.js +2 -2
- package/dist/src/telemetry/invocation.js +87 -24
- package/dist/src/telemetry/process-errors.js +36 -3
- package/dist/src/telemetry/sls-sink.js +7 -10
- 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
|
@@ -31,7 +31,7 @@ try {
|
|
|
31
31
|
redact = redactModule.redact;
|
|
32
32
|
const selectedLocale = localeOption(process.argv.slice(2));
|
|
33
33
|
runtime = runtimeModule.createProductionRuntime({
|
|
34
|
-
product: insmindProduct,
|
|
34
|
+
product: insmindProduct, invocationStartedAt: startedAt, invocationTraceId: bootstrapTraceId,
|
|
35
35
|
...(selectedLocale === undefined ? {} : { locale: selectedLocale })
|
|
36
36
|
});
|
|
37
37
|
const program = cliModule.createCli(runtime, { signal: controller.signal });
|
|
@@ -51,7 +51,7 @@ catch (error) {
|
|
|
51
51
|
const traceId = runtime?.telemetry.traceId ?? bootstrapTraceId;
|
|
52
52
|
try {
|
|
53
53
|
const { reportProcessError } = await import("../src/telemetry/process-errors.js");
|
|
54
|
-
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" });
|
|
55
55
|
}
|
|
56
56
|
catch { /* Retain startup error output even if diagnostic modules cannot load. */ }
|
|
57
57
|
if (mapCliError === undefined || redact === undefined) {
|
|
@@ -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,13 +65,7 @@ export function createCli(runtime, options) {
|
|
|
65
65
|
return program;
|
|
66
66
|
}
|
|
67
67
|
export async function executeCli(options) {
|
|
68
|
-
|
|
69
|
-
// Commander handles version before action selection. Preserve the real
|
|
70
|
-
// operation if writing that version to a closed host pipe fails.
|
|
71
|
-
if (options.argv.some(argument => argument === "--version" || argument === "-V")
|
|
72
|
-
&& options.argv.every(argument => ["--version", "-V", "--json-errors"].includes(argument))) {
|
|
73
|
-
options.telemetry.select({ operation: "version" });
|
|
74
|
-
}
|
|
68
|
+
await options.telemetry.issue(invocationDefinition(options.program, options.argv));
|
|
75
69
|
try {
|
|
76
70
|
try {
|
|
77
71
|
await options.program.parseAsync(options.argv, { from: "user" });
|
|
@@ -79,15 +73,13 @@ export async function executeCli(options) {
|
|
|
79
73
|
catch (error) {
|
|
80
74
|
if (!isHelpOutcome(error))
|
|
81
75
|
throw error;
|
|
82
|
-
helpOnly = true;
|
|
83
76
|
if (options.argv[0] !== "update")
|
|
84
77
|
await checkUpdateNotification(options.updateNotification, options.signal);
|
|
85
78
|
options.signal.throwIfAborted();
|
|
86
79
|
}
|
|
87
80
|
await options.telemetry.stage("output", async () => { await outputs.get(options.program)?.io.flush?.(); });
|
|
88
81
|
await outputs.get(options.program)?.tasks.outputCompleted();
|
|
89
|
-
|
|
90
|
-
await sendFinished(options, { outcome: "success" });
|
|
82
|
+
await sendFinished(options, { outcome: "success" });
|
|
91
83
|
return 0;
|
|
92
84
|
}
|
|
93
85
|
catch (error) {
|
|
@@ -123,16 +115,20 @@ export async function executeCli(options) {
|
|
|
123
115
|
const traceId = options.telemetry.selected
|
|
124
116
|
? options.telemetry.traceId
|
|
125
117
|
: undefined;
|
|
118
|
+
let errorDelivered = false;
|
|
126
119
|
try {
|
|
127
120
|
options.presenter.error(outcome, {
|
|
128
121
|
json: errorUsesJson(options.program, options.argv),
|
|
129
122
|
...(traceId ? { traceId } : {})
|
|
130
123
|
});
|
|
124
|
+
await outputs.get(options.program)?.io.flush?.();
|
|
125
|
+
errorDelivered = true;
|
|
131
126
|
}
|
|
132
127
|
catch (presenterError) {
|
|
133
128
|
await options.telemetry.stage("output", () => { throw presenterError; }).catch(() => undefined);
|
|
134
129
|
}
|
|
135
|
-
|
|
130
|
+
if (errorDelivered)
|
|
131
|
+
await outputs.get(options.program)?.tasks.outputCompleted(error);
|
|
136
132
|
await sendFinished(options, outcome.kind === "interrupted"
|
|
137
133
|
? { outcome: "interrupted", error }
|
|
138
134
|
: {
|
|
@@ -166,6 +162,5 @@ async function sendFinished(options, completion) {
|
|
|
166
162
|
await options.telemetrySink.refreshDiagnostics?.().catch(() => undefined);
|
|
167
163
|
options.telemetry.annotate(options.telemetrySink.diagnostics?.() ?? {});
|
|
168
164
|
const events = options.telemetry.finish(completion);
|
|
169
|
-
|
|
170
|
-
await options.telemetrySink.send(events).catch(() => undefined);
|
|
165
|
+
await options.telemetrySink.send(events).catch(() => undefined);
|
|
171
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";
|
|
@@ -93,14 +93,15 @@ 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) }),
|
|
@@ -332,6 +333,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
332
333
|
store: createTaskStore({
|
|
333
334
|
...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {}),
|
|
334
335
|
stateDirectory: product.stateDirectory,
|
|
336
|
+
validateSummary: task => validators.taskListResult({ tasks: [task] }),
|
|
335
337
|
validate: validators.taskResult
|
|
336
338
|
}),
|
|
337
339
|
idFactory: randomUUID,
|
|
@@ -427,7 +429,6 @@ export function createProductionRuntime(options = {}) {
|
|
|
427
429
|
}
|
|
428
430
|
});
|
|
429
431
|
const agent = withAgentBillingUnit(createAgentUseCases({
|
|
430
|
-
catalog: modelCatalog,
|
|
431
432
|
uploader: transientUploader,
|
|
432
433
|
completion: createCreativeAgentAdapter({
|
|
433
434
|
transport: agentTransport,
|
|
@@ -435,7 +436,6 @@ export function createProductionRuntime(options = {}) {
|
|
|
435
436
|
idFactory: randomUUID,
|
|
436
437
|
telemetry
|
|
437
438
|
}),
|
|
438
|
-
warn: (message) => { presenter.warning(message); },
|
|
439
439
|
telemetry
|
|
440
440
|
}), product.billingUnit);
|
|
441
441
|
const canvasMedia = createCanvasMedia({ fetch, uploader: transientUploader });
|
|
@@ -522,16 +522,26 @@ export function createProductionRuntime(options = {}) {
|
|
|
522
522
|
org,
|
|
523
523
|
agent,
|
|
524
524
|
tasks,
|
|
525
|
-
startBackgroundTask
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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
|
+
},
|
|
535
545
|
editor,
|
|
536
546
|
dam,
|
|
537
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;
|
|
@@ -2,8 +2,8 @@ import { inputValidationSummary, validationIssues } from "../platform/schema-iss
|
|
|
2
2
|
import { canonicalizeInputFileUris } from "../platform/input-uri.js";
|
|
3
3
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
4
4
|
import addFormatsImport, {} from "ajv-formats";
|
|
5
|
+
import { agentInputSchema } from "../contracts/creation-input.js";
|
|
5
6
|
import { contractSchema } from "../contracts/schema.js";
|
|
6
|
-
const agentSendInputSchema = contractSchema("agent.send", "input");
|
|
7
7
|
const agentSendOutputSchema = contractSchema("agent.send", "output");
|
|
8
8
|
const authStatusSchema = contractSchema("auth.status", "output");
|
|
9
9
|
const damDeleteInputSchema = contractSchema("dam.delete", "input");
|
|
@@ -22,6 +22,8 @@ const damMoveInputSchema = contractSchema("dam.move", "input");
|
|
|
22
22
|
const damMoveOutputSchema = contractSchema("dam.move", "output");
|
|
23
23
|
const damRepositoryListOutputSchema = contractSchema("dam.repository.list", "output");
|
|
24
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;
|
|
25
27
|
const damRenameOutputSchema = contractSchema("dam.rename", "output");
|
|
26
28
|
const damSearchInputSchema = contractSchema("dam.search", "input");
|
|
27
29
|
const damSearchOutputSchema = contractSchema("dam.search", "output");
|
|
@@ -66,7 +68,7 @@ export function createContractValidators(options = {}) {
|
|
|
66
68
|
const ajv = new Ajv2020({ allErrors: true, strict: true });
|
|
67
69
|
const addFormats = addFormatsImport;
|
|
68
70
|
addFormats(ajv);
|
|
69
|
-
const agentSendInput = ajv.compile(
|
|
71
|
+
const agentSendInput = ajv.compile(agentInputSchema);
|
|
70
72
|
const agentSendOutput = ajv.compile(agentSendOutputSchema);
|
|
71
73
|
const authStatus = ajv.compile(authStatusSchema);
|
|
72
74
|
const damFolderListInput = ajv.compile(damFolderListInputSchema);
|
|
@@ -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";
|
|
@@ -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 })));
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { InputContractError } from "../bootstrap/validators.js";
|
|
2
|
+
import { productText } from "../product/text.js";
|
|
3
|
+
function object(value) {
|
|
4
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
/** The host is CLI metadata. Neither the service nor the shared MCP operation receives it. */
|
|
7
|
+
export function readHostInput(runtime, raw) {
|
|
8
|
+
if (!object(raw))
|
|
9
|
+
return raw;
|
|
10
|
+
const { host_application, ...input } = raw;
|
|
11
|
+
runtime.telemetry.observeHost(host_application);
|
|
12
|
+
return input;
|
|
13
|
+
}
|
|
14
|
+
export function hostSchema(runtime, schema) {
|
|
15
|
+
const description = productText(runtime.product, "填写发起本次 CLI 命令的应用名称,例如 workbuddy、qwenwork 或 trae。应用通过终端执行命令时仍填该应用的名称。用户直接在终端执行时填 terminal。其他应用填写其实际名称。", "Name the application invoking this command, for example workbuddy, qwenwork or trae. When an app uses a terminal, name the app. For direct terminal use, enter terminal. For other apps, enter their actual name.");
|
|
16
|
+
const augment = (source) => ({ ...source,
|
|
17
|
+
properties: { ...(object(source.properties) ? source.properties : {}), host_application: { type: "string", description } },
|
|
18
|
+
required: [...new Set([...(Array.isArray(source.required) ? source.required : []), "host_application"])] });
|
|
19
|
+
const result = augment(schema);
|
|
20
|
+
if (Array.isArray(schema.allOf)) {
|
|
21
|
+
return { ...result, allOf: schema.allOf.map(branch => object(branch) && object(branch.then) ? { ...branch, then: augment(branch.then) } : branch) };
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
export function editorActions(raw) {
|
|
26
|
+
if (!object(raw) || !Array.isArray(raw.actions))
|
|
27
|
+
throw new InputContractError([
|
|
28
|
+
{ field: "/actions", rule: "type", message: "expected an array of editor actions" }
|
|
29
|
+
]);
|
|
30
|
+
const extra = Object.keys(raw).find(key => key !== "actions");
|
|
31
|
+
if (extra)
|
|
32
|
+
throw new InputContractError([{ field: "/" + extra, rule: "additionalProperties", message: "editor action fields belong inside actions" }]);
|
|
33
|
+
return raw.actions;
|
|
34
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hostSchema } from "./host-input.js";
|
|
1
2
|
import { jsonOutput, bindAction } from "./action-binding.js";
|
|
2
3
|
import { CliUsageError } from "./errors.js";
|
|
3
4
|
import { productText as text } from "../product/text.js";
|
|
@@ -41,8 +42,8 @@ export function registerModelCommands(program, runtime) {
|
|
|
41
42
|
text(runtime.product, "只读查询当前身份可用的 Model,输出 JSON;不提交创作。参数、费用和预估耗时来自实时目录。", "Reads a Model available to the current identity as JSON without submitting creation. Parameters, cost and estimated time come from the live catalog."),
|
|
42
43
|
text(runtime.product, "inputSchema 是选定 Tool + Model 的完整 JSON Schema,包含嵌套对象、数组及约束。同一 Model 用于多个 Tool 时请加 --tool;优先按 inputSchema 构造 Tool 输入。", "inputSchema is the complete JSON Schema for the selected Tool + Model, including nested objects, arrays and constraints. Use --tool when a Model supports multiple Tools; construct Tool input from inputSchema."),
|
|
43
44
|
text(runtime.product, "parameters 是结构化元数据,不是 JSON Schema:遵守 required/type、minimum/maximum/step,SELECT 使用 options[].value 而非 label。", "parameters is structured metadata, not JSON Schema: follow required/type, minimum/maximum/step, and use SELECT options[].value rather than label."),
|
|
44
|
-
text(runtime.product, "
|
|
45
|
-
text(runtime.product, "usageDescription 说明跨字段组合规则。tool call <tool> --schema
|
|
45
|
+
text(runtime.product, "required 和 default 说明模型的输入要求和服务默认值。用户未指定有默认值的参数时可以省略;显式值原样发送。model 放在输入顶层。", "required and default describe the model input and service defaults. Omit a defaulted parameter the user did not specify. Explicit values are forwarded. Put model at the top level."),
|
|
46
|
+
text(runtime.product, "usageDescription 说明跨字段组合规则。tool call <tool> --schema 按 model 展示字段、选项和范围;step 及跨字段规则见本 Model 元数据。Agent 只传显式生成约束,不照搬 Tool 的完整必填参数。", "usageDescription explains cross-field combinations. tool call <tool> --schema describes fields, options and ranges per model; follow this Model's metadata for step and cross-field rules. For Agent, pass explicit generation constraints rather than copying every Tool-required parameter."),
|
|
46
47
|
""
|
|
47
48
|
].join("\n"));
|
|
48
49
|
jsonOutput(get);
|
|
@@ -67,7 +68,7 @@ export function registerModelCommands(program, runtime) {
|
|
|
67
68
|
});
|
|
68
69
|
await runtime.telemetry.stage("output", async () => {
|
|
69
70
|
runtime.validators.modelGetOutput(result);
|
|
70
|
-
runtime.io.writeOut(`${JSON.stringify(result)}\n`);
|
|
71
|
+
runtime.io.writeOut(`${JSON.stringify(result.inputSchema ? { ...result, inputSchema: hostSchema(runtime, result.inputSchema) } : result)}\n`);
|
|
71
72
|
});
|
|
72
73
|
}, {
|
|
73
74
|
operation: "model.get"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hostSchema, readHostInput } from "./host-input.js";
|
|
1
2
|
import { jsonOutput, bindAction, bindPreparedAction } from "./action-binding.js";
|
|
2
3
|
import { CliUsageError } from "./errors.js";
|
|
3
4
|
import { productText as text } from "../product/text.js";
|
|
@@ -56,7 +57,7 @@ export function registerToolCommands(program, runtime) {
|
|
|
56
57
|
if (options.schema === true) {
|
|
57
58
|
return { handled: false, input: { mode: "schema", name } };
|
|
58
59
|
}
|
|
59
|
-
const argumentsInput = await runtime.jsonInput.read(options.input, signal);
|
|
60
|
+
const argumentsInput = readHostInput(runtime, await runtime.jsonInput.read(options.input, signal));
|
|
60
61
|
const input = { name, arguments: argumentsInput };
|
|
61
62
|
runtime.validators.toolCallInput(input);
|
|
62
63
|
return { handled: false, input: { mode: "call", input, async: options.async === true } };
|
|
@@ -73,14 +74,15 @@ export function registerToolCommands(program, runtime) {
|
|
|
73
74
|
});
|
|
74
75
|
runtime.telemetry.annotate({ tool_name: prepared.name });
|
|
75
76
|
await runtime.telemetry.stage("output", async () => {
|
|
76
|
-
runtime.io.writeOut(`${JSON.stringify(schema)}\n`);
|
|
77
|
+
runtime.io.writeOut(`${JSON.stringify(hostSchema(runtime, { ...schema }))}\n`);
|
|
77
78
|
});
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
81
|
+
const { prompt, model } = prepared.input.arguments;
|
|
80
82
|
const task = {
|
|
81
83
|
state: context.state,
|
|
82
84
|
operation: "tool.call",
|
|
83
|
-
label: `${prepared.input.name}: ${
|
|
85
|
+
label: `${prepared.input.name}: ${typeof prompt === "string" ? prompt : typeof model === "string" ? model : ""}`
|
|
84
86
|
};
|
|
85
87
|
if (prepared.async) {
|
|
86
88
|
const result = await runtime.startBackgroundTask({ ...task, input: prepared.input }, signal);
|
|
@@ -90,12 +92,8 @@ export function registerToolCommands(program, runtime) {
|
|
|
90
92
|
});
|
|
91
93
|
return;
|
|
92
94
|
}
|
|
93
|
-
const run =
|
|
94
|
-
|
|
95
|
-
...(observe ? { observe } : {}) });
|
|
96
|
-
runtime.validators.toolCallOutput(result);
|
|
97
|
-
return result;
|
|
98
|
-
};
|
|
95
|
+
const run = (observe) => runtime.tool.call({ input: prepared.input, access, signal,
|
|
96
|
+
...(observe ? { observe } : {}) });
|
|
99
97
|
const result = await runtime.tasks.track({ ...task, run });
|
|
100
98
|
await runtime.telemetry.stage("output", async () => {
|
|
101
99
|
runtime.io.writeOut(`${JSON.stringify(result)}\n`);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { contractSchema } from "./schema.js";
|
|
2
|
+
// Media alone is a prompt. The service has one scene/parameter map and rewrites a
|
|
3
|
+
// question reply into a function response, discarding any accompanying prompt.
|
|
4
|
+
export const agentInputSchema = contractSchema("agent.send", "input");
|
|
5
|
+
const definitions = agentInputSchema.$defs;
|
|
6
|
+
delete definitions.FirstFramePart;
|
|
7
|
+
delete definitions.LastFramePart;
|
|
8
|
+
const generation = definitions.GenerationConstraintsPart.properties.data;
|
|
9
|
+
const model = generation.properties.model;
|
|
10
|
+
if (model.description)
|
|
11
|
+
model.description = "可选创作模型标识;已知编辑模型别名会映射到服务端 code,其余标识原样发送。";
|
|
12
|
+
delete generation.properties.arguments.minProperties;
|
|
13
|
+
const question = { $ref: "#/$defs/QuestionAnswerPart" };
|
|
14
|
+
definitions.UserMessage.allOf = [
|
|
15
|
+
...["GenerationConstraintsPart", "QuestionAnswerPart"].map(part => ({
|
|
16
|
+
properties: { parts: { type: "array", contains: { $ref: "#/$defs/" + part }, minContains: 0, maxContains: 1 } }
|
|
17
|
+
})),
|
|
18
|
+
{ if: { properties: { parts: { type: "array", contains: question } } },
|
|
19
|
+
then: { required: ["contextId"], properties: { contextId: { type: "string" }, parts: { type: "array", maxItems: 1 } } } }
|
|
20
|
+
];
|
|
@@ -32,7 +32,8 @@ export function buildCreativeRequest(message, ids) {
|
|
|
32
32
|
type: "media",
|
|
33
33
|
url: part.asset.url,
|
|
34
34
|
name: part.asset.filename,
|
|
35
|
-
mime: part.asset.mediaType
|
|
35
|
+
mime: part.asset.mediaType,
|
|
36
|
+
extra: { role: part.role }
|
|
36
37
|
});
|
|
37
38
|
attachments.push({
|
|
38
39
|
uri: part.asset.url,
|
|
@@ -144,27 +145,24 @@ export function creativeTurnMessages(value, localMessageId) {
|
|
|
144
145
|
if (!Array.isArray(value)) {
|
|
145
146
|
return fail("AGENT_MESSAGES_NOT_ARRAY", { valueType: value === null ? "null" : typeof value });
|
|
146
147
|
}
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
const messages = value;
|
|
152
|
-
const start = messages.findIndex((message) => {
|
|
153
|
-
if (message.local_message_id !== localMessageId)
|
|
154
|
-
return false;
|
|
155
|
-
return message.role === "user" || contentOf(message)?.type === "function_response";
|
|
156
|
-
});
|
|
148
|
+
const messages = value.map(message => record(message));
|
|
149
|
+
const start = messages.findIndex(message => message?.local_message_id === localMessageId
|
|
150
|
+
&& (message.role === "user" || contentOf(message)?.type === "function_response"));
|
|
157
151
|
if (start < 0) {
|
|
158
|
-
const matchingLocalMessageCount = messages.filter((message) => message
|
|
152
|
+
const matchingLocalMessageCount = messages.filter((message) => message?.local_message_id === localMessageId).length;
|
|
159
153
|
return fail(matchingLocalMessageCount > 0 ? "AGENT_TURN_ANCHOR_INVALID" : "AGENT_TURN_ANCHOR_MISSING", {
|
|
160
154
|
messageCount: messages.length, matchingLocalMessageCount
|
|
161
155
|
});
|
|
162
156
|
}
|
|
163
|
-
const nextInput = messages.findIndex((message, index) => index > start
|
|
157
|
+
const nextInput = messages.findIndex((message, index) => index > start && message !== undefined
|
|
164
158
|
&& typeof message.local_message_id === "string" && message.local_message_id !== ""
|
|
165
159
|
&& message.local_message_id !== localMessageId
|
|
166
160
|
&& (message.role === "user" || contentOf(message)?.type === "function_response"));
|
|
167
|
-
|
|
161
|
+
const turn = messages.slice(start, nextInput < 0 ? undefined : nextInput);
|
|
162
|
+
const valid = turn.filter(message => message !== undefined);
|
|
163
|
+
if (valid.length !== turn.length)
|
|
164
|
+
return fail("AGENT_MESSAGE_INVALID", { messageCount: turn.length, invalidMessageCount: turn.length - valid.length });
|
|
165
|
+
return valid;
|
|
168
166
|
}
|
|
169
167
|
function contentOf(message) {
|
|
170
168
|
return record(message.content);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { modelControlArgumentsAreValid } from "../tool/dynamic-schema.js";
|
|
3
|
-
import { canvasRemoteControlArguments } from "../tool/canvas-models.js";
|
|
1
|
+
import { canvasModelBindings, canvasRemoteControlArguments } from "../tool/canvas-models.js";
|
|
4
2
|
import { parseSafeRemoteAssetUrl, UrlSafetyError } from "../../platform/url-safety.js";
|
|
5
3
|
export class AgentInputError extends Error {
|
|
6
4
|
reason;
|
|
@@ -51,35 +49,12 @@ export function createAgentUseCases(dependencies) {
|
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
if (generation?.model !== undefined) {
|
|
54
|
-
const requested = generation;
|
|
55
52
|
dependencies.telemetry.annotate({ model_id: generation.model });
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
dependencies.warn(warning);
|
|
62
|
-
await dependencies.telemetry.stage("input", async () => {
|
|
63
|
-
let model;
|
|
64
|
-
try {
|
|
65
|
-
model = findModel(catalog, requested.model);
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
if (error instanceof ToolInputError)
|
|
69
|
-
throw new AgentInputError(error.reason, "/generation/model", error);
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
if (!modelControlArgumentsAreValid(model, requested.arguments ?? {}))
|
|
73
|
-
throw new AgentInputError("model_parameters", "/generation/arguments");
|
|
74
|
-
if (model.execution?.kind === "canvas") {
|
|
75
|
-
generation = {
|
|
76
|
-
model: model.execution.code,
|
|
77
|
-
...(requested.arguments === undefined ? {} : {
|
|
78
|
-
arguments: canvasRemoteControlArguments(model.model, requested.arguments)
|
|
79
|
-
})
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
});
|
|
53
|
+
const binding = canvasModelBindings.find(([, alias]) => alias === generation?.model);
|
|
54
|
+
if (binding)
|
|
55
|
+
generation = { model: binding[2], ...(generation.arguments === undefined ? {} : {
|
|
56
|
+
arguments: canvasRemoteControlArguments(binding[1], generation.arguments)
|
|
57
|
+
}) };
|
|
83
58
|
}
|
|
84
59
|
const prepare = async () => {
|
|
85
60
|
for (const part of input.message.parts) {
|