import { ADMIN_BASE, request } from "./client"; import type { HeuristicProfile, LlmProfile, ParseChannel, ParseChannelCreate, ParseChannelUpdate, ParserProfile, ParserProfileCreate, ParserProfileUpdate, TargetField, } from "../types/admin"; export type { HeuristicProfile, LlmProfile, TargetField } from "../types/admin"; export function fetchChannels(): Promise { return request("/parse-channels", undefined, ADMIN_BASE); } export function createChannel(payload: ParseChannelCreate): Promise { return request( "/parse-channels", { method: "POST", body: JSON.stringify(payload) }, ADMIN_BASE, ); } export function updateChannel(id: number, payload: ParseChannelUpdate): Promise { return request( `/parse-channels/${id}`, { method: "PATCH", body: JSON.stringify(payload) }, ADMIN_BASE, ); } export function deleteChannel(id: number): Promise { return request(`/parse-channels/${id}`, { method: "DELETE" }, ADMIN_BASE); } export function fetchProfiles(): Promise { return request("/parser-profiles", undefined, ADMIN_BASE); } export function createProfile(payload: ParserProfileCreate): Promise { return request( "/parser-profiles", { method: "POST", body: JSON.stringify(payload) }, ADMIN_BASE, ); } export function updateProfile(id: number, payload: ParserProfileUpdate): Promise { return request( `/parser-profiles/${id}`, { method: "PATCH", body: JSON.stringify(payload) }, ADMIN_BASE, ); } export function deleteProfile(id: number): Promise { return request(`/parser-profiles/${id}`, { method: "DELETE" }, ADMIN_BASE); } export function fetchTargetFields(): Promise<{ fields: TargetField[] }> { return request<{ fields: TargetField[] }>("/parser-profiles/target-fields", undefined, ADMIN_BASE); } export function fetchLlmDefaults(): Promise { return request("/parser-profiles/llm-defaults", undefined, ADMIN_BASE); } export function generateParserProfile(payload: { sample_post: string; hint?: string; current_profile?: HeuristicProfile | Record | null; }): Promise<{ profile: HeuristicProfile; preview: Record; empty_fields: string[]; }> { return request<{ profile: HeuristicProfile; preview: Record; empty_fields: string[]; }>( "/parser-profiles/generate", { method: "POST", body: JSON.stringify({ sample_post: payload.sample_post, hint: payload.hint || undefined, current_profile: payload.current_profile || undefined, }), }, ADMIN_BASE, ); } export function previewParserProfile( sample_post: string, heuristic_profile: HeuristicProfile | Record, ): Promise<{ fields: Record; matched: boolean; missing_required: string[] }> { return request<{ fields: Record; matched: boolean; missing_required: string[] }>( "/parser-profiles/preview", { method: "POST", body: JSON.stringify({ sample_post, heuristic_profile }) }, ADMIN_BASE, ); } export function previewLlmProfile( sample_post: string, llm_profile: LlmProfile | Record, ): Promise<{ fields: Record; events: Record[]; matched: boolean; missing_required: string[]; is_event: boolean; matched_count: number; }> { return request<{ fields: Record; events: Record[]; matched: boolean; missing_required: string[]; is_event: boolean; matched_count: number; }>( "/parser-profiles/preview-llm", { method: "POST", body: JSON.stringify({ sample_post, llm_profile }) }, ADMIN_BASE, ); }