feat: add SCADA frontend action bridge
This commit is contained in:
@@ -2,7 +2,58 @@ import { z } from "zod";
|
||||
import type { FrontendActionManifest } from "./types.js";
|
||||
|
||||
type Definition = { manifest: FrontendActionManifest; inputSchema: z.ZodTypeAny; outputSchema: z.ZodTypeAny };
|
||||
const definitions: Definition[] = [];
|
||||
const sensorId = z.string().trim().min(1).max(128);
|
||||
const scadaLevel = z.enum(["high", "medium", "low", "unrated"]);
|
||||
const levelCounts = z.object({
|
||||
high: z.number().int().nonnegative(),
|
||||
medium: z.number().int().nonnegative(),
|
||||
low: z.number().int().nonnegative(),
|
||||
unrated: z.number().int().nonnegative(),
|
||||
}).strict();
|
||||
const renderScadaAnalysisInput = z.object({
|
||||
items: z.array(z.object({ sensor_id: sensorId, level: scadaLevel }).strict()).min(1).max(100),
|
||||
}).strict().superRefine((value, context) => {
|
||||
const seen = new Set<string>();
|
||||
value.items.forEach((item, index) => {
|
||||
if (seen.has(item.sensor_id)) {
|
||||
context.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "sensor_id values must be unique",
|
||||
path: ["items", index, "sensor_id"],
|
||||
});
|
||||
}
|
||||
seen.add(item.sensor_id);
|
||||
});
|
||||
});
|
||||
const definitions: Definition[] = [
|
||||
{
|
||||
manifest: {
|
||||
id: "render_scada_analysis",
|
||||
version: "frontend-action@1",
|
||||
risk: "view",
|
||||
timeoutMs: 15_000,
|
||||
supportedSurfaces: ["map_overlay"],
|
||||
},
|
||||
inputSchema: renderScadaAnalysisInput,
|
||||
outputSchema: z.object({
|
||||
rendered_ids: z.array(sensorId),
|
||||
missing_ids: z.array(sensorId),
|
||||
level_counts: levelCounts,
|
||||
fitted: z.literal(true),
|
||||
}).strict(),
|
||||
},
|
||||
{
|
||||
manifest: {
|
||||
id: "clear_scada_analysis",
|
||||
version: "frontend-action@1",
|
||||
risk: "view",
|
||||
timeoutMs: 15_000,
|
||||
supportedSurfaces: ["map_overlay"],
|
||||
},
|
||||
inputSchema: z.object({}).strict(),
|
||||
outputSchema: z.object({ cleared: z.literal(true) }).strict(),
|
||||
},
|
||||
];
|
||||
|
||||
export const frontendActionRegistry = definitions.map((item) => item.manifest);
|
||||
export const getFrontendActionDefinition = (name: string) => definitions.find((item) => item.manifest.id === name);
|
||||
|
||||
Reference in New Issue
Block a user