@axiom-lattice/pg-stores 4.0.5 → 4.1.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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +15 -0
- package/dist/index.d.mts +41 -3
- package/dist/index.d.ts +41 -3
- package/dist/index.js +167 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +163 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/PostgresSharedResourceStore.kind.test.ts +210 -0
- package/src/createPgStoreConfig.ts +2 -0
- package/src/index.ts +1 -0
- package/src/migrations/add_share_kind.ts +45 -0
- package/src/stores/PostgresSharedResourceStore.ts +125 -17
package/dist/index.mjs
CHANGED
|
@@ -9242,7 +9242,106 @@ var createSharedResourcesTable = {
|
|
|
9242
9242
|
}
|
|
9243
9243
|
};
|
|
9244
9244
|
|
|
9245
|
+
// src/migrations/add_share_open_grants.ts
|
|
9246
|
+
var addShareOpenGrants = {
|
|
9247
|
+
version: 180,
|
|
9248
|
+
name: "add_share_open_grants",
|
|
9249
|
+
up: async (client) => {
|
|
9250
|
+
await client.query(`
|
|
9251
|
+
ALTER TABLE lattice_shared_resources
|
|
9252
|
+
ADD COLUMN IF NOT EXISTS open_grants JSONB
|
|
9253
|
+
`);
|
|
9254
|
+
},
|
|
9255
|
+
down: async (client) => {
|
|
9256
|
+
await client.query(`
|
|
9257
|
+
ALTER TABLE lattice_shared_resources
|
|
9258
|
+
DROP COLUMN IF EXISTS open_grants
|
|
9259
|
+
`);
|
|
9260
|
+
}
|
|
9261
|
+
};
|
|
9262
|
+
|
|
9263
|
+
// src/migrations/add_share_kind.ts
|
|
9264
|
+
var addShareKind = {
|
|
9265
|
+
version: 208,
|
|
9266
|
+
name: "add_share_kind",
|
|
9267
|
+
up: async (client) => {
|
|
9268
|
+
await client.query(`
|
|
9269
|
+
ALTER TABLE lattice_shared_resources
|
|
9270
|
+
ADD COLUMN IF NOT EXISTS kind VARCHAR(16) NOT NULL DEFAULT 'file'
|
|
9271
|
+
`);
|
|
9272
|
+
await client.query(`
|
|
9273
|
+
ALTER TABLE lattice_shared_resources
|
|
9274
|
+
DROP CONSTRAINT IF EXISTS lattice_shared_resources_kind_check
|
|
9275
|
+
`);
|
|
9276
|
+
await client.query(`
|
|
9277
|
+
ALTER TABLE lattice_shared_resources
|
|
9278
|
+
ADD CONSTRAINT lattice_shared_resources_kind_check
|
|
9279
|
+
CHECK (kind IN ('file', 'mcpApp'))
|
|
9280
|
+
`);
|
|
9281
|
+
await client.query(`
|
|
9282
|
+
ALTER TABLE lattice_shared_resources
|
|
9283
|
+
DROP CONSTRAINT IF EXISTS lattice_shared_resources_mcp_app_visibility_check
|
|
9284
|
+
`);
|
|
9285
|
+
await client.query(`
|
|
9286
|
+
ALTER TABLE lattice_shared_resources
|
|
9287
|
+
ADD CONSTRAINT lattice_shared_resources_mcp_app_visibility_check
|
|
9288
|
+
CHECK (kind <> 'mcpApp' OR visibility IN ('public', 'password'))
|
|
9289
|
+
`);
|
|
9290
|
+
},
|
|
9291
|
+
down: async (client) => {
|
|
9292
|
+
await client.query(`
|
|
9293
|
+
ALTER TABLE lattice_shared_resources
|
|
9294
|
+
DROP CONSTRAINT IF EXISTS lattice_shared_resources_mcp_app_visibility_check
|
|
9295
|
+
`);
|
|
9296
|
+
await client.query(`
|
|
9297
|
+
ALTER TABLE lattice_shared_resources
|
|
9298
|
+
DROP CONSTRAINT IF EXISTS lattice_shared_resources_kind_check
|
|
9299
|
+
`);
|
|
9300
|
+
await client.query(`
|
|
9301
|
+
ALTER TABLE lattice_shared_resources
|
|
9302
|
+
DROP COLUMN IF EXISTS kind
|
|
9303
|
+
`);
|
|
9304
|
+
}
|
|
9305
|
+
};
|
|
9306
|
+
|
|
9245
9307
|
// src/stores/PostgresSharedResourceStore.ts
|
|
9308
|
+
var InvalidMcpAppShareAddressError = class extends Error {
|
|
9309
|
+
/**
|
|
9310
|
+
* @param token - Share token owning the invalid address.
|
|
9311
|
+
*/
|
|
9312
|
+
constructor(token) {
|
|
9313
|
+
super(`Share ${token} has an invalid MCP App address`);
|
|
9314
|
+
/** Machine-readable failure code. */
|
|
9315
|
+
this.code = "INVALID_MCP_APP_SHARE_ADDRESS";
|
|
9316
|
+
this.name = "InvalidMcpAppShareAddressError";
|
|
9317
|
+
}
|
|
9318
|
+
};
|
|
9319
|
+
var InvalidMcpAppShareVisibilityError = class extends Error {
|
|
9320
|
+
/**
|
|
9321
|
+
* @param token - Share token owning the invalid visibility.
|
|
9322
|
+
* @param visibility - Visibility value found in the row.
|
|
9323
|
+
*/
|
|
9324
|
+
constructor(token, visibility) {
|
|
9325
|
+
super(
|
|
9326
|
+
`Share ${token} has unsupported MCP App visibility: ${visibility}`
|
|
9327
|
+
);
|
|
9328
|
+
/** Machine-readable failure code. */
|
|
9329
|
+
this.code = "INVALID_MCP_APP_SHARE_VISIBILITY";
|
|
9330
|
+
this.name = "InvalidMcpAppShareVisibilityError";
|
|
9331
|
+
this.visibility = visibility;
|
|
9332
|
+
}
|
|
9333
|
+
};
|
|
9334
|
+
var InvalidFileShareAddressError = class extends Error {
|
|
9335
|
+
/**
|
|
9336
|
+
* @param token - Share token owning the invalid address.
|
|
9337
|
+
*/
|
|
9338
|
+
constructor(token) {
|
|
9339
|
+
super(`Share ${token} has an invalid file address`);
|
|
9340
|
+
/** Machine-readable failure code. */
|
|
9341
|
+
this.code = "INVALID_FILE_SHARE_ADDRESS";
|
|
9342
|
+
this.name = "InvalidFileShareAddressError";
|
|
9343
|
+
}
|
|
9344
|
+
};
|
|
9246
9345
|
var PostgresSharedResourceStore = class {
|
|
9247
9346
|
constructor(options) {
|
|
9248
9347
|
this.initialized = false;
|
|
@@ -9259,6 +9358,8 @@ var PostgresSharedResourceStore = class {
|
|
|
9259
9358
|
})();
|
|
9260
9359
|
this.migrationManager = new MigrationManager(this.pool);
|
|
9261
9360
|
this.migrationManager.register(createSharedResourcesTable);
|
|
9361
|
+
this.migrationManager.register(addShareOpenGrants);
|
|
9362
|
+
this.migrationManager.register(addShareKind);
|
|
9262
9363
|
if (options.autoMigrate !== false) {
|
|
9263
9364
|
this.initialize().catch((error) => {
|
|
9264
9365
|
console.error(
|
|
@@ -9300,13 +9401,14 @@ var PostgresSharedResourceStore = class {
|
|
|
9300
9401
|
await this.ensureInitialized();
|
|
9301
9402
|
const { rows } = await this.pool.query(
|
|
9302
9403
|
`INSERT INTO lattice_shared_resources
|
|
9303
|
-
(token, address, title, created_by, tenant_id, workspace_id, project_id,
|
|
9404
|
+
(token, kind, address, title, created_by, tenant_id, workspace_id, project_id,
|
|
9304
9405
|
assistant_id, vm_isolation, visibility, password_hash,
|
|
9305
9406
|
expires_at, max_access, open_grants, revoked)
|
|
9306
|
-
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15)
|
|
9407
|
+
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)
|
|
9307
9408
|
RETURNING *`,
|
|
9308
9409
|
[
|
|
9309
9410
|
record.token,
|
|
9411
|
+
record.kind ?? "file",
|
|
9310
9412
|
JSON.stringify(record.address),
|
|
9311
9413
|
record.title,
|
|
9312
9414
|
record.createdBy,
|
|
@@ -9395,15 +9497,9 @@ var PostgresSharedResourceStore = class {
|
|
|
9395
9497
|
}
|
|
9396
9498
|
}
|
|
9397
9499
|
_mapRow(row) {
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
address = JSON.parse(row.address);
|
|
9401
|
-
} else {
|
|
9402
|
-
address = row.address;
|
|
9403
|
-
}
|
|
9404
|
-
return {
|
|
9500
|
+
const address = parseShareAddress(row.address);
|
|
9501
|
+
const base = {
|
|
9405
9502
|
token: row.token,
|
|
9406
|
-
address,
|
|
9407
9503
|
title: row.title,
|
|
9408
9504
|
createdBy: row.created_by,
|
|
9409
9505
|
tenantId: row.tenant_id,
|
|
@@ -9411,7 +9507,6 @@ var PostgresSharedResourceStore = class {
|
|
|
9411
9507
|
projectId: row.project_id,
|
|
9412
9508
|
assistantId: row.assistant_id,
|
|
9413
9509
|
vmIsolation: row.vm_isolation,
|
|
9414
|
-
visibility: row.visibility,
|
|
9415
9510
|
passwordHash: row.password_hash,
|
|
9416
9511
|
expiresAt: row.expires_at ? new Date(row.expires_at) : null,
|
|
9417
9512
|
maxAccess: row.max_access,
|
|
@@ -9421,8 +9516,52 @@ var PostgresSharedResourceStore = class {
|
|
|
9421
9516
|
createdAt: new Date(row.created_at),
|
|
9422
9517
|
version: row.version ?? 1
|
|
9423
9518
|
};
|
|
9519
|
+
if (row.kind === "mcpApp") {
|
|
9520
|
+
if (!isRecord3(address) || address.kind !== "mcpApp") {
|
|
9521
|
+
throw new InvalidMcpAppShareAddressError(row.token);
|
|
9522
|
+
}
|
|
9523
|
+
const app = address.app;
|
|
9524
|
+
if (!isMcpAppShareApp(app)) {
|
|
9525
|
+
throw new InvalidMcpAppShareAddressError(row.token);
|
|
9526
|
+
}
|
|
9527
|
+
if (row.visibility !== "public" && row.visibility !== "password") {
|
|
9528
|
+
throw new InvalidMcpAppShareVisibilityError(row.token, row.visibility);
|
|
9529
|
+
}
|
|
9530
|
+
return {
|
|
9531
|
+
...base,
|
|
9532
|
+
kind: "mcpApp",
|
|
9533
|
+
address: { kind: "mcpApp", app },
|
|
9534
|
+
visibility: row.visibility
|
|
9535
|
+
};
|
|
9536
|
+
}
|
|
9537
|
+
if (!isRecord3(address) || typeof address.volume !== "string" || typeof address.resourcePath !== "string") {
|
|
9538
|
+
throw new InvalidFileShareAddressError(row.token);
|
|
9539
|
+
}
|
|
9540
|
+
return {
|
|
9541
|
+
...base,
|
|
9542
|
+
kind: "file",
|
|
9543
|
+
address: {
|
|
9544
|
+
volume: address.volume,
|
|
9545
|
+
resourcePath: address.resourcePath
|
|
9546
|
+
},
|
|
9547
|
+
visibility: row.visibility
|
|
9548
|
+
};
|
|
9424
9549
|
}
|
|
9425
9550
|
};
|
|
9551
|
+
function isRecord3(value) {
|
|
9552
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9553
|
+
}
|
|
9554
|
+
function isMcpAppShareApp(value) {
|
|
9555
|
+
return isRecord3(value) && (value.kind === "plugin" || value.kind === "mcp");
|
|
9556
|
+
}
|
|
9557
|
+
function parseShareAddress(raw) {
|
|
9558
|
+
if (typeof raw !== "string") return raw;
|
|
9559
|
+
try {
|
|
9560
|
+
return JSON.parse(raw);
|
|
9561
|
+
} catch {
|
|
9562
|
+
return null;
|
|
9563
|
+
}
|
|
9564
|
+
}
|
|
9426
9565
|
|
|
9427
9566
|
// src/stores/PostgreSQLCollectionStore.ts
|
|
9428
9567
|
import { Pool as Pool24 } from "pg";
|
|
@@ -9939,24 +10078,6 @@ var reencryptLegacyConnectionSecrets = {
|
|
|
9939
10078
|
}
|
|
9940
10079
|
};
|
|
9941
10080
|
|
|
9942
|
-
// src/migrations/add_share_open_grants.ts
|
|
9943
|
-
var addShareOpenGrants = {
|
|
9944
|
-
version: 180,
|
|
9945
|
-
name: "add_share_open_grants",
|
|
9946
|
-
up: async (client) => {
|
|
9947
|
-
await client.query(`
|
|
9948
|
-
ALTER TABLE lattice_shared_resources
|
|
9949
|
-
ADD COLUMN IF NOT EXISTS open_grants JSONB
|
|
9950
|
-
`);
|
|
9951
|
-
},
|
|
9952
|
-
down: async (client) => {
|
|
9953
|
-
await client.query(`
|
|
9954
|
-
ALTER TABLE lattice_shared_resources
|
|
9955
|
-
DROP COLUMN IF EXISTS open_grants
|
|
9956
|
-
`);
|
|
9957
|
-
}
|
|
9958
|
-
};
|
|
9959
|
-
|
|
9960
10081
|
// src/migrations/collection_migrations.ts
|
|
9961
10082
|
var createCollectionsTable = {
|
|
9962
10083
|
version: 137,
|
|
@@ -11456,14 +11577,14 @@ var DuplicateProjectRoomMessageIdempotencyKeyError = class extends Error {
|
|
|
11456
11577
|
this.name = "DuplicateProjectRoomMessageIdempotencyKeyError";
|
|
11457
11578
|
}
|
|
11458
11579
|
};
|
|
11459
|
-
function
|
|
11580
|
+
function isRecord4(value) {
|
|
11460
11581
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11461
11582
|
}
|
|
11462
11583
|
function hasOnlyKeys(value, keys) {
|
|
11463
11584
|
return Object.keys(value).every((key) => keys.includes(key));
|
|
11464
11585
|
}
|
|
11465
11586
|
function mapAuthor(value) {
|
|
11466
|
-
if (!
|
|
11587
|
+
if (!isRecord4(value) || typeof value.type !== "string") return void 0;
|
|
11467
11588
|
if (value.type === "human" && hasOnlyKeys(value, ["type", "userId"]) && typeof value.userId === "string") return { type: "human", userId: value.userId };
|
|
11468
11589
|
if (value.type === "bot" && hasOnlyKeys(value, ["type", "membershipId", "assistantId"]) && typeof value.membershipId === "string" && typeof value.assistantId === "string") {
|
|
11469
11590
|
return { type: "bot", membershipId: value.membershipId, assistantId: value.assistantId };
|
|
@@ -11472,7 +11593,7 @@ function mapAuthor(value) {
|
|
|
11472
11593
|
return void 0;
|
|
11473
11594
|
}
|
|
11474
11595
|
function mapMention(value) {
|
|
11475
|
-
if (!
|
|
11596
|
+
if (!isRecord4(value) || typeof value.type !== "string") return void 0;
|
|
11476
11597
|
if (value.type === "bot" && hasOnlyKeys(value, ["type", "membershipId"]) && typeof value.membershipId === "string") {
|
|
11477
11598
|
return { type: "bot", membershipId: value.membershipId };
|
|
11478
11599
|
}
|
|
@@ -11484,7 +11605,7 @@ function isSource(value) {
|
|
|
11484
11605
|
}
|
|
11485
11606
|
function mapRow5(row) {
|
|
11486
11607
|
const author = mapAuthor(row.author);
|
|
11487
|
-
const content =
|
|
11608
|
+
const content = isRecord4(row.content) && row.content.type === "text" && typeof row.content.text === "string" && hasOnlyKeys(row.content, ["type", "text"]) ? { type: "text", text: row.content.text } : void 0;
|
|
11488
11609
|
const mentions = Array.isArray(row.mentions) ? row.mentions.map(mapMention) : void 0;
|
|
11489
11610
|
if (typeof row.id !== "string" || typeof row.tenant_id !== "string" || typeof row.workspace_id !== "string" || typeof row.project_id !== "string" || typeof row.room_id !== "string" || !author || !content || !mentions || mentions.some((mention) => mention === void 0) || row.reply_to_message_id !== null && typeof row.reply_to_message_id !== "string" || !isSource(row.source) || row.source_id !== null && typeof row.source_id !== "string" || row.idempotency_key !== null && typeof row.idempotency_key !== "string" || !(row.created_at instanceof Date) || Number.isNaN(row.created_at.getTime())) {
|
|
11490
11611
|
throw new Error("Invalid project room message row");
|
|
@@ -13922,7 +14043,7 @@ async function rollbackQuietly(client) {
|
|
|
13922
14043
|
function isUniqueViolation3(error) {
|
|
13923
14044
|
return typeof error === "object" && error !== null && "code" in error && error.code === "23505";
|
|
13924
14045
|
}
|
|
13925
|
-
function
|
|
14046
|
+
function isRecord5(value) {
|
|
13926
14047
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13927
14048
|
}
|
|
13928
14049
|
function checkpointKey(checkpointNs, checkpointId) {
|
|
@@ -13935,17 +14056,17 @@ function checkpointRecord(value) {
|
|
|
13935
14056
|
if (typeof value === "string") {
|
|
13936
14057
|
try {
|
|
13937
14058
|
const parsed = JSON.parse(value);
|
|
13938
|
-
return
|
|
14059
|
+
return isRecord5(parsed) ? parsed : void 0;
|
|
13939
14060
|
} catch {
|
|
13940
14061
|
return void 0;
|
|
13941
14062
|
}
|
|
13942
14063
|
}
|
|
13943
|
-
return
|
|
14064
|
+
return isRecord5(value) ? value : void 0;
|
|
13944
14065
|
}
|
|
13945
14066
|
function channelVersions(value) {
|
|
13946
14067
|
const checkpoint = checkpointRecord(value);
|
|
13947
14068
|
const versions = checkpoint?.channel_versions;
|
|
13948
|
-
return
|
|
14069
|
+
return isRecord5(versions) ? versions : void 0;
|
|
13949
14070
|
}
|
|
13950
14071
|
var DELETE_CHUNK_SIZE = 100;
|
|
13951
14072
|
function chunk(items, size) {
|
|
@@ -14598,6 +14719,7 @@ async function createPgStoreConfig(connectionString) {
|
|
|
14598
14719
|
mm.register(createAgentRunProjectTaskMigration);
|
|
14599
14720
|
mm.register(agentRunProjectTaskRunningIndexMigration);
|
|
14600
14721
|
mm.register(addModelProviderKindDefault);
|
|
14722
|
+
mm.register(addShareKind);
|
|
14601
14723
|
await mm.migrate();
|
|
14602
14724
|
const checkpoint = PostgresSaver.fromConnString(connectionString);
|
|
14603
14725
|
checkpoint.setup().catch((err) => {
|
|
@@ -15205,6 +15327,9 @@ export {
|
|
|
15205
15327
|
CheckpointTargetNotEmptyError,
|
|
15206
15328
|
DuplicateProjectMembershipError,
|
|
15207
15329
|
DuplicateProjectRoomMessageIdempotencyKeyError,
|
|
15330
|
+
InvalidFileShareAddressError,
|
|
15331
|
+
InvalidMcpAppShareAddressError,
|
|
15332
|
+
InvalidMcpAppShareVisibilityError,
|
|
15208
15333
|
MenuStore,
|
|
15209
15334
|
MigrationManager,
|
|
15210
15335
|
PGVectorStoreProvider,
|
|
@@ -15257,6 +15382,7 @@ export {
|
|
|
15257
15382
|
addMcpAppContentType,
|
|
15258
15383
|
addProjectConfigColumn,
|
|
15259
15384
|
addScheduleTenantId,
|
|
15385
|
+
addShareKind,
|
|
15260
15386
|
addSkillTenantId,
|
|
15261
15387
|
addStepThreadId,
|
|
15262
15388
|
addTaskIdToEvalRuns,
|