import type { CompactEmbeddedPiSessionDirect } from "../agents/pi-embedded-runner/compact.runtime.types.js"; import { normalizeStructuredPromptSection } from "../agents/prompt-cache-stability.js"; import type { MemoryCitationsMode } from "../config/types.memory.js"; import { buildMemoryPromptSection } from "../plugins/memory-state.js"; import type { ContextEngine, CompactResult, ContextEngineRuntimeContext } from "./types.js";
type CompactRuntimeModule = {
compactEmbeddedPiSessionDirect: CompactEmbeddedPiSessionDirect;
};
let compactRuntimePromise: Promise<CompactRuntimeModule> | null = null;
function loadCompactRuntime(): Promise<CompactRuntimeModule> { // Use a literal specifier so the bundler rewrites the runtime chunk path // instead of resolving a source-tree path at runtime.
compactRuntimePromise ??= import("../agents/pi-embedded-runner/compact.runtime.js"); return compactRuntimePromise;
}
/** *Delegateacontext-enginecompactionrequesttoOpenClaw'sbuilt-inruntimecompactionpath. * *Thisisthesamebridgeusedbythelegacycontextengine.Third-party *enginescancallitfromtheirown`compact()`implementationswhentheydo *notownthecompactionalgorithmbutstillneed`/compact`andoverflow *recoverytousethestockruntimebehavior. * *Note:`compactionTarget`ispartofthepublic`compact()`contract,butthe *built-inruntimecompactionpathdoesnotexposethatknob.Thishelper *ignoresittopreservelegacybehavior;enginesthatneedtarget-specific *compactionshouldimplementtheirown`compact()`algorithm.
*/
export async function delegateCompactionToRuntime(
params: Parameters<ContextEngine["compact"]>[0],
): Promise<CompactResult> { // Load through the dedicated runtime boundary without introducing another // source-level static edge into the embedded runner graph. const { compactEmbeddedPiSessionDirect } = await loadCompactRuntime();
type RuntimeCompactionParams = Parameters<typeof compactEmbeddedPiSessionDirect>[0];
// runtimeContext carries the full CompactEmbeddedPiSessionParams fields set // by runtime callers. We spread them and override the fields that come from // the public ContextEngine compact() signature directly. const runtimeContext = (params.runtimeContext ?? {}) as ContextEngineRuntimeContext &
Partial<RuntimeCompactionParams>; const currentTokenCount =
params.currentTokenCount ??
(typeof runtimeContext.currentTokenCount === "number" &&
Number.isFinite(runtimeContext.currentTokenCount) &&
runtimeContext.currentTokenCount > 0
? Math.floor(runtimeContext.currentTokenCount)
: undefined);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.