reasonix 0.30.1 → 0.30.3
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/README.md +48 -3
- package/README.zh-CN.md +3 -3
- package/dashboard/dist/app.js +1258 -793
- package/dashboard/dist/app.js.map +1 -1
- package/dist/cli/index.js +1278 -1184
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +107 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -7
package/dist/index.d.ts
CHANGED
|
@@ -1308,9 +1308,15 @@ interface WebFetchOptions {
|
|
|
1308
1308
|
interface WebSearchOptions {
|
|
1309
1309
|
topK?: number;
|
|
1310
1310
|
signal?: AbortSignal;
|
|
1311
|
+
/** Backend engine: "mojeek" (scrapes Mojeek HTML) or "searxng" (self-hosted SearXNG JSON API). */
|
|
1312
|
+
engine?: "mojeek" | "searxng";
|
|
1313
|
+
/** Base URL for SearXNG. Default http://localhost:8080. */
|
|
1314
|
+
endpoint?: string;
|
|
1311
1315
|
}
|
|
1312
1316
|
/** Distinguishes "truly 0 results" from "layout changed / blocked" so callers can tell. */
|
|
1313
1317
|
declare function webSearch(query: string, opts?: WebSearchOptions): Promise<SearchResult[]>;
|
|
1318
|
+
/** Parse SearXNG HTML search results using node-html-parser. */
|
|
1319
|
+
declare function parseSearxngHtmlResults(html: string): SearchResult[];
|
|
1314
1320
|
/** Title-anchor + snippet-paragraph passes paired positionally — robust to attribute reorder. */
|
|
1315
1321
|
declare function parseMojeekResults(html: string): SearchResult[];
|
|
1316
1322
|
declare function webFetch(url: string, opts?: WebFetchOptions): Promise<PageContent>;
|
|
@@ -1320,6 +1326,10 @@ interface WebToolsOptions {
|
|
|
1320
1326
|
defaultTopK?: number;
|
|
1321
1327
|
/** Byte cap for `web_fetch` extracted text. */
|
|
1322
1328
|
maxFetchChars?: number;
|
|
1329
|
+
/** Backend engine: "mojeek" (default, scrapes Mojeek) or "searxng" (self-hosted SearXNG). */
|
|
1330
|
+
webSearchEngine?: "mojeek" | "searxng";
|
|
1331
|
+
/** Base URL for SearXNG (default http://localhost:8080). */
|
|
1332
|
+
webSearchEndpoint?: string;
|
|
1323
1333
|
}
|
|
1324
1334
|
declare function registerWebTools(registry: ToolRegistry, opts?: WebToolsOptions): ToolRegistry;
|
|
1325
1335
|
declare function formatSearchResults(query: string, results: SearchResult[]): string;
|
|
@@ -1341,6 +1351,8 @@ interface SessionMeta {
|
|
|
1341
1351
|
turnCount?: number;
|
|
1342
1352
|
/** Absolute path of the workspace root the session was created/used in. */
|
|
1343
1353
|
workspace?: string;
|
|
1354
|
+
/** Wallet currency at last save — used to format `totalCostUsd` in the picker without re-fetching balance. */
|
|
1355
|
+
balanceCurrency?: string;
|
|
1344
1356
|
}
|
|
1345
1357
|
declare function sessionsDir(): string;
|
|
1346
1358
|
declare function sessionPath(name: string): string;
|
|
@@ -2011,6 +2023,10 @@ interface ReasonixConfig {
|
|
|
2011
2023
|
session?: string | null;
|
|
2012
2024
|
setupCompleted?: boolean;
|
|
2013
2025
|
search?: boolean;
|
|
2026
|
+
/** Web search engine backend: "mojeek" (default, scrapes Mojeek) or "searxng" (self-hosted SearXNG). */
|
|
2027
|
+
webSearchEngine?: "mojeek" | "searxng";
|
|
2028
|
+
/** Base URL for SearXNG instance (default http://localhost:8080). */
|
|
2029
|
+
webSearchEndpoint?: string;
|
|
2014
2030
|
projects?: {
|
|
2015
2031
|
[absoluteRootDir: string]: {
|
|
2016
2032
|
shellAllowed?: string[];
|
|
@@ -2167,4 +2183,4 @@ declare function aggregateUsage(records: UsageRecord[], opts?: AggregateOptions)
|
|
|
2167
2183
|
/** File-size helper for the stats header — "1.2 MB" etc. Returns "" if missing. */
|
|
2168
2184
|
declare function formatLogSize(path?: string): string;
|
|
2169
2185
|
|
|
2170
|
-
export { AT_MENTION_PATTERN, AT_PICKER_PREFIX, type AggregateOptions, AppendOnlyLog, type AppendUsageInput, type ApplyResult, type ApplyStatus, type AtMentionExpansion, type AtMentionOptions, type BranchOptions, type BranchProgress, type BranchResult, type BranchSample, type BranchSelector, type BranchSummary, type BridgeOptions, type BridgeResult, CODE_SYSTEM_PROMPT, CacheFirstLoop, type CacheFirstLoopOptions, type CallToolResult, type ChatMessage, type ChatResponse, type ChoiceOption, ChoiceRequestedError, type ChoiceToolOptions, type CodeSystemPromptOptions, DEFAULT_AT_MENTION_MAX_BYTES, DEFAULT_MAX_RESULT_CHARS, DEFAULT_MAX_RESULT_TOKENS, DEFAULT_PICKER_IGNORE_DIRS, DeepSeekClient, type DeepSeekClientOptions, type RenderOptions as DiffRenderOptions, type DiffReport, type DiffSide, type EditBlock, type EditSnapshot, type EventRole, type FileWithStats, type FilesystemToolsOptions, type FlattenDecision, type FlattenOptions, type GetLatestVersionOptions, type GetPromptResult, HOOK_EVENTS, HOOK_SETTINGS_DIRNAME, HOOK_SETTINGS_FILENAME, type HarvestOptions, type HookConfig, type HookEvent, type HookOutcome, type HookPayload, type HookReport, type HookScope, type HookSettings, type HookSpawnInput, type HookSpawnResult, type HookSpawner, ImmutablePrefix, type ImmutablePrefixOptions, type InitializeResult, type InspectionReport, type JSONSchema, type JsonRpcMessage, type JsonRpcRequest, type JsonRpcResponse, LATEST_CACHE_TTL_MS, LATEST_FETCH_TIMEOUT_MS, type ListFilesOptions, type ListPromptsResult, type ListResourcesResult, type ListToolsResult, type LoadHookSettingsOptions, type LoopEvent, MCP_PROTOCOL_VERSION, MEMORY_INDEX_FILE, MEMORY_INDEX_MAX_CHARS, McpClient, type McpClientOptions, type McpContentBlock, type McpProgressHandler, type McpProgressInfo, type McpPrompt, type McpPromptArgument, type McpPromptMessage, type McpPromptResourceBlock, type McpResource, type McpResourceContents, type McpResourceContentsBlob, type McpResourceContentsText, type McpSpec, type McpTool, type McpToolSchema, type McpTransport, type MemoryEntry, type MemoryScope, MemoryStore, type MemoryStoreOptions, type MemoryToolsOptions, type MemoryType, type WriteInput as MemoryWriteInput, NeedsConfirmationError, PROJECT_MEMORY_FILE, PROJECT_MEMORY_MAX_CHARS, type PageContent, type PickerCandidate, PlanProposedError, PlanRevisionProposedError, type PlanStep, type PlanStepRisk, type PlanToolOptions, type ProgressNotificationParams, type ProjectMemory, type RankPickerOptions, type ReadResourceResult, type ReadTranscriptResult, type ReasonixConfig, type ReconfigurableOptions, type RepairReport, type ReplayStats, type ResolvedHook, type RetryInfo, type RetryOptions, type Role, type RunCommandResult, type RunHooksOptions, type ScavengeOptions, type ScavengeResult, type SearchResult, type SectionResult, type SessionInfo, SessionStats, type SessionSummary, type ShellToolsOptions, type SseMcpSpec, SseTransport, type SseTransportOptions, type StdioMcpSpec, StdioTransport, type StdioTransportOptions, type StepCompletion, StormBreaker, type StreamChunk, type StreamableHttpMcpSpec, StreamableHttpTransport, type StreamableHttpTransportOptions, type SubagentEvent, type SubagentSink, type SubagentToolOptions, type ToolCall, type ToolCallContext, ToolCallRepair, type ToolCallRepairOptions, type ToolDefinition, type ToolFunctionSpec, ToolRegistry, type ToolSpec, type TranscriptMeta, type TranscriptRecord, type TruncationRepairResult, type TurnPair, type TurnStats, type TypedPlanState, USER_MEMORY_DIR, Usage, type UsageAggregate, type UsageBucket, type UsageRecord, VERSION, VolatileScratch, type WebFetchOptions, type WebSearchOptions, type WebToolsOptions, aggregateBranchUsage, aggregateUsage, analyzeSchema, appendSessionMessage, appendUsage, applyEditBlock, applyEditBlocks, applyMemoryStack, applyProjectMemory, applyUserMemory, bridgeMcpTools, bucketCacheHitRatio, bucketSavingsFraction, claudeEquivalentCost, codeSystemPrompt, compareVersions, computeReplayStats, costUsd, decideOutcome, defaultConfigPath, defaultSelector, defaultUsageLogPath, deleteSession, detectAtPicker, detectShellOperator, diffTranscripts, emptyPlanState, expandAtMentions, fetchWithRetry, fixToolCallPairing, flattenMcpResult, flattenSchema, forkRegistryExcluding, formatCommandResult, formatHookOutcomeMessage, formatLogSize, formatLoopError, formatSearchResults, getLatestVersion, globalSettingsPath, harvest, healLoadedMessages, healLoadedMessagesByTokens, htmlToText, injectPowerShellUtf8, inputCostUsd, inspectMcpServer, isAllowed, isJsonRpcError, isNpxInstall, isPlanStateEmpty, isPlausibleKey, listFilesSync, listFilesWithStatsAsync, listFilesWithStatsSync, listSessions, loadApiKey, loadDotenv, loadHooks, loadSessionMessages, matchesTool, memoryEnabled, nestArguments, openTranscriptFile, outputCostUsd, parseEditBlocks, parseMcpSpec, parseMojeekResults, parseTranscript, prepareSpawn, projectHash, projectSettingsPath, quoteForCmdExe, rankPickerCandidates, readConfig, readProjectMemory, readTranscript, readUsageLog, recordFromLoopEvent, redactKey, registerChoiceTool, registerFilesystemTools, registerMemoryTools, registerPlanTool, registerShellTools, registerSubagentTool, registerWebTools, renderMarkdown as renderDiffMarkdown, renderSummaryTable as renderDiffSummary, repairTruncatedJson, replayFromFile, resolveExecutable, restoreSnapshots, runBranches, runCommand, runHooks, sanitizeMemoryName, sanitizeName as sanitizeSessionName, saveApiKey, scavengeToolCalls, sessionPath, sessionsDir, similarity, snapshotBeforeEdits, stripHallucinatedToolMarkup, tokenizeCommand, truncateForModel, truncateForModelByTokens, webFetch, webSearch, withUtf8Codepage, writeConfig, writeMeta, writeRecord };
|
|
2186
|
+
export { AT_MENTION_PATTERN, AT_PICKER_PREFIX, type AggregateOptions, AppendOnlyLog, type AppendUsageInput, type ApplyResult, type ApplyStatus, type AtMentionExpansion, type AtMentionOptions, type BranchOptions, type BranchProgress, type BranchResult, type BranchSample, type BranchSelector, type BranchSummary, type BridgeOptions, type BridgeResult, CODE_SYSTEM_PROMPT, CacheFirstLoop, type CacheFirstLoopOptions, type CallToolResult, type ChatMessage, type ChatResponse, type ChoiceOption, ChoiceRequestedError, type ChoiceToolOptions, type CodeSystemPromptOptions, DEFAULT_AT_MENTION_MAX_BYTES, DEFAULT_MAX_RESULT_CHARS, DEFAULT_MAX_RESULT_TOKENS, DEFAULT_PICKER_IGNORE_DIRS, DeepSeekClient, type DeepSeekClientOptions, type RenderOptions as DiffRenderOptions, type DiffReport, type DiffSide, type EditBlock, type EditSnapshot, type EventRole, type FileWithStats, type FilesystemToolsOptions, type FlattenDecision, type FlattenOptions, type GetLatestVersionOptions, type GetPromptResult, HOOK_EVENTS, HOOK_SETTINGS_DIRNAME, HOOK_SETTINGS_FILENAME, type HarvestOptions, type HookConfig, type HookEvent, type HookOutcome, type HookPayload, type HookReport, type HookScope, type HookSettings, type HookSpawnInput, type HookSpawnResult, type HookSpawner, ImmutablePrefix, type ImmutablePrefixOptions, type InitializeResult, type InspectionReport, type JSONSchema, type JsonRpcMessage, type JsonRpcRequest, type JsonRpcResponse, LATEST_CACHE_TTL_MS, LATEST_FETCH_TIMEOUT_MS, type ListFilesOptions, type ListPromptsResult, type ListResourcesResult, type ListToolsResult, type LoadHookSettingsOptions, type LoopEvent, MCP_PROTOCOL_VERSION, MEMORY_INDEX_FILE, MEMORY_INDEX_MAX_CHARS, McpClient, type McpClientOptions, type McpContentBlock, type McpProgressHandler, type McpProgressInfo, type McpPrompt, type McpPromptArgument, type McpPromptMessage, type McpPromptResourceBlock, type McpResource, type McpResourceContents, type McpResourceContentsBlob, type McpResourceContentsText, type McpSpec, type McpTool, type McpToolSchema, type McpTransport, type MemoryEntry, type MemoryScope, MemoryStore, type MemoryStoreOptions, type MemoryToolsOptions, type MemoryType, type WriteInput as MemoryWriteInput, NeedsConfirmationError, PROJECT_MEMORY_FILE, PROJECT_MEMORY_MAX_CHARS, type PageContent, type PickerCandidate, PlanProposedError, PlanRevisionProposedError, type PlanStep, type PlanStepRisk, type PlanToolOptions, type ProgressNotificationParams, type ProjectMemory, type RankPickerOptions, type ReadResourceResult, type ReadTranscriptResult, type ReasonixConfig, type ReconfigurableOptions, type RepairReport, type ReplayStats, type ResolvedHook, type RetryInfo, type RetryOptions, type Role, type RunCommandResult, type RunHooksOptions, type ScavengeOptions, type ScavengeResult, type SearchResult, type SectionResult, type SessionInfo, SessionStats, type SessionSummary, type ShellToolsOptions, type SseMcpSpec, SseTransport, type SseTransportOptions, type StdioMcpSpec, StdioTransport, type StdioTransportOptions, type StepCompletion, StormBreaker, type StreamChunk, type StreamableHttpMcpSpec, StreamableHttpTransport, type StreamableHttpTransportOptions, type SubagentEvent, type SubagentSink, type SubagentToolOptions, type ToolCall, type ToolCallContext, ToolCallRepair, type ToolCallRepairOptions, type ToolDefinition, type ToolFunctionSpec, ToolRegistry, type ToolSpec, type TranscriptMeta, type TranscriptRecord, type TruncationRepairResult, type TurnPair, type TurnStats, type TypedPlanState, USER_MEMORY_DIR, Usage, type UsageAggregate, type UsageBucket, type UsageRecord, VERSION, VolatileScratch, type WebFetchOptions, type WebSearchOptions, type WebToolsOptions, aggregateBranchUsage, aggregateUsage, analyzeSchema, appendSessionMessage, appendUsage, applyEditBlock, applyEditBlocks, applyMemoryStack, applyProjectMemory, applyUserMemory, bridgeMcpTools, bucketCacheHitRatio, bucketSavingsFraction, claudeEquivalentCost, codeSystemPrompt, compareVersions, computeReplayStats, costUsd, decideOutcome, defaultConfigPath, defaultSelector, defaultUsageLogPath, deleteSession, detectAtPicker, detectShellOperator, diffTranscripts, emptyPlanState, expandAtMentions, fetchWithRetry, fixToolCallPairing, flattenMcpResult, flattenSchema, forkRegistryExcluding, formatCommandResult, formatHookOutcomeMessage, formatLogSize, formatLoopError, formatSearchResults, getLatestVersion, globalSettingsPath, harvest, healLoadedMessages, healLoadedMessagesByTokens, htmlToText, injectPowerShellUtf8, inputCostUsd, inspectMcpServer, isAllowed, isJsonRpcError, isNpxInstall, isPlanStateEmpty, isPlausibleKey, listFilesSync, listFilesWithStatsAsync, listFilesWithStatsSync, listSessions, loadApiKey, loadDotenv, loadHooks, loadSessionMessages, matchesTool, memoryEnabled, nestArguments, openTranscriptFile, outputCostUsd, parseEditBlocks, parseMcpSpec, parseMojeekResults, parseSearxngHtmlResults, parseTranscript, prepareSpawn, projectHash, projectSettingsPath, quoteForCmdExe, rankPickerCandidates, readConfig, readProjectMemory, readTranscript, readUsageLog, recordFromLoopEvent, redactKey, registerChoiceTool, registerFilesystemTools, registerMemoryTools, registerPlanTool, registerShellTools, registerSubagentTool, registerWebTools, renderMarkdown as renderDiffMarkdown, renderSummaryTable as renderDiffSummary, repairTruncatedJson, replayFromFile, resolveExecutable, restoreSnapshots, runBranches, runCommand, runHooks, sanitizeMemoryName, sanitizeName as sanitizeSessionName, saveApiKey, scavengeToolCalls, sessionPath, sessionsDir, similarity, snapshotBeforeEdits, stripHallucinatedToolMarkup, tokenizeCommand, truncateForModel, truncateForModelByTokens, webFetch, webSearch, withUtf8Codepage, writeConfig, writeMeta, writeRecord };
|
package/dist/index.js
CHANGED
|
@@ -5883,6 +5883,16 @@ function loadApiKey(path2 = defaultConfigPath()) {
|
|
|
5883
5883
|
if (process.env.DEEPSEEK_API_KEY) return process.env.DEEPSEEK_API_KEY;
|
|
5884
5884
|
return readConfig(path2).apiKey;
|
|
5885
5885
|
}
|
|
5886
|
+
function webSearchEngine(path2 = defaultConfigPath()) {
|
|
5887
|
+
const cfg = readConfig(path2).webSearchEngine;
|
|
5888
|
+
if (cfg === "searxng") return "searxng";
|
|
5889
|
+
return "mojeek";
|
|
5890
|
+
}
|
|
5891
|
+
function webSearchEndpoint(path2 = defaultConfigPath()) {
|
|
5892
|
+
const cfg = readConfig(path2).webSearchEndpoint;
|
|
5893
|
+
if (cfg && typeof cfg === "string") return cfg;
|
|
5894
|
+
return "http://localhost:8080";
|
|
5895
|
+
}
|
|
5886
5896
|
function saveApiKey(key, path2 = defaultConfigPath()) {
|
|
5887
5897
|
const cfg = readConfig(path2);
|
|
5888
5898
|
cfg.apiKey = key.trim();
|
|
@@ -7290,6 +7300,12 @@ var FETCH_MAX_BYTES = 10 * 1024 * 1024;
|
|
|
7290
7300
|
var USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
7291
7301
|
var MOJEEK_ENDPOINT = "https://www.mojeek.com/search";
|
|
7292
7302
|
async function webSearch(query, opts = {}) {
|
|
7303
|
+
if (opts.engine === "searxng") {
|
|
7304
|
+
return searchSearxng(query, opts);
|
|
7305
|
+
}
|
|
7306
|
+
return searchMojeek(query, opts);
|
|
7307
|
+
}
|
|
7308
|
+
async function searchMojeek(query, opts = {}) {
|
|
7293
7309
|
const topK = Math.max(1, Math.min(10, opts.topK ?? DEFAULT_TOPK));
|
|
7294
7310
|
const resp = await fetch(`${MOJEEK_ENDPOINT}?q=${encodeURIComponent(query)}`, {
|
|
7295
7311
|
headers: {
|
|
@@ -7314,6 +7330,90 @@ async function webSearch(query, opts = {}) {
|
|
|
7314
7330
|
}
|
|
7315
7331
|
return results;
|
|
7316
7332
|
}
|
|
7333
|
+
function normalizeSearxngEndpoint(raw) {
|
|
7334
|
+
let url;
|
|
7335
|
+
try {
|
|
7336
|
+
url = new URL(raw.includes("://") ? raw : `http://${raw}`);
|
|
7337
|
+
} catch {
|
|
7338
|
+
throw new Error(`web_search: invalid SearXNG endpoint "${raw}"`);
|
|
7339
|
+
}
|
|
7340
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
7341
|
+
throw new Error(`web_search: SearXNG endpoint must be http(s), got ${url.protocol}`);
|
|
7342
|
+
}
|
|
7343
|
+
return url.origin;
|
|
7344
|
+
}
|
|
7345
|
+
async function searchSearxng(query, opts = {}) {
|
|
7346
|
+
const topK = Math.max(1, Math.min(10, opts.topK ?? DEFAULT_TOPK));
|
|
7347
|
+
const baseUrl = normalizeSearxngEndpoint(opts.endpoint ?? "http://localhost:8080");
|
|
7348
|
+
const url = `${baseUrl}/search?format=html&q=${encodeURIComponent(query)}`;
|
|
7349
|
+
let resp;
|
|
7350
|
+
try {
|
|
7351
|
+
resp = await fetch(url, {
|
|
7352
|
+
headers: {
|
|
7353
|
+
"User-Agent": USER_AGENT,
|
|
7354
|
+
Accept: "text/html"
|
|
7355
|
+
},
|
|
7356
|
+
signal: opts.signal
|
|
7357
|
+
});
|
|
7358
|
+
} catch (err) {
|
|
7359
|
+
if (err instanceof TypeError && err.message.includes("fetch")) {
|
|
7360
|
+
throw new Error(
|
|
7361
|
+
`web_search: Cannot reach SearXNG server at ${opts.endpoint ?? "http://localhost:8080"}. Please install SearXNG (https://github.com/searxng/searxng) and start it (e.g. \`docker run -d -p 8080:8080 searxng/searxng\`), or switch to the default engine with /search-engine mojeek.`
|
|
7362
|
+
);
|
|
7363
|
+
}
|
|
7364
|
+
throw err;
|
|
7365
|
+
}
|
|
7366
|
+
if (!resp.ok) throw new Error(`web_search ${resp.status}`);
|
|
7367
|
+
const html = await resp.text();
|
|
7368
|
+
const results = parseSearxngHtmlResults(html).slice(0, topK);
|
|
7369
|
+
if (results.length === 0) {
|
|
7370
|
+
if (/no results found|did not match any documents/i.test(html)) return [];
|
|
7371
|
+
throw new Error(
|
|
7372
|
+
`web_search: 0 results but SearXNG response doesn't look like an empty results page (${html.length} chars)`
|
|
7373
|
+
);
|
|
7374
|
+
}
|
|
7375
|
+
return results;
|
|
7376
|
+
}
|
|
7377
|
+
function parseSearxngHtmlResults(html) {
|
|
7378
|
+
const root = parseHtml(html);
|
|
7379
|
+
const results = [];
|
|
7380
|
+
const articles = root.querySelectorAll("article.result, div.result");
|
|
7381
|
+
if (articles.length > 0) {
|
|
7382
|
+
for (const article of articles) {
|
|
7383
|
+
const link = article.querySelector("h3 a, h4 a, a[href^='http']");
|
|
7384
|
+
if (!link) continue;
|
|
7385
|
+
const href = link.getAttribute("href");
|
|
7386
|
+
if (!href) continue;
|
|
7387
|
+
const title = link.textContent.trim();
|
|
7388
|
+
if (!title) continue;
|
|
7389
|
+
let snippet = "";
|
|
7390
|
+
for (const p of article.querySelectorAll("p")) {
|
|
7391
|
+
const text = p.textContent.trim();
|
|
7392
|
+
if (text.length > 10 && !text.includes(title)) {
|
|
7393
|
+
snippet = text;
|
|
7394
|
+
break;
|
|
7395
|
+
}
|
|
7396
|
+
}
|
|
7397
|
+
if (!snippet) {
|
|
7398
|
+
const cs = article.querySelector(".content, .result-content, [class*='snippet']");
|
|
7399
|
+
if (cs) snippet = cs.textContent.trim();
|
|
7400
|
+
}
|
|
7401
|
+
results.push({ title, url: href, snippet });
|
|
7402
|
+
}
|
|
7403
|
+
return results;
|
|
7404
|
+
}
|
|
7405
|
+
for (const a of root.querySelectorAll("h3 a[href]")) {
|
|
7406
|
+
const href = a.getAttribute("href");
|
|
7407
|
+
if (!href || href.startsWith("#")) continue;
|
|
7408
|
+
const title = a.textContent.trim();
|
|
7409
|
+
if (!title) continue;
|
|
7410
|
+
let snippet = "";
|
|
7411
|
+
const p = a.parentNode?.parentNode?.querySelector("p");
|
|
7412
|
+
if (p) snippet = p.textContent.trim();
|
|
7413
|
+
results.push({ title, url: href, snippet });
|
|
7414
|
+
}
|
|
7415
|
+
return results;
|
|
7416
|
+
}
|
|
7317
7417
|
function parseMojeekResults(html) {
|
|
7318
7418
|
const titles = [];
|
|
7319
7419
|
const titleAnchorRe = /<a\b[^>]*\bclass="title"[^>]*>[\s\S]*?<\/a>/g;
|
|
@@ -7487,7 +7587,7 @@ function registerWebTools(registry, opts = {}) {
|
|
|
7487
7587
|
const maxFetchChars = opts.maxFetchChars ?? DEFAULT_FETCH_MAX_CHARS;
|
|
7488
7588
|
registry.register({
|
|
7489
7589
|
name: "web_search",
|
|
7490
|
-
description: "Search the public web. Returns ranked results with title, url, and snippet. Call this when the answer's correctness depends on current state \u2014 anything that changes over time (events, prices, releases, status of a thing in the real world). Composing such answers from training memory invents stale numbers; search first, then ground the answer in the results. For evergreen / definitional questions you don't need this.",
|
|
7590
|
+
description: "Search the public web. Returns ranked results with title, url, and snippet. Call this when the answer's correctness depends on current state \u2014 anything that changes over time (events, prices, releases, status of a thing in the real world). Composing such answers from training memory invents stale numbers; search first, then ground the answer in the results. For evergreen / definitional questions you don't need this. To change the backend, use /web-search-engine mojeek|searxng.",
|
|
7491
7591
|
readOnly: true,
|
|
7492
7592
|
parallelSafe: true,
|
|
7493
7593
|
parameters: {
|
|
@@ -7502,9 +7602,13 @@ function registerWebTools(registry, opts = {}) {
|
|
|
7502
7602
|
required: ["query"]
|
|
7503
7603
|
},
|
|
7504
7604
|
fn: async (args, ctx) => {
|
|
7605
|
+
const engine = opts.webSearchEngine ?? webSearchEngine();
|
|
7606
|
+
const endpoint = opts.webSearchEndpoint ?? webSearchEndpoint();
|
|
7505
7607
|
const results = await webSearch(args.query, {
|
|
7506
7608
|
topK: args.topK ?? defaultTopK,
|
|
7507
|
-
signal: ctx?.signal
|
|
7609
|
+
signal: ctx?.signal,
|
|
7610
|
+
engine,
|
|
7611
|
+
endpoint
|
|
7508
7612
|
});
|
|
7509
7613
|
return formatSearchResults(args.query, results);
|
|
7510
7614
|
}
|
|
@@ -9649,6 +9753,7 @@ export {
|
|
|
9649
9753
|
parseEditBlocks,
|
|
9650
9754
|
parseMcpSpec,
|
|
9651
9755
|
parseMojeekResults,
|
|
9756
|
+
parseSearxngHtmlResults,
|
|
9652
9757
|
parseTranscript,
|
|
9653
9758
|
prepareSpawn,
|
|
9654
9759
|
projectHash,
|