152 lines
6.1 KiB
TypeScript
152 lines
6.1 KiB
TypeScript
|
|
import { FunctionDeclaration, Type } from '@google/genai';
|
|
import { StorageService } from '../services/storageService';
|
|
|
|
export const SYSTEM_TOOLS: FunctionDeclaration[] = [
|
|
{
|
|
name: 'configure_system',
|
|
parameters: {
|
|
type: Type.OBJECT,
|
|
description: 'Changes system settings like theme, focus mode, or language.',
|
|
properties: {
|
|
setting: { type: Type.STRING, enum: ['focus_mode', 'theme', 'language'] },
|
|
value: { type: Type.STRING, description: 'Value for the setting (e.g., "on/off", "dark/light", "nepali/english").' }
|
|
},
|
|
required: ['setting', 'value']
|
|
}
|
|
},
|
|
{
|
|
name: 'open_external_link',
|
|
parameters: {
|
|
type: Type.OBJECT,
|
|
description: 'Opens external websites, plays songs, or performs searches. For "Play [Song]", this uses a smart redirect to the video.',
|
|
properties: {
|
|
platform: { type: Type.STRING, description: 'The platform name (youtube, google, facebook, instagram, twitter, linkedin, spotify, wikipedia, etc.).' },
|
|
action: { type: Type.STRING, enum: ['open', 'search', 'play'], description: 'The intent. Use "play" for media which attempts direct playback.' },
|
|
query: { type: Type.STRING, description: 'The search term, song name, or content title.' }
|
|
},
|
|
required: ['platform']
|
|
}
|
|
},
|
|
{
|
|
name: 'adjust_device_hardware',
|
|
parameters: {
|
|
type: Type.OBJECT,
|
|
description: 'Request to change device brightness or volume. Returns a placeholder response.',
|
|
properties: {
|
|
feature: { type: Type.STRING, enum: ['brightness', 'volume'] },
|
|
value: { type: Type.NUMBER, description: 'The target level percentage (0-100).' }
|
|
},
|
|
required: ['feature']
|
|
}
|
|
},
|
|
{
|
|
name: 'terminate_voice_session',
|
|
parameters: {
|
|
type: Type.OBJECT,
|
|
description: 'Ends the current voice conversation/link without logging out. Use when user says "stop listening", "terminate session", "cut link", "bye".',
|
|
properties: {}
|
|
}
|
|
},
|
|
{
|
|
name: 'system_logout',
|
|
parameters: {
|
|
type: Type.OBJECT,
|
|
description: 'Logs the user out of the application completely. Requires explicit "Logout" command.',
|
|
properties: {}
|
|
}
|
|
}
|
|
];
|
|
|
|
export const executeSystemTool = async (name: string, args: any, navigate: (path: string) => void) => {
|
|
if (name === 'configure_system') {
|
|
if (args.setting === 'focus_mode') {
|
|
const turnOn = args.value.includes('on') || args.value.includes('active') || args.value.includes('start');
|
|
localStorage.setItem('rudraksha_focus_mode', turnOn ? 'true' : 'false');
|
|
window.dispatchEvent(new Event('rudraksha-focus-update'));
|
|
return { result: `Focus Mode ${turnOn ? 'Activated' : 'Deactivated'}.` };
|
|
}
|
|
|
|
if (args.setting === 'theme') {
|
|
const isDark = args.value.includes('dark') || args.value.includes('night');
|
|
const profile = await StorageService.getProfile();
|
|
if (profile) {
|
|
const newTheme = isDark ? 'theme_midnight' : 'default';
|
|
await StorageService.updateProfile({ activeTheme: newTheme });
|
|
window.dispatchEvent(new Event('rudraksha-profile-update'));
|
|
return { result: `Switched to ${isDark ? 'Dark' : 'Light'} visual theme.` };
|
|
}
|
|
}
|
|
|
|
if (args.setting === 'language') {
|
|
const isNepali = args.value.toLowerCase().includes('nep');
|
|
localStorage.setItem('rudraksha_lang', isNepali ? 'ne' : 'en');
|
|
window.location.reload();
|
|
return { result: `Switching language to ${isNepali ? 'Nepali' : 'English'}...` };
|
|
}
|
|
}
|
|
|
|
if (name === 'open_external_link') {
|
|
const p = args.platform.toLowerCase();
|
|
const q = args.query ? args.query.trim() : '';
|
|
const encodedQ = encodeURIComponent(q);
|
|
let url = 'https://www.google.com';
|
|
|
|
// Safety Check (Basic SFW Filter)
|
|
const unsafeKeywords = ['porn', 'xxx', 'nsfw', 'sex', 'nude', 'erotic'];
|
|
if (unsafeKeywords.some(keyword => q.toLowerCase().includes(keyword))) {
|
|
return { result: "Access denied. Safety protocol active. Request contains unsafe content." };
|
|
}
|
|
|
|
// Dynamic Platform Handling
|
|
if (p.includes('youtube')) {
|
|
if (args.action === 'play' && q) {
|
|
// "I'm Feeling Lucky" logic to try and jump directly to the video
|
|
// Queries "site:youtube.com [query]" and presses the Lucky button.
|
|
// This often redirects to the first video result directly.
|
|
url = `https://www.google.com/search?q=site%3Ayoutube.com+${encodedQ}&btnI=1`;
|
|
} else if (q) {
|
|
url = `https://www.youtube.com/results?search_query=${encodedQ}`;
|
|
} else {
|
|
url = 'https://www.youtube.com';
|
|
}
|
|
} else if (p.includes('google')) {
|
|
url = q ? `https://www.google.com/search?q=${encodedQ}` : 'https://www.google.com';
|
|
} else if (p.includes('facebook')) {
|
|
url = 'https://www.facebook.com';
|
|
} else if (p.includes('instagram')) {
|
|
url = 'https://www.instagram.com';
|
|
} else if (p.includes('twitter') || p.includes('x.com')) {
|
|
url = 'https://twitter.com';
|
|
} else if (p.includes('linkedin')) {
|
|
url = 'https://www.linkedin.com';
|
|
} else if (p.includes('wikipedia')) {
|
|
url = q ? `https://en.wikipedia.org/wiki/${encodedQ}` : 'https://www.wikipedia.org';
|
|
} else if (p.includes('tiktok')) {
|
|
url = 'https://www.tiktok.com';
|
|
} else if (p.includes('spotify')) {
|
|
url = q ? `https://open.spotify.com/search/${encodedQ}` : 'https://open.spotify.com';
|
|
} else {
|
|
url = `https://www.google.com/search?q=${p}+${q}`;
|
|
}
|
|
|
|
window.open(url, '_blank');
|
|
return { result: `System order executed: Opening ${args.platform} ${args.action === 'play' ? 'content' : 'interface'}.` };
|
|
}
|
|
|
|
if (name === 'adjust_device_hardware') {
|
|
return { result: "Feature coming soon. Hardware bridge not connected." };
|
|
}
|
|
|
|
// Handle special termination/logout actions in the UI layer (RudraAI.tsx) via event or return signal
|
|
if (name === 'terminate_voice_session') {
|
|
return { result: "TERMINATE_SIGNAL" }; // Special signal for UI to close connection
|
|
}
|
|
|
|
if (name === 'system_logout') {
|
|
return { result: "LOGOUT_SIGNAL" }; // Special signal for UI to perform logout
|
|
}
|
|
|
|
return null;
|
|
};
|