-
Notifications
You must be signed in to change notification settings - Fork 2.6k
refactor: Remove exceptions from RooHandler constructor #7302
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -4,29 +4,27 @@ import { CloudService } from "@roo-code/cloud" | |
|
|
||
| import type { ApiHandlerOptions } from "../../shared/api" | ||
| import { ApiStream } from "../transform/stream" | ||
| import { t } from "../../i18n" | ||
|
|
||
| import type { ApiHandlerCreateMessageMetadata } from "../index" | ||
| import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider" | ||
|
|
||
| export class RooHandler extends BaseOpenAiCompatibleProvider<RooModelId> { | ||
| constructor(options: ApiHandlerOptions) { | ||
| // Check if CloudService is available and get the session token. | ||
| if (!CloudService.hasInstance()) { | ||
| throw new Error(t("common:errors.roo.authenticationRequired")) | ||
| } | ||
|
|
||
| const sessionToken = CloudService.instance.authService?.getSessionToken() | ||
| // Get the session token if available, but don't throw if not. | ||
| // The server will handle authentication errors and return appropriate status codes. | ||
| let sessionToken = "" | ||
|
|
||
| if (!sessionToken) { | ||
| throw new Error(t("common:errors.roo.authenticationRequired")) | ||
| if (CloudService.hasInstance()) { | ||
| sessionToken = CloudService.instance.authService?.getSessionToken() || "" | ||
| } | ||
|
|
||
| // Always construct the handler, even without a valid token. | ||
| // The provider-proxy server will return 401 if authentication fails. | ||
| super({ | ||
| ...options, | ||
| providerName: "Roo Code Cloud", | ||
| baseURL: process.env.ROO_CODE_PROVIDER_URL ?? "https://api.roocode.com/proxy/v1", | ||
| apiKey: sessionToken, | ||
| apiKey: sessionToken || "unauthenticated", // Use a placeholder if no token | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the string "unauthenticated" as a placeholder API key could be misleading. Consider using an empty string or a more descriptive placeholder like "NO_AUTH_TOKEN" to make the intent clearer: |
||
| defaultProviderModelId: rooDefaultModelId, | ||
| providerModels: rooModels, | ||
| defaultTemperature: 0.7, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -288,7 +288,24 @@ export const webviewMessageHandler = async ( | |
| // Initializing new instance of Cline will make sure that any | ||
| // agentically running promises in old instance don't affect our new | ||
| // task. This essentially creates a fresh slate for the new task. | ||
| await provider.createTask(message.text, message.images) | ||
| try { | ||
| await provider.createTask(message.text, message.images) | ||
| // Task created successfully - notify the UI to reset | ||
| await provider.postMessageToWebview({ | ||
| type: "invoke", | ||
| invoke: "newChat", | ||
| }) | ||
| } catch (error) { | ||
| // For all errors, reset the UI and show error | ||
| await provider.postMessageToWebview({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling here catches all errors generically but still sends a "newChat" message on error, which might not be the intended behavior. Also, the error message shown to the user doesn't distinguish between authentication errors and other types of errors. Consider:
|
||
| type: "invoke", | ||
| invoke: "newChat", | ||
| }) | ||
| // Show error to user | ||
| vscode.window.showErrorMessage( | ||
| `Failed to create task: ${error instanceof Error ? error.message : String(error)}`, | ||
| ) | ||
| } | ||
| break | ||
| case "customInstructions": | ||
| await provider.updateCustomInstructions(message.text) | ||
|
|
||
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.
Consider adding debug logging when falling back to an empty token (without exposing the actual token value). This could help with debugging authentication issues.