import {z} from 'zod' export type MachineIDPathSegment = string; export type PublicPathSegment = string; export type DeleteApiV1MachinesMachineIdExecutionsExecutionIdArgs = {'X-Dedalus-Org-Id'?: string | undefined, machine_id: MachineIDPathSegment, execution_id: PublicPathSegment}; export type DeleteApiV1MachinesMachineIdExecutionsExecutionIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const artifactRef = z.object({artifact_id: z.string(), name: z.string()}); export const executionResponse = z.object({artifacts: z.array(artifactRef).nullable().optional(), command: z.array(z.string()).nullable(), completed_at: z.string().optional(), created_at: z.string(), cwd: z.string().optional(), env_keys: z.array(z.string()).nullable().optional(), error_code: z.string().optional(), error_message: z.string().optional(), execution_id: z.string(), exit_code: z.number().int().optional(), expires_at: z.string().optional(), machine_id: z.string(), retry_after_ms: z.number().int().optional(), signal: z.number().int().optional(), started_at: z.string().optional(), status: z.enum(["wake_in_progress", "queued", "running", "succeeded", "failed", "cancelled", "expired"]), stderr_bytes: z.number().int().optional(), stderr_truncated: z.boolean().optional(), stdout_bytes: z.number().int().optional(), stdout_truncated: z.boolean().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 }; /** * Delete execution * * DELETE /v1/machines/{machine_id}/executions/{execution_id} * * Also accepts auth: BearerAuth */ export const deleteApiV1MachinesMachineIdExecutionsExecutionId = async (args: DeleteApiV1MachinesMachineIdExecutionsExecutionIdArgs, options?: DeleteApiV1MachinesMachineIdExecutionsExecutionIdOptions) => { 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))}/executions/${encodeURIComponent(String(args.execution_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(executionResponse, await res.json()) };