Skip to content
Open
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
33 changes: 33 additions & 0 deletions app/src/electron/handlers/chatHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,37 @@ export function setupChatHandlers(chatService: ChatService) {
return { success: false, error: error instanceof Error ? error.message : String(error) };
}
});

// Get checklist for a message
ipcMain.handle(IPC_CHANNELS.GET_CHECKLIST, async (event, sessionId: string, messageId: string) => {
try {
const checklist = await chatService.getChecklist(sessionId, messageId);
return { success: true, data: checklist };
} catch (error) {
console.error('[IPC] Get checklist error:', error);
return { success: false, error: error instanceof Error ? error.message : String(error) };
}
});

// Save checklist for a message
ipcMain.handle(IPC_CHANNELS.SAVE_CHECKLIST, async (event, sessionId: string, messageId: string, tasks: any[]) => {
try {
const result = await chatService.saveChecklist(sessionId, messageId, tasks);
return { success: true, data: result };
} catch (error) {
console.error('[IPC] Save checklist error:', error);
return { success: false, error: error instanceof Error ? error.message : String(error) };
}
});

// Update checklist item
ipcMain.handle(IPC_CHANNELS.UPDATE_CHECKLIST_ITEM, async (event, sessionId: string, messageId: string, itemId: string, isCompleted: boolean) => {
try {
const result = await chatService.updateChecklistItem(sessionId, messageId, itemId, isCompleted);
return { success: true, data: result };
} catch (error) {
console.error('[IPC] Update checklist item error:', error);
return { success: false, error: error instanceof Error ? error.message : String(error) };
}
});
}
6 changes: 6 additions & 0 deletions app/src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const IPC_CHANNELS = {
GET_CHAT_HISTORY: 'get-chat-history',
CREATE_CHAT_SESSION: 'create-chat-session',
DELETE_CHAT_SESSION: 'delete-chat-session',
GET_CHECKLIST: 'get-checklist',
SAVE_CHECKLIST: 'save-checklist',
UPDATE_CHECKLIST_ITEM: 'update-checklist-item',

// Dock Controls
TOGGLE_DOCK: 'toggle-dock',
Expand Down Expand Up @@ -120,6 +123,9 @@ contextBridge.exposeInMainWorld('electron', {
getHistory: (sessionId: string) => ipcRenderer.invoke(IPC_CHANNELS.GET_CHAT_HISTORY, sessionId),
createSession: (context?: string) => ipcRenderer.invoke(IPC_CHANNELS.CREATE_CHAT_SESSION, context),
deleteSession: (sessionId: string) => ipcRenderer.invoke(IPC_CHANNELS.DELETE_CHAT_SESSION, sessionId),
getChecklist: (sessionId: string, messageId: string) => ipcRenderer.invoke(IPC_CHANNELS.GET_CHECKLIST, sessionId, messageId),
saveChecklist: (sessionId: string, messageId: string, tasks: any[]) => ipcRenderer.invoke(IPC_CHANNELS.SAVE_CHECKLIST, sessionId, messageId, tasks),
updateChecklistItem: (sessionId: string, messageId: string, itemId: string, isCompleted: boolean) => ipcRenderer.invoke(IPC_CHANNELS.UPDATE_CHECKLIST_ITEM, sessionId, messageId, itemId, isCompleted),
open: (context?: string) => ipcRenderer.invoke(IPC_CHANNELS.OPEN_CHAT_WINDOW, context),
showDailyPlanNotification: () => ipcRenderer.invoke(IPC_CHANNELS.SHOW_DAILY_PLAN_NOTIFICATION)
},
Expand Down
65 changes: 63 additions & 2 deletions app/src/electron/services/ChatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export class ChatService {
// Get recent activity logs for context (last 2 hours)
const recentLogs = await this.getRecentActivityContext();

// Send message to Flask API with activity context
// Send message to Flask API with activity context and mode
const response = await this.pythonServerService.apiRequest('POST', '/generate', {
message: request.message,
session_id: sessionId,
activity_context: recentLogs
activity_context: recentLogs,
mode: request.mode || 'general',
detective_mode: request.detectiveMode || 'teaching'
});

if (!response.ok) {
Expand Down Expand Up @@ -198,4 +200,63 @@ export class ChatService {
return [];
}
}

async getChecklist(sessionId: string, messageId: string): Promise<any> {
try {
const response = await this.pythonServerService.apiRequest('GET', `/checklist/${sessionId}/${messageId}`);

if (!response.ok) {
throw new Error(response.error || 'Failed to get checklist');
}

const data = response.data;
if (!data.success) {
throw new Error(data.error || 'API returned error');
}

return data.data || [];

} catch (error) {
this.logger.error('Error getting checklist:', error);
return [];
}
}

async saveChecklist(sessionId: string, messageId: string, tasks: any[]): Promise<boolean> {
try {
const response = await this.pythonServerService.apiRequest('POST', `/checklist/${sessionId}/${messageId}`, {
tasks: tasks
});

if (!response.ok) {
throw new Error(response.error || 'Failed to save checklist');
}

const data = response.data;
return data.success || false;

} catch (error) {
this.logger.error('Error saving checklist:', error);
return false;
}
}

async updateChecklistItem(sessionId: string, messageId: string, itemId: string, isCompleted: boolean): Promise<boolean> {
try {
const response = await this.pythonServerService.apiRequest('PATCH', `/checklist/${sessionId}/${messageId}/item/${itemId}`, {
isCompleted: isCompleted
});

if (!response.ok) {
throw new Error(response.error || 'Failed to update checklist item');
}

const data = response.data;
return data.success || false;

} catch (error) {
this.logger.error('Error updating checklist item:', error);
return false;
}
}
}
3 changes: 3 additions & 0 deletions app/src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export const IPC_CHANNELS = {
GET_CHAT_HISTORY: 'get-chat-history',
CREATE_CHAT_SESSION: 'create-chat-session',
DELETE_CHAT_SESSION: 'delete-chat-session',
GET_CHECKLIST: 'get-checklist',
SAVE_CHECKLIST: 'save-checklist',
UPDATE_CHECKLIST_ITEM: 'update-checklist-item',

// Dock Controls
TOGGLE_DOCK: 'toggle-dock',
Expand Down
22 changes: 22 additions & 0 deletions app/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ export interface LLMProvider {
}

// Chat-related types
export type ChatMode = 'blueprint' | 'builder' | 'detective' | 'reviewer' | 'general';
export type DetectiveMode = 'teaching' | 'quick-fix';

export interface ChatMessage {
id: string;
text: string;
sender: 'user' | 'assistant';
timestamp: number;
sessionId: string;
mode?: ChatMode;
checklistId?: string;
}

export interface ChatSession {
Expand All @@ -126,6 +131,8 @@ export interface ChatRequest {
message: string;
sessionId?: string;
context?: string;
mode?: ChatMode;
detectiveMode?: DetectiveMode;
}

export interface ChatResponse {
Expand All @@ -134,6 +141,21 @@ export interface ChatResponse {
messageId: string;
}

export interface ChecklistItem {
id: string;
taskText: string;
isCompleted: boolean;
position: number;
createdAt?: string;
updatedAt?: string;
}

export interface Checklist {
messageId: string;
sessionId: string;
items: ChecklistItem[];
}

export interface GamificationData {
points: number;
level: number;
Expand Down
Loading