@agimon-ai/po-core 0.0.0-alpha.4 → 0.0.0-alpha.5

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 (24) hide show
  1. package/dist/src/server/directHarnessRuntime.cjs +43 -0
  2. package/dist/src/server/directHarnessRuntime.cjs.map +1 -1
  3. package/dist/src/server/directHarnessRuntime.mjs +43 -0
  4. package/dist/src/server/directHarnessRuntime.mjs.map +1 -1
  5. package/dist/src/services/piExtensionHost/index.cjs +5 -2
  6. package/dist/src/services/piExtensionHost/index.cjs.map +1 -1
  7. package/dist/src/services/piExtensionHost/index.d.mts.map +1 -1
  8. package/dist/src/services/piExtensionHost/index.mjs +5 -2
  9. package/dist/src/services/piExtensionHost/index.mjs.map +1 -1
  10. package/dist/src/systems/main/adapters/headlessHost.cjs +11 -8
  11. package/dist/src/systems/main/adapters/headlessHost.cjs.map +1 -1
  12. package/dist/src/systems/main/adapters/headlessHost.d.mts.map +1 -1
  13. package/dist/src/systems/main/adapters/headlessHost.mjs +11 -8
  14. package/dist/src/systems/main/adapters/headlessHost.mjs.map +1 -1
  15. package/dist/src/systems/main/adapters/headlessSessionHost.cjs +22 -1
  16. package/dist/src/systems/main/adapters/headlessSessionHost.cjs.map +1 -1
  17. package/dist/src/systems/main/adapters/headlessSessionHost.d.mts.map +1 -1
  18. package/dist/src/systems/main/adapters/headlessSessionHost.mjs +22 -1
  19. package/dist/src/systems/main/adapters/headlessSessionHost.mjs.map +1 -1
  20. package/dist/src/systems/main/types/headlessHost.d.mts +3 -1
  21. package/dist/src/systems/main/types/headlessHost.d.mts.map +1 -1
  22. package/dist/src/types/server/directHarnessRuntime.d.mts +5 -0
  23. package/dist/src/types/server/directHarnessRuntime.d.mts.map +1 -1
  24. package/package.json +4 -4
@@ -126,6 +126,17 @@ async function createDirectHarnessRuntime(options) {
126
126
  const listeners = /* @__PURE__ */ new Set();
127
127
  const eventListeners = /* @__PURE__ */ new Set();
128
128
  const checkpointBoundaries = /* @__PURE__ */ new Set();
129
+ const toolBoundaryQueue = [];
130
+ let toolBoundaryDrain;
131
+ const flushToolBoundary = () => {
132
+ if (toolBoundaryDrain) return toolBoundaryDrain;
133
+ toolBoundaryDrain = (async () => {
134
+ while (toolBoundaryQueue.length && !disposed && !disposePromise) await toolBoundaryQueue.shift().run();
135
+ })().finally(() => {
136
+ toolBoundaryDrain = void 0;
137
+ });
138
+ return toolBoundaryDrain;
139
+ };
129
140
  const emit = (frame) => {
130
141
  for (const listener of listeners) try {
131
142
  listener(frame);
@@ -356,6 +367,7 @@ async function createDirectHarnessRuntime(options) {
356
367
  async afterTools(_assistant, _results, api, ctx) {
357
368
  const lane = conversation;
358
369
  if (lane.id !== api.conversationId) return;
370
+ await flushToolBoundary();
359
371
  for (const registration of checkpointBoundaries) {
360
372
  if (!registration.active || disposed || ctx.abortSignal?.aborted || external) continue;
361
373
  let open = true;
@@ -593,6 +605,31 @@ async function createDirectHarnessRuntime(options) {
593
605
  kind: "run",
594
606
  status: "open"
595
607
  } : null);
608
+ const runAtToolBoundary = (callback) => {
609
+ if (disposed || disposePromise) return Promise.reject(/* @__PURE__ */ new Error("Direct harness is disposed"));
610
+ return new Promise((resolve, reject) => {
611
+ const pending = {
612
+ async run() {
613
+ try {
614
+ resolve(await callback());
615
+ } catch (error) {
616
+ reject(error);
617
+ }
618
+ },
619
+ reject
620
+ };
621
+ toolBoundaryQueue.push(pending);
622
+ nativeExecution().then(async (active) => {
623
+ if (!active && !external) await flushToolBoundary();
624
+ }).catch((error) => {
625
+ const index = toolBoundaryQueue.indexOf(pending);
626
+ if (index !== -1) {
627
+ toolBoundaryQueue.splice(index, 1);
628
+ reject(error);
629
+ }
630
+ });
631
+ });
632
+ };
596
633
  const readLifecycle = async () => {
597
634
  const record = await readRecord();
598
635
  return {
@@ -849,6 +886,7 @@ async function createDirectHarnessRuntime(options) {
849
886
  }
850
887
  };
851
888
  eventsSettled = eventsSettled.then(async () => {
889
+ if (!await nativeExecution() && !external) await flushToolBoundary();
852
890
  await reconcile();
853
891
  try {
854
892
  await writable(() => harness.commit((tx) => tx.appendEntry(conversation.id, {
@@ -1538,6 +1576,7 @@ async function createDirectHarnessRuntime(options) {
1538
1576
  } finally {
1539
1577
  if (!admitted) {
1540
1578
  external = void 0;
1579
+ if (!await nativeExecution()) await flushToolBoundary();
1541
1580
  drain().catch((error) => emit({
1542
1581
  type: "error",
1543
1582
  error: String(error)
@@ -1564,6 +1603,7 @@ async function createDirectHarnessRuntime(options) {
1564
1603
  } finally {
1565
1604
  external = void 0;
1566
1605
  externalAbort = void 0;
1606
+ await flushToolBoundary();
1567
1607
  await publish();
1568
1608
  drain().catch((error) => emit({
1569
1609
  type: "error",
@@ -1666,6 +1706,7 @@ async function createDirectHarnessRuntime(options) {
1666
1706
  };
1667
1707
  let disposePromise;
1668
1708
  const dispose = () => disposePromise ??= (async () => {
1709
+ for (const pending of toolBoundaryQueue.splice(0)) pending.reject(/* @__PURE__ */ new Error("Direct harness is disposed"));
1669
1710
  const failures = [];
1670
1711
  const attempt = async (cleanup) => {
1671
1712
  try {
@@ -2147,6 +2188,7 @@ async function createDirectHarnessRuntime(options) {
2147
2188
  return resources;
2148
2189
  },
2149
2190
  runExternalOperation,
2191
+ runAtToolBoundary,
2150
2192
  appendCustomEntry: async (customType, data) => {
2151
2193
  const lane = conversation;
2152
2194
  return String((await writable(() => lane.commit((tx) => tx.appendEntry(lane.id, {
@@ -2354,6 +2396,7 @@ async function createDirectHarnessRuntime(options) {
2354
2396
  } finally {
2355
2397
  settings = previous;
2356
2398
  compactionAdmission = false;
2399
+ if (!await nativeExecution()) await flushToolBoundary();
2357
2400
  }
2358
2401
  },
2359
2402
  async admitResume() {