@mindstudio-ai/local-model-tunnel 0.5.45 → 0.5.46

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.
@@ -890,11 +890,11 @@ async function ensureWorker(projectRoot) {
890
890
  stdio: ["ignore", "pipe", "pipe", "ipc"],
891
891
  env: { ...process.env }
892
892
  });
893
- await new Promise((resolve2, reject) => {
893
+ await new Promise((resolve3, reject) => {
894
894
  const onMessage = (msg) => {
895
895
  if (msg?.type === "ready") {
896
896
  child.off("message", onMessage);
897
- resolve2();
897
+ resolve3();
898
898
  }
899
899
  };
900
900
  child.on("message", onMessage);
@@ -958,16 +958,16 @@ async function executeMethodInWorker(opts) {
958
958
  const w = await ensureWorker(opts.projectRoot);
959
959
  const id = randomBytes(8).toString("hex");
960
960
  log.debug("executor", "Sending method to execution process", { id, methodExport: opts.methodExport });
961
- return new Promise((resolve2) => {
961
+ return new Promise((resolve3) => {
962
962
  const timer = setTimeout(() => {
963
963
  pending.delete(id);
964
964
  log.warn("executor", "Method execution timed out", { id, methodExport: opts.methodExport });
965
- resolve2({
965
+ resolve3({
966
966
  success: false,
967
967
  error: { message: "Method execution timed out after 30m" }
968
968
  });
969
969
  }, EXECUTION_TIMEOUT_MS);
970
- pending.set(id, { resolve: resolve2, timer });
970
+ pending.set(id, { resolve: resolve3, timer });
971
971
  if (opts.sessionId) {
972
972
  requestMeta.set(id, { sessionId: opts.sessionId, method: opts.methodExport, input: opts.input });
973
973
  }
@@ -1167,8 +1167,6 @@ async function disconnectHeartbeat() {
1167
1167
  }
1168
1168
 
1169
1169
  // src/dev/execution/runner.ts
1170
- import { readFileSync as readFileSync3 } from "fs";
1171
- import { join as join6 } from "path";
1172
1170
  import { randomBytes as randomBytes2 } from "crypto";
1173
1171
 
1174
1172
  // src/dev/execution/format-error.ts
@@ -1195,9 +1193,205 @@ function formatErrorForDisplay(error) {
1195
1193
  return parts.join("\n");
1196
1194
  }
1197
1195
 
1198
- // src/dev/execution/agent-config.ts
1196
+ // src/dev/interfaces/agent-config.ts
1197
+ import { readFileSync as readFileSync4 } from "fs";
1198
+ import { join as join6, dirname as dirname3 } from "path";
1199
+
1200
+ // src/dev/interfaces/schema/extract.ts
1201
+ import ts3 from "typescript";
1202
+ import { readFileSync as readFileSync3 } from "fs";
1203
+
1204
+ // src/dev/interfaces/schema/type-map.ts
1205
+ import ts from "typescript";
1199
1206
  import { readFileSync as readFileSync2 } from "fs";
1200
- import { join as join5, dirname as dirname2 } from "path";
1207
+ import { dirname as dirname2 } from "path";
1208
+
1209
+ // src/dev/interfaces/schema/resolve-import.ts
1210
+ import { existsSync as existsSync2 } from "fs";
1211
+ import { resolve as resolve2 } from "path";
1212
+ var EXTENSIONS = [".ts", ".tsx", "/index.ts", "/index.tsx"];
1213
+ function resolveImportPath(specifier, fromDir) {
1214
+ if (!specifier.startsWith("./") && !specifier.startsWith("../")) {
1215
+ return null;
1216
+ }
1217
+ const base = resolve2(fromDir, specifier);
1218
+ if (existsSync2(base) && !base.endsWith("/")) return base;
1219
+ for (const ext of EXTENSIONS) {
1220
+ const candidate = base + ext;
1221
+ if (existsSync2(candidate)) return candidate;
1222
+ }
1223
+ return null;
1224
+ }
1225
+
1226
+ // src/dev/interfaces/schema/type-map.ts
1227
+ function collectTypeMap(filePath) {
1228
+ const typeMap = /* @__PURE__ */ new Map();
1229
+ const visited = /* @__PURE__ */ new Set();
1230
+ const source = readFileSync2(filePath, "utf-8");
1231
+ const sourceFile = ts.createSourceFile(
1232
+ filePath,
1233
+ source,
1234
+ ts.ScriptTarget.Latest,
1235
+ true,
1236
+ ts.ScriptKind.TS
1237
+ );
1238
+ collectFromFile(sourceFile, filePath, typeMap, visited);
1239
+ return { typeMap, sourceFile };
1240
+ }
1241
+ function collectFromFile(sourceFile, filePath, typeMap, visited) {
1242
+ if (visited.has(filePath)) return;
1243
+ visited.add(filePath);
1244
+ const dir = dirname2(filePath);
1245
+ for (const stmt of sourceFile.statements) {
1246
+ if (ts.isTypeAliasDeclaration(stmt)) {
1247
+ typeMap.set(stmt.name.text, stmt.type);
1248
+ }
1249
+ if (ts.isInterfaceDeclaration(stmt)) {
1250
+ const typeLiteral = ts.factory.createTypeLiteralNode(
1251
+ stmt.members.filter(ts.isPropertySignature)
1252
+ );
1253
+ typeMap.set(stmt.name.text, typeLiteral);
1254
+ }
1255
+ if (ts.isImportDeclaration(stmt) && stmt.moduleSpecifier && ts.isStringLiteral(stmt.moduleSpecifier)) {
1256
+ const specifier = stmt.moduleSpecifier.text;
1257
+ const resolved = resolveImportPath(specifier, dir);
1258
+ if (!resolved) continue;
1259
+ try {
1260
+ const importSource = readFileSync2(resolved, "utf-8");
1261
+ const importFile = ts.createSourceFile(
1262
+ resolved,
1263
+ importSource,
1264
+ ts.ScriptTarget.Latest,
1265
+ true,
1266
+ ts.ScriptKind.TS
1267
+ );
1268
+ collectFromFile(importFile, resolved, typeMap, visited);
1269
+ } catch {
1270
+ }
1271
+ }
1272
+ }
1273
+ }
1274
+
1275
+ // src/dev/interfaces/schema/convert.ts
1276
+ import ts2 from "typescript";
1277
+ var STRING_FALLBACK = { type: "string" };
1278
+ function convertTypeNode(node, typeMap, sourceFile) {
1279
+ if (ts2.isTypeLiteralNode(node)) {
1280
+ return convertTypeLiteral(node, typeMap, sourceFile);
1281
+ }
1282
+ if (node.kind === ts2.SyntaxKind.StringKeyword) return { type: "string" };
1283
+ if (node.kind === ts2.SyntaxKind.NumberKeyword) return { type: "number" };
1284
+ if (node.kind === ts2.SyntaxKind.BooleanKeyword) return { type: "boolean" };
1285
+ if (node.kind === ts2.SyntaxKind.AnyKeyword) return { type: "object" };
1286
+ if (node.kind === ts2.SyntaxKind.UnknownKeyword) return { type: "object" };
1287
+ if (ts2.isArrayTypeNode(node)) {
1288
+ const items = convertTypeNode(node.elementType, typeMap, sourceFile);
1289
+ return { type: "array", items };
1290
+ }
1291
+ if (ts2.isTypeReferenceNode(node) && ts2.isIdentifier(node.typeName) && node.typeName.text === "Array" && node.typeArguments?.length === 1) {
1292
+ const items = convertTypeNode(node.typeArguments[0], typeMap, sourceFile);
1293
+ return { type: "array", items };
1294
+ }
1295
+ if (ts2.isTypeReferenceNode(node) && ts2.isIdentifier(node.typeName) && node.typeName.text === "Record" && node.typeArguments?.length === 2) {
1296
+ const valueSchema = convertTypeNode(node.typeArguments[1], typeMap, sourceFile);
1297
+ return { type: "object", additionalProperties: valueSchema };
1298
+ }
1299
+ if (ts2.isUnionTypeNode(node)) {
1300
+ const allStringLiterals = node.types.every(
1301
+ (t) => ts2.isLiteralTypeNode(t) && ts2.isStringLiteral(t.literal)
1302
+ );
1303
+ if (allStringLiterals) {
1304
+ const enumValues = node.types.map(
1305
+ (t) => t.literal.text
1306
+ );
1307
+ return { type: "string", enum: enumValues };
1308
+ }
1309
+ return STRING_FALLBACK;
1310
+ }
1311
+ if (ts2.isParenthesizedTypeNode(node)) {
1312
+ return convertTypeNode(node.type, typeMap, sourceFile);
1313
+ }
1314
+ if (ts2.isIntersectionTypeNode(node)) {
1315
+ const merged = { type: "object", properties: {}, required: [] };
1316
+ for (const member of node.types) {
1317
+ const sub = convertTypeNode(member, typeMap, sourceFile);
1318
+ if (sub.properties) {
1319
+ Object.assign(merged.properties, sub.properties);
1320
+ if (sub.required) merged.required.push(...sub.required);
1321
+ }
1322
+ }
1323
+ if (merged.required.length === 0) delete merged.required;
1324
+ if (Object.keys(merged.properties).length === 0) delete merged.properties;
1325
+ return merged;
1326
+ }
1327
+ if (ts2.isTypeReferenceNode(node) && ts2.isIdentifier(node.typeName)) {
1328
+ const resolved = typeMap.get(node.typeName.text);
1329
+ if (resolved) return convertTypeNode(resolved, typeMap, sourceFile);
1330
+ }
1331
+ return STRING_FALLBACK;
1332
+ }
1333
+ function convertTypeLiteral(node, typeMap, sourceFile) {
1334
+ const properties = {};
1335
+ const required = [];
1336
+ for (const member of node.members) {
1337
+ if (!ts2.isPropertySignature(member) || !member.name) continue;
1338
+ const name = member.name.getText(sourceFile);
1339
+ const optional = !!member.questionToken;
1340
+ if (member.type) {
1341
+ properties[name] = convertTypeNode(member.type, typeMap, sourceFile);
1342
+ if (!optional) required.push(name);
1343
+ }
1344
+ }
1345
+ const schema = { type: "object", properties };
1346
+ if (required.length > 0) schema.required = required;
1347
+ return schema;
1348
+ }
1349
+
1350
+ // src/dev/interfaces/schema/types.ts
1351
+ var EMPTY_OBJECT_SCHEMA = { type: "object", properties: {} };
1352
+
1353
+ // src/dev/interfaces/schema/extract.ts
1354
+ function extractInputSchema(filePath, exportName) {
1355
+ let source;
1356
+ try {
1357
+ source = readFileSync3(filePath, "utf-8");
1358
+ } catch {
1359
+ return EMPTY_OBJECT_SCHEMA;
1360
+ }
1361
+ const { typeMap, sourceFile } = collectTypeMap(filePath);
1362
+ const fn = findExportedFunction(sourceFile, exportName);
1363
+ if (!fn || fn.parameters.length === 0) return EMPTY_OBJECT_SCHEMA;
1364
+ const param = fn.parameters[0];
1365
+ if (!param.type) return EMPTY_OBJECT_SCHEMA;
1366
+ return convertTypeNode(param.type, typeMap, sourceFile);
1367
+ }
1368
+ function findExportedFunction(sourceFile, name) {
1369
+ for (const stmt of sourceFile.statements) {
1370
+ if (ts3.isFunctionDeclaration(stmt) && stmt.name?.text === name && hasExportModifier(stmt)) {
1371
+ return stmt;
1372
+ }
1373
+ if (ts3.isVariableStatement(stmt) && hasExportModifier(stmt)) {
1374
+ for (const decl of stmt.declarationList.declarations) {
1375
+ if (ts3.isIdentifier(decl.name) && decl.name.text === name && decl.initializer) {
1376
+ if (ts3.isArrowFunction(decl.initializer)) {
1377
+ return decl.initializer;
1378
+ }
1379
+ if (ts3.isFunctionExpression(decl.initializer)) {
1380
+ return decl.initializer;
1381
+ }
1382
+ }
1383
+ }
1384
+ }
1385
+ }
1386
+ return void 0;
1387
+ }
1388
+ function hasExportModifier(node) {
1389
+ return ts3.canHaveModifiers(node) && (ts3.getModifiers(node) ?? []).some(
1390
+ (m) => m.kind === ts3.SyntaxKind.ExportKeyword
1391
+ );
1392
+ }
1393
+
1394
+ // src/dev/interfaces/agent-config.ts
1201
1395
  function readAgentConfig(projectRoot, appConfig) {
1202
1396
  const agentInterface = appConfig.interfaces.find(
1203
1397
  (i) => i.type === "agent" && i.enabled !== false
@@ -1205,10 +1399,10 @@ function readAgentConfig(projectRoot, appConfig) {
1205
1399
  if (!agentInterface) {
1206
1400
  throw new Error("No agent interface configured in mindstudio.json");
1207
1401
  }
1208
- const configPath = join5(projectRoot, agentInterface.path);
1402
+ const configPath = join6(projectRoot, agentInterface.path);
1209
1403
  let raw;
1210
1404
  try {
1211
- raw = readFileSync2(configPath, "utf-8");
1405
+ raw = readFileSync4(configPath, "utf-8");
1212
1406
  } catch {
1213
1407
  throw new Error(
1214
1408
  `Agent config not found at ${agentInterface.path} \u2014 run your build command`
@@ -1216,11 +1410,11 @@ function readAgentConfig(projectRoot, appConfig) {
1216
1410
  }
1217
1411
  const parsed = JSON.parse(raw);
1218
1412
  const config2 = parsed.agent ?? parsed;
1219
- const agentDir = dirname2(configPath);
1220
- const systemPromptPath = join5(agentDir, config2.systemPrompt);
1413
+ const agentDir = dirname3(configPath);
1414
+ const systemPromptPath = join6(agentDir, config2.systemPrompt);
1221
1415
  let systemPrompt;
1222
1416
  try {
1223
- systemPrompt = readFileSync2(systemPromptPath, "utf-8");
1417
+ systemPrompt = readFileSync4(systemPromptPath, "utf-8");
1224
1418
  } catch {
1225
1419
  throw new Error(
1226
1420
  `Agent system prompt not found at ${config2.systemPrompt} \u2014 run your build command`
@@ -1228,21 +1422,23 @@ function readAgentConfig(projectRoot, appConfig) {
1228
1422
  }
1229
1423
  const tools = (config2.tools ?? []).map(
1230
1424
  (tool) => {
1231
- const descPath = join5(agentDir, tool.description);
1425
+ const descPath = join6(agentDir, tool.description);
1232
1426
  let description;
1233
1427
  try {
1234
- description = readFileSync2(descPath, "utf-8");
1428
+ description = readFileSync4(descPath, "utf-8");
1235
1429
  } catch {
1236
1430
  throw new Error(
1237
1431
  `Agent tool description not found at ${tool.description} for method "${tool.method}" \u2014 run your build command`
1238
1432
  );
1239
1433
  }
1240
- const entry = {
1241
- name: tool.method,
1242
- description
1243
- };
1244
- if (tool.inputSchema) entry.inputSchema = tool.inputSchema;
1245
- return entry;
1434
+ let inputSchema;
1435
+ if (tool.inputSchema) {
1436
+ inputSchema = tool.inputSchema;
1437
+ } else {
1438
+ const method = appConfig.methods.find((m) => m.id === tool.method);
1439
+ inputSchema = method ? extractInputSchema(join6(projectRoot, method.path), method.export) : EMPTY_OBJECT_SCHEMA;
1440
+ }
1441
+ return { name: tool.method, description, inputSchema };
1246
1442
  }
1247
1443
  );
1248
1444
  return {
@@ -1254,6 +1450,51 @@ function readAgentConfig(projectRoot, appConfig) {
1254
1450
  };
1255
1451
  }
1256
1452
 
1453
+ // src/dev/interfaces/api-config.ts
1454
+ import { readFileSync as readFileSync5 } from "fs";
1455
+ import { join as join7 } from "path";
1456
+ function readApiConfig(projectRoot, appConfig) {
1457
+ const apiInterface = appConfig.interfaces.find(
1458
+ (i) => i.type === "api" && i.enabled !== false
1459
+ );
1460
+ if (!apiInterface) {
1461
+ throw new Error("No API interface config found");
1462
+ }
1463
+ const apiJsonPath = join7(projectRoot, apiInterface.path);
1464
+ const raw = readFileSync5(apiJsonPath, "utf-8");
1465
+ const parsed = JSON.parse(raw);
1466
+ if (!parsed.api) {
1467
+ throw new Error("No API interface config found");
1468
+ }
1469
+ return parsed.api;
1470
+ }
1471
+
1472
+ // src/dev/interfaces/read-config.ts
1473
+ function readConfig(projectRoot, appConfig) {
1474
+ let agent = null;
1475
+ try {
1476
+ agent = readAgentConfig(projectRoot, appConfig);
1477
+ } catch (err) {
1478
+ log.debug("config", "Agent config not available", {
1479
+ error: err instanceof Error ? err.message : String(err)
1480
+ });
1481
+ }
1482
+ let api = null;
1483
+ try {
1484
+ api = readApiConfig(projectRoot, appConfig);
1485
+ } catch (err) {
1486
+ log.debug("config", "API config not available", {
1487
+ error: err instanceof Error ? err.message : String(err)
1488
+ });
1489
+ }
1490
+ return {
1491
+ name: appConfig.name,
1492
+ auth: appConfig.auth ?? null,
1493
+ agent,
1494
+ api
1495
+ };
1496
+ }
1497
+
1257
1498
  // src/dev/execution/runner.ts
1258
1499
  var DevRunner = class {
1259
1500
  constructor(appId, projectRoot, startOpts = {}) {
@@ -1549,16 +1790,8 @@ var DevRunner = class {
1549
1790
  }
1550
1791
  }
1551
1792
  async handleRequest(request) {
1552
- if (request.type === "get-agent-config") {
1553
- await this.handleGetAgentConfig(request);
1554
- return;
1555
- }
1556
- if (request.type === "get-auth-config") {
1557
- await this.handleGetAuthConfig(request);
1558
- return;
1559
- }
1560
- if (request.type === "get-api-config") {
1561
- await this.handleGetApiConfig(request);
1793
+ if (request.type === "get-config") {
1794
+ await this.handleGetConfig(request);
1562
1795
  return;
1563
1796
  }
1564
1797
  const startTime = Date.now();
@@ -1699,122 +1932,40 @@ var DevRunner = class {
1699
1932
  });
1700
1933
  }
1701
1934
  }
1702
- async handleGetAgentConfig(request) {
1703
- const startTime = Date.now();
1704
- log.info("runner", "Agent config requested", { requestId: request.requestId, sessionId: this.session.sessionId });
1935
+ async handleGetConfig(request) {
1936
+ log.info("runner", "Config requested", { requestId: request.requestId, sessionId: this.session.sessionId });
1705
1937
  try {
1706
1938
  if (!this.appConfig) {
1707
1939
  throw new Error("App config not available");
1708
1940
  }
1709
- const bundle = readAgentConfig(this.projectRoot, this.appConfig);
1710
- await submitDevResult(
1711
- this.appId,
1712
- this.session.sessionId,
1713
- request.requestId,
1714
- {
1715
- type: "get-agent-config",
1716
- success: true,
1717
- output: bundle
1718
- }
1719
- );
1720
- log.info("runner", "Agent config sent", { requestId: request.requestId, duration: Date.now() - startTime });
1721
- } catch (err) {
1722
- const message = err instanceof Error ? err.message : "Unknown error";
1723
- log.error("runner", "Agent config failed", { requestId: request.requestId, error: message });
1724
- try {
1725
- await submitDevResult(
1726
- this.appId,
1727
- this.session.sessionId,
1728
- request.requestId,
1729
- {
1730
- type: "get-agent-config",
1731
- success: false,
1732
- error: { message }
1733
- }
1734
- );
1735
- } catch (submitErr) {
1736
- log.error("runner", "Failed to report agent config error to platform", { error: submitErr instanceof Error ? submitErr.message : String(submitErr) });
1737
- }
1738
- }
1739
- }
1740
- async handleGetAuthConfig(request) {
1741
- log.info("runner", "Auth config requested", { requestId: request.requestId, sessionId: this.session.sessionId });
1742
- try {
1743
- if (!this.appConfig) {
1744
- throw new Error("App config not available");
1745
- }
1746
- await submitDevResult(
1747
- this.appId,
1748
- this.session.sessionId,
1749
- request.requestId,
1750
- {
1751
- type: "get-auth-config",
1752
- success: true,
1753
- output: { auth: this.appConfig.auth ?? null, name: this.appConfig.name }
1754
- }
1755
- );
1756
- log.info("runner", "Auth config sent", { requestId: request.requestId });
1757
- } catch (err) {
1758
- const message = err instanceof Error ? err.message : "Unknown error";
1759
- log.error("runner", "Auth config failed", { requestId: request.requestId, error: message });
1760
- try {
1761
- await submitDevResult(
1762
- this.appId,
1763
- this.session.sessionId,
1764
- request.requestId,
1765
- {
1766
- type: "get-auth-config",
1767
- success: false,
1768
- error: { message }
1769
- }
1770
- );
1771
- } catch (submitErr) {
1772
- log.error("runner", "Failed to report auth config error to platform", { error: submitErr instanceof Error ? submitErr.message : String(submitErr) });
1773
- }
1774
- }
1775
- }
1776
- async handleGetApiConfig(request) {
1777
- log.info("runner", "API config requested", { requestId: request.requestId, sessionId: this.session.sessionId });
1778
- try {
1779
- const apiInterface = this.appConfig?.interfaces.find(
1780
- (i) => i.type === "api" && i.enabled !== false
1781
- );
1782
- if (!apiInterface) {
1783
- throw new Error("No API interface config found");
1784
- }
1785
- const apiJsonPath = join6(this.projectRoot, apiInterface.path);
1786
- const raw = readFileSync3(apiJsonPath, "utf-8");
1787
- const parsed = JSON.parse(raw);
1788
- if (!parsed.api) {
1789
- throw new Error("No API interface config found");
1790
- }
1941
+ const config2 = readConfig(this.projectRoot, this.appConfig);
1791
1942
  await submitDevResult(
1792
1943
  this.appId,
1793
1944
  this.session.sessionId,
1794
1945
  request.requestId,
1795
1946
  {
1796
- type: "get-api-config",
1947
+ type: "get-config",
1797
1948
  success: true,
1798
- output: parsed.api
1949
+ output: config2
1799
1950
  }
1800
1951
  );
1801
- log.info("runner", "API config sent", { requestId: request.requestId });
1952
+ log.info("runner", "Config sent", { requestId: request.requestId });
1802
1953
  } catch (err) {
1803
1954
  const message = err instanceof Error ? err.message : "Unknown error";
1804
- log.error("runner", "API config failed", { requestId: request.requestId, error: message });
1955
+ log.error("runner", "Config failed", { requestId: request.requestId, error: message });
1805
1956
  try {
1806
1957
  await submitDevResult(
1807
1958
  this.appId,
1808
1959
  this.session.sessionId,
1809
1960
  request.requestId,
1810
1961
  {
1811
- type: "get-api-config",
1962
+ type: "get-config",
1812
1963
  success: false,
1813
1964
  error: { message }
1814
1965
  }
1815
1966
  );
1816
1967
  } catch (submitErr) {
1817
- log.error("runner", "Failed to report API config error to platform", { error: submitErr instanceof Error ? submitErr.message : String(submitErr) });
1968
+ log.error("runner", "Failed to report config error to platform", { error: submitErr instanceof Error ? submitErr.message : String(submitErr) });
1818
1969
  }
1819
1970
  }
1820
1971
  }
@@ -1863,7 +2014,7 @@ var DevRunner = class {
1863
2014
  }
1864
2015
  }
1865
2016
  sleep(ms) {
1866
- return new Promise((resolve2) => setTimeout(resolve2, ms));
2017
+ return new Promise((resolve3) => setTimeout(resolve3, ms));
1867
2018
  }
1868
2019
  };
1869
2020
 
@@ -2057,12 +2208,12 @@ var DevProxy = class _DevProxy {
2057
2208
  );
2058
2209
  }
2059
2210
  const id = randomBytes4(4).toString("hex");
2060
- return new Promise((resolve2, reject) => {
2211
+ return new Promise((resolve3, reject) => {
2061
2212
  this.commandQueue.push({
2062
2213
  id,
2063
2214
  steps,
2064
2215
  timeoutMs,
2065
- resolve: resolve2,
2216
+ resolve: resolve3,
2066
2217
  reject,
2067
2218
  queuedAt: Date.now()
2068
2219
  });
@@ -2082,7 +2233,7 @@ var DevProxy = class _DevProxy {
2082
2233
  const target = this.clients.getCommandTarget();
2083
2234
  if (!target) break;
2084
2235
  const queued = this.commandQueue.shift();
2085
- const { id, steps, timeoutMs, resolve: resolve2, reject } = queued;
2236
+ const { id, steps, timeoutMs, resolve: resolve3, reject } = queued;
2086
2237
  log.info("proxy", "Browser command sent", {
2087
2238
  id,
2088
2239
  clientId: target.id,
@@ -2102,7 +2253,7 @@ var DevProxy = class _DevProxy {
2102
2253
  reject(new Error("Browser command timed out"));
2103
2254
  this.drainCommandQueue();
2104
2255
  }, timeoutMs);
2105
- this.pendingResults.set(id, { resolve: resolve2, timeout, clientId: target.id });
2256
+ this.pendingResults.set(id, { resolve: resolve3, timeout, clientId: target.id });
2106
2257
  target.activeCommandId = id;
2107
2258
  try {
2108
2259
  target.ws.send(JSON.stringify({ type: "command", id, steps }));
@@ -2170,7 +2321,7 @@ var DevProxy = class _DevProxy {
2170
2321
  throw new Error("Failed to start proxy server");
2171
2322
  }
2172
2323
  listenOnPort(server, port) {
2173
- return new Promise((resolve2, reject) => {
2324
+ return new Promise((resolve3, reject) => {
2174
2325
  const onError = (err) => {
2175
2326
  server.removeListener("error", onError);
2176
2327
  reject(err);
@@ -2183,7 +2334,7 @@ var DevProxy = class _DevProxy {
2183
2334
  reject(new Error("Failed to get proxy server address"));
2184
2335
  return;
2185
2336
  }
2186
- resolve2(addr.port);
2337
+ resolve3(addr.port);
2187
2338
  });
2188
2339
  });
2189
2340
  }
@@ -2836,7 +2987,7 @@ var DevProxy = class _DevProxy {
2836
2987
  if (releaseId) url.searchParams.set("releaseId", releaseId);
2837
2988
  const isHttps = url.protocol === "https:";
2838
2989
  const httpModule = isHttps ? https : http;
2839
- return new Promise((resolve2) => {
2990
+ return new Promise((resolve3) => {
2840
2991
  const req = httpModule.request(
2841
2992
  {
2842
2993
  hostname: url.hostname,
@@ -2855,24 +3006,24 @@ var DevProxy = class _DevProxy {
2855
3006
  try {
2856
3007
  const body = JSON.parse(Buffer.concat(chunks).toString("utf-8"));
2857
3008
  if (body.user && body.token) {
2858
- resolve2({
3009
+ resolve3({
2859
3010
  user: body.user,
2860
3011
  token: body.token,
2861
3012
  methods: body.methods ?? {}
2862
3013
  });
2863
3014
  } else {
2864
- resolve2(null);
3015
+ resolve3(null);
2865
3016
  }
2866
3017
  } catch {
2867
- resolve2(null);
3018
+ resolve3(null);
2868
3019
  }
2869
3020
  });
2870
3021
  }
2871
3022
  );
2872
- req.on("error", () => resolve2(null));
3023
+ req.on("error", () => resolve3(null));
2873
3024
  req.setTimeout(3e3, () => {
2874
3025
  req.destroy();
2875
- resolve2(null);
3026
+ resolve3(null);
2876
3027
  });
2877
3028
  req.end();
2878
3029
  });
@@ -2935,13 +3086,13 @@ ${agentScript}`;
2935
3086
  };
2936
3087
 
2937
3088
  // src/dev/config/app-config.ts
2938
- import { readFileSync as readFileSync4, existsSync as existsSync2 } from "fs";
2939
- import { join as join7, dirname as dirname3 } from "path";
3089
+ import { readFileSync as readFileSync6, existsSync as existsSync3 } from "fs";
3090
+ import { join as join8, dirname as dirname4 } from "path";
2940
3091
  function detectAppConfig(cwd = process.cwd()) {
2941
- const appJsonPath = join7(cwd, "mindstudio.json");
2942
- if (!existsSync2(appJsonPath)) return null;
3092
+ const appJsonPath = join8(cwd, "mindstudio.json");
3093
+ if (!existsSync3(appJsonPath)) return null;
2943
3094
  try {
2944
- const raw = readFileSync4(appJsonPath, "utf-8");
3095
+ const raw = readFileSync6(appJsonPath, "utf-8");
2945
3096
  const parsed = JSON.parse(raw);
2946
3097
  if (!parsed.name || !Array.isArray(parsed.methods)) {
2947
3098
  return null;
@@ -2978,12 +3129,12 @@ function getWebInterfaceConfig(appConfig, cwd = process.cwd()) {
2978
3129
  if (!webInterface) {
2979
3130
  return null;
2980
3131
  }
2981
- const configPath = join7(cwd, webInterface.path);
2982
- if (!existsSync2(configPath)) {
3132
+ const configPath = join8(cwd, webInterface.path);
3133
+ if (!existsSync3(configPath)) {
2983
3134
  return null;
2984
3135
  }
2985
3136
  try {
2986
- const raw = readFileSync4(configPath, "utf-8");
3137
+ const raw = readFileSync6(configPath, "utf-8");
2987
3138
  const parsed = JSON.parse(raw);
2988
3139
  const web = parsed.web;
2989
3140
  if (!web || typeof web !== "object") {
@@ -3004,18 +3155,18 @@ function getWebProjectDir(appConfig, cwd = process.cwd()) {
3004
3155
  if (!webInterface) {
3005
3156
  return null;
3006
3157
  }
3007
- return dirname3(join7(cwd, webInterface.path));
3158
+ return dirname4(join8(cwd, webInterface.path));
3008
3159
  }
3009
3160
  function readTableSources(appConfig, cwd = process.cwd()) {
3010
3161
  const results = [];
3011
3162
  for (const table of appConfig.tables) {
3012
- const filePath = join7(cwd, table.path);
3013
- if (!existsSync2(filePath)) {
3163
+ const filePath = join8(cwd, table.path);
3164
+ if (!existsSync3(filePath)) {
3014
3165
  log.warn("config", "Table source file not found", { table: table.export, path: table.path });
3015
3166
  continue;
3016
3167
  }
3017
3168
  try {
3018
- const source = readFileSync4(filePath, "utf-8");
3169
+ const source = readFileSync6(filePath, "utf-8");
3019
3170
  const name = table.export;
3020
3171
  results.push({ name, source });
3021
3172
  } catch (err) {
@@ -3033,9 +3184,9 @@ function findDirsNeedingInstall(appConfig, cwd = process.cwd()) {
3033
3184
  const firstMethodPath = appConfig.methods[0].path;
3034
3185
  const parts = firstMethodPath.split("/");
3035
3186
  for (let i = parts.length - 1; i >= 1; i--) {
3036
- const candidate = join7(cwd, ...parts.slice(0, i));
3037
- if (existsSync2(join7(candidate, "package.json"))) {
3038
- if (!existsSync2(join7(candidate, "node_modules"))) {
3187
+ const candidate = join8(cwd, ...parts.slice(0, i));
3188
+ if (existsSync3(join8(candidate, "package.json"))) {
3189
+ if (!existsSync3(join8(candidate, "node_modules"))) {
3039
3190
  dirs.push(candidate);
3040
3191
  }
3041
3192
  break;
@@ -3043,8 +3194,8 @@ function findDirsNeedingInstall(appConfig, cwd = process.cwd()) {
3043
3194
  }
3044
3195
  }
3045
3196
  const webProjectDir = getWebProjectDir(appConfig, cwd);
3046
- if (webProjectDir && existsSync2(join7(webProjectDir, "package.json"))) {
3047
- if (!existsSync2(join7(webProjectDir, "node_modules"))) {
3197
+ if (webProjectDir && existsSync3(join8(webProjectDir, "package.json"))) {
3198
+ if (!existsSync3(join8(webProjectDir, "node_modules"))) {
3048
3199
  dirs.push(webProjectDir);
3049
3200
  }
3050
3201
  }
@@ -3073,11 +3224,11 @@ function detectGitBranch() {
3073
3224
 
3074
3225
  // src/dev/config/table-watcher.ts
3075
3226
  import { watch } from "chokidar";
3076
- import { join as join8, dirname as dirname4, basename as basename2 } from "path";
3227
+ import { join as join9, dirname as dirname5, basename as basename2 } from "path";
3077
3228
  function watchTableFiles(tables, cwd, onChanged) {
3078
3229
  if (tables.length === 0) return () => {
3079
3230
  };
3080
- const filePaths = tables.map((t) => join8(cwd, t.path));
3231
+ const filePaths = tables.map((t) => join9(cwd, t.path));
3081
3232
  let syncTimer;
3082
3233
  const watcher = watch(filePaths, {
3083
3234
  ignoreInitial: true,
@@ -3090,8 +3241,8 @@ function watchTableFiles(tables, cwd, onChanged) {
3090
3241
  });
3091
3242
  const dirToFiles = /* @__PURE__ */ new Map();
3092
3243
  for (const table of tables) {
3093
- const absPath = join8(cwd, table.path);
3094
- const dir = dirname4(absPath);
3244
+ const absPath = join9(cwd, table.path);
3245
+ const dir = dirname5(absPath);
3095
3246
  const file = basename2(absPath);
3096
3247
  if (!dirToFiles.has(dir)) dirToFiles.set(dir, /* @__PURE__ */ new Set());
3097
3248
  dirToFiles.get(dir).add(file);
@@ -3108,9 +3259,9 @@ function watchTableFiles(tables, cwd, onChanged) {
3108
3259
 
3109
3260
  // src/dev/config/config-watcher.ts
3110
3261
  import { watch as watch2 } from "chokidar";
3111
- import { join as join9 } from "path";
3262
+ import { join as join10 } from "path";
3112
3263
  function watchConfigFile(cwd, onChanged) {
3113
- const configPath = join9(cwd, "mindstudio.json");
3264
+ const configPath = join10(cwd, "mindstudio.json");
3114
3265
  let debounceTimer;
3115
3266
  const watcher = watch2(configPath, {
3116
3267
  ignoreInitial: true,
@@ -3179,4 +3330,4 @@ export {
3179
3330
  watchTableFiles,
3180
3331
  watchConfigFile
3181
3332
  };
3182
- //# sourceMappingURL=chunk-ZKXKUFNA.js.map
3333
+ //# sourceMappingURL=chunk-UKMKZQKQ.js.map