new service configuration
This commit is contained in:
parent
b6c026e8d0
commit
38edfcee40
1
agent/characters/kongming/.gitignore
vendored
Normal file
1
agent/characters/kongming/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
service.yaml
|
||||
21
agent/characters/kongming/service.default.yaml
Normal file
21
agent/characters/kongming/service.default.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
# This file serves as a template for character-specific service overrides.
|
||||
# Copy this to agent/characters/<character>/service.yaml and fill in the credentials.
|
||||
|
||||
xmpp:
|
||||
enabled: false
|
||||
username: ""
|
||||
password: ""
|
||||
muc_rooms: # YAML list, e.g.:
|
||||
# - "room1@conference.server"
|
||||
# - "room2@conference.server"
|
||||
nickname: "" # custom MUC nickname (empty = use username)
|
||||
selective_response: true # true = only response if mentioned/relevant
|
||||
debug: false # true = tampilkan log debug menyeluruh (semua stanza XML, lifecycle, dll)
|
||||
|
||||
telegram:
|
||||
enabled: false
|
||||
token: ""
|
||||
allowed_group_ids: # YAML list, empty = all group. e.g.:
|
||||
# - "123456789"
|
||||
# - "987654321"
|
||||
selective_response: true # true = only response if mentioned/relevant
|
||||
91
config.py
91
config.py
@ -149,5 +149,94 @@ def load_character(char_override=None):
|
||||
AGENT_SKILLS = char_skills
|
||||
|
||||
|
||||
# Load character dari config.yaml saat import time
|
||||
SERVICE_YAML_PATH = None # Path service.yaml milik karakter aktif, jika ada
|
||||
|
||||
|
||||
def _reset_service_from_config():
|
||||
"""Reset konfigurasi service (xmpp/telegram) dari config.yaml global."""
|
||||
global XMPP_ENABLED, XMPP_USERNAME, XMPP_PASSWORD, XMPP_MUC_ROOMS
|
||||
global XMPP_NICKNAME, XMPP_DEBUG, XMPP_SELECTIVE_RESPONSE
|
||||
global TELEGRAM_ENABLED, TELEGRAM_TOKEN, TELEGRAM_ALLOWED_GROUP_IDS
|
||||
global TELEGRAM_SELECTIVE_RESPONSE, SERVICE_YAML_PATH
|
||||
|
||||
XMPP_USERNAME = _yaml_get("xmpp", "username", default="")
|
||||
XMPP_PASSWORD = _yaml_get("xmpp", "password", default="")
|
||||
XMPP_ENABLED = str(_yaml_get("xmpp", "enabled", default="false")).strip().lower() in ("true", "1", "yes")
|
||||
XMPP_MUC_ROOMS = _as_list(_yaml_get("xmpp", "muc_rooms", default=[]))
|
||||
XMPP_NICKNAME = _yaml_get("xmpp", "nickname", default="").strip()
|
||||
XMPP_DEBUG = str(_yaml_get("xmpp", "debug", default="false")).strip().lower() in ("true", "1", "yes")
|
||||
XMPP_SELECTIVE_RESPONSE = str(_yaml_get("xmpp", "selective_response", default="true")).strip().lower() in ("true", "1", "yes")
|
||||
|
||||
TELEGRAM_ENABLED = str(_yaml_get("telegram", "enabled", default="false")).strip().lower() in ("true", "1", "yes")
|
||||
TELEGRAM_TOKEN = _yaml_get("telegram", "token", default="")
|
||||
TELEGRAM_ALLOWED_GROUP_IDS = _as_list(_yaml_get("telegram", "allowed_group_ids", default=[]))
|
||||
TELEGRAM_SELECTIVE_RESPONSE = str(_yaml_get("telegram", "selective_response", default="true")).strip().lower() in ("true", "1", "yes")
|
||||
|
||||
SERVICE_YAML_PATH = None
|
||||
|
||||
|
||||
def load_service_config(char_override=None):
|
||||
"""Override konfigurasi service (xmpp/telegram) dari service.yaml milik
|
||||
karakter aktif, jika file tersebut ada di agent/characters/<char>/.
|
||||
Memanggil load_character() bila char_override diberikan."""
|
||||
global XMPP_ENABLED, XMPP_USERNAME, XMPP_PASSWORD, XMPP_MUC_ROOMS
|
||||
global XMPP_NICKNAME, XMPP_DEBUG, XMPP_SELECTIVE_RESPONSE
|
||||
global TELEGRAM_ENABLED, TELEGRAM_TOKEN, TELEGRAM_ALLOWED_GROUP_IDS
|
||||
global TELEGRAM_SELECTIVE_RESPONSE, SERVICE_YAML_PATH
|
||||
|
||||
_reset_service_from_config()
|
||||
|
||||
if char_override:
|
||||
load_character(char_override=char_override)
|
||||
|
||||
if not AGENT_CHARACTER:
|
||||
return
|
||||
|
||||
service_yaml_path = CHARACTERS_DIR / AGENT_CHARACTER / "service.yaml"
|
||||
|
||||
if not service_yaml_path.is_file():
|
||||
return
|
||||
|
||||
try:
|
||||
data = yaml.safe_load(service_yaml_path.read_text(encoding="utf-8")) or {}
|
||||
if not isinstance(data, dict):
|
||||
data = {}
|
||||
except Exception as _e:
|
||||
print(f"[config] Warning: gagal load service.yaml untuk '{AGENT_CHARACTER}': {_e}", flush=True)
|
||||
data = {}
|
||||
|
||||
if not data:
|
||||
return
|
||||
|
||||
SERVICE_YAML_PATH = service_yaml_path
|
||||
|
||||
xmpp_data = data.get("xmpp") or {}
|
||||
if "enabled" in xmpp_data:
|
||||
XMPP_ENABLED = str(xmpp_data["enabled"]).strip().lower() in ("true", "1", "yes")
|
||||
if "username" in xmpp_data:
|
||||
XMPP_USERNAME = str(xmpp_data["username"]).strip()
|
||||
if "password" in xmpp_data:
|
||||
XMPP_PASSWORD = str(xmpp_data["password"]).strip()
|
||||
if "muc_rooms" in xmpp_data:
|
||||
XMPP_MUC_ROOMS = _as_list(xmpp_data["muc_rooms"])
|
||||
if "nickname" in xmpp_data:
|
||||
XMPP_NICKNAME = str(xmpp_data["nickname"]).strip()
|
||||
if "debug" in xmpp_data:
|
||||
XMPP_DEBUG = str(xmpp_data["debug"]).strip().lower() in ("true", "1", "yes")
|
||||
if "selective_response" in xmpp_data:
|
||||
XMPP_SELECTIVE_RESPONSE = str(xmpp_data["selective_response"]).strip().lower() in ("true", "1", "yes")
|
||||
|
||||
telegram_data = data.get("telegram") or {}
|
||||
if "enabled" in telegram_data:
|
||||
TELEGRAM_ENABLED = str(telegram_data["enabled"]).strip().lower() in ("true", "1", "yes")
|
||||
if "token" in telegram_data:
|
||||
TELEGRAM_TOKEN = str(telegram_data["token"]).strip()
|
||||
if "allowed_group_ids" in telegram_data:
|
||||
TELEGRAM_ALLOWED_GROUP_IDS = _as_list(telegram_data["allowed_group_ids"])
|
||||
if "selective_response" in telegram_data:
|
||||
TELEGRAM_SELECTIVE_RESPONSE = str(telegram_data["selective_response"]).strip().lower() in ("true", "1", "yes")
|
||||
|
||||
|
||||
# Load character & service dari config.yaml saat import time
|
||||
load_character()
|
||||
load_service_config()
|
||||
|
||||
@ -79,7 +79,7 @@ def main():
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.char:
|
||||
config.load_character(char_override=args.char)
|
||||
config.load_service_config(char_override=args.char)
|
||||
|
||||
if args.workspace:
|
||||
resolved = os.path.abspath(args.workspace)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user