@@ -24,6 +24,8 @@ import {
2424 defineTool ,
2525 isDynamicTool ,
2626 isMultipartTool ,
27+ restartTool ,
28+ respondTool ,
2729 tool ,
2830} from '../src/tool.js' ;
2931
@@ -458,3 +460,66 @@ describe('defineTool', () => {
458460 assert . deepStrictEqual ( result , { output : 'foo' } ) ;
459461 } ) ;
460462} ) ;
463+
464+ describe ( 'respondTool' , ( ) => {
465+ it ( 'constructs a ToolResponsePart standalone' , ( ) => {
466+ const interrupt = { toolRequest : { name : 'test' , input : { } } } ;
467+ assert . deepStrictEqual ( respondTool ( interrupt , 'output' ) , {
468+ toolResponse : {
469+ name : 'test' ,
470+ output : 'output' ,
471+ } ,
472+ metadata : {
473+ interruptResponse : true ,
474+ } ,
475+ } ) ;
476+ } ) ;
477+
478+ it ( 'includes metadata standalone' , ( ) => {
479+ const interrupt = { toolRequest : { name : 'test' , input : { } } } ;
480+ assert . deepStrictEqual (
481+ respondTool ( interrupt , 'output' , { metadata : { extra : 'data' } } ) ,
482+ {
483+ toolResponse : {
484+ name : 'test' ,
485+ output : 'output' ,
486+ } ,
487+ metadata : {
488+ interruptResponse : { extra : 'data' } ,
489+ } ,
490+ }
491+ ) ;
492+ } ) ;
493+ } ) ;
494+
495+ describe ( 'restartTool' , ( ) => {
496+ it ( 'constructs a ToolRequestPart standalone' , ( ) => {
497+ const interrupt = { toolRequest : { name : 'test' , input : { } } } ;
498+ assert . deepStrictEqual ( restartTool ( interrupt ) , {
499+ toolRequest : {
500+ name : 'test' ,
501+ input : { } ,
502+ } ,
503+ metadata : {
504+ resumed : true ,
505+ } ,
506+ } ) ;
507+ } ) ;
508+
509+ it ( 'allows replacing input standalone' , ( ) => {
510+ const interrupt = { toolRequest : { name : 'test' , input : { } } } ;
511+ assert . deepStrictEqual (
512+ restartTool ( interrupt , undefined , { replaceInput : 'new' } ) ,
513+ {
514+ toolRequest : {
515+ name : 'test' ,
516+ input : 'new' ,
517+ } ,
518+ metadata : {
519+ resumed : true ,
520+ replacedInput : { } ,
521+ } ,
522+ }
523+ ) ;
524+ } ) ;
525+ } ) ;
0 commit comments