Skip to content

Commit fe5e27f

Browse files
committed
Merge branch 'main' into feat/track-ai-usage
2 parents d155da6 + 5f5a83c commit fe5e27f

Some content is hidden

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

45 files changed

+1051
-389
lines changed

apps/drizzle-studio/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "@acme/drizzle-studio",
3-
"version": "0.0.0",
4-
"private": true,
5-
"type": "module",
6-
"scripts": {
7-
"dev": "NODE_ENV=development pnpm with-env pnpm --filter=db studio",
8-
"with-env": "dotenv -e ../../.env --"
9-
},
10-
"devDependencies": {
11-
"@acme/db": "workspace:*",
12-
"dotenv-cli": "^8.0.0"
13-
}
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "NODE_ENV=development pnpm with-env pnpm --filter=db studio",
8+
"with-env": "dotenv -e ../../.env --"
9+
},
10+
"devDependencies": {
11+
"@acme/db": "workspace:*",
12+
"dotenv-cli": "^8.0.0"
13+
}
1414
}

apps/web/next.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ const config = {
1010
/** We already do linting and typechecking as separate tasks in CI */
1111
eslint: { ignoreDuringBuilds: true },
1212
/** These packages won't be bundled in the server build */
13-
serverExternalPackages: ["@mastra/*"],
13+
/** @see https://nextjs.org/docs/app/api-reference/config/next-config-js/serverExternalPackages */
14+
serverExternalPackages: [
15+
"@mastra/*",
16+
"@blocknote/server-util",
17+
"@blocknote/react",
18+
"@blocknote/core",
19+
],
1420
/** Enables hot reloading for local packages without a build step */
1521
transpilePackages: ["@acme/api", "@acme/auth", "@acme/db"],
1622
typescript: { ignoreBuildErrors: true },

apps/web/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
"@blocknote/core": "^0.35.0",
2626
"@blocknote/mantine": "^0.35.0",
2727
"@blocknote/react": "^0.35.0",
28+
"@blocknote/server-util": "^0.35.0",
2829
"@daveyplate/better-auth-ui": "^2.1.0",
2930
"@hookform/resolvers": "^5.0.1",
3031
"@mantine/core": "^8.1.3",
3132
"@mastra/core": "^0.12.1",
3233
"@mastra/libsql": "^0.12.0",
3334
"@mastra/loggers": "^0.10.5",
3435
"@mastra/memory": "^0.12.0",
36+
"@mastra/rag": "^1.1.0",
3537
"@ngrok/ngrok": "^1.5.1",
3638
"@radix-ui/react-avatar": "^1.1.10",
3739
"@radix-ui/react-dialog": "^1.1.14",
@@ -61,6 +63,7 @@
6163
"react-hook-form": "^7.57.0",
6264
"react-virtuoso": "^4.13.0",
6365
"remark-gfm": "^4.0.1",
66+
"remove-markdown": "^0.6.2",
6467
"sonner": "^2.0.5",
6568
"superjson": "2.2.2",
6669
"tailwind-merge": "^3.3.0",

apps/web/src/ai/mastra/agents/journl-agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Agent } from "@mastra/core/agent";
2-
import { model } from "~/ai/providers/openai/llm";
2+
import { model } from "~/ai/providers/openai/text";
33
import { semanticJournalSearch } from "../tools/semantic-journal-search";
44
import { semanticPageSearch } from "../tools/semantic-page-search";
55
import { temporalJournalSearch } from "../tools/temporal-journal-search";

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ export const semanticJournalSearch = createTool({
1515
});
1616

1717
return results.map((result) => ({
18-
...result,
19-
link: `/journal/${result.date}`,
18+
content: result.embedding.chunk_markdown_text,
19+
date: result.journal_entry.date,
20+
id: result.journal_entry.id,
21+
link: `/journal/${result.journal_entry.date}`,
22+
similarity: result.similarity,
2023
}));
2124
},
2225
id: "semantic-journal-search",

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ export const semanticPageSearch = createTool({
1515
});
1616

1717
return result.map((result) => ({
18-
...result,
19-
link: `/pages/${result.page_id}`,
18+
content: result.embedding.chunk_markdown_text,
19+
link: `/pages/${result.page.id}`,
20+
page_id: result.page.id,
21+
page_title: result.page.title,
22+
similarity: result.similarity,
2023
}));
2124
},
2225
id: "semantic-page-search",
@@ -31,6 +34,7 @@ export const semanticPageSearch = createTool({
3134
outputSchema: z.array(
3235
z.object({
3336
content: z.string(),
37+
link: z.string(),
3438
page_id: z.string(),
3539
page_title: z.string(),
3640
similarity: z.number(),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { openai } from "@ai-sdk/openai";
22

3-
// TODO: Move this to a shared package called `@acme/ai`.
3+
// ! TODO: Move this to a shared package called `@acme/ai`.
44
export const model = openai.embedding("text-embedding-3-small");
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { openai } from "@ai-sdk/openai";
22

3-
// TODO: Move this to a shared package called `@acme/ai`.
3+
// ! TODO: Move this to a shared package called `@acme/ai`.
44
export const model = openai("gpt-4o-mini");

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { X } from "lucide-react";
44
import Link from "next/link";
55
import { useRouter } from "next/navigation";
66
import { useEffect, useState } from "react";
7+
import { useDebounce } from "use-debounce";
78
import { Badge } from "~/components/ui/badge";
89
import { Button } from "~/components/ui/button";
910
import {
@@ -30,22 +31,27 @@ import { useTRPC } from "~/trpc/react";
3031
const MIN_QUERY_LENGTH = 2;
3132
const DEFAULT_THRESHOLD = 0.25;
3233
const DEFAULT_LIMIT = 10;
34+
const DEFAULT_DEBOUNCE_TIME = 500;
35+
3336
type HeaderSearchButtonProps = React.ComponentProps<typeof Dialog> & {
3437
children: React.ReactNode;
3538
limit?: number;
3639
threshold?: number;
40+
debounceTime?: number;
3741
};
3842

3943
export function HeaderSearchButton({
4044
children,
4145
limit = DEFAULT_LIMIT,
4246
threshold = DEFAULT_THRESHOLD,
47+
debounceTime = DEFAULT_DEBOUNCE_TIME,
4348
...rest
4449
}: HeaderSearchButtonProps) {
4550
const isMobile = useIsMobile();
4651
const [isOpen, setIsOpen] = useState(false);
4752
const [query, setQuery] = useState("");
4853
const router = useRouter();
54+
const [debouncedQuery] = useDebounce(query, debounceTime);
4955

5056
// Keyboard shortcut handlers
5157
useEffect(() => {
@@ -65,13 +71,17 @@ export function HeaderSearchButton({
6571
}, [isOpen]);
6672

6773
const trpc = useTRPC();
68-
const { data: notes, isLoading } = useQuery({
74+
const {
75+
data: notes,
76+
isLoading,
77+
isError,
78+
} = useQuery({
6979
...trpc.notes.getSimilarNotes.queryOptions({
7080
limit,
71-
query,
81+
query: debouncedQuery,
7282
threshold,
7383
}),
74-
enabled: query.length > MIN_QUERY_LENGTH,
84+
enabled: debouncedQuery.length > MIN_QUERY_LENGTH,
7585
});
7686

7787
return (
@@ -97,7 +107,6 @@ export function HeaderSearchButton({
97107
autoCorrect="off"
98108
spellCheck={false}
99109
autoFocus
100-
value={query}
101110
onValueChange={(value) => setQuery(value)}
102111
/>
103112
</div>
@@ -113,7 +122,9 @@ export function HeaderSearchButton({
113122
</div>
114123
) : !notes ? (
115124
<span className="text-muted-foreground text-sm">
116-
Write something to search
125+
{isError
126+
? "Something went wrong. Please try again later."
127+
: "Write something to search."}
117128
</span>
118129
) : (
119130
<span className="text-muted-foreground text-sm">

apps/web/src/app/(app)/journal/_components/journal-entry.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use client";
22

3+
import type { PlaceholderJournalEntry } from "@acme/api";
34
import type { JournalEntry } from "@acme/db/schema";
45
import { useMutation } from "@tanstack/react-query";
56
import Link from "next/link";
6-
import type { PlaceholderJournalEntry } from "node_modules/@acme/api/src/router/journal";
77
import type React from "react";
88
import {
99
type ComponentProps,

0 commit comments

Comments
 (0)