agentmail-toolkit 0.1.35 → 0.1.37
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/ai-sdk.cjs +48 -50
- package/dist/ai-sdk.cjs.map +1 -1
- package/dist/ai-sdk.d.cts +1 -1
- package/dist/ai-sdk.d.ts +1 -1
- package/dist/ai-sdk.js +2 -2
- package/dist/ai-sdk.js.map +1 -1
- package/dist/{chunk-4RMN5TYL.js → chunk-4T5LKBWD.js} +48 -50
- package/dist/chunk-4T5LKBWD.js.map +1 -0
- package/dist/index.cjs +48 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/langchain.cjs +50 -52
- package/dist/langchain.cjs.map +1 -1
- package/dist/langchain.d.cts +2 -2
- package/dist/langchain.d.ts +2 -2
- package/dist/langchain.js +3 -3
- package/dist/langchain.js.map +1 -1
- package/dist/mcp.cjs +48 -50
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +2 -2
- package/dist/mcp.js.map +1 -1
- package/dist/{toolkit--KYFOIry.d.cts → toolkit-CzHjKNIf.d.cts} +1 -1
- package/dist/{toolkit--KYFOIry.d.ts → toolkit-CzHjKNIf.d.ts} +1 -1
- package/package.json +11 -5
- package/dist/chunk-4RMN5TYL.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -45,33 +45,33 @@ var MessageIdSchema = import_zod.z.string().describe("ID of message");
|
|
|
45
45
|
var AttachmentIdSchema = import_zod.z.string().describe("ID of attachment");
|
|
46
46
|
var ListItemsParams = import_zod.z.object({
|
|
47
47
|
limit: import_zod.z.number().optional().default(10).describe("Max number of items to return"),
|
|
48
|
-
|
|
48
|
+
pageToken: import_zod.z.string().optional().describe("Page token for pagination")
|
|
49
49
|
});
|
|
50
50
|
var GetInboxParams = import_zod.z.object({
|
|
51
|
-
|
|
51
|
+
inboxId: InboxIdSchema
|
|
52
52
|
});
|
|
53
53
|
var CreateInboxParams = import_zod.z.object({
|
|
54
54
|
username: import_zod.z.string().optional().describe("Username"),
|
|
55
55
|
domain: import_zod.z.string().optional().describe("Domain"),
|
|
56
|
-
|
|
56
|
+
displayName: import_zod.z.string().optional().describe("Display name")
|
|
57
57
|
});
|
|
58
58
|
var ListInboxItemsParams = ListItemsParams.extend({
|
|
59
|
-
|
|
59
|
+
inboxId: InboxIdSchema,
|
|
60
60
|
labels: import_zod.z.array(import_zod.z.string()).optional().describe("Labels to filter items by"),
|
|
61
|
-
before: import_zod.z.string().optional().describe("Filter items before datetime"),
|
|
62
|
-
after: import_zod.z.string().optional().describe("Filter items after datetime")
|
|
61
|
+
before: import_zod.z.string().pipe(import_zod.z.coerce.date()).optional().describe("Filter items before datetime"),
|
|
62
|
+
after: import_zod.z.string().pipe(import_zod.z.coerce.date()).optional().describe("Filter items after datetime")
|
|
63
63
|
});
|
|
64
64
|
var GetThreadParams = import_zod.z.object({
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
inboxId: InboxIdSchema,
|
|
66
|
+
threadId: ThreadIdSchema
|
|
67
67
|
});
|
|
68
68
|
var GetAttachmentParams = import_zod.z.object({
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
inboxId: InboxIdSchema,
|
|
70
|
+
threadId: ThreadIdSchema,
|
|
71
|
+
attachmentId: AttachmentIdSchema
|
|
72
72
|
});
|
|
73
73
|
var BaseMessageParams = import_zod.z.object({
|
|
74
|
-
|
|
74
|
+
inboxId: InboxIdSchema,
|
|
75
75
|
text: import_zod.z.string().optional().describe("Plain text body"),
|
|
76
76
|
html: import_zod.z.string().optional().describe("HTML body"),
|
|
77
77
|
labels: import_zod.z.array(import_zod.z.string()).optional().describe("Labels")
|
|
@@ -83,16 +83,17 @@ var SendMessageParams = BaseMessageParams.extend({
|
|
|
83
83
|
subject: import_zod.z.string().optional().describe("Subject")
|
|
84
84
|
});
|
|
85
85
|
var ReplyToMessageParams = BaseMessageParams.extend({
|
|
86
|
-
|
|
86
|
+
messageId: MessageIdSchema
|
|
87
87
|
});
|
|
88
88
|
var UpdateMessageParams = import_zod.z.object({
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
inboxId: InboxIdSchema,
|
|
90
|
+
messageId: MessageIdSchema,
|
|
91
|
+
addLabels: import_zod.z.array(import_zod.z.string()).optional().describe("Labels to add"),
|
|
92
|
+
removeLabels: import_zod.z.array(import_zod.z.string()).optional().describe("Labels to remove")
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
// src/functions.ts
|
|
96
|
+
var import_worker = require("pdf-parse/worker");
|
|
96
97
|
var import_pdf_parse = require("pdf-parse");
|
|
97
98
|
var import_mammoth = __toESM(require("mammoth"), 1);
|
|
98
99
|
var import_file_type = require("file-type");
|
|
@@ -100,57 +101,54 @@ async function listInboxes(client, args) {
|
|
|
100
101
|
return client.inboxes.list(args);
|
|
101
102
|
}
|
|
102
103
|
async function getInbox(client, args) {
|
|
103
|
-
const {
|
|
104
|
-
return client.inboxes.get(
|
|
104
|
+
const { inboxId, ...options } = args;
|
|
105
|
+
return client.inboxes.get(inboxId, options);
|
|
105
106
|
}
|
|
106
107
|
async function createInbox(client, args) {
|
|
107
108
|
return client.inboxes.create(args);
|
|
108
109
|
}
|
|
109
110
|
async function deleteInbox(client, args) {
|
|
110
|
-
const {
|
|
111
|
-
return client.inboxes.delete(
|
|
111
|
+
const { inboxId } = args;
|
|
112
|
+
return client.inboxes.delete(inboxId);
|
|
112
113
|
}
|
|
113
114
|
async function listThreads(client, args) {
|
|
114
|
-
const {
|
|
115
|
-
return client.inboxes.threads.list(
|
|
115
|
+
const { inboxId, ...options } = args;
|
|
116
|
+
return client.inboxes.threads.list(inboxId, options);
|
|
116
117
|
}
|
|
117
118
|
async function getThread(client, args) {
|
|
118
|
-
const {
|
|
119
|
-
return client.inboxes.threads.get(
|
|
119
|
+
const { inboxId, threadId, ...options } = args;
|
|
120
|
+
return client.inboxes.threads.get(inboxId, threadId, options);
|
|
120
121
|
}
|
|
121
122
|
async function getAttachment(client, args) {
|
|
122
|
-
const {
|
|
123
|
-
const response = await client.threads.getAttachment(
|
|
123
|
+
const { threadId, attachmentId } = args;
|
|
124
|
+
const response = await client.threads.getAttachment(threadId, attachmentId);
|
|
124
125
|
const fileBytes = Buffer.from(await response.arrayBuffer());
|
|
125
126
|
const fileKind = await (0, import_file_type.fileTypeFromBuffer)(fileBytes);
|
|
126
127
|
const fileType = fileKind?.mime;
|
|
127
128
|
let text = void 0;
|
|
128
129
|
if (fileType === "application/pdf") {
|
|
129
|
-
const parser = new import_pdf_parse.PDFParse({ data: fileBytes });
|
|
130
|
+
const parser = new import_pdf_parse.PDFParse({ data: fileBytes, CanvasFactory: import_worker.CanvasFactory });
|
|
130
131
|
const pdfData = await parser.getText();
|
|
131
132
|
text = pdfData.text;
|
|
132
133
|
} else if (fileType === "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
|
|
133
134
|
const result = await import_mammoth.default.extractRawText({ buffer: fileBytes });
|
|
134
135
|
text = result.value;
|
|
135
136
|
} else {
|
|
136
|
-
return {
|
|
137
|
-
error: `Unsupported file type: ${fileType || "unknown"}`,
|
|
138
|
-
file_type: fileType
|
|
139
|
-
};
|
|
137
|
+
return { error: `Unsupported file type: ${fileType || "unknown"}`, fileType };
|
|
140
138
|
}
|
|
141
|
-
return { text,
|
|
139
|
+
return { text, fileType };
|
|
142
140
|
}
|
|
143
141
|
async function sendMessage(client, args) {
|
|
144
|
-
const {
|
|
145
|
-
return client.inboxes.messages.send(
|
|
142
|
+
const { inboxId, ...options } = args;
|
|
143
|
+
return client.inboxes.messages.send(inboxId, options);
|
|
146
144
|
}
|
|
147
145
|
async function replyToMessage(client, args) {
|
|
148
|
-
const {
|
|
149
|
-
return client.inboxes.messages.reply(
|
|
146
|
+
const { inboxId, messageId, ...options } = args;
|
|
147
|
+
return client.inboxes.messages.reply(inboxId, messageId, options);
|
|
150
148
|
}
|
|
151
149
|
async function updateMessage(client, args) {
|
|
152
|
-
const {
|
|
153
|
-
return client.inboxes.messages.update(
|
|
150
|
+
const { inboxId, messageId, ...options } = args;
|
|
151
|
+
return client.inboxes.messages.update(inboxId, messageId, options);
|
|
154
152
|
}
|
|
155
153
|
|
|
156
154
|
// src/tools.ts
|
|
@@ -158,61 +156,61 @@ var tools = [
|
|
|
158
156
|
{
|
|
159
157
|
name: "list_inboxes",
|
|
160
158
|
description: "List inboxes",
|
|
161
|
-
|
|
159
|
+
paramsSchema: ListItemsParams,
|
|
162
160
|
func: listInboxes
|
|
163
161
|
},
|
|
164
162
|
{
|
|
165
163
|
name: "get_inbox",
|
|
166
164
|
description: "Get inbox",
|
|
167
|
-
|
|
165
|
+
paramsSchema: GetInboxParams,
|
|
168
166
|
func: getInbox
|
|
169
167
|
},
|
|
170
168
|
{
|
|
171
169
|
name: "create_inbox",
|
|
172
170
|
description: "Create inbox",
|
|
173
|
-
|
|
171
|
+
paramsSchema: CreateInboxParams,
|
|
174
172
|
func: createInbox
|
|
175
173
|
},
|
|
176
174
|
{
|
|
177
175
|
name: "delete_inbox",
|
|
178
176
|
description: "Delete inbox",
|
|
179
|
-
|
|
177
|
+
paramsSchema: GetInboxParams,
|
|
180
178
|
func: deleteInbox
|
|
181
179
|
},
|
|
182
180
|
{
|
|
183
181
|
name: "list_threads",
|
|
184
182
|
description: "List threads in inbox",
|
|
185
|
-
|
|
183
|
+
paramsSchema: ListInboxItemsParams,
|
|
186
184
|
func: listThreads
|
|
187
185
|
},
|
|
188
186
|
{
|
|
189
187
|
name: "get_thread",
|
|
190
188
|
description: "Get thread",
|
|
191
|
-
|
|
189
|
+
paramsSchema: GetThreadParams,
|
|
192
190
|
func: getThread
|
|
193
191
|
},
|
|
194
192
|
{
|
|
195
193
|
name: "get_attachment",
|
|
196
194
|
description: "Get attachment",
|
|
197
|
-
|
|
195
|
+
paramsSchema: GetAttachmentParams,
|
|
198
196
|
func: getAttachment
|
|
199
197
|
},
|
|
200
198
|
{
|
|
201
199
|
name: "send_message",
|
|
202
200
|
description: "Send message",
|
|
203
|
-
|
|
201
|
+
paramsSchema: SendMessageParams,
|
|
204
202
|
func: sendMessage
|
|
205
203
|
},
|
|
206
204
|
{
|
|
207
205
|
name: "reply_to_message",
|
|
208
206
|
description: "Reply to message",
|
|
209
|
-
|
|
207
|
+
paramsSchema: ReplyToMessageParams,
|
|
210
208
|
func: replyToMessage
|
|
211
209
|
},
|
|
212
210
|
{
|
|
213
211
|
name: "update_message",
|
|
214
212
|
description: "Update message",
|
|
215
|
-
|
|
213
|
+
paramsSchema: UpdateMessageParams,
|
|
216
214
|
func: updateMessage
|
|
217
215
|
}
|
|
218
216
|
];
|
|
@@ -248,7 +246,7 @@ var AgentMailToolkit = class extends ListToolkit {
|
|
|
248
246
|
return {
|
|
249
247
|
name: tool.name,
|
|
250
248
|
description: tool.description,
|
|
251
|
-
|
|
249
|
+
paramsSchema: tool.paramsSchema,
|
|
252
250
|
func: (args) => tool.func(this.client, args)
|
|
253
251
|
};
|
|
254
252
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/toolkit.ts","../src/schemas.ts","../src/functions.ts","../src/tools.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport { ListToolkit } from './toolkit.js'\nimport { type Tool as BaseTool } from './tools.js'\n\ntype Tool = {\n name: string\n description: string\n params_schema: z.ZodObject<any>\n func: (args: any) => Promise<any>\n}\n\nexport class AgentMailToolkit extends ListToolkit<Tool> {\n protected buildTool(tool: BaseTool) {\n return {\n name: tool.name,\n description: tool.description,\n params_schema: tool.params_schema,\n func: (args: z.infer<typeof tool.params_schema>) => tool.func(this.client, args),\n }\n }\n}\n","import { AgentMailClient } from 'agentmail'\n\nimport { type Tool, tools } from './tools.js'\n\nexport abstract class BaseToolkit<T> {\n protected readonly client: AgentMailClient\n protected readonly tools: Record<string, T> = {}\n\n constructor(client?: AgentMailClient) {\n this.client = client ?? new AgentMailClient()\n\n this.tools = tools.reduce(\n (acc, tool) => {\n acc[tool.name] = this.buildTool(tool)\n return acc\n },\n {} as Record<string, T>\n )\n }\n\n protected abstract buildTool(tool: Tool): T\n}\n\nexport abstract class ListToolkit<T> extends BaseToolkit<T> {\n public getTools(names?: string[]) {\n if (!names) return Object.values(this.tools)\n\n return names.reduce((acc, name) => {\n if (name in this.tools) acc.push(this.tools[name])\n return acc\n }, [] as T[])\n }\n}\n\nexport abstract class MapToolkit<T> extends BaseToolkit<T> {\n public getTools(names?: string[]) {\n if (!names) return this.tools\n\n return names.reduce(\n (acc, name) => {\n if (name in this.tools) acc[name] = this.tools[name]\n return acc\n },\n {} as Record<string, T>\n )\n }\n}\n","import { z } from 'zod'\n\nconst InboxIdSchema = z.string().describe('ID of inbox')\nconst ThreadIdSchema = z.string().describe('ID of thread')\nconst MessageIdSchema = z.string().describe('ID of message')\nconst AttachmentIdSchema = z.string().describe('ID of attachment')\n\nexport const ListItemsParams = z.object({\n limit: z.number().optional().default(10).describe('Max number of items to return'),\n page_token: z.string().optional().describe('Page token for pagination'),\n})\n\nexport const GetInboxParams = z.object({\n inbox_id: InboxIdSchema,\n})\n\nexport const CreateInboxParams = z.object({\n username: z.string().optional().describe('Username'),\n domain: z.string().optional().describe('Domain'),\n display_name: z.string().optional().describe('Display name'),\n})\n\nexport const ListInboxItemsParams = ListItemsParams.extend({\n inbox_id: InboxIdSchema,\n labels: z.array(z.string()).optional().describe('Labels to filter items by'),\n before: z.string().optional().describe('Filter items before datetime'),\n after: z.string().optional().describe('Filter items after datetime'),\n})\n\nexport const GetThreadParams = z.object({\n inbox_id: InboxIdSchema,\n thread_id: ThreadIdSchema,\n})\n\nexport const GetAttachmentParams = z.object({\n inbox_id: InboxIdSchema,\n thread_id: ThreadIdSchema,\n attachment_id: AttachmentIdSchema,\n})\n\nconst BaseMessageParams = z.object({\n inbox_id: InboxIdSchema,\n text: z.string().optional().describe('Plain text body'),\n html: z.string().optional().describe('HTML body'),\n labels: z.array(z.string()).optional().describe('Labels'),\n})\n\nexport const SendMessageParams = BaseMessageParams.extend({\n to: z.array(z.string()).describe('Recipients'),\n cc: z.array(z.string()).optional().describe('CC recipients'),\n bcc: z.array(z.string()).optional().describe('BCC recipients'),\n subject: z.string().optional().describe('Subject'),\n})\n\nexport const ReplyToMessageParams = BaseMessageParams.extend({\n message_id: MessageIdSchema,\n})\n\nexport const UpdateMessageParams = z.object({\n inbox_id: InboxIdSchema,\n message_id: MessageIdSchema,\n add_labels: z.array(z.string()).optional().describe('Labels to add'),\n remove_labels: z.array(z.string()).optional().describe('Labels to remove'),\n})\n","import { AgentMailClient } from 'agentmail'\nimport { PDFParse } from 'pdf-parse'\nimport mammoth from 'mammoth'\nimport { fileTypeFromBuffer } from 'file-type'\n\nexport type Args = Record<string, any>\n\ninterface Attachment {\n text?: string\n error?: string\n file_type?: string\n}\n\nexport async function listInboxes(client: AgentMailClient, args: Args) {\n return client.inboxes.list(args)\n}\n\nexport async function getInbox(client: AgentMailClient, args: Args) {\n const { inbox_id, ...options } = args\n return client.inboxes.get(inbox_id, options)\n}\n\nexport async function createInbox(client: AgentMailClient, args: Args) {\n return client.inboxes.create(args)\n}\n\nexport async function deleteInbox(client: AgentMailClient, args: Args) {\n const { inbox_id } = args\n return client.inboxes.delete(inbox_id)\n}\n\nexport async function listThreads(client: AgentMailClient, args: Args) {\n const { inbox_id, ...options } = args\n return client.inboxes.threads.list(inbox_id, options)\n}\n\nexport async function getThread(client: AgentMailClient, args: Args) {\n const { inbox_id, thread_id, ...options } = args\n return client.inboxes.threads.get(inbox_id, thread_id, options)\n}\n\nexport async function getAttachment(client: AgentMailClient, args: Args): Promise<Attachment> {\n const { thread_id, attachment_id } = args\n\n const response = await client.threads.getAttachment(thread_id, attachment_id)\n const fileBytes = Buffer.from(await response.arrayBuffer())\n\n const fileKind = await fileTypeFromBuffer(fileBytes)\n const fileType = fileKind?.mime\n\n let text = undefined\n\n if (fileType === 'application/pdf') {\n const parser = new PDFParse({ data: fileBytes })\n const pdfData = await parser.getText()\n text = pdfData.text\n } else if (fileType === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {\n const result = await mammoth.extractRawText({ buffer: fileBytes })\n text = result.value\n } else {\n return {\n error: `Unsupported file type: ${fileType || 'unknown'}`,\n file_type: fileType,\n }\n }\n\n return { text, file_type: fileType }\n}\n\nexport async function sendMessage(client: AgentMailClient, args: Args) {\n const { inbox_id, ...options } = args\n return client.inboxes.messages.send(inbox_id, options)\n}\n\nexport async function replyToMessage(client: AgentMailClient, args: Args) {\n const { inbox_id, message_id, ...options } = args\n return client.inboxes.messages.reply(inbox_id, message_id, options)\n}\n\nexport async function updateMessage(client: AgentMailClient, args: Args) {\n const { inbox_id, message_id, ...options } = args\n return client.inboxes.messages.update(inbox_id, message_id, options)\n}\n","import { z } from 'zod'\nimport { AgentMailClient } from 'agentmail'\n\nimport {\n ListItemsParams,\n ListInboxItemsParams,\n GetInboxParams,\n CreateInboxParams,\n GetThreadParams,\n GetAttachmentParams,\n SendMessageParams,\n ReplyToMessageParams,\n UpdateMessageParams,\n} from './schemas.js'\nimport {\n type Args,\n listInboxes,\n getInbox,\n createInbox,\n deleteInbox,\n listThreads,\n getThread,\n getAttachment,\n sendMessage,\n replyToMessage,\n updateMessage,\n} from './functions.js'\nexport interface Tool {\n name: string\n description: string\n params_schema: z.ZodObject<any>\n func: (client: AgentMailClient, args: Args) => Promise<any>\n}\n\nexport const tools: Tool[] = [\n {\n name: 'list_inboxes',\n description: 'List inboxes',\n params_schema: ListItemsParams,\n func: listInboxes,\n },\n {\n name: 'get_inbox',\n description: 'Get inbox',\n params_schema: GetInboxParams,\n func: getInbox,\n },\n {\n name: 'create_inbox',\n description: 'Create inbox',\n params_schema: CreateInboxParams,\n func: createInbox,\n },\n {\n name: 'delete_inbox',\n description: 'Delete inbox',\n params_schema: GetInboxParams,\n func: deleteInbox,\n },\n {\n name: 'list_threads',\n description: 'List threads in inbox',\n params_schema: ListInboxItemsParams,\n func: listThreads,\n },\n {\n name: 'get_thread',\n description: 'Get thread',\n params_schema: GetThreadParams,\n func: getThread,\n },\n {\n name: 'get_attachment',\n description: 'Get attachment',\n params_schema: GetAttachmentParams,\n func: getAttachment,\n },\n {\n name: 'send_message',\n description: 'Send message',\n params_schema: SendMessageParams,\n func: sendMessage,\n },\n {\n name: 'reply_to_message',\n description: 'Reply to message',\n params_schema: ReplyToMessageParams,\n func: replyToMessage,\n },\n {\n name: 'update_message',\n description: 'Update message',\n params_schema: UpdateMessageParams,\n func: updateMessage,\n },\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAgC;;;ACAhC,iBAAkB;AAElB,IAAM,gBAAgB,aAAE,OAAO,EAAE,SAAS,aAAa;AACvD,IAAM,iBAAiB,aAAE,OAAO,EAAE,SAAS,cAAc;AACzD,IAAM,kBAAkB,aAAE,OAAO,EAAE,SAAS,eAAe;AAC3D,IAAM,qBAAqB,aAAE,OAAO,EAAE,SAAS,kBAAkB;AAE1D,IAAM,kBAAkB,aAAE,OAAO;AAAA,EACpC,OAAO,aAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,SAAS,+BAA+B;AAAA,EACjF,YAAY,aAAE,OAAO,EAAE,SAAS,EAAE,SAAS,2BAA2B;AAC1E,CAAC;AAEM,IAAM,iBAAiB,aAAE,OAAO;AAAA,EACnC,UAAU;AACd,CAAC;AAEM,IAAM,oBAAoB,aAAE,OAAO;AAAA,EACtC,UAAU,aAAE,OAAO,EAAE,SAAS,EAAE,SAAS,UAAU;AAAA,EACnD,QAAQ,aAAE,OAAO,EAAE,SAAS,EAAE,SAAS,QAAQ;AAAA,EAC/C,cAAc,aAAE,OAAO,EAAE,SAAS,EAAE,SAAS,cAAc;AAC/D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1
|
+
{"version":3,"sources":["../src/index.ts","../src/toolkit.ts","../src/schemas.ts","../src/functions.ts","../src/tools.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport { ListToolkit } from './toolkit.js'\nimport { type Tool as BaseTool } from './tools.js'\n\ntype Tool = {\n name: string\n description: string\n paramsSchema: z.ZodObject<any>\n func: (args: any) => Promise<any>\n}\n\nexport class AgentMailToolkit extends ListToolkit<Tool> {\n protected buildTool(tool: BaseTool) {\n return {\n name: tool.name,\n description: tool.description,\n paramsSchema: tool.paramsSchema,\n func: (args: z.infer<typeof tool.paramsSchema>) => tool.func(this.client, args),\n }\n }\n}\n","import { AgentMailClient } from 'agentmail'\n\nimport { type Tool, tools } from './tools.js'\n\nexport abstract class BaseToolkit<T> {\n protected readonly client: AgentMailClient\n protected readonly tools: Record<string, T> = {}\n\n constructor(client?: AgentMailClient) {\n this.client = client ?? new AgentMailClient()\n\n this.tools = tools.reduce(\n (acc, tool) => {\n acc[tool.name] = this.buildTool(tool)\n return acc\n },\n {} as Record<string, T>\n )\n }\n\n protected abstract buildTool(tool: Tool): T\n}\n\nexport abstract class ListToolkit<T> extends BaseToolkit<T> {\n public getTools(names?: string[]) {\n if (!names) return Object.values(this.tools)\n\n return names.reduce((acc, name) => {\n if (name in this.tools) acc.push(this.tools[name])\n return acc\n }, [] as T[])\n }\n}\n\nexport abstract class MapToolkit<T> extends BaseToolkit<T> {\n public getTools(names?: string[]) {\n if (!names) return this.tools\n\n return names.reduce(\n (acc, name) => {\n if (name in this.tools) acc[name] = this.tools[name]\n return acc\n },\n {} as Record<string, T>\n )\n }\n}\n","import { z } from 'zod'\n\nconst InboxIdSchema = z.string().describe('ID of inbox')\nconst ThreadIdSchema = z.string().describe('ID of thread')\nconst MessageIdSchema = z.string().describe('ID of message')\nconst AttachmentIdSchema = z.string().describe('ID of attachment')\n\nexport const ListItemsParams = z.object({\n limit: z.number().optional().default(10).describe('Max number of items to return'),\n pageToken: z.string().optional().describe('Page token for pagination'),\n})\n\nexport const GetInboxParams = z.object({\n inboxId: InboxIdSchema,\n})\n\nexport const CreateInboxParams = z.object({\n username: z.string().optional().describe('Username'),\n domain: z.string().optional().describe('Domain'),\n displayName: z.string().optional().describe('Display name'),\n})\n\nexport const ListInboxItemsParams = ListItemsParams.extend({\n inboxId: InboxIdSchema,\n labels: z.array(z.string()).optional().describe('Labels to filter items by'),\n before: z.string().pipe(z.coerce.date()).optional().describe('Filter items before datetime'),\n after: z.string().pipe(z.coerce.date()).optional().describe('Filter items after datetime'),\n})\n\nexport const GetThreadParams = z.object({\n inboxId: InboxIdSchema,\n threadId: ThreadIdSchema,\n})\n\nexport const GetAttachmentParams = z.object({\n inboxId: InboxIdSchema,\n threadId: ThreadIdSchema,\n attachmentId: AttachmentIdSchema,\n})\n\nconst BaseMessageParams = z.object({\n inboxId: InboxIdSchema,\n text: z.string().optional().describe('Plain text body'),\n html: z.string().optional().describe('HTML body'),\n labels: z.array(z.string()).optional().describe('Labels'),\n})\n\nexport const SendMessageParams = BaseMessageParams.extend({\n to: z.array(z.string()).describe('Recipients'),\n cc: z.array(z.string()).optional().describe('CC recipients'),\n bcc: z.array(z.string()).optional().describe('BCC recipients'),\n subject: z.string().optional().describe('Subject'),\n})\n\nexport const ReplyToMessageParams = BaseMessageParams.extend({\n messageId: MessageIdSchema,\n})\n\nexport const UpdateMessageParams = z.object({\n inboxId: InboxIdSchema,\n messageId: MessageIdSchema,\n addLabels: z.array(z.string()).optional().describe('Labels to add'),\n removeLabels: z.array(z.string()).optional().describe('Labels to remove'),\n})\n","import { AgentMailClient } from 'agentmail'\nimport { CanvasFactory } from 'pdf-parse/worker'\nimport { PDFParse } from 'pdf-parse'\nimport mammoth from 'mammoth'\nimport { fileTypeFromBuffer } from 'file-type'\n\nexport type Args = Record<string, any>\n\ninterface Attachment {\n text?: string\n error?: string\n fileType?: string\n}\n\nexport async function listInboxes(client: AgentMailClient, args: Args) {\n return client.inboxes.list(args)\n}\n\nexport async function getInbox(client: AgentMailClient, args: Args) {\n const { inboxId, ...options } = args\n return client.inboxes.get(inboxId, options)\n}\n\nexport async function createInbox(client: AgentMailClient, args: Args) {\n return client.inboxes.create(args)\n}\n\nexport async function deleteInbox(client: AgentMailClient, args: Args) {\n const { inboxId } = args\n return client.inboxes.delete(inboxId)\n}\n\nexport async function listThreads(client: AgentMailClient, args: Args) {\n const { inboxId, ...options } = args\n return client.inboxes.threads.list(inboxId, options)\n}\n\nexport async function getThread(client: AgentMailClient, args: Args) {\n const { inboxId, threadId, ...options } = args\n return client.inboxes.threads.get(inboxId, threadId, options)\n}\n\nexport async function getAttachment(client: AgentMailClient, args: Args): Promise<Attachment> {\n const { threadId, attachmentId } = args\n\n const response = await client.threads.getAttachment(threadId, attachmentId)\n const fileBytes = Buffer.from(await response.arrayBuffer())\n\n const fileKind = await fileTypeFromBuffer(fileBytes)\n const fileType = fileKind?.mime\n\n let text = undefined\n\n if (fileType === 'application/pdf') {\n const parser = new PDFParse({ data: fileBytes, CanvasFactory })\n const pdfData = await parser.getText()\n text = pdfData.text\n } else if (fileType === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {\n const result = await mammoth.extractRawText({ buffer: fileBytes })\n text = result.value\n } else {\n return { error: `Unsupported file type: ${fileType || 'unknown'}`, fileType }\n }\n\n return { text, fileType }\n}\n\nexport async function sendMessage(client: AgentMailClient, args: Args) {\n const { inboxId, ...options } = args\n return client.inboxes.messages.send(inboxId, options)\n}\n\nexport async function replyToMessage(client: AgentMailClient, args: Args) {\n const { inboxId, messageId, ...options } = args\n return client.inboxes.messages.reply(inboxId, messageId, options)\n}\n\nexport async function updateMessage(client: AgentMailClient, args: Args) {\n const { inboxId, messageId, ...options } = args\n return client.inboxes.messages.update(inboxId, messageId, options)\n}\n","import { z } from 'zod'\nimport { AgentMailClient } from 'agentmail'\n\nimport {\n ListItemsParams,\n ListInboxItemsParams,\n GetInboxParams,\n CreateInboxParams,\n GetThreadParams,\n GetAttachmentParams,\n SendMessageParams,\n ReplyToMessageParams,\n UpdateMessageParams,\n} from './schemas.js'\nimport {\n type Args,\n listInboxes,\n getInbox,\n createInbox,\n deleteInbox,\n listThreads,\n getThread,\n getAttachment,\n sendMessage,\n replyToMessage,\n updateMessage,\n} from './functions.js'\nexport interface Tool {\n name: string\n description: string\n paramsSchema: z.ZodObject<any>\n func: (client: AgentMailClient, args: Args) => Promise<any>\n}\n\nexport const tools: Tool[] = [\n {\n name: 'list_inboxes',\n description: 'List inboxes',\n paramsSchema: ListItemsParams,\n func: listInboxes,\n },\n {\n name: 'get_inbox',\n description: 'Get inbox',\n paramsSchema: GetInboxParams,\n func: getInbox,\n },\n {\n name: 'create_inbox',\n description: 'Create inbox',\n paramsSchema: CreateInboxParams,\n func: createInbox,\n },\n {\n name: 'delete_inbox',\n description: 'Delete inbox',\n paramsSchema: GetInboxParams,\n func: deleteInbox,\n },\n {\n name: 'list_threads',\n description: 'List threads in inbox',\n paramsSchema: ListInboxItemsParams,\n func: listThreads,\n },\n {\n name: 'get_thread',\n description: 'Get thread',\n paramsSchema: GetThreadParams,\n func: getThread,\n },\n {\n name: 'get_attachment',\n description: 'Get attachment',\n paramsSchema: GetAttachmentParams,\n func: getAttachment,\n },\n {\n name: 'send_message',\n description: 'Send message',\n paramsSchema: SendMessageParams,\n func: sendMessage,\n },\n {\n name: 'reply_to_message',\n description: 'Reply to message',\n paramsSchema: ReplyToMessageParams,\n func: replyToMessage,\n },\n {\n name: 'update_message',\n description: 'Update message',\n paramsSchema: UpdateMessageParams,\n func: updateMessage,\n },\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAgC;;;ACAhC,iBAAkB;AAElB,IAAM,gBAAgB,aAAE,OAAO,EAAE,SAAS,aAAa;AACvD,IAAM,iBAAiB,aAAE,OAAO,EAAE,SAAS,cAAc;AACzD,IAAM,kBAAkB,aAAE,OAAO,EAAE,SAAS,eAAe;AAC3D,IAAM,qBAAqB,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CAAC;AAAA,IACL;AAAA,EACJ;AAGJ;AAEO,IAAe,cAAf,cAAsC,YAAe;AAAA,EACjD,SAAS,OAAkB;AAC9B,QAAI,CAAC,MAAO,QAAO,OAAO,OAAO,KAAK,KAAK;AAE3C,WAAO,MAAM,OAAO,CAAC,KAAK,SAAS;AAC/B,UAAI,QAAQ,KAAK,MAAO,KAAI,KAAK,KAAK,MAAM,IAAI,CAAC;AACjD,aAAO;AAAA,IACX,GAAG,CAAC,CAAQ;AAAA,EAChB;AACJ;;;ADpBO,IAAM,mBAAN,cAA+B,YAAkB;AAAA,EAC1C,UAAU,MAAgB;AAChC,WAAO;AAAA,MACH,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,cAAc,KAAK;AAAA,MACnB,MAAM,CAAC,SAA4C,KAAK,KAAK,KAAK,QAAQ,IAAI;AAAA,IAClF;AAAA,EACJ;AACJ;","names":["mammoth"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { L as ListToolkit, T as Tool$1 } from './toolkit
|
|
2
|
+
import { L as ListToolkit, T as Tool$1 } from './toolkit-CzHjKNIf.cjs';
|
|
3
3
|
import 'agentmail';
|
|
4
4
|
|
|
5
5
|
type Tool = {
|
|
6
6
|
name: string;
|
|
7
7
|
description: string;
|
|
8
|
-
|
|
8
|
+
paramsSchema: z.ZodObject<any>;
|
|
9
9
|
func: (args: any) => Promise<any>;
|
|
10
10
|
};
|
|
11
11
|
declare class AgentMailToolkit extends ListToolkit<Tool> {
|
|
12
12
|
protected buildTool(tool: Tool$1): {
|
|
13
13
|
name: string;
|
|
14
14
|
description: string;
|
|
15
|
-
|
|
16
|
-
func: (args: z.infer<typeof tool.
|
|
15
|
+
paramsSchema: z.ZodObject<any, z.core.$strip>;
|
|
16
|
+
func: (args: z.infer<typeof tool.paramsSchema>) => Promise<any>;
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { L as ListToolkit, T as Tool$1 } from './toolkit
|
|
2
|
+
import { L as ListToolkit, T as Tool$1 } from './toolkit-CzHjKNIf.js';
|
|
3
3
|
import 'agentmail';
|
|
4
4
|
|
|
5
5
|
type Tool = {
|
|
6
6
|
name: string;
|
|
7
7
|
description: string;
|
|
8
|
-
|
|
8
|
+
paramsSchema: z.ZodObject<any>;
|
|
9
9
|
func: (args: any) => Promise<any>;
|
|
10
10
|
};
|
|
11
11
|
declare class AgentMailToolkit extends ListToolkit<Tool> {
|
|
12
12
|
protected buildTool(tool: Tool$1): {
|
|
13
13
|
name: string;
|
|
14
14
|
description: string;
|
|
15
|
-
|
|
16
|
-
func: (args: z.infer<typeof tool.
|
|
15
|
+
paramsSchema: z.ZodObject<any, z.core.$strip>;
|
|
16
|
+
func: (args: z.infer<typeof tool.paramsSchema>) => Promise<any>;
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ListToolkit
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4T5LKBWD.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
var AgentMailToolkit = class extends ListToolkit {
|
|
@@ -8,7 +8,7 @@ var AgentMailToolkit = class extends ListToolkit {
|
|
|
8
8
|
return {
|
|
9
9
|
name: tool.name,
|
|
10
10
|
description: tool.description,
|
|
11
|
-
|
|
11
|
+
paramsSchema: tool.paramsSchema,
|
|
12
12
|
func: (args) => tool.func(this.client, args)
|
|
13
13
|
};
|
|
14
14
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport { ListToolkit } from './toolkit.js'\nimport { type Tool as BaseTool } from './tools.js'\n\ntype Tool = {\n name: string\n description: string\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport { ListToolkit } from './toolkit.js'\nimport { type Tool as BaseTool } from './tools.js'\n\ntype Tool = {\n name: string\n description: string\n paramsSchema: z.ZodObject<any>\n func: (args: any) => Promise<any>\n}\n\nexport class AgentMailToolkit extends ListToolkit<Tool> {\n protected buildTool(tool: BaseTool) {\n return {\n name: tool.name,\n description: tool.description,\n paramsSchema: tool.paramsSchema,\n func: (args: z.infer<typeof tool.paramsSchema>) => tool.func(this.client, args),\n }\n }\n}\n"],"mappings":";;;;;AAYO,IAAM,mBAAN,cAA+B,YAAkB;AAAA,EAC1C,UAAU,MAAgB;AAChC,WAAO;AAAA,MACH,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,cAAc,KAAK;AAAA,MACnB,MAAM,CAAC,SAA4C,KAAK,KAAK,KAAK,QAAQ,IAAI;AAAA,IAClF;AAAA,EACJ;AACJ;","names":[]}
|
package/dist/langchain.cjs
CHANGED
|
@@ -33,7 +33,7 @@ __export(langchain_exports, {
|
|
|
33
33
|
AgentMailToolkit: () => AgentMailToolkit
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(langchain_exports);
|
|
36
|
-
var
|
|
36
|
+
var import_langchain = require("langchain");
|
|
37
37
|
|
|
38
38
|
// src/toolkit.ts
|
|
39
39
|
var import_agentmail = require("agentmail");
|
|
@@ -46,33 +46,33 @@ var MessageIdSchema = import_zod.z.string().describe("ID of message");
|
|
|
46
46
|
var AttachmentIdSchema = import_zod.z.string().describe("ID of attachment");
|
|
47
47
|
var ListItemsParams = import_zod.z.object({
|
|
48
48
|
limit: import_zod.z.number().optional().default(10).describe("Max number of items to return"),
|
|
49
|
-
|
|
49
|
+
pageToken: import_zod.z.string().optional().describe("Page token for pagination")
|
|
50
50
|
});
|
|
51
51
|
var GetInboxParams = import_zod.z.object({
|
|
52
|
-
|
|
52
|
+
inboxId: InboxIdSchema
|
|
53
53
|
});
|
|
54
54
|
var CreateInboxParams = import_zod.z.object({
|
|
55
55
|
username: import_zod.z.string().optional().describe("Username"),
|
|
56
56
|
domain: import_zod.z.string().optional().describe("Domain"),
|
|
57
|
-
|
|
57
|
+
displayName: import_zod.z.string().optional().describe("Display name")
|
|
58
58
|
});
|
|
59
59
|
var ListInboxItemsParams = ListItemsParams.extend({
|
|
60
|
-
|
|
60
|
+
inboxId: InboxIdSchema,
|
|
61
61
|
labels: import_zod.z.array(import_zod.z.string()).optional().describe("Labels to filter items by"),
|
|
62
|
-
before: import_zod.z.string().optional().describe("Filter items before datetime"),
|
|
63
|
-
after: import_zod.z.string().optional().describe("Filter items after datetime")
|
|
62
|
+
before: import_zod.z.string().pipe(import_zod.z.coerce.date()).optional().describe("Filter items before datetime"),
|
|
63
|
+
after: import_zod.z.string().pipe(import_zod.z.coerce.date()).optional().describe("Filter items after datetime")
|
|
64
64
|
});
|
|
65
65
|
var GetThreadParams = import_zod.z.object({
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
inboxId: InboxIdSchema,
|
|
67
|
+
threadId: ThreadIdSchema
|
|
68
68
|
});
|
|
69
69
|
var GetAttachmentParams = import_zod.z.object({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
inboxId: InboxIdSchema,
|
|
71
|
+
threadId: ThreadIdSchema,
|
|
72
|
+
attachmentId: AttachmentIdSchema
|
|
73
73
|
});
|
|
74
74
|
var BaseMessageParams = import_zod.z.object({
|
|
75
|
-
|
|
75
|
+
inboxId: InboxIdSchema,
|
|
76
76
|
text: import_zod.z.string().optional().describe("Plain text body"),
|
|
77
77
|
html: import_zod.z.string().optional().describe("HTML body"),
|
|
78
78
|
labels: import_zod.z.array(import_zod.z.string()).optional().describe("Labels")
|
|
@@ -84,16 +84,17 @@ var SendMessageParams = BaseMessageParams.extend({
|
|
|
84
84
|
subject: import_zod.z.string().optional().describe("Subject")
|
|
85
85
|
});
|
|
86
86
|
var ReplyToMessageParams = BaseMessageParams.extend({
|
|
87
|
-
|
|
87
|
+
messageId: MessageIdSchema
|
|
88
88
|
});
|
|
89
89
|
var UpdateMessageParams = import_zod.z.object({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
inboxId: InboxIdSchema,
|
|
91
|
+
messageId: MessageIdSchema,
|
|
92
|
+
addLabels: import_zod.z.array(import_zod.z.string()).optional().describe("Labels to add"),
|
|
93
|
+
removeLabels: import_zod.z.array(import_zod.z.string()).optional().describe("Labels to remove")
|
|
94
94
|
});
|
|
95
95
|
|
|
96
96
|
// src/functions.ts
|
|
97
|
+
var import_worker = require("pdf-parse/worker");
|
|
97
98
|
var import_pdf_parse = require("pdf-parse");
|
|
98
99
|
var import_mammoth = __toESM(require("mammoth"), 1);
|
|
99
100
|
var import_file_type = require("file-type");
|
|
@@ -101,57 +102,54 @@ async function listInboxes(client, args) {
|
|
|
101
102
|
return client.inboxes.list(args);
|
|
102
103
|
}
|
|
103
104
|
async function getInbox(client, args) {
|
|
104
|
-
const {
|
|
105
|
-
return client.inboxes.get(
|
|
105
|
+
const { inboxId, ...options } = args;
|
|
106
|
+
return client.inboxes.get(inboxId, options);
|
|
106
107
|
}
|
|
107
108
|
async function createInbox(client, args) {
|
|
108
109
|
return client.inboxes.create(args);
|
|
109
110
|
}
|
|
110
111
|
async function deleteInbox(client, args) {
|
|
111
|
-
const {
|
|
112
|
-
return client.inboxes.delete(
|
|
112
|
+
const { inboxId } = args;
|
|
113
|
+
return client.inboxes.delete(inboxId);
|
|
113
114
|
}
|
|
114
115
|
async function listThreads(client, args) {
|
|
115
|
-
const {
|
|
116
|
-
return client.inboxes.threads.list(
|
|
116
|
+
const { inboxId, ...options } = args;
|
|
117
|
+
return client.inboxes.threads.list(inboxId, options);
|
|
117
118
|
}
|
|
118
119
|
async function getThread(client, args) {
|
|
119
|
-
const {
|
|
120
|
-
return client.inboxes.threads.get(
|
|
120
|
+
const { inboxId, threadId, ...options } = args;
|
|
121
|
+
return client.inboxes.threads.get(inboxId, threadId, options);
|
|
121
122
|
}
|
|
122
123
|
async function getAttachment(client, args) {
|
|
123
|
-
const {
|
|
124
|
-
const response = await client.threads.getAttachment(
|
|
124
|
+
const { threadId, attachmentId } = args;
|
|
125
|
+
const response = await client.threads.getAttachment(threadId, attachmentId);
|
|
125
126
|
const fileBytes = Buffer.from(await response.arrayBuffer());
|
|
126
127
|
const fileKind = await (0, import_file_type.fileTypeFromBuffer)(fileBytes);
|
|
127
128
|
const fileType = fileKind?.mime;
|
|
128
129
|
let text = void 0;
|
|
129
130
|
if (fileType === "application/pdf") {
|
|
130
|
-
const parser = new import_pdf_parse.PDFParse({ data: fileBytes });
|
|
131
|
+
const parser = new import_pdf_parse.PDFParse({ data: fileBytes, CanvasFactory: import_worker.CanvasFactory });
|
|
131
132
|
const pdfData = await parser.getText();
|
|
132
133
|
text = pdfData.text;
|
|
133
134
|
} else if (fileType === "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
|
|
134
135
|
const result = await import_mammoth.default.extractRawText({ buffer: fileBytes });
|
|
135
136
|
text = result.value;
|
|
136
137
|
} else {
|
|
137
|
-
return {
|
|
138
|
-
error: `Unsupported file type: ${fileType || "unknown"}`,
|
|
139
|
-
file_type: fileType
|
|
140
|
-
};
|
|
138
|
+
return { error: `Unsupported file type: ${fileType || "unknown"}`, fileType };
|
|
141
139
|
}
|
|
142
|
-
return { text,
|
|
140
|
+
return { text, fileType };
|
|
143
141
|
}
|
|
144
142
|
async function sendMessage(client, args) {
|
|
145
|
-
const {
|
|
146
|
-
return client.inboxes.messages.send(
|
|
143
|
+
const { inboxId, ...options } = args;
|
|
144
|
+
return client.inboxes.messages.send(inboxId, options);
|
|
147
145
|
}
|
|
148
146
|
async function replyToMessage(client, args) {
|
|
149
|
-
const {
|
|
150
|
-
return client.inboxes.messages.reply(
|
|
147
|
+
const { inboxId, messageId, ...options } = args;
|
|
148
|
+
return client.inboxes.messages.reply(inboxId, messageId, options);
|
|
151
149
|
}
|
|
152
150
|
async function updateMessage(client, args) {
|
|
153
|
-
const {
|
|
154
|
-
return client.inboxes.messages.update(
|
|
151
|
+
const { inboxId, messageId, ...options } = args;
|
|
152
|
+
return client.inboxes.messages.update(inboxId, messageId, options);
|
|
155
153
|
}
|
|
156
154
|
|
|
157
155
|
// src/tools.ts
|
|
@@ -159,61 +157,61 @@ var tools = [
|
|
|
159
157
|
{
|
|
160
158
|
name: "list_inboxes",
|
|
161
159
|
description: "List inboxes",
|
|
162
|
-
|
|
160
|
+
paramsSchema: ListItemsParams,
|
|
163
161
|
func: listInboxes
|
|
164
162
|
},
|
|
165
163
|
{
|
|
166
164
|
name: "get_inbox",
|
|
167
165
|
description: "Get inbox",
|
|
168
|
-
|
|
166
|
+
paramsSchema: GetInboxParams,
|
|
169
167
|
func: getInbox
|
|
170
168
|
},
|
|
171
169
|
{
|
|
172
170
|
name: "create_inbox",
|
|
173
171
|
description: "Create inbox",
|
|
174
|
-
|
|
172
|
+
paramsSchema: CreateInboxParams,
|
|
175
173
|
func: createInbox
|
|
176
174
|
},
|
|
177
175
|
{
|
|
178
176
|
name: "delete_inbox",
|
|
179
177
|
description: "Delete inbox",
|
|
180
|
-
|
|
178
|
+
paramsSchema: GetInboxParams,
|
|
181
179
|
func: deleteInbox
|
|
182
180
|
},
|
|
183
181
|
{
|
|
184
182
|
name: "list_threads",
|
|
185
183
|
description: "List threads in inbox",
|
|
186
|
-
|
|
184
|
+
paramsSchema: ListInboxItemsParams,
|
|
187
185
|
func: listThreads
|
|
188
186
|
},
|
|
189
187
|
{
|
|
190
188
|
name: "get_thread",
|
|
191
189
|
description: "Get thread",
|
|
192
|
-
|
|
190
|
+
paramsSchema: GetThreadParams,
|
|
193
191
|
func: getThread
|
|
194
192
|
},
|
|
195
193
|
{
|
|
196
194
|
name: "get_attachment",
|
|
197
195
|
description: "Get attachment",
|
|
198
|
-
|
|
196
|
+
paramsSchema: GetAttachmentParams,
|
|
199
197
|
func: getAttachment
|
|
200
198
|
},
|
|
201
199
|
{
|
|
202
200
|
name: "send_message",
|
|
203
201
|
description: "Send message",
|
|
204
|
-
|
|
202
|
+
paramsSchema: SendMessageParams,
|
|
205
203
|
func: sendMessage
|
|
206
204
|
},
|
|
207
205
|
{
|
|
208
206
|
name: "reply_to_message",
|
|
209
207
|
description: "Reply to message",
|
|
210
|
-
|
|
208
|
+
paramsSchema: ReplyToMessageParams,
|
|
211
209
|
func: replyToMessage
|
|
212
210
|
},
|
|
213
211
|
{
|
|
214
212
|
name: "update_message",
|
|
215
213
|
description: "Update message",
|
|
216
|
-
|
|
214
|
+
paramsSchema: UpdateMessageParams,
|
|
217
215
|
func: updateMessage
|
|
218
216
|
}
|
|
219
217
|
];
|
|
@@ -256,10 +254,10 @@ var safeFunc = async (func, client, args) => {
|
|
|
256
254
|
// src/langchain.ts
|
|
257
255
|
var AgentMailToolkit = class extends ListToolkit {
|
|
258
256
|
buildTool(tool) {
|
|
259
|
-
return (0,
|
|
257
|
+
return (0, import_langchain.tool)(async (args) => JSON.stringify((await safeFunc(tool.func, this.client, args)).result, null, 2), {
|
|
260
258
|
name: tool.name,
|
|
261
259
|
description: tool.description,
|
|
262
|
-
schema: tool.
|
|
260
|
+
schema: tool.paramsSchema
|
|
263
261
|
});
|
|
264
262
|
}
|
|
265
263
|
};
|