From 215bc5e2a1f52a92635d03730705bb1657a8c25c Mon Sep 17 00:00:00 2001 From: yunyingk Date: Wed, 9 Sep 2026 15:06:34 +0800 Subject: [PATCH] feat(app): add workbench apps, desktop menu domain and bump to v0.8.3 --- .zcode-plugin/plugin.json | 2 +- README.md | 7 +- dist/openapi.json | 2 +- openapi/openapi.yaml | 2 +- package.json | 2 +- skills/hose-use/SKILL.md | 16 ++- src/cli/commands/app.test.ts | 183 ++++++++++++++++++++++++++++++++ src/cli/commands/app.ts | 149 ++++++++++++++++++++++++++ src/cli/commands/menu.test.ts | 178 +++++++++++++++++++++++++++++++ src/cli/commands/menu.ts | 71 +++++++++++++ src/cli/commands/platform.ts | 23 ++-- src/cli/printer.ts | 5 + src/cli/runner.ts | 11 +- src/domains/datalink/api.ts | 11 ++ src/domains/datalink/tools.ts | 13 ++- src/domains/menu/README.menu.md | 34 ++++++ src/domains/menu/api.test.ts | 125 ++++++++++++++++++++++ src/domains/menu/api.ts | 62 +++++++++++ src/domains/menu/tools.ts | 35 ++++++ src/domains/menu/types.ts | 47 ++++++++ src/version.ts | 2 +- 21 files changed, 956 insertions(+), 24 deletions(-) create mode 100644 src/cli/commands/app.test.ts create mode 100644 src/cli/commands/app.ts create mode 100644 src/cli/commands/menu.test.ts create mode 100644 src/cli/commands/menu.ts create mode 100644 src/domains/menu/README.menu.md create mode 100644 src/domains/menu/api.test.ts create mode 100644 src/domains/menu/api.ts create mode 100644 src/domains/menu/tools.ts create mode 100644 src/domains/menu/types.ts diff --git a/.zcode-plugin/plugin.json b/.zcode-plugin/plugin.json index 4f79a73..b0e312f 100644 --- a/.zcode-plugin/plugin.json +++ b/.zcode-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "hose-use", - "version": "0.8.2", + "version": "0.8.3", "description": "合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号登录、企业租户切换、单据明细检索、工作流管理、内置 HTTP 服务与常驻守护进程。", "author": { "name": "yingqing" diff --git a/README.md b/README.md index 163ab8f..da8877b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# hose-use (v0.8.2) +# hose-use (v0.8.3) 合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。 @@ -39,7 +39,10 @@ hose-use config paths # 查看多级企业目录发现 hose-use config mode stateless # 切换为无状态模式 (防止 Agent 误操作) hose-use config mode stateful # 切换为有状态模式 (记忆默认企业) -# 4. 平台与工作流管理 (跨自建应用聚合) +# 4. 工作台应用、菜单与工作流管理 (跨自建应用聚合) +hose-use app list # 查看工作台应用管理列表 (含套件/制度/模板/自建) +hose-use app get <应用ID|名称> # 查看具体应用详情与 Web 直达路由 +hose-use menu list # 查看桌面端全站一级主导航与模块列表 hose-use workflow list # 汇总查看全部工作流列表 hose-use workflow get # 获取工作流详情与节点结构 hose-use workflow find --task=code-js2 # 搜索包含特定节点类型的工作流 diff --git a/dist/openapi.json b/dist/openapi.json index 772ba10..d3b2eab 100644 --- a/dist/openapi.json +++ b/dist/openapi.json @@ -2,7 +2,7 @@ "openapi": "3.1.0", "info": { "title": "hose-use API & MCP Tools Specification", - "version": "0.8.2", + "version": "0.8.3", "description": "Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows." }, "servers": [ diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index b3ff228..e6625e5 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.1.0 info: title: hose-use API & MCP Tools Specification - version: 0.8.2 + version: 0.8.3 description: >- Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows. servers: diff --git a/package.json b/package.json index d45ae91..a7e5421 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hose-use", - "version": "0.8.2", + "version": "0.8.3", "module": "src/server.ts", "type": "module", "bin": { diff --git a/skills/hose-use/SKILL.md b/skills/hose-use/SKILL.md index 7343b8f..7adb7ec 100644 --- a/skills/hose-use/SKILL.md +++ b/skills/hose-use/SKILL.md @@ -1,12 +1,12 @@ --- name: hose-use -description: "v0.8.2: 合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号 API 登录、租户切换、单据检索与审批动作、工作流跨域扫描、内置 HTTP 交互文档与常驻守护进程。" +description: "v0.8.3: 合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号 API 登录、租户切换、单据检索与审批动作、工作流跨域扫描、内置 HTTP 交互文档与常驻守护进程。" metadata: - version: 0.8.2 - short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.8.2) + version: 0.8.3 + short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.8.3) --- -# hose-use (v0.8.2) +# hose-use (v0.8.3) 在具备 MCP 的 AI 智能体环境中,**优先使用 `hose_cli` 单工具网关**,传入 `command: string` 执行;在终端或自动化脚本中,直接调用全局 `hose` 或 `hose-use` 命令行。 本 Skill 是智能体的路由分发层:保持主文档简明,遇到复杂业务时深入查阅对应的专属参考文档(`references/*.md`)。 @@ -57,6 +57,9 @@ metadata: | 待办中心 / 已审批 / 我发起的 / 审批记录 / 抄送 | `hose-use task todo`, `hose-use task submitted`, `hose-use task records`, `hose-use task cc` | [references/task.md](references/task.md) | | 消息中心 / 未读统计 / 标记已读 / 类型过滤 | `hose-use message list [--all]`, `hose-use message count`, `hose-use message read` | [references/message.md](references/message.md) | | 跨自建应用工作流聚合检索 | `hose-use workflow list`, `hose-use platform list` | [references/workflow.md](references/workflow.md) | +| 工作台业务应用管理 (用车/套件/制度/模板/自建) | `hose-use app list [--keyword]`, `hose-use app get <应用>` | [references/workflow.md](references/workflow.md) | +| 桌面端全站主导航与一级模块树 | `hose-use menu list`, `hose-use menu tree` | [references/workflow.md](references/workflow.md) | +| 模糊搜索已保存的企业与员工信息 | `hose-use corps search <关键词>` | [references/auth.md](references/auth.md) | | 特定任务节点扫描 (如脚本/Webhook) | `hose-use workflow find --task=code-js2` | [references/workflow.md](references/workflow.md) | | 工作流详情与开通切换 | `hose-use workflow get`, `hose-use workflow toggle` | [references/workflow.md](references/workflow.md) | | 工作流节点树、代码依赖与静态诊断 | `hose-use workflow analyze ` | [references/workflow.md](references/workflow.md) | @@ -122,7 +125,10 @@ hose-use message list --all # 合并查看已读和 hose-use message count # 查看未读数量 hose-use message read # 标记单条消息已读 -# 5. 自建应用与工作流 +# 5. 工作台应用、菜单与工作流 +hose-use app list # 查看桌面端工作台应用列表(含套件/制度/模板/自建) +hose-use app get 用车补贴 # 查看指定工作台应用的配置与 Web 路由 +hose-use menu list # 查看桌面端主框架一级导航树 hose-use platform list # 查看自建应用列表 hose-use workflow list # 聚合扫描全部应用下的工作流 hose-use workflow find --task=code-js2 # 查找部署了代码节点的工作流 diff --git a/src/cli/commands/app.test.ts b/src/cli/commands/app.test.ts new file mode 100644 index 0000000..92401eb --- /dev/null +++ b/src/cli/commands/app.test.ts @@ -0,0 +1,183 @@ +import { describe, it, expect, spyOn } from "bun:test"; +import { handleAppCommand } from "./app.js"; +import * as menuTools from "../../domains/menu/tools.js"; +import type { CliRuntime } from "../types.js"; +import type { CorpConfig } from "../../core/config/types.js"; + +describe("cli/commands/app > handleAppCommand", () => { + const dummyRuntimeNoCorp: CliRuntime = { + corpContext: { + listCorps: () => [], + getCurrent: () => null, + switchCorp: () => false, + resolve: () => null, + } as any, + selectedCorp: null, + jsonMode: false, + }; + + const mockCorp: CorpConfig = { + id: "corp123", + name: "转转二手交易网", + source: "account", + baseUrl: "https://app.ekuaibao.com", + credentials: { + accessToken: "mock-token", + corpId: "corp123", + staffId: "mock-staff", + }, + }; + + const dummyRuntimeWithCorp: CliRuntime = { + corpContext: { + listCorps: () => [mockCorp], + getCurrent: () => mockCorp, + switchCorp: () => true, + resolve: () => mockCorp, + } as any, + selectedCorp: mockCorp, + jsonMode: false, + }; + + it("fails with exitCode 1 when no corp is selected", async () => { + const res = await handleAppCommand( + { + area: "app", + action: "list", + args: [], + options: {}, + raw: ["app", "list"], + }, + dummyRuntimeNoCorp + ); + + expect(res.exitCode).toBe(1); + expect(res.stderr).toContain("未选中企业"); + }); + + it("lists workbench apps in table format", async () => { + const mockApps = [ + { + id: "SCGY:corp123", + name: "用车补贴", + code: "dataLinkItem", + href: "/third-party-item/SCGY:corp123", + type: "MENU", + }, + { + id: "ID01PIqCA1Di0v", + name: "用车制度", + code: "dataLinkItem", + href: "/third-party-item/ID01PIqCA1Di0v", + type: "REGULATION", + }, + ]; + + const spy = spyOn(menuTools, "fetchWorkbenchAppsList").mockResolvedValue(mockApps as any); + + const res = await handleAppCommand( + { + area: "app", + action: "list", + args: [], + options: {}, + raw: ["app", "list"], + }, + dummyRuntimeWithCorp + ); + + expect(res.exitCode).toBe(0); + expect(res.stdout).toContain("工作台应用管理列表"); + expect(res.stdout).toContain("用车补贴"); + expect(res.stdout).toContain("用车制度"); + expect(res.stdout).toContain("用车/商旅套件"); + expect(res.stdout).toContain("制度与规约"); + + spy.mockRestore(); + }); + + it("filters workbench apps with --keyword", async () => { + const mockApps = [ + { + id: "SCGY:corp123", + name: "用车补贴", + code: "dataLinkItem", + href: "/third-party-item/SCGY:corp123", + }, + { + id: "ID01PIqCA1Di0v", + name: "差旅申请", + code: "dataLinkItem", + href: "/third-party-item/ID01PIqCA1Di0v", + }, + ]; + + const spy = spyOn(menuTools, "fetchWorkbenchAppsList").mockResolvedValue(mockApps as any); + + const res = await handleAppCommand( + { + area: "app", + action: "list", + args: [], + options: { keyword: "补贴" }, + raw: ["app", "list", "--keyword", "补贴"], + }, + dummyRuntimeWithCorp + ); + + expect(res.exitCode).toBe(0); + expect(res.stdout).toContain("用车补贴"); + expect(res.stdout).not.toContain("差旅申请"); + + spy.mockRestore(); + }); + + it("supports --json output for app list", async () => { + const mockApps = [ + { + id: "SCGY:corp123", + name: "用车补贴", + code: "dataLinkItem", + href: "/third-party-item/SCGY:corp123", + }, + ]; + + const spy = spyOn(menuTools, "fetchWorkbenchAppsList").mockResolvedValue(mockApps as any); + + const jsonRuntime = { ...dummyRuntimeWithCorp, jsonMode: true }; + const res = await handleAppCommand( + { + area: "app", + action: "list", + args: [], + options: { json: true }, + raw: ["app", "list", "--json"], + }, + jsonRuntime + ); + + expect(res.exitCode).toBe(0); + const parsed = JSON.parse(res.stdout); + expect(parsed.total).toBe(1); + expect(parsed.apps[0].id).toBe("SCGY:corp123"); + expect(parsed.apps[0].name).toBe("用车补贴"); + + spy.mockRestore(); + }); + + it("returns error for unknown subcommand", async () => { + const res = await handleAppCommand( + { + area: "app", + action: "unknownAction", + args: [], + options: {}, + raw: ["app", "unknownAction"], + }, + dummyRuntimeWithCorp + ); + + expect(res.exitCode).toBe(1); + expect(res.stderr).toContain("未知 app 子命令"); + }); +}); diff --git a/src/cli/commands/app.ts b/src/cli/commands/app.ts new file mode 100644 index 0000000..4775206 --- /dev/null +++ b/src/cli/commands/app.ts @@ -0,0 +1,149 @@ +import { fetchWorkbenchAppsList } from "../../domains/menu/tools.js"; +import { getPlatform } from "../../domains/datalink/api.js"; +import { createClientsForCorp } from "../helpers.js"; +import { stringOption, booleanOption } from "../parser.js"; +import { printJson, printTable } from "../printer.js"; +import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js"; + +function inferCategory(app: { id: string; name: string; type?: string | null }): string { + if (app.id.startsWith("SCGY:") || app.type === "PRIVATE_CAR") return "用车/商旅套件"; + if (app.type === "REGULATION") return "制度与规约"; + if (app.type === "VCM") return "商旅卡与金融"; + if (app.name.includes("[模板]") || app.name.includes("模板")) return "预置模板"; + return "自建业务应用"; +} + +export async function handleAppCommand( + parsed: CliParsedArgs, + runtime: CliRuntime +): Promise { + if (!runtime.selectedCorp) { + return { + stdout: "", + stderr: "未选中企业,请先通过 hose-use corps switch 或 --corp 指定企业\n", + exitCode: 1, + }; + } + + const action = parsed.action || "list"; + + switch (action) { + case "list": + case "ls": + case "apps": + case "workbench": { + const keyword = stringOption(parsed.options, ["keyword", "k", "q", "query"])?.toLowerCase(); + const apps = await fetchWorkbenchAppsList(runtime.selectedCorp); + + const filtered = keyword + ? apps.filter((app) => + [app.id, app.name, app.code, app.href] + .filter((val): val is string => Boolean(val)) + .some((val) => val.toLowerCase().includes(keyword)) + ) + : apps; + + if (runtime.jsonMode) { + return { + stdout: printJson( + { + corpId: runtime.selectedCorp.credentials.corpId, + corpName: runtime.selectedCorp.name, + total: apps.length, + count: filtered.length, + keyword: keyword ?? null, + apps: filtered, + }, + runtime.outputOptions + ), + stderr: "", + exitCode: 0, + }; + } + + if (filtered.length === 0) { + const msg = keyword + ? `企业 [${runtime.selectedCorp.name}] 下未找到匹配 "${keyword}" 的工作台应用\n` + : `企业 [${runtime.selectedCorp.name}] 下暂无工作台应用配置\n`; + return { stdout: msg, stderr: "", exitCode: 0 }; + } + + const headers = ["#", "应用 ID", "应用名称", "应用分类", "功能代码", "Web 直达路由"]; + const rows = filtered.map((app, i) => [ + i + 1, + app.id, + app.name, + inferCategory(app), + app.code || "dataLinkItem", + app.href, + ]); + + const title = `====== [${runtime.selectedCorp.name}] 工作台应用管理列表 (${filtered.length} 个应用) ======\n`; + return { + stdout: title + printTable(headers, rows) + "\n", + stderr: "", + exitCode: 0, + }; + } + + case "get": + case "show": { + const target = parsed.args[0] || stringOption(parsed.options, ["id", "name", "app"]); + if (!target) { + return { + stdout: "", + stderr: "请提供应用 ID 或名称: hose-use app get <应用 ID|名称>\n", + exitCode: 1, + }; + } + + const apps = await fetchWorkbenchAppsList(runtime.selectedCorp); + const matched = apps.find( + (a) => + a.id.toLowerCase() === target.toLowerCase() || + a.name.toLowerCase().includes(target.toLowerCase()) + ); + + const appId = matched ? matched.id : target; + const appName = matched ? matched.name : target; + + const clients = await createClientsForCorp(runtime.selectedCorp); + const corpId = runtime.selectedCorp.credentials.corpId; + + try { + const detail = await getPlatform(clients.ekbClient, corpId, appId); + if (runtime.jsonMode) { + return { stdout: printJson(detail, runtime.outputOptions), stderr: "", exitCode: 0 }; + } + + const infoRows = [ + ["应用 ID", detail.id], + ["应用名称", detail.name], + ["应用分类", inferCategory(detail)], + ["启用状态", detail.active ? "🟢 已启用" : "⚪ 未启用"], + ["Web 路由", matched?.href || `/third-party-item/${detail.id}`], + ["管理员数", detail.adminIds.length], + ["可见人员数", detail.staffIds.length], + ["可见角色数", detail.roleIds.length], + ["可见部门数", detail.departmentIds.length], + ]; + + const text = `====== 工作台应用详情: ${appName} ======\n${printTable(["属性", "信息"], infoRows)}\n`; + return { stdout: text, stderr: "", exitCode: 0 }; + } catch (err) { + return { + stdout: "", + stderr: `获取应用详情失败: ${err instanceof Error ? err.message : String(err)}\n`, + exitCode: 1, + }; + } + } + + default: + return { + stdout: "", + stderr: `未知 app 子命令: ${action}。支持: list, get\n用法: hose-use app list [--keyword <关键词>]\n`, + exitCode: 1, + }; + } +} diff --git a/src/cli/commands/menu.test.ts b/src/cli/commands/menu.test.ts new file mode 100644 index 0000000..1bbc6ae --- /dev/null +++ b/src/cli/commands/menu.test.ts @@ -0,0 +1,178 @@ +import { describe, it, expect, spyOn } from "bun:test"; +import { handleMenuCommand } from "./menu.js"; +import * as menuTools from "../../domains/menu/tools.js"; +import type { CliRuntime } from "../types.js"; +import type { CorpConfig } from "../../core/config/types.js"; + +describe("cli/commands/menu > handleMenuCommand", () => { + const dummyRuntimeNoCorp: CliRuntime = { + corpContext: { + listCorps: () => [], + getCurrent: () => null, + switchCorp: () => false, + resolve: () => null, + } as any, + selectedCorp: null, + jsonMode: false, + }; + + const mockCorp: CorpConfig = { + id: "corp123", + name: "转转二手交易网", + source: "account", + baseUrl: "https://app.ekuaibao.com", + credentials: { + accessToken: "mock-token", + corpId: "corp123", + staffId: "mock-staff", + }, + }; + + const dummyRuntimeWithCorp: CliRuntime = { + corpContext: { + listCorps: () => [mockCorp], + getCurrent: () => mockCorp, + switchCorp: () => true, + resolve: () => mockCorp, + } as any, + selectedCorp: mockCorp, + jsonMode: false, + }; + + it("fails with exitCode 1 when no corp is selected", async () => { + const res = await handleMenuCommand( + { + area: "menu", + action: "list", + args: [], + options: {}, + raw: ["menu", "list"], + }, + dummyRuntimeNoCorp + ); + + expect(res.exitCode).toBe(1); + expect(res.stderr).toContain("未选中企业"); + }); + + it("lists desktop menus in table format", async () => { + const mockMenus = [ + { + id: "newHomePage", + label: "首页", + appId: "100-home", + href: "/home", + children: [], + }, + { + id: "dataLink", + label: "应用管理", + appId: "160-datalink-platform", + href: "/datalink", + children: [ + { id: "sub1", label: "用车补贴" }, + { id: "sub2", label: "用车制度" }, + ], + }, + ]; + + const spy = spyOn(menuTools, "fetchDesktopMenus").mockResolvedValue(mockMenus as any); + + const res = await handleMenuCommand( + { + area: "menu", + action: "list", + args: [], + options: {}, + raw: ["menu", "list"], + }, + dummyRuntimeWithCorp + ); + + expect(res.exitCode).toBe(0); + expect(res.stdout).toContain("桌面端主框架导航与模块列表"); + expect(res.stdout).toContain("首页"); + expect(res.stdout).toContain("应用管理"); + expect(res.stdout).toContain("160-datalink-platform"); + + spy.mockRestore(); + }); + + it("supports --json output for menu list", async () => { + const mockMenus = [ + { + id: "newHomePage", + label: "首页", + appId: "100-home", + href: "/home", + }, + ]; + + const spy = spyOn(menuTools, "fetchDesktopMenus").mockResolvedValue(mockMenus as any); + + const jsonRuntime = { ...dummyRuntimeWithCorp, jsonMode: true }; + const res = await handleMenuCommand( + { + area: "menu", + action: "list", + args: [], + options: { json: true }, + raw: ["menu", "list", "--json"], + }, + jsonRuntime + ); + + expect(res.exitCode).toBe(0); + const parsed = JSON.parse(res.stdout); + expect(parsed.count).toBe(1); + expect(parsed.menus[0].id).toBe("newHomePage"); + + spy.mockRestore(); + }); + + it("delegates menu apps to handleAppCommand", async () => { + const mockApps = [ + { + id: "SCGY:corp123", + name: "用车补贴", + code: "dataLinkItem", + href: "/third-party-item/SCGY:corp123", + }, + ]; + + const spy = spyOn(menuTools, "fetchWorkbenchAppsList").mockResolvedValue(mockApps as any); + + const res = await handleMenuCommand( + { + area: "menu", + action: "apps", + args: [], + options: {}, + raw: ["menu", "apps"], + }, + dummyRuntimeWithCorp + ); + + expect(res.exitCode).toBe(0); + expect(res.stdout).toContain("工作台应用管理列表"); + expect(res.stdout).toContain("用车补贴"); + + spy.mockRestore(); + }); + + it("returns error for unknown menu subcommand", async () => { + const res = await handleMenuCommand( + { + area: "menu", + action: "badsub", + args: [], + options: {}, + raw: ["menu", "badsub"], + }, + dummyRuntimeWithCorp + ); + + expect(res.exitCode).toBe(1); + expect(res.stderr).toContain("未知 menu 子命令"); + }); +}); diff --git a/src/cli/commands/menu.ts b/src/cli/commands/menu.ts new file mode 100644 index 0000000..00396c0 --- /dev/null +++ b/src/cli/commands/menu.ts @@ -0,0 +1,71 @@ +import { fetchDesktopMenus } from "../../domains/menu/tools.js"; +import { handleAppCommand } from "./app.js"; +import { printJson, printTable } from "../printer.js"; +import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js"; + +export async function handleMenuCommand( + parsed: CliParsedArgs, + runtime: CliRuntime +): Promise { + if (!runtime.selectedCorp) { + return { + stdout: "", + stderr: "未选中企业,请先通过 hose-use corps switch 或 --corp 指定企业\n", + exitCode: 1, + }; + } + + const action = parsed.action || "list"; + + switch (action) { + case "apps": + case "workbench": + return handleAppCommand(parsed, runtime); + + case "list": + case "ls": + case "tree": { + const items = await fetchDesktopMenus(runtime.selectedCorp); + + if (runtime.jsonMode) { + return { + stdout: printJson( + { + corpId: runtime.selectedCorp.credentials.corpId, + corpName: runtime.selectedCorp.name, + count: items.length, + menus: items, + }, + runtime.outputOptions + ), + stderr: "", + exitCode: 0, + }; + } + + const headers = ["#", "模块 ID", "导航名称", "模块标识 (appId)", "子菜单数", "默认路由"]; + const rows = items.map((m, i) => [ + i + 1, + m.id, + m.label, + m.appId || "-", + m.children?.length || 0, + m.href || "-", + ]); + + const title = `====== [${runtime.selectedCorp.name}] 桌面端主框架导航与模块列表 (共 ${items.length} 个一级导航) ======\n`; + return { + stdout: title + printTable(headers, rows) + "\n", + stderr: "", + exitCode: 0, + }; + } + + default: + return { + stdout: "", + stderr: `未知 menu 子命令: ${action}。支持: list, tree, apps\n用法: hose-use menu list\n`, + exitCode: 1, + }; + } +} diff --git a/src/cli/commands/platform.ts b/src/cli/commands/platform.ts index 004f0c5..8716291 100644 --- a/src/cli/commands/platform.ts +++ b/src/cli/commands/platform.ts @@ -1,7 +1,7 @@ import * as api from "../../domains/datalink/api.js"; import { buildKeywordFilter, resolveEntity, resolvePlatform, selectRecordFields } from "../../domains/datalink/services.js"; import { createClientsForCorp } from "../helpers.js"; -import { numberOption, stringOption } from "../parser.js"; +import { booleanOption, numberOption, stringOption } from "../parser.js"; import { printJson, printTable } from "../printer.js"; import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js"; @@ -41,10 +41,16 @@ export async function handlePlatformCommand(parsed: CliParsedArgs, runtime: CliR } const action = parsed.action || "list"; + const isWorkbench = action === "workbench" || booleanOption(parsed.options, ["workbench", "w"], false); + if (isWorkbench) { + const { handleAppCommand } = await import("./app.js"); + return handleAppCommand(parsed, runtime); + } + switch (action) { case "list": case "ls": - case "apps": return handleList(runtime); + case "apps": return handleList(parsed, runtime); case "get": case "show": return handleGet(parsed, runtime); case "entities": @@ -64,13 +70,18 @@ export async function handlePlatformCommand(parsed: CliParsedArgs, runtime: CliR } } -async function handleList(runtime: CliRuntime): Promise { +async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Promise { const clients = await createClientsForCorp(runtime.selectedCorp!); - const platforms = await api.listPlatforms(clients.ekbClient, runtime.selectedCorp!.credentials.corpId); - if (runtime.jsonMode) return { stdout: printJson({ count: platforms.length, platforms }, runtime.outputOptions), stderr: "", exitCode: 0 }; + const isAll = booleanOption(parsed.options, ["all", "a"], false); + const platforms = isAll + ? await api.listAllPlatforms(clients.ekbClient, runtime.selectedCorp!.credentials.corpId) + : await api.listPlatforms(clients.ekbClient, runtime.selectedCorp!.credentials.corpId); + + if (runtime.jsonMode) return { stdout: printJson({ count: platforms.length, all: isAll, platforms }, runtime.outputOptions), stderr: "", exitCode: 0 }; if (platforms.length === 0) return { stdout: `企业 [${runtime.selectedCorp!.name}] 下暂无自建应用\n`, stderr: "", exitCode: 0 }; const rows = platforms.map((p, i) => [i + 1, p.id, p.name, p.code, p.active ? "🟢 已启用" : "⚪ 未启用"]); - return { stdout: `====== [${runtime.selectedCorp!.name}] 自建应用列表 (共 ${platforms.length} 个) ======\n${printTable(["#", "自建应用 ID", "应用名称", "编码", "状态"], rows)}\n`, stderr: "", exitCode: 0 }; + const label = isAll ? "自建应用与模板全量列表" : "自建应用列表"; + return { stdout: `====== [${runtime.selectedCorp!.name}] ${label} (共 ${platforms.length} 个) ======\n${printTable(["#", "自建应用 ID", "应用名称", "编码", "状态"], rows)}\n`, stderr: "", exitCode: 0 }; } async function handleGet(parsed: CliParsedArgs, runtime: CliRuntime): Promise { diff --git a/src/cli/printer.ts b/src/cli/printer.ts index 1121b89..71d57d8 100644 --- a/src/cli/printer.ts +++ b/src/cli/printer.ts @@ -127,6 +127,8 @@ export function printHelp(): string { contact 企业通讯录与人员检索 (list, search <关键词>, get ) task 待办中心与审批任务 (todo, approved, records, submitted, cc) message 消息中心与通知管理 (list, count, read, read-all) + app 工作台业务应用管理 (list [--keyword], get <应用ID|名称>) + menu 桌面端主导航菜单树与模块 (list, tree, apps) platform 自建应用、业务对象、字段与记录查询 (list, get, entities, schema, records, permissions, imports) datalink platform 的同义入口,面向 DataLink 业务对象查询 dimension 系统/自定义档案维度 (list, items <维度>) @@ -176,6 +178,9 @@ export function printHelp(): string { hose-use message count # 查看未读消息数 hose-use workflow list # 汇总查看全部工作流 hose-use workflow find --task=code-js2 # 搜索包含自定义脚本的工作流 + hose-use app list # 查看工作台应用管理列表(含套件、制度、模板与自建) + hose-use app get 用车补贴 # 查看工作台应用的详情与元数据配置 + hose-use menu list # 查看桌面端主框架一级导航树与功能模块 hose-use platform list # 列出当前企业可见的自建应用 hose-use platform entities <应用> # 查看应用下的业务对象 hose-use platform schema <应用> <对象> # 查看对象字段(--keyword 可筛选字段) diff --git a/src/cli/runner.ts b/src/cli/runner.ts index 82db6a0..6734305 100644 --- a/src/cli/runner.ts +++ b/src/cli/runner.ts @@ -7,6 +7,8 @@ import { handleCorpsCommand } from "./commands/corps.js"; import { handleConfigCommand } from "./commands/config.js"; import { handleWorkflowCommand } from "./commands/workflow.js"; import { handlePlatformCommand } from "./commands/platform.js"; +import { handleAppCommand } from "./commands/app.js"; +import { handleMenuCommand } from "./commands/menu.js"; import { handleSkillCommand } from "./commands/skill.js"; import { handleProbeCommand } from "./commands/probe.js"; import { handleMcpCommand } from "./commands/mcp.js"; @@ -211,11 +213,16 @@ async function dispatchCli( return await handleMessageCommand(parsed, runtime); case "platform": case "platforms": - case "app": - case "apps": case "datalink": case "data-link": return await handlePlatformCommand(parsed, runtime); + case "app": + case "apps": + case "workbench": + return await handleAppCommand(parsed, runtime); + case "menu": + case "menus": + return await handleMenuCommand(parsed, runtime); case "skill": case "skills": return await handleSkillCommand(parsed, runtime); diff --git a/src/domains/datalink/api.ts b/src/domains/datalink/api.ts index 118a3e3..a00a5b4 100644 --- a/src/domains/datalink/api.ts +++ b/src/domains/datalink/api.ts @@ -52,6 +52,17 @@ export async function listPlatforms(client: KyInstance, corpId: string) { return z.array(DatalinkPlatformDetailSchema).parse(items); } +/** 列出当前企业全量自建应用与模板平台(包含 HAB 模板与全部自建应用)。 */ +export async function listAllPlatforms(client: KyInstance, corpId: string) { + const response = await client.get("api/v2/datalink/platform", { + searchParams: { corpId }, + }); + const json = asRecord(await response.json()); + const rawList = Array.isArray(json) ? json : Array.isArray(json.items) ? json.items : []; + const items = rawList.map(sanitizePlatformDetail); + return z.array(DatalinkPlatformDetailSchema).parse(items); +} + /** 获取单个应用详情以及应用级人员/角色/部门权限。 */ export async function getPlatform( client: KyInstance, diff --git a/src/domains/datalink/tools.ts b/src/domains/datalink/tools.ts index b227b9f..1ab900b 100644 --- a/src/domains/datalink/tools.ts +++ b/src/domains/datalink/tools.ts @@ -9,11 +9,16 @@ const clientSchema = z.object({ export const datalinkTools = [ { name: "datalink_platform_list", - description: "列出当前企业账号可见的启用自建应用", - parameters: z.object({}), - handler: async (clients: unknown) => { + description: "列出当前企业账号可见的启用自建应用(可传入 all=true 查看包含模板平台的完整列表)", + parameters: z.object({ + all: z.boolean().optional().describe("是否拉取包含 HAB 模板与全量平台列表"), + }), + handler: async (clients: unknown, params: { all?: boolean } = {}) => { const { corp, ekbClient } = clientSchema.parse(clients); - return { platforms: await api.listPlatforms(ekbClient, corp.credentials.corpId) }; + const platforms = params.all + ? await api.listAllPlatforms(ekbClient, corp.credentials.corpId) + : await api.listPlatforms(ekbClient, corp.credentials.corpId); + return { platforms }; }, }, { diff --git a/src/domains/menu/README.menu.md b/src/domains/menu/README.menu.md new file mode 100644 index 0000000..99bd628 --- /dev/null +++ b/src/domains/menu/README.menu.md @@ -0,0 +1,34 @@ +# Menu 域说明(桌面端主框架菜单与工作台业务应用) + +Menu 域负责获取合思桌面端全站主框架导航菜单树(`MAIN_FRAME_DESKTOP`)以及业务工作台【应用管理】下的业务应用集成列表。 + +## 业务背景 + +在合思产品体系中: +1. **应用中心 -> 自建应用**(由 `platform` / `datalink` 域负责):属于开发者与 PaaS 容器层(`groupType: NORMAL`),主要用于自定义实体建模和脚本工作流; +2. **顶层一级导航【应用管理】**(由本 `menu` 域负责):属于用户业务工作台层,聚合了租户开通的**全部前台业务落地应用**,既包括挂载了对象视图的自建应用(如新转转集团、差旅申请、项目预算),也包含官方业务套件(如用车补贴 `SCGY:...`、用车制度)与金融扩展(如 E商卡管理)。 + +## 核心接口 + +| 接口 | 方法 | 说明 | +|---|---|---| +| `api/menu/v2/menus/byDeviceTypeAndAppId/$MAIN_FRAME_DESKTOP` | `GET` | 获取桌面端全站主框架导航菜单树 | + +## 代码结构 + +```text +src/domains/menu/ +├── types.ts # 菜单树节点与 WorkbenchApp 视图模型 +├── api.ts # HTTP 传输层 +└── tools.ts # 服务层聚合函数与导出 +``` + +## CLI 对应命令 + +```bash +# 查看顶层【应用管理】下的业务应用列表 +hose-use app list [--corp=] + +# 查看桌面端主框架菜单树 +hose-use menu tree [--corp=] +``` diff --git a/src/domains/menu/api.test.ts b/src/domains/menu/api.test.ts new file mode 100644 index 0000000..a43dacd --- /dev/null +++ b/src/domains/menu/api.test.ts @@ -0,0 +1,125 @@ +import { describe, expect, test } from "bun:test"; +import { + fetchDesktopMenuTree, + fetchWorkbenchApps, + fetchAppCenterMenus, +} from "./api.js"; + +const mockMenuPayload = { + items: [ + { + id: "newHomePage", + label: "首页", + appId: "100-home", + href: "/home", + children: [], + }, + { + id: "dataLink", + label: "应用管理", + appId: "160-datalink-platform", + children: [ + { + id: "SCGY:corp-test", + label: "用车补贴", + code: "dataLinkItem", + href: "/third-party-item/SCGY:corp-test", + appId: "160-datalink-platform", + type: "MENU", + fromWay: "SYSTEM", + }, + { + id: "ID01PIqCA1Di0v", + label: "用车制度", + code: "dataLinkItem", + href: "/third-party-item/ID01PIqCA1Di0v", + appId: "160-datalink-platform", + type: "MENU", + fromWay: "SYSTEM", + }, + { + id: "ID01RKbEvQsWbd", + label: "新转转集团", + code: "dataLinkItem", + href: "/third-party-item/ID01RKbEvQsWbd", + appId: "160-datalink-platform", + type: "MENU", + fromWay: "SYSTEM", + }, + ], + }, + { + id: "appcenter", + label: "应用中心", + appId: "150-appcenter", + children: [ + { + id: "selfBuiltApplication", + label: "自建应用", + code: "selfBuiltApplication", + href: "/expense-center-new/self_built_app", + }, + ], + }, + ], +}; + +describe("Domains/Menu - API 单元测试", () => { + test("fetchDesktopMenuTree 成功解析全站桌面端菜单响应", async () => { + const mockClient = { + get: async (url: string, opts: any) => { + expect(url).toBe("api/menu/v2/menus/byDeviceTypeAndAppId/$MAIN_FRAME_DESKTOP"); + expect(opts.searchParams.corpId).toBe("corp-test"); + return { + json: async () => mockMenuPayload, + }; + }, + } as any; + + const items = await fetchDesktopMenuTree(mockClient, "corp-test"); + expect(items.length).toBe(3); + expect(items[0].label).toBe("首页"); + expect(items[1].label).toBe("应用管理"); + expect(items[2].label).toBe("应用中心"); + }); + + test("fetchWorkbenchApps 成功提取应用管理下的 7/N 个业务应用", async () => { + const mockClient = { + get: async () => ({ + json: async () => mockMenuPayload, + }), + } as any; + + const apps = await fetchWorkbenchApps(mockClient, "corp-test"); + expect(apps.length).toBe(3); + expect(apps[0].id).toBe("SCGY:corp-test"); + expect(apps[0].name).toBe("用车补贴"); + expect(apps[0].href).toBe("/third-party-item/SCGY:corp-test"); + expect(apps[1].name).toBe("用车制度"); + expect(apps[2].name).toBe("新转转集团"); + }); + + test("fetchAppCenterMenus 成功提取应用中心子栏目", async () => { + const mockClient = { + get: async () => ({ + json: async () => mockMenuPayload, + }), + } as any; + + const menus = await fetchAppCenterMenus(mockClient, "corp-test"); + expect(menus.length).toBe(1); + expect(menus[0].id).toBe("selfBuiltApplication"); + expect(menus[0].label).toBe("自建应用"); + }); + + test("当菜单树无 dataLink 节点时安全返回空数组", async () => { + const mockClient = { + get: async () => ({ + json: async () => ({ items: [] }), + }), + } as any; + + const apps = await fetchWorkbenchApps(mockClient, "corp-test"); + expect(apps).toEqual([]); + }); +}); diff --git a/src/domains/menu/api.ts b/src/domains/menu/api.ts new file mode 100644 index 0000000..7de4bc7 --- /dev/null +++ b/src/domains/menu/api.ts @@ -0,0 +1,62 @@ +import type { KyInstance } from "ky"; +import { DesktopMenuResponseSchema, type MenuItem, type WorkbenchApp } from "./types.js"; + +/** 获取桌面端全站主框架导航菜单树 */ +export async function fetchDesktopMenuTree( + client: KyInstance, + corpId: string +): Promise { + const response = await client.get( + "api/menu/v2/menus/byDeviceTypeAndAppId/$MAIN_FRAME_DESKTOP", + { + searchParams: { corpId }, + } + ); + const json = await response.json(); + const parsed = DesktopMenuResponseSchema.parse(json); + return parsed.items; +} + +/** 获取工作台【应用管理】下的业务应用列表(包括套件、模板与自建应用) */ +export async function fetchWorkbenchApps( + client: KyInstance, + corpId: string +): Promise { + const items = await fetchDesktopMenuTree(client, corpId); + const dataLinkNode = items.find( + (i) => + i.id === "dataLink" || + i.appId === "160-datalink-platform" || + i.label === "应用管理" + ); + + if (!dataLinkNode || !Array.isArray(dataLinkNode.children)) { + return []; + } + + return dataLinkNode.children.map((child) => ({ + id: child.id, + name: child.label, + code: child.code || "dataLinkItem", + href: child.href || `/third-party-item/${child.id}`, + appId: child.appId || "160-datalink-platform", + type: child.type || "MENU", + fromWay: child.fromWay || "SYSTEM", + })); +} + +/** 获取【应用中心】下的子栏目菜单列表(如应用商店、已购应用、自建应用等) */ +export async function fetchAppCenterMenus( + client: KyInstance, + corpId: string +): Promise { + const items = await fetchDesktopMenuTree(client, corpId); + const appCenterNode = items.find( + (i) => + i.id === "appcenter" || + i.appId === "150-appcenter" || + i.label === "应用中心" + ); + + return appCenterNode?.children || []; +} diff --git a/src/domains/menu/tools.ts b/src/domains/menu/tools.ts new file mode 100644 index 0000000..a5acff2 --- /dev/null +++ b/src/domains/menu/tools.ts @@ -0,0 +1,35 @@ +import { createEkbClient } from "../../core/auth/ekb.js"; +import type { CorpConfig } from "../../core/config/types.js"; +import { + fetchDesktopMenuTree, + fetchWorkbenchApps, + fetchAppCenterMenus, +} from "./api.js"; +import type { MenuItem, WorkbenchApp } from "./types.js"; + +/** 获取桌面端工作台【应用管理】下的业务应用列表 */ +export async function fetchWorkbenchAppsList( + corp: CorpConfig +): Promise { + const client = await createEkbClient(corp); + const corpId = corp.corpId || corp.credentials.corpId; + return fetchWorkbenchApps(client, corpId); +} + +/** 获取桌面端全站主框架导航菜单树 */ +export async function fetchDesktopMenus( + corp: CorpConfig +): Promise { + const client = await createEkbClient(corp); + const corpId = corp.corpId || corp.credentials.corpId; + return fetchDesktopMenuTree(client, corpId); +} + +/** 获取【应用中心】下的子栏目 */ +export async function fetchAppCenterSubMenus( + corp: CorpConfig +): Promise { + const client = await createEkbClient(corp); + const corpId = corp.corpId || corp.credentials.corpId; + return fetchAppCenterMenus(client, corpId); +} diff --git a/src/domains/menu/types.ts b/src/domains/menu/types.ts new file mode 100644 index 0000000..49fffa1 --- /dev/null +++ b/src/domains/menu/types.ts @@ -0,0 +1,47 @@ +import { z } from "zod"; + +export interface MenuItem { + id: string; + label: string; + code?: string | null; + href?: string | null; + appId?: string | null; + type?: string | null; + fromWay?: string | null; + icon?: string | null; + iconFill?: string | null; + selected?: boolean | null; + children?: MenuItem[]; +} + +export const MenuItemSchema: z.ZodType = z.lazy(() => + z.object({ + id: z.string(), + label: z.string().default(""), + code: z.string().nullable().optional(), + href: z.string().nullable().optional(), + appId: z.string().nullable().optional(), + type: z.string().nullable().optional(), + fromWay: z.string().nullable().optional(), + icon: z.string().nullable().optional(), + iconFill: z.string().nullable().optional(), + selected: z.boolean().nullable().optional(), + children: z.array(MenuItemSchema).optional().default([]), + }) +); + +export const DesktopMenuResponseSchema = z.object({ + items: z.array(MenuItemSchema).default([]), +}); +export type DesktopMenuResponse = z.infer; + +export const WorkbenchAppSchema = z.object({ + id: z.string().describe("业务应用 ID (如 SCGY:corpId 或 自建应用物理ID)"), + name: z.string().describe("应用名称"), + code: z.string().optional().describe("功能代码 (如 dataLinkItem)"), + href: z.string().describe("Web 端直达路由路径"), + appId: z.string().default("160-datalink-platform").describe("所属主框架模块"), + type: z.string().optional().describe("菜单或应用类型"), + fromWay: z.string().optional().describe("来源方式 (如 SYSTEM, MANUAL)"), +}); +export type WorkbenchApp = z.infer; diff --git a/src/version.ts b/src/version.ts index 69f320f..34ccbce 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = "0.8.2"; +export const VERSION = "0.8.3";