Просмотр исходного кода

fix: create new Requesty profile during OAuth (#8699)

Co-authored-by: John Costa <[email protected]>
Thibault Jaigu 2 месяцев назад
Родитель
Сommit
ca10cba3c4

+ 2 - 1
src/activate/handleUri.ts

@@ -30,8 +30,9 @@ export const handleUri = async (uri: vscode.Uri) => {
 		}
 		case "/requesty": {
 			const code = query.get("code")
+			const baseUrl = query.get("baseUrl")
 			if (code) {
-				await visibleProvider.handleRequestyCallback(code)
+				await visibleProvider.handleRequestyCallback(code, baseUrl)
 			}
 			break
 		}

+ 13 - 3
src/core/webview/ClineProvider.ts

@@ -95,6 +95,7 @@ import type { ClineMessage } from "@roo-code/types"
 import { readApiMessages, saveApiMessages, saveTaskMessages } from "../task-persistence"
 import { getNonce } from "./getNonce"
 import { getUri } from "./getUri"
+import { REQUESTY_BASE_URL } from "../../shared/utils/requesty"
 
 /**
  * https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
@@ -1470,8 +1471,8 @@ export class ClineProvider
 
 	// Requesty
 
-	async handleRequestyCallback(code: string) {
-		let { apiConfiguration, currentApiConfigName = "default" } = await this.getState()
+	async handleRequestyCallback(code: string, baseUrl: string | null) {
+		let { apiConfiguration } = await this.getState()
 
 		const newConfiguration: ProviderSettings = {
 			...apiConfiguration,
@@ -1480,7 +1481,16 @@ export class ClineProvider
 			requestyModelId: apiConfiguration?.requestyModelId || requestyDefaultModelId,
 		}
 
-		await this.upsertProviderProfile(currentApiConfigName, newConfiguration)
+		// set baseUrl as undefined if we don't provide one
+		// or if it is the default requesty url
+		if (!baseUrl || baseUrl === REQUESTY_BASE_URL) {
+			newConfiguration.requestyBaseUrl = undefined
+		} else {
+			newConfiguration.requestyBaseUrl = baseUrl
+		}
+
+		const profileName = `Requesty (${new Date().toLocaleString()})`
+		await this.upsertProviderProfile(profileName, newConfiguration)
 	}
 
 	// Task history

+ 1 - 1
src/shared/utils/requesty.ts

@@ -1,4 +1,4 @@
-const REQUESTY_BASE_URL = "https://router.requesty.ai/v1"
+export const REQUESTY_BASE_URL = "https://router.requesty.ai/v1"
 
 type URLType = "router" | "app" | "api"
 

+ 13 - 15
webview-ui/src/components/settings/providers/Requesty.tsx

@@ -84,21 +84,19 @@ export const Requesty = ({
 			<div className="text-sm text-vscode-descriptionForeground -mt-2">
 				{t("settings:providers.apiKeyStorageNotice")}
 			</div>
-			{!apiConfiguration?.requestyApiKey && (
-				<a
-					href={getApiKeyUrl()}
-					target="_blank"
-					rel="noopener noreferrer"
-					className="inline-flex items-center justify-center whitespace-nowrap text-sm font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground shadow hover:bg-primary/90 h-9 rounded-md px-3 w-full"
-					style={{
-						width: "100%",
-						textDecoration: "none",
-						color: "var(--vscode-button-foreground)",
-						backgroundColor: "var(--vscode-button-background)",
-					}}>
-					{t("settings:providers.getRequestyApiKey")}
-				</a>
-			)}
+			<a
+				href={getApiKeyUrl()}
+				target="_blank"
+				rel="noopener noreferrer"
+				className="inline-flex items-center justify-center whitespace-nowrap text-sm font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground shadow hover:bg-primary/90 h-9 rounded-md px-3 w-full"
+				style={{
+					width: "100%",
+					textDecoration: "none",
+					color: "var(--vscode-button-foreground)",
+					backgroundColor: "var(--vscode-button-background)",
+				}}>
+				{t("settings:providers.getRequestyApiKey")}
+			</a>
 
 			<VSCodeCheckbox
 				checked={requestyEndpointSelected}

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

@@ -269,7 +269,7 @@
 			"success": "Models list refreshed successfully!",
 			"error": "Failed to refresh models list. Please try again."
 		},
-		"getRequestyApiKey": "Get Requesty API Key",
+		"getRequestyApiKey": "Create new Requesty API Key",
 		"getRequestyBaseUrl": "Base URL",
 		"requestyUseCustomBaseUrl": "Use custom base URL",
 		"openRouterTransformsText": "Compress prompts and message chains to the context size (<a>OpenRouter Transforms</a>)",