@jeffreycao/copilot-api 2.7.37 → 2.7.39
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/{auth-Bamibni8.js → auth-DBOz2FcU.js} +9 -12
- package/dist/{auth-Bamibni8.js.map → auth-DBOz2FcU.js.map} +1 -1
- package/dist/auth-IiEbOqcu.js +1 -0
- package/dist/{config-D8pUyhJp.js → config-BqSuE5h5.js} +7 -22
- package/dist/config-BqSuE5h5.js.map +1 -0
- package/dist/{config-store-CYG9aCTL.js → config-store-BsluQttR.js} +7 -13
- package/dist/{config-store-CYG9aCTL.js.map → config-store-BsluQttR.js.map} +1 -1
- package/dist/{copilot-runtime-VVi3SKsW.js → copilot-runtime-0CujVONa.js} +11 -19
- package/dist/{copilot-runtime-VVi3SKsW.js.map → copilot-runtime-0CujVONa.js.map} +1 -1
- package/dist/{debug-BXvLeaet.js → debug-RUUyusA_.js} +4 -5
- package/dist/{debug-BXvLeaet.js.map → debug-RUUyusA_.js.map} +1 -1
- package/dist/{electron-fetch-DsMaRX6v.js → electron-fetch-ByE9Ctv0.js} +2 -3
- package/dist/{electron-fetch-DsMaRX6v.js.map → electron-fetch-ByE9Ctv0.js.map} +1 -1
- package/dist/{fast-path-BwgQKZBk.js → fast-path-B53kz5S1.js} +1 -2
- package/dist/{fast-path-BwgQKZBk.js.map → fast-path-B53kz5S1.js.map} +1 -1
- package/dist/main.js +9 -10
- package/dist/{mcp-Dd_hxxuG.js → mcp-DJE9135Q.js} +3 -4
- package/dist/{mcp-Dd_hxxuG.js.map → mcp-DJE9135Q.js.map} +1 -1
- package/dist/mcp-server-DPadDLWn.js +1 -0
- package/dist/{mcp-server-CTGaok8g.js → mcp-server-DvGD6L9t.js} +3 -4
- package/dist/{mcp-server-CTGaok8g.js.map → mcp-server-DvGD6L9t.js.map} +1 -1
- package/dist/{provider-C6wFZzeY.js → provider-BMPS2mij.js} +3 -4
- package/dist/{provider-C6wFZzeY.js.map → provider-BMPS2mij.js.map} +1 -1
- package/dist/{provider-management-B9lCOTka.js → provider-management-vyEQj9RR.js} +3 -4
- package/dist/{provider-management-B9lCOTka.js.map → provider-management-vyEQj9RR.js.map} +1 -1
- package/dist/{server-Z3SfnFdc.js → server-Jvc5DYJV.js} +104 -201
- package/dist/{server-Z3SfnFdc.js.map → server-Jvc5DYJV.js.map} +1 -1
- package/dist/{start-BEda1BbC.js → start-BQBvYKD-.js} +13 -18
- package/dist/{start-BEda1BbC.js.map → start-BQBvYKD-.js.map} +1 -1
- package/dist/{tls-uiriilgk.js → tls-cISpkgFD.js} +2 -3
- package/dist/{tls-uiriilgk.js.map → tls-cISpkgFD.js.map} +1 -1
- package/dist/{token-DW6rW7yB.js → token-_1CBLbqH.js} +23 -43
- package/dist/{token-DW6rW7yB.js.map → token-_1CBLbqH.js.map} +1 -1
- package/dist/{tool-search-CcvaqM03.js → tool-search-DzipwtCX.js} +2 -3
- package/dist/{tool-search-CcvaqM03.js.map → tool-search-DzipwtCX.js.map} +1 -1
- package/package.json +6 -6
- package/dist/auth-Dg8DFYd2.js +0 -2
- package/dist/config-D8pUyhJp.js.map +0 -1
- package/dist/mcp-server-CEfcUYiN.js +0 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { D as state, E as isGitHubCopilotEnabled, O as HTTPError, S as PATHS, a as getAnthropicApiKey, c as getConfig, d as getUpstreamTransportConfig, g as isResponsesApiWebSocketEnabled, h as isResponsesApiWebSearchEnabled, i as getAlphaSearchModel, j as forwardError, l as getMessageApiWebSearchModel, m as isMessagesApiEnabled, o as getClaudeAutoModel, p as isAlphaSearchCodexPriorityEnabled, s as getClaudeTokenMultiplier, u as getOpencodeModelContextWindow, w as GITHUB_COPILOT_PROVIDER, y as reloadConfig } from "./config-store-
|
|
2
|
-
import { A as resolveMappedModel, C as getModelResponsesApiCompactThreshold$1, D as isContextManagementEnabledForMessages, E as getSmallModelForProvider, O as isContextManagementEnabledForResponses, S as getModelMappings, T as getSmallModel, _ as getModelsDevModelMaxOutputTokens, a as normalizeProviderBaseUrl, d as isProviderModelVisible, f as resolveProviderModelsDevId, g as getModelsDevModel, h as getBuiltinProviderModelRecords, i as listEnabledProviders, j as setModelMappings, k as isGpt56OrAbove, l as getLocalProviderModelRecords, m as builtinProviderModelRegistry, n as getRawProviderConfig, o as resolveEffectiveProviderType, p as usesModelsDevModelCatalog, s as resolveProviderConfigForModel, t as getProviderConfig, u as getProviderModelConfig, v as getModelsDevModelPricing, w as getReasoningEffortForModel, x as getExtraPromptForModel } from "./config-
|
|
3
|
-
import { $ as forwardCodexResponses, B as getXaiAccessToken, C as copilotHeaders, D as prepareForCompact, E as isOpencodeOauthApp, F as compactTextOnlyGuard, I as createAuthMiddleware, J as XAI_API_BASE_URL, K as readGitHubToken, L as getConfiguredAdminApiKeys, M as compactMessageSections, O as prepareInteractionHeaders, P as compactSystemPromptStarts, Q as buildCodexRequestHeaders, S as copilotBaseUrl, T as copilotWebSocketHeaders, Z as CODEX_API_BASE_URL, _ as isAsyncIterable, at as createResponsesHttpEventStream, b as parseUserIdMetadata, ct as getResponsesStreamTerminalDisposition, d as generateRequestIdFromPayload, et as generateTraceId, f as getPromptCacheKey, ft as stripInternalRequestHeaders, g as getUUID, h as getSessionAffinityFromHeaders, it as fetchUpstreamWithLifecycle, j as compactAutoContinuePromptStarts, k as prepareMessageProxyHeaders, lt as createPooledWebSocketStream, m as getRootSessionIdFromHeaders, n as invalidateCodexRuntime, nt as resolveTraceId$1, ot as createResponsesSafeStream, p as getRootSessionId, q as readGitHubTokenFromEnv, rt as setPluginRequestActualModel, s as setupCodexToken, st as encodePoolKeyPart, tt as requestContext, u as stopCopilotRefreshLoop, ut as createWebSocketUrl, v as isNullish, x as getCopilotUsage, y as isResponsesStream } from "./token-
|
|
4
|
-
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-
|
|
5
|
-
import { n as isProviderAgentModelVisible, t as getProviderAgentModels } from "./provider-management-
|
|
6
|
-
import { i as registerProcessCleanup, n as stopModelsRefreshLoop, r as EventBus, t as setupCopilotRuntime } from "./copilot-runtime-
|
|
1
|
+
import { D as state, E as isGitHubCopilotEnabled, O as HTTPError, S as PATHS, a as getAnthropicApiKey, c as getConfig, d as getUpstreamTransportConfig, g as isResponsesApiWebSocketEnabled, h as isResponsesApiWebSearchEnabled, i as getAlphaSearchModel, j as forwardError, l as getMessageApiWebSearchModel, m as isMessagesApiEnabled, o as getClaudeAutoModel, p as isAlphaSearchCodexPriorityEnabled, s as getClaudeTokenMultiplier, u as getOpencodeModelContextWindow, w as GITHUB_COPILOT_PROVIDER, y as reloadConfig } from "./config-store-BsluQttR.js";
|
|
2
|
+
import { A as resolveMappedModel, C as getModelResponsesApiCompactThreshold$1, D as isContextManagementEnabledForMessages, E as getSmallModelForProvider, O as isContextManagementEnabledForResponses, S as getModelMappings, T as getSmallModel, _ as getModelsDevModelMaxOutputTokens, a as normalizeProviderBaseUrl, d as isProviderModelVisible, f as resolveProviderModelsDevId, g as getModelsDevModel, h as getBuiltinProviderModelRecords, i as listEnabledProviders, j as setModelMappings, k as isGpt56OrAbove, l as getLocalProviderModelRecords, m as builtinProviderModelRegistry, n as getRawProviderConfig, o as resolveEffectiveProviderType, p as usesModelsDevModelCatalog, s as resolveProviderConfigForModel, t as getProviderConfig, u as getProviderModelConfig, v as getModelsDevModelPricing, w as getReasoningEffortForModel, x as getExtraPromptForModel } from "./config-BqSuE5h5.js";
|
|
3
|
+
import { $ as forwardCodexResponses, B as getXaiAccessToken, C as copilotHeaders, D as prepareForCompact, E as isOpencodeOauthApp, F as compactTextOnlyGuard, I as createAuthMiddleware, J as XAI_API_BASE_URL, K as readGitHubToken, L as getConfiguredAdminApiKeys, M as compactMessageSections, O as prepareInteractionHeaders, P as compactSystemPromptStarts, Q as buildCodexRequestHeaders, S as copilotBaseUrl, T as copilotWebSocketHeaders, Z as CODEX_API_BASE_URL, _ as isAsyncIterable, at as createResponsesHttpEventStream, b as parseUserIdMetadata, ct as getResponsesStreamTerminalDisposition, d as generateRequestIdFromPayload, et as generateTraceId, f as getPromptCacheKey, ft as stripInternalRequestHeaders, g as getUUID, h as getSessionAffinityFromHeaders, it as fetchUpstreamWithLifecycle, j as compactAutoContinuePromptStarts, k as prepareMessageProxyHeaders, lt as createPooledWebSocketStream, m as getRootSessionIdFromHeaders, n as invalidateCodexRuntime, nt as resolveTraceId$1, ot as createResponsesSafeStream, p as getRootSessionId, q as readGitHubTokenFromEnv, rt as setPluginRequestActualModel, s as setupCodexToken, st as encodePoolKeyPart, tt as requestContext, u as stopCopilotRefreshLoop, ut as createWebSocketUrl, v as isNullish, x as getCopilotUsage, y as isResponsesStream } from "./token-_1CBLbqH.js";
|
|
4
|
+
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-DzipwtCX.js";
|
|
5
|
+
import { n as isProviderAgentModelVisible, t as getProviderAgentModels } from "./provider-management-vyEQj9RR.js";
|
|
6
|
+
import { i as registerProcessCleanup, n as stopModelsRefreshLoop, r as EventBus, t as setupCopilotRuntime } from "./copilot-runtime-0CujVONa.js";
|
|
7
7
|
import consola from "consola";
|
|
8
8
|
import { createHash, randomUUID } from "node:crypto";
|
|
9
9
|
import fs, { readFileSync } from "node:fs";
|
|
@@ -18,7 +18,7 @@ import { logger } from "hono/logger";
|
|
|
18
18
|
import util from "node:util";
|
|
19
19
|
import { streamSSE } from "hono/streaming";
|
|
20
20
|
import { decompress } from "fzstd";
|
|
21
|
-
|
|
21
|
+
// src/lib/trace.ts
|
|
22
22
|
const traceIdMiddleware = async (c, next) => {
|
|
23
23
|
const traceId = resolveTraceId$1(c.req.header("x-trace-id"));
|
|
24
24
|
c.header("x-trace-id", traceId);
|
|
@@ -34,8 +34,7 @@ const traceIdMiddleware = async (c, next) => {
|
|
|
34
34
|
await next();
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
|
|
38
|
-
//#region src/lib/sqlite.ts
|
|
37
|
+
// src/lib/sqlite.ts
|
|
39
38
|
const MINIMUM_NODE_SQLITE_VERSION = "22.13.0";
|
|
40
39
|
const isBunRuntime = () => Boolean(globalThis.Bun);
|
|
41
40
|
function parseNodeVersion(version) {
|
|
@@ -119,8 +118,7 @@ var SqliteDbStore = class {
|
|
|
119
118
|
return db;
|
|
120
119
|
}
|
|
121
120
|
};
|
|
122
|
-
|
|
123
|
-
//#region src/lib/token-usage/store.ts
|
|
121
|
+
// src/lib/token-usage/store.ts
|
|
124
122
|
const DB_PATH_ENV = "COPILOT_API_SQLITE_DB_PATH";
|
|
125
123
|
const DEFAULT_DB_FILENAME = "copilot-api.sqlite";
|
|
126
124
|
const COST_NANOS_PER_UNIT$1 = 1e9;
|
|
@@ -902,8 +900,7 @@ async function closeUsageStore() {
|
|
|
902
900
|
writeQueue = Promise.resolve();
|
|
903
901
|
}
|
|
904
902
|
registerProcessCleanup(closeUsageStore);
|
|
905
|
-
|
|
906
|
-
//#region src/lib/request-events.ts
|
|
903
|
+
// src/lib/request-events.ts
|
|
907
904
|
const TRACKED = /\/(chat\/completions|responses|messages|alpha\/search)$/;
|
|
908
905
|
function setPluginRequestModel(model) {
|
|
909
906
|
requestContext.getStore()?.pluginRequest?.setModel(model);
|
|
@@ -1035,8 +1032,7 @@ function requestEventsMiddleware(plugins, port) {
|
|
|
1035
1032
|
}
|
|
1036
1033
|
};
|
|
1037
1034
|
}
|
|
1038
|
-
|
|
1039
|
-
//#region src/lib/logger.ts
|
|
1035
|
+
// src/lib/logger.ts
|
|
1040
1036
|
const LOG_RETENTION_MS = 6048e5;
|
|
1041
1037
|
const CLEANUP_INTERVAL_MS = 864e5;
|
|
1042
1038
|
const LOG_DIR_ENV = "COPILOT_API_LOG_DIR";
|
|
@@ -1220,8 +1216,7 @@ const createHandlerLogger = (name) => {
|
|
|
1220
1216
|
} });
|
|
1221
1217
|
return instance;
|
|
1222
1218
|
};
|
|
1223
|
-
|
|
1224
|
-
//#region src/lib/models.ts
|
|
1219
|
+
// src/lib/models.ts
|
|
1225
1220
|
/**
|
|
1226
1221
|
* Converts a Copilot upstream model ID to a client-friendly ID that Claude Code
|
|
1227
1222
|
* and Claude Desktop recognize (dots in version replaced with hyphens).
|
|
@@ -1282,8 +1277,7 @@ const normalizeSdkModelId = (sdkModelId) => {
|
|
|
1282
1277
|
version: pattern5[1]
|
|
1283
1278
|
};
|
|
1284
1279
|
};
|
|
1285
|
-
|
|
1286
|
-
//#region src/lib/provider-model.ts
|
|
1280
|
+
// src/lib/provider-model.ts
|
|
1287
1281
|
const parseProviderModelAlias = (model) => {
|
|
1288
1282
|
const separatorIndex = model.indexOf("/");
|
|
1289
1283
|
if (separatorIndex <= 0 || separatorIndex === model.length - 1) return null;
|
|
@@ -1312,8 +1306,7 @@ const createFallbackModel = (modelId) => ({
|
|
|
1312
1306
|
vendor: "provider",
|
|
1313
1307
|
version: "unknown"
|
|
1314
1308
|
});
|
|
1315
|
-
|
|
1316
|
-
//#region src/lib/provider-resolver.ts
|
|
1309
|
+
// src/lib/provider-resolver.ts
|
|
1317
1310
|
const AZURE_OPENAI_SCOPE = "https://cognitiveservices.azure.com/.default";
|
|
1318
1311
|
let cachedAzureAccessTokenProvider = null;
|
|
1319
1312
|
/**
|
|
@@ -1392,8 +1385,7 @@ async function ensureConfiguredProviderModelAlias(alias, resolveConfig = resolve
|
|
|
1392
1385
|
async function resolveConfiguredProviderModelAlias(model, resolveConfig = resolveProviderConfig) {
|
|
1393
1386
|
return ensureConfiguredProviderModelAlias(parseProviderModelAlias(model), resolveConfig);
|
|
1394
1387
|
}
|
|
1395
|
-
|
|
1396
|
-
//#region src/lib/token-usage/pricing.ts
|
|
1388
|
+
// src/lib/token-usage/pricing.ts
|
|
1397
1389
|
const COST_NANOS_PER_UNIT = 1e9;
|
|
1398
1390
|
const COST_NANOS_PER_TOKEN_AT_ONE_PER_MILLION = 1e3;
|
|
1399
1391
|
const COPILOT_NANO_AIU_TO_COST_NANOS = COST_NANOS_PER_UNIT / 1e11;
|
|
@@ -1541,8 +1533,7 @@ function costNanosForTokens(tokens, pricePerMillionTokens) {
|
|
|
1541
1533
|
if (pricePerMillionTokens === null) return 0;
|
|
1542
1534
|
return Math.round(normalizeToken(tokens) * pricePerMillionTokens * COST_NANOS_PER_TOKEN_AT_ONE_PER_MILLION);
|
|
1543
1535
|
}
|
|
1544
|
-
|
|
1545
|
-
//#region src/lib/token-usage/index.ts
|
|
1536
|
+
// src/lib/token-usage/index.ts
|
|
1546
1537
|
const tokenUsageEventBus = new EventBus();
|
|
1547
1538
|
const USER_AGENT_MAX_LENGTH = 64;
|
|
1548
1539
|
function resolveTraceId(traceId) {
|
|
@@ -1679,8 +1670,7 @@ function mergeAnthropicUsage(current, next) {
|
|
|
1679
1670
|
function normalizeOptionalCost(value) {
|
|
1680
1671
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
1681
1672
|
}
|
|
1682
|
-
|
|
1683
|
-
//#region src/routes/alpha-search/alpha-search-types.ts
|
|
1673
|
+
// src/routes/alpha-search/alpha-search-types.ts
|
|
1684
1674
|
const unsignedInteger = z.number().int().nonnegative();
|
|
1685
1675
|
const passthroughRecord = z.record(z.string(), z.unknown());
|
|
1686
1676
|
const searchQuerySchema = z.object({
|
|
@@ -1813,8 +1803,7 @@ const alphaSearchRequestSchema = z.object({
|
|
|
1813
1803
|
settings: settingsSchema.optional(),
|
|
1814
1804
|
max_output_tokens: unsignedInteger.optional()
|
|
1815
1805
|
}).loose();
|
|
1816
|
-
|
|
1817
|
-
//#region src/routes/messages/web-search/backend.ts
|
|
1806
|
+
// src/routes/messages/web-search/backend.ts
|
|
1818
1807
|
/** Builds the Responses API web_search tool object from normalized config. */
|
|
1819
1808
|
const buildResponsesWebSearchTool = (config) => {
|
|
1820
1809
|
const tool = { type: "web_search" };
|
|
@@ -1891,8 +1880,7 @@ const extractWebSearchResult = (result) => {
|
|
|
1891
1880
|
queries
|
|
1892
1881
|
};
|
|
1893
1882
|
};
|
|
1894
|
-
|
|
1895
|
-
//#region src/lib/copilot-rate-limit.ts
|
|
1883
|
+
// src/lib/copilot-rate-limit.ts
|
|
1896
1884
|
const copilotRateLimitTypes = ["session", "weekly"];
|
|
1897
1885
|
const copilotRateLimitHeaders = {
|
|
1898
1886
|
session: "x-usage-ratelimit-session",
|
|
@@ -1964,8 +1952,7 @@ const isCopilotQuotaSnapshot = (value) => {
|
|
|
1964
1952
|
const record = value;
|
|
1965
1953
|
return typeof record.entitlement === "string" && typeof record.percent_remaining === "number" && typeof record.overage_permitted === "boolean" && typeof record.overage_count === "number" && typeof record.reset_date === "string";
|
|
1966
1954
|
};
|
|
1967
|
-
|
|
1968
|
-
//#region src/services/copilot/create-responses.ts
|
|
1955
|
+
// src/services/copilot/create-responses.ts
|
|
1969
1956
|
const createResponses = async (payload, { vision, initiator, subagentMarker, requestId, sessionId, compactType, transport = "http", clientSignal }) => {
|
|
1970
1957
|
if (!state.copilotToken) throw new Error("Copilot token not found");
|
|
1971
1958
|
const headers = {
|
|
@@ -2090,8 +2077,7 @@ const createResponsesWebSocketStreamChunk = (data) => {
|
|
|
2090
2077
|
return { data };
|
|
2091
2078
|
}
|
|
2092
2079
|
};
|
|
2093
|
-
|
|
2094
|
-
//#region src/lib/grok-build.ts
|
|
2080
|
+
// src/lib/grok-build.ts
|
|
2095
2081
|
const VERSION_URL = "https://x.ai/cli/stable";
|
|
2096
2082
|
const VERSION_CACHE_MS = 864e5;
|
|
2097
2083
|
const VERSION_RETRY_MS = 3e5;
|
|
@@ -2120,8 +2106,7 @@ async function getGrokBuildVersion() {
|
|
|
2120
2106
|
});
|
|
2121
2107
|
return await versionInFlight;
|
|
2122
2108
|
}
|
|
2123
|
-
|
|
2124
|
-
//#region src/lib/timeout-dispatcher.ts
|
|
2109
|
+
// src/lib/timeout-dispatcher.ts
|
|
2125
2110
|
/**
|
|
2126
2111
|
* Node's global fetch keeps Undici's shorter default headers/body timeouts.
|
|
2127
2112
|
* Wrap the global dispatcher so long-running requests (e.g. image
|
|
@@ -2134,8 +2119,7 @@ const createTimeoutDispatcher = (timeoutMs) => ({ dispatch(options, handler) {
|
|
|
2134
2119
|
headersTimeout: timeoutMs
|
|
2135
2120
|
}, handler);
|
|
2136
2121
|
} });
|
|
2137
|
-
|
|
2138
|
-
//#region src/services/providers/provider-proxy.ts
|
|
2122
|
+
// src/services/providers/provider-proxy.ts
|
|
2139
2123
|
const OPENCODE_GO_PROVIDER_NAME = "opencode-go";
|
|
2140
2124
|
const OPENCODE_SESSION_HEADER = "x-opencode-session";
|
|
2141
2125
|
const SHARED_FORWARDABLE_HEADERS = ["accept", "user-agent"];
|
|
@@ -2363,8 +2347,7 @@ async function forwardProviderImages(providerConfig, request, operation) {
|
|
|
2363
2347
|
dispatcher: providerImagesDispatcher
|
|
2364
2348
|
});
|
|
2365
2349
|
}
|
|
2366
|
-
|
|
2367
|
-
//#region src/routes/alpha-search/alpha-search-responses.ts
|
|
2350
|
+
// src/routes/alpha-search/alpha-search-responses.ts
|
|
2368
2351
|
const logger$19 = createHandlerLogger("alpha-search-responses-handler");
|
|
2369
2352
|
const SESSION_TTL_MS = 36e5;
|
|
2370
2353
|
const MAX_SESSIONS = 128;
|
|
@@ -2849,8 +2832,7 @@ async function handleAlphaSearchResponses(c, options) {
|
|
|
2849
2832
|
}
|
|
2850
2833
|
return c.json(buildAlphaSearchResponse(state));
|
|
2851
2834
|
}
|
|
2852
|
-
|
|
2853
|
-
//#region src/services/codex/alpha-search.ts
|
|
2835
|
+
// src/services/codex/alpha-search.ts
|
|
2854
2836
|
const CODEX_ALPHA_SEARCH_URL = `${CODEX_API_BASE_URL}/codex/alpha/search`;
|
|
2855
2837
|
function resolveCodexAlphaSearchUrl(requestUrl) {
|
|
2856
2838
|
const upstreamUrl = new URL(CODEX_ALPHA_SEARCH_URL);
|
|
@@ -2868,8 +2850,7 @@ async function forwardCodexAlphaSearch(request) {
|
|
|
2868
2850
|
body
|
|
2869
2851
|
});
|
|
2870
2852
|
}
|
|
2871
|
-
|
|
2872
|
-
//#region src/routes/alpha-search/route.ts
|
|
2853
|
+
// src/routes/alpha-search/route.ts
|
|
2873
2854
|
const logger$18 = createHandlerLogger("alpha-search-handler");
|
|
2874
2855
|
const alphaSearchRoutes = new Hono();
|
|
2875
2856
|
const alphaSearchRouteDependencies = {
|
|
@@ -3010,8 +2991,7 @@ alphaSearchRoutes.post("/", async (c) => {
|
|
|
3010
2991
|
return await forwardError(c, error);
|
|
3011
2992
|
}
|
|
3012
2993
|
});
|
|
3013
|
-
|
|
3014
|
-
//#region src/lib/first-token.ts
|
|
2994
|
+
// src/lib/first-token.ts
|
|
3015
2995
|
const nonempty = (value) => typeof value === "string" && value.length > 0;
|
|
3016
2996
|
function recordChatCompletionFirstToken(chunk) {
|
|
3017
2997
|
const observer = requestContext.getStore()?.requestTiming ?? requestContext.getStore()?.pluginRequest;
|
|
@@ -3050,8 +3030,7 @@ function recordGoogleFirstToken(response) {
|
|
|
3050
3030
|
if (!observer) return;
|
|
3051
3031
|
if (response.candidates?.some((candidate) => candidate.content?.parts.some((part) => part.thought === true || nonempty(part.text) || nonempty(part.functionCall?.name)))) observer.recordFirstToken();
|
|
3052
3032
|
}
|
|
3053
|
-
|
|
3054
|
-
//#region src/lib/sse.ts
|
|
3033
|
+
// src/lib/sse.ts
|
|
3055
3034
|
async function writeSSEIfConnected(stream, message) {
|
|
3056
3035
|
if (stream.aborted) return false;
|
|
3057
3036
|
try {
|
|
@@ -3062,8 +3041,7 @@ async function writeSSEIfConnected(stream, message) {
|
|
|
3062
3041
|
throw error;
|
|
3063
3042
|
}
|
|
3064
3043
|
}
|
|
3065
|
-
|
|
3066
|
-
//#region src/lib/dashscope.ts
|
|
3044
|
+
// src/lib/dashscope.ts
|
|
3067
3045
|
const OPENAI_COMPATIBLE_CONTEXT_CACHE_MARKER_LIMIT = 4;
|
|
3068
3046
|
const OPENAI_COMPATIBLE_CONTEXT_CACHE_CONTROL = { type: "ephemeral" };
|
|
3069
3047
|
const OPENAI_COMPATIBLE_CONTEXT_CACHE_ROLES = /* @__PURE__ */ new Set([
|
|
@@ -3113,8 +3091,7 @@ const applyContextCacheControl = (message) => {
|
|
|
3113
3091
|
const setContextCacheControl = (part) => {
|
|
3114
3092
|
part.cache_control = { ...OPENAI_COMPATIBLE_CONTEXT_CACHE_CONTROL };
|
|
3115
3093
|
};
|
|
3116
|
-
|
|
3117
|
-
//#region src/lib/reasoning-effort.ts
|
|
3094
|
+
// src/lib/reasoning-effort.ts
|
|
3118
3095
|
const REASONING_EFFORT_LEVELS = [
|
|
3119
3096
|
"none",
|
|
3120
3097
|
"minimal",
|
|
@@ -3160,8 +3137,7 @@ const resolveSupportedReasoningEffort = (requestedEffort, supportedEfforts) => {
|
|
|
3160
3137
|
if (nearestBelow) return nearestBelow;
|
|
3161
3138
|
return supported.reduce((lowest, effort) => reasoningEffortRank(effort) < reasoningEffortRank(lowest) ? effort : lowest);
|
|
3162
3139
|
};
|
|
3163
|
-
|
|
3164
|
-
//#region src/routes/provider/utils.ts
|
|
3140
|
+
// src/routes/provider/utils.ts
|
|
3165
3141
|
const forwardProviderResponseHeaders = (c, upstreamHeaders) => {
|
|
3166
3142
|
const headers = createProviderProxyResponseHeaders(upstreamHeaders);
|
|
3167
3143
|
headers.delete("set-cookie");
|
|
@@ -3191,8 +3167,7 @@ const normalizeProviderResponsesReasoningEffort = (payload, providerConfig) => {
|
|
|
3191
3167
|
to: resolvedEffort
|
|
3192
3168
|
};
|
|
3193
3169
|
};
|
|
3194
|
-
|
|
3195
|
-
//#region src/routes/provider/chat-completions/handler.ts
|
|
3170
|
+
// src/routes/provider/chat-completions/handler.ts
|
|
3196
3171
|
const logger$17 = createHandlerLogger("provider-chat-completions-handler");
|
|
3197
3172
|
async function handleProviderChatCompletionsForProvider(c, options) {
|
|
3198
3173
|
const { payload, provider } = options;
|
|
@@ -3278,8 +3253,7 @@ const parseChatCompletionChunkData = (data) => {
|
|
|
3278
3253
|
return null;
|
|
3279
3254
|
}
|
|
3280
3255
|
};
|
|
3281
|
-
|
|
3282
|
-
//#region src/services/copilot/create-chat-completions.ts
|
|
3256
|
+
// src/services/copilot/create-chat-completions.ts
|
|
3283
3257
|
const createChatCompletions = async (payload, options) => {
|
|
3284
3258
|
if (!state.copilotToken) throw new Error("Copilot token not found");
|
|
3285
3259
|
const enableVision = payload.messages.some((x) => typeof x.content !== "string" && x.content?.some((x) => x.type === "image_url"));
|
|
@@ -3314,8 +3288,7 @@ const createChatCompletions = async (payload, options) => {
|
|
|
3314
3288
|
if (payload.stream) return events(response);
|
|
3315
3289
|
return await response.json();
|
|
3316
3290
|
};
|
|
3317
|
-
|
|
3318
|
-
//#region src/routes/chat-completions/handler.ts
|
|
3291
|
+
// src/routes/chat-completions/handler.ts
|
|
3319
3292
|
const logger$16 = createHandlerLogger("chat-completions-handler");
|
|
3320
3293
|
async function handleCompletion$1(c) {
|
|
3321
3294
|
let payload = await c.req.json();
|
|
@@ -3393,8 +3366,7 @@ const parseChatCompletionChunk = (chunk) => {
|
|
|
3393
3366
|
return null;
|
|
3394
3367
|
}
|
|
3395
3368
|
};
|
|
3396
|
-
|
|
3397
|
-
//#region src/routes/chat-completions/route.ts
|
|
3369
|
+
// src/routes/chat-completions/route.ts
|
|
3398
3370
|
const completionRoutes = new Hono();
|
|
3399
3371
|
completionRoutes.post("/", async (c) => {
|
|
3400
3372
|
try {
|
|
@@ -3403,8 +3375,7 @@ completionRoutes.post("/", async (c) => {
|
|
|
3403
3375
|
return await forwardError(c, error);
|
|
3404
3376
|
}
|
|
3405
3377
|
});
|
|
3406
|
-
|
|
3407
|
-
//#region src/lib/config-reload.ts
|
|
3378
|
+
// src/lib/config-reload.ts
|
|
3408
3379
|
let pendingReload = Promise.resolve();
|
|
3409
3380
|
async function applyConfigReload() {
|
|
3410
3381
|
const previousConfig = getConfig();
|
|
@@ -3449,8 +3420,7 @@ function reloadServerConfig() {
|
|
|
3449
3420
|
pendingReload = reload.catch(() => {});
|
|
3450
3421
|
return reload;
|
|
3451
3422
|
}
|
|
3452
|
-
|
|
3453
|
-
//#region src/routes/admin/config/route.ts
|
|
3423
|
+
// src/routes/admin/config/route.ts
|
|
3454
3424
|
const configRoutes = new Hono();
|
|
3455
3425
|
const modelMappingsRequestSchema = z.object({ modelMappings: z.record(z.string(), z.string()) });
|
|
3456
3426
|
configRoutes.post("/reload", async (c) => {
|
|
@@ -3486,8 +3456,7 @@ configRoutes.post("/model-mappings", async (c) => {
|
|
|
3486
3456
|
return await forwardError(c, error);
|
|
3487
3457
|
}
|
|
3488
3458
|
});
|
|
3489
|
-
|
|
3490
|
-
//#region src/services/copilot/create-embeddings.ts
|
|
3459
|
+
// src/services/copilot/create-embeddings.ts
|
|
3491
3460
|
const createEmbeddings = async (payload) => {
|
|
3492
3461
|
if (!state.copilotToken) throw new Error("Copilot token not found");
|
|
3493
3462
|
const response = await fetch(`${copilotBaseUrl(state)}/embeddings`, {
|
|
@@ -3498,8 +3467,7 @@ const createEmbeddings = async (payload) => {
|
|
|
3498
3467
|
if (!response.ok) throw new HTTPError("Failed to create embeddings", response);
|
|
3499
3468
|
return await response.json();
|
|
3500
3469
|
};
|
|
3501
|
-
|
|
3502
|
-
//#region src/routes/embeddings/route.ts
|
|
3470
|
+
// src/routes/embeddings/route.ts
|
|
3503
3471
|
const embeddingRoutes = new Hono();
|
|
3504
3472
|
embeddingRoutes.post("/", async (c) => {
|
|
3505
3473
|
try {
|
|
@@ -3517,8 +3485,7 @@ embeddingRoutes.post("/", async (c) => {
|
|
|
3517
3485
|
return await forwardError(c, error);
|
|
3518
3486
|
}
|
|
3519
3487
|
});
|
|
3520
|
-
|
|
3521
|
-
//#region src/lib/xai-image-model.ts
|
|
3488
|
+
// src/lib/xai-image-model.ts
|
|
3522
3489
|
/**
|
|
3523
3490
|
* Resolves one image-route model setting. Empty values keep the OpenAI
|
|
3524
3491
|
* protocol. Only an xai/model alias selects the xAI Imagine API.
|
|
@@ -3547,8 +3514,7 @@ function getImageGenerationModel() {
|
|
|
3547
3514
|
function getImageEditModel() {
|
|
3548
3515
|
return resolveConfiguredXaiImageModel(getConfig().imageEditModel, "imageEditModel");
|
|
3549
3516
|
}
|
|
3550
|
-
|
|
3551
|
-
//#region src/routes/images/forward-provider-images.ts
|
|
3517
|
+
// src/routes/images/forward-provider-images.ts
|
|
3552
3518
|
/**
|
|
3553
3519
|
* Forwards an images request to a configured provider with debug logging.
|
|
3554
3520
|
* Shared by the top-level images routes (model mapping) and the
|
|
@@ -3573,8 +3539,7 @@ async function forwardProviderImagesWithLogging(providerConfig, request, operati
|
|
|
3573
3539
|
});
|
|
3574
3540
|
return createProviderProxyResponse(upstreamResponse);
|
|
3575
3541
|
}
|
|
3576
|
-
|
|
3577
|
-
//#region src/services/codex/images.ts
|
|
3542
|
+
// src/services/codex/images.ts
|
|
3578
3543
|
const CODEX_IMAGES_TIMEOUT_MS = 9e5;
|
|
3579
3544
|
const codexImagesDispatcher = createTimeoutDispatcher(CODEX_IMAGES_TIMEOUT_MS);
|
|
3580
3545
|
function resolveCodexImagesUrl(requestUrl, operation) {
|
|
@@ -3600,8 +3565,7 @@ async function forwardCodexImages(request, operation) {
|
|
|
3600
3565
|
dispatcher: codexImagesDispatcher
|
|
3601
3566
|
});
|
|
3602
3567
|
}
|
|
3603
|
-
|
|
3604
|
-
//#region src/routes/images/shared.ts
|
|
3568
|
+
// src/routes/images/shared.ts
|
|
3605
3569
|
const logger$15 = createHandlerLogger("images-handler");
|
|
3606
3570
|
const imageRouteDependencies = {
|
|
3607
3571
|
debugJsonAsync,
|
|
@@ -3725,8 +3689,7 @@ async function routeImagesRequest(c, operation, parsed) {
|
|
|
3725
3689
|
if (parsed.originalRequest && mappedModel === requestedModel) return await handleCodexImages(c, operation, void 0, parsed.originalRequest);
|
|
3726
3690
|
return await handleCodexImages(c, operation, void 0, parsed.createRequest(mappedModel));
|
|
3727
3691
|
}
|
|
3728
|
-
|
|
3729
|
-
//#region src/services/xai/images.ts
|
|
3692
|
+
// src/services/xai/images.ts
|
|
3730
3693
|
const XAI_ASPECT_RATIOS = [
|
|
3731
3694
|
{
|
|
3732
3695
|
label: "1:1",
|
|
@@ -4111,8 +4074,7 @@ async function ensureImageResponseB64Json(response, fetchImage = globalThis.fetc
|
|
|
4111
4074
|
data
|
|
4112
4075
|
}));
|
|
4113
4076
|
}
|
|
4114
|
-
|
|
4115
|
-
//#region src/routes/images/xai-handler.ts
|
|
4077
|
+
// src/routes/images/xai-handler.ts
|
|
4116
4078
|
function xaiImagesRequestErrorResponse(c, error) {
|
|
4117
4079
|
if (!(error instanceof XaiImagesRequestError)) return null;
|
|
4118
4080
|
return c.json({ error: {
|
|
@@ -4165,8 +4127,7 @@ async function handleXaiImageGeneration(c, model) {
|
|
|
4165
4127
|
async function handleXaiImageEdit(c, model) {
|
|
4166
4128
|
return await forwardTranslatedXaiImages(c, "edits", translateXaiImageEditJson(await readJsonBody(c.req.raw, "Image edit body must be JSON"), model));
|
|
4167
4129
|
}
|
|
4168
|
-
|
|
4169
|
-
//#region src/routes/images/edits-handler.ts
|
|
4130
|
+
// src/routes/images/edits-handler.ts
|
|
4170
4131
|
async function handleImagesEdits(c) {
|
|
4171
4132
|
try {
|
|
4172
4133
|
const configuredModel = imageRouteDependencies.getImageEditModel();
|
|
@@ -4187,8 +4148,7 @@ async function handleImagesEdits(c) {
|
|
|
4187
4148
|
return await forwardError(c, error);
|
|
4188
4149
|
}
|
|
4189
4150
|
}
|
|
4190
|
-
|
|
4191
|
-
//#region src/routes/images/generations-handler.ts
|
|
4151
|
+
// src/routes/images/generations-handler.ts
|
|
4192
4152
|
async function handleImagesGenerations(c) {
|
|
4193
4153
|
try {
|
|
4194
4154
|
const configuredModel = imageRouteDependencies.getImageGenerationModel();
|
|
@@ -4207,13 +4167,11 @@ async function handleImagesGenerations(c) {
|
|
|
4207
4167
|
return await forwardError(c, error);
|
|
4208
4168
|
}
|
|
4209
4169
|
}
|
|
4210
|
-
|
|
4211
|
-
//#region src/routes/images/route.ts
|
|
4170
|
+
// src/routes/images/route.ts
|
|
4212
4171
|
const imageRoutes = new Hono();
|
|
4213
4172
|
imageRoutes.post("/generations", handleImagesGenerations);
|
|
4214
4173
|
imageRoutes.post("/edits", handleImagesEdits);
|
|
4215
|
-
|
|
4216
|
-
//#region src/lib/model-pdf-support.ts
|
|
4174
|
+
// src/lib/model-pdf-support.ts
|
|
4217
4175
|
function resolveModelPdfSupport(provider, options) {
|
|
4218
4176
|
if (options.supportPdf !== void 0) return options.supportPdf;
|
|
4219
4177
|
return options.builtinSupportPdf === true || provider === "github-copilot" && Array.isArray(options.supportedMediaTypes) && options.supportedMediaTypes.includes("application/pdf") || Array.isArray(options.catalogInputModalities) && options.catalogInputModalities.includes("pdf");
|
|
@@ -4231,8 +4189,7 @@ function getProviderModelPdfSupport(modelId, provider, selectedModel) {
|
|
|
4231
4189
|
builtinSupportPdf: builtin?.supportPdf ?? builtinProviderModelRegistry.getProviderDefaults(provider.name)?.supportPdf
|
|
4232
4190
|
});
|
|
4233
4191
|
}
|
|
4234
|
-
|
|
4235
|
-
//#region src/lib/claude-models.ts
|
|
4192
|
+
// src/lib/claude-models.ts
|
|
4236
4193
|
const DISCOVERY_MODEL_PREFIX = "my-claude-";
|
|
4237
4194
|
const DISCOVERY_MODEL_SUFFIX = "[1m]";
|
|
4238
4195
|
function isClaudeUserAgent(userAgent) {
|
|
@@ -4258,8 +4215,7 @@ function fromClaudeDiscoveryModelId(modelId) {
|
|
|
4258
4215
|
function stripDiscoveryModelSuffix(modelId) {
|
|
4259
4216
|
return modelId.endsWith(DISCOVERY_MODEL_SUFFIX) ? modelId.slice(0, -4) : modelId;
|
|
4260
4217
|
}
|
|
4261
|
-
|
|
4262
|
-
//#region src/lib/tokenizer.ts
|
|
4218
|
+
// src/lib/tokenizer.ts
|
|
4263
4219
|
const ENCODING_MAP = {
|
|
4264
4220
|
o200k_base: () => import("gpt-tokenizer/encoding/o200k_base"),
|
|
4265
4221
|
cl100k_base: () => import("gpt-tokenizer/encoding/cl100k_base"),
|
|
@@ -4476,8 +4432,7 @@ const getTokenCount = async (payload, model) => {
|
|
|
4476
4432
|
output: outputTokens
|
|
4477
4433
|
};
|
|
4478
4434
|
};
|
|
4479
|
-
|
|
4480
|
-
//#region src/routes/messages/utils.ts
|
|
4435
|
+
// src/routes/messages/utils.ts
|
|
4481
4436
|
function mapOpenAIStopReasonToAnthropic(finishReason) {
|
|
4482
4437
|
if (finishReason === null) return null;
|
|
4483
4438
|
return {
|
|
@@ -5303,8 +5258,7 @@ const prepareMessagesApiPayload = (payload, selectedModel) => {
|
|
|
5303
5258
|
}
|
|
5304
5259
|
}
|
|
5305
5260
|
};
|
|
5306
|
-
|
|
5307
|
-
//#region src/routes/provider/messages/count-tokens-handler.ts
|
|
5261
|
+
// src/routes/provider/messages/count-tokens-handler.ts
|
|
5308
5262
|
const logger$14 = createHandlerLogger("provider-count-tokens-handler");
|
|
5309
5263
|
async function handleProviderCountTokens(c) {
|
|
5310
5264
|
const provider = c.req.param("provider");
|
|
@@ -5340,8 +5294,7 @@ async function handleProviderCountTokensForProvider(c, options) {
|
|
|
5340
5294
|
});
|
|
5341
5295
|
return c.json({ input_tokens: finalTokenCount });
|
|
5342
5296
|
}
|
|
5343
|
-
|
|
5344
|
-
//#region src/routes/messages/count-tokens-handler.ts
|
|
5297
|
+
// src/routes/messages/count-tokens-handler.ts
|
|
5345
5298
|
const resolveCountTokensModel = (modelId, findModel = findEndpointModel) => {
|
|
5346
5299
|
const selectedModel = findModel(modelId);
|
|
5347
5300
|
if (selectedModel) return {
|
|
@@ -5431,8 +5384,7 @@ async function handleCountTokens(c) {
|
|
|
5431
5384
|
consola.info("Token count:", finalTokenCount);
|
|
5432
5385
|
return c.json({ input_tokens: finalTokenCount });
|
|
5433
5386
|
}
|
|
5434
|
-
|
|
5435
|
-
//#region src/lib/codex-rate-limit.ts
|
|
5387
|
+
// src/lib/codex-rate-limit.ts
|
|
5436
5388
|
const codexRateLimitScopes = ["primary", "secondary"];
|
|
5437
5389
|
const formatCodexRateLimitResetAt = (resetAt) => {
|
|
5438
5390
|
const date = /* @__PURE__ */ new Date(resetAt * 1e3);
|
|
@@ -5464,8 +5416,7 @@ const isCodexRateLimitWindow = (value) => {
|
|
|
5464
5416
|
const record = value;
|
|
5465
5417
|
return typeof record.reset_after_seconds === "number" && typeof record.reset_at === "number" && typeof record.used_percent === "number" && typeof record.window_minutes === "number";
|
|
5466
5418
|
};
|
|
5467
|
-
|
|
5468
|
-
//#region src/routes/messages/completions-stream-translation.ts
|
|
5419
|
+
// src/routes/messages/completions-stream-translation.ts
|
|
5469
5420
|
function isToolBlockOpen(state) {
|
|
5470
5421
|
if (!state.contentBlockOpen) return false;
|
|
5471
5422
|
return Object.values(state.toolCalls).some((tc) => tc.anthropicBlockIndex === state.contentBlockIndex);
|
|
@@ -5783,8 +5734,7 @@ function translateErrorToAnthropicErrorEvent() {
|
|
|
5783
5734
|
}
|
|
5784
5735
|
};
|
|
5785
5736
|
}
|
|
5786
|
-
|
|
5787
|
-
//#region src/routes/messages/responses-translation.ts
|
|
5737
|
+
// src/routes/messages/responses-translation.ts
|
|
5788
5738
|
const MESSAGE_TYPE = "message";
|
|
5789
5739
|
const COMPACTION_SIGNATURE_PREFIX = "cm1#";
|
|
5790
5740
|
const COMPACTION_SIGNATURE_SEPARATOR = "@";
|
|
@@ -6391,8 +6341,7 @@ const isSupportAllTurns = (payload) => {
|
|
|
6391
6341
|
if (payload.model === "gpt-5.4" || payload.model === "gpt-5.4-mini" || payload.model === "gpt-5.5") return true;
|
|
6392
6342
|
return isGpt56OrAbove(payload.model);
|
|
6393
6343
|
};
|
|
6394
|
-
|
|
6395
|
-
//#region src/routes/messages/responses-stream-translation.ts
|
|
6344
|
+
// src/routes/messages/responses-stream-translation.ts
|
|
6396
6345
|
const MAX_CONSECUTIVE_FUNCTION_CALL_WHITESPACE = 20;
|
|
6397
6346
|
var FunctionCallArgumentsValidationError = class extends Error {
|
|
6398
6347
|
constructor(message) {
|
|
@@ -6864,8 +6813,7 @@ const stringifyToolSearchArguments = (argumentsValue) => {
|
|
|
6864
6813
|
return;
|
|
6865
6814
|
}
|
|
6866
6815
|
};
|
|
6867
|
-
|
|
6868
|
-
//#region src/routes/messages/responses-stream-collection.ts
|
|
6816
|
+
// src/routes/messages/responses-stream-collection.ts
|
|
6869
6817
|
const collectResponsesStreamResult = async ({ errorMessagePrefix = "Responses stream", parseEvent = parseResponsesStreamEvent$1, upstreamResponse, logger }) => {
|
|
6870
6818
|
const state = createResponsesStreamCollection();
|
|
6871
6819
|
for await (const chunk of upstreamResponse) {
|
|
@@ -6920,8 +6868,7 @@ const collectResponsesStreamEvent = (event, state) => {
|
|
|
6920
6868
|
const getStreamErrorMessage = (event) => {
|
|
6921
6869
|
return event.error?.message ?? event.message ?? void 0;
|
|
6922
6870
|
};
|
|
6923
|
-
|
|
6924
|
-
//#region src/routes/responses/messages-translation.ts
|
|
6871
|
+
// src/routes/responses/messages-translation.ts
|
|
6925
6872
|
const MESSAGES_COMPACTION_PREFIX = "copilot-api:messages-compaction:v1:";
|
|
6926
6873
|
const MESSAGES_REASONING_ID_SUFFIX = "__a1";
|
|
6927
6874
|
const markMessagesReasoningId = (id) => `${id}${MESSAGES_REASONING_ID_SUFFIX}`;
|
|
@@ -7931,8 +7878,7 @@ const containsVisionContent = (value) => {
|
|
|
7931
7878
|
if (Array.isArray(record.content)) return record.content.some((entry) => containsVisionContent(entry));
|
|
7932
7879
|
return false;
|
|
7933
7880
|
};
|
|
7934
|
-
|
|
7935
|
-
//#region src/routes/messages/web-search/fulfill.ts
|
|
7881
|
+
// src/routes/messages/web-search/fulfill.ts
|
|
7936
7882
|
const webSearchFlowDependencies = {
|
|
7937
7883
|
createResponses,
|
|
7938
7884
|
getMessageApiWebSearchModel,
|
|
@@ -8225,8 +8171,7 @@ const buildSyntheticStreamEvents = (response) => {
|
|
|
8225
8171
|
}, { type: "message_stop" });
|
|
8226
8172
|
return events;
|
|
8227
8173
|
};
|
|
8228
|
-
|
|
8229
|
-
//#region src/services/codex/get-models.ts
|
|
8174
|
+
// src/services/codex/get-models.ts
|
|
8230
8175
|
const CODEX_MODELS = [
|
|
8231
8176
|
{
|
|
8232
8177
|
contextWindow: 872e3,
|
|
@@ -8401,8 +8346,7 @@ function getModels() {
|
|
|
8401
8346
|
data: CODEX_MODELS.map((model) => normalizeCodexModel(model))
|
|
8402
8347
|
};
|
|
8403
8348
|
}
|
|
8404
|
-
|
|
8405
|
-
//#region src/routes/messages/google-thinking.ts
|
|
8349
|
+
// src/routes/messages/google-thinking.ts
|
|
8406
8350
|
function supportsThinkingControls(modelId) {
|
|
8407
8351
|
const model = modelId.replace(/^models\//u, "").toLowerCase();
|
|
8408
8352
|
if (/(?:^|-)(?:tts|live|image)(?:-|$)/u.test(model)) return false;
|
|
@@ -8427,8 +8371,7 @@ function translateGoogleThinking(payload) {
|
|
|
8427
8371
|
if (effort) config.thinkingLevel = effort === "low" ? "LOW" : effort === "medium" ? "MEDIUM" : "HIGH";
|
|
8428
8372
|
return config;
|
|
8429
8373
|
}
|
|
8430
|
-
|
|
8431
|
-
//#region src/routes/messages/google-translation.ts
|
|
8374
|
+
// src/routes/messages/google-translation.ts
|
|
8432
8375
|
const GOOGLE_SIGNATURE_PREFIX = "google:";
|
|
8433
8376
|
function encodeGoogleSignature(signature, target) {
|
|
8434
8377
|
return GOOGLE_SIGNATURE_PREFIX + Buffer.from(JSON.stringify({
|
|
@@ -8658,8 +8601,7 @@ function translateGoogleToAnthropic(response, model) {
|
|
|
8658
8601
|
usage: translateGoogleUsage(response.usageMetadata)
|
|
8659
8602
|
};
|
|
8660
8603
|
}
|
|
8661
|
-
|
|
8662
|
-
//#region src/routes/messages/google-stream-translation.ts
|
|
8604
|
+
// src/routes/messages/google-stream-translation.ts
|
|
8663
8605
|
var GoogleMessagesStreamTranslator = class {
|
|
8664
8606
|
started = false;
|
|
8665
8607
|
nextIndex = 0;
|
|
@@ -8839,8 +8781,7 @@ var GoogleMessagesStreamTranslator = class {
|
|
|
8839
8781
|
this.block = void 0;
|
|
8840
8782
|
}
|
|
8841
8783
|
};
|
|
8842
|
-
|
|
8843
|
-
//#region src/services/providers/google.ts
|
|
8784
|
+
// src/services/providers/google.ts
|
|
8844
8785
|
async function forwardGoogleGenerateContent(provider, model, payload, requestHeaders, options) {
|
|
8845
8786
|
const modelId = encodeURIComponent(model.replace(/^models\//u, ""));
|
|
8846
8787
|
const method = options.stream ? "streamGenerateContent" : "generateContent";
|
|
@@ -8861,8 +8802,7 @@ async function forwardGoogleGenerateContent(provider, model, payload, requestHea
|
|
|
8861
8802
|
streamInactivityTimeoutMs: transport.streamInactivityTimeoutMs
|
|
8862
8803
|
});
|
|
8863
8804
|
}
|
|
8864
|
-
|
|
8865
|
-
//#region src/routes/provider/messages/google-handler.ts
|
|
8805
|
+
// src/routes/provider/messages/google-handler.ts
|
|
8866
8806
|
const logger$13 = createHandlerLogger("provider-google-messages");
|
|
8867
8807
|
async function handleGoogleProviderMessages(c, payload, provider, usageEndpoint) {
|
|
8868
8808
|
debugJson(logger$13, "provider.messages.google.original_request", payload);
|
|
@@ -8936,8 +8876,7 @@ async function handleGoogleProviderMessages(c, payload, provider, usageEndpoint)
|
|
|
8936
8876
|
}
|
|
8937
8877
|
});
|
|
8938
8878
|
}
|
|
8939
|
-
|
|
8940
|
-
//#region src/routes/provider/messages/handler.ts
|
|
8879
|
+
// src/routes/provider/messages/handler.ts
|
|
8941
8880
|
const logger$12 = createHandlerLogger("provider-messages-handler");
|
|
8942
8881
|
const providerMessagesHandlerDependencies = { resolveProviderConfig };
|
|
8943
8882
|
async function handleProviderMessages(c) {
|
|
@@ -9618,8 +9557,7 @@ const createProviderMessagesUsageRecorder = (payload, provider, modelConfig, pri
|
|
|
9618
9557
|
providerName: provider,
|
|
9619
9558
|
sessionId: parseUserIdMetadata(payload.metadata?.user_id).sessionId
|
|
9620
9559
|
});
|
|
9621
|
-
|
|
9622
|
-
//#region src/services/copilot/create-messages.ts
|
|
9560
|
+
// src/services/copilot/create-messages.ts
|
|
9623
9561
|
const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
9624
9562
|
const allowedAnthropicBetas = /* @__PURE__ */ new Set([
|
|
9625
9563
|
INTERLEAVED_THINKING_BETA,
|
|
@@ -9680,8 +9618,7 @@ const createMessages = async (payload, anthropicBetaHeader, options) => {
|
|
|
9680
9618
|
if (payload.stream) return events(response);
|
|
9681
9619
|
return await response.json();
|
|
9682
9620
|
};
|
|
9683
|
-
|
|
9684
|
-
//#region src/routes/messages/api-flows.ts
|
|
9621
|
+
// src/routes/messages/api-flows.ts
|
|
9685
9622
|
const COPILOT_CONTEXT_CACHE_SYSTEM_MARKER_LIMIT = 2;
|
|
9686
9623
|
const COPILOT_CONTEXT_CACHE_NON_SYSTEM_MARKER_LIMIT = 1;
|
|
9687
9624
|
const COPILOT_CONTEXT_CACHE_CONTROL = { type: "ephemeral" };
|
|
@@ -9964,11 +9901,9 @@ const parseAnthropicStreamEvent = (data) => {
|
|
|
9964
9901
|
return null;
|
|
9965
9902
|
}
|
|
9966
9903
|
};
|
|
9967
|
-
|
|
9968
|
-
//#region src/lib/subagent.ts
|
|
9904
|
+
// src/lib/subagent.ts
|
|
9969
9905
|
const subagentMarkerPrefix = "__SUBAGENT_MARKER__";
|
|
9970
|
-
|
|
9971
|
-
//#region src/routes/messages/subagent-marker.ts
|
|
9906
|
+
// src/routes/messages/subagent-marker.ts
|
|
9972
9907
|
const parseSubagentMarkerFromFirstUser = (payload) => {
|
|
9973
9908
|
const firstUserMessage = payload.messages.find((msg) => msg.role === "user" && Array.isArray(msg.content));
|
|
9974
9909
|
if (!firstUserMessage || !Array.isArray(firstUserMessage.content)) return null;
|
|
@@ -10010,8 +9945,7 @@ const parseSubagentMarkerFromSystemReminder = (text) => {
|
|
|
10010
9945
|
}
|
|
10011
9946
|
return null;
|
|
10012
9947
|
};
|
|
10013
|
-
|
|
10014
|
-
//#region src/routes/messages/handler.ts
|
|
9948
|
+
// src/routes/messages/handler.ts
|
|
10015
9949
|
const logger$11 = createHandlerLogger("messages-handler");
|
|
10016
9950
|
const messagesFlowHandlers = {
|
|
10017
9951
|
handleWithChatCompletions,
|
|
@@ -10124,8 +10058,7 @@ const shouldUseMessagesApi = (selectedModel) => {
|
|
|
10124
10058
|
if (!isMessagesApiEnabled()) return false;
|
|
10125
10059
|
return selectedModel?.supported_endpoints?.includes(MESSAGES_ENDPOINT$1) ?? false;
|
|
10126
10060
|
};
|
|
10127
|
-
|
|
10128
|
-
//#region src/routes/messages/route.ts
|
|
10061
|
+
// src/routes/messages/route.ts
|
|
10129
10062
|
const messageRoutes = new Hono();
|
|
10130
10063
|
messageRoutes.post("/", async (c) => {
|
|
10131
10064
|
try {
|
|
@@ -10141,8 +10074,7 @@ messageRoutes.post("/count_tokens", async (c) => {
|
|
|
10141
10074
|
return await forwardError(c, error);
|
|
10142
10075
|
}
|
|
10143
10076
|
});
|
|
10144
|
-
|
|
10145
|
-
//#region src/lib/model-display-name.ts
|
|
10077
|
+
// src/lib/model-display-name.ts
|
|
10146
10078
|
/** Keep upstream labels as the base and identify their gateway provider. */
|
|
10147
10079
|
function withModelDisplayName(model, provider) {
|
|
10148
10080
|
if (typeof model !== "object" || model === null || Array.isArray(model)) return model;
|
|
@@ -10157,8 +10089,7 @@ function withModelDisplayName(model, provider) {
|
|
|
10157
10089
|
display_name: displayName
|
|
10158
10090
|
};
|
|
10159
10091
|
}
|
|
10160
|
-
|
|
10161
|
-
//#region src/routes/models/model-discovery.ts
|
|
10092
|
+
// src/routes/models/model-discovery.ts
|
|
10162
10093
|
const logger$10 = createHandlerLogger("models-handler");
|
|
10163
10094
|
const EPOCH_ISO = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
10164
10095
|
function isRecord(value) {
|
|
@@ -10315,8 +10246,7 @@ function createModelListResponse(c, models) {
|
|
|
10315
10246
|
has_more: false
|
|
10316
10247
|
});
|
|
10317
10248
|
}
|
|
10318
|
-
|
|
10319
|
-
//#region src/routes/models/claude-models.ts
|
|
10249
|
+
// src/routes/models/claude-models.ts
|
|
10320
10250
|
async function handleClaudeModels(c) {
|
|
10321
10251
|
return createModelListResponse(c, (await getAgentModels(stripInternalRequestHeaders(c.req.raw.headers))).map((model) => ({
|
|
10322
10252
|
...model,
|
|
@@ -10389,8 +10319,7 @@ function serializeCodexModelCatalog(response, options) {
|
|
|
10389
10319
|
models: models.filter((model) => selected.has(model))
|
|
10390
10320
|
});
|
|
10391
10321
|
}
|
|
10392
|
-
|
|
10393
|
-
//#region src/routes/models/model-metadata.ts
|
|
10322
|
+
// src/routes/models/model-metadata.ts
|
|
10394
10323
|
function normalizeMetadata(fields) {
|
|
10395
10324
|
const contextWindow = firstPositiveInteger(fields?.contextWindow);
|
|
10396
10325
|
const maxOutputTokens = firstPositiveInteger(fields?.maxOutputTokens);
|
|
@@ -10436,8 +10365,7 @@ function getModelMetadata(provider, modelId, model, config) {
|
|
|
10436
10365
|
reasoningEfforts: metadata.reasoningEfforts ?? []
|
|
10437
10366
|
};
|
|
10438
10367
|
}
|
|
10439
|
-
|
|
10440
|
-
//#region src/routes/models/codex-model-candidates.ts
|
|
10368
|
+
// src/routes/models/codex-model-candidates.ts
|
|
10441
10369
|
const logger$9 = createHandlerLogger("models-handler");
|
|
10442
10370
|
const RESPONSES_ENDPOINTS = /* @__PURE__ */ new Set(["/responses", "ws:/responses"]);
|
|
10443
10371
|
const MESSAGES_ENDPOINT = "/v1/messages";
|
|
@@ -10551,8 +10479,7 @@ function selectDefaultReasoningEffort(efforts, configured) {
|
|
|
10551
10479
|
function positiveNumber(value, fallback) {
|
|
10552
10480
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
|
|
10553
10481
|
}
|
|
10554
|
-
|
|
10555
|
-
//#region src/routes/models/models.json
|
|
10482
|
+
// src/routes/models/models.json
|
|
10556
10483
|
var models = [
|
|
10557
10484
|
{
|
|
10558
10485
|
"slug": "gpt-6-astra",
|
|
@@ -12070,8 +11997,7 @@ var models = [
|
|
|
12070
11997
|
"supports_reasoning_summaries": true
|
|
12071
11998
|
}
|
|
12072
11999
|
];
|
|
12073
|
-
|
|
12074
|
-
//#region src/routes/models/codex-models.ts
|
|
12000
|
+
// src/routes/models/codex-models.ts
|
|
12075
12001
|
const logger$8 = createHandlerLogger("codex-models-handler");
|
|
12076
12002
|
const CODEX_USER_AGENT_PATTERN = /^codex/iu;
|
|
12077
12003
|
const DEFAULT_REASONING_EFFORTS = [
|
|
@@ -12318,13 +12244,11 @@ function isCodexModelsResponse(value) {
|
|
|
12318
12244
|
if (!isRecord(value) || !Array.isArray(value.models)) return false;
|
|
12319
12245
|
return value.models.every((model) => isRecord(model) && typeof model.slug === "string");
|
|
12320
12246
|
}
|
|
12321
|
-
|
|
12322
|
-
//#region src/routes/models/default-models.ts
|
|
12247
|
+
// src/routes/models/default-models.ts
|
|
12323
12248
|
async function handleDefaultModels(c) {
|
|
12324
12249
|
return createModelListResponse(c, await (c.req.header("user-agent")?.toLowerCase().startsWith("deepseek") ? getAgentModels : getAggregatedModels)(stripInternalRequestHeaders(c.req.raw.headers)));
|
|
12325
12250
|
}
|
|
12326
|
-
|
|
12327
|
-
//#region src/routes/models/opencode-models.ts
|
|
12251
|
+
// src/routes/models/opencode-models.ts
|
|
12328
12252
|
const RESPONSES_PACKAGE = "@opencode/ai/providers/openai/responses";
|
|
12329
12253
|
const CNY_PER_USD = 6.7;
|
|
12330
12254
|
const COST_DECIMALS = 6;
|
|
@@ -12444,8 +12368,7 @@ async function handleOpencodeModels(c) {
|
|
|
12444
12368
|
c.header("Vary", "User-Agent");
|
|
12445
12369
|
return createModelListResponse(c, models.map((model) => toOpencodeModel(model, contextWindow)));
|
|
12446
12370
|
}
|
|
12447
|
-
|
|
12448
|
-
//#region src/routes/models/route.ts
|
|
12371
|
+
// src/routes/models/route.ts
|
|
12449
12372
|
const modelRoutes = new Hono();
|
|
12450
12373
|
modelRoutes.get("/", async (c) => {
|
|
12451
12374
|
try {
|
|
@@ -12458,8 +12381,7 @@ modelRoutes.get("/", async (c) => {
|
|
|
12458
12381
|
return await forwardError(c, error);
|
|
12459
12382
|
}
|
|
12460
12383
|
});
|
|
12461
|
-
|
|
12462
|
-
//#region src/routes/provider/alpha-search/route.ts
|
|
12384
|
+
// src/routes/provider/alpha-search/route.ts
|
|
12463
12385
|
const logger$7 = createHandlerLogger("provider-alpha-search-handler");
|
|
12464
12386
|
const providerAlphaSearchRoutes = new Hono();
|
|
12465
12387
|
const providerAlphaSearchRouteDependencies = {
|
|
@@ -12496,8 +12418,7 @@ providerAlphaSearchRoutes.post("/", async (c) => {
|
|
|
12496
12418
|
return await forwardError(c, error);
|
|
12497
12419
|
}
|
|
12498
12420
|
});
|
|
12499
|
-
|
|
12500
|
-
//#region src/routes/provider/images/route.ts
|
|
12421
|
+
// src/routes/provider/images/route.ts
|
|
12501
12422
|
const logger$6 = createHandlerLogger("provider-images-handler");
|
|
12502
12423
|
const providerImageRoutes = new Hono();
|
|
12503
12424
|
async function handleProviderImages(c, operation) {
|
|
@@ -12529,8 +12450,7 @@ async function handleProviderImages(c, operation) {
|
|
|
12529
12450
|
}
|
|
12530
12451
|
providerImageRoutes.post("/generations", (c) => handleProviderImages(c, "generations"));
|
|
12531
12452
|
providerImageRoutes.post("/edits", (c) => handleProviderImages(c, "edits"));
|
|
12532
|
-
|
|
12533
|
-
//#region src/routes/provider/messages/route.ts
|
|
12453
|
+
// src/routes/provider/messages/route.ts
|
|
12534
12454
|
const providerMessageRoutes = new Hono();
|
|
12535
12455
|
providerMessageRoutes.post("/", async (c) => {
|
|
12536
12456
|
try {
|
|
@@ -12546,8 +12466,7 @@ providerMessageRoutes.post("/count_tokens", async (c) => {
|
|
|
12546
12466
|
return await forwardError(c, error);
|
|
12547
12467
|
}
|
|
12548
12468
|
});
|
|
12549
|
-
|
|
12550
|
-
//#region src/routes/provider/models/route.ts
|
|
12469
|
+
// src/routes/provider/models/route.ts
|
|
12551
12470
|
const logger$5 = createHandlerLogger("provider-models-handler");
|
|
12552
12471
|
const providerModelRoutes = new Hono();
|
|
12553
12472
|
providerModelRoutes.get("/", async (c) => {
|
|
@@ -12610,8 +12529,7 @@ providerModelRoutes.get("/", async (c) => {
|
|
|
12610
12529
|
return await forwardError(c, error);
|
|
12611
12530
|
}
|
|
12612
12531
|
});
|
|
12613
|
-
|
|
12614
|
-
//#region src/lib/zstd-request.ts
|
|
12532
|
+
// src/lib/zstd-request.ts
|
|
12615
12533
|
const ZSTD_CONTENT_ENCODING = "zstd";
|
|
12616
12534
|
const INVALID_BODY_STATUS = 400;
|
|
12617
12535
|
let nodeZlibPromise = null;
|
|
@@ -12663,8 +12581,7 @@ const toUint8Array = (data) => {
|
|
|
12663
12581
|
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
12664
12582
|
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
12665
12583
|
};
|
|
12666
|
-
|
|
12667
|
-
//#region src/routes/responses/custom-tool-input-stream-decoder.ts
|
|
12584
|
+
// src/routes/responses/custom-tool-input-stream-decoder.ts
|
|
12668
12585
|
const CUSTOM_TOOL_INPUT_PREFIX_TOKENS = [
|
|
12669
12586
|
"{",
|
|
12670
12587
|
"\"input\"",
|
|
@@ -12820,8 +12737,7 @@ var CustomToolInputStreamDecoder = class {
|
|
|
12820
12737
|
function isJsonWhitespace(char) {
|
|
12821
12738
|
return char === " " || char === " " || char === "\r" || char === "\n";
|
|
12822
12739
|
}
|
|
12823
|
-
|
|
12824
|
-
//#region src/routes/responses/messages-stream-translation.ts
|
|
12740
|
+
// src/routes/responses/messages-stream-translation.ts
|
|
12825
12741
|
const EMPTY_SIGNATURE_ENCRYPTED_CONTENT = "";
|
|
12826
12742
|
async function* translateMessagesStream(chunks, context) {
|
|
12827
12743
|
const state = createTranslationState(context);
|
|
@@ -13474,8 +13390,7 @@ function parseAnthropicEvent(data) {
|
|
|
13474
13390
|
} catch {}
|
|
13475
13391
|
throw new ResponsesMessagesTranslationError("Messages API returned malformed streaming JSON", 502);
|
|
13476
13392
|
}
|
|
13477
|
-
|
|
13478
|
-
//#region src/routes/responses/messages-handler.ts
|
|
13393
|
+
// src/routes/responses/messages-handler.ts
|
|
13479
13394
|
const logger$4 = createHandlerLogger("responses-messages-handler");
|
|
13480
13395
|
const responsesMessagesDependencies = { handleCompletionPayload };
|
|
13481
13396
|
async function handleResponsesViaMessages(c, options) {
|
|
@@ -13544,8 +13459,7 @@ function streamTranslatedMessagesEvents(c, response, context) {
|
|
|
13544
13459
|
function isAnthropicResponse(value) {
|
|
13545
13460
|
return typeof value === "object" && value !== null && "type" in value && value.type === "message" && "content" in value && Array.isArray(value.content);
|
|
13546
13461
|
}
|
|
13547
|
-
|
|
13548
|
-
//#region src/routes/responses/task-title.ts
|
|
13462
|
+
// src/routes/responses/task-title.ts
|
|
13549
13463
|
const TASK_TITLE_PROMPT_PREFIX = "Generate a concise, single-line task title of at most 36 characters and under five words where possible.";
|
|
13550
13464
|
const taskTitleDependencies = { getSmallModelForProvider };
|
|
13551
13465
|
const getCodexTaskTitleModel = (userAgent, input, provider) => {
|
|
@@ -13558,8 +13472,7 @@ const getCodexTaskTitleModel = (userAgent, input, provider) => {
|
|
|
13558
13472
|
if (model) consola.debug(`Codex task title small model: ${provider} -> ${model}`);
|
|
13559
13473
|
return model;
|
|
13560
13474
|
};
|
|
13561
|
-
|
|
13562
|
-
//#region src/routes/provider/responses/handler.ts
|
|
13475
|
+
// src/routes/provider/responses/handler.ts
|
|
13563
13476
|
const logger$3 = createHandlerLogger("provider-responses-handler");
|
|
13564
13477
|
const providerResponsesHandlerDependencies = { resolveProviderConfig };
|
|
13565
13478
|
async function handleProviderResponsesForProvider(c, options) {
|
|
@@ -13724,8 +13637,7 @@ const getResponsesStreamEventUsage = (event) => {
|
|
|
13724
13637
|
return null;
|
|
13725
13638
|
};
|
|
13726
13639
|
const getResponsesEvents = (response) => createResponsesSafeStream(createResponsesHttpEventStream(response));
|
|
13727
|
-
|
|
13728
|
-
//#region src/routes/provider/responses/route.ts
|
|
13640
|
+
// src/routes/provider/responses/route.ts
|
|
13729
13641
|
const providerResponsesRoutes = new Hono();
|
|
13730
13642
|
providerResponsesRoutes.use(zstdDecompressionMiddleware);
|
|
13731
13643
|
providerResponsesRoutes.post("/", async (c) => {
|
|
@@ -13741,8 +13653,7 @@ providerResponsesRoutes.post("/", async (c) => {
|
|
|
13741
13653
|
return await forwardError(c, error);
|
|
13742
13654
|
}
|
|
13743
13655
|
});
|
|
13744
|
-
|
|
13745
|
-
//#region src/routes/responses/stream-id-sync.ts
|
|
13656
|
+
// src/routes/responses/stream-id-sync.ts
|
|
13746
13657
|
const createStreamIdTracker = () => ({ outputItems: /* @__PURE__ */ new Map() });
|
|
13747
13658
|
const fixStreamIds = (data, event, tracker) => {
|
|
13748
13659
|
if (!data) return data;
|
|
@@ -13777,8 +13688,7 @@ const handleItemId = (parsed, tracker) => {
|
|
|
13777
13688
|
}
|
|
13778
13689
|
return JSON.stringify(parsed);
|
|
13779
13690
|
};
|
|
13780
|
-
|
|
13781
|
-
//#region src/routes/responses/handler.ts
|
|
13691
|
+
// src/routes/responses/handler.ts
|
|
13782
13692
|
const logger$2 = createHandlerLogger("responses-handler");
|
|
13783
13693
|
const responsesHandlerDependencies = {
|
|
13784
13694
|
createResponses,
|
|
@@ -13986,8 +13896,7 @@ const getCodexResponsesSubagentMarker = (c, session) => {
|
|
|
13986
13896
|
const getTrimmedHeader = (c, name) => {
|
|
13987
13897
|
return c.req.header(name)?.trim() || void 0;
|
|
13988
13898
|
};
|
|
13989
|
-
|
|
13990
|
-
//#region src/routes/responses/route.ts
|
|
13899
|
+
// src/routes/responses/route.ts
|
|
13991
13900
|
const responsesRoutes = new Hono();
|
|
13992
13901
|
responsesRoutes.use(zstdDecompressionMiddleware);
|
|
13993
13902
|
responsesRoutes.post("/", async (c) => {
|
|
@@ -13997,8 +13906,7 @@ responsesRoutes.post("/", async (c) => {
|
|
|
13997
13906
|
return await forwardError(c, error);
|
|
13998
13907
|
}
|
|
13999
13908
|
});
|
|
14000
|
-
|
|
14001
|
-
//#region src/routes/token-usage/route.ts
|
|
13909
|
+
// src/routes/token-usage/route.ts
|
|
14002
13910
|
const tokenUsageRoute = new Hono();
|
|
14003
13911
|
const periods = /* @__PURE__ */ new Set([
|
|
14004
13912
|
"today",
|
|
@@ -14039,8 +13947,7 @@ function parsePageQuery(c) {
|
|
|
14039
13947
|
}
|
|
14040
13948
|
tokenUsageRoute.get("/events", async (c) => c.json(await getTokenUsageEventsPage(parsePageQuery(c))));
|
|
14041
13949
|
tokenUsageRoute.get("/sessions", async (c) => c.json(await getTokenUsageSessionsPage(parsePageQuery(c))));
|
|
14042
|
-
|
|
14043
|
-
//#region src/routes/usage/route.ts
|
|
13950
|
+
// src/routes/usage/route.ts
|
|
14044
13951
|
const usageRoute = new Hono();
|
|
14045
13952
|
usageRoute.get("/", async (c) => {
|
|
14046
13953
|
try {
|
|
@@ -14051,8 +13958,7 @@ usageRoute.get("/", async (c) => {
|
|
|
14051
13958
|
return c.json({ error: "Failed to fetch Copilot usage" }, 500);
|
|
14052
13959
|
}
|
|
14053
13960
|
});
|
|
14054
|
-
|
|
14055
|
-
//#region src/services/xai/videos.ts
|
|
13961
|
+
// src/services/xai/videos.ts
|
|
14056
13962
|
var XaiVideosRequestError = class extends Error {
|
|
14057
13963
|
constructor(message) {
|
|
14058
13964
|
super(message);
|
|
@@ -14080,8 +13986,7 @@ async function forwardXaiVideos(providerConfig, request, videoRequest) {
|
|
|
14080
13986
|
streamInactivityTimeoutMs: transport.streamInactivityTimeoutMs
|
|
14081
13987
|
});
|
|
14082
13988
|
}
|
|
14083
|
-
|
|
14084
|
-
//#region src/routes/videos/route.ts
|
|
13989
|
+
// src/routes/videos/route.ts
|
|
14085
13990
|
const logger$1 = createHandlerLogger("videos-handler");
|
|
14086
13991
|
const SUPPORTED_VIDEO_MODEL = "grok-imagine-video-1.5";
|
|
14087
13992
|
const videoRouteDependencies = {
|
|
@@ -14135,8 +14040,7 @@ async function handleVideos(c, operation) {
|
|
|
14135
14040
|
}
|
|
14136
14041
|
videoRoutes.post("/generations", (c) => handleVideos(c, "generations"));
|
|
14137
14042
|
videoRoutes.get("/:request_id", (c) => handleVideos(c, "result"));
|
|
14138
|
-
|
|
14139
|
-
//#region src/server.ts
|
|
14043
|
+
// src/server.ts
|
|
14140
14044
|
function resolveSameOriginCorsOrigin(origin, context) {
|
|
14141
14045
|
if (!origin) return null;
|
|
14142
14046
|
try {
|
|
@@ -14203,7 +14107,6 @@ function createServer(options = {}) {
|
|
|
14203
14107
|
return server;
|
|
14204
14108
|
}
|
|
14205
14109
|
createServer();
|
|
14206
|
-
//#endregion
|
|
14207
14110
|
export { createServer };
|
|
14208
14111
|
|
|
14209
|
-
//# sourceMappingURL=server-
|
|
14112
|
+
//# sourceMappingURL=server-Jvc5DYJV.js.map
|