feat(settings): onboard hub provider credentials for dictation and voice (#1392)

* feat(settings): onboard hub transcription provider credentials in UI

Env-only keys made dictation invisible; Settings can now add/edit/clear
hub-side credentials (masked), with env still winning as override.
Refs tiann/hapi#1384.

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(settings): onboard voice-assistant backends alongside dictation

Same Settings credential surface now covers ElevenLabs, Gemini Live, and
Qwen Realtime (alias env pairs), not only transcription providers.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): address PR #1392 Major credential onboard findings

Alias env locks, non-destructive Save (omit empty fields), and
owner-only settings.json permissions for hub-stored provider secrets.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): harden credential onboard for second-pass Majors

Owner-namespace gate, stage-then-sync env after persist, and
per-field OpenAI-compatible editability under mixed env locks.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): serialize settings RMW and clear partial compatible creds

Per-file settings lock for concurrent credential PUTs, and Clear shown
for partial OpenAI-compatible entries (key/url/model alone).

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): serialize all settings writers via updateSettings

Route credentials, relay auth, generators, server settings, and CLI
token persistence through a locked RMW helper; reset Clear form state.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): share cross-process settings lock with CLI

Extract withSettingsFileLock for hub+CLI, keep owner-only 0o600
rewrites, and race hub credential updates against CLI-style writers.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): keep UI secrets out of process.env; PID-own settings locks

Settings-backed provider credentials now live in an in-memory overlay
(getProviderEnvironment) so tunnel/ACP/Codex children do not inherit them.
Settings file locks record pid+token and only reclaim dead or legacy locks.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): never reclaim ownerless settings lock sidecars

wx creates the lock path before the owner JSON is visible; unlinking
null owners let a waiter steal a live acquisition and collide on
settings.json.tmp (CI ENOENT). Only reclaim parsed owners with dead PIDs.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): reclaim dead locks via rename; clean up failed publishes

Stale reclaim renames the sidecar to a unique break path and re-verifies
the expected dead owner before deleting it, so a loser cannot unlink a
successor's live lock. Failed owner writes unlink the wx sidecar.
Reclaim uses a sync owner read so contenders do not all observe one
dead owner across an await and race the exclusive create.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): reclaim dead locks under exclusive reaper sidecar

Stale reclaim now takes a fixed settings.json.lock.reap lock, re-validates
pid+token, then unlinks — so a delayed contender cannot move a successor's
live lock aside. Also document providerCredentials in settings.schema.json.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): fail closed on corrupt CLI settings; backoff busy reaper

CLI updateSettings now uses a strict read that rejects invalid JSON
instead of treating errors as {}, which could wipe providerCredentials.
Settings lock reclaim sleeps when another process holds .reap so retries
are not burned synchronously.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): publish locks via candidate+link; fix CLI vitest hoist

Acquire settings locks by writing a complete candidate then linkSync to
the fixed path so a crash cannot leave an empty live sidecar. Fix the
CLI persistence regression test to create its temp dir inside vi.hoisted.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): replace bespoke lock with proper-lockfile; hide tenant creds UI

Codex kept finding crash windows in hand-rolled lock sidecars. Switch the
shared settings lock to proper-lockfile's mkdir + mtime lease. Hide the
owner-only credentials editor from non-default namespaces on the voice page.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(settings): adapt sessionSummaryContract to outcome updateSettings

Rebase onto main brought #1376 unique tmp + outcome-shaped writers;
wire sessionSummaryContract and the write-failure credential test to match.

Co-authored-by: Cursor <cursoragent@cursor.com>

* chore: retrigger CI after rebase onto upstream/main

Empty commit — Meta reported no checks on da0c6c258 after tip-forward rebase.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
HeavyGee
2026-08-07 13:20:03 +08:00
committed by GitHub
co-authored by Cursor
parent a020c73629
commit 28df974edd
32 changed files with 2072 additions and 372 deletions
+36
View File
@@ -183,4 +183,40 @@ describe('ApiClient error mapping', () => {
await expect(api.fetchVoiceBackend()).resolves.toEqual({ backend: null, backends: [] })
expect(fetchMock.mock.calls[0]?.[0]).toBe('/api/voice/backend')
})
it('reads and updates masked transcription credentials', async () => {
const status = {
openai: { configured: true, source: 'settings', hint: '••••cret', editable: true },
elevenlabs: { configured: false, source: 'none', hint: null, editable: true },
deepgram: { configured: false, source: 'none', hint: null, editable: true },
groq: { configured: false, source: 'none', hint: null, editable: true },
openaiCompatible: {
configured: false,
source: 'none',
baseUrl: null,
model: null,
baseUrlEditable: true,
modelEditable: true,
apiKey: { configured: false, source: 'none', hint: null, editable: true },
},
voiceBackends: {
elevenlabs: { configured: false, source: 'none', hint: null, editable: true },
geminiLive: { configured: false, source: 'none', hint: null, editable: true },
qwenRealtime: { configured: false, source: 'none', hint: null, editable: true },
},
}
fetchMock
.mockResolvedValueOnce(new Response(JSON.stringify(status), { status: 200 }))
.mockResolvedValueOnce(new Response(JSON.stringify(status), { status: 200 }))
const api = new ApiClient('test-token')
await expect(api.fetchTranscriptionCredentials()).resolves.toEqual(status)
expect(fetchMock.mock.calls[0]?.[0]).toBe('/api/voice/transcription/credentials')
await expect(api.updateTranscriptionCredentials({ openai: 'sk-test' })).resolves.toEqual(status)
const [, init] = fetchMock.mock.calls[1] ?? []
expect(fetchMock.mock.calls[1]?.[0]).toBe('/api/voice/transcription/credentials')
expect(init?.method).toBe('PUT')
expect(init?.body).toBe(JSON.stringify({ openai: 'sk-test' }))
})
})
+57
View File
@@ -56,6 +56,50 @@ import type { AgentFlavor, MessageDeliveryMode } from '@hapi/protocol'
import type { CancelMessageResponse } from '@hapi/protocol/schemas'
import type { TranscriptionMode, TranscriptionProvider, TranscriptionProviderInfo } from '@hapi/protocol/voice'
export type ProviderCredentialSource = 'env' | 'settings' | 'none'
export interface MaskedCredentialStatus {
configured: boolean
source: ProviderCredentialSource
hint: string | null
editable: boolean
}
export interface TranscriptionCredentialStatus {
openai: MaskedCredentialStatus
elevenlabs: MaskedCredentialStatus
deepgram: MaskedCredentialStatus
groq: MaskedCredentialStatus
openaiCompatible: {
configured: boolean
source: ProviderCredentialSource
baseUrl: string | null
model: string | null
baseUrlEditable: boolean
modelEditable: boolean
apiKey: MaskedCredentialStatus
}
voiceBackends: {
elevenlabs: MaskedCredentialStatus
geminiLive: MaskedCredentialStatus
qwenRealtime: MaskedCredentialStatus
}
}
export interface TranscriptionCredentialsUpdate {
openai?: string | null
elevenlabs?: string | null
deepgram?: string | null
groq?: string | null
openaiCompatible?: {
baseUrl?: string | null
model?: string | null
apiKey?: string | null
}
geminiLive?: string | null
qwenRealtime?: string | null
}
type ApiClientOptions = {
baseUrl?: string
getToken?: () => string | null
@@ -1040,6 +1084,19 @@ export class ApiClient {
return await this.request('/api/voice/transcription/providers')
}
async fetchTranscriptionCredentials(): Promise<TranscriptionCredentialStatus> {
return await this.request('/api/voice/transcription/credentials')
}
async updateTranscriptionCredentials(
update: TranscriptionCredentialsUpdate
): Promise<TranscriptionCredentialStatus> {
return await this.request('/api/voice/transcription/credentials', {
method: 'PUT',
body: JSON.stringify(update),
})
}
async transcribeVoice(options: {
file: File
provider: TranscriptionProvider