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

Function trackForcedToolUsage

apps/sim/providers/utils.ts:1060–1177  ·  view source on GitHub ↗
(
  toolCallsResponse: any[] | undefined,
  originalToolChoice: any,
  logger: any,
  provider?: string,
  forcedTools: string[] = [],
  usedForcedTools: string[] = []
)

Source from the content-addressed store, hash-verified

1058 * @returns Object containing tracking information and next tool choice
1059 */
1060export function trackForcedToolUsage(
1061 toolCallsResponse: any[] | undefined,
1062 originalToolChoice: any,
1063 logger: any,
1064 provider?: string,
1065 forcedTools: string[] = [],
1066 usedForcedTools: string[] = []
1067): {
1068 hasUsedForcedTool: boolean
1069 usedForcedTools: string[]
1070 nextToolChoice?:
1071 | 'auto'
1072 | { type: 'function'; function: { name: string } }
1073 | { type: 'tool'; name: string }
1074 | { type: 'any'; any: { model: string; name: string } }
1075 | null
1076 nextToolConfig?: {
1077 functionCallingConfig: {
1078 mode: 'AUTO' | 'ANY' | 'NONE'
1079 allowedFunctionNames?: string[]
1080 }
1081 }
1082} {
1083 let hasUsedForcedTool = false
1084 let nextToolChoice = originalToolChoice
1085 let nextToolConfig:
1086 | {
1087 functionCallingConfig: {
1088 mode: 'AUTO' | 'ANY' | 'NONE'
1089 allowedFunctionNames?: string[]
1090 }
1091 }
1092 | undefined
1093
1094 const updatedUsedForcedTools = [...usedForcedTools]
1095
1096 const isGoogleFormat = provider === 'google'
1097
1098 let forcedToolNames: string[] = []
1099 if (isGoogleFormat && originalToolChoice?.functionCallingConfig?.allowedFunctionNames) {
1100 forcedToolNames = originalToolChoice.functionCallingConfig.allowedFunctionNames
1101 } else if (
1102 typeof originalToolChoice === 'object' &&
1103 (originalToolChoice?.function?.name ||
1104 (originalToolChoice?.type === 'tool' && originalToolChoice?.name) ||
1105 (originalToolChoice?.type === 'any' && originalToolChoice?.any?.name))
1106 ) {
1107 forcedToolNames = [
1108 originalToolChoice?.function?.name ||
1109 originalToolChoice?.name ||
1110 originalToolChoice?.any?.name,
1111 ].filter(Boolean)
1112 }
1113
1114 if (forcedToolNames.length > 0 && toolCallsResponse && toolCallsResponse.length > 0) {
1115 const toolNames = toolCallsResponse.map((tc) => tc.function?.name || tc.name || tc.id)
1116
1117 const toolNameSet = new Set(toolNames)

Callers 11

checkForForcedToolUsageFunction · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
checkForForcedToolUsageFunction · 0.90
index.tsFile · 0.90
checkForForcedToolUsageFunction · 0.90
checkForForcedToolUsageFunction · 0.90
checkForForcedToolUsageFunction · 0.90
checkForForcedToolUsageFunction · 0.90
index.tsFile · 0.90

Calls 3

infoMethod · 0.80
joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected