From 3fbfc248647885a2f274dee935cfec6f91ecaa2d Mon Sep 17 00:00:00 2001 From: celestial-vault <58194240+celestial-vault@users.noreply.github.com> Date: Tue, 24 Jun 2025 16:07:19 -0700 Subject: [PATCH] fix link by calling grpc (#4422) --- proto/ui.proto | 3 +++ src/core/controller/ui/openUrl.ts | 20 ++++++++++++++++++++ webview-ui/src/components/chat/ChatRow.tsx | 16 +++++++--------- 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 src/core/controller/ui/openUrl.ts diff --git a/proto/ui.proto b/proto/ui.proto index 961e8477b0..48a7f47a5b 100644 --- a/proto/ui.proto +++ b/proto/ui.proto @@ -265,4 +265,7 @@ service UiService { // Returns the HTML for the webview index page. This is only used by external clients, not by the vscode webview. rpc getWebviewHtml(EmptyRequest) returns (String); + + // Opens a URL in the default browser + rpc openUrl(StringRequest) returns (Empty); } diff --git a/src/core/controller/ui/openUrl.ts b/src/core/controller/ui/openUrl.ts new file mode 100644 index 0000000000..c6d6ca1bbd --- /dev/null +++ b/src/core/controller/ui/openUrl.ts @@ -0,0 +1,20 @@ +import type { Controller } from "../index" +import type { StringRequest } from "../../../shared/proto/common" +import { Empty } from "../../../shared/proto/common" +import { openUrlInBrowser } from "../../../utils/github-url-utils" + +/** + * Opens a URL in the default browser + * @param controller The controller instance + * @param request The URL to open + * @returns Empty response + */ +export async function openUrl(controller: Controller, request: StringRequest): Promise { + try { + await openUrlInBrowser(request.value) + return Empty.create({}) + } catch (error) { + console.error(`Failed to open URL: ${error}`) + throw error + } +} diff --git a/webview-ui/src/components/chat/ChatRow.tsx b/webview-ui/src/components/chat/ChatRow.tsx index 65f62efac8..7bde444973 100644 --- a/webview-ui/src/components/chat/ChatRow.tsx +++ b/webview-ui/src/components/chat/ChatRow.tsx @@ -17,7 +17,7 @@ import McpResponseDisplay from "@/components/mcp/chat-display/McpResponseDisplay import McpResourceRow from "@/components/mcp/configuration/tabs/installed/server-row/McpResourceRow" import McpToolRow from "@/components/mcp/configuration/tabs/installed/server-row/McpToolRow" import { useExtensionState } from "@/context/ExtensionStateContext" -import { FileServiceClient, TaskServiceClient } from "@/services/grpc-client" +import { FileServiceClient, TaskServiceClient, UiServiceClient } from "@/services/grpc-client" import { findMatchingResourceOrTemplate, getMcpServerDisplayName } from "@/utils/mcp" import { vscode } from "@/utils/vscode" import { @@ -697,15 +697,13 @@ export const ChatRowContent = ({ msUserSelect: "none", }} onClick={() => { - // Attempt to open the URL in the default browser + // Open the URL in the default browser using gRPC if (tool.path) { - // Assuming 'openUrl' is a valid action the extension can handle. - // If not, this might need adjustment based on how other external link openings are handled. - vscode.postMessage({ - type: "action", // This should be a valid MessageType from WebviewMessage - action: "openUrl", // This should be a valid WebviewAction from WebviewMessage - url: tool.path, - } as any) // Using 'as any' for now if 'openUrl' isn't strictly typed yet + UiServiceClient.openUrl(StringRequest.create({ value: tool.path })) + + .catch((err) => { + console.error("Failed to open URL:", err) + }) } }}>