openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
54 lines (53 loc) • 2.23 kB
JavaScript
import { t as AsyncContext } from "./async-context-BYDAvG9A.mjs";
//#region src/agents/harness/context-engine-assembly-attempt.ts
const assemblyAttempt = new AsyncContext(Symbol.for("openclaw.contextEngineAssemblyAttempt"));
/** Each concrete retry owns its assembly facts; rejected and concurrent attempts share none. */
async function runWithContextEngineAssemblyAttempt(e) {
const t = {};
return {
result: await assemblyAttempt.run(t, e),
assembly: t.snapshot
};
}
function clearContextEngineAssemblySnapshot() {
const e = assemblyAttempt.getStore();
if (e) e.snapshot = void 0;
}
function recordContextEngineAssemblySnapshot(e) {
const t = assemblyAttempt.getStore();
if (t) t.snapshot = e;
}
function readContextEngineAssemblyBudget(e, t = assemblyAttempt.getStore()?.snapshot) {
if (!t || t.sessionId !== e.sessionId || t.sessionKey !== e.sessionKey || t.provider !== e.provider || t.modelId !== e.modelId) return;
return t.tokenBudget;
}
function resolveContextEngineCompletionRuntimeContext(e, t, n, r) {
const i = t.runtimeModelSelection ?? {
provider: e.provider,
model: e.modelId
};
const a = readContextEngineAssemblyBudget({
sessionId: t.sessionIdUsed,
sessionKey: e.sessionKey,
provider: i.provider,
modelId: i.model
}, r ?? null);
const o = t.promptCache ? { promptCache: t.promptCache } : {};
const s = t.contextTokensSource === "runtime" || t.contextTokensSource === "runtime-configured" ? t.contextTokens : void 0;
if (t.runtimeModelSelection && (n || i.provider !== e.provider || i.model !== e.modelId)) return {
provider: i.provider,
modelId: i.model,
...s === void 0 ? {} : { modelContextWindow: s },
...a === void 0 && s === void 0 ? {} : { tokenBudget: a ?? s },
...o
};
return {
provider: e.provider,
modelId: e.modelId,
modelContextWindow: e.contextTokenBudget === void 0 ? s ?? e.modelContextWindow : e.modelContextWindow,
tokenBudget: a ?? e.contextTokenBudget ?? s ?? e.authoredContextTokenCap,
...o
};
}
//#endregion
export { runWithContextEngineAssemblyAttempt as a, resolveContextEngineCompletionRuntimeContext as i, readContextEngineAssemblyBudget as n, recordContextEngineAssemblySnapshot as r, clearContextEngineAssemblySnapshot as t };