AI assistant widget #1

Open
opened 2026-06-03 16:46:59 +00:00 by iannuzzelli · 4 comments
iannuzzelli commented 2026-06-03 16:46:59 +00:00 (Migrated from gitlab.com)

Public website widget

Embed a chat widget in peacelink.it static pages. The widget is page-aware and can chat
about the article it is embedded in. The agent retains full access to RAG and MCP tools.

Page context strategy

The widget passes the current page URL to the API. The FastAPI layer checks if the article
is already indexed in pgvector (by matching cmetadata->>'source' or a URL field):

  • If found in RAG: the article's chunks are prioritised in retrieval — no extra injection needed
  • If not found: fall back to DOM extraction (document.querySelector('article').innerText)
    and inject the raw text as a system section ("L'utente sta leggendo: ...")
    This avoids duplicating content that is already embedded and chunked.

FastAPI layer (api/)

  • POST /auth/token — issue a short-lived JWT for public users (no OAuth2 Proxy)
  • POST /chat SSE endpoint — accepts { message, session_id, page_url, page_text? },
    streams agent tokens back as text/event-stream
  • Resolves page context (RAG lookup vs. injected text) before invoking the agent
  • Reuses existing LangGraph agent and MCP sessions; no intent management exposed
  • Langfuse tracing: tag traces with source=widget and page_url
  • Public users: chat only — no document upload, no intent/profile management
  • Sessions persisted in DB; rate-limited per session

JS widget (widget/)

  • Single <script> embed: <script src="https://.../widget.js" data-api="..."></script>
  • On load: fetches a JWT from /auth/token, renders floating chat button + panel
  • On each message: sends { message, session_id, page_url: location.href, page_text? }
    to /chat; page_text included only if DOM extraction is needed (decided server-side
    or via a flag returned at token time)
  • Streams response via EventSource
  • Vanilla JS, no framework dependency; branded with PeaceLink styles
  • UI: chat bubble (bottom-right), message thread, no sidebar or admin controls

Auth

  • JWT issued by /auth/token (public endpoint, rate-limited per session)
  • Separate from the internal OAuth2 Proxy — internal Streamlit app unchanged
  • Token scoped to role=public, enforced in the /chat handler
## Public website widget Embed a chat widget in peacelink.it static pages. The widget is page-aware and can chat about the article it is embedded in. The agent retains full access to RAG and MCP tools. ### Page context strategy The widget passes the current page URL to the API. The FastAPI layer checks if the article is already indexed in pgvector (by matching `cmetadata->>'source'` or a URL field): - **If found in RAG**: the article's chunks are prioritised in retrieval — no extra injection needed - **If not found**: fall back to DOM extraction (`document.querySelector('article').innerText`) and inject the raw text as a system section ("L'utente sta leggendo: ...") This avoids duplicating content that is already embedded and chunked. ### FastAPI layer (`api/`) - `POST /auth/token` — issue a short-lived JWT for public users (no OAuth2 Proxy) - `POST /chat` SSE endpoint — accepts `{ message, session_id, page_url, page_text? }`, streams agent tokens back as `text/event-stream` - Resolves page context (RAG lookup vs. injected text) before invoking the agent - Reuses existing LangGraph agent and MCP sessions; no intent management exposed - Langfuse tracing: tag traces with `source=widget` and `page_url` - Public users: chat only — no document upload, no intent/profile management - Sessions persisted in DB; rate-limited per session ### JS widget (`widget/`) - Single `<script>` embed: `<script src="https://.../widget.js" data-api="..."></script>` - On load: fetches a JWT from `/auth/token`, renders floating chat button + panel - On each message: sends `{ message, session_id, page_url: location.href, page_text? }` to `/chat`; `page_text` included only if DOM extraction is needed (decided server-side or via a flag returned at token time) - Streams response via `EventSource` - Vanilla JS, no framework dependency; branded with PeaceLink styles - UI: chat bubble (bottom-right), message thread, no sidebar or admin controls ### Auth - JWT issued by `/auth/token` (public endpoint, rate-limited per session) - Separate from the internal OAuth2 Proxy — internal Streamlit app unchanged - Token scoped to `role=public`, enforced in the `/chat` handler
iannuzzelli commented 2026-06-03 16:47:05 +00:00 (Migrated from gitlab.com)

assigned to @iannuzzelli

assigned to @iannuzzelli
iannuzzelli commented 2026-06-03 16:49:59 +00:00 (Migrated from gitlab.com)

changed the description

changed the description
iannuzzelli commented 2026-08-05 07:37:48 +00:00 (Migrated from gitlab.com)

mentioned in commit 6288bc0a64

mentioned in commit 6288bc0a64aef5d9a47ded50671c2820d8dcbbaa
iannuzzelli commented 2026-08-05 11:10:10 +00:00 (Migrated from gitlab.com)
PhPeace chat bridge: https://gitlab.com/peacelink/phpeace/-/commit/aa406fac6da620d632fd8d563475c644f97890e0 API: https://gitlab.com/peacelink/ai/assistant/-/commit/6288bc0a64aef5d9a47ded50671c2820d8dcbbaa UI: https://gitlab.com/peacelink/ui/-/commit/afc65ad2564958547a7e4b2b57e455f4c1a7fed4 and https://gitlab.com/peacelink/ui/-/commit/b5f3e5471d4a42564e76e9de68f84817262283bc Infra: https://gitlab.com/peacelink/pck3s/-/commit/35503d4a05ed4c4d63eb1949726309739b3ffe09
francesco added this to the (deleted) project 2026-08-05 15:10:18 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
peacelink/ai-assistant#1
No description provided.