GeminiBot commited on
Commit ·
d819405
1
Parent(s): c98a3e7
Fix syntax error in duckai.ts and consolidate all patches
Browse files13 unmodified lines141516171819202122232425262728293031173318192021223839232425262710 unmodified lines38394041424344454647484950515253545 unmodified lines60616267686970636465666768697071727374757677787980817273748283848586878889767778798081828384858687888990919290919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155941561571581598 unmodified lines16816917010917117217317417517617717817911611711818018118218318420 unmodified lines20520620714520820921021110 unmodified lines22222322416222522622715 unmodified lines24324424518424613 unmodified lines resources: "usable" });
const window = dom.window as any;
// ГЛУБОКАЯ ЭМУЛЯЦИЯ Object.defineProperties(window.navigator, { userAgent: { value: ua }, platform: { value: 'Win32' }, webdriver: { value: false }, languages: { value: ['en-US', 'en'] } });
window.screen = { width: 1920, height: 1080, availWidth: 1920, availHeight: 1080 }; window.chrome = { runtime: {} }; // Fix for 'Cannot read properties of null (reading 'contentDocument')' // Immortal DOM + Environment Mocks const mockWindow = dom.window as any;
// Self-reference fixes mockWindow.self = mockWindow; mockWindow.parent = mockWindow; mockWindow.top = mockWindow; // Immortal DOM Strategy
// IMMORTAL DOM Strategy const originalGetElementById = mockWindow.document.getElementById; mockWindow.document.getElementById = function(id: string) { const el = originalGetElementById.call(this, id);10 unmodified lines return mockWindow.document.createElement('div'); };
// ГЛУБОКАЯ ЭМУЛЯЦИЯ Object.defineProperties(mockWindow.navigator, { userAgent: { value: ua }, platform: { value: 'Win32' }, webdriver: { value: false }, languages: { value: ['en-US', 'en'] } });
mockWindow.screen = { width: 1920, height: 1080, availWidth: 1920, availHeight: 1080 }; mockWindow.chrome = { runtime: {} }; // Aggressive Patch for iframe contentDocument Object.defineProperty(mockWindow.HTMLIFrameElement.prototype, 'contentDocument', { get: function() { return mockWindow.document; },5 unmodified lines configurable: true });
dom.window.top.__DDG_BE_VERSION__ = 1; dom.window.top.__DDG_FE_CHAT_HASH__ = 1; const result = await dom.window.eval(jsScript) as any; // Also keep the createElement hook just in case const originalCreateElement = mockWindow.document.createElement; mockWindow.document.createElement = function(tagName: string) { const element = originalCreateElement.call(this, tagName); if (tagName.toLowerCase() === 'iframe') { try { Object.defineProperty(element, 'contentDocument', { get: () => mockWindow.document, configurable: true }); Object.defineProperty(element, 'contentWindow', { get: () => mockWindow, configurable: true }); } catch (e) {} } return element; }; if (!result || !result.client_hashes) { throw new Error("Invalid Challenge Response"); } // Robust Canvas Mock const originalGetContext = mockWindow.HTMLCanvasElement.prototype.getContext; mockWindow.HTMLCanvasElement.prototype.getContext = function (type: string, options?: any) { try { const ctx = originalGetContext.call(this, type, options); if (ctx) return ctx; } catch (e) {}
result.client_hashes[0] = ua; result.client_hashes = result.client_hashes.map((t: string) => { const hash = createHash('sha256'); hash.update(t); return hash.digest('base64'); }); return btoa(JSON.stringify(result)); } catch (e: any) { console.error(`[DuckAI] Challenge Solver Failed: ${e.message}`); // Fallback: Return the original hash (sometimes works if challenge is optional or server is lenient) // or return a dummy base64 json. console.log("[DuckAI] Attempting fallback with original VQD..."); return vqdHash; // Try returning the VQD itself as a fallback } } dom.window.top.__DDG_FE_CHAT_HASH__ = 1; return { canvas: this, fillRect: () => {}, clearRect: () => {}, getImageData: (x: number, y: number, w: number, h: number) => ({ data: new Uint8ClampedArray(w * h * 4), width: w, height: h }), putImageData: () => {}, createImageData: () => ({ data: new Uint8ClampedArray(4) }), setTransform: () => {}, drawImage: () => {}, save: () => {}, restore: () => {}, beginPath: () => {}, moveTo: () => {}, lineTo: () => {}, closePath: () => {}, stroke: () => {}, translate: () => {}, scale: () => {}, rotate: () => {}, arc: () => {}, fill: () => {}, measureText: () => ({ width: 0, actualBoundingBoxAscent: 0, actualBoundingBoxDescent: 0 }), transform: () => {}, rect: () => {}, clip: () => {}, createLinearGradient: () => ({ addColorStop: () => {} }), createRadialGradient: () => ({ addColorStop: () => {} }), createPattern: () => ({}), bezierCurveTo: () => {}, quadraticCurveTo: () => {}, fillText: () => {}, strokeText: () => {}, globalAlpha: 1, globalCompositeOperation: 'source-over', fillStyle: '#000000', strokeStyle: '#000000', lineWidth: 1, lineCap: 'butt', lineJoin: 'miter', miterLimit: 10, shadowOffsetX: 0, shadowOffsetY: 0, shadowBlur: 0, shadowColor: 'rgba(0, 0, 0, 0)', font: '10px sans-serif', textAlign: 'start', textBaseline: 'alphabetic' }; } as any;
const originalToDataURL = mockWindow.HTMLCanvasElement.prototype.toDataURL; mockWindow.HTMLCanvasElement.prototype.toDataURL = function(type?: string, quality?: any) { try { const result = originalToDataURL.call(this, type, quality); if (result && result !== "data:,") return result; } catch(e) {} return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="; };
mockWindow.top.__DDG_BE_VERSION__ = 1; mockWindow.top.__DDG_FE_CHAT_HASH__ = 1; const result = await dom.window.eval(jsScript) as any; const result = await mockWindow.eval(jsScript) as any; if (!result || !result.client_hashes) { throw new Error("Invalid Challenge Response");8 unmodified lines return btoa(JSON.stringify(result)); } catch (e: any) { throw new Error(`Challenge Solver Error: ${e.message}`); console.error(`[DuckAI] Challenge Solver Failed: ${e.message}`); console.log("[DuckAI] Attempting fallback with original VQD..."); return vqdHash; } }
getAvailableModels(): string[] { return [ "gpt-4o-mini", "claude-3-haiku-20240307", "meta-llama/Llama-3.3-70B-Instruct-Turbo", "mistralai/Mistral-Small-24B-Instruct-2501" "gpt-5-mini", "openai/gpt-oss-120b" ]; }
20 unmodified lines
console.log("[DuckAI] Solving challenge..."); const solvedVqd = await this.solveChallenge(hashHeader, ua); console.log("[DuckAI] Challenge solved."); console.log("[DuckAI] Challenge solved (or fallback used).");
const response = await fetch("https://duckduckgo.com/duckchat/v1/chat", { method: "POST",10 unmodified lines }
const text = await response.text(); // console.log(`[DuckAI] Raw response: ${text.substring(0, 200)}...`); // Uncomment for ultra verbose let llmResponse = ""; const lines = text.split("\n");15 unmodified lines return llmResponse.trim(); }}}src/duckai.ts+112-50