hypha-debugger 0.1.2 → 0.1.3

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.
@@ -65,7 +65,15 @@ export declare class HyphaDebugger {
65
65
  private createGetSkillMd;
66
66
  /** Build the instruction block for the overlay panel. */
67
67
  private buildInstructionBlock;
68
- /** Wrap a service function with logging and kwargs-to-positional-args support. */
68
+ /**
69
+ * Wrap a service function with logging and correct parameter names.
70
+ *
71
+ * Uses new Function() to create a wrapper whose parameter names match
72
+ * the __schema__ property names. This is critical for production builds
73
+ * where Babel/Terser minifies parameter names — hypha-rpc's
74
+ * getParamNames() parses Function.toString() to map kwargs to positional
75
+ * args, so the wrapper must have the real (unminified) parameter names.
76
+ */
69
77
  private wrapFn;
70
78
  private summarizeArgs;
71
79
  }
@@ -13847,50 +13847,52 @@
13847
13847
  lines.push(``, `# 1. Get interactive elements (smart DOM analysis with indexed elements):`, `curl "$SERVICE_URL/get_browser_state"${auth}`, ``, `# 2. Click element by index (e.g. click [3]):`, `curl -X POST "$SERVICE_URL/click_element_by_index"${auth} -H "Content-Type: application/json" -d '{"index": 3}'`, ``, `# 3. Type into an input by index:`, `curl -X POST "$SERVICE_URL/input_text"${auth} -H "Content-Type: application/json" -d '{"index": 5, "text": "hello"}'`, ``, `# Take a screenshot:`, `curl "$SERVICE_URL/take_screenshot"${auth}`, ``, `# Execute JavaScript remotely:`, `curl -X POST "$SERVICE_URL/execute_script"${auth} -H "Content-Type: application/json" -d '{"code": "document.title"}'`, ``, `# Full API docs:`, `curl "$SERVICE_URL/get_skill_md"${auth}`);
13848
13848
  return lines.join("\n");
13849
13849
  }
13850
- /** Wrap a service function with logging and kwargs-to-positional-args support. */
13850
+ /**
13851
+ * Wrap a service function with logging and correct parameter names.
13852
+ *
13853
+ * Uses new Function() to create a wrapper whose parameter names match
13854
+ * the __schema__ property names. This is critical for production builds
13855
+ * where Babel/Terser minifies parameter names — hypha-rpc's
13856
+ * getParamNames() parses Function.toString() to map kwargs to positional
13857
+ * args, so the wrapper must have the real (unminified) parameter names.
13858
+ */
13851
13859
  wrapFn(fn, name) {
13852
- const wrapped = async (...args) => {
13853
- // Hypha's HTTP API calls with keyword arguments (**kwargs),
13854
- // which arrive on the JS side as a single object argument.
13855
- // Destructure into positional args based on schema properties.
13856
- if (args.length === 1 &&
13857
- args[0] &&
13858
- typeof args[0] === "object" &&
13859
- !Array.isArray(args[0]) &&
13860
- fn.__schema__?.parameters?.properties) {
13861
- const kwargs = args[0];
13862
- const props = fn.__schema__.parameters.properties;
13863
- const paramNames = Object.keys(props);
13864
- // Check if any kwargs key matches a schema property name
13865
- const hasMatchingKey = paramNames.some((p) => p in kwargs);
13866
- if (hasMatchingKey) {
13867
- args = paramNames.map((p) => kwargs[p]);
13868
- while (args.length > 0 && args[args.length - 1] === undefined) {
13869
- args.pop();
13870
- }
13871
- }
13872
- }
13873
- this.overlay?.addLog(`${name}(${this.summarizeArgs(args)})`, "call");
13860
+ const schema = fn.__schema__;
13861
+ const paramNames = schema?.parameters?.properties
13862
+ ? Object.keys(schema.parameters.properties)
13863
+ : [];
13864
+ const self = this;
13865
+ const callAndLog = async (args) => {
13866
+ self.overlay?.addLog(`${name}(${self.summarizeArgs(args)})`, "call");
13874
13867
  try {
13875
13868
  const result = await fn(...args);
13876
13869
  const hasError = result && typeof result === "object" && "error" in result;
13877
13870
  if (hasError) {
13878
- this.overlay?.addLog(`${name}: ${result.error}`, "error");
13871
+ self.overlay?.addLog(`${name}: ${result.error}`, "error");
13879
13872
  }
13880
13873
  else {
13881
- this.overlay?.addLog(`${name} -> OK`, "result");
13874
+ self.overlay?.addLog(`${name} -> OK`, "result");
13882
13875
  }
13883
13876
  return result;
13884
13877
  }
13885
13878
  catch (err) {
13886
- this.overlay?.addLog(`${name}: ${err.message}`, "error");
13879
+ self.overlay?.addLog(`${name}: ${err.message}`, "error");
13887
13880
  throw err;
13888
13881
  }
13889
13882
  };
13890
- if (fn.__schema__) {
13891
- wrapped.__schema__ = fn.__schema__;
13883
+ let wrapper;
13884
+ if (paramNames.length === 0) {
13885
+ wrapper = async (...args) => callAndLog(args);
13892
13886
  }
13893
- return wrapped;
13887
+ else {
13888
+ // Create a function with explicit, unminified parameter names so
13889
+ // hypha-rpc can parse them from Function.toString().
13890
+ const paramList = paramNames.join(", ");
13891
+ wrapper = new Function("callAndLog", `return async function(${paramList}) { return callAndLog([${paramList}]); }`)(callAndLog);
13892
+ }
13893
+ if (schema)
13894
+ wrapper.__schema__ = schema;
13895
+ return wrapper;
13894
13896
  }
13895
13897
  summarizeArgs(args) {
13896
13898
  if (args.length === 0)