mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-08 01:39:12 +00:00
fix(app): model selection persist by session (#17348)
This commit is contained in:
80
packages/app/src/testing/model-selection.ts
Normal file
80
packages/app/src/testing/model-selection.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
type ModelKey = {
|
||||
providerID: string
|
||||
modelID: string
|
||||
}
|
||||
|
||||
type State = {
|
||||
agent?: string
|
||||
model?: ModelKey | null
|
||||
variant?: string | null
|
||||
}
|
||||
|
||||
export type ModelProbeState = {
|
||||
dir?: string
|
||||
sessionID?: string
|
||||
last?: {
|
||||
type: "agent" | "model" | "variant"
|
||||
agent?: string
|
||||
model?: ModelKey | null
|
||||
variant?: string | null
|
||||
}
|
||||
agent?: string
|
||||
model?: (ModelKey & { name?: string }) | undefined
|
||||
variant?: string | null
|
||||
selected?: string | null
|
||||
configured?: string
|
||||
pick?: State
|
||||
base?: State
|
||||
current?: string
|
||||
}
|
||||
|
||||
export type ModelWindow = Window & {
|
||||
__opencode_e2e?: {
|
||||
model?: {
|
||||
enabled?: boolean
|
||||
current?: ModelProbeState
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const clone = (state?: State) => {
|
||||
if (!state) return undefined
|
||||
return {
|
||||
...state,
|
||||
model: state.model ? { ...state.model } : state.model,
|
||||
}
|
||||
}
|
||||
|
||||
export const modelEnabled = () => {
|
||||
if (typeof window === "undefined") return false
|
||||
return (window as ModelWindow).__opencode_e2e?.model?.enabled === true
|
||||
}
|
||||
|
||||
const root = () => {
|
||||
if (!modelEnabled()) return
|
||||
return (window as ModelWindow).__opencode_e2e?.model
|
||||
}
|
||||
|
||||
export const modelProbe = {
|
||||
set(input: ModelProbeState) {
|
||||
const state = root()
|
||||
if (!state) return
|
||||
state.current = {
|
||||
...input,
|
||||
model: input.model ? { ...input.model } : undefined,
|
||||
last: input.last
|
||||
? {
|
||||
...input.last,
|
||||
model: input.last.model ? { ...input.last.model } : input.last.model,
|
||||
}
|
||||
: undefined,
|
||||
pick: clone(input.pick),
|
||||
base: clone(input.base),
|
||||
}
|
||||
},
|
||||
clear() {
|
||||
const state = root()
|
||||
if (!state) return
|
||||
state.current = undefined
|
||||
},
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { ModelProbeState } from "./model-selection"
|
||||
|
||||
export const terminalAttr = "data-pty-id"
|
||||
|
||||
export type TerminalProbeState = {
|
||||
@@ -13,6 +15,10 @@ type TerminalProbeControl = {
|
||||
|
||||
export type E2EWindow = Window & {
|
||||
__opencode_e2e?: {
|
||||
model?: {
|
||||
enabled?: boolean
|
||||
current?: ModelProbeState
|
||||
}
|
||||
terminal?: {
|
||||
enabled?: boolean
|
||||
terminals?: Record<string, TerminalProbeState>
|
||||
|
||||
Reference in New Issue
Block a user