@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/docs/SKILL.md
CHANGED
|
@@ -60,7 +60,7 @@ The background task worker manages concurrency limits, task lifecycle, and resul
|
|
|
60
60
|
|
|
61
61
|
### In-process mode (default)
|
|
62
62
|
|
|
63
|
-
With no configuration, Mastra
|
|
63
|
+
With no configuration, Mastra runs workers inside the API process. Events flow through an in-memory PubSub, and everything shares a single Node.js runtime.
|
|
64
64
|
|
|
65
65
|
```typescript
|
|
66
66
|
import { Mastra } from '@mastra/core/mastra'
|
|
@@ -71,6 +71,8 @@ export const mastra = new Mastra({
|
|
|
71
71
|
})
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
+
The server generated by `mastra build` starts these workers automatically. If you use a [server adapter](https://mastra.ai/docs/server/server-adapters) instead, add a call to `mastra.startWorkers()` after your server starts listening. See [Start background workers](https://mastra.ai/docs/server/server-adapters).
|
|
75
|
+
|
|
74
76
|
This setup needs no external infrastructure beyond your storage adapter. It doesn't survive process crashes, and you can't scale individual components.
|
|
75
77
|
|
|
76
78
|
### Split processes
|
package/dist/index.cjs
CHANGED
|
@@ -21,7 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
|
-
let crypto$1 = require("crypto");
|
|
25
24
|
let _mastra_core_error = require("@mastra/core/error");
|
|
26
25
|
let _mastra_core_storage = require("@mastra/core/storage");
|
|
27
26
|
_mastra_core_storage = __toESM(_mastra_core_storage, 1);
|
|
@@ -35,6 +34,7 @@ xxhash_wasm = __toESM(xxhash_wasm, 1);
|
|
|
35
34
|
let pg_connection_string = require("pg-connection-string");
|
|
36
35
|
let _mastra_core_vector_filter = require("@mastra/core/vector/filter");
|
|
37
36
|
let _mastra_core_base = require("@mastra/core/base");
|
|
37
|
+
let crypto$1 = require("crypto");
|
|
38
38
|
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");
|
|
@@ -849,7 +849,7 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
849
849
|
AND NOT attisdropped`, [tableName])).rowCount === 0) return;
|
|
850
850
|
await client.query(`ALTER TABLE ${tableName} ADD COLUMN IF NOT EXISTS namespace VARCHAR(255) NOT NULL DEFAULT '${DEFAULT_NAMESPACE}'`);
|
|
851
851
|
if (!(await this.getNamespaceSchemaState(tableName, client)).composite_index) {
|
|
852
|
-
const namespaceIndexName = this.getNamespaceIndexName(parsedIndexName);
|
|
852
|
+
const namespaceIndexName = await this.getNamespaceIndexName(parsedIndexName);
|
|
853
853
|
await client.query(`CREATE UNIQUE INDEX IF NOT EXISTS "${namespaceIndexName}" ON ${tableName} (namespace, vector_id)`);
|
|
854
854
|
}
|
|
855
855
|
const legacyConstraints = await client.query(`SELECT c.conname
|
|
@@ -862,10 +862,10 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
862
862
|
await client.query(`ALTER TABLE ${tableName} DROP CONSTRAINT "${parsedConstraintName}"`);
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
|
-
getNamespaceIndexName(parsedIndexName) {
|
|
865
|
+
async getNamespaceIndexName(parsedIndexName) {
|
|
866
866
|
const fullName = `${parsedIndexName}_namespace_vector_id_idx`;
|
|
867
867
|
if (fullName.length <= 63) return fullName;
|
|
868
|
-
const suffix = `_ns_${(
|
|
868
|
+
const suffix = `_ns_${Buffer.from(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(parsedIndexName))).toString("hex").slice(0, 32)}_idx`;
|
|
869
869
|
return `${parsedIndexName.slice(0, 63 - suffix.length)}${suffix}`;
|
|
870
870
|
}
|
|
871
871
|
async getNamespaceSchemaState(tableName, client) {
|
|
@@ -1000,6 +1000,8 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1000
1000
|
let client;
|
|
1001
1001
|
try {
|
|
1002
1002
|
await this.ensureNamespaceReady(indexName);
|
|
1003
|
+
const indexInfo = includeVector ? await this.getIndexMetadata({ indexName }) : void 0;
|
|
1004
|
+
const ops = indexInfo && this.getVectorOps(indexInfo.vectorType, indexInfo.metric ?? "cosine");
|
|
1003
1005
|
client = await this.pool.connect();
|
|
1004
1006
|
const { sql: filterQuery, values: filterValues } = buildDeleteFilterQuery(this.transformFilter(filter));
|
|
1005
1007
|
const { tableName } = this.getTableName(indexName);
|
|
@@ -1023,7 +1025,7 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1023
1025
|
id,
|
|
1024
1026
|
score: 0,
|
|
1025
1027
|
metadata,
|
|
1026
|
-
...
|
|
1028
|
+
...ops && embedding && { vector: ops.parseEmbedding(embedding) }
|
|
1027
1029
|
}));
|
|
1028
1030
|
} catch (error) {
|
|
1029
1031
|
if (error instanceof _mastra_core_error.MastraError) {
|
|
@@ -12677,7 +12679,7 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
12677
12679
|
});
|
|
12678
12680
|
const nowStr = (/* @__PURE__ */ new Date()).toISOString();
|
|
12679
12681
|
const newChunk = {
|
|
12680
|
-
id: `ombuf-${
|
|
12682
|
+
id: `ombuf-${globalThis.crypto.randomUUID()}`,
|
|
12681
12683
|
cycleId: input.chunk.cycleId,
|
|
12682
12684
|
observations: input.chunk.observations,
|
|
12683
12685
|
tokenCount: Math.round(input.chunk.tokenCount),
|
|
@@ -13247,7 +13249,7 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
|
|
|
13247
13249
|
}
|
|
13248
13250
|
const now = input.createdAt ?? /* @__PURE__ */ new Date();
|
|
13249
13251
|
const record = {
|
|
13250
|
-
id: input.id ??
|
|
13252
|
+
id: input.id ?? globalThis.crypto.randomUUID(),
|
|
13251
13253
|
threadId: input.threadId,
|
|
13252
13254
|
source: input.source,
|
|
13253
13255
|
kind: input.kind,
|
|
@@ -21500,7 +21502,6 @@ var SkillsPG = class SkillsPG extends _mastra_core_storage.SkillsStorage {
|
|
|
21500
21502
|
details: { skillId: id }
|
|
21501
21503
|
});
|
|
21502
21504
|
const { authorId, visibility, activeVersionId, status, ...rawConfigFields } = updates;
|
|
21503
|
-
let versionCreated = false;
|
|
21504
21505
|
const configFields = {};
|
|
21505
21506
|
for (const [key, value] of Object.entries(rawConfigFields)) if (value !== void 0) configFields[key] = value;
|
|
21506
21507
|
if (SNAPSHOT_FIELDS$1.some((field) => field in configFields)) {
|
|
@@ -21519,7 +21520,6 @@ var SkillsPG = class SkillsPG extends _mastra_core_storage.SkillsStorage {
|
|
|
21519
21520
|
};
|
|
21520
21521
|
const changedFields = SNAPSHOT_FIELDS$1.filter((field) => field in configFields && !(0, _mastra_core_storage_domains_skills.skillSnapshotFieldValuesEqual)(configFields[field], latestConfig[field]));
|
|
21521
21522
|
if (changedFields.length > 0) {
|
|
21522
|
-
versionCreated = true;
|
|
21523
21523
|
const newVersionId = crypto.randomUUID();
|
|
21524
21524
|
await this.createVersion({
|
|
21525
21525
|
id: newVersionId,
|
|
@@ -21560,7 +21560,7 @@ var SkillsPG = class SkillsPG extends _mastra_core_storage.SkillsStorage {
|
|
|
21560
21560
|
setClauses.push(`"updatedAtZ" = $${paramIndex++}`);
|
|
21561
21561
|
values.push(now);
|
|
21562
21562
|
values.push(id);
|
|
21563
|
-
|
|
21563
|
+
await this.#db.client.none(`UPDATE ${tableName} SET ${setClauses.join(", ")} WHERE id = $${paramIndex}`, values);
|
|
21564
21564
|
const updatedSkill = await this.#getById(this.#db.client, id);
|
|
21565
21565
|
if (!updatedSkill) throw new _mastra_core_error.MastraError({
|
|
21566
21566
|
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "UPDATE_SKILL", "NOT_FOUND_AFTER_UPDATE"),
|
|
@@ -22539,7 +22539,10 @@ var WorkflowDefinitionsPG = class WorkflowDefinitionsPG extends _mastra_core_sto
|
|
|
22539
22539
|
return this.applyUpdate(input, now);
|
|
22540
22540
|
}
|
|
22541
22541
|
async applyUpdate(input, now) {
|
|
22542
|
-
const data = {
|
|
22542
|
+
const data = {
|
|
22543
|
+
updatedAt: now,
|
|
22544
|
+
updatedAtZ: now
|
|
22545
|
+
};
|
|
22543
22546
|
if ("description" in input && input.description !== void 0) data.description = input.description;
|
|
22544
22547
|
if ("metadata" in input && input.metadata !== void 0) data.metadata = input.metadata;
|
|
22545
22548
|
if ("inputSchema" in input && input.inputSchema !== void 0) data.inputSchema = input.inputSchema;
|
|
@@ -23337,7 +23340,6 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
|
|
|
23337
23340
|
details: { workspaceId: id }
|
|
23338
23341
|
});
|
|
23339
23342
|
const { authorId, activeVersionId, metadata, status, ...rawConfigFields } = updates;
|
|
23340
|
-
let versionCreated = false;
|
|
23341
23343
|
const configFields = {};
|
|
23342
23344
|
for (const [key, value] of Object.entries(rawConfigFields)) if (value !== void 0) configFields[key] = value;
|
|
23343
23345
|
if (SNAPSHOT_FIELDS.some((field) => field in configFields)) {
|
|
@@ -23360,7 +23362,6 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
|
|
|
23360
23362
|
};
|
|
23361
23363
|
const changedFields = SNAPSHOT_FIELDS.filter((field) => field in configFields && !(0, util.isDeepStrictEqual)(normalized(configFields[field]), normalized(latestConfig[field])));
|
|
23362
23364
|
if (changedFields.length > 0) {
|
|
23363
|
-
versionCreated = true;
|
|
23364
23365
|
const newVersionId = crypto.randomUUID();
|
|
23365
23366
|
await this.createVersion({
|
|
23366
23367
|
id: newVersionId,
|
|
@@ -23406,7 +23407,7 @@ var WorkspacesPG = class WorkspacesPG extends _mastra_core_storage.WorkspacesSto
|
|
|
23406
23407
|
setClauses.push(`"updatedAtZ" = $${paramIndex++}`);
|
|
23407
23408
|
values.push(now);
|
|
23408
23409
|
values.push(id);
|
|
23409
|
-
|
|
23410
|
+
await this.#db.client.none(`UPDATE ${tableName} SET ${setClauses.join(", ")} WHERE id = $${paramIndex}`, values);
|
|
23410
23411
|
const updatedWorkspace = await this.#getById(this.#db.client, id);
|
|
23411
23412
|
if (!updatedWorkspace) throw new _mastra_core_error.MastraError({
|
|
23412
23413
|
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "UPDATE_WORKSPACE", "NOT_FOUND_AFTER_UPDATE"),
|
|
@@ -23968,7 +23969,7 @@ var PgFactoryStorageOps = class {
|
|
|
23968
23969
|
const schema = this.#schema(collection);
|
|
23969
23970
|
const pk = primaryKeyOf(schema);
|
|
23970
23971
|
const values = { ...row };
|
|
23971
|
-
if (schema.columns[pk].type === "uuid-pk" && values[pk] === void 0) values[pk] =
|
|
23972
|
+
if (schema.columns[pk].type === "uuid-pk" && values[pk] === void 0) values[pk] = globalThis.crypto.randomUUID();
|
|
23972
23973
|
const columns = Object.keys(values).filter((column) => values[column] !== void 0);
|
|
23973
23974
|
for (const column of columns) this.#column(schema, column);
|
|
23974
23975
|
const sql = `INSERT INTO "${schema.name}" (${columns.map((c) => `"${c}"`).join(", ")}) VALUES (${columns.map((_, i) => `$${i + 1}`).join(", ")}) RETURNING *`;
|