11import { Anthropic } from "@anthropic-ai/sdk"
22import cloneDeep from "clone-deep"
3- import { DiffStrategy , getDiffStrategy , UnifiedDiffStrategy } from "./diff/DiffStrategy"
4- import { validateToolUse , isToolAllowedForMode , ToolName } from "./mode-validator"
3+ import crypto from "crypto"
54import delay from "delay"
65import fs from "fs/promises"
76import os from "os"
87import pWaitFor from "p-wait-for"
98import * as path from "path"
109import { serializeError } from "serialize-error"
1110import * as vscode from "vscode"
12- import { ApiHandler , SingleCompletionHandler , buildApiHandler } from "../api"
11+ import { ApiHandler , buildApiHandler } from "../api"
1312import { ApiStream } from "../api/transform/stream"
13+ import { detectCodeOmission } from "../integrations/editor/detect-omission"
1414import { DiffViewProvider } from "../integrations/editor/DiffViewProvider"
1515import { findToolName , formatContentBlockToMarkdown } from "../integrations/misc/export-markdown"
1616import {
17- extractTextFromFile ,
1817 addLineNumbers ,
19- stripLineNumbers ,
2018 everyLineHasLineNumbers ,
19+ extractTextFromFile ,
20+ stripLineNumbers ,
2121 truncateOutput ,
2222} from "../integrations/misc/extract-text"
2323import { TerminalManager } from "../integrations/terminal/TerminalManager"
24+ import { BrowserSession } from "../services/browser/BrowserSession"
2425import { UrlContentFetcher } from "../services/browser/UrlContentFetcher"
2526import { listFiles } from "../services/glob/list-files"
27+ import { McpHub } from "../services/mcp/McpHub"
2628import { regexSearchFiles } from "../services/ripgrep"
2729import { parseSourceCodeForDefinitionsTopLevel } from "../services/tree-sitter"
2830import { ApiConfiguration } from "../shared/api"
2931import { findLastIndex } from "../shared/array"
3032import { combineApiRequests } from "../shared/combineApiRequests"
3133import { combineCommandSequences } from "../shared/combineCommandSequences"
34+ import { EXPERIMENT_IDS , experiments as Experiments } from "../shared/experiments"
3235import {
3336 BrowserAction ,
3437 BrowserActionResult ,
@@ -44,24 +47,20 @@ import {
4447} from "../shared/ExtensionMessage"
4548import { getApiMetrics } from "../shared/getApiMetrics"
4649import { HistoryItem } from "../shared/HistoryItem"
50+ import { defaultModeSlug , getModeBySlug } from "../shared/modes"
4751import { ClineAskResponse } from "../shared/WebviewMessage"
4852import { calculateApiCost } from "../utils/cost"
4953import { fileExistsAtPath } from "../utils/fs"
5054import { arePathsEqual , getReadablePath } from "../utils/path"
51- import { parseMentions } from "./mentions"
5255import { AssistantMessageContent , parseAssistantMessage , ToolParamName , ToolUseName } from "./assistant-message"
56+ import { DiffStrategy , getDiffStrategy } from "./diff/DiffStrategy"
57+ import { insertGroups } from "./diff/insert-groups"
58+ import { parseMentions } from "./mentions"
59+ import { isToolAllowedForMode , ToolName , validateToolUse } from "./mode-validator"
5360import { formatResponse } from "./prompts/responses"
5461import { SYSTEM_PROMPT } from "./prompts/system"
55- import { modes , defaultModeSlug , getModeBySlug } from "../shared/modes"
5662import { truncateHalfConversation } from "./sliding-window"
5763import { ClineProvider , GlobalFileNames } from "./webview/ClineProvider"
58- import { detectCodeOmission } from "../integrations/editor/detect-omission"
59- import { BrowserSession } from "../services/browser/BrowserSession"
60- import { OpenRouterHandler } from "../api/providers/openrouter"
61- import { McpHub } from "../services/mcp/McpHub"
62- import crypto from "crypto"
63- import { insertGroups } from "./diff/insert-groups"
64- import { EXPERIMENT_IDS , experiments as Experiments } from "../shared/experiments"
6564
6665const cwd =
6766 vscode . workspace . workspaceFolders ?. map ( ( folder ) => folder . uri . fsPath ) . at ( 0 ) ?? path . join ( os . homedir ( ) , "Desktop" ) // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution
@@ -125,6 +124,7 @@ export class Cline {
125124 }
126125
127126 this . taskId = crypto . randomUUID ( )
127+ // Update the API handler when configuration changes
128128 this . api = buildApiHandler ( apiConfiguration )
129129 this . terminalManager = new TerminalManager ( )
130130 this . urlContentFetcher = new UrlContentFetcher ( provider . context )
@@ -135,6 +135,19 @@ export class Cline {
135135 this . providerRef = new WeakRef ( provider )
136136 this . diffViewProvider = new DiffViewProvider ( cwd )
137137
138+ // Add listener for configuration changes
139+ provider . context . subscriptions . push (
140+ vscode . workspace . onDidChangeConfiguration ( async ( e ) => {
141+ if ( e . affectsConfiguration ( "roo-cline" ) ) {
142+ // Rebuild API handler with new configuration
143+ const newConfig = await provider . getState ( )
144+ if ( newConfig ?. apiConfiguration ) {
145+ this . api = buildApiHandler ( newConfig . apiConfiguration )
146+ }
147+ }
148+ } ) ,
149+ )
150+
138151 if ( historyItem ) {
139152 this . taskId = historyItem . id
140153 }
0 commit comments