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.
- Error
Kind - Coarse class of an
OpError. The HTTP status is a pure function of this class.
Constants§
- DISCRIMINANT_
CODE - Stable code for an envelope whose
okflag disagrees withdataorerror, 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
Serializeimplementation fails.