Skip to content

Commit

Permalink
Add feature to show timestamp of memories in DSNViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Xm0onh committed Jan 15, 2025
1 parent b39ef08 commit 3888d7e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions agent-memory-viewer/backend/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export async function getAllDsn(
tweet_id: content.tweet?.id || null,
cid: record.cid,
created_at: record.created_at,
timestamp: content.timestamp || null,
author_username: content.tweet?.username || content.tweet?.author_username ||
(content.type === 'posted' ? config.AGENT_USERNAME : null),
tweet_content: content.tweet?.text || null,
Expand Down
12 changes: 9 additions & 3 deletions agent-memory-viewer/frontend/src/components/DSNViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { colors } from '../styles/theme/colors';
import { useSearchParams } from 'react-router-dom';
import SearchBar from './SearchBar';
import StatusFilter from './StatusFilter';
import { getRelativeTime } from '../utils/timeUtils';

function DSNViewer() {
const [searchParams, setSearchParams] = useSearchParams();
Expand Down Expand Up @@ -95,9 +96,14 @@ function DSNViewer() {
>
<Card {...cardStyles.baseStyle}>
<CardBody {...cardStyles.bodyStyle}>
<Text {...textStyles.heading}>
Tweet by @{item.author_username}
</Text>
<HStack justify="space-between" mb={2}>
<Text {...textStyles.heading}>
Tweet by @{item.author_username}
</Text>
<Text color="gray.400" fontSize="sm">
{getRelativeTime(item.timestamp)}
</Text>
</HStack>
<Text {...textStyles.value} whiteSpace="pre-wrap" mb={4}>
{item.tweet_content}
</Text>
Expand Down
1 change: 1 addition & 0 deletions agent-memory-viewer/frontend/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export interface DSNData {
tweet_id: string
cid: string
created_at: string
timestamp: string
author_username: string
tweet_content: string
response_content: string
Expand Down
32 changes: 32 additions & 0 deletions agent-memory-viewer/frontend/src/utils/timeUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export function getRelativeTime(timestamp: string): string {
const date = new Date(timestamp);
const now = new Date();
const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);

if (diffInSeconds < 60) {
return `${diffInSeconds}s ago`;
}

const diffInMinutes = Math.floor(diffInSeconds / 60);
if (diffInMinutes < 60) {
return `${diffInMinutes}m ago`;
}

const diffInHours = Math.floor(diffInMinutes / 60);
if (diffInHours < 24) {
return `${diffInHours}h ago`;
}

const diffInDays = Math.floor(diffInHours / 24);
if (diffInDays < 30) {
return `${diffInDays}d ago`;
}

const diffInMonths = Math.floor(diffInDays / 30);
if (diffInMonths < 12) {
return `${diffInMonths}mo ago`;
}

const diffInYears = Math.floor(diffInDays / 365);
return `${diffInYears}y ago`;
}

0 comments on commit 3888d7e

Please sign in to comment.