@nick3/copilot-api 1.5.3 → 1.5.6
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/LICENSE +1 -1
- package/README.md +26 -3
- package/dist/{account-BMFr8t9b.js → account-AacnHem5.js} +2 -2
- package/dist/{account-BMFr8t9b.js.map → account-AacnHem5.js.map} +1 -1
- package/dist/{accounts-manager-DgQH4KtO.js → accounts-manager-BE-Dq5Wn.js} +76 -31
- package/dist/accounts-manager-BE-Dq5Wn.js.map +1 -0
- package/dist/admin/assets/index-CdoHTemy.css +1 -0
- package/dist/admin/assets/index-wcoGQpIM.js +66 -0
- package/dist/admin/index.html +2 -2
- package/dist/{auth-DipSy-jV.js → auth-B7x3wjry.js} +3 -3
- package/dist/{auth-DipSy-jV.js.map → auth-B7x3wjry.js.map} +1 -1
- package/dist/{check-usage-Dbjs73E0.js → check-usage-B1cbDEOI.js} +3 -3
- package/dist/{check-usage-Dbjs73E0.js.map → check-usage-B1cbDEOI.js.map} +1 -1
- package/dist/{get-copilot-token-DoK8Ia3u.js → get-copilot-token-cha9rQwA.js} +2 -2
- package/dist/{get-copilot-token-DoK8Ia3u.js.map → get-copilot-token-cha9rQwA.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{poll-access-token-BzenaGHn.js → poll-access-token-DFooFWhY.js} +7 -5
- package/dist/poll-access-token-DFooFWhY.js.map +1 -0
- package/dist/{server-DzE_zmUf.js → server-DVpkQrk2.js} +97 -34
- package/dist/server-DVpkQrk2.js.map +1 -0
- package/dist/{start-DEugVHqn.js → start-fPbCDj4c.js} +6 -6
- package/dist/{start-DEugVHqn.js.map → start-fPbCDj4c.js.map} +1 -1
- package/package.json +2 -1
- package/dist/accounts-manager-DgQH4KtO.js.map +0 -1
- package/dist/admin/assets/index-519a65q_.js +0 -66
- package/dist/admin/assets/index-ChMaMig2.css +0 -1
- package/dist/poll-access-token-BzenaGHn.js.map +0 -1
- package/dist/server-DzE_zmUf.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as resolveTraceId, C as normalizeDomain, D as accountFromState, E as prepareMessageProxyHeaders, O as state, T as prepareInteractionHeaders, _ as HTTPError, b as copilotHeaders, c as getRootSessionId, d as parseUserIdMetadata, f as sleep, g as getCopilotUsage, h as getDeviceCode, k as requestContext, l as getUUID, m as getGitHubUser, r as cacheModels, s as generateRequestIdFromPayload, t as pollAccessToken, u as isNullish, v as forwardError, w as prepareForCompact, y as copilotBaseUrl } from "./poll-access-token-
|
|
2
|
-
import { a as getAccountClientIdentityByLoginAndApp, c as listAccountsFromRegistry, f as removeAccountFromRegistry, g as DEFAULT_IDENTITY_ENTERPRISE_DOMAIN, h as saveRegistry, m as saveAccountToken, p as removeAccountToken, r as addAccountToRegistry, t as isAccountType, u as loadRegistry, y as getCurrentIdentityEnvironment } from "./account-
|
|
1
|
+
import { A as resolveTraceId, C as normalizeDomain, D as accountFromState, E as prepareMessageProxyHeaders, O as state, T as prepareInteractionHeaders, _ as HTTPError, b as copilotHeaders, c as getRootSessionId, d as parseUserIdMetadata, f as sleep, g as getCopilotUsage, h as getDeviceCode, k as requestContext, l as getUUID, m as getGitHubUser, r as cacheModels, s as generateRequestIdFromPayload, t as pollAccessToken, u as isNullish, v as forwardError, w as prepareForCompact, y as copilotBaseUrl } from "./poll-access-token-DFooFWhY.js";
|
|
2
|
+
import { a as getAccountClientIdentityByLoginAndApp, c as listAccountsFromRegistry, f as removeAccountFromRegistry, g as DEFAULT_IDENTITY_ENTERPRISE_DOMAIN, h as saveRegistry, m as saveAccountToken, p as removeAccountToken, r as addAccountToRegistry, t as isAccountType, u as loadRegistry, y as getCurrentIdentityEnvironment } from "./account-AacnHem5.js";
|
|
3
3
|
import { r as ensurePaths, t as PATHS } from "./paths-DGlr310R.js";
|
|
4
|
-
import "./get-copilot-token-
|
|
5
|
-
import { _ as isMessagesApiEnabled, a as getClaudeTokenMultiplier, b as mergeConfigWithDefaults, c as getModelAliases, d as getProviderConfig, f as getReasoningEffortForModel, g as isMessageStartInputTokensFallbackEnabled, h as isForceAgentEnabled, i as getAnthropicApiKey, l as getModelAliasesInfo, m as isAccountAffinityEnabled, n as PROVIDER_TYPE_ANTHROPIC, o as getConfig, p as getSmallModel, r as getAliasTargetSet, s as getExtraPromptForModel, t as accountsManager, u as getModelRefreshIntervalMs, v as isResponsesApiContextManagementModel, x as shouldCompactUseSmallModel, y as isResponsesApiWebSearchEnabled } from "./accounts-manager-
|
|
4
|
+
import "./get-copilot-token-cha9rQwA.js";
|
|
5
|
+
import { _ as isMessagesApiEnabled, a as getClaudeTokenMultiplier, b as mergeConfigWithDefaults, c as getModelAliases, d as getProviderConfig, f as getReasoningEffortForModel, g as isMessageStartInputTokensFallbackEnabled, h as isForceAgentEnabled, i as getAnthropicApiKey, l as getModelAliasesInfo, m as isAccountAffinityEnabled, n as PROVIDER_TYPE_ANTHROPIC, o as getConfig, p as getSmallModel, r as getAliasTargetSet, s as getExtraPromptForModel, t as accountsManager, u as getModelRefreshIntervalMs, v as isResponsesApiContextManagementModel, x as shouldCompactUseSmallModel, y as isResponsesApiWebSearchEnabled } from "./accounts-manager-BE-Dq5Wn.js";
|
|
6
6
|
import consola from "consola";
|
|
7
7
|
import fs, { readFile } from "node:fs/promises";
|
|
8
8
|
import { randomUUID, timingSafeEqual } from "node:crypto";
|
|
@@ -232,7 +232,7 @@ function migrateV1(db) {
|
|
|
232
232
|
}
|
|
233
233
|
function migrateAdminDb(db) {
|
|
234
234
|
const current = db.query("PRAGMA user_version;").get()?.user_version ?? 0;
|
|
235
|
-
if (current >=
|
|
235
|
+
if (current >= 6) return;
|
|
236
236
|
if (current < 1) migrateV1(db);
|
|
237
237
|
if (current < 2) db.run(`
|
|
238
238
|
ALTER TABLE request_log ADD COLUMN user_id TEXT;
|
|
@@ -274,6 +274,10 @@ function migrateAdminDb(db) {
|
|
|
274
274
|
|
|
275
275
|
PRAGMA user_version = 5;
|
|
276
276
|
`);
|
|
277
|
+
if (current < 6) {
|
|
278
|
+
if (!db.query("PRAGMA table_info(request_log);").all().some((row) => row.name === "is_subagent")) db.run("ALTER TABLE request_log ADD COLUMN is_subagent INTEGER;");
|
|
279
|
+
db.run("PRAGMA user_version = 6;");
|
|
280
|
+
}
|
|
277
281
|
}
|
|
278
282
|
|
|
279
283
|
//#endregion
|
|
@@ -407,6 +411,7 @@ var RequestHistoryStore = class {
|
|
|
407
411
|
safety_identifier,
|
|
408
412
|
prompt_cache_key,
|
|
409
413
|
initiator,
|
|
414
|
+
is_subagent,
|
|
410
415
|
upstream_request_id,
|
|
411
416
|
tokens_input,
|
|
412
417
|
tokens_output,
|
|
@@ -430,7 +435,7 @@ var RequestHistoryStore = class {
|
|
|
430
435
|
?,?,?,?,?,?,?,?,
|
|
431
436
|
?,?,?,?,?,?,?,?,
|
|
432
437
|
?,?,?,?,?,?,?,?,
|
|
433
|
-
|
|
438
|
+
?,?,?,?,?,?,?,?
|
|
434
439
|
);
|
|
435
440
|
`);
|
|
436
441
|
this.getByRequestIdStmt = db.query("SELECT * FROM request_log WHERE request_id = ? LIMIT 1;");
|
|
@@ -474,6 +479,7 @@ var RequestHistoryStore = class {
|
|
|
474
479
|
toDbNull(record.safetyIdentifier),
|
|
475
480
|
toDbNull(record.promptCacheKey),
|
|
476
481
|
toDbNull(record.initiator),
|
|
482
|
+
toDbBool(record.isSubagent),
|
|
477
483
|
toDbNull(record.upstreamRequestId),
|
|
478
484
|
toDbNull(record.tokensInput),
|
|
479
485
|
toDbNull(record.tokensOutput),
|
|
@@ -812,6 +818,7 @@ var AuthSessionManager = class {
|
|
|
812
818
|
});
|
|
813
819
|
}
|
|
814
820
|
if (!this.getLiveSession(sessionId)) return;
|
|
821
|
+
await accountsManager.reloadRegistryNow();
|
|
815
822
|
this.completeSession(sessionId, accountId);
|
|
816
823
|
} catch (error) {
|
|
817
824
|
if (session.abortController.signal.aborted) return;
|
|
@@ -1001,13 +1008,20 @@ const PROVIDER_MODEL_CONFIG_KEYS = new Set([
|
|
|
1001
1008
|
"topP",
|
|
1002
1009
|
"topK"
|
|
1003
1010
|
]);
|
|
1004
|
-
const
|
|
1011
|
+
const PROVIDER_CONFIG_FIELDS = [
|
|
1005
1012
|
"type",
|
|
1006
1013
|
"enabled",
|
|
1007
1014
|
"baseUrl",
|
|
1008
1015
|
"apiKey",
|
|
1009
|
-
"
|
|
1010
|
-
|
|
1016
|
+
"authType",
|
|
1017
|
+
"models",
|
|
1018
|
+
"adjustInputTokens"
|
|
1019
|
+
];
|
|
1020
|
+
const PROVIDER_AUTH_TYPES = ["authorization", "x-api-key"];
|
|
1021
|
+
const PROVIDER_CONFIG_KEYS = new Set(PROVIDER_CONFIG_FIELDS);
|
|
1022
|
+
function isProviderAuthType(value) {
|
|
1023
|
+
return PROVIDER_AUTH_TYPES.includes(value);
|
|
1024
|
+
}
|
|
1011
1025
|
function validateAllowedObjectKeys(value, field, allowed) {
|
|
1012
1026
|
for (const key of Object.keys(value)) if (!allowed.has(key)) return `${field}.${key} is not supported`;
|
|
1013
1027
|
}
|
|
@@ -1087,12 +1101,27 @@ function applyProviderApiKey(provider, value, field) {
|
|
|
1087
1101
|
if ("error" in parsed) return parsed.error;
|
|
1088
1102
|
if ("value" in parsed) provider.apiKey = parsed.value;
|
|
1089
1103
|
}
|
|
1104
|
+
function applyProviderAuthType(provider, value, field) {
|
|
1105
|
+
if (!Object.hasOwn(value, "authType")) return void 0;
|
|
1106
|
+
const parsed = parseOptionalString(value.authType, `${field}.authType`);
|
|
1107
|
+
if ("error" in parsed) return parsed.error;
|
|
1108
|
+
if ("value" in parsed) {
|
|
1109
|
+
if (!isProviderAuthType(parsed.value)) return `${field}.authType must be one of: ${PROVIDER_AUTH_TYPES.map((item) => `"${item}"`).join(", ")}`;
|
|
1110
|
+
provider.authType = parsed.value;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1090
1113
|
function applyProviderModels(provider, value, field) {
|
|
1091
1114
|
if (!Object.hasOwn(value, "models")) return void 0;
|
|
1092
1115
|
const parsed = parseProviderModelsRecord(value.models, `${field}.models`);
|
|
1093
1116
|
if ("error" in parsed) return parsed.error;
|
|
1094
1117
|
if ("value" in parsed) provider.models = parsed.value;
|
|
1095
1118
|
}
|
|
1119
|
+
function applyProviderAdjustInputTokens(provider, value, field) {
|
|
1120
|
+
if (!Object.hasOwn(value, "adjustInputTokens")) return void 0;
|
|
1121
|
+
const parsed = parseOptionalBoolean(value.adjustInputTokens, `${field}.adjustInputTokens`);
|
|
1122
|
+
if ("error" in parsed) return parsed.error;
|
|
1123
|
+
if ("value" in parsed) provider.adjustInputTokens = parsed.value;
|
|
1124
|
+
}
|
|
1096
1125
|
function parseProviderConfig(value, field) {
|
|
1097
1126
|
if (value === null || value === void 0) return { error: `${field} must be an object` };
|
|
1098
1127
|
if (!isPlainObject(value)) return { error: `${field} must be an object` };
|
|
@@ -1107,8 +1136,12 @@ function parseProviderConfig(value, field) {
|
|
|
1107
1136
|
if (baseUrlError) return { error: baseUrlError };
|
|
1108
1137
|
const apiKeyError = applyProviderApiKey(provider, value, field);
|
|
1109
1138
|
if (apiKeyError) return { error: apiKeyError };
|
|
1139
|
+
const authTypeError = applyProviderAuthType(provider, value, field);
|
|
1140
|
+
if (authTypeError) return { error: authTypeError };
|
|
1110
1141
|
const modelsError = applyProviderModels(provider, value, field);
|
|
1111
1142
|
if (modelsError) return { error: modelsError };
|
|
1143
|
+
const adjustInputTokensError = applyProviderAdjustInputTokens(provider, value, field);
|
|
1144
|
+
if (adjustInputTokensError) return { error: adjustInputTokensError };
|
|
1112
1145
|
return { value: provider };
|
|
1113
1146
|
}
|
|
1114
1147
|
function parseProviders(value) {
|
|
@@ -3578,7 +3611,7 @@ const isWarmupProbeRequest = (payload) => {
|
|
|
3578
3611
|
return false;
|
|
3579
3612
|
};
|
|
3580
3613
|
const handleSelectionFailure = (context) => {
|
|
3581
|
-
const { c, store, requestId, startedAtMs, method, path: path$2, streamRequested, clientModel, clientIp, clientIpSource, userAgent, userId, safetyIdentifier, promptCacheKey, initiator, selection } = context;
|
|
3614
|
+
const { c, store, requestId, startedAtMs, method, path: path$2, streamRequested, clientModel, clientIp, clientIpSource, userAgent, userId, safetyIdentifier, promptCacheKey, initiator, isSubagent, selection } = context;
|
|
3582
3615
|
const finishedAtMs = Date.now();
|
|
3583
3616
|
store.insert({
|
|
3584
3617
|
requestId,
|
|
@@ -3596,6 +3629,7 @@ const handleSelectionFailure = (context) => {
|
|
|
3596
3629
|
safetyIdentifier,
|
|
3597
3630
|
promptCacheKey,
|
|
3598
3631
|
initiator,
|
|
3632
|
+
isSubagent,
|
|
3599
3633
|
httpStatus: selection.reason === "MODEL_NOT_SUPPORTED" ? 400 : 429,
|
|
3600
3634
|
selectionFailureReason: selection.reason
|
|
3601
3635
|
});
|
|
@@ -5191,6 +5225,7 @@ function closeThinkingBlockIfOpen(state$1, events$1) {
|
|
|
5191
5225
|
//#endregion
|
|
5192
5226
|
//#region src/routes/messages/subagent-marker.ts
|
|
5193
5227
|
const subagentMarkerPrefix = "__SUBAGENT_MARKER__";
|
|
5228
|
+
const REMINDER_RE = /<system-reminder>([\s\S]*?)<\/system-reminder>/g;
|
|
5194
5229
|
const parseSubagentMarkerFromFirstUser = (payload) => {
|
|
5195
5230
|
const firstUserMessage = payload.messages.find((msg) => msg.role === "user" && Array.isArray(msg.content));
|
|
5196
5231
|
if (!firstUserMessage || !Array.isArray(firstUserMessage.content)) return null;
|
|
@@ -5202,33 +5237,54 @@ const parseSubagentMarkerFromFirstUser = (payload) => {
|
|
|
5202
5237
|
return null;
|
|
5203
5238
|
};
|
|
5204
5239
|
const parseSubagentMarkerFromSystemReminder = (text) => {
|
|
5205
|
-
const
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
searchFrom = reminderEnd + 18;
|
|
5240
|
+
for (const [, content] of text.matchAll(REMINDER_RE)) {
|
|
5241
|
+
const markerIndex = content.indexOf(subagentMarkerPrefix);
|
|
5242
|
+
if (markerIndex === -1) continue;
|
|
5243
|
+
const afterPrefix = content.slice(markerIndex + 19).trimStart();
|
|
5244
|
+
if (!afterPrefix.startsWith("{")) continue;
|
|
5245
|
+
const json = extractBalancedJson(afterPrefix);
|
|
5246
|
+
if (!json) continue;
|
|
5247
|
+
try {
|
|
5248
|
+
const parsed = JSON.parse(json);
|
|
5249
|
+
if (!parsed.session_id || !parsed.agent_id || !parsed.agent_type) continue;
|
|
5250
|
+
return parsed;
|
|
5251
|
+
} catch {
|
|
5218
5252
|
continue;
|
|
5219
5253
|
}
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5254
|
+
}
|
|
5255
|
+
return null;
|
|
5256
|
+
};
|
|
5257
|
+
/** Extract the first balanced `{...}` object from text that starts with `{`. */
|
|
5258
|
+
const extractBalancedJson = (text) => {
|
|
5259
|
+
let depth = 0;
|
|
5260
|
+
let inString = false;
|
|
5261
|
+
let escaped = false;
|
|
5262
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
5263
|
+
const char = text[index];
|
|
5264
|
+
if (inString) {
|
|
5265
|
+
if (escaped) {
|
|
5266
|
+
escaped = false;
|
|
5225
5267
|
continue;
|
|
5226
5268
|
}
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5269
|
+
if (char === "\\") {
|
|
5270
|
+
escaped = true;
|
|
5271
|
+
continue;
|
|
5272
|
+
}
|
|
5273
|
+
if (char === "\"") inString = false;
|
|
5274
|
+
continue;
|
|
5275
|
+
}
|
|
5276
|
+
if (char === "\"") {
|
|
5277
|
+
inString = true;
|
|
5230
5278
|
continue;
|
|
5231
5279
|
}
|
|
5280
|
+
if (char === "{") {
|
|
5281
|
+
depth += 1;
|
|
5282
|
+
continue;
|
|
5283
|
+
}
|
|
5284
|
+
if (char === "}") {
|
|
5285
|
+
depth -= 1;
|
|
5286
|
+
if (depth === 0) return text.slice(0, index + 1);
|
|
5287
|
+
}
|
|
5232
5288
|
}
|
|
5233
5289
|
return null;
|
|
5234
5290
|
};
|
|
@@ -5289,7 +5345,8 @@ async function handleCompletion(c) {
|
|
|
5289
5345
|
userId,
|
|
5290
5346
|
safetyIdentifier: normalizedSafetyIdentifier,
|
|
5291
5347
|
promptCacheKey: normalizedPromptCacheKey,
|
|
5292
|
-
initiator: initiatorOverride
|
|
5348
|
+
initiator: initiatorOverride,
|
|
5349
|
+
isSubagent: Boolean(subagentMarker)
|
|
5293
5350
|
});
|
|
5294
5351
|
if (blockedResponse) return blockedResponse;
|
|
5295
5352
|
const openAIPayload = translateToOpenAI(anthropicPayload);
|
|
@@ -5326,6 +5383,7 @@ async function handleCompletion(c) {
|
|
|
5326
5383
|
safetyIdentifier: normalizedSafetyIdentifier,
|
|
5327
5384
|
promptCacheKey: normalizedPromptCacheKey,
|
|
5328
5385
|
initiator: fallbackInitiator,
|
|
5386
|
+
isSubagent: Boolean(subagentMarker),
|
|
5329
5387
|
selection
|
|
5330
5388
|
});
|
|
5331
5389
|
const { account, reservation, selectedModel, endpoint, costUnits } = selection;
|
|
@@ -5346,6 +5404,7 @@ async function handleCompletion(c) {
|
|
|
5346
5404
|
userId,
|
|
5347
5405
|
safetyIdentifier: normalizedSafetyIdentifier,
|
|
5348
5406
|
promptCacheKey: normalizedPromptCacheKey,
|
|
5407
|
+
isSubagent: Boolean(subagentMarker),
|
|
5349
5408
|
clientModel,
|
|
5350
5409
|
account,
|
|
5351
5410
|
reservation,
|
|
@@ -5501,6 +5560,7 @@ function insertRequestLog$1(instr, record) {
|
|
|
5501
5560
|
safetyIdentifier: instr.safetyIdentifier,
|
|
5502
5561
|
promptCacheKey: instr.promptCacheKey,
|
|
5503
5562
|
initiator: instr.initiator,
|
|
5563
|
+
isSubagent: instr.isSubagent,
|
|
5504
5564
|
upstreamRequestId: instr.upstreamRequestId,
|
|
5505
5565
|
affinityHit: instr.affinityHit,
|
|
5506
5566
|
affinityCacheKey: instr.affinityCacheKey,
|
|
@@ -6077,10 +6137,13 @@ const STRIPPED_RESPONSE_HEADERS = [
|
|
|
6077
6137
|
"upgrade"
|
|
6078
6138
|
];
|
|
6079
6139
|
function buildProviderUpstreamHeaders(providerConfig, requestHeaders) {
|
|
6140
|
+
const authHeaders = {};
|
|
6141
|
+
if (providerConfig.authType === "authorization") authHeaders.authorization = `Bearer ${providerConfig.apiKey}`;
|
|
6142
|
+
else authHeaders["x-api-key"] = providerConfig.apiKey;
|
|
6080
6143
|
const headers = {
|
|
6081
6144
|
"content-type": "application/json",
|
|
6082
6145
|
accept: "application/json",
|
|
6083
|
-
|
|
6146
|
+
...authHeaders
|
|
6084
6147
|
};
|
|
6085
6148
|
for (const headerName of FORWARDABLE_HEADERS) {
|
|
6086
6149
|
const headerValue = requestHeaders.get(headerName);
|
|
@@ -6831,4 +6894,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
|
|
|
6831
6894
|
|
|
6832
6895
|
//#endregion
|
|
6833
6896
|
export { server };
|
|
6834
|
-
//# sourceMappingURL=server-
|
|
6897
|
+
//# sourceMappingURL=server-DVpkQrk2.js.map
|