@jeffreycao/copilot-api 2.2.6 → 2.2.7

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/main.js CHANGED
@@ -30,7 +30,7 @@ if (isMcpFastPath(process.argv)) {
30
30
  const { auth } = await import("./auth-C-RWNXGU.js");
31
31
  const { debug } = await import("./debug-41w6Whae.js");
32
32
  const { mcp } = await import("./mcp-fpSlKZxK.js");
33
- const { start } = await import("./start-HcJzBszU.js");
33
+ const { start } = await import("./start-DgPGr019.js");
34
34
  await runMain(defineCommand({
35
35
  meta: {
36
36
  name: "copilot-api",
@@ -5956,38 +5956,43 @@ const sanitizeOversizedInputImages = (payload, maxPromptImageSize) => {
5956
5956
  if (limit === void 0 || !Array.isArray(payload.input)) return 0;
5957
5957
  return sanitizeInputImages(payload.input, (image) => image.decodedBytes > limit);
5958
5958
  };
5959
+ const normalizeInputImageDetails = (payload) => {
5960
+ if (!Array.isArray(payload.input)) return 0;
5961
+ let normalizedCount = 0;
5962
+ for (const image of collectInputImages(payload.input)) {
5963
+ if (image.detail === void 0 || VALID_INPUT_IMAGE_DETAILS.has(image.detail)) continue;
5964
+ image.detail = "auto";
5965
+ normalizedCount += 1;
5966
+ }
5967
+ return normalizedCount;
5968
+ };
5959
5969
  const sanitizeInputImages = (input, shouldReplace) => {
5960
5970
  let count = 0;
5961
- for (const image of collectInputImageDataUrls(input)) {
5971
+ for (const record of collectInputImages(input)) {
5972
+ const image = getInputImageDataUrl(record);
5973
+ if (!image) continue;
5962
5974
  if (!shouldReplace(image)) continue;
5963
5975
  replaceInputImageWithPlaceholder(image);
5964
5976
  count += 1;
5965
5977
  }
5966
5978
  return count;
5967
5979
  };
5968
- const collectInputImageDataUrls = (input, images = []) => {
5969
- for (const item of input) collectInputItemImageDataUrls(item, images);
5980
+ const collectInputImages = (input, images = []) => {
5981
+ for (const item of input) if (isResponseInputMessage(item)) collectContentImages(item.content, images);
5982
+ else if (isResponseFunctionCallOutputItem(item)) collectContentImages(item.output, images);
5970
5983
  return images;
5971
5984
  };
5972
- const collectInputItemImageDataUrls = (item, images) => {
5973
- if (isResponseInputMessage(item)) collectContentImageDataUrls(item.content, images);
5974
- else if (isResponseFunctionCallOutputItem(item)) collectContentImageDataUrls(item.output, images);
5975
- };
5976
- const collectContentImageDataUrls = (content, images) => {
5985
+ const collectContentImages = (content, images) => {
5977
5986
  if (!Array.isArray(content)) return;
5978
- for (const block of content) {
5979
- if (isResponseInputImage(block)) block.detail = normalizeInputImageDetail(block.detail);
5980
- const image = getInputImageDataUrl(block);
5981
- if (image) images.push(image);
5982
- }
5987
+ for (const block of content) if (isResponseInputImage(block)) images.push(block);
5983
5988
  };
5984
- const getInputImageDataUrl = (content) => {
5985
- if (!isResponseInputImage(content) || typeof content.image_url !== "string") return null;
5986
- const imageUrl = content.image_url;
5989
+ const getInputImageDataUrl = (image) => {
5990
+ if (typeof image.image_url !== "string") return null;
5991
+ const imageUrl = image.image_url;
5987
5992
  if (!imageUrl.startsWith(DATA_URL_PREFIX)) return null;
5988
5993
  return {
5989
5994
  decodedBytes: estimateDataUrlByteLength(imageUrl),
5990
- record: content
5995
+ record: image
5991
5996
  };
5992
5997
  };
5993
5998
  const estimateDataUrlByteLength = (value) => {
@@ -6004,9 +6009,6 @@ const VALID_INPUT_IMAGE_DETAILS = new Set([
6004
6009
  "high",
6005
6010
  "low"
6006
6011
  ]);
6007
- const normalizeInputImageDetail = (detail) => {
6008
- return VALID_INPUT_IMAGE_DETAILS.has(detail) ? detail : "auto";
6009
- };
6010
6012
  const isResponseInputMessage = (item) => {
6011
6013
  return typeof item === "object" && item !== null && "role" in item && typeof item.role === "string";
6012
6014
  };
@@ -8877,7 +8879,13 @@ function translateToolResultContent(value, path) {
8877
8879
  if (value === void 0 || value === null) return "";
8878
8880
  if (typeof value === "string") return value;
8879
8881
  if (!Array.isArray(value)) throw new ResponsesMessagesTranslationError(`${path} must be text or an array`);
8880
- return value.map((part, index) => translateUserContentPart(part, `${path}[${index}]`));
8882
+ const blocks = value.flatMap((part, index) => isEmptyTextContentPart(part) ? [] : [translateUserContentPart(part, `${path}[${index}]`)]);
8883
+ return blocks.length > 0 ? blocks : "";
8884
+ }
8885
+ function isEmptyTextContentPart(part) {
8886
+ if (!isRecord(part)) return false;
8887
+ const type = part.type;
8888
+ return (type === "input_text" || type === "output_text" || type === "text") && part.text === "";
8881
8889
  }
8882
8890
  function translateImagePart(part, path) {
8883
8891
  const imageUrl = getStringField(part, "image_url");
@@ -10254,6 +10262,8 @@ const handleResponses = async (c) => {
10254
10262
  });
10255
10263
  const sanitizedUnsupportedFieldCount = sanitizeUnsupportedInputFields(payload);
10256
10264
  if (sanitizedUnsupportedFieldCount > 0) logger$1.debug(`Removed ${sanitizedUnsupportedFieldCount} unsupported input field(s) before forwarding to Copilot Responses`);
10265
+ const normalizedImageDetailCount = normalizeInputImageDetails(payload);
10266
+ if (normalizedImageDetailCount > 0) logger$1.debug(`Normalized ${normalizedImageDetailCount} unsupported input image detail value(s) before forwarding to Copilot Responses`);
10257
10267
  removeUnsupportedTools(payload);
10258
10268
  fillEmptyNamespaceToolDescriptions(payload);
10259
10269
  if (!responsesHandlerDependencies.isResponsesApiWebSearchEnabled()) removeWebSearchTool(payload);
@@ -10517,4 +10527,4 @@ server.route("/:provider/images", providerImageRoutes);
10517
10527
  //#endregion
10518
10528
  export { server };
10519
10529
 
10520
- //# sourceMappingURL=server-Bx7xs1FA.js.map
10530
+ //# sourceMappingURL=server-DT2XCiFm.js.map