/** * tools/invoice-parse.ts — invoice_parse 工具:单张/批量发票解析。 * * 行为(对照功能规格第 1 条): * - path 为文件或目录(目录递归扫描,自动识别 pdf/jpg/png); * - 优先解析 PDF 内嵌结构化 XML(号码/代码/金额/税额/双方/日期),文本层正则兜底; * - 输出结构化 JSON + 会话内"抽取结果核对表"(confidence:XML 直读=高/正则=中/缺失=低并列出); * - 勾稽校验:价税合计 = 金额 + 税额(容差 0.01),不符时在核对表标 ⚠; * - 纯图片无 OCR / 加密 PDF 返回明确"跳过原因",不中断批量。 */ import type { Context } from '@deepseek-ai/cordis'; import { type InvoiceData } from '../invoice-model.ts'; /** 解析缓存:invoice_summary 缺省 files 时复用上次 parse 结果。 * key 为 `${scope}:${absPath}`,scope 为会话 id(工具执行上下文的 agent.id)——按会话隔离; * 无法取得会话上下文时回退 'global'(进程级缓存,README「安全与隐私」已如实说明)。 */ export declare const parseCache: Map; /** 缓存作用域:有会话 id 用会话 id;否则回退 'global'(进程级,见 README)。 */ export declare function cacheScope(sessionId: string | undefined | null): string; export interface SkippedFile { path: string; file: string; reason: 'password-protected' | 'image-without-ocr' | 'unsupported-file-type' | 'unparsable' | 'empty-pdf'; detail?: string; } export interface InvoiceParseResult { inputCount: number; parsed: (InvoiceData & { path: string; })[]; skipped: SkippedFile[]; summary: { parsedCount: number; skippedCount: number; amount: number; tax: number; total: number; checksFailed: number; }; } /** 执行解析编排(也被工具 execute 与测试复用其纯逻辑核心)。 */ export declare function runInvoiceParse(ctx: Context, args: { path: string; }, signal?: AbortSignal, sessionId?: string): Promise; /** 核对表渲染(会话内表格)。 */ export declare function renderParseResult(result: InvoiceParseResult): string; /** 定义 invoice_parse 工具。 */ export declare function invoiceParseTool(ctx: Context): import("@deepseek-ai/dsh-tools").ToolDefinition;