swarm_engine_core/orchestrator/
adapter.rs1use crate::exploration::mutation::ExplorationResult;
4use crate::exploration::{MapNodeId, MutationInput};
5
6pub struct WorkResultAdapter {
11 pub node_id: MapNodeId,
13 pub action_name: String,
15 pub target: Option<String>,
17 pub result: ExplorationResult,
19}
20
21impl WorkResultAdapter {
22 pub fn new(
24 node_id: MapNodeId,
25 action_name: &str,
26 target: Option<&str>,
27 success: bool,
28 discovery: Option<&serde_json::Value>,
29 ) -> Self {
30 let result = if success {
31 if let Some(disc) = discovery {
33 if let Some(arr) = disc.as_array() {
35 let children: Vec<String> = arr
36 .iter()
37 .filter_map(|v| v.as_str().map(|s| s.to_string()))
38 .collect();
39 if !children.is_empty() {
40 ExplorationResult::Discover(children)
41 } else {
42 ExplorationResult::Success
43 }
44 } else {
45 ExplorationResult::Success
46 }
47 } else {
48 ExplorationResult::Success
49 }
50 } else {
51 ExplorationResult::Fail(None)
52 };
53
54 Self {
55 node_id,
56 action_name: action_name.to_string(),
57 target: target.map(|s| s.to_string()),
58 result,
59 }
60 }
61}
62
63impl MutationInput for WorkResultAdapter {
64 fn node_id(&self) -> MapNodeId {
65 self.node_id
66 }
67
68 fn action_name(&self) -> &str {
69 &self.action_name
70 }
71
72 fn target(&self) -> Option<&str> {
73 self.target.as_deref()
74 }
75
76 fn result(&self) -> &ExplorationResult {
77 &self.result
78 }
79}