gaoding-cli 1.0.0-alpha.7 → 1.0.0-alpha.8

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 (61) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +18 -14
  3. package/dist/src/api/app-runner.js +1 -2
  4. package/dist/src/api/creative-client.d.ts +34 -0
  5. package/dist/src/api/creative-client.js +184 -0
  6. package/dist/src/api/direct-client.d.ts +9 -2
  7. package/dist/src/api/direct-client.js +45 -18
  8. package/dist/src/api/hub-client.d.ts +11 -8
  9. package/dist/src/api/hub-client.js +17 -18
  10. package/dist/src/api/usage-client.d.ts +4 -4
  11. package/dist/src/api/usage-client.js +9 -49
  12. package/dist/src/auth/credential-store-v2.d.ts +0 -1
  13. package/dist/src/auth/credential-store-v2.js +0 -6
  14. package/dist/src/commands/auth.js +13 -13
  15. package/dist/src/commands/creative.d.ts +8 -0
  16. package/dist/src/commands/creative.js +186 -0
  17. package/dist/src/commands/dam.js +27 -22
  18. package/dist/src/commands/org.js +20 -14
  19. package/dist/src/commands/skills.js +9 -4
  20. package/dist/src/commands/update.js +6 -2
  21. package/dist/src/commands/usage.d.ts +1 -1
  22. package/dist/src/commands/usage.js +6 -4
  23. package/dist/src/commands/workflows.js +31 -13
  24. package/dist/src/core/auth/auth-guard.d.ts +21 -0
  25. package/dist/src/core/auth/auth-guard.js +121 -0
  26. package/dist/src/core/auth/org-manager.d.ts +2 -1
  27. package/dist/src/core/auth/org-manager.js +61 -6
  28. package/dist/src/creative/contract.d.ts +1112 -0
  29. package/dist/src/creative/contract.js +743 -0
  30. package/dist/src/creative/media.d.ts +19 -0
  31. package/dist/src/creative/media.js +83 -0
  32. package/dist/src/creative/protocol.d.ts +60 -0
  33. package/dist/src/creative/protocol.js +337 -0
  34. package/dist/src/middleware/auth.d.ts +6 -2
  35. package/dist/src/middleware/auth.js +25 -63
  36. package/dist/src/middleware/error-handler.d.ts +2 -0
  37. package/dist/src/middleware/error-handler.js +3 -4
  38. package/dist/src/program.js +7 -89
  39. package/dist/src/registry/agent-contracts.d.ts +3 -11
  40. package/dist/src/registry/agent-contracts.js +5 -243
  41. package/dist/src/registry/direct-registry.d.ts +0 -5
  42. package/dist/src/registry/direct-registry.js +0 -19
  43. package/dist/src/registry/registry-client.d.ts +0 -21
  44. package/dist/src/registry/registry-client.js +1 -40
  45. package/dist/src/utils/config.d.ts +2 -2
  46. package/dist/src/utils/config.js +1 -1
  47. package/dist/src/utils/help-verify.d.ts +1 -3
  48. package/dist/src/utils/help-verify.js +1 -25
  49. package/package.json +3 -3
  50. package/skills/gd-cli/SKILL.md +10 -9
  51. package/skills/gd-cli/references/auth.md +6 -0
  52. package/skills/gd-cli/references/creative.md +47 -0
  53. package/skills/gd-cli/references/entitlement.md +2 -2
  54. package/skills/gd-cli/references/errors.md +7 -0
  55. package/skills/gd-cli/references/sop.md +4 -4
  56. package/skills/gd-cli/references/workflows.md +1 -1
  57. package/dist/src/commands/models.d.ts +0 -2
  58. package/dist/src/commands/models.js +0 -78
  59. package/dist/src/commands/tools.d.ts +0 -4
  60. package/dist/src/commands/tools.js +0 -383
  61. package/skills/gd-cli/references/tools.md +0 -29
@@ -1,383 +0,0 @@
1
- import { Option } from "commander";
2
- import { ToolInvoker } from "../api/tool-invoker.js";
3
- import { withAuth } from "../middleware/auth.js";
4
- import { withErrorHandler } from "../middleware/error-handler.js";
5
- import { formatOutput, rowsForToolList } from "../middleware/output.js";
6
- import { resolveInvokeOutputFormat, resolveListOutputFormat, } from "../utils/list-output-format.js";
7
- import { createSpinner } from "../utils/spinner.js";
8
- import { resolveToolActivityLabel, toolActivityLabel, } from "../utils/tool-display.js";
9
- import { enrichUploadParamsIfNeeded } from "../utils/enrich-upload-params.js";
10
- import { appendToolQuickExample } from "../utils/help-verify.js";
11
- import { emitJson, wrapEnvelope, shouldEmitEnvelope } from "../core/output/envelope.js";
12
- import { PUBLIC_DIRECT_TOOLS, resolvePublicToolSpec, } from "../registry/direct-registry.js";
13
- import { buildManifest, buildToolExamples, buildToolSchema, rowsForManifest, } from "../registry/agent-contracts.js";
14
- import { applySetEntries, collectArg, readJsonInput } from "../utils/input-json.js";
15
- import { setStaticHelp } from "../utils/static-help.js";
16
- import { printCapabilityExamples, printCapabilitySchema, } from "../utils/capability-presenter.js";
17
- import { capabilityMetadata } from "../utils/capability-metadata.js";
18
- export function registerToolsCommand(program) {
19
- const tools = program
20
- .command("tools")
21
- .usage("<command> [options]")
22
- .description("单项 AI 创意能力 Tools")
23
- .configureHelp({ showGlobalOptions: true });
24
- setStaticHelp(tools, TOOLS_HELP);
25
- tools
26
- .command("list")
27
- .alias("ls")
28
- .description("列出内置 Tools")
29
- .option("--category <cat>", "分类: image / text / video / infrastructure")
30
- .action(withErrorHandler(async (options, command) => {
31
- const opts = options;
32
- const cmd = command;
33
- let items = PUBLIC_DIRECT_TOOLS;
34
- if (opts.category) {
35
- const cat = String(opts.category);
36
- items = items.filter((item) => item.category === cat);
37
- }
38
- const publicItems = items.map(toPublicToolPayload);
39
- const format = resolveListOutputFormat(cmd);
40
- if (shouldEmitEnvelope(format)) {
41
- emitJson(wrapEnvelope({ tools: publicItems }, { command: "tools list" }));
42
- }
43
- else if (format === "json") {
44
- formatOutput(publicItems, format);
45
- }
46
- else {
47
- formatOutput(rowsForToolList(publicItems), format);
48
- }
49
- }));
50
- tools
51
- .command("info <tool-id>")
52
- .description("查看工具详情")
53
- .action(withErrorHandler(async (toolId, _opts, command) => {
54
- const cmd = command;
55
- const detail = resolvePublicToolSpec(String(toolId));
56
- if (!detail)
57
- throw new Error(`未找到工具: ${String(toolId)}`);
58
- const payload = toPublicToolPayload(detail);
59
- const format = cmd.parent?.parent?.opts().format ?? "json";
60
- if (shouldEmitEnvelope(format)) {
61
- emitJson(wrapEnvelope(payload, { command: "tools info", tool_id: toolId }));
62
- }
63
- else {
64
- formatOutput(payload, format);
65
- }
66
- }));
67
- tools
68
- .command("schema <tool-id>")
69
- .description("查看输入/输出 JSON Schema")
70
- .action(withErrorHandler(async (toolId, _opts, command) => {
71
- const cmd = command;
72
- const payload = buildToolSchema(String(toolId));
73
- const format = resolveListOutputFormat(cmd);
74
- if (format === "json") {
75
- formatOutput(payload, "json");
76
- }
77
- else {
78
- printCapabilitySchema(payload);
79
- }
80
- }));
81
- tools
82
- .command("examples <tool-id>")
83
- .description("查看调用示例")
84
- .action(withErrorHandler(async (toolId, _opts, command) => {
85
- const cmd = command;
86
- const payload = buildToolExamples(String(toolId));
87
- const format = resolveListOutputFormat(cmd);
88
- if (format === "json") {
89
- formatOutput(payload, "json");
90
- }
91
- else {
92
- printCapabilityExamples(payload);
93
- }
94
- }));
95
- tools
96
- .command("manifest")
97
- .description("输出 Tools 机器可读能力清单")
98
- .action((_opts, command) => {
99
- const manifest = buildManifest("tools");
100
- const format = resolveListOutputFormat(command);
101
- formatOutput(format === "json" ? manifest : rowsForManifest(manifest), format);
102
- });
103
- const callCmd = tools
104
- .command("call <tool-id> [input]")
105
- .usage("<tool-id> [input] [options]")
106
- .description("调用指定工具")
107
- .option("--input <file>", "从 JSON 文件读取输入,使用 - 表示 stdin")
108
- .option("--set <key=value>", "直接传入单个字段,可重复", collectArg)
109
- .option("--asset <id-or-url>", "传入 DAM asset_id 或 CDN URL,可重复", collectArg)
110
- .option("--prompt <text>", "文字提示词")
111
- .option("--brief <text>", "业务 brief / 商品描述")
112
- .option("--image <url>", "输入图片 URL")
113
- .option("--image-url <url>", "输入图片 URL")
114
- .option("--image-file <path>", "输入图片本地路径")
115
- .option("--image-prompt <text>", "图片内容描述,不上传本地图片")
116
- .option("--require-image", "要求必须提供真实参考图;缺图时不退化为文生", false)
117
- .option("--video <url>", "输入视频 URL 或本地路径")
118
- .option("--video-url <url>", "输入视频 URL")
119
- .option("--video-file <path>", "输入视频本地路径")
120
- .option("--style <code>", "风格代码")
121
- .option("--style-code <code>", "风格/模型代码")
122
- .option("--model <code-or-name>", "模型 code / 名称 / auto")
123
- .option("--ratio <ratio>", "宽高比")
124
- .option("--resolution <value>", "分辨率参数")
125
- .option("--duration <value>", "视频时长参数")
126
- .option("--content-id <id>", "指定后端 content_id;部分工具未传或非法时会自动生成")
127
- .option("--mask <url>", "蒙版图 URL")
128
- .option("--mask-url <url>", "蒙版图 URL")
129
- .option("--mask-file <path>", "蒙版图本地路径")
130
- .option("--compose-mask", "将后端 mask 与原图合成透明 PNG(默认开启)")
131
- .option("--raw-mask", "仅返回后端 mask,不做合成", false)
132
- .option("--width <n>", "目标宽度", parseInt)
133
- .option("--height <n>", "目标高度", parseInt)
134
- .option("--mode <mode>", "模式参数")
135
- .option("--file <path>", "本地文件路径")
136
- .option("--allow-sensitive-path", "确认上传默认受保护的本地路径", false)
137
- .addOption(new Option("--arg <entry>", "内部调试参数 key=value,可重复").hideHelp().argParser(collectArg))
138
- .option("--async", "异步模式", false)
139
- .option("--timeout <seconds>", "超时秒数;未传时使用工具默认值")
140
- .allowUnknownOption(true);
141
- callCmd.action(withErrorHandler(async (toolName, input, options, command) => {
142
- await withAuth(async () => {
143
- await runToolCall(toolName, input, options, command);
144
- })(toolName, input, options, command);
145
- }));
146
- loadDynamicToolAliases(tools);
147
- callCmd.addHelpText("afterAll", TOOL_CALL_HELP);
148
- }
149
- export async function runToolCall(toolName, input, opts, cmd) {
150
- const spec = resolvePublicToolSpec(toolName);
151
- if (!spec) {
152
- throw new Error(`未找到工具: ${toolName}。临时生成 CDN URL 可使用 gd-cli tools call upload --file <file>;DAM 入库请使用 gd-cli dam upload <file>`);
153
- }
154
- const inputOption = optionalString(opts.input);
155
- const inputOptionIsJson = inputOption ? shouldReadJsonInput(inputOption) : false;
156
- const inputArgIsJson = input ? shouldReadJsonInput(input) : false;
157
- let params = {};
158
- if (inputArgIsJson && input) {
159
- params = { ...params, ...(await readJsonInput(input)) };
160
- }
161
- if (inputOptionIsJson && inputOption) {
162
- params = { ...params, ...(await readJsonInput(inputOption)) };
163
- }
164
- if (input && !inputArgIsJson)
165
- params.input = input;
166
- if (inputOption && !inputOptionIsJson)
167
- params.input = inputOption;
168
- params = mergeToolCallOptions(params, opts);
169
- applySetEntries(params, opts.set);
170
- applyAssetEntries(params, opts.asset);
171
- const canonicalToolName = spec?.name ?? toolName;
172
- const merged = enrichUploadParamsIfNeeded(canonicalToolName, params);
173
- const label = await resolveToolActivityLabel(canonicalToolName);
174
- const spinner = createSpinner(`${label} · 处理中…`);
175
- if (process.stderr.isTTY)
176
- spinner.start();
177
- const invoker = new ToolInvoker();
178
- const result = await invoker.invoke(canonicalToolName, merged, {
179
- async: !!opts.async,
180
- timeout: resolveTimeoutSeconds(opts.timeout, spec.timeout),
181
- });
182
- if (process.stderr.isTTY) {
183
- if (result.status === "completed")
184
- spinner.succeed(`${label} · 已完成`);
185
- else if (result.status === "failed")
186
- spinner.fail(`${label} · 失败`);
187
- else
188
- spinner.stop();
189
- }
190
- const format = resolveInvokeOutputFormat(cmd);
191
- if (shouldEmitEnvelope(format)) {
192
- emitJson(wrapEnvelope(result, { command: "tools call", tool_id: canonicalToolName }));
193
- }
194
- else {
195
- formatOutput(result, format, { activityLabel: label });
196
- }
197
- }
198
- export function mergeToolCallOptions(base, opts) {
199
- const params = { ...base };
200
- const ignoredKeys = new Set(["async", "timeout", "input", "set", "asset"]);
201
- const normalizedKeys = {
202
- imageUrl: "image_url",
203
- "image-url": "image_url",
204
- imageFile: "image_file",
205
- "image-file": "image_file",
206
- imagePrompt: "image_prompt",
207
- "image-prompt": "image_prompt",
208
- maskUrl: "mask_url",
209
- "mask-url": "mask_url",
210
- maskFile: "mask_file",
211
- "mask-file": "mask_file",
212
- style: "style_code",
213
- styleCode: "style_code",
214
- requireImage: "require_image",
215
- "require-image": "require_image",
216
- videoUrl: "video_url",
217
- "video-url": "video_url",
218
- videoFile: "video_file",
219
- "video-file": "video_file",
220
- contentId: "content_id",
221
- "content-id": "content_id",
222
- allowSensitivePath: "allow_sensitive_path",
223
- "allow-sensitive-path": "allow_sensitive_path",
224
- composeMask: "compose_mask",
225
- "compose-mask": "compose_mask",
226
- rawMask: "raw_mask",
227
- "raw-mask": "raw_mask",
228
- };
229
- for (const [key, value] of Object.entries(opts)) {
230
- if (ignoredKeys.has(key) || value === undefined || value === false)
231
- continue;
232
- params[normalizedKeys[key] ?? key] = value;
233
- }
234
- return params;
235
- }
236
- function shouldReadJsonInput(value) {
237
- return value === "-" || /\.json$/i.test(value);
238
- }
239
- function optionalString(value) {
240
- if (typeof value !== "string")
241
- return undefined;
242
- const trimmed = value.trim();
243
- return trimmed ? trimmed : undefined;
244
- }
245
- function applyAssetEntries(target, entries) {
246
- if (!Array.isArray(entries) || entries.length === 0)
247
- return;
248
- const assets = entries.map(String).filter(Boolean);
249
- if (assets.length === 0)
250
- return;
251
- target.assets = assets;
252
- if (!target.image && assets.length === 1)
253
- target.image = assets[0];
254
- if (!target.images && assets.length > 1)
255
- target.images = assets;
256
- }
257
- function resolveTimeoutSeconds(value, fallback) {
258
- if (value === undefined || value === null || value === "")
259
- return fallback;
260
- const parsed = Number.parseInt(String(value), 10);
261
- if (!Number.isFinite(parsed) || parsed <= 0)
262
- return fallback;
263
- return parsed;
264
- }
265
- async function loadDynamicToolAliases(toolsCmd) {
266
- const seen = new Set();
267
- const reserved = new Set([
268
- "list",
269
- "ls",
270
- "search",
271
- "info",
272
- "schema",
273
- "examples",
274
- "manifest",
275
- "call",
276
- "install",
277
- "uninstall",
278
- ]);
279
- for (const spec of PUBLIC_DIRECT_TOOLS) {
280
- for (const commandName of [spec.name, ...(spec.aliases ?? [])]) {
281
- if (seen.has(commandName) || reserved.has(commandName)) {
282
- continue;
283
- }
284
- seen.add(commandName);
285
- registerDynamicToolAlias(toolsCmd, spec, commandName);
286
- }
287
- }
288
- }
289
- function registerDynamicToolAlias(parent, spec, commandName = spec.name) {
290
- const cmd = parent
291
- .command(commandName, { hidden: true })
292
- .description(spec.description)
293
- .configureHelp({ showGlobalOptions: true });
294
- for (const param of spec.input ?? []) {
295
- const flag = param.cli_flag ?? `--${param.name}`;
296
- const desc = param.description + (param.required ? " (必填)" : "");
297
- if (param.type === "boolean") {
298
- cmd.option(flag, desc, param.default);
299
- }
300
- else {
301
- cmd.option(`${flag} <value>`, desc, param.default);
302
- }
303
- }
304
- cmd.action(withErrorHandler(async (...args) => {
305
- await withAuth(async (options, command) => {
306
- const opts = options;
307
- const sub = command;
308
- const label = toolActivityLabel(spec.name, spec);
309
- const spinner = createSpinner(`${label} · 处理中…`);
310
- if (process.stderr.isTTY)
311
- spinner.start();
312
- const merged = enrichUploadParamsIfNeeded(spec.name, opts);
313
- const invoker = new ToolInvoker();
314
- const result = await invoker.invoke(spec.name, merged, {
315
- async: spec.async && !!opts.async,
316
- timeout: spec.timeout,
317
- });
318
- if (process.stderr.isTTY) {
319
- if (result.status === "completed")
320
- spinner.succeed(`${label} · 已完成`);
321
- else if (result.status === "failed")
322
- spinner.fail(`${label} · 失败`);
323
- else
324
- spinner.stop();
325
- }
326
- const format = resolveInvokeOutputFormat(sub.parent ?? sub);
327
- if (shouldEmitEnvelope(format)) {
328
- emitJson(wrapEnvelope(result, { command: `tools ${commandName}`, tool_id: spec.name }));
329
- }
330
- else {
331
- formatOutput(result, format, { activityLabel: label });
332
- }
333
- })(...args);
334
- }));
335
- appendToolQuickExample(cmd, spec.name);
336
- }
337
- const TOOLS_HELP = `
338
- gd-cli tools <command> [options]
339
-
340
- 用于调用一个独立能力,例如图片生成、抠图、高清化、标题生成、提示词扩写、视频生成。
341
- 如果你要完成完整业务场景,请优先查看 workflows。
342
-
343
- 常用命令:
344
- list/ls 列出内置 Tools
345
- info <tool-id> 查看具体 Tool 详情
346
- call <tool-id> 调用具体 Tool 能力
347
- manifest 输出 Tools 能力清单
348
- schema <tool-id> 查看输入/输出 Schema
349
- examples <tool-id> 查看调用示例
350
-
351
- 分类:
352
- image 生图、抠图、高清化、SVG
353
- video 文生视频、图生视频
354
- text 标题、提示词、文案
355
- asset 临时上传、CDN URL
356
-
357
- 示例:
358
- gd-cli tools list --category image
359
- gd-cli tools info image.generate
360
- gd-cli tools schema image.generate
361
- gd-cli tools call image.generate --input prompt.json --format json
362
- `;
363
- function toPublicToolPayload(tool) {
364
- const { endpoint: _endpoint, method: _method, runtime: _runtime, required_env: _requiredEnv, ...publicTool } = tool;
365
- return {
366
- ...publicTool,
367
- ...capabilityMetadata("tool", tool.name),
368
- canonical_command: `gd-cli tools call ${tool.name}`,
369
- schema_command: `gd-cli tools schema ${tool.name} --format json`,
370
- examples_command: `gd-cli tools examples ${tool.name} --format json`,
371
- };
372
- }
373
- const TOOL_CALL_HELP = `
374
-
375
- JSON 输入:
376
- gd-cli tools call image.generate --input prompt.json --format json
377
- cat prompt.json | gd-cli tools call image.generate - --format json
378
- gd-cli tools call text.title --set brief="夏季防晒衣,轻薄透气" --format json
379
-
380
- 说明:
381
- --input <file> 读取 JSON object;位置参数 - 从 stdin 读取 JSON。
382
- 命令行参数会覆盖 JSON 同名字段。
383
- `;
@@ -1,29 +0,0 @@
1
- # GD CLI Tools
2
-
3
- Tool 是可独立调用的单点能力。先发现能力,再读取 schema 或示例:
4
-
5
- ```bash
6
- gd-cli tools list --format json
7
- gd-cli tools info <tool-id> --format json
8
- gd-cli tools schema <tool-id> --format json
9
- gd-cli tools examples <tool-id> --format json
10
- ```
11
-
12
- 执行:
13
-
14
- ```bash
15
- gd-cli tools call <tool-id> --input input.json --format json
16
- ```
17
-
18
- | Tool ID | 能力 | 典型用途 |
19
- | --- | --- | --- |
20
- | `asset.upload` | 素材上传 | 将本地文件转换为可访问的 CDN URL |
21
- | `text.title` | 智能标题 | 根据商品或场景 brief 生成标题 |
22
- | `text.prompt` | 提示词优化 | 根据 brief 和参考图扩写提示词 |
23
- | `image.cutout` | 智能抠图 | 去背景、透明底、白底图 |
24
- | `image.generate` | AI 生图 | 商品主图、海报、场景图、种草图 |
25
- | `image.svg` | 图片转 SVG | 将位图转换为矢量图 |
26
- | `image.super-res` | 高清放大 | 图片高清化、放大、提升分辨率 |
27
- | `video.generate` | AI 视频 | 文生视频、图生视频、动画短片 |
28
-
29
- 复杂输入通过 `--input` 或 stdin 传入。调用后等待 `completed`、`failed` 等终态,再按 `deliverables.md` 交付结果。