Merge pull request #61 from yunyingk/codex/insight-stats

Add insight stats query
This commit is contained in:
yunyingk authored and GitHub committed 2026-09-11 01:43:35 +08:00
commit a9f5e2d3ef
9 files changed
+112

No files matched your search

+1
View File
@@ -94,6 +94,7 @@ seal-use source config [--corp <corpId>]
seal-use tool <toolName> [--corp <corpId>] [--json '{"key":"value"}']
seal-use approval-runs summary --corp <corpId> [--date YYYY-MM-DD] [--timezone Asia/Shanghai]
seal-use approval-runs stats --corp <corpId> [--since 3months] [--dedupe-by sourceDocumentSN|sourceDocumentId|id]
seal-use analytics insight --corp <corpId> [--start-date <ISO>] [--end-date <ISO>] [--limit <n>]
seal-use approval-runs count --corp <corpId> [--status APPROVED]
seal-use approval-runs export --corp <corpId> [--start <YYYY-MM-DD|ms>] [--end <YYYY-MM-DD|ms>] [--limit <n>] [--downloads] [--out <file>]
seal-use approval-runs search --corp <corpId> [--query text] [--limit 20] [--includeBridge true]
+30
View File
@@ -0,0 +1,30 @@
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 handleAnalyticsCommand(
action: string | undefined,
client: Awaited<ReturnType<typeof createSealClient>>,
corp: CorpConfig,
args: ParsedArgs
) {
if (action === "insight" || action === "insight-stats" || action === "stats") {
await runTool(
"seal_insight_stats_get",
client,
corp,
{
startDate: stringOption(args.options.startDate) ?? stringOption(args.options["start-date"]),
endDate: stringOption(args.options.endDate) ?? stringOption(args.options["end-date"]),
limit: numberOption(args.options.limit)
},
outputOptions(args.options)
);
return;
}
throw new Error(`Unknown analytics command: ${action ?? ""}. Run 'seal-use help' for available commands.`);
}
+1
View File
@@ -168,6 +168,7 @@ Usage:
seal-use approval-runs attachments <recordId> [--summary] [--corp <corpId>]
seal-use approval-runs attachments download <recordId> [--all] [--name <name>] [--out-dir <dir>] [--corp <corpId>]
seal-use approval-runs result <recordId> [--summary] [--corp <corpId>]
seal-use analytics insight [--start-date <ISO>] [--end-date <ISO>] [--limit <n>] [--corp <corpId>]
seal-use approval-runs url [--corp <corpId>]
seal-use approval-runs url <recordId> [--corp <corpId>]
seal-use approval-runs url --sourceDocumentSN B26022501 [--corp <corpId>]
+7
View File
@@ -6,6 +6,7 @@ import { createSealClient } from "../core/http/factory.js";
import type { CorpConfig } from "../core/config/types.js";
import { VERSION } from "../version.js";
import { handleApprovalRunsCommand } from "./commands/approval-runs.js";
import { handleAnalyticsCommand } from "./commands/analytics.js";
import { handleAuthCommand } from "./commands/auth.js";
import { handleBillingCommand } from "./commands/billing.js";
import { handleConfigCommand } from "./commands/config.js";
@@ -73,6 +74,7 @@ const KNOWN_AREAS = new Set([
"context",
"rules",
"approval-runs",
"analytics",
"simulation",
"deploy",
"preference",
@@ -362,6 +364,11 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
return;
}
if (area === "analytics") {
await handleAnalyticsCommand(action, client, corp, args);
return;
}
if (area === "simulation") {
await handleSimulationCommand(action, maybeName, client, corp, args);
return;
+29
View File
@@ -11,6 +11,7 @@ import {
previewUpdateWebhookIntegration,
getDepartment,
getContactsLastSyncTime,
getInsightStats,
listDepartmentChildren,
listDepartmentUsers,
listRootDepartments,
@@ -85,6 +86,34 @@ describe("Seal contact API", () => {
"api/v1/contacts/last-sync-time"
]);
});
test("forwards the insight stats date range and limit", async () => {
let requestedUrl = "";
const client = {
get: (url: string, options?: { searchParams?: URLSearchParams }) => {
requestedUrl = `${url}?${options?.searchParams?.toString() ?? ""}`;
return {
json: async () => ({
data: { tagStats: [], totalRisks: 2, analyzedRisks: 1, pendingRisks: 1 }
})
};
}
} as unknown as KyInstance;
await expect(getInsightStats(client, {
startDate: "2026-09-01T00:00:00+08:00",
endDate: "2026-09-30T23:59:59+08:00",
limit: 10
})).resolves.toEqual({
tagStats: [],
totalRisks: 2,
analyzedRisks: 1,
pendingRisks: 1
});
expect(requestedUrl).toBe(
"api/v1/insight/stats?startDate=2026-09-01T00%3A00%3A00%2B08%3A00&endDate=2026-09-30T23%3A59%3A59%2B08%3A00&limit=10"
);
});
});
describe("Seal Webhook API", () => {
+17
View File
@@ -49,6 +49,8 @@ import {
SealDepartmentUsersDataSchema,
SealContactsLastSyncTime,
SealContactsLastSyncTimeSchema,
InsightStats,
InsightStatsSchema,
LlmConfig,
LlmConfigSchema,
LlmProvider,
@@ -975,6 +977,21 @@ export async function getContactsLastSyncTime(client: KyInstance): Promise<SealC
return unwrap(await client.get("api/v1/contacts/last-sync-time"), SealContactsLastSyncTimeSchema);
}
export async function getInsightStats(
client: KyInstance,
params: { startDate?: string; endDate?: string; limit?: number } = {}
): Promise<InsightStats> {
const searchParams = new URLSearchParams();
setOptional(searchParams, "startDate", params.startDate);
setOptional(searchParams, "endDate", params.endDate);
if (params.limit !== undefined) searchParams.set("limit", String(params.limit));
return unwrap(
await client.get("api/v1/insight/stats", { searchParams }),
InsightStatsSchema
);
}
export async function deleteLocalUser(
client: KyInstance,
userId: string
+4
View File
@@ -92,6 +92,10 @@ describe("sealTools", () => {
expect(sealTools.find((item) => item.name === "seal_contacts_last_sync_time_get")).toBeDefined();
});
test("includes the read-only insight stats tool", () => {
expect(sealTools.find((item) => item.name === "seal_insight_stats_get")).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();
+13
View File
@@ -204,6 +204,19 @@ export const sealTools = [
parameters: z.object({}),
handler: async (client: KyInstance) => api.getContactsLastSyncTime(client)
},
{
name: "seal_insight_stats_get",
description: "查询智能洞察风险标签统计及分析状态",
parameters: z.object({
startDate: z.string().optional().describe("统计开始时间(ISO 8601)"),
endDate: z.string().optional().describe("统计结束时间(ISO 8601)"),
limit: z.number().int().positive().max(100).optional().describe("最多返回的风险标签数量")
}),
handler: async (
client: KyInstance,
params: { startDate?: string; endDate?: string; limit?: number }
) => api.getInsightStats(client, params)
},
{
name: "seal_llm_config_get",
description: "查询当前 Seal 租户的大模型 (LLM) 配置",
+10
View File
@@ -314,6 +314,15 @@ export const SealContactsLastSyncTimeSchema = z.object({
lastSyncTime: z.union([z.string(), z.number(), z.null()])
}).passthrough();
export const InsightTagStatsSchema = z.record(z.string(), z.unknown());
export const InsightStatsSchema = z.object({
tagStats: z.array(InsightTagStatsSchema).default([]),
totalRisks: z.number().default(0),
analyzedRisks: z.number().default(0),
pendingRisks: z.number().default(0)
}).passthrough();
export const LlmConfigSchema = z.object({
provider: z.string(),
config: z.record(z.string(), z.unknown()).default({})
@@ -569,6 +578,7 @@ export type SealDepartment = z.infer<typeof SealDepartmentSchema>;
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 LlmConfig = z.infer<typeof LlmConfigSchema>;
export type LlmProvider = z.infer<typeof LlmProviderSchema>;
export type AvailablePermissionsData = z.infer<typeof AvailablePermissionsDataSchema>;