runtara_workflow_stdlib/runtime/
context.rs

1// Copyright (C) 2025 SyncMyOrders Sp. z o.o.
2// SPDX-License-Identifier: AGPL-3.0-or-later
3//! Runtime context for workflow execution
4
5use serde_json::Value;
6use std::collections::HashMap;
7
8/// Runtime context providing workflow execution state
9#[derive(Debug, Default)]
10pub struct RuntimeContext {
11    /// Step execution results
12    pub steps_context: HashMap<String, Value>,
13    /// Workflow input
14    pub input: Value,
15    /// Connection data
16    pub connections: HashMap<String, Value>,
17}
18
19impl RuntimeContext {
20    /// Create a new runtime context
21    pub fn new() -> Self {
22        Self::default()
23    }
24
25    /// Create runtime context with input
26    pub fn with_input(input: Value) -> Self {
27        Self {
28            input,
29            ..Default::default()
30        }
31    }
32
33    /// Get a step result by step ID
34    pub fn get_step_result(&self, step_id: &str) -> Option<&Value> {
35        self.steps_context.get(step_id)
36    }
37
38    /// Set a step result
39    pub fn set_step_result(&mut self, step_id: String, value: Value) {
40        self.steps_context.insert(step_id, value);
41    }
42
43    /// Get the workflow input
44    pub fn get_input(&self) -> &Value {
45        &self.input
46    }
47}