opencode-querit 1.0.2 → 3.0.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 CHANGED
@@ -2,55 +2,73 @@
2
2
 
3
3
  [![license](https://img.shields.io/badge/license-MIT-yellow.svg)](./LICENSE)
4
4
 
5
- Querit-backed `web_search` and `web_fetch` custom tools for [OpenCode](https://opencode.ai). It is the OpenCode counterpart of [`pi-querit`](https://www.npmjs.com/package/pi-querit) and [`dsh-querit`](https://www.npmjs.com/package/dsh-querit): the plugin registers two model-facing tools that route through [Querit](https://www.querit.ai) — live web search and clean page content through `POST https://api.querit.ai/v1/search` and `/v1/contents`.
5
+ [Querit](https://www.querit.ai) web search for [OpenCode](https://opencode.ai) v2 (requires OpenCode **2.0.28 or later** on the 2.x line; verified against 2.4.2). The plugin registers **Querit as a websearch provider** — powering OpenCode's built-in `websearch` tool — plus a `web_fetch` custom tool for page content via `POST https://api.querit.ai/v1/contents`. It is the OpenCode counterpart of [`pi-querit`](https://www.npmjs.com/package/pi-querit) and [`dsh-querit`](https://www.npmjs.com/package/dsh-querit).
6
+
7
+ OpenCode v2 ships a built-in `websearch` tool with several providers (Exa, Firecrawl, Parallel, Tavily, TinyFish), each of which needs its own API key or a connected account. This plugin adds Querit to the provider list — use it with your own Querit API key.
6
8
 
7
9
  Sign up on [Querit.ai](https://www.querit.ai) to get an API key with **1,000 free API calls per month** — no credit card required.
8
10
 
11
+ > Requires OpenCode v2 `2.0.28+`. On OpenCode v1 pin [`opencode-querit@1.0.2`](https://www.npmjs.com/package/opencode-querit/v/1.0.2); on a v2 host older than 2.0.28 pin [`opencode-querit@2.0.0`](https://www.npmjs.com/package/opencode-querit/v/2.0.0).
12
+
13
+ ## Upgrading from 2.x
14
+
15
+ Version 3.0.0 makes two incompatible changes:
16
+
17
+ - **Host floor raised.** The plugin requires OpenCode 2.0.28+. From that release a rejected `web_fetch` call is reported as a normal tool failure instead of crashing the call, and from 2.3.0 stopping the call aborts the in-flight request.
18
+ - **`count` is no longer defaulted to 5.** When `count` is not set it is left out of the request and Querit's server default decides how many results come back. Set `count` if you relied on five results. The accepted range is now 1–100 (was 1–20).
19
+
20
+ The deprecated `chunksPerDoc: 1` is also no longer sent on every request: set `chunksPerDoc` to send it, or switch to `highlights`.
21
+
9
22
  ## Quick start
10
23
 
11
- 1. Install the plugin from npm and add it to `opencode.json`:
24
+ 1. Add the plugin to `opencode.json`:
12
25
 
13
26
  ```json
14
27
  {
15
28
  "$schema": "https://opencode.ai/config.json",
16
- "plugin": ["opencode-querit"]
29
+ "plugins": ["opencode-querit"]
17
30
  }
18
31
  ```
19
32
 
20
33
  2. Configure your Querit API key in priority order:
21
34
  - the `QUERIT_API_KEY` environment variable (default; override the name with `apiKeyEnv`) — the environment always wins, so one exported key overrides plugin options everywhere, or
22
- - `apiKey` in the plugin options tuple (`["opencode-querit", { "apiKey": "..." }]`; least preferred — secrets should not live in config files).
23
- 3. Restart OpenCode. A tool call without a key fails with a message that spells out both options.
35
+ - `apiKey` in the plugin options (`{ "package": "opencode-querit", "options": { "apiKey": "..." } }`; least preferred — secrets should not live in config files).
36
+ 3. Restart OpenCode and ask it to search the web. On the first `websearch` call OpenCode shows its provider form — pick **Querit** (the choice is remembered), or pin it once in config:
24
37
 
25
- The two tools are `web_search` (live web search with cited results) and `web_fetch` (full page content for up to 10 URLs). They are additive: OpenCode's built-in `websearch`/`webfetch` tools stay available. To steer the model to Querit, mention the tools or restrict the built-ins through [permissions](https://opencode.ai/docs/permissions/).
38
+ ```json
39
+ { "websearch": { "provider": "querit" } }
40
+ ```
41
+
42
+ The `web_fetch` tool appears alongside the built-ins immediately.
26
43
 
27
44
  ### Test locally before publishing
28
45
 
29
- Until the package is published (or to iterate on it), load the compiled plugin straight from this repository in any OpenCode project:
46
+ Load the compiled plugin straight from this repository in any OpenCode project:
30
47
 
31
48
  ```json
32
49
  {
33
50
  "$schema": "https://opencode.ai/config.json",
34
- "plugin": ["file:///D:/work/queirt/querit-plugins/opencode-querit/lib/index.js"]
51
+ "plugins": [{ "package": "file:///D:/work/querit/querit-plugins/opencode-querit" }]
35
52
  }
36
53
  ```
37
54
 
38
- Point the `file://` URL at your checkout and restart OpenCode; the tools appear alongside the built-ins. Verify quickly with a `web_search` call — without a configured key it fails with the actionable "Querit is not configured" message, which confirms the plugin loaded and the tools are wired.
55
+ Point the path at your checkout and restart OpenCode. Without a configured key a `websearch`/`web_fetch` call fails with the actionable "Querit is not configured" message, which confirms the plugin loaded.
39
56
 
40
57
  ## Options
41
58
 
42
- Options go in the plugin tuple in `opencode.json`:
59
+ Options go under the plugin entry in `opencode.json`:
43
60
 
44
61
  ```json
45
62
  {
46
63
  "$schema": "https://opencode.ai/config.json",
47
- "plugin": [
48
- ["opencode-querit", {
64
+ "plugins": [
65
+ { "package": "opencode-querit", "options": {
49
66
  "count": 8,
67
+ "highlights": true,
50
68
  "timeRange": "m3",
51
69
  "languages": ["english"],
52
70
  "excludeDomains": ["pinterest.com", "facebook.com", "instagram.com", "tiktok.com"]
53
- }]
71
+ } }
54
72
  ]
55
73
  }
56
74
  ```
@@ -58,68 +76,85 @@ Options go in the plugin tuple in `opencode.json`:
58
76
  | Key | Default | Meaning |
59
77
  |---|---|---|
60
78
  | `apiKey` | omitted | Literal Querit API key. Prefer `apiKeyEnv` so no secret enters configuration. The `apiKeyEnv` environment variable always wins when both are set. |
61
- | `apiKeyEnv` | `QUERIT_API_KEY` | Environment variable holding the Querit API key. A missing value fails the tool call with an actionable message. |
62
- | `baseURL` | `https://api.querit.ai` | Querit API base; `/v1/search` and `/v1/contents` are appended. Falls back to `$QUERIT_BASE_URL`. |
63
- | `timeoutMs` | `70000` | Per-request timeout in ms (minimum 1000). |
64
- | `count` | `5` | Default result count per search (1–20; the API caps at 20). Per-call `count` overrides it. |
65
- | `timeRange` | none | Relative (`d7`, `w2`, `m3`, `y1`, or any `dN`/`wN`/`mN`/`yN`) or `YYYY-MM-DDtoYYYY-MM-DD` date range. |
66
- | `countries` | none | Country bias. Valid values: `argentina`, `australia`, `brazil`, `canada`, `colombia`, `france`, `germany`, `india`, `indonesia`, `japan`, `mexico`, `nigeria`, `philippines`, `south korea`, `spain`, `united kingdom`, `united states`. |
67
- | `languages` | none | Language filter. Valid values: `english`, `japanese`, `korean`, `german`, `french`, `spanish`, `portuguese`. |
79
+ | `apiKeyEnv` | `QUERIT_API_KEY` | Environment variable holding the Querit API key. A missing value fails the call with an actionable message. |
80
+ | `setDefault` | `false` | Make Querit the default websearch provider at startup. Off by default so the plugin never overrides the provider you picked in OpenCode's first-use form or via config `websearch.provider`. |
81
+ | `baseURL` | `https://api.querit.ai` | Querit API base, which must be an HTTP(S) URL; `/v1/search` and `/v1/contents` are appended. Falls back to `$QUERIT_BASE_URL`. |
82
+ | `timeoutMs` | `70000` | Deadline for one request in ms (minimum 1000), retries and backoff waits included. |
83
+ | `count` | unset | Result count per search (1–100). Unset: not sent, so Querit's server default applies. Querit caps it by plan (Free 10, PAYG 20, Enterprise 100). |
84
+ | `timeRange` | none | Relative (`d7`, `w2`, `m3`, `y1`, or any `dN`/`wN`/`mN`/`yN`) or `YYYY-MM-DDtoYYYY-MM-DD` date range. Set it for "latest"/"now"-style queries; a range has no spaces and the letter comes first. |
85
+ | `countries` | none | Country filter. Valid values: `argentina`, `australia`, `brazil`, `canada`, `colombia`, `france`, `germany`, `india`, `indonesia`, `japan`, `mexico`, `nigeria`, `philippines`, `south korea`, `spain`, `united kingdom`, `united states`. |
86
+ | `languages` | none | Language filter. Valid values: `english`, `japanese`, `korean`, `german`, `french`, `spanish`, `portuguese`, `russian`. |
68
87
  | `includeDomains` | none | **Whitelist** hostnames; only these domains return results. |
69
88
  | `excludeDomains` | none | **Blacklist** hostnames; these domains never return results. |
70
- | `includeContent` | `false` | Request sentence-level content excerpts (`needContent`); excerpts are appended to each source's snippet. |
71
- | `chunksPerDoc` | `1` | Content chunks per result (1–3). |
89
+ | `vertical` | unset | `code` or `finance`: vertical search over that domain's data source. Unset: universal search. Use it only for queries that belong to the domain — a mismatched vertical loses results. |
90
+ | `resourceTags` | none | Sub-tags of the `code` vertical to keep: `qa`, `github`. Requires `vertical: "code"`; any other setting fails plugin load. |
91
+ | `rank` | unset | `relevance` or `freshness`: a boost on top of Querit's default ranking, not a sort. Never sent together with `vertical: "code"`, which rejects it. |
92
+ | `highlights` | `false` | Ask Querit for query-focused fragments of each result's body (`highlights: true`); they are appended to the result content. The recommended replacement for `chunksPerDoc`. |
93
+ | `includeContent` | `false` | Request sentence-level body text (`needContent`); it is appended to each result's content. |
94
+ | `contentMaxChars` | unset | Cap on each search result's body text, in Unicode code points (1–1000000), applied by Querit. Sent only together with `includeContent`, the only case Querit reads it. |
95
+ | `needMarkdown` | `false` | Request Markdown versions of each result's snippet and body (`needMarkdown`). Enterprise plans only; silently ignored on other plans. When Querit returns them, the Markdown is used instead of the plain text. |
96
+ | `chunksPerDoc` | unset | Summary chunks per result (1–3; Free and PAYG plans accept 1). Deprecated by Querit in favor of `highlights`; sent only when set. |
72
97
  | `fetchFormat` | `markdown` | Default format requested from `/v1/contents` for fetch calls: `markdown`, `text`, or `html`. Per-call `format` overrides it. |
73
98
  | `fetchCrawlTimeout` | `10` | Per-page crawl timeout in seconds (1–60). Per-call `crawl_timeout` overrides it. |
74
- | `fetchMaxChars` | `8000` | Cap applied to one fetched page's decoded body, in chars; a cut page is flagged `truncated` in the tool metadata. |
75
- | `maxOutputChars` | `200000` | Cap on one tool's rendered output, in chars. |
99
+ | `fetchMaxChars` | `8000` | Cap applied locally to one fetched page's body, in chars; a cut page is flagged `truncated` in the tool metadata. |
100
+ | `maxOutputChars` | `200000` | Cap on one tool's rendered output / all search results' combined content, in chars. |
76
101
 
77
- ## Tools
102
+ Invalid options fail plugin load with a message naming the option and its allowed values.
78
103
 
79
- ### web_search
104
+ ## What gets registered
80
105
 
81
- ```
82
- query: The web search query.
83
- count: Maximum results to return (default: 5).
84
- ```
106
+ ### websearch provider (`querit`)
85
107
 
86
- Search filters (domains, time range, region, language, content detail) are persistent defaults from the plugin options; per-call parameters are limited to `query` and `count`. Returns raw cited results. The tool description instructs the model to treat everything returned as untrusted web data and to cite the returned URLs.
108
+ Powers OpenCode's built-in `websearch` tool. Each query is resolved with the current config and API key; the request is built from the plugin options, and anything you did not set is left out so Querit's server defaults apply. Results map to OpenCode's provider shape — `url`, `title`, `content` (the snippet, then highlights when `highlights` is on, then the body text when `includeContent` or `needMarkdown` is on), `published` when `page_age` is an unambiguous calendar date, which is read as UTC as Querit reports it. Every remote string is sanitized and capped (at most 4096 bytes per result, `maxOutputChars` across all results) before the model sees it. OpenCode renders the citations itself, so a successful search has no place to show `search_id` or cost; both appear on failures (below).
87
109
 
88
- ### web_fetch
110
+ ### web_fetch tool
89
111
 
90
112
  ```
91
- url: A single HTTP(S) URL to fetch.
92
- urls: HTTP(S) URLs to fetch. At most 10 URLs per call.
93
- format: Returned content format (default: markdown).
94
- crawl_timeout: Per-page crawl timeout in seconds (default: 10).
95
- include_metadata: Include page metadata such as title and publication time (default: true).
113
+ url: A single HTTP(S) URL to fetch.
114
+ urls: HTTP(S) URLs to fetch. At most 10 URLs per call.
115
+ format: Returned content format (default: the fetchFormat option).
116
+ crawl_timeout: Per-page crawl timeout in seconds, 1–60 (default: 10).
117
+ include_metadata: Include page metadata such as title and publication time (default: true).
118
+ max_chars: Maximum characters of content per page, 1–1000000, cut short by Querit.
119
+ Omit for the full page.
120
+ highlight_query: Also return the passages of each page that answer this query.
121
+ highlight_max_chars: Maximum highlight characters per page, 100–8000.
96
122
  ```
97
123
 
98
- Fetches full page content for up to 10 HTTP(S) URLs. URLs with embedded credentials are rejected, and every fetched page is capped at `fetchMaxChars` chars.
124
+ Fetches page content for up to 10 HTTP(S) URLs through Querit's crawler. URLs with embedded credentials are rejected, and every fetched page is capped at `fetchMaxChars` chars. With `highlight_query` the matching passages of each page are listed above its content. The tool forwards OpenCode's abort signal, so an interrupted or stopped call cancels the request and any pending retry wait. Not every requested URL comes back: URLs without returned content are listed in the output.
125
+
126
+ OpenCode checks permission for this tool under its own name, `web_fetch`; the permission rule of the built-in `webfetch` tool does not cover it.
99
127
 
100
- ## Mapping
128
+ ### Failures, retries, search_id and cost
101
129
 
102
- Search results become citeable sources: `url` ← `url`, `title` ← `title`, `snippet` ← `snippet` plus requested sentence excerpts, `publishedAt` ← `page_age`. Results are deduplicated by URL and normalized to HTTP(S). Fetch maps each crawled page to its content (`text`/`markdown`/`html` per `format`); pages without returned content are listed at the end of the output instead of failing the whole call.
130
+ Querit reports failures through `error_code`, and the plugin treats that code as the verdict even when the HTTP status is 200.
103
131
 
104
- Failures surface as tool errors with the API key redacted; responses are size-limited (2 MiB search, 10 MiB contents) and retrieved text is stripped of terminal escape/control sequences and bidi controls before the model sees it.
132
+ - **Retried:** 429, 500 and 503, at most twice (three requests in all), with exponential backoff and jitter (500 ms base, 5 s ceiling). A `Retry-After` header — delay-seconds or an HTTP-date — is honored when it fits under the 5 s ceiling; a longer one is not waited out, the call fails instead. On `/v1/contents`, a 503 usually means the server-side processing budget was exceeded: send fewer URLs or a lower `crawl_timeout`.
133
+ - **Never retried:** every other status, including 400, 401, 403 and 404. On `/v1/contents`, a 403 means there is no active Contents subscription or the prepaid quota is exhausted.
134
+ - **Deadline:** everything, retries and waits included, must finish within `timeoutMs`.
135
+ - **`search_id`:** every API failure message carries `[search_id: N]` when Querit sent one, so support can trace the request. For `web_fetch` it is also the `searchId` field of the tool metadata and the `Search ID: N` line of the output.
136
+ - **Cost:** for `web_fetch`, a reported charge is the `cost` field of the tool metadata (`{ currency, total }`) and the `Cost: USD 0.000000` line of the output, kept at six decimals so small charges stay visible. Both appear only when Querit reported a cost: an absent cost is unavailable and is never shown as zero, while a reported `0` is a real zero charge.
105
137
 
106
138
  ## Safety
107
139
 
108
- Treat every search result and retrieved page as untrusted external data. The tools tell the model this on every call (the rendered output always opens with an untrusted-data warning), and the plugin never follows instructions found in retrieved content.
140
+ Treat every search result and retrieved page as untrusted external data. Fetched pages are wrapped in explicit untrusted-content markers, terminal escape sequences and bidi controls are stripped from retrieved text, and the plugin never follows instructions found in retrieved content. Failures surface with the API key redacted; responses are size-limited (2 MiB search, 10 MiB contents).
109
141
 
110
142
  ## Development
111
143
 
144
+ Requires Node 22.19.0 or later.
145
+
112
146
  ```bash
113
147
  npm install
114
- npm run check # typecheck src + tests
115
- npm test # vitest unit tests
116
- npm run build # tsc -> lib/
148
+ npm run check # typecheck src + tests
149
+ npm test # vitest unit tests
150
+ npm run build # tsc -> lib/
151
+ npm run pack:check # npm pack --dry-run
117
152
  npm run test:live # live smoke test against the real API (needs QUERIT_API_KEY)
118
153
  ```
119
154
 
120
155
  ## Packaging notes
121
156
 
122
- `lib/` is committed: OpenCode loads npm plugins directly from the compiled package, and committing it lets users install from GitHub Release tarballs without a build toolchain. `@opencode-ai/plugin` is an (optional) peer dependency — OpenCode resolves it at plugin load time; install it as a dev dependency for local builds.
157
+ `lib/` is committed: OpenCode loads npm plugins directly from the compiled package, and committing it lets users install from GitHub Release tarballs without a build toolchain. `@opencode/plugin` is an optional peer dependency (`>=2.0.28 <3`) used for types only — the compiled plugin is plain structural JavaScript that OpenCode v2 loads via `export default { id, setup }`, and the host supplies `@opencode/plugin` at runtime. `zod` (4.2.0 or later) is the only runtime dependency: from 4.2.0 its schemas expose the JSON Schema hook OpenCode calls to describe a plugin tool's input to the model.
123
158
 
124
159
  ## License
125
160
 
package/lib/client.d.ts CHANGED
@@ -1,10 +1,50 @@
1
1
  export declare const QUERIT_API_BASE_URL = "https://api.querit.ai";
2
2
  export declare const DEFAULT_REQUEST_TIMEOUT_MS = 70000;
3
+ /** Largest `count` the API accepts. */
4
+ export declare const QUERIT_COUNT_LIMIT = 100;
5
+ /** Inclusive bounds of `highlights.maxCharacters`. */
6
+ export declare const QUERIT_HIGHLIGHT_MIN_CHARACTERS = 100;
7
+ export declare const QUERIT_HIGHLIGHT_MAX_CHARACTERS = 8000;
8
+ /** Largest `contentMaxChars` the API accepts. */
9
+ export declare const QUERIT_CONTENT_MAX_CHARS_LIMIT = 1000000;
10
+ /** Most URLs one /v1/contents request accepts. */
11
+ export declare const QUERIT_URLS_LIMIT = 10;
12
+ /** Inclusive bounds of `crawlTimeout`, in seconds. */
13
+ export declare const QUERIT_CRAWL_TIMEOUT_MIN_SECONDS = 1;
14
+ export declare const QUERIT_CRAWL_TIMEOUT_MAX_SECONDS = 60;
15
+ export declare const FETCH_FORMAT_VALUES: readonly ["text", "markdown", "html"];
16
+ export type QueritFetchFormat = (typeof FETCH_FORMAT_VALUES)[number];
17
+ export declare const VERTICAL_VALUES: readonly ["code", "finance"];
18
+ export type QueritVertical = (typeof VERTICAL_VALUES)[number];
19
+ export declare const RANK_VALUES: readonly ["relevance", "freshness"];
20
+ export type QueritRankPreference = (typeof RANK_VALUES)[number];
21
+ export declare const RESOURCE_TAG_VALUES: readonly ["qa", "github"];
22
+ export type QueritResourceTag = (typeof RESOURCE_TAG_VALUES)[number];
23
+ export declare const COUNTRY_VALUES: readonly ["argentina", "australia", "brazil", "canada", "colombia", "france", "germany", "india", "indonesia", "japan", "mexico", "nigeria", "philippines", "south korea", "spain", "united kingdom", "united states"];
24
+ export type QueritCountry = (typeof COUNTRY_VALUES)[number];
25
+ export declare const LANGUAGE_VALUES: readonly ["english", "japanese", "korean", "german", "french", "spanish", "portuguese", "russian"];
26
+ export type QueritLanguage = (typeof LANGUAGE_VALUES)[number];
27
+ export interface QueritHighlights {
28
+ /** Guides the extraction; for search, Querit falls back to the top-level query when omitted. */
29
+ query?: string;
30
+ maxCharacters?: number;
31
+ }
3
32
  export interface QueritSearchRequest {
4
33
  query: string;
5
- count: number;
34
+ /** Omit to let Querit apply its server default. */
35
+ count?: number;
36
+ /** Deprecated by Querit in favor of `highlights`. Send only when a user explicitly configured it. */
6
37
  chunksPerDoc?: number;
38
+ highlights?: boolean | QueritHighlights;
7
39
  needContent?: boolean;
40
+ /** Body-text limit per result; only meaningful together with `needContent: true`. */
41
+ contentMaxChars?: number;
42
+ /** Enterprise only; ignored by Querit on other plans. */
43
+ needMarkdown?: boolean;
44
+ /** Returns 400 when combined with `filters.vertical: "code"`. */
45
+ rank?: {
46
+ preference: QueritRankPreference;
47
+ };
8
48
  filters?: {
9
49
  sites?: {
10
50
  include?: string[];
@@ -21,64 +61,108 @@ export interface QueritSearchRequest {
21
61
  languages?: {
22
62
  include: string[];
23
63
  };
64
+ vertical?: QueritVertical;
65
+ /** Sub-tags of a vertical. Only `qa` and `github`, on the code vertical, are documented. */
66
+ resourceTags?: {
67
+ include: QueritResourceTag[];
68
+ };
24
69
  };
25
70
  }
26
71
  export interface QueritContentsRequest {
27
72
  urls: string[];
28
- format: "text" | "markdown" | "html";
73
+ format: QueritFetchFormat;
29
74
  crawlTimeout: number;
30
75
  extrasMeta: boolean;
76
+ /** Content limit per URL. Omit for the full available content. */
77
+ contentMaxChars?: number;
78
+ highlights?: QueritHighlights;
79
+ }
80
+ export interface QueritCost {
81
+ /** Querit always reports "USD". */
82
+ currency: string;
83
+ /** Charge in dollars with up to six decimal places; 0 is a reported zero charge. */
84
+ total: number;
31
85
  }
32
- export interface QueritSearchResult {
86
+ interface QueritSearchResult {
33
87
  title: string;
34
88
  url: string;
35
89
  snippet: string;
36
90
  pageAge?: string;
37
91
  siteName?: string;
38
92
  siteIcon?: string;
93
+ /** Body text, present only when `needContent: true` was requested and is available. */
39
94
  sentences: string[];
95
+ /** Query-focused fragments, present only when `highlights` was requested and is available. */
96
+ highlights: string[];
97
+ /** Markdown versions. Omitted unless `needMarkdown: true` was requested on an Enterprise plan. */
98
+ snippetMarkdown?: string[];
99
+ contentMarkdown?: string;
40
100
  }
41
101
  export interface QueritSearchResponse {
42
102
  searchId?: string;
43
103
  took?: string;
104
+ /** Absent means unavailable, never "free". */
105
+ cost?: QueritCost;
44
106
  query: string;
45
107
  results: QueritSearchResult[];
46
108
  }
47
- export interface QueritContentMetadata {
109
+ interface QueritContentMetadata {
48
110
  title?: string;
49
111
  url?: string;
50
112
  publishTime?: string;
51
113
  siteName?: string;
52
114
  siteIcon?: string;
53
115
  }
54
- export interface QueritContentResult {
116
+ interface QueritContentResult {
55
117
  id?: string;
56
118
  url: string;
57
119
  content: string;
120
+ /** Query-focused fragments, present only when `highlights` was requested and is available. */
121
+ highlights: string[];
58
122
  metadata?: QueritContentMetadata;
59
123
  }
60
- export interface QueritContentStatus {
124
+ interface QueritContentStatus {
61
125
  id?: string;
62
126
  status?: string;
63
127
  }
64
128
  export interface QueritContentsResponse {
65
129
  searchId?: string;
130
+ /** Absent means unavailable, never "free". */
131
+ cost?: QueritCost;
132
+ searchTime?: number;
66
133
  results: QueritContentResult[];
67
134
  statuses: QueritContentStatus[];
68
- searchTime?: number;
135
+ }
136
+ export interface QueritRetryOptions {
137
+ /** Retries after the first attempt. `0` disables retries. */
138
+ maxRetries: number;
139
+ baseDelayMs: number;
140
+ /**
141
+ * Ceiling for backoff waits and for an honored `Retry-After`. A `Retry-After` that
142
+ * exceeds it is not waited out: the tool call fails instead of blocking the agent.
143
+ */
144
+ maxDelayMs: number;
69
145
  }
70
146
  export interface QueritClientOptions {
71
147
  apiKey: string;
72
148
  fetchImpl?: typeof fetch;
73
149
  baseUrl?: string;
150
+ /** Deadline for the whole operation, retries and backoff waits included. */
74
151
  timeoutMs?: number;
152
+ retry?: Partial<QueritRetryOptions>;
75
153
  }
76
154
  export declare class QueritApiError extends Error {
77
155
  readonly status?: number;
78
156
  readonly searchId?: string;
157
+ /** Wait the server asked for through `Retry-After`, when it sent one. */
158
+ readonly retryAfterMs?: number;
159
+ /** Requests sent before giving up, including the first. */
160
+ readonly attempts: number;
79
161
  constructor(message: string, options?: {
80
162
  status?: number;
81
163
  searchId?: string;
164
+ retryAfterMs?: number;
165
+ attempts?: number;
82
166
  cause?: unknown;
83
167
  });
84
168
  }
@@ -87,8 +171,19 @@ export declare class QueritClient {
87
171
  private readonly fetchImpl;
88
172
  private readonly baseUrl;
89
173
  private readonly timeoutMs;
174
+ private readonly retry;
90
175
  constructor(options: QueritClientOptions);
91
176
  search(request: QueritSearchRequest, signal?: AbortSignal): Promise<QueritSearchResponse>;
92
177
  contents(request: QueritContentsRequest, signal?: AbortSignal): Promise<QueritContentsResponse>;
178
+ /**
179
+ * Posts the request, retrying the statuses Querit calls transient with bounded
180
+ * exponential backoff and jitter. One deadline covers every attempt and wait.
181
+ */
93
182
  private postJson;
183
+ private attempt;
94
184
  }
185
+ /** Parses `Retry-After` in both forms the HTTP spec allows: delay-seconds or an HTTP-date. */
186
+ export declare function parseRetryAfter(value: string | null, now?: number): number | undefined;
187
+ /** Renders a cost at the API's six-decimal precision so small charges stay visible. */
188
+ export declare function formatCost(cost: QueritCost): string;
189
+ export {};