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.
@@ -5390,50 +5390,52 @@ class HyphaDebugger {
5390
5390
  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}`);
5391
5391
  return lines.join("\n");
5392
5392
  }
5393
- /** Wrap a service function with logging and kwargs-to-positional-args support. */
5393
+ /**
5394
+ * Wrap a service function with logging and correct parameter names.
5395
+ *
5396
+ * Uses new Function() to create a wrapper whose parameter names match
5397
+ * the __schema__ property names. This is critical for production builds
5398
+ * where Babel/Terser minifies parameter names — hypha-rpc's
5399
+ * getParamNames() parses Function.toString() to map kwargs to positional
5400
+ * args, so the wrapper must have the real (unminified) parameter names.
5401
+ */
5394
5402
  wrapFn(fn, name) {
5395
- const wrapped = async (...args) => {
5396
- // Hypha's HTTP API calls with keyword arguments (**kwargs),
5397
- // which arrive on the JS side as a single object argument.
5398
- // Destructure into positional args based on schema properties.
5399
- if (args.length === 1 &&
5400
- args[0] &&
5401
- typeof args[0] === "object" &&
5402
- !Array.isArray(args[0]) &&
5403
- fn.__schema__?.parameters?.properties) {
5404
- const kwargs = args[0];
5405
- const props = fn.__schema__.parameters.properties;
5406
- const paramNames = Object.keys(props);
5407
- // Check if any kwargs key matches a schema property name
5408
- const hasMatchingKey = paramNames.some((p) => p in kwargs);
5409
- if (hasMatchingKey) {
5410
- args = paramNames.map((p) => kwargs[p]);
5411
- while (args.length > 0 && args[args.length - 1] === undefined) {
5412
- args.pop();
5413
- }
5414
- }
5415
- }
5416
- this.overlay?.addLog(`${name}(${this.summarizeArgs(args)})`, "call");
5403
+ const schema = fn.__schema__;
5404
+ const paramNames = schema?.parameters?.properties
5405
+ ? Object.keys(schema.parameters.properties)
5406
+ : [];
5407
+ const self = this;
5408
+ const callAndLog = async (args) => {
5409
+ self.overlay?.addLog(`${name}(${self.summarizeArgs(args)})`, "call");
5417
5410
  try {
5418
5411
  const result = await fn(...args);
5419
5412
  const hasError = result && typeof result === "object" && "error" in result;
5420
5413
  if (hasError) {
5421
- this.overlay?.addLog(`${name}: ${result.error}`, "error");
5414
+ self.overlay?.addLog(`${name}: ${result.error}`, "error");
5422
5415
  }
5423
5416
  else {
5424
- this.overlay?.addLog(`${name} -> OK`, "result");
5417
+ self.overlay?.addLog(`${name} -> OK`, "result");
5425
5418
  }
5426
5419
  return result;
5427
5420
  }
5428
5421
  catch (err) {
5429
- this.overlay?.addLog(`${name}: ${err.message}`, "error");
5422
+ self.overlay?.addLog(`${name}: ${err.message}`, "error");
5430
5423
  throw err;
5431
5424
  }
5432
5425
  };
5433
- if (fn.__schema__) {
5434
- wrapped.__schema__ = fn.__schema__;
5426
+ let wrapper;
5427
+ if (paramNames.length === 0) {
5428
+ wrapper = async (...args) => callAndLog(args);
5429
+ }
5430
+ else {
5431
+ // Create a function with explicit, unminified parameter names so
5432
+ // hypha-rpc can parse them from Function.toString().
5433
+ const paramList = paramNames.join(", ");
5434
+ wrapper = new Function("callAndLog", `return async function(${paramList}) { return callAndLog([${paramList}]); }`)(callAndLog);
5435
5435
  }
5436
- return wrapped;
5436
+ if (schema)
5437
+ wrapper.__schema__ = schema;
5438
+ return wrapper;
5437
5439
  }
5438
5440
  summarizeArgs(args) {
5439
5441
  if (args.length === 0)