From 66c4b8822316c703a67f7a38934a87c1d903ba0c Mon Sep 17 00:00:00 2001
From: TevinClaw <510129976@qq.com>
Date: Sat, 14 Mar 2026 12:38:28 +0800
Subject: [PATCH] refactor(tavily-search): 改为仅从环境变量读取API key

---
 workspace/skills/tavily-search/SKILL.md                 |   17 ++++++++++-------
 workspace/skills/tavily-search/scripts/tavily_search.py |   38 ++++++--------------------------------
 2 files changed, 16 insertions(+), 39 deletions(-)

diff --git a/workspace/skills/tavily-search/SKILL.md b/workspace/skills/tavily-search/SKILL.md
index b4ac09f..596e5b3 100644
--- a/workspace/skills/tavily-search/SKILL.md
+++ b/workspace/skills/tavily-search/SKILL.md
@@ -10,13 +10,16 @@
 ## Prerequisites
 
 1. Get a Tavily API key from https://tavily.com
-2. Configure the key using one of these methods:
-   - **.env file (推荐)**: 在 `~/.openclaw/.env` 文件中配置:
-     ```json
-     {"env": {"TAVILY_API_KEY": "your_key_here"}}
-     ```
-   - **Environment variable**: `export TAVILY_API_KEY=your_key_here`
-   - **Direct parameter**: Pass `api_key` when calling the function
+2. Configure the key via **environment variable**:
+   ```bash
+   export TAVILY_API_KEY=your_key_here
+   ```
+   Add to `~/.bashrc` or `~/.zshrc` for persistence:
+   ```bash
+   echo 'export TAVILY_API_KEY=your_key_here' >> ~/.bashrc
+   source ~/.bashrc
+   ```
+3. Or pass `api_key` as a direct parameter when calling the function
 
 ## Usage
 
diff --git a/workspace/skills/tavily-search/scripts/tavily_search.py b/workspace/skills/tavily-search/scripts/tavily_search.py
index fc78222..fe5b65b 100755
--- a/workspace/skills/tavily-search/scripts/tavily_search.py
+++ b/workspace/skills/tavily-search/scripts/tavily_search.py
@@ -8,34 +8,12 @@
 import sys
 import json
 import argparse
-from pathlib import Path
 from typing import List, Dict, Any, Optional
 
 
-def get_tavily_key_from_env_file() -> Optional[str]:
-    """Read Tavily API key from ~/.openclaw/.env file.
-    
-    Expected format: {"env": {"TAVILY_API_KEY": "your_key"}}
-    """
-    env_file = Path.home() / ".openclaw" / ".env"
-    if not env_file.exists():
-        return None
-    
-    try:
-        with open(env_file, 'r', encoding='utf-8') as f:
-            env_data = json.load(f)
-        # Support nested structure: {"env": {"TAVILY_API_KEY": "..."}}
-        if "env" in env_data:
-            return env_data["env"].get("TAVILY_API_KEY")
-        # Fallback to flat structure: {"TAVILY_API_KEY": "..."}
-        return env_data.get("TAVILY_API_KEY")
-    except (json.JSONDecodeError, IOError):
-        return None
-
-
 def get_api_key(api_key: Optional[str] = None) -> str:
-    """Get Tavily API key from various sources."""
-    # Priority: parameter > env var > .env file
+    """Get Tavily API key from environment variable or parameter."""
+    # Priority: parameter > environment variable
     if api_key:
         return api_key
     
@@ -43,15 +21,11 @@
     if env_key:
         return env_key
     
-    env_file_key = get_tavily_key_from_env_file()
-    if env_file_key:
-        return env_file_key
-    
     raise ValueError(
-        "Tavily API key required. Set via one of:\n"
-        "  1. TAVILY_API_KEY environment variable\n"
-        "  2. ~/.openclaw/.env file (JSON format: {\"env\": {\"TAVILY_API_KEY\": \"...\"}})\n"
-        "  3. Pass as api_key parameter\n"
+        "Tavily API key required. Set via:\n"
+        "  1. Environment variable: export TAVILY_API_KEY=your_key\n"
+        "     (Add to ~/.bashrc or ~/.zshrc for persistence)\n"
+        "  2. Direct parameter: pass api_key when calling the function\n"
         "\nGet your API key at: https://tavily.com"
     )
 

--
Gitblit v1.9.1