import {z} from 'zod' export type GetApiV1AccountsAccountIdEvaluationsArgs = {pageSize?: number | undefined, pageToken?: string | undefined, filter?: string | undefined, orderBy?: string | undefined, readMask?: string | undefined, account_id: string}; export type GetApiV1AccountsAccountIdEvaluationsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gatewayCode = z.enum(["OK", "CANCELLED", "UNKNOWN", "INVALID_ARGUMENT", "DEADLINE_EXCEEDED", "NOT_FOUND", "ALREADY_EXISTS", "PERMISSION_DENIED", "UNAUTHENTICATED", "RESOURCE_EXHAUSTED", "FAILED_PRECONDITION", "ABORTED", "OUT_OF_RANGE", "UNIMPLEMENTED", "INTERNAL", "UNAVAILABLE", "DATA_LOSS"]); export const gatewayStatus = z.object({code: gatewayCode.optional(), message: z.string().optional()}); export const gatewayProvider = z.object({id: z.string().optional(), config: z.record(z.string(), z.string()).optional(), label: z.string().optional()}); export const assertionAssertionType = z.enum(["ASSERTION_TYPE_UNSPECIFIED", "ASSERTION_TYPE_LLM", "ASSERTION_TYPE_CODE"]); export const gatewayEvaluateOptions = z.object({maxConcurrency: z.number().int().optional(), repeat: z.number().int().optional(), delay: z.number().int().optional()}); export const gatewayLLMAssertion = z.object({llmEvaluatorPrompt: z.string().optional(), providers: z.array(gatewayProvider), prompts: z.array(z.string()), evaluateOptions: gatewayEvaluateOptions.optional()}); export const codeAssertionExecutionOptions = z.object({timeoutMs: z.number().int().optional(), memoryLimitMb: z.number().int().optional(), envVars: z.record(z.string(), z.string()).optional()}); export const gatewayCodeAssertion = z.object({language: z.string(), code: z.string(), expectedOutput: z.string().optional(), options: codeAssertionExecutionOptions.optional()}); export const gatewayAssertion = z.object({assertionType: assertionAssertionType, llmAssertion: gatewayLLMAssertion.optional(), codeAssertion: gatewayCodeAssertion.optional(), metricName: z.string().optional()}); export const gatewayEvaluation = z.object({name: z.string().optional(), createTime: z.string().optional(), createdBy: z.string().optional(), status: gatewayStatus.optional(), evaluationType: z.string(), description: z.string().optional(), providers: z.array(gatewayProvider), assertions: z.array(gatewayAssertion), updateTime: z.string().optional()}); export const gatewayListEvaluationsResponse = z.object({evaluations: z.array(gatewayEvaluation).optional(), nextPageToken: z.string().optional(), totalSize: z.number().int().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 }; /** * List Evaluations * * GET /v1/accounts/{account_id}/evaluations */ export const getApiV1AccountsAccountIdEvaluations = async (args: GetApiV1AccountsAccountIdEvaluationsArgs, options: GetApiV1AccountsAccountIdEvaluationsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.readMask != null) query.append("readMask", String(args.readMask)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/evaluations${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(gatewayListEvaluationsResponse, await res.json()) };