Signed-off-by: 未知时光 <732857315@qq.com>

This commit is contained in:
2026-06-09 16:23:24 +08:00
parent 1bf1f08f9a
commit f7919eca40
13 changed files with 1206 additions and 1 deletions

15
plugins/echo/Cargo.toml Normal file
View File

@@ -0,0 +1,15 @@
[package]
name = "agentsd-plugin-echo"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "agentsd-plugin-echo"
path = "src/main.rs"
[dependencies]
agentsd-plugin-sdk = { path = "../plugin-sdk" }
agentsd-proto = { path = "../../core/proto" }
anyhow = { workspace = true }
tokio = { workspace = true }
tonic = { workspace = true }

92
plugins/echo/src/main.rs Normal file
View File

@@ -0,0 +1,92 @@
use agentsd_plugin_sdk::{export, plugin_info, request_with_plugin};
use agentsd_proto::agentsd::{
display_client::DisplayClient, fs_client::FsClient, memory_client::MemoryClient,
plugin_bridge_client::PluginBridgeClient, DisplayTextRequest, FsPathRequest, MemoryReadRequest,
MemoryWriteRequest,
};
use anyhow::{ensure, Result};
const PLUGIN_ID: &str = "echo-test";
#[tokio::main]
async fn main() -> Result<()> {
let channel = agentsd_plugin_sdk::connect().await?;
let mut bridge = PluginBridgeClient::new(channel.clone());
let register = bridge
.register(plugin_info(
PLUGIN_ID,
"Echo Test Plugin",
"0.1.0",
"basic",
&["display.text", "fs.list", "memory.read", "memory.write"],
&[],
vec![export("echo", "Echo test")],
))
.await?
.into_inner();
ensure!(register.ok, "register failed: {}", register.error);
println!("Register: ok={} session={}", register.ok, register.session_id);
let mut display = DisplayClient::new(channel.clone());
let resp = display
.text(request_with_plugin(
PLUGIN_ID,
DisplayTextRequest {
content: "Hello from echo plugin!".to_string(),
},
)?)
.await?
.into_inner();
ensure!(resp.ok, "Display.Text failed: {}", resp.error);
println!("Display.Text: ok={}", resp.ok);
let mut memory = MemoryClient::new(channel.clone());
let resp = memory
.write(request_with_plugin(
PLUGIN_ID,
MemoryWriteRequest {
key: "test.greeting".to_string(),
value: b"Hello World".to_vec(),
},
)?)
.await?
.into_inner();
ensure!(resp.ok, "Memory.Write failed: {}", resp.error);
println!("Memory.Write: ok={}", resp.ok);
let resp = memory
.read(request_with_plugin(
PLUGIN_ID,
MemoryReadRequest {
key: "test.greeting".to_string(),
},
)?)
.await?
.into_inner();
ensure!(resp.found, "Memory.Read missing value: {}", resp.error);
println!(
"Memory.Read: found={} value={}",
resp.found,
String::from_utf8_lossy(&resp.value)
);
let mut fs = FsClient::new(channel);
let resp = fs
.list(request_with_plugin(
PLUGIN_ID,
FsPathRequest {
path: ".".to_string(),
},
)?)
.await?
.into_inner();
ensure!(resp.ok, "FS.List failed: {}", resp.error);
println!("FS.List: ok={} entries={}", resp.ok, resp.entries.len());
for entry in resp.entries.iter().take(5) {
println!(" {} {}", entry.name, if entry.is_dir { "[dir]" } else { "" });
}
println!("\nAll syscalls verified OK!");
Ok(())
}