| 53 | } |
| 54 | |
| 55 | function schemaToCLIOptions(toolName: string, schema: JsonSchema): CliOption[] { |
| 56 | if (!schema || !schema.properties) { |
| 57 | return []; |
| 58 | } |
| 59 | const required = schema.required || []; |
| 60 | const properties = schema.properties; |
| 61 | return Object.entries(properties).map(([name, prop]) => { |
| 62 | const isRequired = required.includes(name); |
| 63 | const description = prop.description || ''; |
| 64 | if (typeof prop.type !== 'string') { |
| 65 | throw new Error( |
| 66 | `Property ${name} has a complex type not supported by CLI.`, |
| 67 | ); |
| 68 | } |
| 69 | return { |
| 70 | name, |
| 71 | type: prop.type, |
| 72 | description, |
| 73 | required: isRequired, |
| 74 | positional: |
| 75 | isRequired || OPTIONAL_POSITIONAL_ARGS.has(`${toolName}:${name}`), |
| 76 | default: prop.default, |
| 77 | enum: prop.enum, |
| 78 | }; |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | async function generateCli() { |
| 83 | const tools = createTools( |