langchain 0.0.169 → 0.0.170

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 (69) hide show
  1. package/README.md +2 -2
  2. package/agents/format_scratchpad.cjs +1 -0
  3. package/agents/format_scratchpad.d.ts +1 -0
  4. package/agents/format_scratchpad.js +1 -0
  5. package/dist/agents/agent.cjs +49 -1
  6. package/dist/agents/agent.d.ts +19 -1
  7. package/dist/agents/agent.js +47 -0
  8. package/dist/agents/executor.cjs +10 -1
  9. package/dist/agents/executor.d.ts +22 -8
  10. package/dist/agents/executor.js +11 -2
  11. package/dist/agents/format_scratchpad.cjs +25 -0
  12. package/dist/agents/format_scratchpad.d.ts +10 -0
  13. package/dist/agents/format_scratchpad.js +21 -0
  14. package/dist/agents/toolkits/aws_sfn.d.ts +4 -1
  15. package/dist/agents/toolkits/conversational_retrieval/openai_functions.d.ts +1 -1
  16. package/dist/agents/toolkits/json/json.d.ts +4 -1
  17. package/dist/agents/toolkits/openapi/openapi.cjs +8 -0
  18. package/dist/agents/toolkits/openapi/openapi.d.ts +12 -1
  19. package/dist/agents/toolkits/openapi/openapi.js +8 -0
  20. package/dist/agents/toolkits/sql/sql.d.ts +4 -1
  21. package/dist/agents/toolkits/vectorstore/vectorstore.d.ts +8 -2
  22. package/dist/agents/types.d.ts +13 -1
  23. package/dist/chains/sql_db/sql_db_chain.cjs +9 -0
  24. package/dist/chains/sql_db/sql_db_chain.d.ts +9 -0
  25. package/dist/chains/sql_db/sql_db_chain.js +9 -0
  26. package/dist/chat_models/baiduwenxin.cjs +12 -1
  27. package/dist/chat_models/baiduwenxin.d.ts +3 -1
  28. package/dist/chat_models/baiduwenxin.js +12 -1
  29. package/dist/document_loaders/web/assemblyai.cjs +63 -114
  30. package/dist/document_loaders/web/assemblyai.d.ts +38 -57
  31. package/dist/document_loaders/web/assemblyai.js +63 -100
  32. package/dist/load/import_constants.cjs +1 -0
  33. package/dist/load/import_constants.js +1 -0
  34. package/dist/load/import_map.cjs +3 -2
  35. package/dist/load/import_map.d.ts +1 -0
  36. package/dist/load/import_map.js +1 -0
  37. package/dist/memory/index.d.ts +1 -1
  38. package/dist/memory/index.js +1 -1
  39. package/dist/retrievers/time_weighted.cjs +1 -1
  40. package/dist/retrievers/time_weighted.d.ts +1 -1
  41. package/dist/retrievers/time_weighted.js +1 -1
  42. package/dist/schema/runnable/base.cjs +4 -1
  43. package/dist/schema/runnable/base.d.ts +1 -0
  44. package/dist/schema/runnable/base.js +4 -1
  45. package/dist/schema/runnable/passthrough.cjs +33 -1
  46. package/dist/schema/runnable/passthrough.d.ts +11 -1
  47. package/dist/schema/runnable/passthrough.js +32 -1
  48. package/dist/sql_db.cjs +12 -0
  49. package/dist/sql_db.d.ts +12 -0
  50. package/dist/sql_db.js +12 -0
  51. package/dist/storage/ioredis.cjs +2 -1
  52. package/dist/storage/ioredis.js +2 -1
  53. package/dist/storage/upstash_redis.cjs +155 -0
  54. package/dist/storage/upstash_redis.d.ts +59 -0
  55. package/dist/storage/upstash_redis.js +151 -0
  56. package/dist/storage/vercel_kv.cjs +2 -1
  57. package/dist/storage/vercel_kv.js +2 -1
  58. package/dist/types/assemblyai-types.cjs +0 -150
  59. package/dist/types/assemblyai-types.d.ts +4 -670
  60. package/dist/types/assemblyai-types.js +1 -149
  61. package/dist/vectorstores/pgvector.cjs +1 -1
  62. package/dist/vectorstores/pgvector.js +1 -1
  63. package/package.json +23 -2
  64. package/storage/upstash_redis.cjs +1 -0
  65. package/storage/upstash_redis.d.ts +1 -0
  66. package/storage/upstash_redis.js +1 -0
  67. package/dist/util/assemblyai-client.cjs +0 -173
  68. package/dist/util/assemblyai-client.d.ts +0 -63
  69. package/dist/util/assemblyai-client.js +0 -170
@@ -1,10 +1,7 @@
1
- import { promises as fs } from "node:fs";
1
+ import { AssemblyAI, } from "assemblyai";
2
2
  import { Document } from "../../document.js";
3
3
  import { BaseDocumentLoader } from "../base.js";
4
4
  import { getEnvironmentVariable } from "../../util/env.js";
5
- import { AssemblyAIClient } from "../../util/assemblyai-client.js";
6
- import { SubtitleFormat, } from "../../types/assemblyai-types.js";
7
- export * from "../../types/assemblyai-types.js";
8
5
  /**
9
6
  * Base class for AssemblyAI loaders.
10
7
  */
@@ -22,57 +19,67 @@ class AssemblyAILoader extends BaseDocumentLoader {
22
19
  writable: true,
23
20
  value: void 0
24
21
  });
25
- const apiKey = assemblyAIOptions?.apiKey ?? getEnvironmentVariable("ASSEMBLYAI_API_KEY");
26
- this.client = new AssemblyAIClient(apiKey);
27
- }
28
- /**
29
- * Attempts to upload the file to AssemblyAI if it is a local file.
30
- * If `audio_url` starts with `http://` or `https://`, it is assumed to be a remote file.
31
- * Otherwise, it is assumed to be a local file and is uploaded to AssemblyAI.
32
- * @param createTranscriptOptions
33
- */
34
- async uploadFile(createTranscriptOptions) {
35
- let path = createTranscriptOptions.audio_url;
36
- if (path.startsWith("http://") || path.startsWith("https://"))
37
- return;
38
- if (path.startsWith("file://"))
39
- path = path.slice("file://".length);
40
- const file = await fs.readFile(path);
41
- const uploadUrl = await this.client.uploadFile(file);
42
- // eslint-disable-next-line no-param-reassign
43
- createTranscriptOptions.audio_url = uploadUrl;
22
+ let options = assemblyAIOptions;
23
+ if (!options) {
24
+ options = {};
25
+ }
26
+ if (!options.apiKey) {
27
+ options.apiKey = getEnvironmentVariable("ASSEMBLYAI_API_KEY");
28
+ }
29
+ if (!options.apiKey) {
30
+ throw new Error("No AssemblyAI API key provided");
31
+ }
32
+ this.client = new AssemblyAI(options);
44
33
  }
45
34
  }
46
- /**
47
- * Creates a transcript for the given `CreateTranscriptParams.audio_url`,
48
- * and loads the transcript as a document using AssemblyAI.
49
- */
50
- export class AudioTranscriptLoader extends AssemblyAILoader {
35
+ class CreateTranscriptLoader extends AssemblyAILoader {
51
36
  /**
52
- * Creates a new AudioTranscriptLoader.
53
- * @param createTranscriptParams The parameters to create the transcript.
37
+ * Retrevies an existing transcript by its ID.
38
+ * @param params The parameters to create the transcript, or the ID of the transcript to retrieve.
54
39
  * @param assemblyAIOptions The options to configure the AssemblyAI loader.
55
40
  * Configure the `assemblyAIOptions.apiKey` with your AssemblyAI API key, or configure it as the `ASSEMBLYAI_API_KEY` environment variable.
56
41
  */
57
- constructor(createTranscriptParams, assemblyAIOptions) {
42
+ constructor(params, assemblyAIOptions) {
58
43
  super(assemblyAIOptions);
59
- Object.defineProperty(this, "createTranscriptParams", {
44
+ Object.defineProperty(this, "CreateTranscriptParameters", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: void 0
49
+ });
50
+ Object.defineProperty(this, "transcriptId", {
60
51
  enumerable: true,
61
52
  configurable: true,
62
53
  writable: true,
63
- value: createTranscriptParams
54
+ value: void 0
64
55
  });
56
+ if (typeof params === "string") {
57
+ this.transcriptId = params;
58
+ }
59
+ else {
60
+ this.CreateTranscriptParameters = params;
61
+ }
62
+ }
63
+ async getOrCreateTranscript() {
64
+ if (this.transcriptId) {
65
+ return await this.client.transcripts.get(this.transcriptId);
66
+ }
67
+ if (this.CreateTranscriptParameters) {
68
+ return await this.client.transcripts.create(this.CreateTranscriptParameters);
69
+ }
65
70
  }
71
+ }
72
+ /**
73
+ * Creates and loads the transcript as a document using AssemblyAI.
74
+ */
75
+ export class AudioTranscriptLoader extends CreateTranscriptLoader {
66
76
  /**
67
- * Creates a transcript for the given `CreateTranscriptParams.audio_url`,
68
- * and loads the transcript as a document using AssemblyAI.
77
+ * Creates a transcript and loads the transcript as a document using AssemblyAI.
69
78
  * @returns A promise that resolves to a single document containing the transcript text
70
79
  * as the page content, and the transcript object as the metadata.
71
80
  */
72
81
  async load() {
73
- await this.uploadFile(this.createTranscriptParams);
74
- let transcript = await this.client.createTranscript(this.createTranscriptParams);
75
- transcript = await this.client.waitForTranscriptToComplete(transcript.id);
82
+ const transcript = await this.getOrCreateTranscript();
76
83
  return [
77
84
  new Document({
78
85
  pageContent: transcript.text,
@@ -82,34 +89,16 @@ export class AudioTranscriptLoader extends AssemblyAILoader {
82
89
  }
83
90
  }
84
91
  /**
85
- * Creates a transcript for the given `CreateTranscriptParams.audio_url`,
86
- * and loads the paragraphs of the transcript, creating a document for each paragraph.
92
+ * Creates a transcript and loads the paragraphs of the transcript, creating a document for each paragraph.
87
93
  */
88
- export class AudioTranscriptParagraphsLoader extends AssemblyAILoader {
89
- /**
90
- * Creates a new AudioTranscriptParagraphsLoader.
91
- * @param createTranscriptParams The parameters to create the transcript.
92
- * @param assemblyAIOptions The options to configure the AssemblyAI loader.
93
- * Configure the `assemblyAIOptions.apiKey` with your AssemblyAI API key, or configure it as the `ASSEMBLYAI_API_KEY` environment variable.
94
- */
95
- constructor(createTranscriptParams, assemblyAIOptions) {
96
- super(assemblyAIOptions);
97
- Object.defineProperty(this, "createTranscriptParams", {
98
- enumerable: true,
99
- configurable: true,
100
- writable: true,
101
- value: createTranscriptParams
102
- });
103
- }
94
+ export class AudioTranscriptParagraphsLoader extends CreateTranscriptLoader {
104
95
  /**
105
- * Creates a transcript for the given `CreateTranscriptParams.audio_url`,
106
- * and loads the paragraphs of the transcript, creating a document for each paragraph.
96
+ * Creates a transcript and loads the paragraphs of the transcript, creating a document for each paragraph.
107
97
  * @returns A promise that resolves to an array of documents, each containing a paragraph of the transcript.
108
98
  */
109
99
  async load() {
110
- let transcript = await this.client.createTranscript(this.createTranscriptParams);
111
- transcript = await this.client.waitForTranscriptToComplete(transcript.id);
112
- const paragraphsResponse = await this.client.getParagraphs(transcript.id);
100
+ const transcript = await this.getOrCreateTranscript();
101
+ const paragraphsResponse = await this.client.transcripts.paragraphs(transcript.id);
113
102
  return paragraphsResponse.paragraphs.map((p) => new Document({
114
103
  pageContent: p.text,
115
104
  metadata: p,
@@ -117,34 +106,17 @@ export class AudioTranscriptParagraphsLoader extends AssemblyAILoader {
117
106
  }
118
107
  }
119
108
  /**
120
- * Creates a transcript for the given `CreateTranscriptParams.audio_url`,
109
+ * Creates a transcript for the given `CreateTranscriptParameters.audio_url`,
121
110
  * and loads the sentences of the transcript, creating a document for each sentence.
122
111
  */
123
- export class AudioTranscriptSentencesLoader extends AssemblyAILoader {
124
- /**
125
- * Creates a new AudioTranscriptSentencesLoader.
126
- * @param createTranscriptParams The parameters to create the transcript.
127
- * @param assemblyAIOptions The options to configure the AssemblyAI loader.
128
- * Configure the `assemblyAIOptions.apiKey` with your AssemblyAI API key, or configure it as the `ASSEMBLYAI_API_KEY` environment variable.
129
- */
130
- constructor(createTranscriptParams, assemblyAIOptions) {
131
- super(assemblyAIOptions);
132
- Object.defineProperty(this, "createTranscriptParams", {
133
- enumerable: true,
134
- configurable: true,
135
- writable: true,
136
- value: createTranscriptParams
137
- });
138
- }
112
+ export class AudioTranscriptSentencesLoader extends CreateTranscriptLoader {
139
113
  /**
140
- * Creates a transcript for the given `CreateTranscriptParams.audio_url`,
141
- * and loads the sentences of the transcript, creating a document for each sentence.
114
+ * Creates a transcript and loads the sentences of the transcript, creating a document for each sentence.
142
115
  * @returns A promise that resolves to an array of documents, each containing a sentence of the transcript.
143
116
  */
144
117
  async load() {
145
- let transcript = await this.client.createTranscript(this.createTranscriptParams);
146
- transcript = await this.client.waitForTranscriptToComplete(transcript.id);
147
- const sentencesResponse = await this.client.getSentences(transcript.id);
118
+ const transcript = await this.getOrCreateTranscript();
119
+ const sentencesResponse = await this.client.transcripts.sentences(transcript.id);
148
120
  return sentencesResponse.sentences.map((p) => new Document({
149
121
  pageContent: p.text,
150
122
  metadata: p,
@@ -152,25 +124,18 @@ export class AudioTranscriptSentencesLoader extends AssemblyAILoader {
152
124
  }
153
125
  }
154
126
  /**
155
- * Creates a transcript for the given `CreateTranscriptParams.audio_url`,
156
- * and loads subtitles for the transcript as `srt` or `vtt` format.
127
+ * Creates a transcript and loads subtitles for the transcript as `srt` or `vtt` format.
157
128
  */
158
- export class AudioSubtitleLoader extends AssemblyAILoader {
129
+ export class AudioSubtitleLoader extends CreateTranscriptLoader {
159
130
  /**
160
131
  * Creates a new AudioSubtitleLoader.
161
- * @param createTranscriptParams The parameters to create the transcript.
132
+ * @param params The parameters to create the transcript, or the ID of the transcript to retrieve.
162
133
  * @param subtitleFormat The format of the subtitles, either `srt` or `vtt`.
163
134
  * @param assemblyAIOptions The options to configure the AssemblyAI loader.
164
135
  * Configure the `assemblyAIOptions.apiKey` with your AssemblyAI API key, or configure it as the `ASSEMBLYAI_API_KEY` environment variable.
165
136
  */
166
- constructor(createTranscriptParams, subtitleFormat = SubtitleFormat.Srt, assemblyAIOptions) {
167
- super(assemblyAIOptions);
168
- Object.defineProperty(this, "createTranscriptParams", {
169
- enumerable: true,
170
- configurable: true,
171
- writable: true,
172
- value: createTranscriptParams
173
- });
137
+ constructor(params, subtitleFormat = "srt", assemblyAIOptions) {
138
+ super(params, assemblyAIOptions);
174
139
  Object.defineProperty(this, "subtitleFormat", {
175
140
  enumerable: true,
176
141
  configurable: true,
@@ -180,14 +145,12 @@ export class AudioSubtitleLoader extends AssemblyAILoader {
180
145
  this.subtitleFormat = subtitleFormat;
181
146
  }
182
147
  /**
183
- * Creates a transcript for the given `CreateTranscriptParams.audio_url`,
184
- * and loads subtitles for the transcript as `srt` or `vtt` format.
148
+ * Creates a transcript and loads subtitles for the transcript as `srt` or `vtt` format.
185
149
  * @returns A promise that resolves a document containing the subtitles as the page content.
186
150
  */
187
151
  async load() {
188
- let transcript = await this.client.createTranscript(this.createTranscriptParams);
189
- transcript = await this.client.waitForTranscriptToComplete(transcript.id);
190
- const subtitles = await this.client.getSubtitles(transcript.id, this.subtitleFormat);
152
+ const transcript = await this.getOrCreateTranscript();
153
+ const subtitles = await this.client.transcripts.subtitles(transcript.id, this.subtitleFormat);
191
154
  return [
192
155
  new Document({
193
156
  pageContent: subtitles,
@@ -144,6 +144,7 @@ exports.optionalImportEntrypoints = [
144
144
  "langchain/stores/message/xata",
145
145
  "langchain/storage/ioredis",
146
146
  "langchain/storage/vercel_kv",
147
+ "langchain/storage/upstash_redis",
147
148
  "langchain/graphs/neo4j_graph",
148
149
  "langchain/hub",
149
150
  "langchain/experimental/multimodal_embeddings/googlevertexai",
@@ -141,6 +141,7 @@ export const optionalImportEntrypoints = [
141
141
  "langchain/stores/message/xata",
142
142
  "langchain/storage/ioredis",
143
143
  "langchain/storage/vercel_kv",
144
+ "langchain/storage/upstash_redis",
144
145
  "langchain/graphs/neo4j_graph",
145
146
  "langchain/hub",
146
147
  "langchain/experimental/multimodal_embeddings/googlevertexai",
@@ -24,11 +24,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  return result;
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.schema__query_constructor = exports.schema__output_parser = exports.schema__document = exports.schema = exports.chat_models__fake = exports.chat_models__yandex = exports.chat_models__minimax = exports.chat_models__ollama = exports.chat_models__baiduwenxin = exports.chat_models__fireworks = exports.chat_models__cloudflare_workersai = exports.chat_models__anthropic = exports.chat_models__openai = exports.chat_models__base = exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__web__searchapi = exports.document_loaders__base = exports.document = exports.memory = exports.text_splitter = exports.vectorstores__xata = exports.vectorstores__vectara = exports.vectorstores__prisma = exports.vectorstores__memory = exports.vectorstores__base = exports.prompts = exports.llms__fake = exports.llms__yandex = exports.llms__fireworks = exports.llms__ollama = exports.llms__cloudflare_workersai = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__minimax = exports.embeddings__openai = exports.embeddings__ollama = exports.embeddings__fake = exports.embeddings__cache_backed = exports.embeddings__base = exports.chains__openai_functions = exports.chains = exports.tools = exports.base_language = exports.agents__toolkits = exports.agents = exports.load__serializable = void 0;
28
- exports.runnables__remote = exports.evaluation = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__time = exports.util__math = exports.storage__in_memory = exports.storage__encoder_backed = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__tavily_search_api = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__chaindesk = exports.retrievers__remote = exports.output_parsers = exports.callbacks = exports.schema__storage = exports.schema__runnable = exports.schema__retriever = void 0;
27
+ exports.schema__output_parser = exports.schema__document = exports.schema = exports.chat_models__fake = exports.chat_models__yandex = exports.chat_models__minimax = exports.chat_models__ollama = exports.chat_models__baiduwenxin = exports.chat_models__fireworks = exports.chat_models__cloudflare_workersai = exports.chat_models__anthropic = exports.chat_models__openai = exports.chat_models__base = exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__web__searchapi = exports.document_loaders__base = exports.document = exports.memory = exports.text_splitter = exports.vectorstores__xata = exports.vectorstores__vectara = exports.vectorstores__prisma = exports.vectorstores__memory = exports.vectorstores__base = exports.prompts = exports.llms__fake = exports.llms__yandex = exports.llms__fireworks = exports.llms__ollama = exports.llms__cloudflare_workersai = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__minimax = exports.embeddings__openai = exports.embeddings__ollama = exports.embeddings__fake = exports.embeddings__cache_backed = exports.embeddings__base = exports.chains__openai_functions = exports.chains = exports.tools = exports.base_language = exports.agents__format_scratchpad = exports.agents__toolkits = exports.agents = exports.load__serializable = void 0;
28
+ exports.runnables__remote = exports.evaluation = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__time = exports.util__math = exports.storage__in_memory = exports.storage__encoder_backed = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__tavily_search_api = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__chaindesk = exports.retrievers__remote = exports.output_parsers = exports.callbacks = exports.schema__storage = exports.schema__runnable = exports.schema__retriever = exports.schema__query_constructor = void 0;
29
29
  exports.load__serializable = __importStar(require("../load/serializable.cjs"));
30
30
  exports.agents = __importStar(require("../agents/index.cjs"));
31
31
  exports.agents__toolkits = __importStar(require("../agents/toolkits/index.cjs"));
32
+ exports.agents__format_scratchpad = __importStar(require("../agents/format_scratchpad.cjs"));
32
33
  exports.base_language = __importStar(require("../base_language/index.cjs"));
33
34
  exports.tools = __importStar(require("../tools/index.cjs"));
34
35
  exports.chains = __importStar(require("../chains/index.cjs"));
@@ -1,6 +1,7 @@
1
1
  export * as load__serializable from "../load/serializable.js";
2
2
  export * as agents from "../agents/index.js";
3
3
  export * as agents__toolkits from "../agents/toolkits/index.js";
4
+ export * as agents__format_scratchpad from "../agents/format_scratchpad.js";
4
5
  export * as base_language from "../base_language/index.js";
5
6
  export * as tools from "../tools/index.js";
6
7
  export * as chains from "../chains/index.js";
@@ -2,6 +2,7 @@
2
2
  export * as load__serializable from "../load/serializable.js";
3
3
  export * as agents from "../agents/index.js";
4
4
  export * as agents__toolkits from "../agents/toolkits/index.js";
5
+ export * as agents__format_scratchpad from "../agents/format_scratchpad.js";
5
6
  export * as base_language from "../base_language/index.js";
6
7
  export * as tools from "../tools/index.js";
7
8
  export * as chains from "../chains/index.js";
@@ -1,5 +1,5 @@
1
1
  export { BufferMemory, type BufferMemoryInput } from "./buffer_memory.js";
2
- export { BaseMemory, getInputValue, getBufferString } from "./base.js";
2
+ export { BaseMemory, getInputValue, getBufferString, type InputValues, type OutputValues, type MemoryVariables, } from "./base.js";
3
3
  export { ConversationSummaryMemory, type ConversationSummaryMemoryInput, BaseConversationSummaryMemory, type BaseConversationSummaryMemoryInput, } from "./summary.js";
4
4
  export { BufferWindowMemory, type BufferWindowMemoryInput, } from "./buffer_window_memory.js";
5
5
  export { BaseChatMemory, type BaseChatMemoryInput } from "./chat_memory.js";
@@ -1,5 +1,5 @@
1
1
  export { BufferMemory } from "./buffer_memory.js";
2
- export { BaseMemory, getInputValue, getBufferString } from "./base.js";
2
+ export { BaseMemory, getInputValue, getBufferString, } from "./base.js";
3
3
  export { ConversationSummaryMemory, BaseConversationSummaryMemory, } from "./summary.js";
4
4
  export { BufferWindowMemory, } from "./buffer_window_memory.js";
5
5
  export { BaseChatMemory } from "./chat_memory.js";
@@ -6,7 +6,7 @@ exports.LAST_ACCESSED_AT_KEY = "last_accessed_at";
6
6
  exports.BUFFER_IDX = "buffer_idx";
7
7
  /**
8
8
  * TimeWeightedVectorStoreRetriever retrieves documents based on their time-weighted relevance.
9
- * ref: https://github.com/hwchase17/langchain/blob/master/langchain/retrievers/time_weighted_retriever.py
9
+ * ref: https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/retrievers/time_weighted_retriever.py
10
10
  */
11
11
  class TimeWeightedVectorStoreRetriever extends retriever_js_1.BaseRetriever {
12
12
  static lc_name() {
@@ -19,7 +19,7 @@ export declare const LAST_ACCESSED_AT_KEY = "last_accessed_at";
19
19
  export declare const BUFFER_IDX = "buffer_idx";
20
20
  /**
21
21
  * TimeWeightedVectorStoreRetriever retrieves documents based on their time-weighted relevance.
22
- * ref: https://github.com/hwchase17/langchain/blob/master/langchain/retrievers/time_weighted_retriever.py
22
+ * ref: https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/retrievers/time_weighted_retriever.py
23
23
  */
24
24
  export declare class TimeWeightedVectorStoreRetriever extends BaseRetriever {
25
25
  static lc_name(): string;
@@ -3,7 +3,7 @@ export const LAST_ACCESSED_AT_KEY = "last_accessed_at";
3
3
  export const BUFFER_IDX = "buffer_idx";
4
4
  /**
5
5
  * TimeWeightedVectorStoreRetriever retrieves documents based on their time-weighted relevance.
6
- * ref: https://github.com/hwchase17/langchain/blob/master/langchain/retrievers/time_weighted_retriever.py
6
+ * ref: https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/retrievers/time_weighted_retriever.py
7
7
  */
8
8
  export class TimeWeightedVectorStoreRetriever extends BaseRetriever {
9
9
  static lc_name() {
@@ -366,7 +366,7 @@ class Runnable extends serializable_js_1.Serializable {
366
366
  }
367
367
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
368
368
  static isRunnable(thing) {
369
- return thing.lc_runnable;
369
+ return thing ? thing.lc_runnable : false;
370
370
  }
371
371
  }
372
372
  exports.Runnable = Runnable;
@@ -844,6 +844,9 @@ class RunnableMap extends Runnable {
844
844
  static lc_name() {
845
845
  return "RunnableMap";
846
846
  }
847
+ getStepsKeys() {
848
+ return Object.keys(this.steps);
849
+ }
847
850
  constructor(fields) {
848
851
  super(fields);
849
852
  Object.defineProperty(this, "lc_namespace", {
@@ -289,6 +289,7 @@ export declare class RunnableMap<RunInput> extends Runnable<RunInput, Record<str
289
289
  lc_namespace: string[];
290
290
  lc_serializable: boolean;
291
291
  protected steps: Record<string, Runnable<RunInput>>;
292
+ getStepsKeys(): string[];
292
293
  constructor(fields: {
293
294
  steps: Record<string, RunnableLike<RunInput>>;
294
295
  });
@@ -360,7 +360,7 @@ export class Runnable extends Serializable {
360
360
  }
361
361
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
362
362
  static isRunnable(thing) {
363
- return thing.lc_runnable;
363
+ return thing ? thing.lc_runnable : false;
364
364
  }
365
365
  }
366
366
  /**
@@ -833,6 +833,9 @@ export class RunnableMap extends Runnable {
833
833
  static lc_name() {
834
834
  return "RunnableMap";
835
835
  }
836
+ getStepsKeys() {
837
+ return Object.keys(this.steps);
838
+ }
836
839
  constructor(fields) {
837
840
  super(fields);
838
841
  Object.defineProperty(this, "lc_namespace", {
@@ -1,7 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RunnablePassthrough = void 0;
3
+ exports.RunnablePassthrough = exports.RunnableAssign = void 0;
4
4
  const base_js_1 = require("./base.cjs");
5
+ /**
6
+ * A runnable that assigns key-value pairs to inputs of type `Record<string, unknown>`.
7
+ */
8
+ class RunnableAssign extends base_js_1.Runnable {
9
+ constructor(mapper) {
10
+ super();
11
+ Object.defineProperty(this, "lc_namespace", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: ["langchain", "schema", "runnable"]
16
+ });
17
+ Object.defineProperty(this, "mapper", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ this.mapper = mapper;
24
+ }
25
+ async invoke(input, options) {
26
+ const mapperResult = await this.mapper.invoke(input, options);
27
+ return {
28
+ ...input,
29
+ ...mapperResult,
30
+ };
31
+ }
32
+ }
33
+ exports.RunnableAssign = RunnableAssign;
5
34
  /**
6
35
  * A runnable that passes through the input.
7
36
  */
@@ -27,5 +56,8 @@ class RunnablePassthrough extends base_js_1.Runnable {
27
56
  async invoke(input, options) {
28
57
  return this._callWithConfig((input) => Promise.resolve(input), input, options);
29
58
  }
59
+ static assign(mapping) {
60
+ return new RunnableAssign(new base_js_1.RunnableMap({ steps: mapping }));
61
+ }
30
62
  }
31
63
  exports.RunnablePassthrough = RunnablePassthrough;
@@ -1,5 +1,14 @@
1
- import { Runnable } from "./base.js";
1
+ import { Runnable, RunnableLike, RunnableMap } from "./base.js";
2
2
  import type { RunnableConfig } from "./config.js";
3
+ /**
4
+ * A runnable that assigns key-value pairs to inputs of type `Record<string, unknown>`.
5
+ */
6
+ export declare class RunnableAssign<RunInput extends Record<string, any> = any, RunOutput extends Record<string, any> = any, CallOptions extends RunnableConfig = RunnableConfig> extends Runnable<RunInput, RunOutput> {
7
+ lc_namespace: string[];
8
+ mapper: RunnableMap<RunInput>;
9
+ constructor(mapper: RunnableMap<RunInput>);
10
+ invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
11
+ }
3
12
  /**
4
13
  * A runnable that passes through the input.
5
14
  */
@@ -8,4 +17,5 @@ export declare class RunnablePassthrough<RunInput> extends Runnable<RunInput, Ru
8
17
  lc_namespace: string[];
9
18
  lc_serializable: boolean;
10
19
  invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunInput>;
20
+ static assign(mapping: Record<string, RunnableLike<Record<string, unknown>, any>>): RunnableAssign<Record<string, unknown>, Record<string, unknown>>;
11
21
  }
@@ -1,4 +1,32 @@
1
- import { Runnable } from "./base.js";
1
+ import { Runnable, RunnableMap } from "./base.js";
2
+ /**
3
+ * A runnable that assigns key-value pairs to inputs of type `Record<string, unknown>`.
4
+ */
5
+ export class RunnableAssign extends Runnable {
6
+ constructor(mapper) {
7
+ super();
8
+ Object.defineProperty(this, "lc_namespace", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: ["langchain", "schema", "runnable"]
13
+ });
14
+ Object.defineProperty(this, "mapper", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ this.mapper = mapper;
21
+ }
22
+ async invoke(input, options) {
23
+ const mapperResult = await this.mapper.invoke(input, options);
24
+ return {
25
+ ...input,
26
+ ...mapperResult,
27
+ };
28
+ }
29
+ }
2
30
  /**
3
31
  * A runnable that passes through the input.
4
32
  */
@@ -24,4 +52,7 @@ export class RunnablePassthrough extends Runnable {
24
52
  async invoke(input, options) {
25
53
  return this._callWithConfig((input) => Promise.resolve(input), input, options);
26
54
  }
55
+ static assign(mapping) {
56
+ return new RunnableAssign(new RunnableMap({ steps: mapping }));
57
+ }
27
58
  }
package/dist/sql_db.cjs CHANGED
@@ -3,6 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqlDatabase = void 0;
4
4
  const sql_utils_js_1 = require("./util/sql_utils.cjs");
5
5
  const serializable_js_1 = require("./load/serializable.cjs");
6
+ /**
7
+ * Class that represents a SQL database in the LangChain framework.
8
+ *
9
+ * @security **Security Notice**
10
+ * This class generates SQL queries for the given database.
11
+ * The SQLDatabase class provides a getTableInfo method that can be used
12
+ * to get column information as well as sample data from the table.
13
+ * To mitigate risk of leaking sensitive data, limit permissions
14
+ * to read and scope to the tables that are needed.
15
+ * Optionally, use the includesTables or ignoreTables class parameters
16
+ * to limit which tables can/cannot be accessed.
17
+ */
6
18
  class SqlDatabase extends serializable_js_1.Serializable {
7
19
  toJSON() {
8
20
  return this.toJSONNotImplemented();
package/dist/sql_db.d.ts CHANGED
@@ -2,6 +2,18 @@ import type { DataSource as DataSourceT, DataSourceOptions } from "typeorm";
2
2
  import { SerializedSqlDatabase, SqlDatabaseDataSourceParams, SqlDatabaseOptionsParams, SqlTable } from "./util/sql_utils.js";
3
3
  import { Serializable } from "./load/serializable.js";
4
4
  export type { SqlDatabaseDataSourceParams, SqlDatabaseOptionsParams };
5
+ /**
6
+ * Class that represents a SQL database in the LangChain framework.
7
+ *
8
+ * @security **Security Notice**
9
+ * This class generates SQL queries for the given database.
10
+ * The SQLDatabase class provides a getTableInfo method that can be used
11
+ * to get column information as well as sample data from the table.
12
+ * To mitigate risk of leaking sensitive data, limit permissions
13
+ * to read and scope to the tables that are needed.
14
+ * Optionally, use the includesTables or ignoreTables class parameters
15
+ * to limit which tables can/cannot be accessed.
16
+ */
5
17
  export declare class SqlDatabase extends Serializable implements SqlDatabaseOptionsParams, SqlDatabaseDataSourceParams {
6
18
  lc_namespace: string[];
7
19
  toJSON(): import("./load/serializable.js").SerializedNotImplemented;
package/dist/sql_db.js CHANGED
@@ -1,5 +1,17 @@
1
1
  import { generateTableInfoFromTables, getTableAndColumnsName, verifyIgnoreTablesExistInDatabase, verifyIncludeTablesExistInDatabase, verifyListTablesExistInDatabase, } from "./util/sql_utils.js";
2
2
  import { Serializable } from "./load/serializable.js";
3
+ /**
4
+ * Class that represents a SQL database in the LangChain framework.
5
+ *
6
+ * @security **Security Notice**
7
+ * This class generates SQL queries for the given database.
8
+ * The SQLDatabase class provides a getTableInfo method that can be used
9
+ * to get column information as well as sample data from the table.
10
+ * To mitigate risk of leaking sensitive data, limit permissions
11
+ * to read and scope to the tables that are needed.
12
+ * Optionally, use the includesTables or ignoreTables class parameters
13
+ * to limit which tables can/cannot be accessed.
14
+ */
3
15
  export class SqlDatabase extends Serializable {
4
16
  toJSON() {
5
17
  return this.toJSONNotImplemented();
@@ -115,7 +115,8 @@ class RedisByteStore extends storage_js_1.BaseStore {
115
115
  async *yieldKeys(prefix) {
116
116
  let pattern;
117
117
  if (prefix) {
118
- pattern = this._getPrefixedKey(prefix);
118
+ const wildcardPrefix = prefix.endsWith("*") ? prefix : `${prefix}*`;
119
+ pattern = this._getPrefixedKey(wildcardPrefix);
119
120
  }
120
121
  else {
121
122
  pattern = this._getPrefixedKey("*");
@@ -112,7 +112,8 @@ export class RedisByteStore extends BaseStore {
112
112
  async *yieldKeys(prefix) {
113
113
  let pattern;
114
114
  if (prefix) {
115
- pattern = this._getPrefixedKey(prefix);
115
+ const wildcardPrefix = prefix.endsWith("*") ? prefix : `${prefix}*`;
116
+ pattern = this._getPrefixedKey(wildcardPrefix);
116
117
  }
117
118
  else {
118
119
  pattern = this._getPrefixedKey("*");