Crate設計・mv
This commit is contained in:
parent
e7c53bd8f5
commit
66d005aa30
78
Cargo.lock
generated
78
Cargo.lock
generated
|
|
@ -682,6 +682,16 @@ dependencies = [
|
||||||
name = "insomnia"
|
name = "insomnia"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"insomnia-core",
|
||||||
|
"insomnia-daemon",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "insomnia-core"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"dotenv",
|
||||||
"llm-worker",
|
"llm-worker",
|
||||||
"llm-worker-persistence",
|
"llm-worker-persistence",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
@ -692,6 +702,15 @@ dependencies = [
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "insomnia-daemon"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"insomnia-core",
|
||||||
|
"llm-worker-persistence",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.12.0"
|
version = "2.12.0"
|
||||||
|
|
@ -809,6 +828,15 @@ dependencies = [
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lock_api"
|
||||||
|
version = "0.4.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
|
||||||
|
dependencies = [
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.29"
|
version = "0.4.29"
|
||||||
|
|
@ -939,6 +967,29 @@ dependencies = [
|
||||||
"vcpkg",
|
"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]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.2"
|
version = "2.3.2"
|
||||||
|
|
@ -1000,6 +1051,15 @@ version = "6.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
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]]
|
[[package]]
|
||||||
name = "ref-cast"
|
name = "ref-cast"
|
||||||
version = "1.0.25"
|
version = "1.0.25"
|
||||||
|
|
@ -1177,6 +1237,12 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "security-framework"
|
name = "security-framework"
|
||||||
version = "3.7.0"
|
version = "3.7.0"
|
||||||
|
|
@ -1293,6 +1359,16 @@ version = "1.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
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]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.12"
|
version = "0.4.12"
|
||||||
|
|
@ -1440,7 +1516,9 @@ dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
|
"parking_lot",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"signal-hook-registry",
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio-macros",
|
"tokio-macros",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"crates/insomnia",
|
"crates/insomnia",
|
||||||
|
"crates/insomnia-core",
|
||||||
|
"crates/insomnia-daemon",
|
||||||
"crates/llm-worker",
|
"crates/llm-worker",
|
||||||
"crates/llm-worker-macros",
|
"crates/llm-worker-macros",
|
||||||
"crates/llm-worker-persistence",
|
"crates/llm-worker-persistence",
|
||||||
|
|
|
||||||
20
crates/insomnia-core/Cargo.toml
Normal file
20
crates/insomnia-core/Cargo.toml
Normal 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" }
|
||||||
69
crates/insomnia-core/examples/pod_cli.rs
Normal file
69
crates/insomnia-core/examples/pod_cli.rs
Normal 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(())
|
||||||
|
}
|
||||||
10
crates/insomnia-daemon/Cargo.toml
Normal file
10
crates/insomnia-daemon/Cargo.toml
Normal 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"] }
|
||||||
0
crates/insomnia-daemon/src/lib.rs
Normal file
0
crates/insomnia-daemon/src/lib.rs
Normal file
|
|
@ -5,14 +5,6 @@ edition.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
llm-worker = { path = "../llm-worker" }
|
insomnia-core = { path = "../insomnia-core" }
|
||||||
llm-worker-persistence = { path = "../llm-worker-persistence" }
|
insomnia-daemon = { path = "../insomnia-daemon" }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
tokio = { version = "1.49", features = ["full"] }
|
||||||
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"
|
|
||||||
|
|
|
||||||
3
crates/insomnia/src/main.rs
Normal file
3
crates/insomnia/src/main.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
println!("insomnia");
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user