Skip to content

Commit abf4426

Browse files
feat: add global worker agent templates and improve agent config ui
1 parent a9ba42c commit abf4426

10 files changed

Lines changed: 835 additions & 10 deletions

File tree

electron/main/index.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,88 @@ function registerIpcHandlers() {
16211621
}
16221622
);
16231623

1624+
// ======================== agent-templates (global Worker Agent templates) ========================
1625+
const AGENT_TEMPLATES_FILE = 'agent-templates.json';
1626+
1627+
function getAgentTemplatesPath(userId: string): string {
1628+
return path.join(os.homedir(), '.eigent', userId, AGENT_TEMPLATES_FILE);
1629+
}
1630+
1631+
async function loadAgentTemplates(userId: string): Promise<{
1632+
version: number;
1633+
templates: Array<{
1634+
id: string;
1635+
name: string;
1636+
description: string;
1637+
tools: string[];
1638+
mcp_tools: any;
1639+
custom_model_config?: any;
1640+
updatedAt: number;
1641+
}>;
1642+
}> {
1643+
const configPath = getAgentTemplatesPath(userId);
1644+
const defaultData = { version: 1, templates: [] };
1645+
if (!existsSync(configPath)) {
1646+
try {
1647+
await fsp.mkdir(path.dirname(configPath), { recursive: true });
1648+
await fsp.writeFile(
1649+
configPath,
1650+
JSON.stringify(defaultData, null, 2),
1651+
'utf-8'
1652+
);
1653+
return defaultData;
1654+
} catch (error: any) {
1655+
log.error('Failed to create default agent-templates', error);
1656+
return defaultData;
1657+
}
1658+
}
1659+
try {
1660+
const content = await fsp.readFile(configPath, 'utf-8');
1661+
const data = JSON.parse(content);
1662+
if (!Array.isArray(data.templates)) data.templates = [];
1663+
return { version: data.version ?? 1, templates: data.templates };
1664+
} catch (error: any) {
1665+
log.error('Failed to load agent-templates', error);
1666+
return defaultData;
1667+
}
1668+
}
1669+
1670+
async function saveAgentTemplates(
1671+
userId: string,
1672+
data: { version: number; templates: any[] }
1673+
): Promise<void> {
1674+
const configPath = getAgentTemplatesPath(userId);
1675+
await fsp.mkdir(path.dirname(configPath), { recursive: true });
1676+
await fsp.writeFile(configPath, JSON.stringify(data, null, 2), 'utf-8');
1677+
}
1678+
1679+
ipcMain.handle('agent-templates-load', async (_event, userId: string) => {
1680+
try {
1681+
const data = await loadAgentTemplates(userId);
1682+
return { success: true, templates: data.templates };
1683+
} catch (error: any) {
1684+
log.error('agent-templates-load failed', error);
1685+
return { success: false, error: error?.message, templates: [] };
1686+
}
1687+
});
1688+
1689+
ipcMain.handle(
1690+
'agent-templates-save',
1691+
async (_event, userId: string, templates: any[]) => {
1692+
try {
1693+
const current = await loadAgentTemplates(userId);
1694+
await saveAgentTemplates(userId, {
1695+
version: current.version,
1696+
templates,
1697+
});
1698+
return { success: true };
1699+
} catch (error: any) {
1700+
log.error('agent-templates-save failed', error);
1701+
return { success: false, error: error?.message };
1702+
}
1703+
}
1704+
);
1705+
16241706
// Initialize skills config for a user (ensures config file exists)
16251707
ipcMain.handle('skill-config-init', async (_event, userId: string) => {
16261708
try {

electron/preload/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
201201
ipcRenderer.invoke('skill-config-update', userId, skillName, skillConfig),
202202
skillConfigDelete: (userId: string, skillName: string) =>
203203
ipcRenderer.invoke('skill-config-delete', userId, skillName),
204+
// Global Agent Templates (~/.eigent/<userId>/agent-templates.json)
205+
agentTemplatesLoad: (userId: string) =>
206+
ipcRenderer.invoke('agent-templates-load', userId),
207+
agentTemplatesSave: (userId: string, templates: any[]) =>
208+
ipcRenderer.invoke('agent-templates-save', userId, templates),
204209
});
205210

206211
// --------- Preload scripts loading ---------

0 commit comments

Comments
 (0)