File size: 2,260 Bytes
5d48f4e
 
03b9c12
 
5d48f4e
 
 
 
03b9c12
5d48f4e
 
 
 
 
 
 
 
 
 
03b9c12
 
 
 
 
 
 
 
 
 
 
 
5d48f4e
 
 
 
 
03b9c12
 
 
 
 
 
5d48f4e
 
 
 
03b9c12
 
 
 
5d48f4e
 
 
03b9c12
 
 
 
 
5d48f4e
03b9c12
 
 
 
 
5d48f4e
 
 
 
 
03b9c12
 
 
 
5d48f4e
 
 
 
 
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
"""
OpenClaw sync script for HuggingClaw-Cain
Initializes the OpenClaw agent with proper configuration.
"""

import os
import sys
import json
import logging
from datetime import datetime

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)

def load_config():
    """Load OpenClaw configuration"""
    config_path = os.path.join(os.path.dirname(__file__), "..", "dataset", ".openclaw", "openclaw.json")
    
    try:
        with open(config_path, 'r') as f:
            config = json.load(f)
        return config
    except Exception as e:
        logger.error(f"Failed to load config: {str(e)}")
        return None

def main():
    """Main sync function"""
    try:
        logger.info("Starting Cain sync process...")
        
        # Load configuration
        config = load_config()
        if not config:
            logger.error("Failed to load configuration")
            return 1
            
        # Get configuration from environment
        model = os.getenv("MODEL", "openrouter/openai/gpt-oss-20b")
        port = os.getenv("PORT", "7860")
        
        # Update config with environment values
        config["model"] = model
        config["port"] = int(port)
        
        logger.info(f"Cain sync configured with model: {model}")
        logger.info(f"Running on port: {port}")
        
        # Initialize OpenClaw service
        from openclaw import OpenClaw
        
        # Create OpenClaw instance
        claw = OpenClaw(**config)
        
        # Start the service
        logger.info("Starting OpenClaw service...")
        claw.start()
        
        # Create a completion marker
        with open("/tmp/sync_complete", "w") as f:
            f.write(f"Sync completed at {datetime.now().isoformat()}")
            
        return 0
        
    except ImportError as e:
        logger.error(f"OpenClaw module not found: {str(e)}")
        logger.info("Please ensure OpenClaw is installed: pip install openclaw")
        return 1
    except Exception as e:
        logger.error(f"Error during sync: {str(e)}")
        return 1

if __name__ == "__main__":
    sys.exit(main())