@axiom-lattice/pg-stores 1.0.80 → 1.0.81
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +9 -0
- package/dist/index.d.mts +29 -3
- package/dist/index.d.ts +29 -3
- package/dist/index.js +253 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +250 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/createPgStoreConfig.ts +2 -0
- package/src/index.ts +10 -0
- package/src/migrations/menu_items_add_file_type.ts +29 -0
- package/src/migrations/menu_items_migration.ts +1 -1
- package/src/migrations/shared_resources_migration.ts +43 -0
- package/src/stores/MenuStore.ts +2 -0
- package/src/stores/PostgresSharedResourceStore.ts +220 -0
- package/src/stores/SharedResourceStore.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { Pool as
|
|
2
|
+
import { Pool as Pool23 } from "pg";
|
|
3
3
|
|
|
4
4
|
// src/stores/PostgreSQLThreadStore.ts
|
|
5
5
|
import { Pool } from "pg";
|
|
@@ -6231,7 +6231,7 @@ var createMenuItemsTable = {
|
|
|
6231
6231
|
name VARCHAR(255) NOT NULL,
|
|
6232
6232
|
icon VARCHAR(50),
|
|
6233
6233
|
sort_order INT NOT NULL DEFAULT 0,
|
|
6234
|
-
|
|
6234
|
+
content_type VARCHAR(20) NOT NULL CHECK (content_type IN ('agent', 'html', 'custom', 'file')),
|
|
6235
6235
|
content_config JSONB NOT NULL DEFAULT '{}',
|
|
6236
6236
|
enabled BOOLEAN NOT NULL DEFAULT true,
|
|
6237
6237
|
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
|
@@ -6252,6 +6252,34 @@ var createMenuItemsTable = {
|
|
|
6252
6252
|
}
|
|
6253
6253
|
};
|
|
6254
6254
|
|
|
6255
|
+
// src/migrations/menu_items_add_file_type.ts
|
|
6256
|
+
var addFileContentType = {
|
|
6257
|
+
version: 136,
|
|
6258
|
+
name: "add_file_content_type_to_menu_items",
|
|
6259
|
+
up: async (client) => {
|
|
6260
|
+
await client.query(`
|
|
6261
|
+
ALTER TABLE lattice_menu_items
|
|
6262
|
+
DROP CONSTRAINT IF EXISTS lattice_menu_items_content_type_check
|
|
6263
|
+
`);
|
|
6264
|
+
await client.query(`
|
|
6265
|
+
ALTER TABLE lattice_menu_items
|
|
6266
|
+
ADD CONSTRAINT lattice_menu_items_content_type_check
|
|
6267
|
+
CHECK (content_type IN ('agent', 'html', 'custom', 'file'))
|
|
6268
|
+
`);
|
|
6269
|
+
},
|
|
6270
|
+
down: async (client) => {
|
|
6271
|
+
await client.query(`
|
|
6272
|
+
ALTER TABLE lattice_menu_items
|
|
6273
|
+
DROP CONSTRAINT IF EXISTS lattice_menu_items_content_type_check
|
|
6274
|
+
`);
|
|
6275
|
+
await client.query(`
|
|
6276
|
+
ALTER TABLE lattice_menu_items
|
|
6277
|
+
ADD CONSTRAINT lattice_menu_items_content_type_check
|
|
6278
|
+
CHECK (content_type IN ('agent', 'html', 'custom'))
|
|
6279
|
+
`);
|
|
6280
|
+
}
|
|
6281
|
+
};
|
|
6282
|
+
|
|
6255
6283
|
// src/stores/MenuStore.ts
|
|
6256
6284
|
var MenuStore = class {
|
|
6257
6285
|
constructor(options) {
|
|
@@ -6260,6 +6288,7 @@ var MenuStore = class {
|
|
|
6260
6288
|
this.pool = typeof options.poolConfig === "string" ? new Pool19({ connectionString: options.poolConfig }) : new Pool19(options.poolConfig);
|
|
6261
6289
|
this.migrationManager = new MigrationManager(this.pool);
|
|
6262
6290
|
this.migrationManager.register(createMenuItemsTable);
|
|
6291
|
+
this.migrationManager.register(addFileContentType);
|
|
6263
6292
|
if (options.autoMigrate !== false) {
|
|
6264
6293
|
this.initialize().catch((error) => {
|
|
6265
6294
|
console.error("Failed to initialize MenuStore:", error);
|
|
@@ -6403,6 +6432,215 @@ var MenuStore = class {
|
|
|
6403
6432
|
}
|
|
6404
6433
|
};
|
|
6405
6434
|
|
|
6435
|
+
// src/stores/PostgresSharedResourceStore.ts
|
|
6436
|
+
import { Pool as Pool20 } from "pg";
|
|
6437
|
+
|
|
6438
|
+
// src/migrations/shared_resources_migration.ts
|
|
6439
|
+
var createSharedResourcesTable = {
|
|
6440
|
+
version: 135,
|
|
6441
|
+
name: "create_shared_resources_table",
|
|
6442
|
+
up: async (client) => {
|
|
6443
|
+
await client.query(`
|
|
6444
|
+
CREATE TABLE IF NOT EXISTS lattice_shared_resources (
|
|
6445
|
+
token VARCHAR(64) PRIMARY KEY,
|
|
6446
|
+
address JSONB NOT NULL,
|
|
6447
|
+
title VARCHAR(256),
|
|
6448
|
+
created_by VARCHAR(64) NOT NULL,
|
|
6449
|
+
tenant_id VARCHAR(64) NOT NULL,
|
|
6450
|
+
workspace_id VARCHAR(64) NOT NULL,
|
|
6451
|
+
project_id VARCHAR(64) NOT NULL,
|
|
6452
|
+
assistant_id VARCHAR(64),
|
|
6453
|
+
vm_isolation VARCHAR(16) NOT NULL DEFAULT 'project',
|
|
6454
|
+
visibility VARCHAR(16) NOT NULL DEFAULT 'public',
|
|
6455
|
+
password_hash VARCHAR(128),
|
|
6456
|
+
expires_at TIMESTAMPTZ,
|
|
6457
|
+
max_access INT,
|
|
6458
|
+
access_count INT DEFAULT 0,
|
|
6459
|
+
revoked BOOLEAN DEFAULT FALSE,
|
|
6460
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
6461
|
+
version INT DEFAULT 1
|
|
6462
|
+
)
|
|
6463
|
+
`);
|
|
6464
|
+
await client.query(`
|
|
6465
|
+
CREATE INDEX IF NOT EXISTS idx_shared_resources_tenant
|
|
6466
|
+
ON lattice_shared_resources(tenant_id)
|
|
6467
|
+
`);
|
|
6468
|
+
await client.query(`
|
|
6469
|
+
CREATE INDEX IF NOT EXISTS idx_shared_resources_user
|
|
6470
|
+
ON lattice_shared_resources(created_by)
|
|
6471
|
+
`);
|
|
6472
|
+
},
|
|
6473
|
+
down: async (client) => {
|
|
6474
|
+
await client.query("DROP TABLE IF EXISTS lattice_shared_resources");
|
|
6475
|
+
}
|
|
6476
|
+
};
|
|
6477
|
+
|
|
6478
|
+
// src/stores/PostgresSharedResourceStore.ts
|
|
6479
|
+
var PostgresSharedResourceStore = class {
|
|
6480
|
+
constructor(options) {
|
|
6481
|
+
this.initialized = false;
|
|
6482
|
+
this.initPromise = null;
|
|
6483
|
+
this.pool = typeof options.poolConfig === "string" ? new Pool20({ connectionString: options.poolConfig }) : new Pool20(options.poolConfig);
|
|
6484
|
+
this.migrationManager = new MigrationManager(this.pool);
|
|
6485
|
+
this.migrationManager.register(createSharedResourcesTable);
|
|
6486
|
+
if (options.autoMigrate !== false) {
|
|
6487
|
+
this.initialize().catch((error) => {
|
|
6488
|
+
console.error(
|
|
6489
|
+
"Failed to initialize PostgresSharedResourceStore:",
|
|
6490
|
+
error
|
|
6491
|
+
);
|
|
6492
|
+
throw error;
|
|
6493
|
+
});
|
|
6494
|
+
}
|
|
6495
|
+
}
|
|
6496
|
+
async initialize() {
|
|
6497
|
+
if (this.initialized) return;
|
|
6498
|
+
if (this.initPromise) return this.initPromise;
|
|
6499
|
+
this.initPromise = (async () => {
|
|
6500
|
+
try {
|
|
6501
|
+
await this.migrationManager.migrate();
|
|
6502
|
+
this.initialized = true;
|
|
6503
|
+
} finally {
|
|
6504
|
+
this.initPromise = null;
|
|
6505
|
+
}
|
|
6506
|
+
})();
|
|
6507
|
+
return this.initPromise;
|
|
6508
|
+
}
|
|
6509
|
+
async findByToken(token) {
|
|
6510
|
+
await this.ensureInitialized();
|
|
6511
|
+
const { rows } = await this.pool.query(
|
|
6512
|
+
"SELECT * FROM lattice_shared_resources WHERE token = $1",
|
|
6513
|
+
[token]
|
|
6514
|
+
);
|
|
6515
|
+
if (rows.length === 0) return null;
|
|
6516
|
+
return this._mapRow(rows[0]);
|
|
6517
|
+
}
|
|
6518
|
+
async create(record) {
|
|
6519
|
+
await this.ensureInitialized();
|
|
6520
|
+
const { rows } = await this.pool.query(
|
|
6521
|
+
`INSERT INTO lattice_shared_resources
|
|
6522
|
+
(token, address, title, created_by, tenant_id, workspace_id, project_id,
|
|
6523
|
+
assistant_id, vm_isolation, visibility, password_hash,
|
|
6524
|
+
expires_at, max_access, revoked)
|
|
6525
|
+
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)
|
|
6526
|
+
RETURNING *`,
|
|
6527
|
+
[
|
|
6528
|
+
record.token,
|
|
6529
|
+
JSON.stringify(record.address),
|
|
6530
|
+
record.title,
|
|
6531
|
+
record.createdBy,
|
|
6532
|
+
record.tenantId,
|
|
6533
|
+
record.workspaceId,
|
|
6534
|
+
record.projectId,
|
|
6535
|
+
record.assistantId,
|
|
6536
|
+
record.vmIsolation,
|
|
6537
|
+
record.visibility,
|
|
6538
|
+
record.passwordHash,
|
|
6539
|
+
record.expiresAt ? record.expiresAt.toISOString() : null,
|
|
6540
|
+
record.maxAccess,
|
|
6541
|
+
record.revoked
|
|
6542
|
+
]
|
|
6543
|
+
);
|
|
6544
|
+
return this._mapRow(rows[0]);
|
|
6545
|
+
}
|
|
6546
|
+
async update(token, patch) {
|
|
6547
|
+
await this.ensureInitialized();
|
|
6548
|
+
const ALLOWED_COLUMNS = /* @__PURE__ */ new Set([
|
|
6549
|
+
"title",
|
|
6550
|
+
"expiresAt",
|
|
6551
|
+
"maxAccess",
|
|
6552
|
+
"revoked",
|
|
6553
|
+
"visibility",
|
|
6554
|
+
"passwordHash"
|
|
6555
|
+
]);
|
|
6556
|
+
const COLUMN_MAP = {
|
|
6557
|
+
"title": "title",
|
|
6558
|
+
"expiresAt": "expires_at",
|
|
6559
|
+
"maxAccess": "max_access",
|
|
6560
|
+
"revoked": "revoked",
|
|
6561
|
+
"visibility": "visibility",
|
|
6562
|
+
"passwordHash": "password_hash"
|
|
6563
|
+
};
|
|
6564
|
+
const sets = [];
|
|
6565
|
+
const vals = [];
|
|
6566
|
+
let i = 1;
|
|
6567
|
+
for (const [col, val] of Object.entries(patch)) {
|
|
6568
|
+
const dbCol = COLUMN_MAP[col];
|
|
6569
|
+
if (dbCol && val !== void 0) {
|
|
6570
|
+
sets.push(`${dbCol} = $${i++}`);
|
|
6571
|
+
vals.push(val);
|
|
6572
|
+
}
|
|
6573
|
+
}
|
|
6574
|
+
if (sets.length === 0) return;
|
|
6575
|
+
vals.push(token);
|
|
6576
|
+
await this.pool.query(
|
|
6577
|
+
`UPDATE lattice_shared_resources SET ${sets.join(", ")} WHERE token = $${i}`,
|
|
6578
|
+
vals
|
|
6579
|
+
);
|
|
6580
|
+
}
|
|
6581
|
+
async listByUser(tenantId, userId) {
|
|
6582
|
+
await this.ensureInitialized();
|
|
6583
|
+
const { rows } = await this.pool.query(
|
|
6584
|
+
`SELECT * FROM lattice_shared_resources
|
|
6585
|
+
WHERE tenant_id = $1 AND created_by = $2
|
|
6586
|
+
ORDER BY created_at DESC`,
|
|
6587
|
+
[tenantId, userId]
|
|
6588
|
+
);
|
|
6589
|
+
return rows.map((r) => this._mapRow(r));
|
|
6590
|
+
}
|
|
6591
|
+
async incrementAccess(token) {
|
|
6592
|
+
await this.ensureInitialized();
|
|
6593
|
+
await this.pool.query(
|
|
6594
|
+
"UPDATE lattice_shared_resources SET access_count = access_count + 1 WHERE token = $1",
|
|
6595
|
+
[token]
|
|
6596
|
+
);
|
|
6597
|
+
}
|
|
6598
|
+
async atomicIncrementAccess(token) {
|
|
6599
|
+
await this.ensureInitialized();
|
|
6600
|
+
const { rows } = await this.pool.query(
|
|
6601
|
+
`UPDATE lattice_shared_resources SET access_count = access_count + 1
|
|
6602
|
+
WHERE token = $1 AND NOT revoked
|
|
6603
|
+
AND (expires_at IS NULL OR expires_at > NOW())
|
|
6604
|
+
AND (max_access IS NULL OR access_count < max_access)
|
|
6605
|
+
RETURNING 1`,
|
|
6606
|
+
[token]
|
|
6607
|
+
);
|
|
6608
|
+
return rows.length > 0;
|
|
6609
|
+
}
|
|
6610
|
+
async ensureInitialized() {
|
|
6611
|
+
if (!this.initialized) {
|
|
6612
|
+
await this.initialize();
|
|
6613
|
+
}
|
|
6614
|
+
}
|
|
6615
|
+
_mapRow(row) {
|
|
6616
|
+
let address;
|
|
6617
|
+
if (typeof row.address === "string") {
|
|
6618
|
+
address = JSON.parse(row.address);
|
|
6619
|
+
} else {
|
|
6620
|
+
address = row.address;
|
|
6621
|
+
}
|
|
6622
|
+
return {
|
|
6623
|
+
token: row.token,
|
|
6624
|
+
address,
|
|
6625
|
+
title: row.title,
|
|
6626
|
+
createdBy: row.created_by,
|
|
6627
|
+
tenantId: row.tenant_id,
|
|
6628
|
+
workspaceId: row.workspace_id,
|
|
6629
|
+
projectId: row.project_id,
|
|
6630
|
+
assistantId: row.assistant_id,
|
|
6631
|
+
vmIsolation: row.vm_isolation,
|
|
6632
|
+
visibility: row.visibility,
|
|
6633
|
+
passwordHash: row.password_hash,
|
|
6634
|
+
expiresAt: row.expires_at ? new Date(row.expires_at) : null,
|
|
6635
|
+
maxAccess: row.max_access,
|
|
6636
|
+
accessCount: row.access_count ?? 0,
|
|
6637
|
+
revoked: row.revoked ?? false,
|
|
6638
|
+
createdAt: new Date(row.created_at),
|
|
6639
|
+
version: row.version ?? 1
|
|
6640
|
+
};
|
|
6641
|
+
}
|
|
6642
|
+
};
|
|
6643
|
+
|
|
6406
6644
|
// src/createPgStoreConfig.ts
|
|
6407
6645
|
import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres";
|
|
6408
6646
|
function createPgStoreConfig(connectionString) {
|
|
@@ -6431,12 +6669,13 @@ function createPgStoreConfig(connectionString) {
|
|
|
6431
6669
|
a2aApiKey: new PostgreSQLA2AApiKeyStore(opts),
|
|
6432
6670
|
schedule: new PostgreSQLScheduleStorage(opts),
|
|
6433
6671
|
menu: new MenuStore(opts),
|
|
6672
|
+
sharedResource: new PostgresSharedResourceStore(opts),
|
|
6434
6673
|
checkpoint
|
|
6435
6674
|
};
|
|
6436
6675
|
}
|
|
6437
6676
|
|
|
6438
6677
|
// src/stores/PostgreSQLSkillStore.ts
|
|
6439
|
-
import { Pool as
|
|
6678
|
+
import { Pool as Pool21 } from "pg";
|
|
6440
6679
|
|
|
6441
6680
|
// src/migrations/skill_migrations.ts
|
|
6442
6681
|
var createSkillsTable = {
|
|
@@ -6598,9 +6837,9 @@ var PostgreSQLSkillStore = class {
|
|
|
6598
6837
|
this.ownsPool = true;
|
|
6599
6838
|
this.initPromise = null;
|
|
6600
6839
|
if (typeof options.poolConfig === "string") {
|
|
6601
|
-
this.pool = new
|
|
6840
|
+
this.pool = new Pool21({ connectionString: options.poolConfig });
|
|
6602
6841
|
} else {
|
|
6603
|
-
this.pool = new
|
|
6842
|
+
this.pool = new Pool21(options.poolConfig);
|
|
6604
6843
|
}
|
|
6605
6844
|
this.migrationManager = new MigrationManager(this.pool);
|
|
6606
6845
|
this.migrationManager.register(createSkillsTable);
|
|
@@ -6954,12 +7193,12 @@ var createChannelIdentityMappingTables = {
|
|
|
6954
7193
|
};
|
|
6955
7194
|
|
|
6956
7195
|
// src/stores/ChannelIdentityMappingStore.ts
|
|
6957
|
-
import { Pool as
|
|
7196
|
+
import { Pool as Pool22 } from "pg";
|
|
6958
7197
|
var ChannelIdentityMappingStore = class {
|
|
6959
7198
|
constructor(options) {
|
|
6960
7199
|
this.initialized = false;
|
|
6961
7200
|
this.initPromise = null;
|
|
6962
|
-
this.pool = typeof options.poolConfig === "string" ? new
|
|
7201
|
+
this.pool = typeof options.poolConfig === "string" ? new Pool22({ connectionString: options.poolConfig }) : new Pool22(options.poolConfig);
|
|
6963
7202
|
this.migrationManager = new MigrationManager(this.pool);
|
|
6964
7203
|
this.migrationManager.register(createChannelIdentityMappingTables);
|
|
6965
7204
|
if (options.autoMigrate !== false) {
|
|
@@ -7175,7 +7414,7 @@ export {
|
|
|
7175
7414
|
ChannelIdentityMappingStore,
|
|
7176
7415
|
MenuStore,
|
|
7177
7416
|
MigrationManager,
|
|
7178
|
-
|
|
7417
|
+
Pool23 as Pool,
|
|
7179
7418
|
PostgreSQLA2AApiKeyStore,
|
|
7180
7419
|
PostgreSQLAssistantStore,
|
|
7181
7420
|
PostgreSQLChannelInstallationStore,
|
|
@@ -7192,8 +7431,10 @@ export {
|
|
|
7192
7431
|
PostgreSQLUserTenantLinkStore,
|
|
7193
7432
|
PostgreSQLWorkflowTrackingStore,
|
|
7194
7433
|
PostgreSQLWorkspaceStore,
|
|
7434
|
+
PostgresSharedResourceStore,
|
|
7195
7435
|
ThreadMessageQueueStore,
|
|
7196
7436
|
addAssistantTenantId,
|
|
7437
|
+
addFileContentType,
|
|
7197
7438
|
addProjectConfigColumn,
|
|
7198
7439
|
addScheduleTenantId,
|
|
7199
7440
|
addSkillTenantId,
|
|
@@ -7220,6 +7461,7 @@ export {
|
|
|
7220
7461
|
createPgStoreConfig,
|
|
7221
7462
|
createProjectsTable,
|
|
7222
7463
|
createScheduledTasksTable,
|
|
7464
|
+
createSharedResourcesTable,
|
|
7223
7465
|
createSkillsTable,
|
|
7224
7466
|
createTenantsTable,
|
|
7225
7467
|
createThreadMessageQueueTable,
|