@coinbase/agentkit 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -7
- package/dist/action-providers/across/acrossActionProvider.d.ts +50 -0
- package/dist/action-providers/across/acrossActionProvider.js +333 -0
- package/dist/action-providers/across/acrossActionProvider.test.d.ts +1 -0
- package/dist/action-providers/across/acrossActionProvider.test.js +391 -0
- package/dist/action-providers/across/constants.d.ts +1 -0
- package/dist/action-providers/across/constants.js +2 -0
- package/dist/action-providers/across/index.d.ts +1 -0
- package/dist/action-providers/across/index.js +17 -0
- package/dist/action-providers/across/schemas.d.ts +36 -0
- package/dist/action-providers/across/schemas.js +46 -0
- package/dist/action-providers/across/utils.d.ts +7 -0
- package/dist/action-providers/across/utils.js +25 -0
- package/dist/action-providers/erc20/constants.d.ts +2 -0
- package/dist/action-providers/erc20/constants.js +12 -1
- package/dist/action-providers/erc20/erc20ActionProvider.js +18 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +4 -0
- package/dist/action-providers/flaunch/constants.d.ts +1078 -0
- package/dist/action-providers/flaunch/constants.js +709 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +102 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.js +519 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.test.d.ts +1 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +307 -0
- package/dist/action-providers/flaunch/index.d.ts +7 -0
- package/dist/action-providers/flaunch/index.js +23 -0
- package/dist/action-providers/flaunch/schemas.d.ts +77 -0
- package/dist/action-providers/flaunch/schemas.js +71 -0
- package/dist/action-providers/flaunch/types.d.ts +64 -0
- package/dist/action-providers/flaunch/types.js +2 -0
- package/dist/action-providers/flaunch/utils.d.ts +60 -0
- package/dist/action-providers/flaunch/utils.js +507 -0
- package/dist/action-providers/index.d.ts +4 -0
- package/dist/action-providers/index.js +4 -0
- package/dist/action-providers/messari/constants.d.ts +17 -0
- package/dist/action-providers/messari/constants.js +20 -0
- package/dist/action-providers/messari/index.d.ts +5 -0
- package/dist/action-providers/messari/index.js +21 -0
- package/dist/action-providers/messari/messariActionProvider.d.ts +42 -0
- package/dist/action-providers/messari/messariActionProvider.js +128 -0
- package/dist/action-providers/messari/messariActionProvider.test.d.ts +1 -0
- package/dist/action-providers/messari/messariActionProvider.test.js +152 -0
- package/dist/action-providers/messari/schemas.d.ts +11 -0
- package/dist/action-providers/messari/schemas.js +16 -0
- package/dist/action-providers/messari/types.d.ts +40 -0
- package/dist/action-providers/messari/types.js +2 -0
- package/dist/action-providers/messari/utils.d.ts +22 -0
- package/dist/action-providers/messari/utils.js +65 -0
- package/dist/action-providers/onramp/index.d.ts +7 -0
- package/dist/action-providers/onramp/index.js +23 -0
- package/dist/action-providers/onramp/onrampActionProvider.d.ts +56 -0
- package/dist/action-providers/onramp/onrampActionProvider.js +109 -0
- package/dist/action-providers/onramp/onrampActionProvider.test.d.ts +1 -0
- package/dist/action-providers/onramp/onrampActionProvider.test.js +97 -0
- package/dist/action-providers/onramp/schemas.d.ts +12 -0
- package/dist/action-providers/onramp/schemas.js +15 -0
- package/dist/action-providers/onramp/types.d.ts +107 -0
- package/dist/action-providers/onramp/types.js +2 -0
- package/dist/action-providers/onramp/utils.d.ts +16 -0
- package/dist/action-providers/onramp/utils.js +56 -0
- package/dist/action-providers/onramp/version.d.ts +2 -0
- package/dist/action-providers/onramp/version.js +5 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +11 -2
- package/dist/wallet-providers/cdpWalletProvider.js +44 -10
- package/dist/wallet-providers/cdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpWalletProvider.test.js +735 -0
- package/dist/wallet-providers/evmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/evmWalletProvider.test.js +56 -0
- package/dist/wallet-providers/index.d.ts +1 -0
- package/dist/wallet-providers/index.js +1 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +167 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +438 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +280 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +331 -0
- package/dist/wallet-providers/privyShared.d.ts +9 -0
- package/dist/wallet-providers/privyShared.js +16 -5
- package/dist/wallet-providers/privySvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.js +310 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +21 -8
- package/dist/wallet-providers/privyWalletProvider.js +39 -7
- package/dist/wallet-providers/privyWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyWalletProvider.test.js +124 -0
- package/dist/wallet-providers/smartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/smartWalletProvider.test.js +388 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +210 -16
- package/dist/wallet-providers/svmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/svmWalletProvider.test.js +55 -0
- package/dist/wallet-providers/viemWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/viemWalletProvider.test.js +338 -0
- package/dist/wallet-providers/walletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/walletProvider.test.js +103 -0
- package/package.json +26 -21
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.messariActionProvider = exports.MessariActionProvider = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const actionProvider_1 = require("../actionProvider");
|
|
15
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
16
|
+
const schemas_1 = require("./schemas");
|
|
17
|
+
const constants_1 = require("./constants");
|
|
18
|
+
const utils_1 = require("./utils");
|
|
19
|
+
/**
|
|
20
|
+
* MessariActionProvider is an action provider for Messari AI toolkit interactions.
|
|
21
|
+
* It enables AI agents to ask research questions about crypto markets, protocols, and tokens.
|
|
22
|
+
*
|
|
23
|
+
* @augments ActionProvider
|
|
24
|
+
*/
|
|
25
|
+
class MessariActionProvider extends actionProvider_1.ActionProvider {
|
|
26
|
+
/**
|
|
27
|
+
* Constructor for the MessariActionProvider class.
|
|
28
|
+
*
|
|
29
|
+
* @param config - The configuration options for the MessariActionProvider
|
|
30
|
+
*/
|
|
31
|
+
constructor(config = {}) {
|
|
32
|
+
super("messari", []);
|
|
33
|
+
config.apiKey || (config.apiKey = process.env.MESSARI_API_KEY);
|
|
34
|
+
if (!config.apiKey) {
|
|
35
|
+
throw new Error(constants_1.API_KEY_MISSING_ERROR);
|
|
36
|
+
}
|
|
37
|
+
this.apiKey = config.apiKey;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Makes a request to the Messari AI API with a research question
|
|
41
|
+
*
|
|
42
|
+
* @param args - The arguments containing the research question
|
|
43
|
+
* @returns A string containing the research results or an error message
|
|
44
|
+
*/
|
|
45
|
+
async researchQuestion(args) {
|
|
46
|
+
try {
|
|
47
|
+
// Make API request
|
|
48
|
+
const response = await fetch(`${constants_1.MESSARI_BASE_URL}/chat/completions`, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: {
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
"x-messari-api-key": this.apiKey,
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
messages: [
|
|
56
|
+
{
|
|
57
|
+
role: "user",
|
|
58
|
+
content: args.question,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
throw await (0, utils_1.createMessariError)(response);
|
|
65
|
+
}
|
|
66
|
+
// Parse and validate response
|
|
67
|
+
let data;
|
|
68
|
+
try {
|
|
69
|
+
data = (await response.json());
|
|
70
|
+
}
|
|
71
|
+
catch (jsonError) {
|
|
72
|
+
throw new Error(`Failed to parse API response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`);
|
|
73
|
+
}
|
|
74
|
+
if (!data.data?.messages?.[0]?.content) {
|
|
75
|
+
throw new Error("Received invalid response format from Messari API");
|
|
76
|
+
}
|
|
77
|
+
const result = data.data.messages[0].content;
|
|
78
|
+
return `Messari Research Results:\n\n${result}`;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error instanceof Error && "responseText" in error) {
|
|
82
|
+
return (0, utils_1.formatMessariApiError)(error);
|
|
83
|
+
}
|
|
84
|
+
return (0, utils_1.formatGenericError)(error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Checks if the action provider supports the given network.
|
|
89
|
+
* Messari research is network-agnostic, so it supports all networks.
|
|
90
|
+
*
|
|
91
|
+
* @param _ - The network to check
|
|
92
|
+
* @returns Always returns true as Messari research is network-agnostic
|
|
93
|
+
*/
|
|
94
|
+
supportsNetwork(_) {
|
|
95
|
+
return true; // Messari research is network-agnostic
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.MessariActionProvider = MessariActionProvider;
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, actionDecorator_1.CreateAction)({
|
|
101
|
+
name: "research_question",
|
|
102
|
+
description: `
|
|
103
|
+
This tool queries Messari AI for comprehensive crypto research across these datasets:
|
|
104
|
+
1. News/Content - Latest crypto news, blogs, podcasts
|
|
105
|
+
2. Exchanges - CEX/DEX volumes, market share, assets listed
|
|
106
|
+
3. Onchain Data - Active addresses, transaction fees, total transactions.
|
|
107
|
+
4. Token Unlocks - Upcoming supply unlocks, vesting schedules, and token emission details
|
|
108
|
+
5. Market Data - Asset prices, trading volume, market cap, TVL, and historical performance
|
|
109
|
+
6. Fundraising - Investment data, funding rounds, venture capital activity.
|
|
110
|
+
7. Protocol Research - Technical analysis of how protocols work, tokenomics, and yield mechanisms
|
|
111
|
+
8. Social Data - Twitter followers and Reddit subscribers metrics, growth trends
|
|
112
|
+
|
|
113
|
+
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?"
|
|
114
|
+
`,
|
|
115
|
+
schema: schemas_1.MessariResearchQuestionSchema,
|
|
116
|
+
}),
|
|
117
|
+
__metadata("design:type", Function),
|
|
118
|
+
__metadata("design:paramtypes", [void 0]),
|
|
119
|
+
__metadata("design:returntype", Promise)
|
|
120
|
+
], MessariActionProvider.prototype, "researchQuestion", null);
|
|
121
|
+
/**
|
|
122
|
+
* Factory function to create a new MessariActionProvider instance.
|
|
123
|
+
*
|
|
124
|
+
* @param config - The configuration options for the MessariActionProvider
|
|
125
|
+
* @returns A new instance of MessariActionProvider
|
|
126
|
+
*/
|
|
127
|
+
const messariActionProvider = (config = {}) => new MessariActionProvider(config);
|
|
128
|
+
exports.messariActionProvider = messariActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const messariActionProvider_1 = require("./messariActionProvider");
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const MOCK_API_KEY = "messari-test-key";
|
|
6
|
+
const MOCK_RESEARCH_RESPONSE = {
|
|
7
|
+
data: {
|
|
8
|
+
messages: [
|
|
9
|
+
{
|
|
10
|
+
role: "assistant",
|
|
11
|
+
content: "Ethereum (ETH) has shown strong performance over the past month with a 15% price increase. The current price is approximately $3,500, up from $3,000 at the beginning of the month. Trading volume has also increased by 20% in the same period.",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const MOCK_ERROR_RESPONSE = {
|
|
17
|
+
error: "Internal server error, please try again. If the problem persists, please contact support",
|
|
18
|
+
data: null,
|
|
19
|
+
};
|
|
20
|
+
describe("MessariActionProvider", () => {
|
|
21
|
+
let provider;
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
process.env.MESSARI_API_KEY = MOCK_API_KEY;
|
|
24
|
+
provider = (0, messariActionProvider_1.messariActionProvider)({ apiKey: MOCK_API_KEY });
|
|
25
|
+
jest.restoreAllMocks();
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
jest.clearAllMocks();
|
|
29
|
+
delete process.env.MESSARI_API_KEY;
|
|
30
|
+
});
|
|
31
|
+
describe("constructor", () => {
|
|
32
|
+
it("should initialize with API key from constructor", () => {
|
|
33
|
+
const customProvider = (0, messariActionProvider_1.messariActionProvider)({ apiKey: "custom-key" });
|
|
34
|
+
expect(customProvider["apiKey"]).toBe("custom-key");
|
|
35
|
+
});
|
|
36
|
+
it("should initialize with API key from environment variable", () => {
|
|
37
|
+
process.env.MESSARI_API_KEY = "env-key";
|
|
38
|
+
const envProvider = (0, messariActionProvider_1.messariActionProvider)();
|
|
39
|
+
expect(envProvider["apiKey"]).toBe("env-key");
|
|
40
|
+
});
|
|
41
|
+
it("should throw error if API key is not provided", () => {
|
|
42
|
+
delete process.env.MESSARI_API_KEY;
|
|
43
|
+
expect(() => (0, messariActionProvider_1.messariActionProvider)()).toThrow(constants_1.API_KEY_MISSING_ERROR);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe("researchQuestion", () => {
|
|
47
|
+
it("should successfully fetch research results", async () => {
|
|
48
|
+
const fetchMock = jest.spyOn(global, "fetch").mockResolvedValue({
|
|
49
|
+
ok: true,
|
|
50
|
+
json: async () => MOCK_RESEARCH_RESPONSE,
|
|
51
|
+
});
|
|
52
|
+
const question = "What is the current price of Ethereum?";
|
|
53
|
+
const response = await provider.researchQuestion({ question });
|
|
54
|
+
expect(fetchMock).toHaveBeenCalled();
|
|
55
|
+
const [url, options] = fetchMock.mock.calls[0];
|
|
56
|
+
expect(url).toBe("https://api.messari.io/ai/v1/chat/completions");
|
|
57
|
+
expect(options).toEqual(expect.objectContaining({
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: expect.objectContaining({
|
|
60
|
+
"Content-Type": "application/json",
|
|
61
|
+
"x-messari-api-key": MOCK_API_KEY,
|
|
62
|
+
}),
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
messages: [
|
|
65
|
+
{
|
|
66
|
+
role: "user",
|
|
67
|
+
content: question,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
}),
|
|
71
|
+
}));
|
|
72
|
+
expect(response).toContain("Messari Research Results:");
|
|
73
|
+
expect(response).toContain(MOCK_RESEARCH_RESPONSE.data.messages[0].content);
|
|
74
|
+
});
|
|
75
|
+
it("should handle non-ok response with structured error format", async () => {
|
|
76
|
+
const errorResponseText = JSON.stringify(MOCK_ERROR_RESPONSE);
|
|
77
|
+
jest.spyOn(global, "fetch").mockResolvedValue({
|
|
78
|
+
ok: false,
|
|
79
|
+
status: 500,
|
|
80
|
+
statusText: "Internal Server Error",
|
|
81
|
+
text: async () => errorResponseText,
|
|
82
|
+
});
|
|
83
|
+
const response = await provider.researchQuestion({
|
|
84
|
+
question: "What is the current price of Bitcoin?",
|
|
85
|
+
});
|
|
86
|
+
expect(response).toContain("Messari API Error: Internal server error");
|
|
87
|
+
expect(response).not.toContain("500");
|
|
88
|
+
});
|
|
89
|
+
it("should handle non-ok response with non-JSON error format", async () => {
|
|
90
|
+
const plainTextError = "Rate limit exceeded";
|
|
91
|
+
jest.spyOn(global, "fetch").mockResolvedValue({
|
|
92
|
+
ok: false,
|
|
93
|
+
status: 429,
|
|
94
|
+
statusText: "Too Many Requests",
|
|
95
|
+
text: async () => plainTextError,
|
|
96
|
+
});
|
|
97
|
+
const response = await provider.researchQuestion({
|
|
98
|
+
question: "What is the current price of Bitcoin?",
|
|
99
|
+
});
|
|
100
|
+
expect(response).toContain("Messari API Error:");
|
|
101
|
+
expect(response).toContain("429");
|
|
102
|
+
expect(response).toContain("Too Many Requests");
|
|
103
|
+
expect(response).toContain(plainTextError);
|
|
104
|
+
});
|
|
105
|
+
it("should handle JSON parsing error in successful response", async () => {
|
|
106
|
+
jest.spyOn(global, "fetch").mockResolvedValue({
|
|
107
|
+
ok: true,
|
|
108
|
+
json: async () => {
|
|
109
|
+
throw new Error("Invalid JSON");
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
const response = await provider.researchQuestion({
|
|
113
|
+
question: "What is the market cap of Solana?",
|
|
114
|
+
});
|
|
115
|
+
expect(response).toContain("Unexpected error: Failed to parse API response");
|
|
116
|
+
expect(response).toContain("Invalid JSON");
|
|
117
|
+
});
|
|
118
|
+
it("should handle invalid response format", async () => {
|
|
119
|
+
jest.spyOn(global, "fetch").mockResolvedValue({
|
|
120
|
+
ok: true,
|
|
121
|
+
json: async () => ({ data: { messages: [] } }),
|
|
122
|
+
});
|
|
123
|
+
const response = await provider.researchQuestion({
|
|
124
|
+
question: "What is the market cap of Solana?",
|
|
125
|
+
});
|
|
126
|
+
expect(response).toContain("Unexpected error: Received invalid response format from Messari API");
|
|
127
|
+
});
|
|
128
|
+
it("should handle fetch error", async () => {
|
|
129
|
+
const error = new Error("Network error");
|
|
130
|
+
jest.spyOn(global, "fetch").mockRejectedValue(error);
|
|
131
|
+
const response = await provider.researchQuestion({
|
|
132
|
+
question: "What is the market cap of Solana?",
|
|
133
|
+
});
|
|
134
|
+
expect(response).toContain("Unexpected error: Network error");
|
|
135
|
+
});
|
|
136
|
+
it("should handle string error with JSON content", async () => {
|
|
137
|
+
const stringifiedError = JSON.stringify(MOCK_ERROR_RESPONSE);
|
|
138
|
+
jest.spyOn(global, "fetch").mockRejectedValue(stringifiedError);
|
|
139
|
+
const response = await provider.researchQuestion({
|
|
140
|
+
question: "What is the market cap of Solana?",
|
|
141
|
+
});
|
|
142
|
+
expect(response).toContain("Messari API Error: Internal server error");
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe("supportsNetwork", () => {
|
|
146
|
+
it("should always return true as research is network-agnostic", () => {
|
|
147
|
+
expect(provider.supportsNetwork({ protocolFamily: "evm" })).toBe(true);
|
|
148
|
+
expect(provider.supportsNetwork({ protocolFamily: "solana" })).toBe(true);
|
|
149
|
+
expect(provider.supportsNetwork({ protocolFamily: "unknown" })).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for submitting a research question to Messari AI.
|
|
4
|
+
*/
|
|
5
|
+
export declare const MessariResearchQuestionSchema: z.ZodObject<{
|
|
6
|
+
question: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
question: string;
|
|
9
|
+
}, {
|
|
10
|
+
question: string;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessariResearchQuestionSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Input schema for submitting a research question to Messari AI.
|
|
7
|
+
*/
|
|
8
|
+
exports.MessariResearchQuestionSchema = zod_1.z
|
|
9
|
+
.object({
|
|
10
|
+
question: zod_1.z
|
|
11
|
+
.string()
|
|
12
|
+
.min(1, "Research question is required.")
|
|
13
|
+
.describe("The research question about crypto markets, protocols, or tokens"),
|
|
14
|
+
})
|
|
15
|
+
.strip()
|
|
16
|
+
.describe("Input schema for submitting a research question to Messari AI");
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the MessariActionProvider.
|
|
3
|
+
*/
|
|
4
|
+
export interface MessariActionProviderConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Messari API Key
|
|
7
|
+
*/
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Message format in Messari API responses
|
|
12
|
+
*/
|
|
13
|
+
export interface MessariMessage {
|
|
14
|
+
content: string;
|
|
15
|
+
role: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Response format from Messari API
|
|
19
|
+
*/
|
|
20
|
+
export interface MessariAPIResponse {
|
|
21
|
+
data: {
|
|
22
|
+
messages: MessariMessage[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error response format from Messari API
|
|
27
|
+
*/
|
|
28
|
+
export interface MessariErrorResponse {
|
|
29
|
+
error?: string;
|
|
30
|
+
data?: null | unknown;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Extended Error interface for Messari API errors
|
|
34
|
+
*/
|
|
35
|
+
export interface MessariError extends Error {
|
|
36
|
+
status?: number;
|
|
37
|
+
statusText?: string;
|
|
38
|
+
responseText?: string;
|
|
39
|
+
errorResponse?: MessariErrorResponse;
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MessariError } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a MessariError from an HTTP response
|
|
4
|
+
*
|
|
5
|
+
* @param response - The fetch Response object
|
|
6
|
+
* @returns A MessariError with response details
|
|
7
|
+
*/
|
|
8
|
+
export declare function createMessariError(response: Response): Promise<MessariError>;
|
|
9
|
+
/**
|
|
10
|
+
* Formats error details for API errors
|
|
11
|
+
*
|
|
12
|
+
* @param error - The MessariError to format
|
|
13
|
+
* @returns Formatted error message
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatMessariApiError(error: MessariError): string;
|
|
16
|
+
/**
|
|
17
|
+
* Formats generic errors
|
|
18
|
+
*
|
|
19
|
+
* @param error - The error to format
|
|
20
|
+
* @returns Formatted error message
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatGenericError(error: unknown): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMessariError = createMessariError;
|
|
4
|
+
exports.formatMessariApiError = formatMessariApiError;
|
|
5
|
+
exports.formatGenericError = formatGenericError;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a MessariError from an HTTP response
|
|
8
|
+
*
|
|
9
|
+
* @param response - The fetch Response object
|
|
10
|
+
* @returns A MessariError with response details
|
|
11
|
+
*/
|
|
12
|
+
async function createMessariError(response) {
|
|
13
|
+
const error = new Error(`Messari API returned ${response.status} ${response.statusText}`);
|
|
14
|
+
error.status = response.status;
|
|
15
|
+
error.statusText = response.statusText;
|
|
16
|
+
const responseText = await response.text();
|
|
17
|
+
error.responseText = responseText;
|
|
18
|
+
try {
|
|
19
|
+
const errorJson = JSON.parse(responseText);
|
|
20
|
+
error.errorResponse = errorJson;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// If parsing fails, just use the raw text
|
|
24
|
+
}
|
|
25
|
+
return error;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Formats error details for API errors
|
|
29
|
+
*
|
|
30
|
+
* @param error - The MessariError to format
|
|
31
|
+
* @returns Formatted error message
|
|
32
|
+
*/
|
|
33
|
+
function formatMessariApiError(error) {
|
|
34
|
+
if (error.errorResponse?.error) {
|
|
35
|
+
return `Messari API Error: ${error.errorResponse.error}`;
|
|
36
|
+
}
|
|
37
|
+
const errorDetails = {
|
|
38
|
+
status: error.status,
|
|
39
|
+
statusText: error.statusText,
|
|
40
|
+
responseText: error.responseText,
|
|
41
|
+
message: error.message,
|
|
42
|
+
};
|
|
43
|
+
return `Messari API Error: ${JSON.stringify(errorDetails, null, 2)}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Formats generic errors
|
|
47
|
+
*
|
|
48
|
+
* @param error - The error to format
|
|
49
|
+
* @returns Formatted error message
|
|
50
|
+
*/
|
|
51
|
+
function formatGenericError(error) {
|
|
52
|
+
// Check if this might be a JSON string containing an error message
|
|
53
|
+
if (typeof error === "string") {
|
|
54
|
+
try {
|
|
55
|
+
const parsedError = JSON.parse(error);
|
|
56
|
+
if (parsedError.error) {
|
|
57
|
+
return `Messari API Error: ${parsedError.error}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// Not valid JSON, continue with normal handling
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return `Unexpected error: ${error instanceof Error ? error.message : String(error)}`;
|
|
65
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Exports for onramp action provider
|
|
4
|
+
*
|
|
5
|
+
* @module onramp
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
__exportStar(require("./onrampActionProvider"), exports);
|
|
23
|
+
__exportStar(require("./schemas"), exports);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onramp Action Provider
|
|
3
|
+
*
|
|
4
|
+
* This file contains the implementation of the OnrampActionProvider,
|
|
5
|
+
* which provides actions for onramp operations.
|
|
6
|
+
*
|
|
7
|
+
* @module onramp
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { ActionProvider } from "../actionProvider";
|
|
11
|
+
import { Network } from "../../network";
|
|
12
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
13
|
+
import { GetOnrampBuyUrlActionSchema } from "./schemas";
|
|
14
|
+
type OnrampActionProviderProps = {
|
|
15
|
+
projectId: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* OnrampActionProvider provides actions for onramp operations.
|
|
19
|
+
*
|
|
20
|
+
* @description
|
|
21
|
+
* This provider is designed to work with EvmWalletProvider for blockchain interactions.
|
|
22
|
+
* It supports all evm networks.
|
|
23
|
+
*/
|
|
24
|
+
export declare class OnrampActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
25
|
+
private projectId;
|
|
26
|
+
/**
|
|
27
|
+
* Constructor for the OnrampActionProvider.
|
|
28
|
+
*
|
|
29
|
+
* @param props - The props for the OnrampActionProvider
|
|
30
|
+
* @param props.projectId - The project ID for the OnrampActionProvider
|
|
31
|
+
*/
|
|
32
|
+
constructor(props: OnrampActionProviderProps);
|
|
33
|
+
/**
|
|
34
|
+
* This action provides a link to buy more cryptocurrency (ETH, USDC, or BTC) using fiat currency (regular money like USD).
|
|
35
|
+
*
|
|
36
|
+
* @param walletProvider - The wallet provider instance for blockchain interactions
|
|
37
|
+
* @param _ - The arguments for the action (not used)
|
|
38
|
+
* @returns A promise that resolves to a string describing the action result
|
|
39
|
+
*/
|
|
40
|
+
getOnrampBuyUrl(walletProvider: EvmWalletProvider, _?: z.infer<typeof GetOnrampBuyUrlActionSchema>): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if this provider supports the given network.
|
|
43
|
+
*
|
|
44
|
+
* @param network - The network to check support for
|
|
45
|
+
* @returns True if the network is supported
|
|
46
|
+
*/
|
|
47
|
+
supportsNetwork(network: Network): boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Factory function to create a new OnrampActionProvider instance.
|
|
51
|
+
*
|
|
52
|
+
* @param props - The props for the OnrampActionProvider
|
|
53
|
+
* @returns A new OnrampActionProvider instance
|
|
54
|
+
*/
|
|
55
|
+
export declare const onrampActionProvider: (props: OnrampActionProviderProps) => OnrampActionProvider;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Onramp Action Provider
|
|
4
|
+
*
|
|
5
|
+
* This file contains the implementation of the OnrampActionProvider,
|
|
6
|
+
* which provides actions for onramp operations.
|
|
7
|
+
*
|
|
8
|
+
* @module onramp
|
|
9
|
+
*/
|
|
10
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
11
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
+
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;
|
|
14
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
+
};
|
|
16
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
17
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.onrampActionProvider = exports.OnrampActionProvider = void 0;
|
|
21
|
+
const zod_1 = require("zod");
|
|
22
|
+
const actionProvider_1 = require("../actionProvider");
|
|
23
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
24
|
+
const wallet_providers_1 = require("../../wallet-providers");
|
|
25
|
+
const schemas_1 = require("./schemas");
|
|
26
|
+
const utils_1 = require("./utils");
|
|
27
|
+
/**
|
|
28
|
+
* OnrampActionProvider provides actions for onramp operations.
|
|
29
|
+
*
|
|
30
|
+
* @description
|
|
31
|
+
* This provider is designed to work with EvmWalletProvider for blockchain interactions.
|
|
32
|
+
* It supports all evm networks.
|
|
33
|
+
*/
|
|
34
|
+
class OnrampActionProvider extends actionProvider_1.ActionProvider {
|
|
35
|
+
/**
|
|
36
|
+
* Constructor for the OnrampActionProvider.
|
|
37
|
+
*
|
|
38
|
+
* @param props - The props for the OnrampActionProvider
|
|
39
|
+
* @param props.projectId - The project ID for the OnrampActionProvider
|
|
40
|
+
*/
|
|
41
|
+
constructor(props) {
|
|
42
|
+
super("onramp", []);
|
|
43
|
+
this.projectId = props.projectId;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* This action provides a link to buy more cryptocurrency (ETH, USDC, or BTC) using fiat currency (regular money like USD).
|
|
47
|
+
*
|
|
48
|
+
* @param walletProvider - The wallet provider instance for blockchain interactions
|
|
49
|
+
* @param _ - The arguments for the action (not used)
|
|
50
|
+
* @returns A promise that resolves to a string describing the action result
|
|
51
|
+
*/
|
|
52
|
+
async getOnrampBuyUrl(walletProvider, _ = {}) {
|
|
53
|
+
const networkId = walletProvider.getNetwork().networkId;
|
|
54
|
+
if (!networkId) {
|
|
55
|
+
throw new Error("Network ID is not set");
|
|
56
|
+
}
|
|
57
|
+
const network = (0, utils_1.convertNetworkIdToOnrampNetworkId)(networkId);
|
|
58
|
+
if (!network) {
|
|
59
|
+
throw new Error("Network ID is not supported. Make sure you are using a supported mainnet network.");
|
|
60
|
+
}
|
|
61
|
+
return (0, utils_1.getOnrampBuyUrl)({
|
|
62
|
+
projectId: this.projectId,
|
|
63
|
+
addresses: {
|
|
64
|
+
[walletProvider.getAddress()]: [network],
|
|
65
|
+
},
|
|
66
|
+
defaultNetwork: network,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Checks if this provider supports the given network.
|
|
71
|
+
*
|
|
72
|
+
* @param network - The network to check support for
|
|
73
|
+
* @returns True if the network is supported
|
|
74
|
+
*/
|
|
75
|
+
supportsNetwork(network) {
|
|
76
|
+
return Boolean(network.networkId &&
|
|
77
|
+
(0, utils_1.convertNetworkIdToOnrampNetworkId)(network.networkId) !== null &&
|
|
78
|
+
network.protocolFamily === "evm");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.OnrampActionProvider = OnrampActionProvider;
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, actionDecorator_1.CreateAction)({
|
|
84
|
+
name: "get_onramp_buy_url",
|
|
85
|
+
description: `
|
|
86
|
+
Get a URL to purchase more cryptocurrency when funds are low. This action provides a link to buy more
|
|
87
|
+
cryptocurrency, defaulting to ETH, using fiat currency (regular money like USD).
|
|
88
|
+
|
|
89
|
+
Use this when:
|
|
90
|
+
- You detect that the wallet has insufficient funds for a transaction
|
|
91
|
+
- You need to guide the user to purchase more cryptocurrency
|
|
92
|
+
- The user asks how to buy more crypto
|
|
93
|
+
|
|
94
|
+
The URL will direct to a secure Coinbase-powered purchase interface.
|
|
95
|
+
`,
|
|
96
|
+
schema: schemas_1.GetOnrampBuyUrlActionSchema,
|
|
97
|
+
}),
|
|
98
|
+
__metadata("design:type", Function),
|
|
99
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
100
|
+
__metadata("design:returntype", Promise)
|
|
101
|
+
], OnrampActionProvider.prototype, "getOnrampBuyUrl", null);
|
|
102
|
+
/**
|
|
103
|
+
* Factory function to create a new OnrampActionProvider instance.
|
|
104
|
+
*
|
|
105
|
+
* @param props - The props for the OnrampActionProvider
|
|
106
|
+
* @returns A new OnrampActionProvider instance
|
|
107
|
+
*/
|
|
108
|
+
const onrampActionProvider = (props) => new OnrampActionProvider(props);
|
|
109
|
+
exports.onrampActionProvider = onrampActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|