types.ts 6.5 KB

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