Plugins
Plugin 設定與組態
Plugin 封裝(package.json 中繼資料)、清單(openclaw.plugin.json)、設定項目與設定結構描述的參考。
套件中繼資料
你的 package.json 需要一個 openclaw 欄位,用來告訴 Plugin 系統你的 Plugin 提供什麼:
Channel plugin
{
"name": "@myorg/openclaw-my-channel",
"version": "1.0.0",
"type": "module",
"openclaw": {
"extensions": ["./index.ts"],
"setupEntry": "./setup-entry.ts",
"channel": {
"id": "my-channel",
"label": "My Channel",
"blurb": "Short description of the channel."
}
}
}
Provider plugin / ClawHub baseline
{
"name": "@myorg/openclaw-my-plugin",
"version": "1.0.0",
"type": "module",
"openclaw": {
"extensions": ["./index.ts"],
"compat": {
"pluginApi": ">=2026.3.24-beta.2",
"minGatewayVersion": "2026.3.24-beta.2"
},
"build": {
"openclawVersion": "2026.3.24-beta.2",
"pluginSdkVersion": "2026.3.24-beta.2"
}
}
}
openclaw 欄位
extensionsstring[]進入點檔案(相對於套件根目錄)。
setupEntrystring輕量的僅設定進入點(選用)。
channelobject用於設定、選擇器、快速開始與狀態介面的頻道目錄中繼資料。
providersstring[]此 Plugin 註冊的提供者 ID。
installobject安裝提示:npmSpec、localPath、defaultChoice、minHostVersion、expectedIntegrity、allowInvalidConfigRecovery。
startupobject啟動行為旗標。
openclaw.channel
openclaw.channel 是低成本的套件中繼資料,用於在執行階段載入前探索頻道與顯示設定介面。
| 欄位 | 類型 | 含義 |
|---|---|---|
id |
string |
標準頻道 ID。 |
label |
string |
主要頻道標籤。 |
selectionLabel |
string |
當需要不同於 label 時,選擇器/設定標籤。 |
detailLabel |
string |
用於更完整頻道目錄與狀態介面的次要詳細標籤。 |
docsPath |
string |
用於設定與選取連結的文件路徑。 |
docsLabel |
string |
當需要不同於頻道 ID 時,覆寫文件連結使用的標籤。 |
blurb |
string |
簡短的入門/目錄描述。 |
order |
number |
頻道目錄中的排序順序。 |
aliases |
string[] |
用於頻道選取的額外查找別名。 |
preferOver |
string[] |
此頻道應優先於哪些較低優先順序的 Plugin/頻道 ID。 |
systemImage |
string |
頻道 UI 目錄的選用圖示/系統影像名稱。 |
selectionDocsPrefix |
string |
選取介面中文件連結前的前綴文字。 |
selectionDocsOmitLabel |
boolean |
在選取文案中直接顯示文件路徑,而不是帶標籤的文件連結。 |
selectionExtras |
string[] |
附加到選取文案中的額外短字串。 |
markdownCapable |
boolean |
將頻道標記為支援 Markdown,以供外寄格式決策使用。 |
exposure |
object |
控制頻道在設定、已設定清單與文件介面中的可見性。 |
quickstartAllowFrom |
boolean |
將此頻道納入標準快速開始 allowFrom 設定流程。 |
forceAccountBinding |
boolean |
即使只存在一個帳號,也要求明確的帳號綁定。 |
preferSessionLookupForAnnounceTarget |
boolean |
解析此頻道的公告目標時,偏好使用工作階段查找。 |
範例:
{
"openclaw": {
"channel": {
"id": "my-channel",
"label": "My Channel",
"selectionLabel": "My Channel (self-hosted)",
"detailLabel": "My Channel Bot",
"docsPath": "/channels/my-channel",
"docsLabel": "my-channel",
"blurb": "Webhook-based self-hosted chat integration.",
"order": 80,
"aliases": ["mc"],
"preferOver": ["my-channel-legacy"],
"selectionDocsPrefix": "Guide:",
"selectionExtras": ["Markdown"],
"markdownCapable": true,
"exposure": {
"configured": true,
"setup": true,
"docs": true
},
"quickstartAllowFrom": true
}
}
}
exposure 支援:
configured:將頻道包含在已設定/狀態樣式的清單介面中setup:將頻道包含在互動式設定/組態選擇器中docs:將頻道標記為在文件/導覽介面中公開顯示
openclaw.install
openclaw.install 是套件中繼資料,不是清單中繼資料。
| 欄位 | 類型 | 含義 |
|---|---|---|
clawhubSpec |
string |
用於安裝/更新與入門隨選安裝流程的標準 ClawHub 規格。 |
npmSpec |
string |
用於安裝/更新後援流程的標準 npm 規格。 |
localPath |
string |
本機開發或隨附安裝路徑。 |
defaultChoice |
"clawhub" | "npm" | "local" |
當有多個來源可用時的偏好安裝來源。 |
minHostVersion |
string |
支援的最低 OpenClaw 版本,格式為 >=x.y.z 或 >=x.y.z-prerelease。 |
expectedIntegrity |
string |
預期的 npm dist 完整性字串,通常為 sha512-...,用於釘選安裝。 |
allowInvalidConfigRecovery |
boolean |
讓隨附 Plugin 重新安裝流程可從特定過時設定失敗中復原。 |
Onboarding behavior
互動式入門也會使用 openclaw.install 來呈現隨選安裝介面。如果你的 Plugin 在執行階段載入前公開提供者驗證選項或頻道設定/目錄中繼資料,入門流程可以顯示該選項,提示使用 ClawHub、npm 或本機安裝,安裝或啟用 Plugin,然後繼續選取的流程。ClawHub 入門選項會使用 clawhubSpec,且存在時會優先採用;npm 選項需要可信任的目錄中繼資料並包含登錄檔 npmSpec;精確版本與 expectedIntegrity 是選用的 npm 釘選。如果存在 expectedIntegrity,安裝/更新流程會針對 npm 強制檢查它。請將「要顯示什麼」的中繼資料放在 openclaw.plugin.json,並將「如何安裝它」的中繼資料放在 package.json。
minHostVersion enforcement
如果設定了 minHostVersion,安裝與非隨附清單登錄載入都會強制執行它。較舊的主機會略過外部 Plugin;無效的版本字串會遭到拒絕。隨附來源 Plugin 會假定與主機 checkout 版本一致。
Pinned npm installs
對於釘選的 npm 安裝,請在 npmSpec 中保留精確版本,並加入預期的成品完整性:
{
"openclaw": {
"install": {
"npmSpec": "@wecom/[email protected]",
"expectedIntegrity": "sha512-REPLACE_WITH_NPM_DIST_INTEGRITY",
"defaultChoice": "npm"
}
}
}
allowInvalidConfigRecovery scope
allowInvalidConfigRecovery 不是損壞設定的一般性繞過機制。它只用於狹窄的隨附 Plugin 復原情境,讓重新安裝/設定可以修復已知的升級殘留,例如缺少隨附 Plugin 路徑,或同一 Plugin 的過時 channels.<id> 項目。如果設定因無關原因損壞,安裝仍會以失敗關閉,並提示操作員執行 openclaw doctor --fix。
延後完整載入
頻道 Plugin 可以使用下列設定選擇延後載入:
{
"openclaw": {
"extensions": ["./index.ts"],
"setupEntry": "./setup-entry.ts",
"startup": {
"deferConfiguredChannelFullLoadUntilAfterListen": true
}
}
}
啟用後,即使是已設定的頻道,OpenClaw 在監聽前啟動階段也只會載入 setupEntry。完整進入點會在 Gateway 開始監聽後載入。
如果你的設定/完整進入點會註冊 Gateway RPC 方法,請將它們放在 Plugin 專屬前綴下。保留的核心管理命名空間(config.*、exec.approvals.*、wizard.*、update.*)仍由核心擁有,並且一律解析為 operator.admin。
Plugin 清單
每個原生 Plugin 都必須在套件根目錄隨附 openclaw.plugin.json。OpenClaw 會使用它在不執行 Plugin 程式碼的情況下驗證設定。
{
"id": "my-plugin",
"name": "My Plugin",
"description": "Adds My Plugin capabilities to OpenClaw",
"configSchema": {
"type": "object",
"additionalProperties": false,
"properties": {
"webhookSecret": {
"type": "string",
"description": "Webhook verification secret"
}
}
}
}
對於頻道 Plugin,請加入 kind 與 channels:
{
"id": "my-channel",
"kind": "channel",
"channels": ["my-channel"],
"configSchema": {
"type": "object",
"additionalProperties": false,
"properties": {}
}
}
即使 Plugin 沒有設定,也必須隨附結構描述。空結構描述是有效的:
{
"id": "my-plugin",
"configSchema": {
"type": "object",
"additionalProperties": false
}
}
完整結構描述參考請見 Plugin manifest。
ClawHub 發布
對於 Plugin 套件,請使用套件專屬的 ClawHub 指令:
clawhub package publish your-org/your-plugin --dry-run
clawhub package publish your-org/your-plugin
設定入口
setup-entry.ts 檔案是 index.ts 的輕量替代方案,OpenClaw 只需要設定介面時會載入它(初始設定、設定修復、停用頻道檢查)。
// setup-entry.ts
export default defineSetupPluginEntry(myChannelPlugin);
這可避免在設定流程期間載入繁重的執行階段程式碼(加密函式庫、CLI 註冊、背景服務)。
將設定安全匯出保留在 sidecar 模組中的內建工作區頻道,可以使用來自 openclaw/plugin-sdk/channel-entry-contract 的 defineBundledChannelSetupEntry(...),而不是 defineSetupPluginEntry(...)。該內建合約也支援選用的 runtime 匯出,因此設定期間的執行階段接線可以保持輕量且明確。
OpenClaw 何時使用 setupEntry 而不是完整入口
- 頻道已停用,但需要設定/初始設定介面。
- 頻道已啟用但尚未設定。
- 已啟用延遲載入(
deferConfiguredChannelFullLoadUntilAfterListen)。
setupEntry 必須註冊什麼
- 頻道 Plugin 物件(透過
defineSetupPluginEntry)。 - Gateway listen 前需要的任何 HTTP 路由。
- 啟動期間需要的任何 Gateway 方法。
這些啟動 Gateway 方法仍應避免使用保留的核心管理命名空間,例如 config.* 或 update.*。
setupEntry 不應包含什麼
- CLI 註冊。
- 背景服務。
- 繁重的執行階段匯入(加密、SDK)。
- 僅在啟動後才需要的 Gateway 方法。
窄範圍設定輔助匯入
對於熱門的純設定路徑,若你只需要設定介面的一部分,請優先使用窄範圍設定輔助接縫,而不是較廣的 plugin-sdk/setup 總括匯入:
| 匯入路徑 | 用途 | 主要匯出 |
|---|---|---|
plugin-sdk/setup-runtime |
在 setupEntry / 延遲頻道啟動中保持可用的設定期間執行階段輔助工具 |
createPatchedAccountSetupAdapter, createEnvPatchedAccountSetupAdapter, createSetupInputPresenceValidator, noteChannelLookupFailure, noteChannelLookupSummary, promptResolvedAllowFrom, splitSetupEntries, createAllowlistSetupWizardProxy, createDelegatedSetupWizardProxy |
plugin-sdk/setup-adapter-runtime |
感知環境的帳號設定配接器 | createEnvPatchedAccountSetupAdapter |
plugin-sdk/setup-tools |
設定/安裝 CLI/封存/文件輔助工具 | formatCliCommand, detectBinary, extractArchive, resolveBrewExecutable, formatDocsLink, CONFIG_DIR |
當你需要完整共用設定工具箱時,請使用較廣的 plugin-sdk/setup 接縫,包括 moveSingleAccountChannelSectionToDefaultAccount(...) 這類設定修補輔助工具。
設定修補配接器在匯入時保持熱門路徑安全。它們內建的單帳號提升合約介面查找是惰性的,因此匯入 plugin-sdk/setup-runtime 不會在配接器實際使用前急切載入內建合約介面探索。
頻道擁有的單帳號提升
當頻道從單帳號頂層設定升級到 channels.<id>.accounts.* 時,預設的共用行為是將提升後的帳號範圍值移入 accounts.default。
內建頻道可以透過其設定合約介面縮窄或覆寫該提升:
singleAccountKeysToMove:應移入提升帳號的額外頂層鍵namedAccountPromotionKeys:當具名帳號已存在時,只有這些鍵會移入提升帳號;共用政策/遞送鍵會保留在頻道根層resolveSingleAccountPromotionTarget(...):選擇哪個現有帳號接收提升值
設定結構描述
Plugin 設定會依據 manifest 中的 JSON Schema 驗證。使用者可透過以下方式設定 Plugin:
{
plugins: {
entries: {
"my-plugin": {
config: {
webhookSecret: "abc123",
},
},
},
},
}
你的 Plugin 會在註冊期間以 api.pluginConfig 接收此設定。
對於頻道專屬設定,請改用頻道設定區段:
{
channels: {
"my-channel": {
token: "bot-token",
allowFrom: ["user1", "user2"],
},
},
}
建立頻道設定結構描述
使用 buildChannelConfigSchema 將 Zod schema 轉換為 Plugin 擁有的設定成品所使用的 ChannelConfigSchema 包裝器:
const accountSchema = z.object({
token: z.string().optional(),
allowFrom: z.array(z.string()).optional(),
accounts: z.object({}).catchall(z.any()).optional(),
defaultAccount: z.string().optional(),
});
const configSchema = buildChannelConfigSchema(accountSchema);
如果你已經將合約撰寫為 JSON Schema 或 TypeBox,請使用直接輔助工具,讓 OpenClaw 可在中繼資料路徑上略過 Zod 到 JSON Schema 的轉換:
const configSchema = buildJsonChannelConfigSchema(
Type.Object({
token: Type.Optional(Type.String()),
allowFrom: Type.Optional(Type.Array(Type.String())),
}),
);
對於第三方 Plugin,冷路徑合約仍是 Plugin manifest:將產生的 JSON Schema 鏡像到 openclaw.plugin.json#channelConfigs,讓設定結構描述、設定和 UI 介面可在不載入執行階段程式碼的情況下檢查 channels.<id>。
設定精靈
頻道 Plugin 可為 openclaw onboard 提供互動式設定精靈。精靈是 ChannelPlugin 上的 ChannelSetupWizard 物件:
const setupWizard: ChannelSetupWizard = {
channel: "my-channel",
status: {
configuredLabel: "Connected",
unconfiguredLabel: "Not configured",
resolveConfigured: ({ cfg }) => Boolean((cfg.channels as any)?.["my-channel"]?.token),
},
credentials: [
{
inputKey: "token",
providerHint: "my-channel",
credentialLabel: "Bot token",
preferredEnvVar: "MY_CHANNEL_BOT_TOKEN",
envPrompt: "Use MY_CHANNEL_BOT_TOKEN from environment?",
keepPrompt: "Keep current token?",
inputPrompt: "Enter your bot token:",
inspect: ({ cfg, accountId }) => {
const token = (cfg.channels as any)?.["my-channel"]?.token;
return {
accountConfigured: Boolean(token),
hasConfiguredValue: Boolean(token),
};
},
},
],
};
ChannelSetupWizard 型別支援 credentials、textInputs、dmPolicy、allowFrom、groupAccess、prepare、finalize 等。完整範例請參閱內建 Plugin 套件(例如 Discord Plugin 的 src/channel.setup.ts)。
共用 allowFrom 提示
對於只需要標準 note -> prompt -> parse -> merge -> patch 流程的 DM allowlist 提示,請優先使用來自 openclaw/plugin-sdk/setup 的共用設定輔助工具:createPromptParsedAllowFromForAccount(...)、createTopLevelChannelParsedAllowFromPrompt(...) 和 createNestedChannelParsedAllowFromPrompt(...)。
標準頻道設定狀態
對於只因標籤、分數和選用額外行而不同的頻道設定狀態區塊,請優先使用來自 openclaw/plugin-sdk/setup 的 createStandardChannelSetupStatus(...),而不是在每個 Plugin 中手寫相同的 status 物件。
選用頻道設定介面
對於只應在特定情境中出現的選用設定介面,請使用來自 openclaw/plugin-sdk/channel-setup 的 createOptionalChannelSetupSurface:
import { createOptionalChannelSetupSurface } from "openclaw/plugin-sdk/channel-setup";
const setupSurface = createOptionalChannelSetupSurface({
channel: "my-channel",
label: "My Channel",
npmSpec: "@myorg/openclaw-my-channel",
docsPath: "/channels/my-channel",
});
// Returns { setupAdapter, setupWizard }
當你只需要該選用安裝介面的一半時,plugin-sdk/channel-setup 也公開較低階的 createOptionalChannelSetupAdapter(...) 和 createOptionalChannelSetupWizard(...) 建構器。
產生的選用配接器/精靈會在實際設定寫入時封閉失敗。它們會在 validateInput、applyAccountConfig 和 finalize 之間重用同一則需要安裝的訊息,並在設定 docsPath 時附加文件連結。
二進位支援的設定輔助工具
對於二進位支援的設定 UI,請優先使用共用委派輔助工具,而不是在每個頻道中複製相同的二進位/狀態黏合程式碼:
createDetectedBinaryStatus(...)用於只因標籤、提示、分數和二進位偵測而不同的狀態區塊createCliPathTextInput(...)用於路徑支援的文字輸入- 當
setupEntry需要惰性轉發到較重的完整精靈時,使用createDelegatedSetupWizardStatusResolvers(...)、createDelegatedPrepare(...)、createDelegatedFinalize(...)和createDelegatedResolveConfigured(...) - 當
setupEntry只需要委派textInputs[*].shouldPrompt決策時,使用createDelegatedTextInputShouldPrompt(...)
發布與安裝
**外部 Plugin:**發布到 ClawHub,然後安裝:
npm
openclaw plugins install @myorg/openclaw-my-plugin
在發布切換期間,裸套件規格會從 npm 安裝。
僅 ClawHub
openclaw plugins install clawhub:@myorg/openclaw-my-plugin
npm 套件規格
當套件尚未移至 ClawHub,或你在遷移期間需要 直接 npm 安裝路徑時,請使用 npm:
openclaw plugins install npm:@myorg/openclaw-my-plugin
儲存庫內 Plugin: 放在隨附的 Plugin 工作區樹狀結構下,它們會在建置期間自動被探索。
使用者可以安裝:
openclaw plugins install <package-name>
隨附套件中繼資料是明確定義的,不會在 Gateway 啟動時從已建置的 JavaScript 推斷。執行階段依賴項應屬於擁有它們的 Plugin 套件;已封裝的 OpenClaw 啟動程序絕不會修復或鏡像 Plugin 依賴項。
相關
- 建置 Plugin — 逐步入門指南
- Plugin manifest — 完整 manifest schema 參考
- SDK 進入點 —
definePluginEntry和defineChannelPluginEntry