Skip to content

Commit 324179a

Browse files
authored
feat(api): implement auto model selection and update provider integration (#660)
1 parent bcd2571 commit 324179a

File tree

11 files changed

+95
-88
lines changed

11 files changed

+95
-88
lines changed

src/api/providers/fetchers/modelCache.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { ZgsmAuthConfig } from "../../../core/costrict/auth"
2828
import { IZgsmModelResponseData } from "@roo-code/types"
2929
import { getHuggingFaceModels } from "./huggingface"
3030
import { ClineProvider } from "../../../core/webview/ClineProvider"
31-
import { getRooModels } from "./roo"
31+
// import { getRooModels } from "./roo"
3232
import { getChutesModels } from "./chutes"
3333

3434
const memoryCache = new NodeCache({ stdTTL: 5 * 60, checkperiod: 5 * 60 })
@@ -128,9 +128,10 @@ export const getModels = async (options: GetModelsOptions): Promise<ModelRecord>
128128
break
129129
case "roo": {
130130
// Roo Code Cloud provider requires baseUrl and optional apiKey
131-
const rooBaseUrl =
132-
options.baseUrl ?? process.env.ROO_CODE_PROVIDER_URL ?? "https://api.roocode.com/proxy"
133-
models = await getRooModels(rooBaseUrl, options.apiKey)
131+
// const rooBaseUrl =
132+
// options.baseUrl ?? process.env.ROO_CODE_PROVIDER_URL ?? "https://api.roocode.com/proxy"
133+
// models = await getRooModels(rooBaseUrl, options.apiKey)
134+
models = {}
134135
break
135136
}
136137
case "chutes":

src/api/providers/zgsm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,10 @@ export class ZgsmAiHandler extends BaseProvider implements SingleCompletionHandl
440440
// Yield selected LLM info if available (for Auto model mode)
441441
if (isAuto) {
442442
yield {
443-
type: "text",
444-
text: `["${selectedLLM}" ${selectReason ? `, "(${selectReason})"` : ""}]`,
445-
isAuto,
443+
type: "automodel",
444+
text: selectReason ? ` (${selectReason})` : "",
446445
originModelId: this.options.zgsmModelId,
446+
selectedLLM,
447447
}
448448
}
449449

src/api/transform/stream.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type ApiStream = AsyncGenerator<ApiStreamChunk>
22

33
export type ApiStreamChunk =
44
| ApiStreamTextChunk
5+
| ApiStreamAutoModelChunk
56
| ApiStreamUsageChunk
67
| ApiStreamReasoningChunk
78
| ApiStreamGroundingChunk
@@ -17,8 +18,14 @@ export interface ApiStreamError {
1718
export interface ApiStreamTextChunk {
1819
type: "text"
1920
text: string
21+
}
22+
23+
export interface ApiStreamAutoModelChunk {
24+
type: "automodel"
25+
text: string
2026
isAuto?: boolean
2127
originModelId?: string
28+
selectedLLM?: string
2229
}
2330

2431
export interface ApiStreamReasoningChunk {

src/core/task/Task.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,30 +2190,29 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
21902190
presentAssistantMessage(this)
21912191
break
21922192
}
2193-
case "text": {
2193+
case "automodel": {
21942194
// Check if it is Selected LLM information (only in Auto model mode).
21952195
if (
2196-
chunk.isAuto &&
2196+
this.apiConfiguration.apiProvider === "zgsm" &&
21972197
lastApiReqIndex >= 0 &&
2198-
this.clineMessages[lastApiReqIndex] &&
2199-
this.apiConfiguration.apiProvider === "zgsm"
2198+
this.clineMessages[lastApiReqIndex]
22002199
) {
22012200
// Extract Selected LLM and Reason information and update the api_req_started message.
22022201
const existingData = JSON.parse(this.clineMessages[lastApiReqIndex].text || "{}")
2203-
const [selectedLLM, selectReason] = JSON.parse(chunk.text)
2204-
22052202
this.clineMessages[lastApiReqIndex].text = JSON.stringify({
22062203
...existingData,
2207-
selectedLLM,
2208-
selectReason,
2209-
isAuto: chunk.isAuto,
2204+
selectedLLM: chunk.selectedLLM,
2205+
selectReason: chunk.text,
2206+
isAuto: true,
22102207
originModelId: chunk.originModelId,
22112208
} satisfies ClineApiReqInfo)
22122209
// Save the selection information but do not add it to the assistant message to avoid it being processed by the parser.
2213-
console.log(`[Backend Model Route Detail] ${selectedLLM}${selectReason}`)
2210+
console.log(`[Backend Model Route Detail] ${chunk.selectedLLM}${chunk.text}`)
22142211
break
22152212
}
2216-
2213+
break
2214+
}
2215+
case "text": {
22172216
assistantMessage += chunk.text
22182217

22192218
if (this.assistantMessageParser) {

src/core/webview/webviewMessageHandler.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,38 +1067,38 @@ export const webviewMessageHandler = async (
10671067
}
10681068
break
10691069
}
1070-
case "requestRooModels": {
1071-
// Specific handler for Roo models only - flushes cache to ensure fresh auth token is used
1072-
try {
1073-
// Flush cache first to ensure fresh models with current auth state
1074-
await flushModels("roo")
1075-
1076-
const rooModels = await getModels({
1077-
provider: "roo",
1078-
baseUrl: process.env.ROO_CODE_PROVIDER_URL ?? "https://api.roocode.com/proxy",
1079-
apiKey: CloudService.hasInstance()
1080-
? CloudService.instance.authService?.getSessionToken()
1081-
: undefined,
1082-
})
1083-
1084-
// Always send a response, even if no models are returned
1085-
provider.postMessageToWebview({
1086-
type: "singleRouterModelFetchResponse",
1087-
success: true,
1088-
values: { provider: "roo", models: rooModels },
1089-
})
1090-
} catch (error) {
1091-
// Send error response
1092-
const errorMessage = error instanceof Error ? error.message : String(error)
1093-
provider.postMessageToWebview({
1094-
type: "singleRouterModelFetchResponse",
1095-
success: false,
1096-
error: errorMessage,
1097-
values: { provider: "roo" },
1098-
})
1099-
}
1100-
break
1101-
}
1070+
// case "requestRooModels": {
1071+
// // Specific handler for Roo models only - flushes cache to ensure fresh auth token is used
1072+
// try {
1073+
// // Flush cache first to ensure fresh models with current auth state
1074+
// await flushModels("roo")
1075+
1076+
// const rooModels = await getModels({
1077+
// provider: "roo",
1078+
// baseUrl: process.env.ROO_CODE_PROVIDER_URL ?? "https://api.roocode.com/proxy",
1079+
// apiKey: CloudService.hasInstance()
1080+
// ? CloudService.instance.authService?.getSessionToken()
1081+
// : undefined,
1082+
// })
1083+
1084+
// // Always send a response, even if no models are returned
1085+
// provider.postMessageToWebview({
1086+
// type: "singleRouterModelFetchResponse",
1087+
// success: true,
1088+
// values: { provider: "roo", models: rooModels },
1089+
// })
1090+
// } catch (error) {
1091+
// // Send error response
1092+
// const errorMessage = error instanceof Error ? error.message : String(error)
1093+
// provider.postMessageToWebview({
1094+
// type: "singleRouterModelFetchResponse",
1095+
// success: false,
1096+
// error: errorMessage,
1097+
// values: { provider: "roo" },
1098+
// })
1099+
// }
1100+
// break
1101+
// }
11021102
case "requestOpenAiModels":
11031103
if (message?.values?.baseUrl && message?.values?.apiKey) {
11041104
const openAiModels = await getOpenAiModels(

src/integrations/terminal/TerminalRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class TerminalRegistry {
6262
terminal.busy = true // Mark terminal as busy when shell execution starts
6363
} else {
6464
console.error(
65-
"[onDidStartTerminalShellExecution] Shell execution started, but not from a Roo-registered terminal:",
65+
"[onDidStartTerminalShellExecution] Shell execution started, but not from a CoStrict-registered terminal:",
6666
e,
6767
)
6868
}

src/utils/autoImportSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { t } from "../i18n"
99
import { importSettingsFromPath, ImportOptions } from "../core/config/importExport"
1010

1111
/**
12-
* Automatically imports RooCode settings from a specified path if it exists.
12+
* Automatically imports CoStrict settings from a specified path if it exists.
1313
* This function is called during extension activation to allow users to pre-configure
1414
* their settings by placing a settings file at a predefined location.
1515
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export const About = ({ telemetrySetting, setTelemetrySetting, className, ...pro
6363
components={{
6464
zgsmGithubLink: <VSCodeLink href="https://github.com/zgsm-ai/costrict" />,
6565
githubLink: <VSCodeLink href="https://github.com/zgsm-ai/costrict" />,
66-
redditLink: <VSCodeLink href="https://reddit.com/r/RooCode" />,
67-
discordLink: <VSCodeLink href="https://discord.gg/roocode" />,
66+
// redditLink: <VSCodeLink href="https://reddit.com/r/RooCode" />,
67+
// discordLink: <VSCodeLink href="https://discord.gg/roocode" />,
6868
}}
6969
/>
7070
</div>

webview-ui/src/components/settings/providers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export { OpenAI } from "./OpenAI"
1818
export { OpenAICompatible } from "./OpenAICompatible"
1919
export { OpenRouter } from "./OpenRouter"
2020
export { QwenCode } from "./QwenCode"
21-
export { Roo } from "./Roo"
21+
// export { Roo } from "./Roo"
2222
export { Requesty } from "./Requesty"
2323
export { SambaNova } from "./SambaNova"
2424
export { Unbound } from "./Unbound"

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
327327
isCodebaseReady: true,
328328
})
329329
const [includeTaskHistoryInEnhance, setIncludeTaskHistoryInEnhance] = useState(true)
330-
const [prevCloudIsAuthenticated, setPrevCloudIsAuthenticated] = useState(false)
330+
// const [prevCloudIsAuthenticated, setPrevCloudIsAuthenticated] = useState(false)
331331
const [includeCurrentTime, setIncludeCurrentTime] = useState(true)
332332
const [includeCurrentCost, setIncludeCurrentCost] = useState(true)
333333
const [notices, setNotices] = useState<
@@ -513,15 +513,15 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
513513
}, [])
514514

515515
// Watch for authentication state changes and refresh Roo models
516-
useEffect(() => {
517-
const currentAuth = state.cloudIsAuthenticated ?? false
518-
const currentProvider = state.apiConfiguration?.apiProvider
519-
if (!prevCloudIsAuthenticated && currentAuth && currentProvider === "roo") {
520-
// User just authenticated and Roo is the active provider - refresh Roo models
521-
vscode.postMessage({ type: "requestRooModels" })
522-
}
523-
setPrevCloudIsAuthenticated(currentAuth)
524-
}, [state.cloudIsAuthenticated, prevCloudIsAuthenticated, state.apiConfiguration?.apiProvider])
516+
// useEffect(() => {
517+
// const currentAuth = state.cloudIsAuthenticated ?? false
518+
// const currentProvider = state.apiConfiguration?.apiProvider
519+
// if (!prevCloudIsAuthenticated && currentAuth && currentProvider === "roo") {
520+
// // User just authenticated and Roo is the active provider - refresh Roo models
521+
// vscode.postMessage({ type: "requestRooModels" })
522+
// }
523+
// setPrevCloudIsAuthenticated(currentAuth)
524+
// }, [state.cloudIsAuthenticated, prevCloudIsAuthenticated, state.apiConfiguration?.apiProvider])
525525

526526
const contextValue: ExtensionStateContextType = {
527527
...state,
@@ -541,7 +541,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
541541
writeDelayMs: state.writeDelayMs,
542542
screenshotQuality: state.screenshotQuality,
543543
routerModels: extensionRouterModels,
544-
cloudIsAuthenticated: state.cloudIsAuthenticated ?? false,
544+
// cloudIsAuthenticated: state.cloudIsAuthenticated ?? false,
545545
// cloudOrganizations: state.cloudOrganizations ?? [],
546546
organizationSettingsVersion: state.organizationSettingsVersion ?? -1,
547547
marketplaceItems,

0 commit comments

Comments
 (0)