| Crates.io | aidale-core |
| lib.rs | aidale-core |
| version | 0.1.0 |
| created_at | 2025-11-01 04:11:45.366995+00 |
| updated_at | 2025-11-01 04:11:45.366995+00 |
| description | Core abstractions and runtime for Aidale - Rust AI SDK |
| homepage | https://github.com/hanxuanliang/aidale |
| repository | https://github.com/hanxuanliang/aidale |
| max_upload_size | |
| id | 1911676 |
| size | 100,741 |
Core abstractions and runtime for Aidale - Rust AI SDK.
aidale-core provides the foundational traits and runtime for the Aidale ecosystem:
Pure HTTP client abstraction for AI services:
#[async_trait]
pub trait Provider: Send + Sync {
fn id(&self) -> &str;
fn name(&self) -> &str;
async fn chat_completion(
&self,
model: &str,
params: ChatCompletionParams,
) -> Result<ChatCompletionResponse>;
async fn stream_chat_completion(
&self,
model: &str,
params: ChatCompletionParams,
) -> Result<impl Stream<Item = Result<ChatCompletionChunk>>>;
}
Composable middleware with zero-cost abstraction:
#[async_trait]
pub trait Layer<P: Provider>: Send + Sync {
async fn call(
&self,
provider: &P,
model: &str,
params: ChatCompletionParams,
) -> Result<ChatCompletionResponse>;
}
Layers are composed at compile-time using type-level recursion for static dispatch.
Runtime extension points for business logic:
#[async_trait]
pub trait Plugin: Send + Sync {
async fn on_request(&self, ctx: &mut RequestContext) -> Result<()>;
async fn on_response(&self, ctx: &mut ResponseContext) -> Result<()>;
async fn on_error(&self, ctx: &mut ErrorContext) -> Result<()>;
}
High-level API combining strategies, layers, and plugins:
let executor = RuntimeExecutor::builder(provider)
.layer(LoggingLayer::new())
.plugin(Arc::new(ToolUsePlugin::new(tools)))
.finish();
let result = executor.generate_text(model, params).await?;
This crate is typically used indirectly through the main aidale crate:
[dependencies]
aidale = "0.1"
For direct usage:
[dependencies]
aidale-core = "0.1"
tokio and async-trait┌─────────────────────────────────────┐
│ RuntimeExecutor │ High-level API
│ - generate_text() │ + Plugin orchestration
│ - generate_object() │ + Strategy selection
└─────────────┬───────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Layers (AOP) │ Middleware stack
│ Logging → Retry → Cache │ (Static dispatch)
└─────────────┬───────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Provider │ HTTP client
│ - chat_completion() │ (No business logic)
└─────────────────────────────────────┘
aidale - Main meta-crateaidale-provider - Provider implementationsaidale-layer - Built-in layersaidale-plugin - Built-in pluginsMIT OR Apache-2.0