Files
smart-home-tablet/lib/tools/_registry.ts
d.klimov be0a731738
All checks were successful
Deploy / deploy (push) Successful in 1m52s
voice: усиление умного дома — контекст, промпт, новые tools
- промпт: перечислены ВСЕ 15+ tools, разрешено уверенно управлять домом
- route.ts: живой контекст (время + снимок устройств из HA) в системный промпт
  для LLM-пути (defensive, с таймаутом)
- новые tools: control_climate (кондей/термостат), control_tv, set_scene
  (night/movie/morning/away), all_off, ha_service (универсальный HA с whitelist)
- env: CLIMATE_ENTITY, TV_ENTITY (см. RUNBOOK)
2026-07-22 23:49:50 +03:00

59 lines
1.7 KiB
TypeScript

/**
* Tool plugin registry.
* Aggregates all VoiceTool instances, exposes TOOL_SCHEMAS array
* and executeTool dispatcher.
*/
import type { AgentId, VoiceTool } from './_types'
import { ToolHttpError } from './_http'
import { tool as weather } from './weather'
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'
import { tools as spotifyTools } from './spotify'
import { tools as lightTools } from './lights'
import { tools as climateTools } from './climate'
import { tools as tvTools } from './tv'
import { tools as sceneTools } from './scenes'
import { tools as haGenericTools } from './ha-generic'
const ALL_TOOLS: VoiceTool[] = [
weather,
transport,
...calendarTools,
...timerTools,
notes,
...smartHomeTools,
...spotifyTools,
...lightTools,
...climateTools,
...tvTools,
...sceneTools,
...haGenericTools,
]
export const TOOL_SCHEMAS = ALL_TOOLS.map((t) => t.schema)
export async function executeTool(
name: string,
args: Record<string, any>,
agent: AgentId,
): Promise<Record<string, any> | { error: string }> {
const t = ALL_TOOLS.find((t) => t.schema.function.name === name)
if (!t) return { error: `unknown tool: ${name}` }
try {
return await t.execute(args || {}, agent)
} catch (e) {
if (e instanceof ToolHttpError) {
return { error: `tool_http_${e.status}` }
}
if (e instanceof TypeError && /fetch/i.test(e.message)) {
return { error: 'tool_network_error' }
}
return { error: `tool_exception: ${(e as Error).message}` }
}
}