clawemail / scripts /deploy_agent.py
Echocq's picture
feat: alias/global mail forwarding (CC-style, source-tagged)
ec6eb9a verified
Raw
History Blame Contribute Delete
2.26 kB
#!/usr/bin/env python3
"""Deploy the 参考clawemail mail-agent as its own HF Docker Space.
Reads all credentials from the local .env (gitignored). Creates the space,
injects secrets (CLAW account + the agent api key), uploads the agent folder
(HF builds the image), and restarts it.
python scripts/deploy_agent.py
"""
import os
import sys
REPO_ID = "Echocq/clawemail-agent"
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
AGENT_DIR = os.path.join(ROOT, "参考clawemail")
CLAW_EMAIL = "echocq@claw.163.com"
IGNORE = ["node_modules/*", ".state-test*", ".git/*", "*.log"]
def env(name):
path = os.path.join(ROOT, ".env")
for line in open(path, encoding="utf-8"):
line = line.strip()
if line.startswith(f"{name}=") and "=" in line:
return line.split("=", 1)[1].strip().strip('"').strip("'")
return None
def main() -> int:
token = env("HF_TOKEN")
claw_key = env("CLAW_API_KEY")
agent_key = env("CLAWEMAIL_API_KEY")
if not (token and claw_key and agent_key):
print("missing HF_TOKEN / CLAW_API_KEY / CLAWEMAIL_API_KEY in .env", file=sys.stderr)
return 2
from huggingface_hub import HfApi
api = HfApi(token=token)
print(f"auth: {api.whoami().get('name')}")
api.create_repo(repo_id=REPO_ID, repo_type="space", space_sdk="docker",
exist_ok=True, private=False)
print(f"space ready: {REPO_ID}")
api.add_space_secret(repo_id=REPO_ID, key="CLAW_EMAIL", value=CLAW_EMAIL)
api.add_space_secret(repo_id=REPO_ID, key="CLAW_API_KEY", value=claw_key)
api.add_space_secret(repo_id=REPO_ID, key="CLAWEMAIL_API_KEY", value=agent_key)
print("secrets set: CLAW_EMAIL, CLAW_API_KEY, CLAWEMAIL_API_KEY")
commit = api.upload_folder(repo_id=REPO_ID, repo_type="space",
folder_path=AGENT_DIR, ignore_patterns=IGNORE,
commit_message="deploy clawemail mail-agent (api-key gated remote service)")
print(f"uploaded: {getattr(commit, 'oid', commit)}")
api.restart_space(repo_id=REPO_ID)
print("restart -> BUILDING")
print(f"address: https://echocq-clawemail-agent.hf.space")
return 0
if __name__ == "__main__":
raise SystemExit(main())