Skip to main content

Crate evorule_plugin_kit

Crate evorule_plugin_kit 

Source
Expand description

In-process native plugin mechanism common crate for evorule-services.

This crate defines the NativeService trait, the NativeServiceDef declaration entry, and the generic filter router shared by all plugin families. Each family keeps its own declaration table; the host mounts the router with a per-family enable set.

§Components

  • NativeService: the uniform in-process service entry point.
  • NativeServiceDef: declarative registration entry (name, sensitivity flag, one-line description, optional JSON Schema parameter contract, instance constructor).
  • NativeServiceRouter: composite IoHandler that dispatches by service_name to a native service and falls back to HTTP otherwise.
  • mount_router: mount helper producing an Arc<dyn IoHandler>.

§Enable semantics

NativeServiceRouter::with_enabled and mount_router enforce three fail-fast rejections: unknown name, duplicate name, empty enable set. Router lookup always follows declaration order, regardless of the order of the enable set passed in.

§Async extension point

NativeService::execute_async is an async extension point whose default implementation wraps the synchronous execute in an immediately-ready future, so non-overriding services keep byte-for-byte identical behavior. The router always awaits execute_async, which makes overriding fully transparent to callers.

Services that need external I/O (HTTP egress, long polling, and similar) MUST override this method; they must not perform egress from the synchronous execute (no runtime support on that path). Any degraded result (e.g. a local stub while the external service is unavailable) must be truthfully labeled in the returned body; a stub must never impersonate the real service.

§Usage (plugin side)

  • Export a &'static [NativeServiceDef] declaration table: adding a native capability = append one entry + enable it in the plugin manifest; the host and the mechanism need zero changes.
  • Services with a fixed parameter surface declare parameters as a JSON Schema string (OpenAI function parameters subset); it is forwarded to LLM consumers via the capability inventory.
  • Wrap the table with mount_router (or use NativeServiceRouter directly) to obtain the mountable handler.

Structs§

NativeServiceDef
Native service declaration entry (declarative registration: adding a native capability = appending one entry to the plugin declaration table; the router, the capability inventory, and binding checks need zero changes).
NativeServiceRouter
Composite IoHandler: a service_name hit on a native service name dispatches natively; otherwise falls back to HTTP.

Enums§

JsonValue
JSON value type (deterministic implementation).
MetaOutcome
Outcome of one meta-instruction execution, mirrored arm-for-arm from the canonical executor’s result type (state / io-required / halted).

Constants§

GATEWAY_UNAVAILABLE_ERR
Canonical fail-visible error for mechanism calls without a registered gateway. Byte-stable by design: host-side and guest-side runs must produce the identical error text so downstream golden vectors and parity comparisons stay deterministic.

Traits§

IoHandler
I/O handler trait — all I/O handlers implement this interface.
MechanismGateway
Host-side mechanism executor: synchronous pure-function view over the canonical meta-instruction state machine.
NativeService
Uniform entry point for native services: receives args (with __ paths already resolved to concrete values by the engine) and returns the business result.

Functions§

mechanism_gateway
Registered gateway, if any. Hosts register at startup; guests never do.
mount_router
Mount helper: builds an Arc<dyn IoHandler> with enable semantics (referenced directly by the server-side PluginDef, avoiding per-family wrapper constructors).
register_mechanism_gateway
Register the process-wide mechanism gateway (host startup / plugin loading path).
require_mechanism_gateway
Fail-visible accessor: the registered gateway or GATEWAY_UNAVAILABLE_ERR. Mechanism-dependent services must go through this accessor (never silently degrade when mechanism_gateway is None).
serde_to_tcb
Convert a serde_json::Value into the canonical JsonValue form.

Type Aliases§

IoResult
I/O execution result.
ObjectMap
Object backend type (BTreeMap guarantees deterministic iteration).