@@ -1905,51 +1905,37 @@ describe('AgentBlockHandler', () => {
19051905 describe ( 'customToolId resolution - DB as source of truth' , ( ) => {
19061906 const staleInlineSchema = {
19071907 function : {
1908- name : 'buttonTemplate ' ,
1909- description : 'Creates a button template ' ,
1908+ name : 'formatReport ' ,
1909+ description : 'Formats a report ' ,
19101910 parameters : {
19111911 type : 'object' ,
19121912 properties : {
1913- sender_id : { type : 'string' , description : 'Sender ID' } ,
1914- header_value : { type : 'string' , description : 'Header text' } ,
1915- body_value : { type : 'string' , description : 'Body text' } ,
1916- button_array : {
1917- type : 'array' ,
1918- items : { type : 'string' } ,
1919- description : 'Button labels' ,
1920- } ,
1913+ title : { type : 'string' , description : 'Report title' } ,
1914+ content : { type : 'string' , description : 'Report content' } ,
19211915 } ,
1922- required : [ 'sender_id ' , 'header_value' , 'body_value' , 'button_array '] ,
1916+ required : [ 'title ' , 'content ' ] ,
19231917 } ,
19241918 } ,
19251919 }
19261920
19271921 const dbSchema = {
19281922 function : {
1929- name : 'buttonTemplate ' ,
1930- description : 'Creates a button template ' ,
1923+ name : 'formatReport ' ,
1924+ description : 'Formats a report ' ,
19311925 parameters : {
19321926 type : 'object' ,
19331927 properties : {
1934- sender_id : { type : 'string' , description : 'Sender ID' } ,
1935- header_value : { type : 'string' , description : 'Header text' } ,
1936- body_value : { type : 'string' , description : 'Body text' } ,
1937- button_array : {
1938- type : 'array' ,
1939- items : { type : 'string' } ,
1940- description : 'Button labels' ,
1941- } ,
1942- channel : { type : 'string' , description : 'Channel name' } ,
1928+ title : { type : 'string' , description : 'Report title' } ,
1929+ content : { type : 'string' , description : 'Report content' } ,
1930+ format : { type : 'string' , description : 'Output format' } ,
19431931 } ,
1944- required : [ 'sender_id ' , 'header_value ' , 'body_value' , 'button_array' , 'channel '] ,
1932+ required : [ 'title ' , 'content ' , 'format ' ] ,
19451933 } ,
19461934 } ,
19471935 }
19481936
1949- const staleInlineCode =
1950- 'return JSON.stringify({ type: "button", phone: sender_id, header: header_value, body: body_value, buttons: button_array });'
1951- const dbCode =
1952- 'if (channel === "whatsapp") { return JSON.stringify({ type: "button", phone: sender_id, header: header_value, body: body_value, buttons: button_array }); }'
1937+ const staleInlineCode = 'return { title, content };'
1938+ const dbCode = 'return { title, content, format };'
19531939
19541940 function mockFetchForCustomTool ( toolId : string ) {
19551941 mockFetch . mockImplementation ( ( url : string ) => {
@@ -1962,7 +1948,7 @@ describe('AgentBlockHandler', () => {
19621948 data : [
19631949 {
19641950 id : toolId ,
1965- title : 'buttonTemplate ' ,
1951+ title : 'formatReport ' ,
19661952 schema : dbSchema ,
19671953 code : dbCode ,
19681954 } ,
@@ -2010,13 +1996,13 @@ describe('AgentBlockHandler', () => {
20101996
20111997 const inputs = {
20121998 model : 'gpt-4o' ,
2013- userPrompt : 'Send a button template ' ,
1999+ userPrompt : 'Format a report ' ,
20142000 apiKey : 'test-api-key' ,
20152001 tools : [
20162002 {
20172003 type : 'custom-tool' ,
20182004 customToolId : toolId ,
2019- title : 'buttonTemplate ' ,
2005+ title : 'formatReport ' ,
20202006 schema : staleInlineSchema ,
20212007 code : staleInlineCode ,
20222008 usageControl : 'auto' as const ,
@@ -2033,9 +2019,9 @@ describe('AgentBlockHandler', () => {
20332019 const tools = providerCall [ 1 ] . tools
20342020
20352021 expect ( tools . length ) . toBe ( 1 )
2036- // DB schema wins over stale inline — includes channel param
2037- expect ( tools [ 0 ] . parameters . required ) . toContain ( 'channel ' )
2038- expect ( tools [ 0 ] . parameters . properties ) . toHaveProperty ( 'channel ' )
2022+ // DB schema wins over stale inline — includes format param
2023+ expect ( tools [ 0 ] . parameters . required ) . toContain ( 'format ' )
2024+ expect ( tools [ 0 ] . parameters . properties ) . toHaveProperty ( 'format ' )
20392025 } )
20402026
20412027 it ( 'should fetch from DB when customToolId has no inline schema' , async ( ) => {
@@ -2044,7 +2030,7 @@ describe('AgentBlockHandler', () => {
20442030
20452031 const inputs = {
20462032 model : 'gpt-4o' ,
2047- userPrompt : 'Send a button template ' ,
2033+ userPrompt : 'Format a report ' ,
20482034 apiKey : 'test-api-key' ,
20492035 tools : [
20502036 {
@@ -2064,22 +2050,22 @@ describe('AgentBlockHandler', () => {
20642050 const tools = providerCall [ 1 ] . tools
20652051
20662052 expect ( tools . length ) . toBe ( 1 )
2067- expect ( tools [ 0 ] . name ) . toBe ( 'buttonTemplate ' )
2068- expect ( tools [ 0 ] . parameters . required ) . toContain ( 'channel ' )
2053+ expect ( tools [ 0 ] . name ) . toBe ( 'formatReport ' )
2054+ expect ( tools [ 0 ] . parameters . required ) . toContain ( 'format ' )
20692055 } )
20702056
20712057 it ( 'should fall back to inline schema when DB fetch fails and inline exists' , async ( ) => {
20722058 mockFetchFailure ( )
20732059
20742060 const inputs = {
20752061 model : 'gpt-4o' ,
2076- userPrompt : 'Send a button template ' ,
2062+ userPrompt : 'Format a report ' ,
20772063 apiKey : 'test-api-key' ,
20782064 tools : [
20792065 {
20802066 type : 'custom-tool' ,
20812067 customToolId : 'custom-tool-123' ,
2082- title : 'buttonTemplate ' ,
2068+ title : 'formatReport ' ,
20832069 schema : staleInlineSchema ,
20842070 code : staleInlineCode ,
20852071 usageControl : 'auto' as const ,
@@ -2095,18 +2081,17 @@ describe('AgentBlockHandler', () => {
20952081 const providerCall = mockExecuteProviderRequest . mock . calls [ 0 ]
20962082 const tools = providerCall [ 1 ] . tools
20972083
2098- // Falls back to inline schema (4 params, no channel)
20992084 expect ( tools . length ) . toBe ( 1 )
2100- expect ( tools [ 0 ] . name ) . toBe ( 'buttonTemplate ' )
2101- expect ( tools [ 0 ] . parameters . required ) . not . toContain ( 'channel ' )
2085+ expect ( tools [ 0 ] . name ) . toBe ( 'formatReport ' )
2086+ expect ( tools [ 0 ] . parameters . required ) . not . toContain ( 'format ' )
21022087 } )
21032088
21042089 it ( 'should return null when DB fetch fails and no inline schema exists' , async ( ) => {
21052090 mockFetchFailure ( )
21062091
21072092 const inputs = {
21082093 model : 'gpt-4o' ,
2109- userPrompt : 'Send a button template ' ,
2094+ userPrompt : 'Format a report ' ,
21102095 apiKey : 'test-api-key' ,
21112096 tools : [
21122097 {
@@ -2145,13 +2130,13 @@ describe('AgentBlockHandler', () => {
21452130
21462131 const inputs = {
21472132 model : 'gpt-4o' ,
2148- userPrompt : 'Send a button template ' ,
2133+ userPrompt : 'Format a report ' ,
21492134 apiKey : 'test-api-key' ,
21502135 tools : [
21512136 {
21522137 type : 'custom-tool' ,
21532138 customToolId : toolId ,
2154- title : 'buttonTemplate ' ,
2139+ title : 'formatReport ' ,
21552140 schema : staleInlineSchema ,
21562141 code : staleInlineCode ,
21572142 usageControl : 'auto' as const ,
@@ -2166,9 +2151,8 @@ describe('AgentBlockHandler', () => {
21662151 expect ( capturedTools . length ) . toBe ( 1 )
21672152 expect ( typeof capturedTools [ 0 ] . executeFunction ) . toBe ( 'function' )
21682153
2169- await capturedTools [ 0 ] . executeFunction ( { sender_id : '123 ' , channel : 'whatsapp ' } )
2154+ await capturedTools [ 0 ] . executeFunction ( { title : 'Q1 ' , format : 'pdf ' } )
21702155
2171- // Should use DB code, not stale inline code
21722156 expect ( mockExecuteTool ) . toHaveBeenCalledWith (
21732157 'function_execute' ,
21742158 expect . objectContaining ( {
@@ -2187,7 +2171,7 @@ describe('AgentBlockHandler', () => {
21872171 tools : [
21882172 {
21892173 type : 'custom-tool' ,
2190- title : 'inlineTool ' ,
2174+ title : 'formatReport ' ,
21912175 schema : staleInlineSchema ,
21922176 code : staleInlineCode ,
21932177 usageControl : 'auto' as const ,
@@ -2209,8 +2193,8 @@ describe('AgentBlockHandler', () => {
22092193 const tools = providerCall [ 1 ] . tools
22102194
22112195 expect ( tools . length ) . toBe ( 1 )
2212- expect ( tools [ 0 ] . name ) . toBe ( 'buttonTemplate ' )
2213- expect ( tools [ 0 ] . parameters . required ) . not . toContain ( 'channel ' )
2196+ expect ( tools [ 0 ] . name ) . toBe ( 'formatReport ' )
2197+ expect ( tools [ 0 ] . parameters . required ) . not . toContain ( 'format ' )
22142198 } )
22152199 } )
22162200 } )
0 commit comments