@insmind/cli 1.3.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 (153) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/contracts/operations/agent.send/input.schema.json +335 -0
  4. package/contracts/operations/agent.send/output.schema.json +248 -0
  5. package/contracts/operations/auth.status/input.schema.json +7 -0
  6. package/contracts/operations/auth.status/output.schema.json +119 -0
  7. package/contracts/operations/dam.copy/input.schema.json +42 -0
  8. package/contracts/operations/dam.copy/output.schema.json +43 -0
  9. package/contracts/operations/dam.delete/input.schema.json +24 -0
  10. package/contracts/operations/dam.delete/output.schema.json +5 -0
  11. package/contracts/operations/dam.download/input.schema.json +28 -0
  12. package/contracts/operations/dam.download/output.schema.json +51 -0
  13. package/contracts/operations/dam.folder.list/input.schema.json +36 -0
  14. package/contracts/operations/dam.folder.list/output.schema.json +104 -0
  15. package/contracts/operations/dam.get/input.schema.json +16 -0
  16. package/contracts/operations/dam.get/output.schema.json +107 -0
  17. package/contracts/operations/dam.list/input.schema.json +73 -0
  18. package/contracts/operations/dam.list/output.schema.json +145 -0
  19. package/contracts/operations/dam.move/input.schema.json +42 -0
  20. package/contracts/operations/dam.move/output.schema.json +40 -0
  21. package/contracts/operations/dam.rename/input.schema.json +42 -0
  22. package/contracts/operations/dam.rename/output.schema.json +43 -0
  23. package/contracts/operations/dam.repository.list/input.schema.json +7 -0
  24. package/contracts/operations/dam.repository.list/output.schema.json +65 -0
  25. package/contracts/operations/dam.search/input.schema.json +79 -0
  26. package/contracts/operations/dam.search/output.schema.json +145 -0
  27. package/contracts/operations/dam.tag.list/input.schema.json +21 -0
  28. package/contracts/operations/dam.tag.list/output.schema.json +52 -0
  29. package/contracts/operations/dam.upload/input.schema.json +43 -0
  30. package/contracts/operations/dam.upload/output.schema.json +107 -0
  31. package/contracts/operations/editor.apply/input.schema.json +177 -0
  32. package/contracts/operations/editor.apply/output.schema.json +15 -0
  33. package/contracts/operations/editor.connect/input.schema.json +13 -0
  34. package/contracts/operations/editor.connect/output.schema.json +17 -0
  35. package/contracts/operations/editor.disconnect/input.schema.json +7 -0
  36. package/contracts/operations/editor.disconnect/output.schema.json +14 -0
  37. package/contracts/operations/editor.save/input.schema.json +7 -0
  38. package/contracts/operations/editor.save/output.schema.json +23 -0
  39. package/contracts/operations/editor.screenshot/input.schema.json +7 -0
  40. package/contracts/operations/editor.screenshot/output.schema.json +16 -0
  41. package/contracts/operations/editor.snapshot/input.schema.json +7 -0
  42. package/contracts/operations/editor.snapshot/output.schema.json +148 -0
  43. package/contracts/operations/model.get/input.schema.json +16 -0
  44. package/contracts/operations/model.get/output.schema.json +167 -0
  45. package/contracts/operations/model.list/input.schema.json +13 -0
  46. package/contracts/operations/model.list/output.schema.json +97 -0
  47. package/contracts/operations/task.get/input.schema.json +14 -0
  48. package/contracts/operations/task.get/output.schema.json +103 -0
  49. package/contracts/operations/task.list/input.schema.json +18 -0
  50. package/contracts/operations/task.list/output.schema.json +53 -0
  51. package/contracts/operations/tool.call/input.schema.json +31 -0
  52. package/contracts/operations/tool.call/output.schema.json +115 -0
  53. package/contracts/operations/tool.list/input.schema.json +6 -0
  54. package/contracts/operations/tool.list/output.schema.json +40 -0
  55. package/dist/bin/agent-worker.js +41 -0
  56. package/dist/bin/insmind-cli.js +60 -0
  57. package/dist/bin/postinstall.js +69 -0
  58. package/dist/src/bootstrap/create-cli.js +124 -0
  59. package/dist/src/bootstrap/create-runtime.js +451 -0
  60. package/dist/src/bootstrap/run-agent-worker.js +37 -0
  61. package/dist/src/bootstrap/validators.js +169 -0
  62. package/dist/src/cli/action-binding.js +109 -0
  63. package/dist/src/cli/agent-commands.js +75 -0
  64. package/dist/src/cli/auth-commands.js +58 -0
  65. package/dist/src/cli/credits-command.js +23 -0
  66. package/dist/src/cli/dam-commands.js +470 -0
  67. package/dist/src/cli/editor-commands.js +74 -0
  68. package/dist/src/cli/errors.js +208 -0
  69. package/dist/src/cli/model-commands.js +62 -0
  70. package/dist/src/cli/org-commands.js +58 -0
  71. package/dist/src/cli/presenter.js +123 -0
  72. package/dist/src/cli/prompt.js +30 -0
  73. package/dist/src/cli/task-commands.js +48 -0
  74. package/dist/src/cli/tool-commands.js +101 -0
  75. package/dist/src/cli/update-command.js +15 -0
  76. package/dist/src/contracts/schema.js +4 -0
  77. package/dist/src/features/agent/creative-agent-adapter.js +42 -0
  78. package/dist/src/features/agent/creative-protocol.js +421 -0
  79. package/dist/src/features/agent/creative-stream.js +138 -0
  80. package/dist/src/features/agent/filems-resource-auth-key-provider.js +23 -0
  81. package/dist/src/features/agent/resource-authorizer.js +47 -0
  82. package/dist/src/features/agent/result-reader.js +30 -0
  83. package/dist/src/features/agent/use-cases.js +153 -0
  84. package/dist/src/features/auth/access-policy.js +101 -0
  85. package/dist/src/features/auth/credential-store.js +62 -0
  86. package/dist/src/features/auth/sso-service.js +196 -0
  87. package/dist/src/features/auth/state.js +129 -0
  88. package/dist/src/features/auth/use-cases.js +162 -0
  89. package/dist/src/features/credits/use-cases.js +52 -0
  90. package/dist/src/features/dam/asset-projection.js +278 -0
  91. package/dist/src/features/dam/dam-api-adapter.js +562 -0
  92. package/dist/src/features/dam/file-downloader.js +242 -0
  93. package/dist/src/features/dam/object-storage.js +193 -0
  94. package/dist/src/features/dam/operation-executor.js +72 -0
  95. package/dist/src/features/dam/registered-uploader.js +247 -0
  96. package/dist/src/features/dam/repository-catalog.js +127 -0
  97. package/dist/src/features/dam/storage-upload.js +141 -0
  98. package/dist/src/features/dam/transient-uploader.js +17 -0
  99. package/dist/src/features/dam/use-cases.js +470 -0
  100. package/dist/src/features/editor/bridge-client.js +109 -0
  101. package/dist/src/features/editor/bridge-process.js +229 -0
  102. package/dist/src/features/editor/bridge-server.js +337 -0
  103. package/dist/src/features/editor/protocol.js +1 -0
  104. package/dist/src/features/editor/public-url.js +36 -0
  105. package/dist/src/features/editor/session-state.js +78 -0
  106. package/dist/src/features/editor/session.js +213 -0
  107. package/dist/src/features/editor/use-cases.js +88 -0
  108. package/dist/src/features/org/org-service.js +76 -0
  109. package/dist/src/features/org/use-cases.js +163 -0
  110. package/dist/src/features/skill/bundled-skills.js +63 -0
  111. package/dist/src/features/skill/installer.js +271 -0
  112. package/dist/src/features/task/agent-background.js +63 -0
  113. package/dist/src/features/task/store.js +97 -0
  114. package/dist/src/features/task/types.js +1 -0
  115. package/dist/src/features/task/use-cases.js +139 -0
  116. package/dist/src/features/tool/catalog.js +83 -0
  117. package/dist/src/features/tool/dynamic-schema.js +128 -0
  118. package/dist/src/features/tool/mns-catalog-adapter.js +265 -0
  119. package/dist/src/features/tool/tool-api-adapter.js +369 -0
  120. package/dist/src/features/tool/use-cases.js +180 -0
  121. package/dist/src/features/update/latest-version.js +37 -0
  122. package/dist/src/features/update/update-notification.js +271 -0
  123. package/dist/src/features/update/update-service.js +226 -0
  124. package/dist/src/platform/installation-owner.js +81 -0
  125. package/dist/src/platform/json-input.js +67 -0
  126. package/dist/src/platform/local-json-file.js +59 -0
  127. package/dist/src/platform/open-browser.js +8 -0
  128. package/dist/src/platform/redact.js +80 -0
  129. package/dist/src/platform/remote-error-evidence.js +80 -0
  130. package/dist/src/platform/remote-protocol.js +10 -0
  131. package/dist/src/platform/resource-auth-key.js +1 -0
  132. package/dist/src/platform/safe-upload-file.js +146 -0
  133. package/dist/src/platform/signature.js +20 -0
  134. package/dist/src/platform/signed-http-transport.js +144 -0
  135. package/dist/src/platform/task-observer.js +1 -0
  136. package/dist/src/platform/url-safety.js +100 -0
  137. package/dist/src/product/billing.js +47 -0
  138. package/dist/src/product/config.js +85 -0
  139. package/dist/src/product/locale.js +38 -0
  140. package/dist/src/product/text.js +3 -0
  141. package/dist/src/telemetry/invocation.js +156 -0
  142. package/dist/src/telemetry/sls-sink.js +30 -0
  143. package/package.json +53 -0
  144. package/skills/insmind-cli/SKILL.md +15 -0
  145. package/skills/insmind-cli/references/agent.md +34 -0
  146. package/skills/insmind-cli/references/auth.md +8 -0
  147. package/skills/insmind-cli/references/creation.md +40 -0
  148. package/skills/insmind-cli/references/dam.md +51 -0
  149. package/skills/insmind-cli/references/editor.md +184 -0
  150. package/skills/insmind-cli/references/errors.md +29 -0
  151. package/skills/insmind-cli/references/generation-constraints.md +36 -0
  152. package/skills/insmind-cli/references/tool.md +31 -0
  153. package/skills/insmind-cli/references/update.md +11 -0
@@ -0,0 +1,109 @@
1
+ const environments = new WeakMap();
2
+ const boundPolicies = new WeakMap();
3
+ export function configureActionEnvironment(program, environment) {
4
+ environments.set(program, environment);
5
+ }
6
+ export function bindAction(command, policy, handler, telemetry) {
7
+ if (boundPolicies.has(command))
8
+ throw new Error(`Action already bound: ${commandPath(command)}`);
9
+ boundPolicies.set(command, policy);
10
+ bindTelemetrySelection(command, telemetry);
11
+ command.action(async () => {
12
+ const environment = environments.get(rootCommand(command));
13
+ if (!environment)
14
+ throw new Error("CLI action environment is missing.");
15
+ await checkUpdateNotification(environment, telemetry);
16
+ const context = await environment.telemetry.stage("access", async () => {
17
+ const authorized = await environment.policies[policy].authorize(environment.signal);
18
+ if (authorized.policy !== policy) {
19
+ throw new Error("Access policy returned the wrong context.");
20
+ }
21
+ return authorized;
22
+ });
23
+ annotateAccessContext(environment.telemetry, context);
24
+ await handler(context, environment.signal);
25
+ });
26
+ }
27
+ export function bindPreparedAction(command, policy, prepare, run, telemetry) {
28
+ if (boundPolicies.has(command))
29
+ throw new Error(`Action already bound: ${commandPath(command)}`);
30
+ boundPolicies.set(command, policy);
31
+ bindTelemetrySelection(command, telemetry);
32
+ command.action(async () => {
33
+ const environment = environments.get(rootCommand(command));
34
+ if (!environment)
35
+ throw new Error("CLI action environment is missing.");
36
+ await checkUpdateNotification(environment, telemetry);
37
+ const prepared = await environment.telemetry.stage("input", () => prepare(environment.signal));
38
+ if (prepared.handled)
39
+ return;
40
+ const context = await environment.telemetry.stage("access", async () => {
41
+ const authorized = await environment.policies[policy].authorize(environment.signal);
42
+ if (authorized.policy !== policy) {
43
+ throw new Error("Access policy returned the wrong context.");
44
+ }
45
+ return authorized;
46
+ });
47
+ annotateAccessContext(environment.telemetry, context);
48
+ await run(context, prepared.input, environment.signal);
49
+ });
50
+ }
51
+ async function checkUpdateNotification(environment, telemetry) {
52
+ if (telemetry?.operation === "update")
53
+ return;
54
+ try {
55
+ await environment.updateNotification.check(environment.signal);
56
+ }
57
+ catch {
58
+ // Version availability must never change the requested command outcome.
59
+ }
60
+ }
61
+ export function assertAllLeafCommandsBound(program) {
62
+ for (const command of leafCommands(program)) {
63
+ if (!boundPolicies.has(command)) {
64
+ throw new Error(`Leaf command is missing an access policy: ${commandPath(command)}`);
65
+ }
66
+ }
67
+ }
68
+ function leafCommands(command) {
69
+ if (command.commands.length === 0)
70
+ return [command];
71
+ return command.commands.flatMap(leafCommands);
72
+ }
73
+ function rootCommand(command) {
74
+ let current = command;
75
+ while (current.parent)
76
+ current = current.parent;
77
+ return current;
78
+ }
79
+ function bindTelemetrySelection(command, definition) {
80
+ if (!definition)
81
+ return;
82
+ if (!command.parent)
83
+ throw new Error(`Telemetry command has no parent: ${command.name()}`);
84
+ command.parent.hook("preSubcommand", (parent, selected) => {
85
+ if (selected !== command)
86
+ return;
87
+ const environment = environments.get(rootCommand(parent));
88
+ if (!environment)
89
+ throw new Error("CLI action environment is missing.");
90
+ environment.telemetry.select(definition);
91
+ });
92
+ }
93
+ function annotateAccessContext(telemetry, context) {
94
+ if (context.policy === "none")
95
+ return;
96
+ telemetry.annotate({
97
+ account_id: context.state.account?.id,
98
+ organization_id: context.state.organization?.id
99
+ });
100
+ }
101
+ function commandPath(command) {
102
+ const names = [];
103
+ let current = command;
104
+ while (current) {
105
+ names.unshift(current.name());
106
+ current = current.parent;
107
+ }
108
+ return names.join(" ");
109
+ }
@@ -0,0 +1,75 @@
1
+ import { contractSchema } from "../contracts/schema.js";
2
+ import { bindPreparedAction } from "./action-binding.js";
3
+ import { CliUsageError } from "./errors.js";
4
+ import { productText as text } from "../product/text.js";
5
+ const agentSendInputSchema = contractSchema("agent.send", "input");
6
+ export function registerAgentCommands(program, runtime) {
7
+ const agent = program.command("agent")
8
+ .description(text(runtime.product, "稿定 Agent", "insMind Agent"))
9
+ .helpCommand(false);
10
+ const send = agent.command("send")
11
+ .description(text(runtime.product, "发送结构化创作消息并等待最终结果", "Send a structured creation message and wait for its result"))
12
+ .option("--schema", text(runtime.product, "输出输入 Schema", "output the input Schema"))
13
+ .option("--input <file|->", text(runtime.product, "从文件或标准输入读取 JSON", "read JSON from a file or stdin"))
14
+ .option("--async", text(runtime.product, "提交后返回 taskId,通过 task get 查询结果", "return taskId after submission; retrieve results with task get"))
15
+ .allowExcessArguments(false);
16
+ send.addHelpText("after", [
17
+ "",
18
+ text(runtime.product, "--async 在服务端受理后输出包含 taskId 和 state 的 JSON;退出码 0 仅表示受理。", "--async returns JSON with taskId and state after acceptance; exit code 0 means accepted only."),
19
+ text(runtime.product, "用 task get <taskId> 查询原任务;completed 时 result 为完整结果,running/unknown 或查询超时不应重新提交。", "Query the same taskId with task get; completed includes result. Do not resubmit on running, unknown, or a query timeout."),
20
+ text(runtime.product, "Agent 异步由本机后台进程继续执行;进程终止或关机可能使状态变为 unknown。", "Agent async continues in a local background process; termination or shutdown may leave its state unknown."),
21
+ text(runtime.product, "中断前台等待不会取消已交接的后台任务;仍用原 taskId 查询。", "Interrupting the foreground wait does not cancel a handed-off task; query the same taskId."),
22
+ text(runtime.product, "默认在当前进程等待最终结果,成功后一次输出 JSON。", "By default, the command waits in the current process and returns the final result as one JSON object."),
23
+ text(runtime.product, "运行中请继续等待原进程;已提交但结果未知时,不要重复提交。", "Wait for the original process. Do not resubmit a creation whose outcome is unknown."),
24
+ text(runtime.product, "默认模式在 stderr 提示任务 ID,stdout 保持原结果 JSON。", "In default mode the Task ID is written to stderr; stdout contains only the original result JSON."),
25
+ text(runtime.product, `结果未收到时执行 ${runtime.product.commandName} task list 找到原调用,再执行 ${runtime.product.commandName} task get <id> 查询。`, `If output is missing, find the original run with ${runtime.product.commandName} task list, then query ${runtime.product.commandName} task get <id>.`),
26
+ text(runtime.product, "首次创作省略 JSON 中的 message.contextId;续聊时传入上次结果的 message.contextId。", "Omit message.contextId for the first creation. Continue a conversation using message.contextId from the previous result."),
27
+ text(runtime.product, "usage 仅覆盖本次调用,不包含其他命令调用的消耗。", "usage covers this invocation only, excluding other command invocations."),
28
+ ""
29
+ ].join("\n"));
30
+ bindPreparedAction(send, "organization", async (signal) => {
31
+ signal.throwIfAborted();
32
+ const options = send.opts();
33
+ const modes = Number(options.schema === true) + Number(options.input !== undefined);
34
+ if (modes !== 1 || (options.schema && options.async))
35
+ throw new CliUsageError();
36
+ if (options.schema === true) {
37
+ await runtime.telemetry.stage("output", async () => {
38
+ runtime.io.writeOut(`${JSON.stringify(agentSendInputSchema)}\n`);
39
+ });
40
+ return { handled: true };
41
+ }
42
+ const input = await runtime.jsonInput.read(options.input, signal);
43
+ runtime.validators.agentSendInput(input);
44
+ runtime.telemetry.annotate({ parameters: { ...input } });
45
+ return { handled: false, input };
46
+ }, async (context, input, signal) => {
47
+ const task = {
48
+ state: context.state,
49
+ operation: "agent.send",
50
+ label: input.message.parts.map(part => part && typeof part === "object" && "text" in part ? String(part.text) : text(runtime.product, "[素材或结构化输入]", "[asset or structured input]")).join(" ")
51
+ };
52
+ if (send.opts().async) {
53
+ const result = await runtime.startAgentTask({ state: context.state, label: task.label, input }, signal);
54
+ runtime.validators.taskResult(result);
55
+ runtime.io.writeOut(`${JSON.stringify(result)}\n`);
56
+ return;
57
+ }
58
+ const run = async (observe) => {
59
+ const result = await runtime.agent.send({ input,
60
+ ...(observe ? { observe } : {}),
61
+ access: { credential: context.state.credential, organizationId: context.state.organization.id }, signal });
62
+ runtime.validators.agentSendOutput(result);
63
+ return result;
64
+ };
65
+ const result = await runtime.tasks.track({ ...task, run });
66
+ await runtime.telemetry.stage("output", async () => {
67
+ runtime.io.writeOut(`${JSON.stringify(result)}\n`);
68
+ });
69
+ }, {
70
+ operation: "agent.send",
71
+ mode: () => send.opts().schema === true
72
+ ? "schema"
73
+ : "execute"
74
+ });
75
+ }
@@ -0,0 +1,58 @@
1
+ import { bindAction } from "./action-binding.js";
2
+ import { authStatusViewFor } from "./presenter.js";
3
+ import { productText as text } from "../product/text.js";
4
+ export function registerAuthCommands(program, runtime) {
5
+ const auth = program.command("auth")
6
+ .description(text(runtime.product, "登录与本机凭证", "Authentication and local credentials"))
7
+ .helpCommand(false);
8
+ const login = leaf(auth.command("login"))
9
+ .description(text(runtime.product, "登录稿定", "Sign in to insMind"))
10
+ .option("--no-browser", text(runtime.product, "不自动打开浏览器", "do not open a browser automatically"));
11
+ bindAction(login, "none", async (_context, signal) => {
12
+ const noBrowser = login.opts().browser === false;
13
+ runtime.telemetry.annotate({ parameters: { noBrowser } });
14
+ const result = await runtime.auth.login({
15
+ noBrowser,
16
+ signal,
17
+ interaction: {
18
+ showAuthorization: (url) => runtime.presenter.authorization({
19
+ url,
20
+ terminal: runtime.io.stderrTerminal
21
+ }),
22
+ openBrowser: (url) => runtime.browser.open(url),
23
+ warn: (message) => runtime.presenter.warning(message)
24
+ }
25
+ });
26
+ await runtime.telemetry.stage("output", async () => {
27
+ runtime.presenter.success(result.status === "already_logged_in"
28
+ ? text(runtime.product, "已登录。", "Already signed in.")
29
+ : text(runtime.product, "登录成功。", "Signed in successfully."));
30
+ if (result.status === "already_logged_in" && !result.organizationSelected) {
31
+ runtime.presenter.warning("尚未选择组织,请执行 gd-cli org switch。");
32
+ }
33
+ });
34
+ }, { operation: "auth.login" });
35
+ const status = leaf(auth.command("status"))
36
+ .description(text(runtime.product, "查看登录状态", "Show authentication status"))
37
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
38
+ bindAction(status, "none", async () => {
39
+ const result = await runtime.auth.status({ now: runtime.now() });
40
+ await runtime.telemetry.stage("output", async () => {
41
+ runtime.validators.authStatus(result);
42
+ runtime.presenter.result(result, {
43
+ json: status.opts().json === true,
44
+ view: authStatusViewFor(runtime.product)
45
+ });
46
+ });
47
+ }, { operation: "auth.status" });
48
+ const logout = leaf(auth.command("logout")).description(text(runtime.product, "退出登录", "Sign out"));
49
+ bindAction(logout, "none", async () => {
50
+ await runtime.auth.logout();
51
+ await runtime.telemetry.stage("output", async () => {
52
+ runtime.presenter.success(text(runtime.product, "已退出登录。", "Signed out."));
53
+ });
54
+ }, { operation: "auth.logout" });
55
+ }
56
+ function leaf(command) {
57
+ return command.allowExcessArguments(false);
58
+ }
@@ -0,0 +1,23 @@
1
+ import { bindAction } from "./action-binding.js";
2
+ export function registerCreditsCommand(program, runtime) {
3
+ const credits = program.command("credits")
4
+ .description("Show the current insMind credits balance")
5
+ .option("--json", "output JSON")
6
+ .allowExcessArguments(false);
7
+ bindAction(credits, "organization", async (context, signal) => {
8
+ const result = await runtime.credits.get({
9
+ credential: context.state.credential,
10
+ organizationId: context.state.organization.id,
11
+ signal
12
+ });
13
+ await runtime.telemetry.stage("output", async () => {
14
+ runtime.presenter.result(result, {
15
+ json: credits.opts().json === true,
16
+ view: (value) => {
17
+ const balance = value;
18
+ return `${balance.credits.available} insMind credits available`;
19
+ }
20
+ });
21
+ });
22
+ }, { operation: "credits.get" });
23
+ }