Skip to content

Commit b4058ed

Browse files
common region-to-url function and localize more strings
1 parent 11090ca commit b4058ed

File tree

22 files changed

+137
-41
lines changed

22 files changed

+137
-41
lines changed

src/api/providers/fetchers/ibm-watsonx.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,22 @@ export async function getWatsonxModels(
147147
)
148148
}
149149
}
150+
151+
/**
152+
* Returns the base URL for IBM Watsonx services corresponding to the given region.
153+
*
154+
* @param region - The region identifier (e.g., "us-south", "eu-de").
155+
* @returns The base URL as a string for the specified region, or `undefined` if the region is not recognized.
156+
*/
157+
export function regionToWatsonxBaseUrl(region: string): string {
158+
const regionToUrl: Record<string, string> = {
159+
"us-south": "https://us-south.ml.cloud.ibm.com",
160+
"eu-de": "https://eu-de.ml.cloud.ibm.com",
161+
"eu-gb": "https://eu-gb.ml.cloud.ibm.com",
162+
"jp-tok": "https://jp-tok.ml.cloud.ibm.com",
163+
"au-syd": "https://au-syd.ml.cloud.ibm.com",
164+
"ca-tor": "https://ca-tor.ml.cloud.ibm.com",
165+
"ap-south-1": "https://ap-south-1.aws.wxai.ibm.com",
166+
}
167+
return regionToUrl[region]
168+
}

src/api/providers/ibm-watsonx.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as vscode from "vscode"
21
import { Anthropic } from "@anthropic-ai/sdk"
32
import { ModelInfo, watsonxDefaultModelId, watsonxModels, WatsonxAIModelId } from "@roo-code/types"
43
import type { ApiHandlerOptions } from "../../shared/api"
@@ -9,6 +8,7 @@ import type { SingleCompletionHandler, ApiHandlerCreateMessageMetadata } from ".
98
import { WatsonXAI } from "@ibm-cloud/watsonx-ai"
109
import { calculateApiCostOpenAI } from "../../shared/cost"
1110
import { convertToOpenAiMessages } from "../transform/openai-format"
11+
import { regionToWatsonxBaseUrl } from "./fetchers/ibm-watsonx"
1212

1313
export class WatsonxAIHandler extends BaseProvider implements SingleCompletionHandler {
1414
private options: ApiHandlerOptions
@@ -24,12 +24,17 @@ export class WatsonxAIHandler extends BaseProvider implements SingleCompletionHa
2424
throw new Error("You must provide a valid IBM watsonx project ID.")
2525
}
2626

27-
const serviceUrl = this.options.watsonxBaseUrl
27+
let serviceUrl = this.options.watsonxBaseUrl
2828
const platform = this.options.watsonxPlatform
2929

30+
if (platform === "ibmCloud" && !serviceUrl && this.options.watsonxRegion) {
31+
serviceUrl = regionToWatsonxBaseUrl(this.options.watsonxRegion)
32+
}
33+
3034
if (!platform) {
3135
throw new Error("Platform selection is required for IBM watsonx AI provider")
3236
}
37+
3338
if (!serviceUrl) {
3439
throw new Error("Base URL in IBM watsonx AI provider is required")
3540
}

src/core/webview/webviewMessageHandler.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const ALLOWED_VSCODE_SETTINGS = new Set(["terminal.integrated.inheritEnv"])
6060

6161
import { MarketplaceManager, MarketplaceItemType } from "../../services/marketplace"
6262
import { setPendingTodoList } from "../tools/updateTodoListTool"
63-
import { getWatsonxModels } from "../../api/providers/fetchers/ibm-watsonx"
63+
import { getWatsonxModels, regionToWatsonxBaseUrl } from "../../api/providers/fetchers/ibm-watsonx"
6464

6565
export const webviewMessageHandler = async (
6666
provider: ClineProvider,
@@ -1014,8 +1014,10 @@ export const webviewMessageHandler = async (
10141014
"Missing IBM Cloud authentication credentials in IBM watsonx AI provider for IBM watsonx models",
10151015
)
10161016
provider.postMessageToWebview({
1017-
type: "watsonxModels",
1018-
watsonxModels: {},
1017+
type: "singleRouterModelFetchResponse",
1018+
success: false,
1019+
error: "Missing IBM Cloud authentication credentials for IBM watsonx models",
1020+
values: { provider: "ibm-watsonx" },
10191021
})
10201022
return
10211023
}
@@ -1026,8 +1028,10 @@ export const webviewMessageHandler = async (
10261028
"Missing IBM Cloud Pak for Data authentication credentials in IBM watsonx AI provider for IBM watsonx models",
10271029
)
10281030
provider.postMessageToWebview({
1029-
type: "watsonxModels",
1030-
watsonxModels: {},
1031+
type: "singleRouterModelFetchResponse",
1032+
success: false,
1033+
error: "Missing IBM Cloud Pak for Data authentication credentials for IBM watsonx models",
1034+
values: { provider: "ibm-watsonx" },
10311035
})
10321036
return
10331037
}
@@ -1037,8 +1041,10 @@ export const webviewMessageHandler = async (
10371041
"Missing IBM Cloud Pak for Data authentication credentials in IBM watsonx AI provider for IBM watsonx models",
10381042
)
10391043
provider.postMessageToWebview({
1040-
type: "watsonxModels",
1041-
watsonxModels: {},
1044+
type: "singleRouterModelFetchResponse",
1045+
success: false,
1046+
error: "Missing IBM Cloud Pak for Data authentication credentials for IBM watsonx models",
1047+
values: { provider: "ibm-watsonx" },
10421048
})
10431049
return
10441050
}
@@ -1047,16 +1053,7 @@ export const webviewMessageHandler = async (
10471053

10481054
let effectiveBaseUrl = baseUrl
10491055
if (platform === "ibmCloud" && region && !baseUrl) {
1050-
const regionToUrl: Record<string, string> = {
1051-
"us-south": "https://us-south.ml.cloud.ibm.com",
1052-
"eu-de": "https://eu-de.ml.cloud.ibm.com",
1053-
"eu-gb": "https://eu-gb.ml.cloud.ibm.com",
1054-
"jp-tok": "https://jp-tok.ml.cloud.ibm.com",
1055-
"au-syd": "https://au-syd.ml.cloud.ibm.com",
1056-
"ca-tor": "https://ca-tor.ml.cloud.ibm.com",
1057-
"ap-south-1": "https://ap-south-1.aws.wxai.ibm.com",
1058-
}
1059-
effectiveBaseUrl = regionToUrl[region]
1056+
effectiveBaseUrl = regionToWatsonxBaseUrl(region)
10601057
}
10611058

10621059
const watsonxModels = await getWatsonxModels(

webview-ui/src/components/settings/providers/ibm-watsonx.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ export const WatsonxAI = ({
287287
</SelectContent>
288288
</Select>
289289
<div className="text-sm text-vscode-descriptionForeground mt-1">
290-
Selected endpoint: {REGION_TO_URL[selectedRegion as keyof typeof REGION_TO_URL]}
290+
{t("settings:providers.watsonx.selectedEndpoint")}:{" "}
291+
{REGION_TO_URL[selectedRegion as keyof typeof REGION_TO_URL]}
291292
</div>
292293
</div>
293294
)}
@@ -423,7 +424,7 @@ export const WatsonxAI = ({
423424
) : (
424425
<span className="codicon codicon-refresh" />
425426
)}
426-
{"Retrieve Models"}
427+
{t("settings:providers.watsonx.retrieveModels")}
427428
</div>
428429
</Button>
429430
</div>
@@ -434,11 +435,13 @@ export const WatsonxAI = ({
434435
</div>
435436
)}
436437
{refreshStatus === "success" && (
437-
<div className="text-sm text-vscode-foreground mb-1">{"Models retrieved successfully"}</div>
438+
<div className="text-sm text-vscode-foreground mb-1">
439+
{t("settings:providers.watsonx.retrieveSuccessful")}
440+
</div>
438441
)}
439442
{refreshStatus === "error" && (
440443
<div className="text-sm text-vscode-errorForeground mb-1">
441-
{refreshError || "Failed to retrieve models"}
444+
{refreshError || t("settings:providers.watsonx.retrieveError")}
442445
</div>
443446
)}
444447

webview-ui/src/i18n/locales/ca/settings.json

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/de/settings.json

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/en/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,11 @@
502502
"apiKey": "API Key",
503503
"authType": "Authentication type",
504504
"projectId": "Project ID",
505-
"urlDescription": "Enter the full URL of your IBM Cloud Pak for Data instance"
505+
"urlDescription": "Enter the full URL of your IBM Cloud Pak for Data instance",
506+
"selectedEndpoint": "Selected endpoint",
507+
"retrieveModels": "Retrieve Models",
508+
"retrieveSuccessful": "Models retrieved successfully",
509+
"retrieveError": "Failed to retrieve models. Please check your credentials and try again"
506510
}
507511
},
508512
"browser": {

webview-ui/src/i18n/locales/es/settings.json

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/fr/settings.json

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/hi/settings.json

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)