import {z} from 'zod' export type DeploymentLogType = 'build' | 'runtime'; export type GetApiV1WorkflowsDeploymentsNameLogsArgs = {name: string, log_type?: DeploymentLogType | undefined, worker_name?: (string | null) | undefined, workflow_name?: (string | null) | undefined, after?: (string | null) | undefined, before?: (string | null) | undefined, order?: ('asc' | 'desc') | undefined, cursor?: (string | null) | undefined, limit?: number | undefined}; export type GetApiV1WorkflowsDeploymentsNameLogsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const deploymentLogRecord = z.object({timestamp: z.string(), trace_id: z.string(), span_id: z.string(), severity_text: z.string(), body: z.string(), log_attributes: z.record(z.string(), z.string())}); export const deploymentLogSearchResponse = z.object({results: z.array(deploymentLogRecord), next_cursor: z.string().nullable().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 Deployment Logs * * GET /v1/workflows/deployments/{name}/logs */ export const getApiV1WorkflowsDeploymentsNameLogs = async (args: GetApiV1WorkflowsDeploymentsNameLogsArgs, options?: GetApiV1WorkflowsDeploymentsNameLogsOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.log_type != null) query.append("log_type", String(args.log_type)) if (args.worker_name != null) query.append("worker_name", String(args.worker_name)) if (args.workflow_name != null) query.append("workflow_name", String(args.workflow_name)) if (args.after != null) query.append("after", String(args.after)) if (args.before != null) query.append("before", String(args.before)) if (args.order != null) query.append("order", String(args.order)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workflows/deployments/${encodeURIComponent(String(args.name))}/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(deploymentLogSearchResponse, await res.json()) };