@byline/ai

中文文档
6.13.0发布于 2026/11/04MPL-2.0TypeScriptES Module近 30 天下载 2233

Byline CMS AI subsystem.

原始使用文档
文档目录5 节
  1. What it provides
  2. Browser / server split
  3. Configuration
  4. Documentation
  5. License

@byline/ai

The AI subsystem for Byline CMS — provider-agnostic text generation and structured editing for the admin editor, with built-in editor plugins for the text and Lexical richtext fields.

This package is part of Byline CMS — a developer-friendly, open-source headless CMS with versioning, editorial workflow, and content translation as first-class concerns.

What it provides

  • Provider-agnostic execution — a single ExecuteInstruction contract over OpenAI, Google (Gemini), and Anthropic, with non-streaming and streaming variants (executeInstruction / executeInstructionStreaming).
  • Structured generation — generateStructured / generateStructuredStreaming for schema-constrained output.
  • Patch generation — patch / patchStreaming, which edit an ordered array of Lexical text nodes in place (used by the richtext field's AI drawer).
  • Editor plugins — drop-in plugins for the two editor surfaces: @byline/ai/plugins/text (AiPluginText) and @byline/ai/plugins/lexical (AiPluginLexical, AiLexicalExtension, TOGGLE_AI_DRAWER_COMMAND).
  • Browser-safe config — a public config provider and provider/model helpers that carry no server SDK dependencies.

Browser / server split

The root entry is browser-safe; the SDK-backed execution code lives behind a separate server entry. Import from the right one:

EntryUse fromSurface
@byline/aiBrowser and serverTypes, AiPublicConfigProvider / useAiPublicConfig, provider/model helpers (PROVIDERS, DEFAULT_MODELS, getDefaultModel, …), INSTRUCTION_MODES
@byline/ai/serverServer onlyexecuteInstruction(Streaming), generateStructured(Streaming), patch(Streaming), getAiServerConfig
@byline/ai/plugins/textBrowserAiPluginText
@byline/ai/plugins/lexicalBrowserAiPluginLexical, AiLexicalExtension, TOGGLE_AI_DRAWER_COMMAND

Importing @byline/ai/server in the browser will crash — it pulls in the Anthropic/OpenAI/Google SDKs and pino. Host adapters mount the execute endpoint on the server and the plugins POST ExecuteInstruction payloads to it; see the host integration in @byline/host-tanstack-start (integrations/byline-ai.tsx, server-fns/ai/*).

Configuration

Server config is read from the environment by getAiServerConfig():

VariablePurposeDefault
AI_DEFAULT_PROVIDERopenai | google | anthropicopenai
OPENAI_API_KEY / OPENAI_BASE_URLOpenAI credentials—
GOOGLE_API_KEY / GOOGLE_BASE_URLGoogle (Gemini) credentials—
ANTHROPIC_API_KEY / ANTHROPIC_BASE_URLAnthropic credentials—
BYLINE_AI_ENDPOINTEndpoint the editor plugins POST to/admin/api/ai/execute
LOG_LEVEL / LOG_PRETTYLogginginfo

The curated per-provider model lists live in src/config/ai-config.ts (PROVIDER_MODELS / DEFAULT_MODELS). Run pnpm list:models to discover the models a provider currently exposes.

Documentation

For the full architecture overview, the richtext/AI integration, and getting started instructions, see the main repository: https://github.com/Byline-CMS/bylinecms.dev. Relevant docs: docs/04-collections/07-rich-text.md, docs/04-collections/01-fields.md, and docs/05-reading-and-delivery/05-mcp-server.md.

License

MPL-2.0

版本与发布记录

@byline/ai 共发布 146 个版本,首次发布于 2026/05/11;过去 12 个月发布了 146 个版本。

版本发布日期距今
6.13.0latest2026/11/044 天前
6.12.12026/11/026 天前
6.12.02026/10/318 天前
6.11.02026/10/2514 天前
6.10.12026/10/2217 天前
6.10.02026/10/2217 天前

关于 @byline/ai 的常见问题

@byline/ai 是什么?

Byline CMS AI subsystem.

如何安装 @byline/ai?

在项目目录运行 npm install @byline/ai,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.0.0)、react-dom(^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@byline/ai 支持 TypeScript 吗?

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

@byline/ai 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@byline/ai 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.22.2。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@byline/ai 可以商用吗?

@byline/ai 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@byline/ai 的下载量有多少?

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

@byline/ai 还在维护吗?

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