Skip to content

Fix callModularTool to pass positional args to API methods#5

Open
issmirnov wants to merge 1 commit into
Pixelworlds:masterfrom
issmirnov:fix/callModularTool-positional-args
Open

Fix callModularTool to pass positional args to API methods#5
issmirnov wants to merge 1 commit into
Pixelworlds:masterfrom
issmirnov:fix/callModularTool-positional-args

Conversation

@issmirnov

Copy link
Copy Markdown

Summary

  • Bug: callModularTool merges all params into a single object and passes it as the sole argument to API client methods. Methods like settingsSetHost(uuid, data, config) expect uuid as the first positional arg and data as the second. The current code causes the URL to become /api/dnsmasq/settings/set_host/[object Object] and the POST body to be undefined.
  • Fix: Introspect each method's parameter names via Function.toString() and pass arguments positionally. Named params like uuid and enabled are extracted from the merged params object and passed as leading positional args, with remaining data passed as the data argument.
  • Handles all four API method signature patterns: (config), (data, config), (uuid, data, config), and (uuid, enabled, data, config).

Details

The previous code:

const { method: _, params = {}, ...otherArgs } = args;
const callParams = { ...params, ...otherArgs };
return await method.call(moduleObj, callParams);

The fix parses parameter names from the method source and builds positional args:

const methodSource = method.toString();
const paramMatch = methodSource.match(/^async\s+\w+\(([^)]*)\)/);
const paramNames = paramMatch
  ? paramMatch[1].split(',').map(p => p.trim()).filter(Boolean)
  : [];

const positionalNames = paramNames.filter(p => p !== 'config' && p !== 'data');
const positionalArgs = positionalNames.map(name => {
  const val = callParams[name];
  delete callParams[name];
  return val;
});

// Pass remaining params as data if the method accepts it
if (hasDataParam && Object.keys(callParams).length > 0) {
  positionalArgs.push(callParams);
}
return await method.call(moduleObj, ...positionalArgs);

Test plan

  • Verify settingsSetHost with uuid correctly produces URL /api/dnsmasq/settings/set_host/<uuid> with POST body
  • Verify settingsToggleZone with uuid and enabled correctly produces URL with both path params
  • Verify settingsGet (no params) still works
  • Verify settingsAddHost (data only) still works

🤖 Generated with Claude Code

The callModularTool function was merging all params into a single object
and passing it as the first argument to API client methods. This broke
methods like settingsSetHost(uuid, data, config) because the URL became
`/api/dnsmasq/settings/set_host/[object Object]` and the POST body was
undefined.

The fix introspects each method's parameter names via Function.toString()
and passes arguments positionally: named params like `uuid` and `enabled`
are extracted and passed as leading positional args, with remaining data
passed as the `data` argument. This correctly handles all API method
signatures: (config), (data, config), (uuid, data, config), and
(uuid, enabled, data, config).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant