fix(console): support DeepSeek weekend pricing (#44305)
Co-authored-by: MrMushrooooom <MrMushrooooom@users.noreply.github.com> Co-authored-by: Frank <frank@anoma.ly>
This commit is contained in:
parent
03bba464d4
commit
b1ce938ebe
3 changed files with 29 additions and 2 deletions
|
|
@ -47,6 +47,7 @@ import { createProviderBudgetTracker } from "./providerBudgetTracker"
|
|||
import { accumulateUsage, HOT_WORKSPACES } from "./usageBatcher"
|
||||
import { Workspace } from "@opencode-ai/console-core/workspace.js"
|
||||
import { countryFromRequest, isModelCountryRestricted } from "~/lib/request-country"
|
||||
import { isPeakPricing } from "./pricing"
|
||||
import { prepareRequestBody } from "./requestBody"
|
||||
|
||||
type ZenData = Awaited<ReturnType<typeof ZenData.list>>
|
||||
|
|
@ -992,9 +993,8 @@ export async function handler(
|
|||
const { inputTokens, outputTokens, reasoningTokens, cacheReadTokens, cacheWrite5mTokens, cacheWrite1hTokens } =
|
||||
usageInfo
|
||||
|
||||
const hour = new Date().getUTCHours()
|
||||
const modelCost =
|
||||
modelInfo.costPeak && ((hour >= 1 && hour < 4) || (hour >= 6 && hour < 10))
|
||||
modelInfo.costPeak && isPeakPricing(new Date())
|
||||
? modelInfo.costPeak
|
||||
: modelInfo.cost200K &&
|
||||
inputTokens + (cacheReadTokens ?? 0) + (cacheWrite5mTokens ?? 0) + (cacheWrite1hTokens ?? 0) > 200_000
|
||||
|
|
|
|||
11
packages/console/app/src/routes/zen/util/pricing.ts
Normal file
11
packages/console/app/src/routes/zen/util/pricing.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
export function isPeakPricing(date: Date) {
|
||||
// DeepSeek peak pricing in China Standard Time (UTC+8):
|
||||
// - Weekdays only
|
||||
// - 9 AM to noon
|
||||
// - 2 PM to 6 PM
|
||||
const dateCN = new Date(date.getTime() + 8 * 3_600 * 1000)
|
||||
const dayCN = dateCN.getUTCDay()
|
||||
if (dayCN === 0 || dayCN === 6) return false
|
||||
const hourCN = dateCN.getUTCHours()
|
||||
return (hourCN >= 9 && hourCN < 12) || (hourCN >= 14 && hourCN < 18)
|
||||
}
|
||||
16
packages/console/app/test/pricing.test.ts
Normal file
16
packages/console/app/test/pricing.test.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { describe, expect, test } from "bun:test"
|
||||
import { isPeakPricing } from "../src/routes/zen/util/pricing"
|
||||
|
||||
describe("isPeakPricing", () => {
|
||||
test.each([
|
||||
["weekday 09:00 CN starts peak pricing", "2026-08-27T01:00:00.000Z", true],
|
||||
["weekday 12:00 CN ends peak pricing", "2026-08-27T04:00:00.000Z", false],
|
||||
["weekday 14:00 CN starts peak pricing", "2026-08-27T06:00:00.000Z", true],
|
||||
["weekday 18:00 CN ends peak pricing", "2026-08-27T10:00:00.000Z", false],
|
||||
["Saturday in Beijing", "2026-08-29T01:00:00.000Z", false],
|
||||
["Sunday in Beijing", "2026-08-30T06:00:00.000Z", false],
|
||||
["Monday in Beijing", "2026-08-31T01:00:00.000Z", true],
|
||||
] as const)("handles %s", (_name, timestamp, expected) => {
|
||||
expect(isPeakPricing(new Date(timestamp))).toBe(expected)
|
||||
})
|
||||
})
|
||||
Loading…
Reference in a new issue