@dougbots/avenor-core 0.3.5 → 0.3.6

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 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(): Promise<void>;
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) {
@@ -523,10 +523,10 @@ async function spawnTool(args) {
523
523
  server_url: args.serverUrl,
524
524
  session_id: args.sessionId,
525
525
  parent_run_id: args.parent_run_id
526
- });
526
+ }, runId);
527
527
  return {
528
- run_id: runId,
529
- label,
528
+ run_id: runInfo.runId,
529
+ label: runInfo.label,
530
530
  supervisor_id: sup.supervisorId,
531
531
  runtime_id: runInfo.runtimeId,
532
532
  broker_url: runInfo.brokerUrl,
@@ -579,17 +579,18 @@ function sentinelStatusToResult(sentinelStatus) {
579
579
  }
580
580
  function translateStatus(rawPhase, sentinelData) {
581
581
  const sentinelStatus = sentinelData?._status;
582
- if (sentinelStatus && (rawPhase === "running" || rawPhase === "idle")) return sentinelStatusToResult(sentinelStatus);
583
- switch (rawPhase) {
582
+ const phase = rawPhase.toLowerCase();
583
+ if (sentinelStatus && (phase === "running" || phase === "idle")) return sentinelStatusToResult(sentinelStatus);
584
+ switch (phase) {
584
585
  case "idle": return sentinelStatus ? sentinelStatusToResult(sentinelStatus) : "running";
585
586
  case "running": return "running";
586
587
  case "waiting": return "waiting";
587
588
  case "ended": return sentinelStatus ? sentinelStatusToResult(sentinelStatus) : "running";
588
- case "DONE": return "done";
589
- case "FAILED": return "failed";
590
- case "TIMEOUT": return "timeout";
591
- case "KILLED": return "killed";
592
- case "BLOCKED": return "failed";
589
+ case "done": return "done";
590
+ case "failed": return "failed";
591
+ case "timeout": return "timeout";
592
+ case "killed": return "killed";
593
+ case "blocked": return "failed";
593
594
  default: return "running";
594
595
  }
595
596
  }
@@ -598,7 +599,7 @@ async function buildRunStatus(client, runInfo, liveStatus) {
598
599
  if (await sentinelExists(runInfo.sentinelPath)) sentinel = await parseSentinel$1(runInfo.sentinelPath);
599
600
  const translated = translateStatus(liveStatus?.phase ?? liveStatus?.status ?? "running", sentinel);
600
601
  const result = {
601
- run_id: runInfo.label,
602
+ run_id: runInfo.runId,
602
603
  label: runInfo.label,
603
604
  status: translated,
604
605
  runtime_id: liveStatus?.runtime_id ?? runInfo.runtimeId,
@@ -831,7 +832,7 @@ async function followUpTool(args) {
831
832
  label: followUpLabel
832
833
  });
833
834
  return {
834
- run_id: followUpRun.label,
835
+ run_id: followUpRun.runId,
835
836
  label: followUpRun.label
836
837
  };
837
838
  }
@@ -894,7 +895,7 @@ async function shutdownTool(args) {
894
895
  cleanedUp.push(info.eventLogPath);
895
896
  } catch {}
896
897
  }
897
- await sup.close();
898
+ await sup.close({ skipShutdown: true });
898
899
  } else {
899
900
  const client = await dial(supervisorId);
900
901
  try {
@@ -923,7 +924,7 @@ async function shutdownTool(args) {
923
924
  cleanedUp.push(info.eventLogPath);
924
925
  } catch {}
925
926
  }
926
- await sup.close();
927
+ await sup.close({ skipShutdown: true });
927
928
  return {
928
929
  ok: true,
929
930
  cleaned_up: cleanedUp
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dougbots/avenor-core",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",