# Install tiers(文档片段 SSOT) 用户向 **Install tiers / 安装分层** 文案的唯一来源。VitePress 页面用 Markdown include 区域引用,勿在正文手抄表格。 ```md ``` 维护:改表只改本文件,然后 `pnpm docs:build` 验证。仓库根英文 `README.md` 为入口;中文 `README.zh-CN.md` 保留简表并由 `pnpm check:install-tiers-ssot` 对齐。 | 档位 | 安装 | 约 production 体积 | 能力 | |------|------|-------------------|------| | **IM** | `pnpm add zhin.js @zhin.js/cli` + 适配器(如 `@zhin.js/adapter-sandbox`);`@zhin.js/cli` 提供 `zhin start` 与管理网关 `@zhin.js/gateway`,开发与运行都需要 | **<10MB**(库包) | 内置命令、组件、中间件、定时任务与热重载运行时(按需在 `zhin.config.yml` 挂载适配器与插件,详见 [插件模型](https://zhin.js.org/concepts/plugin-model)) | | **AI** | `+ @zhin.js/agent zod ai` | +~12–15MB | ZhinAgent、会话、工具、压缩 | | **Provider** | `+ @ai-sdk/openai` 等 | 按厂商 | 大模型调用 | | **MCP** | `+ @modelcontextprotocol/sdk` | +~数 MB | MCP Client | | **Rich media** | `+ @zhin.js/html-renderer` | 按平台(含原生引擎) | 出站 `html` / `markdown` 转 PNG(未装则降级 text) | | **Speech** | `+ @zhin.js/speech` | +~数 MB | 入站 STT、出站 TTS、`segment.tts`(未装则 warn 降级) | | Tier | Install | ~production size | Capabilities | |------|---------|------------------|--------------| | **IM** | `pnpm add zhin.js @zhin.js/cli` + an adapter (for example, `@zhin.js/adapter-sandbox`); `@zhin.js/cli` provides `zhin start` and the management gateway `@zhin.js/gateway`, needed in development and in production | **<10MB** (library) | Built-in commands, components, middleware, schedules and hot-reload runtime (mount adapters and plugins on demand in `zhin.config.yml`; see [Plugin model](/en/concepts/plugin-model)) | | **AI** | `+ @zhin.js/agent zod ai` | +~12–15MB | ZhinAgent, sessions, tools, compaction | | **Provider** | `+ @ai-sdk/openai` etc. | per vendor | LLM calls | | **MCP** | `+ @modelcontextprotocol/sdk` | + a few MB | MCP client | | **Rich media** | `+ @zhin.js/html-renderer` | platform-dependent (includes native engine) | outbound `html` / `markdown` to PNG (falls back to text if missing) | | **Speech** | `+ @zhin.js/speech` | + a few MB | inbound STT, outbound TTS, `segment.tts` (warns and degrades if missing) | | 档位 | 安装 | 能力 | |------|------|------| | **IM** | `pnpm add zhin.js @zhin.js/cli` + 适配器 | 创作面 API 经 `zhin.js/*`;`zhin start` 启动管理网关(`@zhin.js/gateway`,承载 HTTP 与 Console),网关拉起实例 | | **AI** | `+ @zhin.js/agent zod ai` | ZhinAgent、会话与工具 | | **Provider** | `+ @ai-sdk/openai` 等 | 大模型调用 | | **Cards** | `+ @zhin.js/components` | 纯 JSX 样式组件(按需;无 React / 图片引擎) | | **Rich media** | `+ @zhin.js/html-renderer` | 出站 html/markdown 转 PNG | | **Speech** | `+ @zhin.js/speech` | 入站 STT、出站 TTS、voice_stt/voice_tts 工具 | 1.1 稳定线兼容说明:`import from 'zhin.js'` **不含** `ZhinAgent` / `AIService`;请 `import from 'zhin.js/agent'` 或 `zhin.js/ai`。详见 [分层架构](/concepts/architecture)。 1.1 稳定线兼容说明:`import from 'zhin.js'` 不含 `ZhinAgent` / `AIService`;请 `import from 'zhin.js/agent'` 或 `zhin.js/ai`。详见 [分层架构](/concepts/architecture)。 | 用途 | 包 / 子路径 | |------|-------------| | `definePlugin` | `zhin.js` | | `defineCommand` / `defineAdapter` / `defineComponent` | `zhin.js/command` / `zhin.js/adapter` / `zhin.js/component` | | Plugin、Message、Adapter 等 IM 运行时 API | `zhin.js` | | `ZhinAgent`、`AIService`、`AgentResourceHub` | `zhin.js/agent` 或 `@zhin.js/agent` | | `agentLoop`、消息与 completion 契约 | `zhin.js/ai` 或 `@zhin.js/ai` | | `InferenceClient`、Driver/Profile 契约 | `@zhin.js/ai/provider`(含 Host 执行 token) | ```bash pnpm add @zhin.js/agent zod ai pnpm add @ai-sdk/openai # 示例:按 provider 替换 ``` `zhin doctor --fix` 或 `zhin config check --fix` 可根据 `ai.enabled` 自动补全 `package.json`;并检查 `@zhin.js/speech` / `@zhin.js/html-renderer` optional peer。升级到 L4:`zhin doctor --upgrade-l4`。 `npm create zhin-app` / `zhin setup` 在启用 AI 时会自动写入 `package.json` 依赖。上表的 **<10MB 是 IM 库安装体积**,不代表脚手架生成项目的完整依赖体积。新项目还会加入 CLI、Sandbox 适配器、Page/Layout/Skill Feature 与 Satori 卡片示例;AI 仍按选择安装。IM 的 Stable Features 由 `@zhin.js/core` 的 `package.json#zhin.features` 继承(经 `zhin.js` 间接依赖亦可,见 [插件模型](/concepts/plugin-model))。浏览器 UI 在独立的 Remote Console;HTTP 与 Console 接口由 `zhin start` 启动的管理网关(`@zhin.js/gateway`,随 CLI 安装)提供。 仓库示例:[minimal-bot](https://github.com/zhinjs/zhin/tree/main/examples/minimal-bot) 默认 **仅 IM**(`ai.enabled: false`);[full-bot](https://github.com/zhinjs/zhin/tree/main/examples/full-bot) 含完整 AI 栈。 **zhin.js 1.1.x 安装分层**:库包 `pnpm add zhin.js`(IM 核心 <10MB);Plugin Runtime 项目再加适配器与 `@zhin.js/cli`(提供 `zhin start` 与管理网关,开发与运行都需要);AI 另装 `@zhin.js/agent zod ai` 与所选 `@ai-sdk/*`。见 [分层架构](/concepts/architecture)、[插件模型](/concepts/plugin-model) 与 [快速开始 — Install tiers](/getting-started/#install-tiers)。