Allow deleting downloaded speech models on desktop and mobile (#5794)
* Allow deleting downloaded speech models on desktop and mobile Implement safe deletion of local speech models across desktop and mobile platforms. - Add a shared helper to coordinate STT service teardown, file deletion, and voice settings cleanup. - Prevent deleting speech models that are currently in use or starting. - Update desktop and mobile settings UIs to expose the delete action. * Track multiple pending model deletions and update action disabling - Replace the single pending delete ID string state with a Set of IDs on desktop settings to track multiple concurrently deleting models. - Switch the desktop delete action to use the standard themed Button component. - Disable all row interactions on the mobile voice model list when any model action is busy. - Add unit test coverage verifying that individual row delete button disabled states behave correctly.
This commit is contained in:
@@ -625,6 +625,10 @@ import type { RateLimitState } from '../../shared/rate-limit-types'
|
||||
import type { VoiceSettings } from '../../shared/speech-types'
|
||||
import { getSpeechModelManager, getSpeechSttService } from '../speech/speech-runtime-service'
|
||||
import { getCatalogModel, isLocalSpeechModel, SPEECH_MODEL_CATALOG } from '../speech/model-catalog'
|
||||
import {
|
||||
deleteLocalSpeechModel,
|
||||
getSpeechModelDeletionErrorCode
|
||||
} from '../speech/speech-model-deletion'
|
||||
import type { CommitMessageAgentEnvironmentResolvers } from '../text-generation/commit-message-agent-environment'
|
||||
import { scanNestedRepos } from '../project-groups/nested-repo-discovery'
|
||||
import {
|
||||
@@ -2980,7 +2984,9 @@ export class OrcaRuntimeService {
|
||||
.map((group) => {
|
||||
const tabOrder = retainedOrder.get(group.id) ?? []
|
||||
const keptActive =
|
||||
group.activeTabId && tabOrder.includes(group.activeTabId) && liveTabIds.has(group.activeTabId)
|
||||
group.activeTabId &&
|
||||
tabOrder.includes(group.activeTabId) &&
|
||||
liveTabIds.has(group.activeTabId)
|
||||
? group.activeTabId
|
||||
: null
|
||||
return {
|
||||
@@ -3370,8 +3376,7 @@ export class OrcaRuntimeService {
|
||||
groupIdByTabId.set(newTabAssignment!.tabId, newTabAssignment!.groupId)
|
||||
}
|
||||
const activeGroupId =
|
||||
(activeTopLevelId ? groupIdByTabId.get(activeTopLevelId) : undefined) ??
|
||||
existingGroups[0]!.id
|
||||
(activeTopLevelId ? groupIdByTabId.get(activeTopLevelId) : undefined) ?? existingGroups[0]!.id
|
||||
const orderByGroup = new Map<string, string[]>(existingGroups.map((group) => [group.id, []]))
|
||||
for (const tabId of tabOrder) {
|
||||
const groupId = groupIdByTabId.get(tabId) ?? activeGroupId
|
||||
@@ -4061,14 +4066,12 @@ export class OrcaRuntimeService {
|
||||
// Merge the client's pane structure into the persisted tab layout. PTY
|
||||
// bindings and active leaf stay host-owned; only ratios/expand/titles change.
|
||||
// terminalLayoutsByTabId is keyed by tab id (worktree-independent).
|
||||
private persistHeadlessTerminalPaneLayout(
|
||||
args: {
|
||||
tabId: string
|
||||
root: TerminalPaneLayoutNode | null
|
||||
expandedLeafId: string | null
|
||||
titlesByLeafId?: Record<string, string>
|
||||
}
|
||||
): void {
|
||||
private persistHeadlessTerminalPaneLayout(args: {
|
||||
tabId: string
|
||||
root: TerminalPaneLayoutNode | null
|
||||
expandedLeafId: string | null
|
||||
titlesByLeafId?: Record<string, string>
|
||||
}): void {
|
||||
const session = this.store?.getWorkspaceSession?.()
|
||||
if (!session || !this.store?.setWorkspaceSession) {
|
||||
return
|
||||
@@ -4167,11 +4170,7 @@ export class OrcaRuntimeService {
|
||||
})
|
||||
const active = nextTabs.find((candidate) => candidate.isActive) ?? nextTabs[0] ?? null
|
||||
const reorderedTargetActiveTabId =
|
||||
active?.type === 'terminal'
|
||||
? active.parentTabId
|
||||
: active
|
||||
? active.id
|
||||
: (tabOrder[0] ?? null)
|
||||
active?.type === 'terminal' ? active.parentTabId : active ? active.id : (tabOrder[0] ?? null)
|
||||
// Why: reorder only changes ONE group's order. Preserve every other group so
|
||||
// a multi-group split isn't deleted by re-sorting tabs in one of its groups.
|
||||
const existingGroups = snapshot.tabGroups ?? []
|
||||
@@ -4323,9 +4322,7 @@ export class OrcaRuntimeService {
|
||||
...session,
|
||||
tabsByWorktree: {
|
||||
...session.tabsByWorktree,
|
||||
[worktreeId]: tabs.map((tab) =>
|
||||
tab.id === tabId ? { ...tab, customTitle: title } : tab
|
||||
)
|
||||
[worktreeId]: tabs.map((tab) => (tab.id === tabId ? { ...tab, customTitle: title } : tab))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -5549,6 +5546,28 @@ export class OrcaRuntimeService {
|
||||
return { started: true }
|
||||
}
|
||||
|
||||
async deleteMobileSpeechModel(modelId: string): Promise<RuntimeSpeechSetupState> {
|
||||
if (!this.store?.getSettings || !this.store.updateSettings) {
|
||||
throw new Error('voice_dictation_unavailable')
|
||||
}
|
||||
const store = this.store
|
||||
try {
|
||||
// The runtime store is adapted to the minimal speech settings contract used by deletion.
|
||||
await deleteLocalSpeechModel({
|
||||
store: {
|
||||
getSettings: () => store.getSettings(),
|
||||
updateSettings: (updates, options) => store.updateSettings?.(updates, options)
|
||||
},
|
||||
modelManager: getSpeechModelManager(store),
|
||||
sttService: getSpeechSttService(store),
|
||||
modelId
|
||||
})
|
||||
} catch (error) {
|
||||
throw new Error(getSpeechModelDeletionErrorCode(error) ?? 'voice_model_delete_failed')
|
||||
}
|
||||
return this.listMobileSpeechModels()
|
||||
}
|
||||
|
||||
// Enables/disables dictation and/or selects the model, merging into the
|
||||
// existing voice settings so other voice fields are preserved.
|
||||
async configureMobileDictation(params: {
|
||||
@@ -15118,8 +15137,7 @@ export class OrcaRuntimeService {
|
||||
} catch {
|
||||
warnings.push({
|
||||
code: 'LINEAGE_PARENT_CONTEXT_MISSING',
|
||||
message:
|
||||
'Worktree created, but Orca could not validate the environment parent context.',
|
||||
message: 'Worktree created, but Orca could not validate the environment parent context.',
|
||||
details: { envParentWorkspace: input.envParentWorkspace }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -102,6 +102,35 @@ describe('speech RPC methods', () => {
|
||||
expect(response).toMatchObject({ ok: true, result: { started: true } })
|
||||
})
|
||||
|
||||
it('deletes a speech model and returns refreshed setup', async () => {
|
||||
const setup = { enabled: true, selectedModelId: '', dictationMode: 'toggle', models: [] }
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'test-runtime',
|
||||
deleteMobileSpeechModel: vi.fn().mockResolvedValue(setup)
|
||||
} as unknown as OrcaRuntimeService
|
||||
const dispatcher = new RpcDispatcher({ runtime, methods: SPEECH_METHODS })
|
||||
|
||||
const response = await dispatcher.dispatch(
|
||||
makeRequest('speech.models.delete', { modelId: 'parakeet-tdt-0.6b-v3-int8' })
|
||||
)
|
||||
|
||||
expect(runtime.deleteMobileSpeechModel).toHaveBeenCalledWith('parakeet-tdt-0.6b-v3-int8')
|
||||
expect(response).toMatchObject({ ok: true, result: setup })
|
||||
})
|
||||
|
||||
it('rejects invalid speech model delete params', async () => {
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'test-runtime',
|
||||
deleteMobileSpeechModel: vi.fn()
|
||||
} as unknown as OrcaRuntimeService
|
||||
const dispatcher = new RpcDispatcher({ runtime, methods: SPEECH_METHODS })
|
||||
|
||||
const response = await dispatcher.dispatch(makeRequest('speech.models.delete', {}))
|
||||
|
||||
expect(response).toMatchObject({ ok: false })
|
||||
expect(runtime.deleteMobileSpeechModel).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('configures dictation enable + model selection', async () => {
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'test-runtime',
|
||||
|
||||
@@ -38,7 +38,7 @@ const DictationHandle = z.object({
|
||||
dictationId: requiredString('Missing dictation ID')
|
||||
})
|
||||
|
||||
const SpeechModelDownload = z.object({
|
||||
const SpeechModelAction = z.object({
|
||||
modelId: requiredString('Missing model ID')
|
||||
})
|
||||
|
||||
@@ -56,9 +56,14 @@ export const SPEECH_METHODS: RpcMethod[] = [
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'speech.models.download',
|
||||
params: SpeechModelDownload,
|
||||
params: SpeechModelAction,
|
||||
handler: async (params, { runtime }) => runtime.downloadMobileSpeechModel(params.modelId)
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'speech.models.delete',
|
||||
params: SpeechModelAction,
|
||||
handler: async (params, { runtime }) => runtime.deleteMobileSpeechModel(params.modelId)
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'speech.dictation.setup',
|
||||
params: DictationSetup,
|
||||
|
||||
@@ -305,6 +305,7 @@ const MOBILE_RPC_METHOD_ALLOWLIST = new Set([
|
||||
'speech.dictation.finish',
|
||||
'speech.dictation.setup',
|
||||
'speech.dictation.start',
|
||||
'speech.models.delete',
|
||||
'speech.models.download',
|
||||
'speech.models.list',
|
||||
'stats.summary',
|
||||
|
||||
Reference in New Issue
Block a user