@octen.ai/cli 0.8.0 → 0.10.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 (63) hide show
  1. package/README.md +272 -6
  2. package/dist/api/constants.d.ts +6 -0
  3. package/dist/api/constants.js +3 -0
  4. package/dist/api/errors.d.ts +15 -0
  5. package/dist/api/errors.js +15 -0
  6. package/dist/api/extract.d.ts +57 -0
  7. package/dist/api/extract.js +36 -1
  8. package/dist/auth/constants.d.ts +47 -0
  9. package/dist/auth/constants.js +89 -0
  10. package/dist/auth/exchange.d.ts +74 -0
  11. package/dist/auth/exchange.js +124 -0
  12. package/dist/auth/login.d.ts +64 -0
  13. package/dist/auth/login.js +163 -0
  14. package/dist/auth/loopback.d.ts +32 -0
  15. package/dist/auth/loopback.js +95 -0
  16. package/dist/auth/oauthClient.d.ts +70 -0
  17. package/dist/auth/oauthClient.js +136 -0
  18. package/dist/auth/pkce.d.ts +6 -0
  19. package/dist/auth/pkce.js +13 -0
  20. package/dist/auth/revoke.d.ts +58 -0
  21. package/dist/auth/revoke.js +91 -0
  22. package/dist/auth/store.d.ts +34 -0
  23. package/dist/auth/store.js +149 -0
  24. package/dist/cli.js +6 -0
  25. package/dist/commands/configureMcp.js +34 -18
  26. package/dist/commands/configureSkills.js +18 -4
  27. package/dist/commands/extract.js +9 -5
  28. package/dist/commands/login.d.ts +49 -0
  29. package/dist/commands/login.js +161 -0
  30. package/dist/commands/logout.d.ts +46 -0
  31. package/dist/commands/logout.js +142 -0
  32. package/dist/commands/reset.js +39 -3
  33. package/dist/commands/utils.d.ts +9 -0
  34. package/dist/commands/utils.js +16 -0
  35. package/dist/commands/whoami.d.ts +27 -0
  36. package/dist/commands/whoami.js +109 -0
  37. package/dist/config/resolve.d.ts +44 -1
  38. package/dist/config/resolve.js +80 -5
  39. package/dist/mcp/install.js +15 -2
  40. package/dist/mcp/write.js +24 -3
  41. package/dist/output/pretty/extract.d.ts +5 -1
  42. package/dist/output/pretty/extract.js +64 -4
  43. package/dist/output/pretty/whoami.d.ts +59 -0
  44. package/dist/output/pretty/whoami.js +103 -0
  45. package/dist/skills/setkey.js +5 -4
  46. package/dist/util/secretFile.d.ts +24 -0
  47. package/dist/util/secretFile.js +35 -0
  48. package/package.json +1 -1
  49. package/skills/manifest.json +5 -1
  50. package/skills/octen-design/SKILL.md +32 -9
  51. package/skills/octen-design/agents/openai.yaml +4 -0
  52. package/skills/octen-design/scripts/search.py +326 -71
  53. package/skills/octen-design/scripts/tests/test_search.py +449 -0
  54. package/skills/octen-extract/SKILL.md +178 -0
  55. package/skills/octen-extract/agents/openai.yaml +4 -0
  56. package/skills/octen-image-search/SKILL.md +125 -0
  57. package/skills/octen-image-search/agents/openai.yaml +4 -0
  58. package/skills/octen-search/SKILL.md +82 -3
  59. package/skills/octen-search/agents/openai.yaml +4 -0
  60. package/skills/octen-video-search/SKILL.md +108 -0
  61. package/skills/octen-video-search/agents/openai.yaml +4 -0
  62. package/skills/octen-web-search/SKILL.md +113 -0
  63. package/skills/octen-web-search/agents/openai.yaml +4 -0
package/README.md CHANGED
@@ -43,16 +43,246 @@ octen completion zsh --install # writes to ~/.zshrc — then: source ~/.zshr
43
43
 
44
44
  ## Auth
45
45
 
46
- Set your API key (get one at https://octen.ai):
46
+ Octen CLI resolves the API key to use in this order — each step stopping resolution before
47
+ the next, so an explicit value always wins over a stored one:
48
+
49
+ 1. `--api-key <key>` on the command itself
50
+ 2. `OCTEN_API_KEY` in the environment
51
+ 3. `~/.octen/credentials.json`, written by `octen login`
52
+
53
+ Get a key at https://octen.ai. Either export it directly:
47
54
 
48
55
  ```sh
49
56
  export OCTEN_API_KEY=your_key_here
50
57
  ```
51
58
 
52
- You can also pass `--api-key <key>` on any command. To point at a self-hosted or staging endpoint, set `OCTEN_API_URL` or pass `--base-url <url>`.
59
+ or log in once and let the CLI manage it:
60
+
61
+ ```sh
62
+ octen login
63
+ ```
64
+
65
+ `octen login` opens your browser, completes an OAuth consent flow, and stores the resulting
66
+ API key at `~/.octen/credentials.json` (written with `0600` permissions). That key does not
67
+ expire, so `octen configure-mcp` and `octen configure-skills --set-key` can write it into
68
+ AI-client configs once and forget about it.
69
+
70
+ You can also pass `--api-key <key>` or `--base-url <url>` on any command; to point at a
71
+ self-hosted or staging endpoint, set `OCTEN_API_URL` or pass `--base-url <url>`.
72
+
73
+ Run `octen whoami` to see which of the three sources is actually in effect — it names the
74
+ winner explicitly, so a stored credential that is being shadowed or ignored says so rather
75
+ than looking live.
76
+
77
+ ### Auth environment variables
78
+
79
+ | Variable | Default | What it does |
80
+ | --- | --- | --- |
81
+ | `OCTEN_API_KEY` | — | The API key to use. Takes precedence over `~/.octen/credentials.json`, so a stored login is ignored while it is set. |
82
+ | `OCTEN_API_URL` | `https://api.octen.ai` | The Octen API base URL. |
83
+ | `OCTEN_AUTH_ISSUER` | `https://auth.octen.ai` | The OAuth authorization server `octen login` talks to. Only for local development against a self-hosted AS. |
84
+ | `OCTEN_AUTH_RESOURCE` | `https://cli.octen.ai` | The audience `octen login` requests the access token for. Despite the shape it is an identifier, not a site — nothing ever connects to it. Only for local development. |
85
+
86
+ `OCTEN_AUTH_ISSUER` and `OCTEN_AUTH_RESOURCE` **must not have a trailing slash** — a
87
+ trailing one is rejected with a named error rather than silently trimmed, because trimming
88
+ is what once turned a JWKS URL into `//api/oauth/jwks` and made a byte-for-byte issuer
89
+ comparison fail.
90
+
91
+ Changing either of them makes an existing stored credential **inapplicable**: the credential
92
+ records the issuer and resource it was minted for, and one minted for a different pair
93
+ belongs to another environment. The CLI never uses it and never deletes it — it says so and
94
+ names the variable. Unset the variable to go back to the stored credential, or run `octen
95
+ login` again to get one for the new environment. `octen whoami` shows both the stored
96
+ `Issuer`/`Resource` and which credential is in effect.
97
+
98
+ ### What the resource is, and why there are two
99
+
100
+ One authorization server issues access tokens for two different audiences, and they are
101
+ deliberately not interchangeable:
102
+
103
+ | Audience | Scope | What a token for it can do |
104
+ | --- | --- | --- |
105
+ | `https://mcp.octen.ai/mcp` | `mcp:tools` | Call MCP tools |
106
+ | `https://cli.octen.ai` | `octen:api_key` | Exchange for your account's API key |
107
+
108
+ Only the second can be traded for the API key. If both shared one audience, a token minted
109
+ for the MCP server — the one an AI client holds — could be replayed against the CLI's
110
+ exchange endpoint and walk away with that key. The `resource` is what keeps them apart: the
111
+ server checks that a token's granted audience is exactly this value before handing anything
112
+ over, and answers `403` otherwise.
113
+
114
+ That check is a byte-for-byte comparison, with no normalization anywhere along the chain,
115
+ which is why the trailing-slash rule above is a rejection rather than a quiet trim.
116
+ Normalizing in one place and not another produces a 401 on every request while each side
117
+ looks correct in isolation.
118
+
119
+ You do not need to set `OCTEN_AUTH_RESOURCE` to use Octen. It exists so a locally running
120
+ authorization server can use a different audience string.
121
+
122
+ **Add `.octen/` to your global gitignore.** A credentials file living in a dotfile directory
123
+ is more likely to be committed by accident than an environment variable ever was:
124
+
125
+ ```sh
126
+ git config --global core.excludesfile ~/.gitignore_global
127
+ echo ".octen/" >> ~/.gitignore_global
128
+ ```
129
+
130
+ **No browser on this machine (CI, containers)?** Paste a key directly — this branch makes
131
+ zero network requests:
132
+
133
+ ```sh
134
+ octen login --api-key "$OCTEN_API_KEY"
135
+ ```
136
+
137
+ **Over SSH**, forward the loopback callback port and pin it on both ends:
138
+
139
+ ```sh
140
+ # on the remote machine
141
+ octen login --port 8765
142
+ # from your local machine, before approving the consent screen in your browser
143
+ ssh -L 8765:localhost:8765 remote-host
144
+ ```
145
+
146
+ ### `octen logout`'s exact semantics
147
+
148
+ `octen logout` deletes `~/.octen/credentials.json` and revokes *this device's authorization*
149
+ (the OAuth grant behind it). Revoking the authorization only prevents it from being used to
150
+ silently mint a new credential later — it does **not** deactivate the underlying API key.
151
+ That key is your own account-wide, long-lived key, and the same key is very likely also
152
+ sitting on other machines, in your production code, and in the AI-client configs `octen
153
+ configure-mcp` wrote. All of those keep working after `octen logout` — that's by design,
154
+ since they're your own legitimate uses of your own key. If you believe the key itself was
155
+ exposed, deactivate or rotate it from the key management page at https://octen.ai — that
156
+ action, unlike `logout`, affects every place holding the key.
157
+
158
+ `octen logout --local` skips the network call entirely and only removes the local file,
159
+ without attempting to revoke the authorization.
160
+
161
+ ### One key, used by both the CLI and MCP
162
+
163
+ The audience split above applies to OAuth *access tokens*. The API key you end up with is
164
+ not audience-bound at all — it is your own account-wide key, and using it in more than one
165
+ place is the normal case, not a workaround. `octen configure-mcp` does exactly that: it
166
+ resolves your key through the same `--api-key` > `OCTEN_API_KEY` > stored-login order as
167
+ every other command and writes it into the MCP client config.
168
+
169
+ Three consequences of sharing one key:
170
+
171
+ - **`octen logout` does not stop MCP.** It revokes this device's authorization, not the key.
172
+ The key is still sitting in the MCP config and keeps working. To stop it everywhere,
173
+ deactivate or rotate the key from the key management page at https://octen.ai.
174
+ - **Usage and billing are pooled.** One key, one account — CLI calls and MCP calls land in
175
+ the same bucket.
176
+ - **The blast radius is shared.** Rotating or losing the key affects both at once.
177
+
178
+ To keep the two independent, pick a separate key for the CLI in the consent screen's **API
179
+ Key** dropdown instead of accepting the default, and leave MCP on another one.
180
+
181
+ This applies to the local stdio MCP server (`npx octen-mcp`, what `octen configure-mcp`
182
+ configures). A **remote OAuth connector** holds no API key at all — it carries an
183
+ MCP-audience token that the server resolves internally — so it is already independent of
184
+ whatever the CLI stores.
185
+
186
+ ### Dashboard "revoke" and an already-logged-in CLI
187
+
188
+ The dashboard's per-authorization "revoke" button has **no effect on a device that already
189
+ holds a credential**: it only stops that device from obtaining a *new* one without going
190
+ through the consent screen again — the API key it already has keeps working exactly as
191
+ before. The authorization still shows up in the dashboard's list either way; run `octen
192
+ whoami` on the device in question to get its `grantId` so you can identify which entry in
193
+ that list corresponds to it. To actually stop a key from working anywhere, deactivate or
194
+ rotate it from the key management page, not the authorization list.
195
+
196
+ ### Switching from a browser login to a pasted key
197
+
198
+ `octen login --api-key <KEY>` overwrites any existing `source: login` credential on disk
199
+ without revoking its grant — that branch makes no network request at all, deliberately, so
200
+ that it still works on a machine with no browser and no reachable auth server (see above).
201
+ So if you switch a machine from a browser login to a pasted key, the old
202
+ authorization is left behind: it stays listed as active in the dashboard's authorization
203
+ list, and once its `grantId` is gone from this machine's disk, nothing here can revoke it —
204
+ only the dashboard can. The command prints that `grantId` on stderr before overwriting the
205
+ file, so you can still find the entry; revoke it there directly if you want to clean it up,
206
+ or run `octen logout` first to revoke it properly.
53
207
 
54
208
  ## Commands
55
209
 
210
+ ### `octen login`
211
+
212
+ Log in via your browser and store the resulting long-lived API key at
213
+ `~/.octen/credentials.json`.
214
+
215
+ ```sh
216
+ octen login
217
+
218
+ # print the authorize URL instead of opening a browser
219
+ octen login --no-browser
220
+
221
+ # pin the loopback callback port, e.g. for the ssh -L forwarding above
222
+ octen login --port 8765
223
+
224
+ # no browser available: store a key directly, with zero network requests
225
+ octen login --api-key "$OCTEN_API_KEY"
226
+ ```
227
+
228
+ The consent screen asks for two things, and shows one you should check:
229
+
230
+ - **Account** — whose key this is: your personal account, or an organization you belong to.
231
+ This decides whose usage and billing the key draws on.
232
+ - **API Key** — which of that account's keys to hand over. Pick a separate one here if you
233
+ want the CLI's key independent of the one MCP uses (see
234
+ [One key, used by both the CLI and MCP](#one-key-used-by-both-the-cli-and-mcp)).
235
+ - **"Authorization result will be sent to 127.0.0.1:PORT"** — the loopback listener this
236
+ `octen login` just opened. If you did not just run it, press **Deny**.
237
+
238
+ On success the terminal names the account you approved as — `Logged in as Octen family.` —
239
+ falling back to the raw account id when the server does not supply a name.
240
+
241
+ If a `source: login` credential already exists, `octen login` best-effort revokes its grant
242
+ before starting the new login, so repeated logins don't accumulate orphaned authorizations
243
+ in the dashboard. A failure to revoke never blocks the new login.
244
+
245
+ Options: `--port <n>`, `--no-browser`.
246
+
247
+ ---
248
+
249
+ ### `octen logout`
250
+
251
+ Revoke this device's authorization and remove the locally stored credential. See
252
+ [Auth](#auth) above for the exact semantics — this does **not** deactivate the API key
253
+ itself.
254
+
255
+ ```sh
256
+ octen logout
257
+
258
+ # skip the network call; only remove the local file
259
+ octen logout --local
260
+ ```
261
+
262
+ A credential created with `octen login --api-key` has no authorization to revoke, so this
263
+ just removes the file, with zero network requests, and the output never mentions revocation
264
+ for that case.
265
+
266
+ Options: `--local`.
267
+
268
+ ---
269
+
270
+ ### `octen whoami`
271
+
272
+ Show the locally stored credential: account, credential source, and the `grantId` you can
273
+ use to find and revoke this device in the dashboard's authorization list. This reads only
274
+ `~/.octen/credentials.json` — it makes **zero network requests** and does not verify that
275
+ the key still works (run `octen search` for that; there's deliberately no `--verify` flag).
276
+
277
+ ```sh
278
+ octen whoami
279
+ octen whoami --json
280
+ ```
281
+
282
+ Exits non-zero when not logged in.
283
+
284
+ ---
285
+
56
286
  ### `octen search`
57
287
 
58
288
  Search the live web.
@@ -95,11 +325,31 @@ Extract content from one or more URLs (1–20).
95
325
 
96
326
  ```sh
97
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
98
330
  ```
99
331
 
100
- 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.
101
333
 
102
- Pretty output truncates page content to ~500 chars for readability; pass `--full` to print the whole thing (or `--json` for the raw response).
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).
103
353
 
104
354
  ---
105
355
 
@@ -307,7 +557,8 @@ Run without flags to show installed skills per client.
307
557
 
308
558
  ### `octen reset`
309
559
 
310
- Remove the Octen MCP server and/or skills from AI clients.
560
+ Remove the Octen MCP server and/or skills from AI clients, or clear the stored login
561
+ credential.
311
562
 
312
563
  ```sh
313
564
  # Remove everything from all clients
@@ -318,9 +569,24 @@ octen reset --mcp
318
569
 
319
570
  # Remove only skills from a specific client
320
571
  octen reset --skills --claude-code
572
+
573
+ # Clear ~/.octen/credentials.json (like octen logout --local, but see the note below)
574
+ octen reset --credentials
321
575
  ```
322
576
 
323
- Options: `--all` (both surfaces, all clients), `--mcp`, `--skills`, plus per-client flags: `--claude-code`, `--cursor`, `--claude-desktop`, `--windsurf`, `--vscode`, `--codex`, `--openclaw`, `--hermes`, `--scope` (user|project).
577
+ Options: `--all` (both surfaces, all clients), `--mcp`, `--skills`, `--credentials`, plus per-client flags: `--claude-code`, `--cursor`, `--claude-desktop`, `--windsurf`, `--vscode`, `--codex`, `--openclaw`, `--hermes`, `--scope` (user|project).
578
+
579
+ `--credentials` is **not** included in `--all` — `--all`'s existing meaning is "both
580
+ surfaces (MCP + skills) across all clients", and folding in the login credential would mean
581
+ `--all` silently logs you out, which would be an unwelcome surprise. Reach for `octen
582
+ logout` instead of `reset --credentials` when there's a remote authorization to revoke too;
583
+ `reset --credentials` only ever touches the local file, with no network request.
584
+
585
+ It behaves like `octen logout --local` — same file, same zero network requests — but it is
586
+ not the same command: `reset --credentials` reports removal in `reset`'s own style, and
587
+ `logout` is the command whose whole job is the authorization. Both print the `grantId` of a
588
+ `source: login` credential before destroying it, so the authorization left listed in the
589
+ dashboard can still be identified and revoked there.
324
590
 
325
591
  ---
326
592
 
@@ -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;
@@ -67,5 +71,7 @@ export declare const TIME_BASIS_OPTIONS: readonly ["auto", "published", "crawled
67
71
  export declare const TIME_RANGE_OPTIONS: readonly ["day", "week", "month", "year", "d", "w", "m", "y"];
68
72
  export declare const SAFESEARCH_OPTIONS: readonly ["off", "strict"];
69
73
  export declare const FORMAT_OPTIONS: readonly ["text", "markdown"];
74
+ export declare const EXTRACT_MODE_OPTIONS: readonly ["standard", "advanced", "auto"];
75
+ export declare const LINK_SCOPE_OPTIONS: readonly ["prefer_internal", "prefer_external"];
70
76
  export declare const SKILLS_REPO = "Octen-Team/octen-skills";
71
77
  export declare const SKILLS_REPO_TARBALL: (ref: string) => string;
@@ -27,6 +27,7 @@ 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 },
@@ -43,5 +44,7 @@ export const TIME_BASIS_OPTIONS = ["auto", "published", "crawled"];
43
44
  export const TIME_RANGE_OPTIONS = ["day", "week", "month", "year", "d", "w", "m", "y"];
44
45
  export const SAFESEARCH_OPTIONS = ["off", "strict"];
45
46
  export const FORMAT_OPTIONS = ["text", "markdown"];
47
+ export const EXTRACT_MODE_OPTIONS = ["standard", "advanced", "auto"];
48
+ export const LINK_SCOPE_OPTIONS = ["prefer_internal", "prefer_external"];
46
49
  export const SKILLS_REPO = "Octen-Team/octen-skills";
47
50
  export const SKILLS_REPO_TARBALL = (ref) => `https://github.com/${SKILLS_REPO}/archive/${ref}.tar.gz`;
@@ -2,6 +2,21 @@ export declare class OctenError extends Error {
2
2
  }
3
3
  export declare class OctenAuthError extends OctenError {
4
4
  }
5
+ /**
6
+ * There is no credential at all — no flag, no env var, no credentials file.
7
+ *
8
+ * A subclass rather than a flag so that every existing `instanceof
9
+ * OctenAuthError` keeps matching, while the two callers that must tell "you
10
+ * have nothing" apart from "you have something that doesn't apply here"
11
+ * (`configure-mcp`, `configure-skills --set-key`) can do it without matching on
12
+ * message text. Both used to treat any OctenAuthError as "no credential", so a
13
+ * working credential plus an OCTEN_AUTH_ISSUER override produced "no API key
14
+ * found", a `${OCTEN_API_KEY}` placeholder config, exit 0 — and, in
15
+ * configure-skills, advice to run `octen login`, which cannot fix an
16
+ * OCTEN_AUTH_* override.
17
+ */
18
+ export declare class OctenNoCredentialError extends OctenAuthError {
19
+ }
5
20
  export declare class OctenValidationError extends OctenError {
6
21
  }
7
22
  export declare class OctenTimeoutError extends OctenError {
@@ -2,6 +2,21 @@ export class OctenError extends Error {
2
2
  }
3
3
  export class OctenAuthError extends OctenError {
4
4
  }
5
+ /**
6
+ * There is no credential at all — no flag, no env var, no credentials file.
7
+ *
8
+ * A subclass rather than a flag so that every existing `instanceof
9
+ * OctenAuthError` keeps matching, while the two callers that must tell "you
10
+ * have nothing" apart from "you have something that doesn't apply here"
11
+ * (`configure-mcp`, `configure-skills --set-key`) can do it without matching on
12
+ * message text. Both used to treat any OctenAuthError as "no credential", so a
13
+ * working credential plus an OCTEN_AUTH_ISSUER override produced "no API key
14
+ * found", a `${OCTEN_API_KEY}` placeholder config, exit 0 — and, in
15
+ * configure-skills, advice to run `octen login`, which cannot fix an
16
+ * OCTEN_AUTH_* override.
17
+ */
18
+ export class OctenNoCredentialError extends OctenAuthError {
19
+ }
5
20
  export class OctenValidationError extends OctenError {
6
21
  }
7
22
  export class OctenTimeoutError extends OctenError {
@@ -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
@@ -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
  }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The pre-registered public client id. This is not a value the CLI chooses:
3
+ * it must byte-match the client row seeded on the authorization server, and a
4
+ * mismatch fails at the authorize step with `invalid_client`, before the user
5
+ * ever sees a consent screen. There is no dynamic client registration, so
6
+ * nothing negotiates this at runtime — it is a cross-repository constant.
7
+ */
8
+ export declare const CLI_CLIENT_ID = "octen-cli";
9
+ export declare const CLI_SCOPE = "octen:api_key";
10
+ export declare const REQUEST_TIMEOUT_MS = 10000;
11
+ export declare const LOOPBACK_TIMEOUT_MS: number;
12
+ /**
13
+ * Every origin that this CLI will send a credential to must be https, with the
14
+ * single exception of a loopback literal (a locally running authorization
15
+ * server, which is what the OCTEN_AUTH_ISSUER doc below invites).
16
+ *
17
+ * This is load-bearing, not hygiene. Two requests carry secrets to whatever
18
+ * this string names: `exchange.ts` sends the access token to `/api/oauth/cli/key`,
19
+ * and `revoke.ts` sends the account-wide, long-lived API key to
20
+ * `/api/oauth/cli/revoke`. Before this check existed, `OCTEN_AUTH_ISSUER=http://…`
21
+ * put both on the wire in cleartext with no warning, and `store.ts` accepted any
22
+ * non-empty string as a *stored* issuer, so a credentials file could name an
23
+ * arbitrary plaintext host and `login`/`logout` would mail the key to it.
24
+ *
25
+ * Exported because store.ts must apply the identical rule to the issuer it reads
26
+ * back off disk — one rule, one implementation, or the two drift.
27
+ */
28
+ export declare function assertSecureOrigin(name: string, value: string): string;
29
+ /**
30
+ * OCTEN_AUTH_ISSUER, default https://auth.octen.ai.
31
+ *
32
+ * Note that the pre-production and production environments share this one
33
+ * auth host — there is no `auth.pre.octen.ai`, and inventing one by analogy
34
+ * with the other per-environment hostnames will produce a DNS failure rather
35
+ * than a pre-prod login. Point this at a locally running authorization server
36
+ * for development instead.
37
+ */
38
+ export declare function authIssuer(env: NodeJS.ProcessEnv): string;
39
+ /**
40
+ * OCTEN_AUTH_RESOURCE, default https://cli.octen.ai.
41
+ *
42
+ * Unlike the issuer this is never dialled — it is an audience identifier that
43
+ * goes into the authorize request and is compared byte-for-byte on the server.
44
+ * So it gets the trailing-slash rule (a mismatch there is a silent auth
45
+ * failure) but not the https rule: nothing is ever sent *to* it.
46
+ */
47
+ export declare function authResource(env: NodeJS.ProcessEnv): string;