Files
content-ingestion-agent/app/main.py
Jonathan Boniface d8a4b6b3c1
Some checks failed
quality-gates / verify (push) Failing after 7s
fix: files manually
2026-09-01 17:21:58 +01:00

61 lines
1.6 KiB
Python

from __future__ import annotations
import os
from typing import Any
from .agent import create_agent_app
from .card import AGENT_CARD
from .routes import card_route, health_route, ingest_route
agent_context = create_agent_app()
def make_asgi_app() -> Any:
try:
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
asgi_app = FastAPI(title="content-ingestion-agent", version="1.0.0")
@asgi_app.get("/health")
def health() -> dict[str, str]:
return health_route()
@asgi_app.get("/card")
def card() -> Any:
return card_route(AGENT_CARD)
@asgi_app.post("/ingest")
async def ingest(request: Request) -> dict[str, Any]:
from kab_ingestion.models import IngestionRequest
data = await request.json()
req = IngestionRequest(
source=data.get("source", "github"),
locator=data.get("locator", ""),
requested_by=data.get("requested_by", "system"),
metadata=data.get("metadata", {}),
)
results = ingest_route(req, agent_context["service"])
return {"results": results, "status": "completed"}
return asgi_app
except ImportError:
return agent_context
app = make_asgi_app()
def main() -> None:
port = int(os.environ.get("PORT", "8080"))
try:
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=port)
except ImportError:
print(f"Starting {AGENT_CARD.name} v{AGENT_CARD.version}")
if __name__ == "__main__":
main()