@agentmbox/plugin-agentmbox 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -13
- package/dist/index.js +25 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/bun.lock +0 -659
- package/src/actions/getEmails.ts +0 -153
- package/src/actions/sendEmail.ts +0 -132
- package/src/index.ts +0 -95
- package/src/providers/emailProvider.ts +0 -82
- package/src/services/AgentMBoxOnboardingService.ts +0 -447
- package/src/services/AgentMBoxService.ts +0 -194
- package/src/types/index.ts +0 -167
- package/tsconfig.json +0 -20
package/src/actions/getEmails.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get Emails Action
|
|
3
|
-
* Allows the agent to retrieve emails from the mailbox via AgentMBox
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
type Action,
|
|
8
|
-
type HandlerCallback,
|
|
9
|
-
type IAgentRuntime,
|
|
10
|
-
type Memory,
|
|
11
|
-
type State,
|
|
12
|
-
type ActionExample,
|
|
13
|
-
} from "@elizaos/core";
|
|
14
|
-
import { AgentMBoxService } from "../services/AgentMBoxService";
|
|
15
|
-
|
|
16
|
-
export const getEmailsAction: Action = {
|
|
17
|
-
name: "GET_EMAILS",
|
|
18
|
-
description: "Retrieve emails from the AgentMBox mailbox. Can filter by read status and limit results.",
|
|
19
|
-
handler: async (
|
|
20
|
-
runtime: IAgentRuntime,
|
|
21
|
-
message: Memory,
|
|
22
|
-
state: State,
|
|
23
|
-
options: Record<string, unknown>,
|
|
24
|
-
callback?: HandlerCallback
|
|
25
|
-
) => {
|
|
26
|
-
const service = runtime.getService<AgentMBoxService>("agentmbox");
|
|
27
|
-
if (!service) {
|
|
28
|
-
throw new Error("AgentMBox service not initialized");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const limit = (options.limit as number) || 10;
|
|
32
|
-
const offset = (options.offset as number) || 0;
|
|
33
|
-
const emailId = options.emailId as string | undefined;
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
// If emailId is provided, get a specific email
|
|
37
|
-
if (emailId) {
|
|
38
|
-
const emailDetail = await service.getEmail(emailId);
|
|
39
|
-
|
|
40
|
-
if (callback) {
|
|
41
|
-
await callback({
|
|
42
|
-
text: `Retrieved email: ${emailDetail.email.subject}`,
|
|
43
|
-
values: {
|
|
44
|
-
email: emailDetail.email,
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
success: true,
|
|
51
|
-
values: {
|
|
52
|
-
email: emailDetail.email,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Otherwise, list emails
|
|
58
|
-
const emailList = await service.listEmails(limit, offset);
|
|
59
|
-
|
|
60
|
-
// Filter by read status if specified
|
|
61
|
-
let emails = emailList.emails;
|
|
62
|
-
const unreadOnly = options.unreadOnly as boolean;
|
|
63
|
-
if (unreadOnly) {
|
|
64
|
-
emails = emails.filter((email) => !email.isRead);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (callback) {
|
|
68
|
-
const preview = emails
|
|
69
|
-
.slice(0, 5)
|
|
70
|
-
.map((e) => `- ${e.subject} from ${e.from[0]?.email}`)
|
|
71
|
-
.join("\n");
|
|
72
|
-
await callback({
|
|
73
|
-
text: `Found ${emails.length} emails:\n${preview}`,
|
|
74
|
-
values: {
|
|
75
|
-
emails: emails,
|
|
76
|
-
total: emailList.emails.length,
|
|
77
|
-
unread: emailList.emails.filter((e) => !e.isRead).length,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
success: true,
|
|
84
|
-
values: {
|
|
85
|
-
emails: emails,
|
|
86
|
-
total: emailList.emails.length,
|
|
87
|
-
limit: emailList.limit,
|
|
88
|
-
offset: emailList.offset,
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
} catch (error) {
|
|
92
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
93
|
-
logger.error("Failed to get emails", { error: errorMessage });
|
|
94
|
-
|
|
95
|
-
if (callback) {
|
|
96
|
-
await callback({
|
|
97
|
-
text: `Failed to get emails: ${errorMessage}`,
|
|
98
|
-
values: {
|
|
99
|
-
success: false,
|
|
100
|
-
error: errorMessage,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
success: false,
|
|
107
|
-
error: errorMessage,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
validate: async (runtime: IAgentRuntime) => {
|
|
112
|
-
try {
|
|
113
|
-
const service = runtime.getService<AgentMBoxService>("agentmbox");
|
|
114
|
-
return !!service;
|
|
115
|
-
} catch {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
examples: [
|
|
120
|
-
[
|
|
121
|
-
{
|
|
122
|
-
name: "user",
|
|
123
|
-
content: "Check my inbox for any new emails",
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
name: "assistant",
|
|
127
|
-
content: "Let me check your inbox for new emails.",
|
|
128
|
-
},
|
|
129
|
-
],
|
|
130
|
-
[
|
|
131
|
-
{
|
|
132
|
-
name: "user",
|
|
133
|
-
content: "Show me the last 5 emails I received",
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
name: "assistant",
|
|
137
|
-
content: "I'll retrieve your recent emails.",
|
|
138
|
-
},
|
|
139
|
-
],
|
|
140
|
-
[
|
|
141
|
-
{
|
|
142
|
-
name: "user",
|
|
143
|
-
content: "Get the details of that email about the meeting",
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
name: "assistant",
|
|
147
|
-
content: "Let me fetch that email for you.",
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
] as ActionExample[][],
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
export default getEmailsAction;
|
package/src/actions/sendEmail.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Send Email Action
|
|
3
|
-
* Allows the agent to send emails via AgentMBox
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
type Action,
|
|
8
|
-
type HandlerCallback,
|
|
9
|
-
type IAgentRuntime,
|
|
10
|
-
type Memory,
|
|
11
|
-
type State,
|
|
12
|
-
type ActionExample,
|
|
13
|
-
} from "@elizaos/core";
|
|
14
|
-
import { AgentMBoxService } from "../services/AgentMBoxService";
|
|
15
|
-
|
|
16
|
-
export const sendEmailAction: Action = {
|
|
17
|
-
name: "SEND_EMAIL",
|
|
18
|
-
description: "Send an email to a recipient using AgentMBox email service",
|
|
19
|
-
handler: async (
|
|
20
|
-
runtime: IAgentRuntime,
|
|
21
|
-
message: Memory,
|
|
22
|
-
state: State,
|
|
23
|
-
options: Record<string, unknown>,
|
|
24
|
-
callback?: HandlerCallback
|
|
25
|
-
) => {
|
|
26
|
-
const service = runtime.getService<AgentMBoxService>("agentmbox");
|
|
27
|
-
if (!service) {
|
|
28
|
-
throw new Error("AgentMBox service not initialized");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const { to, subject, text, html } = options;
|
|
32
|
-
|
|
33
|
-
if (!to) {
|
|
34
|
-
throw new Error("Missing required field: 'to' (recipient email)");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!subject) {
|
|
38
|
-
throw new Error("Missing required field: 'subject'");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const from = options.from as string | undefined;
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const result = await service.sendEmail({
|
|
45
|
-
from,
|
|
46
|
-
to: Array.isArray(to) ? to : to,
|
|
47
|
-
subject,
|
|
48
|
-
text: text as string | undefined,
|
|
49
|
-
html: html as string | undefined,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (callback) {
|
|
53
|
-
await callback({
|
|
54
|
-
text: `Email sent successfully to ${to}`,
|
|
55
|
-
values: {
|
|
56
|
-
success: result.success,
|
|
57
|
-
recipient: to,
|
|
58
|
-
subject,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
success: true,
|
|
65
|
-
values: {
|
|
66
|
-
sentTo: to,
|
|
67
|
-
subject,
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
} catch (error) {
|
|
71
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
72
|
-
logger.error("Failed to send email", { error: errorMessage });
|
|
73
|
-
|
|
74
|
-
if (callback) {
|
|
75
|
-
await callback({
|
|
76
|
-
text: `Failed to send email: ${errorMessage}`,
|
|
77
|
-
values: {
|
|
78
|
-
success: false,
|
|
79
|
-
error: errorMessage,
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
success: false,
|
|
86
|
-
error: errorMessage,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
validate: async (runtime: IAgentRuntime) => {
|
|
91
|
-
try {
|
|
92
|
-
const service = runtime.getService<AgentMBoxService>("agentmbox");
|
|
93
|
-
return !!service;
|
|
94
|
-
} catch {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
examples: [
|
|
99
|
-
[
|
|
100
|
-
{
|
|
101
|
-
name: "user",
|
|
102
|
-
content: "Send an email to john@example.com about the project update",
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
name: "assistant",
|
|
106
|
-
content: "I'll send that email for you.",
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
[
|
|
110
|
-
{
|
|
111
|
-
name: "user",
|
|
112
|
-
content: "Email the team that the meeting is at 3pm",
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
name: "assistant",
|
|
116
|
-
content: "Sending that email now.",
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
[
|
|
120
|
-
{
|
|
121
|
-
name: "user",
|
|
122
|
-
content: "Can you notify alice@example.com that the report is ready?",
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: "assistant",
|
|
126
|
-
content: "I'll send her an email right away.",
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
] as ActionExample[][],
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export default sendEmailAction;
|
package/src/index.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentMBox Plugin for ElizaOS
|
|
3
|
-
* Email integration plugin that enables AI agents to send and receive emails
|
|
4
|
-
* Includes autonomous self-onboarding using the agent's Solana wallet
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { Plugin, IAgentRuntime } from "@elizaos/core";
|
|
8
|
-
import { logger } from "@elizaos/core";
|
|
9
|
-
import { AgentMBoxService } from "./services/AgentMBoxService";
|
|
10
|
-
import { AgentMBoxOnboardingService } from "./services/AgentMBoxOnboardingService";
|
|
11
|
-
import { sendEmailAction } from "./actions/sendEmail";
|
|
12
|
-
import { getEmailsAction } from "./actions/getEmails";
|
|
13
|
-
import { emailProvider } from "./providers/emailProvider";
|
|
14
|
-
|
|
15
|
-
export const agentMBoxPlugin: Plugin = {
|
|
16
|
-
name: "agentmbox",
|
|
17
|
-
description:
|
|
18
|
-
"AgentMBox email integration plugin for ElizaOS - enables AI agents to send/receive emails with autonomous onboarding",
|
|
19
|
-
actions: [sendEmailAction, getEmailsAction],
|
|
20
|
-
providers: [emailProvider],
|
|
21
|
-
services: [AgentMBoxService, AgentMBoxOnboardingService],
|
|
22
|
-
init: async (config: Record<string, string>, runtime: IAgentRuntime) => {
|
|
23
|
-
logger.info("AgentMBox plugin initializing");
|
|
24
|
-
|
|
25
|
-
// Check if onboarding is needed
|
|
26
|
-
const existingApiKey = runtime.getSetting("AGENTMBOX_API_KEY");
|
|
27
|
-
const skipOnboarding =
|
|
28
|
-
runtime.getSetting("AGENTMBOX_SKIP_ONBOARDING") === "true";
|
|
29
|
-
|
|
30
|
-
if (!existingApiKey && !skipOnboarding) {
|
|
31
|
-
logger.info("Starting AgentMBox autonomous onboarding...");
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
const onboardingService =
|
|
35
|
-
runtime.getService<AgentMBoxOnboardingService>(
|
|
36
|
-
"agentmbox-onboarding",
|
|
37
|
-
);
|
|
38
|
-
if (onboardingService) {
|
|
39
|
-
const status = await onboardingService.startOnboarding(runtime);
|
|
40
|
-
|
|
41
|
-
if (status.stage === "complete" && status.mailbox) {
|
|
42
|
-
// Save credentials to runtime settings for persistence
|
|
43
|
-
const apiKey = onboardingService.getApiKey();
|
|
44
|
-
const mailbox = onboardingService.getMailbox();
|
|
45
|
-
if (apiKey) {
|
|
46
|
-
runtime.setSetting("AGENTMBOX_API_KEY", apiKey, true);
|
|
47
|
-
}
|
|
48
|
-
if (mailbox) {
|
|
49
|
-
runtime.setSetting("AGENTMBOX_MAILBOX", mailbox);
|
|
50
|
-
}
|
|
51
|
-
logger.info("Onboarding complete! Mailbox: " + status.mailbox);
|
|
52
|
-
} else if (
|
|
53
|
-
status.stage === "awaiting_payment" &&
|
|
54
|
-
status.paymentAddress
|
|
55
|
-
) {
|
|
56
|
-
logger.warn(
|
|
57
|
-
"Payment required. Please fund: " + status.paymentAddress,
|
|
58
|
-
);
|
|
59
|
-
logger.info("Required: 5 USDC on Solana + ~0.01 SOL for fees");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
} catch (error) {
|
|
63
|
-
const errorMsg =
|
|
64
|
-
error instanceof Error ? error.message : "Unknown error";
|
|
65
|
-
logger.error("Onboarding failed: " + errorMsg);
|
|
66
|
-
}
|
|
67
|
-
} else if (existingApiKey) {
|
|
68
|
-
logger.info("Using existing AgentMBox configuration");
|
|
69
|
-
} else {
|
|
70
|
-
logger.info("Onboarding skipped per configuration");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Initialize main email service (after onboarding has potentially saved credentials)
|
|
74
|
-
const emailService = runtime.getService<AgentMBoxService>("agentmbox");
|
|
75
|
-
if (emailService) {
|
|
76
|
-
try {
|
|
77
|
-
await emailService.initialize(runtime);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
const errorMsg =
|
|
80
|
-
error instanceof Error ? error.message : "Unknown error";
|
|
81
|
-
logger.error(
|
|
82
|
-
"Failed to initialize AgentMBox email service: " + errorMsg,
|
|
83
|
-
);
|
|
84
|
-
// Don't fail the whole plugin initialization - the service will be unavailable
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export default agentMBoxPlugin;
|
|
91
|
-
|
|
92
|
-
// Re-export for convenience
|
|
93
|
-
export { AgentMBoxService } from "./services/AgentMBoxService";
|
|
94
|
-
export { AgentMBoxOnboardingService } from "./services/AgentMBoxOnboardingService";
|
|
95
|
-
export * from "./types";
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Email Provider
|
|
3
|
-
* Provides email context to the agent, including unread counts and recent emails
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
type Provider,
|
|
8
|
-
type IAgentRuntime,
|
|
9
|
-
type Memory,
|
|
10
|
-
type State,
|
|
11
|
-
type ProviderResult,
|
|
12
|
-
} from "@elizaos/core";
|
|
13
|
-
import { AgentMBoxService } from "../services/AgentMBoxService";
|
|
14
|
-
|
|
15
|
-
export const emailProvider: Provider = {
|
|
16
|
-
name: "email",
|
|
17
|
-
description: "Provides email context from AgentMBox including unread counts and recent messages",
|
|
18
|
-
get: async (
|
|
19
|
-
runtime: IAgentRuntime,
|
|
20
|
-
message: Memory,
|
|
21
|
-
_state: State
|
|
22
|
-
): Promise<ProviderResult> => {
|
|
23
|
-
try {
|
|
24
|
-
const service = runtime.getService<AgentMBoxService>("agentmbox");
|
|
25
|
-
if (!service) {
|
|
26
|
-
return {
|
|
27
|
-
text: "Email service not available",
|
|
28
|
-
values: {
|
|
29
|
-
available: false,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Get recent emails
|
|
35
|
-
const emailList = await service.listEmails(10, 0);
|
|
36
|
-
const unreadCount = emailList.emails.filter((e) => !e.isRead).length;
|
|
37
|
-
const recentEmails = emailList.emails.slice(0, 5);
|
|
38
|
-
|
|
39
|
-
// Format recent emails for context
|
|
40
|
-
const recentEmailsText = recentEmails
|
|
41
|
-
.map(
|
|
42
|
-
(email) =>
|
|
43
|
-
`- From: ${email.from[0]?.name || email.from[0]?.email || "Unknown"} | Subject: ${email.subject}${
|
|
44
|
-
!email.isRead ? " [UNREAD]" : ""
|
|
45
|
-
}`
|
|
46
|
-
)
|
|
47
|
-
.join("\n");
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
text: `Email Status: ${unreadCount} unread of ${emailList.emails.length} total${
|
|
51
|
-
recentEmails.length > 0
|
|
52
|
-
? `\n\nRecent Emails:\n${recentEmailsText}`
|
|
53
|
-
: "\n\nNo recent emails."
|
|
54
|
-
}`,
|
|
55
|
-
values: {
|
|
56
|
-
available: true,
|
|
57
|
-
unreadCount,
|
|
58
|
-
totalEmails: emailList.emails.length,
|
|
59
|
-
recentEmails: recentEmails.map((e) => ({
|
|
60
|
-
id: e.id,
|
|
61
|
-
from: e.from[0],
|
|
62
|
-
subject: e.subject,
|
|
63
|
-
preview: e.preview,
|
|
64
|
-
isRead: e.isRead,
|
|
65
|
-
receivedAt: e.receivedAt,
|
|
66
|
-
})),
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
} catch (error) {
|
|
70
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
71
|
-
return {
|
|
72
|
-
text: `Email service error: ${errorMessage}`,
|
|
73
|
-
values: {
|
|
74
|
-
available: false,
|
|
75
|
-
error: errorMessage,
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export default emailProvider;
|