Skip to main content

ExtensionRuntime

Struct ExtensionRuntime 

Source
pub struct ExtensionRuntime { /* private fields */ }

Implementations§

Source§

impl ExtensionRuntime

Source

pub fn new(config: RuntimeConfig) -> Result<Self, RuntimeError>

Source

pub fn for_test() -> Self

Construct a runtime with no extensions loaded, for downstream unit tests that need an ExtensionRuntime instance but do not exercise real WASM dispatch.

Uses production-safe HostOverrides::default() and a throwaway discovery path that is never read (no extension is ever loaded). list_tools returns empty; invoke_tool returns a not-found error.

This exists so crates like greentic-aw-runtime can build an Arc<ExtensionRuntime> in --features test-mock unit tests without a live extension directory. Do NOT use in production.

Source

pub fn with_host_overrides(self, host_overrides: HostOverrides) -> Self

Replace the HostOverrides bundle used for every dispatch. Call once at startup with adapters that wrap real backends (i18n catalogue, secrets store, allow-listed HTTP client). Without this, host fns resolve through HostOverrides::default — fine for unit tests, not for production: i18n returns the key, secrets are empty, http allow-list is empty.

This is a thin ergonomic wrapper over RuntimeConfig::with_host_overrides for callers that already hold an ExtensionRuntime instance:

let runtime = ExtensionRuntime::new(config)?
    .with_host_overrides(production_overrides);
Source

pub fn engine(&self) -> &Engine

Source

pub fn subscribe(&self) -> Receiver<RuntimeEvent>

Source

pub fn config(&self) -> &RuntimeConfig

Source

pub fn loaded(&self) -> Arc<HashMap<ExtensionId, LoadedExtensionRef>>

Source

pub fn capability_registry(&self) -> Arc<CapabilityRegistry>

Source

pub fn register_loaded_from_dir( &mut self, dir: &Path, ) -> Result<(), RuntimeError>

Source

pub fn start_watcher(self: Arc<Self>) -> Result<WatcherGuard, RuntimeError>

Spawns a watcher background thread. Events trigger reload of the affected extension’s directory. Returns a stop sender — dropping or sending on it signals the watcher thread to exit. Also returns the thread JoinHandle for callers that want to wait for clean shutdown.

Source§

impl ExtensionRuntime

Source

pub fn invoke_tool( &self, ext_id: &str, tool_name: &str, args_json: &str, ) -> Result<String, RuntimeError>

Invoke a named tool on a loaded extension.

Builds a fresh wasmtime Store + Instance, calls greentic:extension-design/tools::invoke-tool (resolved newest-first across 0.3.0/0.2.0/0.1.0; WIT errors surface as RuntimeError::Extension), and returns the JSON result string.

Source

pub fn invoke_tool_ctx( &self, ext_id: &str, tool_name: &str, args_json: &str, ctx: &HostCallContext, ) -> Result<String, RuntimeError>

Like Self::invoke_tool but threads a per-call crate::host_ports::HostCallContext (e.g. the caller’s tenant slug) into the host ports for this dispatch. Multi-tenant hosts (the designer) use this so the LLM port can resolve roles per-tenant.

Source§

impl ExtensionRuntime

Source

pub fn evaluate_guardrail( &self, ext_id: &str, input_json: &str, ) -> Result<String, RuntimeError>

Evaluate a guardrail extension against input_json and return the verdict as a JSON string.

Loads the extension identified by ext_id, resolves the greentic:extension-design/guardrail@0.3.0 interface, calls the evaluate export, and maps the returned verdict variant to crate::GuardrailVerdictWire serialised as JSON.

input_json must be a JSON object with fields matching the WIT guardrail-input record:

{
  "direction": "inbound",
  "content": "…",
  "agent_id": "…",
  "session_id": "…",
  "tenant_id": "…",
  "env_id": "…",
  "context": null
}

Returns the verdict as JSON, e.g. {"kind":"accept"} or {"kind":"deny","code":"…","message":"…","details":null}.

§Errors
  • RuntimeError::NotFound when no extension is loaded at ext_id.
  • RuntimeError::Wasmtime when store/instance construction fails, the interface is not exported, the typed-func call fails, or input_json cannot be deserialised.
Source§

impl ExtensionRuntime

Source

pub fn validate_content( &self, ext_id: &str, content_type: &str, content_json: &str, ) -> Result<ValidateResult, RuntimeError>

Validate extension-specific content against the extension’s schema.

Calls greentic:extension-design/validation::validate-content (resolved against @0.2.0 first, then @0.1.0). content_type is an extension-defined label (e.g. "AdaptiveCard" for the adaptive-cards extension); content_json is the content payload as a JSON string.

Returns a [types::ValidateResult] with a valid flag and a list of diagnostics (error/warning/info/hint severities). Extensions that don’t export this interface surface a Wasmtime error — callers that want graceful degradation should treat “interface not exported” as “no validation available” rather than a hard failure.

Source§

impl ExtensionRuntime

Source

pub fn list_tools( &self, ext_id: &str, ) -> Result<Vec<ToolDefinition>, RuntimeError>

List all tools exposed by a loaded design extension.

Calls greentic:extension-design/tools::list-tools (resolved against @0.2.0 first, then @0.1.0) for v1-contract extensions. v2 contract (apiVersion == "greentic.ai/v2") reads the tools from describe.contributions.tools[] — the runtime WIT no longer exports list-tools in that contract. The declarative v2 entries only carry name + export, so description / input_schema_json come back empty; callers that need full schemas must introspect the named WIT export.

Source§

impl ExtensionRuntime

Source

pub fn prompt_fragments( &self, ext_id: &str, ) -> Result<Vec<PromptFragment>, RuntimeError>

Retrieve system prompt fragments from a loaded design extension.

Calls greentic:extension-design/prompting::system-prompt-fragments (resolved against @0.2.0 first, then @0.1.0).

Source§

impl ExtensionRuntime

Source

pub fn knowledge_list( &self, ext_id: &str, category_filter: Option<&str>, ) -> Result<Vec<KnowledgeEntrySummary>, RuntimeError>

List knowledge entries, optionally filtered by category.

Calls greentic:extension-design/knowledge::list-entries (resolved against @0.2.0 first, then @0.1.0).

Source

pub fn knowledge_get( &self, ext_id: &str, entry_id: &str, ) -> Result<KnowledgeEntry, RuntimeError>

Retrieve a single knowledge entry by ID.

Calls greentic:extension-design/knowledge::get-entry, resolving the interface newest-first across @0.3.0/@0.2.0/@0.1.0. The matched version selects which extension-error ABI to deserialize (6-variant base at @0.3.0, 4-variant base at @0.2.0/@0.1.0); WIT errors surface as RuntimeError::Extension.

Source

pub fn knowledge_suggest( &self, ext_id: &str, query: &str, limit: u32, ) -> Result<Vec<KnowledgeEntrySummary>, RuntimeError>

Suggest knowledge entries matching a query.

Calls greentic:extension-design/knowledge::suggest-entries (resolved against @0.2.0 first, then @0.1.0).

Source§

impl ExtensionRuntime

Source

pub fn validate_credentials( &self, ext_id: &str, target_id: &str, credentials_json: &str, ) -> Result<Vec<Diagnostic>, RuntimeError>

Ask a deploy extension to validate a credentials JSON payload for the given target. Returns diagnostics; empty slice means valid.

Source§

impl ExtensionRuntime

Source

pub fn credential_schema( &self, ext_id: &str, target_id: &str, ) -> Result<String, RuntimeError>

Return the JSON Schema (as a string) describing credentials required by the given deploy target.

Source§

impl ExtensionRuntime

Source

pub fn list_targets( &self, ext_id: &str, ) -> Result<Vec<TargetSummary>, RuntimeError>

Enumerate targets exported by a loaded deploy extension.

Returns the list-targets output as host-side TargetSummary values.

Source§

impl ExtensionRuntime

Source

pub fn render_bundle( &self, ext_id: &str, recipe_id: &str, config_json: &str, session: BundleSession, ) -> Result<BundleArtifact, RuntimeError>

Render a bundle artefact by dispatching to a loaded bundle extension’s bundling.render export.

Mirrors the in-process call site that replaces the legacy greentic-bundle ext render subprocess pipeline. The host passes the designer session (flow JSON, content JSON, asset blobs, capability list) and a recipe-specific config string; the extension’s WASM returns the rendered bytes (typically a .gtpack zip) plus the canonical filename and sha256 the extension wants written.

Returns RuntimeError::NotFound when no extension is loaded at ext_id. The bundling interface is resolved newest-first across @0.2.0/@0.1.0; host-level failures surface as RuntimeError::Wasmtime, while the extension’s WIT-level error surfaces as RuntimeError::Extension (6-variant base at @0.2.0, 4-variant base at @0.1.0).

Source§

impl ExtensionRuntime

Source

pub fn deploy( &self, ext_id: &str, req: DeployRequest, ) -> Result<DeployJob, RuntimeError>

Start a deployment inside the extension. Returns the initial job.

Calls greentic:extension-deploy/deployment::deploy, resolving the interface newest-first across @0.2.0/@0.1.0. The matched version selects the extension-error ABI (6-variant base at @0.2.0, 4-variant base at @0.1.0). The call is synchronous and may take up to ~2 minutes for network-bound extensions (artifact upload); run it on a blocking thread.

Source

pub fn deploy_poll( &self, ext_id: &str, job_id: &str, ) -> Result<DeployJob, RuntimeError>

Poll a previously started deployment job.

Source

pub fn deploy_rollback( &self, ext_id: &str, job_id: &str, ) -> Result<(), RuntimeError>

Roll back a previously started deployment job.

Source§

impl ExtensionRuntime

Source

pub fn invoke_composer_metadata( &self, ext_id: &str, ) -> Result<String, RuntimeError>

Call greentic:dw-composer/composer::metadata and return the JSON descriptor string.

The designer parses the returned JSON into its own ComposerDescriptor type. No input argument is required — the function takes no parameters.

§Errors

Returns RuntimeError::NotFound when no extension is loaded at ext_id, and RuntimeError::Wasmtime for any host-level failure (missing interface, trap, type mismatch).

Source

pub fn invoke_composer_compose( &self, ext_id: &str, intent_json: &str, ) -> Result<Result<String, HostExtensionError>, RuntimeError>

Call greentic:dw-composer/composer::compose(intent_json) and return the rendered manifest JSON on success or a canonical crate::types::HostExtensionError on failure.

intent_json is a JSON-serialised ComposeIntent whose schema is defined by the specific composer extension. The Ok variant carries the rendered manifest JSON; the Err variant carries a HostExtensionError (v0.1.0 bare strings map to Internal).

§Errors

Returns RuntimeError::NotFound when no extension is loaded at ext_id, and RuntimeError::Wasmtime for any host-level failure (missing interface, trap, type mismatch). A business-logic failure inside the composer is NOT a RuntimeError — it is the Err(HostExtensionError) inside the returned Ok(Result<String, HostExtensionError>).

Source

pub fn invoke_composer_validate( &self, ext_id: &str, manifest_json: &str, ) -> Result<String, RuntimeError>

Call greentic:dw-composer/composer::validate(manifest_json) and return the JSON validation report string.

The returned string is a JSON-serialised ValidationReport (exact schema is defined by the composer extension — typically an array of diagnostic objects or an object with a valid boolean field).

§Errors

Returns RuntimeError::NotFound when no extension is loaded at ext_id, and RuntimeError::Wasmtime for host-level failures.

Source

pub fn invoke_composer_templates( &self, ext_id: &str, ) -> Result<String, RuntimeError>

Call greentic:dw-composer/composer::templates and return the JSON array string of ComposerTemplate objects.

§Errors

Returns RuntimeError::NotFound when no extension is loaded at ext_id, and RuntimeError::Wasmtime for host-level failures.

Source§

impl ExtensionRuntime

Source

pub fn list_roles(&self, ext_id: &str) -> Result<Vec<RoleSpec>, RuntimeError>

List all roles exposed by a loaded design extension.

Calls greentic:extension-design/roles::list-roles (resolved against @0.3.0 first, then @0.2.0). Returns an empty vec when the extension does not export the roles interface (older 0.1.0 extensions, for example) so callers can treat it as “no roles published” without reaching for RuntimeError::Wasmtime.

Source

pub fn validate_role( &self, ext_id: &str, name: &str, entry_json: &str, ) -> Result<Vec<Diagnostic>, RuntimeError>

Run the cheap-path validator for a role’s DSL entry.

Calls greentic:extension-design/roles::validate-role (resolved against @0.3.0 first, then @0.2.0). Returns the diagnostic list verbatim (empty = valid, mirrors the WIT contract). RuntimeError is reserved for host failures — missing extension, missing interface, wasmtime trap.

Source

pub fn compile_role( &self, ext_id: &str, name: &str, target: TargetKind, entry_json: &str, ctx: Option<&CompileContext>, ) -> Result<String, RoleError>

Compile a single DSL entry to its target representation.

Calls greentic:extension-design/roles::compile-role (resolved against @0.3.0 first, then @0.2.0). A missing extension surfaces as RoleError::UnknownRole(ext_id) (the registry can’t tell “no extension” apart from “no role” from the LLM’s perspective and both should retry with a hint). Host failures (wasmtime trap, missing interface) surface as RoleError::Host(HostExtensionError::Internal(_)) so the caller can match exhaustively without juggling two error types.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Pointer = u32

Source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more