21 lines
2.2 KiB
JavaScript
21 lines
2.2 KiB
JavaScript
// OpenRouter executes web search itself; Spotify calls are handled by the device.
|
|
export const tools = [
|
|
{ type: 'openrouter:web_search' },
|
|
{ type: 'function', function: { name: 'spotify_play', description: 'Play a track, artist, album or playlist on Spotify by search query or Spotify URI. Normalize Russian transliterations of artist names to their canonical spelling when known.', parameters: { type: 'object', properties: { query: { type: 'string', maxLength: 500 }, uri: { type: 'string', maxLength: 500 } }, additionalProperties: false } } },
|
|
{ type: 'function', function: { name: 'spotify_control', description: 'Control Spotify playback or set the Spotify stream volume.', parameters: { type: 'object', properties: { action: { type: 'string', enum: ['pause', 'resume', 'next', 'previous', 'volume'] }, volume: { type: 'integer', minimum: 0, maximum: 100 } }, required: ['action'], additionalProperties: false } } },
|
|
{ type: 'function', function: { name: 'station_volume', description: 'Set the overall speaker volume for both speech and music. Use this for a general volume request.', parameters: { type: 'object', properties: { level: { type: 'integer', minimum: 0, maximum: 100 } }, required: ['level'], additionalProperties: false } } },
|
|
];
|
|
|
|
export function validateTool(name, args) {
|
|
if (!args || typeof args !== 'object' || Array.isArray(args)) throw new Error('invalid_arguments');
|
|
const keys = Object.keys(args);
|
|
if (name === 'spotify_play') {
|
|
if (keys.some(k => !['query', 'uri'].includes(k)) || !keys.length || keys.some(k => typeof args[k] !== 'string' || !args[k].trim() || args[k].length > 500)) throw new Error('invalid_arguments');
|
|
} else if (name === 'spotify_control') {
|
|
if (keys.some(k => !['action', 'volume'].includes(k)) || !['pause', 'resume', 'next', 'previous', 'volume'].includes(args.action) || (args.action === 'volume' ? !Number.isInteger(args.volume) || args.volume < 0 || args.volume > 100 : 'volume' in args)) throw new Error('invalid_arguments');
|
|
} else if (name === 'station_volume') {
|
|
if (keys.length !== 1 || !Number.isInteger(args.level) || args.level < 0 || args.level > 100) throw new Error('invalid_arguments');
|
|
} else throw new Error('unknown_tool');
|
|
return args;
|
|
}
|