@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,470 @@
1
+ import { bindAction, bindPreparedAction } from "./action-binding.js";
2
+ import { CliUsageError } from "./errors.js";
3
+ import { repositoryListView } from "./presenter.js";
4
+ import { productText as text } from "../product/text.js";
5
+ export function registerDamCommands(program, runtime) {
6
+ const dam = program.command("dam")
7
+ .description(text(runtime.product, "DAM 素材管理", "Asset management"))
8
+ .helpCommand(false);
9
+ const repository = dam.command("repository")
10
+ .description(text(runtime.product, "DAM 资源库", "Asset repositories"))
11
+ .helpCommand(false);
12
+ const repositoryList = leaf(repository.command("list"))
13
+ .description(text(runtime.product, "列出可用资源库", "List available repositories"))
14
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
15
+ bindAction(repositoryList, "organization", async (context, signal) => {
16
+ const result = await runtime.telemetry.stage("repository", () => (runtime.dam.repositoryList({
17
+ access: organizationAccess(context.state),
18
+ signal
19
+ })));
20
+ await runtime.telemetry.stage("output", async () => {
21
+ runtime.presenter.result(result, {
22
+ json: repositoryList.opts().json === true,
23
+ view: repositoryListView
24
+ });
25
+ });
26
+ }, { operation: "dam.repository.list" });
27
+ const folder = dam.command("folder")
28
+ .description(text(runtime.product, "DAM 文件夹", "Asset folders"))
29
+ .helpCommand(false);
30
+ const folderList = leaf(folder.command("list"))
31
+ .description(text(runtime.product, "列出文件夹", "List folders"))
32
+ .option("--repository-id <id>", text(runtime.product, "指定资源库 ID", "repository ID"))
33
+ .option("--parent-id <id>", text(runtime.product, "父文件夹 ID", "parent folder ID"))
34
+ .option("--query <text>", text(runtime.product, "按名称筛选", "filter by name"))
35
+ .option("--page <n>", text(runtime.product, "页码", "page number"), positiveInteger)
36
+ .option("--page-size <1-100>", text(runtime.product, "分页大小", "page size"), pageSize)
37
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
38
+ bindPreparedAction(folderList, "organization", async (signal) => {
39
+ signal.throwIfAborted();
40
+ const options = folderList.opts();
41
+ const input = {
42
+ ...defined("repositoryId", options.repositoryId),
43
+ ...defined("parentId", options.parentId),
44
+ ...defined("query", options.query),
45
+ ...defined("page", options.page),
46
+ ...defined("pageSize", options.pageSize)
47
+ };
48
+ runtime.validators.damFolderListInput(input);
49
+ runtime.telemetry.annotate({ parameters: { ...input } });
50
+ return { handled: false, input };
51
+ }, async (context, input, signal) => {
52
+ const result = await runtime.dam.folderList({
53
+ input,
54
+ access: organizationAccess(context.state),
55
+ signal
56
+ });
57
+ await runtime.telemetry.stage("output", async () => {
58
+ runtime.presenter.result(result, {
59
+ json: folderList.opts().json === true,
60
+ view: folderListView
61
+ });
62
+ });
63
+ }, { operation: "dam.folder.list" });
64
+ const tag = dam.command("tag")
65
+ .description(text(runtime.product, "DAM 标签", "Asset tags"))
66
+ .helpCommand(false);
67
+ const tagList = leaf(tag.command("list"))
68
+ .description(text(runtime.product, "列出标签", "List tags"))
69
+ .option("--repository-id <id>", text(runtime.product, "指定资源库 ID", "repository ID"))
70
+ .option("--query <text>", text(runtime.product, "按名称筛选", "filter by name"))
71
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
72
+ bindPreparedAction(tagList, "organization", async (signal) => {
73
+ signal.throwIfAborted();
74
+ const options = tagList.opts();
75
+ const input = {
76
+ ...defined("repositoryId", options.repositoryId),
77
+ ...defined("query", options.query)
78
+ };
79
+ runtime.validators.damTagListInput(input);
80
+ runtime.telemetry.annotate({ parameters: { ...input } });
81
+ return { handled: false, input };
82
+ }, async (context, input, signal) => {
83
+ const result = await runtime.dam.tagList({
84
+ input,
85
+ access: organizationAccess(context.state),
86
+ signal
87
+ });
88
+ await runtime.telemetry.stage("output", async () => {
89
+ runtime.presenter.result(result, {
90
+ json: tagList.opts().json === true,
91
+ view: tagListView
92
+ });
93
+ });
94
+ }, { operation: "dam.tag.list" });
95
+ const download = leaf(dam.command("download"))
96
+ .description(text(runtime.product, "下载一个素材", "Download an asset"))
97
+ .argument("<asset>", text(runtime.product, "素材 ID", "asset ID"))
98
+ .option("--repository-id <id>", text(runtime.product, "所属资源库 ID", "repository ID"))
99
+ .option("--output-dir <directory>", text(runtime.product, "输出目录", "output directory"))
100
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
101
+ bindPreparedAction(download, "organization", async (signal) => {
102
+ signal.throwIfAborted();
103
+ const options = download.opts();
104
+ const input = {
105
+ asset_id: position(download, 0),
106
+ ...defined("repositoryId", options.repositoryId),
107
+ ...defined("outputDir", options.outputDir)
108
+ };
109
+ runtime.validators.damDownloadInput(input);
110
+ runtime.telemetry.annotate({ content_id: input.asset_id, parameters: { ...input } });
111
+ return { handled: false, input };
112
+ }, async (context, input, signal) => {
113
+ const result = await runtime.dam.download({
114
+ input,
115
+ access: organizationAccess(context.state),
116
+ signal
117
+ });
118
+ await runtime.telemetry.stage("output", async () => {
119
+ runtime.presenter.result(result, {
120
+ json: download.opts().json === true,
121
+ view: downloadView
122
+ });
123
+ });
124
+ }, { operation: "dam.download" });
125
+ const rename = leaf(dam.command("rename"))
126
+ .description(text(runtime.product, "重命名一个素材或文件夹", "Rename an asset or folder"))
127
+ .argument("<entry>", text(runtime.product, "素材或文件夹 ID", "asset or folder ID"))
128
+ .requiredOption("--kind <asset|folder>", text(runtime.product, "条目类型", "entry kind"))
129
+ .requiredOption("--title <title>", text(runtime.product, "新标题", "new title"))
130
+ .option("--repository-id <id>", text(runtime.product, "所属资源库 ID", "repository ID"))
131
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
132
+ bindPreparedAction(rename, "organization", async (signal) => {
133
+ signal.throwIfAborted();
134
+ const options = rename.opts();
135
+ const input = {
136
+ entry_id: position(rename, 0),
137
+ kind: options.kind,
138
+ title: options.title,
139
+ ...defined("repositoryId", options.repositoryId)
140
+ };
141
+ runtime.validators.damRenameInput(input);
142
+ runtime.telemetry.annotate({ content_id: input.entry_id, parameters: { ...input } });
143
+ return { handled: false, input };
144
+ }, async (context, input, signal) => {
145
+ const result = await runtime.dam.rename({
146
+ input,
147
+ access: organizationAccess(context.state),
148
+ signal
149
+ });
150
+ await runtime.telemetry.stage("output", async () => {
151
+ runtime.presenter.result(result, {
152
+ json: rename.opts().json === true,
153
+ view: renameView
154
+ });
155
+ });
156
+ }, { operation: "dam.rename" });
157
+ for (const operation of ["move", "copy"]) {
158
+ const command = leaf(dam.command(operation))
159
+ .description(text(runtime.product, operation === "move" ? "移动一个素材或文件夹" : "复制一个素材或文件夹", operation === "move" ? "Move an asset or folder" : "Copy an asset or folder"))
160
+ .argument("<entry>", text(runtime.product, "素材或文件夹 ID", "asset or folder ID"))
161
+ .requiredOption("--kind <asset|folder>", text(runtime.product, "条目类型", "entry kind"))
162
+ .requiredOption("--target-folder-id <id>", text(runtime.product, "目标文件夹 ID;根目录使用 0", "target folder ID; use 0 for root"))
163
+ .option("--repository-id <source-id>", text(runtime.product, "源资源库 ID", "source repository ID"))
164
+ .option("--target-repository-id <target-id>", text(runtime.product, "目标资源库 ID", "target repository ID"))
165
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
166
+ bindPreparedAction(command, "organization", async (signal) => {
167
+ signal.throwIfAborted();
168
+ const options = command.opts();
169
+ const input = {
170
+ entry_id: position(command, 0),
171
+ kind: options.kind,
172
+ targetFolderId: options.targetFolderId,
173
+ ...defined("repositoryId", options.repositoryId),
174
+ ...defined("targetRepositoryId", options.targetRepositoryId)
175
+ };
176
+ if (operation === "move")
177
+ runtime.validators.damMoveInput(input);
178
+ else
179
+ runtime.validators.damCopyInput(input);
180
+ runtime.telemetry.annotate({ content_id: input.entry_id, parameters: { ...input } });
181
+ return { handled: false, input: input };
182
+ }, async (context, input, signal) => {
183
+ const result = operation === "move"
184
+ ? await runtime.dam.move({
185
+ input: input,
186
+ access: organizationAccess(context.state),
187
+ signal
188
+ })
189
+ : await runtime.dam.copy({
190
+ input: input,
191
+ access: organizationAccess(context.state),
192
+ signal
193
+ });
194
+ await runtime.telemetry.stage("output", async () => {
195
+ runtime.presenter.result(result, {
196
+ json: command.opts().json === true,
197
+ view: operation === "move" ? moveView : copyView
198
+ });
199
+ });
200
+ }, { operation: `dam.${operation}` });
201
+ }
202
+ const list = browseCommand(leaf(dam.command("list")), runtime)
203
+ .description(text(runtime.product, "查看最近素材", "List recent assets"));
204
+ bindPreparedAction(list, "organization", async (signal) => {
205
+ signal.throwIfAborted();
206
+ const input = browseInput(list);
207
+ runtime.validators.damListInput(input);
208
+ runtime.telemetry.annotate({ parameters: { ...input } });
209
+ return { handled: false, input };
210
+ }, async (context, input, signal) => {
211
+ const result = await runtime.dam.list({
212
+ input,
213
+ access: organizationAccess(context.state),
214
+ signal
215
+ });
216
+ await runtime.telemetry.stage("output", async () => {
217
+ runtime.presenter.result(result, {
218
+ json: list.opts().json === true,
219
+ view: assetListView
220
+ });
221
+ });
222
+ }, { operation: "dam.list" });
223
+ const search = browseCommand(leaf(dam.command("search")), runtime)
224
+ .description(text(runtime.product, "按关键词搜索素材", "Search assets by keyword"))
225
+ .argument("<query>", text(runtime.product, "搜索关键词", "search query"));
226
+ bindPreparedAction(search, "organization", async (signal) => {
227
+ signal.throwIfAborted();
228
+ const input = {
229
+ query: position(search, 0),
230
+ ...browseInput(search)
231
+ };
232
+ runtime.validators.damSearchInput(input);
233
+ runtime.telemetry.annotate({ parameters: { ...input } });
234
+ return { handled: false, input };
235
+ }, async (context, input, signal) => {
236
+ const result = await runtime.dam.search({
237
+ input,
238
+ access: organizationAccess(context.state),
239
+ signal
240
+ });
241
+ await runtime.telemetry.stage("output", async () => {
242
+ runtime.presenter.result(result, {
243
+ json: search.opts().json === true,
244
+ view: assetListView
245
+ });
246
+ });
247
+ }, { operation: "dam.search" });
248
+ const get = leaf(dam.command("get"))
249
+ .description(text(runtime.product, "查看素材完整信息", "Show complete asset information"))
250
+ .argument("<asset>", text(runtime.product, "素材 ID", "asset ID"))
251
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
252
+ bindPreparedAction(get, "organization", async (signal) => {
253
+ signal.throwIfAborted();
254
+ const input = { asset_id: position(get, 0) };
255
+ runtime.validators.damGetInput(input);
256
+ runtime.telemetry.annotate({ parameters: { ...input } });
257
+ return { handled: false, input };
258
+ }, async (context, input, signal) => {
259
+ const result = await runtime.dam.get({
260
+ input,
261
+ access: organizationAccess(context.state),
262
+ signal
263
+ });
264
+ await runtime.telemetry.stage("output", async () => {
265
+ runtime.presenter.result(result, {
266
+ json: get.opts().json === true,
267
+ view: assetDetailView
268
+ });
269
+ });
270
+ }, { operation: "dam.get" });
271
+ const upload = leaf(dam.command("upload"))
272
+ .description(text(runtime.product, "上传本地文件并创建素材", "Upload a local file and create an asset"))
273
+ .argument("<file>", text(runtime.product, "本地文件路径", "local file path"))
274
+ .option("--repository-id <id>", text(runtime.product, "目标资源库 ID", "target repository ID"))
275
+ .option("--title <title>", text(runtime.product, "素材标题", "asset title"))
276
+ .option("--folder-id <id>", text(runtime.product, "目标文件夹 ID", "target folder ID"))
277
+ .option("--tag-ids <csv>", text(runtime.product, "标签 ID,逗号分隔", "comma-separated tag IDs"))
278
+ .option("--allow-sensitive-path", text(runtime.product, "明确允许受保护路径", "allow a protected local path"))
279
+ .option("--wait-analysis", text(runtime.product, "等待素材分析结束", "wait for asset analysis"))
280
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
281
+ bindPreparedAction(upload, "organization", async (signal) => {
282
+ signal.throwIfAborted();
283
+ const options = upload.opts();
284
+ const input = {
285
+ file: position(upload, 0),
286
+ ...defined("repositoryId", options.repositoryId),
287
+ ...defined("title", options.title),
288
+ ...defined("folderId", options.folderId),
289
+ ...defined("tagIds", csv(options.tagIds)),
290
+ ...(options.allowSensitivePath === true ? { allowSensitivePath: true } : {}),
291
+ ...(options.waitAnalysis === true ? { waitAnalysis: true } : {})
292
+ };
293
+ runtime.validators.damUploadInput(input);
294
+ runtime.telemetry.annotate({ parameters: { ...input } });
295
+ return { handled: false, input };
296
+ }, async (context, input, signal) => {
297
+ const result = await runtime.dam.upload({
298
+ input,
299
+ access: organizationAccess(context.state),
300
+ signal
301
+ });
302
+ await runtime.telemetry.stage("output", async () => {
303
+ runtime.presenter.result(result, {
304
+ json: upload.opts().json === true,
305
+ view: assetDetailView
306
+ });
307
+ });
308
+ }, { operation: "dam.upload" });
309
+ const deleteCommand = leaf(dam.command("delete"))
310
+ .description(text(runtime.product, "删除素材", "Delete an asset"))
311
+ .argument("<asset>", text(runtime.product, "素材 ID", "asset ID"))
312
+ .option("--repository-id <id>", text(runtime.product, "所属资源库 ID", "repository ID"))
313
+ .option("--permanent", text(runtime.product, "移入回收站后永久删除", "permanently delete after moving to trash"));
314
+ bindPreparedAction(deleteCommand, "organization", async (signal) => {
315
+ signal.throwIfAborted();
316
+ const options = deleteCommand.opts();
317
+ const input = {
318
+ asset_id: position(deleteCommand, 0),
319
+ ...defined("repositoryId", options.repositoryId),
320
+ ...(options.permanent === true ? { permanent: true } : {})
321
+ };
322
+ runtime.validators.damDeleteInput(input);
323
+ runtime.telemetry.annotate({ parameters: { ...input } });
324
+ return { handled: false, input };
325
+ }, async (context, input, signal) => {
326
+ await runtime.dam.delete({
327
+ input,
328
+ access: organizationAccess(context.state),
329
+ signal
330
+ });
331
+ await runtime.telemetry.stage("output", async () => {
332
+ runtime.presenter.success(input.permanent === true
333
+ ? text(runtime.product, "素材已永久删除。", "Asset permanently deleted.")
334
+ : text(runtime.product, "素材已移入回收站。", "Asset moved to trash."));
335
+ });
336
+ }, { operation: "dam.delete" });
337
+ }
338
+ function leaf(command) {
339
+ return command.allowExcessArguments(false);
340
+ }
341
+ function browseCommand(command, runtime) {
342
+ return command
343
+ .option("--repository-id <id>", text(runtime.product, "指定资源库 ID", "repository ID"))
344
+ .option("--all-repositories", text(runtime.product, "查询全部可访问资源库", "query all accessible repositories"))
345
+ .option("--folder-id <id>", text(runtime.product, "指定文件夹 ID", "folder ID"))
346
+ .option("--no-include-child-folder", text(runtime.product, "不包含子文件夹", "exclude child folders"))
347
+ .option("--type <type>", text(runtime.product, "素材类型", "asset type"))
348
+ .option("--asset-format <csv>", text(runtime.product, "文件格式,逗号分隔", "comma-separated file formats"))
349
+ .option("--tag-ids <csv>", text(runtime.product, "标签 ID,逗号分隔", "comma-separated tag IDs"))
350
+ .option("--page-size <1-100>", text(runtime.product, "请求分页大小", "request page size"), pageSize)
351
+ .option("--cursor <id>", text(runtime.product, "分页游标", "pagination cursor"))
352
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
353
+ }
354
+ function browseInput(command) {
355
+ const options = command.opts();
356
+ return {
357
+ ...defined("repositoryId", options.repositoryId),
358
+ ...(options.allRepositories === true ? { allRepositories: true } : {}),
359
+ ...defined("folderId", options.folderId),
360
+ ...(command.getOptionValueSource("includeChildFolder") === "cli"
361
+ ? { includeChildFolder: false }
362
+ : {}),
363
+ ...defined("type", options.type),
364
+ ...defined("assetFormats", csv(options.assetFormat)),
365
+ ...defined("tagIds", csv(options.tagIds)),
366
+ ...defined("pageSize", options.pageSize),
367
+ ...defined("cursor", options.cursor)
368
+ };
369
+ }
370
+ function defined(key, value) {
371
+ return value === undefined ? {} : { [key]: value };
372
+ }
373
+ function csv(value) {
374
+ return value?.split(",").map((item) => item.trim()).filter((item) => item !== "");
375
+ }
376
+ function pageSize(value) {
377
+ if (!/^\d+$/u.test(value))
378
+ throw new CliUsageError();
379
+ const parsed = Number(value);
380
+ if (!Number.isInteger(parsed) || parsed < 1 || parsed > 100)
381
+ throw new CliUsageError();
382
+ return parsed;
383
+ }
384
+ function positiveInteger(value) {
385
+ if (!/^\d+$/u.test(value))
386
+ throw new CliUsageError();
387
+ const parsed = Number(value);
388
+ if (!Number.isSafeInteger(parsed) || parsed < 1)
389
+ throw new CliUsageError();
390
+ return parsed;
391
+ }
392
+ function position(command, index) {
393
+ const value = command.processedArgs[index];
394
+ if (typeof value !== "string")
395
+ throw new CliUsageError();
396
+ return value;
397
+ }
398
+ function organizationAccess(state) {
399
+ return {
400
+ credential: state.credential,
401
+ organizationId: state.organization.id
402
+ };
403
+ }
404
+ function assetListView(value) {
405
+ const assets = value.assets;
406
+ if (assets.length === 0)
407
+ return "暂无素材。";
408
+ return [
409
+ "ID\t标题\t类型\t格式",
410
+ ...assets.map(assetRow)
411
+ ].join("\n");
412
+ }
413
+ function assetRow(asset) {
414
+ return [asset.asset_id, asset.title ?? "", asset.type ?? "", asset.format ?? ""].join("\t");
415
+ }
416
+ function assetDetailView(value) {
417
+ const asset = value;
418
+ return [
419
+ `素材:${asset.title ?? asset.asset_id}`,
420
+ `ID:${asset.asset_id}`,
421
+ ...(asset.type === undefined ? [] : [`类型:${asset.type}`]),
422
+ ...(asset.format === undefined ? [] : [`格式:${asset.format}`]),
423
+ ...(asset.url === undefined ? [] : [`URL:${asset.url}`])
424
+ ].join("\n");
425
+ }
426
+ function folderListView(value) {
427
+ const folders = value.folders;
428
+ if (folders.length === 0)
429
+ return "暂无文件夹。";
430
+ return [
431
+ "ID\t名称\t子文件夹数\t素材数",
432
+ ...folders.map((folder) => [
433
+ folder.folder_id,
434
+ folder.title,
435
+ folder.child_folder_count,
436
+ folder.asset_count
437
+ ].join("\t"))
438
+ ].join("\n");
439
+ }
440
+ function tagListView(value) {
441
+ const tags = value.tags;
442
+ if (tags.length === 0)
443
+ return "暂无标签。";
444
+ return [
445
+ "ID\t名称\t素材数",
446
+ ...tags.map((tag) => [tag.tag_id, tag.name, tag.asset_count].join("\t"))
447
+ ].join("\n");
448
+ }
449
+ function downloadView(value) {
450
+ return value.files
451
+ .map((file) => `已下载:${file.path}`)
452
+ .join("\n");
453
+ }
454
+ function renameView(value) {
455
+ const result = value;
456
+ return `已重命名:${result.title} (${result.entry_id})`;
457
+ }
458
+ function moveView(value) {
459
+ const result = value;
460
+ return `已移动至:${result.repository_id} / ${result.folder_id}`;
461
+ }
462
+ function copyView(value) {
463
+ const result = value;
464
+ return [
465
+ `已复制至:${result.repository_id} / ${result.folder_id}`,
466
+ ...(result.copied_entry_id === undefined
467
+ ? []
468
+ : [`复制条目 ID:${result.copied_entry_id}`])
469
+ ].join("\n");
470
+ }
@@ -0,0 +1,74 @@
1
+ import { bindAction, bindPreparedAction } from "./action-binding.js";
2
+ import { productText as text } from "../product/text.js";
3
+ export function registerEditorCommands(program, runtime) {
4
+ const editor = program.command("editor")
5
+ .description(text(runtime.product, "连接并操作 AI+ Editor", "Connect to and operate insMind Editor"))
6
+ .helpCommand(false);
7
+ const connect = leaf(editor.command("connect"))
8
+ .description(text(runtime.product, "打开并连接一个 AI+ Editor 作品", "Open and connect to an Editor work"))
9
+ .argument("[target]", text(runtime.product, "作品 ID 或完整 URL", "work ID or complete URL"));
10
+ bindPreparedAction(connect, "none", async (signal) => {
11
+ signal.throwIfAborted();
12
+ const target = connect.processedArgs[0];
13
+ const input = typeof target === "string" ? { target } : {};
14
+ runtime.validators.editorConnectInput(input);
15
+ return { handled: false, input };
16
+ }, async (_context, input, signal) => {
17
+ const result = await runtime.editor.connect({ input, signal });
18
+ writeJson(runtime, result);
19
+ });
20
+ const disconnect = leaf(editor.command("disconnect"))
21
+ .description(text(runtime.product, "断开当前 Editor 连接", "Disconnect the current Editor"));
22
+ bindAction(disconnect, "none", async (_context, signal) => {
23
+ writeJson(runtime, await runtime.editor.disconnect({ signal }));
24
+ });
25
+ const snapshot = leaf(editor.command("snapshot"))
26
+ .description(text(runtime.product, "读取当前作品快照", "Read the current work snapshot"));
27
+ bindAction(snapshot, "none", async (_context, signal) => {
28
+ writeJson(runtime, await runtime.editor.snapshot({ signal }));
29
+ });
30
+ const apply = leaf(editor.command("apply"))
31
+ .description(text(runtime.product, "按顺序应用元素操作", "Apply element operations in order"))
32
+ .requiredOption("--input <file|->", text(runtime.product, "从文件或标准输入读取 JSON", "read JSON from a file or stdin"));
33
+ bindPreparedAction(apply, "none", async (signal) => {
34
+ signal.throwIfAborted();
35
+ const source = apply.opts().input;
36
+ const input = await runtime.jsonInput.read(source, signal);
37
+ runtime.validators.editorApplyInput(input);
38
+ return { handled: false, input };
39
+ }, async (_context, input, signal) => {
40
+ writeJson(runtime, await runtime.editor.apply({ input, signal }));
41
+ });
42
+ const screenshot = leaf(editor.command("screenshot"))
43
+ .description(text(runtime.product, "导出当前作品 PNG 截图", "Export a PNG screenshot of the current work"))
44
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
45
+ bindAction(screenshot, "none", async (_context, signal) => {
46
+ const result = await runtime.editor.screenshot({ signal });
47
+ runtime.presenter.result(result, {
48
+ json: screenshot.opts().json === true,
49
+ view: screenshotView
50
+ });
51
+ });
52
+ const save = leaf(editor.command("save"))
53
+ .description(text(runtime.product, "保存当前 AI+ Editor 作品", "Save the current Editor work"))
54
+ .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
55
+ bindAction(save, "none", async (_context, signal) => {
56
+ const result = await runtime.editor.save({ signal });
57
+ runtime.presenter.result(result, {
58
+ json: save.opts().json === true,
59
+ view: saveView
60
+ });
61
+ });
62
+ }
63
+ function leaf(command) {
64
+ return command.allowExcessArguments(false);
65
+ }
66
+ function writeJson(runtime, value) {
67
+ runtime.io.writeOut(`${JSON.stringify(value)}\n`);
68
+ }
69
+ function screenshotView(value) {
70
+ return `截图已保存至 ${value.path}`;
71
+ }
72
+ function saveView(value) {
73
+ return `作品已保存:${value.url}`;
74
+ }