@insmind/cli 2.1.0 → 2.1.1
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/agent.send/input.schema.json +1 -77
- package/contracts/operations/dam.folder.list/input.schema.json +0 -1
- package/contracts/operations/dam.folder.list/output.schema.json +1 -2
- package/contracts/operations/dam.list/input.schema.json +3 -6
- package/contracts/operations/dam.list/output.schema.json +1 -2
- package/contracts/operations/dam.search/input.schema.json +3 -6
- package/contracts/operations/dam.search/output.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-edit-smart.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-expand-smart.schema.json +1 -2
- package/contracts/operations/tool.call/models/image-layers-smart.schema.json +1 -3
- package/contracts/operations/tool.call/models/video-edit-smart.schema.json +0 -3
- package/contracts/operations/tool.call/ocr-payload.schema.json +4 -5
- package/dist/bin/postinstall.js +22 -6
- package/dist/bin/task-worker.js +2 -2
- package/dist/src/bootstrap/create-cli.js +13 -6
- package/dist/src/bootstrap/create-runtime.js +98 -28
- package/dist/src/bootstrap/run-task-worker.js +6 -2
- package/dist/src/bootstrap/validators.js +1 -1
- package/dist/src/cli/action-binding.js +14 -37
- package/dist/src/cli/agent-commands.js +11 -11
- package/dist/src/cli/auth-commands.js +2 -1
- package/dist/src/cli/creation-help.js +9 -0
- package/dist/src/cli/dam-commands.js +10 -14
- package/dist/src/cli/editor-commands.js +7 -5
- package/dist/src/cli/errors.js +81 -22
- package/dist/src/cli/host-input.js +64 -5
- package/dist/src/cli/model-commands.js +9 -3
- package/dist/src/cli/observed-errors.js +7 -3
- package/dist/src/cli/org-commands.js +3 -1
- package/dist/src/cli/task-commands.js +6 -2
- package/dist/src/cli/tool-commands.js +12 -11
- package/dist/src/features/agent/creative-agent-adapter.js +6 -2
- package/dist/src/features/agent/creative-protocol.js +8 -29
- package/dist/src/features/agent/resource-authorizer.js +25 -17
- package/dist/src/features/agent/result-reader.js +31 -14
- package/dist/src/features/agent/use-cases.js +6 -31
- package/dist/src/features/credits/use-cases.js +55 -28
- package/dist/src/features/dam/asset-projection.js +3 -6
- package/dist/src/features/dam/dam-api-adapter.js +30 -15
- package/dist/src/features/dam/repository-catalog.js +30 -21
- package/dist/src/features/dam/use-cases.js +12 -7
- package/dist/src/features/editor/bridge-client.js +0 -2
- package/dist/src/features/editor/public-url.js +1 -36
- package/dist/src/features/editor/session.js +3 -2
- package/dist/src/features/editor/use-cases.js +27 -2
- package/dist/src/features/org/org-service.js +10 -1
- package/dist/src/features/org/use-cases.js +18 -4
- package/dist/src/features/task/process-owner.js +54 -0
- package/dist/src/features/task/store.js +37 -10
- package/dist/src/features/task/task-background.js +5 -2
- package/dist/src/features/task/use-cases.js +184 -84
- package/dist/src/features/tool/argument-paths.js +14 -0
- package/dist/src/features/tool/canvas-copy.js +28 -15
- package/dist/src/features/tool/canvas-matting.js +123 -0
- package/dist/src/features/tool/canvas-media.js +100 -52
- package/dist/src/features/tool/canvas-models.js +66 -33
- package/dist/src/features/tool/canvas-pricing.js +12 -0
- package/dist/src/features/tool/canvas-recovery.js +13 -30
- package/dist/src/features/tool/canvas-results.js +79 -87
- package/dist/src/features/tool/canvas-tool-adapter.js +134 -157
- package/dist/src/features/tool/canvas-video.js +44 -37
- package/dist/src/features/tool/dynamic-schema.js +39 -40
- package/dist/src/features/tool/ffprobe-executable.js +21 -0
- package/dist/src/features/tool/mns-catalog-adapter.js +61 -24
- package/dist/src/features/tool/resource-authorizer.js +11 -3
- package/dist/src/features/tool/tool-api-adapter.js +73 -82
- package/dist/src/features/tool/tool-errors.js +25 -0
- package/dist/src/features/tool/tool-output.js +15 -0
- package/dist/src/features/tool/use-cases.js +74 -98
- package/dist/src/features/update/update-service.js +95 -21
- package/dist/src/platform/media-type.js +46 -0
- package/dist/src/platform/public-url.js +35 -0
- package/dist/src/platform/remote-error-evidence.js +33 -6
- package/dist/src/platform/resource-auth-key.js +35 -1
- package/dist/src/platform/safe-upload-file.js +36 -41
- package/dist/src/platform/signature.js +2 -2
- package/dist/src/platform/signed-http-transport.js +4 -1
- package/dist/src/platform/url-safety.js +6 -1
- package/dist/src/platform/webm-header.js +41 -0
- package/dist/src/telemetry/command-route.js +38 -0
- package/dist/src/telemetry/command-routes.json +1 -0
- package/dist/src/telemetry/failure-summary.js +1 -1
- package/dist/src/telemetry/invocation.js +1 -2
- package/dist/src/telemetry/process-errors.js +17 -33
- package/dist/src/telemetry/sanitize.js +19 -4
- package/dist/src/telemetry/sls-sink.js +8 -0
- package/package.json +4 -4
- package/skills/insmind-cli/SKILL.md +18 -5
- package/skills/insmind-cli/references/agent.md +9 -4
- package/skills/insmind-cli/references/creation.md +3 -1
- package/skills/insmind-cli/references/editor.md +7 -5
- package/skills/insmind-cli/references/errors.md +20 -9
- package/skills/insmind-cli/references/matting.md +3 -5
- package/skills/insmind-cli/references/media-tools.md +10 -4
- package/skills/insmind-cli/references/tool.md +9 -15
|
@@ -1,40 +1,22 @@
|
|
|
1
|
+
import { ToolTaskFailedError } from "../tool/tool-errors.js";
|
|
1
2
|
import { redactSensitiveText } from "../../platform/redact.js";
|
|
2
3
|
import { TaskStoreError, taskScope } from "./store.js";
|
|
4
|
+
import { taskProcessAlive, taskProcessGeneration } from "./process-owner.js";
|
|
3
5
|
import { LocalFileError } from "../../platform/local-json-file.js";
|
|
4
|
-
import { ToolTaskFailedError } from "../tool/tool-api-adapter.js";
|
|
5
6
|
import { isContentReviewRejection } from "./creation-refusal.js";
|
|
6
7
|
import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
7
8
|
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
9
|
+
import { ObjectStorageUploadError } from "../dam/object-storage.js";
|
|
8
10
|
export class TaskNotFoundError extends Error {
|
|
9
11
|
constructor(message) { super(message); this.name = "TaskNotFoundError"; }
|
|
10
12
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
const url = new URL(raw);
|
|
19
|
-
if (!url.searchParams.has("auth_key"))
|
|
20
|
-
return raw;
|
|
21
|
-
url.searchParams.delete("auth_key");
|
|
22
|
-
return url.href;
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return raw;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
if (Array.isArray(item))
|
|
30
|
-
return item.map(clean);
|
|
31
|
-
if (item && typeof item === "object")
|
|
32
|
-
return Object.fromEntries(Object.entries(item)
|
|
33
|
-
.filter(([key]) => key.toLowerCase().replaceAll("_", "") !== "authkey")
|
|
34
|
-
.map(([key, nested]) => [key, clean(nested)]));
|
|
35
|
-
return item;
|
|
13
|
+
export class CreationInputUploadError extends Error {
|
|
14
|
+
cause;
|
|
15
|
+
constructor(cause) {
|
|
16
|
+
super("An input upload failed before creation dispatch.", { cause });
|
|
17
|
+
this.cause = cause;
|
|
18
|
+
this.name = "CreationInputUploadError";
|
|
36
19
|
}
|
|
37
|
-
return clean(value);
|
|
38
20
|
}
|
|
39
21
|
function resultTypes(result) {
|
|
40
22
|
const types = new Set();
|
|
@@ -53,6 +35,12 @@ function resultTypes(result) {
|
|
|
53
35
|
}
|
|
54
36
|
const HEARTBEAT_MS = 5_000;
|
|
55
37
|
const LEASE_MS = 15_000;
|
|
38
|
+
export function taskStartedNotice(taskId, command, mode, text) {
|
|
39
|
+
const lookup = `${command} task get ${taskId}`;
|
|
40
|
+
if (mode === "async")
|
|
41
|
+
return text(`本地任务 ID: ${taskId}。请等待当前命令返回受理回执,稍后用 ${lookup} 取回结果。`, `Local Task ID: ${taskId}. Wait for this command's acceptance receipt. Retrieve the result later with ${lookup}.`);
|
|
42
|
+
return text(`本地任务 ID: ${taskId}。请继续等待当前命令返回最终结果。仅在无法继续读取当前进程输出时,用 ${lookup} 取回原任务。`, `Local Task ID: ${taskId}. Keep waiting for this command's final result. Use ${lookup} only if you lose access to this process's output.`);
|
|
43
|
+
}
|
|
56
44
|
export function createTaskUseCases(dependencies) {
|
|
57
45
|
const { text, commandName } = dependencies;
|
|
58
46
|
const telemetry = dependencies.telemetry;
|
|
@@ -70,7 +58,12 @@ export function createTaskUseCases(dependencies) {
|
|
|
70
58
|
telemetry?.annotate({ warning_codes: ["TASK_CACHE_UNAVAILABLE"] });
|
|
71
59
|
await warn("task.cache_warning", text(`任务 ${id} 的本地记录未能保存,task get 可能无法恢复。请保留本次输出,不要重新提交创作。`, `The local record for task ${id} could not be saved; task get may not recover it. Keep this output and do not submit the creation again.`));
|
|
72
60
|
}
|
|
73
|
-
async function usageWarning(id, incomplete) {
|
|
61
|
+
async function usageWarning(id, incomplete, incompleteAmount) {
|
|
62
|
+
if (incompleteAmount && !warnedUsageTasks.has(id + ":amount")) {
|
|
63
|
+
warnedUsageTasks.add(id + ":amount");
|
|
64
|
+
telemetry?.annotate({ warning_codes: ["AGENT_USAGE_AMOUNT_MISSING"] });
|
|
65
|
+
await warn("task.usage_warning", text("本次费用仅包含服务明确返回的金额。部分计费记录缺少有效金额,完整实扣请以账单为准;请勿重复提交。", "Only amounts supplied by the service are included. One or more charges are unknown; consult billing and do not resubmit."));
|
|
66
|
+
}
|
|
74
67
|
if (!incomplete || warnedUsageTasks.has(id))
|
|
75
68
|
return;
|
|
76
69
|
warnedUsageTasks.add(id);
|
|
@@ -79,18 +72,59 @@ export function createTaskUseCases(dependencies) {
|
|
|
79
72
|
}
|
|
80
73
|
// Persist the first observation before enqueue. A later reader retries only unacknowledged facts.
|
|
81
74
|
async function enqueuePending(scope, record) {
|
|
75
|
+
if (!telemetry)
|
|
76
|
+
return;
|
|
82
77
|
for (const item of record.telemetry?.steps ?? []) {
|
|
83
|
-
if (item.enqueued
|
|
78
|
+
if (item.enqueued)
|
|
84
79
|
continue;
|
|
85
|
-
|
|
80
|
+
const generation = taskProcessGeneration();
|
|
81
|
+
let mayEmit = true;
|
|
86
82
|
try {
|
|
87
83
|
await dependencies.store.update(scope, record.task.taskId, stored => {
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
|
|
84
|
+
const saved = stored.telemetry?.steps.find(row => row.event.step === item.event.step);
|
|
85
|
+
if (!saved)
|
|
86
|
+
return; // The first-observation write failed; the stable event still goes to the queue.
|
|
87
|
+
item.enqueued = saved.enqueued;
|
|
88
|
+
mayEmit = !saved.enqueued && !taskProcessAlive(saved.enqueuePid, saved.enqueueGeneration, saved.enqueueAtMs ?? saved.event.occurred_at_ms);
|
|
89
|
+
if (mayEmit) {
|
|
90
|
+
saved.enqueuePid = process.pid;
|
|
91
|
+
saved.enqueueGeneration = generation;
|
|
92
|
+
saved.enqueueAtMs = Date.now();
|
|
93
|
+
}
|
|
91
94
|
});
|
|
92
95
|
}
|
|
93
|
-
catch { /*
|
|
96
|
+
catch { /* A failed local task cache must not discard the stable event. */ }
|
|
97
|
+
if (!mayEmit)
|
|
98
|
+
continue;
|
|
99
|
+
const renew = setInterval(() => {
|
|
100
|
+
void dependencies.store.update(scope, record.task.taskId, stored => {
|
|
101
|
+
const saved = stored.telemetry?.steps.find(row => row.event.step === item.event.step);
|
|
102
|
+
if (saved?.enqueuePid === process.pid && saved.enqueueGeneration === generation)
|
|
103
|
+
saved.enqueueAtMs = Date.now();
|
|
104
|
+
}).catch(() => undefined);
|
|
105
|
+
}, HEARTBEAT_MS);
|
|
106
|
+
renew.unref();
|
|
107
|
+
try {
|
|
108
|
+
item.enqueued = await telemetry.emit(item.event);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
clearInterval(renew);
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
await dependencies.store.update(scope, record.task.taskId, stored => {
|
|
115
|
+
const saved = stored.telemetry?.steps.find(row => row.event.step === item.event.step);
|
|
116
|
+
if (!saved)
|
|
117
|
+
return;
|
|
118
|
+
if (item.enqueued)
|
|
119
|
+
saved.enqueued = true;
|
|
120
|
+
if (saved.enqueuePid === process.pid && saved.enqueueGeneration === generation) {
|
|
121
|
+
delete saved.enqueuePid;
|
|
122
|
+
delete saved.enqueueGeneration;
|
|
123
|
+
delete saved.enqueueAtMs;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch { /* If the writer exits here, a later process reuses the original event key. */ }
|
|
94
128
|
}
|
|
95
129
|
}
|
|
96
130
|
async function fact(scope, record, step, at, outcome = "success", error) {
|
|
@@ -99,14 +133,17 @@ export function createTaskUseCases(dependencies) {
|
|
|
99
133
|
const current = telemetry.creationContext();
|
|
100
134
|
const { parameters, ...origin } = record.telemetry.context;
|
|
101
135
|
const creating = current.operation === origin.operation;
|
|
136
|
+
const protocol = record.progress.toolPipeline?.protocol ?? (record.task.operation === "tool.call" ? "dify" : undefined);
|
|
102
137
|
const event = { ...origin, event_name: "command_step", step, outcome,
|
|
103
138
|
command_kind: "creation", mode: "execute", process_role: current.process_role, occurred_at_ms: at,
|
|
104
139
|
record_seq: step === "request_sent" ? 2 : step === "result_received" ? 3 : 4,
|
|
105
140
|
...(step === "request_sent" && creating && current.tool_name ? { tool_name: current.tool_name } : {}),
|
|
106
141
|
...(step === "request_sent" && creating && current.model_id ? { model_id: current.model_id } : {}),
|
|
107
142
|
...(creating && current.content_id ? { content_id: current.content_id } : {}),
|
|
143
|
+
...(protocol ? { execution_protocol: protocol } : {}),
|
|
108
144
|
...(record.progress.remoteTaskId ? { task_id: record.progress.remoteTaskId } : {}),
|
|
109
|
-
...(
|
|
145
|
+
...(record.task.operation === "tool.call" && current.cli_task_id === record.task.taskId && current.dify_task_id
|
|
146
|
+
? { dify_task_id: current.dify_task_id } : {}),
|
|
110
147
|
...(step === "request_sent" && (current.parameters ?? parameters) ? { parameters: current.parameters ?? parameters } : {}),
|
|
111
148
|
...(error === undefined ? {} : telemetry.taskFailure(error)),
|
|
112
149
|
...(step !== "request_sent" && record.task.result ? { result_types: resultTypes(record.task.result) } : {}) };
|
|
@@ -124,8 +161,13 @@ export function createTaskUseCases(dependencies) {
|
|
|
124
161
|
return;
|
|
125
162
|
if (step === "delivered" && !facts.steps.some(row => row.event.step === "result_received" && row.event.outcome === outcome))
|
|
126
163
|
return;
|
|
164
|
+
if (step === "delivered" && !event.dify_task_id) {
|
|
165
|
+
const received = facts.steps.find(row => row.event.step === "result_received")?.event;
|
|
166
|
+
if (received?.dify_task_id)
|
|
167
|
+
event.dify_task_id = received.dify_task_id;
|
|
168
|
+
}
|
|
127
169
|
if (step === "request_sent") {
|
|
128
|
-
facts.context = { ...origin, ...(event.content_id ? { content_id: event.content_id } : {}), ...(event.tool_name ? { tool_name: event.tool_name } : {}), ...(event.model_id ? { model_id: event.model_id } : {}) };
|
|
170
|
+
facts.context = { ...origin, ...(protocol ? { execution_protocol: protocol } : {}), ...(event.content_id ? { content_id: event.content_id } : {}), ...(event.tool_name ? { tool_name: event.tool_name } : {}), ...(event.model_id ? { model_id: event.model_id } : {}) };
|
|
129
171
|
}
|
|
130
172
|
facts.steps.push({ event, enqueued: false });
|
|
131
173
|
}
|
|
@@ -139,6 +181,23 @@ export function createTaskUseCases(dependencies) {
|
|
|
139
181
|
}
|
|
140
182
|
await enqueuePending(scope, record);
|
|
141
183
|
}
|
|
184
|
+
async function rejected(scope, record, error, executionMode) {
|
|
185
|
+
await fact(scope, record, "result_received", dependencies.now().getTime(), "failure", error);
|
|
186
|
+
if (executionMode !== "async")
|
|
187
|
+
pendingOutput = { scope, record, rejected: true, error };
|
|
188
|
+
}
|
|
189
|
+
async function readRecord(state, id, signal) {
|
|
190
|
+
signal.throwIfAborted();
|
|
191
|
+
telemetry?.annotate({ cli_task_id: id });
|
|
192
|
+
const record = await stage("task.read", () => dependencies.store.read(taskScope(state), id));
|
|
193
|
+
if (!record)
|
|
194
|
+
throw new TaskNotFoundError(text(`当前身份中没有该任务。请执行 ${commandName} task list 查找。`, `No task was found in the current identity context. Use ${commandName} task list to find it.`));
|
|
195
|
+
if (record.telemetry)
|
|
196
|
+
telemetry?.annotate({ creation_trace_id: record.telemetry.context.trace_id });
|
|
197
|
+
if (record.task.operation === "tool.call")
|
|
198
|
+
telemetry?.annotate({ execution_protocol: record.progress.toolPipeline?.protocol ?? "dify" });
|
|
199
|
+
return record;
|
|
200
|
+
}
|
|
142
201
|
function summary(record) {
|
|
143
202
|
const { result: _result, partialResult: _partial, ...task } = record.task;
|
|
144
203
|
if (!record.progress.detached && task.state === "running"
|
|
@@ -221,13 +280,14 @@ export function createTaskUseCases(dependencies) {
|
|
|
221
280
|
throw storageContext(error, "before_dispatch");
|
|
222
281
|
}
|
|
223
282
|
input.onUpdate?.(structuredClone(record.task), { ...record.progress });
|
|
224
|
-
dependencies.notice(
|
|
283
|
+
dependencies.notice(taskStartedNotice(record.task.taskId, commandName, input.executionMode ?? "sync", text));
|
|
225
284
|
let writes = Promise.resolve();
|
|
226
|
-
const save = () => {
|
|
285
|
+
const save = async () => {
|
|
227
286
|
record.task.updatedAt = dependencies.now().toISOString();
|
|
228
287
|
const snapshot = structuredClone(record);
|
|
229
288
|
writes = writes.catch(() => undefined).then(() => dependencies.store.write(scope, snapshot));
|
|
230
|
-
|
|
289
|
+
await writes;
|
|
290
|
+
return snapshot;
|
|
231
291
|
};
|
|
232
292
|
let lastHeartbeatError = -Infinity;
|
|
233
293
|
const timer = setInterval(() => {
|
|
@@ -241,12 +301,20 @@ export function createTaskUseCases(dependencies) {
|
|
|
241
301
|
try {
|
|
242
302
|
const result = await input.run(async (progress) => {
|
|
243
303
|
if (progress.dispatchedAt !== undefined) {
|
|
304
|
+
if (dispatched)
|
|
305
|
+
return;
|
|
244
306
|
dispatched = true;
|
|
245
307
|
await fact(scope, record, "request_sent", progress.dispatchedAt);
|
|
246
308
|
await analyticsFact("started");
|
|
247
309
|
return;
|
|
248
310
|
}
|
|
249
|
-
|
|
311
|
+
const update = structuredClone(progress);
|
|
312
|
+
if (update.toolPipeline)
|
|
313
|
+
update.toolPipeline.checkpoint = (record.progress.toolPipeline?.checkpoint ?? 0) + 1;
|
|
314
|
+
Object.assign(record.progress, update);
|
|
315
|
+
const protocol = record.progress.toolPipeline?.protocol ?? (record.task.operation === "tool.call" ? "dify" : undefined);
|
|
316
|
+
if (protocol)
|
|
317
|
+
telemetry?.annotate({ execution_protocol: protocol });
|
|
250
318
|
telemetry?.annotate({ diagnostic_summary: {
|
|
251
319
|
...(progress.contextId ? { agentContextId: progress.contextId } : {}),
|
|
252
320
|
...(progress.localMessageId ? { localMessageId: progress.localMessageId } : {})
|
|
@@ -257,7 +325,8 @@ export function createTaskUseCases(dependencies) {
|
|
|
257
325
|
await stage("task.progress", save);
|
|
258
326
|
}
|
|
259
327
|
catch (error) {
|
|
260
|
-
if (!(error instanceof LocalFileError) || !dispatched || (input.executionMode === "async" && !durableAcceptance)
|
|
328
|
+
if (!(error instanceof LocalFileError) || !dispatched || (input.executionMode === "async" && !durableAcceptance)
|
|
329
|
+
|| (progress.toolPipeline?.matting && progress.toolPipeline.stage !== "complete")) {
|
|
261
330
|
throw storageContext(error, dispatched ? "after_dispatch" : "before_dispatch");
|
|
262
331
|
}
|
|
263
332
|
await cacheWarning(record.task.taskId);
|
|
@@ -269,28 +338,37 @@ export function createTaskUseCases(dependencies) {
|
|
|
269
338
|
clearInterval(timer);
|
|
270
339
|
await stage("task.validate", async () => { finish(record, result); });
|
|
271
340
|
telemetry?.annotate({ result_state: record.task.state });
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
await analyticsFact("completed");
|
|
275
|
-
}
|
|
341
|
+
const receivedAt = dependencies.now().getTime();
|
|
342
|
+
let persistenceError;
|
|
276
343
|
try {
|
|
277
344
|
await stage("task.persist", save);
|
|
278
345
|
}
|
|
279
346
|
catch (error) {
|
|
280
|
-
if (!(error instanceof LocalFileError)
|
|
281
|
-
throw
|
|
282
|
-
|
|
347
|
+
if (!(error instanceof LocalFileError))
|
|
348
|
+
throw error;
|
|
349
|
+
persistenceError = error;
|
|
350
|
+
}
|
|
351
|
+
if (record.task.state === "completed") {
|
|
352
|
+
await fact(scope, record, "result_received", receivedAt);
|
|
353
|
+
await analyticsFact("completed");
|
|
354
|
+
}
|
|
355
|
+
if (persistenceError) {
|
|
356
|
+
if (record.task.state !== "completed" || input.executionMode === "async")
|
|
357
|
+
throw storageContext(persistenceError, "final_persist");
|
|
283
358
|
await cacheWarning(record.task.taskId);
|
|
284
359
|
}
|
|
285
360
|
return { task: record.task, result, record };
|
|
286
361
|
}
|
|
287
|
-
catch (
|
|
362
|
+
catch (cause) {
|
|
288
363
|
clearInterval(timer);
|
|
364
|
+
const mayBeRunning = dispatched || record.progress.submissionStarted;
|
|
365
|
+
// The same uploader can also write generated assets after dispatch.
|
|
366
|
+
const error = !mayBeRunning && cause instanceof RemoteRequestError && cause.cause instanceof ObjectStorageUploadError
|
|
367
|
+
? new CreationInputUploadError(cause) : cause;
|
|
289
368
|
const diagnostic = telemetry?.taskFailure(error).diagnostic_reason
|
|
290
369
|
?? (error instanceof RemoteRequestError ? error.diagnosticReason : undefined);
|
|
291
370
|
const observationOnly = diagnostic === "LOCAL_WAIT_INTERRUPTED" || diagnostic === "TASK_QUERY_FAILED" || diagnostic === "TASK_CANCELED";
|
|
292
371
|
if (record.task.state !== "completed") {
|
|
293
|
-
const mayBeRunning = dispatched || record.progress.submissionStarted;
|
|
294
372
|
const auditRejected = isContentReviewRejection(error, { product: commandName === "insmind-cli" ? "insmind" : "gaoding", operation: input.operation });
|
|
295
373
|
const creditsRejected = commandName !== "insmind-cli" && input.operation === "tool.call"
|
|
296
374
|
&& (error instanceof RemoteRequestError || error instanceof RemoteProtocolError)
|
|
@@ -311,30 +389,37 @@ export function createTaskUseCases(dependencies) {
|
|
|
311
389
|
if (detail && diagnostic !== "LOCAL_WAIT_INTERRUPTED")
|
|
312
390
|
record.task.note = redactSensitiveText(detail);
|
|
313
391
|
telemetry?.annotate({ result_state: record.task.state });
|
|
392
|
+
const saved = await stage("task.persist", save).catch(() => undefined);
|
|
393
|
+
if (saved?.task.state === "completed" && saved.task.result) {
|
|
394
|
+
const result = await stage("task.authorize", () => dependencies.recovery.authorize(saved.task.result, input.state, input.signal ?? new AbortController().signal, saved.progress));
|
|
395
|
+
return { task: saved.task, result: result, record: saved };
|
|
396
|
+
}
|
|
314
397
|
if (dispatched && record.task.state === "failed") {
|
|
315
|
-
await
|
|
316
|
-
if (input.executionMode !== "async")
|
|
317
|
-
pendingOutput = { scope, record, rejected: true, error };
|
|
398
|
+
await rejected(scope, record, error, input.executionMode);
|
|
318
399
|
}
|
|
319
|
-
await stage("task.persist", save).catch(() => undefined);
|
|
320
400
|
if (error instanceof TaskStoreError && error.context)
|
|
321
401
|
error.context.result_state = record.task.state;
|
|
322
402
|
throw error;
|
|
323
403
|
}
|
|
404
|
+
finally {
|
|
405
|
+
clearInterval(timer);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function finishCreation(record, result) {
|
|
409
|
+
dependencies.validateResult?.(result);
|
|
410
|
+
record.task.state = "completed";
|
|
411
|
+
delete record.task.note;
|
|
412
|
+
record.task.result = result;
|
|
413
|
+
if ("message" in result)
|
|
414
|
+
record.task.contextId = result.message.contextId;
|
|
324
415
|
}
|
|
325
416
|
return {
|
|
326
417
|
async track(input) {
|
|
327
|
-
const execution = await execute(input,
|
|
328
|
-
dependencies.validateResult?.(result);
|
|
329
|
-
record.task.state = "completed";
|
|
330
|
-
record.task.result = withoutResourceKeys(result);
|
|
331
|
-
if ("message" in result)
|
|
332
|
-
record.task.contextId = result.message.contextId;
|
|
333
|
-
});
|
|
418
|
+
const execution = await execute(input, finishCreation);
|
|
334
419
|
if (input.executionMode !== "async") {
|
|
335
420
|
pendingOutput = { scope: taskScope(input.state), record: execution.record };
|
|
336
421
|
}
|
|
337
|
-
await usageWarning(execution.task.taskId, execution.record.progress.agentUsageModelMissing === true);
|
|
422
|
+
await usageWarning(execution.task.taskId, execution.record.progress.agentUsageModelMissing === true, execution.record.progress.agentUsageAmountMissing === true);
|
|
338
423
|
return execution.result;
|
|
339
424
|
},
|
|
340
425
|
async submit(input) {
|
|
@@ -345,25 +430,18 @@ export function createTaskUseCases(dependencies) {
|
|
|
345
430
|
return { tasks: records.filter(r => !operation || r.task.operation === operation).slice(0, limit).map(summary) };
|
|
346
431
|
},
|
|
347
432
|
async get({ state, id, signal }) {
|
|
348
|
-
signal.throwIfAborted();
|
|
349
433
|
const scope = taskScope(state);
|
|
350
|
-
|
|
351
|
-
let record = await stage("task.read", () => dependencies.store.read(scope, id));
|
|
352
|
-
if (!record)
|
|
353
|
-
throw new TaskNotFoundError(text(`当前身份中没有该任务。请执行 ${commandName} task list 查找。`, `No task was found in the current identity context. Use ${commandName} task list to find it.`));
|
|
354
|
-
if (record.telemetry)
|
|
355
|
-
telemetry?.annotate({ creation_trace_id: record.telemetry.context.trace_id });
|
|
434
|
+
const record = await readRecord(state, id, signal);
|
|
356
435
|
await enqueuePending(scope, record);
|
|
357
|
-
record = withoutResourceKeys(record);
|
|
358
436
|
telemetry?.annotate({ diagnostic_summary: {
|
|
359
437
|
...(record.progress.contextId ? { agentContextId: record.progress.contextId } : {}),
|
|
360
438
|
...(record.progress.localMessageId ? { localMessageId: record.progress.localMessageId } : {})
|
|
361
439
|
} });
|
|
362
440
|
telemetry?.annotate({ cli_task_id: id, result_state: record.task.state });
|
|
363
441
|
if (record.task.state === "completed" && record.task.result) {
|
|
364
|
-
const result = { ...record.task, result: await stage("task.authorize", () => dependencies.recovery.authorize(record.task.result, state, signal)) };
|
|
442
|
+
const result = { ...record.task, result: await stage("task.authorize", () => dependencies.recovery.authorize(record.task.result, state, signal, record.progress)) };
|
|
365
443
|
pendingOutput = { scope, record };
|
|
366
|
-
await usageWarning(id, record.progress.agentUsageModelMissing === true);
|
|
444
|
+
await usageWarning(id, record.progress.agentUsageModelMissing === true, record.progress.agentUsageAmountMissing === true);
|
|
367
445
|
return result;
|
|
368
446
|
}
|
|
369
447
|
const task = summary(record);
|
|
@@ -372,11 +450,27 @@ export function createTaskUseCases(dependencies) {
|
|
|
372
450
|
pendingOutput = { scope, record, rejected: true };
|
|
373
451
|
return task;
|
|
374
452
|
}
|
|
375
|
-
|
|
453
|
+
let recoveredFromCache = false;
|
|
454
|
+
const { failure, usageModelMissing, usageAmountMissing, ...recovered } = await stage("task.recover", async () => {
|
|
455
|
+
try {
|
|
456
|
+
return await dependencies.recovery[task.operation === "agent.send" ? "agent" : "tool"](record.progress, state, signal);
|
|
457
|
+
}
|
|
458
|
+
catch (error) {
|
|
459
|
+
signal.throwIfAborted();
|
|
460
|
+
// Another reader may have completed the task while this observation failed.
|
|
461
|
+
const saved = await dependencies.store.read(scope, id);
|
|
462
|
+
if (saved?.task.state !== "completed" || !saved.task.result)
|
|
463
|
+
throw error;
|
|
464
|
+
recoveredFromCache = true;
|
|
465
|
+
return saved.task;
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
if (usageAmountMissing)
|
|
469
|
+
record.progress.agentUsageAmountMissing = true;
|
|
376
470
|
if (usageModelMissing)
|
|
377
471
|
record.progress.agentUsageModelMissing = true;
|
|
378
472
|
const { note: _note, ...metadata } = task;
|
|
379
|
-
|
|
473
|
+
let result = { ...metadata, ...recovered };
|
|
380
474
|
if (result.state === "unknown" && task.note) {
|
|
381
475
|
result.note = [...new Set([task.note, recovered.note].filter(Boolean))].join(" ");
|
|
382
476
|
}
|
|
@@ -392,11 +486,9 @@ export function createTaskUseCases(dependencies) {
|
|
|
392
486
|
}
|
|
393
487
|
});
|
|
394
488
|
result.updatedAt = dependencies.now().toISOString();
|
|
395
|
-
record.task =
|
|
396
|
-
await fact(scope, record, "result_received", dependencies.now().getTime(), result.state === "completed" ? "success" : "failure", failure);
|
|
397
|
-
if (result.state === "failed")
|
|
398
|
-
pendingOutput = { scope, record, rejected: true };
|
|
489
|
+
record.task = result;
|
|
399
490
|
// Store merging protects terminal results and facts against stale heartbeats.
|
|
491
|
+
const observedTask = record.task;
|
|
400
492
|
try {
|
|
401
493
|
await stage("task.persist", () => dependencies.store.write(scope, record));
|
|
402
494
|
}
|
|
@@ -405,24 +497,32 @@ export function createTaskUseCases(dependencies) {
|
|
|
405
497
|
throw error;
|
|
406
498
|
await cacheWarning(id);
|
|
407
499
|
}
|
|
500
|
+
if (record.task !== observedTask || recoveredFromCache) {
|
|
501
|
+
result = { ...record.task, ...(record.task.result ? { result: await stage("task.authorize", () => dependencies.recovery.authorize(record.task.result, state, signal, record.progress)) } : {}) };
|
|
502
|
+
}
|
|
503
|
+
await fact(scope, record, "result_received", dependencies.now().getTime(), result.state === "completed" ? "success" : "failure", result.state === "failed" ? failure : undefined);
|
|
504
|
+
if (result.state === "failed")
|
|
505
|
+
pendingOutput = { scope, record, rejected: true };
|
|
408
506
|
}
|
|
409
507
|
telemetry?.annotate({ result_state: result.state });
|
|
410
508
|
if (result.state === "completed" && result.result)
|
|
411
509
|
pendingOutput = { scope, record };
|
|
412
510
|
if (result.result ?? result.partialResult)
|
|
413
|
-
await usageWarning(id, record.progress.agentUsageModelMissing === true);
|
|
511
|
+
await usageWarning(id, record.progress.agentUsageModelMissing === true, record.progress.agentUsageAmountMissing === true);
|
|
414
512
|
return result;
|
|
415
513
|
},
|
|
416
514
|
async workerStopped(state, id, error, reportedByWorker) {
|
|
417
515
|
const scope = taskScope(state);
|
|
418
516
|
const record = await dependencies.store.read(scope, id);
|
|
419
|
-
if (!record?.telemetry ||
|
|
517
|
+
if (!record?.telemetry || !telemetry)
|
|
420
518
|
return;
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
519
|
+
const original = record.telemetry.context.trace_id === telemetry.traceId;
|
|
520
|
+
if (original)
|
|
521
|
+
for (const { event } of record.telemetry.steps)
|
|
522
|
+
telemetry.observeStep(event.step);
|
|
523
|
+
const failed = record.telemetry.steps.find(({ event }) => event.step === "result_received" && event.outcome === "failure");
|
|
524
|
+
if (reportedByWorker && failed && original)
|
|
424
525
|
pendingOutput = { scope, record, rejected: true, error };
|
|
425
|
-
}
|
|
426
526
|
},
|
|
427
527
|
async outputCompleted(error) {
|
|
428
528
|
const output = pendingOutput;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { canonicalFileUri } from "../../platform/input-uri.js";
|
|
2
|
+
import { ToolInputError } from "./catalog.js";
|
|
3
|
+
// Only an explicit file URI denotes an unmapped local attachment. Opaque controls
|
|
4
|
+
// (server paths, JSON Pointers, prompt text) are forwarded, never read from disk.
|
|
5
|
+
export function assertNoLocalAssetPaths(value, path, declaredType) {
|
|
6
|
+
if (typeof value === "string" && declaredType !== "string" && canonicalFileUri(value) !== undefined) {
|
|
7
|
+
throw new ToolInputError("unmapped_local_asset", path);
|
|
8
|
+
}
|
|
9
|
+
if (value && typeof value === "object") {
|
|
10
|
+
for (const [key, child] of Object.entries(value)) {
|
|
11
|
+
assertNoLocalAssetPaths(child, path + "/" + key.replaceAll("~", "~0").replaceAll("/", "~1"));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,36 +1,46 @@
|
|
|
1
1
|
// Product copy only. Executable constraints stay in the shared formal Schema.
|
|
2
2
|
const copy = {
|
|
3
3
|
"image-edit-standard": ["Standard image edit", "White mask pixels are processed; black pixels are protected. Supply an opaque binary PNG matching the auto-oriented source. The CLI converts service-specific mask polarity and requests source dimensions."],
|
|
4
|
-
"image-edit-smart": ["Smart image edit", "Generative editing can change details. An optional mask is rendered as a cyan outline on the target image; referenceImages are references, never a mask.
|
|
4
|
+
"image-edit-smart": ["Smart image edit", "Generative editing can change details. An optional mask is rendered as a cyan outline on the target image; referenceImages are references, never a mask. Pixels outside the selection are not guaranteed to stay unchanged."],
|
|
5
5
|
"image-matting-standard": ["Standard background removal", "Preserves visible source pixels without reconstructing occluded parts. Returns a real alpha PNG at source dimensions unless cropToSubject is enabled."],
|
|
6
6
|
"image-matting-smart": ["Smart subject extraction", "Redraws the requested subject, then segments the redraw into a transparent PNG. Hidden details are generated guesses. An optional mask is a visual boundary cue. Transparent postprocessing is included; do not pay for another standard matting call."],
|
|
7
7
|
"image-remove-standard": ["Standard object removal", "Remove within white mask pixels; black pixels are protected. The opaque binary PNG mask must match the auto-oriented source. Source dimensions are requested from the service."],
|
|
8
|
-
"image-remove-smart": ["Smart object removal", "Remove objects from one target image using instructions. An optional mask is rendered as a cyan outline, not sent as another reference image.
|
|
8
|
+
"image-remove-smart": ["Smart object removal", "Remove objects from one target image using instructions. An optional mask is rendered as a cyan outline, not sent as another reference image. Pixels outside the selection are not guaranteed to stay unchanged."],
|
|
9
9
|
"image-enhance-standard": ["Standard image upscale", "targetLongEdge specifies the output's longest edge in pixels while retaining aspect ratio. Bounds and steps come from the current catalog."],
|
|
10
|
-
"image-enhance-smart": ["Smart image restoration", "Generative restoration may reconstruct textures, text, faces or product details
|
|
10
|
+
"image-enhance-smart": ["Smart image restoration", "Generative restoration may reconstruct textures, text, faces or product details; unchanged original details are not guaranteed."],
|
|
11
11
|
"image-expand-standard": ["Standard image expansion", "canvas and placement use auto-oriented source pixels. Origin is top-left; x goes right and y down. The original must fit without scaling. The target canvas dimensions are requested from the service."],
|
|
12
12
|
"image-expand-smart": ["Smart image expansion", "Place the source at natural size and expand its surroundings. Output uses the target aspect ratio; pixel dimensions follow the live resolution setting. Source details can change."],
|
|
13
|
-
"image-text-edit": ["Image text replacement", "replacements match complete original text. An empty to deletes it. Repeated text cannot be targeted by occurrence
|
|
13
|
+
"image-text-edit": ["Image text replacement", "replacements match complete original text. An empty to deletes it. Repeated text cannot be targeted by occurrence; actual text and layout are determined by the returned image."],
|
|
14
14
|
"image-ocr": ["Image text recognition", "Returns an embedded application/json resource: image{uri,width,height}, blocks[{bbox:[left,top,right,bottom],category,text?}]. Coordinates use the returned recognition image's top-left origin in pixels."],
|
|
15
|
-
"image-layers-layout": ["Layout decomposition", "Fits the source within 3000×3000 pixels without enlargement. Returns native template JSON and actual element counts, not PSD. Editability depends on the returned layers; fonts may be substituted. Use a discovered Editor import capability to open the template."],
|
|
16
|
-
"image-layers-smart": ["Smart layer decomposition", "Fits the source within 3000×3000 pixels without enlargement; the
|
|
17
|
-
"image-vectorize": ["Image to SVG", "Returns an SVG resource.
|
|
15
|
+
"image-layers-layout": ["Layout decomposition", "For separating layout elements such as poster headlines, body text and background. Fits the source within 3000×3000 pixels without enlargement. Returns native template JSON and actual element counts, not PSD. Editability depends on the returned layers; fonts may be substituted. Use a discovered Editor import capability to open the template."],
|
|
16
|
+
"image-layers-smart": ["Smart layer decomposition", "For separating objects in a photo from each other and the background, such as a product and surrounding props. Fits the source within 3000×3000 pixels without enlargement; the service requires width × height of at least 262144 total pixels (512×512), not a 512-pixel minimum for each edge. Returns native template JSON and layer counts, not PSD or word-by-word OCR. maxLayers is an upper bound. Pricing uses current remote metered components."],
|
|
17
|
+
"image-vectorize": ["Image to SVG", "Returns an SVG resource. Shapes, colors and details may be reconstructed; actual vector contents are determined by the returned file."],
|
|
18
18
|
"video-edit-smart": ["Smart video edit", "Duration and ratio come from the actual source. Reference videos including the source total at most 15 seconds. audioEnabled controls audio presence, not preservation of the original sound."],
|
|
19
|
-
"video-enhance-standard": ["Standard video upscale", "Uses ceil(actual seconds) for billing and requests preservation of the source video.
|
|
20
|
-
"video-enhance-smart": ["Smart video restoration", "Generative restoration requests the source duration rounded to 2–30 seconds and may change details.
|
|
19
|
+
"video-enhance-standard": ["Standard video upscale", "Uses ceil(actual seconds) for billing and requests preservation of the source video. Actual duration, visuals and soundtrack are determined by the returned video."],
|
|
20
|
+
"video-enhance-smart": ["Smart video restoration", "Generative restoration requests the source duration rounded to 2–30 seconds and may change details. Actual duration, sound content and synchronization are determined by the returned video."]
|
|
21
21
|
};
|
|
22
22
|
export function englishCanvasCopy(model, schema) {
|
|
23
|
+
const smartExpansion = model === "image-expand-smart";
|
|
23
24
|
const descriptions = {
|
|
25
|
+
model: "Selected model identifier from the current model list/get output.",
|
|
26
|
+
prompt: "Describe the target, requested changes and content to preserve. Supply media separately in its URI fields.",
|
|
27
|
+
resolution: "Requested output resolution tier as a string; use current options[].value, not the display label.",
|
|
28
|
+
audioEnabled: "Audio-presence option as the current options[].value string, not a JSON boolean. It does not guarantee preservation of the original soundtrack.",
|
|
24
29
|
image: "One HTTP(S) or CLI file:// source image URI.",
|
|
25
30
|
video: "One HTTP(S) or CLI file:// source video URI.",
|
|
26
|
-
mask: "Fully opaque PNG
|
|
31
|
+
mask: "Fully opaque PNG matching the auto-oriented source. Use RGB 0/0/0 or 255/255/255 with alpha 255 if present. Prepare a separate mask from a colored or antialiased preview. White selects the target. Include at least one white pixel. All-white selects the entire image. "
|
|
32
|
+
+ (model.endsWith("-smart") ? "Black marks the area outside the selection. The outline guides generation, and areas outside it may also change." : "Black marks the area to protect."),
|
|
27
33
|
cropToSubject: "Crop to the nonzero alpha subject bounds. Default keeps the final source dimensions.",
|
|
28
|
-
canvas: "
|
|
29
|
-
|
|
34
|
+
canvas: smartExpansion ? "Layout canvas defining the requested aspect ratio. Final pixels follow the selected resolution." : "Requested output canvas size in pixels. The source is placed at its auto-oriented natural size.",
|
|
35
|
+
width: smartExpansion ? "Layout width in source pixels, used for the aspect ratio. Output pixels depend on resolution." : "Requested output canvas width in pixels.",
|
|
36
|
+
height: smartExpansion ? "Layout height in source pixels, used for the aspect ratio. Output pixels depend on resolution." : "Requested output canvas height in pixels.",
|
|
37
|
+
placement: smartExpansion ? "Source top-left in layout coordinates, in auto-oriented source pixels. X goes right and Y goes down." : "Source top-left on the requested output canvas, in pixels. Place the entire source at natural size, X right and Y down.",
|
|
38
|
+
x: "Horizontal offset of the source's left edge from the canvas's left edge, in pixels.",
|
|
39
|
+
y: "Vertical offset of the source's top edge from the canvas's top edge, in pixels.",
|
|
30
40
|
referenceImages: "Additional image references, separate from the target image and mask.",
|
|
31
41
|
referenceVideos: "Additional reference videos. The source video remains first.",
|
|
32
42
|
referenceAudios: "Additional audio references.",
|
|
33
|
-
replacements: "Complete original/new text pairs
|
|
43
|
+
replacements: "Complete original/new text pairs, in processing order. An empty to deletes the matched text.",
|
|
34
44
|
from: "The complete original text to replace, including punctuation and spaces.",
|
|
35
45
|
to: "Replacement text. An empty string deletes the matched original text.",
|
|
36
46
|
targetLongEdge: "Output's longest edge in pixels; aspect ratio is retained.",
|
|
@@ -41,13 +51,16 @@ export function englishCanvasCopy(model, schema) {
|
|
|
41
51
|
property.description = descriptions[name];
|
|
42
52
|
if (property.items?.format === "uri")
|
|
43
53
|
property.items.description = "HTTP(S) or CLI file:// asset URI.";
|
|
44
|
-
for (const [child, field] of Object.entries(property.items?.properties
|
|
54
|
+
for (const [child, field] of Object.entries({ ...property.properties, ...property.items?.properties })) {
|
|
45
55
|
if (descriptions[child])
|
|
46
56
|
field.description = descriptions[child];
|
|
47
57
|
}
|
|
48
58
|
}
|
|
59
|
+
if (model === "image-layers-layout" || model === "image-layers-smart") {
|
|
60
|
+
schema.properties.model.description = copy[model][1];
|
|
61
|
+
}
|
|
49
62
|
if (model.endsWith("-smart") && schema.properties.mask) {
|
|
50
|
-
schema.properties.mask.description = "Fully opaque PNG
|
|
63
|
+
schema.properties.mask.description = "Fully opaque PNG matching the auto-oriented source: RGB 0/0/0 or 255/255/255 and alpha, if present, 255; no gray antialiasing, transparency or colored selection preview. Nonempty white pixels identify the target; all-white selects the entire image. The CLI converts this to a visual boundary cue, which cannot guarantee unchanged pixels outside the selection.";
|
|
51
64
|
}
|
|
52
65
|
if (model === "video-edit-smart") {
|
|
53
66
|
schema.properties.video.description = "Source video to edit, referenced as 视频1 in the prompt. HTTP(S) or CLI file:// URI.";
|