@octen.ai/cli 0.9.0 → 0.11.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 +24 -6
- package/dist/api/constants.d.ts +6 -5
- package/dist/api/constants.js +3 -2
- package/dist/api/extract.d.ts +57 -0
- package/dist/api/extract.js +36 -1
- package/dist/api/mediaSearch.d.ts +0 -4
- package/dist/api/mediaSearch.js +2 -10
- package/dist/commands/configureSkills.js +1 -1
- package/dist/commands/extract.js +9 -5
- package/dist/commands/imageSearch.js +1 -7
- package/dist/commands/utils.d.ts +9 -0
- package/dist/commands/utils.js +16 -0
- package/dist/output/pretty/extract.d.ts +5 -1
- package/dist/output/pretty/extract.js +64 -4
- package/package.json +1 -1
- package/skills/manifest.json +6 -2
- package/skills/octen-extract/SKILL.md +178 -0
- package/skills/octen-extract/agents/openai.yaml +4 -0
- package/skills/octen-image-search/SKILL.md +110 -0
- package/skills/octen-image-search/agents/openai.yaml +4 -0
- package/skills/octen-place-search/SKILL.md +196 -0
- package/skills/octen-place-search/agents/openai.yaml +4 -0
- package/skills/octen-search/SKILL.md +274 -4
- package/skills/octen-search/agents/openai.yaml +4 -0
- package/skills/octen-video-search/SKILL.md +108 -0
- package/skills/octen-video-search/agents/openai.yaml +4 -0
- package/skills/octen-web-search/SKILL.md +117 -0
- package/skills/octen-web-search/agents/openai.yaml +4 -0
- package/skills/octen-design/SKILL.md +0 -218
- package/skills/octen-design/scripts/search.py +0 -304
package/README.md
CHANGED
|
@@ -325,11 +325,31 @@ Extract content from one or more URLs (1–20).
|
|
|
325
325
|
|
|
326
326
|
```sh
|
|
327
327
|
octen extract https://example.com --query "pricing" --max-age 3600 --images
|
|
328
|
+
octen extract https://www.reddit.com/r/programming --mode advanced --fetch-timeout 60
|
|
329
|
+
octen extract https://docs.octen.ai --links prefer_internal --max-links 50
|
|
328
330
|
```
|
|
329
331
|
|
|
330
|
-
Options: `--query` (relevance hint), `--max-age <sec>` (cache age, 300–31536000), `--images` (also returns `cover_image` when present), `--videos`, `--audio`, `--format` (markdown|text), `--fetch-timeout <sec>` (1–60), `--full` (print full page content). The page favicon is returned by default when available.
|
|
332
|
+
Options: `--query` (relevance hint), `--max-age <sec>` (cache age, 300–31536000), `--images` (also returns `cover_image` when present), `--videos`, `--audio`, `--format` (markdown|text), `--fetch-timeout <sec>` (per-URL, 1–60), `--mode <m>` (standard|advanced|auto), `--links [scope]` (prefer_internal|prefer_external), `--max-links <n>` (1–1000), `--full` (print full page content, links and media). The page favicon is returned by default when available.
|
|
331
333
|
|
|
332
|
-
|
|
334
|
+
**Choosing `--mode`.** When omitted the server uses `standard`; the CLI never sends a mode you did not ask for.
|
|
335
|
+
|
|
336
|
+
- `standard` (default): fastest and cheapest ($1 / 1K successful URLs). Right for well-structured pages without anti-bot protection: news, blogs, docs, product pages, static sites. On login-walled, JS-heavy or anti-bot sites it may return empty content or only a page skeleton and still report `success`.
|
|
337
|
+
- `advanced`: highest success rate. Renders in a real browser with stronger anti-bot handling; slower and 2.5x the price ($2.5 / 1K). Use it for known hard sites: anti-bot/WAF-protected sites, JS-heavy SPAs, social sites (Reddit, X, LinkedIn), academic sites (ResearchGate), dynamically loaded content.
|
|
338
|
+
- `auto`: picks per URL — standard where it suffices, advanced only for hard URLs, each billed at the mode it actually used. Use it for a mixed batch when you can't tell which URLs are hard; if most are hard, its cost approaches all-advanced.
|
|
339
|
+
|
|
340
|
+
| Scenario | mode |
|
|
341
|
+
|---|---|
|
|
342
|
+
| News / blogs / docs / product pages (ordinary sites) | standard (or omit) |
|
|
343
|
+
| Known hard sites (Reddit / X / LinkedIn / ResearchGate / anti-bot / SPA) | advanced |
|
|
344
|
+
| Mixed batch, unsure which are hard | auto |
|
|
345
|
+
| Cost-sensitive, mostly ordinary sites | standard |
|
|
346
|
+
| Quality first, mostly hard sites | advanced |
|
|
347
|
+
|
|
348
|
+
If a standard result failed or came back empty/skeletal (`page_structure.primary` "No Main Content", or very short content on a page that should have a body), retry just those URLs with `--mode advanced`; pretty output prints that hint under failed and "No Main Content" results unless advanced was already requested or used. With advanced/auto, raise `--fetch-timeout` (e.g. 60). The client's own request timeout follows it: `fetch-timeout + 90s` (capped at 180s), so 120s when `--fetch-timeout` is omitted and at most 150s. That timeout is per attempt, and 429/5xx responses are retried (up to 3 times), so the worst-case wall time is longer. Failed URLs are not billed; each successful result carries `resolved_mode` (the mode actually used, which can differ from the one requested), and the authoritative billing count is `meta.usage.successful_by_mode`, shown in the pretty-output footer.
|
|
349
|
+
|
|
350
|
+
**Links.** `--links` returns each page's links (`url`, `anchor_text`, `is_external`) — use it to discover a site's pages or follow outbound references. A bare `--links` uses the server defaults; `--links prefer_internal` (the default) lists same-site links first, `--links prefer_external` lists links to other registered domains first, keeping page order within each group. `--max-links <n>` caps the count (1–1000, default 200) and implies `--links`. Because the scope is optional, put `--links` after the URLs or write `--links=<scope>`; if it would swallow a URL as its scope, the CLI stops with an error saying so.
|
|
351
|
+
|
|
352
|
+
Pretty output truncates page content to ~500 chars and lists at most 10 links and 10 of each media type for readability; pass `--full` to print everything (or `--json` for the raw response).
|
|
333
353
|
|
|
334
354
|
---
|
|
335
355
|
|
|
@@ -392,19 +412,17 @@ Options: `-m/--model` (base|large or full ID), `--fusion`/`--no-fusion`, `--dime
|
|
|
392
412
|
|
|
393
413
|
### `octen image-search`
|
|
394
414
|
|
|
395
|
-
**In Beta** — contact us to request beta access.
|
|
396
|
-
|
|
397
415
|
Search the web for images, either by text query or by example image.
|
|
398
416
|
|
|
399
417
|
```sh
|
|
400
|
-
octen image-search "red sports car" -n 10
|
|
418
|
+
octen image-search "red sports car" -n 10
|
|
401
419
|
octen image-search --image https://example.com/car.jpg
|
|
402
420
|
octen image-search --image ./car.png
|
|
403
421
|
```
|
|
404
422
|
|
|
405
423
|
The endpoint takes exactly one input, so pass a query **or** `--image`, not both. `--image` accepts a public URL or a local file path (read inline as base64, max 5MB).
|
|
406
424
|
|
|
407
|
-
Options: `--image <url|path>`,
|
|
425
|
+
Options: `--image <url|path>`, `-n` (result count 1–10), `--include-domains`, `--exclude-domains`, `--safesearch` (off|strict).
|
|
408
426
|
|
|
409
427
|
Unlike `octen search` and `octen video-search`, this endpoint has no time filters.
|
|
410
428
|
|
package/dist/api/constants.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ export declare const LIMITS: {
|
|
|
32
32
|
readonly min: 1;
|
|
33
33
|
readonly max: 60;
|
|
34
34
|
};
|
|
35
|
+
readonly maxLinks: {
|
|
36
|
+
readonly min: 1;
|
|
37
|
+
readonly max: 1000;
|
|
38
|
+
};
|
|
35
39
|
readonly cacheWindow: {
|
|
36
40
|
readonly min: 300;
|
|
37
41
|
readonly max: 31536000;
|
|
@@ -45,10 +49,6 @@ export declare const LIMITS: {
|
|
|
45
49
|
readonly min: 100;
|
|
46
50
|
readonly max: 100000;
|
|
47
51
|
};
|
|
48
|
-
readonly htmlSnippetMaxTokens: {
|
|
49
|
-
readonly min: 100;
|
|
50
|
-
readonly max: 100000;
|
|
51
|
-
};
|
|
52
52
|
readonly vlContents: 20;
|
|
53
53
|
readonly vlImages: 5;
|
|
54
54
|
readonly vlVideos: 1;
|
|
@@ -62,10 +62,11 @@ export declare const LIMITS: {
|
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
64
|
export declare const TOPIC_OPTIONS: readonly ["general", "news"];
|
|
65
|
-
export declare const IMAGE_TOPIC_OPTIONS: readonly ["general", "design"];
|
|
66
65
|
export declare const TIME_BASIS_OPTIONS: readonly ["auto", "published", "crawled"];
|
|
67
66
|
export declare const TIME_RANGE_OPTIONS: readonly ["day", "week", "month", "year", "d", "w", "m", "y"];
|
|
68
67
|
export declare const SAFESEARCH_OPTIONS: readonly ["off", "strict"];
|
|
69
68
|
export declare const FORMAT_OPTIONS: readonly ["text", "markdown"];
|
|
69
|
+
export declare const EXTRACT_MODE_OPTIONS: readonly ["standard", "advanced", "auto"];
|
|
70
|
+
export declare const LINK_SCOPE_OPTIONS: readonly ["prefer_internal", "prefer_external"];
|
|
70
71
|
export declare const SKILLS_REPO = "Octen-Team/octen-skills";
|
|
71
72
|
export declare const SKILLS_REPO_TARBALL: (ref: string) => string;
|
package/dist/api/constants.js
CHANGED
|
@@ -27,10 +27,10 @@ export const LIMITS = {
|
|
|
27
27
|
excludeText: 5,
|
|
28
28
|
extractUrls: { min: 1, max: 20 },
|
|
29
29
|
extractTimeout: { min: 1, max: 60 },
|
|
30
|
+
maxLinks: { min: 1, max: 1000 },
|
|
30
31
|
cacheWindow: { min: 300, max: 31_536_000, default: 86_400 },
|
|
31
32
|
highlightMaxTokens: { min: 100, max: 20_000 },
|
|
32
33
|
fullContentMaxTokens: { min: 100, max: 100_000 },
|
|
33
|
-
htmlSnippetMaxTokens: { min: 100, max: 100_000 },
|
|
34
34
|
vlContents: 20,
|
|
35
35
|
vlImages: 5,
|
|
36
36
|
vlVideos: 1,
|
|
@@ -38,10 +38,11 @@ export const LIMITS = {
|
|
|
38
38
|
videoCount: { min: 1, max: 10 },
|
|
39
39
|
};
|
|
40
40
|
export const TOPIC_OPTIONS = ["general", "news"];
|
|
41
|
-
export const IMAGE_TOPIC_OPTIONS = ["general", "design"];
|
|
42
41
|
export const TIME_BASIS_OPTIONS = ["auto", "published", "crawled"];
|
|
43
42
|
export const TIME_RANGE_OPTIONS = ["day", "week", "month", "year", "d", "w", "m", "y"];
|
|
44
43
|
export const SAFESEARCH_OPTIONS = ["off", "strict"];
|
|
45
44
|
export const FORMAT_OPTIONS = ["text", "markdown"];
|
|
45
|
+
export const EXTRACT_MODE_OPTIONS = ["standard", "advanced", "auto"];
|
|
46
|
+
export const LINK_SCOPE_OPTIONS = ["prefer_internal", "prefer_external"];
|
|
46
47
|
export const SKILLS_REPO = "Octen-Team/octen-skills";
|
|
47
48
|
export const SKILLS_REPO_TARBALL = (ref) => `https://github.com/${SKILLS_REPO}/archive/${ref}.tar.gz`;
|
package/dist/api/extract.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
import { EXTRACT_MODE_OPTIONS, LINK_SCOPE_OPTIONS } from "./constants.js";
|
|
2
|
+
export type ExtractMode = (typeof EXTRACT_MODE_OPTIONS)[number];
|
|
3
|
+
export type LinkScope = (typeof LINK_SCOPE_OPTIONS)[number];
|
|
4
|
+
/** A link found on an extracted page (only when include_links was requested). */
|
|
5
|
+
export interface ExtractLink {
|
|
6
|
+
url?: string;
|
|
7
|
+
anchor_text?: string;
|
|
8
|
+
is_external?: boolean;
|
|
9
|
+
}
|
|
1
10
|
/** A single extracted item. All fields optional — the server is untyped. */
|
|
2
11
|
export interface ExtractItem {
|
|
3
12
|
url?: string;
|
|
4
13
|
status?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The mode actually used for this URL; present on success only. It can differ
|
|
16
|
+
* from the requested mode (auto picks per URL, advanced may resolve to standard).
|
|
17
|
+
*/
|
|
18
|
+
resolved_mode?: "standard" | "advanced";
|
|
5
19
|
title?: string;
|
|
6
20
|
category?: {
|
|
7
21
|
primary?: string;
|
|
@@ -12,12 +26,23 @@ export interface ExtractItem {
|
|
|
12
26
|
secondary?: string;
|
|
13
27
|
};
|
|
14
28
|
time_published?: string;
|
|
29
|
+
time_last_crawled?: string;
|
|
15
30
|
full_content?: string;
|
|
16
31
|
highlights?: string[];
|
|
17
32
|
favicon?: string;
|
|
18
33
|
cover_image?: {
|
|
19
34
|
url?: string;
|
|
20
35
|
};
|
|
36
|
+
images?: {
|
|
37
|
+
url?: string;
|
|
38
|
+
}[];
|
|
39
|
+
videos?: {
|
|
40
|
+
url?: string;
|
|
41
|
+
}[];
|
|
42
|
+
audio?: {
|
|
43
|
+
url?: string;
|
|
44
|
+
}[];
|
|
45
|
+
links?: ExtractLink[];
|
|
21
46
|
error_message?: string;
|
|
22
47
|
}
|
|
23
48
|
/** Response shape for the /extract endpoint. */
|
|
@@ -25,6 +50,31 @@ export interface ExtractResponse {
|
|
|
25
50
|
items?: ExtractItem[];
|
|
26
51
|
results?: ExtractItem[];
|
|
27
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Top-level `meta` of an /extract response — a sibling of `data`, not inside it.
|
|
55
|
+
* Billing is authoritative from `usage.successful_by_mode`, not from summing
|
|
56
|
+
* each item's `resolved_mode`.
|
|
57
|
+
*/
|
|
58
|
+
export interface ExtractMeta {
|
|
59
|
+
usage?: {
|
|
60
|
+
total_urls?: number;
|
|
61
|
+
successful_urls?: number;
|
|
62
|
+
successful_by_mode?: {
|
|
63
|
+
standard_urls?: number;
|
|
64
|
+
advanced_urls?: number;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
latency?: number;
|
|
68
|
+
/** e.g. "1 URL(s) failed and were not billed"; empty when there is nothing to report. */
|
|
69
|
+
warning?: string;
|
|
70
|
+
}
|
|
71
|
+
/** The full /extract envelope as the client returns it. */
|
|
72
|
+
export interface ExtractEnvelope {
|
|
73
|
+
data?: ExtractResponse;
|
|
74
|
+
meta?: ExtractMeta;
|
|
75
|
+
code?: number;
|
|
76
|
+
msg?: string;
|
|
77
|
+
}
|
|
28
78
|
export interface ExtractOpts {
|
|
29
79
|
query?: string;
|
|
30
80
|
maxAge?: number;
|
|
@@ -33,7 +83,14 @@ export interface ExtractOpts {
|
|
|
33
83
|
images?: boolean;
|
|
34
84
|
videos?: boolean;
|
|
35
85
|
audio?: boolean;
|
|
86
|
+
/** Omitted unless given: the server defaults to standard, and we never inject one. */
|
|
87
|
+
mode?: ExtractMode;
|
|
88
|
+
/** `--links` alone is `true` (server defaults); `--links <scope>` is the scope string. */
|
|
89
|
+
links?: boolean | string;
|
|
90
|
+
maxLinks?: number;
|
|
36
91
|
}
|
|
92
|
+
/** Whole-request client timeout (ms) for one /extract call. */
|
|
93
|
+
export declare function extractClientTimeoutMs(fetchTimeout?: number): number;
|
|
37
94
|
/**
|
|
38
95
|
* Auto-prefix bare hosts with https:// and reject inputs that are not plausible
|
|
39
96
|
* http(s) URLs, so obvious typos fail client-side instead of being silently
|
package/dist/api/extract.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
import { LIMITS } from "./constants.js";
|
|
1
|
+
import { EXTRACT_MODE_OPTIONS, LIMITS, LINK_SCOPE_OPTIONS } from "./constants.js";
|
|
2
2
|
import { OctenValidationError } from "./errors.js";
|
|
3
|
+
import { validateEnum } from "./search.js";
|
|
4
|
+
/**
|
|
5
|
+
* `timeout` in the body is the server-side, per-URL fetch budget, so it cannot
|
|
6
|
+
* double as the client ceiling: a 20-URL call, or one in advanced/auto mode, can
|
|
7
|
+
* legitimately outlast it. Allow the per-URL budget plus headroom for the
|
|
8
|
+
* server's own fan-out, bounded so a wedged request still fails. Mirrors octen-mcp.
|
|
9
|
+
*/
|
|
10
|
+
const EXTRACT_SERVER_TIMEOUT_DEFAULT_SEC = 30;
|
|
11
|
+
const EXTRACT_CLIENT_HEADROOM_SEC = 90;
|
|
12
|
+
// Unreachable from the CLI (--fetch-timeout <= 60 gives at most 150s); kept to
|
|
13
|
+
// mirror octen-mcp and to bound any programmatic caller that skips validation.
|
|
14
|
+
const EXTRACT_CLIENT_TIMEOUT_CAP_SEC = 180;
|
|
15
|
+
/** Whole-request client timeout (ms) for one /extract call. */
|
|
16
|
+
export function extractClientTimeoutMs(fetchTimeout) {
|
|
17
|
+
const sec = Math.min(EXTRACT_CLIENT_TIMEOUT_CAP_SEC, (fetchTimeout ?? EXTRACT_SERVER_TIMEOUT_DEFAULT_SEC) + EXTRACT_CLIENT_HEADROOM_SEC);
|
|
18
|
+
return sec * 1000;
|
|
19
|
+
}
|
|
3
20
|
/**
|
|
4
21
|
* Auto-prefix bare hosts with https:// and reject inputs that are not plausible
|
|
5
22
|
* http(s) URLs, so obvious typos fail client-side instead of being silently
|
|
@@ -29,6 +46,14 @@ export function buildExtractRequest(urls, o) {
|
|
|
29
46
|
throw new OctenValidationError(`fetch-timeout must be ${LIMITS.extractTimeout.min}-${LIMITS.extractTimeout.max}`);
|
|
30
47
|
if (o.maxAge != null && (o.maxAge < LIMITS.cacheWindow.min || o.maxAge > LIMITS.cacheWindow.max))
|
|
31
48
|
throw new OctenValidationError(`max-age must be ${LIMITS.cacheWindow.min}-${LIMITS.cacheWindow.max} seconds`);
|
|
49
|
+
validateEnum("--mode", o.mode, EXTRACT_MODE_OPTIONS);
|
|
50
|
+
// Commander yields `true` for a bare `--links`; only a string names a scope. The
|
|
51
|
+
// CLI's option parser already checked it; this keeps programmatic callers honest.
|
|
52
|
+
const scope = typeof o.links === "string" ? o.links : undefined;
|
|
53
|
+
validateEnum("--links", scope, LINK_SCOPE_OPTIONS);
|
|
54
|
+
// Out-of-range max_links is a server 400 (not clamped like timeout), so check here.
|
|
55
|
+
if (o.maxLinks != null && (o.maxLinks < LIMITS.maxLinks.min || o.maxLinks > LIMITS.maxLinks.max))
|
|
56
|
+
throw new OctenValidationError(`max-links must be ${LIMITS.maxLinks.min}-${LIMITS.maxLinks.max}`);
|
|
32
57
|
const normalizedUrls = urls.map(normalizeExtractUrl);
|
|
33
58
|
const maxAge = o.maxAge;
|
|
34
59
|
const req = { urls: normalizedUrls };
|
|
@@ -41,5 +66,15 @@ export function buildExtractRequest(urls, o) {
|
|
|
41
66
|
put("include_images", o.images);
|
|
42
67
|
put("include_videos", o.videos);
|
|
43
68
|
put("include_audio", o.audio);
|
|
69
|
+
put("mode", o.mode);
|
|
70
|
+
// --links and --max-links both opt in; `{}` lets the server apply its defaults.
|
|
71
|
+
if (o.links || o.maxLinks != null) {
|
|
72
|
+
const includeLinks = {};
|
|
73
|
+
if (scope != null)
|
|
74
|
+
includeLinks.scope = scope;
|
|
75
|
+
if (o.maxLinks != null)
|
|
76
|
+
includeLinks.max_links = o.maxLinks;
|
|
77
|
+
req.include_links = includeLinks;
|
|
78
|
+
}
|
|
44
79
|
return req;
|
|
45
80
|
}
|
|
@@ -10,7 +10,6 @@ export interface ImageSearchResult {
|
|
|
10
10
|
time_published?: string;
|
|
11
11
|
time_last_crawled?: string;
|
|
12
12
|
summary?: string;
|
|
13
|
-
html_snippet?: string;
|
|
14
13
|
}
|
|
15
14
|
/** Response shape for the /image-search endpoint. */
|
|
16
15
|
export interface ImageSearchResponse {
|
|
@@ -19,13 +18,10 @@ export interface ImageSearchResponse {
|
|
|
19
18
|
export interface ImageSearchOpts {
|
|
20
19
|
/** Optional image input: a public http(s) URL or a local file path. */
|
|
21
20
|
image?: string;
|
|
22
|
-
topic?: "general" | "design";
|
|
23
21
|
count?: number;
|
|
24
22
|
includeDomains?: string[];
|
|
25
23
|
excludeDomains?: string[];
|
|
26
24
|
safesearch?: "off" | "strict";
|
|
27
|
-
htmlSnippet?: boolean;
|
|
28
|
-
htmlSnippetMaxTokens?: number;
|
|
29
25
|
}
|
|
30
26
|
export declare function buildImageSearchRequest(query: string, o: ImageSearchOpts): Record<string, unknown>;
|
|
31
27
|
/** Matched segment within a video result. */
|
package/dist/api/mediaSearch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync, existsSync, statSync } from "node:fs";
|
|
2
|
-
import { LIMITS,
|
|
2
|
+
import { LIMITS, TIME_RANGE_OPTIONS, SAFESEARCH_OPTIONS, } from "./constants.js";
|
|
3
3
|
import { OctenValidationError } from "./errors.js";
|
|
4
|
-
import { validateEnum, normalizeTimeBound
|
|
4
|
+
import { validateEnum, normalizeTimeBound } from "./search.js";
|
|
5
5
|
/** Max size of a local image read inline as base64. */
|
|
6
6
|
const MAX_IMAGE_BYTES = 5 * 1024 * 1024; // 5 MB
|
|
7
7
|
/**
|
|
@@ -40,22 +40,14 @@ export function buildImageSearchRequest(query, o) {
|
|
|
40
40
|
throw new OctenValidationError("provide a query or --image");
|
|
41
41
|
if (o.count != null && (o.count < LIMITS.imageCount.min || o.count > LIMITS.imageCount.max))
|
|
42
42
|
throw new OctenValidationError(`count must be ${LIMITS.imageCount.min}-${LIMITS.imageCount.max}`);
|
|
43
|
-
assertRange("--html-snippet-max-tokens", o.htmlSnippetMaxTokens, LIMITS.htmlSnippetMaxTokens);
|
|
44
|
-
validateEnum("--topic", o.topic, IMAGE_TOPIC_OPTIONS);
|
|
45
43
|
validateEnum("--safesearch", o.safesearch, SAFESEARCH_OPTIONS);
|
|
46
44
|
const req = { inputs };
|
|
47
45
|
const put = (k, v) => { if (v != null)
|
|
48
46
|
req[k] = v; };
|
|
49
|
-
put("topic", o.topic);
|
|
50
47
|
put("count", o.count);
|
|
51
48
|
put("include_domains", o.includeDomains);
|
|
52
49
|
put("exclude_domains", o.excludeDomains);
|
|
53
50
|
put("safesearch", o.safesearch);
|
|
54
|
-
if (o.htmlSnippet)
|
|
55
|
-
req.html_snippet = {
|
|
56
|
-
enable: true,
|
|
57
|
-
...(o.htmlSnippetMaxTokens ? { max_tokens: o.htmlSnippetMaxTokens } : {}),
|
|
58
|
-
};
|
|
59
51
|
return req;
|
|
60
52
|
}
|
|
61
53
|
export function buildVideoSearchRequest(query, o) {
|
|
@@ -25,7 +25,7 @@ export function registerConfigureSkills(program, internal = {}) {
|
|
|
25
25
|
.option("--hermes", "install into Hermes")
|
|
26
26
|
.option("--skills-dir <path>", "use a custom skills source directory")
|
|
27
27
|
.option("--scope <s>", "config scope: user | project (default: user)", parseScopeOpt("--scope"), "user")
|
|
28
|
-
.option("--only <names>", "comma-separated list of skill names to install (e.g. octen-search,octen-
|
|
28
|
+
.option("--only <names>", "comma-separated list of skill names to install (e.g. octen-search,octen-place-search)", parseCsvOpt("--only"))
|
|
29
29
|
.option("--ref <ref>", "upstream git ref to fetch skills from", "main")
|
|
30
30
|
.option("--bundled", "force use of bundled (vendored) skills — no network")
|
|
31
31
|
.option("--offline", "alias for --bundled")
|
package/dist/commands/extract.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ENDPOINTS } from "../api/constants.js";
|
|
2
|
-
import { buildExtractRequest } from "../api/extract.js";
|
|
2
|
+
import { buildExtractRequest, extractClientTimeoutMs, } from "../api/extract.js";
|
|
3
3
|
import { chooseMode, emit } from "../output/render.js";
|
|
4
4
|
import { renderExtract } from "../output/pretty/extract.js";
|
|
5
|
-
import { makeClient, parseIntOpt } from "./utils.js";
|
|
5
|
+
import { makeClient, parseIntOpt, parseLinkScopeOpt } from "./utils.js";
|
|
6
6
|
export function registerExtract(program) {
|
|
7
7
|
program
|
|
8
8
|
.command("extract")
|
|
@@ -15,12 +15,16 @@ export function registerExtract(program) {
|
|
|
15
15
|
.option("--images", "include images (also returns cover_image when present)")
|
|
16
16
|
.option("--videos", "include videos")
|
|
17
17
|
.option("--audio", "include audio")
|
|
18
|
-
.option("--
|
|
18
|
+
.option("--mode <m>", "standard (default, fast/cheap) | advanced (hard sites, 2.5x) | auto (mixed batch)")
|
|
19
|
+
.option("--links [scope]", "include page links; scope prefer_internal (default) | prefer_external", parseLinkScopeOpt("--links"))
|
|
20
|
+
.option("--max-links <n>", "max links per page (1-1000, default 200); implies --links", parseIntOpt("--max-links"))
|
|
21
|
+
.option("--full", "print full page content, links and media untruncated (pretty mode)")
|
|
19
22
|
.action(async (urls, opts, command) => {
|
|
20
23
|
const g = command.optsWithGlobals();
|
|
21
24
|
const client = makeClient(g);
|
|
22
25
|
const req = buildExtractRequest(urls, opts);
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
// Per-call ceiling derived from the per-URL budget; the client default is too tight.
|
|
27
|
+
const res = await client.request(ENDPOINTS.extract, req, extractClientTimeoutMs(opts.fetchTimeout));
|
|
28
|
+
emit(res, chooseMode(g, process.stdout.isTTY ?? false), (d) => renderExtract(d, opts.full, opts.mode));
|
|
25
29
|
});
|
|
26
30
|
}
|
|
@@ -7,28 +7,22 @@ export function registerImageSearch(program) {
|
|
|
7
7
|
program
|
|
8
8
|
.command("image-search")
|
|
9
9
|
.argument("[query...]", "search query (optional if --image is given)")
|
|
10
|
-
.description("
|
|
10
|
+
.description("Search the web for images by text or by image (one or the other)")
|
|
11
11
|
.option("--image <url|path>", "image input: public URL or local file path")
|
|
12
|
-
.option("--topic <t>", "general|design")
|
|
13
12
|
.option("-n, --count <n>", "results 1-10", parseIntOpt("--count"))
|
|
14
13
|
.option("--include-domains <list>", "comma list", parseCsvOpt("--include-domains"))
|
|
15
14
|
.option("--exclude-domains <list>", "comma list", parseCsvOpt("--exclude-domains"))
|
|
16
15
|
.option("--safesearch <s>", "off|strict")
|
|
17
|
-
.option("--html-snippet", "include HTML snippet for each result")
|
|
18
|
-
.option("--html-snippet-max-tokens <n>", "max tokens per HTML snippet", parseIntOpt("--html-snippet-max-tokens"))
|
|
19
16
|
.action(async (queryArg, opts, command) => {
|
|
20
17
|
const g = command.optsWithGlobals();
|
|
21
18
|
const client = makeClient(g);
|
|
22
19
|
const query = Array.isArray(queryArg) ? queryArg.join(" ") : (queryArg ?? "");
|
|
23
20
|
const imageOpts = {
|
|
24
21
|
image: opts.image,
|
|
25
|
-
topic: opts.topic,
|
|
26
22
|
count: opts.count,
|
|
27
23
|
includeDomains: opts.includeDomains,
|
|
28
24
|
excludeDomains: opts.excludeDomains,
|
|
29
25
|
safesearch: opts.safesearch,
|
|
30
|
-
htmlSnippet: opts.htmlSnippet,
|
|
31
|
-
htmlSnippetMaxTokens: opts.htmlSnippetMaxTokens,
|
|
32
26
|
};
|
|
33
27
|
const req = buildImageSearchRequest(query, imageOpts);
|
|
34
28
|
const res = await client.request(ENDPOINTS.imageSearch, req);
|
package/dist/commands/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OctenClient } from "../api/client.js";
|
|
2
|
+
import type { LinkScope } from "../api/extract.js";
|
|
2
3
|
/** Build an OctenClient from resolved global options (flag > env). */
|
|
3
4
|
export declare function makeClient(g: {
|
|
4
5
|
apiKey?: string;
|
|
@@ -27,3 +28,11 @@ export type ConfigScope = (typeof SCOPE_OPTIONS)[number];
|
|
|
27
28
|
* for, and `reset` would then delete from the wrong one.
|
|
28
29
|
*/
|
|
29
30
|
export declare const parseScopeOpt: (name: string) => (v: string) => ConfigScope;
|
|
31
|
+
/**
|
|
32
|
+
* Commander option parser for extract's `--links [scope]`. The scope is optional,
|
|
33
|
+
* so commander hands the next bare word to this parser — which, in
|
|
34
|
+
* `octen extract --links https://a.com`, is a URL. Name that mistake instead of
|
|
35
|
+
* letting it surface as an unknown scope (or as "missing required argument").
|
|
36
|
+
* A bare `--links` never reaches here: commander sets `true` without parsing.
|
|
37
|
+
*/
|
|
38
|
+
export declare const parseLinkScopeOpt: (name: string) => (v: string) => LinkScope;
|
package/dist/commands/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OctenClient } from "../api/client.js";
|
|
2
|
+
import { LINK_SCOPE_OPTIONS } from "../api/constants.js";
|
|
2
3
|
import { OctenValidationError } from "../api/errors.js";
|
|
3
4
|
import { resolveApiKey, resolveBaseUrl } from "../config/resolve.js";
|
|
4
5
|
/** Build an OctenClient from resolved global options (flag > env). */
|
|
@@ -59,3 +60,18 @@ export const parseScopeOpt = (name) => (v) => {
|
|
|
59
60
|
}
|
|
60
61
|
return v;
|
|
61
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* Commander option parser for extract's `--links [scope]`. The scope is optional,
|
|
65
|
+
* so commander hands the next bare word to this parser — which, in
|
|
66
|
+
* `octen extract --links https://a.com`, is a URL. Name that mistake instead of
|
|
67
|
+
* letting it surface as an unknown scope (or as "missing required argument").
|
|
68
|
+
* A bare `--links` never reaches here: commander sets `true` without parsing.
|
|
69
|
+
*/
|
|
70
|
+
export const parseLinkScopeOpt = (name) => (v) => {
|
|
71
|
+
if (LINK_SCOPE_OPTIONS.includes(v))
|
|
72
|
+
return v;
|
|
73
|
+
if (v.includes("://") || v.includes(".")) {
|
|
74
|
+
throw new OctenValidationError(`${name} got "${v}" as its scope; put ${name} after the URLs or use ${name}=<scope>`);
|
|
75
|
+
}
|
|
76
|
+
throw new OctenValidationError(`${name} must be one of: ${LINK_SCOPE_OPTIONS.join(", ")}`);
|
|
77
|
+
};
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @param requestedMode the `--mode` the caller asked for, if any. Used only to
|
|
3
|
+
* decide whether suggesting `--mode advanced` would be news to them.
|
|
4
|
+
*/
|
|
5
|
+
export declare function renderExtract(data: any, full?: boolean, requestedMode?: string): string;
|
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
import pc from "picocolors";
|
|
2
2
|
const MAX_CONTENT = 500;
|
|
3
|
-
|
|
3
|
+
/** Links and media lists are capped like content: first N entries unless --full. */
|
|
4
|
+
const MAX_LIST = 10;
|
|
5
|
+
/** A labelled, indented URL list, capped at MAX_LIST unless `full`. */
|
|
6
|
+
function formatList(label, entries, full) {
|
|
7
|
+
if (!entries.length)
|
|
8
|
+
return [];
|
|
9
|
+
const shown = full ? entries : entries.slice(0, MAX_LIST);
|
|
10
|
+
const lines = [pc.dim(` ${label} (${entries.length}):`), ...shown.map((e) => ` ${e}`)];
|
|
11
|
+
if (shown.length < entries.length)
|
|
12
|
+
lines.push(pc.dim(` … ${entries.length - shown.length} more (--full to show all)`));
|
|
13
|
+
return lines;
|
|
14
|
+
}
|
|
15
|
+
function formatLink(l) {
|
|
16
|
+
const anchor = l.anchor_text ? ` ${pc.dim(`— ${l.anchor_text}`)}` : "";
|
|
17
|
+
const ext = l.is_external ? ` ${pc.dim("[external]")}` : "";
|
|
18
|
+
return `${l.url ?? ""}${anchor}${ext}`;
|
|
19
|
+
}
|
|
20
|
+
const mediaUrls = (list) => (list ?? []).map((m) => m.url).filter((u) => !!u);
|
|
21
|
+
/** Footer from the top-level `meta`: counts, billing by mode, and any warning. */
|
|
22
|
+
function formatFooter(meta) {
|
|
23
|
+
if (!meta || typeof meta !== "object")
|
|
24
|
+
return undefined;
|
|
25
|
+
const lines = [];
|
|
26
|
+
const usage = meta.usage;
|
|
27
|
+
const parts = [];
|
|
28
|
+
if (usage?.total_urls != null)
|
|
29
|
+
parts.push(`${usage.successful_urls ?? 0}/${usage.total_urls} successful`);
|
|
30
|
+
const byMode = usage?.successful_by_mode;
|
|
31
|
+
if (byMode)
|
|
32
|
+
parts.push(`billed: ${byMode.standard_urls ?? 0} standard, ${byMode.advanced_urls ?? 0} advanced`);
|
|
33
|
+
if (parts.length)
|
|
34
|
+
lines.push(pc.dim(parts.join(" · ")));
|
|
35
|
+
if (meta.warning)
|
|
36
|
+
lines.push(pc.yellow(`warning: ${meta.warning}`));
|
|
37
|
+
return lines.length ? lines.join("\n") : undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @param requestedMode the `--mode` the caller asked for, if any. Used only to
|
|
41
|
+
* decide whether suggesting `--mode advanced` would be news to them.
|
|
42
|
+
*/
|
|
43
|
+
export function renderExtract(data, full = false, requestedMode) {
|
|
4
44
|
// The Octen API wraps the payload in an envelope: { data: { results }, code, msg, ... }.
|
|
5
45
|
// Unwrap to the inner body only when `data.data` is a non-array object (the real
|
|
6
46
|
// API shape); fall back to the raw object otherwise so un-enveloped inputs still work.
|
|
@@ -20,13 +60,16 @@ export function renderExtract(data, full = false) {
|
|
|
20
60
|
}
|
|
21
61
|
return pc.dim("No results.");
|
|
22
62
|
}
|
|
23
|
-
|
|
63
|
+
const blocks = items
|
|
24
64
|
.map((item) => {
|
|
25
65
|
const lines = [];
|
|
26
66
|
// Bold URL header
|
|
27
67
|
lines.push(pc.bold(item.url));
|
|
28
68
|
if (item.status === "failed") {
|
|
29
69
|
lines.push(pc.red(` failed: ${item.error_message ?? "(unknown error)"}`));
|
|
70
|
+
// resolved_mode is absent on failure, so only the requested mode can rule it out.
|
|
71
|
+
if (requestedMode !== "advanced")
|
|
72
|
+
lines.push(pc.dim(" hint: retry with --mode advanced"));
|
|
30
73
|
}
|
|
31
74
|
else {
|
|
32
75
|
// Dim metadata line: category / page_structure
|
|
@@ -39,6 +82,9 @@ export function renderExtract(data, full = false) {
|
|
|
39
82
|
// Title
|
|
40
83
|
if (item.title)
|
|
41
84
|
lines.push(` ${item.title}`);
|
|
85
|
+
// The mode actually used — may differ from the requested one.
|
|
86
|
+
if (item.resolved_mode)
|
|
87
|
+
lines.push(pc.dim(` mode: ${item.resolved_mode}`));
|
|
42
88
|
// Media identity: favicon (default) + cover image (with --images)
|
|
43
89
|
if (item.favicon)
|
|
44
90
|
lines.push(pc.dim(` favicon: ${item.favicon}`));
|
|
@@ -53,8 +99,22 @@ export function renderExtract(data, full = false) {
|
|
|
53
99
|
const snippet = !full && raw.length > MAX_CONTENT ? raw.slice(0, MAX_CONTENT) + "…" : raw;
|
|
54
100
|
lines.push(` ${snippet}`);
|
|
55
101
|
}
|
|
102
|
+
lines.push(...formatList("images", mediaUrls(item.images), full));
|
|
103
|
+
lines.push(...formatList("videos", mediaUrls(item.videos), full));
|
|
104
|
+
lines.push(...formatList("audio", mediaUrls(item.audio), full));
|
|
105
|
+
lines.push(...formatList("links", (item.links ?? []).map(formatLink), full));
|
|
106
|
+
// Standard can report "success" with only a page skeleton; advanced often recovers it.
|
|
107
|
+
if (structPrimary === "No Main Content" &&
|
|
108
|
+
item.resolved_mode !== "advanced" &&
|
|
109
|
+
requestedMode !== "advanced") {
|
|
110
|
+
lines.push(pc.dim(" hint: retry with --mode advanced"));
|
|
111
|
+
}
|
|
56
112
|
}
|
|
57
113
|
return lines.join("\n");
|
|
58
|
-
})
|
|
59
|
-
|
|
114
|
+
});
|
|
115
|
+
// `meta` is top-level in the envelope (a sibling of `data`), not inside it.
|
|
116
|
+
const footer = formatFooter(data?.meta);
|
|
117
|
+
if (footer)
|
|
118
|
+
blocks.push(footer);
|
|
119
|
+
return blocks.join("\n\n");
|
|
60
120
|
}
|
package/package.json
CHANGED
package/skills/manifest.json
CHANGED