Skip to main content

kopitiam_ai/
lib.rs

1//! Pluggable model adapters for KOPITIAM's Semantic Runtime.
2//!
3//! This crate defines the [`ModelAdapter`] trait — the sole boundary through
4//! which a model (local Qwen, Claude, GPT, Gemini, ...) is invoked anywhere
5//! in the platform. Per the Semantic Runtime's dependency rule, only
6//! `kopitiam-workflow` depends on this crate; everything else in the
7//! platform (`kopitiam-knowledge`, `kopitiam-index`, `kopitiam-search`,
8//! `kopitiam-workspace`, `kopitiam-translation`) stays model-agnostic.
9//!
10//! What lives here is the shape of a request/response
11//! ([`CompletionRequest`], [`CompletionResponse`], [`Message`]), one
12//! deterministic stub adapter ([`EchoAdapter`], always available) so
13//! `kopitiam-workflow` has something real to compile and test against with
14//! no weights and no network, and — behind the default-on `local` Cargo
15//! feature — [`LocalAdapter`], a real, offline, on-CPU adapter backed by
16//! `kopitiam-runtime`'s Qwen inference stack. See [`local`]'s module docs
17//! for the full local-vs-cloud architecture and why depending on
18//! `kopitiam-runtime` from here does not violate the Semantic Runtime's
19//! dependency rule.
20//!
21//! Two other pieces round out the boundary for a live chat UI:
22//!
23//! * **Streaming** — alongside the blocking [`ModelAdapter::complete`], every
24//!   adapter can [`ModelAdapter::stream`] its reply token-by-token over a
25//!   channel of [`StreamChunk`]s, so a UI renders tokens as they land instead
26//!   of freezing on a slow generation. [`EchoAdapter`] and [`LocalAdapter`]
27//!   do this on a real background thread (the AID-0028 actor discipline, std
28//!   threads + `mpsc`, no async runtime).
29//! * **Cloud scaffold** — [`CloudAdapter`] + [`CloudStub`] for
30//!   Claude/GPT/Gemini ([`CloudVendor`]), gated on an API key from the
31//!   environment. Key-detection and the "no key → [`CloudUnavailable`]" path
32//!   are real; the network layer itself is a deliberate follow-up.
33
34mod adapter;
35mod bilingual;
36mod cloud;
37mod echo;
38mod glossary;
39mod message;
40mod preprocess;
41mod stream;
42mod translate;
43
44#[cfg(feature = "local")]
45mod local;
46
47pub use adapter::ModelAdapter;
48pub use bilingual::{
49    BilingualOptions, BilingualSegment, Layout, ReviewCoverage, DEFAULT_REVIEW_THRESHOLD,
50    REVIEW_MARKER, from_two_pass, render_bilingual, review_coverage, review_targets,
51};
52pub use cloud::{CloudAdapter, CloudStub, CloudUnavailable, CloudVendor};
53pub use echo::EchoAdapter;
54pub use glossary::{Applied, Entry, Glossary, SourceKind, Substitution};
55#[cfg(feature = "local")]
56pub use local::LocalAdapter;
57pub use message::{CompletionRequest, CompletionResponse, Message, Role};
58pub use preprocess::{
59    Bucket, DiagnosticBuckets, DropReport, Preprocessed, ECHO_PASSTHROUGH_NOTE, classify_diagnostics,
60    draft_commit_message, summarize, triage,
61};
62pub use stream::StreamChunk;
63pub use translate::{
64    ConfidenceSignals, Decision, SegmentPlan, TwoPassConfig, TwoPassPlan, TwoPassSummary,
65    DEFAULT_ACCEPT_THRESHOLD, ECHO_PASSTHROUGH_NOTE as TWO_PASS_ECHO_PASSTHROUGH_NOTE,
66    dice_similarity, draft_and_route, glossary_score, length_score,
67};