lilac-live-discount 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -0
  3. package/package.json +31 -0
  4. package/plugin.tsx +108 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # lilac-live-discount
2
+
3
+ A [OpenCode](https://github.com/anomalyco/opencode) TUI plugin that shows live [Lilac](https://getlilac.com) subscription discount rates as a colored badge next to your prompt.
4
+
5
+ Polls the public `GET https://api.getlilac.com/status` endpoint every 10 minutes and on model switches. Only renders for `lilac` provider models.
6
+
7
+ ## Colors
8
+
9
+ | Discount | Color |
10
+ |----------|-------|
11
+ | 75%+ | green |
12
+ | 25–50% | yellow |
13
+ | 0% | red |
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ opencode plugin lilac-live-discount
19
+ ```
20
+
21
+ Or add to your `tui.json`:
22
+
23
+ ```json
24
+ {
25
+ "$schema": "https://opencode.ai/tui.json",
26
+ "plugin": ["lilac-live-discount"]
27
+ }
28
+ ```
29
+
30
+ No API key required — the status endpoint is public.
31
+
32
+ ## License
33
+
34
+ MIT
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "lilac-live-discount",
3
+ "version": "1.0.0",
4
+ "description": "OpenCode TUI plugin that shows live Lilac subscription discount rates next to your prompt.",
5
+ "type": "module",
6
+ "exports": {
7
+ "./tui": "./plugin.tsx"
8
+ },
9
+ "oc-plugin": ["tui"],
10
+ "keywords": [
11
+ "opencode",
12
+ "opencode-plugin",
13
+ "opencode-tui-plugin",
14
+ "lilac",
15
+ "discount",
16
+ "status"
17
+ ],
18
+ "license": "MIT",
19
+ "engines": {
20
+ "opencode": "^1.0.0"
21
+ },
22
+ "peerDependencies": {
23
+ "@opencode-ai/plugin": ">=1.15.0",
24
+ "@opentui/solid": ">=0.2.16",
25
+ "solid-js": ">=1.8.0"
26
+ },
27
+ "peerDependenciesMeta": {
28
+ "@opentui/solid": { "optional": true },
29
+ "solid-js": { "optional": true }
30
+ }
31
+ }
package/plugin.tsx ADDED
@@ -0,0 +1,108 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+ import { createSignal } from "solid-js"
3
+ import type { TuiPlugin, TuiPluginModule } from "@opencode-ai/plugin/tui"
4
+
5
+ type StatusModel = {
6
+ id: string
7
+ name?: string
8
+ current_subscription_supply_state?: string
9
+ current_subscription_discount_percent?: number
10
+ current_subscription_credit_multiplier?: string
11
+ }
12
+ type StatusData = {
13
+ updated_at: string
14
+ current_subscription_supply_updated_at?: string
15
+ models: StatusModel[]
16
+ }
17
+
18
+ const STATUS_URL = "https://api.getlilac.com/status?window=5m"
19
+ const REFRESH_MS = 10 * 60 * 1000
20
+ const LILAC = "lilac"
21
+
22
+ function parseModelRef(ref: string): { provider: string; id: string } | null {
23
+ const i = ref.indexOf("/")
24
+ if (i < 0) return null
25
+ return { provider: ref.slice(0, i), id: ref.slice(i + 1) }
26
+ }
27
+
28
+ function tierColor(pct: number): string {
29
+ if (pct >= 75) return "#22c55e" // green
30
+ if (pct >= 25) return "#eab308" // yellow
31
+ return "#ef4444" // red
32
+ }
33
+
34
+ function shortName(id: string): string {
35
+ const parts = id.split("/")
36
+ const last = parts[parts.length - 1] ?? id
37
+ return last.replace(/-\d+b-it$/, "").replace(/-it$/, "")
38
+ }
39
+
40
+ const tui: TuiPlugin = async (api) => {
41
+ const [data, setData] = createSignal<StatusData | null>(null)
42
+ const [tick, setTick] = createSignal(0)
43
+
44
+ async function poll() {
45
+ try {
46
+ const res = await fetch(STATUS_URL)
47
+ if (!res.ok) return
48
+ const j = (await res.json()) as unknown
49
+ if (j && typeof j === "object" && Array.isArray((j as StatusData).models)) {
50
+ setData(j as StatusData)
51
+ }
52
+ } catch {
53
+ // keep last good snapshot
54
+ }
55
+ }
56
+ void poll()
57
+ const timer = setInterval(poll, REFRESH_MS)
58
+ api.lifecycle.onDispose(() => clearInterval(timer))
59
+
60
+ // re-render when the active model switches
61
+ api.event.on("session.next.model.switched", () => setTick((n) => n + 1))
62
+
63
+ function findModel(modelId: string): StatusModel | undefined {
64
+ const d = data()
65
+ if (!d || !Array.isArray(d.models)) return undefined
66
+ return d.models.find((m) => m.id === modelId)
67
+ }
68
+
69
+ function badge(modelId: string, display: string) {
70
+ const m = findModel(modelId)
71
+ if (!m) return null
72
+ const pct = m.current_subscription_discount_percent ?? 0
73
+ const color = tierColor(pct)
74
+ const label = m.name ?? display
75
+ return (
76
+ <text fg={color} paddingLeft={1}>
77
+ ● {label} · {pct}% off
78
+ </text>
79
+ )
80
+ }
81
+
82
+ api.slots.register({
83
+ order: 120,
84
+ slots: {
85
+ session_prompt_right(_ctx, value) {
86
+ tick()
87
+ const session = api.state.session.get(value.session_id)
88
+ const model = session?.model
89
+ if (!model || model.providerID.toLowerCase() !== LILAC) return null
90
+ return badge(model.id, shortName(model.id))
91
+ },
92
+ home_prompt_right(_ctx) {
93
+ tick()
94
+ const ref = api.state.config.model
95
+ if (!ref) return null
96
+ const parsed = parseModelRef(ref)
97
+ if (!parsed || parsed.provider.toLowerCase() !== LILAC) return null
98
+ return badge(parsed.id, shortName(parsed.id))
99
+ },
100
+ },
101
+ })
102
+ }
103
+
104
+ const plugin: TuiPluginModule & { id: string } = {
105
+ id: "lilac-discount-tui",
106
+ tui,
107
+ }
108
+ export default plugin