-
Notifications
You must be signed in to change notification settings - Fork 107
feat(chat): add starred models to the agent model picker #287
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
NickTitle
wants to merge
24
commits into
main
Choose a base branch
from
nesposito/starred-models-picker-block
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 all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d2f0c0e
feat(chat): add starred models to the agent model picker
NickTitle 0ed3806
fix(chat): keep starred models visible in the compact picker list
NickTitle 8811486
fix(chat): fit picker within min window width; hover-reveal stars wit…
NickTitle d8b07c5
fix(chat): render star action through shared Button with semantic sel…
NickTitle af9ffaa
fix(chat): store each starred model as its own localStorage entry
NickTitle 34d27b3
fix(chat): toast when starred-model writes fail instead of swallowing
NickTitle b112d29
fix(chat): hide starred models the catalog no longer serves
NickTitle 906ba71
fix(chat): scope star reveal state to each model row
NickTitle 53aa113
fix(chat): clear model star reveal with explicit row state
NickTitle bc1cca2
fix(chat): remove trailing fade from model star reveal
NickTitle cf4cda8
fix(chat): restore a quick model star fade
NickTitle ddad0ca
Revert "fix(chat): restore a quick model star fade"
NickTitle 2efce9c
fix(chat): fade model stars in without trailing on exit
NickTitle f0fbe13
fix(chat): make model star fade-in perceptible
NickTitle 7d25d08
fix(chat): keep favorited model stars visible
NickTitle 0bcc1f9
feat(chat): animate favorite model layout changes
NickTitle 7d8dd78
feat(chat): stage star toggle animation around row movement
NickTitle 8d892c3
fix(chat): keep favorites visible across agent changes
NickTitle 2c9bfc5
fix(chat): show owning agent icons on cross-agent favorites
NickTitle eeecf35
fix(chat): stabilize favorite animations and picker layout
NickTitle 34343e3
fix(chat): reduce favorite star motion to a half turn
NickTitle c1e5ffd
fix(chat): wrap selected model pill around star
NickTitle d63418c
fix(chat): simplify and refresh starred-model state
NickTitle 6126f3c
fix(chat): clarify cross-agent favorite rows
NickTitle 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
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
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,70 @@ | ||
| import { useCallback, useSyncExternalStore } from "react"; | ||
| import { | ||
| getStarredModelKeys, | ||
| modelStarKey, | ||
| STARRED_MODELS_ENTRY_PREFIX, | ||
| STARRED_MODELS_EVENT, | ||
| toggleModelStar, | ||
| } from "../lib/starredModels"; | ||
|
|
||
| let cachedSnapshot: Set<string> | null = null; | ||
| const serverSnapshot = new Set<string>(); | ||
|
|
||
| /** Invalidate the in-memory snapshot cache. Intended for tests. */ | ||
| export function __resetStarredModelsCacheForTests(): void { | ||
| cachedSnapshot = null; | ||
| } | ||
|
|
||
| function getSnapshot(): Set<string> { | ||
| if (cachedSnapshot === null) { | ||
| cachedSnapshot = getStarredModelKeys(); | ||
| } | ||
| return cachedSnapshot; | ||
| } | ||
|
|
||
| function subscribe(callback: () => void): () => void { | ||
| const handleChange = () => { | ||
| cachedSnapshot = null; | ||
| callback(); | ||
| }; | ||
| const handleStorage = (event: StorageEvent) => { | ||
| // Star entries live under per-key storage, so any entry write or removal | ||
| // in another window changes the set. `key === null` covers localStorage | ||
| // clears. | ||
| if ( | ||
| event.key === null || | ||
| event.key.startsWith(STARRED_MODELS_ENTRY_PREFIX) | ||
| ) { | ||
| handleChange(); | ||
| } | ||
| }; | ||
|
|
||
| window.addEventListener(STARRED_MODELS_EVENT, handleChange); | ||
| window.addEventListener("storage", handleStorage); | ||
| // No listener exists while the store has no subscribers. Invalidate after | ||
| // attaching both listeners so a remount rereads changes made during that gap. | ||
| cachedSnapshot = null; | ||
| return () => { | ||
| window.removeEventListener(STARRED_MODELS_EVENT, handleChange); | ||
| window.removeEventListener("storage", handleStorage); | ||
| }; | ||
| } | ||
|
|
||
| export function useStarredModels() { | ||
| const starredKeys = useSyncExternalStore( | ||
| subscribe, | ||
| getSnapshot, | ||
| () => serverSnapshot, | ||
| ); | ||
| const isStarred = useCallback( | ||
| (scopeId: string, modelId: string) => | ||
| starredKeys.has(modelStarKey(scopeId, modelId)), | ||
| [starredKeys], | ||
| ); | ||
| const toggleStar = useCallback( | ||
| (scopeId: string, modelId: string) => toggleModelStar(scopeId, modelId), | ||
| [], | ||
| ); | ||
|
|
||
| return { isStarred, toggleStar, starredKeys }; | ||
| } | ||
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,102 @@ | ||
| import { toast } from "sonner"; | ||
| import { i18n } from "@/shared/i18n"; | ||
|
|
||
| export const STARRED_MODELS_ENTRY_PREFIX = "goose:starredModels:v1:entry:"; | ||
| const STARRED_MODELS_ENTRY_VALUE = "1"; | ||
| const STARRED_MODELS_CHANGED_EVENT = "goose:starred-models-changed"; | ||
|
|
||
| type StarredModelSet = Set<string>; | ||
|
|
||
| export function modelStarKey(scopeId: string, modelId: string): string { | ||
| return JSON.stringify([scopeId, modelId]); | ||
| } | ||
|
|
||
| /** localStorage key of the single entry that records one starred model. */ | ||
| export function starredModelStorageKey(starKey: string): string { | ||
| return STARRED_MODELS_ENTRY_PREFIX + encodeURIComponent(starKey); | ||
| } | ||
|
|
||
| function readStarredModels(): StarredModelSet { | ||
| if (typeof window === "undefined") { | ||
| return new Set(); | ||
| } | ||
|
|
||
| try { | ||
| const storage = window.localStorage; | ||
| const starred = new Set<string>(); | ||
| for (let i = 0; i < storage.length; i += 1) { | ||
| const storageKey = storage.key(i); | ||
| if (!storageKey?.startsWith(STARRED_MODELS_ENTRY_PREFIX)) { | ||
| continue; | ||
| } | ||
| try { | ||
| starred.add( | ||
| decodeURIComponent( | ||
| storageKey.slice(STARRED_MODELS_ENTRY_PREFIX.length), | ||
| ), | ||
| ); | ||
| } catch { | ||
| // Skip a malformed entry rather than dropping every star. | ||
| } | ||
| } | ||
| return starred; | ||
| } catch { | ||
| return new Set(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Write or clear exactly one star entry. Touching a single key (instead of | ||
| * rewriting an aggregate array) removes the cross-window read-modify-write | ||
| * race where concurrent toggles from different windows could drop each | ||
| * other's stars. Note that two windows toggling the same model at the same | ||
| * instant can still interleave; per-model state stays consistent either way. | ||
| */ | ||
| function persistStarEntry(starKey: string, starred: boolean): boolean { | ||
| if (typeof window === "undefined") { | ||
| return false; | ||
| } | ||
|
|
||
| try { | ||
| const storageKey = starredModelStorageKey(starKey); | ||
| if (starred) { | ||
| window.localStorage.setItem(storageKey, STARRED_MODELS_ENTRY_VALUE); | ||
| } else { | ||
| window.localStorage.removeItem(storageKey); | ||
| } | ||
| } catch { | ||
|
NickTitle marked this conversation as resolved.
|
||
| // The write did not land (storage unavailable or over quota). Tell the | ||
| // user instead of letting the toggle silently bounce back. | ||
| toast.error(i18n.t("chat:notifications.starredModelsPersistError")); | ||
| window.dispatchEvent(new CustomEvent(STARRED_MODELS_CHANGED_EVENT)); | ||
| return false; | ||
| } | ||
|
|
||
| window.dispatchEvent(new CustomEvent(STARRED_MODELS_CHANGED_EVENT)); | ||
| return true; | ||
| } | ||
|
|
||
| export function getStarredModelKeys(): StarredModelSet { | ||
| return readStarredModels(); | ||
| } | ||
|
|
||
| export function toggleModelStar(scopeId: string, modelId: string): boolean { | ||
| if (typeof window === "undefined") { | ||
| return false; | ||
| } | ||
|
|
||
| const starKey = modelStarKey(scopeId, modelId); | ||
|
|
||
| try { | ||
| const starred = | ||
| window.localStorage.getItem(starredModelStorageKey(starKey)) !== null; | ||
| return persistStarEntry(starKey, !starred); | ||
| } catch { | ||
| // Storage is unavailable, so the toggle cannot be applied at all. The | ||
| // write path reports its own failures; report this one too. | ||
| toast.error(i18n.t("chat:notifications.starredModelsPersistError")); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| export const STARRED_MODELS_EVENT = STARRED_MODELS_CHANGED_EVENT; | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.