import {z} from 'zod' export type QueryProtocolsB6c8896Protocol = {query: string, tag: string, publisher: string}; export type QueryProtocolsB6c8896 = {queries: Array}; export type CreateApiEkaMcpProtocolsV1SearchArgs = {body: QueryProtocolsB6c8896}; export type CreateApiEkaMcpProtocolsV1SearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const protocolListA9993e3Protocol = z.object({url: z.string().optional(), source_url: z.string().optional(), type: z.enum(["image", "pdf"]).optional(), author: z.string().optional(), publication_year: z.number().int().optional(), conditions: z.array(z.string()).optional()}); export const protocolListA9993e3 = z.array(protocolListA9993e3Protocol); 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 }; /** * Search Protocols * * POST /eka-mcp/protocols/v1/search */ export const createApiEkaMcpProtocolsV1Search = async (args: CreateApiEkaMcpProtocolsV1SearchArgs, options?: CreateApiEkaMcpProtocolsV1SearchOptions) => { const {baseUrl = "https://api.eka.care", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/eka-mcp/protocols/v1/search${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 validateResponse(protocolListA9993e3, await res.json()) };