opencode-server-sdk

    Native MoonBit SDK for starting and managing an OpenCode server

    opencode
    sdk
    server
    process
    Download zip
    Author
    Version
    0.2.0
    License
    MIT
    Last updated
    3 months ago
    Downloads
    44

    #opencode-server-sdk

    Native MoonBit SDK for starting and managing an OpenCode server.

    The server lifecycle follows the handwritten TypeScript SDK contract. This package owns only the server process and its announced URL; callers may use the HTTP client of their choice.

    #Usage

    @async.with_task_group() <| group => {
    let server = @opencode.create_opencode_server(group)
    println(server.url())
    server.close()
    }

    The task group must outlive the returned server. Call Server::close inside the task-group body on both success and failure; task-group defers run only after child tasks finish, while the managed server is itself a long-lived child task.

    Use totto2727/opencode-sdk instead when the application should run agent turns through the opencode CLI.

    ServerError

    pub(all) suberror ServerError {
    StartFailed(String)
    StartTimeout(timeout_ms~ : Int, output~ : String)
    MalformedOutput(line~ : String)
    ServerExited(code~ : Int, output~ : String)
    CleanupFailed(String)
    } derive(
    Debug
    )

    Failures that can occur while starting or stopping an OpenCode server.

    Server

    pub struct Server {
    url : String
    process :
    Process

    log_dir : String
    closed : Bool
    }

    A running OpenCode server owned by the task group passed at creation.

    Server::close

    async fn Server::close(self : Server) -> Unit raise ServerError

    Stop the server, wait for its process, and remove its temporary logs.

    Calling close again after a successful close has no effect.

    Server::url

    fn Server::url(self : Server) -> String

    Return the HTTP base URL announced by the OpenCode server.

    ServerOptions

    pub struct ServerOptions {
    hostname : String
    port : Int
    timeout_ms : Int
    config : Json
    } derive(
    Debug
    )

    Options for starting an OpenCode server.

    When port is omitted, OpenCode selects an available port.

    ServerOptions::ServerOptions

    fn ServerOptions::ServerOptions(hostname? : String, port? : Int, timeout_ms? : Int, config? : Json) -> ServerOptions

    Construct server options.

    create_opencode_server

    async fn[X] create_opencode_server(group :
    TaskGroup
    [X], options? : ServerOptions, command? : String, extra_env? : Map[String, String]) -> Server raise ServerError

    Start an OpenCode server in group.

    The task group must outlive the returned server. The process is started as opencode serve, receives OPENCODE_CONFIG_CONTENT, and is hard-cancelled when startup fails or close is called.

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io