( originalSchema: ToolSchema, userProvidedParams: Record<string, unknown> )
| 823 | * Filters out user-provided parameters from tool schema for LLM |
| 824 | */ |
| 825 | export function filterSchemaForLLM( |
| 826 | originalSchema: ToolSchema, |
| 827 | userProvidedParams: Record<string, unknown> |
| 828 | ): ToolSchema { |
| 829 | if (!originalSchema || !originalSchema.properties) { |
| 830 | return originalSchema |
| 831 | } |
| 832 | |
| 833 | const filteredProperties = { ...originalSchema.properties } |
| 834 | const filteredRequired = [...(originalSchema.required || [])] |
| 835 | |
| 836 | // Remove user-provided parameters from the schema |
| 837 | Object.keys(userProvidedParams).forEach((paramKey) => { |
| 838 | if (isNonEmpty(userProvidedParams[paramKey])) { |
| 839 | delete filteredProperties[paramKey] |
| 840 | const reqIndex = filteredRequired.indexOf(paramKey) |
| 841 | if (reqIndex > -1) { |
| 842 | filteredRequired.splice(reqIndex, 1) |
| 843 | } |
| 844 | } |
| 845 | }) |
| 846 | |
| 847 | return { |
| 848 | ...originalSchema, |
| 849 | properties: filteredProperties, |
| 850 | required: filteredRequired, |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | /** |
| 855 | * Validates that all required parameters are provided |
no test coverage detected