UNPKG

@agentek/tools

Version:

Blockchain tools for AI agents

43 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCoindeskNewsTool = void 0; const zod_1 = require("zod"); const client_js_1 = require("../client.js"); const getLatestCoindeskNewsToolParams = zod_1.z.object({ limit: zod_1.z.number().min(1).max(100).default(10), }); const createCoindeskNewsTool = (apiKey) => { return (0, client_js_1.createTool)({ name: "getLatestCoindeskNewsTool", description: "Calls the Coindesk API to retrieve the latest news articles. Parameter 'limit' allows specification of how many articles to fetch (defaults to 10).", parameters: getLatestCoindeskNewsToolParams, execute: async (_client, args) => { const { limit } = args; const baseUrl = "https://data-api.coindesk.com/news/v1/article/list"; const params = { lang: "EN", limit: limit.toString(), api_key: apiKey, }; const url = new URL(baseUrl); url.search = new URLSearchParams(params).toString(); const options = { method: "GET", headers: { "Content-type": "application/json; charset=UTF-8" }, }; try { const response = await fetch(url.toString(), options); if (!response.ok) { throw new Error(`Coindesk API error: ${response.status} ${response.statusText}`); } const json = await response.json(); return { articles: json.articles || [] }; } catch (err) { throw new Error(`Failed to fetch latest Coindesk news articles: ${err}`); } }, }); }; exports.createCoindeskNewsTool = createCoindeskNewsTool; //# sourceMappingURL=tools.js.map