import {z} from 'zod' export type SortOrderV1 = 'asc' | 'desc'; export type LogLevelV1 = 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR'; export type GetApiV1ModelsModelIdDeploymentsDeploymentIdLogsArgs = {start_epoch_millis?: (number | null) | undefined, end_epoch_millis?: (number | null) | undefined, direction?: (SortOrderV1 | null) | undefined, limit?: (number | null) | undefined, min_level?: (LogLevelV1 | null) | undefined, replica?: (string | null) | undefined, request_id?: (string | null) | undefined, component?: (string | null) | undefined, search_pattern?: (string | null) | undefined, includes?: Array | undefined, excludes?: Array | undefined}; export type GetApiV1ModelsModelIdDeploymentsDeploymentIdLogsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const logLevelV1 = z.enum(["DEBUG", "INFO", "WARNING", "ERROR"]); export const logV1 = z.object({timestamp: z.string(), message: z.string(), replica: z.string().nullable(), request_id: z.string().nullable().optional(), level: logLevelV1.nullable().optional()}); export const getLogsResponseV1 = z.object({logs: z.array(logV1)}); 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 }; /** * Gets the logs for a model deployment * * GET /v1/models/{model_id}/deployments/{deployment_id}/logs */ export const getApiV1ModelsModelIdDeploymentsDeploymentIdLogs = async (args: GetApiV1ModelsModelIdDeploymentsDeploymentIdLogsArgs, options: GetApiV1ModelsModelIdDeploymentsDeploymentIdLogsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start_epoch_millis != null) query.append("start_epoch_millis", String(args.start_epoch_millis)) if (args.end_epoch_millis != null) query.append("end_epoch_millis", String(args.end_epoch_millis)) if (args.direction != null) query.append("direction", String(args.direction)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.min_level != null) query.append("min_level", String(args.min_level)) if (args.replica != null) query.append("replica", String(args.replica)) if (args.request_id != null) query.append("request_id", String(args.request_id)) if (args.component != null) query.append("component", String(args.component)) if (args.search_pattern != null) query.append("search_pattern", String(args.search_pattern)) for (const item of args.includes ?? []) query.append("includes", String(item)) for (const item of args.excludes ?? []) query.append("excludes", String(item)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/models/${encodeURIComponent(String(args.model_id))}/deployments/${encodeURIComponent(String(args.deployment_id))}/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(getLogsResponseV1, await res.json()) };