@nick3/copilot-api 1.5.9 → 1.6.0
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 +33 -30
- package/README.zh-CN.md +953 -0
- package/dist/{account-CbYMFuS4.js → account-B2tSWtVS.js} +2 -2
- package/dist/{account-CbYMFuS4.js.map → account-B2tSWtVS.js.map} +1 -1
- package/dist/{accounts-manager-BKG9aZEL.js → accounts-manager-CAyZJSn8.js} +144 -111
- package/dist/accounts-manager-CAyZJSn8.js.map +1 -0
- package/dist/admin/assets/index-BESw8Vvd.css +1 -0
- package/dist/admin/assets/index-Ddo9RHg-.js +101 -0
- package/dist/admin/index.html +2 -2
- package/dist/{auth-Ckj1wD43.js → auth-BXCeDjRG.js} +3 -3
- package/dist/{auth-Ckj1wD43.js.map → auth-BXCeDjRG.js.map} +1 -1
- package/dist/{check-usage-bIbj_1Q_.js → check-usage-CQxXYfUx.js} +3 -3
- package/dist/{check-usage-bIbj_1Q_.js.map → check-usage-CQxXYfUx.js.map} +1 -1
- package/dist/{get-copilot-token-MAZsr5Vu.js → get-copilot-token-p17sJyPU.js} +2 -2
- package/dist/{get-copilot-token-MAZsr5Vu.js.map → get-copilot-token-p17sJyPU.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{poll-access-token-DiwBJNtK.js → poll-access-token-Bc6VwWab.js} +49 -9
- package/dist/poll-access-token-Bc6VwWab.js.map +1 -0
- package/dist/{server-DAxpfPde.js → server-CFijvv3C.js} +106 -54
- package/dist/server-CFijvv3C.js.map +1 -0
- package/dist/{start-8dkfsQqd.js → start-DQlnH71A.js} +6 -6
- package/dist/{start-8dkfsQqd.js.map → start-DQlnH71A.js.map} +1 -1
- package/package.json +1 -1
- package/dist/accounts-manager-BKG9aZEL.js.map +0 -1
- package/dist/admin/assets/index-BFN8rXmt.css +0 -1
- package/dist/admin/assets/index-HnEqzcKv.js +0 -101
- package/dist/poll-access-token-DiwBJNtK.js.map +0 -1
- package/dist/server-DAxpfPde.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { _ as DEFAULT_IDENTITY_ENTERPRISE_DOMAIN, a as getAccountClientIdentityByLoginAndApp, b as getCurrentIdentityEnvironment, d as loadRegistry, g as saveRegistry, h as saveAccountToken, l as listAccountsFromRegistry, m as removeAccountToken, p as removeAccountFromRegistry, r as addAccountToRegistry, t as isAccountType } from "./account-
|
|
1
|
+
import { A as captureOutboundHeadersSnapshot, D as prepareMessageProxyHeaders, E as prepareInteractionHeaders, M as requestContext, N as resolveTraceId, O as accountFromState, T as prepareForCompact, _ as HTTPError, b as copilotHeaders, c as getUUID, d as parseUserIdMetadata, f as resolveAffinityKey, g as getCopilotUsage, h as getDeviceCode, k as state, l as isNullish, m as getGitHubUser, o as generateRequestIdFromPayload, p as sleep, s as getRootSessionId, t as pollAccessToken, u as normalizeStableSessionId, v as forwardError, w as normalizeDomain, y as copilotBaseUrl } from "./poll-access-token-Bc6VwWab.js";
|
|
2
|
+
import { _ as DEFAULT_IDENTITY_ENTERPRISE_DOMAIN, a as getAccountClientIdentityByLoginAndApp, b as getCurrentIdentityEnvironment, d as loadRegistry, g as saveRegistry, h as saveAccountToken, l as listAccountsFromRegistry, m as removeAccountToken, p as removeAccountFromRegistry, r as addAccountToRegistry, t as isAccountType } from "./account-B2tSWtVS.js";
|
|
3
3
|
import { r as ensurePaths, t as PATHS } from "./paths-DGlr310R.js";
|
|
4
|
-
import "./get-copilot-token-
|
|
5
|
-
import { A as isResponsesApiWebSearchEnabled, C as getReasoningEffortForModel, D as isMessageStartInputTokensFallbackEnabled, E as isForceAgentEnabled, M as resolveModelAlias, N as shouldCompactUseSmallModel, O as isMessagesApiEnabled, S as getProviderConfig, T as isAccountAffinityEnabled, _ as getExtraPromptForModel, a as getClientIpInfo, b as getModelAliasesInfo, c as normalizeChatCompletionsUsage, d as toLocalDateString, f as PROVIDER_TYPE_ANTHROPIC, g as getConfig, h as getClaudeTokenMultiplier, i as extractResponsesUsageFromStreamEvent, j as mergeConfigWithDefaults, k as isResponsesApiContextManagementModel, l as normalizeEmbeddingsUsage, m as getAnthropicApiKey, n as applySharedSessionAffinityRetention, o as getRequestHistoryStore, p as getAliasTargetSet, r as extractResponsesUsageFromResult, s as getStatsStore, t as accountsManager, u as normalizeMessagesUsage, v as getLogLevel, w as getSmallModel, x as getModelRefreshIntervalMs, y as getModelAliases } from "./accounts-manager-
|
|
4
|
+
import "./get-copilot-token-p17sJyPU.js";
|
|
5
|
+
import { A as isResponsesApiWebSearchEnabled, C as getReasoningEffortForModel, D as isMessageStartInputTokensFallbackEnabled, E as isForceAgentEnabled, M as resolveModelAlias, N as shouldCompactUseSmallModel, O as isMessagesApiEnabled, S as getProviderConfig, T as isAccountAffinityEnabled, _ as getExtraPromptForModel, a as getClientIpInfo, b as getModelAliasesInfo, c as normalizeChatCompletionsUsage, d as toLocalDateString, f as PROVIDER_TYPE_ANTHROPIC, g as getConfig, h as getClaudeTokenMultiplier, i as extractResponsesUsageFromStreamEvent, j as mergeConfigWithDefaults, k as isResponsesApiContextManagementModel, l as normalizeEmbeddingsUsage, m as getAnthropicApiKey, n as applySharedSessionAffinityRetention, o as getRequestHistoryStore, p as getAliasTargetSet, r as extractResponsesUsageFromResult, s as getStatsStore, t as accountsManager, u as normalizeMessagesUsage, v as getLogLevel, w as getSmallModel, x as getModelRefreshIntervalMs, y as getModelAliases } from "./accounts-manager-CAyZJSn8.js";
|
|
6
6
|
import consola from "consola";
|
|
7
7
|
import fs, { readFile } from "node:fs/promises";
|
|
8
8
|
import { randomUUID, timingSafeEqual } from "node:crypto";
|
|
@@ -1181,18 +1181,16 @@ adminApiRoutes.get("/stats/premium-daily", (c) => {
|
|
|
1181
1181
|
const granularity = p.get("granularity") === "hour" ? "hour" : "day";
|
|
1182
1182
|
const now = /* @__PURE__ */ new Date();
|
|
1183
1183
|
const todayStr = toLocalDateString(now.getTime());
|
|
1184
|
-
const resolvedFrom = from || toLocalDateString(now.
|
|
1184
|
+
const resolvedFrom = from || toLocalDateString(new Date(now.getFullYear(), now.getMonth(), now.getDate() - 6).getTime());
|
|
1185
1185
|
const resolvedTo = to || todayStr;
|
|
1186
1186
|
function parseLocalDate(dateStr) {
|
|
1187
1187
|
const [y, m, d] = dateStr.split("-").map(Number);
|
|
1188
1188
|
return new Date(y, m - 1, d);
|
|
1189
1189
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
type: "bad_request"
|
|
1195
|
-
});
|
|
1190
|
+
/** DST-safe end-of-day: next local midnight minus 1 ms. */
|
|
1191
|
+
function localDateEndMs(dateStr) {
|
|
1192
|
+
const [y, m, d] = dateStr.split("-").map(Number);
|
|
1193
|
+
return new Date(y, m - 1, d + 1).getTime() - 1;
|
|
1196
1194
|
}
|
|
1197
1195
|
const statsStore = getStatsStore();
|
|
1198
1196
|
if (!statsStore) return c.json({
|
|
@@ -1205,8 +1203,21 @@ adminApiRoutes.get("/stats/premium-daily", (c) => {
|
|
|
1205
1203
|
}
|
|
1206
1204
|
});
|
|
1207
1205
|
if (granularity === "hour") {
|
|
1208
|
-
const
|
|
1209
|
-
const
|
|
1206
|
+
const clientFromMs = parseFiniteNumber(p.get("from_ms"));
|
|
1207
|
+
const clientToMs = parseFiniteNumber(p.get("to_ms"));
|
|
1208
|
+
let fromMs;
|
|
1209
|
+
let toMs;
|
|
1210
|
+
if (clientFromMs !== void 0 && clientToMs !== void 0) {
|
|
1211
|
+
fromMs = clientFromMs;
|
|
1212
|
+
toMs = clientToMs;
|
|
1213
|
+
} else {
|
|
1214
|
+
fromMs = parseLocalDate(resolvedFrom).getTime();
|
|
1215
|
+
toMs = localDateEndMs(resolvedTo);
|
|
1216
|
+
}
|
|
1217
|
+
if (toMs - fromMs > 840 * 60 * 60 * 1e3) return jsonError(c, 400, {
|
|
1218
|
+
message: "Hourly granularity is only supported for ranges up to 35 days.",
|
|
1219
|
+
type: "bad_request"
|
|
1220
|
+
});
|
|
1210
1221
|
const result$1 = statsStore.getHourlyPremiumStats({
|
|
1211
1222
|
fromMs,
|
|
1212
1223
|
toMs,
|
|
@@ -2453,7 +2464,7 @@ const createChatCompletions = async (payload, account, options) => {
|
|
|
2453
2464
|
if (!ctx.copilotToken) throw new Error("Copilot token not found");
|
|
2454
2465
|
const enableVision = payload.messages.some((x) => typeof x.content !== "string" && x.content?.some((x$1) => x$1.type === "image_url"));
|
|
2455
2466
|
const effectiveInitiator = resolveEffectiveInitiator(options?.initiator ?? getChatInitiator(payload.messages), {
|
|
2456
|
-
isCompact: options?.
|
|
2467
|
+
isCompact: Boolean(options?.compactType),
|
|
2457
2468
|
isSubagent: Boolean(options?.subagentMarker)
|
|
2458
2469
|
});
|
|
2459
2470
|
const headers = {
|
|
@@ -2462,7 +2473,8 @@ const createChatCompletions = async (payload, account, options) => {
|
|
|
2462
2473
|
};
|
|
2463
2474
|
prepareInteractionHeaders(options?.sessionId, Boolean(options?.subagentMarker), headers);
|
|
2464
2475
|
const upstreamPayload = applyDefaultReasoningEffort(payload);
|
|
2465
|
-
prepareForCompact(headers, options?.
|
|
2476
|
+
prepareForCompact(headers, options?.compactType);
|
|
2477
|
+
captureOutboundHeadersSnapshot(headers);
|
|
2466
2478
|
const response = await fetch(`${copilotBaseUrl(ctx)}/chat/completions`, {
|
|
2467
2479
|
method: "POST",
|
|
2468
2480
|
headers,
|
|
@@ -3056,9 +3068,11 @@ completionRoutes.post("/", async (c) => {
|
|
|
3056
3068
|
const createEmbeddings = async (payload, account) => {
|
|
3057
3069
|
const ctx = account ?? accountFromState();
|
|
3058
3070
|
if (!ctx.copilotToken) throw new Error("Copilot token not found");
|
|
3071
|
+
const headers = copilotHeaders(ctx);
|
|
3072
|
+
captureOutboundHeadersSnapshot(headers);
|
|
3059
3073
|
const response = await fetch(`${copilotBaseUrl(ctx)}/embeddings`, {
|
|
3060
3074
|
method: "POST",
|
|
3061
|
-
headers
|
|
3075
|
+
headers,
|
|
3062
3076
|
body: JSON.stringify(payload)
|
|
3063
3077
|
});
|
|
3064
3078
|
if (!response.ok) throw new HTTPError("Failed to create embeddings", response);
|
|
@@ -3268,12 +3282,23 @@ const _normalizeSdkModelId = (sdkModelId) => {
|
|
|
3268
3282
|
};
|
|
3269
3283
|
|
|
3270
3284
|
//#endregion
|
|
3271
|
-
//#region src/
|
|
3285
|
+
//#region src/lib/compact.ts
|
|
3286
|
+
const COMPACT_REQUEST = 1;
|
|
3287
|
+
const COMPACT_AUTO_CONTINUE = 2;
|
|
3272
3288
|
const compactSystemPromptStart = "You are a helpful AI assistant tasked with summarizing conversations";
|
|
3273
3289
|
const compactTextOnlyGuard = "CRITICAL: Respond with TEXT ONLY. Do NOT call any tools.";
|
|
3274
3290
|
const compactSummaryPromptStart = "Your task is to create a detailed summary of the conversation so far";
|
|
3291
|
+
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.";
|
|
3292
|
+
const compactAutoContinueOpenCodePromptStart = "Continue if you have next steps, or stop and ask for clarification if you are unsure how to proceed.";
|
|
3293
|
+
const compactAutoContinuePromptStarts = [compactAutoContinueClaudeCodePromptStart, compactAutoContinueOpenCodePromptStart];
|
|
3275
3294
|
const compactMessageSections = ["Pending Tasks:", "Current Work:"];
|
|
3295
|
+
|
|
3296
|
+
//#endregion
|
|
3297
|
+
//#region src/routes/messages/preprocess.ts
|
|
3276
3298
|
const TOOL_REFERENCE_TURN_BOUNDARY = "Tool loaded.";
|
|
3299
|
+
const IDE_EXECUTE_CODE_TOOL = "mcp__ide__executeCode";
|
|
3300
|
+
const IDE_GET_DIAGNOSTICS_TOOL = "mcp__ide__getDiagnostics";
|
|
3301
|
+
const IDE_GET_DIAGNOSTICS_DESCRIPTION = "Get language diagnostics from VS Code. Returns errors, warnings, information, and hints for files in the workspace.";
|
|
3277
3302
|
const getAnthropicEffortForModel = (model) => {
|
|
3278
3303
|
const reasoningEffort = getReasoningEffortForModel(model);
|
|
3279
3304
|
if (reasoningEffort === "xhigh") return "max";
|
|
@@ -3290,13 +3315,19 @@ const isCompactMessage = (lastMessage) => {
|
|
|
3290
3315
|
if (!text) return false;
|
|
3291
3316
|
return text.includes(compactTextOnlyGuard) && text.includes(compactSummaryPromptStart) && compactMessageSections.some((section) => text.includes(section));
|
|
3292
3317
|
};
|
|
3293
|
-
const
|
|
3318
|
+
const isCompactAutoContinueMessage = (lastMessage) => {
|
|
3319
|
+
const text = getCompactCandidateText(lastMessage);
|
|
3320
|
+
return Boolean(text) && compactAutoContinuePromptStarts.some((promptStart) => text.startsWith(promptStart));
|
|
3321
|
+
};
|
|
3322
|
+
const getCompactType = (anthropicPayload) => {
|
|
3294
3323
|
const lastMessage = anthropicPayload.messages.at(-1);
|
|
3295
|
-
if (lastMessage && isCompactMessage(lastMessage)) return
|
|
3324
|
+
if (lastMessage && isCompactMessage(lastMessage)) return COMPACT_REQUEST;
|
|
3325
|
+
if (lastMessage && isCompactAutoContinueMessage(lastMessage)) return COMPACT_AUTO_CONTINUE;
|
|
3296
3326
|
const system = anthropicPayload.system;
|
|
3297
|
-
if (typeof system === "string") return system.startsWith(compactSystemPromptStart);
|
|
3298
|
-
if (!Array.isArray(system)) return
|
|
3299
|
-
|
|
3327
|
+
if (typeof system === "string") return system.startsWith(compactSystemPromptStart) ? COMPACT_REQUEST : 0;
|
|
3328
|
+
if (!Array.isArray(system)) return 0;
|
|
3329
|
+
if (system.some((msg) => typeof msg.text === "string" && msg.text.startsWith(compactSystemPromptStart))) return COMPACT_REQUEST;
|
|
3330
|
+
return 0;
|
|
3300
3331
|
};
|
|
3301
3332
|
const mergeContentWithText = (tr, textBlock) => {
|
|
3302
3333
|
if (typeof tr.content === "string") return {
|
|
@@ -3335,8 +3366,10 @@ const stripToolReferenceTurnBoundary = (anthropicPayload) => {
|
|
|
3335
3366
|
msg.content = msg.content.filter((block) => block.type !== "text" || block.text.trim() !== TOOL_REFERENCE_TURN_BOUNDARY);
|
|
3336
3367
|
}
|
|
3337
3368
|
};
|
|
3338
|
-
const mergeToolResultForClaude = (anthropicPayload) => {
|
|
3339
|
-
|
|
3369
|
+
const mergeToolResultForClaude = (anthropicPayload, options) => {
|
|
3370
|
+
const lastMessageIndex = anthropicPayload.messages.length - 1;
|
|
3371
|
+
for (const [index, msg] of anthropicPayload.messages.entries()) {
|
|
3372
|
+
if (options?.skipLastMessage && index === lastMessageIndex) continue;
|
|
3340
3373
|
if (msg.role !== "user" || !Array.isArray(msg.content)) continue;
|
|
3341
3374
|
const toolResults = [];
|
|
3342
3375
|
const textBlocks = [];
|
|
@@ -3351,6 +3384,17 @@ const mergeToolResultForClaude = (anthropicPayload) => {
|
|
|
3351
3384
|
msg.content = mergeToolResult(toolResults, textBlocks);
|
|
3352
3385
|
}
|
|
3353
3386
|
};
|
|
3387
|
+
const sanitizeIdeTools = (payload) => {
|
|
3388
|
+
if (!payload.tools || payload.tools.length === 0) return;
|
|
3389
|
+
payload.tools = payload.tools.flatMap((tool) => {
|
|
3390
|
+
if (tool.name === IDE_EXECUTE_CODE_TOOL) return [];
|
|
3391
|
+
if (tool.name === IDE_GET_DIAGNOSTICS_TOOL) return [{
|
|
3392
|
+
...tool,
|
|
3393
|
+
description: IDE_GET_DIAGNOSTICS_DESCRIPTION
|
|
3394
|
+
}];
|
|
3395
|
+
return [tool];
|
|
3396
|
+
});
|
|
3397
|
+
};
|
|
3354
3398
|
const hasToolRef = (block) => {
|
|
3355
3399
|
return Array.isArray(block.content) && block.content.some((c) => c.type === "tool_reference");
|
|
3356
3400
|
};
|
|
@@ -3389,10 +3433,12 @@ const filterAssistantThinkingBlocks = (payload) => {
|
|
|
3389
3433
|
const prepareMessagesApiPayload = (payload, selectedModel) => {
|
|
3390
3434
|
stripCacheControl(payload);
|
|
3391
3435
|
filterAssistantThinkingBlocks(payload);
|
|
3436
|
+
const hasThinking = Boolean(payload.thinking);
|
|
3392
3437
|
const toolChoice = payload.tool_choice;
|
|
3393
3438
|
const disableThink = toolChoice?.type === "any" || toolChoice?.type === "tool";
|
|
3394
3439
|
if (selectedModel?.capabilities.supports.adaptive_thinking && !disableThink) {
|
|
3395
3440
|
payload.thinking = { type: "adaptive" };
|
|
3441
|
+
if (!hasThinking) payload.thinking.display = "summarized";
|
|
3396
3442
|
payload.output_config = { effort: getAnthropicEffortForModel(payload.model) };
|
|
3397
3443
|
}
|
|
3398
3444
|
};
|
|
@@ -3775,11 +3821,11 @@ async function handleCountTokens(c) {
|
|
|
3775
3821
|
|
|
3776
3822
|
//#endregion
|
|
3777
3823
|
//#region src/services/copilot/create-responses.ts
|
|
3778
|
-
const createResponses = async (payload, { vision, initiator, upstreamRequestId, subagentMarker, sessionId,
|
|
3824
|
+
const createResponses = async (payload, { vision, initiator, upstreamRequestId, subagentMarker, sessionId, compactType }, account) => {
|
|
3779
3825
|
const ctx = account ?? accountFromState();
|
|
3780
3826
|
if (!ctx.copilotToken) throw new Error("Copilot token not found");
|
|
3781
3827
|
const effectiveInitiator = resolveEffectiveInitiator(initiator, {
|
|
3782
|
-
isCompact,
|
|
3828
|
+
isCompact: Boolean(compactType),
|
|
3783
3829
|
isSubagent: Boolean(subagentMarker)
|
|
3784
3830
|
});
|
|
3785
3831
|
const headers = {
|
|
@@ -3787,8 +3833,9 @@ const createResponses = async (payload, { vision, initiator, upstreamRequestId,
|
|
|
3787
3833
|
"x-initiator": effectiveInitiator
|
|
3788
3834
|
};
|
|
3789
3835
|
prepareInteractionHeaders(sessionId, Boolean(subagentMarker), headers);
|
|
3790
|
-
prepareForCompact(headers,
|
|
3836
|
+
prepareForCompact(headers, compactType);
|
|
3791
3837
|
payload.service_tier = null;
|
|
3838
|
+
captureOutboundHeadersSnapshot(headers);
|
|
3792
3839
|
const response = await fetch(`${copilotBaseUrl(ctx)}/responses`, {
|
|
3793
3840
|
method: "POST",
|
|
3794
3841
|
headers,
|
|
@@ -4774,18 +4821,18 @@ const getMessagesInitiator = (payload) => {
|
|
|
4774
4821
|
return lastMessage.content.some((block) => block.type !== "tool_result") ? "user" : "agent";
|
|
4775
4822
|
};
|
|
4776
4823
|
const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
4824
|
+
const ADVANCED_TOOL_USE_BETA = "advanced-tool-use-2025-11-20";
|
|
4777
4825
|
const allowedAnthropicBetas = new Set([
|
|
4778
4826
|
INTERLEAVED_THINKING_BETA,
|
|
4779
4827
|
"context-management-2025-06-27",
|
|
4780
|
-
|
|
4828
|
+
ADVANCED_TOOL_USE_BETA
|
|
4781
4829
|
]);
|
|
4782
4830
|
const buildAnthropicBetaHeader = (anthropicBetaHeader, thinking) => {
|
|
4783
4831
|
const isAdaptiveThinking = thinking?.type === "adaptive";
|
|
4784
4832
|
if (anthropicBetaHeader) {
|
|
4785
|
-
const filteredBeta = anthropicBetaHeader.split(",").map((item) => item.trim()).filter((item) => item.length > 0).filter((item) => allowedAnthropicBetas.has(item));
|
|
4786
|
-
const uniqueFilteredBetas = [...new Set(filteredBeta)];
|
|
4787
|
-
|
|
4788
|
-
if (finalFilteredBetas.length > 0) return finalFilteredBetas.join(",");
|
|
4833
|
+
const filteredBeta = anthropicBetaHeader.split(",").map((item) => item.trim()).filter((item) => item.length > 0).filter((item) => allowedAnthropicBetas.has(item)).filter((item) => !isAdaptiveThinking || item !== INTERLEAVED_THINKING_BETA);
|
|
4834
|
+
const uniqueFilteredBetas = [...new Set([ADVANCED_TOOL_USE_BETA, ...filteredBeta])];
|
|
4835
|
+
if (uniqueFilteredBetas.length > 0) return uniqueFilteredBetas.join(",");
|
|
4789
4836
|
return;
|
|
4790
4837
|
}
|
|
4791
4838
|
if (thinking?.budget_tokens && !isAdaptiveThinking) return INTERLEAVED_THINKING_BETA;
|
|
@@ -4797,7 +4844,7 @@ const shouldUseMessageProxyHeaders = (payload) => {
|
|
|
4797
4844
|
};
|
|
4798
4845
|
const buildMessagesHeaders = ({ ctx, enableVision, initiator, options, payload }) => {
|
|
4799
4846
|
const effectiveInitiator = resolveEffectiveInitiator(initiator, {
|
|
4800
|
-
isCompact: options?.
|
|
4847
|
+
isCompact: Boolean(options?.compactType),
|
|
4801
4848
|
isSubagent: Boolean(options?.subagentMarker)
|
|
4802
4849
|
});
|
|
4803
4850
|
const headers = {
|
|
@@ -4805,7 +4852,7 @@ const buildMessagesHeaders = ({ ctx, enableVision, initiator, options, payload }
|
|
|
4805
4852
|
"x-initiator": effectiveInitiator
|
|
4806
4853
|
};
|
|
4807
4854
|
prepareInteractionHeaders(options?.sessionId, Boolean(options?.subagentMarker), headers);
|
|
4808
|
-
prepareForCompact(headers, options?.
|
|
4855
|
+
prepareForCompact(headers, options?.compactType);
|
|
4809
4856
|
if (shouldUseMessageProxyHeaders(payload)) prepareMessageProxyHeaders(headers);
|
|
4810
4857
|
const anthropicBeta = buildAnthropicBetaHeader(options?.anthropicBetaHeader, payload.thinking);
|
|
4811
4858
|
if (anthropicBeta) headers["anthropic-beta"] = anthropicBeta;
|
|
@@ -4821,6 +4868,7 @@ const createMessages = async (payload, account, options) => {
|
|
|
4821
4868
|
options,
|
|
4822
4869
|
payload
|
|
4823
4870
|
});
|
|
4871
|
+
captureOutboundHeadersSnapshot(headers);
|
|
4824
4872
|
const response = await fetch(`${copilotBaseUrl(ctx)}/v1/messages`, {
|
|
4825
4873
|
method: "POST",
|
|
4826
4874
|
headers,
|
|
@@ -5092,8 +5140,11 @@ function closeThinkingBlockIfOpen(state$1, events$1) {
|
|
|
5092
5140
|
}
|
|
5093
5141
|
|
|
5094
5142
|
//#endregion
|
|
5095
|
-
//#region src/
|
|
5143
|
+
//#region src/lib/subagent.ts
|
|
5096
5144
|
const subagentMarkerPrefix = "__SUBAGENT_MARKER__";
|
|
5145
|
+
|
|
5146
|
+
//#endregion
|
|
5147
|
+
//#region src/routes/messages/subagent-marker.ts
|
|
5097
5148
|
const subagentStartContextPrefix = "SubagentStart hook additional context:";
|
|
5098
5149
|
const REMINDER_RE = /<system-reminder>([\s\S]*?)<\/system-reminder>/g;
|
|
5099
5150
|
const NONE_INSPECTION = {
|
|
@@ -5127,7 +5178,7 @@ const extractMarkerPayloadFromReminderLine = (line) => {
|
|
|
5127
5178
|
let markerLine = trimmedLine;
|
|
5128
5179
|
if (markerLine.startsWith(subagentStartContextPrefix)) markerLine = markerLine.slice(38).trimStart();
|
|
5129
5180
|
if (!markerLine.startsWith(subagentMarkerPrefix)) return null;
|
|
5130
|
-
return markerLine.slice(
|
|
5181
|
+
return markerLine.slice(subagentMarkerPrefix.length).trimStart();
|
|
5131
5182
|
};
|
|
5132
5183
|
const inspectSubagentMarkerFromSystemReminder = (text) => {
|
|
5133
5184
|
let sawInvalidMarker = false;
|
|
@@ -5213,6 +5264,7 @@ async function handleCompletion(c) {
|
|
|
5213
5264
|
const { ip: clientIp, source: clientIpSource } = getClientIpInfo(c);
|
|
5214
5265
|
const userAgent = c.req.header("user-agent") ?? void 0;
|
|
5215
5266
|
const anthropicPayload = await c.req.json();
|
|
5267
|
+
sanitizeIdeTools(anthropicPayload);
|
|
5216
5268
|
debugJson(logger$5, "Anthropic request payload:", anthropicPayload);
|
|
5217
5269
|
const markerInspection = inspectSubagentMarkerFromFirstUser(anthropicPayload);
|
|
5218
5270
|
const subagentMarker = markerInspection.kind === "valid" ? markerInspection.marker : null;
|
|
@@ -5224,13 +5276,13 @@ async function handleCompletion(c) {
|
|
|
5224
5276
|
const ownershipLookupSessionId = markerInspection.kind === "valid" ? normalizeStableSessionId(markerInspection.marker.session_id) : void 0;
|
|
5225
5277
|
const ownershipWriteSessionId = markerInspection.kind === "none" ? sessionId : void 0;
|
|
5226
5278
|
const anthropicBeta = c.req.header("anthropic-beta");
|
|
5227
|
-
const
|
|
5279
|
+
const compactType = getCompactType(anthropicPayload);
|
|
5280
|
+
const isCompact = compactType !== 0;
|
|
5228
5281
|
const originalRequestModel = anthropicPayload.model;
|
|
5229
5282
|
if (anthropicBeta && isWarmupProbeRequest(anthropicPayload)) anthropicPayload.model = getSmallModel();
|
|
5230
|
-
if (
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
} else {
|
|
5283
|
+
if (compactType !== 0) logger$5.debug("Compact request type:", compactType);
|
|
5284
|
+
if (compactType === COMPACT_REQUEST && shouldCompactUseSmallModel()) anthropicPayload.model = getSmallModel();
|
|
5285
|
+
if (compactType === 0) {
|
|
5234
5286
|
stripToolReferenceTurnBoundary(anthropicPayload);
|
|
5235
5287
|
mergeToolResultForClaude(anthropicPayload);
|
|
5236
5288
|
}
|
|
@@ -5362,7 +5414,7 @@ async function handleCompletion(c) {
|
|
|
5362
5414
|
sessionId,
|
|
5363
5415
|
instr,
|
|
5364
5416
|
selectedModel,
|
|
5365
|
-
|
|
5417
|
+
compactType
|
|
5366
5418
|
});
|
|
5367
5419
|
if (endpoint === RESPONSES_ENDPOINT$1) return await handleWithResponsesApi({
|
|
5368
5420
|
c,
|
|
@@ -5372,7 +5424,7 @@ async function handleCompletion(c) {
|
|
|
5372
5424
|
sessionId,
|
|
5373
5425
|
selectedModel,
|
|
5374
5426
|
instr,
|
|
5375
|
-
|
|
5427
|
+
compactType
|
|
5376
5428
|
});
|
|
5377
5429
|
return await handleWithChatCompletions({
|
|
5378
5430
|
c,
|
|
@@ -5381,15 +5433,15 @@ async function handleCompletion(c) {
|
|
|
5381
5433
|
sessionId,
|
|
5382
5434
|
selectedModel,
|
|
5383
5435
|
instr,
|
|
5384
|
-
|
|
5436
|
+
compactType
|
|
5385
5437
|
});
|
|
5386
5438
|
}
|
|
5387
5439
|
const handleWithChatCompletions = async (params) => {
|
|
5388
|
-
const { c, openAIPayload, subagentMarker, sessionId, selectedModel, instr,
|
|
5440
|
+
const { c, openAIPayload, subagentMarker, sessionId, selectedModel, instr, compactType } = params;
|
|
5389
5441
|
debugJson(logger$5, "Translated OpenAI request payload:", openAIPayload);
|
|
5390
5442
|
const ctx = toAccountContext(instr.account);
|
|
5391
5443
|
const effectiveInitiator = resolveEffectiveInitiator(getChatInitiator(openAIPayload.messages), {
|
|
5392
|
-
isCompact,
|
|
5444
|
+
isCompact: compactType !== 0,
|
|
5393
5445
|
isSubagent: Boolean(subagentMarker)
|
|
5394
5446
|
});
|
|
5395
5447
|
instr.initiator = effectiveInitiator;
|
|
@@ -5400,7 +5452,7 @@ const handleWithChatCompletions = async (params) => {
|
|
|
5400
5452
|
initiator: effectiveInitiator,
|
|
5401
5453
|
subagentMarker,
|
|
5402
5454
|
sessionId,
|
|
5403
|
-
|
|
5455
|
+
compactType
|
|
5404
5456
|
});
|
|
5405
5457
|
instr.confirmAffinity?.();
|
|
5406
5458
|
instr.confirmOwnership?.();
|
|
@@ -5433,14 +5485,14 @@ const handleWithChatCompletions = async (params) => {
|
|
|
5433
5485
|
}));
|
|
5434
5486
|
};
|
|
5435
5487
|
const handleWithResponsesApi = async (params) => {
|
|
5436
|
-
const { c, anthropicPayload, openAIPayload, subagentMarker, sessionId, selectedModel, instr,
|
|
5488
|
+
const { c, anthropicPayload, openAIPayload, subagentMarker, sessionId, selectedModel, instr, compactType } = params;
|
|
5437
5489
|
const responsesPayload = translateAnthropicMessagesToResponsesPayload(anthropicPayload, selectedModel.id);
|
|
5438
5490
|
applyResponsesApiContextManagement(responsesPayload, selectedModel.capabilities.limits.max_prompt_tokens);
|
|
5439
5491
|
compactInputByLatestCompaction(responsesPayload);
|
|
5440
5492
|
debugJson(logger$5, "Translated Responses payload:", responsesPayload);
|
|
5441
5493
|
const { vision, initiator } = getResponsesRequestOptions(responsesPayload);
|
|
5442
5494
|
const effectiveInitiator = resolveEffectiveInitiator(initiator, {
|
|
5443
|
-
isCompact,
|
|
5495
|
+
isCompact: compactType !== 0,
|
|
5444
5496
|
isSubagent: Boolean(subagentMarker)
|
|
5445
5497
|
});
|
|
5446
5498
|
const ctx = toAccountContext(instr.account);
|
|
@@ -5453,7 +5505,7 @@ const handleWithResponsesApi = async (params) => {
|
|
|
5453
5505
|
upstreamRequestId: instr.upstreamRequestId,
|
|
5454
5506
|
subagentMarker,
|
|
5455
5507
|
sessionId,
|
|
5456
|
-
|
|
5508
|
+
compactType
|
|
5457
5509
|
}, ctx);
|
|
5458
5510
|
instr.confirmAffinity?.();
|
|
5459
5511
|
instr.confirmOwnership?.();
|
|
@@ -5946,12 +5998,12 @@ async function streamMessagesAndLog(params) {
|
|
|
5946
5998
|
}
|
|
5947
5999
|
}
|
|
5948
6000
|
const handleWithMessagesApi = async (params) => {
|
|
5949
|
-
const { c, anthropicPayload, anthropicBetaHeader, subagentMarker, sessionId, instr, selectedModel,
|
|
6001
|
+
const { c, anthropicPayload, anthropicBetaHeader, subagentMarker, sessionId, instr, selectedModel, compactType } = params;
|
|
5950
6002
|
prepareMessagesApiPayload(anthropicPayload, selectedModel);
|
|
5951
6003
|
debugJson(logger$5, "Translated Messages payload:", anthropicPayload);
|
|
5952
6004
|
const ctx = toAccountContext(instr.account);
|
|
5953
6005
|
const effectiveInitiator = resolveEffectiveInitiator(getMessagesInitiator(anthropicPayload), {
|
|
5954
|
-
isCompact,
|
|
6006
|
+
isCompact: compactType !== 0,
|
|
5955
6007
|
isSubagent: Boolean(subagentMarker)
|
|
5956
6008
|
});
|
|
5957
6009
|
instr.initiator = effectiveInitiator;
|
|
@@ -5963,7 +6015,7 @@ const handleWithMessagesApi = async (params) => {
|
|
|
5963
6015
|
initiator: effectiveInitiator,
|
|
5964
6016
|
subagentMarker,
|
|
5965
6017
|
sessionId,
|
|
5966
|
-
|
|
6018
|
+
compactType
|
|
5967
6019
|
});
|
|
5968
6020
|
instr.confirmAffinity?.();
|
|
5969
6021
|
instr.confirmOwnership?.();
|
|
@@ -6866,4 +6918,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
|
|
|
6866
6918
|
|
|
6867
6919
|
//#endregion
|
|
6868
6920
|
export { server };
|
|
6869
|
-
//# sourceMappingURL=server-
|
|
6921
|
+
//# sourceMappingURL=server-CFijvv3C.js.map
|