types.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. name?: string;
  130. };
  131. }
  132. export interface RawFile {
  133. name: string;
  134. type: string;
  135. size: number;
  136. content: string;
  137. preview?: string;
  138. file: File; // Keep original file for upload
  139. isNote?: boolean;
  140. textContent?: string;
  141. }
  142. export enum Role {
  143. USER = 'user',
  144. MODEL = 'model',
  145. }
  146. export interface Message {
  147. id: string;
  148. role: Role;
  149. text: string;
  150. timestamp: number;
  151. isError?: boolean;
  152. sources?: ChatSource[];
  153. }
  154. export interface ChatSource {
  155. fileName: string;
  156. title?: string;
  157. content: string;
  158. score: number;
  159. chunkIndex: number;
  160. fileId?: string;
  161. }
  162. export interface ChatState {
  163. messages: Message[];
  164. isLoading: boolean;
  165. }
  166. export type Language = 'ja' | 'en' | 'zh';
  167. export enum ModelType {
  168. // Changed from type to enum
  169. LLM = "llm",
  170. EMBEDDING = "embedding",
  171. RERANK = "rerank",
  172. VISION = "vision",
  173. }
  174. // 1. Model Definition (The "Provider" setup)
  175. export interface ModelConfig {
  176. id: string;
  177. name: string; // Display name, e.g. "My DeepSeek"
  178. modelId: string; // The actual string ID sent to API, e.g., "gpt-4o"
  179. baseUrl?: string; // Base URL for OpenAI compatible API
  180. apiKey?: string; // API key for the service
  181. type: ModelType;
  182. dimensions?: number; // Vector dimensions of the embedding model
  183. supportsVision?: boolean; // Whether it supports vision capabilities
  184. // ==================== Additional Fields ====================
  185. /**
  186. * Model's input token limit
  187. * e.g., OpenAI=8191, Gemini=2048
  188. */
  189. maxInputTokens?: number;
  190. /**
  191. * Batch processing limit (maximum number of inputs per request)
  192. * e.g., OpenAI=2048, Gemini=100
  193. */
  194. maxBatchSize?: number;
  195. /**
  196. * Whether it is a vector model (for identification in system settings)
  197. */
  198. isVectorModel?: boolean;
  199. /**
  200. * Model provider name (for display)
  201. * e.g., "OpenAI", "Google Gemini", "Custom"
  202. */
  203. providerName?: string;
  204. /**
  205. * Whether it is enabled
  206. */
  207. isEnabled?: boolean;
  208. /**
  209. * Whether to use this model as the default
  210. */
  211. isDefault?: boolean;
  212. }
  213. // 2. Application Logic Settings (The "App" setup)
  214. export interface AppSettings {
  215. // References to ModelConfig IDs
  216. selectedLLMId: string;
  217. selectedEmbeddingId: string; // Default for new uploads, and used for query encoding
  218. selectedRerankId: string;
  219. // Model Hyperparameters
  220. temperature: number;
  221. maxTokens: number;
  222. // Retrieval
  223. enableRerank: boolean;
  224. topK: number;
  225. similarityThreshold: number; // Similarity threshold for vector search
  226. rerankSimilarityThreshold: number; // Similarity threshold for reranking
  227. enableFullTextSearch: boolean; // Whether to enable full-text search
  228. hybridVectorWeight: number; // Vector weight for hybrid search
  229. // Search Enhancement
  230. enableQueryExpansion: boolean;
  231. enableHyDE: boolean;
  232. chunkSize?: number;
  233. chunkOverlap?: number;
  234. // Language
  235. language?: string;
  236. // Coach
  237. coachKbId?: string;
  238. // Vision
  239. selectedVisionId?: string;
  240. }
  241. // Default Models (Frontend specific)
  242. export const DEFAULT_MODELS: ModelConfig[] = [];
  243. export const DEFAULT_SETTINGS: AppSettings = {
  244. selectedLLMId: '',
  245. selectedEmbeddingId: '',
  246. selectedRerankId: '',
  247. temperature: 0.3,
  248. maxTokens: 8192,
  249. enableRerank: false,
  250. topK: 4,
  251. similarityThreshold: 0.3, // Default similarity threshold for vector search
  252. rerankSimilarityThreshold: 0.5, // Default similarity threshold for reranking
  253. enableFullTextSearch: false, // Turn off full-text search by default
  254. hybridVectorWeight: 0.7, // Vector weight for hybrid search
  255. enableQueryExpansion: false,
  256. enableHyDE: false,
  257. chunkSize: 1000,
  258. chunkOverlap: 100,
  259. language: 'ja',
  260. };
  261. export const API_BASE_URL = '/api'
  262. export interface Tenant {
  263. id: string;
  264. name: string;
  265. domain?: string;
  266. parentId?: string | null;
  267. children?: Tenant[];
  268. members?: TenantMember[];
  269. settings_obj?: any;
  270. createdAt: string;
  271. updatedAt: string;
  272. }
  273. export interface TenantMember {
  274. id: string;
  275. userId: string;
  276. tenantId: string;
  277. role: string;
  278. user?: {
  279. id: string;
  280. username: string;
  281. displayName?: string;
  282. email?: string;
  283. };
  284. createdAt: string;
  285. updatedAt: string;
  286. }