import { Logger, Schema } from "koishi"; import { ErrorDefinitions } from "./definitions"; export interface ErrorReporterConfig { enabled: boolean; pasteServiceUrl?: string; includeSystemInfo?: boolean; } export declare const ErrorReporterConfigSchema: Schema; pasteServiceUrl: Schema; includeSystemInfo: Schema; }>, Schemastery.ObjectT<{ enabled: Schema; pasteServiceUrl: Schema; includeSystemInfo: Schema; }>>; export interface ReportContext { errorId: string; error: Error; additionalInfo?: Record; } /** * 负责格式化错误详情并将其上报到外部服务 */ export declare class ErrorReporter { private readonly config; private readonly logger; constructor(config: ErrorReporterConfig, logger: Logger); /** * 格式化并上报错误 * @param context 包含错误和附加上下文的对象 */ report(context: ReportContext): Promise; private uploadToPaste; private formatErrorDump; } export declare function initializeErrorReporter(config: ErrorReporterConfig, logger: Logger): void; type ErrorDomains = keyof typeof ErrorDefinitions; export type ErrorDefinitionValue = { [K in ErrorDomains]: (typeof ErrorDefinitions)[K][keyof (typeof ErrorDefinitions)[K]]; }[ErrorDomains]; export declare class AppError extends Error { readonly code: string; readonly suggestion: string; readonly errorId: string; context?: Record; constructor(definition: ErrorDefinitionValue, options?: { context?: Record; cause?: Error; args?: any[]; }); addContext(context: Record): void; } /** * 统一错误处理函数 * 实现了分层日志记录和可选的错误自动上报功能 * @param logger - Koishi 的 Logger 实例,用于记录日志 * @param error - 捕获到的未知类型的错误 * @param contextDescription - 描述错误发生时的操作或环节,例如 "处理聊天请求" * @returns 返回生成的唯一错误 ID */ export declare function handleError(logger: Logger, error: unknown, contextDescription: string): string; export * from "./definitions";