Edit widgets in the code editor

Write or change a widget definition as JSON in the code editor: its states, functions and component tree, with validation and a live preview.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

The code editor shows a widget as a JSON definition. Use it when you want exact control, when you are copying a widget between agents or when the AI widget builder got you most of the way and you want to finish by hand. Changes in the editor and in the builder stay in sync.

Open the editor

  1. Open your agent and go to Actions > Widgets.
  2. Select a widget, or create one with Start from code.
  3. Open the Code tab. The preview stays on the right.

You should see the definition on the left and the rendered widget on the right. Edits update the preview after a short pause.

Structure of a definition

{
  "name": "order_tracker",
  "states": { "order": null, "status": "loading" },
  "onLoad": "load",
  "functions": {
    "load": [
      { "step": "callAction", "action": "act_lookup_order", "args": { "orderNumber": "{{context.orderNumber}}" }, "saveTo": "order" },
      { "step": "setState", "key": "status", "value": "ready" }
    ]
  },
  "components": [
    {
      "type": "card",
      "title": "Order {{states.order.number}}",
      "children": [
        { "type": "badge", "text": "{{states.order.status}}" },
        { "type": "timeline", "items": "{{states.order.events}}" }
      ]
    }
  ]
}
Key Description
name A stable identifier in lowercase with underscores.
states Named values and their starting values. See States.
functions Named lists of steps. See Functions.
onLoad The function to run when the widget first appears.
components The tree of components that makes up the layout.

Each component has a type and its own properties. Containers such as card and stack hold other components in children.

Bindings

Text in double curly braces is replaced with live values.

Binding Value
{{states.name}} The current value of a state.
{{context.key}} A value the agent passed when it showed the widget, or a value set with setContext.
{{event.value}} The value from the input or button that triggered a function.
{{item.key}} The current item inside the itemTemplate of a list.

Validate and save

The editor checks the definition while you type. Problems appear under the code with a line number, such as an unknown component type or a function name that does not exist. Fix them, then select Save.

Tip: Keep component trees shallow. Prefer a stack of a few card components to many nested containers. Shallow definitions are easier to read and to hand back to the AI builder.

Component references

Something unclear or missing? Tell us and we will fix the page.