Repository navigation
feat: Codex voice conversations on web, desktop, and mobile #14865
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
base: main
Are you sure you want to change the base?
Changes from all commits
d55e7b2
40eddda
5ac07dd
f3167f6
4d9120b
c03e1ba
3c96dff
2ee039a
52f0133
07f94f4
887bca9
e89986c
213c146
b4ec1b8
84c0c45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { decideMainWindowMediaRequest, isAppUrl } from "./MainWindowPermissions.ts"; | ||
|
|
||
| const APP_URL = "t3code://app/"; | ||
|
|
||
| function decide(overrides: Partial<Parameters<typeof decideMainWindowMediaRequest>[0]> = {}) { | ||
| return decideMainWindowMediaRequest({ | ||
| requestingUrl: "t3code://app/threads/abc", | ||
| appUrl: APP_URL, | ||
| mediaTypes: ["audio"], | ||
| platform: "darwin", | ||
| microphoneStatus: () => "granted", | ||
| ...overrides, | ||
| }); | ||
| } | ||
|
|
||
| describe("isAppUrl", () => { | ||
| it("matches the app shell and nothing that merely shares its prefix", () => { | ||
| expect(isAppUrl("t3code://app", APP_URL)).toBe(true); | ||
| expect(isAppUrl("t3code://app/settings", APP_URL)).toBe(true); | ||
| expect(isAppUrl("t3code://application/", APP_URL)).toBe(false); | ||
| expect(isAppUrl("https://example.com/", APP_URL)).toBe(false); | ||
| expect(isAppUrl(undefined, APP_URL)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("decideMainWindowMediaRequest", () => { | ||
| it("denies media to frames outside the app shell", () => { | ||
| expect(decide({ requestingUrl: "https://example.com/embed" })).toBe("deny"); | ||
| }); | ||
|
|
||
| it("asks macOS for the microphone until the user has granted it", () => { | ||
| expect(decide({ microphoneStatus: () => "not-determined" })).toBe("ask-microphone"); | ||
| expect(decide({ microphoneStatus: () => "denied" })).toBe("ask-microphone"); | ||
| expect(decide()).toBe("grant"); | ||
| }); | ||
|
|
||
| it("grants the microphone directly off macOS", () => { | ||
| expect(decide({ platform: "win32", microphoneStatus: () => "unknown" })).toBe("grant"); | ||
| }); | ||
|
|
||
| it("keeps granting video-only capture such as preview tab recording", () => { | ||
| expect(decide({ mediaTypes: ["video"], microphoneStatus: () => "denied" })).toBe("grant"); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import * as Electron from "electron"; | ||
|
|
||
| export type MediaPermissionDecision = "grant" | "deny" | "ask-microphone"; | ||
|
|
||
| /** Whether `url` belongs to the app shell served from `appUrl` (e.g. `t3code://app/`). */ | ||
| export function isAppUrl(url: string | undefined, appUrl: string): boolean { | ||
| if (!url) return false; | ||
| // Custom schemes have an opaque WHATWG origin, so compare the serialized prefix. | ||
| const appOrigin = appUrl.endsWith("/") ? appUrl.slice(0, -1) : appUrl; | ||
| return url === appOrigin || url.startsWith(`${appOrigin}/`); | ||
| } | ||
|
|
||
| /** | ||
| * Media requests come from the app shell (voice conversations use the | ||
| * microphone; preview tab recording routes `getDisplayMedia` through the same | ||
| * permission). Frames from any other origin never get media. On macOS the | ||
| * microphone also needs the system's consent, asked for on first use. | ||
| */ | ||
| export function decideMainWindowMediaRequest(input: { | ||
| readonly requestingUrl: string; | ||
| readonly appUrl: string; | ||
| readonly mediaTypes: ReadonlyArray<"audio" | "video">; | ||
| readonly platform: NodeJS.Platform; | ||
| readonly microphoneStatus: () => string; | ||
| }): MediaPermissionDecision { | ||
| if (!isAppUrl(input.requestingUrl, input.appUrl)) return "deny"; | ||
| if (!input.mediaTypes.includes("audio") || input.platform !== "darwin") return "grant"; | ||
| return input.microphoneStatus() === "granted" ? "grant" : "ask-microphone"; | ||
| } | ||
|
|
||
| /** | ||
| * Installs the main window session's permission handlers. Only `media` is | ||
| * decided here; every other permission keeps Electron's default of allowing | ||
| * it, which is what this session did before it had handlers. | ||
| */ | ||
| export function installMainWindowPermissionHandlers( | ||
| session: Electron.Session, | ||
| options: { readonly appUrl: string; readonly platform: NodeJS.Platform }, | ||
| ): void { | ||
| session.setPermissionRequestHandler((_webContents, permission, callback, details) => { | ||
| if (permission !== "media") { | ||
| callback(true); | ||
| return; | ||
| } | ||
| const decision = decideMainWindowMediaRequest({ | ||
| requestingUrl: details.requestingUrl, | ||
| appUrl: options.appUrl, | ||
| mediaTypes: "mediaTypes" in details ? (details.mediaTypes ?? []) : [], | ||
| platform: options.platform, | ||
| microphoneStatus: () => Electron.systemPreferences.getMediaAccessStatus("microphone"), | ||
| }); | ||
| if (decision !== "ask-microphone") { | ||
| callback(decision === "grant"); | ||
| return; | ||
| } | ||
| Electron.systemPreferences.askForMediaAccess("microphone").then(callback, () => { | ||
| callback(false); | ||
| }); | ||
| }); | ||
| session.setPermissionCheckHandler((_webContents, permission, requestingOrigin) => | ||
| permission === "media" ? isAppUrl(requestingOrigin, options.appUrl) : true, | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -115,6 +115,9 @@ import { | |||||
| } from "../voice-input/ComposerDictationControl"; | ||||||
| import { useVoiceInputController } from "../voice-input/useVoiceInputController"; | ||||||
| import { resolveVoiceComposerPresentation } from "../voice-input/voiceInputPresentation"; | ||||||
| import { ComposerVoiceModeButton, ComposerVoiceStrip } from "../voice-mode/ComposerVoiceMode"; | ||||||
| import { useVoiceModePhase, useVoiceModeThreadLifecycle } from "../voice-mode/useVoiceMode"; | ||||||
| import { voiceMode, voiceModeSupported } from "../voice-mode/voiceMode"; | ||||||
| import { | ||||||
| rememberModelOptions, | ||||||
| withRememberedModelOptions, | ||||||
|
|
@@ -509,15 +512,41 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer | |||||
| onUsageLimits: | ||||||
| usageLimitsOffered && props.draftAttachments.length === 0 ? openUsageLimits : undefined, | ||||||
| }); | ||||||
| const voiceTarget = useMemo( | ||||||
| () => ({ environmentId: props.environmentId, threadId: props.selectedThread.id }), | ||||||
| [props.environmentId, props.selectedThread.id], | ||||||
| ); | ||||||
| const voicePhase = useVoiceModePhase(voiceTarget); | ||||||
| useVoiceModeThreadLifecycle(voiceTarget); | ||||||
| // Dictation and a voice conversation both need the microphone. | ||||||
| const voiceConversationLive = voicePhase !== "idle"; | ||||||
| const voiceInput = useVoiceInputController({ | ||||||
| ownerKey: composerDraftKey, | ||||||
| label: props.selectedThread.title || "Untitled thread", | ||||||
| readDraftMessage: () => getComposerDraftSnapshot(composerDraftKey).text, | ||||||
| subscribeToDraftChanges: (onChange) => appAtomRegistry.subscribe(composerDraftsAtom, onChange), | ||||||
| selection: composerMenu.selection, | ||||||
| disabled: voiceConversationLive, | ||||||
| onChangeDraftMessage: (text) => setComposerDraftText(composerDraftKey, text), | ||||||
| onChangeSelection: composerMenu.onSelectionChange, | ||||||
| }); | ||||||
| const offersVoiceConversation = | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High The voice button is enabled for the draft-selected provider even when 🤖 Copy this AI Prompt to have your agent fix this: |
||||||
| voiceModeSupported && selectedProviderStatus?.supportsVoice === true; | ||||||
| // The server attaches voice to the thread's provider thread, which the first | ||||||
| // run creates. An optimistic pending thread already has a message timestamp. | ||||||
| const canToggleVoiceConversation = | ||||||
| voiceConversationLive || | ||||||
| (props.connectionState === "connected" && | ||||||
| props.selectedThread.activeProviderThreadId !== null && | ||||||
| !voiceInput.isBusy); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- changed target region at reviewed head ---'
git show 7a996c1d1e638587da0caeae496ea894bbcf0af1:apps/mobile/src/features/threads/ThreadComposer.tsx | nl -ba | sed -n '470,570p'
printf '%s\n' '--- PR-base diff for target file ---'
git diff 4ee6bfd50ef4a089440d5c3662db2298da9cc50e 7a996c1d1e638587da0caeae496ea894bbcf0af1 -- apps/mobile/src/features/threads/ThreadComposer.tsx | sed -n '1,240p'
printf '%s\n' '--- relevant symbols and imports ---'
git grep -n -E 'useVoiceInputController|canToggleVoiceConversation|voiceMode\\.toggle|useVoiceMode|isBusy|dictation' 7a996c1d1e638587da0caeae496ea894bbcf0af1 -- apps/mobile/src/features/threads/ThreadComposer.tsx apps/mobile/src/featuresRepository: pingdotgg/t3code Length of output: 22178 🏁 Script executed: #!/bin/bash
set -e
for spec in \
'apps/mobile/src/features/voice-input/useVoiceInputController.ts:1,115' \
'apps/mobile/src/features/voice-input/VoiceInputProvider.tsx:1,260' \
'apps/mobile/src/features/voice-mode/voiceMode.ts:1,300' \
'apps/mobile/src/features/voice-mode/useVoiceMode.ts:1,180' \
'apps/mobile/src/features/voice-mode/ComposerVoiceMode.tsx:1,150'
do
file=${spec%%:*}
range=${spec#*:}
printf '\n--- %s ---\n' "$file"
git show "7a996c1d1e638587da0caeae496ea894bbcf0af1:$file" | nl -ba | sed -n "${range}p"
done
printf '\n--- global microphone/session ownership references ---\n'
git grep -n -E 'VoiceMode|voiceMode|VoiceInputProvider|voiceInputBlocksSubmission|start.*(record|microphone)|microphone' 7a996c1d1e638587da0caeae496ea894bbcf0af1 -- apps/mobile/src/features/voice-mode apps/mobile/src/features/voice-inputRepository: pingdotgg/t3code Length of output: 37604 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- tracked VoiceModeController definitions/import resolution ---'
git grep -n -E 'class VoiceModeController|function VoiceModeController|VoiceModeController|makeVoiceSessionOpener|interface VoiceSessionTarget' 7a996c1d1e638587da0caeae496ea894bbcf0af1 -- ':!apps/mobile/src/features/voice-mode/voiceMode.ts' | head -160
printf '%s\n' '--- tracked voice mode / voice input package files ---'
git ls-tree -r --name-only 7a996c1d1e638587da0caeae496ea894bbcf0af1 | grep -E 'voice-(mode|input)|voiceMode' | head -200Repository: pingdotgg/t3code Length of output: 3405 🏁 Script executed: #!/bin/bash
set -e
for spec in \
'packages/client-runtime/src/voice-mode/controller.ts:1,380' \
'packages/client-runtime/src/voice-mode/session.ts:1,180' \
'apps/mobile/src/features/voice-input/voiceInputSession.ts:1,180' \
'packages/client-runtime/src/voice-input/controller.ts:1,250'
do
file=${spec%%:*}
range=${spec#*:}
printf '\n--- %s ---\n' "$file"
git show "7a996c1d1e638587da0caeae496ea894bbcf0af1:$file" | nl -ba | sed -n "${range}p"
doneRepository: pingdotgg/t3code Length of output: 31814 Disable voice mode while any composer is dictating. When another composer owns dictation, this composer’s Suggested fixdiff --git a/apps/mobile/src/features/voice-input/useVoiceInputController.ts b/apps/mobile/src/features/voice-input/useVoiceInputController.ts
@@
return {
isAvailable: global.isAvailable && (!global.isBusy || global.ownerKey === input.ownerKey),
+ isGloballyBusy: global.isBusy,
state,
diff --git a/apps/mobile/src/features/threads/ThreadComposer.tsx b/apps/mobile/src/features/threads/ThreadComposer.tsx
@@
props.selectedThread.activeProviderThreadId !== null &&
- !voiceInput.isBusy);
+ !voiceInput.isGloballyBusy);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| const toggleVoiceConversation = useCallback(() => voiceMode.toggle(voiceTarget), [voiceTarget]); | ||||||
| const voiceModeButton = offersVoiceConversation ? ( | ||||||
| <ComposerVoiceModeButton | ||||||
| phase={voicePhase} | ||||||
| disabled={!canToggleVoiceConversation} | ||||||
| onPress={toggleVoiceConversation} | ||||||
| /> | ||||||
| ) : null; | ||||||
| const voicePresentation = resolveVoiceComposerPresentation( | ||||||
| voiceInput.state, | ||||||
| voiceInput.elapsedSeconds, | ||||||
|
|
@@ -806,6 +835,9 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer | |||||
| {selectedProviderStatus.compatibilityAdvisory.message} | ||||||
| </Text> | ||||||
| ) : null} | ||||||
|
|
||||||
| {voiceConversationLive ? <ComposerVoiceStrip /> : null} | ||||||
|
|
||||||
| {modelUnavailable ? ( | ||||||
| <Pressable accessibilityRole="button" className="px-3 py-2" onPress={openSettings}> | ||||||
| <Text className="text-xs text-foreground">Model unavailable. Open model settings.</Text> | ||||||
|
|
@@ -1048,9 +1080,11 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer | |||||
| ) : null} | ||||||
| {!isExpanded ? ( | ||||||
| <View className="flex-row items-center"> | ||||||
| {voiceModeButton} | ||||||
| <ComposerDictationStartAction | ||||||
| state={voiceInput.state} | ||||||
| isAvailable={voiceInput.isAvailable} | ||||||
| disabled={voiceConversationLive} | ||||||
| onStart={voiceInput.start} | ||||||
| onCancel={voiceInput.cancel} | ||||||
| /> | ||||||
|
|
@@ -1141,10 +1175,12 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer | |||||
| </View> | ||||||
| )} | ||||||
| <View className="shrink-0 flex-row items-center"> | ||||||
| {isVoiceInputPresented ? null : voiceModeButton} | ||||||
| <ComposerDictationPrimaryAction | ||||||
| state={voiceInput.state} | ||||||
| presentation={voicePresentation} | ||||||
| isAvailable={voiceInput.isAvailable} | ||||||
| disabled={voiceConversationLive} | ||||||
| onStart={voiceInput.start} | ||||||
| onConfirm={voiceInput.stop} | ||||||
| onCancel={voiceInput.cancel} | ||||||
|
|
||||||
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.
🟠 High
threads/ThreadComposer.tsx:518Navigating from thread A to thread B leaves A's voice session and microphone running while A's composer is retained in the navigation stack, so B shows no
ComposerVoiceStripor stop control for the active session.useVoiceModeThreadLifecycle(voiceTarget)only cleans up on unmount or target change and does not handle navigation blur; stop the session when the thread loses focus, while preserving the intended overlay behavior.🤖 Copy this AI Prompt to have your agent fix this: