跳到正文
Skillpedia
网站与界面(前端)7.6k · #13145

client-methods

它能做什么

这项技能说明在 Agent-Native 应用的浏览器代码中,应使用哪些客户端方法和 hooks。它涵盖操作、应用状态、导航、上传和设置。适合在这些应用中编写界面的开发者。

适用场景

  • ✓当浏览器代码需要从应用操作中读取或修改数据的时候。
  • ✓当某个组件需要调用框架或应用路由的时候。
  • ✓当你要在界面代码中添加上传、身份验证或设置功能的时候。

技能链接

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/client-methods/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/client-methods/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“你能让设置界面通过应用的具名客户端方法保存其值,而不是使用原始请求吗?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体寻找符合需要的现有客户端方法或 hook。它会使用该方法,而不是编写自定义请求,从而使身份验证和错误处理保持一致。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Client Methods

Rule

Browser/client code imports named methods, hooks, or client modules instead of hand-writing REST calls to framework or app routes.

Why

Route shapes are transport details. If components and docs call fetch("/_agent-native/...") or template /api/* routes directly, every caller has to rediscover auth, base paths, request-source headers, JSON parsing, error handling, optimistic updates, sync invalidation, and route quirks. A named client method gives the UI, docs, and future agents one stable contract.

How

  1. Look for an existing client API first.

    Need Use
    App action reads/writes useActionQuery / useActionMutation from @agent-native/core/client/hooks
    Imperative action calls callAction from @agent-native/core/client/hooks
    Browser application state readClientAppState, writeClientAppState, setClientAppState, deleteClientAppState from @agent-native/core/client/hooks
    Navigation/app-state sync useAgentRouteState / useSemanticNavigationState from @agent-native/core/client/navigation
    Agent chat context Agent chat helpers from @agent-native/core/client/agent-chat
    Ask the user a multiple-choice question from app code askUserQuestion from @agent-native/core/client/agent-chat (renders inline in the agent panel; answer goes to the agent — do not build a custom modal)
    Live sync useDbSync, useChangeVersion, useChangeVersions from @agent-native/core/client/hooks
    Extension iframe calls appAction, appFetch, extensionFetch from the extension runtime

    Action fetch behavior: every useActionQuery / useActionMutation / callAction request is bounded by a 60s timeout, and timeouts surface as errors instead of retrying silently. useActionQuery cancels superseded requests automatically via React Query's abort signal. For imperative calls, callAction(name, params, { method, signal, timeoutMs }) accepts an AbortSignal and a timeoutMs override for legitimately long operations.

  2. If no client API exists, add the narrowest helper at the boundary.

    • Put shared framework helpers in packages/core/src/client/*.
    • Put template-local helpers in templates/<app>/app/hooks/*, templates/<app>/app/lib/*, or an existing local client module.
    • Export reusable core helpers from the focused @agent-native/core/client/* entry for their domain. Never recommend the deprecated broad @agent-native/core/client barrel in new code.
    • Keep raw fetch, agentNativePath, and route paths inside that helper, not scattered through components or docs.
    • Add focused tests for URL construction, headers, response parsing, error shape, and any sync invalidation.
  3. Teach the helper, not the route.

    Docs, skills, examples, and generated code should show:

    await setClientAppState("selection", selection, { keepalive: true });
    

    not:

    await fetch("/_agent-native/application-state/selection", {
      method: "PUT",
      body: JSON.stringify(selection),
    });
    

Exceptions

Raw route calls are acceptable only inside low-level client helpers or for route-shaped protocols that cannot be hidden cleanly:

  • multipart uploads
  • streaming/SSE/WebSocket transports
  • OAuth redirects and callback URL construction
  • webhooks and external provider callbacks
  • extension sandbox appFetch / extensionFetch, which are themselves exposed client methods
  • tests that assert route construction

Even for exceptions, prefer a named helper as soon as more than one caller needs the behavior.

Don't

  • Don't put fetch("/_agent-native/..."), fetch(agentNativePath(...)), or template /api/* calls directly in React components for normal app data, actions, settings, or application state.
  • Don't document route calls as the way client code should do work.
  • Don't add pass-through /api/* routes just to make client fetches look simpler; expose an action and call it with action hooks.
  • Don't duplicate auth/session/base-path/request-source/error parsing logic in every component.

Related Skills

  • actions — app operations shared by UI and agent.
  • context-awareness — application-state navigation and selection helpers.
  • real-time-sync — keeping helper-backed UI reads fresh.
  • server-plugins — when a new route is actually warranted.

References

  • `references/legacy-client-fet
常见问题

为什么要避免原始请求?

路由结构是内部细节,而具名方法可以把身份验证、错误和更新集中在一处。

哪个 hook 用于读取操作?

技能列出了用于读取和写入的操作查询和变更 hooks。

我仍然可以直接调用路由吗?

技能要求先寻找具名方法,若已存在相应方法,就避免手写调用。

详情

作者的原始描述

Client method surface rules. Use when wiring browser/client code to actions, application state, framework routes, app APIs, uploads, auth, or settings.

repo: BuilderIO/agent-native

热度

GitHub 星标
7.6k
排名
#13145
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能