UNPKG

taskflow-ai

Version:

TaskFlow AI - 智能PRD文档解析与任务管理助手,支持多模型AI协同、MCP编辑器集成,专为开发团队设计的CLI工具

143 lines (142 loc) 3.58 kB
/** * 统一API响应格式 * 标准化所有命令和服务的返回格式 */ import { TaskFlowError } from '../error-handling/typed-errors'; import { JSONValue, JSONObject } from '../../types/strict-types'; /** * 统一响应接口 */ export interface UnifiedResponse<T = JSONValue> { success: boolean; data?: T; error?: ErrorDetails; metadata: ResponseMetadata; } /** * 错误详情接口 */ export interface ErrorDetails { code: string; message: string; details?: JSONObject; suggestions?: string[]; documentation?: string; } /** * 响应元数据接口 */ export interface ResponseMetadata { timestamp: string; requestId: string; version: string; executionTime: number; source: string; } /** * 分页响应接口 */ export interface PaginatedResponse<T = JSONValue> extends UnifiedResponse<T[]> { pagination: { page: number; limit: number; total: number; totalPages: number; hasNext: boolean; hasPrev: boolean; }; } /** * 统一响应构建器 */ export declare class ResponseBuilder { private static requestCounter; private static readonly VERSION; /** * 创建成功响应 */ static success<T = JSONValue>(data: T, source: string, executionTime?: number): UnifiedResponse<T>; /** * 创建错误响应 */ static error(error: TaskFlowError | Error | string, source: string, executionTime?: number): UnifiedResponse<never>; /** * 创建分页响应 */ static paginated<T = JSONValue>(data: T[], page: number, limit: number, total: number, source: string, executionTime?: number): PaginatedResponse<T>; /** * 创建空响应 */ static empty(source: string, message?: string, executionTime?: number): UnifiedResponse<null>; /** * 创建响应元数据 */ private static createMetadata; /** * 创建错误详情 */ private static createErrorDetails; /** * 获取错误建议 */ private static getSuggestions; /** * 获取文档链接 */ private static getDocumentationLink; /** * 生成请求ID */ private static generateRequestId; } /** * 命令执行结果接口 */ export interface CommandResult<T = JSONValue> extends UnifiedResponse<T> { command: string; args: string[]; exitCode: number; } /** * 命令响应构建器 */ export declare class CommandResponseBuilder extends ResponseBuilder { /** * 创建命令成功响应 */ static commandSuccess<T = JSONValue>(command: string, args: string[], data: T, executionTime?: number): CommandResult<T>; /** * 创建命令错误响应 */ static commandError(command: string, args: string[], error: TaskFlowError | Error | string, exitCode?: number, executionTime?: number): CommandResult<never>; } /** * 响应验证器 */ export declare class ResponseValidator { /** * 验证响应格式 */ static validate(response: unknown): response is UnifiedResponse; /** * 验证分页响应格式 */ static validatePaginated(response: unknown): response is PaginatedResponse; } /** * 响应转换器 */ export declare class ResponseTransformer { /** * 转换为CLI友好格式 */ static toCLI(response: UnifiedResponse): string; /** * 转换为JSON格式 */ static toJSON(response: UnifiedResponse): string; /** * 转换为简化格式 */ static toSimple(response: UnifiedResponse): JSONObject; }