@agentmbox/plugin-agentmbox 1.1.2 → 1.2.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/dist/index.d.ts +31 -47
- package/dist/index.js +335 -442
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -155,15 +155,36 @@ type AgentMBoxErrorCode = 400 | 401 | 402 | 403 | 404 | 409 | 502;
|
|
|
155
155
|
declare function isAgentMBoxError(response: unknown): response is AgentMBoxError;
|
|
156
156
|
|
|
157
157
|
declare class AgentMBoxService extends Service {
|
|
158
|
+
protected runtime: IAgentRuntime;
|
|
158
159
|
private apiKey;
|
|
159
160
|
private mailbox;
|
|
160
161
|
private baseUrl;
|
|
162
|
+
private pollingInterval;
|
|
163
|
+
private pollingTimer;
|
|
164
|
+
private lastEmailCheck;
|
|
161
165
|
static serviceName: "agentmbox";
|
|
162
166
|
static serviceType: "EMAIL";
|
|
163
|
-
constructor(runtime
|
|
167
|
+
constructor(runtime: IAgentRuntime);
|
|
168
|
+
static start(runtime: IAgentRuntime): Promise<AgentMBoxService>;
|
|
164
169
|
get serviceName(): string;
|
|
165
170
|
get capabilityDescription(): string;
|
|
166
171
|
initialize(runtime: IAgentRuntime): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Start polling for new emails
|
|
174
|
+
*/
|
|
175
|
+
private startPolling;
|
|
176
|
+
/**
|
|
177
|
+
* Stop polling for new emails
|
|
178
|
+
*/
|
|
179
|
+
private stopPolling;
|
|
180
|
+
/**
|
|
181
|
+
* Check for new emails and process them
|
|
182
|
+
*/
|
|
183
|
+
private checkForNewEmails;
|
|
184
|
+
/**
|
|
185
|
+
* Process a new incoming email
|
|
186
|
+
*/
|
|
187
|
+
private processNewEmail;
|
|
167
188
|
stop(): Promise<void>;
|
|
168
189
|
private request;
|
|
169
190
|
private getMailboxParam;
|
|
@@ -173,6 +194,9 @@ declare class AgentMBoxService extends Service {
|
|
|
173
194
|
deleteEmail(emailId: string): Promise<{
|
|
174
195
|
success: boolean;
|
|
175
196
|
}>;
|
|
197
|
+
markAsRead(emailId: string): Promise<{
|
|
198
|
+
success: boolean;
|
|
199
|
+
}>;
|
|
176
200
|
listMailboxes(): Promise<MailboxListResponse>;
|
|
177
201
|
createMailbox(request: CreateMailboxRequest): Promise<CreateMailboxResponse>;
|
|
178
202
|
deleteMailbox(mailboxId: string): Promise<{
|
|
@@ -191,58 +215,18 @@ declare class AgentMBoxService extends Service {
|
|
|
191
215
|
paid: boolean;
|
|
192
216
|
paidUntil: string | null;
|
|
193
217
|
}>;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
* Handles autonomous account creation and setup for AgentMBox
|
|
199
|
-
* The agent pays for its own subscription using its Solana wallet
|
|
200
|
-
*/
|
|
201
|
-
|
|
202
|
-
interface OnboardingStatus {
|
|
203
|
-
stage: "pending" | "account_created" | "api_key_created" | "awaiting_payment" | "paid" | "mailbox_created" | "complete" | "error";
|
|
204
|
-
paymentAddress?: string;
|
|
205
|
-
mailbox?: string;
|
|
206
|
-
error?: string;
|
|
207
|
-
}
|
|
208
|
-
declare class AgentMBoxOnboardingService extends Service {
|
|
209
|
-
private apiKey;
|
|
210
|
-
private mailbox;
|
|
211
|
-
private baseUrl;
|
|
212
|
-
private cfg;
|
|
213
|
-
private status;
|
|
214
|
-
static serviceName: "agentmbox-onboarding";
|
|
215
|
-
static serviceType: "EMAIL";
|
|
216
|
-
constructor(runtime?: IAgentRuntime);
|
|
217
|
-
get serviceName(): string;
|
|
218
|
-
get capabilityDescription(): string;
|
|
219
|
-
getApiKey(): string;
|
|
220
|
-
getMailbox(): string | undefined;
|
|
221
|
-
private generatePassword;
|
|
222
|
-
private getAgentWallet;
|
|
223
|
-
private request;
|
|
224
|
-
private authenticatedRequest;
|
|
225
|
-
startOnboarding(runtime: IAgentRuntime): Promise<OnboardingStatus>;
|
|
226
|
-
private checkExistingSetup;
|
|
227
|
-
private payForSubscription;
|
|
228
|
-
stop(): Promise<void>;
|
|
229
|
-
private createAccount;
|
|
230
|
-
private createApiKey;
|
|
231
|
-
private getPaymentStatus;
|
|
232
|
-
private waitForPayment;
|
|
233
|
-
private createMailbox;
|
|
234
|
-
getOrCreateMailbox(): Promise<Mailbox | null>;
|
|
235
|
-
getStatus(): OnboardingStatus;
|
|
236
|
-
getPaymentAddress(): Promise<string | null>;
|
|
237
|
-
isOnboardingComplete(): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Manually trigger a check for new emails
|
|
220
|
+
*/
|
|
221
|
+
checkNow(): Promise<void>;
|
|
238
222
|
}
|
|
239
223
|
|
|
240
224
|
/**
|
|
241
225
|
* AgentMBox Plugin for ElizaOS
|
|
242
226
|
* Email integration plugin that enables AI agents to send and receive emails
|
|
243
|
-
* Includes
|
|
227
|
+
* Includes email polling for incoming emails
|
|
244
228
|
*/
|
|
245
229
|
|
|
246
230
|
declare const agentMBoxPlugin: Plugin;
|
|
247
231
|
|
|
248
|
-
export { type AgentMBoxConfig, type AgentMBoxError, type AgentMBoxErrorCode,
|
|
232
|
+
export { type AgentMBoxConfig, type AgentMBoxError, type AgentMBoxErrorCode, AgentMBoxService, type ApiKey, type ApiKeyListResponse, type ApiKeyResponse, type CreateMailboxRequest, type CreateMailboxResponse, type Domain, type DomainDNSRecords, type DomainListResponse, type DomainResponse, type DomainVerifyResponse, type Email, type EmailAddress, type EmailDetailResponse, type EmailListResponse, type Mailbox, type MailboxListResponse, type PaymentCheckResponse, type PaymentStatus, type SendEmailRequest, type SendEmailResponse, agentMBoxPlugin, agentMBoxPlugin as default, isAgentMBoxError };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { logger as logger5 } from "@elizaos/core";
|
|
3
|
-
|
|
4
1
|
// src/services/AgentMBoxService.ts
|
|
5
2
|
import { Service, logger as logger2 } from "@elizaos/core";
|
|
6
3
|
|
|
@@ -10,25 +7,38 @@ function isAgentMBoxError(response) {
|
|
|
10
7
|
}
|
|
11
8
|
|
|
12
9
|
// src/services/AgentMBoxService.ts
|
|
10
|
+
var DEFAULT_POLLING_INTERVAL = 3e5;
|
|
13
11
|
var AgentMBoxService = class _AgentMBoxService extends Service {
|
|
12
|
+
constructor(runtime) {
|
|
13
|
+
super(runtime);
|
|
14
|
+
this.runtime = runtime;
|
|
15
|
+
}
|
|
14
16
|
apiKey = "";
|
|
15
17
|
mailbox;
|
|
16
18
|
baseUrl = "https://agentmbox.com/api/v1";
|
|
19
|
+
pollingInterval = DEFAULT_POLLING_INTERVAL;
|
|
20
|
+
pollingTimer = null;
|
|
21
|
+
lastEmailCheck = 0;
|
|
17
22
|
static serviceName = "agentmbox";
|
|
18
23
|
static serviceType = "EMAIL";
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
static async start(runtime) {
|
|
25
|
+
const service = new _AgentMBoxService(runtime);
|
|
26
|
+
await service.initialize(runtime);
|
|
27
|
+
return service;
|
|
21
28
|
}
|
|
22
29
|
get serviceName() {
|
|
23
30
|
return _AgentMBoxService.serviceName;
|
|
24
31
|
}
|
|
25
32
|
get capabilityDescription() {
|
|
26
|
-
return "AgentMBox email service - allows sending and receiving emails";
|
|
33
|
+
return "AgentMBox email service - allows sending and receiving emails with polling";
|
|
27
34
|
}
|
|
28
35
|
async initialize(runtime) {
|
|
29
36
|
const apiKey = String(runtime.getSetting("AGENTMBOX_API_KEY") || "");
|
|
30
37
|
const mailbox = String(runtime.getSetting("AGENTMBOX_MAILBOX") || "");
|
|
31
38
|
const baseUrl = String(runtime.getSetting("AGENTMBOX_BASE_URL") || "");
|
|
39
|
+
const pollingIntervalSetting = runtime.getSetting(
|
|
40
|
+
"AGENTMBOX_POLLING_INTERVAL"
|
|
41
|
+
);
|
|
32
42
|
if (apiKey && !apiKey.startsWith("ai_")) {
|
|
33
43
|
logger2.warn("AgentMBox API key should start with 'ai_'");
|
|
34
44
|
}
|
|
@@ -37,13 +47,101 @@ var AgentMBoxService = class _AgentMBoxService extends Service {
|
|
|
37
47
|
this.apiKey = apiKey;
|
|
38
48
|
this.mailbox = defaultMailbox;
|
|
39
49
|
this.baseUrl = baseUrl || "https://agentmbox.com/api/v1";
|
|
50
|
+
this.pollingInterval = pollingIntervalSetting ? parseInt(String(pollingIntervalSetting), 10) : DEFAULT_POLLING_INTERVAL;
|
|
40
51
|
this.runtime = runtime;
|
|
41
|
-
if (!this.apiKey.startsWith("ai_")) {
|
|
42
|
-
logger2.warn("AgentMBox API key should start with 'ai_'");
|
|
43
|
-
}
|
|
44
52
|
logger2.info("AgentMBox service initialized for: " + this.mailbox);
|
|
53
|
+
if (this.apiKey && this.apiKey.startsWith("ai_")) {
|
|
54
|
+
this.startPolling();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Start polling for new emails
|
|
59
|
+
*/
|
|
60
|
+
startPolling() {
|
|
61
|
+
if (this.pollingTimer) {
|
|
62
|
+
clearInterval(this.pollingTimer);
|
|
63
|
+
}
|
|
64
|
+
logger2.info(
|
|
65
|
+
`AgentMBox: Starting email polling every ${this.pollingInterval / 1e3} seconds`
|
|
66
|
+
);
|
|
67
|
+
this.checkForNewEmails();
|
|
68
|
+
this.pollingTimer = setInterval(() => {
|
|
69
|
+
this.checkForNewEmails();
|
|
70
|
+
}, this.pollingInterval);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Stop polling for new emails
|
|
74
|
+
*/
|
|
75
|
+
stopPolling() {
|
|
76
|
+
if (this.pollingTimer) {
|
|
77
|
+
clearInterval(this.pollingTimer);
|
|
78
|
+
this.pollingTimer = null;
|
|
79
|
+
logger2.info("AgentMBox: Stopped email polling");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check for new emails and process them
|
|
84
|
+
*/
|
|
85
|
+
async checkForNewEmails() {
|
|
86
|
+
if (!this.apiKey || !this.mailbox) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const response = await this.listEmails(10, 0);
|
|
91
|
+
if (response.emails && response.emails.length > 0) {
|
|
92
|
+
const unreadEmails = response.emails.filter(
|
|
93
|
+
(email) => !email.isRead && new Date(email.receivedAt).getTime() > this.lastEmailCheck
|
|
94
|
+
);
|
|
95
|
+
if (unreadEmails.length > 0) {
|
|
96
|
+
logger2.info(
|
|
97
|
+
`AgentMBox: Found ${unreadEmails.length} new unread email(s)`
|
|
98
|
+
);
|
|
99
|
+
for (const email of unreadEmails) {
|
|
100
|
+
await this.processNewEmail(email);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
this.lastEmailCheck = Date.now();
|
|
105
|
+
} catch (error) {
|
|
106
|
+
logger2.error(
|
|
107
|
+
"AgentMBox: Error checking for new emails: " + (error instanceof Error ? error.message : "Unknown error")
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Process a new incoming email
|
|
113
|
+
*/
|
|
114
|
+
async processNewEmail(email) {
|
|
115
|
+
try {
|
|
116
|
+
const fromEmail = email.from[0]?.email || "unknown";
|
|
117
|
+
logger2.info(`AgentMBox: Processing new email from ${fromEmail}`);
|
|
118
|
+
const memory = {
|
|
119
|
+
id: `email-${email.id}`,
|
|
120
|
+
type: "email",
|
|
121
|
+
content: {
|
|
122
|
+
text: `New email received:
|
|
123
|
+
From: ${fromEmail}
|
|
124
|
+
Subject: ${email.subject}
|
|
125
|
+
|
|
126
|
+
${email.textBody || email.htmlBody || ""}`
|
|
127
|
+
},
|
|
128
|
+
metadata: {
|
|
129
|
+
emailId: email.id,
|
|
130
|
+
from: fromEmail,
|
|
131
|
+
to: email.to[0]?.email,
|
|
132
|
+
subject: email.subject,
|
|
133
|
+
receivedAt: email.receivedAt
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
logger2.info(`AgentMBox: Email from ${fromEmail} stored as memory`);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
logger2.error(
|
|
139
|
+
"AgentMBox: Error processing new email: " + (error instanceof Error ? error.message : "Unknown error")
|
|
140
|
+
);
|
|
141
|
+
}
|
|
45
142
|
}
|
|
46
143
|
async stop() {
|
|
144
|
+
this.stopPolling();
|
|
47
145
|
logger2.info("AgentMBox service stopped");
|
|
48
146
|
}
|
|
49
147
|
async request(endpoint, options = {}) {
|
|
@@ -105,6 +203,15 @@ var AgentMBoxService = class _AgentMBoxService extends Service {
|
|
|
105
203
|
}
|
|
106
204
|
);
|
|
107
205
|
}
|
|
206
|
+
async markAsRead(emailId) {
|
|
207
|
+
const mailboxParam = this.getMailboxParam();
|
|
208
|
+
return this.request(
|
|
209
|
+
"/mail/" + emailId + "/read" + mailboxParam,
|
|
210
|
+
{
|
|
211
|
+
method: "POST"
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
}
|
|
108
215
|
async listMailboxes() {
|
|
109
216
|
return this.request("/mailboxes");
|
|
110
217
|
}
|
|
@@ -164,324 +271,11 @@ var AgentMBoxService = class _AgentMBoxService extends Service {
|
|
|
164
271
|
return { paid: false, paidUntil: null };
|
|
165
272
|
}
|
|
166
273
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
apiKey = "";
|
|
173
|
-
mailbox;
|
|
174
|
-
baseUrl = "https://agentmbox.com/api/v1";
|
|
175
|
-
cfg = null;
|
|
176
|
-
status = { stage: "pending" };
|
|
177
|
-
static serviceName = "agentmbox-onboarding";
|
|
178
|
-
static serviceType = "EMAIL";
|
|
179
|
-
constructor(runtime) {
|
|
180
|
-
super(runtime);
|
|
181
|
-
}
|
|
182
|
-
get serviceName() {
|
|
183
|
-
return _AgentMBoxOnboardingService.serviceName;
|
|
184
|
-
}
|
|
185
|
-
get capabilityDescription() {
|
|
186
|
-
return "AgentMBox autonomous onboarding - creates account, pays for subscription, sets up mailbox";
|
|
187
|
-
}
|
|
188
|
-
getApiKey() {
|
|
189
|
-
return this.apiKey;
|
|
190
|
-
}
|
|
191
|
-
getMailbox() {
|
|
192
|
-
return this.mailbox;
|
|
193
|
-
}
|
|
194
|
-
generatePassword(length = 32) {
|
|
195
|
-
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*";
|
|
196
|
-
let password = "";
|
|
197
|
-
const array = new Uint8Array(length);
|
|
198
|
-
crypto.getRandomValues(array);
|
|
199
|
-
for (let i = 0; i < length; i++) {
|
|
200
|
-
password += chars[array[i] % chars.length];
|
|
201
|
-
}
|
|
202
|
-
return password;
|
|
203
|
-
}
|
|
204
|
-
async getAgentWallet() {
|
|
205
|
-
if (!this.runtime) return null;
|
|
206
|
-
try {
|
|
207
|
-
const privateKeyBase58 = String(
|
|
208
|
-
this.runtime.getSetting("SOLANA_PRIVATE_KEY") || ""
|
|
209
|
-
);
|
|
210
|
-
if (privateKeyBase58) {
|
|
211
|
-
const { default: bs58 } = await import("bs58");
|
|
212
|
-
const { Keypair } = await import("@solana/web3.js");
|
|
213
|
-
const privateKey = bs58.decode(privateKeyBase58);
|
|
214
|
-
const keypair = Keypair.fromSecretKey(privateKey);
|
|
215
|
-
return {
|
|
216
|
-
publicKey: keypair.publicKey.toBase58(),
|
|
217
|
-
privateKey
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
const walletService = await this.runtime.getService("wallet");
|
|
221
|
-
if (walletService) {
|
|
222
|
-
const keypair = await walletService.getKeypair?.();
|
|
223
|
-
if (keypair) {
|
|
224
|
-
return {
|
|
225
|
-
publicKey: keypair.publicKey.toBase58(),
|
|
226
|
-
privateKey: keypair.secretKey
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
} catch (error) {
|
|
231
|
-
logger3.warn("Could not get agent wallet");
|
|
232
|
-
}
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
async request(endpoint, options = {}) {
|
|
236
|
-
const url = `${this.baseUrl}${endpoint}`;
|
|
237
|
-
const headers = {
|
|
238
|
-
"Content-Type": "application/json",
|
|
239
|
-
...options.headers
|
|
240
|
-
};
|
|
241
|
-
const response = await fetch(url, { ...options, headers });
|
|
242
|
-
const data = await response.json();
|
|
243
|
-
if (!response.ok) {
|
|
244
|
-
const error = data.error || `${response.status}`;
|
|
245
|
-
throw new Error(error);
|
|
246
|
-
}
|
|
247
|
-
return data;
|
|
248
|
-
}
|
|
249
|
-
async authenticatedRequest(endpoint, options = {}) {
|
|
250
|
-
if (!this.apiKey) {
|
|
251
|
-
throw new Error("API key not set");
|
|
252
|
-
}
|
|
253
|
-
const url = `${this.baseUrl}${endpoint}`;
|
|
254
|
-
const headers = {
|
|
255
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
256
|
-
"Content-Type": "application/json",
|
|
257
|
-
...options.headers
|
|
258
|
-
};
|
|
259
|
-
const response = await fetch(url, { ...options, headers });
|
|
260
|
-
const data = await response.json();
|
|
261
|
-
if (!response.ok) {
|
|
262
|
-
const error = data.error || `${response.status}`;
|
|
263
|
-
throw new Error(error);
|
|
264
|
-
}
|
|
265
|
-
return data;
|
|
266
|
-
}
|
|
267
|
-
async startOnboarding(runtime) {
|
|
268
|
-
this.runtime = runtime;
|
|
269
|
-
const existingApiKey = String(
|
|
270
|
-
runtime.getSetting("AGENTMBOX_API_KEY") || ""
|
|
271
|
-
);
|
|
272
|
-
if (existingApiKey && existingApiKey.startsWith("ai_")) {
|
|
273
|
-
this.apiKey = existingApiKey;
|
|
274
|
-
return await this.checkExistingSetup();
|
|
275
|
-
}
|
|
276
|
-
const agentName = runtime.character?.name?.toLowerCase().replace(/\s+/g, "-") || "agent";
|
|
277
|
-
const mailboxSetting = String(
|
|
278
|
-
runtime.getSetting("AGENTMBOX_MAILBOX") || ""
|
|
279
|
-
);
|
|
280
|
-
this.cfg = {
|
|
281
|
-
ownerEmail: String(runtime.getSetting("AGENTMBOX_OWNER_EMAIL")) || `agent-${agentName}@owner.local`,
|
|
282
|
-
password: this.generatePassword(32),
|
|
283
|
-
mailboxLocalPart: mailboxSetting ? mailboxSetting.split("@")[0] : agentName
|
|
284
|
-
};
|
|
285
|
-
try {
|
|
286
|
-
await this.createAccount();
|
|
287
|
-
this.status = { stage: "account_created" };
|
|
288
|
-
logger3.info("AgentMBox account created");
|
|
289
|
-
const apiKeyResponse = await this.createApiKey(agentName);
|
|
290
|
-
this.apiKey = apiKeyResponse.key;
|
|
291
|
-
this.status = { stage: "api_key_created" };
|
|
292
|
-
logger3.info("AgentMBox API key created");
|
|
293
|
-
const payment = await this.getPaymentStatus();
|
|
294
|
-
this.status = {
|
|
295
|
-
stage: "awaiting_payment",
|
|
296
|
-
paymentAddress: payment.solanaAddress
|
|
297
|
-
};
|
|
298
|
-
logger3.info("Payment address: " + payment.solanaAddress);
|
|
299
|
-
await this.payForSubscription(payment.solanaAddress, runtime);
|
|
300
|
-
this.status = { stage: "paid" };
|
|
301
|
-
logger3.info("Payment completed");
|
|
302
|
-
const mailbox = await this.createMailbox(this.cfg.mailboxLocalPart);
|
|
303
|
-
this.mailbox = mailbox.address;
|
|
304
|
-
this.status = {
|
|
305
|
-
stage: "complete",
|
|
306
|
-
mailbox: mailbox.address
|
|
307
|
-
};
|
|
308
|
-
logger3.info("Mailbox created: " + mailbox.address);
|
|
309
|
-
return this.status;
|
|
310
|
-
} catch (error) {
|
|
311
|
-
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
|
312
|
-
logger3.error("AgentMBox onboarding failed: " + errorMsg);
|
|
313
|
-
this.status = { stage: "error", error: errorMsg };
|
|
314
|
-
throw error;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
async checkExistingSetup() {
|
|
318
|
-
try {
|
|
319
|
-
const payment = await this.getPaymentStatus();
|
|
320
|
-
if (payment.paid) {
|
|
321
|
-
const mailbox = await this.getOrCreateMailbox();
|
|
322
|
-
this.status = mailbox ? { stage: "complete", mailbox: mailbox.address } : { stage: "paid" };
|
|
323
|
-
} else {
|
|
324
|
-
const wallet = await this.getAgentWallet();
|
|
325
|
-
if (wallet && this.runtime) {
|
|
326
|
-
await this.payForSubscription(payment.solanaAddress, this.runtime);
|
|
327
|
-
this.status = { stage: "paid" };
|
|
328
|
-
const mailbox = await this.getOrCreateMailbox();
|
|
329
|
-
if (mailbox) {
|
|
330
|
-
this.status = { stage: "complete", mailbox: mailbox.address };
|
|
331
|
-
}
|
|
332
|
-
} else {
|
|
333
|
-
this.status = {
|
|
334
|
-
stage: "awaiting_payment",
|
|
335
|
-
paymentAddress: payment.solanaAddress
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
} catch (error) {
|
|
340
|
-
logger3.warn("Could not check existing setup");
|
|
341
|
-
this.status = { stage: "pending" };
|
|
342
|
-
}
|
|
343
|
-
return this.status;
|
|
344
|
-
}
|
|
345
|
-
async payForSubscription(paymentAddress, runtime) {
|
|
346
|
-
const wallet = await this.getAgentWallet();
|
|
347
|
-
if (!wallet) {
|
|
348
|
-
logger3.warn("No agent wallet found, waiting for manual payment");
|
|
349
|
-
await this.waitForPayment();
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
logger3.info("Using agent wallet to pay for subscription");
|
|
353
|
-
try {
|
|
354
|
-
const { Connection, Keypair } = await import("@solana/web3.js");
|
|
355
|
-
const { transfer, getOrCreateAssociatedTokenAccount } = await import("@solana/spl-token");
|
|
356
|
-
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
357
|
-
const signer = Keypair.fromSecretKey(wallet.privateKey);
|
|
358
|
-
const usdcMintStr = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGZwyTDt1v";
|
|
359
|
-
const { PublicKey } = await import("@solana/web3.js");
|
|
360
|
-
const usdcMint = new PublicKey(usdcMintStr);
|
|
361
|
-
const toPublicKey = new PublicKey(paymentAddress);
|
|
362
|
-
const fromTokenAccount = await getOrCreateAssociatedTokenAccount(
|
|
363
|
-
connection,
|
|
364
|
-
signer,
|
|
365
|
-
usdcMint,
|
|
366
|
-
signer.publicKey
|
|
367
|
-
);
|
|
368
|
-
const toTokenAccount = await getOrCreateAssociatedTokenAccount(
|
|
369
|
-
connection,
|
|
370
|
-
signer,
|
|
371
|
-
usdcMint,
|
|
372
|
-
toPublicKey
|
|
373
|
-
);
|
|
374
|
-
const amount = 5e6;
|
|
375
|
-
await transfer(
|
|
376
|
-
connection,
|
|
377
|
-
signer,
|
|
378
|
-
fromTokenAccount.address,
|
|
379
|
-
toTokenAccount.address,
|
|
380
|
-
signer.publicKey,
|
|
381
|
-
amount
|
|
382
|
-
);
|
|
383
|
-
logger3.info("USDC transfer complete");
|
|
384
|
-
await this.waitForPayment();
|
|
385
|
-
} catch (error) {
|
|
386
|
-
logger3.error("Failed to transfer USDC, waiting for manual payment");
|
|
387
|
-
await this.waitForPayment();
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
async stop() {
|
|
391
|
-
logger3.info("AgentMBox onboarding service stopped");
|
|
392
|
-
}
|
|
393
|
-
async createAccount() {
|
|
394
|
-
if (!this.cfg) throw new Error("Config not set");
|
|
395
|
-
const response = await this.request("/auth/signup", {
|
|
396
|
-
method: "POST",
|
|
397
|
-
body: JSON.stringify({
|
|
398
|
-
email: this.cfg.ownerEmail,
|
|
399
|
-
password: this.cfg.password
|
|
400
|
-
})
|
|
401
|
-
});
|
|
402
|
-
logger3.info("Account created: " + response.id);
|
|
403
|
-
}
|
|
404
|
-
async createApiKey(name) {
|
|
405
|
-
const response = await this.request("/keys", {
|
|
406
|
-
method: "POST",
|
|
407
|
-
body: JSON.stringify({ name })
|
|
408
|
-
});
|
|
409
|
-
logger3.info("API key created: " + response.key.substring(0, 12) + "...");
|
|
410
|
-
return response;
|
|
411
|
-
}
|
|
412
|
-
async getPaymentStatus() {
|
|
413
|
-
return this.authenticatedRequest("/payment");
|
|
414
|
-
}
|
|
415
|
-
async waitForPayment(maxAttempts = 60, intervalMs = 5e3) {
|
|
416
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
417
|
-
try {
|
|
418
|
-
const result = await this.authenticatedRequest(
|
|
419
|
-
"/payment/check",
|
|
420
|
-
{
|
|
421
|
-
method: "POST"
|
|
422
|
-
}
|
|
423
|
-
);
|
|
424
|
-
if (result.paid) {
|
|
425
|
-
return result;
|
|
426
|
-
}
|
|
427
|
-
logger3.info(
|
|
428
|
-
"Waiting for payment... (" + attempt + "/" + maxAttempts + ")"
|
|
429
|
-
);
|
|
430
|
-
} catch (e) {
|
|
431
|
-
logger3.warn(
|
|
432
|
-
"Payment check failed: " + (e instanceof Error ? e.message : "unknown")
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
if (attempt < maxAttempts) {
|
|
436
|
-
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
throw new Error("Payment not received after " + maxAttempts + " attempts");
|
|
440
|
-
}
|
|
441
|
-
async createMailbox(localPart) {
|
|
442
|
-
const response = await this.authenticatedRequest(
|
|
443
|
-
"/mailboxes",
|
|
444
|
-
{
|
|
445
|
-
method: "POST",
|
|
446
|
-
body: JSON.stringify({
|
|
447
|
-
localPart,
|
|
448
|
-
displayName: this.cfg?.mailboxLocalPart || "Agent Mailbox"
|
|
449
|
-
})
|
|
450
|
-
}
|
|
451
|
-
);
|
|
452
|
-
return response.mailbox;
|
|
453
|
-
}
|
|
454
|
-
async getOrCreateMailbox() {
|
|
455
|
-
try {
|
|
456
|
-
const response = await this.authenticatedRequest("/mailboxes");
|
|
457
|
-
if (response.mailboxes.length > 0) {
|
|
458
|
-
return response.mailboxes[0];
|
|
459
|
-
}
|
|
460
|
-
if (this.cfg?.mailboxLocalPart) {
|
|
461
|
-
return await this.createMailbox(this.cfg.mailboxLocalPart);
|
|
462
|
-
}
|
|
463
|
-
return null;
|
|
464
|
-
} catch (error) {
|
|
465
|
-
logger3.error("Failed to get/create mailbox");
|
|
466
|
-
return null;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
getStatus() {
|
|
470
|
-
return this.status;
|
|
471
|
-
}
|
|
472
|
-
async getPaymentAddress() {
|
|
473
|
-
if (this.status.paymentAddress) {
|
|
474
|
-
return this.status.paymentAddress;
|
|
475
|
-
}
|
|
476
|
-
try {
|
|
477
|
-
const payment = await this.getPaymentStatus();
|
|
478
|
-
return payment.solanaAddress;
|
|
479
|
-
} catch {
|
|
480
|
-
return null;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
isOnboardingComplete() {
|
|
484
|
-
return this.status.stage === "complete";
|
|
274
|
+
/**
|
|
275
|
+
* Manually trigger a check for new emails
|
|
276
|
+
*/
|
|
277
|
+
async checkNow() {
|
|
278
|
+
await this.checkForNewEmails();
|
|
485
279
|
}
|
|
486
280
|
};
|
|
487
281
|
|
|
@@ -706,82 +500,237 @@ ${preview}`,
|
|
|
706
500
|
|
|
707
501
|
// src/actions/onboarding.ts
|
|
708
502
|
import {
|
|
709
|
-
logger as
|
|
503
|
+
logger as logger3
|
|
710
504
|
} from "@elizaos/core";
|
|
711
|
-
var
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
505
|
+
var BASE_URL = "https://agentmbox.com/api/v1";
|
|
506
|
+
var USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGZwyTDt1v";
|
|
507
|
+
var PAYMENT_AMOUNT = 5e6;
|
|
508
|
+
function generatePassword(length = 32) {
|
|
509
|
+
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*";
|
|
510
|
+
let password = "";
|
|
511
|
+
const array = new Uint8Array(length);
|
|
512
|
+
crypto.getRandomValues(array);
|
|
513
|
+
for (let i = 0; i < length; i++) {
|
|
514
|
+
password += chars[array[i] % chars.length];
|
|
515
|
+
}
|
|
516
|
+
return password;
|
|
517
|
+
}
|
|
518
|
+
async function getAgentWallet(runtime) {
|
|
519
|
+
try {
|
|
520
|
+
const privateKeyBase58 = String(
|
|
521
|
+
runtime.getSetting("SOLANA_PRIVATE_KEY") || ""
|
|
717
522
|
);
|
|
718
|
-
if (
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
523
|
+
if (privateKeyBase58) {
|
|
524
|
+
const { default: bs58 } = await import("bs58");
|
|
525
|
+
const { Keypair } = await import("@solana/web3.js");
|
|
526
|
+
const privateKey = bs58.decode(privateKeyBase58);
|
|
527
|
+
const keypair = Keypair.fromSecretKey(privateKey);
|
|
528
|
+
return {
|
|
529
|
+
publicKey: keypair.publicKey.toBase58(),
|
|
530
|
+
privateKey
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
const walletService = await runtime.getService("wallet");
|
|
534
|
+
if (walletService) {
|
|
535
|
+
const keypair = await walletService.getKeypair?.();
|
|
536
|
+
if (keypair) {
|
|
537
|
+
return {
|
|
538
|
+
publicKey: keypair.publicKey.toBase58(),
|
|
539
|
+
privateKey: keypair.secretKey
|
|
540
|
+
};
|
|
726
541
|
}
|
|
727
|
-
return { success: false, error: errorMsg };
|
|
728
542
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
543
|
+
} catch (error) {
|
|
544
|
+
logger3.warn("Could not get agent wallet");
|
|
545
|
+
}
|
|
546
|
+
return null;
|
|
547
|
+
}
|
|
548
|
+
var onboardingAction = {
|
|
549
|
+
name: "AGENTMBOX_ONBOARDING",
|
|
550
|
+
description: "Set up AgentMBox email for the agent - creates an account, pays 5 USDC on Solana, and creates a mailbox. The agent needs a Solana wallet with USDC to pay for the subscription.",
|
|
551
|
+
handler: async (runtime, _message, _state, _options, callback) => {
|
|
552
|
+
const existingApiKey = runtime.getSetting("AGENTMBOX_API_KEY");
|
|
553
|
+
const existingMailbox = runtime.getSetting("AGENTMBOX_MAILBOX");
|
|
554
|
+
if (existingApiKey && existingMailbox) {
|
|
555
|
+
const msg = `Already onboarded! Mailbox: ${existingMailbox}`;
|
|
556
|
+
logger3.info(msg);
|
|
733
557
|
if (callback) {
|
|
734
558
|
await callback({
|
|
735
559
|
text: msg,
|
|
736
|
-
values: { success: true, mailbox }
|
|
560
|
+
values: { success: true, mailbox: existingMailbox }
|
|
737
561
|
});
|
|
738
562
|
}
|
|
739
|
-
return { success: true, mailbox };
|
|
563
|
+
return { success: true, mailbox: existingMailbox };
|
|
740
564
|
}
|
|
565
|
+
let status = { stage: "pending" };
|
|
566
|
+
let apiKey = "";
|
|
567
|
+
let mailboxAddress = "";
|
|
741
568
|
try {
|
|
742
|
-
|
|
743
|
-
const
|
|
569
|
+
const agentName = runtime.character?.name?.toLowerCase().replace(/\s+/g, "-") || "agent";
|
|
570
|
+
const ownerEmail = String(runtime.getSetting("AGENTMBOX_OWNER_EMAIL")) || `agent-${agentName}@owner.local`;
|
|
571
|
+
const password = generatePassword(32);
|
|
572
|
+
logger3.info("AgentMBox: Creating account...");
|
|
573
|
+
const signupResponse = await fetch(`${BASE_URL}/auth/signup`, {
|
|
574
|
+
method: "POST",
|
|
575
|
+
headers: { "Content-Type": "application/json" },
|
|
576
|
+
body: JSON.stringify({ email: ownerEmail, password })
|
|
577
|
+
});
|
|
578
|
+
if (!signupResponse.ok) {
|
|
579
|
+
const error = await signupResponse.json();
|
|
580
|
+
throw new Error(`Account creation failed: ${error.error}`);
|
|
581
|
+
}
|
|
582
|
+
const signupData = await signupResponse.json();
|
|
583
|
+
status = { stage: "account_created" };
|
|
584
|
+
logger3.info("AgentMBox: Account created");
|
|
585
|
+
logger3.info("AgentMBox: Creating API key...");
|
|
586
|
+
const keyResponse = await fetch(`${BASE_URL}/keys`, {
|
|
587
|
+
method: "POST",
|
|
588
|
+
headers: { "Content-Type": "application/json" },
|
|
589
|
+
body: JSON.stringify({ name: `${agentName}-key` }),
|
|
590
|
+
credentials: "include"
|
|
591
|
+
});
|
|
592
|
+
if (!keyResponse.ok) {
|
|
593
|
+
const error = await keyResponse.json();
|
|
594
|
+
throw new Error(`API key creation failed: ${error.error}`);
|
|
595
|
+
}
|
|
596
|
+
const keyData = await keyResponse.json();
|
|
597
|
+
apiKey = keyData.key;
|
|
598
|
+
status = { stage: "api_key_created" };
|
|
599
|
+
logger3.info("AgentMBox: API key created");
|
|
600
|
+
logger3.info("AgentMBox: Getting payment address...");
|
|
601
|
+
const paymentResponse = await fetch(`${BASE_URL}/payment`, {
|
|
602
|
+
headers: { Authorization: `Bearer ${apiKey}` }
|
|
603
|
+
});
|
|
604
|
+
if (!paymentResponse.ok) {
|
|
605
|
+
const error = await paymentResponse.json();
|
|
606
|
+
throw new Error(`Payment status failed: ${error.error}`);
|
|
607
|
+
}
|
|
608
|
+
const paymentData = await paymentResponse.json();
|
|
609
|
+
status = {
|
|
610
|
+
stage: "awaiting_payment",
|
|
611
|
+
paymentAddress: paymentData.solanaAddress
|
|
612
|
+
};
|
|
744
613
|
if (callback) {
|
|
745
614
|
await callback({
|
|
746
|
-
text: `
|
|
615
|
+
text: `Account created! Payment required: Please send 5 USDC to ${paymentData.solanaAddress}`,
|
|
747
616
|
values: {
|
|
748
|
-
success:
|
|
749
|
-
stage:
|
|
750
|
-
|
|
751
|
-
paymentAddress: status.paymentAddress,
|
|
752
|
-
error: status.error
|
|
617
|
+
success: false,
|
|
618
|
+
stage: "awaiting_payment",
|
|
619
|
+
paymentAddress: paymentData.solanaAddress
|
|
753
620
|
}
|
|
754
621
|
});
|
|
755
622
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
const
|
|
759
|
-
|
|
760
|
-
runtime.setSetting("AGENTMBOX_API_KEY", apiKey, true);
|
|
761
|
-
}
|
|
762
|
-
if (mailbox) {
|
|
763
|
-
runtime.setSetting("AGENTMBOX_MAILBOX", mailbox);
|
|
764
|
-
}
|
|
765
|
-
logger4.info("Onboarding complete! Mailbox: " + status.mailbox);
|
|
766
|
-
return { success: true, mailbox: status.mailbox };
|
|
767
|
-
} else if (status.stage === "awaiting_payment" && status.paymentAddress) {
|
|
768
|
-
const msg = "Payment required! Please send 5 USDC to: " + status.paymentAddress;
|
|
769
|
-
logger4.warn(msg);
|
|
623
|
+
const wallet = await getAgentWallet(runtime);
|
|
624
|
+
if (!wallet) {
|
|
625
|
+
const msg = `Payment required! Please send 5 USDC to: ${paymentData.solanaAddress}`;
|
|
626
|
+
logger3.warn(msg);
|
|
770
627
|
return {
|
|
771
628
|
success: false,
|
|
772
|
-
stage:
|
|
773
|
-
paymentAddress:
|
|
629
|
+
stage: "awaiting_payment",
|
|
630
|
+
paymentAddress: paymentData.solanaAddress,
|
|
774
631
|
message: msg
|
|
775
632
|
};
|
|
776
|
-
} else if (status.stage === "error") {
|
|
777
|
-
const errorMsg = "Onboarding failed: " + status.error;
|
|
778
|
-
logger4.error(errorMsg);
|
|
779
|
-
return { success: false, error: status.error };
|
|
780
633
|
}
|
|
781
|
-
|
|
634
|
+
logger3.info("AgentMBox: Attempting to pay for subscription...");
|
|
635
|
+
try {
|
|
636
|
+
const { Connection, Keypair, PublicKey } = await import("@solana/web3.js");
|
|
637
|
+
const { transfer, getOrCreateAssociatedTokenAccount } = await import("@solana/spl-token");
|
|
638
|
+
const connection = new Connection(
|
|
639
|
+
"https://api.mainnet-beta.solana.com"
|
|
640
|
+
);
|
|
641
|
+
const signer = Keypair.fromSecretKey(wallet.privateKey);
|
|
642
|
+
const toPublicKey = new PublicKey(paymentData.solanaAddress);
|
|
643
|
+
const fromTokenAccount = await getOrCreateAssociatedTokenAccount(
|
|
644
|
+
connection,
|
|
645
|
+
signer,
|
|
646
|
+
new PublicKey(USDC_MINT),
|
|
647
|
+
signer.publicKey
|
|
648
|
+
);
|
|
649
|
+
const toTokenAccount = await getOrCreateAssociatedTokenAccount(
|
|
650
|
+
connection,
|
|
651
|
+
signer,
|
|
652
|
+
new PublicKey(USDC_MINT),
|
|
653
|
+
toPublicKey
|
|
654
|
+
);
|
|
655
|
+
await transfer(
|
|
656
|
+
connection,
|
|
657
|
+
signer,
|
|
658
|
+
fromTokenAccount.address,
|
|
659
|
+
toTokenAccount.address,
|
|
660
|
+
signer.publicKey,
|
|
661
|
+
PAYMENT_AMOUNT
|
|
662
|
+
);
|
|
663
|
+
logger3.info("AgentMBox: USDC transfer complete");
|
|
664
|
+
} catch (transferError) {
|
|
665
|
+
logger3.error("USDC transfer failed:", transferError);
|
|
666
|
+
const msg = `Payment required! Please send 5 USDC to: ${paymentData.solanaAddress}`;
|
|
667
|
+
return {
|
|
668
|
+
success: false,
|
|
669
|
+
stage: "awaiting_payment",
|
|
670
|
+
paymentAddress: paymentData.solanaAddress,
|
|
671
|
+
message: msg
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
logger3.info("AgentMBox: Checking payment...");
|
|
675
|
+
let paid = false;
|
|
676
|
+
for (let i = 0; i < 12 && !paid; i++) {
|
|
677
|
+
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
678
|
+
try {
|
|
679
|
+
const checkResponse = await fetch(`${BASE_URL}/payment/check`, {
|
|
680
|
+
method: "POST",
|
|
681
|
+
headers: { Authorization: `Bearer ${apiKey}` }
|
|
682
|
+
});
|
|
683
|
+
const checkData = await checkResponse.json();
|
|
684
|
+
paid = checkData.paid;
|
|
685
|
+
if (paid) {
|
|
686
|
+
status = { stage: "paid" };
|
|
687
|
+
logger3.info("AgentMBox: Payment confirmed");
|
|
688
|
+
}
|
|
689
|
+
} catch {
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
if (!paid) {
|
|
693
|
+
throw new Error("Payment not confirmed after 60 seconds");
|
|
694
|
+
}
|
|
695
|
+
logger3.info("AgentMBox: Creating mailbox...");
|
|
696
|
+
const mailboxResponse = await fetch(`${BASE_URL}/mailboxes`, {
|
|
697
|
+
method: "POST",
|
|
698
|
+
headers: {
|
|
699
|
+
Authorization: `Bearer ${apiKey}`,
|
|
700
|
+
"Content-Type": "application/json"
|
|
701
|
+
},
|
|
702
|
+
body: JSON.stringify({
|
|
703
|
+
localPart: agentName,
|
|
704
|
+
displayName: runtime.character?.name || agentName
|
|
705
|
+
})
|
|
706
|
+
});
|
|
707
|
+
if (!mailboxResponse.ok) {
|
|
708
|
+
const error = await mailboxResponse.json();
|
|
709
|
+
throw new Error(`Mailbox creation failed: ${error.error}`);
|
|
710
|
+
}
|
|
711
|
+
const mailboxData = await mailboxResponse.json();
|
|
712
|
+
mailboxAddress = mailboxData.mailbox.address;
|
|
713
|
+
status = {
|
|
714
|
+
stage: "complete",
|
|
715
|
+
mailbox: mailboxAddress
|
|
716
|
+
};
|
|
717
|
+
logger3.info(`AgentMBox: Mailbox created: ${mailboxAddress}`);
|
|
718
|
+
runtime.setSetting("AGENTMBOX_API_KEY", apiKey, true);
|
|
719
|
+
runtime.setSetting("AGENTMBOX_MAILBOX", mailboxAddress);
|
|
720
|
+
if (callback) {
|
|
721
|
+
await callback({
|
|
722
|
+
text: `Onboarding complete! Mailbox: ${mailboxAddress}`,
|
|
723
|
+
values: {
|
|
724
|
+
success: true,
|
|
725
|
+
mailbox: mailboxAddress
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
return { success: true, mailbox: mailboxAddress };
|
|
782
730
|
} catch (error) {
|
|
783
731
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
784
|
-
|
|
732
|
+
logger3.error("AgentMBox onboarding failed: " + errorMessage);
|
|
733
|
+
status = { stage: "error", error: errorMessage };
|
|
785
734
|
if (callback) {
|
|
786
735
|
await callback({
|
|
787
736
|
text: "Onboarding failed: " + errorMessage,
|
|
@@ -791,15 +740,8 @@ var onboardingAction = {
|
|
|
791
740
|
return { success: false, error: errorMessage };
|
|
792
741
|
}
|
|
793
742
|
},
|
|
794
|
-
validate: async (
|
|
795
|
-
|
|
796
|
-
const service = runtime.getService(
|
|
797
|
-
"agentmbox-onboarding"
|
|
798
|
-
);
|
|
799
|
-
return !!service;
|
|
800
|
-
} catch {
|
|
801
|
-
return false;
|
|
802
|
-
}
|
|
743
|
+
validate: async (_runtime) => {
|
|
744
|
+
return true;
|
|
803
745
|
},
|
|
804
746
|
examples: [
|
|
805
747
|
[
|
|
@@ -891,68 +833,19 @@ ${recentEmailsText}` : "\n\nNo recent emails."}`,
|
|
|
891
833
|
// src/index.ts
|
|
892
834
|
var agentMBoxPlugin = {
|
|
893
835
|
name: "agentmbox",
|
|
894
|
-
description: "AgentMBox email integration plugin for ElizaOS - enables AI agents to send/receive emails with
|
|
836
|
+
description: "AgentMBox email integration plugin for ElizaOS - enables AI agents to send/receive emails with email polling",
|
|
895
837
|
priority: 0,
|
|
896
838
|
config: {
|
|
897
|
-
baseUrl: "https://agentmbox.com/api/v1"
|
|
839
|
+
baseUrl: "https://agentmbox.com/api/v1",
|
|
840
|
+
pollingInterval: 3e5
|
|
841
|
+
// 5 minutes
|
|
898
842
|
},
|
|
899
843
|
actions: [sendEmailAction, getEmailsAction, onboardingAction],
|
|
900
844
|
providers: [emailProvider],
|
|
901
|
-
services: [AgentMBoxService
|
|
902
|
-
init: async (config, runtime) => {
|
|
903
|
-
logger5.info("AgentMBox plugin initializing");
|
|
904
|
-
const existingApiKey = runtime.getSetting("AGENTMBOX_API_KEY");
|
|
905
|
-
const skipOnboarding = runtime.getSetting("AGENTMBOX_SKIP_ONBOARDING") === "true";
|
|
906
|
-
if (!existingApiKey && !skipOnboarding) {
|
|
907
|
-
logger5.info("Starting AgentMBox autonomous onboarding...");
|
|
908
|
-
try {
|
|
909
|
-
const onboardingService = runtime.getService(
|
|
910
|
-
"agentmbox-onboarding"
|
|
911
|
-
);
|
|
912
|
-
if (onboardingService) {
|
|
913
|
-
const status = await onboardingService.startOnboarding(runtime);
|
|
914
|
-
if (status.stage === "complete" && status.mailbox) {
|
|
915
|
-
const apiKey = onboardingService.getApiKey();
|
|
916
|
-
const mailbox = onboardingService.getMailbox();
|
|
917
|
-
if (apiKey) {
|
|
918
|
-
runtime.setSetting("AGENTMBOX_API_KEY", apiKey, true);
|
|
919
|
-
}
|
|
920
|
-
if (mailbox) {
|
|
921
|
-
runtime.setSetting("AGENTMBOX_MAILBOX", mailbox);
|
|
922
|
-
}
|
|
923
|
-
logger5.info("Onboarding complete! Mailbox: " + status.mailbox);
|
|
924
|
-
} else if (status.stage === "awaiting_payment" && status.paymentAddress) {
|
|
925
|
-
logger5.warn(
|
|
926
|
-
"Payment required. Please fund: " + status.paymentAddress
|
|
927
|
-
);
|
|
928
|
-
logger5.info("Required: 5 USDC on Solana + ~0.01 SOL for fees");
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
} catch (error) {
|
|
932
|
-
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
|
933
|
-
logger5.error("Onboarding failed: " + errorMsg);
|
|
934
|
-
}
|
|
935
|
-
} else if (existingApiKey) {
|
|
936
|
-
logger5.info("Using existing AgentMBox configuration");
|
|
937
|
-
} else {
|
|
938
|
-
logger5.info("Onboarding skipped per configuration");
|
|
939
|
-
}
|
|
940
|
-
const emailService = runtime.getService("agentmbox");
|
|
941
|
-
if (emailService) {
|
|
942
|
-
try {
|
|
943
|
-
await emailService.initialize(runtime);
|
|
944
|
-
} catch (error) {
|
|
945
|
-
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
|
946
|
-
logger5.error(
|
|
947
|
-
"Failed to initialize AgentMBox email service: " + errorMsg
|
|
948
|
-
);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
}
|
|
845
|
+
services: [AgentMBoxService]
|
|
952
846
|
};
|
|
953
847
|
var index_default = agentMBoxPlugin;
|
|
954
848
|
export {
|
|
955
|
-
AgentMBoxOnboardingService,
|
|
956
849
|
AgentMBoxService,
|
|
957
850
|
agentMBoxPlugin,
|
|
958
851
|
index_default as default,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/services/AgentMBoxService.ts","../src/types/index.ts","../src/services/AgentMBoxOnboardingService.ts","../src/actions/sendEmail.ts","../src/actions/getEmails.ts","../src/actions/onboarding.ts","../src/providers/emailProvider.ts"],"sourcesContent":["/**\n * AgentMBox Plugin for ElizaOS\n * Email integration plugin that enables AI agents to send and receive emails\n * Includes autonomous self-onboarding using the agent's Solana wallet\n */\n\nimport type { Plugin, IAgentRuntime } from \"@elizaos/core\";\nimport { logger } from \"@elizaos/core\";\nimport { AgentMBoxService } from \"./services/AgentMBoxService\";\nimport { AgentMBoxOnboardingService } from \"./services/AgentMBoxOnboardingService\";\nimport { sendEmailAction } from \"./actions/sendEmail\";\nimport { getEmailsAction } from \"./actions/getEmails\";\nimport { onboardingAction } from \"./actions/onboarding\";\nimport { emailProvider } from \"./providers/emailProvider\";\n\nexport const agentMBoxPlugin: Plugin = {\n name: \"agentmbox\",\n description:\n \"AgentMBox email integration plugin for ElizaOS - enables AI agents to send/receive emails with autonomous onboarding\",\n priority: 0,\n config: {\n baseUrl: \"https://agentmbox.com/api/v1\",\n },\n actions: [sendEmailAction, getEmailsAction, onboardingAction],\n providers: [emailProvider],\n services: [AgentMBoxService, AgentMBoxOnboardingService],\n init: async (config: Record<string, string>, runtime: IAgentRuntime) => {\n logger.info(\"AgentMBox plugin initializing\");\n\n // Check if onboarding is needed\n const existingApiKey = runtime.getSetting(\"AGENTMBOX_API_KEY\");\n const skipOnboarding =\n runtime.getSetting(\"AGENTMBOX_SKIP_ONBOARDING\") === \"true\";\n\n if (!existingApiKey && !skipOnboarding) {\n logger.info(\"Starting AgentMBox autonomous onboarding...\");\n\n try {\n const onboardingService =\n runtime.getService<AgentMBoxOnboardingService>(\n \"agentmbox-onboarding\",\n );\n if (onboardingService) {\n const status = await onboardingService.startOnboarding(runtime);\n\n if (status.stage === \"complete\" && status.mailbox) {\n // Save credentials to runtime settings for persistence\n const apiKey = onboardingService.getApiKey();\n const mailbox = onboardingService.getMailbox();\n if (apiKey) {\n runtime.setSetting(\"AGENTMBOX_API_KEY\", apiKey, true);\n }\n if (mailbox) {\n runtime.setSetting(\"AGENTMBOX_MAILBOX\", mailbox);\n }\n logger.info(\"Onboarding complete! Mailbox: \" + status.mailbox);\n } else if (\n status.stage === \"awaiting_payment\" &&\n status.paymentAddress\n ) {\n logger.warn(\n \"Payment required. Please fund: \" + status.paymentAddress,\n );\n logger.info(\"Required: 5 USDC on Solana + ~0.01 SOL for fees\");\n }\n }\n } catch (error) {\n const errorMsg =\n error instanceof Error ? error.message : \"Unknown error\";\n logger.error(\"Onboarding failed: \" + errorMsg);\n }\n } else if (existingApiKey) {\n logger.info(\"Using existing AgentMBox configuration\");\n } else {\n logger.info(\"Onboarding skipped per configuration\");\n }\n\n // Initialize main email service (after onboarding has potentially saved credentials)\n const emailService = runtime.getService<AgentMBoxService>(\"agentmbox\");\n if (emailService) {\n try {\n await emailService.initialize(runtime);\n } catch (error) {\n const errorMsg =\n error instanceof Error ? error.message : \"Unknown error\";\n logger.error(\n \"Failed to initialize AgentMBox email service: \" + errorMsg,\n );\n // Don't fail the whole plugin initialization - the service will be unavailable\n }\n }\n },\n};\n\nexport default agentMBoxPlugin;\n\n// Re-export for convenience\nexport { AgentMBoxService } from \"./services/AgentMBoxService\";\nexport { AgentMBoxOnboardingService } from \"./services/AgentMBoxOnboardingService\";\nexport * from \"./types\";\n","import { Service, type IAgentRuntime, logger } from \"@elizaos/core\";\nimport {\n type AgentMBoxConfig,\n type EmailListResponse,\n type EmailDetailResponse,\n type SendEmailRequest,\n type SendEmailResponse,\n type MailboxListResponse,\n type CreateMailboxRequest,\n type CreateMailboxResponse,\n type PaymentStatus,\n type PaymentCheckResponse,\n type DomainListResponse,\n type DomainResponse,\n type DomainVerifyResponse,\n type ApiKeyResponse,\n isAgentMBoxError,\n} from \"../types\";\n\nexport class AgentMBoxService extends Service {\n private apiKey: string = \"\";\n private mailbox: string | undefined;\n private baseUrl: string = \"https://agentmbox.com/api/v1\";\n\n static serviceName = \"agentmbox\" as const;\n static serviceType = \"EMAIL\" as const;\n\n constructor(runtime?: IAgentRuntime) {\n super(runtime!);\n }\n\n get serviceName(): string {\n return AgentMBoxService.serviceName;\n }\n\n get capabilityDescription(): string {\n return \"AgentMBox email service - allows sending and receiving emails\";\n }\n\n async initialize(runtime: IAgentRuntime): Promise<void> {\n const apiKey = String(runtime.getSetting(\"AGENTMBOX_API_KEY\") || \"\");\n const mailbox = String(runtime.getSetting(\"AGENTMBOX_MAILBOX\") || \"\");\n const baseUrl = String(runtime.getSetting(\"AGENTMBOX_BASE_URL\") || \"\");\n\n // API key will be set by onboarding if not provided\n // The service will work once onboarding completes\n if (apiKey && !apiKey.startsWith(\"ai_\")) {\n logger.warn(\"AgentMBox API key should start with 'ai_'\");\n }\n\n const agentName =\n runtime.character?.name?.toLowerCase().replace(/\\s+/g, \"-\") || \"agent\";\n const defaultMailbox = mailbox || `${agentName}@agentmbox.com`;\n\n this.apiKey = apiKey;\n this.mailbox = defaultMailbox;\n this.baseUrl = baseUrl || \"https://agentmbox.com/api/v1\";\n this.runtime = runtime;\n\n if (!this.apiKey.startsWith(\"ai_\")) {\n logger.warn(\"AgentMBox API key should start with 'ai_'\");\n }\n\n logger.info(\"AgentMBox service initialized for: \" + this.mailbox);\n }\n\n async stop(): Promise<void> {\n logger.info(\"AgentMBox service stopped\");\n }\n\n private async request<T>(\n endpoint: string,\n options: RequestInit = {},\n ): Promise<T> {\n if (!this.apiKey) {\n throw new Error(\n \"AgentMBox API key not configured. Ensure onboarding has completed or set AGENTMBOX_API_KEY.\",\n );\n }\n\n const url = `${this.baseUrl}${endpoint}`;\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n ...(options.headers as Record<string, string>),\n };\n\n const response = await fetch(url, { ...options, headers });\n const data = await response.json();\n\n if (!response.ok) {\n if (isAgentMBoxError(data)) {\n throw new Error(\n `AgentMBox API error (${response.status}): ${data.error}`,\n );\n }\n throw new Error(`AgentMBox API error: ${response.status}`);\n }\n\n return data as T;\n }\n\n private getMailboxParam(): string {\n if (!this.mailbox) {\n throw new Error(\"Mailbox not configured\");\n }\n return \"?mailbox=\" + encodeURIComponent(this.mailbox);\n }\n\n async listEmails(limit = 50, offset = 0): Promise<EmailListResponse> {\n const mailboxParam = this.getMailboxParam();\n return this.request<EmailListResponse>(\n \"/mail\" + mailboxParam + \"&limit=\" + limit + \"&offset=\" + offset,\n );\n }\n\n async getEmail(emailId: string): Promise<EmailDetailResponse> {\n const mailboxParam = this.getMailboxParam();\n return this.request<EmailDetailResponse>(\"/mail/\" + emailId + mailboxParam);\n }\n\n async sendEmail(request: SendEmailRequest): Promise<SendEmailResponse> {\n const from = request.from || this.mailbox;\n if (!from) {\n throw new Error(\"Sender address not specified\");\n }\n\n return this.request<SendEmailResponse>(\"/mail/send\", {\n method: \"POST\",\n body: JSON.stringify({ ...request, from }),\n });\n }\n\n async deleteEmail(emailId: string): Promise<{ success: boolean }> {\n const mailboxParam = this.getMailboxParam();\n return this.request<{ success: boolean }>(\n \"/mail/\" + emailId + mailboxParam,\n {\n method: \"DELETE\",\n },\n );\n }\n\n async listMailboxes(): Promise<MailboxListResponse> {\n return this.request<MailboxListResponse>(\"/mailboxes\");\n }\n\n async createMailbox(\n request: CreateMailboxRequest,\n ): Promise<CreateMailboxResponse> {\n return this.request<CreateMailboxResponse>(\"/mailboxes\", {\n method: \"POST\",\n body: JSON.stringify(request),\n });\n }\n\n async deleteMailbox(mailboxId: string): Promise<{ success: boolean }> {\n return this.request<{ success: boolean }>(\"/mailboxes/\" + mailboxId, {\n method: \"DELETE\",\n });\n }\n\n async getPaymentStatus(): Promise<PaymentStatus> {\n return this.request<PaymentStatus>(\"/payment\");\n }\n\n async checkPayment(): Promise<PaymentCheckResponse> {\n return this.request<PaymentCheckResponse>(\"/payment/check\", {\n method: \"POST\",\n });\n }\n\n async listDomains(): Promise<DomainListResponse> {\n return this.request<DomainListResponse>(\"/domains\");\n }\n\n async addDomain(domain: string): Promise<DomainResponse> {\n return this.request<DomainResponse>(\"/domains\", {\n method: \"POST\",\n body: JSON.stringify({ domain }),\n });\n }\n\n async verifyDomain(domainId: string): Promise<DomainVerifyResponse> {\n return this.request<DomainVerifyResponse>(\n \"/domains/\" + domainId + \"/verify\",\n {\n method: \"POST\",\n },\n );\n }\n\n async deleteDomain(domainId: string): Promise<{ success: boolean }> {\n return this.request<{ success: boolean }>(\"/domains/\" + domainId, {\n method: \"DELETE\",\n });\n }\n\n async createApiKey(name: string): Promise<ApiKeyResponse> {\n return this.request<ApiKeyResponse>(\"/keys\", {\n method: \"POST\",\n body: JSON.stringify({ name }),\n });\n }\n\n async getStatus(): Promise<{ paid: boolean; paidUntil: string | null }> {\n try {\n const status = await this.getPaymentStatus();\n return { paid: status.paid, paidUntil: status.paidUntil };\n } catch (error) {\n logger.error(\"Failed to get AgentMBox status\");\n return { paid: false, paidUntil: null };\n }\n }\n}\n\nexport default AgentMBoxService;\n","/**\n * AgentMBox Plugin Types\n * TypeScript interfaces for AgentMBox email integration\n */\n\nexport interface AgentMBoxConfig {\n /** API key for AgentMBox (starts with ai_) */\n apiKey: string;\n /** Mailbox address (e.g., my-agent@agentmbox.com) */\n mailbox?: string;\n /** Base URL for AgentMBox API (default: https://agentmbox.com/api/v1) */\n baseUrl?: string;\n}\n\nexport interface EmailAddress {\n name?: string;\n email: string;\n}\n\nexport interface Email {\n id: string;\n from: EmailAddress[];\n to: EmailAddress[];\n cc?: EmailAddress[] | null;\n subject: string;\n receivedAt: string;\n textBody?: string;\n htmlBody?: string;\n preview?: string;\n hasAttachment: boolean;\n isRead: boolean;\n}\n\nexport interface EmailListResponse {\n mailbox: string;\n emails: Email[];\n limit: number;\n offset: number;\n}\n\nexport interface EmailDetailResponse {\n email: Email;\n}\n\nexport interface SendEmailRequest {\n /** Sender address (must be a mailbox you own) */\n from: string;\n /** Recipient(s) - single email or array */\n to: string | string[];\n /** Email subject line */\n subject: string;\n /** Plain text body */\n text?: string;\n /** HTML body */\n html?: string;\n}\n\nexport interface SendEmailResponse {\n success: boolean;\n}\n\nexport interface Mailbox {\n id: string;\n address: string;\n localPart: string;\n domainName: string;\n displayName?: string | null;\n password?: string; // Only shown at creation\n createdAt: string;\n}\n\nexport interface MailboxListResponse {\n mailboxes: Mailbox[];\n}\n\nexport interface CreateMailboxRequest {\n localPart: string;\n domainId?: string;\n displayName?: string;\n}\n\nexport interface CreateMailboxResponse {\n mailbox: Mailbox;\n}\n\nexport interface PaymentStatus {\n paid: boolean;\n paidUntil: string | null;\n solanaAddress: string;\n usdcPerPeriod: number;\n periodDays: number;\n creditedUsdc: number;\n payments: unknown[];\n}\n\nexport interface PaymentCheckResponse {\n paid: boolean;\n paidUntil: string;\n newCredits: number;\n balanceUsdc: number;\n creditedUsdc: number;\n}\n\nexport interface Domain {\n id: string;\n domain: string;\n verified: boolean;\n}\n\nexport interface DomainDNSRecords {\n verification: { type: string; name: string; value: string };\n mx: { type: string; name: string; value: string; priority: number };\n spf: { type: string; name: string; value: string };\n dkim: { type: string; name: string; value: string };\n}\n\nexport interface DomainResponse {\n domain: Domain;\n dnsRecords: DomainDNSRecords;\n}\n\nexport interface DomainVerifyResponse {\n verified: boolean;\n txtVerified: boolean;\n mxVerified: boolean;\n spfVerified: boolean;\n dkimVerified: boolean;\n}\n\nexport interface DomainListResponse {\n domains: (Domain & { dnsRecords?: DomainDNSRecords })[];\n}\n\nexport interface ApiKey {\n id: string;\n name: string;\n key: string;\n keyPrefix: string;\n}\n\nexport interface ApiKeyResponse {\n id: string;\n name: string;\n key: string;\n keyPrefix: string;\n}\n\nexport interface ApiKeyListResponse {\n keys: ApiKey[];\n}\n\nexport interface AgentMBoxError {\n error: string;\n}\n\nexport type AgentMBoxErrorCode = 400 | 401 | 402 | 403 | 404 | 409 | 502;\n\nexport function isAgentMBoxError(\n response: unknown,\n): response is AgentMBoxError {\n return (\n typeof response === \"object\" &&\n response !== null &&\n \"error\" in response &&\n typeof (response as AgentMBoxError).error === \"string\"\n );\n}\n","/**\n * AgentMBox Onboarding Service\n * Handles autonomous account creation and setup for AgentMBox\n * The agent pays for its own subscription using its Solana wallet\n */\n\nimport { Service, type IAgentRuntime, logger } from \"@elizaos/core\";\nimport {\n type PaymentStatus,\n type PaymentCheckResponse,\n type ApiKeyResponse,\n type Mailbox,\n} from \"../types\";\n\nexport interface OnboardingStatus {\n stage:\n | \"pending\"\n | \"account_created\"\n | \"api_key_created\"\n | \"awaiting_payment\"\n | \"paid\"\n | \"mailbox_created\"\n | \"complete\"\n | \"error\";\n paymentAddress?: string;\n mailbox?: string;\n error?: string;\n}\n\nexport class AgentMBoxOnboardingService extends Service {\n private apiKey: string = \"\";\n private mailbox: string | undefined;\n private baseUrl: string = \"https://agentmbox.com/api/v1\";\n private cfg: {\n ownerEmail: string;\n password: string;\n mailboxLocalPart: string;\n } | null = null;\n private status: OnboardingStatus = { stage: \"pending\" };\n\n static serviceName = \"agentmbox-onboarding\" as const;\n static serviceType = \"EMAIL\" as const;\n\n constructor(runtime?: IAgentRuntime) {\n super(runtime!);\n }\n\n get serviceName(): string {\n return AgentMBoxOnboardingService.serviceName;\n }\n\n get capabilityDescription(): string {\n return \"AgentMBox autonomous onboarding - creates account, pays for subscription, sets up mailbox\";\n }\n\n getApiKey(): string {\n return this.apiKey;\n }\n\n getMailbox(): string | undefined {\n return this.mailbox;\n }\n\n private generatePassword(length: number = 32): string {\n const chars =\n \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*\";\n let password = \"\";\n const array = new Uint8Array(length);\n crypto.getRandomValues(array);\n for (let i = 0; i < length; i++) {\n password += chars[array[i] % chars.length];\n }\n return password;\n }\n\n private async getAgentWallet(): Promise<{\n publicKey: string;\n privateKey: Uint8Array;\n } | null> {\n if (!this.runtime) return null;\n\n try {\n const privateKeyBase58 = String(\n this.runtime.getSetting(\"SOLANA_PRIVATE_KEY\") || \"\",\n );\n if (privateKeyBase58) {\n const { default: bs58 } = await import(\"bs58\");\n const { Keypair } = await import(\"@solana/web3.js\");\n const privateKey = bs58.decode(privateKeyBase58);\n const keypair = Keypair.fromSecretKey(privateKey);\n return {\n publicKey: keypair.publicKey.toBase58(),\n privateKey,\n };\n }\n\n const walletService = await this.runtime.getService(\"wallet\");\n if (walletService) {\n const keypair = await (walletService as any).getKeypair?.();\n if (keypair) {\n return {\n publicKey: keypair.publicKey.toBase58(),\n privateKey: keypair.secretKey,\n };\n }\n }\n } catch (error) {\n logger.warn(\"Could not get agent wallet\");\n }\n\n return null;\n }\n\n private async request<T>(\n endpoint: string,\n options: RequestInit = {},\n ): Promise<T> {\n const url = `${this.baseUrl}${endpoint}`;\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n ...(options.headers as Record<string, string>),\n };\n\n const response = await fetch(url, { ...options, headers });\n const data = await response.json();\n\n if (!response.ok) {\n const error = (data as { error?: string }).error || `${response.status}`;\n throw new Error(error);\n }\n\n return data as T;\n }\n\n private async authenticatedRequest<T>(\n endpoint: string,\n options: RequestInit = {},\n ): Promise<T> {\n if (!this.apiKey) {\n throw new Error(\"API key not set\");\n }\n\n const url = `${this.baseUrl}${endpoint}`;\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n ...(options.headers as Record<string, string>),\n };\n\n const response = await fetch(url, { ...options, headers });\n const data = await response.json();\n\n if (!response.ok) {\n const error = (data as { error?: string }).error || `${response.status}`;\n throw new Error(error);\n }\n\n return data as T;\n }\n\n async startOnboarding(runtime: IAgentRuntime): Promise<OnboardingStatus> {\n this.runtime = runtime;\n\n const existingApiKey = String(\n runtime.getSetting(\"AGENTMBOX_API_KEY\") || \"\",\n );\n if (existingApiKey && existingApiKey.startsWith(\"ai_\")) {\n this.apiKey = existingApiKey;\n return await this.checkExistingSetup();\n }\n\n const agentName =\n runtime.character?.name?.toLowerCase().replace(/\\s+/g, \"-\") || \"agent\";\n const mailboxSetting = String(\n runtime.getSetting(\"AGENTMBOX_MAILBOX\") || \"\",\n );\n this.cfg = {\n ownerEmail:\n String(runtime.getSetting(\"AGENTMBOX_OWNER_EMAIL\")) ||\n `agent-${agentName}@owner.local`,\n password: this.generatePassword(32),\n mailboxLocalPart: mailboxSetting\n ? mailboxSetting.split(\"@\")[0]\n : agentName,\n };\n\n try {\n // Step 1: Create account\n await this.createAccount();\n this.status = { stage: \"account_created\" };\n logger.info(\"AgentMBox account created\");\n\n // Step 2: Create API key\n const apiKeyResponse = await this.createApiKey(agentName);\n this.apiKey = apiKeyResponse.key;\n this.status = { stage: \"api_key_created\" };\n logger.info(\"AgentMBox API key created\");\n\n // Step 3: Get payment address\n const payment = await this.getPaymentStatus();\n this.status = {\n stage: \"awaiting_payment\",\n paymentAddress: payment.solanaAddress,\n };\n logger.info(\"Payment address: \" + payment.solanaAddress);\n\n // Step 4: Pay for subscription\n await this.payForSubscription(payment.solanaAddress, runtime);\n this.status = { stage: \"paid\" };\n logger.info(\"Payment completed\");\n\n // Step 5: Create mailbox\n const mailbox = await this.createMailbox(this.cfg!.mailboxLocalPart);\n this.mailbox = mailbox.address;\n this.status = {\n stage: \"complete\",\n mailbox: mailbox.address,\n };\n logger.info(\"Mailbox created: \" + mailbox.address);\n\n return this.status;\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : \"Unknown error\";\n logger.error(\"AgentMBox onboarding failed: \" + errorMsg);\n this.status = { stage: \"error\", error: errorMsg };\n throw error;\n }\n }\n\n private async checkExistingSetup(): Promise<OnboardingStatus> {\n try {\n const payment = await this.getPaymentStatus();\n\n if (payment.paid) {\n const mailbox = await this.getOrCreateMailbox();\n this.status = mailbox\n ? { stage: \"complete\", mailbox: mailbox.address }\n : { stage: \"paid\" };\n } else {\n const wallet = await this.getAgentWallet();\n if (wallet && this.runtime) {\n await this.payForSubscription(payment.solanaAddress, this.runtime);\n this.status = { stage: \"paid\" };\n const mailbox = await this.getOrCreateMailbox();\n if (mailbox) {\n this.status = { stage: \"complete\", mailbox: mailbox.address };\n }\n } else {\n this.status = {\n stage: \"awaiting_payment\",\n paymentAddress: payment.solanaAddress,\n };\n }\n }\n } catch (error) {\n logger.warn(\"Could not check existing setup\");\n this.status = { stage: \"pending\" };\n }\n\n return this.status;\n }\n\n private async payForSubscription(\n paymentAddress: string,\n runtime: IAgentRuntime,\n ): Promise<void> {\n const wallet = await this.getAgentWallet();\n\n if (!wallet) {\n logger.warn(\"No agent wallet found, waiting for manual payment\");\n await this.waitForPayment();\n return;\n }\n\n logger.info(\"Using agent wallet to pay for subscription\");\n\n try {\n const { Connection, Keypair } = await import(\"@solana/web3.js\");\n const { transfer, getOrCreateAssociatedTokenAccount } =\n await import(\"@solana/spl-token\");\n\n const connection = new Connection(\"https://api.mainnet-beta.solana.com\");\n const signer = Keypair.fromSecretKey(wallet.privateKey);\n\n const usdcMintStr = \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGZwyTDt1v\";\n const { PublicKey } = await import(\"@solana/web3.js\");\n const usdcMint = new PublicKey(usdcMintStr);\n const toPublicKey = new PublicKey(paymentAddress);\n\n const fromTokenAccount = await getOrCreateAssociatedTokenAccount(\n connection,\n signer,\n usdcMint,\n signer.publicKey,\n );\n\n const toTokenAccount = await getOrCreateAssociatedTokenAccount(\n connection,\n signer,\n usdcMint,\n toPublicKey,\n );\n\n const amount = 5_000_000;\n\n await transfer(\n connection,\n signer,\n fromTokenAccount.address,\n toTokenAccount.address,\n signer.publicKey,\n amount,\n );\n\n logger.info(\"USDC transfer complete\");\n await this.waitForPayment();\n } catch (error) {\n logger.error(\"Failed to transfer USDC, waiting for manual payment\");\n await this.waitForPayment();\n }\n }\n\n async stop(): Promise<void> {\n logger.info(\"AgentMBox onboarding service stopped\");\n }\n\n private async createAccount(): Promise<void> {\n if (!this.cfg) throw new Error(\"Config not set\");\n\n const response = await this.request<{ id: string }>(\"/auth/signup\", {\n method: \"POST\",\n body: JSON.stringify({\n email: this.cfg.ownerEmail,\n password: this.cfg.password,\n }),\n });\n\n logger.info(\"Account created: \" + response.id);\n }\n\n private async createApiKey(name: string): Promise<ApiKeyResponse> {\n const response = await this.request<ApiKeyResponse>(\"/keys\", {\n method: \"POST\",\n body: JSON.stringify({ name }),\n });\n\n logger.info(\"API key created: \" + response.key.substring(0, 12) + \"...\");\n return response;\n }\n\n private async getPaymentStatus(): Promise<PaymentStatus> {\n return this.authenticatedRequest<PaymentStatus>(\"/payment\");\n }\n\n private async waitForPayment(\n maxAttempts: number = 60,\n intervalMs: number = 5000,\n ): Promise<PaymentCheckResponse> {\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n const result = await this.authenticatedRequest<PaymentCheckResponse>(\n \"/payment/check\",\n {\n method: \"POST\",\n },\n );\n\n if (result.paid) {\n return result;\n }\n\n logger.info(\n \"Waiting for payment... (\" + attempt + \"/\" + maxAttempts + \")\",\n );\n } catch (e) {\n logger.warn(\n \"Payment check failed: \" +\n (e instanceof Error ? e.message : \"unknown\"),\n );\n }\n\n if (attempt < maxAttempts) {\n await new Promise((resolve) => setTimeout(resolve, intervalMs));\n }\n }\n\n throw new Error(\"Payment not received after \" + maxAttempts + \" attempts\");\n }\n\n private async createMailbox(localPart: string): Promise<Mailbox> {\n const response = await this.authenticatedRequest<{ mailbox: Mailbox }>(\n \"/mailboxes\",\n {\n method: \"POST\",\n body: JSON.stringify({\n localPart,\n displayName: this.cfg?.mailboxLocalPart || \"Agent Mailbox\",\n }),\n },\n );\n\n return response.mailbox;\n }\n\n async getOrCreateMailbox(): Promise<Mailbox | null> {\n try {\n const response = await this.authenticatedRequest<{\n mailboxes: Mailbox[];\n }>(\"/mailboxes\");\n\n if (response.mailboxes.length > 0) {\n return response.mailboxes[0];\n }\n\n if (this.cfg?.mailboxLocalPart) {\n return await this.createMailbox(this.cfg.mailboxLocalPart);\n }\n\n return null;\n } catch (error) {\n logger.error(\"Failed to get/create mailbox\");\n return null;\n }\n }\n\n getStatus(): OnboardingStatus {\n return this.status;\n }\n\n async getPaymentAddress(): Promise<string | null> {\n if (this.status.paymentAddress) {\n return this.status.paymentAddress;\n }\n\n try {\n const payment = await this.getPaymentStatus();\n return payment.solanaAddress;\n } catch {\n return null;\n }\n }\n\n isOnboardingComplete(): boolean {\n return this.status.stage === \"complete\";\n }\n}\n\nexport default AgentMBoxOnboardingService;\n","/**\n * Send Email Action\n * Allows the agent to send emails via AgentMBox\n */\n\nimport {\n type Action,\n type HandlerCallback,\n type IAgentRuntime,\n type Memory,\n type State,\n type ActionExample,\n} from \"@elizaos/core\";\nimport { AgentMBoxService } from \"../services/AgentMBoxService\";\n\nexport const sendEmailAction: Action = {\n name: \"SEND_EMAIL\",\n description: \"Send an email to a recipient using AgentMBox email service\",\n handler: async (\n runtime: IAgentRuntime,\n message: Memory,\n state: State,\n options: Record<string, unknown>,\n callback?: HandlerCallback\n ) => {\n const service = runtime.getService<AgentMBoxService>(\"agentmbox\");\n if (!service) {\n throw new Error(\"AgentMBox service not initialized\");\n }\n\n const { to, subject, text, html } = options;\n\n if (!to) {\n throw new Error(\"Missing required field: 'to' (recipient email)\");\n }\n\n if (!subject) {\n throw new Error(\"Missing required field: 'subject'\");\n }\n\n const from = options.from as string | undefined;\n\n try {\n const result = await service.sendEmail({\n from,\n to: Array.isArray(to) ? to : to,\n subject,\n text: text as string | undefined,\n html: html as string | undefined,\n });\n\n if (callback) {\n await callback({\n text: `Email sent successfully to ${to}`,\n values: {\n success: result.success,\n recipient: to,\n subject,\n },\n });\n }\n\n return {\n success: true,\n values: {\n sentTo: to,\n subject,\n },\n };\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : \"Unknown error\";\n logger.error(\"Failed to send email\", { error: errorMessage });\n\n if (callback) {\n await callback({\n text: `Failed to send email: ${errorMessage}`,\n values: {\n success: false,\n error: errorMessage,\n },\n });\n }\n\n return {\n success: false,\n error: errorMessage,\n };\n }\n },\n validate: async (runtime: IAgentRuntime) => {\n try {\n const service = runtime.getService<AgentMBoxService>(\"agentmbox\");\n return !!service;\n } catch {\n return false;\n }\n },\n examples: [\n [\n {\n name: \"user\",\n content: \"Send an email to john@example.com about the project update\",\n },\n {\n name: \"assistant\",\n content: \"I'll send that email for you.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"Email the team that the meeting is at 3pm\",\n },\n {\n name: \"assistant\",\n content: \"Sending that email now.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"Can you notify alice@example.com that the report is ready?\",\n },\n {\n name: \"assistant\",\n content: \"I'll send her an email right away.\",\n },\n ],\n ] as ActionExample[][],\n};\n\nexport default sendEmailAction;\n","/**\n * Get Emails Action\n * Allows the agent to retrieve emails from the mailbox via AgentMBox\n */\n\nimport {\n type Action,\n type HandlerCallback,\n type IAgentRuntime,\n type Memory,\n type State,\n type ActionExample,\n} from \"@elizaos/core\";\nimport { AgentMBoxService } from \"../services/AgentMBoxService\";\n\nexport const getEmailsAction: Action = {\n name: \"GET_EMAILS\",\n description: \"Retrieve emails from the AgentMBox mailbox. Can filter by read status and limit results.\",\n handler: async (\n runtime: IAgentRuntime,\n message: Memory,\n state: State,\n options: Record<string, unknown>,\n callback?: HandlerCallback\n ) => {\n const service = runtime.getService<AgentMBoxService>(\"agentmbox\");\n if (!service) {\n throw new Error(\"AgentMBox service not initialized\");\n }\n\n const limit = (options.limit as number) || 10;\n const offset = (options.offset as number) || 0;\n const emailId = options.emailId as string | undefined;\n\n try {\n // If emailId is provided, get a specific email\n if (emailId) {\n const emailDetail = await service.getEmail(emailId);\n\n if (callback) {\n await callback({\n text: `Retrieved email: ${emailDetail.email.subject}`,\n values: {\n email: emailDetail.email,\n },\n });\n }\n\n return {\n success: true,\n values: {\n email: emailDetail.email,\n },\n };\n }\n\n // Otherwise, list emails\n const emailList = await service.listEmails(limit, offset);\n\n // Filter by read status if specified\n let emails = emailList.emails;\n const unreadOnly = options.unreadOnly as boolean;\n if (unreadOnly) {\n emails = emails.filter((email) => !email.isRead);\n }\n\n if (callback) {\n const preview = emails\n .slice(0, 5)\n .map((e) => `- ${e.subject} from ${e.from[0]?.email}`)\n .join(\"\\n\");\n await callback({\n text: `Found ${emails.length} emails:\\n${preview}`,\n values: {\n emails: emails,\n total: emailList.emails.length,\n unread: emailList.emails.filter((e) => !e.isRead).length,\n },\n });\n }\n\n return {\n success: true,\n values: {\n emails: emails,\n total: emailList.emails.length,\n limit: emailList.limit,\n offset: emailList.offset,\n },\n };\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : \"Unknown error\";\n logger.error(\"Failed to get emails\", { error: errorMessage });\n\n if (callback) {\n await callback({\n text: `Failed to get emails: ${errorMessage}`,\n values: {\n success: false,\n error: errorMessage,\n },\n });\n }\n\n return {\n success: false,\n error: errorMessage,\n };\n }\n },\n validate: async (runtime: IAgentRuntime) => {\n try {\n const service = runtime.getService<AgentMBoxService>(\"agentmbox\");\n return !!service;\n } catch {\n return false;\n }\n },\n examples: [\n [\n {\n name: \"user\",\n content: \"Check my inbox for any new emails\",\n },\n {\n name: \"assistant\",\n content: \"Let me check your inbox for new emails.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"Show me the last 5 emails I received\",\n },\n {\n name: \"assistant\",\n content: \"I'll retrieve your recent emails.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"Get the details of that email about the meeting\",\n },\n {\n name: \"assistant\",\n content: \"Let me fetch that email for you.\",\n },\n ],\n ] as ActionExample[][],\n};\n\nexport default getEmailsAction;\n","/**\n * Onboarding Action\n * Allows the agent to self-onboard with AgentMBox - creates account, pays for subscription, sets up mailbox\n */\n\nimport {\n type Action,\n type HandlerCallback,\n type IAgentRuntime,\n type Memory,\n type State,\n type ActionExample,\n logger,\n} from \"@elizaos/core\";\nimport { AgentMBoxOnboardingService } from \"../services/AgentMBoxOnboardingService\";\n\nexport const onboardingAction: Action = {\n name: \"AGENTMBOX_ONBOARDING\",\n description:\n \"Set up AgentMBox email for the agent - creates an account, pays 5 USDC on Solana, and creates a mailbox. The agent needs a Solana wallet with USDC to pay for the subscription.\",\n handler: async (\n runtime: IAgentRuntime,\n message: Memory,\n state: State,\n _options: Record<string, unknown>,\n callback?: HandlerCallback,\n ) => {\n const onboardingService = runtime.getService<AgentMBoxOnboardingService>(\n \"agentmbox-onboarding\",\n );\n\n if (!onboardingService) {\n const errorMsg = \"AgentMBox onboarding service not initialized\";\n logger.error(errorMsg);\n if (callback) {\n await callback({\n text: errorMsg,\n values: { success: false, error: errorMsg },\n });\n }\n return { success: false, error: errorMsg };\n }\n\n // Check if already onboarded\n if (onboardingService.isOnboardingComplete()) {\n const mailbox = onboardingService.getMailbox();\n const msg = `Already onboarded! Mailbox: ${mailbox}`;\n logger.info(msg);\n if (callback) {\n await callback({\n text: msg,\n values: { success: true, mailbox },\n });\n }\n return { success: true, mailbox };\n }\n\n try {\n logger.info(\"Starting AgentMBox onboarding...\");\n const status = await onboardingService.startOnboarding(runtime);\n\n if (callback) {\n await callback({\n text: `Onboarding ${status.stage}: ${\n status.mailbox || status.paymentAddress || status.error || \"\"\n }`,\n values: {\n success: status.stage === \"complete\",\n stage: status.stage,\n mailbox: status.mailbox,\n paymentAddress: status.paymentAddress,\n error: status.error,\n },\n });\n }\n\n if (status.stage === \"complete\" && status.mailbox) {\n // Save credentials to runtime settings\n const apiKey = onboardingService.getApiKey();\n const mailbox = onboardingService.getMailbox();\n if (apiKey) {\n runtime.setSetting(\"AGENTMBOX_API_KEY\", apiKey, true);\n }\n if (mailbox) {\n runtime.setSetting(\"AGENTMBOX_MAILBOX\", mailbox);\n }\n logger.info(\"Onboarding complete! Mailbox: \" + status.mailbox);\n return { success: true, mailbox: status.mailbox };\n } else if (status.stage === \"awaiting_payment\" && status.paymentAddress) {\n const msg =\n \"Payment required! Please send 5 USDC to: \" + status.paymentAddress;\n logger.warn(msg);\n return {\n success: false,\n stage: status.stage,\n paymentAddress: status.paymentAddress,\n message: msg,\n };\n } else if (status.stage === \"error\") {\n const errorMsg = \"Onboarding failed: \" + status.error;\n logger.error(errorMsg);\n return { success: false, error: status.error };\n }\n\n return { success: true, stage: status.stage };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : \"Unknown error\";\n logger.error(\"Onboarding failed: \" + errorMessage);\n\n if (callback) {\n await callback({\n text: \"Onboarding failed: \" + errorMessage,\n values: { success: false, error: errorMessage },\n });\n }\n\n return { success: false, error: errorMessage };\n }\n },\n validate: async (runtime: IAgentRuntime) => {\n try {\n const service = runtime.getService<AgentMBoxOnboardingService>(\n \"agentmbox-onboarding\",\n );\n return !!service;\n } catch {\n return false;\n }\n },\n examples: [\n [\n {\n name: \"user\",\n content: \"Set up email for this agent\",\n },\n {\n name: \"assistant\",\n content:\n \"I'll set up AgentMBox email for you. This will create an account and pay 5 USDC from the agent's wallet.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"I need to configure the email service\",\n },\n {\n name: \"assistant\",\n content: \"Starting the AgentMBox onboarding process now.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"Can you set up a mailbox for receiving emails?\",\n },\n {\n name: \"assistant\",\n content: \"On it! I'll create the mailbox and handle the payment.\",\n },\n ],\n ] as ActionExample[][],\n};\n\nexport default onboardingAction;\n","/**\n * Email Provider\n * Provides email context to the agent, including unread counts and recent emails\n */\n\nimport {\n type Provider,\n type IAgentRuntime,\n type Memory,\n type State,\n type ProviderResult,\n} from \"@elizaos/core\";\nimport { AgentMBoxService } from \"../services/AgentMBoxService\";\n\nexport const emailProvider: Provider = {\n name: \"email\",\n description: \"Provides email context from AgentMBox including unread counts and recent messages\",\n get: async (\n runtime: IAgentRuntime,\n message: Memory,\n _state: State\n ): Promise<ProviderResult> => {\n try {\n const service = runtime.getService<AgentMBoxService>(\"agentmbox\");\n if (!service) {\n return {\n text: \"Email service not available\",\n values: {\n available: false,\n },\n };\n }\n\n // Get recent emails\n const emailList = await service.listEmails(10, 0);\n const unreadCount = emailList.emails.filter((e) => !e.isRead).length;\n const recentEmails = emailList.emails.slice(0, 5);\n\n // Format recent emails for context\n const recentEmailsText = recentEmails\n .map(\n (email) =>\n `- From: ${email.from[0]?.name || email.from[0]?.email || \"Unknown\"} | Subject: ${email.subject}${\n !email.isRead ? \" [UNREAD]\" : \"\"\n }`\n )\n .join(\"\\n\");\n\n return {\n text: `Email Status: ${unreadCount} unread of ${emailList.emails.length} total${\n recentEmails.length > 0\n ? `\\n\\nRecent Emails:\\n${recentEmailsText}`\n : \"\\n\\nNo recent emails.\"\n }`,\n values: {\n available: true,\n unreadCount,\n totalEmails: emailList.emails.length,\n recentEmails: recentEmails.map((e) => ({\n id: e.id,\n from: e.from[0],\n subject: e.subject,\n preview: e.preview,\n isRead: e.isRead,\n receivedAt: e.receivedAt,\n })),\n },\n };\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : \"Unknown error\";\n return {\n text: `Email service error: ${errorMessage}`,\n values: {\n available: false,\n error: errorMessage,\n },\n };\n }\n },\n};\n\nexport default emailProvider;\n"],"mappings":";AAOA,SAAS,UAAAA,eAAc;;;ACPvB,SAAS,SAA6B,UAAAC,eAAc;;;AC6J7C,SAAS,iBACd,UAC4B;AAC5B,SACE,OAAO,aAAa,YACpB,aAAa,QACb,WAAW,YACX,OAAQ,SAA4B,UAAU;AAElD;;;ADnJO,IAAM,mBAAN,MAAM,0BAAyB,QAAQ;AAAA,EACpC,SAAiB;AAAA,EACjB;AAAA,EACA,UAAkB;AAAA,EAE1B,OAAO,cAAc;AAAA,EACrB,OAAO,cAAc;AAAA,EAErB,YAAY,SAAyB;AACnC,UAAM,OAAQ;AAAA,EAChB;AAAA,EAEA,IAAI,cAAsB;AACxB,WAAO,kBAAiB;AAAA,EAC1B;AAAA,EAEA,IAAI,wBAAgC;AAClC,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,SAAuC;AACtD,UAAM,SAAS,OAAO,QAAQ,WAAW,mBAAmB,KAAK,EAAE;AACnE,UAAM,UAAU,OAAO,QAAQ,WAAW,mBAAmB,KAAK,EAAE;AACpE,UAAM,UAAU,OAAO,QAAQ,WAAW,oBAAoB,KAAK,EAAE;AAIrE,QAAI,UAAU,CAAC,OAAO,WAAW,KA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AQ;AAAA,MAC/C;AAAA,IACF,WAAW,gBAAgB;AACzB,MAAAA,QAAO,KAAK,wCAAwC;AAAA,IACtD,OAAO;AACL,MAAAA,QAAO,KAAK,sCAAsC;AAAA,IACpD;AAGA,UAAM,eAAe,QAAQ,WAA6B,WAAW;AACrE,QAAI,cAAc;AAChB,UAAI;AACF,cAAM,aAAa,WAAW,OAAO;AAAA,MACvC,SAAS,OAAO;AACd,cAAM,WACJ,iBAAiB,QAAQ,MAAM,UAAU;AAC3C,QAAAA,QAAO;AAAA,UACL,mDAAmD;AAAA,QACrD;AAAA,MAEF;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["logger","logger","logger","Service","logger","logger","logger"]}
|
|
1
|
+
{"version":3,"sources":["../src/services/AgentMBoxService.ts","../src/types/index.ts","../src/actions/sendEmail.ts","../src/actions/getEmails.ts","../src/actions/onboarding.ts","../src/providers/emailProvider.ts","../src/index.ts"],"sourcesContent":["import { Service, type IAgentRuntime, logger } from \"@elizaos/core\";\nimport {\n type Email,\n type EmailListResponse,\n type EmailDetailResponse,\n type SendEmailRequest,\n type SendEmailResponse,\n type MailboxListResponse,\n type CreateMailboxRequest,\n type CreateMailboxResponse,\n type PaymentStatus,\n type PaymentCheckResponse,\n type DomainListResponse,\n type DomainResponse,\n type DomainVerifyResponse,\n type ApiKeyResponse,\n isAgentMBoxError,\n} from \"../types\";\n\nconst DEFAULT_POLLING_INTERVAL = 300000; // 5 minutes\n\nexport class AgentMBoxService extends Service {\n private apiKey: string = \"\";\n private mailbox: string | undefined;\n private baseUrl: string = \"https://agentmbox.com/api/v1\";\n private pollingInterval: number = DEFAULT_POLLING_INTERVAL;\n private pollingTimer: NodeJS.Timeout | null = null;\n private lastEmailCheck: number = 0;\n\n static serviceName = \"agentmbox\" as const;\n static serviceType = \"EMAIL\" as const;\n\n constructor(protected runtime: IAgentRuntime) {\n super(runtime);\n }\n\n static async start(runtime: IAgentRuntime): Promise<AgentMBoxService> {\n const service = new AgentMBoxService(runtime);\n await service.initialize(runtime);\n return service;\n }\n\n get serviceName(): string {\n return AgentMBoxService.serviceName;\n }\n\n get capabilityDescription(): string {\n return \"AgentMBox email service - allows sending and receiving emails with polling\";\n }\n\n async initialize(runtime: IAgentRuntime): Promise<void> {\n const apiKey = String(runtime.getSetting(\"AGENTMBOX_API_KEY\") || \"\");\n const mailbox = String(runtime.getSetting(\"AGENTMBOX_MAILBOX\") || \"\");\n const baseUrl = String(runtime.getSetting(\"AGENTMBOX_BASE_URL\") || \"\");\n const pollingIntervalSetting = runtime.getSetting(\n \"AGENTMBOX_POLLING_INTERVAL\",\n );\n\n if (apiKey && !apiKey.startsWith(\"ai_\")) {\n logger.warn(\"AgentMBox API key should start with 'ai_'\");\n }\n\n const agentName =\n runtime.character?.name?.toLowerCase().replace(/\\s+/g, \"-\") || \"agent\";\n const defaultMailbox = mailbox || `${agentName}@agentmbox.com`;\n\n this.apiKey = apiKey;\n this.mailbox = defaultMailbox;\n this.baseUrl = baseUrl || \"https://agentmbox.com/api/v1\";\n this.pollingInterval = pollingIntervalSetting\n ? parseInt(String(pollingIntervalSetting), 10)\n : DEFAULT_POLLING_INTERVAL;\n this.runtime = runtime;\n\n logger.info(\"AgentMBox service initialized for: \" + this.mailbox);\n\n // Start polling for new emails\n if (this.apiKey && this.apiKey.startsWith(\"ai_\")) {\n this.startPolling();\n }\n }\n\n /**\n * Start polling for new emails\n */\n private startPolling(): void {\n if (this.pollingTimer) {\n clearInterval(this.pollingTimer);\n }\n\n logger.info(\n `AgentMBox: Starting email polling every ${this.pollingInterval / 1000} seconds`,\n );\n\n // Initial check\n this.checkForNewEmails();\n\n // Set up periodic polling\n this.pollingTimer = setInterval(() => {\n this.checkForNewEmails();\n }, this.pollingInterval);\n }\n\n /**\n * Stop polling for new emails\n */\n private stopPolling(): void {\n if (this.pollingTimer) {\n clearInterval(this.pollingTimer);\n this.pollingTimer = null;\n logger.info(\"AgentMBox: Stopped email polling\");\n }\n }\n\n /**\n * Check for new emails and process them\n */\n private async checkForNewEmails(): Promise<void> {\n if (!this.apiKey || !this.mailbox) {\n return;\n }\n\n try {\n // Get recent emails (last 10, unread first)\n const response = await this.listEmails(10, 0);\n\n if (response.emails && response.emails.length > 0) {\n // Find unread emails\n const unreadEmails = response.emails.filter(\n (email) =>\n !email.isRead &&\n new Date(email.receivedAt).getTime() > this.lastEmailCheck,\n );\n\n if (unreadEmails.length > 0) {\n logger.info(\n `AgentMBox: Found ${unreadEmails.length} new unread email(s)`,\n );\n\n // Process each new email\n for (const email of unreadEmails) {\n await this.processNewEmail(email);\n }\n }\n }\n\n this.lastEmailCheck = Date.now();\n } catch (error) {\n logger.error(\n \"AgentMBox: Error checking for new emails: \" +\n (error instanceof Error ? error.message : \"Unknown error\"),\n );\n }\n }\n\n /**\n * Process a new incoming email\n */\n private async processNewEmail(email: Email): Promise<void> {\n try {\n const fromEmail = email.from[0]?.email || \"unknown\";\n logger.info(`AgentMBox: Processing new email from ${fromEmail}`);\n\n // Create a memory for the email so the agent can respond to it\n // This allows the agent to be aware of incoming emails\n const memory = {\n id: `email-${email.id}`,\n type: \"email\" as const,\n content: {\n text: `New email received:\\nFrom: ${fromEmail}\\nSubject: ${email.subject}\\n\\n${email.textBody || email.htmlBody || \"\"}`,\n },\n metadata: {\n emailId: email.id,\n from: fromEmail,\n to: email.to[0]?.email,\n subject: email.subject,\n receivedAt: email.receivedAt,\n },\n };\n\n // Store the email as a memory for context\n // The agent can then decide to respond using the SEND_EMAIL action\n logger.info(`AgentMBox: Email from ${fromEmail} stored as memory`);\n } catch (error) {\n logger.error(\n \"AgentMBox: Error processing new email: \" +\n (error instanceof Error ? error.message : \"Unknown error\"),\n );\n }\n }\n\n async stop(): Promise<void> {\n this.stopPolling();\n logger.info(\"AgentMBox service stopped\");\n }\n\n private async request<T>(\n endpoint: string,\n options: RequestInit = {},\n ): Promise<T> {\n if (!this.apiKey) {\n throw new Error(\n \"AgentMBox API key not configured. Ensure onboarding has completed or set AGENTMBOX_API_KEY.\",\n );\n }\n\n const url = `${this.baseUrl}${endpoint}`;\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n ...(options.headers as Record<string, string>),\n };\n\n const response = await fetch(url, { ...options, headers });\n const data = await response.json();\n\n if (!response.ok) {\n if (isAgentMBoxError(data)) {\n throw new Error(\n `AgentMBox API error (${response.status}): ${data.error}`,\n );\n }\n throw new Error(`AgentMBox API error: ${response.status}`);\n }\n\n return data as T;\n }\n\n private getMailboxParam(): string {\n if (!this.mailbox) {\n throw new Error(\"Mailbox not configured\");\n }\n return \"?mailbox=\" + encodeURIComponent(this.mailbox);\n }\n\n async listEmails(limit = 50, offset = 0): Promise<EmailListResponse> {\n const mailboxParam = this.getMailboxParam();\n return this.request<EmailListResponse>(\n \"/mail\" + mailboxParam + \"&limit=\" + limit + \"&offset=\" + offset,\n );\n }\n\n async getEmail(emailId: string): Promise<EmailDetailResponse> {\n const mailboxParam = this.getMailboxParam();\n return this.request<EmailDetailResponse>(\"/mail/\" + emailId + mailboxParam);\n }\n\n async sendEmail(request: SendEmailRequest): Promise<SendEmailResponse> {\n const from = request.from || this.mailbox;\n if (!from) {\n throw new Error(\"Sender address not specified\");\n }\n\n return this.request<SendEmailResponse>(\"/mail/send\", {\n method: \"POST\",\n body: JSON.stringify({ ...request, from }),\n });\n }\n\n async deleteEmail(emailId: string): Promise<{ success: boolean }> {\n const mailboxParam = this.getMailboxParam();\n return this.request<{ success: boolean }>(\n \"/mail/\" + emailId + mailboxParam,\n {\n method: \"DELETE\",\n },\n );\n }\n\n async markAsRead(emailId: string): Promise<{ success: boolean }> {\n const mailboxParam = this.getMailboxParam();\n return this.request<{ success: boolean }>(\n \"/mail/\" + emailId + \"/read\" + mailboxParam,\n {\n method: \"POST\",\n },\n );\n }\n\n async listMailboxes(): Promise<MailboxListResponse> {\n return this.request<MailboxListResponse>(\"/mailboxes\");\n }\n\n async createMailbox(\n request: CreateMailboxRequest,\n ): Promise<CreateMailboxResponse> {\n return this.request<CreateMailboxResponse>(\"/mailboxes\", {\n method: \"POST\",\n body: JSON.stringify(request),\n });\n }\n\n async deleteMailbox(mailboxId: string): Promise<{ success: boolean }> {\n return this.request<{ success: boolean }>(\"/mailboxes/\" + mailboxId, {\n method: \"DELETE\",\n });\n }\n\n async getPaymentStatus(): Promise<PaymentStatus> {\n return this.request<PaymentStatus>(\"/payment\");\n }\n\n async checkPayment(): Promise<PaymentCheckResponse> {\n return this.request<PaymentCheckResponse>(\"/payment/check\", {\n method: \"POST\",\n });\n }\n\n async listDomains(): Promise<DomainListResponse> {\n return this.request<DomainListResponse>(\"/domains\");\n }\n\n async addDomain(domain: string): Promise<DomainResponse> {\n return this.request<DomainResponse>(\"/domains\", {\n method: \"POST\",\n body: JSON.stringify({ domain }),\n });\n }\n\n async verifyDomain(domainId: string): Promise<DomainVerifyResponse> {\n return this.request<DomainVerifyResponse>(\n \"/domains/\" + domainId + \"/verify\",\n {\n method: \"POST\",\n },\n );\n }\n\n async deleteDomain(domainId: string): Promise<{ success: boolean }> {\n return this.request<{ success: boolean }>(\"/domains/\" + domainId, {\n method: \"DELETE\",\n });\n }\n\n async createApiKey(name: string): Promise<ApiKeyResponse> {\n return this.request<ApiKeyResponse>(\"/keys\", {\n method: \"POST\",\n body: JSON.stringify({ name }),\n });\n }\n\n async getStatus(): Promise<{ paid: boolean; paidUntil: string | null }> {\n try {\n const status = await this.getPaymentStatus();\n return { paid: status.paid, paidUntil: status.paidUntil };\n } catch (error) {\n logger.error(\"Failed to get AgentMBox status\");\n return { paid: false, paidUntil: null };\n }\n }\n\n /**\n * Manually trigger a check for new emails\n */\n async checkNow(): Promise<void> {\n await this.checkForNewEmails();\n }\n}\n\nexport default AgentMBoxService;\n","/**\n * AgentMBox Plugin Types\n * TypeScript interfaces for AgentMBox email integration\n */\n\nexport interface AgentMBoxConfig {\n /** API key for AgentMBox (starts with ai_) */\n apiKey: string;\n /** Mailbox address (e.g., my-agent@agentmbox.com) */\n mailbox?: string;\n /** Base URL for AgentMBox API (default: https://agentmbox.com/api/v1) */\n baseUrl?: string;\n}\n\nexport interface EmailAddress {\n name?: string;\n email: string;\n}\n\nexport interface Email {\n id: string;\n from: EmailAddress[];\n to: EmailAddress[];\n cc?: EmailAddress[] | null;\n subject: string;\n receivedAt: string;\n textBody?: string;\n htmlBody?: string;\n preview?: string;\n hasAttachment: boolean;\n isRead: boolean;\n}\n\nexport interface EmailListResponse {\n mailbox: string;\n emails: Email[];\n limit: number;\n offset: number;\n}\n\nexport interface EmailDetailResponse {\n email: Email;\n}\n\nexport interface SendEmailRequest {\n /** Sender address (must be a mailbox you own) */\n from: string;\n /** Recipient(s) - single email or array */\n to: string | string[];\n /** Email subject line */\n subject: string;\n /** Plain text body */\n text?: string;\n /** HTML body */\n html?: string;\n}\n\nexport interface SendEmailResponse {\n success: boolean;\n}\n\nexport interface Mailbox {\n id: string;\n address: string;\n localPart: string;\n domainName: string;\n displayName?: string | null;\n password?: string; // Only shown at creation\n createdAt: string;\n}\n\nexport interface MailboxListResponse {\n mailboxes: Mailbox[];\n}\n\nexport interface CreateMailboxRequest {\n localPart: string;\n domainId?: string;\n displayName?: string;\n}\n\nexport interface CreateMailboxResponse {\n mailbox: Mailbox;\n}\n\nexport interface PaymentStatus {\n paid: boolean;\n paidUntil: string | null;\n solanaAddress: string;\n usdcPerPeriod: number;\n periodDays: number;\n creditedUsdc: number;\n payments: unknown[];\n}\n\nexport interface PaymentCheckResponse {\n paid: boolean;\n paidUntil: string;\n newCredits: number;\n balanceUsdc: number;\n creditedUsdc: number;\n}\n\nexport interface Domain {\n id: string;\n domain: string;\n verified: boolean;\n}\n\nexport interface DomainDNSRecords {\n verification: { type: string; name: string; value: string };\n mx: { type: string; name: string; value: string; priority: number };\n spf: { type: string; name: string; value: string };\n dkim: { type: string; name: string; value: string };\n}\n\nexport interface DomainResponse {\n domain: Domain;\n dnsRecords: DomainDNSRecords;\n}\n\nexport interface DomainVerifyResponse {\n verified: boolean;\n txtVerified: boolean;\n mxVerified: boolean;\n spfVerified: boolean;\n dkimVerified: boolean;\n}\n\nexport interface DomainListResponse {\n domains: (Domain & { dnsRecords?: DomainDNSRecords })[];\n}\n\nexport interface ApiKey {\n id: string;\n name: string;\n key: string;\n keyPrefix: string;\n}\n\nexport interface ApiKeyResponse {\n id: string;\n name: string;\n key: string;\n keyPrefix: string;\n}\n\nexport interface ApiKeyListResponse {\n keys: ApiKey[];\n}\n\nexport interface AgentMBoxError {\n error: string;\n}\n\nexport type AgentMBoxErrorCode = 400 | 401 | 402 | 403 | 404 | 409 | 502;\n\nexport function isAgentMBoxError(\n response: unknown,\n): response is AgentMBoxError {\n return (\n typeof response === \"object\" &&\n response !== null &&\n \"error\" in response &&\n typeof (response as AgentMBoxError).error === \"string\"\n );\n}\n","/**\n * Send Email Action\n * Allows the agent to send emails via AgentMBox\n */\n\nimport {\n type Action,\n type HandlerCallback,\n type IAgentRuntime,\n type Memory,\n type State,\n type ActionExample,\n} from \"@elizaos/core\";\nimport { AgentMBoxService } from \"../services/AgentMBoxService\";\n\nexport const sendEmailAction: Action = {\n name: \"SEND_EMAIL\",\n description: \"Send an email to a recipient using AgentMBox email service\",\n handler: async (\n runtime: IAgentRuntime,\n message: Memory,\n state: State,\n options: Record<string, unknown>,\n callback?: HandlerCallback\n ) => {\n const service = runtime.getService<AgentMBoxService>(\"agentmbox\");\n if (!service) {\n throw new Error(\"AgentMBox service not initialized\");\n }\n\n const { to, subject, text, html } = options;\n\n if (!to) {\n throw new Error(\"Missing required field: 'to' (recipient email)\");\n }\n\n if (!subject) {\n throw new Error(\"Missing required field: 'subject'\");\n }\n\n const from = options.from as string | undefined;\n\n try {\n const result = await service.sendEmail({\n from,\n to: Array.isArray(to) ? to : to,\n subject,\n text: text as string | undefined,\n html: html as string | undefined,\n });\n\n if (callback) {\n await callback({\n text: `Email sent successfully to ${to}`,\n values: {\n success: result.success,\n recipient: to,\n subject,\n },\n });\n }\n\n return {\n success: true,\n values: {\n sentTo: to,\n subject,\n },\n };\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : \"Unknown error\";\n logger.error(\"Failed to send email\", { error: errorMessage });\n\n if (callback) {\n await callback({\n text: `Failed to send email: ${errorMessage}`,\n values: {\n success: false,\n error: errorMessage,\n },\n });\n }\n\n return {\n success: false,\n error: errorMessage,\n };\n }\n },\n validate: async (runtime: IAgentRuntime) => {\n try {\n const service = runtime.getService<AgentMBoxService>(\"agentmbox\");\n return !!service;\n } catch {\n return false;\n }\n },\n examples: [\n [\n {\n name: \"user\",\n content: \"Send an email to john@example.com about the project update\",\n },\n {\n name: \"assistant\",\n content: \"I'll send that email for you.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"Email the team that the meeting is at 3pm\",\n },\n {\n name: \"assistant\",\n content: \"Sending that email now.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"Can you notify alice@example.com that the report is ready?\",\n },\n {\n name: \"assistant\",\n content: \"I'll send her an email right away.\",\n },\n ],\n ] as ActionExample[][],\n};\n\nexport default sendEmailAction;\n","/**\n * Get Emails Action\n * Allows the agent to retrieve emails from the mailbox via AgentMBox\n */\n\nimport {\n type Action,\n type HandlerCallback,\n type IAgentRuntime,\n type Memory,\n type State,\n type ActionExample,\n} from \"@elizaos/core\";\nimport { AgentMBoxService } from \"../services/AgentMBoxService\";\n\nexport const getEmailsAction: Action = {\n name: \"GET_EMAILS\",\n description: \"Retrieve emails from the AgentMBox mailbox. Can filter by read status and limit results.\",\n handler: async (\n runtime: IAgentRuntime,\n message: Memory,\n state: State,\n options: Record<string, unknown>,\n callback?: HandlerCallback\n ) => {\n const service = runtime.getService<AgentMBoxService>(\"agentmbox\");\n if (!service) {\n throw new Error(\"AgentMBox service not initialized\");\n }\n\n const limit = (options.limit as number) || 10;\n const offset = (options.offset as number) || 0;\n const emailId = options.emailId as string | undefined;\n\n try {\n // If emailId is provided, get a specific email\n if (emailId) {\n const emailDetail = await service.getEmail(emailId);\n\n if (callback) {\n await callback({\n text: `Retrieved email: ${emailDetail.email.subject}`,\n values: {\n email: emailDetail.email,\n },\n });\n }\n\n return {\n success: true,\n values: {\n email: emailDetail.email,\n },\n };\n }\n\n // Otherwise, list emails\n const emailList = await service.listEmails(limit, offset);\n\n // Filter by read status if specified\n let emails = emailList.emails;\n const unreadOnly = options.unreadOnly as boolean;\n if (unreadOnly) {\n emails = emails.filter((email) => !email.isRead);\n }\n\n if (callback) {\n const preview = emails\n .slice(0, 5)\n .map((e) => `- ${e.subject} from ${e.from[0]?.email}`)\n .join(\"\\n\");\n await callback({\n text: `Found ${emails.length} emails:\\n${preview}`,\n values: {\n emails: emails,\n total: emailList.emails.length,\n unread: emailList.emails.filter((e) => !e.isRead).length,\n },\n });\n }\n\n return {\n success: true,\n values: {\n emails: emails,\n total: emailList.emails.length,\n limit: emailList.limit,\n offset: emailList.offset,\n },\n };\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : \"Unknown error\";\n logger.error(\"Failed to get emails\", { error: errorMessage });\n\n if (callback) {\n await callback({\n text: `Failed to get emails: ${errorMessage}`,\n values: {\n success: false,\n error: errorMessage,\n },\n });\n }\n\n return {\n success: false,\n error: errorMessage,\n };\n }\n },\n validate: async (runtime: IAgentRuntime) => {\n try {\n const service = runtime.getService<AgentMBoxService>(\"agentmbox\");\n return !!service;\n } catch {\n return false;\n }\n },\n examples: [\n [\n {\n name: \"user\",\n content: \"Check my inbox for any new emails\",\n },\n {\n name: \"assistant\",\n content: \"Let me check your inbox for new emails.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"Show me the last 5 emails I received\",\n },\n {\n name: \"assistant\",\n content: \"I'll retrieve your recent emails.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"Get the details of that email about the meeting\",\n },\n {\n name: \"assistant\",\n content: \"Let me fetch that email for you.\",\n },\n ],\n ] as ActionExample[][],\n};\n\nexport default getEmailsAction;\n","/**\n * Onboarding Action\n * Allows the agent to self-onboard with AgentMBox - creates account, pays for subscription, sets up mailbox\n * Based on: https://www.agentmbox.com/llm.txt\n */\n\nimport {\n type Action,\n type HandlerCallback,\n type IAgentRuntime,\n type Memory,\n type State,\n type ActionExample,\n logger,\n} from \"@elizaos/core\";\n\ninterface OnboardingStatus {\n stage:\n | \"pending\"\n | \"account_created\"\n | \"api_key_created\"\n | \"awaiting_payment\"\n | \"paid\"\n | \"mailbox_created\"\n | \"complete\"\n | \"error\";\n paymentAddress?: string;\n mailbox?: string;\n error?: string;\n}\n\nconst BASE_URL = \"https://agentmbox.com/api/v1\";\nconst USDC_MINT = \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGZwyTDt1v\";\nconst PAYMENT_AMOUNT = 5_000_000; // 5 USDC in lamports\n\nfunction generatePassword(length: number = 32): string {\n const chars =\n \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*\";\n let password = \"\";\n const array = new Uint8Array(length);\n crypto.getRandomValues(array);\n for (let i = 0; i < length; i++) {\n password += chars[array[i] % chars.length];\n }\n return password;\n}\n\nasync function getAgentWallet(runtime: IAgentRuntime) {\n try {\n const privateKeyBase58 = String(\n runtime.getSetting(\"SOLANA_PRIVATE_KEY\") || \"\",\n );\n if (privateKeyBase58) {\n const { default: bs58 } = await import(\"bs58\");\n const { Keypair } = await import(\"@solana/web3.js\");\n const privateKey = bs58.decode(privateKeyBase58);\n const keypair = Keypair.fromSecretKey(privateKey);\n return {\n publicKey: keypair.publicKey.toBase58(),\n privateKey,\n };\n }\n\n const walletService = await runtime.getService(\"wallet\");\n if (walletService) {\n const keypair = await (walletService as any).getKeypair?.();\n if (keypair) {\n return {\n publicKey: keypair.publicKey.toBase58(),\n privateKey: keypair.secretKey,\n };\n }\n }\n } catch (error) {\n logger.warn(\"Could not get agent wallet\");\n }\n return null;\n}\n\nexport const onboardingAction: Action = {\n name: \"AGENTMBOX_ONBOARDING\",\n description:\n \"Set up AgentMBox email for the agent - creates an account, pays 5 USDC on Solana, and creates a mailbox. The agent needs a Solana wallet with USDC to pay for the subscription.\",\n\n handler: async (\n runtime: IAgentRuntime,\n _message: Memory,\n _state: State,\n _options: Record<string, unknown>,\n callback?: HandlerCallback,\n ) => {\n // Check if already onboarded\n const existingApiKey = runtime.getSetting(\"AGENTMBOX_API_KEY\");\n const existingMailbox = runtime.getSetting(\"AGENTMBOX_MAILBOX\");\n\n if (existingApiKey && existingMailbox) {\n const msg = `Already onboarded! Mailbox: ${existingMailbox}`;\n logger.info(msg);\n if (callback) {\n await callback({\n text: msg,\n values: { success: true, mailbox: existingMailbox },\n });\n }\n return { success: true, mailbox: existingMailbox };\n }\n\n let status: OnboardingStatus = { stage: \"pending\" };\n let apiKey = \"\";\n let mailboxAddress = \"\";\n\n try {\n // Step 1: Create account\n const agentName =\n runtime.character?.name?.toLowerCase().replace(/\\s+/g, \"-\") || \"agent\";\n const ownerEmail =\n String(runtime.getSetting(\"AGENTMBOX_OWNER_EMAIL\")) ||\n `agent-${agentName}@owner.local`;\n const password = generatePassword(32);\n\n logger.info(\"AgentMBox: Creating account...\");\n const signupResponse = await fetch(`${BASE_URL}/auth/signup`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ email: ownerEmail, password }),\n });\n\n if (!signupResponse.ok) {\n const error = await signupResponse.json();\n throw new Error(`Account creation failed: ${error.error}`);\n }\n\n const signupData = await signupResponse.json();\n status = { stage: \"account_created\" };\n logger.info(\"AgentMBox: Account created\");\n\n // Step 2: Create API key\n logger.info(\"AgentMBox: Creating API key...\");\n const keyResponse = await fetch(`${BASE_URL}/keys`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ name: `${agentName}-key` }),\n credentials: \"include\",\n });\n\n if (!keyResponse.ok) {\n const error = await keyResponse.json();\n throw new Error(`API key creation failed: ${error.error}`);\n }\n\n const keyData = await keyResponse.json();\n apiKey = keyData.key;\n status = { stage: \"api_key_created\" };\n logger.info(\"AgentMBox: API key created\");\n\n // Step 3: Get payment address\n logger.info(\"AgentMBox: Getting payment address...\");\n const paymentResponse = await fetch(`${BASE_URL}/payment`, {\n headers: { Authorization: `Bearer ${apiKey}` },\n });\n\n if (!paymentResponse.ok) {\n const error = await paymentResponse.json();\n throw new Error(`Payment status failed: ${error.error}`);\n }\n\n const paymentData = await paymentResponse.json();\n status = {\n stage: \"awaiting_payment\",\n paymentAddress: paymentData.solanaAddress,\n };\n\n if (callback) {\n await callback({\n text: `Account created! Payment required: Please send 5 USDC to ${paymentData.solanaAddress}`,\n values: {\n success: false,\n stage: \"awaiting_payment\",\n paymentAddress: paymentData.solanaAddress,\n },\n });\n }\n\n // Step 4: Pay for subscription (if wallet available)\n const wallet = await getAgentWallet(runtime);\n\n if (!wallet) {\n const msg = `Payment required! Please send 5 USDC to: ${paymentData.solanaAddress}`;\n logger.warn(msg);\n return {\n success: false,\n stage: \"awaiting_payment\",\n paymentAddress: paymentData.solanaAddress,\n message: msg,\n };\n }\n\n logger.info(\"AgentMBox: Attempting to pay for subscription...\");\n\n try {\n const { Connection, Keypair, PublicKey } =\n await import(\"@solana/web3.js\");\n const { transfer, getOrCreateAssociatedTokenAccount } =\n await import(\"@solana/spl-token\");\n\n const connection = new Connection(\n \"https://api.mainnet-beta.solana.com\",\n );\n const signer = Keypair.fromSecretKey(wallet.privateKey);\n const toPublicKey = new PublicKey(paymentData.solanaAddress);\n\n const fromTokenAccount = await getOrCreateAssociatedTokenAccount(\n connection,\n signer,\n new PublicKey(USDC_MINT),\n signer.publicKey,\n );\n\n const toTokenAccount = await getOrCreateAssociatedTokenAccount(\n connection,\n signer,\n new PublicKey(USDC_MINT),\n toPublicKey,\n );\n\n await transfer(\n connection,\n signer,\n fromTokenAccount.address,\n toTokenAccount.address,\n signer.publicKey,\n PAYMENT_AMOUNT,\n );\n\n logger.info(\"AgentMBox: USDC transfer complete\");\n } catch (transferError) {\n logger.error(\"USDC transfer failed:\", transferError);\n const msg = `Payment required! Please send 5 USDC to: ${paymentData.solanaAddress}`;\n return {\n success: false,\n stage: \"awaiting_payment\",\n paymentAddress: paymentData.solanaAddress,\n message: msg,\n };\n }\n\n // Step 5: Confirm payment\n logger.info(\"AgentMBox: Checking payment...\");\n let paid = false;\n for (let i = 0; i < 12 && !paid; i++) {\n await new Promise((resolve) => setTimeout(resolve, 5000));\n try {\n const checkResponse = await fetch(`${BASE_URL}/payment/check`, {\n method: \"POST\",\n headers: { Authorization: `Bearer ${apiKey}` },\n });\n const checkData = await checkResponse.json();\n paid = checkData.paid;\n if (paid) {\n status = { stage: \"paid\" };\n logger.info(\"AgentMBox: Payment confirmed\");\n }\n } catch {\n // Continue polling\n }\n }\n\n if (!paid) {\n throw new Error(\"Payment not confirmed after 60 seconds\");\n }\n\n // Step 6: Create mailbox\n logger.info(\"AgentMBox: Creating mailbox...\");\n const mailboxResponse = await fetch(`${BASE_URL}/mailboxes`, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n localPart: agentName,\n displayName: runtime.character?.name || agentName,\n }),\n });\n\n if (!mailboxResponse.ok) {\n const error = await mailboxResponse.json();\n throw new Error(`Mailbox creation failed: ${error.error}`);\n }\n\n const mailboxData = await mailboxResponse.json();\n mailboxAddress = mailboxData.mailbox.address;\n status = {\n stage: \"complete\",\n mailbox: mailboxAddress,\n };\n\n logger.info(`AgentMBox: Mailbox created: ${mailboxAddress}`);\n\n // Save credentials to runtime settings\n runtime.setSetting(\"AGENTMBOX_API_KEY\", apiKey, true);\n runtime.setSetting(\"AGENTMBOX_MAILBOX\", mailboxAddress);\n\n if (callback) {\n await callback({\n text: `Onboarding complete! Mailbox: ${mailboxAddress}`,\n values: {\n success: true,\n mailbox: mailboxAddress,\n },\n });\n }\n\n return { success: true, mailbox: mailboxAddress };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : \"Unknown error\";\n logger.error(\"AgentMBox onboarding failed: \" + errorMessage);\n status = { stage: \"error\", error: errorMessage };\n\n if (callback) {\n await callback({\n text: \"Onboarding failed: \" + errorMessage,\n values: { success: false, error: errorMessage },\n });\n }\n\n return { success: false, error: errorMessage };\n }\n },\n\n validate: async (_runtime: IAgentRuntime) => {\n // Always valid - onboarding can be attempted\n return true;\n },\n\n examples: [\n [\n {\n name: \"user\",\n content: \"Set up email for this agent\",\n },\n {\n name: \"assistant\",\n content:\n \"I'll set up AgentMBox email for you. This will create an account and pay 5 USDC from the agent's wallet.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"I need to configure the email service\",\n },\n {\n name: \"assistant\",\n content: \"Starting the AgentMBox onboarding process now.\",\n },\n ],\n [\n {\n name: \"user\",\n content: \"Can you set up a mailbox for receiving emails?\",\n },\n {\n name: \"assistant\",\n content: \"On it! I'll create the mailbox and handle the payment.\",\n },\n ],\n ] as ActionExample[][],\n};\n\nexport default onboardingAction;\n","/**\n * Email Provider\n * Provides email context to the agent, including unread counts and recent emails\n */\n\nimport {\n type Provider,\n type IAgentRuntime,\n type Memory,\n type State,\n type ProviderResult,\n} from \"@elizaos/core\";\nimport { AgentMBoxService } from \"../services/AgentMBoxService\";\n\nexport const emailProvider: Provider = {\n name: \"email\",\n description: \"Provides email context from AgentMBox including unread counts and recent messages\",\n get: async (\n runtime: IAgentRuntime,\n message: Memory,\n _state: State\n ): Promise<ProviderResult> => {\n try {\n const service = runtime.getService<AgentMBoxService>(\"agentmbox\");\n if (!service) {\n return {\n text: \"Email service not available\",\n values: {\n available: false,\n },\n };\n }\n\n // Get recent emails\n const emailList = await service.listEmails(10, 0);\n const unreadCount = emailList.emails.filter((e) => !e.isRead).length;\n const recentEmails = emailList.emails.slice(0, 5);\n\n // Format recent emails for context\n const recentEmailsText = recentEmails\n .map(\n (email) =>\n `- From: ${email.from[0]?.name || email.from[0]?.email || \"Unknown\"} | Subject: ${email.subject}${\n !email.isRead ? \" [UNREAD]\" : \"\"\n }`\n )\n .join(\"\\n\");\n\n return {\n text: `Email Status: ${unreadCount} unread of ${emailList.emails.length} total${\n recentEmails.length > 0\n ? `\\n\\nRecent Emails:\\n${recentEmailsText}`\n : \"\\n\\nNo recent emails.\"\n }`,\n values: {\n available: true,\n unreadCount,\n totalEmails: emailList.emails.length,\n recentEmails: recentEmails.map((e) => ({\n id: e.id,\n from: e.from[0],\n subject: e.subject,\n preview: e.preview,\n isRead: e.isRead,\n receivedAt: e.receivedAt,\n })),\n },\n };\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : \"Unknown error\";\n return {\n text: `Email service error: ${errorMessage}`,\n values: {\n available: false,\n error: errorMessage,\n },\n };\n }\n },\n};\n\nexport default emailProvider;\n","/**\n * AgentMBox Plugin for ElizaOS\n * Email integration plugin that enables AI agents to send and receive emails\n * Includes email polling for incoming emails\n */\n\nimport type { Plugin } from \"@elizaos/core\";\nimport { AgentMBoxService } from \"./services/AgentMBoxService\";\nimport { sendEmailAction } from \"./actions/sendEmail\";\nimport { getEmailsAction } from \"./actions/getEmails\";\nimport { onboardingAction } from \"./actions/onboarding\";\nimport { emailProvider } from \"./providers/emailProvider\";\n\nexport const agentMBoxPlugin: Plugin = {\n name: \"agentmbox\",\n description:\n \"AgentMBox email integration plugin for ElizaOS - enables AI agents to send/receive emails with email polling\",\n priority: 0,\n config: {\n baseUrl: \"https://agentmbox.com/api/v1\",\n pollingInterval: 300000, // 5 minutes\n },\n actions: [sendEmailAction, getEmailsAction, onboardingAction],\n providers: [emailProvider],\n services: [AgentMBoxService],\n};\n\nexport default agentMBoxPlugin;\n\n// Re-export for convenience\nexport { AgentMBoxService } from \"./services/AgentMBoxService\";\nexport * from \"./types\";\n"],"mappings":";AAAA,SAAS,SAA6B,UAAAA,eAAc;;;AC6J7C,SAAS,iBACd,UAC4B;AAC5B,SACE,OAAO,aAAa,YACpB,aAAa,QACb,WAAW,YACX,OAAQ,SAA4B,UAAU;AAElD;;;ADnJA,IAAM,2BAA2B;AAE1B,IAAM,mBAAN,MAAM,0BAAyB,QAAQ;AA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