hypha-debugger 0.1.7 → 0.1.8

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.
@@ -2802,6 +2802,10 @@ function generateSkillMd(serviceFunctions, serviceUrl) {
2802
2802
  * This helper uses new Function() to create a wrapper whose parameter names
2803
2803
  * are taken from the function's __schema__ property, so hypha-rpc always sees
2804
2804
  * the real parameter names regardless of minification.
2805
+ *
2806
+ * Additionally, it handles the case where hypha-rpc passes kwargs as a single
2807
+ * object argument (e.g. `fn({url: "..."})` instead of `fn("...")`). The
2808
+ * wrapper detects this and destructures the kwargs object automatically.
2805
2809
  */
2806
2810
  function wrapFn(fn) {
2807
2811
  const schema = fn.__schema__;
@@ -2811,8 +2815,23 @@ function wrapFn(fn) {
2811
2815
  if (paramNames.length === 0) {
2812
2816
  return fn;
2813
2817
  }
2818
+ // Create a wrapper that:
2819
+ // 1. Has correct, unminified parameter names (for hypha-rpc getParamNames)
2820
+ // 2. Detects when kwargs are passed as a single object and destructures them
2814
2821
  const paramList = paramNames.join(", ");
2815
- const wrapper = new Function("fn", `return async function(${paramList}) { return fn(${paramList}); }`)(fn);
2822
+ const wrapper = new Function("fn", "paramNames", `return async function(${paramList}) {
2823
+ // Detect kwargs-as-object: single argument that is a plain object
2824
+ // whose keys match schema parameter names
2825
+ if (arguments.length === 1 && ${paramList} != null && typeof ${paramList} === "object" && !Array.isArray(${paramList}) && !(${paramList} instanceof Date)) {
2826
+ var _kw = ${paramList};
2827
+ var _firstKey = Object.keys(_kw)[0];
2828
+ if (_firstKey && paramNames.indexOf(_firstKey) !== -1) {
2829
+ var _args = paramNames.map(function(n) { return _kw[n]; });
2830
+ return fn.apply(null, _args);
2831
+ }
2832
+ }
2833
+ return fn(${paramList});
2834
+ }`)(fn, paramNames);
2816
2835
  if (schema)
2817
2836
  wrapper.__schema__ = schema;
2818
2837
  return wrapper;