@insmind/cli 1.5.11 → 1.5.12

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.
@@ -139,6 +139,7 @@ async function checkUpdateNotification(updateNotification, signal) {
139
139
  }
140
140
  async function sendFinished(options, completion) {
141
141
  await analyticsShutdown.get(options.program)?.().catch(() => undefined);
142
+ options.telemetry.annotate(options.telemetrySink.diagnostics?.() ?? {});
142
143
  const events = options.telemetry.finish(completion);
143
144
  if (events.length > 0)
144
145
  await options.telemetrySink.send(events).catch(() => undefined);
@@ -53,6 +53,7 @@ export async function runTaskWorker(options) {
53
53
  }
54
54
  finally {
55
55
  await runtime.analytics?.shutdown().catch(() => undefined);
56
+ runtime.telemetry.annotate(runtime.telemetrySink.diagnostics?.() ?? {});
56
57
  await runtime.telemetrySink.send(runtime.telemetry.finish(completion)).catch(() => undefined);
57
58
  }
58
59
  }
@@ -10,6 +10,7 @@ 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
12
  import { AgentAuditRejectedError } from "../features/agent/creative-protocol.js";
13
+ import { isContentReviewRejection } from "../features/task/creation-refusal.js";
13
14
  import { ObjectStorageUploadError } from "../features/dam/object-storage.js";
14
15
  import { DamAssetNotDownloadableError, DamAssetNotFoundError, DamFolderNotFoundError } from "../features/dam/dam-api-adapter.js";
15
16
  import { DamDownloadError, DamDownloadDestinationExistsError } from "../features/dam/file-downloader.js";
@@ -28,6 +29,7 @@ import { redactSensitiveText } from "../platform/redact.js";
28
29
  import { EditorNotReadyError, EditorSessionNotFoundError, EditorTargetError } from "../features/editor/session.js";
29
30
  import { UpdateError } from "../features/update/update-service.js";
30
31
  import { WindAnalyticsError } from "../analytics/wind.js";
32
+ import { safeFailureSummary } from "../telemetry/failure-summary.js";
31
33
  export class CliUsageError extends Error {
32
34
  constructor() {
33
35
  super("命令或参数无效。");
@@ -133,14 +135,15 @@ export function mapCliError(error, options) {
133
135
  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."]);
134
136
  return failure("INSUFFICIENT_CREDITS", "当前组织稿豆不足,无法完成本次创作。", 1, INSUFFICIENT_CREDITS_NEXT_STEPS);
135
137
  }
136
- if (error instanceof AgentAuditRejectedError) {
137
- const reason = error.phase === undefined ? "audit_rejected" : `${error.phase}_audit_rejected`;
138
- const message = error.phase === "input"
138
+ if (isContentReviewRejection(error)) {
139
+ const phase = error instanceof AgentAuditRejectedError ? error.phase : undefined;
140
+ const reason = phase === undefined ? "audit_rejected" : `${phase}_audit_rejected`;
141
+ const message = phase === "input"
139
142
  ? text("输入内容未通过审核,本次创作已拒绝。", "The input did not pass content review. This creation was rejected.")
140
- : error.phase === "output"
143
+ : phase === "output"
141
144
  ? text("生成内容未通过审核,无法交付本次结果。", "The generated content did not pass review. This result cannot be delivered.")
142
145
  : 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 });
146
+ return failure(error instanceof ToolTaskFailedError ? "TOOL_TASK_FAILED" : "REMOTE_REQUEST_FAILED", message, 1, [text("请检查并调整创作内容;不要重复提交相同请求。", "Review and adjust the creation content; do not resubmit the same request.")], { reason });
144
147
  }
145
148
  if (error instanceof RemoteProtocolError) {
146
149
  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.`)]);
@@ -243,6 +246,7 @@ export function classifyTelemetryError(error, options = {}) {
243
246
  ...(diagnostics?.failure_stage ? { failureStage: diagnostics.failure_stage } : {}),
244
247
  ...(diagnostics?.http_status === undefined ? {} : { httpStatus: diagnostics.http_status }),
245
248
  ...(diagnostics?.remote_error_code ? { remoteErrorCode: diagnostics.remote_error_code } : {}),
249
+ ...(diagnostics?.diagnostic_summary ? { diagnosticSummary: diagnostics.diagnostic_summary } : {}),
246
250
  ...(diagnostics?.diagnostic_reason ? { diagnosticReason: diagnostics.diagnostic_reason } : {}) };
247
251
  }
248
252
  let remoteError;
@@ -253,8 +257,21 @@ export function classifyTelemetryError(error, options = {}) {
253
257
  break;
254
258
  }
255
259
  }
260
+ let summary;
261
+ if ((remoteError instanceof RemoteRequestError || remoteError instanceof RemoteProtocolError)
262
+ && /^(?:RESPONSE_|AGENT_)/u.test(remoteError.diagnosticReason ?? "")) {
263
+ try {
264
+ summary = JSON.parse(remoteError.remoteBody ?? "null");
265
+ }
266
+ catch { /* No safe summary available. */ }
267
+ }
268
+ const diagnosticSummary = safeFailureSummary({
269
+ ...(summary && typeof summary === "object" && !Array.isArray(summary) ? summary : {}),
270
+ systemCode: systemErrorCode(error)
271
+ });
256
272
  return {
257
273
  outcome: outcome.kind === "interrupted" ? "interrupted" : "failure",
274
+ ...(diagnosticSummary ? { diagnosticSummary } : {}),
258
275
  ...(outcome.kind === "failure" ? { errorCode: outcome.failure.code } : {}),
259
276
  ...((remoteError instanceof RemoteRequestError || remoteError instanceof SsoRequestError) && remoteError.status !== undefined
260
277
  ? { httpStatus: remoteError.status }
@@ -282,7 +299,7 @@ function failure(code, message, exitCode, nextSteps, details) {
282
299
  }
283
300
  function systemErrorCode(error) {
284
301
  for (let depth = 0; error instanceof Error && depth < 10; depth++, error = error.cause) {
285
- if ("code" in error && typeof error.code === "string" && /^E[A-Z0-9_]{1,40}$/u.test(error.code))
302
+ if ("code" in error && typeof error.code === "string" && /^(?:E[A-Z0-9_]{1,40}|UND_ERR_[A-Z0-9_]{1,40}|LOCAL_LOCK_TIMEOUT)$/u.test(error.code))
286
303
  return error.code;
287
304
  }
288
305
  return undefined;
@@ -421,7 +421,7 @@ export function normalizeCreativeMessages(messages) {
421
421
  }
422
422
  const publicParts = dedupeParts(parts);
423
423
  if (publicParts.length === 0)
424
- return fail();
424
+ return fail("AGENT_RESULT_EMPTY", { messageCount: normalized.length, publicPartCount: 0 });
425
425
  const usageItems = [];
426
426
  for (const message of normalized) {
427
427
  if (contentOf(message)?.type !== "function_response")
@@ -436,7 +436,7 @@ export function normalizeCreativeMessages(messages) {
436
436
  continue;
437
437
  const model = nonEmptyString(extra?.scene_code);
438
438
  if (model === undefined)
439
- return fail();
439
+ return fail("AGENT_USAGE_MODEL_MISSING", { messageCount: normalized.length, publicPartCount: publicParts.length });
440
440
  usageItems.push({ model, cost: { unit: "gaodou", amount } });
441
441
  }
442
442
  return {
@@ -1,3 +1,4 @@
1
+ import { RemoteProtocolError } from "../../platform/remote-protocol.js";
1
2
  function isMessage(value) {
2
3
  return value !== null && typeof value === "object" && !Array.isArray(value);
3
4
  }
@@ -118,7 +119,14 @@ export async function parseCreativeStream(stream, signal, onContextId) {
118
119
  signal.removeEventListener("abort", onAbort);
119
120
  reader.releaseLock();
120
121
  }
121
- return messagesFrom(raw);
122
+ const messages = messagesFrom(raw);
123
+ if (messages.length === 0) {
124
+ const payloads = extractPayloads(raw);
125
+ throw new RemoteProtocolError({ remoteBody: JSON.stringify({ messageCount: 0, contextIdPresent: false, systemErrorCount: 0,
126
+ streamHadBytes: raw.length > 0, streamPayloadCount: Math.min(payloads.length, 100_000),
127
+ streamJsonValueCount: Math.min(payloads.reduce((count, payload) => count + parseSequence(payload).length, 0), 100_000) }) }, undefined, "AGENT_CONTEXT_ID_MISSING");
128
+ }
129
+ return messages;
122
130
  }
123
131
  function messagesFrom(raw) {
124
132
  const messages = [];
@@ -1,4 +1,5 @@
1
1
  import { RemoteProtocolError } from "../../platform/remote-protocol.js";
2
+ import { RemoteRequestError } from "../../platform/signed-http-transport.js";
2
3
  function isRecord(value) {
3
4
  return value !== null && typeof value === "object" && !Array.isArray(value);
4
5
  }
@@ -11,11 +12,19 @@ export function createFilemsResourceAuthKeyProvider(dependencies) {
11
12
  credential: access.credential,
12
13
  organizationId: access.organizationId,
13
14
  signal
15
+ }).catch(error => {
16
+ if (error instanceof RemoteRequestError) {
17
+ throw new RemoteRequestError(error.status, error.transient, {
18
+ ...(error.remoteCode === undefined ? {} : { remoteCode: error.remoteCode }),
19
+ ...(error.remoteBody === undefined ? {} : { remoteBody: error.remoteBody })
20
+ }, error, "RESOURCE_AUTH_REQUEST_FAILED");
21
+ }
22
+ throw error;
14
23
  });
15
24
  signal.throwIfAborted();
16
25
  if (!isRecord(response) || typeof response.auth_key !== "string"
17
26
  || ["", "null", "undefined"].includes(response.auth_key.trim())) {
18
- throw new RemoteProtocolError();
27
+ throw new RemoteProtocolError({}, undefined, "RESOURCE_AUTH_INVALID_RESPONSE");
19
28
  }
20
29
  return response.auth_key;
21
30
  }
@@ -0,0 +1,15 @@
1
+ import { AgentAuditRejectedError } from "../agent/creative-protocol.js";
2
+ import { ToolTaskFailedError } from "../tool/tool-api-adapter.js";
3
+ import { RemoteRequestError } from "../../platform/signed-http-transport.js";
4
+ import { RemoteProtocolError } from "../../platform/remote-protocol.js";
5
+ // Explicit CRC_SPAM refusals. Review timeouts and unknown request errors do not
6
+ // prove that a dispatched creation stopped, even when they use HTTP 400.
7
+ const CONTENT_REVIEW_CODES = new Set([
8
+ "12020751", "12020752", "12020753", "12020754", "12020755", "12020756",
9
+ "12020757", "12020758", "12020759", "12020760", "12020761"
10
+ ]);
11
+ export function isContentReviewRejection(error) {
12
+ return error instanceof AgentAuditRejectedError
13
+ || ((error instanceof RemoteRequestError || error instanceof RemoteProtocolError || error instanceof ToolTaskFailedError)
14
+ && error.remoteCode !== undefined && CONTENT_REVIEW_CODES.has(error.remoteCode));
15
+ }
@@ -1,4 +1,5 @@
1
1
  import { fork } from "node:child_process";
2
+ import { safeFailureSummary } from "../../telemetry/failure-summary.js";
2
3
  function diagnosticToken(value, pattern) {
3
4
  return typeof value === "string" && pattern.test(value) ? value : undefined;
4
5
  }
@@ -10,6 +11,7 @@ function safeDiagnostics(value) {
10
11
  const remote_error_code = diagnosticToken(record.remote_error_code, /^(?:-?\d{1,16}|[A-Z][A-Z0-9_.:-]{0,79})$/u);
11
12
  const diagnostic_reason = diagnosticToken(record.diagnostic_reason, /^[A-Z][A-Z0-9_]{0,79}$/u);
12
13
  const failure_stage = diagnosticToken(record.failure_stage, /^[a-z][a-z0-9_.-]{0,79}$/u);
14
+ const diagnostic_summary = safeFailureSummary(record.diagnostic_summary);
13
15
  const http_status = typeof record.http_status === "number" && Number.isInteger(record.http_status)
14
16
  && record.http_status >= 100 && record.http_status <= 599 ? record.http_status : undefined;
15
17
  const causes = Array.isArray(record.causes) ? record.causes.slice(0, 10).flatMap(cause => {
@@ -23,6 +25,7 @@ function safeDiagnostics(value) {
23
25
  return {
24
26
  ...(error_type ? { error_type } : {}), ...(http_status === undefined ? {} : { http_status }),
25
27
  ...(remote_error_code ? { remote_error_code } : {}), ...(diagnostic_reason ? { diagnostic_reason } : {}),
28
+ ...(diagnostic_summary ? { diagnostic_summary } : {}),
26
29
  ...(failure_stage ? { failure_stage } : {}), ...(causes?.length ? { causes } : {})
27
30
  };
28
31
  }
@@ -35,7 +38,8 @@ export function taskWorkerDiagnostics(error, classification, failureStage) {
35
38
  }
36
39
  return safeDiagnostics({ error_type: error instanceof Error ? error.name : typeof error,
37
40
  http_status: classification.httpStatus, remote_error_code: classification.remoteErrorCode,
38
- diagnostic_reason: classification.diagnosticReason, failure_stage: failureStage, causes }) ?? {};
41
+ diagnostic_reason: classification.diagnosticReason, diagnostic_summary: classification.diagnosticSummary,
42
+ failure_stage: failureStage, causes }) ?? {};
39
43
  }
40
44
  function diagnosticCause(diagnostics) {
41
45
  let cause;
@@ -2,7 +2,7 @@ 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";
5
+ import { isContentReviewRejection } from "./creation-refusal.js";
6
6
  import { RemoteRequestError } from "../../platform/signed-http-transport.js";
7
7
  import { RemoteProtocolError } from "../../platform/remote-protocol.js";
8
8
  export class TaskNotFoundError extends Error {
@@ -88,6 +88,7 @@ export function createTaskUseCases(dependencies) {
88
88
  ...(state === "completed" && record.task.result ? { result_types: resultTypes(record.task.result) } : {}) };
89
89
  };
90
90
  let event;
91
+ let writeConfirmed = false;
91
92
  try {
92
93
  const updated = await stage("telemetry.task", () => dependencies.store.update(scope, record.task.taskId, stored => {
93
94
  stored.telemetry ??= { context };
@@ -100,6 +101,7 @@ export function createTaskUseCases(dependencies) {
100
101
  }));
101
102
  if (updated.telemetry)
102
103
  record.telemetry = updated.telemetry;
104
+ writeConfirmed = true;
103
105
  }
104
106
  catch {
105
107
  const states = record.telemetry.states ??= [];
@@ -107,8 +109,10 @@ export function createTaskUseCases(dependencies) {
107
109
  if (event && !states.some(e => e.task_revision === event.task_revision))
108
110
  states.push(event);
109
111
  }
110
- if (event)
112
+ if (event) {
113
+ telemetry.annotate({ task_state_revision: event.task_revision, task_state_write_confirmed: writeConfirmed });
111
114
  await telemetry.emit(event);
115
+ }
112
116
  }
113
117
  async function replay(record) {
114
118
  // Old request_sent/result_ready records are readable, but are never emitted by this binary.
@@ -259,7 +263,7 @@ export function createTaskUseCases(dependencies) {
259
263
  clearInterval(timer);
260
264
  if (record.task.state !== "completed") {
261
265
  const mayBeRunning = dispatched || record.progress.submissionStarted;
262
- const auditRejected = error instanceof AgentAuditRejectedError;
266
+ const auditRejected = isContentReviewRejection(error);
263
267
  const creditsRejected = (error instanceof RemoteRequestError || error instanceof RemoteProtocolError)
264
268
  && error.remoteCode === "12020770";
265
269
  const confirmedFailure = error instanceof ToolTaskFailedError || auditRejected || creditsRejected;
@@ -3,12 +3,13 @@ import * as nodeFileSystem from "node:fs/promises";
3
3
  import { join, resolve } from "node:path";
4
4
  import { setTimeout as delay } from "node:timers/promises";
5
5
  const localTurns = new Map();
6
+ const lockTimeout = () => Object.assign(new Error("Local state lock timed out."), { code: "LOCAL_LOCK_TIMEOUT" });
6
7
  /** Same-process waiters queue before creating bakery owners. Separate processes
7
8
  * still coordinate through unique owner files and retain the two-second budget. */
8
9
  export async function withFileLock(path, run, options = {}) {
9
10
  const deadline = Math.min(options.deadline ?? Infinity, Date.now() + 2_000);
10
11
  if (Date.now() >= deadline)
11
- throw new Error("Local state lock timed out.");
12
+ throw lockTimeout();
12
13
  const key = resolve(path);
13
14
  const previous = localTurns.get(key) ?? Promise.resolve();
14
15
  let release;
@@ -18,7 +19,7 @@ export async function withFileLock(path, run, options = {}) {
18
19
  let timer;
19
20
  try {
20
21
  await new Promise((ready, reject) => {
21
- timer = setTimeout(() => reject(new Error("Local state lock timed out.")), Math.max(0, deadline - Date.now()));
22
+ timer = setTimeout(() => reject(lockTimeout()), Math.max(0, deadline - Date.now()));
22
23
  void previous.then(ready);
23
24
  });
24
25
  clearTimeout(timer);
@@ -38,7 +39,7 @@ async function acquireFileLock(path, run, options) {
38
39
  const { mkdir, open, readFile, readdir, unlink, chmod, rename } = fileSystem;
39
40
  const deadline = Math.min(options.deadline ?? Infinity, Date.now() + 2_000);
40
41
  if (Date.now() >= deadline)
41
- throw new Error("Local state lock timed out.");
42
+ throw lockTimeout();
42
43
  const directory = `${path}.d`;
43
44
  await mkdir(directory, { recursive: true, mode: 0o700 });
44
45
  await chmod(directory, 0o700);
@@ -91,12 +92,12 @@ async function acquireFileLock(path, run, options) {
91
92
  await handle.close();
92
93
  for (;;) {
93
94
  if (Date.now() >= deadline)
94
- throw new Error("Local state lock timed out.");
95
+ throw lockTimeout();
95
96
  const waiting = (await contenders()).some(owner => owner.name !== name
96
97
  && (owner.ticket === null || owner.ticket < ticket || (owner.ticket === ticket && owner.name < name)));
97
98
  if (!waiting) {
98
99
  if (Date.now() >= deadline)
99
- throw new Error("Local state lock timed out.");
100
+ throw lockTimeout();
100
101
  return await run();
101
102
  }
102
103
  await delay(10);
@@ -0,0 +1,20 @@
1
+ const flags = new Set(["bodyUsedAtReceipt", "bodyLockedAtReceipt", "bodyUsedBeforeRead",
2
+ "bodyLockedBeforeRead", "reusedResponse", "contextIdPresent", "streamHadBytes"]);
3
+ const counts = new Set(["messageCount", "invalidMessageCount", "systemErrorCount", "publicPartCount",
4
+ "streamPayloadCount", "streamJsonValueCount"]);
5
+ /** Fixed diagnostic facts, never arbitrary response fields or error messages. */
6
+ export function safeFailureSummary(value) {
7
+ if (!value || typeof value !== "object" || Array.isArray(value))
8
+ return undefined;
9
+ const result = {};
10
+ for (const [key, field] of Object.entries(value)) {
11
+ if (flags.has(key) && typeof field === "boolean")
12
+ result[key] = field;
13
+ if (counts.has(key) && typeof field === "number" && Number.isSafeInteger(field) && field >= 0 && field <= 100_000)
14
+ result[key] = field;
15
+ if (key === "systemCode" && typeof field === "string"
16
+ && /^(?:E[A-Z0-9_]{1,40}|UND_ERR_[A-Z0-9_]{1,40}|LOCAL_LOCK_TIMEOUT)$/u.test(field))
17
+ result[key] = field;
18
+ }
19
+ return Object.keys(result).length ? result : undefined;
20
+ }
@@ -38,6 +38,7 @@ export function createTelemetryInvocation(options) {
38
38
  ...(c.httpStatus === undefined ? {} : { http_status: c.httpStatus }),
39
39
  ...(c.remoteErrorCode === undefined ? {} : { remote_error_code: c.remoteErrorCode }),
40
40
  ...(c.remoteErrorBody === undefined ? {} : { remote_error_body: c.remoteErrorBody }),
41
+ ...(c.diagnosticSummary === undefined ? {} : { diagnostic_summary: c.diagnosticSummary }),
41
42
  ...(c.diagnosticReason === undefined ? {} : { diagnostic_reason: c.diagnosticReason }) };
42
43
  }
43
44
  function failureStage(error) {
@@ -80,7 +81,7 @@ export function createTelemetryInvocation(options) {
80
81
  }
81
82
  },
82
83
  creationContext() {
83
- const { record_seq: _seq, occurred_at_ms: _time, parameters: _parameters, warning_codes: _warnings, invalid_model_count: _invalidModels, content_id: _content, task_id: _task, dify_task_id: _dify, result_state: _state, ...snapshot } = base();
84
+ const { record_seq: _seq, occurred_at_ms: _time, parameters: _parameters, warning_codes: _warnings, invalid_model_count: _invalidModels, task_state_revision: _revision, task_state_write_confirmed: _written, sls_enqueue_failures: _queueFailures, sls_last_enqueue_error: _queueError, content_id: _content, task_id: _task, dify_task_id: _dify, result_state: _state, ...snapshot } = base();
84
85
  return cleanDiagnostic({ ...snapshot, mode: "execute" });
85
86
  },
86
87
  async emit(event) { await publish(remember(event)); },
@@ -91,6 +92,7 @@ export function createTelemetryInvocation(options) {
91
92
  ...(c.errorCode === undefined ? {} : { error_code: c.errorCode }),
92
93
  ...(c.httpStatus === undefined ? {} : { http_status: c.httpStatus }),
93
94
  ...(c.remoteErrorCode === undefined ? {} : { remote_error_code: c.remoteErrorCode }),
95
+ ...(c.diagnosticSummary === undefined ? {} : { diagnostic_summary: c.diagnosticSummary }),
94
96
  ...(c.diagnosticReason === undefined && c.outcome !== "interrupted" ? {} : { diagnostic_reason: c.diagnosticReason ?? "LOCAL_WAIT_INTERRUPTED" }),
95
97
  ...(failedAt === undefined ? {} : { failure_stage: failedAt }) };
96
98
  },
@@ -60,6 +60,8 @@ export function createSlsTelemetrySink(options) {
60
60
  const now = options.now ?? Date.now;
61
61
  const entries = new Map();
62
62
  let writes = Promise.resolve();
63
+ let enqueueFailures = 0;
64
+ let lastEnqueueError;
63
65
  const file = (id) => createLocalJsonFile({ directory: options.directory, filename: `${id}.json` });
64
66
  let exitDeadline = Infinity;
65
67
  const locked = (run, deadline) => options.directory
@@ -154,7 +156,11 @@ export function createSlsTelemetrySink(options) {
154
156
  await persist(id, { event: wireEvent(event), queuedAt: now(), nextAttempt: 0, attempts: 0 });
155
157
  }
156
158
  await trim(deadline);
157
- }, deadline)).catch(() => undefined);
159
+ }, deadline)).catch(error => {
160
+ enqueueFailures++;
161
+ lastEnqueueError = error instanceof Error && error.message === "Local state lock timed out." ? "lock_timeout"
162
+ : error instanceof Error && error.message === "Telemetry delivery budget exhausted." ? "budget_exhausted" : "storage_error";
163
+ });
158
164
  if (options.background && deadline === undefined)
159
165
  void writes.then(() => { if (!sending)
160
166
  void start(Math.min(Date.now() + BUDGET, exitDeadline)); });
@@ -223,6 +229,9 @@ export function createSlsTelemetrySink(options) {
223
229
  return sending;
224
230
  }
225
231
  return { enqueue,
232
+ // This snapshot describes enqueue attempts before final flush, not SLS acceptance.
233
+ diagnostics: () => ({ sls_enqueue_failures: enqueueFailures,
234
+ ...(lastEnqueueError ? { sls_last_enqueue_error: lastEnqueueError } : {}) }),
226
235
  async send(events) {
227
236
  const deadline = exitDeadline = Date.now() + BUDGET;
228
237
  await enqueue(events, deadline);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insmind/cli",
3
- "version": "1.5.11",
3
+ "version": "1.5.12",
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": "0bb51526a839bba7a6ef04e51a765c16ad732926",
50
- "pipelineId": "214012",
51
- "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/214012"
49
+ "sourceCommit": "677a158421a331a863e725e8352b2fa65d6f50e8",
50
+ "pipelineId": "219692",
51
+ "pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/219692"
52
52
  }
53
53
  }