@cuylabs/agent-session-store-postgres 6.2.0 → 6.2.2
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/README.md +4 -0
- package/dist/index.js +16 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -49,6 +49,10 @@ The turn lock uses PostgreSQL advisory locks and holds a dedicated database
|
|
|
49
49
|
connection only while the agent turn is running. It does not hold a database
|
|
50
50
|
transaction open during LLM/tool execution.
|
|
51
51
|
|
|
52
|
+
The turn lock and the session-store append lock use separate PostgreSQL
|
|
53
|
+
advisory-lock namespaces, so a turn can persist session entries without
|
|
54
|
+
blocking on its own turn-ownership lock.
|
|
55
|
+
|
|
52
56
|
## Azure PostgreSQL
|
|
53
57
|
|
|
54
58
|
For Azure Database for PostgreSQL Flexible Server, configure an App Service
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
import { extractSessionInfo } from "@cuylabs/agent-core/sessions";
|
|
3
3
|
import pg from "pg";
|
|
4
4
|
|
|
5
|
+
// src/advisory-locks.ts
|
|
6
|
+
var SESSION_STORE_APPEND_LOCK_NAMESPACE = 1129533523;
|
|
7
|
+
var SESSION_TURN_LOCK_NAMESPACE = 1129533524;
|
|
8
|
+
|
|
5
9
|
// src/identifiers.ts
|
|
6
10
|
function quoteIdentifier(identifier) {
|
|
7
11
|
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(identifier)) {
|
|
@@ -169,7 +173,10 @@ var PostgresSessionStore = class {
|
|
|
169
173
|
async ensureInitialized() {
|
|
170
174
|
if (this.initialized) return;
|
|
171
175
|
if (!this.initializing) {
|
|
172
|
-
this.initializing = this.initialize()
|
|
176
|
+
this.initializing = this.initialize().catch((error) => {
|
|
177
|
+
this.initializing = void 0;
|
|
178
|
+
throw error;
|
|
179
|
+
});
|
|
173
180
|
}
|
|
174
181
|
await this.initializing;
|
|
175
182
|
}
|
|
@@ -203,9 +210,10 @@ var PostgresSessionStore = class {
|
|
|
203
210
|
this.initialized = true;
|
|
204
211
|
}
|
|
205
212
|
async lockSession(client, sessionId) {
|
|
206
|
-
await client.query(
|
|
207
|
-
|
|
208
|
-
|
|
213
|
+
await client.query(
|
|
214
|
+
"SELECT pg_advisory_xact_lock($1::integer, hashtext($2))",
|
|
215
|
+
[SESSION_STORE_APPEND_LOCK_NAMESPACE, sessionId]
|
|
216
|
+
);
|
|
209
217
|
}
|
|
210
218
|
getSessionPath(sessionId) {
|
|
211
219
|
return `postgres://${this.schema}.${this.tableName}/${sessionId}`;
|
|
@@ -267,8 +275,8 @@ var PostgresSessionTurnLock = class {
|
|
|
267
275
|
while (true) {
|
|
268
276
|
throwIfAborted(options.signal);
|
|
269
277
|
const result = await client.query(
|
|
270
|
-
"SELECT pg_try_advisory_lock(hashtext($
|
|
271
|
-
[sessionId]
|
|
278
|
+
"SELECT pg_try_advisory_lock($1::integer, hashtext($2)) AS locked",
|
|
279
|
+
[SESSION_TURN_LOCK_NAMESPACE, sessionId]
|
|
272
280
|
);
|
|
273
281
|
if (result.rows[0]?.locked === true) {
|
|
274
282
|
return createRelease(client, sessionId);
|
|
@@ -301,8 +309,8 @@ function createRelease(client, sessionId) {
|
|
|
301
309
|
released = true;
|
|
302
310
|
try {
|
|
303
311
|
await client.query(
|
|
304
|
-
"SELECT pg_advisory_unlock(hashtext($
|
|
305
|
-
[sessionId]
|
|
312
|
+
"SELECT pg_advisory_unlock($1::integer, hashtext($2)) AS unlocked",
|
|
313
|
+
[SESSION_TURN_LOCK_NAMESPACE, sessionId]
|
|
306
314
|
);
|
|
307
315
|
} finally {
|
|
308
316
|
client.release();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuylabs/agent-session-store-postgres",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.2",
|
|
4
4
|
"description": "PostgreSQL session store for @cuylabs/agent-core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"pg": "^8.16.3",
|
|
21
|
-
"@cuylabs/agent-core": "^6.2.
|
|
21
|
+
"@cuylabs/agent-core": "^6.2.2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/node": "^22.0.0",
|