hypha-rpc 0.21.22 → 0.21.24

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.
@@ -86,7 +86,7 @@
86
86
  <div class='footer quiet pad2 space-top1 center small'>
87
87
  Code coverage generated by
88
88
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
89
- at 2026-02-25T19:07:57.766Z
89
+ at 2026-02-26T10:31:13.151Z
90
90
  </div>
91
91
  <script src="prettify.js"></script>
92
92
  <script>
@@ -10434,18 +10434,19 @@ class WebsocketRPCConnection {
10434
10434
  }
10435
10435
 
10436
10436
  // Log specific error types for better debugging
10437
- if (e.name === "NetworkError" || e.message.includes("network")) {
10438
- console.error(`Network error during reconnection: ${e.message}`);
10437
+ // Convert to string first to safely handle non-standard error objects
10438
+ const errStr = `${e}`;
10439
+ if (errStr.includes("NetworkError") || errStr.includes("network")) {
10440
+ console.error(`Network error during reconnection: ${errStr}`);
10439
10441
  } else if (
10440
- e.name === "TimeoutError" ||
10441
- e.message.includes("timeout")
10442
+ errStr.includes("TimeoutError") || errStr.includes("timeout")
10442
10443
  ) {
10443
10444
  console.error(
10444
- `Connection timeout during reconnection: ${e.message}`,
10445
+ `Connection timeout during reconnection: ${errStr}`,
10445
10446
  );
10446
10447
  } else {
10447
10448
  console.error(
10448
- `Unexpected error during reconnection: ${e.message}`,
10449
+ `Unexpected error during reconnection: ${errStr}`,
10449
10450
  );
10450
10451
  }
10451
10452
 
@@ -10808,6 +10809,43 @@ async function connectToServer(config) {
10808
10809
  });
10809
10810
  wm.rpc = rpc;
10810
10811
 
10812
+ // Auto-refresh workspace manager proxy after reconnection.
10813
+ // When the server restarts, it assigns a new manager_id. The RPC layer
10814
+ // internally uses the updated manager_id for service re-registration
10815
+ // (in the onConnected callback), but the wm proxy returned to the caller
10816
+ // still has methods bound to the old manager_id. This listener refreshes
10817
+ // the wm proxy methods so they target the new manager_id.
10818
+ let isInitialRegistration = true;
10819
+ rpc.on("services_registered", async () => {
10820
+ if (isInitialRegistration) {
10821
+ isInitialRegistration = false;
10822
+ return; // Skip the first event (initial connection, wm is already fresh)
10823
+ }
10824
+ try {
10825
+ const freshWm = await rpc.get_manager_service({
10826
+ timeout: config.method_timeout || 30,
10827
+ case_conversion: "camel",
10828
+ kwargs_expansion: config.kwargs_expansion || false,
10829
+ });
10830
+ // Copy all function properties from fresh wm onto existing wm object.
10831
+ // This preserves the caller's reference while updating method targets.
10832
+ for (const key of Object.keys(freshWm)) {
10833
+ if (typeof freshWm[key] === "function") {
10834
+ wm[key] = freshWm[key];
10835
+ }
10836
+ }
10837
+ console.info(
10838
+ "Workspace manager proxy refreshed after reconnection (new manager_id:",
10839
+ rpc._connection?.manager_id + ")",
10840
+ );
10841
+ } catch (err) {
10842
+ console.warn(
10843
+ "Failed to refresh workspace manager after reconnection:",
10844
+ err,
10845
+ );
10846
+ }
10847
+ });
10848
+
10811
10849
  async function _export(api) {
10812
10850
  api.id = "default";
10813
10851
  api.name = api.name || config.name || api.id;