mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
clawdbot-6f0: route command entry persistence through seam
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Shared session persistence and prompt-body helpers for agent attempt
|
||||
* execution paths.
|
||||
*/
|
||||
import { updateSessionStore } from "../../config/sessions/store.js";
|
||||
import { patchSessionEntry } from "../../config/sessions/session-accessor.js";
|
||||
import { mergeSessionEntry, type SessionEntry } from "../../config/sessions/types.js";
|
||||
import {
|
||||
formatAgentInternalEventsForPlainPrompt,
|
||||
@@ -28,14 +28,15 @@ export type PersistSessionEntryParams = {
|
||||
export async function persistSessionEntry(
|
||||
params: PersistSessionEntryParams,
|
||||
): Promise<SessionEntry | undefined> {
|
||||
const persisted = await updateSessionStore(
|
||||
params.storePath,
|
||||
(store) => {
|
||||
const current = store[params.sessionKey];
|
||||
if (params.shouldPersist && !params.shouldPersist(current)) {
|
||||
return current;
|
||||
let rejectedMissingEntry = false;
|
||||
const persisted = await patchSessionEntry(
|
||||
{ sessionKey: params.sessionKey, storePath: params.storePath },
|
||||
(_entry, context) => {
|
||||
if (params.shouldPersist && !params.shouldPersist(context.existingEntry)) {
|
||||
rejectedMissingEntry = !context.existingEntry;
|
||||
return null;
|
||||
}
|
||||
const merged = mergeSessionEntry(store[params.sessionKey], params.entry);
|
||||
const merged = mergeSessionEntry(context.existingEntry, params.entry);
|
||||
for (const field of params.clearedFields ?? []) {
|
||||
// Cleared fields only apply when the replacement entry did not set the
|
||||
// field again; this preserves explicit false/null updates.
|
||||
@@ -43,21 +44,23 @@ export async function persistSessionEntry(
|
||||
Reflect.deleteProperty(merged, field);
|
||||
}
|
||||
}
|
||||
store[params.sessionKey] = merged;
|
||||
return merged;
|
||||
},
|
||||
{
|
||||
resolveSingleEntryPersistence: (entry) =>
|
||||
entry ? { sessionKey: params.sessionKey, entry } : null,
|
||||
takeCacheOwnership: true,
|
||||
fallbackEntry: params.sessionStore[params.sessionKey] ?? params.entry,
|
||||
replaceEntry: true,
|
||||
},
|
||||
);
|
||||
if (rejectedMissingEntry) {
|
||||
delete params.sessionStore[params.sessionKey];
|
||||
return undefined;
|
||||
}
|
||||
if (persisted) {
|
||||
params.sessionStore[params.sessionKey] = persisted;
|
||||
} else {
|
||||
delete params.sessionStore[params.sessionKey];
|
||||
}
|
||||
return persisted;
|
||||
return persisted ?? undefined;
|
||||
}
|
||||
|
||||
/** Prepends hidden internal event context unless the body already carries it. */
|
||||
|
||||
Reference in New Issue
Block a user