Repository navigation
feat(app): show paced one-time tip toasts #63664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+261
−2
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3000aaa
feat(app): add a paced queue of dismissible tips
thdxr c8409fa
feat(app): show paced one-time tip toasts
thdxr b2d6359
Merge remote-tracking branch 'origin/dev' into tips-queue
thdxr 2daab99
feat(app): enable tip toasts in all builds
thdxr 49f2243
fix(app): update browser control tip copy
thdxr a098207
fix(app): retitle browser tip
thdxr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import { showToast, toaster } from "@opencode/ui/toast" | ||
| import { Schema } from "effect" | ||
| import { createEffect, createMemo, createSignal, onCleanup } from "solid-js" | ||
| import { useLanguage } from "@/runtime/i18n/language" | ||
| import { Persistence } from "@/runtime/persistence/schema" | ||
| import { Persist, persisted } from "@/runtime/persistence/storage" | ||
| import { usePlatform } from "@/runtime/platform/platform" | ||
| import { ServerConnection, useServers } from "@/runtime/server/registry" | ||
| import { useGlobal } from "@/runtime/server/runtime" | ||
| import { useCommand } from "@/shell/commands/command" | ||
| import { selectTip, TIP_INTERVAL_MS, type Tip } from "./queue" | ||
|
|
||
| const STARTUP_DELAY = 2 * 60 * 1000 | ||
|
|
||
| const History = Persistence.struct({ | ||
| current: Schema.String, | ||
| shownAt: Schema.Finite, | ||
| dismissed: Persistence.array(Schema.String), | ||
| dismissedAt: Schema.Finite, | ||
| }) | ||
|
|
||
| export function createTipToasts() { | ||
| const global = useGlobal() | ||
| const servers = useServers() | ||
| const language = useLanguage() | ||
| const platform = usePlatform() | ||
| const command = useCommand() | ||
|
|
||
| const server = createMemo(() => { | ||
| const conn = servers.visible.find(servers.current) ?? servers.visible[0] | ||
|
|
||
| return conn && global.serverCtx(ServerConnection.key(conn)) | ||
| }) | ||
|
|
||
| const location = () => server()?.data.location | ||
| const [awake, setAwake] = createSignal(false) | ||
| const startup = setTimeout(() => setAwake(true), STARTUP_DELAY) | ||
| onCleanup(() => clearTimeout(startup)) | ||
| createEffect(() => { | ||
| const ctx = server() | ||
|
|
||
| if (!awake() || ctx?.sdk.connection.status() !== "connected") return | ||
| const location = ctx.data.location | ||
| void location | ||
| .syncInfo() | ||
| .then(() => location.mcp.server.sync()) | ||
| .catch(() => undefined) | ||
| }) | ||
|
|
||
| const tips: Tip[] = [ | ||
| { | ||
| id: "browse", | ||
| title: "tips.browse.title", | ||
| description: "tips.browse.description", | ||
| when: () => | ||
| !location() | ||
| ?.mcp.server.list() | ||
| ?.some((item) => item.name === "browse"), | ||
| action: { | ||
| label: "tips.browse.install", | ||
| run: () => platform.openExternal("https://chromewebstore.google.com/detail/mfnicocicmmlkpjnaffgihfjhdgjkdjg"), | ||
| }, | ||
| }, | ||
| { | ||
| id: "session-search", | ||
| title: "tips.search.title", | ||
| description: "tips.search.description", | ||
| action: { label: "command.session.search", run: () => command.trigger("sessions.search") }, | ||
| }, | ||
| ] | ||
|
|
||
| const [history, setHistory, , loaded] = persisted({ ...Persist.global("tips.queue"), sync: true }, History, { | ||
| current: "", | ||
| shownAt: 0, | ||
| dismissed: [], | ||
| dismissedAt: 0, | ||
| }) | ||
|
|
||
| const [tick, setTick] = createSignal(0) | ||
|
|
||
| const selected = createMemo(() => { | ||
| if (!awake() || !loaded() || !location()?.mcp.server.list()) return | ||
| tick() | ||
| const now = Date.now() | ||
|
|
||
| const times = [ | ||
| Math.max(history.shownAt, history.dismissedAt) + TIP_INTERVAL_MS, | ||
| ...tips.flatMap((tip) => [tip.start ?? 0, tip.end ?? 0]), | ||
| ] | ||
|
|
||
| const next = Math.min(...times.filter((time) => time > now)) | ||
|
|
||
| if (Number.isFinite(next)) { | ||
| const timer = setTimeout(() => setTick((n) => n + 1), Math.min(next - now, 2 ** 31 - 1)) | ||
| onCleanup(() => clearTimeout(timer)) | ||
| } | ||
|
|
||
| return selectTip(tips, history, now) | ||
| }) | ||
|
|
||
| createEffect(() => { | ||
| const tip = selected() | ||
|
|
||
| if (!tip) return | ||
|
|
||
| const handled = () => | ||
| setHistory({ current: "", dismissed: [...history.dismissed, tip.id], dismissedAt: Date.now() }) | ||
|
|
||
| global.notifications.tip(() => { | ||
| if (history.current !== tip.id) setHistory({ current: tip.id, shownAt: Date.now() }) | ||
| const action = tip.action | ||
|
|
||
| const id = showToast({ | ||
| persistent: true, | ||
| title: language.t(tip.title), | ||
| description: language.t(tip.description), | ||
| onDismiss: handled, | ||
| actions: action && [ | ||
| { | ||
| label: language.t(action.label), | ||
| onClick: () => { | ||
| handled() | ||
| action.run() | ||
| }, | ||
| }, | ||
| ], | ||
| }) | ||
|
|
||
| return () => toaster.dismiss(id) | ||
| }) | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { expect, test } from "bun:test" | ||
| import { selectTip, type Tip } from "./queue" | ||
|
|
||
| const fresh = { current: "", shownAt: 0, dismissed: [], dismissedAt: 0 } | ||
|
|
||
| const first: Tip = { id: "first", title: "tips.browse.title", description: "tips.browse.description" } | ||
|
|
||
| const second: Tip = { ...first, id: "second" } | ||
|
|
||
| const tips = [first, second] | ||
|
|
||
| const hours = 60 * 60 * 1000 | ||
|
|
||
| test("first eligible tip wins until it is handled or stops being eligible", () => { | ||
| expect(selectTip(tips, fresh, 1)).toBe(first) | ||
| expect(selectTip([{ ...first, when: () => false }, second], fresh, 1)).toBe(second) | ||
| expect(selectTip(tips, { ...fresh, current: second.id, shownAt: 1 }, 24 * hours)).toBe(second) | ||
| }) | ||
|
|
||
| test("handling starts a full day's wait and permanently skips that id", () => { | ||
| const handled = { ...fresh, dismissedAt: hours, dismissed: [first.id] } | ||
| expect(selectTip(tips, handled, 25 * hours - 1)).toBeUndefined() | ||
| expect(selectTip(tips, handled, 25 * hours)).toBe(second) | ||
| expect(selectTip([first], handled, 365 * 24 * hours)).toBeUndefined() | ||
| }) | ||
|
|
||
| test("promo starts inclusively, expires even while shown, and cannot immediately yield to another tip", () => { | ||
| const promo = { ...first, start: hours, end: hours + 1 } | ||
| expect(selectTip([promo], fresh, hours - 1)).toBeUndefined() | ||
| expect(selectTip([promo], fresh, hours)).toBe(promo) | ||
| const shown = { ...fresh, current: promo.id, shownAt: hours } | ||
| expect(selectTip([promo, second], shown, hours + 1)).toBeUndefined() | ||
| expect(selectTip([promo, second], shown, 25 * hours)).toBe(second) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { useLanguage } from "@/runtime/i18n/language" | ||
|
|
||
| export const TIP_INTERVAL_MS = 24 * 60 * 60 * 1000 | ||
|
|
||
| type Text = Parameters<ReturnType<typeof useLanguage>["t"]>[0] | ||
|
|
||
| export type Tip = { | ||
| id: string | ||
| title: Text | ||
| description: Text | ||
| action?: { label: Text; run: () => void } | ||
| when?: () => boolean | ||
| start?: number | ||
| end?: number | ||
| } | ||
|
|
||
| export type TipHistory = { | ||
| current: string | ||
| shownAt: number | ||
| dismissed: readonly string[] | ||
| dismissedAt: number | ||
| } | ||
|
|
||
| /** Array order is priority. Dates are epoch milliseconds; the end is exclusive. */ | ||
| export function selectTip(tips: readonly Tip[], history: TipHistory, now: number) { | ||
| const eligible = (tip: Tip) => | ||
| !history.dismissed.includes(tip.id) && | ||
| (tip.start === undefined || tip.start <= now) && | ||
| (tip.end === undefined || now < tip.end) && | ||
| (tip.when?.() ?? true) | ||
|
|
||
| const current = tips.find((tip) => tip.id === history.current && eligible(tip)) | ||
|
|
||
| if (current) return current | ||
|
|
||
| const last = Math.max(history.shownAt, history.dismissedAt) | ||
|
|
||
| if (last && now < last + TIP_INTERVAL_MS) return | ||
|
|
||
| return tips.find(eligible) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description says the first tip links to https://opencode.ai/product/browse, but Install opens the Chrome Web Store listing directly. Is that intended? Also, the tip's
whenchecks for an MCP server namedbrowse. If installing the extension alone doesn't register that server, the tip will still be eligible after a user has installed browse. In practice it won't come back, because clicking Install already marks it as handled.