@@ -38,6 +38,7 @@ import {
3838 supportsThinking ,
3939 supportsToolUsageControl ,
4040 supportsVerbosity ,
41+ transformBlockTool ,
4142 updateOllamaProviderModels ,
4243} from '@/providers/utils'
4344
@@ -1514,3 +1515,130 @@ describe('Provider/Model Blacklist', () => {
15141515 } )
15151516 } )
15161517} )
1518+
1519+ describe ( 'transformBlockTool multi-instance unique IDs' , ( ) => {
1520+ const tableBlockDef = {
1521+ type : 'table' ,
1522+ inputs : { } ,
1523+ subBlocks : [
1524+ { id : 'operation' , type : 'dropdown' } ,
1525+ { id : 'tableSelector' , type : 'table-selector' , canonicalParamId : 'tableId' , mode : 'basic' } ,
1526+ {
1527+ id : 'manualTableId' ,
1528+ type : 'short-input' ,
1529+ canonicalParamId : 'tableId' ,
1530+ mode : 'advanced' ,
1531+ } ,
1532+ ] ,
1533+ tools : {
1534+ access : [ 'table_query_rows' , 'table_insert_row' ] ,
1535+ config : { tool : ( ) => 'table_query_rows' } ,
1536+ } ,
1537+ }
1538+
1539+ const getAllBlocks = ( ) => [ tableBlockDef ]
1540+ const getTool = ( id : string ) => ( {
1541+ id,
1542+ name : 'Query Rows' ,
1543+ description : 'Query table rows' ,
1544+ params : { } ,
1545+ } )
1546+
1547+ const transformTable = (
1548+ params : Record < string , unknown > ,
1549+ canonicalModes ?: Record < string , 'basic' | 'advanced' >
1550+ ) =>
1551+ transformBlockTool (
1552+ { type : 'table' , operation : 'query_rows' , params } ,
1553+ { selectedOperation : 'query_rows' , getAllBlocks, getTool, canonicalModes }
1554+ )
1555+
1556+ it ( 'appends the table id when stored under the basic selector subblock key' , async ( ) => {
1557+ const result = await transformTable ( { tableSelector : 'tbl_abc' } )
1558+ expect ( result ?. id ) . toBe ( 'table_query_rows_tbl_abc' )
1559+ } )
1560+
1561+ it ( 'appends the table id resolved from the advanced manual input' , async ( ) => {
1562+ const result = await transformTable (
1563+ { manualTableId : 'tbl_xyz' } ,
1564+ { 'table:tableId' : 'advanced' }
1565+ )
1566+ expect ( result ?. id ) . toBe ( 'table_query_rows_tbl_xyz' )
1567+ } )
1568+
1569+ it ( 'appends the canonical table id when already present in params' , async ( ) => {
1570+ const result = await transformTable ( { tableId : 'tbl_direct' } )
1571+ expect ( result ?. id ) . toBe ( 'table_query_rows_tbl_direct' )
1572+ } )
1573+
1574+ it ( 'falls back to the base tool id when no table is selected' , async ( ) => {
1575+ const result = await transformTable ( { } )
1576+ expect ( result ?. id ) . toBe ( 'table_query_rows' )
1577+ } )
1578+ } )
1579+
1580+ describe ( 'transformBlockTool knowledge-base multi-instance unique IDs' , ( ) => {
1581+ const knowledgeBlockDef = {
1582+ type : 'knowledge' ,
1583+ inputs : { } ,
1584+ subBlocks : [
1585+ { id : 'operation' , type : 'dropdown' } ,
1586+ {
1587+ id : 'knowledgeBaseSelector' ,
1588+ type : 'knowledge-base-selector' ,
1589+ canonicalParamId : 'knowledgeBaseId' ,
1590+ mode : 'basic' ,
1591+ } ,
1592+ {
1593+ id : 'manualKnowledgeBaseId' ,
1594+ type : 'short-input' ,
1595+ canonicalParamId : 'knowledgeBaseId' ,
1596+ mode : 'advanced' ,
1597+ } ,
1598+ ] ,
1599+ tools : {
1600+ access : [ 'knowledge_search' , 'knowledge_upload_chunk' ] ,
1601+ config : { tool : ( ) => 'knowledge_search' } ,
1602+ } ,
1603+ }
1604+
1605+ const getAllBlocks = ( ) => [ knowledgeBlockDef ]
1606+ const getTool = ( id : string ) => ( {
1607+ id,
1608+ name : 'Search' ,
1609+ description : 'Search the knowledge base' ,
1610+ params : { } ,
1611+ } )
1612+
1613+ const transformKb = (
1614+ params : Record < string , unknown > ,
1615+ canonicalModes ?: Record < string , 'basic' | 'advanced' >
1616+ ) =>
1617+ transformBlockTool (
1618+ { type : 'knowledge' , operation : 'search' , params } ,
1619+ { selectedOperation : 'search' , getAllBlocks, getTool, canonicalModes }
1620+ )
1621+
1622+ it ( 'appends the knowledge base id when stored under the basic selector subblock key' , async ( ) => {
1623+ const result = await transformKb ( { knowledgeBaseSelector : 'kb_abc' } )
1624+ expect ( result ?. id ) . toBe ( 'knowledge_search_kb_abc' )
1625+ } )
1626+
1627+ it ( 'appends the knowledge base id resolved from the advanced manual input' , async ( ) => {
1628+ const result = await transformKb (
1629+ { manualKnowledgeBaseId : 'kb_xyz' } ,
1630+ { 'knowledge:knowledgeBaseId' : 'advanced' }
1631+ )
1632+ expect ( result ?. id ) . toBe ( 'knowledge_search_kb_xyz' )
1633+ } )
1634+
1635+ it ( 'appends the canonical knowledge base id when already present in params' , async ( ) => {
1636+ const result = await transformKb ( { knowledgeBaseId : 'kb_direct' } )
1637+ expect ( result ?. id ) . toBe ( 'knowledge_search_kb_direct' )
1638+ } )
1639+
1640+ it ( 'falls back to the base tool id when no knowledge base is selected' , async ( ) => {
1641+ const result = await transformKb ( { } )
1642+ expect ( result ?. id ) . toBe ( 'knowledge_search' )
1643+ } )
1644+ } )
0 commit comments