(value: unknown, depth = 2)
| 2642 | * e.g. "{title: string, items: [{id: number, name: string}]}" |
| 2643 | */ |
| 2644 | export function inferCompactSchema(value: unknown, depth = 2): string { |
| 2645 | if (value === null) return 'null' |
| 2646 | if (Array.isArray(value)) { |
| 2647 | if (value.length === 0) return '[]' |
| 2648 | return `[${inferCompactSchema(value[0], depth - 1)}]` |
| 2649 | } |
| 2650 | if (typeof value === 'object') { |
| 2651 | if (depth <= 0) return '{...}' |
| 2652 | const entries = Object.entries(value).slice(0, 10) |
| 2653 | const props = entries.map( |
| 2654 | ([k, v]) => `${k}: ${inferCompactSchema(v, depth - 1)}`, |
| 2655 | ) |
| 2656 | const suffix = Object.keys(value).length > 10 ? ', ...' : '' |
| 2657 | return `{${props.join(', ')}${suffix}}` |
| 2658 | } |
| 2659 | return typeof value |
| 2660 | } |
| 2661 | |
| 2662 | export async function transformMCPResult( |
| 2663 | result: unknown, |
no test coverage detected