summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/testing/model-selection.ts
diff options
context:
space:
mode:
authorAdam <[email protected]>2026-03-26 13:41:22 -0500
committerGitHub <[email protected]>2026-03-26 13:41:22 -0500
commitc7760b433b1bdbcaed7e7cd55d53b5b331f0f0fa (patch)
tree4d1a865b8890dc30767b66293923c15e2b3f6d24 /packages/app/src/testing/model-selection.ts
parent2e6ac8ff49eabcb1b62c1bd504338e7449f80c6e (diff)
downloadopencode-c7760b433b1bdbcaed7e7cd55d53b5b331f0f0fa.tar.gz
opencode-c7760b433b1bdbcaed7e7cd55d53b5b331f0f0fa.zip
fix(app): more startup perf (#19288)
Diffstat (limited to 'packages/app/src/testing/model-selection.ts')
-rw-r--r--packages/app/src/testing/model-selection.ts35
1 files changed, 32 insertions, 3 deletions
diff --git a/packages/app/src/testing/model-selection.ts b/packages/app/src/testing/model-selection.ts
index a5ea199ac..d2770fe28 100644
--- a/packages/app/src/testing/model-selection.ts
+++ b/packages/app/src/testing/model-selection.ts
@@ -3,6 +3,14 @@ type ModelKey = {
modelID: string
}
+type ModelItem = ModelKey & {
+ name: string
+}
+
+type AgentItem = {
+ name: string
+}
+
type State = {
agent?: string
model?: ModelKey | null
@@ -26,6 +34,9 @@ export type ModelProbeState = {
pick?: State
base?: State
current?: string
+ variants?: string[]
+ models?: ModelItem[]
+ agents?: AgentItem[]
}
export type ModelWindow = Window & {
@@ -33,6 +44,11 @@ export type ModelWindow = Window & {
model?: {
enabled?: boolean
current?: ModelProbeState
+ controls?: {
+ setAgent?: (name: string | undefined) => void
+ setModel?: (value: ModelKey | undefined) => void
+ setVariant?: (value: string | undefined) => void
+ }
}
}
}
@@ -45,6 +61,8 @@ const clone = (state?: State) => {
}
}
+let active: symbol | undefined
+
export const modelEnabled = () => {
if (typeof window === "undefined") return false
return (window as ModelWindow).__opencode_e2e?.model?.enabled === true
@@ -56,9 +74,15 @@ const root = () => {
}
export const modelProbe = {
- set(input: ModelProbeState) {
+ bind(id: symbol, input: NonNullable<NonNullable<ModelWindow["__opencode_e2e"]>["model"]>["controls"]) {
const state = root()
if (!state) return
+ active = id
+ state.controls = input
+ },
+ set(id: symbol, input: ModelProbeState) {
+ const state = root()
+ if (!state || active !== id) return
state.current = {
...input,
model: input.model ? { ...input.model } : undefined,
@@ -70,11 +94,16 @@ export const modelProbe = {
: undefined,
pick: clone(input.pick),
base: clone(input.base),
+ variants: input.variants?.slice(),
+ models: input.models?.map((item) => ({ ...item })),
+ agents: input.agents?.map((item) => ({ ...item })),
}
},
- clear() {
+ clear(id: symbol) {
const state = root()
- if (!state) return
+ if (!state || active !== id) return
+ active = undefined
state.current = undefined
+ state.controls = undefined
},
}