@nick3/copilot-api 1.6.9 → 1.7.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/dist/{accounts-manager-BNVadA3o.js → accounts-manager-Ca9IG0Fv.js} +10 -3
- package/dist/accounts-manager-Ca9IG0Fv.js.map +1 -0
- package/dist/main.js +1 -1
- package/dist/{server-BhOhCgni.js → server-DT8b_Z5j.js} +25 -7
- package/dist/server-DT8b_Z5j.js.map +1 -0
- package/dist/{start-DRl19gqI.js → start-Dayo0B2n.js} +3 -3
- package/dist/{start-DRl19gqI.js.map → start-Dayo0B2n.js.map} +1 -1
- package/package.json +1 -1
- package/dist/accounts-manager-BNVadA3o.js.map +0 -1
- package/dist/server-BhOhCgni.js.map +0 -1
|
@@ -3,7 +3,7 @@ import { _ as DEFAULT_IDENTITY_ENTERPRISE_DOMAIN, a as getAccountClientIdentityB
|
|
|
3
3
|
import { r as ensurePaths, t as PATHS } from "./paths-DGlr310R.js";
|
|
4
4
|
import "./get-copilot-token-COIPGosP.js";
|
|
5
5
|
import { i as getRequestOutboundStore, r as getRedactedHeaderKeys } from "./request-outbound-qyTeXbzy.js";
|
|
6
|
-
import { A as isMessageStartInputTokensFallbackEnabled, C as getModelAliasesInfo, D as getSmallModel, E as getReasoningEffortForModel, F as resolveModelAlias, I as shouldCompactUseSmallModel, M as isResponsesApiContextManagementModel, N as isResponsesApiWebSearchEnabled, O as isAccountAffinityEnabled, P as mergeConfigWithDefaults, S as getModelAliases, T as getProviderConfig, _ as getAnthropicApiKey, a as getClientIpInfo, b as getExtraPromptForModel, c as normalizeChatCompletionsUsage, d as toLocalDateString, f as copilotFetch, g as getAliasTargetSet, h as PROVIDER_TYPE_ANTHROPIC, i as extractResponsesUsageFromStreamEvent, j as isMessagesApiEnabled, k as isForceAgentEnabled, l as normalizeEmbeddingsUsage, m as isDevModeEnabled, n as applySharedSessionAffinityRetention, o as getRequestHistoryStore, p as flushPendingCapture, r as extractResponsesUsageFromResult, s as getStatsStore, t as accountsManager, u as normalizeMessagesUsage, v as getClaudeTokenMultiplier, w as getModelRefreshIntervalMs, x as getLogLevel, y as getConfig } from "./accounts-manager-
|
|
6
|
+
import { A as isMessageStartInputTokensFallbackEnabled, C as getModelAliasesInfo, D as getSmallModel, E as getReasoningEffortForModel, F as resolveModelAlias, I as shouldCompactUseSmallModel, M as isResponsesApiContextManagementModel, N as isResponsesApiWebSearchEnabled, O as isAccountAffinityEnabled, P as mergeConfigWithDefaults, S as getModelAliases, T as getProviderConfig, _ as getAnthropicApiKey, a as getClientIpInfo, b as getExtraPromptForModel, c as normalizeChatCompletionsUsage, d as toLocalDateString, f as copilotFetch, g as getAliasTargetSet, h as PROVIDER_TYPE_ANTHROPIC, i as extractResponsesUsageFromStreamEvent, j as isMessagesApiEnabled, k as isForceAgentEnabled, l as normalizeEmbeddingsUsage, m as isDevModeEnabled, n as applySharedSessionAffinityRetention, o as getRequestHistoryStore, p as flushPendingCapture, r as extractResponsesUsageFromResult, s as getStatsStore, t as accountsManager, u as normalizeMessagesUsage, v as getClaudeTokenMultiplier, w as getModelRefreshIntervalMs, x as getLogLevel, y as getConfig } from "./accounts-manager-Ca9IG0Fv.js";
|
|
7
7
|
import consola from "consola";
|
|
8
8
|
import fs, { readFile } from "node:fs/promises";
|
|
9
9
|
import { randomUUID, timingSafeEqual } from "node:crypto";
|
|
@@ -675,11 +675,18 @@ const getTokenCount = async (payload, model) => {
|
|
|
675
675
|
const COMPACT_REQUEST = 1;
|
|
676
676
|
const COMPACT_AUTO_CONTINUE = 2;
|
|
677
677
|
const compactSystemPromptStart = "You are a helpful AI assistant tasked with summarizing conversations";
|
|
678
|
+
const compactOpenCodeSystemPromptStart = "You are an anchored context summarization assistant for coding sessions.";
|
|
679
|
+
const compactSystemPromptStarts = [compactSystemPromptStart, compactOpenCodeSystemPromptStart];
|
|
678
680
|
const compactTextOnlyGuard = "CRITICAL: Respond with TEXT ONLY. Do NOT call any tools.";
|
|
679
681
|
const compactSummaryPromptStart = "Your task is to create a detailed summary of the conversation so far";
|
|
680
682
|
const compactAutoContinueClaudeCodePromptStart = "This session is being continued from a previous conversation that ran out of context. The summary below covers the earlier portion of the conversation.";
|
|
681
683
|
const compactAutoContinueOpenCodePromptStart = "Continue if you have next steps, or stop and ask for clarification if you are unsure how to proceed.";
|
|
682
|
-
const
|
|
684
|
+
const compactAutoContinueOpenCodePromptStart2 = "The previous request exceeded the provider's size limit due to large media attachments. The conversation was compacted and media files were removed from context.";
|
|
685
|
+
const compactAutoContinuePromptStarts = [
|
|
686
|
+
compactAutoContinueClaudeCodePromptStart,
|
|
687
|
+
compactAutoContinueOpenCodePromptStart,
|
|
688
|
+
compactAutoContinueOpenCodePromptStart2
|
|
689
|
+
];
|
|
683
690
|
const compactMessageSections = ["Pending Tasks:", "Current Work:"];
|
|
684
691
|
|
|
685
692
|
//#endregion
|
|
@@ -708,9 +715,9 @@ const getCompactType = (anthropicPayload) => {
|
|
|
708
715
|
if (lastMessage && isCompactMessage(lastMessage)) return COMPACT_REQUEST;
|
|
709
716
|
if (lastMessage && isCompactAutoContinueMessage(lastMessage)) return COMPACT_AUTO_CONTINUE;
|
|
710
717
|
const system = anthropicPayload.system;
|
|
711
|
-
if (typeof system === "string") return system.startsWith(
|
|
718
|
+
if (typeof system === "string") return compactSystemPromptStarts.some((promptStart) => system.startsWith(promptStart)) ? COMPACT_REQUEST : 0;
|
|
712
719
|
if (!Array.isArray(system)) return 0;
|
|
713
|
-
if (system.some((msg) => typeof msg.text === "string" && msg.text.startsWith(
|
|
720
|
+
if (system.some((msg) => typeof msg.text === "string" && compactSystemPromptStarts.some((promptStart) => msg.text.startsWith(promptStart)))) return COMPACT_REQUEST;
|
|
714
721
|
return 0;
|
|
715
722
|
};
|
|
716
723
|
const mergeContentWithText = (tr, textBlock) => {
|
|
@@ -6306,10 +6313,14 @@ async function streamChatCompletionsAndLog(params) {
|
|
|
6306
6313
|
});
|
|
6307
6314
|
}
|
|
6308
6315
|
}
|
|
6316
|
+
function invalidateAffinityOnOwnershipMismatch(ownershipMismatch, instr) {
|
|
6317
|
+
if (ownershipMismatch && instr.affinityHit && instr.affinityCacheKey) accountsManager.invalidateAffinity(instr.affinityCacheKey);
|
|
6318
|
+
}
|
|
6309
6319
|
async function handleResponsesCreateError(params) {
|
|
6310
6320
|
const { error, instr, stream } = params;
|
|
6311
6321
|
const finishedAtMs = Date.now();
|
|
6312
6322
|
const details = await extractErrorObservability(error);
|
|
6323
|
+
invalidateAffinityOnOwnershipMismatch(details.ownershipMismatch, instr);
|
|
6313
6324
|
if (shouldMarkAccountFailed(details)) accountsManager.markAccountFailed(instr.account.id, "Unauthorized (401)");
|
|
6314
6325
|
const { premiumRemainingAfter, premiumUnlimitedAfter, premiumRemainingDiff } = await finalizeQuotaAndGetPremiumSnapshot(instr);
|
|
6315
6326
|
insertRequestLog$1(instr, {
|
|
@@ -6450,6 +6461,7 @@ async function streamResponsesAndLog$1(params) {
|
|
|
6450
6461
|
errorMessage = details.errorMessage;
|
|
6451
6462
|
upstreamErrorMessageRaw = details.upstreamErrorMessageRaw;
|
|
6452
6463
|
logger$5.warn("Streaming error:", error);
|
|
6464
|
+
invalidateAffinityOnOwnershipMismatch(details.ownershipMismatch, instr);
|
|
6453
6465
|
if (shouldMarkAccountFailed(details)) accountsManager.markAccountFailed(instr.account.id, "Unauthorized (401)");
|
|
6454
6466
|
await writeAnthropicStreamError(stream, getUserVisibleErrorMessage(details));
|
|
6455
6467
|
} finally {
|
|
@@ -7073,8 +7085,9 @@ const handleResponses = async (c) => {
|
|
|
7073
7085
|
premiumUnlimitedBefore
|
|
7074
7086
|
});
|
|
7075
7087
|
};
|
|
7076
|
-
async function observeRequestError(accountId, error) {
|
|
7088
|
+
async function observeRequestError(accountId, error, affinity) {
|
|
7077
7089
|
const details = await extractErrorObservability(error);
|
|
7090
|
+
if (details.ownershipMismatch && affinity?.affinityHit && affinity.affinityCacheKey) accountsManager.invalidateAffinity(affinity.affinityCacheKey);
|
|
7078
7091
|
if (shouldMarkAccountFailed(details)) accountsManager.markAccountFailed(accountId, "Unauthorized (401)");
|
|
7079
7092
|
return {
|
|
7080
7093
|
httpStatus: details.httpStatus,
|
|
@@ -7228,6 +7241,7 @@ async function handleUpstreamCreateError(params) {
|
|
|
7228
7241
|
const { account, reservation, selectedModel, endpoint, costUnits } = selection;
|
|
7229
7242
|
const finishedAtMs = Date.now();
|
|
7230
7243
|
const details = await extractErrorObservability(error);
|
|
7244
|
+
if (details.ownershipMismatch && request.affinityHit && request.affinityCacheKey) accountsManager.invalidateAffinity(request.affinityCacheKey);
|
|
7231
7245
|
if (shouldMarkAccountFailed(details)) accountsManager.markAccountFailed(account.id, "Unauthorized (401)");
|
|
7232
7246
|
await accountsManager.finalizeQuota(account, reservation);
|
|
7233
7247
|
const premiumRemainingAfter = account.premiumRemaining;
|
|
@@ -7338,6 +7352,7 @@ async function streamResponsesAndLog(params) {
|
|
|
7338
7352
|
errorMessage = details.errorMessage;
|
|
7339
7353
|
upstreamErrorMessageRaw = details.upstreamErrorMessageRaw;
|
|
7340
7354
|
logger$1.warn("Responses streaming error:", error);
|
|
7355
|
+
if (details.ownershipMismatch && request.affinityHit && request.affinityCacheKey) accountsManager.invalidateAffinity(request.affinityCacheKey);
|
|
7341
7356
|
if (shouldMarkAccountFailed(details)) accountsManager.markAccountFailed(account.id, "Unauthorized (401)");
|
|
7342
7357
|
await writeResponsesStreamError(stream, getUserVisibleErrorMessage(details));
|
|
7343
7358
|
} finally {
|
|
@@ -7396,7 +7411,10 @@ async function handleNonStreamingResponses(params) {
|
|
|
7396
7411
|
return c.json(result);
|
|
7397
7412
|
} catch (error) {
|
|
7398
7413
|
finishedAtMs = Date.now();
|
|
7399
|
-
errorState = await observeRequestError(account.id, error
|
|
7414
|
+
errorState = await observeRequestError(account.id, error, {
|
|
7415
|
+
affinityHit: request.affinityHit,
|
|
7416
|
+
affinityCacheKey: request.affinityCacheKey
|
|
7417
|
+
});
|
|
7400
7418
|
throw error;
|
|
7401
7419
|
} finally {
|
|
7402
7420
|
const finishedAtMsFinal = finishedAtMs ?? Date.now();
|
|
@@ -7534,4 +7552,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
|
|
|
7534
7552
|
|
|
7535
7553
|
//#endregion
|
|
7536
7554
|
export { server };
|
|
7537
|
-
//# sourceMappingURL=server-
|
|
7555
|
+
//# sourceMappingURL=server-DT8b_Z5j.js.map
|