Skip to main content

Module registry

Module registry 

Source
Expand description

The registry’s pure half: what a primitive is, who may see it, and the immutable set a publish hands to readers.

Nothing here touches an ArcSwap, a lock, or a clock. The types in this module are the values that get stored, the rule that decides visibility, and the snapshot they are packed into — the decision half of the problem, with the concurrency half left to application::registry.

The split is load-bearing in one direction and cosmetic in the other. is_visible must be pure because the whole feature-gating capability is a claim that a filter is a function of its inputs, and a function that can observe a lock’s state is not one. Snapshot has no mutating method because the publish is the transaction boundary, and a value that can be edited in place has no boundary at all.

§Examples

use protocol_droid::domain::registry::{
    AuthContext, Primitive, Registered, Scope, ScopeSet, Snapshot, Tool, is_visible,
};
use protocol_droid::domain::FeatureProfile;

let mut builder = Snapshot::builder();
builder.insert(Primitive::from(Tool::new("echo", r#"{"type":"object"}"#)?));
let snapshot = builder.build();

// A session holding every scope sees a tool that asks for none.
let alice = AuthContext::unrestricted("alice");
let registered = Registered::from(Primitive::from(
    Tool::new("echo", r#"{"type":"object"}"#)?,
));
assert!(is_visible(&alice, &FeatureProfile::all(), &registered.meta()));

// A session holding no scope does not see a tool that asks for one.
let restricted = AuthContext::new("bob", ScopeSet::empty());
let guarded = registered
    .clone()
    .requiring_scope(Scope::Admin)
    .requiring(FeatureProfile::all().as_set());
assert!(!is_visible(&restricted, &FeatureProfile::all(), &guarded.meta()));

Re-exports§

pub use auth::AuthContext;
pub use auth::Scope;
pub use auth::ScopeSet;
pub use primitive::Primitive;
pub use primitive::PrimitiveId;
pub use primitive::PrimitiveKind;
pub use primitive::Prompt;
pub use primitive::PromptArgument;
pub use primitive::Registered;
pub use primitive::Resource;
pub use primitive::ResourceTemplate;
pub use primitive::Tool;
pub use snapshot::Snapshot;
pub use snapshot::SnapshotBuilder;
pub use visibility::is_visible;
pub use visibility::missing_features;
pub use visibility::missing_scopes;

Modules§

auth
AuthContext — the identity a visibility rule is evaluated against.
primitive
The primitives a registry holds: tools, resources, resource templates, and prompts.
snapshot
Snapshot — the immutable set a registry publishes — and the builder that produces the next one.
visibility
The visibility rule: may this session see this primitive?