@@ -20,6 +20,7 @@ import { Operation, z, type JSONSchema7 } from '@genkit-ai/core';
2020import * as assert from 'assert' ;
2121import { beforeEach , describe , it } from 'node:test' ;
2222import { modelRef } from '../../ai/src/model' ;
23+ import { interrupt } from '../../ai/src/tool' ;
2324import {
2425 dynamicResource ,
2526 dynamicTool ,
@@ -956,6 +957,10 @@ describe('generate', () => {
956957 return interrupt ( ) ;
957958 }
958959 ) ;
960+ const dynamicInterrupt = interrupt ( {
961+ name : 'dynamicInterrupt' ,
962+ description : 'description' ,
963+ } ) ;
959964
960965 // first response is a tool call, the subsequent responses are just text response from agent b.
961966 let reqCounter = 0 ;
@@ -990,6 +995,13 @@ describe('generate', () => {
990995 ref : 'ref789' ,
991996 } ,
992997 } ,
998+ {
999+ toolRequest : {
1000+ name : 'dynamicInterrupt' ,
1001+ input : { doIt : true } ,
1002+ ref : 'ref890' ,
1003+ } ,
1004+ } ,
9931005 ]
9941006 : [ { text : 'done' } ] ,
9951007 } ,
@@ -998,7 +1010,12 @@ describe('generate', () => {
9981010
9991011 const response = await ai . generate ( {
10001012 prompt : 'call the tool' ,
1001- tools : [ 'interruptingTool' , 'simpleTool' , 'resumableTool' ] ,
1013+ tools : [
1014+ 'interruptingTool' ,
1015+ 'simpleTool' ,
1016+ 'resumableTool' ,
1017+ dynamicInterrupt ,
1018+ ] ,
10021019 } ) ;
10031020
10041021 assert . strictEqual ( reqCounter , 1 ) ;
@@ -1039,6 +1056,16 @@ describe('generate', () => {
10391056 } ,
10401057 } ,
10411058 } ,
1059+ {
1060+ metadata : { interrupt : true } ,
1061+ toolRequest : {
1062+ input : {
1063+ doIt : true ,
1064+ } ,
1065+ name : 'dynamicInterrupt' ,
1066+ ref : 'ref890' ,
1067+ } ,
1068+ } ,
10421069 ] ) ;
10431070 assert . deepStrictEqual ( response . message ?. toJSON ( ) , {
10441071 role : 'model' ,
@@ -1082,6 +1109,16 @@ describe('generate', () => {
10821109 } ,
10831110 } ,
10841111 } ,
1112+ {
1113+ metadata : { interrupt : true } ,
1114+ toolRequest : {
1115+ input : {
1116+ doIt : true ,
1117+ } ,
1118+ name : 'dynamicInterrupt' ,
1119+ ref : 'ref890' ,
1120+ } ,
1121+ } ,
10851122 ] ,
10861123 } ) ;
10871124 assert . deepStrictEqual ( pm . lastRequest , {
@@ -1124,6 +1161,16 @@ describe('generate', () => {
11241161 $schema : 'http://json-schema.org/draft-07/schema#' ,
11251162 } ,
11261163 } ,
1164+ {
1165+ description : 'description' ,
1166+ inputSchema : {
1167+ $schema : 'http://json-schema.org/draft-07/schema#' ,
1168+ } ,
1169+ name : 'dynamicInterrupt' ,
1170+ outputSchema : {
1171+ $schema : 'http://json-schema.org/draft-07/schema#' ,
1172+ } ,
1173+ } ,
11271174 ] ,
11281175 } ) ;
11291176 } ) ;
0 commit comments