dsh-mineru 0.1.12 → 0.1.13

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/CHANGELOG.md CHANGED
@@ -4,7 +4,25 @@ All notable changes to **dsh-mineru** are documented here. The format follows [K
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
- - No changes yet (latest release is 0.1.12).
7
+ - No changes yet (latest release is 0.1.13).
8
+
9
+ ## [0.1.13] - 2026-09-25
10
+
11
+ ### Fixed
12
+
13
+ - Fix total plugin failure on DSH 2.x: `ctx.settings.register` was removed from the settings service, so `apply()` threw `TypeError: ctx.settings.register is not a function` on its first statement and the entry never activated. Nothing was registered — no `mineru_*` tools, no `mineru-tools` skill, no `/plugin/mineru` routes — while the client half still mounted, so the settings card failed with `Failed to execute 'json' on 'Response': Unexpected end of JSON input` (the host answers an unmounted route with `404` and an empty body). The card is now derived from the exported `CONFIG_SCHEMA` the way DSH 2.x expects it.
14
+
15
+ ### Changed
16
+
17
+ - Every `CONFIG_SCHEMA` field is marked live through the new `live()` helper, which prefers `.volatile()` and falls back to `.extra('volatile', true)`. DSH only offers the fields carrying `meta.volatile`, and an unguarded `.volatile()` would itself fail activation on schemastery < 3.18.4 — a version a profile can hoist above the installation's copy.
18
+ - `state.getCfg()` and `collectFacts()` re-project the entry config on every read (`plainConfig`), because live fields arrive as cosmokit volatile references rather than plain values. A settings write therefore still reaches the next call without a restart, and `exposeMode` stays a load-time switch.
19
+ - `lib/http.js` looks the card up under the profile entry id (`settingsNamespace(ctx)`, falling back to `'mineru'`) instead of the hard-coded `'mineru'` string, and `GET /plugin/mineru/config` now answers `503` with a `hint` when the card does not exist, instead of a `200` carrying an empty config.
20
+ - DSH 0.1.5 compatibility is retained through feature detection: when `ctx.settings.register` exists, the legacy scope seam is still used (register `'mineru'` + scope read/write), so settings cards and persistence keep working for users who have not upgraded.
21
+ - Docs: AGENTS.md settings convention and known traps, plus a migration note under `docs/plans/`.
22
+
23
+ ### Added
24
+
25
+ - `tests/settings.spec.js`: the schema must flag every field volatile, a settings service **without** `register` must still activate the plugin and register its tools and skill, `settingsNamespace` must follow the entry id, `/config` must explain a missing card, and a settings service **with** `register` (DSH 0.1.5) must register the `'mineru'` namespace and serve `/config` through the legacy scope. The stub settings service throws if `register` is called, so the 2.x regression cannot return silently.
8
26
 
9
27
  ## [0.1.12] - 2026-09-13
10
28
 
@@ -90,7 +108,8 @@ All notable changes to **dsh-mineru** are documented here. The format follows [K
90
108
  - 限流感知(令牌桶 + 429 退避 + 每日限额);
91
109
  - Artifact 落地与 Web 界面(设置卡片、工具结果卡片、HMAC 签名预览)。
92
110
 
93
- [0.1.12]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.12
111
+ [0.1.13]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.13
112
+ [0.1.12]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.12
94
113
  [0.1.11]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.11
95
114
  [0.1.10]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.10
96
115
  [0.1.9]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.9
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # dsh-mineru
2
2
 
3
3
  [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
4
- [![version](https://img.shields.io/badge/version-0.1.12-blue)](https://github.com/Lee-Hilex/dsh-mineru/releases)
4
+ [![version](https://img.shields.io/badge/version-0.1.13-blue)](https://github.com/Lee-Hilex/dsh-mineru/releases)
5
5
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-0.1.0--rc.6%2B-4d6bfe)](https://github.com/deepseek-ai/deepseek-harness)
6
6
  [![MinerU](https://img.shields.io/badge/MinerU-API-4d6bfe)](https://mineru.net/apiManage/docs)
7
7
 
package/README.zh.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # dsh-mineru
2
2
 
3
3
  [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
4
- [![version](https://img.shields.io/badge/version-0.1.12-blue)](https://github.com/Lee-Hilex/dsh-mineru/releases)
4
+ [![version](https://img.shields.io/badge/version-0.1.13-blue)](https://github.com/Lee-Hilex/dsh-mineru/releases)
5
5
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-0.1.0--rc.6%2B-4d6bfe)](https://github.com/deepseek-ai/deepseek-harness)
6
6
  [![MinerU](https://img.shields.io/badge/MinerU-API-4d6bfe)](https://mineru.net/apiManage/docs)
7
7
 
package/lib/client.js CHANGED
@@ -96,9 +96,9 @@ window.__ModuleLoader__.load({
96
96
  "msg.tokenCleared": "Token 已清除 (将使用 Agent 轻量解析 API).",
97
97
  "msg.tokenSaveFail": "保存 Token 失败: {err}",
98
98
  "msg.tokenSaveNetFail": "保存 Token 失败 (网络错误): {err}",
99
- "msg.tokenClearFail": "清除 Token 失败: {err}",
100
- "msg.tokenClearNetFail": "清除 Token 失败 (网络错误): {err}",
101
- "msg.testNetFail": "测试请求失败 (网络错误): {err}",
99
+ "msg.tokenClearFail": "清除 Token 失败: {err}",
100
+ "msg.tokenClearNetFail": "清除 Token 失败 (网络错误): {err}",
101
+ "msg.testNetFail": "测试请求失败 (网络错误): {err}",
102
102
  "err.composer": "输入框服务不可用",
103
103
  "msg.testOk": "测试通过.",
104
104
  "api.precision": "精准解析 API",
@@ -192,9 +192,9 @@ window.__ModuleLoader__.load({
192
192
  "msg.tokenCleared": "Token cleared (the Agent lightweight API will be used).",
193
193
  "msg.tokenSaveFail": "Failed to save token: {err}",
194
194
  "msg.tokenSaveNetFail": "Failed to save token (network error): {err}",
195
- "msg.tokenClearFail": "Failed to clear token: {err}",
196
- "msg.tokenClearNetFail": "Failed to clear token (network error): {err}",
197
- "msg.testNetFail": "Test request failed (network error): {err}",
195
+ "msg.tokenClearFail": "Failed to clear token: {err}",
196
+ "msg.tokenClearNetFail": "Failed to clear token (network error): {err}",
197
+ "msg.testNetFail": "Test request failed (network error): {err}",
198
198
  "err.composer": "Composer input service unavailable",
199
199
  "msg.testOk": "Test passed.",
200
200
  "api.precision": "precision API",
package/lib/config.js CHANGED
@@ -5,13 +5,60 @@
5
5
  * DSH Credentials under the `tokenCredential` reference name (default
6
6
  * MINERU_API_TOKEN), never in settings or composition files.
7
7
  *
8
- * Resolution layers per the settings seam: schema defaults < composition base
9
- * (the bundle row's config) < the user settings section (written through the
10
- * Web Settings card or any host-side settings.update).
8
+ * Resolution layers: schema defaults < composition base (the bundle row's
9
+ * config) < the profile entry patch written by the Web Settings card. DSH 2.x
10
+ * derives that card from this schema, so every field is marked live (see
11
+ * {@link live}) and arrives in `apply(ctx, config)` as a volatile reference
12
+ * rather than a plain value — read it through {@link plainConfig}.
11
13
  * @module dsh-mineru/config
12
14
  */
13
15
  import z from '@deepseek-ai/schemastery';
14
16
 
17
+ /**
18
+ * Mark one field live-editable.
19
+ *
20
+ * DSH 2.x derives a plugin's settings card from its exported `Config` and only
21
+ * offers the fields carrying `meta.volatile`; a schema without them has no card
22
+ * at all. `.volatile()` exists in schemastery >= 3.18.4 only, and a profile can
23
+ * hoist an older copy (3.18.2 still satisfies `^3.18.0`) above the
24
+ * installation's one, so an unguarded call fails activation with
25
+ * `TypeError: ...volatile is not a function`. `.extra('volatile', true)` writes
26
+ * the same flag on every version, so the card appears either way; only hot-edit
27
+ * needs the newer copy.
28
+ * @template T
29
+ * @param {T} field one schemastery field
30
+ * @returns {T} the field, flagged volatile when the copy supports it
31
+ */
32
+ export function live(field) {
33
+ if (typeof field?.volatile === 'function') return field.volatile();
34
+ if (typeof field?.extra === 'function') return field.extra('volatile', true);
35
+ return field;
36
+ }
37
+
38
+ /**
39
+ * Unwrap one live configuration reference.
40
+ *
41
+ * A `meta.volatile` field resolves to a cosmokit volatile reference; reading it
42
+ * through `get()` is what makes a settings write visible to the next call.
43
+ * Plain values pass through unchanged.
44
+ * @param {unknown} value a reference or a plain value
45
+ * @returns {unknown} the current value
46
+ */
47
+ export function unwrapField(value) {
48
+ return value !== null && typeof value === 'object' && typeof value.get === 'function' ? value.get() : value;
49
+ }
50
+
51
+ /**
52
+ * Project the entry config into plain values.
53
+ * @param {object} [config] entry config handed to `apply` (volatile fields are references)
54
+ * @returns {object} a plain, detached configuration object
55
+ */
56
+ export function plainConfig(config) {
57
+ const out = {};
58
+ for (const [key, value] of Object.entries(config ?? {})) out[key] = unwrapField(value);
59
+ return out;
60
+ }
61
+
15
62
  /** Supported MinerU document languages (language packs from the API docs). */
16
63
  export const LANGUAGE_VALUES = Object.freeze([
17
64
  'ch', 'ch_server', 'en', 'japan', 'korean', 'chinese_cht',
@@ -80,56 +127,56 @@ export const DEFAULTS = Object.freeze({
80
127
  });
81
128
 
82
129
  export const CONFIG_SCHEMA = z.object({
83
- apiBaseUrl: z.string().role('text')
130
+ apiBaseUrl: live(z.string().role('text')
84
131
  .default(DEFAULTS.apiBaseUrl)
85
- .description('MinerU API base URL (https://mineru.net).'),
86
- tokenCredential: z.string().role('text')
132
+ .description('MinerU API base URL (https://mineru.net).')),
133
+ tokenCredential: live(z.string().role('text')
87
134
  .default(DEFAULTS.tokenCredential)
88
- .description('DSH Credential reference name holding the MinerU token.'),
89
- mode: z.union([z.const('auto'), z.const('precision'), z.const('agent')])
135
+ .description('DSH Credential reference name holding the MinerU token.')),
136
+ mode: live(z.union([z.const('auto'), z.const('precision'), z.const('agent')])
90
137
  .default(DEFAULTS.mode)
91
- .description('API mode: auto (token present -> precision, else agent), precision, or agent.'),
92
- modelVersion: z.union([z.const('pipeline'), z.const('vlm'), z.const('MinerU-HTML')])
138
+ .description('API mode: auto (token present -> precision, else agent), precision, or agent.')),
139
+ modelVersion: live(z.union([z.const('pipeline'), z.const('vlm'), z.const('MinerU-HTML')])
93
140
  .default(DEFAULTS.modelVersion)
94
- .description('Precision-API model version (pipeline | vlm | MinerU-HTML).'),
95
- language: z.string().role('text')
141
+ .description('Precision-API model version (pipeline | vlm | MinerU-HTML).')),
142
+ language: live(z.string().role('text')
96
143
  .default(DEFAULTS.language)
97
- .description('Document language pack, e.g. ch, en, latin (see README table).'),
98
- enableTable: z.boolean().default(DEFAULTS.enableTable)
99
- .description('Enable table recognition.'),
100
- enableFormula: z.boolean().default(DEFAULTS.enableFormula)
101
- .description('Enable formula recognition.'),
102
- isOcr: z.boolean().default(DEFAULTS.isOcr)
103
- .description('Force OCR for scanned content.'),
104
- extraFormats: z.array(z.union([z.const('docx'), z.const('html'), z.const('latex')]))
144
+ .description('Document language pack, e.g. ch, en, latin (see README table).')),
145
+ enableTable: live(z.boolean().default(DEFAULTS.enableTable)
146
+ .description('Enable table recognition.')),
147
+ enableFormula: live(z.boolean().default(DEFAULTS.enableFormula)
148
+ .description('Enable formula recognition.')),
149
+ isOcr: live(z.boolean().default(DEFAULTS.isOcr)
150
+ .description('Force OCR for scanned content.')),
151
+ extraFormats: live(z.array(z.union([z.const('docx'), z.const('html'), z.const('latex')]))
105
152
  .default(DEFAULTS.extraFormats)
106
- .description('Precision-only extra export formats added to the result zip.'),
107
- exposeMode: z.union([z.const('progressive'), z.const('always')])
153
+ .description('Precision-only extra export formats added to the result zip.')),
154
+ exposeMode: live(z.union([z.const('progressive'), z.const('always')])
108
155
  .default(DEFAULTS.exposeMode)
109
- .description('progressive: mineru_activate bootstrap + skill-based activation; always: register all tools globally.'),
110
- artifactRootName: z.string().role('text')
156
+ .description('progressive: mineru_activate bootstrap + skill-based activation; always: register all tools globally.')),
157
+ artifactRootName: live(z.string().role('text')
111
158
  .default(DEFAULTS.artifactRootName)
112
- .description('Artifact root directory name inside each session workspace.'),
113
- pollIntervalMs: z.number().default(DEFAULTS.pollIntervalMs)
114
- .description('Task-result poll interval (ms).'),
115
- pollJitterMs: z.number().default(DEFAULTS.pollJitterMs)
116
- .description('Per-query poll jitter (ms).'),
117
- timeoutMs: z.number().default(DEFAULTS.timeoutMs)
118
- .description('Whole-operation deadline (ms).'),
119
- maxFileBytes: z.number().default(DEFAULTS.maxFileBytes)
120
- .description('Local file byte cap; 0 = per-mode API limits (200 MB / 10 MB).'),
121
- inlineMarkdownBytes: z.number().default(DEFAULTS.inlineMarkdownBytes)
122
- .description('Markdown preview bytes returned inline with the tool result.'),
123
- artifactUrlTtlSec: z.number().default(DEFAULTS.artifactUrlTtlSec)
124
- .description('Signed artifact preview URL lifetime (seconds).'),
125
- submitRatePerMin: z.number().default(DEFAULTS.submitRatePerMin)
126
- .description('Submission rate cap per minute (official limit: 50/min).'),
127
- pollRatePerMin: z.number().default(DEFAULTS.pollRatePerMin)
128
- .description('Result-query rate cap per minute (official limit: 1000/min).'),
129
- dailySubmitLimit: z.number().default(DEFAULTS.dailySubmitLimit)
130
- .description('Daily submission cap reported before the API rejects (official: 5000/day).'),
131
- userAgent: z.string().role('text').default(DEFAULTS.userAgent)
132
- .description('User-Agent header sent to MinerU.'),
159
+ .description('Artifact root directory name inside each session workspace.')),
160
+ pollIntervalMs: live(z.number().default(DEFAULTS.pollIntervalMs)
161
+ .description('Task-result poll interval (ms).')),
162
+ pollJitterMs: live(z.number().default(DEFAULTS.pollJitterMs)
163
+ .description('Per-query poll jitter (ms).')),
164
+ timeoutMs: live(z.number().default(DEFAULTS.timeoutMs)
165
+ .description('Whole-operation deadline (ms).')),
166
+ maxFileBytes: live(z.number().default(DEFAULTS.maxFileBytes)
167
+ .description('Local file byte cap; 0 = per-mode API limits (200 MB / 10 MB).')),
168
+ inlineMarkdownBytes: live(z.number().default(DEFAULTS.inlineMarkdownBytes)
169
+ .description('Markdown preview bytes returned inline with the tool result.')),
170
+ artifactUrlTtlSec: live(z.number().default(DEFAULTS.artifactUrlTtlSec)
171
+ .description('Signed artifact preview URL lifetime (seconds).')),
172
+ submitRatePerMin: live(z.number().default(DEFAULTS.submitRatePerMin)
173
+ .description('Submission rate cap per minute (official limit: 50/min).')),
174
+ pollRatePerMin: live(z.number().default(DEFAULTS.pollRatePerMin)
175
+ .description('Result-query rate cap per minute (official limit: 1000/min).')),
176
+ dailySubmitLimit: live(z.number().default(DEFAULTS.dailySubmitLimit)
177
+ .description('Daily submission cap reported before the API rejects (official: 5000/day).')),
178
+ userAgent: live(z.string().role('text').default(DEFAULTS.userAgent)
179
+ .description('User-Agent header sent to MinerU.')),
133
180
  });
134
181
 
135
182
  /**
package/lib/http.js CHANGED
@@ -71,8 +71,9 @@ function stripToken(value) {
71
71
  * Mount the /plugin/mineru route tree.
72
72
  * @param {object} ctx injected web context (webServer service available)
73
73
  * @param {object} deps
74
- * @param {object} deps.settings the settings service (describe)
75
- * @param {object} deps.scope the mineru SettingsScope (get/update)
74
+ * @param {object} deps.settings the settings service (describe/update)
75
+ * @param {() => object} deps.config reads the live entry config (volatile fields unwrapped)
76
+ * @param {string} deps.settingsNs the profile entry id the settings card is keyed by
76
77
  * @param {object} deps.credentials the credentials service
77
78
  * @param {object} deps.schema the registered schemastery schema
78
79
  * @param {object} deps.state plugin state (clientFor, collectFacts, artifacts)
@@ -123,14 +124,30 @@ async function handle(req, res, deps) {
123
124
  return;
124
125
  }
125
126
 
127
+ // DSH keys a plugin's settings card by its profile entry id, which the host
128
+ // half resolves and passes down; 'mineru' is only the fallback.
129
+ const settingsNs = typeof deps.settingsNs === 'string' && deps.settingsNs.length > 0 ? deps.settingsNs : 'mineru';
130
+ const descriptorOf = () => (deps.settings.describe({ redactSecrets: true }) ?? []).find((d) => d.ns === settingsNs);
131
+
126
132
  if (route === '/' && method === 'GET') {
127
133
  const facts = await deps.state.collectFacts();
128
134
  sendJson(res, 200, { ok: true, health: facts, plugin: 'dsh-mineru' });
129
135
  return;
130
136
  }
131
137
  if (route === '/config' && method === 'GET') {
132
- const descriptor = (deps.settings.describe({ redactSecrets: true }) ?? [])
133
- .find((d) => d.ns === 'mineru');
138
+ const descriptor = descriptorOf();
139
+ if (descriptor === undefined) {
140
+ // The card is derived from CONFIG_SCHEMA: it is missing when the entry is
141
+ // not active, or when no field carries `meta.volatile`.
142
+ sendJson(res, 503, {
143
+ ok: false,
144
+ namespace: settingsNs,
145
+ error: 'settings namespace "' + settingsNs + '" is not registered',
146
+ hint: 'The host derives this card from the plugin\'s exported Config schema: the entry must be active and declare at least one `meta.volatile` field. '
147
+ + 'Restart DSH after upgrading the plugin, and check that the profile entry id matches the namespace the card asks for.',
148
+ });
149
+ return;
150
+ }
134
151
  const facts = await deps.state.collectFacts();
135
152
  sendJson(res, 200, {
136
153
  ok: true,
@@ -162,8 +179,8 @@ async function handle(req, res, deps) {
162
179
  const patch = body && typeof body.patch === 'object' && body.patch !== null ? body.patch : null;
163
180
  if (!patch) { sendJson(res, 400, { ok: false, error: 'missing patch object' }); return; }
164
181
  try {
165
- await deps.settings.update('mineru', patch, Number.isInteger(body.expectedRevision) ? body.expectedRevision : undefined);
166
- const descriptor = (deps.settings.describe({ redactSecrets: true }) ?? []).find((d) => d.ns === 'mineru');
182
+ await deps.settings.update(settingsNs, patch, Number.isInteger(body.expectedRevision) ? body.expectedRevision : undefined);
183
+ const descriptor = descriptorOf();
167
184
  sendJson(res, 200, { ok: true, revision: descriptor?.revision ?? 0 });
168
185
  } catch (err) {
169
186
  if (err instanceof SettingsConflictError) {
@@ -178,7 +195,7 @@ async function handle(req, res, deps) {
178
195
  const raw = await readBody(req);
179
196
  let body;
180
197
  try { body = JSON.parse(raw || '{}'); } catch { sendJson(res, 400, { ok: false, error: 'invalid JSON body' }); return; }
181
- const cfg = deps.scope.get();
198
+ const cfg = deps.config();
182
199
  const refName = typeof body.ref === 'string' && /^[A-Za-z_][A-Za-z0-9_]*$/.test(body.ref) ? body.ref : cfg.tokenCredential;
183
200
  let ref;
184
201
  try {
@@ -229,7 +246,7 @@ async function handle(req, res, deps) {
229
246
  * priority quota.
230
247
  */
231
248
  async function testToken(deps) {
232
- const cfg = deps.scope.get();
249
+ const cfg = deps.config();
233
250
  const client = await deps.state.clientFor(cfg);
234
251
  if (!client.precisionEnabled()) {
235
252
  return { status: 400, body: { ok: false, error: '未配置 MinerU Token: 请先在上方填写并保存 Token.' } };
@@ -279,7 +296,7 @@ async function testToken(deps) {
279
296
  * Agent lightweight API. Reports success or the current IP rate-limit state.
280
297
  */
281
298
  async function testAgent(deps) {
282
- const cfg = deps.scope.get();
299
+ const cfg = deps.config();
283
300
  const client = await deps.state.clientFor(cfg);
284
301
  const opts = {
285
302
  language: cfg.language,
package/lib/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * dsh-mineru host plugin: MinerU multimodal document parsing for DeepSeek
3
3
  * Harness. Registers the mineru_activate bootstrap (or all tools under
4
- * exposeMode: always), the mineru-tools skill, the "mineru" settings
5
- * namespace, credential resolution, and (Web profile) the /plugin/mineru
6
- * HTTP surface.
4
+ * exposeMode: always), the mineru-tools skill, the "mineru" settings card,
5
+ * credential resolution, and (Web profile) the /plugin/mineru HTTP surface.
7
6
  * @module dsh-mineru
8
7
  */
9
8
  import { createRequire } from 'node:module';
@@ -13,7 +12,7 @@ import { WorkspaceArtifactStore } from './artifacts.js';
13
12
  import { mountHttp } from './http.js';
14
13
  import { buildActivateTool, buildAgentTools } from './tools.js';
15
14
  import { SKILL_CONTENT, SKILL_DESCRIPTION, SKILL_NAME } from './skill.js';
16
- import { CONFIG_SCHEMA, DEFAULTS, resolveLoadConfig, validateConfig } from './config.js';
15
+ import { CONFIG_SCHEMA, DEFAULTS, plainConfig, resolveLoadConfig, validateConfig } from './config.js';
17
16
 
18
17
  const require = createRequire(import.meta.url);
19
18
  /** Plugin version read from the package manifest (single source of truth). */
@@ -26,17 +25,71 @@ export const inject = ['tools', 'skills', 'settings', 'credentials', 'agents'];
26
25
  /** Entry config schema (validated by the Loader). */
27
26
  export const Config = CONFIG_SCHEMA;
28
27
 
28
+ /**
29
+ * Resolve the settings namespace the host keys this plugin's card by.
30
+ *
31
+ * DSH 2.x derives the card from the exported `Config` and reports it under the
32
+ * owning profile entry id, which is also the id `settings.update` writes to.
33
+ * The `/plugin/mineru` routes must therefore look the card up under that id
34
+ * rather than under the constant the installer happened to write.
35
+ * @param {object} ctx plugin context
36
+ * @returns {string} the profile entry id, or 'mineru' when it cannot be read
37
+ */
38
+ export function settingsNamespace(ctx) {
39
+ try {
40
+ const id = ctx?.fiber?.entry?.options?.id;
41
+ if (typeof id === 'string' && id.length > 0) return id;
42
+ } catch {
43
+ // A fiber with no owning entry (or an unreadable computed id) falls back.
44
+ }
45
+ return 'mineru';
46
+ }
47
+
29
48
  /**
30
49
  * @param {import('@deepseek-ai/cordis').Context} ctx
31
- * @param {object} [config] entry config (composition layer)
50
+ * @param {object} [config] entry config (composition layer); `meta.volatile`
51
+ * fields arrive as live references rather than plain values
32
52
  */
33
53
  export function apply(ctx, config) {
34
- const loadCfg = resolveLoadConfig(config);
35
- const scope = ctx.settings.register('mineru', CONFIG_SCHEMA, {
36
- base: config,
37
- applies: 'live',
38
- validate: validateConfig,
39
- });
54
+ // exposeMode is composition-scoped, so it is resolved once at load time from
55
+ // the values the entry actually carries right now.
56
+ const loadCfg = resolveLoadConfig(plainConfig(config));
57
+
58
+ // DSH 2.x removed `ctx.settings.register` (it throws `TypeError:
59
+ // ctx.settings.register is not a function` and aborts the whole activation);
60
+ // the card is derived from CONFIG_SCHEMA instead. What it needs is a volatile
61
+ // field in that schema plus a namespace equal to this entry's id.
62
+ //
63
+ // DSH 0.1.5 still ships `register`; keep using the legacy scope seam there so
64
+ // the settings card and persistence keep working for users who have not
65
+ // upgraded yet. Detect it behaviorally: DSH 2.x removed the method, and its
66
+ // regression stubs throw `TypeError` on call.
67
+ let configNow;
68
+ let settingsNs;
69
+ let scope = null;
70
+ if (typeof ctx.settings?.register === 'function') {
71
+ try {
72
+ scope = ctx.settings.register('mineru', CONFIG_SCHEMA, {
73
+ base: config,
74
+ applies: 'live',
75
+ validate: validateConfig,
76
+ });
77
+ } catch (err) {
78
+ if (!(err instanceof TypeError)) throw err;
79
+ scope = null; // 2.x-shaped service: fall through to the derived card.
80
+ }
81
+ }
82
+ if (scope) {
83
+ // Legacy seam (DSH 0.1.5): the scope re-resolves schema defaults, the
84
+ // composition base and the stored user section.
85
+ configNow = () => scope.get();
86
+ settingsNs = 'mineru';
87
+ } else {
88
+ // DSH 2.x seam: every read re-projects the entry config, so a settings
89
+ // write reaches the next call without a restart.
90
+ configNow = () => ({ ...DEFAULTS, ...plainConfig(config) });
91
+ settingsNs = settingsNamespace(ctx);
92
+ }
40
93
 
41
94
  /** @type {object} */
42
95
  const state = {
@@ -55,7 +108,7 @@ export function apply(ctx, config) {
55
108
  urlBuilder: null,
56
109
  agentToolDefs: [],
57
110
  getCfg() {
58
- return scope.get();
111
+ return configNow();
59
112
  },
60
113
  /**
61
114
  * Build a MinerU client for one call: resolves the token per operation
@@ -79,7 +132,7 @@ export function apply(ctx, config) {
79
132
  },
80
133
  /** Non-secret facts for health surfaces (Web settings + activate). */
81
134
  async collectFacts() {
82
- const cfg = scope.get();
135
+ const cfg = configNow();
83
136
  const ref = credentialRef(cfg.tokenCredential);
84
137
  const info = await ctx.credentials.describe(ref);
85
138
  const tokenConfigured = Boolean(info?.configured);
@@ -124,7 +177,8 @@ export function apply(ctx, config) {
124
177
  state.urlBuilder = (cwd, rel) => state.artifacts.capabilityUrl(cwd, rel);
125
178
  mountHttp(webCtx, {
126
179
  settings: ctx.settings,
127
- scope,
180
+ config: configNow,
181
+ settingsNs,
128
182
  credentials: ctx.credentials,
129
183
  schema: CONFIG_SCHEMA,
130
184
  state,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mineru",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "dsh-mineru: MinerU 文档解析插件 for DeepSeek Harness — 多模态全格式 (PDF/Word/PPT/Excel/HTML/图片) → 结构化 Markdown. 填 Token 走精准解析 API, 留空走 Agent 轻量解析 API.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",