@mastra/convex 1.7.2 → 1.7.3-alpha.0
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/dist/memory/index.d.ts +102 -0
- package/dist/_types/@internal_core/package.json +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +128 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +128 -130
- package/dist/index.js.map +1 -1
- package/dist/schema.cjs +1 -0
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.ts +3 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -0
- package/dist/schema.js.map +1 -1
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/observational-memory.d.ts +26 -1
- package/dist/server/observational-memory.d.ts.map +1 -1
- package/dist/server/storage.d.ts.map +1 -1
- package/dist/{server-D3SG5LQf.js → server-DozOFGfO.js} +304 -56
- package/dist/server-DozOFGfO.js.map +1 -0
- package/dist/{server-D_scBUwi.cjs → server-cdXFJzWz.cjs} +304 -56
- package/dist/server-cdXFJzWz.cjs.map +1 -0
- package/dist/storage/db/index.d.ts +28 -5
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +3 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/types.d.ts +39 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/dist/server-D3SG5LQf.js.map +0 -1
- package/dist/server-D_scBUwi.cjs.map +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//#region src/memory/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Shared rules for observational memory lifecycle writes. Every storage adapter applies
|
|
4
|
+
* these inside its own atomic section (lock, transaction, or conditional update), so the
|
|
5
|
+
* decisions are identical across adapters.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Observational memory columns that lifecycle writes depend on. Storage adapters merge these
|
|
9
|
+
* into the table schema they get from `@mastra/core`, so the columns exist even when the
|
|
10
|
+
* installed core predates them.
|
|
11
|
+
*/
|
|
12
|
+
declare const OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS: {
|
|
13
|
+
readonly supersededBy: {
|
|
14
|
+
readonly type: 'text';
|
|
15
|
+
readonly nullable: true;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/** `schema` plus {@link OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS}; `undefined` when `schema` is. */
|
|
19
|
+
declare function withObservationalMemoryLifecycleColumns<T extends object>(schema: T | undefined): (T & typeof OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS) | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Result of `commitActiveObservations`.
|
|
22
|
+
*/
|
|
23
|
+
interface UpdateActiveObservationsResult {
|
|
24
|
+
/** Whether the observations were written. */
|
|
25
|
+
applied: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Why nothing was written: `retired` — the target record was superseded by a newer
|
|
28
|
+
* generation; `conflict` — `expectedActiveObservations` no longer matches the stored text.
|
|
29
|
+
*/
|
|
30
|
+
reason?: 'retired' | 'conflict';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Result of `appendBufferedObservations`.
|
|
34
|
+
*
|
|
35
|
+
* The append targets the head generation: when `input.id` was superseded, the chunk is
|
|
36
|
+
* appended to the current head instead. The append is skipped (`persisted: false`) when the
|
|
37
|
+
* head already holds a chunk with the same `cycleId`, or when the chunk is wholly covered by
|
|
38
|
+
* the head's cursor. Chunks carry `lastObservedAt = max message time + 1ms`, so a chunk is
|
|
39
|
+
* wholly covered iff `head.lastObservedAt >= chunk.lastObservedAt - 1ms`.
|
|
40
|
+
*/
|
|
41
|
+
interface UpdateBufferedObservationsResult {
|
|
42
|
+
/** Whether the chunk was stored. */
|
|
43
|
+
persisted: boolean;
|
|
44
|
+
/** The record the chunk was written to (or would have been written to). */
|
|
45
|
+
recordId: string;
|
|
46
|
+
}
|
|
47
|
+
/** The fields of an observational memory record that decide head order. */
|
|
48
|
+
interface ObservationalMemoryHeadOrderFields {
|
|
49
|
+
generationCount: number;
|
|
50
|
+
createdAt: Date | string;
|
|
51
|
+
id: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Canonical head order: `generationCount DESC, createdAt ASC, id ASC`.
|
|
55
|
+
* Returns a negative number when `a` sorts before `b` (i.e. `a` is the better head candidate).
|
|
56
|
+
*/
|
|
57
|
+
declare function compareObservationalMemoryHeadOrder(a: ObservationalMemoryHeadOrderFields, b: ObservationalMemoryHeadOrderFields): number;
|
|
58
|
+
/**
|
|
59
|
+
* A buffered chunk stores `lastObservedAt = max message time + 1ms`. It is wholly covered
|
|
60
|
+
* (every message it observed is already at or before the cursor) iff
|
|
61
|
+
* `cursor >= chunk.lastObservedAt - 1ms`.
|
|
62
|
+
*/
|
|
63
|
+
declare function isBufferedChunkCoveredByCursor(chunkLastObservedAt: Date | string, cursor: Date | string | null | undefined): boolean;
|
|
64
|
+
/** The later of two cursors; `undefined` only when both are absent. */
|
|
65
|
+
declare function maxObservationCursor(a: Date | string | null | undefined, b: Date | string | null | undefined): Date | undefined;
|
|
66
|
+
interface ReflectionTextPlan {
|
|
67
|
+
/** `equal`: stored text equals the snapshot. `append`: observations were appended after the snapshot. */
|
|
68
|
+
mode: 'equal' | 'append';
|
|
69
|
+
observations: string;
|
|
70
|
+
tokenCount: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Decide the new generation's text when a reflection built from `snapshot` commits against
|
|
74
|
+
* the stored record.
|
|
75
|
+
*
|
|
76
|
+
* - Stored text equals the snapshot: the reflection replaces it.
|
|
77
|
+
* - Stored text extends the snapshot (activation only appends): the appended tail is kept
|
|
78
|
+
* after the reflection, and its tokens are added.
|
|
79
|
+
* - Anything else (a non-append rewrite): `null` — the reflection must not be applied.
|
|
80
|
+
*/
|
|
81
|
+
declare function planReflectionGenerationText(input: {
|
|
82
|
+
storedObservations: string;
|
|
83
|
+
storedObservationTokenCount: number;
|
|
84
|
+
snapshotObservations: string;
|
|
85
|
+
snapshotObservationTokenCount: number;
|
|
86
|
+
reflection: string;
|
|
87
|
+
tokenCount: number;
|
|
88
|
+
}): ReflectionTextPlan | null;
|
|
89
|
+
/**
|
|
90
|
+
* Backs `updateActiveObservations` in adapters that implement `commitActiveObservations`.
|
|
91
|
+
* Callers of `updateActiveObservations` (which resolves `void`) can't see a commit result, so a
|
|
92
|
+
* write that was not applied throws instead of resolving as if it had committed.
|
|
93
|
+
*/
|
|
94
|
+
declare function assertActiveObservationsApplied(result: UpdateActiveObservationsResult, id: string): void;
|
|
95
|
+
/**
|
|
96
|
+
* Whether the stored text can still accept a reflection built from `snapshot`
|
|
97
|
+
* (equal, or only appended to since).
|
|
98
|
+
*/
|
|
99
|
+
declare function isAppendOnlySince(storedObservations: string, snapshotObservations: string): boolean;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS, ObservationalMemoryHeadOrderFields, ReflectionTextPlan, UpdateActiveObservationsResult, UpdateBufferedObservationsResult, assertActiveObservationsApplied, compareObservationalMemoryHeadOrder, isAppendOnlySince, isBufferedChunkCoveredByCursor, maxObservationCursor, planReflectionGenerationText, withObservationalMemoryLifecycleColumns };
|
|
102
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/dist/docs/SKILL.md
CHANGED
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-cdXFJzWz.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");
|
|
@@ -489,15 +489,43 @@ var ConvexDB = class extends _mastra_core_base.MastraBase {
|
|
|
489
489
|
...args
|
|
490
490
|
});
|
|
491
491
|
}
|
|
492
|
-
async
|
|
492
|
+
async omInitialize(record) {
|
|
493
|
+
return this.client.callStorage({
|
|
494
|
+
op: "omInitialize",
|
|
495
|
+
tableName: TABLE_OBSERVATIONAL_MEMORY$1,
|
|
496
|
+
record
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
async omCreateReflectionGeneration(args) {
|
|
500
|
+
return this.client.callStorage({
|
|
501
|
+
op: "omCreateReflectionGeneration",
|
|
502
|
+
tableName: TABLE_OBSERVATIONAL_MEMORY$1,
|
|
503
|
+
...args
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
async omSetPendingMessageTokens(args) {
|
|
507
|
+
await this.client.callStorage({
|
|
508
|
+
op: "omSetPendingMessageTokens",
|
|
509
|
+
tableName: TABLE_OBSERVATIONAL_MEMORY$1,
|
|
510
|
+
...args
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
async omSetBufferingObservationFlag(args) {
|
|
493
514
|
await this.client.callStorage({
|
|
515
|
+
op: "omSetBufferingObservationFlag",
|
|
516
|
+
tableName: TABLE_OBSERVATIONAL_MEMORY$1,
|
|
517
|
+
...args
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
async omUpdateActive(args) {
|
|
521
|
+
return this.client.callStorage({
|
|
494
522
|
op: "omUpdateActive",
|
|
495
523
|
tableName: TABLE_OBSERVATIONAL_MEMORY$1,
|
|
496
524
|
...args
|
|
497
525
|
});
|
|
498
526
|
}
|
|
499
527
|
async omAppendBufferedChunk(args) {
|
|
500
|
-
|
|
528
|
+
return this.client.callStorage({
|
|
501
529
|
op: "omAppendBufferedChunk",
|
|
502
530
|
tableName: TABLE_OBSERVATIONAL_MEMORY$1,
|
|
503
531
|
...args
|
|
@@ -902,6 +930,17 @@ var ChannelsConvex = class extends _mastra_core_storage.ChannelsStorage {
|
|
|
902
930
|
}
|
|
903
931
|
};
|
|
904
932
|
//#endregion
|
|
933
|
+
//#region ../../packages/_internal-core/dist/memory/index.js
|
|
934
|
+
/**
|
|
935
|
+
* Backs `updateActiveObservations` in adapters that implement `commitActiveObservations`.
|
|
936
|
+
* Callers of `updateActiveObservations` (which resolves `void`) can't see a commit result, so a
|
|
937
|
+
* write that was not applied throws instead of resolving as if it had committed.
|
|
938
|
+
*/
|
|
939
|
+
function assertActiveObservationsApplied(result, id) {
|
|
940
|
+
if (result.applied) return;
|
|
941
|
+
throw new Error(result.reason === "retired" ? `Observational memory record ${id} was superseded by a newer generation; observations were not written` : `Observational memory record ${id} changed since the observations were composed; observations were not written`);
|
|
942
|
+
}
|
|
943
|
+
//#endregion
|
|
905
944
|
//#region src/storage/domains/memory/index.ts
|
|
906
945
|
function parseStoredThread(row) {
|
|
907
946
|
return {
|
|
@@ -977,7 +1016,8 @@ function parseStoredOMRecord(doc) {
|
|
|
977
1016
|
config: config ?? {},
|
|
978
1017
|
metadata: metadata ?? void 0,
|
|
979
1018
|
observedMessageIds: doc.observedMessageIds || void 0,
|
|
980
|
-
observedTimezone: doc.observedTimezone || void 0
|
|
1019
|
+
observedTimezone: doc.observedTimezone || void 0,
|
|
1020
|
+
supersededBy: doc.supersededBy ?? null
|
|
981
1021
|
};
|
|
982
1022
|
}
|
|
983
1023
|
var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
@@ -1465,9 +1505,9 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1465
1505
|
})).map((doc) => parseStoredOMRecord(doc));
|
|
1466
1506
|
}
|
|
1467
1507
|
async initializeObservationalMemory(input) {
|
|
1468
|
-
const id = crypto.randomUUID();
|
|
1469
1508
|
const now = /* @__PURE__ */ new Date();
|
|
1470
1509
|
const lookupKey = this.getOMKey(input.threadId, input.resourceId);
|
|
1510
|
+
const id = crypto.randomUUID();
|
|
1471
1511
|
const record = {
|
|
1472
1512
|
id,
|
|
1473
1513
|
scope: input.scope,
|
|
@@ -1489,38 +1529,36 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1489
1529
|
lastBufferedAtTokens: 0,
|
|
1490
1530
|
lastBufferedAtTime: null,
|
|
1491
1531
|
config: input.config,
|
|
1492
|
-
observedTimezone: input.observedTimezone
|
|
1532
|
+
observedTimezone: input.observedTimezone,
|
|
1533
|
+
supersededBy: null
|
|
1493
1534
|
};
|
|
1494
|
-
await this.#db.
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
createdAt: now.toISOString(),
|
|
1520
|
-
updatedAt: now.toISOString()
|
|
1521
|
-
}
|
|
1535
|
+
const doc = await this.#db.omInitialize({
|
|
1536
|
+
id,
|
|
1537
|
+
lookupKey,
|
|
1538
|
+
scope: input.scope,
|
|
1539
|
+
resourceId: input.resourceId,
|
|
1540
|
+
threadId: input.threadId || null,
|
|
1541
|
+
activeObservations: "",
|
|
1542
|
+
activeObservationsPendingUpdate: null,
|
|
1543
|
+
originType: "initial",
|
|
1544
|
+
config: JSON.stringify(input.config ?? {}),
|
|
1545
|
+
generationCount: 0,
|
|
1546
|
+
lastObservedAt: null,
|
|
1547
|
+
lastReflectionAt: null,
|
|
1548
|
+
pendingMessageTokens: 0,
|
|
1549
|
+
totalTokensObserved: 0,
|
|
1550
|
+
observationTokenCount: 0,
|
|
1551
|
+
isObserving: false,
|
|
1552
|
+
isReflecting: false,
|
|
1553
|
+
isBufferingObservation: false,
|
|
1554
|
+
isBufferingReflection: false,
|
|
1555
|
+
lastBufferedAtTokens: 0,
|
|
1556
|
+
lastBufferedAtTime: null,
|
|
1557
|
+
observedTimezone: input.observedTimezone || null,
|
|
1558
|
+
createdAt: now.toISOString(),
|
|
1559
|
+
updatedAt: now.toISOString()
|
|
1522
1560
|
});
|
|
1523
|
-
return record;
|
|
1561
|
+
return doc ? parseStoredOMRecord(doc) : record;
|
|
1524
1562
|
}
|
|
1525
1563
|
async insertObservationalMemoryRecord(record) {
|
|
1526
1564
|
const lookupKey = this.getOMKey(record.threadId, record.resourceId);
|
|
@@ -1556,22 +1594,30 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1556
1594
|
lastBufferedAtTime: record.lastBufferedAtTime ? toISO(record.lastBufferedAtTime) : null,
|
|
1557
1595
|
observedTimezone: record.observedTimezone || null,
|
|
1558
1596
|
metadata: record.metadata ? JSON.stringify(record.metadata) : null,
|
|
1597
|
+
supersededBy: record.supersededBy ?? null,
|
|
1559
1598
|
createdAt: toISO(record.createdAt),
|
|
1560
1599
|
updatedAt: toISO(record.updatedAt)
|
|
1561
1600
|
}
|
|
1562
1601
|
});
|
|
1563
1602
|
}
|
|
1564
1603
|
async updateActiveObservations(input) {
|
|
1565
|
-
await this
|
|
1604
|
+
assertActiveObservationsApplied(await this.commitActiveObservations(input), input.id);
|
|
1605
|
+
}
|
|
1606
|
+
async commitActiveObservations(input) {
|
|
1607
|
+
return await this.#db.omUpdateActive({
|
|
1566
1608
|
id: input.id,
|
|
1567
1609
|
observations: input.observations,
|
|
1568
1610
|
tokenCount: input.tokenCount,
|
|
1569
1611
|
lastObservedAt: toISO(input.lastObservedAt),
|
|
1570
1612
|
observedMessageIds: input.observedMessageIds ?? null,
|
|
1571
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1572
|
-
|
|
1613
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1614
|
+
...input.expectedActiveObservations !== void 0 ? { expectedActiveObservations: input.expectedActiveObservations } : {}
|
|
1615
|
+
}) ?? { applied: true };
|
|
1573
1616
|
}
|
|
1574
1617
|
async updateBufferedObservations(input) {
|
|
1618
|
+
await this.appendBufferedObservations(input);
|
|
1619
|
+
}
|
|
1620
|
+
async appendBufferedObservations(input) {
|
|
1575
1621
|
const chunk = {
|
|
1576
1622
|
id: `ombuf-${crypto.randomUUID()}`,
|
|
1577
1623
|
cycleId: input.chunk.cycleId,
|
|
@@ -1587,12 +1633,15 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1587
1633
|
extractedValues: input.chunk.extractedValues,
|
|
1588
1634
|
extractionFailures: input.chunk.extractionFailures
|
|
1589
1635
|
};
|
|
1590
|
-
await this.#db.omAppendBufferedChunk({
|
|
1636
|
+
return await this.#db.omAppendBufferedChunk({
|
|
1591
1637
|
id: input.id,
|
|
1592
1638
|
chunk,
|
|
1593
1639
|
lastBufferedAtTime: input.lastBufferedAtTime ? toISO(input.lastBufferedAtTime) : void 0,
|
|
1594
1640
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1595
|
-
})
|
|
1641
|
+
}) ?? {
|
|
1642
|
+
persisted: true,
|
|
1643
|
+
recordId: input.id
|
|
1644
|
+
};
|
|
1596
1645
|
}
|
|
1597
1646
|
async swapBufferedToActive(input) {
|
|
1598
1647
|
return this.#db.omSwapBuffered({
|
|
@@ -1606,65 +1655,33 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1606
1655
|
now: (/* @__PURE__ */ new Date()).toISOString()
|
|
1607
1656
|
});
|
|
1608
1657
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
lastObservedAt:
|
|
1621
|
-
|
|
1622
|
-
generationCount:
|
|
1623
|
-
activeObservations:
|
|
1624
|
-
|
|
1625
|
-
observationTokenCount: input.tokenCount,
|
|
1626
|
-
pendingMessageTokens: 0,
|
|
1627
|
-
isReflecting: false,
|
|
1628
|
-
isObserving: false,
|
|
1629
|
-
isBufferingObservation: false,
|
|
1630
|
-
isBufferingReflection: false,
|
|
1631
|
-
lastBufferedAtTokens: 0,
|
|
1632
|
-
lastBufferedAtTime: null,
|
|
1633
|
-
config: input.currentRecord.config,
|
|
1634
|
-
metadata: input.currentRecord.metadata,
|
|
1635
|
-
observedTimezone: input.currentRecord.observedTimezone
|
|
1658
|
+
/** The caller's snapshot as the server's rollover ops expect it. */
|
|
1659
|
+
#serializeCurrentRecord(currentRecord) {
|
|
1660
|
+
return {
|
|
1661
|
+
id: currentRecord.id,
|
|
1662
|
+
lookupKey: this.getOMKey(currentRecord.threadId, currentRecord.resourceId),
|
|
1663
|
+
scope: currentRecord.scope,
|
|
1664
|
+
threadId: currentRecord.threadId || null,
|
|
1665
|
+
resourceId: currentRecord.resourceId,
|
|
1666
|
+
config: JSON.stringify(currentRecord.config ?? {}),
|
|
1667
|
+
metadata: currentRecord.metadata ? JSON.stringify(currentRecord.metadata) : null,
|
|
1668
|
+
observedTimezone: currentRecord.observedTimezone || null,
|
|
1669
|
+
lastObservedAt: currentRecord.lastObservedAt ? toISO(currentRecord.lastObservedAt) : null,
|
|
1670
|
+
totalTokensObserved: currentRecord.totalTokensObserved,
|
|
1671
|
+
generationCount: currentRecord.generationCount,
|
|
1672
|
+
activeObservations: currentRecord.activeObservations ?? "",
|
|
1673
|
+
observationTokenCount: currentRecord.observationTokenCount ?? 0
|
|
1636
1674
|
};
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
activeObservations: input.reflection,
|
|
1646
|
-
activeObservationsPendingUpdate: null,
|
|
1647
|
-
originType: "reflection",
|
|
1648
|
-
config: JSON.stringify(record.config ?? {}),
|
|
1649
|
-
generationCount: record.generationCount,
|
|
1650
|
-
lastObservedAt: record.lastObservedAt ? toISO(record.lastObservedAt) : null,
|
|
1651
|
-
lastReflectionAt: now.toISOString(),
|
|
1652
|
-
pendingMessageTokens: 0,
|
|
1653
|
-
totalTokensObserved: record.totalTokensObserved,
|
|
1654
|
-
observationTokenCount: record.observationTokenCount,
|
|
1655
|
-
isObserving: false,
|
|
1656
|
-
isReflecting: false,
|
|
1657
|
-
isBufferingObservation: false,
|
|
1658
|
-
isBufferingReflection: false,
|
|
1659
|
-
lastBufferedAtTokens: 0,
|
|
1660
|
-
lastBufferedAtTime: null,
|
|
1661
|
-
observedTimezone: record.observedTimezone || null,
|
|
1662
|
-
metadata: record.metadata ? JSON.stringify(record.metadata) : null,
|
|
1663
|
-
createdAt: now.toISOString(),
|
|
1664
|
-
updatedAt: now.toISOString()
|
|
1665
|
-
}
|
|
1675
|
+
}
|
|
1676
|
+
async createReflectionGeneration(input) {
|
|
1677
|
+
const doc = await this.#db.omCreateReflectionGeneration({
|
|
1678
|
+
currentRecord: this.#serializeCurrentRecord(input.currentRecord),
|
|
1679
|
+
newId: input.newRecordId ?? crypto.randomUUID(),
|
|
1680
|
+
reflection: input.reflection,
|
|
1681
|
+
tokenCount: input.tokenCount,
|
|
1682
|
+
now: (/* @__PURE__ */ new Date()).toISOString()
|
|
1666
1683
|
});
|
|
1667
|
-
return
|
|
1684
|
+
return doc ? parseStoredOMRecord(doc) : input.currentRecord;
|
|
1668
1685
|
}
|
|
1669
1686
|
async updateBufferedReflection(input) {
|
|
1670
1687
|
await this.#db.omUpdateBufferedReflection({
|
|
@@ -1677,26 +1694,13 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1677
1694
|
});
|
|
1678
1695
|
}
|
|
1679
1696
|
async swapBufferedReflectionToActive(input) {
|
|
1680
|
-
const
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
lookupKey: this.getOMKey(currentRecord.threadId, currentRecord.resourceId),
|
|
1684
|
-
scope: currentRecord.scope,
|
|
1685
|
-
threadId: currentRecord.threadId || null,
|
|
1686
|
-
resourceId: currentRecord.resourceId,
|
|
1687
|
-
config: JSON.stringify(currentRecord.config ?? {}),
|
|
1688
|
-
metadata: currentRecord.metadata ? JSON.stringify(currentRecord.metadata) : null,
|
|
1689
|
-
observedTimezone: currentRecord.observedTimezone || null,
|
|
1690
|
-
lastObservedAt: currentRecord.lastObservedAt ? toISO(currentRecord.lastObservedAt) : null,
|
|
1691
|
-
totalTokensObserved: currentRecord.totalTokensObserved,
|
|
1692
|
-
generationCount: currentRecord.generationCount
|
|
1693
|
-
};
|
|
1694
|
-
return parseStoredOMRecord(await this.#db.omSwapBufferedReflection({
|
|
1695
|
-
currentRecord: serializedCurrentRecord,
|
|
1696
|
-
newId: crypto.randomUUID(),
|
|
1697
|
+
const doc = await this.#db.omSwapBufferedReflection({
|
|
1698
|
+
currentRecord: this.#serializeCurrentRecord(input.currentRecord),
|
|
1699
|
+
newId: input.newRecordId ?? crypto.randomUUID(),
|
|
1697
1700
|
tokenCount: input.tokenCount,
|
|
1698
1701
|
now: (/* @__PURE__ */ new Date()).toISOString()
|
|
1699
|
-
})
|
|
1702
|
+
});
|
|
1703
|
+
return doc ? parseStoredOMRecord(doc) : input.currentRecord;
|
|
1700
1704
|
}
|
|
1701
1705
|
async setReflectingFlag(id, isReflecting) {
|
|
1702
1706
|
if (!await this.#db.patch({
|
|
@@ -1719,15 +1723,12 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1719
1723
|
})) throw this.omRecordNotFound("SET_OBSERVING_FLAG", id);
|
|
1720
1724
|
}
|
|
1721
1725
|
async setBufferingObservationFlag(id, isBuffering, lastBufferedAtTokens) {
|
|
1722
|
-
|
|
1723
|
-
tableName: "mastra_observational_memory",
|
|
1726
|
+
await this.#db.omSetBufferingObservationFlag({
|
|
1724
1727
|
id,
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
}
|
|
1730
|
-
})) throw this.omRecordNotFound("SET_BUFFERING_OBSERVATION_FLAG", id);
|
|
1728
|
+
isBuffering,
|
|
1729
|
+
...lastBufferedAtTokens !== void 0 ? { lastBufferedAtTokens } : {},
|
|
1730
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1731
|
+
});
|
|
1731
1732
|
}
|
|
1732
1733
|
async setBufferingReflectionFlag(id, isBuffering) {
|
|
1733
1734
|
if (!await this.#db.patch({
|
|
@@ -1750,14 +1751,11 @@ var MemoryConvex = class extends _mastra_core_storage.MemoryStorage {
|
|
|
1750
1751
|
tokenCount
|
|
1751
1752
|
}
|
|
1752
1753
|
});
|
|
1753
|
-
|
|
1754
|
-
tableName: "mastra_observational_memory",
|
|
1754
|
+
await this.#db.omSetPendingMessageTokens({
|
|
1755
1755
|
id,
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
}
|
|
1760
|
-
})) throw this.omRecordNotFound("SET_PENDING_MESSAGE_TOKENS", id);
|
|
1756
|
+
tokenCount,
|
|
1757
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1758
|
+
});
|
|
1761
1759
|
}
|
|
1762
1760
|
async clearObservationalMemory(threadId, resourceId) {
|
|
1763
1761
|
const lookupKey = this.getOMKey(threadId, resourceId);
|