multica/apps/desktop/electron/ipc/profile.ts
Jiang Bohan a157c6546d 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>
2026-02-04 13:26:40 +08:00

80 lines
1.7 KiB
TypeScript

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