@maplezzk/pi-dynamic-workflows 1.1.2 → 1.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/workflow.ts +16 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maplezzk/pi-dynamic-workflows",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Claude-Code-style dynamic workflow orchestration for Pi. Fork of michaelliv/pi-dynamic-workflows.",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
package/src/workflow.ts CHANGED
@@ -203,7 +203,7 @@ export async function runWorkflow<T = unknown>(
203
203
  };
204
204
 
205
205
  const context = vm.createContext({
206
- agent,
206
+ __agent: agent,
207
207
  parallel,
208
208
  pipeline,
209
209
  log,
@@ -230,7 +230,21 @@ export async function runWorkflow<T = unknown>(
230
230
  Promise,
231
231
  });
232
232
 
233
- const wrapped = `(async () => {\n${body}\n})()`;
233
+ // A host Promise receives a context-local wrapper when it crosses into vm.
234
+ // Track that wrapper in the vm realm itself so a fire-and-forget agent() that
235
+ // later rejects (notably during cancellation) cannot become an unhandled
236
+ // rejection and terminate Pi. Returning the original promise preserves normal
237
+ // await/rejection semantics for workflow scripts.
238
+ const wrapped = `(async (__workflowAgent) => {
239
+ const trackedAgent = (...args) => {
240
+ const promise = __workflowAgent(...args)
241
+ void promise.catch(() => {})
242
+ return promise
243
+ }
244
+ return await (async (agent) => {
245
+ ${body}
246
+ })(trackedAgent)
247
+ })(__agent)`;
234
248
  const result = await new vm.Script(wrapped, { filename: `${meta.name || "workflow"}.js` }).runInContext(context);
235
249
  await Promise.allSettled([...pendingAgentRuns]);
236
250
  assertStructuredCloneable(result, "workflow result");