import {z} from 'zod' export type GetApiApiPublicV2RequestsSuggestionsArgs = {field: 'engine' | 'provider_type' | 'prompt_id' | 'prompt' | 'tags' | 'metadata_keys' | 'status' | 'tool_names' | 'output_keys' | 'input_variable_keys' | 'metadata_values' | 'output_values' | 'input_variable_values', prefix?: string | undefined, metadata_key?: string | undefined, prompt_id?: number | undefined, filter_group?: string | undefined}; export type GetApiApiPublicV2RequestsSuggestionsOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const searchRequestSuggestionsResponse = z.object({success: z.literal(true), values: z.array(z.string())}); 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 Request Suggestions * * GET /api/public/v2/requests/suggestions */ export const getApiApiPublicV2RequestsSuggestions = async (args: GetApiApiPublicV2RequestsSuggestionsArgs, options: GetApiApiPublicV2RequestsSuggestionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.field != null) query.append("field", String(args.field)) if (args.prefix != null) query.append("prefix", String(args.prefix)) if (args.metadata_key != null) query.append("metadata_key", String(args.metadata_key)) if (args.prompt_id != null) query.append("prompt_id", String(args.prompt_id)) if (args.filter_group != null) query.append("filter_group", String(args.filter_group)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v2/requests/suggestions${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(searchRequestSuggestionsResponse, await res.json()) };