Skip to content

Commit 7e1699c

Browse files
Wen-Yong LimWen-Yong Lim
authored andcommitted
fix(venice): narrow replay occurrence guards
1 parent de767bc commit 7e1699c

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎extensions/venice/stream.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)