SurfSense/surfsense_backend/app/services
DESKTOP-RTLN3BA\$punk bdacea8b6e feat(crawler): captcha solving + per-attempt billing (Phase 3d)
Wire captchatools as the StealthyFetcher-tier page_action to detect, harvest
(egressing from the crawl's own proxy IP), inject, and submit reCAPTCHA v2/v3
and hCaptcha tokens. Opt-in and off by default (zero attempts, zero cost).

Licensing split:
- Apache-2 app/utils/captcha/ holds the generic, vendor-agnostic config
  (CaptchaConfig + captcha_enabled() = flag AND key present).
- Proprietary app/proprietary/web_crawler/captcha.py holds the bypass logic
  (detect/harvest/inject) plus a process-wide solver latch that halts solving
  on unrecoverable errors (no balance / bad key).

Crawler: CrawlOutcome gains captcha_attempts/captcha_solved, surfaced via a
per-call captcha_state dict threaded crawl_url -> _crawl_with_stealthy(_sync)
and stamped onto every stealth terminal outcome. The stealth tier captures the
proxy once and reuses it for both the fetch and the solver (IP-coherence).

Billing: WebCrawlCreditService gains captcha_billing_enabled,
captcha_solves_to_micros, charge_captcha, and a generic check_balance, sharing
a single _apply_debit path. The indexer accumulates attempts (even on failed
crawls), runs a combined crawl+captcha pre-flight, and posts a per-attempt
owner charge as usage_type="web_crawl_captcha". The captcha worst-case is only
reserved when solving is actually enabled, so a solving-off deployment is never
blocked for captcha that can never run. Both chat scrape tools fold attempts
into the current turn before the success/fail branch.

Fully config-driven prices; no migration. New unit tests cover the config,
factory (detection/latch/timeout/cap), credit service, indexer wiring, and the
chat fold.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 22:58:21 -07:00
..
confluence refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
dropbox refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
gmail refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
google_calendar refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
google_drive refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
linear refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
mcp_oauth Harden Linear and Slack MCP subagent permissions. 2026-04-29 20:24:21 +02:00
memory refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
notion refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
onedrive refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
streaming feat: improved document, folder mentions rendering 2026-05-09 22:15:51 -07:00
__init__.py Fixed all ruff lint and formatting errors 2025-07-24 14:43:48 -07:00
ai_file_sort_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
auto_model_pin_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
auto_reload_service.py feat(refactor): refactor payment system to implement unified credit wallet. 2026-06-10 16:49:03 -07:00
billable_calls.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
chat_comments_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
chat_session_state_service.py Add chat session state service 2026-01-20 16:31:40 +02:00
composio_service.py feat: enhance task management and timeout configurations in multi-agent chat 2026-05-27 14:58:10 -07:00
connector_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
docling_service.py feat(backend): Remove LLM summaries from document indexing 2026-06-04 00:50:19 +05:30
etl_credit_service.py feat(refactor): refactor payment system to implement unified credit wallet. 2026-06-10 16:49:03 -07:00
export_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
folder_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
global_model_catalog.py refactor(model-connections): remove unused fields and update verification logic 2026-06-14 02:46:19 +05:30
image_gen_router_service.py chore: ran linting 2026-06-13 21:59:35 +05:30
kokoro_tts_service.py feat: Added Local TTS (Kokoro TTS) Support 2025-08-13 17:25:34 -07:00
llm_error_adapter.py chore: ran linting 2026-06-13 21:59:35 +05:30
llm_router_service.py feat: antropic model added fix & kb tooling fixes 2026-06-25 20:19:44 -07:00
llm_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
model_capabilities.py refactor(model-connections): move backend model connections to provider capabilities 2026-06-12 02:17:22 +05:30
model_connection_service.py refactor(model-connections): remove unused fields and update verification logic 2026-06-14 02:46:19 +05:30
model_list_service.py feat(database-migrations): add migration to remove legacy model config tables and remove stale model connection code 2026-06-13 12:45:43 +05:30
model_resolver.py feat: antropic model added fix & kb tooling fixes 2026-06-25 20:19:44 -07:00
new_streaming_service.py Include optional metadata on tool and thinking-step SSE payloads. 2026-05-08 22:47:58 +02:00
obsidian_plugin_indexer.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
openrouter_integration_service.py chore: ran linting 2026-06-13 21:59:35 +05:30
openrouter_model_normalizer.py chore: ran linting 2026-06-13 21:59:35 +05:30
pricing_registration.py feat(database-migrations): add migration to remove legacy model config tables and remove stale model connection code 2026-06-13 12:45:43 +05:30
provider_capabilities.py refactor(model-connections): move backend model connections to provider capabilities 2026-06-12 02:17:22 +05:30
provider_registry.py chore: ran linting 2026-06-13 21:59:35 +05:30
public_chat_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
quality_score.py feat(database-migrations): add migration to remove legacy model config tables and remove stale model connection code 2026-06-13 12:45:43 +05:30
quota_checked_vision_llm.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
reranker_service.py roadmap(1.3): Update citation prompt to use new whole document structure 2025-12-14 22:07:31 -08:00
revert_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
stt_service.py chore: updated docs & refactored sst_service.py 2025-10-15 14:31:38 -07:00
task_dispatcher.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
task_logging_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
token_quota_service.py feat(refactor): refactor payment system to implement unified credit wallet. 2026-06-10 16:49:03 -07:00
token_tracking_service.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
turnstile_service.py feat: no login experience and prem tokens 2026-04-15 17:02:00 -07:00
user_tool_allowlist.py refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D) 2026-06-26 18:30:47 +02:00
web_crawl_credit_service.py feat(crawler): captcha solving + per-attempt billing (Phase 3d) 2026-06-29 22:58:21 -07:00
web_search_service.py chore: ran linting 2026-03-17 04:40:46 +05:30