dsh-querit 1.0.2 → 1.0.4

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-zh.md CHANGED
@@ -8,16 +8,17 @@ English | [中文](./README-zh.md)
8
8
 
9
9
  ## 快速开始
10
10
 
11
- 1. 按「安装与更新」装包,并按「接线」把两段补丁加进 profile 的 `cordis.patch.yml`。
11
+ 1. 按「安装与更新」装包即可。v1.0.3 起本包以 *profile bundle* 形式发布:`dsh plugin add` 会自动完成接线(注册插件行并路由接缝),无需手改 `cordis.patch.yml`(「接线」一节说明了它具体应用的内容,以及如何覆盖默认值)。v1.0.4 起 bundle 还会自动禁用随包自带的 DeepSeek 搜索行;卸载本包即可还原。
12
12
  2. 按优先级配置 API key:
13
13
  - 启动环境里的 `QUERIT_API_KEY` 环境变量,或
14
14
  - 凭据存储(`$DSH_HOME/.credentials.yaml` 加一行 `QUERIT_API_KEY: <key>`,热加载、无需重启),或
15
+ - 设置页卡片(v1.0.4+:**设置 → 插件 → 插件配置 → Querit 网页搜索**),或
15
16
  - `web-search-querit` 行上的 `apiKey` 字面量(最不推荐,密钥不应进组合文件)。
16
- 3. 重启 profile 加载插件行。
17
+ 3. 重启 profile 加载插件行与设置卡片。
17
18
 
18
19
  插件首次加载时若解析不到 key,宿主日志会打印一条一次性警告;在配置 key 之前发起搜索会失败为 `WEB_PROVIDER_CREDENTIAL_MISSING`,错误信息同样写明了以上三种配置方式。
19
20
 
20
- 当前 harness 版本没有为外部插件提供设置页 UI(web 设置 API 只暴露固定命名空间白名单),所以所有配置都走组合补丁 + 凭据存储。
21
+ v1.0.4 起本包还带浏览器端设置卡片:**设置 → 插件 → 插件配置** 会列出「Querit 网页搜索」卡片,可编辑 `web-search-querit` 命名空间(凭据引用名、结果数量、时间范围、语言、国家、域名列表、内容摘录、抓取格式),并能把 API key 直接写入凭据域。卡片写入走的正是 `$DSH_HOME/settings.yaml` 同一条设置通道(见「配置在哪改」)。
21
22
 
22
23
  ## 安装与更新
23
24
 
@@ -29,6 +30,8 @@ dsh plugin --profile web add dsh-querit
29
30
 
30
31
  (`dsh plugin` 会把参数转发给 profile 目录下的 pnpm;`web` 换成你的 profile 名。)
31
32
 
33
+ 安装还会同步 profile 的 bundle 列表:由于 `dsh-querit` 声明了 `dsh.bundle`,它会自动加入 `dsh.profile.bundles`,随包分发的补丁层会自动注册插件行、完成接缝路由并禁用 DeepSeek 搜索行(条目见「接线」)。装完重启 profile 即生效。`dsh plugin remove dsh-querit` 会移除整层,bundle 做的一切——包括 DeepSeek 禁用——都会自动还原。手动接线只在 1.0.3 之前的版本或需要覆盖 bundle 默认行值时才有必要。
34
+
32
35
  ### 更新
33
36
 
34
37
  ```bash
@@ -53,7 +56,7 @@ dsh plugin --profile web add ./dsh-querit-<版本号>.tgz
53
56
 
54
57
  ## 接线
55
58
 
56
- 编辑 profile 的 `cordis.patch.yml`(`$DSH_HOME/profiles/<profile>/cordis.patch.yml`):
59
+ v1.0.3 起本包以 profile bundle 形式发布,随包补丁层会自动完成以下全部接线。作为参考,它会应用(包内 `cordis.patch.yml`)如下条目:
57
60
 
58
61
  ```yaml
59
62
  # 添加插件行(同时注册 Querit provider 与 web_fetch 工具)
@@ -68,9 +71,13 @@ dsh plugin --profile web add ./dsh-querit-<版本号>.tgz
68
71
  config:
69
72
  searchProvider: querit
70
73
  fetchProvider: querit
74
+
75
+ # 本包就是搜索后端:不再挂载 DeepSeek 搜索行;需要时可覆盖回 disabled: false
76
+ - id: web-search-deepseek
77
+ disabled: true
71
78
  ```
72
79
 
73
- 补丁会**整体替换**目标行的 `config`,所以请把需要的键都写上。API key 可以通过凭据服务、启动环境的 `QUERIT_API_KEY`、或行内 `apiKey` 字面量提供。改完后重启 profile 生效。`web-search-deepseek` 行保留不动即可:接缝按配置的 id 选择 provider,随时可以一行补丁切回官方搜索。若某个 preset 自行注册了 `web_fetch`,请把本行 `fetch` 设为 `false`。
80
+ 这就是全部接线:`web_search`(由 preset 按会话注册)与 `web_fetch`(由本包注册)都经由 `ctx.web`,后者现在选择 Querit。补丁会**整体替换**目标行的 `config`,所以上面 `web` 条目把两个键都写全了。bundle 层位于 base 与 app bundle 之后,因此它的 `web` 覆盖生效;若你的 profile 自己的 `cordis.patch.yml` 或 `--patch` 覆盖层更晚出现并重写该行,则以你为准——这也是切回 DeepSeek 搜索(`searchProvider: deepseek-official`)、重新启用 DeepSeek 行(`disabled: false`)或固定自定义默认值的方式。API key 可以通过凭据服务、启动环境的 `QUERIT_API_KEY`、设置卡片、或行内 `apiKey` 字面量提供;改完重启 profile 生效。若某个 preset 自行注册了 `web_fetch`,请把本行 `fetch` 设为 `false`。
74
81
 
75
82
  ## 配置项
76
83
 
@@ -97,10 +104,11 @@ dsh plugin --profile web add ./dsh-querit-<版本号>.tgz
97
104
 
98
105
  ### 配置在哪改
99
106
 
100
- 当前 harness 版本没有为外部插件提供设置页 UI(web 设置 API 只暴露固定命名空间白名单),所以有两个配置入口:
107
+ 现在有三个配置入口(设置卡片写入其中两个):
101
108
 
102
- 1. **组合补丁**(上面「接线」的 `cordis.patch.yml`)——改完需重启
103
- 2. **设置文档**——`$DSH_HOME/settings.yaml`(与 `.credentials.yaml` 同一个 dsh 目录)。其中 `web-search-querit:` 段落覆盖行配置并**热加载**(设置服务监听该文件,实测无需重启):
109
+ 1. **设置页卡片**(v1.0.4+):**设置 → 插件 → 插件配置 → Querit 网页搜索**。编辑 `web-search-querit` 命名空间,并可把 API key 写入凭据域;保存即生效、无需重启。
110
+ 2. **组合补丁**(上面「接线」的 `cordis.patch.yml`)——改完需重启
111
+ 3. **设置文档**——`$DSH_HOME/settings.yaml`(与 `.credentials.yaml` 同一个 dsh 目录)。其中 `web-search-querit:` 段落覆盖行配置并**热加载**(设置服务监听该文件,实测无需重启)。设置卡片通过设置服务写入的就是这份文档:
104
112
 
105
113
  ```yaml
106
114
  web-search-querit:
@@ -109,7 +117,7 @@ web-search-querit:
109
117
  languages: [english]
110
118
  ```
111
119
 
112
- 每个字段的解析优先级:`settings.yaml` 段落 > `cordis.patch.yml` 行配置 > schema 默认值。API key 单独放 `.credentials.yaml`(或启动环境变量),不放 `settings.yaml`。
120
+ 每个字段的解析优先级:`settings.yaml` 段落(含卡片写入)> `cordis.patch.yml` 行配置 > schema 默认值。API key 单独放 `.credentials.yaml`(或启动环境变量、或卡片的密钥输入框),不放 `settings.yaml`。
113
121
 
114
122
  ## 安全性
115
123
 
package/README.md CHANGED
@@ -8,16 +8,17 @@ Sign up on [Querit.ai](https://www.querit.ai) to get an API key with **1,000 fre
8
8
 
9
9
  ## Quick start
10
10
 
11
- 1. Install the package (see **Install and update** below) and add the two patch blocks from **Wire it up** to your profile's `cordis.patch.yml`.
11
+ 1. Install the package (see **Install and update** below). Since v1.0.3 the package ships as a *profile bundle*: `dsh plugin add` wires the provider row and the seam routing automatically — no `cordis.patch.yml` edits needed (see **Wire it up** for what it applies and how to override). Since v1.0.4 the bundle also disables the shipped DeepSeek search provider row, and removing the package restores it.
12
12
  2. Configure your Querit API key in priority order:
13
13
  - `QUERIT_API_KEY` in the launching environment, or
14
14
  - the credentials store (`$DSH_HOME/.credentials.yaml`: `QUERIT_API_KEY: <key>`, hot-reloaded — no restart needed), or
15
+ - the settings page card (v1.0.4+, **Settings → Plugins → Plugin configuration → Querit web search**), or
15
16
  - `apiKey` on the `web-search-querit` row (a literal; least preferred, secrets should not live in composition files).
16
- 3. Restart the profile to load the plugin row.
17
+ 3. Restart the profile to load the plugin row and its settings card.
17
18
 
18
19
  If the plugin loads without any resolvable key, the host log prints a one-time warning; a search attempted before a key is configured fails with a `WEB_PROVIDER_CREDENTIAL_MISSING` error that spells out the same three options.
19
20
 
20
- There is no settings-page UI for out-of-tree plugins in the current harness version (the web settings API serves a fixed namespace whitelist), so all configuration is the composition patch plus the credentials store.
21
+ Since v1.0.4 the package also ships a browser half with a settings card: **Settings → Plugins → Plugin configuration** lists a "Querit web search" card that edits the `web-search-querit` namespace (credential reference, result count, time range, languages, countries, domain lists, content excerpts, fetch format) and can write the API key straight into the credentials domain. Its writes go through the same settings transport as `$DSH_HOME/settings.yaml` (see **Config**).
21
22
 
22
23
  This is an **implementation** package: it registers one search provider and one fetch provider into `ctx.web`. Per operation, it resolves the API key from the launching environment first, then the optional `ctx.credentials` seam, then literal config. It does not register the model-facing `web_search` tool (the agent preset does); by default, it reuses [`@deepseek-ai/dsh-tool-web`](https://www.npmjs.com/package/@deepseek-ai/dsh-tool-web)'s `applyWebFetchTool` to register `web_fetch`. That last step exists because in the web app the host `tool-web` row is disabled and the shipped presets keep `fetch: false` — this package is the one place that turns page retrieval on. Both providers share the stable id `querit`.
23
24
 
@@ -31,6 +32,8 @@ dsh plugin --profile web add dsh-querit
31
32
 
32
33
  (`dsh plugin` forwards to pnpm in the profile directory; replace `web` with your profile name.)
33
34
 
35
+ Installing also reconciles the profile's bundle list: because `dsh-querit` declares `dsh.bundle`, it automatically joins `dsh.profile.bundles` and its shipped patch layer registers the provider row, routes the seam, and disables the DeepSeek search row (the entries shown in **Wire it up**). After the install completes, restart the profile and the plugin is live. `dsh plugin remove dsh-querit` drops the whole layer, so everything the bundle did — including the DeepSeek disable — reverts to the base behavior automatically. The manual wiring below is only needed for pre-1.0.3 installs or when you override the bundle's default row values.
36
+
34
37
  ### Update
35
38
 
36
39
  ```bash
@@ -55,7 +58,7 @@ Only when pnpm is unavailable: unpack the tarball into `<profile>/node_modules/d
55
58
 
56
59
  ## Wire it up
57
60
 
58
- Edit the profile's `cordis.patch.yml` (`$DSH_HOME/profiles/<profile>/cordis.patch.yml`):
61
+ Since v1.0.3 the package ships as a profile bundle whose patch layer applies all of this automatically. For reference, the entries it applies (kept in the package as `cordis.patch.yml`) are:
59
62
 
60
63
  ```yaml
61
64
  # Add the provider row (registers the Querit providers AND the web_fetch tool).
@@ -70,11 +73,16 @@ Edit the profile's `cordis.patch.yml` (`$DSH_HOME/profiles/<profile>/cordis.patc
70
73
  config:
71
74
  searchProvider: querit
72
75
  fetchProvider: querit
76
+
77
+ # This package IS the search backend: stop mounting the DeepSeek provider row.
78
+ # Re-enable with `disabled: false` in a later layer if you need it back.
79
+ - id: web-search-deepseek
80
+ disabled: true
73
81
  ```
74
82
 
75
- That is the whole wiring: `web_search` (registered per session by the agent preset) and `web_fetch` (registered by this package) both route through `ctx.web`, which now selects Querit. A patch **replaces** the targeted row's whole `config`, so restate every key you need. Store the API key through the credentials service, export `QUERIT_API_KEY` in the launching environment, or set a literal `apiKey` in the row above. Restart the profile to load the new row.
83
+ That is the whole wiring: `web_search` (registered per session by the agent preset) and `web_fetch` (registered by this package) both route through `ctx.web`, which now selects Querit. A patch **replaces** the targeted row's whole `config`, so the `web` entry above restates both keys. The bundle layer applies after the base and app bundles, so its `web` override wins unless your profile's own `cordis.patch.yml` or a `--patch` overlay comes later and restates the row — that is also how you switch back to DeepSeek search (`searchProvider: deepseek-official`), re-enable the DeepSeek row (`disabled: false`), or pin custom defaults. Store the API key through the credentials service, export `QUERIT_API_KEY` in the launching environment, or set a literal `apiKey` in the row above. Restart the profile to load the row.
76
84
 
77
- Keep the DeepSeek provider reachable by leaving the `web-search-deepseek` row in place; the seam selects by the configured id, and switching back is a one-line patch.
85
+ Keep the DeepSeek provider row disabled unless you explicitly need it: since v1.0.4 the bundle ships `disabled: true` on `web-search-deepseek`, so only Querit is mounted. Adding `- id: web-search-deepseek / disabled: false` to a later layer re-enables it while the seam keeps selecting Querit.
78
86
 
79
87
  If a preset ever registers `web_fetch` itself (its `tool-web` row with `fetch: true`), set `fetch: false` on this row so only one registration exists per scope.
80
88
 
@@ -114,10 +122,11 @@ If a preset ever registers `web_fetch` itself (its `tool-web` row with `fetch: t
114
122
 
115
123
  The entry above is the base layer of the `web-search-querit` Settings section: a user layer over it reaches the NEXT operation, because the providers project the section per call rather than capturing it at registration. The seam's provider selection therefore never flickers when a default changes. `apiKey` carries `role('secret')`, so it never rides a `describe()` response — a configuration surface learns only whether the credentials domain holds a value for the reference `apiKeyEnv` names.
116
124
 
117
- There are two configuration surfaces, since the current harness version ships no settings-page UI for out-of-tree plugins (the web settings API serves a fixed namespace whitelist):
125
+ There are three configuration surfaces (the settings-page card writes through two of them):
118
126
 
119
- 1. **The composition patch** (`cordis.patch.yml` above) — needs a restart.
120
- 2. **The settings document** — `$DSH_HOME/settings.yaml`, the same directory as `.credentials.yaml`. A `web-search-querit:` section there overrides the row config and **hot-reloads** (the settings provider watches the file; verified live — no restart needed):
127
+ 1. **The settings page card** (v1.0.4+): **Settings → Plugins → Plugin configuration → Querit web search**. Edits the `web-search-querit` namespace and can write the API key into the credentials domain. No restart needed for saves.
128
+ 2. **The composition patch** (`cordis.patch.yml` above) — needs a restart.
129
+ 3. **The settings document** — `$DSH_HOME/settings.yaml`, the same directory as `.credentials.yaml`. A `web-search-querit:` section there overrides the row config and **hot-reloads** (the settings provider watches the file; verified live — no restart needed). The settings card writes this same document through the settings service:
121
130
 
122
131
  ```yaml
123
132
  web-search-querit:
@@ -126,7 +135,7 @@ web-search-querit:
126
135
  languages: [english]
127
136
  ```
128
137
 
129
- Resolution order per field: `settings.yaml` section > `cordis.patch.yml` row config > schema default. The API key is kept separately in `.credentials.yaml` (or the launching environment), never in `settings.yaml`.
138
+ Resolution order per field: `settings.yaml` section (including card writes) > `cordis.patch.yml` row config > schema default. The API key is kept separately in `.credentials.yaml` (or the launching environment, or the card's write-only key input), never in `settings.yaml`.
130
139
 
131
140
  ## Mapping
132
141
 
@@ -145,10 +154,12 @@ Treat every search result and retrieved page as untrusted external data. The mod
145
154
  ```bash
146
155
  npm install
147
156
  npm run check # typecheck src + tests
148
- npm test # vitest unit tests
149
- npm run build # tsc -> lib/
157
+ npm test # vitest: host providers + settings form model + card render smoke tests
158
+ npm run build # tsc -> lib/ plus the browser bundle -> lib/card.js
150
159
  ```
151
160
 
161
+ The settings card's form logic lives in `src/form-model.js` (unit-tested); `scripts/build-client.mjs` inlines it into the loader-wrapped browser bundle `src/card.js` and writes `lib/card.js`. The bundle deliberately does not overwrite `lib/client.js`, which tsc produces from `src/client.ts` (the host-side HTTP client) — that collision breaks the host imports. `tests/card-render.test.mjs` renders the built card with `react-dom/server` and asserts its controls; run `npm run build` before `npm test`. To exercise the card in the browser, restart the profile and open **Settings → Plugins → Plugin configuration**.
162
+
152
163
  ## Packaging notes
153
164
 
154
165
  The `peerDependencies` are declared **optional**: the harness provides them at runtime (the profile boot resolves them through the flat module fallback under `$DSH_HOME/profiles/node_modules`), not through the profile's own pnpm graph — so `dsh plugin add` finishes without installing peers and prints no peer warnings.
@@ -0,0 +1,25 @@
1
+ # The dsh-querit bundle patch: applied as a profile layer after the base and
2
+ # app bundles, so installing this package wires the Querit providers in
3
+ # automatically — no cordis.patch.yml edits needed. Removing the package
4
+ # (`dsh plugin remove dsh-querit`) drops this whole layer, so every entry
5
+ # below — including the DeepSeek disable — reverts to the base behavior.
6
+ #
7
+ # A patch replaces the targeted row's whole `config`, so the `web` row below
8
+ # restates every key it owns (search + fetch selection).
9
+
10
+ - insert:
11
+ - id: web-search-querit
12
+ name: 'dsh-querit'
13
+ config:
14
+ apiKeyEnv: QUERIT_API_KEY
15
+
16
+ - id: web
17
+ config:
18
+ searchProvider: querit
19
+ fetchProvider: querit
20
+
21
+ # This package IS the search backend: stop mounting the DeepSeek provider row.
22
+ # Override with `- id: web-search-deepseek / disabled: false` in a later layer
23
+ # (profile cordis.patch.yml) to re-enable it while keeping Querit selected.
24
+ - id: web-search-deepseek
25
+ disabled: true
package/lib/card.js ADDED
@@ -0,0 +1,817 @@
1
+ /**
2
+ * dsh-querit browser bundle — Querit settings card.
3
+ *
4
+ * Built by scripts/build-client.mjs into lib/card.js (do not edit the
5
+ * generated file). The browser loader wraps this module; the node-side unit
6
+ * tests cover the form model definitions in src/form-model.js, which this
7
+ * bundle inlines below.
8
+ *
9
+ * Plain JavaScript only: no TS, no JSX, no imports — `require` resolves
10
+ * against the browser module loader, and React comes from the shared kernel.
11
+ */
12
+ (function (root, factory) {
13
+ if (root && typeof root.__ModuleLoader__ === 'object' && typeof root.__ModuleLoader__.load === 'function') {
14
+ root.__ModuleLoader__.load({ id: 'dsh-querit', factory: factory });
15
+ return;
16
+ }
17
+ if (typeof module !== 'undefined' && module.exports) {
18
+ module.exports = factory(require);
19
+ }
20
+ })(typeof window !== 'undefined' ? window : globalThis, function (require) {
21
+ 'use strict';
22
+ var module = { exports: {} };
23
+ var exports = module.exports;
24
+ var React = require('react');
25
+
26
+ /**
27
+ * Pure form model behind the dsh-querit settings card.
28
+ *
29
+ * This file is the SINGLE SOURCE of truth for the card's field conversions and
30
+ * save planning. The browser bundle inlines these exact definitions (see
31
+ * scripts/build-client.mjs); the node-side unit tests import them through the
32
+ * exports at the bottom. Keep everything here free of DOM, React, and window
33
+ * references so both consumers can run it.
34
+ */
35
+
36
+ /**
37
+ * A whole-number field. An empty draft clears the field; any other draft that
38
+ * is not a finite number blocks the save.
39
+ * @param {string} field - field name inside the namespace section.
40
+ * @returns {import('./client-types.js').FieldSpec} the field's conversion spec.
41
+ */
42
+ function numberField(field) {
43
+ return {
44
+ field,
45
+ format: (value) => (typeof value === 'number' ? String(value) : ''),
46
+ parse: (text) => {
47
+ const trimmed = text.trim();
48
+ if (trimmed === '') return { kind: 'clear' };
49
+ const parsed = Number(trimmed);
50
+ return Number.isFinite(parsed)
51
+ ? { kind: 'set', value: parsed }
52
+ : undefined;
53
+ },
54
+ };
55
+ }
56
+
57
+ /**
58
+ * A free-text field. An empty draft clears the field, so emptying the control
59
+ * and saving is the same gesture as resetting it.
60
+ * @param {string} field - field name inside the namespace section.
61
+ * @returns {import('./client-types.js').FieldSpec} the field's conversion spec.
62
+ */
63
+ function textField(field) {
64
+ return {
65
+ field,
66
+ format: (value) => (typeof value === 'string' ? value : ''),
67
+ parse: (text) => {
68
+ const trimmed = text.trim();
69
+ return trimmed === '' ? { kind: 'clear' } : { kind: 'set', value: trimmed };
70
+ },
71
+ };
72
+ }
73
+
74
+ /**
75
+ * A comma-separated list field (string[] ↔ "a, b, c"). An empty draft clears
76
+ * the field; duplicates and blank entries are dropped.
77
+ * @param {string} field - field name inside the namespace section.
78
+ * @returns {import('./client-types.js').FieldSpec} the field's conversion spec.
79
+ */
80
+ function listField(field) {
81
+ return {
82
+ field,
83
+ format: (value) => (Array.isArray(value) ? value.join(', ') : ''),
84
+ parse: (text) => {
85
+ const trimmed = text.trim();
86
+ if (trimmed === '') return { kind: 'clear' };
87
+ const seen = new Set();
88
+ const items = [];
89
+ for (const raw of trimmed.split(',')) {
90
+ const item = raw.trim();
91
+ if (item === '' || seen.has(item)) continue;
92
+ seen.add(item);
93
+ items.push(item);
94
+ }
95
+ return { kind: 'set', value: items };
96
+ },
97
+ };
98
+ }
99
+
100
+ /**
101
+ * A boolean toggle field. It always writes a value; there is no "clear".
102
+ * @param {string} field - field name inside the namespace section.
103
+ * @returns {import('./client-types.js').FieldSpec} the field's conversion spec.
104
+ */
105
+ function booleanField(field) {
106
+ return {
107
+ field,
108
+ format: (value) => (typeof value === 'boolean' ? String(value) : 'false'),
109
+ parse: (text) => ({ kind: 'set', value: text === 'true' }),
110
+ choices: ['true', 'false'],
111
+ };
112
+ }
113
+
114
+ /**
115
+ * A single-choice field over a fixed set of strings.
116
+ * @param {string} field - field name inside the namespace section.
117
+ * @param {readonly string[]} choices - acceptable values.
118
+ * @returns {import('./client-types.js').FieldSpec} the field's conversion spec.
119
+ */
120
+ function enumField(field, choices) {
121
+ return {
122
+ field,
123
+ format: (value) => (typeof value === 'string' && choices.includes(value) ? value : ''),
124
+ parse: (text) => {
125
+ const trimmed = text.trim();
126
+ if (trimmed === '') return { kind: 'clear' };
127
+ return choices.includes(trimmed) ? { kind: 'set', value: trimmed } : undefined;
128
+ },
129
+ choices,
130
+ };
131
+ }
132
+
133
+ /**
134
+ * A write-only control staged outside the settings section (the API key is
135
+ * stored in the credentials domain, never in the settings document).
136
+ * @param {string} field - field name this control stages under.
137
+ * @param {(value: string) => Promise<boolean>} write - persist the literal.
138
+ * @returns {import('./client-types.js').SecretSpec} the secret's spec.
139
+ */
140
+ function secretSpec(field, write) {
141
+ return { field, write };
142
+ }
143
+
144
+ /**
145
+ * The staged form model one settings card runs on.
146
+ *
147
+ * A card stages what the user types and writes it only when they save. Each
148
+ * settings write is a durable, revision-fenced document mutation, so nothing
149
+ * commits as the user types. A field shows its effective value — the user
150
+ * layer over the composition layer over the schema default — and whether the
151
+ * user layer carries it; that presence, not a value comparison, is what marks
152
+ * a field overridden.
153
+ */
154
+ class QueritFormModel {
155
+ /** @param {import('./client-types.js').SettingsScope} scope - bound settings scope for the namespace. */
156
+ constructor(scope, specs, secrets = []) {
157
+ this.scope = scope;
158
+ this.specs = new Map(specs.map((spec) => [spec.field, spec]));
159
+ this.secretSpecs = new Map(secrets.map((spec) => [spec.field, spec]));
160
+ this.staged = new Map();
161
+ this.listeners = new Set();
162
+ this.saving = false;
163
+ this.failed = false;
164
+ scope.subscribe(() => this.publish());
165
+ }
166
+
167
+ /**
168
+ * Publish a projection of this form rebuilt whenever the scope or a draft
169
+ * changes.
170
+ * @param {() => object} project - build the card's state from the form reads.
171
+ * @returns {import('./client-types.js').SnapshotStore} the store the component reads.
172
+ */
173
+ bind(project) {
174
+ const store = makeStore(project());
175
+ this.listeners.add(() => {
176
+ store.set(project());
177
+ });
178
+ return store;
179
+ }
180
+
181
+ /** Read the card-level state: what the Host serves, and what a save would do. */
182
+ shell() {
183
+ const snapshot = this.scope.getSnapshot();
184
+ const plan = this.plan();
185
+ return {
186
+ available: snapshot.status === 'ready',
187
+ writable: snapshot.writable === true,
188
+ dirty: plan.length > 0,
189
+ invalid: plan.some((item) => item.run === undefined),
190
+ saving: this.saving,
191
+ failed: this.failed,
192
+ };
193
+ }
194
+
195
+ /** Read one control's state. */
196
+ field(field) {
197
+ const staged = this.staged.get(field);
198
+ if (this.secretSpecs.has(field)) {
199
+ return { text: staged?.text ?? '', overridden: false, invalid: false };
200
+ }
201
+ const spec = this.spec(field);
202
+ if (staged === undefined) {
203
+ return {
204
+ text: spec.format(this.sectionValue(field)),
205
+ overridden: this.stored(field),
206
+ invalid: false,
207
+ };
208
+ }
209
+ const write = staged.clear ? { kind: 'clear' } : spec.parse(staged.text);
210
+ return {
211
+ text: staged.text,
212
+ overridden: write?.kind === 'set',
213
+ invalid: write === undefined,
214
+ };
215
+ }
216
+
217
+ /** The actions a card's slot entry injects. */
218
+ actions() {
219
+ return {
220
+ edit: (field, text) => {
221
+ this.stage(field, { text, clear: false });
222
+ },
223
+ resetField: (field) => {
224
+ if (this.secretSpecs.has(field)) return;
225
+ this.stage(field, { text: this.spec(field).format(this.baseValue(field)), clear: true });
226
+ },
227
+ save: () => {
228
+ return this.save();
229
+ },
230
+ discard: () => {
231
+ if (this.staged.size === 0 && !this.failed) return;
232
+ this.staged.clear();
233
+ this.failed = false;
234
+ this.publish();
235
+ },
236
+ };
237
+ }
238
+
239
+ /**
240
+ * Write every staged edit, then re-seed from what the Host accepted. The Host
241
+ * is the only authority on whether a value was accepted, so the outcome is
242
+ * read back from the scope rather than predicted here.
243
+ */
244
+ async save() {
245
+ const plan = this.plan();
246
+ const writes = plan.flatMap((item) => (item.run === undefined ? [] : [item.run]));
247
+ if (plan.length === 0 || this.saving || writes.length !== plan.length) return;
248
+ this.saving = true;
249
+ this.failed = false;
250
+ this.publish();
251
+ let landed = true;
252
+ for (const write of writes) landed = (await write()) && landed;
253
+ if (landed) this.staged.clear();
254
+ this.saving = false;
255
+ this.failed = !landed;
256
+ this.publish();
257
+ }
258
+
259
+ /** Every staged edit a save would write, in the order the fields were staged. */
260
+ plan() {
261
+ const plan = [];
262
+ for (const [field, staged] of this.staged) {
263
+ const secret = this.secretSpecs.get(field);
264
+ if (secret !== undefined) {
265
+ const value = staged.text.trim();
266
+ if (value !== '') {
267
+ plan.push({ field, run: () => secret.write(value).then((ok) => !!ok) });
268
+ }
269
+ continue;
270
+ }
271
+ const spec = this.spec(field);
272
+ if (staged.clear) {
273
+ if (this.stored(field)) plan.push({ field, run: () => this.clear(field) });
274
+ continue;
275
+ }
276
+ if (staged.text === spec.format(this.sectionValue(field))) continue;
277
+ const write = spec.parse(staged.text);
278
+ if (write === undefined) plan.push({ field, run: undefined });
279
+ else if (write.kind === 'clear') plan.push({ field, run: () => this.clear(field) });
280
+ else plan.push({ field, run: () => this.store(field, write.value) });
281
+ }
282
+ return plan;
283
+ }
284
+
285
+ stage(field, draft) {
286
+ this.staged.set(field, draft);
287
+ this.publish();
288
+ }
289
+
290
+ publish() {
291
+ for (const listener of this.listeners) listener();
292
+ }
293
+
294
+ spec(field) {
295
+ const spec = this.specs.get(field);
296
+ if (spec === undefined) throw new Error(`querit card: unknown field "${field}"`);
297
+ return spec;
298
+ }
299
+
300
+ sectionValue(field) {
301
+ return this.scope.getSnapshot().value?.[field];
302
+ }
303
+
304
+ stored(field) {
305
+ const user = this.scope.getSnapshot().user;
306
+ return typeof user === 'object' && user !== null && Object.prototype.hasOwnProperty.call(user, field);
307
+ }
308
+
309
+ baseValue(field) {
310
+ return this.scope.getSnapshot().base?.[field];
311
+ }
312
+
313
+ clear(field) {
314
+ return this.scope.unset(field);
315
+ }
316
+
317
+ store(field, value) {
318
+ return this.scope.set(field, value);
319
+ }
320
+ }
321
+
322
+ /** Minimal snapshot store: stable state object, getSnapshot, subscribe, set. */
323
+ function makeStore(initial) {
324
+ let state = initial;
325
+ const listeners = new Set();
326
+ return {
327
+ getSnapshot: () => state,
328
+ subscribe: (listener) => {
329
+ listeners.add(listener);
330
+ return () => listeners.delete(listener);
331
+ },
332
+ set: (next) => {
333
+ state = next;
334
+ for (const listener of listeners) listener();
335
+ },
336
+ };
337
+ }
338
+
339
+ var NS = 'dsh-querit';
340
+ var NAMESPACE = 'web-search-querit';
341
+ var DEFAULT_API_KEY_REF = 'QUERIT_API_KEY';
342
+ var FETCH_FORMATS = ['markdown', 'text', 'html'];
343
+
344
+ /* Card styles: scoped classes over the theme's alias tokens. */
345
+ (function injectCardCss() {
346
+ if (typeof document === 'undefined') return;
347
+ var tagId = NS + '/card.css';
348
+ if (document.querySelector('style[data-plugin-css="' + tagId + '"]') !== null) return;
349
+ var css = [
350
+ '.qr-card{list-style:none;border:1px solid var(--dsw-alias-border-l2);border-radius:12px;background:var(--dsw-alias-bg-layer-2)}',
351
+ '.qr-header{display:flex;align-items:center;gap:8px;width:100%;padding:12px 16px;background:none;border:0;cursor:pointer;color:inherit;font:inherit;text-align:left}',
352
+ '.qr-head{flex:1;min-width:0}',
353
+ '.qr-name{display:block;color:var(--dsw-alias-label-primary);font-size:14px;font-weight:600;line-height:1.5}',
354
+ '.qr-desc{display:block;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:1.5}',
355
+ '.qr-badge{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;line-height:17px}',
356
+ '.qr-chev{color:var(--dsw-alias-label-tertiary);font-size:14px;line-height:1}',
357
+ '.qr-body{border-top:1px solid var(--dsw-alias-border-l2);padding:0 16px 12px}',
358
+ '.qr-readonly{color:var(--dsw-alias-label-tertiary);margin:8px 0 0;font-size:12px}',
359
+ '.qr-field{display:flex;flex-direction:column;gap:6px;padding:12px 0;border-bottom:1px solid var(--dsw-alias-border-l1)}',
360
+ '.qr-field:last-child{border-bottom:0}',
361
+ '.qr-fhead{display:flex;align-items:center;gap:8px}',
362
+ '.qr-grow{flex:1}',
363
+ '.qr-label{flex:1;min-width:0;color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:1.5}',
364
+ '.qr-tag{white-space:nowrap;color:var(--dsw-alias-label-tertiary);border-radius:999px;padding:1px 8px;font-size:11px;line-height:17px}',
365
+ '.qr-tagOver{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;line-height:17px}',
366
+ '.qr-reset{font:inherit;color:var(--dsw-alias-label-secondary);cursor:pointer;background:none;border:none;padding:0;font-size:12px;line-height:1.5}',
367
+ '.qr-reset:hover:not(:disabled){color:var(--dsw-alias-label-primary)}',
368
+ '.qr-reset:disabled{cursor:default}',
369
+ '.qr-input{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;line-height:1.5;box-sizing:border-box}',
370
+ '.qr-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}',
371
+ '.qr-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}',
372
+ '.qr-check{width:16px;height:16px;accent-color:var(--dsw-alias-brand-primary);cursor:pointer;flex:none}',
373
+ '.qr-check:disabled{cursor:default}',
374
+ '.qr-invalid{border-color:var(--dsw-alias-label-error)}',
375
+ '.qr-err{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}',
376
+ '.qr-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}',
377
+ '.qr-keybadge{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.5}',
378
+ '.qr-foot{display:flex;align-items:center;justify-content:flex-end;gap:8px;padding-top:12px}',
379
+ '.qr-failed{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5;flex:1}',
380
+ '.qr-btn{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);border-radius:8px;padding:6px 14px;font:inherit;font-size:13px;cursor:pointer}',
381
+ '.qr-btn:hover:not(:disabled){border-color:var(--dsw-alias-label-secondary)}',
382
+ '.qr-save{border-color:var(--dsw-alias-brand-primary);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font-weight:600}',
383
+ '.qr-btn:disabled{opacity:.5;cursor:default}'
384
+ ].join('');
385
+ var tag = document.createElement('style');
386
+ tag.dataset.plugin = NS;
387
+ tag.dataset.pluginCss = tagId;
388
+ tag.textContent = css;
389
+ document.head.appendChild(tag);
390
+ })();
391
+
392
+ var en = {
393
+ title: 'Querit web search',
394
+ description: 'Querit-backed search and fetch provider.',
395
+ readOnly: 'This deployment stores settings read-only.',
396
+ pass: 'Password',
397
+ save: 'Save',
398
+ saving: 'Saving\u2026',
399
+ discard: 'Discard',
400
+ unsaved: 'Unsaved',
401
+ overridden: 'Overridden',
402
+ reset: 'Reset to default',
403
+ saveFailed: 'The deployment did not accept these values; they were left for you to correct.',
404
+ invalidNumber: 'Enter a number, or leave blank to use the default.',
405
+ keyLabel: 'API key',
406
+ keyHint: 'Stored outside the settings file. Leave blank to keep the current key.',
407
+ keySet: 'A key is configured for',
408
+ keyUnset: 'No key is configured; search fails until one is set via the credentials file or here.',
409
+ refLabel: 'Credential reference',
410
+ refHint: 'Environment variable / credentials-store name the provider resolves per call.',
411
+ countLabel: 'Result count',
412
+ countHint: 'Results per search when no explicit bound is given (1\u201320).',
413
+ timeRangeLabel: 'Time range',
414
+ timeRangeHint: 'Relative (d7, w2, m3, y1, \u2026) or YYYY-MM-DDtoYYYY-MM-DD.',
415
+ languagesLabel: 'Languages',
416
+ languagesHint: 'Comma-separated: english, japanese, korean, german, french, spanish, portuguese.',
417
+ countriesLabel: 'Countries',
418
+ countriesHint: 'Comma-separated country bias (argentina, australia, brazil, \u2026).',
419
+ includeLabel: 'Include domains',
420
+ includeHint: 'Whitelist hostnames; only these domains return results.',
421
+ excludeLabel: 'Exclude domains',
422
+ excludeHint: 'Blacklist hostnames; these domains never return results.',
423
+ contentLabel: 'Include content excerpts',
424
+ contentHint: 'Request sentence-level content excerpts alongside snippets.',
425
+ formatLabel: 'Fetch format',
426
+ formatHint: 'Format requested from /v1/contents for fetch calls.'
427
+ };
428
+ var zh = {
429
+ title: 'Querit 网页搜索',
430
+ description: '基于 Querit 的搜索与抓取提供方。',
431
+ readOnly: '本部署的设置为只读。',
432
+ pass: '密码',
433
+ save: '保存',
434
+ saving: '保存中\u2026',
435
+ discard: '放弃修改',
436
+ unsaved: '未保存',
437
+ overridden: '已覆盖',
438
+ reset: '恢复默认',
439
+ saveFailed: '本部署没有接受这些值,已保留供你修改。',
440
+ invalidNumber: '请填数字;留空表示使用默认值。',
441
+ keyLabel: 'API Key',
442
+ keyHint: '不写入设置文件。留空表示保持当前密钥。',
443
+ keySet: '已为',
444
+ keyUnset: '未配置密钥;请在凭据文件或此处配置后搜索才可用。',
445
+ refLabel: '凭据引用名',
446
+ refHint: '每次调用解析的环境变量 / 凭据存储键名。',
447
+ countLabel: '结果数量',
448
+ countHint: '未指定上限时每次搜索返回的结果数(1–20)。',
449
+ timeRangeLabel: '时间范围',
450
+ timeRangeHint: '相对(d7、w2、m3、y1…)或 YYYY-MM-DDtoYYYY-MM-DD。',
451
+ languagesLabel: '语言',
452
+ languagesHint: '逗号分隔:english、japanese、korean、german、french、spanish、portuguese。',
453
+ countriesLabel: '国家',
454
+ countriesHint: '逗号分隔的国家偏好(argentina、australia、brazil…)。',
455
+ includeLabel: '仅限域名',
456
+ includeHint: '白名单主机名;只返回这些域的结果。',
457
+ excludeLabel: '排除域名',
458
+ excludeHint: '黑名单主机名;这些域永不返回结果。',
459
+ contentLabel: '包含内容摘要',
460
+ contentHint: '在摘要旁请求句子级内容摘录。',
461
+ formatLabel: '抓取格式',
462
+ formatHint: '/v1/contents 抓取请求的格式。'
463
+ };
464
+
465
+ /** The credential reference the section names, or the provider default. */
466
+ function refOf(snapshot) {
467
+ var declared = snapshot.value && snapshot.value.apiKeyEnv;
468
+ return declared !== undefined && declared.length > 0 ? declared : DEFAULT_API_KEY_REF;
469
+ }
470
+
471
+ /** Bridges the web-search-querit scope and the credentials domain onto the card. */
472
+ function QueritCardController(scope, api) {
473
+ this.scope = scope;
474
+ this.api = api;
475
+ this.credential = { ref: '', configured: false, writable: true };
476
+ this.form = new QueritFormModel(
477
+ scope,
478
+ [
479
+ textField('apiKeyEnv'),
480
+ numberField('count'),
481
+ textField('timeRange'),
482
+ listField('languages'),
483
+ listField('countries'),
484
+ listField('includeDomains'),
485
+ listField('excludeDomains'),
486
+ booleanField('includeContent'),
487
+ enumField('fetchFormat', FETCH_FORMATS)
488
+ ],
489
+ [secretSpec('apiKey', (value) => this.writeKey(value))]
490
+ );
491
+ this.store = this.form.bind(() => this.projection());
492
+ var self = this;
493
+ scope.subscribe(() => {
494
+ self.readCredential();
495
+ });
496
+ this.readCredential();
497
+ }
498
+
499
+ QueritCardController.prototype.projection = function () {
500
+ return {
501
+ ...this.form.shell(),
502
+ apiKeyEnv: this.form.field('apiKeyEnv'),
503
+ count: this.form.field('count'),
504
+ timeRange: this.form.field('timeRange'),
505
+ languages: this.form.field('languages'),
506
+ countries: this.form.field('countries'),
507
+ includeDomains: this.form.field('includeDomains'),
508
+ excludeDomains: this.form.field('excludeDomains'),
509
+ includeContent: this.form.field('includeContent'),
510
+ fetchFormat: this.form.field('fetchFormat'),
511
+ apiKey: this.form.field('apiKey'),
512
+ apiKeyConfigured: this.credential.configured,
513
+ apiKeyWritable: this.credential.writable,
514
+ apiKeyRef: this.credential.ref
515
+ };
516
+ };
517
+
518
+ QueritCardController.prototype.readCredential = function () {
519
+ var self = this;
520
+ var ref = refOf(this.scope.getSnapshot());
521
+ if (ref !== this.credential.ref) {
522
+ this.credential = { ref: ref, configured: false, writable: true };
523
+ this.store.set(this.projection());
524
+ }
525
+ this.api.credentials
526
+ .describe({ refs: [ref] })
527
+ .then(function (response) {
528
+ if (!response || !response.result || !response.result.ok) return;
529
+ if (ref !== refOf(self.scope.getSnapshot())) return;
530
+ var view = response.result.value.credentials[ref];
531
+ var next = {
532
+ ref: ref,
533
+ configured: view && view.configured === true,
534
+ writable: !view || view.writable !== false
535
+ };
536
+ if (next.configured === self.credential.configured && next.writable === self.credential.writable) return;
537
+ self.credential = next;
538
+ self.store.set(self.projection());
539
+ })
540
+ .catch(function () {});
541
+ };
542
+
543
+ QueritCardController.prototype.refreshCredential = function (ref) {
544
+ if (ref !== this.credential.ref) return;
545
+ this.readCredential();
546
+ };
547
+
548
+ QueritCardController.prototype.writeKey = function (value) {
549
+ var self = this;
550
+ return this.api.credentials
551
+ .set({ ref: refOf(this.scope.getSnapshot()), value: value })
552
+ .then(function () {
553
+ return self.readCredential();
554
+ })
555
+ .catch(function () {
556
+ return self.readCredential();
557
+ })
558
+ .then(function () {
559
+ return self.credential.configured;
560
+ });
561
+ };
562
+
563
+ QueritCardController.prototype.inject = function () {
564
+ return {
565
+ hooks: { queritCard: this.store },
566
+ ...this.form.actions()
567
+ };
568
+ };
569
+
570
+ /** One labeled control row. `inline` puts the control on the label line (toggle rows). */
571
+ function FieldRow(props) {
572
+ var inline = props.inline === true;
573
+ return React.createElement(
574
+ 'div',
575
+ { className: 'qr-field' },
576
+ React.createElement(
577
+ 'div',
578
+ { className: 'qr-fhead' },
579
+ React.createElement('span', { className: 'qr-label' }, props.label),
580
+ props.state && props.state.overridden
581
+ ? React.createElement('span', { className: 'qr-tagOver' }, props.overriddenLabel)
582
+ : null,
583
+ props.state && props.onReset
584
+ ? React.createElement(
585
+ 'button',
586
+ { type: 'button', className: 'qr-reset', disabled: props.disabled || !props.state.overridden, onClick: props.onReset },
587
+ props.resetLabel
588
+ )
589
+ : null,
590
+ inline ? React.createElement('span', { className: 'qr-grow' }) : null,
591
+ inline ? props.children : null
592
+ ),
593
+ inline ? null : props.children,
594
+ props.state && props.state.invalid ? React.createElement('p', { className: 'qr-err' }, props.invalidLabel) : null,
595
+ props.hint ? React.createElement('p', { className: 'qr-hint' }, props.hint) : null
596
+ );
597
+ }
598
+
599
+ /** Render one plugin card: header naming the provider, disclosing its controls in place. */
600
+ function QueritCard(props) {
601
+ var t = props.t || function (key) {
602
+ return zh[key] || en[key] || key;
603
+ };
604
+ var state = props.useQueritCard(function (snapshot) {
605
+ return snapshot;
606
+ });
607
+ var openState = React.useState(props.defaultOpen === true);
608
+ var open = openState[0];
609
+ var setOpen = openState[1];
610
+ if (!state.available) return null;
611
+ var disabled = !state.writable;
612
+ var blocked = !state.dirty || state.invalid || state.saving;
613
+ var text = function (control) {
614
+ return control.text;
615
+ };
616
+ return React.createElement(
617
+ 'li',
618
+ { className: 'qr-card' + (open ? ' qr-open' : '') },
619
+ React.createElement(
620
+ 'button',
621
+ { type: 'button', className: 'qr-header', 'aria-expanded': open ? 'true' : 'false', onClick: function () { setOpen(!open); } },
622
+ React.createElement(
623
+ 'span',
624
+ { className: 'qr-head' },
625
+ React.createElement('span', { className: 'qr-name' }, t('title')),
626
+ React.createElement('span', { className: 'qr-desc' }, t('description'))
627
+ ),
628
+ state.dirty ? React.createElement('span', { className: 'qr-badge' }, t('unsaved')) : null,
629
+ React.createElement('span', { className: 'qr-chev' }, open ? '\u2212' : '+')
630
+ ),
631
+ open
632
+ ? React.createElement(
633
+ 'div',
634
+ { className: 'qr-body' },
635
+ disabled ? React.createElement('p', { className: 'qr-readonly' }, t('readOnly')) : null,
636
+ React.createElement(
637
+ FieldRow,
638
+ {
639
+ label: t('keyLabel'),
640
+ hint: t('keyHint'),
641
+ state: state.apiKey,
642
+ disabled: disabled || !state.apiKeyWritable,
643
+ invalidLabel: t('invalidNumber')
644
+ },
645
+ React.createElement('input', {
646
+ className: 'qr-input',
647
+ type: 'password',
648
+ autoComplete: 'new-password',
649
+ disabled: disabled || !state.apiKeyWritable,
650
+ placeholder: state.apiKeyConfigured ? '\u2022\u2022\u2022\u2022\u2022\u2022' : '',
651
+ value: text(state.apiKey),
652
+ onChange: function (event) { props.edit('apiKey', event.target.value); }
653
+ })
654
+ ),
655
+ React.createElement(
656
+ 'p',
657
+ { className: 'qr-keybadge' },
658
+ state.apiKeyConfigured ? t('keySet') + ' ' + state.apiKeyRef + '.' : t('keyUnset')
659
+ ),
660
+ field(
661
+ props,
662
+ t('refLabel'),
663
+ t('refHint'),
664
+ state.apiKeyEnv,
665
+ 'apiKeyEnv',
666
+ disabled
667
+ ),
668
+ field(props, t('countLabel'), t('countHint'), state.count, 'count', disabled),
669
+ field(props, t('timeRangeLabel'), t('timeRangeHint'), state.timeRange, 'timeRange', disabled),
670
+ field(props, t('languagesLabel'), t('languagesHint'), state.languages, 'languages', disabled),
671
+ field(props, t('countriesLabel'), t('countriesHint'), state.countries, 'countries', disabled),
672
+ field(props, t('includeLabel'), t('includeHint'), state.includeDomains, 'includeDomains', disabled),
673
+ field(props, t('excludeLabel'), t('excludeHint'), state.excludeDomains, 'excludeDomains', disabled),
674
+ React.createElement(
675
+ FieldRow,
676
+ {
677
+ label: t('contentLabel'),
678
+ hint: t('contentHint'),
679
+ state: state.includeContent,
680
+ disabled: disabled,
681
+ inline: true,
682
+ overriddenLabel: t('overridden'),
683
+ resetLabel: t('reset'),
684
+ onReset: function () { props.resetField('includeContent'); }
685
+ },
686
+ React.createElement('input', {
687
+ className: 'qr-check',
688
+ type: 'checkbox',
689
+ disabled: disabled,
690
+ checked: state.includeContent.text === 'true',
691
+ onChange: function (event) { props.edit('includeContent', event.target.checked ? 'true' : 'false'); }
692
+ })
693
+ ),
694
+ React.createElement(
695
+ FieldRow,
696
+ {
697
+ label: t('formatLabel'),
698
+ hint: t('formatHint'),
699
+ state: state.fetchFormat,
700
+ disabled: disabled,
701
+ overriddenLabel: t('overridden'),
702
+ resetLabel: t('reset'),
703
+ onReset: function () { props.resetField('fetchFormat'); }
704
+ },
705
+ React.createElement(
706
+ 'select',
707
+ {
708
+ className: 'qr-input',
709
+ disabled: disabled,
710
+ value: text(state.fetchFormat),
711
+ onChange: function (event) { props.edit('fetchFormat', event.target.value); }
712
+ },
713
+ FETCH_FORMATS.map(function (format) {
714
+ return React.createElement('option', { key: format, value: format }, format);
715
+ })
716
+ )
717
+ ),
718
+ React.createElement(
719
+ 'div',
720
+ { className: 'qr-foot' },
721
+ state.failed ? React.createElement('p', { className: 'qr-failed' }, t('saveFailed')) : null,
722
+ React.createElement(
723
+ 'button',
724
+ { type: 'button', className: 'qr-btn', disabled: (!state.dirty && !state.failed) || state.saving, onClick: props.discard },
725
+ t('discard')
726
+ ),
727
+ React.createElement(
728
+ 'button',
729
+ { type: 'button', className: 'qr-btn qr-save', disabled: blocked, onClick: props.save },
730
+ t(state.saving ? 'saving' : 'save')
731
+ )
732
+ )
733
+ )
734
+ : null
735
+ );
736
+ }
737
+
738
+ /** Extract one section field's row into a shared control render. */
739
+ function field(props, label, hint, state, name, disabled) {
740
+ return React.createElement(
741
+ FieldRow,
742
+ {
743
+ label: label,
744
+ hint: hint,
745
+ state: state,
746
+ disabled: disabled,
747
+ invalidLabel: name === 'count' ? props.t('invalidNumber') : '',
748
+ overriddenLabel: props.t('overridden'),
749
+ resetLabel: props.t('reset'),
750
+ onReset: function () { props.resetField(name); }
751
+ },
752
+ React.createElement('input', {
753
+ className: 'qr-input' + (state.invalid ? ' qr-invalid' : ''),
754
+ type: name === 'count' ? 'number' : 'text',
755
+ disabled: disabled,
756
+ value: state.text,
757
+ onChange: function (event) { props.edit(name, event.target.value); }
758
+ })
759
+ );
760
+ }
761
+
762
+ /** Required services (cordis fiber inject). */
763
+ var inject = ['slots', 'connection', 'settingsScope', 'remote', 'locale'];
764
+
765
+ /**
766
+ * Mount the Querit settings card into the plugins configuration tab.
767
+ * @param ctx - the browser plugin context.
768
+ */
769
+ function apply(ctx) {
770
+ var slots = ctx.get('slots');
771
+ var scopeService = ctx.get('settingsScope');
772
+ var locale = ctx.get('locale');
773
+ var api = ctx.get('connection');
774
+ if (slots === undefined || scopeService === undefined || locale === undefined || api === undefined) return;
775
+ api = api.api;
776
+ // Register the card dictionaries, then bind our own translator. The slot
777
+ // framework may also deliver a `t` seat from the entry's `locale` option,
778
+ // but binding here guarantees text resolves even if that seat is not yet
779
+ // backed for this entry.
780
+ var dicts = { zh: zh, en: en };
781
+ ctx.effect(function () {
782
+ return locale.register(NS, dicts);
783
+ }, 'dsh-querit: card dictionaries');
784
+ var t = locale.bind(NS);
785
+ var scope = scopeService.bind({ namespace: NAMESPACE });
786
+ var controller = new QueritCardController(scope, api);
787
+ var remote = ctx.get('remote');
788
+ if (remote !== undefined) {
789
+ ctx.effect(function () {
790
+ return remote.$on('credentials/updated', function (ref) {
791
+ controller.refreshCredential(ref);
792
+ });
793
+ }, 'dsh-querit: credential invalidations');
794
+ }
795
+ slots.inject('settings.plugin.item', function () {
796
+ return slots.register(
797
+ {
798
+ name: 'settings.plugin.item',
799
+ key: NAMESPACE,
800
+ locale: NS,
801
+ inject: function () {
802
+ var face = controller.inject();
803
+ face.t = t;
804
+ return face;
805
+ }
806
+ },
807
+ QueritCard
808
+ );
809
+ });
810
+ }
811
+
812
+ exports.apply = apply;
813
+ exports.inject = inject;
814
+ exports.QueritCardController = QueritCardController;
815
+ exports.QueritCard = QueritCard;
816
+ return module.exports;
817
+ });
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": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -14,15 +14,33 @@
14
14
  "types": "./lib/invariant.d.ts",
15
15
  "default": "./lib/invariant.js"
16
16
  },
17
+ "./client": {
18
+ "default": "./lib/card.js"
19
+ },
17
20
  "./package.json": "./package.json"
18
21
  },
19
22
  "files": [
20
23
  "lib",
24
+ "cordis.patch.yml",
21
25
  "README.md",
22
26
  "README-zh.md",
23
27
  "LICENSE"
24
28
  ],
25
29
  "license": "MIT",
30
+ "dsh": {
31
+ "bundle": {
32
+ "patch": "./cordis.patch.yml"
33
+ },
34
+ "client": {
35
+ "platform": "web",
36
+ "inject": [
37
+ "@deepseek-ai/dsh-client-connection",
38
+ "@deepseek-ai/dsh-client-locale",
39
+ "@deepseek-ai/dsh-client-ui-settings",
40
+ "@deepseek-ai/dsh-api-remotes"
41
+ ]
42
+ }
43
+ },
26
44
  "repository": {
27
45
  "type": "git",
28
46
  "url": "git+https://github.com/querit-ai/querit-plugins.git"
@@ -39,19 +57,24 @@
39
57
  ],
40
58
  "scripts": {
41
59
  "check": "tsc -p tsconfig.check.json",
42
- "build": "tsc -p tsconfig.json",
60
+ "build": "tsc -p tsconfig.json && node scripts/build-client.mjs",
43
61
  "test": "vitest run tests",
44
62
  "pack:check": "npm pack --dry-run",
45
63
  "prepack": "npm run check && npm test && npm run build"
46
64
  },
47
65
  "peerDependencies": {
48
66
  "@deepseek-ai/cordis": "^4.0.1",
67
+ "@deepseek-ai/dsh-api-remotes": "^0.1.0-rc.6",
68
+ "@deepseek-ai/dsh-client-connection": "^0.1.0-rc.6",
69
+ "@deepseek-ai/dsh-client-locale": "^0.1.0-rc.6",
70
+ "@deepseek-ai/dsh-client-ui-settings": "^0.1.0-rc.6",
49
71
  "@deepseek-ai/dsh-credentials": "^0.1.0-rc.6",
50
72
  "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
51
73
  "@deepseek-ai/dsh-launch-environment": "^0.1.0-rc.6",
52
74
  "@deepseek-ai/dsh-settings": "^0.1.0-rc.6",
53
75
  "@deepseek-ai/dsh-tool-web": "^0.1.0-rc.6",
54
- "@deepseek-ai/dsh-web": "^0.1.0-rc.6"
76
+ "@deepseek-ai/dsh-web": "^0.1.0-rc.6",
77
+ "react": "^18.2.0"
55
78
  },
56
79
  "peerDependenciesMeta": {
57
80
  "@deepseek-ai/cordis": {
@@ -74,6 +97,21 @@
74
97
  },
75
98
  "@deepseek-ai/dsh-web": {
76
99
  "optional": true
100
+ },
101
+ "@deepseek-ai/dsh-api-remotes": {
102
+ "optional": true
103
+ },
104
+ "@deepseek-ai/dsh-client-connection": {
105
+ "optional": true
106
+ },
107
+ "@deepseek-ai/dsh-client-locale": {
108
+ "optional": true
109
+ },
110
+ "@deepseek-ai/dsh-client-ui-settings": {
111
+ "optional": true
112
+ },
113
+ "react": {
114
+ "optional": true
77
115
  }
78
116
  },
79
117
  "dependencies": {
@@ -88,6 +126,8 @@
88
126
  "@deepseek-ai/dsh-tool-web": "^0.1.0-rc.6",
89
127
  "@deepseek-ai/dsh-web": "^0.1.0-rc.6",
90
128
  "@types/node": "^22.0.0",
129
+ "react": "^18.2.0",
130
+ "react-dom": "^18.3.1",
91
131
  "typescript": "^5.9.0",
92
132
  "vitest": "^4.0.0"
93
133
  },