跳到主要內容

SDK

從你自己的腳本、CI 工作和工具驅動 OpenCode。SDK 在你的處理程序內執行 OpenCode,使用你的設定和模型,其具型別的用戶端可以建立工作階段、傳送提示詞並串流每個事件。

功能

用程式碼修復 CI

一段簡短的腳本請 OpenCode 修復失敗的測試,然後重新執行。

追蹤每一步

串流事件,即時查看代理呼叫的每個工具。

打造自己的工具

只要幾行程式碼,就能把 OpenCode 接入機器人、儀表板和工作流程。

在你的處理程序內

在你的處理程序內執行 OpenCode,使用你的設定和模型。

  • TypeScript 用戶端具型別的請求和事件,與 @opencode/client 的值相同。
  • 用程式碼建立工作階段在任何腳本中建立工作階段並傳送提示詞。
  • 任何模型使用你的 OpenCode 設定中的任何模型。
  • npm 或 bun使用 npm i @opencode/sdk 或 bun add @opencode/sdk 安裝。
  • 同處理程序主機在記憶體中執行 OpenCode,不經過網路。
  • 你的外掛建立同處理程序主機時傳入你自己的外掛。
  • Promise 或 EffectPromise API 和 Effect API,回傳相同的值。
  • Cloudflare Workers在 Workers 上的 Cloudflare Durable Object 中執行 OpenCode。

  • npmnpm i @opencode/sdk
  • bunbun add @opencode/sdk
閱讀 SDK 文件

更新日誌

  1. v2.2.4

    Publish Interactive Artifacts

    Enable "experimental": { "artifacts": true } in opencode.json to let agents publish, update, and serve HTML or static artifacts through the built-in local provider or plugin-provided storage.#60351

    改進

    • SDKExtended client.experimental.persistentPty.update to rename terminals or clear a user title, and exposed userTitle plus persistent-pty.updated events.#60329
  2. v2.2.3

    Added lazy loading for stored image references when experimental.media_blob is enabled

    Added lazy loading for stored image references when experimental.media_blob is enabled. Images are downloaded only for previews, while undo, revert, fork, and prompt recall restore referenced attachments safely.#60116

    改進

    • SDKPreserved partial LLMResponse output on AIError.partial when generation, object generation, or a tool loop fails.#60477
    • SDKUnified Effect and Promise tool declarations around tool(...), with optional output schemas and executable or declaration-only tools.#60407
    • SDKAdded typed OpenRouter debug, models, plugins, provider, and user options to the Responses route.#60044

    修正

    • SDKMatched the Promise AI client more closely to the Effect API and accepted typed tools in loops.#60465#60390
    • SDKKept tools whose execute handler can throw available to the AI client.#60431
    • SDKContinued polling queued media generations when providers return unknown intermediate statuses.#59988
    • SDKStopped sending an incompatible filename alongside file_url on OpenAI Responses requests.#60382
  3. v2.2.2

    Exposed SessionInfo.time.busy for the latest execution’s start time

    改進

    • SDKAdded if and until inputs for client.experimental.schedule.create, plus schedule check results and output fields.#60137
    • SDKAdded optional source metadata to prompt file attachments.
查看所有更新