@octen.ai/cli 0.11.0 → 0.12.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 +61 -1
- package/dist/api/constants.d.ts +50 -0
- package/dist/api/constants.js +17 -0
- package/dist/api/placeSearch.d.ts +19 -0
- package/dist/api/placeSearch.js +54 -0
- package/dist/api/verticalSearch.d.ts +41 -0
- package/dist/api/verticalSearch.js +112 -0
- package/dist/cli.js +6 -1
- package/dist/commands/placeSearch.d.ts +2 -0
- package/dist/commands/placeSearch.js +36 -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/envelope.d.ts +22 -0
- package/dist/output/pretty/envelope.js +17 -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/package.json +1 -1
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`
|
package/dist/api/constants.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ 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";
|
|
13
17
|
};
|
|
14
18
|
export declare const EMBEDDING_MODELS: Record<string, string>;
|
|
15
19
|
export declare const VL_EMBEDDING_MODELS: Record<string, string>;
|
|
@@ -60,6 +64,51 @@ export declare const LIMITS: {
|
|
|
60
64
|
readonly min: 1;
|
|
61
65
|
readonly max: 10;
|
|
62
66
|
};
|
|
67
|
+
readonly pulseCount: {
|
|
68
|
+
readonly min: 1;
|
|
69
|
+
readonly max: 10;
|
|
70
|
+
};
|
|
71
|
+
readonly pulseQueryLength: 500;
|
|
72
|
+
readonly subjectsCount: {
|
|
73
|
+
readonly min: 1;
|
|
74
|
+
readonly max: 5;
|
|
75
|
+
};
|
|
76
|
+
readonly maxSubNews: {
|
|
77
|
+
readonly min: 1;
|
|
78
|
+
readonly max: 20;
|
|
79
|
+
};
|
|
80
|
+
readonly entitiesCount: {
|
|
81
|
+
readonly min: 1;
|
|
82
|
+
readonly max: 20;
|
|
83
|
+
};
|
|
84
|
+
readonly maxActivities: {
|
|
85
|
+
readonly min: 1;
|
|
86
|
+
readonly max: 20;
|
|
87
|
+
};
|
|
88
|
+
readonly maxEntityNews: {
|
|
89
|
+
readonly min: 1;
|
|
90
|
+
readonly max: 20;
|
|
91
|
+
};
|
|
92
|
+
readonly placesCount: {
|
|
93
|
+
readonly min: 1;
|
|
94
|
+
readonly max: 20;
|
|
95
|
+
};
|
|
96
|
+
readonly maxReviews: {
|
|
97
|
+
readonly min: 0;
|
|
98
|
+
readonly max: 5;
|
|
99
|
+
};
|
|
100
|
+
readonly placeRadius: {
|
|
101
|
+
readonly min: 1;
|
|
102
|
+
readonly max: 50000;
|
|
103
|
+
};
|
|
104
|
+
readonly latitude: {
|
|
105
|
+
readonly min: -90;
|
|
106
|
+
readonly max: 90;
|
|
107
|
+
};
|
|
108
|
+
readonly longitude: {
|
|
109
|
+
readonly min: -180;
|
|
110
|
+
readonly max: 180;
|
|
111
|
+
};
|
|
63
112
|
};
|
|
64
113
|
export declare const TOPIC_OPTIONS: readonly ["general", "news"];
|
|
65
114
|
export declare const TIME_BASIS_OPTIONS: readonly ["auto", "published", "crawled"];
|
|
@@ -68,5 +117,6 @@ export declare const SAFESEARCH_OPTIONS: readonly ["off", "strict"];
|
|
|
68
117
|
export declare const FORMAT_OPTIONS: readonly ["text", "markdown"];
|
|
69
118
|
export declare const EXTRACT_MODE_OPTIONS: readonly ["standard", "advanced", "auto"];
|
|
70
119
|
export declare const LINK_SCOPE_OPTIONS: readonly ["prefer_internal", "prefer_external"];
|
|
120
|
+
export declare const PULSE_MODE_OPTIONS: readonly ["lite", "standard"];
|
|
71
121
|
export declare const SKILLS_REPO = "Octen-Team/octen-skills";
|
|
72
122
|
export declare const SKILLS_REPO_TARBALL: (ref: string) => string;
|
package/dist/api/constants.js
CHANGED
|
@@ -10,6 +10,10 @@ 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",
|
|
13
17
|
};
|
|
14
18
|
export const EMBEDDING_MODELS = {
|
|
15
19
|
"0.6b": "octen-embedding-0.6b",
|
|
@@ -36,6 +40,18 @@ export const LIMITS = {
|
|
|
36
40
|
vlVideos: 1,
|
|
37
41
|
imageCount: { min: 1, max: 10 },
|
|
38
42
|
videoCount: { min: 1, max: 10 },
|
|
43
|
+
pulseCount: { min: 1, max: 10 },
|
|
44
|
+
pulseQueryLength: 500,
|
|
45
|
+
subjectsCount: { min: 1, max: 5 },
|
|
46
|
+
maxSubNews: { min: 1, max: 20 },
|
|
47
|
+
entitiesCount: { min: 1, max: 20 },
|
|
48
|
+
maxActivities: { min: 1, max: 20 },
|
|
49
|
+
maxEntityNews: { min: 1, max: 20 },
|
|
50
|
+
placesCount: { min: 1, max: 20 },
|
|
51
|
+
maxReviews: { min: 0, max: 5 },
|
|
52
|
+
placeRadius: { min: 1, max: 50_000 },
|
|
53
|
+
latitude: { min: -90, max: 90 },
|
|
54
|
+
longitude: { min: -180, max: 180 },
|
|
39
55
|
};
|
|
40
56
|
export const TOPIC_OPTIONS = ["general", "news"];
|
|
41
57
|
export const TIME_BASIS_OPTIONS = ["auto", "published", "crawled"];
|
|
@@ -44,5 +60,6 @@ export const SAFESEARCH_OPTIONS = ["off", "strict"];
|
|
|
44
60
|
export const FORMAT_OPTIONS = ["text", "markdown"];
|
|
45
61
|
export const EXTRACT_MODE_OPTIONS = ["standard", "advanced", "auto"];
|
|
46
62
|
export const LINK_SCOPE_OPTIONS = ["prefer_internal", "prefer_external"];
|
|
63
|
+
export const PULSE_MODE_OPTIONS = ["lite", "standard"];
|
|
47
64
|
export const SKILLS_REPO = "Octen-Team/octen-skills";
|
|
48
65
|
export const SKILLS_REPO_TARBALL = (ref) => `https://github.com/${SKILLS_REPO}/archive/${ref}.tar.gz`;
|
|
@@ -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,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>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request builders for the three search verticals that post to their own
|
|
3
|
+
* endpoints: /news-search, /business-search and /pulse-search.
|
|
4
|
+
*
|
|
5
|
+
* They are not `/search` with a flag. Each takes a subset of the shared
|
|
6
|
+
* retrieval options plus one structured block of its own, and the subsets
|
|
7
|
+
* differ — news and business drop `include_text`/`exclude_text`, `format`,
|
|
8
|
+
* `safesearch` and `include_images`, while pulse drops the domain, text, time
|
|
9
|
+
* and language filters entirely because it runs no retrieval to filter.
|
|
10
|
+
*
|
|
11
|
+
* The API accepts the dropped parameters and ignores them rather than
|
|
12
|
+
* erroring, which is why they are picked explicitly here instead of being
|
|
13
|
+
* derived from `SearchOpts` by omission. Forwarding a parameter the endpoint
|
|
14
|
+
* silently drops is worse than refusing it: the caller gets results that do
|
|
15
|
+
* not reflect what they asked for, with nothing to indicate why.
|
|
16
|
+
*/
|
|
17
|
+
import { LIMITS, PULSE_MODE_OPTIONS, SAFESEARCH_OPTIONS, TIME_BASIS_OPTIONS, TIME_RANGE_OPTIONS, } from "./constants.js";
|
|
18
|
+
import { OctenValidationError } from "./errors.js";
|
|
19
|
+
import { assertRange, normalizeTimeBound, validateEnum } from "./search.js";
|
|
20
|
+
/** Shared validation + field mapping for news and business. */
|
|
21
|
+
function buildVerticalOptions(o) {
|
|
22
|
+
if (o.count != null && (o.count < LIMITS.searchCount.min || o.count > LIMITS.searchCount.max))
|
|
23
|
+
throw new OctenValidationError(`count must be ${LIMITS.searchCount.min}-${LIMITS.searchCount.max}`);
|
|
24
|
+
assertRange("highlight-max-tokens", o.highlightMaxTokens, LIMITS.highlightMaxTokens);
|
|
25
|
+
assertRange("full-content-max-tokens", o.fullContentMaxTokens, LIMITS.fullContentMaxTokens);
|
|
26
|
+
validateEnum("--time-basis", o.timeBasis, TIME_BASIS_OPTIONS);
|
|
27
|
+
validateEnum("--time-range", o.timeRange, TIME_RANGE_OPTIONS);
|
|
28
|
+
const req = {};
|
|
29
|
+
const put = (k, v) => { if (v != null)
|
|
30
|
+
req[k] = v; };
|
|
31
|
+
put("count", o.count);
|
|
32
|
+
put("include_domains", o.includeDomains);
|
|
33
|
+
put("exclude_domains", o.excludeDomains);
|
|
34
|
+
put("language", o.language);
|
|
35
|
+
put("time_basis", o.timeBasis);
|
|
36
|
+
put("time_range", o.timeRange);
|
|
37
|
+
put("start_time", normalizeTimeBound("--start-time", o.startTime, false));
|
|
38
|
+
put("end_time", normalizeTimeBound("--end-time", o.endTime, true));
|
|
39
|
+
if (o.highlight)
|
|
40
|
+
req.highlight = { enable: true, ...(o.highlightMaxTokens ? { max_tokens: o.highlightMaxTokens } : {}) };
|
|
41
|
+
if (o.fullContent)
|
|
42
|
+
req.full_content = { enable: true, ...(o.fullContentMaxTokens ? { max_tokens: o.fullContentMaxTokens } : {}) };
|
|
43
|
+
return req;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Assemble a structured sub-block (`subjects`, `entities`) only when the
|
|
47
|
+
* caller set something in it.
|
|
48
|
+
*
|
|
49
|
+
* An absent block is not the same as `{enable: false}`: the server turns these
|
|
50
|
+
* on by default, so sending an empty object would be the CLI pinning a default
|
|
51
|
+
* that belongs to the API.
|
|
52
|
+
*/
|
|
53
|
+
function subBlock(disable, fields) {
|
|
54
|
+
if (disable)
|
|
55
|
+
return { enable: false };
|
|
56
|
+
const set = fields.filter(([, v]) => v != null);
|
|
57
|
+
return set.length ? Object.fromEntries(set) : undefined;
|
|
58
|
+
}
|
|
59
|
+
export function buildNewsSearchRequest(query, o) {
|
|
60
|
+
if (!query.trim())
|
|
61
|
+
throw new OctenValidationError("query is required");
|
|
62
|
+
assertRange("subjects-count", o.subjectsCount, LIMITS.subjectsCount);
|
|
63
|
+
assertRange("max-sub-news", o.maxSubNews, LIMITS.maxSubNews);
|
|
64
|
+
const req = { query, ...buildVerticalOptions(o) };
|
|
65
|
+
const subjects = subBlock(o.noSubjects, [
|
|
66
|
+
["count", o.subjectsCount],
|
|
67
|
+
["max_sub_news", o.maxSubNews],
|
|
68
|
+
]);
|
|
69
|
+
if (subjects)
|
|
70
|
+
req.subjects = subjects;
|
|
71
|
+
return req;
|
|
72
|
+
}
|
|
73
|
+
export function buildBusinessSearchRequest(query, o) {
|
|
74
|
+
if (!query.trim())
|
|
75
|
+
throw new OctenValidationError("query is required");
|
|
76
|
+
assertRange("entities-count", o.entitiesCount, LIMITS.entitiesCount);
|
|
77
|
+
assertRange("max-activities", o.maxActivities, LIMITS.maxActivities);
|
|
78
|
+
assertRange("max-entity-news", o.maxEntityNews, LIMITS.maxEntityNews);
|
|
79
|
+
const req = { query, ...buildVerticalOptions(o) };
|
|
80
|
+
const entities = subBlock(o.noEntities, [
|
|
81
|
+
["count", o.entitiesCount],
|
|
82
|
+
["max_activities", o.maxActivities],
|
|
83
|
+
["max_news", o.maxEntityNews],
|
|
84
|
+
]);
|
|
85
|
+
if (entities)
|
|
86
|
+
req.entities = entities;
|
|
87
|
+
return req;
|
|
88
|
+
}
|
|
89
|
+
export function buildPulseSearchRequest(query, o) {
|
|
90
|
+
if (!query.trim())
|
|
91
|
+
throw new OctenValidationError("query is required");
|
|
92
|
+
if (query.length > LIMITS.pulseQueryLength)
|
|
93
|
+
throw new OctenValidationError(`query must be at most ${LIMITS.pulseQueryLength} characters`);
|
|
94
|
+
if (o.count != null && (o.count < LIMITS.pulseCount.min || o.count > LIMITS.pulseCount.max))
|
|
95
|
+
throw new OctenValidationError(`count must be ${LIMITS.pulseCount.min}-${LIMITS.pulseCount.max}`);
|
|
96
|
+
assertRange("highlight-max-tokens", o.highlightMaxTokens, LIMITS.highlightMaxTokens);
|
|
97
|
+
assertRange("full-content-max-tokens", o.fullContentMaxTokens, LIMITS.fullContentMaxTokens);
|
|
98
|
+
validateEnum("--mode", o.mode, PULSE_MODE_OPTIONS);
|
|
99
|
+
validateEnum("--safesearch", o.safesearch, SAFESEARCH_OPTIONS);
|
|
100
|
+
const req = { query };
|
|
101
|
+
const put = (k, v) => { if (v != null)
|
|
102
|
+
req[k] = v; };
|
|
103
|
+
put("mode", o.mode);
|
|
104
|
+
put("count", o.count);
|
|
105
|
+
put("safesearch", o.safesearch);
|
|
106
|
+
put("include_images", o.images);
|
|
107
|
+
if (o.highlight)
|
|
108
|
+
req.highlight = { enable: true, ...(o.highlightMaxTokens ? { max_tokens: o.highlightMaxTokens } : {}) };
|
|
109
|
+
if (o.fullContent)
|
|
110
|
+
req.full_content = { enable: true, ...(o.fullContentMaxTokens ? { max_tokens: o.fullContentMaxTokens } : {}) };
|
|
111
|
+
return req;
|
|
112
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -6,6 +6,8 @@ import { fileURLToPath } from "node:url";
|
|
|
6
6
|
import pc from "picocolors";
|
|
7
7
|
import { exitCodeFor } from "./api/errors.js";
|
|
8
8
|
import { registerSearch } from "./commands/search.js";
|
|
9
|
+
import { registerBusinessSearch, registerNewsSearch, registerPulseSearch, } from "./commands/verticalSearch.js";
|
|
10
|
+
import { registerPlaceSearch } from "./commands/placeSearch.js";
|
|
9
11
|
import { registerBroadSearch } from "./commands/broadSearch.js";
|
|
10
12
|
import { registerExtract } from "./commands/extract.js";
|
|
11
13
|
import { registerChat } from "./commands/chat.js";
|
|
@@ -40,7 +42,10 @@ registerReset(program);
|
|
|
40
42
|
registerConfigureMcp(program);
|
|
41
43
|
registerConfigureSkills(program);
|
|
42
44
|
registerSearch(program);
|
|
43
|
-
|
|
45
|
+
registerNewsSearch(program);
|
|
46
|
+
registerBusinessSearch(program);
|
|
47
|
+
registerPlaceSearch(program);
|
|
48
|
+
registerPulseSearch(program);
|
|
44
49
|
registerBroadSearch(program);
|
|
45
50
|
registerExtract(program);
|
|
46
51
|
registerChat(program);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ENDPOINTS } from "../api/constants.js";
|
|
2
|
+
import { buildPlaceSearchRequest, } from "../api/placeSearch.js";
|
|
3
|
+
import { chooseMode, emit } from "../output/render.js";
|
|
4
|
+
import { renderPlaceSearch } from "../output/pretty/placeSearch.js";
|
|
5
|
+
import { makeClient, parseIntOpt } from "./utils.js";
|
|
6
|
+
/** commander hands numeric options back as strings; coordinates need floats. */
|
|
7
|
+
function parseFloatOpt(flag) {
|
|
8
|
+
return (raw) => {
|
|
9
|
+
const n = Number(raw);
|
|
10
|
+
if (!Number.isFinite(n))
|
|
11
|
+
throw new Error(`${flag} must be a number`);
|
|
12
|
+
return n;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function registerPlaceSearch(program) {
|
|
16
|
+
program.command("place")
|
|
17
|
+
.argument("<query...>", "what to find, e.g. 'coffee shop'")
|
|
18
|
+
.description("Real-world places with address, hours, rating and distance")
|
|
19
|
+
.option("--latitude <n>", "WGS84 latitude to search around", parseFloatOpt("--latitude"))
|
|
20
|
+
.option("--longitude <n>", "WGS84 longitude to search around", parseFloatOpt("--longitude"))
|
|
21
|
+
.option("--radius <m>", "cap distance from the point, in metres (1-50000)", parseIntOpt("--radius"))
|
|
22
|
+
.option("--city <name>", "approximate location, when coordinates are unknown")
|
|
23
|
+
.option("--region <name>", "approximate location: region or state")
|
|
24
|
+
.option("--country <code>", "approximate location: country")
|
|
25
|
+
.option("-n, --count <n>", "places to return, 1-20", parseIntOpt("--count"))
|
|
26
|
+
.option("--max-reviews <n>", "review excerpts per place, 0-5 (off by default)", parseIntOpt("--max-reviews"))
|
|
27
|
+
.option("--web", "also return web pages about these places")
|
|
28
|
+
.option("--web-count <n>", "web results, 1-100 (needs --web)", parseIntOpt("--web-count"))
|
|
29
|
+
.action(async (queryArg, opts, command) => {
|
|
30
|
+
const g = command.optsWithGlobals();
|
|
31
|
+
const client = makeClient(g);
|
|
32
|
+
const req = buildPlaceSearchRequest(queryArg.join(" "), opts);
|
|
33
|
+
const res = await client.request(ENDPOINTS.placeSearch, req);
|
|
34
|
+
emit(res, chooseMode(g, process.stdout.isTTY ?? false), renderPlaceSearch);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
|
-
export declare function registerSearch(program: Command
|
|
2
|
+
export declare function registerSearch(program: Command): void;
|
package/dist/commands/search.js
CHANGED
|
@@ -3,10 +3,10 @@ import { buildSearchRequest } from "../api/search.js";
|
|
|
3
3
|
import { chooseMode, emit } from "../output/render.js";
|
|
4
4
|
import { renderSearch } from "../output/pretty/search.js";
|
|
5
5
|
import { makeClient, parseCsvOpt, parseIntOpt } from "./utils.js";
|
|
6
|
-
export function registerSearch(program
|
|
7
|
-
const cmd = program.command(
|
|
6
|
+
export function registerSearch(program) {
|
|
7
|
+
const cmd = program.command("search")
|
|
8
8
|
.argument("<query...>", "search query")
|
|
9
|
-
.description(
|
|
9
|
+
.description("Search the live web")
|
|
10
10
|
.option("-n, --count <n>", "results 1-100", parseIntOpt("--count"))
|
|
11
11
|
.option("--include-domains <list>", "comma list", parseCsvOpt("--include-domains"))
|
|
12
12
|
.option("--exclude-domains <list>", "comma list", parseCsvOpt("--exclude-domains"))
|
|
@@ -20,14 +20,12 @@ export function registerSearch(program, fixedTopic) {
|
|
|
20
20
|
.option("--highlight").option("--highlight-max-tokens <n>", "max tokens per highlight", parseIntOpt("--highlight-max-tokens"))
|
|
21
21
|
.option("--full-content").option("--full-content-max-tokens <n>", "max tokens per result", parseIntOpt("--full-content-max-tokens"))
|
|
22
22
|
.option("--images");
|
|
23
|
-
|
|
24
|
-
cmd.option("--topic <t>", "general|news");
|
|
23
|
+
cmd.option("--topic <t>", "general|news");
|
|
25
24
|
cmd.action(async (queryArg, opts, command) => {
|
|
26
25
|
const g = command.optsWithGlobals();
|
|
27
26
|
const client = makeClient(g);
|
|
28
27
|
const query = Array.isArray(queryArg) ? queryArg.join(" ") : queryArg;
|
|
29
|
-
const
|
|
30
|
-
const req = buildSearchRequest(query, searchOpts);
|
|
28
|
+
const req = buildSearchRequest(query, opts);
|
|
31
29
|
const res = await client.request(ENDPOINTS.search, req);
|
|
32
30
|
emit(res, chooseMode(g, process.stdout.isTTY ?? false), renderSearch);
|
|
33
31
|
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ENDPOINTS } from "../api/constants.js";
|
|
2
|
+
import { buildBusinessSearchRequest, buildNewsSearchRequest, buildPulseSearchRequest, } from "../api/verticalSearch.js";
|
|
3
|
+
import { chooseMode, emit } from "../output/render.js";
|
|
4
|
+
import { renderBusinessSearch } from "../output/pretty/businessSearch.js";
|
|
5
|
+
import { renderNewsSearch } from "../output/pretty/newsSearch.js";
|
|
6
|
+
import { renderPulseSearch } from "../output/pretty/pulseSearch.js";
|
|
7
|
+
import { makeClient, parseCsvOpt, parseIntOpt } from "./utils.js";
|
|
8
|
+
/**
|
|
9
|
+
* The retrieval options news and business share. Deliberately not `search`'s
|
|
10
|
+
* full set: the API accepts the extras and ignores them, so offering them here
|
|
11
|
+
* would hand back results that silently do not reflect the flags given.
|
|
12
|
+
*/
|
|
13
|
+
function addSharedOptions(cmd) {
|
|
14
|
+
return cmd
|
|
15
|
+
.option("-n, --count <n>", "results 1-100", parseIntOpt("--count"))
|
|
16
|
+
.option("--include-domains <list>", "comma list", parseCsvOpt("--include-domains"))
|
|
17
|
+
.option("--exclude-domains <list>", "comma list", parseCsvOpt("--exclude-domains"))
|
|
18
|
+
.option("--language <list>", "ISO 639-1 codes, comma-separated, e.g. en,ja", parseCsvOpt("--language"))
|
|
19
|
+
.option("--time-basis <b>", "auto|published|crawled")
|
|
20
|
+
.option("--time-range <r>", "day|week|month|year (or d|w|m|y)")
|
|
21
|
+
.option("--start-time <when>", "YYYY-MM-DD or ISO datetime")
|
|
22
|
+
.option("--end-time <when>", "YYYY-MM-DD or ISO datetime")
|
|
23
|
+
.option("--highlight")
|
|
24
|
+
.option("--highlight-max-tokens <n>", "max tokens per highlight", parseIntOpt("--highlight-max-tokens"))
|
|
25
|
+
.option("--full-content")
|
|
26
|
+
.option("--full-content-max-tokens <n>", "max tokens per result", parseIntOpt("--full-content-max-tokens"));
|
|
27
|
+
}
|
|
28
|
+
export function registerNewsSearch(program) {
|
|
29
|
+
addSharedOptions(program.command("news")
|
|
30
|
+
.argument("<query...>", "what is being reported")
|
|
31
|
+
.description("Recent news, returned as ranked articles and as storylines"))
|
|
32
|
+
.option("--no-subjects", "skip the storyline clustering")
|
|
33
|
+
.option("--subjects-count <n>", "storylines to return, 1-5", parseIntOpt("--subjects-count"))
|
|
34
|
+
.option("--max-sub-news <n>", "supporting articles per storyline, 1-20", parseIntOpt("--max-sub-news"))
|
|
35
|
+
.action(async (queryArg, opts, command) => {
|
|
36
|
+
const g = command.optsWithGlobals();
|
|
37
|
+
const client = makeClient(g);
|
|
38
|
+
// commander turns `--no-subjects` into `subjects: false`; the builder
|
|
39
|
+
// wants to know only whether it was switched off.
|
|
40
|
+
const o = { ...opts, noSubjects: opts.subjects === false };
|
|
41
|
+
const req = buildNewsSearchRequest(queryArg.join(" "), o);
|
|
42
|
+
const res = await client.request(ENDPOINTS.newsSearch, req);
|
|
43
|
+
emit(res, chooseMode(g, process.stdout.isTTY ?? false), renderNewsSearch);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function registerBusinessSearch(program) {
|
|
47
|
+
addSharedOptions(program.command("business")
|
|
48
|
+
.argument("<query...>", "a company, or a person in a business context")
|
|
49
|
+
.description("Companies and people as structured cards, alongside ranked sources"))
|
|
50
|
+
.option("--no-entities", "skip the entity cards and return sources only")
|
|
51
|
+
.option("--entities-count <n>", "entities to profile, 1-20", parseIntOpt("--entities-count"))
|
|
52
|
+
.option("--max-activities <n>", "activities per entity, 1-20", parseIntOpt("--max-activities"))
|
|
53
|
+
.option("--max-entity-news <n>", "news items per entity, 1-20", parseIntOpt("--max-entity-news"))
|
|
54
|
+
.action(async (queryArg, opts, command) => {
|
|
55
|
+
const g = command.optsWithGlobals();
|
|
56
|
+
const client = makeClient(g);
|
|
57
|
+
const o = { ...opts, noEntities: opts.entities === false };
|
|
58
|
+
const req = buildBusinessSearchRequest(queryArg.join(" "), o);
|
|
59
|
+
const res = await client.request(ENDPOINTS.businessSearch, req);
|
|
60
|
+
emit(res, chooseMode(g, process.stdout.isTTY ?? false), renderBusinessSearch);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export function registerPulseSearch(program) {
|
|
64
|
+
program.command("pulse")
|
|
65
|
+
.argument("<query...>", "what to find the destination for, e.g. 'uv docs'")
|
|
66
|
+
.description("The URL a query most likely means, in about 10ms")
|
|
67
|
+
.option("--mode <m>", "lite|standard — standard adds highlights and content")
|
|
68
|
+
.option("-n, --count <n>", "results 1-10", parseIntOpt("--count"))
|
|
69
|
+
.option("--safesearch <s>", "off|strict")
|
|
70
|
+
.option("--images", "return image URLs per result (standard mode only)")
|
|
71
|
+
.option("--highlight")
|
|
72
|
+
.option("--highlight-max-tokens <n>", "max tokens per highlight", parseIntOpt("--highlight-max-tokens"))
|
|
73
|
+
.option("--full-content")
|
|
74
|
+
.option("--full-content-max-tokens <n>", "max tokens per result", parseIntOpt("--full-content-max-tokens"))
|
|
75
|
+
.action(async (queryArg, opts, command) => {
|
|
76
|
+
const g = command.optsWithGlobals();
|
|
77
|
+
const client = makeClient(g);
|
|
78
|
+
const req = buildPulseSearchRequest(queryArg.join(" "), opts);
|
|
79
|
+
const res = await client.request(ENDPOINTS.pulseSearch, req);
|
|
80
|
+
emit(res, chooseMode(g, process.stdout.isTTY ?? false), renderPulseSearch);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Business results print the entity cards first, then the ranked sources.
|
|
3
|
+
*
|
|
4
|
+
* The cards are the answer — a company's numbers, its people, what it just
|
|
5
|
+
* announced — and the sources are the evidence behind them.
|
|
6
|
+
*/
|
|
7
|
+
export declare function renderBusinessSearch(data: any): string;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { formatResultList } from "./search.js";
|
|
3
|
+
import { envelopeError, unwrap } from "./envelope.js";
|
|
4
|
+
// Long series are capped: sixteen quarters of financials on one card is the
|
|
5
|
+
// opposite of what a structured answer is for. The count of what was left out
|
|
6
|
+
// is printed, so the reader knows the series continues.
|
|
7
|
+
const SERIES_SHOWN = 4;
|
|
8
|
+
const MAX_SUMMARY = 400;
|
|
9
|
+
/** `81615003648` → `81.6B`. Raw figures at this magnitude are unreadable. */
|
|
10
|
+
function money(n) {
|
|
11
|
+
if (typeof n !== "number" || !Number.isFinite(n))
|
|
12
|
+
return "";
|
|
13
|
+
const abs = Math.abs(n);
|
|
14
|
+
for (const [limit, suffix] of [[1e12, "T"], [1e9, "B"], [1e6, "M"], [1e3, "K"]]) {
|
|
15
|
+
if (abs >= limit)
|
|
16
|
+
return `${(n / limit).toFixed(1)}${suffix}`;
|
|
17
|
+
}
|
|
18
|
+
return String(n);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Business results print the entity cards first, then the ranked sources.
|
|
22
|
+
*
|
|
23
|
+
* The cards are the answer — a company's numbers, its people, what it just
|
|
24
|
+
* announced — and the sources are the evidence behind them.
|
|
25
|
+
*/
|
|
26
|
+
export function renderBusinessSearch(data) {
|
|
27
|
+
const body = unwrap(data);
|
|
28
|
+
const entities = body?.entities ?? [];
|
|
29
|
+
const results = body?.results ?? [];
|
|
30
|
+
if (!entities.length && !results.length) {
|
|
31
|
+
const err = envelopeError(data);
|
|
32
|
+
return err ? pc.red(`error: ${err}`) : pc.dim("No results.");
|
|
33
|
+
}
|
|
34
|
+
const blocks = [];
|
|
35
|
+
if (entities.length)
|
|
36
|
+
blocks.push(entities.map(formatEntity).join("\n\n"));
|
|
37
|
+
if (results.length) {
|
|
38
|
+
if (entities.length)
|
|
39
|
+
blocks.push(pc.bold("Sources"));
|
|
40
|
+
blocks.push(formatResultList(results));
|
|
41
|
+
}
|
|
42
|
+
return blocks.join("\n\n");
|
|
43
|
+
}
|
|
44
|
+
function formatEntity(e) {
|
|
45
|
+
const lines = [];
|
|
46
|
+
const kind = e?.type ? ` ${pc.dim(`(${e.type})`)}` : "";
|
|
47
|
+
lines.push(`${pc.bold(e?.name ?? "(unnamed)")}${kind}`);
|
|
48
|
+
if (e?.summary) {
|
|
49
|
+
const raw = String(e.summary);
|
|
50
|
+
lines.push(` ${raw.length > MAX_SUMMARY ? raw.slice(0, MAX_SUMMARY) + "…" : raw}`);
|
|
51
|
+
}
|
|
52
|
+
lines.push(...formatMetrics(e?.metrics));
|
|
53
|
+
// A person entity carries its own role and history where a company carries
|
|
54
|
+
// key_people. Rendering only the latter leaves a person card with no career
|
|
55
|
+
// information at all.
|
|
56
|
+
if (e?.current_position)
|
|
57
|
+
lines.push(` ${e.current_position}`);
|
|
58
|
+
const career = e?.career ?? [];
|
|
59
|
+
if (career.length) {
|
|
60
|
+
lines.push(` ${pc.bold("Career")}`);
|
|
61
|
+
for (const c of career.slice(0, SERIES_SHOWN)) {
|
|
62
|
+
const span = [c?.start, c?.end ?? "present"].filter(Boolean).join(" – ");
|
|
63
|
+
const role = [c?.title, c?.organization].filter(Boolean).join(" at ");
|
|
64
|
+
lines.push(` ${role || "(role unknown)"}${span ? ` ${pc.dim(`(${span})`)}` : ""}`);
|
|
65
|
+
}
|
|
66
|
+
if (career.length > SERIES_SHOWN)
|
|
67
|
+
pushElided(lines, career.length - SERIES_SHOWN, "earlier roles");
|
|
68
|
+
}
|
|
69
|
+
const people = e?.key_people ?? [];
|
|
70
|
+
if (people.length) {
|
|
71
|
+
lines.push(` ${pc.bold("Key people")}`);
|
|
72
|
+
for (const p of people.slice(0, SERIES_SHOWN * 2)) {
|
|
73
|
+
const role = [p?.title, p?.company].filter(Boolean).join(" at ");
|
|
74
|
+
lines.push(` ${p?.name ?? "(unnamed)"}${role ? ` — ${role}` : ""}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Requested through --max-activities, so dropping them silently makes that
|
|
78
|
+
// flag do nothing the caller can see.
|
|
79
|
+
const activities = e?.activities ?? [];
|
|
80
|
+
if (activities.length) {
|
|
81
|
+
lines.push(` ${pc.bold("Activity")}`);
|
|
82
|
+
for (const a of activities.slice(0, SERIES_SHOWN)) {
|
|
83
|
+
lines.push(` • ${a?.title ?? "(untitled)"}`);
|
|
84
|
+
if (a?.time_published)
|
|
85
|
+
lines.push(` ${pc.dim(a.time_published)}`);
|
|
86
|
+
if (a?.url)
|
|
87
|
+
lines.push(` ${pc.dim(a.url)}`);
|
|
88
|
+
lines.push(...content(a, " "));
|
|
89
|
+
}
|
|
90
|
+
if (activities.length > SERIES_SHOWN)
|
|
91
|
+
pushElided(lines, activities.length - SERIES_SHOWN, "more");
|
|
92
|
+
}
|
|
93
|
+
const news = e?.news ?? [];
|
|
94
|
+
if (news.length) {
|
|
95
|
+
lines.push(` ${pc.bold("Recent")}`);
|
|
96
|
+
for (const n of news.slice(0, SERIES_SHOWN)) {
|
|
97
|
+
lines.push(` • ${n?.title ?? "(no title)"}`);
|
|
98
|
+
if (n?.url)
|
|
99
|
+
lines.push(` ${pc.dim(n.url)}`);
|
|
100
|
+
// The caller enabled --highlight for these too, and paid for them.
|
|
101
|
+
lines.push(...content(n, " "));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return lines.join("\n");
|
|
105
|
+
}
|
|
106
|
+
function formatMetrics(m) {
|
|
107
|
+
if (!m || typeof m !== "object")
|
|
108
|
+
return [];
|
|
109
|
+
const out = [];
|
|
110
|
+
const fin = Array.isArray(m.financials) ? m.financials : [];
|
|
111
|
+
if (fin.length) {
|
|
112
|
+
out.push(` ${pc.bold("Financials")}`);
|
|
113
|
+
for (const f of fin.slice(0, SERIES_SHOWN)) {
|
|
114
|
+
const bits = [
|
|
115
|
+
f?.revenue != null ? `revenue ${money(f.revenue)}` : "",
|
|
116
|
+
f?.net_income != null ? `net income ${money(f.net_income)}` : "",
|
|
117
|
+
].filter(Boolean).join(", ");
|
|
118
|
+
out.push(` ${f?.period ?? "?"}${bits ? ` — ${bits}` : ""}`);
|
|
119
|
+
}
|
|
120
|
+
if (fin.length > SERIES_SHOWN)
|
|
121
|
+
out.push(pc.dim(` (+${fin.length - SERIES_SHOWN} earlier periods)`));
|
|
122
|
+
}
|
|
123
|
+
const fund = Array.isArray(m.funding) ? m.funding : [];
|
|
124
|
+
if (fund.length) {
|
|
125
|
+
out.push(` ${pc.bold("Funding")}`);
|
|
126
|
+
for (const f of fund.slice(0, SERIES_SHOWN)) {
|
|
127
|
+
const led = f?.lead_investors ? ` — led by ${String(f.lead_investors).split(";").join(", ")}` : "";
|
|
128
|
+
out.push(` ${f?.date ?? "?"} ${f?.round ?? ""} ${money(f?.amount)}${led}`.replace(/\s+/g, " "));
|
|
129
|
+
}
|
|
130
|
+
if (fund.length > SERIES_SHOWN)
|
|
131
|
+
out.push(pc.dim(` (+${fund.length - SERIES_SHOWN} earlier rounds)`));
|
|
132
|
+
}
|
|
133
|
+
const s = m.stock;
|
|
134
|
+
if (s && typeof s === "object") {
|
|
135
|
+
const bits = [
|
|
136
|
+
s.price != null ? `${s.price}${s.currency ? ` ${s.currency}` : ""}` : "",
|
|
137
|
+
typeof s.todays_change_percent === "number" ? `${s.todays_change_percent.toFixed(2)}% today` : "",
|
|
138
|
+
].filter(Boolean).join(", ");
|
|
139
|
+
if (bits)
|
|
140
|
+
out.push(` ${pc.bold("Stock")} ${bits}`);
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
/** `(+N more)`, so a truncated series says what was left out. */
|
|
145
|
+
function pushElided(lines, n, label) {
|
|
146
|
+
lines.push(pc.dim(` (+${n} ${label})`));
|
|
147
|
+
}
|
|
148
|
+
/** Whatever content an item carries — the caller asked for it. */
|
|
149
|
+
function content(item, indent) {
|
|
150
|
+
const res = [];
|
|
151
|
+
for (const field of ["summary", "highlight", "full_content"]) {
|
|
152
|
+
const raw = item?.[field];
|
|
153
|
+
if (typeof raw !== "string" || !raw.trim())
|
|
154
|
+
continue;
|
|
155
|
+
const text = raw.length > MAX_SUMMARY ? raw.slice(0, MAX_SUMMARY) + "…" : raw;
|
|
156
|
+
res.push(...text.split("\n").map((l) => `${indent}${l}`));
|
|
157
|
+
}
|
|
158
|
+
return res;
|
|
159
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Octen API wraps every payload in `{ code, msg, data, meta }`. Renderers
|
|
3
|
+
* want the inner body, but have to cope with being handed an already-unwrapped
|
|
4
|
+
* object (tests, piped JSON), so the unwrap is conditional.
|
|
5
|
+
*
|
|
6
|
+
* The seven renderers that predate this file each carry their own copy of the
|
|
7
|
+
* same few lines. New ones use this instead; folding the old ones in is a
|
|
8
|
+
* separate change, since each also has its own empty-state wording to preserve.
|
|
9
|
+
*/
|
|
10
|
+
export interface Envelope {
|
|
11
|
+
code?: number;
|
|
12
|
+
msg?: string;
|
|
13
|
+
data?: unknown;
|
|
14
|
+
}
|
|
15
|
+
/** The inner body, or the input itself when it is not an envelope. */
|
|
16
|
+
export declare function unwrap(data: unknown): any;
|
|
17
|
+
/**
|
|
18
|
+
* The API reports application errors inside a 200 envelope, so a renderer that
|
|
19
|
+
* only checked for an empty list would print "No results" for an auth failure.
|
|
20
|
+
* Returns the message to show, or undefined when the envelope is healthy.
|
|
21
|
+
*/
|
|
22
|
+
export declare function envelopeError(data: unknown): string | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The inner body, or the input itself when it is not an envelope. */
|
|
2
|
+
export function unwrap(data) {
|
|
3
|
+
const inner = data?.data;
|
|
4
|
+
return data && typeof data === "object" && inner && typeof inner === "object" && !Array.isArray(inner)
|
|
5
|
+
? inner
|
|
6
|
+
: data;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The API reports application errors inside a 200 envelope, so a renderer that
|
|
10
|
+
* only checked for an empty list would print "No results" for an auth failure.
|
|
11
|
+
* Returns the message to show, or undefined when the envelope is healthy.
|
|
12
|
+
*/
|
|
13
|
+
export function envelopeError(data) {
|
|
14
|
+
const code = data?.code;
|
|
15
|
+
const msg = data?.msg;
|
|
16
|
+
return code != null && code !== 0 && msg ? String(msg) : undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* News results print the storylines first, then the ranked articles.
|
|
3
|
+
*
|
|
4
|
+
* The storylines are a clustering of the coverage, not a second retrieval, and
|
|
5
|
+
* they carry the summary that answers "what happened with X" without reading
|
|
6
|
+
* every article. One caveat the reader has to know: domain filters narrow the
|
|
7
|
+
* ranked articles only and never reach `subjects`, so a source-restricted
|
|
8
|
+
* question has to be answered from the articles below.
|
|
9
|
+
*/
|
|
10
|
+
export declare function renderNewsSearch(data: any): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { formatResultList } from "./search.js";
|
|
3
|
+
import { envelopeError, unwrap } from "./envelope.js";
|
|
4
|
+
const MAX_SUMMARY = 400;
|
|
5
|
+
/**
|
|
6
|
+
* News results print the storylines first, then the ranked articles.
|
|
7
|
+
*
|
|
8
|
+
* The storylines are a clustering of the coverage, not a second retrieval, and
|
|
9
|
+
* they carry the summary that answers "what happened with X" without reading
|
|
10
|
+
* every article. One caveat the reader has to know: domain filters narrow the
|
|
11
|
+
* ranked articles only and never reach `subjects`, so a source-restricted
|
|
12
|
+
* question has to be answered from the articles below.
|
|
13
|
+
*/
|
|
14
|
+
export function renderNewsSearch(data) {
|
|
15
|
+
const body = unwrap(data);
|
|
16
|
+
const subjects = body?.subjects ?? [];
|
|
17
|
+
const results = body?.results ?? [];
|
|
18
|
+
if (!subjects.length && !results.length) {
|
|
19
|
+
const err = envelopeError(data);
|
|
20
|
+
return err ? pc.red(`error: ${err}`) : pc.dim("No results.");
|
|
21
|
+
}
|
|
22
|
+
const blocks = [];
|
|
23
|
+
if (subjects.length)
|
|
24
|
+
blocks.push(subjects.map(formatSubject).join("\n\n"));
|
|
25
|
+
if (results.length) {
|
|
26
|
+
if (subjects.length)
|
|
27
|
+
blocks.push(pc.bold("Articles"));
|
|
28
|
+
blocks.push(formatResultList(results));
|
|
29
|
+
}
|
|
30
|
+
return blocks.join("\n\n");
|
|
31
|
+
}
|
|
32
|
+
function formatSubject(s, i) {
|
|
33
|
+
const lines = [];
|
|
34
|
+
lines.push(`${pc.bold(`Storyline ${i + 1}: ${s?.name ?? "(unnamed)"}`)}`);
|
|
35
|
+
const span = [s?.time_start, s?.time_latest].filter(Boolean).join(" → ");
|
|
36
|
+
if (span)
|
|
37
|
+
lines.push(` ${pc.dim(span)}`);
|
|
38
|
+
if (s?.summary) {
|
|
39
|
+
const raw = String(s.summary);
|
|
40
|
+
lines.push(` ${raw.length > MAX_SUMMARY ? raw.slice(0, MAX_SUMMARY) + "…" : raw}`);
|
|
41
|
+
}
|
|
42
|
+
// `top_news` is the lead article; `sub_news` are the supporting ones. They
|
|
43
|
+
// need not appear in `results` at all, so dropping them would lose coverage
|
|
44
|
+
// the caller already paid for.
|
|
45
|
+
const articles = [s?.top_news, ...(s?.sub_news ?? [])].filter(Boolean);
|
|
46
|
+
for (const a of articles) {
|
|
47
|
+
lines.push(` • ${a?.title ?? "(no title)"}`);
|
|
48
|
+
if (a?.url)
|
|
49
|
+
lines.push(` ${pc.dim(a.url)}`);
|
|
50
|
+
lines.push(...articleContent(a, " "));
|
|
51
|
+
}
|
|
52
|
+
return lines.join("\n");
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whatever content a storyline article carries, indented under it.
|
|
56
|
+
*
|
|
57
|
+
* These are not duplicates of the ranked results: a storyline's articles need
|
|
58
|
+
* not appear in `data.results` at all, so dropping their `summary`,
|
|
59
|
+
* `highlight` and `full_content` discards content the caller enabled and was
|
|
60
|
+
* billed for, with nowhere else to find it.
|
|
61
|
+
*/
|
|
62
|
+
function articleContent(a, indent) {
|
|
63
|
+
const out = [];
|
|
64
|
+
for (const field of ["summary", "highlight", "full_content"]) {
|
|
65
|
+
const raw = a?.[field];
|
|
66
|
+
if (typeof raw !== "string" || !raw.trim())
|
|
67
|
+
continue;
|
|
68
|
+
const text = raw.length > MAX_SUMMARY ? raw.slice(0, MAX_SUMMARY) + "…" : raw;
|
|
69
|
+
out.push(...text.split("\n").map((l) => `${indent}${l}`));
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Place results live under `data.places`, not `data.results` — `results` is
|
|
3
|
+
* where the optional web pages go, and reading the wrong one is an easy way to
|
|
4
|
+
* conclude the endpoint returned nothing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function renderPlaceSearch(data: any): string;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { formatResultList } from "./search.js";
|
|
3
|
+
import { envelopeError, unwrap } from "./envelope.js";
|
|
4
|
+
/** `1.2 km` / `450 m` — metres are what the API returns, km is what reads past a point. */
|
|
5
|
+
function distance(m) {
|
|
6
|
+
if (typeof m !== "number" || !Number.isFinite(m))
|
|
7
|
+
return "";
|
|
8
|
+
return m >= 1000 ? `${(m / 1000).toFixed(1)} km` : `${Math.round(m)} m`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Place results live under `data.places`, not `data.results` — `results` is
|
|
12
|
+
* where the optional web pages go, and reading the wrong one is an easy way to
|
|
13
|
+
* conclude the endpoint returned nothing.
|
|
14
|
+
*/
|
|
15
|
+
export function renderPlaceSearch(data) {
|
|
16
|
+
const body = unwrap(data);
|
|
17
|
+
const places = body?.places ?? [];
|
|
18
|
+
const web = body?.results ?? [];
|
|
19
|
+
if (!places.length && !web.length) {
|
|
20
|
+
const err = envelopeError(data);
|
|
21
|
+
return err ? pc.red(`error: ${err}`) : pc.dim("No results.");
|
|
22
|
+
}
|
|
23
|
+
const blocks = [];
|
|
24
|
+
if (places.length)
|
|
25
|
+
blocks.push(places.map(formatPlace).join("\n\n"));
|
|
26
|
+
if (web.length) {
|
|
27
|
+
if (places.length)
|
|
28
|
+
blocks.push(pc.bold("Web results"));
|
|
29
|
+
blocks.push(formatResultList(web));
|
|
30
|
+
}
|
|
31
|
+
return blocks.join("\n\n");
|
|
32
|
+
}
|
|
33
|
+
function formatPlace(p, i) {
|
|
34
|
+
const lines = [];
|
|
35
|
+
lines.push(`${i + 1}. ${pc.bold(p?.name ?? "(unnamed)")}`);
|
|
36
|
+
const sub = [p?.category, distance(p?.distance)].filter(Boolean).join(" · ");
|
|
37
|
+
if (sub)
|
|
38
|
+
lines.push(` ${pc.dim(sub)}`);
|
|
39
|
+
if (p?.address)
|
|
40
|
+
lines.push(` ${p.address}`);
|
|
41
|
+
const rating = typeof p?.rating === "number"
|
|
42
|
+
? `${p.rating}/5${typeof p.review_count === "number" ? ` (${p.review_count} reviews)` : ""}`
|
|
43
|
+
: "";
|
|
44
|
+
const status = [rating, p?.status].filter(Boolean).join(" · ");
|
|
45
|
+
if (status)
|
|
46
|
+
lines.push(` ${status}`);
|
|
47
|
+
if (p?.phone)
|
|
48
|
+
lines.push(` ${pc.dim(`Phone: ${p.phone}`)}`);
|
|
49
|
+
if (p?.website)
|
|
50
|
+
lines.push(` ${pc.dim(p.website)}`);
|
|
51
|
+
const hours = Array.isArray(p?.opening_hours) ? p.opening_hours.filter(Boolean) : [];
|
|
52
|
+
if (hours.length)
|
|
53
|
+
lines.push(...hours.map((h) => ` ${pc.dim(h)}`));
|
|
54
|
+
// `false` is printed, not dropped: "not wheelchair accessible" is a reason
|
|
55
|
+
// to pick a different place, and dropping it makes a definite no read the
|
|
56
|
+
// same as an unknown.
|
|
57
|
+
if (p?.attributes && typeof p.attributes === "object") {
|
|
58
|
+
const attrs = Object.entries(p.attributes)
|
|
59
|
+
.map(([k, v]) => (v === true ? k : v === false ? `no ${k}` : v == null ? "" : `${k}=${v}`))
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.join(", ");
|
|
62
|
+
if (attrs)
|
|
63
|
+
lines.push(` ${pc.dim(attrs)}`);
|
|
64
|
+
}
|
|
65
|
+
if (typeof p?.latitude === "number" && typeof p?.longitude === "number") {
|
|
66
|
+
lines.push(` ${pc.dim(`${p.latitude}, ${p.longitude}`)}`);
|
|
67
|
+
}
|
|
68
|
+
// Only present when `--max-reviews` asked for them, so nothing is printed
|
|
69
|
+
// that was not requested — and nothing requested is dropped.
|
|
70
|
+
const reviews = Array.isArray(p?.reviews) ? p.reviews.filter(Boolean) : [];
|
|
71
|
+
if (reviews.length) {
|
|
72
|
+
lines.push(` ${pc.bold("Reviews")}`);
|
|
73
|
+
for (const r of reviews) {
|
|
74
|
+
const stamp = [
|
|
75
|
+
typeof r?.rating === "number" ? `${r.rating}/5` : "",
|
|
76
|
+
r?.time_published || "",
|
|
77
|
+
].filter(Boolean).join(" · ");
|
|
78
|
+
if (stamp)
|
|
79
|
+
lines.push(` ${pc.dim(stamp)}`);
|
|
80
|
+
const text = typeof r?.text === "string" ? r.text.trim() : "";
|
|
81
|
+
// Each line indented, so a paragraph break cannot read as a new field.
|
|
82
|
+
if (text)
|
|
83
|
+
lines.push(...text.split("\n").map((l) => ` ${l}`));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return lines.join("\n");
|
|
87
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Give a lite-mode URL its scheme back.
|
|
3
|
+
*
|
|
4
|
+
* `lite` returns `github.com/docs`, not `https://github.com/docs`. A caller
|
|
5
|
+
* piping that into a browser or another tool gets something nothing can fetch,
|
|
6
|
+
* so the scheme goes on here rather than in a note the reader may not see.
|
|
7
|
+
* Anything already carrying one is left alone, which covers `standard` and any
|
|
8
|
+
* future mode.
|
|
9
|
+
*/
|
|
10
|
+
export declare function withScheme(url: unknown): unknown;
|
|
11
|
+
export declare function renderPulseSearch(data: any): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { formatResultList } from "./search.js";
|
|
3
|
+
import { envelopeError, unwrap } from "./envelope.js";
|
|
4
|
+
/**
|
|
5
|
+
* Give a lite-mode URL its scheme back.
|
|
6
|
+
*
|
|
7
|
+
* `lite` returns `github.com/docs`, not `https://github.com/docs`. A caller
|
|
8
|
+
* piping that into a browser or another tool gets something nothing can fetch,
|
|
9
|
+
* so the scheme goes on here rather than in a note the reader may not see.
|
|
10
|
+
* Anything already carrying one is left alone, which covers `standard` and any
|
|
11
|
+
* future mode.
|
|
12
|
+
*/
|
|
13
|
+
export function withScheme(url) {
|
|
14
|
+
if (typeof url !== "string" || url === "")
|
|
15
|
+
return url;
|
|
16
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(url))
|
|
17
|
+
return url;
|
|
18
|
+
// `//host/path` already has the slashes and wants only the scheme; adding
|
|
19
|
+
// the pair as well would produce `https:////host/path`.
|
|
20
|
+
return url.startsWith("//") ? `https:${url}` : `https://${url}`;
|
|
21
|
+
}
|
|
22
|
+
export function renderPulseSearch(data) {
|
|
23
|
+
const body = unwrap(data);
|
|
24
|
+
const raw = body?.results ?? [];
|
|
25
|
+
if (!raw.length) {
|
|
26
|
+
const err = envelopeError(data);
|
|
27
|
+
return err ? pc.red(`error: ${err}`) : pc.dim("No results.");
|
|
28
|
+
}
|
|
29
|
+
const results = raw.map((r) => (r && typeof r === "object" ? { ...r, url: withScheme(r.url) } : r));
|
|
30
|
+
return formatResultList(results);
|
|
31
|
+
}
|