Skip to main content

Module extension

Module extension 

Source
Expand description

ExtensionPoint<T>: a typed, name-indexed, hot-swappable collection.

In behest’s composable model, every pluggable category of runtime element — chat providers, embedding providers, tools, context adapters, stores, publishers, transports — is exposed as an ExtensionPoint<T>. Operators compose a runtime by registering implementations by name, and can replace any registered instance at runtime.

§Design

  • Name-indexed: every entry is keyed by a stable string. The same name space is shared with the component registry, so config files can reference extensions by name (e.g. "primary", "fallback-eu").
  • Clonable: the inner state is wrapped in an Arc, so cloning an ExtensionPoint is cheap. A clone observes every registration performed on the original.
  • Hot-swappable: ExtensionPoint::replace atomically swaps the stored Arc<T> and returns the previous one. Callers holding the old Arc continue to use it; new get calls return the new instance.
  • In-use detection: ExtensionPoint::unregister refuses to drop an entry whose strong count is above the registry’s reference (one reference for the storage slot). This catches the common bug of removing a provider that is still serving a run.

§Example

use std::sync::Arc;
use behest_runtime::extension::ExtensionPoint;

let ep: ExtensionPoint<String> = ExtensionPoint::new();
ep.register("greeting", Arc::new("hello".to_string())).unwrap();
assert_eq!(ep.get("greeting").map(|s| (*s).clone()), Some("hello".to_string()));

Structs§

ExtensionPoint
Typed, name-indexed collection of Arc<T>.

Enums§

ExtensionError
Errors raised by ExtensionPoint operations.