@mastra/pg 1.7.0 → 1.7.1-alpha.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/CHANGELOG.md +13 -0
- package/LICENSE.md +15 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +191 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +191 -21
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +1 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +3 -2
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 1.7.1-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added atomic `updateWorkflowResults` and `updateWorkflowState` to safely merge concurrent step results into workflow snapshots. ([#12575](https://github.com/mastra-ai/mastra/pull/12575))
|
|
8
|
+
|
|
9
|
+
- Added `insertObservationalMemoryRecord()` to PostgreSQL, LibSQL, MongoDB, and Upstash adapters for OM cloning support. ([#13569](https://github.com/mastra-ai/mastra/pull/13569))
|
|
10
|
+
|
|
11
|
+
- Eliminate pg client deprecation warnings on startup by running index metadata queries sequentially ([#13659](https://github.com/mastra-ai/mastra/pull/13659))
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`504fc8b`](https://github.com/mastra-ai/mastra/commit/504fc8b9d0ddab717577ad3bf9c95ea4bd5377bd), [`f9c150b`](https://github.com/mastra-ai/mastra/commit/f9c150b7595ad05ad9cc9a11098e2944361e8c22), [`88de7e8`](https://github.com/mastra-ai/mastra/commit/88de7e8dfe4b7e1951a9e441bb33136e705ce24e), [`edee4b3`](https://github.com/mastra-ai/mastra/commit/edee4b37dff0af515fc7cc0e8d71ee39e6a762f0), [`3790c75`](https://github.com/mastra-ai/mastra/commit/3790c7578cc6a47d854eb12d89e6b1912867fe29), [`e7a235b`](https://github.com/mastra-ai/mastra/commit/e7a235be6472e0c870ed6c791ddb17c492dc188b), [`d51d298`](https://github.com/mastra-ai/mastra/commit/d51d298953967aab1f58ec965b644d109214f085), [`6dbeeb9`](https://github.com/mastra-ai/mastra/commit/6dbeeb94a8b1eebb727300d1a98961f882180794), [`d5f0d8d`](https://github.com/mastra-ai/mastra/commit/d5f0d8d6a03e515ddaa9b5da19b7e44b8357b07b), [`09c3b18`](https://github.com/mastra-ai/mastra/commit/09c3b1802ff14e243a8a8baea327440bc8cc2e32), [`b896379`](https://github.com/mastra-ai/mastra/commit/b8963791c6afa79484645fcec596a201f936b9a2), [`85c84eb`](https://github.com/mastra-ai/mastra/commit/85c84ebb78aebfcba9d209c8e152b16d7a00cb71), [`a89272a`](https://github.com/mastra-ai/mastra/commit/a89272a5d71939b9fcd284e6a6dc1dd091a6bdcf), [`ee9c8df`](https://github.com/mastra-ai/mastra/commit/ee9c8df644f19d055af5f496bf4942705f5a47b7), [`77b4a25`](https://github.com/mastra-ai/mastra/commit/77b4a254e51907f8ff3a3ba95596a18e93ae4b35), [`276246e`](https://github.com/mastra-ai/mastra/commit/276246e0b9066a1ea48bbc70df84dbe528daaf99), [`08ecfdb`](https://github.com/mastra-ai/mastra/commit/08ecfdbdad6fb8285deef86a034bdf4a6047cfca), [`d5f628c`](https://github.com/mastra-ai/mastra/commit/d5f628ca86c6f6f3ff1035d52f635df32dd81cab), [`524c0f3`](https://github.com/mastra-ai/mastra/commit/524c0f3c434c3d9d18f66338dcef383d6161b59c), [`c18a0e9`](https://github.com/mastra-ai/mastra/commit/c18a0e9cef1e4ca004b2963d35e4cfc031971eac), [`4bd21ea`](https://github.com/mastra-ai/mastra/commit/4bd21ea43d44d0a0427414fc047577f9f0aa3bec), [`115a7a4`](https://github.com/mastra-ai/mastra/commit/115a7a47db5e9896fec12ae6507501adb9ec89bf), [`22a48ae`](https://github.com/mastra-ai/mastra/commit/22a48ae2513eb54d8d79dad361fddbca97a155e8), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9311c17`](https://github.com/mastra-ai/mastra/commit/9311c17d7a0640d9c4da2e71b814dc67c57c6369), [`7edf78f`](https://github.com/mastra-ai/mastra/commit/7edf78f80422c43e84585f08ba11df0d4d0b73c5), [`1c4221c`](https://github.com/mastra-ai/mastra/commit/1c4221cf6032ec98d0e094d4ee11da3e48490d96), [`d25b9ea`](https://github.com/mastra-ai/mastra/commit/d25b9eabd400167255a97b690ffbc4ee4097ded5), [`fe1ce5c`](https://github.com/mastra-ai/mastra/commit/fe1ce5c9211c03d561606fda95cbfe7df1d9a9b5), [`b03c0e0`](https://github.com/mastra-ai/mastra/commit/b03c0e0389a799523929a458b0509c9e4244d562), [`0a8366b`](https://github.com/mastra-ai/mastra/commit/0a8366b0a692fcdde56c4d526e4cf03c502ae4ac), [`85664e9`](https://github.com/mastra-ai/mastra/commit/85664e9fd857320fbc245e301f764f45f66f32a3), [`bc79650`](https://github.com/mastra-ai/mastra/commit/bc796500c6e0334faa158a96077e3fb332274869), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`3a3a59e`](https://github.com/mastra-ai/mastra/commit/3a3a59e8ffaa6a985fe3d9a126a3f5ade11a6724), [`3108d4e`](https://github.com/mastra-ai/mastra/commit/3108d4e649c9fddbf03253a6feeb388a5fa9fa5a), [`0c33b2c`](https://github.com/mastra-ai/mastra/commit/0c33b2c9db537f815e1c59e2c898ffce2e395a79), [`191e5bd`](https://github.com/mastra-ai/mastra/commit/191e5bd29b82f5bda35243945790da7bc7b695c2), [`f77cd94`](https://github.com/mastra-ai/mastra/commit/f77cd94c44eabed490384e7d19232a865e13214c), [`e8135c7`](https://github.com/mastra-ai/mastra/commit/e8135c7e300dac5040670eec7eab896ac6092e30), [`daca48f`](https://github.com/mastra-ai/mastra/commit/daca48f0fb17b7ae0b62a2ac40cf0e491b2fd0b7), [`257d14f`](https://github.com/mastra-ai/mastra/commit/257d14faca5931f2e4186fc165b6f0b1f915deee), [`352f25d`](https://github.com/mastra-ai/mastra/commit/352f25da316b24cdd5b410fd8dddf6a8b763da2a), [`93477d0`](https://github.com/mastra-ai/mastra/commit/93477d0769b8a13ea5ed73d508d967fb23eaeed9), [`31c78b3`](https://github.com/mastra-ai/mastra/commit/31c78b3eb28f58a8017f1dcc795c33214d87feac), [`0bc0720`](https://github.com/mastra-ai/mastra/commit/0bc07201095791858087cc56f353fcd65e87ab54), [`36516ac`](https://github.com/mastra-ai/mastra/commit/36516aca1021cbeb42e74751b46a2614101f37c8), [`e947652`](https://github.com/mastra-ai/mastra/commit/e9476527fdecb4449e54570e80dfaf8466901254), [`3c6ef79`](https://github.com/mastra-ai/mastra/commit/3c6ef798481e00d6d22563be2de98818fd4dd5e0), [`9257d01`](https://github.com/mastra-ai/mastra/commit/9257d01d1366d81f84c582fe02b5e200cf9621f4), [`ec248f6`](https://github.com/mastra-ai/mastra/commit/ec248f6b56e8a037c066c49b2178e2507471d988)]:
|
|
14
|
+
- @mastra/core@1.9.0-alpha.0
|
|
15
|
+
|
|
3
16
|
## 1.7.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/LICENSE.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
1
16
|
# Apache License 2.0
|
|
2
17
|
|
|
3
18
|
Copyright (c) 2025 Kepler Software, Inc.
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1463,11 +1463,9 @@ var PgVector = class extends vector.MastraVector {
|
|
|
1463
1463
|
WHERE c.relname = $1
|
|
1464
1464
|
AND n.nspname = $2;
|
|
1465
1465
|
`;
|
|
1466
|
-
const
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
client.query(indexQuery, [`${indexName}_vector_idx`, this.schema || "public"])
|
|
1470
|
-
]);
|
|
1466
|
+
const dimResult = await client.query(dimensionQuery, [tableName]);
|
|
1467
|
+
const countResult = await client.query(countQuery);
|
|
1468
|
+
const indexResult = await client.query(indexQuery, [`${indexName}_vector_idx`, this.schema || "public"]);
|
|
1471
1469
|
const { index_method, index_def, operator_class } = indexResult.rows[0] || {
|
|
1472
1470
|
index_method: "flat",
|
|
1473
1471
|
index_def: "",
|
|
@@ -6747,7 +6745,8 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
|
|
|
6747
6745
|
"isBufferingObservation",
|
|
6748
6746
|
"isBufferingReflection",
|
|
6749
6747
|
"lastBufferedAtTokens",
|
|
6750
|
-
"lastBufferedAtTime"
|
|
6748
|
+
"lastBufferedAtTime",
|
|
6749
|
+
"metadata"
|
|
6751
6750
|
]
|
|
6752
6751
|
});
|
|
6753
6752
|
}
|
|
@@ -7921,9 +7920,11 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
|
|
|
7921
7920
|
]
|
|
7922
7921
|
);
|
|
7923
7922
|
const clonedMessages = [];
|
|
7923
|
+
const messageIdMap = {};
|
|
7924
7924
|
const targetResourceId = resourceId || sourceThread.resourceId;
|
|
7925
7925
|
for (const sourceMsg of sourceMessages) {
|
|
7926
7926
|
const newMessageId = crypto.randomUUID();
|
|
7927
|
+
messageIdMap[sourceMsg.id] = newMessageId;
|
|
7927
7928
|
const normalizedMsg = this.normalizeMessageRow(sourceMsg);
|
|
7928
7929
|
let parsedContent = normalizedMsg.content;
|
|
7929
7930
|
try {
|
|
@@ -7956,7 +7957,8 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
|
|
|
7956
7957
|
}
|
|
7957
7958
|
return {
|
|
7958
7959
|
thread: newThread,
|
|
7959
|
-
clonedMessages
|
|
7960
|
+
clonedMessages,
|
|
7961
|
+
messageIdMap
|
|
7960
7962
|
};
|
|
7961
7963
|
});
|
|
7962
7964
|
} catch (error$1) {
|
|
@@ -8166,6 +8168,80 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
|
|
|
8166
8168
|
);
|
|
8167
8169
|
}
|
|
8168
8170
|
}
|
|
8171
|
+
async insertObservationalMemoryRecord(record) {
|
|
8172
|
+
try {
|
|
8173
|
+
const lookupKey = this.getOMKey(record.threadId, record.resourceId);
|
|
8174
|
+
const tableName = getTableName3({
|
|
8175
|
+
indexName: OM_TABLE,
|
|
8176
|
+
schemaName: getSchemaName3(this.#schema)
|
|
8177
|
+
});
|
|
8178
|
+
const lastObservedAtStr = record.lastObservedAt ? record.lastObservedAt.toISOString() : null;
|
|
8179
|
+
const lastBufferedAtTimeStr = record.lastBufferedAtTime ? record.lastBufferedAtTime.toISOString() : null;
|
|
8180
|
+
await this.#db.client.none(
|
|
8181
|
+
`INSERT INTO ${tableName} (
|
|
8182
|
+
id, "lookupKey", scope, "resourceId", "threadId",
|
|
8183
|
+
"activeObservations", "activeObservationsPendingUpdate",
|
|
8184
|
+
"originType", config, "generationCount", "lastObservedAt", "lastObservedAtZ", "lastReflectionAt", "lastReflectionAtZ",
|
|
8185
|
+
"pendingMessageTokens", "totalTokensObserved", "observationTokenCount",
|
|
8186
|
+
"observedMessageIds", "bufferedObservationChunks",
|
|
8187
|
+
"bufferedReflection", "bufferedReflectionTokens", "bufferedReflectionInputTokens",
|
|
8188
|
+
"reflectedObservationLineCount",
|
|
8189
|
+
"isObserving", "isReflecting", "isBufferingObservation", "isBufferingReflection",
|
|
8190
|
+
"lastBufferedAtTokens", "lastBufferedAtTime",
|
|
8191
|
+
"observedTimezone", metadata, "createdAt", "createdAtZ", "updatedAt", "updatedAtZ"
|
|
8192
|
+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35)`,
|
|
8193
|
+
[
|
|
8194
|
+
record.id,
|
|
8195
|
+
lookupKey,
|
|
8196
|
+
record.scope,
|
|
8197
|
+
record.resourceId,
|
|
8198
|
+
record.threadId || null,
|
|
8199
|
+
record.activeObservations || "",
|
|
8200
|
+
null,
|
|
8201
|
+
record.originType || "initial",
|
|
8202
|
+
record.config ? JSON.stringify(record.config) : null,
|
|
8203
|
+
record.generationCount || 0,
|
|
8204
|
+
lastObservedAtStr,
|
|
8205
|
+
lastObservedAtStr,
|
|
8206
|
+
null,
|
|
8207
|
+
// lastReflectionAt
|
|
8208
|
+
null,
|
|
8209
|
+
// lastReflectionAtZ
|
|
8210
|
+
record.pendingMessageTokens || 0,
|
|
8211
|
+
record.totalTokensObserved || 0,
|
|
8212
|
+
record.observationTokenCount || 0,
|
|
8213
|
+
record.observedMessageIds ? JSON.stringify(record.observedMessageIds) : null,
|
|
8214
|
+
record.bufferedObservationChunks ? JSON.stringify(record.bufferedObservationChunks) : null,
|
|
8215
|
+
record.bufferedReflection || null,
|
|
8216
|
+
record.bufferedReflectionTokens ?? null,
|
|
8217
|
+
record.bufferedReflectionInputTokens ?? null,
|
|
8218
|
+
record.reflectedObservationLineCount ?? null,
|
|
8219
|
+
record.isObserving || false,
|
|
8220
|
+
record.isReflecting || false,
|
|
8221
|
+
record.isBufferingObservation || false,
|
|
8222
|
+
record.isBufferingReflection || false,
|
|
8223
|
+
record.lastBufferedAtTokens || 0,
|
|
8224
|
+
lastBufferedAtTimeStr,
|
|
8225
|
+
record.observedTimezone || null,
|
|
8226
|
+
record.metadata ? JSON.stringify(record.metadata) : null,
|
|
8227
|
+
record.createdAt.toISOString(),
|
|
8228
|
+
record.createdAt.toISOString(),
|
|
8229
|
+
record.updatedAt.toISOString(),
|
|
8230
|
+
record.updatedAt.toISOString()
|
|
8231
|
+
]
|
|
8232
|
+
);
|
|
8233
|
+
} catch (error$1) {
|
|
8234
|
+
throw new error.MastraError(
|
|
8235
|
+
{
|
|
8236
|
+
id: storage.createStorageErrorId("PG", "INSERT_OBSERVATIONAL_MEMORY_RECORD", "FAILED"),
|
|
8237
|
+
domain: error.ErrorDomain.STORAGE,
|
|
8238
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
8239
|
+
details: { id: record.id, threadId: record.threadId, resourceId: record.resourceId }
|
|
8240
|
+
},
|
|
8241
|
+
error$1
|
|
8242
|
+
);
|
|
8243
|
+
}
|
|
8244
|
+
}
|
|
8169
8245
|
async updateActiveObservations(input) {
|
|
8170
8246
|
try {
|
|
8171
8247
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -8266,8 +8342,8 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
|
|
|
8266
8342
|
"originType", config, "generationCount", "lastObservedAt", "lastObservedAtZ", "lastReflectionAt", "lastReflectionAtZ",
|
|
8267
8343
|
"pendingMessageTokens", "totalTokensObserved", "observationTokenCount",
|
|
8268
8344
|
"isObserving", "isReflecting", "isBufferingObservation", "isBufferingReflection", "lastBufferedAtTokens", "lastBufferedAtTime",
|
|
8269
|
-
"observedTimezone", "createdAt", "createdAtZ", "updatedAt", "updatedAtZ"
|
|
8270
|
-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)`,
|
|
8345
|
+
"observedTimezone", metadata, "createdAt", "createdAtZ", "updatedAt", "updatedAtZ"
|
|
8346
|
+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29)`,
|
|
8271
8347
|
[
|
|
8272
8348
|
id,
|
|
8273
8349
|
lookupKey,
|
|
@@ -8303,6 +8379,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
|
|
|
8303
8379
|
null,
|
|
8304
8380
|
// lastBufferedAtTime
|
|
8305
8381
|
record.observedTimezone || null,
|
|
8382
|
+
record.metadata ? JSON.stringify(record.metadata) : null,
|
|
8306
8383
|
nowStr,
|
|
8307
8384
|
// createdAt
|
|
8308
8385
|
nowStr,
|
|
@@ -11913,6 +11990,9 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
11913
11990
|
this.#skipDefaultIndexes = skipDefaultIndexes;
|
|
11914
11991
|
this.#indexes = indexes?.filter((idx) => _WorkflowsPG.MANAGED_TABLES.includes(idx.table));
|
|
11915
11992
|
}
|
|
11993
|
+
supportsConcurrentUpdates() {
|
|
11994
|
+
return true;
|
|
11995
|
+
}
|
|
11916
11996
|
parseWorkflowRun(row) {
|
|
11917
11997
|
let parsedSnapshot = row.snapshot;
|
|
11918
11998
|
if (typeof parsedSnapshot === "string") {
|
|
@@ -11991,21 +12071,111 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
|
|
|
11991
12071
|
async dangerouslyClearAll() {
|
|
11992
12072
|
await this.#db.clearTable({ tableName: storage.TABLE_WORKFLOW_SNAPSHOT });
|
|
11993
12073
|
}
|
|
11994
|
-
updateWorkflowResults({
|
|
11995
|
-
|
|
11996
|
-
|
|
11997
|
-
|
|
11998
|
-
|
|
11999
|
-
|
|
12074
|
+
async updateWorkflowResults({
|
|
12075
|
+
workflowName,
|
|
12076
|
+
runId,
|
|
12077
|
+
stepId,
|
|
12078
|
+
result,
|
|
12079
|
+
requestContext
|
|
12000
12080
|
}) {
|
|
12001
|
-
|
|
12081
|
+
try {
|
|
12082
|
+
return await this.#db.client.tx(async (t) => {
|
|
12083
|
+
const tableName = getTableName5({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) });
|
|
12084
|
+
const existingSnapshotResult = await t.oneOrNone(
|
|
12085
|
+
`SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
|
|
12086
|
+
[workflowName, runId]
|
|
12087
|
+
);
|
|
12088
|
+
let snapshot;
|
|
12089
|
+
if (!existingSnapshotResult) {
|
|
12090
|
+
snapshot = {
|
|
12091
|
+
context: {},
|
|
12092
|
+
activePaths: [],
|
|
12093
|
+
timestamp: Date.now(),
|
|
12094
|
+
suspendedPaths: {},
|
|
12095
|
+
activeStepsPath: {},
|
|
12096
|
+
resumeLabels: {},
|
|
12097
|
+
serializedStepGraph: [],
|
|
12098
|
+
status: "pending",
|
|
12099
|
+
value: {},
|
|
12100
|
+
waitingPaths: {},
|
|
12101
|
+
runId,
|
|
12102
|
+
requestContext: {}
|
|
12103
|
+
};
|
|
12104
|
+
} else {
|
|
12105
|
+
const existingSnapshot = existingSnapshotResult.snapshot;
|
|
12106
|
+
snapshot = typeof existingSnapshot === "string" ? JSON.parse(existingSnapshot) : existingSnapshot;
|
|
12107
|
+
}
|
|
12108
|
+
snapshot.context[stepId] = result;
|
|
12109
|
+
snapshot.requestContext = { ...snapshot.requestContext, ...requestContext };
|
|
12110
|
+
const now = /* @__PURE__ */ new Date();
|
|
12111
|
+
const sanitizedSnapshot = sanitizeJsonForPg(JSON.stringify(snapshot));
|
|
12112
|
+
await t.none(
|
|
12113
|
+
`INSERT INTO ${tableName} (workflow_name, run_id, snapshot, "createdAt", "updatedAt")
|
|
12114
|
+
VALUES ($1, $2, $3, $4, $5)
|
|
12115
|
+
ON CONFLICT (workflow_name, run_id) DO UPDATE
|
|
12116
|
+
SET snapshot = $3, "updatedAt" = $5`,
|
|
12117
|
+
[workflowName, runId, sanitizedSnapshot, now, now]
|
|
12118
|
+
);
|
|
12119
|
+
return snapshot.context;
|
|
12120
|
+
});
|
|
12121
|
+
} catch (error$1) {
|
|
12122
|
+
throw new error.MastraError(
|
|
12123
|
+
{
|
|
12124
|
+
id: storage.createStorageErrorId("PG", "UPDATE_WORKFLOW_RESULTS", "FAILED"),
|
|
12125
|
+
domain: error.ErrorDomain.STORAGE,
|
|
12126
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
12127
|
+
details: {
|
|
12128
|
+
workflowName,
|
|
12129
|
+
runId,
|
|
12130
|
+
stepId
|
|
12131
|
+
}
|
|
12132
|
+
},
|
|
12133
|
+
error$1
|
|
12134
|
+
);
|
|
12135
|
+
}
|
|
12002
12136
|
}
|
|
12003
|
-
updateWorkflowState({
|
|
12004
|
-
|
|
12005
|
-
|
|
12006
|
-
|
|
12137
|
+
async updateWorkflowState({
|
|
12138
|
+
workflowName,
|
|
12139
|
+
runId,
|
|
12140
|
+
opts
|
|
12007
12141
|
}) {
|
|
12008
|
-
|
|
12142
|
+
try {
|
|
12143
|
+
return await this.#db.client.tx(async (t) => {
|
|
12144
|
+
const tableName = getTableName5({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) });
|
|
12145
|
+
const existingSnapshotResult = await t.oneOrNone(
|
|
12146
|
+
`SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
|
|
12147
|
+
[workflowName, runId]
|
|
12148
|
+
);
|
|
12149
|
+
if (!existingSnapshotResult) {
|
|
12150
|
+
return void 0;
|
|
12151
|
+
}
|
|
12152
|
+
const existingSnapshot = existingSnapshotResult.snapshot;
|
|
12153
|
+
const snapshot = typeof existingSnapshot === "string" ? JSON.parse(existingSnapshot) : existingSnapshot;
|
|
12154
|
+
if (!snapshot || !snapshot?.context) {
|
|
12155
|
+
throw new Error(`Snapshot not found for runId ${runId}`);
|
|
12156
|
+
}
|
|
12157
|
+
const updatedSnapshot = { ...snapshot, ...opts };
|
|
12158
|
+
const sanitizedSnapshot = sanitizeJsonForPg(JSON.stringify(updatedSnapshot));
|
|
12159
|
+
await t.none(
|
|
12160
|
+
`UPDATE ${tableName} SET snapshot = $1, "updatedAt" = $2 WHERE workflow_name = $3 AND run_id = $4`,
|
|
12161
|
+
[sanitizedSnapshot, /* @__PURE__ */ new Date(), workflowName, runId]
|
|
12162
|
+
);
|
|
12163
|
+
return updatedSnapshot;
|
|
12164
|
+
});
|
|
12165
|
+
} catch (error$1) {
|
|
12166
|
+
throw new error.MastraError(
|
|
12167
|
+
{
|
|
12168
|
+
id: storage.createStorageErrorId("PG", "UPDATE_WORKFLOW_STATE", "FAILED"),
|
|
12169
|
+
domain: error.ErrorDomain.STORAGE,
|
|
12170
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
12171
|
+
details: {
|
|
12172
|
+
workflowName,
|
|
12173
|
+
runId
|
|
12174
|
+
}
|
|
12175
|
+
},
|
|
12176
|
+
error$1
|
|
12177
|
+
);
|
|
12178
|
+
}
|
|
12009
12179
|
}
|
|
12010
12180
|
async persistWorkflowSnapshot({
|
|
12011
12181
|
workflowName,
|