- sausage-actor: Message, messages(), send/reply/publish, async Inbox - agent: append-only /data/history.jsonl, no caps on history, steps, waits, tool output, or reads; max_tokens only when configured (Anthropic: 32000)
31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
//! Keep notes in `/data/notes.json` and publish them at `/public/notes.txt`.
|
|
use sausage_actor::{json, messages, reply};
|
|
|
|
const DATA: &str = "/data/notes.json";
|
|
|
|
fn save(notes: &[String]) {
|
|
std::fs::write(DATA, serde_json::to_string(notes).unwrap()).unwrap();
|
|
std::fs::write("/public/notes.txt", notes.join("\n") + "\n").unwrap();
|
|
}
|
|
|
|
fn main() {
|
|
let mut notes: Vec<String> = std::fs::read_to_string(DATA)
|
|
.ok()
|
|
.and_then(|text| serde_json::from_str(&text).ok())
|
|
.unwrap_or_default();
|
|
for message in messages() {
|
|
let body = &message.body;
|
|
let response = match message.kind() {
|
|
"add" => {
|
|
notes.push(body["text"].as_str().unwrap_or_default().to_string());
|
|
save(¬es);
|
|
json!({"type": "added", "count": notes.len()})
|
|
}
|
|
"list" => json!({"type": "notes", "items": notes}),
|
|
"crash" => panic!("asked to crash"),
|
|
_ => json!({"type": "error", "reason": "unknown message"}),
|
|
};
|
|
let _ = reply(&message, response);
|
|
}
|
|
}
|