import json
import sys
def send(obj):
sys.stdout.write(json.dumps(obj) + "\n")
sys.stdout.flush()
for line in sys.stdin:
line = line.strip()
if not line:
continue
msg = json.loads(line)
method = msg.get("method")
ident = msg.get("id")
if method == "initialize":
send({"jsonrpc": "2.0", "id": ident, "result": {
"protocolVersion": 1,
"agentCapabilities": {"loadSession": True, "mcpCapabilities": {"http": True}},
"authMethods": [],
"agentInfo": {"name": "aion-stub-agent", "version": "0.0.0"}}})
elif method == "session/new":
send({"jsonrpc": "2.0", "id": ident, "result": {"sessionId": "stub-session"}})
elif method == "session/load":
wanted = (msg.get("params") or {}).get("sessionId")
send({"jsonrpc": "2.0", "id": ident, "error": {
"code": -32602,
"message": "session/load: no conversation named %r lives in this agent" % (wanted,)}})
elif method == "session/prompt":
sid = msg["params"]["sessionId"]
send({"jsonrpc": "2.0", "method": "session/update", "params": {"sessionId": sid, "update": {
"sessionUpdate": "agent_message_chunk", "messageId": "stub-1",
"content": {"type": "text", "text": "stub answer"}}}})
send({"jsonrpc": "2.0", "id": ident, "result": {"stopReason": "end_turn"}})
elif ident is not None:
send({"jsonrpc": "2.0", "id": ident, "error": {
"code": -32601, "message": "method not found: %s" % (method,)}})
sys.stderr.write("aion-stub-agent: stdin closed, exiting\n")
sys.stderr.flush()