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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mrmd-server",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "HTTP server for mrmd - run mrmd in any browser, access from anywhere",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -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
- // Generate a runtime ID
106
- const id = `python-${Date.now()}`;
107
-
108
- // Check if we can reuse an existing runtime
109
- if (!forceNew && venvPath) {
110
- for (const [existingId, runtime] of runtimes) {
111
- if (runtime.type === 'python' && runtime.venv === venvPath) {
112
- if (runtime.process && !runtime.process.killed) {
113
- return res.json({
114
- id: existingId,
115
- port: runtime.port,
116
- url: `http://localhost:${runtime.port}/mrp/v1`,
117
- reused: true,
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 runtime via session API (reuse that logic)
125
- // For now, return a placeholder
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
- message: 'Use /api/session to start runtimes',
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);
@@ -215,7 +215,26 @@
215
215
  // File scanning
216
216
  // ========================================================================
217
217
 
218
- scanFiles: (searchDir) => GET(`/api/file/scan?root=${encodeURIComponent(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);