import {z} from 'zod' export type GetApiApiV1ContactsContactIdFactsFactIdArgs = {contact_id: string, fact_id: string}; export type GetApiApiV1ContactsContactIdFactsFactIdOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const contactFactCitationResponse = z.object({source_type: z.string(), availability: z.enum(["available", "purged", "source_unavailable_to_caller"]), source_id: z.string().nullable().optional(), source_url: z.string().nullable().optional(), source_locator: z.record(z.string(), z.unknown()).nullable().optional()}); export const contactFactResponse = z.object({id: z.string(), contact_id: z.string(), content: z.string(), confidence: z.string().nullable(), origin: z.enum(["generated", "user"]), kind: z.enum(["profile", "preference", "context"]).nullable().optional(), expires_at: z.string().nullable().optional(), locked_at: z.string().nullable(), created_at: z.string(), updated_at: z.string(), citations: z.array(contactFactCitationResponse).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 Contact Fact * * GET /api/v1/contacts/{contact_id}/facts/{fact_id} * * Also accepts auth: BearerAuth */ export const getApiApiV1ContactsContactIdFactsFactId = async (args: GetApiApiV1ContactsContactIdFactsFactIdArgs, options: GetApiApiV1ContactsContactIdFactsFactIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/contacts/${encodeURIComponent(String(args.contact_id))}/facts/${encodeURIComponent(String(args.fact_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(contactFactResponse, await res.json()) };