kimi-code / packages /agent-core-v2 /src /tool /input-schema.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
4e23b01 verified
Raw History Blame Contribute Delete
719 Bytes
import { z } from 'zod';
export function toInputJsonSchema(schema: z.ZodType): Record<string, unknown> {
const jsonSchema = z.toJSONSchema(schema, {
target: 'draft-7',
io: 'input',
});
closeObjectNodes(jsonSchema);
return jsonSchema;
}
function closeObjectNodes(value: unknown): void {
if (Array.isArray(value)) {
for (const item of value) closeObjectNodes(item);
return;
}
if (typeof value !== 'object' || value === null) return;
const node = value as Record<string, unknown>;
if (node['type'] === 'object' && node['additionalProperties'] === undefined) {
node['additionalProperties'] = false;
}
for (const child of Object.values(node)) {
closeObjectNodes(child);
}
}