@jeffreycao/copilot-api 2.2.2 → 2.2.5

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.
@@ -1,7 +1,7 @@
1
- import { A as isResponsesApiWebSocketEnabled, C as getClaudeTokenMultiplier, D as isAlphaSearchCodexPriorityEnabled, E as getResponsesTransportConfig, M as PATHS, O as isMessagesApiEnabled, S as getClaudeAutoModel, T as getMessageApiWebSearchModel, _ as resolveMappedModel, b as getAlphaSearchModel, d as getModelResponsesApiCompactThreshold$1, f as getReasoningEffortForModel, g as isGpt56OrAbove, h as isContextManagementEnabledForResponses, i as listEnabledProviders, k as isResponsesApiWebSearchEnabled, l as getExtraPromptForModel, m as isContextManagementEnabledForMessages, n as getRawProviderConfig, o as resolveEffectiveProviderType, p as getSmallModel, s as resolveProviderAuthType, t as getProviderConfig, u as getModelMappings, v as setModelMappings, w as getConfig, x as getAnthropicApiKey } from "./config-D0EIG26T.js";
2
- import { A as buildCodexRequestHeaders, B as createPooledWebSocketStream, C as compactAutoContinuePromptStarts, D as compactTextOnlyGuard, E as compactSystemPromptStarts, F as createResponsesHttpEventStream, H as state, I as fetchResponsesWithLifecycle, L as createResponsesSafeStream, M as generateTraceId, N as requestContext, P as resolveTraceId$1, R as encodePoolKeyPart, U as HTTPError, V as createWebSocketUrl, W as forwardError, b as prepareInteractionHeaders, c as getUUID, d as isResponsesStream, f as parseUserIdMetadata, g as copilotHeaders, h as copilotBaseUrl, j as forwardCodexResponses, k as CODEX_API_BASE_URL, l as isAsyncIterable, o as generateRequestIdFromPayload, p as getCopilotUsage, r as setupCodexToken, s as getRootSessionId, u as isNullish, v as copilotWebSocketHeaders, w as compactMessageSections, x as prepareMessageProxyHeaders, y as prepareForCompact, z as isTerminalResponsesStreamChunk } from "./token-Drm4iN8n.js";
1
+ import { A as isResponsesApiWebSocketEnabled, C as getClaudeTokenMultiplier, D as isAlphaSearchCodexPriorityEnabled, E as getResponsesTransportConfig, N as PATHS, O as isMessagesApiEnabled, S as getClaudeAutoModel, T as getMessageApiWebSearchModel, _ as resolveMappedModel, b as getAlphaSearchModel, d as getModelResponsesApiCompactThreshold$1, f as getReasoningEffortForModel, g as isGpt56OrAbove, h as isContextManagementEnabledForResponses, i as listEnabledProviders, k as isResponsesApiWebSearchEnabled, l as getExtraPromptForModel, m as isContextManagementEnabledForMessages, n as getRawProviderConfig, o as resolveEffectiveProviderType, p as getSmallModel, s as resolveProviderAuthType, t as getProviderConfig, u as getModelMappings, v as setModelMappings, x as getAnthropicApiKey } from "./config-BK3_YOxx.js";
2
+ import { B as fetchResponsesWithLifecycle, C as compactAutoContinuePromptStarts, D as compactTextOnlyGuard, E as compactSystemPromptStarts, F as forwardCodexResponses, G as createWebSocketUrl, H as encodePoolKeyPart, I as generateTraceId, J as forwardError, K as state, L as requestContext, N as CODEX_API_BASE_URL, O as createAuthMiddleware, P as buildCodexRequestHeaders, R as resolveTraceId$1, U as isTerminalResponsesStreamChunk, V as createResponsesSafeStream, W as createPooledWebSocketStream, b as prepareInteractionHeaders, c as getUUID, d as isResponsesStream, f as parseUserIdMetadata, g as copilotHeaders, h as copilotBaseUrl, k as getConfiguredAdminApiKeys, l as isAsyncIterable, o as generateRequestIdFromPayload, p as getCopilotUsage, q as HTTPError, r as setupCodexToken, s as getRootSessionId, u as isNullish, v as copilotWebSocketHeaders, w as compactMessageSections, x as prepareMessageProxyHeaders, y as prepareForCompact, z as createResponsesHttpEventStream } from "./token-u7yV0_hw.js";
3
3
  import { a as isDeferredToolName, c as parseMcpToolSearchSentinel, d as shouldEnableResponsesToolSearch, i as isBridgeToolSearchName, l as resolveBridgeToolSearchName, o as listDeferredToolNames, r as formatToolSearchBridgeArguments, s as normalizeToolSearchBridgeArguments, t as BRIDGE_TOOL_SEARCH_NAME, u as selectDeferredToolsByNames } from "./tool-search-Ds1vbmGG.js";
4
- import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-CgxSOPld.js";
4
+ import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-LIZvOolN.js";
5
5
  import consola from "consola";
6
6
  import { createHash } from "node:crypto";
7
7
  import fs, { readFileSync } from "node:fs";
@@ -16,61 +16,6 @@ import { logger } from "hono/logger";
16
16
  import { decompress } from "fzstd";
17
17
  import util from "node:util";
18
18
  import { streamSSE } from "hono/streaming";
19
- //#region src/lib/request-auth.ts
20
- function normalizeApiKeys(apiKeys) {
21
- if (!Array.isArray(apiKeys)) {
22
- if (apiKeys !== void 0) consola.warn("Invalid auth.apiKeys config. Expected an array of strings.");
23
- return [];
24
- }
25
- const normalizedKeys = apiKeys.filter((key) => typeof key === "string").map((key) => key.trim()).filter((key) => key.length > 0);
26
- if (normalizedKeys.length !== apiKeys.length) consola.warn("Invalid auth.apiKeys entries found. Only non-empty strings are allowed.");
27
- return [...new Set(normalizedKeys)];
28
- }
29
- function getConfiguredApiKeys() {
30
- return normalizeApiKeys(getConfig().auth?.apiKeys);
31
- }
32
- function normalizeApiKey(apiKey) {
33
- if (typeof apiKey !== "string") return null;
34
- return apiKey.trim() || null;
35
- }
36
- function getConfiguredAdminApiKeys() {
37
- const adminApiKey = normalizeApiKey(getConfig().auth?.adminApiKey);
38
- return adminApiKey ? [adminApiKey] : [];
39
- }
40
- function extractRequestApiKey(c) {
41
- const xApiKey = c.req.header("x-api-key")?.trim();
42
- if (xApiKey) return xApiKey;
43
- const authorization = c.req.header("authorization");
44
- if (!authorization) return null;
45
- const [scheme, ...rest] = authorization.trim().split(/\s+/);
46
- if (scheme.toLowerCase() !== "bearer") return null;
47
- return rest.join(" ").trim() || null;
48
- }
49
- function createUnauthorizedResponse(c) {
50
- c.header("WWW-Authenticate", "Bearer realm=\"copilot-api\"");
51
- return c.json({ error: {
52
- message: "Unauthorized",
53
- type: "authentication_error"
54
- } }, 401);
55
- }
56
- function createAuthMiddleware(options = {}) {
57
- const getApiKeys = options.getApiKeys ?? getConfiguredApiKeys;
58
- const allowUnauthenticatedPaths = options.allowUnauthenticatedPaths ?? ["/"];
59
- const allowOptionsBypass = options.allowOptionsBypass ?? true;
60
- const allowWhenNoApiKeys = options.allowWhenNoApiKeys ?? true;
61
- const shouldSkipPath = options.shouldSkipPath ?? (() => false);
62
- return async (c, next) => {
63
- if (allowOptionsBypass && c.req.method === "OPTIONS") return next();
64
- if (shouldSkipPath(c.req.path)) return next();
65
- if (allowUnauthenticatedPaths.includes(c.req.path)) return next();
66
- const apiKeys = getApiKeys();
67
- if (apiKeys.length === 0) return allowWhenNoApiKeys ? next() : createUnauthorizedResponse(c);
68
- const requestApiKey = extractRequestApiKey(c);
69
- if (!requestApiKey || !apiKeys.includes(requestApiKey)) return createUnauthorizedResponse(c);
70
- return next();
71
- };
72
- }
73
- //#endregion
74
19
  //#region src/lib/trace.ts
75
20
  const traceIdMiddleware = async (c, next) => {
76
21
  const traceId = resolveTraceId$1(c.req.header("x-trace-id"));
@@ -10563,4 +10508,4 @@ server.route("/:provider/images", providerImageRoutes);
10563
10508
  //#endregion
10564
10509
  export { server };
10565
10510
 
10566
- //# sourceMappingURL=server-ooE0nEgj.js.map
10511
+ //# sourceMappingURL=server-9Fk9a6_A.js.map