@alexwkleung/reika 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD_PARTY_LICENSES.txt +1271 -0
- package/dist/chunk-AX767B3T.js +22724 -0
- package/dist/chunk-JVOYWUGK.js +279 -0
- package/dist/chunk-KI5CTLSX.js +59 -0
- package/dist/chunk-SBBXMTSX.js +4050 -0
- package/dist/cli.js +153 -53
- package/dist/devtools-FYXXYYMR.js +2 -0
- package/dist/esm-SND35LIM.js +8494 -0
- package/dist/headless-Y2V6WPLB.js +592 -0
- package/dist/node-7FRVMBZF.js +69479 -0
- package/dist/tui-KWAD5BDE.js +34366 -0
- package/package.json +16 -17
- package/dist/agent/attachments.js +0 -63
- package/dist/agent/bashread.js +0 -177
- package/dist/agent/compaction.js +0 -922
- package/dist/agent/compactionreport.js +0 -248
- package/dist/agent/continuation.js +0 -153
- package/dist/agent/decoderate.js +0 -132
- package/dist/agent/entropytrace.js +0 -169
- package/dist/agent/genreserve.js +0 -75
- package/dist/agent/groundcheck.js +0 -195
- package/dist/agent/logitrecovery.js +0 -171
- package/dist/agent/loop.js +0 -3676
- package/dist/agent/mentions.js +0 -118
- package/dist/agent/noteslotmonitor.js +0 -82
- package/dist/agent/pastedurls.js +0 -203
- package/dist/agent/planpressure.js +0 -87
- package/dist/agent/plantrack.js +0 -503
- package/dist/agent/prefillcost.js +0 -95
- package/dist/agent/prefixtrace.js +0 -90
- package/dist/agent/prompt.js +0 -349
- package/dist/agent/readfirst.js +0 -190
- package/dist/agent/readtrace.js +0 -191
- package/dist/agent/reasoningtrace.js +0 -242
- package/dist/agent/shellruns.js +0 -81
- package/dist/agent/subagentpressure.js +0 -70
- package/dist/agent/subagentreport.js +0 -117
- package/dist/agent/warm.js +0 -163
- package/dist/approval.js +0 -59
- package/dist/check/typecheck.js +0 -345
- package/dist/config.js +0 -509
- package/dist/context/bootstrap.js +0 -122
- package/dist/context/bundlesize.js +0 -74
- package/dist/context/files.js +0 -67
- package/dist/context/gitignore.js +0 -102
- package/dist/context/repomap.js +0 -304
- package/dist/debug.js +0 -197
- package/dist/headless/headless.js +0 -440
- package/dist/headless/headlessargs.js +0 -108
- package/dist/headless/headlessprompt.js +0 -132
- package/dist/laststate.js +0 -71
- package/dist/limit.js +0 -27
- package/dist/mcp/client.js +0 -630
- package/dist/mcp/config.js +0 -187
- package/dist/mcp/manager.js +0 -158
- package/dist/mcp/tools.js +0 -323
- package/dist/ocr/select.js +0 -29
- package/dist/ocr/system.js +0 -162
- package/dist/ocr/types.js +0 -1
- package/dist/ocr/vision.js +0 -139
- package/dist/provider/budget.js +0 -56
- package/dist/provider/cachehints.js +0 -30
- package/dist/provider/client.js +0 -573
- package/dist/provider/contextwindow.js +0 -78
- package/dist/provider/dispatcher.js +0 -126
- package/dist/provider/latches.js +0 -31
- package/dist/provider/modellimits.js +0 -186
- package/dist/provider/noteslot.js +0 -239
- package/dist/provider/templatekwargs.js +0 -31
- package/dist/provider/tokens.js +0 -32
- package/dist/provider/toolcall.js +0 -1088
- package/dist/provider/transport.js +0 -264
- package/dist/search/_chrome.js +0 -422
- package/dist/search/cdp.js +0 -223
- package/dist/search/searxng.js +0 -86
- package/dist/search/types.js +0 -17
- package/dist/session.js +0 -411
- package/dist/skills/skillmatch.js +0 -143
- package/dist/skills/skills.js +0 -349
- package/dist/store/payloads.js +0 -21
- package/dist/store/sessions.js +0 -180
- package/dist/store/transcript.js +0 -390
- package/dist/tools/_carriers.js +0 -119
- package/dist/tools/_danger.js +0 -1848
- package/dist/tools/_deps.js +0 -203
- package/dist/tools/_diff.js +0 -64
- package/dist/tools/_exfil.js +0 -168
- package/dist/tools/_heredoc.js +0 -419
- package/dist/tools/_hosts.js +0 -224
- package/dist/tools/_markdown.js +0 -288
- package/dist/tools/_net.js +0 -65
- package/dist/tools/_paths.js +0 -171
- package/dist/tools/_readonly.js +0 -545
- package/dist/tools/_sandbox.js +0 -953
- package/dist/tools/_spill.js +0 -216
- package/dist/tools/_spillstats.js +0 -45
- package/dist/tools/_treediff.js +0 -350
- package/dist/tools/_urls.js +0 -335
- package/dist/tools/_walk.js +0 -24
- package/dist/tools/_writetargets.js +0 -96
- package/dist/tools/ask.js +0 -194
- package/dist/tools/bash.js +0 -638
- package/dist/tools/edit.js +0 -439
- package/dist/tools/fetch.js +0 -415
- package/dist/tools/glob.js +0 -142
- package/dist/tools/grep.js +0 -263
- package/dist/tools/index.js +0 -171
- package/dist/tools/list.js +0 -96
- package/dist/tools/read.js +0 -74
- package/dist/tools/search.js +0 -134
- package/dist/tools/subagent.js +0 -23
- package/dist/tools/write.js +0 -107
- package/dist/types.js +0 -1
- package/dist/ui/App.js +0 -2874
- package/dist/ui/Approval.js +0 -148
- package/dist/ui/Confirm.js +0 -51
- package/dist/ui/DiffView.js +0 -401
- package/dist/ui/Input.js +0 -461
- package/dist/ui/ModelSelect.js +0 -32
- package/dist/ui/PlanProgress.js +0 -50
- package/dist/ui/Question.js +0 -238
- package/dist/ui/QueuedList.js +0 -17
- package/dist/ui/ResumeSelect.js +0 -61
- package/dist/ui/Scrollback.js +0 -715
- package/dist/ui/Splash.js +0 -42
- package/dist/ui/Status.js +0 -207
- package/dist/ui/Suggestions.js +0 -50
- package/dist/ui/Working.js +0 -242
- package/dist/ui/clipboard.js +0 -77
- package/dist/ui/commands.js +0 -205
- package/dist/ui/dialogspecs.js +0 -38
- package/dist/ui/focus.js +0 -56
- package/dist/ui/format.js +0 -180
- package/dist/ui/framedrops.js +0 -34
- package/dist/ui/glyphs.js +0 -48
- package/dist/ui/harnessecho.js +0 -24
- package/dist/ui/highlight.js +0 -191
- package/dist/ui/identity.js +0 -211
- package/dist/ui/layout.js +0 -224
- package/dist/ui/markdown.js +0 -357
- package/dist/ui/models.js +0 -32
- package/dist/ui/pastes.js +0 -59
- package/dist/ui/paths.js +0 -19
- package/dist/ui/pr.js +0 -78
- package/dist/ui/queue.js +0 -25
- package/dist/ui/reactbuild.js +0 -15
- package/dist/ui/reasoningfold.js +0 -63
- package/dist/ui/redact.js +0 -51
- package/dist/ui/scrub.js +0 -49
- package/dist/ui/suggest.js +0 -92
- package/dist/ui/summary.js +0 -60
- package/dist/ui/syncframe.js +0 -97
- package/dist/ui/termtext.js +0 -117
- package/dist/ui/theme.js +0 -100
- package/dist/ui/tui.js +0 -9
- package/dist/ui/warmtrigger.js +0 -37
- package/dist/version.js +0 -27
package/dist/search/cdp.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { debugLog } from '../debug.js';
|
|
2
|
-
import { ChromeHost } from './_chrome.js';
|
|
3
|
-
import { SearchUnavailableError } from './types.js';
|
|
4
|
-
// Brave, not Google. Measured on a live SERP: Google and Bing launder every outbound link through
|
|
5
|
-
// an opaque tracker (`google.com/goto?url=…`, `bing.com/ck/a?…`) — 0 of 53 and 0 of 46 visible links
|
|
6
|
-
// respectively survive to a usable URL, and `cite` is a display string, not a fallback ("2 answers ·
|
|
7
|
-
// 2 years ago"). Brave hands back the real href. It also runs its own index rather than reselling
|
|
8
|
-
// Bing, so it isn't correlated with the engine most likely to block us next. See #235.
|
|
9
|
-
const SEARCH_URL = 'https://search.brave.com/search?q=';
|
|
10
|
-
const OWN_HOSTS = /(^|\.)(brave\.com|search\.brave\.com)$/;
|
|
11
|
-
// Brave ends some result anchors with a date line ("May 8, 2026", "3 days ago"), which the
|
|
12
|
-
// last-line rule below then reported as the result's title.
|
|
13
|
-
export const DATE_LINE = /^(?:(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\.? \d{1,2},? \d{4}|\d+ (?:second|minute|hour|day|week|month|year)s? ago)$/i;
|
|
14
|
-
// Deliberately structure-agnostic: every visible link, filtered and deduped. No result-card
|
|
15
|
-
// selectors, so a SERP redesign can't silently empty the results the way class-name scraping does.
|
|
16
|
-
// The snippet walks up from the anchor until a container holds meaningfully more text than the
|
|
17
|
-
// title, which needs no knowledge of the markup either.
|
|
18
|
-
function extractionScript(maxResults) {
|
|
19
|
-
return `(() => {
|
|
20
|
-
const clean = s => (s || '').replace(/\\s+/g, ' ').trim();
|
|
21
|
-
const visible = el => {
|
|
22
|
-
const r = el.getBoundingClientRect();
|
|
23
|
-
const st = getComputedStyle(el);
|
|
24
|
-
return r.width > 0 && r.height > 0 && st.display !== 'none' && st.visibility !== 'hidden';
|
|
25
|
-
};
|
|
26
|
-
const own = ${OWN_HOSTS.toString()};
|
|
27
|
-
// A result anchor's innerText is "SiteName / breadcrumb › path / actual title" on separate lines.
|
|
28
|
-
// The last line is the title; the earlier ones are chrome that would otherwise be fed to the model
|
|
29
|
-
// as part of it. No class names involved, so a redesign degrades this to "whole text", not to junk.
|
|
30
|
-
const dateLine = ${DATE_LINE.toString()};
|
|
31
|
-
const titleOf = a => {
|
|
32
|
-
const lines = (a.innerText || '').split('\\n').map(clean).filter(Boolean);
|
|
33
|
-
const named = lines.filter(l => !dateLine.test(l));
|
|
34
|
-
return named.length ? named[named.length - 1] : '';
|
|
35
|
-
};
|
|
36
|
-
// The container repeats the anchor's own text before the description; removing it stops every
|
|
37
|
-
// snippet from opening with a copy of the title it sits under.
|
|
38
|
-
const snippetFor = (a, title) => {
|
|
39
|
-
const anchorText = clean(a.innerText || '');
|
|
40
|
-
let node = a.parentElement;
|
|
41
|
-
for (let depth = 0; node && depth < 4; depth++, node = node.parentElement) {
|
|
42
|
-
// Stop before climbing into a container that groups several results, or the snippet picks up
|
|
43
|
-
// the *next* result's title. A block holding many links is a group, not one result's body.
|
|
44
|
-
if (node.querySelectorAll('a[href]').length > 3) break;
|
|
45
|
-
const full = clean(node.innerText || '');
|
|
46
|
-
if (full.length <= anchorText.length + 40) continue;
|
|
47
|
-
const body = clean(full.split(anchorText).join(' ').split(title).join(' '));
|
|
48
|
-
if (body.length >= 20) return body.slice(0, 300);
|
|
49
|
-
}
|
|
50
|
-
return '';
|
|
51
|
-
};
|
|
52
|
-
const seen = new Set();
|
|
53
|
-
const perHost = new Map();
|
|
54
|
-
const results = [];
|
|
55
|
-
for (const a of document.querySelectorAll('a[href]')) {
|
|
56
|
-
if (results.length >= ${maxResults}) break;
|
|
57
|
-
if (!visible(a)) continue;
|
|
58
|
-
const title = titleOf(a);
|
|
59
|
-
if (title.length < 8) continue;
|
|
60
|
-
let u;
|
|
61
|
-
try { u = new URL(a.href); } catch { continue; }
|
|
62
|
-
if (!/^https?:$/.test(u.protocol)) continue;
|
|
63
|
-
if (own.test(u.hostname)) continue;
|
|
64
|
-
const key = u.hostname + u.pathname;
|
|
65
|
-
if (seen.has(key)) continue;
|
|
66
|
-
// A result with a nested sub-link cluster (issues, discussions) contributes a run of tightly
|
|
67
|
-
// packed anchors from one host in DOM order, which crowds out every lower-ranked result. Two
|
|
68
|
-
// per host keeps that from turning eight slots into one site's sitemap.
|
|
69
|
-
const used = perHost.get(u.hostname) || 0;
|
|
70
|
-
if (used >= 2) continue;
|
|
71
|
-
perHost.set(u.hostname, used + 1);
|
|
72
|
-
seen.add(key);
|
|
73
|
-
results.push({ title: title.slice(0, 180), url: u.href, snippet: snippetFor(a, title) });
|
|
74
|
-
}
|
|
75
|
-
return JSON.stringify({
|
|
76
|
-
results,
|
|
77
|
-
anchors: document.querySelectorAll('a[href]').length,
|
|
78
|
-
blocked: /verifying you|not a bot|unusual traffic|are you a robot|verify you are human|complete the security check|traditional captcha/i
|
|
79
|
-
.test(document.body ? document.body.innerText : ''),
|
|
80
|
-
});
|
|
81
|
-
})()`;
|
|
82
|
-
}
|
|
83
|
-
// A real SERP carries dozens of links even when it matches nothing. A page with almost none is an
|
|
84
|
-
// interstitial — a challenge, a consent wall, an error. This is the structural half of the check on
|
|
85
|
-
// purpose: the phrase list above cannot be complete (the challenge that prompted it says "Verifying
|
|
86
|
-
// you're not a bot", which none of the obvious phrasings would have caught), so the shape of the
|
|
87
|
-
// page has to carry the verdict when the wording is unfamiliar.
|
|
88
|
-
const MIN_SERP_ANCHORS = 10;
|
|
89
|
-
// A bot check is a gate, not noise: it does not clear on its own, and a solve persists on the
|
|
90
|
-
// profile (observed on a real run — one manual solve, served normally since; #238). So on a
|
|
91
|
-
// challenge the provider does the one thing that can work — puts the window in front of the user
|
|
92
|
-
// and waits for the page to turn into a SERP — rather than retrying with backoff against a wall.
|
|
93
|
-
// The wait is bounded because nobody may be at the desk; past it the search fails the turn the
|
|
94
|
-
// way it did before, with the tab left open and raised so the check can still be completed later.
|
|
95
|
-
const CHALLENGE_WAIT_MS = 120_000;
|
|
96
|
-
const CHALLENGE_POLL_MS = 1_000;
|
|
97
|
-
export class CdpSearchProvider {
|
|
98
|
-
host;
|
|
99
|
-
waitMs;
|
|
100
|
-
pollMs;
|
|
101
|
-
// One challenge at a time. Parallel searches in a turn are all refused together, and the solve
|
|
102
|
-
// is profile-wide: the first to hit it raises its own tab and waits, the rest wait on the same
|
|
103
|
-
// promise and then simply reload — a second raised window would compete for the user's one solve.
|
|
104
|
-
challenge;
|
|
105
|
-
constructor(host = new ChromeHost(), opts = {}) {
|
|
106
|
-
this.host = host;
|
|
107
|
-
this.waitMs = opts.challengeWaitMs ?? CHALLENGE_WAIT_MS;
|
|
108
|
-
this.pollMs = opts.challengePollMs ?? CHALLENGE_POLL_MS;
|
|
109
|
-
}
|
|
110
|
-
async search(query, opts = {}) {
|
|
111
|
-
const max = opts.maxResults ?? 8;
|
|
112
|
-
const url = SEARCH_URL + encodeURIComponent(query);
|
|
113
|
-
const tab = await this.host.newTab();
|
|
114
|
-
// Set when this tab is showing an unsolved check: closing it would take the challenge away
|
|
115
|
-
// from the user who was just told to complete it.
|
|
116
|
-
let holdOpen = false;
|
|
117
|
-
try {
|
|
118
|
-
await tab.navigate(url);
|
|
119
|
-
let data = parseExtraction(await tab.evaluate(extractionScript(max)));
|
|
120
|
-
if (interstitial(data)) {
|
|
121
|
-
const owner = !this.challenge;
|
|
122
|
-
if (owner) {
|
|
123
|
-
this.challenge = this.awaitSolve(tab, max, opts).finally(() => {
|
|
124
|
-
this.challenge = undefined;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
await this.challenge;
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
holdOpen = owner;
|
|
132
|
-
throw e;
|
|
133
|
-
}
|
|
134
|
-
// The solved tab has usually landed on the SERP by itself; the reload is for the tabs that
|
|
135
|
-
// waited on it, which still show the check they never got to answer.
|
|
136
|
-
await tab.navigate(url);
|
|
137
|
-
data = parseExtraction(await tab.evaluate(extractionScript(max)));
|
|
138
|
-
// Passed the check and still walled: not a challenge any more, and not something waiting
|
|
139
|
-
// longer can fix. Report it as the wall it is.
|
|
140
|
-
if (interstitial(data))
|
|
141
|
-
throw unavailable(data);
|
|
142
|
-
}
|
|
143
|
-
const results = (data.results ?? [])
|
|
144
|
-
.filter(r => r.url && r.url.trim().length > 0)
|
|
145
|
-
.slice(0, max)
|
|
146
|
-
.map(r => ({
|
|
147
|
-
title: r.title ?? '',
|
|
148
|
-
url: r.url,
|
|
149
|
-
snippet: r.snippet ?? '',
|
|
150
|
-
source: 'brave',
|
|
151
|
-
}));
|
|
152
|
-
debugLog(`[cdp] "${query}" -> ${results.length} result(s), ${data.anchors ?? 0} links on page`);
|
|
153
|
-
return results;
|
|
154
|
-
}
|
|
155
|
-
finally {
|
|
156
|
-
// The tab closes even when extraction threw; leaking one per failed search would grow the
|
|
157
|
-
// browser's memory for the rest of the session.
|
|
158
|
-
if (!holdOpen)
|
|
159
|
-
await tab.close();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
// Raise the tab and poll it until the page stops looking like an interstitial. A failed probe
|
|
163
|
-
// (the page is mid-navigation after the solve, or the user closed the tab) is not a verdict;
|
|
164
|
-
// the deadline is. The window goes back down only on success: on timeout it stays where the user
|
|
165
|
-
// will find it, with the unsolved check on it.
|
|
166
|
-
async awaitSolve(tab, max, opts) {
|
|
167
|
-
await tab.show();
|
|
168
|
-
opts.onChallenge?.('raised');
|
|
169
|
-
debugLog('[cdp] bot check: window raised, waiting for the user');
|
|
170
|
-
const deadline = Date.now() + this.waitMs;
|
|
171
|
-
let last;
|
|
172
|
-
for (;;) {
|
|
173
|
-
await sleep(this.pollMs);
|
|
174
|
-
try {
|
|
175
|
-
last = parseExtraction(await tab.evaluate(extractionScript(max)));
|
|
176
|
-
if (!interstitial(last))
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
catch {
|
|
180
|
-
/* mid-navigation; keep polling */
|
|
181
|
-
}
|
|
182
|
-
if (Date.now() >= deadline) {
|
|
183
|
-
debugLog('[cdp] bot check: not completed within the wait');
|
|
184
|
-
throw unavailable(last ?? { blocked: true }, true);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
debugLog('[cdp] bot check cleared');
|
|
188
|
-
await tab.hide();
|
|
189
|
-
opts.onChallenge?.('cleared');
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// Same principle as #236: a search the harness could not serve has to say so. A CAPTCHA reported
|
|
193
|
-
// as an empty result set reads to the model as a bad query, and it rewords and retries against a
|
|
194
|
-
// wall that will refuse every variant identically.
|
|
195
|
-
function interstitial(data) {
|
|
196
|
-
return (!!data.blocked || ((data.results ?? []).length === 0 && (data.anchors ?? 0) < MIN_SERP_ANCHORS));
|
|
197
|
-
}
|
|
198
|
-
function unavailable(data, timedOut = false) {
|
|
199
|
-
const message = data.blocked
|
|
200
|
-
? 'the search page served a bot check instead of results'
|
|
201
|
-
: `the search page returned no result list (${data.anchors ?? 0} links on the page) — likely a challenge or interstitial`;
|
|
202
|
-
// The remedy is for the user (the model cannot click a checkbox): where the check is, and that
|
|
203
|
-
// one solve is enough. Only on a timeout — the other way here is a wall the check didn't explain.
|
|
204
|
-
return new SearchUnavailableError(message, timedOut
|
|
205
|
-
? 'The search browser was challenged and the check was not completed in time. Its window is open on the challenge — complete the check once (it persists for that profile), then ask again.'
|
|
206
|
-
: undefined);
|
|
207
|
-
}
|
|
208
|
-
function sleep(ms) {
|
|
209
|
-
return new Promise(r => setTimeout(r, ms));
|
|
210
|
-
}
|
|
211
|
-
function parseExtraction(raw) {
|
|
212
|
-
if (typeof raw !== 'string') {
|
|
213
|
-
// Runtime.evaluate returning a non-string means the page never ran our script — a navigation
|
|
214
|
-
// failure or a detached target, not an answered search.
|
|
215
|
-
throw new Error('the search page returned nothing to extract');
|
|
216
|
-
}
|
|
217
|
-
try {
|
|
218
|
-
return JSON.parse(raw);
|
|
219
|
-
}
|
|
220
|
-
catch {
|
|
221
|
-
throw new Error('could not parse results from the search page');
|
|
222
|
-
}
|
|
223
|
-
}
|
package/dist/search/searxng.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { debugLog } from '../debug.js';
|
|
2
|
-
import { rootMessage } from '../tools/_net.js';
|
|
3
|
-
import { SearchUnavailableError } from './types.js';
|
|
4
|
-
import { WEB_USER_AGENT } from '../version.js';
|
|
5
|
-
const REQUEST_TIMEOUT_MS = 10_000;
|
|
6
|
-
export class SearxngProvider {
|
|
7
|
-
baseUrl;
|
|
8
|
-
constructor(baseUrl) {
|
|
9
|
-
this.baseUrl = baseUrl;
|
|
10
|
-
}
|
|
11
|
-
async search(query, opts = {}) {
|
|
12
|
-
const url = new URL('/search', ensureTrailingSlash(this.baseUrl));
|
|
13
|
-
url.searchParams.set('q', query);
|
|
14
|
-
url.searchParams.set('format', 'json');
|
|
15
|
-
const controller = new AbortController();
|
|
16
|
-
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
17
|
-
try {
|
|
18
|
-
let res;
|
|
19
|
-
try {
|
|
20
|
-
res = await fetch(url.toString(), {
|
|
21
|
-
headers: { Accept: 'application/json', 'User-Agent': WEB_USER_AGENT },
|
|
22
|
-
signal: controller.signal,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
// The instance itself could not be reached — refused, unresolvable, timed out. That is a
|
|
27
|
-
// property of the provider, not the query: there is one host, and rewording the query
|
|
28
|
-
// does not bring it up. Raised as unavailable so the tool latches the turn instead of
|
|
29
|
-
// letting the model spend three searches finding out the same thing three times (#392).
|
|
30
|
-
const detail = controller.signal.aborted
|
|
31
|
-
? `no answer in ${REQUEST_TIMEOUT_MS / 1000}s`
|
|
32
|
-
: rootMessage(e);
|
|
33
|
-
throw new SearchUnavailableError(`SearXNG at ${this.baseUrl} could not be reached (${detail})`, `SearXNG at ${this.baseUrl} did not answer (${detail}). Check that the instance is running and reachable, or set REIKA_CDP_SEARCH=1 (with Chrome installed) to search through Chrome instead.`);
|
|
34
|
-
}
|
|
35
|
-
if (!res.ok) {
|
|
36
|
-
throw new Error(`SearXNG ${res.status} ${res.statusText}`);
|
|
37
|
-
}
|
|
38
|
-
const data = (await res.json());
|
|
39
|
-
const max = opts.maxResults ?? 8;
|
|
40
|
-
const results = (data.results ?? []).slice(0, max).map(r => ({
|
|
41
|
-
title: r.title,
|
|
42
|
-
url: r.url,
|
|
43
|
-
snippet: r.content ?? '',
|
|
44
|
-
source: r.engine,
|
|
45
|
-
}));
|
|
46
|
-
const down = formatUnresponsive(data.unresponsive_engines);
|
|
47
|
-
if (down)
|
|
48
|
-
debugLog(`[searxng] unresponsive engines: ${down} (results=${results.length})`);
|
|
49
|
-
// An empty result set with dead engines is a failed search, not an answered one. Reporting it
|
|
50
|
-
// as "no results" tells the model its *query* was bad, so it rewords and tries again — a spiral
|
|
51
|
-
// that burns the turn's search budget while every attempt is refused for the same reason.
|
|
52
|
-
// Raising here routes it through the tool's failure path, where the cause is stated instead.
|
|
53
|
-
if (results.length === 0 && down) {
|
|
54
|
-
throw new SearchUnavailableError(`every SearXNG engine was unavailable (${down})`, 'Every engine this SearXNG instance tried refused the request. REIKA_CDP_SEARCH=1 (with Chrome installed) drives a real Chrome instead, which keeps being served where a bare HTTP client is blocked.');
|
|
55
|
-
}
|
|
56
|
-
return results;
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
clearTimeout(timer);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Defensive about shape: the entries are [engine, reason] pairs today, but a bare engine name or a
|
|
64
|
-
// longer tuple has to degrade to a readable line rather than "[object Object]" in the model's view.
|
|
65
|
-
function formatUnresponsive(entries) {
|
|
66
|
-
if (!Array.isArray(entries) || entries.length === 0)
|
|
67
|
-
return '';
|
|
68
|
-
return entries
|
|
69
|
-
.map(entry => {
|
|
70
|
-
if (typeof entry === 'string')
|
|
71
|
-
return entry;
|
|
72
|
-
if (!Array.isArray(entry))
|
|
73
|
-
return '';
|
|
74
|
-
const [engine, reason] = entry;
|
|
75
|
-
const name = typeof engine === 'string' ? engine : '';
|
|
76
|
-
const why = typeof reason === 'string' ? reason : '';
|
|
77
|
-
if (!name)
|
|
78
|
-
return '';
|
|
79
|
-
return why ? `${name}: ${why}` : name;
|
|
80
|
-
})
|
|
81
|
-
.filter(Boolean)
|
|
82
|
-
.join('; ');
|
|
83
|
-
}
|
|
84
|
-
function ensureTrailingSlash(url) {
|
|
85
|
-
return url.endsWith('/') ? url : url + '/';
|
|
86
|
-
}
|
package/dist/search/types.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// A failure that is a property of the PROVIDER, not the query: no browser to drive, a bot check,
|
|
2
|
-
// every upstream engine refused. Re-querying cannot succeed, so the tool latches it for the turn
|
|
3
|
-
// instead of letting the model reword against a wall that refuses every variant identically.
|
|
4
|
-
// Distinguished from an ordinary throw, which stays query-level (one unparseable page, say) and
|
|
5
|
-
// leaves the next search free to run.
|
|
6
|
-
export class SearchUnavailableError extends Error {
|
|
7
|
-
// Optional user-facing next step. Kept separate from `message` because the two have different
|
|
8
|
-
// audiences: the message goes to the model (stop searching), the remedy to the user (here is the
|
|
9
|
-
// switch to flip) — and the model cannot set an environment variable, so telling it about one is
|
|
10
|
-
// context noise it can only ignore.
|
|
11
|
-
remedy;
|
|
12
|
-
constructor(message, remedy) {
|
|
13
|
-
super(message);
|
|
14
|
-
this.name = 'SearchUnavailableError';
|
|
15
|
-
this.remedy = remedy;
|
|
16
|
-
}
|
|
17
|
-
}
|