@ryan_nookpi/pi-extension-subagent 0.5.8 → 0.5.9

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.
@@ -15,6 +15,15 @@ interface Invocation {
15
15
  const invocations = new AsyncLocalStorage<Invocation>();
16
16
  const resources = new AsyncLocalStorage<(presence: Presence) => void>();
17
17
 
18
+ /**
19
+ * Pi can start the next agent turn synchronously inside sendMessage(triggerTurn).
20
+ * Run it outside this invocation's async context so tool calls in that turn start
21
+ * their own roots instead of attaching to an already finished one.
22
+ */
23
+ function outsideInvocation<T>(work: () => T): T {
24
+ return invocations.exit(() => resources.exit(work));
25
+ }
26
+
18
27
  export function currentResourceObserver(): (presence: Presence) => void {
19
28
  return resources.getStore() ?? (() => {});
20
29
  }
@@ -247,7 +256,7 @@ export class SubagentAsyncTasks {
247
256
  // A persisted completion from another provider instance must never auto-replay.
248
257
  if (typeof details.asyncTaskRootId === "string" && !root) return;
249
258
  if (!root || options?.triggerTurn === false || (!root.result && options?.triggerTurn !== true)) {
250
- target.sendMessage(message, options);
259
+ outsideInvocation(() => target.sendMessage(message, options));
251
260
  return;
252
261
  }
253
262
  if (root.hidden) return;
@@ -259,7 +268,9 @@ export class SubagentAsyncTasks {
259
268
  root.id,
260
269
  (typeof message.content === "string" ? message.content : JSON.stringify(message.content)).slice(0, 4096),
261
270
  );
262
- this.provider.deliver([root.id], message, (annotated) => target.sendMessage(annotated, options));
271
+ this.provider.deliver([root.id], message, (annotated) =>
272
+ outsideInvocation(() => target.sendMessage(annotated, options)),
273
+ );
263
274
  };
264
275
  return send;
265
276
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryan_nookpi/pi-extension-subagent",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "Asynchronous subagent delegation for pi with run, batch, chain, and continuation workflows.",
5
5
  "license": "MIT",
6
6
  "repository": {