Initial implementation of TriggerShell
A Python CLI (typer) that bootstraps Node/pnpm and launches a Next.js 16 web app for running configured shell scripts: YAML config validated by a shared Zod schema, dynamic per-script forms mapped to shadcn controls, argv-safe execa execution with live WebSocket streaming, SQLite/Drizzle run history, and optional argon2 session + API token auth. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { z } from "zod";
|
||||
import type { ScriptConfig, VariableConfig } from "../config/schema";
|
||||
|
||||
function fieldSchema(variable: VariableConfig): z.ZodTypeAny {
|
||||
let field: z.ZodTypeAny;
|
||||
|
||||
switch (variable.type) {
|
||||
case "string": {
|
||||
let s = z.string();
|
||||
if (variable.minLength !== undefined) s = s.min(variable.minLength);
|
||||
if (variable.maxLength !== undefined) s = s.max(variable.maxLength);
|
||||
if (variable.pattern) s = s.regex(new RegExp(variable.pattern));
|
||||
field = s;
|
||||
break;
|
||||
}
|
||||
case "number": {
|
||||
let n = z.number();
|
||||
if (variable.min !== undefined) n = n.min(variable.min);
|
||||
if (variable.max !== undefined) n = n.max(variable.max);
|
||||
field = n;
|
||||
break;
|
||||
}
|
||||
case "boolean":
|
||||
field = z.boolean();
|
||||
break;
|
||||
case "enum":
|
||||
field = z.enum(variable.choices as [string, ...string[]]);
|
||||
break;
|
||||
case "multiselect":
|
||||
field = z.array(z.enum(variable.choices as [string, ...string[]]));
|
||||
break;
|
||||
}
|
||||
|
||||
if (!variable.required) {
|
||||
field = field.optional().or(z.literal(""));
|
||||
}
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
/** Builds one Zod object schema from a list of variable definitions - the single source of truth
|
||||
* imported by both the client form resolver and the server-side run-creation handler. */
|
||||
export function buildVariableSchemaFromList(
|
||||
variables: readonly VariableConfig[],
|
||||
) {
|
||||
const shape: Record<string, z.ZodTypeAny> = {};
|
||||
for (const variable of variables) {
|
||||
shape[variable.name] = fieldSchema(variable);
|
||||
}
|
||||
return z.object(shape);
|
||||
}
|
||||
|
||||
export function buildVariableSchema(script: ScriptConfig) {
|
||||
return buildVariableSchemaFromList(script.variables);
|
||||
}
|
||||
|
||||
export type VariableValues = Record<string, unknown>;
|
||||
Reference in New Issue
Block a user