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.
- package/LICENSE +1 -1
- package/README.md +34 -50
- package/bin/yuanflow-cli.js +26 -0
- package/bin/yuanflow-skill.cjs +334 -0
- package/generated/registry.json +24641 -0
- package/lib/skill-installer/agents.cjs +203 -0
- package/lib/skill-installer/discover-skills.cjs +79 -0
- package/lib/skill-installer/installer.cjs +300 -0
- package/lib/skill-installer/publish.cjs +53 -0
- package/lib/skill-installer/repo-source.cjs +162 -0
- package/package.json +57 -6
- package/scripts/generate-registry.js +174 -0
- package/skills/yuanflow-skill/SKILL.md +60 -0
- package/skills/yuanflow-skill/yuanflow-cli/SKILL.md +207 -0
- package/src/agent-protocol.js +169 -0
- package/src/cli.js +382 -0
- package/src/config.js +31 -0
- package/src/registry.js +45 -0
- package/src/request.js +97 -0
- package/src/shortcuts.js +346 -0
- package/cli.js +0 -3
- package/src/ycloud/cli.js +0 -29
- package/src/ycloud/commands/analysis.js +0 -82
- package/src/ycloud/commands/auth.js +0 -191
- package/src/ycloud/commands/commands.js +0 -262
- package/src/ycloud/commands/compliance.js +0 -146
- package/src/ycloud/commands/config.js +0 -103
- package/src/ycloud/commands/health.js +0 -35
- package/src/ycloud/commands/index.js +0 -381
- package/src/ycloud/commands/kb.js +0 -82
- package/src/ycloud/commands/schema.js +0 -229
- package/src/ycloud/commands/shared.js +0 -30
- package/src/ycloud/commands/tool-registry.js +0 -209
- package/src/ycloud/commands/tool-runner.js +0 -226
- package/src/ycloud/commands/tool.js +0 -178
- package/src/ycloud/commands/version.js +0 -84
- package/src/ycloud/core/config.js +0 -78
- package/src/ycloud/core/http.js +0 -133
- package/src/ycloud/core/token.js +0 -30
- package/src/ycloud/resources/.gitkeep +0 -1
- package/src/ycloud/resources/tool_catalog_full.json +0 -1
|
@@ -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
|
-
}
|
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
executeAuthCharges,
|
|
3
|
-
executeAuthInfo,
|
|
4
|
-
executeAuthStatus,
|
|
5
|
-
executeAuthValidate,
|
|
6
|
-
getAuthHelp,
|
|
7
|
-
} from "./auth.js";
|
|
8
|
-
import {
|
|
9
|
-
executeAnalysisCreatorProfile,
|
|
10
|
-
getAnalysisHelp,
|
|
11
|
-
} from "./analysis.js";
|
|
12
|
-
import {
|
|
13
|
-
executeComplianceCheck,
|
|
14
|
-
getComplianceHelp,
|
|
15
|
-
} from "./compliance.js";
|
|
16
|
-
import {
|
|
17
|
-
buildExposedCommands,
|
|
18
|
-
executeCommandsDescribe,
|
|
19
|
-
executeCommandsList,
|
|
20
|
-
getCommandsHelp,
|
|
21
|
-
} from "./commands.js";
|
|
22
|
-
import {
|
|
23
|
-
executeConfigClearToken,
|
|
24
|
-
executeConfigGet,
|
|
25
|
-
executeConfigSetToken,
|
|
26
|
-
getConfigHelp,
|
|
27
|
-
} from "./config.js";
|
|
28
|
-
import { executeHealthCheck, getHealthHelp } from "./health.js";
|
|
29
|
-
import { executeKbSearch, getKbHelp } from "./kb.js";
|
|
30
|
-
import { executeSchema, getSchemaHelp } from "./schema.js";
|
|
31
|
-
import { buildToolRegistry } from "./tool-registry.js";
|
|
32
|
-
import {
|
|
33
|
-
createDomainHelp,
|
|
34
|
-
createToolCommandHelp,
|
|
35
|
-
executeRegisteredTool,
|
|
36
|
-
} from "./tool-runner.js";
|
|
37
|
-
import { executeToolCatalog, executeToolExecute, getToolHelp } from "./tool.js";
|
|
38
|
-
import { executeVersionCheck, getVersionHelp } from "./version.js";
|
|
39
|
-
|
|
40
|
-
const TOP_LEVEL_HELP = `YuanFlow CLI local command tool for Agent-friendly cloud API access.
|
|
41
|
-
|
|
42
|
-
USAGE:
|
|
43
|
-
ycloud <command> [subcommand] [flags]
|
|
44
|
-
|
|
45
|
-
EXAMPLES:
|
|
46
|
-
ycloud auth validate --output json
|
|
47
|
-
ycloud tool catalog --output json
|
|
48
|
-
ycloud kb search --query "短视频脚本结构" --top-k 5 --output json
|
|
49
|
-
|
|
50
|
-
GLOBAL FLAGS:
|
|
51
|
-
--output <string> output format: json (default) | text
|
|
52
|
-
--trace-id <string> optional request trace id
|
|
53
|
-
--timeout <int> request timeout in milliseconds
|
|
54
|
-
--base-url <string> override API base URL
|
|
55
|
-
-h, --help show help
|
|
56
|
-
|
|
57
|
-
COMMANDS:
|
|
58
|
-
auth token validation and account info
|
|
59
|
-
health service health check
|
|
60
|
-
version local CLI version info
|
|
61
|
-
tool tool catalog and tool execution
|
|
62
|
-
kb knowledge base search
|
|
63
|
-
analysis creator analysis commands
|
|
64
|
-
compliance compliance checking commands
|
|
65
|
-
config local CLI config management
|
|
66
|
-
commands list and describe exposed commands
|
|
67
|
-
schema inspect command parameter schema from OpenAPI
|
|
68
|
-
content wrapped content generation tools
|
|
69
|
-
social social media atomic tools
|
|
70
|
-
oss oss helper tools
|
|
71
|
-
speech speech helper tools
|
|
72
|
-
`;
|
|
73
|
-
|
|
74
|
-
function parseArgs(rawArgs) {
|
|
75
|
-
const tokens = [...rawArgs];
|
|
76
|
-
const options = {
|
|
77
|
-
output: "json",
|
|
78
|
-
traceId: undefined,
|
|
79
|
-
timeout: undefined,
|
|
80
|
-
baseUrl: undefined,
|
|
81
|
-
help: false,
|
|
82
|
-
};
|
|
83
|
-
const positional = [];
|
|
84
|
-
|
|
85
|
-
for (let index = 0; index < tokens.length; index += 1) {
|
|
86
|
-
const token = tokens[index];
|
|
87
|
-
if (token === "-h" || token === "--help") {
|
|
88
|
-
options.help = true;
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if (token === "--output") {
|
|
92
|
-
options.output = tokens[index + 1] || "json";
|
|
93
|
-
index += 1;
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (token === "--trace-id") {
|
|
97
|
-
options.traceId = tokens[index + 1];
|
|
98
|
-
index += 1;
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
if (token === "--timeout") {
|
|
102
|
-
options.timeout = tokens[index + 1];
|
|
103
|
-
index += 1;
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (token === "--base-url") {
|
|
107
|
-
options.baseUrl = tokens[index + 1];
|
|
108
|
-
index += 1;
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
positional.push(token);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return { positional, options };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function getCommandName(positional) {
|
|
118
|
-
return `${positional[0] || ""} ${positional[1] || ""}`.trim() || "unknown";
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function asJson(command, success, data, error = null, meta = {}, warnings = []) {
|
|
122
|
-
return {
|
|
123
|
-
success,
|
|
124
|
-
command,
|
|
125
|
-
data,
|
|
126
|
-
warnings,
|
|
127
|
-
error,
|
|
128
|
-
meta,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function renderJson(payload) {
|
|
133
|
-
return `${JSON.stringify(payload)}\n`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function renderTextPayload(payload) {
|
|
137
|
-
const lines = [
|
|
138
|
-
`command: ${payload.command}`,
|
|
139
|
-
`success: ${payload.success}`,
|
|
140
|
-
];
|
|
141
|
-
|
|
142
|
-
if (payload.error) {
|
|
143
|
-
lines.push(`error.code: ${payload.error.code}`);
|
|
144
|
-
lines.push(`error.message: ${payload.error.message}`);
|
|
145
|
-
lines.push(`error.retryable: ${payload.error.retryable}`);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (payload.data !== null && payload.data !== undefined) {
|
|
149
|
-
lines.push("data:");
|
|
150
|
-
lines.push(JSON.stringify(payload.data, null, 2));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (payload.meta && Object.keys(payload.meta).length > 0) {
|
|
154
|
-
lines.push("meta:");
|
|
155
|
-
lines.push(JSON.stringify(payload.meta, null, 2));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return `${lines.join("\n")}\n`;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function renderOutput(payload, globalOptions) {
|
|
162
|
-
if (globalOptions.output === "text") {
|
|
163
|
-
return renderTextPayload(payload);
|
|
164
|
-
}
|
|
165
|
-
return renderJson(payload);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function fail(command, code, message, exitCode = 1, retryable = false) {
|
|
169
|
-
const payload = asJson(command, false, null, { code, message, retryable }, {});
|
|
170
|
-
return {
|
|
171
|
-
code: exitCode,
|
|
172
|
-
output: renderOutput(payload, this?.globalOptions || { output: "json" }),
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function ok(command, data, meta = {}) {
|
|
177
|
-
const payload = asJson(command, true, data, null, meta);
|
|
178
|
-
return {
|
|
179
|
-
code: 0,
|
|
180
|
-
output: renderOutput(payload, this?.globalOptions || { output: "json" }),
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function text(commandHelp) {
|
|
185
|
-
return {
|
|
186
|
-
code: 0,
|
|
187
|
-
output: `${commandHelp}\n`,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function parseCommandFlags(tokens) {
|
|
192
|
-
const options = {};
|
|
193
|
-
for (let index = 0; index < tokens.length; index += 1) {
|
|
194
|
-
const token = tokens[index];
|
|
195
|
-
if (!token.startsWith("--")) {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
const name = token.slice(2);
|
|
199
|
-
const next = tokens[index + 1];
|
|
200
|
-
if (!next || next.startsWith("--")) {
|
|
201
|
-
options[name] = true;
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
options[name] = next;
|
|
205
|
-
index += 1;
|
|
206
|
-
}
|
|
207
|
-
return options;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
let cachedToolCatalogMap = null;
|
|
211
|
-
let cachedToolRegistry = null;
|
|
212
|
-
|
|
213
|
-
async function getToolCatalogMap() {
|
|
214
|
-
if (cachedToolCatalogMap) {
|
|
215
|
-
return cachedToolCatalogMap;
|
|
216
|
-
}
|
|
217
|
-
const { readFile } = await import("node:fs/promises");
|
|
218
|
-
const { join } = await import("node:path");
|
|
219
|
-
const { fileURLToPath } = await import("node:url");
|
|
220
|
-
const currentDir = fileURLToPath(new URL(".", import.meta.url));
|
|
221
|
-
const jsonText = await readFile(
|
|
222
|
-
join(currentDir, "..", "resources", "tool_catalog_full.json"),
|
|
223
|
-
"utf8",
|
|
224
|
-
);
|
|
225
|
-
const raw = JSON.parse(jsonText);
|
|
226
|
-
const items = raw.data?.data?.items || [];
|
|
227
|
-
cachedToolCatalogMap = new Map(items.map((item) => [item.tool_id, item]));
|
|
228
|
-
return cachedToolCatalogMap;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
async function getToolRegistry() {
|
|
232
|
-
if (cachedToolRegistry) {
|
|
233
|
-
return cachedToolRegistry;
|
|
234
|
-
}
|
|
235
|
-
const catalogMap = await getToolCatalogMap();
|
|
236
|
-
cachedToolRegistry = buildToolRegistry(catalogMap);
|
|
237
|
-
return cachedToolRegistry;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function buildContext(globalOptions, commandName) {
|
|
241
|
-
return {
|
|
242
|
-
globalOptions,
|
|
243
|
-
commandName,
|
|
244
|
-
ok: ok.bind({ globalOptions }),
|
|
245
|
-
fail: fail.bind({ globalOptions }),
|
|
246
|
-
parseCommandFlags,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export async function executeCommand(rawArgs) {
|
|
251
|
-
const { positional, options } = parseArgs(rawArgs);
|
|
252
|
-
const commandName = getCommandName(positional);
|
|
253
|
-
const context = buildContext(options, commandName);
|
|
254
|
-
const toolRegistry = await getToolRegistry();
|
|
255
|
-
const catalogMap = await getToolCatalogMap();
|
|
256
|
-
const exposedCommands = buildExposedCommands(toolRegistry, catalogMap);
|
|
257
|
-
const allowedToolIds = new Set(
|
|
258
|
-
exposedCommands
|
|
259
|
-
.filter((item) => item.kind === "tool")
|
|
260
|
-
.map((item) => item.tool_id),
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
if (positional.length === 0 || options.help) {
|
|
264
|
-
if (positional.length === 0) {
|
|
265
|
-
return text(TOP_LEVEL_HELP);
|
|
266
|
-
}
|
|
267
|
-
if (positional[0] === "auth") {
|
|
268
|
-
return text(getAuthHelp(positional[1]));
|
|
269
|
-
}
|
|
270
|
-
if (positional[0] === "health") {
|
|
271
|
-
return text(getHealthHelp(positional[1]));
|
|
272
|
-
}
|
|
273
|
-
if (positional[0] === "version") {
|
|
274
|
-
return text(getVersionHelp(positional[1]));
|
|
275
|
-
}
|
|
276
|
-
if (positional[0] === "tool") {
|
|
277
|
-
return text(getToolHelp(positional[1]));
|
|
278
|
-
}
|
|
279
|
-
if (positional[0] === "kb") {
|
|
280
|
-
return text(getKbHelp(positional[1]));
|
|
281
|
-
}
|
|
282
|
-
if (positional[0] === "analysis") {
|
|
283
|
-
return text(getAnalysisHelp(positional[1]));
|
|
284
|
-
}
|
|
285
|
-
if (positional[0] === "compliance") {
|
|
286
|
-
return text(getComplianceHelp(positional[1]));
|
|
287
|
-
}
|
|
288
|
-
if (positional[0] === "config") {
|
|
289
|
-
return text(getConfigHelp(positional[1]));
|
|
290
|
-
}
|
|
291
|
-
if (positional[0] === "commands") {
|
|
292
|
-
return text(getCommandsHelp(positional[1]));
|
|
293
|
-
}
|
|
294
|
-
if (positional[0] === "schema") {
|
|
295
|
-
return text(getSchemaHelp());
|
|
296
|
-
}
|
|
297
|
-
if (toolRegistry[positional[0]]) {
|
|
298
|
-
if (positional[1]) {
|
|
299
|
-
const config = toolRegistry[positional[0]].commands[positional[1]];
|
|
300
|
-
if (config) {
|
|
301
|
-
return text(
|
|
302
|
-
createToolCommandHelp(
|
|
303
|
-
positional[0],
|
|
304
|
-
positional[1],
|
|
305
|
-
config,
|
|
306
|
-
catalogMap.get(config.toolId),
|
|
307
|
-
),
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return text(createDomainHelp(positional[0], toolRegistry[positional[0]], catalogMap));
|
|
312
|
-
}
|
|
313
|
-
return text(TOP_LEVEL_HELP);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (positional[0] === "auth" && positional[1] === "info") {
|
|
317
|
-
return executeAuthInfo(context, positional.slice(2));
|
|
318
|
-
}
|
|
319
|
-
if (positional[0] === "auth" && positional[1] === "validate") {
|
|
320
|
-
return executeAuthValidate(context, positional.slice(2));
|
|
321
|
-
}
|
|
322
|
-
if (positional[0] === "auth" && positional[1] === "charges") {
|
|
323
|
-
return executeAuthCharges(context, positional.slice(2));
|
|
324
|
-
}
|
|
325
|
-
if (positional[0] === "auth" && positional[1] === "status") {
|
|
326
|
-
return executeAuthStatus(context, positional.slice(2));
|
|
327
|
-
}
|
|
328
|
-
if (positional[0] === "health" && positional[1] === "check") {
|
|
329
|
-
return executeHealthCheck(context, positional.slice(2));
|
|
330
|
-
}
|
|
331
|
-
if (positional[0] === "version" && positional[1] === "check") {
|
|
332
|
-
return executeVersionCheck(context, positional.slice(2));
|
|
333
|
-
}
|
|
334
|
-
if (positional[0] === "tool" && positional[1] === "catalog") {
|
|
335
|
-
return executeToolCatalog(context, positional.slice(2));
|
|
336
|
-
}
|
|
337
|
-
if (positional[0] === "tool" && positional[1] === "execute") {
|
|
338
|
-
return executeToolExecute(context, positional.slice(2), allowedToolIds);
|
|
339
|
-
}
|
|
340
|
-
if (positional[0] === "kb" && positional[1] === "search") {
|
|
341
|
-
return executeKbSearch(context, positional.slice(2));
|
|
342
|
-
}
|
|
343
|
-
if (
|
|
344
|
-
positional[0] === "analysis" &&
|
|
345
|
-
positional[1] === "creator-profile"
|
|
346
|
-
) {
|
|
347
|
-
return executeAnalysisCreatorProfile(context, positional.slice(2));
|
|
348
|
-
}
|
|
349
|
-
if (positional[0] === "compliance" && positional[1] === "check") {
|
|
350
|
-
return executeComplianceCheck(context, positional.slice(2));
|
|
351
|
-
}
|
|
352
|
-
if (positional[0] === "config" && positional[1] === "set-token") {
|
|
353
|
-
return executeConfigSetToken(context, positional.slice(2));
|
|
354
|
-
}
|
|
355
|
-
if (positional[0] === "config" && positional[1] === "get") {
|
|
356
|
-
return executeConfigGet(context, positional.slice(2));
|
|
357
|
-
}
|
|
358
|
-
if (positional[0] === "config" && positional[1] === "clear-token") {
|
|
359
|
-
return executeConfigClearToken(context, positional.slice(2));
|
|
360
|
-
}
|
|
361
|
-
if (positional[0] === "commands" && positional[1] === "list") {
|
|
362
|
-
return executeCommandsList(context, exposedCommands);
|
|
363
|
-
}
|
|
364
|
-
if (positional[0] === "commands" && positional[1] === "describe") {
|
|
365
|
-
return executeCommandsDescribe(context, positional.slice(2), exposedCommands);
|
|
366
|
-
}
|
|
367
|
-
if (positional[0] === "schema") {
|
|
368
|
-
return executeSchema(context, positional.slice(1));
|
|
369
|
-
}
|
|
370
|
-
if (toolRegistry[positional[0]]) {
|
|
371
|
-
return executeRegisteredTool(
|
|
372
|
-
context,
|
|
373
|
-
positional.slice(1),
|
|
374
|
-
positional[0],
|
|
375
|
-
toolRegistry[positional[0]],
|
|
376
|
-
catalogMap,
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
return fail(commandName, "UNKNOWN_COMMAND", "未知命令", 1, false);
|
|
381
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { apiPost } from "../core/http.js";
|
|
2
|
-
import { getToken } from "../core/token.js";
|
|
3
|
-
import {
|
|
4
|
-
getGlobalFlagsHelp,
|
|
5
|
-
parseFloatNumber,
|
|
6
|
-
parseInteger,
|
|
7
|
-
} from "./shared.js";
|
|
8
|
-
|
|
9
|
-
export function getKbHelp() {
|
|
10
|
-
return `Search knowledge base content
|
|
11
|
-
|
|
12
|
-
Usage:
|
|
13
|
-
ycloud kb search [flags]
|
|
14
|
-
|
|
15
|
-
Required Flags:
|
|
16
|
-
--query string search keyword
|
|
17
|
-
|
|
18
|
-
Optional Flags:
|
|
19
|
-
--top-k int number of results to return (default 5)
|
|
20
|
-
--min-score float minimum similarity score
|
|
21
|
-
--course-name string course name filter
|
|
22
|
-
|
|
23
|
-
${getGlobalFlagsHelp()}
|
|
24
|
-
|
|
25
|
-
Examples:
|
|
26
|
-
ycloud kb search --query "短视频脚本结构" --top-k 5 --output json
|
|
27
|
-
|
|
28
|
-
Read on success:
|
|
29
|
-
data.hits
|
|
30
|
-
|
|
31
|
-
Read on error:
|
|
32
|
-
error.code
|
|
33
|
-
error.message
|
|
34
|
-
error.retryable`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function requireToken(context) {
|
|
38
|
-
const token = await getToken();
|
|
39
|
-
if (!token) {
|
|
40
|
-
return context.fail(
|
|
41
|
-
context.commandName,
|
|
42
|
-
"TOKEN_MISSING",
|
|
43
|
-
"缺少 YUANCHUANG_API_TOKEN",
|
|
44
|
-
3,
|
|
45
|
-
false,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return token;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export async function executeKbSearch(context, tokens) {
|
|
52
|
-
const options = context.parseCommandFlags(tokens);
|
|
53
|
-
if (!options.query) {
|
|
54
|
-
return context.fail(
|
|
55
|
-
"kb search",
|
|
56
|
-
"BAD_ARGUMENT",
|
|
57
|
-
"缺少必填参数 --query",
|
|
58
|
-
2,
|
|
59
|
-
false,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const token = await requireToken(context);
|
|
64
|
-
if (typeof token !== "string") {
|
|
65
|
-
return token;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const data = await apiPost("/v1/knowledge-base/search", {
|
|
69
|
-
token,
|
|
70
|
-
traceId: context.globalOptions.traceId,
|
|
71
|
-
timeout: context.globalOptions.timeout,
|
|
72
|
-
baseUrl: context.globalOptions.baseUrl,
|
|
73
|
-
body: {
|
|
74
|
-
query: options.query,
|
|
75
|
-
top_k: parseInteger(options["top-k"]) ?? 5,
|
|
76
|
-
min_score: parseFloatNumber(options["min-score"]),
|
|
77
|
-
course_name: options["course-name"],
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return context.ok("kb search", data);
|
|
82
|
-
}
|