@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.js CHANGED
@@ -1125,12 +1125,45 @@ function applyGeminiToolUseShim(messages) {
1125
1125
  }
1126
1126
  }
1127
1127
  }
1128
+ 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."}';
1129
+ function synthesizeMissingToolResponses(messages) {
1130
+ const answered = /* @__PURE__ */ new Set();
1131
+ for (const msg of messages) {
1132
+ if (msg.role === "tool" && msg.tool_call_id !== void 0) {
1133
+ answered.add(String(msg.tool_call_id));
1134
+ }
1135
+ }
1136
+ const out = [];
1137
+ let cursor = 0;
1138
+ while (cursor < messages.length) {
1139
+ const msg = messages[cursor];
1140
+ out.push(msg);
1141
+ cursor += 1;
1142
+ if (msg.role !== "assistant" || !msg.tool_calls?.length) {
1143
+ continue;
1144
+ }
1145
+ while (cursor < messages.length && messages[cursor].role === "tool") {
1146
+ out.push(messages[cursor]);
1147
+ cursor += 1;
1148
+ }
1149
+ for (const call of msg.tool_calls) {
1150
+ const id = call.id ? String(call.id) : "";
1151
+ if (id && !answered.has(id)) {
1152
+ out.push({ role: "tool", tool_call_id: id, content: SYNTHETIC_TOOL_RESPONSE });
1153
+ answered.add(id);
1154
+ }
1155
+ }
1156
+ }
1157
+ messages.length = 0;
1158
+ messages.push(...out);
1159
+ }
1128
1160
  function applyGeminiFixups(messages, model) {
1129
1161
  if (!isGeminiModel(model)) {
1130
1162
  return;
1131
1163
  }
1132
1164
  mergeSystemMessages(messages);
1133
1165
  applyGeminiToolUseShim(messages);
1166
+ synthesizeMissingToolResponses(messages);
1134
1167
  }
1135
1168
 
1136
1169
  // src/translate/openai/translateRequest.ts