refactor(ai-chat): 移除 excel_analyze/office_analyze 工具与 OfficeKit 依赖

- 删除 excel_analyze/office_analyze 两个 A2UI 工具(schema、分发、执行器、测试)
- 附件分析改为依赖上传时自动提取的文本与 preflight_import 报告 errorSamples
- 移除 @officecli/officecli 依赖及 OfficeCliService(PPT 上传不再自动提取文本)
- 保留 AiExcelReaderService(附件文本提取与导入预检仍使用)
This commit is contained in:
2026-08-05 22:26:05 +08:00
parent d1c933f032
commit 6249fefc64
15 changed files with 2 additions and 720 deletions

View File

@@ -10,7 +10,6 @@ import {
import type { AiChatServiceContext, AiSseEmitter, ModelToolCall } from './ai-chat.types';
import type { AgentToolContext } from './ai-chat.tools';
import { finishToolRun, startToolRun } from './ai-chat.tools';
export { executeOfficeAnalyze, buildOfficeCliArgs } from './ai-chat.tool-office';
function isExcelAttachment(attachment: {
mimeType: string;
@@ -93,81 +92,6 @@ export async function executePreflightImport(
}
}
export async function executeExcelAnalyze(
context: AiChatServiceContext,
messageId: number,
call: ModelToolCall,
userId: number,
emit: AiSseEmitter,
): Promise<string> {
const { run, parsedArgs, startedAt } = await startToolRun(context, messageId, call, emit, {
toolName: 'excel_analyze',
skillKey: null,
argumentsData: null,
});
try {
const parsedRecord =
parsedArgs && typeof parsedArgs === 'object' && !Array.isArray(parsedArgs)
? (parsedArgs as Record<string, unknown>)
: {};
const attachmentId =
typeof parsedRecord.attachmentId === 'number' ? parsedRecord.attachmentId : undefined;
if (!Number.isInteger(attachmentId) || (attachmentId as number) <= 0) {
throw new Error('缺少附件 attachmentId');
}
const action = typeof parsedRecord.action === 'string' ? parsedRecord.action : '';
if (action !== 'overview' && action !== 'rows') {
throw new Error('action 只能是 overview 或 rows');
}
const [attachment] = await context.attachmentService.requireReadyOwned(userId, [
attachmentId as number,
]);
if (!isExcelAttachment(attachment)) {
throw new Error('附件不是 Excel 文件,无法解析');
}
if (!context.excelReader) throw new Error('Excel 解析器未配置');
const buffer = await context.attachmentService.readStoredBuffer(attachment);
let data: unknown;
let summary: string;
if (action === 'overview') {
const overview = await context.excelReader.overview(buffer);
data = { sheets: overview.sheets, text: overview.text };
summary = `已解析 ${overview.sheets.length} 个工作表`;
} else {
const sheet = typeof parsedRecord.sheet === 'string' ? parsedRecord.sheet : undefined;
const startRow = Number(parsedRecord.startRow ?? 1);
const maxRows = Number(parsedRecord.maxRows ?? 20);
const maxColumns = Number(parsedRecord.maxColumns ?? 30);
if (!Number.isInteger(startRow) || startRow < 1) throw new Error('startRow 必须是 >=1 的整数');
if (!Number.isInteger(maxRows) || maxRows < 1) {
throw new Error('maxRows 必须是 >=1 的整数');
}
if (!Number.isInteger(maxColumns) || maxColumns < 1) {
throw new Error('maxColumns 必须是 >=1 的整数');
}
data = await context.excelReader.readRows(buffer, sheet, startRow, maxRows, maxColumns);
summary = `已读取工作表「${(data as { sheet: string }).sheet}」${(data as { rows: unknown[] }).rows.length} 行`;
}
await finishToolRun(context, run, call, startedAt, {
status: 'success',
summary,
}, emit);
return JSON.stringify({ status: 'success', data });
} catch (error) {
const summary =
error instanceof Error ? error.message.slice(0, 100) : 'Excel 解析失败';
await finishToolRun(context, run, call, startedAt, {
status: 'failed',
summary,
error: summary,
}, emit);
return JSON.stringify({ status: 'failed', error: run.resultSummary });
}
}
export async function executeStartImportWizard(
context: AiChatServiceContext,
messageId: number,