@nick3/copilot-api 1.6.5 → 1.6.9

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.
Files changed (28) hide show
  1. package/dist/{account-Db80RUHX.js → account-B4EBsn8H.js} +2 -2
  2. package/dist/{account-Db80RUHX.js.map → account-B4EBsn8H.js.map} +1 -1
  3. package/dist/{accounts-manager-B4eOuKSK.js → accounts-manager-BNVadA3o.js} +9 -6
  4. package/dist/accounts-manager-BNVadA3o.js.map +1 -0
  5. package/dist/admin/assets/{index-CH72K8cb.js → index-8eGib92I.js} +20 -20
  6. package/dist/admin/index.html +1 -1
  7. package/dist/{auth-Ba8K-1aX.js → auth-xiepl3lk.js} +3 -3
  8. package/dist/{auth-Ba8K-1aX.js.map → auth-xiepl3lk.js.map} +1 -1
  9. package/dist/{check-usage-ChbkyMqB.js → check-usage-3sFXqP0F.js} +3 -3
  10. package/dist/{check-usage-ChbkyMqB.js.map → check-usage-3sFXqP0F.js.map} +1 -1
  11. package/dist/{get-copilot-token-Buo3CA1x.js → get-copilot-token-COIPGosP.js} +2 -2
  12. package/dist/{get-copilot-token-Buo3CA1x.js.map → get-copilot-token-COIPGosP.js.map} +1 -1
  13. package/dist/main.js +3 -3
  14. package/dist/{poll-access-token-tKPQmH_6.js → poll-access-token-c2IYJJHM.js} +6 -2
  15. package/dist/poll-access-token-c2IYJJHM.js.map +1 -0
  16. package/dist/{request-outbound-IimJTlvY.js → request-outbound-DhI9-SrV.js} +1 -1
  17. package/dist/{request-outbound-C0g49Ab6.js → request-outbound-qyTeXbzy.js} +11 -5
  18. package/dist/request-outbound-qyTeXbzy.js.map +1 -0
  19. package/dist/{server-kG7N_-Aj.js → server-BhOhCgni.js} +71 -7
  20. package/dist/server-BhOhCgni.js.map +1 -0
  21. package/dist/{start-CXd89Ylu.js → start-DRl19gqI.js} +8 -7
  22. package/dist/start-DRl19gqI.js.map +1 -0
  23. package/package.json +1 -1
  24. package/dist/accounts-manager-B4eOuKSK.js.map +0 -1
  25. package/dist/poll-access-token-tKPQmH_6.js.map +0 -1
  26. package/dist/request-outbound-C0g49Ab6.js.map +0 -1
  27. package/dist/server-kG7N_-Aj.js.map +0 -1
  28. package/dist/start-CXd89Ylu.js.map +0 -1
@@ -1,9 +1,9 @@
1
- import { A as captureOutboundHeadersSnapshot, D as prepareMessageProxyHeaders, E as prepareInteractionHeaders, M as requestContext, N as resolveTraceId, O as accountFromState, T as prepareForCompact, _ as HTTPError, b as copilotHeaders, c as getUUID, d as parseUserIdMetadata, f as resolveAffinityKey, g as getCopilotUsage, h as getDeviceCode, k as state, l as isNullish, m as getGitHubUser, o as generateRequestIdFromPayload, p as sleep, s as getRootSessionId, t as pollAccessToken, u as normalizeStableSessionId, v as forwardError, w as normalizeDomain, y as copilotBaseUrl } from "./poll-access-token-tKPQmH_6.js";
2
- import { _ as DEFAULT_IDENTITY_ENTERPRISE_DOMAIN, a as getAccountClientIdentityByLoginAndApp, b as getCurrentIdentityEnvironment, d as loadRegistry, g as saveRegistry, h as saveAccountToken, l as listAccountsFromRegistry, m as removeAccountToken, p as removeAccountFromRegistry, r as addAccountToRegistry, t as isAccountType } from "./account-Db80RUHX.js";
1
+ import { A as captureOutboundHeadersSnapshot, D as prepareMessageProxyHeaders, E as prepareInteractionHeaders, M as requestContext, N as resolveTraceId, O as accountFromState, T as prepareForCompact, _ as HTTPError, b as copilotHeaders, c as getUUID, d as parseUserIdMetadata, f as resolveAffinityKey, g as getCopilotUsage, h as getDeviceCode, k as state, l as isNullish, m as getGitHubUser, o as generateRequestIdFromPayload, p as sleep, s as getRootSessionId, t as pollAccessToken, u as normalizeStableSessionId, v as forwardError, w as normalizeDomain, y as copilotBaseUrl } from "./poll-access-token-c2IYJJHM.js";
2
+ import { _ as DEFAULT_IDENTITY_ENTERPRISE_DOMAIN, a as getAccountClientIdentityByLoginAndApp, b as getCurrentIdentityEnvironment, d as loadRegistry, g as saveRegistry, h as saveAccountToken, l as listAccountsFromRegistry, m as removeAccountToken, p as removeAccountFromRegistry, r as addAccountToRegistry, t as isAccountType } from "./account-B4EBsn8H.js";
3
3
  import { r as ensurePaths, t as PATHS } from "./paths-DGlr310R.js";
4
- import "./get-copilot-token-Buo3CA1x.js";
5
- import { i as getRequestOutboundStore, r as getRedactedHeaderKeys } from "./request-outbound-C0g49Ab6.js";
6
- import { A as isMessageStartInputTokensFallbackEnabled, C as getModelAliasesInfo, D as getSmallModel, E as getReasoningEffortForModel, F as resolveModelAlias, I as shouldCompactUseSmallModel, M as isResponsesApiContextManagementModel, N as isResponsesApiWebSearchEnabled, O as isAccountAffinityEnabled, P as mergeConfigWithDefaults, S as getModelAliases, T as getProviderConfig, _ as getAnthropicApiKey, a as getClientIpInfo, b as getExtraPromptForModel, c as normalizeChatCompletionsUsage, d as toLocalDateString, f as copilotFetch, g as getAliasTargetSet, h as PROVIDER_TYPE_ANTHROPIC, i as extractResponsesUsageFromStreamEvent, j as isMessagesApiEnabled, k as isForceAgentEnabled, l as normalizeEmbeddingsUsage, m as isDevModeEnabled, n as applySharedSessionAffinityRetention, o as getRequestHistoryStore, p as flushPendingCapture, r as extractResponsesUsageFromResult, s as getStatsStore, t as accountsManager, u as normalizeMessagesUsage, v as getClaudeTokenMultiplier, w as getModelRefreshIntervalMs, x as getLogLevel, y as getConfig } from "./accounts-manager-B4eOuKSK.js";
4
+ import "./get-copilot-token-COIPGosP.js";
5
+ import { i as getRequestOutboundStore, r as getRedactedHeaderKeys } from "./request-outbound-qyTeXbzy.js";
6
+ import { A as isMessageStartInputTokensFallbackEnabled, C as getModelAliasesInfo, D as getSmallModel, E as getReasoningEffortForModel, F as resolveModelAlias, I as shouldCompactUseSmallModel, M as isResponsesApiContextManagementModel, N as isResponsesApiWebSearchEnabled, O as isAccountAffinityEnabled, P as mergeConfigWithDefaults, S as getModelAliases, T as getProviderConfig, _ as getAnthropicApiKey, a as getClientIpInfo, b as getExtraPromptForModel, c as normalizeChatCompletionsUsage, d as toLocalDateString, f as copilotFetch, g as getAliasTargetSet, h as PROVIDER_TYPE_ANTHROPIC, i as extractResponsesUsageFromStreamEvent, j as isMessagesApiEnabled, k as isForceAgentEnabled, l as normalizeEmbeddingsUsage, m as isDevModeEnabled, n as applySharedSessionAffinityRetention, o as getRequestHistoryStore, p as flushPendingCapture, r as extractResponsesUsageFromResult, s as getStatsStore, t as accountsManager, u as normalizeMessagesUsage, v as getClaudeTokenMultiplier, w as getModelRefreshIntervalMs, x as getLogLevel, y as getConfig } from "./accounts-manager-BNVadA3o.js";
7
7
  import consola from "consola";
8
8
  import fs, { readFile } from "node:fs/promises";
9
9
  import { randomUUID, timingSafeEqual } from "node:crypto";
@@ -350,6 +350,52 @@ const _normalizeSdkModelId = (sdkModelId) => {
350
350
  };
351
351
  };
352
352
 
353
+ //#endregion
354
+ //#region src/lib/copilot-rate-limit.ts
355
+ const copilotRateLimitTypes = ["session", "weekly"];
356
+ const copilotRateLimitHeaders = {
357
+ session: "x-usage-ratelimit-session",
358
+ weekly: "x-usage-ratelimit-weekly"
359
+ };
360
+ const hasGetMethod = (headers) => {
361
+ return "get" in headers && typeof headers.get === "function";
362
+ };
363
+ const getHeaderValue = (headers, headerName) => {
364
+ if (hasGetMethod(headers)) return headers.get(headerName);
365
+ const normalizedHeaderName = headerName.toLowerCase();
366
+ return Object.entries(headers).find(([key]) => key.toLowerCase() === normalizedHeaderName)?.[1] ?? null;
367
+ };
368
+ const parseCopilotRateLimitHeader = (headerValue) => {
369
+ const params = new URLSearchParams(headerValue);
370
+ const remaining = params.get("rem");
371
+ const resetAt = params.get("rst");
372
+ if (!remaining || !resetAt) return null;
373
+ return {
374
+ remaining,
375
+ resetAt
376
+ };
377
+ };
378
+ const getCopilotRateLimitUsage = (headers, type) => {
379
+ const headerName = copilotRateLimitHeaders[type];
380
+ const headerValue = getHeaderValue(headers, headerName);
381
+ if (!headerValue) return null;
382
+ const parsed = parseCopilotRateLimitHeader(headerValue);
383
+ if (!parsed) return null;
384
+ return {
385
+ type,
386
+ ...parsed
387
+ };
388
+ };
389
+ const logCopilotRateLimits = (headers) => {
390
+ for (const type of copilotRateLimitTypes) {
391
+ const usage = getCopilotRateLimitUsage(headers, type);
392
+ if (!usage) continue;
393
+ const d = new Date(usage.resetAt);
394
+ const dateStr = Number.isNaN(d.getTime()) ? usage.resetAt : d.toLocaleString();
395
+ consola.info(`Copilot ${usage.type} quota remaining: ${usage.remaining}, resets at: ${dateStr}`);
396
+ }
397
+ };
398
+
353
399
  //#endregion
354
400
  //#region src/lib/request-initiator.ts
355
401
  function resolveEffectiveInitiator(baseInitiator, options) {
@@ -400,6 +446,7 @@ const createChatCompletions = async (payload, account, options) => {
400
446
  requestId: options?.requestId,
401
447
  callSite: "chat-completions"
402
448
  });
449
+ logCopilotRateLimits(response.headers);
403
450
  if (!response.ok) {
404
451
  consola.error("Failed to create chat completions", response);
405
452
  throw new HTTPError("Failed to create chat completions", response);
@@ -4354,7 +4401,7 @@ const createResponses = async (payload, { vision, initiator, upstreamRequestId,
4354
4401
  };
4355
4402
  prepareInteractionHeaders(sessionId, Boolean(subagentMarker), headers);
4356
4403
  prepareForCompact(headers, compactType);
4357
- payload.service_tier = null;
4404
+ payload.service_tier = void 0;
4358
4405
  captureOutboundHeadersSnapshot(headers);
4359
4406
  const response = await copilotFetch(`${copilotBaseUrl(ctx)}/responses`, {
4360
4407
  method: "POST",
@@ -4364,6 +4411,7 @@ const createResponses = async (payload, { vision, initiator, upstreamRequestId,
4364
4411
  requestId,
4365
4412
  callSite: "responses"
4366
4413
  });
4414
+ logCopilotRateLimits(response.headers);
4367
4415
  if (!response.ok) {
4368
4416
  consola.error("Failed to create responses", response);
4369
4417
  throw new HTTPError("Failed to create responses", response);
@@ -5419,6 +5467,7 @@ const createMessages = async (payload, account, options) => {
5419
5467
  requestId: options?.requestId,
5420
5468
  callSite: "messages"
5421
5469
  });
5470
+ logCopilotRateLimits(response.headers);
5422
5471
  if (!response.ok) {
5423
5472
  consola.error("Failed to create messages", response);
5424
5473
  throw new HTTPError("Failed to create messages", response);
@@ -6985,6 +7034,7 @@ const handleResponses = async (c) => {
6985
7034
  model: selectedModel.id
6986
7035
  };
6987
7036
  useFunctionApplyPatch(upstreamPayload);
7037
+ removeUnsupportedTools(upstreamPayload);
6988
7038
  applyResponsesApiContextManagement(upstreamPayload, selectedModel.capabilities.limits.max_prompt_tokens);
6989
7039
  compactInputByLatestCompaction(upstreamPayload);
6990
7040
  const premiumRemainingBefore = account.premiumRemaining;
@@ -7377,6 +7427,20 @@ async function handleNonStreamingResponses(params) {
7377
7427
  });
7378
7428
  }
7379
7429
  }
7430
+ const COPILOT_UNSUPPORTED_TOOL_TYPES = new Set(["image_generation"]);
7431
+ const removeUnsupportedTools = (payload) => {
7432
+ if (!Array.isArray(payload.tools) || payload.tools.length === 0) return;
7433
+ const dropped = [];
7434
+ payload.tools = payload.tools.filter((t) => {
7435
+ const type = t.type;
7436
+ if (COPILOT_UNSUPPORTED_TOOL_TYPES.has(type)) {
7437
+ dropped.push(type);
7438
+ return false;
7439
+ }
7440
+ return true;
7441
+ });
7442
+ if (dropped.length > 0) logger$1.debug("Removed unsupported tools:", dropped);
7443
+ };
7380
7444
 
7381
7445
  //#endregion
7382
7446
  //#region src/routes/responses/route.ts
@@ -7470,4 +7534,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
7470
7534
 
7471
7535
  //#endregion
7472
7536
  export { server };
7473
- //# sourceMappingURL=server-kG7N_-Aj.js.map
7537
+ //# sourceMappingURL=server-BhOhCgni.js.map