import {z} from 'zod' export type CustomHarnessStatus = 'draft' | 'active' | 'archived' | 'failed'; export type GetApiV1CustomHarnessesArgs = {team_id?: (string | null) | undefined, limit?: number | undefined, offset?: number | undefined, status?: (CustomHarnessStatus | null) | undefined, agent_id?: (string | null) | undefined}; export type GetApiV1CustomHarnessesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const customHarnessStatus = z.enum(["draft", "active", "archived", "failed"]); export const customHarnessListItem = z.object({id: z.string(), name: z.string(), description: z.string().nullable().optional(), status: customHarnessStatus, created_at: z.number().int(), updated_at: z.number().int(), agent_id: z.string(), agent_name: z.string().nullable().optional(), policy_ids: z.array(z.string()).optional(), persona_ids: z.array(z.string()).optional()}); export const customHarnessListResponse = z.object({results: z.array(customHarnessListItem), total: z.number().int()}); 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 Custom Harnesses * * GET /v1/custom-harnesses/ */ export const getApiV1CustomHarnesses = async (args: GetApiV1CustomHarnessesArgs, options: GetApiV1CustomHarnessesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.team_id != null) query.append("team_id", String(args.team_id)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.status != null) query.append("status", String(args.status)) if (args.agent_id != null) query.append("agent_id", String(args.agent_id)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/custom-harnesses/${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(customHarnessListResponse, await res.json()) };