SurfSense/surfsense_backend/app/capabilities/youtube/comments/schemas.py
DESKTOP-RTLN3BA\$punk 80927a2872 feat(billing): meter platform scrapers per item; consolidate web scraping onto web.crawl
Add per-item, per-platform billing for the platform-native connectors (Reddit, Google Search, Google Maps places/reviews, YouTube videos/comments) through the capability gate/charge seam. Rates are config-driven with a shared wallet-credit module (wallet_credit) and a dedicated PlatformScrapeCreditService; agent and REST capability runs now record cost_micros. Google Maps scrape dual-meters places and attached reviews.

Remove the main-agent scrape_webpage tool now that the web.crawl capability covers single-page (maxCrawlDepth=0) and site crawling. The main agent now reaches crawling via task(web_crawler, ...). Update prompts, tool catalog, receipts, skills, proprietary docs, and tests; drop the obsolete chat-turn crawl fold path.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-05 17:08:01 -07:00

55 lines
1.6 KiB
Python

"""``youtube.comments`` I/O contracts.
A lean surface over ``YouTubeCommentsInput``; the scraper's ``CommentItem`` is
reused verbatim as the output element.
"""
from __future__ import annotations
from typing import Literal
from pydantic import BaseModel, Field
from app.proprietary.platforms.youtube import CommentItem
MAX_COMMENT_VIDEOS = 20
"""Per-call cap on how many video URLs one request may harvest comments from."""
class CommentsInput(BaseModel):
urls: list[str] = Field(
min_length=1,
max_length=MAX_COMMENT_VIDEOS,
description="YouTube video URLs to fetch comments (and replies) for (1-20).",
)
max_comments: int = Field(
default=20,
ge=1,
le=100_000,
description=(
"Max items returned per video, counting both top-level comments and "
"their replies."
),
)
sort_by: Literal["TOP_COMMENTS", "NEWEST_FIRST"] = Field(
default="NEWEST_FIRST",
description="Comment ordering: most-liked first, or most-recent first.",
)
@property
def estimated_units(self) -> int:
"""Worst-case billable comments for the pre-flight gate: up to
``max_comments`` per video URL."""
return len(self.urls) * self.max_comments
class CommentsOutput(BaseModel):
items: list[CommentItem] = Field(
default_factory=list,
description="One item per comment or reply, in the scraper's emission order.",
)
@property
def billable_units(self) -> int:
"""One returned comment or reply = one billable unit."""
return len(self.items)