@sparkelf/dsh-ocr 0.0.0-stage → 0.1.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.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The Client services this plugin consumes, declared structurally.
3
+ *
4
+ * Restated rather than imported from each owning package: the browser bundle may only reach
5
+ * the loader's platform modules, and a type-only import of a package that ships no
6
+ * `./client` entry would fail to resolve. The shape below is the part of the slot and locale
7
+ * registries this plugin actually calls, which is the contract it has to satisfy.
8
+ *
9
+ * @module @sparkelf/dsh-ocr/client/context
10
+ */
11
+ import type { Context } from '@deepseek-ai/cordis';
12
+ import type { LocaleDictOf, LocaleNamespaceMap, SlotCore, TranslateNS } from '@deepseek-ai/dsh-client-ui-slots';
13
+ /** The two slot operations this plugin uses. */
14
+ interface ClientSlots {
15
+ /** Register one occupant of a declared slot. */
16
+ register: SlotCore['register'];
17
+ /** Contribute to one named slot, with a disposer factory. */
18
+ inject(name: 'settings.section', factory: () => () => void): void;
19
+ }
20
+ /** The locale operations this plugin uses. */
21
+ interface ClientLocale {
22
+ /** Register one namespace's dictionaries; returns its disposer. */
23
+ register<N extends keyof LocaleNamespaceMap & string>(namespace: N, dictionaries: {
24
+ zh: LocaleDictOf<N>;
25
+ en: LocaleDictOf<N>;
26
+ }): () => void;
27
+ /** Bind one namespace's resolver. */
28
+ bind<N extends keyof LocaleNamespaceMap & string>(namespace: N): TranslateNS<N>;
29
+ }
30
+ /** Client Cordis context services consumed by the document-recognition plugin. */
31
+ export type OcrClientContext = Context & {
32
+ slots: ClientSlots;
33
+ locale: ClientLocale;
34
+ };
35
+ export {};
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Compile-time declarations for the public slots this plugin consumes.
3
+ *
4
+ * `SlotMap` and `LocaleNamespaceMap` are declaration-merged by every plugin that occupies a
5
+ * slot, so the entry a plugin contributes is also the type its registration is checked
6
+ * against. Declaring them here is what makes a `kind`/`scope` mistake a compile error rather
7
+ * than a registration the shell silently refuses.
8
+ *
9
+ * @module @sparkelf/dsh-ocr/client/contract
10
+ */
11
+ import type { SettingsOcrKey } from './locales.ts';
12
+ declare module '@deepseek-ai/dsh-client-ui-slots' {
13
+ interface SlotMap {
14
+ /**
15
+ * One section of the Settings page.
16
+ *
17
+ * `list` = any number of sections share the page; `root` = the page belongs to no
18
+ * Session, which is why it may not read session state.
19
+ */
20
+ 'settings.section': {
21
+ kind: 'list';
22
+ scope: 'root';
23
+ owner: {
24
+ close: () => void;
25
+ };
26
+ };
27
+ }
28
+ interface LocaleNamespaceMap {
29
+ /** Document-recognition settings copy. */
30
+ settingsOcr: SettingsOcrKey;
31
+ }
32
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Client half of the document-recognition plugin.
3
+ *
4
+ * Contributes one surface: a Settings section where a super administrator configures the
5
+ * MinerU address every member's documents are recognized with. There is no sidebar entry and
6
+ * no management page -- the feature is a skill plus this one write path, and a second
7
+ * navigation entry would promise a page with nothing else on it.
8
+ *
9
+ * The namespace is its own (`settingsOcr`), so this section cannot collide with the knowledge
10
+ * base's `settings.knowledgeBase` entry beside it.
11
+ *
12
+ * @module @sparkelf/dsh-ocr/client
13
+ */
14
+ import type { OcrClientContext } from './context.ts';
15
+ /** Services the browser half needs to contribute a Settings section. */
16
+ export declare const inject: string[];
17
+ /**
18
+ * Register the document-recognition Settings section.
19
+ * @param ctx - the DSH client context carrying the slot and locale registries.
20
+ */
21
+ export declare function apply(ctx: OcrClientContext): void;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Settings copy for the document-recognition section.
3
+ *
4
+ * One English object is the key set and each other locale is a complete record over it,
5
+ * so a missing translation fails to compile rather than falling back at runtime. That is
6
+ * the shape every locale-backed DSH client plugin uses.
7
+ *
8
+ * The reader-facing name is 「文档识别」, matching the skill's own display name in
9
+ * `i18n/zh.json`. Both say what the feature is for rather than naming the backend: MinerU
10
+ * is the implementation, and a reader who has never heard of it still has to find this page.
11
+ *
12
+ * @module @sparkelf/dsh-ocr/client/locales
13
+ */
14
+ /** English copy for the document-recognition settings section. */
15
+ export declare const en: {
16
+ /** Settings navigation entry. */
17
+ readonly nav: "Document recognition";
18
+ /** Accessible name of the section; the page itself shows no second heading. */
19
+ readonly title: "Document text recognition";
20
+ /** Address field label; the only visible label in the section. */
21
+ readonly addressLabel: "MinerU service address";
22
+ /** Placeholder for the address field. */
23
+ readonly addressPlaceholder: "http://172.17.0.1:8000";
24
+ /** Shown while the stored value is being read. */
25
+ readonly loading: "Loading…";
26
+ /** Shown when the Host route cannot answer at all. */
27
+ readonly unavailable: "The document-recognition settings are unavailable.";
28
+ /** Explains {@link unavailable}. */
29
+ readonly unavailableDetail: "The plugin could not reach its own settings route. Reload the page; if this persists, the plugin is not mounted on this deployment.";
30
+ /** Whether the current caller may change the value. */
31
+ readonly readOnly: "Only a super administrator can change this.";
32
+ /** Button that probes the address without saving it. */
33
+ readonly testConnection: "Test connection";
34
+ /** Connection tag: nothing has been probed in this page yet. */
35
+ readonly connectionUntested: "Untested";
36
+ /** Connection tag: the probe is in flight. */
37
+ readonly connectionTesting: "Testing…";
38
+ /** Connection tag: the address answered as MinerU. */
39
+ readonly connectionConnected: "Connected";
40
+ /** Connection tag: the probe failed. */
41
+ readonly connectionFailed: "Connection failed";
42
+ /** Latency under the field after a successful probe. */
43
+ readonly connectionLatency: "{ms} ms";
44
+ /** Probe detail: not an absolute http(s) address. */
45
+ readonly probeBadUrl: "Enter an absolute http or https address";
46
+ /** Probe detail: no answer inside the probe window. */
47
+ readonly probeTimeout: "The address did not answer in time";
48
+ /** Probe detail: refused, unknown host, or unreachable. */
49
+ readonly probeUnreachable: "Could not connect: {reason}";
50
+ /** Probe detail: an HTTP server answered, but it is not MinerU. */
51
+ readonly probeNotMineru: "The address answers, but it is not a MinerU service ({title})";
52
+ /** Probe detail: a non-2xx status. */
53
+ readonly probeHttpError: "The service answered HTTP {status}";
54
+ /** Probe detail: the Host could not check the caller's role first. */
55
+ readonly probeUnavailable: "The connection test is unavailable right now";
56
+ /** Label of the button that fills empty members only. */
57
+ readonly distributeDefault: "Distribute to members without a value";
58
+ /** Label of the button that replaces every member's value. */
59
+ readonly overwrite: "Save and overwrite every member";
60
+ /** Shown while a write is in flight. */
61
+ readonly saving: "Saving…";
62
+ /** Shown while the impact count is being read. */
63
+ readonly counting: "Counting members…";
64
+ /**
65
+ * The overwrite confirmation.
66
+ *
67
+ * Both numbers are load-bearing: `{withValue}` is what the action destroys and
68
+ * `{total}` is the size of the population, so the reader can see the blast radius
69
+ * instead of being asked a bare "are you sure?".
70
+ */
71
+ readonly confirmOverwrite: "This replaces the address {withValue} of {total} members already set. This cannot be undone. Continue?";
72
+ /** The distribute confirmation. */
73
+ readonly confirmDistribute: "Fill the address for {withoutValue} of {total} members that have none. Continue?";
74
+ /** Confirm button. */
75
+ readonly confirm: "Continue";
76
+ /** Cancel button. */
77
+ readonly cancel: "Cancel";
78
+ /** Result headline after a write, before the four counts. */
79
+ readonly resultTitle: "Distribution finished";
80
+ /** One count in the result row. */
81
+ readonly resultFilled: "Written";
82
+ /** One count in the result row. */
83
+ readonly resultSkipped: "Skipped";
84
+ /** One count in the result row. */
85
+ readonly resultFailed: "Failed";
86
+ /** One count in the result row. */
87
+ readonly resultTotal: "Considered";
88
+ /** A write that failed as a whole, before any per-member counting. */
89
+ readonly failure: "The change did not go through: {reason}";
90
+ /** The address typed in is not an absolute http(s) address. */
91
+ readonly badAddress: "Enter an absolute http or https address, for example http://172.17.0.1:8000";
92
+ /** Status line for a distribution that wrote nothing because everyone had a value. */
93
+ readonly nothingToDo: "Nothing to change: every member already has an address.";
94
+ };
95
+ /** The key set this namespace's dictionaries must cover. */
96
+ export type SettingsOcrKey = keyof typeof en;
97
+ /** Chinese copy; a complete record over {@link en}, so a missing key fails to compile. */
98
+ export declare const zh: Record<keyof typeof en, string>;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Who may see the document-recognition Settings section.
3
+ *
4
+ * The section configures one deployment-wide address and offers distribution writes, so it
5
+ * belongs to the roles that administer the deployment. Every other member still USES the
6
+ * shared address through the skill; they simply have no settings entry to change it.
7
+ *
8
+ * Registration is conditional rather than a component that renders null: an unauthorized
9
+ * reader must not find a「文档识别」row in Settings at all. The role can change without a
10
+ * reload (the portal re-posts the identity), so the decision is re-evaluated whenever the
11
+ * account bridge says the user changed.
12
+ *
13
+ * @module @sparkelf/dsh-ocr/client/section-owner
14
+ */
15
+ /** The event the DataOps account bridge dispatches after the identity changes. */
16
+ export declare const ACCOUNT_CHANGED_EVENT = "dataops-account:changed";
17
+ /** Role names that may configure the shared MinerU address. Exact match, by design. */
18
+ export declare const OCR_SETTINGS_ROLES: readonly string[];
19
+ /**
20
+ * Whether one DataOps role name may open the section.
21
+ *
22
+ * Exact equality: a role called「管理员助理」or「超级管理员(试用)」is a different role and
23
+ * must not inherit the write surface by prefix. An absent identity is unauthorized: the
24
+ * section is not something to show optimistically before the portal has answered.
25
+ * @param name - `window.__DATAOPS_USER__.name`, when known.
26
+ * @returns whether the section should be registered.
27
+ */
28
+ export declare function isOcrSettingsVisible(name: string | null | undefined): boolean;
29
+ /** The part of `window` this module reads. */
30
+ export interface VisibilityWindow {
31
+ __DATAOPS_USER__?: {
32
+ readonly name?: unknown;
33
+ } | null;
34
+ addEventListener(type: string, listener: () => void): void;
35
+ removeEventListener(type: string, listener: () => void): void;
36
+ }
37
+ /** Options for {@link installConditionalSection}. */
38
+ export interface ConditionalSectionOptions {
39
+ /** The window that carries the identity and the change event. */
40
+ window: VisibilityWindow;
41
+ /** Register the section; returns its disposer. Only called while authorized. */
42
+ register: () => (() => void) | undefined;
43
+ /** Optional extra signal (e.g. a MutationObserver on the account dataset). */
44
+ observe?: (sync: () => void) => () => void;
45
+ /** Called when registration itself throws, so one failure does not kill the plugin. */
46
+ onError?: (error: unknown) => void;
47
+ }
48
+ /**
49
+ * Register the section only while the current identity is authorized, and follow changes.
50
+ *
51
+ * The disposer removes the event listener and the extra observer, and disposes any section
52
+ * currently registered. Calling it is what lets Cordis unload the plugin without leaving a
53
+ * Settings row behind.
54
+ * @param options - window, registrar, and optional observer/error hook.
55
+ * @returns a disposer for the whole conditional contribution.
56
+ */
57
+ export declare function installConditionalSection(options: ConditionalSectionOptions): () => void;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Settings styles.
3
+ *
4
+ * Inline rather than a CSS-module file: the browser bundle in this package has no CSS
5
+ * pipeline (adding one would mean a `lightningcss` build dependency the other half does not
6
+ * need), and this section is a handful of declarations that read the shell's own design
7
+ * tokens. The tokens are what make it follow the theme; the rules here only place them.
8
+ *
9
+ * @module @sparkelf/dsh-ocr/client/styles
10
+ */
11
+ import type { CSSProperties } from 'react';
12
+ /** The section's outer block: normal settings-page rhythm. */
13
+ export declare const section: CSSProperties;
14
+ /** A field label, matching the official settings page's 14px/22px label line. */
15
+ export declare const label: CSSProperties;
16
+ /** A grouped field: label above control. */
17
+ export declare const field: CSSProperties;
18
+ /**
19
+ * The field row: the input primitive and the status tag share one box.
20
+ *
21
+ * A grid rather than a flex row because the primitive's wrapper is an inline-flex span:
22
+ * as a grid item it stretches to the column width, which a flex item with `flex: 0 1 auto`
23
+ * would not. The tag is positioned over the input's right edge, inside the border.
24
+ */
25
+ export declare const addressBox: CSSProperties;
26
+ /** The status tag's seat inside the input box. */
27
+ export declare const tagSlot: CSSProperties;
28
+ /** A row of actions, right-aligned like the settings page's own footers. */
29
+ export declare const actions: CSSProperties;
30
+ /**
31
+ * The panel's bottom action row.
32
+ *
33
+ * Same width as the field, so the last button's right edge lands exactly on the input's
34
+ * right edge. The extra top margin is deliberate: the row must not crowd the status line
35
+ * under the input -- the failure reason and the buttons are different decisions, and a
36
+ * reader scanning the reason should not hit a button by accident.
37
+ */
38
+ export declare const actionsBar: CSSProperties;
39
+ /** Secondary copy: what is stored, why it cannot be edited, what a result means. */
40
+ export declare const detail: CSSProperties;
41
+ /**
42
+ * A failed connection's reason.
43
+ *
44
+ * Red because the state is an error, smaller than body copy because it is supporting
45
+ * evidence rather than a sentence to read at the same weight as the field, and still
46
+ * selectable so an operator can copy the transport message into a ticket.
47
+ */
48
+ export declare const errorDetail: CSSProperties;
49
+ /** The confirmation block and the result block share this outline. */
50
+ export declare const panel: CSSProperties;
51
+ /** The four result counts. */
52
+ export declare const counts: CSSProperties;
53
+ /** One count: the number leads, the label under it. */
54
+ export declare const count: CSSProperties;
55
+ /** A count's number. */
56
+ export declare const countValue: CSSProperties;
@@ -0,0 +1,317 @@
1
+ /**
2
+ * Host half of the document-text-recognition plugin.
3
+ *
4
+ * Two contributions, and they serve different audiences:
5
+ *
6
+ * 1. **The skill provider.** The package ships one file the model needs -- `SKILL.md` -- and
7
+ * it does not live under a directory the skill registry scans, because `node_modules` is
8
+ * not a scan root. Registering it explicitly is the same thing
9
+ * `@sparkelf/dsh-dataops-admin` and `@sparkelf/dsh-knowledge-base` do.
10
+ *
11
+ * 2. **The settings route.** The settings page cannot call the DataOps backend directly: the
12
+ * browser's credential is an httpOnly cookie and the backend's `/api/ocr/*` routes want a
13
+ * bearer. This Host holds the DataOps JWT (or adopts the one the gateway attached), so it
14
+ * relays the four OCR calls and the page talks only to this process.
15
+ *
16
+ * The MinerU address is NOT stored here. Every member gets their own workspace container and
17
+ * their own DSH profile, so a per-profile setting cannot reach anybody else; the shared value
18
+ * lives in the backend (`GET /api/ocr/config`), which this half reads and relays. A copy in
19
+ * this profile would be a second source of truth that silently goes stale.
20
+ *
21
+ * @module @sparkelf/dsh-ocr
22
+ */
23
+ import type { IncomingMessage, ServerResponse } from 'node:http';
24
+ import z from '@deepseek-ai/schemastery';
25
+ import { OCR_API, type OcrApiMethod, type OcrProbeView } from './api.ts';
26
+ /** The name this plugin mounts as in the profile composition. */
27
+ export declare const PLUGIN_NAME = "@sparkelf/dsh-ocr";
28
+ /**
29
+ * Host services this plugin needs before `apply` runs.
30
+ *
31
+ * Declared rather than reached for: Cordis resolves a service through the plugin's own
32
+ * context, and touching one that was not injected throws
33
+ * `cannot get property "webServer" without inject` during apply -- which took the whole
34
+ * plugin down and, with it, the skill registration. `webServer` carries the settings relay,
35
+ * `credentials` resolves the fallback DataOps token.
36
+ *
37
+ * `skills` is deliberately absent: the registry is an OPTIONAL neighbour, so it is reached
38
+ * through `ctx.inject` inside apply and skipped on a host that does not have it.
39
+ */
40
+ export declare const inject: string[];
41
+ /** Provider name reported to the skill registry. */
42
+ export declare const SKILL_PROVIDER = "dsh-ocr";
43
+ /**
44
+ * Name the model sees in the skill catalog.
45
+ *
46
+ * Must match `^[a-z0-9]+(?:-[a-z0-9]+)*$`: the skill center silently skips a directory that
47
+ * does not, and this value keys the provider.
48
+ */
49
+ export declare const SKILL_NAME = "ocr";
50
+ /**
51
+ * Short description shown in the skill list.
52
+ *
53
+ * Kept beside the SKILL.md body rather than parsed out of its frontmatter: the catalog
54
+ * answers `list()` without reading any skill content, so the text has to be available
55
+ * without touching the file.
56
+ */
57
+ export declare const SKILL_DESCRIPTION = "\u8BC6\u522B PDF\u3001\u56FE\u7247\u3001\u626B\u63CF\u4EF6\u7B49\u6587\u6863\u4E2D\u7684\u6587\u5B57\u5E76\u8F93\u51FA Markdown\uFF0C\u4F7F\u7528\u7BA1\u7406\u5458\u7EDF\u4E00\u914D\u7F6E\u7684 MinerU \u670D\u52A1\u3002";
58
+ /**
59
+ * Display name the skill center shows for this skill.
60
+ *
61
+ * Deliberately NOT the registry name: `ocr` is the internal identifier, while users must see
62
+ * a business-facing Chinese name. The skill center reads the display name from the
63
+ * `i18n/zh.json` beside SKILL.md; this constant is the same string, so a host that reports
64
+ * the catalog without the translation file still has the right name.
65
+ */
66
+ export declare const SKILL_DISPLAY_NAME = "\u6587\u6863\u6587\u5B57\u8BC6\u522B";
67
+ /**
68
+ * Where this package's SKILL.md lives, from either build layout.
69
+ *
70
+ * The build emits `lib/index.js` while a source run executes from `src/`; both sit one level
71
+ * below the package root, so the same `..` answers both.
72
+ *
73
+ * @returns absolute path of the skill document.
74
+ */
75
+ export declare function skillPath(): string;
76
+ /** Both a human and the model may invoke this skill. */
77
+ export declare const SKILL_INVOCATION: {
78
+ readonly modelInvocable: true;
79
+ readonly userInvocable: true;
80
+ };
81
+ /**
82
+ * Rank places this beside the other bundled DataOps capabilities.
83
+ *
84
+ * `knowledge-base` uses 640 and `dataops-admin` uses 641; this one follows them. The value
85
+ * orders a catalog listing, not a priority -- the model reaches for these by name.
86
+ */
87
+ export declare const SKILL_RANK = 642;
88
+ /**
89
+ * The methods this Host relays to the DataOps backend.
90
+ *
91
+ * `test-connection` is answered by this process itself (it probes MinerU from inside the
92
+ * workspace network), so it is excluded from the backend route map rather than mapped to
93
+ * a path that does not exist.
94
+ */
95
+ export type OcrBackendMethod = Exclude<OcrApiMethod, typeof OCR_API.testConnection>;
96
+ /** Backend path each relayed method calls, and the HTTP method it uses. */
97
+ export declare const OCR_BACKEND_ROUTES: Readonly<Record<OcrBackendMethod, {
98
+ path: string;
99
+ method: 'GET' | 'POST';
100
+ }>>;
101
+ /**
102
+ * One catalog entry, shaped like the host's `SkillCandidate`.
103
+ *
104
+ * Declared here instead of imported: this plugin does not depend on the skill package (the
105
+ * registry is an optional injection), so the structural contract is restated rather than
106
+ * turning an optional neighbour into a build requirement. The registry merges these by the
107
+ * fields it reads, so a shape that satisfies them is the contract.
108
+ */
109
+ export interface SkillCandidateLike {
110
+ readonly name: string;
111
+ readonly description: string;
112
+ readonly invocation: {
113
+ readonly modelInvocable: boolean;
114
+ readonly userInvocable: boolean;
115
+ };
116
+ readonly source: 'bundled';
117
+ readonly provider: string;
118
+ readonly path: string;
119
+ readonly resourceBase: {
120
+ readonly kind: 'directory';
121
+ readonly path: string;
122
+ };
123
+ readonly rank: number;
124
+ readonly locator: string;
125
+ }
126
+ /** One loaded skill, shaped like the host's `SkillDefinition`. */
127
+ export interface SkillDefinitionLike extends SkillCandidateLike {
128
+ readonly content: string;
129
+ }
130
+ /**
131
+ * The skill provider that teaches the model to recognise document text.
132
+ *
133
+ * One bundled skill, read from disk on `get()` rather than kept in memory: the body is
134
+ * documentation, and a host that never asks for it should not pay for it.
135
+ *
136
+ * @returns a provider the skill registry can register.
137
+ */
138
+ export declare function ocrSkillProvider(): {
139
+ readonly name: string;
140
+ readonly list: (options: {
141
+ readonly cwd?: string;
142
+ readonly signal?: AbortSignal;
143
+ }) => Promise<readonly SkillCandidateLike[]>;
144
+ readonly get: (candidate: SkillCandidateLike, options: {
145
+ readonly cwd?: string;
146
+ readonly signal?: AbortSignal;
147
+ }) => Promise<SkillDefinitionLike | undefined>;
148
+ };
149
+ /**
150
+ * Read the bearer the browser gateway attached to one request.
151
+ *
152
+ * The page cannot supply its own credential: every browser request reaches this workspace
153
+ * through the DataOps gateway, which resolves the caller's session and forwards a fresh
154
+ * `authorization: Bearer <jwt>`. Relaying exactly that header is what keeps the backend's
155
+ * `AuthGuard` and `PermissionGuard` judging the CALLER rather than this plugin: the admin
156
+ * routes answer 403 for a member who is not a super administrator because the token in the
157
+ * header is theirs, not a service account's.
158
+ *
159
+ * @param request - the incoming request, whose headers the gateway filled in.
160
+ * @returns the token, or undefined when the request carries none.
161
+ */
162
+ export declare function bearerToken(request: IncomingMessage): string | undefined;
163
+ /** Deployment configuration for the settings relay. */
164
+ export interface OcrConfig {
165
+ /**
166
+ * DataOps backend origin.
167
+ *
168
+ * The settings page cannot reach the backend itself -- its credential is an httpOnly cookie
169
+ * while `/api/ocr/*` wants a bearer -- so this Host relays the four calls. The origin is a
170
+ * profile value rather than a constant because a self-hosted backend and a managed one are
171
+ * different addresses.
172
+ */
173
+ baseUrl: string;
174
+ /**
175
+ * Credential holding the DataOps JWT.
176
+ *
177
+ * Only a fallback: the request's own `authorization` header wins, because the backend must
178
+ * judge the CALLER. A service credential would make every member an administrator.
179
+ */
180
+ credentialRef: string;
181
+ /** Bound on one backend call. */
182
+ timeoutMs: number;
183
+ }
184
+ /** Config schema; an invalid value fails the profile load loudly. */
185
+ export declare const Config: z<OcrConfig>;
186
+ /** Everything the relay needs, resolved once at apply time. */
187
+ export interface OcrRelayConfig {
188
+ /** DataOps backend origin, e.g. `http://host.docker.internal:8080`. */
189
+ readonly baseUrl: string;
190
+ /** Credential name to fall back on when the request carries no bearer. */
191
+ readonly credentialRef: string;
192
+ /** Bound on one backend call. */
193
+ readonly timeoutMs: number;
194
+ }
195
+ /**
196
+ * Resolve the token one relayed call acts with.
197
+ *
198
+ * The caller's own header wins: it is the only value that makes the backend's permission
199
+ * checks correct. The stored credential is the fallback for a same-origin fetch that arrived
200
+ * without a header (a probe, or an older page); a plugin instance without either refuses
201
+ * rather than calling the backend anonymously, because an anonymous call would be answered
202
+ * 401 by the backend anyway and the page could not tell why.
203
+ *
204
+ * @param ctx - host context carrying the credential store.
205
+ * @param config - relay configuration.
206
+ * @param request - the incoming request.
207
+ * @returns the token, or undefined when neither source has one.
208
+ */
209
+ export declare function resolveRelayToken(ctx: {
210
+ credentials: {
211
+ resolve: (ref: unknown) => Promise<{
212
+ value: string;
213
+ } | undefined>;
214
+ };
215
+ }, config: OcrRelayConfig, request: IncomingMessage): Promise<string | undefined>;
216
+ /** One relayed call's result: the backend's status and decoded body. */
217
+ export interface RelayResult {
218
+ readonly status: number;
219
+ readonly body: unknown;
220
+ }
221
+ /**
222
+ * Call one DataOps OCR route with the caller's authority.
223
+ *
224
+ * Kept separate from the route handler so the mapping from a page method to a backend path
225
+ * is testable without a server.
226
+ *
227
+ * @param method - which of the four relayed routes the page asked for.
228
+ * @param config - backend origin, credential fallback, and the call bound.
229
+ * @param token - the bearer to act with; a call without one is refused before the round trip.
230
+ * @param body - the JSON body, for the two write routes.
231
+ * @returns the backend's status and decoded body.
232
+ */
233
+ export declare function callOcrBackend(method: OcrBackendMethod, config: OcrRelayConfig, token: string | undefined, body?: Record<string, unknown>): Promise<RelayResult>;
234
+ /** Longest a single connection test may block the settings panel. */
235
+ export declare const PROBE_TIMEOUT_MS = 8000;
236
+ /**
237
+ * Probe one MinerU address from this process.
238
+ *
239
+ * The OpenAPI document is the cheapest endpoint that both proves an HTTP server answers
240
+ * and identifies it: MinerU titles its document "MinerU API", so a 200 with that title is
241
+ * a real match rather than "something is listening on this port". Any other 200 is
242
+ * reported as `not-mineru` -- a proxy error page or a different service are both reasons
243
+ * the reader should not save the address.
244
+ *
245
+ * The probe deliberately does not use the caller's DataOps credential: MinerU is not a
246
+ * DataOps service and has its own (usually absent) auth. It also refuses non-http(s)
247
+ * schemes so the relay cannot be used to read `file:` or `ftp:` URLs.
248
+ * @param address - the candidate base address, as typed or as stored.
249
+ * @param timeoutMs - the caller's relay bound; the probe is clamped to {@link PROBE_TIMEOUT_MS}.
250
+ * @returns a structured verdict for the settings page.
251
+ */
252
+ export declare function probeMineruAddress(address: string, timeoutMs: number): Promise<OcrProbeView>;
253
+ /**
254
+ * Write one JSON reply.
255
+ *
256
+ * @param response - the browser-facing response.
257
+ * @param status - HTTP status to send.
258
+ * @param body - value to serialize.
259
+ */
260
+ export declare function writeJson(response: ServerResponse, status: number, body: unknown): void;
261
+ /**
262
+ * Read a JSON request body, treating an empty body as `{}`.
263
+ *
264
+ * @param request - the incoming request.
265
+ * @returns the parsed object.
266
+ */
267
+ export declare function readJsonBody(request: IncomingMessage): Promise<Record<string, unknown>>;
268
+ /**
269
+ * Answer one `test-connection` request.
270
+ *
271
+ * The stored config is read through the backend first, for two reasons that are really
272
+ * one: the backend is the authority on whether this caller may change the address, and a
273
+ * caller who may not change it must not be able to make this process fetch an arbitrary
274
+ * URL. A super administrator may test the value they are about to save; everyone else
275
+ * tests the shared value.
276
+ * @param ctx - the host context, for the caller's token.
277
+ * @param config - backend origin and probe bound.
278
+ * @param request - the browser request, whose body may carry a candidate address.
279
+ * @param response - the reply.
280
+ */
281
+ export declare function answerConnectionTest(ctx: OcrHostContext, config: OcrRelayConfig, request: IncomingMessage, response: ServerResponse): Promise<void>;
282
+ /** The subset of the host context this plugin uses. */
283
+ export interface OcrHostContext {
284
+ readonly credentials: {
285
+ resolve: (ref: unknown) => Promise<{
286
+ value: string;
287
+ } | undefined>;
288
+ };
289
+ readonly webServer: {
290
+ register: (options: {
291
+ kind: 'prefix';
292
+ path: string;
293
+ handler: (request: IncomingMessage, response: ServerResponse) => Promise<void>;
294
+ }) => () => void;
295
+ };
296
+ readonly logger?: {
297
+ warn: (...args: unknown[]) => void;
298
+ };
299
+ readonly effect: (run: () => () => void, label?: string) => void;
300
+ readonly inject?: (deps: readonly string[], run: (scoped: {
301
+ skills: {
302
+ registerProvider: (provider: () => unknown) => unknown;
303
+ };
304
+ }) => void) => void;
305
+ }
306
+ /**
307
+ * Mount the skill provider and the settings relay on a host context.
308
+ *
309
+ * `inject` rather than a hard dependency entry, and the `typeof` guard around it, are both
310
+ * copied from `@sparkelf/dsh-knowledge-base`: the skill registry is an optional neighbour, and
311
+ * calling `inject` on a host that does not expose it would throw during apply and take the
312
+ * whole plugin down.
313
+ *
314
+ * @param host - the plugin context.
315
+ * @param resolvedConfig - backend origin, credential fallback, and call bound.
316
+ */
317
+ export declare function apply(host: unknown, resolvedConfig?: Partial<OcrConfig>): void;