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.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

    Miglioramenti

    • 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

    Miglioramenti

    • 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

    Correzioni

    • 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

    Miglioramenti

    • 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.
Vedi tutti gli aggiornamenti