okami.mom/web-extract-go

git clone https://git.nkp.pet/okami.mom/web-extract-go

nekomimi.petweb-extract: the Go service running on the Mac mini (vassago)5a90548

main
876 B19 linesraw
1import type { Endpoint } from "./types"
2
3export type QueryFields = {
4  endpoint: Endpoint; query: string; urls: string; domains: string; count: number;
5  highlights: boolean; summary: boolean; text: boolean; characters: number
6}
7export function buildQuery(f: QueryFields) {
8  const contents = {
9    text: f.text ? { maxCharacters: f.characters } : false,
10    highlights: f.highlights ? { query: f.query.trim(), maxCharacters: f.characters } : false,
11    summary: f.summary ? { query: f.query.trim() } : false,
12  }
13  switch (f.endpoint) {
14    case "search": return { query: f.query.trim(), numResults: f.count,
15      ...(f.domains.trim() ? { includeDomains: f.domains.trim().split(/[\s,]+/) } : {}), contents }
16    case "contents": return { urls: f.urls.trim().split(/\s+/).filter(Boolean), ...contents }
17    case "answer": return { query: f.query.trim(), text: f.text }
18  }
19}