import {z} from 'zod' export type GetApiV1ResearchResearchIdArgs = {research_id: string}; export type GetApiV1ResearchResearchIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const currentLocationV1 = z.object({location: z.string(), comments: z.string().nullable().optional(), urls: z.array(z.string()).nullable().optional()}); export const personMetadataV1 = z.object({full_name: z.string().nullable().optional(), alternate_names: z.array(z.string()).nullable().optional(), profile_urls: z.array(z.string()).nullable().optional(), current_locations: z.array(currentLocationV1).nullable().optional(), tagline: z.string().nullable().optional()}); export const employmentV1 = z.object({company_name: z.string().nullable().optional(), job_title: z.string().nullable().optional(), start_date: z.string().nullable().optional(), end_date: z.string().nullable().optional(), description: z.string().nullable().optional(), urls: z.array(z.string()).nullable().optional()}); export const educationV1 = z.object({university_name: z.string().nullable().optional(), degree: z.string().nullable().optional(), start_date: z.string().nullable().optional(), end_date: z.string().nullable().optional(), description: z.string().nullable().optional(), urls: z.array(z.string()).nullable().optional()}); export const projectV1 = z.object({title: z.string().nullable().optional(), description: z.string().nullable().optional(), start_date: z.string().nullable().optional(), end_date: z.string().nullable().optional(), urls: z.array(z.string()).nullable().optional()}); export const writingV1 = z.object({title: z.string().nullable().optional(), description: z.string().nullable().optional(), date: z.string().nullable().optional(), urls: z.array(z.string()).nullable().optional()}); export const hobbyV1 = z.object({description: z.string().nullable().optional(), urls: z.array(z.string()).nullable().optional()}); export const summaryV1 = z.object({text: z.string(), urls: z.array(z.string()).nullable().optional()}); export const profileV1 = z.object({person_metadata: personMetadataV1.nullable().optional(), employment: z.array(employmentV1).nullable().optional(), education: z.array(educationV1).nullable().optional(), projects: z.array(projectV1).nullable().optional(), writings: z.array(writingV1).nullable().optional(), hobbies: z.array(hobbyV1).nullable().optional(), summary: summaryV1.nullable().optional()}); export const getResearchResponseV1 = z.object({id: z.string(), status: z.string(), query: z.string(), created_at: z.string(), updated_at: z.string(), profile: profileV1.nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Research * * GET /v1/research/{research_id} */ export const getApiV1ResearchResearchId = async (args: GetApiV1ResearchResearchIdArgs, options: GetApiV1ResearchResearchIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/research/${encodeURIComponent(String(args.research_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getResearchResponseV1, await res.json()) };