@forestadmin/agent

中文文档
1.113.3发布于 2026/11/13Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 8.1万

The main entry point of the Forest Admin Node.js SDK: createAgent(options) returns an agent to which you attach datasources, customizations, charts and plugins, then mount on your HTTP server.

原始使用文档
文档目录3 节
  1. Optional in-process components
  2. A BFF — agent.addBff()
  3. A workflow executor — agent.addWorkflowExecutor()

@forestadmin/agent

The main entry point of the Forest Admin Node.js SDK: createAgent(options) returns an agent to which you attach datasources, customizations, charts and plugins, then mount on your HTTP server.

See the developer guide for the full documentation.

Optional in-process components

Two components normally deployed on their own can run inside the agent instead. Both are optional packages, loaded dynamically: an agent that does not use them never loads their code.

A BFF — agent.addBff()

npm install @forestadmin/agent-bff
await createAgent(options)
  .addDataSource(/* … */)
  .addBff({ allowedOrigins: ['https://my-app.com'] })
  .mountOnStandaloneServer(3351)
  .start();

Serves the REST BFF under /bff on whatever port the agent is mounted on, on every mount target — mountOnStandaloneServer above, or the host's own listener with mountOnExpress, mountOnKoa, mountOnFastify, mountOnNestJs. A mountOn* call is what opens a socket: start() only builds the agent's router, so a chain without one serves nothing, BFF included.

The BFF reaches the agent in the same process, so there is no second port, no agent url to configure, and no secrets to keep in sync — authSecret, envSecret, the Forest urls and the logger are inherited.

Everything addBff() takes is a feature it switches on: tokenEncryptionKey enables OAuth (and with it the AI relay), allowedOrigins enables browser access, openapiEnabled serves the docs (off by default when embedded). GET /bff/health reports which of them are on, under configured.

Mount the agent before any body parser of your own — a parser that runs first consumes the request stream, and every BFF POST then answers 500 stream.not.readable.

A permissive cors() registered ahead of the mount costs you the preflight but not the allow-list: the host answers OPTIONS with its own policy, and nothing downstream can take that back, so the request that follows arrives here anyway — and is refused with 403 origin_not_allowed unless its Origin is one you listed. The browser sees the wrong preflight; the collection is still never read for that origin.

Mounting under a sub-path of your own works: app.use('/api', mounted) serves the BFF at /api/bff, and the prefix is derived per request, so the OpenAPI servers entry and the docs page carry /api/bff too.

agentTimeoutMs bounds the wait, not the work. When a call to the agent exceeds it the BFF answers with an error, but nothing is cancelled: the in-process request runs to completion. An action cut at the timeout still applies its mutation, so a client that retries applies it twice. Size the timeout above your slowest action, and make actions idempotent if you intend to retry them.

addBff() cannot be combined with mountAiMcpServer({ basePath: '/bff' }) — the MCP server would claim /bff/oauth and /bff/mcp. Whichever you call second throws on the spot, at the builder call and not from start().

See @forestadmin/agent-bff for the routes, the auth modes and the differences with the standalone deployment.

A workflow executor — agent.addWorkflowExecutor()

npm install @forestadmin/workflow-executor

Runs a workflow executor alongside the agent, which proxies /_internal/executor/* to it. See @forestadmin/workflow-executor.

版本与发布记录

@forestadmin/agent 共发布 546 个版本,首次发布于 2022/04/15;过去 12 个月发布了 209 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.113.3latest2026/11/132 天前
1.113.22026/11/105 天前
1.113.12026/11/105 天前
1.113.02026/11/069 天前
1.112.02026/11/0510 天前
1.111.122026/11/0411 天前

其他发布通道:beta → 1.0.0-beta.63,alpha → 1.4.0-alpha.3,alpha-webhook-custom-actions → 1.10.0-alpha-webhook-custom-actions.5,alpha-widgets → 1.17.0-alpha-widgets.4,beta-cloud-customizer → 1.37.0-beta-cloud-customizer.1,beta-cloud-toolkit → 1.37.0-beta-cloud-toolkit.1。

关于 @forestadmin/agent 的常见问题

@forestadmin/agent 是什么?

The main entry point of the Forest Admin Node.js SDK: createAgent(options) returns an agent to which you attach datasources, customizations, charts and plugins, then mount on your HTTP server.

如何安装 @forestadmin/agent?

在项目目录运行 npm install @forestadmin/agent,或使用 pnpm add / yarn add / bun add。

@forestadmin/agent 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@forestadmin/agent 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@forestadmin/agent 可以商用吗?

@forestadmin/agent 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@forestadmin/agent 的下载量有多少?

根据 npm 官方下载统计,@forestadmin/agent 在 2026/10/16 – 2026/11/14 这 30 天内被下载 80,520 次,日均约 2,684 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@forestadmin/agent 还在维护吗?

最新版本 1.113.3 发布于 2026/11/13(2 天前);至今共发布 546 个版本,其中过去 12 个月发布了 209 个;首次发布于 2022/04/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。