Repository navigation
feat(composables): add agent bridge for form controls - #32
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AI agents currently drive
@antfu/designUIs the slow way: they take screenshots or walk the accessibility tree, then click and type. This PR adds an opt-in agent bridge, so an agent can read control state and call control actions directly. The idea comes from UI SDK. In their benchmark, a bridge like this cut tool calls from 17 to 7 and tokens by about 4x, compared with accessibility-tree browser tools.createAgent({ allow? })creates a bridge. Install it withapp.use(agent), or scope it to a subtree withprovideAgent(agent).agent.snapshot()returns{ ref, component, label, value, disabled?, options?, actions }for each registered control.agent.act({ steps: [{ ref, action, args }] })runs the steps in order and stops at the first failure. It returns per-step results and a fresh snapshot. A step'srefcan be a control ref (c1) or its exact label.agent.tools()returnsui_snapshot/ui_acttool definitions, so the bridge can be registered with WebMCP or passed to any agent SDK.Actions go through each component's own
v-model. As a result, an agent can only do what a user can:FormNumberInputclamps tomin/max, andincrement/decrementuse the samestepByas the stepper buttons.Each step also goes through the app's
allow(step, control)guard. While a step runs,getChangeSource()returns'agent', so an update handler can tell agent changes from user changes.If no bridge is installed,
useAgentControlreturns right afterinjectand registers nothing.Change map
composables/agent.ts(new)createAgent,provideAgent,useAgentControl,getChangeSource,assertAgentOption,provideAgentFieldLabelLayoutTabsFormTextInput,FormTextarea,FormNumberInput,FormSelect,FormCombobox,FormSwitch,FormCheckbox,FormRadioGroup,FormSegmentedControl,LayoutTabsFormFieldlabelas the agent-facing name of the control it wrapscore-components.mdentry,Utilities/AgentBridgestory, regeneratedOverview.mdxA control's label comes from its
labelprop, thenaria-label, then the label of an enclosingFormField, thenplaceholder.FormSearchFieldgets registered automatically through theFormTextInputit wraps.Visual changes
Utilities/AgentBridgeis a new story, so main has no "before" version. These screenshots show the story's initial state, the state after "Run agent steps", and a step that theallow()guard rejects.Boundaries and risks
assertAgentOptionthrows, the step fails, later steps don't runtest/agent.test.ts"stops at the first failing step", radiocrejectionallow()guard andgetChangeSource()useAgentControlreturns right afterinjectonBeforeUnmountKnown gaps (not blocking):
ActionToggle*aren't instrumented yet.getChangeSource()is module-level and only valid synchronously inside the handler.User prompts
Claude Code (Opus 5.5) in Paseo.
Verification
pnpm -F @antfu/design exec vitest run: 183 passed (9 new intest/agent.test.ts)pnpm -F @antfu/design run typecheck(vue-tsc): no errorspnpm run lint: cleanpnpm -F @antfu/design run docs:genandgit diff --exit-code -- packages/design/README.md skills: in sync after the docs commitUtilities/AgentBridgein Chromium: all 5 steps applied, "Last change by" showedagent, the forbidden step was rejected, and the console had no errors.nr storybook:buildand the playwright a11y job (left to CI).Written by Claude Code. The human chose the direction (prototype the bridge, then expand it and open a PR) and hasn't reviewed the diff yet, so the reviewer is the first human to look.