1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! # Diaryx Plugin SDK
//!
//! The official SDK for building [Diaryx](https://diaryx.com) Extism WASM plugins.
//!
//! This crate replaces the per-plugin boilerplate: protocol types, host function
//! wrappers, getrandom shims, and state management helpers. Depend on this
//! instead of copy-pasting `host_bridge.rs` and protocol structs.
//!
//! ## Quick Start
//!
//! ```toml
//! [package]
//! name = "diaryx_myplugin_extism"
//! version = "0.1.0"
//! edition = "2024"
//!
//! [lib]
//! crate-type = ["cdylib"]
//!
//! [dependencies]
//! diaryx_plugin_sdk = { version = "0.1", features = ["full"] }
//! extism-pdk = "1.4"
//! serde = { version = "1.0", features = ["derive"] }
//! serde_json = "1.0"
//! ```
//!
//! ```rust,ignore
//! use diaryx_plugin_sdk::prelude::*;
//! use extism_pdk::*;
//!
//! #[plugin_fn]
//! pub fn manifest(_input: String) -> FnResult<String> {
//! let manifest = GuestManifest::new(
//! "diaryx.myplugin",
//! "My Plugin",
//! env!("CARGO_PKG_VERSION"),
//! "Does cool things",
//! vec!["custom_commands".into()],
//! )
//! .commands(vec!["my-command".into()]);
//! Ok(serde_json::to_string(&manifest)?)
//! }
//!
//! #[plugin_fn]
//! pub fn handle_command(input: String) -> FnResult<String> {
//! let req: CommandRequest = serde_json::from_str(&input)?;
//! let resp = match req.command.as_str() {
//! "my-command" => {
//! let content = host::fs::read_file("index.md")?;
//! CommandResponse::ok(serde_json::json!({ "length": content.len() }))
//! }
//! _ => CommandResponse::err(format!("Unknown command: {}", req.command)),
//! };
//! Ok(serde_json::to_string(&resp)?)
//! }
//!
//! #[plugin_fn]
//! pub fn on_event(_input: String) -> FnResult<String> {
//! Ok(String::new())
//! }
//!
//! #[plugin_fn]
//! pub fn get_config(_input: String) -> FnResult<String> {
//! Ok("{}".into())
//! }
//!
//! #[plugin_fn]
//! pub fn set_config(_input: String) -> FnResult<String> {
//! Ok(String::new())
//! }
//! ```
//!
//! ## Feature Flags
//!
//! | Feature | What it enables |
//! |------------------|----------------------------------------------|
//! | `core` (default) | File I/O, storage, logging, timestamps |
//! | `http` | HTTP requests via the host |
//! | `secrets` | Plugin-scoped secret storage via the host |
//! | `ws` | WebSocket bridge |
//! | `events` | Event emission to the host |
//! | `plugins` | Inter-plugin command execution |
//! | `context` | Runtime context queries |
//! | `wasi` | WASI module execution |
//! | `files` | User-provided file requests |
//! | `getrandom-shim` | Custom getrandom backend for WASM |
//! | `full` | All of the above |
/// Convenience re-exports for the most commonly used types.