import {z} from 'zod' export type GetApiEkaMcpPharmacologyV1SearchArgs = {query?: string | undefined, category?: string | undefined, limit?: number | undefined, exact_match?: boolean | undefined, relevance_threshold?: number | undefined}; export type GetApiEkaMcpPharmacologyV1SearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const pharmacologyEntryA9993e3 = z.object({generic_name: z.string(), components: z.array(z.string()), is_compound: z.boolean(), page_number: z.number().int().optional(), reference_page_number: z.number().int().optional(), has_references: z.number().int().optional(), is_a_reference: z.boolean().optional(), pregnancy_category: z.string().optional(), indications: z.string().optional(), availability: z.string().optional(), dose: z.string().optional(), contraindications: z.string().optional(), precautions: z.string().optional(), precautions_appendix: z.string().optional(), adverse_effects: z.string().optional(), storage: z.string().optional(), schedule: z.string().optional(), note: z.string().optional(), additional_keys: z.string().optional(), generic_category: z.string().optional(), comments: z.string().optional()}); export const pharmacologySearchResponseA9993e3 = z.object({results: z.array(pharmacologyEntryA9993e3), search_info: z.record(z.string(), z.unknown()).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 Generic (pharmacology) Information * * GET /eka-mcp/pharmacology/v1/search */ export const getApiEkaMcpPharmacologyV1Search = async (args: GetApiEkaMcpPharmacologyV1SearchArgs, options?: GetApiEkaMcpPharmacologyV1SearchOptions) => { const {baseUrl = "https://api.eka.care", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.query != null) query.append("query", String(args.query)) if (args.category != null) query.append("category", String(args.category)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.exact_match != null) query.append("exact_match", String(args.exact_match)) if (args.relevance_threshold != null) query.append("relevance_threshold", String(args.relevance_threshold)) const url = `${baseUrl.replace(/\/+$/, '')}/eka-mcp/pharmacology/v1/search${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(pharmacologySearchResponseA9993e3, await res.json()) };