@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.
package/lib/client.js ADDED
@@ -0,0 +1,891 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@sparkelf/dsh-ocr",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let react = require("react");
8
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ //#region src/api.ts
11
+ /**
12
+ * The same-origin API surface shared by this package's two halves.
13
+ *
14
+ * The Host registers one prefix and dispatches on the trailing method name; the browser
15
+ * calls the same strings. Keeping them in one module is what stops the two halves
16
+ * drifting apart -- the failure mode knowledge-base recorded when its panel called
17
+ * `/knowledge-base/config` while its Host served `/knowledge-base/api/config`.
18
+ *
19
+ * The namespace is `ocr` rather than a shared one, so this route can never collide with
20
+ * the knowledge base's `/knowledge-base/api/*` or any other plugin's prefix.
21
+ *
22
+ * This module must stay dependency-free so both bundles can import it: the Client bundle
23
+ * rejects Node builtins and non-platform packages.
24
+ *
25
+ * @module @sparkelf/dsh-ocr/api
26
+ */
27
+ /** Prefix the Host registers and the browser calls. */
28
+ const OCR_API_PREFIX = "/ocr/api";
29
+ /** Method names the Host dispatches on. */
30
+ const OCR_API = {
31
+ /** The shared MinerU address plus whether the caller may change it. */
32
+ config: "config",
33
+ /** How many members a distribution reaches, and how many it would replace. */
34
+ impact: "impact",
35
+ /** Fill only members that hold no address of their own. */
36
+ distributeDefault: "distribute-default",
37
+ /** Replace every member's address, including ones they chose themselves. */
38
+ overwrite: "overwrite",
39
+ /**
40
+ * Probe a MinerU address before saving it.
41
+ *
42
+ * Not a backend route: the Host answers this one itself, because only this process can
43
+ * reach the address from inside the workspace network. It still reads the stored config
44
+ * through the backend first, so a caller who may not edit cannot make the relay fetch an
45
+ * arbitrary URL.
46
+ */
47
+ testConnection: "test-connection"
48
+ };
49
+ /**
50
+ * Build the browser path for one method.
51
+ * @param method - one of {@link OCR_API}.
52
+ * @returns the same-origin path the Host dispatches on.
53
+ */
54
+ function ocrApiPath(method) {
55
+ return `${OCR_API_PREFIX}/${method}`;
56
+ }
57
+ //#endregion
58
+ //#region src/client/styles.ts
59
+ /** The section's outer block: normal settings-page rhythm. */
60
+ const section = {
61
+ display: "flex",
62
+ flexDirection: "column",
63
+ gap: "12px"
64
+ };
65
+ /** A field label, matching the official settings page's 14px/22px label line. */
66
+ const label = {
67
+ fontSize: "14px",
68
+ fontWeight: 400,
69
+ lineHeight: "22px"
70
+ };
71
+ /** A grouped field: label above control. */
72
+ const field = {
73
+ display: "flex",
74
+ flexDirection: "column",
75
+ gap: "6px",
76
+ width: "100%"
77
+ };
78
+ /**
79
+ * The field row: the input primitive and the status tag share one box.
80
+ *
81
+ * A grid rather than a flex row because the primitive's wrapper is an inline-flex span:
82
+ * as a grid item it stretches to the column width, which a flex item with `flex: 0 1 auto`
83
+ * would not. The tag is positioned over the input's right edge, inside the border.
84
+ */
85
+ const addressBox = {
86
+ position: "relative",
87
+ display: "grid",
88
+ width: "100%"
89
+ };
90
+ /** The status tag's seat inside the input box. */
91
+ const tagSlot = {
92
+ position: "absolute",
93
+ right: "8px",
94
+ top: "50%",
95
+ transform: "translateY(-50%)",
96
+ display: "flex",
97
+ alignItems: "center",
98
+ pointerEvents: "auto"
99
+ };
100
+ /** A row of actions, right-aligned like the settings page's own footers. */
101
+ const actions = {
102
+ display: "flex",
103
+ flexWrap: "wrap",
104
+ gap: "8px",
105
+ alignItems: "center",
106
+ justifyContent: "flex-end"
107
+ };
108
+ /**
109
+ * The panel's bottom action row.
110
+ *
111
+ * Same width as the field, so the last button's right edge lands exactly on the input's
112
+ * right edge. The extra top margin is deliberate: the row must not crowd the status line
113
+ * under the input -- the failure reason and the buttons are different decisions, and a
114
+ * reader scanning the reason should not hit a button by accident.
115
+ */
116
+ const actionsBar = {
117
+ ...actions,
118
+ marginTop: "20px",
119
+ width: "100%",
120
+ boxSizing: "border-box",
121
+ paddingRight: "9px"
122
+ };
123
+ /** Secondary copy: what is stored, why it cannot be edited, what a result means. */
124
+ const detail = {
125
+ margin: 0,
126
+ fontSize: "12px",
127
+ lineHeight: "18px",
128
+ opacity: .72
129
+ };
130
+ /**
131
+ * A failed connection's reason.
132
+ *
133
+ * Red because the state is an error, smaller than body copy because it is supporting
134
+ * evidence rather than a sentence to read at the same weight as the field, and still
135
+ * selectable so an operator can copy the transport message into a ticket.
136
+ */
137
+ const errorDetail = {
138
+ margin: 0,
139
+ fontSize: "12px",
140
+ lineHeight: 1.5,
141
+ color: "var(--dsw-alias-state-error-primary)",
142
+ overflowWrap: "anywhere"
143
+ };
144
+ /** The confirmation block and the result block share this outline. */
145
+ const panel = {
146
+ display: "flex",
147
+ flexDirection: "column",
148
+ gap: "8px",
149
+ padding: "12px",
150
+ border: "1px solid var(--dsw-alias-border-default, currentColor)",
151
+ borderRadius: "8px",
152
+ width: "100%",
153
+ boxSizing: "border-box"
154
+ };
155
+ /** The four result counts. */
156
+ const counts = {
157
+ display: "grid",
158
+ gridTemplateColumns: "repeat(auto-fit, minmax(88px, 1fr))",
159
+ gap: "8px",
160
+ margin: 0
161
+ };
162
+ /** One count: the number leads, the label under it. */
163
+ const count = {
164
+ display: "flex",
165
+ flexDirection: "column",
166
+ gap: "2px"
167
+ };
168
+ /** A count's number. */
169
+ const countValue = {
170
+ margin: 0,
171
+ fontSize: "20px",
172
+ fontVariantNumeric: "tabular-nums"
173
+ };
174
+ //#endregion
175
+ //#region src/client/SettingsSection.tsx
176
+ /**
177
+ * The 「文档识别」 settings section.
178
+ *
179
+ * Three actions, and they are genuinely different:
180
+ *
181
+ * - **Test connection** probes the address in the field without saving it. It is the only
182
+ * way to answer "is this address right?" before distributing it to every member.
183
+ * - **Distribute** fills members who hold no address of their own. Nobody's own choice is
184
+ * touched, so it is the safe default.
185
+ * - **Overwrite** replaces every member's address, including one they typed themselves.
186
+ *
187
+ * Both writes are gated on `canEdit`, which the backend answers from the caller's role.
188
+ * The write routes enforce that independently: hiding a button is not a permission, so a
189
+ * caller who forges the request is refused by the backend rather than by this page.
190
+ *
191
+ * The section deliberately carries no explanatory prose: a settings page states the field
192
+ * and its state, and the reader who needs the story has the skill document. The connection
193
+ * tag inside the field is the whole status surface.
194
+ *
195
+ * @module @sparkelf/dsh-ocr/client/SettingsSection
196
+ */
197
+ /**
198
+ * Read one JSON route, refusing a non-2xx answer with the backend's own message.
199
+ *
200
+ * The backend explains a refusal in the reader's language ("分发内容为空", a permission
201
+ * message), and that text is what belongs on the page: a status code alone would send the
202
+ * administrator looking in the wrong place.
203
+ *
204
+ * @param method - one of {@link OCR_API}.
205
+ * @param body - the JSON body for a write, omitted for a read.
206
+ * @returns the decoded reply.
207
+ */
208
+ async function request(method, body) {
209
+ const response = await fetch(ocrApiPath(method), {
210
+ method: body === void 0 ? "GET" : "POST",
211
+ ...body === void 0 ? {} : {
212
+ headers: { "content-type": "application/json" },
213
+ body: JSON.stringify(body)
214
+ },
215
+ cache: "no-store"
216
+ });
217
+ const decoded = await response.json().catch(() => ({}));
218
+ if (!response.ok) throw new Error(decoded.error ?? `HTTP ${String(response.status)}`);
219
+ return decoded;
220
+ }
221
+ /**
222
+ * Whether a candidate is an absolute http(s) address.
223
+ *
224
+ * Mirrors the backend's own normaliser, and is checked before the round trip so the answer
225
+ * lands beside the field that was typed into rather than after a request that was always
226
+ * going to be refused. The path is preserved: a MinerU service may sit behind a prefix.
227
+ *
228
+ * @param value - the address as typed.
229
+ * @returns true when it parses and carries an http(s) scheme.
230
+ */
231
+ function isAbsoluteHttpAddress(value) {
232
+ const trimmed = value.trim();
233
+ if (trimmed === "") return false;
234
+ let parsed;
235
+ try {
236
+ parsed = new URL(trimmed);
237
+ } catch {
238
+ return false;
239
+ }
240
+ return parsed.protocol === "http:" || parsed.protocol === "https:";
241
+ }
242
+ /**
243
+ * Render the document-recognition settings section.
244
+ * @param props - the Settings slot injection.
245
+ * @returns the section, or nothing before injection.
246
+ */
247
+ function OcrSettingsSection(props) {
248
+ const { t } = props;
249
+ if (t === void 0) return null;
250
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Loaded, { t });
251
+ }
252
+ /** The section once the locale resolver is available. */
253
+ function Loaded({ t }) {
254
+ const [state, setState] = (0, react.useState)({ kind: "loading" });
255
+ const [draft, setDraft] = (0, react.useState)(void 0);
256
+ const [pending, setPending] = (0, react.useState)(void 0);
257
+ const [impact, setImpact] = (0, react.useState)(void 0);
258
+ const [counting, setCounting] = (0, react.useState)(false);
259
+ const [busy, setBusy] = (0, react.useState)(false);
260
+ const [outcome, setOutcome] = (0, react.useState)({ kind: "idle" });
261
+ const [connection, setConnection] = (0, react.useState)({ kind: "untested" });
262
+ const load = (0, react.useCallback)(async () => {
263
+ setState({ kind: "loading" });
264
+ try {
265
+ const config = await request(OCR_API.config);
266
+ setState({
267
+ kind: "ready",
268
+ config: {
269
+ mineruUrl: typeof config.mineruUrl === "string" ? config.mineruUrl : "",
270
+ canEdit: config.canEdit === true
271
+ }
272
+ });
273
+ setDraft(void 0);
274
+ setOutcome({ kind: "idle" });
275
+ setConnection({ kind: "untested" });
276
+ } catch {
277
+ setState({ kind: "unavailable" });
278
+ }
279
+ }, []);
280
+ (0, react.useEffect)(() => {
281
+ load();
282
+ }, [load]);
283
+ const shown = draft ?? (state.kind === "ready" ? state.config.mineruUrl : "");
284
+ (0, react.useEffect)(() => {
285
+ setConnection((current) => current.kind === "ok" || current.kind === "failed" ? current.url === shown.trim() ? current : { kind: "untested" } : current);
286
+ }, [shown]);
287
+ /**
288
+ * Open a confirmation for one action, reading the impact count first.
289
+ *
290
+ * The count is what makes the confirmation honest: an overwrite names how many members
291
+ * already have a value, which is exactly the set it would destroy. A confirmation that
292
+ * could not state a number would be asking for approval of an unknown quantity.
293
+ *
294
+ * @param action - which of the two writes the reader pressed.
295
+ */
296
+ const begin = (0, react.useCallback)(async (action) => {
297
+ setPending(action);
298
+ setImpact(void 0);
299
+ setCounting(true);
300
+ try {
301
+ setImpact(await request(OCR_API.impact));
302
+ } catch {
303
+ setImpact(void 0);
304
+ } finally {
305
+ setCounting(false);
306
+ }
307
+ }, []);
308
+ /** Run the confirmed action and report its four counts. */
309
+ const confirm = (0, react.useCallback)(async (action) => {
310
+ if (state.kind !== "ready") return;
311
+ const address = (draft ?? state.config.mineruUrl).trim();
312
+ if (!isAbsoluteHttpAddress(address)) {
313
+ setPending(void 0);
314
+ setOutcome({
315
+ kind: "failed",
316
+ message: t("badAddress")
317
+ });
318
+ return;
319
+ }
320
+ setBusy(true);
321
+ setPending(void 0);
322
+ try {
323
+ const result = await request(action === "overwrite" ? OCR_API.overwrite : OCR_API.distributeDefault, { mineruUrl: address });
324
+ const nothingChanged = action === "distribute-default" && result.filled === 0 && result.failed === 0 && result.total > 0;
325
+ setOutcome(nothingChanged ? { kind: "nothing" } : {
326
+ kind: "counts",
327
+ result
328
+ });
329
+ setState((current) => current.kind === "ready" ? {
330
+ ...current,
331
+ config: {
332
+ ...current.config,
333
+ mineruUrl: address
334
+ }
335
+ } : current);
336
+ setDraft(void 0);
337
+ } catch (error) {
338
+ setOutcome({
339
+ kind: "failed",
340
+ message: t("failure").replace("{reason}", error instanceof Error ? error.message : String(error))
341
+ });
342
+ } finally {
343
+ setBusy(false);
344
+ }
345
+ }, [
346
+ draft,
347
+ state,
348
+ t
349
+ ]);
350
+ /**
351
+ * Probe the address currently in the field.
352
+ *
353
+ * The Host answers this itself (it is the process inside the workspace network) but
354
+ * checks the caller's role with the backend first, so a member who cannot edit cannot
355
+ * turn the relay into a URL fetcher.
356
+ */
357
+ const test = (0, react.useCallback)(async () => {
358
+ const address = shown.trim();
359
+ if (!isAbsoluteHttpAddress(address)) {
360
+ setConnection({
361
+ kind: "failed",
362
+ code: "bad-url",
363
+ url: address
364
+ });
365
+ return;
366
+ }
367
+ setConnection({ kind: "testing" });
368
+ try {
369
+ const result = await request(OCR_API.testConnection, { mineruUrl: address });
370
+ if (result.ok) {
371
+ setConnection({
372
+ kind: "ok",
373
+ latencyMs: result.latencyMs,
374
+ url: result.testedUrl
375
+ });
376
+ return;
377
+ }
378
+ setConnection({
379
+ kind: "failed",
380
+ code: result.code,
381
+ ...result.status === void 0 ? {} : { status: result.status },
382
+ ...result.message === void 0 ? {} : { message: result.message },
383
+ url: result.testedUrl
384
+ });
385
+ } catch (error) {
386
+ setConnection({
387
+ kind: "failed",
388
+ code: "unreachable",
389
+ message: error instanceof Error ? error.message : String(error),
390
+ url: address
391
+ });
392
+ }
393
+ }, [shown]);
394
+ if (state.kind === "loading") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
395
+ style: section,
396
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
397
+ style: detail,
398
+ role: "status",
399
+ children: t("loading")
400
+ })
401
+ });
402
+ if (state.kind === "unavailable") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
403
+ style: section,
404
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
405
+ style: detail,
406
+ role: "alert",
407
+ children: t("unavailable")
408
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
409
+ style: detail,
410
+ children: t("unavailableDetail")
411
+ })]
412
+ });
413
+ const { config } = state;
414
+ const action = pending ?? "distribute-default";
415
+ /**
416
+ * The confirmation sentence with its numbers filled in.
417
+ *
418
+ * A failed count leaves `impact` undefined, and the placeholders then read `?` rather than
419
+ * a number this page does not have: inventing one would make the confirmation claim a
420
+ * blast radius it never measured.
421
+ */
422
+ const confirmation = (action === "overwrite" ? t("confirmOverwrite") : t("confirmDistribute")).replace("{withValue}", impact === void 0 ? "?" : String(impact.withValue)).replace("{withoutValue}", impact === void 0 ? "?" : String(impact.withoutValue)).replace("{total}", impact === void 0 ? "?" : String(impact.total));
423
+ /** The tag's palette and label for the current connection state. */
424
+ const tag = (() => {
425
+ if (connection.kind === "testing") return {
426
+ tone: "warning",
427
+ label: t("connectionTesting")
428
+ };
429
+ if (connection.kind === "ok") return {
430
+ tone: "success",
431
+ label: t("connectionConnected")
432
+ };
433
+ if (connection.kind === "failed") return {
434
+ tone: "danger",
435
+ label: t("connectionFailed")
436
+ };
437
+ return {
438
+ tone: "neutral",
439
+ label: t("connectionUntested")
440
+ };
441
+ })();
442
+ /** One line of evidence under the field: latency on success, the reason on failure. */
443
+ const connectionDetail = (() => {
444
+ if (connection.kind === "ok") return t("connectionLatency").replace("{ms}", String(connection.latencyMs));
445
+ if (connection.kind === "failed") {
446
+ if (connection.code === "bad-url") return t("probeBadUrl");
447
+ if (connection.code === "timeout") return t("probeTimeout");
448
+ if (connection.code === "http-error") return t("probeHttpError").replace("{status}", String(connection.status ?? "?"));
449
+ if (connection.code === "not-mineru") return t("probeNotMineru").replace("{title}", connection.message ?? "?");
450
+ return t("probeUnreachable").replace("{reason}", connection.message ?? "?");
451
+ }
452
+ })();
453
+ const tagNode = connection.kind === "failed" && connectionDetail !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
454
+ label: connectionDetail,
455
+ portal: true,
456
+ side: "top",
457
+ align: "end",
458
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
459
+ tone: tag.tone,
460
+ children: tag.label
461
+ })
462
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
463
+ tone: tag.tone,
464
+ children: tag.label
465
+ });
466
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
467
+ style: section,
468
+ "aria-label": t("title"),
469
+ children: [
470
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
471
+ style: field,
472
+ children: [
473
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
474
+ htmlFor: "ocr-mineru-address",
475
+ style: label,
476
+ children: t("addressLabel")
477
+ }),
478
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
479
+ style: addressBox,
480
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Input, {
481
+ id: "ocr-mineru-address",
482
+ type: "url",
483
+ inputMode: "url",
484
+ value: shown,
485
+ placeholder: t("addressPlaceholder"),
486
+ disabled: !config.canEdit || busy,
487
+ "aria-describedby": connectionDetail === void 0 ? void 0 : "ocr-connection-detail",
488
+ style: { paddingRight: "104px" },
489
+ onChange: (event) => {
490
+ setDraft(event.target.value);
491
+ }
492
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
493
+ style: tagSlot,
494
+ children: tagNode
495
+ })]
496
+ }),
497
+ connectionDetail !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
498
+ id: "ocr-connection-detail",
499
+ style: connection.kind === "failed" ? errorDetail : detail,
500
+ role: "status",
501
+ children: connectionDetail
502
+ }),
503
+ !config.canEdit && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
504
+ style: detail,
505
+ children: t("readOnly")
506
+ })
507
+ ]
508
+ }),
509
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
510
+ style: actionsBar,
511
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
512
+ variant: "outline",
513
+ size: "sm",
514
+ disabled: busy || shown.trim() === "" || connection.kind === "testing",
515
+ onClick: () => {
516
+ test();
517
+ },
518
+ children: t("testConnection")
519
+ }), config.canEdit && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
520
+ variant: "outline",
521
+ size: "sm",
522
+ disabled: busy,
523
+ onClick: () => {
524
+ begin("distribute-default");
525
+ },
526
+ children: t("distributeDefault")
527
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
528
+ variant: "primary",
529
+ size: "sm",
530
+ disabled: busy,
531
+ onClick: () => {
532
+ begin("overwrite");
533
+ },
534
+ children: t("overwrite")
535
+ })] })]
536
+ }),
537
+ pending !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
538
+ style: panel,
539
+ role: "dialog",
540
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
541
+ style: detail,
542
+ children: counting ? t("counting") : confirmation
543
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
544
+ style: actions,
545
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
546
+ variant: "outline",
547
+ disabled: busy,
548
+ onClick: () => {
549
+ setPending(void 0);
550
+ },
551
+ children: t("cancel")
552
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
553
+ variant: "primary",
554
+ disabled: busy || counting,
555
+ onClick: () => {
556
+ confirm(action);
557
+ },
558
+ children: busy ? t("saving") : t("confirm")
559
+ })]
560
+ })]
561
+ }),
562
+ outcome.kind === "nothing" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
563
+ style: detail,
564
+ role: "status",
565
+ children: t("nothingToDo")
566
+ }),
567
+ outcome.kind === "failed" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
568
+ style: detail,
569
+ role: "alert",
570
+ children: outcome.message
571
+ }),
572
+ outcome.kind === "counts" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
573
+ style: panel,
574
+ role: "status",
575
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
576
+ style: detail,
577
+ children: t("resultTitle")
578
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("dl", {
579
+ style: counts,
580
+ children: [
581
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
582
+ style: count,
583
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", {
584
+ style: detail,
585
+ children: t("resultFilled")
586
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", {
587
+ style: countValue,
588
+ children: outcome.result.filled
589
+ })]
590
+ }),
591
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
592
+ style: count,
593
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", {
594
+ style: detail,
595
+ children: t("resultSkipped")
596
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", {
597
+ style: countValue,
598
+ children: outcome.result.skipped
599
+ })]
600
+ }),
601
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
602
+ style: count,
603
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", {
604
+ style: detail,
605
+ children: t("resultFailed")
606
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", {
607
+ style: countValue,
608
+ children: outcome.result.failed
609
+ })]
610
+ }),
611
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
612
+ style: count,
613
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", {
614
+ style: detail,
615
+ children: t("resultTotal")
616
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", {
617
+ style: countValue,
618
+ children: outcome.result.total
619
+ })]
620
+ })
621
+ ]
622
+ })]
623
+ })
624
+ ]
625
+ });
626
+ }
627
+ //#endregion
628
+ //#region src/client/locales.ts
629
+ /**
630
+ * Settings copy for the document-recognition section.
631
+ *
632
+ * One English object is the key set and each other locale is a complete record over it,
633
+ * so a missing translation fails to compile rather than falling back at runtime. That is
634
+ * the shape every locale-backed DSH client plugin uses.
635
+ *
636
+ * The reader-facing name is 「文档识别」, matching the skill's own display name in
637
+ * `i18n/zh.json`. Both say what the feature is for rather than naming the backend: MinerU
638
+ * is the implementation, and a reader who has never heard of it still has to find this page.
639
+ *
640
+ * @module @sparkelf/dsh-ocr/client/locales
641
+ */
642
+ /** English copy for the document-recognition settings section. */
643
+ const en = {
644
+ /** Settings navigation entry. */
645
+ nav: "Document recognition",
646
+ /** Accessible name of the section; the page itself shows no second heading. */
647
+ title: "Document text recognition",
648
+ /** Address field label; the only visible label in the section. */
649
+ addressLabel: "MinerU service address",
650
+ /** Placeholder for the address field. */
651
+ addressPlaceholder: "http://172.17.0.1:8000",
652
+ /** Shown while the stored value is being read. */
653
+ loading: "Loading…",
654
+ /** Shown when the Host route cannot answer at all. */
655
+ unavailable: "The document-recognition settings are unavailable.",
656
+ /** Explains {@link unavailable}. */
657
+ unavailableDetail: "The plugin could not reach its own settings route. Reload the page; if this persists, the plugin is not mounted on this deployment.",
658
+ /** Whether the current caller may change the value. */
659
+ readOnly: "Only a super administrator can change this.",
660
+ /** Button that probes the address without saving it. */
661
+ testConnection: "Test connection",
662
+ /** Connection tag: nothing has been probed in this page yet. */
663
+ connectionUntested: "Untested",
664
+ /** Connection tag: the probe is in flight. */
665
+ connectionTesting: "Testing…",
666
+ /** Connection tag: the address answered as MinerU. */
667
+ connectionConnected: "Connected",
668
+ /** Connection tag: the probe failed. */
669
+ connectionFailed: "Connection failed",
670
+ /** Latency under the field after a successful probe. */
671
+ connectionLatency: "{ms} ms",
672
+ /** Probe detail: not an absolute http(s) address. */
673
+ probeBadUrl: "Enter an absolute http or https address",
674
+ /** Probe detail: no answer inside the probe window. */
675
+ probeTimeout: "The address did not answer in time",
676
+ /** Probe detail: refused, unknown host, or unreachable. */
677
+ probeUnreachable: "Could not connect: {reason}",
678
+ /** Probe detail: an HTTP server answered, but it is not MinerU. */
679
+ probeNotMineru: "The address answers, but it is not a MinerU service ({title})",
680
+ /** Probe detail: a non-2xx status. */
681
+ probeHttpError: "The service answered HTTP {status}",
682
+ /** Probe detail: the Host could not check the caller's role first. */
683
+ probeUnavailable: "The connection test is unavailable right now",
684
+ /** Label of the button that fills empty members only. */
685
+ distributeDefault: "Distribute to members without a value",
686
+ /** Label of the button that replaces every member's value. */
687
+ overwrite: "Save and overwrite every member",
688
+ /** Shown while a write is in flight. */
689
+ saving: "Saving…",
690
+ /** Shown while the impact count is being read. */
691
+ counting: "Counting members…",
692
+ /**
693
+ * The overwrite confirmation.
694
+ *
695
+ * Both numbers are load-bearing: `{withValue}` is what the action destroys and
696
+ * `{total}` is the size of the population, so the reader can see the blast radius
697
+ * instead of being asked a bare "are you sure?".
698
+ */
699
+ confirmOverwrite: "This replaces the address {withValue} of {total} members already set. This cannot be undone. Continue?",
700
+ /** The distribute confirmation. */
701
+ confirmDistribute: "Fill the address for {withoutValue} of {total} members that have none. Continue?",
702
+ /** Confirm button. */
703
+ confirm: "Continue",
704
+ /** Cancel button. */
705
+ cancel: "Cancel",
706
+ /** Result headline after a write, before the four counts. */
707
+ resultTitle: "Distribution finished",
708
+ /** One count in the result row. */
709
+ resultFilled: "Written",
710
+ /** One count in the result row. */
711
+ resultSkipped: "Skipped",
712
+ /** One count in the result row. */
713
+ resultFailed: "Failed",
714
+ /** One count in the result row. */
715
+ resultTotal: "Considered",
716
+ /** A write that failed as a whole, before any per-member counting. */
717
+ failure: "The change did not go through: {reason}",
718
+ /** The address typed in is not an absolute http(s) address. */
719
+ badAddress: "Enter an absolute http or https address, for example http://172.17.0.1:8000",
720
+ /** Status line for a distribution that wrote nothing because everyone had a value. */
721
+ nothingToDo: "Nothing to change: every member already has an address."
722
+ };
723
+ /** Chinese copy; a complete record over {@link en}, so a missing key fails to compile. */
724
+ const zh = {
725
+ nav: "文档识别",
726
+ title: "文档文字识别",
727
+ addressLabel: "MinerU 服务地址",
728
+ addressPlaceholder: "http://172.17.0.1:8000",
729
+ loading: "加载中…",
730
+ unavailable: "文档识别设置不可用。",
731
+ unavailableDetail: "插件访问不到自己的设置路由。请刷新页面;若一直如此,说明该部署没有挂载这个插件。",
732
+ readOnly: "仅超级管理员可修改。",
733
+ testConnection: "测试连接",
734
+ connectionUntested: "未测试",
735
+ connectionTesting: "测试中…",
736
+ connectionConnected: "已连接",
737
+ connectionFailed: "连接失败",
738
+ connectionLatency: "{ms} ms",
739
+ probeBadUrl: "请填写完整的 http 或 https 地址",
740
+ probeTimeout: "地址在超时时间内没有响应",
741
+ probeUnreachable: "无法连接:{reason}",
742
+ probeNotMineru: "地址可访问,但不是 MinerU 服务({title})",
743
+ probeHttpError: "服务返回 HTTP {status}",
744
+ probeUnavailable: "当前无法测试连接",
745
+ distributeDefault: "分发给未填写地址的成员",
746
+ overwrite: "保存并覆盖全部成员",
747
+ saving: "保存中…",
748
+ counting: "正在统计成员…",
749
+ confirmOverwrite: "这会把 {withValue} 位已填写地址的成员一并覆盖,共涉及 {total} 位成员,且无法撤销。继续?",
750
+ confirmDistribute: "将为 {total} 位成员中缺地址的 {withoutValue} 位填写该地址。继续?",
751
+ confirm: "继续",
752
+ cancel: "取消",
753
+ resultTitle: "分发完成",
754
+ resultFilled: "已填写",
755
+ resultSkipped: "已跳过",
756
+ resultFailed: "失败",
757
+ resultTotal: "共处理",
758
+ failure: "本次修改未生效:{reason}",
759
+ badAddress: "请填写完整的 http 或 https 地址,例如 http://172.17.0.1:8000",
760
+ nothingToDo: "无需改动:所有成员都已填写地址。"
761
+ };
762
+ //#endregion
763
+ //#region src/client/sectionVisibility.ts
764
+ /**
765
+ * Who may see the document-recognition Settings section.
766
+ *
767
+ * The section configures one deployment-wide address and offers distribution writes, so it
768
+ * belongs to the roles that administer the deployment. Every other member still USES the
769
+ * shared address through the skill; they simply have no settings entry to change it.
770
+ *
771
+ * Registration is conditional rather than a component that renders null: an unauthorized
772
+ * reader must not find a「文档识别」row in Settings at all. The role can change without a
773
+ * reload (the portal re-posts the identity), so the decision is re-evaluated whenever the
774
+ * account bridge says the user changed.
775
+ *
776
+ * @module @sparkelf/dsh-ocr/client/section-owner
777
+ */
778
+ /** The event the DataOps account bridge dispatches after the identity changes. */
779
+ const ACCOUNT_CHANGED_EVENT = "dataops-account:changed";
780
+ /** Role names that may configure the shared MinerU address. Exact match, by design. */
781
+ const OCR_SETTINGS_ROLES = ["超级管理员", "管理员"];
782
+ /**
783
+ * Whether one DataOps role name may open the section.
784
+ *
785
+ * Exact equality: a role called「管理员助理」or「超级管理员(试用)」is a different role and
786
+ * must not inherit the write surface by prefix. An absent identity is unauthorized: the
787
+ * section is not something to show optimistically before the portal has answered.
788
+ * @param name - `window.__DATAOPS_USER__.name`, when known.
789
+ * @returns whether the section should be registered.
790
+ */
791
+ function isOcrSettingsVisible(name) {
792
+ return typeof name === "string" && OCR_SETTINGS_ROLES.includes(name);
793
+ }
794
+ /**
795
+ * Register the section only while the current identity is authorized, and follow changes.
796
+ *
797
+ * The disposer removes the event listener and the extra observer, and disposes any section
798
+ * currently registered. Calling it is what lets Cordis unload the plugin without leaving a
799
+ * Settings row behind.
800
+ * @param options - window, registrar, and optional observer/error hook.
801
+ * @returns a disposer for the whole conditional contribution.
802
+ */
803
+ function installConditionalSection(options) {
804
+ let disposeSection;
805
+ const sync = () => {
806
+ disposeSection?.();
807
+ disposeSection = void 0;
808
+ const name = options.window.__DATAOPS_USER__?.name;
809
+ if (!isOcrSettingsVisible(typeof name === "string" ? name : void 0)) return;
810
+ try {
811
+ disposeSection = options.register();
812
+ } catch (error) {
813
+ options.onError?.(error);
814
+ }
815
+ };
816
+ sync();
817
+ const onChange = () => {
818
+ sync();
819
+ };
820
+ options.window.addEventListener(ACCOUNT_CHANGED_EVENT, onChange);
821
+ const disposeObserver = options.observe?.(sync);
822
+ return () => {
823
+ options.window.removeEventListener(ACCOUNT_CHANGED_EVENT, onChange);
824
+ disposeObserver?.();
825
+ disposeSection?.();
826
+ disposeSection = void 0;
827
+ };
828
+ }
829
+ //#endregion
830
+ //#region src/client/index.ts
831
+ /** Locale namespace this plugin owns. */
832
+ const NS = "settingsOcr";
833
+ /** Settings entry id; also the `id` the section registers under. */
834
+ const SECTION_ID = "ocr";
835
+ /**
836
+ * Rank places this section beside the other DataOps capabilities.
837
+ *
838
+ * The knowledge base uses 35 and Mobile Bridge uses 40, so this one follows them. The value
839
+ * orders the Settings navigation, not a priority.
840
+ */
841
+ const SECTION_ORDER = 36;
842
+ /** Services the browser half needs to contribute a Settings section. */
843
+ const inject = ["slots", "locale"];
844
+ /**
845
+ * Register the document-recognition Settings section.
846
+ * @param ctx - the DSH client context carrying the slot and locale registries.
847
+ */
848
+ function apply(ctx) {
849
+ ctx.effect(() => ctx.locale.register(NS, {
850
+ zh,
851
+ en
852
+ }), "dsh-ocr: dictionaries");
853
+ ctx.slots.inject("settings.section", () => {
854
+ if (typeof window === "undefined") return () => {};
855
+ return installConditionalSection({
856
+ window,
857
+ register: () => ctx.slots.register({
858
+ name: "settings.section",
859
+ id: SECTION_ID,
860
+ order: SECTION_ORDER,
861
+ label: () => ctx.locale.bind(NS)("nav"),
862
+ locale: NS,
863
+ inject: () => ({ t: ctx.locale.bind(NS) })
864
+ }, OcrSettingsSection),
865
+ observe: (sync) => {
866
+ if (typeof MutationObserver === "undefined" || typeof document === "undefined") return () => {};
867
+ const observer = new MutationObserver(() => {
868
+ sync();
869
+ });
870
+ observer.observe(document.documentElement, {
871
+ attributes: true,
872
+ attributeFilter: ["data-dataops-account-name"]
873
+ });
874
+ return () => {
875
+ observer.disconnect();
876
+ };
877
+ },
878
+ onError: (error) => {
879
+ console.error("dsh-ocr: settings section registration rejected", error);
880
+ }
881
+ });
882
+ });
883
+ }
884
+ //#endregion
885
+ exports.apply = apply;
886
+ exports.inject = inject;
887
+ return module.exports;
888
+ }
889
+ });
890
+
891
+ //# sourceMappingURL=client.js.map