Files
smart-home-tablet/lib/tools/_registry.ts
d.klimov e6dab09c38
All checks were successful
Deploy / deploy (push) Successful in 3m43s
voice: локальный агент (fast-path), tool control_light, смелая тема, RUNBOOK
- lib/agent-local.ts + route.ts: команды-действия исполняет локальная intent-служба
  (под AGENT_URL, с fallback на LLM); инфо-запросы остаются у LLM
- lib/tools/lights.ts: голосовое управление светом через HA (control_light)
- app/globals.css + page.tsx: космическая indigo/aurora тема (токены, kiosk-safe)
- agent/: sidecar-служба (Dockerfile, predict.py), веса монтируются томом
- RUNBOOK.md: вывод в продакшен на мини-ПК
2026-07-22 21:48:24 +03:00

51 lines
1.4 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'
const ALL_TOOLS: VoiceTool[] = [
weather,
transport,
...calendarTools,
...timerTools,
notes,
...smartHomeTools,
...spotifyTools,
...lightTools,
]
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}` }
}
}