Merge pull request #429 from chriswritescode-dev/feature/mobile-friendly-replies

feat(chat): tailor replies for mobile and text-to-speech
This commit is contained in:
Chris Scott authored and GitHub committed 2026-10-15 16:45:28 -04:00
commit ccdf75d803
7 files changed
+218 -7

No files matched your search

+47 -1
View File
@@ -58,6 +58,7 @@ describe('OpenCode facade', () => {
afterEach(() => {
vi.unstubAllGlobals()
vi.restoreAllMocks()
})
const lastRequest = () => {
@@ -268,7 +269,7 @@ describe('OpenCode facade', () => {
const [promptUrl, promptInit] = fetchMock.mock.calls[1] ?? []
expect(String(promptUrl)).toBe('http://localhost/api/opencode/api/session/ses_new/prompt')
expect((promptInit as RequestInit).method).toBe('POST')
expect((promptInit as RequestInit).body).toBe(JSON.stringify({ text: 'Fix conflicts' }))
expect((promptInit as RequestInit).body).toBe(JSON.stringify({ text: 'Fix conflicts', metadata: { ocmClient: 'desktop' } }))
})
it('deletes the new session when sending the prompt fails', async () => {
@@ -477,11 +478,56 @@ describe('OpenCode facade', () => {
files: [{ uri: 'file:///repo/src/a.ts', name: 'a.ts', mention: { start: 6, end: 15, text: '@src/a.ts' } }],
agents: [{ name: 'build', mention: { start: 6, end: 12, text: '@build' } }],
skills: [{ id: 'review' }],
metadata: { ocmClient: 'desktop' },
delivery: 'queue',
}))
expect(inbox.id).toBe('msg_1')
})
it('marks a prompt as mobile when the viewport is narrow', async () => {
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(375)
fetchMock.mockResolvedValue(
jsonResponse({
data: {
id: 'msg_1',
sessionID: 'ses_1',
time: { created: 1000 },
type: 'user',
payload: { text: 'Hi' },
},
}),
)
await sendPrompt({ sessionID: 'ses_1', text: 'Hi' })
expect(lastRequest().init.body).toBe(JSON.stringify({
text: 'Hi',
metadata: { ocmClient: 'mobile' },
}))
})
it('marks a prompt as desktop when the viewport is wide', async () => {
vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(1280)
fetchMock.mockResolvedValue(
jsonResponse({
data: {
id: 'msg_1',
sessionID: 'ses_1',
time: { created: 1000 },
type: 'user',
payload: { text: 'Hi' },
},
}),
)
await sendPrompt({ sessionID: 'ses_1', text: 'Hi' })
expect(lastRequest().init.body).toBe(JSON.stringify({
text: 'Hi',
metadata: { ocmClient: 'desktop' },
}))
})
it('switches the session model through the V2 model route', async () => {
fetchMock.mockResolvedValue(new Response(null, { status: 204 }))
+4
View File
@@ -1,4 +1,6 @@
import { openCodeLocation, parseOpenCodeModelRef } from '@opencode-manager/shared/opencode'
import { MANAGER_PROMPT_CLIENT_METADATA_KEY } from '@opencode-manager/shared/schemas'
import { isMobileViewport } from '@/hooks/useMobile'
import { callOpenCode } from './opencodeApi'
import type {
AgentInfo,
@@ -181,11 +183,13 @@ export async function switchSessionAgent(sessionID: string, agent: string): Prom
await callOpenCode((api) => api.session.switchAgent({ sessionID, agent }))
}
/** Sends a session prompt with client metadata derived from the current viewport. */
export async function sendPrompt(input: SendPromptInput): Promise<SessionInboxUser> {
return callOpenCode((api) =>
api.session.prompt({
sessionID: input.sessionID,
...buildPromptFields(input),
metadata: { [MANAGER_PROMPT_CLIENT_METADATA_KEY]: isMobileViewport() ? 'mobile' : 'desktop' },
}),
)
}
+9 -2
View File
@@ -1,12 +1,19 @@
import { useState, useEffect, useCallback, useRef, type CSSProperties } from 'react'
import { useSwipeNavigation } from '@/contexts/SwipeNavigationContext'
/** Returns whether the viewport is narrower than 768 pixels, or false without a browser window. */
export function isMobileViewport(): boolean {
return typeof window !== 'undefined' ? window.innerWidth < 768 : false
}
/** Tracks whether the current viewport is mobile, updating the value on window resize. */
export function useMobile() {
const [isMobile, setIsMobile] = useState(() => (typeof window !== 'undefined' ? window.innerWidth < 768 : false))
const [isMobile, setIsMobile] = useState(isMobileViewport)
useEffect(() => {
/** Refreshes the mobile state from the current viewport width. */
const checkMobile = () => {
setIsMobile(window.innerWidth < 768)
setIsMobile(isMobileViewport())
}
checkMobile()