-
Notifications
You must be signed in to change notification settings - Fork 16
Add platform-specific quota implementations and improve error handling #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3929fe6
5429fa5
5da5814
494a622
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # PROJECT KNOWLEDGE BASE | ||
|
|
||
| **Generated:** 2026-02-26 | ||
| **Commit:** 196eed3 | ||
| **Branch:** main | ||
|
|
||
| ## OVERVIEW | ||
|
|
||
| OpenCode plugin for querying AI platform quotas. TypeScript + Node.js, supports OpenAI, Zhipu AI, Z.ai, GitHub Copilot, Google Antigravity. | ||
|
|
||
| ## STRUCTURE | ||
|
|
||
| ``` | ||
| ./ | ||
| ├── plugin/ # Source code | ||
| │ ├── mystatus.ts # Main entry (MyStatusPlugin) | ||
| │ └── lib/ # Platform implementations | ||
| ├── command/ # /mystatus command template | ||
| ├── assets/ # Banner images | ||
| └── .github/ # CI workflow | ||
| ``` | ||
|
|
||
| ## WHERE TO LOOK | ||
|
|
||
| | Task | Location | Notes | | ||
| | ---------------- | ------------------- | ----------------------------------------- | | ||
| | Add new platform | plugin/lib/ | Copy existing platform module pattern | | ||
| | Plugin entry | plugin/mystatus.ts | Tool definition + parallel query dispatch | | ||
| | Types | plugin/lib/types.ts | AuthData, QueryResult, platform types | | ||
| | i18n | plugin/lib/i18n.ts | Chinese/English translations | | ||
|
|
||
| ## CODE MAP | ||
|
|
||
| | Symbol | Type | Location | Role | | ||
| | ----------------- | --------- | -------------- | -------------------- | | ||
| | MyStatusPlugin | Plugin | mystatus.ts | Main export | | ||
| | queryOpenAIUsage | fn | lib/openai.ts | OpenAI quota | | ||
| | queryZhipuUsage | fn | lib/zhipu.ts | Zhipu AI | | ||
| | queryZaiUsage | fn | lib/zhipu.ts | Z.ai | | ||
| | queryGoogleUsage | fn | lib/google.ts | Google Antigravity | | ||
| | queryCopilotUsage | fn | lib/copilot.ts | GitHub Copilot | | ||
| | QueryResult | interface | lib/types.ts | Platform result type | | ||
| | AuthData | interface | lib/types.ts | Auth structure | | ||
|
|
||
| ## CONVENTIONS | ||
|
|
||
| - **Module pattern**: Each platform in own file under lib/ | ||
| - **Exports**: Single function `queryXxxUsage(auth)` returning `Promise<QueryResult | null>` | ||
| - **Comments**: JSDoc with [输入][输出][定位][同步] fields | ||
| - **Error handling**: Return `{success: false, error: string}` on failure | ||
|
|
||
| ## ANTI-PATTERNS (THIS PROJECT) | ||
|
|
||
| - NO tests - manual verification only | ||
| - NO `any` types - strict TypeScript | ||
| - NO default exports - named exports only | ||
|
|
||
| ## UNIQUE STYLES | ||
|
|
||
| - Progress bars in output (█ characters) | ||
| - JWT token parsing for email extraction | ||
| - Parallel Promise.all for all platform queries | ||
| - Chinese comments, English UI output | ||
|
|
||
| ## COMMANDS | ||
|
|
||
| ```bash | ||
| npm run build # Compile to dist/ | ||
| npm run typecheck # Type check only | ||
| npm run lint # ESLint | ||
| npm run format # Prettier | ||
| ``` | ||
|
|
||
| ## NOTES | ||
|
|
||
| - Auth read from: `~/.local/share/opencode/auth.json` | ||
| - Google reads from: `~/.config/opencode/antigravity-accounts.json` | ||
| - Only plugin/\*.ts included in build (tsconfig.json) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||
| # plugin/lib/ - Platform Implementations | ||||||
|
|
||||||
| **Parent:** ./AGENTS.md | ||||||
|
|
||||||
| ## OVERVIEW | ||||||
|
|
||||||
| Platform-specific quota query implementations. Each file handles one AI provider. | ||||||
|
|
||||||
| ## FILES | ||||||
|
|
||||||
| | File | Platform | Auth Source | | ||||||
| | ---------- | ------------------ | -------------------- | | ||||||
| | openai.ts | OpenAI (ChatGPT) | OAuth access token | | ||||||
| | zhipu.ts | Zhipu AI + Z.ai | API key | | ||||||
| | google.ts | Google Antigravity | OAuth refresh token | | ||||||
| | copilot.ts | GitHub Copilot | OAuth + optional PAT | | ||||||
| | types.ts | Shared types | - | | ||||||
| | utils.ts | Helpers | - | | ||||||
| | i18n.ts | Translations | - | | ||||||
|
|
||||||
| ## PATTERN (Adding New Platform) | ||||||
|
|
||||||
| ```typescript | ||||||
| // 1. Add types to types.ts | ||||||
| export interface XxxAuthData { | ||||||
| type: string; | ||||||
| key?: string; | ||||||
| } | ||||||
|
|
||||||
| // 2. Create lib/xxx.ts with: | ||||||
| export async function queryXxxUsage( | ||||||
| authData: XxxAuthData | undefined, | ||||||
| ): Promise<QueryResult | null> { | ||||||
| if (!authData || !authData.key) return null; | ||||||
| try { | ||||||
| const data = await fetchXxxData(authData.key); | ||||||
| return { success: true, output: formatXxxUsage(data) }; | ||||||
| } catch (err) { | ||||||
| return { | ||||||
| success: false, | ||||||
| error: err instanceof Error ? err.message : String(err), | ||||||
| }; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // 3. Export from mystatus.ts and add to Promise.all | ||||||
|
||||||
| // 3. Export from mystatus.ts and add to Promise.all | |
| // 3. Export from mystatus.ts and add to the platforms array with timeout configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 62 states "Parallel Promise.all for all platform queries", but the implementation now uses
Promise.allSettledinstead ofPromise.all(see mystatus.ts line 129). This is an important architectural change that ensures one failing platform doesn't block others.The documentation should be updated to:
"- Parallel Promise.allSettled with independent timeouts for platform queries"
This accurately reflects the new implementation and the important guarantee it provides about platform independence.