mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 07:50:22 +00:00
fix(repo): restore gate after upstream drift
This commit is contained in:
@@ -208,6 +208,22 @@ export function isOversizedForSummary(msg: AgentMessage, contextWindow: number):
|
||||
return tokens > contextWindow * 0.5;
|
||||
}
|
||||
|
||||
function withSummaryHeaders(
|
||||
model: NonNullable<ExtensionContext["model"]>,
|
||||
headers?: Record<string, string>,
|
||||
): NonNullable<ExtensionContext["model"]> {
|
||||
if (!headers || Object.keys(headers).length === 0) {
|
||||
return model;
|
||||
}
|
||||
return {
|
||||
...model,
|
||||
headers: {
|
||||
...model.headers,
|
||||
...headers,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function summarizeChunks(params: {
|
||||
messages: AgentMessage[];
|
||||
model: NonNullable<ExtensionContext["model"]>;
|
||||
@@ -231,12 +247,13 @@ async function summarizeChunks(params: {
|
||||
params.customInstructions,
|
||||
params.summarizationInstructions,
|
||||
);
|
||||
const model = withSummaryHeaders(params.model, params.headers);
|
||||
for (const chunk of chunks) {
|
||||
summary = await retryAsync(
|
||||
() =>
|
||||
generateSummary(
|
||||
chunk,
|
||||
params.model,
|
||||
model,
|
||||
params.reserveTokens,
|
||||
params.apiKey,
|
||||
params.signal,
|
||||
|
||||
@@ -614,8 +614,12 @@ export default function compactionSafeguardExtension(api: ExtensionAPI): void {
|
||||
return { cancel: true };
|
||||
}
|
||||
|
||||
const apiKey = await ctx.modelRegistry.getApiKey(model);
|
||||
if (!apiKey) {
|
||||
const apiKey = (await ctx.modelRegistry.getApiKey(model)) ?? "";
|
||||
const headers =
|
||||
model.headers && typeof model.headers === "object" && !Array.isArray(model.headers)
|
||||
? model.headers
|
||||
: undefined;
|
||||
if (!apiKey && !headers) {
|
||||
log.warn(
|
||||
"Compaction safeguard: no request auth available; cancelling compaction to preserve history.",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user