Compare commits

...
1 Commits
Author SHA1 Message Date
Aiden Cline eeddfd5e46 fix(tui): use active model for compaction 2026-08-11 03:24:51 +00:00
2 changed files with 67 additions and 0 deletions
+13
View File
@@ -928,6 +928,19 @@ async function runInteractiveRuntime(input: RunRuntimeInput, deps: RunRuntimeDep
},
onAdmissionError: renderPromptError,
onCompact: async () => {
await state.switching?.catch(() => {})
if (state.model)
await state.sdk.session.switchModel(
{
sessionID: state.sessionID,
model: {
providerID: state.model.providerID,
id: state.model.modelID,
variant: state.activeVariant,
},
},
formRequestOptions(state.location),
)
await state.sdk.session.compact({ sessionID: state.sessionID }, formRequestOptions(state.location))
},
settle: async () => {
+54
View File
@@ -5,6 +5,7 @@ import type { LifecycleInput } from "../../src/mini/runtime.lifecycle"
import type { FooterEvent, MiniHost } from "../../src/mini/types"
import { catalogModel, catalogProvider, stubCatalogLists } from "./fixture/catalog"
import { createFooterApiFixture } from "./fixture/footer-api"
import { createApi, createFetch, json } from "../fixture/tui-client"
function defer<T>() {
let resolve!: (value: T | PromiseLike<T>) => void
@@ -164,6 +165,59 @@ describe("run interactive runtime", () => {
await task
})
test("switches to the active model and variant before compacting", async () => {
const ui = createFooterApiFixture()
const requests: Array<{ path: string; body: unknown }> = []
const client = createFetch(async (url, request) => {
if (!url.pathname.startsWith("/api/session/ses_root/")) return
requests.push({ path: url.pathname, body: await request.json() })
if (url.pathname.endsWith("/model")) return new Response(null, { status: 204 })
ui.api.close()
return json({
data: { id: "msg_compact", sessionID: "ses_root", timeCreated: 1, type: "compaction" },
})
})
await runInteractiveDeferredMode(
{
host: host(),
sdk: createApi(client.fetch),
directory: "/tmp",
target: async () => ({
sessionID: "ses_root",
location: { directory: "/tmp", project: { id: "pro-1", directory: "/tmp", canonical: "/tmp" } },
agent: "build",
model: { providerID: "test", modelID: "selected" },
variant: "high",
resume: false,
}),
agent: "build",
model: { providerID: "test", modelID: "selected" },
variant: "high",
files: [],
initialInput: "/compact",
},
{
createRuntimeLifecycle: async () => ({
footer: ui.api,
onResize: () => () => {},
refreshTheme: () => {},
setTitle: () => {},
resetForReplay: async () => {},
close: async () => {},
}),
},
)
expect(requests).toEqual([
{
path: "/api/session/ses_root/model",
body: { model: { providerID: "test", id: "selected", variant: "high" } },
},
{ path: "/api/session/ses_root/compact", body: {} },
])
})
test("routes form responses to their owners with global location and local settlement", async () => {
const sdk = OpenCode.make({ baseUrl: "https://opencode.test" })
const api = footer()