aboutsummaryrefslogtreecommitdiff
path: root/castle-search/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'castle-search/README.md')
-rw-r--r--castle-search/README.md84
1 files changed, 84 insertions, 0 deletions
diff --git a/castle-search/README.md b/castle-search/README.md
index f3fb5e9..accdc24 100644
--- a/castle-search/README.md
+++ b/castle-search/README.md
@@ -29,6 +29,90 @@ the model picks.
It returns titles, URLs and snippets — **search results only**. It does not fetch
the linked pages; follow up with a read/fetch tool for full content.
+## Over HTTP, for clients that are not pi
+
+`src/http.ts` serves the same search as a small HTTP service, in Open WebUI's
+"external" web search protocol: POST `{"query": "...", "count": 5}` to `/`,
+get back `[{"link", "title", "snippet"}]`.
+
+```
+CCS_SEARCH_ENGINE=duckduckgo node --experimental-strip-types src/http.ts 127.0.0.1:11158
+```
+
+Engine and browser are chosen as for the pi tool. A failed search answers
+HTTP 502 with `{"error": "<why>"}`, never an empty list, so a captcha cannot
+pass for "nothing found"; zero hits is reported as an error too, since a
+rate-limited engine serves exactly that. The message adds that the caller cannot
+switch engines, because this protocol has no field for one. There is no
+authentication: bind it to loopback (the default) or a trusted address.
+`GET /health` answers `{"status": true}`.
+
+### X.com: search, posts, profiles, trends
+
+Four reads of X (Twitter), each `POST` a JSON object and get JSON back:
+
+| Route | In | Out |
+|---|---|---|
+| `/x-search` | `query` (X's own search syntax), `count`, `sort` (`latest` or `top`) | the posts |
+| `/x-post` | `url` (a post link or its id), `replies` | the post whole, the `thread` above it when it is a reply, its top `replies` |
+| `/x-user` | `handle`, `count` | the `profile` (bio, location, website, joined, exact follower, following and post counts) and its latest posts |
+| `/x-trends` | `tab`: `trending`, `news`, `sports`, `entertainment`, `for_you` | the trends, each with a `query` for `/x-search` |
+
+Each post comes with its link, author, time, text, counts, photos (X's image
+link and alt text), videos (a still), a link card and any quoted post. A search
+result X cut short is marked `truncated`; `/x-post` reads it whole. It needs the
+browser signed in to X, since X serves none of this to anybody else, and it
+says so when it is not, rather than returning nothing. `GET /openapi.json`
+describes all four, as "X.com", so Open WebUI can offer them as tools. Free,
+where xAI's own X search charges per post returned. Trends are for the
+signed-in account's region.
+
+X keeps only the posts near the screen in the page, so it scrolls and collects
+by link, up to 20 posts (or replies). A read takes 4–7 s.
+
+All four share one set of limits, so the account reads X like a person, not a
+scraper (`src/x-limits.ts`): one read at a time, 30 s ± a random 0–25 s between them,
+drawn afresh each time (a read that comes sooner waits), and at most 30 an hour and 150 a day, beyond which a
+read fails saying when the next may run. The counts live in memory, so a
+restart starts them afresh.
+
+Signed out, it signs back in by itself when `CCS_X_LOGIN_FILE` names a JSON
+file of the account's details (`src/x-login.ts`): `username`, `password`,
+`totpSecret` (the authenticator app's base32 secret) and, optionally, `imap`
+(`host`, `user`, `password`) for the code X emails when a sign-in looks
+unusual, read from the subject over IMAP (`src/imap.ts`). Then it searches
+again, once. It tries at most once every 30 minutes, never sends the password
+twice in one try, and stops at any step it does not recognise, such as a
+captcha, saying a person has to sign in. A sign-in takes about 6 s.
+
+### YouTube transcripts
+
+`POST /youtube-transcript` `{"url": "https://youtu.be/...", "language": "en"}`
+files a YouTube video's transcript as plain text in `CCS_TRANSCRIPT_DIR`, named
+`<upload date>-<Title-With-Dashes>.txt`, and returns it with the title,
+channel, upload date and length (`src/youtube.ts`). Captions only, never the
+video: human-written when the video has them, YouTube's automatic ones
+otherwise, with the rolling repeats of automatic captions taken out. A video
+filed before is read back from the folder. yt-dlp (`CCS_YTDLP`) updates
+itself at most daily, and again when a fetch fails; when YouTube rate-limits
+captions (HTTP 429), the text comes from youtube-transcript-api
+(`CCS_YT_PYTHON`) instead. `GET /youtube/openapi.json` describes it apart from
+X.com, as "YouTube". The recipe is Hermes's, from bambos.
+
+### Video clips
+
+`POST /video` `{"prompt": "...", "kind": "fast"}` has one of DeepInfra's video
+models make a clip and files the `.mp4` in `CCS_VIDEO_DIR`, named by the time
+and the prompt's first words (`src/video.ts`). `kind` picks the model:
+`fast` (FastWan 2.2 5B, 5 s, no sound, about $0.02; the default), `quality`
+(Wan 2.2 14B, 5 s, about $0.17), `long` (LTX 2.3 Fast, 6 to 20 s with sound,
+can start from `image_url`, $0.03 a second) and `sound` (Veo 3.1 Fast, 8 s,
+with realistic sound and speech, about $1.20). `orientation` is landscape or
+portrait. Paid per clip, so at most 10 a day (counted in `CCS_VIDEO_STATE`),
+one at a time; a clip whose caller hangs up is still finished and filed,
+since it is billed anyway. The key is read from `CCS_DEEPINFRA_KEY_FILE`.
+`GET /video/openapi.json` describes it as "Video".
+
## Engines
Four, with independent indexes and independent rate limits. That last part is