Crate設計・mv

This commit is contained in:
Keisuke Hirata 2026-04-09 04:55:14 +09:00
parent e7c53bd8f5
commit 66d005aa30
15 changed files with 187 additions and 11 deletions

1
AGENTS.md Normal file
View File

@ -0,0 +1 @@
設計指針を固め、全体の設計を進めるために、全体の俯瞰と細かいディテールを往復している。

1
CLAUDE.md Normal file
View File

@ -0,0 +1 @@
設計指針を固め、全体の設計を進めるために、全体の俯瞰と細かいディテールを往復している。

78
Cargo.lock generated
View File

@ -682,6 +682,16 @@ dependencies = [
name = "insomnia"
version = "0.1.0"
dependencies = [
"insomnia-core",
"insomnia-daemon",
"tokio",
]
[[package]]
name = "insomnia-core"
version = "0.1.0"
dependencies = [
"dotenv",
"llm-worker",
"llm-worker-persistence",
"serde",
@ -692,6 +702,15 @@ dependencies = [
"uuid",
]
[[package]]
name = "insomnia-daemon"
version = "0.1.0"
dependencies = [
"insomnia-core",
"llm-worker-persistence",
"tokio",
]
[[package]]
name = "ipnet"
version = "2.12.0"
@ -809,6 +828,15 @@ dependencies = [
"uuid",
]
[[package]]
name = "lock_api"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.29"
@ -939,6 +967,29 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "parking_lot"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-link",
]
[[package]]
name = "percent-encoding"
version = "2.3.2"
@ -1000,6 +1051,15 @@ version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]]
name = "redox_syscall"
version = "0.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
dependencies = [
"bitflags",
]
[[package]]
name = "ref-cast"
version = "1.0.25"
@ -1177,6 +1237,12 @@ dependencies = [
"syn",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "security-framework"
version = "3.7.0"
@ -1293,6 +1359,16 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook-registry"
version = "1.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
dependencies = [
"errno",
"libc",
]
[[package]]
name = "slab"
version = "0.4.12"
@ -1440,7 +1516,9 @@ dependencies = [
"bytes",
"libc",
"mio",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.61.2",

View File

@ -2,6 +2,8 @@
resolver = "2"
members = [
"crates/insomnia",
"crates/insomnia-core",
"crates/insomnia-daemon",
"crates/llm-worker",
"crates/llm-worker-macros",
"crates/llm-worker-persistence",

View File

@ -0,0 +1,20 @@
[package]
name = "insomnia-core"
version = "0.1.0"
edition.workspace = true
license.workspace = true
[dependencies]
llm-worker = { path = "../llm-worker" }
llm-worker-persistence = { path = "../llm-worker-persistence" }
serde = { version = "1.0", features = ["derive"] }
toml = "0.8"
uuid = { version = "1", features = ["v7", "serde"] }
thiserror = "2.0"
tokio = { version = "1.49", features = ["fs"] }
[dev-dependencies]
tokio = { version = "1.49", features = ["macros", "rt-multi-thread"] }
tempfile = "3.24"
dotenv = "0.15"
llm-worker-persistence = { path = "../llm-worker-persistence" }

View File

@ -0,0 +1,69 @@
//! Minimal example: Pod running a single prompt with persistence.
//!
//! Demonstrates the core insomnia abstraction — a TOML manifest drives
//! provider selection, model config, and system prompt, while FsStore
//! persists the session to disk automatically.
//!
//! ## Usage
//!
//! ```bash
//! echo "ANTHROPIC_API_KEY=your-key" > .env
//! cargo run -p insomnia-core --example pod_cli
//! ```
use insomnia_core::{Pod, PodManifest, PodRunResult};
use llm_worker_persistence::FsStore;
const MANIFEST_TOML: &str = r#"
[pod]
name = "hello-pod"
[provider]
kind = "anthropic"
model = "claude-sonnet-4-20250514"
api_key_env = "ANTHROPIC_API_KEY"
[worker]
system_prompt = "You are a concise assistant. Reply in one or two sentences."
max_tokens = 256
"#;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv::dotenv().ok();
// 1. Parse the manifest
let manifest = PodManifest::from_toml(MANIFEST_TOML)?;
println!("Pod: {}", manifest.pod.name);
// 2. Create a persistent store (temp dir for demo)
let tmp = tempfile::tempdir()?;
let store = FsStore::new(tmp.path()).await?;
// 3. Build the Pod from manifest
let mut pod = Pod::from_manifest(manifest, store, None).await?;
println!("Session: {}", pod.session_id());
// 4. Run a prompt
let result = pod.run("What is the capital of France?").await?;
match result {
PodRunResult::Finished => println!("(finished)"),
PodRunResult::Paused => println!("(paused)"),
}
// 5. Extract the assistant's reply from history
let history = pod.session_mut().worker.history();
if let Some(text) = history
.iter()
.rev()
.find(|item| item.is_assistant_message())
.and_then(|item| item.as_text())
{
println!("\nAssistant: {text}");
}
// 6. Session ID for potential restore
println!("\nSession ID: {}", pod.session_id());
Ok(())
}

View File

@ -0,0 +1,10 @@
[package]
name = "insomnia-daemon"
version = "0.1.0"
edition.workspace = true
license.workspace = true
[dependencies]
insomnia-core = { path = "../insomnia-core" }
llm-worker-persistence = { path = "../llm-worker-persistence" }
tokio = { version = "1.49", features = ["full"] }

View File

View File

@ -5,14 +5,6 @@ edition.workspace = true
license.workspace = true
[dependencies]
llm-worker = { path = "../llm-worker" }
llm-worker-persistence = { path = "../llm-worker-persistence" }
serde = { version = "1.0", features = ["derive"] }
toml = "0.8"
uuid = { version = "1", features = ["v7", "serde"] }
thiserror = "2.0"
tokio = { version = "1.49", features = ["fs"] }
[dev-dependencies]
tokio = { version = "1.49", features = ["macros", "rt-multi-thread"] }
tempfile = "3.24"
insomnia-core = { path = "../insomnia-core" }
insomnia-daemon = { path = "../insomnia-daemon" }
tokio = { version = "1.49", features = ["full"] }

View File

@ -0,0 +1,3 @@
fn main() {
println!("insomnia");
}