@@ -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 {
0 commit comments