@@ -17,6 +17,7 @@ import { getCurrentSpan } from './tracing';
1717import { RunToolApprovalItem , RunToolCallOutputItem } from './items' ;
1818import { toSmartString } from './utils/smartString' ;
1919import * as ProviderData from './types/providerData' ;
20+ import * as protocol from './types/protocol' ;
2021
2122/**
2223 * A function that determines if a tool call should be approved.
@@ -67,6 +68,7 @@ export type FunctionTool<
6768 invoke : (
6869 runContext : RunContext < Context > ,
6970 input : string ,
71+ details ?: { toolCall : protocol . FunctionCallItem } ,
7072 ) => Promise < string | Result > ;
7173
7274 /**
@@ -411,6 +413,7 @@ type ToolExecuteFunction<
411413> = (
412414 input : ToolExecuteArgument < TParameters > ,
413415 context ?: RunContext < Context > ,
416+ details ?: { toolCall : protocol . FunctionCallItem } ,
414417) => Promise < unknown > | unknown ;
415418
416419/**
@@ -591,6 +594,7 @@ export function tool<
591594 async function _invoke (
592595 runContext : RunContext < Context > ,
593596 input : string ,
597+ details ?: { toolCall : protocol . FunctionCallItem } ,
594598 ) : Promise < Result > {
595599 const [ error , parsed ] = await safeExecute ( ( ) => parser ( input ) ) ;
596600 if ( error !== null ) {
@@ -608,7 +612,7 @@ export function tool<
608612 logger . debug ( `Invoking tool ${ name } with input ${ input } ` ) ;
609613 }
610614
611- const result = await options . execute ( parsed , runContext ) ;
615+ const result = await options . execute ( parsed , runContext , details ) ;
612616 const stringResult = toSmartString ( result ) ;
613617
614618 if ( logger . dontLogToolData ) {
@@ -623,8 +627,9 @@ export function tool<
623627 async function invoke (
624628 runContext : RunContext < Context > ,
625629 input : string ,
630+ details ?: { toolCall : protocol . FunctionCallItem } ,
626631 ) : Promise < string | Result > {
627- return _invoke ( runContext , input ) . catch < string > ( ( error ) => {
632+ return _invoke ( runContext , input , details ) . catch < string > ( ( error ) => {
628633 if ( toolErrorFunction ) {
629634 const currentSpan = getCurrentSpan ( ) ;
630635 currentSpan ?. setError ( {
0 commit comments