feat: Implement worker context management and cache protection mechanisms using type-state
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user