Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(conversations): show balance hint and answer content for web tool calls

Steven Enamakel7cce4c9f4b4c
diff --git a/app/src/features/conversations/components/AssistantUiToolCall.tsx b/app/src/features/conversations/components/AssistantUiToolCall.tsx
index 5713470d2f..8ae5ed0c8d 100644
--- a/app/src/features/conversations/components/AssistantUiToolCall.tsx
+++ b/app/src/features/conversations/components/AssistantUiToolCall.tsx
@@ -14,7 +14,13 @@ import type {
} from '../../../store/chatRuntimeSlice';
import { openUrl } from '../../../utils/openUrl';
import { ToolFailureCard } from '../aui/ToolFailureCard';
-import { FetchBody, FileBody, ShellBody, WebSearchBody } from '../tools/ToolBodies';
+import {
+ FetchBody,
+ FileBody,
+ SearchBalanceHint,
+ ShellBody,
+ WebSearchBody,
+} from '../tools/ToolBodies';
import { hasDisplayValue, parsedValue, ToolDataView } from '../tools/ToolDataView';
import { ToolIcon } from '../tools/ToolIcon';
import { describeToolCall, parseToolArgs, toolLabel } from '../tools/toolPresentation';
@@ -155,6 +161,12 @@ export function AssistantUiToolCallCard({
? FileBody({ args: parsedArgs, result: output })
: null;
const showOutput = !searchBody && hasDisplayValue(parsedValue(output));
+ // Managed search out of balance: say so plainly instead of leaving the user
+ // to decode the raw error.
+ const balanceHint =
+ failed &&
+ presentation.category === 'web' &&
+ (isSearchBalanceError(output) || isSearchBalanceError(failure));
return (
<ToolCall
@@ -216,6 +228,11 @@ export function AssistantUiToolCallCard({
/>
</div>
) : null}
+ {balanceHint ? (
+ <div className="ps-5.5 pt-1 pb-2">
+ <SearchBalanceHint t={t} />
+ </div>
+ ) : null}
{footer ? <div className="ps-5.5">{footer}</div> : null}
{/* Search results are the call's whole point: visible without
opening the disclosure, as in assistant-ui's own web-search. */}
diff --git a/app/src/features/conversations/tools/ToolBodies.tsx b/app/src/features/conversations/tools/ToolBodies.tsx
index a8af8d9078..9dfe58e538 100644
--- a/app/src/features/conversations/tools/ToolBodies.tsx
+++ b/app/src/features/conversations/tools/ToolBodies.tsx
@@ -48,7 +48,12 @@ function renderSearchLink({
);
}
-/** A web search through assistant-ui's web-search element. */
+/**
+ * A web search, answer or research call through assistant-ui's web-search
+ * element. An answer call shows its grounded answer above the element and its
+ * citations as the element's rows; the status line names the provider that
+ * answered and, when the role fell back, the ones it skipped.
+ */
export function WebSearchBody({
args,
result,
@@ -70,34 +75,79 @@ export function WebSearchBody({
: typeof args.objective === 'string'
? args.objective
: '';
- const hits = parsed?.results ?? [];
- const count =
- hits.length === 0
- ? t('conversations.tools.search.none', 'No results')
- : fillPlaceholders(
+ const citations = parsed?.citations ?? [];
+ const answered = Boolean(parsed?.answer) || parsed?.role === 'answer';
+ // An answer lists what it cites; a search lists what it found.
+ const hits = parsed?.results.length ? parsed.results : citations;
+ const count = parsed?.inProgress
+ ? t('conversations.tools.search.researching', 'Research still running')
+ : answered
+ ? fillPlaceholders(
hits.length === 1
- ? t('conversations.tools.search.found.one', 'Found {count} result')
- : t('conversations.tools.search.found.other', 'Found {count} results'),
+ ? t('conversations.tools.search.sources.one', '{count} source')
+ : t('conversations.tools.search.sources.other', '{count} sources'),
{ count: String(hits.length) }
- );
- const statusLabel = parsed?.provider
- ? `${count} · ${fillPlaceholders(t('conversations.tools.search.via', 'via {provider}'), {
- provider: parsed.provider,
- })}`
- : count;
+ )
+ : hits.length === 0
+ ? t('conversations.tools.search.none', 'No results')
+ : fillPlaceholders(
+ hits.length === 1
+ ? t('conversations.tools.search.found.one', 'Found {count} result')
+ : t('conversations.tools.search.found.other', 'Found {count} results'),
+ { count: String(hits.length) }
+ );
+ const fallbackFrom = parsed?.fallbackFrom ?? [];
+ const via = parsed?.provider
+ ? fallbackFrom.length > 0
+ ? fillPlaceholders(
+ t('conversations.tools.search.viaAfter', 'via {provider}, after {fallback}'),
+ { provider: parsed.provider, fallback: fallbackFrom.join(', ') }
+ )
+ : fillPlaceholders(t('conversations.tools.search.via', 'via {provider}'), {
+ provider: parsed.provider,
+ })
+ : undefined;
+ const statusLabel = via ? `${count} · ${via}` : count;
return (
- <WebSearch
- data-testid="web-search-results"
- className={FULL_WIDTH}
- query={parsed?.query ?? argQuery}
- results={hits.map(hit => ({ title: hit.title, domain: hit.domain, url: hit.url }))}
- visibleResults={hits.length}
- searching={searching}
- cycle={0}
- searchingLabel={t('conversations.tools.search.searching', 'Searching')}
- statusLabel={statusLabel}
- renderLink={renderSearchLink}
- />
+ <div className="flex w-full flex-col gap-2.5" data-testid="web-search-body">
+ {parsed?.answer ? (
+ <div
+ data-testid="web-search-answer"
+ className="text-foreground/85 max-h-80 overflow-y-auto text-[13.5px]">
+ <BubbleMarkdown content={parsed.answer} />
+ </div>
+ ) : null}
+ <WebSearch
+ data-testid="web-search-results"
+ className={FULL_WIDTH}
+ query={parsed?.query ?? argQuery}
+ results={hits.map(hit => ({ title: hit.title, domain: hit.domain, url: hit.url }))}
+ visibleResults={hits.length}
+ searching={searching}
+ cycle={0}
+ searchingLabel={t('conversations.tools.search.searching', 'Searching')}
+ statusLabel={statusLabel}
+ renderLink={renderSearchLink}
+ />
+ </div>
+ );
+}
+
+/**
+ * Hint shown on a failed web tool whose error says the TinyHumans balance ran
+ * out, so the user knows to top up or switch a provider to their own key.
+ */
+export function SearchBalanceHint({ t }: { t: Translate }): ReactNode {
+ return (
+ <p
+ role="note"
+ data-testid="web-search-balance-hint"
+ className="rounded-lg border border-amber-200 bg-amber-50 px-2.5 py-1.5 text-xs text-amber-800 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200">
+ {t(
+ 'conversations.tools.search.balanceLow',
+ 'Your TinyHumans balance is too low for included search. Top up, or add your own key for a search provider in Settings.'
+ )}
+ </p>
);
}