fix: account hook system item appends
This commit is contained in:
@@ -42,6 +42,12 @@ pub enum PreRequestAction {
|
||||
/// to: the items are committed before the request so later turns can see
|
||||
/// why the worker changed course.
|
||||
ContinueWith(Vec<Item>),
|
||||
/// Yield after appending these items to durable worker history.
|
||||
///
|
||||
/// This is for host-mediated pre-request appends that must be visible to
|
||||
/// usage accounting and compaction checks before the current LLM request is
|
||||
/// allowed to proceed.
|
||||
YieldWith(Vec<Item>),
|
||||
/// Cancel with a reason (treated as an error).
|
||||
Cancel(String),
|
||||
/// Yield control to the caller for external processing.
|
||||
|
||||
@@ -1177,6 +1177,16 @@ impl<C: LlmClient, S: WorkerState> Worker<C, S> {
|
||||
self.last_run_interrupted = true;
|
||||
return Err(WorkerError::Aborted(reason));
|
||||
}
|
||||
PreRequestAction::YieldWith(items) => {
|
||||
self.append_history_items(items.clone());
|
||||
request_context.extend(items);
|
||||
info!("Yielded by interceptor after pre-request history append");
|
||||
for cb in &self.turn_end_cbs {
|
||||
cb(current_turn);
|
||||
}
|
||||
self.last_run_interrupted = true;
|
||||
return Ok(WorkerResult::Yielded);
|
||||
}
|
||||
PreRequestAction::Yield => {
|
||||
info!("Yielded by interceptor");
|
||||
for cb in &self.turn_end_cbs {
|
||||
|
||||
Reference in New Issue
Block a user