| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"><head><meta charset="utf-8"> |
| 3 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
| 4 | <title>websearch</title> |
| 5 | <!--TOKENS--> |
| 6 | <style> |
| 7 | *{box-sizing:border-box} |
| 8 | html,body{margin:0} |
| 9 | body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px; |
| 10 | line-height:1.5;-webkit-font-smoothing:antialiased} |
| 11 | .wrap{max-width:1100px;margin:0 auto;padding:16px} |
| 12 | .head{display:flex;align-items:center;gap:12px;margin-bottom:14px;flex-wrap:wrap} |
| 13 | h1{font-size:20px;margin:0;font-weight:650;letter-spacing:-.01em} |
| 14 | .sub{color:var(--mu);font-size:12.5px} |
| 15 | .spacer{flex:1} |
| 16 | .card{background:var(--surface);border:1px solid var(--ln);border-radius:14px; |
| 17 | padding:16px;margin-bottom:14px} |
| 18 | .card h2{font-size:13px;font-weight:650;margin:0 0 12px;color:var(--mu); |
| 19 | text-transform:uppercase;letter-spacing:.06em} |
| 20 | .row{display:flex;flex-wrap:wrap;gap:10px;align-items:flex-end} |
| 21 | .f{display:flex;flex-direction:column;gap:4px;min-width:140px;flex:1 1 160px} |
| 22 | label{font-size:11.5px;color:var(--mu);text-transform:uppercase;letter-spacing:.05em} |
| 23 | input,select{background:var(--input-bg);border:1px solid var(--ln);color:var(--text); |
| 24 | border-radius:9px;padding:7px 10px;font-size:13.5px;font-family:var(--font); |
| 25 | outline:none;min-width:0;width:100%} |
| 26 | input:focus,select:focus{border-color:var(--ac)} |
| 27 | button{background:var(--ac);color:#fff;border:0;border-radius:980px;padding:7px 16px; |
| 28 | font-size:13px;font-weight:600;cursor:pointer;font-family:var(--font);white-space:nowrap} |
| 29 | button.ghost{background:var(--surface-2);color:var(--text)} |
| 30 | button.mini{padding:4px 11px;font-size:12px} |
| 31 | button:active{transform:scale(.98)} |
| 32 | button:disabled{opacity:.55;cursor:default} |
| 33 | .providers{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:10px} |
| 34 | .prov{border:1px solid var(--ln);border-radius:12px;padding:12px;background:var(--surface-2); |
| 35 | cursor:pointer;transition:border-color .15s var(--ease),transform .15s var(--ease)} |
| 36 | .prov:hover{border-color:var(--ln2)} |
| 37 | .prov.on{border-color:var(--ac);box-shadow:0 0 0 1px var(--ac) inset} |
| 38 | .prov-top{display:flex;align-items:center;gap:8px;margin-bottom:4px} |
| 39 | .prov-name{font-weight:650;font-size:14px} |
| 40 | .prov-hint{color:var(--mu);font-size:12px} |
| 41 | .pill{font-size:10.5px;font-weight:700;letter-spacing:.04em;text-transform:uppercase; |
| 42 | border-radius:980px;padding:2px 8px;border:1px solid var(--ln);color:var(--mu)} |
| 43 | .pill.ok{color:var(--ok);border-color:color-mix(in srgb,var(--ok) 45%,transparent)} |
| 44 | .pill.miss{color:var(--warn);border-color:color-mix(in srgb,var(--warn) 45%,transparent)} |
| 45 | .pill.mcp{color:var(--ac);border-color:color-mix(in srgb,var(--ac) 45%,transparent)} |
| 46 | .results{margin-top:12px;display:flex;flex-direction:column;gap:10px} |
| 47 | .res{border:1px solid var(--ln);border-radius:12px;padding:12px;background:var(--surface-2)} |
| 48 | .res a{color:var(--ac);font-weight:650;font-size:14px;word-break:break-word} |
| 49 | .res .site{color:var(--mu);font-size:11.5px;margin-left:6px} |
| 50 | .res p{margin:6px 0 0;color:var(--tx);font-size:13px;opacity:.9} |
| 51 | .answer{border-left:3px solid var(--ac);padding:8px 12px;background:var(--surface-2); |
| 52 | border-radius:8px;margin-bottom:10px;font-size:13.5px;white-space:pre-wrap} |
| 53 | .meta{color:var(--mu);font-size:12px;margin-top:8px} |
| 54 | .err{color:var(--err);font-size:13px;margin-top:10px;white-space:pre-wrap;word-break:break-word} |
| 55 | .hint{color:var(--mu);font-size:12px;margin-top:6px} |
| 56 | .hint code{font-family:var(--mono);font-size:11.5px;background:var(--code-bg); |
| 57 | padding:1px 5px;border-radius:5px} |
| 58 | .kv{display:grid;grid-template-columns:1fr 1fr;gap:10px} |
| 59 | @media(max-width:700px){.kv{grid-template-columns:1fr}.wrap{padding:12px}} |
| 60 | .spin{display:inline-block;width:12px;height:12px;border:2px solid var(--ln2); |
| 61 | border-top-color:var(--ac);border-radius:50%;animation:sp .7s linear infinite; |
| 62 | vertical-align:-2px;margin-right:6px} |
| 63 | @keyframes sp{to{transform:rotate(360deg)}} |
| 64 | </style> |
| 65 | </head> |
| 66 | <body> |
| 67 | <div class="wrap"> |
| 68 | <div class="head"> |
| 69 | <div> |
| 70 | <h1>Web search</h1> |
| 71 | <div class="sub">Six backends, one tool: <code>web_search</code></div> |
| 72 | </div> |
| 73 | <div class="spacer"></div> |
| 74 | <button class="ghost embed-hide" id="themeToggle" type="button">Theme</button> |
| 75 | </div> |
| 76 | |
| 77 | <div class="card"> |
| 78 | <h2>Backends</h2> |
| 79 | <div class="providers" id="providers"></div> |
| 80 | <div class="hint">Click a backend to make it the default. Providers that need a key stay |
| 81 | selectable — the search below will tell you exactly what is missing.</div> |
| 82 | </div> |
| 83 | |
| 84 | <div class="card"> |
| 85 | <h2>Search</h2> |
| 86 | <div class="row"> |
| 87 | <div class="f" style="flex:2 1 280px"> |
| 88 | <label for="q">Query</label> |
| 89 | <input id="q" type="text" placeholder="what are you looking for?" autocomplete="off"> |
| 90 | </div> |
| 91 | <div class="f" style="flex:0 1 110px"> |
| 92 | <label for="count">Results</label> |
| 93 | <input id="count" type="number" min="1" max="20" value="5"> |
| 94 | </div> |
| 95 | <div class="f" style="flex:0 1 150px"> |
| 96 | <label for="providerSel">Backend</label> |
| 97 | <select id="providerSel"></select> |
| 98 | </div> |
| 99 | <div class="f" style="flex:0 0 auto"> |
| 100 | <label> </label> |
| 101 | <button id="go" type="button">Search</button> |
| 102 | </div> |
| 103 | </div> |
| 104 | <div class="meta" id="runMeta"></div> |
| 105 | <div class="err" id="err"></div> |
| 106 | <div class="results" id="results"></div> |
| 107 | </div> |
| 108 | |
| 109 | <div class="card"> |
| 110 | <h2>Keys & defaults</h2> |
| 111 | <div class="kv"> |
| 112 | <div class="f"><label for="k_brave">Brave API key</label> |
| 113 | <input id="k_brave" type="password" placeholder="unset" autocomplete="off"> |
| 114 | <span class="hint" id="h_brave"></span></div> |
| 115 | <div class="f"><label for="k_tavily">Tavily API key</label> |
| 116 | <input id="k_tavily" type="password" placeholder="unset" autocomplete="off"> |
| 117 | <span class="hint" id="h_tavily"></span></div> |
| 118 | <div class="f"><label for="k_exa">Exa API key</label> |
| 119 | <input id="k_exa" type="password" placeholder="unset" autocomplete="off"> |
| 120 | <span class="hint" id="h_exa"></span></div> |
| 121 | <div class="f"><label for="k_pplx">Perplexity API key</label> |
| 122 | <input id="k_pplx" type="password" placeholder="unset" autocomplete="off"> |
| 123 | <span class="hint" id="h_pplx"></span></div> |
| 124 | <div class="f"><label for="searxng">SearXNG base URL</label> |
| 125 | <input id="searxng" type="text" placeholder="http://127.0.0.1:8888" autocomplete="off"> |
| 126 | <span class="hint">Self-hosted instance with <code>format=json</code> enabled.</span></div> |
| 127 | <div class="f"><label for="region">DuckDuckGo region</label> |
| 128 | <input id="region" type="text" placeholder="nz-en (empty = default)" autocomplete="off"> |
| 129 | <span class="hint">Two-letter region plus language, e.g. <code>nz-en</code>.</span></div> |
| 130 | <div class="f"><label for="safe">Safe search</label> |
| 131 | <select id="safe"> |
| 132 | <option value="strict">Strict</option> |
| 133 | <option value="moderate">Moderate</option> |
| 134 | <option value="off">Off</option> |
| 135 | </select></div> |
| 136 | <div class="f"><label for="language">Language</label> |
| 137 | <input id="language" type="text" placeholder="en (empty = provider default)" autocomplete="off"></div> |
| 138 | <div class="f"><label for="categories">SearXNG categories</label> |
| 139 | <input id="categories" type="text" placeholder="general" autocomplete="off"></div> |
| 140 | <div class="f"><label for="tavily_answer">Tavily answer</label> |
| 141 | <select id="tavily_answer"> |
| 142 | <option value="0">Off</option> |
| 143 | <option value="1">On</option> |
| 144 | </select></div> |
| 145 | </div> |
| 146 | <div class="row" style="margin-top:14px"> |
| 147 | <button id="save" type="button">Save</button> |
| 148 | <button class="ghost" id="clearKeys" type="button">Clear all keys</button> |
| 149 | <div class="spacer"></div> |
| 150 | <span class="meta" id="saveMeta"></span> |
| 151 | </div> |
| 152 | <div class="hint">Keys are written to <code>config.json</code> at mode <code>0600</code> in the |
| 153 | connector directory and are never sent back to this page — only whether one is set.</div> |
| 154 | </div> |
| 155 | |
| 156 | <div class="card"> |
| 157 | <h2>Agent tools</h2> |
| 158 | <div class="hint"><code>web_search</code> takes <code>query</code>, and optionally |
| 159 | <code>provider</code>, <code>count</code>, <code>country</code>, <code>language</code> and |
| 160 | <code>freshness</code>. <code>web_search_providers</code> reports which backends are ready. |
| 161 | Both are served over MCP stdio through the single <code>sx-connector-mcp</code> router, so |
| 162 | nothing has to be restarted after a change here.</div> |
| 163 | </div> |
| 164 | </div> |
| 165 | <script> |
| 166 | (function () { |
| 167 | var P = null, active = 'duckduckgo'; |
| 168 | function $(id) { return document.getElementById(id); } |
| 169 | function esc(s) { |
| 170 | return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { |
| 171 | return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]; |
| 172 | }); |
| 173 | } |
| 174 | function pwd() { |
| 175 | var m = /[?&]pwd=([^&]*)/.exec(location.search); |
| 176 | return m ? 'pwd=' + encodeURIComponent(decodeURIComponent(m[1])) + '&' : ''; |
| 177 | } |
| 178 | function api(suffix) { |
| 179 | return fetch('?action=' + suffix + '&' + pwd() + 'format=json', |
| 180 | { credentials: 'same-origin' }) |
| 181 | .then(function (r) { return r.json(); }); |
| 182 | } |
| 183 | function post(payload) { |
| 184 | return fetch('?' + pwd() + 'format=json', { |
| 185 | method: 'POST', |
| 186 | credentials: 'same-origin', |
| 187 | headers: { 'Content-Type': 'application/json' }, |
| 188 | body: JSON.stringify(payload) |
| 189 | }).then(function (r) { return r.json(); }); |
| 190 | } |
| 191 | |
| 192 | function renderProviders() { |
| 193 | var host = $('providers'), sel = $('providerSel'), html = '', opts = ''; |
| 194 | (P.providers || []).forEach(function (p) { |
| 195 | var pill = p.ready |
| 196 | ? '<span class="pill ok">' + (p.needs_key ? 'key set' : 'ready') + '</span>' |
| 197 | : '<span class="pill miss">' + (p.needs_key ? 'no key' : 'no URL') + '</span>'; |
| 198 | html += '<div class="prov' + (p.id === active ? ' on' : '') + '" data-id="' + esc(p.id) + '">' + |
| 199 | '<div class="prov-top"><span class="prov-name">' + esc(p.label) + '</span>' + pill + '</div>' + |
| 200 | '<div class="prov-hint">' + esc(p.hint) + '</div>' + |
| 201 | (p.signup ? '<div class="prov-hint"><a href="' + esc(p.signup) + |
| 202 | '" target="_blank" rel="noopener">' + |
| 203 | (p.needs_key ? 'Get a key' : 'Info') + '</a></div>' : '') + |
| 204 | '</div>'; |
| 205 | opts += '<option value="' + esc(p.id) + '"' + (p.id === active ? ' selected' : '') + '>' + |
| 206 | esc(p.label) + '</option>'; |
| 207 | }); |
| 208 | host.innerHTML = html; |
| 209 | sel.innerHTML = opts; |
| 210 | Array.prototype.forEach.call(host.querySelectorAll('.prov'), function (el) { |
| 211 | el.onclick = function () { |
| 212 | active = el.getAttribute('data-id'); |
| 213 | renderProviders(); |
| 214 | $('providerSel').value = active; |
| 215 | }; |
| 216 | }); |
| 217 | } |
| 218 | |
| 219 | function fill(p) { |
| 220 | P = p; |
| 221 | active = p.active || 'duckduckgo'; |
| 222 | renderProviders(); |
| 223 | $('count').value = p.default_count || 5; |
| 224 | $('region').value = p.region || ''; |
| 225 | $('safe').value = p.safe || 'moderate'; |
| 226 | $('language').value = p.language || ''; |
| 227 | $('categories').value = p.searxng_categories || 'general'; |
| 228 | $('tavily_answer').value = p.tavily_answer ? '1' : '0'; |
| 229 | (p.providers || []).forEach(function (x) { |
| 230 | var k = $('k_' + x.id.replace('perplexity', 'pplx')); |
| 231 | if (k) { k.value = ''; k.placeholder = x.has_key ? 'set (leave blank to keep)' : 'unset'; } |
| 232 | var h = $('h_' + x.id.replace('perplexity', 'pplx')); |
| 233 | if (h) h.textContent = x.has_key ? 'A key is saved on this node.' : 'No key saved.'; |
| 234 | if (x.id === 'searxng') $('searxng').value = x.base || ''; |
| 235 | }); |
| 236 | } |
| 237 | |
| 238 | function search() { |
| 239 | var q = $('q').value.trim(); |
| 240 | if (!q) { $('q').focus(); return; } |
| 241 | $('err').textContent = ''; |
| 242 | $('results').innerHTML = ''; |
| 243 | $('runMeta').innerHTML = '<span class="spin"></span>searching with ' + esc($('providerSel').value) + '…'; |
| 244 | $('go').disabled = true; |
| 245 | post({ action: 'search', q: q, provider: $('providerSel').value, |
| 246 | count: parseInt($('count').value, 10) || 5 }) |
| 247 | .then(function (d) { |
| 248 | $('go').disabled = false; |
| 249 | if (!d || d.ok !== true) { |
| 250 | $('runMeta').textContent = ''; |
| 251 | $('err').textContent = (d && d.error ? d.error : 'search failed') + |
| 252 | (d && d.status ? ' (HTTP ' + d.status + ')' : ''); |
| 253 | return; |
| 254 | } |
| 255 | $('runMeta').textContent = d.count + ' result' + (d.count === 1 ? '' : 's') + |
| 256 | ' from ' + d.provider + ' in ' + d.took_ms + ' ms'; |
| 257 | var html = ''; |
| 258 | if (d.answer) html += '<div class="answer">' + esc(d.answer) + '</div>'; |
| 259 | (d.results || []).forEach(function (r) { |
| 260 | html += '<div class="res">' + |
| 261 | '<div><a href="' + esc(r.url) + '" target="_blank" rel="noopener noreferrer">' + |
| 262 | esc(r.title || r.url) + '</a>' + |
| 263 | (r.site ? '<span class="site">' + esc(r.site) + '</span>' : '') + '</div>' + |
| 264 | (r.snippet ? '<p>' + esc(r.snippet) + '</p>' : '') + |
| 265 | (r.published ? '<div class="meta">' + esc(r.published) + '</div>' : '') + |
| 266 | '</div>'; |
| 267 | }); |
| 268 | if (!d.count) html = '<div class="hint">No results. Try a different backend or query.</div>'; |
| 269 | $('results').innerHTML = html; |
| 270 | }) |
| 271 | .catch(function (e) { |
| 272 | $('go').disabled = false; |
| 273 | $('runMeta').textContent = ''; |
| 274 | $('err').textContent = String(e); |
| 275 | }); |
| 276 | } |
| 277 | |
| 278 | function save() { |
| 279 | var body = { |
| 280 | action: 'save', |
| 281 | provider: active, |
| 282 | count: parseInt($('count').value, 10) || 5, |
| 283 | region: $('region').value, |
| 284 | safe: $('safe').value, |
| 285 | language: $('language').value, |
| 286 | searxng_categories: $('categories').value, |
| 287 | tavily_answer: $('tavily_answer').value === '1' ? 1 : 0, |
| 288 | searxng_base: $('searxng').value |
| 289 | }; |
| 290 | [['brave', 'k_brave'], ['tavily', 'k_tavily'], ['exa', 'k_exa'], |
| 291 | ['pplx', 'k_pplx']].forEach(function (pair) { |
| 292 | var v = $(pair[1]).value.trim(); |
| 293 | if (v) body[pair[0] + '_key'] = v; |
| 294 | }); |
| 295 | $('saveMeta').innerHTML = '<span class="spin"></span>saving…'; |
| 296 | post(body).then(function (d) { |
| 297 | if (d && d.providers) { fill(d); $('saveMeta').textContent = 'Saved.'; } |
| 298 | else $('saveMeta').textContent = (d && d.error) ? d.error : 'Save failed.'; |
| 299 | }).catch(function (e) { $('saveMeta').textContent = String(e); }); |
| 300 | } |
| 301 | |
| 302 | function clearKeys() { |
| 303 | if (!confirm('Remove every saved API key from this node?')) return; |
| 304 | post({ action: 'save', clear_brave_key: 1, clear_tavily_key: 1, |
| 305 | clear_exa_key: 1, clear_pplx_key: 1 }) |
| 306 | .then(function (d) { if (d && d.providers) { fill(d); $('saveMeta').textContent = 'Keys cleared.'; } }); |
| 307 | } |
| 308 | |
| 309 | $('go').onclick = search; |
| 310 | $('q').addEventListener('keydown', function (e) { if (e.key === 'Enter') search(); }); |
| 311 | $('save').onclick = save; |
| 312 | $('clearKeys').onclick = clearKeys; |
| 313 | $('providerSel').addEventListener('change', function () { |
| 314 | active = $('providerSel').value; |
| 315 | renderProviders(); |
| 316 | $('providerSel').value = active; |
| 317 | }); |
| 318 | |
| 319 | var tb = $('themeToggle'); |
| 320 | if (tb) tb.onclick = function () { |
| 321 | var cur = document.documentElement.getAttribute('data-theme') === 'light' ? 'dark' : 'light'; |
| 322 | document.documentElement.setAttribute('data-theme', cur); |
| 323 | try { localStorage.setItem('bot_theme', cur); } catch (e) {} |
| 324 | }; |
| 325 | |
| 326 | api('config').then(fill).catch(function (e) { |
| 327 | $('err').textContent = 'cannot load the configuration: ' + e; |
| 328 | }); |
| 329 | })(); |
| 330 | </script> |
| 331 | </body> |
| 332 | </html> |