Download packages/app/src/pages/session/session-model-helpers.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/pages/session/session-model-helpers.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/app/src/pages/session/session-model-helpers.ts
-
curl -L -o session-model-helpers.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/pages/session/session-model-helpers.ts
1.8 kB
| import type { UserMessage } from "@opencode-ai/sdk/v2" | |
| type Local = { | |
| session: { | |
| reset(): void | |
| restore(msg: UserMessage): void | |
| } | |
| } | |
| type ModelSelection = { | |
| model: { | |
| current(): { id: string; provider: { id: string } } | undefined | |
| set(model: { providerID: string; modelID: string }): void | |
| variant: { | |
| current(): string | undefined | |
| set(variant: string | undefined): void | |
| } | |
| } | |
| } | |
| type PromptState = { | |
| model: { | |
| current(): { providerID: string; modelID: string; variant?: string | null } | undefined | |
| set(model: { providerID: string; modelID: string; variant?: string | null }): void | |
| } | |
| } | |
| export const resetSessionModel = (local: Local) => { | |
| local.session.reset() | |
| } | |
| export const syncSessionModel = (local: Local, msg: UserMessage) => { | |
| local.session.restore(msg) | |
| } | |
| export const syncPromptModel = (local: ModelSelection, prompt: PromptState) => { | |
| const model = local.model.current() | |
| if (!model) return | |
| const next = { | |
| providerID: model.provider.id, | |
| modelID: model.id, | |
| variant: local.model.variant.current(), | |
| } | |
| const current = prompt.model.current() | |
| if (current?.providerID === next.providerID && current.modelID === next.modelID && current.variant === next.variant) | |
| return | |
| prompt.model.set(next) | |
| } | |
| export const restorePromptModel = (local: ModelSelection, prompt: PromptState) => { | |
| const model = prompt.model.current() | |
| if (!model) return false | |
| const current = local.model.current() | |
| if ( | |
| current?.provider.id === model.providerID && | |
| current.id === model.modelID && | |
| local.model.variant.current() === (model.variant ?? undefined) | |
| ) | |
| return true | |
| local.model.set({ providerID: model.providerID, modelID: model.modelID }) | |
| local.model.variant.set(model.variant ?? undefined) | |
| return true | |
| } | |