import {z} from 'zod' export type CreateApiV1DrivesNameForkArgs = {name: string, projectId?: string | undefined, teamId?: string | undefined, slug?: string | undefined, body: {name: string}}; export type CreateApiV1DrivesNameForkOptions = {baseUrl?: string | undefined, bearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const drive = z.object({createdAt: z.number(), currentSandboxName: z.string().optional(), currentSessionId: z.string().optional(), id: z.string(), maxSizeBytes: z.number(), name: z.string(), parentDriveId: z.string().optional(), projectId: z.string(), region: z.string(), rootDriveId: z.string().optional(), updatedAt: z.number(), workloadType: z.enum(["sandbox", "v0"]).optional()}); export const createApiV1DrivesNameForkResponse = z.object({drive: drive}); 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 }; /** * Fork a drive * * POST /v1/drives/{name}/fork */ export const createApiV1DrivesNameFork = async (args: CreateApiV1DrivesNameForkArgs, options?: CreateApiV1DrivesNameForkOptions) => { const {baseUrl = "https://api.vercel.com", fetch: fetchFn = fetch, bearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.projectId != null) query.append("projectId", String(args.projectId)) if (args.teamId != null) query.append("teamId", String(args.teamId)) if (args.slug != null) query.append("slug", String(args.slug)) if (bearerToken !== undefined) headers.set('authorization', `Bearer ${bearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/drives/${encodeURIComponent(String(args.name))}/fork${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV1DrivesNameForkResponse, await res.json()) };