1use async_trait::async_trait;
4use thiserror::Error;
5
6use kaish_kernel::ast::Value;
7use kaish_kernel::interpreter::ExecResult;
8
9pub type ClientResult<T> = Result<T, ClientError>;
11
12#[derive(Debug, Error)]
14pub enum ClientError {
15 #[error("connection error: {0}")]
17 Connection(String),
18
19 #[error("execution error: {0}")]
21 Execution(String),
22
23 #[error("io error: {0}")]
25 Io(#[from] std::io::Error),
26
27 #[error("utf8 error: {0}")]
29 Utf8(#[from] std::str::Utf8Error),
30
31 #[error("not connected")]
33 NotConnected,
34
35 #[error("{0}")]
37 Other(#[from] anyhow::Error),
38}
39
40#[async_trait(?Send)]
45pub trait KernelClient {
46 async fn execute(&self, input: &str) -> ClientResult<ExecResult>;
50
51 async fn get_var(&self, name: &str) -> ClientResult<Option<Value>>;
53
54 async fn set_var(&self, name: &str, value: Value) -> ClientResult<()>;
56
57 async fn list_vars(&self) -> ClientResult<Vec<(String, Value)>>;
59
60 async fn cwd(&self) -> ClientResult<String>;
62
63 async fn set_cwd(&self, path: &str) -> ClientResult<()>;
65
66 async fn last_result(&self) -> ClientResult<ExecResult>;
68
69 async fn reset(&self) -> ClientResult<()>;
71
72 async fn ping(&self) -> ClientResult<String>;
74
75 async fn shutdown(&self) -> ClientResult<()>;
77
78 async fn read_blob(&self, id: &str) -> ClientResult<Vec<u8>>;
82
83 async fn write_blob(&self, content_type: &str, data: &[u8]) -> ClientResult<String>;
87
88 async fn delete_blob(&self, id: &str) -> ClientResult<bool>;
92}