File size: 1,279 Bytes
c2b7eb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//#region src/utils/validate_schema.ts
function assertNoEmptyStringEnums(schema, toolName, path = []) {
	if (schema == null || typeof schema !== "object") return;
	const obj = schema;
	if (Array.isArray(obj.enum)) {
		if (obj.enum.some((v) => v === "")) {
			const pathStr = path.length ? ` at path "${path.join(".")}"` : "";
			const toolStr = toolName ? ` in tool "${toolName}"` : "";
			throw new Error(`Invalid enum: empty string not allowed${toolStr}${pathStr}. Gemini API rejects empty strings in enums.`);
		}
	}
	if (obj.type === "object" && obj.properties && typeof obj.properties === "object") for (const [prop, child] of Object.entries(obj.properties)) assertNoEmptyStringEnums(child, toolName, [...path, prop]);
	if (obj.items) assertNoEmptyStringEnums(obj.items, toolName, [...path, "[]"]);
	for (const k of [
		"anyOf",
		"oneOf",
		"allOf"
	]) {
		const arr = obj[k];
		if (Array.isArray(arr)) arr.forEach((child, i) => assertNoEmptyStringEnums(child, toolName, [...path, `${k}[${i}]`]));
	}
	if (obj.additionalProperties && typeof obj.additionalProperties === "object") assertNoEmptyStringEnums(obj.additionalProperties, toolName, [...path, "additionalProperties"]);
}
//#endregion
export { assertNoEmptyStringEnums };

//# sourceMappingURL=validate_schema.js.map