dsh-querit 1.1.2 → 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/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Register Querit-backed search and fetch providers in `ctx.web`.
|
|
3
3
|
* Both providers call the public Querit API (`POST /v1/search`,
|
|
4
|
-
* `POST /v1/contents`) with a Bearer key resolved per operation from
|
|
5
|
-
*
|
|
4
|
+
* `POST /v1/contents`) with a Bearer key resolved per operation from a
|
|
5
|
+
* literal row `apiKey`, then the credentials service (or, only where none
|
|
6
|
+
* runs, the launching environment).
|
|
6
7
|
* The agent preset registers model-facing `web_search`; this package does not.
|
|
7
8
|
* Both model-facing web tools route through the seam, so once it selects Querit
|
|
8
9
|
* neither needs a registration here; `fetch: true` opts into registering
|
|
@@ -10,88 +11,98 @@
|
|
|
10
11
|
* where no `tool-web` row provides it.
|
|
11
12
|
* @module dsh-querit
|
|
12
13
|
*/
|
|
13
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
14
|
+
import type { Context, Volatile } from "@deepseek-ai/cordis";
|
|
14
15
|
import z from "@deepseek-ai/schemastery";
|
|
15
16
|
import { type CredentialRef } from "@deepseek-ai/dsh-credentials";
|
|
16
|
-
import type {
|
|
17
|
+
import type { QueritContentsRequest } from "./client.js";
|
|
17
18
|
import { type QueritProviderOptions } from "./provider.js";
|
|
18
|
-
export {
|
|
19
|
-
export type { QueritClientLike, QueritProviderOptions } from "./provider.js";
|
|
19
|
+
export { QueritFetchProvider, QueritSearchProvider } from "./provider.js";
|
|
20
|
+
export type { QueritClientLike, QueritOperationEvent, QueritProviderOptions } from "./provider.js";
|
|
20
21
|
/** Cordis plugin name used by loader diagnostics. */
|
|
21
22
|
export declare const name = "web-search-querit";
|
|
22
|
-
/**
|
|
23
|
-
* The web seam both providers register into, plus the registries the optional
|
|
24
|
-
* model-facing `web_fetch` tool needs (reused from `@deepseek-ai/dsh-tool-web`).
|
|
25
|
-
*/
|
|
23
|
+
/** Only the web seam is required; the optional `web_fetch` tool injects its own registries. */
|
|
26
24
|
export declare const inject: string[];
|
|
27
25
|
export declare const DEFAULT_API_KEY_ENV = "QUERIT_API_KEY";
|
|
28
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Plugin config. Every field is a `Volatile` handle: the host re-resolves the
|
|
28
|
+
* section when the entry is edited, so each operation reads the current value
|
|
29
|
+
* through `.get()` instead of caching what `apply` saw.
|
|
30
|
+
*/
|
|
29
31
|
export interface Config {
|
|
30
32
|
/** Literal Querit API key; prefer `apiKeyEnv` so no secret enters configuration files. */
|
|
31
|
-
apiKey
|
|
33
|
+
apiKey: Volatile<string | undefined>;
|
|
32
34
|
/** Credential reference resolved per operation; defaults to `QUERIT_API_KEY`. */
|
|
33
|
-
apiKeyEnv
|
|
35
|
+
apiKeyEnv: Volatile<string>;
|
|
34
36
|
/** Querit API base URL; `/v1/search` and `/v1/contents` are appended. */
|
|
35
|
-
baseURL
|
|
36
|
-
/** Per-request timeout in ms. Defaults to 70000. */
|
|
37
|
-
timeoutMs
|
|
38
|
-
/** Result count used when the seam passes no `maxResults` bound (1–
|
|
39
|
-
count
|
|
37
|
+
baseURL: Volatile<string | undefined>;
|
|
38
|
+
/** Per-request timeout in ms, retries included. Defaults to 70000. */
|
|
39
|
+
timeoutMs: Volatile<number>;
|
|
40
|
+
/** Result count used when the seam passes no `maxResults` bound (1–100). Unset leaves it to Querit. */
|
|
41
|
+
count: Volatile<number | undefined>;
|
|
40
42
|
/** Relative (`d7`, `w2`, `m3`, `y1`) or `YYYY-MM-DDtoYYYY-MM-DD` date range. */
|
|
41
|
-
timeRange
|
|
43
|
+
timeRange: Volatile<string | undefined>;
|
|
42
44
|
/** Country bias; values from the Querit country list. */
|
|
43
|
-
countries
|
|
45
|
+
countries: Volatile<string[] | undefined>;
|
|
44
46
|
/** Language filter; values from the Querit language list. */
|
|
45
|
-
languages
|
|
47
|
+
languages: Volatile<string[] | undefined>;
|
|
46
48
|
/** Whitelist hostnames (only these domains return results). */
|
|
47
|
-
includeDomains
|
|
49
|
+
includeDomains: Volatile<string[] | undefined>;
|
|
48
50
|
/** Blacklist hostnames (these domains never return results). */
|
|
49
|
-
excludeDomains
|
|
50
|
-
/** Request
|
|
51
|
-
includeContent
|
|
52
|
-
/**
|
|
53
|
-
|
|
51
|
+
excludeDomains: Volatile<string[] | undefined>;
|
|
52
|
+
/** Request body text (`needContent`). */
|
|
53
|
+
includeContent: Volatile<boolean>;
|
|
54
|
+
/** Body-text budget per result, in Unicode code points (1–1000000). Only with `includeContent`. */
|
|
55
|
+
contentMaxChars: Volatile<number | undefined>;
|
|
56
|
+
/** Request query-focused fragments of each page. */
|
|
57
|
+
highlights: Volatile<boolean>;
|
|
58
|
+
/** Ask for Markdown snippet and body. Enterprise plans only. */
|
|
59
|
+
needMarkdown: Volatile<boolean>;
|
|
60
|
+
/** Deprecated by Querit; kept so existing rows keep working. Prefer `highlights`. */
|
|
61
|
+
chunksPerDoc: Volatile<number | undefined>;
|
|
62
|
+
/** Ranking nudge: `relevance` or `freshness`. Dropped for `vertical: code`, which rejects it. */
|
|
63
|
+
rank: Volatile<string | undefined>;
|
|
64
|
+
/** Vertical data source: `code` or `finance`. Unset for universal search. */
|
|
65
|
+
vertical: Volatile<string | undefined>;
|
|
66
|
+
/** Sub-tags narrowing the code vertical: `qa`, `github`. */
|
|
67
|
+
resourceTags: Volatile<string[] | undefined>;
|
|
54
68
|
/** Format requested from `/v1/contents` for fetch calls. */
|
|
55
|
-
fetchFormat
|
|
69
|
+
fetchFormat: Volatile<QueritContentsRequest["format"]>;
|
|
56
70
|
/** Per-page crawl timeout in seconds (1–60). */
|
|
57
|
-
fetchCrawlTimeout
|
|
71
|
+
fetchCrawlTimeout: Volatile<number>;
|
|
58
72
|
/** Cap applied to one fetched page's decoded body, in chars. */
|
|
59
|
-
fetchMaxChars
|
|
73
|
+
fetchMaxChars: Volatile<number>;
|
|
60
74
|
/**
|
|
61
75
|
* Register the model-facing `web_fetch` tool (via `dsh-tool-web`'s
|
|
62
|
-
* `applyWebFetchTool`). Defaults to false
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
76
|
+
* `applyWebFetchTool`). Defaults to false: the base and agent-preset
|
|
77
|
+
* `tool-web` rows register `web_fetch` themselves (both routing through
|
|
78
|
+
* `ctx.web`, hence Querit); enable only for compositions where no other row
|
|
79
|
+
* provides the tool. Read when the entry starts, so a change applies on restart.
|
|
66
80
|
*/
|
|
67
|
-
fetch
|
|
68
|
-
/** Cooperative tool-call timeout budget (ms) for `web_fetch`. Defaults to 30000. */
|
|
69
|
-
fetchTimeoutMs
|
|
70
|
-
/** Cap on one `web_fetch` rendered output, in chars. Defaults to 200000. */
|
|
71
|
-
fetchMaxOutputChars
|
|
81
|
+
fetch: Volatile<boolean>;
|
|
82
|
+
/** Cooperative tool-call timeout budget (ms) for `web_fetch`. Defaults to 30000. Read at start. */
|
|
83
|
+
fetchTimeoutMs: Volatile<number>;
|
|
84
|
+
/** Cap on one `web_fetch` rendered output, in chars. Defaults to 200000. Read at start. */
|
|
85
|
+
fetchMaxOutputChars: Volatile<number>;
|
|
72
86
|
}
|
|
73
87
|
export declare const Config: z<Config>;
|
|
74
|
-
/**
|
|
75
|
-
export
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
* next operation with. Environment fallbacks stay here rather than in the
|
|
79
|
-
* providers: every value they read is already fully defaulted.
|
|
80
|
-
*/
|
|
81
|
-
export declare function resolveOptions(ctx: Context, config: Config): QueritProviderOptions;
|
|
82
|
-
/** Register both Querit providers with `ctx.web`, the `web_fetch` tool, and the first-load key check. */
|
|
83
|
-
export declare function apply(ctx: Context, config: Config): Promise<void>;
|
|
88
|
+
/** The config with every handle read once: one consistent view for one operation. */
|
|
89
|
+
export type ResolvedQueritConfig = {
|
|
90
|
+
[K in keyof Config]: ReturnType<Config[K]["get"]>;
|
|
91
|
+
};
|
|
84
92
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* the inherited environment before the managed document), then a literal row
|
|
89
|
-
* `apiKey`.
|
|
93
|
+
* Project one read of the config into the options both providers serve their
|
|
94
|
+
* next operation with. Every value is fully defaulted, so the providers never
|
|
95
|
+
* branch on absence.
|
|
90
96
|
*/
|
|
91
|
-
export declare function
|
|
97
|
+
export declare function resolveOptions(ctx: Context, config: ResolvedQueritConfig): QueritProviderOptions;
|
|
98
|
+
/** Register both Querit providers with `ctx.web`, the optional `web_fetch` tool, and the first-load key check. */
|
|
99
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
92
100
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
101
|
+
* Resolve the Querit API key for one operation. An installed credentials
|
|
102
|
+
* service is authoritative, including absence, as it is for the host's own
|
|
103
|
+
* providers; only deployments without that service read the launching
|
|
104
|
+
* environment.
|
|
96
105
|
*/
|
|
97
|
-
export declare function
|
|
106
|
+
export declare function resolveQueritApiKey(ctx: Context, apiKeyEnv: CredentialRef): Promise<string | undefined>;
|
|
107
|
+
/** Whether a key is configured, without resolving the stored value. */
|
|
108
|
+
export declare function queritApiKeyConfigured(ctx: Context, apiKeyEnv: CredentialRef): Promise<boolean>;
|
package/lib/index.js
CHANGED
|
@@ -2,158 +2,198 @@ import z from "@deepseek-ai/schemastery";
|
|
|
2
2
|
import { credentialRef } from "@deepseek-ai/dsh-credentials";
|
|
3
3
|
import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
|
|
4
4
|
import { DEFAULT_FETCH_MAX_OUTPUT_CHARS, DEFAULT_WEB_TOOL_TIMEOUT_MS, applyWebFetchTool, } from "@deepseek-ai/dsh-tool-web";
|
|
5
|
-
import { DEFAULT_REQUEST_TIMEOUT_MS, QUERIT_API_BASE_URL } from "./client.js";
|
|
5
|
+
import { DEFAULT_REQUEST_TIMEOUT_MS, QUERIT_API_BASE_URL, QUERIT_CONTENT_MAX_CHARS_LIMIT, QUERIT_COUNT_LIMIT, RANK_VALUES, RESOURCE_TAG_VALUES, VERTICAL_VALUES, } from "./client.js";
|
|
6
6
|
import { COUNTRY_VALUES, LANGUAGE_VALUES, QueritFetchProvider, QueritSearchProvider, isTimeRange, normalizeDomains, } from "./provider.js";
|
|
7
|
-
|
|
7
|
+
// The providers leave through the package entry for scripts that drive them directly.
|
|
8
|
+
export { QueritFetchProvider, QueritSearchProvider } from "./provider.js";
|
|
8
9
|
/** Cordis plugin name used by loader diagnostics. */
|
|
9
10
|
export const name = "web-search-querit";
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
* model-facing `web_fetch` tool needs (reused from `@deepseek-ai/dsh-tool-web`).
|
|
13
|
-
*/
|
|
14
|
-
export const inject = ["web", "tools", "systemPrompt"];
|
|
11
|
+
/** Only the web seam is required; the optional `web_fetch` tool injects its own registries. */
|
|
12
|
+
export const inject = ["web"];
|
|
15
13
|
export const DEFAULT_API_KEY_ENV = "QUERIT_API_KEY";
|
|
16
14
|
const BASE_URL_ENV = "QUERIT_BASE_URL";
|
|
17
15
|
export const Config = z.object({
|
|
18
|
-
apiKey: z.string().role("secret"),
|
|
19
|
-
apiKeyEnv: z.string().role("credential-ref").default(DEFAULT_API_KEY_ENV),
|
|
20
|
-
baseURL: z.string(),
|
|
21
|
-
timeoutMs: z.number().step(1).min(1_000).default(DEFAULT_REQUEST_TIMEOUT_MS),
|
|
22
|
-
count: z.number().step(1).min(1).max(
|
|
23
|
-
timeRange: z.string(),
|
|
24
|
-
countries: z.array(z.string()),
|
|
25
|
-
languages: z.array(z.string()),
|
|
26
|
-
includeDomains: z.array(z.string()),
|
|
27
|
-
excludeDomains: z.array(z.string()),
|
|
28
|
-
includeContent: z.boolean().default(false),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
apiKey: z.string().role("secret").volatile(),
|
|
17
|
+
apiKeyEnv: z.string().role("credential-ref").default(DEFAULT_API_KEY_ENV).volatile(),
|
|
18
|
+
baseURL: z.string().volatile(),
|
|
19
|
+
timeoutMs: z.number().step(1).min(1_000).default(DEFAULT_REQUEST_TIMEOUT_MS).volatile(),
|
|
20
|
+
count: z.number().step(1).min(1).max(QUERIT_COUNT_LIMIT).volatile(),
|
|
21
|
+
timeRange: z.string().volatile(),
|
|
22
|
+
countries: z.array(z.string()).volatile(),
|
|
23
|
+
languages: z.array(z.string()).volatile(),
|
|
24
|
+
includeDomains: z.array(z.string()).volatile(),
|
|
25
|
+
excludeDomains: z.array(z.string()).volatile(),
|
|
26
|
+
includeContent: z.boolean().default(false).volatile(),
|
|
27
|
+
contentMaxChars: z.number().step(1).min(1).max(QUERIT_CONTENT_MAX_CHARS_LIMIT).volatile(),
|
|
28
|
+
highlights: z.boolean().default(false).volatile(),
|
|
29
|
+
needMarkdown: z.boolean().default(false).volatile(),
|
|
30
|
+
chunksPerDoc: z.number().step(1).min(1).max(3).volatile(),
|
|
31
|
+
rank: z.string().volatile(),
|
|
32
|
+
vertical: z.string().volatile(),
|
|
33
|
+
resourceTags: z.array(z.string()).volatile(),
|
|
34
|
+
fetchFormat: z.union([z.const("markdown"), z.const("text"), z.const("html")]).default("markdown").volatile(),
|
|
35
|
+
fetchCrawlTimeout: z.number().step(1).min(1).max(60).default(10).volatile(),
|
|
36
|
+
fetchMaxChars: z.number().step(1).min(256).default(8_000).volatile(),
|
|
37
|
+
fetch: z.boolean().default(false).volatile(),
|
|
38
|
+
fetchTimeoutMs: z.number().step(1).min(1_000).default(DEFAULT_WEB_TOOL_TIMEOUT_MS).volatile(),
|
|
39
|
+
fetchMaxOutputChars: z.number().step(1).min(256).default(DEFAULT_FETCH_MAX_OUTPUT_CHARS).volatile(),
|
|
36
40
|
});
|
|
37
|
-
/** Settings namespace carrying this provider's endpoint, key reference, and search defaults. */
|
|
38
|
-
export const WEB_SEARCH_QUERIT_SETTINGS_NAMESPACE = "web-search-querit";
|
|
39
41
|
/**
|
|
40
|
-
* Project one
|
|
41
|
-
* next operation with.
|
|
42
|
-
*
|
|
42
|
+
* Project one read of the config into the options both providers serve their
|
|
43
|
+
* next operation with. Every value is fully defaulted, so the providers never
|
|
44
|
+
* branch on absence.
|
|
43
45
|
*/
|
|
44
46
|
export function resolveOptions(ctx, config) {
|
|
45
47
|
const apiKeyEnv = credentialRef(config.apiKeyEnv ?? DEFAULT_API_KEY_ENV);
|
|
46
48
|
const literalApiKey = config.apiKey !== undefined && config.apiKey.trim().length > 0
|
|
47
49
|
? config.apiKey.trim()
|
|
48
50
|
: undefined;
|
|
49
|
-
const
|
|
51
|
+
const timeRange = normalizeTimeRange(config.timeRange);
|
|
50
52
|
return {
|
|
51
|
-
|
|
53
|
+
...(literalApiKey === undefined ? {} : { apiKey: literalApiKey }),
|
|
54
|
+
resolveApiKey: () => resolveQueritApiKey(ctx, apiKeyEnv),
|
|
55
|
+
apiKeyConfigured: () => queritApiKeyConfigured(ctx, apiKeyEnv),
|
|
52
56
|
apiKeyEnv,
|
|
53
|
-
baseURL: (config.baseURL ??
|
|
57
|
+
baseURL: (config.baseURL ?? launchEnvironmentOf(ctx).get(BASE_URL_ENV)?.value ?? QUERIT_API_BASE_URL).replace(/\/+$/, ""),
|
|
54
58
|
timeoutMs: config.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
|
|
55
|
-
count: config.count
|
|
56
|
-
timeRange:
|
|
59
|
+
...(config.count === undefined ? {} : { count: config.count }),
|
|
60
|
+
...(timeRange === undefined ? {} : { timeRange }),
|
|
57
61
|
countries: normalizeEnumList(config.countries, COUNTRY_VALUES),
|
|
58
62
|
languages: normalizeEnumList(config.languages, LANGUAGE_VALUES),
|
|
59
63
|
includeDomains: normalizeDomains(config.includeDomains),
|
|
60
64
|
excludeDomains: normalizeDomains(config.excludeDomains),
|
|
61
65
|
includeContent: config.includeContent ?? false,
|
|
62
|
-
|
|
66
|
+
...(config.contentMaxChars === undefined ? {} : { contentMaxChars: config.contentMaxChars }),
|
|
67
|
+
highlights: config.highlights ?? false,
|
|
68
|
+
needMarkdown: config.needMarkdown ?? false,
|
|
69
|
+
...(config.chunksPerDoc === undefined ? {} : { chunksPerDoc: config.chunksPerDoc }),
|
|
70
|
+
rank: normalizeEnum(config.rank, RANK_VALUES),
|
|
71
|
+
vertical: normalizeEnum(config.vertical, VERTICAL_VALUES),
|
|
72
|
+
resourceTags: normalizeEnumList(config.resourceTags, RESOURCE_TAG_VALUES),
|
|
63
73
|
fetchFormat: config.fetchFormat ?? "markdown",
|
|
64
74
|
fetchCrawlTimeout: config.fetchCrawlTimeout ?? 10,
|
|
65
75
|
fetchMaxChars: config.fetchMaxChars ?? 8_000,
|
|
76
|
+
observe: (event) => {
|
|
77
|
+
// Querit asks for search_id, took, and cost on every operation: support
|
|
78
|
+
// traces a request by the id alone, and an absent cost is never "free".
|
|
79
|
+
const fields = [
|
|
80
|
+
event.searchId === undefined ? "" : `search_id=${event.searchId}`,
|
|
81
|
+
event.took === undefined ? "" : `took=${event.took}`,
|
|
82
|
+
event.cost === undefined ? "cost=n/a" : `cost=${event.cost}`,
|
|
83
|
+
].filter(Boolean);
|
|
84
|
+
ctx.logger.info(`web-search-querit: ${event.operation} ${fields.join(" ")}`);
|
|
85
|
+
},
|
|
66
86
|
};
|
|
67
87
|
}
|
|
68
|
-
/** Register both Querit providers with `ctx.web`, the `web_fetch` tool, and the first-load key check. */
|
|
69
|
-
export
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
/** Register both Querit providers with `ctx.web`, the optional `web_fetch` tool, and the first-load key check. */
|
|
89
|
+
export function apply(ctx, config) {
|
|
90
|
+
const current = () => ({
|
|
91
|
+
apiKey: config.apiKey.get(),
|
|
92
|
+
apiKeyEnv: config.apiKeyEnv.get(),
|
|
93
|
+
baseURL: config.baseURL.get(),
|
|
94
|
+
timeoutMs: config.timeoutMs.get(),
|
|
95
|
+
count: config.count.get(),
|
|
96
|
+
timeRange: config.timeRange.get(),
|
|
97
|
+
countries: config.countries.get(),
|
|
98
|
+
languages: config.languages.get(),
|
|
99
|
+
includeDomains: config.includeDomains.get(),
|
|
100
|
+
excludeDomains: config.excludeDomains.get(),
|
|
101
|
+
includeContent: config.includeContent.get(),
|
|
102
|
+
contentMaxChars: config.contentMaxChars.get(),
|
|
103
|
+
highlights: config.highlights.get(),
|
|
104
|
+
needMarkdown: config.needMarkdown.get(),
|
|
105
|
+
chunksPerDoc: config.chunksPerDoc.get(),
|
|
106
|
+
rank: config.rank.get(),
|
|
107
|
+
vertical: config.vertical.get(),
|
|
108
|
+
resourceTags: config.resourceTags.get(),
|
|
109
|
+
fetchFormat: config.fetchFormat.get(),
|
|
110
|
+
fetchCrawlTimeout: config.fetchCrawlTimeout.get(),
|
|
111
|
+
fetchMaxChars: config.fetchMaxChars.get(),
|
|
112
|
+
fetch: config.fetch.get(),
|
|
113
|
+
fetchTimeoutMs: config.fetchTimeoutMs.get(),
|
|
114
|
+
fetchMaxOutputChars: config.fetchMaxOutputChars.get(),
|
|
115
|
+
});
|
|
116
|
+
const options = () => resolveOptions(ctx, current());
|
|
117
|
+
const search = new QueritSearchProvider(options);
|
|
118
|
+
const fetch = new QueritFetchProvider(options);
|
|
119
|
+
ctx.web.registerSearchProvider({
|
|
120
|
+
id: search.id,
|
|
121
|
+
title: search.title,
|
|
122
|
+
description: search.description,
|
|
123
|
+
available: () => search.available(),
|
|
124
|
+
ready: () => search.ready(),
|
|
125
|
+
search: (request, signal) => search.search(request, signal),
|
|
126
|
+
});
|
|
127
|
+
ctx.web.registerFetchProvider({
|
|
128
|
+
id: fetch.id,
|
|
129
|
+
title: fetch.title,
|
|
130
|
+
description: fetch.description,
|
|
131
|
+
available: () => fetch.available(),
|
|
132
|
+
ready: () => fetch.ready(),
|
|
133
|
+
fetch: (request, signal) => fetch.fetch(request, signal),
|
|
134
|
+
});
|
|
135
|
+
// This package ships its own page (`plugins.row.config`), so it opts out of
|
|
136
|
+
// the host generating one from the schema.
|
|
137
|
+
ctx.inject(["settings"], (child) => {
|
|
138
|
+
child.effect(() => child.settings.configure({ auto: false }, ctx.fiber));
|
|
82
139
|
});
|
|
83
|
-
ctx.web.registerSearchProvider(new QueritSearchProvider(() => resolveOptions(ctx, current())));
|
|
84
|
-
ctx.web.registerFetchProvider(new QueritFetchProvider(() => resolveOptions(ctx, current())));
|
|
85
140
|
// The model-facing web_fetch tool. Since dsh 0.1.2 the base composition and
|
|
86
141
|
// agent presets register `web_fetch` through their own `tool-web` rows (both
|
|
87
142
|
// web tools route through `ctx.web`, hence Querit), so this opt-in covers
|
|
88
143
|
// only compositions where no other row provides the tool.
|
|
89
|
-
if (config.fetch === true) {
|
|
90
|
-
|
|
144
|
+
if (config.fetch.get() === true) {
|
|
145
|
+
const { fetchTimeoutMs, fetchMaxOutputChars } = current();
|
|
146
|
+
ctx.inject(["tools", "systemPrompt"], (child) => {
|
|
147
|
+
applyWebFetchTool(child, fetchTimeoutMs ?? DEFAULT_WEB_TOOL_TIMEOUT_MS, fetchMaxOutputChars ?? DEFAULT_FETCH_MAX_OUTPUT_CHARS);
|
|
148
|
+
});
|
|
91
149
|
}
|
|
92
|
-
// First-load configuration prompt:
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
150
|
+
// First-load configuration prompt: the loudest surface a starting host has
|
|
151
|
+
// is its log. The probe never blocks loading and never throws; a search
|
|
152
|
+
// without a key still fails per call with the actionable
|
|
153
|
+
// WEB_PROVIDER_CREDENTIAL_MISSING message.
|
|
154
|
+
void (async () => {
|
|
155
|
+
try {
|
|
156
|
+
const start = current();
|
|
157
|
+
const apiKeyEnv = credentialRef(start.apiKeyEnv ?? DEFAULT_API_KEY_ENV);
|
|
158
|
+
const configured = (await resolveQueritApiKey(ctx, apiKeyEnv)) !== undefined
|
|
159
|
+
|| (start.apiKey?.trim().length ?? 0) > 0;
|
|
160
|
+
if (!configured) {
|
|
161
|
+
ctx.logger.warn(`web-search-querit: Querit web search is not configured yet — searches will fail until a key is provided. `
|
|
162
|
+
+ `Open the Querit row's page in Settings, or in priority order: set "apiKey" on the web-search-querit row, `
|
|
163
|
+
+ `add ${apiKeyEnv} to the credentials store, or (only where no credentials service runs) export `
|
|
164
|
+
+ `${apiKeyEnv} in the launching environment. See the dsh-querit README for details.`);
|
|
165
|
+
}
|
|
106
166
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
167
|
+
catch {
|
|
168
|
+
// Probe-only; provider calls surface credential failures with full detail.
|
|
169
|
+
}
|
|
170
|
+
})();
|
|
111
171
|
}
|
|
112
172
|
/**
|
|
113
|
-
* Resolve the Querit API key for one operation
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* `apiKey`.
|
|
173
|
+
* Resolve the Querit API key for one operation. An installed credentials
|
|
174
|
+
* service is authoritative, including absence, as it is for the host's own
|
|
175
|
+
* providers; only deployments without that service read the launching
|
|
176
|
+
* environment.
|
|
118
177
|
*/
|
|
119
|
-
export async function resolveQueritApiKey(ctx, apiKeyEnv
|
|
120
|
-
const ambient = launchEnvironmentOf(ctx).get(apiKeyEnv);
|
|
121
|
-
if (ambient !== undefined && ambient.value.length > 0)
|
|
122
|
-
return ambient.value;
|
|
178
|
+
export async function resolveQueritApiKey(ctx, apiKeyEnv) {
|
|
123
179
|
const credentials = ctx.get("credentials");
|
|
124
180
|
if (credentials !== undefined) {
|
|
125
181
|
const stored = await credentials.resolve(apiKeyEnv);
|
|
126
|
-
|
|
127
|
-
return stored.value;
|
|
182
|
+
return stored !== undefined && stored.value.length > 0 ? stored.value : undefined;
|
|
128
183
|
}
|
|
129
|
-
|
|
184
|
+
const ambient = launchEnvironmentOf(ctx).get(apiKeyEnv);
|
|
185
|
+
return ambient !== undefined && ambient.value.length > 0 ? ambient.value : undefined;
|
|
130
186
|
}
|
|
131
|
-
/**
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (value.baseURL !== undefined && !URL.canParse(value.baseURL)) {
|
|
138
|
-
throw new Error("baseURL must be a parseable HTTP(S) URL.");
|
|
139
|
-
}
|
|
140
|
-
if (value.timeRange !== undefined && !isTimeRange(value.timeRange)) {
|
|
141
|
-
throw new Error("timeRange must be a relative range (d7, w2, m3, y1, ...) or YYYY-MM-DDtoYYYY-MM-DD.");
|
|
142
|
-
}
|
|
143
|
-
if (value.countries !== undefined)
|
|
144
|
-
rejectUnknownValues(value.countries, COUNTRY_VALUES, "countries");
|
|
145
|
-
if (value.languages !== undefined)
|
|
146
|
-
rejectUnknownValues(value.languages, LANGUAGE_VALUES, "languages");
|
|
147
|
-
if (value.includeDomains !== undefined)
|
|
148
|
-
rejectInvalidDomains(value.includeDomains, "includeDomains");
|
|
149
|
-
if (value.excludeDomains !== undefined)
|
|
150
|
-
rejectInvalidDomains(value.excludeDomains, "excludeDomains");
|
|
187
|
+
/** Whether a key is configured, without resolving the stored value. */
|
|
188
|
+
export async function queritApiKeyConfigured(ctx, apiKeyEnv) {
|
|
189
|
+
const credentials = ctx.get("credentials");
|
|
190
|
+
return credentials === undefined
|
|
191
|
+
? (launchEnvironmentOf(ctx).get(apiKeyEnv)?.value.length ?? 0) > 0
|
|
192
|
+
: (await credentials.describe(apiKeyEnv)).configured;
|
|
151
193
|
}
|
|
152
194
|
function normalizeTimeRange(value) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const trimmed = value.trim();
|
|
156
|
-
return trimmed.length > 0 ? trimmed : undefined;
|
|
195
|
+
const trimmed = value?.trim();
|
|
196
|
+
return trimmed !== undefined && isTimeRange(trimmed) ? trimmed : undefined;
|
|
157
197
|
}
|
|
158
198
|
function normalizeEnumList(values, allowed) {
|
|
159
199
|
const allowedSet = new Set(allowed);
|
|
@@ -165,19 +205,6 @@ function normalizeEnumList(values, allowed) {
|
|
|
165
205
|
}
|
|
166
206
|
return [...matched];
|
|
167
207
|
}
|
|
168
|
-
function
|
|
169
|
-
|
|
170
|
-
const unknown = [...new Set(values.map((value) => value.trim().toLowerCase()))].filter((value) => !allowedSet.has(value));
|
|
171
|
-
if (unknown.length > 0) {
|
|
172
|
-
throw new Error(`${field} contains unsupported values: ${unknown.join(", ")}. Allowed: ${allowed.join(", ")}.`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function rejectInvalidDomains(values, field) {
|
|
176
|
-
const invalid = values.filter((value) => {
|
|
177
|
-
const trimmed = value.trim().toLowerCase();
|
|
178
|
-
return trimmed.length === 0 || trimmed.length > 253 || /\s/u.test(trimmed) || !trimmed.includes(".");
|
|
179
|
-
});
|
|
180
|
-
if (invalid.length > 0) {
|
|
181
|
-
throw new Error(`${field} contains invalid hostnames: ${invalid.join(", ")}. Use bare hostnames like github.com.`);
|
|
182
|
-
}
|
|
208
|
+
function normalizeEnum(value, allowed) {
|
|
209
|
+
return normalizeEnumList(value === undefined ? undefined : [value], allowed)[0];
|
|
183
210
|
}
|