@swmansion/argent 0.14.1-next.5 → 0.14.1-next.6

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.
@@ -15716,14 +15716,27 @@ var init_registry = __esm({
15716
15716
  effectiveParams = parsed.data;
15717
15717
  }
15718
15718
  const aliasToRef = definition.services(effectiveParams);
15719
- const resolvedServices = {};
15720
- for (const [alias, ref] of Object.entries(aliasToRef)) {
15721
- const urn = typeof ref === "string" ? ref : ref.urn;
15722
- const resolveOptions = typeof ref === "string" ? void 0 : ref.options;
15723
- resolvedServices[alias] = await this.resolveService(urn, resolveOptions);
15724
- }
15719
+ const refs = Object.entries(aliasToRef).map(([alias, ref]) => ({
15720
+ alias,
15721
+ urn: typeof ref === "string" ? ref : ref.urn,
15722
+ options: typeof ref === "string" ? void 0 : ref.options
15723
+ }));
15725
15724
  const ctx = { ...options, artifacts: this.artifacts };
15726
- const result = await definition.execute(resolvedServices, effectiveParams, ctx);
15725
+ const runOnce = async () => {
15726
+ const resolvedServices = {};
15727
+ for (const { alias, urn, options: resolveOptions } of refs) {
15728
+ resolvedServices[alias] = await this.resolveService(urn, resolveOptions);
15729
+ }
15730
+ return definition.execute(resolvedServices, effectiveParams, ctx);
15731
+ };
15732
+ let result;
15733
+ try {
15734
+ result = await runOnce();
15735
+ } catch (execError) {
15736
+ const recovered = await this._recoverFailedServices(refs, execError);
15737
+ if (!recovered) throw execError;
15738
+ result = await runOnce();
15739
+ }
15727
15740
  const duration3 = performance.now() - startTime;
15728
15741
  this.events.emit("toolCompleted", id, toolInvocationId, duration3);
15729
15742
  return result;
@@ -15763,6 +15776,30 @@ var init_registry = __esm({
15763
15776
  tools: [...this.tools.keys()]
15764
15777
  };
15765
15778
  }
15779
+ /**
15780
+ * After a tool failed, ask each service it resolved whether the error means
15781
+ * that service's instance is dead (`blueprint.recoverable(error)`). Dispose
15782
+ * every one that says yes so the next `resolveService` re-creates it, and
15783
+ * report whether anything was disposed (i.e. whether a retry is worthwhile).
15784
+ *
15785
+ * Only currently-RUNNING nodes are considered: a service that already
15786
+ * errored/torn down during resolution needs no recovery here, and a URN this
15787
+ * tool never resolved must not be touched.
15788
+ */
15789
+ async _recoverFailedServices(refs, error52) {
15790
+ let recoveredAny = false;
15791
+ for (const { urn } of refs) {
15792
+ const node = this.services.get(urn);
15793
+ if (!node || node.state !== "RUNNING" /* RUNNING */) continue;
15794
+ if (node.blueprint.recoverable?.(error52) !== true) continue;
15795
+ try {
15796
+ await this.disposeService(urn);
15797
+ recoveredAny = true;
15798
+ } catch {
15799
+ }
15800
+ }
15801
+ return recoveredAny;
15802
+ }
15766
15803
  /**
15767
15804
  * Tear down a single service by URN (and cascade to its dependents).
15768
15805
  * After disposal the service returns to IDLE and can be re-resolved.
@@ -109737,6 +109774,26 @@ var simulatorServerBlueprint = {
109737
109774
  getURN(device) {
109738
109775
  return `${SIMULATOR_SERVER_NAMESPACE}:${device.id}`;
109739
109776
  },
109777
+ /**
109778
+ * A cached simulator-server handle can outlive the thing it points at: when a
109779
+ * simulator is un-booted (or the native server crashes) the child process may
109780
+ * stay alive but stop listening on its API port, so every subsequent request
109781
+ * fails with `ECONNREFUSED` against the now-dead port — the exact "worked once,
109782
+ * then every call times out" symptom, unrecoverable until a human runs
109783
+ * `stop-simulator-server`. The process never emitting `exit` means the
109784
+ * registry's normal teardown (wired to `proc.on("exit")`) never fires.
109785
+ *
109786
+ * Treat a connection-refused failure as proof the instance is dead so the
109787
+ * registry disposes it (killing the wedged process) and re-spawns a fresh
109788
+ * simulator-server on the next call. Scoped to connection-refused only:
109789
+ * ECONNREFUSED means the request never reached the server, so retrying can't
109790
+ * double-apply a gesture. Timeouts and resets are deliberately excluded — the
109791
+ * request there may have taken effect, and a hung-but-listening server is a
109792
+ * different failure that respawning wouldn't fix.
109793
+ */
109794
+ recoverable(error52) {
109795
+ return getFailureSignal(error52)?.network_failure === "connection_refused";
109796
+ },
109740
109797
  async factory(_deps, _payload, options) {
109741
109798
  const opts = options;
109742
109799
  if (!opts?.device) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/argent",
3
- "version": "0.14.1-next.5",
3
+ "version": "0.14.1-next.6",
4
4
  "description": "MCP server for iOS Simulator and Android Emulator control",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {