This commit is contained in:
56
app/main.py
56
app/main.py
@@ -1,11 +1,59 @@
|
||||
from .agent import create_agent_app
|
||||
from __future__ import annotations
|
||||
|
||||
app = create_agent_app()
|
||||
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:
|
||||
"""Application entry point for ASGI hosts and local smoke checks."""
|
||||
print(app["card"].name)
|
||||
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__":
|
||||
|
||||
Reference in New Issue
Block a user