-
Notifications
You must be signed in to change notification settings - Fork 625
feat: add usage for cherryin #998
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
feat: add usage for cherryin #998
Conversation
WalkthroughAdds 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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.vuesrc/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.vuesrc/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.vuesrc/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 insrc/main/presenter/llmProviderPresenter/providers/*.tsshould 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 acoreStreammethod that yields standardized stream events to decouple the main loop from provider-specific details.
ThecoreStreammethod 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 asformatMessages,convertToProviderTools,parseFunctionCalls, andprepareFunctionCallPromptas 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., usingconvertToProviderTools) 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 appropriatestop_reasonin 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 Dividingtotal_usageby 100 properly converts cents to USD per CherryIn API documentation.
| const usageResponse = await fetch(`${baseUrl}/dashboard/billing/usage`, { | ||
| method: 'GET', | ||
| headers | ||
| }) |
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.
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.
| [ | ||
| 'ppio', | ||
| 'openrouter', | ||
| 'siliconcloud', | ||
| 'silicon', | ||
| 'deepseek', | ||
| '302ai', | ||
| 'cherryin' | ||
| ].includes(props.provider.id) && |
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.
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.
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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.vuesrc/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.vuesrc/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.vuesrc/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 insrc/main/presenter/llmProviderPresenter/providers/*.tsshould 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 acoreStreammethod that yields standardized stream events to decouple the main loop from provider-specific details.
ThecoreStreammethod 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 asformatMessages,convertToProviderTools,parseFunctionCalls, andprepareFunctionCallPromptas 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., usingconvertToProviderTools) 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 appropriatestop_reasonin 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/usageortotal_usagewere found in the repo or public docs. Please confirm:
- The correct usage endpoint for the CherryIn API.
- That
total_usageis returned in cents (so dividing by 100 yields USD).
| const usageResponse = await fetch(`${baseUrl}/dashboard/billing/usage`, { | ||
| method: 'GET', | ||
| headers | ||
| }) |
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.
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.
| 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.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68edfd1be158832cae2afcb6e2206dfa
Summary by CodeRabbit