importService.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { apiClient } from './apiClient';
  2. export interface ImportTask {
  3. id: string;
  4. sourcePath: string;
  5. targetGroupId?: string;
  6. targetGroupName?: string;
  7. scheduledAt?: string;
  8. status: 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED';
  9. logs?: string;
  10. embeddingModelId?: string;
  11. chunkSize?: number;
  12. chunkOverlap?: number;
  13. mode?: string;
  14. createdAt: string;
  15. }
  16. export const importService = {
  17. create: async (authToken: string, data: {
  18. sourcePath: string;
  19. targetGroupId?: string;
  20. targetGroupName?: string;
  21. embeddingModelId: string;
  22. scheduledAt?: string;
  23. chunkSize?: number;
  24. chunkOverlap?: number;
  25. mode?: string;
  26. }): Promise<ImportTask> => {
  27. const response = await apiClient.request('/import-tasks', {
  28. method: 'POST',
  29. body: JSON.stringify(data)
  30. });
  31. if (!response.ok) throw new Error('Failed to create import task');
  32. return response.json();
  33. },
  34. getAll: async (authToken: string, options: { page?: number; limit?: number } = {}): Promise<{ items: ImportTask[]; total: number; page: number; limit: number }> => {
  35. const queryParams = new URLSearchParams();
  36. if (options.page) queryParams.append('page', options.page.toString());
  37. if (options.limit) queryParams.append('limit', options.limit.toString());
  38. const queryString = queryParams.toString();
  39. const url = `/import-tasks${queryString ? `?${queryString}` : ''}`;
  40. const response = await apiClient.request(url, {});
  41. if (!response.ok) throw new Error('Failed to fetch import tasks');
  42. return response.json();
  43. },
  44. delete: async (authToken: string, id: string): Promise<void> => {
  45. const response = await apiClient.request(`/import-tasks/${id}`, {
  46. method: 'DELETE',
  47. });
  48. if (!response.ok) throw new Error('Failed to delete import task');
  49. }
  50. };