@jeffreycao/copilot-api 1.11.2 → 1.11.4
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--yUElsYz.js → server-BKXMXGoo.js} +61 -28
- package/dist/server-BKXMXGoo.js.map +1 -0
- package/dist/{start-CUCHCtOg.js → start-Bxn62Q9K.js} +2 -2
- package/dist/{start-CUCHCtOg.js.map → start-Bxn62Q9K.js.map} +1 -1
- package/package.json +1 -1
- package/dist/server--yUElsYz.js.map +0 -1
package/dist/main.js
CHANGED
|
@@ -43,7 +43,7 @@ const { auth } = await import("./auth-D3ta3JW0.js");
|
|
|
43
43
|
const { checkUsage } = await import("./check-usage-Dh0WqiLC.js");
|
|
44
44
|
const { debug } = await import("./debug-BiX0ewij.js");
|
|
45
45
|
const { mcp } = await import("./mcp-DZgcvqQY.js");
|
|
46
|
-
const { start } = await import("./start-
|
|
46
|
+
const { start } = await import("./start-Bxn62Q9K.js");
|
|
47
47
|
await runMain(defineCommand({
|
|
48
48
|
meta: {
|
|
49
49
|
name: "copilot-api",
|
|
@@ -1918,6 +1918,18 @@ function getAnthropicToolUseBlocks(toolCalls) {
|
|
|
1918
1918
|
}
|
|
1919
1919
|
//#endregion
|
|
1920
1920
|
//#region src/lib/models.ts
|
|
1921
|
+
/**
|
|
1922
|
+
* Converts a Copilot upstream model ID to a client-friendly ID that Claude Code
|
|
1923
|
+
* and Claude Desktop recognize (dots in version replaced with hyphens).
|
|
1924
|
+
* e.g. "claude-sonnet-4.6" -> "claude-sonnet-4-6"
|
|
1925
|
+
* Non-Claude models are returned unchanged.
|
|
1926
|
+
*/
|
|
1927
|
+
const toClientModelId = (modelId) => {
|
|
1928
|
+
const normalized = normalizeSdkModelId(modelId);
|
|
1929
|
+
if (!normalized) return modelId;
|
|
1930
|
+
const versionHyphenated = normalized.version.replace(/\./g, "-");
|
|
1931
|
+
return `claude-${normalized.family}-${versionHyphenated}`;
|
|
1932
|
+
};
|
|
1921
1933
|
const findEndpointModel = (sdkModelId) => {
|
|
1922
1934
|
const models = state.models?.data ?? [];
|
|
1923
1935
|
const exactMatch = models.find((m) => m.id === sdkModelId);
|
|
@@ -2343,7 +2355,7 @@ const prepareMessagesApiPayload = (payload, selectedModel) => {
|
|
|
2343
2355
|
payload.thinking = { type: "adaptive" };
|
|
2344
2356
|
if (!hasThinking) payload.thinking.display = "summarized";
|
|
2345
2357
|
if (shouldSummarizeThinkingDisplayForModel(payload.model)) payload.thinking.display = "summarized";
|
|
2346
|
-
let effort = getReasoningEffortForModel(payload.model);
|
|
2358
|
+
let effort = payload.output_config?.effort ?? getReasoningEffortForModel(payload.model);
|
|
2347
2359
|
if (effort === "none" || effort === "minimal") effort = "low";
|
|
2348
2360
|
const reasoningEffort = selectedModel.capabilities.supports.reasoning_effort;
|
|
2349
2361
|
if (reasoningEffort && !reasoningEffort.includes(effort)) effort = reasoningEffort.at(-1);
|
|
@@ -5666,10 +5678,11 @@ modelRoutes.get("/", async (c) => {
|
|
|
5666
5678
|
try {
|
|
5667
5679
|
if (!state.models) await cacheModels();
|
|
5668
5680
|
const models = state.models?.data.map((model) => {
|
|
5669
|
-
const
|
|
5681
|
+
const contextWindow = model.capabilities?.limits?.max_context_window_tokens ?? 0;
|
|
5682
|
+
const clientId = toClientModelId(model.id);
|
|
5670
5683
|
return {
|
|
5671
5684
|
...model,
|
|
5672
|
-
id:
|
|
5685
|
+
id: contextWindow > 1e6 ? `${clientId}[1m]` : clientId,
|
|
5673
5686
|
object: "model",
|
|
5674
5687
|
type: "model",
|
|
5675
5688
|
created: 0,
|
|
@@ -5791,34 +5804,54 @@ const createProviderResponsesUsageRecorder = (payload, provider) => {
|
|
|
5791
5804
|
sessionId: sessionAffinity ?? ""
|
|
5792
5805
|
});
|
|
5793
5806
|
};
|
|
5794
|
-
const streamProviderResponses = (c, upstreamResponse, options) => {
|
|
5807
|
+
const streamProviderResponses = async (c, upstreamResponse, options) => {
|
|
5808
|
+
const iterator = upstreamResponse[Symbol.asyncIterator]();
|
|
5809
|
+
const firstResult = await iterator.next();
|
|
5810
|
+
if (firstResult.done) throw new HTTPError(`Empty stream from ${options.provider} responses`, new Response("", { status: 502 }));
|
|
5811
|
+
const firstChunk = firstResult.value;
|
|
5812
|
+
if (firstChunk.data && firstChunk.data !== "[DONE]") {
|
|
5813
|
+
const event = parseProviderResponsesStreamEvent(firstChunk.data, {
|
|
5814
|
+
normalizeCodex: options.normalizeCodex,
|
|
5815
|
+
provider: options.provider
|
|
5816
|
+
});
|
|
5817
|
+
if (event?.type === "error") {
|
|
5818
|
+
const errorEvent = event;
|
|
5819
|
+
const statusCode = errorEvent.status_code ?? 500;
|
|
5820
|
+
return c.json({ error: {
|
|
5821
|
+
message: errorEvent.message,
|
|
5822
|
+
...errorEvent.error
|
|
5823
|
+
} }, statusCode, errorEvent.headers ?? void 0);
|
|
5824
|
+
}
|
|
5825
|
+
}
|
|
5795
5826
|
return streamSSE(c, async (stream) => {
|
|
5796
5827
|
let usage = {};
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
provider: options.provider
|
|
5806
|
-
});
|
|
5807
|
-
if (event && options.normalizeCodex) responseChunk = {
|
|
5808
|
-
...chunk,
|
|
5809
|
-
data: JSON.stringify(event),
|
|
5810
|
-
event: event.type
|
|
5811
|
-
};
|
|
5812
|
-
}
|
|
5813
|
-
if (event) {
|
|
5814
|
-
const nextUsage = getResponsesStreamEventUsage(event);
|
|
5815
|
-
if (nextUsage) usage = nextUsage;
|
|
5816
|
-
}
|
|
5817
|
-
await stream.writeSSE({
|
|
5818
|
-
data: responseChunk.data ?? "",
|
|
5819
|
-
event: responseChunk.event
|
|
5828
|
+
const writeChunk = async (chunk) => {
|
|
5829
|
+
debugJson(logger$2, "Responses stream chunk:", chunk);
|
|
5830
|
+
let responseChunk = chunk;
|
|
5831
|
+
let event = null;
|
|
5832
|
+
if (chunk.data && chunk.data !== "[DONE]") {
|
|
5833
|
+
event = parseProviderResponsesStreamEvent(chunk.data, {
|
|
5834
|
+
normalizeCodex: options.normalizeCodex,
|
|
5835
|
+
provider: options.provider
|
|
5820
5836
|
});
|
|
5837
|
+
if (event && options.normalizeCodex) responseChunk = {
|
|
5838
|
+
...chunk,
|
|
5839
|
+
data: JSON.stringify(event),
|
|
5840
|
+
event: event.type
|
|
5841
|
+
};
|
|
5842
|
+
}
|
|
5843
|
+
if (event) {
|
|
5844
|
+
const nextUsage = getResponsesStreamEventUsage(event);
|
|
5845
|
+
if (nextUsage) usage = nextUsage;
|
|
5821
5846
|
}
|
|
5847
|
+
await stream.writeSSE({
|
|
5848
|
+
data: responseChunk.data ?? "",
|
|
5849
|
+
event: responseChunk.event
|
|
5850
|
+
});
|
|
5851
|
+
};
|
|
5852
|
+
try {
|
|
5853
|
+
await writeChunk(firstChunk);
|
|
5854
|
+
for await (const chunk of { [Symbol.asyncIterator]: () => iterator }) await writeChunk(chunk);
|
|
5822
5855
|
} finally {
|
|
5823
5856
|
options.recordUsage(usage);
|
|
5824
5857
|
}
|
|
@@ -6136,4 +6169,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
|
|
|
6136
6169
|
//#endregion
|
|
6137
6170
|
export { server };
|
|
6138
6171
|
|
|
6139
|
-
//# sourceMappingURL=server
|
|
6172
|
+
//# sourceMappingURL=server-BKXMXGoo.js.map
|