types.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. 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. parentId?: string | null;
  47. children?: KnowledgeGroup[];
  48. createdAt: string;
  49. updatedAt?: string;
  50. }
  51. export interface CreateGroupData {
  52. name: string;
  53. description?: string;
  54. color?: string;
  55. parentId?: string | null;
  56. }
  57. export interface UpdateGroupData {
  58. name?: string;
  59. description?: string;
  60. color?: string;
  61. parentId?: string | null;
  62. }
  63. export interface KnowledgeFile {
  64. id: string;
  65. name: string;
  66. originalName: string;
  67. size: number;
  68. type: string;
  69. status: 'pending' | 'indexing' | 'extracted' | 'vectorized' | 'failed' | 'ready' | 'error';
  70. groups?: KnowledgeGroup[];
  71. createdAt: string;
  72. updatedAt: string;
  73. }
  74. export interface SearchHistoryItem {
  75. id: string;
  76. title: string;
  77. selectedGroups: string[] | null;
  78. messageCount: number;
  79. lastMessageAt: string;
  80. createdAt: string;
  81. }
  82. export interface SearchHistoryDetail {
  83. id: string;
  84. title: string;
  85. selectedGroups: string[] | null;
  86. messages: Array<{
  87. id: string;
  88. role: 'user' | 'assistant';
  89. content: string;
  90. sources?: Array<{
  91. fileName: string;
  92. content: string;
  93. score: number;
  94. chunkIndex: number;
  95. }>;
  96. createdAt: string;
  97. }>;
  98. }
  99. export interface PDFStatus {
  100. status: 'pending' | 'converting' | 'ready' | 'failed';
  101. pdfPath?: string;
  102. error?: string;
  103. }
  104. export interface NoteCategory {
  105. id: string
  106. name: string
  107. parentId?: string
  108. level: number
  109. userId: string
  110. tenantId: string
  111. createdAt: string
  112. updatedAt: string
  113. }
  114. export interface Note {
  115. id: string;
  116. title: string;
  117. content: string;
  118. userId: string;
  119. tenantId?: string;
  120. groupId?: string;
  121. categoryId?: string;
  122. sharingStatus: 'PRIVATE' | 'TENANT' | 'GLOBAL_PENDING' | 'GLOBAL_APPROVED';
  123. createdAt: string;
  124. updatedAt: string;
  125. user?: {
  126. id: string;
  127. username: string;
  128. name?: 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. // Vision
  238. selectedVisionId?: string;
  239. }
  240. // Default Models (Frontend specific)
  241. export const DEFAULT_MODELS: ModelConfig[] = [];
  242. export const DEFAULT_SETTINGS: AppSettings = {
  243. selectedLLMId: '',
  244. selectedEmbeddingId: '',
  245. selectedRerankId: '',
  246. selectedVisionId: '',
  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. }
  287. // Assessment Template Types
  288. export interface AssessmentTemplate {
  289. id: string;
  290. name: string;
  291. description?: string;
  292. keywords?: string[];
  293. questionCount: number;
  294. difficultyDistribution?: Record<string, number>;
  295. style?: string;
  296. knowledgeBaseId?: string;
  297. knowledgeGroupId?: string;
  298. knowledgeGroup?: KnowledgeGroup;
  299. isActive: boolean;
  300. version: number;
  301. creatorId: string;
  302. createdAt: string;
  303. updatedAt: string;
  304. }
  305. export interface CreateTemplateData {
  306. name: string;
  307. description?: string;
  308. keywords?: string[];
  309. questionCount?: number;
  310. difficultyDistribution?: Record<string, number>;
  311. style?: string;
  312. knowledgeBaseId?: string;
  313. knowledgeGroupId?: string;
  314. }
  315. export interface UpdateTemplateData extends Partial<CreateTemplateData> {
  316. isActive?: boolean;
  317. }