pub enum Envelope {
Handshake {
protocol_version: String,
},
HandshakeAck {
protocol_version: String,
provider: ProviderInfo,
capabilities: Capabilities,
},
Query {
id: Option<String>,
query: ContextQuery,
},
Frames {
id: Option<String>,
result: ContextQueryResult,
},
Verify {
request: VerifyRequest,
},
Verified {
response: VerifyResponse,
},
Shutdown,
Error {
id: Option<String>,
code: Option<ErrorCode>,
message: String,
},
}Expand description
One Context Graph Protocol message. Every variant is a small, versioned, type-tagged JSON
object; the host writes exactly one per line (NDJSON) over stdio and one
per HTTP body (SPEC.md §2).
Variants§
Handshake
Host hello: opens the exchange with the protocol version the host
speaks (SPEC.md §3 initialize).
HandshakeAck
Provider hello-back: its protocol version, identity + declared
data-flow direction, and negotiated capabilities (SPEC.md §3). The host
checks the version and surfaces provider.data_flow at consent time.
Query
Host → provider retrieval request (context/query).
Frames
Provider → host budgeted, provenance-carrying frames.
Fields
result: ContextQueryResultVerify
Host → provider revalidation request: are these held frames still
valid (docs/context-reuse.md §4 context/verify)? Carries frame
identities only — never bodies. Capability-gated: a host sends it only
to a provider advertising Capabilities::verify.
Fields
request: VerifyRequestVerified
Provider → host per-frame verdicts.
Fields
response: VerifyResponseShutdown
Lifecycle teardown; the provider should exit cleanly.
Error
Provider-reported failure — lets a provider report a bad request
without dying (SPEC.md §R1 “fail loud”). The host maps this to
HostError::Provider.
Fields
code: Option<ErrorCode>Machine-readable classification (SPEC.md §Errors). Optional so
that a provider written against an earlier revision stays
conformant; a host treats its absence as
ErrorCode::Internal.
Implementations§
Source§impl Envelope
impl Envelope
Sourcepub fn correlation_id(&self) -> Option<&str>
pub fn correlation_id(&self) -> Option<&str>
The correlation id this envelope carries, if any.
None means one of two things, and the caller can tell them apart from
context: either the envelope is a lifecycle message that never carries
one (handshake, shutdown), or the peer does not implement
correlation and the exchange must stay lock-step.
Sourcepub fn error_code(&self) -> Option<ErrorCode>
pub fn error_code(&self) -> Option<ErrorCode>
The error code carried by an error envelope, defaulting to
ErrorCode::Internal when the provider declared none.
Defaulting to Internal rather than to something retryable is the
conservative reading: a host must not infer “safe to retry” from a
provider’s silence.