File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -112,13 +112,23 @@ function applyVeniceGeminiToolHistoryCompatibility(
112112 const record = message as Record < string , unknown > ;
113113 if ( record . role === "tool" ) {
114114 const toolCallId = typeof record . tool_call_id === "string" ? record . tool_call_id : undefined ;
115- const toolNames = toolCallId ? pendingDowngradedToolCalls ?. get ( toolCallId ) : undefined ;
116- const toolName = toolNames ?. shift ( ) ;
115+ if ( ! toolCallId ) {
116+ continue ;
117+ }
118+ const pendingCalls = pendingDowngradedToolCalls ;
119+ if ( ! pendingCalls ) {
120+ continue ;
121+ }
122+ const toolNames = pendingCalls . get ( toolCallId ) ;
123+ if ( ! toolNames ) {
124+ continue ;
125+ }
126+ const toolName = toolNames . shift ( ) ;
117127 if ( ! toolName ) {
118128 continue ;
119129 }
120130 if ( toolNames . length === 0 ) {
121- pendingDowngradedToolCalls ? .delete ( toolCallId ) ;
131+ pendingCalls . delete ( toolCallId ) ;
122132 }
123133 const result = stringifyHistoricalValue ( record . content ) ;
124134 for ( const key of Object . keys ( record ) ) {
@@ -146,7 +156,9 @@ function applyVeniceGeminiToolHistoryCompatibility(
146156 const historicalCall = historicalBatch ?. [ toolCallIndex ] ;
147157 const describedCall = describeHistoricalToolCall ( toolCallRecord ) ;
148158 const signature =
149- historicalCall ?. id === toolCallRecord . id && historicalCall . name === describedCall . name
159+ historicalCall &&
160+ historicalCall . id === toolCallRecord . id &&
161+ historicalCall . name === describedCall . name
150162 ? historicalCall . thoughtSignature
151163 : undefined ;
152164 if ( signature ) {
You can’t perform that action at this time.
0 commit comments