feat(openapi): 引入双层 OpenAPI 规范管理 (原始下游 & 包装层工具) 并升级版本至 v0.2.2
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled

This commit is contained in:
gitea committed 2026-08-27 11:29:32 +08:00
1 parent 2dfcf67b00
commit b13959451a
21 files changed
+1435 -12

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
import { getOpenApiSchema, listOpenApiPaths, type OpenApiType } from "../../core/embedded-openapi.js";
import { booleanOption, stringOption } from "../parser.js";
import { printJson, printKeyValue, printTable } from "../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
export async function handleOpenApiCommand(
parsed: CliParsedArgs,
runtime: CliRuntime
): Promise<CliResult> {
const isRaw =
booleanOption(parsed.options, ["raw"]) ||
parsed.action === "raw" ||
parsed.args[0] === "raw";
const type: OpenApiType = isRaw ? "raw" : "wrapped";
const action = parsed.action?.toLowerCase();
switch (action) {
case "paths":
case "list":
case "ls": {
const paths = listOpenApiPaths(type);
if (runtime.jsonMode) {
return {
stdout: printJson({ type, count: paths.length, paths }),
stderr: "",
exitCode: 0,
};
}
const rows = paths.map((p) => [
p.method,
p.path,
p.summary || "-",
p.tags.join(", ") || "-",
]);
const table = printTable(["Method", "Path", "Summary", "Tags"], rows);
const title = isRaw
? "====== 合思/易快报 原生下游 OpenAPI 接口列表 ======"
: "====== hose-use 包装层 OpenAPI 接口列表 ======";
return {
stdout: `${title}\n\n${table}\n\n提示: 运行 hose-use openapi ${isRaw ? "--raw " : ""}可直接输出完整 OpenAPI 3.1.0 JSON\n`,
stderr: "",
exitCode: 0,
};
}
case "info":
case "summary": {
const schema = getOpenApiSchema(type);
const info = (schema.info as Record<string, unknown>) || {};
const servers = ((schema.servers as Array<{ url: string; description?: string }>) || []).map(
(s) => `${s.url} (${s.description || "-"})`
);
const tags = ((schema.tags as Array<{ name: string; description?: string }>) || []).map(
(t) => `${t.name}: ${t.description || ""}`
);
const paths = listOpenApiPaths(type);
const infoObj = {
title: info.title,
version: info.version,
description: info.description,
type,
totalEndpoints: paths.length,
servers,
tags,
};
if (runtime.jsonMode) {
return {
stdout: printJson(infoObj),
stderr: "",
exitCode: 0,
};
}
const out = printKeyValue({
"规范标题": info.title,
"规范版本": info.version,
"规范类型": isRaw ? "原始下游原生 API (Raw Spec)" : "包装层工具 API (Wrapped Spec)",
"接口总数": paths.length,
"描述信息": info.description,
"服务器列表": servers.join("\n "),
"标签分组": tags.join("\n "),
});
return {
stdout: `====== OpenAPI 规范概览 ======\n${out}\n`,
stderr: "",
exitCode: 0,
};
}
case "dump":
case "export":
case "raw":
case undefined:
default: {
const schema = getOpenApiSchema(type);
return {
stdout: `${JSON.stringify(schema, null, 2)}\n`,
stderr: "",
exitCode: 0,
};
}
}
}
+30 -5
View File
@@ -1,5 +1,26 @@
import type { CliParsedArgs } from "./types.js";
const KNOWN_BOOLEAN_FLAGS = new Set([
"raw",
"json",
"j",
"help",
"h",
"version",
"v",
"force",
"f",
"stateless",
"stateful",
"check",
"check-only",
"changelog",
"log",
"local",
"workspace",
"external",
]);
export function parseArgs(rawArgs: string[]): CliParsedArgs {
const options: Record<string, string | boolean | number> = {};
const positional: string[] = [];
@@ -20,12 +41,16 @@ export function parseArgs(rawArgs: string[]): CliParsedArgs {
options[key] = val;
} else {
const key = arg.slice(2);
const next = rawArgs[i + 1];
if (next && !next.startsWith("-")) {
options[key] = next;
i++;
} else {
if (KNOWN_BOOLEAN_FLAGS.has(key)) {
options[key] = true;
} else {
const next = rawArgs[i + 1];
if (next && !next.startsWith("-")) {
options[key] = next;
i++;
} else {
options[key] = true;
}
}
}
continue;
+3
View File
@@ -52,6 +52,7 @@ export function printHelp(): string {
skill Agent Skill 管理 (install, status, dump)
probe 连通性诊断 (probe [corpId])
update 版本自更新与发布记录 (update, update check, update --changelog)
openapi OpenAPI 3.1.0 规范导出 (openapi, openapi --raw, openapi paths, openapi info)
mcp MCP Server 运行 (serve)
version 查看版本信息
@@ -74,5 +75,7 @@ export function printHelp(): string {
hose-use skill install # 安装 Agent 技能到用户目录
hose-use update # 自动检查并升级到最新版本
hose-use update --changelog # 查看版本发布历史
hose-use openapi paths # 查看所有 API 路径与概要一览
hose-use openapi --raw # 导出原生下游全量 OpenAPI 规范
`.trim();
}
+5
View File
@@ -11,6 +11,7 @@ import { handleSkillCommand } from "./commands/skill.js";
import { handleProbeCommand } from "./commands/probe.js";
import { handleMcpCommand } from "./commands/mcp.js";
import { handleUpdateCommand } from "./commands/update.js";
import { handleOpenApiCommand } from "./commands/openapi.js";
import type { CliResult, CliRunOptions } from "./types.js";
export async function runCli(
@@ -70,6 +71,10 @@ export async function runCli(
case "self-update":
case "changelog":
return await handleUpdateCommand(parsed, runtime, options);
case "openapi":
case "schema":
case "spec":
return await handleOpenApiCommand(parsed, runtime);
case "mcp":
case "serve":
return await handleMcpCommand(parsed, options);