Parallax

App commands

Register named commands in your app that an agent can list and run, such as resetting state or jumping to a screen.

A command is a function in your app that you give a name. The agent lists the commands with app_commands and runs one with app_command_run. Use them for development shortcuts: reset a store, sign in a test user, open a deep screen.

Register a command

if (__DEV__) {
  const { registerCommand } = require('@parallax-rn/sdk');

  registerCommand(
    'cart.fill',
    async ({ items }) => {
      store.dispatch(fillCart(items));
      return { count: items };
    },
    { description: 'Put test items in the cart', argsHint: '{ items: number }' },
  );
}
  • registerCommand(name, handler, { description, argsHint }) returns a function that unregisters it.
  • Registering the same name again replaces it, so Fast Refresh is safe.
  • The handler gets the arguments the agent passed (JSON) and may be async. Its return value must be JSON-serializable; undefined becomes null.
  • description and argsHint (a short description of the arguments) are shown to the agent.
  • The SDK has one built-in command, parallax.ping.

What the agent does

app_commands
  1 command registered.
  cart.fill — Put test items in the cart (args: { items: number })

app_command_run { name: "cart.fill", args: { items: 3 } }
  Command "cart.fill" ran. Result:
  { "count": 3 }

app_command_run takes an optional timeout_ms. It can change app data, so it counts as an acting tool: it needs your approval in strict mode, and the agent's own prompt applies otherwise. If the name is unknown the answer is command_not_found ("List the registered commands with app_commands"). If the handler throws or its result is not JSON, it is command_failed with the message. In an app with two simulators, pass device.

On this page