Merge pull request #62 from yunyingk/codex/financial-data-query
Add financial data list queries
This commit is contained in:
9 files changed
+168
No files matched your search
@@ -66,6 +66,8 @@ seal-use contacts departments [<departmentId>] [--corp <corpId>]
|
||||
seal-use contacts children <departmentId> [--corp <corpId>]
|
||||
seal-use contacts users <departmentId> [--corp <corpId>]
|
||||
seal-use contacts sync-time [--corp <corpId>]
|
||||
seal-use data expenses --corp <corpId> [--search <text>] [--start-date <ISO|ms>] [--end-date <ISO|ms>] [--offset <n>] [--limit <n>]
|
||||
seal-use data invoices --corp <corpId> [--search <text>] [--start-date <ISO|ms>] [--end-date <ISO|ms>] [--offset <n>] [--limit <n>]
|
||||
seal-use llm config [--corp <corpId>]
|
||||
seal-use llm providers [--corp <corpId>]
|
||||
seal-use permissions available [--corp <corpId>]
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
import type { createSealClient } from "../../core/http/factory.js";
|
||||
import { runTool } from "../helpers.js";
|
||||
import { numberOption, stringOption } from "../parser.js";
|
||||
import { outputOptions } from "../printer.js";
|
||||
import type { ParsedArgs } from "../types.js";
|
||||
|
||||
export async function handleDataCommand(
|
||||
action: string | undefined,
|
||||
client: Awaited<ReturnType<typeof createSealClient>>,
|
||||
corp: CorpConfig,
|
||||
args: ParsedArgs
|
||||
) {
|
||||
const params = {
|
||||
offset: numberOption(args.options.offset),
|
||||
limit: numberOption(args.options.limit),
|
||||
startDate: stringOption(args.options.startDate) ?? stringOption(args.options["start-date"]),
|
||||
endDate: stringOption(args.options.endDate) ?? stringOption(args.options["end-date"]),
|
||||
search: stringOption(args.options.search) ?? stringOption(args.options.query)
|
||||
};
|
||||
|
||||
if (action === "expenses" || action === "expense") {
|
||||
await runTool("seal_expenses_list", client, corp, params, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "invoices" || action === "invoice") {
|
||||
await runTool("seal_invoices_list", client, corp, params, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(`Unknown data command: ${action ?? ""}. Run 'seal-use help' for available commands.`);
|
||||
}
|
||||
@@ -117,6 +117,8 @@ Usage:
|
||||
seal-use contacts children <departmentId> [--corp <corpId>]
|
||||
seal-use contacts users <departmentId> [--corp <corpId>]
|
||||
seal-use contacts sync-time [--corp <corpId>]
|
||||
seal-use data expenses [--search <text>] [--start-date <ISO|ms>] [--end-date <ISO|ms>] [--offset <n>] [--limit <n>] [--corp <corpId>]
|
||||
seal-use data invoices [--search <text>] [--start-date <ISO|ms>] [--end-date <ISO|ms>] [--offset <n>] [--limit <n>] [--corp <corpId>]
|
||||
seal-use llm config [--corp <corpId>]
|
||||
seal-use llm providers [--corp <corpId>]
|
||||
seal-use permissions available [--corp <corpId>]
|
||||
|
||||
@@ -11,6 +11,7 @@ import { handleAuthCommand } from "./commands/auth.js";
|
||||
import { handleBillingCommand } from "./commands/billing.js";
|
||||
import { handleConfigCommand } from "./commands/config.js";
|
||||
import { handleContactsCommand } from "./commands/contacts.js";
|
||||
import { handleDataCommand } from "./commands/data.js";
|
||||
import { handleContextCommand } from "./commands/context.js";
|
||||
import { handleCorpsCommand } from "./commands/corps.js";
|
||||
import { handleDelegationCommand, handleDelegationFromHoseLink } from "./commands/delegation.js";
|
||||
@@ -66,6 +67,7 @@ const KNOWN_AREAS = new Set([
|
||||
"delegation",
|
||||
"users",
|
||||
"contacts",
|
||||
"data",
|
||||
"llm",
|
||||
"permissions",
|
||||
"billing",
|
||||
@@ -329,6 +331,11 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "data") {
|
||||
await handleDataCommand(action, client, corp, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "llm") {
|
||||
await handleLlmCommand(action, client, corp, args);
|
||||
return;
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
getDepartment,
|
||||
getContactsLastSyncTime,
|
||||
getInsightStats,
|
||||
listExpenses,
|
||||
listInvoices,
|
||||
listDepartmentChildren,
|
||||
listDepartmentUsers,
|
||||
listRootDepartments,
|
||||
@@ -114,6 +116,42 @@ describe("Seal contact API", () => {
|
||||
"api/v1/insight/stats?startDate=2026-09-01T00%3A00%3A00%2B08%3A00&endDate=2026-09-30T23%3A59%3A59%2B08%3A00&limit=10"
|
||||
);
|
||||
});
|
||||
|
||||
test("uses the frontend filter parameter names for expenses and invoices", async () => {
|
||||
const requestedUrls: string[] = [];
|
||||
const client = {
|
||||
get: (url: string, options?: { searchParams?: URLSearchParams }) => {
|
||||
requestedUrls.push(`${url}?${options?.searchParams?.toString() ?? ""}`);
|
||||
return {
|
||||
json: async () => ({
|
||||
data: url.includes("expenses")
|
||||
? { expenses: [], total: 0 }
|
||||
: { invoices: [], total: 0, feishuApprovalAppId: null }
|
||||
})
|
||||
};
|
||||
}
|
||||
} as unknown as KyInstance;
|
||||
|
||||
await expect(listExpenses(client, {
|
||||
startDate: "1757520000000",
|
||||
endDate: "1789142399999",
|
||||
search: "zz-probe-no-match",
|
||||
offset: 0,
|
||||
limit: 50
|
||||
})).resolves.toEqual({ expenses: [], total: 0 });
|
||||
await expect(listInvoices(client, {
|
||||
startDate: "2026-08-31T16:00:00.000Z",
|
||||
endDate: "2026-09-30T15:59:59.999Z",
|
||||
search: "zz-probe-no-match",
|
||||
offset: 0,
|
||||
limit: 50
|
||||
})).resolves.toEqual({ invoices: [], total: 0, feishuApprovalAppId: null });
|
||||
|
||||
expect(requestedUrls).toEqual([
|
||||
"api/v1/expenses/list?filter%5BstartDate%5D=1757520000000&filter%5BendDate%5D=1789142399999&filter%5Bsearch%5D=zz-probe-no-match&offset=0&limit=50",
|
||||
"api/v1/invoice/list?filter%5BstartDate%5D=2026-08-31T16%3A00%3A00.000Z&filter%5BendDate%5D=2026-09-30T15%3A59%3A59.999Z&filter%5Bsearch%5D=zz-probe-no-match&offset=0&limit=50"
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Seal Webhook API", () => {
|
||||
|
||||
@@ -51,6 +51,10 @@ import {
|
||||
SealContactsLastSyncTimeSchema,
|
||||
InsightStats,
|
||||
InsightStatsSchema,
|
||||
ExpenseListData,
|
||||
ExpenseListDataSchema,
|
||||
InvoiceListData,
|
||||
InvoiceListDataSchema,
|
||||
LlmConfig,
|
||||
LlmConfigSchema,
|
||||
LlmProvider,
|
||||
@@ -992,6 +996,44 @@ export async function getInsightStats(
|
||||
);
|
||||
}
|
||||
|
||||
export type DataListParams = {
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
search?: string;
|
||||
};
|
||||
|
||||
function dataListSearchParams(params: DataListParams): URLSearchParams {
|
||||
const searchParams = new URLSearchParams();
|
||||
setOptional(searchParams, "filter[startDate]", params.startDate);
|
||||
setOptional(searchParams, "filter[endDate]", params.endDate);
|
||||
setOptional(searchParams, "filter[search]", params.search);
|
||||
searchParams.set("offset", String(params.offset ?? 0));
|
||||
searchParams.set("limit", String(params.limit ?? 50));
|
||||
return searchParams;
|
||||
}
|
||||
|
||||
export async function listExpenses(
|
||||
client: KyInstance,
|
||||
params: DataListParams = {}
|
||||
): Promise<ExpenseListData> {
|
||||
return unwrap(
|
||||
await client.get("api/v1/expenses/list", { searchParams: dataListSearchParams(params) }),
|
||||
ExpenseListDataSchema
|
||||
);
|
||||
}
|
||||
|
||||
export async function listInvoices(
|
||||
client: KyInstance,
|
||||
params: DataListParams = {}
|
||||
): Promise<InvoiceListData> {
|
||||
return unwrap(
|
||||
await client.get("api/v1/invoice/list", { searchParams: dataListSearchParams(params) }),
|
||||
InvoiceListDataSchema
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteLocalUser(
|
||||
client: KyInstance,
|
||||
userId: string
|
||||
|
||||
@@ -96,6 +96,11 @@ describe("sealTools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_insight_stats_get")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes read-only financial data tools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_expenses_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_invoices_list")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes system configuration tools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_llm_config_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_llm_providers_list")).toBeDefined();
|
||||
|
||||
@@ -217,6 +217,30 @@ export const sealTools = [
|
||||
params: { startDate?: string; endDate?: string; limit?: number }
|
||||
) => api.getInsightStats(client, params)
|
||||
},
|
||||
{
|
||||
name: "seal_expenses_list",
|
||||
description: "分页查询费用明细",
|
||||
parameters: z.object({
|
||||
offset: z.number().int().nonnegative().optional(),
|
||||
limit: z.number().int().positive().max(100).optional(),
|
||||
startDate: z.string().optional().describe("开始时间"),
|
||||
endDate: z.string().optional().describe("结束时间"),
|
||||
search: z.string().optional().describe("搜索费用类型、描述或金额")
|
||||
}),
|
||||
handler: async (client: KyInstance, params: api.DataListParams) => api.listExpenses(client, params)
|
||||
},
|
||||
{
|
||||
name: "seal_invoices_list",
|
||||
description: "分页查询进项发票",
|
||||
parameters: z.object({
|
||||
offset: z.number().int().nonnegative().optional(),
|
||||
limit: z.number().int().positive().max(100).optional(),
|
||||
startDate: z.string().optional().describe("开始时间"),
|
||||
endDate: z.string().optional().describe("结束时间"),
|
||||
search: z.string().optional().describe("搜索发票号码或销售方")
|
||||
}),
|
||||
handler: async (client: KyInstance, params: api.DataListParams) => api.listInvoices(client, params)
|
||||
},
|
||||
{
|
||||
name: "seal_llm_config_get",
|
||||
description: "查询当前 Seal 租户的大模型 (LLM) 配置",
|
||||
|
||||
@@ -323,6 +323,19 @@ export const InsightStatsSchema = z.object({
|
||||
pendingRisks: z.number().default(0)
|
||||
}).passthrough();
|
||||
|
||||
const DataRecordSchema = z.record(z.string(), z.unknown());
|
||||
|
||||
export const ExpenseListDataSchema = z.object({
|
||||
expenses: z.array(DataRecordSchema).default([]),
|
||||
total: z.number().optional()
|
||||
}).passthrough();
|
||||
|
||||
export const InvoiceListDataSchema = z.object({
|
||||
invoices: z.array(DataRecordSchema).default([]),
|
||||
total: z.number().optional(),
|
||||
feishuApprovalAppId: z.string().nullable().optional()
|
||||
}).passthrough();
|
||||
|
||||
export const LlmConfigSchema = z.object({
|
||||
provider: z.string(),
|
||||
config: z.record(z.string(), z.unknown()).default({})
|
||||
@@ -579,6 +592,8 @@ export type SealDepartmentListData = z.infer<typeof SealDepartmentListDataSchema
|
||||
export type SealDepartmentUsersData = z.infer<typeof SealDepartmentUsersDataSchema>;
|
||||
export type SealContactsLastSyncTime = z.infer<typeof SealContactsLastSyncTimeSchema>;
|
||||
export type InsightStats = z.infer<typeof InsightStatsSchema>;
|
||||
export type ExpenseListData = z.infer<typeof ExpenseListDataSchema>;
|
||||
export type InvoiceListData = z.infer<typeof InvoiceListDataSchema>;
|
||||
export type LlmConfig = z.infer<typeof LlmConfigSchema>;
|
||||
export type LlmProvider = z.infer<typeof LlmProviderSchema>;
|
||||
export type AvailablePermissionsData = z.infer<typeof AvailablePermissionsDataSchema>;
|
||||
|
||||
Reference in new issue
Block a user