mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-06 22:12:12 +02:00
feat(capabilities): add registry contracts and package
This commit is contained in:
parent
0944d9bb78
commit
78f7a93a88
2 changed files with 52 additions and 0 deletions
5
surfsense_backend/app/capabilities/__init__.py
Normal file
5
surfsense_backend/app/capabilities/__init__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
"""Scraper capability registry — typed, stateless verbs. See plans/backend/04-capabilities.md."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
__all__: list[str] = []
|
||||
47
surfsense_backend/app/capabilities/types.py
Normal file
47
surfsense_backend/app/capabilities/types.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
"""``Capability`` registry contracts shared by every verb."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from dataclasses import dataclass
|
||||
from enum import StrEnum
|
||||
from typing import TYPE_CHECKING, Any, Protocol
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
|
||||
class BillingUnit(StrEnum):
|
||||
"""The meter a verb charges on (priced by the billing service, 03c)."""
|
||||
|
||||
WEB_CRAWL = "web_crawl"
|
||||
|
||||
|
||||
class BillableOutput(Protocol):
|
||||
"""A capability output that reports its own billable count."""
|
||||
|
||||
@property
|
||||
def billable_units(self) -> int: ...
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class CapabilityContext:
|
||||
"""Request-scoped deps a capability call needs beyond its typed input."""
|
||||
|
||||
session: AsyncSession
|
||||
workspace_id: int
|
||||
|
||||
|
||||
Executor = Callable[[Any], Awaitable[Any]]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Capability:
|
||||
"""One typed verb; the source of truth the doors (05) and agent (07) read."""
|
||||
|
||||
name: str
|
||||
input_schema: type[BaseModel]
|
||||
output_schema: type[BaseModel]
|
||||
executor: Executor
|
||||
billing_unit: BillingUnit
|
||||
Loading…
Add table
Add a link
Reference in a new issue