Skip to content

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

feat(memory): add memory engine tab

Steven Enamakel05f1d5bfe0af
diff --git a/app/src/components/memory/MemoryEngineTab.tsx b/app/src/components/memory/MemoryEngineTab.tsx
index 93748a244a..5521fb095e 100644
--- a/app/src/components/memory/MemoryEngineTab.tsx
+++ b/app/src/components/memory/MemoryEngineTab.tsx
@@ -1,27 +1,28 @@
/**
- * Memory → Engine: memory runs on CortexDB, reached one of three ways, shown as
- * a single-open accordion (#7025):
+ * Memory → Provider: where memory is stored. All three providers run on
+ * CortexDB, shown as cards (like Connections → Voice agents), each with a
+ * Settings modal:
*
- * - Built-in: the `tinyhumans` engine, the TinyHumans backend's `/memory/*`
- * API (CortexDB hosted per account), authenticated by sign-in. The backend
- * origin it uses is shown read-only from `memory_engine_get`. Signed out (or
- * on a local session), it says so and cannot be selected.
- * - Your API key: the `cortexdb` engine on CortexDB's managed API. The endpoint
- * is fixed; only the key is entered.
- * - Self-host: the `cortexdb` engine on a server on this computer. Self-host is
- * local only (a product rule), so the endpoint's host must be loopback; either
- * scheme is fine there. The core itself allows https to any host and
- * cleartext http only to loopback, so this check is the stricter of the two.
+ * - TinyHumans Memory (`builtin`): the `tinyhumans` engine, the TinyHumans
+ * backend's `/memory/*` API (CortexDB hosted per account), authenticated by
+ * sign-in. Included with TinyHumans; Basic and Pro plans ingest for free
+ * under the fair-use terms the modal states. Signed out (or on a local
+ * session) it cannot be selected.
+ * - CortexDB Cloud (`apikey`): the `cortexdb` engine on CortexDB's managed
+ * API. The endpoint is fixed; only the key is entered.
+ * - CortexDB Local (`selfhost`): the `cortexdb` engine on a server on this
+ * computer. Local is loopback only (a product rule); either scheme is fine
+ * there. The core itself allows https to any host and cleartext http only to
+ * loopback, so this check is the stricter of the two.
*
- * Which item is active is derived from `memory_engine_get`: `tinyhumans` is
- * Built-in, and `cortexdb` is Self-host when its endpoint is loopback, else
- * API key. The status banner still explains an off, degraded or down engine.
+ * Which card is active is derived from `memory_engine_get`: `tinyhumans` is
+ * TinyHumans, and `cortexdb` is Local when its endpoint is loopback, else
+ * Cloud. Engines that are not supported yet are listed as coming soon.
*
* debug logging: DEBUG=openhuman:memory:engine
*/
import debug from 'debug';
-import { ExternalLink } from 'lucide-react';
-import { useCallback, useId, useState } from 'react';
+import { useCallback, useState } from 'react';
import { useT } from '../../lib/i18n/I18nContext';
import { useCoreState } from '../../providers/CoreStateProvider';
@@ -33,34 +34,21 @@ import {
memoryErrorMessage,
} from '../../services/api/memoryApi';
import { isLocalSessionToken } from '../../utils/localSession';
-import { openUrl } from '../../utils/openUrl';
-import {
- AccordionContent,
- AccordionItem,
- AccordionRoot,
- AccordionTrigger,
- Alert,
- AlertDescription,
- AlertTitle,
- Badge,
- Button,
- Label,
- TextField,
-} from '../ui';
+import { Alert, AlertDescription, AlertTitle, type BadgeVariant } from '../ui';
import { CenteredLoadingState } from '../ui/LoadingState';
+import { toast } from '../ui/Toast';
+import MemoryComingSoon from './MemoryComingSoon';
+import MemoryProviderCard from './MemoryProviderCard';
+import MemoryProviderLogo, { type MemoryProviderOption } from './MemoryProviderLogo';
+import MemoryProviderModal from './MemoryProviderModal';
-const log = debug('openhuman:memory:engine');
-
-/** CortexDB's self-hosting guide, linked from the Self-host item. */
-export const CORTEXDB_SELF_HOST_DOCS_URL = 'https://cortexdb.ai/docs/self-hosting/quickstart';
+export { CORTEXDB_SELF_HOST_DOCS_URL } from './MemoryProviderModal';
-/** CortexDB's managed API, the fixed endpoint of the API-key item. */
-const CORTEXDB_CLOUD_ENDPOINT = 'https://api-v1.cortexdb.ai';
+const log = debug('openhuman:memory:engine');
-/** CortexDB's default port on this computer, shown as the example endpoint. */
-const SELF_HOST_EXAMPLE_ENDPOINT = 'http://localhost:3141';
+type EngineOption = MemoryProviderOption;
-type EngineOption = 'builtin' | 'apikey' | 'selfhost';
+const OPTIONS: EngineOption[] = ['builtin', 'apikey', 'selfhost'];
/**
* True for an http(s) URL whose host is this computer (localhost, 127.x, ::1).
@@ -78,7 +66,7 @@ export function isLoopbackEndpoint(raw: string): boolean {
return host === 'localhost' || host === '[::1]' || /^127(\.\d{1,3}){3}$/.test(host);
}
-/** The accordion item the configured engine corresponds to. */
+/** The provider the configured engine corresponds to. */
function optionOf(state: EngineState | null): EngineOption | null {
if (state?.engine === 'tinyhumans') return 'builtin';
if (state?.engine === 'cortexdb') {
@@ -98,14 +86,14 @@ interface MemoryEngineTabProps {
export default function MemoryEngineTab({ state, onStateChange, embedded }: MemoryEngineTabProps) {
const { t } = useT();
- const baseId = useId();
const { snapshot } = useCoreState();
const signedIn = snapshot.auth.isAuthenticated && !isLocalSessionToken(snapshot.sessionToken);
+ const plan = snapshot.currentUser?.subscription?.plan ?? null;
const active = optionOf(state);
const on = isMemoryOn(state);
- const [open, setOpen] = useState<string | undefined>(undefined);
+ const [openOption, setOpenOption] = useState<EngineOption | null>(null);
const [saving, setSaving] = useState<EngineOption | null>(null);
const [errors, setErrors] = useState<Partial<Record<EngineOption, string>>>({});
const [cloudKey, setCloudKey] = useState('');
@@ -114,14 +102,40 @@ export default function MemoryEngineTab({ state, onStateChange, embedded }: Memo
const [typedEndpoint, setTypedEndpoint] = useState<string | null>(null);
const [localKey, setLocalKey] = useState('');
+ const titles: Record<EngineOption, string> = {
+ builtin: t('memoryPage.engine.builtin.title'),
+ apikey: t('memoryPage.engine.apiKeyOption.title'),
+ selfhost: t('memoryPage.engine.selfHost.title'),
+ };
+ const descriptions: Record<EngineOption, string> = {
+ builtin: t('memoryPage.engine.builtin.cardDescription'),
+ apikey: t('memoryPage.engine.apiKeyOption.cardDescription'),
+ selfhost: t('memoryPage.engine.selfHost.cardDescription'),
+ };
+
const select = useCallback(
async (option: EngineOption, req: EngineSetRequest): Promise<boolean> => {
+ const wasActive = optionOf(state) === option;
setSaving(option);
setErrors(prev => ({ ...prev, [option]: undefined }));
try {
const next = await memoryEngineSet(req);
log('engine set (%s): %s status=%s', option, next.engine ?? 'none', next.status);
onStateChange(next);
+ toast.add(
+ wasActive
+ ? { type: 'success', title: t('memoryPage.engine.toastSaved') }
+ : {
+ type: 'success',
+ title: t('memoryPage.engine.toastSwitched'),
+ description: t('memoryPage.engine.toastSwitchedBody').replace(
+ '{name}',
+ titles[option]
+ ),
+ data: { icon: <MemoryProviderLogo option={option} className="h-5 w-5" /> },
+ }
+ );
+ setOpenOption(null);
return true;
} catch (err) {
log('engine set (%s) failed: %o', option, err);
@@ -131,21 +145,24 @@ export default function MemoryEngineTab({ state, onStateChange, embedded }: Memo
setSaving(null);
}
},
- [onStateChange, t]
+ // `titles` is rebuilt from `t` every render; `t` is the real dependency.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ [onStateChange, state, t]
);
if (!state) {
return <CenteredLoadingState label={t('memoryPage.loading')} />;
}
+ // Off: a plain prompt to pick a provider. The core's reason is developer
+ // text ("legacy memory backend is unsupported…"), so it is not shown here;
+ // degraded and down keep theirs, which names what is wrong.
const statusBanner = (() => {
if (!on) {
return (
<Alert variant="info" data-testid="memory-engine-status-off">
<AlertTitle>{t('memoryPage.off.title')}</AlertTitle>
- <AlertDescription>
- {state.reason || t('memoryPage.engine.offExplanation')}
- </AlertDescription>
+ <AlertDescription>{t('memoryPage.engine.offPrompt')}</AlertDescription>
</Alert>
);
}
@@ -166,76 +183,28 @@ export default function MemoryEngineTab({ state, onStateChange, embedded }: Memo
return null;
})();
- const activeBadge = (option: EngineOption) => {
- if (option !== active) return null;
- const [variant, label] = !on
- ? (['warning', t('memoryPage.engine.statusOff')] as const)
- : state.status === 'down'
- ? (['danger', t('memoryPage.engine.badgeDown')] as const)
- : state.status === 'degraded'
- ? (['warning', t('memoryPage.engine.badgeDegraded')] as const)
- : (['success', t('memoryPage.engine.active')] as const);
- return (
- <Badge variant={variant} data-testid={`memory-engine-${option}-active`}>
- {label}
- </Badge>
- );
- };
-
- const itemError = (option: EngineOption) =>
- errors[option] ? (
- <Alert variant="destructive" data-testid={`memory-engine-${option}-error`}>
- <AlertDescription>{errors[option]}</AlertDescription>
- </Alert>
- ) : null;
-
- const actionLabel = (option: EngineOption) =>
- saving === option
- ? t('memoryPage.engine.connecting')
- : option === active
- ? t('memoryPage.engine.save')
- : t('memoryPage.engine.connect');
-
- const keyField = (
- option: 'apikey' | 'selfhost',
- value: string,
- onChange: (value: string) => void
- ) => {
- const saved = option === active && state.has_key;
- return (
- <div className="flex flex-col gap-1.5">
- <Label htmlFor={`${baseId}-${option}-key`} className="text-xs text-content-secondary">
- {t('memoryPage.engine.apiKey')}
- </Label>
- <TextField
- id={`${baseId}-${option}-key`}
- data-testid={`memory-engine-${option}-key`}
- type="password"
- mono
- autoComplete="off"
- spellCheck={false}
- data-lpignore="true"
- data-1p-ignore="true"
- value={value}
- disabled={saving !== null}
- placeholder={saved ? t('memoryPage.engine.keySavedPlaceholder') : ''}
- onChange={e => onChange(e.target.value)}
- />
- {saved && (
- <p className="text-[11px] leading-4 text-content-muted">
- {t('memoryPage.engine.keySavedHint')}
- </p>
- )}
- </div>
- );
+ const statusOf = (option: EngineOption): { variant: BadgeVariant; label: string } => {
+ if (option === active) {
+ if (!on) return { variant: 'warning', label: t('memoryPage.engine.statusOff') };
+ if (state.status === 'down') return { variant: 'danger', label: t('memoryPage.engine.badgeDown') };
+ if (state.status === 'degraded') {
+ return { variant: 'warning', label: t('memoryPage.engine.badgeDegraded') };
+ }
+ return { variant: 'primary', label: t('memoryPage.engine.inUse') };
+ }
+ if (option === 'builtin') {
+ return signedIn
+ ? { variant: 'success', label: t('memoryPage.engine.badgeReady') }
+ : { variant: 'neutral', label: t('memoryPage.engine.builtin.signInRequired') };
+ }
+ return { variant: 'neutral', label: t('memoryPage.engine.badgeNotConnected') };
};
- // Built-in.
- const builtinBlocked = !signedIn;
- const builtinIdle = active === 'builtin' && on;
+ // TinyHumans: one click when signed in.
+ const useBuiltin = () => void select('builtin', { engine: 'tinyhumans' });
- // API key: the endpoint is CortexDB's managed API. Sending a blank endpoint
- // clears any custom (self-host) endpoint, so the engine falls back to it.
+ // Cloud: the endpoint is CortexDB's managed API. Sending a blank endpoint
+ // clears any custom (local) endpoint, so the engine falls back to it.
const cloudKeyRequired = !(active === 'apikey' && state.has_key);
const canSubmitCloud = saving === null && (!cloudKeyRequired || cloudKey.trim().length > 0);
const submitCloud = async () => {
@@ -245,7 +214,7 @@ export default function MemoryEngineTab({ state, onStateChange, embedded }: Memo
if (await select('apikey', req)) setCloudKey('');
};
- // Self-host: loopback only.
+ // Local: loopback only.
const localEndpoint = typedEndpoint ?? (active === 'selfhost' ? (state.endpoint ?? '') : '');
const endpointTyped = localEndpoint.trim().length > 0;
const endpointLocal = isLoopbackEndpoint(localEndpoint);
@@ -259,187 +228,90 @@ export default function MemoryEngineTab({ state, onStateChange, embedded }: Memo
if (await select('selfhost', req)) setLocalKey('');
};
- const trigger = (option: EngineOption, title: string, detail: string) => (
- <AccordionTrigger data-testid={`memory-engine-${option}-trigger`}>
- <span className="flex min-w-0 flex-1 flex-col gap-0.5">
- <span className="flex items-center gap-2">
- {title}
- {activeBadge(option)}
- </span>
- <span className="truncate text-xs font-normal text-content-muted">{detail}</span>
- </span>
- </AccordionTrigger>
- );
+ const actionOf = (option: EngineOption) => {
+ if (option === active && (on || option !== 'builtin')) return undefined;
+ if (option === 'builtin') {
+ return {
+ label: saving === 'builtin' ? t('memoryPage.engine.connecting') : t('memoryPage.engine.use'),
+ onClick: useBuiltin,
+ disabled: saving !== null || !signedIn,
+ };
+ }
+ return { label: t('memoryPage.engine.connect'), onClick: () => setOpenOption(option) };
+ };
+
+ const freeNote =
+ plan === 'BASIC' || plan === 'PRO'
+ ? t('memoryPage.engine.freeIngestion.notePlan').replace('{plan}', plan === 'PRO' ? 'Pro' : 'Basic')
+ : t('memoryPage.engine.freeIngestion.noteUpgrade');
return (
<div
- className={embedded ? 'space-y-4' : 'space-y-4 animate-fade-up'}
+ className={`@container ${embedded ? 'space-y-5' : 'mx-auto w-full max-w-5xl space-y-6 animate-fade-up'}`}
data-testid="memory-engine-tab">
{statusBanner}
- <div className="space-y-2">
- <div>
+ <section className="flex flex-col gap-2.5">
+ <header>
<h3 className="text-sm font-semibold text-content">{t('memoryPage.engine.listTitle')}</h3>
<p className="text-xs text-content-muted">{t('memoryPage.engine.listDescription')}</p>
- </div>
-
- <AccordionRoot
- type="single"
- collapsible
- variant="card"
- value={open ?? active ?? 'builtin'}
- onValueChange={setOpen}
+ </header>
+ <div
+ className="grid items-stretch gap-3 @xl:grid-cols-2 @4xl:grid-cols-3"
data-testid="memory-engines">
- <AccordionItem value="builtin" variant="card" data-testid="memory-engine-builtin">
- {trigger(
- 'builtin',
- t('memoryPage.engine.builtin.title'),
- builtinBlocked
- ? t('memoryPage.engine.builtin.signInRequired')
- : t('memoryPage.engine.builtin.detail')
- )}
- <AccordionContent className="space-y-3">
- <p>{t('memoryPage.engine.builtin.description')}</p>
- <p className="text-xs text-content-muted">
- {t('memoryPage.engine.builtin.enrichmentNote')}
- </p>
- {/* The backend origin the core resolved, read-only: never a
- hard-coded URL, and only known while Built-in is configured. */}
- {active === 'builtin' && state.endpoint && (
- <p className="text-xs text-content-muted">
- {t('memoryPage.engine.endpoint')}:{' '}
- <span className="font-mono" data-testid="memory-engine-builtin-endpoint">
- {state.endpoint}
- </span>
- </p>
- )}
- {builtinBlocked && (
- <p
- className="text-xs text-content-muted"
- data-testid="memory-engine-builtin-sign-in">
- {t('memoryPage.engine.builtin.signInHint')}
- </p>
- )}
- {itemError('builtin')}
- {!builtinIdle && (
- <Button
- type="button"
- size="sm"
- variant="primary"
- disabled={saving !== null || builtinBlocked}
- data-testid="memory-engine-builtin-use"
- onClick={() => void select('builtin', { engine: 'tinyhumans' })}>
- {saving === 'builtin'
- ? t('memoryPage.engine.connecting')
- : t('memoryPage.engine.use')}
- </Button>
- )}
- </AccordionContent>
- </AccordionItem>
+ {OPTIONS.map(option => (
+ <MemoryProviderCard
+ key={option}
+ option={option}
+ title={titles[option]}
+ description={descriptions[option]}
+ active={option === active}
+ status={statusOf(option)}
+ action={actionOf(option)}
+ note={option === 'builtin' ? freeNote : undefined}
+ onOpenSettings={() => setOpenOption(option)}
+ />
+ ))}
+ </div>
+ </section>
- <AccordionItem value="apikey" variant="card" data-testid="memory-engine-apikey">
- {trigger('apikey', t('memoryPage.engine.apiKeyOption.title'), CORTEXDB_CLOUD_ENDPOINT)}
- <AccordionContent>
- <form
- className="flex flex-col gap-3"
- onSubmit={event => {
- event.preventDefault();
- void submitCloud();
- }}>
- <p>{t('memoryPage.engine.apiKeyOption.description')}</p>
- {keyField('apikey', cloudKey, setCloudKey)}
- {itemError('apikey')}
- <div>
- <Button
- type="submit"
- size="sm"
- variant="primary"
- disabled={!canSubmitCloud}
- data-testid="memory-engine-apikey-submit">
- {actionLabel('apikey')}
- </Button>
- </div>
- </form>
- </AccordionContent>
- </AccordionItem>
+ <MemoryComingSoon />
- <AccordionItem value="selfhost" variant="card" data-testid="memory-engine-selfhost">
- {trigger(
- 'selfhost',
- t('memoryPage.engine.selfHost.title'),
- active === 'selfhost' && state.endpoint
- ? state.endpoint
- : t('memoryPage.engine.selfHost.detail')
- )}
- <AccordionContent>
- <form
- className="flex flex-col gap-3"
- onSubmit={event => {
- event.preventDefault();
- void submitLocal();
- }}>
- <ol className="list-decimal space-y-1 pl-4">
- <li>
- {t('memoryPage.engine.selfHost.step1')}{' '}
- <a
- href={CORTEXDB_SELF_HOST_DOCS_URL}
- target="_blank"
- rel="noopener noreferrer"
- data-testid="memory-engine-selfhost-docs"
- onClick={event => {
- event.preventDefault();
- void openUrl(CORTEXDB_SELF_HOST_DOCS_URL).catch(() => undefined);
- }}
- className="inline-flex items-center gap-1 font-medium text-primary-600 hover:underline dark:text-primary-300">
- {t('memoryPage.engine.selfHost.docsLink')}
- <ExternalLink className="h-3 w-3" aria-hidden />
- </a>
- </li>
- <li>{t('memoryPage.engine.selfHost.step2')}</li>
- <li>{t('memoryPage.engine.selfHost.step3')}</li>
- </ol>
- <div className="flex flex-col gap-1.5">
- <Label
- htmlFor={`${baseId}-selfhost-endpoint`}
- className="text-xs text-content-secondary">
- {t('memoryPage.engine.endpoint')}
- </Label>
- <TextField
- id={`${baseId}-selfhost-endpoint`}
- data-testid="memory-engine-selfhost-endpoint"
- type="url"
- mono
- spellCheck={false}
- value={localEndpoint}
- disabled={saving !== null}
- placeholder={SELF_HOST_EXAMPLE_ENDPOINT}
- onChange={e => setTypedEndpoint(e.target.value)}
- />
- {endpointTyped && !endpointLocal && (
- <p
- className="text-[11px] leading-4 text-destructive"
- data-testid="memory-engine-selfhost-endpoint-error">
- {t('memoryPage.engine.selfHost.notLocal')}
- </p>
- )}
- </div>
- {keyField('selfhost', localKey, setLocalKey)}
- {itemError('selfhost')}
- <div>
- <Button
- type="submit"
- size="sm"
- variant="primary"
- disabled={!canSubmitLocal}
- data-testid="memory-engine-selfhost-submit">
- {actionLabel('selfhost')}
- </Button>
- </div>
- </form>
- </AccordionContent>
- </AccordionItem>
- </AccordionRoot>
- </div>
+ {openOption && (
+ <MemoryProviderModal
+ option={openOption}
+ title={titles[openOption]}
+ description={descriptions[openOption]}
+ state={state}
+ active={openOption === active}
+ signedIn={signedIn}
+ plan={plan}
+ saving={saving}
+ error={errors[openOption]}
+ cloudKey={cloudKey}
+ onCloudKey={setCloudKey}
+ localEndpoint={localEndpoint}
+ onLocalEndpoint={setTypedEndpoint}
+ endpointInvalid={endpointTyped && !endpointLocal}
+ localKey={localKey}
+ onLocalKey={setLocalKey}
+ canSubmit={
+ openOption === 'builtin'
+ ? saving === null && signedIn
+ : openOption === 'apikey'
+ ? canSubmitCloud
+ : canSubmitLocal
+ }
+ onSubmit={
+ openOption === 'builtin'
+ ? useBuiltin
+ : openOption === 'apikey'
+ ? () => void submitCloud()
+ : () => void submitLocal()
+ }
+ onClose={() => setOpenOption(null)}
+ />
+ )}
</div>
);
}