import {z} from 'zod' export type KerasModelTypeEnum = 'int8' | 'float32' | 'akida' | 'requiresRetrain'; export type DeploymentTargetEngine = 'tflite' | 'tflite-eon' | 'tflite-eon-ram-optimized' | 'tensorrt' | 'tensaiflow' | 'drp-ai' | 'tidl' | 'akida' | 'syntiant' | 'memryx' | 'neox' | 'ethos-linux' | 'st-aton' | 'ceva-npn' | 'nordic-axon' | 'vlm-connector' | 'qaic'; export type GetApiApiProjectIdDeploymentArgs = {projectId: number, type: string, modelType?: KerasModelTypeEnum | undefined, engine?: DeploymentTargetEngine | undefined, impulseId?: number | undefined}; export type GetApiApiProjectIdDeploymentOptions = {baseUrl?: string | undefined, ApiKeyAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const getDeploymentResponse = z.object({success: z.boolean(), error: z.string().optional(), hasDeployment: z.boolean(), version: z.number().int().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 }; /** * Get deployment info * * GET /api/{projectId}/deployment * * Also accepts auth: JWTAuthentication, JWTHttpHeaderAuthentication, OAuth2 */ export const getApiApiProjectIdDeployment = async (args: GetApiApiProjectIdDeploymentArgs, options?: GetApiApiProjectIdDeploymentOptions) => { const {baseUrl = "https://studio.edgeimpulse.com/v1", fetch: fetchFn = fetch, ApiKeyAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.modelType != null) query.append("modelType", String(args.modelType)) if (args.engine != null) query.append("engine", String(args.engine)) if (args.impulseId != null) query.append("impulseId", String(args.impulseId)) if (ApiKeyAuthentication !== undefined) headers.set("x-api-key", ApiKeyAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.projectId))}/deployment${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getDeploymentResponse, await res.json()) };