@insmind/cli 1.9.1 → 2.1.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.
Files changed (66) hide show
  1. package/README.md +5 -0
  2. package/contracts/operations/credits.get/input.schema.json +8 -0
  3. package/contracts/operations/credits.get/output.schema.json +92 -0
  4. package/contracts/operations/credits.usage.get/input.schema.json +17 -0
  5. package/contracts/operations/credits.usage.get/output.schema.json +46 -0
  6. package/contracts/operations/credits.usage.list/input.schema.json +27 -0
  7. package/contracts/operations/credits.usage.list/output.schema.json +135 -0
  8. package/dist/bin/insmind-cli.js +2 -2
  9. package/dist/src/bootstrap/create-cli.js +28 -24
  10. package/dist/src/bootstrap/create-runtime.js +31 -18
  11. package/dist/src/bootstrap/run-task-worker.js +2 -1
  12. package/dist/src/bootstrap/validators.js +7 -2
  13. package/dist/src/cli/action-binding.js +42 -13
  14. package/dist/src/cli/agent-commands.js +8 -12
  15. package/dist/src/cli/credits-command.js +127 -16
  16. package/dist/src/cli/dam-commands.js +3 -2
  17. package/dist/src/cli/editor-commands.js +10 -5
  18. package/dist/src/cli/host-input.js +34 -0
  19. package/dist/src/cli/model-commands.js +4 -3
  20. package/dist/src/cli/presenter.js +4 -0
  21. package/dist/src/cli/tool-commands.js +7 -9
  22. package/dist/src/cli/update-command.js +24 -1
  23. package/dist/src/contracts/creation-input.js +20 -0
  24. package/dist/src/features/agent/creative-protocol.js +12 -14
  25. package/dist/src/features/agent/use-cases.js +6 -31
  26. package/dist/src/features/auth/access-policy.js +1 -3
  27. package/dist/src/features/auth/sso-service.js +6 -4
  28. package/dist/src/features/auth/use-cases.js +2 -1
  29. package/dist/src/features/credits/amount.js +51 -0
  30. package/dist/src/features/credits/response.js +11 -0
  31. package/dist/src/features/credits/use-cases.js +174 -31
  32. package/dist/src/features/dam/file-downloader.js +2 -1
  33. package/dist/src/features/dam/use-cases.js +7 -7
  34. package/dist/src/features/editor/bridge-client.js +1 -1
  35. package/dist/src/features/editor/use-cases.js +6 -8
  36. package/dist/src/features/org/use-cases.js +3 -3
  37. package/dist/src/features/skill/installer.js +24 -22
  38. package/dist/src/features/task/store.js +26 -12
  39. package/dist/src/features/task/use-cases.js +97 -82
  40. package/dist/src/features/tool/canvas-models.js +21 -4
  41. package/dist/src/features/tool/canvas-tool-adapter.js +29 -20
  42. package/dist/src/features/tool/canvas-video.js +2 -4
  43. package/dist/src/features/tool/dynamic-schema.js +29 -64
  44. package/dist/src/features/tool/mns-catalog-adapter.js +9 -2
  45. package/dist/src/features/tool/scene-catalog-adapter.js +0 -1
  46. package/dist/src/features/tool/tool-api-adapter.js +2 -2
  47. package/dist/src/features/tool/use-cases.js +24 -35
  48. package/dist/src/features/update/check-schema.js +17 -0
  49. package/dist/src/features/update/host-receipt.js +30 -0
  50. package/dist/src/features/update/notice-output.js +30 -0
  51. package/dist/src/features/update/update-lock.js +80 -0
  52. package/dist/src/features/update/update-notification.js +129 -240
  53. package/dist/src/platform/json-input.js +1 -1
  54. package/dist/src/platform/safe-upload-file.js +6 -0
  55. package/dist/src/platform/signature.js +3 -1
  56. package/dist/src/platform/signed-http-transport.js +34 -32
  57. package/dist/src/telemetry/host-diagnostics.js +2 -2
  58. package/dist/src/telemetry/invocation.js +87 -24
  59. package/dist/src/telemetry/process-errors.js +36 -3
  60. package/dist/src/telemetry/sls-sink.js +7 -10
  61. package/package.json +4 -4
  62. package/skills/insmind-cli/SKILL.md +2 -0
  63. package/skills/insmind-cli/references/editor.md +1 -1
  64. package/skills/insmind-cli/references/generation-constraints.md +3 -1
  65. package/skills/insmind-cli/references/tool.md +2 -3
  66. package/skills/insmind-cli/references/update.md +2 -0
package/README.md CHANGED
@@ -7,8 +7,13 @@ npm install --global --allow-scripts=@insmind/cli @insmind/cli
7
7
  insmind-cli auth login
8
8
  insmind-cli --help
9
9
  insmind-cli editor apply --schema
10
+ insmind-cli credits --json
11
+ insmind-cli credits usage list --help
12
+ insmind-cli credits usage get --schema
10
13
  ```
11
14
 
12
15
  Requires Node.js 20 or newer. Credentials and local runtime state are stored separately from GaoDing CLI under `~/.insmind`.
13
16
 
17
+ `credits` reads the current balance; `credits usage list` returns one page of consumption, restoration, recycling and expiry records. `credits usage get <record-id>` reads source breakdown. Each supports offline `--schema` discovery without login. Records default to the current UTC month. Continue using the returned range and `nextCursor`; a page is not a complete spending total. Member period limits are shown separately from the overview balance.
18
+
14
19
  Discover command behavior with `--help`, structured input through supported `--schema` modes, and live model parameters through `model list` and `model get`. `editor apply --schema` reads the installed Action contract without login or an Editor connection; it cannot be combined with execution via `--input`.
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.insmind.com/operations/credits.get/input.schema.json",
4
+ "title": "CreditsGetInput",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "properties": {}
8
+ }
@@ -0,0 +1,92 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.insmind.com/operations/credits.get/output.schema.json",
4
+ "title": "CreditsResult",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "credits"
9
+ ],
10
+ "properties": {
11
+ "credits": {
12
+ "type": "object",
13
+ "additionalProperties": false,
14
+ "required": [
15
+ "unit",
16
+ "total",
17
+ "used",
18
+ "pending",
19
+ "available"
20
+ ],
21
+ "properties": {
22
+ "unit": {
23
+ "type": "string",
24
+ "const": "credit"
25
+ },
26
+ "total": {
27
+ "type": "number",
28
+ "minimum": 0,
29
+ "maximum": 9007199254740991
30
+ },
31
+ "used": {
32
+ "type": "number",
33
+ "minimum": 0,
34
+ "maximum": 9007199254740991
35
+ },
36
+ "pending": {
37
+ "type": "number",
38
+ "minimum": 0,
39
+ "maximum": 9007199254740991
40
+ },
41
+ "available": {
42
+ "type": "number",
43
+ "minimum": 0,
44
+ "maximum": 9007199254740991
45
+ }
46
+ }
47
+ },
48
+ "balances": {
49
+ "type": "array",
50
+ "items": {
51
+ "type": "object",
52
+ "additionalProperties": false,
53
+ "required": [
54
+ "total",
55
+ "used",
56
+ "pending",
57
+ "available"
58
+ ],
59
+ "properties": {
60
+ "identifier": {
61
+ "type": "string"
62
+ },
63
+ "total": {
64
+ "type": "number",
65
+ "minimum": 0,
66
+ "maximum": 9007199254740991
67
+ },
68
+ "used": {
69
+ "type": "number",
70
+ "minimum": 0,
71
+ "maximum": 9007199254740991
72
+ },
73
+ "pending": {
74
+ "type": "number",
75
+ "minimum": 0,
76
+ "maximum": 9007199254740991
77
+ },
78
+ "available": {
79
+ "type": "number",
80
+ "minimum": 0,
81
+ "maximum": 9007199254740991
82
+ },
83
+ "memberPeriodLimit": {
84
+ "type": "number",
85
+ "minimum": 0,
86
+ "maximum": 9007199254740991
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.insmind.com/operations/credits.usage.get/input.schema.json",
4
+ "title": "CreditsUsageGetInput",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "id"
9
+ ],
10
+ "properties": {
11
+ "id": {
12
+ "type": "string",
13
+ "minLength": 1,
14
+ "pattern": ".*\\S.*"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,46 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.insmind.com/operations/credits.usage.get/output.schema.json",
4
+ "title": "CreditsUsageGetResult",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "id",
9
+ "unit",
10
+ "breakdown"
11
+ ],
12
+ "properties": {
13
+ "id": {
14
+ "type": "string",
15
+ "minLength": 1,
16
+ "pattern": ".*\\S.*"
17
+ },
18
+ "unit": {
19
+ "type": "string",
20
+ "const": "credit"
21
+ },
22
+ "breakdown": {
23
+ "type": "array",
24
+ "items": {
25
+ "type": "object",
26
+ "additionalProperties": false,
27
+ "required": [
28
+ "amount"
29
+ ],
30
+ "properties": {
31
+ "amount": {
32
+ "type": "number",
33
+ "minimum": 0,
34
+ "maximum": 9007199254740991
35
+ },
36
+ "usageType": {
37
+ "type": "number"
38
+ },
39
+ "sourceType": {
40
+ "type": "string"
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.insmind.com/operations/credits.usage.list/input.schema.json",
4
+ "title": "CreditsUsageListInput",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "from": {
9
+ "type": "string",
10
+ "format": "date-time"
11
+ },
12
+ "to": {
13
+ "type": "string",
14
+ "format": "date-time"
15
+ },
16
+ "limit": {
17
+ "type": "integer",
18
+ "minimum": 1,
19
+ "default": 20
20
+ },
21
+ "cursor": {
22
+ "type": "string",
23
+ "minLength": 1,
24
+ "pattern": ".*\\S.*"
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,135 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.insmind.com/operations/credits.usage.list/output.schema.json",
4
+ "title": "CreditsUsageListResult",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "unit",
9
+ "range",
10
+ "items",
11
+ "hasMore",
12
+ "nextCursor"
13
+ ],
14
+ "properties": {
15
+ "unit": {
16
+ "type": "string",
17
+ "const": "credit"
18
+ },
19
+ "range": {
20
+ "type": "object",
21
+ "additionalProperties": false,
22
+ "required": [
23
+ "from",
24
+ "to"
25
+ ],
26
+ "properties": {
27
+ "from": {
28
+ "type": "string",
29
+ "format": "date-time"
30
+ },
31
+ "to": {
32
+ "type": "string",
33
+ "format": "date-time"
34
+ }
35
+ }
36
+ },
37
+ "items": {
38
+ "type": "array",
39
+ "items": {
40
+ "type": "object",
41
+ "additionalProperties": false,
42
+ "required": [
43
+ "id",
44
+ "changeType",
45
+ "amount",
46
+ "recordedAt"
47
+ ],
48
+ "properties": {
49
+ "id": {
50
+ "type": "string",
51
+ "minLength": 1,
52
+ "pattern": ".*\\S.*"
53
+ },
54
+ "changeType": {
55
+ "type": "string",
56
+ "minLength": 1,
57
+ "pattern": ".*\\S.*"
58
+ },
59
+ "amount": {
60
+ "type": "number",
61
+ "minimum": 0,
62
+ "maximum": 9007199254740991
63
+ },
64
+ "recordedAt": {
65
+ "type": "string",
66
+ "format": "date-time"
67
+ },
68
+ "recordMode": {
69
+ "type": "string"
70
+ },
71
+ "description": {
72
+ "type": "string"
73
+ },
74
+ "scene": {
75
+ "type": "number"
76
+ },
77
+ "referenceId": {
78
+ "type": "string"
79
+ },
80
+ "user": {
81
+ "type": "object",
82
+ "additionalProperties": false,
83
+ "properties": {
84
+ "id": {
85
+ "type": "string"
86
+ },
87
+ "name": {
88
+ "type": "string"
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
94
+ },
95
+ "hasMore": {
96
+ "type": "boolean"
97
+ },
98
+ "nextCursor": {
99
+ "type": [
100
+ "string",
101
+ "null"
102
+ ]
103
+ }
104
+ },
105
+ "allOf": [
106
+ {
107
+ "if": {
108
+ "properties": {
109
+ "hasMore": {
110
+ "const": true
111
+ }
112
+ },
113
+ "required": [
114
+ "hasMore"
115
+ ]
116
+ },
117
+ "then": {
118
+ "properties": {
119
+ "nextCursor": {
120
+ "type": "string",
121
+ "minLength": 1,
122
+ "pattern": ".*\\S.*"
123
+ }
124
+ }
125
+ },
126
+ "else": {
127
+ "properties": {
128
+ "nextCursor": {
129
+ "type": "null"
130
+ }
131
+ }
132
+ }
133
+ }
134
+ ]
135
+ }
@@ -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";
@@ -35,22 +35,19 @@ export function createCli(runtime, options) {
35
35
  writeErr: () => undefined
36
36
  });
37
37
  program.addHelpText("after", runtime.product.id === "insmind"
38
- ? "\nstdout contains command results; stderr contains progress, warnings and errors. Fixed JSON commands, --json and --json-errors use {error:{code,message,details?,trace_id?}} for final errors. stderr may contain multiple messages.\nExit codes: 0 success, 1 execution failure, 2 invalid input, 130 local interruption; dispatched work may still be active.\n"
39
- : "\nstdout 输出命令结果;stderr 输出进度、警告和错误。固定 JSON 命令、--json 和 --json-errors 的最终错误使用 {error:{code,message,details?,trace_id?}},stderr 可能包含多条信息。\n退出码:0 成功,1 执行失败,2 输入无效,130 本地中断;已派发的工作可能仍在继续。\n");
38
+ ? "\nstdout contains command results; human-readable views can include an update notice. stderr contains progress, warnings and errors. Fixed JSON commands, --json and --json-errors use {error:{code,message,details?,trace_id?}} for final errors. stderr may contain multiple messages.\nExit codes: 0 success, 1 execution failure, 2 invalid input, 130 local interruption; dispatched work may still be active.\n"
39
+ : "\nstdout 输出命令结果,人类可读视图可以附带升级提醒;stderr 输出进度、警告和错误。固定 JSON 命令、--json 和 --json-errors 的最终错误使用 {error:{code,message,details?,trace_id?}},stderr 可能包含多条信息。\n退出码:0 成功,1 执行失败,2 输入无效,130 本地中断;已派发的工作可能仍在继续。\n");
40
40
  if (runtime.product.id === "insmind") {
41
41
  program.option("--locale <locale>", "locale for service-owned business descriptions");
42
42
  }
43
43
  configureActionEnvironment(program, {
44
44
  policies: runtime.accessPolicies,
45
45
  signal: options.signal,
46
- telemetry: runtime.telemetry,
47
- updateNotification: runtime.updateNotification
46
+ telemetry: runtime.telemetry
48
47
  });
49
48
  registerAuthCommands(program, runtime);
50
49
  if (runtime.product.exposesOrganizations)
51
50
  registerOrgCommands(program, runtime);
52
- else
53
- registerCreditsCommand(program, runtime);
54
51
  registerAgentCommands(program, runtime);
55
52
  registerToolCommands(program, runtime);
56
53
  registerModelCommands(program, runtime);
@@ -58,6 +55,7 @@ export function createCli(runtime, options) {
58
55
  registerDamCommands(program, runtime);
59
56
  registerUpdateCommand(program, runtime);
60
57
  registerTaskCommands(program, runtime);
58
+ registerCreditsCommand(program, runtime);
61
59
  assertAllLeafCommandsBound(program);
62
60
  outputs.set(program, runtime);
63
61
  if (runtime.analytics)
@@ -65,13 +63,11 @@ export function createCli(runtime, options) {
65
63
  return program;
66
64
  }
67
65
  export async function executeCli(options) {
68
- let helpOnly = false;
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
- }
66
+ const definition = invocationDefinition(options.program, options.argv);
67
+ await options.telemetry.issue(definition);
68
+ const automaticNotice = definition.operation !== "update" && !definition.operation.startsWith("update.");
69
+ let informational = false;
70
+ let help = false;
75
71
  try {
76
72
  try {
77
73
  await options.program.parseAsync(options.argv, { from: "user" });
@@ -79,15 +75,17 @@ export async function executeCli(options) {
79
75
  catch (error) {
80
76
  if (!isHelpOutcome(error))
81
77
  throw error;
82
- helpOnly = true;
83
- if (options.argv[0] !== "update")
84
- await checkUpdateNotification(options.updateNotification, options.signal);
78
+ informational = true;
79
+ help = error instanceof CommanderError && error.code === "commander.helpDisplayed";
85
80
  options.signal.throwIfAborted();
86
81
  }
87
82
  await options.telemetry.stage("output", async () => { await outputs.get(options.program)?.io.flush?.(); });
88
83
  await outputs.get(options.program)?.tasks.outputCompleted();
89
- if (!helpOnly)
90
- await sendFinished(options, { outcome: "success" });
84
+ if (automaticNotice)
85
+ await checkUpdateNotification(options.updateNotification, options.signal, help || options.presenter.humanResult ? "text" : "machine");
86
+ if (informational)
87
+ options.signal.throwIfAborted();
88
+ await sendFinished(options, { outcome: "success" });
91
89
  return 0;
92
90
  }
93
91
  catch (error) {
@@ -123,16 +121,23 @@ export async function executeCli(options) {
123
121
  const traceId = options.telemetry.selected
124
122
  ? options.telemetry.traceId
125
123
  : undefined;
124
+ let errorDelivered = false;
126
125
  try {
127
126
  options.presenter.error(outcome, {
128
127
  json: errorUsesJson(options.program, options.argv),
129
128
  ...(traceId ? { traceId } : {})
130
129
  });
130
+ await outputs.get(options.program)?.io.flush?.();
131
+ errorDelivered = true;
131
132
  }
132
133
  catch (presenterError) {
133
134
  await options.telemetry.stage("output", () => { throw presenterError; }).catch(() => undefined);
134
135
  }
135
- await options.telemetry.stage("output", async () => { await outputs.get(options.program)?.io.flush?.(); }).catch(() => undefined);
136
+ if (errorDelivered)
137
+ await outputs.get(options.program)?.tasks.outputCompleted(error);
138
+ if (errorDelivered && automaticNotice && outcome.exitCode === 1 && definition.operation !== "unknown") {
139
+ await checkUpdateNotification(options.updateNotification, options.signal, "machine");
140
+ }
136
141
  await sendFinished(options, outcome.kind === "interrupted"
137
142
  ? { outcome: "interrupted", error }
138
143
  : {
@@ -153,9 +158,9 @@ export async function executeCli(options) {
153
158
  return outcome.exitCode;
154
159
  }
155
160
  }
156
- async function checkUpdateNotification(updateNotification, signal) {
161
+ async function checkUpdateNotification(updateNotification, signal, output) {
157
162
  try {
158
- await updateNotification.check(signal);
163
+ await updateNotification.check(signal, output);
159
164
  }
160
165
  catch {
161
166
  // Version availability must never change the requested command outcome.
@@ -166,6 +171,5 @@ async function sendFinished(options, completion) {
166
171
  await options.telemetrySink.refreshDiagnostics?.().catch(() => undefined);
167
172
  options.telemetry.annotate(options.telemetrySink.diagnostics?.() ?? {});
168
173
  const events = options.telemetry.finish(completion);
169
- if (events.length > 0)
170
- await options.telemetrySink.send(events).catch(() => undefined);
174
+ await options.telemetrySink.send(events).catch(() => undefined);
171
175
  }
@@ -1,9 +1,10 @@
1
1
  import { createWindAnalytics } from "../analytics/wind.js";
2
2
  import { taskScope } from "../features/task/store.js";
3
+ import { noticeWriter, sameTerminal } from "../features/update/notice-output.js";
3
4
  import { createTextOutput } from "../platform/text-output.js";
4
5
  import { TaskNotFoundError } from "../features/task/use-cases.js";
5
6
  import { homedir } from "node:os";
6
- import { createTaskBackgroundLauncher } from "../features/task/task-background.js";
7
+ import { createTaskBackgroundLauncher, TaskBackgroundError } from "../features/task/task-background.js";
7
8
  import { createTaskStore } from "../features/task/store.js";
8
9
  import { createTaskUseCases } from "../features/task/use-cases.js";
9
10
  import { readAgentResult } from "../features/agent/result-reader.js";
@@ -93,14 +94,15 @@ export function createProductionRuntime(options = {}) {
93
94
  const telemetrySink = options.telemetrySink ?? createSlsTelemetrySink({
94
95
  fetch, trackingUrl: options.telemetryTrackingUrl ?? product.telemetryUrl,
95
96
  background: options.telemetryBackground ?? true,
96
- directory: join(options.homeDirectory ?? homedir(), product.stateDirectory, "telemetry"),
97
+ directory: join(options.homeDirectory ?? homedir(), product.stateDirectory, "telemetry", "v6"),
97
98
  now: () => now().getTime()
98
99
  });
99
100
  const telemetry = createTelemetryInvocation({
100
- cliVersion: primarySkill.version, cliName: product.commandName, env: telemetryEnvironment,
101
+ ...(options.invocationStartedAt === undefined ? {} : { startedAt: options.invocationStartedAt }),
102
+ cliVersion: options.telemetryVersion ?? primarySkill.version, cliName: product.commandName, env: telemetryEnvironment,
101
103
  processRole: options.processRole ?? "cli",
102
104
  now: () => now().getTime(),
103
- traceIdFactory: () => randomBytes(16).toString("hex"),
105
+ traceIdFactory: () => options.invocationTraceId ?? randomBytes(16).toString("hex"),
104
106
  spanIdFactory: () => randomBytes(8).toString("hex"),
105
107
  runtime: { os: process.platform, arch: process.arch, nodeMajor: Number.parseInt(process.versions.node, 10) },
106
108
  classifyError: error => classifyTelemetryError(error, { product, operation: telemetry.creationContext().operation, failureStage: telemetry.failureStage(error) }),
@@ -212,7 +214,8 @@ export function createProductionRuntime(options = {}) {
212
214
  });
213
215
  const credits = createCreditsUseCases({
214
216
  transport: creditsTransport,
215
- billingUnit: product.billingUnit
217
+ billingUnit: product.billingUnit,
218
+ now
216
219
  });
217
220
  const storageUpload = createDamStorageUploader({
218
221
  transport: damTransport,
@@ -332,6 +335,7 @@ export function createProductionRuntime(options = {}) {
332
335
  store: createTaskStore({
333
336
  ...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {}),
334
337
  stateDirectory: product.stateDirectory,
338
+ validateSummary: task => validators.taskListResult({ tasks: [task] }),
335
339
  validate: validators.taskResult
336
340
  }),
337
341
  idFactory: randomUUID,
@@ -427,7 +431,6 @@ export function createProductionRuntime(options = {}) {
427
431
  }
428
432
  });
429
433
  const agent = withAgentBillingUnit(createAgentUseCases({
430
- catalog: modelCatalog,
431
434
  uploader: transientUploader,
432
435
  completion: createCreativeAgentAdapter({
433
436
  transport: agentTransport,
@@ -435,7 +438,6 @@ export function createProductionRuntime(options = {}) {
435
438
  idFactory: randomUUID,
436
439
  telemetry
437
440
  }),
438
- warn: (message) => { presenter.warning(message); },
439
441
  telemetry
440
442
  }), product.billingUnit);
441
443
  const canvasMedia = createCanvasMedia({ fetch, uploader: transientUploader });
@@ -504,7 +506,8 @@ export function createProductionRuntime(options = {}) {
504
506
  installationOwner,
505
507
  ...(options.homeDirectory ? { homeDirectory: options.homeDirectory } : {}),
506
508
  ...(options.env ? { env: options.env } : {}),
507
- notify: (message) => { presenter.notice(message); },
509
+ diagnosticOnly: !io.stderrTerminal && env.CLI_UPDATE_NOTICE_FORMAT !== "offer",
510
+ notify: noticeWriter(stdout, stderr, sameTerminal(rawIo.stdout, rawIo.stderr), env.CLI_UPDATE_NOTICE_FORMAT === "offer", text("提示: ", "Notice: ")),
508
511
  ...(product.id === "insmind" ? {
509
512
  stateDirectoryName: product.stateDirectory,
510
513
  registryUrl: `https://registry.npmjs.org/${encodeURIComponent(product.npmPackage)}`,
@@ -522,16 +525,26 @@ export function createProductionRuntime(options = {}) {
522
525
  org,
523
526
  agent,
524
527
  tasks,
525
- startBackgroundTask: (input, signal) => (options.taskBackground ?? createTaskBackgroundLauncher({
526
- workerPath: join(packageRoot, "dist", "bin", "task-worker.js"), env
527
- })).submit({ ...input, product: product.id, homeDirectory: options.homeDirectory ?? homedir(),
528
- telemetryEnvironment, telemetryVersion: primarySkill.version,
529
- telemetryTrackingUrl: String(options.telemetryTrackingUrl ?? product.telemetryUrl),
530
- locale: locale.locale, endpoints: Object.fromEntries(Object.entries(endpoints).map(([key, value]) => [key, String(value)]))
531
- }, signal, task => {
532
- telemetry.annotate({ cli_task_id: task.taskId, execution_mode: "async", result_state: task.state });
533
- 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}`));
534
- }),
528
+ async startBackgroundTask(input, signal) {
529
+ let startedId;
530
+ const launcher = options.taskBackground ?? createTaskBackgroundLauncher({ workerPath: join(packageRoot, "dist", "bin", "task-worker.js"), env });
531
+ try {
532
+ return await launcher.submit({ ...input, product: product.id, homeDirectory: options.homeDirectory ?? homedir(),
533
+ telemetryEnvironment, telemetryVersion: options.telemetryVersion ?? primarySkill.version, origin: telemetry.creationContext(),
534
+ telemetryTrackingUrl: String(options.telemetryTrackingUrl ?? product.telemetryUrl),
535
+ locale: locale.locale, endpoints: Object.fromEntries(Object.entries(endpoints).map(([key, value]) => [key, String(value)]))
536
+ }, signal, task => {
537
+ startedId = task.taskId;
538
+ telemetry.annotate({ cli_task_id: task.taskId, execution_mode: "async", result_state: task.state });
539
+ 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}`));
540
+ });
541
+ }
542
+ catch (error) {
543
+ if (startedId)
544
+ await tasks.workerStopped(input.state, startedId, error, error instanceof TaskBackgroundError).catch(() => undefined);
545
+ throw error;
546
+ }
547
+ },
535
548
  editor,
536
549
  dam,
537
550
  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(agentSendInputSchema);
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);
@@ -121,6 +123,9 @@ export function createContractValidators(options = {}) {
121
123
  const taskResult = ajv.compile(runOutputSchema);
122
124
  const taskListResult = ajv.compile(contractSchema("task.list", "output"));
123
125
  return {
126
+ creditsOutput: assertion(ajv.compile(contractSchema("credits.get", "output")), OutputContractError),
127
+ creditsUsageListOutput: assertion(ajv.compile(contractSchema("credits.usage.list", "output")), OutputContractError),
128
+ creditsUsageGetOutput: assertion(ajv.compile(contractSchema("credits.usage.get", "output")), OutputContractError),
124
129
  taskResult: assertion(taskResult, OutputContractError),
125
130
  taskListResult: assertion(taskListResult, OutputContractError),
126
131
  agentSendInput: assertion(agentSendInput, InputContractError),