mirror of
https://github.com/elder-plinius/G0DM0D3.git
synced 2026-11-16 07:02:25 +00:00
fix: flush auth, dedup filenames, TS errors, stale UI counts
- Require Bearer TELEMETRY_FLUSH_SECRET on GET ?flush=force - Derive flush filename from key fingerprint (concurrent flushes → same file → idempotent overwrite, no duplicate rows) - Fix TS errors in Venice helper (explicit type assertions) - Correct model counts in SettingsModal (smart=41, power=53, ultra=60) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,7 @@ interface Env {
|
||||
HF_DATASET_REPO: string
|
||||
HF_DATASET_BRANCH?: string
|
||||
TELEMETRY_KV?: KVNamespace
|
||||
TELEMETRY_FLUSH_SECRET?: string
|
||||
}
|
||||
|
||||
interface TelemetryEvent {
|
||||
@@ -108,15 +109,26 @@ export const onRequestOptions: PagesFunction<Env> = async () => {
|
||||
return new Response(null, { status: 204, headers: CORS_HEADERS })
|
||||
}
|
||||
|
||||
// GET ?flush=force — external cron trigger for guaranteed flush
|
||||
// Set up a CF Worker cron or external cron to hit this every 30 min
|
||||
// to ensure batches don't sit in KV forever during low-traffic periods.
|
||||
// GET ?flush=force — authenticated cron trigger for guaranteed flush.
|
||||
// Requires Authorization: Bearer <TELEMETRY_FLUSH_SECRET> header.
|
||||
// Set TELEMETRY_FLUSH_SECRET in CF Pages env vars, then configure a
|
||||
// CF Worker scheduled event or external cron to call this every 30 min.
|
||||
export const onRequestGet: PagesFunction<Env> = async (context) => {
|
||||
const { request, env } = context
|
||||
const url = new URL(request.url)
|
||||
|
||||
if (url.searchParams.get('flush') !== 'force') {
|
||||
return jsonResponse({ status: 'ok', hint: 'POST events here, or GET ?flush=force to trigger a flush' }, 200)
|
||||
return new Response(null, { status: 204, headers: CORS_HEADERS })
|
||||
}
|
||||
|
||||
if (!env.TELEMETRY_FLUSH_SECRET) {
|
||||
return jsonResponse({ error: 'Flush not configured' }, 503)
|
||||
}
|
||||
|
||||
const authHeader = request.headers.get('Authorization') || ''
|
||||
const token = authHeader.replace(/^Bearer\s+/i, '')
|
||||
if (!token || token !== env.TELEMETRY_FLUSH_SECRET) {
|
||||
return jsonResponse({ error: 'Unauthorized' }, 401)
|
||||
}
|
||||
|
||||
if (!env.TELEMETRY_KV || !env.HF_TOKEN || !env.HF_DATASET_REPO) {
|
||||
@@ -248,8 +260,12 @@ async function flushKVToHF(env: Env): Promise<number> {
|
||||
if (chunks.length === 0) return 0
|
||||
|
||||
const combined = chunks.join('\n')
|
||||
// Derive filename from the key set — if two concurrent flushes read
|
||||
// the same keys, they produce the same filename and HF overwrites
|
||||
// (idempotent). This prevents duplicate data from concurrent flushes.
|
||||
const keyFingerprint = shortHash(allKeys.map(k => k.name).sort().join(','))
|
||||
const ts = new Date().toISOString().replace(/[:.]/g, '-')
|
||||
const hash = shortHash(combined)
|
||||
const hash = keyFingerprint
|
||||
const filePath = `telemetry/batch_${ts}_${hash}.jsonl`
|
||||
const branch = env.HF_DATASET_BRANCH || 'main'
|
||||
|
||||
|
||||
@@ -1669,9 +1669,9 @@ function UltraplinianTab() {
|
||||
const tiers: { id: 'fast' | 'standard' | 'smart' | 'power' | 'ultra'; label: string; models: number; desc: string }[] = [
|
||||
{ id: 'fast', label: 'FAST', models: 12, desc: 'Quick responses, free-tier models (~10-15s)' },
|
||||
{ id: 'standard', label: 'STANDARD', models: 27, desc: 'Fast + mid-range workhorses (~15-25s)' },
|
||||
{ id: 'smart', label: 'SMART', models: 39, desc: 'Standard + flagships & heavy hitters (~25-40s)' },
|
||||
{ id: 'power', label: 'POWER', models: 49, desc: 'Smart + frontier cutting-edge models (~35-50s)' },
|
||||
{ id: 'ultra', label: 'ULTRA', models: 56, desc: 'ALL available models, maximum coverage (~45-70s)' },
|
||||
{ id: 'smart', label: 'SMART', models: 41, desc: 'Standard + flagships & heavy hitters (~25-40s)' },
|
||||
{ id: 'power', label: 'POWER', models: 53, desc: 'Smart + frontier cutting-edge models (~35-50s)' },
|
||||
{ id: 'ultra', label: 'ULTRA', models: 60, desc: 'ALL available models, maximum coverage (~45-70s)' },
|
||||
]
|
||||
|
||||
return (
|
||||
@@ -1821,9 +1821,9 @@ function ConsortiumTab() {
|
||||
const tiers: { id: 'fast' | 'standard' | 'smart' | 'power' | 'ultra'; label: string; models: number; desc: string }[] = [
|
||||
{ id: 'fast', label: 'FAST', models: 12, desc: 'Collect from 12 models + orchestrator synthesis (~20-30s)' },
|
||||
{ id: 'standard', label: 'STANDARD', models: 27, desc: 'Collect from 27 models + orchestrator synthesis (~30-45s)' },
|
||||
{ id: 'smart', label: 'SMART', models: 39, desc: 'Collect from 39 models + orchestrator synthesis (~40-60s)' },
|
||||
{ id: 'power', label: 'POWER', models: 49, desc: 'Collect from 49 models + orchestrator synthesis (~45-65s)' },
|
||||
{ id: 'ultra', label: 'ULTRA', models: 56, desc: 'Collect from ALL 56 models + orchestrator synthesis (~55-80s)' },
|
||||
{ id: 'smart', label: 'SMART', models: 41, desc: 'Collect from 41 models + orchestrator synthesis (~40-60s)' },
|
||||
{ id: 'power', label: 'POWER', models: 53, desc: 'Collect from 53 models + orchestrator synthesis (~45-65s)' },
|
||||
{ id: 'ultra', label: 'ULTRA', models: 60, desc: 'Collect from ALL 60 models + orchestrator synthesis (~55-80s)' },
|
||||
]
|
||||
|
||||
return (
|
||||
@@ -1987,12 +1987,12 @@ function PlanTab() {
|
||||
limits: 'Unlimited total, 60/min, 1000/day',
|
||||
features: [
|
||||
'Everything in Free',
|
||||
'ULTRAPLINIAN fast + standard + smart + power (49 models)',
|
||||
'ULTRAPLINIAN fast + standard + smart + power (53 models)',
|
||||
'Dataset export (JSON)',
|
||||
'Research API (read: stats, batches)',
|
||||
],
|
||||
locked: [
|
||||
'ULTRAPLINIAN ultra tier (all 56 models)',
|
||||
'ULTRAPLINIAN ultra tier (all 60 models)',
|
||||
'Corpus query + download',
|
||||
'Force-flush to HuggingFace',
|
||||
'Metadata event log',
|
||||
@@ -2005,7 +2005,7 @@ function PlanTab() {
|
||||
limits: 'Unlimited total, 300/min, 10000/day',
|
||||
features: [
|
||||
'Everything in Pro',
|
||||
'ULTRAPLINIAN all tiers (56 models)',
|
||||
'ULTRAPLINIAN all tiers (60 models)',
|
||||
'Dataset export (JSON + JSONL)',
|
||||
'Full Research API (query, download)',
|
||||
'Force-flush to HuggingFace',
|
||||
|
||||
@@ -753,12 +753,12 @@ export async function sendMessageViaVenice({
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}))
|
||||
const errorData = await response.json().catch(() => ({})) as { error?: { message?: string } }
|
||||
const msg = errorData.error?.message || `Venice API error (${response.status})`
|
||||
throw new Error(msg)
|
||||
}
|
||||
|
||||
const data: OpenRouterResponse = await response.json()
|
||||
const data = await response.json() as OpenRouterResponse
|
||||
|
||||
if (!data.choices || data.choices.length === 0) {
|
||||
throw new Error('No response from Venice model')
|
||||
|
||||
Reference in New Issue
Block a user