Control Windows audio streaming from Alice
This commit is contained in:
@@ -16,6 +16,17 @@ function volumeLevel(text) {
|
||||
export function quickAction(transcript) {
|
||||
const text = transcript.toLowerCase().replace(/[.,!?;:…\s]+/gu, ' ').trim()
|
||||
.replace(/^алиса\s+/, '').replace(/^пожалуйста\s+|\s+пожалуйста$/g, '');
|
||||
const pc = /^(включи|запусти|выключи|отключи|останови) (?:звук|трансляцию(?: звука)?) (?:с |из )?(?:пк|компьютера|компа)(?: на колонку| на колонке)?$/u.exec(text);
|
||||
if (pc) {
|
||||
const enabled = pc[1] === 'включи' || pc[1] === 'запусти';
|
||||
return {
|
||||
name: 'pc_audio',
|
||||
args: { action: enabled ? 'start' : 'stop' },
|
||||
done: enabled ? 'Звук с компьютера включён.' : 'Звук с компьютера выключен.',
|
||||
failure: 'Не удалось переключить звук с компьютера. Проверь агент на Windows.',
|
||||
success: result => result?.ok === true && result.enabled === enabled,
|
||||
};
|
||||
}
|
||||
if (/^(?:пауза|на паузу|(?:поставь|поставить)(?: музыку| воспроизведение)? на паузу|(?:приостанови|выключи|останови) (?:музыку|воспроизведение))$/.test(text)) {
|
||||
return {
|
||||
name: 'spotify_control',
|
||||
|
||||
@@ -11,6 +11,7 @@ const actions = {
|
||||
|
||||
export const tools = [
|
||||
{ type: 'openrouter:web_search' },
|
||||
{ type: 'function', function: { name: 'pc_audio', description: 'Start, stop or check the Windows PC audio mirror on the speaker. Use for explicit requests about sound from the PC, independently of Spotify.', parameters: { type: 'object', properties: { action: { type: 'string', enum: ['start', 'stop', 'status'] } }, required: ['action'], additionalProperties: false } } },
|
||||
{ type: 'function', function: { name: 'spotify_play', description: 'Play a track, artist, album or playlist on Spotify. Pass type when the user names a kind of content. Normalize known transliterations.', parameters: { type: 'object', properties: { query: { type: 'string', maxLength: 500 }, uri: { type: 'string', maxLength: 500 }, type: { type: 'string', enum: spotifyTypes } }, additionalProperties: false } } },
|
||||
{ type: 'function', function: { name: 'spotify_control', description: 'Control Spotify on the station. Use status for what is playing, queue to read upcoming tracks, enqueue to add a track by name, seek with an absolute position in milliseconds, and repeat with track, context (album or playlist), or off.', parameters: { type: 'object', properties: { action: { type: 'string', enum: Object.keys(actions) }, ...Object.assign({}, ...Object.values(actions)) }, required: ['action'], additionalProperties: false } } },
|
||||
{ type: 'function', function: { name: 'spotify_playlist', description: 'List own playlists, read tracks, create a private playlist, or add/remove a track. Use playlistUri for an existing playlist, trackUri or trackQuery for a track, and name when creating.', parameters: { type: 'object', properties: {
|
||||
@@ -44,6 +45,8 @@ export function validateTool(name, args) {
|
||||
if (args.playlistUri && !/^spotify:playlist:[A-Za-z0-9]{22}$/.test(args.playlistUri)) throw new Error('invalid_arguments');
|
||||
if (args.trackUri && !/^spotify:track:[A-Za-z0-9]{22}$/.test(args.trackUri)) throw new Error('invalid_arguments');
|
||||
if (['add', 'remove'].includes(args.action) && !args.trackUri && !args.trackQuery) throw new Error('invalid_arguments');
|
||||
} else if (name === 'pc_audio') {
|
||||
if (keys.length !== 1 || !['start', 'stop', 'status'].includes(args.action)) throw new Error('invalid_arguments');
|
||||
} else if (name === 'station_volume') {
|
||||
if (keys.length !== 1 || ('delta' in args ? ![-10, 10].includes(args.delta) : !Number.isInteger(args.level) || args.level < 0 || args.level > 100)) throw new Error('invalid_arguments');
|
||||
} else throw new Error('unknown_tool');
|
||||
|
||||
Reference in New Issue
Block a user