@mindstudio-ai/local-model-tunnel 0.5.45 → 0.5.47
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/dist/{chunk-ZKXKUFNA.js → chunk-UT7QCCAJ.js} +317 -167
- package/dist/chunk-UT7QCCAJ.js.map +1 -0
- package/dist/{chunk-AWDTYW4T.js → chunk-WDCWN4FW.js} +2 -2
- package/dist/{chunk-FKTKVF7D.js → chunk-YWEWXNQ6.js} +5 -3
- package/dist/chunk-YWEWXNQ6.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/headless.js +2 -2
- package/dist/index.js +3 -3
- package/dist/{tui-DD2KVJU4.js → tui-AJTMDHAG.js} +6 -6
- package/package.json +3 -3
- package/dist/chunk-FKTKVF7D.js.map +0 -1
- package/dist/chunk-ZKXKUFNA.js.map +0 -1
- /package/dist/{chunk-AWDTYW4T.js.map → chunk-WDCWN4FW.js.map} +0 -0
- /package/dist/{tui-DD2KVJU4.js.map → tui-AJTMDHAG.js.map} +0 -0
|
@@ -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((
|
|
893
|
+
await new Promise((resolve3, reject) => {
|
|
894
894
|
const onMessage = (msg) => {
|
|
895
895
|
if (msg?.type === "ready") {
|
|
896
896
|
child.off("message", onMessage);
|
|
897
|
-
|
|
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((
|
|
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
|
-
|
|
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:
|
|
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/
|
|
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 {
|
|
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 =
|
|
1402
|
+
const configPath = join6(projectRoot, agentInterface.path);
|
|
1209
1403
|
let raw;
|
|
1210
1404
|
try {
|
|
1211
|
-
raw =
|
|
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 =
|
|
1220
|
-
const systemPromptPath =
|
|
1413
|
+
const agentDir = dirname3(configPath);
|
|
1414
|
+
const systemPromptPath = join6(agentDir, config2.systemPrompt);
|
|
1221
1415
|
let systemPrompt;
|
|
1222
1416
|
try {
|
|
1223
|
-
systemPrompt =
|
|
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 =
|
|
1425
|
+
const descPath = join6(agentDir, tool.description);
|
|
1232
1426
|
let description;
|
|
1233
1427
|
try {
|
|
1234
|
-
description =
|
|
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
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
|
|
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 = {}) {
|
|
@@ -1363,13 +1604,12 @@ var DevRunner = class {
|
|
|
1363
1604
|
try {
|
|
1364
1605
|
const authorizationToken = await fetchCallbackToken(this.appId, this.session.sessionId);
|
|
1365
1606
|
const transpiledPath = await this.transpiler.transpile(opts.methodPath);
|
|
1366
|
-
const
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
} : this.session.auth;
|
|
1607
|
+
const userId = opts.userId ?? this.session.auth.userId;
|
|
1608
|
+
const roles = opts.roles ?? this.roleOverride;
|
|
1609
|
+
const auth = roles ? {
|
|
1610
|
+
userId,
|
|
1611
|
+
roleAssignments: roles.map((roleName) => ({ userId, roleName }))
|
|
1612
|
+
} : { ...this.session.auth, userId };
|
|
1373
1613
|
const result = await executeMethod({
|
|
1374
1614
|
transpiledPath,
|
|
1375
1615
|
methodExport: opts.methodExport,
|
|
@@ -1549,16 +1789,8 @@ var DevRunner = class {
|
|
|
1549
1789
|
}
|
|
1550
1790
|
}
|
|
1551
1791
|
async handleRequest(request) {
|
|
1552
|
-
if (request.type === "get-
|
|
1553
|
-
await this.
|
|
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);
|
|
1792
|
+
if (request.type === "get-config") {
|
|
1793
|
+
await this.handleGetConfig(request);
|
|
1562
1794
|
return;
|
|
1563
1795
|
}
|
|
1564
1796
|
const startTime = Date.now();
|
|
@@ -1699,122 +1931,40 @@ var DevRunner = class {
|
|
|
1699
1931
|
});
|
|
1700
1932
|
}
|
|
1701
1933
|
}
|
|
1702
|
-
async
|
|
1703
|
-
|
|
1704
|
-
log.info("runner", "Agent config requested", { requestId: request.requestId, sessionId: this.session.sessionId });
|
|
1705
|
-
try {
|
|
1706
|
-
if (!this.appConfig) {
|
|
1707
|
-
throw new Error("App config not available");
|
|
1708
|
-
}
|
|
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 });
|
|
1934
|
+
async handleGetConfig(request) {
|
|
1935
|
+
log.info("runner", "Config requested", { requestId: request.requestId, sessionId: this.session.sessionId });
|
|
1742
1936
|
try {
|
|
1743
1937
|
if (!this.appConfig) {
|
|
1744
1938
|
throw new Error("App config not available");
|
|
1745
1939
|
}
|
|
1940
|
+
const config2 = readConfig(this.projectRoot, this.appConfig);
|
|
1746
1941
|
await submitDevResult(
|
|
1747
1942
|
this.appId,
|
|
1748
1943
|
this.session.sessionId,
|
|
1749
1944
|
request.requestId,
|
|
1750
1945
|
{
|
|
1751
|
-
type: "get-
|
|
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
|
-
}
|
|
1791
|
-
await submitDevResult(
|
|
1792
|
-
this.appId,
|
|
1793
|
-
this.session.sessionId,
|
|
1794
|
-
request.requestId,
|
|
1795
|
-
{
|
|
1796
|
-
type: "get-api-config",
|
|
1946
|
+
type: "get-config",
|
|
1797
1947
|
success: true,
|
|
1798
|
-
output:
|
|
1948
|
+
output: config2
|
|
1799
1949
|
}
|
|
1800
1950
|
);
|
|
1801
|
-
log.info("runner", "
|
|
1951
|
+
log.info("runner", "Config sent", { requestId: request.requestId });
|
|
1802
1952
|
} catch (err) {
|
|
1803
1953
|
const message = err instanceof Error ? err.message : "Unknown error";
|
|
1804
|
-
log.error("runner", "
|
|
1954
|
+
log.error("runner", "Config failed", { requestId: request.requestId, error: message });
|
|
1805
1955
|
try {
|
|
1806
1956
|
await submitDevResult(
|
|
1807
1957
|
this.appId,
|
|
1808
1958
|
this.session.sessionId,
|
|
1809
1959
|
request.requestId,
|
|
1810
1960
|
{
|
|
1811
|
-
type: "get-
|
|
1961
|
+
type: "get-config",
|
|
1812
1962
|
success: false,
|
|
1813
1963
|
error: { message }
|
|
1814
1964
|
}
|
|
1815
1965
|
);
|
|
1816
1966
|
} catch (submitErr) {
|
|
1817
|
-
log.error("runner", "Failed to report
|
|
1967
|
+
log.error("runner", "Failed to report config error to platform", { error: submitErr instanceof Error ? submitErr.message : String(submitErr) });
|
|
1818
1968
|
}
|
|
1819
1969
|
}
|
|
1820
1970
|
}
|
|
@@ -1863,7 +2013,7 @@ var DevRunner = class {
|
|
|
1863
2013
|
}
|
|
1864
2014
|
}
|
|
1865
2015
|
sleep(ms) {
|
|
1866
|
-
return new Promise((
|
|
2016
|
+
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
1867
2017
|
}
|
|
1868
2018
|
};
|
|
1869
2019
|
|
|
@@ -2057,12 +2207,12 @@ var DevProxy = class _DevProxy {
|
|
|
2057
2207
|
);
|
|
2058
2208
|
}
|
|
2059
2209
|
const id = randomBytes4(4).toString("hex");
|
|
2060
|
-
return new Promise((
|
|
2210
|
+
return new Promise((resolve3, reject) => {
|
|
2061
2211
|
this.commandQueue.push({
|
|
2062
2212
|
id,
|
|
2063
2213
|
steps,
|
|
2064
2214
|
timeoutMs,
|
|
2065
|
-
resolve:
|
|
2215
|
+
resolve: resolve3,
|
|
2066
2216
|
reject,
|
|
2067
2217
|
queuedAt: Date.now()
|
|
2068
2218
|
});
|
|
@@ -2082,7 +2232,7 @@ var DevProxy = class _DevProxy {
|
|
|
2082
2232
|
const target = this.clients.getCommandTarget();
|
|
2083
2233
|
if (!target) break;
|
|
2084
2234
|
const queued = this.commandQueue.shift();
|
|
2085
|
-
const { id, steps, timeoutMs, resolve:
|
|
2235
|
+
const { id, steps, timeoutMs, resolve: resolve3, reject } = queued;
|
|
2086
2236
|
log.info("proxy", "Browser command sent", {
|
|
2087
2237
|
id,
|
|
2088
2238
|
clientId: target.id,
|
|
@@ -2102,7 +2252,7 @@ var DevProxy = class _DevProxy {
|
|
|
2102
2252
|
reject(new Error("Browser command timed out"));
|
|
2103
2253
|
this.drainCommandQueue();
|
|
2104
2254
|
}, timeoutMs);
|
|
2105
|
-
this.pendingResults.set(id, { resolve:
|
|
2255
|
+
this.pendingResults.set(id, { resolve: resolve3, timeout, clientId: target.id });
|
|
2106
2256
|
target.activeCommandId = id;
|
|
2107
2257
|
try {
|
|
2108
2258
|
target.ws.send(JSON.stringify({ type: "command", id, steps }));
|
|
@@ -2170,7 +2320,7 @@ var DevProxy = class _DevProxy {
|
|
|
2170
2320
|
throw new Error("Failed to start proxy server");
|
|
2171
2321
|
}
|
|
2172
2322
|
listenOnPort(server, port) {
|
|
2173
|
-
return new Promise((
|
|
2323
|
+
return new Promise((resolve3, reject) => {
|
|
2174
2324
|
const onError = (err) => {
|
|
2175
2325
|
server.removeListener("error", onError);
|
|
2176
2326
|
reject(err);
|
|
@@ -2183,7 +2333,7 @@ var DevProxy = class _DevProxy {
|
|
|
2183
2333
|
reject(new Error("Failed to get proxy server address"));
|
|
2184
2334
|
return;
|
|
2185
2335
|
}
|
|
2186
|
-
|
|
2336
|
+
resolve3(addr.port);
|
|
2187
2337
|
});
|
|
2188
2338
|
});
|
|
2189
2339
|
}
|
|
@@ -2836,7 +2986,7 @@ var DevProxy = class _DevProxy {
|
|
|
2836
2986
|
if (releaseId) url.searchParams.set("releaseId", releaseId);
|
|
2837
2987
|
const isHttps = url.protocol === "https:";
|
|
2838
2988
|
const httpModule = isHttps ? https : http;
|
|
2839
|
-
return new Promise((
|
|
2989
|
+
return new Promise((resolve3) => {
|
|
2840
2990
|
const req = httpModule.request(
|
|
2841
2991
|
{
|
|
2842
2992
|
hostname: url.hostname,
|
|
@@ -2855,24 +3005,24 @@ var DevProxy = class _DevProxy {
|
|
|
2855
3005
|
try {
|
|
2856
3006
|
const body = JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
2857
3007
|
if (body.user && body.token) {
|
|
2858
|
-
|
|
3008
|
+
resolve3({
|
|
2859
3009
|
user: body.user,
|
|
2860
3010
|
token: body.token,
|
|
2861
3011
|
methods: body.methods ?? {}
|
|
2862
3012
|
});
|
|
2863
3013
|
} else {
|
|
2864
|
-
|
|
3014
|
+
resolve3(null);
|
|
2865
3015
|
}
|
|
2866
3016
|
} catch {
|
|
2867
|
-
|
|
3017
|
+
resolve3(null);
|
|
2868
3018
|
}
|
|
2869
3019
|
});
|
|
2870
3020
|
}
|
|
2871
3021
|
);
|
|
2872
|
-
req.on("error", () =>
|
|
3022
|
+
req.on("error", () => resolve3(null));
|
|
2873
3023
|
req.setTimeout(3e3, () => {
|
|
2874
3024
|
req.destroy();
|
|
2875
|
-
|
|
3025
|
+
resolve3(null);
|
|
2876
3026
|
});
|
|
2877
3027
|
req.end();
|
|
2878
3028
|
});
|
|
@@ -2935,13 +3085,13 @@ ${agentScript}`;
|
|
|
2935
3085
|
};
|
|
2936
3086
|
|
|
2937
3087
|
// src/dev/config/app-config.ts
|
|
2938
|
-
import { readFileSync as
|
|
2939
|
-
import { join as
|
|
3088
|
+
import { readFileSync as readFileSync6, existsSync as existsSync3 } from "fs";
|
|
3089
|
+
import { join as join8, dirname as dirname4 } from "path";
|
|
2940
3090
|
function detectAppConfig(cwd = process.cwd()) {
|
|
2941
|
-
const appJsonPath =
|
|
2942
|
-
if (!
|
|
3091
|
+
const appJsonPath = join8(cwd, "mindstudio.json");
|
|
3092
|
+
if (!existsSync3(appJsonPath)) return null;
|
|
2943
3093
|
try {
|
|
2944
|
-
const raw =
|
|
3094
|
+
const raw = readFileSync6(appJsonPath, "utf-8");
|
|
2945
3095
|
const parsed = JSON.parse(raw);
|
|
2946
3096
|
if (!parsed.name || !Array.isArray(parsed.methods)) {
|
|
2947
3097
|
return null;
|
|
@@ -2978,12 +3128,12 @@ function getWebInterfaceConfig(appConfig, cwd = process.cwd()) {
|
|
|
2978
3128
|
if (!webInterface) {
|
|
2979
3129
|
return null;
|
|
2980
3130
|
}
|
|
2981
|
-
const configPath =
|
|
2982
|
-
if (!
|
|
3131
|
+
const configPath = join8(cwd, webInterface.path);
|
|
3132
|
+
if (!existsSync3(configPath)) {
|
|
2983
3133
|
return null;
|
|
2984
3134
|
}
|
|
2985
3135
|
try {
|
|
2986
|
-
const raw =
|
|
3136
|
+
const raw = readFileSync6(configPath, "utf-8");
|
|
2987
3137
|
const parsed = JSON.parse(raw);
|
|
2988
3138
|
const web = parsed.web;
|
|
2989
3139
|
if (!web || typeof web !== "object") {
|
|
@@ -3004,18 +3154,18 @@ function getWebProjectDir(appConfig, cwd = process.cwd()) {
|
|
|
3004
3154
|
if (!webInterface) {
|
|
3005
3155
|
return null;
|
|
3006
3156
|
}
|
|
3007
|
-
return
|
|
3157
|
+
return dirname4(join8(cwd, webInterface.path));
|
|
3008
3158
|
}
|
|
3009
3159
|
function readTableSources(appConfig, cwd = process.cwd()) {
|
|
3010
3160
|
const results = [];
|
|
3011
3161
|
for (const table of appConfig.tables) {
|
|
3012
|
-
const filePath =
|
|
3013
|
-
if (!
|
|
3162
|
+
const filePath = join8(cwd, table.path);
|
|
3163
|
+
if (!existsSync3(filePath)) {
|
|
3014
3164
|
log.warn("config", "Table source file not found", { table: table.export, path: table.path });
|
|
3015
3165
|
continue;
|
|
3016
3166
|
}
|
|
3017
3167
|
try {
|
|
3018
|
-
const source =
|
|
3168
|
+
const source = readFileSync6(filePath, "utf-8");
|
|
3019
3169
|
const name = table.export;
|
|
3020
3170
|
results.push({ name, source });
|
|
3021
3171
|
} catch (err) {
|
|
@@ -3033,9 +3183,9 @@ function findDirsNeedingInstall(appConfig, cwd = process.cwd()) {
|
|
|
3033
3183
|
const firstMethodPath = appConfig.methods[0].path;
|
|
3034
3184
|
const parts = firstMethodPath.split("/");
|
|
3035
3185
|
for (let i = parts.length - 1; i >= 1; i--) {
|
|
3036
|
-
const candidate =
|
|
3037
|
-
if (
|
|
3038
|
-
if (!
|
|
3186
|
+
const candidate = join8(cwd, ...parts.slice(0, i));
|
|
3187
|
+
if (existsSync3(join8(candidate, "package.json"))) {
|
|
3188
|
+
if (!existsSync3(join8(candidate, "node_modules"))) {
|
|
3039
3189
|
dirs.push(candidate);
|
|
3040
3190
|
}
|
|
3041
3191
|
break;
|
|
@@ -3043,8 +3193,8 @@ function findDirsNeedingInstall(appConfig, cwd = process.cwd()) {
|
|
|
3043
3193
|
}
|
|
3044
3194
|
}
|
|
3045
3195
|
const webProjectDir = getWebProjectDir(appConfig, cwd);
|
|
3046
|
-
if (webProjectDir &&
|
|
3047
|
-
if (!
|
|
3196
|
+
if (webProjectDir && existsSync3(join8(webProjectDir, "package.json"))) {
|
|
3197
|
+
if (!existsSync3(join8(webProjectDir, "node_modules"))) {
|
|
3048
3198
|
dirs.push(webProjectDir);
|
|
3049
3199
|
}
|
|
3050
3200
|
}
|
|
@@ -3073,11 +3223,11 @@ function detectGitBranch() {
|
|
|
3073
3223
|
|
|
3074
3224
|
// src/dev/config/table-watcher.ts
|
|
3075
3225
|
import { watch } from "chokidar";
|
|
3076
|
-
import { join as
|
|
3226
|
+
import { join as join9, dirname as dirname5, basename as basename2 } from "path";
|
|
3077
3227
|
function watchTableFiles(tables, cwd, onChanged) {
|
|
3078
3228
|
if (tables.length === 0) return () => {
|
|
3079
3229
|
};
|
|
3080
|
-
const filePaths = tables.map((t) =>
|
|
3230
|
+
const filePaths = tables.map((t) => join9(cwd, t.path));
|
|
3081
3231
|
let syncTimer;
|
|
3082
3232
|
const watcher = watch(filePaths, {
|
|
3083
3233
|
ignoreInitial: true,
|
|
@@ -3090,8 +3240,8 @@ function watchTableFiles(tables, cwd, onChanged) {
|
|
|
3090
3240
|
});
|
|
3091
3241
|
const dirToFiles = /* @__PURE__ */ new Map();
|
|
3092
3242
|
for (const table of tables) {
|
|
3093
|
-
const absPath =
|
|
3094
|
-
const dir =
|
|
3243
|
+
const absPath = join9(cwd, table.path);
|
|
3244
|
+
const dir = dirname5(absPath);
|
|
3095
3245
|
const file = basename2(absPath);
|
|
3096
3246
|
if (!dirToFiles.has(dir)) dirToFiles.set(dir, /* @__PURE__ */ new Set());
|
|
3097
3247
|
dirToFiles.get(dir).add(file);
|
|
@@ -3108,9 +3258,9 @@ function watchTableFiles(tables, cwd, onChanged) {
|
|
|
3108
3258
|
|
|
3109
3259
|
// src/dev/config/config-watcher.ts
|
|
3110
3260
|
import { watch as watch2 } from "chokidar";
|
|
3111
|
-
import { join as
|
|
3261
|
+
import { join as join10 } from "path";
|
|
3112
3262
|
function watchConfigFile(cwd, onChanged) {
|
|
3113
|
-
const configPath =
|
|
3263
|
+
const configPath = join10(cwd, "mindstudio.json");
|
|
3114
3264
|
let debounceTimer;
|
|
3115
3265
|
const watcher = watch2(configPath, {
|
|
3116
3266
|
ignoreInitial: true,
|
|
@@ -3179,4 +3329,4 @@ export {
|
|
|
3179
3329
|
watchTableFiles,
|
|
3180
3330
|
watchConfigFile
|
|
3181
3331
|
};
|
|
3182
|
-
//# sourceMappingURL=chunk-
|
|
3332
|
+
//# sourceMappingURL=chunk-UT7QCCAJ.js.map
|