mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3420] [GUI] Web search and page reading for the web app's Chat (DuckDuckGo default, SearXNG, Brave, Tavily, Serper, Exa, Perplexity) #4626
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#4626
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/3420
Author: @c-OOL-io
Created: 10/20/2026
Status: 🔄 Open
Base:
main← Head:web-search📝 Commits (10+)
c172000Web 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 exportf27bc83Web search: read result pages in full, context-aware reading budget, page-text limit switch6a89630Web search: fix /search crash - reported_ctx lives on the Service (svc), not the HTTP handler74d2f77Web search: Jina reader tiers (off/fallback/always) with privacy notices, DDG bot-check fix, clearer errors, Settings wording and empty-state text9d9e396Web search: combined page-read failure reason reads as 'reason; Jina too: reason' instead of two bare parenthesised reasonsa1ef2d8Web 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 on81bb96dWeb 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 fighte280915Merge upstream Strata main (0.2.0-beta + user-args/VRAM-reserve fix8aaf188a) into web-searchf2b25e4Merge upstream main into web-search (pre-rebuild pull)2ab1f71README: fork notice (source-only search, headless serve route) + search screenshots📊 Changes
37 files changed (+7834 additions, -133 deletions)
View changed files
📝
README.de.md(+32 -0)📝
README.es.md(+31 -0)📝
README.fr.md(+31 -0)📝
README.ja.md(+31 -0)📝
README.md(+34 -0)📝
README.pl.md(+23 -0)📝
README.pt-BR.md(+31 -0)📝
README.zh-CN.md(+31 -0)➕
docs/INSTALL.FORK.md(+81 -0)➕
docs/media/web-search-chat.png(+0 -0)➕
docs/media/web-search-settings.png(+0 -0)➕
feature_merge.diff(+2880 -0)📝
serve/server.py(+30 -0)➕
serve/test_websearch.py(+522 -0)📝
serve/web/app.css(+1 -1)📝
serve/web/app.js(+538 -47)📝
serve/web/chats-ui.js(+8 -0)📝
serve/web/components.css(+17 -1)📝
serve/web/history.js(+2 -1)📝
serve/web/i18n.js(+4 -1)...and 17 more files
📄 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
Replaces #2826: that PR was closed in the pre-0.2.0-beta tracker reset ("closed here does not mean rejected"); after the rebase its stored head commit became unreachable, so GitHub refuses to reopen it and this PR carries the same work on a live base. 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.Status: maintained & up to date
This branch is kept current with upstream 0.2.2 (engine 0.1.47) and re-tested after every refresh. On real hardware (Ryzen 9 7950X3D, RTX 4080 SUPER, Windows 11) the committed offline suite is green on the merged tree (27 tests: scheme guards, engine whitelist, reader tiers, keyed engines, context-aware budgets), and live DuckDuckGo and SearXNG searches still return results and sources unchanged. The fork
web-searchbranch is pushed to the current 0.2.2 state, so this PR merges cleanly against latestmain.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/Exa/Perplexity; 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)sonar)Exa and Perplexity call the same endpoints upstream's App calls (
api.exa.ai/searchwith Bearer key,api.perplexity.ai/chat/completionsmodelsonar, sources taken fromsearch_results, falling back to barecitationswhen the plan omits them), so a key someone already has for the App works here unchanged.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@0042c1e2, 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): 27 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; keyed engines: Exa/Perplexity demand their key, Exa result+highlights mapping skips URL-less rows, Perplexity mapssearch_resultsand falls back to barecitations; hardening pass from an independent review pinned as tests: malformed engine envelopes (top-level lists, non-list result rows, non-dict rows, wrong-typehighlights/citations) become named engine errors instead of crashes, junk rows dropped, snippet cap 2000 verified for every engine).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); Exa and Perplexity were not live-tested (no API keys available here; the request/response mapping is verified against mocks of the same endpoints upstream's App calls).
Limits
Happy to adjust anything (naming, where the settings live, engine list, budget shares, the Jina default) if this should look different.
New in this update: Auto search, message-box draft, 14-language UI
Auto search (tri-state)
The composer globe now cycles Off -> On -> Auto. On always searches; Auto lets a per-message decision pick: the model itself calls a
web_searchtool (Weg A, recommended) or a fixed keyword heuristic fires (Weg B, for models that cannot call tools reliably). In every mode search respects the privacy gate: nothing leaves the PC unless search is enabled. Stopping the model during the decision no longer wedges the composer; a failed decision falls back to the heuristic, never to an unvetted raw search, and the single decision call now has room so a thorough reasoning model does not burn its budget before emitting the tool call.Keyword (Simple check) heuristic precision
Whole-word Unicode-aware boundaries for Latin/Cyrillic/Greek with CJK substring matching, so "now" no longer fires inside "know" and "ora" inside "ancora" while Japanese/Chinese/Korean phrasing still triggers. The year signal requires the current year +/- 1, and the date signal a real 4-digit year that is not part of a longer digit run ("3.10.12", "1.2.20234" no longer read as dates). Turkish currency phrasing ("dolar kuru", "döviz kuru") now triggers while "kurulum" does not.
Fix: search settings section
The Chat > Web search settings were permanently hidden by a wrong radio read; the engine/limits/reader rows now show whenever search is on, and the mode buttons carry
role="radio"for screen readers.Message-box draft (optional, browser-only)
A new "Save what you type" toggle in Chat Settings > Chats keeps the message box draft per chat in this browser (off by default). It survives reload and chat switch; oversized images/file payloads are capped and a quota failure retries text-only so typed input is never lost; a pending debounced save cannot land in the next chat's slot; deleting a chat purges its draft, disabling the option clears all saved drafts, and taking back a parked message re-saves the restored text.
Notification scoping
Clearing the web-search notice toasts no longer discards action/undo toasts, and Reset now also clears any lingering privacy notice.
Language: 14 locales
The web UI switches across 14 languages (de, es, fr, ja, ko, pt, ru, zh, hi, ar with RTL, tr, it, pl) from Chat Settings. All labels are translated, plural forms (including the token count) are correct in every catalog, and the last leftover untranslated strings (greedy, seed, mode and engine labels) are closed.
Web search hardening + small UI fixes
ws.onEmptyin all 14 catalogs.node --checkandpy_compileclean.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.