File size: 1,731 Bytes
76289e7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | // Legacy context engine wraps pre-plugin context behavior behind the pluggable interface.
import { delegateCompactionToRuntime } from "./delegate.js";
import { CONTEXT_ENGINE_HOST_PARAMS } from "./registry-contract.js";
import type { AssembleResult, ContextEngine, ContextEngineInfo } from "./types.js";
/**
* LegacyContextEngine wraps the existing compaction behavior behind the
* ContextEngine interface, preserving 100% backward compatibility.
*
* - ingest: no-op (SessionManager handles message persistence)
* - assemble: pass-through (existing sanitize/validate/limit pipeline in attempt.ts handles this)
* - compact: delegates to the built-in compaction runtime
*/
export class LegacyContextEngine implements ContextEngine {
readonly info: ContextEngineInfo = {
id: "legacy",
name: "Legacy Context Engine",
version: "1.0.0",
acceptedHostParams: [...CONTEXT_ENGINE_HOST_PARAMS],
};
async ingest(_params: Parameters<ContextEngine["ingest"]>[0]) {
// No-op: SessionManager handles message persistence in the legacy flow
return { ingested: false };
}
async assemble(params: Parameters<ContextEngine["assemble"]>[0]): Promise<AssembleResult> {
// Pass-through: the existing sanitize -> validate -> limit -> repair pipeline
// in attempt.ts handles context assembly for the legacy engine.
// We just return the messages as-is with a rough token estimate.
return {
messages: params.messages,
estimatedTokens: 0, // Caller handles estimation
};
}
// Preserve the canonical delegate identity so the host knows the built-in
// runtime, rather than this engine wrapper, owns the compaction watchdog.
readonly compact = delegateCompactionToRuntime;
}
|