Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
Audit & add web cookie providers: fix 4 missing registry entries + DuckDuckGo (#2862)
Paijo2355bf941912
diff --git a/open-sse/config/providerRegistry.ts b/open-sse/config/providerRegistry.tsindex fddcefbd8b..07269eb476 100644--- a/open-sse/config/providerRegistry.ts+++ b/open-sse/config/providerRegistry.ts@@ -2899,6 +2899,86 @@ export const REGISTRY: Record<string, RegistryEntry> = {],},+ "blackbox-web": {+ id: "blackbox-web",+ alias: "bb-web",+ format: "openai",+ executor: "blackbox-web",+ baseUrl: "https://app.blackbox.ai/api/chat",+ authType: "apikey",+ authHeader: "cookie",+ models: [+ { id: "gpt-4-turbo", name: "GPT-4 Turbo" },+ { id: "gpt-4", name: "GPT-4" },+ { id: "gpt-3.5-turbo", name: "GPT-3.5 Turbo" },+ { id: "claude-3-opus", name: "Claude 3 Opus" },+ { id: "claude-3-sonnet", name: "Claude 3 Sonnet" },+ { id: "gemini-pro", name: "Gemini Pro" },+ ],+ },++ "claude-web": {+ id: "claude-web",+ alias: "claude-web",+ format: "openai",+ executor: "claude-web",+ baseUrl: "https://claude.ai/api/organizations",+ authType: "apikey",+ authHeader: "cookie",+ models: [+ { id: "claude-3-opus-20250219", name: "Claude 3 Opus (web)" },+ { id: "claude-3-5-sonnet-20241022", name: "Claude 3.5 Sonnet (web)" },+ { id: "claude-3-5-haiku-20241022", name: "Claude 3.5 Haiku (web)" },+ ],+ },++ "copilot-web": {+ id: "copilot-web",+ alias: "copilot-web",+ format: "openai",+ executor: "copilot-web",+ baseUrl: "wss://copilot.microsoft.com/c/api/chat?api-version=2",+ authType: "apikey",+ authHeader: "cookie",+ models: [+ { id: "copilot-pro", name: "Copilot Pro (web)" },+ { id: "gpt-4-turbo", name: "GPT-4 Turbo (via Copilot)" },+ { id: "gpt-4", name: "GPT-4 (via Copilot)" },+ ],+ },++ "veoaifree-web": {+ id: "veoaifree-web",+ alias: "veo-free",+ format: "openai",+ executor: "veoaifree-web",+ baseUrl: "https://veoaifree.com/wp-admin/admin-ajax.php",+ authType: "none",+ authHeader: "none",+ models: [+ { id: "veo", name: "VEO 3.1" },+ { id: "seedance", name: "Seedance" },+ ],+ },++ "duckduckgo-web": {+ id: "duckduckgo-web",+ alias: "ddgw",+ format: "openai",+ executor: "duckduckgo-web",+ baseUrl: "https://duckduckgo.com/duckchat/v1/chat",+ authType: "none",+ authHeader: "none",+ models: [+ { id: "gpt-4o-mini", name: "GPT-4o Mini" },+ { id: "gpt-5-mini", name: "GPT-5 Mini" },+ { id: "claude-3-5-haiku-20241022", name: "Claude 3.5 Haiku" },+ { id: "llama-4-scout", name: "Llama 4 Scout" },+ { id: "mistral-small-2501", name: "Mistral Small" },+ { id: "o3-mini", name: "O3 Mini" },+ ],+ },+together: {id: "together",alias: "together",diff --git a/open-sse/executors/duckduckgo-web.ts b/open-sse/executors/duckduckgo-web.tsnew file mode 100644index 0000000000..9dd1c091a1--- /dev/null+++ b/open-sse/executors/duckduckgo-web.ts@@ -0,0 +1,282 @@+import { BaseExecutor, type ExecuteInput } from "./base.ts";+import { FETCH_TIMEOUT_MS } from "../config/constants.ts";++export const DUCKDUCKGO_BASE = "https://duckduckgo.com";+const STATUS_URL = `${DUCKDUCKGO_BASE}/duckchat/v1/status`;+const CHAT_URL = `${DUCKDUCKGO_BASE}/duckchat/v1/chat`;++const FAKE_HEADERS: Record<string, string> = {+ Accept: "*/*",+ "Accept-Encoding": "gzip, deflate, br, zstd",+ "Accept-Language": "en-US,en;q=0.9",+ Origin: DUCKDUCKGO_BASE,+ Referer: `${DUCKDUCKGO_BASE}/`,+ "User-Agent":+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",+};++/**+ * DuckDuckGoWebExecutor handles anonymous, free access to DuckDuckGo AI Chat.+ *+ * Authentication flow:+ * 1. GET /duckchat/v1/status → get x-vqd-hash-1 header (VQD token)+ * 2. POST /duckchat/v1/chat with VQD header + model + messages+ * 3. Parse NDJSON SSE stream and transform to OpenAI format+ *+ * VQD tokens are per-request; no caching or cleanup needed.+ */+export class DuckDuckGoWebExecutor extends BaseExecutor {+ constructor() {+ super("duckduckgo-web", { baseUrl: DUCKDUCKGO_BASE });+ }++ async testConnection(credentials: Record<string, unknown>, signal?: AbortSignal): Promise<boolean> {+ try {+ const controller = new AbortController();+ const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);++ const mergedSignal = signal+ ? AbortSignal.any([signal, controller.signal])+ : controller.signal;++ const resp = await fetch(STATUS_URL, {+ method: "GET",+ headers: { ...FAKE_HEADERS, Accept: "text/event-stream" },+ signal: mergedSignal,+ });++ clearTimeout(timeout);++ return resp.ok && resp.headers.get("x-vqd-hash-1") !== null;+ } catch {+ return false;+ }+ }++ async execute(input: ExecuteInput) {+ const { model, messages, stream, signal, upstreamHeaders } = input;++ if (!messages || messages.length === 0) {+ return new Response(+ JSON.stringify({ error: { message: "No messages provided" } }),+ { status: 400, headers: { "Content-Type": "application/json" } }+ );+ }++ try {+ const controller = new AbortController();+ const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);+ const mergedSignal = signal+ ? AbortSignal.any([signal, controller.signal])+ : controller.signal;++ if (mergedSignal.aborted) {+ clearTimeout(timeout);+ return new Response(+ JSON.stringify({ error: { message: "Request cancelled" } }),+ { status: 499, headers: { "Content-Type": "application/json" } }+ );+ }++ const vqdToken = await this.acquireVqdHash(mergedSignal);+ if (!vqdToken) {+ clearTimeout(timeout);+ return new Response(+ JSON.stringify({ error: { message: "Failed to acquire VQD token" } }),+ { status: 503, headers: { "Content-Type": "application/json" } }+ );+ }++ const chatResponse = await fetch(CHAT_URL, {+ method: "POST",+ headers: {+ ...FAKE_HEADERS,+ "Content-Type": "application/json",+ "x-vqd-hash-1": vqdToken,+ },+ body: JSON.stringify({+ model,+ messages,+ stream: stream !== false,+ }),+ signal: mergedSignal,+ });++ clearTimeout(timeout);++ if (chatResponse.status === 429) {+ return new Response(+ JSON.stringify({ error: { message: "DuckDuckGo rate limited" } }),+ { status: 429, headers: { "Content-Type": "application/json" } }+ );+ }++ if (chatResponse.status === 401 || chatResponse.status === 403) {+ const newVqd = await this.acquireVqdHash(mergedSignal);+ if (newVqd) {+ const retryResponse = await fetch(CHAT_URL, {+ method: "POST",+ headers: {+ ...FAKE_HEADERS,+ "Content-Type": "application/json",+ "x-vqd-hash-1": newVqd,+ },+ body: JSON.stringify({+ model,+ messages,+ stream: stream !== false,+ }),+ signal: mergedSignal,+ });++ return this.processResponse(retryResponse, stream !== false);+ }+ return new Response(+ JSON.stringify({ error: { message: "Service unavailable" } }),+ { status: 503, headers: { "Content-Type": "application/json" } }+ );+ }++ if (chatResponse.status >= 500) {+ return new Response(+ JSON.stringify({ error: { message: "Upstream error" } }),+ { status: 502, headers: { "Content-Type": "application/json" } }+ );+ }++ return this.processResponse(chatResponse, stream !== false);+ } catch (error) {+ if (error instanceof DOMException && error.name === "AbortError") {+ return new Response(+ JSON.stringify({ error: { message: "Request cancelled" } }),+ { status: 499, headers: { "Content-Type": "application/json" } }+ );+ }++ return new Response(+ JSON.stringify({ error: { message: error instanceof Error ? error.message : "Unknown error" } }),+ { status: 500, headers: { "Content-Type": "application/json" } }+ );+ }+ }++ private async acquireVqdHash(signal: AbortSignal): Promise<string | null> {+ try {+ if (signal.aborted) throw new DOMException("Aborted", "AbortError");++ const resp = await fetch(STATUS_URL, {+ method: "GET",+ headers: { ...FAKE_HEADERS, Accept: "text/event-stream" },+ signal,+ });++ if (!resp.ok) return null;+ return resp.headers.get("x-vqd-hash-1");+ } catch (error) {+ if (error instanceof DOMException && error.name === "AbortError") {+ throw error;+ }+ return null;+ }+ }++ private async processResponse(response: Response, streaming: boolean): Promise<Response> {+ if (!response.ok) {+ const body = await response.text();+ return new Response(body, {+ status: response.status,+ headers: { "Content-Type": "application/json" },+ });+ }++ if (streaming) {+ const reader = response.body?.getReader();+ if (!reader) {+ return new Response(+ JSON.stringify({ error: { message: "No response body" } }),+ { status: 500, headers: { "Content-Type": "application/json" } }+ );+ }++ const transformStream = new TransformStream({+ async transform(chunk, controller) {+ const text = new TextDecoder().decode(chunk);+ const lines = text.split("\n");++ for (const line of lines) {+ if (!line.trim()) continue;+ if (line === "[DONE]") {+ controller.enqueue(new TextEncoder().encode("data: [DONE]\n\n"));+ continue;+ }++ try {+ if (line.startsWith("data: ")) {+ const jsonStr = line.slice(6);+ const data = JSON.parse(jsonStr);++ if (data.content) {+ const openaiFormat = {+ choices: [+ {+ delta: { content: data.content },+ index: 0,+ },+ ],+ };+ const encoded = new TextEncoder().encode(+ `data: ${JSON.stringify(openaiFormat)}\n\n`+ );+ controller.enqueue(encoded);+ }+ }+ } catch {+ continue;+ }+ }+ },+ });++ const transformedBody = reader.pipeThrough(transformStream);+ return new Response(transformedBody, {+ headers: { "Content-Type": "text/event-stream" },+ });+ } else {+ const text = await response.text();+ let fullContent = "";++ const lines = text.split("\n");+ for (const line of lines) {+ if (!line.trim() || line === "[DONE]") continue;++ try {+ if (line.startsWith("data: ")) {+ const jsonStr = line.slice(6);+ const data = JSON.parse(jsonStr);+ if (data.content) {+ fullContent += data.content;+ }+ }+ } catch {+ continue;+ }+ }++ const openaiResponse = {+ choices: [+ {+ message: { content: fullContent, role: "assistant" },+ index: 0,+ finish_reason: "stop",+ },+ ],+ };++ return new Response(JSON.stringify(openaiResponse), {+ headers: { "Content-Type": "application/json" },+ });+ }+ }+}++export const duckduckgoWebExecutor = new DuckDuckGoWebExecutor();diff --git a/open-sse/executors/index.ts b/open-sse/executors/index.tsindex 0d78b88987..e694d444aa 100644--- a/open-sse/executors/index.ts+++ b/open-sse/executors/index.ts@@ -34,6 +34,7 @@ import { AdaptaWebExecutor } from "./adapta-web.ts";import { ClaudeWebWithAutoRefresh } from "./claude-web-with-auto-refresh.ts";import { CopilotWebExecutor } from "./copilot-web.ts";import { VeoAIFreeWebExecutor } from "./veoaifree-web.ts";+import { DuckDuckGoWebExecutor } from "./duckduckgo-web.ts";import { T3ChatWebExecutor } from "./t3-chat-web.ts";import { ClaudeWebExecutor } from "./claude-web.ts";import { InnerAiExecutor } from "./inner-ai.ts";@@ -99,6 +100,8 @@ const executors = {copilot: new CopilotWebExecutor(), // Alias"veoaifree-web": new VeoAIFreeWebExecutor(),"veo-free": new VeoAIFreeWebExecutor(), // Alias+ "duckduckgo-web": new DuckDuckGoWebExecutor(),+ "ddgw": new DuckDuckGoWebExecutor(), // Alias"t3-web": new T3ChatWebExecutor(),t3chat: new T3ChatWebExecutor(), // Alias"claude-web": new ClaudeWebExecutor(),@@ -153,6 +156,7 @@ export { WindsurfExecutor } from "./windsurf.ts";export { DevinCliExecutor } from "./devin-cli.ts";export { CopilotWebExecutor } from "./copilot-web.ts";export { VeoAIFreeWebExecutor } from "./veoaifree-web.ts";+export { DuckDuckGoWebExecutor } from "./duckduckgo-web.ts";export { ClaudeWebExecutor } from "./claude-web.ts";export { DeepSeekWebExecutor } from "./deepseek-web.ts";export { DeepSeekWebWithAutoRefreshExecutor } from "./deepseek-web-with-auto-refresh.ts";diff --git a/src/app/(dashboard)/dashboard/providers/[id]/webSessionCredentials.ts b/src/app/(dashboard)/dashboard/providers/[id]/webSessionCredentials.tsindex 7b355d90a8..88139f7aa7 100644--- a/src/app/(dashboard)/dashboard/providers/[id]/webSessionCredentials.ts+++ b/src/app/(dashboard)/dashboard/providers/[id]/webSessionCredentials.ts@@ -93,6 +93,12 @@ export const WEB_SESSION_CREDENTIAL_REQUIREMENTS = {placeholder: "token_value [email protected]",acceptsFullCookieHeader: false,},+ "duckduckgo-web": {+ kind: "none",+ credentialName: "",+ placeholder: "",+ acceptsFullCookieHeader: false,+ },} satisfies Record<keyof typeof WEB_COOKIE_PROVIDERS, WebSessionCredentialRequirement>;export function getWebSessionCredentialRequirement(diff --git a/src/shared/constants/providers.ts b/src/shared/constants/providers.tsindex e2a5da13ce..964dbd1911 100644--- a/src/shared/constants/providers.ts+++ b/src/shared/constants/providers.ts@@ -309,6 +309,8 @@ export const WEB_COOKIE_PROVIDERS = {color: "#0866FF",textIcon: "MS",website: "https://www.meta.ai",+ hasFree: true,+ freeNote: "Free with login — Meta AI platform with Llama models.",authHint: "Paste your abra_sess value or full cookie header from meta.ai",},"claude-web": {@@ -384,6 +386,8 @@ export const WEB_COOKIE_PROVIDERS = {color: "#1A56DB",textIcon: "IA",website: "https://app.innerai.com",+ subscriptionRisk: true,+ riskNoticeVariant: "webCookie",authHint:"Paste your token cookie and email separated by a space: open DevTools → Application → Cookies → .innerai.com, copy the token value, then append a space and your Inner.ai login email. Example: eyJhbG... [email protected]",},@@ -395,9 +399,23 @@ export const WEB_COOKIE_PROVIDERS = {color: "#6E3AD3",textIcon: "AW",website: "https://agent.adapta.one",+ subscriptionRisk: true,+ riskNoticeVariant: "webCookie",authHint:"Paste your __client cookie value from .clerk.agent.adapta.one (DevTools → Application → Cookies)",},+ "duckduckgo-web": {+ id: "duckduckgo-web",+ alias: "ddgw",+ name: "DuckDuckGo AI Chat",+ icon: "auto_awesome",+ color: "#DE5833",+ textIcon: "DDG",+ website: "https://duckduckgo.com/duckchat",+ hasFree: true,+ freeNote: "Free — anonymous access to multiple AI models via DuckDuckGo.",+ authHint: "No credentials required — DuckDuckGo AI Chat is anonymous and free.",+ },};// API Key Providersdiff --git a/tests/unit/duckduckgo-web-executor.test.ts b/tests/unit/duckduckgo-web-executor.test.tsnew file mode 100644index 0000000000..81f2f4140e--- /dev/null+++ b/tests/unit/duckduckgo-web-executor.test.ts@@ -0,0 +1,204 @@+import { describe, it, mock } from "node:test";+import assert from "node:assert/strict";+import { DuckDuckGoWebExecutor, DUCKDUCKGO_BASE } from "../../open-sse/executors/duckduckgo-web.ts";++describe("DuckDuckGoWebExecutor", () => {+ describe("class instantiation", () => {+ it("should instantiate executor", () => {+ const executor = new DuckDuckGoWebExecutor();+ assert.ok(executor, "Executor should be created");+ });++ it("should have execute method", () => {+ const executor = new DuckDuckGoWebExecutor();+ assert.equal(typeof executor.execute, "function", "execute should be a function");+ });++ it("should have testConnection method", () => {+ const executor = new DuckDuckGoWebExecutor();+ assert.equal(typeof executor.testConnection, "function", "testConnection should be a function");+ });++ it("should export DUCKDUCKGO_BASE constant", () => {+ assert.equal(DUCKDUCKGO_BASE, "https://duckduckgo.com", "DUCKDUCKGO_BASE should be correct URL");+ });+ });++ describe("execute method validation", () => {+ it("should reject empty messages array", async () => {+ const executor = new DuckDuckGoWebExecutor();++ const response = await executor.execute({+ model: "gpt-4o-mini",+ messages: [],+ stream: false,+ } as any);++ assert.ok(response instanceof Response, "should return Response");+ assert.equal(response.status, 400, "should return 400 for empty messages");++ const body = await response.json();+ assert.ok(body.error, "error response should have error field");+ });++ it("should accept non-empty messages array", async () => {+ const executor = new DuckDuckGoWebExecutor();++ // This will fail due to network, but should pass input validation+ try {+ const response = await executor.execute({+ model: "gpt-4o-mini",+ messages: [{ role: "user", content: "test" }],+ stream: false,+ } as any);++ // Should either succeed with real response or fail with network error (status 5xx, not 400)+ assert.notEqual(response.status, 400, "should not return 400 for valid messages");+ } catch (error) {+ // Network error is expected since we're not running against real DuckDuckGo+ assert.ok(error instanceof Error, "should throw Error for network issues");+ }+ });++ it("should handle missing model parameter", async () => {+ const executor = new DuckDuckGoWebExecutor();++ try {+ await executor.execute({+ model: undefined,+ messages: [{ role: "user", content: "test" }],+ stream: false,+ } as any);+ } catch (error) {+ assert.ok(error instanceof Error || error instanceof Response, "should handle missing model");+ }+ });+ });++ describe("testConnection method", () => {+ it("should return boolean", async () => {+ const executor = new DuckDuckGoWebExecutor();++ try {+ const result = await executor.testConnection({});+ assert.equal(typeof result, "boolean", "testConnection should return boolean");+ } catch (error) {+ // Network error is acceptable - just verify method exists and is callable+ assert.ok(true, "testConnection is callable");+ }+ });++ it("should complete within timeout", async () => {+ const executor = new DuckDuckGoWebExecutor();+ const startTime = Date.now();++ try {+ await executor.testConnection({});+ } catch (error) {+ // Expected to fail or timeout+ }++ const elapsed = Date.now() - startTime;+ assert.ok(elapsed < 35000, `testConnection should complete within 35 seconds, took ${elapsed}ms`);+ });+ });++ describe("response handling", () => {+ it("should handle AbortSignal", async () => {+ const executor = new DuckDuckGoWebExecutor();+ const controller = new AbortController();++ // Abort immediately+ controller.abort();++ const response = await executor.execute({+ model: "gpt-4o-mini",+ messages: [{ role: "user", content: "test" }],+ stream: false,+ signal: controller.signal,+ } as any);++ assert.ok(response instanceof Response, "should return Response");+ assert.equal(response.status, 499, "should return 499 for aborted request");+ });++ it("should support streaming parameter", async () => {+ const executor = new DuckDuckGoWebExecutor();++ try {+ // Test with stream: true+ const response1 = await executor.execute({+ model: "gpt-4o-mini",+ messages: [{ role: "user", content: "test" }],+ stream: true,+ } as any);+ assert.ok(response1 instanceof Response, "streaming mode should return Response");++ // Test with stream: false+ const response2 = await executor.execute({+ model: "gpt-4o-mini",+ messages: [{ role: "user", content: "test" }],+ stream: false,+ } as any);+ assert.ok(response2 instanceof Response, "non-streaming mode should return Response");+ } catch (error) {+ // Network errors are expected+ assert.ok(error instanceof Error || error instanceof Response);+ }+ });+ });++ describe("error handling", () => {+ it("should handle network timeouts gracefully", async () => {+ const executor = new DuckDuckGoWebExecutor();++ try {+ const response = await executor.execute({+ model: "gpt-4o-mini",+ messages: [{ role: "user", content: "test" }],+ stream: false,+ } as any);++ // Should get a response, not throw+ assert.ok(response instanceof Response, "should return Response even on timeout");+ } catch (error) {+ // Timeout or network error is acceptable+ assert.ok(error instanceof Error, "should handle errors gracefully");+ }+ });++ it("should return valid error responses with JSON", async () => {+ const executor = new DuckDuckGoWebExecutor();++ const response = await executor.execute({+ model: "gpt-4o-mini",+ messages: [],+ stream: false,+ } as any);++ assert.equal(response.status, 400);+ const contentType = response.headers.get("content-type");+ assert.ok(contentType?.includes("application/json"), "error response should be JSON");++ const body = await response.json();+ assert.ok(body.error, "error response should have error object");+ assert.ok(body.error.message, "error should have message");+ });+ });++ describe("integration checks", () => {+ it("should be properly exported from executor module", async () => {+ // Import the singleton as well+ const { duckduckgoWebExecutor } = await import("../../open-sse/executors/duckduckgo-web.ts");+ assert.ok(duckduckgoWebExecutor, "singleton executor should be exported");+ assert.ok(duckduckgoWebExecutor.execute, "singleton should have execute method");+ });++ it("should be registered in executor index", async () => {+ const { getExecutor } = await import("../../open-sse/executors/index.ts");+ const executor = getExecutor("duckduckgo-web");+ assert.ok(executor, "executor should be registered in index");+ assert.equal(typeof executor.execute, "function", "registered executor should have execute method");+ });+ });+});