@codeproxy/core 0.1.15 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1127,12 +1127,45 @@ function applyGeminiToolUseShim(messages) {
1127
1127
  }
1128
1128
  }
1129
1129
  }
1130
+ var SYNTHETIC_TOOL_RESPONSE = '{"status":"no_result","note":"No tool result was recorded for this call before the request was sent (the turn was interrupted or the result was not persisted). Treat the call as unfinished \u2014 do not assume it succeeded; re-check the underlying state before retrying."}';
1131
+ function synthesizeMissingToolResponses(messages) {
1132
+ const answered = /* @__PURE__ */ new Set();
1133
+ for (const msg of messages) {
1134
+ if (msg.role === "tool" && msg.tool_call_id !== void 0) {
1135
+ answered.add(String(msg.tool_call_id));
1136
+ }
1137
+ }
1138
+ const out = [];
1139
+ let cursor = 0;
1140
+ while (cursor < messages.length) {
1141
+ const msg = messages[cursor];
1142
+ out.push(msg);
1143
+ cursor += 1;
1144
+ if (msg.role !== "assistant" || !msg.tool_calls?.length) {
1145
+ continue;
1146
+ }
1147
+ while (cursor < messages.length && messages[cursor].role === "tool") {
1148
+ out.push(messages[cursor]);
1149
+ cursor += 1;
1150
+ }
1151
+ for (const call of msg.tool_calls) {
1152
+ const id = call.id ? String(call.id) : "";
1153
+ if (id && !answered.has(id)) {
1154
+ out.push({ role: "tool", tool_call_id: id, content: SYNTHETIC_TOOL_RESPONSE });
1155
+ answered.add(id);
1156
+ }
1157
+ }
1158
+ }
1159
+ messages.length = 0;
1160
+ messages.push(...out);
1161
+ }
1130
1162
  function applyGeminiFixups(messages, model) {
1131
1163
  if (!isGeminiModel(model)) {
1132
1164
  return;
1133
1165
  }
1134
1166
  mergeSystemMessages(messages);
1135
1167
  applyGeminiToolUseShim(messages);
1168
+ synthesizeMissingToolResponses(messages);
1136
1169
  }
1137
1170
 
1138
1171
  // src/translate/openai/translateRequest.ts