@mastra/pg 1.32.0-alpha.4 → 1.32.0-alpha.6
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/docs/references/docs-memory-semantic-recall.md +20 -0
- package/dist/docs/references/reference-memory-memory-class.md +2 -0
- package/dist/index.cjs +123 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +122 -94
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/trace-aggregate.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/trace-query.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/docs/SKILL.md
CHANGED
|
@@ -405,6 +405,26 @@ Multilingual E5 produces 1024-dimensional vectors. Your vector index must be cre
|
|
|
405
405
|
|
|
406
406
|
FastEmbed models embed at most 512 tokens per input (roughly 2,000 to 2,500 characters of English text). Longer inputs are truncated, so text past the limit doesn't affect the embedding and can't be found by semantic recall. The AI SDK v3 FastEmbed models return a warning when this happens. The legacy v1 and v2 models don't. If you embed long documents with FastEmbed, chunk them to fit the window, for example with `maxSize: 1500` in `MDocument.chunk()`.
|
|
407
407
|
|
|
408
|
+
### Setting the embedding dimension
|
|
409
|
+
|
|
410
|
+
To name the vector index, Memory needs the embedder's output dimension. By default it finds the dimension by embedding a short probe string the first time semantic recall is set up, once per `Memory` instance. If you already know the dimension, set `embeddingDimension`. Memory then skips the probe, so startup makes no embedding call and doesn't depend on the embedding provider being reachable:
|
|
411
|
+
|
|
412
|
+
```ts
|
|
413
|
+
import { Memory } from '@mastra/memory'
|
|
414
|
+
|
|
415
|
+
const memory = new Memory({
|
|
416
|
+
embedder: 'openai/text-embedding-3-small',
|
|
417
|
+
embeddingDimension: 1536,
|
|
418
|
+
options: {
|
|
419
|
+
semanticRecall: true,
|
|
420
|
+
},
|
|
421
|
+
})
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
The index name is the same whether the dimension is configured or probed, so existing indexes keep working.
|
|
425
|
+
|
|
426
|
+
The value must match the vectors the embedder returns. Memory compares it with the first real embedding, and on a mismatch it throws a `MASTRA_MEMORY_EMBEDDING_DIMENSION_MISMATCH` error naming both values before creating or querying any index. Update `embeddingDimension` whenever you change the embedding model or its output dimension.
|
|
427
|
+
|
|
408
428
|
## PostgreSQL index optimization
|
|
409
429
|
|
|
410
430
|
When using PostgreSQL as your vector store, you can optimize semantic recall performance by configuring the vector index. This is particularly important for large-scale deployments with thousands of messages.
|
|
@@ -37,6 +37,8 @@ export const agent = new Agent({
|
|
|
37
37
|
|
|
38
38
|
**embedder** (`EmbeddingModel<string> | EmbeddingModelV2<string>`): Embedder instance for vector embeddings. Required when semantic recall is enabled.
|
|
39
39
|
|
|
40
|
+
**embeddingDimension** (`number`): Output dimension of the embedder, as a positive integer. When set, Memory uses it to name the semantic recall index instead of embedding a probe string on first use. It must match the vectors the embedder returns: a mismatch throws a MASTRA\_MEMORY\_EMBEDDING\_DIMENSION\_MISMATCH error before any index is created. See Setting the embedding dimension.
|
|
41
|
+
|
|
40
42
|
**options** (`MemoryConfig`): Memory configuration options.
|
|
41
43
|
|
|
42
44
|
**options.lastMessages** (`number | false`): Number of most recent messages to include in context. Set to false to disable the message history feature entirely (messages are not loaded into context or saved). Use Number.MAX\_SAFE\_INTEGER to retrieve all messages with no limit. To load messages without saving new ones, use the readOnly option. The window slides forward on every request, so once a thread exceeds the limit, each turn invalidates the provider prompt cache. For long-running conversations, use Observational Memory instead.
|
package/dist/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
@@ -185,12 +185,14 @@ var PGFilterTranslator = class extends _mastra_core_vector_filter.BaseFilterTran
|
|
|
185
185
|
if (key === "$options") continue;
|
|
186
186
|
const newPath = currentPath ? `${currentPath}.${key}` : key;
|
|
187
187
|
if (this.isLogicalOperator(key)) result[key] = Array.isArray(value) ? value.map((filter) => this.translateNode(filter)) : this.translateNode(value);
|
|
188
|
-
else if (this.isOperator(key))
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
else
|
|
193
|
-
|
|
188
|
+
else if (this.isOperator(key)) {
|
|
189
|
+
if (this.isArrayOperator(key) && !Array.isArray(value) && key !== "$elemMatch") result[key] = [value];
|
|
190
|
+
else if (this.isBasicOperator(key) && Array.isArray(value)) result[key] = JSON.stringify(value);
|
|
191
|
+
else result[key] = value;
|
|
192
|
+
} else if (typeof value === "object" && value !== null) {
|
|
193
|
+
if (Object.keys(value).some((k) => this.isOperator(k))) result[newPath] = this.translateNode(value);
|
|
194
|
+
else Object.assign(result, this.translateNode(value, newPath));
|
|
195
|
+
} else result[newPath] = this.translateNode(value);
|
|
194
196
|
}
|
|
195
197
|
return result;
|
|
196
198
|
}
|
|
@@ -1451,19 +1453,21 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1451
1453
|
try {
|
|
1452
1454
|
existingIndexInfo = await this.describeIndexMetadata({ indexName }, client);
|
|
1453
1455
|
dimension = existingIndexInfo.dimension;
|
|
1454
|
-
if (isConfigEmpty && existingIndexInfo.metric === metric)
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1456
|
+
if (isConfigEmpty && existingIndexInfo.metric === metric) {
|
|
1457
|
+
if (existingIndexInfo.type === "flat") this.logger?.debug(`No index exists for ${vectorIndexName}, will create default ivfflat index`);
|
|
1458
|
+
else {
|
|
1459
|
+
this.logger?.debug(`Index ${vectorIndexName} already exists (type: ${existingIndexInfo.type}, metric: ${existingIndexInfo.metric}), preserving existing configuration`);
|
|
1460
|
+
const cacheKey = await this.getIndexCacheKey({
|
|
1461
|
+
indexName,
|
|
1462
|
+
dimension,
|
|
1463
|
+
type: existingIndexInfo.type,
|
|
1464
|
+
metric: existingIndexInfo.metric,
|
|
1465
|
+
vectorType: existingIndexInfo.vectorType
|
|
1466
|
+
});
|
|
1467
|
+
this.createdIndexes.set(indexName, cacheKey);
|
|
1468
|
+
this.indexVectorTypes.set(indexName, existingIndexInfo.vectorType);
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1467
1471
|
}
|
|
1468
1472
|
let configMatches = existingIndexInfo.metric === metric && existingIndexInfo.type === indexType;
|
|
1469
1473
|
if (indexType === "hnsw") configMatches = configMatches && existingIndexInfo.config.m === (indexConfig.hnsw?.m ?? 8) && existingIndexInfo.config.efConstruction === (indexConfig.hnsw?.efConstruction ?? 32);
|
|
@@ -2969,19 +2973,13 @@ var PgDB = class extends _mastra_core_base.MastraBase {
|
|
|
2969
2973
|
return filtered;
|
|
2970
2974
|
}
|
|
2971
2975
|
async hasColumn(table, column) {
|
|
2972
|
-
const schema = this.schemaName || "public";
|
|
2973
2976
|
const snapshot = this.schemaSnapshot;
|
|
2974
2977
|
if (snapshot) {
|
|
2975
2978
|
const columns = snapshot.columns.get(table);
|
|
2976
2979
|
if (!columns) return false;
|
|
2977
2980
|
return columns.has(column) || columns.has(column.toLowerCase());
|
|
2978
2981
|
}
|
|
2979
|
-
return
|
|
2980
|
-
schema,
|
|
2981
|
-
table,
|
|
2982
|
-
column,
|
|
2983
|
-
column.toLowerCase()
|
|
2984
|
-
]);
|
|
2982
|
+
return await this.getColumnType(table, column) !== null;
|
|
2985
2983
|
}
|
|
2986
2984
|
/**
|
|
2987
2985
|
* Returns the Postgres data type of a column (e.g. `jsonb`, `json`, `text`),
|
|
@@ -3003,7 +3001,7 @@ var PgDB = class extends _mastra_core_base.MastraBase {
|
|
|
3003
3001
|
const cached = this.columnTypeCache.get(table)?.get(column);
|
|
3004
3002
|
if (cached !== void 0) return cached;
|
|
3005
3003
|
const schema = this.schemaName || "public";
|
|
3006
|
-
const dataType = (await this.client.oneOrNone(`SELECT data_type FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND (column_name = $3 OR column_name = $4)`, [
|
|
3004
|
+
const dataType = (await this.client.oneOrNone(`SELECT data_type FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND (column_name = $3 OR column_name = $4) ORDER BY (column_name = $3) DESC LIMIT 1`, [
|
|
3007
3005
|
schema,
|
|
3008
3006
|
table,
|
|
3009
3007
|
column,
|
|
@@ -5392,15 +5390,19 @@ var BackgroundTasksPG = class BackgroundTasksPG extends _mastra_core_storage.Bac
|
|
|
5392
5390
|
where += ` AND "status" = $${paramIdx++}`;
|
|
5393
5391
|
params.push(options.expectedStatus);
|
|
5394
5392
|
}
|
|
5395
|
-
if (options?.expectedOwnerId !== void 0)
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5393
|
+
if (options?.expectedOwnerId !== void 0) {
|
|
5394
|
+
if (options.expectedOwnerId === null) where += ` AND "ownerId" IS NULL`;
|
|
5395
|
+
else {
|
|
5396
|
+
where += ` AND "ownerId" = $${paramIdx++}`;
|
|
5397
|
+
params.push(options.expectedOwnerId);
|
|
5398
|
+
}
|
|
5399
5399
|
}
|
|
5400
|
-
if (options?.expectedLeaseExpiresAt !== void 0)
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5400
|
+
if (options?.expectedLeaseExpiresAt !== void 0) {
|
|
5401
|
+
if (options.expectedLeaseExpiresAt === null) where += ` AND "leaseExpiresAtZ" IS NULL`;
|
|
5402
|
+
else {
|
|
5403
|
+
where += ` AND "leaseExpiresAtZ" = $${paramIdx++}`;
|
|
5404
|
+
params.push(options.expectedLeaseExpiresAt.toISOString());
|
|
5405
|
+
}
|
|
5404
5406
|
}
|
|
5405
5407
|
return ((await this.#db.client.query(`UPDATE ${table} SET ${setClauses.join(", ")} WHERE ${where}`, params)).rowCount ?? 0) > 0;
|
|
5406
5408
|
}
|
|
@@ -5698,9 +5700,10 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
|
|
|
5698
5700
|
await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_CHANNEL_CONFIG });
|
|
5699
5701
|
}
|
|
5700
5702
|
async saveInstallation(installation) {
|
|
5703
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5701
5704
|
const tableName = getTableName$5({
|
|
5702
5705
|
indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
|
|
5703
|
-
schemaName
|
|
5706
|
+
schemaName
|
|
5704
5707
|
});
|
|
5705
5708
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
5706
5709
|
const createdAt = installation.createdAt?.toISOString() ?? now;
|
|
@@ -5731,47 +5734,53 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
|
|
|
5731
5734
|
]);
|
|
5732
5735
|
}
|
|
5733
5736
|
async getInstallation(id) {
|
|
5737
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5734
5738
|
const tableName = getTableName$5({
|
|
5735
5739
|
indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
|
|
5736
|
-
schemaName
|
|
5740
|
+
schemaName
|
|
5737
5741
|
});
|
|
5738
5742
|
const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "id" = $1`, [id]);
|
|
5739
5743
|
return row ? this.#parseInstallationRow(row) : null;
|
|
5740
5744
|
}
|
|
5741
5745
|
async getInstallationByAgent(platform, agentId) {
|
|
5746
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5742
5747
|
const tableName = getTableName$5({
|
|
5743
5748
|
indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
|
|
5744
|
-
schemaName
|
|
5749
|
+
schemaName
|
|
5745
5750
|
});
|
|
5746
5751
|
const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1 AND "agentId" = $2 ORDER BY CASE "status" WHEN 'active' THEN 0 WHEN 'pending' THEN 1 ELSE 2 END, "updatedAt" DESC LIMIT 1`, [platform, agentId]);
|
|
5747
5752
|
return row ? this.#parseInstallationRow(row) : null;
|
|
5748
5753
|
}
|
|
5749
5754
|
async getInstallationByWebhookId(webhookId) {
|
|
5755
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5750
5756
|
const tableName = getTableName$5({
|
|
5751
5757
|
indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
|
|
5752
|
-
schemaName
|
|
5758
|
+
schemaName
|
|
5753
5759
|
});
|
|
5754
5760
|
const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "webhookId" = $1`, [webhookId]);
|
|
5755
5761
|
return row ? this.#parseInstallationRow(row) : null;
|
|
5756
5762
|
}
|
|
5757
5763
|
async listInstallations(platform) {
|
|
5764
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5758
5765
|
const tableName = getTableName$5({
|
|
5759
5766
|
indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
|
|
5760
|
-
schemaName
|
|
5767
|
+
schemaName
|
|
5761
5768
|
});
|
|
5762
5769
|
return (await this.#db.readClient.manyOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1 ORDER BY "createdAt" DESC`, [platform])).map((row) => this.#parseInstallationRow(row));
|
|
5763
5770
|
}
|
|
5764
5771
|
async deleteInstallation(id) {
|
|
5772
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5765
5773
|
const tableName = getTableName$5({
|
|
5766
5774
|
indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
|
|
5767
|
-
schemaName
|
|
5775
|
+
schemaName
|
|
5768
5776
|
});
|
|
5769
5777
|
await this.#db.client.none(`DELETE FROM ${tableName} WHERE "id" = $1`, [id]);
|
|
5770
5778
|
}
|
|
5771
5779
|
async saveConfig(config) {
|
|
5780
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5772
5781
|
const tableName = getTableName$5({
|
|
5773
5782
|
indexName: _mastra_core_storage.TABLE_CHANNEL_CONFIG,
|
|
5774
|
-
schemaName
|
|
5783
|
+
schemaName
|
|
5775
5784
|
});
|
|
5776
5785
|
const now = config.updatedAt.toISOString();
|
|
5777
5786
|
await this.#db.client.none(`INSERT INTO ${tableName} ("platform", "data", "updatedAt", "updatedAtZ")
|
|
@@ -5787,9 +5796,10 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
|
|
|
5787
5796
|
]);
|
|
5788
5797
|
}
|
|
5789
5798
|
async getConfig(platform) {
|
|
5799
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5790
5800
|
const tableName = getTableName$5({
|
|
5791
5801
|
indexName: _mastra_core_storage.TABLE_CHANNEL_CONFIG,
|
|
5792
|
-
schemaName
|
|
5802
|
+
schemaName
|
|
5793
5803
|
});
|
|
5794
5804
|
const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1`, [platform]);
|
|
5795
5805
|
if (!row) return null;
|
|
@@ -5800,9 +5810,10 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
|
|
|
5800
5810
|
};
|
|
5801
5811
|
}
|
|
5802
5812
|
async deleteConfig(platform) {
|
|
5813
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5803
5814
|
const tableName = getTableName$5({
|
|
5804
5815
|
indexName: _mastra_core_storage.TABLE_CHANNEL_CONFIG,
|
|
5805
|
-
schemaName
|
|
5816
|
+
schemaName
|
|
5806
5817
|
});
|
|
5807
5818
|
await this.#db.client.none(`DELETE FROM ${tableName} WHERE "platform" = $1`, [platform]);
|
|
5808
5819
|
}
|
|
@@ -11720,10 +11731,11 @@ const DB_NOW_MS = `(EXTRACT(EPOCH FROM clock_timestamp()) * 1000)::bigint`;
|
|
|
11720
11731
|
*/
|
|
11721
11732
|
async function assertRunFence(t, claimsTable, fence, operation) {
|
|
11722
11733
|
const row = await t.oneOrNone(`SELECT generation, "ownerId" FROM ${claimsTable} WHERE "runId" = $1 FOR SHARE`, [fence.runId]);
|
|
11723
|
-
|
|
11734
|
+
const current = row && {
|
|
11724
11735
|
generation: Number(row.generation),
|
|
11725
11736
|
ownerId: row.ownerId
|
|
11726
|
-
}
|
|
11737
|
+
};
|
|
11738
|
+
if (!(0, _mastra_core_storage.matchesRunFence)(current, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
|
|
11727
11739
|
}
|
|
11728
11740
|
/**
|
|
11729
11741
|
* Runs `write` directly when it carries no fence, or in a transaction behind
|
|
@@ -14850,9 +14862,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
|
|
|
14850
14862
|
async updateNotificationRow(threadId, id, data) {
|
|
14851
14863
|
const entries = Object.entries(data).filter(([, value]) => value !== void 0);
|
|
14852
14864
|
if (entries.length === 0) return;
|
|
14865
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
14853
14866
|
const tableName = getTableName$5({
|
|
14854
14867
|
indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
|
|
14855
|
-
schemaName
|
|
14868
|
+
schemaName
|
|
14856
14869
|
});
|
|
14857
14870
|
const setColumns = entries.map(([key], index) => `"${(0, _mastra_core_utils.parseSqlIdentifier)(key, "column name")}" = $${index + 1}`);
|
|
14858
14871
|
const values = entries.map(([key, value]) => {
|
|
@@ -14951,9 +14964,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
|
|
|
14951
14964
|
}
|
|
14952
14965
|
const limit = input.limit ? ` LIMIT $${args.length + 1}` : "";
|
|
14953
14966
|
if (input.limit) args.push(input.limit);
|
|
14967
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
14954
14968
|
const tableName = getTableName$5({
|
|
14955
14969
|
indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
|
|
14956
|
-
schemaName
|
|
14970
|
+
schemaName
|
|
14957
14971
|
});
|
|
14958
14972
|
return (await this.#db.readClient.manyOrNone(`SELECT * FROM ${tableName} WHERE ${conditions.join(" AND ")} ORDER BY "updatedAt" DESC${limit}`, args)).map((row) => rowToNotification(row));
|
|
14959
14973
|
}
|
|
@@ -14974,9 +14988,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
|
|
|
14974
14988
|
}
|
|
14975
14989
|
const limit = input.limit ? ` LIMIT $${args.length + 1}` : "";
|
|
14976
14990
|
if (input.limit) args.push(input.limit);
|
|
14991
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
14977
14992
|
const tableName = getTableName$5({
|
|
14978
14993
|
indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
|
|
14979
|
-
schemaName
|
|
14994
|
+
schemaName
|
|
14980
14995
|
});
|
|
14981
14996
|
return (await this.#db.readClient.manyOrNone(`SELECT * FROM ${tableName} WHERE ${conditions.join(" AND ")} ORDER BY CASE WHEN "deliverAt" IS NULL THEN "summaryAt" WHEN "summaryAt" IS NULL THEN "deliverAt" WHEN "deliverAt" <= "summaryAt" THEN "deliverAt" ELSE "summaryAt" END ASC, "updatedAt" ASC${limit}`, args)).map((row) => rowToNotification(row));
|
|
14982
14997
|
}
|
|
@@ -14988,9 +15003,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
|
|
|
14988
15003
|
* lagging read replica cannot yield stale or missing rows mid-update.
|
|
14989
15004
|
*/
|
|
14990
15005
|
async #getNotification(client, input) {
|
|
15006
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
14991
15007
|
const tableName = getTableName$5({
|
|
14992
15008
|
indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
|
|
14993
|
-
schemaName
|
|
15009
|
+
schemaName
|
|
14994
15010
|
});
|
|
14995
15011
|
const row = await client.oneOrNone(`SELECT * FROM ${tableName} WHERE "threadId" = $1 AND "id" = $2 LIMIT 1`, [input.threadId, input.id]);
|
|
14996
15012
|
return row ? rowToNotification(row) : null;
|
|
@@ -15038,9 +15054,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
|
|
|
15038
15054
|
};
|
|
15039
15055
|
const columns = Object.keys(assignments);
|
|
15040
15056
|
const setClause = columns.map((column, index) => `"${(0, _mastra_core_utils.parseSqlIdentifier)(column, "column name")}" = $${index + 1}`).join(", ");
|
|
15057
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
15041
15058
|
const tableName = getTableName$5({
|
|
15042
15059
|
indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
|
|
15043
|
-
schemaName
|
|
15060
|
+
schemaName
|
|
15044
15061
|
});
|
|
15045
15062
|
return (await this.#db.client.manyOrNone(`UPDATE ${tableName} SET ${setClause} WHERE "threadId" = $${columns.length + 1} AND "id" = ANY($${columns.length + 2}::text[]) RETURNING *`, [
|
|
15046
15063
|
...Object.values(assignments),
|
|
@@ -15050,9 +15067,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
|
|
|
15050
15067
|
}
|
|
15051
15068
|
async findCoalescable(input) {
|
|
15052
15069
|
if (!input.dedupeKey && !input.coalesceKey) return void 0;
|
|
15070
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
15053
15071
|
const tableName = getTableName$5({
|
|
15054
15072
|
indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
|
|
15055
|
-
schemaName
|
|
15073
|
+
schemaName
|
|
15056
15074
|
});
|
|
15057
15075
|
const row = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE "threadId" = $1 AND "source" = $2 AND "kind" = $3 AND "status" = $4 AND (("agentId" = $5::text) OR ("agentId" IS NULL AND $5::text IS NULL)) AND (("resourceId" = $6::text) OR ("resourceId" IS NULL AND $6::text IS NULL)) AND (($7::text IS NOT NULL AND "dedupeKey" = $7::text) OR ($8::text IS NOT NULL AND "coalesceKey" = $8::text)) ORDER BY "updatedAt" DESC LIMIT 1`, [
|
|
15058
15076
|
input.threadId,
|
|
@@ -15594,18 +15612,18 @@ var ObservabilityPG = class ObservabilityPG extends _mastra_core_storage.Observa
|
|
|
15594
15612
|
case _mastra_core_storage.TraceStatus.RUNNING:
|
|
15595
15613
|
conditions.push(`r."endedAtZ" IS NULL AND r."error" IS NULL`);
|
|
15596
15614
|
break;
|
|
15597
|
-
case _mastra_core_storage.TraceStatus.SUCCESS:
|
|
15598
|
-
conditions.push(`r."endedAtZ" IS NOT NULL AND r."error" IS NULL`);
|
|
15599
|
-
break;
|
|
15615
|
+
case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`r."endedAtZ" IS NOT NULL AND r."error" IS NULL`);
|
|
15600
15616
|
}
|
|
15601
|
-
if (filters.hasChildError !== void 0)
|
|
15617
|
+
if (filters.hasChildError !== void 0) {
|
|
15618
|
+
if (filters.hasChildError) conditions.push(`EXISTS (
|
|
15602
15619
|
SELECT 1 FROM ${tableName} c
|
|
15603
15620
|
WHERE c."traceId" = r."traceId" AND c."error" IS NOT NULL
|
|
15604
15621
|
)`);
|
|
15605
|
-
|
|
15622
|
+
else conditions.push(`NOT EXISTS (
|
|
15606
15623
|
SELECT 1 FROM ${tableName} c
|
|
15607
15624
|
WHERE c."traceId" = r."traceId" AND c."error" IS NOT NULL
|
|
15608
15625
|
)`);
|
|
15626
|
+
}
|
|
15609
15627
|
}
|
|
15610
15628
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
15611
15629
|
const orderField = orderBy?.field ?? "startedAt";
|
|
@@ -16785,9 +16803,6 @@ function additiveColumns(schema) {
|
|
|
16785
16803
|
}
|
|
16786
16804
|
];
|
|
16787
16805
|
}
|
|
16788
|
-
/** Existence probe for an additive column. Params: schema, table, column. */
|
|
16789
|
-
const columnExistsSQL = `SELECT 1 FROM information_schema.columns
|
|
16790
|
-
WHERE table_schema = $1 AND table_name = $2 AND column_name = $3`;
|
|
16791
16806
|
/** Index CREATEs. Safe to run repeatedly. */
|
|
16792
16807
|
function allIndexDDL(schema) {
|
|
16793
16808
|
return tableIndexes().map((spec) => indexDDL(schema, spec));
|
|
@@ -16795,7 +16810,7 @@ function allIndexDDL(schema) {
|
|
|
16795
16810
|
//#endregion
|
|
16796
16811
|
//#region src/storage/domains/observability/v-next/discovery.ts
|
|
16797
16812
|
const DEFAULT_TTL_SECONDS = 300;
|
|
16798
|
-
const DEFAULT_LOOKBACK_SECONDS =
|
|
16813
|
+
const DEFAULT_LOOKBACK_SECONDS = 2592e3;
|
|
16799
16814
|
/** All signal tables that contain a column. Used by cross-signal discovery. */
|
|
16800
16815
|
const SIGNAL_TABLES_WITH_CONTEXT = [
|
|
16801
16816
|
TABLE_SPAN_EVENTS,
|
|
@@ -18040,7 +18055,7 @@ function shiftRange(range, period) {
|
|
|
18040
18055
|
offset = 864e5;
|
|
18041
18056
|
break;
|
|
18042
18057
|
case "previous_week":
|
|
18043
|
-
offset =
|
|
18058
|
+
offset = 6048e5;
|
|
18044
18059
|
break;
|
|
18045
18060
|
default: offset = duration;
|
|
18046
18061
|
}
|
|
@@ -18160,12 +18175,14 @@ function pushFeedbackIdentity(acc, feedbackType, feedbackSource) {
|
|
|
18160
18175
|
acc.conditions.push(`"valueNumber" IS NOT NULL`);
|
|
18161
18176
|
}
|
|
18162
18177
|
async function createFeedback(client, schema, args) {
|
|
18163
|
-
const
|
|
18178
|
+
const row = feedbackRecordToRow(args.feedback);
|
|
18179
|
+
const insert = buildInsert(schema, TABLE_FEEDBACK_EVENTS, [row], FEEDBACK_UPSERT_CLAUSE);
|
|
18164
18180
|
if (insert) await client.query(insert.text, insert.values);
|
|
18165
18181
|
}
|
|
18166
18182
|
async function batchCreateFeedback(client, schema, args) {
|
|
18167
18183
|
if (args.feedbacks.length === 0) return;
|
|
18168
|
-
const
|
|
18184
|
+
const rows = [...new Map(args.feedbacks.map((feedback) => [feedback.feedbackId, feedback])).values()].map(feedbackRecordToRow);
|
|
18185
|
+
const insert = buildInsert(schema, TABLE_FEEDBACK_EVENTS, rows, FEEDBACK_UPSERT_CLAUSE);
|
|
18169
18186
|
if (insert) await client.query(insert.text, insert.values);
|
|
18170
18187
|
}
|
|
18171
18188
|
async function updateFeedbackReviewStatus(client, schema, args) {
|
|
@@ -18367,7 +18384,8 @@ function applyLogFilters(acc, filters) {
|
|
|
18367
18384
|
}
|
|
18368
18385
|
async function batchCreateLogs(client, schema, args) {
|
|
18369
18386
|
if (args.logs.length === 0) return;
|
|
18370
|
-
const
|
|
18387
|
+
const rows = args.logs.map(logRecordToRow);
|
|
18388
|
+
const insert = buildInsert(schema, TABLE_LOG_EVENTS, rows);
|
|
18371
18389
|
if (insert) await client.query(insert.text, insert.values);
|
|
18372
18390
|
}
|
|
18373
18391
|
async function listLogs(client, schema, args) {
|
|
@@ -18442,7 +18460,8 @@ function pushMetricNameFilter(acc, names) {
|
|
|
18442
18460
|
}
|
|
18443
18461
|
async function batchCreateMetrics(client, schema, args) {
|
|
18444
18462
|
if (args.metrics.length === 0) return;
|
|
18445
|
-
const
|
|
18463
|
+
const rows = args.metrics.map(metricRecordToRow);
|
|
18464
|
+
const insert = buildInsert(schema, TABLE_METRIC_EVENTS, rows);
|
|
18446
18465
|
if (insert) await client.query(insert.text, insert.values);
|
|
18447
18466
|
}
|
|
18448
18467
|
async function listMetrics(client, schema, args) {
|
|
@@ -19246,6 +19265,7 @@ const TRACE_FIELDS = {
|
|
|
19246
19265
|
endedAt: "r.\"endedAt\"",
|
|
19247
19266
|
durationMs: durationMsSql("r.\"startedAt\"", "r.\"endedAt\""),
|
|
19248
19267
|
timeToFirstChunkMs: "r.\"timeToFirstChunkMs\"",
|
|
19268
|
+
entityId: "r.\"entityId\"",
|
|
19249
19269
|
entityName: "r.\"entityName\"",
|
|
19250
19270
|
entityType: "r.\"entityType\"",
|
|
19251
19271
|
name: "r.\"name\"",
|
|
@@ -19547,6 +19567,7 @@ const ROOT_PUSHDOWN_FIELDS = /* @__PURE__ */ new Set([
|
|
|
19547
19567
|
"organizationId",
|
|
19548
19568
|
"startedAt",
|
|
19549
19569
|
"endedAt",
|
|
19570
|
+
"entityId",
|
|
19550
19571
|
"entityName",
|
|
19551
19572
|
"entityType",
|
|
19552
19573
|
"name",
|
|
@@ -20417,7 +20438,7 @@ function predicateFields(predicate, fields = /* @__PURE__ */ new Set()) {
|
|
|
20417
20438
|
return fields;
|
|
20418
20439
|
}
|
|
20419
20440
|
function canUseThreadCandidates(probe) {
|
|
20420
|
-
return Number(probe.threadCount) <= 16384 && Number(probe.traceCount) <= 1e5 && Number(probe.threadBytes) + Number(probe.traceBytes) <=
|
|
20441
|
+
return Number(probe.threadCount) <= 16384 && Number(probe.traceCount) <= 1e5 && Number(probe.threadBytes) + Number(probe.traceBytes) <= 4194304;
|
|
20421
20442
|
}
|
|
20422
20443
|
function compilePostgresThreadRowsQuery(schema, plan, strategy = "full") {
|
|
20423
20444
|
const values = [plan.timeRange.from, plan.timeRange.to];
|
|
@@ -20632,6 +20653,7 @@ const DIMENSION_SQL = {
|
|
|
20632
20653
|
entityName: "r.\"entityName\"",
|
|
20633
20654
|
name: "r.\"name\"",
|
|
20634
20655
|
spanType: "r.\"spanType\"",
|
|
20656
|
+
entityId: "r.\"entityId\"",
|
|
20635
20657
|
environment: "r.\"environment\"",
|
|
20636
20658
|
status: TRACE_STATUS_SQL,
|
|
20637
20659
|
serviceName: "r.\"serviceName\"",
|
|
@@ -21059,9 +21081,7 @@ function buildListTracesFilters(filters, spanTable, nextParamIdx) {
|
|
|
21059
21081
|
case _mastra_core_storage.TraceStatus.RUNNING:
|
|
21060
21082
|
conditions.push(`r."isPending"`);
|
|
21061
21083
|
break;
|
|
21062
|
-
case _mastra_core_storage.TraceStatus.SUCCESS:
|
|
21063
|
-
conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
|
|
21064
|
-
break;
|
|
21084
|
+
case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
|
|
21065
21085
|
}
|
|
21066
21086
|
if (filters.hasChildError !== void 0) {
|
|
21067
21087
|
const sub = `EXISTS (
|
|
@@ -21397,9 +21417,7 @@ function buildListBranchesFilters(filters, spanType, spanTable, nextParamIdx) {
|
|
|
21397
21417
|
case _mastra_core_storage.TraceStatus.RUNNING:
|
|
21398
21418
|
conditions.push(`r."isPending"`);
|
|
21399
21419
|
break;
|
|
21400
|
-
case _mastra_core_storage.TraceStatus.SUCCESS:
|
|
21401
|
-
conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
|
|
21402
|
-
break;
|
|
21420
|
+
case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
|
|
21403
21421
|
}
|
|
21404
21422
|
return {
|
|
21405
21423
|
conditions,
|
|
@@ -21740,7 +21758,7 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
21740
21758
|
} catch (error) {
|
|
21741
21759
|
if (!isDuplicateRelationError(error)) throw error;
|
|
21742
21760
|
}
|
|
21743
|
-
for (const { table, column, ddl } of additiveColumns(this.#schema)) if (!await this.#client.oneOrNone(
|
|
21761
|
+
for (const { table, column, ddl } of additiveColumns(this.#schema)) if (!await this.#client.oneOrNone("SELECT 1 FROM information_schema.columns\n WHERE table_schema = $1 AND table_name = $2 AND column_name = $3", [
|
|
21744
21762
|
this.#schema,
|
|
21745
21763
|
table,
|
|
21746
21764
|
column
|
|
@@ -21866,7 +21884,8 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
21866
21884
|
"feedback",
|
|
21867
21885
|
"trace-query-context-ids",
|
|
21868
21886
|
...timeToFirstChunkFeatures,
|
|
21869
|
-
"trace-query-root-span-fields"
|
|
21887
|
+
"trace-query-root-span-fields",
|
|
21888
|
+
"trace-query-root-entity-id"
|
|
21870
21889
|
];
|
|
21871
21890
|
return [
|
|
21872
21891
|
"metrics",
|
|
@@ -21889,7 +21908,8 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
21889
21908
|
"feedback",
|
|
21890
21909
|
"trace-query-context-ids",
|
|
21891
21910
|
...timeToFirstChunkFeatures,
|
|
21892
|
-
"trace-query-root-span-fields"
|
|
21911
|
+
"trace-query-root-span-fields",
|
|
21912
|
+
"trace-query-root-entity-id"
|
|
21893
21913
|
];
|
|
21894
21914
|
}
|
|
21895
21915
|
async #run(op, fn, details) {
|
|
@@ -22906,15 +22926,19 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
|
|
|
22906
22926
|
params.push(filter.workflowId);
|
|
22907
22927
|
conditions.push(`target->>'workflowId' = $${params.length}`);
|
|
22908
22928
|
}
|
|
22909
|
-
if (filter?.ownerType !== void 0)
|
|
22910
|
-
|
|
22911
|
-
|
|
22912
|
-
|
|
22929
|
+
if (filter?.ownerType !== void 0) {
|
|
22930
|
+
if (filter.ownerType === null) conditions.push("owner_type IS NULL");
|
|
22931
|
+
else {
|
|
22932
|
+
params.push(filter.ownerType);
|
|
22933
|
+
conditions.push(`owner_type = $${params.length}`);
|
|
22934
|
+
}
|
|
22913
22935
|
}
|
|
22914
|
-
if (filter?.ownerId !== void 0)
|
|
22915
|
-
|
|
22916
|
-
|
|
22917
|
-
|
|
22936
|
+
if (filter?.ownerId !== void 0) {
|
|
22937
|
+
if (filter.ownerId === null) conditions.push("owner_id IS NULL");
|
|
22938
|
+
else {
|
|
22939
|
+
params.push(filter.ownerId);
|
|
22940
|
+
conditions.push(`owner_id = $${params.length}`);
|
|
22941
|
+
}
|
|
22918
22942
|
}
|
|
22919
22943
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
22920
22944
|
return (await this.#readClient.manyOrNone(`SELECT * FROM ${this.#table(_mastra_core_storage.TABLE_SCHEDULES)} ${where} ORDER BY created_at ASC`, params)).map(rowToSchedule);
|
|
@@ -26024,16 +26048,20 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
|
|
|
26024
26048
|
values.push(status);
|
|
26025
26049
|
paramIndex++;
|
|
26026
26050
|
}
|
|
26027
|
-
if (resourceId)
|
|
26028
|
-
|
|
26029
|
-
|
|
26030
|
-
|
|
26031
|
-
|
|
26032
|
-
|
|
26033
|
-
|
|
26034
|
-
|
|
26035
|
-
|
|
26036
|
-
|
|
26051
|
+
if (resourceId) {
|
|
26052
|
+
if (await this.#db.hasColumn(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
|
|
26053
|
+
conditions.push(`"resourceId" = $${paramIndex}`);
|
|
26054
|
+
values.push(resourceId);
|
|
26055
|
+
paramIndex++;
|
|
26056
|
+
} else this.logger?.warn?.(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
|
|
26057
|
+
}
|
|
26058
|
+
if (threadId) {
|
|
26059
|
+
if (await this.#db.getColumnType(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "snapshot") === "jsonb") {
|
|
26060
|
+
conditions.push(`${WORKFLOW_SNAPSHOT_THREAD_ID_EXPR} = $${paramIndex}`);
|
|
26061
|
+
values.push(threadId);
|
|
26062
|
+
paramIndex++;
|
|
26063
|
+
} else this.logger?.warn?.(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] snapshot column is not jsonb. Skipping threadId filter.`);
|
|
26064
|
+
}
|
|
26037
26065
|
if (fromDate) {
|
|
26038
26066
|
conditions.push(`"createdAt" >= $${paramIndex}`);
|
|
26039
26067
|
values.push(fromDate);
|