38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""SubagentStop:guest sub agent 結束時解除它的 pin(下次啟動要重新 first-touch)。"""
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts"))
|
||
import persona_lib as pl # noqa: E402
|
||
|
||
|
||
def main() -> int:
|
||
try:
|
||
event = json.load(sys.stdin)
|
||
except json.JSONDecodeError:
|
||
return 0
|
||
session_id = event.get("session_id") or "unknown"
|
||
agent_id = event.get("agent_id")
|
||
agent_type = str(event.get("agent_type") or "")
|
||
if not agent_id or "persona-guest" not in agent_type:
|
||
return 0
|
||
data = pl.load_session(session_id)
|
||
pins = data.get("pins") or {}
|
||
slug = pins.pop(agent_id, None)
|
||
if slug is not None:
|
||
pl.save_session(session_id, data)
|
||
info = (data.get("guests") or {}).get(slug) or {}
|
||
if info.get("room"):
|
||
pl.add_guest_lease(slug, session_id, info["room"], data.get("host") or "")
|
||
print(json.dumps({"suppressOutput": True}, ensure_ascii=False))
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
raise SystemExit(main())
|