dsh-querit 1.1.1 → 2.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 +62 -46
- package/cordis.patch.yml +6 -0
- package/lib/card.js +264 -240
- package/lib/client.d.ts +105 -6
- package/lib/client.js +198 -41
- package/lib/index.d.ts +70 -59
- package/lib/index.js +150 -123
- package/lib/provider.d.ts +51 -17
- package/lib/provider.js +160 -90
- package/lib/sanitize.d.ts +2 -0
- package/lib/sanitize.js +4 -0
- package/package.json +29 -30
- package/lib/invariant.d.ts +0 -18
- package/lib/invariant.js +0 -20
package/lib/provider.d.ts
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Querit-backed `WebSearchProvider` and `WebFetchProvider` for the harness web
|
|
3
|
-
* capability seam (`ctx.web`). Each
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* capability seam (`ctx.web`). Each operation snapshots the options resolved
|
|
4
|
+
* for it, honors the caller's `AbortSignal`, maps failures to the seam's
|
|
5
|
+
* `WebError` taxonomy, and never emits provider-generated answer text as
|
|
6
|
+
* trusted `content` — only citeable sources.
|
|
7
7
|
* @module dsh-querit/provider
|
|
8
8
|
*/
|
|
9
|
+
import type { LocalizedText } from "@deepseek-ai/dsh-package-manifest";
|
|
9
10
|
import type { WebFetchProvider, WebFetchResult, WebSearchProvider, WebSearchResult } from "@deepseek-ai/dsh-web";
|
|
10
11
|
import type { CredentialRef } from "@deepseek-ai/dsh-credentials";
|
|
11
|
-
import { type QueritClientOptions, type QueritContentsRequest, type QueritContentsResponse, type QueritSearchRequest, type QueritSearchResponse } from "./client.js";
|
|
12
|
+
import { type QueritClientOptions, type QueritContentsRequest, type QueritContentsResponse, type QueritRankPreference, type QueritResourceTag, type QueritSearchRequest, type QueritSearchResponse, type QueritVertical } from "./client.js";
|
|
12
13
|
/** Stable id both providers register under, mirroring the native `web-search-deepseek` row naming. */
|
|
13
14
|
export declare const QUERIT_PROVIDER_ID = "web-search-querit";
|
|
14
15
|
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"];
|
|
15
|
-
export declare const LANGUAGE_VALUES: readonly ["english", "japanese", "korean", "german", "french", "spanish", "portuguese"];
|
|
16
|
-
/**
|
|
17
|
-
export
|
|
16
|
+
export declare const LANGUAGE_VALUES: readonly ["english", "japanese", "korean", "german", "french", "spanish", "portuguese", "russian"];
|
|
17
|
+
/** What a completed operation reports to the observability hook. */
|
|
18
|
+
export interface QueritOperationEvent {
|
|
19
|
+
operation: "search" | "fetch";
|
|
20
|
+
/** Querit's request identifier; its support team traces a request with it. */
|
|
21
|
+
searchId?: string;
|
|
22
|
+
/** Server-side time as Querit reports it. */
|
|
23
|
+
took?: string;
|
|
24
|
+
/** Formatted `<currency> <amount>`; absent when Querit reported no cost. */
|
|
25
|
+
cost?: string;
|
|
26
|
+
}
|
|
18
27
|
export interface QueritClientLike {
|
|
19
28
|
search(request: QueritSearchRequest, signal?: AbortSignal): Promise<QueritSearchResponse>;
|
|
20
29
|
contents(request: QueritContentsRequest, signal?: AbortSignal): Promise<QueritContentsResponse>;
|
|
@@ -24,14 +33,19 @@ export interface QueritProviderOptions {
|
|
|
24
33
|
apiKey?: string;
|
|
25
34
|
/** Resolve the current Querit API key for one operation. */
|
|
26
35
|
resolveApiKey?: () => Promise<string | undefined>;
|
|
36
|
+
/**
|
|
37
|
+
* Whether a key is configured, without reading its value. Feeds the seam's
|
|
38
|
+
* readiness answer; falls back to `resolveApiKey` when omitted.
|
|
39
|
+
*/
|
|
40
|
+
apiKeyConfigured?: () => Promise<boolean>;
|
|
27
41
|
/** Credential reference named by missing-credential diagnostics. */
|
|
28
42
|
apiKeyEnv?: CredentialRef;
|
|
29
43
|
/** Querit API base URL (`/v1/search` and `/v1/contents` are appended). */
|
|
30
44
|
baseURL: string;
|
|
31
45
|
/** Per-request timeout in ms. */
|
|
32
46
|
timeoutMs: number;
|
|
33
|
-
/** Result count used when the seam passes no `maxResults` bound. */
|
|
34
|
-
count
|
|
47
|
+
/** Result count used when the seam passes no `maxResults` bound; undefined leaves it to Querit. */
|
|
48
|
+
count?: number;
|
|
35
49
|
/** Relative (`d7`, `m3`) or absolute date range filter. */
|
|
36
50
|
timeRange?: string;
|
|
37
51
|
/** Country bias list (validated against `COUNTRY_VALUES`). */
|
|
@@ -42,18 +56,32 @@ export interface QueritProviderOptions {
|
|
|
42
56
|
includeDomains: string[];
|
|
43
57
|
/** Blacklist hostnames; these domains never return results. */
|
|
44
58
|
excludeDomains: string[];
|
|
45
|
-
/** Request
|
|
59
|
+
/** Request body text (`needContent`). */
|
|
46
60
|
includeContent: boolean;
|
|
47
|
-
/**
|
|
48
|
-
|
|
61
|
+
/** Body-text budget per result, in Unicode code points. Only applies with `includeContent`. */
|
|
62
|
+
contentMaxChars?: number;
|
|
63
|
+
/** Request query-focused fragments of each page. */
|
|
64
|
+
highlights: boolean;
|
|
65
|
+
/** Ask for Markdown snippet and body. Enterprise plans only. */
|
|
66
|
+
needMarkdown: boolean;
|
|
67
|
+
/** Deprecated by Querit; sent only when a deployment still sets it. */
|
|
68
|
+
chunksPerDoc?: number;
|
|
69
|
+
/** A nudge on top of Querit's default ranking. Dropped for the code vertical, which rejects it. */
|
|
70
|
+
rank?: QueritRankPreference;
|
|
71
|
+
/** Vertical data source; a mismatched vertical loses results, so it stays unset by default. */
|
|
72
|
+
vertical?: QueritVertical;
|
|
73
|
+
/** Sub-tags narrowing the code vertical. */
|
|
74
|
+
resourceTags: QueritResourceTag[];
|
|
49
75
|
/** Format requested from `/v1/contents` for fetch calls. */
|
|
50
|
-
fetchFormat: "
|
|
76
|
+
fetchFormat: QueritContentsRequest["format"];
|
|
51
77
|
/** Per-page crawl timeout in seconds, 1–60. */
|
|
52
78
|
fetchCrawlTimeout: number;
|
|
53
79
|
/** Cap applied to one fetched page's decoded body, in chars. */
|
|
54
80
|
fetchMaxChars: number;
|
|
55
81
|
/** Client factory used by tests; defaults to `QueritClient`. */
|
|
56
82
|
clientFactory?: (options: QueritClientOptions) => QueritClientLike;
|
|
83
|
+
/** Receives one event per completed operation. */
|
|
84
|
+
observe?: (event: QueritOperationEvent) => void;
|
|
57
85
|
}
|
|
58
86
|
export declare function isTimeRange(value: unknown): value is string;
|
|
59
87
|
/**
|
|
@@ -61,29 +89,35 @@ export declare function isTimeRange(value: unknown): value is string;
|
|
|
61
89
|
* and keep at most 100 unique entries. Invalid entries are dropped.
|
|
62
90
|
*/
|
|
63
91
|
export declare function normalizeDomains(values: readonly string[] | undefined): string[];
|
|
64
|
-
export declare function normalizeHostname(value: string): string | undefined;
|
|
65
92
|
export declare class QueritSearchProvider implements WebSearchProvider {
|
|
66
93
|
private readonly resolveOptions;
|
|
67
94
|
readonly id = "web-search-querit";
|
|
95
|
+
readonly title = "Querit";
|
|
96
|
+
readonly description: LocalizedText;
|
|
68
97
|
/**
|
|
69
98
|
* @param resolveOptions - options for the NEXT operation, snapshotted once
|
|
70
99
|
* at each operation's entry so one search never mixes two settings sections.
|
|
71
100
|
*/
|
|
72
101
|
constructor(resolveOptions: () => QueritProviderOptions);
|
|
73
102
|
available(): boolean;
|
|
103
|
+
/** Whether a search now would have a key to send; configuration only, no network. */
|
|
104
|
+
ready(): Promise<boolean>;
|
|
74
105
|
search(request: {
|
|
75
106
|
query: string;
|
|
76
107
|
maxResults?: number;
|
|
108
|
+
llmProvider?: string;
|
|
77
109
|
}, signal?: AbortSignal): Promise<WebSearchResult>;
|
|
78
|
-
private client;
|
|
79
110
|
}
|
|
80
111
|
export declare class QueritFetchProvider implements WebFetchProvider {
|
|
81
112
|
private readonly resolveOptions;
|
|
82
113
|
readonly id = "web-search-querit";
|
|
114
|
+
readonly title = "Querit";
|
|
115
|
+
readonly description: LocalizedText;
|
|
83
116
|
constructor(resolveOptions: () => QueritProviderOptions);
|
|
84
117
|
available(): boolean;
|
|
118
|
+
/** Whether a fetch now would have a key to send; configuration only, no network. */
|
|
119
|
+
ready(): Promise<boolean>;
|
|
85
120
|
fetch(request: {
|
|
86
121
|
url: string;
|
|
87
122
|
}, signal?: AbortSignal): Promise<WebFetchResult>;
|
|
88
|
-
private client;
|
|
89
123
|
}
|
package/lib/provider.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { WebError } from "@deepseek-ai/dsh-web";
|
|
2
|
-
import {
|
|
2
|
+
import { QUERIT_COUNT_LIMIT, QueritClient, formatCost, } from "./client.js";
|
|
3
|
+
import { sanitizeErrorMessage } from "./sanitize.js";
|
|
3
4
|
/** Stable id both providers register under, mirroring the native `web-search-deepseek` row naming. */
|
|
4
5
|
export const QUERIT_PROVIDER_ID = "web-search-querit";
|
|
6
|
+
/** What the provider picker and the plugin page show. */
|
|
7
|
+
const QUERIT_PROVIDER_TITLE = "Querit";
|
|
8
|
+
/** What the provider picker shows under the provider when it is selected. */
|
|
9
|
+
const QUERIT_PROVIDER_DESCRIPTION = {
|
|
10
|
+
en: "Live web search and page fetch through the Querit API. Needs a QUERIT_API_KEY credential. Querit bills per search and per fetched page.",
|
|
11
|
+
zh: "通过 Querit API 进行实时网页搜索与网页抓取。需要 QUERIT_API_KEY 凭据。Querit 按搜索次数和抓取页数计费。",
|
|
12
|
+
};
|
|
5
13
|
export const COUNTRY_VALUES = [
|
|
6
14
|
"argentina",
|
|
7
15
|
"australia",
|
|
@@ -29,11 +37,14 @@ export const LANGUAGE_VALUES = [
|
|
|
29
37
|
"french",
|
|
30
38
|
"spanish",
|
|
31
39
|
"portuguese",
|
|
40
|
+
"russian",
|
|
32
41
|
];
|
|
33
42
|
/** `dN`/`wN`/`mN`/`yN` (N ≥ 1) or an inclusive `YYYY-MM-DDtoYYYY-MM-DD` range. */
|
|
34
|
-
|
|
35
|
-
/** Cap on one source's
|
|
36
|
-
const SNIPPET_MAX_CHARS =
|
|
43
|
+
const TIME_RANGE_PATTERN = /^(?:[dwmy][1-9][0-9]*|\d{4}-\d{2}-\d{2}to\d{4}-\d{2}-\d{2})$/u;
|
|
44
|
+
/** Cap on one source's display snippet, in chars. */
|
|
45
|
+
const SNIPPET_MAX_CHARS = 512;
|
|
46
|
+
/** Cap on one source's model-facing summary (highlights and body excerpts), in chars. */
|
|
47
|
+
const SUMMARY_MAX_CHARS = 4_096;
|
|
37
48
|
export function isTimeRange(value) {
|
|
38
49
|
return typeof value === "string" && TIME_RANGE_PATTERN.test(value.trim());
|
|
39
50
|
}
|
|
@@ -52,7 +63,8 @@ export function normalizeDomains(values) {
|
|
|
52
63
|
}
|
|
53
64
|
return [...domains];
|
|
54
65
|
}
|
|
55
|
-
|
|
66
|
+
/** One hostname from a configured entry, or undefined for what cannot be a host. */
|
|
67
|
+
function normalizeHostname(value) {
|
|
56
68
|
const trimmed = value.trim().toLowerCase();
|
|
57
69
|
if (!trimmed)
|
|
58
70
|
return undefined;
|
|
@@ -71,24 +83,52 @@ export function normalizeHostname(value) {
|
|
|
71
83
|
return undefined;
|
|
72
84
|
return host;
|
|
73
85
|
}
|
|
86
|
+
/** Whether the options carry what an operation needs before it can talk to Querit. */
|
|
87
|
+
function coreUsable(options) {
|
|
88
|
+
if (!URL.canParse(options.baseURL))
|
|
89
|
+
return false;
|
|
90
|
+
if ((options.apiKey?.length ?? 0) === 0 && options.resolveApiKey === undefined)
|
|
91
|
+
return false;
|
|
92
|
+
if (!Number.isInteger(options.timeoutMs) || options.timeoutMs < 1_000)
|
|
93
|
+
return false;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
74
96
|
function clampInteger(value, min, max) {
|
|
75
97
|
return Math.min(max, Math.max(min, Math.trunc(value)));
|
|
76
98
|
}
|
|
77
|
-
function
|
|
99
|
+
function truncateChars(value, maxChars) {
|
|
100
|
+
return value.length <= maxChars ? value : `${value.slice(0, maxChars - 3)}...`;
|
|
101
|
+
}
|
|
102
|
+
/** The display line: the snippet alone, whitespace collapsed. */
|
|
103
|
+
function displaySnippet(result) {
|
|
104
|
+
const snippet = result.snippetMarkdown?.length
|
|
105
|
+
? result.snippetMarkdown.join(" ")
|
|
106
|
+
: result.snippet;
|
|
107
|
+
return truncateChars(snippet.replace(/\s+/gu, " ").trim(), SNIPPET_MAX_CHARS);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The model-facing line. Highlights lead because Querit selects them against
|
|
111
|
+
* the query; body text follows for context when it was requested.
|
|
112
|
+
*/
|
|
113
|
+
function modelSummary(result) {
|
|
114
|
+
if (result.contentMarkdown)
|
|
115
|
+
return truncateChars(result.contentMarkdown.trim(), SUMMARY_MAX_CHARS);
|
|
78
116
|
const parts = [];
|
|
79
|
-
|
|
80
|
-
|
|
117
|
+
for (const highlight of result.highlights) {
|
|
118
|
+
if (highlight.trim())
|
|
119
|
+
parts.push(highlight.trim());
|
|
120
|
+
}
|
|
81
121
|
for (const sentence of result.sentences) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
parts.push(`- ${trimmed}`);
|
|
122
|
+
if (sentence.trim())
|
|
123
|
+
parts.push(`- ${sentence.trim()}`);
|
|
85
124
|
}
|
|
86
|
-
|
|
87
|
-
return merged.length <= SNIPPET_MAX_CHARS ? merged : `${merged.slice(0, SNIPPET_MAX_CHARS - 3)}...`;
|
|
125
|
+
return truncateChars(parts.join("\n"), SUMMARY_MAX_CHARS);
|
|
88
126
|
}
|
|
89
127
|
export class QueritSearchProvider {
|
|
90
128
|
resolveOptions;
|
|
91
129
|
id = QUERIT_PROVIDER_ID;
|
|
130
|
+
title = QUERIT_PROVIDER_TITLE;
|
|
131
|
+
description = QUERIT_PROVIDER_DESCRIPTION;
|
|
92
132
|
/**
|
|
93
133
|
* @param resolveOptions - options for the NEXT operation, snapshotted once
|
|
94
134
|
* at each operation's entry so one search never mixes two settings sections.
|
|
@@ -98,96 +138,99 @@ export class QueritSearchProvider {
|
|
|
98
138
|
}
|
|
99
139
|
available() {
|
|
100
140
|
const options = this.resolveOptions();
|
|
101
|
-
if (!
|
|
141
|
+
if (!coreUsable(options))
|
|
102
142
|
return false;
|
|
103
|
-
if (
|
|
143
|
+
if (options.count !== undefined && (!Number.isInteger(options.count) || options.count < 1 || options.count > QUERIT_COUNT_LIMIT)) {
|
|
104
144
|
return false;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (!Number.isInteger(options.count) || options.count < 1 || options.count > 20)
|
|
108
|
-
return false;
|
|
109
|
-
if (!Number.isInteger(options.chunksPerDoc) || options.chunksPerDoc < 1 || options.chunksPerDoc > 3)
|
|
145
|
+
}
|
|
146
|
+
if (options.chunksPerDoc !== undefined && (!Number.isInteger(options.chunksPerDoc) || options.chunksPerDoc < 1 || options.chunksPerDoc > 3)) {
|
|
110
147
|
return false;
|
|
148
|
+
}
|
|
111
149
|
if (options.timeRange !== undefined && !isTimeRange(options.timeRange))
|
|
112
150
|
return false;
|
|
113
151
|
return true;
|
|
114
152
|
}
|
|
153
|
+
/** Whether a search now would have a key to send; configuration only, no network. */
|
|
154
|
+
async ready() {
|
|
155
|
+
return hasApiKey(this.resolveOptions());
|
|
156
|
+
}
|
|
115
157
|
async search(request, signal) {
|
|
116
158
|
throwIfAborted(signal);
|
|
117
159
|
const options = this.resolveOptions();
|
|
118
|
-
const client = await
|
|
160
|
+
const client = await createClient(options, signal);
|
|
119
161
|
const filters = {};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
162
|
+
const sites = {
|
|
163
|
+
...(options.includeDomains.length > 0 ? { include: options.includeDomains } : {}),
|
|
164
|
+
...(options.excludeDomains.length > 0 ? { exclude: options.excludeDomains } : {}),
|
|
165
|
+
};
|
|
166
|
+
if (Object.keys(sites).length > 0)
|
|
167
|
+
filters.sites = sites;
|
|
126
168
|
if (options.timeRange)
|
|
127
169
|
filters.timeRange = { date: options.timeRange };
|
|
128
170
|
if (options.countries.length > 0)
|
|
129
171
|
filters.geo = { countries: { include: options.countries } };
|
|
130
172
|
if (options.languages.length > 0)
|
|
131
173
|
filters.languages = { include: options.languages };
|
|
132
|
-
|
|
174
|
+
if (options.vertical)
|
|
175
|
+
filters.vertical = options.vertical;
|
|
176
|
+
if (options.vertical === "code" && options.resourceTags.length > 0) {
|
|
177
|
+
filters.resourceTags = { include: options.resourceTags };
|
|
178
|
+
}
|
|
179
|
+
// The seam enforces its bound regardless; asking Querit for the same count
|
|
180
|
+
// keeps the cost and latency of the request proportional to what is used.
|
|
181
|
+
const count = request.maxResults === undefined ? options.count : clampInteger(request.maxResults, 1, QUERIT_COUNT_LIMIT);
|
|
133
182
|
let response;
|
|
134
183
|
try {
|
|
135
184
|
response = await client.search({
|
|
136
185
|
query: request.query,
|
|
137
|
-
count,
|
|
138
|
-
|
|
186
|
+
...(count === undefined ? {} : { count }),
|
|
187
|
+
// Deprecated by Querit; forwarded only for deployments that set it before highlights existed.
|
|
188
|
+
...(options.chunksPerDoc === undefined ? {} : { chunksPerDoc: options.chunksPerDoc }),
|
|
189
|
+
...(options.highlights ? { highlights: true } : {}),
|
|
139
190
|
needContent: options.includeContent,
|
|
191
|
+
...(options.includeContent && options.contentMaxChars !== undefined ? { contentMaxChars: options.contentMaxChars } : {}),
|
|
192
|
+
...(options.needMarkdown ? { needMarkdown: true } : {}),
|
|
193
|
+
// The code vertical rejects rank with a 400.
|
|
194
|
+
...(options.rank && options.vertical !== "code" ? { rank: { preference: options.rank } } : {}),
|
|
140
195
|
...(Object.keys(filters).length === 0 ? {} : { filters }),
|
|
141
196
|
}, signal);
|
|
142
197
|
}
|
|
143
198
|
catch (error) {
|
|
144
199
|
if (signal?.aborted === true || isAbortError(error))
|
|
145
200
|
throw aborted(signal, error);
|
|
146
|
-
throw new WebError(`Querit search failed: ${
|
|
201
|
+
throw new WebError(`Querit search failed: ${sanitizeErrorMessage(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
|
|
147
202
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
...(
|
|
151
|
-
...(
|
|
152
|
-
...(
|
|
153
|
-
})
|
|
203
|
+
options.observe?.({
|
|
204
|
+
operation: "search",
|
|
205
|
+
...(response.searchId ? { searchId: response.searchId } : {}),
|
|
206
|
+
...(response.took ? { took: response.took } : {}),
|
|
207
|
+
...(response.cost ? { cost: formatCost(response.cost) } : {}),
|
|
208
|
+
});
|
|
209
|
+
const sources = response.results.map((result) => {
|
|
210
|
+
const snippet = displaySnippet(result);
|
|
211
|
+
const summary = modelSummary(result);
|
|
212
|
+
return {
|
|
213
|
+
url: result.url,
|
|
214
|
+
...(result.title && result.title !== result.url ? { title: result.title } : {}),
|
|
215
|
+
...(snippet ? { snippet } : {}),
|
|
216
|
+
...(summary ? { summary } : {}),
|
|
217
|
+
...(result.pageAge ? { publishedAt: result.pageAge } : {}),
|
|
218
|
+
};
|
|
219
|
+
});
|
|
154
220
|
return { sources, truncated: false };
|
|
155
221
|
}
|
|
156
|
-
async client(options, signal) {
|
|
157
|
-
throwIfAborted(signal);
|
|
158
|
-
let apiKey = options.apiKey;
|
|
159
|
-
if (apiKey === undefined || apiKey.length === 0) {
|
|
160
|
-
let resolved;
|
|
161
|
-
try {
|
|
162
|
-
resolved = await abortable(options.resolveApiKey?.() ?? Promise.resolve(undefined), signal);
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
if (signal?.aborted === true || isAbortError(error))
|
|
166
|
-
throw aborted(signal, error);
|
|
167
|
-
throw new WebError(`Querit credential resolution failed: ${errorMessage(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
|
|
168
|
-
}
|
|
169
|
-
apiKey = resolved;
|
|
170
|
-
}
|
|
171
|
-
if (apiKey === undefined || apiKey.length === 0) {
|
|
172
|
-
throw new WebError(`Querit has no API key for "${options.apiKeyEnv ?? "QUERIT_API_KEY"}". Configure it in priority order: export it in the launching environment, add it to the credentials store ($DSH_HOME/.credentials.yaml), or set a literal "apiKey" on the web-search-querit row. See the dsh-querit README for details.`, "WEB_PROVIDER_CREDENTIAL_MISSING");
|
|
173
|
-
}
|
|
174
|
-
return options.clientFactory?.({ apiKey, baseUrl: options.baseURL, timeoutMs: options.timeoutMs })
|
|
175
|
-
?? new QueritClient({ apiKey, baseUrl: options.baseURL, timeoutMs: options.timeoutMs });
|
|
176
|
-
}
|
|
177
222
|
}
|
|
178
223
|
export class QueritFetchProvider {
|
|
179
224
|
resolveOptions;
|
|
180
225
|
id = QUERIT_PROVIDER_ID;
|
|
226
|
+
title = QUERIT_PROVIDER_TITLE;
|
|
227
|
+
description = QUERIT_PROVIDER_DESCRIPTION;
|
|
181
228
|
constructor(resolveOptions) {
|
|
182
229
|
this.resolveOptions = resolveOptions;
|
|
183
230
|
}
|
|
184
231
|
available() {
|
|
185
232
|
const options = this.resolveOptions();
|
|
186
|
-
if (!
|
|
187
|
-
return false;
|
|
188
|
-
if ((options.apiKey?.length ?? 0) === 0 && options.resolveApiKey === undefined)
|
|
189
|
-
return false;
|
|
190
|
-
if (!Number.isInteger(options.timeoutMs) || options.timeoutMs < 1_000)
|
|
233
|
+
if (!coreUsable(options))
|
|
191
234
|
return false;
|
|
192
235
|
if (!Number.isInteger(options.fetchCrawlTimeout) || options.fetchCrawlTimeout < 1 || options.fetchCrawlTimeout > 60)
|
|
193
236
|
return false;
|
|
@@ -195,10 +238,14 @@ export class QueritFetchProvider {
|
|
|
195
238
|
return false;
|
|
196
239
|
return true;
|
|
197
240
|
}
|
|
241
|
+
/** Whether a fetch now would have a key to send; configuration only, no network. */
|
|
242
|
+
async ready() {
|
|
243
|
+
return hasApiKey(this.resolveOptions());
|
|
244
|
+
}
|
|
198
245
|
async fetch(request, signal) {
|
|
199
246
|
throwIfAborted(signal);
|
|
200
247
|
const options = this.resolveOptions();
|
|
201
|
-
const client = await
|
|
248
|
+
const client = await createClient(options, signal);
|
|
202
249
|
let response;
|
|
203
250
|
try {
|
|
204
251
|
response = await client.contents({
|
|
@@ -211,10 +258,18 @@ export class QueritFetchProvider {
|
|
|
211
258
|
catch (error) {
|
|
212
259
|
if (signal?.aborted === true || isAbortError(error))
|
|
213
260
|
throw aborted(signal, error);
|
|
214
|
-
throw new WebError(`Querit fetch failed: ${
|
|
261
|
+
throw new WebError(`Querit fetch failed: ${sanitizeErrorMessage(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
|
|
215
262
|
}
|
|
216
|
-
|
|
263
|
+
options.observe?.({
|
|
264
|
+
operation: "fetch",
|
|
265
|
+
...(response.searchId ? { searchId: response.searchId } : {}),
|
|
266
|
+
...(response.searchTime === undefined ? {} : { took: `${response.searchTime}s` }),
|
|
267
|
+
...(response.cost ? { cost: formatCost(response.cost) } : {}),
|
|
268
|
+
});
|
|
269
|
+
// Match a status to its result by id, not by array position: not every
|
|
270
|
+
// requested URL produces a result.
|
|
217
271
|
const result = response.results.find((item) => item.content.length > 0) ?? response.results[0];
|
|
272
|
+
const succeeded = response.statuses.some((status) => status.status === "success");
|
|
218
273
|
if (succeeded && result !== undefined && result.content.length > 0) {
|
|
219
274
|
const truncated = result.content.length > options.fetchMaxChars;
|
|
220
275
|
const content = truncated ? `${result.content.slice(0, options.fetchMaxChars - 3)}...` : result.content;
|
|
@@ -228,27 +283,47 @@ export class QueritFetchProvider {
|
|
|
228
283
|
const failed = response.statuses.find((status) => status.status !== undefined && status.status !== "success");
|
|
229
284
|
throw new WebError(failed ? `Querit could not retrieve the page: ${failed.status}` : "Querit returned no content for the requested URL.", "WEB_PROVIDER_ERROR");
|
|
230
285
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
286
|
+
}
|
|
287
|
+
async function hasApiKey(options) {
|
|
288
|
+
if (options.apiKey !== undefined && options.apiKey.length > 0)
|
|
289
|
+
return true;
|
|
290
|
+
try {
|
|
291
|
+
if (options.apiKeyConfigured !== undefined)
|
|
292
|
+
return await options.apiKeyConfigured();
|
|
293
|
+
return (await options.resolveApiKey?.()) !== undefined;
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
// A store that cannot be read supplies no key to the operation either.
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Resolve the credential for one operation and build the client around it.
|
|
302
|
+
* Credential reads are raced against cancellation so an aborted call never
|
|
303
|
+
* waits on the store.
|
|
304
|
+
*/
|
|
305
|
+
async function createClient(options, signal) {
|
|
306
|
+
throwIfAborted(signal);
|
|
307
|
+
let apiKey = options.apiKey;
|
|
308
|
+
if (apiKey === undefined || apiKey.length === 0) {
|
|
309
|
+
let resolved;
|
|
310
|
+
try {
|
|
311
|
+
resolved = await abortable(options.resolveApiKey?.() ?? Promise.resolve(undefined), signal);
|
|
245
312
|
}
|
|
246
|
-
|
|
247
|
-
|
|
313
|
+
catch (error) {
|
|
314
|
+
if (signal?.aborted === true || isAbortError(error))
|
|
315
|
+
throw aborted(signal, error);
|
|
316
|
+
throw new WebError(`Querit credential resolution failed: ${sanitizeErrorMessage(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
|
|
248
317
|
}
|
|
249
|
-
|
|
250
|
-
?? new QueritClient({ apiKey, baseUrl: options.baseURL, timeoutMs: options.timeoutMs });
|
|
318
|
+
apiKey = resolved;
|
|
251
319
|
}
|
|
320
|
+
if (apiKey === undefined || apiKey.length === 0) {
|
|
321
|
+
throw new WebError(`Querit has no API key for "${options.apiKeyEnv ?? "QUERIT_API_KEY"}". Set it on the Querit row's page in Settings, `
|
|
322
|
+
+ `or configure it in priority order: a literal "apiKey" on the web-search-querit row, the credentials store, or `
|
|
323
|
+
+ `(only where no credentials service runs) the launching environment. See the dsh-querit README for details.`, "WEB_PROVIDER_CREDENTIAL_MISSING");
|
|
324
|
+
}
|
|
325
|
+
const clientOptions = { apiKey, baseUrl: options.baseURL, timeoutMs: options.timeoutMs };
|
|
326
|
+
return options.clientFactory?.(clientOptions) ?? new QueritClient(clientOptions);
|
|
252
327
|
}
|
|
253
328
|
/**
|
|
254
329
|
* Race a same-process asynchronous preflight against caller cancellation. The
|
|
@@ -268,7 +343,7 @@ function abortable(operation, signal) {
|
|
|
268
343
|
resolve(value);
|
|
269
344
|
}, (error) => {
|
|
270
345
|
signal.removeEventListener("abort", onAbort);
|
|
271
|
-
reject(new Error(
|
|
346
|
+
reject(new Error(sanitizeErrorMessage(error), { cause: error }));
|
|
272
347
|
});
|
|
273
348
|
});
|
|
274
349
|
}
|
|
@@ -285,8 +360,3 @@ function aborted(signal, fallback) {
|
|
|
285
360
|
function isAbortError(error) {
|
|
286
361
|
return error instanceof DOMException && error.name === "AbortError";
|
|
287
362
|
}
|
|
288
|
-
function errorMessage(error) {
|
|
289
|
-
if (error instanceof QueritApiError)
|
|
290
|
-
return error.message;
|
|
291
|
-
return error instanceof Error ? error.message : String(error);
|
|
292
|
-
}
|
package/lib/sanitize.d.ts
CHANGED
|
@@ -5,3 +5,5 @@
|
|
|
5
5
|
* @module dsh-querit/sanitize
|
|
6
6
|
*/
|
|
7
7
|
export declare function sanitizeUntrustedText(value: string): string;
|
|
8
|
+
/** An error's message, sanitized: errors that carry remote text end up in the model's tool results. */
|
|
9
|
+
export declare function sanitizeErrorMessage(error: unknown): string;
|
package/lib/sanitize.js
CHANGED
|
@@ -62,6 +62,10 @@ export function sanitizeUntrustedText(value) {
|
|
|
62
62
|
}
|
|
63
63
|
return output.replace(BIDI_CONTROLS, "");
|
|
64
64
|
}
|
|
65
|
+
/** An error's message, sanitized: errors that carry remote text end up in the model's tool results. */
|
|
66
|
+
export function sanitizeErrorMessage(error) {
|
|
67
|
+
return sanitizeUntrustedText(error instanceof Error ? error.message : String(error));
|
|
68
|
+
}
|
|
65
69
|
function skipCsi(value, start) {
|
|
66
70
|
let index = start;
|
|
67
71
|
while (index < value.length) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-querit",
|
|
3
3
|
"description": "Querit-backed search and fetch providers for the DeepSeek Harness web capability seam (ctx.web)",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -10,10 +10,6 @@
|
|
|
10
10
|
"types": "./lib/index.d.ts",
|
|
11
11
|
"default": "./lib/index.js"
|
|
12
12
|
},
|
|
13
|
-
"./invariant": {
|
|
14
|
-
"types": "./lib/invariant.d.ts",
|
|
15
|
-
"default": "./lib/invariant.js"
|
|
16
|
-
},
|
|
17
13
|
"./client": {
|
|
18
14
|
"default": "./lib/card.js"
|
|
19
15
|
},
|
|
@@ -62,18 +58,17 @@
|
|
|
62
58
|
"prepack": "npm run check && npm test && npm run build"
|
|
63
59
|
},
|
|
64
60
|
"peerDependencies": {
|
|
65
|
-
"@deepseek-ai/cordis": "
|
|
66
|
-
"@deepseek-ai/dsh-api-remotes": "
|
|
67
|
-
"@deepseek-ai/dsh-client-connection": "
|
|
68
|
-
"@deepseek-ai/dsh-client-locale": "
|
|
69
|
-
"@deepseek-ai/dsh-client-ui-settings": "
|
|
70
|
-
"@deepseek-ai/dsh-credentials": "
|
|
71
|
-
"@deepseek-ai/dsh-
|
|
72
|
-
"@deepseek-ai/dsh-
|
|
73
|
-
"@deepseek-ai/dsh-
|
|
74
|
-
"@deepseek-ai/dsh-
|
|
75
|
-
"
|
|
76
|
-
"react": "^18.2.0"
|
|
61
|
+
"@deepseek-ai/cordis": ">=4.0.2 <5.0.0",
|
|
62
|
+
"@deepseek-ai/dsh-api-remotes": ">=0.2.2-rc.5 <0.3.0",
|
|
63
|
+
"@deepseek-ai/dsh-client-connection": ">=0.2.2-rc.5 <0.3.0",
|
|
64
|
+
"@deepseek-ai/dsh-client-locale": ">=0.2.2-rc.5 <0.3.0",
|
|
65
|
+
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.2-rc.5 <0.3.0",
|
|
66
|
+
"@deepseek-ai/dsh-credentials": ">=0.2.2-rc.5 <0.3.0",
|
|
67
|
+
"@deepseek-ai/dsh-launch-environment": ">=0.2.2-rc.5 <0.3.0",
|
|
68
|
+
"@deepseek-ai/dsh-settings": ">=0.2.2-rc.5 <0.3.0",
|
|
69
|
+
"@deepseek-ai/dsh-tool-web": ">=0.2.2-rc.5 <0.3.0",
|
|
70
|
+
"@deepseek-ai/dsh-web": ">=0.2.2-rc.5 <0.3.0",
|
|
71
|
+
"react": ">=18.2.0"
|
|
77
72
|
},
|
|
78
73
|
"peerDependenciesMeta": {
|
|
79
74
|
"@deepseek-ai/cordis": {
|
|
@@ -82,9 +77,6 @@
|
|
|
82
77
|
"@deepseek-ai/dsh-credentials": {
|
|
83
78
|
"optional": true
|
|
84
79
|
},
|
|
85
|
-
"@deepseek-ai/dsh-invariants": {
|
|
86
|
-
"optional": true
|
|
87
|
-
},
|
|
88
80
|
"@deepseek-ai/dsh-launch-environment": {
|
|
89
81
|
"optional": true
|
|
90
82
|
},
|
|
@@ -114,23 +106,30 @@
|
|
|
114
106
|
}
|
|
115
107
|
},
|
|
116
108
|
"dependencies": {
|
|
117
|
-
"@deepseek-ai/schemastery": "^3.
|
|
109
|
+
"@deepseek-ai/schemastery": "^3.19.0"
|
|
118
110
|
},
|
|
119
111
|
"devDependencies": {
|
|
120
|
-
"@deepseek-ai/cordis": "^4.0
|
|
121
|
-
"@deepseek-ai/dsh-
|
|
122
|
-
"@deepseek-ai/dsh-
|
|
123
|
-
"@deepseek-ai/dsh-
|
|
124
|
-
"@deepseek-ai/dsh-settings": "^0.
|
|
125
|
-
"@deepseek-ai/dsh-
|
|
126
|
-
"@deepseek-ai/dsh-
|
|
127
|
-
"@
|
|
112
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
113
|
+
"@deepseek-ai/dsh-api-remotes": "^0.2.2-rc.5",
|
|
114
|
+
"@deepseek-ai/dsh-client-connection": "^0.2.2-rc.5",
|
|
115
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.5",
|
|
116
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.5",
|
|
117
|
+
"@deepseek-ai/dsh-credentials": "^0.2.2-rc.5",
|
|
118
|
+
"@deepseek-ai/dsh-launch-environment": "^0.2.2-rc.5",
|
|
119
|
+
"@deepseek-ai/dsh-llm": "^0.2.2-rc.5",
|
|
120
|
+
"@deepseek-ai/dsh-settings": "^0.2.2-rc.5",
|
|
121
|
+
"@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.5",
|
|
122
|
+
"@deepseek-ai/dsh-tool-web": "^0.2.2-rc.5",
|
|
123
|
+
"@deepseek-ai/dsh-tools": "^0.2.2-rc.5",
|
|
124
|
+
"@deepseek-ai/dsh-web": "^0.2.2-rc.5",
|
|
125
|
+
"@types/node": "^24.0.0",
|
|
128
126
|
"react": "^18.2.0",
|
|
129
127
|
"react-dom": "^18.3.1",
|
|
130
128
|
"typescript": "^5.9.0",
|
|
131
129
|
"vitest": "^4.0.0"
|
|
132
130
|
},
|
|
133
131
|
"engines": {
|
|
134
|
-
"node": ">=
|
|
132
|
+
"node": ">=24.9.0",
|
|
133
|
+
"dsh": ">=0.2.2-rc.5 <0.3.0"
|
|
135
134
|
}
|
|
136
135
|
}
|
package/lib/invariant.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Package-owned invariant companion for `dsh-querit`.
|
|
3
|
-
* @module dsh-querit/invariant
|
|
4
|
-
*/
|
|
5
|
-
/** Cordis companion plugin name. */
|
|
6
|
-
declare const name = "web-querit-invariant";
|
|
7
|
-
/** Service required before the companion can reserve package ownership. */
|
|
8
|
-
declare const inject: string[];
|
|
9
|
-
/**
|
|
10
|
-
* Register this package's invariant companion.
|
|
11
|
-
* @param ctx - Cordis context carrying the invariant service.
|
|
12
|
-
*/
|
|
13
|
-
declare const apply: (ctx: {
|
|
14
|
-
invariants: {
|
|
15
|
-
register(packageName: string, installer: () => void): () => void;
|
|
16
|
-
};
|
|
17
|
-
}) => Promise<() => void>;
|
|
18
|
-
export { apply, inject, name };
|