import {z} from 'zod' export type GetApiV1AccountsAccountIdEvaluatorsArgs = {pageSize?: number | undefined, pageToken?: string | undefined, filter?: string | undefined, orderBy?: string | undefined, readMask?: string | undefined, account_id: string}; export type GetApiV1AccountsAccountIdEvaluatorsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gatewayEvaluatorState = z.enum(["STATE_UNSPECIFIED", "ACTIVE", "BUILDING", "BUILD_FAILED"]); export const gatewayCriterionType = z.enum(["TYPE_UNSPECIFIED", "CODE_SNIPPETS"]); export const gatewayCodeSnippets = z.object({language: z.string().optional(), fileContents: z.record(z.string(), z.string()).optional(), entryFile: z.string().optional(), entryFunc: z.string().optional()}); export const gatewayCriterion = z.object({type: gatewayCriterionType.optional(), name: z.string().optional(), description: z.string().optional(), codeSnippets: gatewayCodeSnippets.optional()}); 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 evaluatorSourceType = z.enum(["TYPE_UNSPECIFIED", "TYPE_UPLOAD", "TYPE_GITHUB", "TYPE_TEMPORARY"]); export const evaluatorSource = z.object({type: evaluatorSourceType.optional(), githubRepositoryName: z.string().optional()}); export const gatewayEncryptionState = z.enum(["ENCRYPTION_STATE_UNSPECIFIED", "ENCRYPTION_STATE_PLAINTEXT", "ENCRYPTION_STATE_CMEK"]); export const gatewayEvaluator = z.object({name: z.string().optional(), displayName: z.string().optional(), description: z.string().optional(), createTime: z.string().optional(), createdBy: z.string().optional(), updateTime: z.string().optional(), state: gatewayEvaluatorState.optional(), criteria: z.array(gatewayCriterion).optional(), requirements: z.string().optional(), entryPoint: z.string().optional(), status: gatewayStatus.optional(), commitHash: z.string().optional(), source: evaluatorSource.optional(), defaultDataset: z.string().optional(), encryptionState: gatewayEncryptionState.optional()}); export const gatewayListEvaluatorsResponse = z.object({evaluators: z.array(gatewayEvaluator).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 Evaluators * * GET /v1/accounts/{account_id}/evaluators */ export const getApiV1AccountsAccountIdEvaluators = async (args: GetApiV1AccountsAccountIdEvaluatorsArgs, options: GetApiV1AccountsAccountIdEvaluatorsOptions) => { 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))}/evaluators${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(gatewayListEvaluatorsResponse, await res.json()) };