@jeffreycao/copilot-api 2.5.8 → 2.5.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.
package/dist/main.js CHANGED
@@ -27,10 +27,10 @@ if (isMcpFastPath(process.argv)) {
27
27
  if (process.platform === "win32" && process.stdout.isTTY && !process.env.WT_SESSION) process.env.WT_SESSION = "copilot-api";
28
28
  const { bindElectronFetch } = await import("./electron-fetch-DsMaRX6v.js");
29
29
  bindElectronFetch();
30
- const { auth } = await import("./auth-CX6c7jlD.js");
30
+ const { auth } = await import("./auth-CdETqUtu.js");
31
31
  const { debug } = await import("./debug-DV0aYj65.js");
32
32
  const { mcp } = await import("./mcp-Byz9h_xz.js");
33
- const { start } = await import("./start-CBnChdoU.js");
33
+ const { start } = await import("./start-zddonYc0.js");
34
34
  await runMain(defineCommand({
35
35
  meta: {
36
36
  name: "copilot-api",
@@ -1,4 +1,4 @@
1
- import { J as state } from "./token-O2WH6ipn.js";
1
+ import { X as state } from "./token-4p5BAEqO.js";
2
2
  //#region src/lib/models.ts
3
3
  /**
4
4
  * Converts a Copilot upstream model ID to a client-friendly ID that Claude Code
@@ -87,4 +87,4 @@ const normalizeSdkModelId = (sdkModelId) => {
87
87
  //#endregion
88
88
  export { toClientModelId as i, getLatestModelForFamily as n, normalizeSdkModelId as r, findEndpointModel as t };
89
89
 
90
- //# sourceMappingURL=models-mp3HRQcW.js.map
90
+ //# sourceMappingURL=models-B1c5UcTP.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"models-mp3HRQcW.js","names":[],"sources":["../src/lib/models.ts"],"sourcesContent":["import type { Model } from \"~/lib/types/models\"\n\nimport { state } from \"~/lib/state\"\n\n/**\n * Converts a Copilot upstream model ID to a client-friendly ID that Claude Code\n * and Claude Desktop recognize (dots in version replaced with hyphens).\n * e.g. \"claude-sonnet-4.6\" -> \"claude-sonnet-4-6\"\n * Non-Claude models are returned unchanged.\n */\nexport const toClientModelId = (modelId: string): string => {\n const normalized = normalizeSdkModelId(modelId)\n if (!normalized) return modelId\n const versionHyphenated = normalized.version.replaceAll(\".\", \"-\")\n return `claude-${normalized.family}-${versionHyphenated}`\n}\n\nexport interface NormalizedSdkModelId {\n family: string\n version: string\n}\n\nexport const findEndpointModel = (sdkModelId: string): Model | undefined => {\n const models = state.models?.data ?? []\n const exactMatch = models.find((m) => m.id === sdkModelId)\n if (exactMatch) {\n return exactMatch\n }\n\n const normalized = normalizeSdkModelId(sdkModelId)\n if (!normalized) {\n return undefined\n }\n\n const modelName = `claude-${normalized.family}-${normalized.version}`\n const model = models.find((m) => m.id === modelName)\n if (model) {\n return model\n }\n\n return undefined\n}\n\n/**\n * Finds the latest available model for a given Claude family (e.g. \"opus\",\n * \"sonnet\", \"haiku\") among the models currently cached in `state.models`.\n * \"Latest\" is determined by the highest semantic version parsed from the model\n * ID. Returns `undefined` when no model of that family is available.\n */\nexport const getLatestModelForFamily = (family: string): Model | undefined => {\n const models = state.models?.data ?? []\n\n let best: { model: Model; major: number; minor: number } | undefined\n\n for (const model of models) {\n const normalized = normalizeSdkModelId(model.id)\n if (!normalized || normalized.family !== family) {\n continue\n }\n\n const [majorPart, minorPart = \"0\"] = normalized.version.split(\".\")\n const major = Number.parseInt(majorPart, 10)\n const minor = Number.parseInt(minorPart, 10)\n if (Number.isNaN(major) || Number.isNaN(minor)) {\n continue\n }\n\n if (\n !best\n || major > best.major\n || (major === best.major && minor > best.minor)\n ) {\n best = { model, major, minor }\n }\n }\n\n return best?.model\n}\n\n/**\n * Normalizes an SDK model ID to extract the model family and version.\n * this method from github copilot extension\n * Examples:\n * - \"claude-opus-4-5-20251101\" -> { family: \"opus\", version: \"4.5\" }\n * - \"claude-3-5-sonnet-20241022\" -> { family: \"sonnet\", version: \"3.5\" }\n * - \"claude-sonnet-4-20250514\" -> { family: \"sonnet\", version: \"4\" }\n * - \"claude-haiku-3-5-20250514\" -> { family: \"haiku\", version: \"3.5\" }\n * - \"claude-haiku-4.5\" -> { family: \"haiku\", version: \"4.5\" }\n */\nexport const normalizeSdkModelId = (\n sdkModelId: string,\n): NormalizedSdkModelId | undefined => {\n const lower = sdkModelId.toLowerCase()\n\n // Strip date suffix (8 digits at the end)\n const withoutDate = lower.replace(/-\\d{8}$/, \"\")\n\n // Pattern 1: claude-{family}-{major}.{minor} (e.g., claude-haiku-4.5)\n const pattern1 = withoutDate.match(/^claude-(\\w+)-(\\d+)\\.(\\d+)$/)\n if (pattern1) {\n return { family: pattern1[1], version: `${pattern1[2]}.${pattern1[3]}` }\n }\n\n // Pattern 2: claude-{family}-{major}-{minor} (e.g., claude-opus-4-5, claude-haiku-3-5)\n const pattern2 = withoutDate.match(/^claude-(\\w+)-(\\d+)-(\\d+)$/)\n if (pattern2) {\n return { family: pattern2[1], version: `${pattern2[2]}.${pattern2[3]}` }\n }\n\n // Pattern 3: claude-{major}-{minor}-{family} (e.g., claude-3-5-sonnet)\n const pattern3 = withoutDate.match(/^claude-(\\d+)-(\\d+)-(\\w+)$/)\n if (pattern3) {\n return { family: pattern3[3], version: `${pattern3[1]}.${pattern3[2]}` }\n }\n\n // Pattern 4: claude-{family}-{major} (e.g., claude-sonnet-4)\n const pattern4 = withoutDate.match(/^claude-(\\w+)-(\\d+)$/)\n if (pattern4) {\n return { family: pattern4[1], version: pattern4[2] }\n }\n\n // Pattern 5: claude-{major}-{family} (e.g., claude-3-opus)\n const pattern5 = withoutDate.match(/^claude-(\\d+)-(\\w+)$/)\n if (pattern5) {\n return { family: pattern5[2], version: pattern5[1] }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;AAUA,MAAa,mBAAmB,YAA4B;CAC1D,MAAM,aAAa,oBAAoB,OAAO;CAC9C,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,oBAAoB,WAAW,QAAQ,WAAW,KAAK,GAAG;CAChE,OAAO,UAAU,WAAW,OAAO,GAAG;AACxC;AAOA,MAAa,qBAAqB,eAA0C;CAC1E,MAAM,SAAS,MAAM,QAAQ,QAAQ,CAAC;CACtC,MAAM,aAAa,OAAO,MAAM,MAAM,EAAE,OAAO,UAAU;CACzD,IAAI,YACF,OAAO;CAGT,MAAM,aAAa,oBAAoB,UAAU;CACjD,IAAI,CAAC,YACH;CAGF,MAAM,YAAY,UAAU,WAAW,OAAO,GAAG,WAAW;CAC5D,MAAM,QAAQ,OAAO,MAAM,MAAM,EAAE,OAAO,SAAS;CACnD,IAAI,OACF,OAAO;AAIX;;;;;;;AAQA,MAAa,2BAA2B,WAAsC;CAC5E,MAAM,SAAS,MAAM,QAAQ,QAAQ,CAAC;CAEtC,IAAI;CAEJ,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,aAAa,oBAAoB,MAAM,EAAE;EAC/C,IAAI,CAAC,cAAc,WAAW,WAAW,QACvC;EAGF,MAAM,CAAC,WAAW,YAAY,OAAO,WAAW,QAAQ,MAAM,GAAG;EACjE,MAAM,QAAQ,OAAO,SAAS,WAAW,EAAE;EAC3C,MAAM,QAAQ,OAAO,SAAS,WAAW,EAAE;EAC3C,IAAI,OAAO,MAAM,KAAK,KAAK,OAAO,MAAM,KAAK,GAC3C;EAGF,IACE,CAAC,QACE,QAAQ,KAAK,SACZ,UAAU,KAAK,SAAS,QAAQ,KAAK,OAEzC,OAAO;GAAE;GAAO;GAAO;EAAM;CAEjC;CAEA,OAAO,MAAM;AACf;;;;;;;;;;;AAYA,MAAa,uBACX,eACqC;CAIrC,MAAM,cAHQ,WAAW,YAGD,CAAC,CAAC,QAAQ,WAAW,EAAE;CAG/C,MAAM,WAAW,YAAY,MAAM,6BAA6B;CAChE,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,GAAG,SAAS,GAAG,GAAG,SAAS;CAAK;CAIzE,MAAM,WAAW,YAAY,MAAM,4BAA4B;CAC/D,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,GAAG,SAAS,GAAG,GAAG,SAAS;CAAK;CAIzE,MAAM,WAAW,YAAY,MAAM,4BAA4B;CAC/D,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,GAAG,SAAS,GAAG,GAAG,SAAS;CAAK;CAIzE,MAAM,WAAW,YAAY,MAAM,sBAAsB;CACzD,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,SAAS;CAAG;CAIrD,MAAM,WAAW,YAAY,MAAM,sBAAsB;CACzD,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,SAAS;CAAG;AAIvD"}
1
+ {"version":3,"file":"models-B1c5UcTP.js","names":[],"sources":["../src/lib/models.ts"],"sourcesContent":["import type { Model } from \"~/lib/types/models\"\n\nimport { state } from \"~/lib/state\"\n\n/**\n * Converts a Copilot upstream model ID to a client-friendly ID that Claude Code\n * and Claude Desktop recognize (dots in version replaced with hyphens).\n * e.g. \"claude-sonnet-4.6\" -> \"claude-sonnet-4-6\"\n * Non-Claude models are returned unchanged.\n */\nexport const toClientModelId = (modelId: string): string => {\n const normalized = normalizeSdkModelId(modelId)\n if (!normalized) return modelId\n const versionHyphenated = normalized.version.replaceAll(\".\", \"-\")\n return `claude-${normalized.family}-${versionHyphenated}`\n}\n\nexport interface NormalizedSdkModelId {\n family: string\n version: string\n}\n\nexport const findEndpointModel = (sdkModelId: string): Model | undefined => {\n const models = state.models?.data ?? []\n const exactMatch = models.find((m) => m.id === sdkModelId)\n if (exactMatch) {\n return exactMatch\n }\n\n const normalized = normalizeSdkModelId(sdkModelId)\n if (!normalized) {\n return undefined\n }\n\n const modelName = `claude-${normalized.family}-${normalized.version}`\n const model = models.find((m) => m.id === modelName)\n if (model) {\n return model\n }\n\n return undefined\n}\n\n/**\n * Finds the latest available model for a given Claude family (e.g. \"opus\",\n * \"sonnet\", \"haiku\") among the models currently cached in `state.models`.\n * \"Latest\" is determined by the highest semantic version parsed from the model\n * ID. Returns `undefined` when no model of that family is available.\n */\nexport const getLatestModelForFamily = (family: string): Model | undefined => {\n const models = state.models?.data ?? []\n\n let best: { model: Model; major: number; minor: number } | undefined\n\n for (const model of models) {\n const normalized = normalizeSdkModelId(model.id)\n if (!normalized || normalized.family !== family) {\n continue\n }\n\n const [majorPart, minorPart = \"0\"] = normalized.version.split(\".\")\n const major = Number.parseInt(majorPart, 10)\n const minor = Number.parseInt(minorPart, 10)\n if (Number.isNaN(major) || Number.isNaN(minor)) {\n continue\n }\n\n if (\n !best\n || major > best.major\n || (major === best.major && minor > best.minor)\n ) {\n best = { model, major, minor }\n }\n }\n\n return best?.model\n}\n\n/**\n * Normalizes an SDK model ID to extract the model family and version.\n * this method from github copilot extension\n * Examples:\n * - \"claude-opus-4-5-20251101\" -> { family: \"opus\", version: \"4.5\" }\n * - \"claude-3-5-sonnet-20241022\" -> { family: \"sonnet\", version: \"3.5\" }\n * - \"claude-sonnet-4-20250514\" -> { family: \"sonnet\", version: \"4\" }\n * - \"claude-haiku-3-5-20250514\" -> { family: \"haiku\", version: \"3.5\" }\n * - \"claude-haiku-4.5\" -> { family: \"haiku\", version: \"4.5\" }\n */\nexport const normalizeSdkModelId = (\n sdkModelId: string,\n): NormalizedSdkModelId | undefined => {\n const lower = sdkModelId.toLowerCase()\n\n // Strip date suffix (8 digits at the end)\n const withoutDate = lower.replace(/-\\d{8}$/, \"\")\n\n // Pattern 1: claude-{family}-{major}.{minor} (e.g., claude-haiku-4.5)\n const pattern1 = withoutDate.match(/^claude-(\\w+)-(\\d+)\\.(\\d+)$/)\n if (pattern1) {\n return { family: pattern1[1], version: `${pattern1[2]}.${pattern1[3]}` }\n }\n\n // Pattern 2: claude-{family}-{major}-{minor} (e.g., claude-opus-4-5, claude-haiku-3-5)\n const pattern2 = withoutDate.match(/^claude-(\\w+)-(\\d+)-(\\d+)$/)\n if (pattern2) {\n return { family: pattern2[1], version: `${pattern2[2]}.${pattern2[3]}` }\n }\n\n // Pattern 3: claude-{major}-{minor}-{family} (e.g., claude-3-5-sonnet)\n const pattern3 = withoutDate.match(/^claude-(\\d+)-(\\d+)-(\\w+)$/)\n if (pattern3) {\n return { family: pattern3[3], version: `${pattern3[1]}.${pattern3[2]}` }\n }\n\n // Pattern 4: claude-{family}-{major} (e.g., claude-sonnet-4)\n const pattern4 = withoutDate.match(/^claude-(\\w+)-(\\d+)$/)\n if (pattern4) {\n return { family: pattern4[1], version: pattern4[2] }\n }\n\n // Pattern 5: claude-{major}-{family} (e.g., claude-3-opus)\n const pattern5 = withoutDate.match(/^claude-(\\d+)-(\\w+)$/)\n if (pattern5) {\n return { family: pattern5[2], version: pattern5[1] }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;AAUA,MAAa,mBAAmB,YAA4B;CAC1D,MAAM,aAAa,oBAAoB,OAAO;CAC9C,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,oBAAoB,WAAW,QAAQ,WAAW,KAAK,GAAG;CAChE,OAAO,UAAU,WAAW,OAAO,GAAG;AACxC;AAOA,MAAa,qBAAqB,eAA0C;CAC1E,MAAM,SAAS,MAAM,QAAQ,QAAQ,CAAC;CACtC,MAAM,aAAa,OAAO,MAAM,MAAM,EAAE,OAAO,UAAU;CACzD,IAAI,YACF,OAAO;CAGT,MAAM,aAAa,oBAAoB,UAAU;CACjD,IAAI,CAAC,YACH;CAGF,MAAM,YAAY,UAAU,WAAW,OAAO,GAAG,WAAW;CAC5D,MAAM,QAAQ,OAAO,MAAM,MAAM,EAAE,OAAO,SAAS;CACnD,IAAI,OACF,OAAO;AAIX;;;;;;;AAQA,MAAa,2BAA2B,WAAsC;CAC5E,MAAM,SAAS,MAAM,QAAQ,QAAQ,CAAC;CAEtC,IAAI;CAEJ,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,aAAa,oBAAoB,MAAM,EAAE;EAC/C,IAAI,CAAC,cAAc,WAAW,WAAW,QACvC;EAGF,MAAM,CAAC,WAAW,YAAY,OAAO,WAAW,QAAQ,MAAM,GAAG;EACjE,MAAM,QAAQ,OAAO,SAAS,WAAW,EAAE;EAC3C,MAAM,QAAQ,OAAO,SAAS,WAAW,EAAE;EAC3C,IAAI,OAAO,MAAM,KAAK,KAAK,OAAO,MAAM,KAAK,GAC3C;EAGF,IACE,CAAC,QACE,QAAQ,KAAK,SACZ,UAAU,KAAK,SAAS,QAAQ,KAAK,OAEzC,OAAO;GAAE;GAAO;GAAO;EAAM;CAEjC;CAEA,OAAO,MAAM;AACf;;;;;;;;;;;AAYA,MAAa,uBACX,eACqC;CAIrC,MAAM,cAHQ,WAAW,YAGD,CAAC,CAAC,QAAQ,WAAW,EAAE;CAG/C,MAAM,WAAW,YAAY,MAAM,6BAA6B;CAChE,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,GAAG,SAAS,GAAG,GAAG,SAAS;CAAK;CAIzE,MAAM,WAAW,YAAY,MAAM,4BAA4B;CAC/D,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,GAAG,SAAS,GAAG,GAAG,SAAS;CAAK;CAIzE,MAAM,WAAW,YAAY,MAAM,4BAA4B;CAC/D,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,GAAG,SAAS,GAAG,GAAG,SAAS;CAAK;CAIzE,MAAM,WAAW,YAAY,MAAM,sBAAsB;CACzD,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,SAAS;CAAG;CAIrD,MAAM,WAAW,YAAY,MAAM,sBAAsB;CACzD,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,SAAS;CAAG;AAIvD"}
@@ -1,7 +1,7 @@
1
1
  import { A as isResponsesApiWebSocketEnabled, C as getClaudeTokenMultiplier, D as isAlphaSearchCodexPriorityEnabled, E as getUpstreamTransportConfig, 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-2Dli6AI8.js";
2
- import { A as createAuthMiddleware, B as resolveTraceId$1, C as prepareMessageProxyHeaders, E as compactMessageSections, F as CODEX_API_BASE_URL, G as isTerminalResponsesStreamChunk, H as createResponsesHttpEventStream, I as buildCodexRequestHeaders, J as state, K as createPooledWebSocketStream, L as forwardCodexResponses, O as compactSystemPromptStarts, R as generateTraceId, S as prepareInteractionHeaders, T as compactAutoContinuePromptStarts, U as createResponsesSafeStream, V as fetchUpstreamWithLifecycle, W as encodePoolKeyPart, X as forwardError, Y as HTTPError, _ as copilotBaseUrl, b as copilotWebSocketHeaders, c as getUUID, d as isResponsesStream, f as parseUserIdMetadata, j as getConfiguredAdminApiKeys, k as compactTextOnlyGuard, l as isAsyncIterable, o as generateRequestIdFromPayload, p as getCopilotUsage, q as createWebSocketUrl, r as setupCodexToken, s as getRootSessionId, u as isNullish, v as copilotHeaders, x as prepareForCompact, z as requestContext } from "./token-O2WH6ipn.js";
2
+ import { A as compactSystemPromptStarts, B as generateTraceId, C as prepareForCompact, D as compactAutoContinuePromptStarts, G as createResponsesSafeStream, H as resolveTraceId$1, J as createPooledWebSocketStream, K as encodePoolKeyPart, L as CODEX_API_BASE_URL, M as createAuthMiddleware, N as getConfiguredAdminApiKeys, O as compactMessageSections, Q as forwardError, R as buildCodexRequestHeaders, S as copilotWebSocketHeaders, T as prepareMessageProxyHeaders, U as fetchUpstreamWithLifecycle, V as requestContext, W as createResponsesHttpEventStream, X as state, Y as createWebSocketUrl, Z as HTTPError, a as setupCodexToken, b as copilotHeaders, c as generateRequestIdFromPayload, d as isAsyncIterable, f as isNullish, h as getCopilotUsage, j as compactTextOnlyGuard, l as getRootSessionId, m as parseUserIdMetadata, p as isResponsesStream, q as isTerminalResponsesStreamChunk, u as getUUID, w as prepareInteractionHeaders, y as copilotBaseUrl, z as forwardCodexResponses } from "./token-4p5BAEqO.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-BgFcDbNQ.js";
4
- import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-mp3HRQcW.js";
4
+ import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-B1c5UcTP.js";
5
5
  import consola from "consola";
6
6
  import { createHash } from "node:crypto";
7
7
  import fs, { createWriteStream, readFileSync, rmSync } from "node:fs";
@@ -396,6 +396,33 @@ var EventBus = class {
396
396
  };
397
397
  }
398
398
  };
399
+ //#endregion
400
+ //#region src/lib/token-usage/peak-windows.ts
401
+ const deepseekPeakWindows = [{
402
+ endMinuteUtc: 240,
403
+ startMinuteUtc: 60,
404
+ weekdays: [
405
+ 1,
406
+ 2,
407
+ 3,
408
+ 4,
409
+ 5
410
+ ]
411
+ }, {
412
+ endMinuteUtc: 600,
413
+ startMinuteUtc: 360,
414
+ weekdays: [
415
+ 1,
416
+ 2,
417
+ 3,
418
+ 4,
419
+ 5
420
+ ]
421
+ }];
422
+ const dashscopePeakWindows = [{
423
+ endMinuteUtc: 840,
424
+ startMinuteUtc: 0
425
+ }];
399
426
  const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
400
427
  static catalog = {
401
428
  codex: {
@@ -598,10 +625,32 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
598
625
  contextWindow: 1e6,
599
626
  inputModalities: ["text"],
600
627
  maxOutputTokens: 64e3,
628
+ pricing: {
629
+ cachedInput: .3,
630
+ input: 3,
631
+ offPeak: {
632
+ cachedInput: .15,
633
+ input: 1.5,
634
+ output: 4.5
635
+ },
636
+ output: 9,
637
+ peakWindows: dashscopePeakWindows
638
+ }
639
+ },
640
+ "deepseek-v4.1-flash": {
641
+ contextWindow: 1e6,
642
+ inputModalities: ["text", "image"],
643
+ maxOutputTokens: 393216,
601
644
  pricing: {
602
645
  cachedInput: .2,
603
- input: 1,
604
- output: 2
646
+ input: 2,
647
+ offPeak: {
648
+ cachedInput: .1,
649
+ input: 1,
650
+ output: 4
651
+ },
652
+ output: 8,
653
+ peakWindows: dashscopePeakWindows
605
654
  }
606
655
  },
607
656
  "qwen3.7-plus": {
@@ -643,7 +692,13 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
643
692
  pricing: {
644
693
  cachedInput: .04,
645
694
  input: 2,
646
- output: 8
695
+ offPeak: {
696
+ cachedInput: .02,
697
+ input: 1,
698
+ output: 4
699
+ },
700
+ output: 8,
701
+ peakWindows: deepseekPeakWindows
647
702
  },
648
703
  reasoningEfforts: [
649
704
  "low",
@@ -658,7 +713,13 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
658
713
  pricing: {
659
714
  cachedInput: .3,
660
715
  input: 9,
661
- output: 27
716
+ offPeak: {
717
+ cachedInput: .15,
718
+ input: 4.5,
719
+ output: 13.5
720
+ },
721
+ output: 27,
722
+ peakWindows: deepseekPeakWindows
662
723
  },
663
724
  reasoningEfforts: [
664
725
  "low",
@@ -822,7 +883,13 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
822
883
  pricing: {
823
884
  cachedInput: .006,
824
885
  input: .3,
825
- output: 1.2
886
+ offPeak: {
887
+ cachedInput: .003,
888
+ input: .15,
889
+ output: .6
890
+ },
891
+ output: 1.2,
892
+ peakWindows: deepseekPeakWindows
826
893
  },
827
894
  reasoningEfforts: [
828
895
  "low",
@@ -835,9 +902,15 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
835
902
  inputModalities: ["text"],
836
903
  maxOutputTokens: 64e3,
837
904
  pricing: {
838
- cachedInput: .007,
839
- input: .22,
840
- output: .66
905
+ cachedInput: .006,
906
+ input: .3,
907
+ offPeak: {
908
+ cachedInput: .003,
909
+ input: .15,
910
+ output: .6
911
+ },
912
+ output: 1.2,
913
+ peakWindows: deepseekPeakWindows
841
914
  }
842
915
  },
843
916
  "deepseek-v4-flash-vision-exp": {
@@ -845,9 +918,15 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
845
918
  inputModalities: ["text", "image"],
846
919
  maxOutputTokens: 384e3,
847
920
  pricing: {
848
- cachedInput: .007,
849
- input: .22,
850
- output: .66
921
+ cachedInput: .006,
922
+ input: .3,
923
+ offPeak: {
924
+ cachedInput: .003,
925
+ input: .15,
926
+ output: .6
927
+ },
928
+ output: 1.2,
929
+ peakWindows: deepseekPeakWindows
851
930
  },
852
931
  reasoningEfforts: [
853
932
  "low",
@@ -860,9 +939,15 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
860
939
  inputModalities: ["text"],
861
940
  maxOutputTokens: 64e3,
862
941
  pricing: {
863
- cachedInput: .022,
864
- input: .66,
865
- output: 1.98
942
+ cachedInput: .044,
943
+ input: 1.32,
944
+ offPeak: {
945
+ cachedInput: .022,
946
+ input: .66,
947
+ output: 1.98
948
+ },
949
+ output: 3.96,
950
+ peakWindows: deepseekPeakWindows
866
951
  }
867
952
  },
868
953
  "kimi-k2.7-code": {
@@ -1731,7 +1816,7 @@ function resolveTokenUsageCost(input) {
1731
1816
  if (!providerName) return null;
1732
1817
  const resolvedPricing = resolveProviderPricing(providerName, input.model, input.pricing);
1733
1818
  if (!resolvedPricing) return null;
1734
- const pricing = resolvePricingTier(resolvedPricing.pricing, getInputTokenTotal(input));
1819
+ const pricing = resolvePricingTier(resolvedPricing.pricing, getInputTokenTotal(input), resolvePricingTime(input.at));
1735
1820
  const currency = resolveProviderCurrency(providerName, input.pricingCurrency);
1736
1821
  if (!currency) return null;
1737
1822
  const inputPrice = normalizePrice(pricing.input);
@@ -1780,13 +1865,37 @@ function resolveProviderPricing(providerName, model, configuredPricing) {
1780
1865
  source: "builtin"
1781
1866
  };
1782
1867
  }
1783
- function resolvePricingTier(pricing, inputTokenTotal) {
1868
+ function resolvePricingTier(pricing, inputTokenTotal, at) {
1784
1869
  const tiers = pricing.tiers?.filter((tier) => typeof tier === "object" && tier !== null).toSorted((a, b) => normalizeTierMax(a) - normalizeTierMax(b));
1785
1870
  const selectedTier = tiers?.find((tier) => inputTokenTotal <= normalizeTierMax(tier)) ?? tiers?.at(-1);
1786
- return {
1871
+ const resolvedTier = {
1787
1872
  ...pricing,
1788
1873
  ...selectedTier
1789
1874
  };
1875
+ const offPeak = pricing.offPeak;
1876
+ const peakWindows = pricing.peakWindows;
1877
+ if (offPeak && peakWindows?.length && !isPeakPricingTime(peakWindows, at)) return {
1878
+ ...resolvedTier,
1879
+ ...offPeak
1880
+ };
1881
+ return resolvedTier;
1882
+ }
1883
+ function resolvePricingTime(at) {
1884
+ return at instanceof Date && Number.isFinite(at.getTime()) ? at : /* @__PURE__ */ new Date();
1885
+ }
1886
+ function isPeakPricingTime(windows, at) {
1887
+ const minuteOfDay = at.getUTCHours() * 60 + at.getUTCMinutes();
1888
+ const isoWeekday = at.getUTCDay() || 7;
1889
+ return windows.some((window) => {
1890
+ const startMinute = normalizeMinuteOfDay(window.startMinuteUtc);
1891
+ const endMinute = normalizeMinuteOfDay(window.endMinuteUtc);
1892
+ if (startMinute === null || endMinute === null || endMinute <= startMinute) return false;
1893
+ if (window.weekdays?.length && !window.weekdays.includes(isoWeekday)) return false;
1894
+ return minuteOfDay >= startMinute && minuteOfDay < endMinute;
1895
+ });
1896
+ }
1897
+ function normalizeMinuteOfDay(value) {
1898
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1440 ? value : null;
1790
1899
  }
1791
1900
  function normalizeTierMax(tier) {
1792
1901
  const maxInputTokens = tier.maxInputTokens;
@@ -1831,7 +1940,10 @@ function resolveUserId(input) {
1831
1940
  function toPersistedEvent(input) {
1832
1941
  if (!hasAnyToken(input)) return null;
1833
1942
  const now = /* @__PURE__ */ new Date();
1834
- const cost = resolveTokenUsageCost(input);
1943
+ const cost = resolveTokenUsageCost({
1944
+ ...input,
1945
+ at: now
1946
+ });
1835
1947
  return {
1836
1948
  cache_creation_input_tokens: normalizeToken(input.cache_creation_input_tokens),
1837
1949
  cache_read_input_tokens: normalizeToken(input.cache_read_input_tokens),
@@ -12567,4 +12679,4 @@ createServer();
12567
12679
  //#endregion
12568
12680
  export { createServer };
12569
12681
 
12570
- //# sourceMappingURL=server-CcnH-kO1.js.map
12682
+ //# sourceMappingURL=server-D0Wx-DQF.js.map