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
feat(memory): add brain search component with e2e coverage
Steven Enamakele86bda000e5b
diff --git a/app/src/components/memory/MemoryBrainSearch.tsx b/app/src/components/memory/MemoryBrainSearch.tsxnew file mode 100644index 0000000000..2dff009f36--- /dev/null+++ b/app/src/components/memory/MemoryBrainSearch.tsx@@ -0,0 +1,131 @@+/**+ * Memory → Brain → Search: search the shared brain's documents+ * (`memory_brain_search`), optionally within one source type.+ *+ * debug logging: DEBUG=openhuman:memory:brain+ */+import debug from 'debug';+import { type FormEvent, useState } from 'react';++import { useT } from '../../lib/i18n/I18nContext';+import { type Hit, memoryBrainSearch, memoryErrorMessage } from '../../services/api/memoryApi';+import { Alert, AlertDescription, Button, Card, NativeSelect, TextField } from '../ui';+import { CenteredLoadingState } from '../ui/LoadingState';+import MemoryHitRow from './MemoryHitRow';+import { brainSourceLabel } from './memoryLifecycleLabels';++const log = debug('openhuman:memory:brain');++const SEARCH_LIMIT = 20;++interface MemoryBrainSearchProps {+ /** The source types the brain holds, for the filter. */+ sources: string[];+}++export default function MemoryBrainSearch({ sources }: MemoryBrainSearchProps) {+ const { t } = useT();+ const [query, setQuery] = useState('');+ const [source, setSource] = useState('');+ const [busy, setBusy] = useState(false);+ const [error, setError] = useState<string | null>(null);+ const [hits, setHits] = useState<Hit[] | null>(null);++ const submit = async (event?: FormEvent) => {+ event?.preventDefault();+ const text = query.trim();+ if (!text || busy) return;+ setBusy(true);+ setError(null);+ try {+ log('search: source=%s len=%d', source || 'all', text.length);+ const res = await memoryBrainSearch({+ query: text,+ source: source || undefined,+ limit: SEARCH_LIMIT,+ });+ setHits(res.hits ?? []);+ } catch (err) {+ log('search failed: %o', err);+ setError(memoryErrorMessage(err));+ } finally {+ setBusy(false);+ }+ };++ return (+ <Card+ title={t('memoryPage.brain.searchTitle')}+ description={t('memoryPage.brain.searchDescription')}+ data-testid="memory-brain-search">+ <form+ className="flex flex-wrap items-center gap-2 px-4 py-3"+ onSubmit={event => void submit(event)}>+ <div className="min-w-0 flex-1">+ <TextField+ aria-label={t('memoryPage.brain.searchLabel')}+ data-testid="memory-brain-search-input"+ value={query}+ placeholder={t('memoryPage.brain.searchPlaceholder')}+ onChange={e => setQuery(e.target.value)}+ />+ </div>+ <NativeSelect+ aria-label={t('memoryPage.brain.searchSource')}+ data-testid="memory-brain-search-source"+ value={source}+ onChange={e => setSource(e.target.value)}>+ <option value="">{t('memoryPage.brain.allSources')}</option>+ {sources.map(id => (+ <option key={id} value={id}>+ {brainSourceLabel(id, t)}+ </option>+ ))}+ </NativeSelect>+ <Button+ type="submit"+ variant="secondary"+ size="sm"+ analyticsId="memory-brain-search"+ data-testid="memory-brain-search-submit"+ disabled={busy || query.trim().length === 0}>+ {t('memoryPage.ask.search')}+ </Button>+ </form>++ {error !== null && (+ <div className="px-4 pb-3">+ <Alert variant="destructive" data-testid="memory-brain-search-error">+ <AlertDescription>{error}</AlertDescription>+ </Alert>+ </div>+ )}++ {busy && <CenteredLoadingState label={t('memoryPage.ask.thinking')} />}++ {!busy &&+ hits !== null &&+ (hits.length === 0 ? (+ <p+ className="px-4 py-3 text-sm text-content-muted"+ data-testid="memory-brain-search-empty">+ {t('memoryPage.brain.searchEmpty')}+ </p>+ ) : (+ <ul className="divide-y divide-line-subtle" data-testid="memory-brain-search-hits">+ {hits.map(hit => (+ <MemoryHitRow+ key={hit.id}+ id={hit.id}+ kind={hit.kind}+ text={hit.text}+ meta={hit.meta}+ score={hit.score}+ showScore+ />+ ))}+ </ul>+ ))}+ </Card>+ );+}diff --git a/tests/memory_v2_e2e.rs b/tests/memory_v2_e2e.rsindex 7ed5e000d2..37bf325dfb 100644--- a/tests/memory_v2_e2e.rs+++ b/tests/memory_v2_e2e.rs@@ -1288,16 +1288,21 @@ async fn a_chat_turn_carries_its_pack_and_is_logged() {}).await;- // The pack is ephemeral: the stored thread holds only what was said.- let messages = f+ // The pack is ephemeral: the committed transcript holds only what was+ // said (the reply is logged after the durable commit, so it exists).+ let transcript = f.ok(- "openhuman.threads_messages",+ "openhuman.threads_transcript_get",json!({ "thread_id": "launch-thread" }),).await;assert!(- !messages.to_string().contains("memory-context"),- "the pack never reaches the transcript: {messages}"+ transcript.to_string().contains("Where should the launch event be held?"),+ "the turn was committed: {transcript}"+ );+ assert!(+ !transcript.to_string().contains("memory-context"),+ "the pack never reaches the transcript: {transcript}");}