@@ -20,6 +20,7 @@ import { Operation, z, type JSONSchema7 } from '@genkit-ai/core';
20
20
import * as assert from 'assert' ;
21
21
import { beforeEach , describe , it } from 'node:test' ;
22
22
import { modelRef } from '../../ai/src/model' ;
23
+ import { interrupt } from '../../ai/src/tool' ;
23
24
import {
24
25
dynamicResource ,
25
26
dynamicTool ,
@@ -956,6 +957,10 @@ describe('generate', () => {
956
957
return interrupt ( ) ;
957
958
}
958
959
) ;
960
+ const dynamicInterrupt = interrupt ( {
961
+ name : 'dynamicInterrupt' ,
962
+ description : 'description' ,
963
+ } ) ;
959
964
960
965
// first response is a tool call, the subsequent responses are just text response from agent b.
961
966
let reqCounter = 0 ;
@@ -990,6 +995,13 @@ describe('generate', () => {
990
995
ref : 'ref789' ,
991
996
} ,
992
997
} ,
998
+ {
999
+ toolRequest : {
1000
+ name : 'dynamicInterrupt' ,
1001
+ input : { doIt : true } ,
1002
+ ref : 'ref890' ,
1003
+ } ,
1004
+ } ,
993
1005
]
994
1006
: [ { text : 'done' } ] ,
995
1007
} ,
@@ -998,7 +1010,12 @@ describe('generate', () => {
998
1010
999
1011
const response = await ai . generate ( {
1000
1012
prompt : 'call the tool' ,
1001
- tools : [ 'interruptingTool' , 'simpleTool' , 'resumableTool' ] ,
1013
+ tools : [
1014
+ 'interruptingTool' ,
1015
+ 'simpleTool' ,
1016
+ 'resumableTool' ,
1017
+ dynamicInterrupt ,
1018
+ ] ,
1002
1019
} ) ;
1003
1020
1004
1021
assert . strictEqual ( reqCounter , 1 ) ;
@@ -1039,6 +1056,16 @@ describe('generate', () => {
1039
1056
} ,
1040
1057
} ,
1041
1058
} ,
1059
+ {
1060
+ metadata : { interrupt : true } ,
1061
+ toolRequest : {
1062
+ input : {
1063
+ doIt : true ,
1064
+ } ,
1065
+ name : 'dynamicInterrupt' ,
1066
+ ref : 'ref890' ,
1067
+ } ,
1068
+ } ,
1042
1069
] ) ;
1043
1070
assert . deepStrictEqual ( response . message ?. toJSON ( ) , {
1044
1071
role : 'model' ,
@@ -1082,6 +1109,16 @@ describe('generate', () => {
1082
1109
} ,
1083
1110
} ,
1084
1111
} ,
1112
+ {
1113
+ metadata : { interrupt : true } ,
1114
+ toolRequest : {
1115
+ input : {
1116
+ doIt : true ,
1117
+ } ,
1118
+ name : 'dynamicInterrupt' ,
1119
+ ref : 'ref890' ,
1120
+ } ,
1121
+ } ,
1085
1122
] ,
1086
1123
} ) ;
1087
1124
assert . deepStrictEqual ( pm . lastRequest , {
@@ -1124,6 +1161,16 @@ describe('generate', () => {
1124
1161
$schema : 'http://json-schema.org/draft-07/schema#' ,
1125
1162
} ,
1126
1163
} ,
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
+ } ,
1127
1174
] ,
1128
1175
} ) ;
1129
1176
} ) ;
0 commit comments