sample-center.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { get, post } from '@/request/index'
  2. import { type Ref } from 'vue'
  3. import type { Result } from '@/request/Result'
  4. export interface SampleCenterKB {
  5. id: string
  6. name: string
  7. parent_table: string
  8. child_table: string
  9. document_count: number
  10. status: number
  11. created_at: string
  12. created_by: string
  13. metadata_schema: Array<{
  14. field_name_cn: string
  15. field_name_en: string
  16. field_type: string
  17. description: string
  18. }>
  19. }
  20. export interface SampleCenterKBDetail extends SampleCenterKB {
  21. description: string
  22. updated_at: string
  23. }
  24. export interface ImportTask {
  25. task_id: string
  26. task_no: string
  27. status: 'pending' | 'processing' | 'completed' | 'failed'
  28. progress?: {
  29. total: number
  30. processed: number
  31. succeeded: number
  32. failed: number
  33. }
  34. created_at?: string
  35. completed_at?: string
  36. }
  37. export interface ParentItem {
  38. index: number
  39. parent_id: string
  40. hierarchy?: string
  41. text: string
  42. metadata?: Record<string, any>
  43. doc_id?: string
  44. tag_list?: string[]
  45. permission?: {
  46. visible_roles?: string[]
  47. visible_users?: string[]
  48. }
  49. }
  50. export interface ChildItem extends ParentItem {
  51. parent_id: string
  52. }
  53. export function getSampleCenterKBList(
  54. params: {
  55. base_url: string
  56. app_id: string
  57. app_secret: string
  58. page?: number
  59. page_size?: number
  60. },
  61. loading?: Ref<boolean>,
  62. ): Promise<Result<{ total: number; items: SampleCenterKB[] }>> {
  63. return get('workspace/sample-center/knowledge-bases', params, loading)
  64. }
  65. export function getSampleCenterKBDetail(
  66. params: {
  67. kb_id: string
  68. base_url: string
  69. app_id: string
  70. app_secret: string
  71. },
  72. loading?: Ref<boolean>,
  73. ): Promise<Result<SampleCenterKBDetail>> {
  74. return get('workspace/sample-center/knowledge-bases/detail', params, loading)
  75. }
  76. export function submitBatchImport(
  77. data: {
  78. kb_id: string
  79. base_url: string
  80. app_id: string
  81. app_secret: string
  82. parents: ParentItem[]
  83. children?: ChildItem[]
  84. callback_url?: string
  85. },
  86. loading?: Ref<boolean>,
  87. ): Promise<Result<ImportTask>> {
  88. return post('workspace/sample-center/knowledge-bases/batch-import', data, loading)
  89. }
  90. export function getImportTaskStatus(
  91. params: {
  92. task_id: string
  93. base_url: string
  94. app_id: string
  95. app_secret: string
  96. },
  97. loading?: Ref<boolean>,
  98. ): Promise<Result<ImportTask>> {
  99. return get('workspace/sample-center/batch-import/task', params, loading)
  100. }