import {z} from 'zod' export type GetApiInflightTestModelsInflightTestModelIdRunsArgs = {inflightTestModelId: string, order?: string | undefined, size?: number | undefined, sort?: string | undefined, start?: number | undefined}; export type GetApiInflightTestModelsInflightTestModelIdRunsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const testInstanceDTO = z.object({id: z.string().optional(), testModelId: z.string().optional(), testSetKey: z.string().optional(), scopeId: z.string().optional(), scopeType: z.string().optional(), scopeDefinitionId: z.string().optional(), scopeDefinitionKey: z.string().optional(), startTime: z.string().optional(), endTime: z.string().optional(), durationMs: z.number().int().optional(), status: z.string().optional(), result: z.string().optional(), passedCount: z.number().int().optional(), failedCount: z.number().int().optional(), totalSteps: z.number().int().optional(), progress: z.number().optional(), failedStepName: z.string().optional(), tenantId: z.string().optional()}); export const dataResponseTestInstanceDTO = z.object({data: z.array(testInstanceDTO).optional(), total: z.number().int().optional(), start: z.number().int().optional(), sort: z.string().optional(), order: z.string().optional(), size: 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 }; /** * Get the runs for an inflight test model * * GET /inflight-test-models/{inflightTestModelId}/runs */ export const getApiInflightTestModelsInflightTestModelIdRuns = async (args: GetApiInflightTestModelsInflightTestModelIdRunsArgs, options?: GetApiInflightTestModelsInflightTestModelIdRunsOptions) => { const {baseUrl = "http://localhost:8090/inspect-api", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.order != null) query.append("order", String(args.order)) if (args.size != null) query.append("size", String(args.size)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.start != null) query.append("start", String(args.start)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/inflight-test-models/${encodeURIComponent(String(args.inflightTestModelId))}/runs${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(dataResponseTestInstanceDTO, await res.json()) };