Skip to main content

dkp_core/procedures/
schema.rs

1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5/// Mirrors {procedure-id}.schema.json (Appendix B §B.23).
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ProcedureSchema {
8    pub id: String,
9    pub title: String,
10    pub description: String,
11    /// JSON Schema object describing input
12    pub input: serde_json::Value,
13    /// JSON Schema object describing output
14    pub output: serde_json::Value,
15    /// Present only for non-WASM procedures (spec §9.12)
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub entry_point: Option<EntryPoint>,
18}
19
20/// Alternative executable declaration for non-WASM procedures.
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct EntryPoint {
23    /// Exact filename of the alternative executable (e.g. "macro_calculator.py")
24    pub filename: String,
25    /// Full execution command string (e.g. "python3 macro_calculator.py")
26    pub command: String,
27}
28
29/// Fully-resolved view of one procedure in a pack.
30#[derive(Debug, Clone)]
31pub struct ProcedureDef {
32    pub id: String,
33    pub schema: ProcedureSchema,
34    /// Present when {id}.wasm exists
35    pub wasm_path: Option<PathBuf>,
36    /// Present when schema.entry_point is set (non-WASM path)
37    pub entry_point: Option<EntryPoint>,
38    /// Path to {id}.md documentation
39    pub doc_path: PathBuf,
40    /// Path to {id}.schema.json
41    pub schema_path: PathBuf,
42}
43
44impl ProcedureDef {
45    pub fn is_runnable(&self) -> bool {
46        self.wasm_path.is_some() || self.entry_point.is_some()
47    }
48}