Kotoba Handler - Unified Integration
kotoba-handler はKotobaエコシステム全体の統合的なhandlerを提供するクレートです。
統合アーキテクチャ
既存クレートとの統合
1. kotoba-jsonnet との統合
// Jsonnet評価機能の統合
use JsonnetEvaluationHandler;
let handler = new;
let result = handler.evaluate?;
2. kotoba-kotobas との統合
// HTTP設定パーサーの統合
use KotobasHttpHandler;
let handler = new?;
let route = handler.find_route?;
3. kotoba-server との統合
// HTTPサーバー機能の統合
use server;
run_server.await?;
使用方法
基本的な使用例
use ;
// シンプルな実行
let context = HandlerContext ;
let result = execute_simple_handler.await?;
統合handlerの使用
use IntegratedHandler;
// JsonnetとKotobasの両方を統合
let mut handler = new?;
let result = handler.process_request.await?;
Executorを使用した実行
use ;
let executor = new
.with_mode;
let result = executor.execute_batch.await?;
機能
コア機能
- Unified Handler: すべてのKotoba操作の統一インターフェース
- Multiple Runtimes: Native, WASM, Node.js, Deno, Browser
- Execution Modes: Sync, Async, Streaming
- Caching: 自動結果キャッシュ
- Configuration: 柔軟な設定管理
統合機能
- Jsonnet Integration: オプションのJsonnet評価(後方互換)
- Kotobas Integration: HTTP設定パーサー
- Server Integration: HTTPサーバー統合
- CLI Integration: コマンドライン統合
- WASM Integration: ブラウザ実行
設定
Cargo.toml
[]
= { = "https://github.com/com-junkawasaki/kotoba", = ["full"] }
機能フラグ
default: CLIとサーバー機能cli: CLI統合server: HTTPサーバー統合wasm: WASM実行環境websocket: WebSocketサポートjsonnet-integration: Jsonnet統合(オプション)full: すべての機能
統合フロー
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ densha │────│ kotoba-handler │────│ kotoba-* │
│ │ │ │ │ crates │
│ - CLI Interface │ │ - Unified API │ │ │
│ - HTTP Server │ │ - Runtime Mgmt │ │ - jsonnet │
│ - File System │ │ - Caching │ │ - kotobas │
└─────────────────┘ │ - Integration │ │ - server │
└──────────────────┘ │ - 2tsx │
└─────────────────┘
後方互換性
- Jsonnet統合はオプション機能として提供
- 既存のkotoba-jsonnet, kotoba-kotobasのAPIは維持
- 段階的な移行が可能
利点
- 統合インターフェース: すべてのKotoba機能を統一的に扱える
- 柔軟な実行環境: 複数のランタイムをサポート
- パフォーマンス最適化: キャッシュとストリーミング
- 開発効率向上: シンプルなAPIで複雑な処理が可能
- 将来拡張性: 新しい統合機能の容易な追加