pub mod json_fields {
pub mod claude {
pub const USAGE: &str = "usage";
pub const INPUT_TOKENS: &str = "input_tokens";
pub const OUTPUT_TOKENS: &str = "output_tokens";
pub const CONTENT: &str = "content";
pub const TYPE: &str = "type";
pub const TEXT: &str = "text";
}
pub mod titan {
pub const INPUT_TEXT_TOKEN_COUNT: &str = "inputTextTokenCount";
pub const RESULTS: &str = "results";
pub const TOKEN_COUNT: &str = "tokenCount";
pub const OUTPUT_TEXT: &str = "outputText";
}
pub mod llama {
pub const GENERATION_TOKEN_COUNT: &str = "generation_token_count";
pub const PROMPT_TOKEN_COUNT: &str = "prompt_token_count";
pub const GENERATION: &str = "generation";
}
pub mod jurassic {
pub const COMPLETIONS: &str = "completions";
pub const DATA: &str = "data";
pub const TOKENS: &str = "tokens";
pub const GENERATED_TOKENS: &str = "generated_tokens";
}
pub mod command {
pub const PROMPT_TOKENS: &str = "prompt_tokens";
pub const COMPLETION_TOKENS: &str = "completion_tokens";
}
pub mod common {
pub const MODEL: &str = "model";
pub const ERROR: &str = "error";
pub const MESSAGE: &str = "message";
pub const ID: &str = "id";
pub const TYPE: &str = "type";
}
}
pub mod paths {
pub mod bedrock {
pub const MODEL_SEGMENT: &str = "model";
pub const INVOKE_ENDPOINT: &str = "invoke";
pub const INVOKE_STREAM_ENDPOINT: &str = "invoke-with-response-stream";
pub const MODEL_PATH_PREFIX: &str = "/bedrock/model/";
}
}
pub mod http {
pub mod content_types {
pub const APPLICATION_JSON: &str = "application/json";
pub const APPLICATION_OCTET_STREAM: &str = "application/octet-stream";
pub const TEXT_EVENT_STREAM: &str = "text/event-stream";
pub const TEXT_PLAIN: &str = "text/plain";
pub const TEXT_HTML: &str = "text/html; charset=utf-8";
}
pub mod headers {
pub mod aws {
pub const AMZ_TARGET: &str = "x-amz-target";
pub const AMZ_DATE: &str = "x-amz-date";
pub const AMZ_SECURITY_TOKEN: &str = "x-amz-security-token";
pub const AMZ_CONTENT_SHA256: &str = "x-amz-content-sha256";
}
}
}
pub mod error_messages {
pub const DATABASE_HEALTH_CHECK_FAILED: &str = "Database health check failed";
pub const INVALID_MODEL_RESPONSE: &str = "Invalid model response format";
pub const MISSING_TOKEN_USAGE: &str = "Token usage information not found in response";
pub const AUTHENTICATION_FAILED: &str = "Authentication failed";
pub const INVALID_REQUEST_FORMAT: &str = "Invalid request format";
pub const INVALID_ERROR_MESSAGE: &str = "Invalid error message";
pub const UNKNOWN_FIELD: &str = "unknown_field";
pub const UNKNOWN_RESOURCE: &str = "unknown_resource";
}
pub mod sql {
pub const HEALTH_CHECK_QUERY: &str = "SELECT 1 as health_check";
pub const HEALTH_CHECK_COLUMN: &str = "health_check";
pub const HEALTH_CHECK_EXPECTED_VALUE: i32 = 1;
}
pub mod limits {
pub const MAX_CLAUDE_TOKENS: u32 = 200_000;
pub const MAX_TITAN_TOKENS: u32 = 8_000;
pub const MAX_LLAMA_TOKENS: u32 = 4_096;
pub const MAX_REQUEST_SIZE: usize = 10 * 1024 * 1024; pub const MAX_RESPONSE_SIZE: usize = 10 * 1024 * 1024; }
pub mod model_patterns {
pub const CLAUDE: &str = "claude";
pub const TITAN: &str = "titan";
pub const LLAMA: &str = "llama";
pub const JURASSIC_J2: &str = "j2";
pub const JURASSIC_FULL: &str = "jurassic";
pub const COMMAND: &str = "command";
pub const STABLE: &str = "stable";
}
pub mod provider_ids {
pub const BEDROCK: &str = "bedrock";
pub const OPENAI: &str = "openai";
pub const ANTHROPIC: &str = "anthropic";
pub const GOOGLE: &str = "google";
pub const AZURE: &str = "azure";
}
pub mod config_paths {
pub const DEFAULT: &str = "config/default";
pub const LOCAL: &str = "config/local";
pub const ENV_PREFIX: &str = "UNION_SQUARE";
pub const ENV_SEPARATOR: &str = "__";
}
pub mod migration_paths {
pub const MIGRATIONS_DIR: &str = "./migrations";
}
pub mod environments {
pub const PRODUCTION: &str = "production";
pub const STAGING: &str = "staging";
pub const DEVELOPMENT: &str = "development";
pub const QA: &str = "qa";
}
pub mod config_defaults {
pub const APP_HOST: &str = "0.0.0.0";
pub const APP_PORT: i64 = 8080;
pub const DB_HOST: &str = "localhost";
pub const DB_PORT: i64 = 5432;
pub const DB_USERNAME: &str = "postgres";
pub const DB_PASSWORD: &str = "password";
pub const DB_NAME: &str = "union_square";
pub const DB_MAX_CONNECTIONS: i64 = 10;
pub const EVENTCORE_BATCH_SIZE: i64 = 100;
pub const EVENTCORE_FLUSH_INTERVAL: i64 = 1000;
pub const LOG_LEVEL: &str = "info";
pub const LOG_FORMAT: &str = "json";
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_json_field_constants_have_expected_values() {
assert_eq!(json_fields::claude::USAGE, "usage");
assert_eq!(json_fields::claude::INPUT_TOKENS, "input_tokens");
assert_eq!(json_fields::claude::OUTPUT_TOKENS, "output_tokens");
assert_eq!(
json_fields::titan::INPUT_TEXT_TOKEN_COUNT,
"inputTextTokenCount"
);
assert_eq!(json_fields::titan::RESULTS, "results");
assert_eq!(json_fields::common::MODEL, "model");
assert_eq!(json_fields::common::ERROR, "error");
}
#[test]
fn test_path_constants_have_expected_values() {
assert_eq!(paths::bedrock::MODEL_SEGMENT, "model");
assert_eq!(paths::bedrock::INVOKE_ENDPOINT, "invoke");
assert_eq!(
paths::bedrock::INVOKE_STREAM_ENDPOINT,
"invoke-with-response-stream"
);
assert!(paths::bedrock::MODEL_PATH_PREFIX.starts_with('/'));
assert!(paths::bedrock::MODEL_PATH_PREFIX.ends_with('/'));
}
#[test]
fn test_sql_constants_have_expected_values() {
assert_eq!(sql::HEALTH_CHECK_QUERY, "SELECT 1 as health_check");
assert_eq!(sql::HEALTH_CHECK_COLUMN, "health_check");
assert_eq!(sql::HEALTH_CHECK_EXPECTED_VALUE, 1);
}
#[test]
fn test_http_constants_have_expected_values() {
assert_eq!(http::content_types::APPLICATION_JSON, "application/json");
assert_eq!(
http::content_types::APPLICATION_OCTET_STREAM,
"application/octet-stream"
);
assert_eq!(http::content_types::TEXT_EVENT_STREAM, "text/event-stream");
assert_eq!(http::content_types::TEXT_PLAIN, "text/plain");
assert_eq!(http::content_types::TEXT_HTML, "text/html; charset=utf-8");
assert_eq!(http::headers::aws::AMZ_TARGET, "x-amz-target");
}
#[test]
fn test_limits_have_expected_values() {
assert_eq!(limits::MAX_CLAUDE_TOKENS, 200_000);
assert_eq!(limits::MAX_TITAN_TOKENS, 8_000);
assert_eq!(limits::MAX_LLAMA_TOKENS, 4_096);
assert_eq!(limits::MAX_REQUEST_SIZE, limits::MAX_RESPONSE_SIZE);
assert_eq!(limits::MAX_REQUEST_SIZE, 10 * 1024 * 1024); }
#[test]
fn test_model_patterns_are_defined() {
assert_eq!(model_patterns::CLAUDE, "claude");
assert_eq!(model_patterns::TITAN, "titan");
assert_eq!(model_patterns::LLAMA, "llama");
assert_eq!(model_patterns::JURASSIC_J2, "j2");
assert_eq!(model_patterns::JURASSIC_FULL, "jurassic");
assert_eq!(model_patterns::COMMAND, "command");
assert_eq!(model_patterns::STABLE, "stable");
}
#[test]
fn test_provider_ids_are_defined() {
assert_eq!(provider_ids::BEDROCK, "bedrock");
assert_eq!(provider_ids::OPENAI, "openai");
assert_eq!(provider_ids::ANTHROPIC, "anthropic");
assert_eq!(provider_ids::GOOGLE, "google");
assert_eq!(provider_ids::AZURE, "azure");
}
#[test]
fn test_config_paths_are_defined() {
assert_eq!(config_paths::DEFAULT, "config/default");
assert_eq!(config_paths::LOCAL, "config/local");
assert_eq!(config_paths::ENV_PREFIX, "UNION_SQUARE");
assert_eq!(config_paths::ENV_SEPARATOR, "__");
}
#[test]
fn test_environments_are_defined() {
assert_eq!(environments::PRODUCTION, "production");
assert_eq!(environments::STAGING, "staging");
assert_eq!(environments::DEVELOPMENT, "development");
assert_eq!(environments::QA, "qa");
}
#[test]
fn test_config_defaults_are_reasonable() {
assert_eq!(config_defaults::APP_HOST, "0.0.0.0");
assert_eq!(config_defaults::APP_PORT, 8080);
assert_eq!(config_defaults::DB_HOST, "localhost");
assert_eq!(config_defaults::DB_PORT, 5432);
assert_eq!(config_defaults::DB_USERNAME, "postgres");
assert_eq!(config_defaults::DB_PASSWORD, "password");
assert_eq!(config_defaults::DB_NAME, "union_square");
assert_eq!(config_defaults::DB_MAX_CONNECTIONS, 10);
assert_eq!(config_defaults::EVENTCORE_BATCH_SIZE, 100);
assert_eq!(config_defaults::EVENTCORE_FLUSH_INTERVAL, 1000);
assert_eq!(config_defaults::LOG_LEVEL, "info");
assert_eq!(config_defaults::LOG_FORMAT, "json");
}
}