opencode-mastra-om 0.1.3 → 0.1.4
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/index.js +39 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -179825,6 +179825,42 @@ var MastraPlugin = async (ctx) => {
|
|
|
179825
179825
|
}
|
|
179826
179826
|
const om = new ObservationalMemory(omOptions);
|
|
179827
179827
|
omLog(`[init] ObservationalMemory created, model=${config2.model ?? "default"}`);
|
|
179828
|
+
const backupObservations = async (threadId, label) => {
|
|
179829
|
+
try {
|
|
179830
|
+
const record3 = await om.getRecord(threadId);
|
|
179831
|
+
const observations = record3?.activeObservations;
|
|
179832
|
+
if (!observations)
|
|
179833
|
+
return;
|
|
179834
|
+
const generationCount = record3?.generationCount ?? 0;
|
|
179835
|
+
const lookupKey = threadId;
|
|
179836
|
+
const savedAt = new Date().toISOString();
|
|
179837
|
+
const db = store.turso;
|
|
179838
|
+
if (!db)
|
|
179839
|
+
return;
|
|
179840
|
+
await db.execute({
|
|
179841
|
+
sql: `INSERT INTO mastra_om_backups (id, lookupKey, slot, generationCount, observations, savedAt)
|
|
179842
|
+
SELECT hex(randomblob(16)), lookupKey, 2, generationCount, observations, savedAt
|
|
179843
|
+
FROM mastra_om_backups WHERE lookupKey = ? AND slot = 1
|
|
179844
|
+
ON CONFLICT(lookupKey, slot) DO UPDATE SET
|
|
179845
|
+
generationCount = excluded.generationCount,
|
|
179846
|
+
observations = excluded.observations,
|
|
179847
|
+
savedAt = excluded.savedAt`,
|
|
179848
|
+
args: [lookupKey]
|
|
179849
|
+
});
|
|
179850
|
+
await db.execute({
|
|
179851
|
+
sql: `INSERT INTO mastra_om_backups (id, lookupKey, slot, generationCount, observations, savedAt)
|
|
179852
|
+
VALUES (hex(randomblob(16)), ?, 1, ?, ?, ?)
|
|
179853
|
+
ON CONFLICT(lookupKey, slot) DO UPDATE SET
|
|
179854
|
+
generationCount = excluded.generationCount,
|
|
179855
|
+
observations = excluded.observations,
|
|
179856
|
+
savedAt = excluded.savedAt`,
|
|
179857
|
+
args: [lookupKey, generationCount, observations, savedAt]
|
|
179858
|
+
});
|
|
179859
|
+
omLog(`[backup] ${label} — saved gen ${generationCount} to slot 1, rotated old slot 1 → slot 2`);
|
|
179860
|
+
} catch (err) {
|
|
179861
|
+
omLog(`[backup] failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
179862
|
+
}
|
|
179863
|
+
};
|
|
179828
179864
|
setTimeout(() => {
|
|
179829
179865
|
ctx.client.tui.showToast({
|
|
179830
179866
|
body: { title: "Mastra OM", message: "Observational Memory active", variant: "success", duration: 3000 }
|
|
@@ -179875,6 +179911,7 @@ var MastraPlugin = async (ctx) => {
|
|
|
179875
179911
|
try {
|
|
179876
179912
|
const mastraMessages = convertMessages2(output.messages, sessionId);
|
|
179877
179913
|
if (mastraMessages.length > 0) {
|
|
179914
|
+
await backupObservations(sessionId, "pre-auto-observe");
|
|
179878
179915
|
await runObserve(sessionId, mastraMessages);
|
|
179879
179916
|
}
|
|
179880
179917
|
const record3 = await om.getRecord(sessionId);
|
|
@@ -179981,6 +180018,7 @@ ${OBSERVATION_CONTINUATION_HINT}`);
|
|
|
179981
180018
|
if (!resp.data || resp.data.length === 0)
|
|
179982
180019
|
return "No messages to observe.";
|
|
179983
180020
|
const mastraMessages = convertMessages2(resp.data, threadId);
|
|
180021
|
+
await backupObservations(threadId, "pre-observe");
|
|
179984
180022
|
await runObserve(threadId, mastraMessages);
|
|
179985
180023
|
return "Observation cycle triggered. Check memory_status for results.";
|
|
179986
180024
|
} catch (err) {
|
|
@@ -179997,6 +180035,7 @@ ${OBSERVATION_CONTINUATION_HINT}`);
|
|
|
179997
180035
|
const threadId = context2.sessionID;
|
|
179998
180036
|
await resolveCredentials();
|
|
179999
180037
|
try {
|
|
180038
|
+
await backupObservations(threadId, "pre-reflect");
|
|
180000
180039
|
await om.reflect(threadId);
|
|
180001
180040
|
return "Reflection cycle triggered. Check memory_observations for results.";
|
|
180002
180041
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "opencode-mastra-om",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Enhanced Mastra Observational Memory plugin for OpenCode — persistent cross-session memory with observation, reflection, and manual trigger tools",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@mastra/core": "^1.21.0",
|
|
41
|
-
"@mastra/libsql": "^1.7.
|
|
42
|
-
"@mastra/memory": "^1.13.
|
|
41
|
+
"@mastra/libsql": "^1.7.4",
|
|
42
|
+
"@mastra/memory": "^1.13.1",
|
|
43
43
|
"@opencode-ai/plugin": "^1.3.11",
|
|
44
44
|
"@opencode-ai/sdk": "^1.3.11"
|
|
45
45
|
},
|