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

Function transformBlockTool

apps/sim/providers/utils.ts:521–685  ·  view source on GitHub ↗
(
  block: any,
  options: {
    selectedOperation?: string
    getAllBlocks: () => any[]
    getTool: (toolId: string) => any
    getToolAsync?: (toolId: string) => Promise<any>
    canonicalModes?: Record<string, 'basic' | 'advanced'>
  }
)

Source from the content-addressed store, hash-verified

519 * @returns The provider tool config or null if transform fails
520 */
521export async function transformBlockTool(
522 block: any,
523 options: {
524 selectedOperation?: string
525 getAllBlocks: () => any[]
526 getTool: (toolId: string) => any
527 getToolAsync?: (toolId: string) => Promise<any>
528 canonicalModes?: Record<string, 'basic' | 'advanced'>
529 }
530): Promise<ProviderToolConfig | null> {
531 const { selectedOperation, getAllBlocks, getTool, getToolAsync, canonicalModes } = options
532
533 const blockDef = getAllBlocks().find((b: any) => b.type === block.type)
534 if (!blockDef) {
535 logger.warn(`Block definition not found for type: ${block.type}`)
536 return null
537 }
538
539 let toolId: string | null = null
540
541 if ((blockDef.tools?.access?.length || 0) > 1) {
542 if (selectedOperation && blockDef.tools?.config?.tool) {
543 try {
544 toolId = blockDef.tools.config.tool({
545 ...block.params,
546 operation: selectedOperation,
547 })
548 } catch (error) {
549 logger.error('Error selecting tool for block', {
550 blockType: block.type,
551 operation: selectedOperation,
552 error,
553 })
554 return null
555 }
556 } else {
557 toolId = blockDef.tools.access[0]
558 }
559 } else {
560 toolId = blockDef.tools?.access?.[0] || null
561 }
562
563 if (!toolId) {
564 logger.warn(`No tool ID found for block: ${block.type}`)
565 return null
566 }
567
568 let toolConfig: any
569
570 if (isCustomTool(toolId) && getToolAsync) {
571 toolConfig = await getToolAsync(toolId)
572 } else {
573 toolConfig = getTool(toolId)
574 }
575
576 if (!toolConfig) {
577 logger.warn(`Tool config not found for ID: ${toolId}`)
578 return null

Callers 4

transformTableFunction · 0.90
transformKbFunction · 0.90
buildSimToolSpecsFunction · 0.90
transformBlockToolMethod · 0.90

Calls 13

isCustomToolFunction · 0.90
buildCanonicalIndexFunction · 0.90
getToolAsyncFunction · 0.85
createLLMToolSchemaFunction · 0.85
fetchWorkflowMetadataFunction · 0.85
errorMethod · 0.80
parseMethod · 0.80
getAllBlocksFunction · 0.70
getToolFunction · 0.70

Tested by 2

transformTableFunction · 0.72
transformKbFunction · 0.72