Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 96 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion casper-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2024"
[dependencies]
enigo = "0.5.0"
notify-rust = "4.0.0"
tokio = { version = "1.46.1", features = ["rt", "net", "io-util"] }
tokio = { version = "1.46.1", features = ["rt-multi-thread", "net", "io-util"] }
serde = { version = "1.0.0", features = ["derive"] }
serde_json = "1.0.0"
reqwest = { version = "0.12.9", features = ["json"] }
8 changes: 8 additions & 0 deletions casper-core/src/ai.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub fn process_command(command: &str) -> Result<String, String> {
// Basic keyword matcching, thinking about using use rust-bert, I got interesred º-º
if command.contains("hello") {
Ok("I'm an AI response º-º!".to_string())
} else {
Err("AI under construction".to_string())
}
}
17 changes: 17 additions & 0 deletions casper-core/src/connections.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use reqwest::Client;

pub async fn connect_to_service(service: &str, _action: &str) -> Result<String, String> {
// Example HTTP request
let client = Client::new();
match service {
"example_api" => {
let response = client
.get("https://api.example.com")
.send()
.await
.map_err(|e| e.to_string())?;
response.text().await.map_err(|e| e.to_string())
},
_ => Err(format!("Unsupported service: {}", service)),
}
}
4 changes: 4 additions & 0 deletions casper-core/src/mcp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub fn process_mcp(data: &str) -> Result<String, String> {
// Process MCP protocol data
Err(format!("MCP under development: received {}", data))
}
9 changes: 8 additions & 1 deletion casper-core/src/screen.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use enigo::{Enigo, Settings, Coordinate, Mouse};
use enigo::{Enigo, Settings, Coordinate, Mouse, Keyboard};

pub fn move_mouse(x: i32, y: i32) -> Result<(), String> {
let settings = Settings::default();
let mut enigo = Enigo::new(&settings).map_err(|e| e.to_string())?;
enigo.move_mouse(x, y, Coordinate::Abs).map_err(|e| e.to_string())?;
Ok(())
}

pub fn type_text(text: &str) -> Result<(), String> {
let settings = Settings::default();
let mut enigo = Enigo::new(&settings).map_err(|e| e.to_string())?;
enigo.fast_text(text).map_err(|e| e.to_string())?;
Ok(())
}
9 changes: 9 additions & 0 deletions casper-core/src/tts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::process::Command;

pub fn speak(text: &str) -> Result<(), String> {
Command::new("espeak-ng")
.arg(text)
.spawn()
.map_err(|e| e.to_string())?;
Ok(())
}
4 changes: 4 additions & 0 deletions casper-core/src/voice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub fn recognize_voice() -> Result<String, String> {
// Will use vosk-rust later, later...
Err("Voice under contruction".to_string())
}
49 changes: 48 additions & 1 deletion casper-daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ use tokio::net::UnixListener;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use std::path::Path;
use casper_core::commands::run_command;
use casper_core::screen::move_mouse;
use casper_core::screen::{move_mouse, type_text};
use casper_core::notifications::show_notification;
use casper_core::connections::connect_to_service;
use casper_core::mcp::process_mcp;
use casper_core::ai::process_command;
use casper_core::voice::recognize_voice;
use casper_core::tts::speak;
use serde_json::json;

#[tokio::main]
Expand Down Expand Up @@ -46,6 +51,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Err(e) => json!({ "status": "error", "message": e }),
}
},
Some("type_text") => {
let text = req["text"].as_str().unwrap_or("");
match type_text(text) {
Ok(_) => json!({ "status": "success" }),
Err(e) => json!({ "status": "error", "message": e }),
}
},
Some("show_notification") => {
let summary = req["summary"].as_str().unwrap_or("");
let body = req["body"].as_str().unwrap_or("");
Expand All @@ -54,6 +66,41 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Err(e) => json!({ "status": "error", "message": e }),
}
},
Some("connect_to_service") => {
let service = req["service"].as_str().unwrap_or("");
let action = req["action"].as_str().unwrap_or("");
match connect_to_service(service, action).await {
Ok(result) => json!({ "status": "success", "result": result }),
Err(e) => json!({ "status": "error", "message": e }),
}
},
Some("process_mcp") => {
let data = req["data"].as_str().unwrap_or("");
match process_mcp(data) {
Ok(result) => json!({ "status": "success", "result": result }),
Err(e) => json!({ "status": "error", "message": e }),
}
},
Some("process_command") => {
let command = req["command"].as_str().unwrap_or("");
match process_command(command) {
Ok(result) => json!({ "status": "success", "result": result }),
Err(e) => json!({ "status": "error", "message": e }),
}
},
Some("recognize_voice") => {
match recognize_voice() {
Ok(result) => json!({ "status": "success", "result": result }),
Err(e) => json!({ "status": "error", "message": e }),
}
},
Some("speak") => {
let text = req["text"].as_str().unwrap_or("");
match speak(text) {
Ok(_) => json!({ "status": "success" }),
Err(e) => json!({ "status": "error", "message": e }),
}
},
_ => json!({ "status": "error", "message": "Unknown request type" }),
};

Expand Down
Loading
Loading