enact_core/context/
invocation.rs1use super::execution_context::RuntimeContext;
7use crate::kernel::{ExecutionId, StepId};
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
12pub struct InvocationServices {
13 pub memory: bool,
15 pub artifacts: bool,
17 pub tools: bool,
19}
20
21impl InvocationServices {
22 pub fn all() -> Self {
24 Self {
25 memory: true,
26 artifacts: true,
27 tools: true,
28 }
29 }
30
31 pub fn none() -> Self {
33 Self::default()
34 }
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct InvocationContext {
43 pub runtime: RuntimeContext,
45
46 pub input: serde_json::Value,
48
49 pub services: InvocationServices,
51}
52
53impl InvocationContext {
54 pub fn new(runtime: RuntimeContext, input: serde_json::Value) -> Self {
56 Self {
57 runtime,
58 input,
59 services: InvocationServices::default(),
60 }
61 }
62
63 pub fn with_all_services(mut self) -> Self {
65 self.services = InvocationServices::all();
66 self
67 }
68
69 pub fn with_services(mut self, services: InvocationServices) -> Self {
71 self.services = services;
72 self
73 }
74
75 pub fn execution_id(&self) -> &ExecutionId {
77 &self.runtime.execution_id
78 }
79
80 pub fn step_id(&self) -> Option<&StepId> {
82 self.runtime.step_id.as_ref()
83 }
84
85 pub fn runtime(&self) -> &RuntimeContext {
87 &self.runtime
88 }
89
90 pub fn input(&self) -> &serde_json::Value {
92 &self.input
93 }
94
95 pub fn input_str(&self) -> Option<&str> {
97 self.input.as_str()
98 }
99}