import {z} from 'zod' export type FootageRulesDTO = {source?: ('prefer_library' | 'fallback' | 'library_only' | 'never') | undefined, roll?: ('a_first' | 'b_first' | 'mix') | undefined, generate_missing?: boolean | undefined, threshold?: number | undefined, character?: ('strict' | 'loose') | undefined, instructions?: string | undefined}; export type MomentRefDTO = {item_id: string, moment_id: string}; export type EditPlanDTO = {text: string, mode?: ('idea' | 'script') | undefined, duration_seconds?: number | undefined, footage_rules?: FootageRulesDTO | undefined, item_ids?: Array | undefined, picks?: Array | undefined, picks_only?: boolean | undefined, presenter?: (string | null) | undefined, domain_id?: (string | null) | undefined}; export type CreateApiApiV1VideoLibraryGeneratePlanArgs = {body: EditPlanDTO}; export type CreateApiApiV1VideoLibraryGeneratePlanOptions = {baseUrl: string, JWTBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1VideoLibraryGeneratePlanResponse = z.unknown(); 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 }; /** * Plan a video from a script or idea: beats, and the library footage an LLM picks for each * * POST /api/v1/video-library/generate/plan */ export const createApiApiV1VideoLibraryGeneratePlan = async (args: CreateApiApiV1VideoLibraryGeneratePlanArgs, options: CreateApiApiV1VideoLibraryGeneratePlanOptions) => { const {baseUrl, fetch: fetchFn = fetch, JWTBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (JWTBearer !== undefined) headers.set('authorization', `Bearer ${JWTBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/video-library/generate/plan${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(createApiApiV1VideoLibraryGeneratePlanResponse, await res.json()) };