refactor(frontend): rework speech-to-text to tap-first interaction (#207)

* refactor(frontend): extract VoiceStatusOverlay component and improve swipe tracking

- Extract voice status overlay to dedicated VoiceStatusOverlay.tsx component
- Move pointer event handlers from button to container for larger swipe surface area
- Users can now initiate swipe gesture from anywhere in the container, not just the button

* refactor(frontend): add SSE delta support and improve status synchronization

- Add SSEMessagePartDeltaEvent type for streaming delta updates
- Add SSESessionCreatedEvent type for session creation events
- Implement directory filtering for SSE events to prevent cross-contamination
- Add version tracking for status snapshots to ignore stale responses
- Replace individual status updates with atomic replaceStatuses operation
- Refactor parts batcher to use unified operation queue with delta support
- Clear stale statuses on initial snapshot and directory changes
- Add tests for status snapshot clearing and stale response handling

* refactor: remove auto-restart from assistant mode and fix mobile sheet close behavior

Stop restarting OpenCode after assistant mode initialization since the
startup error logic is no longer needed. Also fix the repo quick switch
sheet to stay open when launched from the mobile tab bar, preventing
unwanted navigation away from the sheet.

* refactor(frontend): improve speech-to-text UI
This commit is contained in:
Chris Scott authored and GitHub committed 2026-04-29 12:26:41 -04:00
1 parent 04400c91cc
commit f0c87ffa5d
11 files changed
+525 -270

No files matched your search

+56 -53
View File
@@ -3,18 +3,23 @@ import type { Part, MessageWithParts } from '@/api/types'
interface PartsBatcher {
queuePartUpdate: (sessionID: string, part: Part) => void
queuePartDelta: (sessionID: string, messageID: string, partID: string, field: string, delta: string) => void
queuePartRemoval: (sessionID: string, messageID: string, partID: string) => void
flush: () => void
destroy: () => void
}
type PartOperation =
| { type: 'upsert'; part: Part }
| { type: 'delta'; messageID: string; partID: string; field: string; delta: string }
| { type: 'remove'; messageID: string; partID: string }
export function createPartsBatcher(
queryClient: QueryClient,
opcodeUrl: string,
directory?: string
): PartsBatcher {
const pendingUpserts = new Map<string, Map<string, Part>>()
const pendingRemovals = new Map<string, Map<string, Set<string>>>()
const pendingOperations = new Map<string, PartOperation[]>()
let pendingFrameId: number | null = null
const scheduleFlush = () => {
@@ -26,14 +31,9 @@ export function createPartsBatcher(
}
const flush = () => {
if (pendingUpserts.size === 0 && pendingRemovals.size === 0) return
if (pendingOperations.size === 0) return
const sessionsToUpdate = new Set([
...pendingUpserts.keys(),
...pendingRemovals.keys(),
])
for (const sessionID of sessionsToUpdate) {
for (const [sessionID, operations] of pendingOperations.entries()) {
const queryKey = ['opencode', 'messages', opcodeUrl, sessionID, directory]
const currentData = queryClient.getQueryData<MessageWithParts[]>(queryKey)
@@ -41,64 +41,67 @@ export function createPartsBatcher(
let updatedData = [...currentData]
const sessionUpserts = pendingUpserts.get(sessionID)
const sessionRemovals = pendingRemovals.get(sessionID)
for (const operation of operations) {
updatedData = updatedData.map((msgWithParts) => {
if (operation.type === 'upsert') {
if (msgWithParts.info.id !== operation.part.messageID) return msgWithParts
updatedData = updatedData.map((msgWithParts) => {
let msgParts = [...msgWithParts.parts]
if (sessionRemovals?.has(msgWithParts.info.id)) {
const partIDsToRemove = sessionRemovals.get(msgWithParts.info.id)!
msgParts = msgParts.filter((p) => !partIDsToRemove.has(p.id))
}
if (sessionUpserts) {
const partsForMessage = Array.from(sessionUpserts.values()).filter(
(part) => part.messageID === msgWithParts.info.id
)
for (const part of partsForMessage) {
const existingIdx = msgParts.findIndex((p) => p.id === part.id)
const existingIdx = msgWithParts.parts.findIndex((part) => part.id === operation.part.id)
const parts = [...msgWithParts.parts]
if (existingIdx >= 0) {
msgParts[existingIdx] = part
parts[existingIdx] = operation.part
} else {
msgParts.push(part)
parts.push(operation.part)
}
return { ...msgWithParts, parts }
}
if (msgWithParts.info.id !== operation.messageID) return msgWithParts
if (operation.type === 'remove') {
return {
...msgWithParts,
parts: msgWithParts.parts.filter((part) => part.id !== operation.partID),
}
}
}
return {
...msgWithParts,
parts: msgParts,
}
})
return {
...msgWithParts,
parts: msgWithParts.parts.map((part) => {
if (part.id !== operation.partID) return part
const currentValue = (part as Record<string, unknown>)[operation.field]
const nextValue = `${typeof currentValue === 'string' ? currentValue : ''}${operation.delta}`
return { ...part, [operation.field]: nextValue } as Part
}),
}
})
}
queryClient.setQueryData(queryKey, updatedData)
}
pendingUpserts.clear()
pendingRemovals.clear()
pendingOperations.clear()
}
const queueOperation = (sessionID: string, operation: PartOperation) => {
const operations = pendingOperations.get(sessionID) ?? []
operations.push(operation)
pendingOperations.set(sessionID, operations)
scheduleFlush()
}
const queuePartUpdate = (sessionID: string, part: Part) => {
if (!pendingUpserts.has(sessionID)) {
pendingUpserts.set(sessionID, new Map())
}
const sessionUpserts = pendingUpserts.get(sessionID)!
sessionUpserts.set(part.id, part)
scheduleFlush()
queueOperation(sessionID, { type: 'upsert', part })
}
const queuePartDelta = (sessionID: string, messageID: string, partID: string, field: string, delta: string) => {
queueOperation(sessionID, { type: 'delta', messageID, partID, field, delta })
}
const queuePartRemoval = (sessionID: string, messageID: string, partID: string) => {
if (!pendingRemovals.has(sessionID)) {
pendingRemovals.set(sessionID, new Map())
}
const sessionRemovals = pendingRemovals.get(sessionID)!
if (!sessionRemovals.has(messageID)) {
sessionRemovals.set(messageID, new Set())
}
const messageRemovals = sessionRemovals.get(messageID)!
messageRemovals.add(partID)
scheduleFlush()
queueOperation(sessionID, { type: 'remove', messageID, partID })
}
const destroy = () => {
@@ -106,12 +109,12 @@ export function createPartsBatcher(
cancelAnimationFrame(pendingFrameId)
pendingFrameId = null
}
pendingUpserts.clear()
pendingRemovals.clear()
pendingOperations.clear()
}
return {
queuePartUpdate,
queuePartDelta,
queuePartRemoval,
flush,
destroy,