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 — fix(console): merge duplicate Go usage rows (#45503) · Archipel/opencode@dfa91ed

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/console/app
    • src/lib
      • lite-usage.ts
    • test
      • liteUsage.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/console/app/src/lib/lite-usage.ts‎

Copy file name to clipboardExpand all lines: packages/console/app/src/lib/lite-usage.ts
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@ export type LiteUsageBreakdownItem = {
1818
}
1919

2020
export function buildLiteUsageBreakdown(input: { usage: number; limit: number; sources: LiteUsageBreakdownSource[] }) {
21-
const rows: LiteUsageBreakdownItem[] = input.sources
21+
// Legacy usage can resolve to the same rate as a separately grouped recorded multiplier.
22+
const groups = new Map<string, LiteUsageBreakdownSource>()
23+
input.sources.forEach((item) => {
24+
const key = JSON.stringify([item.model, item.multiplier])
25+
const row = groups.get(key)
26+
if (!row) {
27+
groups.set(key, { ...item })
28+
return
29+
}
30+
row.cost += item.cost
31+
row.quotaCost += item.quotaCost
32+
row.estimated ||= item.estimated
33+
})
34+
const rows: LiteUsageBreakdownItem[] = Array.from(groups.values())
2235
.filter((item) => item.cost !== 0 || item.quotaCost !== 0)
2336
.sort((a, b) => b.quotaCost - a.quotaCost)
2437
.map((item) => ({
Collapse file

‎packages/console/app/test/liteUsage.test.ts‎

Copy file name to clipboardExpand all lines: packages/console/app/test/liteUsage.test.ts
+58Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,62 @@ describe("Go usage breakdown", () => {
7272
expect(result.rows.map((row) => row.multiplier)).toEqual([2, 1])
7373
expect(result.rows.map((row) => row.contributionPercent)).toEqual([40, 10])
7474
})
75+
76+
test.each([false, true])("merges same-rate usage (estimated first: %s)", (estimated) => {
77+
const sources = [
78+
{ model: "deepseek-v4-flash", name: "DeepSeek V4 Flash", cost: 200, quotaCost: 400, multiplier: 2, estimated },
79+
{ model: "other", name: "Other", cost: 500, quotaCost: 500, multiplier: 1, estimated: false },
80+
{
81+
model: "deepseek-v4-flash",
82+
name: "DeepSeek V4 Flash",
83+
cost: 100,
84+
quotaCost: 199,
85+
multiplier: 2,
86+
estimated: !estimated,
87+
},
88+
]
89+
const original = structuredClone(sources)
90+
const result = buildLiteUsageBreakdown({ usage: 1_050, limit: 6_000, sources })
91+
92+
expect(result.rows).toHaveLength(2)
93+
expect(result.rows[0]).toMatchObject({
94+
model: "deepseek-v4-flash",
95+
cost: 300,
96+
quotaCost: 599,
97+
multiplier: 2,
98+
estimated: true,
99+
})
100+
expect(getModelQuotaLimit(result.limit, result.rows[0].multiplier)).toBe(3_000)
101+
expect(result.usage).toBe(1_050)
102+
expect(result.usagePercent).toBe(17.5)
103+
expect(result.rows.reduce((total, row) => total + row.contributionPercent, 0)).toBeCloseTo(result.usagePercent)
104+
expect(sources).toEqual(original)
105+
})
106+
107+
test("keeps distinct model IDs with the same display name separate", () => {
108+
const result = buildLiteUsageBreakdown({
109+
usage: 300,
110+
limit: 1_000,
111+
sources: [
112+
{ model: "first", name: "Model", cost: 100, quotaCost: 100, multiplier: 1, estimated: false },
113+
{ model: "second", name: "Model", cost: 200, quotaCost: 200, multiplier: 1, estimated: false },
114+
],
115+
})
116+
117+
expect(result.rows.map((row) => row.model)).toEqual(["second", "first"])
118+
})
119+
120+
test("does not merge unknown rates with recorded rates", () => {
121+
const result = buildLiteUsageBreakdown({
122+
usage: 300,
123+
limit: 1_000,
124+
sources: [
125+
{ model: "glm", name: "GLM", cost: 100, quotaCost: 100, estimated: true },
126+
{ model: "glm", name: "GLM", cost: 200, quotaCost: 200, multiplier: 1, estimated: false },
127+
],
128+
})
129+
130+
expect(result.rows.map((row) => row.multiplier)).toEqual([1, undefined])
131+
expect(getModelQuotaLimit(result.limit, result.rows[1].multiplier)).toBeUndefined()
132+
})
75133
})

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.