-
Notifications
You must be signed in to change notification settings - Fork 415
works on adding user context #1369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
steven-mpawulo
wants to merge
3
commits into
fastrepl:main
Choose a base branch
from
steven-mpawulo:add-user-context
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,12 +22,30 @@ import { toast } from "@hypr/ui/components/ui/toast"; | |||||
| import { cn } from "@hypr/ui/lib/utils"; | ||||||
| import { generateText, localProviderName, modelProvider, smoothStream, streamText, tool } from "@hypr/utils/ai"; | ||||||
| import { useOngoingSession, useSession, useSessions } from "@hypr/utils/contexts"; | ||||||
| import { load } from "@tauri-apps/plugin-store"; | ||||||
| import { enhanceFailedToast } from "../toast/shared"; | ||||||
| import { AnnotationBox } from "./annotation-box"; | ||||||
| import { FloatingButton } from "./floating-button"; | ||||||
| import { NoteHeader } from "./note-header"; | ||||||
| import { TextSelectionPopover } from "./text-selection-popover"; | ||||||
|
|
||||||
| const getUserContext = async (): Promise<{ value: string } | null> => { | ||||||
| try { | ||||||
| const store = await load("store.json", { autoSave: false }) | ||||||
| const val = await store.get("user_context") | ||||||
| if (val && typeof val === "object" && "value" in val) { | ||||||
| return val as { value: string } | ||||||
| } | ||||||
| return null | ||||||
| } catch (error) { | ||||||
| console.error("Failed to fetch user context", error) | ||||||
| return null | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| async function generateTitleDirect( | ||||||
| enhancedContent: string, | ||||||
| targetSessionId: string, | ||||||
|
|
@@ -448,11 +466,14 @@ export function useEnhanceMutation({ | |||||
|
|
||||||
| let customInstruction = selectedTemplate?.description; | ||||||
|
|
||||||
| let userContext = await getUserContext() || ""; | ||||||
|
||||||
| let userContext = await getUserContext() || ""; | |
| let userContext = (await getUserContext())?.value ?? ""; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
apps/desktop/src/components/settings/views/user-context.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { Button } from "@hypr/ui/components/ui/button"; | ||
| import { Textarea } from "@hypr/ui/components/ui/textarea"; | ||
| import { toast } from "@hypr/ui/components/ui/toast"; | ||
| import { load } from "@tauri-apps/plugin-store"; | ||
| import React, { useEffect, useRef, useState } from "react"; | ||
|
|
||
| export default function UserContext() { | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const textAreaRef = useRef<HTMLTextAreaElement>(null); | ||
| const [userContext, setUserContext] = useState<{ value: string } | null>(null); | ||
|
|
||
| const showUserContextToast = (content: string) => { | ||
| toast({ | ||
| id: "user-context", | ||
| title: "User Context", | ||
| content: content, | ||
| dismissible: true, | ||
| }); | ||
| }; | ||
|
|
||
| const getStore = async () => { | ||
| return await load("store.json", { autoSave: false }); | ||
| }; | ||
|
|
||
| const getUserContext = async (): Promise<{ value: string } | null> => { | ||
| let store = await getStore(); | ||
| let userContext = await store.get("user_context"); | ||
|
|
||
| return userContext as { value: string } | null; | ||
| }; | ||
|
|
||
| const handleSave = async () => { | ||
| try { | ||
| setIsLoading(true); | ||
| let store = await getStore(); | ||
|
|
||
| if (!store) { | ||
| showUserContextToast("Failed to retrieve user store"); | ||
| setIsLoading(false); | ||
| return; | ||
| } | ||
|
|
||
| if (!textAreaRef?.current?.value) { | ||
| showUserContextToast("Failed to save user context"); | ||
| setIsLoading(false); | ||
| return; | ||
| } | ||
|
|
||
| store.set("user_context", { value: textAreaRef?.current?.value }); | ||
| await store.save(); | ||
| showUserContextToast("User context saved successfully"); | ||
| setIsLoading(false); | ||
| } catch (error) { | ||
| setIsLoading(false); | ||
| console.log("Failed to save user context with error ", error); | ||
| } | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| getUserContext().then((val) => { | ||
| setUserContext(val); | ||
| }).catch((e) => { | ||
| console.log(e); | ||
| }); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div className="flex-1 "> | ||
| <div className="mb-2"> | ||
| <p className="text-black ">User Context</p> | ||
| </div> | ||
| <Textarea | ||
| className="h-full" | ||
| ref={textAreaRef} | ||
| placeholder={`${userContext?.value || "Enter details about yourself"}`} | ||
| > | ||
| </Textarea> | ||
|
|
||
| <div className="mt-2 flex flex-row w-full justify-center"> | ||
| <Button | ||
| isLoading={isLoading} | ||
| className="w-3/4" | ||
| onClick={handleSave} | ||
| > | ||
| <span className="text-white">Save</span> | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.