Skip to content

Commit 2068456

Browse files
engineerCopilot
andcommitted
fix(app): wire voice, font, and UI component updates
Co-authored-by: Copilot <[email protected]>
1 parent a83fd1f commit 2068456

12 files changed

Lines changed: 703 additions & 26 deletions

File tree

‎packages/app/src/components/status-popover.tsx‎

Lines changed: 389 additions & 21 deletions
Large diffs are not rendered by default.

‎packages/app/src/context/platform.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ export type Platform = {
8787

8888
/** Read image from clipboard (desktop only) */
8989
readClipboardImage?(): Promise<File | null>
90+
91+
/** Request microphone access from the host app (desktop only) */
92+
requestMicrophoneAccess?(): Promise<boolean>
9093
}
9194

9295
export type DisplayBackend = "auto" | "wayland"

‎packages/app/src/entry.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ if (!(root instanceof HTMLElement) && import.meta.env.DEV) {
9797
throw new Error(getRootNotFoundError())
9898
}
9999

100+
const localUrl = () =>
101+
`http://${import.meta.env.VITE_OPENCODE_SERVER_HOST ?? "localhost"}:${import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096"}`
102+
100103
const getCurrentUrl = () => {
101-
if (location.hostname.includes("opencode.ai")) return "http://localhost:4096"
102-
if (import.meta.env.DEV)
103-
return `http://${import.meta.env.VITE_OPENCODE_SERVER_HOST ?? "localhost"}:${import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096"}`
104+
if (location.hostname.includes("opencode.ai")) return localUrl()
105+
if (import.meta.env.DEV) return localUrl()
104106
return location.origin
105107
}
106108

‎packages/app/src/testing/terminal.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ type TerminalProbeControl = {
1414
disconnect?: VoidFunction
1515
}
1616

17+
type VoiceProbeState = {
18+
starts?: number
19+
cancels?: number
20+
requests?: number
21+
spoken?: string[]
22+
}
23+
1724
export type E2EWindow = Window & {
1825
__opencode_e2e?: {
1926
model?: {
@@ -30,6 +37,7 @@ export type E2EWindow = Window & {
3037
terminals?: Record<string, TerminalProbeState>
3138
controls?: Record<string, TerminalProbeControl>
3239
}
40+
voice?: VoiceProbeState
3341
}
3442
}
3543

‎packages/app/src/utils/runtime-adapters.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { describe, expect, test } from "bun:test"
22
import {
33
disposeIfDisposable,
4+
getMediaDevices,
5+
getPermissions,
46
getHoveredLinkText,
57
getSpeechRecognitionCtor,
8+
getSpeechSynthesis,
9+
getSpeechSynthesisUtteranceCtor,
610
hasSetOption,
711
isDisposable,
812
setOptionIfSupported,
@@ -59,4 +63,43 @@ describe("runtime adapters", () => {
5963
expect(getSpeechRecognitionCtor({ SpeechRecognition: "nope" })).toBeUndefined()
6064
expect(getSpeechRecognitionCtor(undefined)).toBeUndefined()
6165
})
66+
67+
test("returns media devices when getUserMedia exists", () => {
68+
const media = {
69+
getUserMedia: async () => ({
70+
getTracks: () => [],
71+
}),
72+
}
73+
expect(getMediaDevices<typeof media>({ navigator: { mediaDevices: media } })).toBe(media)
74+
expect(getMediaDevices({ navigator: { mediaDevices: {} } })).toBeUndefined()
75+
expect(getMediaDevices(undefined)).toBeUndefined()
76+
})
77+
78+
test("returns permissions when query exists", () => {
79+
const perms = {
80+
query: async () => ({ state: "prompt" }),
81+
}
82+
expect(getPermissions<typeof perms>({ navigator: { permissions: perms } })).toBe(perms)
83+
expect(getPermissions({ navigator: { permissions: {} } })).toBeUndefined()
84+
expect(getPermissions(undefined)).toBeUndefined()
85+
})
86+
87+
test("returns speech synthesis when required methods exist", () => {
88+
const synth = {
89+
cancel() {},
90+
speak() {},
91+
}
92+
expect(getSpeechSynthesis<typeof synth>({ speechSynthesis: synth })).toBe(synth)
93+
expect(getSpeechSynthesis({ speechSynthesis: { speak() {} } })).toBeUndefined()
94+
expect(getSpeechSynthesis(undefined)).toBeUndefined()
95+
})
96+
97+
test("returns speech synthesis utterance constructor when present", () => {
98+
class Ctor {
99+
constructor(readonly text = "") {}
100+
}
101+
expect(getSpeechSynthesisUtteranceCtor({ SpeechSynthesisUtterance: Ctor })).toBe(Ctor)
102+
expect(getSpeechSynthesisUtteranceCtor({ SpeechSynthesisUtterance: "nope" })).toBeUndefined()
103+
expect(getSpeechSynthesisUtteranceCtor(undefined)).toBeUndefined()
104+
})
62105
})

‎packages/app/src/utils/runtime-adapters.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,38 @@ export const getSpeechRecognitionCtor = <T>(value: unknown): (new () => T) | und
3737
if (typeof ctor !== "function") return
3838
return ctor as new () => T
3939
}
40+
41+
export const getMediaDevices = <T>(value: unknown): T | undefined => {
42+
if (!isRecord(value)) return
43+
const nav = value.navigator
44+
if (!isRecord(nav)) return
45+
const media = nav.mediaDevices
46+
if (!isRecord(media)) return
47+
if (typeof media.getUserMedia !== "function") return
48+
return media as T
49+
}
50+
51+
export const getPermissions = <T>(value: unknown): T | undefined => {
52+
if (!isRecord(value)) return
53+
const nav = value.navigator
54+
if (!isRecord(nav)) return
55+
const perms = nav.permissions
56+
if (!isRecord(perms)) return
57+
if (typeof perms.query !== "function") return
58+
return perms as T
59+
}
60+
61+
export const getSpeechSynthesis = <T>(value: unknown): T | undefined => {
62+
if (!isRecord(value)) return
63+
const synth = value.speechSynthesis
64+
if (!isRecord(synth)) return
65+
if (typeof synth.speak !== "function") return
66+
if (typeof synth.cancel !== "function") return
67+
return synth as T
68+
}
69+
70+
export const getSpeechSynthesisUtteranceCtor = <T>(value: unknown): (new (text?: string) => T) | undefined => {
71+
if (!isRecord(value)) return
72+
if (typeof value.SpeechSynthesisUtterance !== "function") return
73+
return value.SpeechSynthesisUtterance as new (text?: string) => T
74+
}
Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
1-
export const Font = () => null
1+
import { Link, Style } from "@solidjs/meta"
2+
import { Show } from "solid-js"
3+
import inter from "../assets/fonts/inter.woff2"
4+
import ibmPlexMonoBold from "../assets/fonts/ibm-plex-mono-bold.woff2"
5+
import ibmPlexMonoMedium from "../assets/fonts/ibm-plex-mono-medium.woff2"
6+
import ibmPlexMonoRegular from "../assets/fonts/ibm-plex-mono.woff2"
7+
8+
export const Font = () => {
9+
return (
10+
<>
11+
<Style>{`
12+
@font-face {
13+
font-family: "Inter";
14+
src: url("${inter}") format("woff2-variations");
15+
font-display: swap;
16+
font-style: normal;
17+
font-weight: 100 900;
18+
}
19+
@font-face {
20+
font-family: "Inter Fallback";
21+
src: local("Arial");
22+
size-adjust: 100%;
23+
ascent-override: 97%;
24+
descent-override: 25%;
25+
line-gap-override: 1%;
26+
}
27+
@font-face {
28+
font-family: "IBM Plex Mono";
29+
src: url("${ibmPlexMonoRegular}") format("woff2");
30+
font-display: swap;
31+
font-style: normal;
32+
font-weight: 400;
33+
}
34+
@font-face {
35+
font-family: "IBM Plex Mono";
36+
src: url("${ibmPlexMonoMedium}") format("woff2");
37+
font-display: swap;
38+
font-style: normal;
39+
font-weight: 500;
40+
}
41+
@font-face {
42+
font-family: "IBM Plex Mono";
43+
src: url("${ibmPlexMonoBold}") format("woff2");
44+
font-display: swap;
45+
font-style: normal;
46+
font-weight: 700;
47+
}
48+
@font-face {
49+
font-family: "IBM Plex Mono Fallback";
50+
src: local("Courier New");
51+
size-adjust: 100%;
52+
ascent-override: 97%;
53+
descent-override: 25%;
54+
line-gap-override: 1%;
55+
}
56+
`}</Style>
57+
<Show when={typeof location === "undefined" || location.protocol !== "file:"}>
58+
<Link rel="preload" href={inter} as="font" type="font/woff2" crossorigin="anonymous" />
59+
<Link rel="preload" href={ibmPlexMonoRegular} as="font" type="font/woff2" crossorigin="anonymous" />
60+
</Show>
61+
</>
62+
)
63+
}

‎packages/ui/src/components/icon.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ const icons = {
8989
branch: `<path d="M14.2036 7.19987L14.2079 6.69989L13.2079 6.69132L13.2036 7.1913L13.7036 7.19559L14.2036 7.19987ZM8.14804 5.09032H7.64804C7.64804 5.75797 7.06861 6.34471 6.29619 6.34471V6.84471V7.34471C7.56926 7.34471 8.64804 6.36051 8.64804 5.09032H8.14804ZM6.29619 6.84471V6.34471C5.52376 6.34471 4.94434 5.75797 4.94434 5.09032H4.44434H3.94434C3.94434 6.36051 5.02311 7.34471 6.29619 7.34471V6.84471ZM4.44434 5.09032H4.94434C4.94434 4.42267 5.52376 3.83594 6.29619 3.83594V3.33594V2.83594C5.02311 2.83594 3.94434 3.82013 3.94434 5.09032H4.44434ZM6.29619 3.33594V3.83594C7.06861 3.83594 7.64804 4.42267 7.64804 5.09032H8.14804H8.64804C8.64804 3.82013 7.56926 2.83594 6.29619 2.83594V3.33594ZM8.14804 14.9149H7.64804C7.64804 15.5825 7.06861 16.1693 6.29619 16.1693V16.6693V17.1693C7.56926 17.1693 8.64804 16.1851 8.64804 14.9149H8.14804ZM6.29619 16.6693V16.1693C5.52376 16.1693 4.94434 15.5825 4.94434 14.9149H4.44434H3.94434C3.94434 16.1851 5.02311 17.1693 6.29619 17.1693V16.6693ZM4.44434 14.9149H4.94434C4.94434 14.2472 5.52376 13.6605 6.29619 13.6605V13.1605V12.6605C5.02311 12.6605 3.94434 13.6447 3.94434 14.9149H4.44434ZM6.29619 13.1605V13.6605C7.06861 13.6605 7.64804 14.2472 7.64804 14.9149H8.14804H8.64804C8.64804 13.6447 7.56926 12.6605 6.29619 12.6605V13.1605ZM15.5554 5.09032H15.0554C15.0554 5.75797 14.476 6.34471 13.7036 6.34471V6.84471V7.34471C14.9767 7.34471 16.0554 6.36051 16.0554 5.09032H15.5554ZM13.7036 6.84471V6.34471C12.9312 6.34471 12.3517 5.75797 12.3517 5.09032H11.8517H11.3517C11.3517 6.36051 12.4305 7.34471 13.7036 7.34471V6.84471ZM11.8517 5.09032H12.3517C12.3517 4.42267 12.9312 3.83594 13.7036 3.83594V3.33594V2.83594C12.4305 2.83594 11.3517 3.82013 11.3517 5.09032H11.8517ZM13.7036 3.33594V3.83594C14.476 3.83594 15.0554 4.42267 15.0554 5.09032H15.5554H16.0554C16.0554 3.82013 14.9767 2.83594 13.7036 2.83594V3.33594ZM13.7036 7.19559L13.2036 7.1913L13.1544 12.9277L13.6544 12.932L14.1544 12.9363L14.2036 7.19987L13.7036 7.19559ZM6.29619 6.84471H5.79619V13.1605H6.29619H6.79619V6.84471H6.29619ZM11.6545 14.9149V14.4149H8.14804V14.9149V15.4149H11.6545V14.9149ZM13.6544 12.932L13.1544 12.9277C13.1474 13.7511 12.4779 14.4149 11.6545 14.4149V14.9149V15.4149C13.0269 15.4149 14.1426 14.3086 14.1544 12.9363L13.6544 12.932Z" fill="currentColor"/>`,
9090
edit: `<path d="M17.0832 17.0807V17.5807H17.5832V17.0807H17.0832ZM2.9165 17.0807H2.4165V17.5807H2.9165V17.0807ZM2.9165 2.91406V2.41406H2.4165V2.91406H2.9165ZM9.58317 3.41406H10.0832V2.41406H9.58317V2.91406V3.41406ZM17.5832 10.4141V9.91406H16.5832V10.4141H17.0832H17.5832ZM6.24984 11.2474L5.89628 10.8938L5.74984 11.0403V11.2474H6.24984ZM6.24984 13.7474H5.74984V14.2474H6.24984V13.7474ZM8.74984 13.7474V14.2474H8.95694L9.10339 14.101L8.74984 13.7474ZM15.2082 2.28906L15.5617 1.93551L15.2082 1.58196L14.8546 1.93551L15.2082 2.28906ZM17.7082 4.78906L18.0617 5.14262L18.4153 4.78906L18.0617 4.43551L17.7082 4.78906ZM17.0832 17.0807V16.5807H2.9165V17.0807V17.5807H17.0832V17.0807ZM2.9165 17.0807H3.4165V2.91406H2.9165H2.4165V17.0807H2.9165ZM2.9165 2.91406V3.41406H9.58317V2.91406V2.41406H2.9165V2.91406ZM17.0832 10.4141H16.5832V17.0807H17.0832H17.5832V10.4141H17.0832ZM6.24984 11.2474H5.74984V13.7474H6.24984H6.74984V11.2474H6.24984ZM6.24984 13.7474V14.2474H8.74984V13.7474V13.2474H6.24984V13.7474ZM6.24984 11.2474L6.60339 11.6009L15.5617 2.64262L15.2082 2.28906L14.8546 1.93551L5.89628 10.8938L6.24984 11.2474ZM15.2082 2.28906L14.8546 2.64262L17.3546 5.14262L17.7082 4.78906L18.0617 4.43551L15.5617 1.93551L15.2082 2.28906ZM17.7082 4.78906L17.3546 4.43551L8.39628 13.3938L8.74984 13.7474L9.10339 14.101L18.0617 5.14262L17.7082 4.78906Z" fill="currentColor"/>`,
9191
help: `<path d="M7.91683 7.91927V6.2526H12.0835V8.7526L10.0002 10.0026V12.0859M10.0002 13.7526V13.7609M17.9168 10.0026C17.9168 14.3749 14.3724 17.9193 10.0002 17.9193C5.62791 17.9193 2.0835 14.3749 2.0835 10.0026C2.0835 5.63035 5.62791 2.08594 10.0002 2.08594C14.3724 2.08594 17.9168 5.63035 17.9168 10.0026Z" stroke="currentColor" stroke-linecap="square"/>`,
92+
microphone: `<path d="M10 13.3333C11.6108 13.3333 12.9167 12.0274 12.9167 10.4167V5.83333C12.9167 4.2225 11.6108 2.91666 10 2.91666C8.38917 2.91666 7.08333 4.2225 7.08333 5.83333V10.4167C7.08333 12.0274 8.38917 13.3333 10 13.3333ZM10 13.3333V17.0833M5.83333 9.99999V10.4167C5.83333 12.7178 7.69881 14.5833 10 14.5833C12.3012 14.5833 14.1667 12.7178 14.1667 10.4167V9.99999" stroke="currentColor" stroke-linecap="square"/>`,
93+
speaker: `<path d="M3.33325 8.33333H6.24992L10.4166 4.99999V15L6.24992 11.6667H3.33325V8.33333ZM13.3333 7.08333C14.434 7.72806 15.1666 8.92039 15.1666 10.2833C15.1666 11.6463 14.434 12.8386 13.3333 13.4833M14.9999 4.99999C16.7053 6.05364 17.9166 7.94563 17.9166 10.1167C17.9166 12.2877 16.7053 14.1797 14.9999 15.2333" stroke="currentColor" stroke-linecap="square"/>`,
9294
"settings-gear": `<path d="M7.62516 4.46094L5.05225 3.86719L3.86475 5.05469L4.4585 7.6276L2.0835 9.21094V10.7943L4.4585 12.3776L3.86475 14.9505L5.05225 16.138L7.62516 15.5443L9.2085 17.9193H10.7918L12.3752 15.5443L14.9481 16.138L16.1356 14.9505L15.5418 12.3776L17.9168 10.7943V9.21094L15.5418 7.6276L16.1356 5.05469L14.9481 3.86719L12.3752 4.46094L10.7918 2.08594H9.2085L7.62516 4.46094Z" stroke="currentColor"/><path d="M12.5002 10.0026C12.5002 11.3833 11.3809 12.5026 10.0002 12.5026C8.61945 12.5026 7.50016 11.3833 7.50016 10.0026C7.50016 8.62189 8.61945 7.5026 10.0002 7.5026C11.3809 7.5026 12.5002 8.62189 12.5002 10.0026Z" stroke="currentColor"/>`,
9395
dash: `<rect x="5" y="9.5" width="10" height="1" fill="currentColor"/>`,
9496
"cloud-upload": `<path d="M12.0833 16.25H15C17.0711 16.25 18.75 14.5711 18.75 12.5C18.75 10.5649 17.2843 8.97217 15.4025 8.77133C15.2 6.13103 12.8586 4.08333 10 4.08333C7.71532 4.08333 5.76101 5.49781 4.96501 7.49881C2.84892 7.90461 1.25 9.76559 1.25 11.6667C1.25 13.9813 3.30203 16.25 5.83333 16.25H7.91667M10 16.25V10.4167M12.0833 11.875L10 9.79167L7.91667 11.875" stroke="currentColor" stroke-linecap="square"/>`,

‎packages/ui/src/components/message-part.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export interface MessageProps {
134134
actions?: UserActions
135135
showAssistantCopyPartID?: string | null
136136
showReasoningSummaries?: boolean
137+
onSpeak?: (input: { messageID: string; text: string }) => void
137138
}
138139

139140
export type SessionAction = (input: { sessionID: string; messageID: string }) => Promise<void> | void
@@ -150,6 +151,7 @@ export interface MessagePartProps {
150151
defaultOpen?: boolean
151152
showAssistantCopyPartID?: string | null
152153
turnDurationMs?: number
154+
onSpeak?: (input: { messageID: string; text: string }) => void
153155
}
154156

155157
export type PartComponent = Component<MessagePartProps>
@@ -748,6 +750,7 @@ export function Message(props: MessageProps) {
748750
parts={props.parts}
749751
showAssistantCopyPartID={props.showAssistantCopyPartID}
750752
showReasoningSummaries={props.showReasoningSummaries}
753+
onSpeak={props.onSpeak}
751754
/>
752755
)}
753756
</Match>
@@ -760,6 +763,7 @@ export function AssistantMessageDisplay(props: {
760763
parts: PartType[]
761764
showAssistantCopyPartID?: string | null
762765
showReasoningSummaries?: boolean
766+
onSpeak?: (input: { messageID: string; text: string }) => void
763767
}) {
764768
const emptyTools: ToolPart[] = []
765769
const part = createMemo(() => index(props.parts))
@@ -819,6 +823,7 @@ export function AssistantMessageDisplay(props: {
819823
part={item()!}
820824
message={props.message}
821825
showAssistantCopyPartID={props.showAssistantCopyPartID}
826+
onSpeak={props.onSpeak}
822827
/>
823828
</Show>
824829
)
@@ -1157,6 +1162,7 @@ export function Part(props: MessagePartProps) {
11571162
defaultOpen={props.defaultOpen}
11581163
showAssistantCopyPartID={props.showAssistantCopyPartID}
11591164
turnDurationMs={props.turnDurationMs}
1165+
onSpeak={props.onSpeak}
11601166
/>
11611167
</Show>
11621168
)
@@ -1399,6 +1405,7 @@ PART_MAPPING["text"] = function TextPartDisplay(props) {
13991405
if (typeof props.showAssistantCopyPartID === "string") return props.showAssistantCopyPartID === part().id
14001406
return isLastTextPart()
14011407
})
1408+
const showSpeak = createMemo(() => props.message.role === "assistant" && isLastTextPart() && !!displayText())
14021409
const [copied, setCopied] = createSignal(false)
14031410

14041411
const handleCopy = async () => {
@@ -1433,6 +1440,18 @@ PART_MAPPING["text"] = function TextPartDisplay(props) {
14331440
aria-label={copied() ? i18n.t("ui.message.copied") : i18n.t("ui.message.copyResponse")}
14341441
/>
14351442
</Tooltip>
1443+
<Show when={showSpeak()}>
1444+
<Tooltip value={i18n.t("ui.message.speakResponse")} placement="top" gutter={4}>
1445+
<IconButton
1446+
icon="speaker"
1447+
size="normal"
1448+
variant="ghost"
1449+
onMouseDown={(e) => e.preventDefault()}
1450+
onClick={() => props.onSpeak?.({ messageID: props.message.id, text: displayText() })}
1451+
aria-label={i18n.t("ui.message.speakResponse")}
1452+
/>
1453+
</Tooltip>
1454+
</Show>
14361455
<Show when={meta()}>
14371456
<span data-slot="text-part-meta" class="text-12-regular text-text-weak cursor-default">
14381457
{meta()}

‎packages/ui/src/components/session-turn.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export function SessionTurn(
143143
messageID: string
144144
messages?: MessageType[]
145145
actions?: UserActions
146+
onSpeak?: (input: { messageID: string; text: string }) => void
146147
showReasoningSummaries?: boolean
147148
shellToolDefaultOpen?: boolean
148149
editToolDefaultOpen?: boolean
@@ -386,7 +387,7 @@ export function SessionTurn(
386387
class={props.classes?.container}
387388
>
388389
<div data-slot="session-turn-message-content" aria-live="off">
389-
<Message message={message()!} parts={parts()} actions={props.actions} />
390+
<Message message={message()!} parts={parts()} actions={props.actions} onSpeak={props.onSpeak} />
390391
</div>
391392
<Show when={divider()}>
392393
<div data-slot="session-turn-compaction">

0 commit comments

Comments
 (0)