causa_kernel/lib.rs
1//! causa-kernel — ContextBlock conversation kernel.
2//! No dependency on a host application, a UI shell, or another agent framework.
3//!
4//! The kernel holds ordered material and atomic identity-preserving edits, plus
5//! third-party model, preparation, tool and cancellation contracts. It performs
6//! no I/O, execution policy or conversation management. Reference execution
7//! lives in causa-runtime; concrete transports live in edge crates.
8//! [`GenerationOptions`] describes requested generation settings; hosts own
9//! model capability selection and persisted definitions.
10//!
11//! # Stable serialized forms
12//!
13//! A host stores context, so the serialized form of [`Context`] and of every
14//! type it contains is the stable set: [`ContextBlock`], [`BlockId`],
15//! [`BlockMeta`], [`WireMeta`], [`BlockContent`], [`ContentPart`],
16//! [`TextPayload`], [`MediaRef`], [`SealedPart`], [`ToolCallPayload`],
17//! [`ToolResultPayload`], [`ToolResultStatus`], [`ToolOutput`],
18//! [`ToolOutputMeta`], [`Truncation`], [`ArtifactRef`] and [`ArtifactKind`].
19//! From `0.1.0` a breaking change to one of these forms needs a minor
20//! version. Adding an optional field is not a break: a reader ignores a field
21//! it does not know, and a field missing from an older record reads as unset.
22//!
23//! Every other serializable type (model output, request options,
24//! identifiers, error kinds) can be written to logs but carries no such
25//! promise. A host that stores one owns its migration.
26
27#![deny(unsafe_code)]
28#![deny(missing_docs)]
29
30mod context;
31mod ports;
32
33// --- context: the external rule interface ------------------------------------
34pub use context::block::{
35 BlockContent, BlockMeta, ContentPart, ContextBlock, MediaRef, SealedPart, TextPayload,
36 ToolCallPayload, WireMeta,
37};
38pub use context::ids::{BlockId, InvocationId, RoundId, TurnId};
39pub use context::material::{
40 Context, ContextEdit, ContextFrame, EditError, EditFailure, Replacement, ToolResultError,
41 validate_tool_result_append,
42};
43pub use context::model::{
44 ModelBlockError, ModelItem, ModelItemContent, ModelResponse, ModelStopReason, ToolCallDraft,
45};
46pub use context::tool_data::{
47 ArtifactKind, ArtifactRef, ToolCallId, ToolOutput, ToolOutputMeta, ToolResultPayload,
48 ToolResultStatus, Truncation,
49};
50
51// --- ports: behavior seams for external implementors ------------------------
52pub use ports::batch::{
53 BatchError, ProcessorContext, ProcessorError, RejectedToolResult, ToolBatch,
54 ToolBatchProcessor, ToolCallEntry,
55};
56pub use ports::control::{CallControl, ControlError};
57pub use ports::gateway::{
58 CacheDirective, GenerationOptions, ModelGateway, ModelInvokeError, ModelInvokeErrorKind,
59 ModelOutput, ModelRef, ModelRequest, ModelStream, ModelUsage, ReasoningPayload, StreamDelta,
60 completed_model_stream,
61};
62pub use ports::prepare::{ContextPreparer, PrepareError, RoundInfo};
63pub use ports::source::{DynamicToolSource, SourceError, ToolExecutionError};
64pub use ports::tool::{
65 ArtifactHint, ArtifactStore, StoreError, Tool, ToolCallContext, ToolDefinition, ToolSurface,
66};
67/// The cancellation primitive behind the control planes, re-exported so the
68/// port is self-contained for external drivers.
69pub use tokio_util::sync::CancellationToken;