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 <noreply@anthropic.com>
This commit is contained in:
Jiang Bohan 2026-02-04 03:12:17 +08:00
parent a80c858ce5
commit a157c6546d
4 changed files with 107 additions and 0 deletions

View file

@ -65,6 +65,12 @@ interface SkillAddResult {
skills?: string[]
}
interface ProfileData {
profileId: string | undefined
name: string | undefined
userContent: string | undefined
}
interface ElectronAPI {
hub: {
init: () => Promise<unknown>
@ -97,6 +103,11 @@ interface ElectronAPI {
agent: {
status: () => Promise<unknown>
}
profile: {
get: () => Promise<ProfileData>
updateName: (name: string) => Promise<unknown>
updateUser: (content: string) => Promise<unknown>
}
}
// Used in Renderer process, expose in `preload.ts`

View file

@ -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()
}
/**

View file

@ -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<ProfileData> => {
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 }
})
}

View file

@ -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<ProfileData> => ipcRenderer.invoke('profile:get'),
updateName: (name: string) => ipcRenderer.invoke('profile:updateName', name),
updateUser: (content: string) => ipcRenderer.invoke('profile:updateUser', content),
},
}
// Expose to renderer