import {z} from 'zod' export type GetApiApiProjectIdRawDataDataExplorerPredictionsArgs = {projectId: number}; export type GetApiApiProjectIdRawDataDataExplorerPredictionsOptions = {baseUrl?: string | undefined, ApiKeyAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const boundingBoxWithScore = z.object({label: z.string(), x: z.number(), y: z.number(), width: z.number(), height: z.number(), score: z.number()}); export const modelPrediction = z.object({sampleId: z.number().int(), startMs: z.number(), endMs: z.number(), label: z.string().optional(), prediction: z.string(), predictionCorrect: z.boolean().optional(), expectedAnomalyOutcome: z.string().optional(), f1Score: z.number().optional(), anomalyScores: z.array(z.array(z.number())).optional(), boundingBoxes: z.array(boundingBoxWithScore).optional(), labelMapPredictions: z.record(z.string(), z.string()).optional()}); export const dataExplorerPredictionsResponse = z.object({success: z.boolean(), error: z.string().optional(), predictions: z.array(modelPrediction), labels: z.array(z.string()), classificationType: z.enum(["classification", "regression"])}); 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 predictions * * GET /api/{projectId}/raw-data/data-explorer/predictions * * Also accepts auth: JWTAuthentication, JWTHttpHeaderAuthentication, OAuth2 */ export const getApiApiProjectIdRawDataDataExplorerPredictions = async (args: GetApiApiProjectIdRawDataDataExplorerPredictionsArgs, options?: GetApiApiProjectIdRawDataDataExplorerPredictionsOptions) => { 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))}/raw-data/data-explorer/predictions${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(dataExplorerPredictionsResponse, await res.json()) };