@mastra/convex 1.9.1 → 1.9.2-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/_types/@internal_core@0.1.4/dist/memory/index.d.ts +25 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +13 -13
- package/dist/docs/references/integrations-databases-convex.md +6 -6
- package/dist/index.cjs +10 -5
- package/dist/index.js +10 -5
- package/dist/schema.cjs +0 -2
- package/dist/schema.js +0 -2
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/observational-memory.d.ts +10 -0
- package/dist/{server-DS6X9y1L.js → server-3jHGWr-2.js} +29 -9
- package/dist/{server-CwHPmdFF.cjs → server-RoaQqgbZ.cjs} +29 -9
- package/dist/storage/types.d.ts +4 -0
- package/package.json +8 -7
- package/dist/cache/client.d.ts.map +0 -1
- package/dist/cache/index.d.ts.map +0 -1
- package/dist/cache/types.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/schema.cjs.map +0 -1
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js.map +0 -1
- package/dist/server/cache.d.ts.map +0 -1
- package/dist/server/index-map.d.ts.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/native-vector.d.ts.map +0 -1
- package/dist/server/observational-memory.d.ts.map +0 -1
- package/dist/server/run-fencing.d.ts.map +0 -1
- package/dist/server/storage.d.ts.map +0 -1
- package/dist/server/workflow-snapshot.d.ts.map +0 -1
- package/dist/server-CwHPmdFF.cjs.map +0 -1
- package/dist/server-DS6X9y1L.js.map +0 -1
- package/dist/storage/client.d.ts.map +0 -1
- package/dist/storage/db/index.d.ts.map +0 -1
- package/dist/storage/domains/background-tasks/index.d.ts.map +0 -1
- package/dist/storage/domains/channels/index.d.ts.map +0 -1
- package/dist/storage/domains/memory/index.d.ts.map +0 -1
- package/dist/storage/domains/schedules/index.d.ts.map +0 -1
- package/dist/storage/domains/scores/index.d.ts.map +0 -1
- package/dist/storage/domains/workflows/index.d.ts.map +0 -1
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/run-fencing.d.ts.map +0 -1
- package/dist/storage/types.d.ts.map +0 -1
- package/dist/vector/index.d.ts.map +0 -1
- package/dist/vector/native.d.ts.map +0 -1
|
@@ -96,4 +96,29 @@ export declare function assertActiveObservationsApplied(result: UpdateActiveObse
|
|
|
96
96
|
* (equal, or only appended to since).
|
|
97
97
|
*/
|
|
98
98
|
export declare function isAppendOnlySince(storedObservations: string, snapshotObservations: string): boolean;
|
|
99
|
+
/** The buffered-reflection fields a `swapBufferedReflectionToActive` caller read, and the stored ones. */
|
|
100
|
+
export interface BufferedReflectionState {
|
|
101
|
+
bufferedReflection?: string | null;
|
|
102
|
+
reflectedObservationLineCount?: number | null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Whether the stored buffered reflection and reflected line count are still the ones in
|
|
106
|
+
* `snapshot`, so a buffered-reflection swap activates exactly the buffer the caller read.
|
|
107
|
+
*
|
|
108
|
+
* Another writer can extend the buffer (`updateBufferedReflection` appends and moves the line
|
|
109
|
+
* count) after the caller's read. The activated text alone cannot tell the two apart: an
|
|
110
|
+
* extension that repeats the unreflected tail and moves the cut past it produces the same text.
|
|
111
|
+
* A snapshot without a buffered reflection (callers that never read one) is not checked.
|
|
112
|
+
*/
|
|
113
|
+
export declare function isBufferedReflectionUnchangedSince(stored: BufferedReflectionState, snapshot: BufferedReflectionState): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* The generation a buffered-reflection swap just created, marked with
|
|
116
|
+
* `bufferedReflectionVerified: true` when the swap checked the caller's buffered reflection with
|
|
117
|
+
* `isBufferedReflectionUnchangedSince` in the same atomic step. A snapshot without a buffered
|
|
118
|
+
* reflection was not checked, so its successor is returned unmarked. Always returns a new object,
|
|
119
|
+
* so a store's own record is never handed out or mutated.
|
|
120
|
+
*/
|
|
121
|
+
export declare function withBufferedReflectionVerified<T extends object>(successor: T, snapshot: BufferedReflectionState): T & {
|
|
122
|
+
bufferedReflectionVerified?: true;
|
|
123
|
+
};
|
|
99
124
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.9.1",
|
|
2
|
+
"version": "1.9.2-alpha.1",
|
|
3
3
|
"package": "@mastra/convex",
|
|
4
4
|
"exports": {
|
|
5
5
|
"ConvexCacheClient": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"ConvexNativeVector": {
|
|
11
11
|
"types": "dist/vector/native.d.ts",
|
|
12
12
|
"implementation": "dist/index.js",
|
|
13
|
-
"line":
|
|
13
|
+
"line": 2882
|
|
14
14
|
},
|
|
15
15
|
"ConvexServerCache": {
|
|
16
16
|
"types": "dist/cache/index.d.ts",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"ConvexStore": {
|
|
21
21
|
"types": "dist/storage/index.d.ts",
|
|
22
22
|
"implementation": "dist/index.js",
|
|
23
|
-
"line":
|
|
23
|
+
"line": 2588
|
|
24
24
|
},
|
|
25
25
|
"ConvexVector": {
|
|
26
26
|
"types": "dist/vector/index.d.ts",
|
|
27
27
|
"implementation": "dist/index.js",
|
|
28
|
-
"line":
|
|
28
|
+
"line": 2612
|
|
29
29
|
},
|
|
30
30
|
"TABLE_OBSERVATIONAL_MEMORY": {
|
|
31
31
|
"types": "dist/schema.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"mastraCache": {
|
|
46
46
|
"types": "dist/server/cache.d.ts",
|
|
47
|
-
"implementation": "dist/server-
|
|
47
|
+
"implementation": "dist/server-3jHGWr-2.js",
|
|
48
48
|
"line": 297
|
|
49
49
|
},
|
|
50
50
|
"mastraCacheListItemsTable": {
|
|
@@ -79,18 +79,18 @@
|
|
|
79
79
|
},
|
|
80
80
|
"mastraNativeVectorAction": {
|
|
81
81
|
"types": "dist/server/native-vector.d.ts",
|
|
82
|
-
"implementation": "dist/server-
|
|
83
|
-
"line":
|
|
82
|
+
"implementation": "dist/server-3jHGWr-2.js",
|
|
83
|
+
"line": 2279
|
|
84
84
|
},
|
|
85
85
|
"mastraNativeVectorMutation": {
|
|
86
86
|
"types": "dist/server/native-vector.d.ts",
|
|
87
|
-
"implementation": "dist/server-
|
|
88
|
-
"line":
|
|
87
|
+
"implementation": "dist/server-3jHGWr-2.js",
|
|
88
|
+
"line": 2335
|
|
89
89
|
},
|
|
90
90
|
"mastraNativeVectorQuery": {
|
|
91
91
|
"types": "dist/server/native-vector.d.ts",
|
|
92
|
-
"implementation": "dist/server-
|
|
93
|
-
"line":
|
|
92
|
+
"implementation": "dist/server-3jHGWr-2.js",
|
|
93
|
+
"line": 2301
|
|
94
94
|
},
|
|
95
95
|
"mastraObservationalMemoryTable": {
|
|
96
96
|
"types": "dist/schema.d.ts",
|
|
@@ -119,8 +119,8 @@
|
|
|
119
119
|
},
|
|
120
120
|
"mastraStorage": {
|
|
121
121
|
"types": "dist/server/storage.d.ts",
|
|
122
|
-
"implementation": "dist/server-
|
|
123
|
-
"line":
|
|
122
|
+
"implementation": "dist/server-3jHGWr-2.js",
|
|
123
|
+
"line": 1558
|
|
124
124
|
},
|
|
125
125
|
"mastraThreadsTable": {
|
|
126
126
|
"types": "dist/schema.d.ts",
|
|
@@ -75,7 +75,7 @@ export default defineSchema({
|
|
|
75
75
|
})
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
### 2. Create the
|
|
78
|
+
### 2. Create the storage handler
|
|
79
79
|
|
|
80
80
|
In `convex/mastra/storage.ts`:
|
|
81
81
|
|
|
@@ -174,11 +174,11 @@ const cache = new ConvexServerCache({
|
|
|
174
174
|
|
|
175
175
|
`ConvexServerCache` stores list entries as separate Convex documents. This avoids growing a stream replay list inside one document and helps stay within Convex's record size limit.
|
|
176
176
|
|
|
177
|
-
Each scalar cache value and each list item is stored as one Convex row and must stay within Convex's row-size limits.
|
|
177
|
+
Each scalar cache value and each list item is stored as one Convex row and must stay within Convex's row-size limits. Large lists are still bounded by Convex query limits when replaying a range.
|
|
178
178
|
|
|
179
|
-
Cache cleanup and `clear()` run in bounded batches. A single client call can loop through up to 1,000 Convex mutations, with each mutation handling up to 25 list items.
|
|
179
|
+
Cache cleanup and `clear()` run in bounded batches. A single client call can loop through up to 1,000 Convex mutations, with each mutation handling up to 25 list items. A key that `clear()` is cleaning returns empty results on read until cleanup finishes.
|
|
180
180
|
|
|
181
|
-
For
|
|
181
|
+
For large cache namespaces, clear incrementally or use narrower prefixes to avoid long-running cleanup operations.
|
|
182
182
|
|
|
183
183
|
During batched cleanup, cache metadata can temporarily use an internal `deleted` state. The next cleanup pass removes those rows. Avoid writing new values with the same prefix until `clear()` finishes.
|
|
184
184
|
|
|
@@ -192,7 +192,7 @@ Use a non-empty `keyPrefix` unless you intentionally want `clear()` to remove ev
|
|
|
192
192
|
|
|
193
193
|
## Additional notes
|
|
194
194
|
|
|
195
|
-
### Schema
|
|
195
|
+
### Schema management
|
|
196
196
|
|
|
197
197
|
The storage implementation uses typed Convex tables for each Mastra domain:
|
|
198
198
|
|
|
@@ -219,7 +219,7 @@ All typed tables include:
|
|
|
219
219
|
- An `id` field for Mastra's record ID (distinct from Convex's auto-generated `_id`)
|
|
220
220
|
- A `by_record_id` index for efficient lookups by Mastra ID
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
The adapter stores data in a layout compatible with Mastra's storage contract and uses Convex's automatic indexing and real-time capabilities.
|
|
223
223
|
|
|
224
224
|
### Environment variables
|
|
225
225
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_server = require("./server-
|
|
2
|
+
const require_server = require("./server-RoaQqgbZ.cjs");
|
|
3
3
|
const require_schema = require("./schema.cjs");
|
|
4
4
|
let _mastra_core_cache = require("@mastra/core/cache");
|
|
5
5
|
let _mastra_core_storage = require("@mastra/core/storage");
|
|
@@ -1918,7 +1918,9 @@ var MemoryConvex = class MemoryConvex extends _mastra_core_storage.MemoryStorage
|
|
|
1918
1918
|
totalTokensObserved: currentRecord.totalTokensObserved,
|
|
1919
1919
|
generationCount: currentRecord.generationCount,
|
|
1920
1920
|
activeObservations: currentRecord.activeObservations ?? "",
|
|
1921
|
-
observationTokenCount: currentRecord.observationTokenCount ?? 0
|
|
1921
|
+
observationTokenCount: currentRecord.observationTokenCount ?? 0,
|
|
1922
|
+
bufferedReflection: currentRecord.bufferedReflection ?? null,
|
|
1923
|
+
reflectedObservationLineCount: currentRecord.reflectedObservationLineCount ?? null
|
|
1922
1924
|
};
|
|
1923
1925
|
}
|
|
1924
1926
|
async createReflectionGeneration(input) {
|
|
@@ -1948,7 +1950,12 @@ var MemoryConvex = class MemoryConvex extends _mastra_core_storage.MemoryStorage
|
|
|
1948
1950
|
tokenCount: input.tokenCount,
|
|
1949
1951
|
now: (/* @__PURE__ */ new Date()).toISOString()
|
|
1950
1952
|
});
|
|
1951
|
-
|
|
1953
|
+
if (!doc) return input.currentRecord;
|
|
1954
|
+
const record = parseStoredOMRecord(doc);
|
|
1955
|
+
return doc.bufferedReflectionVerified === true ? {
|
|
1956
|
+
...record,
|
|
1957
|
+
bufferedReflectionVerified: true
|
|
1958
|
+
} : record;
|
|
1952
1959
|
}
|
|
1953
1960
|
async setReflectingFlag(id, isReflecting) {
|
|
1954
1961
|
if (!await this.#db.patch({
|
|
@@ -3133,5 +3140,3 @@ exports.mastraThreadsTable = require_schema.mastraThreadsTable;
|
|
|
3133
3140
|
exports.mastraVectorIndexesTable = require_schema.mastraVectorIndexesTable;
|
|
3134
3141
|
exports.mastraVectorsTable = require_schema.mastraVectorsTable;
|
|
3135
3142
|
exports.mastraWorkflowSnapshotsTable = require_schema.mastraWorkflowSnapshotsTable;
|
|
3136
|
-
|
|
3137
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as mastraCache, i as mastraStorage, n as mastraNativeVectorMutation, r as mastraNativeVectorQuery, t as mastraNativeVectorAction } from "./server-
|
|
1
|
+
import { a as mastraCache, i as mastraStorage, n as mastraNativeVectorMutation, r as mastraNativeVectorQuery, t as mastraNativeVectorAction } from "./server-3jHGWr-2.js";
|
|
2
2
|
import { TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_MESSAGES, TABLE_OBSERVATIONAL_MEMORY, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCORERS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, defineMastraNativeVectorTable, mastraBackgroundTasksTable, mastraCacheListItemsTable, mastraCacheTable, mastraChannelConfigTable, mastraChannelInstallationsTable, mastraDocumentsTable, mastraMessagesTable, mastraObservationalMemoryTable, mastraResourcesTable, mastraScheduleTriggersTable, mastraSchedulesTable, mastraScoresTable, mastraThreadsTable, mastraVectorIndexesTable, mastraVectorsTable, mastraWorkflowSnapshotsTable } from "./schema.js";
|
|
3
3
|
import { MastraServerCache } from "@mastra/core/cache";
|
|
4
4
|
import { BackgroundTasksStorage, ChannelsStorage, MastraCompositeStore, MemoryStorage, RUN_FENCE_CONFLICT_ERROR_ID, RunFenceConflictError, SchedulesStorage, ScoresStorage, TABLE_BACKGROUND_TASKS as TABLE_BACKGROUND_TASKS$1, TABLE_CHANNEL_CONFIG as TABLE_CHANNEL_CONFIG$1, TABLE_CHANNEL_INSTALLATIONS as TABLE_CHANNEL_INSTALLATIONS$1, TABLE_MEMORY_RUN_FENCES, TABLE_MESSAGES as TABLE_MESSAGES$1, TABLE_RESOURCES as TABLE_RESOURCES$1, TABLE_SCHEDULES as TABLE_SCHEDULES$1, TABLE_SCHEDULE_TRIGGERS as TABLE_SCHEDULE_TRIGGERS$1, TABLE_SCORERS as TABLE_SCORERS$1, TABLE_THREADS as TABLE_THREADS$1, TABLE_WORKFLOW_RUN_OWNERS, TABLE_WORKFLOW_SNAPSHOT as TABLE_WORKFLOW_SNAPSHOT$1, WorkflowsStorage, calculatePagination, createStorageErrorId, createVectorErrorId, executeRetentionPrune, filterByDateRange, normalizePerPage, normalizeScheduleTarget, resolveRetentionTargets, resolveRunFence, retentionCutoffMs, safelyParseJSON, storageMessageMatchesMetadataFilter, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
@@ -1916,7 +1916,9 @@ var MemoryConvex = class MemoryConvex extends MemoryStorage {
|
|
|
1916
1916
|
totalTokensObserved: currentRecord.totalTokensObserved,
|
|
1917
1917
|
generationCount: currentRecord.generationCount,
|
|
1918
1918
|
activeObservations: currentRecord.activeObservations ?? "",
|
|
1919
|
-
observationTokenCount: currentRecord.observationTokenCount ?? 0
|
|
1919
|
+
observationTokenCount: currentRecord.observationTokenCount ?? 0,
|
|
1920
|
+
bufferedReflection: currentRecord.bufferedReflection ?? null,
|
|
1921
|
+
reflectedObservationLineCount: currentRecord.reflectedObservationLineCount ?? null
|
|
1920
1922
|
};
|
|
1921
1923
|
}
|
|
1922
1924
|
async createReflectionGeneration(input) {
|
|
@@ -1946,7 +1948,12 @@ var MemoryConvex = class MemoryConvex extends MemoryStorage {
|
|
|
1946
1948
|
tokenCount: input.tokenCount,
|
|
1947
1949
|
now: (/* @__PURE__ */ new Date()).toISOString()
|
|
1948
1950
|
});
|
|
1949
|
-
|
|
1951
|
+
if (!doc) return input.currentRecord;
|
|
1952
|
+
const record = parseStoredOMRecord(doc);
|
|
1953
|
+
return doc.bufferedReflectionVerified === true ? {
|
|
1954
|
+
...record,
|
|
1955
|
+
bufferedReflectionVerified: true
|
|
1956
|
+
} : record;
|
|
1950
1957
|
}
|
|
1951
1958
|
async setReflectingFlag(id, isReflecting) {
|
|
1952
1959
|
if (!await this.#db.patch({
|
|
@@ -3044,5 +3051,3 @@ var ConvexNativeVector = class extends MastraVector {
|
|
|
3044
3051
|
}
|
|
3045
3052
|
};
|
|
3046
3053
|
export { ConvexCacheClient, ConvexNativeVector, ConvexServerCache, ConvexStore, ConvexVector, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_MESSAGES, TABLE_OBSERVATIONAL_MEMORY, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCORERS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, defineMastraNativeVectorTable, mastraBackgroundTasksTable, mastraCache, mastraCacheListItemsTable, mastraCacheTable, mastraChannelConfigTable, mastraChannelInstallationsTable, mastraDocumentsTable, mastraMessagesTable, mastraNativeVectorAction, mastraNativeVectorMutation, mastraNativeVectorQuery, mastraObservationalMemoryTable, mastraResourcesTable, mastraScheduleTriggersTable, mastraSchedulesTable, mastraScoresTable, mastraStorage, mastraThreadsTable, mastraVectorIndexesTable, mastraVectorsTable, mastraWorkflowSnapshotsTable };
|
|
3047
|
-
|
|
3048
|
-
//# sourceMappingURL=index.js.map
|
package/dist/schema.cjs
CHANGED
|
@@ -412,5 +412,3 @@ exports.mastraThreadsTable = mastraThreadsTable;
|
|
|
412
412
|
exports.mastraVectorIndexesTable = mastraVectorIndexesTable;
|
|
413
413
|
exports.mastraVectorsTable = mastraVectorsTable;
|
|
414
414
|
exports.mastraWorkflowSnapshotsTable = mastraWorkflowSnapshotsTable;
|
|
415
|
-
|
|
416
|
-
//# sourceMappingURL=schema.cjs.map
|
package/dist/schema.js
CHANGED
|
@@ -331,5 +331,3 @@ const TABLE_VECTORS = "mastra_vectors";
|
|
|
331
331
|
const TABLE_DOCUMENTS = "mastra_documents";
|
|
332
332
|
const TABLE_OBSERVATIONAL_MEMORY = "mastra_observational_memory";
|
|
333
333
|
export { TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_DOCUMENTS, TABLE_MESSAGES, TABLE_OBSERVATIONAL_MEMORY, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCORERS, TABLE_THREADS, TABLE_VECTORS, TABLE_VECTOR_INDEXES, TABLE_WORKFLOW_SNAPSHOT, defineMastraNativeVectorTable, mastraBackgroundTasksTable, mastraCacheListItemsTable, mastraCacheTable, mastraChannelConfigTable, mastraChannelInstallationsTable, mastraDocumentsTable, mastraMessagesTable, mastraObservationalMemoryTable, mastraResourcesTable, mastraScheduleTriggersTable, mastraSchedulesTable, mastraScoresTable, mastraThreadsTable, mastraVectorIndexesTable, mastraVectorsTable, mastraWorkflowSnapshotsTable };
|
|
334
|
-
|
|
335
|
-
//# sourceMappingURL=schema.js.map
|
package/dist/server/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_server = require("../server-
|
|
2
|
+
const require_server = require("../server-RoaQqgbZ.cjs");
|
|
3
3
|
const require_schema = require("../schema.cjs");
|
|
4
4
|
let _mastra_core_storage_constants = require("@mastra/core/storage/constants");
|
|
5
5
|
Object.defineProperty(exports, "TABLE_BACKGROUND_TASKS", {
|
package/dist/server/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as mastraCache, i as mastraStorage, n as mastraNativeVectorMutation, r as mastraNativeVectorQuery, t as mastraNativeVectorAction } from "../server-
|
|
1
|
+
import { a as mastraCache, i as mastraStorage, n as mastraNativeVectorMutation, r as mastraNativeVectorQuery, t as mastraNativeVectorAction } from "../server-3jHGWr-2.js";
|
|
2
2
|
import { TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_MESSAGES, TABLE_OBSERVATIONAL_MEMORY, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCORERS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, defineMastraNativeVectorTable, mastraBackgroundTasksTable, mastraCacheListItemsTable, mastraCacheTable, mastraChannelConfigTable, mastraChannelInstallationsTable, mastraDocumentsTable, mastraMessagesTable, mastraObservationalMemoryTable, mastraResourcesTable, mastraScheduleTriggersTable, mastraSchedulesTable, mastraScoresTable, mastraThreadsTable, mastraVectorIndexesTable, mastraVectorsTable, mastraWorkflowSnapshotsTable } from "../schema.js";
|
|
3
3
|
export { TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_MESSAGES, TABLE_OBSERVATIONAL_MEMORY, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCORERS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, defineMastraNativeVectorTable, mastraBackgroundTasksTable, mastraCache, mastraCacheListItemsTable, mastraCacheTable, mastraChannelConfigTable, mastraChannelInstallationsTable, mastraDocumentsTable, mastraMessagesTable, mastraNativeVectorAction, mastraNativeVectorMutation, mastraNativeVectorQuery, mastraObservationalMemoryTable, mastraResourcesTable, mastraScheduleTriggersTable, mastraSchedulesTable, mastraScoresTable, mastraStorage, mastraThreadsTable, mastraVectorIndexesTable, mastraVectorsTable, mastraWorkflowSnapshotsTable };
|
|
@@ -67,6 +67,16 @@ export declare function planReflectionText(input: {
|
|
|
67
67
|
} | null;
|
|
68
68
|
/** Whether the stored text equals or only extends the snapshot. */
|
|
69
69
|
export declare function isAppendOnly(storedObservations: string, snapshotObservations: string): boolean;
|
|
70
|
+
type BufferedReflectionFields = {
|
|
71
|
+
bufferedReflection?: string | null;
|
|
72
|
+
reflectedObservationLineCount?: number | null;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Whether the stored buffered reflection and reflected line count are still the snapshot's, so
|
|
76
|
+
* a swap activates exactly the buffer the caller read. Mirrors core's
|
|
77
|
+
* `isBufferedReflectionUnchangedSince`. A snapshot without a buffered reflection is not checked.
|
|
78
|
+
*/
|
|
79
|
+
export declare function isBufferedReflectionUnchanged(stored: BufferedReflectionFields, snapshot: BufferedReflectionFields): boolean;
|
|
70
80
|
/**
|
|
71
81
|
* Deep-merge two plain config objects (source wins; undefined source values
|
|
72
82
|
* are skipped). Mirrors MemoryStorage.deepMergeConfig in @mastra/core.
|
|
@@ -651,6 +651,17 @@ function isAppendOnly(storedObservations, snapshotObservations) {
|
|
|
651
651
|
const snapshot = snapshotObservations ?? "";
|
|
652
652
|
return stored === snapshot || stored.startsWith(snapshot);
|
|
653
653
|
}
|
|
654
|
+
/**
|
|
655
|
+
* Whether the stored buffered reflection and reflected line count are still the snapshot's, so
|
|
656
|
+
* a swap activates exactly the buffer the caller read. Mirrors core's
|
|
657
|
+
* `isBufferedReflectionUnchangedSince`. A snapshot without a buffered reflection is not checked.
|
|
658
|
+
*/
|
|
659
|
+
function isBufferedReflectionUnchanged(stored, snapshot) {
|
|
660
|
+
if (snapshot.bufferedReflection === void 0 || snapshot.bufferedReflection === null) return true;
|
|
661
|
+
if ((stored.bufferedReflection ?? "") !== snapshot.bufferedReflection) return false;
|
|
662
|
+
if (snapshot.reflectedObservationLineCount === void 0 || snapshot.reflectedObservationLineCount === null) return true;
|
|
663
|
+
return Number(stored.reflectedObservationLineCount ?? 0) === snapshot.reflectedObservationLineCount;
|
|
664
|
+
}
|
|
654
665
|
/** Canonical head order: generationCount DESC, createdAt ASC, id ASC. */
|
|
655
666
|
function sortsBeforeAsHead(a, b) {
|
|
656
667
|
if (a.generationCount !== b.generationCount) return a.generationCount > b.generationCount;
|
|
@@ -1057,15 +1068,26 @@ async function handleObservationalMemoryOperation(ctx, convexTable, request) {
|
|
|
1057
1068
|
ok: true,
|
|
1058
1069
|
result: stored
|
|
1059
1070
|
};
|
|
1071
|
+
if (!isBufferedReflectionUnchanged({
|
|
1072
|
+
bufferedReflection: stored.bufferedReflection,
|
|
1073
|
+
reflectedObservationLineCount: stored.reflectedObservationLineCount
|
|
1074
|
+
}, currentRecord)) return {
|
|
1075
|
+
ok: true,
|
|
1076
|
+
result: stored
|
|
1077
|
+
};
|
|
1078
|
+
const newRecord = await rollOver(ctx, convexTable, stored, {
|
|
1079
|
+
newId,
|
|
1080
|
+
observations: mergeReflectionWithUnreflected(storedObservations, bufferedReflection, Number(stored.reflectedObservationLineCount || 0)),
|
|
1081
|
+
tokenCount: tokenCount + Math.max(0, Number(stored.observationTokenCount || 0) - (currentRecord.observationTokenCount ?? 0)),
|
|
1082
|
+
now,
|
|
1083
|
+
clearBufferedReflection: true
|
|
1084
|
+
});
|
|
1060
1085
|
return {
|
|
1061
1086
|
ok: true,
|
|
1062
|
-
result:
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
now,
|
|
1067
|
-
clearBufferedReflection: true
|
|
1068
|
-
})
|
|
1087
|
+
result: currentRecord.bufferedReflection !== void 0 && currentRecord.bufferedReflection !== null ? {
|
|
1088
|
+
...newRecord,
|
|
1089
|
+
bufferedReflectionVerified: true
|
|
1090
|
+
} : newRecord
|
|
1069
1091
|
};
|
|
1070
1092
|
}
|
|
1071
1093
|
case "omUpdateConfig": {
|
|
@@ -2375,5 +2397,3 @@ const mastraNativeVectorMutation = mutationGeneric({
|
|
|
2375
2397
|
}
|
|
2376
2398
|
});
|
|
2377
2399
|
export { mastraCache as a, mastraStorage as i, mastraNativeVectorMutation as n, mastraNativeVectorQuery as r, mastraNativeVectorAction as t };
|
|
2378
|
-
|
|
2379
|
-
//# sourceMappingURL=server-DS6X9y1L.js.map
|
|
@@ -651,6 +651,17 @@ function isAppendOnly(storedObservations, snapshotObservations) {
|
|
|
651
651
|
const snapshot = snapshotObservations ?? "";
|
|
652
652
|
return stored === snapshot || stored.startsWith(snapshot);
|
|
653
653
|
}
|
|
654
|
+
/**
|
|
655
|
+
* Whether the stored buffered reflection and reflected line count are still the snapshot's, so
|
|
656
|
+
* a swap activates exactly the buffer the caller read. Mirrors core's
|
|
657
|
+
* `isBufferedReflectionUnchangedSince`. A snapshot without a buffered reflection is not checked.
|
|
658
|
+
*/
|
|
659
|
+
function isBufferedReflectionUnchanged(stored, snapshot) {
|
|
660
|
+
if (snapshot.bufferedReflection === void 0 || snapshot.bufferedReflection === null) return true;
|
|
661
|
+
if ((stored.bufferedReflection ?? "") !== snapshot.bufferedReflection) return false;
|
|
662
|
+
if (snapshot.reflectedObservationLineCount === void 0 || snapshot.reflectedObservationLineCount === null) return true;
|
|
663
|
+
return Number(stored.reflectedObservationLineCount ?? 0) === snapshot.reflectedObservationLineCount;
|
|
664
|
+
}
|
|
654
665
|
/** Canonical head order: generationCount DESC, createdAt ASC, id ASC. */
|
|
655
666
|
function sortsBeforeAsHead(a, b) {
|
|
656
667
|
if (a.generationCount !== b.generationCount) return a.generationCount > b.generationCount;
|
|
@@ -1057,15 +1068,26 @@ async function handleObservationalMemoryOperation(ctx, convexTable, request) {
|
|
|
1057
1068
|
ok: true,
|
|
1058
1069
|
result: stored
|
|
1059
1070
|
};
|
|
1071
|
+
if (!isBufferedReflectionUnchanged({
|
|
1072
|
+
bufferedReflection: stored.bufferedReflection,
|
|
1073
|
+
reflectedObservationLineCount: stored.reflectedObservationLineCount
|
|
1074
|
+
}, currentRecord)) return {
|
|
1075
|
+
ok: true,
|
|
1076
|
+
result: stored
|
|
1077
|
+
};
|
|
1078
|
+
const newRecord = await rollOver(ctx, convexTable, stored, {
|
|
1079
|
+
newId,
|
|
1080
|
+
observations: mergeReflectionWithUnreflected(storedObservations, bufferedReflection, Number(stored.reflectedObservationLineCount || 0)),
|
|
1081
|
+
tokenCount: tokenCount + Math.max(0, Number(stored.observationTokenCount || 0) - (currentRecord.observationTokenCount ?? 0)),
|
|
1082
|
+
now,
|
|
1083
|
+
clearBufferedReflection: true
|
|
1084
|
+
});
|
|
1060
1085
|
return {
|
|
1061
1086
|
ok: true,
|
|
1062
|
-
result:
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
now,
|
|
1067
|
-
clearBufferedReflection: true
|
|
1068
|
-
})
|
|
1087
|
+
result: currentRecord.bufferedReflection !== void 0 && currentRecord.bufferedReflection !== null ? {
|
|
1088
|
+
...newRecord,
|
|
1089
|
+
bufferedReflectionVerified: true
|
|
1090
|
+
} : newRecord
|
|
1069
1091
|
};
|
|
1070
1092
|
}
|
|
1071
1093
|
case "omUpdateConfig": {
|
|
@@ -2404,5 +2426,3 @@ Object.defineProperty(exports, "mastraStorage", {
|
|
|
2404
2426
|
return mastraStorage;
|
|
2405
2427
|
}
|
|
2406
2428
|
});
|
|
2407
|
-
|
|
2408
|
-
//# sourceMappingURL=server-CwHPmdFF.cjs.map
|
package/dist/storage/types.d.ts
CHANGED
|
@@ -71,6 +71,10 @@ export type SerializedOMCurrentRecord = {
|
|
|
71
71
|
activeObservations?: string;
|
|
72
72
|
/** The snapshot's observation token count; tokens appended since are added to the new generation. */
|
|
73
73
|
observationTokenCount?: number;
|
|
74
|
+
/** The snapshot's buffered reflection; a buffered-reflection swap only applies if it is still stored. */
|
|
75
|
+
bufferedReflection?: string | null;
|
|
76
|
+
/** The snapshot's reflected line count; a buffered-reflection swap only applies if it is still stored. */
|
|
77
|
+
reflectedObservationLineCount?: number | null;
|
|
74
78
|
};
|
|
75
79
|
export type StorageRequest = {
|
|
76
80
|
op: 'insert';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/convex",
|
|
3
|
-
"version": "1.9.1",
|
|
3
|
+
"version": "1.9.2-alpha.1",
|
|
4
4
|
"description": "Convex provider for Mastra - includes both storage and vector adapters plus Convex server helpers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"license": "Apache-2.0",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"convex": "^1.
|
|
43
|
+
"convex": "^1.50.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "22.19.15",
|
|
@@ -51,17 +51,18 @@
|
|
|
51
51
|
"tsx": "^4.23.15",
|
|
52
52
|
"typescript": "^7.0.2",
|
|
53
53
|
"vitest": "5.1.0",
|
|
54
|
+
"@internal/lint": "0.0.151",
|
|
55
|
+
"@internal/storage-test-utils": "0.0.147",
|
|
56
|
+
"@internal/types-builder": "0.0.126",
|
|
54
57
|
"@internal/core": "0.1.4",
|
|
55
|
-
"@
|
|
56
|
-
"@internal/storage-test-utils": "0.0.146",
|
|
57
|
-
"@internal/types-builder": "0.0.125",
|
|
58
|
-
"@mastra/core": "1.84.0"
|
|
58
|
+
"@mastra/core": "1.86.0-alpha.7"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@mastra/core": ">=1.76.0-0 <2.0.0-0"
|
|
62
62
|
},
|
|
63
63
|
"files": [
|
|
64
|
-
"dist"
|
|
64
|
+
"dist",
|
|
65
|
+
"!dist/**/*.d.*ts.map"
|
|
65
66
|
],
|
|
66
67
|
"homepage": "https://mastra.ai",
|
|
67
68
|
"repository": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/cache/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAC;AAE3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,OAAO,IAAI;IACxC,MAAM,EAAE,CAAC,CAAC;IACV,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAaF,qBAAa,iBAAiB;IAC5B,OAAO,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