feat: add Moonshot and DeepSeek providers (balance-based) (rebase of #68)#107
Merged
Conversation
Mirrors the OpenRouter pattern to track two pay-as-you-go providers whose quotas are exposed as a remaining balance (not cumulative usage). Endpoints: - Moonshot: GET https://api.moonshot.ai/v1/users/me/balance (CNY) - DeepSeek: GET https://api.deepseek.com/user/balance (USD/CNY) Semantic inversion vs OpenRouter: - OpenRouter tracks cumulative usage (grows, resets monthly) -> reset on 50% drop - Moonshot/DeepSeek track balance (decreases on spend, grows on recharge) -> reset on >=50% growth (recharge); TotalDelta cumulates balance drops Files added (mirroring openrouter pattern): - internal/api/{moonshot,deepseek}_{client,types}.go (+tests) - internal/agent/{moonshot,deepseek}_agent.go - internal/store/{moonshot,deepseek}_store.go (+tests, with currency col on deepseek) - internal/tracker/{moonshot,deepseek}_tracker.go (+tests) - internal/web/{moonshot,deepseek}_handlers.go Files modified: - internal/config/config.go: MOONSHOT_API_KEY, DEEPSEEK_API_KEY env vars - internal/store/store.go: schema migrations - internal/web/{handlers,static/app.js,templates/dashboard.html}: dashboard tabs - internal/metrics/metrics.go: onwatch_credits_balance{unit="cny_*"|"usd_*"} gauges - main.go: agent registration Tested live on Linux Mint 22.3 / Cinnamon 6.6.7 / Go 1.25.7: - Moonshot balance: ¥19.47 detected - DeepSeek balance: $34.69 detected - 1224 unit tests pass (api/store/tracker packages) Note: Moonshot endpoint set to api.moonshot.ai (international). Users on the Chinese moonshot.cn endpoint may need to patch the baseURL or expose it via env (suggested follow-up). Co-Authored-By: Jules <noreply@jules.google> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
# Conflicts: # internal/web/static/app.js # internal/web/templates/dashboard.html # main.go
The dashboard now renders provider tabs as <img src=/static/icons/{provider}.svg>
(added after this PR was opened), so Moonshot/DeepSeek need real icons or the
tab shows a broken image (dashboard CSP blocks an inline onerror fallback).
- add moonshot.svg (crescent) + deepseek.svg (magnifier) icons matching existing format
- dashboard_tabs.go: proper labels (Moonshot, DeepSeek) instead of title-case fallback
- menubar.html: tray icon classes + switch cases so they don't fall back to the OpenAI icon
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
Conflict-resolution/rebase of #68 onto current main, plus minimal required fixes. Original work by @papajade55-debug (commits preserved via merge).
Security review (clean)
MOONSHOT_API_KEY/DEEPSEEK_API_KEYis set (no default-on).redactAPIKey), never logged.Conflicts resolved (keep-both: moonshot/deepseek + grok/kimi)
main.go: merged provider slice;dashboard.html: table headers;app.js: chart datasets + usePercent (moonshot/deepseek stay balance-based, excluded from delta%).Minimal fixes added (separate commit)
moonshot.svg/deepseek.svgicons - the dashboard now renders tabs via<img>, and CSP blocks an inline onerror fallback, so missing icons would show a broken image.Verified:
go build,go vet, and the full test suite pass (isolated HOME).Closes #68.