@mastra/pg 1.0.0-beta.12 → 1.0.0-beta.13
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/CHANGELOG.md +127 -0
- package/dist/docs/README.md +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/SOURCE_MAP.json +1 -1
- package/dist/docs/memory/01-storage.md +59 -25
- package/dist/docs/memory/02-working-memory.md +10 -6
- package/dist/docs/memory/03-semantic-recall.md +2 -4
- package/dist/docs/memory/04-reference.md +2 -4
- package/dist/docs/processors/01-reference.md +2 -0
- package/dist/docs/rag/02-vector-databases.md +10 -5
- package/dist/docs/rag/03-retrieval.md +5 -6
- package/dist/docs/rag/04-reference.md +18 -0
- package/dist/docs/storage/01-reference.md +176 -15
- package/dist/index.cjs +34 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -23
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +1 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/test-utils.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2078,7 +2078,7 @@ var PgDB = class extends MastraBase {
|
|
|
2078
2078
|
SELECT 1 FROM information_schema.tables
|
|
2079
2079
|
WHERE table_schema = $1 AND table_name = $2
|
|
2080
2080
|
)`,
|
|
2081
|
-
[this.schemaName || "
|
|
2081
|
+
[this.schemaName || "public", tableName]
|
|
2082
2082
|
);
|
|
2083
2083
|
if (tableExists?.exists) {
|
|
2084
2084
|
await this.client.none(`TRUNCATE TABLE ${tableNameWithSchema} CASCADE`);
|
|
@@ -4733,6 +4733,11 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
|
|
|
4733
4733
|
}
|
|
4734
4734
|
async init() {
|
|
4735
4735
|
await this.#db.createTable({ tableName: TABLE_SCORERS, schema: TABLE_SCHEMAS[TABLE_SCORERS] });
|
|
4736
|
+
await this.#db.alterTable({
|
|
4737
|
+
tableName: TABLE_SCORERS,
|
|
4738
|
+
schema: TABLE_SCHEMAS[TABLE_SCORERS],
|
|
4739
|
+
ifNotExists: ["spanId", "requestContext"]
|
|
4740
|
+
});
|
|
4736
4741
|
await this.createDefaultIndexes();
|
|
4737
4742
|
await this.createCustomIndexes();
|
|
4738
4743
|
}
|
|
@@ -5084,23 +5089,8 @@ function getTableName5({ indexName, schemaName }) {
|
|
|
5084
5089
|
const quotedIndexName = `"${indexName}"`;
|
|
5085
5090
|
return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
|
|
5086
5091
|
}
|
|
5087
|
-
function
|
|
5088
|
-
|
|
5089
|
-
if (typeof parsedSnapshot === "string") {
|
|
5090
|
-
try {
|
|
5091
|
-
parsedSnapshot = JSON.parse(row.snapshot);
|
|
5092
|
-
} catch (e) {
|
|
5093
|
-
console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
|
|
5094
|
-
}
|
|
5095
|
-
}
|
|
5096
|
-
return {
|
|
5097
|
-
workflowName: row.workflow_name,
|
|
5098
|
-
runId: row.run_id,
|
|
5099
|
-
snapshot: parsedSnapshot,
|
|
5100
|
-
resourceId: row.resourceId,
|
|
5101
|
-
createdAt: new Date(row.createdAtZ || row.createdAt),
|
|
5102
|
-
updatedAt: new Date(row.updatedAtZ || row.updatedAt)
|
|
5103
|
-
};
|
|
5092
|
+
function sanitizeJsonForPg(jsonString) {
|
|
5093
|
+
return jsonString.replace(/\\u(0000|[Dd][89A-Fa-f][0-9A-Fa-f]{2})/g, "");
|
|
5104
5094
|
}
|
|
5105
5095
|
var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
5106
5096
|
#db;
|
|
@@ -5117,6 +5107,24 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
5117
5107
|
this.#skipDefaultIndexes = skipDefaultIndexes;
|
|
5118
5108
|
this.#indexes = indexes?.filter((idx) => _WorkflowsPG.MANAGED_TABLES.includes(idx.table));
|
|
5119
5109
|
}
|
|
5110
|
+
parseWorkflowRun(row) {
|
|
5111
|
+
let parsedSnapshot = row.snapshot;
|
|
5112
|
+
if (typeof parsedSnapshot === "string") {
|
|
5113
|
+
try {
|
|
5114
|
+
parsedSnapshot = JSON.parse(row.snapshot);
|
|
5115
|
+
} catch (e) {
|
|
5116
|
+
this.logger.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
|
|
5117
|
+
}
|
|
5118
|
+
}
|
|
5119
|
+
return {
|
|
5120
|
+
workflowName: row.workflow_name,
|
|
5121
|
+
runId: row.run_id,
|
|
5122
|
+
snapshot: parsedSnapshot,
|
|
5123
|
+
resourceId: row.resourceId,
|
|
5124
|
+
createdAt: new Date(row.createdAtZ || row.createdAt),
|
|
5125
|
+
updatedAt: new Date(row.updatedAtZ || row.updatedAt)
|
|
5126
|
+
};
|
|
5127
|
+
}
|
|
5120
5128
|
/**
|
|
5121
5129
|
* Returns default index definitions for the workflows domain tables.
|
|
5122
5130
|
* Currently no default indexes are defined for workflows.
|
|
@@ -5189,12 +5197,13 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
5189
5197
|
const now = /* @__PURE__ */ new Date();
|
|
5190
5198
|
const createdAtValue = createdAt ? createdAt : now;
|
|
5191
5199
|
const updatedAtValue = updatedAt ? updatedAt : now;
|
|
5200
|
+
const sanitizedSnapshot = sanitizeJsonForPg(JSON.stringify(snapshot));
|
|
5192
5201
|
await this.#db.client.none(
|
|
5193
5202
|
`INSERT INTO ${getTableName5({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
|
|
5194
5203
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
5195
5204
|
ON CONFLICT (workflow_name, run_id) DO UPDATE
|
|
5196
5205
|
SET "resourceId" = $3, snapshot = $4, "updatedAt" = $6`,
|
|
5197
|
-
[workflowName, runId, resourceId,
|
|
5206
|
+
[workflowName, runId, resourceId, sanitizedSnapshot, createdAtValue, updatedAtValue]
|
|
5198
5207
|
);
|
|
5199
5208
|
} catch (error) {
|
|
5200
5209
|
throw new MastraError(
|
|
@@ -5257,7 +5266,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
5257
5266
|
if (!result) {
|
|
5258
5267
|
return null;
|
|
5259
5268
|
}
|
|
5260
|
-
return parseWorkflowRun(result);
|
|
5269
|
+
return this.parseWorkflowRun(result);
|
|
5261
5270
|
} catch (error) {
|
|
5262
5271
|
throw new MastraError(
|
|
5263
5272
|
{
|
|
@@ -5313,7 +5322,9 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
5313
5322
|
paramIndex++;
|
|
5314
5323
|
}
|
|
5315
5324
|
if (status) {
|
|
5316
|
-
conditions.push(
|
|
5325
|
+
conditions.push(
|
|
5326
|
+
`regexp_replace(snapshot::text, '\\\\u(0000|[Dd][89A-Fa-f][0-9A-Fa-f]{2})', '', 'g')::jsonb ->> 'status' = $${paramIndex}`
|
|
5327
|
+
);
|
|
5317
5328
|
values.push(status);
|
|
5318
5329
|
paramIndex++;
|
|
5319
5330
|
}
|
|
@@ -5358,7 +5369,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
5358
5369
|
const queryValues = usePagination ? [...values, normalizedPerPage, offset] : values;
|
|
5359
5370
|
const result = await this.#db.client.manyOrNone(query, queryValues);
|
|
5360
5371
|
const runs = (result || []).map((row) => {
|
|
5361
|
-
return parseWorkflowRun(row);
|
|
5372
|
+
return this.parseWorkflowRun(row);
|
|
5362
5373
|
});
|
|
5363
5374
|
return { runs, total: total || runs.length };
|
|
5364
5375
|
} catch (error) {
|
|
@@ -5391,7 +5402,7 @@ var PostgresStore = class extends MastraStorage {
|
|
|
5391
5402
|
try {
|
|
5392
5403
|
validateConfig("PostgresStore", config);
|
|
5393
5404
|
super({ id: config.id, name: "PostgresStore", disableInit: config.disableInit });
|
|
5394
|
-
this.schema = config.schemaName || "public";
|
|
5405
|
+
this.schema = parseSqlIdentifier(config.schemaName || "public", "schema name");
|
|
5395
5406
|
if (isPoolConfig(config)) {
|
|
5396
5407
|
this.#pool = config.pool;
|
|
5397
5408
|
this.#ownsPool = false;
|