opencode-sdk

    MoonBit SDKs for OpenCode CLI execution and managed Server lifecycle

    opencode
    sdk
    cli
    server
    moonbit
    Download zip
    Author
    Version
    0.4.2
    License
    MIT
    Last updated
    6 hours ago
    Downloads
    344

    #moonbit: backend: wasm import: - path: moonbitlang/async@0.21.0 - path: totto2727/opencode-sdk@0.4.2/cli alias: opencode

    #OpenCode SDK for MoonBit

    totto2727/opencode-sdk provides MoonBit SDKs for running OpenCode through its CLI and managing an OpenCode server process.

    #Usage

    The inline CLI example is the common consumer flow. For package-distinct checked behavior, use the CLI thread flows or the managed Server health example.

    Ask OpenCode to explain a repository and return the completed response:

    ///|
    async test "CLI usage - requests a repository explanation" {
    let client = @opencode.Client::Client()
    let turn = client.start_thread().run(
    @opencode.Input::Prompt("Explain this repository in one paragraph"),
    )
    println(turn.final_response)
    }

    #Key features

    • Typed JSONL events and buffered or streamed turns for opencode run --format json.
    • New and resumed OpenCode sessions with configurable model, agent, directory, files, and environment.
    • Native managed opencode serve lifecycle with readiness URL parsing, timeout errors, and idempotent cleanup.

    The CLI package prefers wasm, also supports native, and raises typed SdkError values for invalid events, failed turns, and nonzero exits. The managed Server package is native-only and raises typed ServerError values for startup, readiness, exit, timeout, and cleanup failures.

    #Prerequisites

    • MoonBit: Install the MoonBit toolchain.
    • OpenCode: Install the opencode executable and make it available on PATH for CLI or server execution.

    #Setup

    1. Add the published module to the MoonBit project.

    moon add totto2727/opencode-sdk@0.4.2

    1. Import the package required by the application in moon.pkg.

    ///|
    import {
    "totto2727/opencode-sdk/cli" @opencode,
    }

    Use totto2727/opencode-sdk/server for the native managed server package.

    1. When using the native Server package, add its direct async dependency and import both packages.

    moon add moonbitlang/async@0.21.0

    ///|
    import {
    "moonbitlang/async",
    "totto2727/opencode-sdk/server" @opencode,
    }

    #API

    #Development

    For repository structure, ownership, targets, and executable development commands, see AGENTS.md.

    #License

    This README was generated from the share-artifact skill and README template.