pub struct Timeline { /* private fields */ }Expand description
イベントストリームの管理とハンドラへのディスパッチ
LLMからのイベントを受信し、登録されたハンドラに振り分けます。 ブロック系イベントはスコープ管理付きで処理されます。
§Examples
ⓘ
use llm_worker::{Timeline, Handler, TextBlockKind, TextBlockEvent};
struct MyHandler;
impl Handler<TextBlockKind> for MyHandler {
type Scope = String;
fn on_event(&mut self, buffer: &mut String, event: &TextBlockEvent) {
if let TextBlockEvent::Delta(text) = event {
buffer.push_str(text);
}
}
}
let mut timeline = Timeline::new();
timeline.on_text_block(MyHandler);§サポートするイベント種別
- メタ系: Usage, Ping, Status, Error
- ブロック系: TextBlock, ThinkingBlock, ToolUseBlock
Implementations§
Source§impl Timeline
impl Timeline
pub fn new() -> Self
Sourcepub fn on_text_block<H>(&mut self, handler: H) -> &mut Self
pub fn on_text_block<H>(&mut self, handler: H) -> &mut Self
TextBlockKind用のHandlerを登録
Sourcepub fn on_thinking_block<H>(&mut self, handler: H) -> &mut Self
pub fn on_thinking_block<H>(&mut self, handler: H) -> &mut Self
ThinkingBlockKind用のHandlerを登録
Sourcepub fn on_tool_use_block<H>(&mut self, handler: H) -> &mut Self
pub fn on_tool_use_block<H>(&mut self, handler: H) -> &mut Self
ToolUseBlockKind用のHandlerを登録
Sourcepub fn current_block(&self) -> Option<BlockType>
pub fn current_block(&self) -> Option<BlockType>
現在アクティブなブロックタイプを取得
Sourcepub fn abort_current_block(&mut self)
pub fn abort_current_block(&mut self)
現在アクティブなブロックを中断する
キャンセルやエラー時に呼び出し、進行中のブロックに対して BlockAbortイベントを発火してスコープをクリーンアップする。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Timeline
impl !RefUnwindSafe for Timeline
impl Send for Timeline
impl Sync for Timeline
impl Unpin for Timeline
impl !UnwindSafe for Timeline
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more