@codeproxy/core 0.1.12 → 0.1.14

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,41 +1211,30 @@ 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
  }
1239
1222
  } else if (part.type === "input_file" || part.type === "file") {
1240
- const partFile = part;
1241
- const fileData = String(partFile.file_data ?? partFile.data ?? "");
1223
+ const fileData = String(contentPart.file_data ?? contentPart.data ?? "");
1242
1224
  const mimeType = String(
1243
- partFile.mime_type ?? partFile.media_type ?? "application/pdf"
1225
+ contentPart.mime_type ?? contentPart.media_type ?? "application/pdf"
1244
1226
  );
1245
1227
  if (fileData) {
1246
1228
  const url = fileData.startsWith("data:") ? fileData : `data:${mimeType};base64,${fileData}`;
1247
1229
  contentBlocks.push({ type: "image_url", image_url: { url } });
1248
1230
  }
1231
+ } else if (contentPart.type === "input_audio") {
1232
+ const ia = contentPart.input_audio;
1233
+ const data = String(ia?.data ?? contentPart.data ?? "");
1234
+ const format = String(ia?.format ?? contentPart.format ?? "mp3");
1235
+ if (data) {
1236
+ contentBlocks.push({ type: "input_audio", input_audio: { data, format } });
1237
+ }
1249
1238
  }
1250
1239
  }
1251
1240
  }
@@ -1291,7 +1280,7 @@ function processInputItem(item, messages, options) {
1291
1280
  return;
1292
1281
  }
1293
1282
  if (itemType === "function_call_output" || itemType === "commandExecutionOutput" || itemType === "fileChangeOutput" || itemType === "custom_tool_call_output") {
1294
- processToolOutput(item, messages);
1283
+ processToolOutput(item, messages, options);
1295
1284
  return;
1296
1285
  }
1297
1286
  }
@@ -1357,10 +1346,29 @@ function processToolCall(item, messages, getLastAssistant, fallbackThoughtSignat
1357
1346
  amsg.reasoning_content = (amsg.reasoning_content ?? "") + thought;
1358
1347
  }
1359
1348
  }
1360
- function processToolOutput(item, messages) {
1349
+ function isImagePart(part) {
1350
+ return part.type === "input_image" || part.type === "image" || part.type === "image_url";
1351
+ }
1352
+ function imagePartToUrl(part) {
1353
+ const imgUrl = part.image_url;
1354
+ if (typeof imgUrl === "string") {
1355
+ return imgUrl;
1356
+ }
1357
+ if (imgUrl && typeof imgUrl === "object" && imgUrl.url) {
1358
+ return imgUrl.url;
1359
+ }
1360
+ const imgData = String(part.data ?? part.base64 ?? "");
1361
+ if (imgData) {
1362
+ const mimeType = String(part.mime_type ?? part.media_type ?? "image/png");
1363
+ return imgData.startsWith("data:") ? imgData : `data:${mimeType};base64,${imgData}`;
1364
+ }
1365
+ return "";
1366
+ }
1367
+ function processToolOutput(item, messages, options) {
1361
1368
  const callId = item.call_id === void 0 ? void 0 : String(item.call_id);
1362
1369
  const outputRaw = item.output ?? item.content ?? item.stdout ?? "";
1363
1370
  let content = "";
1371
+ const imageBlocks = [];
1364
1372
  if (typeof outputRaw === "string") {
1365
1373
  content = outputRaw;
1366
1374
  } else if (Array.isArray(outputRaw)) {
@@ -1371,6 +1379,11 @@ function processToolOutput(item, messages) {
1371
1379
  const partItem = part;
1372
1380
  if (partItem.type === "input_text" || partItem.type === "text") {
1373
1381
  content += String(partItem.text ?? "");
1382
+ } else if (!options.dropImages && isImagePart(partItem)) {
1383
+ const url = imagePartToUrl(part);
1384
+ if (url) {
1385
+ imageBlocks.push({ type: "image_url", image_url: { url } });
1386
+ }
1374
1387
  }
1375
1388
  }
1376
1389
  }
@@ -1389,6 +1402,15 @@ function processToolOutput(item, messages) {
1389
1402
  tool_call_id: callId,
1390
1403
  content
1391
1404
  });
1405
+ if (imageBlocks.length > 0) {
1406
+ messages.push({
1407
+ role: "user",
1408
+ content: [
1409
+ { type: "text", text: "[Image output returned by the preceding tool call]" },
1410
+ ...imageBlocks
1411
+ ]
1412
+ });
1413
+ }
1392
1414
  }
1393
1415
  function mapTools2(tools) {
1394
1416
  const out = [];