feat(preemptive-compaction): apply compaction model override from agent config
This commit is contained in:
parent
09314dba1a
commit
2d069ce4cc
@ -269,7 +269,7 @@ describe("preemptive-compaction", () => {
|
|||||||
|
|
||||||
it("should use 1M limit when model cache flag is enabled", async () => {
|
it("should use 1M limit when model cache flag is enabled", async () => {
|
||||||
//#given
|
//#given
|
||||||
const hook = createPreemptiveCompactionHook(ctx as never, {
|
const hook = createPreemptiveCompactionHook(ctx as never, {}, {
|
||||||
anthropicContext1MEnabled: true,
|
anthropicContext1MEnabled: true,
|
||||||
})
|
})
|
||||||
const sessionID = "ses_1m_flag"
|
const sessionID = "ses_1m_flag"
|
||||||
@ -308,7 +308,7 @@ describe("preemptive-compaction", () => {
|
|||||||
it("should keep env var fallback when model cache flag is disabled", async () => {
|
it("should keep env var fallback when model cache flag is disabled", async () => {
|
||||||
//#given
|
//#given
|
||||||
process.env[ANTHROPIC_CONTEXT_ENV_KEY] = "true"
|
process.env[ANTHROPIC_CONTEXT_ENV_KEY] = "true"
|
||||||
const hook = createPreemptiveCompactionHook(ctx as never, {
|
const hook = createPreemptiveCompactionHook(ctx as never, {}, {
|
||||||
anthropicContext1MEnabled: false,
|
anthropicContext1MEnabled: false,
|
||||||
})
|
})
|
||||||
const sessionID = "ses_env_fallback"
|
const sessionID = "ses_env_fallback"
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import { log } from "../shared/logger"
|
import { log } from "../shared/logger"
|
||||||
|
import type { OhMyOpenCodeConfig } from "../config"
|
||||||
|
|
||||||
|
import { resolveCompactionModel } from "./shared/compaction-model-resolver"
|
||||||
const DEFAULT_ACTUAL_LIMIT = 200_000
|
const DEFAULT_ACTUAL_LIMIT = 200_000
|
||||||
|
|
||||||
type ModelCacheStateLike = {
|
type ModelCacheStateLike = {
|
||||||
@ -51,6 +53,7 @@ type PluginInput = {
|
|||||||
|
|
||||||
export function createPreemptiveCompactionHook(
|
export function createPreemptiveCompactionHook(
|
||||||
ctx: PluginInput,
|
ctx: PluginInput,
|
||||||
|
pluginConfig: OhMyOpenCodeConfig,
|
||||||
modelCacheState?: ModelCacheStateLike,
|
modelCacheState?: ModelCacheStateLike,
|
||||||
) {
|
) {
|
||||||
const compactionInProgress = new Set<string>()
|
const compactionInProgress = new Set<string>()
|
||||||
@ -84,9 +87,16 @@ export function createPreemptiveCompactionHook(
|
|||||||
compactionInProgress.add(sessionID)
|
compactionInProgress.add(sessionID)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const { providerID: targetProviderID, modelID: targetModelID } = resolveCompactionModel(
|
||||||
|
pluginConfig,
|
||||||
|
sessionID,
|
||||||
|
cached.providerID,
|
||||||
|
modelID
|
||||||
|
)
|
||||||
|
|
||||||
await ctx.client.session.summarize({
|
await ctx.client.session.summarize({
|
||||||
path: { id: sessionID },
|
path: { id: sessionID },
|
||||||
body: { providerID: cached.providerID, modelID, auto: true } as never,
|
body: { providerID: targetProviderID, modelID: targetModelID, auto: true } as never,
|
||||||
query: { directory: ctx.directory },
|
query: { directory: ctx.directory },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user