Skip to content

Commit cd64b67

Browse files
authored
feat(tui): show /connect tip when user has no models configured (anomalyco#24014)
1 parent 9af46df commit cd64b67

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

packages/opencode/src/cli/cmd/tui/feature-plugins/home/tips-view.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { For } from "solid-js"
1+
import { createMemo, For } from "solid-js"
22
import { DEFAULT_THEMES, useTheme } from "@tui/context/theme"
33

44
const themeCount = Object.keys(DEFAULT_THEMES).length
@@ -30,17 +30,20 @@ function parse(tip: string): TipPart[] {
3030
return parts
3131
}
3232

33-
export function Tips() {
33+
const NO_MODELS_TIP = "Run {highlight}/connect{/highlight} to add an AI provider and start coding"
34+
35+
export function Tips(props: { connected?: boolean }) {
3436
const theme = useTheme().theme
35-
const parts = parse(TIPS[Math.floor(Math.random() * TIPS.length)])
37+
const randomTip = TIPS[Math.floor(Math.random() * TIPS.length)]
38+
const parts = createMemo(() => parse(props.connected === false ? NO_MODELS_TIP : randomTip))
3639

3740
return (
3841
<box flexDirection="row" maxWidth="100%">
3942
<text flexShrink={0} style={{ fg: theme.warning }}>
4043
● Tip{" "}
4144
</text>
4245
<text flexShrink={1}>
43-
<For each={parts}>
46+
<For each={parts()}>
4447
{(part) => <span style={{ fg: part.highlight ? theme.text : theme.textMuted }}>{part.text}</span>}
4548
</For>
4649
</text>

packages/opencode/src/cli/cmd/tui/feature-plugins/home/tips.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { Tips } from "./tips-view"
44

55
const id = "internal:home-tips"
66

7-
function View(props: { show: boolean }) {
7+
function View(props: { show: boolean; connected: boolean }) {
88
return (
99
<box height={4} minHeight={0} width="100%" maxWidth={75} alignItems="center" paddingTop={3} flexShrink={1}>
1010
<Show when={props.show}>
11-
<Tips />
11+
<Tips connected={props.connected} />
1212
</Show>
1313
</box>
1414
)
@@ -35,8 +35,13 @@ const tui: TuiPlugin = async (api) => {
3535
home_bottom() {
3636
const hidden = createMemo(() => api.kv.get("tips_hidden", false))
3737
const first = createMemo(() => api.state.session.count() === 0)
38-
const show = createMemo(() => !first() && !hidden())
39-
return <View show={show()} />
38+
const connected = createMemo(() =>
39+
api.state.provider.some(
40+
(item) => item.id !== "opencode" || Object.values(item.models).some((model) => model.cost?.input !== 0),
41+
),
42+
)
43+
const show = createMemo(() => (!first() || !connected()) && !hidden())
44+
return <View show={show()} connected={connected()} />
4045
},
4146
},
4247
})

0 commit comments

Comments
 (0)