oclaw/runtime/operations/scripts/set_wecom_auto_bind.py
oliver d14e9d3596 feat(persistence): PostgreSQL assistant store, chat persist fixes, gateway scripts
- Add SQLAlchemy Core repos, pg adapter/compat, assistant_store factory, Alembic bootstrap and migration/cutover scripts.

- Harden chat_message writes (NUL scrub for PG), turn_uuid on attempt failure, WS turn_runner fallbacks and gateway executed_turn_uuid init.

- start_gateway: log paths, PS7 stderr handling via cmd, background stdout/stderr redirect; runtime assistant_runtime_log_dir export.

- Ops: clear_all_chat_sessions with PG-only --postgresql and env-gated wipe; clear_postgres_chat_sessions.ps1.

- Tests: SA repos, pg compat, persist fallback, smoke env isolation; CI and docs touch-ups.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-14 09:33:50 +08:00

56 lines
1.8 KiB
Python

from __future__ import annotations
import sys
from svc.config.paths import db_path
from svc.persistence.sqlite_store import SqliteStore
from svc.persistence.assistant_store import get_assistant_store
def _to_bool(v: str) -> str:
return "1" if str(v).strip().lower() in ("1", "true", "yes", "on") else "0"
def main() -> int:
args = [str(x).strip() for x in sys.argv[1:]]
if not args:
print("usage:")
print(" python -m scripts.set_wecom_auto_bind on|off")
print(" python -m scripts.set_wecom_auto_bind on <tenant_name> <role>")
print(" python -m scripts.set_wecom_auto_bind show")
return 2
cmd = args[0].lower()
store = get_assistant_store()
if cmd == "show":
enabled = str(store.get_setting("wecom_auto_bind_enabled") or "1").strip()
tenant_name = str(store.get_setting("wecom_auto_bind_tenant_name") or "Team").strip() or "Team"
role = str(store.get_setting("wecom_auto_bind_role") or "member").strip() or "member"
print("ok=1")
print(f"enabled={enabled}")
print(f"tenant_name={tenant_name}")
print(f"role={role}")
return 0
if cmd not in ("on", "off"):
print("error=invalid_command")
return 2
enabled = _to_bool("1" if cmd == "on" else "0")
tenant_name = (args[1] if len(args) >= 2 else "Team").strip() or "Team"
role = (args[2] if len(args) >= 3 else "member").strip() or "member"
store.set_setting("wecom_auto_bind_enabled", enabled)
store.set_setting("wecom_auto_bind_tenant_name", tenant_name)
store.set_setting("wecom_auto_bind_role", role)
print("ok=1")
print(f"enabled={enabled}")
print(f"tenant_name={tenant_name}")
print(f"role={role}")
return 0
if __name__ == "__main__":
raise SystemExit(main())