feat: add internal ZCLAW kernel crates to git tracking

This commit is contained in:
iven
2026-03-22 09:26:36 +08:00
parent d72c0f7161
commit 58cd24f85b
36 changed files with 10298 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
//! Streaming utilities
use tokio::sync::mpsc;
use zclaw_types::Result;
/// Stream event for LLM responses
#[derive(Debug, Clone)]
pub enum StreamEvent {
/// Text delta received
TextDelta(String),
/// Thinking delta received
ThinkingDelta(String),
/// Tool use started
ToolUseStart { id: String, name: String },
/// Tool use input chunk
ToolUseInput { id: String, chunk: String },
/// Tool use completed
ToolUseEnd { id: String, input: serde_json::Value },
/// Response completed
Complete { input_tokens: u32, output_tokens: u32 },
/// Error occurred
Error(String),
}
/// Stream sender wrapper
pub struct StreamSender {
tx: mpsc::Sender<StreamEvent>,
}
impl StreamSender {
pub fn new(tx: mpsc::Sender<StreamEvent>) -> Self {
Self { tx }
}
pub async fn send_text(&self, delta: impl Into<String>) -> Result<()> {
self.tx.send(StreamEvent::TextDelta(delta.into())).await.ok();
Ok(())
}
pub async fn send_thinking(&self, delta: impl Into<String>) -> Result<()> {
self.tx.send(StreamEvent::ThinkingDelta(delta.into())).await.ok();
Ok(())
}
pub async fn send_complete(&self, input_tokens: u32, output_tokens: u32) -> Result<()> {
self.tx.send(StreamEvent::Complete { input_tokens, output_tokens }).await.ok();
Ok(())
}
pub async fn send_error(&self, error: impl Into<String>) -> Result<()> {
self.tx.send(StreamEvent::Error(error.into())).await.ok();
Ok(())
}
}