返回 JoyAI-Echo
pe-api.ts
1 import { ApiError } from "./api";
2
3 export interface PeSet {
4 name: string;
5 label: string;
6 description: string;
7 }
8
9 export interface PeListResponse {
10 ok: boolean;
11 sets: PeSet[];
12 active: string;
13 enabled: boolean;
14 }
15
16 /** Fetch the available Prompt Engineering sets and the currently active one. */
17 export async function listPeSets(
18 token: string,
19 base: string = "",
20 ): Promise<PeListResponse> {
21 const res = await fetch(`${base}/api/pe-sets`, {
22 headers: { Authorization: `Bearer ${token}` },
23 credentials: "same-origin",
24 });
25 if (!res.ok) {
26 const detail = (await res.text()).trim();
27 throw new ApiError(res.status, detail || `HTTP ${res.status}`);
28 }
29 return (await res.json()) as PeListResponse;
30 }
31
31 lines TYPESCRIPT