55 * with table-specific information so LLMs can construct proper queries.
66 */
77
8- /**
9- * Table schema information used for LLM enrichment.
10- */
11- export interface TableSchemaInfo {
12- name : string
13- columns : Array < { name : string ; type : string } >
14- }
8+ import type { TableSummary } from '../types'
159
1610/**
1711 * Operations that use filters and need filter-specific enrichment.
@@ -33,28 +27,28 @@ export const DATA_OPERATIONS = new Set([
3327] )
3428
3529/**
36- * Enriches a table tool description with schema information based on the operation type.
30+ * Enriches a table tool description with table information based on the operation type.
3731 *
3832 * @param originalDescription - The original tool description
39- * @param tableSchema - The table schema with name and columns
33+ * @param table - The table summary with name and columns
4034 * @param toolId - The tool identifier to determine operation type
4135 * @returns Enriched description with table-specific instructions
4236 */
4337export function enrichTableToolDescription (
4438 originalDescription : string ,
45- tableSchema : TableSchemaInfo ,
39+ table : TableSummary ,
4640 toolId : string
4741) : string {
48- if ( ! tableSchema . columns || tableSchema . columns . length === 0 ) {
42+ if ( ! table . columns || table . columns . length === 0 ) {
4943 return originalDescription
5044 }
5145
52- const columnList = tableSchema . columns . map ( ( col ) => ` - ${ col . name } (${ col . type } )` ) . join ( '\n' )
46+ const columnList = table . columns . map ( ( col ) => ` - ${ col . name } (${ col . type } )` ) . join ( '\n' )
5347
5448 // Filter-based operations: emphasize filter usage
5549 if ( FILTER_OPERATIONS . has ( toolId ) ) {
56- const stringCols = tableSchema . columns . filter ( ( c ) => c . type === 'string' )
57- const numberCols = tableSchema . columns . filter ( ( c ) => c . type === 'number' )
50+ const stringCols = table . columns . filter ( ( c ) => c . type === 'string' )
51+ const numberCols = table . columns . filter ( ( c ) => c . type === 'number' )
5852
5953 let filterExample = ''
6054 if ( stringCols . length > 0 && numberCols . length > 0 ) {
@@ -96,14 +90,14 @@ INSTRUCTIONS:
9690 return `${ originalDescription }
9791${ queryInstructions }
9892
99- Table "${ tableSchema . name } " columns:
93+ Table "${ table . name } " columns:
10094${ columnList }
10195${ filterExample } ${ sortExample } `
10296 }
10397
10498 // Data operations: show columns for data construction
10599 if ( DATA_OPERATIONS . has ( toolId ) ) {
106- const exampleCols = tableSchema . columns . slice ( 0 , 3 )
100+ const exampleCols = table . columns . slice ( 0 , 3 )
107101 const dataExample = exampleCols . reduce (
108102 ( obj , col ) => {
109103 obj [ col . name ] = col . type === 'number' ? 123 : col . type === 'boolean' ? true : 'example'
@@ -114,7 +108,7 @@ ${filterExample}${sortExample}`
114108
115109 return `${ originalDescription }
116110
117- Table "${ tableSchema . name } " available columns:
111+ Table "${ table . name } " available columns:
118112${ columnList }
119113
120114Pass the "data" parameter with an object like: ${ JSON . stringify ( dataExample ) } `
@@ -123,31 +117,31 @@ Pass the "data" parameter with an object like: ${JSON.stringify(dataExample)}`
123117 // Default: just show columns
124118 return `${ originalDescription }
125119
126- Table "${ tableSchema . name } " columns:
120+ Table "${ table . name } " columns:
127121${ columnList } `
128122}
129123
130124/**
131125 * Enriches LLM tool parameters with table-specific information.
132126 *
133127 * @param llmSchema - The original LLM schema with properties and required fields
134- * @param tableSchema - The table schema with name and columns
128+ * @param table - The table summary with name and columns
135129 * @param toolId - The tool identifier to determine operation type
136130 * @returns Enriched schema with updated property descriptions and required fields
137131 */
138132export function enrichTableToolParameters (
139133 llmSchema : { properties ?: Record < string , any > ; required ?: string [ ] } ,
140- tableSchema : TableSchemaInfo ,
134+ table : TableSummary ,
141135 toolId : string
142136) : { properties : Record < string , any > ; required : string [ ] } {
143- if ( ! tableSchema . columns || tableSchema . columns . length === 0 ) {
137+ if ( ! table . columns || table . columns . length === 0 ) {
144138 return {
145139 properties : llmSchema . properties || { } ,
146140 required : llmSchema . required || [ ] ,
147141 }
148142 }
149143
150- const columnNames = tableSchema . columns . map ( ( c ) => c . name ) . join ( ', ' )
144+ const columnNames = table . columns . map ( ( c ) => c . name ) . join ( ', ' )
151145 const enrichedProperties = { ...llmSchema . properties }
152146 const enrichedRequired = llmSchema . required ? [ ...llmSchema . required ] : [ ]
153147
@@ -182,7 +176,7 @@ export function enrichTableToolParameters(
182176
183177 // Enrich data parameter for insert/update operations
184178 if ( enrichedProperties . data && DATA_OPERATIONS . has ( toolId ) ) {
185- const exampleCols = tableSchema . columns . slice ( 0 , 2 )
179+ const exampleCols = table . columns . slice ( 0 , 2 )
186180 const exampleData = exampleCols . reduce (
187181 ( obj : Record < string , unknown > , col : { name : string ; type : string } ) => {
188182 obj [ col . name ] = col . type === 'number' ? 123 : col . type === 'boolean' ? true : 'value'
0 commit comments