import {z} from 'zod' export type CreateApiApiPreviewCapsulesIdSkillFilesMoveArgs = {id: string, body: {expected_revision_id: string, new_path: string, path: string}}; export type CreateApiApiPreviewCapsulesIdSkillFilesMoveOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiPreviewCapsulesIdSkillFilesMoveResponse = z.object({evicted_revisions: z.number().int().gte(-9007199254740991).lte(9007199254740991), file: z.object({executable: z.boolean(), is_text: z.boolean(), path: z.string().min(1).max(512), revision_id: z.string().max(36), sha256: z.string().max(64), size: z.number().int().gte(-9007199254740991).lte(9007199254740991), source_kind: z.enum(["stored", "linked"]), updated_at: z.string().max(40)}).nullable(), usage: z.object({current_bytes: z.number().int().gte(-9007199254740991).lte(9007199254740991), history_rows: z.number().int().gte(-9007199254740991).lte(9007199254740991), path_count: z.number().int().gte(-9007199254740991).lte(9007199254740991), retained_bytes: z.number().int().gte(-9007199254740991).lte(9007199254740991)})}); 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 }; /** * Rename a skill file, keeping its identity and bytes * * POST /api/preview/capsules/{id}/skill-files/move * * Also accepts auth: cookieAuth, oauth2 */ export const createApiApiPreviewCapsulesIdSkillFilesMove = async (args: CreateApiApiPreviewCapsulesIdSkillFilesMoveArgs, options: CreateApiApiPreviewCapsulesIdSkillFilesMoveOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/preview/capsules/${encodeURIComponent(String(args.id))}/skill-files/move${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(createApiApiPreviewCapsulesIdSkillFilesMoveResponse, await res.json()) };