types.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. export interface IndexingConfig {
  2. chunkSize: number;
  3. chunkOverlap: number;
  4. embeddingModelId: string;
  5. mode?: 'fast' | 'precise'; // Processing mode: fast/precise
  6. groupIds?: string[]; // Groups to associate with the file upon upload
  7. }
  8. // Vision Pipeline 相关类型
  9. export interface VisionAnalysisResult {
  10. text: string; // Extracted text content
  11. images: ImageDescription[]; // Image descriptions
  12. layout: string; // Layout type
  13. confidence: number; // 信頼度 (0-1)
  14. pageIndex?: number; // Page number
  15. }
  16. export interface ImageDescription {
  17. type: string; // Image type (graph/diagram/flowchart etc.)
  18. description: string; // Detailed description
  19. position?: number; // Position within the page
  20. }
  21. export interface PipelineResult {
  22. success: boolean;
  23. fileId: string;
  24. fileName: string;
  25. totalPages: number;
  26. processedPages: number;
  27. failedPages: number;
  28. results: VisionAnalysisResult[];
  29. cost: number; // Cost (USD)
  30. duration: number; // Duration (seconds)
  31. mode: 'precise';
  32. }
  33. export interface ModeRecommendation {
  34. recommendedMode: 'precise' | 'fast';
  35. reason: string;
  36. estimatedCost?: number; // Estimated cost (USD)
  37. estimatedTime?: number; // Estimated time (seconds)
  38. warnings?: string[];
  39. }
  40. // Type definitions for knowledge base extensions
  41. export interface KnowledgeGroup {
  42. id: string;
  43. name: string;
  44. description?: string;
  45. color: string;
  46. fileCount: number;
  47. parentId?: string | null;
  48. children?: KnowledgeGroup[];
  49. createdAt: string;
  50. updatedAt?: string;
  51. }
  52. export interface CreateGroupData {
  53. name: string;
  54. description?: string;
  55. color?: string;
  56. parentId?: string | null;
  57. }
  58. export interface UpdateGroupData {
  59. name?: string;
  60. description?: string;
  61. color?: string;
  62. parentId?: string | null;
  63. }
  64. export interface KnowledgeFile {
  65. id: string;
  66. name: string;
  67. originalName: string;
  68. size: number;
  69. type: string;
  70. status: 'pending' | 'indexing' | 'extracted' | 'vectorized' | 'failed' | 'ready' | 'error';
  71. groups?: KnowledgeGroup[];
  72. createdAt: string;
  73. updatedAt: string;
  74. }
  75. export interface SearchHistoryItem {
  76. id: string;
  77. title: string;
  78. selectedGroups: string[] | null;
  79. messageCount: number;
  80. lastMessageAt: string;
  81. createdAt: string;
  82. }
  83. export interface SearchHistoryDetail {
  84. id: string;
  85. title: string;
  86. selectedGroups: string[] | null;
  87. messages: Array<{
  88. id: string;
  89. role: 'user' | 'assistant';
  90. content: string;
  91. sources?: Array<{
  92. fileName: string;
  93. content: string;
  94. score: number;
  95. chunkIndex: number;
  96. }>;
  97. createdAt: string;
  98. }>;
  99. }
  100. export interface PDFStatus {
  101. status: 'pending' | 'converting' | 'ready' | 'failed';
  102. pdfPath?: string;
  103. error?: string;
  104. }
  105. export interface NoteCategory {
  106. id: string
  107. name: string
  108. parentId?: string
  109. level: number
  110. userId: string
  111. tenantId: string
  112. createdAt: string
  113. updatedAt: string
  114. }
  115. export interface Note {
  116. id: string;
  117. title: string;
  118. content: string;
  119. userId: string;
  120. tenantId?: string;
  121. groupId?: string;
  122. categoryId?: string;
  123. sharingStatus: 'PRIVATE' | 'TENANT' | 'GLOBAL_PENDING' | 'GLOBAL_APPROVED';
  124. createdAt: string;
  125. updatedAt: string;
  126. user?: {
  127. id: string;
  128. username: string;
  129. };
  130. }
  131. export interface RawFile {
  132. name: string;
  133. type: string;
  134. size: number;
  135. content: string;
  136. preview?: string;
  137. file: File; // Keep original file for upload
  138. isNote?: boolean;
  139. textContent?: string;
  140. }
  141. export enum Role {
  142. USER = 'user',
  143. MODEL = 'model',
  144. }
  145. export interface Message {
  146. id: string;
  147. role: Role;
  148. text: string;
  149. timestamp: number;
  150. isError?: boolean;
  151. sources?: ChatSource[];
  152. }
  153. export interface ChatSource {
  154. fileName: string;
  155. title?: string;
  156. content: string;
  157. score: number;
  158. chunkIndex: number;
  159. fileId?: string;
  160. }
  161. export interface ChatState {
  162. messages: Message[];
  163. isLoading: boolean;
  164. }
  165. export type Language = 'ja' | 'en' | 'zh';
  166. export enum ModelType {
  167. // Changed from type to enum
  168. LLM = "llm",
  169. EMBEDDING = "embedding",
  170. RERANK = "rerank",
  171. VISION = "vision",
  172. }
  173. // 1. Model Definition (The "Provider" setup)
  174. export interface ModelConfig {
  175. id: string;
  176. name: string; // Display name, e.g. "My DeepSeek"
  177. modelId: string; // The actual string ID sent to API, e.g., "gpt-4o"
  178. baseUrl?: string; // Base URL for OpenAI compatible API
  179. apiKey?: string; // API key for the service
  180. type: ModelType;
  181. dimensions?: number; // Vector dimensions of the embedding model
  182. supportsVision?: boolean; // Whether it supports vision capabilities
  183. // ==================== Additional Fields ====================
  184. /**
  185. * Model's input token limit
  186. * e.g., OpenAI=8191, Gemini=2048
  187. */
  188. maxInputTokens?: number;
  189. /**
  190. * Batch processing limit (maximum number of inputs per request)
  191. * e.g., OpenAI=2048, Gemini=100
  192. */
  193. maxBatchSize?: number;
  194. /**
  195. * Whether it is a vector model (for identification in system settings)
  196. */
  197. isVectorModel?: boolean;
  198. /**
  199. * Model provider name (for display)
  200. * e.g., "OpenAI", "Google Gemini", "Custom"
  201. */
  202. providerName?: string;
  203. /**
  204. * Whether it is enabled
  205. */
  206. isEnabled?: boolean;
  207. /**
  208. * Whether to use this model as the default
  209. */
  210. isDefault?: boolean;
  211. }
  212. // 2. Application Logic Settings (The "App" setup)
  213. export interface AppSettings {
  214. // References to ModelConfig IDs
  215. selectedLLMId: string;
  216. selectedEmbeddingId: string; // Default for new uploads, and used for query encoding
  217. selectedRerankId: string;
  218. // Model Hyperparameters
  219. temperature: number;
  220. maxTokens: number;
  221. // Retrieval
  222. enableRerank: boolean;
  223. topK: number;
  224. similarityThreshold: number; // Similarity threshold for vector search
  225. rerankSimilarityThreshold: number; // Similarity threshold for reranking
  226. enableFullTextSearch: boolean; // Whether to enable full-text search
  227. hybridVectorWeight: number; // Vector weight for hybrid search
  228. // Search Enhancement
  229. enableQueryExpansion: boolean;
  230. enableHyDE: boolean;
  231. chunkSize?: number;
  232. chunkOverlap?: number;
  233. // Language
  234. language?: string;
  235. // Coach
  236. coachKbId?: string;
  237. }
  238. // Default Models (Frontend specific)
  239. export const DEFAULT_MODELS: ModelConfig[] = [];
  240. export const DEFAULT_SETTINGS: AppSettings = {
  241. selectedLLMId: '',
  242. selectedEmbeddingId: '',
  243. selectedRerankId: '',
  244. temperature: 0.3,
  245. maxTokens: 8192,
  246. enableRerank: false,
  247. topK: 4,
  248. similarityThreshold: 0.3, // Default similarity threshold for vector search
  249. rerankSimilarityThreshold: 0.5, // Default similarity threshold for reranking
  250. enableFullTextSearch: false, // Turn off full-text search by default
  251. hybridVectorWeight: 0.7, // Vector weight for hybrid search
  252. enableQueryExpansion: false,
  253. enableHyDE: false,
  254. chunkSize: 1000,
  255. chunkOverlap: 100,
  256. language: 'ja',
  257. };
  258. export const API_BASE_URL = '/api'