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.
- package/dist/debugger.d.ts +9 -1
- package/dist/hypha-debugger.js +31 -29
- package/dist/hypha-debugger.js.map +1 -1
- package/dist/hypha-debugger.min.js +2 -2
- package/dist/hypha-debugger.min.js.map +1 -1
- package/dist/hypha-debugger.mjs +31 -29
- package/dist/hypha-debugger.mjs.map +1 -1
- package/package.json +1 -1
package/dist/hypha-debugger.mjs
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
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
|
-
|
|
5414
|
+
self.overlay?.addLog(`${name}: ${result.error}`, "error");
|
|
5422
5415
|
}
|
|
5423
5416
|
else {
|
|
5424
|
-
|
|
5417
|
+
self.overlay?.addLog(`${name} -> OK`, "result");
|
|
5425
5418
|
}
|
|
5426
5419
|
return result;
|
|
5427
5420
|
}
|
|
5428
5421
|
catch (err) {
|
|
5429
|
-
|
|
5422
|
+
self.overlay?.addLog(`${name}: ${err.message}`, "error");
|
|
5430
5423
|
throw err;
|
|
5431
5424
|
}
|
|
5432
5425
|
};
|
|
5433
|
-
|
|
5434
|
-
|
|
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
|
-
|
|
5436
|
+
if (schema)
|
|
5437
|
+
wrapper.__schema__ = schema;
|
|
5438
|
+
return wrapper;
|
|
5437
5439
|
}
|
|
5438
5440
|
summarizeArgs(args) {
|
|
5439
5441
|
if (args.length === 0)
|