Skip to content

Commit 402efff

Browse files
committed
feat(journal-entries): implemented journal entry editor & document blocks
1 parent 656ead7 commit 402efff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+810
-666
lines changed

apps/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@radix-ui/react-tooltip": "^1.2.7",
4545
"@t3-oss/env-nextjs": "^0.13.6",
4646
"@tanstack/react-query": "^5.80.7",
47+
"@tanstack/react-query-devtools": "^5.80.7",
4748
"@tanstack/react-virtual": "^3.13.12",
4849
"@trpc/client": "^11.4.0",
4950
"@trpc/server": "^11.4.0",

apps/web/src/ai/mastra/tools/semantic-journal-search.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ export const semanticJournalSearch = createTool({
66
description:
77
"Search the journal for entries that are semantically similar to a query",
88
execute: async ({ context }) => {
9-
console.debug("[semanticJournalSearch] context 👀", context);
10-
119
const results = await api.journal.getRelevantEntries({
1210
limit: context.limit,
1311
query: context.query,
@@ -17,7 +15,6 @@ export const semanticJournalSearch = createTool({
1715
return results.map((result) => ({
1816
content: result.embedding.chunk_markdown_text,
1917
date: result.journal_entry.date,
20-
id: result.journal_entry.id,
2118
link: `/journal/${result.journal_entry.date}`,
2219
similarity: result.similarity,
2320
}));
@@ -35,7 +32,7 @@ export const semanticJournalSearch = createTool({
3532
z.object({
3633
content: z.string(),
3734
date: z.string(),
38-
id: z.string(),
35+
link: z.string(),
3936
similarity: z.number(),
4037
}),
4138
),

apps/web/src/ai/mastra/tools/semantic-page-search.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ export const semanticPageSearch = createTool({
66
description:
77
"Search the pages for all entries that are semantically similar to a query. Returns multiple relevant results from different pages that should all be analyzed and synthesized.",
88
execute: async ({ context }) => {
9-
console.debug("[semanticPageSearch] context 👀", context);
10-
11-
const result = await api.pages.getRelevantPageChunks({
9+
const result = await api.pages.getRelevantPages({
1210
limit: context.limit,
1311
query: context.query,
1412
threshold: context.threshold,

apps/web/src/ai/mastra/tools/temporal-journal-search.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1+
import { ServerBlockNoteEditor } from "@blocknote/server-util";
12
import { createTool } from "@mastra/core/tools";
3+
import { MDocument } from "@mastra/rag";
24
import { z } from "zod";
5+
import { schema } from "~/components/editor/block-schema";
36
import { api } from "~/trpc/server";
47

58
export const temporalJournalSearch = createTool({
69
description: "Search the journal for entries between two dates",
710
execute: async ({ context }) => {
8-
console.debug("[temporalJournalSearch] context 👀", context);
9-
1011
const results = await api.journal.getBetween({
1112
from: context.from,
1213
to: context.to,
1314
});
1415

15-
return results.map((result) => ({
16-
...result,
17-
link: `/journal/${result.date}`,
18-
}));
16+
return await Promise.all(
17+
results.map(async (result) => {
18+
const editor = ServerBlockNoteEditor.create({
19+
schema,
20+
});
21+
const markdown = result.document
22+
? await editor.blocksToMarkdownLossy(result.document)
23+
: "";
24+
const mDocument = MDocument.fromMarkdown(markdown);
25+
return {
26+
content: mDocument.getText().join("\n"),
27+
date: result.date,
28+
id: result.id,
29+
link: `/journal/${result.date}`,
30+
};
31+
}),
32+
);
1933
},
2034
id: "temporal-journal-search",
2135
inputSchema: z.object({
@@ -35,6 +49,7 @@ export const temporalJournalSearch = createTool({
3549
content: z.string(),
3650
date: z.string(),
3751
id: z.string(),
52+
link: z.string(),
3853
}),
3954
),
4055
});

apps/web/src/app/(app)/@appSidebar/_components/app-sidebar-page-item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function AppSidebarPageItem(props: AppSidebarPageItemProps) {
3838
</Link>
3939
{!!page && (
4040
<DeletePageButton
41-
className="hover:!bg-transparent hover:!text-destructive opacity-0 transition-opacity duration-200 group-hover/page-item:opacity-100"
41+
className="!text-destructive !bg-transparent !pr-0 hidden group-hover/page-item:block"
4242
page={page}
4343
/>
4444
)}

apps/web/src/app/(app)/@appSidebar/_components/app-sidebar-pages.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const AppSidebarPages = (props: AppSidebarPagesProps) => {
2929
const { state, setOpen } = useSidebar();
3030

3131
const { data: pages } = useQuery({
32-
...trpc.pages.getAll.queryOptions(),
32+
...trpc.pages.getByUser.queryOptions(),
3333
initialData: props.pages,
3434
});
3535

@@ -62,7 +62,7 @@ export const AppSidebarPages = (props: AppSidebarPagesProps) => {
6262
</SidebarMenuButton>
6363
</CollapsibleTrigger>
6464
<CollapsibleContent>
65-
<SidebarMenuSub>
65+
<SidebarMenuSub className="mr-0 pr-0">
6666
<CreatePageButton />
6767
{pages?.map((page) => (
6868
<AppSidebarPageItem key={page.id} page={page} />

apps/web/src/app/(app)/@appSidebar/_components/create-page-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function CreatePageButton() {
3636
onSuccess: (newPage) => {
3737
// Optimistically update the pages list
3838
queryClient.setQueryData(
39-
trpc.pages.getAll.queryOptions().queryKey,
39+
trpc.pages.getByUser.queryOptions().queryKey,
4040
(oldPages: Page[] | undefined) => {
4141
if (!oldPages) return [newPage];
4242
return [newPage, ...oldPages];

apps/web/src/app/(app)/@appSidebar/_components/delete-page-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function DeletePageButton({ page, className }: DeletePageButtonProps) {
5555

5656
// Optimistically update the pages list
5757
queryClient.setQueryData(
58-
trpc.pages.getAll.queryOptions().queryKey,
58+
trpc.pages.getByUser.queryOptions().queryKey,
5959
(oldPages: Page[] | undefined) => {
6060
if (!oldPages) return [];
6161
return oldPages.filter((p) => p.id !== page.id);

apps/web/src/app/(app)/@appSidebar/default.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { AppSidebarUser } from "./_components/app-sidebar-user";
1515
import { AppSidebarUserSkeleton } from "./_components/app-sidebar-user-skeleton";
1616

1717
async function SuspendedAppSidebarPages() {
18-
const pages = await api.pages.getAll();
18+
const pages = await api.pages.getByUser();
1919
return <AppSidebarPages pages={pages} />;
2020
}
2121

apps/web/src/app/(app)/@header/_components/header-search-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { useTRPC } from "~/trpc/react";
3131
const MIN_QUERY_LENGTH = 2;
3232
const DEFAULT_THRESHOLD = 0.25;
3333
const DEFAULT_LIMIT = 10;
34-
const DEFAULT_DEBOUNCE_TIME = 500;
34+
const DEFAULT_DEBOUNCE_TIME = 150;
3535

3636
type HeaderSearchButtonProps = React.ComponentProps<typeof Dialog> & {
3737
children: React.ReactNode;

0 commit comments

Comments
 (0)