yuanflow-cli 0.1.0 → 0.1.1

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 (39) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +34 -50
  3. package/bin/yuanflow-cli.js +26 -0
  4. package/bin/yuanflow-skill.cjs +334 -0
  5. package/generated/registry.json +24641 -0
  6. package/lib/skill-installer/agents.cjs +203 -0
  7. package/lib/skill-installer/discover-skills.cjs +79 -0
  8. package/lib/skill-installer/installer.cjs +300 -0
  9. package/lib/skill-installer/publish.cjs +53 -0
  10. package/lib/skill-installer/repo-source.cjs +157 -0
  11. package/package.json +56 -6
  12. package/scripts/generate-registry.js +174 -0
  13. package/src/agent-protocol.js +169 -0
  14. package/src/cli.js +382 -0
  15. package/src/config.js +31 -0
  16. package/src/registry.js +45 -0
  17. package/src/request.js +97 -0
  18. package/src/shortcuts.js +346 -0
  19. package/cli.js +0 -3
  20. package/src/ycloud/cli.js +0 -29
  21. package/src/ycloud/commands/analysis.js +0 -82
  22. package/src/ycloud/commands/auth.js +0 -191
  23. package/src/ycloud/commands/commands.js +0 -262
  24. package/src/ycloud/commands/compliance.js +0 -146
  25. package/src/ycloud/commands/config.js +0 -103
  26. package/src/ycloud/commands/health.js +0 -35
  27. package/src/ycloud/commands/index.js +0 -381
  28. package/src/ycloud/commands/kb.js +0 -82
  29. package/src/ycloud/commands/schema.js +0 -229
  30. package/src/ycloud/commands/shared.js +0 -30
  31. package/src/ycloud/commands/tool-registry.js +0 -209
  32. package/src/ycloud/commands/tool-runner.js +0 -226
  33. package/src/ycloud/commands/tool.js +0 -178
  34. package/src/ycloud/commands/version.js +0 -84
  35. package/src/ycloud/core/config.js +0 -78
  36. package/src/ycloud/core/http.js +0 -133
  37. package/src/ycloud/core/token.js +0 -30
  38. package/src/ycloud/resources/.gitkeep +0 -1
  39. package/src/ycloud/resources/tool_catalog_full.json +0 -1
@@ -1,262 +0,0 @@
1
- import { getGlobalFlagsHelp } from "./shared.js";
2
-
3
- export function getCommandsHelp(subcommand) {
4
- if (subcommand === "list") {
5
- return `List all exposed CLI commands for Agent usage
6
-
7
- Usage:
8
- ycloud commands list
9
-
10
- Optional Flags:
11
- none
12
-
13
- ${getGlobalFlagsHelp()}
14
- `;
15
- }
16
-
17
- if (subcommand === "describe") {
18
- return `Describe one exposed command
19
-
20
- Usage:
21
- ycloud commands describe <command-key>
22
-
23
- Optional Flags:
24
- none
25
-
26
- ${getGlobalFlagsHelp()}
27
-
28
- Examples:
29
- ycloud commands describe auth.validate
30
- ycloud commands describe social.bilibili-fetch-one-video-v3
31
- `;
32
- }
33
-
34
- return `Commands discovery
35
-
36
- Usage:
37
- ycloud commands <list|describe> [flags]`;
38
- }
39
-
40
- function buildStaticCommands() {
41
- return [
42
- {
43
- key: "auth.validate",
44
- command: "auth validate",
45
- kind: "api",
46
- description: "Validate current API token",
47
- api_path: "/v1/auth/validate",
48
- method: "GET",
49
- flags: [],
50
- },
51
- {
52
- key: "auth.info",
53
- command: "auth info",
54
- kind: "api",
55
- description: "Get current token account info",
56
- api_path: "/v1/auth/info",
57
- method: "GET",
58
- flags: [],
59
- },
60
- {
61
- key: "auth.charges",
62
- command: "auth charges",
63
- kind: "api",
64
- description: "List token billing charge records",
65
- api_path: "/v1/auth/charges",
66
- method: "GET",
67
- flags: [
68
- { flag: "--model-id", required: false },
69
- { flag: "--charge-type", required: false },
70
- { flag: "--user-level", required: false },
71
- { flag: "--start-at", required: false },
72
- { flag: "--end-at", required: false },
73
- { flag: "--limit", required: false },
74
- { flag: "--offset", required: false },
75
- ],
76
- },
77
- {
78
- key: "auth.status",
79
- command: "auth status",
80
- kind: "local",
81
- description: "Show current token source and masked token",
82
- flags: [],
83
- },
84
- {
85
- key: "health.check",
86
- command: "health check",
87
- kind: "api",
88
- description: "Check cloud service health",
89
- api_path: "/v1/health",
90
- method: "GET",
91
- flags: [],
92
- },
93
- {
94
- key: "version.check",
95
- command: "version check",
96
- kind: "api",
97
- description: "Check remote version update information",
98
- api_path: "/v1/version/check",
99
- method: "GET",
100
- flags: [
101
- { flag: "--app-id", required: false },
102
- { flag: "--platform", required: false },
103
- { flag: "--channel", required: false },
104
- { flag: "--current-version", required: false },
105
- { flag: "--current-build", required: false },
106
- ],
107
- },
108
- {
109
- key: "tool.catalog",
110
- command: "tool catalog",
111
- kind: "api",
112
- description: "List server tool catalog",
113
- api_path: "/v1/tools/catalog",
114
- method: "GET",
115
- flags: [],
116
- },
117
- {
118
- key: "tool.execute",
119
- command: "tool execute",
120
- kind: "local",
121
- description: "Execute only registered tool_id values through CLI",
122
- flags: [
123
- { flag: "--tool-id", required: true },
124
- { flag: "--params", required: false },
125
- { flag: "--params-file", required: false },
126
- { flag: "--session-id", required: false },
127
- { flag: "--idempotency-key", required: false },
128
- ],
129
- },
130
- {
131
- key: "kb.search",
132
- command: "kb search",
133
- kind: "api",
134
- description: "Search knowledge base content",
135
- api_path: "/v1/knowledge-base/search",
136
- method: "POST",
137
- flags: [
138
- { flag: "--query", required: true },
139
- { flag: "--top-k", required: false },
140
- { flag: "--min-score", required: false },
141
- { flag: "--course-name", required: false },
142
- ],
143
- },
144
- {
145
- key: "analysis.creator-profile",
146
- command: "analysis creator-profile",
147
- kind: "api",
148
- description: "Analyze Douyin creator profile",
149
- api_path: "/v1/analysis/douyin/creator-profile",
150
- method: "POST",
151
- flags: [
152
- { flag: "--profile-url", required: true },
153
- { flag: "--video-limit", required: false },
154
- ],
155
- },
156
- {
157
- key: "compliance.check",
158
- command: "compliance check",
159
- kind: "api",
160
- description: "Check compliance risk for content",
161
- api_path: "/v1/compliance/check",
162
- method: "POST",
163
- flags: [
164
- { flag: "--content", required: false },
165
- { flag: "--content-file", required: false },
166
- { flag: "--project-id", required: false },
167
- { flag: "--metadata", required: false },
168
- { flag: "--metadata-file", required: false },
169
- ],
170
- },
171
- {
172
- key: "config.set-token",
173
- command: "config set-token",
174
- kind: "local",
175
- description: "Store token into local CLI config file",
176
- flags: [{ flag: "<token>", required: true }],
177
- },
178
- {
179
- key: "config.get",
180
- command: "config get",
181
- kind: "local",
182
- description: "Read current CLI config",
183
- flags: [],
184
- },
185
- {
186
- key: "config.clear-token",
187
- command: "config clear-token",
188
- kind: "local",
189
- description: "Clear stored token from local CLI config",
190
- flags: [],
191
- },
192
- ];
193
- }
194
-
195
- function buildToolCommands(toolRegistry, catalogMap) {
196
- const rows = [];
197
- for (const [domain, domainConfig] of Object.entries(toolRegistry)) {
198
- for (const [subcommand, commandConfig] of Object.entries(domainConfig.commands)) {
199
- const catalogItem = catalogMap.get(commandConfig.toolId);
200
- const properties = catalogItem?.schema?.properties || {};
201
- const flags = Object.keys(properties).map((name) => ({
202
- flag: `--${name.replace(/_/g, "-")}`,
203
- required: (catalogItem?.schema?.required || []).includes(name),
204
- }));
205
- rows.push({
206
- key: `${domain}.${subcommand}`,
207
- command: `${domain} ${subcommand}`,
208
- kind: "tool",
209
- description: catalogItem?.description || commandConfig.description,
210
- tool_id: commandConfig.toolId,
211
- exposed: true,
212
- flags,
213
- });
214
- }
215
- }
216
- return rows;
217
- }
218
-
219
- export function buildExposedCommands(toolRegistry, catalogMap) {
220
- return [
221
- ...buildStaticCommands().map((item) => ({ ...item, exposed: true })),
222
- ...buildToolCommands(toolRegistry, catalogMap),
223
- ].sort((left, right) => left.command.localeCompare(right.command));
224
- }
225
-
226
- export async function executeCommandsList(context, exposedCommands) {
227
- return context.ok("commands list", {
228
- commands: exposedCommands.map((item) => ({
229
- key: item.key,
230
- command: item.command,
231
- kind: item.kind,
232
- exposed: true,
233
- description: item.description,
234
- })),
235
- });
236
- }
237
-
238
- export async function executeCommandsDescribe(context, tokens, exposedCommands) {
239
- const key = tokens[0];
240
- if (!key) {
241
- return context.fail(
242
- "commands describe",
243
- "BAD_ARGUMENT",
244
- "缺少命令标识,例如 social.bilibili-fetch-one-video-v3",
245
- 2,
246
- false,
247
- );
248
- }
249
-
250
- const match = exposedCommands.find((item) => item.key === key);
251
- if (!match) {
252
- return context.fail(
253
- "commands describe",
254
- "BAD_ARGUMENT",
255
- `未找到命令: ${key}`,
256
- 2,
257
- false,
258
- );
259
- }
260
-
261
- return context.ok("commands describe", match);
262
- }
@@ -1,146 +0,0 @@
1
- import { apiPost } from "../core/http.js";
2
- import { getToken } from "../core/token.js";
3
- import { getGlobalFlagsHelp, parseJsonString } from "./shared.js";
4
-
5
- export function getComplianceHelp() {
6
- return `Check content compliance risk
7
-
8
- Usage:
9
- ycloud compliance check [flags]
10
-
11
- Required Flags:
12
- --content string inline content text
13
- --content-file string UTF-8 text file path
14
-
15
- Optional Flags:
16
- --project-id string project id
17
- --metadata string JSON object string
18
- --metadata-file string local JSON file path
19
-
20
- ${getGlobalFlagsHelp()}
21
-
22
- Examples:
23
- ycloud compliance check --content "这是一个短视频口播文案测试文本" --output json
24
- ycloud compliance check --content-file content.txt --output json
25
-
26
- Read on success:
27
- data.passed
28
- data.issues
29
-
30
- Read on error:
31
- error.code
32
- error.message
33
- error.retryable`;
34
- }
35
-
36
- async function requireToken(context) {
37
- const token = await getToken();
38
- if (!token) {
39
- return context.fail(
40
- context.commandName,
41
- "TOKEN_MISSING",
42
- "缺少 YUANCHUANG_API_TOKEN",
43
- 3,
44
- false,
45
- );
46
- }
47
- return token;
48
- }
49
-
50
- export async function executeComplianceCheck(context, tokens) {
51
- const options = context.parseCommandFlags(tokens);
52
- if (!options.content && !options["content-file"]) {
53
- return context.fail(
54
- "compliance check",
55
- "BAD_ARGUMENT",
56
- "必须提供 --content 或 --content-file",
57
- 2,
58
- false,
59
- );
60
- }
61
- if (options.content && options["content-file"]) {
62
- return context.fail(
63
- "compliance check",
64
- "BAD_ARGUMENT",
65
- "--content 和 --content-file 只能二选一",
66
- 2,
67
- false,
68
- );
69
- }
70
- if (options.metadata && options["metadata-file"]) {
71
- return context.fail(
72
- "compliance check",
73
- "BAD_ARGUMENT",
74
- "--metadata 和 --metadata-file 只能二选一",
75
- 2,
76
- false,
77
- );
78
- }
79
-
80
- const token = await requireToken(context);
81
- if (typeof token !== "string") {
82
- return token;
83
- }
84
-
85
- let content = options.content;
86
- if (options["content-file"]) {
87
- const { readFile } = await import("node:fs/promises");
88
- try {
89
- content = await readFile(options["content-file"], { encoding: "utf-8" });
90
- } catch {
91
- return context.fail(
92
- "compliance check",
93
- "BAD_ARGUMENT",
94
- "--content-file 必须是合法 UTF-8 文本文件",
95
- 2,
96
- false,
97
- );
98
- }
99
- }
100
-
101
- let metadata = undefined;
102
- if (options.metadata) {
103
- try {
104
- metadata = parseJsonString(options.metadata);
105
- } catch {
106
- return context.fail(
107
- "compliance check",
108
- "BAD_ARGUMENT",
109
- "--metadata 必须是合法 JSON",
110
- 2,
111
- false,
112
- );
113
- }
114
- }
115
-
116
- if (options["metadata-file"]) {
117
- const { readFile } = await import("node:fs/promises");
118
- try {
119
- metadata = JSON.parse(
120
- await readFile(options["metadata-file"], { encoding: "utf-8" }),
121
- );
122
- } catch {
123
- return context.fail(
124
- "compliance check",
125
- "BAD_ARGUMENT",
126
- "--metadata-file 必须是合法 JSON 文件",
127
- 2,
128
- false,
129
- );
130
- }
131
- }
132
-
133
- const data = await apiPost("/v1/compliance/check", {
134
- token,
135
- traceId: context.globalOptions.traceId,
136
- timeout: context.globalOptions.timeout,
137
- baseUrl: context.globalOptions.baseUrl,
138
- body: {
139
- project_id: options["project-id"],
140
- content,
141
- metadata,
142
- },
143
- });
144
-
145
- return context.ok("compliance check", data);
146
- }
@@ -1,103 +0,0 @@
1
- import {
2
- clearConfigKey,
3
- getConfigPath,
4
- maskToken,
5
- readConfig,
6
- updateConfig,
7
- } from "../core/config.js";
8
- import { getTokenWithSource } from "../core/token.js";
9
- import { getGlobalFlagsHelp } from "./shared.js";
10
-
11
- export function getConfigHelp(subcommand) {
12
- if (subcommand === "set-token") {
13
- return `Store API token into local CLI config file
14
-
15
- Usage:
16
- ycloud config set-token <token>
17
-
18
- Optional Flags:
19
- none
20
-
21
- ${getGlobalFlagsHelp()}
22
-
23
- Examples:
24
- ycloud config set-token yc-xxxx
25
- `;
26
- }
27
-
28
- if (subcommand === "get") {
29
- return `Read current local CLI config
30
-
31
- Usage:
32
- ycloud config get
33
-
34
- Optional Flags:
35
- none
36
-
37
- ${getGlobalFlagsHelp()}
38
- `;
39
- }
40
-
41
- if (subcommand === "clear-token") {
42
- return `Clear stored API token from local CLI config
43
-
44
- Usage:
45
- ycloud config clear-token
46
-
47
- Optional Flags:
48
- none
49
-
50
- ${getGlobalFlagsHelp()}
51
- `;
52
- }
53
-
54
- return `Config commands
55
-
56
- Usage:
57
- ycloud config <set-token|get|clear-token> [flags]`;
58
- }
59
-
60
- export async function executeConfigSetToken(context, tokens) {
61
- const token = (tokens[0] || "").trim();
62
- if (!token) {
63
- return context.fail(
64
- "config set-token",
65
- "BAD_ARGUMENT",
66
- "缺少 token 参数",
67
- 2,
68
- false,
69
- );
70
- }
71
-
72
- await updateConfig({ token });
73
- return context.ok("config set-token", {
74
- token_present: true,
75
- token_masked: maskToken(token),
76
- token_source: "config",
77
- config_path: getConfigPath(),
78
- });
79
- }
80
-
81
- export async function executeConfigGet(context) {
82
- const config = await readConfig();
83
- const { token, source } = await getTokenWithSource();
84
- return context.ok("config get", {
85
- config_path: getConfigPath(),
86
- token_present: Boolean(token),
87
- token_source: source,
88
- token_masked: maskToken(token),
89
- base_url: config.base_url || null,
90
- default_output: config.default_output || null,
91
- timeout: config.timeout || null,
92
- });
93
- }
94
-
95
- export async function executeConfigClearToken(context) {
96
- await clearConfigKey("token");
97
- return context.ok("config clear-token", {
98
- token_present: false,
99
- token_source: null,
100
- token_masked: null,
101
- config_path: getConfigPath(),
102
- });
103
- }
@@ -1,35 +0,0 @@
1
- import { apiGet } from "../core/http.js";
2
- import { getGlobalFlagsHelp } from "./shared.js";
3
-
4
- export function getHealthHelp() {
5
- return `Check cloud API health
6
-
7
- Usage:
8
- ycloud health check [flags]
9
-
10
- Optional Flags:
11
- none
12
-
13
- ${getGlobalFlagsHelp()}
14
-
15
- Examples:
16
- ycloud health check --output json
17
-
18
- Read on success:
19
- success
20
- data
21
-
22
- Read on error:
23
- error.code
24
- error.message
25
- error.retryable`;
26
- }
27
-
28
- export async function executeHealthCheck(context) {
29
- const data = await apiGet("/v1/health", {
30
- traceId: context.globalOptions.traceId,
31
- timeout: context.globalOptions.timeout,
32
- baseUrl: context.globalOptions.baseUrl,
33
- });
34
- return context.ok("health check", data);
35
- }