mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(chat): tailor replies for mobile and text-to-speech
This commit is contained in:
1 parent
b140a9c77b
commit
b974618dee
7 files changed
+204
-7
No files matched your search
@@ -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 }))
|
||||
|
||||
|
||||
@@ -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,
|
||||
@@ -186,6 +188,7 @@ export async function sendPrompt(input: SendPromptInput): Promise<SessionInboxUs
|
||||
api.session.prompt({
|
||||
sessionID: input.sessionID,
|
||||
...buildPromptFields(input),
|
||||
metadata: { [MANAGER_PROMPT_CLIENT_METADATA_KEY]: isMobileViewport() ? 'mobile' : 'desktop' },
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { useState, useEffect, useCallback, useRef, type CSSProperties } from 'react'
|
||||
import { useSwipeNavigation } from '@/contexts/SwipeNavigationContext'
|
||||
|
||||
export function isMobileViewport(): boolean {
|
||||
return typeof window !== 'undefined' ? window.innerWidth < 768 : false
|
||||
}
|
||||
|
||||
export function useMobile() {
|
||||
const [isMobile, setIsMobile] = useState(() => (typeof window !== 'undefined' ? window.innerWidth < 768 : false))
|
||||
const [isMobile, setIsMobile] = useState(isMobileViewport)
|
||||
|
||||
useEffect(() => {
|
||||
const checkMobile = () => {
|
||||
setIsMobile(window.innerWidth < 768)
|
||||
setIsMobile(isMobileViewport())
|
||||
}
|
||||
|
||||
checkMobile()
|
||||
|
||||
Reference in new issue
Block a user