feat: Adjust module re-exports and publishing settings
This commit is contained in:
parent
9233bb9163
commit
a01f19b112
|
|
@ -2,6 +2,7 @@
|
|||
name = "worker-macros"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
name = "worker-types"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1.89"
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ use tracing_subscriber::EnvFilter;
|
|||
|
||||
use clap::{Parser, ValueEnum};
|
||||
use worker::{
|
||||
ControlFlow, Handler, HookError, TextBlockEvent, TextBlockKind, ToolResult, ToolUseBlockEvent,
|
||||
ToolUseBlockKind, Worker, WorkerHook,
|
||||
Worker,
|
||||
hook::{ControlFlow, HookError, ToolResult, WorkerHook},
|
||||
llm_client::{
|
||||
LlmClient,
|
||||
providers::{
|
||||
|
|
@ -49,6 +49,7 @@ use worker::{
|
|||
openai::OpenAIClient,
|
||||
},
|
||||
},
|
||||
timeline::{Handler, TextBlockEvent, TextBlockKind, ToolUseBlockEvent, ToolUseBlockKind},
|
||||
};
|
||||
use worker_macros::tool_registry;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
//! # 主要なコンポーネント
|
||||
//!
|
||||
//! - [`Worker`] - LLMとの対話を管理する中心コンポーネント
|
||||
//! - [`Tool`] - LLMから呼び出し可能なツール
|
||||
//! - [`WorkerHook`] - ターン進行への介入
|
||||
//! - [`WorkerSubscriber`] - ストリーミングイベントの購読
|
||||
//! - [`tool::Tool`] - LLMから呼び出し可能なツール
|
||||
//! - [`hook::WorkerHook`] - ターン進行への介入
|
||||
//! - [`subscriber::WorkerSubscriber`] - ストリーミングイベントの購読
|
||||
//!
|
||||
//! # Quick Start
|
||||
//!
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
//! .system_prompt("You are a helpful assistant.");
|
||||
//!
|
||||
//! // ツールを登録(オプション)
|
||||
//! use worker::tool::Tool;
|
||||
//! worker.register_tool(my_tool);
|
||||
//!
|
||||
//! // 対話を実行
|
||||
|
|
@ -36,14 +37,57 @@
|
|||
//! ```
|
||||
|
||||
pub mod llm_client;
|
||||
pub mod timeline;
|
||||
|
||||
mod subscriber_adapter;
|
||||
mod text_block_collector;
|
||||
mod timeline;
|
||||
mod tool_call_collector;
|
||||
mod worker;
|
||||
|
||||
pub use text_block_collector::TextBlockCollector;
|
||||
pub use timeline::*;
|
||||
pub use tool_call_collector::ToolCallCollector;
|
||||
pub use worker::*;
|
||||
pub use worker_types::*;
|
||||
// =============================================================================
|
||||
// トップレベル公開(最も頻繁に使う型)
|
||||
// =============================================================================
|
||||
|
||||
pub use worker::{Worker, WorkerConfig, WorkerError};
|
||||
pub use worker_types::{ContentPart, Message, MessageContent, Role};
|
||||
|
||||
// =============================================================================
|
||||
// 意味のあるモジュールとして公開
|
||||
// =============================================================================
|
||||
|
||||
/// ツール定義
|
||||
///
|
||||
/// LLMから呼び出し可能なツールを定義するためのトレイトと型。
|
||||
pub mod tool {
|
||||
pub use worker_types::{Tool, ToolError};
|
||||
}
|
||||
|
||||
/// Hook機能
|
||||
///
|
||||
/// ターンの進行・ツール実行に介入するためのトレイトと型。
|
||||
pub mod hook {
|
||||
pub use worker_types::{ControlFlow, HookError, ToolCall, ToolResult, TurnResult, WorkerHook};
|
||||
}
|
||||
|
||||
/// イベント購読
|
||||
///
|
||||
/// LLMからのストリーミングイベントをリアルタイムで受信するためのトレイト。
|
||||
pub mod subscriber {
|
||||
pub use worker_types::WorkerSubscriber;
|
||||
}
|
||||
|
||||
/// イベント型
|
||||
///
|
||||
/// LLMからのストリーミングレスポンスを表現するイベント型。
|
||||
/// Timeline層を直接使用する場合に必要です。
|
||||
pub mod event {
|
||||
pub use worker_types::{
|
||||
BlockAbort, BlockDelta, BlockMetadata, BlockStart, BlockStop, BlockType, DeltaContent,
|
||||
ErrorEvent, Event, PingEvent, ResponseStatus, StatusEvent, StopReason, UsageEvent,
|
||||
};
|
||||
}
|
||||
|
||||
/// Worker状態
|
||||
///
|
||||
/// Type-stateパターンによるキャッシュ保護のための状態マーカー型。
|
||||
pub mod state {
|
||||
pub use worker_types::{Locked, Mutable, WorkerState};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! LLMクライアント層
|
||||
//!
|
||||
//! 各LLMプロバイダと通信し、統一された[`Event`](crate::Event)ストリームを出力します。
|
||||
//! 各LLMプロバイダと通信し、統一された[`Event`](crate::event::Event)ストリームを出力します。
|
||||
//!
|
||||
//! # サポートするプロバイダ
|
||||
//!
|
||||
|
|
|
|||
33
worker/src/timeline/mod.rs
Normal file
33
worker/src/timeline/mod.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
//! Timeline層
|
||||
//!
|
||||
//! LLMからのイベントストリームを受信し、登録されたHandlerにディスパッチします。
|
||||
//!
|
||||
//! # 主要コンポーネント
|
||||
//!
|
||||
//! - [`Timeline`] - イベントストリームの管理とディスパッチ
|
||||
//! - [`Handler`] - イベントを処理するトレイト
|
||||
//! - [`TextBlockCollector`] - テキストブロックを収集するHandler
|
||||
//! - [`ToolCallCollector`] - ツール呼び出しを収集するHandler
|
||||
|
||||
mod text_block_collector;
|
||||
mod timeline;
|
||||
mod tool_call_collector;
|
||||
|
||||
// 公開API
|
||||
pub use text_block_collector::TextBlockCollector;
|
||||
pub use timeline::{ErasedHandler, HandlerWrapper, Timeline};
|
||||
pub use tool_call_collector::ToolCallCollector;
|
||||
|
||||
// worker-typesからのre-export
|
||||
pub use worker_types::{
|
||||
// Core traits
|
||||
Handler, Kind,
|
||||
// Block Kinds
|
||||
TextBlockKind, ThinkingBlockKind, ToolUseBlockKind,
|
||||
// Block Events
|
||||
TextBlockEvent, TextBlockStart, TextBlockStop,
|
||||
ThinkingBlockEvent, ThinkingBlockStart, ThinkingBlockStop,
|
||||
ToolUseBlockEvent, ToolUseBlockStart, ToolUseBlockStop,
|
||||
// Meta Kinds
|
||||
ErrorKind, PingKind, StatusKind, UsageKind,
|
||||
};
|
||||
|
|
@ -84,7 +84,7 @@ impl Handler<TextBlockKind> for TextBlockCollector {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::Timeline;
|
||||
use crate::timeline::Timeline;
|
||||
use worker_types::Event;
|
||||
|
||||
/// TextBlockCollectorが単一のテキストブロックを正しく収集することを確認
|
||||
|
|
@ -97,7 +97,7 @@ impl Handler<ToolUseBlockKind> for ToolCallCollector {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::Timeline;
|
||||
use crate::timeline::Timeline;
|
||||
use worker_types::Event;
|
||||
|
||||
#[test]
|
||||
|
|
@ -5,14 +5,12 @@ use std::sync::{Arc, Mutex};
|
|||
use futures::StreamExt;
|
||||
use tracing::{debug, info, trace, warn};
|
||||
|
||||
use crate::Timeline;
|
||||
use crate::timeline::{TextBlockCollector, Timeline, ToolCallCollector};
|
||||
use crate::llm_client::{ClientError, LlmClient, Request, ToolDefinition};
|
||||
use crate::subscriber_adapter::{
|
||||
ErrorSubscriberAdapter, StatusSubscriberAdapter, TextBlockSubscriberAdapter,
|
||||
ToolUseBlockSubscriberAdapter, UsageSubscriberAdapter,
|
||||
};
|
||||
use crate::text_block_collector::TextBlockCollector;
|
||||
use crate::tool_call_collector::ToolCallCollector;
|
||||
use worker_types::{
|
||||
ContentPart, ControlFlow, HookError, Locked, Message, MessageContent, Mutable, Tool, ToolCall,
|
||||
ToolError, ToolResult, TurnResult, WorkerHook, WorkerState, WorkerSubscriber,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use std::sync::{Arc, Mutex};
|
|||
use async_trait::async_trait;
|
||||
use futures::Stream;
|
||||
use worker::llm_client::{ClientError, LlmClient, Request};
|
||||
use worker::{Handler, TextBlockEvent, TextBlockKind, Timeline};
|
||||
use worker::timeline::{Handler, TextBlockEvent, TextBlockKind, Timeline};
|
||||
use worker_types::{BlockType, DeltaContent, Event};
|
||||
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ mod common;
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use common::MockLlmClient;
|
||||
use worker::{Worker, WorkerSubscriber};
|
||||
use worker::subscriber::WorkerSubscriber;
|
||||
use worker::Worker;
|
||||
use worker_types::{
|
||||
ErrorEvent, Event, ResponseStatus, StatusEvent, TextBlockEvent, ToolCall, ToolUseBlockEvent,
|
||||
UsageEvent,
|
||||
|
|
|
|||
|
|
@ -205,8 +205,7 @@ async fn test_worker_with_programmatic_events() {
|
|||
/// id, name, input(JSON)を正しく抽出できることを検証する。
|
||||
#[tokio::test]
|
||||
async fn test_tool_call_collector_integration() {
|
||||
use worker::Timeline;
|
||||
use worker::ToolCallCollector;
|
||||
use worker::timeline::{Timeline, ToolCallCollector};
|
||||
use worker_types::Event;
|
||||
|
||||
// ToolUseブロックを含むイベントシーケンス
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user