@dougbots/avenor-core 0.10.1 → 0.10.3

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
@@ -407,6 +407,13 @@ declare class Supervisor {
407
407
  private static start;
408
408
  private startProcess;
409
409
  get supervisorId(): string;
410
+ /**
411
+ * Look up a run by its public run ID first, then by its label alias.
412
+ * Public run IDs are canonical; labels are lookup-only aliases.
413
+ */
414
+ getRunByReference(reference: string): RunInfo | undefined;
415
+ /** Match a stored run by its broker runtime ID. */
416
+ getRunByRuntimeId(runtimeId: string): RunInfo | undefined;
410
417
  static isCurrentInstance(supervisorId: string): boolean;
411
418
  static currentInstance(): Supervisor | null;
412
419
  getClient(): Client;
@@ -420,7 +427,7 @@ declare class Supervisor {
420
427
  declare function socketsRoot(): string;
421
428
  //#endregion
422
429
  //#region src/tools/get-supervisor-client.d.ts
423
- declare function getSupervisorClient(supervisorId: string): Promise<{
430
+ declare function getSupervisorClient(supervisorId: string | undefined): Promise<{
424
431
  client: Client;
425
432
  isSingleton: boolean;
426
433
  sup: Supervisor | null;
package/dist/index.js CHANGED
@@ -1496,6 +1496,18 @@ var Supervisor = class Supervisor {
1496
1496
  get supervisorId() {
1497
1497
  return this.socketPath;
1498
1498
  }
1499
+ /**
1500
+ * Look up a run by its public run ID first, then by its label alias.
1501
+ * Public run IDs are canonical; labels are lookup-only aliases.
1502
+ */
1503
+ getRunByReference(reference) {
1504
+ return this.runs.get(reference) ?? this.aliases.get(reference);
1505
+ }
1506
+ /** Match a stored run by its broker runtime ID. */
1507
+ getRunByRuntimeId(runtimeId) {
1508
+ if (!runtimeId) return void 0;
1509
+ for (const runInfo of this.runs.values()) if (runInfo.runtimeId === runtimeId) return runInfo;
1510
+ }
1499
1511
  static isCurrentInstance(supervisorId) {
1500
1512
  return Supervisor.instance !== null && Supervisor.instance.supervisorId === supervisorId;
1501
1513
  }
@@ -1641,6 +1653,15 @@ function validateObservedAt(observedAt) {
1641
1653
  //#endregion
1642
1654
  //#region src/tools/get-supervisor-client.ts
1643
1655
  async function getSupervisorClient(supervisorId) {
1656
+ if (supervisorId === void 0) {
1657
+ const sup = await Supervisor.get();
1658
+ return {
1659
+ client: sup.getClient(),
1660
+ isSingleton: true,
1661
+ sup,
1662
+ supervisorId: sup.supervisorId
1663
+ };
1664
+ }
1644
1665
  const id = validateSupervisorSocketPath(supervisorId);
1645
1666
  const current = Supervisor.currentInstance();
1646
1667
  if (current !== null && validateSupervisorSocketPath(current.supervisorId) === id) return {
@@ -2096,14 +2117,11 @@ function validateThinkingForBackendResume(backend, value) {
2096
2117
  //#region src/tools/run-resolution.ts
2097
2118
  /** Resolve a local public run ID before considering a label alias. */
2098
2119
  function findLocalRunByReference(sup, reference) {
2099
- const { runs, aliases } = sup;
2100
- return runs.get(reference) ?? aliases.get(reference);
2120
+ return sup.getRunByReference(reference);
2101
2121
  }
2102
2122
  /** Match a supervisor list entry to its stored runtime identity. */
2103
2123
  function findLocalRunByRuntimeId(sup, runtimeId) {
2104
- if (!runtimeId) return void 0;
2105
- const { runs } = sup;
2106
- for (const runInfo of runs.values()) if (runInfo.runtimeId === runtimeId) return runInfo;
2124
+ return sup.getRunByRuntimeId(runtimeId);
2107
2125
  }
2108
2126
  //#endregion
2109
2127
  //#region src/tools/status.ts
@@ -3016,9 +3034,10 @@ function extractReplyMessage(result) {
3016
3034
  return JSON.stringify(result);
3017
3035
  }
3018
3036
  async function executeAskTool(args, getSupervisorClient) {
3019
- const { client, isSingleton } = await getSupervisorClient(args.supervisorId);
3037
+ const { client, isSingleton, sup, supervisorId } = await getSupervisorClient(args.supervisorId);
3020
3038
  try {
3021
- const result = await client.brokerAsk(args.toRunId, args.message);
3039
+ const target = (isSingleton && sup ? findLocalRunByReference(sup, args.toRunId) : findExternalRun(supervisorId, args.toRunId))?.runtimeId ?? args.toRunId;
3040
+ const result = await client.brokerAsk(target, args.message);
3022
3041
  return {
3023
3042
  reply: extractReplyMessage(result),
3024
3043
  from_run_id: result.from_run_id ?? ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dougbots/avenor-core",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",