From a30307027a17f650b8f6d227d675e08f0147b652 Mon Sep 17 00:00:00 2001 From: cerq <66092565+cerqiest@users.noreply.github.com> Date: Thu, 21 May 2026 15:04:16 +0000 Subject: [PATCH 1/3] fix: dev server improperly handling browser spawn failures --- scripts/dev.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/scripts/dev.ts b/scripts/dev.ts index 81893084..37408ac2 100644 --- a/scripts/dev.ts +++ b/scripts/dev.ts @@ -241,15 +241,23 @@ console.log('Watching for changes...'); // --- Auto-open browser (unless --no-open) --- -function openBrowser(url: string) { - if (process.platform === 'win32') { - nodeSpawn('cmd', ['/c', 'start', '""', url], { detached: true, stdio: 'ignore' }).unref(); - } else { - nodeSpawn(process.platform === 'darwin' ? 'open' : 'xdg-open', [url], { - detached: true, - stdio: 'ignore', - }).unref(); - } +function openBrowser(url: string): Promise { + return new Promise((resolve, reject) => { + let proc: ChildProcess; + if (process.platform === 'win32') { + proc = nodeSpawn('cmd', ['/c', 'start', '""', url], { detached: true, stdio: 'ignore' }); + } else { + proc = nodeSpawn(process.platform === 'darwin' ? 'open' : 'xdg-open', [url], { + detached: true, + stdio: 'ignore', + }); + } + proc.on('error', reject); + proc.on('spawn', () => { + proc.unref(); + resolve(); + }); + }); } if (!noOpen) { @@ -259,7 +267,7 @@ if (!noOpen) { await waitForServer(); const url = `http://localhost:${process.env.PORT}/ui/login?token=${encodeURIComponent(process.env.ADMIN_KEY!)}`; console.log(`[dev] Server ready. Opening browser: ${url}`); - openBrowser(url); + await openBrowser(url); } catch (err) { console.error(`[dev] ${err instanceof Error ? err.message : err}. Not opening browser.`); } From 8839188cb6e4e6d700a162e040c7a6aef5346cdd Mon Sep 17 00:00:00 2001 From: cerq <66092565+cerqiest@users.noreply.github.com> Date: Thu, 21 May 2026 16:04:20 +0000 Subject: [PATCH 2/3] feat: add exe.dev quota checker --- .../backend/drizzle/schema/postgres/enums.ts | 1 + packages/backend/src/config.ts | 12 ++ .../src/services/quota/checker-registry.ts | 1 + .../checkers/__tests__/exedev-checker.test.ts | 137 ++++++++++++++++++ .../services/quota/checkers/exedev-checker.ts | 87 +++++++++++ .../providers/ProviderQuotaEditor.tsx | 2 + .../components/quota/ExeDevQuotaConfig.tsx | 35 +++++ .../frontend/src/hooks/useProviderForm.tsx | 2 + 8 files changed, 277 insertions(+) create mode 100644 packages/backend/src/services/quota/checkers/__tests__/exedev-checker.test.ts create mode 100644 packages/backend/src/services/quota/checkers/exedev-checker.ts create mode 100644 packages/frontend/src/components/quota/ExeDevQuotaConfig.tsx diff --git a/packages/backend/drizzle/schema/postgres/enums.ts b/packages/backend/drizzle/schema/postgres/enums.ts index 535f24b7..9618e985 100644 --- a/packages/backend/drizzle/schema/postgres/enums.ts +++ b/packages/backend/drizzle/schema/postgres/enums.ts @@ -37,4 +37,5 @@ export const quotaCheckerTypeEnum = pgEnum('quota_checker_type', [ 'wafer', 'opencode-go', 'crof', + 'exedev', ]); diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 27976c68..b31721a1 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -329,6 +329,11 @@ const CrofQuotaCheckerOptionsSchema = z.object({ endpoint: z.string().url().optional(), }); +const ExeDevQuotaCheckerOptionsSchema = z.object({ + apiKey: z.string().min(1, 'exe.dev API bearer token is required'), + endpoint: z.string().url().optional(), +}); + const ProviderQuotaCheckerSchema = z.discriminatedUnion('type', [ z.object({ type: z.literal('naga'), @@ -519,6 +524,13 @@ const ProviderQuotaCheckerSchema = z.discriminatedUnion('type', [ id: z.string().trim().min(1).optional(), options: CrofQuotaCheckerOptionsSchema.optional().default({}), }), + z.object({ + type: z.literal('exedev'), + enabled: z.boolean().default(true), + intervalMinutes: z.number().min(1).default(30), + id: z.string().trim().min(1).optional(), + options: ExeDevQuotaCheckerOptionsSchema, + }), ]); export const ProviderConfigSchema = z diff --git a/packages/backend/src/services/quota/checker-registry.ts b/packages/backend/src/services/quota/checker-registry.ts index 3134340c..c1cc0c5a 100644 --- a/packages/backend/src/services/quota/checker-registry.ts +++ b/packages/backend/src/services/quota/checker-registry.ts @@ -210,4 +210,5 @@ export async function loadAllCheckers(): Promise { await import('./checkers/wafer-checker'); await import('./checkers/opencode-go-checker'); await import('./checkers/crof-checker'); + await import('./checkers/exedev-checker'); } diff --git a/packages/backend/src/services/quota/checkers/__tests__/exedev-checker.test.ts b/packages/backend/src/services/quota/checkers/__tests__/exedev-checker.test.ts new file mode 100644 index 00000000..346232a6 --- /dev/null +++ b/packages/backend/src/services/quota/checkers/__tests__/exedev-checker.test.ts @@ -0,0 +1,137 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { createMeterContext, isCheckerRegistered } from '../../checker-registry'; +import checkerDef from '../exedev-checker'; + +const makeCtx = (options: Record = {}) => + createMeterContext('exedev-test', 'exedev', { apiKey: 'exedev-api-key', ...options }); + +const mockCreditsResponse = { + monthly_allowance_usd: 20, + monthly_credits_left_usd: 17.992124659999995, + extra_credits_left_usd: 0, + next_credit_reset: '00:00 on Jun 1', +}; + +describe('exedev checker', () => { + const setFetchMock = (impl: (...args: unknown[]) => Promise): void => { + global.fetch = vi.fn(impl) as unknown as typeof fetch; + }; + + beforeEach(() => { + vi.restoreAllMocks(); + }); + + it('is registered under exedev', () => { + expect(isCheckerRegistered('exedev')).toBe(true); + }); + + it('sends POST with correct body, headers, and returns two meters', async () => { + let capturedUrl: string | undefined; + let capturedMethod: string | undefined; + let capturedBody: string | undefined; + let capturedAuth: string | undefined; + let capturedContentType: string | undefined; + + setFetchMock(async (input: unknown, init: unknown) => { + const reqInit = init as RequestInit | undefined; + capturedUrl = String(input as string); + capturedMethod = reqInit?.method; + const body = reqInit?.body; + capturedBody = typeof body === 'string' ? body : body ? await new Response(body).text() : ''; + const headers = new Headers(reqInit?.headers); + capturedAuth = headers.get('Authorization') ?? undefined; + capturedContentType = headers.get('Content-Type') ?? undefined; + return new Response(JSON.stringify(mockCreditsResponse), { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }); + }); + + const meters = await checkerDef.check(makeCtx()); + + expect(capturedUrl).toBe('https://exe.dev/exec'); + expect(capturedMethod).toBe('POST'); + expect(capturedBody).toBe('billing credits --json'); + expect(capturedAuth).toBe('Bearer exedev-api-key'); + expect(capturedContentType).toBe('text/plain'); + + expect(meters).toHaveLength(2); + + const allowance = meters.find((m) => m.key === 'shelley_allowance')!; + expect(allowance.kind).toBe('allowance'); + expect(allowance.limit).toBe(20); + expect(allowance.used).toBeCloseTo(2.00787534); + expect(allowance.remaining).toBeCloseTo(17.99212466); + expect(allowance.periodValue).toBe(1); + expect(allowance.periodUnit).toBe('month'); + expect(allowance.periodCycle).toBe('fixed'); + expect(allowance.resetsAt).toMatch(/^20\d{2}-06-01T00:00:00\.000Z$/); + + const balance = meters.find((m) => m.key === 'shelley_extra_credits')!; + expect(balance.kind).toBe('balance'); + expect(balance.remaining).toBe(0); + expect(balance.unit).toBe('usd'); + }); + + it('returns extra credits balance when greater than zero', async () => { + setFetchMock( + async () => + new Response( + JSON.stringify({ + ...mockCreditsResponse, + extra_credits_left_usd: 5.5, + }), + { status: 200, headers: { 'Content-Type': 'application/json' } } + ) + ); + + const meters = await checkerDef.check(makeCtx()); + const balance = meters.find((m) => m.key === 'shelley_extra_credits')!; + expect(balance.remaining).toBe(5.5); + }); + + it('throws for non-200 response', async () => { + setFetchMock( + async () => new Response('unauthorized', { status: 401, statusText: 'Unauthorized' }) + ); + + await expect(checkerDef.check(makeCtx())).rejects.toThrow('HTTP 401: Unauthorized'); + }); + + it('uses custom endpoint when provided', async () => { + let capturedUrl: string | undefined; + setFetchMock(async (input: unknown) => { + capturedUrl = String(input as string); + return new Response(JSON.stringify(mockCreditsResponse), { status: 200 }); + }); + + await checkerDef.check(makeCtx({ endpoint: 'https://custom.example.com/exec' })); + + expect(capturedUrl).toBe('https://custom.example.com/exec'); + }); + + it('parses next_credit_reset with year inference', async () => { + setFetchMock(async () => new Response(JSON.stringify(mockCreditsResponse), { status: 200 })); + + const meters = await checkerDef.check(makeCtx()); + const allowance = meters.find((m) => m.key === 'shelley_allowance')!; + // resetsAt should be an ISO string for June 1 of current or next year + const resetsAt = allowance.resetsAt!; + const resetDate = new Date(resetsAt); + expect(resetDate.getUTCMonth()).toBe(5); // June = 5 + expect(resetDate.getUTCDate()).toBe(1); + expect(resetDate.getUTCHours()).toBe(0); + expect(resetDate.getUTCMinutes()).toBe(0); + }); + + it('throws on invalid monthly_allowance_usd', async () => { + setFetchMock( + async () => + new Response(JSON.stringify({ ...mockCreditsResponse, monthly_allowance_usd: 'bad' }), { + status: 200, + }) + ); + + await expect(checkerDef.check(makeCtx())).rejects.toThrow('Invalid monthly_allowance_usd'); + }); +}); diff --git a/packages/backend/src/services/quota/checkers/exedev-checker.ts b/packages/backend/src/services/quota/checkers/exedev-checker.ts new file mode 100644 index 00000000..31f19680 --- /dev/null +++ b/packages/backend/src/services/quota/checkers/exedev-checker.ts @@ -0,0 +1,87 @@ +import { defineChecker } from '../checker-registry'; +import { z } from 'zod'; +import { logger } from '../../../utils/logger'; + +interface ExeDevCreditsResponse { + monthly_allowance_usd: number; + monthly_credits_left_usd: number; + extra_credits_left_usd: number; + next_credit_reset: string; +} + +function parseResetTimestamp(input: string): string { + // Format: "00:00 on Jun 1" → ISO 8601 + const [time, datePart] = input.split(' on '); + if (!time || !datePart) throw new Error(`Cannot parse next_credit_reset: "${input}"`); + + const year = new Date().getUTCFullYear(); + let date = new Date(`${datePart}, ${year} ${time} UTC`); + if (isNaN(date.getTime())) throw new Error(`Cannot parse next_credit_reset: "${input}"`); + if (date < new Date()) date = new Date(`${datePart}, ${year + 1} ${time} UTC`); + return date.toISOString(); +} + +export default defineChecker({ + type: 'exedev', + displayName: 'exe.dev', + optionsSchema: z.object({ + apiKey: z.string().min(1, 'exe.dev API bearer token is required'), + endpoint: z.string().url().optional(), + }), + async check(ctx) { + const apiKey = ctx.requireOption('apiKey'); + const endpoint = ctx.getOption('endpoint', 'https://exe.dev/exec'); + + logger.silly(`Calling ${endpoint}`); + + const response = await fetch(endpoint, { + method: 'POST', + headers: { + Authorization: `Bearer ${apiKey}`, + 'Content-Type': 'text/plain', + }, + body: 'billing credits --json', + }); + + if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`); + + const data: ExeDevCreditsResponse = await response.json(); + + const limit = Number(data.monthly_allowance_usd); + const remaining = Number(data.monthly_credits_left_usd); + const used = limit - remaining; + const extraCredits = Number(data.extra_credits_left_usd); + + if (!Number.isFinite(limit)) + throw new Error(`Invalid monthly_allowance_usd: ${String(data.monthly_allowance_usd)}`); + if (!Number.isFinite(remaining)) + throw new Error(`Invalid monthly_credits_left_usd: ${String(data.monthly_credits_left_usd)}`); + if (!Number.isFinite(extraCredits)) + throw new Error(`Invalid extra_credits_left_usd: ${String(data.extra_credits_left_usd)}`); + + const resetsAt = data.next_credit_reset + ? parseResetTimestamp(data.next_credit_reset) + : undefined; + + return [ + ctx.allowance({ + key: 'shelley_allowance', + label: 'Monthly allowance', + unit: 'usd', + limit, + used, + remaining, + periodValue: 1, + periodUnit: 'month', + periodCycle: 'fixed', + resetsAt, + }), + ctx.balance({ + key: 'shelley_extra_credits', + label: 'Extra credits', + unit: 'usd', + remaining: extraCredits, + }), + ]; + }, +}); diff --git a/packages/frontend/src/components/providers/ProviderQuotaEditor.tsx b/packages/frontend/src/components/providers/ProviderQuotaEditor.tsx index 8bb22e54..6811b0b4 100644 --- a/packages/frontend/src/components/providers/ProviderQuotaEditor.tsx +++ b/packages/frontend/src/components/providers/ProviderQuotaEditor.tsx @@ -23,6 +23,7 @@ import { ZenmuxQuotaConfig } from '../quota/ZenmuxQuotaConfig'; import { WaferQuotaConfig } from '../quota/WaferQuotaConfig'; import { OpenCodeGoQuotaConfig } from '../quota/OpenCodeGoQuotaConfig'; import { CrofQuotaConfig } from '../quota/CrofQuotaConfig'; +import { ExeDevQuotaConfig } from '../quota/ExeDevQuotaConfig'; interface Props { editingProvider: Provider; @@ -65,6 +66,7 @@ const QUOTA_CONFIG_MAP: Record< wafer: WaferQuotaConfig, 'opencode-go': OpenCodeGoQuotaConfig, crof: CrofQuotaConfig, + exedev: ExeDevQuotaConfig, }; export function ProviderQuotaEditor({ diff --git a/packages/frontend/src/components/quota/ExeDevQuotaConfig.tsx b/packages/frontend/src/components/quota/ExeDevQuotaConfig.tsx new file mode 100644 index 00000000..dce72d84 --- /dev/null +++ b/packages/frontend/src/components/quota/ExeDevQuotaConfig.tsx @@ -0,0 +1,35 @@ +import React from "react"; +import { Input } from "../ui/Input"; + +export interface ExeDevQuotaConfigProps { + options: Record; + onChange: (options: Record) => void; +} + +export const ExeDevQuotaConfig: React.FC = ({ + options, + onChange, +}) => { + const handleChange = (key: string, value: string) => { + onChange({ ...options, [key]: value }); + }; + + return ( +
+ handleChange("apiKey", e.target.value)} + placeholder="Bearer token from exe.dev" + hint={`Generate with: ssh exe.dev ssh-key generate-api-key --cmds "'billing credits'" --label "'Plexus Quota Checker'"`} + /> + + handleChange("endpoint", e.target.value)} + placeholder="https://exe.dev/exec" + /> +
+ ); +}; diff --git a/packages/frontend/src/hooks/useProviderForm.tsx b/packages/frontend/src/hooks/useProviderForm.tsx index 485299bc..e362839d 100644 --- a/packages/frontend/src/hooks/useProviderForm.tsx +++ b/packages/frontend/src/hooks/useProviderForm.tsx @@ -767,6 +767,8 @@ export function useProviderForm() { return 'Session cookie is required for Wisdom Gate quota checker'; if (quotaType === 'devpass' && (!options.session || !(options.session as string).trim())) return 'Session cookie is required for DevPass quota checker'; + if (quotaType === 'exedev' && (!options.apiKey || !(options.apiKey as string).trim())) + return 'API bearer token is required for exe.dev quota checker'; if (quotaType === 'opencode-go') { if (!options.workspaceId || !(options.workspaceId as string).trim()) return 'Workspace ID is required for OpenCode Go quota checker'; From 897efbb505ce66910c509d00ec674aeda77ae382 Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Sun, 24 May 2026 16:26:20 -0700 Subject: [PATCH 3/3] fix(quota): clean up exedev checker per review feedback - Remove apiKey from options schema (auto-inherited from provider config) - Make options optional().default({}) in discriminated union - Replace non-spec Date string parsing with explicit Date.UTC() - Include response body text in HTTP error messages - Add [exedev] prefix to logger messages - Add negative-value validation on numeric fields - Switch ExeDevQuotaConfig to single quotes and match CrofQuotaConfig style - Remove apiKey input from frontend config component - Remove exedev apiKey validation from useProviderForm - Add ExeDevQuotaConfig export to quota/index.ts barrel - Revert unrelated openBrowser change in scripts/dev.ts --- .../drizzle/migrations_pg/0058_test_setup.sql | 1 + .../migrations_pg/meta/0058_snapshot.json | 3174 +++++++++++++++++ .../drizzle/migrations_pg/meta/_journal.json | 7 + packages/backend/src/config.ts | 3 +- .../checkers/__tests__/exedev-checker.test.ts | 15 +- .../services/quota/checkers/exedev-checker.ts | 49 +- .../components/quota/ExeDevQuotaConfig.tsx | 45 +- .../frontend/src/components/quota/index.ts | 1 + .../frontend/src/hooks/useProviderForm.tsx | 2 - scripts/dev.ts | 28 +- 10 files changed, 3269 insertions(+), 56 deletions(-) create mode 100644 packages/backend/drizzle/migrations_pg/0058_test_setup.sql create mode 100644 packages/backend/drizzle/migrations_pg/meta/0058_snapshot.json diff --git a/packages/backend/drizzle/migrations_pg/0058_test_setup.sql b/packages/backend/drizzle/migrations_pg/0058_test_setup.sql new file mode 100644 index 00000000..79e0a5ab --- /dev/null +++ b/packages/backend/drizzle/migrations_pg/0058_test_setup.sql @@ -0,0 +1 @@ +ALTER TYPE "public"."quota_checker_type" ADD VALUE 'exedev'; \ No newline at end of file diff --git a/packages/backend/drizzle/migrations_pg/meta/0058_snapshot.json b/packages/backend/drizzle/migrations_pg/meta/0058_snapshot.json new file mode 100644 index 00000000..73a310dd --- /dev/null +++ b/packages/backend/drizzle/migrations_pg/meta/0058_snapshot.json @@ -0,0 +1,3174 @@ +{ + "id": "77c83238-560f-4b35-9048-4a55fcbbd0fb", + "prevId": "6ce4fac8-63df-433d-9cf4-00bc6ab58da8", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.oauth_credentials": { + "name": "oauth_credentials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "oauth_provider_type": { + "name": "oauth_provider_type", + "type": "oauth_provider_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uq_oauth_credentials": { + "name": "uq_oauth_credentials", + "nullsNotDistinct": false, + "columns": [ + "oauth_provider_type", + "account_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.request_usage": { + "name": "request_usage", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_ip": { + "name": "source_ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attribution": { + "name": "attribution", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "incoming_api_type": { + "name": "incoming_api_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attempt_count": { + "name": "attempt_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "retry_history": { + "name": "retry_history", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "incoming_model_alias": { + "name": "incoming_model_alias", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "canonical_model_name": { + "name": "canonical_model_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "selected_model_name": { + "name": "selected_model_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "final_attempt_provider": { + "name": "final_attempt_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "final_attempt_model": { + "name": "final_attempt_model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "all_attempted_providers": { + "name": "all_attempted_providers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "outgoing_api_type": { + "name": "outgoing_api_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tokens_input": { + "name": "tokens_input", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tokens_output": { + "name": "tokens_output", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tokens_reasoning": { + "name": "tokens_reasoning", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tokens_cached": { + "name": "tokens_cached", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tokens_cache_write": { + "name": "tokens_cache_write", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cost_input": { + "name": "cost_input", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "cost_output": { + "name": "cost_output", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "cost_cached": { + "name": "cost_cached", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "cost_cache_write": { + "name": "cost_cache_write", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "cost_total": { + "name": "cost_total", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "cost_source": { + "name": "cost_source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cost_metadata": { + "name": "cost_metadata", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_time": { + "name": "start_time", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "duration_ms": { + "name": "duration_ms", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "ttft_ms": { + "name": "ttft_ms", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "tokens_per_sec": { + "name": "tokens_per_sec", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "is_streamed": { + "name": "is_streamed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "is_passthrough": { + "name": "is_passthrough", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "response_status": { + "name": "response_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tokens_estimated": { + "name": "tokens_estimated", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "tools_defined": { + "name": "tools_defined", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "message_count": { + "name": "message_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parallel_tool_calls_enabled": { + "name": "parallel_tool_calls_enabled", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tool_calls_count": { + "name": "tool_calls_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "finish_reason": { + "name": "finish_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_vision_fallthrough": { + "name": "is_vision_fallthrough", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "is_descriptor_request": { + "name": "is_descriptor_request", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "vision_fallthrough_model": { + "name": "vision_fallthrough_model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kwh_used": { + "name": "kwh_used", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "provider_reported_cost": { + "name": "provider_reported_cost", + "type": "real", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_request_usage_date": { + "name": "idx_request_usage_date", + "columns": [ + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_request_usage_provider": { + "name": "idx_request_usage_provider", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_request_usage_request_id": { + "name": "idx_request_usage_request_id", + "columns": [ + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_request_usage_api_key": { + "name": "idx_request_usage_api_key", + "columns": [ + { + "expression": "api_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "start_time", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "request_usage_request_id_unique": { + "name": "request_usage_request_id_unique", + "nullsNotDistinct": false, + "columns": [ + "request_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.provider_models": { + "name": "provider_models", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "model_name": { + "name": "model_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pricing_config": { + "name": "pricing_config", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "model_type": { + "name": "model_type", + "type": "model_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "access_via": { + "name": "access_via", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "extra_body": { + "name": "extra_body", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "adapter": { + "name": "adapter", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "max_concurrency": { + "name": "max_concurrency", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "provider_models_provider_id_providers_id_fk": { + "name": "provider_models_provider_id_providers_id_fk", + "tableFrom": "provider_models", + "tableTo": "providers", + "columnsFrom": [ + "provider_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uq_provider_models": { + "name": "uq_provider_models", + "nullsNotDistinct": false, + "columns": [ + "provider_id", + "model_name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.quota_snapshots": { + "name": "quota_snapshots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "checker_id": { + "name": "checker_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "group_id": { + "name": "group_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "window_type": { + "name": "window_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "checked_at": { + "name": "checked_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "limit": { + "name": "limit", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "used": { + "name": "used", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "remaining": { + "name": "remaining", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "utilization_percent": { + "name": "utilization_percent", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resets_at": { + "name": "resets_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "success": { + "name": "success", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_quota_provider_checked": { + "name": "idx_quota_provider_checked", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_quota_checker_window": { + "name": "idx_quota_checker_window", + "columns": [ + { + "expression": "checker_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "window_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_quota_group_window": { + "name": "idx_quota_group_window", + "columns": [ + { + "expression": "group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "window_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_quota_checked_at": { + "name": "idx_quota_checked_at", + "columns": [ + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.model_alias_targets": { + "name": "model_alias_targets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "alias_id": { + "name": "alias_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "provider_slug": { + "name": "provider_slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "model_name": { + "name": "model_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "group_name": { + "name": "group_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "model_alias_targets_alias_id_model_aliases_id_fk": { + "name": "model_alias_targets_alias_id_model_aliases_id_fk", + "tableFrom": "model_alias_targets", + "tableTo": "model_aliases", + "columnsFrom": [ + "alias_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uq_alias_targets": { + "name": "uq_alias_targets", + "nullsNotDistinct": false, + "columns": [ + "alias_id", + "provider_slug", + "model_name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.api_keys": { + "name": "api_keys", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "secret_hash": { + "name": "secret_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quota_name": { + "name": "quota_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "allowed_models": { + "name": "allowed_models", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "allowed_providers": { + "name": "allowed_providers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "excluded_models": { + "name": "excluded_models", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "excluded_providers": { + "name": "excluded_providers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "api_keys_name_unique": { + "name": "api_keys_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + }, + "api_keys_secret_unique": { + "name": "api_keys_secret_unique", + "nullsNotDistinct": false, + "columns": [ + "secret" + ] + }, + "api_keys_secret_hash_unique": { + "name": "api_keys_secret_hash_unique", + "nullsNotDistinct": false, + "columns": [ + "secret_hash" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mcp_debug_logs": { + "name": "mcp_debug_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "raw_request_headers": { + "name": "raw_request_headers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "raw_request_body": { + "name": "raw_request_body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "raw_response_headers": { + "name": "raw_response_headers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "raw_response_body": { + "name": "raw_response_body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_mcp_debug_logs_request_id": { + "name": "idx_mcp_debug_logs_request_id", + "columns": [ + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "mcp_debug_logs_request_id_unique": { + "name": "mcp_debug_logs_request_id_unique", + "nullsNotDistinct": false, + "columns": [ + "request_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mcp_request_usage": { + "name": "mcp_request_usage", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "start_time": { + "name": "start_time", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "duration_ms": { + "name": "duration_ms", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "server_name": { + "name": "server_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "upstream_url": { + "name": "upstream_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "method": { + "name": "method", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "jsonrpc_method": { + "name": "jsonrpc_method", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tool_name": { + "name": "tool_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attribution": { + "name": "attribution", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_ip": { + "name": "source_ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "response_status": { + "name": "response_status", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "is_streamed": { + "name": "is_streamed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "has_debug": { + "name": "has_debug", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error_code": { + "name": "error_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_mcp_request_usage_server_name": { + "name": "idx_mcp_request_usage_server_name", + "columns": [ + { + "expression": "server_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_mcp_request_usage_created_at": { + "name": "idx_mcp_request_usage_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "mcp_request_usage_request_id_unique": { + "name": "mcp_request_usage_request_id_unique", + "nullsNotDistinct": false, + "columns": [ + "request_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.alias_metadata_overrides": { + "name": "alias_metadata_overrides", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "alias_id": { + "name": "alias_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "context_length": { + "name": "context_length", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "pricing_prompt": { + "name": "pricing_prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pricing_completion": { + "name": "pricing_completion", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pricing_input_cache_read": { + "name": "pricing_input_cache_read", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pricing_input_cache_write": { + "name": "pricing_input_cache_write", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "architecture_input_modalities": { + "name": "architecture_input_modalities", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "architecture_output_modalities": { + "name": "architecture_output_modalities", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "architecture_tokenizer": { + "name": "architecture_tokenizer", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "supported_parameters": { + "name": "supported_parameters", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "top_provider_context_length": { + "name": "top_provider_context_length", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "top_provider_max_completion_tokens": { + "name": "top_provider_max_completion_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "alias_metadata_overrides_alias_id_model_aliases_id_fk": { + "name": "alias_metadata_overrides_alias_id_model_aliases_id_fk", + "tableFrom": "alias_metadata_overrides", + "tableTo": "model_aliases", + "columnsFrom": [ + "alias_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uq_alias_metadata_overrides": { + "name": "uq_alias_metadata_overrides", + "nullsNotDistinct": false, + "columns": [ + "alias_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.providers": { + "name": "providers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "api_base_url": { + "name": "api_base_url", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "oauth_provider_type": { + "name": "oauth_provider_type", + "type": "oauth_provider_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "oauth_credential_id": { + "name": "oauth_credential_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "disable_cooldown": { + "name": "disable_cooldown", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "stall_cooldown": { + "name": "stall_cooldown", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "discount": { + "name": "discount", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "estimate_tokens": { + "name": "estimate_tokens", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "use_claude_masking": { + "name": "use_claude_masking", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "gemini_thinking_enabled": { + "name": "gemini_thinking_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "headers": { + "name": "headers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "extra_body": { + "name": "extra_body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quota_checker_type": { + "name": "quota_checker_type", + "type": "quota_checker_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "quota_checker_id": { + "name": "quota_checker_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quota_checker_enabled": { + "name": "quota_checker_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "quota_checker_interval": { + "name": "quota_checker_interval", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 30 + }, + "quota_checker_options": { + "name": "quota_checker_options", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "gpu_profile": { + "name": "gpu_profile", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "gpu_ram_gb": { + "name": "gpu_ram_gb", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "gpu_bandwidth_tb_s": { + "name": "gpu_bandwidth_tb_s", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "gpu_flops_tflop": { + "name": "gpu_flops_tflop", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "gpu_power_draw_watts": { + "name": "gpu_power_draw_watts", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "adapter": { + "name": "adapter", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "timeout_ms": { + "name": "timeout_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "stall_ttfb_ms": { + "name": "stall_ttfb_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "stall_ttfb_bytes": { + "name": "stall_ttfb_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "stall_min_bps": { + "name": "stall_min_bps", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "stall_window_ms": { + "name": "stall_window_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "stall_grace_period_ms": { + "name": "stall_grace_period_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "max_concurrency": { + "name": "max_concurrency", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_providers_slug": { + "name": "idx_providers_slug", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "providers_oauth_credential_id_oauth_credentials_id_fk": { + "name": "providers_oauth_credential_id_oauth_credentials_id_fk", + "tableFrom": "providers", + "tableTo": "oauth_credentials", + "columnsFrom": [ + "oauth_credential_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "providers_slug_unique": { + "name": "providers_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mcp_servers": { + "name": "mcp_servers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "upstream_url": { + "name": "upstream_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "headers": { + "name": "headers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "mcp_servers_name_unique": { + "name": "mcp_servers_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.inference_errors": { + "name": "inference_errors", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_stack": { + "name": "error_stack", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_errors_request_id": { + "name": "idx_errors_request_id", + "columns": [ + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_errors_date": { + "name": "idx_errors_date", + "columns": [ + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_inference_errors_api_key": { + "name": "idx_inference_errors_api_key", + "columns": [ + { + "expression": "api_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.debug_logs": { + "name": "debug_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "raw_request": { + "name": "raw_request", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "transformed_request": { + "name": "transformed_request", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "raw_response": { + "name": "raw_response", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "transformed_response": { + "name": "transformed_response", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "raw_response_snapshot": { + "name": "raw_response_snapshot", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "transformed_response_snapshot": { + "name": "transformed_response_snapshot", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_debug_logs_request_id": { + "name": "idx_debug_logs_request_id", + "columns": [ + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_debug_logs_created_at": { + "name": "idx_debug_logs_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_debug_logs_api_key": { + "name": "idx_debug_logs_api_key", + "columns": [ + { + "expression": "api_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_quota_definitions": { + "name": "user_quota_definitions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quota_type": { + "name": "quota_type", + "type": "quota_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "limit_type": { + "name": "limit_type", + "type": "limit_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "limit_value": { + "name": "limit_value", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "duration": { + "name": "duration", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_quota_definitions_name_unique": { + "name": "user_quota_definitions_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.conversations": { + "name": "conversations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "plexus_account_id": { + "name": "plexus_account_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_conversations_updated": { + "name": "idx_conversations_updated", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.meter_snapshots": { + "name": "meter_snapshots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "checker_id": { + "name": "checker_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "checker_type": { + "name": "checker_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "meter_key": { + "name": "meter_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "group": { + "name": "group", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "limit": { + "name": "limit", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "used": { + "name": "used", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "remaining": { + "name": "remaining", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "utilization_state": { + "name": "utilization_state", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "utilization_percent": { + "name": "utilization_percent", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "period_value": { + "name": "period_value", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "period_unit": { + "name": "period_unit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "period_cycle": { + "name": "period_cycle", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resets_at": { + "name": "resets_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "success": { + "name": "success", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "checked_at": { + "name": "checked_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_meter_checker_meter_checked": { + "name": "idx_meter_checker_meter_checked", + "columns": [ + { + "expression": "checker_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "meter_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_meter_provider_checked": { + "name": "idx_meter_provider_checked", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_meter_checked_at": { + "name": "idx_meter_checked_at", + "columns": [ + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.model_aliases": { + "name": "model_aliases", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "selector": { + "name": "selector", + "type": "selector_strategy", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "priority": { + "name": "priority", + "type": "alias_priority", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'selector'" + }, + "model_type": { + "name": "model_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "additional_aliases": { + "name": "additional_aliases", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "advanced": { + "name": "advanced", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "metadata_source": { + "name": "metadata_source", + "type": "metadata_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "metadata_source_path": { + "name": "metadata_source_path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "use_image_fallthrough": { + "name": "use_image_fallthrough", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "model_architecture": { + "name": "model_architecture", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "enforce_limits": { + "name": "enforce_limits", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "sticky_session": { + "name": "sticky_session", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "preferred_api": { + "name": "preferred_api", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "pi_model": { + "name": "pi_model", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "target_groups": { + "name": "target_groups", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "extra_body": { + "name": "extra_body", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "model_aliases_slug_unique": { + "name": "model_aliases_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.provider_cooldowns": { + "name": "provider_cooldowns", + "schema": "", + "columns": { + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expiry": { + "name": "expiry", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_cooldowns_expiry": { + "name": "idx_cooldowns_expiry", + "columns": [ + { + "expression": "expiry", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "provider_cooldowns_provider_model_pk": { + "name": "provider_cooldowns_provider_model_pk", + "columns": [ + "provider", + "model" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.provider_performance": { + "name": "provider_performance", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "canonical_model_name": { + "name": "canonical_model_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "time_to_first_token_ms": { + "name": "time_to_first_token_ms", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "total_tokens": { + "name": "total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "tokens_per_sec": { + "name": "tokens_per_sec", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "e2e_tokens_per_sec": { + "name": "e2e_tokens_per_sec", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "failure_count": { + "name": "failure_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "success_count": { + "name": "success_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_provider_performance_lookup": { + "name": "idx_provider_performance_lookup", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "model", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.quota_state": { + "name": "quota_state", + "schema": "", + "columns": { + "key_name": { + "name": "key_name", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "quota_name": { + "name": "quota_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "limit_type": { + "name": "limit_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "current_usage": { + "name": "current_usage", + "type": "real", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_updated": { + "name": "last_updated", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "window_start": { + "name": "window_start", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.response_items": { + "name": "response_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "response_id": { + "name": "response_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "item_index": { + "name": "item_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_type": { + "name": "item_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "item_data": { + "name": "item_data", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_response_items_response": { + "name": "idx_response_items_response", + "columns": [ + { + "expression": "response_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_index", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_response_items_type": { + "name": "idx_response_items_type", + "columns": [ + { + "expression": "item_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.responses": { + "name": "responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "object": { + "name": "object", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "completed_at": { + "name": "completed_at", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "output_items": { + "name": "output_items", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "instructions": { + "name": "instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "temperature": { + "name": "temperature", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "top_p": { + "name": "top_p", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "max_output_tokens": { + "name": "max_output_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "top_logprobs": { + "name": "top_logprobs", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parallel_tool_calls": { + "name": "parallel_tool_calls", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tool_choice": { + "name": "tool_choice", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tools": { + "name": "tools", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "text_config": { + "name": "text_config", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reasoning_config": { + "name": "reasoning_config", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "usage_input_tokens": { + "name": "usage_input_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "usage_output_tokens": { + "name": "usage_output_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "usage_reasoning_tokens": { + "name": "usage_reasoning_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "usage_cached_tokens": { + "name": "usage_cached_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "usage_total_tokens": { + "name": "usage_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "previous_response_id": { + "name": "previous_response_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "conversation_id": { + "name": "conversation_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "store": { + "name": "store", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "background": { + "name": "background", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "truncation": { + "name": "truncation", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "incomplete_details": { + "name": "incomplete_details", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "safety_identifier": { + "name": "safety_identifier", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "service_tier": { + "name": "service_tier", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "prompt_cache_key": { + "name": "prompt_cache_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "prompt_cache_retention": { + "name": "prompt_cache_retention", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "plexus_provider": { + "name": "plexus_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "plexus_target_model": { + "name": "plexus_target_model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "plexus_api_type": { + "name": "plexus_api_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "plexus_canonical_model": { + "name": "plexus_canonical_model", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_responses_conversation": { + "name": "idx_responses_conversation", + "columns": [ + { + "expression": "conversation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_responses_created_at": { + "name": "idx_responses_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_responses_status": { + "name": "idx_responses_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_responses_previous": { + "name": "idx_responses_previous", + "columns": [ + { + "expression": "previous_response_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.system_settings": { + "name": "system_settings", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.model_type": { + "name": "model_type", + "schema": "public", + "values": [ + "chat", + "embeddings", + "transcriptions", + "speech", + "image", + "responses" + ] + }, + "public.oauth_provider_type": { + "name": "oauth_provider_type", + "schema": "public", + "values": [ + "anthropic", + "openai-codex", + "github-copilot", + "google-gemini-cli", + "google-antigravity" + ] + }, + "public.quota_checker_type": { + "name": "quota_checker_type", + "schema": "public", + "values": [ + "naga", + "synthetic", + "nanogpt", + "zai", + "moonshot", + "minimax", + "minimax-coding", + "openrouter", + "kilo", + "openai-codex", + "claude-code", + "kimi-code", + "copilot", + "wisdomgate", + "apertis", + "apertis-coding-plan", + "poe", + "routing-run", + "gemini-cli", + "antigravity", + "novita", + "ollama", + "neuralwatt", + "zenmux", + "devpass", + "wafer", + "opencode-go", + "crof", + "exedev" + ] + }, + "public.limit_type": { + "name": "limit_type", + "schema": "public", + "values": [ + "requests", + "tokens", + "cost" + ] + }, + "public.quota_type": { + "name": "quota_type", + "schema": "public", + "values": [ + "rolling", + "daily", + "weekly", + "monthly" + ] + }, + "public.alias_priority": { + "name": "alias_priority", + "schema": "public", + "values": [ + "selector", + "api_match" + ] + }, + "public.metadata_source": { + "name": "metadata_source", + "schema": "public", + "values": [ + "openrouter", + "models.dev", + "catwalk", + "custom" + ] + }, + "public.selector_strategy": { + "name": "selector_strategy", + "schema": "public", + "values": [ + "random", + "in_order", + "cost", + "latency", + "usage", + "performance" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/backend/drizzle/migrations_pg/meta/_journal.json b/packages/backend/drizzle/migrations_pg/meta/_journal.json index 23a57387..7eb5cc52 100644 --- a/packages/backend/drizzle/migrations_pg/meta/_journal.json +++ b/packages/backend/drizzle/migrations_pg/meta/_journal.json @@ -407,6 +407,13 @@ "when": 1779130553213, "tag": "0057_add_alias_extra_body", "breakpoints": true + }, + { + "idx": 58, + "version": "7", + "when": 1779665076807, + "tag": "0058_test_setup", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index b31721a1..c65077ed 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -330,7 +330,6 @@ const CrofQuotaCheckerOptionsSchema = z.object({ }); const ExeDevQuotaCheckerOptionsSchema = z.object({ - apiKey: z.string().min(1, 'exe.dev API bearer token is required'), endpoint: z.string().url().optional(), }); @@ -529,7 +528,7 @@ const ProviderQuotaCheckerSchema = z.discriminatedUnion('type', [ enabled: z.boolean().default(true), intervalMinutes: z.number().min(1).default(30), id: z.string().trim().min(1).optional(), - options: ExeDevQuotaCheckerOptionsSchema, + options: ExeDevQuotaCheckerOptionsSchema.optional().default({}), }), ]); diff --git a/packages/backend/src/services/quota/checkers/__tests__/exedev-checker.test.ts b/packages/backend/src/services/quota/checkers/__tests__/exedev-checker.test.ts index 346232a6..caf5fdda 100644 --- a/packages/backend/src/services/quota/checkers/__tests__/exedev-checker.test.ts +++ b/packages/backend/src/services/quota/checkers/__tests__/exedev-checker.test.ts @@ -95,7 +95,9 @@ describe('exedev checker', () => { async () => new Response('unauthorized', { status: 401, statusText: 'Unauthorized' }) ); - await expect(checkerDef.check(makeCtx())).rejects.toThrow('HTTP 401: Unauthorized'); + await expect(checkerDef.check(makeCtx())).rejects.toThrow( + 'HTTP 401: Unauthorized - unauthorized' + ); }); it('uses custom endpoint when provided', async () => { @@ -134,4 +136,15 @@ describe('exedev checker', () => { await expect(checkerDef.check(makeCtx())).rejects.toThrow('Invalid monthly_allowance_usd'); }); + + it('throws on negative monthly_allowance_usd', async () => { + setFetchMock( + async () => + new Response(JSON.stringify({ ...mockCreditsResponse, monthly_allowance_usd: -5 }), { + status: 200, + }) + ); + + await expect(checkerDef.check(makeCtx())).rejects.toThrow('Invalid monthly_allowance_usd'); + }); }); diff --git a/packages/backend/src/services/quota/checkers/exedev-checker.ts b/packages/backend/src/services/quota/checkers/exedev-checker.ts index 31f19680..e3913bac 100644 --- a/packages/backend/src/services/quota/checkers/exedev-checker.ts +++ b/packages/backend/src/services/quota/checkers/exedev-checker.ts @@ -9,30 +9,52 @@ interface ExeDevCreditsResponse { next_credit_reset: string; } +const MONTHS: Record = { + Jan: 0, + Feb: 1, + Mar: 2, + Apr: 3, + May: 4, + Jun: 5, + Jul: 6, + Aug: 7, + Sep: 8, + Oct: 9, + Nov: 10, + Dec: 11, +}; + function parseResetTimestamp(input: string): string { - // Format: "00:00 on Jun 1" → ISO 8601 const [time, datePart] = input.split(' on '); if (!time || !datePart) throw new Error(`Cannot parse next_credit_reset: "${input}"`); + const [hours, minutes] = time.split(':').map(Number); + const parts = datePart.trim().split(/\s+/); + if (parts.length < 2) throw new Error(`Cannot parse next_credit_reset: "${input}"`); + const [monthName, dayStr] = parts; + if (!monthName || !dayStr) throw new Error(`Cannot parse next_credit_reset: "${input}"`); + const monthIdx = MONTHS[monthName]; + const day = parseInt(dayStr, 10); + if (monthIdx === undefined || isNaN(day) || isNaN(hours!) || isNaN(minutes!)) + throw new Error(`Cannot parse next_credit_reset: "${input}"`); + const year = new Date().getUTCFullYear(); - let date = new Date(`${datePart}, ${year} ${time} UTC`); - if (isNaN(date.getTime())) throw new Error(`Cannot parse next_credit_reset: "${input}"`); - if (date < new Date()) date = new Date(`${datePart}, ${year + 1} ${time} UTC`); - return date.toISOString(); + let ts = Date.UTC(year, monthIdx, day, hours, minutes); + if (ts < Date.now()) ts = Date.UTC(year + 1, monthIdx, day, hours, minutes); + return new Date(ts).toISOString(); } export default defineChecker({ type: 'exedev', displayName: 'exe.dev', optionsSchema: z.object({ - apiKey: z.string().min(1, 'exe.dev API bearer token is required'), endpoint: z.string().url().optional(), }), async check(ctx) { const apiKey = ctx.requireOption('apiKey'); const endpoint = ctx.getOption('endpoint', 'https://exe.dev/exec'); - logger.silly(`Calling ${endpoint}`); + logger.silly(`[exedev] Calling ${endpoint}`); const response = await fetch(endpoint, { method: 'POST', @@ -43,7 +65,12 @@ export default defineChecker({ body: 'billing credits --json', }); - if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`); + if (!response.ok) { + const text = await response.text().catch(() => ''); + throw new Error( + `HTTP ${response.status}: ${response.statusText}${text ? ` - ${text.slice(0, 200)}` : ''}` + ); + } const data: ExeDevCreditsResponse = await response.json(); @@ -52,11 +79,11 @@ export default defineChecker({ const used = limit - remaining; const extraCredits = Number(data.extra_credits_left_usd); - if (!Number.isFinite(limit)) + if (!Number.isFinite(limit) || limit < 0) throw new Error(`Invalid monthly_allowance_usd: ${String(data.monthly_allowance_usd)}`); - if (!Number.isFinite(remaining)) + if (!Number.isFinite(remaining) || remaining < 0) throw new Error(`Invalid monthly_credits_left_usd: ${String(data.monthly_credits_left_usd)}`); - if (!Number.isFinite(extraCredits)) + if (!Number.isFinite(extraCredits) || extraCredits < 0) throw new Error(`Invalid extra_credits_left_usd: ${String(data.extra_credits_left_usd)}`); const resetsAt = data.next_credit_reset diff --git a/packages/frontend/src/components/quota/ExeDevQuotaConfig.tsx b/packages/frontend/src/components/quota/ExeDevQuotaConfig.tsx index dce72d84..abca1ae9 100644 --- a/packages/frontend/src/components/quota/ExeDevQuotaConfig.tsx +++ b/packages/frontend/src/components/quota/ExeDevQuotaConfig.tsx @@ -1,35 +1,36 @@ -import React from "react"; -import { Input } from "../ui/Input"; +import React from 'react'; +import { Input } from '../ui/Input'; export interface ExeDevQuotaConfigProps { options: Record; onChange: (options: Record) => void; } -export const ExeDevQuotaConfig: React.FC = ({ - options, - onChange, -}) => { - const handleChange = (key: string, value: string) => { - onChange({ ...options, [key]: value }); +export const ExeDevQuotaConfig: React.FC = ({ options, onChange }) => { + const handleChange = (key: string, value: string | undefined) => { + if (value !== undefined) { + onChange({ ...options, [key]: value }); + } else { + const { [key]: _, ...rest } = options; + onChange(rest); + } }; return (
- handleChange("apiKey", e.target.value)} - placeholder="Bearer token from exe.dev" - hint={`Generate with: ssh exe.dev ssh-key generate-api-key --cmds "'billing credits'" --label "'Plexus Quota Checker'"`} - /> - - handleChange("endpoint", e.target.value)} - placeholder="https://exe.dev/exec" - /> +
+ + handleChange('endpoint', e.target.value)} + placeholder="https://exe.dev/exec" + /> + + Custom endpoint URL. Defaults to exe.dev's exec endpoint. + +
); }; diff --git a/packages/frontend/src/components/quota/index.ts b/packages/frontend/src/components/quota/index.ts index 3a8acc02..8cd55fc8 100644 --- a/packages/frontend/src/components/quota/index.ts +++ b/packages/frontend/src/components/quota/index.ts @@ -4,6 +4,7 @@ export { WaferQuotaConfig } from './WaferQuotaConfig'; export { OpenCodeGoQuotaConfig } from './OpenCodeGoQuotaConfig'; export { RoutingRunQuotaConfig } from './RoutingRunQuotaConfig'; export { CrofQuotaConfig } from './CrofQuotaConfig'; +export { ExeDevQuotaConfig } from './ExeDevQuotaConfig'; export { CombinedBalancesCard } from './CombinedBalancesCard'; export { CompactBalancesCard } from './CompactBalancesCard'; export { CompactQuotasCard } from './CompactQuotasCard'; diff --git a/packages/frontend/src/hooks/useProviderForm.tsx b/packages/frontend/src/hooks/useProviderForm.tsx index e362839d..485299bc 100644 --- a/packages/frontend/src/hooks/useProviderForm.tsx +++ b/packages/frontend/src/hooks/useProviderForm.tsx @@ -767,8 +767,6 @@ export function useProviderForm() { return 'Session cookie is required for Wisdom Gate quota checker'; if (quotaType === 'devpass' && (!options.session || !(options.session as string).trim())) return 'Session cookie is required for DevPass quota checker'; - if (quotaType === 'exedev' && (!options.apiKey || !(options.apiKey as string).trim())) - return 'API bearer token is required for exe.dev quota checker'; if (quotaType === 'opencode-go') { if (!options.workspaceId || !(options.workspaceId as string).trim()) return 'Workspace ID is required for OpenCode Go quota checker'; diff --git a/scripts/dev.ts b/scripts/dev.ts index 37408ac2..81893084 100644 --- a/scripts/dev.ts +++ b/scripts/dev.ts @@ -241,23 +241,15 @@ console.log('Watching for changes...'); // --- Auto-open browser (unless --no-open) --- -function openBrowser(url: string): Promise { - return new Promise((resolve, reject) => { - let proc: ChildProcess; - if (process.platform === 'win32') { - proc = nodeSpawn('cmd', ['/c', 'start', '""', url], { detached: true, stdio: 'ignore' }); - } else { - proc = nodeSpawn(process.platform === 'darwin' ? 'open' : 'xdg-open', [url], { - detached: true, - stdio: 'ignore', - }); - } - proc.on('error', reject); - proc.on('spawn', () => { - proc.unref(); - resolve(); - }); - }); +function openBrowser(url: string) { + if (process.platform === 'win32') { + nodeSpawn('cmd', ['/c', 'start', '""', url], { detached: true, stdio: 'ignore' }).unref(); + } else { + nodeSpawn(process.platform === 'darwin' ? 'open' : 'xdg-open', [url], { + detached: true, + stdio: 'ignore', + }).unref(); + } } if (!noOpen) { @@ -267,7 +259,7 @@ if (!noOpen) { await waitForServer(); const url = `http://localhost:${process.env.PORT}/ui/login?token=${encodeURIComponent(process.env.ADMIN_KEY!)}`; console.log(`[dev] Server ready. Opening browser: ${url}`); - await openBrowser(url); + openBrowser(url); } catch (err) { console.error(`[dev] ${err instanceof Error ? err.message : err}. Not opening browser.`); }