Skip to content

feat: weekday-aware dynamic pricing schedule (DeepSeek weekend off-peak) - #12

Merged
zhumengzhu merged 2 commits into
mainfrom
feat/weekday-pricing
Aug 23, 2026
Merged

feat: weekday-aware dynamic pricing schedule (DeepSeek weekend off-peak)#12
zhumengzhu merged 2 commits into
mainfrom
feat/weekday-pricing

Conversation

@zhumengzhu

Copy link
Copy Markdown
Owner

Summary

Make the dynamicPricing schedule 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: TimeWindow had 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 empty windows).

What changed

  • types.ts: TimeWindow.days?; DEFAULT_SCHEDULE = peak Mon–Fri + offpeak fallback level
  • schedule.ts: tzWeekdayOf; weekday-aware inWindow (start-day rule for cross-midnight windows); fallback (last-resort) in isLevelAt; weekday-aware nextBoundaryMs (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 without days; 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 badge
  • Docs: README ×2 (migration note + badge semantics), design ×2, dynamic-pricing-plan, example config $comment, fetch-deepseek-pricing.ts prints a weekday-aware schedule
  • Version bump 0.7.2

Backward compatibility

  • days omitted or [] = every day — legacy configs behave exactly as before (weekends still peak)
  • To pick up the weekend fix: add "days": [1,2,3,4,5] to peak windows, or adopt the new default schedule (peak Mon–Fri + offpeak fallback)
  • A one-time stderr hint fires when a DeepSeek model is resolved while the configured schedule has windowed levels but no days

Testing

bun test432 tests / 809 assertions, all green. New coverage: weekend→offpeak, fallback semantics, cross-day start-day rule, nextBoundaryMs Fri→Mon, config days parsing/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).

- 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.
@zhumengzhu
zhumengzhu merged commit a50083c into main Aug 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant