Support kind=llm profiles (instruction/schema), optional multi-event posts via #eN URLs, and recover stale running/queued parse jobs after worker crashes. Co-authored-by: Cursor <cursoragent@cursor.com>
134 lines
3.8 KiB
TypeScript
134 lines
3.8 KiB
TypeScript
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<ParseChannel[]> {
|
|
return request<ParseChannel[]>("/parse-channels", undefined, ADMIN_BASE);
|
|
}
|
|
|
|
export function createChannel(payload: ParseChannelCreate): Promise<ParseChannel> {
|
|
return request<ParseChannel>(
|
|
"/parse-channels",
|
|
{ method: "POST", body: JSON.stringify(payload) },
|
|
ADMIN_BASE,
|
|
);
|
|
}
|
|
|
|
export function updateChannel(id: number, payload: ParseChannelUpdate): Promise<ParseChannel> {
|
|
return request<ParseChannel>(
|
|
`/parse-channels/${id}`,
|
|
{ method: "PATCH", body: JSON.stringify(payload) },
|
|
ADMIN_BASE,
|
|
);
|
|
}
|
|
|
|
export function deleteChannel(id: number): Promise<void> {
|
|
return request<void>(`/parse-channels/${id}`, { method: "DELETE" }, ADMIN_BASE);
|
|
}
|
|
|
|
export function fetchProfiles(): Promise<ParserProfile[]> {
|
|
return request<ParserProfile[]>("/parser-profiles", undefined, ADMIN_BASE);
|
|
}
|
|
|
|
export function createProfile(payload: ParserProfileCreate): Promise<ParserProfile> {
|
|
return request<ParserProfile>(
|
|
"/parser-profiles",
|
|
{ method: "POST", body: JSON.stringify(payload) },
|
|
ADMIN_BASE,
|
|
);
|
|
}
|
|
|
|
export function updateProfile(id: number, payload: ParserProfileUpdate): Promise<ParserProfile> {
|
|
return request<ParserProfile>(
|
|
`/parser-profiles/${id}`,
|
|
{ method: "PATCH", body: JSON.stringify(payload) },
|
|
ADMIN_BASE,
|
|
);
|
|
}
|
|
|
|
export function deleteProfile(id: number): Promise<void> {
|
|
return request<void>(`/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<LlmProfile> {
|
|
return request<LlmProfile>("/parser-profiles/llm-defaults", undefined, ADMIN_BASE);
|
|
}
|
|
|
|
export function generateParserProfile(payload: {
|
|
sample_post: string;
|
|
hint?: string;
|
|
current_profile?: HeuristicProfile | Record<string, unknown> | null;
|
|
}): Promise<{
|
|
profile: HeuristicProfile;
|
|
preview: Record<string, string>;
|
|
empty_fields: string[];
|
|
}> {
|
|
return request<{
|
|
profile: HeuristicProfile;
|
|
preview: Record<string, string>;
|
|
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<string, unknown>,
|
|
): Promise<{ fields: Record<string, string>; matched: boolean; missing_required: string[] }> {
|
|
return request<{ fields: Record<string, string>; 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<string, unknown>,
|
|
): Promise<{
|
|
fields: Record<string, string>;
|
|
events: Record<string, string>[];
|
|
matched: boolean;
|
|
missing_required: string[];
|
|
is_event: boolean;
|
|
matched_count: number;
|
|
}> {
|
|
return request<{
|
|
fields: Record<string, string>;
|
|
events: Record<string, string>[];
|
|
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,
|
|
);
|
|
}
|