@mastra/pg 1.27.0-alpha.0 → 1.27.0-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/docs/references/reference-memory-memory-class.md +2 -0
- package/dist/docs/references/reference-storage-retention.md +9 -7
- package/dist/index.cjs +296 -228
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +296 -228
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/sanitize-json.d.ts +2 -10
- package/dist/storage/db/sanitize-json.d.ts.map +1 -1
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
- package/dist/storage/domains/channels/index.d.ts.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
- package/dist/storage/domains/mcp-clients/index.d.ts.map +1 -1
- package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/notifications/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/discovery.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/metrics.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/scores.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/trace-query.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/traces.d.ts.map +1 -1
- package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -1
- package/dist/storage/domains/schedules/index.d.ts.map +1 -1
- package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/skills/index.d.ts.map +1 -1
- package/dist/storage/domains/thread-state/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +0 -2
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/domains/workspaces/index.d.ts.map +1 -1
- package/dist/storage/factory-storage.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
|
|
|
39
39
|
let _mastra_core_features = require("@mastra/core/features");
|
|
40
40
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
41
41
|
let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
|
|
42
|
+
let util = require("util");
|
|
42
43
|
//#region src/shared/config.ts
|
|
43
44
|
/**
|
|
44
45
|
* Type guard for pre-configured pg.Pool config
|
|
@@ -2432,6 +2433,29 @@ function isDuplicateSchemaError(error) {
|
|
|
2432
2433
|
return /schema .* already exists/i.test(message);
|
|
2433
2434
|
}
|
|
2434
2435
|
//#endregion
|
|
2436
|
+
//#region src/storage/db/sanitize-json.ts
|
|
2437
|
+
const repair = (value) => value.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "�").replaceAll("\0", "");
|
|
2438
|
+
function repairJson(value) {
|
|
2439
|
+
if (typeof value === "string") return repair(value);
|
|
2440
|
+
if (Array.isArray(value)) return value.map(repairJson);
|
|
2441
|
+
if (value && typeof value === "object") {
|
|
2442
|
+
const repaired = Object.create(null);
|
|
2443
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
2444
|
+
const repairedKey = repair(key);
|
|
2445
|
+
if (Object.hasOwn(repaired, repairedKey)) throw new Error(`JSON keys collide after PostgreSQL normalization: ${repairedKey}`);
|
|
2446
|
+
repaired[repairedKey] = repairJson(entry);
|
|
2447
|
+
}
|
|
2448
|
+
return repaired;
|
|
2449
|
+
}
|
|
2450
|
+
return value;
|
|
2451
|
+
}
|
|
2452
|
+
/** Serialize JSON values without emitting Unicode sequences PostgreSQL rejects. */
|
|
2453
|
+
function toPgJson(value) {
|
|
2454
|
+
const json = JSON.stringify(value);
|
|
2455
|
+
if (json === void 0 || !/\\u(?:0000|[dD][89a-fA-F][0-9a-fA-F]{2})/.test(json)) return json;
|
|
2456
|
+
return JSON.stringify(repairJson(JSON.parse(json)));
|
|
2457
|
+
}
|
|
2458
|
+
//#endregion
|
|
2435
2459
|
//#region src/storage/db/schema-snapshot.ts
|
|
2436
2460
|
/**
|
|
2437
2461
|
* Returns the snapshot currently installed on `client`, but only when it was
|
|
@@ -2956,7 +2980,7 @@ var PgDB = class extends _mastra_core_base.MastraBase {
|
|
|
2956
2980
|
*/
|
|
2957
2981
|
prepareValuesForInsert(record, tableName) {
|
|
2958
2982
|
return Object.entries(record).map(([key, value]) => {
|
|
2959
|
-
if ((_mastra_core_storage.TABLE_SCHEMAS[tableName]?.[key])?.type === "jsonb" && value !== null && value !== void 0) return
|
|
2983
|
+
if ((_mastra_core_storage.TABLE_SCHEMAS[tableName]?.[key])?.type === "jsonb" && value !== null && value !== void 0) return toPgJson(value);
|
|
2960
2984
|
return value;
|
|
2961
2985
|
});
|
|
2962
2986
|
}
|
|
@@ -2974,8 +2998,8 @@ var PgDB = class extends _mastra_core_base.MastraBase {
|
|
|
2974
2998
|
prepareValue(value, columnName, tableName) {
|
|
2975
2999
|
if (value === null || value === void 0) return value;
|
|
2976
3000
|
if (value instanceof Date) return value.toISOString();
|
|
2977
|
-
if ((_mastra_core_storage.TABLE_SCHEMAS[tableName]?.[columnName])?.type === "jsonb") return
|
|
2978
|
-
if (typeof value === "object") return
|
|
3001
|
+
if ((_mastra_core_storage.TABLE_SCHEMAS[tableName]?.[columnName])?.type === "jsonb") return toPgJson(value);
|
|
3002
|
+
if (typeof value === "object") return toPgJson(value);
|
|
2979
3003
|
return value;
|
|
2980
3004
|
}
|
|
2981
3005
|
async setupSchema() {
|
|
@@ -4229,7 +4253,7 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4229
4253
|
"published",
|
|
4230
4254
|
versionId,
|
|
4231
4255
|
row.ownerId ?? row.authorId ?? null,
|
|
4232
|
-
row.metadata ?
|
|
4256
|
+
row.metadata ? toPgJson(row.metadata) : null,
|
|
4233
4257
|
row.createdAt ?? now,
|
|
4234
4258
|
row.updatedAt ?? now
|
|
4235
4259
|
]);
|
|
@@ -4245,17 +4269,17 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4245
4269
|
row.name ?? agentId,
|
|
4246
4270
|
row.description ?? null,
|
|
4247
4271
|
this.serializeInstructions(row.instructions ?? ""),
|
|
4248
|
-
row.model ?
|
|
4249
|
-
row.tools ?
|
|
4250
|
-
row.defaultOptions ?
|
|
4251
|
-
row.workflows ?
|
|
4252
|
-
row.agents ?
|
|
4253
|
-
row.integrationTools ?
|
|
4254
|
-
row.toolProviders ?
|
|
4255
|
-
row.inputProcessors ?
|
|
4256
|
-
row.outputProcessors ?
|
|
4257
|
-
row.memory ?
|
|
4258
|
-
row.scorers ?
|
|
4272
|
+
row.model ? toPgJson(row.model) : "{}",
|
|
4273
|
+
row.tools ? toPgJson(row.tools) : null,
|
|
4274
|
+
row.defaultOptions ? toPgJson(row.defaultOptions) : null,
|
|
4275
|
+
row.workflows ? toPgJson(row.workflows) : null,
|
|
4276
|
+
row.agents ? toPgJson(row.agents) : null,
|
|
4277
|
+
row.integrationTools ? toPgJson(row.integrationTools) : null,
|
|
4278
|
+
row.toolProviders ? toPgJson(row.toolProviders) : null,
|
|
4279
|
+
row.inputProcessors ? toPgJson(row.inputProcessors) : null,
|
|
4280
|
+
row.outputProcessors ? toPgJson(row.outputProcessors) : null,
|
|
4281
|
+
row.memory ? toPgJson(row.memory) : null,
|
|
4282
|
+
row.scorers ? toPgJson(row.scorers) : null,
|
|
4259
4283
|
null,
|
|
4260
4284
|
"Migrated from legacy schema",
|
|
4261
4285
|
row.createdAt ?? now
|
|
@@ -4305,7 +4329,7 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4305
4329
|
for (const toolKey of toolsArray) toolsObject[toolKey] = {};
|
|
4306
4330
|
await this.#db.client.none(`UPDATE ${fullVersionsTableName}
|
|
4307
4331
|
SET tools = $1::jsonb
|
|
4308
|
-
WHERE id = $2`, [
|
|
4332
|
+
WHERE id = $2`, [toPgJson(toolsObject), record.id]);
|
|
4309
4333
|
}
|
|
4310
4334
|
this.logger?.info?.(`Migrated ${recordsWithArrayTools.length} agent version(s) tools from array to object format`);
|
|
4311
4335
|
} catch (error) {
|
|
@@ -4402,6 +4426,7 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4402
4426
|
const now = /* @__PURE__ */ new Date();
|
|
4403
4427
|
const nowIso = now.toISOString();
|
|
4404
4428
|
const visibility = agent.visibility ?? (agent.authorId ? "private" : null);
|
|
4429
|
+
const metadataJson = agent.metadata ? toPgJson(agent.metadata) : null;
|
|
4405
4430
|
await this.#db.client.none(`INSERT INTO ${agentsTable} (
|
|
4406
4431
|
id, status, "authorId", visibility, metadata, "favoriteCount",
|
|
4407
4432
|
"activeVersionId",
|
|
@@ -4411,7 +4436,7 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4411
4436
|
"draft",
|
|
4412
4437
|
agent.authorId ?? null,
|
|
4413
4438
|
visibility,
|
|
4414
|
-
|
|
4439
|
+
metadataJson,
|
|
4415
4440
|
0,
|
|
4416
4441
|
null,
|
|
4417
4442
|
nowIso,
|
|
@@ -4435,7 +4460,7 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4435
4460
|
activeVersionId: void 0,
|
|
4436
4461
|
authorId: agent.authorId,
|
|
4437
4462
|
visibility: visibility ?? void 0,
|
|
4438
|
-
metadata: agent.metadata,
|
|
4463
|
+
metadata: metadataJson ? JSON.parse(metadataJson) : agent.metadata,
|
|
4439
4464
|
favoriteCount: 0,
|
|
4440
4465
|
createdAt: now,
|
|
4441
4466
|
updatedAt: now
|
|
@@ -4493,7 +4518,7 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4493
4518
|
}
|
|
4494
4519
|
if (metadata !== void 0) {
|
|
4495
4520
|
setClauses.push(`metadata = $${paramIndex++}`);
|
|
4496
|
-
values.push(
|
|
4521
|
+
values.push(toPgJson(metadata));
|
|
4497
4522
|
}
|
|
4498
4523
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4499
4524
|
setClauses.push(`"updatedAt" = $${paramIndex++}`);
|
|
@@ -4587,7 +4612,7 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4587
4612
|
}
|
|
4588
4613
|
if (metadata && Object.keys(metadata).length > 0) {
|
|
4589
4614
|
conditions.push(`a.metadata @> $${paramIdx++}::jsonb`);
|
|
4590
|
-
queryParams.push(
|
|
4615
|
+
queryParams.push(toPgJson(metadata));
|
|
4591
4616
|
}
|
|
4592
4617
|
if (entityIds && entityIds.length > 0) {
|
|
4593
4618
|
const placeholders = entityIds.map(() => `$${paramIdx++}`).join(", ");
|
|
@@ -4653,9 +4678,8 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4653
4678
|
indexName: _mastra_core_storage.TABLE_AGENT_VERSIONS,
|
|
4654
4679
|
schemaName: getSchemaName$5(this.#schema)
|
|
4655
4680
|
});
|
|
4656
|
-
const
|
|
4657
|
-
const
|
|
4658
|
-
await this.#db.client.none(`INSERT INTO ${tableName} (
|
|
4681
|
+
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
4682
|
+
const row = await this.#db.client.one(`INSERT INTO ${tableName} (
|
|
4659
4683
|
id, "agentId", "versionNumber",
|
|
4660
4684
|
name, description, instructions, model, tools,
|
|
4661
4685
|
"defaultOptions", workflows, agents, "integrationTools", "toolProviders",
|
|
@@ -4664,40 +4688,37 @@ var AgentsPG = class AgentsPG extends _mastra_core_storage.AgentsStorage {
|
|
|
4664
4688
|
durable, browser,
|
|
4665
4689
|
"changedFields", "changeMessage",
|
|
4666
4690
|
"createdAt", "createdAtZ"
|
|
4667
|
-
) 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)
|
|
4691
|
+
) 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) RETURNING *`, [
|
|
4668
4692
|
input.id,
|
|
4669
4693
|
input.agentId,
|
|
4670
4694
|
input.versionNumber,
|
|
4671
4695
|
input.name,
|
|
4672
4696
|
input.description ?? null,
|
|
4673
4697
|
this.serializeInstructions(input.instructions),
|
|
4674
|
-
|
|
4675
|
-
input.tools ?
|
|
4676
|
-
input.defaultOptions ?
|
|
4677
|
-
input.workflows ?
|
|
4678
|
-
input.agents ?
|
|
4679
|
-
input.integrationTools ?
|
|
4680
|
-
input.toolProviders ?
|
|
4681
|
-
input.inputProcessors ?
|
|
4682
|
-
input.outputProcessors ?
|
|
4683
|
-
input.memory ?
|
|
4684
|
-
input.scorers ?
|
|
4685
|
-
input.mcpClients ?
|
|
4686
|
-
input.requestContextSchema ?
|
|
4687
|
-
input.workspace ?
|
|
4688
|
-
input.skills ?
|
|
4698
|
+
toPgJson(input.model),
|
|
4699
|
+
input.tools ? toPgJson(input.tools) : null,
|
|
4700
|
+
input.defaultOptions ? toPgJson(input.defaultOptions) : null,
|
|
4701
|
+
input.workflows ? toPgJson(input.workflows) : null,
|
|
4702
|
+
input.agents ? toPgJson(input.agents) : null,
|
|
4703
|
+
input.integrationTools ? toPgJson(input.integrationTools) : null,
|
|
4704
|
+
input.toolProviders ? toPgJson(input.toolProviders) : null,
|
|
4705
|
+
input.inputProcessors ? toPgJson(input.inputProcessors) : null,
|
|
4706
|
+
input.outputProcessors ? toPgJson(input.outputProcessors) : null,
|
|
4707
|
+
input.memory ? toPgJson(input.memory) : null,
|
|
4708
|
+
input.scorers ? toPgJson(input.scorers) : null,
|
|
4709
|
+
input.mcpClients ? toPgJson(input.mcpClients) : null,
|
|
4710
|
+
input.requestContextSchema ? toPgJson(input.requestContextSchema) : null,
|
|
4711
|
+
input.workspace ? toPgJson(input.workspace) : null,
|
|
4712
|
+
input.skills ? toPgJson(input.skills) : null,
|
|
4689
4713
|
input.skillsFormat ?? null,
|
|
4690
|
-
input.durable !== void 0 ?
|
|
4691
|
-
input.browser ?
|
|
4692
|
-
input.changedFields ?
|
|
4714
|
+
input.durable !== void 0 ? toPgJson(input.durable) : null,
|
|
4715
|
+
input.browser ? toPgJson(input.browser) : null,
|
|
4716
|
+
input.changedFields ? toPgJson(input.changedFields) : null,
|
|
4693
4717
|
input.changeMessage ?? null,
|
|
4694
4718
|
nowIso,
|
|
4695
4719
|
nowIso
|
|
4696
4720
|
]);
|
|
4697
|
-
return
|
|
4698
|
-
...input,
|
|
4699
|
-
createdAt: now
|
|
4700
|
-
};
|
|
4721
|
+
return this.parseVersionRow(row);
|
|
4701
4722
|
} catch (error) {
|
|
4702
4723
|
if (error instanceof _mastra_core_error.MastraError) throw error;
|
|
4703
4724
|
throw new _mastra_core_error.MastraError({
|
|
@@ -4981,7 +5002,7 @@ function getTableName$4(schemaName) {
|
|
|
4981
5002
|
return schemaName ? `${schemaName}.${quoted}` : quoted;
|
|
4982
5003
|
}
|
|
4983
5004
|
function serializeJson(v) {
|
|
4984
|
-
if (typeof v === "object" && v != null) return
|
|
5005
|
+
if (typeof v === "object" && v != null) return toPgJson(v);
|
|
4985
5006
|
return v ?? null;
|
|
4986
5007
|
}
|
|
4987
5008
|
function parseJson$2(v) {
|
|
@@ -5560,7 +5581,7 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
|
|
|
5560
5581
|
installation.agentId,
|
|
5561
5582
|
installation.status,
|
|
5562
5583
|
installation.webhookId ?? null,
|
|
5563
|
-
|
|
5584
|
+
toPgJson(installation.data),
|
|
5564
5585
|
installation.configHash ?? null,
|
|
5565
5586
|
installation.error ?? null,
|
|
5566
5587
|
createdAt,
|
|
@@ -5620,7 +5641,7 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
|
|
|
5620
5641
|
"updatedAt" = EXCLUDED."updatedAt",
|
|
5621
5642
|
"updatedAtZ" = EXCLUDED."updatedAtZ"`, [
|
|
5622
5643
|
config.platform,
|
|
5623
|
-
|
|
5644
|
+
toPgJson(config.data),
|
|
5624
5645
|
now,
|
|
5625
5646
|
now
|
|
5626
5647
|
]);
|
|
@@ -5664,8 +5685,21 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
|
|
|
5664
5685
|
//#region src/storage/domains/datasets/index.ts
|
|
5665
5686
|
/** Serialize a value for a jsonb column. Returns null for null/undefined. */
|
|
5666
5687
|
function jsonbArg(value) {
|
|
5667
|
-
return value === void 0 || value === null ? null :
|
|
5688
|
+
return value === void 0 || value === null ? null : toPgJson(value);
|
|
5689
|
+
}
|
|
5690
|
+
/** Preserve JSON null as data, rather than converting it to an absent SQL value. */
|
|
5691
|
+
function jsonDataArg(value) {
|
|
5692
|
+
return value === void 0 ? null : JSON.stringify(value);
|
|
5668
5693
|
}
|
|
5694
|
+
const ITEM_SELECT_COLUMNS = [
|
|
5695
|
+
...Object.keys(_mastra_core_storage.DATASET_ITEMS_SCHEMA),
|
|
5696
|
+
"createdAtZ",
|
|
5697
|
+
"updatedAtZ"
|
|
5698
|
+
].map((column) => [
|
|
5699
|
+
"input",
|
|
5700
|
+
"groundTruth",
|
|
5701
|
+
"expectedTrajectory"
|
|
5702
|
+
].includes(column) ? `"${column}"::text AS "${column}"` : `"${column}"`).join(", ");
|
|
5669
5703
|
function parseStoredJSON(value) {
|
|
5670
5704
|
if (typeof value === "string") try {
|
|
5671
5705
|
return JSON.parse(value);
|
|
@@ -5840,9 +5874,9 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
5840
5874
|
groundTruthSchema: row.groundTruthSchema ? (0, _mastra_core_storage.safelyParseJSON)(row.groundTruthSchema) : void 0,
|
|
5841
5875
|
requestContextSchema: row.requestContextSchema ? (0, _mastra_core_storage.safelyParseJSON)(row.requestContextSchema) : void 0,
|
|
5842
5876
|
tags: row.tags ? (0, _mastra_core_storage.safelyParseJSON)(row.tags) : void 0,
|
|
5843
|
-
targetType: row.targetType ||
|
|
5844
|
-
targetIds: row.targetIds
|
|
5845
|
-
scorerIds: row.scorerIds
|
|
5877
|
+
targetType: row.targetType || void 0,
|
|
5878
|
+
targetIds: row.targetIds ?? void 0,
|
|
5879
|
+
scorerIds: row.scorerIds ?? void 0,
|
|
5846
5880
|
organizationId: row.organizationId ?? null,
|
|
5847
5881
|
projectId: row.projectId ?? null,
|
|
5848
5882
|
candidateKey: row.candidateKey ?? null,
|
|
@@ -5944,9 +5978,9 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
5944
5978
|
inputSchema: input.inputSchema ?? void 0,
|
|
5945
5979
|
groundTruthSchema: input.groundTruthSchema ?? void 0,
|
|
5946
5980
|
requestContextSchema: input.requestContextSchema ?? void 0,
|
|
5947
|
-
targetType: input.targetType ??
|
|
5948
|
-
targetIds: input.targetIds ??
|
|
5949
|
-
scorerIds: input.scorerIds ??
|
|
5981
|
+
targetType: input.targetType ?? void 0,
|
|
5982
|
+
targetIds: input.targetIds ?? void 0,
|
|
5983
|
+
scorerIds: input.scorerIds ?? void 0,
|
|
5950
5984
|
organizationId: input.organizationId ?? null,
|
|
5951
5985
|
projectId: input.projectId ?? null,
|
|
5952
5986
|
candidateKey: input.candidateKey ?? null,
|
|
@@ -6032,23 +6066,23 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6032
6066
|
}
|
|
6033
6067
|
if (args.metadata !== void 0) {
|
|
6034
6068
|
setClauses.push(`"metadata" = $${paramIndex++}`);
|
|
6035
|
-
values.push(
|
|
6069
|
+
values.push(toPgJson(args.metadata));
|
|
6036
6070
|
}
|
|
6037
6071
|
if (args.inputSchema !== void 0) {
|
|
6038
6072
|
setClauses.push(`"inputSchema" = $${paramIndex++}`);
|
|
6039
|
-
values.push(args.inputSchema === null ? null :
|
|
6073
|
+
values.push(args.inputSchema === null ? null : toPgJson(args.inputSchema));
|
|
6040
6074
|
}
|
|
6041
6075
|
if (args.groundTruthSchema !== void 0) {
|
|
6042
6076
|
setClauses.push(`"groundTruthSchema" = $${paramIndex++}`);
|
|
6043
|
-
values.push(args.groundTruthSchema === null ? null :
|
|
6077
|
+
values.push(args.groundTruthSchema === null ? null : toPgJson(args.groundTruthSchema));
|
|
6044
6078
|
}
|
|
6045
6079
|
if (args.requestContextSchema !== void 0) {
|
|
6046
6080
|
setClauses.push(`"requestContextSchema" = $${paramIndex++}`);
|
|
6047
|
-
values.push(args.requestContextSchema === null ? null :
|
|
6081
|
+
values.push(args.requestContextSchema === null ? null : toPgJson(args.requestContextSchema));
|
|
6048
6082
|
}
|
|
6049
6083
|
if (args.tags !== void 0) {
|
|
6050
6084
|
setClauses.push(`"tags" = $${paramIndex++}`);
|
|
6051
|
-
values.push(args.tags === null ? null :
|
|
6085
|
+
values.push(args.tags === null ? null : toPgJson(args.tags));
|
|
6052
6086
|
}
|
|
6053
6087
|
if (args.targetType !== void 0) {
|
|
6054
6088
|
setClauses.push(`"targetType" = $${paramIndex++}`);
|
|
@@ -6056,11 +6090,11 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6056
6090
|
}
|
|
6057
6091
|
if (args.targetIds !== void 0) {
|
|
6058
6092
|
setClauses.push(`"targetIds" = $${paramIndex++}`);
|
|
6059
|
-
values.push(args.targetIds === null ? null :
|
|
6093
|
+
values.push(args.targetIds === null ? null : toPgJson(args.targetIds));
|
|
6060
6094
|
}
|
|
6061
6095
|
if (args.scorerIds !== void 0) {
|
|
6062
6096
|
setClauses.push(`"scorerIds" = $${paramIndex++}`);
|
|
6063
|
-
values.push(args.scorerIds === null ? null :
|
|
6097
|
+
values.push(args.scorerIds === null ? null : toPgJson(args.scorerIds));
|
|
6064
6098
|
}
|
|
6065
6099
|
values.push(args.id);
|
|
6066
6100
|
await this.#db.client.none(`UPDATE ${tableName} SET ${setClauses.join(", ")} WHERE "id" = $${paramIndex}`, values);
|
|
@@ -6073,9 +6107,9 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6073
6107
|
groundTruthSchema: (args.groundTruthSchema !== void 0 ? args.groundTruthSchema : existing.groundTruthSchema) ?? void 0,
|
|
6074
6108
|
requestContextSchema: (args.requestContextSchema !== void 0 ? args.requestContextSchema : existing.requestContextSchema) ?? void 0,
|
|
6075
6109
|
tags: (args.tags !== void 0 ? args.tags : existing.tags) ?? void 0,
|
|
6076
|
-
targetType: (args.targetType !== void 0 ? args.targetType : existing.targetType) ??
|
|
6077
|
-
targetIds: (args.targetIds !== void 0 ? args.targetIds : existing.targetIds) ??
|
|
6078
|
-
scorerIds: (args.scorerIds !== void 0 ? args.scorerIds : existing.scorerIds) ??
|
|
6110
|
+
targetType: (args.targetType !== void 0 ? args.targetType : existing.targetType) ?? void 0,
|
|
6111
|
+
targetIds: (args.targetIds !== void 0 ? args.targetIds : existing.targetIds) ?? void 0,
|
|
6112
|
+
scorerIds: (args.scorerIds !== void 0 ? args.scorerIds : existing.scorerIds) ?? void 0,
|
|
6079
6113
|
organizationId: existing.organizationId ?? null,
|
|
6080
6114
|
projectId: existing.projectId ?? null,
|
|
6081
6115
|
candidateKey: existing.candidateKey ?? null,
|
|
@@ -6253,8 +6287,8 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6253
6287
|
parentOrganizationId,
|
|
6254
6288
|
parentProjectId,
|
|
6255
6289
|
JSON.stringify(args.input),
|
|
6256
|
-
|
|
6257
|
-
|
|
6290
|
+
jsonDataArg(args.groundTruth),
|
|
6291
|
+
jsonDataArg(args.expectedTrajectory),
|
|
6258
6292
|
jsonbArg(args.toolMocks),
|
|
6259
6293
|
args.unmockedToolPolicy ?? null,
|
|
6260
6294
|
jsonbArg(args.scorerIds),
|
|
@@ -6370,8 +6404,8 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6370
6404
|
parentOrganizationId,
|
|
6371
6405
|
parentProjectId,
|
|
6372
6406
|
JSON.stringify(mergedInput),
|
|
6373
|
-
|
|
6374
|
-
|
|
6407
|
+
jsonDataArg(mergedGroundTruth),
|
|
6408
|
+
jsonDataArg(mergedExpectedTrajectory),
|
|
6375
6409
|
jsonbArg(mergedToolMocks),
|
|
6376
6410
|
mergedUnmockedToolPolicy ?? null,
|
|
6377
6411
|
jsonbArg(mergedScorerIds),
|
|
@@ -6460,8 +6494,8 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6460
6494
|
parentOrganizationId,
|
|
6461
6495
|
parentProjectId,
|
|
6462
6496
|
JSON.stringify(existing.input),
|
|
6463
|
-
|
|
6464
|
-
|
|
6497
|
+
jsonDataArg(existing.groundTruth),
|
|
6498
|
+
jsonDataArg(existing.expectedTrajectory),
|
|
6465
6499
|
jsonbArg(existing.toolMocks),
|
|
6466
6500
|
existing.unmockedToolPolicy ?? null,
|
|
6467
6501
|
jsonbArg(existing.scorerIds),
|
|
@@ -6508,10 +6542,9 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6508
6542
|
indexName: _mastra_core_storage.TABLE_EXPERIMENT_RESULTS,
|
|
6509
6543
|
schemaName: getSchemaName$5(this.#schema)
|
|
6510
6544
|
});
|
|
6511
|
-
const
|
|
6512
|
-
const purgedMetadata = JSON.stringify({
|
|
6545
|
+
const purgedMetadata = toPgJson({
|
|
6513
6546
|
__purged: true,
|
|
6514
|
-
purgedAt
|
|
6547
|
+
purgedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
6515
6548
|
});
|
|
6516
6549
|
await this.#db.client.tx(async (t) => {
|
|
6517
6550
|
if (!await t.oneOrNone(`SELECT "id" FROM ${datasetsTable} WHERE "id" = $1 FOR UPDATE`, [datasetId])) return;
|
|
@@ -6561,7 +6594,7 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6561
6594
|
details: { datasetId: input.datasetId }
|
|
6562
6595
|
});
|
|
6563
6596
|
const externalIds = [...new Set(input.items.flatMap((item) => item.externalId ? [item.externalId] : []))];
|
|
6564
|
-
const historyRows = externalIds.length ? await t.manyOrNone(`SELECT
|
|
6597
|
+
const historyRows = externalIds.length ? await t.manyOrNone(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${itemsTable} WHERE "datasetId" = $1 AND "externalId" = ANY($2::text[]) ORDER BY "datasetVersion"`, [input.datasetId, externalIds]) : [];
|
|
6565
6598
|
const plan = this.planDatasetItemBatch(input.items, historyRows.map((row) => this.transformItemRowFull(row)), () => crypto.randomUUID());
|
|
6566
6599
|
const resolved = new Map([...plan.existingCurrentItems].map(([id, row]) => [id, this.datasetItemFromRow(row)]));
|
|
6567
6600
|
if (plan.inserts.length > 0) {
|
|
@@ -6578,8 +6611,8 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6578
6611
|
dataset.organizationId ?? null,
|
|
6579
6612
|
dataset.projectId ?? null,
|
|
6580
6613
|
JSON.stringify(item.input),
|
|
6581
|
-
|
|
6582
|
-
|
|
6614
|
+
jsonDataArg(item.groundTruth),
|
|
6615
|
+
jsonDataArg(item.expectedTrajectory),
|
|
6583
6616
|
jsonbArg(item.toolMocks),
|
|
6584
6617
|
item.unmockedToolPolicy ?? null,
|
|
6585
6618
|
jsonbArg(item.scorerIds),
|
|
@@ -6656,7 +6689,7 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6656
6689
|
category: _mastra_core_error.ErrorCategory.USER,
|
|
6657
6690
|
details: { datasetId: input.datasetId }
|
|
6658
6691
|
});
|
|
6659
|
-
const currentItems = (await t.manyOrNone(`SELECT
|
|
6692
|
+
const currentItems = (await t.manyOrNone(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${itemsTable} WHERE "id" = ANY($1::text[]) AND "datasetId" = $2 AND "validTo" IS NULL AND "isDeleted" = false`, [input.itemIds, input.datasetId])).map((row) => this.transformItemRow(row));
|
|
6660
6693
|
if (currentItems.length === 0) return;
|
|
6661
6694
|
const parentOrganizationId = dataset.organizationId ?? null;
|
|
6662
6695
|
const parentProjectId = dataset.projectId ?? null;
|
|
@@ -6671,8 +6704,8 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6671
6704
|
parentOrganizationId,
|
|
6672
6705
|
parentProjectId,
|
|
6673
6706
|
JSON.stringify(item.input),
|
|
6674
|
-
|
|
6675
|
-
|
|
6707
|
+
jsonDataArg(item.groundTruth),
|
|
6708
|
+
jsonDataArg(item.expectedTrajectory),
|
|
6676
6709
|
jsonbArg(item.toolMocks),
|
|
6677
6710
|
item.unmockedToolPolicy ?? null,
|
|
6678
6711
|
jsonbArg(item.scorerIds),
|
|
@@ -6712,8 +6745,8 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6712
6745
|
schemaName: getSchemaName$5(this.#schema)
|
|
6713
6746
|
});
|
|
6714
6747
|
let result;
|
|
6715
|
-
if (args.datasetVersion !== void 0) result = await client.oneOrNone(`SELECT
|
|
6716
|
-
else result = await client.oneOrNone(`SELECT
|
|
6748
|
+
if (args.datasetVersion !== void 0) result = await client.oneOrNone(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableName} WHERE "id" = $1 AND "datasetVersion" <= $2 AND ("validTo" IS NULL OR "validTo" > $2) AND "isDeleted" = false ORDER BY "datasetVersion" DESC LIMIT 1`, [args.id, args.datasetVersion]);
|
|
6749
|
+
else result = await client.oneOrNone(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableName} WHERE "id" = $1 AND "validTo" IS NULL AND "isDeleted" = false`, [args.id]);
|
|
6717
6750
|
return result ? this.transformItemRow(result) : null;
|
|
6718
6751
|
} catch (error) {
|
|
6719
6752
|
throw new _mastra_core_error.MastraError({
|
|
@@ -6729,7 +6762,7 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6729
6762
|
indexName: _mastra_core_storage.TABLE_DATASET_ITEMS,
|
|
6730
6763
|
schemaName: getSchemaName$5(this.#schema)
|
|
6731
6764
|
});
|
|
6732
|
-
return (await this.#db.readClient.manyOrNone(`SELECT
|
|
6765
|
+
return (await this.#db.readClient.manyOrNone(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableName} WHERE "datasetId" = $1 AND "datasetVersion" <= $2 AND ("validTo" IS NULL OR "validTo" > $3) AND "isDeleted" = false ORDER BY "createdAt" DESC, "id" ASC`, [
|
|
6733
6766
|
datasetId,
|
|
6734
6767
|
version,
|
|
6735
6768
|
version
|
|
@@ -6748,7 +6781,7 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6748
6781
|
indexName: _mastra_core_storage.TABLE_DATASET_ITEMS,
|
|
6749
6782
|
schemaName: getSchemaName$5(this.#schema)
|
|
6750
6783
|
});
|
|
6751
|
-
return (await this.#db.readClient.manyOrNone(`SELECT
|
|
6784
|
+
return (await this.#db.readClient.manyOrNone(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableName} WHERE "id" = $1 ORDER BY "datasetVersion" DESC`, [itemId]) || []).map((row) => this.transformItemRowFull(row));
|
|
6752
6785
|
} catch (error) {
|
|
6753
6786
|
throw new _mastra_core_error.MastraError({
|
|
6754
6787
|
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "GET_ITEM_HISTORY", "FAILED"),
|
|
@@ -6820,7 +6853,7 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6820
6853
|
const { offset, perPage: perPageForResponse } = (0, _mastra_core_storage.calculatePagination)(page, perPageInput, perPage);
|
|
6821
6854
|
const limitValue = perPageInput === false ? total : perPage;
|
|
6822
6855
|
return {
|
|
6823
|
-
items: (await client.manyOrNone(`SELECT
|
|
6856
|
+
items: (await client.manyOrNone(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableName} ${whereClause} ORDER BY "${orderBy.field}" ${orderBy.direction}, "id" ASC LIMIT $${paramIndex} OFFSET $${paramIndex + 1}`, [
|
|
6824
6857
|
...queryParams,
|
|
6825
6858
|
limitValue,
|
|
6826
6859
|
offset
|
|
@@ -7311,7 +7344,7 @@ var ExperimentsPG = class ExperimentsPG extends _mastra_core_storage.Experiments
|
|
|
7311
7344
|
}
|
|
7312
7345
|
if (input.metadata !== void 0) {
|
|
7313
7346
|
setClauses.push(`"metadata" = $${paramIndex++}`);
|
|
7314
|
-
values.push(
|
|
7347
|
+
values.push(toPgJson(input.metadata));
|
|
7315
7348
|
}
|
|
7316
7349
|
if (input.status !== void 0) {
|
|
7317
7350
|
setClauses.push(`"status" = $${paramIndex++}`);
|
|
@@ -7542,19 +7575,19 @@ var ExperimentsPG = class ExperimentsPG extends _mastra_core_storage.Experiments
|
|
|
7542
7575
|
input.itemDatasetVersion ?? null,
|
|
7543
7576
|
input.organizationId ?? null,
|
|
7544
7577
|
input.projectId ?? null,
|
|
7545
|
-
|
|
7546
|
-
purgeMetadata || input.output == null ? null :
|
|
7547
|
-
purgeMetadata || input.groundTruth == null ? null :
|
|
7548
|
-
|
|
7549
|
-
purgeMetadata || input.error == null ? null :
|
|
7578
|
+
toPgJson(purgeMetadata ? null : input.input),
|
|
7579
|
+
purgeMetadata || input.output == null ? null : toPgJson(input.output),
|
|
7580
|
+
purgeMetadata || input.groundTruth == null ? null : toPgJson(input.groundTruth),
|
|
7581
|
+
toPgJson(purgeMetadata ?? input.metadata ?? null),
|
|
7582
|
+
purgeMetadata || input.error == null ? null : toPgJson(input.error),
|
|
7550
7583
|
input.startedAt.toISOString(),
|
|
7551
7584
|
input.completedAt.toISOString(),
|
|
7552
7585
|
input.retryCount,
|
|
7553
7586
|
input.attempt ?? 0,
|
|
7554
7587
|
input.traceId ?? null,
|
|
7555
7588
|
input.status ?? null,
|
|
7556
|
-
purgeMetadata || input.tags == null ? null :
|
|
7557
|
-
purgeMetadata || input.toolMockReport == null ? null :
|
|
7589
|
+
purgeMetadata || input.tags == null ? null : toPgJson(input.tags),
|
|
7590
|
+
purgeMetadata || input.toolMockReport == null ? null : toPgJson(input.toolMockReport),
|
|
7558
7591
|
nowIso
|
|
7559
7592
|
]);
|
|
7560
7593
|
});
|
|
@@ -7600,19 +7633,19 @@ var ExperimentsPG = class ExperimentsPG extends _mastra_core_storage.Experiments
|
|
|
7600
7633
|
input.itemDatasetVersion ?? null,
|
|
7601
7634
|
input.organizationId ?? null,
|
|
7602
7635
|
input.projectId ?? null,
|
|
7603
|
-
|
|
7604
|
-
purgeMetadata || input.output == null ? null :
|
|
7605
|
-
purgeMetadata || input.groundTruth == null ? null :
|
|
7606
|
-
|
|
7607
|
-
purgeMetadata || input.error == null ? null :
|
|
7636
|
+
toPgJson(purgeMetadata ? null : input.input),
|
|
7637
|
+
purgeMetadata || input.output == null ? null : toPgJson(input.output),
|
|
7638
|
+
purgeMetadata || input.groundTruth == null ? null : toPgJson(input.groundTruth),
|
|
7639
|
+
toPgJson(purgeMetadata ?? input.metadata ?? null),
|
|
7640
|
+
purgeMetadata || input.error == null ? null : toPgJson(input.error),
|
|
7608
7641
|
input.startedAt.toISOString(),
|
|
7609
7642
|
input.completedAt.toISOString(),
|
|
7610
7643
|
input.retryCount,
|
|
7611
7644
|
attempt,
|
|
7612
7645
|
input.traceId ?? null,
|
|
7613
7646
|
input.status ?? null,
|
|
7614
|
-
purgeMetadata || input.tags == null ? null :
|
|
7615
|
-
purgeMetadata || input.toolMockReport == null ? null :
|
|
7647
|
+
purgeMetadata || input.tags == null ? null : toPgJson(input.tags),
|
|
7648
|
+
purgeMetadata || input.toolMockReport == null ? null : toPgJson(input.toolMockReport),
|
|
7616
7649
|
(/* @__PURE__ */ new Date()).toISOString()
|
|
7617
7650
|
]);
|
|
7618
7651
|
}
|
|
@@ -7626,19 +7659,19 @@ var ExperimentsPG = class ExperimentsPG extends _mastra_core_storage.Experiments
|
|
|
7626
7659
|
input.itemDatasetVersion ?? null,
|
|
7627
7660
|
input.organizationId ?? null,
|
|
7628
7661
|
input.projectId ?? null,
|
|
7629
|
-
|
|
7630
|
-
purgeMetadata || input.output == null ? null :
|
|
7631
|
-
purgeMetadata || input.groundTruth == null ? null :
|
|
7632
|
-
|
|
7633
|
-
purgeMetadata || input.error == null ? null :
|
|
7662
|
+
toPgJson(purgeMetadata ? null : input.input),
|
|
7663
|
+
purgeMetadata || input.output == null ? null : toPgJson(input.output),
|
|
7664
|
+
purgeMetadata || input.groundTruth == null ? null : toPgJson(input.groundTruth),
|
|
7665
|
+
toPgJson(purgeMetadata ?? input.metadata ?? null),
|
|
7666
|
+
purgeMetadata || input.error == null ? null : toPgJson(input.error),
|
|
7634
7667
|
input.startedAt.toISOString(),
|
|
7635
7668
|
input.completedAt.toISOString(),
|
|
7636
7669
|
input.retryCount,
|
|
7637
7670
|
attempt,
|
|
7638
7671
|
input.traceId ?? null,
|
|
7639
7672
|
input.status ?? null,
|
|
7640
|
-
purgeMetadata || input.tags == null ? null :
|
|
7641
|
-
purgeMetadata || input.toolMockReport == null ? null :
|
|
7673
|
+
purgeMetadata || input.tags == null ? null : toPgJson(input.tags),
|
|
7674
|
+
purgeMetadata || input.toolMockReport == null ? null : toPgJson(input.toolMockReport)
|
|
7642
7675
|
]);
|
|
7643
7676
|
});
|
|
7644
7677
|
return this.transformExperimentResultRow(row);
|
|
@@ -7678,7 +7711,7 @@ var ExperimentsPG = class ExperimentsPG extends _mastra_core_storage.Experiments
|
|
|
7678
7711
|
input.status ?? null,
|
|
7679
7712
|
Boolean(purgeMetadata),
|
|
7680
7713
|
input.tags !== void 0,
|
|
7681
|
-
input.tags === void 0 ? null :
|
|
7714
|
+
input.tags === void 0 ? null : toPgJson(input.tags),
|
|
7682
7715
|
input.comment !== void 0,
|
|
7683
7716
|
input.comment ?? null,
|
|
7684
7717
|
...input.experimentId !== void 0 ? [input.experimentId] : []
|
|
@@ -7749,7 +7782,7 @@ var ExperimentsPG = class ExperimentsPG extends _mastra_core_storage.Experiments
|
|
|
7749
7782
|
}
|
|
7750
7783
|
for (const tag of args.tags ?? []) {
|
|
7751
7784
|
conditions.push(`"tags" @> $${paramIndex++}::jsonb`);
|
|
7752
|
-
queryParams.push(
|
|
7785
|
+
queryParams.push(toPgJson([tag]));
|
|
7753
7786
|
}
|
|
7754
7787
|
if (args.filters) {
|
|
7755
7788
|
const { organizationId, projectId } = args.filters;
|
|
@@ -8676,6 +8709,7 @@ var KnowledgePG = class extends _mastra_core_storage.KnowledgeStorage {
|
|
|
8676
8709
|
return this.#transaction(async (tx) => {
|
|
8677
8710
|
const parent = await this.#resolveTerminalNode(tx, nodeReferenceId(input.node));
|
|
8678
8711
|
if (!parent) throw new _mastra_core_storage.KnowledgeNotFoundError("node", nodeReferenceId(input.node));
|
|
8712
|
+
const metadataJson = input.metadata ? toPgJson(input.metadata) : null;
|
|
8679
8713
|
const record = {
|
|
8680
8714
|
id: input.id ?? (0, _mastra_core_storage.createKnowledgeUlid)(),
|
|
8681
8715
|
node: parent.id,
|
|
@@ -8699,13 +8733,16 @@ var KnowledgePG = class extends _mastra_core_storage.KnowledgeStorage {
|
|
|
8699
8733
|
record.capturedAt.toISOString(),
|
|
8700
8734
|
record.when?.toISOString() ?? null,
|
|
8701
8735
|
record.maxScope ?? null,
|
|
8702
|
-
|
|
8736
|
+
metadataJson
|
|
8703
8737
|
]
|
|
8704
8738
|
});
|
|
8705
8739
|
await this.#replaceMentions(tx, "record", record.id, record.text, resolutionScope, defaultScope);
|
|
8706
8740
|
await this.#activity(tx, "record-created", "record", record.id, scope, record.sourceThreadId);
|
|
8707
8741
|
await this.#outbox(tx, "record", record.id, "upsert", record.id, scope);
|
|
8708
|
-
return
|
|
8742
|
+
return metadataJson ? {
|
|
8743
|
+
...record,
|
|
8744
|
+
metadata: JSON.parse(metadataJson)
|
|
8745
|
+
} : record;
|
|
8709
8746
|
});
|
|
8710
8747
|
}
|
|
8711
8748
|
async getKnowledge(input) {
|
|
@@ -9274,6 +9311,7 @@ var MCPClientsPG = class MCPClientsPG extends _mastra_core_storage.MCPClientsSto
|
|
|
9274
9311
|
});
|
|
9275
9312
|
const now = /* @__PURE__ */ new Date();
|
|
9276
9313
|
const nowIso = now.toISOString();
|
|
9314
|
+
const metadataJson = mcpClient.metadata ? toPgJson(mcpClient.metadata) : null;
|
|
9277
9315
|
await this.#db.client.none(`INSERT INTO ${tableName} (
|
|
9278
9316
|
id, status, "activeVersionId", "authorId", metadata,
|
|
9279
9317
|
"createdAt", "createdAtZ", "updatedAt", "updatedAtZ"
|
|
@@ -9282,7 +9320,7 @@ var MCPClientsPG = class MCPClientsPG extends _mastra_core_storage.MCPClientsSto
|
|
|
9282
9320
|
"draft",
|
|
9283
9321
|
null,
|
|
9284
9322
|
mcpClient.authorId ?? null,
|
|
9285
|
-
|
|
9323
|
+
metadataJson,
|
|
9286
9324
|
nowIso,
|
|
9287
9325
|
nowIso,
|
|
9288
9326
|
nowIso,
|
|
@@ -9303,7 +9341,7 @@ var MCPClientsPG = class MCPClientsPG extends _mastra_core_storage.MCPClientsSto
|
|
|
9303
9341
|
status: "draft",
|
|
9304
9342
|
activeVersionId: void 0,
|
|
9305
9343
|
authorId: mcpClient.authorId,
|
|
9306
|
-
metadata: mcpClient.metadata,
|
|
9344
|
+
metadata: metadataJson ? JSON.parse(metadataJson) : mcpClient.metadata,
|
|
9307
9345
|
createdAt: now,
|
|
9308
9346
|
updatedAt: now
|
|
9309
9347
|
};
|
|
@@ -9361,7 +9399,7 @@ var MCPClientsPG = class MCPClientsPG extends _mastra_core_storage.MCPClientsSto
|
|
|
9361
9399
|
...metadata
|
|
9362
9400
|
};
|
|
9363
9401
|
setClauses.push(`metadata = $${paramIndex++}`);
|
|
9364
|
-
values.push(
|
|
9402
|
+
values.push(toPgJson(mergedMetadata));
|
|
9365
9403
|
}
|
|
9366
9404
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
9367
9405
|
setClauses.push(`"updatedAt" = $${paramIndex++}`);
|
|
@@ -9434,7 +9472,7 @@ var MCPClientsPG = class MCPClientsPG extends _mastra_core_storage.MCPClientsSto
|
|
|
9434
9472
|
}
|
|
9435
9473
|
if (metadata && Object.keys(metadata).length > 0) {
|
|
9436
9474
|
conditions.push(`metadata @> $${paramIdx++}::jsonb`);
|
|
9437
|
-
queryParams.push(
|
|
9475
|
+
queryParams.push(toPgJson(metadata));
|
|
9438
9476
|
}
|
|
9439
9477
|
const whereClause = `WHERE ${conditions.join(" AND ")}`;
|
|
9440
9478
|
const countResult = await this.#db.readClient.one(`SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`, queryParams);
|
|
@@ -9485,6 +9523,8 @@ var MCPClientsPG = class MCPClientsPG extends _mastra_core_storage.MCPClientsSto
|
|
|
9485
9523
|
});
|
|
9486
9524
|
const now = /* @__PURE__ */ new Date();
|
|
9487
9525
|
const nowIso = now.toISOString();
|
|
9526
|
+
const serversJson = toPgJson(input.servers);
|
|
9527
|
+
const changedFieldsJson = input.changedFields ? toPgJson(input.changedFields) : null;
|
|
9488
9528
|
await this.#db.client.none(`INSERT INTO ${tableName} (
|
|
9489
9529
|
id, "mcpClientId", "versionNumber",
|
|
9490
9530
|
name, description, servers,
|
|
@@ -9496,14 +9536,16 @@ var MCPClientsPG = class MCPClientsPG extends _mastra_core_storage.MCPClientsSto
|
|
|
9496
9536
|
input.versionNumber,
|
|
9497
9537
|
input.name,
|
|
9498
9538
|
input.description ?? null,
|
|
9499
|
-
|
|
9500
|
-
|
|
9539
|
+
serversJson,
|
|
9540
|
+
changedFieldsJson,
|
|
9501
9541
|
input.changeMessage ?? null,
|
|
9502
9542
|
nowIso,
|
|
9503
9543
|
nowIso
|
|
9504
9544
|
]);
|
|
9505
9545
|
return {
|
|
9506
9546
|
...input,
|
|
9547
|
+
servers: JSON.parse(serversJson),
|
|
9548
|
+
changedFields: changedFieldsJson ? JSON.parse(changedFieldsJson) : input.changedFields,
|
|
9507
9549
|
createdAt: now
|
|
9508
9550
|
};
|
|
9509
9551
|
} catch (error) {
|
|
@@ -9845,7 +9887,7 @@ var MCPServersPG = class MCPServersPG extends _mastra_core_storage.MCPServersSto
|
|
|
9845
9887
|
"draft",
|
|
9846
9888
|
null,
|
|
9847
9889
|
mcpServer.authorId ?? null,
|
|
9848
|
-
mcpServer.metadata ?
|
|
9890
|
+
mcpServer.metadata ? toPgJson(mcpServer.metadata) : null,
|
|
9849
9891
|
nowIso,
|
|
9850
9892
|
nowIso,
|
|
9851
9893
|
nowIso,
|
|
@@ -9924,7 +9966,7 @@ var MCPServersPG = class MCPServersPG extends _mastra_core_storage.MCPServersSto
|
|
|
9924
9966
|
...metadata
|
|
9925
9967
|
};
|
|
9926
9968
|
setClauses.push(`metadata = $${paramIndex++}`);
|
|
9927
|
-
values.push(
|
|
9969
|
+
values.push(toPgJson(mergedMetadata));
|
|
9928
9970
|
}
|
|
9929
9971
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
9930
9972
|
setClauses.push(`"updatedAt" = $${paramIndex++}`);
|
|
@@ -9997,7 +10039,7 @@ var MCPServersPG = class MCPServersPG extends _mastra_core_storage.MCPServersSto
|
|
|
9997
10039
|
}
|
|
9998
10040
|
if (metadata && Object.keys(metadata).length > 0) {
|
|
9999
10041
|
conditions.push(`metadata @> $${paramIdx++}::jsonb`);
|
|
10000
|
-
queryParams.push(
|
|
10042
|
+
queryParams.push(toPgJson(metadata));
|
|
10001
10043
|
}
|
|
10002
10044
|
const whereClause = `WHERE ${conditions.join(" AND ")}`;
|
|
10003
10045
|
const countResult = await this.#db.readClient.one(`SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`, queryParams);
|
|
@@ -10063,14 +10105,14 @@ var MCPServersPG = class MCPServersPG extends _mastra_core_storage.MCPServersSto
|
|
|
10063
10105
|
input.version,
|
|
10064
10106
|
input.description ?? null,
|
|
10065
10107
|
input.instructions ?? null,
|
|
10066
|
-
input.repository ?
|
|
10108
|
+
input.repository ? toPgJson(input.repository) : null,
|
|
10067
10109
|
input.releaseDate ?? null,
|
|
10068
10110
|
input.isLatest ?? null,
|
|
10069
10111
|
input.packageCanonical ?? null,
|
|
10070
|
-
input.tools ?
|
|
10071
|
-
input.agents ?
|
|
10072
|
-
input.workflows ?
|
|
10073
|
-
input.changedFields ?
|
|
10112
|
+
input.tools ? toPgJson(input.tools) : null,
|
|
10113
|
+
input.agents ? toPgJson(input.agents) : null,
|
|
10114
|
+
input.workflows ? toPgJson(input.workflows) : null,
|
|
10115
|
+
input.changedFields ? toPgJson(input.changedFields) : null,
|
|
10074
10116
|
input.changeMessage ?? null,
|
|
10075
10117
|
nowIso,
|
|
10076
10118
|
nowIso
|
|
@@ -10805,7 +10847,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
10805
10847
|
}
|
|
10806
10848
|
if (filter?.metadata && Object.keys(filter.metadata).length > 0) for (const [key, value] of Object.entries(filter.metadata)) {
|
|
10807
10849
|
whereClauses.push(`metadata::jsonb @> $${paramIndex}::jsonb`);
|
|
10808
|
-
queryParams.push(
|
|
10850
|
+
queryParams.push(toPgJson({ [key]: value }));
|
|
10809
10851
|
paramIndex++;
|
|
10810
10852
|
}
|
|
10811
10853
|
const baseQuery = `FROM ${tableName} ${whereClauses.length > 0 ? `WHERE ${whereClauses.join(" AND ")}` : ""}`;
|
|
@@ -10864,6 +10906,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
10864
10906
|
});
|
|
10865
10907
|
const createdAt = toUtcISOString(thread.createdAt);
|
|
10866
10908
|
const updatedAt = toUtcISOString(thread.updatedAt);
|
|
10909
|
+
const metadataJson = thread.metadata ? toPgJson(thread.metadata) : null;
|
|
10867
10910
|
await this.#db.client.none(`INSERT INTO ${tableName} (
|
|
10868
10911
|
id,
|
|
10869
10912
|
"resourceId",
|
|
@@ -10885,13 +10928,16 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
10885
10928
|
thread.id,
|
|
10886
10929
|
thread.resourceId,
|
|
10887
10930
|
thread.title,
|
|
10888
|
-
|
|
10931
|
+
metadataJson,
|
|
10889
10932
|
createdAt,
|
|
10890
10933
|
createdAt,
|
|
10891
10934
|
updatedAt,
|
|
10892
10935
|
updatedAt
|
|
10893
10936
|
]);
|
|
10894
|
-
return
|
|
10937
|
+
return {
|
|
10938
|
+
...thread,
|
|
10939
|
+
metadata: metadataJson ? JSON.parse(metadataJson) : thread.metadata
|
|
10940
|
+
};
|
|
10895
10941
|
} catch (error) {
|
|
10896
10942
|
throw new _mastra_core_error.MastraError({
|
|
10897
10943
|
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "SAVE_THREAD", "FAILED"),
|
|
@@ -11707,16 +11753,20 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
11707
11753
|
async saveResource({ resource }) {
|
|
11708
11754
|
const createdAt = toUtcISOString(resource.createdAt);
|
|
11709
11755
|
const updatedAt = toUtcISOString(resource.updatedAt);
|
|
11756
|
+
const metadataJson = toPgJson(resource.metadata);
|
|
11710
11757
|
await this.#db.insert({
|
|
11711
11758
|
tableName: _mastra_core_storage.TABLE_RESOURCES,
|
|
11712
11759
|
record: {
|
|
11713
11760
|
...resource,
|
|
11714
|
-
metadata:
|
|
11761
|
+
metadata: metadataJson,
|
|
11715
11762
|
createdAt,
|
|
11716
11763
|
updatedAt
|
|
11717
11764
|
}
|
|
11718
11765
|
});
|
|
11719
|
-
return
|
|
11766
|
+
return {
|
|
11767
|
+
...resource,
|
|
11768
|
+
metadata: metadataJson ? JSON.parse(metadataJson) : resource.metadata
|
|
11769
|
+
};
|
|
11720
11770
|
}
|
|
11721
11771
|
async updateResource({ resourceId, workingMemory, metadata }) {
|
|
11722
11772
|
const existingResource = await this.#getResourceById(this.#db.client, resourceId);
|
|
@@ -11751,9 +11801,11 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
11751
11801
|
values.push(workingMemory);
|
|
11752
11802
|
paramIndex++;
|
|
11753
11803
|
}
|
|
11804
|
+
let metadataJson;
|
|
11754
11805
|
if (metadata) {
|
|
11806
|
+
metadataJson = toPgJson(updatedResource.metadata);
|
|
11755
11807
|
updates.push(`metadata = $${paramIndex}`);
|
|
11756
|
-
values.push(
|
|
11808
|
+
values.push(metadataJson);
|
|
11757
11809
|
paramIndex++;
|
|
11758
11810
|
}
|
|
11759
11811
|
const updatedAtStr = updatedResource.updatedAt.toISOString();
|
|
@@ -11763,7 +11815,10 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
11763
11815
|
values.push(updatedAtStr);
|
|
11764
11816
|
values.push(resourceId);
|
|
11765
11817
|
await this.#db.client.none(`UPDATE ${tableName} SET ${updates.join(", ")} WHERE id = $${paramIndex}`, values);
|
|
11766
|
-
return
|
|
11818
|
+
return metadataJson ? {
|
|
11819
|
+
...updatedResource,
|
|
11820
|
+
metadata: JSON.parse(metadataJson)
|
|
11821
|
+
} : updatedResource;
|
|
11767
11822
|
}
|
|
11768
11823
|
async copyThread(args) {
|
|
11769
11824
|
const { sourceThreadId, newThreadId: providedThreadId, resourceId, title, metadata, options } = args;
|
|
@@ -11848,7 +11903,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
11848
11903
|
newThread.id,
|
|
11849
11904
|
newThread.resourceId,
|
|
11850
11905
|
newThread.title,
|
|
11851
|
-
newThread.metadata ?
|
|
11906
|
+
newThread.metadata ? toPgJson(newThread.metadata) : null,
|
|
11852
11907
|
nowStr,
|
|
11853
11908
|
nowStr,
|
|
11854
11909
|
nowStr,
|
|
@@ -12039,7 +12094,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12039
12094
|
"",
|
|
12040
12095
|
null,
|
|
12041
12096
|
"initial",
|
|
12042
|
-
|
|
12097
|
+
toPgJson(input.config),
|
|
12043
12098
|
0,
|
|
12044
12099
|
null,
|
|
12045
12100
|
null,
|
|
@@ -12102,7 +12157,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12102
12157
|
record.activeObservations || "",
|
|
12103
12158
|
null,
|
|
12104
12159
|
record.originType || "initial",
|
|
12105
|
-
record.config ?
|
|
12160
|
+
record.config ? toPgJson(record.config) : null,
|
|
12106
12161
|
record.generationCount || 0,
|
|
12107
12162
|
lastObservedAtStr,
|
|
12108
12163
|
lastObservedAtStr,
|
|
@@ -12111,8 +12166,8 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12111
12166
|
record.pendingMessageTokens || 0,
|
|
12112
12167
|
record.totalTokensObserved || 0,
|
|
12113
12168
|
record.observationTokenCount || 0,
|
|
12114
|
-
record.observedMessageIds ?
|
|
12115
|
-
record.bufferedObservationChunks ?
|
|
12169
|
+
record.observedMessageIds ? toPgJson(record.observedMessageIds) : null,
|
|
12170
|
+
record.bufferedObservationChunks ? toPgJson(record.bufferedObservationChunks) : null,
|
|
12116
12171
|
record.bufferedReflection || null,
|
|
12117
12172
|
record.bufferedReflectionTokens ?? null,
|
|
12118
12173
|
record.bufferedReflectionInputTokens ?? null,
|
|
@@ -12124,7 +12179,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12124
12179
|
record.lastBufferedAtTokens || 0,
|
|
12125
12180
|
lastBufferedAtTimeStr,
|
|
12126
12181
|
record.observedTimezone || null,
|
|
12127
|
-
record.metadata ?
|
|
12182
|
+
record.metadata ? toPgJson(record.metadata) : null,
|
|
12128
12183
|
record.createdAt.toISOString(),
|
|
12129
12184
|
record.createdAt.toISOString(),
|
|
12130
12185
|
record.updatedAt.toISOString(),
|
|
@@ -12152,7 +12207,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12152
12207
|
});
|
|
12153
12208
|
const lastObservedAtStr = input.lastObservedAt.toISOString();
|
|
12154
12209
|
const nowStr = now.toISOString();
|
|
12155
|
-
const observedMessageIdsJson = input.observedMessageIds ?
|
|
12210
|
+
const observedMessageIdsJson = input.observedMessageIds ? toPgJson(input.observedMessageIds) : null;
|
|
12156
12211
|
if ((await this.#db.client.query(`UPDATE ${tableName} SET
|
|
12157
12212
|
"activeObservations" = $1,
|
|
12158
12213
|
"lastObservedAt" = $2,
|
|
@@ -12241,7 +12296,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12241
12296
|
input.reflection,
|
|
12242
12297
|
null,
|
|
12243
12298
|
"reflection",
|
|
12244
|
-
|
|
12299
|
+
toPgJson(record.config),
|
|
12245
12300
|
input.currentRecord.generationCount + 1,
|
|
12246
12301
|
lastObservedAtStr,
|
|
12247
12302
|
lastObservedAtStr,
|
|
@@ -12257,7 +12312,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12257
12312
|
0,
|
|
12258
12313
|
null,
|
|
12259
12314
|
record.observedTimezone || null,
|
|
12260
|
-
record.metadata ?
|
|
12315
|
+
record.metadata ? toPgJson(record.metadata) : null,
|
|
12261
12316
|
nowStr,
|
|
12262
12317
|
nowStr,
|
|
12263
12318
|
nowStr,
|
|
@@ -12508,7 +12563,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12508
12563
|
const merged = this.deepMergeConfig(existing, input.config);
|
|
12509
12564
|
const nowStr = (/* @__PURE__ */ new Date()).toISOString();
|
|
12510
12565
|
await this.#db.client.query(`UPDATE ${tableName} SET config = $1, "updatedAt" = $2, "updatedAtZ" = $3 WHERE id = $4`, [
|
|
12511
|
-
|
|
12566
|
+
toPgJson(merged),
|
|
12512
12567
|
nowStr,
|
|
12513
12568
|
nowStr,
|
|
12514
12569
|
input.id
|
|
@@ -12559,7 +12614,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12559
12614
|
"updatedAt" = $4,
|
|
12560
12615
|
"updatedAtZ" = $5
|
|
12561
12616
|
WHERE id = $6`, [
|
|
12562
|
-
|
|
12617
|
+
toPgJson([newChunk]),
|
|
12563
12618
|
input.chunk.cycleId,
|
|
12564
12619
|
lastBufferedAtTime,
|
|
12565
12620
|
nowStr,
|
|
@@ -12674,7 +12729,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12674
12729
|
activatedContent,
|
|
12675
12730
|
activatedTokens,
|
|
12676
12731
|
activatedMessageTokens,
|
|
12677
|
-
remainingChunks.length > 0 ?
|
|
12732
|
+
remainingChunks.length > 0 ? toPgJson(remainingChunks) : null,
|
|
12678
12733
|
lastObservedAtStr,
|
|
12679
12734
|
lastObservedAtStr,
|
|
12680
12735
|
nowStr,
|
|
@@ -13054,7 +13109,7 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
|
|
|
13054
13109
|
});
|
|
13055
13110
|
const setColumns = entries.map(([key], index) => `"${(0, _mastra_core_utils.parseSqlIdentifier)(key, "column name")}" = $${index + 1}`);
|
|
13056
13111
|
const values = entries.map(([key, value]) => {
|
|
13057
|
-
if (_mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_NOTIFICATIONS][key]?.type === "jsonb" && value !== null) return
|
|
13112
|
+
if (_mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_NOTIFICATIONS][key]?.type === "jsonb" && value !== null) return toPgJson(value);
|
|
13058
13113
|
return value;
|
|
13059
13114
|
});
|
|
13060
13115
|
await this.#db.client.none(`UPDATE ${tableName} SET ${setColumns.join(", ")} WHERE "threadId" = $${values.length + 1} AND "id" = $${values.length + 2}`, [
|
|
@@ -13775,15 +13830,15 @@ var ObservabilityPG = class ObservabilityPG extends _mastra_core_storage.Observa
|
|
|
13775
13830
|
}
|
|
13776
13831
|
if (filters.scope != null) {
|
|
13777
13832
|
conditions.push(`r."scope" @> $${paramIndex++}`);
|
|
13778
|
-
params.push(
|
|
13833
|
+
params.push(toPgJson(filters.scope));
|
|
13779
13834
|
}
|
|
13780
13835
|
if (filters.metadata != null) {
|
|
13781
13836
|
conditions.push(`r."metadata" @> $${paramIndex++}`);
|
|
13782
|
-
params.push(
|
|
13837
|
+
params.push(toPgJson(filters.metadata));
|
|
13783
13838
|
}
|
|
13784
13839
|
if (filters.tags != null && filters.tags.length > 0) {
|
|
13785
13840
|
conditions.push(`r."tags" @> $${paramIndex++}`);
|
|
13786
|
-
params.push(
|
|
13841
|
+
params.push(toPgJson(filters.tags));
|
|
13787
13842
|
}
|
|
13788
13843
|
if (filters.status !== void 0) switch (filters.status) {
|
|
13789
13844
|
case _mastra_core_storage.TraceStatus.ERROR:
|
|
@@ -15092,7 +15147,7 @@ async function upsertCache(client, schema, cacheKey, values) {
|
|
|
15092
15147
|
VALUES ($1, NOW(), $2::jsonb)
|
|
15093
15148
|
ON CONFLICT ("cacheKey") DO UPDATE SET
|
|
15094
15149
|
"refreshedAt" = EXCLUDED."refreshedAt",
|
|
15095
|
-
"values" = EXCLUDED."values"`, [cacheKey,
|
|
15150
|
+
"values" = EXCLUDED."values"`, [cacheKey, toPgJson(values)]);
|
|
15096
15151
|
}
|
|
15097
15152
|
/**
|
|
15098
15153
|
* Time predicate that bounds a discovery refresh to recent events.
|
|
@@ -16046,20 +16101,6 @@ const COMPLEX_GROUP_BY_EXCLUDED = /* @__PURE__ */ new Set([
|
|
|
16046
16101
|
"requestContext"
|
|
16047
16102
|
]);
|
|
16048
16103
|
//#endregion
|
|
16049
|
-
//#region src/storage/db/sanitize-json.ts
|
|
16050
|
-
/**
|
|
16051
|
-
* Sanitizes JSON string for PostgreSQL jsonb:
|
|
16052
|
-
* - Removes problematic Unicode sequences:
|
|
16053
|
-
* - \u0000 (null character) - causes error 22P05 "unsupported Unicode escape sequence"
|
|
16054
|
-
* - \uD800-\uDFFF (unpaired surrogates) - causes "Unicode low surrogate must follow a high surrogate"
|
|
16055
|
-
* - \\uD800 (escaped-backslash + surrogate, e.g. from JS regex literals like [^\ud800-\udfff]):
|
|
16056
|
-
* removing just \uXXXX would leave a dangling backslash that creates a new invalid escape (e.g. \-)
|
|
16057
|
-
* - Escapes any remaining invalid JSON escape sequences (e.g. \v, \k, \-)
|
|
16058
|
-
*/
|
|
16059
|
-
function sanitizeJsonForPg(jsonString) {
|
|
16060
|
-
return jsonString.replace(/\\\\?u(0000|[Dd][89A-Fa-f][0-9A-Fa-f]{2})/g, "").replace(/(^|[^\\])(\\(?!["\\/bfnrtu]))/g, "$1\\\\");
|
|
16061
|
-
}
|
|
16062
|
-
//#endregion
|
|
16063
16104
|
//#region src/storage/domains/observability/v-next/sql.ts
|
|
16064
16105
|
/**
|
|
16065
16106
|
* SQL helpers for the v-next Postgres observability domain.
|
|
@@ -16081,7 +16122,7 @@ function sanitizeJsonForPg(jsonString) {
|
|
|
16081
16122
|
*/
|
|
16082
16123
|
function encodeJsonb(value) {
|
|
16083
16124
|
if (value === null || value === void 0) return null;
|
|
16084
|
-
return
|
|
16125
|
+
return toPgJson(value);
|
|
16085
16126
|
}
|
|
16086
16127
|
/**
|
|
16087
16128
|
* Build a multi-row INSERT with explicit column types and ON CONFLICT DO NOTHING.
|
|
@@ -16482,7 +16523,7 @@ function applyMetricFilters(acc, filters) {
|
|
|
16482
16523
|
applySingleOrArrayFilter(acc, "costUnit", filters?.costUnit);
|
|
16483
16524
|
if (filters?.labels) {
|
|
16484
16525
|
acc.conditions.push(`"labels" @> $${acc.next++}::jsonb`);
|
|
16485
|
-
acc.params.push(
|
|
16526
|
+
acc.params.push(toPgJson(filters.labels));
|
|
16486
16527
|
}
|
|
16487
16528
|
}
|
|
16488
16529
|
/** Additional WHERE for metric-name restriction (OLAP queries take a `name` array). */
|
|
@@ -16995,7 +17036,7 @@ function applyScoreFilters(acc, filters) {
|
|
|
16995
17036
|
}
|
|
16996
17037
|
if (filters?.metadata && Object.keys(filters.metadata).length > 0) for (const [key, value] of Object.entries(filters.metadata)) {
|
|
16997
17038
|
acc.conditions.push(`"metadata"->($${acc.next++}::text) = $${acc.next++}::jsonb`);
|
|
16998
|
-
acc.params.push(key,
|
|
17039
|
+
acc.params.push(key, toPgJson(value ?? null));
|
|
16999
17040
|
}
|
|
17000
17041
|
}
|
|
17001
17042
|
/** OLAP queries take an explicit scorerId / scoreSource pair as identity. */
|
|
@@ -17261,16 +17302,21 @@ async function getScorePercentiles(client, schema, args) {
|
|
|
17261
17302
|
//#endregion
|
|
17262
17303
|
//#region src/storage/domains/observability/v-next/trace-query.ts
|
|
17263
17304
|
const TRACE_STATUS_SQL = `CASE WHEN r."error" IS NOT NULL THEN 'error' ELSE 'success' END`;
|
|
17305
|
+
function durationMsSql(startedAt, endedAt) {
|
|
17306
|
+
return `EXTRACT(EPOCH FROM (${endedAt} - ${startedAt}))::numeric * 1000`;
|
|
17307
|
+
}
|
|
17264
17308
|
const TRACE_FIELDS = {
|
|
17265
17309
|
traceId: "r.\"traceId\"",
|
|
17266
17310
|
threadId: "r.\"threadId\"",
|
|
17267
17311
|
resourceId: "r.\"resourceId\"",
|
|
17268
17312
|
startedAt: "r.\"startedAt\"",
|
|
17269
17313
|
endedAt: "r.\"endedAt\"",
|
|
17314
|
+
durationMs: durationMsSql("r.\"startedAt\"", "r.\"endedAt\""),
|
|
17270
17315
|
entityName: "r.\"entityName\"",
|
|
17271
17316
|
entityType: "r.\"entityType\"",
|
|
17272
17317
|
environment: "r.\"environment\"",
|
|
17273
|
-
status: TRACE_STATUS_SQL
|
|
17318
|
+
status: TRACE_STATUS_SQL,
|
|
17319
|
+
tags: "r.\"tags\""
|
|
17274
17320
|
};
|
|
17275
17321
|
const SPAN_FIELDS = {
|
|
17276
17322
|
name: "s.\"name\"",
|
|
@@ -17372,6 +17418,19 @@ function compileScalarPredicate(predicate, registry, parameterOffset, allowMetad
|
|
|
17372
17418
|
sql: `${field} IS ${predicate.operator === "exists" ? "NOT " : ""}NULL`,
|
|
17373
17419
|
values: fieldValues
|
|
17374
17420
|
};
|
|
17421
|
+
if (predicate.type === "collection") {
|
|
17422
|
+
if (predicate.operator === "includes" || predicate.operator === "notIncludes") {
|
|
17423
|
+
const contains = `${field} @> ARRAY[$${parameterOffset}]::text[]`;
|
|
17424
|
+
return {
|
|
17425
|
+
sql: predicate.operator === "includes" ? contains : `cardinality(${field}) > 0 AND NOT (${contains})`,
|
|
17426
|
+
values: [...fieldValues, predicate.value]
|
|
17427
|
+
};
|
|
17428
|
+
}
|
|
17429
|
+
return {
|
|
17430
|
+
sql: `cardinality(${field}) ${predicate.operator === "empty" ? "=" : ">"} 0`,
|
|
17431
|
+
values: fieldValues
|
|
17432
|
+
};
|
|
17433
|
+
}
|
|
17375
17434
|
if (predicate.type === "membership") {
|
|
17376
17435
|
const list = placeholders(predicate.values, parameterOffset);
|
|
17377
17436
|
if (predicate.operator === "in") return {
|
|
@@ -17425,6 +17484,7 @@ function compileFeedbackScalarPredicate(predicate, parameterOffset) {
|
|
|
17425
17484
|
};
|
|
17426
17485
|
}
|
|
17427
17486
|
if (predicate.field !== "value") return compileScalarPredicate(predicate, FEEDBACK_FIELDS, parameterOffset);
|
|
17487
|
+
if (predicate.type === "collection") throw new Error(`Unsupported trusted trace-query field: ${predicate.field}`);
|
|
17428
17488
|
if (predicate.type === "presence") {
|
|
17429
17489
|
const present = `(s."valueString" IS NOT NULL OR s."valueNumber" IS NOT NULL)`;
|
|
17430
17490
|
return {
|
|
@@ -17580,7 +17640,7 @@ function compilePostgresTraceScope(schema, selection, relationCollections, scope
|
|
|
17580
17640
|
CASE WHEN s."isPending" THEN NULL ELSE s."endedAt" END AS "endedAt",
|
|
17581
17641
|
CASE
|
|
17582
17642
|
WHEN s."isPending" THEN NULL
|
|
17583
|
-
ELSE
|
|
17643
|
+
ELSE ${durationMsSql("s.\"startedAt\"", "s.\"endedAt\"")}
|
|
17584
17644
|
END AS "durationMs",
|
|
17585
17645
|
CASE WHEN s."error" IS NOT NULL THEN 'error' ELSE 'success' END AS "status",
|
|
17586
17646
|
s."error",
|
|
@@ -17808,22 +17868,23 @@ LIMIT $${values.length}`,
|
|
|
17808
17868
|
}
|
|
17809
17869
|
function compilePostgresTraceQueryValues(schema, plan) {
|
|
17810
17870
|
const { ctes, values } = compilePostgresTraceScope(schema, plan, discoveryCollections(plan.predicateScope), plan.scope);
|
|
17811
|
-
let
|
|
17812
|
-
if (plan.predicateScope === "trace" && plan.path.
|
|
17871
|
+
let extracted;
|
|
17872
|
+
if (plan.predicateScope === "trace" && plan.path === "tags") extracted = `SELECT value FROM (SELECT DISTINCT r."traceId", UNNEST(r."tags") AS value FROM root_scope r) t`;
|
|
17873
|
+
else if (plan.predicateScope === "trace" && plan.path.startsWith("metadata.")) {
|
|
17813
17874
|
const keyParameter = `$${values.length + 1}`;
|
|
17814
|
-
|
|
17875
|
+
extracted = `SELECT COALESCE(
|
|
17815
17876
|
CASE WHEN jsonb_typeof(r."metadataSearch" -> ${keyParameter}) = 'string' THEN r."metadataSearch" ->> ${keyParameter} END,
|
|
17816
17877
|
CASE WHEN jsonb_typeof(r."metadataRaw" -> ${keyParameter}) = 'string' THEN NULLIF(btrim(r."metadataRaw" ->> ${keyParameter}), '') END
|
|
17817
|
-
)`;
|
|
17878
|
+
)::text AS value FROM root_scope r`;
|
|
17818
17879
|
values.push(plan.path.slice(9));
|
|
17819
|
-
} else
|
|
17880
|
+
} else extracted = `SELECT ${fieldSql(discoveryRegistry(plan.predicateScope), plan.path)}::text AS value FROM ${discoverySource(plan.predicateScope)}`;
|
|
17820
17881
|
const searchParameter = values.length + 1;
|
|
17821
17882
|
const search = plan.search ? `AND strpos(lower(value), lower($${searchParameter})) > 0` : "";
|
|
17822
17883
|
if (plan.search) values.push(plan.search);
|
|
17823
17884
|
values.push(plan.limit + 1);
|
|
17824
17885
|
return {
|
|
17825
17886
|
text: `WITH ${ctes.join(",\n")}, extracted AS (
|
|
17826
|
-
|
|
17887
|
+
${extracted}
|
|
17827
17888
|
)
|
|
17828
17889
|
SELECT value, count(*)::bigint AS count
|
|
17829
17890
|
FROM extracted
|
|
@@ -18178,7 +18239,7 @@ function buildListTracesFilters(filters, spanTable, nextParamIdx) {
|
|
|
18178
18239
|
}
|
|
18179
18240
|
if (filters.metadata != null) {
|
|
18180
18241
|
conditions.push(`r."metadataSearch" @> $${i++}::jsonb`);
|
|
18181
|
-
params.push(
|
|
18242
|
+
params.push(toPgJson(filters.metadata));
|
|
18182
18243
|
}
|
|
18183
18244
|
if (filters.tags != null && filters.tags.length > 0) {
|
|
18184
18245
|
conditions.push(`r."tags" @> $${i++}::text[]`);
|
|
@@ -18456,7 +18517,7 @@ function buildListBranchesFilters(filters, spanType, spanTable, nextParamIdx) {
|
|
|
18456
18517
|
}
|
|
18457
18518
|
if (filters.metadata != null) {
|
|
18458
18519
|
conditions.push(`r."metadataSearch" @> $${i++}::jsonb`);
|
|
18459
|
-
params.push(
|
|
18520
|
+
params.push(toPgJson(filters.metadata));
|
|
18460
18521
|
}
|
|
18461
18522
|
if (filters.tags != null && filters.tags.length > 0) {
|
|
18462
18523
|
conditions.push(`r."tags" @> $${i++}::text[]`);
|
|
@@ -18921,6 +18982,7 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
18921
18982
|
"metrics",
|
|
18922
18983
|
"logs",
|
|
18923
18984
|
"trace-query",
|
|
18985
|
+
"trace-query-root-duration",
|
|
18924
18986
|
"trace-query-discovery",
|
|
18925
18987
|
"thread-query",
|
|
18926
18988
|
"trace-query-tenant-scope"
|
|
@@ -18930,6 +18992,7 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
18930
18992
|
"logs",
|
|
18931
18993
|
"delta-polling",
|
|
18932
18994
|
"trace-query",
|
|
18995
|
+
"trace-query-root-duration",
|
|
18933
18996
|
"trace-query-discovery",
|
|
18934
18997
|
"thread-query",
|
|
18935
18998
|
"trace-query-tenant-scope"
|
|
@@ -19247,7 +19310,7 @@ var PromptBlocksPG = class PromptBlocksPG extends _mastra_core_storage.PromptBlo
|
|
|
19247
19310
|
"draft",
|
|
19248
19311
|
null,
|
|
19249
19312
|
promptBlock.authorId ?? null,
|
|
19250
|
-
promptBlock.metadata ?
|
|
19313
|
+
promptBlock.metadata ? toPgJson(promptBlock.metadata) : null,
|
|
19251
19314
|
nowIso,
|
|
19252
19315
|
nowIso,
|
|
19253
19316
|
nowIso,
|
|
@@ -19326,7 +19389,7 @@ var PromptBlocksPG = class PromptBlocksPG extends _mastra_core_storage.PromptBlo
|
|
|
19326
19389
|
...metadata
|
|
19327
19390
|
};
|
|
19328
19391
|
setClauses.push(`metadata = $${paramIndex++}`);
|
|
19329
|
-
values.push(
|
|
19392
|
+
values.push(toPgJson(mergedMetadata));
|
|
19330
19393
|
}
|
|
19331
19394
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
19332
19395
|
setClauses.push(`"updatedAt" = $${paramIndex++}`);
|
|
@@ -19401,7 +19464,7 @@ var PromptBlocksPG = class PromptBlocksPG extends _mastra_core_storage.PromptBlo
|
|
|
19401
19464
|
}
|
|
19402
19465
|
if (metadata && Object.keys(metadata).length > 0) {
|
|
19403
19466
|
conditions.push(`metadata @> $${paramIdx++}::jsonb`);
|
|
19404
|
-
queryParams.push(
|
|
19467
|
+
queryParams.push(toPgJson(metadata));
|
|
19405
19468
|
}
|
|
19406
19469
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
19407
19470
|
const countResult = await this.#db.readClient.one(`SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`, queryParams);
|
|
@@ -19464,9 +19527,9 @@ var PromptBlocksPG = class PromptBlocksPG extends _mastra_core_storage.PromptBlo
|
|
|
19464
19527
|
input.name,
|
|
19465
19528
|
input.description ?? null,
|
|
19466
19529
|
input.content,
|
|
19467
|
-
input.rules ?
|
|
19468
|
-
input.requestContextSchema ?
|
|
19469
|
-
input.changedFields ?
|
|
19530
|
+
input.rules ? toPgJson(input.rules) : null,
|
|
19531
|
+
input.requestContextSchema ? toPgJson(input.requestContextSchema) : null,
|
|
19532
|
+
input.changedFields ? toPgJson(input.changedFields) : null,
|
|
19470
19533
|
input.changeMessage ?? null,
|
|
19471
19534
|
nowIso,
|
|
19472
19535
|
nowIso
|
|
@@ -19973,8 +20036,8 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
|
|
|
19973
20036
|
if ("timezone" in patch) push("timezone = ?", patch.timezone ?? null);
|
|
19974
20037
|
if ("status" in patch && patch.status !== void 0) push("status = ?", patch.status);
|
|
19975
20038
|
if ("nextFireAt" in patch && patch.nextFireAt !== void 0) push("next_fire_at = ?", patch.nextFireAt);
|
|
19976
|
-
if ("target" in patch && patch.target !== void 0) push("target = ?::jsonb",
|
|
19977
|
-
if ("metadata" in patch) push("metadata = ?::jsonb", patch.metadata != null ?
|
|
20039
|
+
if ("target" in patch && patch.target !== void 0) push("target = ?::jsonb", toPgJson(patch.target));
|
|
20040
|
+
if ("metadata" in patch) push("metadata = ?::jsonb", patch.metadata != null ? toPgJson(patch.metadata) : null);
|
|
19978
20041
|
if ("ownerType" in patch) push("owner_type = ?", patch.ownerType ?? null);
|
|
19979
20042
|
if ("ownerId" in patch) push("owner_id = ?", patch.ownerId ?? null);
|
|
19980
20043
|
push("updated_at = ?", Date.now());
|
|
@@ -20192,7 +20255,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends _mastra_core_storage
|
|
|
20192
20255
|
scorerDefinition.authorId ?? null,
|
|
20193
20256
|
scorerDefinition.organizationId ?? null,
|
|
20194
20257
|
scorerDefinition.projectId ?? null,
|
|
20195
|
-
scorerDefinition.metadata ?
|
|
20258
|
+
scorerDefinition.metadata ? toPgJson(scorerDefinition.metadata) : null,
|
|
20196
20259
|
nowIso,
|
|
20197
20260
|
nowIso,
|
|
20198
20261
|
nowIso,
|
|
@@ -20273,7 +20336,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends _mastra_core_storage
|
|
|
20273
20336
|
...metadata
|
|
20274
20337
|
};
|
|
20275
20338
|
setClauses.push(`metadata = $${paramIndex++}`);
|
|
20276
|
-
values.push(
|
|
20339
|
+
values.push(toPgJson(mergedMetadata));
|
|
20277
20340
|
}
|
|
20278
20341
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
20279
20342
|
setClauses.push(`"updatedAt" = $${paramIndex++}`);
|
|
@@ -20356,7 +20419,7 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends _mastra_core_storage
|
|
|
20356
20419
|
}
|
|
20357
20420
|
if (metadata && Object.keys(metadata).length > 0) {
|
|
20358
20421
|
conditions.push(`metadata @> $${paramIdx++}::jsonb`);
|
|
20359
|
-
queryParams.push(
|
|
20422
|
+
queryParams.push(toPgJson(metadata));
|
|
20360
20423
|
}
|
|
20361
20424
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
20362
20425
|
const countResult = await this.#db.readClient.one(`SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`, queryParams);
|
|
@@ -20419,12 +20482,12 @@ var ScorerDefinitionsPG = class ScorerDefinitionsPG extends _mastra_core_storage
|
|
|
20419
20482
|
input.name,
|
|
20420
20483
|
input.description ?? null,
|
|
20421
20484
|
input.type,
|
|
20422
|
-
input.model ?
|
|
20485
|
+
input.model ? toPgJson(input.model) : null,
|
|
20423
20486
|
input.instructions ?? null,
|
|
20424
|
-
input.scoreRange ?
|
|
20425
|
-
input.presetConfig ?
|
|
20426
|
-
input.defaultSampling ?
|
|
20427
|
-
input.changedFields ?
|
|
20487
|
+
input.scoreRange ? toPgJson(input.scoreRange) : null,
|
|
20488
|
+
input.presetConfig ? toPgJson(input.presetConfig) : null,
|
|
20489
|
+
input.defaultSampling ? toPgJson(input.defaultSampling) : null,
|
|
20490
|
+
input.changedFields ? toPgJson(input.changedFields) : null,
|
|
20428
20491
|
input.changeMessage ?? null,
|
|
20429
20492
|
nowIso,
|
|
20430
20493
|
nowIso
|
|
@@ -20944,15 +21007,15 @@ var ScoresPG = class ScoresPG extends _mastra_core_storage.ScoresStorage {
|
|
|
20944
21007
|
record: {
|
|
20945
21008
|
id,
|
|
20946
21009
|
...rest,
|
|
20947
|
-
input:
|
|
20948
|
-
output:
|
|
20949
|
-
scorer: scorer ?
|
|
20950
|
-
preprocessStepResult: preprocessStepResult ?
|
|
20951
|
-
analyzeStepResult: analyzeStepResult ?
|
|
20952
|
-
metadata: metadata ?
|
|
20953
|
-
additionalContext: additionalContext ?
|
|
20954
|
-
requestContext: requestContext ?
|
|
20955
|
-
entity: entity ?
|
|
21010
|
+
input: toPgJson(input) || "",
|
|
21011
|
+
output: toPgJson(output) || "",
|
|
21012
|
+
scorer: scorer ? toPgJson(scorer) : null,
|
|
21013
|
+
preprocessStepResult: preprocessStepResult ? toPgJson(preprocessStepResult) : null,
|
|
21014
|
+
analyzeStepResult: analyzeStepResult ? toPgJson(analyzeStepResult) : null,
|
|
21015
|
+
metadata: metadata ? toPgJson(metadata) : null,
|
|
21016
|
+
additionalContext: additionalContext ? toPgJson(additionalContext) : null,
|
|
21017
|
+
requestContext: requestContext ? toPgJson(requestContext) : null,
|
|
21018
|
+
entity: entity ? toPgJson(entity) : null,
|
|
20956
21019
|
createdAt: now.toISOString(),
|
|
20957
21020
|
updatedAt: now.toISOString()
|
|
20958
21021
|
}
|
|
@@ -21537,15 +21600,15 @@ var SkillsPG = class SkillsPG extends _mastra_core_storage.SkillsStorage {
|
|
|
21537
21600
|
input.description ?? null,
|
|
21538
21601
|
input.instructions ?? null,
|
|
21539
21602
|
input.license ?? null,
|
|
21540
|
-
input.compatibility ?
|
|
21541
|
-
input.source ?
|
|
21542
|
-
input.references ?
|
|
21543
|
-
input.scripts ?
|
|
21544
|
-
input.assets ?
|
|
21545
|
-
input.files ?
|
|
21546
|
-
input.metadata ?
|
|
21547
|
-
input.tree ?
|
|
21548
|
-
input.changedFields ?
|
|
21603
|
+
input.compatibility ? toPgJson(input.compatibility) : null,
|
|
21604
|
+
input.source ? toPgJson(input.source) : null,
|
|
21605
|
+
input.references ? toPgJson(input.references) : null,
|
|
21606
|
+
input.scripts ? toPgJson(input.scripts) : null,
|
|
21607
|
+
input.assets ? toPgJson(input.assets) : null,
|
|
21608
|
+
input.files ? toPgJson(input.files) : null,
|
|
21609
|
+
input.metadata ? toPgJson(input.metadata) : null,
|
|
21610
|
+
input.tree ? toPgJson(input.tree) : null,
|
|
21611
|
+
input.changedFields ? toPgJson(input.changedFields) : null,
|
|
21549
21612
|
input.changeMessage ?? null,
|
|
21550
21613
|
nowIso,
|
|
21551
21614
|
nowIso
|
|
@@ -21921,7 +21984,7 @@ var ThreadStatePG = class ThreadStatePG extends _mastra_core_storage.ThreadState
|
|
|
21921
21984
|
}
|
|
21922
21985
|
async setState({ threadId, type, value }) {
|
|
21923
21986
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
21924
|
-
const serialized =
|
|
21987
|
+
const serialized = toPgJson(value ?? null);
|
|
21925
21988
|
try {
|
|
21926
21989
|
await this.#db.client.none(`INSERT INTO ${this.#table} ("threadId", "type", "value", "createdAt", "createdAtZ", "updatedAt", "updatedAtZ")
|
|
21927
21990
|
VALUES ($1, $2, $3::jsonb, $4::timestamp, $5::timestamptz, $4::timestamp, $5::timestamptz)
|
|
@@ -22698,7 +22761,7 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
|
|
|
22698
22761
|
requestContext
|
|
22699
22762
|
});
|
|
22700
22763
|
const now = /* @__PURE__ */ new Date();
|
|
22701
|
-
const sanitizedSnapshot =
|
|
22764
|
+
const sanitizedSnapshot = toPgJson(snapshot);
|
|
22702
22765
|
await t.none(`INSERT INTO ${tableName}
|
|
22703
22766
|
(workflow_name, run_id, snapshot, "createdAt", "updatedAt", "createdAtZ", "updatedAtZ")
|
|
22704
22767
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
@@ -22745,7 +22808,7 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
|
|
|
22745
22808
|
...snapshot,
|
|
22746
22809
|
...state
|
|
22747
22810
|
};
|
|
22748
|
-
const sanitizedSnapshot =
|
|
22811
|
+
const sanitizedSnapshot = toPgJson(updatedSnapshot);
|
|
22749
22812
|
const now = /* @__PURE__ */ new Date();
|
|
22750
22813
|
await t.none(`UPDATE ${tableName}
|
|
22751
22814
|
SET snapshot = $1, "updatedAt" = $2, "updatedAtZ" = $3
|
|
@@ -22775,7 +22838,7 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
|
|
|
22775
22838
|
const now = /* @__PURE__ */ new Date();
|
|
22776
22839
|
const createdAtValue = createdAt ? createdAt : now;
|
|
22777
22840
|
const updatedAtValue = updatedAt ? updatedAt : now;
|
|
22778
|
-
const sanitizedSnapshot =
|
|
22841
|
+
const sanitizedSnapshot = toPgJson(snapshot);
|
|
22779
22842
|
await this.#db.client.none(`INSERT INTO ${getTableName({
|
|
22780
22843
|
indexName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
22781
22844
|
schemaName: getSchemaName(this.#schema)
|
|
@@ -23087,7 +23150,7 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
|
|
|
23087
23150
|
"draft",
|
|
23088
23151
|
null,
|
|
23089
23152
|
workspace.authorId ?? null,
|
|
23090
|
-
workspace.metadata ?
|
|
23153
|
+
workspace.metadata ? toPgJson(workspace.metadata) : null,
|
|
23091
23154
|
nowIso,
|
|
23092
23155
|
nowIso,
|
|
23093
23156
|
nowIso,
|
|
@@ -23162,7 +23225,11 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
|
|
|
23162
23225
|
...latestConfig,
|
|
23163
23226
|
...configFields
|
|
23164
23227
|
};
|
|
23165
|
-
const
|
|
23228
|
+
const normalized = (value) => {
|
|
23229
|
+
const json = toPgJson(value);
|
|
23230
|
+
return json === void 0 ? void 0 : JSON.parse(json);
|
|
23231
|
+
};
|
|
23232
|
+
const changedFields = SNAPSHOT_FIELDS.filter((field) => field in configFields && !(0, util.isDeepStrictEqual)(normalized(configFields[field]), normalized(latestConfig[field])));
|
|
23166
23233
|
if (changedFields.length > 0) {
|
|
23167
23234
|
versionCreated = true;
|
|
23168
23235
|
const newVersionId = crypto.randomUUID();
|
|
@@ -23196,12 +23263,13 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
|
|
|
23196
23263
|
values.push(status);
|
|
23197
23264
|
}
|
|
23198
23265
|
if (metadata !== void 0) {
|
|
23266
|
+
const normalizedMetadata = JSON.parse(toPgJson(metadata));
|
|
23199
23267
|
const mergedMetadata = {
|
|
23200
23268
|
...existingWorkspace.metadata || {},
|
|
23201
|
-
...
|
|
23269
|
+
...normalizedMetadata
|
|
23202
23270
|
};
|
|
23203
23271
|
setClauses.push(`metadata = $${paramIndex++}`);
|
|
23204
|
-
values.push(
|
|
23272
|
+
values.push(toPgJson(mergedMetadata));
|
|
23205
23273
|
}
|
|
23206
23274
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
23207
23275
|
setClauses.push(`"updatedAt" = $${paramIndex++}`);
|
|
@@ -23272,7 +23340,7 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
|
|
|
23272
23340
|
}
|
|
23273
23341
|
if (metadata && Object.keys(metadata).length > 0) {
|
|
23274
23342
|
conditions.push(`metadata @> $${paramIdx++}::jsonb`);
|
|
23275
|
-
queryParams.push(
|
|
23343
|
+
queryParams.push(toPgJson(metadata));
|
|
23276
23344
|
}
|
|
23277
23345
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
23278
23346
|
const countResult = await this.#db.readClient.one(`SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`, queryParams);
|
|
@@ -23335,15 +23403,15 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
|
|
|
23335
23403
|
input.versionNumber,
|
|
23336
23404
|
input.name,
|
|
23337
23405
|
input.description ?? null,
|
|
23338
|
-
input.filesystem ?
|
|
23339
|
-
input.sandbox ?
|
|
23340
|
-
input.mounts ?
|
|
23341
|
-
input.search ?
|
|
23342
|
-
input.skills ?
|
|
23343
|
-
input.tools ?
|
|
23406
|
+
input.filesystem ? toPgJson(input.filesystem) : null,
|
|
23407
|
+
input.sandbox ? toPgJson(input.sandbox) : null,
|
|
23408
|
+
input.mounts ? toPgJson(input.mounts) : null,
|
|
23409
|
+
input.search ? toPgJson(input.search) : null,
|
|
23410
|
+
input.skills ? toPgJson(input.skills) : null,
|
|
23411
|
+
input.tools ? toPgJson(input.tools) : null,
|
|
23344
23412
|
input.autoSync ?? false,
|
|
23345
23413
|
input.operationTimeout ?? null,
|
|
23346
|
-
input.changedFields ?
|
|
23414
|
+
input.changedFields ? toPgJson(input.changedFields) : null,
|
|
23347
23415
|
input.changeMessage ?? null,
|
|
23348
23416
|
nowIso,
|
|
23349
23417
|
nowIso
|
|
@@ -23635,7 +23703,7 @@ var PgFactoryStorageOps = class {
|
|
|
23635
23703
|
switch (spec.type) {
|
|
23636
23704
|
case "timestamp": return value instanceof Date ? value : new Date(String(value));
|
|
23637
23705
|
case "boolean": return Boolean(value);
|
|
23638
|
-
case "json": return
|
|
23706
|
+
case "json": return toPgJson(value);
|
|
23639
23707
|
case "bigint":
|
|
23640
23708
|
case "integer": return Number(value);
|
|
23641
23709
|
default: return String(value);
|