#!/usr/bin/env python3
"""
修复所有工具文件中的 ToolRuntime 参数问题
"""
import os
import re

tools_dir = "/workspace/projects/src/tools"

files_to_fix = [
    "tts_tool.py",
    "voice_tool.py", 
    "voice_session_tool.py",
    "phone_tool.py"
]

for filename in files_to_fix:
    filepath = os.path.join(tools_dir, filename)
    
    if not os.path.exists(filepath):
        print(f"文件不存在: {filepath}")
        continue
    
    with open(filepath, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 移除 ToolRuntime 导入
    content = re.sub(r', ToolRuntime', '', content)
    content = re.sub(r'from langchain\.tools import ToolRuntime\n', '', content)
    
    # 移除函数参数中的 runtime: ToolRuntime = None
    # 匹配模式：参数列表中可能出现在不同位置的 runtime 参数
    content = re.sub(r',\s*runtime:\s*ToolRuntime\s*=\s*None', '', content)
    content = re.sub(r'runtime:\s*ToolRuntime\s*=\s*None,\s*', '', content)
    
    with open(filepath, 'w', encoding='utf-8') as f:
        f.write(content)
    
    print(f"已修复: {filename}")

print("\n所有文件修复完成！")
