import {z} from 'zod' export type GetApiVersionsVersionIdPodLogsArgs = {version_id: string, pod?: (string | null) | undefined, container?: (string | null) | undefined, stream?: (string | null) | undefined, since?: (string | null) | undefined, until?: (string | null) | undefined, search?: (string | null) | undefined, limit?: number | undefined, after?: (string | null) | undefined}; export type GetApiVersionsVersionIdPodLogsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const versionPodLogEntry = z.object({agent_id: z.string(), branch_id: z.string().nullable().optional(), cluster: z.string().nullable().optional(), container_name: z.string().nullable().optional(), k8s_namespace: z.string().nullable().optional(), log_id: z.string(), message: z.string(), pod_name: z.string().nullable().optional(), stream: z.string().nullable().optional(), timestamp: z.string(), version_id: z.string()}); export const versionPodLogsResponse = z.object({has_more: z.boolean(), logs: z.array(versionPodLogEntry).optional(), 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 }; /** * Get Version Pod Logs * * GET /versions/{version_id}/pod-logs */ export const getApiVersionsVersionIdPodLogs = async (args: GetApiVersionsVersionIdPodLogsArgs, options: GetApiVersionsVersionIdPodLogsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pod != null) query.append("pod", String(args.pod)) if (args.container != null) query.append("container", String(args.container)) if (args.stream != null) query.append("stream", String(args.stream)) if (args.since != null) query.append("since", String(args.since)) if (args.until != null) query.append("until", String(args.until)) if (args.search != null) query.append("search", String(args.search)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.after != null) query.append("after", String(args.after)) const url = `${baseUrl.replace(/\/+$/, '')}/versions/${encodeURIComponent(String(args.version_id))}/pod-logs${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(versionPodLogsResponse, await res.json()) };