Skip to content

Conversation

@zerob13
Copy link
Collaborator

@zerob13 zerob13 commented Oct 14, 2025

Summary

  • stop requesting CherryIn subscription data and remaining quota since it is inaccurate
  • keep usage retrieval so the settings panel still displays CherryIn consumption information

Testing

  • pnpm run typecheck

https://chatgpt.com/codex/tasks/task_e_68edfd1be158832cae2afcb6e2206dfa

Summary by CodeRabbit

  • New Features
    • Added API key status and usage display for the CherryIn provider in Settings.
    • Introduced a built-in health check for CherryIn keys, providing immediate validation feedback.
  • Bug Fixes
    • Improved error messaging when CherryIn key validation fails, offering clearer guidance to resolve issues.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

Walkthrough

Adds key status and health check capabilities to CherryInProvider, including a base URL helper and response parsing. Updates the settings UI to allow key-status retrieval for the CherryIn provider by whitelisting its ID.

Changes

Cohort / File(s) Summary
CherryIn provider status & health
src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
Introduces getKeyStatus (calls CherryIn usage endpoint, parses total_usage, formats USD), check (wraps getKeyStatus for health), getBaseUrl helper, imports KeyStatus, and a CherryInUsageResponse type.
Renderer UI whitelist update
src/renderer/settings/components/ProviderApiConfig.vue
Extends provider ID whitelist to include 'cherryin' for key-status retrieval when an API key is present.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User (Settings UI)
  participant R as ProviderApiConfig.vue
  participant P as CherryInProvider
  participant A as CherryIn API

  U->>R: Open provider settings
  R->>R: Detect API key + whitelist includes "cherryin"
  R->>P: getKeyStatus()
  P->>P: getBaseUrl()
  P->>A: GET /usage (Authorization: Bearer <key>)
  A-->>P: { total_usage, ... }
  P->>P: Parse, convert to USD, build KeyStatus
  P-->>R: KeyStatus
  R-->>U: Display key usage/status

  rect rgba(255, 230, 200, 0.3)
  note over P,A: Error path
  A--x P: Non-OK / network error
  P-->>R: Throw / error
  R-->>U: Show error (keyStatus = null)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I nibble bytes beneath the cherry sky,
Hop-hop—new checks report and verify.
Keys counted, coins in tidy rows,
A whisper to the UI: “All clear,” it shows.
With gentle thumps I test and run—
Usage tallied, carrots won. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “feat: add usage for cherryin” accurately reflects the primary enhancement of this pull request, which is the addition of usage retrieval functionality for the CherryIn provider. It is concise and clearly indicates the feature being introduced without extraneous detail or ambiguity. The wording aligns with conventional commit style while remaining understandable to a reviewer scanning the history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/add-getkeystatus-billing-interface-implementation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zerob13 zerob13 changed the title Fix CherryIn key status usage reporting feat: add usage for cherryin Oct 14, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62ccaf1 and 3c62a88.

📒 Files selected for processing (2)
  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts (1 hunks)
  • src/renderer/settings/components/ProviderApiConfig.vue (1 hunks)
🧰 Additional context used
📓 Path-based instructions (16)
src/renderer/**/*.{vue,ts,js,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

渲染进程代码放在 src/renderer

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
src/renderer/**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,tsx,vue}: Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
Use TypeScript for all code; prefer types over interfaces.
Avoid enums; use const objects instead.
Use arrow functions for methods and computed properties.
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
src/renderer/**/*.{vue,ts}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

Implement lazy loading for routes and components.

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
src/renderer/**/*.{ts,vue}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,vue}: Use useFetch and useAsyncData for data fetching.
Implement SEO best practices using Nuxt's useHead and useSeoMeta.

Use Pinia for frontend state management (do not introduce alternative state libraries)

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
**/*.{ts,tsx,js,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Use English for all logs and comments

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Enable and adhere to strict TypeScript typing (avoid implicit any, prefer precise types)

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
**/*.{js,jsx,ts,tsx,vue}

📄 CodeRabbit inference engine (AGENTS.md)

Apply Prettier formatting: single quotes, no semicolons, max width 100

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/renderer/**/*.vue

📄 CodeRabbit inference engine (AGENTS.md)

Name Vue components in PascalCase (e.g., ChatInput.vue)

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)

**/*.{js,jsx,ts,tsx}: 使用 OxLint 进行代码检查
Log和注释使用英文书写

**/*.{js,jsx,ts,tsx}: Use OxLint for JS/TS code; pre-commit hooks run lint-staged and typecheck
Use camelCase for variables and functions
Use PascalCase for types and classes
Use SCREAMING_SNAKE_CASE for constants

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/{main,renderer}/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)

src/{main,renderer}/**/*.ts: Use context isolation for improved security
Implement proper inter-process communication (IPC) patterns
Optimize application startup time with lazy loading
Implement proper error handling and logging for debugging

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/main/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)

Use Electron's built-in APIs for file system and native dialogs

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/error-logging.mdc)

**/*.{ts,tsx}: 始终使用 try-catch 处理可能的错误
提供有意义的错误信息
记录详细的错误日志
优雅降级处理
日志应包含时间戳、日志级别、错误代码、错误描述、堆栈跟踪(如适用)、相关上下文信息
日志级别应包括 ERROR、WARN、INFO、DEBUG
不要吞掉错误
提供用户友好的错误信息
实现错误重试机制
避免记录敏感信息
使用结构化日志
设置适当的日志级别

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/main/presenter/llmProviderPresenter/providers/*.ts

📄 CodeRabbit inference engine (.cursor/rules/llm-agent-loop.mdc)

src/main/presenter/llmProviderPresenter/providers/*.ts: Each file in src/main/presenter/llmProviderPresenter/providers/*.ts should handle interaction with a specific LLM API, including request/response formatting, tool definition conversion, native/non-native tool call management, and standardizing output streams to a common event format.
Provider implementations must use a coreStream method that yields standardized stream events to decouple the main loop from provider-specific details.
The coreStream method in each Provider must perform a single streaming API request per conversation round and must not contain multi-round tool call loop logic.
Provider files should implement helper methods such as formatMessages, convertToProviderTools, parseFunctionCalls, and prepareFunctionCallPrompt as needed for provider-specific logic.
All provider implementations must parse provider-specific data chunks and yield standardized events for text, reasoning, tool calls, usage, errors, stop reasons, and image data.
When a provider does not support native function calling, it must prepare messages using prompt wrapping (e.g., prepareFunctionCallPrompt) before making the API call.
When a provider supports native function calling, MCP tools must be converted to the provider's format (e.g., using convertToProviderTools) and included in the API request.
Provider implementations should aggregate and yield usage events as part of the standardized stream.
Provider implementations should yield image data events in the standardized format when applicable.
Provider implementations should yield reasoning events in the standardized format when applicable.
Provider implementations should yield tool call events (tool_call_start, tool_call_chunk, tool_call_end) in the standardized format.
Provider implementations should yield stop events with appropriate stop_reason in the standardized format.
Provider implementations should yield error events in the standardized format...

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/main/**/*.{ts,js,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

主进程代码放在 src/main

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/main/**

📄 CodeRabbit inference engine (AGENTS.md)

Place all Electron main-process code under src/main/

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/main/presenter/**

📄 CodeRabbit inference engine (AGENTS.md)

src/main/presenter/**: Organize main-process presenters under src/main/presenter/ (Window/Tab/Thread/Mcp/Config/LLMProvider)
Follow the Presenter pattern for main-process modules

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
🧬 Code graph analysis (1)
src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts (2)
src/main/presenter/llmProviderPresenter/providers/openAICompatibleProvider.ts (1)
  • OpenAICompatibleProvider (69-1499)
src/shared/types/presenters/legacy.presenters.d.ts (1)
  • IConfigPresenter (380-542)
🪛 GitHub Actions: PR Check
src/renderer/settings/components/ProviderApiConfig.vue

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

🔇 Additional comments (6)
src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts (6)

1-1: LGTM!

The KeyStatus import is correctly added to support the new getKeyStatus method.


4-6: LGTM!

The internal type definition accurately models the expected billing API response structure.


13-15: LGTM!

The helper method correctly normalizes the base URL by removing trailing slashes and providing a sensible default.


33-38: LGTM!

The error handling properly captures the status code, status text, and response body for detailed diagnostics.


51-66: LGTM!

The check method properly wraps getKeyStatus with comprehensive error handling and returns a structured result suitable for validation flows.


42-48: USD conversion is correct Dividing total_usage by 100 properly converts cents to USD per CherryIn API documentation.

Comment on lines +28 to +31
const usageResponse = await fetch(`${baseUrl}/dashboard/billing/usage`, {
method: 'GET',
headers
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add timeout to prevent indefinite hangs.

The fetch call lacks a timeout, which could cause the key status check to hang indefinitely if the CherryIn API is unresponsive.

Apply this diff to add an AbortController with timeout:

+    const abortController = new AbortController()
+    const timeoutId = setTimeout(() => abortController.abort(), 10000) // 10 second timeout
+
     const usageResponse = await fetch(`${baseUrl}/dashboard/billing/usage`, {
       method: 'GET',
-      headers
+      headers,
+      signal: abortController.signal
     })
+
+    clearTimeout(timeoutId)

Update error handling to catch AbortError:

} catch (error: unknown) {
  if (error instanceof Error && error.name === 'AbortError') {
    throw new Error('CherryIn usage check timed out')
  }
  throw error
}
🤖 Prompt for AI Agents
In src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts around
lines 28-31, the fetch call to `${baseUrl}/dashboard/billing/usage` has no
timeout and can hang; create an AbortController, pass its signal to fetch, set a
timeout (e.g. 5s or configurable) to call controller.abort(), clear the timer
after fetch completes, and update the catch block to detect an AbortError and
throw new Error('CherryIn usage check timed out') while rethrowing other errors.

Comment on lines 208 to 216
[
'ppio',
'openrouter',
'siliconcloud',
'silicon',
'deepseek',
'302ai',
'cherryin'
].includes(props.provider.id) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

LGTM! Fix the Prettier formatting issue.

The addition of 'cherryin' to the key status whitelist is correct and aligns with the new CherryInProvider implementation.

However, the pipeline reports a Prettier formatting failure. Run prettier --write to fix the code style:

#!/bin/bash
# Fix Prettier formatting issues
prettier --write src/renderer/settings/components/ProviderApiConfig.vue
🤖 Prompt for AI Agents
In src/renderer/settings/components/ProviderApiConfig.vue around lines 208 to
216, Prettier reported a formatting failure for the updated array (the added
'cherryin' entry). Re-run Prettier to fix formatting inconsistencies (or run
your project's format command) and commit the resulting changes; alternatively,
manually reformat the array to match the project's Prettier rules (consistent
quotes, spacing, and line breaks) and then run prettier --write
src/renderer/settings/components/ProviderApiConfig.vue before pushing.

@zerob13 zerob13 merged commit 84d1a35 into dev Oct 14, 2025
1 check passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62ccaf1 and f3fd800.

📒 Files selected for processing (2)
  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts (1 hunks)
  • src/renderer/settings/components/ProviderApiConfig.vue (1 hunks)
🧰 Additional context used
📓 Path-based instructions (16)
src/renderer/**/*.{vue,ts,js,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

渲染进程代码放在 src/renderer

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
src/renderer/**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,tsx,vue}: Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
Use TypeScript for all code; prefer types over interfaces.
Avoid enums; use const objects instead.
Use arrow functions for methods and computed properties.
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
src/renderer/**/*.{vue,ts}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

Implement lazy loading for routes and components.

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
src/renderer/**/*.{ts,vue}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,vue}: Use useFetch and useAsyncData for data fetching.
Implement SEO best practices using Nuxt's useHead and useSeoMeta.

Use Pinia for frontend state management (do not introduce alternative state libraries)

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
**/*.{ts,tsx,js,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Use English for all logs and comments

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Enable and adhere to strict TypeScript typing (avoid implicit any, prefer precise types)

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
**/*.{js,jsx,ts,tsx,vue}

📄 CodeRabbit inference engine (AGENTS.md)

Apply Prettier formatting: single quotes, no semicolons, max width 100

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/renderer/**/*.vue

📄 CodeRabbit inference engine (AGENTS.md)

Name Vue components in PascalCase (e.g., ChatInput.vue)

Files:

  • src/renderer/settings/components/ProviderApiConfig.vue
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)

**/*.{js,jsx,ts,tsx}: 使用 OxLint 进行代码检查
Log和注释使用英文书写

**/*.{js,jsx,ts,tsx}: Use OxLint for JS/TS code; pre-commit hooks run lint-staged and typecheck
Use camelCase for variables and functions
Use PascalCase for types and classes
Use SCREAMING_SNAKE_CASE for constants

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/{main,renderer}/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)

src/{main,renderer}/**/*.ts: Use context isolation for improved security
Implement proper inter-process communication (IPC) patterns
Optimize application startup time with lazy loading
Implement proper error handling and logging for debugging

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/main/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)

Use Electron's built-in APIs for file system and native dialogs

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/error-logging.mdc)

**/*.{ts,tsx}: 始终使用 try-catch 处理可能的错误
提供有意义的错误信息
记录详细的错误日志
优雅降级处理
日志应包含时间戳、日志级别、错误代码、错误描述、堆栈跟踪(如适用)、相关上下文信息
日志级别应包括 ERROR、WARN、INFO、DEBUG
不要吞掉错误
提供用户友好的错误信息
实现错误重试机制
避免记录敏感信息
使用结构化日志
设置适当的日志级别

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/main/presenter/llmProviderPresenter/providers/*.ts

📄 CodeRabbit inference engine (.cursor/rules/llm-agent-loop.mdc)

src/main/presenter/llmProviderPresenter/providers/*.ts: Each file in src/main/presenter/llmProviderPresenter/providers/*.ts should handle interaction with a specific LLM API, including request/response formatting, tool definition conversion, native/non-native tool call management, and standardizing output streams to a common event format.
Provider implementations must use a coreStream method that yields standardized stream events to decouple the main loop from provider-specific details.
The coreStream method in each Provider must perform a single streaming API request per conversation round and must not contain multi-round tool call loop logic.
Provider files should implement helper methods such as formatMessages, convertToProviderTools, parseFunctionCalls, and prepareFunctionCallPrompt as needed for provider-specific logic.
All provider implementations must parse provider-specific data chunks and yield standardized events for text, reasoning, tool calls, usage, errors, stop reasons, and image data.
When a provider does not support native function calling, it must prepare messages using prompt wrapping (e.g., prepareFunctionCallPrompt) before making the API call.
When a provider supports native function calling, MCP tools must be converted to the provider's format (e.g., using convertToProviderTools) and included in the API request.
Provider implementations should aggregate and yield usage events as part of the standardized stream.
Provider implementations should yield image data events in the standardized format when applicable.
Provider implementations should yield reasoning events in the standardized format when applicable.
Provider implementations should yield tool call events (tool_call_start, tool_call_chunk, tool_call_end) in the standardized format.
Provider implementations should yield stop events with appropriate stop_reason in the standardized format.
Provider implementations should yield error events in the standardized format...

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/main/**/*.{ts,js,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

主进程代码放在 src/main

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/main/**

📄 CodeRabbit inference engine (AGENTS.md)

Place all Electron main-process code under src/main/

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
src/main/presenter/**

📄 CodeRabbit inference engine (AGENTS.md)

src/main/presenter/**: Organize main-process presenters under src/main/presenter/ (Window/Tab/Thread/Mcp/Config/LLMProvider)
Follow the Presenter pattern for main-process modules

Files:

  • src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts
🧬 Code graph analysis (1)
src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts (2)
src/main/presenter/llmProviderPresenter/providers/openAICompatibleProvider.ts (1)
  • OpenAICompatibleProvider (69-1499)
src/shared/types/presenters/legacy.presenters.d.ts (1)
  • IConfigPresenter (380-542)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-check (x64)
🔇 Additional comments (6)
src/renderer/settings/components/ProviderApiConfig.vue (1)

208-208: LGTM! CherryIn added to key status whitelist.

The addition of 'cherryin' to the provider ID whitelist correctly enables key status retrieval in the UI, consistent with the PR objective to display usage information.

src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts (5)

1-1: LGTM! KeyStatus import added.

The KeyStatus import is correctly added to support the new getKeyStatus() method's return type.


4-6: LGTM! Response interface correctly defined.

The CherryInUsageResponse interface provides appropriate type safety for parsing the API response.


13-15: LGTM! URL normalization helper is well-implemented.

The getBaseUrl() helper correctly normalizes the base URL and removes trailing slashes, providing a consistent URL format for API calls.


51-66: Well-structured error handling.

The check() method follows best practices for error handling:

  • Proper try-catch block
  • Normalizes different error types
  • Provides meaningful error messages
  • Logs errors appropriately

However, ensure the timeout issue in getKeyStatus() is resolved, as this method depends on it.


28-44: Validate CherryIn billing endpoint and currency conversion
No references to /dashboard/billing/usage or total_usage were found in the repo or public docs. Please confirm:

  1. The correct usage endpoint for the CherryIn API.
  2. That total_usage is returned in cents (so dividing by 100 yields USD).

Comment on lines +28 to +31
const usageResponse = await fetch(`${baseUrl}/dashboard/billing/usage`, {
method: 'GET',
headers
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Add timeout to prevent indefinite blocking.

The fetch call lacks a timeout, which can cause the main process to hang indefinitely if the API is unresponsive. This violates the guideline about "blocking calls without timeouts on request threads."

Apply this diff to add a timeout:

-    const usageResponse = await fetch(`${baseUrl}/dashboard/billing/usage`, {
-      method: 'GET',
-      headers
-    })
+    const controller = new AbortController()
+    const timeoutId = setTimeout(() => controller.abort(), 10000) // 10 second timeout
+    
+    try {
+      const usageResponse = await fetch(`${baseUrl}/dashboard/billing/usage`, {
+        method: 'GET',
+        headers,
+        signal: controller.signal
+      })
+      clearTimeout(timeoutId)
+      
+      if (!usageResponse.ok) {
+        const errorText = await usageResponse.text()
+        throw new Error(
+          `CherryIn usage check failed: ${usageResponse.status} ${usageResponse.statusText} - ${errorText}`
+        )
+      }
+      
+      const usageData: CherryInUsageResponse = await usageResponse.json()
+      // ... rest of the logic
+    } catch (error) {
+      clearTimeout(timeoutId)
+      if (error.name === 'AbortError') {
+        throw new Error('CherryIn usage check timed out after 10 seconds')
+      }
+      throw error
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const usageResponse = await fetch(`${baseUrl}/dashboard/billing/usage`, {
method: 'GET',
headers
})
// add a timeout to prevent indefinite blocking
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), 10000) // 10 second timeout
try {
const usageResponse = await fetch(`${baseUrl}/dashboard/billing/usage`, {
method: 'GET',
headers,
signal: controller.signal
})
clearTimeout(timeoutId)
if (!usageResponse.ok) {
const errorText = await usageResponse.text()
throw new Error(
`CherryIn usage check failed: ${usageResponse.status} ${usageResponse.statusText} - ${errorText}`
)
}
const usageData: CherryInUsageResponse = await usageResponse.json()
// ... rest of the existing logic to extract total_usage, convert to USD, and return
} catch (error: any) {
clearTimeout(timeoutId)
if (error.name === 'AbortError') {
throw new Error('CherryIn usage check timed out after 10 seconds')
}
throw error
}
🤖 Prompt for AI Agents
In src/main/presenter/llmProviderPresenter/providers/cherryInProvider.ts around
lines 28 to 31, the fetch to `${baseUrl}/dashboard/billing/usage` has no timeout
and can hang; wrap the fetch in an AbortController, start a timer (e.g.,
setTimeout) that calls controller.abort() after a reasonable timeout (e.g.,
5–10s), pass controller.signal to fetch, clear the timer on success, and handle
the abort error path to return a controlled timeout error/response instead of
leaving the request hanging.

@zerob13 zerob13 deleted the codex/add-getkeystatus-billing-interface-implementation branch January 6, 2026 12:18
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