mrmd-server 0.1.9 → 0.1.11
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.
- package/package.json +1 -1
- package/src/api/runtime.js +33 -22
- package/static/http-shim.js +20 -1
package/package.json
CHANGED
package/src/api/runtime.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { Router } from 'express';
|
|
8
|
+
import path from 'path';
|
|
8
9
|
|
|
9
10
|
// Global runtime registry (shared with session.js in a real impl)
|
|
10
11
|
const runtimes = new Map();
|
|
@@ -100,32 +101,42 @@ export function createRuntimeRoutes(ctx) {
|
|
|
100
101
|
*/
|
|
101
102
|
router.post('/start-python', async (req, res) => {
|
|
102
103
|
try {
|
|
103
|
-
const { venvPath, forceNew = false } = req.body;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
104
|
+
const { venvPath, forceNew = false, cwd } = req.body;
|
|
105
|
+
const { sessionService } = ctx;
|
|
106
|
+
|
|
107
|
+
if (!venvPath) {
|
|
108
|
+
return res.status(400).json({ error: 'venvPath required' });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Check if we can reuse an existing session
|
|
112
|
+
if (!forceNew) {
|
|
113
|
+
const existing = sessionService.list().find(s =>
|
|
114
|
+
s.language === 'python' && s.venv === venvPath && s.alive
|
|
115
|
+
);
|
|
116
|
+
if (existing) {
|
|
117
|
+
return res.json({
|
|
118
|
+
id: existing.name,
|
|
119
|
+
port: existing.port,
|
|
120
|
+
url: `http://localhost:${existing.port}/mrp/v1`,
|
|
121
|
+
reused: true,
|
|
122
|
+
});
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
125
|
|
|
124
|
-
// Start new
|
|
125
|
-
|
|
126
|
+
// Start a new Python session
|
|
127
|
+
const sessionName = `runtime-${Date.now()}`;
|
|
128
|
+
const result = await sessionService.start({
|
|
129
|
+
name: sessionName,
|
|
130
|
+
language: 'python',
|
|
131
|
+
venv: venvPath,
|
|
132
|
+
cwd: cwd || path.dirname(venvPath),
|
|
133
|
+
});
|
|
134
|
+
|
|
126
135
|
res.json({
|
|
127
|
-
id,
|
|
128
|
-
|
|
136
|
+
id: result.name,
|
|
137
|
+
port: result.port,
|
|
138
|
+
url: `http://localhost:${result.port}/mrp/v1`,
|
|
139
|
+
pid: result.pid,
|
|
129
140
|
});
|
|
130
141
|
} catch (err) {
|
|
131
142
|
console.error('[runtime:start-python]', err);
|
package/static/http-shim.js
CHANGED
|
@@ -215,7 +215,26 @@
|
|
|
215
215
|
// File scanning
|
|
216
216
|
// ========================================================================
|
|
217
217
|
|
|
218
|
-
scanFiles: (searchDir) =>
|
|
218
|
+
scanFiles: (searchDir) => {
|
|
219
|
+
// Trigger scan and emit results via onFilesUpdate (matches electron behavior)
|
|
220
|
+
GET(`/api/file/scan?root=${encodeURIComponent(searchDir || '')}`)
|
|
221
|
+
.then(files => {
|
|
222
|
+
// Emit files-update event with the results
|
|
223
|
+
const handlers = eventHandlers['files-update'];
|
|
224
|
+
if (handlers) {
|
|
225
|
+
handlers.forEach(cb => {
|
|
226
|
+
try {
|
|
227
|
+
cb({ files });
|
|
228
|
+
} catch (err) {
|
|
229
|
+
console.error('[http-shim] files-update handler error:', err);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
})
|
|
234
|
+
.catch(err => {
|
|
235
|
+
console.error('[http-shim] scanFiles error:', err);
|
|
236
|
+
});
|
|
237
|
+
},
|
|
219
238
|
|
|
220
239
|
onFilesUpdate: (callback) => {
|
|
221
240
|
eventHandlers['files-update'].push(callback);
|