@mindstudio-ai/local-model-tunnel 0.5.49 → 0.5.51

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.
@@ -25,7 +25,7 @@ import {
25
25
  syncSchema,
26
26
  watchConfigFile,
27
27
  watchTableFiles
28
- } from "./chunk-UFGZOWZ6.js";
28
+ } from "./chunk-ZLWMDAZU.js";
29
29
 
30
30
  // src/dev/ipc/ipc.ts
31
31
  function emitEvent(event, data) {
@@ -698,4 +698,4 @@ async function startHeadless(opts = {}) {
698
698
  export {
699
699
  startHeadless
700
700
  };
701
- //# sourceMappingURL=chunk-PVWSKNUB.js.map
701
+ //# sourceMappingURL=chunk-KC7I6UWI.js.map
@@ -540,6 +540,7 @@ import { build } from "esbuild";
540
540
  var Transpiler = class {
541
541
  projectRoot;
542
542
  outputFiles = /* @__PURE__ */ new Set();
543
+ outDir = null;
543
544
  constructor(projectRoot) {
544
545
  this.projectRoot = projectRoot;
545
546
  this.cleanupOrphans();
@@ -570,6 +571,7 @@ var Transpiler = class {
570
571
  }
571
572
  const outDir = join3(nodeModulesDir, ".cache", "mindstudio-dev");
572
573
  await mkdir(outDir, { recursive: true });
574
+ this.outDir = outDir;
573
575
  const outfile = join3(outDir, `${name}.__ms_dev__.mjs`);
574
576
  await build({
575
577
  entryPoints: [absolutePath],
@@ -586,6 +588,15 @@ var Transpiler = class {
586
588
  log.info("transpiler", "Method transpiled", { duration: Date.now() - start, methodPath, outfile });
587
589
  return outfile;
588
590
  }
591
+ /**
592
+ * Get the output directory where transpiled files and the worker script
593
+ * are written. Returns null if no method has been transpiled yet.
594
+ * This is inside node_modules/.cache/mindstudio-dev/ — Node's module
595
+ * resolution can find @mindstudio-ai/agent from here.
596
+ */
597
+ getOutputDir() {
598
+ return this.outDir;
599
+ }
589
600
  /**
590
601
  * Clean up all transpiled output files.
591
602
  */
@@ -626,9 +637,9 @@ function findNearestNodeModules(startDir) {
626
637
 
627
638
  // src/dev/execution/executor.ts
628
639
  import { fork } from "child_process";
629
- import { writeFile, unlink as unlink2 } from "fs/promises";
640
+ import { writeFile, unlink as unlink2, mkdir as mkdir2 } from "fs/promises";
630
641
  import { readFileSync } from "fs";
631
- import { join as join4 } from "path";
642
+ import { join as join4, dirname as dirname2 } from "path";
632
643
  import { tmpdir } from "os";
633
644
  import { randomBytes } from "crypto";
634
645
  var EXECUTION_TIMEOUT_MS = 30 * 60 * 1e3;
@@ -860,18 +871,24 @@ process.on('message', async (msg) => {
860
871
  process.send({ type: 'ready' });
861
872
  `;
862
873
  }
863
- function detectAlsSupport(projectRoot) {
864
- try {
865
- const pkgPath = join4(projectRoot, "node_modules", "@mindstudio-ai", "agent", "package.json");
866
- const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
867
- const parts = (pkg.version || "").split(".").map(Number);
868
- const [major = 0, minor = 0, patch = 0] = parts;
869
- return major > 0 || minor > 1 || minor === 1 && patch >= 46;
870
- } catch {
871
- return false;
874
+ function detectAlsSupport(scriptDir) {
875
+ let dir = scriptDir;
876
+ while (true) {
877
+ const candidate = join4(dir, "node_modules", "@mindstudio-ai", "agent", "package.json");
878
+ try {
879
+ const pkg = JSON.parse(readFileSync(candidate, "utf-8"));
880
+ const parts = (pkg.version || "").split(".").map(Number);
881
+ const [major = 0, minor = 0, patch = 0] = parts;
882
+ return major > 0 || minor > 1 || minor === 1 && patch >= 46;
883
+ } catch {
884
+ }
885
+ const parent = join4(dir, "..");
886
+ if (parent === dir) break;
887
+ dir = parent;
872
888
  }
889
+ return false;
873
890
  }
874
- async function ensureWorker(projectRoot) {
891
+ async function ensureWorker(projectRoot, scriptDir) {
875
892
  if (worker?.connected && workerProjectRoot === projectRoot) {
876
893
  return worker;
877
894
  }
@@ -889,10 +906,14 @@ async function ensureWorker(projectRoot) {
889
906
  });
890
907
  workerScriptPath = null;
891
908
  }
892
- workerSupportsAls = detectAlsSupport(projectRoot);
893
- log.info("executor", "SDK context support", { als: workerSupportsAls });
909
+ workerSupportsAls = scriptDir ? detectAlsSupport(scriptDir) : false;
910
+ log.info("executor", "SDK context support", { als: workerSupportsAls, scriptDir: scriptDir ?? null });
911
+ const workerDir = workerSupportsAls && scriptDir ? scriptDir : tmpdir();
912
+ if (workerDir !== tmpdir()) {
913
+ await mkdir2(workerDir, { recursive: true });
914
+ }
894
915
  const scriptPath = join4(
895
- tmpdir(),
916
+ workerDir,
896
917
  `ms-dev-worker-${randomBytes(4).toString("hex")}.mjs`
897
918
  );
898
919
  const script = workerSupportsAls ? buildAlsWorkerScript() : buildLegacyWorkerScript();
@@ -970,8 +991,8 @@ function executeMethod(opts) {
970
991
  return enqueue(() => executeMethodInWorker(opts));
971
992
  }
972
993
  async function executeMethodInWorker(opts) {
973
- const w = await ensureWorker(opts.projectRoot);
974
- const id = randomBytes(8).toString("hex");
994
+ const w = await ensureWorker(opts.projectRoot, dirname2(opts.transpiledPath));
995
+ const id = opts.requestId;
975
996
  log.debug("executor", "Sending method to execution process", { id, methodExport: opts.methodExport });
976
997
  return new Promise((resolve3) => {
977
998
  const timer = setTimeout(() => {
@@ -1210,7 +1231,7 @@ function formatErrorForDisplay(error) {
1210
1231
 
1211
1232
  // src/dev/interfaces/agent-config.ts
1212
1233
  import { readFileSync as readFileSync4 } from "fs";
1213
- import { join as join6, dirname as dirname3 } from "path";
1234
+ import { join as join6, dirname as dirname4 } from "path";
1214
1235
 
1215
1236
  // src/dev/interfaces/schema/extract.ts
1216
1237
  import ts3 from "typescript";
@@ -1219,7 +1240,7 @@ import { readFileSync as readFileSync3 } from "fs";
1219
1240
  // src/dev/interfaces/schema/type-map.ts
1220
1241
  import ts from "typescript";
1221
1242
  import { readFileSync as readFileSync2 } from "fs";
1222
- import { dirname as dirname2 } from "path";
1243
+ import { dirname as dirname3 } from "path";
1223
1244
 
1224
1245
  // src/dev/interfaces/schema/resolve-import.ts
1225
1246
  import { existsSync as existsSync2 } from "fs";
@@ -1256,7 +1277,7 @@ function collectTypeMap(filePath) {
1256
1277
  function collectFromFile(sourceFile, filePath, typeMap, visited) {
1257
1278
  if (visited.has(filePath)) return;
1258
1279
  visited.add(filePath);
1259
- const dir = dirname2(filePath);
1280
+ const dir = dirname3(filePath);
1260
1281
  for (const stmt of sourceFile.statements) {
1261
1282
  if (ts.isTypeAliasDeclaration(stmt)) {
1262
1283
  typeMap.set(stmt.name.text, stmt.type);
@@ -1425,7 +1446,7 @@ function readAgentConfig(projectRoot, appConfig) {
1425
1446
  }
1426
1447
  const parsed = JSON.parse(raw);
1427
1448
  const config2 = parsed.agent ?? parsed;
1428
- const agentDir = dirname3(configPath);
1449
+ const agentDir = dirname4(configPath);
1429
1450
  const systemPromptPath = join6(agentDir, config2.systemPrompt);
1430
1451
  let systemPrompt;
1431
1452
  try {
@@ -1630,6 +1651,7 @@ var DevRunner = class {
1630
1651
  roleAssignments: roles.map((roleName) => ({ userId, roleName }))
1631
1652
  } : { ...this.session.auth, userId };
1632
1653
  const result = await executeMethod({
1654
+ requestId,
1633
1655
  transpiledPath,
1634
1656
  methodExport: opts.methodExport,
1635
1657
  input: opts.input,
@@ -1695,9 +1717,10 @@ var DevRunner = class {
1695
1717
  if (!this.session || !this.transpiler) {
1696
1718
  return { success: false, databases: [], error: "Session not started" };
1697
1719
  }
1720
+ const requestId = randomBytes2(8).toString("hex");
1698
1721
  const startTime = Date.now();
1699
1722
  const scenarioName = scenario.name ?? scenario.export;
1700
- log.info("runner", "Scenario starting", { id: scenario.id, name: scenarioName });
1723
+ log.info("runner", "Scenario starting", { requestId, id: scenario.id, name: scenarioName });
1701
1724
  try {
1702
1725
  if (!opts?.skipTruncate) {
1703
1726
  log.debug("runner", "Resetting database for scenario");
@@ -1709,6 +1732,7 @@ var DevRunner = class {
1709
1732
  const authorizationToken = await fetchCallbackToken(this.appId, this.session.sessionId);
1710
1733
  log.debug("runner", "Running scenario seed function", { export: scenario.export });
1711
1734
  const result = await executeMethod({
1735
+ requestId,
1712
1736
  transpiledPath,
1713
1737
  methodExport: scenario.export,
1714
1738
  input: {},
@@ -1846,6 +1870,7 @@ var DevRunner = class {
1846
1870
  roleAssignments: overrideRoles ? overrideRoles.map((roleName) => ({ userId, roleName })) : request.roleAssignments ?? []
1847
1871
  };
1848
1872
  const result = await executeMethod({
1873
+ requestId: request.requestId,
1849
1874
  transpiledPath,
1850
1875
  methodExport: method.export,
1851
1876
  input: request.input,
@@ -2282,7 +2307,14 @@ var DevProxy = class _DevProxy {
2282
2307
  const timeout = setTimeout(() => {
2283
2308
  this.pendingResults.delete(id);
2284
2309
  const client = this.clients.findByCommandId(id);
2285
- if (client) client.activeCommandId = null;
2310
+ if (client) {
2311
+ log.warn("proxy", "Removing unresponsive browser client", { clientId: client.id });
2312
+ this.clients.remove(client.id);
2313
+ try {
2314
+ client.ws.terminate();
2315
+ } catch {
2316
+ }
2317
+ }
2286
2318
  log.warn("proxy", "Browser command timed out", {
2287
2319
  id,
2288
2320
  pendingCount: this.pendingResults.size
@@ -3125,7 +3157,7 @@ ${agentScript}`;
3125
3157
 
3126
3158
  // src/dev/config/app-config.ts
3127
3159
  import { readFileSync as readFileSync6, existsSync as existsSync3 } from "fs";
3128
- import { join as join8, dirname as dirname4 } from "path";
3160
+ import { join as join8, dirname as dirname5 } from "path";
3129
3161
  function detectAppConfig(cwd = process.cwd()) {
3130
3162
  const appJsonPath = join8(cwd, "mindstudio.json");
3131
3163
  if (!existsSync3(appJsonPath)) return null;
@@ -3193,7 +3225,7 @@ function getWebProjectDir(appConfig, cwd = process.cwd()) {
3193
3225
  if (!webInterface) {
3194
3226
  return null;
3195
3227
  }
3196
- return dirname4(join8(cwd, webInterface.path));
3228
+ return dirname5(join8(cwd, webInterface.path));
3197
3229
  }
3198
3230
  function readTableSources(appConfig, cwd = process.cwd()) {
3199
3231
  const results = [];
@@ -3262,7 +3294,7 @@ function detectGitBranch() {
3262
3294
 
3263
3295
  // src/dev/config/table-watcher.ts
3264
3296
  import { watch } from "chokidar";
3265
- import { join as join9, dirname as dirname5, basename as basename2 } from "path";
3297
+ import { join as join9, dirname as dirname6, basename as basename2 } from "path";
3266
3298
  function watchTableFiles(tables, cwd, onChanged) {
3267
3299
  if (tables.length === 0) return () => {
3268
3300
  };
@@ -3280,7 +3312,7 @@ function watchTableFiles(tables, cwd, onChanged) {
3280
3312
  const dirToFiles = /* @__PURE__ */ new Map();
3281
3313
  for (const table of tables) {
3282
3314
  const absPath = join9(cwd, table.path);
3283
- const dir = dirname5(absPath);
3315
+ const dir = dirname6(absPath);
3284
3316
  const file = basename2(absPath);
3285
3317
  if (!dirToFiles.has(dir)) dirToFiles.set(dir, /* @__PURE__ */ new Set());
3286
3318
  dirToFiles.get(dir).add(file);
@@ -3369,4 +3401,4 @@ export {
3369
3401
  watchTableFiles,
3370
3402
  watchConfigFile
3371
3403
  };
3372
- //# sourceMappingURL=chunk-UFGZOWZ6.js.map
3404
+ //# sourceMappingURL=chunk-ZLWMDAZU.js.map