From a157c6546dc853b9193f69dc6202597dec0a72d9 Mon Sep 17 00:00:00 2001 From: Jiang Bohan Date: Wed, 4 Feb 2026 03:12:17 +0800 Subject: [PATCH] feat(desktop): add profile IPC handlers Add IPC handlers for profile management: - profile:get - Get profile name and user content - profile:updateName - Update agent display name - profile:updateUser - Update user.md content Co-Authored-By: Claude Opus 4.5 --- apps/desktop/electron/electron-env.d.ts | 11 ++++ apps/desktop/electron/ipc/index.ts | 3 + apps/desktop/electron/ipc/profile.ts | 80 +++++++++++++++++++++++++ apps/desktop/electron/preload.ts | 13 ++++ 4 files changed, 107 insertions(+) create mode 100644 apps/desktop/electron/ipc/profile.ts diff --git a/apps/desktop/electron/electron-env.d.ts b/apps/desktop/electron/electron-env.d.ts index 583a19b9..c92ef48a 100644 --- a/apps/desktop/electron/electron-env.d.ts +++ b/apps/desktop/electron/electron-env.d.ts @@ -65,6 +65,12 @@ interface SkillAddResult { skills?: string[] } +interface ProfileData { + profileId: string | undefined + name: string | undefined + userContent: string | undefined +} + interface ElectronAPI { hub: { init: () => Promise @@ -97,6 +103,11 @@ interface ElectronAPI { agent: { status: () => Promise } + profile: { + get: () => Promise + updateName: (name: string) => Promise + updateUser: (content: string) => Promise + } } // Used in Renderer process, expose in `preload.ts` diff --git a/apps/desktop/electron/ipc/index.ts b/apps/desktop/electron/ipc/index.ts index 71bbec88..762fe18f 100644 --- a/apps/desktop/electron/ipc/index.ts +++ b/apps/desktop/electron/ipc/index.ts @@ -4,10 +4,12 @@ export { registerAgentIpcHandlers, cleanupAgent } from './agent.js' export { registerSkillsIpcHandlers } from './skills.js' export { registerHubIpcHandlers, cleanupHub, initializeHub } from './hub.js' +export { registerProfileIpcHandlers } from './profile.js' import { registerAgentIpcHandlers, cleanupAgent } from './agent.js' import { registerSkillsIpcHandlers } from './skills.js' import { registerHubIpcHandlers, cleanupHub, initializeHub } from './hub.js' +import { registerProfileIpcHandlers } from './profile.js' /** * Register all IPC handlers. @@ -17,6 +19,7 @@ export function registerAllIpcHandlers(): void { registerHubIpcHandlers() registerAgentIpcHandlers() registerSkillsIpcHandlers() + registerProfileIpcHandlers() } /** diff --git a/apps/desktop/electron/ipc/profile.ts b/apps/desktop/electron/ipc/profile.ts new file mode 100644 index 00000000..bfb924da --- /dev/null +++ b/apps/desktop/electron/ipc/profile.ts @@ -0,0 +1,80 @@ +/** + * Profile IPC handlers for Electron main process. + * + * Manages agent profile settings like name and user.md content. + */ +import { ipcMain } from 'electron' +import { getCurrentHub } from './hub.js' + +/** + * Get the default agent from Hub. + */ +function getDefaultAgent() { + const hub = getCurrentHub() + if (!hub) return null + + const agentIds = hub.listAgents() + if (agentIds.length === 0) return null + + return hub.getAgent(agentIds[0]) ?? null +} + +/** + * Profile data returned to renderer. + */ +export interface ProfileData { + profileId: string | undefined + name: string | undefined + userContent: string | undefined +} + +/** + * Register all Profile-related IPC handlers. + */ +export function registerProfileIpcHandlers(): void { + /** + * Get profile data (name + user content). + */ + ipcMain.handle('profile:get', async (): Promise => { + const agent = getDefaultAgent() + if (!agent) { + return { + profileId: undefined, + name: undefined, + userContent: undefined, + } + } + + return { + profileId: agent.getProfileId(), + name: agent.getAgentName(), + userContent: agent.getUserContent(), + } + }) + + /** + * Update agent display name. + */ + ipcMain.handle('profile:updateName', async (_event, name: string) => { + const agent = getDefaultAgent() + if (!agent) { + return { error: 'No agent available' } + } + + agent.setAgentName(name) + return { ok: true, name } + }) + + /** + * Update user.md content. + */ + ipcMain.handle('profile:updateUser', async (_event, content: string) => { + const agent = getDefaultAgent() + if (!agent) { + return { error: 'No agent available' } + } + + agent.setUserContent(content) + return { ok: true } + }) +} diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts index 8c898819..e0afbf9a 100644 --- a/apps/desktop/electron/preload.ts +++ b/apps/desktop/electron/preload.ts @@ -37,6 +37,12 @@ export interface SkillInfo { triggers: string[] } +export interface ProfileData { + profileId: string | undefined + name: string | undefined + userContent: string | undefined +} + // ============================================================================ // Expose typed API to Renderer process // ============================================================================ @@ -84,6 +90,13 @@ const electronAPI = { agent: { status: () => ipcRenderer.invoke('agent:status'), }, + + // Profile management + profile: { + get: (): Promise => ipcRenderer.invoke('profile:get'), + updateName: (name: string) => ipcRenderer.invoke('profile:updateName', name), + updateUser: (content: string) => ipcRenderer.invoke('profile:updateUser', content), + }, } // Expose to renderer