Skip to content

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

chore: files changed app/src/components/memory/MemoryConversationsTab.tsx

Steven Enamakel93e08d031b6b
diff --git a/app/src/components/memory/MemoryConversationsTab.tsx b/app/src/components/memory/MemoryConversationsTab.tsx
index 4d4169bbc6..2aefb4f400 100644
--- a/app/src/components/memory/MemoryConversationsTab.tsx
+++ b/app/src/components/memory/MemoryConversationsTab.tsx
@@ -1,7 +1,9 @@
/**
- * Memory → Conversations: whether chat threads are stored automatically, and
- * when (`batch_turns` committed turns, or `idle_secs` of quiet), plus the
- * threads stored most recently. Backed by `memory_conversations_get/_set`.
+ * Memory → Conversations: whether every turn is logged to memory
+ * (`memory_policy_set { log_conversations }`), the agents whose turns are
+ * logged (`memory_agents_list`) — opening one lists its stored conversation
+ * items (`memory_items_list` filtered to `kinds: ["conversation"]` and the
+ * agent) — and the consent-gated sync of chats from before logging was on.
*
* debug logging: DEBUG=openhuman:memory:conversations
*/
@@ -10,84 +12,107 @@ import { useCallback, useEffect, useState } from 'react';
import { useT } from '../../lib/i18n/I18nContext';
import {
- type ConversationsSettings,
- type ConversationsUpdate,
- memoryConversationsGet,
- memoryConversationsSet,
+ type Hit,
+ type MemoryAgent,
+ memoryAgentsList,
memoryErrorMessage,
+ memoryItemsList,
+ type MemoryPolicy,
+ memoryPolicyGet,
+ memoryPolicySet,
} from '../../services/api/memoryApi';
-import { Alert, AlertDescription, Card, NumberField, Switch } from '../ui';
+import { Alert, AlertDescription, Button, Card, Switch } from '../ui';
import { CenteredLoadingState } from '../ui/LoadingState';
import MemoryConversationsBackfill from './MemoryConversationsBackfill';
-import { fill, formatTimestamp, parsePositiveInt } from './memoryFormat';
+import MemoryHitRow from './MemoryHitRow';
+import { fill } from './memoryFormat';
const log = debug('openhuman:memory:conversations');
+const PAGE_SIZE = 20;
+
export default function MemoryConversationsTab() {
const { t } = useT();
- const [settings, setSettings] = useState<ConversationsSettings | null>(null);
+ const [policy, setPolicy] = useState<MemoryPolicy | null>(null);
+ const [agents, setAgents] = useState<MemoryAgent[] | null>(null);
const [error, setError] = useState<string | null>(null);
const [saving, setSaving] = useState(false);
- const [batch, setBatch] = useState('');
- const [idle, setIdle] = useState('');
-
- const apply = useCallback((next: ConversationsSettings) => {
- setSettings({ ...next, recent: next.recent ?? [] });
- setBatch(String(next.batch_turns));
- setIdle(String(next.idle_secs));
- }, []);
+ const [openAgent, setOpenAgent] = useState<string | null>(null);
+ const [items, setItems] = useState<Hit[] | null>(null);
+ const [cursor, setCursor] = useState<string | null>(null);
+ const [loadingItems, setLoadingItems] = useState(false);
useEffect(() => {
let cancelled = false;
- memoryConversationsGet()
- .then(next => {
- if (!cancelled) apply(next);
- })
- .catch(err => {
- if (cancelled) return;
- log('get failed: %o', err);
- setError(memoryErrorMessage(err));
- });
+ Promise.allSettled([memoryPolicyGet(), memoryAgentsList()]).then(([got, list]) => {
+ if (cancelled) return;
+ if (got.status === 'fulfilled') {
+ setPolicy(got.value);
+ } else {
+ log('policy_get failed: %o', got.reason);
+ setError(memoryErrorMessage(got.reason));
+ }
+ if (list.status === 'fulfilled') {
+ log('agents: %d', list.value.agents?.length ?? 0);
+ setAgents(list.value.agents ?? []);
+ } else {
+ log('agents_list failed: %o', list.reason);
+ setError(prev => prev ?? memoryErrorMessage(list.reason));
+ setAgents([]);
+ }
+ });
return () => {
cancelled = true;
};
- }, [apply]);
+ }, []);
- const save = async (update: ConversationsUpdate) => {
+ const setLogging = async (next: boolean) => {
setSaving(true);
setError(null);
try {
- log('set: %o', update);
- apply(await memoryConversationsSet(update));
+ log('set log_conversations=%s', next);
+ setPolicy(await memoryPolicySet({ log_conversations: next }));
} catch (err) {
- log('set failed: %o', err);
+ log('policy_set failed: %o', err);
setError(memoryErrorMessage(err));
} finally {
setSaving(false);
}
};
- const commitNumber = (field: 'batch_turns' | 'idle_secs', raw: string) => {
- if (!settings) return;
- const value = parsePositiveInt(raw);
- if (value === null) {
- // Revert an invalid entry to the stored value instead of saving it.
- if (field === 'batch_turns') setBatch(String(settings.batch_turns));
- else setIdle(String(settings.idle_secs));
+ const loadItems = useCallback(async (agentId: string, after: string | null) => {
+ setLoadingItems(true);
+ try {
+ const page = await memoryItemsList({
+ filter: { kinds: ['conversation'], agent_id: agentId },
+ limit: PAGE_SIZE,
+ cursor: after ?? undefined,
+ });
+ log('items: agent=%s n=%d more=%s', agentId, page.items?.length ?? 0, !!page.next_cursor);
+ setItems(prev => [...(after ? (prev ?? []) : []), ...(page.items ?? [])]);
+ setCursor(page.next_cursor ?? null);
+ } catch (err) {
+ log('items_list failed: %o', err);
+ setError(memoryErrorMessage(err));
+ setItems(prev => prev ?? []);
+ } finally {
+ setLoadingItems(false);
+ }
+ }, []);
+
+ const toggleAgent = (agentId: string) => {
+ if (openAgent === agentId) {
+ setOpenAgent(null);
return;
}
- if (value === settings[field]) return;
- void save({ [field]: value });
+ setOpenAgent(agentId);
+ setItems(null);
+ setCursor(null);
+ void loadItems(agentId, null);
};
- if (settings === null) {
- return error !== null ? (
- <Alert variant="destructive" data-testid="memory-conversations-error">
- <AlertDescription>{error}</AlertDescription>
- </Alert>
- ) : (
- <CenteredLoadingState label={t('memoryPage.loading')} />
- );
+ if (policy === null && agents === null) {
+ return <CenteredLoadingState label={t('memoryPage.loading')} />;
}
return (
@@ -98,84 +123,91 @@ export default function MemoryConversationsTab() {
</Alert>
)}
- <Card
- title={t('memoryPage.conversations.settingsTitle')}
- description={t('memoryPage.conversations.settingsDescription')}>
- <div className="flex items-center justify-between gap-4 px-4 py-3">
- <label htmlFor="memory-conversations-enabled" className="text-sm text-content">
- {t('memoryPage.conversations.enabled')}
- </label>
- <Switch
- id="memory-conversations-enabled"
- data-testid="memory-conversations-enabled"
- checked={settings.enabled}
- disabled={saving}
- aria-label={t('memoryPage.conversations.enabled')}
- onCheckedChange={next => void save({ enabled: next })}
- />
- </div>
- <div className="flex items-center justify-between gap-4 px-4 py-3">
- <div className="min-w-0">
- <p className="text-sm text-content">{t('memoryPage.conversations.batchTurns')}</p>
- <p className="text-xs text-content-muted">
- {t('memoryPage.conversations.batchTurnsHelp')}
- </p>
- </div>
- <NumberField
- id="memory-conversations-batch"
- data-testid="memory-conversations-batch"
- aria-label={t('memoryPage.conversations.batchTurns')}
- value={batch}
- min={1}
- disabled={saving || !settings.enabled}
- onChange={setBatch}
- onCommit={() => commitNumber('batch_turns', batch)}
- />
- </div>
- <div className="flex items-center justify-between gap-4 px-4 py-3">
- <div className="min-w-0">
- <p className="text-sm text-content">{t('memoryPage.conversations.idleSecs')}</p>
- <p className="text-xs text-content-muted">
- {t('memoryPage.conversations.idleSecsHelp')}
- </p>
+ {policy !== null && (
+ <Card
+ title={t('memoryPage.conversations.settingsTitle')}
+ description={t('memoryPage.conversations.settingsDescription')}>
+ <div className="flex items-center justify-between gap-4 px-4 py-3">
+ <label htmlFor="memory-conversations-log" className="text-sm text-content">
+ {t('memoryPage.conversations.logTurns')}
+ </label>
+ <Switch
+ id="memory-conversations-log"
+ data-testid="memory-conversations-log"
+ checked={policy.log_conversations}
+ disabled={saving}
+ aria-label={t('memoryPage.conversations.logTurns')}
+ onCheckedChange={next => void setLogging(next)}
+ />
</div>
- <NumberField
- id="memory-conversations-idle"
- data-testid="memory-conversations-idle"
- aria-label={t('memoryPage.conversations.idleSecs')}
- value={idle}
- min={1}
- unit={t('memoryPage.conversations.seconds')}
- disabled={saving || !settings.enabled}
- onChange={setIdle}
- onCommit={() => commitNumber('idle_secs', idle)}
- />
- </div>
- </Card>
+ </Card>
+ )}
<MemoryConversationsBackfill />
<Card
- title={t('memoryPage.conversations.recentTitle')}
- data-testid="memory-conversations-recent">
- {settings.recent.length === 0 ? (
+ title={t('memoryPage.conversations.agentsTitle')}
+ description={t('memoryPage.conversations.agentsDescription')}
+ data-testid="memory-conversations-agents">
+ {(agents ?? []).length === 0 ? (
<p
className="px-4 py-3 text-sm text-content-muted"
data-testid="memory-conversations-empty">
- {t('memoryPage.conversations.recentEmpty')}
+ {t('memoryPage.conversations.agentsEmpty')}
</p>
) : (
<ul className="divide-y divide-line-subtle">
- {settings.recent.map(entry => (
- <li
- key={`${entry.thread_id}-${entry.stored_at}`}
- className="flex items-center justify-between gap-3 px-4 py-2.5"
- data-testid={`memory-conversation-${entry.thread_id}`}>
- <span className="truncate font-mono text-xs text-content">{entry.thread_id}</span>
- <span className="shrink-0 text-xs text-content-muted">
- {fill(t('memoryPage.conversations.turns'), { count: entry.turns })}
- {formatTimestamp(entry.stored_at) ? ` · ${formatTimestamp(entry.stored_at)}` : ''}
- </span>
+ {(agents ?? []).map(agent => (
+ <li key={agent.agent_id} data-testid={`memory-agent-${agent.agent_id}`}>
+ <button
+ type="button"
+ className="flex w-full items-center justify-between gap-3 px-4 py-2.5 text-left hover:bg-surface-hover"
+ aria-expanded={openAgent === agent.agent_id}
+ data-testid={`memory-agent-${agent.agent_id}-open`}
+ onClick={() => toggleAgent(agent.agent_id)}>
+ <span className="truncate font-mono text-xs text-content">{agent.agent_id}</span>
+ <span className="shrink-0 text-xs text-content-muted">
+ {fill(t('memoryPage.conversations.turns'), { count: agent.turns })}
+ </span>
+ </button>
+ {openAgent === agent.agent_id && (
+ <div
+ className="border-t border-line-subtle"
+ data-testid={`memory-agent-${agent.agent_id}-items`}>
+ {items === null ? (
+ <CenteredLoadingState label={t('memoryPage.loading')} />
+ ) : items.length === 0 ? (
+ <p className="px-4 py-3 text-sm text-content-muted">
+ {t('memoryPage.conversations.itemsEmpty')}
+ </p>
+ ) : (
+ <ul className="divide-y divide-line-subtle">
+ {items.map(item => (
+ <MemoryHitRow
+ key={item.id}
+ id={item.id}
+ kind={item.kind}
+ text={item.text}
+ meta={item.meta}
+ />
+ ))}
+ </ul>
+ )}
+ {cursor && (
+ <div className="px-4 py-3">
+ <Button
+ type="button"
+ variant="secondary"
+ size="sm"
+ data-testid="memory-conversations-more"
+ disabled={loadingItems}
+ onClick={() => void loadItems(agent.agent_id, cursor)}>
+ {t('memoryPage.loadMore')}
+ </Button>
+ </div>
+ )}
+ </div>
+ )}
</li>
))}
</ul>