types.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. createdAt: string;
  48. updatedAt?: string;
  49. }
  50. export interface CreateGroupData {
  51. name: string;
  52. description?: string;
  53. color?: string;
  54. }
  55. export interface UpdateGroupData {
  56. name?: string;
  57. description?: string;
  58. color?: string;
  59. }
  60. export interface KnowledgeFile {
  61. id: string;
  62. name: string;
  63. originalName: string;
  64. size: number;
  65. type: string;
  66. status: 'pending' | 'indexing' | 'extracted' | 'vectorized' | 'failed' | 'ready' | 'error';
  67. groups?: KnowledgeGroup[];
  68. createdAt: string;
  69. updatedAt: string;
  70. }
  71. export interface SearchHistoryItem {
  72. id: string;
  73. title: string;
  74. selectedGroups: string[] | null;
  75. messageCount: number;
  76. lastMessageAt: string;
  77. createdAt: string;
  78. }
  79. export interface SearchHistoryDetail {
  80. id: string;
  81. title: string;
  82. selectedGroups: string[] | null;
  83. messages: Array<{
  84. id: string;
  85. role: 'user' | 'assistant';
  86. content: string;
  87. sources?: Array<{
  88. fileName: string;
  89. content: string;
  90. score: number;
  91. chunkIndex: number;
  92. }>;
  93. createdAt: string;
  94. }>;
  95. }
  96. export interface PDFStatus {
  97. status: 'pending' | 'converting' | 'ready' | 'failed';
  98. pdfPath?: string;
  99. error?: string;
  100. }
  101. export interface NoteCategory {
  102. id: string
  103. name: string
  104. parentId?: string
  105. level: number
  106. userId: string
  107. tenantId: string
  108. createdAt: string
  109. updatedAt: string
  110. }
  111. export interface Note {
  112. id: string;
  113. title: string;
  114. content: string;
  115. userId: string;
  116. tenantId?: string;
  117. groupId?: string;
  118. categoryId?: string;
  119. sharingStatus: 'PRIVATE' | 'TENANT' | 'GLOBAL_PENDING' | 'GLOBAL_APPROVED';
  120. createdAt: string;
  121. updatedAt: string;
  122. user?: {
  123. id: string;
  124. username: string;
  125. };
  126. }
  127. export interface RawFile {
  128. name: string;
  129. type: string;
  130. size: number;
  131. content: string;
  132. preview?: string;
  133. file: File; // Keep original file for upload
  134. isNote?: boolean;
  135. textContent?: string;
  136. }
  137. export enum Role {
  138. USER = 'user',
  139. MODEL = 'model',
  140. }
  141. export interface Message {
  142. id: string;
  143. role: Role;
  144. text: string;
  145. timestamp: number;
  146. isError?: boolean;
  147. sources?: ChatSource[];
  148. }
  149. export interface ChatSource {
  150. fileName: string;
  151. title?: string;
  152. content: string;
  153. score: number;
  154. chunkIndex: number;
  155. fileId?: string;
  156. }
  157. export interface ChatState {
  158. messages: Message[];
  159. isLoading: boolean;
  160. }
  161. export type Language = 'ja' | 'en' | 'zh';
  162. export enum ModelType {
  163. // Changed from type to enum
  164. LLM = "llm",
  165. EMBEDDING = "embedding",
  166. RERANK = "rerank",
  167. VISION = "vision",
  168. }
  169. // 1. Model Definition (The "Provider" setup)
  170. export interface ModelConfig {
  171. id: string;
  172. name: string; // Display name, e.g. "My DeepSeek"
  173. modelId: string; // The actual string ID sent to API, e.g., "gpt-4o"
  174. baseUrl?: string; // Base URL for OpenAI compatible API
  175. apiKey?: string; // API key for the service
  176. type: ModelType;
  177. dimensions?: number; // Vector dimensions of the embedding model
  178. supportsVision?: boolean; // Whether it supports vision capabilities
  179. // ==================== Additional Fields ====================
  180. /**
  181. * Model's input token limit
  182. * e.g., OpenAI=8191, Gemini=2048
  183. */
  184. maxInputTokens?: number;
  185. /**
  186. * Batch processing limit (maximum number of inputs per request)
  187. * e.g., OpenAI=2048, Gemini=100
  188. */
  189. maxBatchSize?: number;
  190. /**
  191. * Whether it is a vector model (for identification in system settings)
  192. */
  193. isVectorModel?: boolean;
  194. /**
  195. * Model provider name (for display)
  196. * e.g., "OpenAI", "Google Gemini", "Custom"
  197. */
  198. providerName?: string;
  199. /**
  200. * Whether it is enabled
  201. */
  202. isEnabled?: boolean;
  203. /**
  204. * Whether to use this model as the default
  205. */
  206. isDefault?: boolean;
  207. }
  208. // 2. Application Logic Settings (The "App" setup)
  209. export interface AppSettings {
  210. // References to ModelConfig IDs
  211. selectedLLMId: string;
  212. selectedEmbeddingId: string; // Default for new uploads, and used for query encoding
  213. selectedRerankId: string;
  214. // Model Hyperparameters
  215. temperature: number;
  216. maxTokens: number;
  217. // Retrieval
  218. enableRerank: boolean;
  219. topK: number;
  220. similarityThreshold: number; // Similarity threshold for vector search
  221. rerankSimilarityThreshold: number; // Similarity threshold for reranking
  222. enableFullTextSearch: boolean; // Whether to enable full-text search
  223. hybridVectorWeight: number; // Vector weight for hybrid search
  224. // Search Enhancement
  225. enableQueryExpansion: boolean;
  226. enableHyDE: boolean;
  227. chunkSize?: number;
  228. chunkOverlap?: number;
  229. // Language
  230. language?: string;
  231. // Coach
  232. coachKbId?: string;
  233. }
  234. // Default Models (Frontend specific)
  235. export const DEFAULT_MODELS: ModelConfig[] = [];
  236. export const DEFAULT_SETTINGS: AppSettings = {
  237. selectedLLMId: '',
  238. selectedEmbeddingId: '',
  239. selectedRerankId: '',
  240. temperature: 0.3,
  241. maxTokens: 8192,
  242. enableRerank: false,
  243. topK: 4,
  244. similarityThreshold: 0.3, // Default similarity threshold for vector search
  245. rerankSimilarityThreshold: 0.5, // Default similarity threshold for reranking
  246. enableFullTextSearch: false, // Turn off full-text search by default
  247. hybridVectorWeight: 0.7, // Vector weight for hybrid search
  248. enableQueryExpansion: false,
  249. enableHyDE: false,
  250. chunkSize: 1000,
  251. chunkOverlap: 100,
  252. language: 'ja',
  253. };
  254. export const API_BASE_URL = '/api'