import {z} from 'zod' export type OrganizationTransferLearningOperatesOn = 'object_detection' | 'audio' | 'image' | 'regression' | 'anomaly_detection' | 'visual_anomaly_detection' | 'other' | 'image_akida' | 'object_detection_akida' | 'classification_akida' | 'self_contained_freeform_output'; export type ObjectDetectionLastLayer = 'mobilenet-ssd' | 'fomo' | 'yolov2-akida' | 'yolov5' | 'yolov5v5-drpai' | 'yolox' | 'yolov7' | 'yolo-pro' | 'tao-retinanet' | 'tao-ssd' | 'tao-yolov3' | 'tao-yolov4' | 'yolov11' | 'yolov11-abs' | 'paddleocr-detector' | 'qc-face-det-lite' | 'qc-yolox'; export type PublicProjectTierAvailability = 'enterprise-only' | 'all-projects' | 'all-projects-including-whitelabels'; export type ImageInputScaling = '0..1' | '-1..1' | '-128..127' | '0..255' | 'torch' | 'bgr-subtract-imagenet-mean'; export type BlockDisplayCategory = 'classical' | 'tao' | 'developer-preview'; export type OrganizationTransferLearningBlockModelFile = {id: string, name: string, type: 'binary' | 'json' | 'text', description: string}; export type OrganizationTransferLearningBlockCustomVariant = {key: string, name: string, inferencingEntrypoint: string, profilingEntrypoint?: string | undefined, modelFiles?: Array | undefined}; export type UpdateOrganizationTransferLearningBlockRequest = {name?: string | undefined, dockerContainer?: string | undefined, description?: string | undefined, operatesOn?: OrganizationTransferLearningOperatesOn | undefined, objectDetectionLastLayer?: ObjectDetectionLastLayer | undefined, implementationVersion?: number | undefined, isPublic?: boolean | undefined, isPublicForDevices?: Array | undefined, publicProjectTierAvailability?: PublicProjectTierAvailability | undefined, repositoryUrl?: string | undefined, parameters?: Array> | undefined, imageInputScaling?: ImageInputScaling | undefined, indRequiresGpu?: boolean | undefined, displayCategory?: BlockDisplayCategory | undefined, customModelVariants?: Array | undefined, indBlockNoLongerAvailable?: boolean | undefined, blockNoLongerAvailableReason?: string | undefined, sourceCodeDownloadStaffOnly?: boolean | undefined}; export type CreateApiApiOrganizationsOrganizationIdTransferLearningTransferLearningIdArgs = {organizationId: number, transferLearningId: number, body: UpdateOrganizationTransferLearningBlockRequest}; export type CreateApiApiOrganizationsOrganizationIdTransferLearningTransferLearningIdOptions = {baseUrl?: string | undefined, ApiKeyAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const genericApiResponse = z.object({success: z.boolean(), error: z.string().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 }; /** * Update transfer learning block * * POST /api/organizations/{organizationId}/transfer-learning/{transferLearningId} * * Also accepts auth: JWTAuthentication, JWTHttpHeaderAuthentication, OAuth2 */ export const createApiApiOrganizationsOrganizationIdTransferLearningTransferLearningId = async (args: CreateApiApiOrganizationsOrganizationIdTransferLearningTransferLearningIdArgs, options?: CreateApiApiOrganizationsOrganizationIdTransferLearningTransferLearningIdOptions) => { const {baseUrl = "https://studio.edgeimpulse.com/v1", fetch: fetchFn = fetch, ApiKeyAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuthentication !== undefined) headers.set("x-api-key", ApiKeyAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/api/organizations/${encodeURIComponent(String(args.organizationId))}/transfer-learning/${encodeURIComponent(String(args.transferLearningId))}${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(genericApiResponse, await res.json()) };