Skip to main content

Crate moonlit_pdk

Crate moonlit_pdk 

Source
Expand description

Write a Moonlit plugin: one Middleware impl per step, and one moonlit_plugin! block naming them.

Targets plugin ABI moonlit:plugin@0.3.0. Each middleware publishes a JSON Schema for its Input and Output, which is what moonlit plugin inspect reads. See Middleware for a worked example and testing for driving one in a unit test.

Modules§

bindings
Generated WIT bindings. Public because the moonlit_plugin! macro output (expanded in the author crate) references this exact path via export!(Component with_types_in moonlit_pdk::bindings).
clock
Monotonic clock access. ctx.clock().start() yields a Timer whose elapsed_ms() re-reads the live clock — an honest stopwatch across an arbitrarily long operation, with the plugin never touching raw nanos.
config
Config binding with §5.4 string coercion. The engine sends config JSON in which every scalar is a string (see engine value_to_json); typed fields parse those strings in the fixed order bool -> i64 -> f64 -> datetime -> String. deserialize_any (dynamic targets) applies the same order, with datetime collapsing to a string (serde has no datetime type).
env
Environment access. Reads route through the host, which serves wasi:cli/environment — already permission-filtered by the engine (filter_env). Funnelling through Host keeps env mockable in native tests.
http
Tiny blocking HTTP client over the host http_send capability. Verbs, bearer auth, custom headers, JSON in/out, per-request timeout, and gzip response inflate. Sized for GitHub/GitLab/Slack/OpenAI/npm/NuGet-style REST calls.
prelude
process
Safe, native-testable wrappers over the host process capability. Command builds a subprocess; .run() captures, .stream() live-logs via a LineHandler, .spawn() yields a Child for line-by-line control. Non-zero exit is data (Ok), not an error; Err means the spawn itself failed.
random
Randomness, routed through the host so tests can seed it deterministically.
state
Interior-mutable state shared between a plugin’s middlewares.
testing
Drive a middleware against a recording mock host, with no wasm build.

Macros§

export
Generates #[unsafe(no_mangle)] functions to export the specified type as the root implementation of all generated traits.
moonlit_plugin

Structs§

Context
Execution context handed to every middleware.
MiddlewareResult
What a Middleware returns.
NoInput
Marker for a middleware that reads no configuration. Deserializes from {} (or an absent config block) and yields an empty-object input schema (“no declared inputs”). Input-only: it has no Serialize impl.
NoOutput
Marker for a middleware that publishes no outputs. Serializes to {} and yields an empty-object output schema (“no declared outputs”).

Enums§

LogLevel
Log severity surfaced to the CLI renderer.

Traits§

Host
The capabilities Context needs from the environment.
Middleware
One step a pipeline can run:. Implement it on a Default unit struct.
PluginConfig
Semantic validation for a plugin’s config:, beyond what decoding checks.