import {z} from 'zod' export type ArtifactType = 'recording' | 'audio' | 'session_replay' | 'eval_score' | 'eval_trajectory' | 'eval_rubrics' | 'browser_console_log' | 'browser_session_action_log' | 'skyvern_log' | 'skyvern_log_raw' | 'screenshot' | 'screenshot_llm' | 'screenshot_action' | 'screenshot_final' | 'screenshot_proxy' | 'screenshot_pre_submit' | 'llm_prompt' | 'llm_request' | 'llm_response' | 'llm_response_parsed' | 'llm_response_rendered' | 'visible_elements_id_css_map' | 'visible_elements_id_frame_map' | 'visible_elements_tree' | 'visible_elements_tree_trimmed' | 'visible_elements_tree_in_prompt' | 'hashed_href_map' | 'visible_elements_id_xpath_map' | 'html' | 'html_scrape' | 'html_action' | 'html_pre_submit' | 'trace' | 'har' | 'script_file' | 'pdf' | 'step_archive' | 'task_archive' | 'download' | 'unknown'; export type GetApiV1RunsRunIdArtifactsArgs = {run_id: string, artifact_type?: (Array | null) | undefined}; export type GetApiV1RunsRunIdArtifactsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const artifactType = z.enum(["recording", "audio", "session_replay", "eval_score", "eval_trajectory", "eval_rubrics", "browser_console_log", "browser_session_action_log", "skyvern_log", "skyvern_log_raw", "screenshot", "screenshot_llm", "screenshot_action", "screenshot_final", "screenshot_proxy", "screenshot_pre_submit", "llm_prompt", "llm_request", "llm_response", "llm_response_parsed", "llm_response_rendered", "visible_elements_id_css_map", "visible_elements_id_frame_map", "visible_elements_tree", "visible_elements_tree_trimmed", "visible_elements_tree_in_prompt", "hashed_href_map", "visible_elements_id_xpath_map", "html", "html_scrape", "html_action", "html_pre_submit", "trace", "har", "script_file", "pdf", "step_archive", "task_archive", "download", "unknown"]); export const artifact = z.object({created_at: z.string(), modified_at: z.string(), artifact_id: z.string(), artifact_type: artifactType, uri: z.string(), bundle_key: z.string().nullable().optional(), checksum: z.string().nullable().optional(), file_size: z.number().int().nullable().optional(), task_id: z.string().nullable().optional(), step_id: z.string().nullable().optional(), workflow_run_id: z.string().nullable().optional(), workflow_run_block_id: z.string().nullable().optional(), run_id: z.string().nullable().optional(), browser_session_id: z.string().nullable().optional(), observer_cruise_id: z.string().nullable().optional(), observer_thought_id: z.string().nullable().optional(), ai_suggestion_id: z.string().nullable().optional(), signed_url: z.string().nullable().optional(), archived: z.boolean().optional(), organization_id: z.string()}); export const getApiV1RunsRunIdArtifactsResponse = z.array(artifact); 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 artifacts for a run * * GET /v1/runs/{run_id}/artifacts */ export const getApiV1RunsRunIdArtifacts = async (args: GetApiV1RunsRunIdArtifactsArgs, options?: GetApiV1RunsRunIdArtifactsOptions) => { const {baseUrl = "https://api.skyvern.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.artifact_type ?? []) query.append("artifact_type", String(item)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/runs/${encodeURIComponent(String(args.run_id))}/artifacts${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(getApiV1RunsRunIdArtifactsResponse, await res.json()) };