datasets.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. import type { AppMode } from './app'
  2. import type { DataSourceNotionPage } from './common'
  3. export enum DataSourceType {
  4. FILE = 'upload_file',
  5. NOTION = 'notion_import',
  6. WEB = 'web_import',
  7. }
  8. export type DataSet = {
  9. id: string
  10. name: string
  11. icon: string
  12. icon_background: string
  13. description: string
  14. permission: 'only_me' | 'all_team_members'
  15. data_source_type: DataSourceType
  16. indexing_technique: 'high_quality' | 'economy'
  17. created_by: string
  18. updated_by: string
  19. updated_at: number
  20. app_count: number
  21. document_count: number
  22. word_count: number
  23. }
  24. export type CustomFile = File & {
  25. id?: string
  26. extension?: string
  27. mime_type?: string
  28. created_by?: string
  29. created_at?: number
  30. }
  31. export type FileItem = {
  32. fileID: string
  33. file: CustomFile
  34. progress: number
  35. }
  36. export type DataSetListResponse = {
  37. data: DataSet[]
  38. has_more: boolean
  39. limit: number
  40. page: number
  41. total: number
  42. }
  43. export type QA = {
  44. question: string
  45. answer: string
  46. }
  47. export type IndexingEstimateResponse = {
  48. tokens: number
  49. total_price: number
  50. currency: string
  51. total_segments: number
  52. preview: string[]
  53. qa_preview?: QA[]
  54. }
  55. export type FileIndexingEstimateResponse = {
  56. total_nodes: number
  57. } & IndexingEstimateResponse
  58. export type IndexingStatusResponse = {
  59. id: string
  60. indexing_status: DocumentIndexingStatus
  61. processing_started_at: number
  62. parsing_completed_at: number
  63. cleaning_completed_at: number
  64. splitting_completed_at: number
  65. completed_at: any
  66. paused_at: any
  67. error: any
  68. stopped_at: any
  69. completed_segments: number
  70. total_segments: number
  71. }
  72. export type IndexingStatusBatchResponse = {
  73. data: IndexingStatusResponse[]
  74. }
  75. export type ProcessMode = 'automatic' | 'custom'
  76. export type ProcessRuleResponse = {
  77. mode: ProcessMode
  78. rules: Rules
  79. }
  80. export type Rules = {
  81. pre_processing_rules: PreProcessingRule[]
  82. segmentation: Segmentation
  83. }
  84. export type PreProcessingRule = {
  85. id: string
  86. enabled: boolean
  87. }
  88. export type Segmentation = {
  89. separator: string
  90. max_tokens: number
  91. }
  92. export const DocumentIndexingStatusList = [
  93. 'waiting',
  94. 'parsing',
  95. 'cleaning',
  96. 'splitting',
  97. 'indexing',
  98. 'paused',
  99. 'error',
  100. 'completed',
  101. ] as const
  102. export type DocumentIndexingStatus = typeof DocumentIndexingStatusList[number]
  103. export const DisplayStatusList = [
  104. 'queuing',
  105. 'indexing',
  106. 'paused',
  107. 'error',
  108. 'available',
  109. 'enabled',
  110. 'disabled',
  111. 'archived',
  112. ] as const
  113. export type DocumentDisplayStatus = typeof DisplayStatusList[number]
  114. export type DataSourceInfo = {
  115. upload_file: {
  116. id: string
  117. name: string
  118. size: number
  119. mime_type: string
  120. created_at: number
  121. created_by: string
  122. extension: string
  123. }
  124. notion_page_icon?: string
  125. }
  126. export type InitialDocumentDetail = {
  127. id: string
  128. batch: string
  129. position: number
  130. dataset_id: string
  131. data_source_type: DataSourceType
  132. data_source_info: DataSourceInfo
  133. dataset_process_rule_id: string
  134. name: string
  135. created_from: 'api' | 'web'
  136. created_by: string
  137. created_at: number
  138. indexing_status: DocumentIndexingStatus
  139. display_status: DocumentDisplayStatus
  140. completed_segments?: number
  141. total_segments?: number
  142. doc_form: 'text_model' | 'qa_model'
  143. }
  144. export type SimpleDocumentDetail = InitialDocumentDetail & {
  145. enabled: boolean
  146. word_count: number
  147. error?: string | null
  148. archived: boolean
  149. updated_at: number
  150. hit_count: number
  151. dataset_process_rule_id?: string
  152. }
  153. export type DocumentListResponse = {
  154. data: SimpleDocumentDetail[]
  155. has_more: boolean
  156. total: number
  157. page: number
  158. limit: number
  159. }
  160. export type CreateDocumentReq = {
  161. original_document_id?: string
  162. indexing_technique?: string
  163. doc_form: 'text_model' | 'qa_model'
  164. data_source: DataSource
  165. process_rule: ProcessRule
  166. }
  167. export type DataSource = {
  168. type: DataSourceType
  169. info_list: {
  170. data_source_type: DataSourceType
  171. notion_info_list?: NotionInfo[]
  172. file_info_list?: {
  173. file_ids: string[]
  174. }
  175. }
  176. }
  177. export type NotionInfo = {
  178. workspace_id: string
  179. pages: DataSourceNotionPage[]
  180. }
  181. export type NotionPage = {
  182. page_id: string
  183. type: string
  184. }
  185. export type ProcessRule = {
  186. mode: string
  187. rules: Rules
  188. }
  189. export type createDocumentResponse = {
  190. dataset?: DataSet
  191. batch: string
  192. documents: InitialDocumentDetail[]
  193. }
  194. export type FullDocumentDetail = SimpleDocumentDetail & {
  195. batch: string
  196. created_api_request_id: string
  197. processing_started_at: number
  198. parsing_completed_at: number
  199. cleaning_completed_at: number
  200. splitting_completed_at: number
  201. tokens: number
  202. indexing_latency: number
  203. completed_at: number
  204. paused_by: string
  205. paused_at: number
  206. stopped_at: number
  207. indexing_status: string
  208. disabled_at: number
  209. disabled_by: string
  210. archived_reason: 'rule_modified' | 're_upload'
  211. archived_by: string
  212. archived_at: number
  213. doc_type?: DocType | null
  214. doc_metadata?: DocMetadata | null
  215. segment_count: number
  216. [key: string]: any
  217. }
  218. export type DocMetadata = {
  219. title: string
  220. language: string
  221. author: string
  222. publisher: string
  223. publicationDate: string
  224. ISBN: string
  225. category: string
  226. [key: string]: string
  227. }
  228. export const CUSTOMIZABLE_DOC_TYPES = [
  229. 'book',
  230. 'web_page',
  231. 'paper',
  232. 'social_media_post',
  233. 'personal_document',
  234. 'business_document',
  235. 'im_chat_log',
  236. ] as const
  237. export const FIXED_DOC_TYPES = ['synced_from_github', 'synced_from_notion', 'wikipedia_entry'] as const
  238. export type CustomizableDocType = typeof CUSTOMIZABLE_DOC_TYPES[number]
  239. export type FixedDocType = typeof FIXED_DOC_TYPES[number]
  240. export type DocType = CustomizableDocType | FixedDocType
  241. export type DocumentDetailResponse = FullDocumentDetail
  242. export const SEGMENT_STATUS_LIST = ['waiting', 'completed', 'error', 'indexing']
  243. export type SegmentStatus = typeof SEGMENT_STATUS_LIST[number]
  244. export type SegmentsQuery = {
  245. last_id?: string
  246. limit: number
  247. // status?: SegmentStatus
  248. hit_count_gte?: number
  249. keyword?: string
  250. enabled?: boolean
  251. }
  252. export type SegmentDetailModel = {
  253. id: string
  254. position: number
  255. document_id: string
  256. content: string
  257. word_count: number
  258. tokens: number
  259. keywords: string[]
  260. index_node_id: string
  261. index_node_hash: string
  262. hit_count: number
  263. enabled: boolean
  264. disabled_at: number
  265. disabled_by: string
  266. status: SegmentStatus
  267. created_by: string
  268. created_at: number
  269. indexing_at: number
  270. completed_at: number
  271. error: string | null
  272. stopped_at: number
  273. answer?: string
  274. }
  275. export type SegmentsResponse = {
  276. data: SegmentDetailModel[]
  277. has_more: boolean
  278. limit: number
  279. total: number
  280. }
  281. export type HitTestingRecord = {
  282. id: string
  283. content: string
  284. source: 'app' | 'hit_testing' | 'plugin'
  285. source_app_id: string
  286. created_by_role: 'account' | 'end_user'
  287. created_by: string
  288. created_at: number
  289. }
  290. export type HitTesting = {
  291. segment: Segment
  292. score: number
  293. tsne_position: TsnePosition
  294. }
  295. export type Segment = {
  296. id: string
  297. document: Document
  298. content: string
  299. position: number
  300. word_count: number
  301. tokens: number
  302. keywords: string[]
  303. hit_count: number
  304. index_node_hash: string
  305. }
  306. export type Document = {
  307. id: string
  308. data_source_type: string
  309. name: string
  310. doc_type: DocType
  311. }
  312. export type HitTestingRecordsResponse = {
  313. data: HitTestingRecord[]
  314. has_more: boolean
  315. limit: number
  316. total: number
  317. page: number
  318. }
  319. export type TsnePosition = {
  320. x: number
  321. y: number
  322. }
  323. export type HitTestingResponse = {
  324. query: {
  325. content: string
  326. tsne_position: TsnePosition
  327. }
  328. records: Array<HitTesting>
  329. }
  330. export type RelatedApp = {
  331. id: string
  332. name: string
  333. mode: AppMode
  334. icon: string
  335. icon_background: string
  336. }
  337. export type RelatedAppResponse = {
  338. data: Array<RelatedApp>
  339. total: number
  340. }
  341. export type SegmentUpdator = {
  342. content: string
  343. answer?: string
  344. }