datasets.ts 6.6 KB

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