@jeffreycao/copilot-api 2.2.13 → 2.2.14
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/main.js +1 -1
- package/dist/{server-Bmd_z-tv.js → server-B3NoF9oG.js} +43 -19
- package/dist/server-B3NoF9oG.js.map +1 -0
- package/dist/{start-z_xmbJbc.js → start-HHr2HlXT.js} +2 -2
- package/dist/{start-z_xmbJbc.js.map → start-HHr2HlXT.js.map} +1 -1
- package/package.json +1 -1
- package/dist/server-Bmd_z-tv.js.map +0 -1
package/dist/main.js
CHANGED
|
@@ -30,7 +30,7 @@ if (isMcpFastPath(process.argv)) {
|
|
|
30
30
|
const { auth } = await import("./auth-C-RWNXGU.js");
|
|
31
31
|
const { debug } = await import("./debug-41w6Whae.js");
|
|
32
32
|
const { mcp } = await import("./mcp-fpSlKZxK.js");
|
|
33
|
-
const { start } = await import("./start-
|
|
33
|
+
const { start } = await import("./start-HHr2HlXT.js");
|
|
34
34
|
await runMain(defineCommand({
|
|
35
35
|
meta: {
|
|
36
36
|
name: "copilot-api",
|
|
@@ -374,6 +374,21 @@ async function resolveProviderConfig(providerName) {
|
|
|
374
374
|
}
|
|
375
375
|
return getProviderConfig(normalizedProviderName);
|
|
376
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Returns the parsed "provider/model" alias only when that provider is
|
|
379
|
+
* actually configured, otherwise null so the caller falls through to its
|
|
380
|
+
* default flow. GitHub Copilot enterprise models can ship with namespaced ids
|
|
381
|
+
* such as "org/family/model": without this check the first segment is
|
|
382
|
+
* misrouted to a non-existent provider and surfaced as a 400/404.
|
|
383
|
+
*/
|
|
384
|
+
async function ensureConfiguredProviderModelAlias(alias, resolveConfig = resolveProviderConfig) {
|
|
385
|
+
if (!alias) return null;
|
|
386
|
+
return await resolveConfig(alias.provider) ? alias : null;
|
|
387
|
+
}
|
|
388
|
+
/** parseProviderModelAlias + ensureConfiguredProviderModelAlias. */
|
|
389
|
+
async function resolveConfiguredProviderModelAlias(model, resolveConfig = resolveProviderConfig) {
|
|
390
|
+
return ensureConfiguredProviderModelAlias(parseProviderModelAlias(model), resolveConfig);
|
|
391
|
+
}
|
|
377
392
|
//#endregion
|
|
378
393
|
//#region src/lib/event-bus.ts
|
|
379
394
|
var EventBus = class {
|
|
@@ -2845,10 +2860,12 @@ async function handleAlphaSearchRequest(c, resolvedProviderConfig) {
|
|
|
2845
2860
|
}
|
|
2846
2861
|
}
|
|
2847
2862
|
const fallbackRequestedModel = messagesBackedModel ? payload.model : requestedModel;
|
|
2848
|
-
if (providerModelAlias)
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2863
|
+
if (providerModelAlias) {
|
|
2864
|
+
if (await ensureConfiguredProviderModelAlias(providerModelAlias, alphaSearchRouteDependencies.resolveProviderConfig)) return await alphaSearchRouteDependencies.handleAlphaSearchResponses(c, {
|
|
2865
|
+
provider: providerModelAlias.provider,
|
|
2866
|
+
request: payload
|
|
2867
|
+
});
|
|
2868
|
+
}
|
|
2852
2869
|
return await alphaSearchRouteDependencies.handleAlphaSearchResponses(c, { request: {
|
|
2853
2870
|
...payload,
|
|
2854
2871
|
model: fallbackRequestedModel
|
|
@@ -3127,7 +3144,7 @@ async function handleCompletion$1(c) {
|
|
|
3127
3144
|
const requestedModel = payload.model;
|
|
3128
3145
|
payload.model = resolveMappedModel(payload.model);
|
|
3129
3146
|
if (payload.model !== requestedModel) consola.debug(`Resolved model mapping: ${requestedModel} -> ${payload.model}`);
|
|
3130
|
-
const providerModelAlias =
|
|
3147
|
+
const providerModelAlias = await resolveConfiguredProviderModelAlias(payload.model);
|
|
3131
3148
|
if (providerModelAlias) {
|
|
3132
3149
|
payload.model = providerModelAlias.model;
|
|
3133
3150
|
return await handleProviderChatCompletionsForProvider(c, {
|
|
@@ -4419,7 +4436,7 @@ async function handleCountTokens(c) {
|
|
|
4419
4436
|
const anthropicPayload = await c.req.json();
|
|
4420
4437
|
anthropicPayload.model = resolveMappedModel(anthropicPayload.model);
|
|
4421
4438
|
normalizeSystemMessages(anthropicPayload);
|
|
4422
|
-
const providerModelAlias =
|
|
4439
|
+
const providerModelAlias = await resolveConfiguredProviderModelAlias(anthropicPayload.model);
|
|
4423
4440
|
if (providerModelAlias) {
|
|
4424
4441
|
anthropicPayload.model = providerModelAlias.model;
|
|
4425
4442
|
return await handleProviderCountTokensForProvider(c, {
|
|
@@ -6144,6 +6161,7 @@ const containsVisionContent = (value) => {
|
|
|
6144
6161
|
//#region src/routes/messages/web-search/fulfill.ts
|
|
6145
6162
|
const webSearchFlowDependencies = {
|
|
6146
6163
|
createResponses,
|
|
6164
|
+
resolveProviderConfig,
|
|
6147
6165
|
createUsageRecorder: (payload, sessionId, webSearchModel) => createCopilotTokenUsageRecorder({
|
|
6148
6166
|
endpoint: "responses",
|
|
6149
6167
|
fallbackSessionId: sessionId,
|
|
@@ -6165,14 +6183,17 @@ const stripWebSearchServerTool = (payload) => {
|
|
|
6165
6183
|
if (!Array.isArray(payload.tools)) return;
|
|
6166
6184
|
payload.tools = payload.tools.filter((tool) => !isWebSearchServerTool(tool));
|
|
6167
6185
|
};
|
|
6168
|
-
const resolveWebSearchRoute = (payload, options) => {
|
|
6186
|
+
const resolveWebSearchRoute = async (payload, options) => {
|
|
6169
6187
|
const { webSearchModel, responsesWebSearchEnabled } = options;
|
|
6170
6188
|
if (!webSearchModel || !isWebSearchOnlyRequest(payload)) return { kind: "strip" };
|
|
6171
6189
|
const alias = parseProviderModelAlias(webSearchModel);
|
|
6172
|
-
if (alias)
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6190
|
+
if (alias) {
|
|
6191
|
+
const configuredAlias = await ensureConfiguredProviderModelAlias(alias, options.resolveProviderConfig ?? resolveProviderConfig);
|
|
6192
|
+
return configuredAlias ? {
|
|
6193
|
+
kind: "provider",
|
|
6194
|
+
alias: configuredAlias
|
|
6195
|
+
} : { kind: "strip" };
|
|
6196
|
+
}
|
|
6176
6197
|
if (responsesWebSearchEnabled) return {
|
|
6177
6198
|
kind: "responses",
|
|
6178
6199
|
model: webSearchModel
|
|
@@ -6274,9 +6295,10 @@ const createUsageRecorder = (payload, sessionId, webSearchModel) => webSearchFlo
|
|
|
6274
6295
|
const tryHandleWebSearch = async (c, payload, options) => {
|
|
6275
6296
|
if (!hasWebSearchServerTool(payload)) return null;
|
|
6276
6297
|
normalizeSystemMessages(payload);
|
|
6277
|
-
const route = resolveWebSearchRoute(payload, {
|
|
6298
|
+
const route = await resolveWebSearchRoute(payload, {
|
|
6278
6299
|
webSearchModel: getMessageApiWebSearchModel(),
|
|
6279
|
-
responsesWebSearchEnabled: isResponsesApiWebSearchEnabled()
|
|
6300
|
+
responsesWebSearchEnabled: isResponsesApiWebSearchEnabled(),
|
|
6301
|
+
resolveProviderConfig: webSearchFlowDependencies.resolveProviderConfig
|
|
6280
6302
|
});
|
|
6281
6303
|
if (route.kind === "provider") {
|
|
6282
6304
|
payload.model = route.alias.model;
|
|
@@ -7560,7 +7582,7 @@ async function handleCompletionPayload(c, anthropicPayload, dispatchOptions = {}
|
|
|
7560
7582
|
consola.debug(`Claude auto model override: ${anthropicPayload.model} -> ${claudeAutoModel}`);
|
|
7561
7583
|
anthropicPayload.model = claudeAutoModel;
|
|
7562
7584
|
}
|
|
7563
|
-
const providerModelAlias =
|
|
7585
|
+
const providerModelAlias = await resolveConfiguredProviderModelAlias(anthropicPayload.model, providerMessagesHandlerDependencies.resolveProviderConfig);
|
|
7564
7586
|
if (providerModelAlias) {
|
|
7565
7587
|
anthropicPayload.model = providerModelAlias.model;
|
|
7566
7588
|
return await handleProviderMessagesForProvider(c, {
|
|
@@ -9148,12 +9170,14 @@ function appendUserBlock(messages, block) {
|
|
|
9148
9170
|
};
|
|
9149
9171
|
messages.push(message);
|
|
9150
9172
|
}
|
|
9151
|
-
function parseFunctionArguments(value,
|
|
9173
|
+
function parseFunctionArguments(value, _path) {
|
|
9152
9174
|
try {
|
|
9153
9175
|
const parsed = JSON.parse(value);
|
|
9154
9176
|
if (isRecord(parsed)) return parsed;
|
|
9155
|
-
} catch {
|
|
9156
|
-
|
|
9177
|
+
} catch {
|
|
9178
|
+
return {};
|
|
9179
|
+
}
|
|
9180
|
+
return {};
|
|
9157
9181
|
}
|
|
9158
9182
|
function parseDataUrl(value) {
|
|
9159
9183
|
const match = /^data:([^;,]+);base64,(.*)$/su.exec(value);
|
|
@@ -10315,7 +10339,7 @@ const handleResponses = async (c) => {
|
|
|
10315
10339
|
const requestedModel = payload.model;
|
|
10316
10340
|
payload.model = responsesHandlerDependencies.resolveMappedModel(payload.model);
|
|
10317
10341
|
if (payload.model !== requestedModel) consola.debug(`Resolved model mapping: ${requestedModel} -> ${payload.model}`);
|
|
10318
|
-
const providerModelAlias =
|
|
10342
|
+
const providerModelAlias = await resolveConfiguredProviderModelAlias(payload.model, providerResponsesHandlerDependencies.resolveProviderConfig);
|
|
10319
10343
|
if (providerModelAlias) {
|
|
10320
10344
|
payload.model = providerModelAlias.model;
|
|
10321
10345
|
return await handleProviderResponsesForProvider(c, {
|
|
@@ -10622,4 +10646,4 @@ server.route("/:provider/images", providerImageRoutes);
|
|
|
10622
10646
|
//#endregion
|
|
10623
10647
|
export { server };
|
|
10624
10648
|
|
|
10625
|
-
//# sourceMappingURL=server-
|
|
10649
|
+
//# sourceMappingURL=server-B3NoF9oG.js.map
|