ข้ามไปยังเนื้อหา

SDK

ควบคุม OpenCode จากสคริปต์ งาน CI และเครื่องมือของคุณเอง SDK รัน OpenCode ภายในโปรเซสของคุณด้วยการตั้งค่าและโมเดลของคุณ และไคลเอนต์แบบมีชนิดข้อมูลจะสร้างเซสชัน ส่งพรอมต์ และสตรีมทุกอีเวนต์

ฟีเจอร์

แก้ CI จากโค้ด

สคริปต์สั้นๆ ขอให้ OpenCode แก้เทสต์ที่ล้มเหลว แล้วรันเทสต์อีกครั้ง

ติดตามทุกขั้นตอน

สตรีมอีเวนต์เพื่อดูเครื่องมือแต่ละตัวที่เอเจนต์เรียกใช้ ทันทีที่เกิดขึ้น

สร้างเครื่องมือของคุณ

เชื่อม OpenCode เข้ากับบอต แดชบอร์ด และเวิร์กโฟลว์ด้วยโค้ดไม่กี่บรรทัด

ในโปรเซสของคุณ

รัน OpenCode ภายในโปรเซสของคุณ ด้วยการตั้งค่าและโมเดลของคุณ

  • ไคลเอนต์ TypeScriptคำขอและอีเวนต์แบบมีชนิดข้อมูล ใช้ค่าเดียวกับ @opencode/client
  • เซสชันจากโค้ดสร้างเซสชันและส่งพรอมต์จากสคริปต์ใดก็ได้
  • โมเดลใดก็ได้ใช้โมเดลที่ตั้งค่าไว้ใน OpenCode ของคุณ
  • npm หรือ bunติดตั้งด้วย npm i @opencode/sdk หรือ bun add @opencode/sdk
  • โฮสต์ในโปรเซสรัน OpenCode ในหน่วยความจำ โดยไม่ผ่านเครือข่าย
  • ปลั๊กอินของคุณส่งปลั๊กอินของคุณเข้าไปเมื่อสร้างโฮสต์ในโปรเซส
  • Promise หรือ EffectAPI แบบ Promise และแบบ Effect ที่ให้ค่าเดียวกัน
  • Cloudflare Workersรัน OpenCode ใน Cloudflare Durable Object บน Workers

  • npmnpm i @opencode/sdk
  • bunbun add @opencode/sdk
อ่านเอกสาร SDK

บันทึกการเปลี่ยนแปลง

  1. v2.2.7

    session.generate returns tokens and cost along with text

    ดูไฮไลต์ทั้งหมดใน v2.2.7

    การเปลี่ยนแปลงที่ไม่เข้ากัน

    SDK: fewer endpoints wait for plugins to load

    On a Location that is still loading plugins, agent.list returns the agents loaded so far, and integration.list, usage.limits, vcs.init, rpc.call and artifact.* no longer wait up to 5 seconds. Entries and actions that a plugin provides appear when it finishes loading, so refresh on the matching *.updated event. Model, provider, generate.*, voice.* and websearch.query endpoints still wait.

    #62796#63040

    การปรับปรุง

    • SDKcredential.updated includes the integrationID and credentialID of the login that changed.#62762
    • SDKPredicate questions in client.experimental.generate.decisions accept optional criteria: { true?, false? }.#62819
  2. v2.2.6

    Improvements

    ดูไฮไลต์ทั้งหมดใน v2.2.6

    การปรับปรุง

    • SDKAdded client.experimental.job.list() and its Effect equivalent for listing background shell, subagent, and image jobs, with session, descendant, kind, and status filters.#60698
    • SDKServer embedders can provide a custom fetch implementation for OpenCode HTTP, model, web, and remote MCP traffic.#61582
  3. 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

    ดูไฮไลต์ทั้งหมดใน v2.2.4

    การปรับปรุง

    • SDKExtended client.experimental.persistentPty.update to rename terminals or clear a user title, and exposed userTitle plus persistent-pty.updated events.#60329
ดูอัปเดตทั้งหมด