@mastra/pg 1.0.0 → 1.1.0-alpha.1
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 +102 -0
- package/dist/docs/README.md +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/SOURCE_MAP.json +1 -1
- package/dist/docs/memory/01-storage.md +115 -87
- package/dist/docs/memory/02-working-memory.md +22 -1
- package/dist/docs/memory/03-semantic-recall.md +45 -22
- package/dist/docs/memory/04-reference.md +11 -11
- package/dist/docs/processors/01-reference.md +6 -7
- package/dist/docs/rag/02-vector-databases.md +1 -1
- package/dist/docs/rag/03-retrieval.md +4 -4
- package/dist/docs/rag/04-reference.md +10 -10
- package/dist/docs/storage/01-reference.md +107 -30
- package/dist/docs/tools/01-reference.md +2 -2
- package/dist/docs/vectors/01-reference.md +2 -2
- package/dist/index.cjs +305 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +306 -83
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/agents/index.d.ts +11 -1
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +1 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
2
|
-
import { createVectorErrorId, TABLE_SCHEMAS, AgentsStorage, TABLE_AGENTS, createStorageErrorId, normalizePerPage, calculatePagination, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, MastraCompositeStore, TraceStatus, getDefaultValue, transformScoreRow as transformScoreRow$1, getSqlType } from '@mastra/core/storage';
|
|
2
|
+
import { createVectorErrorId, TABLE_SCHEMAS, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, 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';
|
|
@@ -3093,7 +3093,7 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
|
|
|
3093
3093
|
#skipDefaultIndexes;
|
|
3094
3094
|
#indexes;
|
|
3095
3095
|
/** Tables managed by this domain */
|
|
3096
|
-
static MANAGED_TABLES = [TABLE_AGENTS];
|
|
3096
|
+
static MANAGED_TABLES = [TABLE_AGENTS, TABLE_AGENT_VERSIONS];
|
|
3097
3097
|
constructor(config) {
|
|
3098
3098
|
super();
|
|
3099
3099
|
const { client, schemaName, skipDefaultIndexes, indexes } = resolvePgConfig(config);
|
|
@@ -3120,6 +3120,7 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
|
|
|
3120
3120
|
}
|
|
3121
3121
|
async init() {
|
|
3122
3122
|
await this.#db.createTable({ tableName: TABLE_AGENTS, schema: TABLE_SCHEMAS[TABLE_AGENTS] });
|
|
3123
|
+
await this.#db.createTable({ tableName: TABLE_AGENT_VERSIONS, schema: TABLE_SCHEMAS[TABLE_AGENT_VERSIONS] });
|
|
3123
3124
|
await this.createDefaultIndexes();
|
|
3124
3125
|
await this.createCustomIndexes();
|
|
3125
3126
|
}
|
|
@@ -3139,6 +3140,7 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
|
|
|
3139
3140
|
}
|
|
3140
3141
|
}
|
|
3141
3142
|
async dangerouslyClearAll() {
|
|
3143
|
+
await this.#db.clearTable({ tableName: TABLE_AGENT_VERSIONS });
|
|
3142
3144
|
await this.#db.clearTable({ tableName: TABLE_AGENTS });
|
|
3143
3145
|
}
|
|
3144
3146
|
parseJson(value, fieldName) {
|
|
@@ -3168,18 +3170,9 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
|
|
|
3168
3170
|
parseRow(row) {
|
|
3169
3171
|
return {
|
|
3170
3172
|
id: row.id,
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
model: this.parseJson(row.model, "model"),
|
|
3175
|
-
tools: this.parseJson(row.tools, "tools"),
|
|
3176
|
-
defaultOptions: this.parseJson(row.defaultOptions, "defaultOptions"),
|
|
3177
|
-
workflows: this.parseJson(row.workflows, "workflows"),
|
|
3178
|
-
agents: this.parseJson(row.agents, "agents"),
|
|
3179
|
-
inputProcessors: this.parseJson(row.inputProcessors, "inputProcessors"),
|
|
3180
|
-
outputProcessors: this.parseJson(row.outputProcessors, "outputProcessors"),
|
|
3181
|
-
memory: this.parseJson(row.memory, "memory"),
|
|
3182
|
-
scorers: this.parseJson(row.scorers, "scorers"),
|
|
3173
|
+
status: row.status,
|
|
3174
|
+
activeVersionId: row.activeVersionId,
|
|
3175
|
+
authorId: row.authorId,
|
|
3183
3176
|
metadata: this.parseJson(row.metadata, "metadata"),
|
|
3184
3177
|
createdAt: row.createdAtZ || row.createdAt,
|
|
3185
3178
|
updatedAt: row.updatedAtZ || row.updatedAt
|
|
@@ -3207,38 +3200,48 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
|
|
|
3207
3200
|
}
|
|
3208
3201
|
async createAgent({ agent }) {
|
|
3209
3202
|
try {
|
|
3210
|
-
const
|
|
3203
|
+
const agentsTable = getTableName2({ indexName: TABLE_AGENTS, schemaName: getSchemaName2(this.#schema) });
|
|
3211
3204
|
const now = /* @__PURE__ */ new Date();
|
|
3212
3205
|
const nowIso = now.toISOString();
|
|
3213
3206
|
await this.#db.client.none(
|
|
3214
|
-
`INSERT INTO ${
|
|
3215
|
-
id,
|
|
3216
|
-
"
|
|
3207
|
+
`INSERT INTO ${agentsTable} (
|
|
3208
|
+
id, status, "authorId", metadata,
|
|
3209
|
+
"activeVersionId",
|
|
3217
3210
|
"createdAt", "createdAtZ", "updatedAt", "updatedAtZ"
|
|
3218
|
-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9
|
|
3211
|
+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
|
|
3219
3212
|
[
|
|
3220
3213
|
agent.id,
|
|
3221
|
-
|
|
3222
|
-
agent.
|
|
3223
|
-
agent.instructions,
|
|
3224
|
-
JSON.stringify(agent.model),
|
|
3225
|
-
agent.tools ? JSON.stringify(agent.tools) : null,
|
|
3226
|
-
agent.defaultOptions ? JSON.stringify(agent.defaultOptions) : null,
|
|
3227
|
-
agent.workflows ? JSON.stringify(agent.workflows) : null,
|
|
3228
|
-
agent.agents ? JSON.stringify(agent.agents) : null,
|
|
3229
|
-
agent.inputProcessors ? JSON.stringify(agent.inputProcessors) : null,
|
|
3230
|
-
agent.outputProcessors ? JSON.stringify(agent.outputProcessors) : null,
|
|
3231
|
-
agent.memory ? JSON.stringify(agent.memory) : null,
|
|
3232
|
-
agent.scorers ? JSON.stringify(agent.scorers) : null,
|
|
3214
|
+
"draft",
|
|
3215
|
+
agent.authorId ?? null,
|
|
3233
3216
|
agent.metadata ? JSON.stringify(agent.metadata) : null,
|
|
3217
|
+
null,
|
|
3218
|
+
// activeVersionId starts as null
|
|
3234
3219
|
nowIso,
|
|
3235
3220
|
nowIso,
|
|
3236
3221
|
nowIso,
|
|
3237
3222
|
nowIso
|
|
3238
3223
|
]
|
|
3239
3224
|
);
|
|
3225
|
+
const { id: _id, authorId: _authorId, metadata: _metadata, ...snapshotConfig } = agent;
|
|
3226
|
+
const versionId = crypto.randomUUID();
|
|
3227
|
+
await this.createVersion({
|
|
3228
|
+
id: versionId,
|
|
3229
|
+
agentId: agent.id,
|
|
3230
|
+
versionNumber: 1,
|
|
3231
|
+
...snapshotConfig,
|
|
3232
|
+
changedFields: Object.keys(snapshotConfig),
|
|
3233
|
+
changeMessage: "Initial version"
|
|
3234
|
+
});
|
|
3235
|
+
await this.#db.client.none(
|
|
3236
|
+
`UPDATE ${agentsTable} SET "activeVersionId" = $1, status = $2, "updatedAt" = $3, "updatedAtZ" = $4 WHERE id = $5`,
|
|
3237
|
+
[versionId, "published", nowIso, nowIso, agent.id]
|
|
3238
|
+
);
|
|
3240
3239
|
return {
|
|
3241
|
-
|
|
3240
|
+
id: agent.id,
|
|
3241
|
+
status: "published",
|
|
3242
|
+
activeVersionId: versionId,
|
|
3243
|
+
authorId: agent.authorId,
|
|
3244
|
+
metadata: agent.metadata,
|
|
3242
3245
|
createdAt: now,
|
|
3243
3246
|
updatedAt: now
|
|
3244
3247
|
};
|
|
@@ -3270,53 +3273,15 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
|
|
|
3270
3273
|
const setClauses = [];
|
|
3271
3274
|
const values = [];
|
|
3272
3275
|
let paramIndex = 1;
|
|
3273
|
-
if (updates.
|
|
3274
|
-
setClauses.push(`
|
|
3275
|
-
values.push(updates.
|
|
3276
|
-
}
|
|
3277
|
-
if (updates.description !== void 0) {
|
|
3278
|
-
setClauses.push(`description = $${paramIndex++}`);
|
|
3279
|
-
values.push(updates.description);
|
|
3280
|
-
}
|
|
3281
|
-
if (updates.instructions !== void 0) {
|
|
3282
|
-
setClauses.push(`instructions = $${paramIndex++}`);
|
|
3283
|
-
values.push(updates.instructions);
|
|
3284
|
-
}
|
|
3285
|
-
if (updates.model !== void 0) {
|
|
3286
|
-
setClauses.push(`model = $${paramIndex++}`);
|
|
3287
|
-
values.push(JSON.stringify(updates.model));
|
|
3288
|
-
}
|
|
3289
|
-
if (updates.tools !== void 0) {
|
|
3290
|
-
setClauses.push(`tools = $${paramIndex++}`);
|
|
3291
|
-
values.push(JSON.stringify(updates.tools));
|
|
3292
|
-
}
|
|
3293
|
-
if (updates.defaultOptions !== void 0) {
|
|
3294
|
-
setClauses.push(`"defaultOptions" = $${paramIndex++}`);
|
|
3295
|
-
values.push(JSON.stringify(updates.defaultOptions));
|
|
3296
|
-
}
|
|
3297
|
-
if (updates.workflows !== void 0) {
|
|
3298
|
-
setClauses.push(`workflows = $${paramIndex++}`);
|
|
3299
|
-
values.push(JSON.stringify(updates.workflows));
|
|
3300
|
-
}
|
|
3301
|
-
if (updates.agents !== void 0) {
|
|
3302
|
-
setClauses.push(`agents = $${paramIndex++}`);
|
|
3303
|
-
values.push(JSON.stringify(updates.agents));
|
|
3304
|
-
}
|
|
3305
|
-
if (updates.inputProcessors !== void 0) {
|
|
3306
|
-
setClauses.push(`"inputProcessors" = $${paramIndex++}`);
|
|
3307
|
-
values.push(JSON.stringify(updates.inputProcessors));
|
|
3276
|
+
if (updates.authorId !== void 0) {
|
|
3277
|
+
setClauses.push(`"authorId" = $${paramIndex++}`);
|
|
3278
|
+
values.push(updates.authorId);
|
|
3308
3279
|
}
|
|
3309
|
-
if (updates.
|
|
3310
|
-
setClauses.push(`"
|
|
3311
|
-
values.push(
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
setClauses.push(`memory = $${paramIndex++}`);
|
|
3315
|
-
values.push(JSON.stringify(updates.memory));
|
|
3316
|
-
}
|
|
3317
|
-
if (updates.scorers !== void 0) {
|
|
3318
|
-
setClauses.push(`scorers = $${paramIndex++}`);
|
|
3319
|
-
values.push(JSON.stringify(updates.scorers));
|
|
3280
|
+
if (updates.activeVersionId !== void 0) {
|
|
3281
|
+
setClauses.push(`"activeVersionId" = $${paramIndex++}`);
|
|
3282
|
+
values.push(updates.activeVersionId);
|
|
3283
|
+
setClauses.push(`status = $${paramIndex++}`);
|
|
3284
|
+
values.push("published");
|
|
3320
3285
|
}
|
|
3321
3286
|
if (updates.metadata !== void 0) {
|
|
3322
3287
|
const mergedMetadata = { ...existingAgent.metadata, ...updates.metadata };
|
|
@@ -3364,6 +3329,7 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
|
|
|
3364
3329
|
async deleteAgent({ id }) {
|
|
3365
3330
|
try {
|
|
3366
3331
|
const tableName = getTableName2({ indexName: TABLE_AGENTS, schemaName: getSchemaName2(this.#schema) });
|
|
3332
|
+
await this.deleteVersionsByAgentId(id);
|
|
3367
3333
|
await this.#db.client.none(`DELETE FROM ${tableName} WHERE id = $1`, [id]);
|
|
3368
3334
|
} catch (error) {
|
|
3369
3335
|
throw new MastraError(
|
|
@@ -3430,6 +3396,261 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
|
|
|
3430
3396
|
);
|
|
3431
3397
|
}
|
|
3432
3398
|
}
|
|
3399
|
+
// ==========================================================================
|
|
3400
|
+
// Agent Version Methods
|
|
3401
|
+
// ==========================================================================
|
|
3402
|
+
async createVersion(input) {
|
|
3403
|
+
try {
|
|
3404
|
+
const tableName = getTableName2({ indexName: TABLE_AGENT_VERSIONS, schemaName: getSchemaName2(this.#schema) });
|
|
3405
|
+
const now = /* @__PURE__ */ new Date();
|
|
3406
|
+
const nowIso = now.toISOString();
|
|
3407
|
+
await this.#db.client.none(
|
|
3408
|
+
`INSERT INTO ${tableName} (
|
|
3409
|
+
id, "agentId", "versionNumber",
|
|
3410
|
+
name, description, instructions, model, tools,
|
|
3411
|
+
"defaultOptions", workflows, agents, "integrationTools",
|
|
3412
|
+
"inputProcessors", "outputProcessors", memory, scorers,
|
|
3413
|
+
"changedFields", "changeMessage",
|
|
3414
|
+
"createdAt", "createdAtZ"
|
|
3415
|
+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)`,
|
|
3416
|
+
[
|
|
3417
|
+
input.id,
|
|
3418
|
+
input.agentId,
|
|
3419
|
+
input.versionNumber,
|
|
3420
|
+
input.name,
|
|
3421
|
+
input.description ?? null,
|
|
3422
|
+
input.instructions,
|
|
3423
|
+
JSON.stringify(input.model),
|
|
3424
|
+
input.tools ? JSON.stringify(input.tools) : null,
|
|
3425
|
+
input.defaultOptions ? JSON.stringify(input.defaultOptions) : null,
|
|
3426
|
+
input.workflows ? JSON.stringify(input.workflows) : null,
|
|
3427
|
+
input.agents ? JSON.stringify(input.agents) : null,
|
|
3428
|
+
input.integrationTools ? JSON.stringify(input.integrationTools) : null,
|
|
3429
|
+
input.inputProcessors ? JSON.stringify(input.inputProcessors) : null,
|
|
3430
|
+
input.outputProcessors ? JSON.stringify(input.outputProcessors) : null,
|
|
3431
|
+
input.memory ? JSON.stringify(input.memory) : null,
|
|
3432
|
+
input.scorers ? JSON.stringify(input.scorers) : null,
|
|
3433
|
+
input.changedFields ? JSON.stringify(input.changedFields) : null,
|
|
3434
|
+
input.changeMessage ?? null,
|
|
3435
|
+
nowIso,
|
|
3436
|
+
nowIso
|
|
3437
|
+
]
|
|
3438
|
+
);
|
|
3439
|
+
return {
|
|
3440
|
+
...input,
|
|
3441
|
+
createdAt: now
|
|
3442
|
+
};
|
|
3443
|
+
} catch (error) {
|
|
3444
|
+
throw new MastraError(
|
|
3445
|
+
{
|
|
3446
|
+
id: createStorageErrorId("PG", "CREATE_VERSION", "FAILED"),
|
|
3447
|
+
domain: ErrorDomain.STORAGE,
|
|
3448
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
3449
|
+
details: { versionId: input.id, agentId: input.agentId }
|
|
3450
|
+
},
|
|
3451
|
+
error
|
|
3452
|
+
);
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
async getVersion(id) {
|
|
3456
|
+
try {
|
|
3457
|
+
const tableName = getTableName2({ indexName: TABLE_AGENT_VERSIONS, schemaName: getSchemaName2(this.#schema) });
|
|
3458
|
+
const result = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE id = $1`, [id]);
|
|
3459
|
+
if (!result) {
|
|
3460
|
+
return null;
|
|
3461
|
+
}
|
|
3462
|
+
return this.parseVersionRow(result);
|
|
3463
|
+
} catch (error) {
|
|
3464
|
+
throw new MastraError(
|
|
3465
|
+
{
|
|
3466
|
+
id: createStorageErrorId("PG", "GET_VERSION", "FAILED"),
|
|
3467
|
+
domain: ErrorDomain.STORAGE,
|
|
3468
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
3469
|
+
details: { versionId: id }
|
|
3470
|
+
},
|
|
3471
|
+
error
|
|
3472
|
+
);
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
async getVersionByNumber(agentId, versionNumber) {
|
|
3476
|
+
try {
|
|
3477
|
+
const tableName = getTableName2({ indexName: TABLE_AGENT_VERSIONS, schemaName: getSchemaName2(this.#schema) });
|
|
3478
|
+
const result = await this.#db.client.oneOrNone(
|
|
3479
|
+
`SELECT * FROM ${tableName} WHERE "agentId" = $1 AND "versionNumber" = $2`,
|
|
3480
|
+
[agentId, versionNumber]
|
|
3481
|
+
);
|
|
3482
|
+
if (!result) {
|
|
3483
|
+
return null;
|
|
3484
|
+
}
|
|
3485
|
+
return this.parseVersionRow(result);
|
|
3486
|
+
} catch (error) {
|
|
3487
|
+
throw new MastraError(
|
|
3488
|
+
{
|
|
3489
|
+
id: createStorageErrorId("PG", "GET_VERSION_BY_NUMBER", "FAILED"),
|
|
3490
|
+
domain: ErrorDomain.STORAGE,
|
|
3491
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
3492
|
+
details: { agentId, versionNumber }
|
|
3493
|
+
},
|
|
3494
|
+
error
|
|
3495
|
+
);
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
async getLatestVersion(agentId) {
|
|
3499
|
+
try {
|
|
3500
|
+
const tableName = getTableName2({ indexName: TABLE_AGENT_VERSIONS, schemaName: getSchemaName2(this.#schema) });
|
|
3501
|
+
const result = await this.#db.client.oneOrNone(
|
|
3502
|
+
`SELECT * FROM ${tableName} WHERE "agentId" = $1 ORDER BY "versionNumber" DESC LIMIT 1`,
|
|
3503
|
+
[agentId]
|
|
3504
|
+
);
|
|
3505
|
+
if (!result) {
|
|
3506
|
+
return null;
|
|
3507
|
+
}
|
|
3508
|
+
return this.parseVersionRow(result);
|
|
3509
|
+
} catch (error) {
|
|
3510
|
+
throw new MastraError(
|
|
3511
|
+
{
|
|
3512
|
+
id: createStorageErrorId("PG", "GET_LATEST_VERSION", "FAILED"),
|
|
3513
|
+
domain: ErrorDomain.STORAGE,
|
|
3514
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
3515
|
+
details: { agentId }
|
|
3516
|
+
},
|
|
3517
|
+
error
|
|
3518
|
+
);
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
async listVersions(input) {
|
|
3522
|
+
const { agentId, page = 0, perPage: perPageInput, orderBy } = input;
|
|
3523
|
+
if (page < 0) {
|
|
3524
|
+
throw new MastraError(
|
|
3525
|
+
{
|
|
3526
|
+
id: createStorageErrorId("PG", "LIST_VERSIONS", "INVALID_PAGE"),
|
|
3527
|
+
domain: ErrorDomain.STORAGE,
|
|
3528
|
+
category: ErrorCategory.USER,
|
|
3529
|
+
details: { page }
|
|
3530
|
+
},
|
|
3531
|
+
new Error("page must be >= 0")
|
|
3532
|
+
);
|
|
3533
|
+
}
|
|
3534
|
+
const perPage = normalizePerPage(perPageInput, 20);
|
|
3535
|
+
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
3536
|
+
try {
|
|
3537
|
+
const { field, direction } = this.parseVersionOrderBy(orderBy);
|
|
3538
|
+
const tableName = getTableName2({ indexName: TABLE_AGENT_VERSIONS, schemaName: getSchemaName2(this.#schema) });
|
|
3539
|
+
const countResult = await this.#db.client.one(`SELECT COUNT(*) as count FROM ${tableName} WHERE "agentId" = $1`, [
|
|
3540
|
+
agentId
|
|
3541
|
+
]);
|
|
3542
|
+
const total = parseInt(countResult.count, 10);
|
|
3543
|
+
if (total === 0) {
|
|
3544
|
+
return {
|
|
3545
|
+
versions: [],
|
|
3546
|
+
total: 0,
|
|
3547
|
+
page,
|
|
3548
|
+
perPage: perPageForResponse,
|
|
3549
|
+
hasMore: false
|
|
3550
|
+
};
|
|
3551
|
+
}
|
|
3552
|
+
const limitValue = perPageInput === false ? total : perPage;
|
|
3553
|
+
const dataResult = await this.#db.client.manyOrNone(
|
|
3554
|
+
`SELECT * FROM ${tableName} WHERE "agentId" = $1 ORDER BY "${field}" ${direction} LIMIT $2 OFFSET $3`,
|
|
3555
|
+
[agentId, limitValue, offset]
|
|
3556
|
+
);
|
|
3557
|
+
const versions = (dataResult || []).map((row) => this.parseVersionRow(row));
|
|
3558
|
+
return {
|
|
3559
|
+
versions,
|
|
3560
|
+
total,
|
|
3561
|
+
page,
|
|
3562
|
+
perPage: perPageForResponse,
|
|
3563
|
+
hasMore: perPageInput === false ? false : offset + perPage < total
|
|
3564
|
+
};
|
|
3565
|
+
} catch (error) {
|
|
3566
|
+
throw new MastraError(
|
|
3567
|
+
{
|
|
3568
|
+
id: createStorageErrorId("PG", "LIST_VERSIONS", "FAILED"),
|
|
3569
|
+
domain: ErrorDomain.STORAGE,
|
|
3570
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
3571
|
+
details: { agentId }
|
|
3572
|
+
},
|
|
3573
|
+
error
|
|
3574
|
+
);
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
async deleteVersion(id) {
|
|
3578
|
+
try {
|
|
3579
|
+
const tableName = getTableName2({ indexName: TABLE_AGENT_VERSIONS, schemaName: getSchemaName2(this.#schema) });
|
|
3580
|
+
await this.#db.client.none(`DELETE FROM ${tableName} WHERE id = $1`, [id]);
|
|
3581
|
+
} catch (error) {
|
|
3582
|
+
throw new MastraError(
|
|
3583
|
+
{
|
|
3584
|
+
id: createStorageErrorId("PG", "DELETE_VERSION", "FAILED"),
|
|
3585
|
+
domain: ErrorDomain.STORAGE,
|
|
3586
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
3587
|
+
details: { versionId: id }
|
|
3588
|
+
},
|
|
3589
|
+
error
|
|
3590
|
+
);
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
async deleteVersionsByAgentId(agentId) {
|
|
3594
|
+
try {
|
|
3595
|
+
const tableName = getTableName2({ indexName: TABLE_AGENT_VERSIONS, schemaName: getSchemaName2(this.#schema) });
|
|
3596
|
+
await this.#db.client.none(`DELETE FROM ${tableName} WHERE "agentId" = $1`, [agentId]);
|
|
3597
|
+
} catch (error) {
|
|
3598
|
+
throw new MastraError(
|
|
3599
|
+
{
|
|
3600
|
+
id: createStorageErrorId("PG", "DELETE_VERSIONS_BY_AGENT_ID", "FAILED"),
|
|
3601
|
+
domain: ErrorDomain.STORAGE,
|
|
3602
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
3603
|
+
details: { agentId }
|
|
3604
|
+
},
|
|
3605
|
+
error
|
|
3606
|
+
);
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
async countVersions(agentId) {
|
|
3610
|
+
try {
|
|
3611
|
+
const tableName = getTableName2({ indexName: TABLE_AGENT_VERSIONS, schemaName: getSchemaName2(this.#schema) });
|
|
3612
|
+
const result = await this.#db.client.one(`SELECT COUNT(*) as count FROM ${tableName} WHERE "agentId" = $1`, [
|
|
3613
|
+
agentId
|
|
3614
|
+
]);
|
|
3615
|
+
return parseInt(result.count, 10);
|
|
3616
|
+
} catch (error) {
|
|
3617
|
+
throw new MastraError(
|
|
3618
|
+
{
|
|
3619
|
+
id: createStorageErrorId("PG", "COUNT_VERSIONS", "FAILED"),
|
|
3620
|
+
domain: ErrorDomain.STORAGE,
|
|
3621
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
3622
|
+
details: { agentId }
|
|
3623
|
+
},
|
|
3624
|
+
error
|
|
3625
|
+
);
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
// ==========================================================================
|
|
3629
|
+
// Private Helper Methods
|
|
3630
|
+
// ==========================================================================
|
|
3631
|
+
parseVersionRow(row) {
|
|
3632
|
+
return {
|
|
3633
|
+
id: row.id,
|
|
3634
|
+
agentId: row.agentId,
|
|
3635
|
+
versionNumber: row.versionNumber,
|
|
3636
|
+
name: row.name,
|
|
3637
|
+
description: row.description,
|
|
3638
|
+
instructions: row.instructions,
|
|
3639
|
+
model: this.parseJson(row.model, "model"),
|
|
3640
|
+
tools: this.parseJson(row.tools, "tools"),
|
|
3641
|
+
defaultOptions: this.parseJson(row.defaultOptions, "defaultOptions"),
|
|
3642
|
+
workflows: this.parseJson(row.workflows, "workflows"),
|
|
3643
|
+
agents: this.parseJson(row.agents, "agents"),
|
|
3644
|
+
integrationTools: this.parseJson(row.integrationTools, "integrationTools"),
|
|
3645
|
+
inputProcessors: this.parseJson(row.inputProcessors, "inputProcessors"),
|
|
3646
|
+
outputProcessors: this.parseJson(row.outputProcessors, "outputProcessors"),
|
|
3647
|
+
memory: this.parseJson(row.memory, "memory"),
|
|
3648
|
+
scorers: this.parseJson(row.scorers, "scorers"),
|
|
3649
|
+
changedFields: this.parseJson(row.changedFields, "changedFields"),
|
|
3650
|
+
changeMessage: row.changeMessage,
|
|
3651
|
+
createdAt: row.createdAtZ || row.createdAt
|
|
3652
|
+
};
|
|
3653
|
+
}
|
|
3433
3654
|
};
|
|
3434
3655
|
function getSchemaName3(schema) {
|
|
3435
3656
|
return schema ? `"${schema}"` : '"public"';
|
|
@@ -5016,11 +5237,13 @@ var ObservabilityPG = class _ObservabilityPG extends ObservabilityStorage {
|
|
|
5016
5237
|
perPage,
|
|
5017
5238
|
hasMore: (page + 1) * perPage < count
|
|
5018
5239
|
},
|
|
5019
|
-
spans:
|
|
5020
|
-
(
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5240
|
+
spans: toTraceSpans(
|
|
5241
|
+
spans.map(
|
|
5242
|
+
(span) => transformFromSqlRow({
|
|
5243
|
+
tableName: TABLE_SPANS,
|
|
5244
|
+
sqlRow: span
|
|
5245
|
+
})
|
|
5246
|
+
)
|
|
5024
5247
|
)
|
|
5025
5248
|
};
|
|
5026
5249
|
} catch (error) {
|