yuanflow-cli 0.1.0 → 0.1.2

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 (41) 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 +162 -0
  11. package/package.json +57 -6
  12. package/scripts/generate-registry.js +174 -0
  13. package/skills/yuanflow-skill/SKILL.md +60 -0
  14. package/skills/yuanflow-skill/yuanflow-cli/SKILL.md +207 -0
  15. package/src/agent-protocol.js +169 -0
  16. package/src/cli.js +382 -0
  17. package/src/config.js +31 -0
  18. package/src/registry.js +45 -0
  19. package/src/request.js +97 -0
  20. package/src/shortcuts.js +346 -0
  21. package/cli.js +0 -3
  22. package/src/ycloud/cli.js +0 -29
  23. package/src/ycloud/commands/analysis.js +0 -82
  24. package/src/ycloud/commands/auth.js +0 -191
  25. package/src/ycloud/commands/commands.js +0 -262
  26. package/src/ycloud/commands/compliance.js +0 -146
  27. package/src/ycloud/commands/config.js +0 -103
  28. package/src/ycloud/commands/health.js +0 -35
  29. package/src/ycloud/commands/index.js +0 -381
  30. package/src/ycloud/commands/kb.js +0 -82
  31. package/src/ycloud/commands/schema.js +0 -229
  32. package/src/ycloud/commands/shared.js +0 -30
  33. package/src/ycloud/commands/tool-registry.js +0 -209
  34. package/src/ycloud/commands/tool-runner.js +0 -226
  35. package/src/ycloud/commands/tool.js +0 -178
  36. package/src/ycloud/commands/version.js +0 -84
  37. package/src/ycloud/core/config.js +0 -78
  38. package/src/ycloud/core/http.js +0 -133
  39. package/src/ycloud/core/token.js +0 -30
  40. package/src/ycloud/resources/.gitkeep +0 -1
  41. package/src/ycloud/resources/tool_catalog_full.json +0 -1
@@ -1,191 +0,0 @@
1
- import { apiGet } from "../core/http.js";
2
- import { getConfigPath, maskToken } from "../core/config.js";
3
- import { getToken, getTokenWithSource } from "../core/token.js";
4
- import { getGlobalFlagsHelp, parseInteger } from "./shared.js";
5
-
6
- export function getAuthHelp(subcommand) {
7
- if (subcommand === "validate") {
8
- return `Validate current API token
9
-
10
- Usage:
11
- ycloud auth validate [flags]
12
-
13
- Optional Flags:
14
- none
15
-
16
- ${getGlobalFlagsHelp()}
17
-
18
- Examples:
19
- ycloud auth validate --output json
20
-
21
- Read on success:
22
- success
23
- data
24
-
25
- Read on error:
26
- error.code
27
- error.message
28
- error.retryable`;
29
- }
30
-
31
- if (subcommand === "info") {
32
- return `Get current token account info
33
-
34
- Usage:
35
- ycloud auth info [flags]
36
-
37
- Optional Flags:
38
- none
39
-
40
- ${getGlobalFlagsHelp()}
41
-
42
- Examples:
43
- ycloud auth info --output json
44
-
45
- Read on success:
46
- data
47
-
48
- Read on error:
49
- error.code
50
- error.message
51
- error.retryable`;
52
- }
53
-
54
- if (subcommand === "charges") {
55
- return `List token billing charge records
56
-
57
- Usage:
58
- ycloud auth charges [flags]
59
-
60
- Optional Flags:
61
- --model-id string filter by model id
62
- --charge-type string filter by charge type
63
- --user-level string filter by user level
64
- --start-at string ISO datetime start
65
- --end-at string ISO datetime end
66
- --limit int page size, default 20
67
- --offset int offset, default 0
68
-
69
- ${getGlobalFlagsHelp()}
70
-
71
- Examples:
72
- ycloud auth charges --limit 20 --output json
73
-
74
- Read on success:
75
- data
76
-
77
- Read on error:
78
- error.code
79
- error.message
80
- error.retryable`;
81
- }
82
-
83
- if (subcommand === "status") {
84
- return `Show current token source and masked token
85
-
86
- Usage:
87
- ycloud auth status [flags]
88
-
89
- Optional Flags:
90
- none
91
-
92
- ${getGlobalFlagsHelp()}
93
- `;
94
- }
95
-
96
- return `Auth commands
97
-
98
- Usage:
99
- ycloud auth <validate|info|charges|status> [flags]`;
100
- }
101
-
102
- async function requireToken(context) {
103
- const token = await getToken();
104
- if (!token) {
105
- return context.fail(
106
- context.commandName,
107
- "TOKEN_MISSING",
108
- "缺少 YUANCHUANG_API_TOKEN",
109
- 3,
110
- false,
111
- );
112
- }
113
- return token;
114
- }
115
-
116
- export async function executeAuthInfo(context) {
117
- const token = await requireToken(context);
118
- if (typeof token !== "string") {
119
- return token;
120
- }
121
- const data = await apiGet("/v1/auth/info", {
122
- token,
123
- traceId: context.globalOptions.traceId,
124
- timeout: context.globalOptions.timeout,
125
- baseUrl: context.globalOptions.baseUrl,
126
- });
127
- return context.ok("auth info", data);
128
- }
129
-
130
- export async function executeAuthValidate(context) {
131
- const token = await requireToken(context);
132
- if (typeof token !== "string") {
133
- return token;
134
- }
135
- const data = await apiGet("/v1/auth/validate", {
136
- token,
137
- traceId: context.globalOptions.traceId,
138
- timeout: context.globalOptions.timeout,
139
- baseUrl: context.globalOptions.baseUrl,
140
- });
141
- return context.ok("auth validate", data);
142
- }
143
-
144
- export async function executeAuthCharges(context, tokens) {
145
- const token = await requireToken(context);
146
- if (typeof token !== "string") {
147
- return token;
148
- }
149
-
150
- const options = context.parseCommandFlags(tokens);
151
- const query = new URLSearchParams();
152
- const mapping = {
153
- "model-id": "model_id",
154
- "charge-type": "charge_type",
155
- "user-level": "user_level",
156
- "start-at": "start_at",
157
- "end-at": "end_at",
158
- };
159
-
160
- for (const [flag, field] of Object.entries(mapping)) {
161
- if (options[flag] !== undefined) {
162
- query.set(field, String(options[flag]));
163
- }
164
- }
165
-
166
- if (options.limit !== undefined) {
167
- query.set("limit", String(parseInteger(options.limit) ?? 20));
168
- }
169
- if (options.offset !== undefined) {
170
- query.set("offset", String(parseInteger(options.offset) ?? 0));
171
- }
172
-
173
- const suffix = query.toString() ? `?${query.toString()}` : "";
174
- const data = await apiGet(`/v1/auth/charges${suffix}`, {
175
- token,
176
- traceId: context.globalOptions.traceId,
177
- timeout: context.globalOptions.timeout,
178
- baseUrl: context.globalOptions.baseUrl,
179
- });
180
- return context.ok("auth charges", data);
181
- }
182
-
183
- export async function executeAuthStatus(context) {
184
- const { token, source } = await getTokenWithSource();
185
- return context.ok("auth status", {
186
- token_present: Boolean(token),
187
- token_source: source,
188
- token_masked: maskToken(token),
189
- config_path: getConfigPath(),
190
- });
191
- }
@@ -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
- }