refactor: tool plugin registry - each tool in separate file
All checks were successful
Deploy / deploy (push) Successful in 1m25s

This commit is contained in:
Cosmo
2026-04-30 20:58:11 +00:00
parent 4ba1aa43d5
commit 7b5f76576f
9 changed files with 465 additions and 2 deletions

111
lib/tools/timers.ts Normal file
View File

@@ -0,0 +1,111 @@
import type { VoiceTool, AgentId } from './_types'
import { tabletJson } from './_http'
const setTimer: VoiceTool = {
schema: {
type: 'function',
function: {
name: 'set_timer',
description:
'Запустить таймер на планшете. Показывает обратный отсчёт с названием и звенит ' +
'по окончании. Используй для «поставь таймер на 10 минут», «напомни через час», ' +
'«засеки 5 минут для чайника».',
parameters: {
type: 'object',
properties: {
seconds: {
type: 'integer',
description: 'Длительность в секундах (1..86400)',
minimum: 1,
maximum: 86400,
},
label: {
type: 'string',
description: 'Короткое название таймера (например «Чайник», «Паста»)',
},
},
required: ['seconds', 'label'],
},
},
},
async execute(args, agent: AgentId) {
const seconds = Number(args?.seconds || 0)
const label = String(args?.label || 'Таймер')
if (!Number.isFinite(seconds) || seconds < 1) return { error: 'seconds must be positive' }
return tabletJson('POST', '/api/voice/timer', {
action: 'start',
seconds,
label,
agent,
})
},
}
const cancelTimer: VoiceTool = {
schema: {
type: 'function',
function: {
name: 'cancel_timer',
description:
'Отменить активный таймер по его названию. Для «отмени таймер чайник», ' +
'«убери таймер пасты», «останови отсчёт».',
parameters: {
type: 'object',
properties: {
label: {
type: 'string',
description: 'Название таймера (примерное совпадение — можно частично).',
},
},
required: ['label'],
},
},
},
async execute(args) {
const label = String(args?.label || '').trim()
if (!label) return { error: 'label required' }
return tabletJson('POST', '/api/voice/timer', { action: 'cancel', label })
},
}
const adjustTimer: VoiceTool = {
schema: {
type: 'function',
function: {
name: 'adjust_timer',
description:
'Изменить оставшееся время таймера. Для «добавь ещё 5 минут», «убавь на минуту», ' +
'«накинь времени чайнику». Положительный delta_seconds = добавить, отрицательный = уменьшить.',
parameters: {
type: 'object',
properties: {
label: {
type: 'string',
description: 'Название таймера для которого меняем время.',
},
delta_seconds: {
type: 'integer',
description: 'Секунды (+ добавить, - уменьшить). Например 300 = +5 минут, -60 = -1 минута.',
},
},
required: ['label', 'delta_seconds'],
},
},
},
async execute(args) {
const label = String(args?.label || '').trim()
const delta = Number(args?.delta_seconds || 0)
if (!label) return { error: 'label required' }
if (!Number.isFinite(delta) || delta === 0) return { error: 'delta_seconds must be non-zero' }
return tabletJson('POST', '/api/voice/timer', {
action: 'adjust',
label,
delta_seconds: delta,
})
},
}
export const tools: VoiceTool[] = [setTimer, cancelTimer, adjustTimer]