UNPKG

@utcp/sdk

Version:

Universal Tool Calling Protocol (UTCP) client library for TypeScript

58 lines 1.77 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = __importDefault(require("express")); const app = (0, express_1.default)(); app.use(express_1.default.json()); const PORT = 8080; const __version__ = '0.1.0'; const BASE_PATH = `http://localhost:${PORT}`; // Manually define the tool const testTool = { name: 'test_endpoint', description: 'A simple test endpoint that echoes a value.', tags: ['test', 'example'], tool_provider: { name: 'test_provider', provider_type: 'http', url: `${BASE_PATH}/test`, http_method: 'POST', }, inputs: { type: 'object', properties: { value: { type: 'string', description: 'A string value to be echoed back.' }, }, required: ['value'], }, outputs: { type: 'object', properties: { received: { type: 'string', description: 'The value that was received by the tool.' }, }, required: ['received'], }, }; // Manually construct the UTCP manual const manual = { version: __version__, tools: [testTool], }; // Endpoint to serve the UTCP manual app.get('/utcp', (req, res) => { res.json(manual); }); // The actual tool endpoint app.post('/test', (req, res) => { const { value } = req.body; if (typeof value !== 'string') { return res.status(400).json({ error: 'Invalid input: value must be a string.' }); } return res.json({ received: value }); }); app.listen(PORT, () => { console.log(`UTCP example server running at :${PORT}`); }); //# sourceMappingURL=server.js.map