feat(ai): provider-agnostic AI crate (Anthropic, OpenAI, Gemini, compatible)

Streaming chat, embeddings (Embedder impl), key stores, retries/cancellation,
and graph features: ask_graph, summarize_journal, suggest_links_and_tags,
extract_tasks, consolidate_week.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5.5 committed 2026-10-21 03:41:21 +02:00
1 parent fbcfcf678f
commit 6697924bf5
20 files changed
+4084 -6

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
use async_trait::async_trait;
use tokio_util::sync::CancellationToken;
use crate::error::Result;
use crate::types::{ChatRequest, ChatResponse, EmbedResponse, TokenSink};
#[async_trait]
pub trait ChatProvider: Send + Sync {
/// Runs one chat completion. Text deltas are pushed to `sink` as they arrive; the full text
/// is also returned. Cancelling `cancel` aborts the request with `Error::Cancelled`.
async fn chat(
&self,
req: &ChatRequest,
sink: Option<TokenSink<'_>>,
cancel: &CancellationToken,
) -> Result<ChatResponse>;
}
#[async_trait]
pub trait EmbeddingProvider: Send + Sync {
/// `provider/model`, e.g. `openai/text-embedding-3-small`.
fn model_id(&self) -> String;
/// Known vector size, if it does not need a probe request.
fn known_dims(&self) -> Option<usize>;
async fn embed(&self, texts: &[String], cancel: &CancellationToken) -> Result<EmbedResponse>;
}