hypha-rpc 0.20.68 → 0.20.69

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.
@@ -1583,52 +1583,22 @@ class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
1583
1583
  } else {
1584
1584
  args = [];
1585
1585
  }
1586
- let kwargs = {};
1587
- if (data.with_kwargs) {
1588
- kwargs = args.pop();
1589
- }
1590
-
1591
1586
  if (
1592
1587
  this._method_annotations.has(method) &&
1593
1588
  this._method_annotations.get(method).require_context
1594
1589
  ) {
1595
- // Create context from data.ctx if available, otherwise from default_context + message fields
1596
- let context = data.ctx;
1597
- if (!context) {
1598
- // For local service calls, create context from default_context and message fields
1599
- context = JSON.parse(JSON.stringify(this.default_context));
1600
- context.from = data.from;
1601
- context.to = data.to;
1602
- if (data.ws) context.ws = data.ws;
1603
- }
1604
-
1605
- // NEW JS-KWARGS PATTERN: Check if first argument has ._rkwargs=true
1606
- if (
1607
- args.length > 0 &&
1608
- args[0] &&
1609
- typeof args[0] === "object" &&
1610
- args[0]._rkwargs === true
1611
- ) {
1612
- // Inject context into the kwargs object instead of appending
1613
- args[0].context = context;
1614
- // Remove the _rkwargs flag as it's just for detection
1615
- delete args[0]._rkwargs;
1616
- } else if (data.with_kwargs) {
1617
- // Standard kwargs handling
1618
- kwargs.context = context;
1619
- } else {
1620
- // Backward compatibility: append context as last argument
1621
- // For functions expecting context, we need to inject context at the right position
1622
- // to avoid breaking parameter ordering when some parameters are optional
1623
- const expectedParams = method.length; // Number of parameters the function expects
1624
- if (expectedParams > 0 && args.length < expectedParams - 1) {
1625
- // Pad with undefined to ensure context goes to the right position
1626
- while (args.length < expectedParams - 1) {
1627
- args.push(undefined);
1628
- }
1590
+ // if args.length + 1 is less than the required number of arguments we will pad with undefined
1591
+ // so we make sure the last argument is the context
1592
+ if (args.length + 1 < method.length) {
1593
+ for (let i = args.length; i < method.length - 1; i++) {
1594
+ args.push(undefined);
1629
1595
  }
1630
- args.push(context);
1631
1596
  }
1597
+ args.push(data.ctx);
1598
+ (0,_utils_index_js__WEBPACK_IMPORTED_MODULE_0__.assert)(
1599
+ args.length === method.length,
1600
+ `Runtime Error: Invalid number of arguments for method ${method_name}, expected ${method.length} but got ${args.length}`,
1601
+ );
1632
1602
  }
1633
1603
  // console.debug(`Executing method: ${method_name} (${data.method})`);
1634
1604
  if (data.promise) {
@@ -1651,12 +1621,6 @@ class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
1651
1621
  method.apply(null, args);
1652
1622
  clearInterval(heartbeat_task);
1653
1623
  }
1654
- if (data.session) {
1655
- const session_store = this._get_session_store(data.session, false);
1656
- if (session_store) {
1657
- delete session_store.heartbeat_task;
1658
- }
1659
- }
1660
1624
  } catch (err) {
1661
1625
  if (reject) {
1662
1626
  reject(err);
@@ -1674,6 +1638,9 @@ class RPC extends _utils_index_js__WEBPACK_IMPORTED_MODULE_0__.MessageEmitter {
1674
1638
  }
1675
1639
 
1676
1640
  _get_session_store(session_id, create) {
1641
+ if (!session_id) {
1642
+ return null;
1643
+ }
1677
1644
  let store = this._object_store;
1678
1645
  const levels = session_id.split(".");
1679
1646
  if (create) {