mirror of
https://github.com/browser-use/web-ui.git
synced 2026-03-22 11:17:17 +08:00
feat: added supportfor sensitive variables
This commit is contained in:
@@ -91,6 +91,20 @@ class CustomAgent(Agent):
|
||||
planner_llm: Optional[BaseChatModel] = None,
|
||||
planner_interval: int = 1, # Run planner every N steps
|
||||
):
|
||||
|
||||
# Load sensitive data from environment variables
|
||||
env_sensitive_data = {}
|
||||
for key, value in os.environ.items():
|
||||
if key.startswith('SENSITIVE_'):
|
||||
env_key = key.replace('SENSITIVE_', '', 1).lower()
|
||||
env_sensitive_data[env_key] = value
|
||||
|
||||
# Merge environment variables with provided sensitive_data
|
||||
if sensitive_data is None:
|
||||
sensitive_data = {}
|
||||
sensitive_data = {**env_sensitive_data, **sensitive_data} # Provided data takes precedence
|
||||
|
||||
|
||||
super().__init__(
|
||||
task=task,
|
||||
llm=llm,
|
||||
|
||||
26
webui.py
26
webui.py
@@ -44,6 +44,30 @@ _global_agent = None
|
||||
# Create the global agent state instance
|
||||
_global_agent_state = AgentState()
|
||||
|
||||
def resolve_sensitive_env_variables(text):
|
||||
"""
|
||||
Replace environment variable placeholders ($SENSITIVE_*) with their values.
|
||||
Only replaces variables that start with SENSITIVE_.
|
||||
"""
|
||||
if not text:
|
||||
return text
|
||||
|
||||
import re
|
||||
|
||||
# Find all $SENSITIVE_* patterns
|
||||
env_vars = re.findall(r'\$SENSITIVE_[A-Za-z0-9_]*', text)
|
||||
|
||||
result = text
|
||||
for var in env_vars:
|
||||
# Remove the $ prefix to get the actual environment variable name
|
||||
env_name = var[1:] # removes the $
|
||||
env_value = os.getenv(env_name)
|
||||
if env_value is not None:
|
||||
# Replace $SENSITIVE_VAR_NAME with its value
|
||||
result = result.replace(var, env_value)
|
||||
|
||||
return result
|
||||
|
||||
async def stop_agent():
|
||||
"""Request the agent to stop and update UI with enhanced feedback"""
|
||||
global _global_agent_state, _global_browser_context, _global_browser, _global_agent
|
||||
@@ -141,6 +165,8 @@ async def run_browser_agent(
|
||||
+ glob.glob(os.path.join(save_recording_path, "*.[wW][eE][bB][mM]"))
|
||||
)
|
||||
|
||||
task = resolve_sensitive_env_variables(task)
|
||||
|
||||
# Run the agent
|
||||
llm = utils.get_llm_model(
|
||||
provider=llm_provider,
|
||||
|
||||
Reference in New Issue
Block a user