import {z} from 'zod' export type PoolHealthStatus = 'healthy' | 'partial' | 'inactive'; export type GetApiRunnersRunnerPoolsArgs = {searchQuery?: string | undefined, pageSize?: number | undefined, offset?: number | undefined, status?: Array | undefined, labels?: Array | undefined, sort?: ({field?: ('name' | 'createdAt' | 'updatedAt' | 'runnersCount' | 'assignedProjectsCount' | 'assignedWorkspaceCount' | 'poolStatus') | undefined, direction?: ('asc' | 'desc') | undefined}) | undefined}; export type GetApiRunnersRunnerPoolsOptions = {baseUrl?: string | undefined, JWTAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const poolHealthStatus = z.enum(["healthy", "partial", "inactive"]); export const runnerHealthStatus = z.enum(["active", "awaiting_first_heartbeat", "timeout"]); export const poolHealth = z.object({poolStatus: poolHealthStatus.optional(), statusByRunner: z.record(z.string(), runnerHealthStatus).optional()}); export const runnerPool = z.object({id: z.string().optional(), name: z.string().optional(), accountId: z.string().optional(), labels: z.array(z.string()).optional(), description: z.string().optional(), runnersCount: z.number().int().gte(0).optional(), assignedProjectsCount: z.number().int().gte(0).optional(), assignedWorkspaceCount: z.number().int().gte(0).optional(), assignedProjects: z.array(z.object({id: z.string().optional(), name: z.string().optional()})).optional(), assignedWorkspaces: z.array(z.object({id: z.string().optional(), name: z.string().optional()})).optional(), health: poolHealth.optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const getApiRunnersRunnerPoolsResponse = z.array(runnerPool); 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 runner pools * * GET /runners/runner-pools */ export const getApiRunnersRunnerPools = async (args: GetApiRunnersRunnerPoolsArgs, options?: GetApiRunnersRunnerPoolsOptions) => { const {baseUrl = "https://api.firefly.ai/v2", fetch: fetchFn = fetch, JWTAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.searchQuery != null) query.append("searchQuery", String(args.searchQuery)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.offset != null) query.append("offset", String(args.offset)) for (const item of args.status ?? []) query.append("status", String(item)) for (const item of args.labels ?? []) query.append("labels", String(item)) if (args.sort != null) query.append("sort", JSON.stringify(args.sort)) if (JWTAuth !== undefined) headers.set('authorization', `Bearer ${JWTAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/runners/runner-pools${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(getApiRunnersRunnerPoolsResponse, await res.json()) };