@agimon-ai/po-workflow 0.0.0-alpha.83 → 0.0.0-alpha.84

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.
@@ -7593,7 +7593,7 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
7593
7593
  deferred: report.deferred ?? []
7594
7594
  };
7595
7595
  };
7596
- const policyHandles = /* @__PURE__ */ new Set();
7596
+ const policies = /* @__PURE__ */ new Map();
7597
7597
  const admissions = createWorkflowAdmissions({
7598
7598
  sessionId: host.context.sessionId,
7599
7599
  journal: featureFor(legacyHome).registry,
@@ -7602,12 +7602,24 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
7602
7602
  registerPolicy(coordinator, callback, options) {
7603
7603
  assertAvailable();
7604
7604
  if (!publicServices) throw new Error("Workflow policy registration is unavailable.");
7605
- const handle = publicServices.registerPolicy(host.context.sessionId, coordinator, callback, options);
7606
- policyHandles.add(handle);
7605
+ if (policies.has(coordinator)) throw new Error("Workflow policy coordinator is already registered for this session.");
7606
+ const registration = {
7607
+ callback,
7608
+ options: {
7609
+ ...options,
7610
+ environmentKeys: [...options.environmentKeys]
7611
+ }
7612
+ };
7613
+ registration.binding = {
7614
+ service: publicServices,
7615
+ handle: publicServices.registerPolicy(host.context.sessionId, coordinator, callback, registration.options)
7616
+ };
7617
+ policies.set(coordinator, registration);
7607
7618
  queueMicrotask(deliverSettlements);
7608
7619
  return { dispose() {
7609
- handle.dispose();
7610
- policyHandles.delete(handle);
7620
+ registration.binding?.handle.dispose();
7621
+ delete registration.binding;
7622
+ if (policies.get(coordinator) === registration) policies.delete(coordinator);
7611
7623
  } };
7612
7624
  },
7613
7625
  async execute(request, admission) {
@@ -7809,11 +7821,27 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
7809
7821
  })).isError) throw new Error("Workflow recovery did not acknowledge admission.");
7810
7822
  }
7811
7823
  });
7812
- return () => {
7824
+ const detach = () => {
7825
+ for (const registration of policies.values()) {
7826
+ if (registration.binding?.service !== service) continue;
7827
+ registration.binding.handle.dispose();
7828
+ delete registration.binding;
7829
+ }
7813
7830
  owner.dispose();
7814
7831
  service.withdraw(host.context.sessionId);
7815
7832
  if (publicServices === service) publicServices = void 0;
7816
7833
  };
7834
+ try {
7835
+ for (const [coordinator, registration] of policies) registration.binding = {
7836
+ service,
7837
+ handle: service.registerPolicy(host.context.sessionId, coordinator, registration.callback, registration.options)
7838
+ };
7839
+ queueMicrotask(deliverSettlements);
7840
+ } catch (error) {
7841
+ detach();
7842
+ throw error;
7843
+ }
7844
+ return detach;
7817
7845
  });
7818
7846
  });
7819
7847
  }
@@ -8030,8 +8058,8 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
8030
8058
  disposed = true;
8031
8059
  publicServices?.withdraw(host.context.sessionId);
8032
8060
  startupAbort.abort();
8033
- for (const handle of policyHandles) handle.dispose();
8034
- policyHandles.clear();
8061
+ for (const registration of policies.values()) registration.binding?.handle.dispose();
8062
+ policies.clear();
8035
8063
  if (deliveryRetry !== void 0) clearTimeout(deliveryRetry);
8036
8064
  deliveryRetry = void 0;
8037
8065
  pendingCompletions.clear();