Repository navigation
feat(voice): an extension can draw the avatar in voice mode, chosen per agent #308
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
5e74ce6
feat(voice): an extension can draw the avatar in voice mode, chosen p…
thecodacus df51d81
fix(agents): an extension's avatar is cut at its square on the Agents…
thecodacus 0200062
test(voice): an extension's avatar is drawn again for a new mode, not…
thecodacus 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
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,57 @@ | ||
| import { Suspense, useEffect, useMemo, useState, type MutableRefObject } from "react"; | ||
| import { api } from "../api"; | ||
| import { failedIn } from "../extensions/loader"; | ||
| import { useSlot } from "../extensions/slots"; | ||
| import { DEFAULT_ORB, type OrbState, type OrbStyle } from "../../../server/src/orb-style"; | ||
| import { ErrorBoundary } from "./ErrorBoundary"; | ||
| import { ORB_STYLE_EVENT, VoiceOrb, type VoiceLevels } from "./VoiceOrb"; | ||
|
|
||
| /** | ||
| * The agent a chat talks to, and its avatar: the default orb and no agent until | ||
| * the server answers, then whatever is saved. Asked again when an avatar is | ||
| * saved, since it can be this one. | ||
| */ | ||
| export function useChatAvatar(session: string): { agent?: { id: string; name: string }; look: OrbStyle } { | ||
| const [avatar, setAvatar] = useState<{ agent?: { id: string; name: string }; look: OrbStyle }>({ look: DEFAULT_ORB }); | ||
| useEffect(() => { | ||
| let live = true; | ||
| const load = () => api.chatAvatar(session).then(({ agent, orb }) => { if (live) setAvatar({ agent, look: orb }); }).catch(() => {}); | ||
| void load(); | ||
| window.addEventListener(ORB_STYLE_EVENT, load); | ||
| return () => { live = false; window.removeEventListener(ORB_STYLE_EVENT, load); }; | ||
| }, [session]); | ||
| return avatar; | ||
| } | ||
|
|
||
| /** | ||
| * An agent's avatar, wherever the portal shows one: the orb, or what an | ||
| * extension draws in its place (`voice.avatar`) for an agent whose look chose | ||
| * it (`look.avatar`, "<package>/<id>"). The orb is drawn while that entry is | ||
| * not in the page (its extension is not installed, is switched off, has not | ||
| * loaded or not registered it yet), and in place of it when it fails to draw, | ||
| * which Settings → Extensions then says. `thinking` is the stage's (see | ||
| * AvatarMode); `still` is for a picture of the agent rather than voice mode. | ||
| * | ||
| * The orb and the agent are made once for what they show: the stage is drawn | ||
| * again with every token of a reply, and an extension's part is drawn again | ||
| * only when what it is given changes. | ||
| */ | ||
| export function AgentAvatar({ look, agent, mode, thinking = false, levels, still = false }: { | ||
| look: OrbStyle; agent?: { id: string; name: string }; mode: OrbState; thinking?: boolean; levels: MutableRefObject<VoiceLevels>; still?: boolean; | ||
| }) { | ||
| const orb = useMemo(() => <VoiceOrb mode={mode} levels={levels} look={look} />, [mode, levels, look]); | ||
| const id = agent?.id, name = agent?.name; | ||
| const who = useMemo(() => (id === undefined || name === undefined ? undefined : { id, name }), [id, name]); | ||
| const entry = useSlot("voice.avatar").find((e) => e.key === look.avatar); | ||
| if (!entry || !who) return orb; | ||
| return ( | ||
| <div className="voice-avatar-x" aria-hidden="true"> | ||
| <ErrorBoundary resetKey={`${entry.key}:${who.id}`} fallback={() => orb} onError={failedIn(entry.extension)}> | ||
| {/* Its own: a part still being fetched would otherwise blank the page above it until it is. */} | ||
| <Suspense fallback={orb}> | ||
| <entry.component agent={who} mode={thinking ? "thinking" : mode} levels={levels} still={still} orb={orb} /> | ||
| </Suspense> | ||
| </ErrorBoundary> | ||
| </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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: thecodacus/pithagoras
Length of output: 6063
🏁 Script executed:
Repository: thecodacus/pithagoras
Length of output: 42357
🏁 Script executed:
Repository: thecodacus/pithagoras
Length of output: 41881
🏁 Script executed:
Repository: thecodacus/pithagoras
Length of output: 42181
🏁 Script executed:
Repository: thecodacus/pithagoras
Length of output: 10355
🏁 Script executed:
Repository: thecodacus/pithagoras
Length of output: 11245
Reload the chat avatar when the session reloads.
When another tab relinks the project, the active voice chat receives
portal_reload, butuseChatAvatardoes not reload. The mounted stage can therefore keep the old agent name and extension avatar after/reload.Suggested fix
🤖 Prompt for AI Agents