-
Notifications
You must be signed in to change notification settings - Fork 172
fix(opencode-go): fetch models unconditionally — the /models endpoint is public #437
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
95d0fca
e06e845
a3683a5
4a5684a
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 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,15 +1,20 @@ | ||||||||||||||||||||||||||||||
| import { useCallback } from "react" | ||||||||||||||||||||||||||||||
| import { useCallback, useState, useEffect, useRef } from "react" | ||||||||||||||||||||||||||||||
| import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||
| type ProviderSettings, | ||||||||||||||||||||||||||||||
| type OrganizationAllowList, | ||||||||||||||||||||||||||||||
| type RouterModels, | ||||||||||||||||||||||||||||||
| type ExtensionMessage, | ||||||||||||||||||||||||||||||
| opencodeGoDefaultModelId, | ||||||||||||||||||||||||||||||
| } from "@roo-code/types" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import type { RouterName } from "@roo/api" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import { vscode } from "@src/utils/vscode" | ||||||||||||||||||||||||||||||
| import { useAppTranslation } from "@src/i18n/TranslationContext" | ||||||||||||||||||||||||||||||
| import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink" | ||||||||||||||||||||||||||||||
| import { Button } from "@src/components/ui" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import { inputEventTransform } from "../transforms" | ||||||||||||||||||||||||||||||
| import { ModelPicker } from "../ModelPicker" | ||||||||||||||||||||||||||||||
|
|
@@ -32,6 +37,34 @@ export const OpenCodeGo = ({ | |||||||||||||||||||||||||||||
| simplifySettings, | ||||||||||||||||||||||||||||||
| }: OpenCodeGoProps) => { | ||||||||||||||||||||||||||||||
| const { t } = useAppTranslation() | ||||||||||||||||||||||||||||||
| const [refreshStatus, setRefreshStatus] = useState<"idle" | "loading" | "success" | "error">("idle") | ||||||||||||||||||||||||||||||
| const [refreshError, setRefreshError] = useState<string | undefined>() | ||||||||||||||||||||||||||||||
| const errorJustReceived = useRef(false) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||
| const handleMessage = (event: MessageEvent<ExtensionMessage>) => { | ||||||||||||||||||||||||||||||
| const message = event.data | ||||||||||||||||||||||||||||||
| if (message.type === "singleRouterModelFetchResponse" && !message.success) { | ||||||||||||||||||||||||||||||
| const providerName = message.values?.provider as RouterName | ||||||||||||||||||||||||||||||
| if (providerName === "opencode-go") { | ||||||||||||||||||||||||||||||
| errorJustReceived.current = true | ||||||||||||||||||||||||||||||
| setRefreshStatus("error") | ||||||||||||||||||||||||||||||
| setRefreshError(message.error) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } else if (message.type === "routerModels") { | ||||||||||||||||||||||||||||||
| if (refreshStatus === "loading") { | ||||||||||||||||||||||||||||||
| if (!errorJustReceived.current) { | ||||||||||||||||||||||||||||||
| setRefreshStatus("success") | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+59
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. Gate success state to Opencode-Go responses only. While loading, any Suggested fix- } else if (message.type === "routerModels") {
+ } else if (message.type === "routerModels") {
+ const providerName = message.values?.provider
if (refreshStatus === "loading") {
- if (!errorJustReceived.current) {
+ if (providerName === "opencode-go" && !errorJustReceived.current) {
setRefreshStatus("success")
}
}
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| window.addEventListener("message", handleMessage) | ||||||||||||||||||||||||||||||
| return () => { | ||||||||||||||||||||||||||||||
| window.removeEventListener("message", handleMessage) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }, [refreshStatus]) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const handleInputChange = useCallback( | ||||||||||||||||||||||||||||||
| <K extends keyof ProviderSettings, E>( | ||||||||||||||||||||||||||||||
|
|
@@ -44,6 +77,16 @@ export const OpenCodeGo = ({ | |||||||||||||||||||||||||||||
| [setApiConfigurationField], | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const handleRefreshModels = useCallback(() => { | ||||||||||||||||||||||||||||||
| errorJustReceived.current = false | ||||||||||||||||||||||||||||||
| setRefreshStatus("loading") | ||||||||||||||||||||||||||||||
| setRefreshError(undefined) | ||||||||||||||||||||||||||||||
| vscode.postMessage({ | ||||||||||||||||||||||||||||||
| type: "requestRouterModels", | ||||||||||||||||||||||||||||||
| values: { provider: "opencode-go", refresh: true, opencodeGoApiKey: apiConfiguration.opencodeGoApiKey }, | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
| }, [apiConfiguration.opencodeGoApiKey]) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||
| <VSCodeTextField | ||||||||||||||||||||||||||||||
|
|
@@ -62,6 +105,33 @@ export const OpenCodeGo = ({ | |||||||||||||||||||||||||||||
| {t("settings:providers.getOpencodeGoApiKey")} | ||||||||||||||||||||||||||||||
| </VSCodeButtonLink> | ||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||
| variant="outline" | ||||||||||||||||||||||||||||||
| onClick={handleRefreshModels} | ||||||||||||||||||||||||||||||
| disabled={refreshStatus === "loading"} | ||||||||||||||||||||||||||||||
| className="w-full"> | ||||||||||||||||||||||||||||||
| <div className="flex items-center gap-2"> | ||||||||||||||||||||||||||||||
| {refreshStatus === "loading" ? ( | ||||||||||||||||||||||||||||||
| <span className="codicon codicon-loading codicon-modifier-spin" /> | ||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||
| <span className="codicon codicon-refresh" /> | ||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||
| {t("settings:providers.refreshModels.label")} | ||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||
| {refreshStatus === "loading" && ( | ||||||||||||||||||||||||||||||
| <div className="text-sm text-vscode-descriptionForeground"> | ||||||||||||||||||||||||||||||
| {t("settings:providers.refreshModels.loading")} | ||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||
| {refreshStatus === "success" && ( | ||||||||||||||||||||||||||||||
| <div className="text-sm text-vscode-foreground">{t("settings:providers.refreshModels.success")}</div> | ||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||
| {refreshStatus === "error" && ( | ||||||||||||||||||||||||||||||
| <div className="text-sm text-vscode-errorForeground"> | ||||||||||||||||||||||||||||||
| {refreshError || t("settings:providers.refreshModels.error")} | ||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||
| <ModelPicker | ||||||||||||||||||||||||||||||
| apiConfiguration={apiConfiguration} | ||||||||||||||||||||||||||||||
| setApiConfigurationField={setApiConfigurationField} | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
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.
Wrap the variable declaration in a block to fix scoping issue.
The
const opencodeGoApiKeydeclaration inside the switch case should be wrapped in curly braces to prevent potential scoping conflicts with other switch clauses.🔧 Proposed fix
As per coding guidelines, Biome flagged: "Other switch clauses can erroneously access this declaration. Wrap the declaration in a block to restrict its access to the switch clause."
🧰 Tools
🪛 Biome (2.4.16)
[error] 1021-1021: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
(lint/correctness/noSwitchDeclarations)
🤖 Prompt for AI Agents