@jeffreycao/copilot-api 2.7.38 → 2.7.40
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-BVjOyO_F.js +1 -0
- package/dist/{auth-jHSWJs1b.js → auth-ByQjInU9.js} +9 -12
- package/dist/{auth-jHSWJs1b.js.map → auth-ByQjInU9.js.map} +1 -1
- package/dist/{config-BzhriV_y.js → config-BqSuE5h5.js} +7 -12
- package/dist/{config-BzhriV_y.js.map → config-BqSuE5h5.js.map} +1 -1
- 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-8IpywGxw.js → copilot-runtime-D6YjAamL.js} +11 -19
- package/dist/{copilot-runtime-8IpywGxw.js.map → copilot-runtime-D6YjAamL.js.map} +1 -1
- package/dist/{debug-q7d6HJLV.js → debug-RUUyusA_.js} +4 -5
- package/dist/{debug-q7d6HJLV.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-CEF4Sh-g.js → server-DhHL2SxL.js} +430 -205
- package/dist/{server-CEF4Sh-g.js.map → server-DhHL2SxL.js.map} +1 -1
- package/dist/{start-Bawh7LU_.js → start-CxJBWBbt.js} +13 -18
- package/dist/{start-Bawh7LU_.js.map → start-CxJBWBbt.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-XNKmjmqH.js → token-CNWvfwYi.js} +29 -46
- package/dist/{token-XNKmjmqH.js.map → token-CNWvfwYi.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/pages/index.html +304 -325
- package/dist/auth-i0XN57BZ.js +0 -2
- package/dist/mcp-server-CEfcUYiN.js +0 -2
|
@@ -1,14 +1,15 @@
|
|
|
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
|
|
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 buildCodexRequestHeaders, B as getXaiAccessToken, C as copilotHeaders, D as prepareForCompact, E as isOpencodeOauthApp, F as compactTextOnlyGuard, I as createAuthMiddleware, J as readGitHubTokenFromEnv, L as getConfiguredAdminApiKeys, M as compactMessageSections, O as prepareInteractionHeaders, P as compactSystemPromptStarts, Q as CODEX_API_BASE_URL, S as copilotBaseUrl, T as copilotWebSocketHeaders, U as readXaiCredentials, Y as XAI_API_BASE_URL, _ as isAsyncIterable, at as fetchUpstreamWithLifecycle, b as parseUserIdMetadata, ct as encodePoolKeyPart, d as generateRequestIdFromPayload, dt as createWebSocketUrl, et as forwardCodexResponses, f as getPromptCacheKey, g as getUUID, h as getSessionAffinityFromHeaders, it as setPluginRequestActualModel, j as compactAutoContinuePromptStarts, k as prepareMessageProxyHeaders, lt as getResponsesStreamTerminalDisposition, m as getRootSessionIdFromHeaders, n as invalidateCodexRuntime, nt as requestContext, ot as createResponsesHttpEventStream, p as getRootSessionId, pt as stripInternalRequestHeaders, q as readGitHubToken, rt as resolveTraceId$1, s as setupCodexToken, st as createResponsesSafeStream, tt as generateTraceId, u as stopCopilotRefreshLoop, ut as createPooledWebSocketStream, v as isNullish, x as getCopilotUsage, y as isResponsesStream } from "./token-CNWvfwYi.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-D6YjAamL.js";
|
|
7
7
|
import consola from "consola";
|
|
8
8
|
import { createHash, randomUUID } from "node:crypto";
|
|
9
9
|
import fs, { readFileSync } from "node:fs";
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import fs$1 from "node:fs/promises";
|
|
12
|
+
import os from "node:os";
|
|
12
13
|
import { fetch as fetch$1, getGlobalDispatcher } from "undici";
|
|
13
14
|
import { events } from "fetch-event-stream";
|
|
14
15
|
import { z } from "zod";
|
|
@@ -18,7 +19,7 @@ import { logger } from "hono/logger";
|
|
|
18
19
|
import util from "node:util";
|
|
19
20
|
import { streamSSE } from "hono/streaming";
|
|
20
21
|
import { decompress } from "fzstd";
|
|
21
|
-
|
|
22
|
+
// src/lib/trace.ts
|
|
22
23
|
const traceIdMiddleware = async (c, next) => {
|
|
23
24
|
const traceId = resolveTraceId$1(c.req.header("x-trace-id"));
|
|
24
25
|
c.header("x-trace-id", traceId);
|
|
@@ -34,8 +35,7 @@ const traceIdMiddleware = async (c, next) => {
|
|
|
34
35
|
await next();
|
|
35
36
|
});
|
|
36
37
|
};
|
|
37
|
-
|
|
38
|
-
//#region src/lib/sqlite.ts
|
|
38
|
+
// src/lib/sqlite.ts
|
|
39
39
|
const MINIMUM_NODE_SQLITE_VERSION = "22.13.0";
|
|
40
40
|
const isBunRuntime = () => Boolean(globalThis.Bun);
|
|
41
41
|
function parseNodeVersion(version) {
|
|
@@ -119,8 +119,7 @@ var SqliteDbStore = class {
|
|
|
119
119
|
return db;
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
-
|
|
123
|
-
//#region src/lib/token-usage/store.ts
|
|
122
|
+
// src/lib/token-usage/store.ts
|
|
124
123
|
const DB_PATH_ENV = "COPILOT_API_SQLITE_DB_PATH";
|
|
125
124
|
const DEFAULT_DB_FILENAME = "copilot-api.sqlite";
|
|
126
125
|
const COST_NANOS_PER_UNIT$1 = 1e9;
|
|
@@ -902,8 +901,7 @@ async function closeUsageStore() {
|
|
|
902
901
|
writeQueue = Promise.resolve();
|
|
903
902
|
}
|
|
904
903
|
registerProcessCleanup(closeUsageStore);
|
|
905
|
-
|
|
906
|
-
//#region src/lib/request-events.ts
|
|
904
|
+
// src/lib/request-events.ts
|
|
907
905
|
const TRACKED = /\/(chat\/completions|responses|messages|alpha\/search)$/;
|
|
908
906
|
function setPluginRequestModel(model) {
|
|
909
907
|
requestContext.getStore()?.pluginRequest?.setModel(model);
|
|
@@ -1035,8 +1033,7 @@ function requestEventsMiddleware(plugins, port) {
|
|
|
1035
1033
|
}
|
|
1036
1034
|
};
|
|
1037
1035
|
}
|
|
1038
|
-
|
|
1039
|
-
//#region src/lib/logger.ts
|
|
1036
|
+
// src/lib/logger.ts
|
|
1040
1037
|
const LOG_RETENTION_MS = 6048e5;
|
|
1041
1038
|
const CLEANUP_INTERVAL_MS = 864e5;
|
|
1042
1039
|
const LOG_DIR_ENV = "COPILOT_API_LOG_DIR";
|
|
@@ -1220,8 +1217,7 @@ const createHandlerLogger = (name) => {
|
|
|
1220
1217
|
} });
|
|
1221
1218
|
return instance;
|
|
1222
1219
|
};
|
|
1223
|
-
|
|
1224
|
-
//#region src/lib/models.ts
|
|
1220
|
+
// src/lib/models.ts
|
|
1225
1221
|
/**
|
|
1226
1222
|
* Converts a Copilot upstream model ID to a client-friendly ID that Claude Code
|
|
1227
1223
|
* and Claude Desktop recognize (dots in version replaced with hyphens).
|
|
@@ -1282,8 +1278,7 @@ const normalizeSdkModelId = (sdkModelId) => {
|
|
|
1282
1278
|
version: pattern5[1]
|
|
1283
1279
|
};
|
|
1284
1280
|
};
|
|
1285
|
-
|
|
1286
|
-
//#region src/lib/provider-model.ts
|
|
1281
|
+
// src/lib/provider-model.ts
|
|
1287
1282
|
const parseProviderModelAlias = (model) => {
|
|
1288
1283
|
const separatorIndex = model.indexOf("/");
|
|
1289
1284
|
if (separatorIndex <= 0 || separatorIndex === model.length - 1) return null;
|
|
@@ -1312,8 +1307,7 @@ const createFallbackModel = (modelId) => ({
|
|
|
1312
1307
|
vendor: "provider",
|
|
1313
1308
|
version: "unknown"
|
|
1314
1309
|
});
|
|
1315
|
-
|
|
1316
|
-
//#region src/lib/provider-resolver.ts
|
|
1310
|
+
// src/lib/provider-resolver.ts
|
|
1317
1311
|
const AZURE_OPENAI_SCOPE = "https://cognitiveservices.azure.com/.default";
|
|
1318
1312
|
let cachedAzureAccessTokenProvider = null;
|
|
1319
1313
|
/**
|
|
@@ -1392,8 +1386,7 @@ async function ensureConfiguredProviderModelAlias(alias, resolveConfig = resolve
|
|
|
1392
1386
|
async function resolveConfiguredProviderModelAlias(model, resolveConfig = resolveProviderConfig) {
|
|
1393
1387
|
return ensureConfiguredProviderModelAlias(parseProviderModelAlias(model), resolveConfig);
|
|
1394
1388
|
}
|
|
1395
|
-
|
|
1396
|
-
//#region src/lib/token-usage/pricing.ts
|
|
1389
|
+
// src/lib/token-usage/pricing.ts
|
|
1397
1390
|
const COST_NANOS_PER_UNIT = 1e9;
|
|
1398
1391
|
const COST_NANOS_PER_TOKEN_AT_ONE_PER_MILLION = 1e3;
|
|
1399
1392
|
const COPILOT_NANO_AIU_TO_COST_NANOS = COST_NANOS_PER_UNIT / 1e11;
|
|
@@ -1541,8 +1534,7 @@ function costNanosForTokens(tokens, pricePerMillionTokens) {
|
|
|
1541
1534
|
if (pricePerMillionTokens === null) return 0;
|
|
1542
1535
|
return Math.round(normalizeToken(tokens) * pricePerMillionTokens * COST_NANOS_PER_TOKEN_AT_ONE_PER_MILLION);
|
|
1543
1536
|
}
|
|
1544
|
-
|
|
1545
|
-
//#region src/lib/token-usage/index.ts
|
|
1537
|
+
// src/lib/token-usage/index.ts
|
|
1546
1538
|
const tokenUsageEventBus = new EventBus();
|
|
1547
1539
|
const USER_AGENT_MAX_LENGTH = 64;
|
|
1548
1540
|
function resolveTraceId(traceId) {
|
|
@@ -1679,8 +1671,7 @@ function mergeAnthropicUsage(current, next) {
|
|
|
1679
1671
|
function normalizeOptionalCost(value) {
|
|
1680
1672
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
1681
1673
|
}
|
|
1682
|
-
|
|
1683
|
-
//#region src/routes/alpha-search/alpha-search-types.ts
|
|
1674
|
+
// src/routes/alpha-search/alpha-search-types.ts
|
|
1684
1675
|
const unsignedInteger = z.number().int().nonnegative();
|
|
1685
1676
|
const passthroughRecord = z.record(z.string(), z.unknown());
|
|
1686
1677
|
const searchQuerySchema = z.object({
|
|
@@ -1813,8 +1804,7 @@ const alphaSearchRequestSchema = z.object({
|
|
|
1813
1804
|
settings: settingsSchema.optional(),
|
|
1814
1805
|
max_output_tokens: unsignedInteger.optional()
|
|
1815
1806
|
}).loose();
|
|
1816
|
-
|
|
1817
|
-
//#region src/routes/messages/web-search/backend.ts
|
|
1807
|
+
// src/routes/messages/web-search/backend.ts
|
|
1818
1808
|
/** Builds the Responses API web_search tool object from normalized config. */
|
|
1819
1809
|
const buildResponsesWebSearchTool = (config) => {
|
|
1820
1810
|
const tool = { type: "web_search" };
|
|
@@ -1891,8 +1881,7 @@ const extractWebSearchResult = (result) => {
|
|
|
1891
1881
|
queries
|
|
1892
1882
|
};
|
|
1893
1883
|
};
|
|
1894
|
-
|
|
1895
|
-
//#region src/lib/copilot-rate-limit.ts
|
|
1884
|
+
// src/lib/copilot-rate-limit.ts
|
|
1896
1885
|
const copilotRateLimitTypes = ["session", "weekly"];
|
|
1897
1886
|
const copilotRateLimitHeaders = {
|
|
1898
1887
|
session: "x-usage-ratelimit-session",
|
|
@@ -1964,8 +1953,7 @@ const isCopilotQuotaSnapshot = (value) => {
|
|
|
1964
1953
|
const record = value;
|
|
1965
1954
|
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
1955
|
};
|
|
1967
|
-
|
|
1968
|
-
//#region src/services/copilot/create-responses.ts
|
|
1956
|
+
// src/services/copilot/create-responses.ts
|
|
1969
1957
|
const createResponses = async (payload, { vision, initiator, subagentMarker, requestId, sessionId, compactType, transport = "http", clientSignal }) => {
|
|
1970
1958
|
if (!state.copilotToken) throw new Error("Copilot token not found");
|
|
1971
1959
|
const headers = {
|
|
@@ -2090,8 +2078,7 @@ const createResponsesWebSocketStreamChunk = (data) => {
|
|
|
2090
2078
|
return { data };
|
|
2091
2079
|
}
|
|
2092
2080
|
};
|
|
2093
|
-
|
|
2094
|
-
//#region src/lib/grok-build.ts
|
|
2081
|
+
// src/lib/grok-build.ts
|
|
2095
2082
|
const VERSION_URL = "https://x.ai/cli/stable";
|
|
2096
2083
|
const VERSION_CACHE_MS = 864e5;
|
|
2097
2084
|
const VERSION_RETRY_MS = 3e5;
|
|
@@ -2120,8 +2107,7 @@ async function getGrokBuildVersion() {
|
|
|
2120
2107
|
});
|
|
2121
2108
|
return await versionInFlight;
|
|
2122
2109
|
}
|
|
2123
|
-
|
|
2124
|
-
//#region src/lib/timeout-dispatcher.ts
|
|
2110
|
+
// src/lib/timeout-dispatcher.ts
|
|
2125
2111
|
/**
|
|
2126
2112
|
* Node's global fetch keeps Undici's shorter default headers/body timeouts.
|
|
2127
2113
|
* Wrap the global dispatcher so long-running requests (e.g. image
|
|
@@ -2134,8 +2120,7 @@ const createTimeoutDispatcher = (timeoutMs) => ({ dispatch(options, handler) {
|
|
|
2134
2120
|
headersTimeout: timeoutMs
|
|
2135
2121
|
}, handler);
|
|
2136
2122
|
} });
|
|
2137
|
-
|
|
2138
|
-
//#region src/services/providers/provider-proxy.ts
|
|
2123
|
+
// src/services/providers/provider-proxy.ts
|
|
2139
2124
|
const OPENCODE_GO_PROVIDER_NAME = "opencode-go";
|
|
2140
2125
|
const OPENCODE_SESSION_HEADER = "x-opencode-session";
|
|
2141
2126
|
const SHARED_FORWARDABLE_HEADERS = ["accept", "user-agent"];
|
|
@@ -2363,8 +2348,7 @@ async function forwardProviderImages(providerConfig, request, operation) {
|
|
|
2363
2348
|
dispatcher: providerImagesDispatcher
|
|
2364
2349
|
});
|
|
2365
2350
|
}
|
|
2366
|
-
|
|
2367
|
-
//#region src/routes/alpha-search/alpha-search-responses.ts
|
|
2351
|
+
// src/routes/alpha-search/alpha-search-responses.ts
|
|
2368
2352
|
const logger$19 = createHandlerLogger("alpha-search-responses-handler");
|
|
2369
2353
|
const SESSION_TTL_MS = 36e5;
|
|
2370
2354
|
const MAX_SESSIONS = 128;
|
|
@@ -2849,8 +2833,7 @@ async function handleAlphaSearchResponses(c, options) {
|
|
|
2849
2833
|
}
|
|
2850
2834
|
return c.json(buildAlphaSearchResponse(state));
|
|
2851
2835
|
}
|
|
2852
|
-
|
|
2853
|
-
//#region src/services/codex/alpha-search.ts
|
|
2836
|
+
// src/services/codex/alpha-search.ts
|
|
2854
2837
|
const CODEX_ALPHA_SEARCH_URL = `${CODEX_API_BASE_URL}/codex/alpha/search`;
|
|
2855
2838
|
function resolveCodexAlphaSearchUrl(requestUrl) {
|
|
2856
2839
|
const upstreamUrl = new URL(CODEX_ALPHA_SEARCH_URL);
|
|
@@ -2868,8 +2851,7 @@ async function forwardCodexAlphaSearch(request) {
|
|
|
2868
2851
|
body
|
|
2869
2852
|
});
|
|
2870
2853
|
}
|
|
2871
|
-
|
|
2872
|
-
//#region src/routes/alpha-search/route.ts
|
|
2854
|
+
// src/routes/alpha-search/route.ts
|
|
2873
2855
|
const logger$18 = createHandlerLogger("alpha-search-handler");
|
|
2874
2856
|
const alphaSearchRoutes = new Hono();
|
|
2875
2857
|
const alphaSearchRouteDependencies = {
|
|
@@ -3010,8 +2992,7 @@ alphaSearchRoutes.post("/", async (c) => {
|
|
|
3010
2992
|
return await forwardError(c, error);
|
|
3011
2993
|
}
|
|
3012
2994
|
});
|
|
3013
|
-
|
|
3014
|
-
//#region src/lib/first-token.ts
|
|
2995
|
+
// src/lib/first-token.ts
|
|
3015
2996
|
const nonempty = (value) => typeof value === "string" && value.length > 0;
|
|
3016
2997
|
function recordChatCompletionFirstToken(chunk) {
|
|
3017
2998
|
const observer = requestContext.getStore()?.requestTiming ?? requestContext.getStore()?.pluginRequest;
|
|
@@ -3050,8 +3031,7 @@ function recordGoogleFirstToken(response) {
|
|
|
3050
3031
|
if (!observer) return;
|
|
3051
3032
|
if (response.candidates?.some((candidate) => candidate.content?.parts.some((part) => part.thought === true || nonempty(part.text) || nonempty(part.functionCall?.name)))) observer.recordFirstToken();
|
|
3052
3033
|
}
|
|
3053
|
-
|
|
3054
|
-
//#region src/lib/sse.ts
|
|
3034
|
+
// src/lib/sse.ts
|
|
3055
3035
|
async function writeSSEIfConnected(stream, message) {
|
|
3056
3036
|
if (stream.aborted) return false;
|
|
3057
3037
|
try {
|
|
@@ -3062,8 +3042,7 @@ async function writeSSEIfConnected(stream, message) {
|
|
|
3062
3042
|
throw error;
|
|
3063
3043
|
}
|
|
3064
3044
|
}
|
|
3065
|
-
|
|
3066
|
-
//#region src/lib/dashscope.ts
|
|
3045
|
+
// src/lib/dashscope.ts
|
|
3067
3046
|
const OPENAI_COMPATIBLE_CONTEXT_CACHE_MARKER_LIMIT = 4;
|
|
3068
3047
|
const OPENAI_COMPATIBLE_CONTEXT_CACHE_CONTROL = { type: "ephemeral" };
|
|
3069
3048
|
const OPENAI_COMPATIBLE_CONTEXT_CACHE_ROLES = /* @__PURE__ */ new Set([
|
|
@@ -3113,8 +3092,7 @@ const applyContextCacheControl = (message) => {
|
|
|
3113
3092
|
const setContextCacheControl = (part) => {
|
|
3114
3093
|
part.cache_control = { ...OPENAI_COMPATIBLE_CONTEXT_CACHE_CONTROL };
|
|
3115
3094
|
};
|
|
3116
|
-
|
|
3117
|
-
//#region src/lib/reasoning-effort.ts
|
|
3095
|
+
// src/lib/reasoning-effort.ts
|
|
3118
3096
|
const REASONING_EFFORT_LEVELS = [
|
|
3119
3097
|
"none",
|
|
3120
3098
|
"minimal",
|
|
@@ -3160,8 +3138,7 @@ const resolveSupportedReasoningEffort = (requestedEffort, supportedEfforts) => {
|
|
|
3160
3138
|
if (nearestBelow) return nearestBelow;
|
|
3161
3139
|
return supported.reduce((lowest, effort) => reasoningEffortRank(effort) < reasoningEffortRank(lowest) ? effort : lowest);
|
|
3162
3140
|
};
|
|
3163
|
-
|
|
3164
|
-
//#region src/routes/provider/utils.ts
|
|
3141
|
+
// src/routes/provider/utils.ts
|
|
3165
3142
|
const forwardProviderResponseHeaders = (c, upstreamHeaders) => {
|
|
3166
3143
|
const headers = createProviderProxyResponseHeaders(upstreamHeaders);
|
|
3167
3144
|
headers.delete("set-cookie");
|
|
@@ -3191,8 +3168,7 @@ const normalizeProviderResponsesReasoningEffort = (payload, providerConfig) => {
|
|
|
3191
3168
|
to: resolvedEffort
|
|
3192
3169
|
};
|
|
3193
3170
|
};
|
|
3194
|
-
|
|
3195
|
-
//#region src/routes/provider/chat-completions/handler.ts
|
|
3171
|
+
// src/routes/provider/chat-completions/handler.ts
|
|
3196
3172
|
const logger$17 = createHandlerLogger("provider-chat-completions-handler");
|
|
3197
3173
|
async function handleProviderChatCompletionsForProvider(c, options) {
|
|
3198
3174
|
const { payload, provider } = options;
|
|
@@ -3278,8 +3254,7 @@ const parseChatCompletionChunkData = (data) => {
|
|
|
3278
3254
|
return null;
|
|
3279
3255
|
}
|
|
3280
3256
|
};
|
|
3281
|
-
|
|
3282
|
-
//#region src/services/copilot/create-chat-completions.ts
|
|
3257
|
+
// src/services/copilot/create-chat-completions.ts
|
|
3283
3258
|
const createChatCompletions = async (payload, options) => {
|
|
3284
3259
|
if (!state.copilotToken) throw new Error("Copilot token not found");
|
|
3285
3260
|
const enableVision = payload.messages.some((x) => typeof x.content !== "string" && x.content?.some((x) => x.type === "image_url"));
|
|
@@ -3314,8 +3289,7 @@ const createChatCompletions = async (payload, options) => {
|
|
|
3314
3289
|
if (payload.stream) return events(response);
|
|
3315
3290
|
return await response.json();
|
|
3316
3291
|
};
|
|
3317
|
-
|
|
3318
|
-
//#region src/routes/chat-completions/handler.ts
|
|
3292
|
+
// src/routes/chat-completions/handler.ts
|
|
3319
3293
|
const logger$16 = createHandlerLogger("chat-completions-handler");
|
|
3320
3294
|
async function handleCompletion$1(c) {
|
|
3321
3295
|
let payload = await c.req.json();
|
|
@@ -3393,8 +3367,7 @@ const parseChatCompletionChunk = (chunk) => {
|
|
|
3393
3367
|
return null;
|
|
3394
3368
|
}
|
|
3395
3369
|
};
|
|
3396
|
-
|
|
3397
|
-
//#region src/routes/chat-completions/route.ts
|
|
3370
|
+
// src/routes/chat-completions/route.ts
|
|
3398
3371
|
const completionRoutes = new Hono();
|
|
3399
3372
|
completionRoutes.post("/", async (c) => {
|
|
3400
3373
|
try {
|
|
@@ -3403,8 +3376,7 @@ completionRoutes.post("/", async (c) => {
|
|
|
3403
3376
|
return await forwardError(c, error);
|
|
3404
3377
|
}
|
|
3405
3378
|
});
|
|
3406
|
-
|
|
3407
|
-
//#region src/lib/config-reload.ts
|
|
3379
|
+
// src/lib/config-reload.ts
|
|
3408
3380
|
let pendingReload = Promise.resolve();
|
|
3409
3381
|
async function applyConfigReload() {
|
|
3410
3382
|
const previousConfig = getConfig();
|
|
@@ -3449,8 +3421,7 @@ function reloadServerConfig() {
|
|
|
3449
3421
|
pendingReload = reload.catch(() => {});
|
|
3450
3422
|
return reload;
|
|
3451
3423
|
}
|
|
3452
|
-
|
|
3453
|
-
//#region src/routes/admin/config/route.ts
|
|
3424
|
+
// src/routes/admin/config/route.ts
|
|
3454
3425
|
const configRoutes = new Hono();
|
|
3455
3426
|
const modelMappingsRequestSchema = z.object({ modelMappings: z.record(z.string(), z.string()) });
|
|
3456
3427
|
configRoutes.post("/reload", async (c) => {
|
|
@@ -3486,8 +3457,7 @@ configRoutes.post("/model-mappings", async (c) => {
|
|
|
3486
3457
|
return await forwardError(c, error);
|
|
3487
3458
|
}
|
|
3488
3459
|
});
|
|
3489
|
-
|
|
3490
|
-
//#region src/services/copilot/create-embeddings.ts
|
|
3460
|
+
// src/services/copilot/create-embeddings.ts
|
|
3491
3461
|
const createEmbeddings = async (payload) => {
|
|
3492
3462
|
if (!state.copilotToken) throw new Error("Copilot token not found");
|
|
3493
3463
|
const response = await fetch(`${copilotBaseUrl(state)}/embeddings`, {
|
|
@@ -3498,8 +3468,7 @@ const createEmbeddings = async (payload) => {
|
|
|
3498
3468
|
if (!response.ok) throw new HTTPError("Failed to create embeddings", response);
|
|
3499
3469
|
return await response.json();
|
|
3500
3470
|
};
|
|
3501
|
-
|
|
3502
|
-
//#region src/routes/embeddings/route.ts
|
|
3471
|
+
// src/routes/embeddings/route.ts
|
|
3503
3472
|
const embeddingRoutes = new Hono();
|
|
3504
3473
|
embeddingRoutes.post("/", async (c) => {
|
|
3505
3474
|
try {
|
|
@@ -3517,8 +3486,7 @@ embeddingRoutes.post("/", async (c) => {
|
|
|
3517
3486
|
return await forwardError(c, error);
|
|
3518
3487
|
}
|
|
3519
3488
|
});
|
|
3520
|
-
|
|
3521
|
-
//#region src/lib/xai-image-model.ts
|
|
3489
|
+
// src/lib/xai-image-model.ts
|
|
3522
3490
|
/**
|
|
3523
3491
|
* Resolves one image-route model setting. Empty values keep the OpenAI
|
|
3524
3492
|
* protocol. Only an xai/model alias selects the xAI Imagine API.
|
|
@@ -3547,8 +3515,7 @@ function getImageGenerationModel() {
|
|
|
3547
3515
|
function getImageEditModel() {
|
|
3548
3516
|
return resolveConfiguredXaiImageModel(getConfig().imageEditModel, "imageEditModel");
|
|
3549
3517
|
}
|
|
3550
|
-
|
|
3551
|
-
//#region src/routes/images/forward-provider-images.ts
|
|
3518
|
+
// src/routes/images/forward-provider-images.ts
|
|
3552
3519
|
/**
|
|
3553
3520
|
* Forwards an images request to a configured provider with debug logging.
|
|
3554
3521
|
* Shared by the top-level images routes (model mapping) and the
|
|
@@ -3573,8 +3540,7 @@ async function forwardProviderImagesWithLogging(providerConfig, request, operati
|
|
|
3573
3540
|
});
|
|
3574
3541
|
return createProviderProxyResponse(upstreamResponse);
|
|
3575
3542
|
}
|
|
3576
|
-
|
|
3577
|
-
//#region src/services/codex/images.ts
|
|
3543
|
+
// src/services/codex/images.ts
|
|
3578
3544
|
const CODEX_IMAGES_TIMEOUT_MS = 9e5;
|
|
3579
3545
|
const codexImagesDispatcher = createTimeoutDispatcher(CODEX_IMAGES_TIMEOUT_MS);
|
|
3580
3546
|
function resolveCodexImagesUrl(requestUrl, operation) {
|
|
@@ -3600,8 +3566,7 @@ async function forwardCodexImages(request, operation) {
|
|
|
3600
3566
|
dispatcher: codexImagesDispatcher
|
|
3601
3567
|
});
|
|
3602
3568
|
}
|
|
3603
|
-
|
|
3604
|
-
//#region src/routes/images/shared.ts
|
|
3569
|
+
// src/routes/images/shared.ts
|
|
3605
3570
|
const logger$15 = createHandlerLogger("images-handler");
|
|
3606
3571
|
const imageRouteDependencies = {
|
|
3607
3572
|
debugJsonAsync,
|
|
@@ -3725,8 +3690,7 @@ async function routeImagesRequest(c, operation, parsed) {
|
|
|
3725
3690
|
if (parsed.originalRequest && mappedModel === requestedModel) return await handleCodexImages(c, operation, void 0, parsed.originalRequest);
|
|
3726
3691
|
return await handleCodexImages(c, operation, void 0, parsed.createRequest(mappedModel));
|
|
3727
3692
|
}
|
|
3728
|
-
|
|
3729
|
-
//#region src/services/xai/images.ts
|
|
3693
|
+
// src/services/xai/images.ts
|
|
3730
3694
|
const XAI_ASPECT_RATIOS = [
|
|
3731
3695
|
{
|
|
3732
3696
|
label: "1:1",
|
|
@@ -4111,8 +4075,7 @@ async function ensureImageResponseB64Json(response, fetchImage = globalThis.fetc
|
|
|
4111
4075
|
data
|
|
4112
4076
|
}));
|
|
4113
4077
|
}
|
|
4114
|
-
|
|
4115
|
-
//#region src/routes/images/xai-handler.ts
|
|
4078
|
+
// src/routes/images/xai-handler.ts
|
|
4116
4079
|
function xaiImagesRequestErrorResponse(c, error) {
|
|
4117
4080
|
if (!(error instanceof XaiImagesRequestError)) return null;
|
|
4118
4081
|
return c.json({ error: {
|
|
@@ -4165,8 +4128,7 @@ async function handleXaiImageGeneration(c, model) {
|
|
|
4165
4128
|
async function handleXaiImageEdit(c, model) {
|
|
4166
4129
|
return await forwardTranslatedXaiImages(c, "edits", translateXaiImageEditJson(await readJsonBody(c.req.raw, "Image edit body must be JSON"), model));
|
|
4167
4130
|
}
|
|
4168
|
-
|
|
4169
|
-
//#region src/routes/images/edits-handler.ts
|
|
4131
|
+
// src/routes/images/edits-handler.ts
|
|
4170
4132
|
async function handleImagesEdits(c) {
|
|
4171
4133
|
try {
|
|
4172
4134
|
const configuredModel = imageRouteDependencies.getImageEditModel();
|
|
@@ -4187,8 +4149,7 @@ async function handleImagesEdits(c) {
|
|
|
4187
4149
|
return await forwardError(c, error);
|
|
4188
4150
|
}
|
|
4189
4151
|
}
|
|
4190
|
-
|
|
4191
|
-
//#region src/routes/images/generations-handler.ts
|
|
4152
|
+
// src/routes/images/generations-handler.ts
|
|
4192
4153
|
async function handleImagesGenerations(c) {
|
|
4193
4154
|
try {
|
|
4194
4155
|
const configuredModel = imageRouteDependencies.getImageGenerationModel();
|
|
@@ -4207,13 +4168,11 @@ async function handleImagesGenerations(c) {
|
|
|
4207
4168
|
return await forwardError(c, error);
|
|
4208
4169
|
}
|
|
4209
4170
|
}
|
|
4210
|
-
|
|
4211
|
-
//#region src/routes/images/route.ts
|
|
4171
|
+
// src/routes/images/route.ts
|
|
4212
4172
|
const imageRoutes = new Hono();
|
|
4213
4173
|
imageRoutes.post("/generations", handleImagesGenerations);
|
|
4214
4174
|
imageRoutes.post("/edits", handleImagesEdits);
|
|
4215
|
-
|
|
4216
|
-
//#region src/lib/model-pdf-support.ts
|
|
4175
|
+
// src/lib/model-pdf-support.ts
|
|
4217
4176
|
function resolveModelPdfSupport(provider, options) {
|
|
4218
4177
|
if (options.supportPdf !== void 0) return options.supportPdf;
|
|
4219
4178
|
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 +4190,7 @@ function getProviderModelPdfSupport(modelId, provider, selectedModel) {
|
|
|
4231
4190
|
builtinSupportPdf: builtin?.supportPdf ?? builtinProviderModelRegistry.getProviderDefaults(provider.name)?.supportPdf
|
|
4232
4191
|
});
|
|
4233
4192
|
}
|
|
4234
|
-
|
|
4235
|
-
//#region src/lib/claude-models.ts
|
|
4193
|
+
// src/lib/claude-models.ts
|
|
4236
4194
|
const DISCOVERY_MODEL_PREFIX = "my-claude-";
|
|
4237
4195
|
const DISCOVERY_MODEL_SUFFIX = "[1m]";
|
|
4238
4196
|
function isClaudeUserAgent(userAgent) {
|
|
@@ -4258,8 +4216,7 @@ function fromClaudeDiscoveryModelId(modelId) {
|
|
|
4258
4216
|
function stripDiscoveryModelSuffix(modelId) {
|
|
4259
4217
|
return modelId.endsWith(DISCOVERY_MODEL_SUFFIX) ? modelId.slice(0, -4) : modelId;
|
|
4260
4218
|
}
|
|
4261
|
-
|
|
4262
|
-
//#region src/lib/tokenizer.ts
|
|
4219
|
+
// src/lib/tokenizer.ts
|
|
4263
4220
|
const ENCODING_MAP = {
|
|
4264
4221
|
o200k_base: () => import("gpt-tokenizer/encoding/o200k_base"),
|
|
4265
4222
|
cl100k_base: () => import("gpt-tokenizer/encoding/cl100k_base"),
|
|
@@ -4476,8 +4433,7 @@ const getTokenCount = async (payload, model) => {
|
|
|
4476
4433
|
output: outputTokens
|
|
4477
4434
|
};
|
|
4478
4435
|
};
|
|
4479
|
-
|
|
4480
|
-
//#region src/routes/messages/utils.ts
|
|
4436
|
+
// src/routes/messages/utils.ts
|
|
4481
4437
|
function mapOpenAIStopReasonToAnthropic(finishReason) {
|
|
4482
4438
|
if (finishReason === null) return null;
|
|
4483
4439
|
return {
|
|
@@ -5303,8 +5259,7 @@ const prepareMessagesApiPayload = (payload, selectedModel) => {
|
|
|
5303
5259
|
}
|
|
5304
5260
|
}
|
|
5305
5261
|
};
|
|
5306
|
-
|
|
5307
|
-
//#region src/routes/provider/messages/count-tokens-handler.ts
|
|
5262
|
+
// src/routes/provider/messages/count-tokens-handler.ts
|
|
5308
5263
|
const logger$14 = createHandlerLogger("provider-count-tokens-handler");
|
|
5309
5264
|
async function handleProviderCountTokens(c) {
|
|
5310
5265
|
const provider = c.req.param("provider");
|
|
@@ -5340,8 +5295,7 @@ async function handleProviderCountTokensForProvider(c, options) {
|
|
|
5340
5295
|
});
|
|
5341
5296
|
return c.json({ input_tokens: finalTokenCount });
|
|
5342
5297
|
}
|
|
5343
|
-
|
|
5344
|
-
//#region src/routes/messages/count-tokens-handler.ts
|
|
5298
|
+
// src/routes/messages/count-tokens-handler.ts
|
|
5345
5299
|
const resolveCountTokensModel = (modelId, findModel = findEndpointModel) => {
|
|
5346
5300
|
const selectedModel = findModel(modelId);
|
|
5347
5301
|
if (selectedModel) return {
|
|
@@ -5431,8 +5385,7 @@ async function handleCountTokens(c) {
|
|
|
5431
5385
|
consola.info("Token count:", finalTokenCount);
|
|
5432
5386
|
return c.json({ input_tokens: finalTokenCount });
|
|
5433
5387
|
}
|
|
5434
|
-
|
|
5435
|
-
//#region src/lib/codex-rate-limit.ts
|
|
5388
|
+
// src/lib/codex-rate-limit.ts
|
|
5436
5389
|
const codexRateLimitScopes = ["primary", "secondary"];
|
|
5437
5390
|
const formatCodexRateLimitResetAt = (resetAt) => {
|
|
5438
5391
|
const date = /* @__PURE__ */ new Date(resetAt * 1e3);
|
|
@@ -5464,8 +5417,7 @@ const isCodexRateLimitWindow = (value) => {
|
|
|
5464
5417
|
const record = value;
|
|
5465
5418
|
return typeof record.reset_after_seconds === "number" && typeof record.reset_at === "number" && typeof record.used_percent === "number" && typeof record.window_minutes === "number";
|
|
5466
5419
|
};
|
|
5467
|
-
|
|
5468
|
-
//#region src/routes/messages/completions-stream-translation.ts
|
|
5420
|
+
// src/routes/messages/completions-stream-translation.ts
|
|
5469
5421
|
function isToolBlockOpen(state) {
|
|
5470
5422
|
if (!state.contentBlockOpen) return false;
|
|
5471
5423
|
return Object.values(state.toolCalls).some((tc) => tc.anthropicBlockIndex === state.contentBlockIndex);
|
|
@@ -5783,8 +5735,7 @@ function translateErrorToAnthropicErrorEvent() {
|
|
|
5783
5735
|
}
|
|
5784
5736
|
};
|
|
5785
5737
|
}
|
|
5786
|
-
|
|
5787
|
-
//#region src/routes/messages/responses-translation.ts
|
|
5738
|
+
// src/routes/messages/responses-translation.ts
|
|
5788
5739
|
const MESSAGE_TYPE = "message";
|
|
5789
5740
|
const COMPACTION_SIGNATURE_PREFIX = "cm1#";
|
|
5790
5741
|
const COMPACTION_SIGNATURE_SEPARATOR = "@";
|
|
@@ -6391,8 +6342,7 @@ const isSupportAllTurns = (payload) => {
|
|
|
6391
6342
|
if (payload.model === "gpt-5.4" || payload.model === "gpt-5.4-mini" || payload.model === "gpt-5.5") return true;
|
|
6392
6343
|
return isGpt56OrAbove(payload.model);
|
|
6393
6344
|
};
|
|
6394
|
-
|
|
6395
|
-
//#region src/routes/messages/responses-stream-translation.ts
|
|
6345
|
+
// src/routes/messages/responses-stream-translation.ts
|
|
6396
6346
|
const MAX_CONSECUTIVE_FUNCTION_CALL_WHITESPACE = 20;
|
|
6397
6347
|
var FunctionCallArgumentsValidationError = class extends Error {
|
|
6398
6348
|
constructor(message) {
|
|
@@ -6864,8 +6814,7 @@ const stringifyToolSearchArguments = (argumentsValue) => {
|
|
|
6864
6814
|
return;
|
|
6865
6815
|
}
|
|
6866
6816
|
};
|
|
6867
|
-
|
|
6868
|
-
//#region src/routes/messages/responses-stream-collection.ts
|
|
6817
|
+
// src/routes/messages/responses-stream-collection.ts
|
|
6869
6818
|
const collectResponsesStreamResult = async ({ errorMessagePrefix = "Responses stream", parseEvent = parseResponsesStreamEvent$1, upstreamResponse, logger }) => {
|
|
6870
6819
|
const state = createResponsesStreamCollection();
|
|
6871
6820
|
for await (const chunk of upstreamResponse) {
|
|
@@ -6920,8 +6869,7 @@ const collectResponsesStreamEvent = (event, state) => {
|
|
|
6920
6869
|
const getStreamErrorMessage = (event) => {
|
|
6921
6870
|
return event.error?.message ?? event.message ?? void 0;
|
|
6922
6871
|
};
|
|
6923
|
-
|
|
6924
|
-
//#region src/routes/responses/messages-translation.ts
|
|
6872
|
+
// src/routes/responses/messages-translation.ts
|
|
6925
6873
|
const MESSAGES_COMPACTION_PREFIX = "copilot-api:messages-compaction:v1:";
|
|
6926
6874
|
const MESSAGES_REASONING_ID_SUFFIX = "__a1";
|
|
6927
6875
|
const markMessagesReasoningId = (id) => `${id}${MESSAGES_REASONING_ID_SUFFIX}`;
|
|
@@ -7931,8 +7879,7 @@ const containsVisionContent = (value) => {
|
|
|
7931
7879
|
if (Array.isArray(record.content)) return record.content.some((entry) => containsVisionContent(entry));
|
|
7932
7880
|
return false;
|
|
7933
7881
|
};
|
|
7934
|
-
|
|
7935
|
-
//#region src/routes/messages/web-search/fulfill.ts
|
|
7882
|
+
// src/routes/messages/web-search/fulfill.ts
|
|
7936
7883
|
const webSearchFlowDependencies = {
|
|
7937
7884
|
createResponses,
|
|
7938
7885
|
getMessageApiWebSearchModel,
|
|
@@ -8225,8 +8172,7 @@ const buildSyntheticStreamEvents = (response) => {
|
|
|
8225
8172
|
}, { type: "message_stop" });
|
|
8226
8173
|
return events;
|
|
8227
8174
|
};
|
|
8228
|
-
|
|
8229
|
-
//#region src/services/codex/get-models.ts
|
|
8175
|
+
// src/services/codex/get-models.ts
|
|
8230
8176
|
const CODEX_MODELS = [
|
|
8231
8177
|
{
|
|
8232
8178
|
contextWindow: 872e3,
|
|
@@ -8401,8 +8347,7 @@ function getModels() {
|
|
|
8401
8347
|
data: CODEX_MODELS.map((model) => normalizeCodexModel(model))
|
|
8402
8348
|
};
|
|
8403
8349
|
}
|
|
8404
|
-
|
|
8405
|
-
//#region src/routes/messages/google-thinking.ts
|
|
8350
|
+
// src/routes/messages/google-thinking.ts
|
|
8406
8351
|
function supportsThinkingControls(modelId) {
|
|
8407
8352
|
const model = modelId.replace(/^models\//u, "").toLowerCase();
|
|
8408
8353
|
if (/(?:^|-)(?:tts|live|image)(?:-|$)/u.test(model)) return false;
|
|
@@ -8427,8 +8372,7 @@ function translateGoogleThinking(payload) {
|
|
|
8427
8372
|
if (effort) config.thinkingLevel = effort === "low" ? "LOW" : effort === "medium" ? "MEDIUM" : "HIGH";
|
|
8428
8373
|
return config;
|
|
8429
8374
|
}
|
|
8430
|
-
|
|
8431
|
-
//#region src/routes/messages/google-translation.ts
|
|
8375
|
+
// src/routes/messages/google-translation.ts
|
|
8432
8376
|
const GOOGLE_SIGNATURE_PREFIX = "google:";
|
|
8433
8377
|
function encodeGoogleSignature(signature, target) {
|
|
8434
8378
|
return GOOGLE_SIGNATURE_PREFIX + Buffer.from(JSON.stringify({
|
|
@@ -8658,8 +8602,7 @@ function translateGoogleToAnthropic(response, model) {
|
|
|
8658
8602
|
usage: translateGoogleUsage(response.usageMetadata)
|
|
8659
8603
|
};
|
|
8660
8604
|
}
|
|
8661
|
-
|
|
8662
|
-
//#region src/routes/messages/google-stream-translation.ts
|
|
8605
|
+
// src/routes/messages/google-stream-translation.ts
|
|
8663
8606
|
var GoogleMessagesStreamTranslator = class {
|
|
8664
8607
|
started = false;
|
|
8665
8608
|
nextIndex = 0;
|
|
@@ -8839,8 +8782,7 @@ var GoogleMessagesStreamTranslator = class {
|
|
|
8839
8782
|
this.block = void 0;
|
|
8840
8783
|
}
|
|
8841
8784
|
};
|
|
8842
|
-
|
|
8843
|
-
//#region src/services/providers/google.ts
|
|
8785
|
+
// src/services/providers/google.ts
|
|
8844
8786
|
async function forwardGoogleGenerateContent(provider, model, payload, requestHeaders, options) {
|
|
8845
8787
|
const modelId = encodeURIComponent(model.replace(/^models\//u, ""));
|
|
8846
8788
|
const method = options.stream ? "streamGenerateContent" : "generateContent";
|
|
@@ -8861,8 +8803,7 @@ async function forwardGoogleGenerateContent(provider, model, payload, requestHea
|
|
|
8861
8803
|
streamInactivityTimeoutMs: transport.streamInactivityTimeoutMs
|
|
8862
8804
|
});
|
|
8863
8805
|
}
|
|
8864
|
-
|
|
8865
|
-
//#region src/routes/provider/messages/google-handler.ts
|
|
8806
|
+
// src/routes/provider/messages/google-handler.ts
|
|
8866
8807
|
const logger$13 = createHandlerLogger("provider-google-messages");
|
|
8867
8808
|
async function handleGoogleProviderMessages(c, payload, provider, usageEndpoint) {
|
|
8868
8809
|
debugJson(logger$13, "provider.messages.google.original_request", payload);
|
|
@@ -8936,8 +8877,7 @@ async function handleGoogleProviderMessages(c, payload, provider, usageEndpoint)
|
|
|
8936
8877
|
}
|
|
8937
8878
|
});
|
|
8938
8879
|
}
|
|
8939
|
-
|
|
8940
|
-
//#region src/routes/provider/messages/handler.ts
|
|
8880
|
+
// src/routes/provider/messages/handler.ts
|
|
8941
8881
|
const logger$12 = createHandlerLogger("provider-messages-handler");
|
|
8942
8882
|
const providerMessagesHandlerDependencies = { resolveProviderConfig };
|
|
8943
8883
|
async function handleProviderMessages(c) {
|
|
@@ -9618,8 +9558,7 @@ const createProviderMessagesUsageRecorder = (payload, provider, modelConfig, pri
|
|
|
9618
9558
|
providerName: provider,
|
|
9619
9559
|
sessionId: parseUserIdMetadata(payload.metadata?.user_id).sessionId
|
|
9620
9560
|
});
|
|
9621
|
-
|
|
9622
|
-
//#region src/services/copilot/create-messages.ts
|
|
9561
|
+
// src/services/copilot/create-messages.ts
|
|
9623
9562
|
const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
9624
9563
|
const allowedAnthropicBetas = /* @__PURE__ */ new Set([
|
|
9625
9564
|
INTERLEAVED_THINKING_BETA,
|
|
@@ -9680,8 +9619,7 @@ const createMessages = async (payload, anthropicBetaHeader, options) => {
|
|
|
9680
9619
|
if (payload.stream) return events(response);
|
|
9681
9620
|
return await response.json();
|
|
9682
9621
|
};
|
|
9683
|
-
|
|
9684
|
-
//#region src/routes/messages/api-flows.ts
|
|
9622
|
+
// src/routes/messages/api-flows.ts
|
|
9685
9623
|
const COPILOT_CONTEXT_CACHE_SYSTEM_MARKER_LIMIT = 2;
|
|
9686
9624
|
const COPILOT_CONTEXT_CACHE_NON_SYSTEM_MARKER_LIMIT = 1;
|
|
9687
9625
|
const COPILOT_CONTEXT_CACHE_CONTROL = { type: "ephemeral" };
|
|
@@ -9891,11 +9829,11 @@ const handleWithMessagesApi = async (c, anthropicPayload, options) => {
|
|
|
9891
9829
|
recordAnthropicFirstToken(parsedEvent);
|
|
9892
9830
|
if (parsedEvent?.type === "message_start") usage = mergeAnthropicUsage(usage, {
|
|
9893
9831
|
...normalizeAnthropicUsage(parsedEvent.message.usage),
|
|
9894
|
-
...normalizeCopilotUsage(parsedEvent.message.copilot_usage)
|
|
9832
|
+
...normalizeCopilotUsage$1(parsedEvent.message.copilot_usage)
|
|
9895
9833
|
});
|
|
9896
9834
|
else if (parsedEvent?.type === "message_delta") usage = mergeAnthropicUsage(usage, {
|
|
9897
9835
|
...normalizeAnthropicUsage(parsedEvent.usage),
|
|
9898
|
-
...normalizeCopilotUsage(parsedEvent.copilot_usage)
|
|
9836
|
+
...normalizeCopilotUsage$1(parsedEvent.copilot_usage)
|
|
9899
9837
|
});
|
|
9900
9838
|
if (parsedEvent?.type === "message_stop" || eventName === "message_stop") messageStopSeen = true;
|
|
9901
9839
|
else if (parsedEvent?.type === "error" || eventName === "error") errorSeen = true;
|
|
@@ -9924,7 +9862,7 @@ const handleWithMessagesApi = async (c, anthropicPayload, options) => {
|
|
|
9924
9862
|
});
|
|
9925
9863
|
recordUsage({
|
|
9926
9864
|
...normalizeAnthropicUsage(response.usage),
|
|
9927
|
-
...normalizeCopilotUsage(response.copilot_usage)
|
|
9865
|
+
...normalizeCopilotUsage$1(response.copilot_usage)
|
|
9928
9866
|
});
|
|
9929
9867
|
return c.json(response);
|
|
9930
9868
|
};
|
|
@@ -9956,7 +9894,7 @@ const createCopilotUsageRecorder = (options) => createCopilotTokenUsageRecorder(
|
|
|
9956
9894
|
sessionId: getMetadataSessionId(options.payload)
|
|
9957
9895
|
});
|
|
9958
9896
|
const getMetadataSessionId = (payload) => parseUserIdMetadata(payload.metadata?.user_id).sessionId;
|
|
9959
|
-
const normalizeCopilotUsage = (copilotUsage) => ({ total_nano_aiu: normalizeOptionalToken(copilotUsage?.total_nano_aiu) });
|
|
9897
|
+
const normalizeCopilotUsage$1 = (copilotUsage) => ({ total_nano_aiu: normalizeOptionalToken(copilotUsage?.total_nano_aiu) });
|
|
9960
9898
|
const parseAnthropicStreamEvent = (data) => {
|
|
9961
9899
|
try {
|
|
9962
9900
|
return JSON.parse(data);
|
|
@@ -9964,11 +9902,9 @@ const parseAnthropicStreamEvent = (data) => {
|
|
|
9964
9902
|
return null;
|
|
9965
9903
|
}
|
|
9966
9904
|
};
|
|
9967
|
-
|
|
9968
|
-
//#region src/lib/subagent.ts
|
|
9905
|
+
// src/lib/subagent.ts
|
|
9969
9906
|
const subagentMarkerPrefix = "__SUBAGENT_MARKER__";
|
|
9970
|
-
|
|
9971
|
-
//#region src/routes/messages/subagent-marker.ts
|
|
9907
|
+
// src/routes/messages/subagent-marker.ts
|
|
9972
9908
|
const parseSubagentMarkerFromFirstUser = (payload) => {
|
|
9973
9909
|
const firstUserMessage = payload.messages.find((msg) => msg.role === "user" && Array.isArray(msg.content));
|
|
9974
9910
|
if (!firstUserMessage || !Array.isArray(firstUserMessage.content)) return null;
|
|
@@ -10010,8 +9946,7 @@ const parseSubagentMarkerFromSystemReminder = (text) => {
|
|
|
10010
9946
|
}
|
|
10011
9947
|
return null;
|
|
10012
9948
|
};
|
|
10013
|
-
|
|
10014
|
-
//#region src/routes/messages/handler.ts
|
|
9949
|
+
// src/routes/messages/handler.ts
|
|
10015
9950
|
const logger$11 = createHandlerLogger("messages-handler");
|
|
10016
9951
|
const messagesFlowHandlers = {
|
|
10017
9952
|
handleWithChatCompletions,
|
|
@@ -10124,8 +10059,7 @@ const shouldUseMessagesApi = (selectedModel) => {
|
|
|
10124
10059
|
if (!isMessagesApiEnabled()) return false;
|
|
10125
10060
|
return selectedModel?.supported_endpoints?.includes(MESSAGES_ENDPOINT$1) ?? false;
|
|
10126
10061
|
};
|
|
10127
|
-
|
|
10128
|
-
//#region src/routes/messages/route.ts
|
|
10062
|
+
// src/routes/messages/route.ts
|
|
10129
10063
|
const messageRoutes = new Hono();
|
|
10130
10064
|
messageRoutes.post("/", async (c) => {
|
|
10131
10065
|
try {
|
|
@@ -10141,8 +10075,7 @@ messageRoutes.post("/count_tokens", async (c) => {
|
|
|
10141
10075
|
return await forwardError(c, error);
|
|
10142
10076
|
}
|
|
10143
10077
|
});
|
|
10144
|
-
|
|
10145
|
-
//#region src/lib/model-display-name.ts
|
|
10078
|
+
// src/lib/model-display-name.ts
|
|
10146
10079
|
/** Keep upstream labels as the base and identify their gateway provider. */
|
|
10147
10080
|
function withModelDisplayName(model, provider) {
|
|
10148
10081
|
if (typeof model !== "object" || model === null || Array.isArray(model)) return model;
|
|
@@ -10157,8 +10090,7 @@ function withModelDisplayName(model, provider) {
|
|
|
10157
10090
|
display_name: displayName
|
|
10158
10091
|
};
|
|
10159
10092
|
}
|
|
10160
|
-
|
|
10161
|
-
//#region src/routes/models/model-discovery.ts
|
|
10093
|
+
// src/routes/models/model-discovery.ts
|
|
10162
10094
|
const logger$10 = createHandlerLogger("models-handler");
|
|
10163
10095
|
const EPOCH_ISO = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
10164
10096
|
function isRecord(value) {
|
|
@@ -10315,8 +10247,7 @@ function createModelListResponse(c, models) {
|
|
|
10315
10247
|
has_more: false
|
|
10316
10248
|
});
|
|
10317
10249
|
}
|
|
10318
|
-
|
|
10319
|
-
//#region src/routes/models/claude-models.ts
|
|
10250
|
+
// src/routes/models/claude-models.ts
|
|
10320
10251
|
async function handleClaudeModels(c) {
|
|
10321
10252
|
return createModelListResponse(c, (await getAgentModels(stripInternalRequestHeaders(c.req.raw.headers))).map((model) => ({
|
|
10322
10253
|
...model,
|
|
@@ -10389,8 +10320,7 @@ function serializeCodexModelCatalog(response, options) {
|
|
|
10389
10320
|
models: models.filter((model) => selected.has(model))
|
|
10390
10321
|
});
|
|
10391
10322
|
}
|
|
10392
|
-
|
|
10393
|
-
//#region src/routes/models/model-metadata.ts
|
|
10323
|
+
// src/routes/models/model-metadata.ts
|
|
10394
10324
|
function normalizeMetadata(fields) {
|
|
10395
10325
|
const contextWindow = firstPositiveInteger(fields?.contextWindow);
|
|
10396
10326
|
const maxOutputTokens = firstPositiveInteger(fields?.maxOutputTokens);
|
|
@@ -10436,8 +10366,7 @@ function getModelMetadata(provider, modelId, model, config) {
|
|
|
10436
10366
|
reasoningEfforts: metadata.reasoningEfforts ?? []
|
|
10437
10367
|
};
|
|
10438
10368
|
}
|
|
10439
|
-
|
|
10440
|
-
//#region src/routes/models/codex-model-candidates.ts
|
|
10369
|
+
// src/routes/models/codex-model-candidates.ts
|
|
10441
10370
|
const logger$9 = createHandlerLogger("models-handler");
|
|
10442
10371
|
const RESPONSES_ENDPOINTS = /* @__PURE__ */ new Set(["/responses", "ws:/responses"]);
|
|
10443
10372
|
const MESSAGES_ENDPOINT = "/v1/messages";
|
|
@@ -10551,8 +10480,7 @@ function selectDefaultReasoningEffort(efforts, configured) {
|
|
|
10551
10480
|
function positiveNumber(value, fallback) {
|
|
10552
10481
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
|
|
10553
10482
|
}
|
|
10554
|
-
|
|
10555
|
-
//#region src/routes/models/models.json
|
|
10483
|
+
// src/routes/models/models.json
|
|
10556
10484
|
var models = [
|
|
10557
10485
|
{
|
|
10558
10486
|
"slug": "gpt-6-astra",
|
|
@@ -12070,8 +11998,7 @@ var models = [
|
|
|
12070
11998
|
"supports_reasoning_summaries": true
|
|
12071
11999
|
}
|
|
12072
12000
|
];
|
|
12073
|
-
|
|
12074
|
-
//#region src/routes/models/codex-models.ts
|
|
12001
|
+
// src/routes/models/codex-models.ts
|
|
12075
12002
|
const logger$8 = createHandlerLogger("codex-models-handler");
|
|
12076
12003
|
const CODEX_USER_AGENT_PATTERN = /^codex/iu;
|
|
12077
12004
|
const DEFAULT_REASONING_EFFORTS = [
|
|
@@ -12318,13 +12245,11 @@ function isCodexModelsResponse(value) {
|
|
|
12318
12245
|
if (!isRecord(value) || !Array.isArray(value.models)) return false;
|
|
12319
12246
|
return value.models.every((model) => isRecord(model) && typeof model.slug === "string");
|
|
12320
12247
|
}
|
|
12321
|
-
|
|
12322
|
-
//#region src/routes/models/default-models.ts
|
|
12248
|
+
// src/routes/models/default-models.ts
|
|
12323
12249
|
async function handleDefaultModels(c) {
|
|
12324
12250
|
return createModelListResponse(c, await (c.req.header("user-agent")?.toLowerCase().startsWith("deepseek") ? getAgentModels : getAggregatedModels)(stripInternalRequestHeaders(c.req.raw.headers)));
|
|
12325
12251
|
}
|
|
12326
|
-
|
|
12327
|
-
//#region src/routes/models/opencode-models.ts
|
|
12252
|
+
// src/routes/models/opencode-models.ts
|
|
12328
12253
|
const RESPONSES_PACKAGE = "@opencode/ai/providers/openai/responses";
|
|
12329
12254
|
const CNY_PER_USD = 6.7;
|
|
12330
12255
|
const COST_DECIMALS = 6;
|
|
@@ -12444,8 +12369,7 @@ async function handleOpencodeModels(c) {
|
|
|
12444
12369
|
c.header("Vary", "User-Agent");
|
|
12445
12370
|
return createModelListResponse(c, models.map((model) => toOpencodeModel(model, contextWindow)));
|
|
12446
12371
|
}
|
|
12447
|
-
|
|
12448
|
-
//#region src/routes/models/route.ts
|
|
12372
|
+
// src/routes/models/route.ts
|
|
12449
12373
|
const modelRoutes = new Hono();
|
|
12450
12374
|
modelRoutes.get("/", async (c) => {
|
|
12451
12375
|
try {
|
|
@@ -12458,8 +12382,7 @@ modelRoutes.get("/", async (c) => {
|
|
|
12458
12382
|
return await forwardError(c, error);
|
|
12459
12383
|
}
|
|
12460
12384
|
});
|
|
12461
|
-
|
|
12462
|
-
//#region src/routes/provider/alpha-search/route.ts
|
|
12385
|
+
// src/routes/provider/alpha-search/route.ts
|
|
12463
12386
|
const logger$7 = createHandlerLogger("provider-alpha-search-handler");
|
|
12464
12387
|
const providerAlphaSearchRoutes = new Hono();
|
|
12465
12388
|
const providerAlphaSearchRouteDependencies = {
|
|
@@ -12496,8 +12419,7 @@ providerAlphaSearchRoutes.post("/", async (c) => {
|
|
|
12496
12419
|
return await forwardError(c, error);
|
|
12497
12420
|
}
|
|
12498
12421
|
});
|
|
12499
|
-
|
|
12500
|
-
//#region src/routes/provider/images/route.ts
|
|
12422
|
+
// src/routes/provider/images/route.ts
|
|
12501
12423
|
const logger$6 = createHandlerLogger("provider-images-handler");
|
|
12502
12424
|
const providerImageRoutes = new Hono();
|
|
12503
12425
|
async function handleProviderImages(c, operation) {
|
|
@@ -12529,8 +12451,7 @@ async function handleProviderImages(c, operation) {
|
|
|
12529
12451
|
}
|
|
12530
12452
|
providerImageRoutes.post("/generations", (c) => handleProviderImages(c, "generations"));
|
|
12531
12453
|
providerImageRoutes.post("/edits", (c) => handleProviderImages(c, "edits"));
|
|
12532
|
-
|
|
12533
|
-
//#region src/routes/provider/messages/route.ts
|
|
12454
|
+
// src/routes/provider/messages/route.ts
|
|
12534
12455
|
const providerMessageRoutes = new Hono();
|
|
12535
12456
|
providerMessageRoutes.post("/", async (c) => {
|
|
12536
12457
|
try {
|
|
@@ -12546,8 +12467,7 @@ providerMessageRoutes.post("/count_tokens", async (c) => {
|
|
|
12546
12467
|
return await forwardError(c, error);
|
|
12547
12468
|
}
|
|
12548
12469
|
});
|
|
12549
|
-
|
|
12550
|
-
//#region src/routes/provider/models/route.ts
|
|
12470
|
+
// src/routes/provider/models/route.ts
|
|
12551
12471
|
const logger$5 = createHandlerLogger("provider-models-handler");
|
|
12552
12472
|
const providerModelRoutes = new Hono();
|
|
12553
12473
|
providerModelRoutes.get("/", async (c) => {
|
|
@@ -12610,8 +12530,7 @@ providerModelRoutes.get("/", async (c) => {
|
|
|
12610
12530
|
return await forwardError(c, error);
|
|
12611
12531
|
}
|
|
12612
12532
|
});
|
|
12613
|
-
|
|
12614
|
-
//#region src/lib/zstd-request.ts
|
|
12533
|
+
// src/lib/zstd-request.ts
|
|
12615
12534
|
const ZSTD_CONTENT_ENCODING = "zstd";
|
|
12616
12535
|
const INVALID_BODY_STATUS = 400;
|
|
12617
12536
|
let nodeZlibPromise = null;
|
|
@@ -12663,8 +12582,7 @@ const toUint8Array = (data) => {
|
|
|
12663
12582
|
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
12664
12583
|
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
12665
12584
|
};
|
|
12666
|
-
|
|
12667
|
-
//#region src/routes/responses/custom-tool-input-stream-decoder.ts
|
|
12585
|
+
// src/routes/responses/custom-tool-input-stream-decoder.ts
|
|
12668
12586
|
const CUSTOM_TOOL_INPUT_PREFIX_TOKENS = [
|
|
12669
12587
|
"{",
|
|
12670
12588
|
"\"input\"",
|
|
@@ -12820,8 +12738,7 @@ var CustomToolInputStreamDecoder = class {
|
|
|
12820
12738
|
function isJsonWhitespace(char) {
|
|
12821
12739
|
return char === " " || char === " " || char === "\r" || char === "\n";
|
|
12822
12740
|
}
|
|
12823
|
-
|
|
12824
|
-
//#region src/routes/responses/messages-stream-translation.ts
|
|
12741
|
+
// src/routes/responses/messages-stream-translation.ts
|
|
12825
12742
|
const EMPTY_SIGNATURE_ENCRYPTED_CONTENT = "";
|
|
12826
12743
|
async function* translateMessagesStream(chunks, context) {
|
|
12827
12744
|
const state = createTranslationState(context);
|
|
@@ -13474,8 +13391,7 @@ function parseAnthropicEvent(data) {
|
|
|
13474
13391
|
} catch {}
|
|
13475
13392
|
throw new ResponsesMessagesTranslationError("Messages API returned malformed streaming JSON", 502);
|
|
13476
13393
|
}
|
|
13477
|
-
|
|
13478
|
-
//#region src/routes/responses/messages-handler.ts
|
|
13394
|
+
// src/routes/responses/messages-handler.ts
|
|
13479
13395
|
const logger$4 = createHandlerLogger("responses-messages-handler");
|
|
13480
13396
|
const responsesMessagesDependencies = { handleCompletionPayload };
|
|
13481
13397
|
async function handleResponsesViaMessages(c, options) {
|
|
@@ -13544,8 +13460,7 @@ function streamTranslatedMessagesEvents(c, response, context) {
|
|
|
13544
13460
|
function isAnthropicResponse(value) {
|
|
13545
13461
|
return typeof value === "object" && value !== null && "type" in value && value.type === "message" && "content" in value && Array.isArray(value.content);
|
|
13546
13462
|
}
|
|
13547
|
-
|
|
13548
|
-
//#region src/routes/responses/task-title.ts
|
|
13463
|
+
// src/routes/responses/task-title.ts
|
|
13549
13464
|
const TASK_TITLE_PROMPT_PREFIX = "Generate a concise, single-line task title of at most 36 characters and under five words where possible.";
|
|
13550
13465
|
const taskTitleDependencies = { getSmallModelForProvider };
|
|
13551
13466
|
const getCodexTaskTitleModel = (userAgent, input, provider) => {
|
|
@@ -13558,8 +13473,7 @@ const getCodexTaskTitleModel = (userAgent, input, provider) => {
|
|
|
13558
13473
|
if (model) consola.debug(`Codex task title small model: ${provider} -> ${model}`);
|
|
13559
13474
|
return model;
|
|
13560
13475
|
};
|
|
13561
|
-
|
|
13562
|
-
//#region src/routes/provider/responses/handler.ts
|
|
13476
|
+
// src/routes/provider/responses/handler.ts
|
|
13563
13477
|
const logger$3 = createHandlerLogger("provider-responses-handler");
|
|
13564
13478
|
const providerResponsesHandlerDependencies = { resolveProviderConfig };
|
|
13565
13479
|
async function handleProviderResponsesForProvider(c, options) {
|
|
@@ -13724,8 +13638,7 @@ const getResponsesStreamEventUsage = (event) => {
|
|
|
13724
13638
|
return null;
|
|
13725
13639
|
};
|
|
13726
13640
|
const getResponsesEvents = (response) => createResponsesSafeStream(createResponsesHttpEventStream(response));
|
|
13727
|
-
|
|
13728
|
-
//#region src/routes/provider/responses/route.ts
|
|
13641
|
+
// src/routes/provider/responses/route.ts
|
|
13729
13642
|
const providerResponsesRoutes = new Hono();
|
|
13730
13643
|
providerResponsesRoutes.use(zstdDecompressionMiddleware);
|
|
13731
13644
|
providerResponsesRoutes.post("/", async (c) => {
|
|
@@ -13741,8 +13654,7 @@ providerResponsesRoutes.post("/", async (c) => {
|
|
|
13741
13654
|
return await forwardError(c, error);
|
|
13742
13655
|
}
|
|
13743
13656
|
});
|
|
13744
|
-
|
|
13745
|
-
//#region src/routes/responses/stream-id-sync.ts
|
|
13657
|
+
// src/routes/responses/stream-id-sync.ts
|
|
13746
13658
|
const createStreamIdTracker = () => ({ outputItems: /* @__PURE__ */ new Map() });
|
|
13747
13659
|
const fixStreamIds = (data, event, tracker) => {
|
|
13748
13660
|
if (!data) return data;
|
|
@@ -13777,8 +13689,7 @@ const handleItemId = (parsed, tracker) => {
|
|
|
13777
13689
|
}
|
|
13778
13690
|
return JSON.stringify(parsed);
|
|
13779
13691
|
};
|
|
13780
|
-
|
|
13781
|
-
//#region src/routes/responses/handler.ts
|
|
13692
|
+
// src/routes/responses/handler.ts
|
|
13782
13693
|
const logger$2 = createHandlerLogger("responses-handler");
|
|
13783
13694
|
const responsesHandlerDependencies = {
|
|
13784
13695
|
createResponses,
|
|
@@ -13986,8 +13897,7 @@ const getCodexResponsesSubagentMarker = (c, session) => {
|
|
|
13986
13897
|
const getTrimmedHeader = (c, name) => {
|
|
13987
13898
|
return c.req.header(name)?.trim() || void 0;
|
|
13988
13899
|
};
|
|
13989
|
-
|
|
13990
|
-
//#region src/routes/responses/route.ts
|
|
13900
|
+
// src/routes/responses/route.ts
|
|
13991
13901
|
const responsesRoutes = new Hono();
|
|
13992
13902
|
responsesRoutes.use(zstdDecompressionMiddleware);
|
|
13993
13903
|
responsesRoutes.post("/", async (c) => {
|
|
@@ -13997,8 +13907,7 @@ responsesRoutes.post("/", async (c) => {
|
|
|
13997
13907
|
return await forwardError(c, error);
|
|
13998
13908
|
}
|
|
13999
13909
|
});
|
|
14000
|
-
|
|
14001
|
-
//#region src/routes/token-usage/route.ts
|
|
13910
|
+
// src/routes/token-usage/route.ts
|
|
14002
13911
|
const tokenUsageRoute = new Hono();
|
|
14003
13912
|
const periods = /* @__PURE__ */ new Set([
|
|
14004
13913
|
"today",
|
|
@@ -14039,9 +13948,329 @@ function parsePageQuery(c) {
|
|
|
14039
13948
|
}
|
|
14040
13949
|
tokenUsageRoute.get("/events", async (c) => c.json(await getTokenUsageEventsPage(parsePageQuery(c))));
|
|
14041
13950
|
tokenUsageRoute.get("/sessions", async (c) => c.json(await getTokenUsageSessionsPage(parsePageQuery(c))));
|
|
14042
|
-
|
|
14043
|
-
|
|
13951
|
+
// src/services/subscription-usage.ts
|
|
13952
|
+
const CODEX_CLI_VERSION = "0.164.0";
|
|
13953
|
+
const amount = z.union([z.number().finite(), z.string().trim().min(1).refine((value) => Number.isFinite(Number(value)))]).transform(Number);
|
|
13954
|
+
const number = z.number().finite();
|
|
13955
|
+
const codexWindow = z.object({
|
|
13956
|
+
used_percent: number,
|
|
13957
|
+
limit_window_seconds: number.nullish(),
|
|
13958
|
+
reset_at: number.nullish(),
|
|
13959
|
+
reset_after_seconds: number.nullish()
|
|
13960
|
+
});
|
|
13961
|
+
const codexRateLimit = z.object({
|
|
13962
|
+
allowed: z.boolean().nullish(),
|
|
13963
|
+
limit_reached: z.boolean().nullish(),
|
|
13964
|
+
primary_window: codexWindow.nullish(),
|
|
13965
|
+
secondary_window: codexWindow.nullish()
|
|
13966
|
+
});
|
|
13967
|
+
const codexUsage = z.object({
|
|
13968
|
+
plan_type: z.string(),
|
|
13969
|
+
rate_limit: codexRateLimit.nullish(),
|
|
13970
|
+
additional_rate_limits: z.array(z.object({
|
|
13971
|
+
limit_name: z.string(),
|
|
13972
|
+
metered_feature: z.string(),
|
|
13973
|
+
rate_limit: codexRateLimit.nullish()
|
|
13974
|
+
})).nullish(),
|
|
13975
|
+
credits: z.object({
|
|
13976
|
+
has_credits: z.boolean(),
|
|
13977
|
+
unlimited: z.boolean(),
|
|
13978
|
+
balance: amount.nullish()
|
|
13979
|
+
}).nullish(),
|
|
13980
|
+
spend_control: z.object({
|
|
13981
|
+
reached: z.boolean(),
|
|
13982
|
+
individual_limit: z.object({
|
|
13983
|
+
limit: amount,
|
|
13984
|
+
used: amount,
|
|
13985
|
+
used_percent: number,
|
|
13986
|
+
reset_at: number.nullish(),
|
|
13987
|
+
reset_after_seconds: number.nullish()
|
|
13988
|
+
}).nullish()
|
|
13989
|
+
}).nullish(),
|
|
13990
|
+
rate_limit_reached_type: z.object({ type: z.string() }).nullish()
|
|
13991
|
+
});
|
|
13992
|
+
const cents = z.object({ val: amount.default(0) }).nullish();
|
|
13993
|
+
const xaiUsage = z.object({
|
|
13994
|
+
config: z.object({
|
|
13995
|
+
creditUsagePercent: number.nullish(),
|
|
13996
|
+
currentPeriod: z.object({
|
|
13997
|
+
type: z.string().nullish(),
|
|
13998
|
+
end: z.string().nullish()
|
|
13999
|
+
}).nullish(),
|
|
14000
|
+
monthlyLimit: cents,
|
|
14001
|
+
used: cents,
|
|
14002
|
+
onDemandCap: cents,
|
|
14003
|
+
onDemandUsed: cents,
|
|
14004
|
+
prepaidBalance: cents,
|
|
14005
|
+
billingPeriodEnd: z.string().nullish()
|
|
14006
|
+
}).nullish(),
|
|
14007
|
+
subscription_tier: z.string().nullish()
|
|
14008
|
+
});
|
|
14009
|
+
const copilotQuota = z.object({
|
|
14010
|
+
entitlement: number.nullish(),
|
|
14011
|
+
remaining: number.nullish(),
|
|
14012
|
+
quota_remaining: number.nullish(),
|
|
14013
|
+
percent_remaining: number.nullish(),
|
|
14014
|
+
unlimited: z.boolean().nullish()
|
|
14015
|
+
});
|
|
14016
|
+
const copilotUsage = z.object({
|
|
14017
|
+
copilot_plan: z.string().nullish(),
|
|
14018
|
+
quota_reset_date: z.string().nullish(),
|
|
14019
|
+
quota_snapshots: z.object({
|
|
14020
|
+
premium_interactions: copilotQuota.nullish(),
|
|
14021
|
+
chat: copilotQuota.nullish(),
|
|
14022
|
+
completions: copilotQuota.nullish()
|
|
14023
|
+
}).nullish()
|
|
14024
|
+
});
|
|
14025
|
+
const opencodeGoWindow = z.object({
|
|
14026
|
+
status: z.enum(["ok", "rate-limited"]),
|
|
14027
|
+
percent: number,
|
|
14028
|
+
resetsAt: z.string().nullish()
|
|
14029
|
+
});
|
|
14030
|
+
const opencodeGoUsage = z.object({ usage: z.object({
|
|
14031
|
+
rolling: opencodeGoWindow.nullish(),
|
|
14032
|
+
weekly: opencodeGoWindow.nullish(),
|
|
14033
|
+
monthly: opencodeGoWindow.nullish()
|
|
14034
|
+
}) });
|
|
14035
|
+
function normalizeOpencodeGoUsage(value) {
|
|
14036
|
+
const { usage } = opencodeGoUsage.parse(value);
|
|
14037
|
+
const windows = [];
|
|
14038
|
+
for (const scope of [
|
|
14039
|
+
"rolling",
|
|
14040
|
+
"weekly",
|
|
14041
|
+
"monthly"
|
|
14042
|
+
]) {
|
|
14043
|
+
const window = usage[scope];
|
|
14044
|
+
if (!window) continue;
|
|
14045
|
+
windows.push({
|
|
14046
|
+
id: `opencode-go:${scope}`,
|
|
14047
|
+
kind: "usage",
|
|
14048
|
+
windowSeconds: scope === "rolling" ? 18e3 : void 0,
|
|
14049
|
+
period: scope === "rolling" ? void 0 : scope,
|
|
14050
|
+
usedPercent: window.percent,
|
|
14051
|
+
resetAt: parseResetDate(window.resetsAt),
|
|
14052
|
+
limitReached: window.status === "rate-limited" || window.percent >= 100
|
|
14053
|
+
});
|
|
14054
|
+
}
|
|
14055
|
+
return {
|
|
14056
|
+
provider: "opencode-go",
|
|
14057
|
+
windows,
|
|
14058
|
+
limitReached: windows.some((window) => window.limitReached)
|
|
14059
|
+
};
|
|
14060
|
+
}
|
|
14061
|
+
function normalizeCopilotUsage(value) {
|
|
14062
|
+
const usage = copilotUsage.parse(value);
|
|
14063
|
+
const windows = [];
|
|
14064
|
+
const labels = {
|
|
14065
|
+
premium_interactions: "Premium",
|
|
14066
|
+
chat: "Chat",
|
|
14067
|
+
completions: "Completions"
|
|
14068
|
+
};
|
|
14069
|
+
for (const id of [
|
|
14070
|
+
"premium_interactions",
|
|
14071
|
+
"chat",
|
|
14072
|
+
"completions"
|
|
14073
|
+
]) {
|
|
14074
|
+
const quota = usage.quota_snapshots?.[id];
|
|
14075
|
+
if (!quota) continue;
|
|
14076
|
+
const remaining = quota.remaining ?? quota.quota_remaining;
|
|
14077
|
+
const limit = quota.entitlement ?? void 0;
|
|
14078
|
+
const remainingPercent = quota.percent_remaining ?? (limit !== void 0 && limit > 0 && remaining != null ? remaining / limit * 100 : void 0);
|
|
14079
|
+
if (!quota.unlimited && remainingPercent == null && remaining == null && limit === void 0) continue;
|
|
14080
|
+
windows.push({
|
|
14081
|
+
id: `copilot:${id}`,
|
|
14082
|
+
kind: "usage",
|
|
14083
|
+
name: labels[id],
|
|
14084
|
+
unlimited: quota.unlimited ?? false,
|
|
14085
|
+
usedPercent: quota.unlimited || remainingPercent == null ? void 0 : 100 - remainingPercent,
|
|
14086
|
+
used: limit !== void 0 && remaining != null ? Math.max(0, limit - remaining) : void 0,
|
|
14087
|
+
limit,
|
|
14088
|
+
unit: "requests",
|
|
14089
|
+
resetDate: usage.quota_reset_date ?? void 0,
|
|
14090
|
+
limitReached: !quota.unlimited && remainingPercent != null && remainingPercent <= 0
|
|
14091
|
+
});
|
|
14092
|
+
}
|
|
14093
|
+
return {
|
|
14094
|
+
provider: "github-copilot",
|
|
14095
|
+
planType: usage.copilot_plan ?? void 0,
|
|
14096
|
+
windows,
|
|
14097
|
+
limitReached: windows.some((window) => window.limitReached)
|
|
14098
|
+
};
|
|
14099
|
+
}
|
|
14100
|
+
function resetAt(window, now) {
|
|
14101
|
+
return window.reset_at ?? (window.reset_after_seconds == null ? void 0 : Math.floor(now / 1e3) + window.reset_after_seconds);
|
|
14102
|
+
}
|
|
14103
|
+
function normalizeCodexUsage(value, now = Date.now()) {
|
|
14104
|
+
const usage = codexUsage.parse(value);
|
|
14105
|
+
const windows = [];
|
|
14106
|
+
const addWindows = (id, limits, name) => {
|
|
14107
|
+
for (const scope of ["primary_window", "secondary_window"]) {
|
|
14108
|
+
const window = limits?.[scope];
|
|
14109
|
+
if (!window) continue;
|
|
14110
|
+
windows.push({
|
|
14111
|
+
id: `${id}:${scope}`,
|
|
14112
|
+
kind: "usage",
|
|
14113
|
+
name,
|
|
14114
|
+
usedPercent: window.used_percent,
|
|
14115
|
+
windowSeconds: window.limit_window_seconds ?? void 0,
|
|
14116
|
+
resetAt: resetAt(window, now),
|
|
14117
|
+
limitReached: limits?.limit_reached === true || limits?.allowed === false
|
|
14118
|
+
});
|
|
14119
|
+
}
|
|
14120
|
+
};
|
|
14121
|
+
addWindows("codex", usage.rate_limit);
|
|
14122
|
+
for (const [index, limit] of (usage.additional_rate_limits ?? []).entries()) addWindows(`${limit.metered_feature}:${index}`, limit.rate_limit, limit.limit_name);
|
|
14123
|
+
const spend = usage.spend_control?.individual_limit;
|
|
14124
|
+
if (spend) windows.push({
|
|
14125
|
+
id: "individual-limit",
|
|
14126
|
+
kind: "spend",
|
|
14127
|
+
period: "monthly",
|
|
14128
|
+
usedPercent: spend.used_percent,
|
|
14129
|
+
used: spend.used,
|
|
14130
|
+
limit: spend.limit,
|
|
14131
|
+
unit: "credits",
|
|
14132
|
+
resetAt: resetAt(spend, now),
|
|
14133
|
+
limitReached: usage.spend_control?.reached
|
|
14134
|
+
});
|
|
14135
|
+
return {
|
|
14136
|
+
provider: "codex",
|
|
14137
|
+
planType: usage.plan_type,
|
|
14138
|
+
windows,
|
|
14139
|
+
credits: usage.credits ? {
|
|
14140
|
+
balance: usage.credits.balance ?? void 0,
|
|
14141
|
+
unlimited: usage.credits.unlimited,
|
|
14142
|
+
hasCredits: usage.credits.has_credits,
|
|
14143
|
+
unit: "credits"
|
|
14144
|
+
} : void 0,
|
|
14145
|
+
limitReached: usage.rate_limit?.limit_reached === true || usage.rate_limit?.allowed === false || usage.spend_control?.reached === true || usage.rate_limit_reached_type != null && usage.rate_limit_reached_type.type !== "unknown",
|
|
14146
|
+
limitReason: usage.rate_limit_reached_type?.type
|
|
14147
|
+
};
|
|
14148
|
+
}
|
|
14149
|
+
function parseResetDate(value) {
|
|
14150
|
+
const milliseconds = value ? Date.parse(value) : NaN;
|
|
14151
|
+
return Number.isFinite(milliseconds) ? milliseconds / 1e3 : void 0;
|
|
14152
|
+
}
|
|
14153
|
+
function normalizeXaiUsage(value) {
|
|
14154
|
+
const usage = xaiUsage.parse(value);
|
|
14155
|
+
const config = usage.config;
|
|
14156
|
+
const windows = [];
|
|
14157
|
+
if (config) {
|
|
14158
|
+
const limit = config.monthlyLimit?.val;
|
|
14159
|
+
const used = config.used?.val;
|
|
14160
|
+
const usedPercent = config.creditUsagePercent ?? (limit !== void 0 && limit > 0 && used !== void 0 ? used / limit * 100 : void 0);
|
|
14161
|
+
if (usedPercent != null || limit !== void 0 || used !== void 0) windows.push({
|
|
14162
|
+
id: "included",
|
|
14163
|
+
kind: "usage",
|
|
14164
|
+
period: config.currentPeriod?.type === "USAGE_PERIOD_TYPE_WEEKLY" ? "weekly" : config.currentPeriod?.type === "USAGE_PERIOD_TYPE_MONTHLY" || config.monthlyLimit ? "monthly" : void 0,
|
|
14165
|
+
usedPercent,
|
|
14166
|
+
used: config.creditUsagePercent == null && used !== void 0 ? used / 100 : void 0,
|
|
14167
|
+
limit: config.creditUsagePercent == null && limit !== void 0 ? limit / 100 : void 0,
|
|
14168
|
+
unit: "USD",
|
|
14169
|
+
resetAt: parseResetDate(config.currentPeriod?.end ?? config.billingPeriodEnd)
|
|
14170
|
+
});
|
|
14171
|
+
if (config.onDemandCap || config.onDemandUsed) {
|
|
14172
|
+
const cap = Math.abs(config.onDemandCap?.val ?? 0);
|
|
14173
|
+
const spent = Math.abs(config.onDemandUsed?.val ?? 0);
|
|
14174
|
+
windows.push({
|
|
14175
|
+
id: "on-demand",
|
|
14176
|
+
kind: "on-demand",
|
|
14177
|
+
period: "monthly",
|
|
14178
|
+
unit: "USD",
|
|
14179
|
+
used: spent / 100,
|
|
14180
|
+
limit: cap / 100,
|
|
14181
|
+
usedPercent: cap > 0 ? spent / cap * 100 : void 0
|
|
14182
|
+
});
|
|
14183
|
+
}
|
|
14184
|
+
}
|
|
14185
|
+
return {
|
|
14186
|
+
provider: "xai",
|
|
14187
|
+
planType: usage.subscription_tier ?? void 0,
|
|
14188
|
+
windows,
|
|
14189
|
+
credits: config?.prepaidBalance ? {
|
|
14190
|
+
balance: Math.abs(config.prepaidBalance.val) / 100,
|
|
14191
|
+
unlimited: false,
|
|
14192
|
+
hasCredits: config.prepaidBalance.val !== 0,
|
|
14193
|
+
unit: "USD"
|
|
14194
|
+
} : void 0,
|
|
14195
|
+
limitReached: (windows.find((window) => window.id === "included")?.usedPercent ?? 0) >= 100
|
|
14196
|
+
};
|
|
14197
|
+
}
|
|
14198
|
+
async function getSubscriptionUsage(provider, signal) {
|
|
14199
|
+
if (provider === "github-copilot") {
|
|
14200
|
+
if (!isGitHubCopilotEnabled()) return null;
|
|
14201
|
+
const timeout = AbortSignal.timeout(15e3);
|
|
14202
|
+
const usage = await getCopilotUsage(void 0, signal ? AbortSignal.any([signal, timeout]) : timeout);
|
|
14203
|
+
return usage ? normalizeCopilotUsage(usage) : null;
|
|
14204
|
+
}
|
|
14205
|
+
const config = await resolveProviderConfig(provider);
|
|
14206
|
+
if (!config) return null;
|
|
14207
|
+
if (provider !== "opencode-go" && config.authType !== "oauth2") return null;
|
|
14208
|
+
let headers;
|
|
14209
|
+
let url;
|
|
14210
|
+
if (provider === "opencode-go") {
|
|
14211
|
+
url = resolveProviderEndpointUrl(config, "usage");
|
|
14212
|
+
headers = new Headers({
|
|
14213
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
14214
|
+
Accept: "application/json"
|
|
14215
|
+
});
|
|
14216
|
+
} else if (provider === "codex") {
|
|
14217
|
+
const platform = process.platform === "win32" ? "Windows" : process.platform === "darwin" ? "Mac OS" : os.type();
|
|
14218
|
+
const arch = process.arch === "x64" ? "x86_64" : process.arch === "arm64" ? "aarch64" : process.arch;
|
|
14219
|
+
headers = buildCodexRequestHeaders(new Headers({
|
|
14220
|
+
"user-agent": `codex_cli_rs/${CODEX_CLI_VERSION} (${platform} ${os.release()}; ${arch}) unknown`,
|
|
14221
|
+
originator: "codex_cli_rs",
|
|
14222
|
+
accept: "application/json"
|
|
14223
|
+
}));
|
|
14224
|
+
url = `${CODEX_API_BASE_URL}/wham/usage`;
|
|
14225
|
+
} else {
|
|
14226
|
+
const credentials = await readXaiCredentials();
|
|
14227
|
+
if (!credentials) return null;
|
|
14228
|
+
if (credentials.accessToken !== config.apiKey) throw new Error("Subscription account changed during the usage query");
|
|
14229
|
+
const version = await getGrokBuildVersion();
|
|
14230
|
+
const platform = process.platform === "win32" ? "windows" : process.platform === "darwin" ? "macos" : process.platform;
|
|
14231
|
+
const arch = process.arch === "x64" ? "x86_64" : process.arch === "arm64" ? "aarch64" : process.arch;
|
|
14232
|
+
headers = new Headers({
|
|
14233
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
14234
|
+
"X-XAI-Token-Auth": "xai-grok-cli",
|
|
14235
|
+
"x-userid": credentials.accountId,
|
|
14236
|
+
"x-grok-client-version": version,
|
|
14237
|
+
"x-grok-client-mode": "headless",
|
|
14238
|
+
"User-Agent": `grok-shell/${version} (${platform}; ${arch})`,
|
|
14239
|
+
Accept: "application/json"
|
|
14240
|
+
});
|
|
14241
|
+
url = `${XAI_API_BASE_URL}/v1/billing?format=credits`;
|
|
14242
|
+
}
|
|
14243
|
+
const timeout = AbortSignal.timeout(15e3);
|
|
14244
|
+
const response = await fetch(url, {
|
|
14245
|
+
headers,
|
|
14246
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
14247
|
+
redirect: "error"
|
|
14248
|
+
});
|
|
14249
|
+
if (provider === "opencode-go" && response.status === 403) {
|
|
14250
|
+
await response.body?.cancel();
|
|
14251
|
+
return null;
|
|
14252
|
+
}
|
|
14253
|
+
if (!response.ok) {
|
|
14254
|
+
await response.body?.cancel();
|
|
14255
|
+
throw new Error(`Subscription usage request failed (HTTP ${response.status})`);
|
|
14256
|
+
}
|
|
14257
|
+
const value = await response.json();
|
|
14258
|
+
if (provider === "opencode-go") return normalizeOpencodeGoUsage(value);
|
|
14259
|
+
return provider === "codex" ? normalizeCodexUsage(value) : normalizeXaiUsage(value);
|
|
14260
|
+
}
|
|
14261
|
+
// src/routes/usage/route.ts
|
|
14044
14262
|
const usageRoute = new Hono();
|
|
14263
|
+
usageRoute.get("/:provider", async (c) => {
|
|
14264
|
+
const provider = c.req.param("provider");
|
|
14265
|
+
c.header("Cache-Control", "no-store");
|
|
14266
|
+
if (provider !== "codex" && provider !== "xai" && provider !== "github-copilot" && provider !== "opencode-go") return c.json({ error: "Unsupported subscription provider" }, 404);
|
|
14267
|
+
try {
|
|
14268
|
+
const usage = await getSubscriptionUsage(provider, c.req.raw.signal);
|
|
14269
|
+
return usage ? c.json(usage) : c.json({ error: "Subscription account is not available" }, 404);
|
|
14270
|
+
} catch {
|
|
14271
|
+
return c.json({ error: "Failed to fetch subscription usage" }, 502);
|
|
14272
|
+
}
|
|
14273
|
+
});
|
|
14045
14274
|
usageRoute.get("/", async (c) => {
|
|
14046
14275
|
try {
|
|
14047
14276
|
const usage = await getCopilotUsage();
|
|
@@ -14051,8 +14280,7 @@ usageRoute.get("/", async (c) => {
|
|
|
14051
14280
|
return c.json({ error: "Failed to fetch Copilot usage" }, 500);
|
|
14052
14281
|
}
|
|
14053
14282
|
});
|
|
14054
|
-
|
|
14055
|
-
//#region src/services/xai/videos.ts
|
|
14283
|
+
// src/services/xai/videos.ts
|
|
14056
14284
|
var XaiVideosRequestError = class extends Error {
|
|
14057
14285
|
constructor(message) {
|
|
14058
14286
|
super(message);
|
|
@@ -14080,8 +14308,7 @@ async function forwardXaiVideos(providerConfig, request, videoRequest) {
|
|
|
14080
14308
|
streamInactivityTimeoutMs: transport.streamInactivityTimeoutMs
|
|
14081
14309
|
});
|
|
14082
14310
|
}
|
|
14083
|
-
|
|
14084
|
-
//#region src/routes/videos/route.ts
|
|
14311
|
+
// src/routes/videos/route.ts
|
|
14085
14312
|
const logger$1 = createHandlerLogger("videos-handler");
|
|
14086
14313
|
const SUPPORTED_VIDEO_MODEL = "grok-imagine-video-1.5";
|
|
14087
14314
|
const videoRouteDependencies = {
|
|
@@ -14135,8 +14362,7 @@ async function handleVideos(c, operation) {
|
|
|
14135
14362
|
}
|
|
14136
14363
|
videoRoutes.post("/generations", (c) => handleVideos(c, "generations"));
|
|
14137
14364
|
videoRoutes.get("/:request_id", (c) => handleVideos(c, "result"));
|
|
14138
|
-
|
|
14139
|
-
//#region src/server.ts
|
|
14365
|
+
// src/server.ts
|
|
14140
14366
|
function resolveSameOriginCorsOrigin(origin, context) {
|
|
14141
14367
|
if (!origin) return null;
|
|
14142
14368
|
try {
|
|
@@ -14203,7 +14429,6 @@ function createServer(options = {}) {
|
|
|
14203
14429
|
return server;
|
|
14204
14430
|
}
|
|
14205
14431
|
createServer();
|
|
14206
|
-
//#endregion
|
|
14207
14432
|
export { createServer };
|
|
14208
14433
|
|
|
14209
|
-
//# sourceMappingURL=server-
|
|
14434
|
+
//# sourceMappingURL=server-DhHL2SxL.js.map
|