mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-15 15:13:48 -06:00
8b0735e89f
* refactor(memory): remove qmd backend Make builtin the sole memory-core engine, rename the retained session helper barrel, retire QMD config with doctor migrations, and remove QMD runtime/UI/policy surfaces. * docs(memory): remove qmd backend guidance Delete the QMD concept page, rewrite memory documentation for builtin retrieval, and remove QMD from navigation and taxonomy source. * refactor(memory): remove qmd-only leftovers * refactor(memory): finish qmd integration cleanup * build(deps): align root string-width types * build(deps): model root string-width tooling * refactor(memory): align qmd removal ui and docs * fix(memory): preserve qmd external paths in doctor * test(memory): remove obsolete backend probe case * test(plugin-sdk): refresh private type baseline
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
// Memory Core plugin module implements tools.citations behavior.
|
|
import {
|
|
parseAgentSessionKey,
|
|
type MemoryCitationsMode,
|
|
type OpenClawConfig,
|
|
} from "openclaw/plugin-sdk/memory-core-host-runtime-core";
|
|
import type { MemorySearchResult } from "openclaw/plugin-sdk/memory-core-host-runtime-files";
|
|
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
|
|
export function resolveMemoryCitationsMode(cfg: OpenClawConfig): MemoryCitationsMode {
|
|
const mode = cfg.memory?.citations;
|
|
if (mode === "on" || mode === "off" || mode === "auto") {
|
|
return mode;
|
|
}
|
|
return "auto";
|
|
}
|
|
|
|
export function decorateCitations(
|
|
results: MemorySearchResult[],
|
|
include: boolean,
|
|
): MemorySearchResult[] {
|
|
if (!include) {
|
|
return results.map((entry) => ({ ...entry, citation: undefined }));
|
|
}
|
|
return results.map((entry) => {
|
|
const citation = formatCitation(entry);
|
|
const snippet = `${entry.snippet.trim()}\n\nSource: ${citation}`;
|
|
return { ...entry, citation, snippet };
|
|
});
|
|
}
|
|
|
|
function formatCitation(entry: MemorySearchResult): string {
|
|
const lineRange =
|
|
entry.startLine === entry.endLine
|
|
? `#L${entry.startLine}`
|
|
: `#L${entry.startLine}-L${entry.endLine}`;
|
|
return `${entry.path}${lineRange}`;
|
|
}
|
|
|
|
export function shouldIncludeCitations(params: {
|
|
mode: MemoryCitationsMode;
|
|
sessionKey?: string;
|
|
}): boolean {
|
|
if (params.mode === "on") {
|
|
return true;
|
|
}
|
|
if (params.mode === "off") {
|
|
return false;
|
|
}
|
|
return deriveChatTypeFromSessionKey(params.sessionKey) === "direct";
|
|
}
|
|
|
|
function deriveChatTypeFromSessionKey(sessionKey?: string): "direct" | "group" | "channel" {
|
|
const parsed = parseAgentSessionKey(sessionKey);
|
|
if (!parsed?.rest) {
|
|
return "direct";
|
|
}
|
|
const tokens = new Set(normalizeLowercaseStringOrEmpty(parsed.rest).split(":").filter(Boolean));
|
|
if (tokens.has("channel")) {
|
|
return "channel";
|
|
}
|
|
if (tokens.has("group")) {
|
|
return "group";
|
|
}
|
|
return "direct";
|
|
}
|