(schema: Record<string, unknown>)
| 752 | * which reject schemas missing these constraints with an HTTP 400. |
| 753 | */ |
| 754 | export function enforceStrictSchema(schema: Record<string, unknown>): Record<string, unknown> { |
| 755 | if (!schema || typeof schema !== 'object') return schema |
| 756 | |
| 757 | const result = { ...schema } |
| 758 | |
| 759 | if (result.type === 'object') { |
| 760 | result.additionalProperties = false |
| 761 | |
| 762 | if (result.properties && typeof result.properties === 'object') { |
| 763 | const propKeys = Object.keys(result.properties as Record<string, unknown>) |
| 764 | result.required = propKeys |
| 765 | result.properties = Object.fromEntries( |
| 766 | Object.entries(result.properties as Record<string, unknown>).map(([key, value]) => [ |
| 767 | key, |
| 768 | enforceStrictSchema(value as Record<string, unknown>), |
| 769 | ]) |
| 770 | ) |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | if (result.type === 'array' && result.items) { |
| 775 | result.items = enforceStrictSchema(result.items as Record<string, unknown>) |
| 776 | } |
| 777 | |
| 778 | for (const keyword of ['anyOf', 'oneOf', 'allOf']) { |
| 779 | if (Array.isArray(result[keyword])) { |
| 780 | result[keyword] = (result[keyword] as Record<string, unknown>[]).map(enforceStrictSchema) |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | for (const defKey of ['$defs', 'definitions']) { |
| 785 | if (result[defKey] && typeof result[defKey] === 'object') { |
| 786 | result[defKey] = Object.fromEntries( |
| 787 | Object.entries(result[defKey] as Record<string, unknown>).map(([key, value]) => [ |
| 788 | key, |
| 789 | enforceStrictSchema(value as Record<string, unknown>), |
| 790 | ]) |
| 791 | ) |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | return result |
| 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Sums the `cost.total` from each tool result returned during a provider tool loop. |
no outgoing calls
no test coverage detected