@mastra/pg 1.9.4 → 1.10.0-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 +11 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +270 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +271 -23
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/schedules/index.d.ts +22 -0
- package/dist/storage/domains/schedules/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
2
|
-
import { createVectorErrorId, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_SCHEMAS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, DatasetsStorage, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, DATASETS_SCHEMA, TABLE_CONFIGS, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, ensureDate, safelyParseJSON, ExperimentsStorage, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, MCPClientsStorage, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, ScorerDefinitionsStorage, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SkillsStorage, TABLE_SKILLS, TABLE_SKILL_VERSIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, TraceStatus, getDefaultValue, transformScoreRow as transformScoreRow$1, getSqlType } from '@mastra/core/storage';
|
|
2
|
+
import { createVectorErrorId, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_SCHEMAS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, ChannelsStorage, TABLE_CHANNEL_INSTALLATIONS, TABLE_CHANNEL_CONFIG, DatasetsStorage, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, DATASETS_SCHEMA, TABLE_CONFIGS, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, ensureDate, safelyParseJSON, ExperimentsStorage, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, MCPClientsStorage, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, SchedulesStorage, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, ScorerDefinitionsStorage, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SkillsStorage, TABLE_SKILLS, TABLE_SKILL_VERSIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, TraceStatus, getDefaultValue, transformScoreRow as transformScoreRow$1, getSqlType } from '@mastra/core/storage';
|
|
3
3
|
import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
|
|
4
4
|
import { MastraVector, validateTopK, validateUpsertInput } from '@mastra/core/vector';
|
|
5
5
|
import { Mutex } from 'async-mutex';
|
|
@@ -11352,6 +11352,252 @@ var PromptBlocksPG = class _PromptBlocksPG extends PromptBlocksStorage {
|
|
|
11352
11352
|
};
|
|
11353
11353
|
}
|
|
11354
11354
|
};
|
|
11355
|
+
function getSchemaName5(schema) {
|
|
11356
|
+
return schema ? `"${schema}"` : '"public"';
|
|
11357
|
+
}
|
|
11358
|
+
function getTableName5(table, schema) {
|
|
11359
|
+
const quoted = `"${table}"`;
|
|
11360
|
+
return schema ? `${schema}.${quoted}` : quoted;
|
|
11361
|
+
}
|
|
11362
|
+
function parseJson2(val) {
|
|
11363
|
+
if (val == null) return void 0;
|
|
11364
|
+
if (typeof val === "string") {
|
|
11365
|
+
try {
|
|
11366
|
+
return JSON.parse(val);
|
|
11367
|
+
} catch {
|
|
11368
|
+
return val;
|
|
11369
|
+
}
|
|
11370
|
+
}
|
|
11371
|
+
return val;
|
|
11372
|
+
}
|
|
11373
|
+
function toNumber(val) {
|
|
11374
|
+
if (typeof val === "bigint") return Number(val);
|
|
11375
|
+
return Number(val);
|
|
11376
|
+
}
|
|
11377
|
+
function rowToSchedule(row) {
|
|
11378
|
+
const target = parseJson2(row.target);
|
|
11379
|
+
if (!target) {
|
|
11380
|
+
throw new Error(`Schedule row ${row.id} has invalid target`);
|
|
11381
|
+
}
|
|
11382
|
+
const schedule = {
|
|
11383
|
+
id: String(row.id),
|
|
11384
|
+
target,
|
|
11385
|
+
cron: String(row.cron),
|
|
11386
|
+
status: String(row.status),
|
|
11387
|
+
nextFireAt: toNumber(row.next_fire_at),
|
|
11388
|
+
createdAt: toNumber(row.created_at),
|
|
11389
|
+
updatedAt: toNumber(row.updated_at)
|
|
11390
|
+
};
|
|
11391
|
+
if (row.timezone != null) schedule.timezone = String(row.timezone);
|
|
11392
|
+
if (row.last_fire_at != null) schedule.lastFireAt = toNumber(row.last_fire_at);
|
|
11393
|
+
if (row.last_run_id != null) schedule.lastRunId = String(row.last_run_id);
|
|
11394
|
+
const metadata = parseJson2(row.metadata);
|
|
11395
|
+
if (metadata !== void 0) schedule.metadata = metadata;
|
|
11396
|
+
return schedule;
|
|
11397
|
+
}
|
|
11398
|
+
function rowToTrigger(row) {
|
|
11399
|
+
const trigger = {
|
|
11400
|
+
scheduleId: String(row.schedule_id),
|
|
11401
|
+
runId: String(row.run_id),
|
|
11402
|
+
scheduledFireAt: toNumber(row.scheduled_fire_at),
|
|
11403
|
+
actualFireAt: toNumber(row.actual_fire_at),
|
|
11404
|
+
status: String(row.status)
|
|
11405
|
+
};
|
|
11406
|
+
if (row.error != null) trigger.error = String(row.error);
|
|
11407
|
+
return trigger;
|
|
11408
|
+
}
|
|
11409
|
+
var SchedulesPG = class extends SchedulesStorage {
|
|
11410
|
+
#db;
|
|
11411
|
+
#client;
|
|
11412
|
+
#schema;
|
|
11413
|
+
/** Tables managed by this domain */
|
|
11414
|
+
static MANAGED_TABLES = [TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS];
|
|
11415
|
+
constructor(config) {
|
|
11416
|
+
super();
|
|
11417
|
+
const { client, schemaName, skipDefaultIndexes } = resolvePgConfig(config);
|
|
11418
|
+
this.#client = client;
|
|
11419
|
+
this.#db = new PgDB({ client, schemaName, skipDefaultIndexes });
|
|
11420
|
+
this.#schema = schemaName || "public";
|
|
11421
|
+
}
|
|
11422
|
+
async init() {
|
|
11423
|
+
await this.#db.createTable({
|
|
11424
|
+
tableName: TABLE_SCHEDULES,
|
|
11425
|
+
schema: TABLE_SCHEMAS[TABLE_SCHEDULES]
|
|
11426
|
+
});
|
|
11427
|
+
await this.#db.createTable({
|
|
11428
|
+
tableName: TABLE_SCHEDULE_TRIGGERS,
|
|
11429
|
+
schema: TABLE_SCHEMAS[TABLE_SCHEDULE_TRIGGERS]
|
|
11430
|
+
});
|
|
11431
|
+
}
|
|
11432
|
+
static getExportDDL(schemaName) {
|
|
11433
|
+
return [
|
|
11434
|
+
generateTableSQL({
|
|
11435
|
+
tableName: TABLE_SCHEDULES,
|
|
11436
|
+
schema: TABLE_SCHEMAS[TABLE_SCHEDULES],
|
|
11437
|
+
schemaName,
|
|
11438
|
+
includeAllConstraints: true
|
|
11439
|
+
}),
|
|
11440
|
+
generateTableSQL({
|
|
11441
|
+
tableName: TABLE_SCHEDULE_TRIGGERS,
|
|
11442
|
+
schema: TABLE_SCHEMAS[TABLE_SCHEDULE_TRIGGERS],
|
|
11443
|
+
schemaName,
|
|
11444
|
+
includeAllConstraints: true
|
|
11445
|
+
})
|
|
11446
|
+
];
|
|
11447
|
+
}
|
|
11448
|
+
async dangerouslyClearAll() {
|
|
11449
|
+
await this.#db.clearTable({ tableName: TABLE_SCHEDULE_TRIGGERS });
|
|
11450
|
+
await this.#db.clearTable({ tableName: TABLE_SCHEDULES });
|
|
11451
|
+
}
|
|
11452
|
+
#table(tableName) {
|
|
11453
|
+
const schema = parseSqlIdentifier(this.#schema, "schema name");
|
|
11454
|
+
return getTableName5(tableName, getSchemaName5(schema));
|
|
11455
|
+
}
|
|
11456
|
+
async createSchedule(schedule) {
|
|
11457
|
+
const existing = await this.getSchedule(schedule.id);
|
|
11458
|
+
if (existing) {
|
|
11459
|
+
throw new Error(`Schedule with id "${schedule.id}" already exists`);
|
|
11460
|
+
}
|
|
11461
|
+
await this.#db.insert({
|
|
11462
|
+
tableName: TABLE_SCHEDULES,
|
|
11463
|
+
record: {
|
|
11464
|
+
id: schedule.id,
|
|
11465
|
+
target: schedule.target,
|
|
11466
|
+
cron: schedule.cron,
|
|
11467
|
+
timezone: schedule.timezone ?? null,
|
|
11468
|
+
status: schedule.status,
|
|
11469
|
+
next_fire_at: schedule.nextFireAt,
|
|
11470
|
+
last_fire_at: schedule.lastFireAt ?? null,
|
|
11471
|
+
last_run_id: schedule.lastRunId ?? null,
|
|
11472
|
+
created_at: schedule.createdAt,
|
|
11473
|
+
updated_at: schedule.updatedAt,
|
|
11474
|
+
metadata: schedule.metadata ?? null
|
|
11475
|
+
}
|
|
11476
|
+
});
|
|
11477
|
+
return schedule;
|
|
11478
|
+
}
|
|
11479
|
+
async getSchedule(id) {
|
|
11480
|
+
const row = await this.#client.oneOrNone(
|
|
11481
|
+
`SELECT * FROM ${this.#table(TABLE_SCHEDULES)} WHERE id = $1`,
|
|
11482
|
+
[id]
|
|
11483
|
+
);
|
|
11484
|
+
return row ? rowToSchedule(row) : null;
|
|
11485
|
+
}
|
|
11486
|
+
async listSchedules(filter) {
|
|
11487
|
+
const conditions = [];
|
|
11488
|
+
const params = [];
|
|
11489
|
+
if (filter?.status) {
|
|
11490
|
+
params.push(filter.status);
|
|
11491
|
+
conditions.push(`status = $${params.length}`);
|
|
11492
|
+
}
|
|
11493
|
+
if (filter?.workflowId) {
|
|
11494
|
+
params.push(filter.workflowId);
|
|
11495
|
+
conditions.push(`target->>'workflowId' = $${params.length}`);
|
|
11496
|
+
}
|
|
11497
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
11498
|
+
const rows = await this.#client.manyOrNone(
|
|
11499
|
+
`SELECT * FROM ${this.#table(TABLE_SCHEDULES)} ${where} ORDER BY created_at ASC`,
|
|
11500
|
+
params
|
|
11501
|
+
);
|
|
11502
|
+
return rows.map(rowToSchedule);
|
|
11503
|
+
}
|
|
11504
|
+
async listDueSchedules(now, limit) {
|
|
11505
|
+
const cap = limit ?? 100;
|
|
11506
|
+
const rows = await this.#client.manyOrNone(
|
|
11507
|
+
`SELECT * FROM ${this.#table(TABLE_SCHEDULES)}
|
|
11508
|
+
WHERE status = $1 AND next_fire_at <= $2
|
|
11509
|
+
ORDER BY next_fire_at ASC
|
|
11510
|
+
LIMIT $3`,
|
|
11511
|
+
["active", now, cap]
|
|
11512
|
+
);
|
|
11513
|
+
return rows.map(rowToSchedule);
|
|
11514
|
+
}
|
|
11515
|
+
async updateSchedule(id, patch) {
|
|
11516
|
+
const setClauses = [];
|
|
11517
|
+
const params = [];
|
|
11518
|
+
const push = (frag, value) => {
|
|
11519
|
+
params.push(value);
|
|
11520
|
+
setClauses.push(frag.replace("?", `$${params.length}`));
|
|
11521
|
+
};
|
|
11522
|
+
if ("cron" in patch && patch.cron !== void 0) push("cron = ?", patch.cron);
|
|
11523
|
+
if ("timezone" in patch) push("timezone = ?", patch.timezone ?? null);
|
|
11524
|
+
if ("status" in patch && patch.status !== void 0) push("status = ?", patch.status);
|
|
11525
|
+
if ("nextFireAt" in patch && patch.nextFireAt !== void 0) push("next_fire_at = ?", patch.nextFireAt);
|
|
11526
|
+
if ("target" in patch && patch.target !== void 0) {
|
|
11527
|
+
push("target = ?::jsonb", JSON.stringify(patch.target));
|
|
11528
|
+
}
|
|
11529
|
+
if ("metadata" in patch) {
|
|
11530
|
+
push("metadata = ?::jsonb", patch.metadata != null ? JSON.stringify(patch.metadata) : null);
|
|
11531
|
+
}
|
|
11532
|
+
push("updated_at = ?", Date.now());
|
|
11533
|
+
if (setClauses.length === 1) {
|
|
11534
|
+
const existing = await this.getSchedule(id);
|
|
11535
|
+
if (!existing) throw new Error(`Schedule ${id} not found`);
|
|
11536
|
+
return existing;
|
|
11537
|
+
}
|
|
11538
|
+
params.push(id);
|
|
11539
|
+
await this.#client.none(
|
|
11540
|
+
`UPDATE ${this.#table(TABLE_SCHEDULES)} SET ${setClauses.join(", ")} WHERE id = $${params.length}`,
|
|
11541
|
+
params
|
|
11542
|
+
);
|
|
11543
|
+
const updated = await this.getSchedule(id);
|
|
11544
|
+
if (!updated) throw new Error(`Schedule ${id} not found`);
|
|
11545
|
+
return updated;
|
|
11546
|
+
}
|
|
11547
|
+
async updateScheduleNextFire(id, expectedNextFireAt, newNextFireAt, lastFireAt, lastRunId) {
|
|
11548
|
+
const result = await this.#client.query(
|
|
11549
|
+
`UPDATE ${this.#table(TABLE_SCHEDULES)}
|
|
11550
|
+
SET next_fire_at = $1, last_fire_at = $2, last_run_id = $3, updated_at = $4
|
|
11551
|
+
WHERE id = $5 AND next_fire_at = $6 AND status = $7`,
|
|
11552
|
+
[newNextFireAt, lastFireAt, lastRunId, Date.now(), id, expectedNextFireAt, "active"]
|
|
11553
|
+
);
|
|
11554
|
+
return (result.rowCount ?? 0) > 0;
|
|
11555
|
+
}
|
|
11556
|
+
async deleteSchedule(id) {
|
|
11557
|
+
await this.#client.none(`DELETE FROM ${this.#table(TABLE_SCHEDULE_TRIGGERS)} WHERE schedule_id = $1`, [id]);
|
|
11558
|
+
await this.#client.none(`DELETE FROM ${this.#table(TABLE_SCHEDULES)} WHERE id = $1`, [id]);
|
|
11559
|
+
}
|
|
11560
|
+
async recordTrigger(trigger) {
|
|
11561
|
+
await this.#db.insert({
|
|
11562
|
+
tableName: TABLE_SCHEDULE_TRIGGERS,
|
|
11563
|
+
record: {
|
|
11564
|
+
schedule_id: trigger.scheduleId,
|
|
11565
|
+
run_id: trigger.runId,
|
|
11566
|
+
scheduled_fire_at: trigger.scheduledFireAt,
|
|
11567
|
+
actual_fire_at: trigger.actualFireAt,
|
|
11568
|
+
status: trigger.status,
|
|
11569
|
+
error: trigger.error ?? null
|
|
11570
|
+
}
|
|
11571
|
+
});
|
|
11572
|
+
}
|
|
11573
|
+
async listTriggers(scheduleId, opts) {
|
|
11574
|
+
const conditions = [];
|
|
11575
|
+
const params = [];
|
|
11576
|
+
params.push(scheduleId);
|
|
11577
|
+
conditions.push(`schedule_id = $${params.length}`);
|
|
11578
|
+
if (opts?.fromActualFireAt != null) {
|
|
11579
|
+
params.push(opts.fromActualFireAt);
|
|
11580
|
+
conditions.push(`actual_fire_at >= $${params.length}`);
|
|
11581
|
+
}
|
|
11582
|
+
if (opts?.toActualFireAt != null) {
|
|
11583
|
+
params.push(opts.toActualFireAt);
|
|
11584
|
+
conditions.push(`actual_fire_at < $${params.length}`);
|
|
11585
|
+
}
|
|
11586
|
+
let limitClause = "";
|
|
11587
|
+
if (opts?.limit != null) {
|
|
11588
|
+
params.push(Math.floor(opts.limit));
|
|
11589
|
+
limitClause = `LIMIT $${params.length}`;
|
|
11590
|
+
}
|
|
11591
|
+
const rows = await this.#client.manyOrNone(
|
|
11592
|
+
`SELECT * FROM ${this.#table(TABLE_SCHEDULE_TRIGGERS)}
|
|
11593
|
+
WHERE ${conditions.join(" AND ")}
|
|
11594
|
+
ORDER BY actual_fire_at DESC
|
|
11595
|
+
${limitClause}`,
|
|
11596
|
+
params
|
|
11597
|
+
);
|
|
11598
|
+
return rows.map(rowToTrigger);
|
|
11599
|
+
}
|
|
11600
|
+
};
|
|
11355
11601
|
var SNAPSHOT_FIELDS4 = [
|
|
11356
11602
|
"name",
|
|
11357
11603
|
"description",
|
|
@@ -12019,10 +12265,10 @@ var ScorerDefinitionsPG = class _ScorerDefinitionsPG extends ScorerDefinitionsSt
|
|
|
12019
12265
|
};
|
|
12020
12266
|
}
|
|
12021
12267
|
};
|
|
12022
|
-
function
|
|
12268
|
+
function getSchemaName6(schema) {
|
|
12023
12269
|
return schema ? `"${schema}"` : '"public"';
|
|
12024
12270
|
}
|
|
12025
|
-
function
|
|
12271
|
+
function getTableName6({ indexName, schemaName }) {
|
|
12026
12272
|
const quotedIndexName = `"${indexName}"`;
|
|
12027
12273
|
return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
|
|
12028
12274
|
}
|
|
@@ -12136,7 +12382,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
|
|
|
12136
12382
|
async getScoreById({ id }) {
|
|
12137
12383
|
try {
|
|
12138
12384
|
const result = await this.#db.client.oneOrNone(
|
|
12139
|
-
`SELECT * FROM ${
|
|
12385
|
+
`SELECT * FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE id = $1`,
|
|
12140
12386
|
[id]
|
|
12141
12387
|
);
|
|
12142
12388
|
return result ? transformScoreRow(result) : null;
|
|
@@ -12176,7 +12422,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
|
|
|
12176
12422
|
}
|
|
12177
12423
|
const whereClause = conditions.join(" AND ");
|
|
12178
12424
|
const total = await this.#db.client.oneOrNone(
|
|
12179
|
-
`SELECT COUNT(*) FROM ${
|
|
12425
|
+
`SELECT COUNT(*) FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE ${whereClause}`,
|
|
12180
12426
|
queryParams
|
|
12181
12427
|
);
|
|
12182
12428
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -12196,7 +12442,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
|
|
|
12196
12442
|
const limitValue = perPageInput === false ? Number(total?.count) : perPage;
|
|
12197
12443
|
const end = perPageInput === false ? Number(total?.count) : start + perPage;
|
|
12198
12444
|
const result = await this.#db.client.manyOrNone(
|
|
12199
|
-
`SELECT * FROM ${
|
|
12445
|
+
`SELECT * FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`,
|
|
12200
12446
|
[...queryParams, limitValue, start]
|
|
12201
12447
|
);
|
|
12202
12448
|
return {
|
|
@@ -12291,7 +12537,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
|
|
|
12291
12537
|
}) {
|
|
12292
12538
|
try {
|
|
12293
12539
|
const total = await this.#db.client.oneOrNone(
|
|
12294
|
-
`SELECT COUNT(*) FROM ${
|
|
12540
|
+
`SELECT COUNT(*) FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "runId" = $1`,
|
|
12295
12541
|
[runId]
|
|
12296
12542
|
);
|
|
12297
12543
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -12311,7 +12557,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
|
|
|
12311
12557
|
const limitValue = perPageInput === false ? Number(total?.count) : perPage;
|
|
12312
12558
|
const end = perPageInput === false ? Number(total?.count) : start + perPage;
|
|
12313
12559
|
const result = await this.#db.client.manyOrNone(
|
|
12314
|
-
`SELECT * FROM ${
|
|
12560
|
+
`SELECT * FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
|
|
12315
12561
|
[runId, limitValue, start]
|
|
12316
12562
|
);
|
|
12317
12563
|
return {
|
|
@@ -12341,7 +12587,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
|
|
|
12341
12587
|
}) {
|
|
12342
12588
|
try {
|
|
12343
12589
|
const total = await this.#db.client.oneOrNone(
|
|
12344
|
-
`SELECT COUNT(*) FROM ${
|
|
12590
|
+
`SELECT COUNT(*) FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2`,
|
|
12345
12591
|
[entityId, entityType]
|
|
12346
12592
|
);
|
|
12347
12593
|
const { page, perPage: perPageInput } = pagination;
|
|
@@ -12361,7 +12607,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
|
|
|
12361
12607
|
const limitValue = perPageInput === false ? Number(total?.count) : perPage;
|
|
12362
12608
|
const end = perPageInput === false ? Number(total?.count) : start + perPage;
|
|
12363
12609
|
const result = await this.#db.client.manyOrNone(
|
|
12364
|
-
`SELECT * FROM ${
|
|
12610
|
+
`SELECT * FROM ${getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
|
|
12365
12611
|
[entityId, entityType, limitValue, start]
|
|
12366
12612
|
);
|
|
12367
12613
|
return {
|
|
@@ -12390,7 +12636,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
|
|
|
12390
12636
|
pagination
|
|
12391
12637
|
}) {
|
|
12392
12638
|
try {
|
|
12393
|
-
const tableName =
|
|
12639
|
+
const tableName = getTableName6({ indexName: TABLE_SCORERS, schemaName: getSchemaName6(this.#schema) });
|
|
12394
12640
|
const countSQLResult = await this.#db.client.oneOrNone(
|
|
12395
12641
|
`SELECT COUNT(*) as count FROM ${tableName} WHERE "traceId" = $1 AND "spanId" = $2`,
|
|
12396
12642
|
[traceId, spanId]
|
|
@@ -13093,10 +13339,10 @@ var SkillsPG = class _SkillsPG extends SkillsStorage {
|
|
|
13093
13339
|
};
|
|
13094
13340
|
}
|
|
13095
13341
|
};
|
|
13096
|
-
function
|
|
13342
|
+
function getSchemaName7(schema) {
|
|
13097
13343
|
return schema ? `"${schema}"` : '"public"';
|
|
13098
13344
|
}
|
|
13099
|
-
function
|
|
13345
|
+
function getTableName7({ indexName, schemaName }) {
|
|
13100
13346
|
const quotedIndexName = `"${indexName}"`;
|
|
13101
13347
|
return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
|
|
13102
13348
|
}
|
|
@@ -13208,7 +13454,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
13208
13454
|
}) {
|
|
13209
13455
|
try {
|
|
13210
13456
|
return await this.#db.client.tx(async (t) => {
|
|
13211
|
-
const tableName =
|
|
13457
|
+
const tableName = getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) });
|
|
13212
13458
|
const existingSnapshotResult = await t.oneOrNone(
|
|
13213
13459
|
`SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
|
|
13214
13460
|
[workflowName, runId]
|
|
@@ -13269,7 +13515,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
13269
13515
|
}) {
|
|
13270
13516
|
try {
|
|
13271
13517
|
return await this.#db.client.tx(async (t) => {
|
|
13272
|
-
const tableName =
|
|
13518
|
+
const tableName = getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) });
|
|
13273
13519
|
const existingSnapshotResult = await t.oneOrNone(
|
|
13274
13520
|
`SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
|
|
13275
13521
|
[workflowName, runId]
|
|
@@ -13319,7 +13565,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
13319
13565
|
const updatedAtValue = updatedAt ? updatedAt : now;
|
|
13320
13566
|
const sanitizedSnapshot = sanitizeJsonForPg(JSON.stringify(snapshot));
|
|
13321
13567
|
await this.#db.client.none(
|
|
13322
|
-
`INSERT INTO ${
|
|
13568
|
+
`INSERT INTO ${getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
|
|
13323
13569
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
13324
13570
|
ON CONFLICT (workflow_name, run_id) DO UPDATE
|
|
13325
13571
|
SET "resourceId" = $3, snapshot = $4, "updatedAt" = $6`,
|
|
@@ -13377,7 +13623,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
13377
13623
|
}
|
|
13378
13624
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
13379
13625
|
const query = `
|
|
13380
|
-
SELECT * FROM ${
|
|
13626
|
+
SELECT * FROM ${getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })}
|
|
13381
13627
|
${whereClause}
|
|
13382
13628
|
ORDER BY "createdAt" DESC LIMIT 1
|
|
13383
13629
|
`;
|
|
@@ -13405,7 +13651,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
13405
13651
|
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
13406
13652
|
try {
|
|
13407
13653
|
await this.#db.client.none(
|
|
13408
|
-
`DELETE FROM ${
|
|
13654
|
+
`DELETE FROM ${getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} WHERE run_id = $1 AND workflow_name = $2`,
|
|
13409
13655
|
[runId, workflowName]
|
|
13410
13656
|
);
|
|
13411
13657
|
} catch (error) {
|
|
@@ -13473,7 +13719,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
13473
13719
|
const usePagination = typeof perPage === "number" && typeof page === "number";
|
|
13474
13720
|
if (usePagination) {
|
|
13475
13721
|
const countResult = await this.#db.client.one(
|
|
13476
|
-
`SELECT COUNT(*) as count FROM ${
|
|
13722
|
+
`SELECT COUNT(*) as count FROM ${getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })} ${whereClause}`,
|
|
13477
13723
|
values
|
|
13478
13724
|
);
|
|
13479
13725
|
total = Number(countResult.count);
|
|
@@ -13481,7 +13727,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
|
|
|
13481
13727
|
const normalizedPerPage = usePagination ? normalizePerPage(perPage, Number.MAX_SAFE_INTEGER) : 0;
|
|
13482
13728
|
const offset = usePagination ? page * normalizedPerPage : void 0;
|
|
13483
13729
|
const query = `
|
|
13484
|
-
SELECT * FROM ${
|
|
13730
|
+
SELECT * FROM ${getTableName7({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName7(this.#schema) })}
|
|
13485
13731
|
${whereClause}
|
|
13486
13732
|
ORDER BY "createdAt" DESC
|
|
13487
13733
|
${usePagination ? ` LIMIT $${paramIndex} OFFSET $${paramIndex + 1}` : ""}
|
|
@@ -14206,7 +14452,8 @@ var ALL_DOMAINS = [
|
|
|
14206
14452
|
DatasetsPG,
|
|
14207
14453
|
ExperimentsPG,
|
|
14208
14454
|
BackgroundTasksPG,
|
|
14209
|
-
ChannelsPG
|
|
14455
|
+
ChannelsPG,
|
|
14456
|
+
SchedulesPG
|
|
14210
14457
|
];
|
|
14211
14458
|
function exportSchemas(schemaName) {
|
|
14212
14459
|
const statements = [];
|
|
@@ -14262,7 +14509,8 @@ var PostgresStore = class extends MastraCompositeStore {
|
|
|
14262
14509
|
datasets: new DatasetsPG(domainConfig),
|
|
14263
14510
|
experiments: new ExperimentsPG(domainConfig),
|
|
14264
14511
|
backgroundTasks: new BackgroundTasksPG(domainConfig),
|
|
14265
|
-
channels: new ChannelsPG(domainConfig)
|
|
14512
|
+
channels: new ChannelsPG(domainConfig),
|
|
14513
|
+
schedules: new SchedulesPG(domainConfig)
|
|
14266
14514
|
};
|
|
14267
14515
|
} catch (e) {
|
|
14268
14516
|
throw new MastraError(
|
|
@@ -14451,6 +14699,6 @@ Example Complex Query:
|
|
|
14451
14699
|
]
|
|
14452
14700
|
}`;
|
|
14453
14701
|
|
|
14454
|
-
export { AgentsPG, BackgroundTasksPG, BlobsPG, ChannelsPG, DatasetsPG, ExperimentsPG, MCPClientsPG, MCPServersPG, MemoryPG, ObservabilityPG, PGVECTOR_PROMPT, PgVector, PoolAdapter, PostgresStore, PromptBlocksPG, ScorerDefinitionsPG, ScoresPG, SkillsPG, WorkflowsPG, WorkspacesPG, exportSchemas };
|
|
14702
|
+
export { AgentsPG, BackgroundTasksPG, BlobsPG, ChannelsPG, DatasetsPG, ExperimentsPG, MCPClientsPG, MCPServersPG, MemoryPG, ObservabilityPG, PGVECTOR_PROMPT, PgVector, PoolAdapter, PostgresStore, PromptBlocksPG, SchedulesPG, ScorerDefinitionsPG, ScoresPG, SkillsPG, WorkflowsPG, WorkspacesPG, exportSchemas };
|
|
14455
14703
|
//# sourceMappingURL=index.js.map
|
|
14456
14704
|
//# sourceMappingURL=index.js.map
|