@@ -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 /**
@@ -337,6 +339,7 @@ type ToolExecuteFunction<
337339> = (
338340 input : ToolExecuteArgument < TParameters > ,
339341 context ?: RunContext < Context > ,
342+ details ?: { toolCall : protocol . FunctionCallItem } ,
340343) => Promise < unknown > | unknown ;
341344
342345/**
@@ -517,6 +520,7 @@ export function tool<
517520 async function _invoke (
518521 runContext : RunContext < Context > ,
519522 input : string ,
523+ details : { toolCall : protocol . FunctionCallItem } ,
520524 ) : Promise < Result > {
521525 const [ error , parsed ] = await safeExecute ( ( ) => parser ( input ) ) ;
522526 if ( error !== null ) {
@@ -534,7 +538,7 @@ export function tool<
534538 logger . debug ( `Invoking tool ${ name } with input ${ input } ` ) ;
535539 }
536540
537- const result = await options . execute ( parsed , runContext ) ;
541+ const result = await options . execute ( parsed , runContext , details ) ;
538542 const stringResult = toSmartString ( result ) ;
539543
540544 if ( logger . dontLogToolData ) {
@@ -549,8 +553,9 @@ export function tool<
549553 async function invoke (
550554 runContext : RunContext < Context > ,
551555 input : string ,
556+ details : { toolCall : protocol . FunctionCallItem } ,
552557 ) : Promise < string | Result > {
553- return _invoke ( runContext , input ) . catch < string > ( ( error ) => {
558+ return _invoke ( runContext , input , details ) . catch < string > ( ( error ) => {
554559 if ( toolErrorFunction ) {
555560 const currentSpan = getCurrentSpan ( ) ;
556561 currentSpan ?. setError ( {
0 commit comments