* Get the tool prefix (service name) from a tool name. * e.g., "calcom_list_schedules" -> "calcom"
(toolName: string)
| 1341 | * e.g., "calcom_list_schedules" -> "calcom" |
| 1342 | */ |
| 1343 | function getToolPrefixFromName(toolName: string): string { |
| 1344 | const parts = toolName.split('_') |
| 1345 | |
| 1346 | // Try to find a valid tool directory |
| 1347 | for (let i = parts.length - 1; i >= 1; i--) { |
| 1348 | const possiblePrefix = parts.slice(0, i).join('_') |
| 1349 | const toolDirPath = path.join(rootDir, `apps/sim/tools/${possiblePrefix}`) |
| 1350 | |
| 1351 | if (fs.existsSync(toolDirPath) && fs.statSync(toolDirPath).isDirectory()) { |
| 1352 | return possiblePrefix |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | return parts[0] |
| 1357 | } |
| 1358 | |
| 1359 | /** |
| 1360 | * Resolve a const reference from a types file. |