/** * Provider-safe TypeBox string enum helpers. * * Emits flat `enum` schemas instead of `anyOf` unions so provider tool-schema validators accept them. */ import { Type } from "typebox"; type StringEnumOptions = { description?: string; title?: string; default?: T[number]; deprecated?: boolean; }; export function stringEnum( values: T, options: StringEnumOptions = {}, ) { const enumValues = Array.isArray(values) ? values : values && typeof values === "object" ? Object.values(values).filter((value): value is T[number] => typeof value === "string") : []; return enumValues.length === 0 ? Type.Unsafe({ type: "string", ...options }) : Type.Enum(enumValues, { type: "string", ...options }); } export function optionalStringEnum( values: T, options: StringEnumOptions = {}, ) { return Type.Optional(stringEnum(values, options)); }