dsh-mineru 0.1.7

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/lib/index.js ADDED
@@ -0,0 +1,135 @@
1
+ /**
2
+ * dsh-mineru host plugin: MinerU multimodal document parsing for DeepSeek
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.
7
+ * @module dsh-mineru
8
+ */
9
+ import { createRequire } from 'node:module';
10
+ import { credentialRef } from '@deepseek-ai/dsh-credentials';
11
+ import { settingsNamespace } from '@deepseek-ai/dsh-settings';
12
+ import { DailyCounter, MineruClient, RateLimiter } from './mineru-client.js';
13
+ import { WorkspaceArtifactStore } from './artifacts.js';
14
+ import { mountHttp } from './http.js';
15
+ import { buildActivateTool, buildAgentTools } from './tools.js';
16
+ import { SKILL_CONTENT, SKILL_DESCRIPTION, SKILL_NAME } from './skill.js';
17
+ import { CONFIG_SCHEMA, DEFAULTS, resolveLoadConfig, validateConfig } from './config.js';
18
+
19
+ const require = createRequire(import.meta.url);
20
+ /** Plugin version read from the package manifest (single source of truth). */
21
+ export const PLUGIN_VERSION = require('../package.json').version ?? '0.0.0';
22
+
23
+ /** Cordis plugin name used by loader diagnostics. */
24
+ export const name = 'mineru';
25
+ /** Required host-plane services. */
26
+ export const inject = ['tools', 'skills', 'settings', 'credentials', 'agents'];
27
+ /** Entry config schema (validated by the Loader). */
28
+ export const Config = CONFIG_SCHEMA;
29
+
30
+ /**
31
+ * @param {import('@deepseek-ai/cordis').Context} ctx
32
+ * @param {object} [config] entry config (composition layer)
33
+ */
34
+ export function apply(ctx, config) {
35
+ const loadCfg = resolveLoadConfig(config);
36
+ const scope = ctx.settings.register(settingsNamespace('mineru'), CONFIG_SCHEMA, {
37
+ base: config,
38
+ applies: 'live',
39
+ validate: validateConfig,
40
+ });
41
+
42
+ /** @type {object} */
43
+ const state = {
44
+ activatedAgents: new WeakSet(),
45
+ artifacts: new WorkspaceArtifactStore({
46
+ artifactRootName: loadCfg.artifactRootName,
47
+ urlTtlSec: loadCfg.artifactUrlTtlSec,
48
+ pluginVersion: PLUGIN_VERSION,
49
+ }),
50
+ limiters: {
51
+ submit: new RateLimiter(loadCfg.submitRatePerMin),
52
+ poll: new RateLimiter(loadCfg.pollRatePerMin),
53
+ daily: new DailyCounter(loadCfg.dailySubmitLimit),
54
+ },
55
+ /** Set when the Web host mounts; builds preview URLs for tool results. */
56
+ urlBuilder: null,
57
+ agentToolDefs: [],
58
+ getCfg() {
59
+ return scope.get();
60
+ },
61
+ /**
62
+ * Build a MinerU client for one call: resolves the token per operation
63
+ * (credential changes apply to the very next call) and live-updates the
64
+ * shared rate-limit parameters.
65
+ */
66
+ async clientFor(cfg) {
67
+ const ref = credentialRef(cfg.tokenCredential);
68
+ const hit = await ctx.credentials.resolve(ref);
69
+ state.limiters.submit.rate = cfg.submitRatePerMin / 60000;
70
+ state.limiters.submit.capacity = Math.max(1, Math.ceil(cfg.submitRatePerMin / 5));
71
+ state.limiters.poll.rate = cfg.pollRatePerMin / 60000;
72
+ state.limiters.poll.capacity = Math.max(1, Math.ceil(cfg.pollRatePerMin / 5));
73
+ state.limiters.daily.limit = cfg.dailySubmitLimit;
74
+ return new MineruClient({
75
+ baseUrl: cfg.apiBaseUrl,
76
+ token: hit?.value,
77
+ limiters: state.limiters,
78
+ userAgent: cfg.userAgent === DEFAULTS.userAgent ? 'dsh-mineru/' + PLUGIN_VERSION + ' (+DeepSeek-Harness)' : cfg.userAgent,
79
+ });
80
+ },
81
+ /** Non-secret facts for health surfaces (Web settings + activate). */
82
+ async collectFacts() {
83
+ const cfg = scope.get();
84
+ const ref = credentialRef(cfg.tokenCredential);
85
+ const info = await ctx.credentials.describe(ref);
86
+ const tokenConfigured = Boolean(info?.configured);
87
+ let api = 'agent';
88
+ if (cfg.mode === 'precision') api = tokenConfigured ? 'precision' : 'precision-missing-token';
89
+ else if (cfg.mode === 'auto') api = tokenConfigured ? 'precision' : 'agent';
90
+ return {
91
+ mode: cfg.mode,
92
+ api,
93
+ tokenConfigured,
94
+ tokenSource: info?.source ?? null,
95
+ tokenWritable: info?.writable ?? false,
96
+ credentialRef: cfg.tokenCredential,
97
+ modelVersion: cfg.modelVersion,
98
+ baseUrl: cfg.apiBaseUrl,
99
+ artifactRootName: cfg.artifactRootName,
100
+ submitRatePerMin: cfg.submitRatePerMin,
101
+ pollRatePerMin: cfg.pollRatePerMin,
102
+ dailySubmitLimit: cfg.dailySubmitLimit,
103
+ exposeMode: loadCfg.exposeMode,
104
+ };
105
+ },
106
+ };
107
+ state.agentToolDefs = buildAgentTools(state);
108
+
109
+ ctx.effect(() => {
110
+ ctx.skills.register({
111
+ name: SKILL_NAME,
112
+ description: SKILL_DESCRIPTION,
113
+ source: 'runtime',
114
+ content: SKILL_CONTENT,
115
+ });
116
+ if (loadCfg.exposeMode === 'always') {
117
+ for (const def of state.agentToolDefs) ctx.tools.register(def);
118
+ } else {
119
+ ctx.tools.register(buildActivateTool(state));
120
+ }
121
+ });
122
+
123
+ // Web profile only: preview URL builder + /plugin/mineru routes.
124
+ ctx.inject(['webServer'], (webCtx) => {
125
+ state.urlBuilder = (cwd, rel) => state.artifacts.capabilityUrl(cwd, rel);
126
+ mountHttp(webCtx, {
127
+ settings: ctx.settings,
128
+ scope,
129
+ credentials: ctx.credentials,
130
+ schema: CONFIG_SCHEMA,
131
+ state,
132
+ agents: ctx.agents,
133
+ });
134
+ });
135
+ }