Compare commits

..
2 Commits
Author SHA1 Message Date
gitea 0372698ff9 ci: 添加 openapi:all 构建步骤并集成 GitHub 与 Gitea 自动双发布
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled
2026-08-27 11:33:45 +08:00
gitea b13959451a feat(openapi): 引入双层 OpenAPI 规范管理 (原始下游 & 包装层工具) 并升级版本至 v0.2.2
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled
2026-08-27 11:29:32 +08:00
22 changed files with 1496 additions and 12 deletions

No files matched your search

+61
View File
@@ -25,9 +25,15 @@ jobs:
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Generate & bundle OpenAPI
run: bun run openapi:all
- name: Type-check
run: bun run check
- name: Test
run: bun test
- name: Compile multi-target binaries
run: |
mkdir -p dist/bin
@@ -54,3 +60,58 @@ jobs:
gh release view "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1 || gh release create "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" --title "${GITHUB_REF_NAME}" --generate-notes
fi
gh release upload "${GITHUB_REF_NAME}" dist/bin/hose-use-* --repo "${GITHUB_REPOSITORY}" --clobber
- name: Publish Gitea Release
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GITEA_HOST: "https://git.ying-qing.cn"
GITEA_REPO: "gitea/hose-use"
run: |
if [ -z "$GITEA_TOKEN" ]; then
echo "::notice::GITEA_TOKEN secret not configured, skipping Gitea upload."
exit 0
fi
TAG_NAME="${GITHUB_REF_NAME}"
TAG_MSG=$(git tag -l --format='%(contents)' "${TAG_NAME}" | sed '/^$/d')
NOTES="${TAG_MSG:-Automated release for ${TAG_NAME}}"
echo "==> Creating release on Gitea for ${TAG_NAME}..."
RELEASE_RESP=$(curl -s -X POST "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG_NAME}\",\"name\":\"${TAG_NAME}\",\"body\":$(echo "$NOTES" | jq -Rsa .),\"draft\":false,\"prerelease\":false}")
RELEASE_ID=$(echo "$RELEASE_RESP" | jq -r '.id // empty')
if [ -z "$RELEASE_ID" ]; then
RELEASE_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/tags/${TAG_NAME}" | jq -r '.id // empty')
fi
if [ -z "$RELEASE_ID" ]; then
echo "::warning::Failed to create or find Gitea release ID. Response: $RELEASE_RESP"
exit 0
fi
echo "==> Uploading assets to Gitea release ID ${RELEASE_ID}..."
upload_asset() {
local file="$1"
local filename
filename=$(basename "$file")
echo " [start] Uploading ${filename} to Gitea..."
RESP=$(curl -s -m 120 -w "\nHTTP_STATUS:%{http_code}" -X POST "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}/assets?name=${filename}" \
-H "Authorization: token ${GITEA_TOKEN}" \
-F "attachment=@${file}")
STATUS=$(echo "$RESP" | tail -n 1)
echo " [done] ${filename} -> ${STATUS}"
}
pids=()
for file in dist/bin/hose-use-*; do
upload_asset "$file" &
pids+=($!)
done
for pid in "${pids[@]}"; do
wait "$pid" || true
done
echo "✓ Successfully published release assets to Gitea!"
+10 -3
View File
@@ -1,4 +1,4 @@
# hose-use (v0.2.1)
# hose-use (v0.2.2)
合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。
@@ -44,11 +44,18 @@ hose-use workflow find --task=code-js2 # 搜索包含特定节点类型
hose-use workflow toggle <pipelineId> --state=1 # 启用/停用工作流
hose-use platform list # 查看企业下所有启用的自建应用
# 5. Agent Skill 与连通性诊断
# 5. OpenAPI 规范导出 (原始下游契约 & 包装层工具规范)
hose-use openapi paths # 查看包装层 API 路径与概要一览
hose-use openapi --raw paths # 查看合思原生下游全量 API 路径
hose-use openapi info # 查看 OpenAPI 规范元数据概览
hose-use openapi # 输出包装层标准 OpenAPI 3.1.0 JSON
hose-use openapi --raw # 输出原生下游全量 OpenAPI 3.1.0 JSON
# 6. Agent Skill 与连通性诊断
hose-use skill install # 一键将 Agent Skill 安装到 ~/.agents/skills/
hose-use probe # 诊断当前企业主站 Session、EASO 握手与接口连通性
# 6. 一键自更新与版本发布历史
# 7. 一键自更新与版本发布历史
hose-use update # 自动检查并升级到最新版本 (多镜像源加速)
hose-use update --check # 仅检查新版本与 Release Notes
hose-use update --changelog # 查看最近版本发布历史
+3
View File
@@ -7,6 +7,7 @@
"dependencies": {
"@modelcontextprotocol/sdk": "^1.29.0",
"ky": "^2.0.2",
"yaml": "^2.9.0",
"zod": "^4.4.3",
},
"devDependencies": {
@@ -206,6 +207,8 @@
"wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="],
"yaml": ["yaml@2.9.0", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA=="],
"zod": ["zod@4.4.3", "", {}, "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ=="],
"zod-to-json-schema": ["zod-to-json-schema@3.25.2", "", { "peerDependencies": { "zod": "^3.25.28 || ^4" } }, "sha512-O/PgfnpT1xKSDeQYSCfRI5Gy3hPf91mKVDuYLUHZJMiDFptvP41MSnWofm8dnCm0256ZNfZIM7DSzuSMAFnjHA=="],
+130
View File
@@ -0,0 +1,130 @@
ErrorResponse:
type: object
properties:
error:
type: boolean
example: true
message:
type: string
example: 操作失败原因
AuthLoginRequest:
type: object
required:
- phone
- password
properties:
phone:
type: string
description: 登录手机号
example: "17718556446"
password:
type: string
description: 登录明文密码 (由客户端自动完成 RSA 加密)
autoSwitch:
type: boolean
description: 是否自动切换到首个企业
default: true
AuthStatusResponse:
type: object
properties:
loggedIn:
type: boolean
activeCorpId:
type: string
activeCorpName:
type: string
totalAccounts:
type: integer
totalCorps:
type: integer
CorpConfig:
type: object
properties:
corpId:
type: string
description: 企业唯一标识
corpName:
type: string
description: 企业名称
staffId:
type: string
description: 员工身份 ID
accountId:
type: string
description: 归属账号手机号
PlatformItem:
type: object
properties:
id:
type: string
description: 自建应用 ID
name:
type: string
description: 自建应用名称
code:
type: string
description: 应用编码
status:
type: string
description: 应用状态
WorkflowSummary:
type: object
properties:
id:
type: string
description: 工作流 ID
name:
type: string
description: 工作流名称
platformId:
type: string
description: 归属自建应用 ID
platformName:
type: string
description: 归属自建应用名称
state:
type: integer
description: "1: 启用, 0: 停用"
updatedAt:
type: string
WorkflowDetail:
type: object
properties:
id:
type: string
name:
type: string
state:
type: integer
nodes:
type: array
items:
type: object
description: 工作流节点列表 (code-js2, loop, sql 等)
links:
type: array
items:
type: object
ProbeResult:
type: object
properties:
corpId:
type: string
corpName:
type: string
mainSession:
type: boolean
description: 主站会话是否有效
easoToken:
type: boolean
description: EASO 平台 Token 是否有效
platformsReachable:
type: boolean
description: 自建应用接口是否可访问
+46
View File
@@ -0,0 +1,46 @@
openapi: 3.1.0
info:
title: hose-use API & MCP Tools Specification
version: 0.2.2
description: >-
Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows.
servers:
- url: http://localhost:3000
description: Local hose-use CLI / MCP Runtime Gateway
tags:
- name: Auth & SSO
description: 统一认证、多账号管理与 30 天 Token 自动无感续杯
- name: Corps & Tenancy
description: 多企业租户管理与工作空间切换
- name: Platforms
description: 自建应用检索与实例枚举
- name: Workflows
description: 跨自建应用工作流聚合检索、DSL 图谱与启停
- name: Probe & Diagnostics
description: 会话有效性与 EASO 鉴权连通性诊断
paths:
/api/auth/login:
$ref: ./paths/auth.yaml#/login
/api/auth/status:
$ref: ./paths/auth.yaml#/status
/api/auth/refresh:
$ref: ./paths/auth.yaml#/refresh
/api/corps:
$ref: ./paths/corps.yaml#/list
/api/corps/switch:
$ref: ./paths/corps.yaml#/switch
/api/platforms:
$ref: ./paths/platform.yaml#/list
/api/workflows:
$ref: ./paths/workflow.yaml#/list
/api/workflows/find:
$ref: ./paths/workflow.yaml#/find
/api/workflows/{pipelineId}:
$ref: ./paths/workflow.yaml#/detail
/api/workflows/{pipelineId}/toggle:
$ref: ./paths/workflow.yaml#/toggle
/api/probe:
$ref: ./paths/probe.yaml#/probe
components:
schemas:
$ref: ./components/schemas/index.yaml
+68
View File
@@ -0,0 +1,68 @@
login:
post:
tags:
- Auth & SSO
summary: 纯 API 账密自动全流程登录
description: 自动拉取公钥进行 RSA PKCS#1 加密,发起统一认证中心握手并批量获取名下所有企业身份。
operationId: authLogin
requestBody:
required: true
content:
"application/json":
schema:
$ref: ../components/schemas/index.yaml#/AuthLoginRequest
responses:
"200":
description: 登录成功
content:
"application/json":
schema:
type: object
properties:
success:
type: boolean
totalCorps:
type: integer
activeCorp:
$ref: ../components/schemas/index.yaml#/CorpConfig
"401":
description: 账密错误或鉴权失败
content:
"application/json":
schema:
$ref: ../components/schemas/index.yaml#/ErrorResponse
status:
get:
tags:
- Auth & SSO
summary: 查看当前登录与活跃企业状态
description: 查询本地或无状态下的当前账号、工作企业与凭证有效期。
operationId: authStatus
responses:
"200":
description: 状态正常
content:
"application/json":
schema:
$ref: ../components/schemas/index.yaml#/AuthStatusResponse
refresh:
post:
tags:
- Auth & SSO
summary: 批量刷新企业 30 天 AccessToken
description: 自动无感为当前账号名下的所有企业租户更新最新 30 天访问令牌。
operationId: authRefresh
responses:
"200":
description: 刷新完成
content:
"application/json":
schema:
type: object
properties:
refreshed:
type: integer
total:
type: integer
+48
View File
@@ -0,0 +1,48 @@
list:
get:
tags:
- Corps & Tenancy
summary: 列出当前账号名下所有已配置企业租户
description: 支持单账号管理多家企业与同一企业下的多员工身份分层展示。
operationId: listCorps
responses:
"200":
description: 企业租户列表
content:
"application/json":
schema:
type: array
items:
$ref: ../components/schemas/index.yaml#/CorpConfig
switch:
post:
tags:
- Corps & Tenancy
summary: 切换当前工作企业
description: 在有状态模式下切换并记忆工作企业,后续操作自动以该企业身份执行。
operationId: switchCorp
requestBody:
required: true
content:
"application/json":
schema:
type: object
required:
- corpId
properties:
corpId:
type: string
description: 目标企业 ID 或身份 ID (corpId@accountId)
responses:
"200":
description: 切换成功
content:
"application/json":
schema:
type: object
properties:
success:
type: boolean
activeCorp:
$ref: ../components/schemas/index.yaml#/CorpConfig
+23
View File
@@ -0,0 +1,23 @@
list:
get:
tags:
- Platforms
summary: 查询企业下所有启用的自建应用
description: 枚举当前企业已配置的自建应用及 EASO 平台实例。
operationId: listPlatforms
parameters:
- name: corpId
in: query
required: false
schema:
type: string
description: 目标企业 ID (未指定时使用默认工作企业)
responses:
"200":
description: 自建应用列表
content:
"application/json":
schema:
type: array
items:
$ref: ../components/schemas/index.yaml#/PlatformItem
+20
View File
@@ -0,0 +1,20 @@
probe:
get:
tags:
- Probe & Diagnostics
summary: 诊断当前企业鉴权与接口连通性
description: 依次校验企业主站 Session Cookie、EASO 换票握手与自建应用接口可访问性。
operationId: probeCorp
parameters:
- name: corpId
in: query
required: false
schema:
type: string
responses:
"200":
description: 诊断报告
content:
"application/json":
schema:
$ref: ../components/schemas/index.yaml#/ProbeResult
+113
View File
@@ -0,0 +1,113 @@
list:
get:
tags:
- Workflows
summary: 跨自建应用汇总查看全部工作流
description: 自动遍历当前企业下所有自建应用,聚合返回全量工作流列表及运行状态。
operationId: listAllWorkflows
parameters:
- name: corpId
in: query
required: false
schema:
type: string
responses:
"200":
description: 聚合工作流列表
content:
"application/json":
schema:
type: array
items:
$ref: ../components/schemas/index.yaml#/WorkflowSummary
find:
get:
tags:
- Workflows
summary: 按节点类型递归搜索工作流
description: 递归解析所有工作流的 DSL 节点图谱,检索包含特定任务类型(如 code-js2, loop, sql 等)的工作流。
operationId: findWorkflowsByTask
parameters:
- name: task
in: query
required: true
schema:
type: string
example: "code-js2"
description: 目标节点任务类型
- name: corpId
in: query
required: false
schema:
type: string
responses:
"200":
description: 匹配的工作流列表
content:
"application/json":
schema:
type: array
items:
$ref: ../components/schemas/index.yaml#/WorkflowSummary
detail:
get:
tags:
- Workflows
summary: 获取单个工作流详情与节点结构
description: 查询指定工作流的完整节点链、输入输出参数映射与触发器配置。
operationId: getWorkflowDetail
parameters:
- name: pipelineId
in: path
required: true
schema:
type: string
description: 工作流 ID
responses:
"200":
description: 工作流详情
content:
"application/json":
schema:
$ref: ../components/schemas/index.yaml#/WorkflowDetail
toggle:
put:
tags:
- Workflows
summary: 启用或停用工作流
description: "切换工作流的运行开关(1: 启用, 0: 停用)。"
operationId: toggleWorkflow
parameters:
- name: pipelineId
in: path
required: true
schema:
type: string
requestBody:
required: true
content:
"application/json":
schema:
type: object
required:
- state
properties:
state:
type: integer
enum: [0, 1]
description: "目标状态 (1=启用, 0=停用)"
responses:
"200":
description: 状态切换成功
content:
"application/json":
schema:
type: object
properties:
success:
type: boolean
state:
type: integer
+5 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hose-use",
"version": "0.2.1",
"version": "0.2.2",
"module": "src/server.ts",
"type": "module",
"bin": {
@@ -14,6 +14,9 @@
"typecheck": "tsc --noEmit",
"test": "bun test",
"bump": "bun run scripts/bump-version.ts",
"openapi:bundle": "bun run scripts/bundle-openapi.ts",
"openapi:generate-raw": "bun run scripts/generate-raw-openapi.ts",
"openapi:all": "bun run scripts/generate-raw-openapi.ts && bun run scripts/bundle-openapi.ts",
"build:binary": "node scripts/build-binary.mjs",
"dev": "bun run --watch src/server.ts",
"start": "bun run src/server.ts",
@@ -22,6 +25,7 @@
"dependencies": {
"@modelcontextprotocol/sdk": "^1.29.0",
"ky": "^2.0.2",
"yaml": "^2.9.0",
"zod": "^4.4.3"
},
"devDependencies": {
+14 -1
View File
@@ -54,7 +54,16 @@ skillContent = skillContent.replace(/# hose-use \(v[\d.]+\)/g, `# hose-use (v${n
writeFileSync(skillPath, skillContent);
console.log("✓ Updated skills/hose-use/SKILL.md");
// 5. Sync to global ~/.agents/skills/hose-use/ if present
// 5. openapi/openapi.yaml
const openapiPath = join(ROOT, "openapi", "openapi.yaml");
if (existsSync(openapiPath)) {
let openapiContent = readFileSync(openapiPath, "utf-8");
openapiContent = openapiContent.replace(/version: [\d.]+/g, `version: ${nextVersion}`);
writeFileSync(openapiPath, openapiContent);
console.log("✓ Updated openapi/openapi.yaml");
}
// 6. Sync to global ~/.agents/skills/hose-use/ if present
const globalSkillDir = join(process.env.HOME || "", ".agents", "skills", "hose-use");
const { existsSync, cpSync } = await import("node:fs");
if (existsSync(globalSkillDir)) {
@@ -62,6 +71,10 @@ if (existsSync(globalSkillDir)) {
console.log("✓ Synchronized ~/.agents/skills/hose-use/");
}
// 7. Rebuild OpenAPI bundles
console.log("==> Rebuilding OpenAPI bundles...");
execSync("bun run openapi:all", { cwd: ROOT, stdio: "inherit" });
console.log("\n🎉 Successfully bumped version to " + nextVersion + "!");
console.log("\nNext steps to publish:");
console.log(` 1. Update CHANGELOG.md (if exists)`);
+78
View File
@@ -0,0 +1,78 @@
#!/usr/bin/env bun
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import YAML from "yaml";
type Json = null | boolean | number | string | Json[] | { [key: string]: Json };
const inputFile = resolve("openapi/openapi.yaml");
const outputFile = resolve("dist/openapi.json");
const bundled = bundle(inputFile, new Set());
mkdirSync(dirname(outputFile), { recursive: true });
writeFileSync(outputFile, `${JSON.stringify(bundled, null, 2)}\n`);
console.log(`✓ Bundled wrapped OpenAPI: ${outputFile}`);
function bundle(filePath: string, seen: Set<string>): Json {
const absolutePath = resolve(filePath);
if (seen.has(absolutePath)) {
throw new Error(`Circular OpenAPI reference: ${absolutePath}`);
}
const parsed = YAML.parse(readFileSync(absolutePath, "utf8")) as Json;
return resolveReferences(parsed, absolutePath, new Set([...seen, absolutePath]));
}
function resolveReferences(value: Json, currentFile: string, seen: Set<string>): Json {
if (Array.isArray(value)) {
return value.map((item) => resolveReferences(item, currentFile, seen));
}
if (!isObject(value)) return value;
if (typeof value.$ref === "string" && isFileReference(value.$ref)) {
const [refPath, pointer = ""] = value.$ref.split("#");
const refFile = refPath ? resolve(dirname(currentFile), refPath) : currentFile;
const target = pointer ? resolvePointer(bundle(refFile, seen), pointer) : bundle(refFile, seen);
return resolveReferences(target, refFile, seen);
}
return Object.fromEntries(
Object.entries(value).map(([key, item]) => [
key,
resolveReferences(item as Json, currentFile, seen),
])
);
}
function isFileReference(ref: string) {
return !ref.startsWith("#") && !/^[a-z][a-z0-9+.-]*:/i.test(ref);
}
function resolvePointer(document: Json, pointer: string): Json {
const path = pointer.replace(/^#/, "");
if (!path) return document;
return path
.split("/")
.filter(Boolean)
.map((part) => part.replace(/~1/g, "/").replace(/~0/g, "~"))
.reduce((target: Json, key) => {
if (!isObject(target) && !Array.isArray(target)) {
throw new Error(`Invalid JSON pointer segment "${key}" in ${pointer}`);
}
const next = (target as Record<string, Json>)[key];
if (next === undefined) {
throw new Error(`Missing JSON pointer segment "${key}" in ${pointer}`);
}
return next;
}, document);
}
function isObject(value: Json): value is { [key: string]: Json } {
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
}
+638
View File
@@ -0,0 +1,638 @@
#!/usr/bin/env bun
import { mkdirSync, writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
const outputFile = resolve("dist/raw-hose-openapi.json");
function standardResponse(description: string, dataSchema: any) {
return {
"200": {
description,
content: {
"application/json": {
schema: {
type: "object",
properties: {
data: dataSchema,
code: { type: "string", example: "SUCCESS" },
message: { type: "string", example: "成功" },
},
},
},
},
},
"401": {
description: "未授权或 Token 已失效",
content: {
"application/json": {
schema: { $ref: "#/components/schemas/ErrorResponse" },
},
},
},
"400": {
description: "请求参数错误或鉴权异常",
content: {
"application/json": {
schema: { $ref: "#/components/schemas/ErrorResponse" },
},
},
},
};
}
const spec = {
openapi: "3.1.0",
info: {
title: "Hose / Ekuaibao Downstream Native API",
version: "1.0.0",
description: "Raw downstream Ekuaibao (合思/易快报), EASO, and Piper business API contracts.",
},
servers: [
{
url: "https://app.ekuaibao.com",
description: "合思/易快报主站与统一认证中心",
},
{
url: "https://easo.ekuaibao.com",
description: "合思 EASO 开放平台网关",
},
{
url: "https://piper.ekuaibao.com",
description: "合思 Piper 工作流与集成网关",
},
],
tags: [
{ name: "SSO & Security", description: "统一认证中心、RSA 公钥密码加密与多企业身份切换" },
{ name: "EASO & Piper Auth", description: "开放平台 OAuth2 免登握手、换票与 Token 自动刷新" },
{ name: "Platforms & Apps", description: "自建应用列表与集成检索" },
{ name: "Workflows & Pipelines", description: "跨应用工作流聚合、运行日志、节点详情与启停" },
{ name: "Jobs & Execution", description: "工作流任务运行实例与调试" },
{ name: "Staffs & Webhooks", description: "企业通讯录人员与 Webhook 触发配置" },
],
paths: {
"/api/common/security/getPublicKey": {
post: {
tags: ["SSO & Security"],
summary: "获取统一认证中心 RSA 公钥",
description: "获取用于登录密码加密的 RSA Public Key 模数与指数 (PKCS#1)。",
operationId: "getPublicKey",
responses: {
"200": {
description: "RSA 公钥响应",
content: {
"application/json": {
schema: {
type: "object",
properties: {
value: {
type: "object",
properties: {
publicKey: { type: "string", description: "RSA 公钥字符串" },
modulus: { type: "string", description: "RSA Modulus" },
exponent: { type: "string", description: "RSA Exponent" },
},
},
},
},
},
},
},
},
},
},
"/api/common/login/verifyPhone": {
post: {
tags: ["SSO & Security"],
summary: "手机号与加密密码纯 API 登录",
description: "使用 RSA 加密后的密码和手机号发起统一认证,换取全企业 AccessToken 与 Session Cookie。",
operationId: "loginVerifyPhone",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
required: ["phone", "password"],
properties: {
phone: { type: "string", description: "手机号" },
password: { type: "string", description: "RSA 加密后的密码密文" },
countryCode: { type: "string", default: "+86" },
},
},
},
},
},
responses: {
"200": {
description: "登录成功并下发凭证",
content: {
"application/json": {
schema: {
type: "object",
properties: {
value: {
type: "object",
properties: {
accessToken: { type: "string", description: "全局访问令牌" },
user: {
type: "object",
properties: {
id: { type: "string" },
name: { type: "string" },
phone: { type: "string" },
},
},
},
},
},
},
},
},
},
},
},
},
"/api/common/user/corporations": {
get: {
tags: ["SSO & Security"],
summary: "获取账号名下可访问企业列表",
description: "拉取当前已登录账号授权的所有企业租户及其 Staff 身份。",
operationId: "listCorporations",
responses: {
"200": {
description: "企业与身份列表",
content: {
"application/json": {
schema: {
type: "object",
properties: {
items: {
type: "array",
items: { $ref: "#/components/schemas/CorporationItem" },
},
},
},
},
},
},
},
},
},
"/api/common/user/corporations/{corpId}/switch": {
post: {
tags: ["SSO & Security"],
summary: "切换工作企业上下文",
description: "切换当前会话至指定企业租户,并签发该企业的专属 Session。",
operationId: "switchCorporation",
parameters: [
{ name: "corpId", in: "path", required: true, schema: { type: "string" }, description: "目标企业 ID" },
],
responses: {
"200": {
description: "切换结果",
content: {
"application/json": {
schema: {
type: "object",
properties: {
value: {
type: "object",
properties: {
activeCorpId: { type: "string" },
staffId: { type: "string" },
},
},
},
},
},
},
},
},
},
},
"/api/open/oauth2/auth": {
post: {
tags: ["EASO & Piper Auth"],
summary: "EASO 换票 Step 1: 获取授权码",
description: "使用主站会话 Cookie 和 appKey 获取临时 code。",
operationId: "easoGetAuthCode",
responses: {
"200": {
description: "临时授权码",
content: {
"application/json": {
schema: {
type: "object",
properties: {
code: { type: "string", description: "临时授权码" },
},
},
},
},
},
},
},
},
"/api/open/oauth2/token": {
post: {
tags: ["EASO & Piper Auth"],
summary: "EASO 换票 Step 2: 换取 AccessToken",
description: "使用授权码 code 换取平台接口访问 Token 与 RefreshToken。",
operationId: "easoGetToken",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
required: ["code", "appKey", "appSecret"],
properties: {
code: { type: "string" },
appKey: { type: "string" },
appSecret: { type: "string" },
grant_type: { type: "string", default: "authorization_code" },
},
},
},
},
},
responses: {
"200": {
description: "平台 Token 响应",
content: {
"application/json": {
schema: {
type: "object",
properties: {
access_token: { type: "string" },
refresh_token: { type: "string" },
expires_in: { type: "integer" },
},
},
},
},
},
},
},
},
"/api/open/oauth2/user_info": {
get: {
tags: ["EASO & Piper Auth"],
summary: "EASO 换票 Step 3: 获取当前开放平台用户信息",
description: "使用 AccessToken 获取当前用户的 openId 与企业绑定身份。",
operationId: "easoGetUserInfo",
responses: {
"200": {
description: "用户信息",
content: {
"application/json": {
schema: {
type: "object",
properties: {
openId: { type: "string" },
corpId: { type: "string" },
name: { type: "string" },
},
},
},
},
},
},
},
},
"/api/open/oauth2/token/refresh": {
post: {
tags: ["EASO & Piper Auth"],
summary: "EASO 令牌无感刷新",
description: "使用 refresh_token 换取新的 30 天 accessToken。",
operationId: "easoRefreshToken",
requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
required: ["refresh_token"],
properties: {
refresh_token: { type: "string" },
grant_type: { type: "string", default: "refresh_token" },
},
},
},
},
},
responses: {
"200": {
description: "新 Token",
content: {
"application/json": {
schema: {
type: "object",
properties: {
access_token: { type: "string" },
refresh_token: { type: "string" },
expires_in: { type: "integer" },
},
},
},
},
},
},
},
},
"/api/v2/datalink/platform/search": {
get: {
tags: ["Platforms & Apps"],
summary: "获取企业自建应用列表",
description: "查询指定企业下已启用的自建应用与平台实例列表。",
operationId: "searchPlatforms",
parameters: [
{ name: "corpId", in: "query", required: true, schema: { type: "string" }, description: "企业 ID" },
{ name: "scope", in: "query", schema: { type: "string", default: "enable" } },
],
responses: {
"200": {
description: "应用列表",
content: {
"application/json": {
schema: {
type: "object",
properties: {
items: {
type: "array",
items: { $ref: "#/components/schemas/PlatformItem" },
},
},
},
},
},
},
},
},
},
"/api/easo/pipelines/logs": {
get: {
tags: ["Workflows & Pipelines"],
summary: "获取应用下的工作流列表与日志",
description: "按自建应用 ID 分页查询名下的工作流及最近执行日志。",
operationId: "listWorkflowsByPlatform",
parameters: [
{ name: "platformId", in: "query", required: true, schema: { type: "string" } },
{ name: "number", in: "query", schema: { type: "integer", default: 1 } },
{ name: "pageSize", in: "query", schema: { type: "integer", default: 20 } },
],
responses: standardResponse("工作流分页列表", { $ref: "#/components/schemas/WorkflowPageData" }),
},
},
"/api/easo/stats": {
get: {
tags: ["Workflows & Pipelines"],
summary: "获取工作流运行统计",
description: "统计指定应用下工作流的成功、失败及总触发次数。",
operationId: "getWorkflowStats",
parameters: [
{ name: "platformId", in: "query", required: true, schema: { type: "string" } },
],
responses: standardResponse("工作流运行统计", { $ref: "#/components/schemas/WorkflowStatsData" }),
},
},
"/api/easo/charge": {
get: {
tags: ["Workflows & Pipelines"],
summary: "获取工作流配额与计费信息",
description: "查询当前企业工作流运行调用次数与配额剩余。",
operationId: "getWorkflowCharge",
responses: standardResponse("配额信息", { $ref: "#/components/schemas/WorkflowChargeData" }),
},
},
"/api/easo/pipelines/{pipelineId}": {
get: {
tags: ["Workflows & Pipelines"],
summary: "获取工作流详情与 DSL 节点图",
description: "查询指定工作流的完整配置、触发器与节点链路图谱(code-js2, loop, sql 等)。",
operationId: "getWorkflowDetail",
parameters: [
{ name: "pipelineId", in: "path", required: true, schema: { type: "string" } },
],
responses: standardResponse("工作流完整详情", { $ref: "#/components/schemas/WorkflowDetailData" }),
},
},
"/api/easo/pipelines/state/{pipelineId}": {
put: {
tags: ["Workflows & Pipelines"],
summary: "启用或停用工作流",
description: "切换工作流运行状态(1: 启用, 0: 停用)。",
operationId: "toggleWorkflowState",
parameters: [
{ name: "pipelineId", in: "path", required: true, schema: { type: "string" } },
{ name: "state", in: "query", required: true, schema: { type: "integer", enum: [0, 1] } },
],
responses: {
"200": {
description: "状态更新成功",
},
},
},
},
"/api/easo/jobs/running": {
get: {
tags: ["Jobs & Execution"],
summary: "获取运行中的任务实例",
description: "查询工作流正在执行的调试(DEBUG)或生产(PROD)任务列表。",
operationId: "listRunningJobs",
parameters: [
{ name: "pipelineId", in: "query", required: true, schema: { type: "string" } },
{ name: "runType", in: "query", schema: { type: "string", enum: ["DEBUG", "PROD"], default: "DEBUG" } },
],
responses: standardResponse("任务实例列表", {
type: "array",
items: { $ref: "#/components/schemas/WorkflowJobItem" },
}),
},
},
"/api/easo/dsl/all": {
get: {
tags: ["Workflows & Pipelines"],
summary: "获取企业全部 DSL 规则配置",
description: "查询企业下所有生效的 DSL 脚本规则。",
operationId: "listAllDsl",
responses: standardResponse("DSL 规则列表", {
type: "array",
items: { $ref: "#/components/schemas/WorkflowDslItem" },
}),
},
},
"/api/easo/common/staffs": {
get: {
tags: ["Staffs & Webhooks"],
summary: "获取企业员工通讯录列表",
description: "查询企业内部或外部员工名单,用于工作流执行人与节点通知映射。",
operationId: "listCommonStaffs",
parameters: [
{ name: "external", in: "query", schema: { type: "boolean", default: false } },
],
responses: standardResponse("员工列表", {
type: "array",
items: { $ref: "#/components/schemas/StaffItem" },
}),
},
},
"/api/webhook/{pipelineId}": {
get: {
tags: ["Staffs & Webhooks"],
summary: "获取工作流 Webhook 触发配置",
description: "查询指定工作流的 Webhook URL 入口与密钥配置。",
operationId: "getWebhookInfo",
parameters: [
{ name: "pipelineId", in: "path", required: true, schema: { type: "string" } },
],
responses: standardResponse("Webhook 配置", { $ref: "#/components/schemas/WebhookInfoData" }),
},
},
"/api/easo/pipelines/{pipelineId}/sampleData": {
post: {
tags: ["Workflows & Pipelines"],
summary: "提取工作流调试/采样数据",
description: "触发工作流节点采样数据提取,用于脚本调试与输入校验。",
operationId: "sampleWorkflowData",
parameters: [
{ name: "pipelineId", in: "path", required: true, schema: { type: "string" } },
],
responses: {
"200": {
description: "采样数据",
content: {
"application/json": {
schema: {
type: "object",
properties: {
data: { type: "object" },
type: { type: "string" },
},
},
},
},
},
},
},
},
},
components: {
schemas: {
ErrorResponse: {
type: "object",
properties: {
code: { type: "string" },
message: { type: "string" },
details: { type: "object" },
},
},
CorporationItem: {
type: "object",
properties: {
id: { type: "string", description: "企业 ID" },
name: { type: "string", description: "企业名称" },
staffId: { type: "string", description: "员工 ID" },
role: { type: "string", description: "角色权限" },
},
},
PlatformItem: {
type: "object",
properties: {
id: { type: "string", description: "自建应用 ID" },
name: { type: "string", description: "应用名称" },
code: { type: "string", description: "应用标识 Code" },
icon: { type: "string" },
status: { type: "string" },
},
},
WorkflowPageData: {
type: "object",
properties: {
items: {
type: "array",
items: { $ref: "#/components/schemas/WorkflowItem" },
},
total: { type: "integer" },
number: { type: "integer" },
pageSize: { type: "integer" },
},
},
WorkflowItem: {
type: "object",
properties: {
id: { type: "string" },
name: { type: "string" },
description: { type: "string" },
state: { type: "integer", description: "1: 启用, 0: 停用" },
platformId: { type: "string" },
updatedAt: { type: "string" },
},
},
WorkflowStatsData: {
type: "object",
properties: {
totalCount: { type: "integer" },
successCount: { type: "integer" },
failCount: { type: "integer" },
},
},
WorkflowChargeData: {
type: "object",
properties: {
used: { type: "integer" },
total: { type: "integer" },
remaining: { type: "integer" },
},
},
WorkflowDetailData: {
type: "object",
properties: {
id: { type: "string" },
name: { type: "string" },
state: { type: "integer" },
nodes: { type: "array", items: { type: "object" }, description: "节点列表 (含 code-js2, loop, sql 等)" },
links: { type: "array", items: { type: "object" }, description: "节点连线" },
},
},
WorkflowJobItem: {
type: "object",
properties: {
jobId: { type: "string" },
pipelineId: { type: "string" },
status: { type: "string" },
startTime: { type: "string" },
},
},
WorkflowDslItem: {
type: "object",
properties: {
id: { type: "string" },
name: { type: "string" },
content: { type: "string" },
},
},
StaffItem: {
type: "object",
properties: {
id: { type: "string" },
name: { type: "string" },
email: { type: "string" },
cellphone: { type: "string" },
},
},
WebhookInfoData: {
type: "object",
properties: {
webhookUrl: { type: "string" },
token: { type: "string" },
},
},
},
},
};
mkdirSync(dirname(outputFile), { recursive: true });
writeFileSync(outputFile, `${JSON.stringify(spec, null, 2)}\n`);
console.log(`✓ Generated raw downstream OpenAPI: ${outputFile}`);
+20 -1
View File
@@ -95,7 +95,26 @@ hose-use probe --corp=uzU7pcWfScck00
hose-use mcp serve
```
### 6. 自更新与版本历史 (`hose-use update`)
### 6. OpenAPI 规范导出 (`hose-use openapi`)
```bash
# 查看包装层 API 路径与概要一览
hose-use openapi paths
# 查看合思原生下游全量 API 路径
hose-use openapi --raw paths
# 查看 OpenAPI 规范元数据概览
hose-use openapi info
# 输出包装层标准 OpenAPI 3.1.0 JSON (适合导入 Postman/Swagger/Agent)
hose-use openapi
# 输出原生下游全量 OpenAPI 3.1.0 JSON
hose-use openapi --raw
```
### 7. 自更新与版本历史 (`hose-use update`)
```bash
# 检查最新可用版本与 Release Notes
+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);
+31
View File
@@ -0,0 +1,31 @@
import { describe, expect, test } from "bun:test";
import { getOpenApiSchema, listOpenApiPaths } from "./embedded-openapi.js";
describe("embedded OpenAPI", () => {
test("wrapped OpenAPI contains paths and components", () => {
const wrapped = getOpenApiSchema("wrapped");
expect(wrapped.openapi).toBe("3.1.0");
expect(wrapped.info).toBeDefined();
expect(wrapped.paths).toBeDefined();
expect(Object.keys(wrapped.paths as object).length).toBeGreaterThan(0);
const paths = listOpenApiPaths("wrapped");
expect(paths.length).toBeGreaterThan(0);
expect(paths.some((p) => p.path === "/api/auth/login")).toBe(true);
expect(paths.some((p) => p.path === "/api/workflows")).toBe(true);
});
test("raw downstream OpenAPI contains downstream paths", () => {
const raw = getOpenApiSchema("raw");
expect(raw.openapi).toBe("3.1.0");
expect(raw.info).toBeDefined();
expect(raw.paths).toBeDefined();
expect(Object.keys(raw.paths as object).length).toBeGreaterThan(0);
const paths = listOpenApiPaths("raw");
expect(paths.length).toBeGreaterThan(0);
expect(paths.some((p) => p.path === "/api/common/security/getPublicKey")).toBe(true);
expect(paths.some((p) => p.path === "/api/open/oauth2/token")).toBe(true);
expect(paths.some((p) => p.path === "/api/easo/pipelines/logs")).toBe(true);
});
});
+38
View File
@@ -0,0 +1,38 @@
import wrappedOpenApi from "../../dist/openapi.json" with { type: "json" };
import rawOpenApi from "../../dist/raw-hose-openapi.json" with { type: "json" };
export type OpenApiType = "wrapped" | "raw";
export function getOpenApiSchema(type: OpenApiType = "wrapped"): Record<string, unknown> {
if (type === "raw") {
return rawOpenApi as Record<string, unknown>;
}
return wrappedOpenApi as Record<string, unknown>;
}
export function listOpenApiPaths(type: OpenApiType = "wrapped"): Array<{
path: string;
method: string;
summary: string;
tags: string[];
}> {
const schema = getOpenApiSchema(type);
const paths = (schema.paths as Record<string, Record<string, any>>) || {};
const results: Array<{ path: string; method: string; summary: string; tags: string[] }> = [];
for (const [pathKey, methods] of Object.entries(paths)) {
if (typeof methods !== "object" || methods === null) continue;
for (const [method, def] of Object.entries(methods)) {
if (["get", "post", "put", "delete", "patch"].includes(method.toLowerCase()) && typeof def === "object") {
results.push({
path: pathKey,
method: method.toUpperCase(),
summary: def.summary || def.description || "",
tags: def.tags || [],
});
}
}
}
return results;
}
+1 -1
View File
@@ -1 +1 @@
export const VERSION = "0.2.1";
export const VERSION = "0.2.2";