kimi_wire/lib.rs
1#![warn(missing_docs)]
2#![warn(clippy::await_holding_lock)]
3#![warn(clippy::dbg_macro)]
4#![warn(clippy::wildcard_imports)]
5#![warn(clippy::unused_async)]
6#![cfg_attr(not(test), warn(clippy::unwrap_used))]
7
8//! # `kimi-wire`
9//!
10//! Typed Rust client for the [Kimi Code CLI Wire protocol](https://www.kimi.com/code/docs/en/kimi-code-cli/customization/wire-protocol.html).
11//!
12//! ## Overview
13//!
14//! The Wire protocol is a JSON-RPC 2.0 based bidirectional communication
15//! protocol exposed by `kimi --wire`. This crate provides:
16//!
17//! * Strongly typed protocol structs ([`protocol::event::Event`], [`protocol::request::Request`], [`protocol::method::PromptResult`], ...).
18//! * A [`WireClient`] trait with high-level methods (`prompt`, `replay`, `steer`, ...).
19//! * A [`transport::Transport`] abstraction for stdio, in-memory channels, or custom backends.
20//! * Optional secret redaction for wire logs.
21//!
22//! ## Feature flags
23//!
24//! | Feature | Description |
25//! |---------|-------------|
26//! | `process` (default) | Enables [`transport::ChildProcessTransport`] for spawning `kimi --wire`. |
27//! | `redact` (default) | Enables [`protocol::redact::redact_secrets`] for scrubbing secrets from JSON. |
28//!
29//! ## Example
30//!
31//! ```no_run
32//! use kimi_wire::{InMemoryWireClient, WireClient};
33//!
34//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
35//! let mut client = InMemoryWireClient::new();
36//! let result = client.prompt("hello").await?;
37//! # Ok(())
38//! # }
39//! ```
40
41/// Client trait and in-memory implementation for the Wire protocol.
42pub mod client;
43/// Extension traits for [`WireClient`].
44pub mod client_ext;
45/// Ready-made dispatch loop for wire conversations.
46#[cfg(feature = "process")]
47pub mod dispatch;
48/// Error types for wire protocol failures.
49pub mod error;
50/// Message parsing: `RawWireMessage` → typed [`WireMessage`](crate::message::WireMessage).
51pub mod message;
52/// Protocol types: JSON-RPC, events, requests, methods, and content parts.
53pub mod protocol;
54#[cfg(feature = "process")]
55/// Transport implementations (child process, channels).
56pub mod transport;
57
58pub use client::{InMemoryWireClient, WireClient};
59pub use client_ext::{EventExt, RequestExt, WireClientExt};
60pub use error::WireError;
61#[cfg(feature = "redact")]
62pub use protocol::redact::redact_secrets;
63
64/// The latest wire protocol version supported by this crate.
65pub const WIRE_PROTOCOL_VERSION: &str = "1.10";
66
67/// Legacy protocol version used when the server does not support `initialize`.
68pub const WIRE_PROTOCOL_LEGACY_VERSION: &str = "legacy/no-handshake";