File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,19 +26,37 @@ const TOOL_MESSAGE_DEBUG_KEYS = new Set([
2626 "response_metadata" ,
2727] ) ;
2828
29+ function getToolCallDebugPayload ( outputRecord : Record < string , unknown > ) {
30+ const lcKwargs =
31+ typeof outputRecord . lc_kwargs === "object" && outputRecord . lc_kwargs !== null
32+ ? outputRecord . lc_kwargs as Record < string , unknown >
33+ : null ;
34+
35+ if ( lcKwargs && "tool_call_id" in lcKwargs ) {
36+ return lcKwargs ;
37+ }
38+
39+ if ( "tool_call_id" in outputRecord ) {
40+ return outputRecord ;
41+ }
42+
43+ return null ;
44+ }
45+
2946function sanitizeToolCallOutputForDebug ( output : unknown ) {
3047 if ( typeof output !== "object" || output === null ) {
3148 return output ;
3249 }
3350
3451 const outputRecord = output as Record < string , unknown > ;
52+ const debugPayload = getToolCallDebugPayload ( outputRecord ) ;
3553
36- if ( ! ( "tool_call_id" in outputRecord ) ) {
54+ if ( ! debugPayload ) {
3755 return output ;
3856 }
3957
4058 return Object . fromEntries (
41- Object . entries ( outputRecord ) . filter ( ( [ key ] ) => ! TOOL_MESSAGE_DEBUG_KEYS . has ( key ) ) ,
59+ Object . entries ( debugPayload ) . filter ( ( [ key ] ) => ! TOOL_MESSAGE_DEBUG_KEYS . has ( key ) ) ,
4260 ) ;
4361}
4462
You can’t perform that action at this time.
0 commit comments