feat: weekday-aware dynamic pricing schedule (DeepSeek weekend off-peak) - #12
Merged
Conversation
- TimeWindow gains optional days (ISO 1=Mon..7=Sun; omitted = every day); a level with empty windows is the catch-all fallback level - DEFAULT_SCHEDULE: peak Mon-Fri 09:00-12:00 / 14:00-18:00 Beijing, offpeak fallback covers weekends — no more weekend peak mispricing - isLevelAt: fallback is last-resort (never first-match); tzWeekdayOf added; inWindow applies start-day rule for cross-midnight windows - nextBoundaryMs is weekday-aware (Fri 18:00 -> Mon 09:00), skipping weekend pseudo-boundaries - normalizeSchedule parses days, keeps explicit empty-windows levels, dedupes to at most one fallback; drops all-invalid-window levels - one-time stderr hint when a DeepSeek model resolves against a windowed schedule without days (legacy configs stay compatible) - level badge only when the model prices the current level: plain static models and unpriced levels (e.g. peak-only rule at off-peak) show no peak/offpeak label - docs: README x2 migration note + badge semantics, design x2, dynamic-pricing-plan, example config $comment, fetch-deepseek-pricing prints weekday-aware schedule; version 0.7.2
Code comments were ~29% Chinese, concentrated in the dynamic-pricing module; the rest of the codebase is English. Unify on English comments (no behavior change). The DeepSeek pricing-page regex in fetch-deepseek-pricing.ts keeps Chinese terms (it matches the official page). Also translated the DeepSeek legacy-schedule stderr hint to English for consistency with the other runtime warnings. Bilingual user-facing docs (README/docs zh-CN) and i18n strings are untouched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make the
dynamicPricingschedule weekday-aware so DeepSeek's official weekend off-peak pricing is honored: peak = Mon–Fri 09:00-12:00 / 14:00-18:00 Beijing time; everything else (incl. weekends) is off-peak at 0.5×.Before:
TimeWindowhad no weekday field → Saturdays/Sundays 09-12 & 14-18 were billed as peak (2× overcharge).After: windows accept
days(ISO 1=Mon…7=Sun) + a catch-all fallback level (a level with emptywindows).What changed
types.ts:TimeWindow.days?;DEFAULT_SCHEDULE= peak Mon–Fri +offpeakfallback levelschedule.ts:tzWeekdayOf; weekday-awareinWindow(start-day rule for cross-midnight windows); fallback (last-resort) inisLevelAt; weekday-awarenextBoundaryMs(Fri 18:00 → Mon 09:00, no weekend pseudo-boundaries)plugin-config.ts:normalizeDays(warn+ignore invalid, dedupe, sort); keeps explicit empty-windows levels; ≤1 fallback dedupe; drops all-invalid-window levels (a typo must not silently become a fallback)lookup.ts: one-time stderr hint when a DeepSeek model resolves against a windowed schedule withoutdays; level badge only when the model actually prices the current level — plain static models no longer show "off-peak"/"peak", and a peak-only rule at an off-peak moment shows no badgedynamic-pricing-plan, example config$comment,fetch-deepseek-pricing.tsprints a weekday-aware scheduleBackward compatibility
daysomitted or[]= every day — legacy configs behave exactly as before (weekends still peak)"days": [1,2,3,4,5]topeakwindows, or adopt the new default schedule (peak Mon–Fri +offpeakfallback)daysTesting
bun test— 432 tests / 809 assertions, all green. New coverage: weekend→offpeak, fallback semantics, cross-day start-day rule,nextBoundaryMsFri→Mon, configdaysparsing/dedupe, badge-regression (static models get no level), and the legacy-schedule warning path.Also includes
chore: translate code comments to English(comment-only; bilingual user docs and i18n strings untouched).