import { EmptyRequest, StringRequest } from "@shared/proto/cline/common" import open from "open" import { HostProvider } from "@/hosts/host-provider" /** * Writes text to the system clipboard * @param text The text to write to the clipboard * @returns Promise that resolves when the operation is complete * @throws Error if the operation fails */ export async function writeTextToClipboard(text: string): Promise { try { await HostProvider.env.clipboardWriteText(StringRequest.create({ value: text })) } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error) throw new Error(`Failed to write to clipboard: ${errorMessage}`) } } /** * Reads text from the system clipboard * @returns Promise that resolves to the clipboard text * @throws Error if the operation fails */ export async function readTextFromClipboard(): Promise { try { const response = await HostProvider.env.clipboardReadText(EmptyRequest.create({})) return response.value } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error) throw new Error(`Failed to read from clipboard: ${errorMessage}`) } } /** * Opens an external URL in the default browser * @param url The URL to open * @returns Promise that resolves when the operation is complete * @throws Error if the operation fails */ export async function openExternal(url: string): Promise { console.log("Opening browser:", url) await open(url) }