The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(web-search): handle missing web search results gracefully
Steven Enamakel0f3d38a80073
diff --git a/app/src/features/conversations/tools/parseWebSearchResult.ts b/app/src/features/conversations/tools/parseWebSearchResult.tsindex 6ceb9b1438..25d631d86e 100644--- a/app/src/features/conversations/tools/parseWebSearchResult.ts+++ b/app/src/features/conversations/tools/parseWebSearchResult.ts@@ -20,7 +20,30 @@* URLs are admitted; anything else is dropped rather than rendered as a* link.*/-import { extractSearchProvider } from '../../../utils/toolTimelineFormatting';+/** Upper bound on a provider label, so a malformed marker can't blow up a row. */+const MAX_SEARCH_PROVIDER_LENGTH = 32;++/**+ * Extract the resolved search provider from a completed web-search result.+ * Every search engine tags its output with a `(via <Provider>)` marker on the+ * heading line (managed resolves to "Exa" by default, or to whatever the+ * backend reports; BYOK engines tag "Brave"/"Querit"/"Seltz"/"Tavily"). Reading it back+ * keeps the attribution dynamic: it is driven by what actually ran, never by+ * a hardcoded provider name (#5136).+ *+ * Only the first line is inspected, and only its *trailing* marker, so neither+ * a `(via …)` string inside a result excerpt nor one inside the echoed query+ * (`Search results for: login (via OAuth) (via Exa)`) can be mistaken for the+ * provider. Returns `undefined` while the call is still running (no result+ * yet) or if no marker is present.+ */+export function extractSearchProvider(result: string | undefined): string | undefined {+ if (!result) return undefined;+ const headingLine = result.split('\n', 1)[0];+ const provider = headingLine?.match(/\(via ([^)]+)\)\s*_?$/i)?.[1]?.trim();+ if (!provider || provider.length > MAX_SEARCH_PROVIDER_LENGTH) return undefined;+ return provider;+}export interface WebSearchHit {title: string;diff --git a/app/src/store/chatRuntimeSlice.ts b/app/src/store/chatRuntimeSlice.tsindex 141f882f11..f155df6be8 100644--- a/app/src/store/chatRuntimeSlice.ts+++ b/app/src/store/chatRuntimeSlice.ts@@ -368,6 +368,15 @@ export interface ToolTimelineEntry {* and on rows from cores that predate output forwarding.*/result?: string;+ /**+ * Machine-readable result the core attached to `tool_result` as+ * `structured` (today `{ kind: "web_search", query, provider, results }`).+ * Lets a rich renderer skip re-parsing `result` text. Absent on rows from+ * older cores, which fall back to parsing.+ */+ structured?: unknown;+ /** Wall time the call took, from `tool_result.elapsed_ms`. */+ elapsedMs?: number;}export interface StreamingAssistantState {diff --git a/app/src/utils/toolTimelineFormatting.ts b/app/src/utils/toolTimelineFormatting.tsindex ec207fb10e..7f36f24111 100644--- a/app/src/utils/toolTimelineFormatting.ts+++ b/app/src/utils/toolTimelineFormatting.ts@@ -6,7 +6,10 @@* adapts {@link ToolTimelineEntry} rows onto it and keeps the timeline-only* helpers (processing blocks, sources, envelope stripping).*/-import { parseWebSearchResult } from '../features/conversations/tools/parseWebSearchResult';+import {+ extractSearchProvider,+ parseWebSearchResult,+} from '../features/conversations/tools/parseWebSearchResult';import {describeToolCall,type ToolCallPresentation,@@ -19,6 +22,7 @@ import type { ToolTimelineEntry } from '../store/chatRuntimeSlice';import type { PersistedTranscriptItem } from '../types/turnState';export type { ToolCategory, Translate };+export { extractSearchProvider };/** Resolve a timeline row through the registry. */export function presentTimelineEntry(entry: ToolTimelineEntry): ToolCallPresentation {@@ -267,31 +271,6 @@ function isHttpUrl(url: string): boolean {}}-/** Upper bound on a provider label, so a malformed marker can't blow up a row. */-const MAX_SEARCH_PROVIDER_LENGTH = 32;--/**- * Extract the resolved search provider from a completed web-search result.- * Every search engine tags its output with a `(via <Provider>)` marker on the- * heading line (managed resolves to "Exa" by default, or to whatever the- * backend reports; BYOK engines tag "Brave"/"Querit"/"Seltz"/"Tavily"). Reading it back- * keeps the attribution dynamic: it is driven by what actually ran, never by- * a hardcoded provider name (#5136).- *- * Only the first line is inspected, and only its *trailing* marker, so neither- * a `(via …)` string inside a result excerpt nor one inside the echoed query- * (`Search results for: login (via OAuth) (via Exa)`) can be mistaken for the- * provider. Returns `undefined` while the call is still running (no result- * yet) or if no marker is present.- */-export function extractSearchProvider(result: string | undefined): string | undefined {- if (!result) return undefined;- const headingLine = result.split('\n', 1)[0];- const provider = headingLine?.match(/\(via ([^)]+)\)\s*_?$/i)?.[1]?.trim();- if (!provider || provider.length > MAX_SEARCH_PROVIDER_LENGTH) return undefined;- return provider;-}-function parseArgsObject(argsBuffer?: string): Record<string, unknown> | null {if (!argsBuffer) return null;try {diff --git a/crates/openhuman-core/src/web_chat/progress_bridge_tests.rs b/crates/openhuman-core/src/web_chat/progress_bridge_tests.rsindex 17e1a86bed..abf966b33a 100644--- a/crates/openhuman-core/src/web_chat/progress_bridge_tests.rs+++ b/crates/openhuman-core/src/web_chat/progress_bridge_tests.rs@@ -365,6 +365,9 @@ async fn stamps_monotonic_seq_on_emitted_events() {elapsed_ms: 5,iteration: 1,failure: None,+ display_label: None,+ display_detail: None,+ structured: None,}).await.unwrap();