@jeffreycao/copilot-api 1.13.23 → 1.13.25
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 +12 -3
- package/README.zh-CN.md +12 -3
- package/dist/{auth-DkG1pyuW.js → auth-BkP8Iq1X.js} +3 -3
- package/dist/{auth-DkG1pyuW.js.map → auth-BkP8Iq1X.js.map} +1 -1
- package/dist/auth-ESiQzf-H.js +2 -0
- package/dist/{config-BCyM6AdG.js → config-BypwNNvl.js} +5 -2
- package/dist/config-BypwNNvl.js.map +1 -0
- package/dist/{debug-CY_fNIt4.js → debug-DPB_2BUI.js} +2 -2
- package/dist/{debug-CY_fNIt4.js.map → debug-DPB_2BUI.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{server-BrgJPQLJ.js → server-BUJBoWLv.js} +220 -132
- package/dist/server-BUJBoWLv.js.map +1 -0
- package/dist/{start-BxncuUfS.js → start-rftAmv6G.js} +5 -5
- package/dist/{start-BxncuUfS.js.map → start-rftAmv6G.js.map} +1 -1
- package/dist/{token-Bf4cLt-K.js → token-DBkrVCVU.js} +2 -2
- package/dist/{token-Bf4cLt-K.js.map → token-DBkrVCVU.js.map} +1 -1
- package/package.json +1 -1
- package/dist/auth-CYNyMACQ.js +0 -2
- package/dist/config-BCyM6AdG.js.map +0 -1
- package/dist/server-BrgJPQLJ.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as resolveMappedModel, D as PATHS, S as resolveEffectiveProviderType, T as setModelMappings, _ as isResponsesApiWebSocketEnabled, a as getExtraPromptForModel, c as getModelResponsesApiCompactThreshold$1, d as getReasoningEffortForModel, f as getSmallModel, g as isResponsesApiWebSearchEnabled, h as isMessagesApiEnabled, i as getConfig, l as getProviderConfig, m as isContextManagementEnabledForResponses, n as getAnthropicApiKey, o as getMessageApiWebSearchModel, p as isContextManagementEnabledForMessages, r as getClaudeTokenMultiplier, s as getModelMappings, u as getRawProviderConfig, w as resolveProviderAuthType, y as listEnabledProviders } from "./config-
|
|
2
|
-
import { B as HTTPError, C as prepareMessageProxyHeaders, E as compactMessageSections, F as requestContext, I as resolveTraceId$1, L as createPooledWebSocketStream, M as buildCodexRequestHeaders, N as forwardCodexResponses, O as compactSystemPromptStarts, P as generateTraceId, R as createWebSocketUrl, S as prepareInteractionHeaders, T as compactAutoContinuePromptStarts, V as forwardError, b as copilotWebSocketHeaders, d as generateRequestIdFromPayload, f as getRootSessionId, g as getCopilotUsage, h as parseUserIdMetadata, j as CODEX_API_BASE_URL, m as isNullish, p as getUUID, r as setupCodexToken, v as copilotBaseUrl, x as prepareForCompact, y as copilotHeaders, z as state } from "./token-
|
|
1
|
+
import { C as resolveMappedModel, D as PATHS, S as resolveEffectiveProviderType, T as setModelMappings, _ as isResponsesApiWebSocketEnabled, a as getExtraPromptForModel, c as getModelResponsesApiCompactThreshold$1, d as getReasoningEffortForModel, f as getSmallModel, g as isResponsesApiWebSearchEnabled, h as isMessagesApiEnabled, i as getConfig, l as getProviderConfig, m as isContextManagementEnabledForResponses, n as getAnthropicApiKey, o as getMessageApiWebSearchModel, p as isContextManagementEnabledForMessages, r as getClaudeTokenMultiplier, s as getModelMappings, u as getRawProviderConfig, w as resolveProviderAuthType, y as listEnabledProviders } from "./config-BypwNNvl.js";
|
|
2
|
+
import { B as HTTPError, C as prepareMessageProxyHeaders, E as compactMessageSections, F as requestContext, I as resolveTraceId$1, L as createPooledWebSocketStream, M as buildCodexRequestHeaders, N as forwardCodexResponses, O as compactSystemPromptStarts, P as generateTraceId, R as createWebSocketUrl, S as prepareInteractionHeaders, T as compactAutoContinuePromptStarts, V as forwardError, b as copilotWebSocketHeaders, d as generateRequestIdFromPayload, f as getRootSessionId, g as getCopilotUsage, h as parseUserIdMetadata, j as CODEX_API_BASE_URL, m as isNullish, p as getUUID, r as setupCodexToken, v as copilotBaseUrl, x as prepareForCompact, y as copilotHeaders, z as state } from "./token-DBkrVCVU.js";
|
|
3
3
|
import { a as isDeferredToolName, c as parseMcpToolSearchSentinel, d as shouldEnableResponsesToolSearch, i as isBridgeToolSearchName, l as resolveBridgeToolSearchName, o as listDeferredToolNames, r as formatToolSearchBridgeArguments, s as normalizeToolSearchBridgeArguments, t as BRIDGE_TOOL_SEARCH_NAME, u as selectDeferredToolsByNames } from "./tool-search-OX6iPJ9D.js";
|
|
4
4
|
import consola from "consola";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
@@ -12,8 +12,8 @@ import { Hono } from "hono";
|
|
|
12
12
|
import { cors } from "hono/cors";
|
|
13
13
|
import { logger } from "hono/logger";
|
|
14
14
|
import { decompress } from "fzstd";
|
|
15
|
-
import { streamSSE } from "hono/streaming";
|
|
16
15
|
import util from "node:util";
|
|
16
|
+
import { streamSSE } from "hono/streaming";
|
|
17
17
|
//#region src/lib/request-auth.ts
|
|
18
18
|
function normalizeApiKeys(apiKeys) {
|
|
19
19
|
if (!Array.isArray(apiKeys)) {
|
|
@@ -321,6 +321,147 @@ const createHandlerLogger = (name) => {
|
|
|
321
321
|
return instance;
|
|
322
322
|
};
|
|
323
323
|
//#endregion
|
|
324
|
+
//#region src/lib/provider-resolver.ts
|
|
325
|
+
function isMissingCodexCredentialsError(error) {
|
|
326
|
+
return error instanceof Error && error.message === "Codex credentials not found. Run `copilot-api auth login --provider codex` first.";
|
|
327
|
+
}
|
|
328
|
+
async function resolveProviderConfig(providerName) {
|
|
329
|
+
const normalizedProviderName = providerName.trim();
|
|
330
|
+
if (!normalizedProviderName) return null;
|
|
331
|
+
if (normalizedProviderName === "codex") {
|
|
332
|
+
if (getRawProviderConfig(normalizedProviderName)?.enabled === false) return null;
|
|
333
|
+
try {
|
|
334
|
+
await setupCodexToken();
|
|
335
|
+
} catch (error) {
|
|
336
|
+
if (isMissingCodexCredentialsError(error)) return null;
|
|
337
|
+
throw error;
|
|
338
|
+
}
|
|
339
|
+
const providerConfig = getProviderConfig(normalizedProviderName);
|
|
340
|
+
if (!providerConfig) return null;
|
|
341
|
+
return {
|
|
342
|
+
...providerConfig,
|
|
343
|
+
apiKey: state.codexAccessToken ?? providerConfig.apiKey
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
return getProviderConfig(normalizedProviderName);
|
|
347
|
+
}
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/services/codex/alpha-search.ts
|
|
350
|
+
const CODEX_ALPHA_SEARCH_URL = `${CODEX_API_BASE_URL}/codex/alpha/search`;
|
|
351
|
+
function resolveCodexAlphaSearchUrl(requestUrl) {
|
|
352
|
+
const upstreamUrl = new URL(CODEX_ALPHA_SEARCH_URL);
|
|
353
|
+
upstreamUrl.search = new URL(requestUrl, "http://localhost").search;
|
|
354
|
+
return upstreamUrl.toString();
|
|
355
|
+
}
|
|
356
|
+
async function forwardCodexAlphaSearch(request) {
|
|
357
|
+
const headers = buildCodexRequestHeaders(request.headers);
|
|
358
|
+
if (!headers.has("accept")) headers.set("accept", "application/json");
|
|
359
|
+
const body = await request.arrayBuffer();
|
|
360
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
361
|
+
return await fetch(resolveCodexAlphaSearchUrl(request.url), {
|
|
362
|
+
method: "POST",
|
|
363
|
+
headers,
|
|
364
|
+
body
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/services/providers/provider-proxy.ts
|
|
369
|
+
const SHARED_FORWARDABLE_HEADERS = ["accept", "user-agent"];
|
|
370
|
+
const ANTHROPIC_FORWARDABLE_HEADERS = ["anthropic-version", "anthropic-beta"];
|
|
371
|
+
const STRIPPED_RESPONSE_HEADERS = [
|
|
372
|
+
"connection",
|
|
373
|
+
"content-encoding",
|
|
374
|
+
"content-length",
|
|
375
|
+
"keep-alive",
|
|
376
|
+
"proxy-authenticate",
|
|
377
|
+
"proxy-authorization",
|
|
378
|
+
"te",
|
|
379
|
+
"trailer",
|
|
380
|
+
"transfer-encoding",
|
|
381
|
+
"upgrade"
|
|
382
|
+
];
|
|
383
|
+
function buildProviderUpstreamHeaders(providerConfig, requestHeaders) {
|
|
384
|
+
const authHeaders = {};
|
|
385
|
+
if (providerConfig.authType === "x-api-key") authHeaders["x-api-key"] = providerConfig.apiKey;
|
|
386
|
+
else authHeaders.authorization = `Bearer ${providerConfig.apiKey}`;
|
|
387
|
+
const headers = {
|
|
388
|
+
"content-type": "application/json",
|
|
389
|
+
accept: "application/json",
|
|
390
|
+
...authHeaders
|
|
391
|
+
};
|
|
392
|
+
for (const headerName of SHARED_FORWARDABLE_HEADERS) {
|
|
393
|
+
const headerValue = requestHeaders.get(headerName);
|
|
394
|
+
if (headerValue) headers[headerName] = headerValue;
|
|
395
|
+
}
|
|
396
|
+
if (providerConfig.type !== "anthropic") return headers;
|
|
397
|
+
for (const headerName of ANTHROPIC_FORWARDABLE_HEADERS) {
|
|
398
|
+
const headerValue = requestHeaders.get(headerName);
|
|
399
|
+
if (headerValue) headers[headerName] = headerValue;
|
|
400
|
+
}
|
|
401
|
+
return headers;
|
|
402
|
+
}
|
|
403
|
+
function createProviderProxyResponse(upstreamResponse, body) {
|
|
404
|
+
const headers = new Headers(upstreamResponse.headers);
|
|
405
|
+
for (const headerName of STRIPPED_RESPONSE_HEADERS) headers.delete(headerName);
|
|
406
|
+
return new Response(body ?? upstreamResponse.body, {
|
|
407
|
+
headers,
|
|
408
|
+
status: upstreamResponse.status,
|
|
409
|
+
statusText: upstreamResponse.statusText
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
async function forwardProviderMessages(providerConfig, payload, requestHeaders) {
|
|
413
|
+
consola.log(`<-- model: ${payload.model}`);
|
|
414
|
+
return await fetch(`${providerConfig.baseUrl}/v1/messages`, {
|
|
415
|
+
method: "POST",
|
|
416
|
+
headers: buildProviderUpstreamHeaders(providerConfig, requestHeaders),
|
|
417
|
+
body: JSON.stringify(payload)
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
async function forwardProviderChatCompletions(providerConfig, payload, requestHeaders) {
|
|
421
|
+
consola.log(`<-- model: ${payload.model}`);
|
|
422
|
+
return await fetch(`${providerConfig.baseUrl}/v1/chat/completions`, {
|
|
423
|
+
method: "POST",
|
|
424
|
+
headers: buildProviderUpstreamHeaders(providerConfig, requestHeaders),
|
|
425
|
+
body: JSON.stringify(payload)
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
async function forwardProviderResponses(providerConfig, payload, requestHeaders) {
|
|
429
|
+
consola.log(`<-- model: ${payload.model}`);
|
|
430
|
+
return await fetch(`${providerConfig.baseUrl}/v1/responses`, {
|
|
431
|
+
method: "POST",
|
|
432
|
+
headers: buildProviderUpstreamHeaders(providerConfig, requestHeaders),
|
|
433
|
+
body: JSON.stringify(payload)
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
async function forwardProviderModels(providerConfig, requestHeaders) {
|
|
437
|
+
return await fetch(`${providerConfig.baseUrl}/v1/models`, {
|
|
438
|
+
method: "GET",
|
|
439
|
+
headers: buildProviderUpstreamHeaders(providerConfig, requestHeaders)
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/routes/alpha-search/route.ts
|
|
444
|
+
const logger$10 = createHandlerLogger("alpha-search-handler");
|
|
445
|
+
const alphaSearchRoutes = new Hono();
|
|
446
|
+
alphaSearchRoutes.post("/", async (c) => {
|
|
447
|
+
try {
|
|
448
|
+
if (!await resolveProviderConfig("codex")) return c.json({ error: {
|
|
449
|
+
message: "Provider 'codex' not found or disabled",
|
|
450
|
+
type: "invalid_request_error"
|
|
451
|
+
} }, 404);
|
|
452
|
+
debugJson(logger$10, "alpha_search.codex.request", { body: await c.req.raw.clone().text() });
|
|
453
|
+
const upstreamResponse = await forwardCodexAlphaSearch(c.req.raw);
|
|
454
|
+
debugJson(logger$10, "alpha_search.codex.response", {
|
|
455
|
+
body: await upstreamResponse.clone().text(),
|
|
456
|
+
statusCode: upstreamResponse.status
|
|
457
|
+
});
|
|
458
|
+
return createProviderProxyResponse(upstreamResponse);
|
|
459
|
+
} catch (error) {
|
|
460
|
+
logger$10.error("alpha_search.codex.error", { error });
|
|
461
|
+
return await forwardError(c, error);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
//#endregion
|
|
324
465
|
//#region src/lib/provider-model.ts
|
|
325
466
|
const parseProviderModelAlias = (model) => {
|
|
326
467
|
const separatorIndex = model.indexOf("/");
|
|
@@ -1009,36 +1150,72 @@ const BUILTIN_PROVIDER_PRICING = {
|
|
|
1009
1150
|
input: 1.75,
|
|
1010
1151
|
output: 14
|
|
1011
1152
|
},
|
|
1012
|
-
"gpt-5.4": {
|
|
1153
|
+
"gpt-5.4": { tiers: [{
|
|
1013
1154
|
cachedInput: .25,
|
|
1014
1155
|
input: 2.5,
|
|
1156
|
+
maxInputTokens: 272e3,
|
|
1015
1157
|
output: 15
|
|
1016
|
-
},
|
|
1017
|
-
|
|
1158
|
+
}, {
|
|
1159
|
+
cachedInput: .5,
|
|
1160
|
+
input: 5,
|
|
1161
|
+
output: 22.5
|
|
1162
|
+
}] },
|
|
1163
|
+
"gpt-5.4-mini": { tiers: [{
|
|
1018
1164
|
cachedInput: .075,
|
|
1019
1165
|
input: .75,
|
|
1166
|
+
maxInputTokens: 272e3,
|
|
1020
1167
|
output: 4.5
|
|
1021
|
-
},
|
|
1022
|
-
|
|
1168
|
+
}, {
|
|
1169
|
+
cachedInput: .15,
|
|
1170
|
+
input: 1.5,
|
|
1171
|
+
output: 6.75
|
|
1172
|
+
}] },
|
|
1173
|
+
"gpt-5.5": { tiers: [{
|
|
1023
1174
|
cachedInput: .5,
|
|
1024
1175
|
input: 5,
|
|
1176
|
+
maxInputTokens: 272e3,
|
|
1025
1177
|
output: 30
|
|
1026
|
-
},
|
|
1027
|
-
|
|
1178
|
+
}, {
|
|
1179
|
+
cachedInput: 1,
|
|
1180
|
+
input: 10,
|
|
1181
|
+
output: 45
|
|
1182
|
+
}] },
|
|
1183
|
+
"gpt-5.6-sol": { tiers: [{
|
|
1184
|
+
cacheCreationInput: 6.25,
|
|
1028
1185
|
cachedInput: .5,
|
|
1029
1186
|
input: 5,
|
|
1187
|
+
maxInputTokens: 272e3,
|
|
1030
1188
|
output: 30
|
|
1031
|
-
},
|
|
1032
|
-
|
|
1189
|
+
}, {
|
|
1190
|
+
cacheCreationInput: 12.5,
|
|
1191
|
+
cachedInput: 1,
|
|
1192
|
+
input: 10,
|
|
1193
|
+
output: 45
|
|
1194
|
+
}] },
|
|
1195
|
+
"gpt-5.6-terra": { tiers: [{
|
|
1196
|
+
cacheCreationInput: 3.125,
|
|
1033
1197
|
cachedInput: .25,
|
|
1034
1198
|
input: 2.5,
|
|
1199
|
+
maxInputTokens: 272e3,
|
|
1035
1200
|
output: 15
|
|
1036
|
-
},
|
|
1037
|
-
|
|
1201
|
+
}, {
|
|
1202
|
+
cacheCreationInput: 6.25,
|
|
1203
|
+
cachedInput: .5,
|
|
1204
|
+
input: 5,
|
|
1205
|
+
output: 22.5
|
|
1206
|
+
}] },
|
|
1207
|
+
"gpt-5.6-luna": { tiers: [{
|
|
1208
|
+
cacheCreationInput: 1.25,
|
|
1038
1209
|
cachedInput: .1,
|
|
1039
1210
|
input: 1,
|
|
1211
|
+
maxInputTokens: 272e3,
|
|
1040
1212
|
output: 6
|
|
1041
|
-
}
|
|
1213
|
+
}, {
|
|
1214
|
+
cacheCreationInput: 2.5,
|
|
1215
|
+
cachedInput: .2,
|
|
1216
|
+
input: 2,
|
|
1217
|
+
output: 9
|
|
1218
|
+
}] }
|
|
1042
1219
|
},
|
|
1043
1220
|
dashscope: {
|
|
1044
1221
|
"glm-5.1": { tiers: [{
|
|
@@ -1235,7 +1412,10 @@ function resolveCacheCreationPrice(pricing) {
|
|
|
1235
1412
|
return normalizePrice(pricing.cacheCreationInput);
|
|
1236
1413
|
}
|
|
1237
1414
|
function resolveCacheReadPrice(pricing, input) {
|
|
1238
|
-
if (input.cache_creation_input_tokens !== void 0 && input.cache_creation_input_tokens !== null)
|
|
1415
|
+
if (input.cache_creation_input_tokens !== void 0 && input.cache_creation_input_tokens !== null) {
|
|
1416
|
+
const explicitPrice = normalizePrice(pricing.explicitCachedInput);
|
|
1417
|
+
if (explicitPrice !== null) return explicitPrice;
|
|
1418
|
+
}
|
|
1239
1419
|
return normalizePrice(pricing.cachedInput);
|
|
1240
1420
|
}
|
|
1241
1421
|
function costNanosForTokens(tokens, pricePerMillionTokens) {
|
|
@@ -1329,10 +1509,12 @@ function normalizeOpenAIUsage(usage) {
|
|
|
1329
1509
|
}
|
|
1330
1510
|
function normalizeResponsesUsage(usage) {
|
|
1331
1511
|
const cachedTokens = normalizeToken(usage?.input_tokens_details?.cached_tokens);
|
|
1512
|
+
const cacheWriteTokens = normalizeToken(usage?.input_tokens_details?.cache_write_tokens);
|
|
1332
1513
|
const inputTokens = normalizeToken(usage?.input_tokens);
|
|
1333
1514
|
return {
|
|
1515
|
+
...cacheWriteTokens > 0 && { cache_creation_input_tokens: cacheWriteTokens },
|
|
1334
1516
|
cache_read_input_tokens: cachedTokens,
|
|
1335
|
-
input_tokens: Math.max(0, inputTokens - cachedTokens),
|
|
1517
|
+
input_tokens: Math.max(0, inputTokens - cachedTokens - cacheWriteTokens),
|
|
1336
1518
|
output_tokens: normalizeToken(usage?.output_tokens),
|
|
1337
1519
|
total_tokens: normalizeOptionalToken(usage?.total_tokens)
|
|
1338
1520
|
};
|
|
@@ -1406,106 +1588,6 @@ const setContextCacheControl = (part) => {
|
|
|
1406
1588
|
part.cache_control = { ...OPENAI_COMPATIBLE_CONTEXT_CACHE_CONTROL };
|
|
1407
1589
|
};
|
|
1408
1590
|
//#endregion
|
|
1409
|
-
//#region src/lib/provider-resolver.ts
|
|
1410
|
-
function isMissingCodexCredentialsError(error) {
|
|
1411
|
-
return error instanceof Error && error.message === "Codex credentials not found. Run `copilot-api auth login --provider codex` first.";
|
|
1412
|
-
}
|
|
1413
|
-
async function resolveProviderConfig(providerName) {
|
|
1414
|
-
const normalizedProviderName = providerName.trim();
|
|
1415
|
-
if (!normalizedProviderName) return null;
|
|
1416
|
-
if (normalizedProviderName === "codex") {
|
|
1417
|
-
if (getRawProviderConfig(normalizedProviderName)?.enabled === false) return null;
|
|
1418
|
-
try {
|
|
1419
|
-
await setupCodexToken();
|
|
1420
|
-
} catch (error) {
|
|
1421
|
-
if (isMissingCodexCredentialsError(error)) return null;
|
|
1422
|
-
throw error;
|
|
1423
|
-
}
|
|
1424
|
-
const providerConfig = getProviderConfig(normalizedProviderName);
|
|
1425
|
-
if (!providerConfig) return null;
|
|
1426
|
-
return {
|
|
1427
|
-
...providerConfig,
|
|
1428
|
-
apiKey: state.codexAccessToken ?? providerConfig.apiKey
|
|
1429
|
-
};
|
|
1430
|
-
}
|
|
1431
|
-
return getProviderConfig(normalizedProviderName);
|
|
1432
|
-
}
|
|
1433
|
-
//#endregion
|
|
1434
|
-
//#region src/services/providers/provider-proxy.ts
|
|
1435
|
-
const SHARED_FORWARDABLE_HEADERS = ["accept", "user-agent"];
|
|
1436
|
-
const ANTHROPIC_FORWARDABLE_HEADERS = ["anthropic-version", "anthropic-beta"];
|
|
1437
|
-
const STRIPPED_RESPONSE_HEADERS = [
|
|
1438
|
-
"connection",
|
|
1439
|
-
"content-encoding",
|
|
1440
|
-
"content-length",
|
|
1441
|
-
"keep-alive",
|
|
1442
|
-
"proxy-authenticate",
|
|
1443
|
-
"proxy-authorization",
|
|
1444
|
-
"te",
|
|
1445
|
-
"trailer",
|
|
1446
|
-
"transfer-encoding",
|
|
1447
|
-
"upgrade"
|
|
1448
|
-
];
|
|
1449
|
-
function buildProviderUpstreamHeaders(providerConfig, requestHeaders) {
|
|
1450
|
-
const authHeaders = {};
|
|
1451
|
-
if (providerConfig.authType === "x-api-key") authHeaders["x-api-key"] = providerConfig.apiKey;
|
|
1452
|
-
else authHeaders.authorization = `Bearer ${providerConfig.apiKey}`;
|
|
1453
|
-
const headers = {
|
|
1454
|
-
"content-type": "application/json",
|
|
1455
|
-
accept: "application/json",
|
|
1456
|
-
...authHeaders
|
|
1457
|
-
};
|
|
1458
|
-
for (const headerName of SHARED_FORWARDABLE_HEADERS) {
|
|
1459
|
-
const headerValue = requestHeaders.get(headerName);
|
|
1460
|
-
if (headerValue) headers[headerName] = headerValue;
|
|
1461
|
-
}
|
|
1462
|
-
if (providerConfig.type !== "anthropic") return headers;
|
|
1463
|
-
for (const headerName of ANTHROPIC_FORWARDABLE_HEADERS) {
|
|
1464
|
-
const headerValue = requestHeaders.get(headerName);
|
|
1465
|
-
if (headerValue) headers[headerName] = headerValue;
|
|
1466
|
-
}
|
|
1467
|
-
return headers;
|
|
1468
|
-
}
|
|
1469
|
-
function createProviderProxyResponse(upstreamResponse, body) {
|
|
1470
|
-
const headers = new Headers(upstreamResponse.headers);
|
|
1471
|
-
for (const headerName of STRIPPED_RESPONSE_HEADERS) headers.delete(headerName);
|
|
1472
|
-
return new Response(body ?? upstreamResponse.body, {
|
|
1473
|
-
headers,
|
|
1474
|
-
status: upstreamResponse.status,
|
|
1475
|
-
statusText: upstreamResponse.statusText
|
|
1476
|
-
});
|
|
1477
|
-
}
|
|
1478
|
-
async function forwardProviderMessages(providerConfig, payload, requestHeaders) {
|
|
1479
|
-
consola.log(`<-- model: ${payload.model}`);
|
|
1480
|
-
return await fetch(`${providerConfig.baseUrl}/v1/messages`, {
|
|
1481
|
-
method: "POST",
|
|
1482
|
-
headers: buildProviderUpstreamHeaders(providerConfig, requestHeaders),
|
|
1483
|
-
body: JSON.stringify(payload)
|
|
1484
|
-
});
|
|
1485
|
-
}
|
|
1486
|
-
async function forwardProviderChatCompletions(providerConfig, payload, requestHeaders) {
|
|
1487
|
-
consola.log(`<-- model: ${payload.model}`);
|
|
1488
|
-
return await fetch(`${providerConfig.baseUrl}/v1/chat/completions`, {
|
|
1489
|
-
method: "POST",
|
|
1490
|
-
headers: buildProviderUpstreamHeaders(providerConfig, requestHeaders),
|
|
1491
|
-
body: JSON.stringify(payload)
|
|
1492
|
-
});
|
|
1493
|
-
}
|
|
1494
|
-
async function forwardProviderResponses(providerConfig, payload, requestHeaders) {
|
|
1495
|
-
consola.log(`<-- model: ${payload.model}`);
|
|
1496
|
-
return await fetch(`${providerConfig.baseUrl}/v1/responses`, {
|
|
1497
|
-
method: "POST",
|
|
1498
|
-
headers: buildProviderUpstreamHeaders(providerConfig, requestHeaders),
|
|
1499
|
-
body: JSON.stringify(payload)
|
|
1500
|
-
});
|
|
1501
|
-
}
|
|
1502
|
-
async function forwardProviderModels(providerConfig, requestHeaders) {
|
|
1503
|
-
return await fetch(`${providerConfig.baseUrl}/v1/models`, {
|
|
1504
|
-
method: "GET",
|
|
1505
|
-
headers: buildProviderUpstreamHeaders(providerConfig, requestHeaders)
|
|
1506
|
-
});
|
|
1507
|
-
}
|
|
1508
|
-
//#endregion
|
|
1509
1591
|
//#region src/routes/provider/chat-completions/handler.ts
|
|
1510
1592
|
const logger$9 = createHandlerLogger("provider-chat-completions-handler");
|
|
1511
1593
|
async function handleProviderChatCompletionsForProvider(c, options) {
|
|
@@ -3526,7 +3608,8 @@ const translateAnthropicMessagesToResponsesPayload = (payload, subagentAgentId)
|
|
|
3526
3608
|
parallel_tool_calls: true,
|
|
3527
3609
|
reasoning: {
|
|
3528
3610
|
effort: getReasoningEffortForModel(payload.model),
|
|
3529
|
-
summary: "detailed"
|
|
3611
|
+
summary: "detailed",
|
|
3612
|
+
context: "all_turns"
|
|
3530
3613
|
},
|
|
3531
3614
|
include: ["reasoning.encrypted_content"]
|
|
3532
3615
|
};
|
|
@@ -4036,10 +4119,13 @@ const mapResponsesStopReason = (response, options) => {
|
|
|
4036
4119
|
const mapResponsesUsage = (response) => {
|
|
4037
4120
|
const inputTokens = response.usage?.input_tokens ?? 0;
|
|
4038
4121
|
const outputTokens = response.usage?.output_tokens ?? 0;
|
|
4122
|
+
const inputCachedTokens = response.usage?.input_tokens_details?.cached_tokens;
|
|
4123
|
+
const cacheWriteTokens = response.usage?.input_tokens_details?.cache_write_tokens;
|
|
4039
4124
|
return {
|
|
4040
|
-
input_tokens: inputTokens - (
|
|
4125
|
+
input_tokens: inputTokens - (inputCachedTokens ?? 0) - (cacheWriteTokens ?? 0),
|
|
4041
4126
|
output_tokens: outputTokens,
|
|
4042
|
-
...
|
|
4127
|
+
...inputCachedTokens !== void 0 && { cache_read_input_tokens: inputCachedTokens },
|
|
4128
|
+
...cacheWriteTokens !== void 0 && { cache_creation_input_tokens: cacheWriteTokens }
|
|
4043
4129
|
};
|
|
4044
4130
|
};
|
|
4045
4131
|
const isRecord$1 = (value) => typeof value === "object" && value !== null;
|
|
@@ -4390,7 +4476,8 @@ const handleFunctionCallArgumentsValidationError = (error, state, events = []) =
|
|
|
4390
4476
|
const messageStart = (state, response) => {
|
|
4391
4477
|
state.messageStartSent = true;
|
|
4392
4478
|
const inputCachedTokens = response.usage?.input_tokens_details?.cached_tokens;
|
|
4393
|
-
const
|
|
4479
|
+
const cacheWriteTokens = response.usage?.input_tokens_details?.cache_write_tokens;
|
|
4480
|
+
const inputTokens = (response.usage?.input_tokens ?? 0) - (inputCachedTokens ?? 0) - (cacheWriteTokens ?? 0);
|
|
4394
4481
|
return [{
|
|
4395
4482
|
type: "message_start",
|
|
4396
4483
|
message: {
|
|
@@ -4404,7 +4491,8 @@ const messageStart = (state, response) => {
|
|
|
4404
4491
|
usage: {
|
|
4405
4492
|
input_tokens: inputTokens,
|
|
4406
4493
|
output_tokens: 0,
|
|
4407
|
-
cache_read_input_tokens: inputCachedTokens ?? 0
|
|
4494
|
+
cache_read_input_tokens: inputCachedTokens ?? 0,
|
|
4495
|
+
...cacheWriteTokens !== void 0 && { cache_creation_input_tokens: cacheWriteTokens }
|
|
4408
4496
|
}
|
|
4409
4497
|
}
|
|
4410
4498
|
}];
|
|
@@ -5145,16 +5233,16 @@ const CODEX_MODELS = [
|
|
|
5145
5233
|
name: "GPT-5.6 Luna"
|
|
5146
5234
|
}
|
|
5147
5235
|
];
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
const upstreamUrl = new URL(
|
|
5236
|
+
const CODEX_MODELS_URL = `${CODEX_API_BASE_URL}/codex/models`;
|
|
5237
|
+
function resolveCodexModelsUrl(requestUrl) {
|
|
5238
|
+
const upstreamUrl = new URL(CODEX_MODELS_URL);
|
|
5151
5239
|
upstreamUrl.search = new URL(requestUrl, "http://localhost").search;
|
|
5152
5240
|
return upstreamUrl.toString();
|
|
5153
5241
|
}
|
|
5154
|
-
async function forwardCodexModels(requestUrl, requestHeaders
|
|
5242
|
+
async function forwardCodexModels(requestUrl, requestHeaders) {
|
|
5155
5243
|
const headers = buildCodexRequestHeaders(requestHeaders);
|
|
5156
5244
|
if (!headers.has("accept")) headers.set("accept", "application/json");
|
|
5157
|
-
return await fetch(resolveCodexModelsUrl(requestUrl
|
|
5245
|
+
return await fetch(resolveCodexModelsUrl(requestUrl), {
|
|
5158
5246
|
method: "GET",
|
|
5159
5247
|
headers
|
|
5160
5248
|
});
|
|
@@ -6247,7 +6335,7 @@ async function getAggregatedModels(requestHeaders) {
|
|
|
6247
6335
|
async function logCodexModelsResponse(response) {
|
|
6248
6336
|
try {
|
|
6249
6337
|
const responseText = await response.clone().text();
|
|
6250
|
-
logger$4
|
|
6338
|
+
debugJson(logger$4, "models.codex.response", {
|
|
6251
6339
|
statusCode: response.status,
|
|
6252
6340
|
models: responseText
|
|
6253
6341
|
});
|
|
@@ -6258,12 +6346,11 @@ async function logCodexModelsResponse(response) {
|
|
|
6258
6346
|
modelRoutes.get("/", async (c) => {
|
|
6259
6347
|
try {
|
|
6260
6348
|
if (isCodexUserAgent(c.req.header("user-agent"))) {
|
|
6261
|
-
|
|
6262
|
-
if (!codexProviderConfig) return c.json({ error: {
|
|
6349
|
+
if (!await resolveProviderConfig("codex")) return c.json({ error: {
|
|
6263
6350
|
message: "Provider 'codex' not found or disabled",
|
|
6264
6351
|
type: "invalid_request_error"
|
|
6265
6352
|
} }, 404);
|
|
6266
|
-
const upstreamResponse = await forwardCodexModels(c.req.url, c.req.raw.headers
|
|
6353
|
+
const upstreamResponse = await forwardCodexModels(c.req.url, c.req.raw.headers);
|
|
6267
6354
|
await logCodexModelsResponse(upstreamResponse);
|
|
6268
6355
|
return createProviderProxyResponse(upstreamResponse);
|
|
6269
6356
|
}
|
|
@@ -6747,6 +6834,7 @@ server.route("/usage", usageRoute);
|
|
|
6747
6834
|
server.route("/token-usage", tokenUsageRoute);
|
|
6748
6835
|
server.route("/token", tokenRoute);
|
|
6749
6836
|
server.route("/responses", responsesRoutes);
|
|
6837
|
+
server.route("/alpha/search", alphaSearchRoutes);
|
|
6750
6838
|
server.route("/v1/chat/completions", completionRoutes);
|
|
6751
6839
|
server.route("/v1/models", modelRoutes);
|
|
6752
6840
|
server.route("/v1/embeddings", embeddingRoutes);
|
|
@@ -6757,4 +6845,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
|
|
|
6757
6845
|
//#endregion
|
|
6758
6846
|
export { server };
|
|
6759
6847
|
|
|
6760
|
-
//# sourceMappingURL=server-
|
|
6848
|
+
//# sourceMappingURL=server-BUJBoWLv.js.map
|