@langchain/google-cloud-sql-pg 0.0.2 → 1.0.0
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/CHANGELOG.md +17 -0
- package/LICENSE +6 -6
- package/README.md +1 -1
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/chat_message_history.cjs +104 -137
- package/dist/chat_message_history.cjs.map +1 -0
- package/dist/chat_message_history.d.cts +57 -0
- package/dist/chat_message_history.d.cts.map +1 -0
- package/dist/chat_message_history.d.ts +53 -43
- package/dist/chat_message_history.d.ts.map +1 -0
- package/dist/chat_message_history.js +103 -133
- package/dist/chat_message_history.js.map +1 -0
- package/dist/engine.cjs +188 -242
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +138 -0
- package/dist/engine.d.cts.map +1 -0
- package/dist/engine.d.ts +102 -80
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +186 -234
- package/dist/engine.js.map +1 -0
- package/dist/index.cjs +21 -20
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +7 -4
- package/dist/indexes.cjs +96 -168
- package/dist/indexes.cjs.map +1 -0
- package/dist/indexes.d.cts +68 -0
- package/dist/indexes.d.cts.map +1 -0
- package/dist/indexes.d.ts +50 -47
- package/dist/indexes.d.ts.map +1 -0
- package/dist/indexes.js +90 -161
- package/dist/indexes.js.map +1 -0
- package/dist/loader.cjs +159 -242
- package/dist/loader.cjs.map +1 -0
- package/dist/loader.d.cts +101 -0
- package/dist/loader.d.cts.map +1 -0
- package/dist/loader.d.ts +40 -26
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +157 -237
- package/dist/loader.js.map +1 -0
- package/dist/utils/utils.cjs +36 -65
- package/dist/utils/utils.cjs.map +1 -0
- package/dist/utils/utils.js +36 -62
- package/dist/utils/utils.js.map +1 -0
- package/dist/vectorstore.cjs +438 -593
- package/dist/vectorstore.cjs.map +1 -0
- package/dist/vectorstore.d.cts +300 -0
- package/dist/vectorstore.d.cts.map +1 -0
- package/dist/vectorstore.d.ts +147 -130
- package/dist/vectorstore.d.ts.map +1 -0
- package/dist/vectorstore.js +436 -588
- package/dist/vectorstore.js.map +1 -0
- package/package.json +38 -47
- package/dist/utils/utils.d.ts +0 -22
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @langchain/google-cloud-sql-pg
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
This release updates the package for compatibility with LangChain v1.0. See the v1.0 [release notes](https://docs.langchain.com/oss/javascript/releases/langchain-v1) for details on what's new.
|
|
6
|
+
|
|
7
|
+
## 0.0.2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- cae3674: properly handle explicit metadata columns in PostgresVectorStore (#8334)
|
|
12
|
+
- Updated dependencies [41bd944]
|
|
13
|
+
- Updated dependencies [e90bc0a]
|
|
14
|
+
- Updated dependencies [3a99a40]
|
|
15
|
+
- Updated dependencies [58e9522]
|
|
16
|
+
- Updated dependencies [e44dc1b]
|
|
17
|
+
- @langchain/core@0.3.76
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) LangChain, Inc.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
|
10
10
|
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
14
|
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
exports.__toESM = __toESM;
|
|
@@ -1,72 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class PostgresChatMessageHistory extends
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.sessionId = sessionId;
|
|
46
|
-
this.tableName = tableName;
|
|
47
|
-
this.schemaName = schemaName;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Create a new PostgresChatMessageHistory instance.
|
|
51
|
-
*
|
|
52
|
-
* @param {PostgresEngine} engine Postgres engine instance to use.
|
|
53
|
-
* @param {string} sessionId Retrieve the table content with this session ID.
|
|
54
|
-
* @param {string} tableName Table name that stores that chat message history. Parameter is not escaped. Do not use with end user input.
|
|
55
|
-
* @param {string} schemaName Schema name for the chat message history table. Default: "public". Parameter is not escaped. Do not use with end user input.
|
|
56
|
-
* @returns PostgresChatMessageHistory instance.
|
|
57
|
-
*/
|
|
58
|
-
static async initialize(engine, sessionId, tableName, schemaName = "public") {
|
|
59
|
-
const query = `SELECT column_name, data_type FROM information_schema.columns WHERE table_name = '${tableName}' AND table_schema = '${schemaName}'`;
|
|
60
|
-
const { rows } = await engine.pool.raw(query);
|
|
61
|
-
const columnNames = [];
|
|
62
|
-
for (const index in rows) {
|
|
63
|
-
if (Object.prototype.hasOwnProperty.call(rows, index)) {
|
|
64
|
-
columnNames.push(rows[index].column_name);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const requiredColumns = ["id", "session_id", "data", "type"];
|
|
68
|
-
if (!requiredColumns.every((x) => columnNames.includes(x))) {
|
|
69
|
-
throw new Error(`Table '${schemaName}'.'${tableName}' has incorrect schema.
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const __langchain_core_chat_history = require_rolldown_runtime.__toESM(require("@langchain/core/chat_history"));
|
|
3
|
+
const __langchain_core_messages = require_rolldown_runtime.__toESM(require("@langchain/core/messages"));
|
|
4
|
+
|
|
5
|
+
//#region src/chat_message_history.ts
|
|
6
|
+
var PostgresChatMessageHistory = class PostgresChatMessageHistory extends __langchain_core_chat_history.BaseChatMessageHistory {
|
|
7
|
+
lc_namespace = [
|
|
8
|
+
"langchain",
|
|
9
|
+
"stores",
|
|
10
|
+
"message",
|
|
11
|
+
"google-cloud-sql-pg"
|
|
12
|
+
];
|
|
13
|
+
engine;
|
|
14
|
+
sessionId;
|
|
15
|
+
tableName;
|
|
16
|
+
schemaName;
|
|
17
|
+
constructor({ engine, sessionId, tableName, schemaName = "public" }) {
|
|
18
|
+
super();
|
|
19
|
+
this.engine = engine;
|
|
20
|
+
this.sessionId = sessionId;
|
|
21
|
+
this.tableName = tableName;
|
|
22
|
+
this.schemaName = schemaName;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a new PostgresChatMessageHistory instance.
|
|
26
|
+
*
|
|
27
|
+
* @param {PostgresEngine} engine Postgres engine instance to use.
|
|
28
|
+
* @param {string} sessionId Retrieve the table content with this session ID.
|
|
29
|
+
* @param {string} tableName Table name that stores that chat message history. Parameter is not escaped. Do not use with end user input.
|
|
30
|
+
* @param {string} schemaName Schema name for the chat message history table. Default: "public". Parameter is not escaped. Do not use with end user input.
|
|
31
|
+
* @returns PostgresChatMessageHistory instance.
|
|
32
|
+
*/
|
|
33
|
+
static async initialize(engine, sessionId, tableName, schemaName = "public") {
|
|
34
|
+
const query = `SELECT column_name, data_type FROM information_schema.columns WHERE table_name = '${tableName}' AND table_schema = '${schemaName}'`;
|
|
35
|
+
const { rows } = await engine.pool.raw(query);
|
|
36
|
+
const columnNames = [];
|
|
37
|
+
for (const index in rows) if (Object.prototype.hasOwnProperty.call(rows, index)) columnNames.push(rows[index].column_name);
|
|
38
|
+
const requiredColumns = [
|
|
39
|
+
"id",
|
|
40
|
+
"session_id",
|
|
41
|
+
"data",
|
|
42
|
+
"type"
|
|
43
|
+
];
|
|
44
|
+
if (!requiredColumns.every((x) => columnNames.includes(x))) throw new Error(`Table '${schemaName}'.'${tableName}' has incorrect schema.
|
|
70
45
|
Got column names ${columnNames} but required column names ${requiredColumns}.
|
|
71
46
|
Please create table with following schema: CREATE TABLE '${schemaName}'.'${tableName}' (
|
|
72
47
|
id SERIAL AUTO_INCREMENT PRIMARY KEY,
|
|
@@ -75,72 +50,64 @@ class PostgresChatMessageHistory extends chat_history_1.BaseChatMessageHistory {
|
|
|
75
50
|
type TEXT NOT NULL
|
|
76
51
|
);
|
|
77
52
|
`);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
*/
|
|
138
|
-
async clear() {
|
|
139
|
-
const query = `DELETE FROM "${this.schemaName}"."${this.tableName}" WHERE session_id = :session_id;`;
|
|
140
|
-
const values = {
|
|
141
|
-
session_id: this.sessionId,
|
|
142
|
-
};
|
|
143
|
-
await this.engine.pool.raw(query, values);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
53
|
+
return new PostgresChatMessageHistory({
|
|
54
|
+
engine,
|
|
55
|
+
sessionId,
|
|
56
|
+
tableName,
|
|
57
|
+
schemaName
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
addUserMessage(message) {
|
|
61
|
+
return this.addMessage(new __langchain_core_messages.HumanMessage(message));
|
|
62
|
+
}
|
|
63
|
+
addAIChatMessage(message) {
|
|
64
|
+
return this.addMessage(new __langchain_core_messages.AIMessage(message));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns a list of messages stored in the store.
|
|
68
|
+
*/
|
|
69
|
+
async getMessages() {
|
|
70
|
+
const query = `SELECT data, type FROM "${this.schemaName}"."${this.tableName}" WHERE session_id = :session_id ORDER BY id;`;
|
|
71
|
+
const values = { session_id: this.sessionId };
|
|
72
|
+
const items = [];
|
|
73
|
+
const { rows } = await this.engine.pool.raw(query, values);
|
|
74
|
+
if (rows.length === 0) return [];
|
|
75
|
+
for (const row of rows) items.push({
|
|
76
|
+
data: row.data.data,
|
|
77
|
+
type: row.type
|
|
78
|
+
});
|
|
79
|
+
return (0, __langchain_core_messages.mapStoredMessagesToChatMessages)(items);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Add a message object to the store.
|
|
83
|
+
* @param {BaseMessage} message Message to be added to the store
|
|
84
|
+
*/
|
|
85
|
+
async addMessage(message) {
|
|
86
|
+
const query = `INSERT INTO "${this.schemaName}"."${this.tableName}"("session_id", "data", "type") VALUES (:session_id, :data, :type)`;
|
|
87
|
+
const values = {
|
|
88
|
+
session_id: this.sessionId,
|
|
89
|
+
data: JSON.stringify(message.toDict()),
|
|
90
|
+
type: message.getType()
|
|
91
|
+
};
|
|
92
|
+
await this.engine.pool.raw(query, values);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Add a list of messages object to the store.
|
|
96
|
+
* @param {Array<BaseMessage>} messages List of messages to be added to the store
|
|
97
|
+
*/
|
|
98
|
+
async addMessages(messages) {
|
|
99
|
+
for (const msg of messages) await this.addMessage(msg);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Remove all messages from the store.
|
|
103
|
+
*/
|
|
104
|
+
async clear() {
|
|
105
|
+
const query = `DELETE FROM "${this.schemaName}"."${this.tableName}" WHERE session_id = :session_id;`;
|
|
106
|
+
const values = { session_id: this.sessionId };
|
|
107
|
+
await this.engine.pool.raw(query, values);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
146
112
|
exports.PostgresChatMessageHistory = PostgresChatMessageHistory;
|
|
113
|
+
//# sourceMappingURL=chat_message_history.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat_message_history.cjs","names":["BaseChatMessageHistory","engine: PostgresEngine","sessionId: string","tableName: string","schemaName: string","columnNames: string[]","message: string","HumanMessage","AIMessage","values: { [key: string]: string }","items: StoredMessage[]","message: BaseMessage","messages: BaseMessage[]"],"sources":["../src/chat_message_history.ts"],"sourcesContent":["import { BaseChatMessageHistory } from \"@langchain/core/chat_history\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n StoredMessage,\n mapStoredMessagesToChatMessages,\n} from \"@langchain/core/messages\";\nimport PostgresEngine from \"./engine.js\";\n\nexport interface PostgresChatMessageHistoryInput {\n engine: PostgresEngine;\n sessionId: string;\n tableName: string;\n schemaName: string;\n}\n\nexport class PostgresChatMessageHistory extends BaseChatMessageHistory {\n lc_namespace: string[] = [\n \"langchain\",\n \"stores\",\n \"message\",\n \"google-cloud-sql-pg\",\n ];\n\n engine: PostgresEngine;\n\n sessionId: string;\n\n tableName: string;\n\n schemaName: string;\n\n constructor({\n engine,\n sessionId,\n tableName,\n schemaName = \"public\",\n }: PostgresChatMessageHistoryInput) {\n super();\n this.engine = engine;\n this.sessionId = sessionId;\n this.tableName = tableName;\n this.schemaName = schemaName;\n }\n\n /**\n * Create a new PostgresChatMessageHistory instance.\n *\n * @param {PostgresEngine} engine Postgres engine instance to use.\n * @param {string} sessionId Retrieve the table content with this session ID.\n * @param {string} tableName Table name that stores that chat message history. Parameter is not escaped. Do not use with end user input.\n * @param {string} schemaName Schema name for the chat message history table. Default: \"public\". Parameter is not escaped. Do not use with end user input.\n * @returns PostgresChatMessageHistory instance.\n */\n static async initialize(\n engine: PostgresEngine,\n sessionId: string,\n tableName: string,\n schemaName: string = \"public\"\n ) {\n const query = `SELECT column_name, data_type FROM information_schema.columns WHERE table_name = '${tableName}' AND table_schema = '${schemaName}'`;\n const { rows } = await engine.pool.raw(query);\n const columnNames: string[] = [];\n\n for (const index in rows) {\n if (Object.prototype.hasOwnProperty.call(rows, index)) {\n columnNames.push(rows[index].column_name);\n }\n }\n\n const requiredColumns = [\"id\", \"session_id\", \"data\", \"type\"];\n\n if (!requiredColumns.every((x) => columnNames.includes(x))) {\n throw new Error(\n `Table '${schemaName}'.'${tableName}' has incorrect schema.\n Got column names ${columnNames} but required column names ${requiredColumns}.\n Please create table with following schema: CREATE TABLE '${schemaName}'.'${tableName}' (\n id SERIAL AUTO_INCREMENT PRIMARY KEY,\n session_id TEXT NOT NULL,\n data JSONB NOT NULL,\n type TEXT NOT NULL\n );\n `\n );\n }\n\n return new PostgresChatMessageHistory({\n engine,\n sessionId,\n tableName,\n schemaName,\n });\n }\n\n addUserMessage(message: string): Promise<void> {\n return this.addMessage(new HumanMessage(message));\n }\n\n addAIChatMessage(message: string): Promise<void> {\n return this.addMessage(new AIMessage(message));\n }\n\n /**\n * Returns a list of messages stored in the store.\n */\n async getMessages(): Promise<BaseMessage[]> {\n const query = `SELECT data, type FROM \"${this.schemaName}\".\"${this.tableName}\" WHERE session_id = :session_id ORDER BY id;`;\n const values: { [key: string]: string } = {\n session_id: this.sessionId,\n };\n const items: StoredMessage[] = [];\n const { rows } = await this.engine.pool.raw(query, values);\n\n if (rows.length === 0) {\n return [];\n }\n\n for (const row of rows) {\n items.push({\n data: row.data.data,\n type: row.type,\n });\n }\n\n return mapStoredMessagesToChatMessages(items);\n }\n\n /**\n * Add a message object to the store.\n * @param {BaseMessage} message Message to be added to the store\n */\n async addMessage(message: BaseMessage): Promise<void> {\n const query = `INSERT INTO \"${this.schemaName}\".\"${this.tableName}\"(\"session_id\", \"data\", \"type\") VALUES (:session_id, :data, :type)`;\n const values: { [key: string]: string } = {\n session_id: this.sessionId,\n data: JSON.stringify(message.toDict()),\n type: message.getType(),\n };\n\n await this.engine.pool.raw(query, values);\n }\n\n /**\n * Add a list of messages object to the store.\n * @param {Array<BaseMessage>} messages List of messages to be added to the store\n */\n async addMessages(messages: BaseMessage[]): Promise<void> {\n for (const msg of messages) {\n await this.addMessage(msg);\n }\n }\n\n /**\n * Remove all messages from the store.\n */\n async clear(): Promise<void> {\n const query = `DELETE FROM \"${this.schemaName}\".\"${this.tableName}\" WHERE session_id = :session_id;`;\n const values: { [key: string]: string } = {\n session_id: this.sessionId,\n };\n\n await this.engine.pool.raw(query, values);\n }\n}\n"],"mappings":";;;;;AAiBA,IAAa,6BAAb,MAAa,mCAAmCA,qDAAuB;CACrE,eAAyB;EACvB;EACA;EACA;EACA;CACD;CAED;CAEA;CAEA;CAEA;CAEA,YAAY,EACV,QACA,WACA,WACA,aAAa,UACmB,EAAE;EAClC,OAAO;EACP,KAAK,SAAS;EACd,KAAK,YAAY;EACjB,KAAK,YAAY;EACjB,KAAK,aAAa;CACnB;;;;;;;;;;CAWD,aAAa,WACXC,QACAC,WACAC,WACAC,aAAqB,UACrB;EACA,MAAM,QAAQ,CAAC,kFAAkF,EAAE,UAAU,sBAAsB,EAAE,WAAW,CAAC,CAAC;EAClJ,MAAM,EAAE,MAAM,GAAG,MAAM,OAAO,KAAK,IAAI,MAAM;EAC7C,MAAMC,cAAwB,CAAE;AAEhC,OAAK,MAAM,SAAS,KAClB,KAAI,OAAO,UAAU,eAAe,KAAK,MAAM,MAAM,EACnD,YAAY,KAAK,KAAK,OAAO,YAAY;EAI7C,MAAM,kBAAkB;GAAC;GAAM;GAAc;GAAQ;EAAO;AAE5D,MAAI,CAAC,gBAAgB,MAAM,CAAC,MAAM,YAAY,SAAS,EAAE,CAAC,CACxD,OAAM,IAAI,MACR,CAAC,OAAO,EAAE,WAAW,GAAG,EAAE,UAAU;yBACnB,EAAE,YAAY,2BAA2B,EAAE,gBAAgB;iEACnB,EAAE,WAAW,GAAG,EAAE,UAAU;;;;;;MAMvF,CAAC;AAIH,SAAO,IAAI,2BAA2B;GACpC;GACA;GACA;GACA;EACD;CACF;CAED,eAAeC,SAAgC;AAC7C,SAAO,KAAK,WAAW,IAAIC,uCAAa,SAAS;CAClD;CAED,iBAAiBD,SAAgC;AAC/C,SAAO,KAAK,WAAW,IAAIE,oCAAU,SAAS;CAC/C;;;;CAKD,MAAM,cAAsC;EAC1C,MAAM,QAAQ,CAAC,wBAAwB,EAAE,KAAK,WAAW,GAAG,EAAE,KAAK,UAAU,6CAA6C,CAAC;EAC3H,MAAMC,SAAoC,EACxC,YAAY,KAAK,UAClB;EACD,MAAMC,QAAyB,CAAE;EACjC,MAAM,EAAE,MAAM,GAAG,MAAM,KAAK,OAAO,KAAK,IAAI,OAAO,OAAO;AAE1D,MAAI,KAAK,WAAW,EAClB,QAAO,CAAE;AAGX,OAAK,MAAM,OAAO,MAChB,MAAM,KAAK;GACT,MAAM,IAAI,KAAK;GACf,MAAM,IAAI;EACX,EAAC;AAGJ,wEAAuC,MAAM;CAC9C;;;;;CAMD,MAAM,WAAWC,SAAqC;EACpD,MAAM,QAAQ,CAAC,aAAa,EAAE,KAAK,WAAW,GAAG,EAAE,KAAK,UAAU,kEAAkE,CAAC;EACrI,MAAMF,SAAoC;GACxC,YAAY,KAAK;GACjB,MAAM,KAAK,UAAU,QAAQ,QAAQ,CAAC;GACtC,MAAM,QAAQ,SAAS;EACxB;EAED,MAAM,KAAK,OAAO,KAAK,IAAI,OAAO,OAAO;CAC1C;;;;;CAMD,MAAM,YAAYG,UAAwC;AACxD,OAAK,MAAM,OAAO,UAChB,MAAM,KAAK,WAAW,IAAI;CAE7B;;;;CAKD,MAAM,QAAuB;EAC3B,MAAM,QAAQ,CAAC,aAAa,EAAE,KAAK,WAAW,GAAG,EAAE,KAAK,UAAU,iCAAiC,CAAC;EACpG,MAAMH,SAAoC,EACxC,YAAY,KAAK,UAClB;EAED,MAAM,KAAK,OAAO,KAAK,IAAI,OAAO,OAAO;CAC1C;AACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { PostgresEngine } from "./engine.cjs";
|
|
2
|
+
import { BaseChatMessageHistory } from "@langchain/core/chat_history";
|
|
3
|
+
import { BaseMessage } from "@langchain/core/messages";
|
|
4
|
+
|
|
5
|
+
//#region src/chat_message_history.d.ts
|
|
6
|
+
interface PostgresChatMessageHistoryInput {
|
|
7
|
+
engine: PostgresEngine;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
tableName: string;
|
|
10
|
+
schemaName: string;
|
|
11
|
+
}
|
|
12
|
+
declare class PostgresChatMessageHistory extends BaseChatMessageHistory {
|
|
13
|
+
lc_namespace: string[];
|
|
14
|
+
engine: PostgresEngine;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
tableName: string;
|
|
17
|
+
schemaName: string;
|
|
18
|
+
constructor({
|
|
19
|
+
engine,
|
|
20
|
+
sessionId,
|
|
21
|
+
tableName,
|
|
22
|
+
schemaName
|
|
23
|
+
}: PostgresChatMessageHistoryInput);
|
|
24
|
+
/**
|
|
25
|
+
* Create a new PostgresChatMessageHistory instance.
|
|
26
|
+
*
|
|
27
|
+
* @param {PostgresEngine} engine Postgres engine instance to use.
|
|
28
|
+
* @param {string} sessionId Retrieve the table content with this session ID.
|
|
29
|
+
* @param {string} tableName Table name that stores that chat message history. Parameter is not escaped. Do not use with end user input.
|
|
30
|
+
* @param {string} schemaName Schema name for the chat message history table. Default: "public". Parameter is not escaped. Do not use with end user input.
|
|
31
|
+
* @returns PostgresChatMessageHistory instance.
|
|
32
|
+
*/
|
|
33
|
+
static initialize(engine: PostgresEngine, sessionId: string, tableName: string, schemaName?: string): Promise<PostgresChatMessageHistory>;
|
|
34
|
+
addUserMessage(message: string): Promise<void>;
|
|
35
|
+
addAIChatMessage(message: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Returns a list of messages stored in the store.
|
|
38
|
+
*/
|
|
39
|
+
getMessages(): Promise<BaseMessage[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Add a message object to the store.
|
|
42
|
+
* @param {BaseMessage} message Message to be added to the store
|
|
43
|
+
*/
|
|
44
|
+
addMessage(message: BaseMessage): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Add a list of messages object to the store.
|
|
47
|
+
* @param {Array<BaseMessage>} messages List of messages to be added to the store
|
|
48
|
+
*/
|
|
49
|
+
addMessages(messages: BaseMessage[]): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Remove all messages from the store.
|
|
52
|
+
*/
|
|
53
|
+
clear(): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { PostgresChatMessageHistory, PostgresChatMessageHistoryInput };
|
|
57
|
+
//# sourceMappingURL=chat_message_history.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat_message_history.d.cts","names":["BaseChatMessageHistory","BaseMessage","PostgresEngine","PostgresChatMessageHistoryInput","PostgresChatMessageHistory","engine","sessionId","tableName","schemaName","Promise"],"sources":["../src/chat_message_history.d.ts"],"sourcesContent":["import { BaseChatMessageHistory } from \"@langchain/core/chat_history\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport PostgresEngine from \"./engine.js\";\nexport interface PostgresChatMessageHistoryInput {\n engine: PostgresEngine;\n sessionId: string;\n tableName: string;\n schemaName: string;\n}\nexport declare class PostgresChatMessageHistory extends BaseChatMessageHistory {\n lc_namespace: string[];\n engine: PostgresEngine;\n sessionId: string;\n tableName: string;\n schemaName: string;\n constructor({ engine, sessionId, tableName, schemaName }: PostgresChatMessageHistoryInput);\n /**\n * Create a new PostgresChatMessageHistory instance.\n *\n * @param {PostgresEngine} engine Postgres engine instance to use.\n * @param {string} sessionId Retrieve the table content with this session ID.\n * @param {string} tableName Table name that stores that chat message history. Parameter is not escaped. Do not use with end user input.\n * @param {string} schemaName Schema name for the chat message history table. Default: \"public\". Parameter is not escaped. Do not use with end user input.\n * @returns PostgresChatMessageHistory instance.\n */\n static initialize(engine: PostgresEngine, sessionId: string, tableName: string, schemaName?: string): Promise<PostgresChatMessageHistory>;\n addUserMessage(message: string): Promise<void>;\n addAIChatMessage(message: string): Promise<void>;\n /**\n * Returns a list of messages stored in the store.\n */\n getMessages(): Promise<BaseMessage[]>;\n /**\n * Add a message object to the store.\n * @param {BaseMessage} message Message to be added to the store\n */\n addMessage(message: BaseMessage): Promise<void>;\n /**\n * Add a list of messages object to the store.\n * @param {Array<BaseMessage>} messages List of messages to be added to the store\n */\n addMessages(messages: BaseMessage[]): Promise<void>;\n /**\n * Remove all messages from the store.\n */\n clear(): Promise<void>;\n}\n"],"mappings":";;;;;UAGiBG,+BAAAA;UACLD;EADKC,SAAAA,EAAAA,MAAAA;EAMIC,SAAAA,EAAAA,MAAAA;EAA0B,UAAA,EAAA,MAAA;;AAM7BC,cANGD,0BAAAA,SAAmCJ,sBAAAA,CAMtCK;EAAM,YAAEC,EAAAA,MAAAA,EAAAA;EAAS,MAAEC,EAJzBL,cAIyBK;EAAS,SAAEC,EAAAA,MAAAA;EAAU,SAAIL,EAAAA,MAAAA;EAA+B,UAU/DD,EAAAA,MAAAA;EAAc,WAAsEE,CAAAA;IAAAA,MAAAA;IAAAA,SAAAA;IAAAA,SAAAA;IAAAA;EAAAA,CAAAA,EAVpDD,+BAUoDC;EAA0B;;;;;;;;;EAgB3F,OAIpCK,UAAAA,CAAAA,MAAAA,EApBiBP,cAoBjBO,EAAAA,SAAAA,EAAAA,MAAAA,EAAAA,SAAAA,EAAAA,MAAAA,EAAAA,UAAAA,CAAAA,EAAAA,MAAAA,CAAAA,EApB6FA,OAoB7FA,CApBqGL,0BAoBrGK,CAAAA;EAAO,cApCoCT,CAAAA,OAAAA,EAAAA,MAAAA,CAAAA,EAiBnBS,OAjBmBT,CAAAA,IAAAA,CAAAA;EAAsB,gBAAA,CAAA,OAAA,EAAA,MAAA,CAAA,EAkBvCS,OAlBuC,CAAA,IAAA,CAAA;;;;iBAsB3DA,QAAQR;;;;;sBAKHA,cAAcQ;;;;;wBAKZR,gBAAgBQ;;;;WAI7BA"}
|
|
@@ -1,47 +1,57 @@
|
|
|
1
|
+
import { PostgresEngine } from "./engine.js";
|
|
1
2
|
import { BaseChatMessageHistory } from "@langchain/core/chat_history";
|
|
2
3
|
import { BaseMessage } from "@langchain/core/messages";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
|
|
5
|
+
//#region src/chat_message_history.d.ts
|
|
6
|
+
interface PostgresChatMessageHistoryInput {
|
|
7
|
+
engine: PostgresEngine;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
tableName: string;
|
|
10
|
+
schemaName: string;
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
12
|
+
declare class PostgresChatMessageHistory extends BaseChatMessageHistory {
|
|
13
|
+
lc_namespace: string[];
|
|
14
|
+
engine: PostgresEngine;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
tableName: string;
|
|
17
|
+
schemaName: string;
|
|
18
|
+
constructor({
|
|
19
|
+
engine,
|
|
20
|
+
sessionId,
|
|
21
|
+
tableName,
|
|
22
|
+
schemaName
|
|
23
|
+
}: PostgresChatMessageHistoryInput);
|
|
24
|
+
/**
|
|
25
|
+
* Create a new PostgresChatMessageHistory instance.
|
|
26
|
+
*
|
|
27
|
+
* @param {PostgresEngine} engine Postgres engine instance to use.
|
|
28
|
+
* @param {string} sessionId Retrieve the table content with this session ID.
|
|
29
|
+
* @param {string} tableName Table name that stores that chat message history. Parameter is not escaped. Do not use with end user input.
|
|
30
|
+
* @param {string} schemaName Schema name for the chat message history table. Default: "public". Parameter is not escaped. Do not use with end user input.
|
|
31
|
+
* @returns PostgresChatMessageHistory instance.
|
|
32
|
+
*/
|
|
33
|
+
static initialize(engine: PostgresEngine, sessionId: string, tableName: string, schemaName?: string): Promise<PostgresChatMessageHistory>;
|
|
34
|
+
addUserMessage(message: string): Promise<void>;
|
|
35
|
+
addAIChatMessage(message: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Returns a list of messages stored in the store.
|
|
38
|
+
*/
|
|
39
|
+
getMessages(): Promise<BaseMessage[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Add a message object to the store.
|
|
42
|
+
* @param {BaseMessage} message Message to be added to the store
|
|
43
|
+
*/
|
|
44
|
+
addMessage(message: BaseMessage): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Add a list of messages object to the store.
|
|
47
|
+
* @param {Array<BaseMessage>} messages List of messages to be added to the store
|
|
48
|
+
*/
|
|
49
|
+
addMessages(messages: BaseMessage[]): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Remove all messages from the store.
|
|
52
|
+
*/
|
|
53
|
+
clear(): Promise<void>;
|
|
47
54
|
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { PostgresChatMessageHistory, PostgresChatMessageHistoryInput };
|
|
57
|
+
//# sourceMappingURL=chat_message_history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat_message_history.d.ts","names":["BaseChatMessageHistory","BaseMessage","PostgresEngine","PostgresChatMessageHistoryInput","PostgresChatMessageHistory","engine","sessionId","tableName","schemaName","Promise"],"sources":["../src/chat_message_history.d.ts"],"sourcesContent":["import { BaseChatMessageHistory } from \"@langchain/core/chat_history\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport PostgresEngine from \"./engine.js\";\nexport interface PostgresChatMessageHistoryInput {\n engine: PostgresEngine;\n sessionId: string;\n tableName: string;\n schemaName: string;\n}\nexport declare class PostgresChatMessageHistory extends BaseChatMessageHistory {\n lc_namespace: string[];\n engine: PostgresEngine;\n sessionId: string;\n tableName: string;\n schemaName: string;\n constructor({ engine, sessionId, tableName, schemaName }: PostgresChatMessageHistoryInput);\n /**\n * Create a new PostgresChatMessageHistory instance.\n *\n * @param {PostgresEngine} engine Postgres engine instance to use.\n * @param {string} sessionId Retrieve the table content with this session ID.\n * @param {string} tableName Table name that stores that chat message history. Parameter is not escaped. Do not use with end user input.\n * @param {string} schemaName Schema name for the chat message history table. Default: \"public\". Parameter is not escaped. Do not use with end user input.\n * @returns PostgresChatMessageHistory instance.\n */\n static initialize(engine: PostgresEngine, sessionId: string, tableName: string, schemaName?: string): Promise<PostgresChatMessageHistory>;\n addUserMessage(message: string): Promise<void>;\n addAIChatMessage(message: string): Promise<void>;\n /**\n * Returns a list of messages stored in the store.\n */\n getMessages(): Promise<BaseMessage[]>;\n /**\n * Add a message object to the store.\n * @param {BaseMessage} message Message to be added to the store\n */\n addMessage(message: BaseMessage): Promise<void>;\n /**\n * Add a list of messages object to the store.\n * @param {Array<BaseMessage>} messages List of messages to be added to the store\n */\n addMessages(messages: BaseMessage[]): Promise<void>;\n /**\n * Remove all messages from the store.\n */\n clear(): Promise<void>;\n}\n"],"mappings":";;;;;UAGiBG,+BAAAA;UACLD;EADKC,SAAAA,EAAAA,MAAAA;EAMIC,SAAAA,EAAAA,MAAAA;EAA0B,UAAA,EAAA,MAAA;;AAM7BC,cANGD,0BAAAA,SAAmCJ,sBAAAA,CAMtCK;EAAM,YAAEC,EAAAA,MAAAA,EAAAA;EAAS,MAAEC,EAJzBL,cAIyBK;EAAS,SAAEC,EAAAA,MAAAA;EAAU,SAAIL,EAAAA,MAAAA;EAA+B,UAU/DD,EAAAA,MAAAA;EAAc,WAAsEE,CAAAA;IAAAA,MAAAA;IAAAA,SAAAA;IAAAA,SAAAA;IAAAA;EAAAA,CAAAA,EAVpDD,+BAUoDC;EAA0B;;;;;;;;;EAgB3F,OAIpCK,UAAAA,CAAAA,MAAAA,EApBiBP,cAoBjBO,EAAAA,SAAAA,EAAAA,MAAAA,EAAAA,SAAAA,EAAAA,MAAAA,EAAAA,UAAAA,CAAAA,EAAAA,MAAAA,CAAAA,EApB6FA,OAoB7FA,CApBqGL,0BAoBrGK,CAAAA;EAAO,cApCoCT,CAAAA,OAAAA,EAAAA,MAAAA,CAAAA,EAiBnBS,OAjBmBT,CAAAA,IAAAA,CAAAA;EAAsB,gBAAA,CAAA,OAAA,EAAA,MAAA,CAAA,EAkBvCS,OAlBuC,CAAA,IAAA,CAAA;;;;iBAsB3DA,QAAQR;;;;;sBAKHA,cAAcQ;;;;;wBAKZR,gBAAgBQ;;;;WAI7BA"}
|