The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(voice): A19 voice session speaks as the persona of the open chat
purplec3485d9a28ed
diff --git a/src/api/__tests__/a19-voice-speaks-as-the-persona.test.ts b/src/api/__tests__/a19-voice-speaks-as-the-persona.test.tsnew file mode 100644index 00000000..d47a697c--- /dev/null+++ b/src/api/__tests__/a19-voice-speaks-as-the-persona.test.ts@@ -0,0 +1,133 @@+// A19 (setimu, Discord 12.11.2026): Voice ignored the persona of the chat.+//+// A voice session keeps its transcript in a conversation made fresh at Start,+// and a fresh conversation starts with the persona off. The system prompt was+// built from that record, so Voice always answered as the plain assistant.+//+// This drives the real startVoiceSession up to the request that opens the+// session on the voice loop (/session) and reads the system prompt it sends.+// Only the edges are stubbed: microphone, the voice loop process, the brain.+//+// Run: npx vitest run src/api/__tests__/a19-voice-speaks-as-the-persona.test.ts+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++vi.mock('../voice-media', () => {+ class VoiceMicError extends Error {}+ class LuVoiceMediaManager {+ selectedMic = {}+ updateMic = vi.fn(async () => {})+ initialize() { return Promise.resolve() }+ disconnect() { return Promise.resolve() }+ enableMic() {}+ levels() { return { mic: 0, bot: 0 } }+ }+ return { LuVoiceMediaManager, VoiceMicError }+})+vi.mock('../microphone', () => ({ listMicrophones: vi.fn(async () => []), onMicrophoneChosen: () => () => {} }))+vi.mock('../voice-loop', () => ({+ getVoiceLoopStatus: vi.fn(async () => ({ ready: true })),+ startVoiceLoop: vi.fn(async () => ({ port: 1, token: 't', baseUrl: 'http://127.0.0.1:1', voice: 'v' })),+ stopVoiceLoop: vi.fn(async () => {}),+}))+vi.mock('../voice-speech', () => ({ voiceSessionSpeech: vi.fn(async () => ({})) }))+vi.mock('../workspace-slug', () => ({ resolveChatWorkspaceSlug: vi.fn(async () => 'voice-test') }))+vi.mock('../voice-brain', async (orig) => {+ const real = await orig<typeof import('../voice-brain')>()+ return {+ ...real,+ resolveVoiceBrain: vi.fn(async () => ({+ llm: { base_url: 'http://127.0.0.1:2/v1', model: 'test-model' },+ providerId: 'openai',+ modelLabel: 'Test model',+ toolsSupported: false,+ local: true,+ thinking: () => ({ extra: {}, directExtra: {}, wanted: false, always: false }),+ })),+ }+})++import { startVoiceSession, stopVoiceSession } from '../voice-session'+import { useChatStore } from '../../stores/chatStore'+import { useSettingsStore } from '../../stores/settingsStore'+import { useModelStore } from '../../stores/modelStore'+import type { Persona } from '../../types/settings'++const BARON: Persona = {+ id: 'baron',+ name: 'Baron',+ icon: 'Crown',+ systemPrompt: 'You are Baron von Pfeffer, a grumpy aristocrat who answers every question with a sigh.',+ isBuiltIn: false,+} as Persona++let sentPrompt: string | null = null+/** The conversations as they stood when /session was asked for. A start+ * that fails afterwards removes its empty record again. */+let atSession: ReturnType<typeof useChatStore.getState>['conversations'] = []++beforeEach(() => {+ sentPrompt = null+ vi.stubGlobal('fetch', vi.fn(async (url: string, init?: RequestInit) => {+ if (String(url).endsWith('/session')) {+ sentPrompt = JSON.parse(String(init?.body)).system_prompt+ atSession = useChatStore.getState().conversations+ // The test has what it came for; the start ends here.+ return new Response('stop here', { status: 500 })+ }+ return new Response('{}', { status: 404 })+ }))+ useModelStore.setState({ activeModel: 'openai::test-model' } as never)+ useSettingsStore.setState((s) => ({+ personas: [...s.personas.filter((p) => p.id !== BARON.id), BARON],+ activePersonaId: undefined,+ settings: { ...s.settings, personasEnabled: true },+ }) as never)+})++afterEach(() => {+ stopVoiceSession()+ vi.unstubAllGlobals()+})++async function startAndRead(): Promise<string> {+ await startVoiceSession().catch(() => {})+ await vi.waitFor(() => expect(sentPrompt).not.toBeNull(), { timeout: 3000 })+ return sentPrompt!+}++describe('A19: Voice speaks as the persona of the chat it was started from', () => {+ it('a chat with Baron switched on: the session prompt carries Baron', async () => {+ const chat = useChatStore.getState()+ const id = chat.createConversation('openai::test-model', BARON.systemPrompt, undefined)+ useChatStore.getState().setConversationPersona(id, BARON)+ useChatStore.getState().setConversationPersonaEnabled(id, true)+ useChatStore.getState().setActiveConversation(id)++ const prompt = await startAndRead()+ expect(prompt).toContain('Baron von Pfeffer')+ // Still a voice prompt: the speech rules are kept behind the persona.+ expect(prompt).toContain('live voice conversation')++ // The session's own record speaks as Baron too, and the open chat stays open.+ expect(useChatStore.getState().activeConversationId).toBe(id)+ const record = atSession.find((c) => c.id !== id && c.personaId === BARON.id)+ expect(record?.personaEnabled).toBe(true)+ })++ it('a chat with the persona off: no persona, as before', async () => {+ const id = useChatStore.getState().createConversation('openai::test-model', BARON.systemPrompt, undefined)+ useChatStore.getState().setConversationPersona(id, BARON)+ useChatStore.getState().setConversationPersonaEnabled(id, false)+ useChatStore.getState().setActiveConversation(id)+ expect(await startAndRead()).not.toContain('Baron von Pfeffer')+ })++ it('personas switched off in Settings win over the chat', async () => {+ const id = useChatStore.getState().createConversation('openai::test-model', BARON.systemPrompt, undefined)+ useChatStore.getState().setConversationPersona(id, BARON)+ useChatStore.getState().setConversationPersonaEnabled(id, true)+ useChatStore.getState().setActiveConversation(id)+ useSettingsStore.setState((s) => ({ settings: { ...s.settings, personasEnabled: false } }) as never)+ expect(await startAndRead()).not.toContain('Baron von Pfeffer')+ })+})diff --git a/src/api/voice-session.ts b/src/api/voice-session.tsindex c75c77a6..39c560b8 100644--- a/src/api/voice-session.ts+++ b/src/api/voice-session.ts@@ -63,7 +63,7 @@ import { log } from '../lib/logger'import { resolveExecutor } from './computer-executor'import { gatePlanTool, planToolAllowed } from '../lib/plan-gate'import { buildChatSystemPrompt } from '../lib/system-prompt'-import { withChatPersona } from '../lib/chat-persona'+import { voicePersonaFrom } from '../lib/voice/voice-persona'import { applyMaxTools, toolSelectionOpts } from '../lib/tool-selection'import { yieldSilentRunsTo } from '../lib/silent-runs-yield'import { startTimeout } from '../lib/voice/session-state'@@ -557,7 +557,23 @@ export async function startVoiceSession(): Promise<void> {const settings = useSettingsStore.getState().settingsconst chat = useChatStore.getState()const shown = chat.activeConversationId- const conversationId = chat.createConversation(activeModel!, '')+ // A19: the persona of the chat on screen when Start was pressed. The new+ // record below starts with the persona off, like every new chat, so it+ // is read here, before that record exists.+ const shownConversation = shown ? chat.conversations.find((c) => c.id === shown) : undefined+ const voicePersona = voicePersonaFrom(+ shownConversation,+ useSettingsStore.getState().personas,+ useSettingsStore.getState().activePersonaId,+ settings.personasEnabled !== false,+ )+ const conversationId = chat.createConversation(activeModel!, voicePersona?.prompt ?? '')+ if (voicePersona) {+ // The record speaks as the same persona, so its Plugins menu and any+ // later typed message in it say what Voice spoke as.+ if (voicePersona.persona) useChatStore.getState().setConversationPersona(conversationId, voicePersona.persona)+ useChatStore.getState().setConversationPersonaEnabled(conversationId, true)+ }// The new conversation is the session's record, not a place the user// asked to go. Whatever chat was open stays open.useChatStore.getState().setActiveConversation(shown)@@ -592,12 +608,10 @@ export async function startVoiceSession(): Promise<void> {brain,all: tools.defs,slug,- // GH #170: the persona of THIS chat, the one its Plugins menu names.+ // GH #170 + A19: the persona of the chat the user started Voice from.prompt: {base: buildChatSystemPrompt(- conversation- ? withChatPersona(conversation, useSettingsStore.getState().personas, useSettingsStore.getState().activePersonaId)- : {},+ voicePersona ? { systemPrompt: voicePersona.prompt, personaEnabled: true } : {},settings.personasEnabled !== false,),memory,diff --git a/src/lib/voice/voice-persona.ts b/src/lib/voice/voice-persona.tsnew file mode 100644index 00000000..4fd670ea--- /dev/null+++ b/src/lib/voice/voice-persona.ts@@ -0,0 +1,49 @@+import type { Persona } from '../../types/settings'+import { isGroupChat } from '../group-chat'+import { resolveChatPersona } from '../chat-persona'++/**+ * A19 (setimu, Discord 12.11.2026): Voice ignored the persona of the chat.+ *+ * A voice session keeps its transcript in a conversation of its own, made+ * fresh at Start. A new conversation starts with the persona OFF (the+ * owner's rule for new chats), and the session built its prompt from that+ * new record. So whatever persona the chat on screen spoke as, Voice always+ * answered as the plain assistant.+ *+ * The persona now comes from the chat that was open when Start was pressed,+ * resolved the way every send resolves it (GH #170): a plain chat with its+ * persona switched on, and personas switched on in Settings. The record of+ * the session carries the same persona, so its Plugins menu says what Voice+ * spoke as. No open chat, a chat with the persona off, an agent or code chat,+ * a group chat: no persona, as before.+ */+export interface VoicePersona {+ /** The persona, absent for a kept prompt that no persona has any more. */+ persona?: Persona+ /** The prompt that goes into the session's system prompt. */+ prompt: string+}++export function voicePersonaFrom(+ shown:+ | {+ mode?: string+ personaId?: string+ systemPrompt?: string | null+ personaEnabled?: boolean+ groupModels?: string[]+ }+ | null+ | undefined,+ personas: readonly Persona[],+ activePersonaId: string | undefined,+ personasOn: boolean,+): VoicePersona | null {+ if (!shown || !personasOn || shown.personaEnabled !== true) return null+ if ((shown.mode ?? 'lu') !== 'lu') return null+ if (isGroupChat(shown.groupModels)) return null+ const resolved = resolveChatPersona(shown, personas, activePersonaId)+ if (!resolved.prompt.trim()) return null+ return resolved+}