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 — tui: go plan payg msg (#26248) · anotheroni/opencode@f5d0371

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • opencode
      • src
        • cli/cmd/tui
          • component
            • dialog-retry-action.tsx
          • routes/session
            • index.tsx
          • ui
            • link.tsx
        • session
          • processor.ts
          • retry.ts
          • status.ts
      • test/session
        • retry.test.ts
        • schema-decoding.test.ts
    • sdk/js/src/v2/gen
      • types.gen.ts
  • script
    • zen-limit-server.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎…i/cmd/tui/component/dialog-go-upsell.tsx‎ ‎…md/tui/component/dialog-retry-action.tsx‎packages/opencode/src/cli/cmd/tui/component/dialog-go-upsell.tsx renamed to packages/opencode/src/cli/cmd/tui/component/dialog-retry-action.tsx packages/opencode/src/cli/cmd/tui/component/dialog-go-upsell.tsx renamed to packages/opencode/src/cli/cmd/tui/component/dialog-retry-action.tsx

Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/component/dialog-retry-action.tsx
+52-42Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,50 @@ import { GoLogo } from "./logo"
88
import { BgPulse, type BgPulseMask } from "./bg-pulse"
99
import { useBindings } from "../keymap"
1010

11-
const GO_URL = "https://opencode.ai/go"
1211
const PAD_X = 3
1312
const PAD_TOP_OUTER = 1
1413

15-
export type DialogGoUpsellProps = {
14+
export type DialogRetryActionProps = {
15+
title: string
16+
message: string
17+
label: string
18+
link?: string
1619
onClose?: (dontShowAgain?: boolean) => void
1720
}
1821

19-
function subscribe(props: DialogGoUpsellProps, dialog: ReturnType<typeof useDialog>) {
20-
open(GO_URL).catch(() => {})
22+
function runAction(props: DialogRetryActionProps, dialog: ReturnType<typeof useDialog>) {
23+
if (props.link) open(props.link).catch(() => {})
2124
props.onClose?.()
2225
dialog.clear()
2326
}
2427

25-
function dismiss(props: DialogGoUpsellProps, dialog: ReturnType<typeof useDialog>) {
28+
function dismiss(props: DialogRetryActionProps, dialog: ReturnType<typeof useDialog>) {
2629
props.onClose?.(true)
2730
dialog.clear()
2831
}
2932

30-
export function DialogGoUpsell(props: DialogGoUpsellProps) {
33+
export function DialogRetryAction(props: DialogRetryActionProps) {
3134
const dialog = useDialog()
3235
const { theme } = useTheme()
3336
const fg = selectedForeground(theme)
34-
const [selected, setSelected] = createSignal<"dismiss" | "subscribe">("subscribe")
37+
const [selected, setSelected] = createSignal<"dismiss" | "action">("action")
3538
const [center, setCenter] = createSignal<{ x: number; y: number } | undefined>()
3639
const [masks, setMasks] = createSignal<BgPulseMask[]>([])
40+
const showGoTreatment = () => props.link === "https://opencode.ai/go"
3741
let content: BoxRenderable | undefined
3842
let logoBox: BoxRenderable | undefined
3943
let headingBox: BoxRenderable | undefined
4044
let descBox: BoxRenderable | undefined
4145
let buttonsBox: BoxRenderable | undefined
4246

4347
const sync = () => {
44-
if (!content || !logoBox) return
45-
setCenter({
46-
x: logoBox.x - content.x + logoBox.width / 2,
47-
y: logoBox.y - content.y + logoBox.height / 2 + PAD_TOP_OUTER,
48-
})
48+
if (!content) return
49+
if (logoBox) {
50+
setCenter({
51+
x: logoBox.x - content.x + logoBox.width / 2,
52+
y: logoBox.y - content.y + logoBox.height / 2 + PAD_TOP_OUTER,
53+
})
54+
}
4955
const next: BgPulseMask[] = []
5056
const baseY = PAD_TOP_OUTER
5157
for (const b of [headingBox, descBox, buttonsBox]) {
@@ -75,20 +81,20 @@ export function DialogGoUpsell(props: DialogGoUpsellProps) {
7581
bindings: [
7682
{
7783
key: "left",
78-
cmd: () => setSelected((value) => (value === "subscribe" ? "dismiss" : "subscribe")),
84+
cmd: () => setSelected((value) => (value === "action" ? "dismiss" : "action")),
7985
},
8086
{
8187
key: "right",
82-
cmd: () => setSelected((value) => (value === "subscribe" ? "dismiss" : "subscribe")),
88+
cmd: () => setSelected((value) => (value === "action" ? "dismiss" : "action")),
8389
},
8490
{
8591
key: "tab",
86-
cmd: () => setSelected((value) => (value === "subscribe" ? "dismiss" : "subscribe")),
92+
cmd: () => setSelected((value) => (value === "action" ? "dismiss" : "action")),
8793
},
8894
{
8995
key: "return",
9096
cmd: () => {
91-
if (selected() === "subscribe") subscribe(props, dialog)
97+
if (selected() === "action") runAction(props, dialog)
9298
else dismiss(props, dialog)
9399
},
94100
},
@@ -97,33 +103,34 @@ export function DialogGoUpsell(props: DialogGoUpsellProps) {
97103

98104
return (
99105
<box ref={(item: BoxRenderable) => (content = item)}>
100-
<box position="absolute" top={-PAD_TOP_OUTER} left={0} right={0} bottom={0} zIndex={0}>
101-
<BgPulse centerX={center()?.x} centerY={center()?.y} masks={masks()} />
102-
</box>
103-
<box paddingLeft={PAD_X} paddingRight={PAD_X} paddingBottom={1} gap={1}>
106+
{showGoTreatment() ? (
107+
<box position="absolute" top={-PAD_TOP_OUTER} left={0} right={0} bottom={0} zIndex={0}>
108+
<BgPulse centerX={center()?.x} centerY={center()?.y} masks={masks()} />
109+
</box>
110+
) : null}
111+
<box paddingLeft={PAD_X} paddingRight={PAD_X} paddingBottom={1} gap={1} zIndex={1}>
104112
<box ref={(item: BoxRenderable) => (headingBox = item)} flexDirection="row" justifyContent="space-between">
105113
<text attributes={TextAttributes.BOLD} fg={theme.text}>
106-
Free limit reached
114+
{props.title}
107115
</text>
108116
<text fg={theme.textMuted} onMouseUp={() => dialog.clear()}>
109117
esc
110118
</text>
111119
</box>
112120
<box ref={(item: BoxRenderable) => (descBox = item)} gap={0}>
113-
<box flexDirection="row">
114-
<text fg={theme.textMuted}>Subscribe to </text>
115-
<text attributes={TextAttributes.BOLD} fg={theme.textMuted}>
116-
OpenCode Go
117-
</text>
118-
<text fg={theme.textMuted}> for reliable access to the</text>
119-
</box>
120-
<text fg={theme.textMuted}>best open-source models, starting at $5/month.</text>
121+
<text fg={theme.textMuted}>{props.message}</text>
121122
</box>
122-
<box alignItems="center" gap={1} paddingBottom={1}>
123-
<box ref={(item: BoxRenderable) => (logoBox = item)}>
124-
<GoLogo />
125-
</box>
126-
<Link href={GO_URL} fg={theme.primary} />
123+
<box gap={1} paddingBottom={1}>
124+
{showGoTreatment() ? (
125+
<box ref={(item: BoxRenderable) => (logoBox = item)} alignItems="center">
126+
<GoLogo />
127+
</box>
128+
) : null}
129+
{props.link ? (
130+
<box width="100%" flexDirection="row" justifyContent="center">
131+
<Link href={props.link} fg={theme.primary} wrapMode="none" />
132+
</box>
133+
) : null}
127134
</box>
128135
<box ref={(item: BoxRenderable) => (buttonsBox = item)} flexDirection="row" justifyContent="space-between">
129136
<box
@@ -143,15 +150,15 @@ export function DialogGoUpsell(props: DialogGoUpsellProps) {
143150
<box
144151
paddingLeft={2}
145152
paddingRight={2}
146-
backgroundColor={selected() === "subscribe" ? theme.primary : RGBA.fromInts(0, 0, 0, 0)}
147-
onMouseOver={() => setSelected("subscribe")}
148-
onMouseUp={() => subscribe(props, dialog)}
153+
backgroundColor={selected() === "action" ? theme.primary : RGBA.fromInts(0, 0, 0, 0)}
154+
onMouseOver={() => setSelected("action")}
155+
onMouseUp={() => runAction(props, dialog)}
149156
>
150157
<text
151-
fg={selected() === "subscribe" ? fg : theme.text}
152-
attributes={selected() === "subscribe" ? TextAttributes.BOLD : undefined}
158+
fg={selected() === "action" ? fg : theme.text}
159+
attributes={selected() === "action" ? TextAttributes.BOLD : undefined}
153160
>
154-
subscribe
161+
{props.label}
155162
</text>
156163
</box>
157164
</box>
@@ -160,10 +167,13 @@ export function DialogGoUpsell(props: DialogGoUpsellProps) {
160167
)
161168
}
162169

163-
DialogGoUpsell.show = (dialog: DialogContext) => {
170+
DialogRetryAction.show = (
171+
dialog: DialogContext,
172+
props: Pick<DialogRetryActionProps, "title" | "message" | "label" | "link">,
173+
) => {
164174
return new Promise<boolean>((resolve) => {
165175
dialog.replace(
166-
() => <DialogGoUpsell onClose={(dontShow) => resolve(dontShow ?? false)} />,
176+
() => <DialogRetryAction {...props} onClose={(dontShow) => resolve(dontShow ?? false)} />,
167177
() => resolve(false),
168178
)
169179
})
Collapse file

‎packages/opencode/src/cli/cmd/tui/routes/session/index.tsx‎

Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ import { UI } from "@/cli/ui.ts"
8585
import { useTuiConfig } from "../../context/tui-config"
8686
import { getScrollAcceleration } from "../../util/scroll"
8787
import { TuiPluginRuntime } from "@/cli/cmd/tui/plugin/runtime"
88-
import { DialogGoUpsell } from "../../component/dialog-go-upsell"
88+
import { DialogRetryAction } from "../../component/dialog-retry-action"
8989
import { SessionRetry } from "@/session/retry"
9090
import { getRevertDiffFiles } from "../../util/revert-diff"
9191
import { useCommandPalette } from "../../context/command-palette"
@@ -260,15 +260,15 @@ export function Session() {
260260
event.on("session.status", (evt) => {
261261
if (evt.properties.sessionID !== route.sessionID) return
262262
if (evt.properties.status.type !== "retry") return
263-
if (evt.properties.status.message !== SessionRetry.GO_UPSELL_MESSAGE) return
263+
if (!evt.properties.status.action) return
264264
if (dialog.stack.length > 0) return
265265

266266
const seen = kv.get(GO_UPSELL_LAST_SEEN_AT)
267267
if (typeof seen === "number" && Date.now() - seen < GO_UPSELL_WINDOW) return
268268

269269
if (kv.get(GO_UPSELL_DONT_SHOW)) return
270270

271-
void DialogGoUpsell.show(dialog).then((dontShowAgain) => {
271+
void DialogRetryAction.show(dialog, evt.properties.status.action).then((dontShowAgain) => {
272272
if (dontShowAgain) kv.set(GO_UPSELL_DONT_SHOW, true)
273273
kv.set(GO_UPSELL_LAST_SEEN_AT, Date.now())
274274
})
Collapse file

‎packages/opencode/src/cli/cmd/tui/ui/link.tsx‎

Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/ui/link.tsx
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export interface LinkProps {
66
href: string
77
children?: JSX.Element | string
88
fg?: RGBA
9+
width?: number | "auto" | `${number}%`
10+
wrapMode?: "word" | "none"
911
}
1012

1113
/**
@@ -18,6 +20,8 @@ export function Link(props: LinkProps) {
1820
return (
1921
<text
2022
fg={props.fg}
23+
width={props.width}
24+
wrapMode={props.wrapMode}
2125
onMouseUp={() => {
2226
open(props.href).catch(() => {})
2327
}}
Collapse file

‎packages/opencode/src/session/processor.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/session/processor.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ export const layer: Layer.Layer<
717717
type: "retry",
718718
attempt: info.attempt,
719719
message: info.message,
720+
action: info.action,
720721
next: info.next,
721722
})
722723
},
Collapse file

‎packages/opencode/src/session/retry.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/session/retry.ts
+92-25Lines changed: 92 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@ import { iife } from "@/util/iife"
55

66
export type Err = ReturnType<NamedError["toObject"]>
77

8-
// This exported message is shared with the TUI upsell detector. Matching on a
9-
// literal error string kind of sucks, but it is the simplest for now.
10-
export const GO_UPSELL_MESSAGE = "Free usage exceeded, subscribe to Go https://opencode.ai/go"
8+
export const GO_UPSELL_MESSAGE = "Free usage exceeded, subscribe to Go"
9+
export const PAYG_UPSELL_MESSAGE = "Go usage exceeded, enable PAYG"
10+
export const GO_UPSELL_URL = "https://opencode.ai/go"
11+
12+
export type Retryable = {
13+
message: string
14+
action?: {
15+
title: string
16+
message: string
17+
label: string
18+
link?: string
19+
}
20+
}
1121

1222
export const RETRY_INITIAL_DELAY = 2000
1323
export const RETRY_BACKOFF_FACTOR = 2
@@ -59,8 +69,49 @@ export function retryable(error: Err) {
5969
// 5xx errors are transient server failures and should always be retried,
6070
// even when the provider SDK doesn't explicitly mark them as retryable.
6171
if (!error.data.isRetryable && !(status !== undefined && status >= 500)) return undefined
62-
if (error.data.responseBody?.includes("FreeUsageLimitError")) return GO_UPSELL_MESSAGE
63-
return error.data.message.includes("Overloaded") ? "Provider is overloaded" : error.data.message
72+
if (error.data.responseBody?.includes("FreeUsageLimitError")) {
73+
return {
74+
message: GO_UPSELL_MESSAGE,
75+
action: {
76+
title: "Free limit reached",
77+
message:
78+
"Subscribe to OpenCode Go for reliable access to the best open-source models, starting at $5/month.",
79+
label: "subscribe",
80+
link: GO_UPSELL_URL,
81+
},
82+
}
83+
}
84+
if (error.data.responseBody?.includes("GoUsageLimitError")) {
85+
const body = parseJSON(error.data.responseBody)
86+
const workspace = str(body?.metadata?.workspace)
87+
const limit = str(body?.metadata?.limit)
88+
const resetAt = num(body?.metadata?.resetAt)
89+
const resetIn = iife(() => {
90+
if (resetAt === undefined) return ""
91+
const seconds = Math.max(0, Math.ceil(resetAt))
92+
const days = Math.floor(seconds / 86_400)
93+
const hours = Math.floor((seconds % 86_400) / 3_600)
94+
const minutes = Math.ceil((seconds % 3_600) / 60)
95+
const unit = (value: number, name: string) => `${value} ${name}${value === 1 ? "" : "s"}`
96+
97+
if (days > 0) return hours > 0 ? `${unit(days, "day")} ${unit(hours, "hour")}` : unit(days, "day")
98+
if (hours > 0) return minutes > 0 ? `${unit(hours, "hour")} ${unit(minutes, "minute")}` : unit(hours, "hour")
99+
return minutes > 0 ? unit(minutes, "minute") : "less than a minute"
100+
})
101+
return {
102+
message: PAYG_UPSELL_MESSAGE,
103+
action: {
104+
title: "Go limit reached",
105+
message:
106+
limit && resetIn
107+
? `You hit your ${limit} limit. It will reset in ${resetIn}. You can also enable pay-as-you-go.`
108+
: "Enable pay-as-you-go to keep using Go models after your subscription quota is used.",
109+
label: "enable PAYG",
110+
...(workspace ? { link: `https://opencode.ai/workspace/${workspace}/go` } : {}),
111+
},
112+
}
113+
}
114+
return { message: error.data.message.includes("Overloaded") ? "Provider is overloaded" : error.data.message }
64115
}
65116

66117
// Check for rate limit patterns in plain text error messages
@@ -72,50 +123,66 @@ export function retryable(error: Err) {
72123
lower.includes("rate limit") ||
73124
lower.includes("too many requests")
74125
) {
75-
return msg
126+
return { message: msg }
76127
}
77128
}
78129

79-
const json = iife(() => {
80-
try {
81-
if (typeof error.data?.message === "string") {
82-
const parsed = JSON.parse(error.data.message)
83-
return parsed
84-
}
85-
86-
return JSON.parse(error.data.message)
87-
} catch {
88-
return undefined
89-
}
90-
})
130+
const json = parseJSON(error.data?.message)
91131
if (!json || typeof json !== "object") return undefined
92132
const code = typeof json.code === "string" ? json.code : ""
93133

94134
if (json.type === "error" && json.error?.type === "too_many_requests") {
95-
return "Too Many Requests"
135+
return { message: "Too Many Requests" }
96136
}
97137
if (code.includes("exhausted") || code.includes("unavailable")) {
98-
return "Provider is overloaded"
138+
return { message: "Provider is overloaded" }
99139
}
100140
if (json.type === "error" && typeof json.error?.code === "string" && json.error.code.includes("rate_limit")) {
101-
return "Rate Limited"
141+
return { message: "Rate Limited" }
102142
}
103143
return undefined
104144
}
105145

146+
function str(value: unknown) {
147+
if (value === undefined || value === null) return ""
148+
return String(value)
149+
}
150+
151+
function num(value: unknown) {
152+
const parsed = Number.parseFloat(str(value))
153+
if (Number.isNaN(parsed)) return undefined
154+
return parsed
155+
}
156+
157+
function parseJSON(value: unknown) {
158+
return iife(() => {
159+
try {
160+
if (typeof value !== "string") return undefined
161+
return JSON.parse(value)
162+
} catch {
163+
return undefined
164+
}
165+
})
166+
}
167+
106168
export function policy(opts: {
107169
parse: (error: unknown) => Err
108-
set: (input: { attempt: number; message: string; next: number }) => Effect.Effect<void>
170+
set: (input: { attempt: number; message: string; action?: Retryable["action"]; next: number }) => Effect.Effect<void>
109171
}) {
110172
return Schedule.fromStepWithMetadata(
111173
Effect.succeed((meta: Schedule.InputMetadata<unknown>) => {
112174
const error = opts.parse(meta.input)
113-
const message = retryable(error)
114-
if (!message) return Cause.done(meta.attempt)
175+
const retry = retryable(error)
176+
if (!retry) return Cause.done(meta.attempt)
115177
return Effect.gen(function* () {
116178
const wait = delay(meta.attempt, MessageV2.APIError.isInstance(error) ? error : undefined)
117179
const now = yield* Clock.currentTimeMillis
118-
yield* opts.set({ attempt: meta.attempt, message, next: now + wait })
180+
yield* opts.set({
181+
attempt: meta.attempt,
182+
message: retry.message,
183+
action: retry.action,
184+
next: now + wait,
185+
})
119186
return [meta.attempt, Duration.millis(wait)] as [number, Duration.Duration]
120187
})
121188
}),

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.