debugApi.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import type { DebugExecuteRequest } from '../types';
  2. const BASE_URL = '/debug/api';
  3. export interface PromptVersionInfo {
  4. name: string;
  5. version: string;
  6. time: string;
  7. chain: string;
  8. isCurrent: boolean;
  9. systemPrompt?: string;
  10. userPrompt?: string;
  11. }
  12. export async function executeReview(
  13. params: DebugExecuteRequest,
  14. signal?: AbortSignal,
  15. ): Promise<{ task_id: string }> {
  16. const res = await fetch(`${BASE_URL}/review/execute`, {
  17. method: 'POST',
  18. headers: { 'Content-Type': 'application/json' },
  19. body: JSON.stringify(params),
  20. signal,
  21. });
  22. if (!res.ok) {
  23. let message = `请求失败 (${res.status})`;
  24. try {
  25. const body = await res.json();
  26. message = body.message || body.detail || message;
  27. } catch {
  28. // ignore parse error
  29. }
  30. throw new Error(message);
  31. }
  32. return res.json();
  33. }
  34. export async function fetchPromptVersions(): Promise<PromptVersionInfo[]> {
  35. const res = await fetch(`${BASE_URL}/prompts`);
  36. if (!res.ok) throw new Error('获取提示词版本失败');
  37. const data = await res.json();
  38. return data.items ?? [];
  39. }