feat: Adjust module re-exports and publishing settings
This commit is contained in:
parent
9233bb9163
commit
a01f19b112
|
|
@ -2,6 +2,7 @@
|
||||||
name = "worker-macros"
|
name = "worker-macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
publish = false
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
name = "worker-types"
|
name = "worker-types"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait = "0.1.89"
|
async-trait = "0.1.89"
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use worker::{
|
use worker::{
|
||||||
ControlFlow, Handler, HookError, TextBlockEvent, TextBlockKind, ToolResult, ToolUseBlockEvent,
|
Worker,
|
||||||
ToolUseBlockKind, Worker, WorkerHook,
|
hook::{ControlFlow, HookError, ToolResult, WorkerHook},
|
||||||
llm_client::{
|
llm_client::{
|
||||||
LlmClient,
|
LlmClient,
|
||||||
providers::{
|
providers::{
|
||||||
|
|
@ -49,6 +49,7 @@ use worker::{
|
||||||
openai::OpenAIClient,
|
openai::OpenAIClient,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
timeline::{Handler, TextBlockEvent, TextBlockKind, ToolUseBlockEvent, ToolUseBlockKind},
|
||||||
};
|
};
|
||||||
use worker_macros::tool_registry;
|
use worker_macros::tool_registry;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
//! # 主要なコンポーネント
|
//! # 主要なコンポーネント
|
||||||
//!
|
//!
|
||||||
//! - [`Worker`] - LLMとの対話を管理する中心コンポーネント
|
//! - [`Worker`] - LLMとの対話を管理する中心コンポーネント
|
||||||
//! - [`Tool`] - LLMから呼び出し可能なツール
|
//! - [`tool::Tool`] - LLMから呼び出し可能なツール
|
||||||
//! - [`WorkerHook`] - ターン進行への介入
|
//! - [`hook::WorkerHook`] - ターン進行への介入
|
||||||
//! - [`WorkerSubscriber`] - ストリーミングイベントの購読
|
//! - [`subscriber::WorkerSubscriber`] - ストリーミングイベントの購読
|
||||||
//!
|
//!
|
||||||
//! # Quick Start
|
//! # Quick Start
|
||||||
//!
|
//!
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
//! .system_prompt("You are a helpful assistant.");
|
//! .system_prompt("You are a helpful assistant.");
|
||||||
//!
|
//!
|
||||||
//! // ツールを登録(オプション)
|
//! // ツールを登録(オプション)
|
||||||
|
//! use worker::tool::Tool;
|
||||||
//! worker.register_tool(my_tool);
|
//! worker.register_tool(my_tool);
|
||||||
//!
|
//!
|
||||||
//! // 対話を実行
|
//! // 対話を実行
|
||||||
|
|
@ -36,14 +37,57 @@
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
pub mod llm_client;
|
pub mod llm_client;
|
||||||
|
pub mod timeline;
|
||||||
|
|
||||||
mod subscriber_adapter;
|
mod subscriber_adapter;
|
||||||
mod text_block_collector;
|
|
||||||
mod timeline;
|
|
||||||
mod tool_call_collector;
|
|
||||||
mod worker;
|
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クライアント層
|
||||||
//!
|
//!
|
||||||
//! 各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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::Timeline;
|
use crate::timeline::Timeline;
|
||||||
use worker_types::Event;
|
use worker_types::Event;
|
||||||
|
|
||||||
/// TextBlockCollectorが単一のテキストブロックを正しく収集することを確認
|
/// TextBlockCollectorが単一のテキストブロックを正しく収集することを確認
|
||||||
|
|
@ -97,7 +97,7 @@ impl Handler<ToolUseBlockKind> for ToolCallCollector {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::Timeline;
|
use crate::timeline::Timeline;
|
||||||
use worker_types::Event;
|
use worker_types::Event;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -5,14 +5,12 @@ use std::sync::{Arc, Mutex};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use tracing::{debug, info, trace, warn};
|
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::llm_client::{ClientError, LlmClient, Request, ToolDefinition};
|
||||||
use crate::subscriber_adapter::{
|
use crate::subscriber_adapter::{
|
||||||
ErrorSubscriberAdapter, StatusSubscriberAdapter, TextBlockSubscriberAdapter,
|
ErrorSubscriberAdapter, StatusSubscriberAdapter, TextBlockSubscriberAdapter,
|
||||||
ToolUseBlockSubscriberAdapter, UsageSubscriberAdapter,
|
ToolUseBlockSubscriberAdapter, UsageSubscriberAdapter,
|
||||||
};
|
};
|
||||||
use crate::text_block_collector::TextBlockCollector;
|
|
||||||
use crate::tool_call_collector::ToolCallCollector;
|
|
||||||
use worker_types::{
|
use worker_types::{
|
||||||
ContentPart, ControlFlow, HookError, Locked, Message, MessageContent, Mutable, Tool, ToolCall,
|
ContentPart, ControlFlow, HookError, Locked, Message, MessageContent, Mutable, Tool, ToolCall,
|
||||||
ToolError, ToolResult, TurnResult, WorkerHook, WorkerState, WorkerSubscriber,
|
ToolError, ToolResult, TurnResult, WorkerHook, WorkerState, WorkerSubscriber,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use std::sync::{Arc, Mutex};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use worker::llm_client::{ClientError, LlmClient, Request};
|
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 worker_types::{BlockType, DeltaContent, Event};
|
||||||
|
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ mod common;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use common::MockLlmClient;
|
use common::MockLlmClient;
|
||||||
use worker::{Worker, WorkerSubscriber};
|
use worker::subscriber::WorkerSubscriber;
|
||||||
|
use worker::Worker;
|
||||||
use worker_types::{
|
use worker_types::{
|
||||||
ErrorEvent, Event, ResponseStatus, StatusEvent, TextBlockEvent, ToolCall, ToolUseBlockEvent,
|
ErrorEvent, Event, ResponseStatus, StatusEvent, TextBlockEvent, ToolCall, ToolUseBlockEvent,
|
||||||
UsageEvent,
|
UsageEvent,
|
||||||
|
|
|
||||||
|
|
@ -205,8 +205,7 @@ async fn test_worker_with_programmatic_events() {
|
||||||
/// id, name, input(JSON)を正しく抽出できることを検証する。
|
/// id, name, input(JSON)を正しく抽出できることを検証する。
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_tool_call_collector_integration() {
|
async fn test_tool_call_collector_integration() {
|
||||||
use worker::Timeline;
|
use worker::timeline::{Timeline, ToolCallCollector};
|
||||||
use worker::ToolCallCollector;
|
|
||||||
use worker_types::Event;
|
use worker_types::Event;
|
||||||
|
|
||||||
// ToolUseブロックを含むイベントシーケンス
|
// ToolUseブロックを含むイベントシーケンス
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user