UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

45 lines (44 loc) • 1.51 kB
import { r as selectBoundedContextStart } from "./session-bounded-context-selection-B1kY2VbM.mjs"; import { n as estimateTokens } from "./compaction-cut-point-CEj7MSFJ.mjs"; import { r as resolveExpiredRuntimeContextContentBytes } from "./transcript-byte-limit-SRI2OVpS.mjs"; import { createHash } from "node:crypto"; //#region src/context-engine/bounded-context.ts /** Bounds only the model view; required instructions and the pending input stay with their owners. */ function boundContextEngineAssembly(e, t, n, r, i = false) { if (t === void 0) return e; const { messages: a } = e; const o = i ? resolveExpiredRuntimeContextContentBytes(a) : void 0; const s = selectBoundedContextStart(a, t, n, (e) => { const t = a[e]; const n = r?.get(t) ?? 0; return { bytes: Buffer.byteLength(JSON.stringify(t), "utf8") + n - (o?.get(t) ?? 0), tokens: (o?.has(t) ? 0 : estimateTokens(t)) + (n ? Math.ceil(n / 4) : 0) }; }); if (!s) return e; const c = a.slice(s); const l = createHash("sha256").update(JSON.stringify([ e.contextProjection, t, a[s - 1], c, e.systemPromptAddition ])).digest("hex"); return { ...e, messages: c, estimatedTokens: c.reduce((e, t) => { const n = r?.get(t) ?? 0; return e + (o?.has(t) ? 0 : estimateTokens(t)) + (n ? Math.ceil(n / 4) : 0); }, 0), promptAuthority: "assembled", contextProjection: { mode: "thread_bootstrap", epoch: `bounded:${l}`, fingerprint: l } }; } //#endregion export { boundContextEngineAssembly as t };