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

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.
@@ -7186,6 +7186,7 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
7186
7186
  */
7187
7187
  const launchIn = async (owner, parameters) => {
7188
7188
  if (serverHost.context.requestApi === void 0) return textResult(`Error: this host cannot reach session ${owner} to launch the workflow there.`, true);
7189
+ watchOwner(owner);
7189
7190
  const response = await serverHost.context.requestApi({
7190
7191
  scope: "session",
7191
7192
  sessionId: owner
@@ -7593,7 +7594,7 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
7593
7594
  deferred: report.deferred ?? []
7594
7595
  };
7595
7596
  };
7596
- const policyHandles = /* @__PURE__ */ new Set();
7597
+ const policies = /* @__PURE__ */ new Map();
7597
7598
  const admissions = createWorkflowAdmissions({
7598
7599
  sessionId: host.context.sessionId,
7599
7600
  journal: featureFor(legacyHome).registry,
@@ -7602,12 +7603,24 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
7602
7603
  registerPolicy(coordinator, callback, options) {
7603
7604
  assertAvailable();
7604
7605
  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);
7606
+ if (policies.has(coordinator)) throw new Error("Workflow policy coordinator is already registered for this session.");
7607
+ const registration = {
7608
+ callback,
7609
+ options: {
7610
+ ...options,
7611
+ environmentKeys: [...options.environmentKeys]
7612
+ }
7613
+ };
7614
+ registration.binding = {
7615
+ service: publicServices,
7616
+ handle: publicServices.registerPolicy(host.context.sessionId, coordinator, callback, registration.options)
7617
+ };
7618
+ policies.set(coordinator, registration);
7607
7619
  queueMicrotask(deliverSettlements);
7608
7620
  return { dispose() {
7609
- handle.dispose();
7610
- policyHandles.delete(handle);
7621
+ registration.binding?.handle.dispose();
7622
+ delete registration.binding;
7623
+ if (policies.get(coordinator) === registration) policies.delete(coordinator);
7611
7624
  } };
7612
7625
  },
7613
7626
  async execute(request, admission) {
@@ -7617,6 +7630,7 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
7617
7630
  const ownerId = record.admission?.ownerSessionId ?? request.previousRun.ownerSessionId;
7618
7631
  const owner = publicServices?.owner(ownerId);
7619
7632
  if (!owner) throw new Error("Workflow recovery owner is unavailable; admission remains pending.");
7633
+ watchOwner(ownerId);
7620
7634
  await owner.recover(request.previousRun, request.options?.runner, admission);
7621
7635
  } else {
7622
7636
  const input = await admissionInput(request);
@@ -7624,6 +7638,7 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
7624
7638
  if (ownerId !== void 0) {
7625
7639
  const owner = publicServices?.owner(ownerId);
7626
7640
  if (!owner) throw new Error("Workflow launch owner is unavailable; admission remains pending.");
7641
+ watchOwner(ownerId);
7627
7642
  await owner.launch(input, {
7628
7643
  ...admission,
7629
7644
  ownerSessionId: ownerId
@@ -7809,11 +7824,27 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
7809
7824
  })).isError) throw new Error("Workflow recovery did not acknowledge admission.");
7810
7825
  }
7811
7826
  });
7812
- return () => {
7827
+ const detach = () => {
7828
+ for (const registration of policies.values()) {
7829
+ if (registration.binding?.service !== service) continue;
7830
+ registration.binding.handle.dispose();
7831
+ delete registration.binding;
7832
+ }
7813
7833
  owner.dispose();
7814
7834
  service.withdraw(host.context.sessionId);
7815
7835
  if (publicServices === service) publicServices = void 0;
7816
7836
  };
7837
+ try {
7838
+ for (const [coordinator, registration] of policies) registration.binding = {
7839
+ service,
7840
+ handle: service.registerPolicy(host.context.sessionId, coordinator, registration.callback, registration.options)
7841
+ };
7842
+ queueMicrotask(deliverSettlements);
7843
+ } catch (error) {
7844
+ detach();
7845
+ throw error;
7846
+ }
7847
+ return detach;
7817
7848
  });
7818
7849
  });
7819
7850
  }
@@ -8030,8 +8061,8 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
8030
8061
  disposed = true;
8031
8062
  publicServices?.withdraw(host.context.sessionId);
8032
8063
  startupAbort.abort();
8033
- for (const handle of policyHandles) handle.dispose();
8034
- policyHandles.clear();
8064
+ for (const registration of policies.values()) registration.binding?.handle.dispose();
8065
+ policies.clear();
8035
8066
  if (deliveryRetry !== void 0) clearTimeout(deliveryRetry);
8036
8067
  deliveryRetry = void 0;
8037
8068
  pendingCompletions.clear();