Skip to content

Commit e311f7c

Browse files
committed
Add Requesty OAuth flow
1 parent 4338f64 commit e311f7c

File tree

4 files changed

+62
-12
lines changed

4 files changed

+62
-12
lines changed

src/activate/handleUri.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export const handleUri = async (uri: vscode.Uri) => {
66
const path = uri.path
77
const query = new URLSearchParams(uri.query.replace(/\+/g, "%2B"))
88
const visibleProvider = ClineProvider.getVisibleInstance()
9-
109
if (!visibleProvider) {
1110
return
1211
}
@@ -26,6 +25,13 @@ export const handleUri = async (uri: vscode.Uri) => {
2625
}
2726
break
2827
}
28+
case "/requesty": {
29+
const code = query.get("code")
30+
if (code) {
31+
await visibleProvider.handleRequestyCallback(code)
32+
}
33+
break
34+
}
2935
default:
3036
break
3137
}

src/core/webview/ClineProvider.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,28 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
23152315
// await this.postMessageToWebview({ type: "action", action: "settingsButtonClicked" }) // bad ux if user is on welcome
23162316
}
23172317

2318+
// Requesty
2319+
2320+
async handleRequestyCallback(code: string) {
2321+
const apiKey = code
2322+
const requesty: ApiProvider = "requesty"
2323+
await this.contextProxy.setValues({
2324+
apiProvider: requesty,
2325+
requestyApiKey: apiKey,
2326+
})
2327+
await this.postStateToWebview()
2328+
if (this.getCurrentCline()) {
2329+
this.getCurrentCline()!.api = buildApiHandler({
2330+
apiProvider: requesty,
2331+
requestyApiKey: apiKey,
2332+
})
2333+
}
2334+
2335+
// TODO: Tell user that everything is ready and they can start their first task.
2336+
// await this.postMessageToWebview({ type: "action", action: "settingsButtonClicked" })
2337+
// bad ux if user is on welcome
2338+
}
2339+
23182340
// Task history
23192341

23202342
async getTaskWithId(id: string): Promise<{

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { memo, useCallback, useEffect, useMemo, useState } from "react"
22
import { useAppTranslation } from "@/i18n/TranslationContext"
33
import { Trans } from "react-i18next"
4+
import { getRequestyAuthUrl, getOpenRouterAuthUrl, getGlamaAuthUrl } from "../../oauth/urls"
45
import { useDebounce, useEvent } from "react-use"
56
import { LanguageModelChatSelector } from "vscode"
67
import { Checkbox } from "vscrui"
@@ -279,7 +280,10 @@ const ApiOptions = ({
279280
{t("settings:providers.apiKeyStorageNotice")}
280281
</div>
281282
{!apiConfiguration?.openRouterApiKey && (
282-
<VSCodeButtonLink href={getOpenRouterAuthUrl(uriScheme)} appearance="secondary">
283+
<VSCodeButtonLink
284+
href={getOpenRouterAuthUrl(uriScheme)}
285+
style={{ width: "100%" }}
286+
appearance="primary">
283287
{t("settings:providers.getOpenRouterApiKey")}
284288
</VSCodeButtonLink>
285289
)}
@@ -380,7 +384,10 @@ const ApiOptions = ({
380384
{t("settings:providers.apiKeyStorageNotice")}
381385
</div>
382386
{!apiConfiguration?.glamaApiKey && (
383-
<VSCodeButtonLink href={getGlamaAuthUrl(uriScheme)} appearance="secondary">
387+
<VSCodeButtonLink
388+
href={getGlamaAuthUrl(uriScheme)}
389+
style={{ width: "100%" }}
390+
appearance="primary">
384391
{t("settings:providers.getGlamaApiKey")}
385392
</VSCodeButtonLink>
386393
)}
@@ -400,6 +407,14 @@ const ApiOptions = ({
400407
<div className="text-sm text-vscode-descriptionForeground -mt-2">
401408
{t("settings:providers.apiKeyStorageNotice")}
402409
</div>
410+
{!apiConfiguration?.requestyApiKey && (
411+
<VSCodeButtonLink
412+
href={getRequestyAuthUrl(uriScheme)}
413+
style={{ width: "100%" }}
414+
appearance="primary">
415+
{t("settings:providers.getRequestyApiKey")}
416+
</VSCodeButtonLink>
417+
)}
403418
</>
404419
)}
405420

@@ -1536,15 +1551,6 @@ const ApiOptions = ({
15361551
)
15371552
}
15381553

1539-
export function getGlamaAuthUrl(uriScheme?: string) {
1540-
const callbackUrl = `${uriScheme || "vscode"}://rooveterinaryinc.roo-cline/glama`
1541-
return `https://glama.ai/oauth/authorize?callback_url=${encodeURIComponent(callbackUrl)}`
1542-
}
1543-
1544-
export function getOpenRouterAuthUrl(uriScheme?: string) {
1545-
return `https://openrouter.ai/auth?callback_url=${uriScheme || "vscode"}://rooveterinaryinc.roo-cline/openrouter`
1546-
}
1547-
15481554
export function normalizeApiConfiguration(apiConfiguration?: ApiConfiguration) {
15491555
const provider = apiConfiguration?.apiProvider || "anthropic"
15501556
const modelId = apiConfiguration?.apiModelId

webview-ui/src/oauth/urls.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function getCallbackUrl(provider: string, uriScheme?: string) {
2+
const callbackUrl = `${uriScheme || "vscode"}://rooveterinaryinc.roo-cline/${provider}`
3+
return encodeURIComponent(callbackUrl)
4+
}
5+
6+
export function getGlamaAuthUrl(uriScheme?: string) {
7+
return `https://glama.ai/oauth/authorize?callback_url=${getCallbackUrl("glama", uriScheme)}`
8+
}
9+
10+
export function getOpenRouterAuthUrl(uriScheme?: string) {
11+
return `https://openrouter.ai/auth?callback_url=${getCallbackUrl("openrouter", uriScheme)}`
12+
}
13+
14+
export function getRequestyAuthUrl(uriScheme?: string) {
15+
return `https://app.requesty.ai/oauth/authorize?callback_url=${getCallbackUrl("requesty", uriScheme)}`
16+
}

0 commit comments

Comments
 (0)