Skip to main content

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`], [`Role`], [`ContentPart`],
16//! [`TextPayload`], [`MediaRef`], [`SealedPart`], [`ToolCallPayload`],
17//! [`ToolResultPayload`], [`ToolResultStatus`], [`ToolOutput`],
18//! [`ToolOutputMeta`], [`Truncation`], [`ArtifactRef`], [`ArtifactKind`],
19//! [`ToolChange`] and [`ToolDefinition`].
20//! From `0.1.0` a breaking change to one of these forms needs a minor
21//! version. Adding an optional field is not a break: a reader ignores a field
22//! it does not know, and a field missing from an older record reads as unset.
23//!
24//! Every other serializable type (model output, request options,
25//! identifiers, error kinds) can be written to logs but carries no such
26//! promise. A host that stores one owns its migration.
27
28#![deny(unsafe_code)]
29#![deny(missing_docs)]
30
31mod context;
32mod ports;
33
34// --- context: the external rule interface ------------------------------------
35pub use context::block::{
36    BlockContent, BlockMeta, ContentPart, ContextBlock, MediaRef, Role, SealedPart, TextPayload,
37    ToolCallPayload, WireMeta,
38};
39pub use context::ids::{BlockId, InvocationId, RoundId, TurnId};
40pub use context::material::{
41    Context, ContextEdit, ContextFrame, EditError, EditFailure, Replacement, ToolResultError,
42    validate_tool_result_append,
43};
44pub use context::model::{
45    ModelBlockError, ModelItem, ModelItemContent, ModelResponse, ModelStopReason, ToolCallDraft,
46};
47pub use context::tool_data::{
48    ArtifactKind, ArtifactRef, ToolCallId, ToolOutput, ToolOutputMeta, ToolResultPayload,
49    ToolResultStatus, Truncation,
50};
51pub use context::tools::{ToolChange, ToolDefinition, current_tools};
52
53// --- ports: behavior seams for external implementors ------------------------
54pub use ports::batch::{
55    BatchError, ProcessorContext, ProcessorData, ProcessorError, RejectedToolResult, ToolBatch,
56    ToolBatchProcessor, ToolCallEntry,
57};
58pub use ports::control::{CallControl, ControlError};
59pub use ports::gateway::{
60    CacheDirective, GenerationOptions, ModelGateway, ModelInvokeError, ModelInvokeErrorKind,
61    ModelOutput, ModelRef, ModelRequest, ModelStream, ModelUsage, ReasoningPayload, StreamDelta,
62    completed_model_stream,
63};
64pub use ports::prepare::{ContextPreparer, PrepareError, RoundInfo};
65pub use ports::source::{DynamicToolSource, SourceError, ToolExecutionError};
66pub use ports::tool::{
67    ArtifactHint, ArtifactStore, CallAttachments, StoreError, Tool, ToolCallContext,
68    ToolDescription, ToolMetadata, ToolSurface,
69};
70/// The cancellation primitive behind the control planes, re-exported so the
71/// port is self-contained for external drivers.
72pub use tokio_util::sync::CancellationToken;