Skip to content

feat: add Moonshot and DeepSeek providers (balance-based) (rebase of #68)#107

Merged
prakersh merged 3 commits into
mainfrom
resolve-pr68
Jul 23, 2026
Merged

feat: add Moonshot and DeepSeek providers (balance-based) (rebase of #68)#107
prakersh merged 3 commits into
mainfrom
resolve-pr68

Conversation

@prakersh

Copy link
Copy Markdown
Contributor

Conflict-resolution/rebase of #68 onto current main, plus minimal required fixes. Original work by @papajade55-debug (commits preserved via merge).

Security review (clean)

  • Providers are opt-in - only enabled when MOONSHOT_API_KEY/DEEPSEEK_API_KEY is set (no default-on).
  • API keys redacted in config debug dump (redactAPIKey), never logged.
  • Bearer auth, response body capped at 64KB, parameterized SQL.

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)

  • Added moonshot.svg/deepseek.svg icons - the dashboard now renders tabs via <img>, and CSP blocks an inline onerror fallback, so missing icons would show a broken image.
  • Proper display labels (Moonshot, DeepSeek) + menubar tray icon cases.

Verified: go build, go vet, and the full test suite pass (isolated HOME).

Closes #68.

papajade55-debug and others added 3 commits April 25, 2026 03:22
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
@prakersh
prakersh merged commit 2019d12 into main Jul 23, 2026
5 checks passed
@prakersh
prakersh deleted the resolve-pr68 branch July 23, 2026 20:40
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.

2 participants