Skip to content

Let whoever manages a Bot change its Agent URL on Setup - #1899

Open
davidmckayv wants to merge 2 commits into
mainfrom
fix/edit-agent-url
Open

davidmckayv wants to merge 2 commits into
mainfrom
fix/edit-agent-url

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

What

A Bot that runs at an address of its own showed its Agent URL on Setup as a plain value, with no way to change it. The page says it edits the Bot's runtime settings, and the update API already takes a new endpoint, so only the screen was missing. Moving a Bot to a new address meant deleting it and making it again.

The Agent URL row now has a chevron and opens the same dialog as the Identity rows above it. This applies to whoever manages a Bot that runs at its own address.

  • Checked before it is sent. The address must be an http:// or https:// web address, the same check the New Bot sheet uses (agentFormSchema.shape.endpoint). An empty field is refused too: an empty endpoint on a change leaves the stored one as it is, so saving one would look done and change nothing.
  • The server's refusal shows in the dialog. If the deployment won't reach an address, the server's own sentence shows under the field. The field is marked aria-invalid and described by that sentence, it gets focus again, and the dialog stays open with what was typed.
  • Saving the same address back sends nothing.
  • Who sees what. The row stays read-only (no chevron, nothing to click) for anyone who can't manage the Bot. A built-in Bot ("Built in") is unchanged.
  • The field uses the URL keyboard and monospace, like the row, and has no autocorrect. The dialog has one help line: "This Bot’s replies come from the agent at this address."

The stored address no longer rides along on other edits

Before this, every other Setup edit (name, title, what it does, visibility, Isolated) sent the Bot's stored endpoint back in the full update body. The route checks any endpoint it is sent as one somebody typed, using the deployment's rules as they are today. So a Bot saved at an address the rules have since closed could not be renamed. That is the case profileUpdateInput's comment already described for a built-in Bot's managed address. profileUpdateInput now sends an empty endpoint unless the patch changes it. Per the spec (BotEndpoint), empty on a change leaves the stored address as it is.

The dialog body scrolls, so it was clipping the top and bottom of the field's focus ring, and now of the red ring an error adds. Every Identity dialog had this too. The body now has 4px of padding above and below, and its margins are 4px smaller, so the spacing is the same as before.

Best practice

  • Validate on Save, not while typing, and show the error under the field. A partly typed address is not an error (Deque, WebAIM).
  • Set aria-invalid and aria-describedby only while the error shows, so a screen reader reads the error with the field. Remove both once the field is valid (Chrome guidance, Mass.gov).
  • Move focus back to the field that needs fixing (WebAIM).

Tests

app/tests/bot-setup-agent-url.test.tsx draws the Setup sections from the Bot the server returns. It serves them the spec's generated MSW handlers at the API's addresses: the PATCH keeps what it was sent, and the GET returns it. A private address is refused with the server's own problem details and sentence. The tests:

  1. change the Agent URL. One PATCH is sent with the new endpoint and no key, and the row then shows the address the server returned
  2. a refused address shows the server's sentence in the dialog, with the field marked invalid and described by it, and the Bot keeps its address
  3. a value that isn't a web address, or an empty one, is refused before anything is sent
  4. the same address saved back sends nothing
  5. the row is read-only to someone who can't manage the Bot, and Built in has nothing to click
  6. renaming a Bot whose stored address the rules now refuse sends an empty endpoint and succeeds

On main, 1 to 4 fail (there is no Agent URL button) and 6 fails (the rename sends the stored address and is refused). 5 passes on main and stays as a guard. With the change, all 6 pass. The full app suite passes: 4335 pass, 339 skip, 0 fail. The app typechecks, and biome and the copy guard tests pass.

In the real product

I ran OpenBot from this branch against a local backend at the current RC, with two small AG-UI agents on 127.0.0.1:4801 and :4802. The deployment's allowed hosts named only those two. I created "Sales Assistant" at :4801.

In headless Chromium and headless WebKit, in light and dark:

  • I opened Setup and changed the Agent URL to :4802. One PATCH was sent with "endpoint":"http://127.0.0.1:4802/ag-ui", and after a reload the server returned :4802.
  • A new conversation was answered "Reply from agent B, at port 4802."
  • :4803 was refused in the dialog: "That address is inside OpenBot's own network, so an agent may not live there."
  • agents.example.com/ag-ui was refused before sending.

Setup before, Chromium light, and after, WebKit dark:

The dialog with the new address, and the server's refusal (Chromium light, WebKit dark):

Not a web address (Chromium dark, WebKit light), and the Bot answering from its new address:

The Agent URL row on a Bot's Setup page was a plain value: nobody could move a Bot to a new address without deleting it and making it again, though the page says it edits the Bot's runtime settings and the update API already took a new endpoint.

The row now opens the same dialog as the Identity rows, for whoever manages a Bot that runs at an address of its own. The address is checked for shape before it is sent, and the server's refusal (an address the deployment won't reach, say) shows under the field, which is marked invalid while it does. Saving the same address back sends nothing. The row stays read-only for anyone who can't manage the Bot, and a built-in Bot is unchanged.

Every other edit on Setup stops sending the stored address. The route checks any endpoint it is sent as one somebody typed, so a Bot saved at an address the deployment's rules have since closed could not be renamed. An empty endpoint leaves the stored one as it is.
The dialog body scrolls, so it clipped the top and bottom of the field's focus ring and of the red ring an error gives it. The body has 4px of padding above and below, and its margins are 4px less, so the gaps stay as they were.

This branch has not been deployed

No deployments
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