GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(app): persist per-agent model selections across agent switches · kagura-chen/opencode@e54b762

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/app/src/context
    • local.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/src/context/local.tsx‎

Copy file name to clipboardExpand all lines: packages/app/src/context/local.tsx
+24-2Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type State = {
1616
agent?: string
1717
model?: ModelKey
1818
variant?: string | null
19+
agents?: Record<string, { model?: ModelKey; variant?: string | null }>
1920
}
2021

2122
type Saved = {
@@ -48,6 +49,11 @@ const clone = (value: State | undefined) => {
4849
return {
4950
...value,
5051
model: value.model ? { ...value.model } : undefined,
52+
agents: value.agents
53+
? Object.fromEntries(
54+
Object.entries(value.agents).map(([k, v]) => [k, { ...v, model: v.model ? { ...v.model } : undefined }]),
55+
)
56+
: undefined,
5157
} satisfies State
5258
}
5359

@@ -192,10 +198,21 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
192198
variant: item.variant ?? null,
193199
})
194200
const prev = scope()
201+
const prevAgent = prev?.agent
202+
203+
// Save outgoing agent's model selection
204+
const agents = { ...(prev?.agents ?? {}) }
205+
if (prevAgent && prev?.model) {
206+
agents[prevAgent] = { model: prev.model, variant: prev.variant }
207+
}
208+
209+
// Restore saved model for the target agent, or fall back to agent config / previous
210+
const savedAgent = agents[item.name]
195211
const next = {
196212
agent: item.name,
197-
model: item.model ?? prev?.model,
198-
variant: item.variant ?? prev?.variant,
213+
model: savedAgent?.model ?? item.model ?? prev?.model,
214+
variant: savedAgent?.variant ?? item.variant ?? prev?.variant,
215+
agents,
199216
} satisfies State
200217
const session = id()
201218
if (session) {
@@ -245,10 +262,12 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
245262

246263
const snapshot = () => {
247264
const model = current()
265+
const s = scope()
248266
return {
249267
agent: agent.current()?.name,
250268
model: model ? { providerID: model.provider.id, modelID: model.id } : undefined,
251269
variant: selected(),
270+
agents: s?.agents,
252271
} satisfies State
253272
}
254273

@@ -383,6 +402,9 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
383402
agent: msg.agent,
384403
model: msg.model,
385404
variant: msg.model.variant ?? null,
405+
agents: {
406+
[msg.agent]: { model: msg.model, variant: msg.model.variant ?? null },
407+
},
386408
})
387409
},
388410
},

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.