wrolpi/modules/ai/schema.py
Roland cfce0a1224
ai: kind-generic search_files / get_file / read_content
Small models carry every tool definition on every request, and the
per-kind trios (four searches, three getters, three readers) cost a
quarter of an 8k context while giving the model near-duplicate choices.
Three generic endpoints replace them:

- POST files/search: one search over videos, archives, and docs with an
  optional kind; channel (name or id), domain, author, subject each
  imply their kind and are ignored for other kinds.  When the term also
  names channels/domains/authors, they are returned as `matches` so the
  model can narrow without a second tool.  Channels resolve by name, so
  the library map already in the prompt is enough: no list call first.
- GET files/{id}: detail by id whatever the kind; videos now report
  has_captions/has_comments and the full description, archives keep
  their snapshot history.
- GET files/{id}/content?part=text|comments: captions, page text, or
  comments, paged; a wrong part for the kind says what the file is.

Inventories take an optional slug on GET /inventories (one tool lists
and fetches).  Listings are slimmed: no derivable captions/text links,
no size/mimetype, duration as H:MM:SS, published as a date.  The
library map gains the tag names.

wrolpi_mcp keeps every existing tool name; the wrappers now call the
generic routes, and search_files/get_file/read_content are exposed too.
The old per-kind endpoints remain until the modes switch over.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-24 18:23:26 -06:00

104 lines
2.4 KiB
Python

import dataclasses
from typing import List, Optional
@dataclasses.dataclass
class AISearchRequest:
search_str: Optional[str] = None
limit: int = 5
offset: int = 0
mimetypes: Optional[List[str]] = None
tag_names: Optional[List[str]] = None
@dataclasses.dataclass
class AIVideoSearchRequest:
search_str: Optional[str] = None
limit: int = 5
offset: int = 0
channel_id: Optional[int] = None
tag_names: Optional[List[str]] = None
@dataclasses.dataclass
class AIArchiveSearchRequest:
search_str: Optional[str] = None
limit: int = 5
offset: int = 0
domain: Optional[str] = None
tag_names: Optional[List[str]] = None
@dataclasses.dataclass
class AIDocSearchRequest:
search_str: Optional[str] = None
author: Optional[str] = None
subject: Optional[str] = None
language: Optional[str] = None
mimetype: Optional[str] = None
limit: int = 5
offset: int = 0
tag_names: Optional[List[str]] = None
@dataclasses.dataclass
class AIZimSearchRequest:
search_str: Optional[str] = None
zim_id: Optional[int] = None
limit: int = 5
offset: int = 0
@dataclasses.dataclass
class AIHelpSearchRequest:
search_str: Optional[str] = None
limit: int = 5
@dataclasses.dataclass
class AIManageSettingsRequest:
enabled: Optional[bool] = None
active_model: Optional[str] = None
idle_unload_minutes: Optional[int] = None
context_size: Optional[int] = None
@dataclasses.dataclass
class AISearchResponse:
results: list = dataclasses.field(default_factory=list)
total: int = 0
@dataclasses.dataclass
class AIPagedTextResponse:
content: str = ''
next_offset: Optional[int] = None
total_chars: int = 0
@dataclasses.dataclass
class AIListFilesResponse:
path: str = ''
directories: list = dataclasses.field(default_factory=list)
files: list = dataclasses.field(default_factory=list)
total: int = 0
next_offset: Optional[int] = None
@dataclasses.dataclass
class AISearchSuggestionsRequest:
search_str: Optional[str] = None
tag_names: List[str] = dataclasses.field(default_factory=list)
@dataclasses.dataclass
class AIFileSearchRequest:
search_str: Optional[str] = None
kind: Optional[str] = None
channel: Optional[str] = None
domain: Optional[str] = None
author: Optional[str] = None
subject: Optional[str] = None
tag_names: Optional[List[str]] = None
limit: int = 5
offset: int = 0