@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.
Files changed (44) hide show
  1. package/README.md +109 -2
  2. package/dist/api/constants.d.ts +61 -0
  3. package/dist/api/constants.js +22 -0
  4. package/dist/api/designSearch.d.ts +55 -0
  5. package/dist/api/designSearch.js +136 -0
  6. package/dist/api/placeSearch.d.ts +19 -0
  7. package/dist/api/placeSearch.js +54 -0
  8. package/dist/api/premierSearch.d.ts +19 -0
  9. package/dist/api/premierSearch.js +37 -0
  10. package/dist/api/verticalSearch.d.ts +41 -0
  11. package/dist/api/verticalSearch.js +112 -0
  12. package/dist/cli.js +15 -2
  13. package/dist/commands/designSearch.d.ts +2 -0
  14. package/dist/commands/designSearch.js +63 -0
  15. package/dist/commands/placeSearch.d.ts +2 -0
  16. package/dist/commands/placeSearch.js +36 -0
  17. package/dist/commands/premierSearch.d.ts +8 -0
  18. package/dist/commands/premierSearch.js +37 -0
  19. package/dist/commands/search.d.ts +1 -1
  20. package/dist/commands/search.js +5 -7
  21. package/dist/commands/verticalSearch.d.ts +4 -0
  22. package/dist/commands/verticalSearch.js +82 -0
  23. package/dist/output/pretty/businessSearch.d.ts +7 -0
  24. package/dist/output/pretty/businessSearch.js +159 -0
  25. package/dist/output/pretty/designSearch.d.ts +15 -0
  26. package/dist/output/pretty/designSearch.js +202 -0
  27. package/dist/output/pretty/envelope.d.ts +24 -0
  28. package/dist/output/pretty/envelope.js +21 -0
  29. package/dist/output/pretty/newsSearch.d.ts +10 -0
  30. package/dist/output/pretty/newsSearch.js +72 -0
  31. package/dist/output/pretty/placeSearch.d.ts +6 -0
  32. package/dist/output/pretty/placeSearch.js +87 -0
  33. package/dist/output/pretty/pulseSearch.d.ts +11 -0
  34. package/dist/output/pretty/pulseSearch.js +31 -0
  35. package/dist/output/pretty/search.d.ts +9 -3
  36. package/dist/output/pretty/search.js +26 -11
  37. package/dist/util/terminalText.d.ts +14 -0
  38. package/dist/util/terminalText.js +30 -0
  39. package/package.json +1 -1
  40. package/skills/manifest.json +1 -0
  41. package/skills/octen-design-search/SKILL.md +312 -0
  42. package/skills/octen-design-search/agents/openai.yaml +4 -0
  43. package/skills/octen-search/SKILL.md +53 -5
  44. package/skills/octen-web-search/SKILL.md +14 -2
@@ -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
@@ -5,13 +5,18 @@ import { readFileSync } from "node:fs";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import pc from "picocolors";
7
7
  import { exitCodeFor } from "./api/errors.js";
8
+ import { printable } from "./util/terminalText.js";
8
9
  import { registerSearch } from "./commands/search.js";
10
+ import { registerBusinessSearch, registerNewsSearch, registerPulseSearch, } from "./commands/verticalSearch.js";
11
+ import { registerPlaceSearch } from "./commands/placeSearch.js";
9
12
  import { registerBroadSearch } from "./commands/broadSearch.js";
13
+ import { registerPremierSearch } from "./commands/premierSearch.js";
10
14
  import { registerExtract } from "./commands/extract.js";
11
15
  import { registerChat } from "./commands/chat.js";
12
16
  import { registerEmbed } from "./commands/embed.js";
13
17
  import { registerVlEmbed } from "./commands/vlEmbed.js";
14
18
  import { registerImageSearch } from "./commands/imageSearch.js";
19
+ import { registerDesignSearch } from "./commands/designSearch.js";
15
20
  import { registerVideoSearch } from "./commands/videoSearch.js";
16
21
  import { registerConfigureMcp } from "./commands/configureMcp.js";
17
22
  import { registerConfigureSkills } from "./commands/configureSkills.js";
@@ -40,13 +45,18 @@ registerReset(program);
40
45
  registerConfigureMcp(program);
41
46
  registerConfigureSkills(program);
42
47
  registerSearch(program);
43
- registerSearch(program, "news");
48
+ registerNewsSearch(program);
49
+ registerBusinessSearch(program);
50
+ registerPlaceSearch(program);
51
+ registerPulseSearch(program);
44
52
  registerBroadSearch(program);
53
+ registerPremierSearch(program);
45
54
  registerExtract(program);
46
55
  registerChat(program);
47
56
  registerEmbed(program);
48
57
  registerVlEmbed(program);
49
58
  registerImageSearch(program);
59
+ registerDesignSearch(program);
50
60
  registerVideoSearch(program);
51
61
  registerLogin(program);
52
62
  registerLogout(program);
@@ -54,6 +64,9 @@ registerWhoami(program);
54
64
  // Register LAST so introspection sees every command and its flags.
55
65
  registerCompletion(program);
56
66
  program.parseAsync().catch((err) => {
57
- process.stderr.write(pc.red(`error: ${err.message}\n`));
67
+ // An API error carries the server's own message, which is response text
68
+ // like any other: shown, never sent, if it holds control characters.
69
+ const message = printable(String(err?.message ?? err));
70
+ process.stderr.write(pc.red(`error: ${message}\n`));
58
71
  process.exit(exitCodeFor(err));
59
72
  });
@@ -0,0 +1,2 @@
1
+ import type { Command } from "commander";
2
+ export declare function registerDesignSearch(program: Command): void;
@@ -0,0 +1,63 @@
1
+ import { ENDPOINTS } from "../api/constants.js";
2
+ import { buildDesignSearchRequest, } from "../api/designSearch.js";
3
+ import { chooseMode, emit } from "../output/render.js";
4
+ import { renderDesignSearch } from "../output/pretty/designSearch.js";
5
+ import { makeClient, parseCsvOpt, parseIntOpt } from "./utils.js";
6
+ export function registerDesignSearch(program) {
7
+ program.command("design-search")
8
+ .argument("[query...]", "what to find, e.g. 'saas pricing page' (optional with --group)")
9
+ .description("Real web pages, page sections, app screens and slides as design references — each a screenshot with its design values and, for page sections, the HTML. Web results on the same query come back alongside")
10
+ .option("-n, --count <n>", "design references to return, 1-100", parseIntOpt("--count"))
11
+ .option("--group <id>", "every image of one page or deck, in order — takes a result's group_id; set -n to the group's total")
12
+ .option("--no-design-facts", "leave out the design values")
13
+ .option("--no-snippet", "leave out the code")
14
+ .option("--snippet-max-tokens <n>", "max tokens of code per result, 100-100000", parseIntOpt("--snippet-max-tokens"))
15
+ .option("--no-images", "web results only")
16
+ .option("--no-web", "design references only")
17
+ .option("--web-count <n>", "web results, 1-100", parseIntOpt("--web-count"))
18
+ .option("--include-domains <list>", "web results only: comma list", parseCsvOpt("--include-domains"))
19
+ .option("--exclude-domains <list>", "web results only: comma list", parseCsvOpt("--exclude-domains"))
20
+ .option("--language <list>", "web results only: ISO 639-1 codes, comma-separated, e.g. en,ja", parseCsvOpt("--language"))
21
+ .option("--time-basis <b>", "web results only: auto|published|crawled")
22
+ .option("--time-range <r>", "web results only: day|week|month|year (or d|w|m|y)")
23
+ .option("--start-time <when>", "web results only: YYYY-MM-DD or ISO datetime")
24
+ .option("--end-time <when>", "web results only: YYYY-MM-DD or ISO datetime")
25
+ .option("--highlight", "web results only")
26
+ .option("--highlight-max-tokens <n>", "web results only: max tokens per highlight", parseIntOpt("--highlight-max-tokens"))
27
+ .option("--full-content", "web results only")
28
+ .option("--full-content-max-tokens <n>", "web results only: max tokens per result (needs --full-content)", parseIntOpt("--full-content-max-tokens"))
29
+ .action(async (queryArg, opts, command) => {
30
+ const g = command.optsWithGlobals();
31
+ const client = makeClient(g);
32
+ // Picked field by field, not spread: commander gives every `--no-x`
33
+ // option a default of `true`, and the builder wants to know only whether
34
+ // it was switched off.
35
+ const o = {
36
+ count: opts.count,
37
+ group: opts.group,
38
+ noImages: opts.images === false,
39
+ noDesignFacts: opts.designFacts === false,
40
+ noSnippet: opts.snippet === false,
41
+ snippetMaxTokens: opts.snippetMaxTokens,
42
+ noWeb: opts.web === false,
43
+ webCount: opts.webCount,
44
+ includeDomains: opts.includeDomains,
45
+ excludeDomains: opts.excludeDomains,
46
+ language: opts.language,
47
+ timeBasis: opts.timeBasis,
48
+ timeRange: opts.timeRange,
49
+ startTime: opts.startTime,
50
+ endTime: opts.endTime,
51
+ highlight: opts.highlight,
52
+ highlightMaxTokens: opts.highlightMaxTokens,
53
+ fullContent: opts.fullContent,
54
+ fullContentMaxTokens: opts.fullContentMaxTokens,
55
+ };
56
+ const req = buildDesignSearchRequest((queryArg ?? []).join(" "), o);
57
+ const res = await client.request(ENDPOINTS.designSearch, req);
58
+ // The renderer is told when this was a lookup: it prints different hints
59
+ // for a group that was asked for than for one a search happened to hit.
60
+ const group = req.images?.group_id;
61
+ emit(res, chooseMode(g, process.stdout.isTTY ?? false), (d) => renderDesignSearch(d, { group, baseUrl: g.baseUrl }));
62
+ });
63
+ }
@@ -0,0 +1,2 @@
1
+ import type { Command } from "commander";
2
+ export declare function registerPlaceSearch(program: Command): void;
@@ -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
+ }
@@ -0,0 +1,8 @@
1
+ import type { Command } from "commander";
2
+ /**
3
+ * `/search-premier` takes the request body of `/search` and returns the same
4
+ * response, so this is `search`'s flag set and `search`'s renderer. It is a
5
+ * command of its own because it is a different endpoint, slower and billed at
6
+ * its own rate — not something a flag on `search` should switch on quietly.
7
+ */
8
+ export declare function registerPremierSearch(program: Command): void;
@@ -0,0 +1,37 @@
1
+ import { ENDPOINTS } from "../api/constants.js";
2
+ import { buildPremierSearchRequest } from "../api/premierSearch.js";
3
+ import { chooseMode, emit } from "../output/render.js";
4
+ import { renderSearch } from "../output/pretty/search.js";
5
+ import { makeClient, parseCsvOpt, parseIntOpt } from "./utils.js";
6
+ /**
7
+ * `/search-premier` takes the request body of `/search` and returns the same
8
+ * response, so this is `search`'s flag set and `search`'s renderer. It is a
9
+ * command of its own because it is a different endpoint, slower and billed at
10
+ * its own rate — not something a flag on `search` should switch on quietly.
11
+ */
12
+ export function registerPremierSearch(program) {
13
+ program.command("premier-search")
14
+ .argument("<query...>", "search query")
15
+ .description("Search the live web with deeper retrieval and reranking — slower than `search` and billed at its own rate, so reach for it when `search` falls short")
16
+ .option("--result-type <t>", "standard|dynamic")
17
+ .option("-n, --count <n>", "results 1-100", parseIntOpt("--count"))
18
+ .option("--include-domains <list>", "comma list", parseCsvOpt("--include-domains"))
19
+ .option("--exclude-domains <list>", "comma list", parseCsvOpt("--exclude-domains"))
20
+ .option("--include-text <list>", "comma list", parseCsvOpt("--include-text"))
21
+ .option("--exclude-text <list>", "comma list", parseCsvOpt("--exclude-text"))
22
+ .option("--time-basis <b>", "auto|published|crawled").option("--time-range <r>", "day|week|month|year (or d|w|m|y)")
23
+ .option("--start-time <when>", "YYYY-MM-DD or ISO datetime (e.g. 2024-01-01T00:00:00Z)")
24
+ .option("--end-time <when>", "YYYY-MM-DD or ISO datetime (e.g. 2024-12-31T23:59:59Z)")
25
+ .option("--format <f>", "text|markdown").option("--safesearch <s>", "off|strict")
26
+ .option("--language <list>", "ISO 639-1 codes, comma-separated, e.g. en,ja", parseCsvOpt("--language"))
27
+ .option("--highlight").option("--highlight-max-tokens <n>", "max tokens per highlight", parseIntOpt("--highlight-max-tokens"))
28
+ .option("--full-content").option("--full-content-max-tokens <n>", "max tokens per result", parseIntOpt("--full-content-max-tokens"))
29
+ .option("--images")
30
+ .action(async (queryArg, opts, command) => {
31
+ const g = command.optsWithGlobals();
32
+ const client = makeClient(g);
33
+ const req = buildPremierSearchRequest(queryArg.join(" "), opts);
34
+ const res = await client.request(ENDPOINTS.searchPremier, req);
35
+ emit(res, chooseMode(g, process.stdout.isTTY ?? false), renderSearch);
36
+ });
37
+ }
@@ -1,2 +1,2 @@
1
1
  import type { Command } from "commander";
2
- export declare function registerSearch(program: Command, fixedTopic?: "news"): void;
2
+ export declare function registerSearch(program: Command): void;
@@ -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, fixedTopic) {
7
- const cmd = program.command(fixedTopic ?? "search")
6
+ export function registerSearch(program) {
7
+ const cmd = program.command("search")
8
8
  .argument("<query...>", "search query")
9
- .description(fixedTopic ? "News-focused web search" : "Search the live web")
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
- if (!fixedTopic)
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 searchOpts = { ...opts, topic: fixedTopic ?? opts.topic };
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,4 @@
1
+ import type { Command } from "commander";
2
+ export declare function registerNewsSearch(program: Command): void;
3
+ export declare function registerBusinessSearch(program: Command): void;
4
+ export declare function registerPulseSearch(program: Command): void;
@@ -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,15 @@
1
+ export interface DesignRenderContext {
2
+ /** Set when the request was a group lookup, to the id that was asked for. */
3
+ group?: string;
4
+ /**
5
+ * Set when the search was sent to a base URL given on the command line, so
6
+ * the command printed for a follow-up lookup goes to the same place. A base
7
+ * URL from the environment needs nothing: it carries over by itself.
8
+ */
9
+ baseUrl?: string;
10
+ }
11
+ /**
12
+ * Design references live under `data.images`; `data.results` holds the web
13
+ * results that come back alongside.
14
+ */
15
+ export declare function renderDesignSearch(data: any, ctx?: DesignRenderContext): string;