Load (canned) proposal from IPC

This commit is contained in:
Will Chen
2025-04-18 11:11:58 -07:00
parent 7aec3ef455
commit 4e0f93d21c
8 changed files with 191 additions and 45 deletions

View File

@@ -0,0 +1,47 @@
import { ipcMain, type IpcMainInvokeEvent } from "electron";
import type { Proposal } from "@/lib/schemas";
// Placeholder Proposal data
const placeholderProposal: Proposal = {
title: "Review: Example Refactoring (from IPC)",
securityRisks: [
{
type: "warning",
title: "Potential XSS Vulnerability",
description: "User input is directly rendered without sanitization.",
},
{
type: "danger",
title: "Hardcoded API Key",
description: "API key found in plain text in configuration file.",
},
],
filesChanged: [
{
name: "ChatInput.tsx",
path: "src/components/chat/ChatInput.tsx",
summary: "Added review actions and details section.",
},
{
name: "api.ts",
path: "src/lib/api.ts",
summary: "Refactored API call structure.",
},
],
};
const getProposalHandler = async (
_event: IpcMainInvokeEvent,
{ chatId }: { chatId: number }
): Promise<Proposal> => {
console.log(`IPC: get-proposal called for chatId: ${chatId}`);
// Simulate async operation
await new Promise((resolve) => setTimeout(resolve, 500)); // 500ms delay
return placeholderProposal;
};
// Function to register proposal-related handlers
export function registerProposalHandlers() {
ipcMain.handle("get-proposal", getProposalHandler);
console.log("Registered proposal IPC handlers");
}

View File

@@ -17,6 +17,7 @@ import type {
NodeSystemInfo,
Version,
} from "./ipc_types";
import type { Proposal } from "@/lib/schemas";
import { showError } from "@/lib/toast";
export interface ChatStreamCallbacks {
@@ -614,6 +615,18 @@ export class IpcClient {
}
}
// Get proposal details
public async getProposal(chatId: number): Promise<Proposal> {
try {
const data = await this.ipcRenderer.invoke("get-proposal", { chatId });
// Assuming the main process returns data matching the Proposal interface
return data as Proposal;
} catch (error) {
showError(error);
throw error;
}
}
// Example methods for listening to events (if needed)
// public on(channel: string, func: (...args: any[]) => void): void {
}

View File

@@ -6,6 +6,7 @@ import { registerShellHandlers } from "./handlers/shell_handler";
import { registerDependencyHandlers } from "./handlers/dependency_handlers";
import { registerGithubHandlers } from "./handlers/github_handlers";
import { registerNodeHandlers } from "./handlers/node_handlers";
import { registerProposalHandlers } from "./handlers/proposal_handlers";
export function registerIpcHandlers() {
// Register all IPC handlers by category
@@ -17,4 +18,5 @@ export function registerIpcHandlers() {
registerDependencyHandlers();
registerGithubHandlers();
registerNodeHandlers();
registerProposalHandlers();
}