dsh-ab-ocr 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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +378 -0
  3. package/cordis.patch.yml +7 -0
  4. package/lib/artifacts.d.ts +100 -0
  5. package/lib/artifacts.d.ts.map +1 -0
  6. package/lib/artifacts.js +97 -0
  7. package/lib/artifacts.js.map +1 -0
  8. package/lib/config.d.ts +77 -0
  9. package/lib/config.d.ts.map +1 -0
  10. package/lib/config.js +51 -0
  11. package/lib/config.js.map +1 -0
  12. package/lib/documents.d.ts +62 -0
  13. package/lib/documents.d.ts.map +1 -0
  14. package/lib/documents.js +173 -0
  15. package/lib/documents.js.map +1 -0
  16. package/lib/events.d.ts +161 -0
  17. package/lib/events.d.ts.map +1 -0
  18. package/lib/events.js +158 -0
  19. package/lib/events.js.map +1 -0
  20. package/lib/filename.d.ts +47 -0
  21. package/lib/filename.d.ts.map +1 -0
  22. package/lib/filename.js +77 -0
  23. package/lib/filename.js.map +1 -0
  24. package/lib/index.d.ts +85 -0
  25. package/lib/index.d.ts.map +1 -0
  26. package/lib/index.js +1761 -0
  27. package/lib/index.js.map +1 -0
  28. package/lib/levels.d.ts +24 -0
  29. package/lib/levels.d.ts.map +1 -0
  30. package/lib/levels.js +52 -0
  31. package/lib/levels.js.map +1 -0
  32. package/lib/plan.d.ts +103 -0
  33. package/lib/plan.d.ts.map +1 -0
  34. package/lib/plan.js +210 -0
  35. package/lib/plan.js.map +1 -0
  36. package/lib/recognize.d.ts +36 -0
  37. package/lib/recognize.d.ts.map +1 -0
  38. package/lib/recognize.js +390 -0
  39. package/lib/recognize.js.map +1 -0
  40. package/lib/records.d.ts +91 -0
  41. package/lib/records.d.ts.map +1 -0
  42. package/lib/records.js +130 -0
  43. package/lib/records.js.map +1 -0
  44. package/lib/render.d.ts +19 -0
  45. package/lib/render.d.ts.map +1 -0
  46. package/lib/render.js +45 -0
  47. package/lib/render.js.map +1 -0
  48. package/lib/sandbox.d.ts +54 -0
  49. package/lib/sandbox.d.ts.map +1 -0
  50. package/lib/sandbox.js +101 -0
  51. package/lib/sandbox.js.map +1 -0
  52. package/lib/types.d.ts +147 -0
  53. package/lib/types.d.ts.map +1 -0
  54. package/lib/types.js +7 -0
  55. package/lib/types.js.map +1 -0
  56. package/lib/worker.d.ts +107 -0
  57. package/lib/worker.d.ts.map +1 -0
  58. package/lib/worker.js +143 -0
  59. package/lib/worker.js.map +1 -0
  60. package/package.json +98 -0
  61. package/python/README.md +125 -0
  62. package/python/assemble.py +358 -0
  63. package/python/clean.py +197 -0
  64. package/python/layout.py +403 -0
  65. package/python/ocr_worker.py +516 -0
  66. package/python/requirements.txt +16 -0
  67. package/python/source.py +182 -0
  68. package/scripts/setup.mjs +251 -0
  69. package/tsconfig.json +30 -0
  70. package/tsdown.config.ts +18 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAGH,OAAO,EAAE,UAAU,EAAwB,MAAM,wBAAwB,CAAA;AAIzE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAIxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAClH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAA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,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAA;YACtF,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;YACrC,OAAO,SAAS,CACd,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EACb,IAAI,EACJ,MAAM,EACN,KAAK,EAAE,aAAa,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EACzE,IAAI,CAAC,MAAM,EACX,KAAK,CACN,CAAA;QACH,CAAC;QACD,WAAW;KACZ,CAAC,CAAC,CAAA;AACL,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The `levels` request value: heading-level corrections a caller makes after
3
+ * reading the outline a recognition saved.
4
+ *
5
+ * The value is compact because the model writes it: `"h12=2,h15=0,h20=3"`,
6
+ * where the id is an outline candidate and the number is the Markdown heading
7
+ * depth it should take. Zero, or anything below it, takes the line out of the
8
+ * heading hierarchy and leaves it as body text, which is what makes the pass
9
+ * able to demote a line the merge promoted. Anything else is rejected rather
10
+ * than half-applied.
11
+ * @module @deepseek-ai/dsh-ab-ocr/levels
12
+ */
13
+ /** Candidate ids mapped to the heading level each should take. */
14
+ export type LevelOverrides = Record<string, number>;
15
+ /**
16
+ * Parse the corrections one `levels` value carries.
17
+ * @param value - the model-supplied value.
18
+ * @returns the candidate id to heading level corrections.
19
+ * @throws Error when the value is empty, when a piece is not `<id>=<level>`,
20
+ * when the level is not a whole number, or when two pieces give one
21
+ * candidate different levels.
22
+ */
23
+ export declare function parseLevels(value: string): LevelOverrides;
24
+ //# sourceMappingURL=levels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"levels.d.ts","sourceRoot":"","sources":["../src/levels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,kEAAkE;AAClE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAQnD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CA8BzD"}
package/lib/levels.js ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The `levels` request value: heading-level corrections a caller makes after
3
+ * reading the outline a recognition saved.
4
+ *
5
+ * The value is compact because the model writes it: `"h12=2,h15=0,h20=3"`,
6
+ * where the id is an outline candidate and the number is the Markdown heading
7
+ * depth it should take. Zero, or anything below it, takes the line out of the
8
+ * heading hierarchy and leaves it as body text, which is what makes the pass
9
+ * able to demote a line the merge promoted. Anything else is rejected rather
10
+ * than half-applied.
11
+ * @module @deepseek-ai/dsh-ab-ocr/levels
12
+ */
13
+ /** One correction: an outline candidate id, then the level it should take. */
14
+ const CORRECTION = /^h([1-9][0-9]*)=(.+)$/;
15
+ /** A level the worker accepts: a whole number, 0 or below meaning body text. */
16
+ const LEVEL = /^-?[0-9]+$/;
17
+ /**
18
+ * Parse the corrections one `levels` value carries.
19
+ * @param value - the model-supplied value.
20
+ * @returns the candidate id to heading level corrections.
21
+ * @throws Error when the value is empty, when a piece is not `<id>=<level>`,
22
+ * when the level is not a whole number, or when two pieces give one
23
+ * candidate different levels.
24
+ */
25
+ export function parseLevels(value) {
26
+ const trimmed = value.trim();
27
+ if (trimmed === '') {
28
+ throw new Error('invalid ocr: levels is empty; write corrections such as "h12=2,h15=0"');
29
+ }
30
+ const overrides = {};
31
+ for (const piece of trimmed.split(',')) {
32
+ const entry = piece.trim();
33
+ const match = CORRECTION.exec(entry);
34
+ if (match === null) {
35
+ throw new Error('invalid ocr: levels cannot read "' + entry + '"; write an outline id and its level such as "h12=2"');
36
+ }
37
+ const id = 'h' + (match[1] ?? '');
38
+ const raw = match[2] ?? '';
39
+ if (!LEVEL.test(raw)) {
40
+ throw new Error('invalid ocr: levels gives "' + raw + '" to ' + id
41
+ + '; a level is a whole number, 0 for a line that is not a heading and 1 to 6 for a heading');
42
+ }
43
+ const level = Number(raw);
44
+ const previous = overrides[id];
45
+ if (previous !== undefined && previous !== level) {
46
+ throw new Error('invalid ocr: levels gives ' + id + ' both ' + String(previous) + ' and ' + String(level));
47
+ }
48
+ overrides[id] = level;
49
+ }
50
+ return overrides;
51
+ }
52
+ //# sourceMappingURL=levels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"levels.js","sourceRoot":"","sources":["../src/levels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,8EAA8E;AAC9E,MAAM,UAAU,GAAG,uBAAuB,CAAA;AAE1C,gFAAgF;AAChF,MAAM,KAAK,GAAG,YAAY,CAAA;AAE1B;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;IAC5B,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAA;IAC1F,CAAC;IACD,MAAM,SAAS,GAAmB,EAAE,CAAA;IACpC,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;QAC1B,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACpC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CACb,mCAAmC,GAAG,KAAK,GAAG,sDAAsD,CACrG,CAAA;QACH,CAAC;QACD,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QACjC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QAC1B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CACb,6BAA6B,GAAG,GAAG,GAAG,OAAO,GAAG,EAAE;kBAChD,0FAA0F,CAC7F,CAAA;QACH,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;QACzB,MAAM,QAAQ,GAAG,SAAS,CAAC,EAAE,CAAC,CAAA;QAC9B,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,EAAE,GAAG,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QAC5G,CAAC;QACD,SAAS,CAAC,EAAE,CAAC,GAAG,KAAK,CAAA;IACvB,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
package/lib/plan.d.ts ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Request planning: which files one call recognizes, where each document's
3
+ * artifacts go, and what the worker is told about each one.
4
+ *
5
+ * Everything here is decided before a worker process starts, so a call that
6
+ * names a file the worker cannot read is reported as a failure without paying
7
+ * for a process. The one exception is the source's own content digest, which
8
+ * only the worker can compute; {@link prepareJob} therefore resolves the paths
9
+ * that do not depend on a recognition, and the entry module names the rest when
10
+ * the document reports it started.
11
+ * @module @deepseek-ai/dsh-ab-ocr/plan
12
+ */
13
+ import type FileSystem from '@deepseek-ai/dsh-fs';
14
+ import { type ArtifactRoot, type SourceStamp } from './artifacts.ts';
15
+ import type { Config } from './config.ts';
16
+ import type { OcrArgs, OcrFailure } from './types.ts';
17
+ import type { WorkerJob } from './worker.ts';
18
+ /** Extensions the worker accepts as a still image or a PDF. */
19
+ export declare const SUPPORTED_EXTENSIONS: readonly string[];
20
+ /**
21
+ * Resolve the Python executable that carries the OCR dependencies.
22
+ * @param configured - the row's pythonPath value.
23
+ * @param packageRoot - this package's directory.
24
+ * @param platform - the platform the plugin is running on.
25
+ * @returns the configured path, the package's own environment, or the platform's interpreter name.
26
+ */
27
+ export declare function resolvePython(configured: string, packageRoot: string, platform: string): string;
28
+ /**
29
+ * Resolve the worker script this package runs.
30
+ * @param configured - the row's workerScript value.
31
+ * @param packageRoot - this package's directory.
32
+ * @returns the configured path, or the script shipped inside the package.
33
+ */
34
+ export declare function resolveWorkerScript(configured: string, packageRoot: string): string;
35
+ /**
36
+ * Resolve a deployment directory value against a base.
37
+ * @param configured - the configured or requested directory.
38
+ * @param base - the directory a relative value resolves against.
39
+ * @returns the absolute directory, or an empty string when the value is empty.
40
+ */
41
+ export declare function resolveDirectory(configured: string, base: string): string;
42
+ /**
43
+ * Collect the paths one call named, in request order and without duplicates.
44
+ * @param args - the model-supplied call arguments.
45
+ * @param base - the directory a relative path resolves against.
46
+ * @param maxDocuments - documents one call may name.
47
+ * @returns the absolute paths to recognize.
48
+ * @throws Error when the call names no path, or more than the ceiling.
49
+ */
50
+ export declare function requestPaths(args: OcrArgs, base: string, maxDocuments: number): string[];
51
+ /**
52
+ * Report why a path cannot be recognized, before any process is started.
53
+ * @param path - the absolute path to check.
54
+ * @returns the reason, or undefined when the worker can read the path.
55
+ */
56
+ export declare function rejectPath(path: string): string | undefined;
57
+ /**
58
+ * Resolve the directory one call's artifacts are written to: the call's own
59
+ * request when it made one, otherwise the deployment's configured directory.
60
+ * @param args - the model-supplied call arguments.
61
+ * @param config - the deployment's values.
62
+ * @param base - the directory a relative value resolves against.
63
+ * @returns the call's output directory, or an empty string for the source's own.
64
+ */
65
+ export declare function requestedOutputDir(args: OcrArgs, config: Config, base: string): string;
66
+ /** One planned job: the worker spec entry and the source it reads. */
67
+ export interface PlannedJob {
68
+ /** The worker spec entry. */
69
+ job: WorkerJob;
70
+ /** The absolute path the model supplied. */
71
+ input: string;
72
+ /** Directory the document's artifacts are written under. */
73
+ base: string;
74
+ }
75
+ /** One planned job with the artifact paths that do not depend on a recognition. */
76
+ export interface PreparedJob extends PlannedJob {
77
+ /** Every path that is fixed before the worker names the source's digest. */
78
+ root: ArtifactRoot;
79
+ /** What the digest covered about the source file, beyond its content. */
80
+ stamp: SourceStamp;
81
+ }
82
+ /**
83
+ * Build the worker spec and the failures that never reach the worker.
84
+ * @param paths - the absolute paths one call named.
85
+ * @param args - the model-supplied call arguments.
86
+ * @param config - the deployment's values.
87
+ * @param base - the directory a relative output directory resolves against.
88
+ * @returns the jobs to run and the paths rejected before running.
89
+ */
90
+ export declare function planJobs(paths: readonly string[], args: OcrArgs, config: Config, base: string): {
91
+ jobs: PlannedJob[];
92
+ failures: OcrFailure[];
93
+ };
94
+ /**
95
+ * Resolve the digest and the artifact paths of one planned job.
96
+ * @param fs - the mounted filesystem capability.
97
+ * @param planned - the job {@link planJobs} produced.
98
+ * @param pageDirName - the page directory's name under the base directory.
99
+ * @param signal - caller cancellation.
100
+ * @returns the job with its artifact paths and source metadata.
101
+ */
102
+ export declare function prepareJob(fs: FileSystem, planned: PlannedJob, pageDirName: string, signal?: AbortSignal): Promise<PreparedJob>;
103
+ //# sourceMappingURL=plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AAEjD,OAAO,EAA8B,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAChG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAgB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,+DAA+D;AAC/D,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAGjD,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,Q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ACd,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,WAAW,CAAC,CAOtB"}
package/lib/plan.js ADDED
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Request planning: which files one call recognizes, where each document's
3
+ * artifacts go, and what the worker is told about each one.
4
+ *
5
+ * Everything here is decided before a worker process starts, so a call that
6
+ * names a file the worker cannot read is reported as a failure without paying
7
+ * for a process. The one exception is the source's own content digest, which
8
+ * only the worker can compute; {@link prepareJob} therefore resolves the paths
9
+ * that do not depend on a recognition, and the entry module names the rest when
10
+ * the document reports it started.
11
+ * @module @deepseek-ai/dsh-ab-ocr/plan
12
+ */
13
+ import { existsSync } from 'node:fs';
14
+ import { isAbsolute, join, resolve } from 'node:path';
15
+ import { artifactBase, artifactRoot } from "./artifacts.js";
16
+ /** Extensions the worker accepts as a still image or a PDF. */
17
+ export const SUPPORTED_EXTENSIONS = [
18
+ '.pdf', '.png', '.jpg', '.jpeg', '.jpe', '.bmp', '.dib', '.tif', '.tiff',
19
+ '.webp', '.gif', '.jp2', '.pbm', '.pgm', '.ppm', '.tga', '.ico',
20
+ ];
21
+ /**
22
+ * Resolve the Python executable that carries the OCR dependencies.
23
+ * @param configured - the row's pythonPath value.
24
+ * @param packageRoot - this package's directory.
25
+ * @param platform - the platform the plugin is running on.
26
+ * @returns the configured path, the package's own environment, or the platform's interpreter name.
27
+ */
28
+ export function resolvePython(configured, packageRoot, platform) {
29
+ if (configured !== '')
30
+ return configured;
31
+ const bundled = platform === 'win32'
32
+ ? join(packageRoot, 'python', '.venv', 'Scripts', 'python.exe')
33
+ : join(packageRoot, 'python', '.venv', 'bin', 'python');
34
+ return existsSync(bundled) ? bundled : (platform === 'win32' ? 'python' : 'python3');
35
+ }
36
+ /**
37
+ * Resolve the worker script this package runs.
38
+ * @param configured - the row's workerScript value.
39
+ * @param packageRoot - this package's directory.
40
+ * @returns the configured path, or the script shipped inside the package.
41
+ */
42
+ export function resolveWorkerScript(configured, packageRoot) {
43
+ return configured !== '' ? configured : join(packageRoot, 'python', 'ocr_worker.py');
44
+ }
45
+ /**
46
+ * Resolve a deployment directory value against a base.
47
+ * @param configured - the configured or requested directory.
48
+ * @param base - the directory a relative value resolves against.
49
+ * @returns the absolute directory, or an empty string when the value is empty.
50
+ */
51
+ export function resolveDirectory(configured, base) {
52
+ if (configured === '')
53
+ return '';
54
+ return isAbsolute(configured) ? configured : resolve(base, configured);
55
+ }
56
+ /**
57
+ * Collect the paths one call named, in request order and without duplicates.
58
+ * @param args - the model-supplied call arguments.
59
+ * @param base - the directory a relative path resolves against.
60
+ * @param maxDocuments - documents one call may name.
61
+ * @returns the absolute paths to recognize.
62
+ * @throws Error when the call names no path, or more than the ceiling.
63
+ */
64
+ export function requestPaths(args, base, maxDocuments) {
65
+ const named = [...(args.path === undefined ? [] : [args.path]), ...(args.paths ?? [])];
66
+ if (named.length === 0)
67
+ throw new Error('invalid ocr: give path or paths with at least one file');
68
+ const paths = [];
69
+ for (const raw of named) {
70
+ const trimmed = raw.trim();
71
+ if (trimmed === '')
72
+ throw new Error('invalid ocr: path must be a non-empty string');
73
+ const absolute = isAbsolute(trimmed) ? trimmed : resolve(base, trimmed);
74
+ if (!paths.includes(absolute))
75
+ paths.push(absolute);
76
+ }
77
+ if (paths.length > maxDocuments) {
78
+ throw new Error('invalid ocr: one call recognizes at most ' + maxDocuments + ' files');
79
+ }
80
+ return paths;
81
+ }
82
+ /**
83
+ * Report why a path cannot be recognized, before any process is started.
84
+ * @param path - the absolute path to check.
85
+ * @returns the reason, or undefined when the worker can read the path.
86
+ */
87
+ export function rejectPath(path) {
88
+ if (!existsSync(path))
89
+ return 'no such file: ' + path;
90
+ const lower = path.toLowerCase();
91
+ if (!SUPPORTED_EXTENSIONS.some(extension => lower.endsWith(extension))) {
92
+ return 'unsupported file type: neither a PDF nor a supported image';
93
+ }
94
+ return undefined;
95
+ }
96
+ /**
97
+ * Collect the merge switches and thresholds one call sends.
98
+ * @param config - the deployment's values.
99
+ * @returns the merge options, in the names the worker reads them under.
100
+ */
101
+ function mergeOptions(config) {
102
+ return {
103
+ removePageNumbers: config.removePageNumbers,
104
+ removeRunningHeads: config.removeRunningHeads,
105
+ runningHeadRatio: config.runningHeadRatio,
106
+ runningHeadMinPages: config.runningHeadMinPages,
107
+ detectHeadings: config.detectHeadings,
108
+ headingMinRatio: config.headingMinRatio,
109
+ indentRatio: config.indentRatio,
110
+ paragraphGapRatio: config.paragraphGapRatio,
111
+ outlineCandidateRatio: config.outlineCandidateRatio,
112
+ maxOutlineCandidates: config.maxOutlineCandidates,
113
+ };
114
+ }
115
+ /**
116
+ * Resolve the directory one call's artifacts are written to: the call's own
117
+ * request when it made one, otherwise the deployment's configured directory.
118
+ * @param args - the model-supplied call arguments.
119
+ * @param config - the deployment's values.
120
+ * @param base - the directory a relative value resolves against.
121
+ * @returns the call's output directory, or an empty string for the source's own.
122
+ */
123
+ export function requestedOutputDir(args, config, base) {
124
+ const requested = resolveDirectory(args.outputDir ?? '', base);
125
+ return requested !== '' ? requested : resolveDirectory(config.outputDir, base);
126
+ }
127
+ /**
128
+ * Build the worker spec and the failures that never reach the worker.
129
+ * @param paths - the absolute paths one call named.
130
+ * @param args - the model-supplied call arguments.
131
+ * @param config - the deployment's values.
132
+ * @param base - the directory a relative output directory resolves against.
133
+ * @returns the jobs to run and the paths rejected before running.
134
+ */
135
+ export function planJobs(paths, args, config, base) {
136
+ const outputDir = requestedOutputDir(args, config, base);
137
+ const jobs = [];
138
+ const failures = [];
139
+ for (const input of paths) {
140
+ const rejection = rejectPath(input);
141
+ if (rejection !== undefined) {
142
+ failures.push({ input, error: rejection });
143
+ continue;
144
+ }
145
+ jobs.push({
146
+ input,
147
+ // The document and the pages beside it share one base directory, so two
148
+ // sources never share a page directory and a source with no configured
149
+ // output directory keeps its artifacts next to itself.
150
+ base: artifactBase(input, outputDir),
151
+ job: {
152
+ mode: 'recognize',
153
+ id: String(jobs.length + 1),
154
+ input,
155
+ pages: args.pages ?? null,
156
+ dpi: config.dpi,
157
+ maxPixels: config.maxPixels,
158
+ textScore: config.textScore,
159
+ detectColumns: config.detectColumns,
160
+ maxPages: config.maxPages,
161
+ merge: mergeOptions(config),
162
+ },
163
+ });
164
+ }
165
+ return { jobs, failures };
166
+ }
167
+ /**
168
+ * Read the metadata the digest covers for one source file.
169
+ * @param fs - the mounted filesystem capability.
170
+ * @param target - the resolved source target.
171
+ * @param signal - caller cancellation.
172
+ * @returns the size and modification time the filesystem reported, or the
173
+ * documented fallbacks when it reported none or refused the read.
174
+ */
175
+ async function sourceStamp(fs, target, signal) {
176
+ try {
177
+ const info = await fs.stat(target, signal);
178
+ if (info === undefined)
179
+ return { size: '', mtimeMs: 0, unavailable: true };
180
+ const reported = info;
181
+ return {
182
+ size: typeof reported.size === 'number' ? reported.size : '',
183
+ mtimeMs: typeof reported.mtimeMs === 'number' ? reported.mtimeMs : 0,
184
+ unavailable: false,
185
+ };
186
+ }
187
+ catch {
188
+ // A backend that refuses this metadata read still lets the document be
189
+ // recognized; the digest falls back to the empty stamp and the record says
190
+ // the metadata was unavailable.
191
+ return { size: '', mtimeMs: 0, unavailable: true };
192
+ }
193
+ }
194
+ /**
195
+ * Resolve the digest and the artifact paths of one planned job.
196
+ * @param fs - the mounted filesystem capability.
197
+ * @param planned - the job {@link planJobs} produced.
198
+ * @param pageDirName - the page directory's name under the base directory.
199
+ * @param signal - caller cancellation.
200
+ * @returns the job with its artifact paths and source metadata.
201
+ */
202
+ export async function prepareJob(fs, planned, pageDirName, signal) {
203
+ const target = await fs.resolve(planned.input);
204
+ const stamp = await sourceStamp(fs, target, signal);
205
+ // The worker reads the source in its own execution world, so the job carries
206
+ // the path that world can open rather than the one the model named.
207
+ planned.job.input = fs.processPath(target);
208
+ return { ...planned, root: artifactRoot(planned.input, planned.base, pageDirName), stamp };
209
+ }
210
+ //# sourceMappingURL=plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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AY,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,KAAK,EAAE,CAAA;AAC5F,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * One `ocr` call: refuse an installation that cannot run, drive the worker
3
+ * through the plan, write each page as it finishes, and merge the document only
4
+ * after the last page.
5
+ *
6
+ * A later call carrying `levels` does not recognize anything: it reads the
7
+ * record the recognition left behind and sends its stored geometry to the worker
8
+ * with the caller's heading-level corrections, which rewrites the document at
9
+ * the path the record named.
10
+ *
11
+ * The worker runs in its own execution world and writes only to stdout, so every
12
+ * value this module persists travels back as an event and is written through the
13
+ * mounted filesystem capability rather than by the worker.
14
+ * @module @deepseek-ai/dsh-ab-ocr/recognize
15
+ */
16
+ import type FileSystem from '@deepseek-ai/dsh-fs';
17
+ import type { Config } from './config.ts';
18
+ import { type CallFence } from './sandbox.ts';
19
+ import type { OcrArgs, OcrResult } from './types.ts';
20
+ /**
21
+ * Read the documents one call asked for, writing every artifact through the
22
+ * filesystem capability the composition mounted.
23
+ * @param fs - the mounted filesystem capability every write goes through, or
24
+ * undefined when the composition mounts none.
25
+ * @param args - the model-supplied call arguments.
26
+ * @param config - the deployment's values.
27
+ * @param base - the directory a relative path resolves against.
28
+ * @param signal - caller cancellation.
29
+ * @param fence - the fence every write is stamped with; absent on a bare backend.
30
+ * @returns the canonical value the call records.
31
+ * @throws Error when the request is malformed, no filesystem is mounted, the
32
+ * environment is unusable, the deployment denies a write, the worker reports
33
+ * pages out of order, or the worker fails.
34
+ */
35
+ export declare function recognize(fs: FileSystem | undefined, args: OcrArgs, config: Config, base: string, signal?: AbortSignal, fence?: CallFence | undefined): Promise<OcrResult>;
36
+ //# sourceMappingURL=recognize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recognize.d.ts","sourceRoot":"","sources":["../src/recognize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAA;AAEjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAyBzC,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,KAAK,EAAgB,OAAO,EAAoC,SAAS,EAAE,MAAM,YAAY,CAAA;AA6SpG;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,SAAS,CAC7B,EAAE,EAAE,UAAU,GAAG,SAAS,EAC1B,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,GAC5B,OAAO,CAAC,SAAS,CAAC,CAgJpB"}