Spaces:
Configuration error
Configuration error
| /** | |
| * src/config/runtime.ts — RuntimeConfig | |
| * Source of truth unica per tutti i default runtime, limiti e feature flags. | |
| * | |
| * NON duplicare questi valori in altri file. | |
| * Importa sempre da qui, mai hardcodarli altrove. | |
| */ | |
| import { ENV } from "./env"; | |
| // ─── Endpoints ────────────────────────────────────────────────────────────── | |
| export const ENDPOINTS = { | |
| HF_ROUTER: "https://router.huggingface.co/v1/chat/completions", | |
| HF_INFERENCE: "https://api-inference.huggingface.co/models", | |
| GROQ: "https://api.groq.com/openai/v1/chat/completions", | |
| OPENROUTER: "https://openrouter.ai/api/v1/chat/completions", | |
| OPENAI: "https://api.openai.com/v1/chat/completions", | |
| TOGETHER: "https://api.together.xyz/v1/chat/completions", | |
| GEMINI_BASE: "https://generativelanguage.googleapis.com", | |
| LOCAL_BACKEND: ENV.BACKEND_URL || "http://localhost:8000", | |
| // S325: Cerebras — 2000+ tok/s su Llama 3.3 70B, 1M tok/giorno gratis, free tier | |
| CEREBRAS: "https://api.cerebras.ai/v1/chat/completions", | |
| // S408: SambaNova — 2200+ tok/s, OpenAI-compatible, free tier (cloud.sambanova.ai) | |
| // S-LOOP9: modelli verificati live 2026-06-12 -- vedi SAMBANOVA_MODELS | |
| SAMBANOVA: "https://api.sambanova.ai/v1/chat/completions", | |
| // S408: Cloudflare Workers AI — gratis 10k req/giorno, non serve account separato | |
| // URL dinamico: dipende da CF_ACCOUNT_ID — costruito in cfAiEndpoint() | |
| CF_AI_BASE: "https://api.cloudflare.com/client/v4/accounts", | |
| } as const; | |
| // ─── CF Workers AI endpoint builder ────────────────────────────────────────── | |
| // Costruisce l'URL per un modello Cloudflare Workers AI dato l'account ID. | |
| export function cfAiEndpoint(accountId: string, model: string): string { | |
| return `${ENDPOINTS.CF_AI_BASE}/${accountId}/ai/run/${model}`; | |
| } | |
| // ─── Model defaults ────────────────────────────────────────────────────────── | |
| export const DEFAULT_MODELS = { | |
| HF_ROUTER: "deepseek-ai/DeepSeek-V3-0324", | |
| GROQ: "llama-3.3-70b-versatile", | |
| OPENROUTER: "openai/gpt-oss-20b:free", | |
| OPENAI: "gpt-4o-mini", | |
| GEMINI: "gemini-2.5-flash", | |
| // S325: Cerebras — gpt-oss-120b (llama-3.3-70b rimosso da Cerebras a giugno 2026) | |
| CEREBRAS: "gpt-oss-120b", | |
| // S408: SambaNova — modelli free tier (giugno 2026) | |
| SAMBANOVA: "Meta-Llama-3.3-70B-Instruct", | |
| // S408: CF Workers AI — fp8-fast = versione ottimizzata per latenza | |
| CF_AI: "@cf/meta/llama-3.3-70b-instruct-fp8-fast", | |
| } as const; | |
| // ─── SambaNova model list (free tier, giugno 2026) ─────────────────────────── | |
| // S-LOOP9: verificato live 2026-06-12 -- specchio di SAMBANOVA_MODELS_FAST in providerConstants.ts | |
| // Rimossi (non piu in /v1/models): Llama-4-Scout-17B-16E, Meta-Llama-3.1-8B-Instruct, DeepSeek-R1-671B | |
| export const SAMBANOVA_MODELS = [ | |
| "DeepSeek-V3.1", // 131k ctx, best quality | |
| "Meta-Llama-3.3-70B-Instruct", // 131k ctx, 2200+ tok/s -- default | |
| "MiniMax-M2.7", // 196k ctx -- contesti lunghi | |
| "gemma-4-31B-it", // 131k ctx, Gemma 4 31B | |
| "gpt-oss-120b", // 131k ctx, GPT-class quality | |
| "DeepSeek-V3.2", // 32k ctx, versione alternativa | |
| ] as const; | |
| // ─── CF Workers AI model list (free tier) ──────────────────────────────────── | |
| export const CF_AI_MODELS = [ | |
| "@cf/meta/llama-3.3-70b-instruct-fp8-fast", // 70B fast -- massima qualita CF | |
| "@cf/deepseek-ai/deepseek-r1-distill-llama-70b", // reasoning 70B con <think> | |
| "@cf/deepseek-ai/deepseek-r1-distill-qwen-32b", // reasoning 32B alternativo | |
| "@cf/meta/llama-3.1-8b-instruct", // 8B fallback (ancora disponibile) | |
| ] as const; | |
| // ─── Token / request limits ────────────────────────────────────────────────── | |
| export const LIMITS = { | |
| MAX_TOKENS_DEFAULT: 4096, | |
| MAX_TOKENS_AGENT: 8192, | |
| MAX_TOKENS_SERVERLESS: 2048, // HF Inference API — modelli piccoli | |
| TEMPERATURE_DEFAULT: 0.7, | |
| TEMPERATURE_AGENT: 0.5, | |
| TIMEOUT_FAST_MS: 10_000, // Groq, Cerebras, SambaNova — provider veloci | |
| TIMEOUT_DEFAULT_MS: 22_000, // HF Router, OpenRouter | |
| TIMEOUT_SLOW_MS: 45_000, // Gemini, backend locale | |
| TIMEOUT_AGENT_MS: 120_000, | |
| LOCAL_BACKEND_CHECK_TTL_MS: 30_000, | |
| PROVIDER_RETRY_AFTER_MS: 20_000, | |
| } as const; | |
| // ─── Provider chain order (usata dal fallback automatico) ──────────────────── | |
| // Ordine: più affidabile → meno affidabile per uso generale. | |
| export const PROVIDER_CHAIN_ORDER = [ | |
| "gemini", | |
| "deepseek-hf", | |
| "deepseek-openrouter", | |
| "llama-groq", | |
| "llama-sambanova", | |
| "llama-openrouter", | |
| "hf-router", | |
| "hf-serverless", | |
| "openai", | |
| "together", | |
| "browser-llm", | |
| ] as const; | |
| // ─── Feature flags ─────────────────────────────────────────────────────────── | |
| export const FEATURES = { | |
| // WebGPU/WebLLM: carica modelli nel browser (disabilitato di default — crash su iOS) | |
| BROWSER_LLM_AUTO_PRELOAD: false, | |
| // Virtualizzazione lista messaggi (riduce DOM su Safari) | |
| VIRTUALIZE_MESSAGES: true, | |
| // Backend locale (Ollama) — check automatico all'avvio | |
| LOCAL_BACKEND_CHECK: !!ENV.BACKEND_URL, | |
| // Diagnostics panel in dev | |
| DIAGNOSTICS_PANEL: import.meta.env.DEV, | |
| } as const; | |
| // ─── OpenRouter branding headers ───────────────────────────────────────────── | |
| export const OPENROUTER_HEADERS = { | |
| "HTTP-Referer": "https://baida98.github.io", | |
| "X-Title": "Agente AI", | |
| } as const; | |