opencode-mastra-om 0.1.6 → 0.1.8

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -179843,15 +179843,15 @@ var MastraPlugin = async (ctx) => {
179843
179843
  lastReflectionAt: record3.lastReflectionAt ?? null,
179844
179844
  pendingMessageTokens: record3.pendingMessageTokens ?? 0,
179845
179845
  observedMessageIds: record3.observedMessageIds ?? "[]",
179846
- trigger,
179846
+ triggerEvent: trigger,
179847
179847
  savedAt: new Date().toISOString()
179848
179848
  };
179849
179849
  await db.execute({
179850
179850
  sql: `INSERT INTO mastra_om_backups
179851
179851
  (id, lookupKey, slot, generationCount, observations, observationTokenCount,
179852
- lastObservedAt, lastReflectionAt, pendingMessageTokens, observedMessageIds, trigger, savedAt)
179852
+ lastObservedAt, lastReflectionAt, pendingMessageTokens, observedMessageIds, triggerEvent, savedAt)
179853
179853
  SELECT hex(randomblob(16)), lookupKey, 2, generationCount, observations, observationTokenCount,
179854
- lastObservedAt, lastReflectionAt, pendingMessageTokens, observedMessageIds, trigger, savedAt
179854
+ lastObservedAt, lastReflectionAt, pendingMessageTokens, observedMessageIds, triggerEvent, savedAt
179855
179855
  FROM mastra_om_backups WHERE lookupKey = ? AND slot = 1
179856
179856
  ON CONFLICT(lookupKey, slot) DO UPDATE SET
179857
179857
  generationCount = excluded.generationCount,
@@ -179861,14 +179861,14 @@ var MastraPlugin = async (ctx) => {
179861
179861
  lastReflectionAt = excluded.lastReflectionAt,
179862
179862
  pendingMessageTokens = excluded.pendingMessageTokens,
179863
179863
  observedMessageIds = excluded.observedMessageIds,
179864
- trigger = excluded.trigger,
179864
+ triggerEvent = excluded.triggerEvent,
179865
179865
  savedAt = excluded.savedAt`,
179866
179866
  args: [threadId]
179867
179867
  });
179868
179868
  await db.execute({
179869
179869
  sql: `INSERT INTO mastra_om_backups
179870
179870
  (id, lookupKey, slot, generationCount, observations, observationTokenCount,
179871
- lastObservedAt, lastReflectionAt, pendingMessageTokens, observedMessageIds, trigger, savedAt)
179871
+ lastObservedAt, lastReflectionAt, pendingMessageTokens, observedMessageIds, triggerEvent, savedAt)
179872
179872
  VALUES (hex(randomblob(16)), ?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?)
179873
179873
  ON CONFLICT(lookupKey, slot) DO UPDATE SET
179874
179874
  generationCount = excluded.generationCount,
@@ -179878,7 +179878,7 @@ var MastraPlugin = async (ctx) => {
179878
179878
  lastReflectionAt = excluded.lastReflectionAt,
179879
179879
  pendingMessageTokens = excluded.pendingMessageTokens,
179880
179880
  observedMessageIds = excluded.observedMessageIds,
179881
- trigger = excluded.trigger,
179881
+ triggerEvent = excluded.triggerEvent,
179882
179882
  savedAt = excluded.savedAt`,
179883
179883
  args: [
179884
179884
  threadId,
@@ -180056,24 +180056,23 @@ ${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
- const chunkTokens = config2.chunkTokens;
180060
- if (!chunkTokens) {
180059
+ const chunkBytes = config2.chunkBytes;
180060
+ if (!chunkBytes) {
180061
180061
  await runObserve(threadId, mastraMessages);
180062
180062
  return "Observation cycle triggered. Check om_status for results.";
180063
180063
  }
180064
- const tokenCounter = new TokenCounter;
180065
180064
  const chunks = [];
180066
180065
  let currentChunk = [];
180067
- let currentTokens = 0;
180066
+ let currentBytes = 0;
180068
180067
  for (const msg of mastraMessages) {
180069
- const msgTokens = tokenCounter.countMessages([msg]);
180070
- if (currentTokens + msgTokens > chunkTokens && currentChunk.length > 0) {
180068
+ const msgBytes = Buffer.byteLength(JSON.stringify(msg), "utf8");
180069
+ if (currentBytes + msgBytes > chunkBytes && currentChunk.length > 0) {
180071
180070
  chunks.push(currentChunk);
180072
180071
  currentChunk = [msg];
180073
- currentTokens = msgTokens;
180072
+ currentBytes = msgBytes;
180074
180073
  } else {
180075
180074
  currentChunk.push(msg);
180076
- currentTokens += msgTokens;
180075
+ currentBytes += msgBytes;
180077
180076
  }
180078
180077
  }
180079
180078
  if (currentChunk.length > 0)
@@ -180082,9 +180081,9 @@ ${OBSERVATION_CONTINUATION_HINT}`);
180082
180081
  await runObserve(threadId, mastraMessages);
180083
180082
  return "Observation cycle triggered (single chunk). Check om_status for results.";
180084
180083
  }
180085
- omLog(`[observe] chunked into ${chunks.length} chunks of ~${chunkTokens} tokens each`);
180084
+ omLog(`[observe] chunked into ${chunks.length} chunks of ~${Math.round(chunkBytes / 1024)}KB each`);
180086
180085
  ctx.client.tui.showToast({
180087
- body: { title: "Mastra OM", message: `Observing in ${chunks.length} chunks...`, variant: "info", duration: 5000 }
180086
+ body: { title: "Mastra OM", message: `Observing in ${chunks.length} chunks (~${Math.round(chunkBytes / 1024)}KB each)...`, variant: "info", duration: 5000 }
180088
180087
  });
180089
180088
  const refThreshold = resolveThreshold(omOptions.reflection?.observationTokens ?? 60000);
180090
180089
  const reflectAt = Math.floor(refThreshold * 0.8);
@@ -180189,7 +180188,7 @@ ${OBSERVATION_CONTINUATION_HINT}`);
180189
180188
  `✅ Restored from slot ${slot}`,
180190
180189
  ` Generation: ${row.generationCount}`,
180191
180190
  ` Saved at: ${row.savedAt}`,
180192
- ` Trigger: ${row.trigger}`,
180191
+ ` Trigger: ${row.triggerEvent}`,
180193
180192
  ` Observation tokens: ${row.observationTokenCount}`,
180194
180193
  ` Last observed: ${row.lastObservedAt ?? "never"}`,
180195
180194
  ` Last reflection: ${row.lastReflectionAt ?? "never"}`
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.6",
4
+ "version": "0.1.8",
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",