Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Keep the model picker in sync with runtime default changes (#1669)

Joshua Francea5a36675041a
diff --git a/plugins/web-ui/src/chat.ts b/plugins/web-ui/src/chat.ts
index 1005d9108..c711594d1 100644
--- a/plugins/web-ui/src/chat.ts
+++ b/plugins/web-ui/src/chat.ts
@@ -576,6 +576,7 @@ export function createChatSurface(
if (agent !== chatState.agent) return;
adoptActiveSessionFromList(agent);
await refreshTranscriptFromEntries(agent);
+ void ctx.composer.refreshRuntimeSelection(scopeId, agent, true);
void followNextQueuedRun(agent, threadRef, normalStreamFn, onWork);
if (wasUnsaved && chatState.sessionId) void settleNewSessionTitle(agent, threadRef);
});
diff --git a/plugins/web-ui/src/composer.ts b/plugins/web-ui/src/composer.ts
index 50438abe2..6c99e9394 100644
--- a/plugins/web-ui/src/composer.ts
+++ b/plugins/web-ui/src/composer.ts
@@ -202,6 +202,11 @@ export function createComposerSurface(ctx: ConvCtx, options: ComposerOptions = {
void refreshRuntimeSelection(ctx.chat.state.scopeId, ctx.chat.state.agent ?? undefined, true);
};
window.addEventListener("model-account-changed", refreshAccount);
+ const revalidateRuntime = () => {
+ if (document.visibilityState === "visible")
+ void refreshRuntimeSelection(ctx.chat.state.scopeId, ctx.chat.state.agent ?? undefined, true);
+ };
+ document.addEventListener("visibilitychange", revalidateRuntime);
let runtimeRequest = 0;
let runtimeIdentity = "";
let unsubscribeRuntime: (() => void) | undefined;
@@ -371,6 +376,7 @@ export function createComposerSurface(ctx: ConvCtx, options: ComposerOptions = {
)
) {
restoredLoadout = undefined;
+ followDefault(defaults);
}
defaults = next;
syncRuntimeSelection(ctx.chat.state.agent ?? undefined);
@@ -387,6 +393,18 @@ export function createComposerSurface(ctx: ConvCtx, options: ComposerOptions = {
syncRuntimeSelection(agent);
}
+ function followDefault(previous: { harnessId: string; modelId: string } | undefined): void {
+ const threadRef = ctx.chat.state.threadRef;
+ const pick = threadRef ? threadModelPicks.get(threadRef) : undefined;
+ const picked = pick ? modelOptionFor(pick, scopeKey()) : undefined;
+ if (!threadRef || !previous || !picked) return;
+ if (picked.harnessId !== previous.harnessId || picked.model.id !== previous.modelId) return;
+ forgetThreadPick(threadRef);
+ effortOverride = undefined;
+ fastModeOverride = undefined;
+ loadoutRestored = false;
+ }
+
function restoreLoadoutSelection(): void {
loadout = loadLoadout(loadoutKey);
let selected = currentModelOption();
@@ -1942,6 +1960,7 @@ export function createComposerSurface(ctx: ConvCtx, options: ComposerOptions = {
function dispose(): void {
window.removeEventListener("model-account-changed", refreshAccount);
+ document.removeEventListener("visibilitychange", revalidateRuntime);
modelPicker.dispose();
unsubscribeRuntime?.();
++runtimeRequest;
diff --git a/plugins/web-ui/test/runtime-picker-follow.test.ts b/plugins/web-ui/test/runtime-picker-follow.test.ts
new file mode 100644
index 000000000..8cea38b7a
--- /dev/null
+++ b/plugins/web-ui/test/runtime-picker-follow.test.ts
@@ -0,0 +1,20 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { test } from "node:test";
+
+const composer = readFileSync(new URL("../src/composer.ts", import.meta.url), "utf8");
+const chat = readFileSync(new URL("../src/chat.ts", import.meta.url), "utf8");
+
+test("a thread pick that only mirrored the old default follows a new default", () => {
+ assert.match(composer, /followDefault\(defaults\);\n\s+\}\n\s+defaults = next;/);
+ assert.match(composer, /picked\.model\.id !== previous\.modelId\) return;\n\s+forgetThreadPick\(threadRef\);/);
+});
+
+test("runtime settings revalidate after each turn and when the tab regains focus", () => {
+ assert.match(
+ chat,
+ /refreshTranscriptFromEntries\(agent\);\n\s+void ctx\.composer\.refreshRuntimeSelection\(scopeId, agent, true\);/,
+ );
+ assert.match(composer, /addEventListener\("visibilitychange", revalidateRuntime\)/);
+ assert.match(composer, /removeEventListener\("visibilitychange", revalidateRuntime\)/);
+});