datasets.ts 7.5 KB

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