1use std::fmt;
14use std::sync::Arc;
15
16use crate::agent::continuation::ContinuationInput;
17use crate::agent::{AgentResult, InvocationContext, InvocationState, InvokeArgs, LocalAgent, ToolAgent};
18use crate::error::Error;
19use crate::interrupt::{Interrupt, InterruptError, InterruptSource};
20use crate::models::streaming::ModelStreamEvent;
21use crate::models::{Model, Redaction};
22use crate::tools::{Tool, ToolStreamEvent};
23use crate::types::{
24 ContentBlock, InterruptParams, JsonValue, Message, StopReason, ToolResultBlock, ToolResultError, ToolUse,
25};
26
27pub type ToolUseData = ToolUse;
29
30#[derive(Debug, Clone, Default, PartialEq, Eq)]
32#[non_exhaustive]
33pub enum Cancel {
34 #[default]
36 NotCancelled,
37 Cancelled,
39 Message(String),
41}
42
43impl Cancel {
44 #[must_use]
46 pub fn is_cancelled(&self) -> bool {
47 !matches!(self, Self::NotCancelled)
48 }
49
50 #[must_use]
52 pub fn message_or<'a>(&'a self, default: &'a str) -> Option<&'a str> {
53 match self {
54 Self::NotCancelled => None,
55 Self::Cancelled => Some(default),
56 Self::Message(message) => Some(message),
57 }
58 }
59}
60
61impl From<bool> for Cancel {
62 fn from(cancel: bool) -> Self {
63 if cancel { Self::Cancelled } else { Self::NotCancelled }
64 }
65}
66
67impl From<&str> for Cancel {
68 fn from(message: &str) -> Self {
69 Self::Message(message.to_owned())
70 }
71}
72
73impl From<String> for Cancel {
74 fn from(message: String) -> Self {
75 Self::Message(message)
76 }
77}
78
79#[derive(Debug, Clone, Default, PartialEq)]
81#[non_exhaustive]
82pub enum EndTurn {
83 #[default]
85 Continue,
86 End,
88 Message(String),
90 Content(Vec<ContentBlock>),
92}
93
94impl EndTurn {
95 #[must_use]
97 pub fn is_end(&self) -> bool {
98 !matches!(self, Self::Continue)
99 }
100}
101
102impl From<bool> for EndTurn {
103 fn from(end: bool) -> Self {
104 if end { Self::End } else { Self::Continue }
105 }
106}
107
108impl From<&str> for EndTurn {
109 fn from(message: &str) -> Self {
110 Self::Message(message.to_owned())
111 }
112}
113
114impl From<String> for EndTurn {
115 fn from(message: String) -> Self {
116 Self::Message(message)
117 }
118}
119
120impl From<Vec<ContentBlock>> for EndTurn {
121 fn from(content: Vec<ContentBlock>) -> Self {
122 Self::Content(content)
123 }
124}
125
126#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
128#[serde(rename_all = "camelCase")]
129#[non_exhaustive]
130pub struct ModelStopResponse {
131 pub message: Message,
133 pub stop_reason: StopReason,
135 #[serde(default, skip_serializing_if = "Option::is_none")]
138 pub redaction: Option<Redaction>,
139}
140
141impl ModelStopResponse {
142 pub fn new(message: Message, stop_reason: StopReason) -> Self {
144 Self {
145 message,
146 stop_reason,
147 redaction: None,
148 }
149 }
150
151 #[must_use]
153 pub fn with_redaction(mut self, redaction: Redaction) -> Self {
154 self.redaction = Some(redaction);
155 self
156 }
157}
158
159struct Sequential<'a> {
161 agent: &'a mut LocalAgent,
162 invocation_state: InvocationState,
163 invocation_context: Option<InvocationContext>,
164}
165
166impl<'a> Sequential<'a> {
167 fn new(agent: &'a mut LocalAgent, invocation_state: InvocationState) -> Self {
168 Self {
169 agent,
170 invocation_state,
171 invocation_context: None,
172 }
173 }
174}
175
176#[derive(Clone)]
178struct PerTool {
179 agent: ToolAgent,
180 invocation_state: InvocationState,
181 invocation_context: Option<InvocationContext>,
182}
183
184impl PerTool {
185 fn new(agent: ToolAgent, invocation_state: InvocationState) -> Self {
186 let invocation_context = agent.invocation_context().cloned();
187 Self {
188 agent,
189 invocation_state,
190 invocation_context,
191 }
192 }
193}
194
195macro_rules! sequential_accessors {
196 ($event:ident) => {
197 impl<'a> $event<'a> {
198 #[must_use]
200 pub fn agent(&self) -> &LocalAgent {
201 self.base.agent
202 }
203
204 pub fn agent_mut(&mut self) -> &mut LocalAgent {
206 self.base.agent
207 }
208
209 #[must_use]
211 pub fn invocation_state(&self) -> &InvocationState {
212 &self.base.invocation_state
213 }
214
215 #[must_use]
217 pub fn invocation_context(&self) -> Option<&InvocationContext> {
218 self.base.invocation_context.as_ref()
219 }
220
221 pub(crate) fn with_invocation_context(mut self, context: Option<InvocationContext>) -> Self {
222 self.base.invocation_context = context;
223 self
224 }
225 }
226
227 impl fmt::Debug for $event<'_> {
228 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
229 f.debug_struct(stringify!($event)).finish_non_exhaustive()
230 }
231 }
232 };
233}
234
235macro_rules! per_tool_accessors {
236 ($event:ident) => {
237 impl $event {
238 #[must_use]
240 pub fn agent(&self) -> &ToolAgent {
241 &self.base.agent
242 }
243
244 #[must_use]
246 pub fn invocation_state(&self) -> &InvocationState {
247 &self.base.invocation_state
248 }
249
250 #[must_use]
252 pub fn invocation_context(&self) -> Option<&InvocationContext> {
253 self.base.invocation_context.as_ref()
254 }
255 }
256
257 impl fmt::Debug for $event {
258 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
259 f.debug_struct(stringify!($event)).finish_non_exhaustive()
260 }
261 }
262 };
263}
264
265#[non_exhaustive]
269pub struct InitializedEvent<'a> {
270 agent: &'a mut LocalAgent,
271}
272
273impl<'a> InitializedEvent<'a> {
274 pub(crate) fn new(agent: &'a mut LocalAgent) -> Self {
275 Self { agent }
276 }
277
278 #[must_use]
280 pub fn agent(&self) -> &LocalAgent {
281 self.agent
282 }
283
284 pub fn agent_mut(&mut self) -> &mut LocalAgent {
286 self.agent
287 }
288}
289
290impl fmt::Debug for InitializedEvent<'_> {
291 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
292 f.debug_struct("InitializedEvent").finish_non_exhaustive()
293 }
294}
295
296#[non_exhaustive]
298pub struct BeforeInvocationEvent<'a> {
299 base: Sequential<'a>,
300 messages: Vec<Message>,
301 cancel: Cancel,
302}
303
304sequential_accessors!(BeforeInvocationEvent);
305
306impl<'a> BeforeInvocationEvent<'a> {
307 pub(crate) fn new(agent: &'a mut LocalAgent, invocation_state: InvocationState, messages: Vec<Message>) -> Self {
308 Self {
309 base: Sequential::new(agent, invocation_state),
310 messages,
311 cancel: Cancel::NotCancelled,
312 }
313 }
314
315 #[must_use]
317 pub fn messages(&self) -> &[Message] {
318 &self.messages
319 }
320
321 pub fn messages_mut(&mut self) -> &mut Vec<Message> {
323 &mut self.messages
324 }
325
326 pub fn set_messages(&mut self, messages: Vec<Message>) {
328 self.messages = messages;
329 }
330
331 #[must_use]
333 pub fn cancel(&self) -> &Cancel {
334 &self.cancel
335 }
336
337 pub fn set_cancel(&mut self, cancel: impl Into<Cancel>) {
340 self.cancel = cancel.into();
341 }
342
343 pub(crate) fn take_messages(&mut self) -> Vec<Message> {
344 std::mem::take(&mut self.messages)
345 }
346}
347
348#[non_exhaustive]
351pub struct AfterInvocationEvent<'a> {
352 base: Sequential<'a>,
353 resume: Option<InvokeArgs>,
354 continuation_inputs: Vec<ContinuationInput>,
355}
356
357sequential_accessors!(AfterInvocationEvent);
358
359impl<'a> AfterInvocationEvent<'a> {
360 pub(crate) fn new(agent: &'a mut LocalAgent, invocation_state: InvocationState) -> Self {
361 Self {
362 base: Sequential::new(agent, invocation_state),
363 resume: None,
364 continuation_inputs: Vec::new(),
365 }
366 }
367
368 #[must_use]
370 pub fn resume(&self) -> Option<&InvokeArgs> {
371 self.resume.as_ref()
372 }
373
374 pub fn set_resume(&mut self, args: impl Into<InvokeArgs>) {
378 self.resume = Some(args.into());
379 }
380
381 pub fn clear_resume(&mut self) {
383 self.resume = None;
384 }
385
386 pub(crate) fn take_resume(&mut self) -> Option<InvokeArgs> {
387 self.resume.take()
388 }
389
390 pub(crate) fn add_continuation_input(&mut self, input: ContinuationInput) {
392 self.continuation_inputs.push(input);
393 }
394
395 pub(crate) fn take_continuation_inputs(&mut self) -> Vec<ContinuationInput> {
396 std::mem::take(&mut self.continuation_inputs)
397 }
398}
399
400#[non_exhaustive]
402pub struct MessageAddedEvent<'a> {
403 base: Sequential<'a>,
404 message: Message,
405}
406
407sequential_accessors!(MessageAddedEvent);
408
409impl<'a> MessageAddedEvent<'a> {
410 pub(crate) fn new(agent: &'a mut LocalAgent, invocation_state: InvocationState, message: Message) -> Self {
411 Self {
412 base: Sequential::new(agent, invocation_state),
413 message,
414 }
415 }
416
417 #[must_use]
419 pub fn message(&self) -> &Message {
420 &self.message
421 }
422}
423
424#[non_exhaustive]
426pub struct BeforeModelCallEvent<'a> {
427 base: Sequential<'a>,
428 model: Arc<dyn Model>,
429 projected_input_tokens: Option<u64>,
430 cancel: Cancel,
431 continuation_inputs: Vec<ContinuationInput>,
432 raised_interrupts: Vec<Interrupt>,
433}
434
435sequential_accessors!(BeforeModelCallEvent);
436
437impl<'a> BeforeModelCallEvent<'a> {
438 pub(crate) fn new(agent: &'a mut LocalAgent, invocation_state: InvocationState, model: Arc<dyn Model>) -> Self {
439 Self {
440 base: Sequential::new(agent, invocation_state),
441 model,
442 projected_input_tokens: None,
443 cancel: Cancel::NotCancelled,
444 continuation_inputs: Vec::new(),
445 raised_interrupts: Vec::new(),
446 }
447 }
448
449 pub(crate) fn add_continuation_input(&mut self, input: ContinuationInput) {
451 self.continuation_inputs.push(input);
452 }
453
454 pub(crate) fn raise_interrupts(&mut self, interrupts: Vec<Interrupt>) {
457 self.raised_interrupts.extend(interrupts);
458 }
459
460 pub(crate) fn take_raised_interrupts(&mut self) -> Vec<Interrupt> {
461 std::mem::take(&mut self.raised_interrupts)
462 }
463
464 pub(crate) fn take_continuation_inputs(&mut self) -> Vec<ContinuationInput> {
465 std::mem::take(&mut self.continuation_inputs)
466 }
467
468 #[must_use]
469 pub(crate) fn with_projected_input_tokens(mut self, tokens: u64) -> Self {
470 self.projected_input_tokens = Some(tokens);
471 self
472 }
473
474 #[must_use]
476 pub fn model(&self) -> &Arc<dyn Model> {
477 &self.model
478 }
479
480 #[must_use]
482 pub fn projected_input_tokens(&self) -> Option<u64> {
483 self.projected_input_tokens
484 }
485
486 #[must_use]
488 pub fn cancel(&self) -> &Cancel {
489 &self.cancel
490 }
491
492 pub fn set_cancel(&mut self, cancel: impl Into<Cancel>) {
495 self.cancel = cancel.into();
496 }
497}
498
499#[non_exhaustive]
502pub struct AfterModelCallEvent<'a> {
503 base: Sequential<'a>,
504 model: Arc<dyn Model>,
505 attempt_count: u32,
506 stop_data: Option<ModelStopResponse>,
507 error: Option<Error>,
508 retry: bool,
509}
510
511sequential_accessors!(AfterModelCallEvent);
512
513impl<'a> AfterModelCallEvent<'a> {
514 pub(crate) fn new(
515 agent: &'a mut LocalAgent,
516 invocation_state: InvocationState,
517 model: Arc<dyn Model>,
518 attempt_count: u32,
519 ) -> Self {
520 Self {
521 base: Sequential::new(agent, invocation_state),
522 model,
523 attempt_count,
524 stop_data: None,
525 error: None,
526 retry: false,
527 }
528 }
529
530 #[must_use]
531 pub(crate) fn with_stop_data(mut self, stop_data: ModelStopResponse) -> Self {
532 self.stop_data = Some(stop_data);
533 self
534 }
535
536 #[must_use]
537 pub(crate) fn with_error(mut self, error: Error) -> Self {
538 self.error = Some(error);
539 self
540 }
541
542 #[must_use]
544 pub fn model(&self) -> &Arc<dyn Model> {
545 &self.model
546 }
547
548 #[must_use]
551 pub fn attempt_count(&self) -> u32 {
552 self.attempt_count
553 }
554
555 #[must_use]
557 pub fn stop_data(&self) -> Option<&ModelStopResponse> {
558 self.stop_data.as_ref()
559 }
560
561 #[must_use]
563 pub fn error(&self) -> Option<&Error> {
564 self.error.as_ref()
565 }
566
567 #[must_use]
569 pub fn retry(&self) -> bool {
570 self.retry
571 }
572
573 pub fn set_retry(&mut self, retry: bool) {
575 self.retry = retry;
576 }
577
578 pub(crate) fn take_error(&mut self) -> Option<Error> {
579 self.error.take()
580 }
581}
582
583#[non_exhaustive]
585pub struct ModelStreamUpdateEvent<'a> {
586 base: Sequential<'a>,
587 event: ModelStreamEvent,
588}
589
590sequential_accessors!(ModelStreamUpdateEvent);
591
592impl<'a> ModelStreamUpdateEvent<'a> {
593 pub(crate) fn new(agent: &'a mut LocalAgent, invocation_state: InvocationState, event: ModelStreamEvent) -> Self {
594 Self {
595 base: Sequential::new(agent, invocation_state),
596 event,
597 }
598 }
599
600 #[must_use]
602 pub fn event(&self) -> &ModelStreamEvent {
603 &self.event
604 }
605}
606
607#[non_exhaustive]
609pub struct ContentBlockEvent<'a> {
610 base: Sequential<'a>,
611 content_block: ContentBlock,
612}
613
614sequential_accessors!(ContentBlockEvent);
615
616impl<'a> ContentBlockEvent<'a> {
617 pub(crate) fn new(
618 agent: &'a mut LocalAgent,
619 invocation_state: InvocationState,
620 content_block: ContentBlock,
621 ) -> Self {
622 Self {
623 base: Sequential::new(agent, invocation_state),
624 content_block,
625 }
626 }
627
628 #[must_use]
630 pub fn content_block(&self) -> &ContentBlock {
631 &self.content_block
632 }
633}
634
635#[non_exhaustive]
637pub struct ModelMessageEvent<'a> {
638 base: Sequential<'a>,
639 message: Message,
640 stop_reason: StopReason,
641}
642
643sequential_accessors!(ModelMessageEvent);
644
645impl<'a> ModelMessageEvent<'a> {
646 pub(crate) fn new(
647 agent: &'a mut LocalAgent,
648 invocation_state: InvocationState,
649 message: Message,
650 stop_reason: StopReason,
651 ) -> Self {
652 Self {
653 base: Sequential::new(agent, invocation_state),
654 message,
655 stop_reason,
656 }
657 }
658
659 #[must_use]
661 pub fn message(&self) -> &Message {
662 &self.message
663 }
664
665 #[must_use]
667 pub fn stop_reason(&self) -> StopReason {
668 self.stop_reason.clone()
669 }
670}
671
672#[non_exhaustive]
674pub struct BeforeToolsEvent<'a> {
675 base: Sequential<'a>,
676 message: Message,
677 cancel: Cancel,
678 interrupts: Vec<Interrupt>,
679}
680
681sequential_accessors!(BeforeToolsEvent);
682
683impl<'a> BeforeToolsEvent<'a> {
684 pub(crate) fn new(agent: &'a mut LocalAgent, invocation_state: InvocationState, message: Message) -> Self {
685 Self {
686 base: Sequential::new(agent, invocation_state),
687 message,
688 cancel: Cancel::NotCancelled,
689 interrupts: Vec::new(),
690 }
691 }
692
693 #[must_use]
695 pub fn message(&self) -> &Message {
696 &self.message
697 }
698
699 #[must_use]
701 pub fn cancel(&self) -> &Cancel {
702 &self.cancel
703 }
704
705 pub fn set_cancel(&mut self, cancel: impl Into<Cancel>) {
708 self.cancel = cancel.into();
709 }
710
711 pub fn interrupt(&mut self, params: impl Into<InterruptParams>) -> Result<JsonValue, InterruptError> {
722 let params = params.into();
723 let id = format!("hook:beforeTools:{}", params.name);
724 let raised = self
725 .base
726 .agent
727 .interrupt_state()
728 .raise(&id, ¶ms, InterruptSource::Hook);
729 raised.inspect_err(|error| self.interrupts.extend(error.interrupts.iter().cloned()))
730 }
731
732 pub(crate) fn take_interrupts(&mut self) -> Vec<Interrupt> {
733 std::mem::take(&mut self.interrupts)
734 }
735}
736
737#[non_exhaustive]
740pub struct AfterToolsEvent<'a> {
741 base: Sequential<'a>,
742 message: Message,
743 end_turn: EndTurn,
744}
745
746sequential_accessors!(AfterToolsEvent);
747
748impl<'a> AfterToolsEvent<'a> {
749 pub(crate) fn new(agent: &'a mut LocalAgent, invocation_state: InvocationState, message: Message) -> Self {
750 Self {
751 base: Sequential::new(agent, invocation_state),
752 message,
753 end_turn: EndTurn::Continue,
754 }
755 }
756
757 #[must_use]
759 pub fn message(&self) -> &Message {
760 &self.message
761 }
762
763 #[must_use]
765 pub fn end_turn(&self) -> &EndTurn {
766 &self.end_turn
767 }
768
769 pub fn set_end_turn(&mut self, end_turn: impl Into<EndTurn>) {
773 self.end_turn = end_turn.into();
774 }
775}
776
777#[non_exhaustive]
779pub struct AgentResultEvent<'a> {
780 base: Sequential<'a>,
781 result: AgentResult,
782}
783
784sequential_accessors!(AgentResultEvent);
785
786impl<'a> AgentResultEvent<'a> {
787 pub(crate) fn new(agent: &'a mut LocalAgent, invocation_state: InvocationState, result: AgentResult) -> Self {
788 Self {
789 base: Sequential::new(agent, invocation_state),
790 result,
791 }
792 }
793
794 #[must_use]
796 pub fn result(&self) -> &AgentResult {
797 &self.result
798 }
799}
800
801#[non_exhaustive]
804pub struct InterruptEvent<'a> {
805 base: Sequential<'a>,
806 interrupt: Interrupt,
807}
808
809sequential_accessors!(InterruptEvent);
810
811impl<'a> InterruptEvent<'a> {
812 pub(crate) fn new(agent: &'a mut LocalAgent, invocation_state: InvocationState, interrupt: Interrupt) -> Self {
813 Self {
814 base: Sequential::new(agent, invocation_state),
815 interrupt,
816 }
817 }
818
819 #[must_use]
821 pub fn interrupt(&self) -> &Interrupt {
822 &self.interrupt
823 }
824}
825
826#[non_exhaustive]
832pub struct BeforeToolCallEvent {
833 base: PerTool,
834 tool_use: ToolUse,
835 tool: Option<Arc<dyn Tool>>,
836 cancel: Cancel,
837 selected_tool: Option<Arc<dyn Tool>>,
838 interrupts: Vec<Interrupt>,
839}
840
841per_tool_accessors!(BeforeToolCallEvent);
842
843impl BeforeToolCallEvent {
844 pub(crate) fn new(
845 agent: ToolAgent,
846 invocation_state: InvocationState,
847 tool_use: ToolUse,
848 tool: Option<Arc<dyn Tool>>,
849 ) -> Self {
850 Self {
851 base: PerTool::new(agent, invocation_state),
852 tool_use,
853 tool,
854 cancel: Cancel::NotCancelled,
855 selected_tool: None,
856 interrupts: Vec::new(),
857 }
858 }
859
860 #[must_use]
862 pub fn tool_use(&self) -> &ToolUse {
863 &self.tool_use
864 }
865
866 pub fn tool_use_mut(&mut self) -> &mut ToolUse {
868 &mut self.tool_use
869 }
870
871 pub fn set_tool_use(&mut self, tool_use: ToolUse) {
873 self.tool_use = tool_use;
874 }
875
876 #[must_use]
878 pub fn tool(&self) -> Option<&Arc<dyn Tool>> {
879 self.tool.as_ref()
880 }
881
882 #[must_use]
884 pub fn cancel(&self) -> &Cancel {
885 &self.cancel
886 }
887
888 pub fn set_cancel(&mut self, cancel: impl Into<Cancel>) {
891 self.cancel = cancel.into();
892 }
893
894 #[must_use]
896 pub fn selected_tool(&self) -> Option<&Arc<dyn Tool>> {
897 self.selected_tool.as_ref()
898 }
899
900 pub fn set_selected_tool(&mut self, tool: Arc<dyn Tool>) {
902 self.selected_tool = Some(tool);
903 }
904
905 pub fn interrupt(&mut self, params: impl Into<InterruptParams>) -> Result<JsonValue, InterruptError> {
917 let params = params.into();
918 let id = format!("hook:beforeToolCall:{}:{}", self.tool_use.tool_use_id, params.name);
919 let raised = self.base.agent.raise_interrupt(&id, ¶ms);
920 raised.inspect_err(|error| self.interrupts.extend(error.interrupts.iter().cloned()))
921 }
922
923 pub(crate) fn take_interrupts(&mut self) -> Vec<Interrupt> {
924 std::mem::take(&mut self.interrupts)
925 }
926
927 pub(crate) fn take_selected_tool(&mut self) -> Option<Arc<dyn Tool>> {
928 self.selected_tool.take()
929 }
930}
931
932#[non_exhaustive]
935pub struct AfterToolCallEvent {
936 base: PerTool,
937 tool_use: ToolUse,
938 tool: Option<Arc<dyn Tool>>,
939 result: ToolResultBlock,
940 error: Option<ToolResultError>,
941 retry: bool,
942}
943
944per_tool_accessors!(AfterToolCallEvent);
945
946impl AfterToolCallEvent {
947 pub(crate) fn new(
948 agent: ToolAgent,
949 invocation_state: InvocationState,
950 tool_use: ToolUse,
951 tool: Option<Arc<dyn Tool>>,
952 result: ToolResultBlock,
953 ) -> Self {
954 let error = result.error.clone();
955 Self {
956 base: PerTool::new(agent, invocation_state),
957 tool_use,
958 tool,
959 result,
960 error,
961 retry: false,
962 }
963 }
964
965 #[must_use]
967 pub fn tool_use(&self) -> &ToolUse {
968 &self.tool_use
969 }
970
971 #[must_use]
973 pub fn tool(&self) -> Option<&Arc<dyn Tool>> {
974 self.tool.as_ref()
975 }
976
977 #[must_use]
979 pub fn result(&self) -> &ToolResultBlock {
980 &self.result
981 }
982
983 pub fn result_mut(&mut self) -> &mut ToolResultBlock {
985 &mut self.result
986 }
987
988 pub fn set_result(&mut self, result: ToolResultBlock) {
990 self.result = result;
991 }
992
993 #[must_use]
995 pub fn error(&self) -> Option<&ToolResultError> {
996 self.error.as_ref()
997 }
998
999 #[must_use]
1001 pub fn retry(&self) -> bool {
1002 self.retry
1003 }
1004
1005 pub fn set_retry(&mut self, retry: bool) {
1007 self.retry = retry;
1008 }
1009
1010 pub(crate) fn into_result(self) -> ToolResultBlock {
1011 self.result
1012 }
1013}
1014
1015#[non_exhaustive]
1017pub struct ToolStreamUpdateEvent {
1018 base: PerTool,
1019 event: ToolStreamEvent,
1020}
1021
1022per_tool_accessors!(ToolStreamUpdateEvent);
1023
1024impl ToolStreamUpdateEvent {
1025 pub(crate) fn new(agent: ToolAgent, invocation_state: InvocationState, event: ToolStreamEvent) -> Self {
1026 Self {
1027 base: PerTool::new(agent, invocation_state),
1028 event,
1029 }
1030 }
1031
1032 #[must_use]
1034 pub fn event(&self) -> &ToolStreamEvent {
1035 &self.event
1036 }
1037}
1038
1039#[non_exhaustive]
1041pub struct ToolResultEvent {
1042 base: PerTool,
1043 result: ToolResultBlock,
1044}
1045
1046per_tool_accessors!(ToolResultEvent);
1047
1048impl ToolResultEvent {
1049 pub(crate) fn new(agent: ToolAgent, invocation_state: InvocationState, result: ToolResultBlock) -> Self {
1050 Self {
1051 base: PerTool::new(agent, invocation_state),
1052 result,
1053 }
1054 }
1055
1056 #[must_use]
1058 pub fn result(&self) -> &ToolResultBlock {
1059 &self.result
1060 }
1061}
1062
1063#[cfg(test)]
1064mod tests;