@nick3/copilot-api 1.1.8 → 1.2.1
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/README.md +2 -2
- package/dist/{accounts-manager-CB2fKUZ_.js → accounts-manager-BY_xYGQ7.js} +3 -15
- package/dist/accounts-manager-BY_xYGQ7.js.map +1 -0
- package/dist/main.js +3 -3
- package/dist/main.js.map +1 -1
- package/dist/{server-D5lMSTsD.js → server-B6nFgTkW.js} +36 -7
- package/dist/{server-D5lMSTsD.js.map → server-B6nFgTkW.js.map} +1 -1
- package/package.json +3 -2
- package/pages/index.html +556 -0
- package/dist/accounts-manager-CB2fKUZ_.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { HTTPError, PATHS, accountFromState, accountsManager, copilotBaseUrl, copilotHeaders, forwardError, getAliasTargetSet, getConfig, getCopilotUsage, getExtraPromptForModel, getModelAliases, getModelAliasesInfo, getModelRefreshIntervalMs, getReasoningEffortForModel, getSmallModel, isForceAgentEnabled, isFreeModelLoadBalancingEnabled, isMessageStartInputTokensFallbackEnabled, isNullish, listAccountsFromRegistry, mergeConfigWithDefaults, shouldCompactUseSmallModel, sleep, state } from "./accounts-manager-
|
|
1
|
+
import { HTTPError, PATHS, accountFromState, accountsManager, copilotBaseUrl, copilotHeaders, forwardError, getAliasTargetSet, getConfig, getCopilotUsage, getExtraPromptForModel, getModelAliases, getModelAliasesInfo, getModelRefreshIntervalMs, getReasoningEffortForModel, getSmallModel, isForceAgentEnabled, isFreeModelLoadBalancingEnabled, isMessageStartInputTokensFallbackEnabled, isNullish, listAccountsFromRegistry, mergeConfigWithDefaults, shouldCompactUseSmallModel, sleep, state } from "./accounts-manager-BY_xYGQ7.js";
|
|
2
2
|
import consola from "consola";
|
|
3
3
|
import fs, { readFile } from "node:fs/promises";
|
|
4
4
|
import * as path$1 from "node:path";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { randomUUID, timingSafeEqual } from "node:crypto";
|
|
7
|
-
import fs$1, { existsSync } from "node:fs";
|
|
7
|
+
import fs$1, { existsSync, readFileSync } from "node:fs";
|
|
8
8
|
import { Hono } from "hono";
|
|
9
9
|
import { cors } from "hono/cors";
|
|
10
10
|
import { logger } from "hono/logger";
|
|
@@ -4087,6 +4087,23 @@ const getMessagesInitiator = (payload) => {
|
|
|
4087
4087
|
if (!Array.isArray(lastMessage.content)) return "user";
|
|
4088
4088
|
return lastMessage.content.some((block) => block.type !== "tool_result") ? "user" : "agent";
|
|
4089
4089
|
};
|
|
4090
|
+
const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
4091
|
+
const allowedAnthropicBetas = new Set([
|
|
4092
|
+
INTERLEAVED_THINKING_BETA,
|
|
4093
|
+
"context-management-2025-06-27",
|
|
4094
|
+
"advanced-tool-use-2025-11-20"
|
|
4095
|
+
]);
|
|
4096
|
+
const buildAnthropicBetaHeader = (anthropicBetaHeader, thinking) => {
|
|
4097
|
+
const isAdaptiveThinking = thinking?.type === "adaptive";
|
|
4098
|
+
if (anthropicBetaHeader) {
|
|
4099
|
+
const filteredBeta = anthropicBetaHeader.split(",").map((item) => item.trim()).filter((item) => item.length > 0).filter((item) => allowedAnthropicBetas.has(item));
|
|
4100
|
+
const uniqueFilteredBetas = [...new Set(filteredBeta)];
|
|
4101
|
+
const finalFilteredBetas = isAdaptiveThinking ? uniqueFilteredBetas.filter((item) => item !== INTERLEAVED_THINKING_BETA) : uniqueFilteredBetas;
|
|
4102
|
+
if (finalFilteredBetas.length > 0) return finalFilteredBetas.join(",");
|
|
4103
|
+
return;
|
|
4104
|
+
}
|
|
4105
|
+
if (thinking?.budget_tokens && !isAdaptiveThinking) return INTERLEAVED_THINKING_BETA;
|
|
4106
|
+
};
|
|
4090
4107
|
const createMessages = async (payload, account, options) => {
|
|
4091
4108
|
const ctx = account ?? accountFromState();
|
|
4092
4109
|
if (!ctx.copilotToken) throw new Error("Copilot token not found");
|
|
@@ -4096,9 +4113,8 @@ const createMessages = async (payload, account, options) => {
|
|
|
4096
4113
|
...copilotHeaders(ctx, enableVision, options?.upstreamRequestId),
|
|
4097
4114
|
"X-Initiator": initiator
|
|
4098
4115
|
};
|
|
4099
|
-
const
|
|
4100
|
-
if (
|
|
4101
|
-
else if (payload.thinking?.budget_tokens) headers["anthropic-beta"] = "interleaved-thinking-2025-05-14";
|
|
4116
|
+
const anthropicBeta = buildAnthropicBetaHeader(options?.anthropicBetaHeader, payload.thinking);
|
|
4117
|
+
if (anthropicBeta) headers["anthropic-beta"] = anthropicBeta;
|
|
4102
4118
|
const response = await fetch(`${copilotBaseUrl(ctx)}/v1/messages`, {
|
|
4103
4119
|
method: "POST",
|
|
4104
4120
|
headers,
|
|
@@ -4503,6 +4519,7 @@ async function handleCompletion(c) {
|
|
|
4503
4519
|
});
|
|
4504
4520
|
const { account, reservation, selectedModel, endpoint, costUnits } = selection;
|
|
4505
4521
|
openAIPayload.model = selectedModel.id;
|
|
4522
|
+
anthropicPayload.model = selectedModel.id;
|
|
4506
4523
|
const premiumRemainingBefore = account.premiumRemaining;
|
|
4507
4524
|
const premiumUnlimitedBefore = account.unlimited;
|
|
4508
4525
|
if (state.manualApprove) await awaitApproval();
|
|
@@ -5727,8 +5744,20 @@ usageRoute.get("/:accountIndex", async (c) => {
|
|
|
5727
5744
|
const server = new Hono();
|
|
5728
5745
|
server.use(logger());
|
|
5729
5746
|
server.use(cors());
|
|
5730
|
-
server.use("*", createAuthMiddleware({
|
|
5747
|
+
server.use("*", createAuthMiddleware({
|
|
5748
|
+
allowUnauthenticatedPaths: [
|
|
5749
|
+
"/",
|
|
5750
|
+
"/usage-viewer",
|
|
5751
|
+
"/usage-viewer/"
|
|
5752
|
+
],
|
|
5753
|
+
allowUnauthenticatedPathPrefixes: ["/admin", "/api/admin"]
|
|
5754
|
+
}));
|
|
5731
5755
|
server.get("/", (c) => c.text("Server running"));
|
|
5756
|
+
server.get("/usage-viewer", (c) => {
|
|
5757
|
+
const usageViewerFileUrl = new URL("../pages/index.html", import.meta.url);
|
|
5758
|
+
return c.html(readFileSync(usageViewerFileUrl, "utf8"));
|
|
5759
|
+
});
|
|
5760
|
+
server.get("/usage-viewer/", (c) => c.redirect("/usage-viewer", 301));
|
|
5732
5761
|
server.route("/chat/completions", completionRoutes);
|
|
5733
5762
|
server.route("/models", modelRoutes);
|
|
5734
5763
|
server.route("/embeddings", embeddingRoutes);
|
|
@@ -5745,4 +5774,4 @@ server.route("/v1/messages", messageRoutes);
|
|
|
5745
5774
|
|
|
5746
5775
|
//#endregion
|
|
5747
5776
|
export { server };
|
|
5748
|
-
//# sourceMappingURL=server-
|
|
5777
|
+
//# sourceMappingURL=server-B6nFgTkW.js.map
|