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 — zen: track session in usage · HashNuke/opencode@5712cff

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • infra
    • console.ts
  • packages
    • console
      • app/src/routes
        • workspace/[id]/billing
          • black-section.tsx
        • zen/util
          • handler.ts
      • core
        • migrations
          • 20250902065410_fluffy_raza
            • migration.sql
            • snapshot.json
          • 20250903035359_serious_whistler
            • migration.sql
            • snapshot.json
          • 20250911133331_violet_loners
            • migration.sql
            • snapshot.json
          • 20250911141957_dusty_clint_barton
            • migration.sql
            • snapshot.json
          • 20250911214917_first_mockingbird
            • migration.sql
            • snapshot.json
          • 20250911231144_jazzy_skrulls
            • migration.sql
            • snapshot.json
          • 20250912021148_parallel_gauntlet
            • migration.sql
            • snapshot.json
          • 20250912161749_familiar_nightshade
            • migration.sql
            • snapshot.json
          • 20250914213824_eminent_ultimatum
            • migration.sql
            • snapshot.json
          • 20250914222302_redundant_piledriver
            • migration.sql
            • snapshot.json
          • 20250914232505_needy_sue_storm
            • migration.sql
            • snapshot.json
          • 20250915150801_freezing_phil_sheldon
            • migration.sql
            • snapshot.json
          • 20250915172014_bright_photon
            • migration.sql
            • snapshot.json
          • 20250915172258_absurd_hobgoblin
            • migration.sql
            • snapshot.json
          • 20250919135159_demonic_princess_powerful
            • migration.sql
            • snapshot.json
          • 20250921042124_cloudy_revanche
            • migration.sql
            • snapshot.json
          • 20250923213126_cold_la_nuit
            • migration.sql
            • snapshot.json
          • 20250924230623_woozy_thaddeus_ross
            • migration.sql
            • snapshot.json
          • 20250928163425_nervous_iron_lad
            • migration.sql
            • snapshot.json
          • 20250928235456_dazzling_cable
            • migration.sql
            • snapshot.json
          • 20250929181457_supreme_jack_power
            • migration.sql
            • snapshot.json
          • 20250929224703_flawless_clea
            • migration.sql
            • snapshot.json
          • 20251002175032_nice_dreadnoughts
            • migration.sql
            • snapshot.json
          • 20251002223020_optimal_paibok
            • migration.sql
            • snapshot.json
          • 20251003202205_early_black_crow
            • migration.sql
            • snapshot.json
          • 20251003210411_legal_joseph
            • migration.sql
            • snapshot.json
          • 20251004030300_numerous_prodigy
            • migration.sql
            • snapshot.json
          • 20251004045106_hot_wong
            • migration.sql
            • snapshot.json
          • 20251007024345_careful_cerise
            • migration.sql
            • snapshot.json
          • 20251007043715_panoramic_harrier
            • migration.sql
            • snapshot.json
          • 20251007230438_ordinary_ultragirl
            • migration.sql
            • snapshot.json
          • 20251008161718_outgoing_outlaw_kid
            • migration.sql
            • snapshot.json
          • 20251009021849_white_doctor_doom
            • migration.sql
            • snapshot.json
          • 20251016175624_cynical_jack_flag
            • migration.sql
            • snapshot.json
          • 20251016214520_short_bulldozer
            • migration.sql
            • snapshot.json
          • 20251017015733_narrow_blindfold
            • migration.sql
            • snapshot.json
          • 20251017024232_slimy_energizer
            • migration.sql
            • snapshot.json
          • 20251031163113_messy_jackal
            • migration.sql
            • snapshot.json
          • 20251125223403_famous_magik
            • migration.sql
            • snapshot.json
          • 20251228182259_striped_forge
            • migration.sql
            • snapshot.json
          • 20260105034337_broken_gamora
            • migration.sql
            • snapshot.json
          • 20260106204919_odd_misty_knight
            • migration.sql
            • snapshot.json
          • 20260107000117_flat_nightmare
            • migration.sql
            • snapshot.json
          • 20260107022356_lame_calypso
            • migration.sql
            • snapshot.json
          • 20260107041522_tiny_captain_midlands
            • migration.sql
            • snapshot.json
          • 20260107055817_cuddly_diamondback
            • migration.sql
            • snapshot.json
          • 20260108224422_charming_black_bolt
            • migration.sql
            • snapshot.json
          • 20260109000245_huge_omega_red
            • migration.sql
            • snapshot.json
          • 20260109001625_mean_frank_castle
            • migration.sql
            • snapshot.json
          • 20260109014234_noisy_domino
            • migration.sql
            • snapshot.json
          • 20260109040130_bumpy_mephistopheles
            • migration.sql
            • snapshot.json
          • 20260113215232_jazzy_green_goblin
            • migration.sql
            • snapshot.json
          • 20260113223840_aromatic_agent_zero
            • migration.sql
            • snapshot.json
          • 20260116213606_gigantic_hardball
            • migration.sql
            • snapshot.json
          • 20260116224745_numerous_annihilus
            • migration.sql
            • snapshot.json
          • 20260122190905_moaning_karnak
            • migration.sql
            • snapshot.json
          • 20260222233442_clever_toxin
            • migration.sql
            • snapshot.json
          • meta
            • 0000_snapshot.json
            • 0001_snapshot.json
            • 0002_snapshot.json
            • 0003_snapshot.json
            • 0004_snapshot.json
            • 0005_snapshot.json
            • 0006_snapshot.json
            • 0007_snapshot.json
            • 0008_snapshot.json
            • 0009_snapshot.json
            • 0010_snapshot.json
            • 0011_snapshot.json
            • 0012_snapshot.json
            • 0013_snapshot.json
            • 0014_snapshot.json
            • 0015_snapshot.json
            • 0016_snapshot.json
            • 0017_snapshot.json
            • 0018_snapshot.json
            • 0019_snapshot.json
            • 0020_snapshot.json
            • 0021_snapshot.json
            • 0022_snapshot.json
            • 0023_snapshot.json
            • 0024_snapshot.json
            • 0025_snapshot.json
            • 0026_snapshot.json
            • 0027_snapshot.json
            • 0028_snapshot.json
            • 0029_snapshot.json
            • 0030_snapshot.json
            • 0031_snapshot.json
            • 0032_snapshot.json
            • 0033_snapshot.json
            • 0034_snapshot.json
            • 0035_snapshot.json
            • 0036_snapshot.json
            • 0037_snapshot.json
            • 0038_snapshot.json
            • 0039_snapshot.json
            • 0040_snapshot.json
            • 0041_snapshot.json
            • 0042_snapshot.json
            • 0043_snapshot.json
            • 0044_snapshot.json
            • 0045_snapshot.json
            • 0046_snapshot.json
            • 0047_snapshot.json
            • 0048_snapshot.json
            • 0049_snapshot.json
            • 0050_snapshot.json
            • 0051_snapshot.json
            • 0052_snapshot.json
            • 0053_snapshot.json
            • 0054_snapshot.json
            • 0055_snapshot.json
            • _journal.json
        • package.json
        • script
          • promote-lite.ts
          • update-lite.ts
        • src
          • black.ts
          • lite.ts
          • schema
            • billing.sql.ts
          • subscription.ts
        • sst-env.d.ts
      • function
        • sst-env.d.ts
      • resource
        • sst-env.d.ts
    • enterprise
      • sst-env.d.ts
    • function
      • sst-env.d.ts
  • sst-env.d.ts

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎infra/console.ts‎

Copy file name to clipboardExpand all lines: infra/console.ts
+32-10Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,46 @@ export const stripeWebhook = new stripe.WebhookEndpoint("StripeWebhookEndpoint",
100100
],
101101
})
102102

103-
const zenProduct = new stripe.Product("ZenBlack", {
103+
const zenLiteProduct = new stripe.Product("ZenLite", {
104+
name: "OpenCode Lite",
105+
})
106+
const zenLitePrice = new stripe.Price("ZenLitePrice", {
107+
product: zenLiteProduct.id,
108+
currency: "usd",
109+
recurring: {
110+
interval: "month",
111+
intervalCount: 1,
112+
},
113+
unitAmount: 1000,
114+
})
115+
const ZEN_LITE_PRICE = new sst.Linkable("ZEN_LITE_PRICE", {
116+
properties: {
117+
product: zenLiteProduct.id,
118+
price: zenLitePrice.id,
119+
},
120+
})
121+
const ZEN_LITE_LIMITS = new sst.Secret("ZEN_LITE_LIMITS")
122+
123+
const zenBlackProduct = new stripe.Product("ZenBlack", {
104124
name: "OpenCode Black",
105125
})
106-
const zenPriceProps = {
107-
product: zenProduct.id,
126+
const zenBlackPriceProps = {
127+
product: zenBlackProduct.id,
108128
currency: "usd",
109129
recurring: {
110130
interval: "month",
111131
intervalCount: 1,
112132
},
113133
}
114-
const zenPrice200 = new stripe.Price("ZenBlackPrice", { ...zenPriceProps, unitAmount: 20000 })
115-
const zenPrice100 = new stripe.Price("ZenBlack100Price", { ...zenPriceProps, unitAmount: 10000 })
116-
const zenPrice20 = new stripe.Price("ZenBlack20Price", { ...zenPriceProps, unitAmount: 2000 })
134+
const zenBlackPrice200 = new stripe.Price("ZenBlackPrice", { ...zenBlackPriceProps, unitAmount: 20000 })
135+
const zenBlackPrice100 = new stripe.Price("ZenBlack100Price", { ...zenBlackPriceProps, unitAmount: 10000 })
136+
const zenBlackPrice20 = new stripe.Price("ZenBlack20Price", { ...zenBlackPriceProps, unitAmount: 2000 })
117137
const ZEN_BLACK_PRICE = new sst.Linkable("ZEN_BLACK_PRICE", {
118138
properties: {
119-
product: zenProduct.id,
120-
plan200: zenPrice200.id,
121-
plan100: zenPrice100.id,
122-
plan20: zenPrice20.id,
139+
product: zenBlackProduct.id,
140+
plan200: zenBlackPrice200.id,
141+
plan100: zenBlackPrice100.id,
142+
plan20: zenBlackPrice20.id,
123143
},
124144
})
125145
const ZEN_BLACK_LIMITS = new sst.Secret("ZEN_BLACK_LIMITS")
@@ -196,6 +216,8 @@ new sst.cloudflare.x.SolidStart("Console", {
196216
AWS_SES_SECRET_ACCESS_KEY,
197217
ZEN_BLACK_PRICE,
198218
ZEN_BLACK_LIMITS,
219+
ZEN_LITE_PRICE,
220+
ZEN_LITE_LIMITS,
199221
new sst.Secret("ZEN_SESSION_SECRET"),
200222
...ZEN_MODELS,
201223
...($dev
Collapse file

‎packages/console/app/src/routes/workspace/[id]/billing/black-section.tsx‎

Copy file name to clipboardExpand all lines: packages/console/app/src/routes/workspace/[id]/billing/black-section.tsx
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Billing } from "@opencode-ai/console-core/billing.js"
55
import { Database, eq, and, isNull, sql } from "@opencode-ai/console-core/drizzle/index.js"
66
import { BillingTable, SubscriptionTable } from "@opencode-ai/console-core/schema/billing.sql.js"
77
import { Actor } from "@opencode-ai/console-core/actor.js"
8-
import { Black } from "@opencode-ai/console-core/black.js"
8+
import { Subscription } from "@opencode-ai/console-core/black.js"
99
import { withActor } from "~/context/auth.withActor"
1010
import { queryBillingInfo } from "../../common"
1111
import styles from "./black-section.module.css"
@@ -35,12 +35,12 @@ const querySubscription = query(async (workspaceID: string) => {
3535
return {
3636
plan: row.subscription.plan,
3737
useBalance: row.subscription.useBalance ?? false,
38-
rollingUsage: Black.analyzeRollingUsage({
38+
rollingUsage: Subscription.analyzeRollingUsage({
3939
plan: row.subscription.plan,
4040
usage: row.rollingUsage ?? 0,
4141
timeUpdated: row.timeRollingUpdated ?? new Date(),
4242
}),
43-
weeklyUsage: Black.analyzeWeeklyUsage({
43+
weeklyUsage: Subscription.analyzeWeeklyUsage({
4444
plan: row.subscription.plan,
4545
usage: row.fixedUsage ?? 0,
4646
timeUpdated: row.timeFixedUpdated ?? new Date(),
Collapse file

‎packages/console/app/src/routes/zen/util/handler.ts‎

Copy file name to clipboardExpand all lines: packages/console/app/src/routes/zen/util/handler.ts
+13-7Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { Billing } from "@opencode-ai/console-core/billing.js"
99
import { Actor } from "@opencode-ai/console-core/actor.js"
1010
import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
1111
import { ZenData } from "@opencode-ai/console-core/model.js"
12-
import { Black, BlackData } from "@opencode-ai/console-core/black.js"
12+
import { Subscription } from "@opencode-ai/console-core/subscription.js"
13+
import { BlackData } from "@opencode-ai/console-core/black.js"
1314
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
1415
import { ModelTable } from "@opencode-ai/console-core/schema/model.sql.js"
1516
import { ProviderTable } from "@opencode-ai/console-core/schema/provider.sql.js"
@@ -196,7 +197,7 @@ export async function handler(
196197
const costInfo = calculateCost(modelInfo, usageInfo)
197198
await trialLimiter?.track(usageInfo)
198199
await rateLimiter?.track()
199-
await trackUsage(billingSource, authInfo, modelInfo, providerInfo, usageInfo, costInfo)
200+
await trackUsage(sessionId, billingSource, authInfo, modelInfo, providerInfo, usageInfo, costInfo)
200201
await reload(billingSource, authInfo, costInfo)
201202

202203
const responseConverter = createResponseConverter(providerInfo.format, opts.format)
@@ -246,7 +247,7 @@ export async function handler(
246247
const usageInfo = providerInfo.normalizeUsage(usage)
247248
const costInfo = calculateCost(modelInfo, usageInfo)
248249
await trialLimiter?.track(usageInfo)
249-
await trackUsage(billingSource, authInfo, modelInfo, providerInfo, usageInfo, costInfo)
250+
await trackUsage(sessionId, billingSource, authInfo, modelInfo, providerInfo, usageInfo, costInfo)
250251
await reload(billingSource, authInfo, costInfo)
251252
cost = calculateOccuredCost(billingSource, costInfo)
252253
}
@@ -541,8 +542,9 @@ export async function handler(
541542

542543
// Check weekly limit
543544
if (sub.fixedUsage && sub.timeFixedUpdated) {
544-
const result = Black.analyzeWeeklyUsage({
545-
plan,
545+
const blackData = BlackData.getLimits({ plan })
546+
const result = Subscription.analyzeWeeklyUsage({
547+
limit: blackData.fixedLimit,
546548
usage: sub.fixedUsage,
547549
timeUpdated: sub.timeFixedUpdated,
548550
})
@@ -555,8 +557,10 @@ export async function handler(
555557

556558
// Check rolling limit
557559
if (sub.rollingUsage && sub.timeRollingUpdated) {
558-
const result = Black.analyzeRollingUsage({
559-
plan,
560+
const blackData = BlackData.getLimits({ plan })
561+
const result = Subscription.analyzeRollingUsage({
562+
limit: blackData.rollingLimit,
563+
window: blackData.rollingWindow,
560564
usage: sub.rollingUsage,
561565
timeUpdated: sub.timeRollingUpdated,
562566
})
@@ -687,6 +691,7 @@ export async function handler(
687691
}
688692

689693
async function trackUsage(
694+
sessionId: string,
690695
billingSource: BillingSource,
691696
authInfo: AuthInfo,
692697
modelInfo: ModelInfo,
@@ -734,6 +739,7 @@ export async function handler(
734739
cacheWrite1hTokens,
735740
cost,
736741
keyID: authInfo.apiKeyId,
742+
sessionID: sessionId.substring(0, 30),
737743
enrichment: billingSource === "subscription" ? { plan: "sub" } : undefined,
738744
}),
739745
db
Collapse file

‎…ole/core/migrations/0000_fluffy_raza.sql‎ ‎…20250902065410_fluffy_raza/migration.sql‎packages/console/core/migrations/0000_fluffy_raza.sql renamed to packages/console/core/migrations/20250902065410_fluffy_raza/migration.sql packages/console/core/migrations/0000_fluffy_raza.sql renamed to packages/console/core/migrations/20250902065410_fluffy_raza/migration.sql

Copy file name to clipboard
File renamed without changes.

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.