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: stat worker · comio/opencode@005e64e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • infra
    • console.ts
  • packages
    • console
      • core
        • sst-env.d.ts
      • function
        • src
          • stat.ts
        • sst-env.d.ts
      • resource
        • sst-env.d.ts
    • enterprise
      • sst-env.d.ts
    • function
      • sst-env.d.ts
  • sst-env.d.ts
  • sst.config.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎infra/console.ts‎

Copy file name to clipboardExpand all lines: infra/console.ts
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,12 @@ new sst.cloudflare.x.SolidStart("Console", {
293293
},
294294
},
295295
})
296+
297+
////////////////
298+
// HELPERS
299+
////////////////
300+
301+
export const stat = new sst.cloudflare.Worker("Stat", {
302+
handler: "packages/console/function/src/stat.ts",
303+
link: [database],
304+
})
Collapse file

‎packages/console/core/sst-env.d.ts‎

Copy file name to clipboardExpand all lines: packages/console/core/sst-env.d.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ declare module "sst" {
298298
"EnterpriseStorage": cloudflare.R2Bucket
299299
"GatewayKv": cloudflare.KVNamespace
300300
"LogProcessor": cloudflare.Service
301+
"Stat": cloudflare.Service
301302
"ZenData": cloudflare.R2Bucket
302303
"ZenDataNew": cloudflare.R2Bucket
303304
}
Collapse file

‎packages/console/function/src/stat.ts‎

Copy file name to clipboard
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { WorkerEntrypoint } from "cloudflare:workers"
2+
import { and, Database, inArray } from "@opencode-ai/console-core/drizzle/index.js"
3+
import { ModelTpsRateLimitTable } from "@opencode-ai/console-core/schema/ip.sql.js"
4+
5+
type Result = Record<string, { qualify: number; unqualify: number }>
6+
7+
export default class Stat extends WorkerEntrypoint {
8+
async fetch() {
9+
return new Response("Not Found", { status: 404 })
10+
}
11+
12+
async getStats(ids: string[]): Promise<Result> {
13+
if (ids.length === 0) return {}
14+
15+
const toInterval = (date: Date) =>
16+
parseInt(
17+
date
18+
.toISOString()
19+
.replace(/[^0-9]/g, "")
20+
.substring(0, 12),
21+
)
22+
const now = Date.now()
23+
const intervals = Array.from({ length: 5 }, (_, i) => toInterval(new Date(now - i * 60 * 1000)))
24+
25+
const rows = await Database.use((tx) =>
26+
tx
27+
.select()
28+
.from(ModelTpsRateLimitTable)
29+
.where(and(inArray(ModelTpsRateLimitTable.id, ids), inArray(ModelTpsRateLimitTable.interval, intervals))),
30+
)
31+
32+
const result: Result = Object.fromEntries(ids.map((id) => [id, { qualify: 0, unqualify: 0 }]))
33+
for (const row of rows) {
34+
result[row.id].qualify += row.qualify
35+
result[row.id].unqualify += row.unqualify
36+
}
37+
return result
38+
}
39+
}
Collapse file

‎packages/console/function/sst-env.d.ts‎

Copy file name to clipboardExpand all lines: packages/console/function/sst-env.d.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ declare module "sst" {
298298
"EnterpriseStorage": cloudflare.R2Bucket
299299
"GatewayKv": cloudflare.KVNamespace
300300
"LogProcessor": cloudflare.Service
301+
"Stat": cloudflare.Service
301302
"ZenData": cloudflare.R2Bucket
302303
"ZenDataNew": cloudflare.R2Bucket
303304
}
Collapse file

‎packages/console/resource/sst-env.d.ts‎

Copy file name to clipboardExpand all lines: packages/console/resource/sst-env.d.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ declare module "sst" {
298298
"EnterpriseStorage": cloudflare.R2Bucket
299299
"GatewayKv": cloudflare.KVNamespace
300300
"LogProcessor": cloudflare.Service
301+
"Stat": cloudflare.Service
301302
"ZenData": cloudflare.R2Bucket
302303
"ZenDataNew": cloudflare.R2Bucket
303304
}
Collapse file

‎packages/enterprise/sst-env.d.ts‎

Copy file name to clipboardExpand all lines: packages/enterprise/sst-env.d.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ declare module "sst" {
298298
"EnterpriseStorage": cloudflare.R2Bucket
299299
"GatewayKv": cloudflare.KVNamespace
300300
"LogProcessor": cloudflare.Service
301+
"Stat": cloudflare.Service
301302
"ZenData": cloudflare.R2Bucket
302303
"ZenDataNew": cloudflare.R2Bucket
303304
}
Collapse file

‎packages/function/sst-env.d.ts‎

Copy file name to clipboardExpand all lines: packages/function/sst-env.d.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ declare module "sst" {
298298
"EnterpriseStorage": cloudflare.R2Bucket
299299
"GatewayKv": cloudflare.KVNamespace
300300
"LogProcessor": cloudflare.Service
301+
"Stat": cloudflare.Service
301302
"ZenData": cloudflare.R2Bucket
302303
"ZenDataNew": cloudflare.R2Bucket
303304
}
Collapse file

‎sst-env.d.ts‎

Copy file name to clipboardExpand all lines: sst-env.d.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ declare module "sst" {
153153
"type": "sst.sst.Linkable"
154154
"value": string
155155
}
156+
"Stat": {
157+
"type": "sst.cloudflare.Worker"
158+
}
156159
"Teams": {
157160
"type": "sst.cloudflare.SolidStart"
158161
"url": string
Collapse file

‎sst.config.ts‎

Copy file name to clipboardExpand all lines: sst.config.ts
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ export default $config({
1919
},
2020
async run() {
2121
await import("./infra/app.js")
22-
await import("./infra/console.js")
22+
const { stat } = await import("./infra/console.js")
2323
await import("./infra/enterprise.js")
2424
if ($app.stage === "production" || $app.stage === "vimtor") {
2525
await import("./infra/monitoring.js")
2626
}
27+
28+
return {
29+
STAT_WORKER_NAME: stat.nodes.worker.scriptName,
30+
}
2731
},
2832
})

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.