UI SDK:让Agent既会搭界面,也能按权限操作组件

UI SDK: Agent UI Behaviors and Permission Boundaries

Tech-News #UI SDK#Vercel#Agent#前端开发#无障碍#WebMCP
更新于
🇨🇳 中文

UI SDK 让 Agent 用可复用的交互行为搭建组件,再通过组件接口读取和修改界面。它适合给自己的应用增加可编程的操作入口;已有网站不会因为安装了一个包,就自动变成可控的 Agent 工作台。

这是 Vercel Labs 的 vercel-labs/ui,源码采用 Apache-2.0。本文核对的 core 版本为 0.1.0-beta.20,项目仍处于 Beta,README也提示API和行为可能变化,并列出Beta条款。不要把它和负责模型调用的 AI SDK 混为一谈。

核对日期:2026年11月30日;源码提交:12af339be047274c80aceec4d5a809f91ab19653。我们阅读原始文档、权限实现与基准说明,并在本地运行选定的原始测试。未运行付费模型基准,也未把测试环境结果当成真实浏览器或生产业务验收。

官网:https://ui-sdk.dev/ 官方源码:https://github.com/vercel-labs/ui/tree/12af339be047274c80aceec4d5a809f91ab19653

它把界面拆成了什么?

做一个选择器,麻烦的通常不是画出边框,而是键盘如何移动焦点、输入字母如何定位选项、弹层如何避开屏幕边缘、按Escape后焦点回到哪里。UI SDK把这些交互拆成behavior,再用primitive统一状态、动作和界面部件。

比如弹层、选择与键入查找,可以拼成Select,也可以继续组合为Combobox。官方提供50多种行为,并有React、Vue、Svelte、Solid与Web Components五种适配层。同一交互定义可以用不同框架渲染,视觉样式仍由应用负责。

这不是“自动保证所有页面都无障碍”。行为层提供键盘、焦点与ARIA基础,开发者仍要给控件正确名称、保留可见焦点,并检查组合后的实际体验。官方的skill和随包Markdown文档,主要是让编程Agent按安装版本查资料、搭组件、做验证。

小M把焦点、弹层和选择积木组合为组件,再连接不同框架

Agent怎样操作这些组件?

UI SDK还有第二层能力:给已经接入的组件提供结构化桥接。snapshot()读取组件名称、状态与可用动作,query()查找组件或选项,act()按顺序执行动作。一个命名为Project name的输入框,可以暴露setValue与clear,而不必让Agent靠坐标猜测输入位置。

这条路径调用组件API和变更回调,并把变更来源标成agent。它不是把任意网页DOM都变成工具,也不意味着所有点击都能由字段赋值替代。自定义primitive可以显式声明agent.actions;没有声明时,桥接会按部分方法命名推断可用动作,接入前应检查实际snapshot。

层次负责什么仍需应用提供什么
行为与primitive交互、状态与部件业务规则、样式、可访问名称
框架适配将同一primitive渲染到页面框架环境与组件布局
Agent bridge结构化读取、查找、调用动作策略、结果校验
模型与服务端理解目标、选择工具模型来源、密钥、预算、认证

模型可以运行在应用服务端,浏览器执行桥接动作,再将JSON结果传回。它没有强制绑定某个云端模型,但这也不证明整条链路默认离线。是否使用本地模型、页面数据送往何处,要看你接入的模型SDK和传输代码。

默认权限,哪些地方需要主动配置?

未经标记的受支持动作,在没有allow回调时默认可以执行。data-agent-confirm可以标记需要人确认的控件;未提供allow时,相关动作会被拒绝。但如果应用写了一个永远返回true的allow,确认标记也会被当成已获同意,不能再声称“加了标记就总会弹窗”。

allow管理动作,不会自动隐藏snapshot中的字段,也不会把query变成禁止读取。隐藏区域用data-agent-hidden;敏感值可用data-agent-secret,密码类字段也有保护。它们约束的是此桥接向Agent暴露什么,不代替服务端鉴权,也不是防御任意同源脚本读取DOM的隔离机制。

另一个容易忽略的区别是回调层次。动作直接进入组件API,校验若只写在键盘或指针事件里,不一定会被触发。应该在值变更回调和服务端业务接口上执行对应校验,并检查最终状态,不能只看工具是否返回成功。

小M分别检查动作许可、人工确认和敏感值遮蔽,避免把一个开关当成全部权限

批量动作失败,会自动回滚吗?

不会。一次act可以包含多步,某一步失败后停止,前面成功的变更仍保留。比如改名成功、修改可见性被拒绝,页面可能已经处于“新名字、旧可见性”的状态。它不是数据库事务,应让业务接口负责真正的原子提交、重试与幂等。

历史与undo可以记录、恢复部分控件值,不等于撤销已发生的外部副作用。邮件已经发送、支付已经完成,就不能靠把输入框改回原值来撤销。更适合的初始范围,是草稿字段编辑;发布、付款、删成员等操作仍需业务层确认与审计。

WebMCP可以把这三个工具注册给支持的浏览器,但需要document.modelContext.registerTool。缺少该API时注册不会生效;应用仍可直接调用bridge。registerTools还要求单独的allow,浏览器Agent的动作需同时经过原桥接和注册层策略。

官网的提速数字,到底比较了什么?

原仓库记录的是2026年11月24日的一项设置页任务:改项目名和可见性、调整成员及通知,最后保存。每行运行三次,报告中位数,使用Claude Code中的Sonnet;正确性要求保存一次且值符合目标。

React路径,官方中位数工具调用时间费用
Base UI + 浏览器工具1756秒0.138美元
UI SDK + 浏览器工具1759秒0.140美元
UI SDK + Agent工具213秒0.021美元

最有价值的对照,是UI SDK自己也跑了一遍浏览器工具路径:结果接近其他组件库。改善主要来自结构化工具入口,而不是换个组件库就让模型突然更聪明。这里的工具调用口径包含最后的done,不应把2次解释为任何复杂业务只需两个操作。

这些是作者报告,不是我们的计费实测。单一设置页、三次运行不能证明在任意站点、模型、长流程或高风险动作上都能保持同样比例。建议用自己的任务,连同失败恢复、误操作和人工确认成本一起测。

基准原文与复现入口:https://github.com/vercel-labs/ui/blob/12af339be047274c80aceec4d5a809f91ab19653/benchmarks/agent/README.md

小M对照相同设置页的浏览器与结构化工具路径,旁边保留任务范围和验证记录

本地验证到了哪一步?

本次运行固定源码中的四个原始测试文件,覆盖Agent标记、跨组件安全边界、开关值与服务端空环境,结果见下方记录。测试使用Vitest与jsdom,原套件包含spy、合成DOM、布局补足与工具替身;它验证组件逻辑,不是用真实浏览器或LLM完成一项生产任务。

结果:四个文件、150项测试全部通过,运行21.42秒。这个耗时只是本机测试套件耗时,不是Agent速度或UI性能指标。

没有复跑官方付费Agent基准,没有声称完成五框架浏览器兼容性、完整无障碍认证或安全审计。Mycelium Protocol的判断是:先在自己能改源码的一个设置页上接入,配置动作白名单和人工确认,再验证部分失败时的状态,是比全站替换更有价值的试点。

原测试目录:https://github.com/vercel-labs/ui/tree/12af339be047274c80aceec4d5a809f91ab19653/packages/core/test 权限文档:https://ui-sdk.dev/docs/agents/connect-an-agent/permissions 相关Agent接口讨论:https://blog.mushroom.cv/blog/copilotkit-frontend-stack-agents-guide/

常见问题

安装后能操作任何网站吗?

不能。它围绕已接入UI SDK的组件与primitive工作。第三方网站若没有相应集成,仍需浏览器自动化或其他工具。

它和AI SDK有什么关系?

UI SDK负责交互行为、组件与浏览器桥接;AI SDK可以承担模型调用和工具消息传输。两者可以配合,但不是同一个包,也没有把模型服务自动包含进来。

能否直接用于生产关键操作?

应先验收自己的业务。项目仍为Beta,默认动作许可、确认回调、敏感值读取、部分失败和服务端鉴权都要检查;本次原始测试通过也不代替你的应用验收。


© 2026 Author: Mycelium Protocol. 本文采用 CC BY 4.0 授权——欢迎转载和引用,须注明作者姓名及原文链接,不得去除署名后以原创发布。

🇬🇧 English

UI SDK lets agents build components from reusable interaction behaviors and operate those components through structured APIs. It is useful when you control the application and can expose intentional actions. Installing a package does not give an agent control over arbitrary websites.

The project is Vercel Labs’ vercel-labs/ui, licensed under Apache-2.0. We checked core 0.1.0-beta.20 at commit 12af339be047274c80aceec4d5a809f91ab19653 on November 30, 2026. It remains a beta: the README flags API and behavior changes and references beta terms. It is distinct from AI SDK, which handles model integration.

We reviewed source, documentation and benchmark methodology and ran selected original local tests. We did not run the paid model benchmark or validate a production application in a real browser.

Website: https://ui-sdk.dev/ Pinned source: https://github.com/vercel-labs/ui/tree/12af339be047274c80aceec4d5a809f91ab19653

What is a behavior, and what becomes a component?

A selector needs more than a border and some options. It needs keyboard navigation, focus recovery, typeahead, popup positioning and dismissal. UI SDK separates these interaction concerns into behaviors and combines them in a primitive that owns state, actions and parts.

Popup, selection and typeahead behaviors can form a Select or a Combobox. The project describes more than 50 behaviors and adapters for React, Vue, Svelte, Solid and Web Components. Shared interaction definitions can render through different frameworks, while the application supplies visual styling.

This is not an accessibility certificate for every resulting page. Names, focus visibility and composed behavior still need checking. The agent skill and versioned Markdown package docs help coding agents find the right APIs and verify the interface they build.

Little M assembles focus, popup and selection behaviors into a primitive connected to several framework adapters

How does an agent use the finished interface?

The second layer is a bridge to instrumented components. snapshot() reports their names, state and available actions; query() finds components or choices; act() runs ordered actions. An input named Project name can expose setValue and clear instead of making the agent guess coordinates.

Actions go through the component API and change callbacks, with the source marked as agent. This does not automatically expose every DOM element. Custom primitives can declare agent.actions; without that declaration, the bridge infers some actions from method names. Inspect the actual snapshot before granting access.

LayerResponsibilityApplication responsibility
Behaviors and primitiveInteraction, state and partsBusiness rules, styling and accessible names
Framework adapterRendering the primitiveFramework environment and layout
Agent bridgeRead, find and actAction policy and outcome checks
Model and serverChoose tools from a goalProvider, credentials, budget and authentication

A model can run on your server while the bridge executes in the browser and returns JSON. The bridge is not tied to one cloud model, but neither does it make a complete deployment offline. Local-model use and data destinations depend on your integration and transport code.

Which permissions must the application configure?

With no allow callback, supported unmarked actions are accepted. A data-agent-confirm mark blocks a consequential action without an allow callback. But an allow callback that always returns true answers yes for the person; the mark does not guarantee a confirmation dialog on its own.

Action permission is separate from visibility. Refusing an action does not hide fields in snapshot or stop choices being queried. Use data-agent-hidden for excluded regions and data-agent-secret for sensitive values; password-like fields also receive protection. These govern what the bridge exposes, not server authorization or arbitrary same-origin scripts reading the DOM.

Validation in keyboard or pointer handlers may not run when an agent invokes the component API directly. Put value checks in change callbacks and enforce business authorization on the server. Read the resulting state when confirming an outcome.

Little M separates action permission, human confirmation and sensitive-value redaction

Is a multi-step act a transaction?

No. A failure stops subsequent steps but leaves earlier changes applied. Renaming a project may succeed before a visibility change is refused. Atomic business submission, retries and idempotency remain application responsibilities.

History and undo can restore some control values; they cannot retract an email or reverse a payment merely by restoring form fields. Draft editing is a sensible pilot. Publishing, purchases and member deletion need application confirmation and auditing.

WebMCP registration requires document.modelContext.registerTool in the browser. Without it, registration does nothing, although direct bridge methods remain available. registerTools requires its own allow policy, applied in addition to the bridge policy.

What does the official speed comparison measure?

The repository reports one settings-screen task on November 24, 2026: rename a project, change visibility, update members and notifications, then save. Each row is the median of three runs using Sonnet through Claude Code. Correctness requires exactly one save with the requested values.

React path, author-reported medianTool callsTimeCost
Base UI with browser tools1756 seconds$0.138
UI SDK with browser tools1759 seconds$0.140
UI SDK with agent tools213 seconds$0.021

The useful control is UI SDK operated with browser tools: it performs much like the other libraries. The improvement is associated with the structured tool path, not an automatic increase in model intelligence. Tool calls include the final done call, so two calls are not a universal bound on business operations.

These are the authors’ results, not our measured costs. One screen and three runs do not establish performance across arbitrary sites, models or long workflows. Measure your own task with failure recovery, incorrect actions and human confirmation included.

Benchmark source and reproduction: https://github.com/vercel-labs/ui/blob/12af339be047274c80aceec4d5a809f91ab19653/benchmarks/agent/README.md

Little M compares browser and structured-tool paths on the same settings task, retaining scope and evidence

What did our local check establish?

We ran four original test files covering agent marks, cross-component security boundaries, toggle values and the empty server environment. They use Vitest and jsdom, with spies, synthetic DOM, layout substitutes and tool stand-ins in the original suite. This checks component logic, not a production task performed by a model or real browser.

All four files passed: 150 tests in 21.42 seconds. This is local test-suite duration, not agent speed or UI performance.

We did not rerun the paid benchmark, perform five-framework browser compatibility testing or certify accessibility or security. Mycelium Protocol recommends one application settings page as the first pilot: declare allowed actions, handle human confirmation and verify partial-failure state before replacing an entire interface.

Original tests: https://github.com/vercel-labs/ui/tree/12af339be047274c80aceec4d5a809f91ab19653/packages/core/test Permissions: https://ui-sdk.dev/docs/agents/connect-an-agent/permissions Related agent interfaces: https://blog.mushroom.cv/blog/copilotkit-frontend-stack-agents-guide/

FAQ

Can it operate any website after installation?

No. It works with integrated UI SDK components and primitives. Other sites require browser automation or another integration.

Is UI SDK the same as AI SDK?

No. UI SDK supplies behaviors, components and a browser bridge. AI SDK can handle model calls and tool-message transport. They can work together without being the same package.

Is it ready for consequential production actions?

Evaluate your application first. Beta changes, default action permission, confirmation callbacks, sensitive reads, partial failure and server authorization all matter. Passing the selected upstream tests does not replace application acceptance testing.


© 2026 Author: Mycelium Protocol. Licensed under CC BY 4.0 — free to share and adapt with attribution. You must credit the author and link to the original; removing attribution and republishing as original is not permitted.

💬 评论与讨论

使用 GitHub 账号登录后发表评论

关于本站 · 免责声明

🍄 Mushroom Research Blog 是非营利、免费公开的个人科技观察博客与公众号 XStack18,不接受商业合作、不代表任何企业或机构立场,也不谋求商业利益。我们以个人视角客观中立地记录和分析 AI、Web3 等领域的最新模型发布与技术动态——不止转述新闻标题或二手信息,而是给出有独立思考的深入分析,希望帮更多人获得有价值的一手科技认知。

⚠️ 文中介绍的开源代码与模型,仅供学习交流与技术借鉴。它们大多仍处于早期阶段,有待进一步研究和验证,请勿直接用于工作或生产环境;如需采用,请先自行充分测试,并核实其许可证与安全性。
Open-source code and models featured here are shared for learning and reference only. Most are early-stage and still need further study and verification — please don't use them directly in your work or in production. Test them thoroughly and check their licenses and security first.

  1. 本站文章均为作者基于公开信息的个人研究与观点整理,不代表文中提及的任何公司、产品、模型的官方立场,未与其构成商业关联或合作关系。
  2. 科技行业信息更新极快,我们尽力保证内容准确、及时,但不对完整性、实时性做绝对保证,具体请以相关企业/项目官方公告为准。
  3. 文中引用的第三方商标、产品名称、图片、数据等版权归原权利人所有,我们会尽量注明来源;如你认为存在版权疑问或侵权,请通过下方邮箱联系我们,收到通知后会尽快核实处理(更正、加注来源或删除)。
  4. 文章内容仅为技术科普与个人观点,不构成投资、法律或其他专业建议,据此进行任何决策的后果需自行判断和承担。

📮 侵权 / 勘误 / 合作咨询:[email protected]