@@ -55,6 +55,7 @@ import type {
5555 StringInputToolSchema ,
5656 ToolInterface ,
5757 ToolOutputType ,
58+ ToolRuntime ,
5859} from "./types.js" ;
5960import { type JSONSchema , validatesOnlyStrings } from "../utils/json_schema.js" ;
6061
@@ -79,6 +80,7 @@ export {
7980 isRunnableToolLike ,
8081 isStructuredTool ,
8182 isStructuredToolParams ,
83+ type ToolRuntime ,
8284} from "./types.js" ;
8385
8486export { ToolInputParsingException } ;
@@ -635,6 +637,98 @@ export function tool<
635637> (
636638 func : RunnableFunc < SchemaOutputT , ToolOutputT , ToolRunnableConfig > ,
637639 fields : ToolWrapperParams < SchemaT >
640+ ) :
641+ | DynamicStructuredTool < SchemaT , SchemaOutputT , SchemaInputT , ToolOutputT >
642+ | DynamicTool < ToolOutputT > ;
643+
644+ // Overloads with ToolRuntime as CallOptions
645+ export function tool <
646+ SchemaT extends ZodStringV3 ,
647+ ToolOutputT = ToolOutputType ,
648+ TState = unknown ,
649+ TContext = unknown
650+ > (
651+ func : (
652+ input : InferInteropZodOutput < SchemaT > ,
653+ runtime : ToolRuntime < TState , TContext >
654+ ) => ToolOutputT | Promise < ToolOutputT > ,
655+ fields : ToolWrapperParams < SchemaT >
656+ ) : DynamicTool < ToolOutputT > ;
657+
658+ export function tool <
659+ SchemaT extends ZodStringV4 ,
660+ ToolOutputT = ToolOutputType ,
661+ TState = unknown ,
662+ TContext = unknown
663+ > (
664+ func : (
665+ input : InferInteropZodOutput < SchemaT > ,
666+ runtime : ToolRuntime < TState , TContext >
667+ ) => ToolOutputT | Promise < ToolOutputT > ,
668+ fields : ToolWrapperParams < SchemaT >
669+ ) : DynamicTool < ToolOutputT > ;
670+
671+ export function tool <
672+ SchemaT extends ZodObjectV3 ,
673+ SchemaOutputT = InferInteropZodOutput < SchemaT > ,
674+ SchemaInputT = InferInteropZodInput < SchemaT > ,
675+ ToolOutputT = ToolOutputType ,
676+ TState = unknown ,
677+ TContext = unknown
678+ > (
679+ func : (
680+ input : SchemaOutputT ,
681+ runtime : ToolRuntime < TState , TContext >
682+ ) => ToolOutputT | Promise < ToolOutputT > ,
683+ fields : ToolWrapperParams < SchemaT >
684+ ) : DynamicStructuredTool < SchemaT , SchemaOutputT , SchemaInputT , ToolOutputT > ;
685+
686+ export function tool <
687+ SchemaT extends ZodObjectV4 ,
688+ SchemaOutputT = InferInteropZodOutput < SchemaT > ,
689+ SchemaInputT = InferInteropZodInput < SchemaT > ,
690+ ToolOutputT = ToolOutputType ,
691+ TState = unknown ,
692+ TContext = unknown
693+ > (
694+ func : (
695+ input : SchemaOutputT ,
696+ runtime : ToolRuntime < TState , TContext >
697+ ) => ToolOutputT | Promise < ToolOutputT > ,
698+ fields : ToolWrapperParams < SchemaT >
699+ ) : DynamicStructuredTool < SchemaT , SchemaOutputT , SchemaInputT , ToolOutputT > ;
700+
701+ export function tool <
702+ SchemaT extends JSONSchema ,
703+ SchemaOutputT = ToolInputSchemaOutputType < SchemaT > ,
704+ SchemaInputT = ToolInputSchemaInputType < SchemaT > ,
705+ ToolOutputT = ToolOutputType ,
706+ TState = unknown ,
707+ TContext = unknown
708+ > (
709+ func : (
710+ input : Parameters < DynamicStructuredToolInput < SchemaT > [ "func" ] > [ 0 ] ,
711+ runtime : ToolRuntime < TState , TContext >
712+ ) => ToolOutputT | Promise < ToolOutputT > ,
713+ fields : ToolWrapperParams < SchemaT >
714+ ) : DynamicStructuredTool < SchemaT , SchemaOutputT , SchemaInputT , ToolOutputT > ;
715+
716+ export function tool <
717+ SchemaT extends
718+ | InteropZodObject
719+ | InteropZodType < string >
720+ | JSONSchema = InteropZodObject ,
721+ SchemaOutputT = ToolInputSchemaOutputType < SchemaT > ,
722+ SchemaInputT = ToolInputSchemaInputType < SchemaT > ,
723+ ToolOutputT = ToolOutputType ,
724+ TState = unknown ,
725+ TContext = unknown
726+ > (
727+ func : (
728+ input : SchemaOutputT ,
729+ runtime : ToolRuntime < TState , TContext >
730+ ) => ToolOutputT | Promise < ToolOutputT > ,
731+ fields : ToolWrapperParams < SchemaT >
638732) :
639733 | DynamicStructuredTool < SchemaT , SchemaOutputT , SchemaInputT , ToolOutputT >
640734 | DynamicTool < ToolOutputT > {
@@ -659,9 +753,8 @@ export function tool<
659753 pickRunnableConfigKeys ( childConfig ) ,
660754 async ( ) => {
661755 try {
662- // TS doesn't restrict the type here based on the guard above
663756 // eslint-disable-next-line @typescript-eslint/no-explicit-any
664- resolve ( func ( input as any , childConfig ) ) ;
757+ resolve ( func ( input as any , childConfig as any ) ) ;
665758 } catch ( e ) {
666759 reject ( e ) ;
667760 }
@@ -704,7 +797,8 @@ export function tool<
704797 pickRunnableConfigKeys ( childConfig ) ,
705798 async ( ) => {
706799 try {
707- const result = await func ( input , childConfig ) ;
800+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
801+ const result = await func ( input as any , childConfig as any ) ;
708802
709803 /**
710804 * If the signal is aborted, we don't want to resolve the promise
0 commit comments