UNPKG

@agentek/tools

Version:

Blockchain tools for AI agents

38 lines 1.6 kB
import { z } from "zod"; import { createTool } from "../client.js"; import { assertOkResponse } from "../utils/fetch.js"; const getLatestCoindeskNewsToolParams = z.object({ limit: z.number().min(1).max(100).default(10).describe("Number of articles to fetch (1-100). Default: 10"), }); export const createCoindeskNewsTool = (apiKey) => { return createTool({ name: "getLatestCoindeskNewsTool", description: "Get the latest cryptocurrency and blockchain news articles from CoinDesk.", 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); await assertOkResponse(response, "Coindesk API error"); const json = await response.json(); return { articles: json.articles || [] }; } catch (err) { throw new Error(`Failed to fetch latest Coindesk news articles: ${err}`); } }, }); }; //# sourceMappingURL=tools.js.map