opencode-mastra-om 0.1.5 → 0.1.7
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 +85 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -180045,7 +180045,7 @@ ${OBSERVATION_CONTINUATION_HINT}`);
|
|
|
180045
180045
|
}
|
|
180046
180046
|
}),
|
|
180047
180047
|
om_observe: tool5({
|
|
180048
|
-
description: "Manually trigger an observation cycle right now, without waiting for the token threshold.",
|
|
180048
|
+
description: "Manually trigger an observation cycle right now, without waiting for the token threshold. Automatically chunks large message sets if chunkTokens is configured.",
|
|
180049
180049
|
args: {},
|
|
180050
180050
|
async execute(_args, context2) {
|
|
180051
180051
|
const threadId = context2.sessionID;
|
|
@@ -180056,8 +180056,53 @@ ${OBSERVATION_CONTINUATION_HINT}`);
|
|
|
180056
180056
|
return "No messages to observe.";
|
|
180057
180057
|
const mastraMessages = convertMessages2(resp.data, threadId);
|
|
180058
180058
|
await backupObservations(threadId, "pre-observe");
|
|
180059
|
-
|
|
180060
|
-
|
|
180059
|
+
const chunkBytes = config2.chunkBytes;
|
|
180060
|
+
if (!chunkBytes) {
|
|
180061
|
+
await runObserve(threadId, mastraMessages);
|
|
180062
|
+
return "Observation cycle triggered. Check om_status for results.";
|
|
180063
|
+
}
|
|
180064
|
+
const chunks = [];
|
|
180065
|
+
let currentChunk = [];
|
|
180066
|
+
let currentBytes = 0;
|
|
180067
|
+
for (const msg of mastraMessages) {
|
|
180068
|
+
const msgBytes = Buffer.byteLength(JSON.stringify(msg), "utf8");
|
|
180069
|
+
if (currentBytes + msgBytes > chunkBytes && currentChunk.length > 0) {
|
|
180070
|
+
chunks.push(currentChunk);
|
|
180071
|
+
currentChunk = [msg];
|
|
180072
|
+
currentBytes = msgBytes;
|
|
180073
|
+
} else {
|
|
180074
|
+
currentChunk.push(msg);
|
|
180075
|
+
currentBytes += msgBytes;
|
|
180076
|
+
}
|
|
180077
|
+
}
|
|
180078
|
+
if (currentChunk.length > 0)
|
|
180079
|
+
chunks.push(currentChunk);
|
|
180080
|
+
if (chunks.length === 1) {
|
|
180081
|
+
await runObserve(threadId, mastraMessages);
|
|
180082
|
+
return "Observation cycle triggered (single chunk). Check om_status for results.";
|
|
180083
|
+
}
|
|
180084
|
+
omLog(`[observe] chunked into ${chunks.length} chunks of ~${Math.round(chunkBytes / 1024)}KB each`);
|
|
180085
|
+
ctx.client.tui.showToast({
|
|
180086
|
+
body: { title: "Mastra OM", message: `Observing in ${chunks.length} chunks (~${Math.round(chunkBytes / 1024)}KB each)...`, variant: "info", duration: 5000 }
|
|
180087
|
+
});
|
|
180088
|
+
const refThreshold = resolveThreshold(omOptions.reflection?.observationTokens ?? 60000);
|
|
180089
|
+
const reflectAt = Math.floor(refThreshold * 0.8);
|
|
180090
|
+
for (let i = 0;i < chunks.length; i++) {
|
|
180091
|
+
omLog(`[observe] processing chunk ${i + 1}/${chunks.length} (${chunks[i].length} messages)`);
|
|
180092
|
+
await runObserve(threadId, chunks[i]);
|
|
180093
|
+
if (i < chunks.length - 1) {
|
|
180094
|
+
const record3 = await om.getRecord(threadId);
|
|
180095
|
+
const obsTokens = record3?.observationTokenCount ?? 0;
|
|
180096
|
+
if (obsTokens >= reflectAt) {
|
|
180097
|
+
omLog(`[observe] observations at ${obsTokens} tokens (>= ${reflectAt}), reflecting before next chunk`);
|
|
180098
|
+
ctx.client.tui.showToast({
|
|
180099
|
+
body: { title: "Mastra OM", message: `Reflecting between chunks (${i + 1}/${chunks.length})...`, variant: "info", duration: 5000 }
|
|
180100
|
+
});
|
|
180101
|
+
await om.reflect(threadId);
|
|
180102
|
+
}
|
|
180103
|
+
}
|
|
180104
|
+
}
|
|
180105
|
+
return `Observation complete — processed ${chunks.length} chunks, ${mastraMessages.length} messages total. Check om_status for results.`;
|
|
180061
180106
|
} catch (err) {
|
|
180062
180107
|
const msg = err instanceof Error ? err.message : String(err);
|
|
180063
180108
|
lastError = msg;
|
|
@@ -180155,6 +180200,43 @@ ${OBSERVATION_CONTINUATION_HINT}`);
|
|
|
180155
180200
|
}
|
|
180156
180201
|
}
|
|
180157
180202
|
}),
|
|
180203
|
+
om_reset: tool5({
|
|
180204
|
+
description: "Reset observational memory for this session to a clean slate. Backs up current state first so it can be restored via om_restore.",
|
|
180205
|
+
args: {},
|
|
180206
|
+
async execute(_args, context2) {
|
|
180207
|
+
const threadId = context2.sessionID;
|
|
180208
|
+
try {
|
|
180209
|
+
const db = store.turso;
|
|
180210
|
+
if (!db)
|
|
180211
|
+
return "Raw DB access unavailable.";
|
|
180212
|
+
await backupObservations(threadId, "pre-reset");
|
|
180213
|
+
await db.execute({
|
|
180214
|
+
sql: `UPDATE mastra_observational_memory SET
|
|
180215
|
+
activeObservations = '',
|
|
180216
|
+
generationCount = 0,
|
|
180217
|
+
observationTokenCount = 0,
|
|
180218
|
+
lastObservedAt = NULL,
|
|
180219
|
+
lastReflectionAt = NULL,
|
|
180220
|
+
pendingMessageTokens = 0,
|
|
180221
|
+
observedMessageIds = '[]',
|
|
180222
|
+
bufferedObservations = NULL,
|
|
180223
|
+
bufferedObservationTokens = 0,
|
|
180224
|
+
bufferedMessageIds = NULL,
|
|
180225
|
+
bufferedReflection = NULL,
|
|
180226
|
+
bufferedReflectionTokens = 0,
|
|
180227
|
+
bufferedReflectionInputTokens = 0,
|
|
180228
|
+
reflectedObservationLineCount = 0
|
|
180229
|
+
WHERE lookupKey = ?`,
|
|
180230
|
+
args: [threadId]
|
|
180231
|
+
});
|
|
180232
|
+
omLog(`[reset] observations cleared for ${threadId}`);
|
|
180233
|
+
return "✅ Observational memory reset. Previous state saved to backup slot 1 — use om_restore to recover if needed.";
|
|
180234
|
+
} catch (err) {
|
|
180235
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
180236
|
+
return `Reset failed: ${msg}`;
|
|
180237
|
+
}
|
|
180238
|
+
}
|
|
180239
|
+
}),
|
|
180158
180240
|
om_config: tool5({
|
|
180159
180241
|
description: "Show the current Mastra Observational Memory configuration.",
|
|
180160
180242
|
args: {},
|
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.7",
|
|
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",
|