Vai al contenuto

SDK

Controlla OpenCode dai tuoi script, job di CI e strumenti. L'SDK esegue OpenCode nel tuo processo, con la tua configurazione e i tuoi modelli, e il suo client tipizzato crea sessioni, invia prompt e trasmette ogni evento.

Funzionalità

Ripara la CI da codice

Un breve script chiede a OpenCode di correggere i test falliti, poi li riesegue.

Segui ogni passo

Trasmetti gli eventi e vedi ogni strumento chiamato dall'agente.

Crea i tuoi strumenti

Integra OpenCode in bot, dashboard e workflow con poche righe.

Nel tuo processo

Esegue OpenCode nel tuo processo, con la tua config e i tuoi modelli.

  • Client TypeScriptRichieste ed eventi tipizzati, con gli stessi valori di @opencode/client.
  • Sessioni da codiceCrea sessioni e invia prompt da qualsiasi script.
  • Ogni modelloUsa i modelli configurati nel tuo OpenCode.
  • npm o bunInstallalo con npm i @opencode/sdk o bun add @opencode/sdk.
  • Host in-processEsegue OpenCode in memoria, senza passare dalla rete.
  • I tuoi pluginPassa i tuoi plugin quando crei l'host in-process.
  • Promise o EffectUn'API Promise e un'API Effect con gli stessi valori.
  • Cloudflare WorkersEsegui OpenCode in un Durable Object di Cloudflare su Workers.

  • npmnpm i @opencode/sdk
  • bunbun add @opencode/sdk
Leggi la documentazione dell'SDK

Changelog

  1. v2.2.7

    session.generate returns tokens and cost along with text

    Vedi tutte le novità principali di v2.2.7

    Modifiche incompatibili

    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

    Miglioramenti

    • 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

    Vedi tutte le novità principali di v2.2.6

    Miglioramenti

    • 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

    Vedi tutte le novità principali di v2.2.4

    Miglioramenti

    • SDKExtended client.experimental.persistentPty.update to rename terminals or clear a user title, and exposed userTitle plus persistent-pty.updated events.#60329
Vedi tutti gli aggiornamenti