Skip to content

Commit 6e5ad0c

Browse files
committed
When called from the onboard flow, created the default profile
Glama OAuth handler changed for consistency.
1 parent 289796e commit 6e5ad0c

File tree

1 file changed

+62
-54
lines changed

1 file changed

+62
-54
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@ import * as vscode from "vscode"
1010

1111
import { changeLanguage, t } from "../../i18n"
1212
import { setPanel } from "../../activate/registerCommands"
13-
import { ApiConfiguration, ApiProvider, ModelInfo, API_CONFIG_KEYS } from "../../shared/api"
13+
import {
14+
ApiConfiguration,
15+
ApiProvider,
16+
ModelInfo,
17+
API_CONFIG_KEYS,
18+
requestyDefaultModelId,
19+
requestyDefaultModelInfo,
20+
openRouterDefaultModelId,
21+
openRouterDefaultModelInfo,
22+
glamaDefaultModelId,
23+
glamaDefaultModelInfo,
24+
} from "../../shared/api"
1425
import { findLast } from "../../shared/array"
1526
import { supportPrompt } from "../../shared/support-prompt"
1627
import { GlobalFileNames } from "../../shared/globalFileNames"
@@ -1811,23 +1822,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
18111822
break
18121823
case "upsertApiConfiguration":
18131824
if (message.text && message.apiConfiguration) {
1814-
try {
1815-
await this.configManager.saveConfig(message.text, message.apiConfiguration)
1816-
const listApiConfig = await this.configManager.listConfig()
1817-
1818-
await Promise.all([
1819-
this.updateGlobalState("listApiConfigMeta", listApiConfig),
1820-
this.updateApiConfiguration(message.apiConfiguration),
1821-
this.updateGlobalState("currentApiConfigName", message.text),
1822-
])
1823-
1824-
await this.postStateToWebview()
1825-
} catch (error) {
1826-
this.outputChannel.appendLine(
1827-
`Error create new api configuration: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`,
1828-
)
1829-
vscode.window.showErrorMessage(t("common:errors.create_api_config"))
1830-
}
1825+
await this.upsertApiConfiguration(message.text, message.apiConfiguration)
18311826
}
18321827
break
18331828
case "renameApiConfiguration":
@@ -2250,9 +2245,10 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
22502245
// OpenRouter
22512246

22522247
async handleOpenRouterCallback(code: string) {
2248+
let { apiConfiguration, currentApiConfigName } = await this.getState()
2249+
22532250
let apiKey: string
22542251
try {
2255-
const { apiConfiguration } = await this.getState()
22562252
const baseUrl = apiConfiguration.openRouterBaseUrl || "https://openrouter.ai/api/v1"
22572253
// Extract the base domain for the auth endpoint
22582254
const baseUrlDomain = baseUrl.match(/^(https?:\/\/[^\/]+)/)?.[1] || "https://openrouter.ai"
@@ -2269,17 +2265,15 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
22692265
throw error
22702266
}
22712267

2272-
const openrouter: ApiProvider = "openrouter"
2273-
await this.contextProxy.setValues({
2274-
apiProvider: openrouter,
2268+
const newConfiguration: ApiConfiguration = {
2269+
...apiConfiguration,
2270+
apiProvider: "openrouter",
22752271
openRouterApiKey: apiKey,
2276-
})
2277-
2278-
await this.postStateToWebview()
2279-
if (this.getCurrentCline()) {
2280-
this.getCurrentCline()!.api = buildApiHandler({ apiProvider: openrouter, openRouterApiKey: apiKey })
2272+
openRouterModelId: apiConfiguration?.openRouterModelId || openRouterDefaultModelId,
2273+
openRouterModelInfo: apiConfiguration?.openRouterModelInfo || openRouterDefaultModelInfo,
22812274
}
2282-
// await this.postMessageToWebview({ type: "action", action: "settingsButtonClicked" }) // bad ux if user is on welcome
2275+
2276+
await this.upsertApiConfiguration(currentApiConfigName, newConfiguration)
22832277
}
22842278

22852279
// Glama
@@ -2300,41 +2294,55 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
23002294
throw error
23012295
}
23022296

2303-
const glama: ApiProvider = "glama"
2304-
await this.contextProxy.setValues({
2305-
apiProvider: glama,
2297+
const { apiConfiguration, currentApiConfigName } = await this.getState()
2298+
2299+
const newConfiguration: ApiConfiguration = {
2300+
...apiConfiguration,
2301+
apiProvider: "glama",
23062302
glamaApiKey: apiKey,
2307-
})
2308-
await this.postStateToWebview()
2309-
if (this.getCurrentCline()) {
2310-
this.getCurrentCline()!.api = buildApiHandler({
2311-
apiProvider: glama,
2312-
glamaApiKey: apiKey,
2313-
})
2303+
glamaModelId: apiConfiguration?.glamaModelId || glamaDefaultModelId,
2304+
glamaModelInfo: apiConfiguration?.glamaModelInfo || glamaDefaultModelInfo,
23142305
}
2315-
// await this.postMessageToWebview({ type: "action", action: "settingsButtonClicked" }) // bad ux if user is on welcome
2306+
2307+
await this.upsertApiConfiguration(currentApiConfigName, newConfiguration)
23162308
}
23172309

23182310
// Requesty
23192311

23202312
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-
})
2313+
let { apiConfiguration, currentApiConfigName } = await this.getState()
2314+
2315+
const newConfiguration: ApiConfiguration = {
2316+
...apiConfiguration,
2317+
apiProvider: "requesty",
2318+
requestyApiKey: code,
2319+
requestyModelId: apiConfiguration?.requestyModelId || requestyDefaultModelId,
2320+
requestyModelInfo: apiConfiguration?.requestyModelInfo || requestyDefaultModelInfo,
23332321
}
23342322

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
2323+
await this.upsertApiConfiguration(currentApiConfigName, newConfiguration)
2324+
}
2325+
2326+
// Save configuration
2327+
2328+
async upsertApiConfiguration(configName: string, apiConfiguration: ApiConfiguration) {
2329+
try {
2330+
await this.configManager.saveConfig(configName, apiConfiguration)
2331+
const listApiConfig = await this.configManager.listConfig()
2332+
2333+
await Promise.all([
2334+
this.updateGlobalState("listApiConfigMeta", listApiConfig),
2335+
this.updateApiConfiguration(apiConfiguration),
2336+
this.updateGlobalState("currentApiConfigName", configName),
2337+
])
2338+
2339+
await this.postStateToWebview()
2340+
} catch (error) {
2341+
this.outputChannel.appendLine(
2342+
`Error create new api configuration: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`,
2343+
)
2344+
vscode.window.showErrorMessage(t("common:errors.create_api_config"))
2345+
}
23382346
}
23392347

23402348
// Task history

0 commit comments

Comments
 (0)