@agentek/tools
Version:
Blockchain tools for AI agents
39 lines • 1.64 kB
JavaScript
import { z } from "zod";
import { createTool } from "../client.js";
const getLatestCoindeskNewsToolParams = z.object({
limit: z.number().min(1).max(100).default(10),
});
export const createCoindeskNewsTool = (apiKey) => {
return 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}`);
}
},
});
};
//# sourceMappingURL=tools.js.map