@mindstudio-ai/local-model-tunnel 0.5.41 → 0.5.43
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-DKTUVHTX.js → chunk-KM4JKO3T.js} +2 -2
- package/dist/{chunk-3GMBQERL.js → chunk-TBW6BCIS.js} +49 -6
- package/dist/{chunk-3GMBQERL.js.map → chunk-TBW6BCIS.js.map} +1 -1
- package/dist/{chunk-VO5KLV5S.js → chunk-UCESXK4F.js} +299 -35
- package/dist/chunk-UCESXK4F.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-K5LIL42S.js → tui-4JFTV6MT.js} +6 -6
- package/package.json +1 -1
- package/dist/chunk-VO5KLV5S.js.map +0 -1
- /package/dist/{chunk-DKTUVHTX.js.map → chunk-KM4JKO3T.js.map} +0 -0
- /package/dist/{tui-K5LIL42S.js.map → tui-4JFTV6MT.js.map} +0 -0
|
@@ -421,6 +421,45 @@ function logScenarioExecution(entry) {
|
|
|
421
421
|
stats: entry.result?.stats ?? null
|
|
422
422
|
});
|
|
423
423
|
}
|
|
424
|
+
function logMethodStart(requestId, sessionId, method, input) {
|
|
425
|
+
ndjsonLog.append({
|
|
426
|
+
ts: Date.now(),
|
|
427
|
+
level: "info",
|
|
428
|
+
module: "execution",
|
|
429
|
+
msg: "Method started",
|
|
430
|
+
type: "method-start",
|
|
431
|
+
requestId,
|
|
432
|
+
sessionId,
|
|
433
|
+
method,
|
|
434
|
+
input
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
function logMethodStdout(requestId, sessionId, method, lines) {
|
|
438
|
+
ndjsonLog.append({
|
|
439
|
+
ts: Date.now(),
|
|
440
|
+
level: "info",
|
|
441
|
+
module: "execution",
|
|
442
|
+
msg: "Method stdout",
|
|
443
|
+
type: "method-stdout",
|
|
444
|
+
requestId,
|
|
445
|
+
sessionId,
|
|
446
|
+
method,
|
|
447
|
+
stdout: lines
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
function logBackgroundStdout(requestId, sessionId, method, lines) {
|
|
451
|
+
ndjsonLog.append({
|
|
452
|
+
ts: Date.now(),
|
|
453
|
+
level: "info",
|
|
454
|
+
module: "execution",
|
|
455
|
+
msg: "Background stdout",
|
|
456
|
+
type: "method-background-stdout",
|
|
457
|
+
requestId,
|
|
458
|
+
sessionId,
|
|
459
|
+
method,
|
|
460
|
+
stdout: lines
|
|
461
|
+
});
|
|
462
|
+
}
|
|
424
463
|
function closeRequestLog() {
|
|
425
464
|
ndjsonLog.close();
|
|
426
465
|
}
|
|
@@ -582,6 +621,7 @@ function findNearestNodeModules(startDir) {
|
|
|
582
621
|
// src/dev/execution/executor.ts
|
|
583
622
|
import { fork } from "child_process";
|
|
584
623
|
import { writeFile, unlink as unlink2 } from "fs/promises";
|
|
624
|
+
import { readFileSync } from "fs";
|
|
585
625
|
import { join as join4 } from "path";
|
|
586
626
|
import { tmpdir } from "os";
|
|
587
627
|
import { randomBytes } from "crypto";
|
|
@@ -589,9 +629,10 @@ var EXECUTION_TIMEOUT_MS = 30 * 60 * 1e3;
|
|
|
589
629
|
var worker = null;
|
|
590
630
|
var workerScriptPath = null;
|
|
591
631
|
var workerProjectRoot = null;
|
|
632
|
+
var workerSupportsAls = false;
|
|
592
633
|
var pending = /* @__PURE__ */ new Map();
|
|
593
|
-
|
|
594
|
-
|
|
634
|
+
var requestMeta = /* @__PURE__ */ new Map();
|
|
635
|
+
var SERIALIZE_ERROR_FN = `
|
|
595
636
|
function serializeError(err) {
|
|
596
637
|
if (!err) return { message: 'Unknown error' };
|
|
597
638
|
|
|
@@ -626,14 +667,136 @@ function serializeError(err) {
|
|
|
626
667
|
|
|
627
668
|
return serialized;
|
|
628
669
|
}
|
|
670
|
+
`;
|
|
671
|
+
function buildAlsWorkerScript() {
|
|
672
|
+
return `
|
|
673
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
674
|
+
import { format } from 'node:util';
|
|
675
|
+
import { runWithContext } from '@mindstudio-ai/agent';
|
|
676
|
+
|
|
677
|
+
${SERIALIZE_ERROR_FN}
|
|
678
|
+
|
|
679
|
+
// Per-request console capture via AsyncLocalStorage
|
|
680
|
+
const consoleAls = new AsyncLocalStorage();
|
|
681
|
+
const _origLog = console.log;
|
|
682
|
+
const _origWarn = console.warn;
|
|
683
|
+
const _origError = console.error;
|
|
684
|
+
|
|
685
|
+
console.log = (...args) => {
|
|
686
|
+
const stdout = consoleAls.getStore();
|
|
687
|
+
if (stdout) stdout.push(format(...args));
|
|
688
|
+
_origLog(...args);
|
|
689
|
+
};
|
|
690
|
+
console.warn = (...args) => {
|
|
691
|
+
const stdout = consoleAls.getStore();
|
|
692
|
+
if (stdout) stdout.push(format(...args));
|
|
693
|
+
_origWarn(...args);
|
|
694
|
+
};
|
|
695
|
+
console.error = (...args) => {
|
|
696
|
+
const stdout = consoleAls.getStore();
|
|
697
|
+
if (stdout) stdout.push(format(...args));
|
|
698
|
+
_origError(...args);
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
// Track secret keys so we can clean up between requests
|
|
702
|
+
let _activeSecretKeys = [];
|
|
703
|
+
|
|
704
|
+
process.on('message', async (msg) => {
|
|
705
|
+
const { id, transpiledPath, methodExport, input, auth, databases, authorizationToken, apiBaseUrl, streamId, secrets } = msg;
|
|
706
|
+
|
|
707
|
+
// Apply per-request secrets to process.env (clean up previous first)
|
|
708
|
+
for (const key of _activeSecretKeys) delete process.env[key];
|
|
709
|
+
_activeSecretKeys = secrets ? Object.keys(secrets) : [];
|
|
710
|
+
if (secrets) Object.assign(process.env, secrets);
|
|
711
|
+
|
|
712
|
+
const ctx = {
|
|
713
|
+
callbackToken: authorizationToken,
|
|
714
|
+
remoteHostname: apiBaseUrl,
|
|
715
|
+
auth: auth ?? { userId: null, roleAssignments: [] },
|
|
716
|
+
databases: databases ?? [],
|
|
717
|
+
streamId: streamId ?? undefined,
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
const stdout = [];
|
|
721
|
+
let flushed = 0;
|
|
722
|
+
let done = false;
|
|
723
|
+
|
|
724
|
+
// Flush new stdout lines every 1s while the method is running.
|
|
725
|
+
// After the method returns, switches to background-stdout type.
|
|
726
|
+
const flushInterval = setInterval(() => {
|
|
727
|
+
if (stdout.length > flushed) {
|
|
728
|
+
const lines = stdout.slice(flushed);
|
|
729
|
+
flushed = stdout.length;
|
|
730
|
+
try {
|
|
731
|
+
process.send({ type: done ? 'background-stdout' : 'stdout', id, lines });
|
|
732
|
+
} catch {}
|
|
733
|
+
idleTicks = 0;
|
|
734
|
+
} else if (done) {
|
|
735
|
+
idleTicks++;
|
|
736
|
+
if (idleTicks >= 2) {
|
|
737
|
+
clearInterval(flushInterval);
|
|
738
|
+
try { process.send({ type: 'stdout-end', id }); } catch {}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}, 1000);
|
|
742
|
+
let idleTicks = 0;
|
|
743
|
+
|
|
744
|
+
process.send({ type: 'start', id });
|
|
745
|
+
|
|
746
|
+
const startTime = Date.now();
|
|
747
|
+
|
|
748
|
+
try {
|
|
749
|
+
const returnValue = await consoleAls.run(stdout, () =>
|
|
750
|
+
runWithContext(ctx, async () => {
|
|
751
|
+
const mod = await import(transpiledPath + '?t=' + Date.now());
|
|
752
|
+
const fn = mod[methodExport];
|
|
753
|
+
if (typeof fn !== 'function') {
|
|
754
|
+
throw new Error(methodExport + ' is not a function (got ' + typeof fn + ')');
|
|
755
|
+
}
|
|
756
|
+
return fn(input);
|
|
757
|
+
}),
|
|
758
|
+
);
|
|
759
|
+
const stats = { memoryUsedBytes: process.memoryUsage().heapUsed, executionTimeMs: Date.now() - startTime };
|
|
760
|
+
|
|
761
|
+
// Final flush of any remaining lines before sending result
|
|
762
|
+
if (stdout.length > flushed) {
|
|
763
|
+
try { process.send({ type: 'stdout', id, lines: stdout.slice(flushed) }); } catch {}
|
|
764
|
+
flushed = stdout.length;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
done = true;
|
|
768
|
+
process.send({ id, success: true, output: returnValue, stats });
|
|
769
|
+
} catch (err) {
|
|
770
|
+
const stats = { memoryUsedBytes: process.memoryUsage().heapUsed, executionTimeMs: Date.now() - startTime };
|
|
771
|
+
|
|
772
|
+
if (stdout.length > flushed) {
|
|
773
|
+
try { process.send({ type: 'stdout', id, lines: stdout.slice(flushed) }); } catch {}
|
|
774
|
+
flushed = stdout.length;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
done = true;
|
|
778
|
+
process.send({ id, success: false, error: serializeError(err), stats });
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
// Signal ready
|
|
783
|
+
process.send({ type: 'ready' });
|
|
784
|
+
`;
|
|
785
|
+
}
|
|
786
|
+
function buildLegacyWorkerScript() {
|
|
787
|
+
return `
|
|
788
|
+
${SERIALIZE_ERROR_FN}
|
|
629
789
|
|
|
630
790
|
// Save original console methods so we can restore after each request
|
|
631
791
|
const _origLog = console.log;
|
|
632
792
|
const _origWarn = console.warn;
|
|
633
793
|
const _origError = console.error;
|
|
634
794
|
|
|
795
|
+
// Track secret keys so we can clean up between requests
|
|
796
|
+
let _activeSecretKeys = [];
|
|
797
|
+
|
|
635
798
|
process.on('message', async (msg) => {
|
|
636
|
-
const { id, transpiledPath, methodExport, input, auth, databases, authorizationToken, apiBaseUrl, streamId } = msg;
|
|
799
|
+
const { id, transpiledPath, methodExport, input, auth, databases, authorizationToken, apiBaseUrl, streamId, secrets } = msg;
|
|
637
800
|
|
|
638
801
|
// Update per-request env vars
|
|
639
802
|
process.env.CALLBACK_TOKEN = authorizationToken;
|
|
@@ -641,6 +804,11 @@ process.on('message', async (msg) => {
|
|
|
641
804
|
if (streamId) process.env.STREAM_ID = streamId;
|
|
642
805
|
else delete process.env.STREAM_ID;
|
|
643
806
|
|
|
807
|
+
// Apply per-request secrets to process.env (clean up previous first)
|
|
808
|
+
for (const key of _activeSecretKeys) delete process.env[key];
|
|
809
|
+
_activeSecretKeys = secrets ? Object.keys(secrets) : [];
|
|
810
|
+
if (secrets) Object.assign(process.env, secrets);
|
|
811
|
+
|
|
644
812
|
// Update global context
|
|
645
813
|
global.ai = { auth, databases };
|
|
646
814
|
|
|
@@ -677,6 +845,17 @@ process.on('message', async (msg) => {
|
|
|
677
845
|
process.send({ type: 'ready' });
|
|
678
846
|
`;
|
|
679
847
|
}
|
|
848
|
+
function detectAlsSupport(projectRoot) {
|
|
849
|
+
try {
|
|
850
|
+
const pkgPath = join4(projectRoot, "node_modules", "@mindstudio-ai", "agent", "package.json");
|
|
851
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
852
|
+
const parts = (pkg.version || "").split(".").map(Number);
|
|
853
|
+
const [major = 0, minor = 0, patch = 0] = parts;
|
|
854
|
+
return major > 0 || minor > 1 || minor === 1 && patch >= 46;
|
|
855
|
+
} catch {
|
|
856
|
+
return false;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
680
859
|
async function ensureWorker(projectRoot) {
|
|
681
860
|
if (worker?.connected && workerProjectRoot === projectRoot) {
|
|
682
861
|
return worker;
|
|
@@ -695,14 +874,17 @@ async function ensureWorker(projectRoot) {
|
|
|
695
874
|
});
|
|
696
875
|
workerScriptPath = null;
|
|
697
876
|
}
|
|
877
|
+
workerSupportsAls = detectAlsSupport(projectRoot);
|
|
878
|
+
log.info("executor", "SDK context support", { als: workerSupportsAls });
|
|
698
879
|
const scriptPath = join4(
|
|
699
880
|
tmpdir(),
|
|
700
881
|
`ms-dev-worker-${randomBytes(4).toString("hex")}.mjs`
|
|
701
882
|
);
|
|
702
|
-
|
|
883
|
+
const script = workerSupportsAls ? buildAlsWorkerScript() : buildLegacyWorkerScript();
|
|
884
|
+
await writeFile(scriptPath, script, "utf-8");
|
|
703
885
|
workerScriptPath = scriptPath;
|
|
704
886
|
workerProjectRoot = projectRoot;
|
|
705
|
-
log.debug("executor", "Spawning method execution process", { cwd: projectRoot, scriptPath });
|
|
887
|
+
log.debug("executor", "Spawning method execution process", { cwd: projectRoot, scriptPath, als: workerSupportsAls });
|
|
706
888
|
const child = fork(scriptPath, [], {
|
|
707
889
|
cwd: projectRoot,
|
|
708
890
|
stdio: ["ignore", "pipe", "pipe", "ipc"],
|
|
@@ -721,6 +903,21 @@ async function ensureWorker(projectRoot) {
|
|
|
721
903
|
});
|
|
722
904
|
child.on("message", (msg) => {
|
|
723
905
|
if (!msg?.id) return;
|
|
906
|
+
const meta = requestMeta.get(msg.id);
|
|
907
|
+
switch (msg.type) {
|
|
908
|
+
case "start":
|
|
909
|
+
if (meta) logMethodStart(msg.id, meta.sessionId, meta.method, meta.input);
|
|
910
|
+
return;
|
|
911
|
+
case "stdout":
|
|
912
|
+
if (meta && msg.lines?.length) logMethodStdout(msg.id, meta.sessionId, meta.method, msg.lines);
|
|
913
|
+
return;
|
|
914
|
+
case "background-stdout":
|
|
915
|
+
if (meta && msg.lines?.length) logBackgroundStdout(msg.id, meta.sessionId, meta.method, msg.lines);
|
|
916
|
+
return;
|
|
917
|
+
case "stdout-end":
|
|
918
|
+
requestMeta.delete(msg.id);
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
724
921
|
const req = pending.get(msg.id);
|
|
725
922
|
if (!req) return;
|
|
726
923
|
pending.delete(msg.id);
|
|
@@ -752,6 +949,9 @@ function enqueue(fn) {
|
|
|
752
949
|
return task;
|
|
753
950
|
}
|
|
754
951
|
function executeMethod(opts) {
|
|
952
|
+
if (workerSupportsAls) {
|
|
953
|
+
return executeMethodInWorker(opts);
|
|
954
|
+
}
|
|
755
955
|
return enqueue(() => executeMethodInWorker(opts));
|
|
756
956
|
}
|
|
757
957
|
async function executeMethodInWorker(opts) {
|
|
@@ -768,6 +968,9 @@ async function executeMethodInWorker(opts) {
|
|
|
768
968
|
});
|
|
769
969
|
}, EXECUTION_TIMEOUT_MS);
|
|
770
970
|
pending.set(id, { resolve: resolve2, timer });
|
|
971
|
+
if (opts.sessionId) {
|
|
972
|
+
requestMeta.set(id, { sessionId: opts.sessionId, method: opts.methodExport, input: opts.input });
|
|
973
|
+
}
|
|
771
974
|
w.send({
|
|
772
975
|
id,
|
|
773
976
|
transpiledPath: opts.transpiledPath,
|
|
@@ -777,7 +980,8 @@ async function executeMethodInWorker(opts) {
|
|
|
777
980
|
databases: opts.databases,
|
|
778
981
|
authorizationToken: opts.authorizationToken,
|
|
779
982
|
apiBaseUrl: opts.apiBaseUrl,
|
|
780
|
-
streamId: opts.streamId
|
|
983
|
+
streamId: opts.streamId,
|
|
984
|
+
secrets: opts.secrets
|
|
781
985
|
});
|
|
782
986
|
});
|
|
783
987
|
}
|
|
@@ -793,10 +997,12 @@ async function cleanupWorker() {
|
|
|
793
997
|
workerScriptPath = null;
|
|
794
998
|
}
|
|
795
999
|
workerProjectRoot = null;
|
|
1000
|
+
workerSupportsAls = false;
|
|
796
1001
|
for (const [, req] of pending) {
|
|
797
1002
|
clearTimeout(req.timer);
|
|
798
1003
|
}
|
|
799
1004
|
pending.clear();
|
|
1005
|
+
requestMeta.clear();
|
|
800
1006
|
queueTail = Promise.resolve();
|
|
801
1007
|
}
|
|
802
1008
|
|
|
@@ -961,6 +1167,8 @@ async function disconnectHeartbeat() {
|
|
|
961
1167
|
}
|
|
962
1168
|
|
|
963
1169
|
// src/dev/execution/runner.ts
|
|
1170
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
1171
|
+
import { join as join6 } from "path";
|
|
964
1172
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
965
1173
|
|
|
966
1174
|
// src/dev/execution/format-error.ts
|
|
@@ -988,7 +1196,7 @@ function formatErrorForDisplay(error) {
|
|
|
988
1196
|
}
|
|
989
1197
|
|
|
990
1198
|
// src/dev/execution/agent-config.ts
|
|
991
|
-
import { readFileSync } from "fs";
|
|
1199
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
992
1200
|
import { join as join5, dirname as dirname2 } from "path";
|
|
993
1201
|
function readAgentConfig(projectRoot, appConfig) {
|
|
994
1202
|
const agentInterface = appConfig.interfaces.find(
|
|
@@ -1000,7 +1208,7 @@ function readAgentConfig(projectRoot, appConfig) {
|
|
|
1000
1208
|
const configPath = join5(projectRoot, agentInterface.path);
|
|
1001
1209
|
let raw;
|
|
1002
1210
|
try {
|
|
1003
|
-
raw =
|
|
1211
|
+
raw = readFileSync2(configPath, "utf-8");
|
|
1004
1212
|
} catch {
|
|
1005
1213
|
throw new Error(
|
|
1006
1214
|
`Agent config not found at ${agentInterface.path} \u2014 run your build command`
|
|
@@ -1012,7 +1220,7 @@ function readAgentConfig(projectRoot, appConfig) {
|
|
|
1012
1220
|
const systemPromptPath = join5(agentDir, config2.systemPrompt);
|
|
1013
1221
|
let systemPrompt;
|
|
1014
1222
|
try {
|
|
1015
|
-
systemPrompt =
|
|
1223
|
+
systemPrompt = readFileSync2(systemPromptPath, "utf-8");
|
|
1016
1224
|
} catch {
|
|
1017
1225
|
throw new Error(
|
|
1018
1226
|
`Agent system prompt not found at ${config2.systemPrompt} \u2014 run your build command`
|
|
@@ -1023,7 +1231,7 @@ function readAgentConfig(projectRoot, appConfig) {
|
|
|
1023
1231
|
const descPath = join5(agentDir, tool.description);
|
|
1024
1232
|
let description;
|
|
1025
1233
|
try {
|
|
1026
|
-
description =
|
|
1234
|
+
description = readFileSync2(descPath, "utf-8");
|
|
1027
1235
|
} catch {
|
|
1028
1236
|
throw new Error(
|
|
1029
1237
|
`Agent tool description not found at ${tool.description} for method "${tool.method}" \u2014 run your build command`
|
|
@@ -1168,7 +1376,8 @@ var DevRunner = class {
|
|
|
1168
1376
|
databases: this.session.databases,
|
|
1169
1377
|
authorizationToken,
|
|
1170
1378
|
apiBaseUrl: getApiBaseUrl(),
|
|
1171
|
-
projectRoot: this.projectRoot
|
|
1379
|
+
projectRoot: this.projectRoot,
|
|
1380
|
+
sessionId: this.session.sessionId
|
|
1172
1381
|
});
|
|
1173
1382
|
const duration = Date.now() - startTime;
|
|
1174
1383
|
if (result.success) {
|
|
@@ -1246,7 +1455,8 @@ var DevRunner = class {
|
|
|
1246
1455
|
databases: this.session.databases,
|
|
1247
1456
|
authorizationToken,
|
|
1248
1457
|
apiBaseUrl: getApiBaseUrl(),
|
|
1249
|
-
projectRoot: this.projectRoot
|
|
1458
|
+
projectRoot: this.projectRoot,
|
|
1459
|
+
sessionId: this.session.sessionId
|
|
1250
1460
|
});
|
|
1251
1461
|
if (!result.success) {
|
|
1252
1462
|
const error = result.error?.message ?? "Scenario seed failed";
|
|
@@ -1345,6 +1555,10 @@ var DevRunner = class {
|
|
|
1345
1555
|
await this.handleGetAuthConfig(request);
|
|
1346
1556
|
return;
|
|
1347
1557
|
}
|
|
1558
|
+
if (request.type === "get-api-config") {
|
|
1559
|
+
await this.handleGetApiConfig(request);
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1348
1562
|
const startTime = Date.now();
|
|
1349
1563
|
const method = this.appConfig?.methods.find((m) => m.id === request.methodId);
|
|
1350
1564
|
if (!method) {
|
|
@@ -1387,7 +1601,9 @@ var DevRunner = class {
|
|
|
1387
1601
|
authorizationToken: request.authorizationToken,
|
|
1388
1602
|
apiBaseUrl: getApiBaseUrl(),
|
|
1389
1603
|
projectRoot: this.projectRoot,
|
|
1390
|
-
|
|
1604
|
+
sessionId: this.session.sessionId,
|
|
1605
|
+
streamId: request.streamId,
|
|
1606
|
+
secrets: request.secrets
|
|
1391
1607
|
});
|
|
1392
1608
|
const t2 = Date.now();
|
|
1393
1609
|
const devResult = {
|
|
@@ -1555,6 +1771,51 @@ var DevRunner = class {
|
|
|
1555
1771
|
}
|
|
1556
1772
|
}
|
|
1557
1773
|
}
|
|
1774
|
+
async handleGetApiConfig(request) {
|
|
1775
|
+
log.info("runner", "API config requested", { requestId: request.requestId, sessionId: this.session.sessionId });
|
|
1776
|
+
try {
|
|
1777
|
+
const apiInterface = this.appConfig?.interfaces.find(
|
|
1778
|
+
(i) => i.type === "api" && i.enabled !== false
|
|
1779
|
+
);
|
|
1780
|
+
if (!apiInterface) {
|
|
1781
|
+
throw new Error("No API interface config found");
|
|
1782
|
+
}
|
|
1783
|
+
const apiJsonPath = join6(this.projectRoot, apiInterface.path);
|
|
1784
|
+
const raw = readFileSync3(apiJsonPath, "utf-8");
|
|
1785
|
+
const parsed = JSON.parse(raw);
|
|
1786
|
+
if (!parsed.api) {
|
|
1787
|
+
throw new Error("No API interface config found");
|
|
1788
|
+
}
|
|
1789
|
+
await submitDevResult(
|
|
1790
|
+
this.appId,
|
|
1791
|
+
this.session.sessionId,
|
|
1792
|
+
request.requestId,
|
|
1793
|
+
{
|
|
1794
|
+
type: "get-api-config",
|
|
1795
|
+
success: true,
|
|
1796
|
+
output: parsed.api
|
|
1797
|
+
}
|
|
1798
|
+
);
|
|
1799
|
+
log.info("runner", "API config sent", { requestId: request.requestId });
|
|
1800
|
+
} catch (err) {
|
|
1801
|
+
const message = err instanceof Error ? err.message : "Unknown error";
|
|
1802
|
+
log.error("runner", "API config failed", { requestId: request.requestId, error: message });
|
|
1803
|
+
try {
|
|
1804
|
+
await submitDevResult(
|
|
1805
|
+
this.appId,
|
|
1806
|
+
this.session.sessionId,
|
|
1807
|
+
request.requestId,
|
|
1808
|
+
{
|
|
1809
|
+
type: "get-api-config",
|
|
1810
|
+
success: false,
|
|
1811
|
+
error: { message }
|
|
1812
|
+
}
|
|
1813
|
+
);
|
|
1814
|
+
} catch (submitErr) {
|
|
1815
|
+
log.error("runner", "Failed to report API config error to platform", { error: submitErr instanceof Error ? submitErr.message : String(submitErr) });
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1558
1819
|
/**
|
|
1559
1820
|
* Attempt to refresh expired auth credentials via the device auth flow.
|
|
1560
1821
|
* Opens the browser for the user to re-authorize, polls for the new token.
|
|
@@ -2252,6 +2513,9 @@ var DevProxy = class _DevProxy {
|
|
|
2252
2513
|
};
|
|
2253
2514
|
delete headers["connection"];
|
|
2254
2515
|
delete headers["accept-encoding"];
|
|
2516
|
+
if (originalPath.startsWith("/_/api/") && this.clientContext.releaseId) {
|
|
2517
|
+
headers["x-dev-session"] = this.clientContext.releaseId;
|
|
2518
|
+
}
|
|
2255
2519
|
const proxyReq = httpModule.request(
|
|
2256
2520
|
{
|
|
2257
2521
|
hostname: target.hostname,
|
|
@@ -2669,13 +2933,13 @@ ${agentScript}`;
|
|
|
2669
2933
|
};
|
|
2670
2934
|
|
|
2671
2935
|
// src/dev/config/app-config.ts
|
|
2672
|
-
import { readFileSync as
|
|
2673
|
-
import { join as
|
|
2936
|
+
import { readFileSync as readFileSync4, existsSync as existsSync2 } from "fs";
|
|
2937
|
+
import { join as join7, dirname as dirname3 } from "path";
|
|
2674
2938
|
function detectAppConfig(cwd = process.cwd()) {
|
|
2675
|
-
const appJsonPath =
|
|
2939
|
+
const appJsonPath = join7(cwd, "mindstudio.json");
|
|
2676
2940
|
if (!existsSync2(appJsonPath)) return null;
|
|
2677
2941
|
try {
|
|
2678
|
-
const raw =
|
|
2942
|
+
const raw = readFileSync4(appJsonPath, "utf-8");
|
|
2679
2943
|
const parsed = JSON.parse(raw);
|
|
2680
2944
|
if (!parsed.name || !Array.isArray(parsed.methods)) {
|
|
2681
2945
|
return null;
|
|
@@ -2712,12 +2976,12 @@ function getWebInterfaceConfig(appConfig, cwd = process.cwd()) {
|
|
|
2712
2976
|
if (!webInterface) {
|
|
2713
2977
|
return null;
|
|
2714
2978
|
}
|
|
2715
|
-
const configPath =
|
|
2979
|
+
const configPath = join7(cwd, webInterface.path);
|
|
2716
2980
|
if (!existsSync2(configPath)) {
|
|
2717
2981
|
return null;
|
|
2718
2982
|
}
|
|
2719
2983
|
try {
|
|
2720
|
-
const raw =
|
|
2984
|
+
const raw = readFileSync4(configPath, "utf-8");
|
|
2721
2985
|
const parsed = JSON.parse(raw);
|
|
2722
2986
|
const web = parsed.web;
|
|
2723
2987
|
if (!web || typeof web !== "object") {
|
|
@@ -2738,18 +3002,18 @@ function getWebProjectDir(appConfig, cwd = process.cwd()) {
|
|
|
2738
3002
|
if (!webInterface) {
|
|
2739
3003
|
return null;
|
|
2740
3004
|
}
|
|
2741
|
-
return dirname3(
|
|
3005
|
+
return dirname3(join7(cwd, webInterface.path));
|
|
2742
3006
|
}
|
|
2743
3007
|
function readTableSources(appConfig, cwd = process.cwd()) {
|
|
2744
3008
|
const results = [];
|
|
2745
3009
|
for (const table of appConfig.tables) {
|
|
2746
|
-
const filePath =
|
|
3010
|
+
const filePath = join7(cwd, table.path);
|
|
2747
3011
|
if (!existsSync2(filePath)) {
|
|
2748
3012
|
log.warn("config", "Table source file not found", { table: table.export, path: table.path });
|
|
2749
3013
|
continue;
|
|
2750
3014
|
}
|
|
2751
3015
|
try {
|
|
2752
|
-
const source =
|
|
3016
|
+
const source = readFileSync4(filePath, "utf-8");
|
|
2753
3017
|
const name = table.export;
|
|
2754
3018
|
results.push({ name, source });
|
|
2755
3019
|
} catch (err) {
|
|
@@ -2767,9 +3031,9 @@ function findDirsNeedingInstall(appConfig, cwd = process.cwd()) {
|
|
|
2767
3031
|
const firstMethodPath = appConfig.methods[0].path;
|
|
2768
3032
|
const parts = firstMethodPath.split("/");
|
|
2769
3033
|
for (let i = parts.length - 1; i >= 1; i--) {
|
|
2770
|
-
const candidate =
|
|
2771
|
-
if (existsSync2(
|
|
2772
|
-
if (!existsSync2(
|
|
3034
|
+
const candidate = join7(cwd, ...parts.slice(0, i));
|
|
3035
|
+
if (existsSync2(join7(candidate, "package.json"))) {
|
|
3036
|
+
if (!existsSync2(join7(candidate, "node_modules"))) {
|
|
2773
3037
|
dirs.push(candidate);
|
|
2774
3038
|
}
|
|
2775
3039
|
break;
|
|
@@ -2777,8 +3041,8 @@ function findDirsNeedingInstall(appConfig, cwd = process.cwd()) {
|
|
|
2777
3041
|
}
|
|
2778
3042
|
}
|
|
2779
3043
|
const webProjectDir = getWebProjectDir(appConfig, cwd);
|
|
2780
|
-
if (webProjectDir && existsSync2(
|
|
2781
|
-
if (!existsSync2(
|
|
3044
|
+
if (webProjectDir && existsSync2(join7(webProjectDir, "package.json"))) {
|
|
3045
|
+
if (!existsSync2(join7(webProjectDir, "node_modules"))) {
|
|
2782
3046
|
dirs.push(webProjectDir);
|
|
2783
3047
|
}
|
|
2784
3048
|
}
|
|
@@ -2807,11 +3071,11 @@ function detectGitBranch() {
|
|
|
2807
3071
|
|
|
2808
3072
|
// src/dev/config/table-watcher.ts
|
|
2809
3073
|
import { watch } from "chokidar";
|
|
2810
|
-
import { join as
|
|
3074
|
+
import { join as join8, dirname as dirname4, basename as basename2 } from "path";
|
|
2811
3075
|
function watchTableFiles(tables, cwd, onChanged) {
|
|
2812
3076
|
if (tables.length === 0) return () => {
|
|
2813
3077
|
};
|
|
2814
|
-
const filePaths = tables.map((t) =>
|
|
3078
|
+
const filePaths = tables.map((t) => join8(cwd, t.path));
|
|
2815
3079
|
let syncTimer;
|
|
2816
3080
|
const watcher = watch(filePaths, {
|
|
2817
3081
|
ignoreInitial: true,
|
|
@@ -2824,7 +3088,7 @@ function watchTableFiles(tables, cwd, onChanged) {
|
|
|
2824
3088
|
});
|
|
2825
3089
|
const dirToFiles = /* @__PURE__ */ new Map();
|
|
2826
3090
|
for (const table of tables) {
|
|
2827
|
-
const absPath =
|
|
3091
|
+
const absPath = join8(cwd, table.path);
|
|
2828
3092
|
const dir = dirname4(absPath);
|
|
2829
3093
|
const file = basename2(absPath);
|
|
2830
3094
|
if (!dirToFiles.has(dir)) dirToFiles.set(dir, /* @__PURE__ */ new Set());
|
|
@@ -2842,9 +3106,9 @@ function watchTableFiles(tables, cwd, onChanged) {
|
|
|
2842
3106
|
|
|
2843
3107
|
// src/dev/config/config-watcher.ts
|
|
2844
3108
|
import { watch as watch2 } from "chokidar";
|
|
2845
|
-
import { join as
|
|
3109
|
+
import { join as join9 } from "path";
|
|
2846
3110
|
function watchConfigFile(cwd, onChanged) {
|
|
2847
|
-
const configPath =
|
|
3111
|
+
const configPath = join9(cwd, "mindstudio.json");
|
|
2848
3112
|
let debounceTimer;
|
|
2849
3113
|
const watcher = watch2(configPath, {
|
|
2850
3114
|
ignoreInitial: true,
|
|
@@ -2887,6 +3151,8 @@ export {
|
|
|
2887
3151
|
getUploadUrl,
|
|
2888
3152
|
createAuthSession,
|
|
2889
3153
|
devRequestEvents,
|
|
3154
|
+
initRequestLog,
|
|
3155
|
+
closeRequestLog,
|
|
2890
3156
|
pollForRequest,
|
|
2891
3157
|
submitProgress,
|
|
2892
3158
|
submitResult,
|
|
@@ -2897,8 +3163,6 @@ export {
|
|
|
2897
3163
|
pollDeviceAuth,
|
|
2898
3164
|
getEditorSessions,
|
|
2899
3165
|
disconnectHeartbeat,
|
|
2900
|
-
initRequestLog,
|
|
2901
|
-
closeRequestLog,
|
|
2902
3166
|
DevRunner,
|
|
2903
3167
|
initBrowserLog,
|
|
2904
3168
|
closeBrowserLog,
|
|
@@ -2913,4 +3177,4 @@ export {
|
|
|
2913
3177
|
watchTableFiles,
|
|
2914
3178
|
watchConfigFile
|
|
2915
3179
|
};
|
|
2916
|
-
//# sourceMappingURL=chunk-
|
|
3180
|
+
//# sourceMappingURL=chunk-UCESXK4F.js.map
|