Spaces:
Sleeping
Sleeping
| import crypto from 'crypto'; | |
| const API_URL = 'https://api.deepai.org/hacking_is_a_serious_crime'; | |
| const SECRET = 'hackers_become_a_little_stinkier_every_time_they_hack'; | |
| const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'; | |
| const FREE = 0; | |
| const LOCKED = 1; | |
| export const MODELS = { | |
| 'standard': { name: 'Standard', id: 'standard', status: FREE }, | |
| 'deepseek-v3.2': { name: 'DeepSeek V3.2', id: 'deepseek-v3.2', status: FREE }, | |
| 'gemini-2.5-flash-lite':{ name: 'Gemini 2.5 Flash Lite', id: 'gemini-2.5-flash-lite', status: FREE }, | |
| 'gemma-4': { name: 'Gemma 4', id: 'gemma-4', status: FREE }, | |
| 'gpt-4.1-nano': { name: 'GPT-4.1 Nano', id: 'gpt-4.1-nano', status: FREE }, | |
| 'gpt-oss-120b': { name: 'GPT OSS 120B', id: 'gpt-oss-120b', status: FREE }, | |
| 'qwen3-30b-a3b': { name: 'Qwen3 30B', id: 'qwen3-30b-a3b', status: FREE }, | |
| 'gpt-5-nano': { name: 'GPT-5 Nano', id: 'gpt-5-nano', status: FREE }, | |
| 'llama-3.3-70b-instruct':{name: 'Llama 3.3 70B Instruct',id: 'llama-3.3-70b-instruct',status: FREE }, | |
| 'llama-3.1-8b-instant': { name: 'Llama 3.1 8B Instant', id: 'llama-3.1-8b-instant', status: FREE }, | |
| 'llama-4-scout': { name: 'Llama 4 Scout', id: 'llama-4-scout', status: FREE }, | |
| 'claude-opus-4.6': { name: 'Claude Opus 4.6', id: 'claude-opus-4.6', status: FREE }, | |
| 'gemini-3.1-pro': { name: 'Gemini 3.1 Pro', id: 'gemini-3.1-pro', status: FREE }, | |
| 'grok-4': { name: 'Grok 4', id: 'grok-4', status: FREE }, | |
| 'gpt-5.2': { name: 'GPT-5.2', id: 'gpt-5.2', status: LOCKED }, | |
| 'gpt-5.3-chat-latest': { name: 'GPT-5.3 Chat Latest', id: 'gpt-5.3-chat-latest', status: LOCKED }, | |
| 'gpt-4.1': { name: 'GPT-4.1', id: 'gpt-4.1', status: LOCKED }, | |
| 'gpt-4o-mini': { name: 'GPT-4o mini', id: 'gpt-4o-mini', status: LOCKED }, | |
| 'chatgpt-4o-latest': { name: 'ChatGPT 4o Latest', id: 'chatgpt-4o-latest', status: LOCKED }, | |
| 'o3': { name: 'o3', id: 'o3', status: LOCKED }, | |
| 'o4-mini': { name: 'o4 Mini', id: 'o4-mini', status: LOCKED }, | |
| }; | |
| function md5(s) { | |
| const hash = crypto.createHash('md5').update(s, 'utf8').digest(); | |
| const g = []; | |
| for (let i = 0; i < 4; i++) { | |
| const w = (hash[4 * i] | (hash[4 * i + 1] << 8) | (hash[4 * i + 2] << 16) | (hash[4 * i + 3] << 24)) >>> 0; | |
| g.push(w); | |
| } | |
| const chars = []; | |
| for (let l = 0; l < 32; l++) { | |
| const word = l >> 8; | |
| const shift = (4 * (1 ^ l)) & 31; | |
| const nibble = (g[word] >> shift) & 0xF; | |
| chars.push(nibble.toString(16)); | |
| } | |
| return chars.join('').split('').reverse().join(''); | |
| } | |
| function genKey() { | |
| const r = String(Math.round(Math.random() * 100000000000)); | |
| const h1 = md5(UA + r + SECRET); | |
| const h2 = md5(UA + h1); | |
| const h3 = md5(UA + h2); | |
| return `tryit-${r}-${h3}`; | |
| } | |
| export class DeepAIError extends Error { | |
| constructor(message, code, details) { | |
| super(message); | |
| this.code = code || 'deepai_error'; | |
| this.details = details || null; | |
| } | |
| } | |
| export async function deepaiChat(messages, options = {}) { | |
| const { model, onDelta } = options; | |
| const modelId = model || 'standard'; | |
| const prompt = messages.map(m => { | |
| if (typeof m.content === 'string') return m.content; | |
| if (m.content && Array.isArray(m.content)) return m.content.map(c => c.text || '').join(''); | |
| return ''; | |
| }).filter(Boolean).join('\n'); | |
| if (!prompt) throw new DeepAIError('No message content', 'no_content'); | |
| const payload = new URLSearchParams({ | |
| chat_style: 'chat', | |
| chatHistory: JSON.stringify([{ role: 'user', content: prompt }]), | |
| model: modelId, | |
| hacker_is_stinky: 'very_stinky', | |
| enabled_tools: JSON.stringify(['image_generator', 'image_editor']), | |
| }); | |
| const headers = { | |
| 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Mobile Safari/537.36', | |
| 'Accept-Encoding': 'gzip, deflate, br, zstd', | |
| 'sec-ch-ua-platform': '"Android"', | |
| 'api-key': genKey(), | |
| 'sec-ch-ua': '"Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99"', | |
| 'sec-ch-ua-mobile': '?1', | |
| 'origin': 'https://deepai.org', | |
| 'sec-fetch-site': 'same-site', | |
| 'sec-fetch-mode': 'cors', | |
| 'sec-fetch-dest': 'empty', | |
| 'accept-language': 'ar-IQ,ar;q=0.9,en-US;q=0.8,en;q=0.7', | |
| 'priority': 'u=1, i', | |
| }; | |
| try { | |
| const res = await fetch(API_URL, { method: 'POST', headers, body: payload }); | |
| const text = await res.text(); | |
| if (res.status === 401) { | |
| throw new DeepAIError(`Model locked: ${text}`, 'model_locked', { model: modelId, status: res.status }); | |
| } | |
| if (!res.ok) { | |
| throw new DeepAIError(`API error: ${text}`, 'api_error', { model: modelId, status: res.status }); | |
| } | |
| if (onDelta) onDelta(text); | |
| return { text, model: modelId }; | |
| } catch (e) { | |
| if (e instanceof DeepAIError) throw e; | |
| throw new DeepAIError(e.message, 'network_error'); | |
| } | |
| } | |
| export function listModels() { | |
| return Object.entries(MODELS).map(([id, info]) => ({ | |
| id, | |
| name: info.name, | |
| free: info.status === FREE, | |
| })); | |
| } | |
| export function getFreeModels() { | |
| return Object.entries(MODELS) | |
| .filter(([_, info]) => info.status === FREE) | |
| .map(([id, info]) => ({ id, name: info.name })); | |
| } | |