opencode-mastra-om 0.1.11 → 0.1.13

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 +68 -37
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -179793,43 +179793,54 @@ var MastraPlugin = async (ctx) => {
179793
179793
  omLog(`[credentials] resolved. GOOGLE_GENERATIVE_AI_API_KEY=${process.env.GOOGLE_GENERATIVE_AI_API_KEY ? "set" : "missing"}`);
179794
179794
  };
179795
179795
  let store;
179796
- if (config2.storageUrl && (config2.storageUrl.startsWith("postgresql://") || config2.storageUrl.startsWith("postgres://"))) {
179797
- omLog(`[init] using PostgreSQL storage: ${config2.storageUrl.replace(/:\/\/[^@]+@/, "://<redacted>@")}`);
179798
- const pgMod = await new Function('return import("@mastra/pg")')();
179799
- const PostgresStore = pgMod.PostgresStore;
179800
- store = new PostgresStore({ connectionString: config2.storageUrl });
179801
- await store.init();
179802
- } else {
179803
- const url2 = config2.storageUrl ?? `file:${join5(ctx.directory, config2.storagePath ?? DEFAULT_STORAGE_PATH)}`;
179804
- if (!config2.storageUrl) {
179805
- const dbAbsolutePath = join5(ctx.directory, config2.storagePath ?? DEFAULT_STORAGE_PATH);
179806
- await mkdir2(dirname4(dbAbsolutePath), { recursive: true });
179807
- }
179808
- omLog(`[init] using SQLite/LibSQL storage: ${url2}`);
179809
- store = new LibSQLStore({ id: "mastra-om", url: url2 });
179810
- await store.init();
179811
- }
179812
- const storage = await store.getStore("memory");
179813
- if (!storage)
179814
- throw new Error(`mastra-om: failed to initialize storage`);
179815
- const omOptions = {
179816
- storage,
179817
- scope: config2.scope,
179818
- shareTokenBudget: config2.shareTokenBudget,
179819
- observation: {
179820
- ...config2.observation,
179821
- ...config2.observationModel ? { model: config2.observationModel } : {}
179822
- },
179823
- reflection: {
179824
- ...config2.reflection,
179825
- ...config2.reflectionModel ? { model: config2.reflectionModel } : {}
179796
+ let om;
179797
+ let initFailed = false;
179798
+ try {
179799
+ if (config2.storageUrl && (config2.storageUrl.startsWith("postgresql://") || config2.storageUrl.startsWith("postgres://"))) {
179800
+ omLog(`[init] using PostgreSQL storage: ${config2.storageUrl.replace(/:\/\/[^@]+@/, "://<redacted>@")}`);
179801
+ const pgMod = await new Function('return import("@mastra/pg")')();
179802
+ const PostgresStore = pgMod.PostgresStore;
179803
+ store = new PostgresStore({ connectionString: config2.storageUrl });
179804
+ await store.init();
179805
+ } else {
179806
+ const url2 = config2.storageUrl ?? `file:${join5(ctx.directory, config2.storagePath ?? DEFAULT_STORAGE_PATH)}`;
179807
+ if (!config2.storageUrl) {
179808
+ const dbAbsolutePath = join5(ctx.directory, config2.storagePath ?? DEFAULT_STORAGE_PATH);
179809
+ await mkdir2(dirname4(dbAbsolutePath), { recursive: true });
179810
+ }
179811
+ omLog(`[init] using SQLite/LibSQL storage: ${url2}`);
179812
+ store = new LibSQLStore({ id: "mastra-om", url: url2 });
179813
+ await store.init();
179826
179814
  }
179827
- };
179828
- if (config2.model && !config2.observationModel && !config2.reflectionModel) {
179829
- omOptions.model = config2.model;
179815
+ const storage = await store.getStore("memory");
179816
+ if (!storage) {
179817
+ omLog(`[init] ERROR: failed to get storage — OM disabled`);
179818
+ initFailed = true;
179819
+ } else {
179820
+ const omOptions2 = {
179821
+ storage,
179822
+ scope: config2.scope,
179823
+ shareTokenBudget: config2.shareTokenBudget,
179824
+ observation: {
179825
+ ...config2.observation,
179826
+ ...config2.observationModel ? { model: config2.observationModel } : {}
179827
+ },
179828
+ reflection: {
179829
+ ...config2.reflection,
179830
+ ...config2.reflectionModel ? { model: config2.reflectionModel } : {}
179831
+ }
179832
+ };
179833
+ if (config2.model && !config2.observationModel && !config2.reflectionModel) {
179834
+ omOptions2.model = config2.model;
179835
+ }
179836
+ om = new ObservationalMemory(omOptions2);
179837
+ omLog(`[init] ObservationalMemory created, model=${config2.model ?? "default"}`);
179838
+ }
179839
+ } catch (err) {
179840
+ const msg = err instanceof Error ? err.message : String(err);
179841
+ omLog(`[init] ERROR during storage init: ${msg} — OM disabled`);
179842
+ initFailed = true;
179830
179843
  }
179831
- const om = new ObservationalMemory(omOptions);
179832
- omLog(`[init] ObservationalMemory created, model=${config2.model ?? "default"}`);
179833
179844
  const backupObservations = async (threadId, trigger) => {
179834
179845
  try {
179835
179846
  const record3 = await om.getRecord(threadId);
@@ -179934,8 +179945,12 @@ var MastraPlugin = async (ctx) => {
179934
179945
  };
179935
179946
  return {
179936
179947
  event: async ({ event }) => {
179948
+ omLog(`[event] received event type=${event.type}`);
179949
+ if (initFailed || !om)
179950
+ return;
179937
179951
  if (event.type === "session.created") {
179938
179952
  const sessionId = event.properties.info.id;
179953
+ omLog(`[session] creating record for ${sessionId}`);
179939
179954
  try {
179940
179955
  await om.getOrCreateRecord(sessionId);
179941
179956
  omLog(`[session] initialized record for ${sessionId}`);
@@ -179947,6 +179962,10 @@ var MastraPlugin = async (ctx) => {
179947
179962
  },
179948
179963
  "experimental.chat.messages.transform": async (_input, output) => {
179949
179964
  omLog(`[transform] messages.transform called, messages=${output.messages.length}`);
179965
+ if (initFailed || !om) {
179966
+ omLog(`[transform] OM not initialized, skipping`);
179967
+ return;
179968
+ }
179950
179969
  const sessionId = output.messages[0]?.info.sessionID;
179951
179970
  if (!sessionId) {
179952
179971
  omLog(`[transform] no sessionId, skipping`);
@@ -179985,11 +180004,20 @@ var MastraPlugin = async (ctx) => {
179985
180004
  }
179986
180005
  },
179987
180006
  "experimental.chat.system.transform": async (input, output) => {
180007
+ omLog(`[system.transform] called, sessionID=${input.sessionID}`);
180008
+ if (initFailed || !om) {
180009
+ omLog(`[system.transform] OM not initialized, skipping`);
180010
+ return;
180011
+ }
179988
180012
  const sessionId = input.sessionID;
179989
- if (!sessionId)
180013
+ if (!sessionId) {
180014
+ omLog(`[system.transform] no sessionId, skipping`);
179990
180015
  return;
180016
+ }
179991
180017
  try {
180018
+ omLog(`[system.transform] getting observations`);
179992
180019
  const observations = await om.getObservations(sessionId);
180020
+ omLog(`[system.transform] got observations, length=${observations?.length ?? 0}`);
179993
180021
  if (!observations)
179994
180022
  return;
179995
180023
  const optimized = optimizeObservationsForContext(observations);
@@ -180002,7 +180030,10 @@ ${optimized}
180002
180030
  ${OBSERVATION_CONTEXT_INSTRUCTIONS}
180003
180031
 
180004
180032
  ${OBSERVATION_CONTINUATION_HINT}`);
180005
- } catch {}
180033
+ omLog(`[system.transform] done`);
180034
+ } catch (err) {
180035
+ omLog(`[system.transform] error: ${err instanceof Error ? err.message : String(err)}`);
180036
+ }
180006
180037
  },
180007
180038
  tool: {
180008
180039
  om_status: tool5({
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.11",
4
+ "version": "0.1.13",
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",