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,7 +50,6 @@ 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: {
|
||||||
@@ -72,7 +71,6 @@ export function createAnthropicAutoCompactHook(ctx: PluginInput) {
|
|||||||
)
|
)
|
||||||
}, 300)
|
}, 300)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,12 +97,21 @@ 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) {
|
const lastAssistant = await getLastAssistant(sessionID, ctx.client, ctx.directory)
|
||||||
|
|
||||||
|
if (lastAssistant?.summary === true) {
|
||||||
|
autoCompactState.pendingCompact.delete(sessionID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const providerID = errorData?.providerID ?? (lastAssistant?.providerID as string | undefined)
|
||||||
|
const modelID = errorData?.modelID ?? (lastAssistant?.modelID as string | undefined)
|
||||||
|
|
||||||
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,
|
||||||
},
|
},
|
||||||
@@ -113,42 +120,11 @@ export function createAnthropicAutoCompactHook(ctx: PluginInput) {
|
|||||||
|
|
||||||
await executeCompact(
|
await executeCompact(
|
||||||
sessionID,
|
sessionID,
|
||||||
{ providerID: errorData.providerID, modelID: errorData.modelID },
|
{ providerID, modelID },
|
||||||
autoCompactState,
|
autoCompactState,
|
||||||
ctx.client,
|
ctx.client,
|
||||||
ctx.directory
|
ctx.directory
|
||||||
)
|
)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const lastAssistant = await getLastAssistant(sessionID, ctx.client, ctx.directory)
|
|
||||||
if (!lastAssistant) {
|
|
||||||
autoCompactState.pendingCompact.delete(sessionID)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastAssistant.summary === true) {
|
|
||||||
autoCompactState.pendingCompact.delete(sessionID)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lastAssistant.modelID || !lastAssistant.providerID) {
|
|
||||||
autoCompactState.pendingCompact.delete(sessionID)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
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, lastAssistant, autoCompactState, ctx.client, ctx.directory)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user