/*** @ Base: https://play.google.com/store/apps/details?id=com.jetkite.deepsearch @ Author: Shannz @ Note: Wrapper from apk Deepsearch AI Chatbot. ***/ import axios from 'axios'; import crypto from 'crypto'; import fs from 'fs'; const CONFIG = { URLS: { CHAT: 'https://deepseekv2-qbvg2hl3qq-uc.a.run.app', KEY: 'https://rotatingkey-qbvg2hl3qq-uc.a.run.app' }, HEADERS: { 'User-Agent': 'okhttp/4.12.0', 'Accept-Encoding': 'gzip', 'Content-Type': 'application/json' }, AES_INPUT_KEY: "NiIsImtpZCI6I56" }; async function getSecretKey() { try { const response = await axios.get(CONFIG.URLS.KEY, { headers: { 'User-Agent': 'Android', 'Accept-Encoding': 'gzip' } }); return response.data?.rotatingKey || null; } catch (error) { return null; } } function generateSecurityHeaders(secretKey) { try { const iv = crypto.randomBytes(16); const ivBase64 = iv.toString('base64'); const keyBuffer = Buffer.from(secretKey, 'utf8'); const cipher = crypto.createCipheriv('aes-128-cbc', keyBuffer, iv); let encrypted = cipher.update(CONFIG.AES_INPUT_KEY, 'utf8'); encrypted = Buffer.concat([encrypted, cipher.final()]); return { iv: ivBase64 + '\n', authorization: "Bearer " + encrypted.toString('base64') }; } catch (error) { return null; } } const toBase64 = async (input) => { try { let buffer; if (Buffer.isBuffer(input)) buffer = input; else if (input.startsWith('http')) { const res = await axios.get(input, { responseType: 'arraybuffer' }); buffer = Buffer.from(res.data); } else if (fs.existsSync(input)) { buffer = fs.readFileSync(input); } else return null; return buffer.toString('base64'); } catch (e) { return null; } }; export const deepseek = { chat: async (prompt, history = [], media = null, model = 'deepseek-chat') => { try { const secretKey = await getSecretKey(); if (!secretKey) return { success: false, msg: 'Failed to fetch secret key' }; const security = generateSecurityHeaders(secretKey); if (!security) return { success: false, msg: 'Failed to generate security headers' }; let messages = [...history]; const currentMessage = { role: "user", content: prompt }; let payloadMessages = [...messages, currentMessage]; let finalModel = model; let base64Image = null; if (media) { const rawBase64 = await toBase64(media); if (rawBase64) { finalModel = 'gpt-4o-mini'; base64Image = `data:image/jpeg;base64,${rawBase64}`; payloadMessages = []; } } const dataPayload = { data: prompt, iv: security.iv, messages: payloadMessages, model: finalModel, secretKey: secretKey }; if (base64Image) { dataPayload.image1 = base64Image; } const response = await axios.post(CONFIG.URLS.CHAT, dataPayload, { headers: { ...CONFIG.HEADERS, 'authorization': security.authorization } }); const apiResult = response.data?.data; if (apiResult && apiResult.choices && apiResult.choices.length > 0) { const messageObj = apiResult.choices[0].message; const replyText = messageObj.content || ""; const reasoningText = messageObj.reasoning_content || null; const newHistory = [...messages, currentMessage, { role: "assistant", content: replyText }]; return { success: true, reply: replyText, reasoning: reasoningText, history: newHistory, modelUsed: finalModel, usage: apiResult.usage }; } return { success: false, msg: 'Empty response choices' }; } catch (error) { console.error(`[Deepseek Error]: ${error.message}`); return { success: false, msg: error.message }; } } }; /* (async () => { // 1. Chat Biasa console.log("--- Tes Chat ---"); let resChat = await deepseek.chat("Halo, perkenalkan aku shannz!"); console.log("Bot:", resChat.reply); // Simpan History let myHistory = resChat.history // 2. Chat peke history console.log("--- Tes History Chat ---"); let resChat2 = await deepseek.chat("siapa namaku tadi?", myHistory); console.log("Bot:", resChat2.reply); // 3. Model Reasoner console.log("\n--- Tes Reasoner ---"); let resReason = await deepseek.chat("Mengapa langit berwarna biru?", [], null, 'deepseek-reasoner'); if (resReason.reasoning) { console.log("[Reasoning]:", resReason.reasoning); console.log("--------------------------------"); } console.log("[Answer]:", resReason.reply); // 4. Chat pake gambar console.log("\n--- Tes Gambar ---"); let resImg = await deepseek.chat("Jelaskan gambar ini", [], "./u.jpg"); console.log("Bot Vision:", resImg.reply); })(); */