feat: Implement worker context management and cache protection mechanisms using type-state

This commit is contained in:
2026-01-08 17:57:03 +09:00
parent 45c8457b71
commit 2487d1ece7
9 changed files with 831 additions and 195 deletions
+4 -17
View File
@@ -51,7 +51,6 @@ use worker::{
},
};
use worker_macros::tool_registry;
use worker_types::Message;
// 必要なマクロ展開用インポート
use schemars;
@@ -453,14 +452,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
worker.add_hook(ToolResultPrinterHook::new(tool_call_names));
// 会話履歴
let mut history: Vec<Message> = Vec::new();
// ワンショットモード
if let Some(prompt) = args.prompt {
history.push(Message::user(&prompt));
match worker.run(history).await {
match worker.run(&prompt).await {
Ok(_) => {}
Err(e) => {
eprintln!("\n❌ Error: {}", e);
@@ -489,18 +483,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
break;
}
// ユーザーメッセージを履歴に追加
history.push(Message::user(input));
// Workerを実行
match worker.run(history.clone()).await {
Ok(new_history) => {
history = new_history;
}
// Workerを実行(Workerが履歴を管理)
match worker.run(input).await {
Ok(_) => {}
Err(e) => {
eprintln!("\n❌ Error: {}", e);
// エラー時は最後のユーザーメッセージを削除
history.pop();
}
}
}