@mastra/pg 1.28.0 → 1.28.1-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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-deployment-workers.md +3 -1
- package/dist/index.cjs +16 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -15
- package/dist/index.js.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/skills/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/dist/vector/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createHash, randomUUID } from "crypto";
|
|
2
1
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
3
2
|
import * as coreStorage from "@mastra/core/storage";
|
|
4
3
|
import { AgentsStorage, BRANCH_SPAN_TYPES, BackgroundTasksStorage, BlobStore, ChannelsStorage, DATASETS_SCHEMA, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, DatasetsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, EntityType, ExperimentsStorage, FactoryStorage, FavoritesStorage, KNOWLEDGE_ACTIVITY_SCHEMA, KNOWLEDGE_CURSORS_SCHEMA, KNOWLEDGE_MENTIONS_SCHEMA, KNOWLEDGE_NODES_SCHEMA, KNOWLEDGE_RECORDS_SCHEMA, KNOWLEDGE_SEMANTIC_OUTBOX_SCHEMA, KnowledgeConflictError, KnowledgeNotFoundError, KnowledgeStorage, MCPClientsStorage, MCPServersStorage, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, NotificationsStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PromptBlocksStorage, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_CONFIGS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_CURSORS, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_NOTIFICATIONS, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_THREAD_STATE, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, ThreadStateStorage, ToolProviderConnectionsStorage, TraceStatus, UniqueViolationError, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, assertKnowledgeCeilingRaised, assertKnowledgeScopeWithinCeiling, calculatePagination, canonicalizeKnowledgeScope, createKnowledgeUlid, createStorageErrorId, createVectorErrorId, ensureDate, executeRetentionPrune, getDefaultValue, getSqlType, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, matchesExpectedWorkflowStatus, mergeWorkflowStepResult, normalizePerPage, normalizeScheduleTarget, parseDuration, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, resolveListOrderBy, resolveRetentionTargets, retentionCutoffMs, runRetentionBatches, safelyParseJSON, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
@@ -11,6 +10,7 @@ import xxhash from "xxhash-wasm";
|
|
|
11
10
|
import { parse } from "pg-connection-string";
|
|
12
11
|
import { BaseFilterTranslator } from "@mastra/core/vector/filter";
|
|
13
12
|
import { MastraBase } from "@mastra/core/base";
|
|
13
|
+
import { createHash } from "crypto";
|
|
14
14
|
import { MessageList } from "@mastra/core/agent";
|
|
15
15
|
import { coreFeatures } from "@mastra/core/features";
|
|
16
16
|
import { saveScorePayloadSchema } from "@mastra/core/evals";
|
|
@@ -825,7 +825,7 @@ var PgVector = class extends MastraVector {
|
|
|
825
825
|
AND NOT attisdropped`, [tableName])).rowCount === 0) return;
|
|
826
826
|
await client.query(`ALTER TABLE ${tableName} ADD COLUMN IF NOT EXISTS namespace VARCHAR(255) NOT NULL DEFAULT '${DEFAULT_NAMESPACE}'`);
|
|
827
827
|
if (!(await this.getNamespaceSchemaState(tableName, client)).composite_index) {
|
|
828
|
-
const namespaceIndexName = this.getNamespaceIndexName(parsedIndexName);
|
|
828
|
+
const namespaceIndexName = await this.getNamespaceIndexName(parsedIndexName);
|
|
829
829
|
await client.query(`CREATE UNIQUE INDEX IF NOT EXISTS "${namespaceIndexName}" ON ${tableName} (namespace, vector_id)`);
|
|
830
830
|
}
|
|
831
831
|
const legacyConstraints = await client.query(`SELECT c.conname
|
|
@@ -838,10 +838,10 @@ var PgVector = class extends MastraVector {
|
|
|
838
838
|
await client.query(`ALTER TABLE ${tableName} DROP CONSTRAINT "${parsedConstraintName}"`);
|
|
839
839
|
}
|
|
840
840
|
}
|
|
841
|
-
getNamespaceIndexName(parsedIndexName) {
|
|
841
|
+
async getNamespaceIndexName(parsedIndexName) {
|
|
842
842
|
const fullName = `${parsedIndexName}_namespace_vector_id_idx`;
|
|
843
843
|
if (fullName.length <= 63) return fullName;
|
|
844
|
-
const suffix = `_ns_${
|
|
844
|
+
const suffix = `_ns_${Buffer.from(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(parsedIndexName))).toString("hex").slice(0, 32)}_idx`;
|
|
845
845
|
return `${parsedIndexName.slice(0, 63 - suffix.length)}${suffix}`;
|
|
846
846
|
}
|
|
847
847
|
async getNamespaceSchemaState(tableName, client) {
|
|
@@ -976,6 +976,8 @@ var PgVector = class extends MastraVector {
|
|
|
976
976
|
let client;
|
|
977
977
|
try {
|
|
978
978
|
await this.ensureNamespaceReady(indexName);
|
|
979
|
+
const indexInfo = includeVector ? await this.getIndexMetadata({ indexName }) : void 0;
|
|
980
|
+
const ops = indexInfo && this.getVectorOps(indexInfo.vectorType, indexInfo.metric ?? "cosine");
|
|
979
981
|
client = await this.pool.connect();
|
|
980
982
|
const { sql: filterQuery, values: filterValues } = buildDeleteFilterQuery(this.transformFilter(filter));
|
|
981
983
|
const { tableName } = this.getTableName(indexName);
|
|
@@ -999,7 +1001,7 @@ var PgVector = class extends MastraVector {
|
|
|
999
1001
|
id,
|
|
1000
1002
|
score: 0,
|
|
1001
1003
|
metadata,
|
|
1002
|
-
...
|
|
1004
|
+
...ops && embedding && { vector: ops.parseEmbedding(embedding) }
|
|
1003
1005
|
}));
|
|
1004
1006
|
} catch (error) {
|
|
1005
1007
|
if (error instanceof MastraError) {
|
|
@@ -12653,7 +12655,7 @@ var MemoryPG = class MemoryPG extends MemoryStorage {
|
|
|
12653
12655
|
});
|
|
12654
12656
|
const nowStr = (/* @__PURE__ */ new Date()).toISOString();
|
|
12655
12657
|
const newChunk = {
|
|
12656
|
-
id: `ombuf-${randomUUID()}`,
|
|
12658
|
+
id: `ombuf-${globalThis.crypto.randomUUID()}`,
|
|
12657
12659
|
cycleId: input.chunk.cycleId,
|
|
12658
12660
|
observations: input.chunk.observations,
|
|
12659
12661
|
tokenCount: Math.round(input.chunk.tokenCount),
|
|
@@ -13223,7 +13225,7 @@ var NotificationsPG = class NotificationsPG extends NotificationsStorage {
|
|
|
13223
13225
|
}
|
|
13224
13226
|
const now = input.createdAt ?? /* @__PURE__ */ new Date();
|
|
13225
13227
|
const record = {
|
|
13226
|
-
id: input.id ?? randomUUID(),
|
|
13228
|
+
id: input.id ?? globalThis.crypto.randomUUID(),
|
|
13227
13229
|
threadId: input.threadId,
|
|
13228
13230
|
source: input.source,
|
|
13229
13231
|
kind: input.kind,
|
|
@@ -21476,7 +21478,6 @@ var SkillsPG = class SkillsPG extends SkillsStorage {
|
|
|
21476
21478
|
details: { skillId: id }
|
|
21477
21479
|
});
|
|
21478
21480
|
const { authorId, visibility, activeVersionId, status, ...rawConfigFields } = updates;
|
|
21479
|
-
let versionCreated = false;
|
|
21480
21481
|
const configFields = {};
|
|
21481
21482
|
for (const [key, value] of Object.entries(rawConfigFields)) if (value !== void 0) configFields[key] = value;
|
|
21482
21483
|
if (SNAPSHOT_FIELDS$1.some((field) => field in configFields)) {
|
|
@@ -21495,7 +21496,6 @@ var SkillsPG = class SkillsPG extends SkillsStorage {
|
|
|
21495
21496
|
};
|
|
21496
21497
|
const changedFields = SNAPSHOT_FIELDS$1.filter((field) => field in configFields && !skillSnapshotFieldValuesEqual(configFields[field], latestConfig[field]));
|
|
21497
21498
|
if (changedFields.length > 0) {
|
|
21498
|
-
versionCreated = true;
|
|
21499
21499
|
const newVersionId = crypto.randomUUID();
|
|
21500
21500
|
await this.createVersion({
|
|
21501
21501
|
id: newVersionId,
|
|
@@ -21536,7 +21536,7 @@ var SkillsPG = class SkillsPG extends SkillsStorage {
|
|
|
21536
21536
|
setClauses.push(`"updatedAtZ" = $${paramIndex++}`);
|
|
21537
21537
|
values.push(now);
|
|
21538
21538
|
values.push(id);
|
|
21539
|
-
|
|
21539
|
+
await this.#db.client.none(`UPDATE ${tableName} SET ${setClauses.join(", ")} WHERE id = $${paramIndex}`, values);
|
|
21540
21540
|
const updatedSkill = await this.#getById(this.#db.client, id);
|
|
21541
21541
|
if (!updatedSkill) throw new MastraError({
|
|
21542
21542
|
id: createStorageErrorId("PG", "UPDATE_SKILL", "NOT_FOUND_AFTER_UPDATE"),
|
|
@@ -22515,7 +22515,10 @@ var WorkflowDefinitionsPG = class WorkflowDefinitionsPG extends WorkflowDefiniti
|
|
|
22515
22515
|
return this.applyUpdate(input, now);
|
|
22516
22516
|
}
|
|
22517
22517
|
async applyUpdate(input, now) {
|
|
22518
|
-
const data = {
|
|
22518
|
+
const data = {
|
|
22519
|
+
updatedAt: now,
|
|
22520
|
+
updatedAtZ: now
|
|
22521
|
+
};
|
|
22519
22522
|
if ("description" in input && input.description !== void 0) data.description = input.description;
|
|
22520
22523
|
if ("metadata" in input && input.metadata !== void 0) data.metadata = input.metadata;
|
|
22521
22524
|
if ("inputSchema" in input && input.inputSchema !== void 0) data.inputSchema = input.inputSchema;
|
|
@@ -23313,7 +23316,6 @@ var WorkspacesPG = class WorkspacesPG extends WorkspacesStorage {
|
|
|
23313
23316
|
details: { workspaceId: id }
|
|
23314
23317
|
});
|
|
23315
23318
|
const { authorId, activeVersionId, metadata, status, ...rawConfigFields } = updates;
|
|
23316
|
-
let versionCreated = false;
|
|
23317
23319
|
const configFields = {};
|
|
23318
23320
|
for (const [key, value] of Object.entries(rawConfigFields)) if (value !== void 0) configFields[key] = value;
|
|
23319
23321
|
if (SNAPSHOT_FIELDS.some((field) => field in configFields)) {
|
|
@@ -23336,7 +23338,6 @@ var WorkspacesPG = class WorkspacesPG extends WorkspacesStorage {
|
|
|
23336
23338
|
};
|
|
23337
23339
|
const changedFields = SNAPSHOT_FIELDS.filter((field) => field in configFields && !isDeepStrictEqual(normalized(configFields[field]), normalized(latestConfig[field])));
|
|
23338
23340
|
if (changedFields.length > 0) {
|
|
23339
|
-
versionCreated = true;
|
|
23340
23341
|
const newVersionId = crypto.randomUUID();
|
|
23341
23342
|
await this.createVersion({
|
|
23342
23343
|
id: newVersionId,
|
|
@@ -23382,7 +23383,7 @@ var WorkspacesPG = class WorkspacesPG extends WorkspacesStorage {
|
|
|
23382
23383
|
setClauses.push(`"updatedAtZ" = $${paramIndex++}`);
|
|
23383
23384
|
values.push(now);
|
|
23384
23385
|
values.push(id);
|
|
23385
|
-
|
|
23386
|
+
await this.#db.client.none(`UPDATE ${tableName} SET ${setClauses.join(", ")} WHERE id = $${paramIndex}`, values);
|
|
23386
23387
|
const updatedWorkspace = await this.#getById(this.#db.client, id);
|
|
23387
23388
|
if (!updatedWorkspace) throw new MastraError({
|
|
23388
23389
|
id: createStorageErrorId("PG", "UPDATE_WORKSPACE", "NOT_FOUND_AFTER_UPDATE"),
|
|
@@ -23944,7 +23945,7 @@ var PgFactoryStorageOps = class {
|
|
|
23944
23945
|
const schema = this.#schema(collection);
|
|
23945
23946
|
const pk = primaryKeyOf(schema);
|
|
23946
23947
|
const values = { ...row };
|
|
23947
|
-
if (schema.columns[pk].type === "uuid-pk" && values[pk] === void 0) values[pk] = randomUUID();
|
|
23948
|
+
if (schema.columns[pk].type === "uuid-pk" && values[pk] === void 0) values[pk] = globalThis.crypto.randomUUID();
|
|
23948
23949
|
const columns = Object.keys(values).filter((column) => values[column] !== void 0);
|
|
23949
23950
|
for (const column of columns) this.#column(schema, column);
|
|
23950
23951
|
const sql = `INSERT INTO "${schema.name}" (${columns.map((c) => `"${c}"`).join(", ")}) VALUES (${columns.map((_, i) => `$${i + 1}`).join(", ")}) RETURNING *`;
|