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

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.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.
ดูอัปเดตทั้งหมด