hypha-rpc 0.20.77 → 0.20.79

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.
@@ -966,7 +966,23 @@ class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
966
966
  config.workspace =
967
967
  config.workspace || this._local_workspace || this._connection.workspace;
968
968
  const skipContext = config.require_context;
969
- const serviceSchema = _get_schema(service, null, skipContext);
969
+ const excludeKeys = [
970
+ "id",
971
+ "config",
972
+ "name",
973
+ "description",
974
+ "type",
975
+ "docs",
976
+ "app_id",
977
+ "service_schema",
978
+ ];
979
+ const filteredService = {};
980
+ for (const key of Object.keys(service)) {
981
+ if (!excludeKeys.includes(key)) {
982
+ filteredService[key] = service[key];
983
+ }
984
+ }
985
+ const serviceSchema = _get_schema(filteredService, null, skipContext);
970
986
  const serviceInfo = {
971
987
  config: config,
972
988
  id: `${config.workspace}/${this._client_id}:${service["id"]}`,
@@ -1645,10 +1661,26 @@ class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
1645
1661
  // I.e. the session id won't be passed for promises themselves
1646
1662
  main_message["session"] = local_session_id;
1647
1663
  let method_name = `${target_id}:${method_id}`;
1664
+
1665
+ // Create a timer that gets reset by heartbeat
1666
+ // Methods can run indefinitely as long as heartbeat keeps resetting the timer
1667
+ // IMPORTANT: When timeout occurs, we must clean up the session to prevent memory leaks
1668
+ const timeoutCallback = function (error_msg) {
1669
+ // First reject the promise
1670
+ reject(error_msg);
1671
+ // Then clean up the entire session to stop all callbacks
1672
+ if (self._object_store[local_session_id]) {
1673
+ delete self._object_store[local_session_id];
1674
+ console.debug(
1675
+ `Cleaned up session ${local_session_id} after timeout`,
1676
+ );
1677
+ }
1678
+ };
1679
+
1648
1680
  timer = new Timer(
1649
1681
  self._method_timeout,
1650
- reject,
1651
- [`Method call time out: ${method_name}, context: ${description}`],
1682
+ timeoutCallback,
1683
+ [`Method call timed out: ${method_name}, context: ${description}`],
1652
1684
  method_name,
1653
1685
  );
1654
1686
  // By default, hypha will clear the session after the method is called
@@ -1705,8 +1737,8 @@ class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
1705
1737
  ._emit_message(message_package)
1706
1738
  .then(function () {
1707
1739
  if (timer) {
1708
- // If resolved successfully, reset the timer
1709
- timer.reset();
1740
+ // Start the timer after message is sent successfully
1741
+ timer.start();
1710
1742
  }
1711
1743
  })
1712
1744
  .catch(function (err) {
@@ -1727,8 +1759,8 @@ class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
1727
1759
  ._send_chunks(message_package, target_id, remote_parent)
1728
1760
  .then(function () {
1729
1761
  if (timer) {
1730
- // If resolved successfully, reset the timer
1731
- timer.reset();
1762
+ // Start the timer after message is sent successfully
1763
+ timer.start();
1732
1764
  }
1733
1765
  })
1734
1766
  .catch(function (err) {
@@ -1990,10 +2022,10 @@ class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
1990
2022
  }
1991
2023
  }
1992
2024
  args.push(data.ctx);
1993
- (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
1994
- args.length === method.length,
1995
- `Runtime Error: Invalid number of arguments for method ${method_name}, expected ${method.length} but got ${args.length}`,
1996
- );
2025
+ // assert(
2026
+ // args.length === method.length,
2027
+ // `Runtime Error: Invalid number of arguments for method ${method_name}, expected ${method.length} but got ${args.length}`,
2028
+ // );
1997
2029
  }
1998
2030
  // console.debug(`Executing method: ${method_name} (${data.method})`);
1999
2031
  if (data.promise) {
@@ -5656,6 +5688,7 @@ class WebsocketRPCConnection {
5656
5688
  timeout = 60,
5657
5689
  WebSocketClass = null,
5658
5690
  token_refresh_interval = 2 * 60 * 60,
5691
+ additional_headers = null,
5659
5692
  ) {
5660
5693
  (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(server_url && client_id, "server_url and client_id are required");
5661
5694
  this._server_url = server_url;
@@ -5678,6 +5711,7 @@ class WebsocketRPCConnection {
5678
5711
  this._refresh_token_task = null;
5679
5712
  this._last_message = null; // Store the last sent message
5680
5713
  this._reconnect_timeouts = new Set(); // Track reconnection timeouts
5714
+ this._additional_headers = additional_headers;
5681
5715
  }
5682
5716
 
5683
5717
  /**
@@ -6116,10 +6150,12 @@ async function login(config) {
6116
6150
  const timeout = config.login_timeout || 60;
6117
6151
  const callback = config.login_callback;
6118
6152
  const profile = config.profile;
6153
+ const additional_headers = config.additional_headers;
6119
6154
 
6120
6155
  const server = await connectToServer({
6121
6156
  name: "initial login client",
6122
6157
  server_url: config.server_url,
6158
+ additional_headers: additional_headers,
6123
6159
  });
6124
6160
  try {
6125
6161
  const svc = await server.getService(service_id);
@@ -6222,6 +6258,8 @@ async function connectToServer(config) {
6222
6258
  config.reconnection_token,
6223
6259
  config.method_timeout || 60,
6224
6260
  config.WebSocketClass,
6261
+ config.token_refresh_interval,
6262
+ config.additional_headers,
6225
6263
  );
6226
6264
  const connection_info = await connection.open();
6227
6265
  (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_1__.assert)(