starweaver_context/
tool_runtime.rs1use std::collections::BTreeMap;
4
5use crate::{ModelConfig, ToolConfig};
6
7#[derive(Clone, Default, Eq, PartialEq)]
14pub struct ToolRuntimeSnapshot {
15 model_config: ModelConfig,
16 tool_config: ToolConfig,
17 shell_environment: BTreeMap<String, String>,
18}
19
20impl std::fmt::Debug for ToolRuntimeSnapshot {
21 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 formatter
23 .debug_struct("ToolRuntimeSnapshot")
24 .field("model_config", &self.model_config)
25 .field("tool_config", &self.tool_config)
26 .field(
27 "shell_environment_keys",
28 &self.shell_environment.keys().collect::<Vec<_>>(),
29 )
30 .finish()
31 }
32}
33
34impl ToolRuntimeSnapshot {
35 pub(crate) const fn new(
36 model_config: ModelConfig,
37 tool_config: ToolConfig,
38 shell_environment: BTreeMap<String, String>,
39 ) -> Self {
40 Self {
41 model_config,
42 tool_config,
43 shell_environment,
44 }
45 }
46
47 pub(crate) const fn filtered(model_config: ModelConfig, tool_config: ToolConfig) -> Self {
48 Self {
49 model_config,
50 tool_config,
51 shell_environment: BTreeMap::new(),
52 }
53 }
54
55 #[must_use]
57 pub const fn model_config(&self) -> &ModelConfig {
58 &self.model_config
59 }
60
61 #[must_use]
63 pub const fn tool_config(&self) -> &ToolConfig {
64 &self.tool_config
65 }
66
67 #[must_use]
69 pub const fn shell_environment(&self) -> &BTreeMap<String, String> {
70 &self.shell_environment
71 }
72}
73
74#[derive(Clone, Default, Eq, PartialEq)]
76pub struct ShellEnvironmentSnapshot {
77 environment: BTreeMap<String, String>,
78}
79
80impl ShellEnvironmentSnapshot {
81 pub(crate) const fn new(environment: BTreeMap<String, String>) -> Self {
82 Self { environment }
83 }
84
85 #[must_use]
87 pub const fn environment(&self) -> &BTreeMap<String, String> {
88 &self.environment
89 }
90}
91
92impl std::fmt::Debug for ShellEnvironmentSnapshot {
93 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
94 formatter
95 .debug_struct("ShellEnvironmentSnapshot")
96 .field(
97 "environment_keys",
98 &self.environment.keys().collect::<Vec<_>>(),
99 )
100 .finish()
101 }
102}
103
104#[cfg(test)]
105mod tests {
106 use std::collections::BTreeMap;
107
108 use super::ShellEnvironmentSnapshot;
109
110 #[test]
111 fn shell_environment_snapshot_debug_omits_values() {
112 let snapshot = ShellEnvironmentSnapshot::new(BTreeMap::from([(
113 "STARWEAVER_SECRET".to_string(),
114 "STARWEAVER_SECRET_SENTINEL_7f9c".to_string(),
115 )]));
116
117 let debug = format!("{snapshot:?}");
118 assert!(debug.contains("STARWEAVER_SECRET"));
119 assert!(!debug.contains("STARWEAVER_SECRET_SENTINEL_7f9c"));
120 }
121}