From 0910a6bd3500577d40e93e0fb04fde181f48b5cf Mon Sep 17 00:00:00 2001 From: Matt Cowger Date: Sun, 24 May 2026 17:14:47 -0700 Subject: [PATCH] feat(debug): add HTTP request/response headers and status to trace logs Closes #444 - Add requestHeaders, responseHeaders, responseStatus columns to debug_logs - Capture sanitized request headers in startLog() across all route handlers - Capture response metadata via addResponseMeta() at all dispatch paths - Extract sanitize-headers utility from dispatcher private method - Add Request Headers and Response Headers accordion panels in frontend - Include new fields in debug log export/download payloads - Add DB migrations for SQLite and Postgres --- .../0046_add_debug_log_http_metadata.sql | 3 + .../migrations/meta/0046_snapshot.json | 3034 ++++++++++++++++ .../drizzle/migrations/meta/_journal.json | 7 + .../0059_add_debug_log_http_metadata.sql | 3 + .../migrations_pg/meta/0059_snapshot.json | 3192 +++++++++++++++++ .../drizzle/migrations_pg/meta/_journal.json | 7 + .../drizzle/schema/postgres/debug-logs.ts | 5 +- .../drizzle/schema/sqlite/debug-logs.ts | 3 + packages/backend/src/routes/inference/chat.ts | 3 +- .../src/routes/inference/embeddings.ts | 3 +- .../backend/src/routes/inference/gemini.ts | 3 +- .../backend/src/routes/inference/images.ts | 39 +- .../backend/src/routes/inference/messages.ts | 3 +- .../backend/src/routes/inference/responses.ts | 3 +- .../backend/src/routes/inference/speech.ts | 23 +- .../src/routes/inference/transcriptions.ts | 25 +- .../__tests__/debug-manager-metadata.test.ts | 60 + .../backend/src/services/debug-manager.ts | 22 +- packages/backend/src/services/dispatcher.ts | 112 +- .../backend/src/services/usage-storage.ts | 44 +- .../src/utils/__tests__/provider-cost.test.ts | 49 +- .../utils/__tests__/sanitize-headers.test.ts | 73 + packages/backend/src/utils/provider-cost.ts | 4 +- .../backend/src/utils/sanitize-headers.ts | 36 + .../backend/src/utils/usage-normalizer.ts | 3 +- packages/frontend/src/pages/Debug.tsx | 20 + scripts/deploy-staging.ts | 63 +- 27 files changed, 6720 insertions(+), 122 deletions(-) create mode 100644 packages/backend/drizzle/migrations/0046_add_debug_log_http_metadata.sql create mode 100644 packages/backend/drizzle/migrations/meta/0046_snapshot.json create mode 100644 packages/backend/drizzle/migrations_pg/0059_add_debug_log_http_metadata.sql create mode 100644 packages/backend/drizzle/migrations_pg/meta/0059_snapshot.json create mode 100644 packages/backend/src/services/__tests__/debug-manager-metadata.test.ts create mode 100644 packages/backend/src/utils/__tests__/sanitize-headers.test.ts create mode 100644 packages/backend/src/utils/sanitize-headers.ts diff --git a/packages/backend/drizzle/migrations/0046_add_debug_log_http_metadata.sql b/packages/backend/drizzle/migrations/0046_add_debug_log_http_metadata.sql new file mode 100644 index 00000000..576ce5c2 --- /dev/null +++ b/packages/backend/drizzle/migrations/0046_add_debug_log_http_metadata.sql @@ -0,0 +1,3 @@ +ALTER TABLE `debug_logs` ADD `request_headers` text;--> statement-breakpoint +ALTER TABLE `debug_logs` ADD `response_headers` text;--> statement-breakpoint +ALTER TABLE `debug_logs` ADD `response_status` integer; \ No newline at end of file diff --git a/packages/backend/drizzle/migrations/meta/0046_snapshot.json b/packages/backend/drizzle/migrations/meta/0046_snapshot.json new file mode 100644 index 00000000..2c37baf6 --- /dev/null +++ b/packages/backend/drizzle/migrations/meta/0046_snapshot.json @@ -0,0 +1,3034 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "5a247000-369e-46c6-881b-b66ffabd9fdc", + "prevId": "14f82022-e9fa-4b30-be7b-e9a763cdb862", + "tables": { + "meter_snapshots": { + "name": "meter_snapshots", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "checker_id": { + "name": "checker_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "checker_type": { + "name": "checker_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "meter_key": { + "name": "meter_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "group": { + "name": "group", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "limit": { + "name": "limit", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "used": { + "name": "used", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "remaining": { + "name": "remaining", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "utilization_state": { + "name": "utilization_state", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "utilization_percent": { + "name": "utilization_percent", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "period_value": { + "name": "period_value", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "period_unit": { + "name": "period_unit", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "period_cycle": { + "name": "period_cycle", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "resets_at": { + "name": "resets_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "success": { + "name": "success", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "checked_at": { + "name": "checked_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "idx_meter_checker_meter_checked": { + "name": "idx_meter_checker_meter_checked", + "columns": [ + "checker_id", + "meter_key", + "checked_at" + ], + "isUnique": false + }, + "idx_meter_provider_checked": { + "name": "idx_meter_provider_checked", + "columns": [ + "provider", + "checked_at" + ], + "isUnique": false + }, + "idx_meter_checked_at": { + "name": "idx_meter_checked_at", + "columns": [ + "checked_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "request_usage": { + "name": "request_usage", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "source_ip": { + "name": "source_ip", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "attribution": { + "name": "attribution", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "incoming_api_type": { + "name": "incoming_api_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "attempt_count": { + "name": "attempt_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "retry_history": { + "name": "retry_history", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "incoming_model_alias": { + "name": "incoming_model_alias", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "canonical_model_name": { + "name": "canonical_model_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "selected_model_name": { + "name": "selected_model_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "final_attempt_provider": { + "name": "final_attempt_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "final_attempt_model": { + "name": "final_attempt_model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "all_attempted_providers": { + "name": "all_attempted_providers", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "outgoing_api_type": { + "name": "outgoing_api_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tokens_input": { + "name": "tokens_input", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tokens_output": { + "name": "tokens_output", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tokens_reasoning": { + "name": "tokens_reasoning", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tokens_cached": { + "name": "tokens_cached", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tokens_cache_write": { + "name": "tokens_cache_write", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost_input": { + "name": "cost_input", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost_output": { + "name": "cost_output", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost_cached": { + "name": "cost_cached", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost_cache_write": { + "name": "cost_cache_write", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost_total": { + "name": "cost_total", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost_source": { + "name": "cost_source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost_metadata": { + "name": "cost_metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "start_time": { + "name": "start_time", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ttft_ms": { + "name": "ttft_ms", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tokens_per_sec": { + "name": "tokens_per_sec", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_streamed": { + "name": "is_streamed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "is_passthrough": { + "name": "is_passthrough", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "response_status": { + "name": "response_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tokens_estimated": { + "name": "tokens_estimated", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tools_defined": { + "name": "tools_defined", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "message_count": { + "name": "message_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "parallel_tool_calls_enabled": { + "name": "parallel_tool_calls_enabled", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_calls_count": { + "name": "tool_calls_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "finish_reason": { + "name": "finish_reason", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_vision_fallthrough": { + "name": "is_vision_fallthrough", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "is_descriptor_request": { + "name": "is_descriptor_request", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "vision_fallthrough_model": { + "name": "vision_fallthrough_model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "kwh_used": { + "name": "kwh_used", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider_reported_cost": { + "name": "provider_reported_cost", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "request_usage_request_id_unique": { + "name": "request_usage_request_id_unique", + "columns": [ + "request_id" + ], + "isUnique": true + }, + "idx_request_usage_date": { + "name": "idx_request_usage_date", + "columns": [ + "date" + ], + "isUnique": false + }, + "idx_request_usage_provider": { + "name": "idx_request_usage_provider", + "columns": [ + "provider" + ], + "isUnique": false + }, + "idx_request_usage_request_id": { + "name": "idx_request_usage_request_id", + "columns": [ + "request_id" + ], + "isUnique": false + }, + "idx_request_usage_api_key": { + "name": "idx_request_usage_api_key", + "columns": [ + "api_key", + "start_time" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "provider_cooldowns": { + "name": "provider_cooldowns", + "columns": { + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expiry": { + "name": "expiry", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "idx_cooldowns_expiry": { + "name": "idx_cooldowns_expiry", + "columns": [ + "expiry" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "provider_cooldowns_provider_model_pk": { + "columns": [ + "provider", + "model" + ], + "name": "provider_cooldowns_provider_model_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "debug_logs": { + "name": "debug_logs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "raw_request": { + "name": "raw_request", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "transformed_request": { + "name": "transformed_request", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "raw_response": { + "name": "raw_response", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "transformed_response": { + "name": "transformed_response", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "raw_response_snapshot": { + "name": "raw_response_snapshot", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "transformed_response_snapshot": { + "name": "transformed_response_snapshot", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "request_headers": { + "name": "request_headers", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "response_headers": { + "name": "response_headers", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "response_status": { + "name": "response_status", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "idx_debug_logs_request_id": { + "name": "idx_debug_logs_request_id", + "columns": [ + "request_id" + ], + "isUnique": false + }, + "idx_debug_logs_created_at": { + "name": "idx_debug_logs_created_at", + "columns": [ + "created_at" + ], + "isUnique": false + }, + "idx_debug_logs_api_key": { + "name": "idx_debug_logs_api_key", + "columns": [ + "api_key" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "inference_errors": { + "name": "inference_errors", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error_stack": { + "name": "error_stack", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "details": { + "name": "details", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "idx_errors_request_id": { + "name": "idx_errors_request_id", + "columns": [ + "request_id" + ], + "isUnique": false + }, + "idx_errors_date": { + "name": "idx_errors_date", + "columns": [ + "date" + ], + "isUnique": false + }, + "idx_inference_errors_api_key": { + "name": "idx_inference_errors_api_key", + "columns": [ + "api_key" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "provider_performance": { + "name": "provider_performance", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "canonical_model_name": { + "name": "canonical_model_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_to_first_token_ms": { + "name": "time_to_first_token_ms", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "total_tokens": { + "name": "total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tokens_per_sec": { + "name": "tokens_per_sec", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "e2e_tokens_per_sec": { + "name": "e2e_tokens_per_sec", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "failure_count": { + "name": "failure_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "success_count": { + "name": "success_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "idx_provider_performance_lookup": { + "name": "idx_provider_performance_lookup", + "columns": [ + "provider", + "model", + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "quota_snapshots": { + "name": "quota_snapshots", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "checker_id": { + "name": "checker_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "group_id": { + "name": "group_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "window_type": { + "name": "window_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "checked_at": { + "name": "checked_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "limit": { + "name": "limit", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "used": { + "name": "used", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "remaining": { + "name": "remaining", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "utilization_percent": { + "name": "utilization_percent", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "resets_at": { + "name": "resets_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "success": { + "name": "success", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "idx_quota_provider_checked": { + "name": "idx_quota_provider_checked", + "columns": [ + "provider", + "checked_at" + ], + "isUnique": false + }, + "idx_quota_checker_window": { + "name": "idx_quota_checker_window", + "columns": [ + "checker_id", + "window_type", + "checked_at" + ], + "isUnique": false + }, + "idx_quota_group_window": { + "name": "idx_quota_group_window", + "columns": [ + "group_id", + "window_type", + "checked_at" + ], + "isUnique": false + }, + "idx_quota_checked_at": { + "name": "idx_quota_checked_at", + "columns": [ + "checked_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "conversations": { + "name": "conversations", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "plexus_account_id": { + "name": "plexus_account_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "idx_conversations_updated": { + "name": "idx_conversations_updated", + "columns": [ + "updated_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "response_items": { + "name": "response_items", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "response_id": { + "name": "response_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "item_index": { + "name": "item_index", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "item_type": { + "name": "item_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "item_data": { + "name": "item_data", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "idx_response_items_response": { + "name": "idx_response_items_response", + "columns": [ + "response_id", + "item_index" + ], + "isUnique": false + }, + "idx_response_items_type": { + "name": "idx_response_items_type", + "columns": [ + "item_type" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "responses": { + "name": "responses", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "object": { + "name": "object", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "completed_at": { + "name": "completed_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "output_items": { + "name": "output_items", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "instructions": { + "name": "instructions", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "temperature": { + "name": "temperature", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "top_p": { + "name": "top_p", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "max_output_tokens": { + "name": "max_output_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "top_logprobs": { + "name": "top_logprobs", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "parallel_tool_calls": { + "name": "parallel_tool_calls", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_choice": { + "name": "tool_choice", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tools": { + "name": "tools", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "text_config": { + "name": "text_config", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reasoning_config": { + "name": "reasoning_config", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "usage_input_tokens": { + "name": "usage_input_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "usage_output_tokens": { + "name": "usage_output_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "usage_reasoning_tokens": { + "name": "usage_reasoning_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "usage_cached_tokens": { + "name": "usage_cached_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "usage_total_tokens": { + "name": "usage_total_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "previous_response_id": { + "name": "previous_response_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "conversation_id": { + "name": "conversation_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "store": { + "name": "store", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "background": { + "name": "background", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "truncation": { + "name": "truncation", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "incomplete_details": { + "name": "incomplete_details", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "safety_identifier": { + "name": "safety_identifier", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "service_tier": { + "name": "service_tier", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "prompt_cache_key": { + "name": "prompt_cache_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "prompt_cache_retention": { + "name": "prompt_cache_retention", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "plexus_provider": { + "name": "plexus_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "plexus_target_model": { + "name": "plexus_target_model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "plexus_api_type": { + "name": "plexus_api_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "plexus_canonical_model": { + "name": "plexus_canonical_model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "idx_responses_conversation": { + "name": "idx_responses_conversation", + "columns": [ + "conversation_id" + ], + "isUnique": false + }, + "idx_responses_created_at": { + "name": "idx_responses_created_at", + "columns": [ + "created_at" + ], + "isUnique": false + }, + "idx_responses_status": { + "name": "idx_responses_status", + "columns": [ + "status" + ], + "isUnique": false + }, + "idx_responses_previous": { + "name": "idx_responses_previous", + "columns": [ + "previous_response_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcp_debug_logs": { + "name": "mcp_debug_logs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "raw_request_headers": { + "name": "raw_request_headers", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "raw_request_body": { + "name": "raw_request_body", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "raw_response_headers": { + "name": "raw_response_headers", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "raw_response_body": { + "name": "raw_response_body", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "mcp_debug_logs_request_id_unique": { + "name": "mcp_debug_logs_request_id_unique", + "columns": [ + "request_id" + ], + "isUnique": true + }, + "idx_mcp_debug_logs_request_id": { + "name": "idx_mcp_debug_logs_request_id", + "columns": [ + "request_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcp_request_usage": { + "name": "mcp_request_usage", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "start_time": { + "name": "start_time", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "server_name": { + "name": "server_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "upstream_url": { + "name": "upstream_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "method": { + "name": "method", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "jsonrpc_method": { + "name": "jsonrpc_method", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool_name": { + "name": "tool_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "attribution": { + "name": "attribution", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_ip": { + "name": "source_ip", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "response_status": { + "name": "response_status", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_streamed": { + "name": "is_streamed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "has_debug": { + "name": "has_debug", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "error_code": { + "name": "error_code", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "mcp_request_usage_request_id_unique": { + "name": "mcp_request_usage_request_id_unique", + "columns": [ + "request_id" + ], + "isUnique": true + }, + "idx_mcp_request_usage_server_name": { + "name": "idx_mcp_request_usage_server_name", + "columns": [ + "server_name" + ], + "isUnique": false + }, + "idx_mcp_request_usage_created_at": { + "name": "idx_mcp_request_usage_created_at", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "quota_state": { + "name": "quota_state", + "columns": { + "key_name": { + "name": "key_name", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "quota_name": { + "name": "quota_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "limit_type": { + "name": "limit_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "current_usage": { + "name": "current_usage", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "last_updated": { + "name": "last_updated", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "window_start": { + "name": "window_start", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "providers": { + "name": "providers", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "api_base_url": { + "name": "api_base_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "api_key": { + "name": "api_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "oauth_provider_type": { + "name": "oauth_provider_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "oauth_credential_id": { + "name": "oauth_credential_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "disable_cooldown": { + "name": "disable_cooldown", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "stall_cooldown": { + "name": "stall_cooldown", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "discount": { + "name": "discount", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "estimate_tokens": { + "name": "estimate_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "use_claude_masking": { + "name": "use_claude_masking", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "gemini_thinking_enabled": { + "name": "gemini_thinking_enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "headers": { + "name": "headers", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "extra_body": { + "name": "extra_body", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "quota_checker_type": { + "name": "quota_checker_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "quota_checker_id": { + "name": "quota_checker_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "quota_checker_enabled": { + "name": "quota_checker_enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "quota_checker_interval": { + "name": "quota_checker_interval", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 30 + }, + "quota_checker_options": { + "name": "quota_checker_options", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gpu_profile": { + "name": "gpu_profile", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gpu_ram_gb": { + "name": "gpu_ram_gb", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gpu_bandwidth_tb_s": { + "name": "gpu_bandwidth_tb_s", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gpu_flops_tflop": { + "name": "gpu_flops_tflop", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gpu_power_draw_watts": { + "name": "gpu_power_draw_watts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "adapter": { + "name": "adapter", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "timeout_ms": { + "name": "timeout_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stall_ttfb_ms": { + "name": "stall_ttfb_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stall_ttfb_bytes": { + "name": "stall_ttfb_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stall_min_bps": { + "name": "stall_min_bps", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stall_window_ms": { + "name": "stall_window_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stall_grace_period_ms": { + "name": "stall_grace_period_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "max_concurrency": { + "name": "max_concurrency", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "providers_slug_unique": { + "name": "providers_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + }, + "idx_providers_slug": { + "name": "idx_providers_slug", + "columns": [ + "slug" + ], + "isUnique": false + } + }, + "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": {}, + "checkConstraints": {} + }, + "provider_models": { + "name": "provider_models", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "provider_id": { + "name": "provider_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "model_name": { + "name": "model_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "pricing_config": { + "name": "pricing_config", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model_type": { + "name": "model_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_via": { + "name": "access_via", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "extra_body": { + "name": "extra_body", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "adapter": { + "name": "adapter", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "max_concurrency": { + "name": "max_concurrency", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": { + "uq_provider_models": { + "name": "uq_provider_models", + "columns": [ + "provider_id", + "model_name" + ], + "isUnique": true + } + }, + "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": {}, + "checkConstraints": {} + }, + "model_aliases": { + "name": "model_aliases", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "selector": { + "name": "selector", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "priority": { + "name": "priority", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'selector'" + }, + "model_type": { + "name": "model_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "additional_aliases": { + "name": "additional_aliases", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "advanced": { + "name": "advanced", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "metadata_source": { + "name": "metadata_source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "metadata_source_path": { + "name": "metadata_source_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "use_image_fallthrough": { + "name": "use_image_fallthrough", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "model_architecture": { + "name": "model_architecture", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enforce_limits": { + "name": "enforce_limits", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "sticky_session": { + "name": "sticky_session", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "preferred_api": { + "name": "preferred_api", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pi_model": { + "name": "pi_model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_groups": { + "name": "target_groups", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "extra_body": { + "name": "extra_body", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "model_aliases_slug_unique": { + "name": "model_aliases_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "model_alias_targets": { + "name": "model_alias_targets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "alias_id": { + "name": "alias_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider_slug": { + "name": "provider_slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "model_name": { + "name": "model_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "group_name": { + "name": "group_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": { + "uq_alias_targets": { + "name": "uq_alias_targets", + "columns": [ + "alias_id", + "provider_slug", + "model_name" + ], + "isUnique": true + } + }, + "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": {}, + "checkConstraints": {} + }, + "alias_metadata_overrides": { + "name": "alias_metadata_overrides", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "alias_id": { + "name": "alias_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "context_length": { + "name": "context_length", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pricing_prompt": { + "name": "pricing_prompt", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pricing_completion": { + "name": "pricing_completion", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pricing_input_cache_read": { + "name": "pricing_input_cache_read", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pricing_input_cache_write": { + "name": "pricing_input_cache_write", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "architecture_input_modalities": { + "name": "architecture_input_modalities", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "architecture_output_modalities": { + "name": "architecture_output_modalities", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "architecture_tokenizer": { + "name": "architecture_tokenizer", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "supported_parameters": { + "name": "supported_parameters", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "top_provider_context_length": { + "name": "top_provider_context_length", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "top_provider_max_completion_tokens": { + "name": "top_provider_max_completion_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "uq_alias_metadata_overrides": { + "name": "uq_alias_metadata_overrides", + "columns": [ + "alias_id" + ], + "isUnique": true + } + }, + "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": {}, + "checkConstraints": {} + }, + "api_keys": { + "name": "api_keys", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "secret_hash": { + "name": "secret_hash", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "quota_name": { + "name": "quota_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "allowed_models": { + "name": "allowed_models", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "allowed_providers": { + "name": "allowed_providers", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "excluded_models": { + "name": "excluded_models", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "excluded_providers": { + "name": "excluded_providers", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "api_keys_name_unique": { + "name": "api_keys_name_unique", + "columns": [ + "name" + ], + "isUnique": true + }, + "api_keys_secret_unique": { + "name": "api_keys_secret_unique", + "columns": [ + "secret" + ], + "isUnique": true + }, + "api_keys_secret_hash_unique": { + "name": "api_keys_secret_hash_unique", + "columns": [ + "secret_hash" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user_quota_definitions": { + "name": "user_quota_definitions", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "quota_type": { + "name": "quota_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "limit_type": { + "name": "limit_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "limit_value": { + "name": "limit_value", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "duration": { + "name": "duration", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "user_quota_definitions_name_unique": { + "name": "user_quota_definitions_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcp_servers": { + "name": "mcp_servers", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "upstream_url": { + "name": "upstream_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "headers": { + "name": "headers", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "mcp_servers_name_unique": { + "name": "mcp_servers_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "system_settings": { + "name": "system_settings", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "oauth_credentials": { + "name": "oauth_credentials", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "oauth_provider_type": { + "name": "oauth_provider_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "uq_oauth_credentials": { + "name": "uq_oauth_credentials", + "columns": [ + "oauth_provider_type", + "account_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/packages/backend/drizzle/migrations/meta/_journal.json b/packages/backend/drizzle/migrations/meta/_journal.json index 44bf9a0f..d5336fb2 100644 --- a/packages/backend/drizzle/migrations/meta/_journal.json +++ b/packages/backend/drizzle/migrations/meta/_journal.json @@ -323,6 +323,13 @@ "when": 1779130552887, "tag": "0045_add_alias_extra_body", "breakpoints": true + }, + { + "idx": 46, + "version": "6", + "when": 1779666862601, + "tag": "0046_add_debug_log_http_metadata", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/backend/drizzle/migrations_pg/0059_add_debug_log_http_metadata.sql b/packages/backend/drizzle/migrations_pg/0059_add_debug_log_http_metadata.sql new file mode 100644 index 00000000..96198c29 --- /dev/null +++ b/packages/backend/drizzle/migrations_pg/0059_add_debug_log_http_metadata.sql @@ -0,0 +1,3 @@ +ALTER TABLE "debug_logs" ADD COLUMN "request_headers" text;--> statement-breakpoint +ALTER TABLE "debug_logs" ADD COLUMN "response_headers" text;--> statement-breakpoint +ALTER TABLE "debug_logs" ADD COLUMN "response_status" integer; \ No newline at end of file diff --git a/packages/backend/drizzle/migrations_pg/meta/0059_snapshot.json b/packages/backend/drizzle/migrations_pg/meta/0059_snapshot.json new file mode 100644 index 00000000..27f138a5 --- /dev/null +++ b/packages/backend/drizzle/migrations_pg/meta/0059_snapshot.json @@ -0,0 +1,3192 @@ +{ + "id": "c922c2c7-46bb-4d36-8dd3-20d4e20ec9b1", + "prevId": "77c83238-560f-4b35-9048-4a55fcbbd0fb", + "version": "7", + "dialect": "postgresql", + "tables": { + "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.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.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 + }, + "request_headers": { + "name": "request_headers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "response_headers": { + "name": "response_headers", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "response_status": { + "name": "response_status", + "type": "integer", + "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.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.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_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.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.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_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.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.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.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.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.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.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.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.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.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.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.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 + }, + "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 + } + }, + "enums": { + "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.model_type": { + "name": "model_type", + "schema": "public", + "values": [ + "chat", + "embeddings", + "transcriptions", + "speech", + "image", + "responses" + ] + }, + "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" + ] + }, + "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" + ] + } + }, + "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 7eb5cc52..5e0c62b1 100644 --- a/packages/backend/drizzle/migrations_pg/meta/_journal.json +++ b/packages/backend/drizzle/migrations_pg/meta/_journal.json @@ -414,6 +414,13 @@ "when": 1779665076807, "tag": "0058_test_setup", "breakpoints": true + }, + { + "idx": 59, + "version": "7", + "when": 1779666862922, + "tag": "0059_add_debug_log_http_metadata", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/backend/drizzle/schema/postgres/debug-logs.ts b/packages/backend/drizzle/schema/postgres/debug-logs.ts index ebc07754..ef274a4e 100644 --- a/packages/backend/drizzle/schema/postgres/debug-logs.ts +++ b/packages/backend/drizzle/schema/postgres/debug-logs.ts @@ -1,4 +1,4 @@ -import { pgTable, serial, text, bigint, index } from 'drizzle-orm/pg-core'; +import { pgTable, serial, text, bigint, integer, index } from 'drizzle-orm/pg-core'; export const debugLogs = pgTable( 'debug_logs', @@ -12,6 +12,9 @@ export const debugLogs = pgTable( transformedResponse: text('transformed_response'), rawResponseSnapshot: text('raw_response_snapshot'), transformedResponseSnapshot: text('transformed_response_snapshot'), + requestHeaders: text('request_headers'), + responseHeaders: text('response_headers'), + responseStatus: integer('response_status'), createdAt: bigint('created_at', { mode: 'number' }).notNull(), }, (table) => ({ diff --git a/packages/backend/drizzle/schema/sqlite/debug-logs.ts b/packages/backend/drizzle/schema/sqlite/debug-logs.ts index fd9c6569..8977e9ec 100644 --- a/packages/backend/drizzle/schema/sqlite/debug-logs.ts +++ b/packages/backend/drizzle/schema/sqlite/debug-logs.ts @@ -13,6 +13,9 @@ export const debugLogs = sqliteTable( transformedResponse: text('transformed_response'), rawResponseSnapshot: text('raw_response_snapshot'), transformedResponseSnapshot: text('transformed_response_snapshot'), + requestHeaders: text('request_headers'), + responseHeaders: text('response_headers'), + responseStatus: integer('response_status'), createdAt: integer('created_at').notNull(), }, (table) => ({ diff --git a/packages/backend/src/routes/inference/chat.ts b/packages/backend/src/routes/inference/chat.ts index 47c871d7..874ae8ef 100644 --- a/packages/backend/src/routes/inference/chat.ts +++ b/packages/backend/src/routes/inference/chat.ts @@ -12,6 +12,7 @@ import { checkQuotaMiddleware } from '../../services/quota/quota-middleware'; import { attachKeyAccessPolicy } from '../../utils/auth'; import { wireUpstreamTimeout, wireEarlyDisconnectDetection } from '../../utils/timeout'; import { wireStallDetection, getGlobalStallConfig } from '../../utils/stall'; +import { sanitizeHeaders } from '../../utils/sanitize-headers'; export async function registerChatRoute( fastify: FastifyInstance, @@ -81,7 +82,7 @@ export async function registerChatRoute( }; } - DebugManager.getInstance().startLog(requestId, body); + DebugManager.getInstance().startLog(requestId, body, sanitizeHeaders(request.headers as any)); // Check quota before processing if (quotaEnforcer) { diff --git a/packages/backend/src/routes/inference/embeddings.ts b/packages/backend/src/routes/inference/embeddings.ts index c0b84ec9..cee1765b 100644 --- a/packages/backend/src/routes/inference/embeddings.ts +++ b/packages/backend/src/routes/inference/embeddings.ts @@ -8,6 +8,7 @@ import { getClientIp } from '../../utils/ip'; import { calculateCosts } from '../../utils/calculate-costs'; import { DebugManager } from '../../services/debug-manager'; import { attachKeyAccessPolicy } from '../../utils/auth'; +import { sanitizeHeaders } from '../../utils/sanitize-headers'; export async function registerEmbeddingsRoute( fastify: FastifyInstance, @@ -60,7 +61,7 @@ export async function registerEmbeddingsRoute( unifiedRequest.requestId = requestId; unifiedRequest = attachKeyAccessPolicy(request, unifiedRequest); - DebugManager.getInstance().startLog(requestId, body); + DebugManager.getInstance().startLog(requestId, body, sanitizeHeaders(request.headers as any)); const unifiedResponse = await dispatcher.dispatchEmbeddings(unifiedRequest); diff --git a/packages/backend/src/routes/inference/gemini.ts b/packages/backend/src/routes/inference/gemini.ts index b128e618..17d986a3 100644 --- a/packages/backend/src/routes/inference/gemini.ts +++ b/packages/backend/src/routes/inference/gemini.ts @@ -12,6 +12,7 @@ import { checkQuotaMiddleware } from '../../services/quota/quota-middleware'; import { attachKeyAccessPolicy } from '../../utils/auth'; import { wireUpstreamTimeout, wireEarlyDisconnectDetection } from '../../utils/timeout'; import { wireStallDetection, getGlobalStallConfig } from '../../utils/stall'; +import { sanitizeHeaders } from '../../utils/sanitize-headers'; export async function registerGeminiRoute( fastify: FastifyInstance, @@ -85,7 +86,7 @@ export async function registerGeminiRoute( }; } - DebugManager.getInstance().startLog(requestId, body); + DebugManager.getInstance().startLog(requestId, body, sanitizeHeaders(request.headers as any)); // Check quota before processing if (quotaEnforcer) { diff --git a/packages/backend/src/routes/inference/images.ts b/packages/backend/src/routes/inference/images.ts index 9c026d7f..8bf6ddaf 100644 --- a/packages/backend/src/routes/inference/images.ts +++ b/packages/backend/src/routes/inference/images.ts @@ -9,6 +9,7 @@ import { calculateCosts } from '../../utils/calculate-costs'; import { DebugManager } from '../../services/debug-manager'; import { UnifiedImageGenerationRequest, UnifiedImageEditRequest } from '../../types/unified'; import { attachKeyAccessPolicy } from '../../utils/auth'; +import { sanitizeHeaders } from '../../utils/sanitize-headers'; export async function registerImagesRoute( fastify: FastifyInstance, @@ -72,13 +73,17 @@ export async function registerImagesRoute( }; unifiedRequest = attachKeyAccessPolicy(request, unifiedRequest); - DebugManager.getInstance().startLog(requestId, { - model: body.model, - prompt: body.prompt?.substring(0, 100), - n: body.n, - size: body.size, - response_format: body.response_format, - }); + DebugManager.getInstance().startLog( + requestId, + { + model: body.model, + prompt: body.prompt?.substring(0, 100), + n: body.n, + size: body.size, + response_format: body.response_format, + }, + sanitizeHeaders(request.headers as any) + ); const unifiedResponse = await dispatcher.dispatchImageGenerations(unifiedRequest); @@ -241,14 +246,18 @@ export async function registerImagesRoute( }; unifiedRequest = attachKeyAccessPolicy(request, unifiedRequest); - DebugManager.getInstance().startLog(requestId, { - model: formFields.model, - prompt: formFields.prompt?.substring(0, 100), - filename: imageFilename, - hasMask: !!maskBuffer, - n: formFields.n, - size: formFields.size, - }); + DebugManager.getInstance().startLog( + requestId, + { + model: formFields.model, + prompt: formFields.prompt?.substring(0, 100), + filename: imageFilename, + hasMask: !!maskBuffer, + n: formFields.n, + size: formFields.size, + }, + sanitizeHeaders(request.headers as any) + ); const unifiedResponse = await dispatcher.dispatchImageEdits(unifiedRequest); diff --git a/packages/backend/src/routes/inference/messages.ts b/packages/backend/src/routes/inference/messages.ts index 862bf70c..359f969b 100644 --- a/packages/backend/src/routes/inference/messages.ts +++ b/packages/backend/src/routes/inference/messages.ts @@ -12,6 +12,7 @@ import { checkQuotaMiddleware } from '../../services/quota/quota-middleware'; import { attachKeyAccessPolicy } from '../../utils/auth'; import { wireUpstreamTimeout, wireEarlyDisconnectDetection } from '../../utils/timeout'; import { wireStallDetection, getGlobalStallConfig } from '../../utils/stall'; +import { sanitizeHeaders } from '../../utils/sanitize-headers'; export async function registerMessagesRoute( fastify: FastifyInstance, @@ -79,7 +80,7 @@ export async function registerMessagesRoute( }; } - DebugManager.getInstance().startLog(requestId, body); + DebugManager.getInstance().startLog(requestId, body, sanitizeHeaders(request.headers as any)); // Check quota before processing if (quotaEnforcer) { diff --git a/packages/backend/src/routes/inference/responses.ts b/packages/backend/src/routes/inference/responses.ts index 7122aef8..58b2dc19 100644 --- a/packages/backend/src/routes/inference/responses.ts +++ b/packages/backend/src/routes/inference/responses.ts @@ -13,6 +13,7 @@ import { checkQuotaMiddleware } from '../../services/quota/quota-middleware'; import { attachKeyAccessPolicy } from '../../utils/auth'; import { wireUpstreamTimeout, wireEarlyDisconnectDetection } from '../../utils/timeout'; import { wireStallDetection, getGlobalStallConfig } from '../../utils/stall'; +import { sanitizeHeaders } from '../../utils/sanitize-headers'; export async function registerResponsesRoute( fastify: FastifyInstance, @@ -162,7 +163,7 @@ export async function registerResponsesRoute( }; } - DebugManager.getInstance().startLog(requestId, body); + DebugManager.getInstance().startLog(requestId, body, sanitizeHeaders(request.headers as any)); // Check quota before processing if (quotaEnforcer) { diff --git a/packages/backend/src/routes/inference/speech.ts b/packages/backend/src/routes/inference/speech.ts index ea466c54..d5ecdee1 100644 --- a/packages/backend/src/routes/inference/speech.ts +++ b/packages/backend/src/routes/inference/speech.ts @@ -9,6 +9,7 @@ import { calculateCosts } from '../../utils/calculate-costs'; import { DebugManager } from '../../services/debug-manager'; import { UnifiedSpeechRequest } from '../../types/unified'; import { attachKeyAccessPolicy } from '../../utils/auth'; +import { sanitizeHeaders } from '../../utils/sanitize-headers'; const VALID_VOICES = [ 'alloy', @@ -89,15 +90,19 @@ export async function registerSpeechRoute( }; unifiedRequest = attachKeyAccessPolicy(request, unifiedRequest); - DebugManager.getInstance().startLog(requestId, { - model: body.model, - voice: body.voice, - inputLength: body.input?.length || 0, - response_format: body.response_format, - speed: body.speed, - stream_format: body.stream_format, - instructions: body.instructions ? '(provided)' : undefined, - }); + DebugManager.getInstance().startLog( + requestId, + { + model: body.model, + voice: body.voice, + inputLength: body.input?.length || 0, + response_format: body.response_format, + speed: body.speed, + stream_format: body.stream_format, + instructions: body.instructions ? '(provided)' : undefined, + }, + sanitizeHeaders(request.headers as any) + ); const unifiedResponse = await dispatcher.dispatchSpeech(unifiedRequest); diff --git a/packages/backend/src/routes/inference/transcriptions.ts b/packages/backend/src/routes/inference/transcriptions.ts index 631f6a93..ec3fb1aa 100644 --- a/packages/backend/src/routes/inference/transcriptions.ts +++ b/packages/backend/src/routes/inference/transcriptions.ts @@ -9,6 +9,7 @@ import { calculateCosts } from '../../utils/calculate-costs'; import { DebugManager } from '../../services/debug-manager'; import { UnifiedTranscriptionRequest } from '../../types/unified'; import { attachKeyAccessPolicy } from '../../utils/auth'; +import { sanitizeHeaders } from '../../utils/sanitize-headers'; export async function registerTranscriptionsRoute( fastify: FastifyInstance, @@ -133,16 +134,20 @@ export async function registerTranscriptionsRoute( attribution: (request as any).attribution || null, }); - DebugManager.getInstance().startLog(requestId, { - model, - filename: fileData.filename, - fileSize, - mimeType: fileData.mimetype, - language, - prompt: prompt ? '(provided)' : undefined, - response_format, - temperature, - }); + DebugManager.getInstance().startLog( + requestId, + { + model, + filename: fileData.filename, + fileSize, + mimeType: fileData.mimetype, + language, + prompt: prompt ? '(provided)' : undefined, + response_format, + temperature, + }, + sanitizeHeaders(request.headers as any) + ); // Dispatch const unifiedResponse = await dispatcher.dispatchTranscription(unifiedRequest); diff --git a/packages/backend/src/services/__tests__/debug-manager-metadata.test.ts b/packages/backend/src/services/__tests__/debug-manager-metadata.test.ts new file mode 100644 index 00000000..1b656468 --- /dev/null +++ b/packages/backend/src/services/__tests__/debug-manager-metadata.test.ts @@ -0,0 +1,60 @@ +import { describe, expect, test, beforeEach } from 'vitest'; +import { DebugManager } from '../debug-manager'; + +describe('DebugManager HTTP metadata', () => { + let debugManager: DebugManager; + + beforeEach(() => { + debugManager = DebugManager.getInstance(); + debugManager.setEnabled(true); + debugManager.resetForTesting?.(); + }); + + test('startLog stores requestHeaders in dedicated field', () => { + const requestId = 'test-req-headers'; + const headers = { 'content-type': 'application/json', authorization: 'Bea***' }; + + debugManager.startLog(requestId, { model: 'gpt-4' }, headers); + + const log = debugManager.getPendingLog?.(requestId); + expect(log).toBeDefined(); + expect(log?.requestHeaders).toEqual(headers); + expect(log?.rawRequest).toEqual({ model: 'gpt-4' }); + }); + + test('startLog works without requestHeaders', () => { + const requestId = 'test-no-headers'; + debugManager.startLog(requestId, { model: 'gpt-4' }); + + const log = debugManager.getPendingLog?.(requestId); + expect(log).toBeDefined(); + expect(log?.requestHeaders).toBeUndefined(); + expect(log?.rawRequest).toEqual({ model: 'gpt-4' }); + }); + + test('addResponseMeta stores status and headers', () => { + const requestId = 'test-resp-meta'; + const respHeaders = { 'content-type': 'application/json', 'x-request-id': 'abc' }; + + debugManager.startLog(requestId, { test: 'data' }); + debugManager.addResponseMeta(requestId, 200, respHeaders); + + const log = debugManager.getPendingLog?.(requestId); + expect(log?.responseStatus).toBe(200); + expect(log?.responseHeaders).toEqual(respHeaders); + }); + + test('addResponseMeta does not overwrite rawResponseSnapshot', () => { + const requestId = 'test-no-wrap'; + const body = { id: '123', choices: [] }; + + debugManager.startLog(requestId, { test: 'data' }); + debugManager.addResponseMeta(requestId, 200, { 'content-type': 'application/json' }); + debugManager.addReconstructedRawResponse(requestId, body); + + const log = debugManager.getPendingLog?.(requestId); + expect(log?.rawResponseSnapshot).toEqual(body); + expect(log?.responseStatus).toBe(200); + expect(log?.responseHeaders).toEqual({ 'content-type': 'application/json' }); + }); +}); diff --git a/packages/backend/src/services/debug-manager.ts b/packages/backend/src/services/debug-manager.ts index 83ab0ecd..f0503cec 100644 --- a/packages/backend/src/services/debug-manager.ts +++ b/packages/backend/src/services/debug-manager.ts @@ -13,6 +13,9 @@ export interface DebugLogRecord { transformedResponse?: any; rawResponseSnapshot?: any; transformedResponseSnapshot?: any; + requestHeaders?: Record; + responseHeaders?: Record; + responseStatus?: number; provider?: string; createdAt?: number; } @@ -105,12 +108,13 @@ export class DebugManager { } // ─── Log capture ──────────────────────────────────────────────── - startLog(requestId: string, rawRequest: any) { + startLog(requestId: string, rawRequest: any, requestHeaders?: Record) { if (!this.isCaptureEnabled()) return; this.pendingLogs.set(requestId, { requestId, apiKey: getCurrentKeyName() ?? null, rawRequest, + requestHeaders, createdAt: Date.now(), }); @@ -171,6 +175,13 @@ export class DebugManager { log.transformedResponseSnapshot = payload; } + addResponseMeta(requestId: string, status: number, headers: Record) { + if (!this.isCaptureEnabled()) return; + const log = this.ensureLog(requestId); + log.responseStatus = status; + log.responseHeaders = headers; + } + flush(requestId: string) { // Skip flushing ephemeral requests if (this.ephemeralRequests.has(requestId)) { @@ -240,4 +251,13 @@ export class DebugManager { logger.debug(`Discarded ephemeral data for ${requestId}`); } } + + resetForTesting(): void { + this.pendingLogs.clear(); + this.ephemeralRequests.clear(); + } + + getPendingLog(requestId: string): DebugLogRecord | undefined { + return this.pendingLogs.get(requestId); + } } diff --git a/packages/backend/src/services/dispatcher.ts b/packages/backend/src/services/dispatcher.ts index f80967bb..6b9d3cb9 100644 --- a/packages/backend/src/services/dispatcher.ts +++ b/packages/backend/src/services/dispatcher.ts @@ -37,6 +37,7 @@ import { calculateCosts } from '../utils/calculate-costs'; import { resolveModelParams, DEFAULT_GPU_PARAMS } from '@plexus/shared'; import type { GpuParams, ModelParams } from '@plexus/shared'; import { ConcurrencyTracker } from './concurrency-tracker'; +import { sanitizeHeaders } from '../utils/sanitize-headers'; interface RetryAttemptRecord { index: number; @@ -2823,7 +2824,7 @@ export class Dispatcher { targetModel: route.model, targetApiType: targetApiType, url: url, - headers: this.sanitizeHeaders(headers || {}), + headers: sanitizeHeaders(headers || {}), statusCode: response.status, providerResponse: errorText, providerResponseHeaders: this.extractResponseHeaders(response), @@ -2832,6 +2833,11 @@ export class Dispatcher { // Capture the raw error response for debug logs if (requestId) { + DebugManager.getInstance().addResponseMeta( + requestId, + response.status, + this.extractResponseHeaders(response) + ); DebugManager.getInstance().addRawResponse(requestId, errorText); } @@ -2849,42 +2855,6 @@ export class Dispatcher { return headers; } - /** - * Sanitize headers to remove sensitive information before logging - */ - private sanitizeHeaders(headers: Record): Record { - const sanitized = { ...headers }; - - // Mask sensitive headers - if (sanitized['x-api-key']) { - sanitized['x-api-key'] = this.maskSecret(sanitized['x-api-key']); - } - if (sanitized['Authorization']) { - sanitized['Authorization'] = this.maskSecret(sanitized['Authorization']); - } - if (sanitized['x-goog-api-key']) { - sanitized['x-goog-api-key'] = this.maskSecret(sanitized['x-goog-api-key']); - } - - return sanitized; - } - - /** - * Mask secret values, showing only first and last few characters - */ - private maskSecret(value: string): string { - if (value.length <= 8) return '***'; - - // For Bearer tokens, preserve the "Bearer " prefix - if (value.startsWith('Bearer ')) { - const token = value.substring(7); - if (token.length <= 8) return 'Bearer ***'; - return `Bearer ${token.substring(0, 4)}...${token.substring(token.length - 4)}`; - } - - return `${value.substring(0, 4)}...${value.substring(value.length - 4)}`; - } - /** * Enriches response with Plexus metadata */ @@ -2917,6 +2887,15 @@ export class Dispatcher { ): UnifiedChatResponse { logger.debug('Streaming response detected'); + // Capture response metadata for debug logging + if (request.requestId) { + DebugManager.getInstance().addResponseMeta( + request.requestId, + response.status, + this.extractResponseHeaders(response) + ); + } + let rawStream: ReadableStream = response.body!; // If any adapter defines preDispatchStreamChunk, pipe the raw SSE stream @@ -2993,6 +2972,15 @@ export class Dispatcher { bypassTransformation: boolean, adapters: ResolvedAdapter[] = [] ): Promise { + // Capture response metadata for debug logging + if (request.requestId) { + DebugManager.getInstance().addResponseMeta( + request.requestId, + response.status, + this.extractResponseHeaders(response) + ); + } + let responseBody = await this.parseJsonResponseBody( response, request.requestId, @@ -3015,6 +3003,11 @@ export class Dispatcher { } if (request.requestId) { + DebugManager.getInstance().addResponseMeta( + request.requestId, + response.status, + this.extractResponseHeaders(response) + ); DebugManager.getInstance().addRawResponse(request.requestId, responseBody); } @@ -3154,6 +3147,15 @@ export class Dispatcher { const response = await this.executeProviderRequest(url, headers, payload); + // Capture response metadata for debug logging + if (request.requestId) { + DebugManager.getInstance().addResponseMeta( + request.requestId, + response.status, + this.extractResponseHeaders(response) + ); + } + if (!response.ok) { const errorText = await response.text(); logger.error(`Embeddings request failed: ${url}`, { @@ -3385,6 +3387,15 @@ export class Dispatcher { body: formData, }); + // Capture response metadata for debug logging + if (request.requestId) { + DebugManager.getInstance().addResponseMeta( + request.requestId, + response.status, + this.extractResponseHeaders(response) + ); + } + if (!response.ok) { const errorText = await response.text(); const canRetry = @@ -3625,6 +3636,15 @@ export class Dispatcher { body: JSON.stringify(payload), }); + // Capture response metadata for debug logging + if (request.requestId) { + DebugManager.getInstance().addResponseMeta( + request.requestId, + response.status, + this.extractResponseHeaders(response) + ); + } + if (!response.ok) { const errorText = await response.text(); const canRetry = @@ -3900,6 +3920,15 @@ export class Dispatcher { body: JSON.stringify(payload), }); + // Capture response metadata for debug logging + if (request.requestId) { + DebugManager.getInstance().addResponseMeta( + request.requestId, + response.status, + this.extractResponseHeaders(response) + ); + } + if (!response.ok) { const errorText = await response.text(); const canRetry = @@ -4122,6 +4151,15 @@ export class Dispatcher { body: formData, }); + // Capture response metadata for debug logging + if (request.requestId) { + DebugManager.getInstance().addResponseMeta( + request.requestId, + response.status, + this.extractResponseHeaders(response) + ); + } + if (!response.ok) { const errorText = await response.text(); const canRetry = diff --git a/packages/backend/src/services/usage-storage.ts b/packages/backend/src/services/usage-storage.ts index 6bff8393..1936e1a7 100644 --- a/packages/backend/src/services/usage-storage.ts +++ b/packages/backend/src/services/usage-storage.ts @@ -261,37 +261,26 @@ export class UsageStorageService extends EventEmitter { async saveDebugLog(record: DebugLogRecord) { try { + const serialize = (data: any): string | null => { + if (!data) return null; + if (typeof data === 'string') return data; + return JSON.stringify(data); + }; + await this.ensureDb() .insert(this.schema.debugLogs) .values({ requestId: record.requestId, apiKey: record.apiKey ?? null, - rawRequest: record.rawRequest - ? typeof record.rawRequest === 'string' - ? record.rawRequest - : JSON.stringify(record.rawRequest) - : null, - transformedRequest: record.transformedRequest - ? typeof record.transformedRequest === 'string' - ? record.transformedRequest - : JSON.stringify(record.transformedRequest) - : null, - rawResponse: record.rawResponse - ? typeof record.rawResponse === 'string' - ? record.rawResponse - : JSON.stringify(record.rawResponse) - : null, - transformedResponse: record.transformedResponse - ? typeof record.transformedResponse === 'string' - ? record.transformedResponse - : JSON.stringify(record.transformedResponse) - : null, - rawResponseSnapshot: record.rawResponseSnapshot - ? JSON.stringify(record.rawResponseSnapshot) - : null, - transformedResponseSnapshot: record.transformedResponseSnapshot - ? JSON.stringify(record.transformedResponseSnapshot) - : null, + rawRequest: serialize(record.rawRequest), + transformedRequest: serialize(record.transformedRequest), + rawResponse: serialize(record.rawResponse), + transformedResponse: serialize(record.transformedResponse), + rawResponseSnapshot: serialize(record.rawResponseSnapshot), + transformedResponseSnapshot: serialize(record.transformedResponseSnapshot), + requestHeaders: serialize(record.requestHeaders), + responseHeaders: serialize(record.responseHeaders), + responseStatus: record.responseStatus ?? null, createdAt: record.createdAt || Date.now(), }); @@ -471,6 +460,9 @@ export class UsageStorageService extends EventEmitter { transformedResponse: row.transformedResponse, rawResponseSnapshot: row.rawResponseSnapshot, transformedResponseSnapshot: row.transformedResponseSnapshot, + requestHeaders: row.requestHeaders, + responseHeaders: row.responseHeaders, + responseStatus: row.responseStatus, }; } catch (error) { logger.error(`Failed to get debug log for ${requestId}`, error); diff --git a/packages/backend/src/utils/__tests__/provider-cost.test.ts b/packages/backend/src/utils/__tests__/provider-cost.test.ts index c738bbb4..6f94b175 100644 --- a/packages/backend/src/utils/__tests__/provider-cost.test.ts +++ b/packages/backend/src/utils/__tests__/provider-cost.test.ts @@ -440,7 +440,12 @@ describe('extractUsageCostDetails', () => { completion_tokens: 131, total_tokens: 285, cost: 0.0003287, - prompt_tokens_details: { cached_tokens: 128, cache_write_tokens: 0, audio_tokens: 0, video_tokens: 0 }, + prompt_tokens_details: { + cached_tokens: 128, + cache_write_tokens: 0, + audio_tokens: 0, + video_tokens: 0, + }, completion_tokens_details: { reasoning_tokens: 87, image_tokens: 0, audio_tokens: 0 }, }; @@ -458,8 +463,18 @@ describe('extractUsageCostDetails', () => { prompt_tokens: 165, completion_tokens: 2, total_tokens: 296, - prompt_tokens_details: { text_tokens: 165, audio_tokens: 0, image_tokens: 0, cached_tokens: 164 }, - completion_tokens_details: { reasoning_tokens: 129, audio_tokens: 0, accepted_prediction_tokens: 0, rejected_prediction_tokens: 0 }, + prompt_tokens_details: { + text_tokens: 165, + audio_tokens: 0, + image_tokens: 0, + cached_tokens: 164, + }, + completion_tokens_details: { + reasoning_tokens: 129, + audio_tokens: 0, + accepted_prediction_tokens: 0, + rejected_prediction_tokens: 0, + }, num_sources_used: 0, cost_in_usd_ticks: 739000, }; @@ -1264,7 +1279,12 @@ describe('extractUsageCostDetails - real-world cassette shapes', () => { total_tokens: 750, cost: 0.001322, is_byok: false, - prompt_tokens_details: { cached_tokens: 0, cache_write_tokens: 0, audio_tokens: 0, video_tokens: 0 }, + prompt_tokens_details: { + cached_tokens: 0, + cache_write_tokens: 0, + audio_tokens: 0, + video_tokens: 0, + }, cost_details: { upstream_inference_cost: 0.001322, upstream_inference_prompt_cost: 0.000607, @@ -1288,7 +1308,12 @@ describe('extractUsageCostDetails - real-world cassette shapes', () => { total_tokens: 193, cost: 0.00008825, is_byok: false, - prompt_tokens_details: { cached_tokens: 0, cache_write_tokens: 0, audio_tokens: 0, video_tokens: 0 }, + prompt_tokens_details: { + cached_tokens: 0, + cache_write_tokens: 0, + audio_tokens: 0, + video_tokens: 0, + }, cost_details: { upstream_inference_cost: 0.00008825, upstream_inference_prompt_cost: 0.00004025, @@ -1312,7 +1337,12 @@ describe('extractUsageCostDetails - real-world cassette shapes', () => { total_tokens: 351, cost: 0.0006228, is_byok: false, - prompt_tokens_details: { cached_tokens: 0, cache_write_tokens: 0, audio_tokens: 0, video_tokens: 0 }, + prompt_tokens_details: { + cached_tokens: 0, + cache_write_tokens: 0, + audio_tokens: 0, + video_tokens: 0, + }, cost_details: { upstream_inference_cost: 0.0006228, upstream_inference_prompt_cost: 0.0003348, @@ -1333,7 +1363,12 @@ describe('extractUsageCostDetails - real-world cassette shapes', () => { total_tokens: 167, cost: 0.0000901, is_byok: false, - prompt_tokens_details: { cached_tokens: 0, cache_write_tokens: 0, audio_tokens: 0, video_tokens: 0 }, + prompt_tokens_details: { + cached_tokens: 0, + cache_write_tokens: 0, + audio_tokens: 0, + video_tokens: 0, + }, cost_details: { upstream_inference_cost: 0.0000901, upstream_inference_prompt_cost: 0.0000226, diff --git a/packages/backend/src/utils/__tests__/sanitize-headers.test.ts b/packages/backend/src/utils/__tests__/sanitize-headers.test.ts new file mode 100644 index 00000000..224400c9 --- /dev/null +++ b/packages/backend/src/utils/__tests__/sanitize-headers.test.ts @@ -0,0 +1,73 @@ +import { describe, expect, test } from 'vitest'; +import { sanitizeHeaders } from '../sanitize-headers'; + +describe('sanitizeHeaders', () => { + test('masks authorization header', () => { + const result = sanitizeHeaders({ + authorization: 'Bearer sk-1234567890abcdef', + 'content-type': 'application/json', + }); + expect(result['authorization']).toBe('Bearer sk-1...cdef'); + expect(result['content-type']).toBe('application/json'); + }); + + test('masks x-api-key header', () => { + const result = sanitizeHeaders({ + 'x-api-key': 'my-long-api-key-value', + }); + expect(result['x-api-key']).toBe('my-l...alue'); + }); + + test('masks short secrets as ***', () => { + const result = sanitizeHeaders({ + 'x-api-key': 'short', + }); + expect(result['x-api-key']).toBe('***'); + }); + + test('masks short bearer tokens', () => { + const result = sanitizeHeaders({ + authorization: 'Bearer short', + }); + expect(result['authorization']).toBe('Bearer ***'); + }); + + test('handles undefined values', () => { + const result = sanitizeHeaders({ + 'content-type': 'application/json', + 'x-api-key': undefined, + }); + expect(result['content-type']).toBe('application/json'); + expect(result).not.toHaveProperty('x-api-key'); + }); + + test('handles array values for sensitive headers', () => { + const result = sanitizeHeaders({ + cookie: ['session=abc12345678', 'token=xyz98765432'], + }); + expect(Array.isArray(result['cookie'])).toBe(true); + expect((result['cookie'] as string[])[0]).toBe('sess...5678'); + }); + + test('masks api-key and x-goog-api-key', () => { + const result = sanitizeHeaders({ + 'api-key': 'my-secret-key-value-here', + 'x-goog-api-key': 'google-secret-key-val', + }); + expect(result['api-key']).toBe('my-s...here'); + expect(result['x-goog-api-key']).toBe('goog...-val'); + }); + + test('preserves non-sensitive headers', () => { + const result = sanitizeHeaders({ + 'content-type': 'application/json', + accept: 'text/html', + 'x-request-id': 'abc-123', + }); + expect(result).toEqual({ + 'content-type': 'application/json', + accept: 'text/html', + 'x-request-id': 'abc-123', + }); + }); +}); diff --git a/packages/backend/src/utils/provider-cost.ts b/packages/backend/src/utils/provider-cost.ts index ac6f7eb7..357a0683 100644 --- a/packages/backend/src/utils/provider-cost.ts +++ b/packages/backend/src/utils/provider-cost.ts @@ -132,7 +132,9 @@ export function applyUsageCostDetails( if (prevPromptTotal > 0) { usageRecord.costInput = Number(((prevInput / prevPromptTotal) * promptTotal).toFixed(8)); usageRecord.costCached = Number(((prevCached / prevPromptTotal) * promptTotal).toFixed(8)); - usageRecord.costCacheWrite = Number(((prevCacheWrite / prevPromptTotal) * promptTotal).toFixed(8)); + usageRecord.costCacheWrite = Number( + ((prevCacheWrite / prevPromptTotal) * promptTotal).toFixed(8) + ); } else { // No prior breakdown — attribute full prompt cost to input usageRecord.costInput = Number(promptTotal.toFixed(8)); diff --git a/packages/backend/src/utils/sanitize-headers.ts b/packages/backend/src/utils/sanitize-headers.ts new file mode 100644 index 00000000..8db75f29 --- /dev/null +++ b/packages/backend/src/utils/sanitize-headers.ts @@ -0,0 +1,36 @@ +const SENSITIVE_HEADERS = ['authorization', 'x-api-key', 'x-goog-api-key', 'api-key', 'cookie']; + +export function sanitizeHeaders( + headers: Record +): Record { + const sanitized: Record = {}; + + for (const [key, value] of Object.entries(headers)) { + if (value === undefined) continue; + + const lowerKey = key.toLowerCase(); + if (SENSITIVE_HEADERS.some((h) => lowerKey === h || lowerKey.includes(h))) { + if (Array.isArray(value)) { + sanitized[key] = value.map((v) => maskSecret(v)); + } else { + sanitized[key] = maskSecret(value); + } + } else { + sanitized[key] = value; + } + } + + return sanitized; +} + +function maskSecret(value: string): string { + if (value.length <= 8) return '***'; + + if (value.startsWith('Bearer ')) { + const token = value.substring(7); + if (token.length <= 8) return 'Bearer ***'; + return `Bearer ${token.substring(0, 4)}...${token.substring(token.length - 4)}`; + } + + return `${value.substring(0, 4)}...${value.substring(value.length - 4)}`; +} diff --git a/packages/backend/src/utils/usage-normalizer.ts b/packages/backend/src/utils/usage-normalizer.ts index c686f5e6..d80197e7 100644 --- a/packages/backend/src/utils/usage-normalizer.ts +++ b/packages/backend/src/utils/usage-normalizer.ts @@ -170,7 +170,8 @@ export function normalizeOpenAIResponsesUsage(usage: any): UsageSubset { input_tokens: inputTokens, output_tokens: outputTokens, total_tokens: - safeToken(usage?.total_tokens) || inputTokens + cachedTokens + cacheWriteTokens + outputTokens, + safeToken(usage?.total_tokens) || + inputTokens + cachedTokens + cacheWriteTokens + outputTokens, reasoning_tokens: reasoningTokens, cached_tokens: cachedTokens, cache_creation_tokens: cacheWriteTokens, diff --git a/packages/frontend/src/pages/Debug.tsx b/packages/frontend/src/pages/Debug.tsx index d82efdc9..ce576ed1 100644 --- a/packages/frontend/src/pages/Debug.tsx +++ b/packages/frontend/src/pages/Debug.tsx @@ -37,6 +37,9 @@ interface DebugLogDetail extends DebugLogMeta { transformedResponse: string | object; rawResponseSnapshot?: string | object; transformedResponseSnapshot?: string | object; + requestHeaders?: string | object; + responseHeaders?: string | object; + responseStatus?: number; } export const Debug: React.FC = () => { @@ -241,6 +244,9 @@ export const Debug: React.FC = () => { rawResponseSnapshot: normalizeExportContent(detail.rawResponseSnapshot), transformedResponse: normalizeExportContent(detail.transformedResponse), transformedResponseSnapshot: normalizeExportContent(detail.transformedResponseSnapshot), + requestHeaders: normalizeExportContent(detail.requestHeaders), + responseHeaders: normalizeExportContent(detail.responseHeaders), + responseStatus: detail.responseStatus, }; return JSON.stringify(payload, null, 2); }, [detail]); @@ -471,6 +477,13 @@ export const Debug: React.FC = () => { color="text-blue-400" defaultOpen={true} /> + {detail.requestHeaders && ( + + )} { color="text-orange-400" /> )} + {detail.responseHeaders && ( + + )} n.trim()) + .filter(Boolean); + if (names.length === 1) return names[0]!; + if (names.length > 1) { + console.warn(` ⚠️ Multiple containers match (plexus:staging-latest): ${names.join(', ')}`); + console.warn(` Using first: ${names[0]}`); + return names[0]!; + } + } + + const fallbackResult = spawnSync( + 'docker', + ['--context', CTX, 'ps', '-a', '--format', '{{.Names}}\t{{.Image}}'], + { encoding: 'utf-8' } + ); + const lines = (fallbackResult.stdout ?? '').trim().split('\n').filter(Boolean); + for (const line of lines) { + const [name, image] = line.split('\t'); + if (name && image?.startsWith('plexus:')) return name; + } + + return 'Plexus'; +} + +const CONTAINER_NAME = resolveContainerName(); + // Timestamp-based tag — works for uncommitted work, always sortable const now = new Date(); const TIMESTAMP = [ @@ -133,7 +180,9 @@ console.log('╚═════════════════════ console.log(); console.log(` Docker context: ${CTX}`); console.log(` Staging URL: ${STAGING_URL}`); -console.log(` Container: ${CONTAINER_NAME}`); +console.log( + ` Container: ${CONTAINER_NAME}${process.env.PLEXUS_STAGING_CONTAINER_NAME ? '' : ' (auto-detected)'}` +); console.log(` New image tag: ${NEW_TAG}`); console.log(); @@ -213,11 +262,9 @@ if (inspectResult.success && inspectResult.stdout) { if (info) { previousImage = info.Config?.Image ?? null; - // Reconstruct a docker run command from the live container config const parts: string[] = [`docker --context ${CTX} run -d`]; parts.push(` --name ${CONTAINER_NAME}`); - // Restart policy const restartPolicy = info.HostConfig?.RestartPolicy?.Name; if (restartPolicy && restartPolicy !== 'no') { const maxRetries = info.HostConfig.RestartPolicy.MaximumRetryCount; @@ -226,7 +273,6 @@ if (inspectResult.success && inspectResult.stdout) { parts.push(` --restart ${policyStr}`); } - // Port bindings const portBindings = info.HostConfig?.PortBindings ?? {}; for (const [containerPort, bindings] of Object.entries(portBindings)) { for (const binding of (bindings as any[]) ?? []) { @@ -237,7 +283,6 @@ if (inspectResult.success && inspectResult.stdout) { } } - // Mounts / volumes const mounts = info.Mounts ?? []; for (const m of mounts) { if (m.Type === 'bind') { @@ -249,7 +294,6 @@ if (inspectResult.success && inspectResult.stdout) { } } - // Environment variables (skip internal Docker bookkeeping vars) const skipEnvPrefixes = ['PATH=', 'HOSTNAME=', 'HOME=']; const envVars: string[] = info.Config?.Env ?? []; for (const e of envVars) { @@ -285,10 +329,10 @@ docker(['build', '--build-arg', `APP_VERSION=${TIMESTAMP}`, '-t', NEW_TAG, '-t', console.log(` ✓ Built ${NEW_TAG}`); // --------------------------------------------------------------------------- -// Phase 4: Deploy via Watchtower --run-once +// Phase 4: Deploy via Watchtower --run-once --no-pull // --------------------------------------------------------------------------- -step(4, 'Deploy via Watchtower --run-once'); +step(4, 'Deploy via Watchtower --run-once --no-pull'); docker( [ @@ -298,6 +342,7 @@ docker( '/var/run/docker.sock:/var/run/docker.sock', 'containrrr/watchtower', '--run-once', + '--no-pull', CONTAINER_NAME, ], { fatal: true }