gaoding-cli 1.0.0-alpha.5

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 (177) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/LICENSE +21 -0
  3. package/README.md +136 -0
  4. package/SECURITY.md +34 -0
  5. package/dist/bin/gd-cli.d.ts +2 -0
  6. package/dist/bin/gd-cli.js +10 -0
  7. package/dist/src/api/app-runner.d.ts +33 -0
  8. package/dist/src/api/app-runner.js +1177 -0
  9. package/dist/src/api/dam-client.d.ts +111 -0
  10. package/dist/src/api/dam-client.js +897 -0
  11. package/dist/src/api/direct-auth.d.ts +3 -0
  12. package/dist/src/api/direct-auth.js +11 -0
  13. package/dist/src/api/direct-client.d.ts +27 -0
  14. package/dist/src/api/direct-client.js +151 -0
  15. package/dist/src/api/direct-tools.d.ts +43 -0
  16. package/dist/src/api/direct-tools.js +1155 -0
  17. package/dist/src/api/hub-client.d.ts +20 -0
  18. package/dist/src/api/hub-client.js +99 -0
  19. package/dist/src/api/sso-client.d.ts +60 -0
  20. package/dist/src/api/sso-client.js +140 -0
  21. package/dist/src/api/task-poller.d.ts +38 -0
  22. package/dist/src/api/task-poller.js +72 -0
  23. package/dist/src/api/tool-invoker.d.ts +12 -0
  24. package/dist/src/api/tool-invoker.js +11 -0
  25. package/dist/src/api/usage-client.d.ts +39 -0
  26. package/dist/src/api/usage-client.js +179 -0
  27. package/dist/src/auth/credential-store-v2.d.ts +12 -0
  28. package/dist/src/auth/credential-store-v2.js +59 -0
  29. package/dist/src/commands/auth.d.ts +2 -0
  30. package/dist/src/commands/auth.js +191 -0
  31. package/dist/src/commands/dam.d.ts +2 -0
  32. package/dist/src/commands/dam.js +293 -0
  33. package/dist/src/commands/models.d.ts +2 -0
  34. package/dist/src/commands/models.js +78 -0
  35. package/dist/src/commands/org.d.ts +2 -0
  36. package/dist/src/commands/org.js +137 -0
  37. package/dist/src/commands/skills.d.ts +2 -0
  38. package/dist/src/commands/skills.js +213 -0
  39. package/dist/src/commands/tools.d.ts +4 -0
  40. package/dist/src/commands/tools.js +383 -0
  41. package/dist/src/commands/update.d.ts +2 -0
  42. package/dist/src/commands/update.js +167 -0
  43. package/dist/src/commands/usage.d.ts +7 -0
  44. package/dist/src/commands/usage.js +43 -0
  45. package/dist/src/commands/workflows.d.ts +3 -0
  46. package/dist/src/commands/workflows.js +398 -0
  47. package/dist/src/core/auth/auth-provider.d.ts +8 -0
  48. package/dist/src/core/auth/auth-provider.js +12 -0
  49. package/dist/src/core/auth/device-oauth-provider.d.ts +12 -0
  50. package/dist/src/core/auth/device-oauth-provider.js +124 -0
  51. package/dist/src/core/auth/org-manager.d.ts +26 -0
  52. package/dist/src/core/auth/org-manager.js +224 -0
  53. package/dist/src/core/auth/signature.d.ts +19 -0
  54. package/dist/src/core/auth/signature.js +33 -0
  55. package/dist/src/core/auth/types.d.ts +52 -0
  56. package/dist/src/core/auth/types.js +3 -0
  57. package/dist/src/core/output/cli-error.d.ts +5 -0
  58. package/dist/src/core/output/cli-error.js +8 -0
  59. package/dist/src/core/output/detector.d.ts +5 -0
  60. package/dist/src/core/output/detector.js +14 -0
  61. package/dist/src/core/output/engine.d.ts +32 -0
  62. package/dist/src/core/output/engine.js +77 -0
  63. package/dist/src/core/output/envelope.d.ts +40 -0
  64. package/dist/src/core/output/envelope.js +119 -0
  65. package/dist/src/core/output/index.d.ts +4 -0
  66. package/dist/src/core/output/index.js +4 -0
  67. package/dist/src/core/output/live-display.d.ts +15 -0
  68. package/dist/src/core/output/live-display.js +111 -0
  69. package/dist/src/core/output/result-card.d.ts +18 -0
  70. package/dist/src/core/output/result-card.js +39 -0
  71. package/dist/src/core/prompt/index.d.ts +31 -0
  72. package/dist/src/core/prompt/index.js +36 -0
  73. package/dist/src/io.d.ts +14 -0
  74. package/dist/src/io.js +31 -0
  75. package/dist/src/middleware/auth.d.ts +3 -0
  76. package/dist/src/middleware/auth.js +74 -0
  77. package/dist/src/middleware/error-handler.d.ts +3 -0
  78. package/dist/src/middleware/error-handler.js +431 -0
  79. package/dist/src/middleware/interactive-params.d.ts +14 -0
  80. package/dist/src/middleware/interactive-params.js +53 -0
  81. package/dist/src/middleware/output.d.ts +14 -0
  82. package/dist/src/middleware/output.js +546 -0
  83. package/dist/src/models/model-catalog.d.ts +26 -0
  84. package/dist/src/models/model-catalog.js +216 -0
  85. package/dist/src/program.d.ts +2 -0
  86. package/dist/src/program.js +152 -0
  87. package/dist/src/registry/agent-contracts.d.ts +43 -0
  88. package/dist/src/registry/agent-contracts.js +483 -0
  89. package/dist/src/registry/app-loader.d.ts +2 -0
  90. package/dist/src/registry/app-loader.js +70 -0
  91. package/dist/src/registry/direct-registry.d.ts +11 -0
  92. package/dist/src/registry/direct-registry.js +234 -0
  93. package/dist/src/registry/registry-cache.d.ts +10 -0
  94. package/dist/src/registry/registry-cache.js +52 -0
  95. package/dist/src/registry/registry-client.d.ts +28 -0
  96. package/dist/src/registry/registry-client.js +50 -0
  97. package/dist/src/registry/types.d.ts +69 -0
  98. package/dist/src/registry/types.js +1 -0
  99. package/dist/src/tty/auth-presenter.d.ts +3 -0
  100. package/dist/src/tty/auth-presenter.js +21 -0
  101. package/dist/src/update/install-source.d.ts +19 -0
  102. package/dist/src/update/install-source.js +139 -0
  103. package/dist/src/update/notifier.d.ts +2 -0
  104. package/dist/src/update/notifier.js +59 -0
  105. package/dist/src/update/update-checker.d.ts +22 -0
  106. package/dist/src/update/update-checker.js +110 -0
  107. package/dist/src/update/version.d.ts +9 -0
  108. package/dist/src/update/version.js +52 -0
  109. package/dist/src/utils/agent-skill-installer.d.ts +57 -0
  110. package/dist/src/utils/agent-skill-installer.js +389 -0
  111. package/dist/src/utils/capability-metadata.d.ts +18 -0
  112. package/dist/src/utils/capability-metadata.js +88 -0
  113. package/dist/src/utils/capability-presenter.d.ts +4 -0
  114. package/dist/src/utils/capability-presenter.js +190 -0
  115. package/dist/src/utils/config.d.ts +16 -0
  116. package/dist/src/utils/config.js +54 -0
  117. package/dist/src/utils/credential-permissions.d.ts +2 -0
  118. package/dist/src/utils/credential-permissions.js +22 -0
  119. package/dist/src/utils/ecommerce-input-guidance.d.ts +15 -0
  120. package/dist/src/utils/ecommerce-input-guidance.js +85 -0
  121. package/dist/src/utils/endpoints.d.ts +52 -0
  122. package/dist/src/utils/endpoints.js +258 -0
  123. package/dist/src/utils/enrich-upload-params.d.ts +6 -0
  124. package/dist/src/utils/enrich-upload-params.js +11 -0
  125. package/dist/src/utils/entitlement.d.ts +17 -0
  126. package/dist/src/utils/entitlement.js +146 -0
  127. package/dist/src/utils/gd-home.d.ts +7 -0
  128. package/dist/src/utils/gd-home.js +26 -0
  129. package/dist/src/utils/help-verify.d.ts +9 -0
  130. package/dist/src/utils/help-verify.js +41 -0
  131. package/dist/src/utils/input-json.d.ts +3 -0
  132. package/dist/src/utils/input-json.js +61 -0
  133. package/dist/src/utils/list-output-format.d.ts +10 -0
  134. package/dist/src/utils/list-output-format.js +34 -0
  135. package/dist/src/utils/logger.d.ts +6 -0
  136. package/dist/src/utils/logger.js +19 -0
  137. package/dist/src/utils/matting-compose.d.ts +10 -0
  138. package/dist/src/utils/matting-compose.js +45 -0
  139. package/dist/src/utils/open-browser.d.ts +1 -0
  140. package/dist/src/utils/open-browser.js +4 -0
  141. package/dist/src/utils/output-path.d.ts +5 -0
  142. package/dist/src/utils/output-path.js +70 -0
  143. package/dist/src/utils/redact.d.ts +3 -0
  144. package/dist/src/utils/redact.js +96 -0
  145. package/dist/src/utils/reference-image.d.ts +8 -0
  146. package/dist/src/utils/reference-image.js +43 -0
  147. package/dist/src/utils/resolve-app-local-images.d.ts +8 -0
  148. package/dist/src/utils/resolve-app-local-images.js +84 -0
  149. package/dist/src/utils/sensitive-path.d.ts +6 -0
  150. package/dist/src/utils/sensitive-path.js +69 -0
  151. package/dist/src/utils/settings-store.d.ts +42 -0
  152. package/dist/src/utils/settings-store.js +50 -0
  153. package/dist/src/utils/sleep.d.ts +1 -0
  154. package/dist/src/utils/sleep.js +3 -0
  155. package/dist/src/utils/spinner.d.ts +2 -0
  156. package/dist/src/utils/spinner.js +4 -0
  157. package/dist/src/utils/static-help.d.ts +2 -0
  158. package/dist/src/utils/static-help.js +3 -0
  159. package/dist/src/utils/tool-display.d.ts +10 -0
  160. package/dist/src/utils/tool-display.js +55 -0
  161. package/dist/src/utils/transient-network-error.d.ts +4 -0
  162. package/dist/src/utils/transient-network-error.js +40 -0
  163. package/dist/src/utils/url-safety.d.ts +6 -0
  164. package/dist/src/utils/url-safety.js +67 -0
  165. package/dist/src/utils/write-app-deliverables.d.ts +18 -0
  166. package/dist/src/utils/write-app-deliverables.js +386 -0
  167. package/package.json +91 -0
  168. package/skills/gd-cli/SKILL.md +57 -0
  169. package/skills/gd-cli/references/auth.md +31 -0
  170. package/skills/gd-cli/references/deliverables.md +22 -0
  171. package/skills/gd-cli/references/entitlement.md +21 -0
  172. package/skills/gd-cli/references/errors.md +19 -0
  173. package/skills/gd-cli/references/org.md +18 -0
  174. package/skills/gd-cli/references/sop.md +25 -0
  175. package/skills/gd-cli/references/tools.md +29 -0
  176. package/skills/gd-cli/references/update.md +16 -0
  177. package/skills/gd-cli/references/workflows.md +22 -0
@@ -0,0 +1,3 @@
1
+ export type DirectAuthMode = "aksk";
2
+ export declare function resolveDirectAuthMode(): DirectAuthMode;
3
+ export declare function readEnv(...keys: string[]): string | undefined;
@@ -0,0 +1,11 @@
1
+ export function resolveDirectAuthMode() {
2
+ return "aksk";
3
+ }
4
+ export function readEnv(...keys) {
5
+ for (const key of keys) {
6
+ const value = process.env[key]?.trim();
7
+ if (value)
8
+ return value;
9
+ }
10
+ return undefined;
11
+ }
@@ -0,0 +1,27 @@
1
+ import { CredentialStoreV2 } from "../auth/credential-store-v2.js";
2
+ type QueryValue = string | number | boolean | readonly (string | number | boolean)[] | undefined;
3
+ export interface DirectRequestOptions {
4
+ query?: Record<string, QueryValue>;
5
+ headers?: Record<string, string>;
6
+ auth?: boolean;
7
+ }
8
+ export declare class DirectApiError extends Error {
9
+ statusCode: number;
10
+ body: unknown;
11
+ url: string;
12
+ constructor(statusCode: number, body: unknown, url: string);
13
+ }
14
+ export declare class DirectApiClient {
15
+ private baseUrl;
16
+ private storeV2;
17
+ constructor(baseUrl?: string, storeV2?: CredentialStoreV2);
18
+ get<T>(path: string, options?: DirectRequestOptions): Promise<T>;
19
+ post<T>(path: string, body?: unknown, options?: DirectRequestOptions): Promise<T>;
20
+ delete<T>(path: string, options?: DirectRequestOptions): Promise<T>;
21
+ private request;
22
+ private attachAuthHeaders;
23
+ }
24
+ export declare function unwrapEnvelope<T>(value: T | {
25
+ data: T;
26
+ }): T;
27
+ export {};
@@ -0,0 +1,151 @@
1
+ import chalk from "chalk";
2
+ import { CredentialStoreV2 } from "../auth/credential-store-v2.js";
3
+ import { signApiRequest } from "../core/auth/signature.js";
4
+ import { isCredentialsV2 } from "../core/auth/types.js";
5
+ import { CLI_USER_AGENT, resolveApiBase, resolveEndpoints } from "../utils/config.js";
6
+ import { readEnv } from "./direct-auth.js";
7
+ import { redactSensitiveText } from "../utils/redact.js";
8
+ export class DirectApiError extends Error {
9
+ statusCode;
10
+ body;
11
+ url;
12
+ constructor(statusCode, body, url) {
13
+ const extraHint = resolveAuthTypeHint(statusCode, body);
14
+ super(redactSensitiveText(`业务 API 请求失败 [${statusCode}] ${url}: ${formatErrorBody(body)}${extraHint}`));
15
+ this.statusCode = statusCode;
16
+ this.body = body;
17
+ this.url = url;
18
+ this.name = "DirectApiError";
19
+ }
20
+ }
21
+ export class DirectApiClient {
22
+ baseUrl;
23
+ storeV2;
24
+ constructor(baseUrl = resolveApiBase(), storeV2 = new CredentialStoreV2()) {
25
+ this.baseUrl = normalizeBaseUrl(baseUrl);
26
+ this.storeV2 = storeV2;
27
+ }
28
+ async get(path, options) {
29
+ return this.request("GET", path, undefined, options);
30
+ }
31
+ async post(path, body, options) {
32
+ return this.request("POST", path, body, options);
33
+ }
34
+ async delete(path, options) {
35
+ return this.request("DELETE", path, undefined, options);
36
+ }
37
+ async request(method, path, body, options = {}) {
38
+ const url = buildUrl(this.baseUrl, path, options.query);
39
+ const headers = new Headers({
40
+ Accept: "application/json",
41
+ "User-Agent": CLI_USER_AGENT,
42
+ ...defaultBusinessHeaders(this.baseUrl),
43
+ ...(options.headers ?? {}),
44
+ });
45
+ if (body !== undefined) {
46
+ headers.set("Content-Type", "application/json");
47
+ }
48
+ if (options.auth !== false) {
49
+ await this.attachAuthHeaders(headers, method, url);
50
+ }
51
+ const response = await fetch(url.toString(), {
52
+ method,
53
+ headers,
54
+ body: body === undefined ? undefined : JSON.stringify(body),
55
+ });
56
+ const parsed = await parseResponse(response);
57
+ if (!response.ok) {
58
+ throw new DirectApiError(response.status, parsed, url.toString());
59
+ }
60
+ return parsed;
61
+ }
62
+ async attachAuthHeaders(headers, method, url) {
63
+ const v2 = this.storeV2.read();
64
+ if (v2 && isCredentialsV2(v2)) {
65
+ if (!v2.current_org?.id) {
66
+ throw new Error(chalk.yellow("当前未绑定组织:请先执行 gd-cli org switch\n"));
67
+ }
68
+ const { signature, timestamp } = signApiRequest(method, url.pathname, url.searchParams.toString(), v2.sk);
69
+ headers.set("X-AccessKey", v2.ak);
70
+ headers.set("X-Signature", signature);
71
+ headers.set("X-Timestamp", timestamp);
72
+ headers.set("X-Org-Id", v2.current_org.id);
73
+ return;
74
+ }
75
+ console.log("");
76
+ throw new Error(chalk.yellow("先登录并绑定组织:gd-cli auth login\n"));
77
+ }
78
+ }
79
+ export function unwrapEnvelope(value) {
80
+ if (value &&
81
+ typeof value === "object" &&
82
+ "data" in value &&
83
+ value.data !== undefined) {
84
+ return value.data;
85
+ }
86
+ return value;
87
+ }
88
+ function normalizeBaseUrl(value) {
89
+ return value.replace(/\/$/, "");
90
+ }
91
+ function buildUrl(baseUrl, path, query) {
92
+ const normalizedPath = path.replace(/^\//, "");
93
+ const url = new URL(`${baseUrl}/${normalizedPath}`);
94
+ for (const key of Object.keys(query ?? {}).sort()) {
95
+ const value = query?.[key];
96
+ if (value === undefined)
97
+ continue;
98
+ if (Array.isArray(value)) {
99
+ for (const item of value)
100
+ url.searchParams.append(key, String(item));
101
+ }
102
+ else {
103
+ url.searchParams.set(key, String(value));
104
+ }
105
+ }
106
+ return url;
107
+ }
108
+ async function parseResponse(response) {
109
+ const text = await response.text();
110
+ if (!text)
111
+ return null;
112
+ try {
113
+ return JSON.parse(text);
114
+ }
115
+ catch {
116
+ return text;
117
+ }
118
+ }
119
+ function defaultBusinessHeaders(baseUrl) {
120
+ const endpoints = resolveEndpoints();
121
+ const origin = readEnv("GD_ORIGIN", "GAODING_ORIGIN") ??
122
+ endpoints.web_origin.value ??
123
+ originFromBaseUrl(baseUrl);
124
+ const referer = readEnv("GD_REFERER", "GAODING_REFERER") ?? `${origin}/`;
125
+ return Object.fromEntries(Object.entries({
126
+ Origin: origin,
127
+ Referer: referer,
128
+ "x-channel-id": readEnv("GD_CHANNEL_ID", "GAODING_CHANNEL_ID") ??
129
+ endpoints.channel_id.value,
130
+ "x-business-id": readEnv("GD_BUSINESS_ID", "GAODING_BUSINESS_ID") ??
131
+ endpoints.business_id.value,
132
+ }).filter(([, value]) => Boolean(value)));
133
+ }
134
+ function originFromBaseUrl(baseUrl) {
135
+ const parsed = new URL(baseUrl);
136
+ return `${parsed.protocol}//${parsed.host}`;
137
+ }
138
+ function formatErrorBody(body) {
139
+ if (typeof body === "string")
140
+ return body;
141
+ return JSON.stringify(body);
142
+ }
143
+ function resolveAuthTypeHint(statusCode, body) {
144
+ const text = typeof body === "string" ? body : body ? JSON.stringify(body) : "";
145
+ if (statusCode === 401 &&
146
+ /Unsupported Authorization Type/i.test(text)) {
147
+ return ("\n\n当前仅支持 AK/SK 签名鉴权。请重新登录并确认网关支持 X-AccessKey / X-Signature:\n" +
148
+ " gd-cli auth login\n");
149
+ }
150
+ return "";
151
+ }
@@ -0,0 +1,43 @@
1
+ import { DirectApiClient } from "./direct-client.js";
2
+ import type { TaskResult } from "./task-poller.js";
3
+ interface InvokeOptions {
4
+ async?: boolean;
5
+ timeout?: number;
6
+ }
7
+ export declare class MediaResourceError extends Error {
8
+ url?: string | undefined;
9
+ code: string;
10
+ constructor(message: string, url?: string | undefined);
11
+ }
12
+ export declare class DirectToolInvoker {
13
+ private client;
14
+ private dam;
15
+ constructor(client?: DirectApiClient);
16
+ invoke(toolName: string, params: Record<string, unknown>, options?: InvokeOptions): Promise<TaskResult>;
17
+ private handlers;
18
+ private requireRemoteImage;
19
+ private optionalRemoteImage;
20
+ private remoteMedia;
21
+ private uploadPngBuffer;
22
+ private resolveMattingMode;
23
+ private prepareVideoReferenceImage;
24
+ private invokeModelOrderedAsyncTool;
25
+ private resolveDailyCachedModelOrder;
26
+ private resolveSceneCode;
27
+ private resolveToolIntent;
28
+ private callSyncTool;
29
+ private callAsyncTool;
30
+ private pollDifyTask;
31
+ private pollSuperResolution;
32
+ }
33
+ export interface ResolvedNumericContentId {
34
+ value: string;
35
+ generated: boolean;
36
+ requested?: string;
37
+ }
38
+ export declare function resolveNumericContentId(requested?: string): ResolvedNumericContentId;
39
+ export declare function probeReferenceImageUrl(url: string): Promise<void>;
40
+ export declare function isSignedDamReferenceUrl(url: string): boolean;
41
+ export declare function isRiskyVideoReferenceUrl(url: string): boolean;
42
+ export declare function normalizeMediaUrlArguments(args: Record<string, unknown>): Record<string, unknown>;
43
+ export {};