Skip to content

Commit 5c08276

Browse files
authored
toggleFavoriteModel protobus migration (RooCodeInc#3488)
1 parent 4a230ad commit 5c08276

File tree

8 files changed

+67
-28
lines changed

8 files changed

+67
-28
lines changed

.changeset/nice-pears-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
toggleFavoriteModel protobus migration

proto/state.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "common.proto";
66
service StateService {
77
rpc getLatestState(EmptyRequest) returns (State);
88
rpc subscribeToState(EmptyRequest) returns (stream State);
9+
rpc toggleFavoriteModel(StringRequest) returns (Empty);
910
}
1011

1112
message State {

src/core/controller/index.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -603,27 +603,6 @@ export class Controller {
603603
this.postMessageToWebview({ type: "relinquishControl" })
604604
break
605605
}
606-
case "toggleFavoriteModel": {
607-
if (message.modelId) {
608-
const { apiConfiguration } = await getAllExtensionState(this.context)
609-
const favoritedModelIds = apiConfiguration.favoritedModelIds || []
610-
611-
// Toggle favorite status
612-
const updatedFavorites = favoritedModelIds.includes(message.modelId)
613-
? favoritedModelIds.filter((id) => id !== message.modelId)
614-
: [...favoritedModelIds, message.modelId]
615-
616-
await updateGlobalState(this.context, "favoritedModelIds", updatedFavorites)
617-
618-
// Capture telemetry for model favorite toggle
619-
const isFavorited = !favoritedModelIds.includes(message.modelId)
620-
telemetryService.captureModelFavoritesUsage(message.modelId, isFavorited)
621-
622-
// Post state to webview without changing any other configuration
623-
await this.postStateToWebview()
624-
}
625-
break
626-
}
627606
case "grpc_request": {
628607
if (message.grpc_request) {
629608
await handleGrpcRequest(this, message.grpc_request)

src/core/controller/state/methods.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { registerMethod } from "./index"
66
import { getLatestState } from "./getLatestState"
77
import { subscribeToState } from "./subscribeToState"
8+
import { toggleFavoriteModel } from "./toggleFavoriteModel"
89

910
// Streaming methods for this service
1011
export const streamingMethods = ["subscribeToState"]
@@ -14,4 +15,5 @@ export function registerAllMethods(): void {
1415
// Register each method with the registry
1516
registerMethod("getLatestState", getLatestState)
1617
registerMethod("subscribeToState", subscribeToState, { isStreaming: true })
18+
registerMethod("toggleFavoriteModel", toggleFavoriteModel)
1719
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { telemetryService } from "@/services/posthog/telemetry/TelemetryService"
2+
import { Controller } from ".."
3+
import { Empty, StringRequest } from "../../../shared/proto/common"
4+
import { updateGlobalState } from "@/core/storage/state"
5+
6+
/**
7+
* Toggles a model's favorite status
8+
* @param controller The controller instance
9+
* @param request The request containing the model ID to toggle
10+
* @returns An empty response
11+
*/
12+
export async function toggleFavoriteModel(controller: Controller, request: StringRequest): Promise<Empty> {
13+
try {
14+
if (!request.value) {
15+
throw new Error("Model ID is required")
16+
}
17+
18+
const modelId = request.value
19+
const { apiConfiguration } = await controller.getStateToPostToWebview()
20+
21+
if (!apiConfiguration) {
22+
throw new Error("API configuration not found")
23+
}
24+
25+
const favoritedModelIds = apiConfiguration.favoritedModelIds || []
26+
27+
// Toggle favorite status
28+
const updatedFavorites = favoritedModelIds.includes(modelId)
29+
? favoritedModelIds.filter((id) => id !== modelId)
30+
: [...favoritedModelIds, modelId]
31+
32+
await updateGlobalState(controller.context, "favoritedModelIds", updatedFavorites)
33+
34+
// Capture telemetry for model favorite toggle
35+
const isFavorited = !favoritedModelIds.includes(modelId)
36+
telemetryService.captureModelFavoritesUsage(modelId, isFavorited)
37+
38+
// Post state to webview without changing any other configuration
39+
await controller.postStateToWebview()
40+
41+
return Empty.create()
42+
} catch (error) {
43+
console.error(`Failed to toggle favorite status for model ${request.value}:`, error)
44+
throw error
45+
}
46+
}

src/shared/WebviewMessage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export interface WebviewMessage {
5454
| "taskFeedback"
5555
| "scrollToSettings"
5656
| "searchFiles"
57-
| "toggleFavoriteModel"
5857
| "grpc_request"
5958
| "grpc_request_cancel"
6059
| "toggleClineRule"

src/shared/proto/state.ts

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useMount } from "react-use"
66
import styled from "styled-components"
77
import { openRouterDefaultModelId } from "@shared/api"
88
import { useExtensionState } from "@/context/ExtensionStateContext"
9-
import { ModelsServiceClient } from "@/services/grpc-client"
9+
import { ModelsServiceClient, StateServiceClient } from "@/services/grpc-client"
1010
import { vscode } from "@/utils/vscode"
1111
import { highlight } from "../history/HistoryView"
1212
import { ModelInfoView, normalizeApiConfiguration } from "./ApiOptions"
@@ -292,10 +292,9 @@ const OpenRouterModelPicker: React.FC<OpenRouterModelPickerProps> = ({ isPopup }
292292
isFavorite={isFavorite}
293293
onClick={(e) => {
294294
e.stopPropagation()
295-
vscode.postMessage({
296-
type: "toggleFavoriteModel",
297-
modelId: item.id,
298-
})
295+
StateServiceClient.toggleFavoriteModel({ value: item.id }).catch((error) =>
296+
console.error("Failed to toggle favorite model:", error),
297+
)
299298
}}
300299
/>
301300
</div>

0 commit comments

Comments
 (0)