UNPKG

@coinbase/agentkit

Version:

Coinbase AgentKit core primitives

129 lines (127 loc) 5.9 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.messariActionProvider = exports.MessariActionProvider = void 0; const zod_1 = require("zod"); const actionProvider_1 = require("../actionProvider"); const actionDecorator_1 = require("../actionDecorator"); const schemas_1 = require("./schemas"); const constants_1 = require("./constants"); const utils_1 = require("./utils"); /** * MessariActionProvider is an action provider for Messari AI toolkit interactions. * It enables AI agents to ask research questions about crypto markets, protocols, and tokens. * * @augments ActionProvider */ class MessariActionProvider extends actionProvider_1.ActionProvider { /** * Constructor for the MessariActionProvider class. * * @param config - The configuration options for the MessariActionProvider */ constructor(config = {}) { super("messari", []); config.apiKey || (config.apiKey = process.env.MESSARI_API_KEY); if (!config.apiKey) { throw new Error(constants_1.API_KEY_MISSING_ERROR); } this.apiKey = config.apiKey; } /** * Makes a request to the Messari AI API with a research question * * @param args - The arguments containing the research question * @returns A string containing the research results or an error message */ async researchQuestion(args) { try { // Make API request const response = await fetch(`${constants_1.MESSARI_BASE_URL}/chat/completions`, { method: "POST", headers: { "Content-Type": "application/json", "x-messari-api-key": this.apiKey, }, body: JSON.stringify({ messages: [ { role: "user", content: args.question, }, ], }), }); if (!response.ok) { throw await (0, utils_1.createMessariError)(response); } // Parse and validate response let data; try { data = (await response.json()); } catch (jsonError) { throw new Error(`Failed to parse API response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`); } if (!data.data?.messages?.[0]?.content) { throw new Error("Received invalid response format from Messari API"); } const result = data.data.messages[0].content; return `Messari Research Results:\n\n${result}`; } catch (error) { if (error instanceof Error && "responseText" in error) { return (0, utils_1.formatMessariApiError)(error); } return (0, utils_1.formatGenericError)(error); } } /** * Checks if the action provider supports the given network. * Messari research is network-agnostic, so it supports all networks. * * @param _ - The network to check * @returns Always returns true as Messari research is network-agnostic */ supportsNetwork(_) { return true; // Messari research is network-agnostic } } exports.MessariActionProvider = MessariActionProvider; __decorate([ (0, actionDecorator_1.CreateAction)({ name: "research_question", description: ` This tool queries Messari AI for comprehensive crypto research across these datasets: 1. News/Content - Latest crypto news, blogs, podcasts 2. Exchanges - CEX/DEX volumes, market share, assets listed 3. Onchain Data - Active addresses, transaction fees, total transactions. 4. Token Unlocks - Upcoming supply unlocks, vesting schedules, and token emission details 5. Market Data - Asset prices, trading volume, market cap, TVL, and historical performance 6. Fundraising - Investment data, funding rounds, venture capital activity. 7. Protocol Research - Technical analysis of how protocols work, tokenomics, and yield mechanisms 8. Social Data - Twitter followers and Reddit subscribers metrics, growth trends Examples: "Which DEXs have the highest trading volume this month?", "When is Arbitrum's next major token unlock?", "How does Morpho generate yield for users?", "Which cryptocurrency has gained the most Twitter followers in 2023?", "What did Vitalik Buterin say about rollups in his recent blog posts?" `, schema: schemas_1.MessariResearchQuestionSchema, }), __metadata("design:type", Function), __metadata("design:paramtypes", [void 0]), __metadata("design:returntype", Promise) ], MessariActionProvider.prototype, "researchQuestion", null); /** * Factory function to create a new MessariActionProvider instance. * * @param config - The configuration options for the MessariActionProvider * @returns A new instance of MessariActionProvider */ const messariActionProvider = (config = {}) => new MessariActionProvider(config); exports.messariActionProvider = messariActionProvider;