@insmind/cli 1.5.9 → 1.5.11
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/src/bootstrap/create-runtime.js +1 -1
- package/dist/src/cli/errors.js +10 -0
- package/dist/src/features/agent/creative-protocol.js +21 -0
- package/dist/src/features/task/store.js +3 -1
- package/dist/src/features/task/use-cases.js +69 -28
- package/dist/src/telemetry/invocation.js +10 -0
- package/dist/src/telemetry/sls-sink.js +6 -4
- package/package.json +4 -4
|
@@ -384,7 +384,7 @@ export function createProductionRuntime(options = {}) {
|
|
|
384
384
|
catch (error) {
|
|
385
385
|
if (!(error instanceof ToolTaskFailedError))
|
|
386
386
|
throw error;
|
|
387
|
-
return { state: "failed", note: text(error.message, "The Tool run failed.") };
|
|
387
|
+
return { state: "failed", note: text(error.message, "The Tool run failed."), failure: error };
|
|
388
388
|
}
|
|
389
389
|
if (response.state === "pending")
|
|
390
390
|
return { state: "running", note: text("原 Tool 查询尚未返回最终结果。", "The original Tool is still processing.") };
|
package/dist/src/cli/errors.js
CHANGED
|
@@ -9,6 +9,7 @@ import { AuthorizedAccountContextMissingError, DeviceAuthorizationExpiredError }
|
|
|
9
9
|
import { AgentInputError } from "../features/agent/use-cases.js";
|
|
10
10
|
import { ToolInputError } from "../features/tool/catalog.js";
|
|
11
11
|
import { ToolTaskFailedError } from "../features/tool/tool-api-adapter.js";
|
|
12
|
+
import { AgentAuditRejectedError } from "../features/agent/creative-protocol.js";
|
|
12
13
|
import { ObjectStorageUploadError } from "../features/dam/object-storage.js";
|
|
13
14
|
import { DamAssetNotDownloadableError, DamAssetNotFoundError, DamFolderNotFoundError } from "../features/dam/dam-api-adapter.js";
|
|
14
15
|
import { DamDownloadError, DamDownloadDestinationExistsError } from "../features/dam/file-downloader.js";
|
|
@@ -132,6 +133,15 @@ export function mapCliError(error, options) {
|
|
|
132
133
|
return failure("INSUFFICIENT_CREDITS", "There are not enough insMind credits to complete this creation.", 1, [`Buy credits at ${options.product.pricingUrl.href}`, "Retry after adding credits."]);
|
|
133
134
|
return failure("INSUFFICIENT_CREDITS", "当前组织稿豆不足,无法完成本次创作。", 1, INSUFFICIENT_CREDITS_NEXT_STEPS);
|
|
134
135
|
}
|
|
136
|
+
if (error instanceof AgentAuditRejectedError) {
|
|
137
|
+
const reason = error.phase === undefined ? "audit_rejected" : `${error.phase}_audit_rejected`;
|
|
138
|
+
const message = error.phase === "input"
|
|
139
|
+
? text("输入内容未通过审核,本次创作已拒绝。", "The input did not pass content review. This creation was rejected.")
|
|
140
|
+
: error.phase === "output"
|
|
141
|
+
? text("生成内容未通过审核,无法交付本次结果。", "The generated content did not pass review. This result cannot be delivered.")
|
|
142
|
+
: text("本次创作被内容审核拒绝。", "This creation was rejected by content review.");
|
|
143
|
+
return failure("REMOTE_REQUEST_FAILED", message, 1, [text("请检查并调整创作内容;不要重复提交相同请求。", "Review and adjust the creation content; do not resubmit the same request.")], { reason });
|
|
144
|
+
}
|
|
135
145
|
if (error instanceof RemoteProtocolError) {
|
|
136
146
|
return failure("REMOTE_PROTOCOL_INCOMPATIBLE", text("稿定服务返回了当前 CLI 无法安全处理的结果;为避免重复创作,已停止处理。", "The insMind service returned a result this CLI cannot safely process; processing stopped to avoid duplicate creation."), 1, [text(`保留诊断 ID。若已有任务 ID,用 ${command} task get <id> 查询原任务;查询异常不能证明生成失败,不要重新提交。`, `Keep the diagnostic ID. If a Task ID is available, use ${command} task get <id>. A query error does not prove generation failed; do not resubmit.`)]);
|
|
137
147
|
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
2
2
|
import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
3
|
+
export class AgentAuditRejectedError extends RemoteRequestError {
|
|
4
|
+
phase;
|
|
5
|
+
constructor(revokedMessageId) {
|
|
6
|
+
const phase = typeof revokedMessageId === "string" ? revokedMessageId === "" ? "input" : "output" : undefined;
|
|
7
|
+
super(undefined, false, { remoteCode: "-1006", remoteBody: '{"code":"-1006"}' }, undefined, phase === "input" ? "AGENT_INPUT_AUDIT_REJECTED" : phase === "output" ? "AGENT_OUTPUT_AUDIT_REJECTED" : "AGENT_AUDIT_REJECTED");
|
|
8
|
+
this.name = "AgentAuditRejectedError";
|
|
9
|
+
this.message = "Agent content review rejected this creation.";
|
|
10
|
+
this.phase = phase;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
3
13
|
export function buildCreativeRequest(message, ids) {
|
|
4
14
|
const prompt = [];
|
|
5
15
|
const textParts = [];
|
|
@@ -109,6 +119,17 @@ function fail(diagnosticReason, summary) {
|
|
|
109
119
|
throw new RemoteProtocolError(summary === undefined ? {} : { remoteBody: JSON.stringify(summary) }, undefined, diagnosticReason);
|
|
110
120
|
}
|
|
111
121
|
export function creativeContextId(messages) {
|
|
122
|
+
// A pre-run refusal is streamed before the user input is persisted. Checking
|
|
123
|
+
// status first prevents an empty messages history from hiding that decision.
|
|
124
|
+
for (const message of messages) {
|
|
125
|
+
const content = contentOf(message);
|
|
126
|
+
if (message.role !== "status" || content?.type !== "status")
|
|
127
|
+
continue;
|
|
128
|
+
const status = record(parseJson(content.text));
|
|
129
|
+
if (status?.code === "-1006" || status?.code === -1006) {
|
|
130
|
+
throw new AgentAuditRejectedError(record(message.extra)?.revoked_message_id);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
112
133
|
const contextId = messages
|
|
113
134
|
.map((message) => nonEmptyString(message.thread_id))
|
|
114
135
|
.find((value) => value !== undefined);
|
|
@@ -75,7 +75,9 @@ export function createTaskStore(options) {
|
|
|
75
75
|
if (previous.telemetry)
|
|
76
76
|
record.telemetry = {
|
|
77
77
|
...record.telemetry, ...previous.telemetry,
|
|
78
|
-
context: previous.telemetry.request_sent ? previous.telemetry.context : record.telemetry?.context ?? previous.telemetry.context
|
|
78
|
+
context: previous.telemetry.states?.length || previous.telemetry.request_sent ? previous.telemetry.context : record.telemetry?.context ?? previous.telemetry.context,
|
|
79
|
+
states: [...new Map([...(record.telemetry?.states ?? []), ...(previous.telemetry.states ?? [])]
|
|
80
|
+
.map(event => [event.task_revision, event])).values()].sort((a, b) => a.task_revision - b.task_revision)
|
|
79
81
|
};
|
|
80
82
|
}
|
|
81
83
|
options.validate(record.task);
|
|
@@ -2,6 +2,9 @@ import { redactSensitiveText } from "../../platform/redact.js";
|
|
|
2
2
|
import { TaskStoreError, taskScope } from "./store.js";
|
|
3
3
|
import { LocalFileError } from "../../platform/local-json-file.js";
|
|
4
4
|
import { ToolTaskFailedError } from "../tool/tool-api-adapter.js";
|
|
5
|
+
import { AgentAuditRejectedError } from "../agent/creative-protocol.js";
|
|
6
|
+
import { RemoteRequestError } from "../../platform/signed-http-transport.js";
|
|
7
|
+
import { RemoteProtocolError } from "../../platform/remote-protocol.js";
|
|
5
8
|
export class TaskNotFoundError extends Error {
|
|
6
9
|
constructor(message) { super(message); this.name = "TaskNotFoundError"; }
|
|
7
10
|
}
|
|
@@ -33,6 +36,21 @@ export function withoutResourceKeys(value) {
|
|
|
33
36
|
}
|
|
34
37
|
return clean(value);
|
|
35
38
|
}
|
|
39
|
+
function resultTypes(result) {
|
|
40
|
+
const types = new Set();
|
|
41
|
+
const parts = "message" in result ? result.message.parts : result.content;
|
|
42
|
+
for (const part of parts) {
|
|
43
|
+
if ("text" in part)
|
|
44
|
+
types.add("text");
|
|
45
|
+
else if ("data" in part)
|
|
46
|
+
types.add("clarification");
|
|
47
|
+
else {
|
|
48
|
+
const mime = "mediaType" in part ? part.mediaType : "mimeType" in part ? part.mimeType : undefined;
|
|
49
|
+
types.add(mime?.startsWith("image/") ? "image" : mime?.startsWith("video/") ? "video" : "other");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return [...types].sort();
|
|
53
|
+
}
|
|
36
54
|
const HEARTBEAT_MS = 5_000;
|
|
37
55
|
const LEASE_MS = 15_000;
|
|
38
56
|
export function createTaskUseCases(dependencies) {
|
|
@@ -47,42 +65,55 @@ export function createTaskUseCases(dependencies) {
|
|
|
47
65
|
telemetry?.annotate({ warning_codes: ["TASK_CACHE_UNAVAILABLE"] });
|
|
48
66
|
(dependencies.warning ?? dependencies.notice)(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.`));
|
|
49
67
|
}
|
|
50
|
-
async function fact(scope, record,
|
|
68
|
+
async function fact(scope, record, state, at, error) {
|
|
51
69
|
if (!telemetry || !record.telemetry)
|
|
52
70
|
return;
|
|
53
71
|
let context = record.telemetry.context;
|
|
54
|
-
if (
|
|
72
|
+
if (!record.telemetry.states?.length) {
|
|
55
73
|
const current = telemetry.creationContext();
|
|
56
|
-
context = { ...context,
|
|
74
|
+
context = { ...context, schema_version: "4",
|
|
57
75
|
...(current.tool_name ? { tool_name: current.tool_name } : {}),
|
|
58
76
|
...(current.model_id ? { model_id: current.model_id } : {}) };
|
|
59
|
-
// Fix the creation identity at dispatch even if the fact cannot be saved.
|
|
60
|
-
// Later completion and recovery must not use mutable command annotations.
|
|
61
77
|
record.telemetry.context = Object.freeze(context);
|
|
62
78
|
}
|
|
63
|
-
const
|
|
64
|
-
|
|
79
|
+
const make = (states) => {
|
|
80
|
+
const previous = states.at(-1);
|
|
81
|
+
if (previous?.result_state === state || previous?.result_state === "completed"
|
|
82
|
+
|| previous?.result_state === "failed" && state !== "completed")
|
|
83
|
+
return previous;
|
|
84
|
+
return { ...context, ...(error === undefined ? {} : telemetry.taskFailure(error)),
|
|
85
|
+
schema_version: "4", event_name: "task_state", result_state: state,
|
|
86
|
+
occurred_at_ms: at, started_at_ms: previous?.started_at_ms ?? record.telemetry?.request_sent?.occurred_at_ms ?? (state === "running" ? at : Date.parse(record.task.createdAt)),
|
|
87
|
+
task_revision: (previous?.task_revision ?? 0) + 1, record_seq: (previous?.task_revision ?? 0) + 1,
|
|
88
|
+
...(state === "completed" && record.task.result ? { result_types: resultTypes(record.task.result) } : {}) };
|
|
89
|
+
};
|
|
90
|
+
let event;
|
|
65
91
|
try {
|
|
66
92
|
const updated = await stage("telemetry.task", () => dependencies.store.update(scope, record.task.taskId, stored => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
93
|
+
stored.telemetry ??= { context };
|
|
94
|
+
const states = stored.telemetry.states ??= [];
|
|
95
|
+
// A stale caller cannot overwrite the first immutable revision.
|
|
96
|
+
event = make(states);
|
|
97
|
+
if (event && !states.some(e => e.task_revision === event.task_revision))
|
|
98
|
+
states.push(event);
|
|
99
|
+
stored.telemetry.context = context;
|
|
71
100
|
}));
|
|
72
101
|
if (updated.telemetry)
|
|
73
102
|
record.telemetry = updated.telemetry;
|
|
74
103
|
}
|
|
75
104
|
catch {
|
|
76
|
-
|
|
77
|
-
|
|
105
|
+
const states = record.telemetry.states ??= [];
|
|
106
|
+
event = make(states);
|
|
107
|
+
if (event && !states.some(e => e.task_revision === event.task_revision))
|
|
108
|
+
states.push(event);
|
|
78
109
|
}
|
|
79
|
-
|
|
110
|
+
if (event)
|
|
111
|
+
await telemetry.emit(event);
|
|
80
112
|
}
|
|
81
113
|
async function replay(record) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
114
|
+
// Old request_sent/result_ready records are readable, but are never emitted by this binary.
|
|
115
|
+
for (const event of record.telemetry?.states ?? [])
|
|
116
|
+
await telemetry?.emit(event);
|
|
86
117
|
}
|
|
87
118
|
function summary(record) {
|
|
88
119
|
const { result: _result, partialResult: _partial, ...task } = record.task;
|
|
@@ -186,7 +217,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
186
217
|
const result = await input.run(async (progress) => {
|
|
187
218
|
if (progress.dispatchedAt !== undefined) {
|
|
188
219
|
dispatched = true;
|
|
189
|
-
await fact(scope, record, "
|
|
220
|
+
await fact(scope, record, "running", progress.dispatchedAt);
|
|
190
221
|
await analyticsFact("started");
|
|
191
222
|
return;
|
|
192
223
|
}
|
|
@@ -210,7 +241,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
210
241
|
await stage("task.validate", async () => { finish(record, result); });
|
|
211
242
|
telemetry?.annotate({ result_state: record.task.state });
|
|
212
243
|
if (record.task.state === "completed") {
|
|
213
|
-
await fact(scope, record, "
|
|
244
|
+
await fact(scope, record, "completed", dependencies.now().getTime());
|
|
214
245
|
await analyticsFact("completed");
|
|
215
246
|
}
|
|
216
247
|
try {
|
|
@@ -228,18 +259,25 @@ export function createTaskUseCases(dependencies) {
|
|
|
228
259
|
clearInterval(timer);
|
|
229
260
|
if (record.task.state !== "completed") {
|
|
230
261
|
const mayBeRunning = dispatched || record.progress.submissionStarted;
|
|
231
|
-
const
|
|
262
|
+
const auditRejected = error instanceof AgentAuditRejectedError;
|
|
263
|
+
const creditsRejected = (error instanceof RemoteRequestError || error instanceof RemoteProtocolError)
|
|
264
|
+
&& error.remoteCode === "12020770";
|
|
265
|
+
const confirmedFailure = error instanceof ToolTaskFailedError || auditRejected || creditsRejected;
|
|
232
266
|
record.task.state = confirmedFailure || !mayBeRunning ? "failed" : "unknown";
|
|
233
|
-
record.task.note =
|
|
234
|
-
? text("
|
|
235
|
-
:
|
|
236
|
-
? text("
|
|
237
|
-
:
|
|
267
|
+
record.task.note = auditRejected
|
|
268
|
+
? text("内容未通过审核,本次创作已拒绝;具体错误见原命令。", "Content review rejected this creation. See the original command for the error.")
|
|
269
|
+
: confirmedFailure
|
|
270
|
+
? text("服务已明确拒绝本次创作或返回任务失败;具体错误见原命令。", "The service explicitly rejected this creation or reported task failure. See the original command for the error.")
|
|
271
|
+
: mayBeRunning
|
|
272
|
+
? text("CLI 未取得完整回执或结果;远端可能仍在执行。查询原任务,不自动重新生成。", "The CLI did not receive a complete receipt or result; the service may still be running. Query this task instead of submitting again.")
|
|
273
|
+
: text("CLI 在提交创作前结束;具体错误见原命令。", "The CLI stopped before submitting the creation. See the original command for the error.");
|
|
238
274
|
}
|
|
239
275
|
const detail = dependencies.failureNote?.(error);
|
|
240
276
|
if (detail)
|
|
241
277
|
record.task.note = [record.task.note, redactSensitiveText(detail)].filter(Boolean).join(" ");
|
|
242
278
|
telemetry?.annotate({ result_state: record.task.state });
|
|
279
|
+
if (dispatched)
|
|
280
|
+
await fact(scope, record, record.task.state, dependencies.now().getTime(), error);
|
|
243
281
|
await stage("task.persist", save).catch(() => undefined);
|
|
244
282
|
throw error;
|
|
245
283
|
}
|
|
@@ -276,7 +314,7 @@ export function createTaskUseCases(dependencies) {
|
|
|
276
314
|
const task = summary(record);
|
|
277
315
|
if (task.state === "failed" || (task.state === "running" && !record.progress.detached))
|
|
278
316
|
return task;
|
|
279
|
-
const recovered = await stage("task.recover", () => dependencies.recovery[task.operation === "agent.send" ? "agent" : "tool"](record.progress, state, signal));
|
|
317
|
+
const { failure, ...recovered } = await stage("task.recover", () => dependencies.recovery[task.operation === "agent.send" ? "agent" : "tool"](record.progress, state, signal));
|
|
280
318
|
const { note: _note, ...metadata } = task;
|
|
281
319
|
const result = { ...metadata, ...recovered };
|
|
282
320
|
if (result.state === "unknown" && task.note) {
|
|
@@ -284,7 +322,10 @@ export function createTaskUseCases(dependencies) {
|
|
|
284
322
|
}
|
|
285
323
|
if (result.state === "completed" && result.result) {
|
|
286
324
|
await stage("task.validate", async () => { dependencies.validateResult?.(result.result); });
|
|
287
|
-
|
|
325
|
+
}
|
|
326
|
+
if (result.state === "completed" || result.state === "failed") {
|
|
327
|
+
record.task = withoutResourceKeys(result);
|
|
328
|
+
await fact(scope, record, result.state, dependencies.now().getTime(), failure);
|
|
288
329
|
}
|
|
289
330
|
telemetry?.annotate({ result_state: result.state });
|
|
290
331
|
// Store merging protects terminal results and facts against stale heartbeats.
|
|
@@ -84,6 +84,16 @@ export function createTelemetryInvocation(options) {
|
|
|
84
84
|
return cleanDiagnostic({ ...snapshot, mode: "execute" });
|
|
85
85
|
},
|
|
86
86
|
async emit(event) { await publish(remember(event)); },
|
|
87
|
+
taskFailure(error) {
|
|
88
|
+
const c = classify(error);
|
|
89
|
+
const failedAt = c.failureStage ?? failureStage(error);
|
|
90
|
+
return { error_type: c.errorType ?? (error instanceof Error ? error.name : typeof error),
|
|
91
|
+
...(c.errorCode === undefined ? {} : { error_code: c.errorCode }),
|
|
92
|
+
...(c.httpStatus === undefined ? {} : { http_status: c.httpStatus }),
|
|
93
|
+
...(c.remoteErrorCode === undefined ? {} : { remote_error_code: c.remoteErrorCode }),
|
|
94
|
+
...(c.diagnosticReason === undefined && c.outcome !== "interrupted" ? {} : { diagnostic_reason: c.diagnosticReason ?? "LOCAL_WAIT_INTERRUPTED" }),
|
|
95
|
+
...(failedAt === undefined ? {} : { failure_stage: failedAt }) };
|
|
96
|
+
},
|
|
87
97
|
async stage(name, run, details) {
|
|
88
98
|
const start = options.now();
|
|
89
99
|
const allowed = detailedStages[definition?.mode ? `${definition.operation}:${definition.mode()}` : definition?.operation ?? ""];
|
|
@@ -8,9 +8,11 @@ const TTL = 7 * 86_400_000;
|
|
|
8
8
|
const CAPACITY = 10 * 1024 * 1024;
|
|
9
9
|
const BUDGET = 2_000;
|
|
10
10
|
export function eventKey(event) {
|
|
11
|
-
const key = event.event_name === "
|
|
12
|
-
? [event.cli_name, event.env, event.cli_task_id, event.
|
|
13
|
-
:
|
|
11
|
+
const key = event.event_name === "task_state"
|
|
12
|
+
? [event.cli_name, event.env, event.cli_task_id, "task_state", Number(event.task_revision)]
|
|
13
|
+
: event.event_name === "request_sent" || event.event_name === "result_ready"
|
|
14
|
+
? [event.cli_name, event.env, event.cli_task_id, event.event_name]
|
|
15
|
+
: [event.cli_name, event.env, event.trace_id, event.process_role, Number(event.record_seq)];
|
|
14
16
|
return createHash("sha256").update(JSON.stringify(key)).digest("hex");
|
|
15
17
|
}
|
|
16
18
|
export function wireEvent(event) {
|
|
@@ -127,7 +129,7 @@ export function createSlsTelemetrySink(options) {
|
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
let size = [...entries.values()].reduce((sum, e) => sum + Buffer.byteLength(JSON.stringify(e)), 0);
|
|
130
|
-
const priority = (e) => e.event.event_name === "request_sent" || e.event.event_name === "result_ready" ? 2
|
|
132
|
+
const priority = (e) => e.event.event_name === "task_state" || e.event.event_name === "request_sent" || e.event.event_name === "result_ready" ? 2
|
|
131
133
|
: "outcome" in e.event && e.event.outcome !== "success" ? 1 : 0;
|
|
132
134
|
for (const [id, entry] of [...entries].sort((a, b) => priority(a[1]) - priority(b[1]) || a[1].queuedAt - b[1].queuedAt)) {
|
|
133
135
|
checkBudget(deadline);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insmind/cli",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.11",
|
|
4
4
|
"description": "insMind command-line interface for agents and people.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@gaoding/cli": "workspace:*"
|
|
47
47
|
},
|
|
48
48
|
"gaodingRelease": {
|
|
49
|
-
"sourceCommit": "
|
|
50
|
-
"pipelineId": "
|
|
51
|
-
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/
|
|
49
|
+
"sourceCommit": "0bb51526a839bba7a6ef04e51a765c16ad732926",
|
|
50
|
+
"pipelineId": "214012",
|
|
51
|
+
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/214012"
|
|
52
52
|
}
|
|
53
53
|
}
|