export type CreateApiExplorerAnswerArgs = {body: {question?: string | undefined, format?: ('json' | 'sqlite') | undefined, ignoreCache?: boolean | undefined}}; export type CreateApiExplorerAnswerOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Get answer of a new question * * POST /explorer/answer/ */ export const createApiExplorerAnswer = async (args: CreateApiExplorerAnswerArgs, options: CreateApiExplorerAnswerOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/explorer/answer/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };