@agentek/tools
Version:
Blockchain tools for AI agents
42 lines • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCoindeskNewsTool = void 0;
const zod_1 = require("zod");
const client_js_1 = require("../client.js");
const fetch_js_1 = require("../utils/fetch.js");
const getLatestCoindeskNewsToolParams = zod_1.z.object({
limit: zod_1.z.number().min(1).max(100).default(10).describe("Number of articles to fetch (1-100). Default: 10"),
});
const createCoindeskNewsTool = (apiKey) => {
return (0, client_js_1.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 (0, fetch_js_1.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}`);
}
},
});
};
exports.createCoindeskNewsTool = createCoindeskNewsTool;
//# sourceMappingURL=tools.js.map