feat: release v0.5.2 with protected contact domain and bill web link
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled
This commit is contained in:
1 parent
188a0fb5dc
commit
68d570022d
19 files changed
+679
-146
No files matched your search
@@ -195,7 +195,68 @@ export async function handleBillCommand(
|
||||
};
|
||||
}
|
||||
|
||||
case "link":
|
||||
case "url": {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id", "c"]);
|
||||
if (!target) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose bill link <单号或ID>",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const items = await getBillByCodeOrId(client, corpId, target);
|
||||
if (!items || items.length === 0) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `未找到单据: ${target}`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const item = items[0];
|
||||
const billId = item.billId;
|
||||
const billCode = item.billCode || target;
|
||||
const baseUrl = (corp.baseUrl || "https://app.ekuaibao.com").replace(/\/+$/, "");
|
||||
const webUrl = `${baseUrl}/#/invoice/detail?id=${encodeURIComponent(billId)}&corporationId=${encodeURIComponent(corpId)}`;
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(
|
||||
{
|
||||
code: billCode,
|
||||
id: billId,
|
||||
corpId,
|
||||
corpName: corp.name,
|
||||
url: webUrl,
|
||||
},
|
||||
runtime.outputOptions
|
||||
),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const text = [
|
||||
`====== 合思单据 Web 直达链接 ======`,
|
||||
` 单据编号: ${billCode}`,
|
||||
` 单据 ID : ${billId}`,
|
||||
` 所属企业: ${corp.name} (${corpId})`,
|
||||
` 直达链接:`,
|
||||
` ${webUrl}`,
|
||||
``,
|
||||
`Markdown 链接: [查看单据 ${billCode}](${webUrl})`,
|
||||
].join("\n");
|
||||
|
||||
return {
|
||||
stdout: text + "\n",
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, schema`);
|
||||
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号>, schema, link <单号>`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import { numberOption, stringOption } from "../parser.js";
|
||||
import { printJson, printKeyValue, printTable } from "../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
||||
import {
|
||||
getStaffById,
|
||||
listStaffsProtected,
|
||||
searchStaffs,
|
||||
DEFAULT_STAFF_LIST_LIMIT,
|
||||
} from "../../domains/contact/tools.js";
|
||||
|
||||
export async function handleContactCommand(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "未指定或未找到有效企业配置。请运行 'hose corps list' 或指定 '--corp=<id>'",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const action = parsed.action || parsed.args[0] || "list";
|
||||
const limit = numberOption(parsed.options, ["limit", "l"]);
|
||||
|
||||
// 1. 搜索: hose contact search <keyword> 或 hose contact find <keyword>
|
||||
if (action === "search" || action === "find") {
|
||||
const keyword = parsed.args[0] || stringOption(parsed.options, ["keyword", "query", "k"]) || "";
|
||||
if (!keyword.trim()) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose contact search <关键词 (姓名/邮箱/工号)>",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const results = await searchStaffs(corp, { keyword, limit });
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({ count: results.length, keyword, staffs: results }, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
if (results.length === 0) {
|
||||
return {
|
||||
stdout: `未找到匹配关键词 "${keyword}" 的员工。\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const headers = ["姓名", "工号 / staffId", "邮箱", "手机号"];
|
||||
const rows = results.map((s) => [
|
||||
s.name || "-",
|
||||
s.id,
|
||||
s.email || "-",
|
||||
s.cellphone || "-",
|
||||
]);
|
||||
|
||||
return {
|
||||
stdout: `====== 员工搜索结果 (关键词: "${keyword}", 找到 ${results.length} 人) ======\n${printTable(headers, rows)}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 2. 详情: hose contact get <staffId>
|
||||
if (action === "get") {
|
||||
const staffId = parsed.args[0] || stringOption(parsed.options, ["id", "staff-id"]);
|
||||
if (!staffId) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose contact get <staffId>",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const staff = await getStaffById(corp, staffId);
|
||||
if (!staff) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `未找到员工档案: ${staffId}`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(staff, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const pairs: Record<string, unknown> = {
|
||||
"员工姓名": staff.name,
|
||||
"工号/staffId": staff.id,
|
||||
"电子邮箱": staff.email || "-",
|
||||
"联系手机": staff.cellphone || "-",
|
||||
"所属部门": staff.department || "-",
|
||||
};
|
||||
|
||||
return {
|
||||
stdout: `====== 员工详细档案 ======\n${printKeyValue(pairs)}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 3. 列表采样: hose contact list (默认限流截断防爆)
|
||||
if (action === "list") {
|
||||
const isFull = runtime.outputOptions?.allowFull === true;
|
||||
const result = await listStaffsProtected(corp, {
|
||||
limit: limit ?? (isFull ? undefined : DEFAULT_STAFF_LIST_LIMIT),
|
||||
allowFull: isFull,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(result, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const headers = ["姓名", "工号 / staffId", "邮箱", "手机号"];
|
||||
const rows = result.staffs.map((s) => [
|
||||
s.name || "-",
|
||||
s.id,
|
||||
s.email || "-",
|
||||
s.cellphone || "-",
|
||||
]);
|
||||
|
||||
let output = `====== 企业通讯录采样 (共 ${result.total} 人,当前显示 ${result.staffs.length} 条) ======\n`;
|
||||
output += printTable(headers, rows) + "\n";
|
||||
if (result.hint) {
|
||||
output += `\n💡 提示: ${result.hint}\n`;
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: output,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `未知通讯录子命令: ${action}。支持的子命令: list, search <关键词>, get <staffId>`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
+6
-2
@@ -119,7 +119,8 @@ export function printHelp(): string {
|
||||
corps 多企业租户管理 (list, switch, current)
|
||||
config 全局运行模式与路径诊断 (show, paths, mode <stateful|stateless>, set)
|
||||
workflow 工作流管理 (list, get, find, toggle)
|
||||
bill 单据与费用明细检索 (list, get <单号|ID>, schema)
|
||||
bill 单据与费用明细检索 (list, get <单号|ID>, schema, link <单号|ID>)
|
||||
contact 企业通讯录与人员检索 (list, search <关键词>, get <staffId>)
|
||||
platform 自建应用管理 (list)
|
||||
skill Agent Skill 管理 (install, status, dump)
|
||||
probe 连通性诊断 (probe [corpId])
|
||||
@@ -145,10 +146,13 @@ export function printHelp(): string {
|
||||
hose-use config paths # 查看多级企业配置目录链
|
||||
hose-use config mode stateless # 切换为无状态模式 (防止 Agent 误操作)
|
||||
hose-use corps list # 列出名下所有企业
|
||||
hose-use corps switch uzU7pcWfScck00 # 切换工作企业
|
||||
hose-use corps switch ID01MCcOgJl1td # 切换工作企业
|
||||
hose-use contact search 张三 # 模糊搜索员工工号、邮箱与电话
|
||||
hose-use contact list --limit=20 # 采样查看企业通讯录(带防爆截断保护)
|
||||
hose-use workflow list # 汇总查看全部工作流
|
||||
hose-use workflow find --task=code-js2 # 搜索包含自定义脚本的工作流
|
||||
hose-use bill list # 查看当前企业单据与报销列表
|
||||
hose-use bill link CL20260901001 # 获取单据 Web 详情直达免密跳转链接
|
||||
hose-use bill list --json -o /tmp/bills.json # 导出单据报文到本地磁盘并防爆
|
||||
hose-use bill get n0GMIM0dkQmKbS # 根据单号精准查询单据结构化详情
|
||||
hose-use http --port=8888 # 启动本地 HTTP 服务与可视化交互文档
|
||||
|
||||
@@ -13,6 +13,7 @@ import { handleMcpCommand } from "./commands/mcp.js";
|
||||
import { handleUpdateCommand } from "./commands/update.js";
|
||||
import { handleOpenApiCommand } from "./commands/openapi.js";
|
||||
import { handleBillCommand } from "./commands/bill.js";
|
||||
import { handleContactCommand } from "./commands/contact.js";
|
||||
import { handleServiceCommand } from "./commands/service.js";
|
||||
import { handleHttpCommand } from "./commands/http.js";
|
||||
import type { CliResult, CliRunOptions } from "./types.js";
|
||||
@@ -129,6 +130,11 @@ async function dispatchCli(
|
||||
case "invoice":
|
||||
case "invoices":
|
||||
return await handleBillCommand(parsed, runtime);
|
||||
case "contact":
|
||||
case "contacts":
|
||||
case "staff":
|
||||
case "staffs":
|
||||
return await handleContactCommand(parsed, runtime);
|
||||
case "platform":
|
||||
case "platforms":
|
||||
case "app":
|
||||
|
||||
@@ -24,6 +24,9 @@ describe("embedded-skill - 多文件内嵌 Skill 体系", () => {
|
||||
|
||||
expect(EMBEDDED_SKILL_FILES["references/service.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/service.md"]).toContain("POST /api/cli");
|
||||
|
||||
expect(EMBEDDED_SKILL_FILES["references/contact.md"]).toBeDefined();
|
||||
expect(EMBEDDED_SKILL_FILES["references/contact.md"]).toContain("contact search");
|
||||
});
|
||||
|
||||
test("installSkillFiles 递归保留层级结构并落盘到目标目录", () => {
|
||||
@@ -31,11 +34,12 @@ describe("embedded-skill - 多文件内嵌 Skill 体系", () => {
|
||||
try {
|
||||
const res = installSkillFiles(tmp);
|
||||
expect(res.targetDir).toBe(tmp);
|
||||
expect(res.files.length).toBe(6);
|
||||
expect(res.files.length).toBe(7);
|
||||
expect(existsSync(join(tmp, "SKILL.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "agents", "openai.yaml"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "auth.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "bill.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "contact.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "workflow.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "service.md"))).toBe(true);
|
||||
} finally {
|
||||
|
||||
@@ -8,12 +8,14 @@ import refAuth from "../../skills/hose-use/references/auth.md" with { type: "tex
|
||||
import refBill from "../../skills/hose-use/references/bill.md" with { type: "text" };
|
||||
import refWorkflow from "../../skills/hose-use/references/workflow.md" with { type: "text" };
|
||||
import refService from "../../skills/hose-use/references/service.md" with { type: "text" };
|
||||
import refContact from "../../skills/hose-use/references/contact.md" with { type: "text" };
|
||||
|
||||
export const EMBEDDED_SKILL_FILES: Record<string, string> = {
|
||||
"SKILL.md": skillMain,
|
||||
"agents/openai.yaml": agentOpenAi,
|
||||
"references/auth.md": refAuth,
|
||||
"references/bill.md": refBill,
|
||||
"references/contact.md": refContact,
|
||||
"references/workflow.md": refWorkflow,
|
||||
"references/service.md": refService,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { z } from "zod";
|
||||
import type { KyInstance } from "ky";
|
||||
import { StaffSchema, type Staff } from "./types.js";
|
||||
|
||||
export async function fetchStaffs(
|
||||
client: KyInstance,
|
||||
external: boolean = false
|
||||
): Promise<Staff[]> {
|
||||
const response = await client.get("api/easo/common/staffs", {
|
||||
searchParams: { external: String(external) },
|
||||
});
|
||||
const json = (await response.json()) as { data: unknown };
|
||||
return z.array(StaffSchema).parse(json.data ?? []);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { StaffSchema, type Staff } from "./types.js";
|
||||
|
||||
describe("Contact Domain - 通讯录与人员模型", () => {
|
||||
test("StaffSchema 正确解析包含 null 字段的员工对象", () => {
|
||||
const raw = {
|
||||
id: "corp123:staff456",
|
||||
name: "测试员工",
|
||||
email: null,
|
||||
cellphone: null,
|
||||
department: null,
|
||||
};
|
||||
const parsed = StaffSchema.parse(raw);
|
||||
expect(parsed.id).toBe("corp123:staff456");
|
||||
expect(parsed.name).toBe("测试员工");
|
||||
expect(parsed.email).toBeNull();
|
||||
});
|
||||
|
||||
test("StaffSchema 正确解析完整员工信息", () => {
|
||||
const raw = {
|
||||
id: "corp123:staff456",
|
||||
name: "张三",
|
||||
email: "zhangsan@example.com",
|
||||
cellphone: "13800138000",
|
||||
department: "研发部",
|
||||
};
|
||||
const parsed = StaffSchema.parse(raw);
|
||||
expect(parsed.name).toBe("张三");
|
||||
expect(parsed.email).toBe("zhangsan@example.com");
|
||||
expect(parsed.cellphone).toBe("13800138000");
|
||||
expect(parsed.department).toBe("研发部");
|
||||
});
|
||||
|
||||
test("模糊搜索与过滤逻辑可正确按姓名、邮箱、工号匹配", () => {
|
||||
const list: Staff[] = [
|
||||
{ id: "corp:001", name: "王硕", email: "wangshuo@test.com", cellphone: "13911112222" },
|
||||
{ id: "corp:002", name: "李雨笑", email: "liyuxiao@test.com", cellphone: null },
|
||||
{ id: "corp:003", name: "谢子豪", email: "xiezihao@test.com", cellphone: "13933334444" },
|
||||
];
|
||||
|
||||
const search = (kw: string) => {
|
||||
const q = kw.toLowerCase();
|
||||
return list.filter((s) => s.name.includes(q) || (s.email && s.email.includes(q)) || s.id.includes(q));
|
||||
};
|
||||
|
||||
expect(search("王硕").length).toBe(1);
|
||||
expect(search("wangshuo").length).toBe(1);
|
||||
expect(search("003").length).toBe(1);
|
||||
expect(search("003")[0].name).toBe("谢子豪");
|
||||
expect(search("不存在").length).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,111 @@
|
||||
import { z } from "zod";
|
||||
import { getEasoClient } from "../../core/auth/easo.js";
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
import { fetchStaffs } from "./api.js";
|
||||
import type { ContactListResult, ContactSearchOptions, Staff } from "./types.js";
|
||||
|
||||
export const DEFAULT_STAFF_LIST_LIMIT = 20;
|
||||
|
||||
export async function listStaffsProtected(
|
||||
corp: CorpConfig,
|
||||
options: ContactSearchOptions = {}
|
||||
): Promise<ContactListResult> {
|
||||
const { client } = await getEasoClient(corp);
|
||||
const allStaffs = await fetchStaffs(client, options.external ?? false);
|
||||
|
||||
const total = allStaffs.length;
|
||||
const isFull = options.allowFull === true;
|
||||
const limit = isFull ? total : options.limit ?? DEFAULT_STAFF_LIST_LIMIT;
|
||||
const staffs = allStaffs.slice(0, limit);
|
||||
const hasMore = total > staffs.length;
|
||||
|
||||
return {
|
||||
total,
|
||||
limit,
|
||||
hasMore,
|
||||
hint: hasMore
|
||||
? `企业员工共 ${total} 人,当前仅展示前 ${staffs.length} 条以防止上下文溢出。可使用 'hose contact search <姓名|工号>' 精准检索,或附加 '--limit <数量>' / '-o <文件路径>' / '--full'`
|
||||
: undefined,
|
||||
staffs,
|
||||
};
|
||||
}
|
||||
|
||||
export async function searchStaffs(
|
||||
corp: CorpConfig,
|
||||
options: { keyword: string; limit?: number; external?: boolean }
|
||||
): Promise<Staff[]> {
|
||||
const { client } = await getEasoClient(corp);
|
||||
const allStaffs = await fetchStaffs(client, options.external ?? false);
|
||||
|
||||
const kw = options.keyword.trim().toLowerCase();
|
||||
if (!kw) {
|
||||
return allStaffs.slice(0, options.limit ?? DEFAULT_STAFF_LIST_LIMIT);
|
||||
}
|
||||
|
||||
const matched = allStaffs.filter((s) => {
|
||||
const name = s.name?.toLowerCase() || "";
|
||||
const email = s.email?.toLowerCase() || "";
|
||||
const phone = s.cellphone || "";
|
||||
const id = s.id?.toLowerCase() || "";
|
||||
return name.includes(kw) || email.includes(kw) || phone.includes(kw) || id.includes(kw);
|
||||
});
|
||||
|
||||
return matched.slice(0, options.limit ?? 50);
|
||||
}
|
||||
|
||||
export async function getStaffById(
|
||||
corp: CorpConfig,
|
||||
staffId: string
|
||||
): Promise<Staff | null> {
|
||||
const { client } = await getEasoClient(corp);
|
||||
const allStaffs = await fetchStaffs(client, false);
|
||||
|
||||
const cleanId = staffId.trim();
|
||||
const found = allStaffs.find(
|
||||
(s) => s.id === cleanId || s.id.endsWith(`:${cleanId}`) || s.id.split(":")[1] === cleanId
|
||||
);
|
||||
|
||||
return found || null;
|
||||
}
|
||||
|
||||
// ── MCP Tool Definitions ──────────────────────────────────────────────────────
|
||||
|
||||
export const contactTools = [
|
||||
{
|
||||
name: "contact_search",
|
||||
description: "在当前企业通讯录中模糊检索员工(支持姓名、邮箱、手机号、工号)",
|
||||
parameters: z.object({
|
||||
keyword: z.string().describe("检索关键词,如姓名、邮箱前缀、手机号或工号"),
|
||||
limit: z.number().optional().describe("最大返回条数,默认 20"),
|
||||
}),
|
||||
handler: async (corp: CorpConfig, params: { keyword: string; limit?: number }) => {
|
||||
const results = await searchStaffs(corp, params);
|
||||
return { count: results.length, staffs: results };
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "contact_get",
|
||||
description: "根据员工 staffId 或工号精准获取员工详细档案",
|
||||
parameters: z.object({
|
||||
staffId: z.string().describe("员工的完整 staffId 或 ID"),
|
||||
}),
|
||||
handler: async (corp: CorpConfig, params: { staffId: string }) => {
|
||||
const staff = await getStaffById(corp, params.staffId);
|
||||
if (!staff) {
|
||||
throw new Error(`未找到员工: ${params.staffId}`);
|
||||
}
|
||||
return staff;
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "contact_list",
|
||||
description: "查看企业通讯录(带默认 20 条防爆截断与总数保护)",
|
||||
parameters: z.object({
|
||||
limit: z.number().optional().describe("截断返回条数,默认 20"),
|
||||
allowFull: z.boolean().optional().describe("是否强制全量输出(大企业请谨慎使用)"),
|
||||
}),
|
||||
handler: async (corp: CorpConfig, params: { limit?: number; allowFull?: boolean }) => {
|
||||
return await listStaffsProtected(corp, params);
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,26 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const StaffSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
email: z.string().nullable().optional(),
|
||||
cellphone: z.string().nullable().optional(),
|
||||
department: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
export type Staff = z.infer<typeof StaffSchema>;
|
||||
|
||||
export interface ContactListResult {
|
||||
total: number;
|
||||
limit: number;
|
||||
hasMore: boolean;
|
||||
hint?: string;
|
||||
staffs: Staff[];
|
||||
}
|
||||
|
||||
export interface ContactSearchOptions {
|
||||
keyword?: string;
|
||||
limit?: number;
|
||||
allowFull?: boolean;
|
||||
external?: boolean;
|
||||
}
|
||||
+1
-1
@@ -1 +1 @@
|
||||
export const VERSION = "0.5.1";
|
||||
export const VERSION = "0.5.2";
|
||||
Reference in new issue
Block a user