feat(context): optional current-page awareness for embedded webchat
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 5/100
Hướng nghiên cứu
Start with docs/http-contract.md and the request path in packages/dewee-webchat/src/widget/element.ts, src/widget/api-client.ts, src/server/handler.ts and src/server/gateway-client.ts to see how a chat turn is sent today. The issue is a multi-part design spanning the widget, both server implementations and the Gateway, so a newcomer should first ask a maintainer to split it into a smaller, agreed first step. Done means that step is agreed and its scope is written down in the issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Mục tiêu
Khi khách truy cập mở <dewee-chat> trên website đã bật tính năng, Dewee agent có thể hiểu nội dung trang hiện tại (bài viết, tài liệu, trang sản phẩm, mục hỗ trợ...) và trả lời câu hỏi như "trang này nói gì?" mà khách không phải dán URL hoặc copy nội dung.
Khác Chrome Extension: widget là script nhúng trên website, không có quyền đọc các tab/browser khác và không cần activeTab hay host permissions. Quyền truy cập context do site owner cấu hình + visitor kiểm soát; mặc định không tự động gửi nội dung trang tới backend/LLM.
Hiện trạng được kiểm tra (main @ 6f0083da8387)
packages/dewee-webchat/src/widget/element.tslà web component dùng Shadow DOM,DeweeChatConfigchưa có page-context setting;send(text)chỉ gọi API vớimessage/agent/conversationId.src/widget/api-client.tschỉ gửi các trường chat đó đếnPOST /api/dewee/chat;src/server/handler.tsforwardmessageđếnstreamChat;src/server/gateway-client.tsgọi Gateway WSchat.sendvớimessage/agentId/sessionKey/stream. Chưa có per-turn context attachment.docs/http-contract.mdlà hợp đồng dùng chung cho Node/Workers vàphp/dewee-webchat.php; phải cập nhật parity của cả hai server implementation + các framework wrappers/CDN/build docs. Không nhúng raw page vào user message bằng string concatenation.- Server giữ gateway token; visitor dùng signed session, origin allowlist và rate limits. Bảo toàn những biên an toàn này.
Thiết kế đề xuất
1. Host-controlled configuration + visitor UI
pageContext?: 'off' | 'metadata' | 'content', default 'off' để tránh vô tình chia sẻ dữ liệu của visitor khi upgrade SDK; site owner chủ động enable. Khicontentđược bật, widget chuẩn bị local ephemeral snapshot lúc mở, hiển thịCurrent page: title • preview • remove/disable; chỉ chuyển nội dung lên backend khi người dùng gửi tin nhắn và chọn chia sẻ ngữ cảnh theo chính sách consent rõ ràng.- Metadata mode gồm title/sanitized URL/description; content mode ưu tiên visible main content + selected text; nên hỗ trợ
contextSelector/excludeSelectors/contextProvider?: () => Promise<PageContext>tùy biến do site owner cung cấp. Không cho widget ăn toàn bộdocument.body.innerTextmột cách mù quáng. - SDK APIs/web component attributes hợp lý (đảm bảo SSR-safe):
page-context="content",configure({pageContext:'content'}); React/Vue/Astro wrappers truyền config; sự kiện privacy-awaredewee:context-ready,dewee:context-errorkhông chứa page text trong telemetry. - Không tự gọi LLM, không tự gửi nội dung trang khi widget chỉ load, không persist raw context vào localStorage/sessionStorage/history. Chat/persist session hiện tại giữ nguyên.
2. Shared versioned context envelope
Đồng bộ schema logic với issue Page Context trong nextlevelbuilder/dewee-chrome-ext:
{
"page_context": {
"version": 1,
"source": "embedded_webchat",
"url": "https://example.com/docs/article",
"title": "Article",
"captured_at": "2026-10-15T00:00:00Z",
"content": { "format": "markdown", "text": "# Article\n...", "truncated": false },
"trust_level": "untrusted_external"
}
}
- Client sanitize URL (strip credentials, fragments and secret-looking query keys); bound document size and use modest token budget (initial target 2k–4k, tune after eval).
- Server validates schema, enforces max size/length + visitor rate limits; assigns canonical source/trust server-side, not trusted from payload. Content is untrusted webpage text and must never become high-privilege instruction.
- Propagate attachment
widget → POST /api/dewee/chat → server handler (Workers/Node + PHP parity) → Dewee Gateway chat.send/agent looponly after backend support exists; do not silently fall back to interpolating raw context into user-authored message if feature not supported. - Per-turn context not injected into durable system prompt, public logs, traces, saved chat history, memory; preserve ownership and visitor isolation. Document backend dependency in
nextlevelbuilder/dewee.
3. Extraction, performance and security
- Extract only readable/visible content, headings, lists, code and tables with Readability-like filter; site-owner selectors override safely; never read form values, passwords, OTPs, payment fields, editable drafts, script/style/hidden DOM, cross-origin frames.
- Context keyed to current navigation/location/content hash; SPA route changes and updates invalidate snapshot; discard stale async results. No periodic background scraping; collect on open/explicit refresh + refresh on Send when stale.
- Host page can be malicious or contain prompt injection, so treat page as data only, not instructions. No origin bypass, token exfiltration or tool permission escalation.
- Inline use on site owner page, avoid cross-frame access; for iframe embedding, only expose explicitly approved context via a secure, exact-origin
postMessagehandshake if required later. Do not implement wildcard messaging or trust arbitraryevent.data. - No breaking change to existing
<dewee-chat>embeds. If disabled or context fails, normal chat still works. Keep browser bundle light and lazy-load extractor.
Implementation hotspots
packages/dewee-webchat/src/widget/element.ts(config + lifecycle + chip UI)packages/dewee-webchat/src/widget/api-client.tspackages/dewee-webchat/src/protocol.ts(shared type)packages/dewee-webchat/src/widget/page-context.ts(new extractor)packages/dewee-webchat/src/server/handler.ts&src/server/gateway-client.tsphp/dewee-webchat.php,docs/http-contract.md,packages/dewee-webchat/README.md- Examples and framework wrappers + tests.
Acceptance criteria
- Host enabling page-context allows question about actual current page without copying text; default existing embeds remain private and unchanged.
- Context status/chip preview/removal and visitor control work; no send until explicit chat submission + consent rule.
- Metadata/content/excluded selectors/custom provider behave consistently across HTML/React/Vue/Astro.
- Navigation/SPAs update context, no stale snapshot or cross-page bleed, selected text can be prioritized.
- No secrets, hidden data, form values, credentials, cookies, localStorage or cross-origin iframe content are captured.
- Node/Workers/PHP handlers all validate and propagate typed schema identically; Gateway receives untrusted per-turn context, not fake user/system instructions.
- Oversized/malformed content fails safely without breaking normal chat, no unbounded token costs, no page content persisted/logged.
- Unit/integration tests cover privacy, custom selectors, XSS/prompt injection, SPA, SSR import, parallel chats, history, visitor isolation, backend incompatibility and request limits.
Related
- Companion feature:
nextlevelbuilder/dewee-chrome-extPage Context Provider (link issue once published). - Backend contract/dependency:
nextlevelbuilder/deweetyped untrusted ephemeral context for chat runtimes. Share conceptual schema/parser semantics where practical, without force-coupling webchat widget code to Chrome APIs.
- Ngôn ngữ chính
- TypeScript
- Star
- 7
- Fork
- 1
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nextlevelbuilder/dewee-webchat
-
ai-handle
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
-
ai-handle enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
ai-handle enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
ai-handle bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 53/100
Tất cả issue của nextlevelbuilder/dewee-webchat
Issue tương tự
-
area:cli bug P4
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug from-studio
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
esengine/DeepSeek-Reasonix#14868 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
linxiv-dev/linXiv#384 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
factory-active task-identify-harness-labels-done task-identify-issue-type-done
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
vercel/ai#24302 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày