@specstream/cli 0.1.0 → 0.2.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 +3 -2
- package/bin/specstream.js +10 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ No Node on the machine? Each release has one file per system, with nothing else
|
|
|
23
23
|
| Windows x64 | `specstream-windows-x64.exe` |
|
|
24
24
|
|
|
25
25
|
```sh
|
|
26
|
-
curl -fsSL -o specstream https://github.com/specstream/specstream-tools/releases/download/cli-v0.
|
|
26
|
+
curl -fsSL -o specstream https://github.com/specstream/specstream-tools/releases/download/cli-v0.2.0/specstream-linux-x64
|
|
27
27
|
chmod +x specstream
|
|
28
28
|
./specstream --version
|
|
29
29
|
```
|
|
@@ -36,9 +36,10 @@ chmod +x specstream
|
|
|
36
36
|
specstream search "What is the latest stable release of PostgreSQL?"
|
|
37
37
|
specstream search "open source vector databases" --fast --num 20
|
|
38
38
|
specstream search "central bank rate decision" --news --country us --json
|
|
39
|
+
specstream search "PostgreSQL 18 release notes logical replication" --passages
|
|
39
40
|
```
|
|
40
41
|
|
|
41
|
-
The Search API answers from the live web and prints the answer, the page it stands on, and the sources. The default search costs $5 per 1,000 searches of up to 10 results; `--fast` costs $1 per 1,000.
|
|
42
|
+
The Search API answers from the live web and prints the answer, the page it stands on, and the sources. The default search costs $5 per 1,000 searches of up to 10 results; `--fast` costs $1 per 1,000. `--passages` reads the pages and prints under each source the passages closest to the question, so an agent answers without opening a page; `--compact` prints one best snippet per source instead.
|
|
42
43
|
|
|
43
44
|
## Read pages
|
|
44
45
|
|
package/bin/specstream.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// One file with no dependencies, so the npm package and the single binary (Node SEA) run the same code.
|
|
4
4
|
"use strict";
|
|
5
5
|
|
|
6
|
-
const VERSION = "0.
|
|
6
|
+
const VERSION = "0.2.0";
|
|
7
7
|
const DEFAULT_BASE_URL = "https://api.specstream.ai";
|
|
8
8
|
const KEY_HELP =
|
|
9
9
|
"Set SPECSTREAM_API_KEY (or pass --api-key). Create a key under Agents & API at https://specstream.ai/workspace";
|
|
@@ -15,6 +15,8 @@ Usage:
|
|
|
15
15
|
--fast the fast search ($1 per 1,000 searches; the default search is $5 per 1,000)
|
|
16
16
|
--num <n> how many results (default 10)
|
|
17
17
|
--news news results
|
|
18
|
+
--passages each source with its passages closest to the question, read from the page
|
|
19
|
+
--compact one best snippet per source, read from the page (not with --passages or --news)
|
|
18
20
|
--country <cc> two-letter country --language <xx> two-letter language
|
|
19
21
|
specstream read <url> [<url> ...] Extract API: the main text of up to 20 pages, PDF, Word or Excel
|
|
20
22
|
--format <markdown|text> (default markdown)
|
|
@@ -38,7 +40,7 @@ ${KEY_HELP}
|
|
|
38
40
|
const VALUE_FLAGS = new Set([
|
|
39
41
|
"num", "country", "language", "format", "results", "max-cents", "key", "api-key", "base-url", "limit",
|
|
40
42
|
]);
|
|
41
|
-
const SWITCHES = new Set(["fast", "news", "json", "all", "help", "version"]);
|
|
43
|
+
const SWITCHES = new Set(["fast", "news", "passages", "compact", "json", "all", "help", "version"]);
|
|
42
44
|
|
|
43
45
|
class Usage extends Error {}
|
|
44
46
|
class ApiError extends Error {
|
|
@@ -146,6 +148,9 @@ async function search(ctx, words, flags) {
|
|
|
146
148
|
if (flags.fast) query.set("speed", "fast");
|
|
147
149
|
if (flags.num !== undefined) query.set("num", String(wholeNumber(flags, "num", 10, 1, 100)));
|
|
148
150
|
if (flags.news) query.set("news", "true");
|
|
151
|
+
if (flags.compact && (flags.passages || flags.news)) throw new Usage("--compact goes with neither --passages nor --news");
|
|
152
|
+
if (flags.passages) query.set("passages", "true");
|
|
153
|
+
if (flags.compact) query.set("compact", "true");
|
|
149
154
|
if (flags.country) query.set("country", flags.country);
|
|
150
155
|
if (flags.language) query.set("language", flags.language);
|
|
151
156
|
const data = await ctx.api("GET", "/v1/web-search?" + query);
|
|
@@ -159,7 +164,9 @@ async function search(ctx, words, flags) {
|
|
|
159
164
|
sources.forEach((source, index) => {
|
|
160
165
|
ctx.out(`${index + 1}. ${source.title || source.url}`);
|
|
161
166
|
ctx.out(` ${source.url}`);
|
|
162
|
-
|
|
167
|
+
const highlights = Array.isArray(source.highlights) ? source.highlights.filter(Boolean) : [];
|
|
168
|
+
if (highlights.length) highlights.forEach((text) => ctx.out(` > ${String(text).replace(/\s+/g, " ").trim()}`));
|
|
169
|
+
else if (source.snippet) ctx.out(` ${String(source.snippet).replace(/\s+/g, " ").trim()}`);
|
|
163
170
|
});
|
|
164
171
|
if (!sources.length && !(data.answer && data.answer.value)) ctx.err("No results.");
|
|
165
172
|
if (typeof data.price_usd === "number") ctx.err(`$${data.price_usd} charged, ${data.took_ms} ms`);
|
package/package.json
CHANGED