fix(anthropic-auto-compact): ensure executeCompact always runs for truncation/revert regardless of model info
🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -50,28 +50,26 @@ export function createAnthropicAutoCompactHook(ctx: PluginInput) {
|
|||||||
const providerID = parsed.providerID ?? (lastAssistant?.providerID as string | undefined)
|
const providerID = parsed.providerID ?? (lastAssistant?.providerID as string | undefined)
|
||||||
const modelID = parsed.modelID ?? (lastAssistant?.modelID as string | undefined)
|
const modelID = parsed.modelID ?? (lastAssistant?.modelID as string | undefined)
|
||||||
|
|
||||||
if (providerID && modelID) {
|
await ctx.client.tui
|
||||||
await ctx.client.tui
|
.showToast({
|
||||||
.showToast({
|
body: {
|
||||||
body: {
|
title: "Context Limit Hit",
|
||||||
title: "Context Limit Hit",
|
message: "Truncating large tool outputs and recovering...",
|
||||||
message: "Truncating large tool outputs and recovering...",
|
variant: "warning" as const,
|
||||||
variant: "warning" as const,
|
duration: 3000,
|
||||||
duration: 3000,
|
},
|
||||||
},
|
})
|
||||||
})
|
.catch(() => {})
|
||||||
.catch(() => {})
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
executeCompact(
|
executeCompact(
|
||||||
sessionID,
|
sessionID,
|
||||||
{ providerID, modelID },
|
{ providerID, modelID },
|
||||||
autoCompactState,
|
autoCompactState,
|
||||||
ctx.client,
|
ctx.client,
|
||||||
ctx.directory
|
ctx.directory
|
||||||
)
|
)
|
||||||
}, 300)
|
}, 300)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -99,56 +97,34 @@ export function createAnthropicAutoCompactHook(ctx: PluginInput) {
|
|||||||
if (!autoCompactState.pendingCompact.has(sessionID)) return
|
if (!autoCompactState.pendingCompact.has(sessionID)) return
|
||||||
|
|
||||||
const errorData = autoCompactState.errorDataBySession.get(sessionID)
|
const errorData = autoCompactState.errorDataBySession.get(sessionID)
|
||||||
if (errorData?.providerID && errorData?.modelID) {
|
|
||||||
await ctx.client.tui
|
|
||||||
.showToast({
|
|
||||||
body: {
|
|
||||||
title: "Auto Compact",
|
|
||||||
message: "Token limit exceeded. Summarizing session...",
|
|
||||||
variant: "warning" as const,
|
|
||||||
duration: 3000,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.catch(() => {})
|
|
||||||
|
|
||||||
await executeCompact(
|
|
||||||
sessionID,
|
|
||||||
{ providerID: errorData.providerID, modelID: errorData.modelID },
|
|
||||||
autoCompactState,
|
|
||||||
ctx.client,
|
|
||||||
ctx.directory
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const lastAssistant = await getLastAssistant(sessionID, ctx.client, ctx.directory)
|
const lastAssistant = await getLastAssistant(sessionID, ctx.client, ctx.directory)
|
||||||
if (!lastAssistant) {
|
|
||||||
|
if (lastAssistant?.summary === true) {
|
||||||
autoCompactState.pendingCompact.delete(sessionID)
|
autoCompactState.pendingCompact.delete(sessionID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastAssistant.summary === true) {
|
const providerID = errorData?.providerID ?? (lastAssistant?.providerID as string | undefined)
|
||||||
autoCompactState.pendingCompact.delete(sessionID)
|
const modelID = errorData?.modelID ?? (lastAssistant?.modelID as string | undefined)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lastAssistant.modelID || !lastAssistant.providerID) {
|
|
||||||
autoCompactState.pendingCompact.delete(sessionID)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await ctx.client.tui
|
await ctx.client.tui
|
||||||
.showToast({
|
.showToast({
|
||||||
body: {
|
body: {
|
||||||
title: "Auto Compact",
|
title: "Auto Compact",
|
||||||
message: "Token limit exceeded. Summarizing session...",
|
message: "Token limit exceeded. Attempting recovery...",
|
||||||
variant: "warning" as const,
|
variant: "warning" as const,
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
|
|
||||||
await executeCompact(sessionID, lastAssistant, autoCompactState, ctx.client, ctx.directory)
|
await executeCompact(
|
||||||
|
sessionID,
|
||||||
|
{ providerID, modelID },
|
||||||
|
autoCompactState,
|
||||||
|
ctx.client,
|
||||||
|
ctx.directory
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user