Skip to content

Feat/crofai plugin#460

Open
briepala wants to merge 4 commits into
robinebers:mainfrom
briepala:feat/crofai-plugin
Open

Feat/crofai plugin#460
briepala wants to merge 4 commits into
robinebers:mainfrom
briepala:feat/crofai-plugin

Conversation

@briepala
Copy link
Copy Markdown

@briepala briepala commented May 10, 2026

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 against GET /usage_api/ to retrieve usable
requests and credit balance. Optionally reads CROF_AI_SESSION_KEY (env var or file) to fetch plan limits from GET /pricing_api and per-model token
breakdown from GET /user-api/usage via session cookie.

Progress bar limit resolves from: pricing API (with session key) → usage API requests_plan field → 15000 fallback. Response validation rejects
malformed, 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

  • Bug fix
  • New feature
  • New provider plugin
  • Documentation
  • Performance improvement
  • Other (describe below)

Testing

  • I ran bun run build and it succeeded
  • I ran bun run test and all tests pass (1158 tests, 61 files)
  • I tested the change locally with bun tauri dev

Screenshots

Dashboard view
Screenshot 2026-05-10 at 12 41 44

Provider view
Screenshot 2026-05-10 at 12 42 04

Checklist

  • I read CONTRIBUTING.md
  • My PR targets the main branch
  • I did not introduce new dependencies without justification

Summary by cubic

Adds a bundled crofai provider plugin that shows requests usage, credit balance, and per-model token usage with strict fallbacks and validation. Also whitelists CROF_AI_* env vars, adds docs, and a full test suite.

  • New Features

    • New crofai plugin using GET /usage_api/ (API key) and optionally GET /pricing_api + GET /user-api/usage (session key).
    • Progress bar limit resolves from pricing.requests → usage.requests_plan → 15000 fallback.
    • Shows credits (omits negative) and total tokens with top 5 models; compact K/M/B formatting.
    • Strict validation, including numeric-only checks for per-model tokens (rejects strings/booleans/objects/Infinity/NaN/negatives); 10s timeouts.
    • Maps plan names to friendly labels; docs at docs/providers/crofai.md, README entry, icon, and extensive tests for edge cases.
  • Migration

    • Set CROF_AI_API_KEY (required).
    • Optional: set CROF_AI_SESSION_KEY for plan limits and per-model tokens, or save it to {appDataDir}/plugins_data/crofai/session-key.
    • No code changes needed; env vars are now whitelisted by the host.

Written for commit ea4562b. Summary will update on new commits.

briepala added 3 commits May 10, 2026 12:11
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
@github-actions github-actions Bot added rust Pull requests that update rust code plugin docs labels May 10, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread plugins/crofai/plugin.js Outdated
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.
@validatedev
Copy link
Copy Markdown
Collaborator

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread plugins/crofai/plugin.js
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread plugins/crofai/plugin.js
method: "GET",
url: opts.url,
headers: opts.headers || {},
Accept: "application/json",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs plugin rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants