@codeproxy/core 0.1.11 → 0.1.13

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
@@ -1211,28 +1211,11 @@ function processInputItem(item, messages, options) {
1211
1211
  contentBlocks.push({ type: "text", text: String(contentPart.text ?? "") });
1212
1212
  } else if (contentPart.type === "reasoning_text") {
1213
1213
  reasoningContent += String(contentPart.text ?? "");
1214
- } else if (contentPart.type === "input_image" || contentPart.type === "image" || contentPart.type === "image_url") {
1214
+ } else if (isImagePart(contentPart)) {
1215
1215
  if (options.dropImages) {
1216
1216
  continue;
1217
1217
  }
1218
- let url = "";
1219
- const partWithImage = part;
1220
- const imgUrl = partWithImage.image_url;
1221
- if (typeof imgUrl === "string") {
1222
- url = imgUrl;
1223
- } else if (imgUrl && typeof imgUrl === "object" && imgUrl.url) {
1224
- url = imgUrl.url;
1225
- } else {
1226
- const partWithData = part;
1227
- const imgData = String(partWithData.data ?? partWithData.base64 ?? "");
1228
- if (imgData) {
1229
- const partWithMime = part;
1230
- const mimeType = String(
1231
- partWithMime.mime_type ?? partWithMime.media_type ?? "image/png"
1232
- );
1233
- url = imgData.startsWith("data:") ? imgData : `data:${mimeType};base64,${imgData}`;
1234
- }
1235
- }
1218
+ const url = imagePartToUrl(part);
1236
1219
  if (url) {
1237
1220
  contentBlocks.push({ type: "image_url", image_url: { url } });
1238
1221
  }
@@ -1291,7 +1274,7 @@ function processInputItem(item, messages, options) {
1291
1274
  return;
1292
1275
  }
1293
1276
  if (itemType === "function_call_output" || itemType === "commandExecutionOutput" || itemType === "fileChangeOutput" || itemType === "custom_tool_call_output") {
1294
- processToolOutput(item, messages);
1277
+ processToolOutput(item, messages, options);
1295
1278
  return;
1296
1279
  }
1297
1280
  }
@@ -1357,10 +1340,29 @@ function processToolCall(item, messages, getLastAssistant, fallbackThoughtSignat
1357
1340
  amsg.reasoning_content = (amsg.reasoning_content ?? "") + thought;
1358
1341
  }
1359
1342
  }
1360
- function processToolOutput(item, messages) {
1343
+ function isImagePart(part) {
1344
+ return part.type === "input_image" || part.type === "image" || part.type === "image_url";
1345
+ }
1346
+ function imagePartToUrl(part) {
1347
+ const imgUrl = part.image_url;
1348
+ if (typeof imgUrl === "string") {
1349
+ return imgUrl;
1350
+ }
1351
+ if (imgUrl && typeof imgUrl === "object" && imgUrl.url) {
1352
+ return imgUrl.url;
1353
+ }
1354
+ const imgData = String(part.data ?? part.base64 ?? "");
1355
+ if (imgData) {
1356
+ const mimeType = String(part.mime_type ?? part.media_type ?? "image/png");
1357
+ return imgData.startsWith("data:") ? imgData : `data:${mimeType};base64,${imgData}`;
1358
+ }
1359
+ return "";
1360
+ }
1361
+ function processToolOutput(item, messages, options) {
1361
1362
  const callId = item.call_id === void 0 ? void 0 : String(item.call_id);
1362
1363
  const outputRaw = item.output ?? item.content ?? item.stdout ?? "";
1363
1364
  let content = "";
1365
+ const imageBlocks = [];
1364
1366
  if (typeof outputRaw === "string") {
1365
1367
  content = outputRaw;
1366
1368
  } else if (Array.isArray(outputRaw)) {
@@ -1371,6 +1373,11 @@ function processToolOutput(item, messages) {
1371
1373
  const partItem = part;
1372
1374
  if (partItem.type === "input_text" || partItem.type === "text") {
1373
1375
  content += String(partItem.text ?? "");
1376
+ } else if (!options.dropImages && isImagePart(partItem)) {
1377
+ const url = imagePartToUrl(part);
1378
+ if (url) {
1379
+ imageBlocks.push({ type: "image_url", image_url: { url } });
1380
+ }
1374
1381
  }
1375
1382
  }
1376
1383
  }
@@ -1389,6 +1396,15 @@ function processToolOutput(item, messages) {
1389
1396
  tool_call_id: callId,
1390
1397
  content
1391
1398
  });
1399
+ if (imageBlocks.length > 0) {
1400
+ messages.push({
1401
+ role: "user",
1402
+ content: [
1403
+ { type: "text", text: "[Image output returned by the preceding tool call]" },
1404
+ ...imageBlocks
1405
+ ]
1406
+ });
1407
+ }
1392
1408
  }
1393
1409
  function mapTools2(tools) {
1394
1410
  const out = [];