mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
clawdbot-ce2: route gateway session entries through accessor
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
import { normalizeAgentId } from "../../routing/session-key.js";
|
||||
import type { OpenClawConfig } from "../types.openclaw.js";
|
||||
import { resolveStorePath } from "./paths.js";
|
||||
import { loadSessionStore } from "./store-load.js";
|
||||
import { listSessionEntries } from "./session-accessor.js";
|
||||
import {
|
||||
resolveAgentSessionStoreTargetsSync,
|
||||
resolveAllAgentSessionStoreTargetsSync,
|
||||
@@ -22,6 +22,15 @@ function isStorePathTemplate(store?: string): boolean {
|
||||
return typeof store === "string" && store.includes("{agentId}");
|
||||
}
|
||||
|
||||
function loadGatewayStoreEntries(storePath: string): Record<string, SessionEntry> {
|
||||
return Object.fromEntries(
|
||||
listSessionEntries({ clone: false, storePath }).map(({ sessionKey, entry }) => [
|
||||
sessionKey,
|
||||
entry,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
function mergeSessionEntryIntoCombined(params: {
|
||||
cfg: OpenClawConfig;
|
||||
combined: Record<string, SessionEntry>;
|
||||
@@ -76,7 +85,7 @@ export function loadCombinedSessionStoreForGateway(
|
||||
// A single shared store still needs keys canonicalized as if owned by the default agent.
|
||||
const storePath = resolveStorePath(storeConfig);
|
||||
const defaultAgentId = normalizeAgentId(resolveDefaultAgentId(cfg));
|
||||
const store = loadSessionStore(storePath, { clone: false });
|
||||
const store = loadGatewayStoreEntries(storePath);
|
||||
const combined: Record<string, SessionEntry> = {};
|
||||
for (const [key, entry] of Object.entries(store)) {
|
||||
const canonicalKey = resolveStoredSessionKeyForAgentStore({
|
||||
@@ -108,7 +117,7 @@ export function loadCombinedSessionStoreForGateway(
|
||||
for (const target of targets) {
|
||||
const agentId = target.agentId;
|
||||
const storePath = target.storePath;
|
||||
const store = loadSessionStore(storePath, { clone: false });
|
||||
const store = loadGatewayStoreEntries(storePath);
|
||||
for (const [key, entry] of Object.entries(store)) {
|
||||
const canonicalKey = resolveStoredSessionKeyForAgentStore({
|
||||
cfg,
|
||||
|
||||
@@ -57,7 +57,6 @@ import { resolveStateDir } from "../config/paths.js";
|
||||
import {
|
||||
buildGroupDisplayName,
|
||||
getSessionStoreCacheVersion,
|
||||
loadSessionStore,
|
||||
resolveAllAgentSessionStoreTargetsSync,
|
||||
resolveAgentMainSessionKey,
|
||||
resolveFreshSessionTotalTokens,
|
||||
@@ -67,6 +66,7 @@ import {
|
||||
type SessionStoreTarget,
|
||||
type SessionScope,
|
||||
} from "../config/sessions.js";
|
||||
import { listSessionEntries as listAccessorSessionEntries } from "../config/sessions/session-accessor.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { openRootFileSync } from "../infra/boundary-file-read.js";
|
||||
import { projectPluginSessionExtensionsSync } from "../plugins/host-hook-state.js";
|
||||
@@ -1346,6 +1346,18 @@ function resolveGatewaySessionStoreCandidates(
|
||||
return [...targets.values()];
|
||||
}
|
||||
|
||||
function loadGatewaySessionLookupStore(
|
||||
storePath: string,
|
||||
clone: boolean | undefined,
|
||||
): Record<string, SessionEntry> {
|
||||
return Object.fromEntries(
|
||||
listAccessorSessionEntries({
|
||||
...(clone === false ? { clone: false } : {}),
|
||||
storePath,
|
||||
}).map(({ sessionKey, entry }) => [sessionKey, entry]),
|
||||
);
|
||||
}
|
||||
|
||||
function resolveGatewaySessionStoreLookup(params: {
|
||||
cfg: OpenClawConfig;
|
||||
key: string;
|
||||
@@ -1364,9 +1376,9 @@ function resolveGatewaySessionStoreLookup(params: {
|
||||
agentId: params.agentId,
|
||||
storePath: resolveStorePath(params.cfg.session?.store, { agentId: params.agentId }),
|
||||
};
|
||||
const loadOptions = params.clone === false ? { clone: false } : undefined;
|
||||
const loadStore = (storePath: string) => loadGatewaySessionLookupStore(storePath, params.clone);
|
||||
let selectedStorePath = fallback.storePath;
|
||||
let selectedStore = params.initialStore ?? loadSessionStore(fallback.storePath, loadOptions);
|
||||
let selectedStore = params.initialStore ?? loadStore(fallback.storePath);
|
||||
let selectedMatch = findFreshestStoreMatch(selectedStore, ...scanTargets);
|
||||
let selectedUpdatedAt = selectedMatch?.entry.updatedAt ?? Number.NEGATIVE_INFINITY;
|
||||
|
||||
@@ -1375,7 +1387,7 @@ function resolveGatewaySessionStoreLookup(params: {
|
||||
if (!candidate) {
|
||||
continue;
|
||||
}
|
||||
const store = loadSessionStore(candidate.storePath, loadOptions);
|
||||
const store = loadStore(candidate.storePath);
|
||||
const match = findFreshestStoreMatch(store, ...scanTargets);
|
||||
if (!match) {
|
||||
continue;
|
||||
@@ -1433,12 +1445,11 @@ function resolveExplicitDeletedLegacyMainStoreTarget(params: {
|
||||
match: { entry: SessionEntry; key: string };
|
||||
}
|
||||
| undefined;
|
||||
const loadOptions = params.clone === false ? { clone: false } : undefined;
|
||||
for (const target of resolveAllAgentSessionStoreTargetsSync(params.cfg)) {
|
||||
if (target.agentId !== legacyAgentId) {
|
||||
continue;
|
||||
}
|
||||
const store = loadSessionStore(target.storePath, loadOptions);
|
||||
const store = loadGatewaySessionLookupStore(target.storePath, params.clone);
|
||||
const match = findFreshestStoreMatch(store, ...lookupSeeds);
|
||||
if (!match) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user