Improve voice turns, local commands and Spotify controls
This commit is contained in:
+17
-3
@@ -4,6 +4,8 @@ import { join } from 'node:path';
|
||||
export const defaults = Object.freeze({
|
||||
llmModel: 'anthropic/claude-haiku-5.5',
|
||||
sttModel: 'scribe_v3_live',
|
||||
followUpMs: 3000,
|
||||
activationSound: false,
|
||||
ttsModel: 'eleven_v4_turbo',
|
||||
voiceId: '21m00Tcm4TlvDq8ikWAM',
|
||||
systemPrompt: 'Ты голосовой помощник Алиса. Отвечай по-русски, коротко и по делу. Пиши так, чтобы ответ хорошо звучал вслух: обычный текст, без Markdown. Если не знаешь ответа, скажи об этом прямо.',
|
||||
@@ -14,12 +16,13 @@ export const ttsModels = ['eleven_v4_turbo', 'eleven_v3_conversational', 'eleven
|
||||
|
||||
export function validateSettings(input) {
|
||||
if (typeof input !== 'object' || input === null) return null;
|
||||
const { llmModel, sttModel, ttsModel, voiceId, systemPrompt } = input;
|
||||
const { llmModel, sttModel, ttsModel, voiceId, systemPrompt, followUpMs = defaults.followUpMs, activationSound = defaults.activationSound } = input;
|
||||
if (typeof llmModel !== 'string' || !/^[\w.~:-]+\/[\w.:~-]+$/.test(llmModel) || llmModel.length > 120) return null;
|
||||
if (!sttModels.includes(sttModel) || !ttsModels.includes(ttsModel)) return null;
|
||||
if (typeof voiceId !== 'string' || !/^[a-zA-Z0-9]{20}$/.test(voiceId)) return null;
|
||||
if (typeof systemPrompt !== 'string' || !systemPrompt.trim() || systemPrompt.length > 4000) return null;
|
||||
return { llmModel, sttModel, ttsModel, voiceId, systemPrompt: systemPrompt.trim() };
|
||||
if (!Number.isInteger(followUpMs) || followUpMs < 0 || followUpMs > 10000 || typeof activationSound !== 'boolean') return null;
|
||||
return { llmModel, sttModel, ttsModel, voiceId, systemPrompt: systemPrompt.trim(), followUpMs, activationSound };
|
||||
}
|
||||
|
||||
export function openStore(directory = process.env.DATA_DIR ?? './data') {
|
||||
@@ -30,7 +33,7 @@ export function openStore(directory = process.env.DATA_DIR ?? './data') {
|
||||
const saved = JSON.parse(readFileSync(path, 'utf8'));
|
||||
const settings = validateSettings({ ...defaults, ...saved.settings });
|
||||
if (!settings || !Array.isArray(saved.history)) throw new Error('Invalid assistant state');
|
||||
state = { settings, history: saved.history };
|
||||
state = { settings, history: saved.history, device: saved.device };
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') throw error;
|
||||
}
|
||||
@@ -43,6 +46,17 @@ export function openStore(directory = process.env.DATA_DIR ?? './data') {
|
||||
}
|
||||
|
||||
return {
|
||||
getDevice: () => {
|
||||
if (!state.device) return null;
|
||||
return { ...state.device, online: Date.now() - state.device.updatedAt < 45000 };
|
||||
},
|
||||
recordDevice(device) {
|
||||
const updatedAt = Date.now();
|
||||
const lastPlayback = device.item?.uri && device.active
|
||||
? { item: device.item, context: device.context, position: device.position, status: device.status, updatedAt }
|
||||
: state.device?.lastPlayback;
|
||||
commit({ ...state, device: { ...device, updatedAt, lastPlayback } });
|
||||
},
|
||||
getSettings: () => ({ ...state.settings }),
|
||||
getHistory: () => state.history.map(turn => ({ ...turn })),
|
||||
updateSettings(settings) {
|
||||
|
||||
Reference in New Issue
Block a user