開發者指南

外掛開發文件

為 AnBoWork 桌面用戶端開發外掛:幫 AI 增加新工具、在工作階段旁邊掛一塊自己的面板、發系統通知、解析新的檔案格式。一個 manifest.json 加一個進入點腳本就能跑起來。

01概覽

AnBoWork 外掛是一個普通的 Node.js 程式。安裝後,用戶端把它 fork 成一個獨立的子程序執行(純 Node 環境,沒有 Electron API),透過程序間訊息跟宿主通訊。外掛不需要依賴任何 SDK 套件,只要會 process.on('message') 和 process.send()。

外掛「有哪些能力」全部寫在 manifest.json 裡,是靜態宣告:安裝前的知情同意頁、市集審核,都不需要執行外掛程式碼就能知道它會裝哪些工具、要什麼權限。所有 UI(頂欄圖示、設定項、命令面板、右鍵選單)都由宿主按宣告統一渲染,外掛程式碼不會跑進主視窗。只有停靠視圖和浮動面板是外掛自己的 HTML,也執行在獨立沙箱頁面裡。

能力一覽

manifest 欄位能力使用者在哪裡看到
tools幫 AI 增加可呼叫的工具AI 在對話中自動呼叫;工具呼叫記錄顯示在工作階段裡
views停靠在工作階段右側欄的常駐視圖預設收在工作階段頂欄的「⋮」選單裡,點開後在右側顯示你的頁面;只有宣告為 pinned 的視圖才會在頂欄常駐一個圖示
ui獨立浮動視窗外掛清單的「⋯」選單裡開啟
sessionAction工作階段頂欄常駐操作圖示點一下呼叫你指定的工具
configuration設定頁的設定項設定 → 外掛設定,值隨每次呼叫傳給你
commandsCtrl/Cmd+K 命令面板項目命令面板
keybindings全域快捷鍵按鍵觸發某條命令
menus工作階段右鍵選單項工作階段清單列的「⋯」/右鍵選單
documentParsers解析拖進輸入框的檔案使用者拖入對應格式檔案時自動呼叫
activationEvents隨應用程式啟動拉起無感知;用於需要背景計時器的外掛
permissions宣告需要的權限安裝前的知情同意頁

02快速開始

一個最小外掛只需要兩個檔案。

my-plugin/
├── manifest.json   # plugin manifest (required)
├── index.js        # entry script, referenced by manifest.main (required)
├── view.html       # docked view page (optional, manifest.views[].entry)
└── ui.html         # floating panel page (optional, manifest.ui.entry)

1. 寫 manifest.json

{
  "id": "com.example.hello",
  "name": "Hello Plugin",
  "version": "1.0.0",
  "description": "Say hello to the user.",
  "main": "index.js",
  "permissions": [],
  "tools": [
    {
      "name": "say_hello",
      "summary": "Greet the user by name",
      "description": "Return a greeting for the given name. Call this when the user explicitly asks the plugin to say hello.",
      "parameters": {
        "type": "object",
        "properties": {
          "name": { "type": "string", "description": "Who to greet." }
        },
        "required": ["name"]
      }
    }
  ]
}

2. 寫進入點腳本

// The entry script runs in a standalone Node.js child process (ELECTRON_RUN_AS_NODE=1).
// Only Node built-ins and dependencies shipped inside the plugin folder are available;
// there is no Electron API.
process.on('message', (msg) => {
  if (!msg || msg.type !== 'call_tool') return;
  const { requestId, toolName, params } = msg;
  try {
    if (toolName !== 'say_hello') throw new Error(`unknown tool: ${toolName}`);
    process.send({
      type: 'tool_result',
      requestId,
      content: [{ type: 'text', text: `Hello, ${params.name}!` }],
    });
  } catch (err) {
    process.send({ type: 'tool_error', requestId, message: err.message });
  }
});

3. 安裝到用戶端

開啟 AnBoWork → 頂部「工具」→「外掛」→ 右上角「本機安裝」,選擇外掛目錄(或打成 zip 後選 zip 檔)。安裝前會彈出知情同意頁,列出這個外掛宣告的權限和全部工具,確認後啟用。

4. 試一下

在任意工作階段裡對 AI 說「讓外掛跟小明打個招呼」,AI 會根據工具描述決定呼叫 say_hello,工作階段裡會顯示這次呼叫和回傳結果。

提示
外掛的工具是在工作階段啟動時一次性註冊給 AI 的:安裝、更新或啟用外掛之後,要新建一個工作階段AI 才看得到新工具,已經開著的工作階段不會重新整理。安裝前彈出的知情同意頁上也寫著這句。

03manifest 欄位

欄位型別必填說明
idstring是反向網域風格,如 com.example.my-plugin。只允許字母、數字、點、連字號。建立後不可改,安裝同 id 視為覆蓋重裝。
namestring是外掛名稱。這個欄位和 description 會作為上下文餵給模型,建議用英文。
versionstring是語意化版本,市集按它判斷更新。
descriptionstring是一句話說明外掛做什麼(英文,上限 700 字)。也是 AI 判斷要不要推薦安裝的依據,寫法見「推薦說明」。
authorstring否作者。
readmestring否市集詳情頁展示的長文說明,支援 Markdown。圖片只能用 https 連結,不支援引用 zip 裡的相對路徑圖片。
iconstring否市集列表/詳情頁展示的圖示,填 zip 裡一個相對路徑(例如 icon.png)。必須是 PNG,不支援 SVG,尺寸至少 128×128。
mainstring是進入點腳本,相對外掛目錄的路徑,不允許 .. 跳出目錄。
permissionsstring[]是network / filesystem / notifications / account,可為空陣列。見「權限模型」。
toolsobject[]是工具宣告,可為空陣列。見「工具與呼叫協定」。
documentParsersobject[]否檔案解析能力。
uiobject否浮動面板:{ entry, title }
viewsobject[]否停靠視圖:{ id, title, icon, entry, width?, pinned? }
sessionActionobject否頂欄圖示,每個外掛最多一個。
configurationobject[]否設定項清單。
commandsobject[]否命令面板項目。
keybindingsobject[]否快捷鍵,command 必須引用 commands[] 裡某條的 tool,否則安裝被拒絕。
menusobject否目前只開放 session/context 一個位置。
activationEventsstring[]否目前只有 onStartupFinished。
defaultLocalestring否manifest 裡這些給人看的原文所使用語言的語言代碼(zh、en……),搭配 localizations 使用,見「國際化(多語系)」。
localizationsobject否給人看的文案的各語言譯文,鍵是語言代碼,見「國際化(多語系)」。

文案語言約定

manifest 裡的文字有兩類讀者。給模型看的:name、description、tools[].description、tools[].parameters.*.description,一律寫英文、不要翻譯:模型對英文工具描述的理解更穩定,參數也填得更準。給人看的:tools[].summary(知情同意頁上的一句話摘要)、tools[].confirmation、ui.title、views[].title、sessionAction.tooltip、configuration[].label、commands[].title 和 menus 裡的 title。原文可以寫任何語言,用 defaultLocale 宣告,再在 localizations 裡補上譯文,就能跟著應用程式的介面語言顯示(見「國際化(多語系)」)。

{
  "id": "com.example.full",
  "name": "Full Example",
  "version": "1.2.0",
  "description": "Every contribution point in one manifest.",
  "author": "Example Inc.",
  "readme": "## Full Example\n\nLonger Markdown shown on the marketplace detail page. Images must be https URLs.",
  "icon": "icon.png",
  "main": "index.js",
  "permissions": ["filesystem", "network", "notifications", "account"],
  "activationEvents": ["onStartupFinished"],
  "tools": [
    {
      "name": "do_something",
      "summary": "Do one thing to the current project",
      "description": "…English. State clearly when to call this and when not to…",
      "parameters": { "type": "object", "properties": {}, "required": [] },
      "renderAs": "checklist"
    },
    {
      "name": "manage_reports",
      "summary": "Publish or list reports",
      "description": "…publish is irreversible; the host shows a confirmation card before running it…",
      "parameters": {
        "type": "object",
        "properties": {
          "action": { "type": "string", "enum": ["publish", "list"] },
          "path": { "type": "string", "description": "Report file to publish." }
        },
        "required": ["action"]
      },
      "confirmation": {
        "param": "action",
        "values": ["publish"],
        "title": "Publish this report?",
        "message": "The report becomes publicly reachable. This cannot be undone.",
        "confirmLabel": "Publish",
        "detailParams": [{ "param": "path", "label": "File" }]
      }
    },
    { "name": "is_available", "summary": "Whether the current folder applies", "description": "…", "parameters": { "type": "object", "properties": {} } },
    { "name": "list_modes", "summary": "List selectable modes", "description": "…", "parameters": { "type": "object", "properties": {} } }
  ],
  "ui": { "entry": "ui.html", "title": "Example Panel" },
  "views": [
    { "id": "board", "title": "Example Board", "icon": "checklist", "entry": "view.html", "width": 380, "pinned": false }
  ],
  "sessionAction": {
    "tool": "do_something",
    "icon": "git-branch",
    "tooltip": "Do one thing to the current project",
    "visibleTool": "is_available"
  },
  "configuration": [
    { "id": "mode", "label": "Mode", "type": "select", "optionsTool": "list_modes", "defaultValue": "auto" },
    { "id": "verbose", "label": "Verbose output", "type": "boolean", "defaultValue": false },
    { "id": "prefix", "label": "Prefix", "type": "string", "defaultValue": "" },
    { "id": "limit", "label": "Max items", "type": "number", "defaultValue": 20 }
  ],
  "commands": [
    { "tool": "do_something", "icon": "git-branch", "title": "Do one thing to the current project" }
  ],
  "keybindings": [
    { "command": "do_something", "key": "mod+shift+d" }
  ],
  "menus": {
    "session/context": [
      { "tool": "do_something", "icon": "git-branch", "title": "Do one thing to this session" }
    ]
  }
}

04權限模型

permissions 必須如實反映程式碼實際做的事。安裝前的知情同意頁會逐條展示,使用者據此決定要不要裝;市集審核也會對照程式碼檢查宣告是否屬實。

權限什麼時候必須宣告宿主如何對待
filesystem讀寫使用者檔案(讀專案程式碼、產生文件、在使用者目錄存資料)知情同意,向使用者展示。
network發起任何網路請求(呼叫第三方 API、下載資源)知情同意,向使用者展示。
notifications透過反向 RPC show_notification 彈系統通知硬校驗:沒有宣告就呼叫,宿主直接回傳 host_error,通知不會彈出。
account透過反向 RPC piomodel_api_request 以目前登入使用者的身分呼叫 AnBoWork 後端,或使用 render_office_cloud / publish_office_preview硬校驗:沒有宣告,宿主直接回傳 host_error。登入 token 只在主程序,由主程序代為附帶,絕不進入外掛程序;而且只放行白名單裡的介面路徑(/api/user/sites、/api/user/office-authoring、/api/user/office-documents、/api/user/office-previews/:id/source),宣告了這個權限也不能拿使用者身分去改密碼、換綁信箱。
注意
外掛子程序是完整的 Node.js 環境,filesystem 和 network 目前是知情同意層面的宣告,不是執行期沙箱:宿主不會攔截 fs 或 fetch。這正是為什麼宣告必須誠實——漏報權限的外掛在市集審核時會被拒絕,被使用者發現後會失去信任。不要多報(用不到的權限會讓使用者猶豫),也不要少報。

隱私與資料

context.cwd 是使用者的專案目錄,裡面可能有原始碼和敏感設定;工具參數裡可能有使用者的對話內容。除非功能必需,不要把這些資料發到網路;需要傳送時在 description 和 summary 裡說清楚發給誰、發什麼。外掛自己的持久化資料建議放在使用者主目錄下一個以外掛 id 命名的檔案裡,解除安裝時使用者能一眼找到。

05工具與呼叫協定

宣告

欄位說明
name工具名,小寫字母加底線,在整個用戶端裡要唯一(會和內建工具、其它外掛的工具一起註冊給模型)。
description給模型的說明(英文)。寫清楚三件事:這個工具做什麼、使用者說什麼話時應該呼叫、什麼情況下不要呼叫。這是決定 AI 會不會用你外掛的最關鍵欄位。
summary給人看的一句話摘要,知情同意頁展示。可選但強烈建議提供,否則會退回展示裁剪過的 description。
parameters標準 JSON Schema 物件,每個屬性都寫 description。模型按它填參數,宿主原樣傳給你,不做額外校驗,程式碼裡要自己檢查必填項。
renderAs可選,目前只有 checklist:宿主把這次呼叫參數裡的 todos 陣列渲染成清單卡片,見下方。
confirmation可選。宣告後,params[param] 落在 values 裡的呼叫要先讓使用者在聊天裡點確認才會執行,見下方「執行前確認」。
timeoutSeconds可選。單次呼叫最多等多少秒,逾時宿主就放棄(預設 30,限制在 30–900 之間)。只給確實要跑很久、且一直在推進的工具用,例如上傳大資料夾;別拿它掩蓋卡死。
注意
模型能呼叫的工具只來自這裡宣告的 tools[]——sessionAction.tool、commands[].tool、menus 裡的 tool 欄位只在安裝時檢查是否為非空字串,不會檢查這個名稱有沒有在 tools[] 裡宣告過,點擊/觸發時宿主照樣用這個名稱發起呼叫。所以一個純 UI 觸發的按鈕可以只在你自己的 index.js 裡實作處理邏輯、完全不出現在 tools[] 裡——但這樣 AI 永遠看不到也呼叫不了它。想讓同一個功能既能點擊觸發、也能被 AI 在對話裡直接呼叫,就把這個名稱也宣告進 tools[],兩條入口共用同一份處理邏輯;確定只要 UI 觸發、不希望 AI 插手,不宣告即可,不用為了「看起來齊全」硬加一條。

執行前確認:confirmation

公開發佈、刪除這類不可撤回的操作,不能只靠模型「先問一句」——提示詞管不住。在工具上宣告 confirmation 後,宿主在碰你的程序之前就暫停這次呼叫,在訊息流裡畫一張帶按鈕的確認卡片,使用者點了確認才送出 call_tool;使用者取消時你的程式碼不會執行,模型收到一則以 [user-declined] 開頭的普通結果(不是錯誤,所以不會重試)。title、message、confirmLabel、detailParams[].label 是給人看的文案,請用目標使用者的語言。once: true 表示這是一項長期授權(例如「允許把文件上傳到雲端」):使用者點過一次之後,本次應用程式執行期間同一個工具的後續呼叫不再彈出卡片;發佈、刪除這類單次操作不要設 once。

// manifest.tools[]: a call needs the user's click only when params[param] is one of values.
{
  "name": "manage_html_sites",
  "description": "…",
  "parameters": { "type": "object", "properties": { "action": { "type": "string", "enum": ["publish", "list", "unpublish"] }, "path": { "type": "string" } }, "required": ["action"] },
  "confirmation": {
    "param": "action",
    "values": ["publish"],                       // list / unpublish run without a card
    "title": "Publish this page to the web?",
    "message": "Anyone with the link can open it. Confirm to continue.",
    "confirmLabel": "Publish",
    "detailParams": [{ "param": "path", "label": "File" }],   // shown on the card as "File: <params.path>"
    "once": false                                // true = a standing grant: ask once per app run, not per call
  }
}

// The host pauses BEFORE your process is called and renders the card in the chat.
// Confirmed → call_tool arrives as usual. Declined → your code never runs; the model receives
// a plain tool result starting with "[user-declined]" and will not retry.

訊息協定

宿主發 call_tool,外掛必須用同一個 requestId 回一條 tool_result 或 tool_error。單次呼叫 30 秒內沒有回應會被判為逾時,模型收到錯誤。

// host → plugin
{
  "type": "call_tool",
  "requestId": "0b2d…",          // unique per call, echo it back unchanged
  "toolName": "do_something",
  "params": { "name": "…" },     // arguments validated against tools[].parameters
  "context": {
    "cwd": "/Users/me/project",  // project folder of the calling session; a temp folder for chat sessions
    "config": { "mode": "auto", "verbose": false }   // present only when configuration is declared; keys are configuration[].id
  }
}

content 只認 text 和 image 兩種區塊(image 用 base64 的 data 加 mimeType),其它型別會被丟棄。details 是任意結構化資料,不會餵給模型,用於宿主 UI 渲染和你自己的停靠視圖。

產物是檔案:檔案卡片

// When the result is a file: include the absolute path and file name. The session
// renders a clickable file card that previews in-app (docx/xlsx/pdf/markdown/code…).
process.send({
  type: 'tool_result',
  requestId,
  content: [{ type: 'text', text: `Generated [${fileName}](${filePath})` }],
  details: { filePath, fileName },
});

清單渲染:renderAs checklist

// For tools with renderAs: "checklist", the host renders the todos array from the call arguments:
{
  "todos": [
    { "id": "1", "content": "Initialize repository", "status": "completed" },
    { "id": "2", "content": "Write unit tests", "status": "in_progress" },
    { "id": "3", "content": "Publish", "status": "pending" }
  ]
}

寫好 description 的要點

用祈使句描述觸發條件(「Call this when the user asks to…」),明確排除項(「Do not call this for…」)。如果產物是檔案,要求模型在回覆裡引用回傳的檔案連結、不要憑空聲稱已產生。如果參數會被轉發給外部生成類 API,說明參數要用什麼語言。避免只寫「manage todos」這類一句話,模型會不知道什麼時候該用。

06停靠視圖 views

停靠視圖是一張掛在工作階段右側欄的常駐頁面:工作階段頂欄多出一個圖示,點開後你的 HTML 顯示在右側,切換工作階段、收起再展開都不會遺失頁面狀態(捲動位置、草稿),跟 VS Code 側欄視圖同一個語意。

欄位說明
id外掛內唯一。
title圖示的提示文字(人類可讀)。
icon從宿主白名單裡選:git-branch、checklist、world。保持全應用程式圖示風格統一,不接受自帶圖片。
entryHTML 檔案,相對外掛目錄。
width可選,面板預設寬度(像素),240 到 640,預設 360。使用者之後可以拖曳調整並被記住。
pinned可選,預設 false。預設所有外掛的視圖都收進工作階段頂欄的「⋮」更多選單,不各占一個常駐圖示;只有 pinned: true 才在頂欄單獨常駐一個圖示。別為了顯眼就都設成 true——裝了幾個外掛頂欄就堆幾個圖示,正是這個預設值要避免的。

頁面執行環境

頁面在沙箱裡執行(sandbox + contextIsolation,沒有 Node、沒有宿主應用程式的任何資料),只能透過 window.pluginHost 這幾個方法跟自己的外掛程序通訊。樣式自己寫,建議按下面範例跟隨應用程式的亮/暗色。

interface PluginHost {
  // Call a tool declared in this plugin's manifest.tools; same call_tool channel the AI uses
  invoke(toolName: string, params: unknown): Promise<
    { content: unknown[]; details?: unknown } | { error: string }
  >;
  // Subscribe to ui_push messages from the plugin process; returns an unsubscribe function
  onPush(callback: (channel: string, payload: unknown) => void): () => void;
  // Current light/dark scheme and subsequent changes
  getColorScheme(): Promise<'light' | 'dark'>;
  onColorSchemeChange(callback: (scheme: 'light' | 'dark') => void): () => void;
  // Docked views only: ask the host to collapse the panel this view is shown in. The host does not
  // draw a header for views, so draw your own close button and call this. Older app versions do not
  // have it — check `typeof pluginHost.closeView === 'function'` before rendering the button.
  closeView?(): void;
  // Put text into the user's current input box and focus it. The text is APPENDED to the existing draft
  // (never overwrites what the user typed) and is NOT sent: the user decides whether to edit it and press
  // send. No permission needed, no limit on call count; one call is capped at 100,000 characters.
  // Resolves to { delivered: true }, or { delivered: false, reason: 'no_composer' } when the current page
  // has no input box. Older app versions do not have it — check typeof before drawing the button.
  composeMessage?(params: { text: string }): Promise<{ delivered: boolean; reason?: string }>;
  // App interface language (zh, en, ja, ...; empty string until the app has reported it) and later changes.
  // Older app versions do not have these two: check typeof before use. Panel pages only; plugin processes
  // get the same information from the PIOMODE_LOCALE env var and the locale_changed message.
  getLocale?(): Promise<string>;
  onLocaleChange?(callback: (locale: string) => void): () => void;
}
declare const pluginHost: PluginHost; // exposed as window.pluginHost

推薦模式:頁面首次載入用 invoke() 呼叫自己的一個查詢工具,並讓工具在 details 裡回傳結構化資料;之後每次資料變化由外掛程序 ui_push 推送,頁面不輪詢。AI 在對話裡改了資料,面板會即時重新整理。

宿主不替停靠視圖畫標頭,面板裡的關閉按鈕要由你的頁面自己畫,點擊時呼叫 <code>window.pluginHost.closeView()</code>;舊版用戶端沒有這個方法,渲染前先判斷 <code>typeof host.closeView === 'function'</code>。頁面裡帶 <code>target="_blank"</code> 的連結不需要自己處理:在工作階段頁會在應用程式內的瀏覽器面板開啟,在新建工作階段頁則退回系統瀏覽器。

頁面裡也可以畫一個「傳送到對話」按鈕,點擊時呼叫 <code>window.pluginHost.composeMessage({ text })</code>:宿主會把這段文字<strong>附加</strong>到使用者目前輸入框的草稿末尾(不會覆蓋已經輸入的內容)並聚焦輸入框,但<strong>不會送出</strong>,要不要修改、要不要送出由使用者自己決定。不需要宣告權限,也沒有呼叫次數限制,只是單次文字不超過 100000 個字元。回傳 <code>{ delivered: true }</code>;目前頁面沒有輸入框時回傳 <code>{ delivered: false, reason: 'no_composer' }</code>。舊版用戶端沒有這個方法,繪製按鈕前請先判斷 <code>typeof host.composeMessage === 'function'</code>。

07浮動面板 ui

ui: { entry, title } 宣告一個獨立的浮動視窗(900×700),使用者在外掛清單的「⋯」選單裡開啟,關掉即銷毀。頁面環境和 window.pluginHost API 跟停靠視圖完全一樣,ui_push 也會同時送到浮動面板和停靠視圖。適合「偶爾開啟看一眼」的大面板;需要常駐在工作階段旁邊的內容用 views。

08工作階段頂欄圖示 sessionAction

每個外掛最多一個常駐圖示,點擊時用空參數呼叫 tool,所以那個工具必須在沒有參數時也能有意義地執行。

欄位說明
tool點擊呼叫的工具名。
icon白名單圖示名。
tooltip懸停提示。
visibleTool可選。給了就在渲染前先用空參數呼叫它,按回傳的 details.visible(布林)決定要不要顯示圖示。適合「目前目錄是不是 git 儲存庫」這類依賴執行期狀態的判斷。
// The host calls visibleTool with empty params and shows the icon based on details.visible
process.send({
  type: 'tool_result',
  requestId,
  content: [{ type: 'text', text: isGitRepo ? 'git repo' : 'not a git repo' }],
  details: { visible: isGitRepo },
});

09設定項 configuration

宣告後出現在設定頁的外掛設定裡。使用者改的值由宿主儲存,每次 call_tool 都會以 context.config 傳給你(鍵是 id,沒改過的用 defaultValue),不管這次呼叫來自 AI、頂欄圖示還是你的面板,你不需要自己去問。

type渲染成defaultValue 型別
select單選清單,候選項來自 optionsToolstring
boolean開關boolean
string文字輸入框,失焦提交string
number數字輸入框number
// For type: "select" settings, the host calls optionsTool with empty params to fetch options
process.send({
  type: 'tool_result',
  requestId,
  content: [{ type: 'text', text: '2 options' }],
  details: {
    options: [
      { value: 'fast', label: 'Fast' },
      { value: 'accurate', label: 'Accurate' },
    ],
  },
});
// The host automatically prepends an "Auto" option whose value equals this
// configuration entry's defaultValue; the plugin must not return it again.

10命令面板 / 快捷鍵 / 右鍵選單

三者都是「用空參數呼叫某個工具」的不同入口,一個外掛可以宣告多條。

欄位形狀說明
commands{ tool, icon, title }[]出現在 Ctrl/Cmd+K 命令面板,使用者搜尋後觸發。
keybindings{ command, key }[]command 必須等於 commands[] 裡某條的 tool。key 用 mod+shift+g 這種寫法,mod 在 macOS 是 Cmd、其它平台是 Ctrl。跟其它快捷鍵衝突不做靜態檢查,選不常用的組合。
menus{ "session/context": { tool, icon, title }[] }掛進工作階段清單列的選單。目前只開放這一個位置。

11國際化(多語系)

應用程式有 19 種介面語言。外掛裡給人看的文字(知情同意摘要、確認卡片、面板標題、提示、設定項、命令標題,以及你自己的面板頁面和系統通知)應該跟著介面語言走。給模型看的文字永遠不做在地化:name、description、tools[].description、參數說明,以及工具回傳給模型的文字都保持英文。

manifest 裡的文字

原文照常寫在各個欄位裡,用 defaultLocale 宣告它是哪種語言;譯文放進 localizations,鍵是語言代碼,只寫你翻譯的那些欄位。條目依工具名、視圖 id、設定項 id 索引,而不是依陣列位置,所以調整宣告順序不會讓譯文錯位。

譯文裡的欄位翻譯什麼
name / description外掛清單和安裝頁上顯示的名稱與一句話簡介。僅供人閱讀:模型讀的仍是頂層的英文欄位。每種語言(包括原文所用的語言)都可以有自己的一筆。
tools.<tool>.summary知情同意頁上的一句話摘要。
tools.<tool>.confirmation確認卡片文案:title、message、confirmLabel,以及 detailLabels(入參名對應卡片上的列標籤)。
ui.title / views.<id>.title浮動面板和每個停靠視圖的標題(視圖依 id 索引)。
sessionAction.tooltip工作階段頂欄圖示的懸停提示。
configuration.<id>.label每個設定項的標籤(依設定項 id 索引)。
commands.<tool>.title / menus.<location>.<tool>.title命令面板裡的命令標題(依工具名索引)和右鍵選單項標題(先依位置、再依工具名索引)。
{
  "id": "com.example.todo",
  "name": "Todo Quadrant",
  "description": "Daily to-do list organized by urgent/important quadrants. Install this when the user wants to track todos. (English, for the model)",
  "defaultLocale": "en",
  "tools": [
    {
      "name": "manage_todo",
      "description": "Add, list, complete and delete todos. (English, for the model)",
      "summary": "Manage your to-do list",
      "parameters": { "type": "object", "properties": { "action": { "type": "string", "description": "add | list | complete | clear_all" } } },
      "confirmation": {
        "param": "action",
        "values": ["clear_all"],
        "title": "Clear all to-dos?",
        "message": "This removes every item and cannot be undone.",
        "confirmLabel": "Clear all"
      }
    }
  ],
  "localizations": {
    "zh": {
      "name": "四象限待办",
      "description": "按紧急/重要四象限管理待办。",
      "tools": {
        "manage_todo": {
          "summary": "管理你的待办清单",
          "confirmation": {
            "title": "清空全部待办?",
            "message": "这会删除所有待办,无法撤销。",
            "confirmLabel": "全部清空"
          }
        }
      }
    },
    "ja": {
      "tools": { "manage_todo": { "summary": "ToDoリストを管理します" } }
    }
  }
}

取用順序

宿主依這個順序取用文字:介面語言本身,再來是近親語言(zh-TW 與 zh-HK 互相備援,pt-BR 退回 pt),再來是 en,最後是原文。取用到 defaultLocale 就停下並使用原文,所以原文是中文的外掛,不會被英文譯文蓋掉。缺的欄位逐個往後退回。應用程式的介面語言有:zh、en、zh-TW、zh-HK、ja、ko、vi、id、tr、de、fr、es、pt-BR、hi、ar、ru、fa、pl、he。舊版應用程式不認識這兩個欄位,會一直顯示原文。

執行時顯示的文字

系統通知和你自己的面板頁面由你的程式碼產生,需要自己做多語言。宿主用三種方式告訴你介面語言:程序被 fork 時的環境變數 PIOMODE_LOCALE;使用者切換語言時送來的、帶 locale 欄位的 locale_changed 訊息;面板頁面裡的 pluginHost.getLocale() 和 pluginHost.onLocaleChange()。把譯文表直接寫在 index.js 和頁面 HTML 裡,因為發佈時只會打包 manifest、入口檔案和頁面 HTML。

// ---- index.js (plugin process) ----
const TEXTS = {
  en: { due: 'Due today: COUNT' },
  zh: { due: '今日待办:COUNT' },
};
// undefined on old app versions, '' right after launch (not reported yet), then e.g. 'zh-TW'
let locale = process.env.PIOMODE_LOCALE || '';

process.on('message', (msg) => {
  if (msg.type === 'locale_changed') locale = msg.locale; // the user switched the interface language
});

function text(key, count) {
  const table = TEXTS[locale] || TEXTS[locale.split('-')[0]] || TEXTS.en;
  return table[key].replace('COUNT', String(count));
}

// ---- panel page (view.html / ui.html) ----
const host = window.pluginHost;
const apply = (code) => { /* re-render with the texts for this language code */ };
if (typeof host.getLocale === 'function') host.getLocale().then(apply); // '' until reported
if (typeof host.onLocaleChange === 'function') host.onLocaleChange(apply);
提示
舊版應用程式既沒有這個環境變數,也沒有這兩個方法:先判斷是否存在,不存在就用你的原文語言。應用程式剛啟動時語言可能還沒回報(環境變數是空字串):稍等一下再彈出通知,別用錯語言彈出去。

12文件解析 documentParsers

這個能力已基本停用。用戶端現在對拖進輸入框、有磁碟路徑的檔案只記下路徑,傳送時變成 @path 引用,交給官方命令列自己讀取,不再呼叫外掛解析;documentParsers 目前只被用來判斷「這個 MIME 型別有沒有外掛能解析」,給輸入框裡的附件標記顯示狀態,解析本身不會發生。新外掛不需要實作它;已有的宣告保留無害,但別再往 tools 裡寫解析工具。

13反向 RPC host_request

外掛程序沒有 Electron API,需要「真實系統能力」時向宿主發 host_request,宿主回 host_response 或 host_error。這條通道和 call_tool 完全獨立,可以在處理一次工具呼叫的過程中發起,也可以在計時器裡發起。

capabilityparamsresult前提
show_notification{ title, body?, viewId? }{ shown: true } / { shown: false, reason: "disabled" | "unsupported" }宣告 notifications 權限;使用者在設定裡關閉桌面通知時回傳 disabled 而不是報錯。viewId 指向自己的停靠視圖時,點擊通知會把應用程式拉到前景並展開該視圖。
render_pdf{ outputPath, title, content }{}content 是 Markdown,宿主用內建渲染器產生 PDF 到 outputPath。
rasterize_pdf{ pdfBase64, width, pages: number[] }{ totalPages, images: string[] }不需要權限。把 pdfBase64 裡的 PDF 依 pages(從 1 起)渲染成 width 像素寬的 PNG,images 是 base64 陣列;適合把產物渲染成圖片給模型自查。
piomodel_api_request{ method, path, body? }{ ok: true, envelope: { code, msg, data? } } / { ok: false, message }宣告 account 權限。以目前登入使用者的身分請求 AnBoWork 後端:主程序代為附帶登入 token(token 不進入外掛程序),只放行白名單路徑(見「權限模型」),其它路徑回傳 host_error。envelope 是後端原樣的回應信封。
compose_message{ text }{ delivered: true } / { delivered: false, reason: "no_composer" }不需要權限。把 text 附加到使用者目前輸入框的草稿末尾並聚焦,不送出,由使用者自己決定要不要修改、要不要按送出;不會覆蓋既有內容,沒有呼叫次數限制,單次文字不超過 100000 個字元。目前頁面沒有輸入框(例如設定頁)時回傳 no_composer,不會報錯。面板頁面使用 window.pluginHost.composeMessage(),走同一條通路。
open_external{ url }{ opened: true } / { opened: false, reason: "invalid_params" | "permission_denied" | "not_allowed" }需宣告 <code>account</code> 權限(沒有新增權限名稱)。以系統瀏覽器開啟付款頁,但<strong>只放行</strong>外掛剛從白名單內的 <code>orders/link</code> / <code>renew-orders/link</code> 介面(VPS 下單、續約)取得的 <code>redirect_url</code>:主程序轉發回應時會記下,只能使用一次、20 分鐘內有效、只有取得它的那個外掛能用,且必須是 https 的 <code>/pay?k=…</code> 結帳連結;其他任何網址一律拒絕。回傳 <code>{ opened: true }</code>,或 <code>{ opened: false, reason }</code>(<code>invalid_params</code> / <code>permission_denied</code> / <code>not_allowed</code>),不會拋出錯誤。舊版用戶端沒有這項能力(呼叫會回傳 <code>host_error</code>),請先探測(例如傳入空的 <code>url</code>),沒有就降級成說明文字,不要建立一筆無法付款的訂單。
render_office_cloud
publish_office_preview
{ filePath | url, pages: number[] }
{ filePath }
{ status: "ready" | "pending" | "failed", … }
{ ok: true, url, … }
宣告 account 權限;兩者都會把檔案傳到伺服器。render_office_cloud 把 docx/xlsx/pptx(本機 filePath 或已在線上的 url)轉成頁面圖回給你,轉換還沒完成時回傳 pending,稍後再呼叫;publish_office_preview 把本機 Office 檔案發佈成線上預覽並回傳連結。上傳前的使用者同意要由你的工具用 confirmation 卡片把關。
const crypto = require('crypto');
const fs = require('fs');
const pending = new Map();

function requestHost(capability, params) {
  const requestId = crypto.randomUUID();
  return new Promise((resolve, reject) => {
    const timer = setTimeout(() => {
      pending.delete(requestId);
      reject(new Error(`host capability "${capability}" timed out`));
    }, 30_000);
    pending.set(requestId, { resolve, reject, timer });
    process.send({ type: 'host_request', requestId, capability, params });
  });
}

process.on('message', (msg) => {
  if (msg.type === 'host_response' || msg.type === 'host_error') {
    const p = pending.get(msg.requestId);
    if (!p) return;
    pending.delete(msg.requestId);
    clearTimeout(p.timer);
    if (msg.type === 'host_error') p.reject(new Error(msg.message));
    else p.resolve(msg.result);
  }
});

// usage
await requestHost('show_notification', {
  title: '3 todos for today',
  body: '• Write weekly report\n• Reply to emails',
  viewId: 'board',      // optional: expand this docked view when the notification is clicked
});
// => { shown: true } or { shown: false, reason: 'disabled' | 'unsupported' }

await requestHost('render_pdf', {
  outputPath: '/abs/path/report.pdf',
  title: 'Report',
  content: '# Title\n\nBody (Markdown)',
});

// Rasterize PDF pages to PNG (base64) so the model can look at them. No permission needed.
const { totalPages, images } = await requestHost('rasterize_pdf', {
  pdfBase64: fs.readFileSync('/abs/path/report.pdf').toString('base64'),
  width: 1100,          // output width in pixels
  pages: [1, 2],        // 1-based page numbers
});

// Call the AnBoWork backend as the signed-in user. Requires the "account" permission;
// the token never enters your process, and only allow-listed paths are accepted.
const res = await requestHost('piomodel_api_request', {
  method: 'GET',
  path: '/api/user/sites',
});
// => { ok: true, envelope: { code, msg, data } } or { ok: false, message }

14生命週期

階段行為
啟動預設延遲啟動:應用程式啟動時不拉起,第一次有人呼叫你的工具(AI、頂欄圖示、面板、命令)時才 fork。宣告 activationEvents: ["onStartupFinished"] 的外掛在應用程式啟動完成後立即拉起,給需要背景計時器(到點提醒、輪詢)的外掛用;普通工具型外掛不要宣告。
常駐程序啟動後一直存活,跨多次工具呼叫重用,可以在記憶體裡快取狀態,但要假設隨時可能被重啟。
當機程序意外結束時宿主自動重啟:立即一次,再等 5 秒、15 秒,連續 3 次失敗後標記為「當機」不再重試,使用者在外掛頁能看到狀態。進行中的呼叫全部以錯誤回傳。
停用 / 解除安裝 / 重裝程序被終止,停靠視圖和浮動面板銷毀;重裝是整個目錄推倒重來。
日誌你的 stdout/stderr 會帶著外掛 id 前綴寫進應用程式日誌檔。用 console.log 除錯即可,見「除錯與常見問題」。
環境
子程序以 ELECTRON_RUN_AS_NODE=1 啟動,cwd 是外掛安裝目錄,Node 版本跟用戶端內建的 Electron 一致。不要依賴全域安裝的任何套件,也不要假設有 npx。

15打包與發佈

打包

把外掛目錄打成 zip,manifest.json 必須在壓縮檔根目錄。有第三方依賴時建議先用 esbuild/webpack 打成單一檔案,不要把整個 node_modules 塞進去。

my-plugin.zip
├── manifest.json     # must be at the archive root
├── icon.png          # optional, referenced by manifest.icon
├── index.js
├── view.html
└── node_modules/…    # include dependencies if any (bundling into a single file is recommended)

發佈到市集

AnBoWork → 工具 → 外掛 → 「市集」分頁 → 右上角「發佈外掛」,選擇 zip 上傳。提交後進入待審核狀態,審核會核對 manifest 宣告與程式碼是否一致(尤其是權限)。審核進度和拒絕原因在同一個「發佈外掛」抽屜的「我的提交」裡查看。通過後其他使用者可以在市集裡搜尋安裝,AI 也可以在判斷需要時自動為使用者安裝已認證或官方內建的外掛。

審核與重新提交

同一個外掛 id + 版本號只會有一筆記錄:被拒絕的版本可以修好後用相同版本號重新提交(原記錄重設回待審核);審核中或已通過的版本不能再提交,必須提高 version。一個外掛同時只能有一個待審核版本,先等它出結果再提下一版。

更新

改 version 後重新發佈。用戶端依已安裝版本和市集版本比對提示更新;已啟用且新版本沒有新增權限的外掛,更新時直接以啟用狀態裝上、不再彈知情同意頁(使用者當初的同意仍然涵蓋它),首次安裝或權限擴大時才會再問。重裝會保留使用者的啟用狀態和設定項的值。更新後已經開著的工作階段拿不到新工具,要新建工作階段。

16推薦說明(讓 AI 推薦你的外掛)

外掛安裝之前,AI 看不到工具描述,只能靠 manifest 頂層的 description 判斷「現在該不該推薦這個外掛、要不要自動安裝」。所以這一句就是外掛的推薦說明,值得單獨打磨。

要點寫法
語言與長度用英文,上限 700 字。AI 讀的是這段原文;給使用者看的名稱和簡介另外寫進 localizations(見「國際化」),兩者互不影響。
觸發情境寫成 Install this whenever the user wants to… 這樣的觸發措辭,列出具體情境和同義說法(分享、發布、代管、部署……)。只寫「a todo plugin」這類名詞,模型對不上情境就不會想到裝它。
主動動作要模型主動做的事(例如產生 HTML 後直接發起發布)放在最前面,用祈使句。只寫在工具描述裡沒用,安裝之前模型看不到。
誰會被推薦只有官方內建或已認證開發者的外掛,AI 才會主動推薦並發起安裝;其他外掛只能由使用者在市集裡手動安裝。發起安裝前聊天裡一定會彈出確認卡片,使用者點「安裝」才會裝。
{
  "description": "Publish a finished HTML page to a public share link. After you generate a standalone HTML report, dashboard or prototype, call publish_html right away instead of asking the user how to share it. Install this whenever the user wants to share, publish, host, deploy or send a web page as a link."
}

17完整範例:四象限待辦

一個真實可用的外掛(精簡版):AI 可以增刪待辦,右側欄有即時重新整理的看板,可以彈系統通知提醒。把三個能力串起來正好涵蓋了工具協定、停靠視圖推送和反向 RPC。

{
  "id": "local.todo-quadrant",
  "name": "Todo Quadrant",
  "version": "1.2.0",
  "description": "Daily todo list organized by the Eisenhower matrix. Install this whenever the user wants to track tasks or asks to be reminded about something…",
  "main": "index.js",
  "permissions": ["filesystem", "notifications"],
  "activationEvents": ["onStartupFinished"],
  "tools": [{
    "name": "manage_todo_quadrant",
    "summary": "Add, list, complete, delete and update todos in an urgent/important matrix",
    "description": "Manage the user's daily todo list… Actions: add / list / complete / delete / update / set_reminder / remind_now. add/update also accept remind_at to schedule a one-time reminder for that specific todo. Call this whenever the user talks about their todos…",
    "parameters": {
      "type": "object",
      "properties": {
        "action": { "type": "string", "enum": ["add", "list", "complete", "delete", "update", "set_reminder", "remind_now"] },
        "id": { "type": "string" },
        "content": { "type": "string" },
        "quadrant": { "type": "string", "enum": ["urgent_important", "important_not_urgent", "urgent_not_important", "not_urgent_not_important"] },
        "due_date": { "type": "string", "description": "YYYY-MM-DD" },
        "remind_at": { "type": "string", "description": "YYYY-MM-DD HH:MM — a one-time reminder for this todo, independent of the daily digest" }
      },
      "required": ["action"]
    }
  }],
  "views": [{ "id": "quadrant", "title": "Todo Quadrant", "icon": "checklist", "entry": "view.html", "width": 380 }]
}

18除錯與常見問題

現象原因與解法
安裝時提示 manifest 校驗失敗按提示逐欄位對照「manifest 欄位」表:id 格式、main/entry 不能帶 ..、icon 必須在白名單、keybindings 的 command 必須指向 commands 裡存在的 tool、width 在 240 到 640 之間。
AI 從不呼叫我的工具先確認用的是安裝/啟用之後新建的工作階段——工具是在工作階段啟動時註冊給 AI 的,舊工作階段看不到。其餘幾乎都是 description 的問題:沒寫清楚觸發條件,或者用了非英文。參考「寫好 description 的要點」。也檢查工具名是否和別的工具重名。
呼叫逾時(30 秒)進入點腳本沒有回 tool_result,通常是 requestId 沒原樣帶回、訊息 type 拼錯,或者腳本啟動時就拋例外結束了。看應用程式日誌裡帶 [plugin:你的id] 前綴的行。
外掛狀態顯示「當機」連續 3 次啟動失敗。常見於 require 了不存在的套件;在外掛目錄裡直接 node index.js 能重現。修好後在外掛頁關掉再開啟即可。
面板開啟是空白entry 路徑不對,或者頁面 JS 報錯。頁面執行在沙箱裡,沒有 Node 的 require,只能用 window.pluginHost。
通知沒有彈出依次檢查:manifest 宣告了 notifications;回傳值不是 shown:false(使用者關了桌面通知);系統設定裡允許了 AnBoWork 的通知。
設定項的值讀不到值在 message.context.config[id],不在 params 裡。

日誌檔位置

系統路徑
macOS~/Library/Logs/AnBoWork/main.log
Windows%USERPROFILE%\AppData\Roaming\AnBoWork\logs\main.log
查看 API 接入文件