Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0372698ff9 | ||
|
|
b13959451a | ||
|
|
2dfcf67b00 | ||
|
|
6e73de697b |
No files matched your search
@@ -25,9 +25,15 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: bun install --frozen-lockfile
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Generate & bundle OpenAPI
|
||||||
|
run: bun run openapi:all
|
||||||
|
|
||||||
- name: Type-check
|
- name: Type-check
|
||||||
run: bun run check
|
run: bun run check
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: bun test
|
||||||
|
|
||||||
- name: Compile multi-target binaries
|
- name: Compile multi-target binaries
|
||||||
run: |
|
run: |
|
||||||
mkdir -p dist/bin
|
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
|
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
|
fi
|
||||||
gh release upload "${GITHUB_REF_NAME}" dist/bin/hose-use-* --repo "${GITHUB_REPOSITORY}" --clobber
|
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!"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# hose-use (v0.2.0)
|
# hose-use (v0.2.2)
|
||||||
|
|
||||||
合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。
|
合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
### 方式一:一键脚本安装独立二进制(推荐)
|
### 方式一:一键脚本安装独立二进制(推荐)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -fsSL https://raw.githubusercontent.com/yunyingk/hose-serve-tool/main/scripts/install.sh | bash
|
curl -fsSL https://raw.githubusercontent.com/yunyingk/hose-use/main/scripts/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
### 方式二:本地 Bun 源码开发
|
### 方式二:本地 Bun 源码开发
|
||||||
@@ -44,9 +44,21 @@ hose-use workflow find --task=code-js2 # 搜索包含特定节点类型
|
|||||||
hose-use workflow toggle <pipelineId> --state=1 # 启用/停用工作流
|
hose-use workflow toggle <pipelineId> --state=1 # 启用/停用工作流
|
||||||
hose-use platform list # 查看企业下所有启用的自建应用
|
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 skill install # 一键将 Agent Skill 安装到 ~/.agents/skills/
|
||||||
hose-use probe # 诊断当前企业主站 Session、EASO 握手与接口连通性
|
hose-use probe # 诊断当前企业主站 Session、EASO 握手与接口连通性
|
||||||
|
|
||||||
|
# 7. 一键自更新与版本发布历史
|
||||||
|
hose-use update # 自动检查并升级到最新版本 (多镜像源加速)
|
||||||
|
hose-use update --check # 仅检查新版本与 Release Notes
|
||||||
|
hose-use update --changelog # 查看最近版本发布历史
|
||||||
```
|
```
|
||||||
|
|
||||||
## 架构
|
## 架构
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.29.0",
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
||||||
"ky": "^2.0.2",
|
"ky": "^2.0.2",
|
||||||
|
"yaml": "^2.9.0",
|
||||||
"zod": "^4.4.3",
|
"zod": "^4.4.3",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -206,6 +207,8 @@
|
|||||||
|
|
||||||
"wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="],
|
"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": ["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=="],
|
"zod-to-json-schema": ["zod-to-json-schema@3.25.2", "", { "peerDependencies": { "zod": "^3.25.28 || ^4" } }, "sha512-O/PgfnpT1xKSDeQYSCfRI5Gy3hPf91mKVDuYLUHZJMiDFptvP41MSnWofm8dnCm0256ZNfZIM7DSzuSMAFnjHA=="],
|
||||||
|
|||||||
@@ -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: 自建应用接口是否可访问
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
+7
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hose-use",
|
"name": "hose-use",
|
||||||
"version": "0.2.0",
|
"version": "0.2.2",
|
||||||
"module": "src/server.ts",
|
"module": "src/server.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -12,6 +12,11 @@
|
|||||||
"probe": "bun run src/cli.ts probe",
|
"probe": "bun run src/cli.ts probe",
|
||||||
"check": "tsc --noEmit",
|
"check": "tsc --noEmit",
|
||||||
"typecheck": "tsc --noEmit",
|
"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",
|
"build:binary": "node scripts/build-binary.mjs",
|
||||||
"dev": "bun run --watch src/server.ts",
|
"dev": "bun run --watch src/server.ts",
|
||||||
"start": "bun run src/server.ts",
|
"start": "bun run src/server.ts",
|
||||||
@@ -20,6 +25,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.29.0",
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
||||||
"ky": "^2.0.2",
|
"ky": "^2.0.2",
|
||||||
|
"yaml": "^2.9.0",
|
||||||
"zod": "^4.4.3"
|
"zod": "^4.4.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
#!/usr/bin/env bun
|
||||||
|
import { readFileSync, writeFileSync } from "node:fs";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { execSync } from "node:child_process";
|
||||||
|
|
||||||
|
const ROOT = join(import.meta.dirname, "..");
|
||||||
|
const pkgPath = join(ROOT, "package.json");
|
||||||
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
||||||
|
const currentVersion: string = pkg.version;
|
||||||
|
|
||||||
|
const input = process.argv[2]?.trim();
|
||||||
|
if (!input) {
|
||||||
|
console.error("Usage: bun run bump <version | patch | minor | major>");
|
||||||
|
console.error(`Current version: ${currentVersion}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let nextVersion = input.replace(/^v/, "");
|
||||||
|
if (input === "patch" || input === "minor" || input === "major") {
|
||||||
|
const [major, minor, patch] = currentVersion.split(".").map(Number);
|
||||||
|
if (input === "patch") nextVersion = `${major}.${minor}.${patch + 1}`;
|
||||||
|
if (input === "minor") nextVersion = `${major}.${minor + 1}.0`;
|
||||||
|
if (input === "major") nextVersion = `${major + 1}.0.0`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$/.test(nextVersion)) {
|
||||||
|
console.error(`Invalid SemVer format: '${nextVersion}'`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`==> Bumping version: ${currentVersion} -> ${nextVersion}`);
|
||||||
|
|
||||||
|
// 1. package.json
|
||||||
|
pkg.version = nextVersion;
|
||||||
|
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
||||||
|
console.log("✓ Updated package.json");
|
||||||
|
|
||||||
|
// 2. src/version.ts
|
||||||
|
const versionTsPath = join(ROOT, "src", "version.ts");
|
||||||
|
writeFileSync(versionTsPath, `export const VERSION = "${nextVersion}";\n`);
|
||||||
|
console.log("✓ Updated src/version.ts");
|
||||||
|
|
||||||
|
// 3. README.md
|
||||||
|
const readmePath = join(ROOT, "README.md");
|
||||||
|
let readmeContent = readFileSync(readmePath, "utf-8");
|
||||||
|
readmeContent = readmeContent.replace(/# hose-use \(v[\d.]+\)/g, `# hose-use (v${nextVersion})`);
|
||||||
|
writeFileSync(readmePath, readmeContent);
|
||||||
|
console.log("✓ Updated README.md");
|
||||||
|
|
||||||
|
// 4. skills/hose-use/SKILL.md
|
||||||
|
const skillPath = join(ROOT, "skills", "hose-use", "SKILL.md");
|
||||||
|
let skillContent = readFileSync(skillPath, "utf-8");
|
||||||
|
skillContent = skillContent.replace(/# hose-use \(v[\d.]+\)/g, `# hose-use (v${nextVersion})`);
|
||||||
|
writeFileSync(skillPath, skillContent);
|
||||||
|
console.log("✓ Updated skills/hose-use/SKILL.md");
|
||||||
|
|
||||||
|
// 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)) {
|
||||||
|
cpSync(join(ROOT, "skills", "hose-use"), globalSkillDir, { recursive: true });
|
||||||
|
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)`);
|
||||||
|
console.log(` 2. git commit -am "chore(release): bump version to v${nextVersion}"`);
|
||||||
|
console.log(` 3. git tag -a v${nextVersion} -m "🚀 Release v${nextVersion}"`);
|
||||||
|
console.log(` 4. git push origin main --tags\n`);
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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}`);
|
||||||
+16
-5
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
REPO="yunyingk/hose-serve-tool"
|
REPO="yunyingk/hose-use"
|
||||||
|
|
||||||
echo "==> Detecting platform and architecture..."
|
echo "==> Detecting platform and architecture..."
|
||||||
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||||||
@@ -118,15 +118,25 @@ TMP_FILE="$(mktemp)"
|
|||||||
DOWNLOAD_SUCCESS=false
|
DOWNLOAD_SUCCESS=false
|
||||||
|
|
||||||
# Candidate mirrors
|
# Candidate mirrors
|
||||||
|
GITEA_URL="https://git.ying-qing.cn/gitea/hose-use/releases/download/latest/${ASSET_NAME}"
|
||||||
GITHUB_URL="https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}"
|
GITHUB_URL="https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}"
|
||||||
GHPROXY_URL="https://ghfast.top/https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}"
|
GHPROXY_URL="https://ghfast.top/https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}"
|
||||||
|
|
||||||
# 1. Try direct GitHub Releases
|
# 1. Try Gitea mirror
|
||||||
if download_candidate "$GITHUB_URL" "$TMP_FILE" "GitHub Releases (Direct)"; then
|
if [ "${HOSE_USE_MIRROR:-auto}" = "gitea" ] || [ "${HOSE_USE_MIRROR:-auto}" = "auto" ]; then
|
||||||
DOWNLOAD_SUCCESS=true
|
if download_candidate "$GITEA_URL" "$TMP_FILE" "Gitea High-Speed Mirror"; then
|
||||||
|
DOWNLOAD_SUCCESS=true
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. Try Fast CDN Proxy Fallback
|
# 2. Try direct GitHub Releases
|
||||||
|
if [ "$DOWNLOAD_SUCCESS" = "false" ]; then
|
||||||
|
if download_candidate "$GITHUB_URL" "$TMP_FILE" "GitHub Releases (Direct)"; then
|
||||||
|
DOWNLOAD_SUCCESS=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 3. Try Fast CDN Proxy Fallback
|
||||||
if [ "$DOWNLOAD_SUCCESS" = "false" ]; then
|
if [ "$DOWNLOAD_SUCCESS" = "false" ]; then
|
||||||
if download_candidate "$GHPROXY_URL" "$TMP_FILE" "Fast CDN Mirror (Fallback)"; then
|
if download_candidate "$GHPROXY_URL" "$TMP_FILE" "Fast CDN Mirror (Fallback)"; then
|
||||||
DOWNLOAD_SUCCESS=true
|
DOWNLOAD_SUCCESS=true
|
||||||
@@ -166,4 +176,5 @@ echo " 1. Login: hose-use auth login --phone=177... --password=..."
|
|||||||
echo " 2. List corps: hose-use corps list"
|
echo " 2. List corps: hose-use corps list"
|
||||||
echo " 3. List workflows: hose-use workflow list"
|
echo " 3. List workflows: hose-use workflow list"
|
||||||
echo " 4. Switch mode: hose-use config mode stateless"
|
echo " 4. Switch mode: hose-use config mode stateless"
|
||||||
|
echo " 5. Self-update: hose-use update"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -95,6 +95,38 @@ hose-use probe --corp=uzU7pcWfScck00
|
|||||||
hose-use mcp serve
|
hose-use mcp serve
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 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
|
||||||
|
hose-use update --check
|
||||||
|
|
||||||
|
# 一键自动下载并升级到最新版本(多源 CDN 加速 + 自动同步 Agent 技能)
|
||||||
|
hose-use update
|
||||||
|
|
||||||
|
# 查看最近版本发布历史与更新说明
|
||||||
|
hose-use update --changelog
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 全局选项
|
## 全局选项
|
||||||
|
|||||||
@@ -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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { describe, expect, test } from "bun:test";
|
||||||
|
import { compareSemVer, isNewerVersion, matchAssetForPlatform, type GitHubAsset } from "./update.js";
|
||||||
|
|
||||||
|
describe("update version comparator", () => {
|
||||||
|
test("correctly identifies newer semantic versions", () => {
|
||||||
|
expect(isNewerVersion("0.2.1", "0.2.0")).toBe(true);
|
||||||
|
expect(isNewerVersion("1.0.0", "0.2.0")).toBe(true);
|
||||||
|
expect(isNewerVersion("0.3.0", "0.2.1")).toBe(true);
|
||||||
|
expect(isNewerVersion("0.2.0", "0.2.0")).toBe(false);
|
||||||
|
expect(isNewerVersion("0.1.9", "0.2.0")).toBe(false);
|
||||||
|
expect(isNewerVersion("0.2.0", "0.2.1")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("compareSemVer handles tags, major, minor, and patch", () => {
|
||||||
|
expect(compareSemVer("v0.2.1", "0.2.0")).toBe(1);
|
||||||
|
expect(compareSemVer("0.2.0", "v0.2.1")).toBe(-1);
|
||||||
|
expect(compareSemVer("v0.2.1", "v0.2.1")).toBe(0);
|
||||||
|
expect(compareSemVer("1.0.0", "0.9.9")).toBe(1);
|
||||||
|
expect(compareSemVer("0.1.0", "0.2.1")).toBe(-1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("matchAssetForPlatform", () => {
|
||||||
|
const assets: GitHubAsset[] = [
|
||||||
|
{ name: "hose-use-darwin-arm64", downloadUrl: "https://example.com/darwin-arm64", size: 100 },
|
||||||
|
{ name: "hose-use-darwin-x64", downloadUrl: "https://example.com/darwin-x64", size: 100 },
|
||||||
|
{ name: "hose-use-linux-x64.tar.gz", downloadUrl: "https://example.com/linux-x64.tar.gz", size: 100 },
|
||||||
|
{ name: "hose-use-linux-arm64", downloadUrl: "https://example.com/linux-arm64", size: 100 },
|
||||||
|
{ name: "hose-use-windows-x64.zip", downloadUrl: "https://example.com/win-x64.zip", size: 100 },
|
||||||
|
];
|
||||||
|
|
||||||
|
test("matches darwin arm64", () => {
|
||||||
|
const matched = matchAssetForPlatform(assets, "darwin", "arm64");
|
||||||
|
expect(matched?.name).toBe("hose-use-darwin-arm64");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("matches darwin x64", () => {
|
||||||
|
const matched = matchAssetForPlatform(assets, "darwin", "x64");
|
||||||
|
expect(matched?.name).toBe("hose-use-darwin-x64");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("matches linux x64 archive", () => {
|
||||||
|
const matched = matchAssetForPlatform(assets, "linux", "x64");
|
||||||
|
expect(matched?.name).toBe("hose-use-linux-x64.tar.gz");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("matches windows x64 archive", () => {
|
||||||
|
const matched = matchAssetForPlatform(assets, "windows", "x64");
|
||||||
|
expect(matched?.name).toBe("hose-use-windows-x64.zip");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,812 @@
|
|||||||
|
import { chmodSync, existsSync, mkdirSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
import { spawnSync } from "node:child_process";
|
||||||
|
import { isCompiledBinary, resolveAppRoot } from "../../core/runtime.js";
|
||||||
|
import { syncGlobalSkillIfPresent } from "../../core/embedded-skill.js";
|
||||||
|
import { VERSION } from "../../version.js";
|
||||||
|
import { booleanOption, numberOption, stringOption } from "../parser.js";
|
||||||
|
import { printJson, printKeyValue } from "../printer.js";
|
||||||
|
import type { CliParsedArgs, CliResult, CliRunOptions, CliRuntime } from "../types.js";
|
||||||
|
|
||||||
|
const DEFAULT_GITHUB_REPO = "yunyingk/hose-use";
|
||||||
|
const GITHUB_REPO_ENV = "HOSE_USE_GITHUB_REPO";
|
||||||
|
|
||||||
|
export type UpdateOptions = {
|
||||||
|
checkOnly?: boolean;
|
||||||
|
changelogOnly?: boolean;
|
||||||
|
limit?: number;
|
||||||
|
force?: boolean;
|
||||||
|
targetVersion?: string;
|
||||||
|
repo?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function handleUpdateCommand(
|
||||||
|
parsed: CliParsedArgs,
|
||||||
|
runtime: CliRuntime,
|
||||||
|
runOptions: CliRunOptions = {}
|
||||||
|
): Promise<CliResult> {
|
||||||
|
const isChangelog =
|
||||||
|
parsed.area === "changelog" ||
|
||||||
|
parsed.action === "changelog" ||
|
||||||
|
parsed.action === "log" ||
|
||||||
|
parsed.action === "history" ||
|
||||||
|
booleanOption(parsed.options, ["changelog", "log", "l"]);
|
||||||
|
|
||||||
|
const isCheck =
|
||||||
|
parsed.action === "check" ||
|
||||||
|
booleanOption(parsed.options, ["check", "check-only", "c"]);
|
||||||
|
|
||||||
|
const targetVersionRaw =
|
||||||
|
stringOption(parsed.options, ["version", "tag", "target", "t"]) ||
|
||||||
|
(!isChangelog && !isCheck && parsed.action && !parsed.action.startsWith("-")
|
||||||
|
? parsed.action
|
||||||
|
: undefined);
|
||||||
|
|
||||||
|
const targetVersion =
|
||||||
|
targetVersionRaw && targetVersionRaw.toLowerCase() !== "latest"
|
||||||
|
? targetVersionRaw.replace(/^v/, "")
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const repo =
|
||||||
|
stringOption(parsed.options, ["repo"]) ||
|
||||||
|
process.env[GITHUB_REPO_ENV]?.trim() ||
|
||||||
|
DEFAULT_GITHUB_REPO;
|
||||||
|
|
||||||
|
const options: UpdateOptions = {
|
||||||
|
checkOnly: isCheck,
|
||||||
|
changelogOnly: isChangelog,
|
||||||
|
limit: numberOption(parsed.options, ["limit", "n"]),
|
||||||
|
force: booleanOption(parsed.options, ["force", "f"]),
|
||||||
|
targetVersion,
|
||||||
|
repo,
|
||||||
|
};
|
||||||
|
|
||||||
|
const appRoot = runOptions.appRoot || resolveAppRoot(runOptions.entryFile);
|
||||||
|
|
||||||
|
// Validate targetVersion: prevent downgrade to older versions
|
||||||
|
if (targetVersion) {
|
||||||
|
const cmp = compareSemVer(targetVersion, VERSION);
|
||||||
|
if (cmp < 0 && !options.force) {
|
||||||
|
const msg = `无法降级 hose-use(当前版本 v${VERSION},目标版本 v${targetVersion})。如需强制重装请使用 --force。`;
|
||||||
|
if (runtime.jsonMode) {
|
||||||
|
return {
|
||||||
|
stdout: printJson({
|
||||||
|
updated: false,
|
||||||
|
currentVersion: VERSION,
|
||||||
|
targetVersion,
|
||||||
|
mode: isCompiledBinary() ? "binary" : "source",
|
||||||
|
message: msg,
|
||||||
|
}),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
stdout: "",
|
||||||
|
stderr: `[ERROR] ${msg}\n`,
|
||||||
|
exitCode: 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (cmp === 0 && !options.force) {
|
||||||
|
const msg = `hose-use 当前已是版本 v${VERSION}。如需强制重装请添加 --force。`;
|
||||||
|
if (runtime.jsonMode) {
|
||||||
|
return {
|
||||||
|
stdout: printJson({
|
||||||
|
updated: false,
|
||||||
|
currentVersion: VERSION,
|
||||||
|
targetVersion,
|
||||||
|
mode: isCompiledBinary() ? "binary" : "source",
|
||||||
|
message: msg,
|
||||||
|
}),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
stdout: `ℹ️ ${msg}\n`,
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Changelog / Release History query
|
||||||
|
if (options.changelogOnly) {
|
||||||
|
const releases = await fetchGitHubReleases(repo, options.limit ?? 10);
|
||||||
|
if (runtime.jsonMode) {
|
||||||
|
return {
|
||||||
|
stdout: printJson({
|
||||||
|
currentVersion: VERSION,
|
||||||
|
totalQueried: releases.length,
|
||||||
|
releases: releases.map((r) => ({
|
||||||
|
version: r.version,
|
||||||
|
tagName: r.tagName,
|
||||||
|
publishedAt: r.publishedAt,
|
||||||
|
author: r.author,
|
||||||
|
releaseNotes: r.notes,
|
||||||
|
releaseUrl: r.htmlUrl,
|
||||||
|
isCurrent: r.version === VERSION,
|
||||||
|
isNewer: isNewerVersion(r.version, VERSION),
|
||||||
|
})),
|
||||||
|
}),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const lines: string[] = [
|
||||||
|
`====== hose-use 版本发布记录 (当前版本: v${VERSION}) ======`,
|
||||||
|
"",
|
||||||
|
];
|
||||||
|
for (const r of releases) {
|
||||||
|
const badge = r.version === VERSION ? " [当前版本]" : isNewerVersion(r.version, VERSION) ? " [新版本 ✨]" : "";
|
||||||
|
lines.push(`• v${r.version} (${r.publishedAt ? r.publishedAt.slice(0, 10) : "未知日期"})${badge}`);
|
||||||
|
if (r.notes) {
|
||||||
|
const snippet = r.notes.trim().split("\n").map((l) => ` ${l}`).join("\n");
|
||||||
|
lines.push(snippet);
|
||||||
|
}
|
||||||
|
lines.push("");
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
stdout: lines.join("\n"),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Source development mode (running via bun/node)
|
||||||
|
if (!isCompiledBinary()) {
|
||||||
|
if (options.checkOnly) {
|
||||||
|
const releases = await fetchGitHubReleases(repo, 30);
|
||||||
|
const latestRelease = releases[0];
|
||||||
|
const latestVersion = latestRelease?.version ?? VERSION;
|
||||||
|
const currentRelease = releases.find((r) => r.version === VERSION);
|
||||||
|
const isUpgrade = isNewerVersion(latestVersion, VERSION);
|
||||||
|
const pendingReleases = releases.filter((r) => isNewerVersion(r.version, VERSION));
|
||||||
|
|
||||||
|
if (runtime.jsonMode) {
|
||||||
|
return {
|
||||||
|
stdout: printJson({
|
||||||
|
updated: false,
|
||||||
|
updateAvailable: isUpgrade,
|
||||||
|
currentVersion: VERSION,
|
||||||
|
currentVersionPublishedAt: currentRelease?.publishedAt,
|
||||||
|
latestVersion,
|
||||||
|
latestVersionPublishedAt: latestRelease?.publishedAt,
|
||||||
|
behindCount: pendingReleases.length,
|
||||||
|
pendingReleases: pendingReleases.map((r) => ({
|
||||||
|
version: r.version,
|
||||||
|
tagName: r.tagName,
|
||||||
|
publishedAt: r.publishedAt,
|
||||||
|
author: r.author,
|
||||||
|
releaseNotes: r.notes,
|
||||||
|
releaseUrl: r.htmlUrl,
|
||||||
|
})),
|
||||||
|
releaseNotes: latestRelease?.notes ?? "",
|
||||||
|
releaseUrl: latestRelease?.htmlUrl ?? "",
|
||||||
|
mode: "source",
|
||||||
|
message: "当前运行于源码开发模式。运行 'hose-use update' 执行 git pull 与依赖更新。",
|
||||||
|
}),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const out = printKeyValue({
|
||||||
|
"运行模式": "源码开发模式 (Source Mode)",
|
||||||
|
"当前版本": `v${VERSION}`,
|
||||||
|
"最新版本": `v${latestVersion} ${isUpgrade ? "(可升级 ✨)" : "(已是最新 ✅)"}`,
|
||||||
|
"待更新版本数": pendingReleases.length,
|
||||||
|
"源码路径": appRoot,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
stdout: `====== hose-use 版本检查 ======\n${out}\n\n${isUpgrade ? `可运行 hose-use update 执行 git pull 与依赖同步` : "已经是最新版本"}\n`,
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
runCommand("git", ["-C", appRoot, "pull", "--ff-only"]);
|
||||||
|
} catch (err) {
|
||||||
|
const msg = err instanceof Error ? err.message : String(err);
|
||||||
|
console.error(`git pull 提示: ${msg}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
runCommand("bun", ["install"], { cwd: appRoot });
|
||||||
|
const skillSync = syncGlobalSkillIfPresent();
|
||||||
|
|
||||||
|
if (runtime.jsonMode) {
|
||||||
|
return {
|
||||||
|
stdout: printJson({
|
||||||
|
updated: true,
|
||||||
|
version: VERSION,
|
||||||
|
mode: "source",
|
||||||
|
skillSynced: skillSync.synced ? skillSync.targetDir : false,
|
||||||
|
}),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
stdout: `[SUCCESS] hose-use 源码与依赖更新成功!\n版本: v${VERSION}\n技能同步: ${skillSync.synced ? "已同步至全局 ✅" : "未同步"}\n`,
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Standalone binary mode: check GitHub Releases
|
||||||
|
const platform = detectPlatform();
|
||||||
|
const arch = detectArch();
|
||||||
|
|
||||||
|
const releases = await fetchGitHubReleases(repo, 30);
|
||||||
|
const release = targetVersion
|
||||||
|
? (releases.find((r) => r.version === targetVersion || r.tagName === targetVersion || r.tagName === `v${targetVersion}`) ??
|
||||||
|
await fetchGitHubRelease(repo, targetVersion))
|
||||||
|
: (releases[0] ?? await fetchGitHubRelease(repo));
|
||||||
|
|
||||||
|
if (!release) {
|
||||||
|
const errorMsg = `无法从 GitHub 仓库 '${repo}' 获取 Release 列表`;
|
||||||
|
if (runtime.jsonMode) {
|
||||||
|
return {
|
||||||
|
stdout: printJson({
|
||||||
|
updated: false,
|
||||||
|
currentVersion: VERSION,
|
||||||
|
mode: "binary",
|
||||||
|
message: errorMsg,
|
||||||
|
}),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
stdout: "",
|
||||||
|
stderr: `[ERROR] ${errorMsg}\n`,
|
||||||
|
exitCode: 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const latestVersion = release.version;
|
||||||
|
const currentRelease = releases.find((r) => r.version === VERSION);
|
||||||
|
const isUpgrade = isNewerVersion(latestVersion, VERSION);
|
||||||
|
const shouldUpdate = isUpgrade || Boolean(options.force);
|
||||||
|
const pendingReleases = releases.filter((r) => isNewerVersion(r.version, VERSION));
|
||||||
|
|
||||||
|
if (options.checkOnly) {
|
||||||
|
if (runtime.jsonMode) {
|
||||||
|
return {
|
||||||
|
stdout: printJson({
|
||||||
|
updated: false,
|
||||||
|
updateAvailable: isUpgrade,
|
||||||
|
currentVersion: VERSION,
|
||||||
|
currentVersionPublishedAt: currentRelease?.publishedAt,
|
||||||
|
latestVersion,
|
||||||
|
latestVersionPublishedAt: release.publishedAt,
|
||||||
|
behindCount: pendingReleases.length,
|
||||||
|
pendingReleases: pendingReleases.map((r) => ({
|
||||||
|
version: r.version,
|
||||||
|
tagName: r.tagName,
|
||||||
|
publishedAt: r.publishedAt,
|
||||||
|
author: r.author,
|
||||||
|
releaseNotes: r.notes,
|
||||||
|
releaseUrl: r.htmlUrl,
|
||||||
|
})),
|
||||||
|
releaseNotes: release.notes,
|
||||||
|
releaseUrl: release.htmlUrl,
|
||||||
|
mode: "binary",
|
||||||
|
}),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const out = printKeyValue({
|
||||||
|
"运行模式": "独立二进制 (Binary Mode)",
|
||||||
|
"当前版本": `v${VERSION}`,
|
||||||
|
"最新版本": `v${latestVersion} ${isUpgrade ? "(可升级 ✨)" : "(已是最新 ✅)"}`,
|
||||||
|
"发布时间": release.publishedAt ? release.publishedAt.slice(0, 10) : "未知",
|
||||||
|
"平台架构": `${platform}-${arch}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
stdout: `====== hose-use 版本检查 ======\n${out}\n\n${isUpgrade ? `运行 hose-use update 升级至 v${latestVersion}` : "已经是最新版本"}\n`,
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shouldUpdate) {
|
||||||
|
if (runtime.jsonMode) {
|
||||||
|
return {
|
||||||
|
stdout: printJson({
|
||||||
|
updated: false,
|
||||||
|
currentVersion: VERSION,
|
||||||
|
currentVersionPublishedAt: currentRelease?.publishedAt,
|
||||||
|
latestVersion,
|
||||||
|
latestVersionPublishedAt: release.publishedAt,
|
||||||
|
mode: "binary",
|
||||||
|
message: `hose-use 当前已是最新版本 (v${VERSION})`,
|
||||||
|
}),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
stdout: `ℹ️ hose-use 当前已是最新版本 (v${VERSION})。如需重装请添加 --force。\n`,
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find matching asset
|
||||||
|
const asset = matchAssetForPlatform(release.assets, platform, arch);
|
||||||
|
if (!asset) {
|
||||||
|
const errorMsg = `未找到适用于 ${platform}-${arch} 平台的 Release 资产 (v${latestVersion})。可用文件: ${release.assets.map((a) => a.name).join(", ")}`;
|
||||||
|
if (runtime.jsonMode) {
|
||||||
|
return {
|
||||||
|
stdout: printJson({ updated: false, error: true, message: errorMsg }),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
stdout: "",
|
||||||
|
stderr: `[ERROR] ${errorMsg}\n`,
|
||||||
|
exitCode: 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const execPath = process.execPath;
|
||||||
|
const execDir = dirname(execPath);
|
||||||
|
const tmpDir = join(execDir, `.tmp-update-${Date.now()}`);
|
||||||
|
mkdirSync(tmpDir, { recursive: true });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const downloadedFile = join(tmpDir, asset.name);
|
||||||
|
await downloadFile(asset.downloadUrl, downloadedFile, release.tagName, asset.name);
|
||||||
|
|
||||||
|
let newBinaryPath = downloadedFile;
|
||||||
|
if (asset.name.endsWith(".tar.gz") || asset.name.endsWith(".tgz")) {
|
||||||
|
newBinaryPath = extractTarGz(downloadedFile, tmpDir, platform);
|
||||||
|
} else if (asset.name.endsWith(".zip")) {
|
||||||
|
newBinaryPath = extractZip(downloadedFile, tmpDir, platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
chmodSync(newBinaryPath, 0o755);
|
||||||
|
|
||||||
|
// Re-sign on macOS ad-hoc if codesign exists
|
||||||
|
if (process.platform === "darwin") {
|
||||||
|
try {
|
||||||
|
spawnSync("/usr/bin/codesign", ["--remove-signature", newBinaryPath], { stdio: "ignore" });
|
||||||
|
spawnSync("/usr/bin/codesign", ["--force", "--sign", "-", newBinaryPath], { stdio: "ignore" });
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Atomic replace
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
const oldBinary = `${execPath}.old.${Date.now()}`;
|
||||||
|
try {
|
||||||
|
renameSync(execPath, oldBinary);
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
renameSync(newBinaryPath, execPath);
|
||||||
|
} else {
|
||||||
|
renameSync(newBinaryPath, execPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
const skillSync = syncGlobalSkillIfPresent();
|
||||||
|
|
||||||
|
if (runtime.jsonMode) {
|
||||||
|
return {
|
||||||
|
stdout: printJson({
|
||||||
|
updated: true,
|
||||||
|
fromVersion: VERSION,
|
||||||
|
toVersion: latestVersion,
|
||||||
|
skillSynced: skillSync.synced ? skillSync.targetDir : false,
|
||||||
|
mode: "binary",
|
||||||
|
}),
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
stdout: `[SUCCESS] ✨ hose-use 已成功升级至 v${latestVersion}!\n可执行文件: ${execPath}\nAgent 技能: ${skillSync.synced ? "已自动同步最新版 ✅" : "未同步"}\n`,
|
||||||
|
stderr: "",
|
||||||
|
exitCode: 0,
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
rmSync(tmpDir, { recursive: true, force: true });
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function detectPlatform(): "darwin" | "linux" | "windows" {
|
||||||
|
if (process.platform === "darwin") return "darwin";
|
||||||
|
if (process.platform === "win32") return "windows";
|
||||||
|
return "linux";
|
||||||
|
}
|
||||||
|
|
||||||
|
function detectArch(): "arm64" | "x64" {
|
||||||
|
return process.arch === "arm64" ? "arm64" : "x64";
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GitHubAsset = {
|
||||||
|
name: string;
|
||||||
|
downloadUrl: string;
|
||||||
|
size: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type GitHubRelease = {
|
||||||
|
version: string;
|
||||||
|
tagName: string;
|
||||||
|
name?: string;
|
||||||
|
publishedAt?: string;
|
||||||
|
author?: string;
|
||||||
|
notes: string;
|
||||||
|
htmlUrl: string;
|
||||||
|
assets: GitHubAsset[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRelease[]> {
|
||||||
|
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
"User-Agent": `hose-use/${VERSION}`,
|
||||||
|
Accept: "application/vnd.github.v3+json",
|
||||||
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const urls = [
|
||||||
|
`https://git.ying-qing.cn/api/v1/repos/gitea/hose-use/releases?per_page=${limit}`,
|
||||||
|
`https://api.github.com/repos/${repo}/releases?per_page=${limit}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const url of urls) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(url, { headers, signal: AbortSignal.timeout(5000) });
|
||||||
|
if (!res.ok) continue;
|
||||||
|
const json = (await res.json()) as Array<{
|
||||||
|
tag_name?: string;
|
||||||
|
name?: string;
|
||||||
|
body?: string;
|
||||||
|
html_url?: string;
|
||||||
|
published_at?: string;
|
||||||
|
author?: { login?: string };
|
||||||
|
assets?: Array<{ name: string; browser_download_url: string; size?: number }>;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
if (!Array.isArray(json) || json.length === 0) continue;
|
||||||
|
|
||||||
|
const list: GitHubRelease[] = [];
|
||||||
|
for (const item of json) {
|
||||||
|
const tagName = item.tag_name ?? "";
|
||||||
|
const version = tagName.replace(/^v/, "");
|
||||||
|
if (!version) continue;
|
||||||
|
const assets: GitHubAsset[] = (item.assets ?? []).map((a) => ({
|
||||||
|
name: a.name,
|
||||||
|
downloadUrl: a.browser_download_url,
|
||||||
|
size: a.size ?? 0,
|
||||||
|
}));
|
||||||
|
list.push({
|
||||||
|
version,
|
||||||
|
tagName,
|
||||||
|
name: item.name ?? tagName,
|
||||||
|
publishedAt: item.published_at,
|
||||||
|
author: item.author?.login,
|
||||||
|
notes: item.body ?? "",
|
||||||
|
htmlUrl: item.html_url ?? "",
|
||||||
|
assets,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (list.length > 0) return list;
|
||||||
|
} catch {
|
||||||
|
// try next source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchGitHubRelease(
|
||||||
|
repo: string,
|
||||||
|
targetVersion?: string
|
||||||
|
): Promise<GitHubRelease | undefined> {
|
||||||
|
const tag = targetVersion ? (targetVersion.startsWith("v") ? targetVersion : `v${targetVersion}`) : undefined;
|
||||||
|
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
"User-Agent": `hose-use/${VERSION}`,
|
||||||
|
Accept: "application/vnd.github.v3+json",
|
||||||
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const urls = tag
|
||||||
|
? [
|
||||||
|
`https://git.ying-qing.cn/api/v1/repos/gitea/hose-use/releases/tags/${tag}`,
|
||||||
|
`https://api.github.com/repos/${repo}/releases/tags/${tag}`,
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
`https://git.ying-qing.cn/api/v1/repos/gitea/hose-use/releases/latest`,
|
||||||
|
`https://api.github.com/repos/${repo}/releases/latest`,
|
||||||
|
];
|
||||||
|
|
||||||
|
let fallbackRelease: GitHubRelease | undefined;
|
||||||
|
|
||||||
|
for (const url of urls) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(url, { headers, signal: AbortSignal.timeout(5000) });
|
||||||
|
if (!res.ok) continue;
|
||||||
|
const json = (await res.json()) as {
|
||||||
|
tag_name?: string;
|
||||||
|
name?: string;
|
||||||
|
body?: string;
|
||||||
|
html_url?: string;
|
||||||
|
published_at?: string;
|
||||||
|
author?: { login?: string };
|
||||||
|
assets?: Array<{ name: string; browser_download_url: string; size?: number }>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const tagName = json.tag_name ?? "";
|
||||||
|
const version = tagName.replace(/^v/, "");
|
||||||
|
if (!version) continue;
|
||||||
|
|
||||||
|
const assets: GitHubAsset[] = (json.assets ?? []).map((item) => ({
|
||||||
|
name: item.name,
|
||||||
|
downloadUrl: item.browser_download_url,
|
||||||
|
size: item.size ?? 0,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const candidateRelease: GitHubRelease = {
|
||||||
|
version,
|
||||||
|
tagName,
|
||||||
|
name: json.name ?? tagName,
|
||||||
|
publishedAt: json.published_at,
|
||||||
|
author: json.author?.login,
|
||||||
|
notes: json.body ?? "",
|
||||||
|
htmlUrl: json.html_url ?? "",
|
||||||
|
assets,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (assets.length > 0) {
|
||||||
|
return candidateRelease;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fallbackRelease) {
|
||||||
|
fallbackRelease = candidateRelease;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// try next source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallbackRelease;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function matchAssetForPlatform(
|
||||||
|
assets: GitHubAsset[],
|
||||||
|
platform: "darwin" | "linux" | "windows",
|
||||||
|
arch: "arm64" | "x64"
|
||||||
|
): GitHubAsset | undefined {
|
||||||
|
const platformKeywords: Record<string, string[]> = {
|
||||||
|
darwin: ["darwin", "macos", "osx", "apple"],
|
||||||
|
linux: ["linux"],
|
||||||
|
windows: ["windows", "win32", "win64", ".exe"],
|
||||||
|
};
|
||||||
|
const archKeywords: Record<string, string[]> = {
|
||||||
|
arm64: ["arm64", "aarch64"],
|
||||||
|
x64: ["x64", "x86_64", "amd64"],
|
||||||
|
};
|
||||||
|
|
||||||
|
const pKeys = platformKeywords[platform] || [];
|
||||||
|
const aKeys = archKeywords[arch] || [];
|
||||||
|
|
||||||
|
const matched = assets.filter((asset) => {
|
||||||
|
const lower = asset.name.toLowerCase();
|
||||||
|
const matchesP = pKeys.some((k) => lower.includes(k));
|
||||||
|
const matchesA = aKeys.some((k) => lower.includes(k));
|
||||||
|
return matchesP && matchesA;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Prefer direct raw executable over tar.gz / zip if both exist
|
||||||
|
const directBinary = matched.find(
|
||||||
|
(asset) =>
|
||||||
|
!asset.name.endsWith(".tar.gz") &&
|
||||||
|
!asset.name.endsWith(".tgz") &&
|
||||||
|
!asset.name.endsWith(".zip") &&
|
||||||
|
!asset.name.endsWith(".sha256")
|
||||||
|
);
|
||||||
|
if (directBinary) return directBinary;
|
||||||
|
|
||||||
|
// Fallback to archive
|
||||||
|
const archive = matched.find(
|
||||||
|
(asset) =>
|
||||||
|
asset.name.endsWith(".tar.gz") ||
|
||||||
|
asset.name.endsWith(".tgz") ||
|
||||||
|
asset.name.endsWith(".zip")
|
||||||
|
);
|
||||||
|
return archive || matched[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function logProgress(msg: string) {
|
||||||
|
try {
|
||||||
|
process.stderr.write(`${msg}\n`);
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadFile(url: string, destPath: string, tagName?: string, assetName?: string) {
|
||||||
|
const candidates: string[] = [];
|
||||||
|
const tag = tagName ? (tagName.startsWith("v") ? tagName : `v${tagName}`) : undefined;
|
||||||
|
const fileName = assetName || url.split("/").pop() || "";
|
||||||
|
|
||||||
|
// 1. High-speed Gitea direct mirror first
|
||||||
|
if (tag && fileName) {
|
||||||
|
candidates.push(`https://git.ying-qing.cn/gitea/hose-use/releases/download/${tag}/${fileName}`);
|
||||||
|
}
|
||||||
|
if (url.startsWith("https://git.ying-qing.cn")) {
|
||||||
|
candidates.push(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Fast GitHub CDN proxies and direct GitHub fallback
|
||||||
|
if (tag && fileName) {
|
||||||
|
const ghDirectUrl = `https://github.com/${DEFAULT_GITHUB_REPO}/releases/download/${tag}/${fileName}`;
|
||||||
|
candidates.push(`https://ghfast.top/${ghDirectUrl}`);
|
||||||
|
candidates.push(`https://ghproxy.net/${ghDirectUrl}`);
|
||||||
|
candidates.push(`https://gh.ddlc.top/${ghDirectUrl}`);
|
||||||
|
candidates.push(`https://mirror.ghproxy.com/${ghDirectUrl}`);
|
||||||
|
candidates.push(ghDirectUrl);
|
||||||
|
} else if (url.includes("github.com")) {
|
||||||
|
candidates.push(`https://ghfast.top/${url}`);
|
||||||
|
candidates.push(`https://ghproxy.net/${url}`);
|
||||||
|
candidates.push(`https://gh.ddlc.top/${url}`);
|
||||||
|
candidates.push(`https://mirror.ghproxy.com/${url}`);
|
||||||
|
candidates.push(url);
|
||||||
|
} else {
|
||||||
|
candidates.push(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
const uniqueCandidates = Array.from(new Set(candidates));
|
||||||
|
|
||||||
|
let lastError: Error | undefined;
|
||||||
|
for (let i = 0; i < uniqueCandidates.length; i++) {
|
||||||
|
const candidate = uniqueCandidates[i]!;
|
||||||
|
try {
|
||||||
|
logProgress(`==> [${i + 1}/${uniqueCandidates.length}] 正在下载更新: ${candidate}`);
|
||||||
|
const res = await fetch(candidate, { signal: AbortSignal.timeout(6000) });
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalBytes = Number(res.headers.get("content-length")) || 0;
|
||||||
|
const reader = res.body?.getReader();
|
||||||
|
if (!reader) {
|
||||||
|
const buffer = Buffer.from(await res.arrayBuffer());
|
||||||
|
if (buffer.length < 1000) {
|
||||||
|
throw new Error(`下载文件异常(大小仅 ${buffer.length} 字节)`);
|
||||||
|
}
|
||||||
|
writeFileSync(destPath, buffer);
|
||||||
|
logProgress(`✓ 下载完成 (${(buffer.length / 1024 / 1024).toFixed(1)} MB)`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const chunks: Uint8Array[] = [];
|
||||||
|
let receivedBytes = 0;
|
||||||
|
let lastReport = 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const { done, value } = await reader.read();
|
||||||
|
if (done) break;
|
||||||
|
if (value) {
|
||||||
|
chunks.push(value);
|
||||||
|
receivedBytes += value.length;
|
||||||
|
const now = Date.now();
|
||||||
|
if (now - lastReport > 200) {
|
||||||
|
lastReport = now;
|
||||||
|
const percent = totalBytes ? Math.round((receivedBytes / totalBytes) * 100) : 0;
|
||||||
|
const receivedMb = (receivedBytes / (1024 * 1024)).toFixed(1);
|
||||||
|
const totalMb = totalBytes ? (totalBytes / (1024 * 1024)).toFixed(1) : "?";
|
||||||
|
try {
|
||||||
|
process.stderr.write(`\r ↳ 进度: ${percent}% (${receivedMb} / ${totalMb} MB)...`);
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.stderr.write("\n");
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
const completeBuffer = Buffer.concat(chunks);
|
||||||
|
if (completeBuffer.length < 1000) {
|
||||||
|
throw new Error(`下载文件异常(大小仅 ${completeBuffer.length} 字节)`);
|
||||||
|
}
|
||||||
|
writeFileSync(destPath, completeBuffer);
|
||||||
|
logProgress(`✓ 下载完成 (${(completeBuffer.length / 1024 / 1024).toFixed(1)} MB)`);
|
||||||
|
return;
|
||||||
|
} catch (err) {
|
||||||
|
lastError = err instanceof Error ? err : new Error(String(err));
|
||||||
|
logProgress(` ↳ 节点失败: ${lastError.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`所有下载镜像均失败: ${lastError?.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractTarGz(archivePath: string, targetDir: string, platform: string): string {
|
||||||
|
const result = spawnSync("tar", ["-xzf", archivePath, "-C", targetDir], { stdio: "pipe" });
|
||||||
|
if (result.status !== 0) {
|
||||||
|
throw new Error(`解压 tar 归档失败: ${result.stderr.toString()}`);
|
||||||
|
}
|
||||||
|
unlinkSync(archivePath);
|
||||||
|
|
||||||
|
const expectedName = platform === "windows" ? "hose-use.exe" : "hose-use";
|
||||||
|
const files = spawnSync("find", [targetDir, "-type", "f"], { encoding: "utf8" })
|
||||||
|
.stdout.trim()
|
||||||
|
.split("\n")
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
const exact = files.find((f) => f.endsWith(`/${expectedName}`) || f.endsWith(expectedName));
|
||||||
|
if (exact) return exact;
|
||||||
|
return files[0] || archivePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractZip(archivePath: string, targetDir: string, platform: string): string {
|
||||||
|
const result = spawnSync("unzip", ["-q", "-o", archivePath, "-d", targetDir], { stdio: "pipe" });
|
||||||
|
if (result.status !== 0) {
|
||||||
|
throw new Error(`解压 zip 归档失败: ${result.stderr.toString()}`);
|
||||||
|
}
|
||||||
|
unlinkSync(archivePath);
|
||||||
|
|
||||||
|
const expectedName = platform === "windows" ? "hose-use.exe" : "hose-use";
|
||||||
|
const files = spawnSync("find", [targetDir, "-type", "f"], { encoding: "utf8" })
|
||||||
|
.stdout.trim()
|
||||||
|
.split("\n")
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
const exact = files.find((f) => f.endsWith(`/${expectedName}`) || f.endsWith(expectedName));
|
||||||
|
if (exact) return exact;
|
||||||
|
return files[0] || archivePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function compareSemVer(v1: string, v2: string): number {
|
||||||
|
const p1 = v1.replace(/^v/, "").split(".").map((n) => Number.parseInt(n, 10) || 0);
|
||||||
|
const p2 = v2.replace(/^v/, "").split(".").map((n) => Number.parseInt(n, 10) || 0);
|
||||||
|
for (let i = 0; i < Math.max(p1.length, p2.length); i++) {
|
||||||
|
const a = p1[i] ?? 0;
|
||||||
|
const b = p2[i] ?? 0;
|
||||||
|
if (a > b) return 1;
|
||||||
|
if (a < b) return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isNewerVersion(latest: string, current: string): boolean {
|
||||||
|
return compareSemVer(latest, current) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function runCommand(command: string, args: string[], options: { cwd?: string } = {}) {
|
||||||
|
const result = spawnSync(command, args, {
|
||||||
|
cwd: options.cwd,
|
||||||
|
encoding: "utf8",
|
||||||
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.stdout) console.error(result.stdout.trimEnd());
|
||||||
|
if (result.stderr) console.error(result.stderr.trimEnd());
|
||||||
|
|
||||||
|
if (result.status !== 0) {
|
||||||
|
throw new Error(`${command} ${args.join(" ")} 执行失败 (退出码 ${result.status})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
-5
@@ -1,5 +1,26 @@
|
|||||||
import type { CliParsedArgs } from "./types.js";
|
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 {
|
export function parseArgs(rawArgs: string[]): CliParsedArgs {
|
||||||
const options: Record<string, string | boolean | number> = {};
|
const options: Record<string, string | boolean | number> = {};
|
||||||
const positional: string[] = [];
|
const positional: string[] = [];
|
||||||
@@ -20,12 +41,16 @@ export function parseArgs(rawArgs: string[]): CliParsedArgs {
|
|||||||
options[key] = val;
|
options[key] = val;
|
||||||
} else {
|
} else {
|
||||||
const key = arg.slice(2);
|
const key = arg.slice(2);
|
||||||
const next = rawArgs[i + 1];
|
if (KNOWN_BOOLEAN_FLAGS.has(key)) {
|
||||||
if (next && !next.startsWith("-")) {
|
|
||||||
options[key] = next;
|
|
||||||
i++;
|
|
||||||
} else {
|
|
||||||
options[key] = true;
|
options[key] = true;
|
||||||
|
} else {
|
||||||
|
const next = rawArgs[i + 1];
|
||||||
|
if (next && !next.startsWith("-")) {
|
||||||
|
options[key] = next;
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
options[key] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ export function printHelp(): string {
|
|||||||
platform 自建应用管理 (list)
|
platform 自建应用管理 (list)
|
||||||
skill Agent Skill 管理 (install, status, dump)
|
skill Agent Skill 管理 (install, status, dump)
|
||||||
probe 连通性诊断 (probe [corpId])
|
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)
|
mcp MCP Server 运行 (serve)
|
||||||
version 查看版本信息
|
version 查看版本信息
|
||||||
|
|
||||||
@@ -71,5 +73,9 @@ export function printHelp(): string {
|
|||||||
hose-use workflow find --task=code-js2 # 搜索包含自定义脚本的工作流
|
hose-use workflow find --task=code-js2 # 搜索包含自定义脚本的工作流
|
||||||
hose-use probe # 诊断当前企业鉴权连通性
|
hose-use probe # 诊断当前企业鉴权连通性
|
||||||
hose-use skill install # 安装 Agent 技能到用户目录
|
hose-use skill install # 安装 Agent 技能到用户目录
|
||||||
|
hose-use update # 自动检查并升级到最新版本
|
||||||
|
hose-use update --changelog # 查看版本发布历史
|
||||||
|
hose-use openapi paths # 查看所有 API 路径与概要一览
|
||||||
|
hose-use openapi --raw # 导出原生下游全量 OpenAPI 规范
|
||||||
`.trim();
|
`.trim();
|
||||||
}
|
}
|
||||||
+11
-1
@@ -10,6 +10,8 @@ import { handlePlatformCommand } from "./commands/platform.js";
|
|||||||
import { handleSkillCommand } from "./commands/skill.js";
|
import { handleSkillCommand } from "./commands/skill.js";
|
||||||
import { handleProbeCommand } from "./commands/probe.js";
|
import { handleProbeCommand } from "./commands/probe.js";
|
||||||
import { handleMcpCommand } from "./commands/mcp.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";
|
import type { CliResult, CliRunOptions } from "./types.js";
|
||||||
|
|
||||||
export async function runCli(
|
export async function runCli(
|
||||||
@@ -62,9 +64,17 @@ export async function runCli(
|
|||||||
case "skills":
|
case "skills":
|
||||||
return await handleSkillCommand(parsed, runtime);
|
return await handleSkillCommand(parsed, runtime);
|
||||||
case "probe":
|
case "probe":
|
||||||
case "check":
|
|
||||||
case "diagnose":
|
case "diagnose":
|
||||||
return await handleProbeCommand(parsed, runtime);
|
return await handleProbeCommand(parsed, runtime);
|
||||||
|
case "update":
|
||||||
|
case "upgrade":
|
||||||
|
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 "mcp":
|
||||||
case "serve":
|
case "serve":
|
||||||
return await handleMcpCommand(parsed, options);
|
return await handleMcpCommand(parsed, options);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { dirname } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
export function isCompiledBinary(execPath = process.execPath, metaUrl = import.meta.url): boolean {
|
||||||
|
if (metaUrl.includes("/$bunfs/") || metaUrl.includes("\\$bunfs\\")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const lower = execPath.toLowerCase().replace(/\\/g, "/");
|
||||||
|
return !lower.endsWith("/bun") && !lower.endsWith("/bun.exe");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveAppRoot(entryFile?: string, isCompiled = isCompiledBinary()): string {
|
||||||
|
if (isCompiled) {
|
||||||
|
return process.cwd();
|
||||||
|
}
|
||||||
|
const file = entryFile || fileURLToPath(import.meta.url);
|
||||||
|
return dirname(dirname(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LauncherConfig = {
|
||||||
|
command: string;
|
||||||
|
args?: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function resolveDefaultLauncher(
|
||||||
|
entryFile: string,
|
||||||
|
isCompiled = isCompiledBinary(),
|
||||||
|
execPath = process.execPath
|
||||||
|
): LauncherConfig {
|
||||||
|
if (isCompiled) {
|
||||||
|
return {
|
||||||
|
command: execPath,
|
||||||
|
args: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
command: execPath,
|
||||||
|
args: [entryFile],
|
||||||
|
};
|
||||||
|
}
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
export const VERSION = "0.2.0";
|
export const VERSION = "0.2.2";
|
||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
"declaration": true,
|
"declaration": true,
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"rootDir": "./src",
|
"rootDir": "./src",
|
||||||
"types": ["node"],
|
"types": ["node", "bun"],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@core/*": ["./src/core/*"],
|
"@core/*": ["./src/core/*"],
|
||||||
"@domains/*": ["./src/domains/*"]
|
"@domains/*": ["./src/domains/*"]
|
||||||
|
|||||||
Reference in new issue
Block a user