Skip to content

Commit c1b55ff

Browse files
committed
fix(schemas): preserve string enum fallbacks
1 parent e798a76 commit c1b55ff

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎src/agents/schema/string-enum.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ export function stringEnum<T extends readonly string[]>(
1616
values: T,
1717
options: StringEnumOptions<T> = {},
1818
) {
19-
return values.length === 0
19+
const enumValues = Array.isArray(values)
20+
? values
21+
: values && typeof values === "object"
22+
? Object.values(values).filter((value): value is T[number] => typeof value === "string")
23+
: [];
24+
return enumValues.length === 0
2025
? Type.Unsafe<T[number]>({ type: "string", ...options })
21-
: Type.Enum(values, { type: "string", ...options });
26+
: Type.Enum(enumValues, { type: "string", ...options });
2227
}
2328

2429
export function optionalStringEnum<T extends readonly string[]>(

0 commit comments

Comments
 (0)