openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
186 lines (185 loc) • 7.5 kB
JavaScript
import { i as clampNumber } from "./utils-C8YECn2Q.mjs";
import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs";
import { c as resolveOpenClawAgentSqlitePath } from "./openclaw-agent-db.paths-DJxv80ws.mjs";
import { r as resolveAgentConfig } from "./agent-scope-config-DmXgFGKP.mjs";
import "./agent-scope-BwB8YH6y.mjs";
import { r as assertSecretOwnerAvailable } from "./runtime-degraded-state-BSnwk5PQ.mjs";
import { n as normalizeConfiguredMemoryExtraPaths, o as resolveRememberAcrossConversations } from "./config-utils-sHBULYOF.mjs";
import "./config-utils-CoN3l5FQ.mjs";
import { i as normalizeMemoryMultimodalSettings, r as isMemoryMultimodalEnabled } from "./multimodal-CD7YKC3g.mjs";
import { t as runtimeMemorySecretOwnerId } from "./runtime-memory-secret-owner-4045GklN.mjs";
import { t as getMemoryEmbeddingProvider } from "./memory-embedding-provider-runtime-XHJ-dZvt.mjs";
//#region src/agents/memory-search.ts
/**
* Resolves memory-search source, sync, and ranking configuration.
*/
const DEFAULT_SOURCES = ["memory"];
function normalizeSources(e, t) {
const n = e?.length ? e : DEFAULT_SOURCES;
const r = [...new Set(n.filter((e) => e === "memory" || e === "sessions" && t))];
return r.length > 0 ? r : [...DEFAULT_SOURCES];
}
const DEFAULT_MAX_RESULTS = 6;
const DEFAULT_MIN_SCORE = .35;
const DEFAULT_CACHE_ENABLED = true;
const DEFAULT_CACHE_MAX_ENTRIES = 5e4;
const DEFAULT_MEMORY_EMBEDDING_PROVIDER = "openai";
function resolveMemorySearchProviderId(e) {
const t = e?.trim();
if (t?.toLowerCase() === "none") return "none";
return t && t.toLowerCase() !== "auto" ? t : DEFAULT_MEMORY_EMBEDDING_PROVIDER;
}
/** Compare provider identities without collapsing distinct configured tenants into their adapter. */
function isSameMemorySearchProvider(e, t) {
const canonical = (e) => {
const t = resolveMemorySearchProviderId(normalizeProviderId(e ?? ""));
return t === "google" ? "gemini" : t;
};
return canonical(e) === canonical(t);
}
function getConfiguredMemoryEmbeddingProvider(e, t) {
if (normalizeProviderId(e) === "none") return;
return getMemoryEmbeddingProvider(e, t);
}
/** Resolves source and query settings without loading an embedding provider runtime. */
function resolveMemorySearchIndexConfig(e, t) {
const n = e.memory?.search;
const r = resolveAgentConfig(e, t)?.memory?.search;
const i = r?.enabled ?? n?.enabled ?? true;
if (!i) return null;
assertSecretOwnerAvailable("capability", runtimeMemorySecretOwnerId(t));
const a = resolveRememberAcrossConversations(e, t);
const o = r?.experimental?.sessionMemory ?? n?.experimental?.sessionMemory ?? false;
const s = r?.sources ?? n?.sources;
/** Resolve query and indexed sources from already-selected memory policy facts. */
const c = a || o;
const l = normalizeSources(s, c);
return {
enabled: i,
rememberAcrossConversations: a,
sources: normalizeSources(a ? [...l, "sessions"] : s, c),
searchSources: l,
sessionSourceExcluded: s?.includes("sessions") === true && !l.includes("sessions"),
extraPaths: normalizeConfiguredMemoryExtraPaths([...n?.extraPaths ?? [], ...r?.extraPaths ?? []]),
query: {
maxResults: r?.query?.maxResults ?? n?.query?.maxResults ?? DEFAULT_MAX_RESULTS,
minScore: clampNumber(r?.query?.minScore ?? n?.query?.minScore ?? DEFAULT_MIN_SCORE, 0, 1),
hybrid: {
enabled: true,
vectorWeight: .7,
textWeight: .3,
candidateMultiplier: 4,
mmr: {
enabled: true,
lambda: .7
},
temporalDecay: {
enabled: true,
halfLifeDays: 30
}
}
},
experimental: { sessionMemory: c },
sync: resolveSyncConfig()
};
}
function produceMemorySearchConfig(e, t) {
const n = resolveMemorySearchIndexConfig(e, t);
if (!n) return null;
const r = e.memory?.search;
const i = resolveAgentConfig(e, t)?.memory?.search;
const a = resolveMemorySearchProviderId(i?.provider ?? r?.provider);
const o = getConfiguredMemoryEmbeddingProvider(a, e);
const s = r?.remote;
const c = i?.remote;
const l = isSameMemorySearchProvider(a, r?.provider) || c?.baseUrl === void 0 && s?.baseUrl?.trim() ? s : void 0;
const u = i?.fallback ?? r?.fallback ?? "none";
const d = u.toLowerCase() === "none" ? "none" : u;
const f = normalizeProviderId(a) !== "none" && d && d !== "none" ? getConfiguredMemoryEmbeddingProvider(d, e) : void 0;
const p = [c, s].some((e) => e?.baseUrl || e?.apiKey || e?.headers) || o?.transport !== "local" || f?.transport === "remote" ? {
baseUrl: c?.baseUrl ?? l?.baseUrl,
apiKey: c?.apiKey ?? l?.apiKey,
headers: c?.headers ?? l?.headers,
batch: {
enabled: c?.batch?.enabled ?? s?.batch?.enabled ?? false,
wait: true,
concurrency: 2,
pollIntervalMs: 2e3,
timeoutMinutes: 60
}
} : void 0;
const m = i?.model ?? r?.model ?? o?.defaultModel ?? "";
const h = i?.inputType?.trim() || r?.inputType?.trim() || void 0;
const g = i?.queryInputType?.trim() || r?.queryInputType?.trim() || void 0;
const _ = i?.documentInputType?.trim() || r?.documentInputType?.trim() || void 0;
const v = i?.outputDimensionality ?? r?.outputDimensionality;
const y = normalizeMemoryMultimodalSettings({
enabled: i?.multimodal?.enabled ?? r?.multimodal?.enabled,
modalities: i?.multimodal?.modalities ?? r?.multimodal?.modalities,
maxFileBytes: i?.multimodal?.maxFileBytes ?? r?.multimodal?.maxFileBytes
});
const b = {
...n,
multimodal: y,
provider: a,
remote: p,
fallback: d,
model: m,
inputFormat: i?.inputFormat ?? r?.inputFormat,
inputType: h,
queryInputType: g,
queryInstruction: (i?.queryInstruction ?? r?.queryInstruction) || void 0,
documentInputType: _,
outputDimensionality: v,
local: { modelPath: i?.local?.modelPath ?? r?.local?.modelPath },
store: {
driver: "sqlite",
databasePath: resolveOpenClawAgentSqlitePath({
agentId: t,
env: process.env
}),
fts: { tokenizer: i?.store?.fts?.tokenizer ?? r?.store?.fts?.tokenizer ?? "unicode61" },
vector: {
enabled: i?.store?.vector?.enabled ?? r?.store?.vector?.enabled ?? true,
extensionPath: i?.store?.vector?.extensionPath ?? r?.store?.vector?.extensionPath
}
},
chunking: {
tokens: 400,
overlap: 80
},
cache: {
enabled: i?.cache?.enabled ?? r?.cache?.enabled ?? DEFAULT_CACHE_ENABLED,
maxEntries: DEFAULT_CACHE_MAX_ENTRIES
}
};
const x = isMemoryMultimodalEnabled(b.multimodal);
if (x && o && !(o.supportsMultimodalEmbeddings?.({ model: b.model }) ?? false)) throw new Error("memory.search.multimodal requires a provider adapter that supports multimodal embeddings for the configured model.");
if (x && b.fallback !== "none") throw new Error("memory.search.multimodal does not support memory.search.fallback. Set fallback to \"none\".");
return b;
}
function resolveMemorySearchConfig(e, t) {
return produceMemorySearchConfig(e, t);
}
function resolveSyncConfig() {
return {
onSessionStart: true,
onSearch: true,
watch: true,
watchDebounceMs: 1500,
intervalMinutes: 0,
embeddingBatchTimeoutSeconds: void 0,
sessions: {
deltaBytes: 1e5,
deltaMessages: 50,
postCompactionForce: true
}
};
}
function resolveMemorySearchSyncConfig(e, t) {
const n = e.memory?.search;
if (!((resolveAgentConfig(e, t)?.memory?.search)?.enabled ?? n?.enabled ?? true)) return null;
return resolveSyncConfig();
}
//#endregion
export { resolveMemorySearchSyncConfig as a, resolveMemorySearchProviderId as i, resolveMemorySearchConfig as n, resolveMemorySearchIndexConfig as r, isSameMemorySearchProvider as t };