fix(anthropic-auto-compact): use OpenCode's official compaction mechanism and proper retry
🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -15,9 +15,13 @@ type Client = {
|
|||||||
body: { messageID: string; partID?: string }
|
body: { messageID: string; partID?: string }
|
||||||
query: { directory: string }
|
query: { directory: string }
|
||||||
}) => Promise<unknown>
|
}) => Promise<unknown>
|
||||||
|
prompt_async: (opts: {
|
||||||
|
path: { sessionID: string }
|
||||||
|
body: { parts: Array<{ type: string; text: string }> }
|
||||||
|
query: { directory: string }
|
||||||
|
}) => Promise<unknown>
|
||||||
}
|
}
|
||||||
tui: {
|
tui: {
|
||||||
submitPrompt: (opts: { query: { directory: string } }) => Promise<unknown>
|
|
||||||
showToast: (opts: {
|
showToast: (opts: {
|
||||||
body: { title: string; message: string; variant: string; duration: number }
|
body: { title: string; message: string; variant: string; duration: number }
|
||||||
}) => Promise<unknown>
|
}) => Promise<unknown>
|
||||||
@@ -190,7 +194,11 @@ export async function executeCompact(
|
|||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
await (client as Client).tui.submitPrompt({ query: { directory } })
|
await (client as Client).session.prompt_async({
|
||||||
|
path: { sessionID },
|
||||||
|
body: { parts: [{ type: "text", text: "Continue" }] },
|
||||||
|
query: { directory },
|
||||||
|
})
|
||||||
} catch {}
|
} catch {}
|
||||||
}, 500)
|
}, 500)
|
||||||
return
|
return
|
||||||
@@ -230,7 +238,11 @@ export async function executeCompact(
|
|||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
await (client as Client).tui.submitPrompt({ query: { directory } })
|
await (client as Client).session.prompt_async({
|
||||||
|
path: { sessionID },
|
||||||
|
body: { parts: [{ type: "text", text: "Continue" }] },
|
||||||
|
query: { directory },
|
||||||
|
})
|
||||||
} catch {}
|
} catch {}
|
||||||
}, 500)
|
}, 500)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ interface StoredToolPart {
|
|||||||
input: Record<string, unknown>
|
input: Record<string, unknown>
|
||||||
output?: string
|
output?: string
|
||||||
error?: string
|
error?: string
|
||||||
|
time?: {
|
||||||
|
start: number
|
||||||
|
end?: number
|
||||||
|
compacted?: number
|
||||||
|
}
|
||||||
}
|
}
|
||||||
truncated?: boolean
|
truncated?: boolean
|
||||||
originalSize?: number
|
originalSize?: number
|
||||||
@@ -124,6 +129,11 @@ export function truncateToolResult(partPath: string): {
|
|||||||
part.originalSize = originalSize
|
part.originalSize = originalSize
|
||||||
part.state.output = TRUNCATION_MESSAGE
|
part.state.output = TRUNCATION_MESSAGE
|
||||||
|
|
||||||
|
if (!part.state.time) {
|
||||||
|
part.state.time = { start: Date.now() }
|
||||||
|
}
|
||||||
|
part.state.time.compacted = Date.now()
|
||||||
|
|
||||||
writeFileSync(partPath, JSON.stringify(part, null, 2))
|
writeFileSync(partPath, JSON.stringify(part, null, 2))
|
||||||
|
|
||||||
return { success: true, toolName, originalSize }
|
return { success: true, toolName, originalSize }
|
||||||
|
|||||||
Reference in New Issue
Block a user