mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-24 06:33:01 -04:00
fix(console): support DeepSeek weekend pricing
This commit is contained in:
@@ -53,6 +53,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"
|
||||
|
||||
type ZenData = Awaited<ReturnType<typeof ZenData.list>>
|
||||
type RetryOptions = {
|
||||
@@ -1048,9 +1049,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
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export function isPeakPricing(date: Date) {
|
||||
const hour = date.getUTCHours()
|
||||
// DeepSeek defines weekends in Beijing time, which is fixed at UTC+8.
|
||||
const dayInBeijing = new Date(date.getTime() + 8 * 60 * 60 * 1000).getUTCDay()
|
||||
if (dayInBeijing === 0 || dayInBeijing === 6) return false
|
||||
return (hour >= 1 && hour < 4) || (hour >= 6 && hour < 10)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { isPeakPricing } from "../src/routes/zen/util/pricing"
|
||||
|
||||
describe("isPeakPricing", () => {
|
||||
test.each([
|
||||
["weekday first window starts", "2026-08-27T01:00:00.000Z", true],
|
||||
["weekday first window ends", "2026-08-27T04:00:00.000Z", false],
|
||||
["weekday second window starts", "2026-08-27T06:00:00.000Z", true],
|
||||
["weekday second window ends", "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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user