Initial commit

This commit is contained in:
2026-01-26 18:04:07 +02:00
commit 0786cf0165
45 changed files with 12608 additions and 0 deletions

10
crates/daemon/Cargo.toml Normal file
View File

@@ -0,0 +1,10 @@
[package]
name = "daemon"
version = "0.1.0"
edition = "2021"
[dependencies]
shared = { path = "../shared" }
tokio = { version = "1.49.0", features = ["full"] }
tonic = "0.14.2"
tonic-reflection = "0.14.2"

35
crates/daemon/src/main.rs Normal file
View File

@@ -0,0 +1,35 @@
use shared::ai::ai_daemon_server::{AiDaemonServer, AiDaemon};
use shared::ai::{PromptRequest, PromptResponse};
use tonic::{transport::Server, Response, Request, Status};
#[derive(Default)]
pub struct DaemonServer {}
#[tonic::async_trait]
impl AiDaemon for DaemonServer {
async fn prompt(
&self,
request: Request<PromptRequest>,
) -> Result<Response<PromptResponse>, Status> {
println!("Request from {:?}: {:?}", request.remote_addr(), request.into_inner().prompt);
let reply = PromptResponse {
response: "Very nice!".to_string()
};
Ok(Response::new(reply))
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:50051".parse().unwrap();
let daemon = DaemonServer::default();
let reflection_service = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(shared::ai::FILE_DESCRIPTOR_SET)
.build_v1()?;
Server::builder()
.add_service(AiDaemonServer::new(daemon))
.add_service(reflection_service)
.serve(addr)
.await?;
Ok(())
}

13
crates/shared/Cargo.toml Normal file
View File

@@ -0,0 +1,13 @@
[package]
name = "shared"
version = "0.1.0"
edition = "2021"
[dependencies]
prost = "0.14.3"
serde = { version = "1.0.228", features = ["derive"] }
tonic = "0.14.2"
tonic-prost = "0.14.2"
[build-dependencies]
tonic-prost-build = "0.14.2"

10
crates/shared/build.rs Normal file
View File

@@ -0,0 +1,10 @@
use std::env;
use std::path::PathBuf;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
tonic_prost_build::configure()
.file_descriptor_set_path(out_dir.join("ai_service_descriptor.bin"))
.compile_protos(&["proto/api.proto"], &["proto"])?;
Ok(())
}

View File

@@ -0,0 +1,14 @@
syntax = "proto3";
package ai_daemon;
service AiDaemon {
rpc Prompt (PromptRequest) returns (PromptResponse);
}
message PromptRequest {
string prompt = 1;
}
message PromptResponse {
string response = 1;
}

5
crates/shared/src/lib.rs Normal file
View File

@@ -0,0 +1,5 @@
pub mod ai {
tonic::include_proto!("ai_daemon");
pub const FILE_DESCRIPTOR_SET: &[u8] = tonic::include_file_descriptor_set!("ai_service_descriptor");
}