langchain 0.0.158 → 0.0.160

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.
Files changed (58) hide show
  1. package/dist/chat_models/bedrock.cjs +28 -13
  2. package/dist/chat_models/bedrock.d.ts +6 -1
  3. package/dist/chat_models/bedrock.js +28 -13
  4. package/dist/llms/bedrock.cjs +29 -13
  5. package/dist/llms/bedrock.d.ts +6 -1
  6. package/dist/llms/bedrock.js +29 -13
  7. package/dist/load/import_constants.cjs +1 -0
  8. package/dist/load/import_constants.js +1 -0
  9. package/dist/prompts/few_shot.d.ts +1 -1
  10. package/dist/prompts/prompt.cjs +0 -3
  11. package/dist/prompts/prompt.d.ts +1 -1
  12. package/dist/prompts/prompt.js +0 -3
  13. package/dist/prompts/template.cjs +0 -2
  14. package/dist/prompts/template.d.ts +3 -3
  15. package/dist/prompts/template.js +0 -2
  16. package/dist/tools/google_calendar/base.cjs +94 -0
  17. package/dist/tools/google_calendar/base.d.ts +24 -0
  18. package/dist/tools/google_calendar/base.js +90 -0
  19. package/dist/tools/google_calendar/commands/run-create-events.cjs +71 -0
  20. package/dist/tools/google_calendar/commands/run-create-events.d.ts +10 -0
  21. package/dist/tools/google_calendar/commands/run-create-events.js +68 -0
  22. package/dist/tools/google_calendar/commands/run-view-events.cjs +50 -0
  23. package/dist/tools/google_calendar/commands/run-view-events.d.ts +10 -0
  24. package/dist/tools/google_calendar/commands/run-view-events.js +47 -0
  25. package/dist/tools/google_calendar/create.cjs +33 -0
  26. package/dist/tools/google_calendar/create.d.ts +8 -0
  27. package/dist/tools/google_calendar/create.js +29 -0
  28. package/dist/tools/google_calendar/descriptions.cjs +26 -0
  29. package/dist/tools/google_calendar/descriptions.d.ts +2 -0
  30. package/dist/tools/google_calendar/descriptions.js +23 -0
  31. package/dist/tools/google_calendar/index.cjs +7 -0
  32. package/dist/tools/google_calendar/index.d.ts +3 -0
  33. package/dist/tools/google_calendar/index.js +2 -0
  34. package/dist/tools/google_calendar/prompts/create-event-prompt.cjs +59 -0
  35. package/dist/tools/google_calendar/prompts/create-event-prompt.d.ts +1 -0
  36. package/dist/tools/google_calendar/prompts/create-event-prompt.js +56 -0
  37. package/dist/tools/google_calendar/prompts/index.cjs +7 -0
  38. package/dist/tools/google_calendar/prompts/index.d.ts +2 -0
  39. package/dist/tools/google_calendar/prompts/index.js +2 -0
  40. package/dist/tools/google_calendar/prompts/view-events-prompt.cjs +37 -0
  41. package/dist/tools/google_calendar/prompts/view-events-prompt.d.ts +1 -0
  42. package/dist/tools/google_calendar/prompts/view-events-prompt.js +34 -0
  43. package/dist/tools/google_calendar/utils/get-timezone-offset-in-hours.cjs +9 -0
  44. package/dist/tools/google_calendar/utils/get-timezone-offset-in-hours.d.ts +2 -0
  45. package/dist/tools/google_calendar/utils/get-timezone-offset-in-hours.js +6 -0
  46. package/dist/tools/google_calendar/view.cjs +33 -0
  47. package/dist/tools/google_calendar/view.d.ts +8 -0
  48. package/dist/tools/google_calendar/view.js +29 -0
  49. package/dist/vectorstores/pinecone.cjs +21 -34
  50. package/dist/vectorstores/pinecone.d.ts +6 -9
  51. package/dist/vectorstores/pinecone.js +21 -34
  52. package/dist/vectorstores/vectara.cjs +9 -0
  53. package/dist/vectorstores/vectara.d.ts +3 -0
  54. package/dist/vectorstores/vectara.js +9 -0
  55. package/package.json +17 -4
  56. package/tools/google_calendar.cjs +1 -0
  57. package/tools/google_calendar.d.ts +1 -0
  58. package/tools/google_calendar.js +1 -0
@@ -161,20 +161,23 @@ class ChatBedrock extends base_js_1.SimpleChatModel {
161
161
  Example:
162
162
  response = model.call("Tell me a joke.")
163
163
  */
164
- async _call(messages, options, runManager) {
165
- const chunks = [];
166
- for await (const chunk of this._streamResponseChunks(messages, options, runManager)) {
167
- chunks.push(chunk);
168
- }
169
- return chunks.map((chunk) => chunk.text).join("");
170
- }
171
- async *_streamResponseChunks(messages, options, runManager) {
172
- const provider = this.model.split(".")[0];
164
+ async _call(messages, options) {
173
165
  const service = "bedrock-runtime";
174
- const inputBody = bedrock_js_1.BedrockLLMInputOutputAdapter.prepareInput(provider, convertMessagesToPromptAnthropic(messages), this.maxTokens, this.temperature, this.stopSequences, this.modelKwargs);
175
166
  const endpointHost = this.endpointHost ?? `${service}.${this.region}.amazonaws.com`;
176
- const amazonMethod = provider === "anthropic" ? "invoke-with-response-stream" : "invoke";
177
- const url = new URL(`https://${endpointHost}/model/${this.model}/${amazonMethod}`);
167
+ const provider = this.model.split(".")[0];
168
+ const response = await this._signedFetch(messages, options, {
169
+ bedrockMethod: "invoke",
170
+ endpointHost,
171
+ provider,
172
+ });
173
+ const json = await response.json();
174
+ const text = bedrock_js_1.BedrockLLMInputOutputAdapter.prepareOutput(provider, json);
175
+ return text;
176
+ }
177
+ async _signedFetch(messages, options, fields) {
178
+ const { bedrockMethod, endpointHost, provider } = fields;
179
+ const inputBody = bedrock_js_1.BedrockLLMInputOutputAdapter.prepareInput(provider, convertMessagesToPromptAnthropic(messages), this.maxTokens, this.temperature, this.stopSequences, this.modelKwargs);
180
+ const url = new URL(`https://${endpointHost}/model/${this.model}/${bedrockMethod}`);
178
181
  const request = new protocol_http_1.HttpRequest({
179
182
  hostname: url.hostname,
180
183
  path: url.pathname,
@@ -202,8 +205,20 @@ class ChatBedrock extends base_js_1.SimpleChatModel {
202
205
  body: signedRequest.body,
203
206
  method: signedRequest.method,
204
207
  }));
208
+ return response;
209
+ }
210
+ async *_streamResponseChunks(messages, options, runManager) {
211
+ const provider = this.model.split(".")[0];
212
+ const service = "bedrock-runtime";
213
+ const endpointHost = this.endpointHost ?? `${service}.${this.region}.amazonaws.com`;
214
+ const bedrockMethod = provider === "anthropic" ? "invoke-with-response-stream" : "invoke";
215
+ const response = await this._signedFetch(messages, options, {
216
+ bedrockMethod,
217
+ endpointHost,
218
+ provider,
219
+ });
205
220
  if (response.status < 200 || response.status >= 300) {
206
- throw Error(`Failed to access underlying url '${url}': got ${response.status} ${response.statusText}: ${await response.text()}`);
221
+ throw Error(`Failed to access underlying url '${endpointHost}': got ${response.status} ${response.statusText}: ${await response.text()}`);
207
222
  }
208
223
  if (provider === "anthropic") {
209
224
  const reader = response.body?.getReader();
@@ -49,7 +49,12 @@ export declare class ChatBedrock extends SimpleChatModel implements BaseBedrockI
49
49
  Example:
50
50
  response = model.call("Tell me a joke.")
51
51
  */
52
- _call(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<string>;
52
+ _call(messages: BaseMessage[], options: this["ParsedCallOptions"]): Promise<string>;
53
+ _signedFetch(messages: BaseMessage[], options: this["ParsedCallOptions"], fields: {
54
+ bedrockMethod: "invoke" | "invoke-with-response-stream";
55
+ endpointHost: string;
56
+ provider: string;
57
+ }): Promise<Response>;
53
58
  _streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
54
59
  _readChunks(reader: any): {
55
60
  [Symbol.asyncIterator](): AsyncGenerator<any, void, unknown>;
@@ -156,20 +156,23 @@ export class ChatBedrock extends SimpleChatModel {
156
156
  Example:
157
157
  response = model.call("Tell me a joke.")
158
158
  */
159
- async _call(messages, options, runManager) {
160
- const chunks = [];
161
- for await (const chunk of this._streamResponseChunks(messages, options, runManager)) {
162
- chunks.push(chunk);
163
- }
164
- return chunks.map((chunk) => chunk.text).join("");
165
- }
166
- async *_streamResponseChunks(messages, options, runManager) {
167
- const provider = this.model.split(".")[0];
159
+ async _call(messages, options) {
168
160
  const service = "bedrock-runtime";
169
- const inputBody = BedrockLLMInputOutputAdapter.prepareInput(provider, convertMessagesToPromptAnthropic(messages), this.maxTokens, this.temperature, this.stopSequences, this.modelKwargs);
170
161
  const endpointHost = this.endpointHost ?? `${service}.${this.region}.amazonaws.com`;
171
- const amazonMethod = provider === "anthropic" ? "invoke-with-response-stream" : "invoke";
172
- const url = new URL(`https://${endpointHost}/model/${this.model}/${amazonMethod}`);
162
+ const provider = this.model.split(".")[0];
163
+ const response = await this._signedFetch(messages, options, {
164
+ bedrockMethod: "invoke",
165
+ endpointHost,
166
+ provider,
167
+ });
168
+ const json = await response.json();
169
+ const text = BedrockLLMInputOutputAdapter.prepareOutput(provider, json);
170
+ return text;
171
+ }
172
+ async _signedFetch(messages, options, fields) {
173
+ const { bedrockMethod, endpointHost, provider } = fields;
174
+ const inputBody = BedrockLLMInputOutputAdapter.prepareInput(provider, convertMessagesToPromptAnthropic(messages), this.maxTokens, this.temperature, this.stopSequences, this.modelKwargs);
175
+ const url = new URL(`https://${endpointHost}/model/${this.model}/${bedrockMethod}`);
173
176
  const request = new HttpRequest({
174
177
  hostname: url.hostname,
175
178
  path: url.pathname,
@@ -197,8 +200,20 @@ export class ChatBedrock extends SimpleChatModel {
197
200
  body: signedRequest.body,
198
201
  method: signedRequest.method,
199
202
  }));
203
+ return response;
204
+ }
205
+ async *_streamResponseChunks(messages, options, runManager) {
206
+ const provider = this.model.split(".")[0];
207
+ const service = "bedrock-runtime";
208
+ const endpointHost = this.endpointHost ?? `${service}.${this.region}.amazonaws.com`;
209
+ const bedrockMethod = provider === "anthropic" ? "invoke-with-response-stream" : "invoke";
210
+ const response = await this._signedFetch(messages, options, {
211
+ bedrockMethod,
212
+ endpointHost,
213
+ provider,
214
+ });
200
215
  if (response.status < 200 || response.status >= 300) {
201
- throw Error(`Failed to access underlying url '${url}': got ${response.status} ${response.statusText}: ${await response.text()}`);
216
+ throw Error(`Failed to access underlying url '${endpointHost}': got ${response.status} ${response.statusText}: ${await response.text()}`);
202
217
  }
203
218
  if (provider === "anthropic") {
204
219
  const reader = response.body?.getReader();
@@ -120,20 +120,23 @@ class Bedrock extends base_js_1.LLM {
120
120
  Example:
121
121
  response = model.call("Tell me a joke.")
122
122
  */
123
- async _call(prompt, options, runManager) {
124
- const chunks = [];
125
- for await (const chunk of this._streamResponseChunks(prompt, options, runManager)) {
126
- chunks.push(chunk);
127
- }
128
- return chunks.map((chunk) => chunk.text).join("");
129
- }
130
- async *_streamResponseChunks(prompt, options, runManager) {
131
- const provider = this.model.split(".")[0];
123
+ async _call(prompt, options) {
132
124
  const service = "bedrock-runtime";
133
- const inputBody = bedrock_js_1.BedrockLLMInputOutputAdapter.prepareInput(provider, prompt, this.maxTokens, this.temperature, this.stopSequences, this.modelKwargs);
134
125
  const endpointHost = this.endpointHost ?? `${service}.${this.region}.amazonaws.com`;
135
- const amazonMethod = provider === "anthropic" ? "invoke-with-response-stream" : "invoke";
136
- const url = new URL(`https://${endpointHost}/model/${this.model}/${amazonMethod}`);
126
+ const provider = this.model.split(".")[0];
127
+ const response = await this._signedFetch(prompt, options, {
128
+ bedrockMethod: "invoke",
129
+ endpointHost,
130
+ provider,
131
+ });
132
+ const json = await response.json();
133
+ const text = bedrock_js_1.BedrockLLMInputOutputAdapter.prepareOutput(provider, json);
134
+ return text;
135
+ }
136
+ async _signedFetch(prompt, options, fields) {
137
+ const { bedrockMethod, endpointHost, provider } = fields;
138
+ const inputBody = bedrock_js_1.BedrockLLMInputOutputAdapter.prepareInput(provider, prompt, this.maxTokens, this.temperature, this.stopSequences, this.modelKwargs);
139
+ const url = new URL(`https://${endpointHost}/model/${this.model}/${bedrockMethod}`);
137
140
  const request = new protocol_http_1.HttpRequest({
138
141
  hostname: url.hostname,
139
142
  path: url.pathname,
@@ -161,8 +164,21 @@ class Bedrock extends base_js_1.LLM {
161
164
  body: signedRequest.body,
162
165
  method: signedRequest.method,
163
166
  }));
167
+ return response;
168
+ }
169
+ async *_streamResponseChunks(prompt, options, runManager) {
170
+ const provider = this.model.split(".")[0];
171
+ const bedrockMethod = provider === "anthropic" ? "invoke-with-response-stream" : "invoke";
172
+ const service = "bedrock-runtime";
173
+ const endpointHost = this.endpointHost ?? `${service}.${this.region}.amazonaws.com`;
174
+ // Send request to AWS using the low-level fetch API
175
+ const response = await this._signedFetch(prompt, options, {
176
+ bedrockMethod,
177
+ endpointHost,
178
+ provider,
179
+ });
164
180
  if (response.status < 200 || response.status >= 300) {
165
- throw Error(`Failed to access underlying url '${url}': got ${response.status} ${response.statusText}: ${await response.text()}`);
181
+ throw Error(`Failed to access underlying url '${endpointHost}': got ${response.status} ${response.statusText}: ${await response.text()}`);
166
182
  }
167
183
  if (provider === "anthropic") {
168
184
  const reader = response.body?.getReader();
@@ -39,7 +39,12 @@ export declare class Bedrock extends LLM implements BaseBedrockInput {
39
39
  Example:
40
40
  response = model.call("Tell me a joke.")
41
41
  */
42
- _call(prompt: string, options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<string>;
42
+ _call(prompt: string, options: this["ParsedCallOptions"]): Promise<string>;
43
+ _signedFetch(prompt: string, options: this["ParsedCallOptions"], fields: {
44
+ bedrockMethod: "invoke" | "invoke-with-response-stream";
45
+ endpointHost: string;
46
+ provider: string;
47
+ }): Promise<Response>;
43
48
  _streamResponseChunks(prompt: string, options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;
44
49
  _readChunks(reader: any): {
45
50
  [Symbol.asyncIterator](): AsyncGenerator<any, void, unknown>;
@@ -117,20 +117,23 @@ export class Bedrock extends LLM {
117
117
  Example:
118
118
  response = model.call("Tell me a joke.")
119
119
  */
120
- async _call(prompt, options, runManager) {
121
- const chunks = [];
122
- for await (const chunk of this._streamResponseChunks(prompt, options, runManager)) {
123
- chunks.push(chunk);
124
- }
125
- return chunks.map((chunk) => chunk.text).join("");
126
- }
127
- async *_streamResponseChunks(prompt, options, runManager) {
128
- const provider = this.model.split(".")[0];
120
+ async _call(prompt, options) {
129
121
  const service = "bedrock-runtime";
130
- const inputBody = BedrockLLMInputOutputAdapter.prepareInput(provider, prompt, this.maxTokens, this.temperature, this.stopSequences, this.modelKwargs);
131
122
  const endpointHost = this.endpointHost ?? `${service}.${this.region}.amazonaws.com`;
132
- const amazonMethod = provider === "anthropic" ? "invoke-with-response-stream" : "invoke";
133
- const url = new URL(`https://${endpointHost}/model/${this.model}/${amazonMethod}`);
123
+ const provider = this.model.split(".")[0];
124
+ const response = await this._signedFetch(prompt, options, {
125
+ bedrockMethod: "invoke",
126
+ endpointHost,
127
+ provider,
128
+ });
129
+ const json = await response.json();
130
+ const text = BedrockLLMInputOutputAdapter.prepareOutput(provider, json);
131
+ return text;
132
+ }
133
+ async _signedFetch(prompt, options, fields) {
134
+ const { bedrockMethod, endpointHost, provider } = fields;
135
+ const inputBody = BedrockLLMInputOutputAdapter.prepareInput(provider, prompt, this.maxTokens, this.temperature, this.stopSequences, this.modelKwargs);
136
+ const url = new URL(`https://${endpointHost}/model/${this.model}/${bedrockMethod}`);
134
137
  const request = new HttpRequest({
135
138
  hostname: url.hostname,
136
139
  path: url.pathname,
@@ -158,8 +161,21 @@ export class Bedrock extends LLM {
158
161
  body: signedRequest.body,
159
162
  method: signedRequest.method,
160
163
  }));
164
+ return response;
165
+ }
166
+ async *_streamResponseChunks(prompt, options, runManager) {
167
+ const provider = this.model.split(".")[0];
168
+ const bedrockMethod = provider === "anthropic" ? "invoke-with-response-stream" : "invoke";
169
+ const service = "bedrock-runtime";
170
+ const endpointHost = this.endpointHost ?? `${service}.${this.region}.amazonaws.com`;
171
+ // Send request to AWS using the low-level fetch API
172
+ const response = await this._signedFetch(prompt, options, {
173
+ bedrockMethod,
174
+ endpointHost,
175
+ provider,
176
+ });
161
177
  if (response.status < 200 || response.status >= 300) {
162
- throw Error(`Failed to access underlying url '${url}': got ${response.status} ${response.statusText}: ${await response.text()}`);
178
+ throw Error(`Failed to access underlying url '${endpointHost}': got ${response.status} ${response.statusText}: ${await response.text()}`);
163
179
  }
164
180
  if (provider === "anthropic") {
165
181
  const reader = response.body?.getReader();
@@ -11,6 +11,7 @@ exports.optionalImportEntrypoints = [
11
11
  "langchain/tools/calculator",
12
12
  "langchain/tools/sql",
13
13
  "langchain/tools/webbrowser",
14
+ "langchain/tools/google_calendar",
14
15
  "langchain/chains/load",
15
16
  "langchain/chains/query_constructor",
16
17
  "langchain/chains/query_constructor/ir",
@@ -8,6 +8,7 @@ export const optionalImportEntrypoints = [
8
8
  "langchain/tools/calculator",
9
9
  "langchain/tools/sql",
10
10
  "langchain/tools/webbrowser",
11
+ "langchain/tools/google_calendar",
11
12
  "langchain/chains/load",
12
13
  "langchain/chains/query_constructor",
13
14
  "langchain/chains/query_constructor/ir",
@@ -35,7 +35,7 @@ export interface FewShotPromptTemplateInput extends BasePromptTemplateInput<Inpu
35
35
  */
36
36
  suffix?: string;
37
37
  /**
38
- * The format of the prompt template. Options are: 'f-string', 'jinja-2'
38
+ * The format of the prompt template. Options are: 'f-string'
39
39
  */
40
40
  templateFormat?: TemplateFormat;
41
41
  /**
@@ -89,9 +89,6 @@ class PromptTemplate extends base_js_1.BaseStringPromptTemplate {
89
89
  * Load prompt template from a template f-string
90
90
  */
91
91
  static fromTemplate(template, { templateFormat = "f-string", ...rest } = {}) {
92
- if (templateFormat === "jinja2") {
93
- throw new Error("jinja2 templates are not currently supported.");
94
- }
95
92
  const names = new Set();
96
93
  (0, template_js_1.parseTemplate)(template, templateFormat).forEach((node) => {
97
94
  if (node.type === "variable") {
@@ -12,7 +12,7 @@ export interface PromptTemplateInput<RunInput extends InputValues = any, Partial
12
12
  */
13
13
  template: string;
14
14
  /**
15
- * The format of the prompt template. Options are 'f-string', 'jinja-2'
15
+ * The format of the prompt template. Options are 'f-string'
16
16
  *
17
17
  * @defaultValue 'f-string'
18
18
  */
@@ -86,9 +86,6 @@ export class PromptTemplate extends BaseStringPromptTemplate {
86
86
  * Load prompt template from a template f-string
87
87
  */
88
88
  static fromTemplate(template, { templateFormat = "f-string", ...rest } = {}) {
89
- if (templateFormat === "jinja2") {
90
- throw new Error("jinja2 templates are not currently supported.");
91
- }
92
89
  const names = new Set();
93
90
  parseTemplate(template, templateFormat).forEach((node) => {
94
91
  if (node.type === "variable") {
@@ -62,11 +62,9 @@ const interpolateFString = (template, values) => (0, exports.parseFString)(templ
62
62
  exports.interpolateFString = interpolateFString;
63
63
  exports.DEFAULT_FORMATTER_MAPPING = {
64
64
  "f-string": exports.interpolateFString,
65
- jinja2: (_, __) => "",
66
65
  };
67
66
  exports.DEFAULT_PARSER_MAPPING = {
68
67
  "f-string": exports.parseFString,
69
- jinja2: (_) => [],
70
68
  };
71
69
  const renderTemplate = (template, templateFormat, inputValues) => exports.DEFAULT_FORMATTER_MAPPING[templateFormat](template, inputValues);
72
70
  exports.renderTemplate = renderTemplate;
@@ -1,9 +1,9 @@
1
1
  import { InputValues } from "../schema/index.js";
2
2
  /**
3
- * Type that specifies the format of a template. It can be either
4
- * "f-string" or "jinja2".
3
+ * Type that specifies the format of a template. Only
4
+ * "f-string" is supported currently.
5
5
  */
6
- export type TemplateFormat = "f-string" | "jinja2";
6
+ export type TemplateFormat = "f-string";
7
7
  /**
8
8
  * Type that represents a node in a parsed format string. It can be either
9
9
  * a literal text or a variable name.
@@ -57,11 +57,9 @@ export const interpolateFString = (template, values) => parseFString(template).r
57
57
  }, "");
58
58
  export const DEFAULT_FORMATTER_MAPPING = {
59
59
  "f-string": interpolateFString,
60
- jinja2: (_, __) => "",
61
60
  };
62
61
  export const DEFAULT_PARSER_MAPPING = {
63
62
  "f-string": parseFString,
64
- jinja2: (_) => [],
65
63
  };
66
64
  export const renderTemplate = (template, templateFormat, inputValues) => DEFAULT_FORMATTER_MAPPING[templateFormat](template, inputValues);
67
65
  export const parseTemplate = (template, templateFormat) => DEFAULT_PARSER_MAPPING[templateFormat](template);
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GoogleCalendarBase = void 0;
4
+ const googleapis_1 = require("googleapis");
5
+ const base_js_1 = require("../base.cjs");
6
+ const env_js_1 = require("../../util/env.cjs");
7
+ class GoogleCalendarBase extends base_js_1.Tool {
8
+ constructor(fields = {
9
+ credentials: {
10
+ clientEmail: (0, env_js_1.getEnvironmentVariable)("GOOGLE_CALENDAR_CLIENT_EMAIL"),
11
+ privateKey: (0, env_js_1.getEnvironmentVariable)("GOOGLE_CALENDAR_PRIVATE_KEY"),
12
+ calendarId: (0, env_js_1.getEnvironmentVariable)("GOOGLE_CALENDAR_CALENDAR_ID"),
13
+ },
14
+ scopes: [
15
+ "https://www.googleapis.com/auth/calendar",
16
+ "https://www.googleapis.com/auth/calendar.events",
17
+ ],
18
+ }) {
19
+ super(...arguments);
20
+ Object.defineProperty(this, "name", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: "Google Calendar"
25
+ });
26
+ Object.defineProperty(this, "description", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: "A tool to lookup Google Calendar events and create events in Google Calendar"
31
+ });
32
+ Object.defineProperty(this, "clientEmail", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ Object.defineProperty(this, "privateKey", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: void 0
43
+ });
44
+ Object.defineProperty(this, "calendarId", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: void 0
49
+ });
50
+ Object.defineProperty(this, "scopes", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: void 0
55
+ });
56
+ Object.defineProperty(this, "llm", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: void 0
61
+ });
62
+ if (!fields.model) {
63
+ throw new Error("Missing llm instance to interact with Google Calendar");
64
+ }
65
+ if (!fields.credentials) {
66
+ throw new Error("Missing credentials to authenticate to Google Calendar");
67
+ }
68
+ if (!fields.credentials.clientEmail) {
69
+ throw new Error("Missing GOOGLE_CALENDAR_CLIENT_EMAIL to interact with Google Calendar");
70
+ }
71
+ if (!fields.credentials.privateKey) {
72
+ throw new Error("Missing GOOGLE_CALENDAR_PRIVATE_KEY to interact with Google Calendar");
73
+ }
74
+ if (!fields.credentials.calendarId) {
75
+ throw new Error("Missing GOOGLE_CALENDAR_CALENDAR_ID to interact with Google Calendar");
76
+ }
77
+ this.clientEmail = fields.credentials.clientEmail;
78
+ this.privateKey = fields.credentials.privateKey;
79
+ this.calendarId = fields.credentials.calendarId;
80
+ this.scopes = fields.scopes || [];
81
+ this.llm = fields.model;
82
+ }
83
+ getModel() {
84
+ return this.llm;
85
+ }
86
+ async getAuth() {
87
+ const auth = new googleapis_1.google.auth.JWT(this.clientEmail, undefined, this.privateKey, this.scopes);
88
+ return auth;
89
+ }
90
+ async _call(input) {
91
+ return input;
92
+ }
93
+ }
94
+ exports.GoogleCalendarBase = GoogleCalendarBase;
@@ -0,0 +1,24 @@
1
+ import { Tool } from "../base.js";
2
+ import { BaseLLM } from "../../llms/base.js";
3
+ export interface GoogleCalendarAgentParams {
4
+ credentials?: {
5
+ clientEmail?: string;
6
+ privateKey?: string;
7
+ calendarId?: string;
8
+ };
9
+ scopes?: string[];
10
+ model?: BaseLLM;
11
+ }
12
+ export declare class GoogleCalendarBase extends Tool {
13
+ name: string;
14
+ description: string;
15
+ protected clientEmail: string;
16
+ protected privateKey: string;
17
+ protected calendarId: string;
18
+ protected scopes: string[];
19
+ protected llm: BaseLLM;
20
+ constructor(fields?: GoogleCalendarAgentParams);
21
+ getModel(): BaseLLM<import("../../llms/base.js").BaseLLMCallOptions>;
22
+ getAuth(): Promise<import("googleapis-common").JWT>;
23
+ _call(input: string): Promise<string>;
24
+ }
@@ -0,0 +1,90 @@
1
+ import { google } from "googleapis";
2
+ import { Tool } from "../base.js";
3
+ import { getEnvironmentVariable } from "../../util/env.js";
4
+ export class GoogleCalendarBase extends Tool {
5
+ constructor(fields = {
6
+ credentials: {
7
+ clientEmail: getEnvironmentVariable("GOOGLE_CALENDAR_CLIENT_EMAIL"),
8
+ privateKey: getEnvironmentVariable("GOOGLE_CALENDAR_PRIVATE_KEY"),
9
+ calendarId: getEnvironmentVariable("GOOGLE_CALENDAR_CALENDAR_ID"),
10
+ },
11
+ scopes: [
12
+ "https://www.googleapis.com/auth/calendar",
13
+ "https://www.googleapis.com/auth/calendar.events",
14
+ ],
15
+ }) {
16
+ super(...arguments);
17
+ Object.defineProperty(this, "name", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: "Google Calendar"
22
+ });
23
+ Object.defineProperty(this, "description", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: "A tool to lookup Google Calendar events and create events in Google Calendar"
28
+ });
29
+ Object.defineProperty(this, "clientEmail", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+ Object.defineProperty(this, "privateKey", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ Object.defineProperty(this, "calendarId", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: void 0
46
+ });
47
+ Object.defineProperty(this, "scopes", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: void 0
52
+ });
53
+ Object.defineProperty(this, "llm", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: void 0
58
+ });
59
+ if (!fields.model) {
60
+ throw new Error("Missing llm instance to interact with Google Calendar");
61
+ }
62
+ if (!fields.credentials) {
63
+ throw new Error("Missing credentials to authenticate to Google Calendar");
64
+ }
65
+ if (!fields.credentials.clientEmail) {
66
+ throw new Error("Missing GOOGLE_CALENDAR_CLIENT_EMAIL to interact with Google Calendar");
67
+ }
68
+ if (!fields.credentials.privateKey) {
69
+ throw new Error("Missing GOOGLE_CALENDAR_PRIVATE_KEY to interact with Google Calendar");
70
+ }
71
+ if (!fields.credentials.calendarId) {
72
+ throw new Error("Missing GOOGLE_CALENDAR_CALENDAR_ID to interact with Google Calendar");
73
+ }
74
+ this.clientEmail = fields.credentials.clientEmail;
75
+ this.privateKey = fields.credentials.privateKey;
76
+ this.calendarId = fields.credentials.calendarId;
77
+ this.scopes = fields.scopes || [];
78
+ this.llm = fields.model;
79
+ }
80
+ getModel() {
81
+ return this.llm;
82
+ }
83
+ async getAuth() {
84
+ const auth = new google.auth.JWT(this.clientEmail, undefined, this.privateKey, this.scopes);
85
+ return auth;
86
+ }
87
+ async _call(input) {
88
+ return input;
89
+ }
90
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCreateEvent = void 0;
4
+ const googleapis_1 = require("googleapis");
5
+ const index_js_1 = require("../../../prompts/index.cjs");
6
+ const index_js_2 = require("../../../chains/index.cjs");
7
+ const index_js_3 = require("../prompts/index.cjs");
8
+ const get_timezone_offset_in_hours_js_1 = require("../utils/get-timezone-offset-in-hours.cjs");
9
+ const createEvent = async ({ eventSummary, eventStartTime, eventEndTime, userTimezone, eventLocation = "", eventDescription = "", }, calendarId, auth) => {
10
+ const calendar = googleapis_1.google.calendar("v3");
11
+ const event = {
12
+ summary: eventSummary,
13
+ location: eventLocation,
14
+ description: eventDescription,
15
+ start: {
16
+ dateTime: eventStartTime,
17
+ timeZone: userTimezone,
18
+ },
19
+ end: {
20
+ dateTime: eventEndTime,
21
+ timeZone: userTimezone,
22
+ },
23
+ };
24
+ try {
25
+ const createdEvent = await calendar.events.insert({
26
+ auth,
27
+ calendarId,
28
+ requestBody: event,
29
+ });
30
+ return createdEvent;
31
+ }
32
+ catch (error) {
33
+ return {
34
+ error: `An error occurred: ${error}`,
35
+ };
36
+ }
37
+ };
38
+ const runCreateEvent = async (query, { calendarId, auth, model }, runManager) => {
39
+ const prompt = new index_js_1.PromptTemplate({
40
+ template: index_js_3.CREATE_EVENT_PROMPT,
41
+ inputVariables: ["date", "query", "u_timezone", "dayName"],
42
+ });
43
+ const createEventChain = new index_js_2.LLMChain({
44
+ llm: model,
45
+ prompt,
46
+ });
47
+ const date = new Date().toISOString();
48
+ const u_timezone = (0, get_timezone_offset_in_hours_js_1.getTimezoneOffsetInHours)();
49
+ const dayName = new Date().toLocaleString("en-us", { weekday: "long" });
50
+ const output = await createEventChain.call({
51
+ query,
52
+ date,
53
+ u_timezone,
54
+ dayName,
55
+ }, runManager?.getChild());
56
+ const loaded = JSON.parse(output.text);
57
+ const [eventSummary, eventStartTime, eventEndTime, eventLocation, eventDescription, userTimezone,] = Object.values(loaded);
58
+ const event = await createEvent({
59
+ eventSummary,
60
+ eventStartTime,
61
+ eventEndTime,
62
+ userTimezone,
63
+ eventLocation,
64
+ eventDescription,
65
+ }, calendarId, auth);
66
+ if (!event.error) {
67
+ return `Event created successfully, details: event ${event.data.htmlLink}`;
68
+ }
69
+ return `An error occurred creating the event: ${event.error}`;
70
+ };
71
+ exports.runCreateEvent = runCreateEvent;
@@ -0,0 +1,10 @@
1
+ import type { JWT } from "googleapis-common";
2
+ import { BaseLLM } from "../../../llms/base.js";
3
+ import { CallbackManagerForToolRun } from "../../../callbacks/manager.js";
4
+ type RunCreateEventParams = {
5
+ calendarId: string;
6
+ auth: JWT;
7
+ model: BaseLLM;
8
+ };
9
+ declare const runCreateEvent: (query: string, { calendarId, auth, model }: RunCreateEventParams, runManager?: CallbackManagerForToolRun) => Promise<string>;
10
+ export { runCreateEvent };