langchain 0.0.200 → 0.0.202
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/agents/toolkits/connery.cjs +1 -0
- package/agents/toolkits/connery.d.ts +1 -0
- package/agents/toolkits/connery.js +1 -0
- package/dist/agents/toolkits/connery/index.cjs +39 -0
- package/dist/agents/toolkits/connery/index.d.ts +23 -0
- package/dist/agents/toolkits/connery/index.js +35 -0
- package/dist/document_loaders/fs/obsidian.cjs +240 -0
- package/dist/document_loaders/fs/obsidian.d.ts +26 -0
- package/dist/document_loaders/fs/obsidian.js +233 -0
- package/dist/embeddings/gradient_ai.cjs +1 -0
- package/dist/embeddings/gradient_ai.js +1 -0
- package/dist/load/import_constants.cjs +2 -0
- package/dist/load/import_constants.js +2 -0
- package/dist/load/import_map.cjs +5 -3
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/tools/connery.cjs +279 -0
- package/dist/tools/connery.d.ts +145 -0
- package/dist/tools/connery.js +274 -0
- package/dist/tools/gmail/base.cjs +69 -0
- package/dist/tools/gmail/base.d.ts +19 -0
- package/dist/tools/gmail/base.js +65 -0
- package/dist/tools/gmail/create_draft.cjs +62 -0
- package/dist/tools/gmail/create_draft.d.ts +35 -0
- package/dist/tools/gmail/create_draft.js +58 -0
- package/dist/tools/gmail/descriptions.cjs +118 -0
- package/dist/tools/gmail/descriptions.d.ts +5 -0
- package/dist/tools/gmail/descriptions.js +115 -0
- package/dist/tools/gmail/get_message.cjs +83 -0
- package/dist/tools/gmail/get_message.d.ts +18 -0
- package/dist/tools/gmail/get_message.js +79 -0
- package/dist/tools/gmail/get_thread.cjs +89 -0
- package/dist/tools/gmail/get_thread.d.ts +18 -0
- package/dist/tools/gmail/get_thread.js +85 -0
- package/dist/tools/gmail/index.cjs +13 -0
- package/dist/tools/gmail/index.d.ts +11 -0
- package/dist/tools/gmail/index.js +5 -0
- package/dist/tools/gmail/search.cjs +118 -0
- package/dist/tools/gmail/search.d.ts +29 -0
- package/dist/tools/gmail/search.js +114 -0
- package/dist/tools/gmail/send_message.cjs +74 -0
- package/dist/tools/gmail/send_message.d.ts +35 -0
- package/dist/tools/gmail/send_message.js +70 -0
- package/dist/tools/wolframalpha.cjs +1 -1
- package/dist/tools/wolframalpha.js +1 -1
- package/dist/util/stream.cjs +15 -85
- package/dist/util/stream.d.ts +1 -15
- package/dist/util/stream.js +1 -83
- package/dist/vectorstores/xata.cjs +1 -1
- package/dist/vectorstores/xata.js +1 -1
- package/document_loaders/fs/obsidian.cjs +1 -0
- package/document_loaders/fs/obsidian.d.ts +1 -0
- package/document_loaders/fs/obsidian.js +1 -0
- package/package.json +37 -5
- package/tools/connery.cjs +1 -0
- package/tools/connery.d.ts +1 -0
- package/tools/connery.js +1 -0
- package/tools/gmail.cjs +1 -0
- package/tools/gmail.d.ts +1 -0
- package/tools/gmail.js +1 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GmailSearch = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const base_js_1 = require("./base.cjs");
|
|
6
|
+
const descriptions_js_1 = require("./descriptions.cjs");
|
|
7
|
+
class GmailSearch extends base_js_1.GmailBaseTool {
|
|
8
|
+
constructor(fields) {
|
|
9
|
+
super(fields);
|
|
10
|
+
Object.defineProperty(this, "name", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: "search_gmail"
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "schema", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: zod_1.z.object({
|
|
21
|
+
query: zod_1.z.string(),
|
|
22
|
+
maxResults: zod_1.z.number().optional(),
|
|
23
|
+
resource: zod_1.z.enum(["messages", "threads"]).optional(),
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "description", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: descriptions_js_1.SEARCH_DESCRIPTION
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async _call(arg) {
|
|
34
|
+
const { query, maxResults = 10, resource = "messages" } = arg;
|
|
35
|
+
const response = await this.gmail.users.messages.list({
|
|
36
|
+
userId: "me",
|
|
37
|
+
q: query,
|
|
38
|
+
maxResults,
|
|
39
|
+
});
|
|
40
|
+
const { data } = response;
|
|
41
|
+
if (!data) {
|
|
42
|
+
throw new Error("No data returned from Gmail");
|
|
43
|
+
}
|
|
44
|
+
const { messages } = data;
|
|
45
|
+
if (!messages) {
|
|
46
|
+
throw new Error("No messages returned from Gmail");
|
|
47
|
+
}
|
|
48
|
+
if (resource === "messages") {
|
|
49
|
+
const parsedMessages = await this.parseMessages(messages);
|
|
50
|
+
return `Result for the query ${query}:\n${JSON.stringify(parsedMessages)}`;
|
|
51
|
+
}
|
|
52
|
+
else if (resource === "threads") {
|
|
53
|
+
const parsedThreads = await this.parseThreads(messages);
|
|
54
|
+
return `Result for the query ${query}:\n${JSON.stringify(parsedThreads)}`;
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`Invalid resource: ${resource}`);
|
|
57
|
+
}
|
|
58
|
+
async parseMessages(messages) {
|
|
59
|
+
const parsedMessages = await Promise.all(messages.map(async (message) => {
|
|
60
|
+
const messageData = await this.gmail.users.messages.get({
|
|
61
|
+
userId: "me",
|
|
62
|
+
format: "raw",
|
|
63
|
+
id: message.id ?? "",
|
|
64
|
+
});
|
|
65
|
+
const headers = messageData.data.payload?.headers || [];
|
|
66
|
+
const subject = headers.find((header) => header.name === "Subject");
|
|
67
|
+
const sender = headers.find((header) => header.name === "From");
|
|
68
|
+
let body = "";
|
|
69
|
+
if (messageData.data.payload?.parts) {
|
|
70
|
+
body = messageData.data.payload.parts
|
|
71
|
+
.map((part) => part.body?.data ?? "")
|
|
72
|
+
.join("");
|
|
73
|
+
}
|
|
74
|
+
else if (messageData.data.payload?.body?.data) {
|
|
75
|
+
body = messageData.data.payload.body.data;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
id: message.id,
|
|
79
|
+
threadId: message.threadId,
|
|
80
|
+
snippet: message.snippet,
|
|
81
|
+
body,
|
|
82
|
+
subject,
|
|
83
|
+
sender,
|
|
84
|
+
};
|
|
85
|
+
}));
|
|
86
|
+
return parsedMessages;
|
|
87
|
+
}
|
|
88
|
+
async parseThreads(threads) {
|
|
89
|
+
const parsedThreads = await Promise.all(threads.map(async (thread) => {
|
|
90
|
+
const threadData = await this.gmail.users.threads.get({
|
|
91
|
+
userId: "me",
|
|
92
|
+
format: "raw",
|
|
93
|
+
id: thread.id ?? "",
|
|
94
|
+
});
|
|
95
|
+
const headers = threadData.data.messages?.[0]?.payload?.headers || [];
|
|
96
|
+
const subject = headers.find((header) => header.name === "Subject");
|
|
97
|
+
const sender = headers.find((header) => header.name === "From");
|
|
98
|
+
let body = "";
|
|
99
|
+
if (threadData.data.messages?.[0]?.payload?.parts) {
|
|
100
|
+
body = threadData.data.messages[0].payload.parts
|
|
101
|
+
.map((part) => part.body?.data ?? "")
|
|
102
|
+
.join("");
|
|
103
|
+
}
|
|
104
|
+
else if (threadData.data.messages?.[0]?.payload?.body?.data) {
|
|
105
|
+
body = threadData.data.messages[0].payload.body.data;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
id: thread.id,
|
|
109
|
+
snippet: thread.snippet,
|
|
110
|
+
body,
|
|
111
|
+
subject,
|
|
112
|
+
sender,
|
|
113
|
+
};
|
|
114
|
+
}));
|
|
115
|
+
return parsedThreads;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.GmailSearch = GmailSearch;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { gmail_v1 } from "googleapis";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { GmailBaseTool, GmailBaseToolParams } from "./base.js";
|
|
4
|
+
export declare class GmailSearch extends GmailBaseTool {
|
|
5
|
+
name: string;
|
|
6
|
+
schema: z.ZodObject<{
|
|
7
|
+
query: z.ZodString;
|
|
8
|
+
maxResults: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
resource: z.ZodOptional<z.ZodEnum<["messages", "threads"]>>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
query: string;
|
|
12
|
+
maxResults?: number | undefined;
|
|
13
|
+
resource?: "messages" | "threads" | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
query: string;
|
|
16
|
+
maxResults?: number | undefined;
|
|
17
|
+
resource?: "messages" | "threads" | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
description: string;
|
|
20
|
+
constructor(fields?: GmailBaseToolParams);
|
|
21
|
+
_call(arg: z.output<typeof this.schema>): Promise<string>;
|
|
22
|
+
parseMessages(messages: gmail_v1.Schema$Message[]): Promise<gmail_v1.Schema$Message[]>;
|
|
23
|
+
parseThreads(threads: gmail_v1.Schema$Thread[]): Promise<gmail_v1.Schema$Thread[]>;
|
|
24
|
+
}
|
|
25
|
+
export type SearchSchema = {
|
|
26
|
+
query: string;
|
|
27
|
+
maxResults?: number;
|
|
28
|
+
resource?: "messages" | "threads";
|
|
29
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { GmailBaseTool } from "./base.js";
|
|
3
|
+
import { SEARCH_DESCRIPTION } from "./descriptions.js";
|
|
4
|
+
export class GmailSearch extends GmailBaseTool {
|
|
5
|
+
constructor(fields) {
|
|
6
|
+
super(fields);
|
|
7
|
+
Object.defineProperty(this, "name", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: "search_gmail"
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "schema", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: z.object({
|
|
18
|
+
query: z.string(),
|
|
19
|
+
maxResults: z.number().optional(),
|
|
20
|
+
resource: z.enum(["messages", "threads"]).optional(),
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "description", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: SEARCH_DESCRIPTION
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async _call(arg) {
|
|
31
|
+
const { query, maxResults = 10, resource = "messages" } = arg;
|
|
32
|
+
const response = await this.gmail.users.messages.list({
|
|
33
|
+
userId: "me",
|
|
34
|
+
q: query,
|
|
35
|
+
maxResults,
|
|
36
|
+
});
|
|
37
|
+
const { data } = response;
|
|
38
|
+
if (!data) {
|
|
39
|
+
throw new Error("No data returned from Gmail");
|
|
40
|
+
}
|
|
41
|
+
const { messages } = data;
|
|
42
|
+
if (!messages) {
|
|
43
|
+
throw new Error("No messages returned from Gmail");
|
|
44
|
+
}
|
|
45
|
+
if (resource === "messages") {
|
|
46
|
+
const parsedMessages = await this.parseMessages(messages);
|
|
47
|
+
return `Result for the query ${query}:\n${JSON.stringify(parsedMessages)}`;
|
|
48
|
+
}
|
|
49
|
+
else if (resource === "threads") {
|
|
50
|
+
const parsedThreads = await this.parseThreads(messages);
|
|
51
|
+
return `Result for the query ${query}:\n${JSON.stringify(parsedThreads)}`;
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`Invalid resource: ${resource}`);
|
|
54
|
+
}
|
|
55
|
+
async parseMessages(messages) {
|
|
56
|
+
const parsedMessages = await Promise.all(messages.map(async (message) => {
|
|
57
|
+
const messageData = await this.gmail.users.messages.get({
|
|
58
|
+
userId: "me",
|
|
59
|
+
format: "raw",
|
|
60
|
+
id: message.id ?? "",
|
|
61
|
+
});
|
|
62
|
+
const headers = messageData.data.payload?.headers || [];
|
|
63
|
+
const subject = headers.find((header) => header.name === "Subject");
|
|
64
|
+
const sender = headers.find((header) => header.name === "From");
|
|
65
|
+
let body = "";
|
|
66
|
+
if (messageData.data.payload?.parts) {
|
|
67
|
+
body = messageData.data.payload.parts
|
|
68
|
+
.map((part) => part.body?.data ?? "")
|
|
69
|
+
.join("");
|
|
70
|
+
}
|
|
71
|
+
else if (messageData.data.payload?.body?.data) {
|
|
72
|
+
body = messageData.data.payload.body.data;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
id: message.id,
|
|
76
|
+
threadId: message.threadId,
|
|
77
|
+
snippet: message.snippet,
|
|
78
|
+
body,
|
|
79
|
+
subject,
|
|
80
|
+
sender,
|
|
81
|
+
};
|
|
82
|
+
}));
|
|
83
|
+
return parsedMessages;
|
|
84
|
+
}
|
|
85
|
+
async parseThreads(threads) {
|
|
86
|
+
const parsedThreads = await Promise.all(threads.map(async (thread) => {
|
|
87
|
+
const threadData = await this.gmail.users.threads.get({
|
|
88
|
+
userId: "me",
|
|
89
|
+
format: "raw",
|
|
90
|
+
id: thread.id ?? "",
|
|
91
|
+
});
|
|
92
|
+
const headers = threadData.data.messages?.[0]?.payload?.headers || [];
|
|
93
|
+
const subject = headers.find((header) => header.name === "Subject");
|
|
94
|
+
const sender = headers.find((header) => header.name === "From");
|
|
95
|
+
let body = "";
|
|
96
|
+
if (threadData.data.messages?.[0]?.payload?.parts) {
|
|
97
|
+
body = threadData.data.messages[0].payload.parts
|
|
98
|
+
.map((part) => part.body?.data ?? "")
|
|
99
|
+
.join("");
|
|
100
|
+
}
|
|
101
|
+
else if (threadData.data.messages?.[0]?.payload?.body?.data) {
|
|
102
|
+
body = threadData.data.messages[0].payload.body.data;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
id: thread.id,
|
|
106
|
+
snippet: thread.snippet,
|
|
107
|
+
body,
|
|
108
|
+
subject,
|
|
109
|
+
sender,
|
|
110
|
+
};
|
|
111
|
+
}));
|
|
112
|
+
return parsedThreads;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GmailSendMessage = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const base_js_1 = require("./base.cjs");
|
|
6
|
+
const descriptions_js_1 = require("./descriptions.cjs");
|
|
7
|
+
class GmailSendMessage extends base_js_1.GmailBaseTool {
|
|
8
|
+
constructor(fields) {
|
|
9
|
+
super(fields);
|
|
10
|
+
Object.defineProperty(this, "name", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: "gmail_send_message"
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "schema", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: zod_1.z.object({
|
|
21
|
+
message: zod_1.z.string(),
|
|
22
|
+
to: zod_1.z.array(zod_1.z.string()),
|
|
23
|
+
subject: zod_1.z.string(),
|
|
24
|
+
cc: zod_1.z.array(zod_1.z.string()).optional(),
|
|
25
|
+
bcc: zod_1.z.array(zod_1.z.string()).optional(),
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "description", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: descriptions_js_1.GET_MESSAGE_DESCRIPTION
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
createEmailMessage({ message, to, subject, cc, bcc, }) {
|
|
36
|
+
const emailLines = [];
|
|
37
|
+
// Format the recipient(s)
|
|
38
|
+
const formatEmailList = (emails) => Array.isArray(emails) ? emails.join(",") : emails;
|
|
39
|
+
emailLines.push(`To: ${formatEmailList(to)}`);
|
|
40
|
+
if (cc)
|
|
41
|
+
emailLines.push(`Cc: ${formatEmailList(cc)}`);
|
|
42
|
+
if (bcc)
|
|
43
|
+
emailLines.push(`Bcc: ${formatEmailList(bcc)}`);
|
|
44
|
+
emailLines.push(`Subject: ${subject}`);
|
|
45
|
+
emailLines.push("");
|
|
46
|
+
emailLines.push(message);
|
|
47
|
+
// Convert the email message to base64url string
|
|
48
|
+
const email = emailLines.join("\r\n").trim();
|
|
49
|
+
// this encode may be an issue
|
|
50
|
+
return Buffer.from(email).toString("base64url");
|
|
51
|
+
}
|
|
52
|
+
async _call({ message, to, subject, cc, bcc, }) {
|
|
53
|
+
const rawMessage = this.createEmailMessage({
|
|
54
|
+
message,
|
|
55
|
+
to,
|
|
56
|
+
subject,
|
|
57
|
+
cc,
|
|
58
|
+
bcc,
|
|
59
|
+
});
|
|
60
|
+
try {
|
|
61
|
+
const response = await this.gmail.users.messages.send({
|
|
62
|
+
userId: "me",
|
|
63
|
+
requestBody: {
|
|
64
|
+
raw: rawMessage,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
return `Message sent. Message Id: ${response.data.id}`;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw new Error(`An error occurred while sending the message: ${error}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.GmailSendMessage = GmailSendMessage;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { GmailBaseTool, GmailBaseToolParams } from "./base.js";
|
|
3
|
+
export declare class GmailSendMessage extends GmailBaseTool {
|
|
4
|
+
name: string;
|
|
5
|
+
schema: z.ZodObject<{
|
|
6
|
+
message: z.ZodString;
|
|
7
|
+
to: z.ZodArray<z.ZodString, "many">;
|
|
8
|
+
subject: z.ZodString;
|
|
9
|
+
cc: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
10
|
+
bcc: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
message: string;
|
|
13
|
+
subject: string;
|
|
14
|
+
to: string[];
|
|
15
|
+
cc?: string[] | undefined;
|
|
16
|
+
bcc?: string[] | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
message: string;
|
|
19
|
+
subject: string;
|
|
20
|
+
to: string[];
|
|
21
|
+
cc?: string[] | undefined;
|
|
22
|
+
bcc?: string[] | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
description: string;
|
|
25
|
+
constructor(fields?: GmailBaseToolParams);
|
|
26
|
+
private createEmailMessage;
|
|
27
|
+
_call({ message, to, subject, cc, bcc, }: z.output<typeof this.schema>): Promise<string>;
|
|
28
|
+
}
|
|
29
|
+
export type SendMessageSchema = {
|
|
30
|
+
message: string;
|
|
31
|
+
to: string[];
|
|
32
|
+
subject: string;
|
|
33
|
+
cc?: string[];
|
|
34
|
+
bcc?: string[];
|
|
35
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { GmailBaseTool } from "./base.js";
|
|
3
|
+
import { GET_MESSAGE_DESCRIPTION } from "./descriptions.js";
|
|
4
|
+
export class GmailSendMessage extends GmailBaseTool {
|
|
5
|
+
constructor(fields) {
|
|
6
|
+
super(fields);
|
|
7
|
+
Object.defineProperty(this, "name", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: "gmail_send_message"
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "schema", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: z.object({
|
|
18
|
+
message: z.string(),
|
|
19
|
+
to: z.array(z.string()),
|
|
20
|
+
subject: z.string(),
|
|
21
|
+
cc: z.array(z.string()).optional(),
|
|
22
|
+
bcc: z.array(z.string()).optional(),
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "description", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: GET_MESSAGE_DESCRIPTION
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
createEmailMessage({ message, to, subject, cc, bcc, }) {
|
|
33
|
+
const emailLines = [];
|
|
34
|
+
// Format the recipient(s)
|
|
35
|
+
const formatEmailList = (emails) => Array.isArray(emails) ? emails.join(",") : emails;
|
|
36
|
+
emailLines.push(`To: ${formatEmailList(to)}`);
|
|
37
|
+
if (cc)
|
|
38
|
+
emailLines.push(`Cc: ${formatEmailList(cc)}`);
|
|
39
|
+
if (bcc)
|
|
40
|
+
emailLines.push(`Bcc: ${formatEmailList(bcc)}`);
|
|
41
|
+
emailLines.push(`Subject: ${subject}`);
|
|
42
|
+
emailLines.push("");
|
|
43
|
+
emailLines.push(message);
|
|
44
|
+
// Convert the email message to base64url string
|
|
45
|
+
const email = emailLines.join("\r\n").trim();
|
|
46
|
+
// this encode may be an issue
|
|
47
|
+
return Buffer.from(email).toString("base64url");
|
|
48
|
+
}
|
|
49
|
+
async _call({ message, to, subject, cc, bcc, }) {
|
|
50
|
+
const rawMessage = this.createEmailMessage({
|
|
51
|
+
message,
|
|
52
|
+
to,
|
|
53
|
+
subject,
|
|
54
|
+
cc,
|
|
55
|
+
bcc,
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
const response = await this.gmail.users.messages.send({
|
|
59
|
+
userId: "me",
|
|
60
|
+
requestBody: {
|
|
61
|
+
raw: rawMessage,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
return `Message sent. Message Id: ${response.data.id}`;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw new Error(`An error occurred while sending the message: ${error}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -41,7 +41,7 @@ class WolframAlphaTool extends base_js_1.Tool {
|
|
|
41
41
|
return "WolframAlphaTool";
|
|
42
42
|
}
|
|
43
43
|
async _call(query) {
|
|
44
|
-
const url = `https://www.wolframalpha.com/api/v1/llm-api?appid=${this.appid}&input=${query}`;
|
|
44
|
+
const url = `https://www.wolframalpha.com/api/v1/llm-api?appid=${this.appid}&input=${encodeURIComponent(query)}`;
|
|
45
45
|
const res = await fetch(url);
|
|
46
46
|
return res.text();
|
|
47
47
|
}
|
|
@@ -38,7 +38,7 @@ export class WolframAlphaTool extends Tool {
|
|
|
38
38
|
return "WolframAlphaTool";
|
|
39
39
|
}
|
|
40
40
|
async _call(query) {
|
|
41
|
-
const url = `https://www.wolframalpha.com/api/v1/llm-api?appid=${this.appid}&input=${query}`;
|
|
41
|
+
const url = `https://www.wolframalpha.com/api/v1/llm-api?appid=${this.appid}&input=${encodeURIComponent(query)}`;
|
|
42
42
|
const res = await fetch(url);
|
|
43
43
|
return res.text();
|
|
44
44
|
}
|
package/dist/util/stream.cjs
CHANGED
|
@@ -1,87 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
class IterableReadableStream extends ReadableStream {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(...arguments);
|
|
11
|
-
Object.defineProperty(this, "reader", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: void 0
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
ensureReader() {
|
|
19
|
-
if (!this.reader) {
|
|
20
|
-
this.reader = this.getReader();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
async next() {
|
|
24
|
-
this.ensureReader();
|
|
25
|
-
try {
|
|
26
|
-
const result = await this.reader.read();
|
|
27
|
-
if (result.done)
|
|
28
|
-
this.reader.releaseLock(); // release lock when stream becomes closed
|
|
29
|
-
return {
|
|
30
|
-
done: result.done,
|
|
31
|
-
value: result.value, // Cloudflare Workers typing fix
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
catch (e) {
|
|
35
|
-
this.reader.releaseLock(); // release lock when stream becomes errored
|
|
36
|
-
throw e;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async return() {
|
|
40
|
-
this.ensureReader();
|
|
41
|
-
const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet
|
|
42
|
-
this.reader.releaseLock(); // release lock first
|
|
43
|
-
await cancelPromise; // now await it
|
|
44
|
-
return { done: true, value: undefined }; // This cast fixes TS typing, and convention is to ignore final chunk value anyway
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
45
7
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return reader.read().then(({ done, value }) => {
|
|
57
|
-
// When no more data needs to be consumed, close the stream
|
|
58
|
-
if (done) {
|
|
59
|
-
controller.close();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// Enqueue the next data chunk into our target stream
|
|
63
|
-
controller.enqueue(value);
|
|
64
|
-
return pump();
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
cancel() {
|
|
69
|
-
reader.releaseLock();
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
static fromAsyncGenerator(generator) {
|
|
74
|
-
return new IterableReadableStream({
|
|
75
|
-
async pull(controller) {
|
|
76
|
-
const { value, done } = await generator.next();
|
|
77
|
-
// When no more data needs to be consumed, close the stream
|
|
78
|
-
if (done) {
|
|
79
|
-
controller.close();
|
|
80
|
-
}
|
|
81
|
-
// Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled
|
|
82
|
-
controller.enqueue(value);
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.IterableReadableStream = IterableReadableStream;
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@langchain/core/utils/stream"), exports);
|
package/dist/util/stream.d.ts
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
reader: ReadableStreamDefaultReader<T>;
|
|
3
|
-
ensureReader(): void;
|
|
4
|
-
next(): Promise<{
|
|
5
|
-
done: boolean;
|
|
6
|
-
value: T;
|
|
7
|
-
}>;
|
|
8
|
-
return(): Promise<{
|
|
9
|
-
done: boolean;
|
|
10
|
-
value: T;
|
|
11
|
-
}>;
|
|
12
|
-
[Symbol.asyncIterator](): this;
|
|
13
|
-
static fromReadableStream<T>(stream: ReadableStream<T>): IterableReadableStream<T>;
|
|
14
|
-
static fromAsyncGenerator<T>(generator: AsyncGenerator<T>): IterableReadableStream<T>;
|
|
15
|
-
}
|
|
1
|
+
export * from "@langchain/core/utils/stream";
|
package/dist/util/stream.js
CHANGED
|
@@ -1,83 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Support async iterator syntax for ReadableStreams in all environments.
|
|
3
|
-
* Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
4
|
-
*/
|
|
5
|
-
export class IterableReadableStream extends ReadableStream {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
Object.defineProperty(this, "reader", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
configurable: true,
|
|
11
|
-
writable: true,
|
|
12
|
-
value: void 0
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
ensureReader() {
|
|
16
|
-
if (!this.reader) {
|
|
17
|
-
this.reader = this.getReader();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async next() {
|
|
21
|
-
this.ensureReader();
|
|
22
|
-
try {
|
|
23
|
-
const result = await this.reader.read();
|
|
24
|
-
if (result.done)
|
|
25
|
-
this.reader.releaseLock(); // release lock when stream becomes closed
|
|
26
|
-
return {
|
|
27
|
-
done: result.done,
|
|
28
|
-
value: result.value, // Cloudflare Workers typing fix
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
this.reader.releaseLock(); // release lock when stream becomes errored
|
|
33
|
-
throw e;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async return() {
|
|
37
|
-
this.ensureReader();
|
|
38
|
-
const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet
|
|
39
|
-
this.reader.releaseLock(); // release lock first
|
|
40
|
-
await cancelPromise; // now await it
|
|
41
|
-
return { done: true, value: undefined }; // This cast fixes TS typing, and convention is to ignore final chunk value anyway
|
|
42
|
-
}
|
|
43
|
-
[Symbol.asyncIterator]() {
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
static fromReadableStream(stream) {
|
|
47
|
-
// From https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream
|
|
48
|
-
const reader = stream.getReader();
|
|
49
|
-
return new IterableReadableStream({
|
|
50
|
-
start(controller) {
|
|
51
|
-
return pump();
|
|
52
|
-
function pump() {
|
|
53
|
-
return reader.read().then(({ done, value }) => {
|
|
54
|
-
// When no more data needs to be consumed, close the stream
|
|
55
|
-
if (done) {
|
|
56
|
-
controller.close();
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
// Enqueue the next data chunk into our target stream
|
|
60
|
-
controller.enqueue(value);
|
|
61
|
-
return pump();
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
cancel() {
|
|
66
|
-
reader.releaseLock();
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
static fromAsyncGenerator(generator) {
|
|
71
|
-
return new IterableReadableStream({
|
|
72
|
-
async pull(controller) {
|
|
73
|
-
const { value, done } = await generator.next();
|
|
74
|
-
// When no more data needs to be consumed, close the stream
|
|
75
|
-
if (done) {
|
|
76
|
-
controller.close();
|
|
77
|
-
}
|
|
78
|
-
// Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled
|
|
79
|
-
controller.enqueue(value);
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
export * from "@langchain/core/utils/stream";
|
|
@@ -89,7 +89,7 @@ class XataVectorSearch extends base_js_1.VectorStore {
|
|
|
89
89
|
* @returns Promise resolving to an array of tuples, each containing a Document and its score.
|
|
90
90
|
*/
|
|
91
91
|
async similaritySearchVectorWithScore(query, k, filter) {
|
|
92
|
-
const records = await this.client.db[this.table].vectorSearch("embedding", query, {
|
|
92
|
+
const { records } = await this.client.db[this.table].vectorSearch("embedding", query, {
|
|
93
93
|
size: k,
|
|
94
94
|
filter,
|
|
95
95
|
});
|