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: compositeIoHandlerthat dispatches byservice_nameto a native service and falls back to HTTP otherwise.mount_router: mount helper producing anArc<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
parametersas 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 useNativeServiceRouterdirectly) to obtain the mountable handler.
Structs§
- Native
Service Def - 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).
- Native
Service Router - Composite IoHandler: a
service_namehit on a native service name dispatches natively; otherwise falls back to HTTP.
Enums§
- Json
Value - JSON value type (deterministic implementation).
- Meta
Outcome - 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.
- Mechanism
Gateway - Host-side mechanism executor: synchronous pure-function view over the canonical meta-instruction state machine.
- Native
Service - 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-sidePluginDef, 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 whenmechanism_gatewayisNone). - serde_
to_ tcb - Convert a
serde_json::Valueinto the canonicalJsonValueform.