MCPcopy Index your code
hub / github.com/simstudioai/sim / mergeToolParameters

Function mergeToolParameters

apps/sim/tools/params.ts:778–820  ·  view source on GitHub ↗
(
  userProvidedParams: Record<string, unknown>,
  llmGeneratedParams: Record<string, unknown>
)

Source from the content-addressed store, hash-verified

776 * fields that user left empty in the UI.
777 */
778export function mergeToolParameters(
779 userProvidedParams: Record<string, unknown>,
780 llmGeneratedParams: Record<string, unknown>
781): Record<string, unknown> {
782 // Filter out empty and effectively-empty values from user-provided params
783 // so that cleared fields don't override LLM values
784 const filteredUserParams: Record<string, unknown> = {}
785 for (const [key, value] of Object.entries(userProvidedParams)) {
786 if (isNonEmpty(value)) {
787 // Skip tag-based params if they're effectively empty (only default/unfilled entries)
788 if ((key === 'documentTags' || key === 'tagFilters') && isEmptyTagValue(value)) {
789 continue
790 }
791 filteredUserParams[key] = value
792 }
793 }
794
795 // Start with LLM params as base
796 const result: Record<string, unknown> = { ...llmGeneratedParams }
797
798 // Apply user params, with special handling for inputMapping
799 for (const [key, userValue] of Object.entries(filteredUserParams)) {
800 if (key === 'inputMapping') {
801 // Deep merge inputMapping so LLM values fill in empty user fields
802 const llmInputMapping = llmGeneratedParams.inputMapping as Record<string, unknown> | undefined
803 const mergedInputMapping = deepMergeInputMapping(
804 llmInputMapping,
805 userValue as Record<string, unknown> | string | undefined
806 )
807 result.inputMapping = mergedInputMapping
808 } else {
809 // Normal override for other params
810 result[key] = userValue
811 }
812 }
813
814 // If LLM provided inputMapping but user didn't, ensure it's included
815 if (llmGeneratedParams.inputMapping && !filteredUserParams.inputMapping) {
816 result.inputMapping = llmGeneratedParams.inputMapping
817 }
818
819 return result
820}
821
822/**
823 * Filters out user-provided parameters from tool schema for LLM

Callers 2

params.test.tsFile · 0.90
prepareToolExecutionFunction · 0.90

Calls 3

isEmptyTagValueFunction · 0.90
isNonEmptyFunction · 0.85
deepMergeInputMappingFunction · 0.85

Tested by

no test coverage detected