import {z} from 'zod' export type KugelTurnActivateRequest = {instance_id: string, model_id: string, artifact_version?: (string | null) | undefined}; export type CreateApiV1LicenseKugelturnActivateArgs = {'X-API-Key': string, body: KugelTurnActivateRequest}; export type CreateApiV1LicenseKugelturnActivateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const kugelTurnActivateResponse = z.object({activation_id: z.string(), instance_id: z.string(), model_id: z.string(), artifact_version: z.string(), artifact_download_url: z.string(), artifact_size_bytes: z.number().int().gte(0).nullable().optional(), manifest_sha256: z.string(), model_key: z.string(), usage_key: z.string(), offline_token: z.string(), public_key_pem: z.string(), grant_expires_at_ms: z.number().int().gt(0).lte(9223372036854776000), authorized_calls: z.number().int().gt(0).lte(9223372036854776000), authorized_audio_ms: z.number().int().gt(0).lte(9223372036854776000), acknowledged_sequence: z.number().int().gte(0).lte(9223372036854776000), cumulative_calls: z.number().int().gte(0).lte(9223372036854776000), cumulative_audio_ms: z.number().int().gte(0).lte(9223372036854776000), cumulative_context_chars: z.number().int().gte(0).lte(9223372036854776000)}); 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 }; /** * Activate Kugelturn * * POST /v1/license/kugelturn/activate */ export const createApiV1LicenseKugelturnActivate = async (args: CreateApiV1LicenseKugelturnActivateArgs, options: CreateApiV1LicenseKugelturnActivateOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/license/kugelturn/activate${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(kugelTurnActivateResponse, await res.json()) };