import {z} from 'zod' export type GetApiApiProjectIdTrainingKerasLearnIdDataExplorerFeaturesArgs = {projectId: number, learnId: number}; export type GetApiApiProjectIdTrainingKerasLearnIdDataExplorerFeaturesOptions = {baseUrl?: string | undefined, ApiKeyAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const inputBlockType = z.enum(["time-series", "image", "features"]); export const imageInputResizeMode = z.enum(["squash", "fit-short", "fit-long", "crop"]); export const impulseInputBlockDatasetSubset = z.object({includePercentage: z.number(), seed: z.number().int().optional()}); export const impulseInputBlock = z.object({id: z.number().int().gte(1), type: inputBlockType, name: z.string(), title: z.string(), axes: z.array(z.string()).optional(), windowSizeMs: z.number().int().optional(), windowIncreaseMs: z.number().int().optional(), frequencyHz: z.number().optional(), classificationWindowIncreaseMs: z.number().int().optional(), padZeros: z.boolean().optional(), labelingMethodMultiLabel: z.object({type: z.enum(["end-of-window", "anywhere-in-window", "anywhere-in-window-min-percentage", "majority-in-window"]), labels: z.array(z.string()).optional(), minPercentage: z.number().optional()}).optional(), imageWidth: z.number().int().optional(), imageHeight: z.number().int().optional(), resizeMode: imageInputResizeMode.optional(), resizeMethod: z.enum(["lanczos3", "nearest"]).optional(), cropAnchor: z.enum(["top-left", "top-center", "top-right", "middle-left", "middle-center", "middle-right", "bottom-left", "bottom-center", "bottom-right"]).optional(), createdBy: z.string().optional(), createdAt: z.string().optional(), datasetSubset: impulseInputBlockDatasetSubset.optional()}); export const getDataExplorerFeaturesResponse = z.object({success: z.boolean(), error: z.string().optional(), hasFeatures: z.boolean(), data: z.array(z.object({X: z.record(z.string(), z.number()), y: z.number().int(), yLabel: z.string(), sample: z.object({id: z.number(), name: z.string(), startMs: z.number(), endMs: z.number(), category: z.enum(["training", "testing", "validation"])}).optional()})), inputBlock: impulseInputBlock.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 data explorer features * * GET /api/{projectId}/training/keras/{learnId}/data-explorer/features * * Also accepts auth: JWTAuthentication, JWTHttpHeaderAuthentication, OAuth2 */ export const getApiApiProjectIdTrainingKerasLearnIdDataExplorerFeatures = async (args: GetApiApiProjectIdTrainingKerasLearnIdDataExplorerFeaturesArgs, options?: GetApiApiProjectIdTrainingKerasLearnIdDataExplorerFeaturesOptions) => { 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 (ApiKeyAuthentication !== undefined) headers.set("x-api-key", ApiKeyAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.projectId))}/training/keras/${encodeURIComponent(String(args.learnId))}/data-explorer/features${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(getDataExplorerFeaturesResponse, await res.json()) };