@jeffreycao/copilot-api 2.2.6 → 2.2.8

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-DPPlLU86.js");
34
34
  await runMain(defineCommand({
35
35
  meta: {
36
36
  name: "copilot-api",
@@ -5384,7 +5384,6 @@ const translateResponsesStreamEvent = (rawEvent, state) => {
5384
5384
  case "response.reasoning_summary_part.added": return handleReasoningSummaryPartAdded(rawEvent, state);
5385
5385
  case "response.output_text.delta": return handleOutputTextDelta(rawEvent, state);
5386
5386
  case "response.reasoning_summary_text.done": return handleReasoningSummaryTextDone(rawEvent, state);
5387
- case "response.output_text.done": return handleOutputTextDone(rawEvent, state);
5388
5387
  case "response.output_item.done": return handleOutputItemDone$1(rawEvent, state);
5389
5388
  case "response.function_call_arguments.delta": return handleFunctionCallArgumentsDelta(rawEvent, state);
5390
5389
  case "response.function_call_arguments.done": return handleFunctionCallArgumentsDone(rawEvent, state);
@@ -5621,26 +5620,6 @@ const handleReasoningSummaryTextDone = (rawEvent, state) => {
5621
5620
  }
5622
5621
  return events;
5623
5622
  };
5624
- const handleOutputTextDone = (rawEvent, state) => {
5625
- const events = new Array();
5626
- const outputIndex = rawEvent.output_index;
5627
- const contentIndex = rawEvent.content_index;
5628
- const text = rawEvent.text;
5629
- const blockIndex = openTextBlockIfNeeded(state, {
5630
- outputIndex,
5631
- contentIndex,
5632
- events
5633
- });
5634
- if (text && !state.blockHasDelta.has(blockIndex)) events.push({
5635
- type: "content_block_delta",
5636
- index: blockIndex,
5637
- delta: {
5638
- type: "text_delta",
5639
- text
5640
- }
5641
- });
5642
- return events;
5643
- };
5644
5623
  const handleResponseCompleted = (rawEvent, state) => {
5645
5624
  const response = rawEvent.response;
5646
5625
  const events = new Array();
@@ -5792,6 +5771,7 @@ const openFunctionCallBlock = (state, params) => {
5792
5771
  }
5793
5772
  const { blockIndex } = functionCallState;
5794
5773
  if (!state.openBlocks.has(blockIndex)) {
5774
+ closeOpenBlocks(state, events);
5795
5775
  events.push({
5796
5776
  type: "content_block_start",
5797
5777
  index: blockIndex,
@@ -5956,38 +5936,43 @@ const sanitizeOversizedInputImages = (payload, maxPromptImageSize) => {
5956
5936
  if (limit === void 0 || !Array.isArray(payload.input)) return 0;
5957
5937
  return sanitizeInputImages(payload.input, (image) => image.decodedBytes > limit);
5958
5938
  };
5939
+ const normalizeInputImageDetails = (payload) => {
5940
+ if (!Array.isArray(payload.input)) return 0;
5941
+ let normalizedCount = 0;
5942
+ for (const image of collectInputImages(payload.input)) {
5943
+ if (image.detail === void 0 || VALID_INPUT_IMAGE_DETAILS.has(image.detail)) continue;
5944
+ image.detail = "auto";
5945
+ normalizedCount += 1;
5946
+ }
5947
+ return normalizedCount;
5948
+ };
5959
5949
  const sanitizeInputImages = (input, shouldReplace) => {
5960
5950
  let count = 0;
5961
- for (const image of collectInputImageDataUrls(input)) {
5951
+ for (const record of collectInputImages(input)) {
5952
+ const image = getInputImageDataUrl(record);
5953
+ if (!image) continue;
5962
5954
  if (!shouldReplace(image)) continue;
5963
5955
  replaceInputImageWithPlaceholder(image);
5964
5956
  count += 1;
5965
5957
  }
5966
5958
  return count;
5967
5959
  };
5968
- const collectInputImageDataUrls = (input, images = []) => {
5969
- for (const item of input) collectInputItemImageDataUrls(item, images);
5960
+ const collectInputImages = (input, images = []) => {
5961
+ for (const item of input) if (isResponseInputMessage(item)) collectContentImages(item.content, images);
5962
+ else if (isResponseFunctionCallOutputItem(item)) collectContentImages(item.output, images);
5970
5963
  return images;
5971
5964
  };
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) => {
5965
+ const collectContentImages = (content, images) => {
5977
5966
  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
- }
5967
+ for (const block of content) if (isResponseInputImage(block)) images.push(block);
5983
5968
  };
5984
- const getInputImageDataUrl = (content) => {
5985
- if (!isResponseInputImage(content) || typeof content.image_url !== "string") return null;
5986
- const imageUrl = content.image_url;
5969
+ const getInputImageDataUrl = (image) => {
5970
+ if (typeof image.image_url !== "string") return null;
5971
+ const imageUrl = image.image_url;
5987
5972
  if (!imageUrl.startsWith(DATA_URL_PREFIX)) return null;
5988
5973
  return {
5989
5974
  decodedBytes: estimateDataUrlByteLength(imageUrl),
5990
- record: content
5975
+ record: image
5991
5976
  };
5992
5977
  };
5993
5978
  const estimateDataUrlByteLength = (value) => {
@@ -6004,9 +5989,6 @@ const VALID_INPUT_IMAGE_DETAILS = new Set([
6004
5989
  "high",
6005
5990
  "low"
6006
5991
  ]);
6007
- const normalizeInputImageDetail = (detail) => {
6008
- return VALID_INPUT_IMAGE_DETAILS.has(detail) ? detail : "auto";
6009
- };
6010
5992
  const isResponseInputMessage = (item) => {
6011
5993
  return typeof item === "object" && item !== null && "role" in item && typeof item.role === "string";
6012
5994
  };
@@ -8877,7 +8859,13 @@ function translateToolResultContent(value, path) {
8877
8859
  if (value === void 0 || value === null) return "";
8878
8860
  if (typeof value === "string") return value;
8879
8861
  if (!Array.isArray(value)) throw new ResponsesMessagesTranslationError(`${path} must be text or an array`);
8880
- return value.map((part, index) => translateUserContentPart(part, `${path}[${index}]`));
8862
+ const blocks = value.flatMap((part, index) => isEmptyTextContentPart(part) ? [] : [translateUserContentPart(part, `${path}[${index}]`)]);
8863
+ return blocks.length > 0 ? blocks : "";
8864
+ }
8865
+ function isEmptyTextContentPart(part) {
8866
+ if (!isRecord(part)) return false;
8867
+ const type = part.type;
8868
+ return (type === "input_text" || type === "output_text" || type === "text") && part.text === "";
8881
8869
  }
8882
8870
  function translateImagePart(part, path) {
8883
8871
  const imageUrl = getStringField(part, "image_url");
@@ -9169,83 +9157,69 @@ var CustomToolInputStreamDecoder = class {
9169
9157
  return this.inputParts.join("");
9170
9158
  }
9171
9159
  consume(char, deltaParts) {
9172
- if (this.state === "prefix") {
9173
- const token = CUSTOM_TOOL_INPUT_PREFIX_TOKENS[this.prefixTokenOffset];
9174
- if (this.prefixCharOffset === 0 && isJsonWhitespace(char)) return;
9175
- if (!token || char !== token[this.prefixCharOffset]) return this.fail("unexpected custom tool input prefix");
9176
- this.prefixCharOffset += 1;
9177
- if (this.prefixCharOffset < token.length) return;
9178
- this.prefixTokenOffset += 1;
9179
- this.prefixCharOffset = 0;
9180
- if (this.prefixTokenOffset === CUSTOM_TOOL_INPUT_PREFIX_TOKENS.length) this.state = "input";
9160
+ switch (this.state) {
9161
+ case "prefix": return this.consumePrefix(char);
9162
+ case "suffix": return this.consumeSuffix(char);
9163
+ case "trailing": return this.consumeTrailing(char);
9164
+ case "done": return this.consumeDone(char);
9165
+ default: return this.consumeInput(char, deltaParts);
9166
+ }
9167
+ }
9168
+ consumePrefix(char) {
9169
+ const token = CUSTOM_TOOL_INPUT_PREFIX_TOKENS[this.prefixTokenOffset];
9170
+ if (this.prefixCharOffset === 0 && isJsonWhitespace(char)) return;
9171
+ if (char !== token?.[this.prefixCharOffset]) return this.fail("unexpected custom tool input prefix");
9172
+ this.prefixCharOffset += 1;
9173
+ if (this.prefixCharOffset < token.length) return;
9174
+ this.prefixTokenOffset += 1;
9175
+ this.prefixCharOffset = 0;
9176
+ if (this.prefixTokenOffset === CUSTOM_TOOL_INPUT_PREFIX_TOKENS.length) this.state = "input";
9177
+ }
9178
+ consumeSuffix(char) {
9179
+ if (isJsonWhitespace(char)) return;
9180
+ if (char === "}") {
9181
+ this.state = "done";
9181
9182
  return;
9182
9183
  }
9183
- if (this.state === "suffix") {
9184
- if (isJsonWhitespace(char)) return;
9185
- if (char === "}") {
9186
- this.state = "done";
9187
- return;
9188
- }
9189
- if (char === ",") {
9190
- this.state = "trailing";
9191
- this.trailingDepth = 1;
9192
- return;
9193
- }
9194
- return this.fail("expected \"}\" or \",\" after the input string");
9184
+ if (char === ",") {
9185
+ this.state = "trailing";
9186
+ this.trailingDepth = 1;
9187
+ return;
9195
9188
  }
9196
- if (this.state === "trailing") {
9197
- if (this.trailingInString) {
9198
- if (this.trailingEscaped) {
9199
- this.trailingEscaped = false;
9200
- return;
9201
- }
9202
- if (char === "\\") {
9203
- this.trailingEscaped = true;
9204
- return;
9205
- }
9206
- if (char === "\"") this.trailingInString = false;
9207
- return;
9208
- }
9209
- if (char === "\"") {
9210
- this.trailingInString = true;
9211
- return;
9212
- }
9213
- if (char === "{" || char === "[") {
9214
- this.trailingDepth += 1;
9215
- return;
9216
- }
9217
- if (char === "}" || char === "]") {
9218
- this.trailingDepth -= 1;
9219
- if (this.trailingDepth === 0) this.state = "done";
9220
- }
9189
+ return this.fail("expected \"}\" or \",\" after the input string");
9190
+ }
9191
+ consumeTrailing(char) {
9192
+ if (this.trailingInString) return this.consumeTrailingString(char);
9193
+ if (char === "\"") {
9194
+ this.trailingInString = true;
9221
9195
  return;
9222
9196
  }
9223
- if (this.state === "done") {
9224
- if (!isJsonWhitespace(char)) return this.fail("unexpected data after the input wrapper");
9197
+ if (char === "{" || char === "[") {
9198
+ this.trailingDepth += 1;
9225
9199
  return;
9226
9200
  }
9227
- if (this.escapeState === "unicode") {
9228
- if (!/^[0-9A-Fa-f]$/u.test(char)) return this.fail("invalid Unicode escape");
9229
- this.encodedInput += char;
9230
- this.unicodeDigitsRemaining -= 1;
9231
- if (this.unicodeDigitsRemaining === 0) {
9232
- this.escapeState = "plain";
9233
- this.safeInputLength = this.encodedInput.length;
9234
- }
9201
+ if (char === "}" || char === "]") {
9202
+ this.trailingDepth -= 1;
9203
+ if (this.trailingDepth === 0) this.state = "done";
9204
+ }
9205
+ }
9206
+ consumeTrailingString(char) {
9207
+ if (this.trailingEscaped) {
9208
+ this.trailingEscaped = false;
9235
9209
  return;
9236
9210
  }
9237
- if (this.escapeState === "escaped") {
9238
- if (!"\"\\/bfnrtu".includes(char)) return this.fail("invalid JSON escape");
9239
- this.encodedInput += char;
9240
- if (char === "u") {
9241
- this.escapeState = "unicode";
9242
- this.unicodeDigitsRemaining = 4;
9243
- } else {
9244
- this.escapeState = "plain";
9245
- this.safeInputLength = this.encodedInput.length;
9246
- }
9211
+ if (char === "\\") {
9212
+ this.trailingEscaped = true;
9247
9213
  return;
9248
9214
  }
9215
+ if (char === "\"") this.trailingInString = false;
9216
+ }
9217
+ consumeDone(char) {
9218
+ if (!isJsonWhitespace(char)) return this.fail("unexpected data after the input wrapper");
9219
+ }
9220
+ consumeInput(char, deltaParts) {
9221
+ if (this.escapeState === "unicode") return this.consumeUnicodeEscape(char);
9222
+ if (this.escapeState === "escaped") return this.consumeEscape(char);
9249
9223
  if (char === "\\") {
9250
9224
  this.encodedInput += char;
9251
9225
  this.escapeState = "escaped";
@@ -9256,10 +9230,30 @@ var CustomToolInputStreamDecoder = class {
9256
9230
  this.state = "suffix";
9257
9231
  return;
9258
9232
  }
9259
- if (char.charCodeAt(0) < 32) return this.fail("unescaped control character in custom tool input");
9233
+ if ((char.codePointAt(0) ?? 0) < 32) return this.fail("unescaped control character in custom tool input");
9260
9234
  this.encodedInput += char;
9261
9235
  this.safeInputLength = this.encodedInput.length;
9262
9236
  }
9237
+ consumeUnicodeEscape(char) {
9238
+ if (!/^[0-9A-Fa-f]$/u.test(char)) return this.fail("invalid Unicode escape");
9239
+ this.encodedInput += char;
9240
+ this.unicodeDigitsRemaining -= 1;
9241
+ if (this.unicodeDigitsRemaining === 0) {
9242
+ this.escapeState = "plain";
9243
+ this.safeInputLength = this.encodedInput.length;
9244
+ }
9245
+ }
9246
+ consumeEscape(char) {
9247
+ if (!String.raw`"\/bfnrtu`.includes(char)) return this.fail("invalid JSON escape");
9248
+ this.encodedInput += char;
9249
+ if (char === "u") {
9250
+ this.escapeState = "unicode";
9251
+ this.unicodeDigitsRemaining = 4;
9252
+ } else {
9253
+ this.escapeState = "plain";
9254
+ this.safeInputLength = this.encodedInput.length;
9255
+ }
9256
+ }
9263
9257
  flushSafeInput(deltaParts) {
9264
9258
  if (this.safeInputLength === 0) return;
9265
9259
  const encoded = this.encodedInput.slice(0, this.safeInputLength);
@@ -10254,6 +10248,8 @@ const handleResponses = async (c) => {
10254
10248
  });
10255
10249
  const sanitizedUnsupportedFieldCount = sanitizeUnsupportedInputFields(payload);
10256
10250
  if (sanitizedUnsupportedFieldCount > 0) logger$1.debug(`Removed ${sanitizedUnsupportedFieldCount} unsupported input field(s) before forwarding to Copilot Responses`);
10251
+ const normalizedImageDetailCount = normalizeInputImageDetails(payload);
10252
+ if (normalizedImageDetailCount > 0) logger$1.debug(`Normalized ${normalizedImageDetailCount} unsupported input image detail value(s) before forwarding to Copilot Responses`);
10257
10253
  removeUnsupportedTools(payload);
10258
10254
  fillEmptyNamespaceToolDescriptions(payload);
10259
10255
  if (!responsesHandlerDependencies.isResponsesApiWebSearchEnabled()) removeWebSearchTool(payload);
@@ -10517,4 +10513,4 @@ server.route("/:provider/images", providerImageRoutes);
10517
10513
  //#endregion
10518
10514
  export { server };
10519
10515
 
10520
- //# sourceMappingURL=server-Bx7xs1FA.js.map
10516
+ //# sourceMappingURL=server-Bg4A4rdK.js.map