81 lines
2.9 KiB
TypeScript
81 lines
2.9 KiB
TypeScript
import type { VoiceTool } from './_types'
|
|
import { tabletGet, tabletJson } from './_http'
|
|
|
|
const getSmartHomeState: VoiceTool = {
|
|
schema: {
|
|
type: 'function',
|
|
function: {
|
|
name: 'get_smart_home_state',
|
|
description:
|
|
'Получить текущее состояние умного дома: температура и влажность в квартире, ' +
|
|
'уровень PM2.5 (качество воздуха), состояние очистителя воздуха. ' +
|
|
'Используй для вопросов вроде «какая температура дома», «как качество воздуха», ' +
|
|
'«работает ли очиститель».',
|
|
parameters: {
|
|
type: 'object',
|
|
properties: {},
|
|
},
|
|
},
|
|
},
|
|
|
|
async execute(_args) {
|
|
return tabletGet('/api/voice/tools/smart-home')
|
|
},
|
|
}
|
|
|
|
const controlAirPurifier: VoiceTool = {
|
|
schema: {
|
|
type: 'function',
|
|
function: {
|
|
name: 'control_air_purifier',
|
|
description:
|
|
'Управление очистителем воздуха: включить, выключить или установить режим работы. ' +
|
|
'Режимы: Auto (автоматический), Night (ночной/тихий), High (максимальный). ' +
|
|
'Используй для команд вроде «включи очиститель», «поставь ночной режим», «выключи очиститель».',
|
|
parameters: {
|
|
type: 'object',
|
|
properties: {
|
|
action: {
|
|
type: 'string',
|
|
enum: ['turn_on', 'turn_off', 'set_mode'],
|
|
description: 'Действие: включить, выключить или установить режим',
|
|
},
|
|
mode: {
|
|
type: 'string',
|
|
description: 'Режим работы при action=set_mode: Auto, Night или High',
|
|
},
|
|
},
|
|
required: ['action'],
|
|
},
|
|
},
|
|
},
|
|
|
|
async execute(args) {
|
|
const action = String(args?.action || '')
|
|
const mode = args?.mode as string | undefined
|
|
|
|
let payload: Record<string, any>
|
|
|
|
if (action === 'turn_on') {
|
|
payload = { domain: 'fan', service: 'turn_on', entity_id: 'fan.air_purifier' }
|
|
} else if (action === 'turn_off') {
|
|
payload = { domain: 'fan', service: 'turn_off', entity_id: 'fan.air_purifier' }
|
|
} else if (action === 'set_mode') {
|
|
if (!mode) return { error: 'mode required for set_mode action' }
|
|
payload = {
|
|
domain: 'fan',
|
|
service: 'set_preset_mode',
|
|
entity_id: 'fan.air_purifier',
|
|
preset_mode: mode,
|
|
}
|
|
} else {
|
|
return { error: `unknown action: ${action}` }
|
|
}
|
|
|
|
await tabletJson('POST', '/api/voice/tools/smart-home', payload)
|
|
return { success: true, action, ...(mode ? { mode } : {}) }
|
|
},
|
|
}
|
|
|
|
export const tools: VoiceTool[] = [getSmartHomeState, controlAirPurifier]
|