@@ -3,7 +3,7 @@ import type { ChatCompletionChunk } from 'openai/resources/chat/completions'
33import type { CompletionUsage } from 'openai/resources/completions'
44import { env } from '@/lib/core/config/env'
55import { isHosted } from '@/lib/core/config/feature-flags'
6- import { enrichTableToolDescription , enrichTableToolParameters } from '@/lib/table/llm'
6+ import { enrichTableToolForLLM } from '@/lib/table/llm'
77import { isCustomTool } from '@/executor/constants'
88import {
99 getComputerUseModels ,
@@ -497,60 +497,34 @@ export async function transformBlockTool(
497497 uniqueToolId = `${ toolConfig . id } _${ userProvidedParams . knowledgeBaseId } `
498498 }
499499
500- // Enrich table tool descriptions with schema information
501- let enrichedDescription = toolConfig . description
502- let enrichedLlmSchema = llmSchema
503- if (
504- toolId . startsWith ( 'table_' ) &&
505- userProvidedParams . tableId &&
506- workspaceId &&
507- workflowId &&
508- executeTool
509- ) {
510- try {
511- logger . info ( `[transformBlockTool] Fetching schema for table ${ userProvidedParams . tableId } ` )
512- const schemaResult = await executeTool ( 'table_get_schema' , {
513- tableId : userProvidedParams . tableId ,
514- _context : { workspaceId, workflowId } ,
515- } )
516-
517- if ( schemaResult . success && schemaResult . output ) {
518- const tableSchema = {
519- name : schemaResult . output . name ,
520- columns : schemaResult . output . columns || [ ] ,
521- }
522-
523- // Enrich description and parameters using lib/table utilities
524- enrichedDescription = enrichTableToolDescription (
525- toolConfig . description ,
526- tableSchema ,
527- toolId
528- )
529- const enrichedParams = enrichTableToolParameters ( llmSchema , tableSchema , toolId )
530- enrichedLlmSchema = {
531- ...llmSchema ,
532- properties : enrichedParams . properties ,
533- required :
534- enrichedParams . required . length > 0 ? enrichedParams . required : llmSchema . required ,
535- }
536-
537- logger . info (
538- `[transformBlockTool] Enriched ${ toolId } with ${ tableSchema . columns . length } columns`
539- )
540- } else {
541- logger . warn ( `[transformBlockTool] Failed to fetch table schema: ${ schemaResult . error } ` )
500+ // Apply table tool enrichment if applicable
501+ let finalDescription = toolConfig . description
502+ let finalSchema = llmSchema
503+
504+ if ( toolId . startsWith ( 'table_' ) && workspaceId && workflowId && executeTool ) {
505+ const result = await enrichTableToolForLLM (
506+ toolId ,
507+ toolConfig . description ,
508+ llmSchema ,
509+ userProvidedParams ,
510+ {
511+ workspaceId,
512+ workflowId,
513+ executeTool,
542514 }
543- } catch ( error ) {
544- logger . warn ( `[transformBlockTool] Error fetching table schema:` , error )
515+ )
516+ if ( result ) {
517+ finalDescription = result . description
518+ finalSchema = { ...llmSchema , ...result . parameters }
545519 }
546520 }
547521
548522 return {
549523 id : uniqueToolId ,
550524 name : toolConfig . name ,
551- description : enrichedDescription ,
525+ description : finalDescription ,
552526 params : userProvidedParams ,
553- parameters : enrichedLlmSchema ,
527+ parameters : finalSchema ,
554528 }
555529}
556530
0 commit comments