Feat/crofai plugin#460
Conversation
Adds a new Crof.AI plugin that displays: - Usage progress bar (via usage_api + pricing_api) - Credit balance - Per-model token breakdown (via user-api/usage with optional session key) The plugin reads CROF_AI_API_KEY (required) and optionally CROF_AI_SESSION_KEY for plan details and model-level usage.
Replaces hardcoded 15000 fallback with requests_plan from /usage_api/ response when no session key is available. Falls through to 15000 only when both pricing API and usage API lack plan info. Also updates icon.svg to use the CrofAI letterform logo from /tmp/crofai.svg.
- Credits line omitted when negative (matching PR robinebers#412 pattern) - Added 82 tests covering all edge cases from PR robinebers#412 review - Covers: auth, HTTP errors, response validation, progress bar sources, fallback chains, credits display, plan names, session key sources, token formatting, model sorting, error messages - Previous 30 tests expanded to 82 with 52 new test cases
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="plugins/crofai/plugin.js">
<violation number="1" location="plugins/crofai/plugin.js:156">
P2: Per-model token counts from the usage API are not type-checked before aggregation, so numeric strings or malformed values can corrupt the total tokens display.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
Model total_tokens/totalTokens are now required to be actual numbers via typeof check before aggregation into totalTokens and model list. Rejects strings, booleans, objects, Infinity, NaN, and negatives. Adds 7 tests for type edge cases.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea4562b5f5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for (var key in usageData) { | ||
| if (Object.prototype.hasOwnProperty.call(usageData, key)) { | ||
| var model = usageData[key]; | ||
| var rawTt = model.total_tokens !== undefined ? model.total_tokens : model.totalTokens; |
There was a problem hiding this comment.
Guard model entry before reading token fields
If user-api/usage returns any key with null or undefined value, model.total_tokens throws a runtime TypeError, so the whole probe fails instead of just skipping that bad entry. This is especially impactful because this endpoint is optional and already wrapped in best-effort behavior; one malformed model record can currently break all Crof.AI output for that refresh.
Useful? React with 👍 / 👎.
| method: "GET", | ||
| url: opts.url, | ||
| headers: opts.headers || {}, | ||
| Accept: "application/json", |
There was a problem hiding this comment.
Move Accept header into the request headers map
The Accept value is set at the top level of the request object, not inside headers, so it is not forwarded by the host HTTP wrapper (which serializes only req.headers). If Crof.AI enforces content negotiation, this can return non-JSON content and trigger the plugin's "Invalid response" path even with valid credentials.
Useful? React with 👍 / 👎.
Adds a new Crof.AI plugin that displays:
- Usage progress bar (via usage_api + optional pricing_api for plan limits)
- Credit balance
- Per-model token breakdown (via user-api/usage with optional session key)
The plugin reads CROF_AI_API_KEY (required) and optionally CROF_AI_SESSION_KEY for plan details and model-level usage.
Description
Adds the CrofAI provider as a bundled plugin. Reads
CROF_AI_API_KEY(required) for Bearer-token auth againstGET /usage_api/to retrieve usablerequests and credit balance. Optionally reads
CROF_AI_SESSION_KEY(env var or file) to fetch plan limits fromGET /pricing_apiand per-model tokenbreakdown from
GET /user-api/usagevia session cookie.Progress bar limit resolves from: pricing API (with session key) → usage API
requests_planfield → 15000 fallback. Response validation rejectsmalformed, non-finite, or wrong-type fields with clear error messages. Plan names are mapped to full labels (int → Intermediate, hobby → Hobby, etc.).
Negative credits are omitted. Token counts use compact formatting (K/M/B) and models are sorted and capped at 5.
Type of Change
Testing
bun run buildand it succeededbun run testand all tests pass (1158 tests, 61 files)bun tauri devScreenshots
Dashboard view

Provider view

Checklist
mainbranchSummary by cubic
Adds a bundled
crofaiprovider plugin that shows requests usage, credit balance, and per-model token usage with strict fallbacks and validation. Also whitelistsCROF_AI_*env vars, adds docs, and a full test suite.New Features
crofaiplugin usingGET /usage_api/(API key) and optionallyGET /pricing_api+GET /user-api/usage(session key).docs/providers/crofai.md, README entry, icon, and extensive tests for edge cases.Migration
CROF_AI_API_KEY(required).CROF_AI_SESSION_KEYfor plan limits and per-model tokens, or save it to{appDataDir}/plugins_data/crofai/session-key.Written for commit ea4562b. Summary will update on new commits.