File size: 2,078 Bytes
732e77c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# /agenticcore/web_agentic.py
from fastapi import FastAPI, Query, Request
from fastapi.responses import HTMLResponse, JSONResponse, FileResponse, Response
from fastapi.staticfiles import StaticFiles  # <-- ADD THIS
from agenticcore.chatbot.services import ChatBot
import pathlib
import os

app = FastAPI(title="AgenticCore Web UI")

# 1) Simple HTML form at /
@app.get("/", response_class=HTMLResponse)
def index():
    return """
    <head>
      <link rel="icon" type="image/png" href="/static/favicon.png">
      <title>AgenticCore</title>
    </head>
    <form action="/agentic" method="get" style="padding:16px;">
        <input type="text" name="msg" placeholder="Type a message" style="width:300px">
        <input type="submit" value="Send">
    </form>
    """

# 2) Agentic endpoint
@app.get("/agentic")
def run_agentic(msg: str = Query(..., description="Message to send to ChatBot")):
    bot = ChatBot()
    return bot.reply(msg)

# --- Static + favicon setup ---

# TIP: we're inside <repo>/agenticcore/web_agentic.py
# repo root = parents[1]
repo_root = pathlib.Path(__file__).resolve().parents[1]

# Put static assets under app/assets/html
assets_path = repo_root / "app" / "assets" / "html"
assets_path_str = str(assets_path)

# Mount /static so /static/favicon.png works
app.mount("/static", StaticFiles(directory=assets_path_str), name="static")

# Serve /favicon.ico (browsers request this path)
@app.get("/favicon.ico", include_in_schema=False)
async def favicon():
    ico = assets_path / "favicon.ico"
    png = assets_path / "favicon.png"
    if ico.exists():
        return FileResponse(str(ico), media_type="image/x-icon")
    if png.exists():
        return FileResponse(str(png), media_type="image/png")
    # Graceful fallback if no icon present
    return Response(status_code=204)

@app.get("/health")
def health():
    return {"status": "ok"}

@app.post("/chatbot/message")
async def chatbot_message(request: Request):
    payload = await request.json()
    msg = str(payload.get("message", "")).strip() or "help"
    return ChatBot().reply(msg)