wasm_sandbox/wrappers/
mod.rs1use std::path::{Path, PathBuf};
4use std::collections::HashMap;
5use serde::{Deserialize, Serialize};
6
7pub mod cli_tool;
8pub mod http_server;
9pub mod mcp_server;
10pub mod generic;
11pub mod http_server_impl;
12
13pub use http_server_impl::{HttpServerGenerator, HttpServerConfig};
15
16use crate::error::Result;
17
18pub trait WrapperGenerator {
20 fn generate_wrapper(&self, spec: &WrapperSpec) -> Result<String>;
22
23 fn compile_wrapper(&self, code: &str, output_path: &Path) -> Result<()>;
25
26 fn generate_and_compile(
28 &self,
29 spec: &WrapperSpec,
30 output_path: &Path,
31 ) -> Result<()> {
32 let code = self.generate_wrapper(spec)?;
33 self.compile_wrapper(&code, output_path)
34 }
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39pub enum ApplicationType {
40 HttpServer { port: u16 },
42
43 McpServer { port: u16, schema_path: Option<PathBuf> },
45
46 CliTool { interactive: bool },
48
49 Generic,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct CommunicationSpec {
56 pub protocol: CommunicationProtocol,
58
59 pub channels: Vec<String>,
61
62 pub rpc_functions: HashMap<String, String>,
64}
65
66impl Default for CommunicationSpec {
67 fn default() -> Self {
68 Self {
69 protocol: CommunicationProtocol::Json,
70 channels: vec!["default".to_string()],
71 rpc_functions: HashMap::new(),
72 }
73 }
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78pub enum CommunicationProtocol {
79 Json,
81
82 MessagePack,
84
85 Custom(String),
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct WrapperSpec {
92 pub app_type: ApplicationType,
94
95 pub app_path: PathBuf,
97
98 pub arguments: Vec<String>,
100
101 pub environment: HashMap<String, String>,
103
104 pub working_directory: Option<PathBuf>,
106
107 pub communication: CommunicationSpec,
109
110 pub template_variables: HashMap<String, String>,
112}