import {z} from 'zod' export type MachineIDPathSegment = string; export type PublicPathSegment = string; export type GetApiV1MachinesMachineIdArtifactsArtifactIdArgs = {'X-Dedalus-Org-Id'?: string | undefined, machine_id: MachineIDPathSegment, artifact_id: PublicPathSegment}; export type GetApiV1MachinesMachineIdArtifactsArtifactIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const artifactResponse = z.object({artifact_id: z.string(), created_at: z.string(), download_url: z.string().optional(), execution_id: z.string().optional(), expires_at: z.string().optional(), machine_id: z.string(), mime_type: z.string().optional(), name: z.string(), sha256: z.string().optional(), size_bytes: 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 artifact * * GET /v1/machines/{machine_id}/artifacts/{artifact_id} * * Also accepts auth: BearerAuth */ export const getApiV1MachinesMachineIdArtifactsArtifactId = async (args: GetApiV1MachinesMachineIdArtifactsArtifactIdArgs, options?: GetApiV1MachinesMachineIdArtifactsArtifactIdOptions) => { const {baseUrl = "https://dcs.dedaluslabs.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Dedalus-Org-Id'] != null) headers.set("X-Dedalus-Org-Id", String(args['X-Dedalus-Org-Id'])) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/machines/${encodeURIComponent(String(args.machine_id))}/artifacts/${encodeURIComponent(String(args.artifact_id))}${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(artifactResponse, await res.json()) };