Przejdź do treści

SDK

Steruj OpenCode z własnych skryptów, zadań CI i narzędzi. SDK uruchamia OpenCode w Twoim procesie, z Twoją konfiguracją i modelami, a typowany klient tworzy sesje, wysyła prompty i strumieniuje każde zdarzenie.

Funkcje

Napraw CI z kodu

Skrypt prosi OpenCode o naprawę nieudanych testów i uruchamia je ponownie.

Śledź każdy krok

Strumieniuj zdarzenia, by na bieżąco widzieć każde narzędzie, którego używa agent.

Własne narzędzia

Podłącz OpenCode do botów, dashboardów i workflowów w kilku linijkach.

W Twoim procesie

Uruchamia OpenCode w Twoim procesie, z Twoją konfiguracją i modelami.

  • Klient TypeScriptTypowane żądania i zdarzenia, z tymi samymi wartościami co @opencode/client.
  • Sesje z koduTwórz sesje i wysyłaj prompty z dowolnego skryptu.
  • Każdy modelUżywa modeli skonfigurowanych w Twoim OpenCode.
  • npm lub bunZainstaluj przez npm i @opencode/sdk lub bun add @opencode/sdk.
  • Host w procesieUruchamia OpenCode w pamięci, bez ruchu sieciowego.
  • Twoje pluginyPrzekaż własne pluginy przy tworzeniu hosta w procesie.
  • Promise lub EffectAPI Promise i API Effect z tymi samymi wartościami.
  • Cloudflare WorkersUruchamiaj OpenCode w Durable Object Cloudflare na Workers.

  • npmnpm i @opencode/sdk
  • bunbun add @opencode/sdk
Czytaj dokumentację SDK

Zmiany

  1. v2.2.7

    session.generate returns tokens and cost along with text

    Zobacz wszystkie najważniejsze zmiany w v2.2.7

    Zmiany niekompatybilne

    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

    Ulepszenia

    • 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

    Zobacz wszystkie najważniejsze zmiany w v2.2.6

    Ulepszenia

    • 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

    Zobacz wszystkie najważniejsze zmiany w v2.2.4

    Ulepszenia

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