Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function DialogAgent() {
return (
<DialogSelect
title="Select agent"
current={local.agent.current().name}
current={local.agent.current()?.name ?? "default"}
options={options()}
onSelect={(option) => {
local.agent.set(option.value)
Expand Down
36 changes: 18 additions & 18 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ export function Prompt(props: PromptProps) {
const sessionID = props.sessionID
? props.sessionID
: await (async () => {
const sessionID = await sdk.client.session.create({}).then((x) => x.data!.id)
return sessionID
})()
const sessionID = await sdk.client.session.create({}).then((x) => x.data!.id)
return sessionID
})()
const messageID = Identifier.ascending("message")
let inputText = store.prompt.input

Expand Down Expand Up @@ -530,7 +530,7 @@ export function Prompt(props: PromptProps) {
if (store.mode === "shell") {
sdk.client.session.shell({
sessionID,
agent: local.agent.current().name,
agent: local.agent.current()?.name ?? "default",
model: {
providerID: selectedModel.providerID,
modelID: selectedModel.modelID,
Expand All @@ -551,7 +551,7 @@ export function Prompt(props: PromptProps) {
sessionID,
command: command.slice(1),
arguments: args.join(" "),
agent: local.agent.current().name,
agent: local.agent.current()?.name ?? "default",
model: `${selectedModel.providerID}/${selectedModel.modelID}`,
messageID,
variant,
Expand All @@ -567,7 +567,7 @@ export function Prompt(props: PromptProps) {
sessionID,
...selectedModel,
messageID,
agent: local.agent.current().name,
agent: local.agent.current()?.name ?? "default",
model: selectedModel,
variant,
parts: [
Expand Down Expand Up @@ -687,7 +687,7 @@ export function Prompt(props: PromptProps) {
const highlight = createMemo(() => {
if (keybind.leader) return theme.border
if (store.mode === "shell") return theme.primary
return local.agent.color(local.agent.current().name)
return local.agent.color(local.agent.current()?.name ?? "default")
})

const showVariant = createMemo(() => {
Expand All @@ -698,7 +698,7 @@ export function Prompt(props: PromptProps) {
})

const spinnerDef = createMemo(() => {
const color = local.agent.color(local.agent.current().name)
const color = local.agent.color(local.agent.current()?.name ?? "default")
return {
frames: createFrames({
color,
Expand Down Expand Up @@ -875,7 +875,7 @@ export function Prompt(props: PromptProps) {
// Handle SVG as raw text content, not as base64 image
if (file.type === "image/svg+xml") {
event.preventDefault()
const content = await file.text().catch(() => {})
const content = await file.text().catch(() => { })
if (content) {
pasteText(content, `[SVG: ${file.name ?? "image"}]`)
return
Expand All @@ -886,7 +886,7 @@ export function Prompt(props: PromptProps) {
const content = await file
.arrayBuffer()
.then((buffer) => Buffer.from(buffer).toString("base64"))
.catch(() => {})
.catch(() => { })
if (content) {
await pasteImage({
filename: file.name,
Expand All @@ -896,7 +896,7 @@ export function Prompt(props: PromptProps) {
return
}
}
} catch {}
} catch { }
}

const lineCount = (pastedContent.match(/\n/g)?.length ?? 0) + 1
Expand Down Expand Up @@ -932,7 +932,7 @@ export function Prompt(props: PromptProps) {
/>
<box flexDirection="row" flexShrink={0} paddingTop={1} gap={1}>
<text fg={highlight()}>
{store.mode === "shell" ? "Shell" : Locale.titlecase(local.agent.current().name)}{" "}
{store.mode === "shell" ? "Shell" : Locale.titlecase(local.agent.current()?.name ?? "default")}{" "}
</text>
<Show when={store.mode === "normal"}>
<box flexDirection="row" gap={1}>
Expand Down Expand Up @@ -967,13 +967,13 @@ export function Prompt(props: PromptProps) {
customBorderChars={
theme.backgroundElement.a !== 0
? {
...EmptyBorder,
horizontal: "▀",
}
...EmptyBorder,
horizontal: "▀",
}
: {
...EmptyBorder,
horizontal: " ",
}
...EmptyBorder,
horizontal: " ",
}
}
/>
</box>
Expand Down
20 changes: 12 additions & 8 deletions packages/opencode/src/cli/cmd/tui/context/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
const [agentStore, setAgentStore] = createStore<{
current: string
}>({
current: agents()[0].name,
current: agents()[0]?.name ?? "default",
})
const { theme } = useTheme()
const colors = createMemo(() => [
Expand All @@ -54,7 +54,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
return agents()
},
current() {
return agents().find((x) => x.name === agentStore.current)!
return agents().find((x) => x.name === agentStore.current)
},
set(name: string) {
if (!agents().some((x) => x.name === name))
Expand Down Expand Up @@ -132,7 +132,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
if (Array.isArray(x.favorite)) setModelStore("favorite", x.favorite)
if (typeof x.variant === "object" && x.variant !== null) setModelStore("variant", x.variant)
})
.catch(() => {})
.catch(() => { })
.finally(() => {
setModelStore("ready", true)
})
Expand Down Expand Up @@ -181,8 +181,8 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
const a = agent.current()
return (
getFirstValidModel(
() => modelStore.model[a.name],
() => a.model,
() => a ? modelStore.model[a.name] : undefined,
() => a?.model,
fallbackModel,
) ?? undefined
)
Expand Down Expand Up @@ -227,7 +227,8 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
if (next >= recent.length) next = 0
const val = recent[next]
if (!val) return
setModelStore("model", agent.current().name, { ...val })
const currentAgent = agent.current()
if (currentAgent) setModelStore("model", currentAgent.name, { ...val })
},
cycleFavorite(direction: 1 | -1) {
const favorites = modelStore.favorite.filter((item) => isModelValid(item))
Expand All @@ -253,7 +254,8 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
}
const next = favorites[index]
if (!next) return
setModelStore("model", agent.current().name, { ...next })
const currentAgent = agent.current()
if (currentAgent) setModelStore("model", currentAgent.name, { ...next })
const uniq = uniqueBy([next, ...modelStore.recent], (x) => `${x.providerID}/${x.modelID}`)
if (uniq.length > 10) uniq.pop()
setModelStore(
Expand All @@ -272,7 +274,8 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
})
return
}
setModelStore("model", agent.current().name, model)
const currentAgent = agent.current()
if (currentAgent) setModelStore("model", currentAgent.name, model)
if (options?.recent) {
const uniq = uniqueBy([model, ...modelStore.recent], (x) => `${x.providerID}/${x.modelID}`)
if (uniq.length > 10) uniq.pop()
Expand Down Expand Up @@ -368,6 +371,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
// Automatically update model when agent changes
createEffect(() => {
const value = agent.current()
if (!value) return
if (value.model) {
if (isModelValid(value.model))
model.set({
Expand Down