@pmate/cli 0.44.3 → 0.44.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,7 @@ const { homedir } = require('node:os')
|
|
|
4
4
|
const path = require('node:path')
|
|
5
5
|
const methods = ['capabilities','workspaces.list','agents.list','agents.create','agents.update','plugins.list','plugins.configure','runtime.checkEnvironment','runtime.install','runtime.status','scripts.run']
|
|
6
6
|
function createAgentRuntime({ platform = process.platform, home = homedir(), execute, fetcher = fetch } = {}) {
|
|
7
|
+
let identityEpoch=0
|
|
7
8
|
let identity, installation, progress = { phase: 'idle' }
|
|
8
9
|
const root = path.join(home, '.pmate', 'merry-runtime')
|
|
9
10
|
const run = execute || ((file, args, cwd) => new Promise((resolve, reject) => {
|
|
@@ -65,7 +66,15 @@ function createAgentRuntime({ platform = process.platform, home = homedir(), exe
|
|
|
65
66
|
if(method==='agents.create'&&expectedRevision!==undefined)throw new Error('创建不能指定 revision')
|
|
66
67
|
return api(base+(method==='plugins.configure'?'/runtime-plugins/':'/vega-agents/')+encodeURIComponent(id),'PUT',{...config,...(expectedRevision===undefined?{}:{expectedRevision})})
|
|
67
68
|
}
|
|
68
|
-
return { invoke,
|
|
69
|
+
return { invoke,
|
|
70
|
+
async configureIdentity(value, configure) {
|
|
71
|
+
const epoch=++identityEpoch;identity=undefined
|
|
72
|
+
const result=await configure(value)
|
|
73
|
+
if(epoch===identityEpoch)identity={appId:value.appId,token:value.token}
|
|
74
|
+
return result
|
|
75
|
+
},
|
|
76
|
+
setIdentity(value) { identityEpoch++;identity=value ? {appId:value.appId,token:value.token} : undefined }
|
|
77
|
+
}
|
|
69
78
|
}
|
|
70
79
|
function installAgentRuntime({ ipcMain, trusted, runtime }) {
|
|
71
80
|
ipcMain.handle('pmate:electron:invoke',(event,method,input)=>{if(!trusted(event))throw new Error('Untrusted Electron sender');return runtime.invoke(method,input)})
|
|
@@ -71,6 +71,7 @@ else {
|
|
|
71
71
|
})
|
|
72
72
|
desktopApps = installDesktopApps({ ipcMain, BrowserWindow, session: desktopSession, config, installNavigationRestrictions,
|
|
73
73
|
openExternal: url => shell.openExternal(url), trusted: event => desktopNotifications.trusted(event) })
|
|
74
|
+
if (config.app === 'pmate:merry') installAgentRuntime({ ipcMain, trusted: event => desktopNotifications.trusted(event), runtime: agentRuntime })
|
|
74
75
|
updateController = installUpdateHandlers({ ipcMain, app, shell, appId: config.app, trusted: event => desktopNotifications.trusted(event), updater: require('electron-updater').autoUpdater, getWindow: () => mainWindow })
|
|
75
76
|
const instanceId = desktopInstanceId(app.getPath('userData'))
|
|
76
77
|
const rendererReach = createRendererReach({ ipcMain, getWindow: () => mainWindow, trusted: event => desktopNotifications.trusted(event) })
|
|
@@ -95,9 +96,7 @@ else {
|
|
|
95
96
|
})
|
|
96
97
|
ipcMain.handle('pmate:reach:configure', async (event, identity) => {
|
|
97
98
|
if (!desktopNotifications.trusted(event)) throw new Error('Untrusted reach sender')
|
|
98
|
-
|
|
99
|
-
agentRuntime.setIdentity(identity)
|
|
100
|
-
return result
|
|
99
|
+
return agentRuntime.configureIdentity(identity, value => desktopReach.configure(value))
|
|
101
100
|
})
|
|
102
101
|
ipcMain.handle('pmate:reach:stop', event => {
|
|
103
102
|
if (!desktopNotifications.trusted(event)) throw new Error('Untrusted reach sender')
|