opencode-mastra-om 0.1.12 → 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.
- package/dist/index.js +56 -35
- 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
|
-
|
|
179797
|
-
|
|
179798
|
-
|
|
179799
|
-
|
|
179800
|
-
|
|
179801
|
-
|
|
179802
|
-
|
|
179803
|
-
|
|
179804
|
-
|
|
179805
|
-
|
|
179806
|
-
|
|
179807
|
-
|
|
179808
|
-
|
|
179809
|
-
|
|
179810
|
-
|
|
179811
|
-
|
|
179812
|
-
|
|
179813
|
-
|
|
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
|
-
|
|
179829
|
-
|
|
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);
|
|
@@ -179935,6 +179946,8 @@ var MastraPlugin = async (ctx) => {
|
|
|
179935
179946
|
return {
|
|
179936
179947
|
event: async ({ event }) => {
|
|
179937
179948
|
omLog(`[event] received event type=${event.type}`);
|
|
179949
|
+
if (initFailed || !om)
|
|
179950
|
+
return;
|
|
179938
179951
|
if (event.type === "session.created") {
|
|
179939
179952
|
const sessionId = event.properties.info.id;
|
|
179940
179953
|
omLog(`[session] creating record for ${sessionId}`);
|
|
@@ -179949,6 +179962,10 @@ var MastraPlugin = async (ctx) => {
|
|
|
179949
179962
|
},
|
|
179950
179963
|
"experimental.chat.messages.transform": async (_input, output) => {
|
|
179951
179964
|
omLog(`[transform] messages.transform called, messages=${output.messages.length}`);
|
|
179965
|
+
if (initFailed || !om) {
|
|
179966
|
+
omLog(`[transform] OM not initialized, skipping`);
|
|
179967
|
+
return;
|
|
179968
|
+
}
|
|
179952
179969
|
const sessionId = output.messages[0]?.info.sessionID;
|
|
179953
179970
|
if (!sessionId) {
|
|
179954
179971
|
omLog(`[transform] no sessionId, skipping`);
|
|
@@ -179988,6 +180005,10 @@ var MastraPlugin = async (ctx) => {
|
|
|
179988
180005
|
},
|
|
179989
180006
|
"experimental.chat.system.transform": async (input, output) => {
|
|
179990
180007
|
omLog(`[system.transform] called, sessionID=${input.sessionID}`);
|
|
180008
|
+
if (initFailed || !om) {
|
|
180009
|
+
omLog(`[system.transform] OM not initialized, skipping`);
|
|
180010
|
+
return;
|
|
180011
|
+
}
|
|
179991
180012
|
const sessionId = input.sessionID;
|
|
179992
180013
|
if (!sessionId) {
|
|
179993
180014
|
omLog(`[system.transform] no sessionId, skipping`);
|
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.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",
|