Skip to main content

Crate muse_code_sdk

Crate muse_code_sdk 

Source
Expand description

Async, caller-runtime-owned Rust client for the Muse Stream Protocol.

The SDK can spawn a muse serve host, or attach to a caller-owned DuplexTransport. Both constructors complete the initialization handshake before returning a client::MuseClientConnection, including any warning-only schema fingerprint mismatch.

A session::Session submits turns (session::Session::send_user_turn), answers approvals through a handler (session::Session::on_approval) and questions (session::Session::answer_user_input), and keeps a fold of the events it applied, read through session::Session::fold. After a transport drop on a durable client, session::Session::pending lists the submissions it never saw settle, and session::Session::resolve_reconnect resends them on the resumed session.

use muse_code_sdk::client::{MuseClient, StartSessionOptions};
use muse_code_sdk::msp::{TurnInputPart, TurnInputPartType};
use muse_code_sdk::session::SendUserTurnOptions;
use muse_code_sdk::spawn::SpawnOptions;
use muse_code_sdk::turn::TurnOutcome;

let connection = MuseClient::spawn(SpawnOptions::default()).await?;
let client = connection.client;
let session = client.start_session(StartSessionOptions::default()).await?;
let turn = session
    .send_user_turn(SendUserTurnOptions {
        input: vec![text_part("Summarize this repository.")],
        ..SendUserTurnOptions::default()
    })
    .await?;

let mut items = turn.items();
while let Some(item) = items.recv().await? {
    drop(item);
}
match turn.completed().await? {
    TurnOutcome::Completed { params, .. } => println!("turn ended as {:?}", params.terminal),
    TurnOutcome::Unqueued(params) => println!("turn {} was unqueued", params.turn_id),
    _ => println!("turn ended"),
}
client.close().await;

Modules§

approval
Approval handler routing.
client
Client lifecycle and command-id minting.
connection
MSP NDJSON framing and request matching.
errors
Typed SDK errors.
fingerprint
Stable schema pin and compatibility warning.
fold
Ephemeral fold. Params stay as JSON so newer open values survive verbatim.
gap
Reattach and delivery-gap recovery.
handshake
MSP initialization handshake.
host_death
Host-exit attribution helpers.
msp
Stable Muse Session Protocol (MSP) wire types.
pending
Locally pending command bookkeeping.
session
Session verbs and turn submission.
spawn
Host discovery and process ownership.
turn
Streaming turn handle.

Traits§

DuplexTransport
A two-way stream of decoded UTF-8 chunks and outgoing newline-framed MSP.