openclaw-memory-alibaba-local 1.0.4 → 1.0.5
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/db.ts +1 -1
- package/index.ts +30 -2
- package/package.json +1 -1
package/db.ts
CHANGED
|
@@ -1400,7 +1400,7 @@ export class MemoryDB {
|
|
|
1400
1400
|
try {
|
|
1401
1401
|
const eid = sqlEscapeLiteral(id);
|
|
1402
1402
|
await (this.table! as any).update(
|
|
1403
|
-
{ createdAt: now },
|
|
1403
|
+
{ createdAt: String(now) },
|
|
1404
1404
|
{ where: `id = '${eid}' AND agentId = '${a}' AND category = '${wf}'` },
|
|
1405
1405
|
);
|
|
1406
1406
|
} catch (err) {
|
package/index.ts
CHANGED
|
@@ -947,6 +947,11 @@ type DeltaFullContextRow = {
|
|
|
947
947
|
/**
|
|
948
948
|
* agent_end: per-role cursors → delta rows by source → LanceDB for full_context_* (shared batchId, no embed / no dedup);
|
|
949
949
|
* then Promise.all(user-memory pipeline on user deltas, self-improving on user+assistant deltas).
|
|
950
|
+
*
|
|
951
|
+
* When `cursorOnly` is true the function advances the per-role cursor and persists it
|
|
952
|
+
* but skips all memory extraction / storage. This is used for non-user triggers
|
|
953
|
+
* (heartbeat, cron, memory, …) so the cursor stays in sync with the growing
|
|
954
|
+
* session messages list without accidentally capturing heartbeat content.
|
|
950
955
|
*/
|
|
951
956
|
async function runAgentEndCapture(
|
|
952
957
|
cfg: MemoryConfig,
|
|
@@ -957,6 +962,7 @@ async function runAgentEndCapture(
|
|
|
957
962
|
userId: string | null,
|
|
958
963
|
messages: unknown[],
|
|
959
964
|
lancedbDir: string,
|
|
965
|
+
cursorOnly = false,
|
|
960
966
|
): Promise<void> {
|
|
961
967
|
if (messages.length === 0) {
|
|
962
968
|
return;
|
|
@@ -973,6 +979,25 @@ async function runAgentEndCapture(
|
|
|
973
979
|
}
|
|
974
980
|
|
|
975
981
|
const running: Record<string, number> = { ...saved };
|
|
982
|
+
|
|
983
|
+
// --- cursor-only fast path: count roles then persist without extraction ---
|
|
984
|
+
if (cursorOnly) {
|
|
985
|
+
for (const msg of messages) {
|
|
986
|
+
if (!msg || typeof msg !== "object") continue;
|
|
987
|
+
const m = msg as Record<string, unknown>;
|
|
988
|
+
const roleRaw = typeof m.role === "string" ? m.role : "unknown";
|
|
989
|
+
const roleKey = normalizeRoleForCursor(roleRaw);
|
|
990
|
+
running[roleKey] = (running[roleKey] ?? 0) + 1;
|
|
991
|
+
}
|
|
992
|
+
map[key] = { version: 2, roleCounts: { ...running }, lastMessagesLength: messages.length };
|
|
993
|
+
saveAgentEndCursorMap(lancedbDir, map);
|
|
994
|
+
console.log(
|
|
995
|
+
`[openclaw-memory-alibaba-local] agent_end cursor-only advance (non-user trigger) messages=${messages.length}`,
|
|
996
|
+
);
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
// --- full capture path (trigger === "user") ---
|
|
976
1001
|
const fullRows: DeltaFullContextRow[] = [];
|
|
977
1002
|
const userRawTexts: string[] = [];
|
|
978
1003
|
const uaLines: string[] = [];
|
|
@@ -1942,7 +1967,6 @@ const memoryPlugin = {
|
|
|
1942
1967
|
|
|
1943
1968
|
if (cfg.autoCapture) {
|
|
1944
1969
|
api.on("agent_end", async (event, ctx) => {
|
|
1945
|
-
if ((ctx as { trigger?: string }).trigger !== "user") return;
|
|
1946
1970
|
if (!db || !backend) {
|
|
1947
1971
|
return;
|
|
1948
1972
|
}
|
|
@@ -1950,6 +1974,9 @@ const memoryPlugin = {
|
|
|
1950
1974
|
return;
|
|
1951
1975
|
}
|
|
1952
1976
|
|
|
1977
|
+
const trigger = (ctx as { trigger?: string }).trigger;
|
|
1978
|
+
const isUserTrigger = trigger === "user";
|
|
1979
|
+
|
|
1953
1980
|
try {
|
|
1954
1981
|
const tCap0 = Date.now();
|
|
1955
1982
|
const storageSessionKey = resolveStorageSessionKey(ctx);
|
|
@@ -1971,9 +1998,10 @@ const memoryPlugin = {
|
|
|
1971
1998
|
userId,
|
|
1972
1999
|
event.messages,
|
|
1973
2000
|
resolvedDbPath,
|
|
2001
|
+
!isUserTrigger,
|
|
1974
2002
|
);
|
|
1975
2003
|
console.log(
|
|
1976
|
-
`[openclaw-memory-alibaba-local] agent_end capture done totalHookMs=${Date.now() - tCap0} messages=${event.messages.length}`,
|
|
2004
|
+
`[openclaw-memory-alibaba-local] agent_end ${isUserTrigger ? "capture" : "cursor-only"} done totalHookMs=${Date.now() - tCap0} messages=${event.messages.length} trigger=${trigger ?? "unknown"}`,
|
|
1977
2005
|
);
|
|
1978
2006
|
} catch (err) {
|
|
1979
2007
|
console.warn(`[openclaw-memory-alibaba-local] agent_end capture failed: ${String(err)}`);
|