Compare commits

...

3 Commits

Author SHA1 Message Date
celestial-vault eff328d20f update proto type names 2025-07-21 17:57:06 -07:00
celestial-vault d4eefdd0e7 rework proto type 2025-07-21 16:42:54 -07:00
celestial-vault 793e54191d migrate showSaveDialog hostBridge 2025-07-21 16:05:03 -07:00
3 changed files with 58 additions and 15 deletions
+20 -1
View File
@@ -12,6 +12,7 @@ service WindowService {
rpc showTextDocument(ShowTextDocumentRequest) returns (TextEditorInfo);
rpc showOpenDialogue(ShowOpenDialogueRequest) returns (SelectedResources);
rpc showMessage(ShowMessageRequest) returns (SelectedResponse);
rpc showSaveDialog(ShowSaveDialogRequest) returns (ShowSaveDialogResponse);
}
message ShowTextDocumentRequest {
@@ -70,4 +71,22 @@ message ShowMessageRequestOptions {
message SelectedResponse {
optional string selected_option = 1;
}
}
message ShowSaveDialogRequest {
cline.Metadata metadata = 1;
optional ShowSaveDialogOptions options = 2;
}
message ShowSaveDialogOptions {
optional string default_path = 1;
map<string, FileExtensionList> filters = 2;
}
message FileExtensionList {
repeated string extensions = 1;
}
message ShowSaveDialogResponse {
optional string selected_path = 1;
}
@@ -0,0 +1,25 @@
import { window, Uri, SaveDialogOptions } from "vscode"
import { ShowSaveDialogRequest, ShowSaveDialogResponse } from "@/shared/proto/index.host"
export async function showSaveDialog(request: ShowSaveDialogRequest): Promise<ShowSaveDialogResponse> {
const { options } = request
const vscodeOptions: SaveDialogOptions = {}
if (options?.defaultPath) {
vscodeOptions.defaultUri = Uri.file(options.defaultPath)
}
if (options?.filters && Object.keys(options.filters).length > 0) {
vscodeOptions.filters = {}
Object.entries(options.filters).forEach(([name, extensionList]) => {
vscodeOptions.filters![name] = extensionList.extensions
})
}
const selectedUri = await window.showSaveDialog(vscodeOptions)
return ShowSaveDialogResponse.create({
selectedPath: selectedUri?.fsPath,
})
}
+13 -14
View File
@@ -1,9 +1,8 @@
import { Anthropic } from "@anthropic-ai/sdk"
import os from "os"
import * as path from "path"
import * as vscode from "vscode"
import { HostProvider } from "@/hosts/host-provider"
import { ShowTextDocumentRequest, ShowTextDocumentOptions, ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
import { ShowMessageType } from "@/shared/proto/host/window"
import { writeFile } from "@utils/fs"
export async function downloadTask(dateTs: number, conversationHistory: Anthropic.MessageParam[]) {
@@ -32,23 +31,23 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi
.join("---\n\n")
// Prompt user for save location
const saveUri = await vscode.window.showSaveDialog({
filters: { Markdown: ["md"] },
defaultUri: vscode.Uri.file(path.join(os.homedir(), "Downloads", fileName)),
const saveResponse = await HostProvider.window.showSaveDialog({
options: {
filters: { Markdown: { extensions: ["md"] } },
defaultPath: path.join(os.homedir(), "Downloads", fileName),
},
})
if (saveUri) {
if (saveResponse.selectedPath) {
try {
// Write content to the selected location
await writeFile(saveUri.fsPath, markdownContent)
await HostProvider.window.showTextDocument(
ShowTextDocumentRequest.create({
path: saveUri.fsPath,
options: ShowTextDocumentOptions.create({ preview: true }),
}),
)
await writeFile(saveResponse.selectedPath, markdownContent)
await HostProvider.window.showTextDocument({
path: saveResponse.selectedPath,
options: { preview: true },
})
} catch (error) {
HostProvider.window.showMessage({
await HostProvider.window.showMessage({
type: ShowMessageType.ERROR,
message: `Failed to save markdown file: ${error instanceof Error ? error.message : String(error)}`,
})