@dougbots/avenor-core 0.3.5 → 0.3.7
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/index.d.ts +5 -2
- package/dist/index.js +39 -33
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ declare function dial(socketPath: string, opts?: {
|
|
|
58
58
|
//#endregion
|
|
59
59
|
//#region src/supervisor.d.ts
|
|
60
60
|
interface RunInfo {
|
|
61
|
+
runId: string;
|
|
61
62
|
label: string;
|
|
62
63
|
sentinelPath: string;
|
|
63
64
|
eventLogPath: string;
|
|
@@ -90,8 +91,10 @@ declare class Supervisor {
|
|
|
90
91
|
static isCurrentInstance(supervisorId: string): boolean;
|
|
91
92
|
static currentInstance(): Supervisor | null;
|
|
92
93
|
getClient(): Client;
|
|
93
|
-
spawn(params: SpawnParams): Promise<RunInfo>;
|
|
94
|
-
close(
|
|
94
|
+
spawn(params: SpawnParams, runId?: `${string}-${string}-${string}-${string}-${string}`): Promise<RunInfo>;
|
|
95
|
+
close(options?: {
|
|
96
|
+
skipShutdown?: boolean;
|
|
97
|
+
}): Promise<void>;
|
|
95
98
|
}
|
|
96
99
|
//#endregion
|
|
97
100
|
//#region src/tools/spawn.d.ts
|
package/dist/index.js
CHANGED
|
@@ -383,9 +383,8 @@ var Supervisor = class Supervisor {
|
|
|
383
383
|
if (!this.client) throw new Error("supervisor not started");
|
|
384
384
|
return this.client;
|
|
385
385
|
}
|
|
386
|
-
async spawn(params) {
|
|
386
|
+
async spawn(params, runId = crypto.randomUUID()) {
|
|
387
387
|
const client = this.getClient();
|
|
388
|
-
const runId = crypto.randomUUID();
|
|
389
388
|
const { sentinelPath, eventLogPath } = ensureRunPaths(runId);
|
|
390
389
|
const spawnParams = {
|
|
391
390
|
...params,
|
|
@@ -395,6 +394,7 @@ var Supervisor = class Supervisor {
|
|
|
395
394
|
};
|
|
396
395
|
const result = await client.spawn(spawnParams);
|
|
397
396
|
const runInfo = {
|
|
397
|
+
runId,
|
|
398
398
|
label: spawnParams.label ?? runId,
|
|
399
399
|
sentinelPath: result.sentinel_file ?? sentinelPath,
|
|
400
400
|
eventLogPath: result.on_event ?? eventLogPath,
|
|
@@ -407,8 +407,8 @@ var Supervisor = class Supervisor {
|
|
|
407
407
|
this.runs.set(runId, runInfo);
|
|
408
408
|
return runInfo;
|
|
409
409
|
}
|
|
410
|
-
async close() {
|
|
411
|
-
if (this.client) try {
|
|
410
|
+
async close(options = {}) {
|
|
411
|
+
if (this.client && !options.skipShutdown) try {
|
|
412
412
|
await this.client.shutdown("graceful");
|
|
413
413
|
} catch {}
|
|
414
414
|
if (this.childProcess) {
|
|
@@ -447,26 +447,23 @@ function validateTimeout(value) {
|
|
|
447
447
|
return amount;
|
|
448
448
|
}
|
|
449
449
|
function validateSupervisorSocketPath(supervisorId) {
|
|
450
|
-
const canonical = fs.realpathSync(supervisorId);
|
|
451
450
|
const root = fs.realpathSync(socketsRoot());
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
451
|
+
const parent = fs.realpathSync(path.dirname(supervisorId));
|
|
452
|
+
const basename = path.basename(supervisorId);
|
|
453
|
+
if (parent !== root || !/^avenor-mcp-[^/\\]+\.sock$/.test(basename)) throw new Error(`invalid supervisorId: ${supervisorId}`);
|
|
454
|
+
return path.join(parent, basename);
|
|
455
455
|
}
|
|
456
456
|
//#endregion
|
|
457
457
|
//#region src/tools/get-supervisor-client.ts
|
|
458
458
|
async function getSupervisorClient(supervisorId) {
|
|
459
459
|
const id = validateSupervisorSocketPath(supervisorId);
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
supervisorId: id
|
|
468
|
-
};
|
|
469
|
-
}
|
|
460
|
+
const current = Supervisor.currentInstance();
|
|
461
|
+
if (current !== null && validateSupervisorSocketPath(current.supervisorId) === id) return {
|
|
462
|
+
client: current.getClient(),
|
|
463
|
+
isSingleton: true,
|
|
464
|
+
sup: current,
|
|
465
|
+
supervisorId: id
|
|
466
|
+
};
|
|
470
467
|
return {
|
|
471
468
|
client: await dial(id),
|
|
472
469
|
isSingleton: false,
|
|
@@ -523,10 +520,10 @@ async function spawnTool(args) {
|
|
|
523
520
|
server_url: args.serverUrl,
|
|
524
521
|
session_id: args.sessionId,
|
|
525
522
|
parent_run_id: args.parent_run_id
|
|
526
|
-
});
|
|
523
|
+
}, runId);
|
|
527
524
|
return {
|
|
528
|
-
run_id: runId,
|
|
529
|
-
label,
|
|
525
|
+
run_id: runInfo.runId,
|
|
526
|
+
label: runInfo.label,
|
|
530
527
|
supervisor_id: sup.supervisorId,
|
|
531
528
|
runtime_id: runInfo.runtimeId,
|
|
532
529
|
broker_url: runInfo.brokerUrl,
|
|
@@ -579,17 +576,18 @@ function sentinelStatusToResult(sentinelStatus) {
|
|
|
579
576
|
}
|
|
580
577
|
function translateStatus(rawPhase, sentinelData) {
|
|
581
578
|
const sentinelStatus = sentinelData?._status;
|
|
582
|
-
|
|
583
|
-
|
|
579
|
+
const phase = rawPhase.toLowerCase();
|
|
580
|
+
if (sentinelStatus && (phase === "running" || phase === "idle")) return sentinelStatusToResult(sentinelStatus);
|
|
581
|
+
switch (phase) {
|
|
584
582
|
case "idle": return sentinelStatus ? sentinelStatusToResult(sentinelStatus) : "running";
|
|
585
583
|
case "running": return "running";
|
|
586
584
|
case "waiting": return "waiting";
|
|
587
585
|
case "ended": return sentinelStatus ? sentinelStatusToResult(sentinelStatus) : "running";
|
|
588
|
-
case "
|
|
589
|
-
case "
|
|
590
|
-
case "
|
|
591
|
-
case "
|
|
592
|
-
case "
|
|
586
|
+
case "done": return "done";
|
|
587
|
+
case "failed": return "failed";
|
|
588
|
+
case "timeout": return "timeout";
|
|
589
|
+
case "killed": return "killed";
|
|
590
|
+
case "blocked": return "failed";
|
|
593
591
|
default: return "running";
|
|
594
592
|
}
|
|
595
593
|
}
|
|
@@ -598,7 +596,7 @@ async function buildRunStatus(client, runInfo, liveStatus) {
|
|
|
598
596
|
if (await sentinelExists(runInfo.sentinelPath)) sentinel = await parseSentinel$1(runInfo.sentinelPath);
|
|
599
597
|
const translated = translateStatus(liveStatus?.phase ?? liveStatus?.status ?? "running", sentinel);
|
|
600
598
|
const result = {
|
|
601
|
-
run_id: runInfo.
|
|
599
|
+
run_id: runInfo.runId,
|
|
602
600
|
label: runInfo.label,
|
|
603
601
|
status: translated,
|
|
604
602
|
runtime_id: liveStatus?.runtime_id ?? runInfo.runtimeId,
|
|
@@ -623,10 +621,18 @@ async function buildRunStatus(client, runInfo, liveStatus) {
|
|
|
623
621
|
}
|
|
624
622
|
async function statusTool(args) {
|
|
625
623
|
if (args.supervisorId) {
|
|
626
|
-
const { client, isSingleton } = await getSupervisorClient(args.supervisorId);
|
|
624
|
+
const { client, isSingleton, sup } = await getSupervisorClient(args.supervisorId);
|
|
627
625
|
try {
|
|
628
626
|
if (args.runId) {
|
|
629
627
|
validateRunId(args.runId);
|
|
628
|
+
const runInfo = isSingleton && sup ? findRunByLabel$3(sup, args.runId) : void 0;
|
|
629
|
+
if (runInfo) {
|
|
630
|
+
let liveStatus = null;
|
|
631
|
+
if (runInfo.runtimeId) try {
|
|
632
|
+
liveStatus = await client.status(runInfo.runtimeId);
|
|
633
|
+
} catch {}
|
|
634
|
+
return buildRunStatus(client, runInfo, liveStatus);
|
|
635
|
+
}
|
|
630
636
|
let liveStatus = null;
|
|
631
637
|
try {
|
|
632
638
|
liveStatus = await client.status(args.runId);
|
|
@@ -831,7 +837,7 @@ async function followUpTool(args) {
|
|
|
831
837
|
label: followUpLabel
|
|
832
838
|
});
|
|
833
839
|
return {
|
|
834
|
-
run_id: followUpRun.
|
|
840
|
+
run_id: followUpRun.runId,
|
|
835
841
|
label: followUpRun.label
|
|
836
842
|
};
|
|
837
843
|
}
|
|
@@ -894,7 +900,7 @@ async function shutdownTool(args) {
|
|
|
894
900
|
cleanedUp.push(info.eventLogPath);
|
|
895
901
|
} catch {}
|
|
896
902
|
}
|
|
897
|
-
await sup.close();
|
|
903
|
+
await sup.close({ skipShutdown: true });
|
|
898
904
|
} else {
|
|
899
905
|
const client = await dial(supervisorId);
|
|
900
906
|
try {
|
|
@@ -923,7 +929,7 @@ async function shutdownTool(args) {
|
|
|
923
929
|
cleanedUp.push(info.eventLogPath);
|
|
924
930
|
} catch {}
|
|
925
931
|
}
|
|
926
|
-
await sup.close();
|
|
932
|
+
await sup.close({ skipShutdown: true });
|
|
927
933
|
return {
|
|
928
934
|
ok: true,
|
|
929
935
|
cleaned_up: cleanedUp
|