File size: 1,748 Bytes
3d325be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
"""
Sync utility for OpenClaw HF Deployment
Handles agent-channel synchronization and state management
"""

import os
import json
from pathlib import Path


def sync_agent_bindings():
    """同步Agent与通道绑定关系"""
    state_dir = os.environ.get("OPENCLAW_STATE_DIR", "/root/.openclaw")
    
    # 读取配置
    config_path = f"{state_dir}/openclaw.json"
    bindings_path = f"{state_dir}/agent_bindings.json"
    
    if not os.path.exists(config_path):
        print("[Sync] Config not found, skipping")
        return
    
    with open(config_path, 'r') as f:
        config = json.load(f)
    
    # 读取绑定关系
    if os.path.exists(bindings_path):
        with open(bindings_path, 'r') as f:
            bindings = json.load(f)
        
        # 更新agents的channels
        agents = config.get("agents", [])
        for agent in agents:
            agent_id = agent.get("id")
            agent["channels"] = []
            
            for binding in bindings:
                if binding.get("agent_id") == agent_id:
                    agent["channels"].append({
                        "id": binding.get("channel_id"),
                        "type": binding.get("channel_type"),
                        "status": binding.get("status")
                    })
        
        # 保存更新后的配置
        with open(config_path, 'w') as f:
            json.dump(config, f, indent=2)
        
        print(f"[Sync] Updated {len(agents)} agents with channel bindings")
    else:
        print("[Sync] No bindings file found")


def main():
    print("[Sync] Starting synchronization...")
    sync_agent_bindings()
    print("[Sync] Completed!")


if __name__ == "__main__":
    main()