@jeffreycao/copilot-api 1.16.0 → 1.16.2
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-CskgMMwz.js → auth-BJIo9_6w.js} +3 -3
- package/dist/{auth-CskgMMwz.js.map → auth-BJIo9_6w.js.map} +1 -1
- package/dist/auth-BxxohyBj.js +2 -0
- package/dist/{config-B3hsNlmB.js → config-BAC1UYyJ.js} +73 -69
- package/dist/config-BAC1UYyJ.js.map +1 -0
- package/dist/{debug-CVd8Dq56.js → debug-DLs4OzAq.js} +2 -2
- package/dist/{debug-CVd8Dq56.js.map → debug-DLs4OzAq.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{models-_FSj4UOe.js → models-BY_m4eOW.js} +2 -2
- package/dist/models-BY_m4eOW.js.map +1 -0
- package/dist/{server-DWY7PmxG.js → server-DhaNHHv3.js} +39 -86
- package/dist/server-DhaNHHv3.js.map +1 -0
- package/dist/start-D1TEEQrw.js +525 -0
- package/dist/start-D1TEEQrw.js.map +1 -0
- package/dist/{token-DArgO8vi.js → token-ByZO3ykJ.js} +43 -302
- package/dist/token-ByZO3ykJ.js.map +1 -0
- package/package.json +1 -1
- package/dist/auth-CRonPTZQ.js +0 -2
- package/dist/config-B3hsNlmB.js.map +0 -1
- package/dist/models-_FSj4UOe.js.map +0 -1
- package/dist/server-DWY7PmxG.js.map +0 -1
- package/dist/start-YxEMb8V2.js +0 -256
- package/dist/start-YxEMb8V2.js.map +0 -1
- package/dist/token-DArgO8vi.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as PATHS, D as
|
|
2
|
-
import { B as
|
|
1
|
+
import { A as PATHS, C as getConfig, D as isResponsesApiWebSearchEnabled, E as isMessagesApiEnabled, O as isResponsesApiWebSocketEnabled, S as getClaudeTokenMultiplier, T as isAlphaSearchCodexPriorityEnabled, _ as resolveMappedModel, b as getAnthropicApiKey, d as getModelResponsesApiCompactThreshold$1, f as getReasoningEffortForModel, g as isGpt56OrAbove, h as isContextManagementEnabledForResponses, i as listEnabledProviders, 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 getMessageApiWebSearchModel, x as getClaudeAutoModel } from "./config-BAC1UYyJ.js";
|
|
2
|
+
import { A as buildCodexRequestHeaders, B as state, C as compactAutoContinuePromptStarts, E as compactSystemPromptStarts, F as createResponsesSafeStream, H as forwardError, I as encodePoolKeyPart, L as isTerminalResponsesStreamChunk, M as generateTraceId, N as requestContext, P as resolveTraceId$1, R as createPooledWebSocketStream, V as HTTPError, 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 createWebSocketUrl } from "./token-ByZO3ykJ.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-
|
|
4
|
+
import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-BY_m4eOW.js";
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import fs, { readFileSync } from "node:fs";
|
|
@@ -1875,13 +1875,6 @@ const createPooledResponsesWebSocketStream = (request) => createResponsesSafeStr
|
|
|
1875
1875
|
streamErrorMessage: "Responses websocket stream error",
|
|
1876
1876
|
terminalChunkMissingMessage: "Responses websocket ended without a terminal response"
|
|
1877
1877
|
}));
|
|
1878
|
-
const createResponsesSafeStream = async function* (source) {
|
|
1879
|
-
try {
|
|
1880
|
-
yield* source;
|
|
1881
|
-
} catch (error) {
|
|
1882
|
-
yield createResponsesErrorServerSentEventChunk(getErrorMessage(error));
|
|
1883
|
-
}
|
|
1884
|
-
};
|
|
1885
1878
|
const buildResponsesWebSocketPayload = (payload, initiator) => {
|
|
1886
1879
|
const websocketPayload = {
|
|
1887
1880
|
...payload,
|
|
@@ -1900,7 +1893,6 @@ const getHeaderValue = (headers, headerName) => {
|
|
|
1900
1893
|
const normalizedHeaderName = headerName.toLowerCase();
|
|
1901
1894
|
return Object.entries(headers).find(([key]) => key.toLowerCase() === normalizedHeaderName)?.[1];
|
|
1902
1895
|
};
|
|
1903
|
-
const encodePoolKeyPart = (value) => encodeURIComponent(value);
|
|
1904
1896
|
const createResponsesWebSocketStreamChunk = (data) => {
|
|
1905
1897
|
if (data === "[DONE]") return { data };
|
|
1906
1898
|
try {
|
|
@@ -1920,32 +1912,20 @@ const createResponsesWebSocketStreamChunk = (data) => {
|
|
|
1920
1912
|
return { data };
|
|
1921
1913
|
}
|
|
1922
1914
|
};
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
sequence_number: 0,
|
|
1938
|
-
type: "error"
|
|
1939
|
-
};
|
|
1940
|
-
return {
|
|
1941
|
-
event: errorEvent.type,
|
|
1942
|
-
data: JSON.stringify(errorEvent)
|
|
1943
|
-
};
|
|
1944
|
-
};
|
|
1945
|
-
const getErrorMessage = (error) => {
|
|
1946
|
-
if (error instanceof Error && error.message) return error.message;
|
|
1947
|
-
return String(error);
|
|
1948
|
-
};
|
|
1915
|
+
//#endregion
|
|
1916
|
+
//#region src/lib/timeout-dispatcher.ts
|
|
1917
|
+
/**
|
|
1918
|
+
* Node's global fetch keeps Undici's shorter default headers/body timeouts.
|
|
1919
|
+
* Wrap the global dispatcher so long-running requests (e.g. image
|
|
1920
|
+
* generation) get an explicit cap.
|
|
1921
|
+
*/
|
|
1922
|
+
const createTimeoutDispatcher = (timeoutMs) => ({ dispatch(options, handler) {
|
|
1923
|
+
return getGlobalDispatcher().dispatch({
|
|
1924
|
+
...options,
|
|
1925
|
+
bodyTimeout: timeoutMs,
|
|
1926
|
+
headersTimeout: timeoutMs
|
|
1927
|
+
}, handler);
|
|
1928
|
+
} });
|
|
1949
1929
|
//#endregion
|
|
1950
1930
|
//#region src/services/providers/provider-proxy.ts
|
|
1951
1931
|
const SHARED_FORWARDABLE_HEADERS = ["accept", "user-agent"];
|
|
@@ -2023,13 +2003,7 @@ async function forwardProviderModels(providerConfig, requestHeaders) {
|
|
|
2023
2003
|
}
|
|
2024
2004
|
/** Align with Codex images: long-running generation/edits need a generous cap. */
|
|
2025
2005
|
const PROVIDER_IMAGES_TIMEOUT_MS = 900 * 1e3;
|
|
2026
|
-
const providerImagesDispatcher =
|
|
2027
|
-
return getGlobalDispatcher().dispatch({
|
|
2028
|
-
...options,
|
|
2029
|
-
bodyTimeout: PROVIDER_IMAGES_TIMEOUT_MS,
|
|
2030
|
-
headersTimeout: PROVIDER_IMAGES_TIMEOUT_MS
|
|
2031
|
-
}, handler);
|
|
2032
|
-
} };
|
|
2006
|
+
const providerImagesDispatcher = createTimeoutDispatcher(PROVIDER_IMAGES_TIMEOUT_MS);
|
|
2033
2007
|
function resolveProviderRequestUrl(providerConfig, requestUrl, path) {
|
|
2034
2008
|
const upstreamUrl = new URL(`${providerConfig.baseUrl}${path}`);
|
|
2035
2009
|
upstreamUrl.search = new URL(requestUrl, "http://localhost").search;
|
|
@@ -2701,6 +2675,16 @@ const setContextCacheControl = (part) => {
|
|
|
2701
2675
|
part.cache_control = { ...OPENAI_COMPATIBLE_CONTEXT_CACHE_CONTROL };
|
|
2702
2676
|
};
|
|
2703
2677
|
//#endregion
|
|
2678
|
+
//#region src/routes/provider/utils.ts
|
|
2679
|
+
const applyModelDefaults = (payload, modelConfig) => {
|
|
2680
|
+
payload.temperature ??= modelConfig?.temperature;
|
|
2681
|
+
payload.top_p ??= modelConfig?.topP;
|
|
2682
|
+
payload.top_k ??= modelConfig?.topK;
|
|
2683
|
+
};
|
|
2684
|
+
const applyMissingExtraBody = (payload, options) => {
|
|
2685
|
+
for (const [key, value] of Object.entries(options.extraBody ?? {})) if (!Object.hasOwn(payload, key)) payload[key] = value;
|
|
2686
|
+
};
|
|
2687
|
+
//#endregion
|
|
2704
2688
|
//#region src/routes/provider/chat-completions/handler.ts
|
|
2705
2689
|
const logger$13 = createHandlerLogger("provider-chat-completions-handler");
|
|
2706
2690
|
async function handleProviderChatCompletionsForProvider(c, options) {
|
|
@@ -2711,8 +2695,8 @@ async function handleProviderChatCompletionsForProvider(c, options) {
|
|
|
2711
2695
|
type: "invalid_request_error"
|
|
2712
2696
|
} }, 400);
|
|
2713
2697
|
const modelConfig = providerConfig.models?.[payload.model];
|
|
2714
|
-
|
|
2715
|
-
applyMissingExtraBody
|
|
2698
|
+
applyModelDefaults(payload, modelConfig);
|
|
2699
|
+
applyMissingExtraBody(payload, { extraBody: modelConfig?.extraBody });
|
|
2716
2700
|
applyProviderStreamOptions(payload);
|
|
2717
2701
|
applyDashScopePreserveThinkingDefault(payload, providerConfig);
|
|
2718
2702
|
applyProviderContextCache(payload, modelConfig, providerConfig);
|
|
@@ -2739,14 +2723,6 @@ async function handleProviderChatCompletionsForProvider(c, options) {
|
|
|
2739
2723
|
debugJson(logger$13, "provider.chat_completions.response", responseBody);
|
|
2740
2724
|
return createProviderProxyResponse(upstreamResponse);
|
|
2741
2725
|
}
|
|
2742
|
-
const applyProviderModelDefaults = (payload, modelConfig) => {
|
|
2743
|
-
payload.temperature ??= modelConfig?.temperature;
|
|
2744
|
-
payload.top_p ??= modelConfig?.topP;
|
|
2745
|
-
payload.top_k ??= modelConfig?.topK;
|
|
2746
|
-
};
|
|
2747
|
-
const applyMissingExtraBody$1 = (payload, options) => {
|
|
2748
|
-
for (const [key, value] of Object.entries(options.extraBody ?? {})) if (!Object.hasOwn(payload, key)) payload[key] = value;
|
|
2749
|
-
};
|
|
2750
2726
|
const applyProviderStreamOptions = (payload) => {
|
|
2751
2727
|
if (!payload.stream) return;
|
|
2752
2728
|
payload.stream_options = {
|
|
@@ -2968,13 +2944,7 @@ embeddingRoutes.post("/", async (c) => {
|
|
|
2968
2944
|
//#endregion
|
|
2969
2945
|
//#region src/services/codex/images.ts
|
|
2970
2946
|
const CODEX_IMAGES_TIMEOUT_MS = 900 * 1e3;
|
|
2971
|
-
const codexImagesDispatcher =
|
|
2972
|
-
return getGlobalDispatcher().dispatch({
|
|
2973
|
-
...options,
|
|
2974
|
-
bodyTimeout: CODEX_IMAGES_TIMEOUT_MS,
|
|
2975
|
-
headersTimeout: CODEX_IMAGES_TIMEOUT_MS
|
|
2976
|
-
}, handler);
|
|
2977
|
-
} };
|
|
2947
|
+
const codexImagesDispatcher = createTimeoutDispatcher(CODEX_IMAGES_TIMEOUT_MS);
|
|
2978
2948
|
function resolveCodexImagesUrl(requestUrl, operation) {
|
|
2979
2949
|
const upstreamUrl = new URL(`${CODEX_API_BASE_URL}/codex/images/${operation}`);
|
|
2980
2950
|
upstreamUrl.search = new URL(requestUrl, "http://localhost").search;
|
|
@@ -3264,7 +3234,7 @@ function mapOpenAIStopReasonToAnthropic(finishReason) {
|
|
|
3264
3234
|
}
|
|
3265
3235
|
//#endregion
|
|
3266
3236
|
//#region src/routes/messages/non-stream-translation.ts
|
|
3267
|
-
const THINKING_TEXT
|
|
3237
|
+
const THINKING_TEXT = "Thinking...";
|
|
3268
3238
|
const COPILOT_TOOL_CONTENT_SUPPORT_TYPE = ["array", "image"];
|
|
3269
3239
|
function translateToOpenAI(payload, options = {}) {
|
|
3270
3240
|
const modelId = payload.model;
|
|
@@ -3573,7 +3543,7 @@ function getAnthropicThinkBlocks(reasoningText, reasoningOpaque) {
|
|
|
3573
3543
|
}];
|
|
3574
3544
|
if (reasoningOpaque && reasoningOpaque.length > 0) return [{
|
|
3575
3545
|
type: "thinking",
|
|
3576
|
-
thinking: THINKING_TEXT
|
|
3546
|
+
thinking: THINKING_TEXT,
|
|
3577
3547
|
signature: reasoningOpaque
|
|
3578
3548
|
}];
|
|
3579
3549
|
return [];
|
|
@@ -4423,7 +4393,7 @@ function handleReasoningOpaque(delta, events, state) {
|
|
|
4423
4393
|
index: state.contentBlockIndex,
|
|
4424
4394
|
delta: {
|
|
4425
4395
|
type: "thinking_delta",
|
|
4426
|
-
thinking: THINKING_TEXT
|
|
4396
|
+
thinking: THINKING_TEXT
|
|
4427
4397
|
}
|
|
4428
4398
|
}, {
|
|
4429
4399
|
type: "content_block_delta",
|
|
@@ -4491,7 +4461,6 @@ function closeThinkingBlockIfOpen(state, events) {
|
|
|
4491
4461
|
const MESSAGE_TYPE = "message";
|
|
4492
4462
|
const COMPACTION_SIGNATURE_PREFIX = "cm1#";
|
|
4493
4463
|
const COMPACTION_SIGNATURE_SEPARATOR = "@";
|
|
4494
|
-
const THINKING_TEXT = "Thinking...";
|
|
4495
4464
|
const REASONING_SUMMARY_SEPARATOR = "\xA0\n\n";
|
|
4496
4465
|
const REASONING_SUMMARY_SEPARATOR_PATTERN = /\u00a0\n\n|\u2063\n\n/;
|
|
4497
4466
|
const resolveReasoningEffort = (payload) => payload.output_config?.effort ?? getReasoningEffortForModel(payload.model);
|
|
@@ -6309,7 +6278,7 @@ const handleOpenAIResponsesProviderWebSearchMessages = async (c, options) => {
|
|
|
6309
6278
|
});
|
|
6310
6279
|
if (providerConfig.name === "codex") {
|
|
6311
6280
|
const upstreamResponse = await forwardCodexResponses(responsesPayload, c.req.raw.headers, providerConfig.baseUrl);
|
|
6312
|
-
if (isResponsesStream
|
|
6281
|
+
if (isResponsesStream(upstreamResponse)) return respondWebSearchProviderMessagesJson(c, {
|
|
6313
6282
|
body: await collectResponsesStreamResult({
|
|
6314
6283
|
errorMessagePrefix: `${provider} web search responses stream`,
|
|
6315
6284
|
parseEvent: (data) => parseResponsesProviderStreamChunk(data, providerConfig),
|
|
@@ -6370,7 +6339,7 @@ const handleOpenAIResponsesProviderMessages = async (c, options) => {
|
|
|
6370
6339
|
});
|
|
6371
6340
|
if (providerConfig.name === "codex") {
|
|
6372
6341
|
const upstreamResponse = await forwardCodexResponses(responsesPayload, c.req.raw.headers, providerConfig.baseUrl);
|
|
6373
|
-
if (isResponsesStream
|
|
6342
|
+
if (isResponsesStream(upstreamResponse)) {
|
|
6374
6343
|
if (wantsStream) return streamResponsesProviderMessages({
|
|
6375
6344
|
c,
|
|
6376
6345
|
modelConfig,
|
|
@@ -6426,14 +6395,6 @@ const handleOpenAIResponsesProviderMessages = async (c, options) => {
|
|
|
6426
6395
|
providerConfig
|
|
6427
6396
|
});
|
|
6428
6397
|
};
|
|
6429
|
-
const applyModelDefaults = (payload, modelConfig) => {
|
|
6430
|
-
payload.temperature ??= modelConfig?.temperature;
|
|
6431
|
-
payload.top_p ??= modelConfig?.topP;
|
|
6432
|
-
payload.top_k ??= modelConfig?.topK;
|
|
6433
|
-
};
|
|
6434
|
-
const applyMissingExtraBody = (payload, options) => {
|
|
6435
|
-
for (const [key, value] of Object.entries(options.extraBody ?? {})) if (!Object.hasOwn(payload, key)) payload[key] = value;
|
|
6436
|
-
};
|
|
6437
6398
|
const getRequestThinkingBudget = (payload) => {
|
|
6438
6399
|
const budget = payload.thinking?.budget_tokens;
|
|
6439
6400
|
if (typeof budget !== "number" || !Number.isFinite(budget)) return;
|
|
@@ -6646,9 +6607,6 @@ const streamResponsesProviderMessages = ({ c, modelConfig, payload, pricingCurre
|
|
|
6646
6607
|
recordUsage(usage);
|
|
6647
6608
|
});
|
|
6648
6609
|
};
|
|
6649
|
-
const isResponsesStream$1 = (value) => {
|
|
6650
|
-
return Boolean(value) && typeof value[Symbol.asyncIterator] === "function";
|
|
6651
|
-
};
|
|
6652
6610
|
const parseOpenAICompatibleStreamChunk = (data) => {
|
|
6653
6611
|
try {
|
|
6654
6612
|
return JSON.parse(data);
|
|
@@ -6945,7 +6903,7 @@ const handleWithResponsesApi = async (c, anthropicPayload, options) => {
|
|
|
6945
6903
|
transport,
|
|
6946
6904
|
...requestOptions
|
|
6947
6905
|
});
|
|
6948
|
-
if (responsesPayload.stream && isAsyncIterable
|
|
6906
|
+
if (responsesPayload.stream && isAsyncIterable(response)) {
|
|
6949
6907
|
logger.debug("Streaming response from Copilot (Responses API)");
|
|
6950
6908
|
return streamSSE(c, async (stream) => {
|
|
6951
6909
|
const streamState = createResponsesStreamState({ toolSearchName: resolveBridgeToolSearchName(anthropicPayload.tools) });
|
|
@@ -7017,7 +6975,7 @@ const handleWithMessagesApi = async (c, anthropicPayload, options) => {
|
|
|
7017
6975
|
sessionId,
|
|
7018
6976
|
compactType
|
|
7019
6977
|
});
|
|
7020
|
-
if (isAsyncIterable
|
|
6978
|
+
if (isAsyncIterable(response)) {
|
|
7021
6979
|
logger.debug("Streaming response from Copilot (Messages API)");
|
|
7022
6980
|
return streamSSE(c, async (stream) => {
|
|
7023
6981
|
let usage = {};
|
|
@@ -7075,7 +7033,6 @@ const isCopilotContextCacheEligible = (message) => {
|
|
|
7075
7033
|
};
|
|
7076
7034
|
const uniqueIndexes = (indexes) => [...new Set(indexes)];
|
|
7077
7035
|
const isNonStreaming = (response) => Object.hasOwn(response, "choices");
|
|
7078
|
-
const isAsyncIterable$1 = (value) => Boolean(value) && typeof value[Symbol.asyncIterator] === "function";
|
|
7079
7036
|
const createCopilotUsageRecorder = (options) => createCopilotTokenUsageRecorder({
|
|
7080
7037
|
endpoint: options.endpoint,
|
|
7081
7038
|
fallbackSessionId: options.fallbackSessionId,
|
|
@@ -7636,9 +7593,6 @@ const getResponsesStreamEventUsage = (event) => {
|
|
|
7636
7593
|
return null;
|
|
7637
7594
|
};
|
|
7638
7595
|
const getResponsesEvents = (response) => events(response);
|
|
7639
|
-
const isResponsesStream = (value) => {
|
|
7640
|
-
return Boolean(value) && typeof value[Symbol.asyncIterator] === "function";
|
|
7641
|
-
};
|
|
7642
7596
|
//#endregion
|
|
7643
7597
|
//#region src/routes/provider/responses/route.ts
|
|
7644
7598
|
const providerResponsesRoutes = new Hono();
|
|
@@ -7782,7 +7736,6 @@ const handleResponses = async (c) => {
|
|
|
7782
7736
|
});
|
|
7783
7737
|
return c.json(result);
|
|
7784
7738
|
};
|
|
7785
|
-
const isAsyncIterable = (value) => Boolean(value) && typeof value[Symbol.asyncIterator] === "function";
|
|
7786
7739
|
const isStreamingRequested = (payload) => Boolean(payload.stream);
|
|
7787
7740
|
const parseResponsesStreamEvent = (chunk) => {
|
|
7788
7741
|
const data = chunk.data;
|
|
@@ -7964,4 +7917,4 @@ server.route("/:provider/images", providerImageRoutes);
|
|
|
7964
7917
|
//#endregion
|
|
7965
7918
|
export { server };
|
|
7966
7919
|
|
|
7967
|
-
//# sourceMappingURL=server-
|
|
7920
|
+
//# sourceMappingURL=server-DhaNHHv3.js.map
|