Skip to main content

Crate sc_command

Crate sc_command 

Source
Expand description

Lossless sc-ai-cli response envelope and the two server conversions.

Default features export Envelope, OpError, and ErrorKind. Feature server adds the HTTP response conversion and the sealed MCP conversion. That feature is off by default.

The envelope contract version for values this crate creates is ENVELOPE_VERSION ("1"). A value read from JSON keeps the version string it arrived with.

§sc-command

sc-command 0.1.0 is published on crates.io under the MIT license. The repository is https://github.com/randlee/sc-runtime.

Lossless response envelope for a JSON-first CLI or API, plus the conversions that put that envelope on an Axum response or an rmcp tool result.

The default build is the envelope and OpError. The server feature adds the Axum and rmcp conversions and is off by default.

use sc_command::{Envelope, ErrorKind, OpError};
use sc_observability_types::{ErrorCode, Remediation};

let error = OpError::new(
    ErrorKind::Unavailable,
    ErrorCode::new_static("DAEMON.NOT_RUNNING"),
    "the daemon is not running",
)
.with_suggestion("run my-app daemon start");
let envelope = Envelope::from(Err::<(), _>(error));
let value = serde_json::to_value(&envelope)?;
assert_eq!(value["ok"], false);
assert_eq!(value["data"], serde_json::Value::Null);
assert_eq!(
    value["error"]["suggested_action"],
    "run my-app daemon start"
);
let again: Envelope<()> = serde_json::from_value(value)?;
assert!(!again.is_ok());

with_suggestion stores sc_observability_types::Remediation. The wire field suggested_action is that remediation as a JSON string, or JSON null when no remediation is set.

Modules§

observability
Application-owned canonical logging injection without a logging runtime. Canonical event injection without linking a logging runtime.

Structs§

OpError
Operation error inside a response envelope.

Enums§

Envelope
sc-ai-cli response envelope.
ErrorKind
Coarse class of an OpError. The HTTP status is a pure function of this class.

Constants§

DISCRIMINANT_CODE
Stable code for an envelope whose ok flag disagrees with data or error, or whose object is missing a required key.
ENVELOPE_VERSION
Envelope contract version written by constructors in this crate.
SERIALIZATION_CODE
Stable code for a payload whose Serialize implementation fails.