@mastra/pg 1.36.0-alpha.1 → 1.36.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 +30 -30
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-processors-semantic-recall-processor.md +5 -3
- package/dist/index.cjs +29 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -23
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +5 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/schema-snapshot.d.ts +8 -0
- package/dist/storage/db/schema-snapshot.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.36.0-alpha.
|
|
2
|
+
"version": "1.36.0-alpha.2",
|
|
3
3
|
"package": "@mastra/pg",
|
|
4
4
|
"exports": {
|
|
5
5
|
"AgentsPG": {
|
|
6
6
|
"types": "dist/storage/domains/agents/index.d.ts",
|
|
7
7
|
"implementation": "dist/index.js",
|
|
8
|
-
"line":
|
|
8
|
+
"line": 4371
|
|
9
9
|
},
|
|
10
10
|
"BackgroundTasksPG": {
|
|
11
11
|
"types": "dist/storage/domains/background-tasks/index.d.ts",
|
|
12
12
|
"implementation": "dist/index.js",
|
|
13
|
-
"line":
|
|
13
|
+
"line": 5302
|
|
14
14
|
},
|
|
15
15
|
"BlobsPG": {
|
|
16
16
|
"types": "dist/storage/domains/blobs/index.d.ts",
|
|
17
17
|
"implementation": "dist/index.js",
|
|
18
|
-
"line":
|
|
18
|
+
"line": 5693
|
|
19
19
|
},
|
|
20
20
|
"ChannelsPG": {
|
|
21
21
|
"types": "dist/storage/domains/channels/index.d.ts",
|
|
22
22
|
"implementation": "dist/index.js",
|
|
23
|
-
"line":
|
|
23
|
+
"line": 5795
|
|
24
24
|
},
|
|
25
25
|
"DatasetsPG": {
|
|
26
26
|
"types": "dist/storage/domains/datasets/index.d.ts",
|
|
27
27
|
"implementation": "dist/index.js",
|
|
28
|
-
"line":
|
|
28
|
+
"line": 6037
|
|
29
29
|
},
|
|
30
30
|
"ExperimentsPG": {
|
|
31
31
|
"types": "dist/storage/domains/experiments/index.d.ts",
|
|
32
32
|
"implementation": "dist/index.js",
|
|
33
|
-
"line":
|
|
33
|
+
"line": 7294
|
|
34
34
|
},
|
|
35
35
|
"FavoritesPG": {
|
|
36
36
|
"types": "dist/storage/domains/favorites/index.d.ts",
|
|
37
37
|
"implementation": "dist/index.js",
|
|
38
|
-
"line":
|
|
38
|
+
"line": 8266
|
|
39
39
|
},
|
|
40
40
|
"KnowledgePG": {
|
|
41
41
|
"types": "dist/storage/domains/knowledge/index.d.ts",
|
|
42
42
|
"implementation": "dist/index.js",
|
|
43
|
-
"line":
|
|
43
|
+
"line": 10144
|
|
44
44
|
},
|
|
45
45
|
"MCPClientsPG": {
|
|
46
46
|
"types": "dist/storage/domains/mcp-clients/index.d.ts",
|
|
47
47
|
"implementation": "dist/index.js",
|
|
48
|
-
"line":
|
|
48
|
+
"line": 10301
|
|
49
49
|
},
|
|
50
50
|
"MCPServersPG": {
|
|
51
51
|
"types": "dist/storage/domains/mcp-servers/index.d.ts",
|
|
52
52
|
"implementation": "dist/index.js",
|
|
53
|
-
"line":
|
|
53
|
+
"line": 10870
|
|
54
54
|
},
|
|
55
55
|
"MemoryPG": {
|
|
56
56
|
"types": "dist/storage/domains/memory/index.d.ts",
|
|
57
57
|
"implementation": "dist/index.js",
|
|
58
|
-
"line":
|
|
58
|
+
"line": 11658
|
|
59
59
|
},
|
|
60
60
|
"NotificationsPG": {
|
|
61
61
|
"types": "dist/storage/domains/notifications/index.d.ts",
|
|
62
62
|
"implementation": "dist/index.js",
|
|
63
|
-
"line":
|
|
63
|
+
"line": 14469
|
|
64
64
|
},
|
|
65
65
|
"ObservabilityPG": {
|
|
66
66
|
"types": "dist/storage/domains/observability/index.d.ts",
|
|
67
67
|
"implementation": "dist/index.js",
|
|
68
|
-
"line":
|
|
68
|
+
"line": 14891
|
|
69
69
|
},
|
|
70
70
|
"ObservabilityStoragePostgresVNext": {
|
|
71
71
|
"types": "dist/storage/domains/observability/v-next/index.d.ts",
|
|
72
72
|
"implementation": "dist/index.js",
|
|
73
|
-
"line":
|
|
73
|
+
"line": 21810
|
|
74
74
|
},
|
|
75
75
|
"PGVECTOR_PROMPT": {
|
|
76
76
|
"types": "dist/vector/prompt.d.ts",
|
|
77
77
|
"implementation": "dist/index.js",
|
|
78
|
-
"line":
|
|
78
|
+
"line": 28481
|
|
79
79
|
},
|
|
80
80
|
"PgFactoryStorage": {
|
|
81
81
|
"types": "dist/storage/factory-storage.d.ts",
|
|
82
82
|
"implementation": "dist/index.js",
|
|
83
|
-
"line":
|
|
83
|
+
"line": 27967
|
|
84
84
|
},
|
|
85
85
|
"PgVector": {
|
|
86
86
|
"types": "dist/vector/index.d.ts",
|
|
@@ -95,67 +95,67 @@
|
|
|
95
95
|
"PostgresStore": {
|
|
96
96
|
"types": "dist/storage/index.d.ts",
|
|
97
97
|
"implementation": "dist/index.js",
|
|
98
|
-
"line":
|
|
98
|
+
"line": 28182
|
|
99
99
|
},
|
|
100
100
|
"PostgresStoreVNext": {
|
|
101
101
|
"types": "dist/storage/index.d.ts",
|
|
102
102
|
"implementation": "dist/index.js",
|
|
103
|
-
"line":
|
|
103
|
+
"line": 28400
|
|
104
104
|
},
|
|
105
105
|
"PromptBlocksPG": {
|
|
106
106
|
"types": "dist/storage/domains/prompt-blocks/index.d.ts",
|
|
107
107
|
"implementation": "dist/index.js",
|
|
108
|
-
"line":
|
|
108
|
+
"line": 22255
|
|
109
109
|
},
|
|
110
110
|
"SchedulesPG": {
|
|
111
111
|
"types": "dist/storage/domains/schedules/index.d.ts",
|
|
112
112
|
"implementation": "dist/index.js",
|
|
113
|
-
"line":
|
|
113
|
+
"line": 22882
|
|
114
114
|
},
|
|
115
115
|
"ScorerDefinitionsPG": {
|
|
116
116
|
"types": "dist/storage/domains/scorer-definitions/index.d.ts",
|
|
117
117
|
"implementation": "dist/index.js",
|
|
118
|
-
"line":
|
|
118
|
+
"line": 23203
|
|
119
119
|
},
|
|
120
120
|
"ScoresPG": {
|
|
121
121
|
"types": "dist/storage/domains/scores/index.d.ts",
|
|
122
122
|
"implementation": "dist/index.js",
|
|
123
|
-
"line":
|
|
123
|
+
"line": 23826
|
|
124
124
|
},
|
|
125
125
|
"SkillsPG": {
|
|
126
126
|
"types": "dist/storage/domains/skills/index.d.ts",
|
|
127
127
|
"implementation": "dist/index.js",
|
|
128
|
-
"line":
|
|
128
|
+
"line": 24269
|
|
129
129
|
},
|
|
130
130
|
"ThreadStatePG": {
|
|
131
131
|
"types": "dist/storage/domains/thread-state/index.d.ts",
|
|
132
132
|
"implementation": "dist/index.js",
|
|
133
|
-
"line":
|
|
133
|
+
"line": 24960
|
|
134
134
|
},
|
|
135
135
|
"ToolProviderConnectionsPG": {
|
|
136
136
|
"types": "dist/storage/domains/tool-provider-connections/index.d.ts",
|
|
137
137
|
"implementation": "dist/index.js",
|
|
138
|
-
"line":
|
|
138
|
+
"line": 25134
|
|
139
139
|
},
|
|
140
140
|
"WorkflowDefinitionsPG": {
|
|
141
141
|
"types": "dist/storage/domains/workflow-definitions/index.d.ts",
|
|
142
142
|
"implementation": "dist/index.js",
|
|
143
|
-
"line":
|
|
143
|
+
"line": 25398
|
|
144
144
|
},
|
|
145
145
|
"WorkflowsPG": {
|
|
146
146
|
"types": "dist/storage/domains/workflows/index.d.ts",
|
|
147
147
|
"implementation": "dist/index.js",
|
|
148
|
-
"line":
|
|
148
|
+
"line": 25781
|
|
149
149
|
},
|
|
150
150
|
"WorkspacesPG": {
|
|
151
151
|
"types": "dist/storage/domains/workspaces/index.d.ts",
|
|
152
152
|
"implementation": "dist/index.js",
|
|
153
|
-
"line":
|
|
153
|
+
"line": 27067
|
|
154
154
|
},
|
|
155
155
|
"exportSchemas": {
|
|
156
156
|
"types": "dist/storage/index.d.ts",
|
|
157
157
|
"implementation": "dist/index.js",
|
|
158
|
-
"line":
|
|
158
|
+
"line": 28149
|
|
159
159
|
}
|
|
160
160
|
},
|
|
161
161
|
"modules": {}
|
|
@@ -49,7 +49,7 @@ export const agent = new Agent({
|
|
|
49
49
|
|
|
50
50
|
**options.retainFullInput** (`boolean`): When true, the request input is processed exactly as supplied instead of being filtered against stored history. Use this when you assemble the input yourself and need the message sequence preserved. Stored history is still loaded underneath, and every input message that isn't already stored is saved to the thread, including few-shot examples. Can be set per call on memory.options or agent-wide in the memory constructor options.
|
|
51
51
|
|
|
52
|
-
**options.semanticRecall** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource' }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires a vector store, and an embedder unless the vector store embeds text itself (isSelfEmbedding). Default topK is 4, default messageRange is {before: 1, after: 1}.
|
|
52
|
+
**options.semanticRecall** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource'; maxChunkChars?: number }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires a vector store, and an embedder unless the vector store embeds text itself (isSelfEmbedding). Default topK is 4, default messageRange is {before: 1, after: 1}. maxChunkChars caps the characters of message text per embedded chunk; see Long messages.
|
|
53
53
|
|
|
54
54
|
**options.workingMemory** (`WorkingMemory`): Configuration for working memory feature. Can be { enabled: boolean; template?: string; schema?: ZodObject\<any> | JSONSchema7; scope?: 'thread' | 'resource' } or { enabled: boolean } to disable.
|
|
55
55
|
|
|
@@ -44,6 +44,8 @@ const processor = new SemanticRecall({
|
|
|
44
44
|
|
|
45
45
|
**options.logger** (`IMastraLogger`): Optional logger instance for structured logging
|
|
46
46
|
|
|
47
|
+
**options.maxChunkChars** (`number`): Largest number of characters of message text sent to the embedder in one input. Longer messages are split into chunks, each stored as its own vector row. When unset, the limit comes from the embedder's maxInputTokens if it declares one (FastEmbed models do), otherwise 16,384 characters (about 4,096 English tokens).
|
|
48
|
+
|
|
47
49
|
## Returns
|
|
48
50
|
|
|
49
51
|
**id** (`string`): Processor identifier set to 'semantic-recall'
|
|
@@ -105,9 +107,9 @@ export const agent = new Agent({
|
|
|
105
107
|
|
|
106
108
|
### Output processing
|
|
107
109
|
|
|
108
|
-
1. Extracts text content from new user and assistant messages
|
|
109
|
-
2.
|
|
110
|
-
3. Stores
|
|
110
|
+
1. Extracts text content from new user and assistant messages, skipping messages already embedded earlier in the same run
|
|
111
|
+
2. Splits long messages into chunks of at most `maxChunkChars` characters and generates an embedding for each chunk
|
|
112
|
+
3. Stores one vector row per chunk with metadata (thread metadata, message ID, thread ID, resource ID, role, content, timestamp). Row IDs are derived from the message ID (the first chunk uses a UUID message ID as is), so saving the same message again replaces its rows instead of adding new ones
|
|
111
113
|
4. Uses LRU caching for embeddings to avoid redundant API calls
|
|
112
114
|
|
|
113
115
|
### Cross-thread recall
|
package/dist/index.cjs
CHANGED
|
@@ -2719,7 +2719,8 @@ async function loadSchemaSnapshot(client, schemaName) {
|
|
|
2719
2719
|
notNullColumns,
|
|
2720
2720
|
indexes,
|
|
2721
2721
|
replicaIdentityIndexes,
|
|
2722
|
-
primaryKeyIndexes
|
|
2722
|
+
primaryKeyIndexes,
|
|
2723
|
+
createdTables: /* @__PURE__ */ new Set()
|
|
2723
2724
|
};
|
|
2724
2725
|
}
|
|
2725
2726
|
// src/storage/db/index.ts
|
|
@@ -2879,26 +2880,30 @@ function generateTableSQL({ tableName, schema, schemaName, compositePrimaryKey,
|
|
|
2879
2880
|
` : ""}
|
|
2880
2881
|
`;
|
|
2881
2882
|
}
|
|
2883
|
+
function indexColumnsSQL(columns, opclass) {
|
|
2884
|
+
return columns.map((col) => {
|
|
2885
|
+
const [colName, ...modifiers] = col.includes(" DESC") || col.includes(" ASC") ? col.split(" ") : [col];
|
|
2886
|
+
if (!colName) throw new Error(`Invalid column specification: ${col}`);
|
|
2887
|
+
return [
|
|
2888
|
+
`"${(0, _mastra_core_utils.parseSqlIdentifier)(colName, "column name")}"`,
|
|
2889
|
+
opclass,
|
|
2890
|
+
...modifiers
|
|
2891
|
+
].filter(Boolean).join(" ");
|
|
2892
|
+
}).join(", ");
|
|
2893
|
+
}
|
|
2882
2894
|
/**
|
|
2883
2895
|
* Generates a CREATE INDEX SQL statement from index options.
|
|
2884
2896
|
* Used by exportSchemas to produce index DDL without a database connection.
|
|
2885
2897
|
*/
|
|
2886
2898
|
function generateIndexSQL(options, schemaName) {
|
|
2887
|
-
const { name, table, columns, unique = false, where, method = "btree" } = options;
|
|
2899
|
+
const { name, table, columns, unique = false, where, method = "btree", opclass } = options;
|
|
2888
2900
|
const fullTableName = getTableName$6({
|
|
2889
2901
|
indexName: table,
|
|
2890
2902
|
schemaName: getSchemaName$6(schemaName)
|
|
2891
2903
|
});
|
|
2892
2904
|
const uniqueStr = unique ? "UNIQUE " : "";
|
|
2893
2905
|
const methodStr = method !== "btree" ? `USING ${method} ` : "";
|
|
2894
|
-
const columnsStr = columns
|
|
2895
|
-
if (col.includes(" DESC") || col.includes(" ASC")) {
|
|
2896
|
-
const [colName, ...modifiers] = col.split(" ");
|
|
2897
|
-
if (!colName) throw new Error(`Invalid column specification: ${col}`);
|
|
2898
|
-
return `"${(0, _mastra_core_utils.parseSqlIdentifier)(colName, "column name")}" ${modifiers.join(" ")}`;
|
|
2899
|
-
}
|
|
2900
|
-
return `"${(0, _mastra_core_utils.parseSqlIdentifier)(col, "column name")}"`;
|
|
2901
|
-
}).join(", ");
|
|
2906
|
+
const columnsStr = indexColumnsSQL(columns, opclass);
|
|
2902
2907
|
const whereStr = where ? ` WHERE ${where}` : "";
|
|
2903
2908
|
return `CREATE ${uniqueStr}INDEX IF NOT EXISTS ${`"${(0, _mastra_core_utils.parseSqlIdentifier)(name, "index name")}"`} ON ${fullTableName} ${methodStr}(${columnsStr})${whereStr};`;
|
|
2904
2909
|
}
|
|
@@ -3409,6 +3414,7 @@ var PgDB = class extends _mastra_core_base.MastraBase {
|
|
|
3409
3414
|
if (this.schemaName) await this.setupSchema();
|
|
3410
3415
|
const snapshot = this.schemaSnapshot;
|
|
3411
3416
|
if (!snapshot || !this.snapshotShowsTableConverged(snapshot, tableName)) {
|
|
3417
|
+
const isNewTable = snapshot ? !snapshot.tables.has(tableName) : false;
|
|
3412
3418
|
const sql = generateTableSQL({
|
|
3413
3419
|
tableName,
|
|
3414
3420
|
schema,
|
|
@@ -3422,6 +3428,7 @@ var PgDB = class extends _mastra_core_base.MastraBase {
|
|
|
3422
3428
|
}
|
|
3423
3429
|
if (snapshot) {
|
|
3424
3430
|
snapshot.tables.add(tableName);
|
|
3431
|
+
if (isNewTable) snapshot.createdTables.add(tableName);
|
|
3425
3432
|
const created = this.snapshotColumns(snapshot, tableName);
|
|
3426
3433
|
for (const [name, def] of Object.entries(schema)) {
|
|
3427
3434
|
const parsedName = (0, _mastra_core_utils.parseSqlIdentifier)(name, "column name");
|
|
@@ -3890,18 +3897,9 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
|
|
|
3890
3897
|
const snapshot = this.schemaSnapshot;
|
|
3891
3898
|
if (snapshot?.indexes.has(name)) return;
|
|
3892
3899
|
const uniqueStr = unique ? "UNIQUE " : "";
|
|
3893
|
-
const concurrentStr = concurrent ? "CONCURRENTLY " : "";
|
|
3900
|
+
const concurrentStr = concurrent && !this.isTableCreatedInThisInit(table) ? "CONCURRENTLY " : "";
|
|
3894
3901
|
const methodStr = method !== "btree" ? `USING ${method} ` : "";
|
|
3895
|
-
const columnsStr = columns
|
|
3896
|
-
if (col.includes(" DESC") || col.includes(" ASC")) {
|
|
3897
|
-
const [colName, ...modifiers] = col.split(" ");
|
|
3898
|
-
if (!colName) throw new Error(`Invalid column specification: ${col}`);
|
|
3899
|
-
const quotedCol = `"${(0, _mastra_core_utils.parseSqlIdentifier)(colName, "column name")}" ${modifiers.join(" ")}`;
|
|
3900
|
-
return opclass ? `${quotedCol} ${opclass}` : quotedCol;
|
|
3901
|
-
}
|
|
3902
|
-
const quotedCol = `"${(0, _mastra_core_utils.parseSqlIdentifier)(col, "column name")}"`;
|
|
3903
|
-
return opclass ? `${quotedCol} ${opclass}` : quotedCol;
|
|
3904
|
-
}).join(", ");
|
|
3902
|
+
const columnsStr = indexColumnsSQL(columns, opclass);
|
|
3905
3903
|
const whereStr = where ? ` WHERE ${where}` : "";
|
|
3906
3904
|
const tablespaceStr = tablespace ? ` TABLESPACE ${tablespace}` : "";
|
|
3907
3905
|
let withStr = "";
|
|
@@ -3934,6 +3932,13 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
|
|
|
3934
3932
|
if (snapshot?.indexes.has(indexName)) return;
|
|
3935
3933
|
if (await buildIndex(this.client, this.schemaName || "public", indexName, () => this.timedIndexBuild(indexName, sql), this.logger)) snapshot?.indexes.add(indexName);
|
|
3936
3934
|
}
|
|
3935
|
+
/**
|
|
3936
|
+
* Whether `tableName` was absent when this init's snapshot was read and this
|
|
3937
|
+
* init created it, so its indexes can be built without CONCURRENTLY.
|
|
3938
|
+
*/
|
|
3939
|
+
isTableCreatedInThisInit(tableName) {
|
|
3940
|
+
return this.schemaSnapshot?.createdTables.has(tableName) ?? false;
|
|
3941
|
+
}
|
|
3937
3942
|
async timedIndexBuild(indexName, sql) {
|
|
3938
3943
|
const startedAt = Date.now();
|
|
3939
3944
|
this.logger.info(`Creating index ${indexName}`);
|
|
@@ -25964,15 +25969,16 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
|
|
|
25964
25969
|
this.logger?.warn?.(`Failed to create index ${stateBaseIndexName}:`, error);
|
|
25965
25970
|
}
|
|
25966
25971
|
if (await this.#db.getColumnType(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "snapshot") !== "jsonb") return;
|
|
25972
|
+
const concurrently = !this.#db.isTableCreatedInThisInit(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
25967
25973
|
const indexName = workflowSnapshotStatusIndexName(this.#schema);
|
|
25968
25974
|
try {
|
|
25969
|
-
await this.#db.createIndexFromStatement(indexName, workflowSnapshotStatusIndexSQL(indexName, this.#schema,
|
|
25975
|
+
await this.#db.createIndexFromStatement(indexName, workflowSnapshotStatusIndexSQL(indexName, this.#schema, concurrently));
|
|
25970
25976
|
} catch (error) {
|
|
25971
25977
|
this.logger?.warn?.(`Failed to create index ${indexName}:`, error);
|
|
25972
25978
|
}
|
|
25973
25979
|
const threadIdIndexName = workflowSnapshotThreadIdIndexName(this.#schema);
|
|
25974
25980
|
try {
|
|
25975
|
-
await this.#db.createIndexFromStatement(threadIdIndexName, workflowSnapshotThreadIdIndexSQL(threadIdIndexName, this.#schema,
|
|
25981
|
+
await this.#db.createIndexFromStatement(threadIdIndexName, workflowSnapshotThreadIdIndexSQL(threadIdIndexName, this.#schema, concurrently));
|
|
25976
25982
|
} catch (error) {
|
|
25977
25983
|
this.logger?.warn?.(`Failed to create index ${threadIdIndexName}:`, error);
|
|
25978
25984
|
}
|