GeezerVison is showing github.com — zen: track session in usage · HashNuke/opencode@5712cff
File treeExpand file treeCollapse file tree Open diff view settings 20250902065410_fluffy_raza 20250903035359_serious_whistler 20250911133331_violet_loners 20250911141957_dusty_clint_barton 20250911214917_first_mockingbird 20250911231144_jazzy_skrulls 20250912021148_parallel_gauntlet 20250912161749_familiar_nightshade 20250914213824_eminent_ultimatum 20250914222302_redundant_piledriver 20250914232505_needy_sue_storm 20250915150801_freezing_phil_sheldon 20250915172014_bright_photon 20250915172258_absurd_hobgoblin 20250919135159_demonic_princess_powerful 20250921042124_cloudy_revanche 20250923213126_cold_la_nuit 20250924230623_woozy_thaddeus_ross 20250928163425_nervous_iron_lad 20250928235456_dazzling_cable 20250929181457_supreme_jack_power 20250929224703_flawless_clea 20251002175032_nice_dreadnoughts 20251002223020_optimal_paibok 20251003202205_early_black_crow 20251003210411_legal_joseph 20251004030300_numerous_prodigy 20251007024345_careful_cerise 20251007043715_panoramic_harrier 20251007230438_ordinary_ultragirl 20251008161718_outgoing_outlaw_kid 20251009021849_white_doctor_doom 20251016175624_cynical_jack_flag 20251016214520_short_bulldozer 20251017015733_narrow_blindfold 20251017024232_slimy_energizer 20251031163113_messy_jackal 20251125223403_famous_magik 20251228182259_striped_forge 20260105034337_broken_gamora 20260106204919_odd_misty_knight 20260107000117_flat_nightmare 20260107022356_lame_calypso 20260107041522_tiny_captain_midlands 20260107055817_cuddly_diamondback 20260108224422_charming_black_bolt 20260109000245_huge_omega_red 20260109001625_mean_frank_castle 20260109014234_noisy_domino 20260109040130_bumpy_mephistopheles 20260113215232_jazzy_green_goblin 20260113223840_aromatic_agent_zero 20260116213606_gigantic_hardball 20260116224745_numerous_annihilus 20260122190905_moaning_karnak 20260222233442_clever_toxin
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: infra/console.ts +32-10Lines changed: 32 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -100,26 +100,46 @@ export const stripeWebhook = new stripe.WebhookEndpoint("StripeWebhookEndpoint", | 100 | 100 | ], | 101 | 101 | }) | 102 | 102 |
| 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", { | 104 | 124 | name: "OpenCode Black", | 105 | 125 | }) | 106 | | -const zenPriceProps = { | 107 | | - product: zenProduct.id, | | 126 | +const zenBlackPriceProps = { | | 127 | + product: zenBlackProduct.id, | 108 | 128 | currency: "usd", | 109 | 129 | recurring: { | 110 | 130 | interval: "month", | 111 | 131 | intervalCount: 1, | 112 | 132 | }, | 113 | 133 | } | 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 }) | 117 | 137 | const ZEN_BLACK_PRICE = new sst.Linkable("ZEN_BLACK_PRICE", { | 118 | 138 | 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, | 123 | 143 | }, | 124 | 144 | }) | 125 | 145 | const ZEN_BLACK_LIMITS = new sst.Secret("ZEN_BLACK_LIMITS") | @@ -196,6 +216,8 @@ new sst.cloudflare.x.SolidStart("Console", { | 196 | 216 | AWS_SES_SECRET_ACCESS_KEY, | 197 | 217 | ZEN_BLACK_PRICE, | 198 | 218 | ZEN_BLACK_LIMITS, | | 219 | + ZEN_LITE_PRICE, | | 220 | + ZEN_LITE_LIMITS, | 199 | 221 | new sst.Secret("ZEN_SESSION_SECRET"), | 200 | 222 | ...ZEN_MODELS, | 201 | 223 | ...($dev | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -5,7 +5,7 @@ import { Billing } from "@opencode-ai/console-core/billing.js" | 5 | 5 | import { Database, eq, and, isNull, sql } from "@opencode-ai/console-core/drizzle/index.js" | 6 | 6 | import { BillingTable, SubscriptionTable } from "@opencode-ai/console-core/schema/billing.sql.js" | 7 | 7 | 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" | 9 | 9 | import { withActor } from "~/context/auth.withActor" | 10 | 10 | import { queryBillingInfo } from "../../common" | 11 | 11 | import styles from "./black-section.module.css" | @@ -35,12 +35,12 @@ const querySubscription = query(async (workspaceID: string) => { | 35 | 35 | return { | 36 | 36 | plan: row.subscription.plan, | 37 | 37 | useBalance: row.subscription.useBalance ?? false, | 38 | | - rollingUsage: Black.analyzeRollingUsage({ | | 38 | + rollingUsage: Subscription.analyzeRollingUsage({ | 39 | 39 | plan: row.subscription.plan, | 40 | 40 | usage: row.rollingUsage ?? 0, | 41 | 41 | timeUpdated: row.timeRollingUpdated ?? new Date(), | 42 | 42 | }), | 43 | | - weeklyUsage: Black.analyzeWeeklyUsage({ | | 43 | + weeklyUsage: Subscription.analyzeWeeklyUsage({ | 44 | 44 | plan: row.subscription.plan, | 45 | 45 | usage: row.fixedUsage ?? 0, | 46 | 46 | timeUpdated: row.timeFixedUpdated ?? new Date(), | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,8 @@ import { Billing } from "@opencode-ai/console-core/billing.js" | 9 | 9 | import { Actor } from "@opencode-ai/console-core/actor.js" | 10 | 10 | import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js" | 11 | 11 | 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" | 13 | 14 | import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js" | 14 | 15 | import { ModelTable } from "@opencode-ai/console-core/schema/model.sql.js" | 15 | 16 | import { ProviderTable } from "@opencode-ai/console-core/schema/provider.sql.js" | @@ -196,7 +197,7 @@ export async function handler( | 196 | 197 | const costInfo = calculateCost(modelInfo, usageInfo) | 197 | 198 | await trialLimiter?.track(usageInfo) | 198 | 199 | await rateLimiter?.track() | 199 | | - await trackUsage(billingSource, authInfo, modelInfo, providerInfo, usageInfo, costInfo) | | 200 | + await trackUsage(sessionId, billingSource, authInfo, modelInfo, providerInfo, usageInfo, costInfo) | 200 | 201 | await reload(billingSource, authInfo, costInfo) | 201 | 202 |
| 202 | 203 | const responseConverter = createResponseConverter(providerInfo.format, opts.format) | @@ -246,7 +247,7 @@ export async function handler( | 246 | 247 | const usageInfo = providerInfo.normalizeUsage(usage) | 247 | 248 | const costInfo = calculateCost(modelInfo, usageInfo) | 248 | 249 | await trialLimiter?.track(usageInfo) | 249 | | - await trackUsage(billingSource, authInfo, modelInfo, providerInfo, usageInfo, costInfo) | | 250 | + await trackUsage(sessionId, billingSource, authInfo, modelInfo, providerInfo, usageInfo, costInfo) | 250 | 251 | await reload(billingSource, authInfo, costInfo) | 251 | 252 | cost = calculateOccuredCost(billingSource, costInfo) | 252 | 253 | } | @@ -541,8 +542,9 @@ export async function handler( | 541 | 542 |
| 542 | 543 | // Check weekly limit | 543 | 544 | 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, | 546 | 548 | usage: sub.fixedUsage, | 547 | 549 | timeUpdated: sub.timeFixedUpdated, | 548 | 550 | }) | @@ -555,8 +557,10 @@ export async function handler( | 555 | 557 |
| 556 | 558 | // Check rolling limit | 557 | 559 | 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, | 560 | 564 | usage: sub.rollingUsage, | 561 | 565 | timeUpdated: sub.timeRollingUpdated, | 562 | 566 | }) | @@ -687,6 +691,7 @@ export async function handler( | 687 | 691 | } | 688 | 692 |
| 689 | 693 | async function trackUsage( | | 694 | + sessionId: string, | 690 | 695 | billingSource: BillingSource, | 691 | 696 | authInfo: AuthInfo, | 692 | 697 | modelInfo: ModelInfo, | @@ -734,6 +739,7 @@ export async function handler( | 734 | 739 | cacheWrite1hTokens, | 735 | 740 | cost, | 736 | 741 | keyID: authInfo.apiKeyId, | | 742 | + sessionID: sessionId.substring(0, 30), | 737 | 743 | enrichment: billingSource === "subscription" ? { plan: "sub" } : undefined, | 738 | 744 | }), | 739 | 745 | db | |
Collapse file Copy file name to clipboard File renamed without changes.
|