Skip to content

Commit 3abb431

Browse files
works on adding user context
1 parent 98fbb53 commit 3abb431

File tree

7 files changed

+132
-1
lines changed

7 files changed

+132
-1
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
"rust-analyzer.cargo.targetDir": "target/analyzer",
2222
"rust-analyzer.cargo.extraEnv": {
2323
"MACOSX_DEPLOYMENT_TARGET": "14.2"
24+
},
25+
"[typescriptreact]": {
26+
"editor.defaultFormatter": "vscode.typescript-language-features"
2427
}
2528
}

apps/desktop/src/components/editor-area/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,30 @@ import { toast } from "@hypr/ui/components/ui/toast";
2222
import { cn } from "@hypr/ui/lib/utils";
2323
import { generateText, localProviderName, modelProvider, smoothStream, streamText, tool } from "@hypr/utils/ai";
2424
import { useOngoingSession, useSession, useSessions } from "@hypr/utils/contexts";
25+
import { load } from "@tauri-apps/plugin-store";
2526
import { enhanceFailedToast } from "../toast/shared";
2627
import { AnnotationBox } from "./annotation-box";
2728
import { FloatingButton } from "./floating-button";
2829
import { NoteHeader } from "./note-header";
2930
import { TextSelectionPopover } from "./text-selection-popover";
3031

32+
const getUserContext = async (): Promise<{ value: string } | null> => {
33+
try {
34+
const store = await load("store.json", { autoSave: false })
35+
const val = await store.get("user_context")
36+
if (val && typeof val === "object" && "value" in val) {
37+
return val as { value: string }
38+
}
39+
return null
40+
} catch (error) {
41+
console.error("Failed to fetch user context", error)
42+
return null
43+
}
44+
}
45+
46+
47+
48+
3149
async function generateTitleDirect(
3250
enhancedContent: string,
3351
targetSessionId: string,
@@ -448,11 +466,14 @@ export function useEnhanceMutation({
448466

449467
let customInstruction = selectedTemplate?.description;
450468

469+
let userContext = await getUserContext() || "";
470+
451471
const systemMessage = await templateCommands.render(
452472
"enhance.system",
453473
{
454474
config,
455475
type,
476+
userContext,
456477
// Pass userHeaders when using H1 headers, templateInfo otherwise
457478
...(shouldUseH1Headers
458479
? { userHeaders: h1Headers }

apps/desktop/src/components/settings/components/tab-icon.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
MessageSquareIcon,
1010
SettingsIcon,
1111
SparklesIcon,
12+
UserIcon,
1213
} from "lucide-react";
1314

1415
import { type Tab } from "./types";
@@ -56,6 +57,8 @@ export function TabIcon({ tab }: { tab: Tab }) {
5657
return <CreditCardIcon className="h-4 w-4" />;
5758
case "mcp":
5859
return <McpIcon className="h-4 w-4" />;
60+
case "user-context":
61+
return <UserIcon className="h-4 w-4" />;
5962
default:
6063
return null;
6164
}

apps/desktop/src/components/settings/components/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
NetworkIcon,
1010
Settings,
1111
Sparkles,
12+
User,
1213
Volume2,
1314
} from "lucide-react";
1415

@@ -23,7 +24,8 @@ export type Tab =
2324
| "feedback"
2425
| "integrations"
2526
| "mcp"
26-
| "billing";
27+
| "billing"
28+
| "user-context";
2729

2830
export const TABS: { name: Tab; icon: LucideIcon }[] = [
2931
{ name: "general", icon: Settings },
@@ -37,4 +39,5 @@ export const TABS: { name: Tab; icon: LucideIcon }[] = [
3739
{ name: "mcp", icon: NetworkIcon },
3840
{ name: "billing", icon: CreditCard },
3941
{ name: "feedback", icon: BlocksIcon },
42+
{ name: "user-context", icon: User },
4043
];
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { Button } from "@hypr/ui/components/ui/button";
2+
import { Textarea } from "@hypr/ui/components/ui/textarea";
3+
import { toast } from "@hypr/ui/components/ui/toast";
4+
import { load } from "@tauri-apps/plugin-store";
5+
import React, { useEffect, useRef, useState } from "react";
6+
7+
export default function UserContext() {
8+
const [isLoading, setIsLoading] = useState(false);
9+
const textAreaRef = useRef<HTMLTextAreaElement>(null);
10+
const [userContext, setUserContext] = useState<{ value: string } | null>(null);
11+
12+
const showUserContextToast = (content: string) => {
13+
toast({
14+
id: "user-context",
15+
title: "User Context",
16+
content: content,
17+
dismissible: true,
18+
});
19+
};
20+
21+
const getStore = async () => {
22+
return await load("store.json", { autoSave: false });
23+
};
24+
25+
const getUserContext = async (): Promise<{ value: string } | null> => {
26+
let store = await getStore();
27+
let userContext = await store.get("user_context");
28+
29+
return userContext as { value: string } | null;
30+
};
31+
32+
const handleSave = async () => {
33+
try {
34+
setIsLoading(true);
35+
let store = await getStore();
36+
37+
if (!store) {
38+
showUserContextToast("Failed to retrieve user store");
39+
setIsLoading(false);
40+
return;
41+
}
42+
43+
if (!textAreaRef?.current?.value) {
44+
showUserContextToast("Failed to save user context");
45+
setIsLoading(false);
46+
return;
47+
}
48+
49+
store.set("user_context", { value: textAreaRef?.current?.value });
50+
await store.save();
51+
showUserContextToast("User context saved successfully");
52+
setIsLoading(false);
53+
} catch (error) {
54+
setIsLoading(false);
55+
console.log("Failed to save user context with error ", error);
56+
}
57+
};
58+
59+
useEffect(() => {
60+
getUserContext().then((val) => {
61+
setUserContext(val);
62+
}).catch((e) => {
63+
console.log(e);
64+
});
65+
}, []);
66+
67+
return (
68+
<div className="flex-1 ">
69+
<div className="mb-2">
70+
<p className="text-black ">User Context</p>
71+
</div>
72+
<Textarea
73+
className="h-full"
74+
ref={textAreaRef}
75+
placeholder={`${userContext?.value || "Enter details about yourself"}`}
76+
>
77+
</Textarea>
78+
79+
<div className="mt-2 flex flex-row w-full justify-center">
80+
<Button
81+
isLoading={isLoading}
82+
className="w-3/4"
83+
onClick={handleSave}
84+
>
85+
<span className="text-white">Save</span>
86+
</Button>
87+
</div>
88+
</div>
89+
);
90+
}

apps/desktop/src/routes/app.settings.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
Sound,
2020
TemplatesView,
2121
} from "@/components/settings/views";
22+
import UserContext from "@/components/settings/views/user-context";
2223
import { cn } from "@hypr/ui/lib/utils";
2324

2425
const schema = z.object({
@@ -71,6 +72,8 @@ function Component() {
7172
return t`License`;
7273
case "mcp":
7374
return t`MCP`;
75+
case "user-context":
76+
return t`User Context`;
7477
default:
7578
return tab;
7679
}
@@ -140,6 +143,7 @@ function Component() {
140143
{search.tab === "integrations" && <Integrations />}
141144
{search.tab === "mcp" && <MCP />}
142145
{search.tab === "billing" && <Billing />}
146+
{search.tab === "user-context" && <UserContext />}
143147
</div>
144148
</div>
145149
</div>

crates/template/assets/enhance.system.jinja

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ You will be given multiple inputs from the user. Below are useful information th
6363
- The beginning of a raw note may include agenda items, discussion topics, and preliminary questions.
6464
- Primarily consist of key phrases or sentences the user wants to remember, though they may also contain random or extraneous words.
6565
- May sometimes be empty.
66+
- User Context (txt)
67+
68+
The User Context contains important background details about the user, such as their role, company, ongoing projects, style/tone preferences, and domain terminology.
69+
You must always take this into account when generating enhanced notes to make them more relevant and personalized.
70+
71+
Here is the User Context:
72+
{{ userContext}}
6673

6774
# Enhanced Note Format
6875

0 commit comments

Comments
 (0)