openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
163 lines (162 loc) • 5.89 kB
JavaScript
import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs";
import { S as resolveSessionAgentIdStrict, _ as resolveDefaultAgentId } from "./agent-scope-config-DmXgFGKP.mjs";
import { Et as _enum, Jn as string, Lt as boolean, Nt as array, Pn as number, qn as strictObject } from "./schemas-Cy6abvsu.mjs";
import "./state-paths-qdCZ9HDY.mjs";
import "./agent-scope-runtime-CDpr-vor.mjs";
import path from "node:path";
import os from "node:os";
//#region extensions/memory-wiki/src/config.ts
const WIKI_VAULT_MODES = [
"isolated",
"bridge",
"unsafe-local"
];
const WIKI_VAULT_SCOPES = ["global", "agent"];
const WIKI_RENDER_MODES = ["native", "obsidian"];
const WIKI_SEARCH_BACKENDS = ["shared", "local"];
const WIKI_SEARCH_CORPORA = [
"wiki",
"memory",
"all"
];
const MemoryWikiConfigSource = strictObject({
vaultMode: _enum(WIKI_VAULT_MODES).optional(),
vault: strictObject({
scope: _enum(WIKI_VAULT_SCOPES).optional(),
path: string().optional(),
renderMode: _enum(WIKI_RENDER_MODES).optional()
}).optional(),
obsidian: strictObject({
enabled: boolean().optional(),
useOfficialCli: boolean().optional(),
vaultName: string().optional(),
openAfterWrites: boolean().optional()
}).optional(),
bridge: strictObject({
enabled: boolean().optional(),
readMemoryArtifacts: boolean().optional(),
indexDreamReports: boolean().optional(),
indexDailyNotes: boolean().optional(),
indexMemoryRoot: boolean().optional(),
followMemoryEvents: boolean().optional()
}).optional(),
unsafeLocal: strictObject({
allowPrivateMemoryCoreAccess: boolean().optional(),
paths: array(string()).optional()
}).optional(),
ingest: strictObject({
autoCompile: boolean().optional(),
maxConcurrentJobs: number().int().min(1).optional(),
allowUrlIngest: boolean().optional()
}).optional(),
search: strictObject({
backend: _enum(WIKI_SEARCH_BACKENDS).optional(),
corpus: _enum(WIKI_SEARCH_CORPORA).optional()
}).optional(),
context: strictObject({ includeCompiledDigestPrompt: boolean().optional() }).optional(),
render: strictObject({
preserveHumanBlocks: boolean().optional(),
createBacklinks: boolean().optional(),
createDashboards: boolean().optional()
}).optional()
}).superRefine((e, t) => {
if (e.vault?.scope === "agent" && e.vaultMode === "unsafe-local") t.addIssue({
code: "custom",
path: ["vaultMode"],
message: "vaultMode=unsafe-local cannot be combined with vault.scope=agent"
});
if (e.vault?.scope === "agent" && e.obsidian?.useOfficialCli === true) t.addIssue({
code: "custom",
path: ["obsidian", "useOfficialCli"],
message: "obsidian.useOfficialCli cannot be enabled with vault.scope=agent"
});
});
function expandHomePath(e, t) {
if (e === "~") return t;
if (e.startsWith("~/")) return path.join(t, e.slice(2));
return e;
}
function resolveMemoryWikiConfig(e, t) {
const n = t?.homedir ?? os.homedir();
const r = e ?? {};
const i = r.vault?.scope ?? "global";
const a = r.vault?.path ?? path.join(resolveStateDir({
...t?.env ?? process.env,
HOME: n
}), "wiki", ...i === "agent" ? [] : ["main"]);
return {
vaultMode: r.vaultMode ?? "isolated",
vault: {
scope: i,
path: expandHomePath(a, n),
renderMode: r.vault?.renderMode ?? "native"
},
obsidian: {
enabled: r.obsidian?.enabled ?? false,
useOfficialCli: r.obsidian?.useOfficialCli ?? false,
...r.obsidian?.vaultName ? { vaultName: r.obsidian.vaultName } : {},
openAfterWrites: r.obsidian?.openAfterWrites ?? false
},
bridge: {
enabled: r.bridge?.enabled ?? false,
readMemoryArtifacts: r.bridge?.readMemoryArtifacts ?? true,
indexDreamReports: r.bridge?.indexDreamReports ?? true,
indexDailyNotes: r.bridge?.indexDailyNotes ?? true,
indexMemoryRoot: r.bridge?.indexMemoryRoot ?? true,
followMemoryEvents: r.bridge?.followMemoryEvents ?? true
},
unsafeLocal: {
allowPrivateMemoryCoreAccess: r.unsafeLocal?.allowPrivateMemoryCoreAccess ?? false,
paths: r.unsafeLocal?.paths ?? []
},
ingest: {
autoCompile: r.ingest?.autoCompile ?? true,
maxConcurrentJobs: r.ingest?.maxConcurrentJobs ?? 1,
allowUrlIngest: r.ingest?.allowUrlIngest ?? true
},
search: {
backend: r.search?.backend ?? "shared",
corpus: r.search?.corpus ?? "wiki"
},
context: { includeCompiledDigestPrompt: r.context?.includeCompiledDigestPrompt ?? false },
render: {
preserveHumanBlocks: r.render?.preserveHumanBlocks ?? true,
createBacklinks: r.render?.createBacklinks ?? true,
createDashboards: r.render?.createDashboards ?? true
}
};
}
function resolveMemoryWikiConfiguredAgentIds(e) {
const t = Object.keys(e?.agents?.entries ?? {}).flatMap((t) => {
const n = t.trim();
if (!n) return [];
return [resolveSessionAgentIdStrict({
config: e,
agentId: n
})];
});
return [...new Set(t.length > 0 ? t : [resolveDefaultAgentId(e ?? {})])];
}
/** Resolve the exact vault for one trusted runtime agent context. */
function resolveMemoryWikiAgentConfig(e) {
if (e.config.vault.scope === "global") return e.config;
if (e.config.vaultMode === "unsafe-local") throw new Error("memory-wiki vault.scope=agent does not support vaultMode=unsafe-local.");
const t = resolveMemoryWikiConfiguredAgentIds(e.appConfig);
const n = e.agentId?.trim();
if (!n && t.length > 1) throw new Error("agentId is required for memory-wiki when vault.scope=agent.");
const r = resolveSessionAgentIdStrict({
config: e.appConfig,
agentId: n ?? resolveDefaultAgentId(e.appConfig ?? {})
});
if (!t.includes(r)) throw new Error(`Unknown memory-wiki agentId: ${n ?? r}.`);
return {
...e.config,
agentId: r,
vault: {
...e.config.vault,
path: path.join(e.config.vault.path, r)
}
};
}
//#endregion
export { resolveMemoryWikiConfig as a, resolveMemoryWikiAgentConfig as i, WIKI_SEARCH_BACKENDS as n, resolveMemoryWikiConfiguredAgentIds as o, WIKI_SEARCH_CORPORA as r, MemoryWikiConfigSource as t };