Also scopes the MCP plugin to explicit per-collection eligibility (mcpCollections). Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
77 lines
No EOL
2.8 KiB
TypeScript
77 lines
No EOL
2.8 KiB
TypeScript
export type RibbonValidationResult = { ok: true } | { ok: false; error: string };
|
|
|
|
export function validateRibbonDesign(design: unknown): RibbonValidationResult {
|
|
if (!design || typeof design !== "object") {
|
|
return { ok: false, error: "Invalid design object" };
|
|
}
|
|
|
|
const designObj = design as Record<string, unknown>;
|
|
|
|
// Check stripes
|
|
const stripes = designObj.stripes;
|
|
if (!Array.isArray(stripes)) {
|
|
return { ok: false, error: "Stripes must be an array" };
|
|
}
|
|
|
|
if (stripes.length < 1 || stripes.length > 10) {
|
|
return { ok: false, error: "Must have between 1 and 10 stripes" };
|
|
}
|
|
|
|
for (let i = 0; i < stripes.length; i++) {
|
|
const stripe = stripes[i];
|
|
if (!stripe || typeof stripe !== "object") {
|
|
return { ok: false, error: `Stripe ${i + 1} is invalid` };
|
|
}
|
|
|
|
const stripeObj = stripe as Record<string, unknown>;
|
|
if (typeof stripeObj.width !== "number" || stripeObj.width <= 0 || !Number.isFinite(stripeObj.width)) {
|
|
return { ok: false, error: `Stripe ${i + 1} width must be a positive finite number` };
|
|
}
|
|
|
|
if (typeof stripeObj.color !== "string" || !/^#[0-9a-fA-F]{6}$/.test(stripeObj.color)) {
|
|
return { ok: false, error: `Stripe ${i + 1} color must be a valid hex color (#RRGGBB)` };
|
|
}
|
|
}
|
|
|
|
// Check devices
|
|
const devices = designObj.devices;
|
|
if (!Array.isArray(devices)) {
|
|
return { ok: false, error: "Devices must be an array" };
|
|
}
|
|
|
|
if (devices.length > 6) {
|
|
return { ok: false, error: "Must have at most 6 devices" };
|
|
}
|
|
|
|
const validDeviceTypes = ["star", "oakLeaf", "arrowUp", "campaignClasp"];
|
|
for (let i = 0; i < devices.length; i++) {
|
|
const device = devices[i];
|
|
if (!device || typeof device !== "object") {
|
|
return { ok: false, error: `Device ${i + 1} is invalid` };
|
|
}
|
|
|
|
const deviceObj = device as Record<string, unknown>;
|
|
if (typeof deviceObj.id !== "string") {
|
|
return { ok: false, error: `Device ${i + 1} must have a string id` };
|
|
}
|
|
|
|
if (!validDeviceTypes.includes(deviceObj.type as string)) {
|
|
return { ok: false, error: `Device ${i + 1} type must be one of: ${validDeviceTypes.join(", ")}` };
|
|
}
|
|
|
|
if (typeof deviceObj.position !== "number" || !Number.isFinite(deviceObj.position) || deviceObj.position < 0 || deviceObj.position > 100) {
|
|
return { ok: false, error: `Device ${i + 1} position must be a finite number between 0 and 100` };
|
|
}
|
|
|
|
if (typeof deviceObj.positionY !== "number" || !Number.isFinite(deviceObj.positionY) || deviceObj.positionY < 0 || deviceObj.positionY > 100) {
|
|
return { ok: false, error: `Device ${i + 1} positionY must be a finite number between 0 and 100` };
|
|
}
|
|
}
|
|
|
|
// Check mirrored
|
|
if (typeof designObj.mirrored !== "boolean") {
|
|
return { ok: false, error: "Mirrored must be a boolean" };
|
|
}
|
|
|
|
return { ok: true };
|
|
} |