@octen.ai/cli 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -2
- package/dist/api/constants.d.ts +61 -0
- package/dist/api/constants.js +22 -0
- package/dist/api/designSearch.d.ts +55 -0
- package/dist/api/designSearch.js +136 -0
- package/dist/api/placeSearch.d.ts +19 -0
- package/dist/api/placeSearch.js +54 -0
- package/dist/api/premierSearch.d.ts +19 -0
- package/dist/api/premierSearch.js +37 -0
- package/dist/api/verticalSearch.d.ts +41 -0
- package/dist/api/verticalSearch.js +112 -0
- package/dist/cli.js +15 -2
- package/dist/commands/designSearch.d.ts +2 -0
- package/dist/commands/designSearch.js +63 -0
- package/dist/commands/placeSearch.d.ts +2 -0
- package/dist/commands/placeSearch.js +36 -0
- package/dist/commands/premierSearch.d.ts +8 -0
- package/dist/commands/premierSearch.js +37 -0
- package/dist/commands/search.d.ts +1 -1
- package/dist/commands/search.js +5 -7
- package/dist/commands/verticalSearch.d.ts +4 -0
- package/dist/commands/verticalSearch.js +82 -0
- package/dist/output/pretty/businessSearch.d.ts +7 -0
- package/dist/output/pretty/businessSearch.js +159 -0
- package/dist/output/pretty/designSearch.d.ts +15 -0
- package/dist/output/pretty/designSearch.js +202 -0
- package/dist/output/pretty/envelope.d.ts +24 -0
- package/dist/output/pretty/envelope.js +21 -0
- package/dist/output/pretty/newsSearch.d.ts +10 -0
- package/dist/output/pretty/newsSearch.js +72 -0
- package/dist/output/pretty/placeSearch.d.ts +6 -0
- package/dist/output/pretty/placeSearch.js +87 -0
- package/dist/output/pretty/pulseSearch.d.ts +11 -0
- package/dist/output/pretty/pulseSearch.js +31 -0
- package/dist/output/pretty/search.d.ts +9 -3
- package/dist/output/pretty/search.js +26 -11
- package/dist/util/terminalText.d.ts +14 -0
- package/dist/util/terminalText.js +30 -0
- package/package.json +1 -1
- package/skills/manifest.json +1 -0
- package/skills/octen-design-search/SKILL.md +312 -0
- package/skills/octen-design-search/agents/openai.yaml +4 -0
- package/skills/octen-search/SKILL.md +53 -5
- package/skills/octen-web-search/SKILL.md +14 -2
package/README.md
CHANGED
|
@@ -297,12 +297,72 @@ Options: `-n` (result count 1–100), `--topic` (general|news), `--highlight` (+
|
|
|
297
297
|
|
|
298
298
|
### `octen news`
|
|
299
299
|
|
|
300
|
-
|
|
300
|
+
Recent news from the dedicated `/news-search` endpoint. Returns ranked articles **and** `subjects` — the coverage grouped into storylines, each with a summary and the span it covers, so "what happened with X" is answerable without reading every article.
|
|
301
301
|
|
|
302
302
|
```sh
|
|
303
303
|
octen news "OpenAI announcement" --highlight --time-range day
|
|
304
|
+
octen news "EU AI Act" --subjects-count 3
|
|
305
|
+
octen news "chip export rules" --no-subjects
|
|
304
306
|
```
|
|
305
307
|
|
|
308
|
+
Options: `-n` (1–100), `--include-domains`, `--exclude-domains`, `--language`, `--time-basis`, `--time-range`, `--start-time`, `--end-time`, `--highlight` (+`--highlight-max-tokens`), `--full-content` (+`--full-content-max-tokens`), `--subjects-count` (1–5), `--max-sub-news` (1–20), `--no-subjects`.
|
|
309
|
+
|
|
310
|
+
**`--include-domains` / `--exclude-domains` narrow the ranked articles only — never the storylines.** The storylines are built from the open web either way, so a question that restricts its sources has to be answered from the articles.
|
|
311
|
+
|
|
312
|
+
Not the same flag set as `search`: this endpoint has no `--include-text`/`--exclude-text`, `--format`, `--safesearch` or `--images`. It accepts them and ignores them, so they are not offered here.
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
### `octen business`
|
|
317
|
+
|
|
318
|
+
A company, or a person in a business context, as **structured cards** — profile, financial and stock metrics, key people and their career history, recent announcements — alongside the ranked sources.
|
|
319
|
+
|
|
320
|
+
```sh
|
|
321
|
+
octen business "NVIDIA" --highlight
|
|
322
|
+
octen business "AMD and Intel" --entities-count 2
|
|
323
|
+
octen business "Anthropic funding" --no-entities
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Options: the same retrieval flags as `news`, plus `--entities-count` (1–20), `--max-activities` (1–20), `--max-entity-news` (1–20), `--no-entities`.
|
|
327
|
+
|
|
328
|
+
Domain, time and language filters narrow the ranked sources only, never the cards.
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
### `octen place`
|
|
333
|
+
|
|
334
|
+
Real-world places as structured cards: name, category, address, coordinates, phone, website, opening hours, status, rating and review count.
|
|
335
|
+
|
|
336
|
+
```sh
|
|
337
|
+
octen place "coffee shop" --latitude 35.6812 --longitude 139.7671
|
|
338
|
+
octen place "ramen in Shinjuku"
|
|
339
|
+
octen place "museums" --city Lisbon
|
|
340
|
+
octen place "coffee shop" --latitude 35.6812 --longitude 139.7671 --max-reviews 3
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
Pass `--latitude` and `--longitude` to search around a point — each card then carries its `distance` — and `--radius` (metres, 1–50000) to cap how far. When only the city is known, use `--city` / `--region` / `--country`. A query that names its own area needs neither.
|
|
344
|
+
|
|
345
|
+
Options: `-n` (places, 1–20), `--max-reviews` (0–5, off by default), `--web` (+`--web-count`) to also return pages about these places.
|
|
346
|
+
|
|
347
|
+
The places arrive in `data.places`; `data.results` is where the optional web pages go.
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
### `octen pulse`
|
|
352
|
+
|
|
353
|
+
The URL a query most likely means, in about 10ms. One inference predicts destinations instead of searching and ranking them — for official docs, help centres and sites you could almost name.
|
|
354
|
+
|
|
355
|
+
```sh
|
|
356
|
+
octen pulse "uv documentation"
|
|
357
|
+
octen pulse "github docs" --mode standard --highlight
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Options: `--mode` (`lite`/`standard`), `-n` (1–10), `--safesearch`, `--images`, `--highlight` (+`--highlight-max-tokens`), `--full-content` (+`--full-content-max-tokens`).
|
|
361
|
+
|
|
362
|
+
`lite` (the default) returns titles and URLs only and ignores the content options; `standard` turns them on at roughly twice the latency. The API returns lite URLs **without a scheme**; the CLI puts `https://` back, so what you get is a URL you can actually open.
|
|
363
|
+
|
|
364
|
+
No domain, text, time or language filters — pulse runs no retrieval to filter. For those, use `search` or `news`.
|
|
365
|
+
|
|
306
366
|
---
|
|
307
367
|
|
|
308
368
|
### `octen broad-search`
|
|
@@ -319,6 +379,25 @@ Options: `--max-queries` (decompose into up to N sub-queries, 1–30, default 5)
|
|
|
319
379
|
|
|
320
380
|
---
|
|
321
381
|
|
|
382
|
+
### `octen premier-search`
|
|
383
|
+
|
|
384
|
+
Web Search Premier: the same search with deeper retrieval and more careful reranking behind it — for the exact page that holds an answer, a niche document, or a query `octen search` answered thinly.
|
|
385
|
+
|
|
386
|
+
```sh
|
|
387
|
+
octen premier-search "kafka default topic retention period" -n 5
|
|
388
|
+
octen premier-search "EU AI Act obligations for general-purpose models" --result-type dynamic --time-range year
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
It posts to its own endpoint, `/search-premier`, which takes the request `/search` takes and returns the same response. So the flags, the output and the JSON are `octen search`'s.
|
|
392
|
+
|
|
393
|
+
**Use `octen search` by default.** Premier takes longer, and it is billed at its own per-call rate, which a Search Plan's unlimited searches do not cover.
|
|
394
|
+
|
|
395
|
+
Options: every `octen search` flag except `--topic`, plus `--result-type` (`standard`|`dynamic`). `standard` returns results as the other flags specify; `dynamic` returns only the relevant results, up to `-n`, and adjusts the highlight length per result.
|
|
396
|
+
|
|
397
|
+
A token cap given without its switch is not dropped here: `--highlight-max-tokens` alone caps the highlights, and `--full-content-max-tokens` without `--full-content` exits 2, since it would return no content.
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
322
401
|
### `octen extract`
|
|
323
402
|
|
|
324
403
|
Extract content from one or more URLs (1–20).
|
|
@@ -428,6 +507,34 @@ Unlike `octen search` and `octen video-search`, this endpoint has no time filter
|
|
|
428
507
|
|
|
429
508
|
---
|
|
430
509
|
|
|
510
|
+
### `octen design-search`
|
|
511
|
+
|
|
512
|
+
Real designs to build from: screenshots of web pages, page sections, app screens and slides, each with the design values behind it — colours, fonts, sizes — and, for page sections, the HTML. Web results on the same query come back alongside.
|
|
513
|
+
|
|
514
|
+
```sh
|
|
515
|
+
octen design-search "saas pricing page"
|
|
516
|
+
octen design-search "landing page hero section" -n 10 --no-web
|
|
517
|
+
octen design-search "startup pitch deck slide" --no-snippet
|
|
518
|
+
octen design-search --group <group_id> -n 28
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
A page section or a slide carries the `group` it belongs to. `--group <group_id>` returns every image of that page or deck, in order, instead of searching — it needs no query, and a query given beside it drives the web results only; it does not search within the group. **It still returns five unless told otherwise**, so set `-n` to the group's `total` (the most one call returns is 100). In the terminal, each section or slide prints the command that does this.
|
|
522
|
+
|
|
523
|
+
The response has two parts, each with its own flags:
|
|
524
|
+
|
|
525
|
+
- **Design references** (`data.images`): `-n` (1–100, default 5), `--no-design-facts` (leave out the design values), `--no-snippet` (leave out the code), `--snippet-max-tokens` (100–100000), `--group <id>`. `--no-images` returns web results only.
|
|
526
|
+
- **Web results** (`data.results`): `--web-count` (1–100, default 5), `--include-domains`, `--exclude-domains`, `--language`, `--time-basis`, `--time-range`, `--start-time`, `--end-time`, `--highlight` (+`--highlight-max-tokens`), `--full-content` (+`--full-content-max-tokens`). `--no-web` returns design references only.
|
|
527
|
+
|
|
528
|
+
**The web flags narrow the web results only — never the design references.** A flag for a part that is switched off is refused rather than ignored: `--no-web --include-domains stripe.com` exits 2, because the likeliest reason to type it is expecting the screenshots to be filtered. So is a web flag on a `--group` lookup that has no query — a lookup alone returns no web results — and `--full-content-max-tokens` without `--full-content`, which would return no content.
|
|
529
|
+
|
|
530
|
+
The design values are whatever the API returned for that image, and they differ by kind: design tokens for a web page, colour and font lists for a slide, component counts for an app screen. The terminal view shortens them and the code; `--json` (or a pipe) prints both in full.
|
|
531
|
+
|
|
532
|
+
Image links are signed and expire, so download a screenshot when you get it rather than keeping its link.
|
|
533
|
+
|
|
534
|
+
`octen image-search --topic design` was removed in 0.11.0. Design search has an endpoint of its own now, and this is the command for it; `image-search` is unchanged and still takes no `--topic`.
|
|
535
|
+
|
|
536
|
+
---
|
|
537
|
+
|
|
431
538
|
### `octen video-search`
|
|
432
539
|
|
|
433
540
|
**In Beta** — contact us to request beta access.
|
|
@@ -621,7 +728,7 @@ Scripts must check the exit status, not just the output.
|
|
|
621
728
|
| Status | When |
|
|
622
729
|
|---|---|
|
|
623
730
|
| `0` | The command completed and the response was complete. |
|
|
624
|
-
| `2` | Bad input, caught before any request: a malformed number (`--count 1.5`, `--count 2junk`), an empty comma list (`--include-domains ""`), a blank query, an unknown `--scope`, or a missing API key. |
|
|
731
|
+
| `2` | Bad input, caught before any request: a malformed number (`--count 1.5`, `--count 2junk`), an empty comma list (`--include-domains ""`), a blank query, an unknown `--scope`, flags that cannot be combined (`octen design-search --no-images --no-web`), or a missing API key. |
|
|
625
732
|
| `1` | Everything else: HTTP errors, an API envelope with a non-zero `code`, a timeout, and stream failures. |
|
|
626
733
|
|
|
627
734
|
Two consequences worth knowing:
|
package/dist/api/constants.d.ts
CHANGED
|
@@ -10,6 +10,12 @@ export declare const ENDPOINTS: {
|
|
|
10
10
|
readonly chat: "/v1/chat/completions";
|
|
11
11
|
readonly imageSearch: "/image-search";
|
|
12
12
|
readonly videoSearch: "/video-search";
|
|
13
|
+
readonly newsSearch: "/news-search";
|
|
14
|
+
readonly businessSearch: "/business-search";
|
|
15
|
+
readonly placeSearch: "/place-search";
|
|
16
|
+
readonly pulseSearch: "/pulse-search";
|
|
17
|
+
readonly searchPremier: "/search-premier";
|
|
18
|
+
readonly designSearch: "/design-search";
|
|
13
19
|
};
|
|
14
20
|
export declare const EMBEDDING_MODELS: Record<string, string>;
|
|
15
21
|
export declare const VL_EMBEDDING_MODELS: Record<string, string>;
|
|
@@ -60,6 +66,59 @@ export declare const LIMITS: {
|
|
|
60
66
|
readonly min: 1;
|
|
61
67
|
readonly max: 10;
|
|
62
68
|
};
|
|
69
|
+
readonly pulseCount: {
|
|
70
|
+
readonly min: 1;
|
|
71
|
+
readonly max: 10;
|
|
72
|
+
};
|
|
73
|
+
readonly pulseQueryLength: 500;
|
|
74
|
+
readonly subjectsCount: {
|
|
75
|
+
readonly min: 1;
|
|
76
|
+
readonly max: 5;
|
|
77
|
+
};
|
|
78
|
+
readonly maxSubNews: {
|
|
79
|
+
readonly min: 1;
|
|
80
|
+
readonly max: 20;
|
|
81
|
+
};
|
|
82
|
+
readonly entitiesCount: {
|
|
83
|
+
readonly min: 1;
|
|
84
|
+
readonly max: 20;
|
|
85
|
+
};
|
|
86
|
+
readonly maxActivities: {
|
|
87
|
+
readonly min: 1;
|
|
88
|
+
readonly max: 20;
|
|
89
|
+
};
|
|
90
|
+
readonly maxEntityNews: {
|
|
91
|
+
readonly min: 1;
|
|
92
|
+
readonly max: 20;
|
|
93
|
+
};
|
|
94
|
+
readonly placesCount: {
|
|
95
|
+
readonly min: 1;
|
|
96
|
+
readonly max: 20;
|
|
97
|
+
};
|
|
98
|
+
readonly maxReviews: {
|
|
99
|
+
readonly min: 0;
|
|
100
|
+
readonly max: 5;
|
|
101
|
+
};
|
|
102
|
+
readonly placeRadius: {
|
|
103
|
+
readonly min: 1;
|
|
104
|
+
readonly max: 50000;
|
|
105
|
+
};
|
|
106
|
+
readonly latitude: {
|
|
107
|
+
readonly min: -90;
|
|
108
|
+
readonly max: 90;
|
|
109
|
+
};
|
|
110
|
+
readonly longitude: {
|
|
111
|
+
readonly min: -180;
|
|
112
|
+
readonly max: 180;
|
|
113
|
+
};
|
|
114
|
+
readonly designCount: {
|
|
115
|
+
readonly min: 1;
|
|
116
|
+
readonly max: 100;
|
|
117
|
+
};
|
|
118
|
+
readonly snippetMaxTokens: {
|
|
119
|
+
readonly min: 100;
|
|
120
|
+
readonly max: 100000;
|
|
121
|
+
};
|
|
63
122
|
};
|
|
64
123
|
export declare const TOPIC_OPTIONS: readonly ["general", "news"];
|
|
65
124
|
export declare const TIME_BASIS_OPTIONS: readonly ["auto", "published", "crawled"];
|
|
@@ -68,5 +127,7 @@ export declare const SAFESEARCH_OPTIONS: readonly ["off", "strict"];
|
|
|
68
127
|
export declare const FORMAT_OPTIONS: readonly ["text", "markdown"];
|
|
69
128
|
export declare const EXTRACT_MODE_OPTIONS: readonly ["standard", "advanced", "auto"];
|
|
70
129
|
export declare const LINK_SCOPE_OPTIONS: readonly ["prefer_internal", "prefer_external"];
|
|
130
|
+
export declare const PULSE_MODE_OPTIONS: readonly ["lite", "standard"];
|
|
131
|
+
export declare const RESULT_TYPE_OPTIONS: readonly ["standard", "dynamic"];
|
|
71
132
|
export declare const SKILLS_REPO = "Octen-Team/octen-skills";
|
|
72
133
|
export declare const SKILLS_REPO_TARBALL: (ref: string) => string;
|
package/dist/api/constants.js
CHANGED
|
@@ -10,6 +10,12 @@ export const ENDPOINTS = {
|
|
|
10
10
|
chat: "/v1/chat/completions",
|
|
11
11
|
imageSearch: "/image-search",
|
|
12
12
|
videoSearch: "/video-search",
|
|
13
|
+
newsSearch: "/news-search",
|
|
14
|
+
businessSearch: "/business-search",
|
|
15
|
+
placeSearch: "/place-search",
|
|
16
|
+
pulseSearch: "/pulse-search",
|
|
17
|
+
searchPremier: "/search-premier",
|
|
18
|
+
designSearch: "/design-search",
|
|
13
19
|
};
|
|
14
20
|
export const EMBEDDING_MODELS = {
|
|
15
21
|
"0.6b": "octen-embedding-0.6b",
|
|
@@ -36,6 +42,20 @@ export const LIMITS = {
|
|
|
36
42
|
vlVideos: 1,
|
|
37
43
|
imageCount: { min: 1, max: 10 },
|
|
38
44
|
videoCount: { min: 1, max: 10 },
|
|
45
|
+
pulseCount: { min: 1, max: 10 },
|
|
46
|
+
pulseQueryLength: 500,
|
|
47
|
+
subjectsCount: { min: 1, max: 5 },
|
|
48
|
+
maxSubNews: { min: 1, max: 20 },
|
|
49
|
+
entitiesCount: { min: 1, max: 20 },
|
|
50
|
+
maxActivities: { min: 1, max: 20 },
|
|
51
|
+
maxEntityNews: { min: 1, max: 20 },
|
|
52
|
+
placesCount: { min: 1, max: 20 },
|
|
53
|
+
maxReviews: { min: 0, max: 5 },
|
|
54
|
+
placeRadius: { min: 1, max: 50_000 },
|
|
55
|
+
latitude: { min: -90, max: 90 },
|
|
56
|
+
longitude: { min: -180, max: 180 },
|
|
57
|
+
designCount: { min: 1, max: 100 },
|
|
58
|
+
snippetMaxTokens: { min: 100, max: 100_000 },
|
|
39
59
|
};
|
|
40
60
|
export const TOPIC_OPTIONS = ["general", "news"];
|
|
41
61
|
export const TIME_BASIS_OPTIONS = ["auto", "published", "crawled"];
|
|
@@ -44,5 +64,7 @@ export const SAFESEARCH_OPTIONS = ["off", "strict"];
|
|
|
44
64
|
export const FORMAT_OPTIONS = ["text", "markdown"];
|
|
45
65
|
export const EXTRACT_MODE_OPTIONS = ["standard", "advanced", "auto"];
|
|
46
66
|
export const LINK_SCOPE_OPTIONS = ["prefer_internal", "prefer_external"];
|
|
67
|
+
export const PULSE_MODE_OPTIONS = ["lite", "standard"];
|
|
68
|
+
export const RESULT_TYPE_OPTIONS = ["standard", "dynamic"];
|
|
47
69
|
export const SKILLS_REPO = "Octen-Team/octen-skills";
|
|
48
70
|
export const SKILLS_REPO_TARBALL = (ref) => `https://github.com/${SKILLS_REPO}/archive/${ref}.tar.gz`;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type SearchResult } from "./search.js";
|
|
2
|
+
export interface DesignSearchOpts {
|
|
3
|
+
count?: number;
|
|
4
|
+
group?: string;
|
|
5
|
+
noImages?: boolean;
|
|
6
|
+
noDesignFacts?: boolean;
|
|
7
|
+
noSnippet?: boolean;
|
|
8
|
+
snippetMaxTokens?: number;
|
|
9
|
+
noWeb?: boolean;
|
|
10
|
+
webCount?: number;
|
|
11
|
+
includeDomains?: string[];
|
|
12
|
+
excludeDomains?: string[];
|
|
13
|
+
language?: string[];
|
|
14
|
+
timeBasis?: "auto" | "published" | "crawled";
|
|
15
|
+
timeRange?: string;
|
|
16
|
+
startTime?: string;
|
|
17
|
+
endTime?: string;
|
|
18
|
+
highlight?: boolean;
|
|
19
|
+
highlightMaxTokens?: number;
|
|
20
|
+
fullContent?: boolean;
|
|
21
|
+
fullContentMaxTokens?: number;
|
|
22
|
+
}
|
|
23
|
+
/** The page or deck an image belongs to. */
|
|
24
|
+
export interface DesignImageGroup {
|
|
25
|
+
group_id?: string;
|
|
26
|
+
type?: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
position?: number;
|
|
29
|
+
total?: number;
|
|
30
|
+
master?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/** One design reference. All fields optional — the server is untyped. */
|
|
33
|
+
export interface DesignImage {
|
|
34
|
+
type?: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
url?: string;
|
|
38
|
+
thumbnail?: string;
|
|
39
|
+
source_page?: string;
|
|
40
|
+
width?: number;
|
|
41
|
+
height?: number;
|
|
42
|
+
group?: DesignImageGroup;
|
|
43
|
+
design_facts?: Record<string, unknown>;
|
|
44
|
+
snippet?: {
|
|
45
|
+
format?: string;
|
|
46
|
+
code?: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Response shape for the /design-search endpoint. */
|
|
50
|
+
export interface DesignSearchResponse {
|
|
51
|
+
query?: string;
|
|
52
|
+
images?: DesignImage[];
|
|
53
|
+
results?: SearchResult[];
|
|
54
|
+
}
|
|
55
|
+
export declare function buildDesignSearchRequest(query: string, o: DesignSearchOpts): Record<string, unknown>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request builder for /design-search.
|
|
3
|
+
*
|
|
4
|
+
* The endpoint returns two groups of results and takes a block of options for
|
|
5
|
+
* each: `images` — the design references, which are what the search is for —
|
|
6
|
+
* and `web_search`, pages on the same query. Both are on unless switched off,
|
|
7
|
+
* and an option is only ever sent when the caller gave it, so the defaults
|
|
8
|
+
* stay the API's.
|
|
9
|
+
*
|
|
10
|
+
* `images.group_id` replaces the search with a lookup: every image of one page
|
|
11
|
+
* or deck, in order. A lookup needs no query.
|
|
12
|
+
*
|
|
13
|
+
* A token cap is a request for the thing it caps, so `--snippet-max-tokens`
|
|
14
|
+
* and `--highlight-max-tokens` are sent with `enable: true`. This endpoint
|
|
15
|
+
* honours a cap sent alone, but `/search` reads a block with no `enable` as
|
|
16
|
+
* switched off; saying it leaves nothing to interpretation.
|
|
17
|
+
*
|
|
18
|
+
* Refused here rather than spent on a request:
|
|
19
|
+
* - nothing to search for and no group to fetch;
|
|
20
|
+
* - a group with the images switched off;
|
|
21
|
+
* - both groups switched off — the API answers that with an empty success
|
|
22
|
+
* that still counts as a search;
|
|
23
|
+
* - an option for a group that is switched off, which does nothing at the API
|
|
24
|
+
* and is usually typed in the belief that it applies to the other group;
|
|
25
|
+
* - a web option on a lookup that has no query, which returns no web results
|
|
26
|
+
* for it to apply to;
|
|
27
|
+
* - a full-content cap without `--full-content`, which returns no content.
|
|
28
|
+
*/
|
|
29
|
+
import { LIMITS, TIME_BASIS_OPTIONS, TIME_RANGE_OPTIONS } from "./constants.js";
|
|
30
|
+
import { OctenValidationError } from "./errors.js";
|
|
31
|
+
import { assertRange, normalizeTimeBound, validateEnum } from "./search.js";
|
|
32
|
+
/** The first option in the list that the caller actually gave. */
|
|
33
|
+
function firstGiven(options) {
|
|
34
|
+
return options.find(([, v]) => v != null && v !== false)?.[0];
|
|
35
|
+
}
|
|
36
|
+
/** An object of the fields that were given, or undefined when none were. */
|
|
37
|
+
function block(fields) {
|
|
38
|
+
const set = fields.filter(([, v]) => v != null);
|
|
39
|
+
return set.length ? Object.fromEntries(set) : undefined;
|
|
40
|
+
}
|
|
41
|
+
export function buildDesignSearchRequest(query, o) {
|
|
42
|
+
const hasQuery = query.trim().length > 0;
|
|
43
|
+
// Trimmed before it is checked, so the id that was checked is the id sent.
|
|
44
|
+
const group = o.group?.trim();
|
|
45
|
+
if (o.group != null && !group)
|
|
46
|
+
throw new OctenValidationError("--group must not be empty");
|
|
47
|
+
if (!hasQuery && !group)
|
|
48
|
+
throw new OctenValidationError("give a query, or --group <id> to fetch every image of one page or deck");
|
|
49
|
+
if (group && o.noImages)
|
|
50
|
+
throw new OctenValidationError("--group returns images, so it cannot be combined with --no-images");
|
|
51
|
+
if (o.noImages && o.noWeb)
|
|
52
|
+
throw new OctenValidationError("--no-images and --no-web together leave nothing to return");
|
|
53
|
+
const imageOnly = [
|
|
54
|
+
["--count", o.count],
|
|
55
|
+
["--no-design-facts", o.noDesignFacts],
|
|
56
|
+
["--no-snippet", o.noSnippet],
|
|
57
|
+
["--snippet-max-tokens", o.snippetMaxTokens],
|
|
58
|
+
];
|
|
59
|
+
const webOnly = [
|
|
60
|
+
["--web-count", o.webCount],
|
|
61
|
+
["--include-domains", o.includeDomains],
|
|
62
|
+
["--exclude-domains", o.excludeDomains],
|
|
63
|
+
["--language", o.language],
|
|
64
|
+
["--time-basis", o.timeBasis],
|
|
65
|
+
["--time-range", o.timeRange],
|
|
66
|
+
["--start-time", o.startTime],
|
|
67
|
+
["--end-time", o.endTime],
|
|
68
|
+
["--highlight", o.highlight],
|
|
69
|
+
["--highlight-max-tokens", o.highlightMaxTokens],
|
|
70
|
+
["--full-content", o.fullContent],
|
|
71
|
+
["--full-content-max-tokens", o.fullContentMaxTokens],
|
|
72
|
+
];
|
|
73
|
+
const strayImage = o.noImages ? firstGiven(imageOnly) : undefined;
|
|
74
|
+
if (strayImage)
|
|
75
|
+
throw new OctenValidationError(`${strayImage} applies to the design references, which --no-images switches off`);
|
|
76
|
+
const strayWeb = o.noWeb ? firstGiven(webOnly) : undefined;
|
|
77
|
+
if (strayWeb)
|
|
78
|
+
throw new OctenValidationError(`${strayWeb} applies to the web results, which --no-web switches off`);
|
|
79
|
+
// A lookup with no query returns no web results, so a web option beside it
|
|
80
|
+
// has nothing to apply to — and it does not reach the images either.
|
|
81
|
+
const idleWeb = group && !hasQuery && !o.noWeb ? firstGiven(webOnly) : undefined;
|
|
82
|
+
if (idleWeb)
|
|
83
|
+
throw new OctenValidationError(`${idleWeb} applies to the web results, which need a query — a group lookup alone returns none`);
|
|
84
|
+
if (o.noSnippet && o.snippetMaxTokens != null)
|
|
85
|
+
throw new OctenValidationError("--snippet-max-tokens has no effect with --no-snippet");
|
|
86
|
+
if (o.fullContentMaxTokens != null && !o.fullContent)
|
|
87
|
+
throw new OctenValidationError("--full-content-max-tokens needs --full-content — full content is off unless asked for");
|
|
88
|
+
assertRange("count", o.count, LIMITS.designCount);
|
|
89
|
+
assertRange("snippet-max-tokens", o.snippetMaxTokens, LIMITS.snippetMaxTokens);
|
|
90
|
+
assertRange("web-count", o.webCount, LIMITS.searchCount);
|
|
91
|
+
assertRange("highlight-max-tokens", o.highlightMaxTokens, LIMITS.highlightMaxTokens);
|
|
92
|
+
assertRange("full-content-max-tokens", o.fullContentMaxTokens, LIMITS.fullContentMaxTokens);
|
|
93
|
+
validateEnum("--time-basis", o.timeBasis, TIME_BASIS_OPTIONS);
|
|
94
|
+
validateEnum("--time-range", o.timeRange, TIME_RANGE_OPTIONS);
|
|
95
|
+
const req = {};
|
|
96
|
+
// Sent as typed; a query of only whitespace beside a group is not sent at all.
|
|
97
|
+
if (hasQuery)
|
|
98
|
+
req.query = query;
|
|
99
|
+
const images = o.noImages
|
|
100
|
+
? { enable: false }
|
|
101
|
+
: block([
|
|
102
|
+
["count", o.count],
|
|
103
|
+
["design_facts", o.noDesignFacts ? false : undefined],
|
|
104
|
+
[
|
|
105
|
+
"snippet",
|
|
106
|
+
o.noSnippet
|
|
107
|
+
? { enable: false }
|
|
108
|
+
: o.snippetMaxTokens != null ? { enable: true, max_tokens: o.snippetMaxTokens } : undefined,
|
|
109
|
+
],
|
|
110
|
+
["group_id", group],
|
|
111
|
+
]);
|
|
112
|
+
if (images)
|
|
113
|
+
req.images = images;
|
|
114
|
+
const web = o.noWeb
|
|
115
|
+
? { enable: false }
|
|
116
|
+
: block([
|
|
117
|
+
["count", o.webCount],
|
|
118
|
+
["include_domains", o.includeDomains],
|
|
119
|
+
["exclude_domains", o.excludeDomains],
|
|
120
|
+
["language", o.language],
|
|
121
|
+
["time_basis", o.timeBasis],
|
|
122
|
+
["time_range", o.timeRange],
|
|
123
|
+
["start_time", normalizeTimeBound("--start-time", o.startTime, false)],
|
|
124
|
+
["end_time", normalizeTimeBound("--end-time", o.endTime, true)],
|
|
125
|
+
[
|
|
126
|
+
"highlight",
|
|
127
|
+
o.highlight || o.highlightMaxTokens != null
|
|
128
|
+
? { enable: true, ...block([["max_tokens", o.highlightMaxTokens]]) }
|
|
129
|
+
: undefined,
|
|
130
|
+
],
|
|
131
|
+
["full_content", o.fullContent ? { enable: true, ...block([["max_tokens", o.fullContentMaxTokens]]) } : undefined],
|
|
132
|
+
]);
|
|
133
|
+
if (web)
|
|
134
|
+
req.web_search = web;
|
|
135
|
+
return req;
|
|
136
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface PlaceSearchOpts {
|
|
2
|
+
latitude?: number;
|
|
3
|
+
longitude?: number;
|
|
4
|
+
radius?: number;
|
|
5
|
+
city?: string;
|
|
6
|
+
region?: string;
|
|
7
|
+
country?: string;
|
|
8
|
+
count?: number;
|
|
9
|
+
maxReviews?: number;
|
|
10
|
+
web?: boolean;
|
|
11
|
+
webCount?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface PlaceSearchResponse {
|
|
14
|
+
query?: string;
|
|
15
|
+
location?: Record<string, unknown> | null;
|
|
16
|
+
places?: Array<Record<string, unknown>>;
|
|
17
|
+
results?: Array<Record<string, unknown>>;
|
|
18
|
+
}
|
|
19
|
+
export declare function buildPlaceSearchRequest(query: string, o: PlaceSearchOpts): Record<string, unknown>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request builder for /place-search.
|
|
3
|
+
*
|
|
4
|
+
* Not a search variant: it shares no options with `/search`. It takes a point
|
|
5
|
+
* (`latitude` + `longitude`, optionally capped by `radius`), or an approximate
|
|
6
|
+
* `user_location` when only the city is known, or neither when the query names
|
|
7
|
+
* its own area. Web results are off by default and nest under `web_search` —
|
|
8
|
+
* the inverse of the other endpoints, where the pages are the answer.
|
|
9
|
+
*
|
|
10
|
+
* Half a coordinate pair, or a radius with no point, is refused here rather
|
|
11
|
+
* than spent on a round trip the API answers with a 400.
|
|
12
|
+
*/
|
|
13
|
+
import { LIMITS } from "./constants.js";
|
|
14
|
+
import { OctenValidationError } from "./errors.js";
|
|
15
|
+
import { assertRange } from "./search.js";
|
|
16
|
+
export function buildPlaceSearchRequest(query, o) {
|
|
17
|
+
if (!query.trim())
|
|
18
|
+
throw new OctenValidationError("query is required");
|
|
19
|
+
const hasLat = o.latitude != null;
|
|
20
|
+
const hasLon = o.longitude != null;
|
|
21
|
+
if (hasLat !== hasLon) {
|
|
22
|
+
const missing = hasLat ? "--longitude" : "--latitude";
|
|
23
|
+
throw new OctenValidationError(`${missing} is required when the other is given — a point needs both`);
|
|
24
|
+
}
|
|
25
|
+
if (o.radius != null && !hasLat)
|
|
26
|
+
throw new OctenValidationError("--radius needs --latitude and --longitude — it measures from that point");
|
|
27
|
+
assertRange("latitude", o.latitude, LIMITS.latitude);
|
|
28
|
+
assertRange("longitude", o.longitude, LIMITS.longitude);
|
|
29
|
+
assertRange("radius", o.radius, LIMITS.placeRadius);
|
|
30
|
+
assertRange("count", o.count, LIMITS.placesCount);
|
|
31
|
+
assertRange("max-reviews", o.maxReviews, LIMITS.maxReviews);
|
|
32
|
+
assertRange("web-count", o.webCount, LIMITS.searchCount);
|
|
33
|
+
const req = { query };
|
|
34
|
+
const put = (k, v) => { if (v != null)
|
|
35
|
+
req[k] = v; };
|
|
36
|
+
put("latitude", o.latitude);
|
|
37
|
+
put("longitude", o.longitude);
|
|
38
|
+
put("radius", o.radius);
|
|
39
|
+
// `user_location` is the fallback when coordinates are unknown. The API
|
|
40
|
+
// takes it as an approximate place, so it is only sent when something was
|
|
41
|
+
// actually given for it.
|
|
42
|
+
const loc = [["city", o.city], ["region", o.region], ["country", o.country]]
|
|
43
|
+
.filter(([, v]) => v != null);
|
|
44
|
+
if (loc.length)
|
|
45
|
+
req.user_location = { type: "approximate", ...Object.fromEntries(loc) };
|
|
46
|
+
const places = [["count", o.count], ["max_reviews", o.maxReviews]].filter(([, v]) => v != null);
|
|
47
|
+
if (places.length)
|
|
48
|
+
req.places = Object.fromEntries(places);
|
|
49
|
+
// Off unless asked for, matching the server. `--web-count` alone does not
|
|
50
|
+
// turn it on: a count without `--web` would otherwise read as enabling it.
|
|
51
|
+
if (o.web)
|
|
52
|
+
req.web_search = { enable: true, ...(o.webCount != null ? { count: o.webCount } : {}) };
|
|
53
|
+
return req;
|
|
54
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request builder for /search-premier.
|
|
3
|
+
*
|
|
4
|
+
* The API reference gives this endpoint the request body of `/search`, so the
|
|
5
|
+
* shared options go through the search builder rather than a second copy of
|
|
6
|
+
* it. Kept here are the places where this command differs from `search`:
|
|
7
|
+
*
|
|
8
|
+
* - `result_type`, which the reference documents and `search` does not offer;
|
|
9
|
+
* - `topic`, which is `search`'s own and is never forwarded;
|
|
10
|
+
* - a token cap given without its switch. The search builder sends a cap only
|
|
11
|
+
* beside `--highlight` / `--full-content` and drops it otherwise. Here a
|
|
12
|
+
* highlight cap is sent, and a full-content cap is refused — see below.
|
|
13
|
+
*/
|
|
14
|
+
import { RESULT_TYPE_OPTIONS } from "./constants.js";
|
|
15
|
+
import { type SearchOpts } from "./search.js";
|
|
16
|
+
export interface PremierSearchOpts extends Omit<SearchOpts, "topic"> {
|
|
17
|
+
resultType?: (typeof RESULT_TYPE_OPTIONS)[number];
|
|
18
|
+
}
|
|
19
|
+
export declare function buildPremierSearchRequest(query: string, o: PremierSearchOpts): Record<string, unknown>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request builder for /search-premier.
|
|
3
|
+
*
|
|
4
|
+
* The API reference gives this endpoint the request body of `/search`, so the
|
|
5
|
+
* shared options go through the search builder rather than a second copy of
|
|
6
|
+
* it. Kept here are the places where this command differs from `search`:
|
|
7
|
+
*
|
|
8
|
+
* - `result_type`, which the reference documents and `search` does not offer;
|
|
9
|
+
* - `topic`, which is `search`'s own and is never forwarded;
|
|
10
|
+
* - a token cap given without its switch. The search builder sends a cap only
|
|
11
|
+
* beside `--highlight` / `--full-content` and drops it otherwise. Here a
|
|
12
|
+
* highlight cap is sent, and a full-content cap is refused — see below.
|
|
13
|
+
*/
|
|
14
|
+
import { RESULT_TYPE_OPTIONS } from "./constants.js";
|
|
15
|
+
import { OctenValidationError } from "./errors.js";
|
|
16
|
+
import { buildSearchOptions, validateEnum } from "./search.js";
|
|
17
|
+
export function buildPremierSearchRequest(query, o) {
|
|
18
|
+
if (query.trim().length === 0)
|
|
19
|
+
throw new OctenValidationError("query is required");
|
|
20
|
+
validateEnum("--result-type", o.resultType, RESULT_TYPE_OPTIONS);
|
|
21
|
+
// Full content is off unless asked for, and the API returns none for a cap
|
|
22
|
+
// sent alone. Dropping the cap would hide that; switching a billed option on
|
|
23
|
+
// from a flag that did not name it would be worse.
|
|
24
|
+
if (o.fullContentMaxTokens != null && !o.fullContent)
|
|
25
|
+
throw new OctenValidationError("--full-content-max-tokens needs --full-content — full content is off unless asked for");
|
|
26
|
+
// Dropped by name, not by type: an options object built for `search` would
|
|
27
|
+
// otherwise carry its `topic` straight through.
|
|
28
|
+
const { topic: _topic, resultType, ...shared } = o;
|
|
29
|
+
// A highlight cap is a request for highlights of that length, so it is sent
|
|
30
|
+
// as one. It has to carry `enable`: the API returns no highlights at all for
|
|
31
|
+
// a `highlight` block without it, whatever the documented default.
|
|
32
|
+
const highlight = shared.highlight || shared.highlightMaxTokens != null;
|
|
33
|
+
const req = { query, ...buildSearchOptions({ ...shared, highlight }) };
|
|
34
|
+
if (resultType != null)
|
|
35
|
+
req.result_type = resultType;
|
|
36
|
+
return req;
|
|
37
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Options common to /news-search and /business-search. */
|
|
2
|
+
export interface VerticalSearchOpts {
|
|
3
|
+
count?: number;
|
|
4
|
+
includeDomains?: string[];
|
|
5
|
+
excludeDomains?: string[];
|
|
6
|
+
language?: string[];
|
|
7
|
+
timeBasis?: "auto" | "published" | "crawled";
|
|
8
|
+
timeRange?: string;
|
|
9
|
+
startTime?: string;
|
|
10
|
+
endTime?: string;
|
|
11
|
+
highlight?: boolean;
|
|
12
|
+
highlightMaxTokens?: number;
|
|
13
|
+
fullContent?: boolean;
|
|
14
|
+
fullContentMaxTokens?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface NewsSearchOpts extends VerticalSearchOpts {
|
|
17
|
+
subjects?: boolean;
|
|
18
|
+
noSubjects?: boolean;
|
|
19
|
+
subjectsCount?: number;
|
|
20
|
+
maxSubNews?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface BusinessSearchOpts extends VerticalSearchOpts {
|
|
23
|
+
entities?: boolean;
|
|
24
|
+
noEntities?: boolean;
|
|
25
|
+
entitiesCount?: number;
|
|
26
|
+
maxActivities?: number;
|
|
27
|
+
maxEntityNews?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface PulseSearchOpts {
|
|
30
|
+
mode?: "lite" | "standard";
|
|
31
|
+
count?: number;
|
|
32
|
+
safesearch?: "off" | "strict";
|
|
33
|
+
images?: boolean;
|
|
34
|
+
highlight?: boolean;
|
|
35
|
+
highlightMaxTokens?: number;
|
|
36
|
+
fullContent?: boolean;
|
|
37
|
+
fullContentMaxTokens?: number;
|
|
38
|
+
}
|
|
39
|
+
export declare function buildNewsSearchRequest(query: string, o: NewsSearchOpts): Record<string, unknown>;
|
|
40
|
+
export declare function buildBusinessSearchRequest(query: string, o: BusinessSearchOpts): Record<string, unknown>;
|
|
41
|
+
export declare function buildPulseSearchRequest(query: string, o: PulseSearchOpts): Record<string, unknown>;
|