mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2826] [CLOSED] [GUI] Web search and page reading for the web app's Chat (DuckDuckGo default, SearXNG, Brave, Tavily, Serper) #4284
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4284
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2826
Author: @c-OOL-io
Created: 10/17/2026
Status: ❌ Closed
Base:
main← Head:web-search📝 Commits (7)
5ad9e70Web search for the web app: settings drawer with engine picker (DuckDuckGo default, SearXNG, Brave, Tavily, Serper), composer globe toggle, results injected as context, sources under each answer and in the Markdown export60fd49eWeb search: read result pages in full, context-aware reading budget, page-text limit switch612fdacWeb search: fix /search crash - reported_ctx lives on the Service (svc), not the HTTP handlerb391679Web search: Jina reader tiers (off/fallback/always) with privacy notices, DDG bot-check fix, clearer errors, Settings wording and empty-state text03cb9d7Web search: combined page-read failure reason reads as 'reason; Jina too: reason' instead of two bare parenthesised reasons0e71229Web search hardening: same-origin guard on /search, http(s)-only URLs for engine base and page reading, links rendered only for http(s), search prompt marks web data untrusted, LAN-bound servers warn when search turns onbd5c88bWeb search: query optimizer (local, language-preserving) with searched-as transparency in the sources line, Chat Settings drawer rework (fixed Reset/Apply, Sampling section, search controls collapse when off), live search progress in the pill and answer bubble with a single pill priority function so the metrics poll and the search timer can no longer fight📊 Changes
7 files changed (+733 additions, -32 deletions)
View changed files
📝
serve/server.py(+30 -0)📝
serve/web/app.css(+1 -1)📝
serve/web/app.js(+277 -18)📝
serve/web/components.css(+14 -1)📝
serve/web/index.html(+63 -12)📝
serve/web/sprite.svg(+1 -0)➕
serve/websearch.py(+347 -0)📄 Description
Problem and result
The Chat tab of the lean web app (the serve/Terminal frontend, not the App) has no web access at all: answers are limited to the model's weights, and agent-style use on a headless server had no source-backed option. Upstream shipped web search for the App in 0.2.0; the serve web chat route is still without it.
Before: no search in the web app's Chat, no sources. After: a built-in web search, modeled after how Open WebUI and similar chat tools do it: the model can look the question up before answering, and the answer shows its sources. Web search is completely off by default: until the user turns it on in Chat Settings, nothing about this feature sends anything out of the PC. Strata's Chat is deliberately lean, and this feature is built the same way: it adds no tokens until a chat turns search on, and results are budget-capped to a small slice of the model's context window (defaults scale with the context window), so the Chat gains recent information without losing what makes it comfortable for long sessions.
Related discussion
None (no prior scope-issue exists). Note: this PR is the original discussion; it was closed 19.10. in the pre-0.2.0-beta tracker reset ("closed here does not mean rejected") and is rebased on current main and re-validated per the reopen steps. Upstream's App search (
apps/host, DuckDuckGo via MCP) does not overlap with this work: this targets the serve web chat, with self-hostable engines (SearXNG) and server-side page reading.Approach
Search runs server-side in the serve backend (
serve/websearch.py, stdlib-only); the browser frontend only configures and renders it. All providers are fetched through the Strata server (a browser could not call them directly because of CORS). API keys stay browser-only (localStorage), like the existing API-key field; nothing search-related is stored on the server.What it looks like in the UI
[n].Sources (DuckDuckGo): [1] … | [2] …(clickable, engine named, read pages get areadbadge), and they are included in the "Save this chat as Markdown" export.Framing query→Searching web + reading pages · DuckDuckGo · 12.4 s; a failed search readsSearch failedfor 2.5 s. The same status line appears in the answer bubble exactly where "Thinking…" would sit.… · 1 queued) instead of hiding it or hijacking the label: one priority function owns the pill (search phase > engine state > queue count > idle), so the 1 s metrics poll and the 250 ms search timer can no longer overwrite each other.Query optimizer
Conversational wording ("can you look up what the newest Qwen release from Alibaba is") makes weak search queries, so there is an "Optimize search query" toggle (on by default): one fast call to the user's own local model (temperature 0, reasoning off, max 100 tokens) extracts the core search question before the search runs.
Sources (DuckDuckGo) · searched: "…", and so does the Markdown export. An optimized query is never hidden behind a plain-looking result.Reading result pages in full
Snippets alone often miss the details, so search can also fetch the top result pages and inject their extracted text (Open WebUI's "Web Loader" idea, stdlib
html.parserbased, which skips nav/footer/scripts, prefersmain/article):Page reader: direct fetch, or Jina Reader for JS-heavy pages
Plain
urllibcannot render JavaScript-heavy pages, so there is a 3-tier Page reader setting:STRATA_JINA_URL(e.g. a self-hosted instance), and failures of either path degrade to a readable combined reason.Context-aware reading budget
How much search text goes into the prompt scales with the model's own context window (
reported_ctx()), so small-context instances are never overloaded:/health'smax_context(e.g. 16K ctx → 4 results / 1 page × 3000 chars; 128K → 6 / 2 × 5000; 262K → 8 / 3 × 5000).Distinct, persistent search warnings
A failed search no longer fails silently: the reason stays on the message (in the sources line, warning-colored) and in the Markdown export, with a different message per cause:
Brave Search needs its API key (Chat Settings > Web search)(same for Tavily/Serper; a rejected key gets its own message, incl. Brave's 422)SearXNG at http://127.0.0.1:8888 is not reachable (…); start it or pick another engineanomaly.jspage; the fetcher uses an honest custom UA and, if the bot page still shows up, says so instead of reporting "no results"no resultsread_error(shown as a warning line), never a silent empty stringSecurity hardening
/searchsits behind the web app's own-page guard (_own_page): a JSON body is required (415 for form posts) and a foreignOriginis rejected (403;trusted_originsstill allowed), so a random web page cannot make this PC run searches or fetch URLs through it._http_url);file://,data:,javascript:and friends are refused with an explicit reason, so page reading can never become a local file reader.http(s)URLs become clickable<a href>; anything else shows as plain text, so nojavascript:/data:links from a poisoned result./healthreportslan_bound(server bound beyond loopback, e.g.0.0.0.0); turning search on fires an extra toast line warning that queries and engine keys then cross the network in plain HTTP and that devices on it can use the search without an api_key. On the default127.0.0.1bind this warning never appears.Settings drawer updates
Scroll fix (drive-by)
Auto-follow-to-bottom was broken for turns where content grows past the stick threshold mid-stream (the thinking panel expanding could pin the view at the user's own message). Stickiness is now captured before the content grows, so the view keeps following the answer.
Engines
http://127.0.0.1:8888)Design notes
serve/websearch.pyis stdlib-only (urllib,json,re,html.parser,os); no new dependencies, cross-platform (Windows/Linux/macOS).POST /searchcarries its own engine config per request; nothing is stored on the server.contenton success,read_erroron failure,read_viafor Jina-read pages) instead of heuristics./searchhas a catch-all so an unexpected error returns a clean 502 with a server-side log line instead of a broken connection.Validation
Re-validated today (20.10.) on the rebased branch
web-search@e447e11f, which contains upstreammainincluding894d1be1(0.2.1) and8aaf188a(user-args/VRAM fix). Environment: Windows 11, RTX 4080 SUPER 16 GB, Ryzen 9 7950X3D, engine 0.1.45 (MIN_ENGINE(0,1,45) met), model qwen3.8-flash-next-iq3_xxs, 128K ctx.Passed:
python -m unittest serve.test_websearch -v(the suite now committed in this branch): 14 tests, all green (scheme guard rejects 15 poison URL typesfile:// gopher:// javascript: data: ftp:// dict:// ldap:// sftp:// ssh:// mailto: telnet: jar: chrome-extension: vbscript:and accepts http(s); reader tier matrix direct/fallback/always incl. Jina rescue on a failing direct fetch and the combined both-paths-fail reason; bad reader values degrade to direct; non-HTML content refused; reading-budget clamps at 10 %/25 % of context with per-page caps derived at 4K/16K/128K;max_resultsclamp).python -m py_compile serve/server.py serve/websearch.py serve/runconfig.py tools/strata_bench.pyon the merged revision: clean.--vram-reserve-mib 700,--pcie-frac 0.20,--pool-workers 10; no override), and 3 benchmark arms measured agent decode 104.9 / 110.7 / 110.8 tok/s, chat decode median 94.1 vs 94.6 baseline from 19.10. (no regression introduced by the merge).lan_boundverified on loopback vs.0.0.0.0mock servers; the pill priority table unit-tested headlessly.Failed: none observed.
Not run: CUDA/HIP/SYCL/Metal builds and the Docker images (this PR changes only the Python serve layer and its web frontend, no engine or C++ code); the 45 headless-JS UI checks from development were not re-run after the rebase (the committed Python suite covers the server side; the UI behaviors were verified interactively pre-rebase).
Limits
Happy to adjust anything (naming, where the settings live, engine list, budget shares, the Jina default) if this should look different.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.