Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
560 changes: 338 additions & 222 deletions apps/frontend/src/main/__tests__/ipc-handlers.test.ts

Large diffs are not rendered by default.

479 changes: 479 additions & 0 deletions apps/frontend/src/main/__tests__/utils.test.ts

Large diffs are not rendered by default.

469 changes: 239 additions & 230 deletions apps/frontend/src/main/ipc-handlers/agent-events-handlers.ts

Large diffs are not rendered by default.

148 changes: 54 additions & 94 deletions apps/frontend/src/main/ipc-handlers/ideation-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* - file-utils.ts: File system operations
*/

import { ipcMain } from 'electron';
import type { BrowserWindow } from 'electron';
import { IPC_CHANNELS } from '../../shared/constants';
import type { AgentManager } from '../agent';
import type { IdeationGenerationStatus, IdeationSession, Idea } from '../../shared/types';
import { ipcMain } from "electron";
import type { BrowserWindow } from "electron";
import { IPC_CHANNELS } from "../../shared/constants";
import type { AgentManager } from "../agent";
import type { IdeationGenerationStatus, IdeationSession, Idea } from "../../shared/types";
import {
getIdeationSession,
updateIdeaStatus,
Expand All @@ -28,8 +28,9 @@ import {
startIdeationGeneration,
refreshIdeationSession,
stopIdeationGeneration,
convertIdeaToTask
} from './ideation';
convertIdeaToTask,
} from "./ideation";
import { safeSendToRenderer } from "./utils";

/**
* Register all ideation-related IPC handlers
Expand All @@ -39,135 +40,94 @@ export function registerIdeationHandlers(
getMainWindow: () => BrowserWindow | null
): () => void {
// Session management
ipcMain.handle(
IPC_CHANNELS.IDEATION_GET,
getIdeationSession
);
ipcMain.handle(IPC_CHANNELS.IDEATION_GET, getIdeationSession);

// Idea operations
ipcMain.handle(
IPC_CHANNELS.IDEATION_UPDATE_IDEA,
updateIdeaStatus
);
ipcMain.handle(IPC_CHANNELS.IDEATION_UPDATE_IDEA, updateIdeaStatus);

ipcMain.handle(
IPC_CHANNELS.IDEATION_DISMISS,
dismissIdea
);
ipcMain.handle(IPC_CHANNELS.IDEATION_DISMISS, dismissIdea);

ipcMain.handle(
IPC_CHANNELS.IDEATION_DISMISS_ALL,
dismissAllIdeas
);
ipcMain.handle(IPC_CHANNELS.IDEATION_DISMISS_ALL, dismissAllIdeas);

ipcMain.handle(
IPC_CHANNELS.IDEATION_ARCHIVE,
archiveIdea
);
ipcMain.handle(IPC_CHANNELS.IDEATION_ARCHIVE, archiveIdea);

ipcMain.handle(
IPC_CHANNELS.IDEATION_DELETE,
deleteIdea
);
ipcMain.handle(IPC_CHANNELS.IDEATION_DELETE, deleteIdea);

ipcMain.handle(
IPC_CHANNELS.IDEATION_DELETE_MULTIPLE,
deleteMultipleIdeas
);
ipcMain.handle(IPC_CHANNELS.IDEATION_DELETE_MULTIPLE, deleteMultipleIdeas);

// Generation operations
ipcMain.on(
IPC_CHANNELS.IDEATION_GENERATE,
(event, projectId, config) =>
startIdeationGeneration(event, projectId, config, agentManager, getMainWindow())
ipcMain.on(IPC_CHANNELS.IDEATION_GENERATE, (event, projectId, config) =>
startIdeationGeneration(event, projectId, config, agentManager, getMainWindow())
);

ipcMain.on(
IPC_CHANNELS.IDEATION_REFRESH,
(event, projectId, config) =>
refreshIdeationSession(event, projectId, config, agentManager, getMainWindow())
ipcMain.on(IPC_CHANNELS.IDEATION_REFRESH, (event, projectId, config) =>
refreshIdeationSession(event, projectId, config, agentManager, getMainWindow())
);

ipcMain.handle(
IPC_CHANNELS.IDEATION_STOP,
(event, projectId) =>
stopIdeationGeneration(event, projectId, agentManager, getMainWindow())
ipcMain.handle(IPC_CHANNELS.IDEATION_STOP, (event, projectId) =>
stopIdeationGeneration(event, projectId, agentManager, getMainWindow())
);

// Task conversion
ipcMain.handle(
IPC_CHANNELS.IDEATION_CONVERT_TO_TASK,
convertIdeaToTask
);
ipcMain.handle(IPC_CHANNELS.IDEATION_CONVERT_TO_TASK, convertIdeaToTask);

// ============================================
// Ideation Agent Events → Renderer
// ============================================

const handleIdeationProgress = (projectId: string, status: IdeationGenerationStatus): void => {
const mainWindow = getMainWindow();
if (mainWindow) {
mainWindow.webContents.send(IPC_CHANNELS.IDEATION_PROGRESS, projectId, status);
}
safeSendToRenderer(getMainWindow, IPC_CHANNELS.IDEATION_PROGRESS, projectId, status);
};

const handleIdeationLog = (projectId: string, log: string): void => {
const mainWindow = getMainWindow();
if (mainWindow) {
mainWindow.webContents.send(IPC_CHANNELS.IDEATION_LOG, projectId, log);
}
safeSendToRenderer(getMainWindow, IPC_CHANNELS.IDEATION_LOG, projectId, log);
};

const handleIdeationTypeComplete = (projectId: string, ideationType: string, ideas: Idea[]): void => {
const mainWindow = getMainWindow();
if (mainWindow) {
mainWindow.webContents.send(IPC_CHANNELS.IDEATION_TYPE_COMPLETE, projectId, ideationType, ideas);
}
const handleIdeationTypeComplete = (
projectId: string,
ideationType: string,
ideas: Idea[]
): void => {
safeSendToRenderer(
getMainWindow,
IPC_CHANNELS.IDEATION_TYPE_COMPLETE,
projectId,
ideationType,
ideas
);
};

const handleIdeationTypeFailed = (projectId: string, ideationType: string): void => {
const mainWindow = getMainWindow();
if (mainWindow) {
mainWindow.webContents.send(IPC_CHANNELS.IDEATION_TYPE_FAILED, projectId, ideationType);
}
safeSendToRenderer(getMainWindow, IPC_CHANNELS.IDEATION_TYPE_FAILED, projectId, ideationType);
};

const handleIdeationComplete = (projectId: string, session: IdeationSession): void => {
const mainWindow = getMainWindow();
if (mainWindow) {
mainWindow.webContents.send(IPC_CHANNELS.IDEATION_COMPLETE, projectId, session);
}
safeSendToRenderer(getMainWindow, IPC_CHANNELS.IDEATION_COMPLETE, projectId, session);
};

const handleIdeationError = (projectId: string, error: string): void => {
const mainWindow = getMainWindow();
if (mainWindow) {
mainWindow.webContents.send(IPC_CHANNELS.IDEATION_ERROR, projectId, error);
}
safeSendToRenderer(getMainWindow, IPC_CHANNELS.IDEATION_ERROR, projectId, error);
};

const handleIdeationStopped = (projectId: string): void => {
const mainWindow = getMainWindow();
if (mainWindow) {
mainWindow.webContents.send(IPC_CHANNELS.IDEATION_STOPPED, projectId);
}
safeSendToRenderer(getMainWindow, IPC_CHANNELS.IDEATION_STOPPED, projectId);
};

agentManager.on('ideation-progress', handleIdeationProgress);
agentManager.on('ideation-log', handleIdeationLog);
agentManager.on('ideation-type-complete', handleIdeationTypeComplete);
agentManager.on('ideation-type-failed', handleIdeationTypeFailed);
agentManager.on('ideation-complete', handleIdeationComplete);
agentManager.on('ideation-error', handleIdeationError);
agentManager.on('ideation-stopped', handleIdeationStopped);
agentManager.on("ideation-progress", handleIdeationProgress);
agentManager.on("ideation-log", handleIdeationLog);
agentManager.on("ideation-type-complete", handleIdeationTypeComplete);
agentManager.on("ideation-type-failed", handleIdeationTypeFailed);
agentManager.on("ideation-complete", handleIdeationComplete);
agentManager.on("ideation-error", handleIdeationError);
agentManager.on("ideation-stopped", handleIdeationStopped);

return (): void => {
agentManager.off('ideation-progress', handleIdeationProgress);
agentManager.off('ideation-log', handleIdeationLog);
agentManager.off('ideation-type-complete', handleIdeationTypeComplete);
agentManager.off('ideation-type-failed', handleIdeationTypeFailed);
agentManager.off('ideation-complete', handleIdeationComplete);
agentManager.off('ideation-error', handleIdeationError);
agentManager.off('ideation-stopped', handleIdeationStopped);
agentManager.off("ideation-progress", handleIdeationProgress);
agentManager.off("ideation-log", handleIdeationLog);
agentManager.off("ideation-type-complete", handleIdeationTypeComplete);
agentManager.off("ideation-type-failed", handleIdeationTypeFailed);
agentManager.off("ideation-complete", handleIdeationComplete);
agentManager.off("ideation-error", handleIdeationError);
agentManager.off("ideation-stopped", handleIdeationStopped);
};
}
Loading
Loading