@jeffreycao/copilot-api 1.6.2 → 1.6.3
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 +1 -1
- package/dist/{server-ABtVTO7w.js → server-wOqxNjw_.js} +67 -6
- package/dist/server-wOqxNjw_.js.map +1 -0
- package/dist/{start-CcPjJUMF.js → start-DzdGfvGi.js} +2 -2
- package/dist/{start-CcPjJUMF.js.map → start-DzdGfvGi.js.map} +1 -1
- package/package.json +1 -1
- package/dist/server-ABtVTO7w.js.map +0 -1
package/dist/main.js
CHANGED
|
@@ -23,7 +23,7 @@ if (typeof args["enterprise-url"] === "string") process.env.COPILOT_API_ENTERPRI
|
|
|
23
23
|
const { auth } = await import("./auth-I-jV5RwF.js");
|
|
24
24
|
const { checkUsage } = await import("./check-usage-DYLFqYhN.js");
|
|
25
25
|
const { debug } = await import("./debug-DcC7ZPH0.js");
|
|
26
|
-
const { start } = await import("./start-
|
|
26
|
+
const { start } = await import("./start-DzdGfvGi.js");
|
|
27
27
|
const main = defineCommand({
|
|
28
28
|
meta: {
|
|
29
29
|
name: "copilot-api",
|
|
@@ -756,6 +756,9 @@ function mapContent(content) {
|
|
|
756
756
|
image_url: { url: `data:${block.source.media_type};base64,${block.source.data}` }
|
|
757
757
|
});
|
|
758
758
|
break;
|
|
759
|
+
case "document":
|
|
760
|
+
contentParts.push(createDocumentTextPart());
|
|
761
|
+
break;
|
|
759
762
|
case "tool_reference":
|
|
760
763
|
contentParts.push({
|
|
761
764
|
type: "text",
|
|
@@ -765,6 +768,12 @@ function mapContent(content) {
|
|
|
765
768
|
}
|
|
766
769
|
return contentParts;
|
|
767
770
|
}
|
|
771
|
+
function createDocumentTextPart() {
|
|
772
|
+
return {
|
|
773
|
+
type: "text",
|
|
774
|
+
text: "A PDF document was attached, but this api cannot send PDF inputs directly. Analyze using other tools."
|
|
775
|
+
};
|
|
776
|
+
}
|
|
768
777
|
function translateAnthropicToolsToOpenAI(anthropicTools) {
|
|
769
778
|
if (!anthropicTools) return;
|
|
770
779
|
return anthropicTools.map((tool) => ({
|
|
@@ -1026,7 +1035,7 @@ const translateUserMessage = (message) => {
|
|
|
1026
1035
|
continue;
|
|
1027
1036
|
}
|
|
1028
1037
|
const converted = translateUserContentBlock(block);
|
|
1029
|
-
if (converted) pendingContent.push(converted);
|
|
1038
|
+
if (converted.length > 0) pendingContent.push(...converted);
|
|
1030
1039
|
}
|
|
1031
1040
|
flushPendingContent(pendingContent, items, { role: "user" });
|
|
1032
1041
|
return items;
|
|
@@ -1076,9 +1085,10 @@ const translateAssistantMessage = (message, model, applyPhase) => {
|
|
|
1076
1085
|
};
|
|
1077
1086
|
const translateUserContentBlock = (block) => {
|
|
1078
1087
|
switch (block.type) {
|
|
1079
|
-
case "text": return createTextContent(block.text);
|
|
1080
|
-
case "image": return createImageContent(block);
|
|
1081
|
-
|
|
1088
|
+
case "text": return [createTextContent(block.text)];
|
|
1089
|
+
case "image": return [createImageContent(block)];
|
|
1090
|
+
case "document": return [createFileContent(block)];
|
|
1091
|
+
default: return [];
|
|
1082
1092
|
}
|
|
1083
1093
|
};
|
|
1084
1094
|
const translateAssistantContentBlock = (block) => {
|
|
@@ -1122,6 +1132,11 @@ const createImageContent = (block) => ({
|
|
|
1122
1132
|
image_url: `data:${block.source.media_type};base64,${block.source.data}`,
|
|
1123
1133
|
detail: "auto"
|
|
1124
1134
|
});
|
|
1135
|
+
const createFileContent = (block) => ({
|
|
1136
|
+
type: "input_file",
|
|
1137
|
+
file_data: `data:${block.source.media_type};base64,${block.source.data}`,
|
|
1138
|
+
filename: block.title ?? "document.pdf"
|
|
1139
|
+
});
|
|
1125
1140
|
const createReasoningContent = (block) => {
|
|
1126
1141
|
const { encryptedContent, id } = parseReasoningSignature(block.signature);
|
|
1127
1142
|
const thinking = block.thinking === THINKING_TEXT$1 ? "" : block.thinking;
|
|
@@ -1373,6 +1388,9 @@ const convertToolResultContent = (content) => {
|
|
|
1373
1388
|
case "image":
|
|
1374
1389
|
result.push(createImageContent(block));
|
|
1375
1390
|
break;
|
|
1391
|
+
case "document":
|
|
1392
|
+
result.push(createFileContent(block));
|
|
1393
|
+
break;
|
|
1376
1394
|
case "tool_reference":
|
|
1377
1395
|
result.push(createTextContent(`Tool ${block.tool_name} loaded`));
|
|
1378
1396
|
break;
|
|
@@ -1989,6 +2007,48 @@ const mergeContentWithTexts = (tr, textBlocks) => {
|
|
|
1989
2007
|
content: [...tr.content, ...textBlocks]
|
|
1990
2008
|
};
|
|
1991
2009
|
};
|
|
2010
|
+
const mergeContentWithAttachments = (tr, attachments) => {
|
|
2011
|
+
if (typeof tr.content === "string") return {
|
|
2012
|
+
...tr,
|
|
2013
|
+
content: [{
|
|
2014
|
+
type: "text",
|
|
2015
|
+
text: tr.content
|
|
2016
|
+
}, ...attachments]
|
|
2017
|
+
};
|
|
2018
|
+
return {
|
|
2019
|
+
...tr,
|
|
2020
|
+
content: [...tr.content, ...attachments]
|
|
2021
|
+
};
|
|
2022
|
+
};
|
|
2023
|
+
const isAttachmentBlock = (block) => {
|
|
2024
|
+
return block.type === "image" || block.type === "document";
|
|
2025
|
+
};
|
|
2026
|
+
const mergeAttachmentsIntoLastToolResult = (content) => {
|
|
2027
|
+
const attachments = content.filter((block) => isAttachmentBlock(block));
|
|
2028
|
+
if (attachments.length === 0) return content;
|
|
2029
|
+
const mergeableToolResultIndices = content.flatMap((block, index) => block.type === "tool_result" && !hasToolRef(block) ? [index] : []);
|
|
2030
|
+
if (mergeableToolResultIndices.length === 0) return content;
|
|
2031
|
+
const attachmentsByToolResultIndex = /* @__PURE__ */ new Map();
|
|
2032
|
+
if (mergeableToolResultIndices.length === attachments.length) for (const [index, toolResultIndex] of mergeableToolResultIndices.entries()) attachmentsByToolResultIndex.set(toolResultIndex, [attachments[index]]);
|
|
2033
|
+
else {
|
|
2034
|
+
const lastToolResultIndex = mergeableToolResultIndices.at(-1);
|
|
2035
|
+
if (lastToolResultIndex === void 0) return content;
|
|
2036
|
+
attachmentsByToolResultIndex.set(lastToolResultIndex, attachments);
|
|
2037
|
+
}
|
|
2038
|
+
const mergedContent = [];
|
|
2039
|
+
for (const [index, block] of content.entries()) {
|
|
2040
|
+
if (isAttachmentBlock(block)) continue;
|
|
2041
|
+
if (block.type === "tool_result") {
|
|
2042
|
+
const matchedAttachments = attachmentsByToolResultIndex.get(index);
|
|
2043
|
+
if (matchedAttachments) {
|
|
2044
|
+
mergedContent.push(mergeContentWithAttachments(block, matchedAttachments));
|
|
2045
|
+
continue;
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
mergedContent.push(block);
|
|
2049
|
+
}
|
|
2050
|
+
return mergedContent;
|
|
2051
|
+
};
|
|
1992
2052
|
const mergeToolResult = (toolResults, textBlocks) => {
|
|
1993
2053
|
if (toolResults.length === textBlocks.length) return toolResults.map((tr, i) => mergeContentWithText(tr, textBlocks[i]));
|
|
1994
2054
|
const lastIndex = toolResults.length - 1;
|
|
@@ -2006,6 +2066,7 @@ const mergeToolResultForClaude = (anthropicPayload, options) => {
|
|
|
2006
2066
|
for (const [index, msg] of anthropicPayload.messages.entries()) {
|
|
2007
2067
|
if (options?.skipLastMessage && index === lastMessageIndex) continue;
|
|
2008
2068
|
if (msg.role !== "user" || !Array.isArray(msg.content)) continue;
|
|
2069
|
+
msg.content = mergeAttachmentsIntoLastToolResult(msg.content);
|
|
2009
2070
|
const toolResults = [];
|
|
2010
2071
|
const textBlocks = [];
|
|
2011
2072
|
let valid = true;
|
|
@@ -2022,7 +2083,7 @@ const mergeToolResultForClaude = (anthropicPayload, options) => {
|
|
|
2022
2083
|
const sanitizeIdeTools = (payload) => {
|
|
2023
2084
|
if (!payload.tools || payload.tools.length === 0) return;
|
|
2024
2085
|
payload.tools = payload.tools.flatMap((tool) => {
|
|
2025
|
-
if (tool.name === IDE_EXECUTE_CODE_TOOL) return [];
|
|
2086
|
+
if (tool.name === IDE_EXECUTE_CODE_TOOL && !tool.defer_loading) return [];
|
|
2026
2087
|
if (tool.name === IDE_GET_DIAGNOSTICS_TOOL) return [{
|
|
2027
2088
|
...tool,
|
|
2028
2089
|
description: IDE_GET_DIAGNOSTICS_DESCRIPTION
|
|
@@ -3035,4 +3096,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
|
|
|
3035
3096
|
|
|
3036
3097
|
//#endregion
|
|
3037
3098
|
export { server };
|
|
3038
|
-
//# sourceMappingURL=server-
|
|
3099
|
+
//# sourceMappingURL=server-wOqxNjw_.js.map
|