feat: smart-home voice tools (get_state + control_air_purifier)
Some checks failed
Deploy / deploy (push) Failing after 1m18s

This commit is contained in:
Cosmo
2026-05-01 06:57:43 +00:00
parent 7b5f76576f
commit 89d8140014
3 changed files with 138 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ import { tool as transport } from './transport'
import { tools as calendarTools } from './calendar'
import { tools as timerTools } from './timers'
import { tool as notes } from './notes'
import { tools as smartHomeTools } from './smart-home'
const ALL_TOOLS: VoiceTool[] = [
weather,
@@ -19,6 +20,7 @@ const ALL_TOOLS: VoiceTool[] = [
...calendarTools,
...timerTools,
notes,
...smartHomeTools,
]
export const TOOL_SCHEMAS = ALL_TOOLS.map((t) => t.schema)

80
lib/tools/smart-home.ts Normal file
View File

@@ -0,0 +1,80 @@
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: }
}
await tabletJson('POST', '/api/voice/tools/smart-home', payload)
return { success: true, action, ...(mode ? { mode } : {}) }
},
}
export const tools: VoiceTool[] = [getSmartHomeState, controlAirPurifier]