@mastra/pg 1.22.3-alpha.1 → 1.22.3-alpha.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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +61 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +61 -20
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/agents/index.d.ts +1 -0
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/skills/index.d.ts +1 -0
- package/dist/storage/domains/skills/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -818,19 +818,18 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
818
818
|
}
|
|
819
819
|
async ensureNamespaceSchema(indexName, client) {
|
|
820
820
|
const { tableName, parsedIndexName } = this.getTableName(indexName);
|
|
821
|
-
const schemaName = this.schema ? (0, _mastra_core_utils.parseSqlIdentifier)(this.schema, "schema name") : "public";
|
|
822
821
|
if ((await client.query(`SELECT 1
|
|
823
|
-
FROM
|
|
824
|
-
WHERE
|
|
822
|
+
FROM pg_attribute
|
|
823
|
+
WHERE attrelid = to_regclass($1)
|
|
824
|
+
AND attname = 'vector_id'
|
|
825
|
+
AND attnum > 0
|
|
826
|
+
AND NOT attisdropped`, [tableName])).rowCount === 0) return;
|
|
825
827
|
await client.query(`ALTER TABLE ${tableName} ADD COLUMN IF NOT EXISTS namespace VARCHAR(255) NOT NULL DEFAULT '${DEFAULT_NAMESPACE}'`);
|
|
826
828
|
const legacyConstraints = await client.query(`SELECT c.conname
|
|
827
829
|
FROM pg_constraint c
|
|
828
|
-
|
|
829
|
-
JOIN pg_namespace n ON n.oid = t.relnamespace
|
|
830
|
-
WHERE n.nspname = $1
|
|
831
|
-
AND t.relname = $2
|
|
830
|
+
WHERE c.conrelid = to_regclass($1)
|
|
832
831
|
AND c.contype = 'u'
|
|
833
|
-
AND pg_get_constraintdef(c.oid) = 'UNIQUE (vector_id)'`, [
|
|
832
|
+
AND pg_get_constraintdef(c.oid) = 'UNIQUE (vector_id)'`, [tableName]);
|
|
834
833
|
for (const { conname } of legacyConstraints.rows) {
|
|
835
834
|
const parsedConstraintName = (0, _mastra_core_utils.parseSqlIdentifier)(conname, "constraint name");
|
|
836
835
|
await client.query(`ALTER TABLE ${tableName} DROP CONSTRAINT "${parsedConstraintName}"`);
|
|
@@ -1468,7 +1467,9 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1468
1467
|
return (await client.query(`
|
|
1469
1468
|
SELECT DISTINCT t.table_name
|
|
1470
1469
|
FROM information_schema.tables t
|
|
1471
|
-
WHERE t.table_schema =
|
|
1470
|
+
WHERE t.table_schema = ANY(
|
|
1471
|
+
CASE WHEN $1::text IS NULL THEN current_schemas(false) ELSE ARRAY[$1::text] END
|
|
1472
|
+
)
|
|
1472
1473
|
AND EXISTS (
|
|
1473
1474
|
SELECT 1
|
|
1474
1475
|
FROM information_schema.columns c
|
|
@@ -1493,7 +1494,7 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1493
1494
|
AND c.column_name = 'metadata'
|
|
1494
1495
|
AND c.data_type = 'jsonb'
|
|
1495
1496
|
);
|
|
1496
|
-
`, [this.schema
|
|
1497
|
+
`, [this.schema ?? null])).rows.map((row) => row.table_name);
|
|
1497
1498
|
} catch (e) {
|
|
1498
1499
|
const mastraError = new _mastra_core_error.MastraError({
|
|
1499
1500
|
id: (0, _mastra_core_storage.createVectorErrorId)("PG", "LIST_INDEXES", "FAILED"),
|
|
@@ -1528,15 +1529,18 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1528
1529
|
async describeIndexMetadata({ indexName }) {
|
|
1529
1530
|
const client = await this.pool.connect();
|
|
1530
1531
|
try {
|
|
1531
|
-
const { tableName } = this.getTableName(indexName);
|
|
1532
|
+
const { tableName, parsedIndexName } = this.getTableName(indexName);
|
|
1532
1533
|
const tableExists = await client.query(`
|
|
1533
|
-
SELECT udt_name
|
|
1534
|
-
FROM
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
AND
|
|
1534
|
+
SELECT t.typname AS udt_name
|
|
1535
|
+
FROM pg_attribute a
|
|
1536
|
+
JOIN pg_type t ON t.oid = a.atttypid
|
|
1537
|
+
WHERE a.attrelid = to_regclass($1)
|
|
1538
|
+
AND a.attname = 'embedding'
|
|
1539
|
+
AND a.attnum > 0
|
|
1540
|
+
AND NOT a.attisdropped
|
|
1541
|
+
AND t.typname IN ('vector', 'halfvec', 'bit', 'sparsevec')
|
|
1538
1542
|
LIMIT 1;
|
|
1539
|
-
`, [
|
|
1543
|
+
`, [tableName]);
|
|
1540
1544
|
if (tableExists.rows.length === 0) throw new Error(`Vector table ${tableName} does not exist`);
|
|
1541
1545
|
const udtName = tableExists.rows[0].udt_name;
|
|
1542
1546
|
const vectorType = udtName === "halfvec" ? "halfvec" : udtName === "bit" ? "bit" : udtName === "sparsevec" ? "sparsevec" : "vector";
|
|
@@ -1555,12 +1559,11 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1555
1559
|
JOIN pg_class c ON i.indexrelid = c.oid
|
|
1556
1560
|
JOIN pg_am am ON c.relam = am.oid
|
|
1557
1561
|
JOIN pg_opclass opclass ON i.indclass[0] = opclass.oid
|
|
1558
|
-
JOIN pg_namespace n ON c.relnamespace = n.oid
|
|
1559
1562
|
WHERE c.relname = $1
|
|
1560
|
-
AND
|
|
1563
|
+
AND i.indrelid = to_regclass($2);
|
|
1561
1564
|
`;
|
|
1562
1565
|
const dimResult = await client.query(dimensionQuery, [tableName]);
|
|
1563
|
-
const { index_method, index_def, operator_class } = (await client.query(indexQuery, [`${
|
|
1566
|
+
const { index_method, index_def, operator_class } = (await client.query(indexQuery, [`${parsedIndexName}_vector_idx`, tableName])).rows[0] || {
|
|
1564
1567
|
index_method: "flat",
|
|
1565
1568
|
index_def: "",
|
|
1566
1569
|
operator_class: "cosine"
|
|
@@ -4498,6 +4501,25 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4498
4501
|
}, error);
|
|
4499
4502
|
}
|
|
4500
4503
|
}
|
|
4504
|
+
async getVersions(ids) {
|
|
4505
|
+
if (ids.length === 0) return [];
|
|
4506
|
+
try {
|
|
4507
|
+
const tableName = getTableName$5({
|
|
4508
|
+
indexName: _mastra_core_storage.TABLE_AGENT_VERSIONS,
|
|
4509
|
+
schemaName: getSchemaName$5(this.#schema)
|
|
4510
|
+
});
|
|
4511
|
+
const placeholders = ids.map((_, i) => `$${i + 1}`).join(", ");
|
|
4512
|
+
return (await this.#db.client.manyOrNone(`SELECT * FROM ${tableName} WHERE id IN (${placeholders})`, ids)).map((row) => this.parseVersionRow(row));
|
|
4513
|
+
} catch (error) {
|
|
4514
|
+
if (error instanceof _mastra_core_error.MastraError) throw error;
|
|
4515
|
+
throw new _mastra_core_error.MastraError({
|
|
4516
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "GET_VERSIONS", "FAILED"),
|
|
4517
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
4518
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
4519
|
+
details: { count: ids.length }
|
|
4520
|
+
}, error);
|
|
4521
|
+
}
|
|
4522
|
+
}
|
|
4501
4523
|
async getVersionByNumber(agentId, versionNumber) {
|
|
4502
4524
|
try {
|
|
4503
4525
|
const tableName = getTableName$5({
|
|
@@ -20122,6 +20144,25 @@ var SkillsPG = class SkillsPG extends _mastra_core_storage.SkillsStorage {
|
|
|
20122
20144
|
}, error);
|
|
20123
20145
|
}
|
|
20124
20146
|
}
|
|
20147
|
+
async getVersions(ids) {
|
|
20148
|
+
if (ids.length === 0) return [];
|
|
20149
|
+
try {
|
|
20150
|
+
const tableName = getTableName$5({
|
|
20151
|
+
indexName: _mastra_core_storage.TABLE_SKILL_VERSIONS,
|
|
20152
|
+
schemaName: getSchemaName$5(this.#schema)
|
|
20153
|
+
});
|
|
20154
|
+
const placeholders = ids.map((_, i) => `$${i + 1}`).join(", ");
|
|
20155
|
+
return (await this.#db.client.manyOrNone(`SELECT * FROM ${tableName} WHERE id IN (${placeholders})`, ids)).map((row) => this.parseVersionRow(row));
|
|
20156
|
+
} catch (error) {
|
|
20157
|
+
if (error instanceof _mastra_core_error.MastraError) throw error;
|
|
20158
|
+
throw new _mastra_core_error.MastraError({
|
|
20159
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "GET_SKILL_VERSIONS", "FAILED"),
|
|
20160
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
20161
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
20162
|
+
details: { count: ids.length }
|
|
20163
|
+
}, error);
|
|
20164
|
+
}
|
|
20165
|
+
}
|
|
20125
20166
|
async getVersionByNumber(skillId, versionNumber) {
|
|
20126
20167
|
try {
|
|
20127
20168
|
const tableName = getTableName$5({
|