opencode-querit 2.0.0 → 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 +61 -24
- package/lib/client.d.ts +102 -7
- package/lib/client.js +234 -51
- package/lib/config.d.ts +37 -37
- package/lib/config.js +61 -62
- package/lib/format.d.ts +3 -5
- package/lib/format.js +25 -32
- package/lib/index.d.ts +15 -7
- package/lib/index.js +104 -34
- package/lib/sanitize.d.ts +2 -0
- package/lib/sanitize.js +4 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,13 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
[](./LICENSE)
|
|
4
4
|
|
|
5
|
-
[Querit](https://www.querit.ai) web search for [OpenCode](https://opencode.ai) v2 (requires
|
|
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
6
|
|
|
7
|
-
OpenCode v2 ships a built-in `websearch` tool
|
|
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.
|
|
8
8
|
|
|
9
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.
|
|
10
10
|
|
|
11
|
-
> Requires
|
|
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`.
|
|
12
21
|
|
|
13
22
|
## Quick start
|
|
14
23
|
|
|
@@ -39,7 +48,7 @@ Load the compiled plugin straight from this repository in any OpenCode project:
|
|
|
39
48
|
```json
|
|
40
49
|
{
|
|
41
50
|
"$schema": "https://opencode.ai/config.json",
|
|
42
|
-
"plugins": [{ "package": "file:///D:/work/
|
|
51
|
+
"plugins": [{ "package": "file:///D:/work/querit/querit-plugins/opencode-querit" }]
|
|
43
52
|
}
|
|
44
53
|
```
|
|
45
54
|
|
|
@@ -55,6 +64,7 @@ Options go under the plugin entry in `opencode.json`:
|
|
|
55
64
|
"plugins": [
|
|
56
65
|
{ "package": "opencode-querit", "options": {
|
|
57
66
|
"count": 8,
|
|
67
|
+
"highlights": true,
|
|
58
68
|
"timeRange": "m3",
|
|
59
69
|
"languages": ["english"],
|
|
60
70
|
"excludeDomains": ["pinterest.com", "facebook.com", "instagram.com", "tiktok.com"]
|
|
@@ -68,38 +78,62 @@ Options go under the plugin entry in `opencode.json`:
|
|
|
68
78
|
| `apiKey` | omitted | Literal Querit API key. Prefer `apiKeyEnv` so no secret enters configuration. The `apiKeyEnv` environment variable always wins when both are set. |
|
|
69
79
|
| `apiKeyEnv` | `QUERIT_API_KEY` | Environment variable holding the Querit API key. A missing value fails the call with an actionable message. |
|
|
70
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`. |
|
|
71
|
-
| `baseURL` | `https://api.querit.ai` | Querit API base; `/v1/search` and `/v1/contents` are appended. Falls back to `$QUERIT_BASE_URL`. |
|
|
72
|
-
| `timeoutMs` | `70000` |
|
|
73
|
-
| `count` |
|
|
74
|
-
| `timeRange` | none | Relative (`d7`, `w2`, `m3`, `y1`, or any `dN`/`wN`/`mN`/`yN`) or `YYYY-MM-DDtoYYYY-MM-DD` date range. |
|
|
75
|
-
| `countries` | none | Country
|
|
76
|
-
| `languages` | none | Language filter. Valid values: `english`, `japanese`, `korean`, `german`, `french`, `spanish`, `portuguese`. |
|
|
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`. |
|
|
77
87
|
| `includeDomains` | none | **Whitelist** hostnames; only these domains return results. |
|
|
78
88
|
| `excludeDomains` | none | **Blacklist** hostnames; these domains never return results. |
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
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. |
|
|
81
97
|
| `fetchFormat` | `markdown` | Default format requested from `/v1/contents` for fetch calls: `markdown`, `text`, or `html`. Per-call `format` overrides it. |
|
|
82
98
|
| `fetchCrawlTimeout` | `10` | Per-page crawl timeout in seconds (1–60). Per-call `crawl_timeout` overrides it. |
|
|
83
|
-
| `fetchMaxChars` | `8000` | Cap applied to one fetched page's
|
|
99
|
+
| `fetchMaxChars` | `8000` | Cap applied locally to one fetched page's body, in chars; a cut page is flagged `truncated` in the tool metadata. |
|
|
84
100
|
| `maxOutputChars` | `200000` | Cap on one tool's rendered output / all search results' combined content, in chars. |
|
|
85
101
|
|
|
102
|
+
Invalid options fail plugin load with a message naming the option and its allowed values.
|
|
103
|
+
|
|
86
104
|
## What gets registered
|
|
87
105
|
|
|
88
106
|
### websearch provider (`querit`)
|
|
89
107
|
|
|
90
|
-
Powers OpenCode's built-in `websearch` tool. Each query is resolved with the current config and API key;
|
|
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).
|
|
91
109
|
|
|
92
110
|
### web_fetch tool
|
|
93
111
|
|
|
94
112
|
```
|
|
95
|
-
url:
|
|
96
|
-
urls:
|
|
97
|
-
format:
|
|
98
|
-
crawl_timeout:
|
|
99
|
-
include_metadata:
|
|
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.
|
|
100
122
|
```
|
|
101
123
|
|
|
102
|
-
Fetches
|
|
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.
|
|
127
|
+
|
|
128
|
+
### Failures, retries, search_id and cost
|
|
129
|
+
|
|
130
|
+
Querit reports failures through `error_code`, and the plugin treats that code as the verdict even when the HTTP status is 200.
|
|
131
|
+
|
|
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.
|
|
103
137
|
|
|
104
138
|
## Safety
|
|
105
139
|
|
|
@@ -107,17 +141,20 @@ Treat every search result and retrieved page as untrusted external data. Fetched
|
|
|
107
141
|
|
|
108
142
|
## Development
|
|
109
143
|
|
|
144
|
+
Requires Node 22.19.0 or later.
|
|
145
|
+
|
|
110
146
|
```bash
|
|
111
147
|
npm install
|
|
112
|
-
npm run check
|
|
113
|
-
npm test
|
|
114
|
-
npm run build
|
|
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
|
|
115
152
|
npm run test:live # live smoke test against the real API (needs QUERIT_API_KEY)
|
|
116
153
|
```
|
|
117
154
|
|
|
118
155
|
## Packaging notes
|
|
119
156
|
|
|
120
|
-
`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 used for types only — the compiled plugin is plain structural JavaScript that OpenCode v2 loads via `export default { id, setup }
|
|
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.
|
|
121
158
|
|
|
122
159
|
## License
|
|
123
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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {};
|