Files
agent-call/agent_call/main.py
T

46 lines
1.2 KiB
Python

from __future__ import annotations
import os
from pathlib import Path
from .core import AgentCallService, ConfigurationError, _integer
from .http import make_server
def build_service() -> AgentCallService:
profile = Path(
os.environ.get("AGENT_CALL_PROFILE", "docs/contracts/mock-profile.json")
)
db_path = os.environ.get("AGENT_CALL_DB", "data/agent-call.sqlite3")
object_dir = os.environ.get("AGENT_CALL_OBJECT_DIR")
provider_mode = os.environ.get("AGENT_CALL_MODE")
return AgentCallService(
db_path=db_path,
profile_path=profile,
object_dir=object_dir,
mode=provider_mode,
start_background=True,
)
def main() -> None:
service = build_service()
host = os.environ.get("AGENT_CALL_HOST", "127.0.0.1")
port = _integer(os.environ.get("AGENT_CALL_PORT", "8080"))
server = make_server(service, host, port)
try:
server.serve_forever()
except KeyboardInterrupt:
return
finally:
server.shutdown()
server.server_close()
service.stop()
if __name__ == "__main__":
try:
main()
except ConfigurationError as exc:
raise SystemExit(f"configuration error: {exc.detail}") from exc