feat: i18n full support, responsive UI, multi-model AI config, and bug fixes
Major Features:
- Internationalization (i18n) with auto-detection for ES/EN/PT
- Mobile-first responsive design for Studio and Experience
- Multi-model AI configuration (llama3.2:3b, qwen3.5:9b, gpt-oss:latest)
- Course language configuration (auto-detect or fixed per course)
Backend Changes:
- shared/common: ModelType enum for intelligent model selection
- LMS: log_ai_usage function migration (fix chat tutor 500 error)
- LMS/CMS: course language config fields (language_setting, fixed_language)
- LMS: /courses/{id}/language-config endpoint for language detection
Frontend Changes:
- Experience: Enhanced i18n with browser language detection
- Experience: Audio recording with HTTPS check and error handling
- Studio: Memory game with unique pair IDs and debug logging
- Studio: Expanded translations (250+ keys for ES, EN, PT)
- Both: Language selector in headers (mobile responsive)
Documentation:
- AI_MODELS_CONFIG.md: Multi-model configuration guide
- RESPONSIVIDAD_GUIA.md: Mobile-first design patterns
- I18N_RESPONSIVIDAD_IMPLEMENTACION.md: Implementation details
- DEBUG_AUDIO_RECORDING.md: Audio troubleshooting guide
- DEBUG_MEMORY_GAME.md: Memory game debugging steps
Bug Fixes:
- Fix chat tutor 500 error (missing log_ai_usage function)
- Fix audio recording (HTTPS check, browser compatibility)
- Fix memory game pair IDs (unique ID generation)
- Fix HotspotBlock TypeScript errors
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
-- AI Usage Tracking: Add log_ai_usage function
|
||||
-- Required for chat with tutor and other AI features
|
||||
|
||||
-- Create ai_usage_logs table if not exists
|
||||
CREATE TABLE IF NOT EXISTS ai_usage_logs (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID NOT NULL,
|
||||
organization_id UUID NOT NULL,
|
||||
tokens_used INTEGER NOT NULL,
|
||||
input_tokens INTEGER NOT NULL,
|
||||
output_tokens INTEGER NOT NULL,
|
||||
endpoint VARCHAR(255) NOT NULL,
|
||||
model VARCHAR(100) NOT NULL,
|
||||
request_type VARCHAR(50) NOT NULL,
|
||||
request_metadata JSONB,
|
||||
estimated_cost_usd NUMERIC(10, 6),
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
prompt TEXT,
|
||||
response TEXT
|
||||
);
|
||||
|
||||
-- Create indexes for performance
|
||||
CREATE INDEX IF NOT EXISTS idx_ai_usage_logs_user_id ON ai_usage_logs(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_ai_usage_logs_org_id ON ai_usage_logs(organization_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_ai_usage_logs_created_at ON ai_usage_logs(created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_ai_usage_logs_endpoint ON ai_usage_logs(endpoint);
|
||||
|
||||
-- Create log_ai_usage function
|
||||
CREATE OR REPLACE FUNCTION log_ai_usage(
|
||||
p_user_id UUID,
|
||||
p_org_id UUID,
|
||||
p_tokens INTEGER,
|
||||
p_input_tokens INTEGER,
|
||||
p_output_tokens INTEGER,
|
||||
p_endpoint VARCHAR,
|
||||
p_model VARCHAR,
|
||||
p_request_type VARCHAR,
|
||||
p_metadata JSONB,
|
||||
p_prompt TEXT DEFAULT NULL,
|
||||
p_response TEXT DEFAULT NULL
|
||||
)
|
||||
RETURNS UUID AS $$
|
||||
DECLARE
|
||||
v_log_id UUID;
|
||||
v_cost NUMERIC(10, 6);
|
||||
BEGIN
|
||||
-- Calculate estimated cost (OpenAI-like pricing)
|
||||
v_cost := (p_input_tokens::NUMERIC * 0.000001) + (p_output_tokens::NUMERIC * 0.000003);
|
||||
|
||||
INSERT INTO ai_usage_logs (
|
||||
user_id, organization_id, tokens_used, input_tokens, output_tokens,
|
||||
endpoint, model, request_type, request_metadata, estimated_cost_usd,
|
||||
prompt, response
|
||||
)
|
||||
VALUES (
|
||||
p_user_id, p_org_id, p_tokens, p_input_tokens, p_output_tokens,
|
||||
p_endpoint, p_model, p_request_type, p_metadata, v_cost,
|
||||
p_prompt, p_response
|
||||
)
|
||||
RETURNING id INTO v_log_id;
|
||||
|
||||
RETURN v_log_id;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
COMMENT ON COLUMN ai_usage_logs.prompt IS 'The actual prompt sent to the AI model';
|
||||
COMMENT ON COLUMN ai_usage_logs.response IS 'The AI model response content';
|
||||
@@ -0,0 +1,24 @@
|
||||
-- Add language configuration to courses table (LMS side)
|
||||
-- This mirrors the CMS migration for cross-service compatibility
|
||||
|
||||
ALTER TABLE courses
|
||||
ADD COLUMN IF NOT EXISTS language_setting VARCHAR(20) DEFAULT 'auto',
|
||||
ADD COLUMN IF NOT EXISTS fixed_language VARCHAR(5) DEFAULT NULL;
|
||||
|
||||
-- Add comment explaining the fields
|
||||
COMMENT ON COLUMN courses.language_setting IS 'Language mode: auto (detect from user browser) or fixed (use fixed_language)';
|
||||
COMMENT ON COLUMN courses.fixed_language IS 'Fixed language code (es, en, pt) when language_setting is fixed. NULL when language_setting is auto.';
|
||||
|
||||
-- Add check constraints (only if they don't exist)
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE courses ADD CONSTRAINT chk_language_setting CHECK (language_setting IN ('auto', 'fixed'));
|
||||
EXCEPTION WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE courses ADD CONSTRAINT chk_fixed_language CHECK (fixed_language IS NULL OR fixed_language IN ('es', 'en', 'pt'));
|
||||
EXCEPTION WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
|
||||
-- Create index for filtering courses by language
|
||||
CREATE INDEX IF NOT EXISTS idx_courses_language ON courses(language_setting, fixed_language);
|
||||
Reference in New Issue
Block a user