plazbot
Version:
Official Plazbot SDK for creating AI agents for WhatsApp, portals, and developers.
44 lines (43 loc) • 1.5 kB
JavaScript
;
// ============================================================================
// Plazbot Workers - defineTool()
// Crea una herramienta que los agentes IA pueden ejecutar durante una conversacion
// ============================================================================
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineTool = defineTool;
/**
* Define una herramienta (tool) para agentes IA de Plazbot.
*
* El agente decide cuando ejecutarla basandose en la `reference`.
* Los `parameters` son extraidos automaticamente de la conversacion.
*
* @example
* ```typescript
* import { defineTool } from 'plazbot/workers';
*
* export default defineTool({
* name: 'consultar-stock',
* reference: 'Consulta el inventario de un producto',
* parameters: {
* producto: { type: 'string', description: 'Nombre del producto' },
* },
* async handler(input, plz) {
* const res = await plz.fetch(`https://api.ejemplo.com/stock/${input.producto}`);
* const data = await res.json();
* return { result: `Stock: ${data.cantidad} unidades` };
* },
* });
* ```
*/
function defineTool(config) {
if (!config.name)
throw new Error('defineTool: "name" es requerido');
if (!config.reference)
throw new Error('defineTool: "reference" es requerido');
if (!config.handler)
throw new Error('defineTool: "handler" es requerido');
return {
__type: 'tool',
config,
};
}