dsh-pdf-mineru 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +89 -300
- package/assets/icon.svg +15 -0
- package/lib/client.js +2308 -2765
- package/lib/client.js.map +1 -1
- package/lib/index.js +6645 -6991
- package/lib/pdfjs-worker.mjs +40 -16
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +92 -73
- package/lib/types/adapters/dsh-document-source.d.ts +0 -16
- package/lib/types/client/DisclosureCard.d.ts +0 -15
- package/lib/types/client/NumericInput.d.ts +0 -23
- package/lib/types/client/SettingsPage.d.ts +0 -10
- package/lib/types/client/StorageOperations.d.ts +0 -10
- package/lib/types/client/helpers.d.ts +0 -27
- package/lib/types/client/icons.d.ts +0 -17
- package/lib/types/client/index.d.ts +0 -9
- package/lib/types/client/locales.d.ts +0 -4
- package/lib/types/client/sections/AdvancedSections.d.ts +0 -11
- package/lib/types/client/sections/DefaultsSection.d.ts +0 -12
- package/lib/types/client/sections/ProviderSection.d.ts +0 -24
- package/lib/types/config/migration-values.d.ts +0 -6
- package/lib/types/config/pure.d.ts +0 -94
- package/lib/types/config.d.ts +0 -34
- package/lib/types/domain/cache-key.d.ts +0 -7
- package/lib/types/domain/errors.d.ts +0 -20
- package/lib/types/domain/ids.d.ts +0 -20
- package/lib/types/domain/job.d.ts +0 -2
- package/lib/types/domain/request.d.ts +0 -90
- package/lib/types/domain/result.d.ts +0 -32
- package/lib/types/domain/schemas.d.ts +0 -33
- package/lib/types/index.d.ts +0 -20
- package/lib/types/loopback-rpc.d.ts +0 -8
- package/lib/types/observability.d.ts +0 -32
- package/lib/types/providers/http-client.d.ts +0 -48
- package/lib/types/providers/official-v4-types.d.ts +0 -55
- package/lib/types/providers/official-v4.d.ts +0 -20
- package/lib/types/providers/provider.d.ts +0 -139
- package/lib/types/providers/registry.d.ts +0 -15
- package/lib/types/providers/retry.d.ts +0 -66
- package/lib/types/providers/safe-zip.d.ts +0 -23
- package/lib/types/providers/self-hosted-legacy-v2.d.ts +0 -62
- package/lib/types/providers/self-hosted-v1.d.ts +0 -141
- package/lib/types/rpc.d.ts +0 -31
- package/lib/types/service/document-index.d.ts +0 -36
- package/lib/types/service/image-policy.d.ts +0 -11
- package/lib/types/service/mineru-service.d.ts +0 -88
- package/lib/types/service/page-renderer.d.ts +0 -64
- package/lib/types/service/pdfjs-backend.d.ts +0 -5
- package/lib/types/service/read-cursor.d.ts +0 -44
- package/lib/types/service/read-delivery.d.ts +0 -28
- package/lib/types/service/request-normalizer.d.ts +0 -13
- package/lib/types/service/result-presenter.d.ts +0 -197
- package/lib/types/service/shared-operations.d.ts +0 -47
- package/lib/types/storage/access-gate.d.ts +0 -40
- package/lib/types/storage/artifact-sink.d.ts +0 -24
- package/lib/types/storage/index.d.ts +0 -9
- package/lib/types/storage/maintenance-service.d.ts +0 -193
- package/lib/types/storage/paths.d.ts +0 -34
- package/lib/types/storage/process-lock.d.ts +0 -43
- package/lib/types/storage/result-repository.d.ts +0 -68
- package/lib/types/tools.d.ts +0 -29
- package/lib/types/utils/crypto.d.ts +0 -2
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import type { Readable } from 'node:stream';
|
|
2
|
-
import type { MinerUFailure, MinerUProviderId } from '../domain/errors.js';
|
|
3
|
-
import type { MinerUFileState, MinerUJobState } from '../domain/job.js';
|
|
4
|
-
import type { MinerUFileId } from '../domain/ids.js';
|
|
5
|
-
import type { ArtifactRef } from '../domain/result.js';
|
|
6
|
-
import type { ArtifactKind, CanonicalParseRequest, MinerUModel, ParseMethod, PreparedSourceFile } from '../domain/request.js';
|
|
7
|
-
import type { ProviderRetryOptions } from './retry.js';
|
|
8
|
-
export * from './retry.js';
|
|
9
|
-
export interface ProviderOptions {
|
|
10
|
-
readonly retry?: ProviderRetryOptions;
|
|
11
|
-
}
|
|
12
|
-
export interface ProviderCapabilities {
|
|
13
|
-
readonly models: readonly MinerUModel[];
|
|
14
|
-
readonly parseMethods: readonly ParseMethod[];
|
|
15
|
-
readonly supportsOcr: boolean;
|
|
16
|
-
readonly supportsLanguage: boolean;
|
|
17
|
-
readonly supportsFormula: boolean;
|
|
18
|
-
readonly supportsTable: boolean;
|
|
19
|
-
readonly supportsPageRanges: boolean;
|
|
20
|
-
readonly supportedArtifacts: readonly ArtifactKind[];
|
|
21
|
-
readonly maxFilesPerSubmission: number;
|
|
22
|
-
readonly maxFileBytes?: number;
|
|
23
|
-
readonly maxPagesPerFile?: number;
|
|
24
|
-
}
|
|
25
|
-
export interface ProviderCallLimits {
|
|
26
|
-
readonly maxApiResponseBytes: number;
|
|
27
|
-
readonly maxZipDownloadBytes: number;
|
|
28
|
-
readonly maxZipEntries: number;
|
|
29
|
-
readonly maxZipEntryBytes: number;
|
|
30
|
-
readonly maxZipTotalBytes: number;
|
|
31
|
-
readonly maxZipCompressionRatio: number;
|
|
32
|
-
}
|
|
33
|
-
export interface ProviderCallContext {
|
|
34
|
-
readonly signal: AbortSignal;
|
|
35
|
-
readonly credential?: string;
|
|
36
|
-
readonly timeoutMs: number;
|
|
37
|
-
readonly limits: ProviderCallLimits;
|
|
38
|
-
readonly retry?: ProviderRetryOptions;
|
|
39
|
-
/** Observe upstream acceptance within this invocation; references remain transient. */
|
|
40
|
-
readonly onAccepted?: (ref: ProviderJobRef) => Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
export interface ProviderCompatibilityContext {
|
|
43
|
-
readonly configuredVersion?: string;
|
|
44
|
-
}
|
|
45
|
-
export interface ProviderProbeResult {
|
|
46
|
-
readonly available: boolean;
|
|
47
|
-
readonly provider: MinerUProviderId;
|
|
48
|
-
readonly authentication: 'valid' | 'invalid' | 'not-configured' | 'unknown';
|
|
49
|
-
readonly protocolVersion: string;
|
|
50
|
-
readonly serverVersion?: string;
|
|
51
|
-
readonly availableTiers?: readonly string[];
|
|
52
|
-
readonly outputFormats?: readonly string[];
|
|
53
|
-
readonly sourceTypes?: readonly string[];
|
|
54
|
-
readonly queue?: {
|
|
55
|
-
readonly queued?: number;
|
|
56
|
-
readonly processing?: number;
|
|
57
|
-
readonly completed?: number;
|
|
58
|
-
readonly failed?: number;
|
|
59
|
-
readonly maxConcurrent?: number;
|
|
60
|
-
};
|
|
61
|
-
readonly diagnostics?: string;
|
|
62
|
-
}
|
|
63
|
-
export interface ProviderSubmittedFile {
|
|
64
|
-
readonly dataId: string;
|
|
65
|
-
readonly fileId: MinerUFileId;
|
|
66
|
-
readonly name: string;
|
|
67
|
-
}
|
|
68
|
-
/** Upstream self-hosted dialect selected for one submission. */
|
|
69
|
-
export type SelfHostedProtocol = 'legacy' | 'v1';
|
|
70
|
-
export type ProviderJobRef = {
|
|
71
|
-
readonly provider: 'self-hosted-legacy-v2';
|
|
72
|
-
readonly protocol: 'legacy';
|
|
73
|
-
readonly taskId: string;
|
|
74
|
-
readonly files: readonly ProviderSubmittedFile[];
|
|
75
|
-
} | {
|
|
76
|
-
readonly provider: 'self-hosted-v1';
|
|
77
|
-
readonly protocol: 'v1';
|
|
78
|
-
readonly taskId: string;
|
|
79
|
-
readonly files: readonly ProviderSubmittedFile[];
|
|
80
|
-
} | {
|
|
81
|
-
readonly provider: 'official-v4';
|
|
82
|
-
readonly batchId: string;
|
|
83
|
-
readonly files: readonly ProviderSubmittedFile[];
|
|
84
|
-
};
|
|
85
|
-
export interface ProviderSubmission {
|
|
86
|
-
readonly ref: ProviderJobRef;
|
|
87
|
-
readonly state: MinerUJobState;
|
|
88
|
-
readonly files: readonly ProviderFileSnapshot[];
|
|
89
|
-
}
|
|
90
|
-
export interface ProviderFileSnapshot {
|
|
91
|
-
readonly fileId: MinerUFileId;
|
|
92
|
-
readonly state: MinerUFileState;
|
|
93
|
-
readonly rawState?: string;
|
|
94
|
-
readonly progress?: {
|
|
95
|
-
readonly completed: number;
|
|
96
|
-
readonly total: number;
|
|
97
|
-
};
|
|
98
|
-
readonly failure?: MinerUFailure;
|
|
99
|
-
}
|
|
100
|
-
export interface ProviderJobSnapshot {
|
|
101
|
-
readonly state: MinerUJobState;
|
|
102
|
-
readonly files: readonly ProviderFileSnapshot[];
|
|
103
|
-
readonly rawState?: string;
|
|
104
|
-
readonly queuedAhead?: number;
|
|
105
|
-
}
|
|
106
|
-
export type ArtifactInput = Readable | ReadableStream<Uint8Array> | Uint8Array | string;
|
|
107
|
-
export interface ArtifactWriteOptions {
|
|
108
|
-
readonly mediaType: string;
|
|
109
|
-
readonly relativeName?: string;
|
|
110
|
-
readonly maxBytes?: number;
|
|
111
|
-
}
|
|
112
|
-
export interface TemporaryArtifact {
|
|
113
|
-
readonly path: string;
|
|
114
|
-
readonly bytes: number;
|
|
115
|
-
readonly sha256: string;
|
|
116
|
-
}
|
|
117
|
-
export interface ArtifactSink {
|
|
118
|
-
writeArtifact(fileId: MinerUFileId, kind: ArtifactKind, input: ArtifactInput, options: ArtifactWriteOptions): Promise<ArtifactRef>;
|
|
119
|
-
writeTemporary(name: string, input: ArtifactInput, maxBytes: number): Promise<TemporaryArtifact>;
|
|
120
|
-
}
|
|
121
|
-
export interface ProviderCollectedFile {
|
|
122
|
-
readonly fileId: MinerUFileId;
|
|
123
|
-
readonly name: string;
|
|
124
|
-
readonly artifacts: readonly ArtifactRef[];
|
|
125
|
-
readonly failure?: MinerUFailure;
|
|
126
|
-
}
|
|
127
|
-
export interface ProviderCollection {
|
|
128
|
-
readonly files: readonly ProviderCollectedFile[];
|
|
129
|
-
}
|
|
130
|
-
export interface MinerUProvider {
|
|
131
|
-
readonly id: MinerUProviderId;
|
|
132
|
-
readonly capabilities: ProviderCapabilities;
|
|
133
|
-
probe(context: ProviderCallContext): Promise<ProviderProbeResult>;
|
|
134
|
-
compatibilityKey(request: CanonicalParseRequest, context: ProviderCompatibilityContext): Promise<string>;
|
|
135
|
-
submit(request: CanonicalParseRequest, sources: readonly PreparedSourceFile[], context: ProviderCallContext): Promise<ProviderSubmission>;
|
|
136
|
-
inspect(ref: ProviderJobRef, context: ProviderCallContext): Promise<ProviderJobSnapshot>;
|
|
137
|
-
collect(ref: ProviderJobRef, request: CanonicalParseRequest, sink: ArtifactSink, context: ProviderCallContext): Promise<ProviderCollection>;
|
|
138
|
-
}
|
|
139
|
-
export declare function validateProviderCapabilities(request: CanonicalParseRequest, capabilities: ProviderCapabilities): void;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ProviderConfigId } from '../domain/ids.js';
|
|
2
|
-
import type { MinerUConfig, ProviderConfig } from '../config.js';
|
|
3
|
-
import type { MinerUProvider, ProviderOptions } from './provider.js';
|
|
4
|
-
export interface ResolvedProvider {
|
|
5
|
-
readonly provider: MinerUProvider;
|
|
6
|
-
readonly config: ProviderConfig;
|
|
7
|
-
}
|
|
8
|
-
export declare class ProviderRegistry {
|
|
9
|
-
private readonly getConfig;
|
|
10
|
-
private readonly options?;
|
|
11
|
-
constructor(getConfig: () => MinerUConfig, options?: ProviderOptions | undefined);
|
|
12
|
-
active(): ResolvedProvider;
|
|
13
|
-
resolve(configId: ProviderConfigId): ResolvedProvider;
|
|
14
|
-
create(config: ProviderConfig): MinerUProvider;
|
|
15
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { MinerUProviderId } from '../domain/errors.js';
|
|
2
|
-
export type ProviderRetryOperation = 'probe' | 'submit' | 'inspect' | 'collect' | 'api-json' | 'presigned-put' | 'upload-put' | 'cdn-download' | 'result-download';
|
|
3
|
-
export interface ProviderRetryEvent {
|
|
4
|
-
readonly provider: MinerUProviderId;
|
|
5
|
-
readonly operation: ProviderRetryOperation;
|
|
6
|
-
readonly attempt: number;
|
|
7
|
-
readonly maxRetries: number;
|
|
8
|
-
readonly delayMs: number;
|
|
9
|
-
readonly reason: 'transport' | 'http-status';
|
|
10
|
-
readonly status?: number;
|
|
11
|
-
readonly retryAfterMs?: number;
|
|
12
|
-
}
|
|
13
|
-
export type ProviderRetryHook = (event: ProviderRetryEvent) => void;
|
|
14
|
-
export interface ProviderRetryPolicy {
|
|
15
|
-
readonly maxRetries?: number;
|
|
16
|
-
readonly initialDelayMs?: number;
|
|
17
|
-
readonly maxDelayMs?: number;
|
|
18
|
-
readonly backoffFactor?: number;
|
|
19
|
-
readonly jitter?: boolean;
|
|
20
|
-
}
|
|
21
|
-
export interface ProviderRetryHooks {
|
|
22
|
-
readonly onRetry?: ProviderRetryHook;
|
|
23
|
-
readonly sleep?: (ms: number, signal: AbortSignal) => Promise<void>;
|
|
24
|
-
readonly random?: () => number;
|
|
25
|
-
}
|
|
26
|
-
export interface ProviderRetryOptions extends ProviderRetryPolicy, ProviderRetryHooks {
|
|
27
|
-
}
|
|
28
|
-
export declare function mergeRetryOptions(defaults: ProviderRetryOptions, overrides: ProviderRetryOptions | undefined): ProviderRetryOptions;
|
|
29
|
-
export declare function readBoundedResponseText(response: Response, maxBytes: number, signal: AbortSignal): Promise<string>;
|
|
30
|
-
export declare const DEFAULT_RETRY_POLICY: Required<ProviderRetryPolicy>;
|
|
31
|
-
/**
|
|
32
|
-
* Parses a standard HTTP Retry-After header value.
|
|
33
|
-
* Supports decimal integer seconds (e.g. "120") and HTTP-date strings.
|
|
34
|
-
* Returns the delay in milliseconds, or undefined if missing/unparseable.
|
|
35
|
-
*/
|
|
36
|
-
export declare function parseRetryAfter(header: string | null | undefined, now?: number): number | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Returns true if an HTTP status code is typically transient and safe to retry.
|
|
39
|
-
* Matches 408 (Request Timeout), 429 (Too Many Requests), and 5xx server errors.
|
|
40
|
-
*/
|
|
41
|
-
export declare function isRetryableHttpStatus(status: number): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Determines whether a caught error is retryable.
|
|
44
|
-
* Abort/cancellation errors and explicit non-retryable MinerUErrors return false.
|
|
45
|
-
*/
|
|
46
|
-
export declare function isRetryableError(err: unknown, signal?: AbortSignal): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Abort-aware delay utility using node:timers/promises.
|
|
49
|
-
*/
|
|
50
|
-
export declare function defaultSleep(ms: number, signal: AbortSignal): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Calculates exponential backoff delay with optional jitter or Retry-After header.
|
|
53
|
-
*/
|
|
54
|
-
export declare function calculateBackoffDelay(attempt: number, policy: Required<ProviderRetryPolicy>, retryAfterMs?: number, random?: () => number): number;
|
|
55
|
-
export interface RetryExecutionContext<T> {
|
|
56
|
-
readonly provider: MinerUProviderId;
|
|
57
|
-
readonly operation: ProviderRetryOperation;
|
|
58
|
-
readonly signal: AbortSignal;
|
|
59
|
-
readonly retryOptions?: ProviderRetryOptions;
|
|
60
|
-
readonly fn: (attempt: number) => Promise<T>;
|
|
61
|
-
}
|
|
62
|
-
export declare function resolveRetryPolicy(options?: ProviderRetryPolicy): Required<ProviderRetryPolicy>;
|
|
63
|
-
/**
|
|
64
|
-
* Reusable bounded, abort-aware retry executor for idempotent provider operations.
|
|
65
|
-
*/
|
|
66
|
-
export declare function executeWithRetry<T>(ctx: RetryExecutionContext<T>): Promise<T>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type Entry } from 'yauzl';
|
|
2
|
-
import type { ArtifactKind } from '../domain/request.js';
|
|
3
|
-
import type { ArtifactSink, ProviderCollectedFile } from './provider.js';
|
|
4
|
-
import type { ExtractZipTargetFile, SafeZipLimits } from './official-v4-types.js';
|
|
5
|
-
export interface SafeZipOptions {
|
|
6
|
-
readonly zipPath: string;
|
|
7
|
-
readonly sink: ArtifactSink;
|
|
8
|
-
readonly files: readonly ExtractZipTargetFile[];
|
|
9
|
-
readonly requiredArtifacts: readonly ArtifactKind[];
|
|
10
|
-
readonly limits: SafeZipLimits;
|
|
11
|
-
readonly signal: AbortSignal;
|
|
12
|
-
}
|
|
13
|
-
export interface ZipEntryMetadata {
|
|
14
|
-
readonly fileName: string;
|
|
15
|
-
readonly directory: boolean;
|
|
16
|
-
readonly compressedBytes: number;
|
|
17
|
-
readonly uncompressedBytes: number;
|
|
18
|
-
}
|
|
19
|
-
export declare function validateEntrySecurity(entry: Entry, limits: SafeZipLimits): void;
|
|
20
|
-
/** Security-focused compatibility helper: scans metadata and drains no entry into memory. */
|
|
21
|
-
export declare function readAllZipEntries(zipPath: string, limits: SafeZipLimits, signal: AbortSignal): Promise<ZipEntryMetadata[]>;
|
|
22
|
-
export declare function validateJsonFile(path: string, maxBytes?: number, signal?: AbortSignal): Promise<void>;
|
|
23
|
-
export declare function extractSafeZip(options: SafeZipOptions): Promise<ProviderCollectedFile[]>;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { type ProviderConfigId } from '../domain/ids.js';
|
|
2
|
-
import type { CanonicalParseRequest, MinerUModel, PreparedSourceFile } from '../domain/request.js';
|
|
3
|
-
import { type ArtifactSink, type MinerUProvider, type ProviderCallContext, type ProviderCapabilities, type ProviderCollection, type ProviderCompatibilityContext, type ProviderJobRef, type ProviderJobSnapshot, type ProviderOptions, type ProviderProbeResult, type ProviderSubmission } from './provider.js';
|
|
4
|
-
export interface SelfHostedLegacyV2ProviderConfig {
|
|
5
|
-
readonly id: ProviderConfigId;
|
|
6
|
-
readonly type: 'self-hosted-legacy-v2';
|
|
7
|
-
readonly baseURL: string;
|
|
8
|
-
readonly apiKeyEnv?: string;
|
|
9
|
-
readonly modelMap: Readonly<Partial<Record<MinerUModel, string>>>;
|
|
10
|
-
readonly configuredVersion?: string;
|
|
11
|
-
readonly allowInsecureHttp?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export interface SelfHostedHealthResponse {
|
|
14
|
-
readonly status: 'healthy' | 'unhealthy' | string;
|
|
15
|
-
readonly version?: string;
|
|
16
|
-
readonly protocol_version?: number;
|
|
17
|
-
readonly queued_tasks?: number;
|
|
18
|
-
readonly processing_tasks?: number;
|
|
19
|
-
readonly completed_tasks?: number;
|
|
20
|
-
readonly failed_tasks?: number;
|
|
21
|
-
readonly max_concurrent_requests?: number;
|
|
22
|
-
}
|
|
23
|
-
export interface SelfHostedTaskSubmitResponse {
|
|
24
|
-
readonly task_id: string;
|
|
25
|
-
readonly status: string;
|
|
26
|
-
readonly backend?: string;
|
|
27
|
-
readonly file_names?: readonly string[];
|
|
28
|
-
readonly created_at?: string | null;
|
|
29
|
-
readonly started_at?: string | null;
|
|
30
|
-
readonly completed_at?: string | null;
|
|
31
|
-
readonly error?: string | null;
|
|
32
|
-
readonly status_url?: string;
|
|
33
|
-
readonly result_url?: string;
|
|
34
|
-
readonly queued_ahead?: number;
|
|
35
|
-
}
|
|
36
|
-
export interface SelfHostedFileParseResult {
|
|
37
|
-
readonly md_content?: string | null;
|
|
38
|
-
readonly middle_json?: unknown;
|
|
39
|
-
readonly model_output?: unknown;
|
|
40
|
-
readonly content_list?: unknown;
|
|
41
|
-
readonly images?: Readonly<Record<string, string>> | null;
|
|
42
|
-
}
|
|
43
|
-
export interface SelfHostedTaskResultResponse {
|
|
44
|
-
readonly backend?: string;
|
|
45
|
-
readonly version?: string;
|
|
46
|
-
readonly results?: Readonly<Record<string, SelfHostedFileParseResult>>;
|
|
47
|
-
}
|
|
48
|
-
export declare class SelfHostedLegacyV2Provider implements MinerUProvider {
|
|
49
|
-
readonly id: "self-hosted-legacy-v2";
|
|
50
|
-
readonly config: SelfHostedLegacyV2ProviderConfig;
|
|
51
|
-
readonly capabilities: ProviderCapabilities;
|
|
52
|
-
private readonly parsedBaseUrl;
|
|
53
|
-
private readonly retryOptions;
|
|
54
|
-
private readonly client;
|
|
55
|
-
constructor(config: SelfHostedLegacyV2ProviderConfig, options?: ProviderOptions);
|
|
56
|
-
compatibilityKey(request: CanonicalParseRequest, context: ProviderCompatibilityContext): Promise<string>;
|
|
57
|
-
probe(context: ProviderCallContext): Promise<ProviderProbeResult>;
|
|
58
|
-
submit(request: CanonicalParseRequest, sources: readonly PreparedSourceFile[], context: ProviderCallContext): Promise<ProviderSubmission>;
|
|
59
|
-
inspect(ref: ProviderJobRef, context: ProviderCallContext): Promise<ProviderJobSnapshot>;
|
|
60
|
-
collect(ref: ProviderJobRef, request: CanonicalParseRequest, sink: ArtifactSink, context: ProviderCallContext): Promise<ProviderCollection>;
|
|
61
|
-
private requestJson;
|
|
62
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* self-hosted-v1.ts — MinerU 4.x self-hosted "V1 API" protocol adapter.
|
|
3
|
-
*
|
|
4
|
-
* Wire contract (see scripts/http_api_example.sh in opendatalab/MinerU):
|
|
5
|
-
* POST /v1/uploads create an upload session (deduplicated files are already completed)
|
|
6
|
-
* PUT {upload_url} stream the raw bytes with the service-provided upload headers
|
|
7
|
-
* POST /v1/uploads/{id}/complete finalize the upload and obtain the file id
|
|
8
|
-
* POST /v1/parse/jobs submit one parse job covering every uploaded file
|
|
9
|
-
* GET /v1/parse/jobs/{job_id} poll job/file status and per-file output references
|
|
10
|
-
* GET /v1/files/{file_id}/content download a parse output (the result archive)
|
|
11
|
-
*
|
|
12
|
-
* A job requests the `zip` output format, which is the complete MinerU output package
|
|
13
|
-
* (`markdown.md`, `middle_json.json`, `structured_content.json`, `model_output.json`,
|
|
14
|
-
* `images/*`). Collection therefore reuses the shared bounded ZIP extractor and only
|
|
15
|
-
* canonicalizes the two documents whose MinerU 4.x shape differs from the plugin's
|
|
16
|
-
* canonical artifact shape (layout page list and structured content).
|
|
17
|
-
*/
|
|
18
|
-
import type { MinerUFileState, MinerUJobState } from '../domain/job.js';
|
|
19
|
-
import { type SelfHostedV1Config } from '../config/pure.js';
|
|
20
|
-
import type { CanonicalParseRequest, PreparedSourceFile } from '../domain/request.js';
|
|
21
|
-
import { type MinerUProvider, type ProviderCapabilities, type ProviderCompatibilityContext, type ProviderOptions, type ArtifactSink, type ProviderCallContext, type ProviderCollection, type ProviderJobRef, type ProviderJobSnapshot, type ProviderProbeResult, type ProviderSubmission, type ProviderSubmittedFile } from './provider.js';
|
|
22
|
-
/** The only output format the plugin consumes; it carries every canonical artifact. */
|
|
23
|
-
export declare const SELF_HOSTED_V1_ARCHIVE_FORMAT = "zip";
|
|
24
|
-
export interface SelfHostedV1HealthResponse {
|
|
25
|
-
readonly status?: string;
|
|
26
|
-
readonly version?: string;
|
|
27
|
-
readonly features?: {
|
|
28
|
-
readonly output_formats?: readonly string[];
|
|
29
|
-
readonly sources?: readonly string[];
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export interface SelfHostedV1UsageResponse {
|
|
33
|
-
readonly limits?: {
|
|
34
|
-
readonly max_concurrent_jobs?: number;
|
|
35
|
-
readonly max_files_per_job?: number;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
export interface SelfHostedV1UploadResponse {
|
|
39
|
-
readonly id?: string;
|
|
40
|
-
readonly status?: string;
|
|
41
|
-
readonly upload_url?: string | null;
|
|
42
|
-
readonly upload_method?: string | null;
|
|
43
|
-
readonly upload_headers?: Readonly<Record<string, string>> | null;
|
|
44
|
-
readonly file?: {
|
|
45
|
-
readonly id?: string;
|
|
46
|
-
} | null;
|
|
47
|
-
}
|
|
48
|
-
export interface SelfHostedV1OutputFileRef {
|
|
49
|
-
readonly file_id?: string;
|
|
50
|
-
readonly bytes?: number;
|
|
51
|
-
}
|
|
52
|
-
export interface SelfHostedV1JobFile {
|
|
53
|
-
readonly file_id?: string | null;
|
|
54
|
-
readonly name?: string;
|
|
55
|
-
readonly page_range?: string;
|
|
56
|
-
readonly status?: string;
|
|
57
|
-
readonly output_files?: Readonly<Record<string, SelfHostedV1OutputFileRef | null>> | null;
|
|
58
|
-
readonly error?: {
|
|
59
|
-
readonly code?: string | null;
|
|
60
|
-
readonly message?: string;
|
|
61
|
-
} | null;
|
|
62
|
-
}
|
|
63
|
-
export interface SelfHostedV1JobResponse {
|
|
64
|
-
readonly job_id?: string;
|
|
65
|
-
readonly status?: string;
|
|
66
|
-
readonly files?: readonly SelfHostedV1JobFile[];
|
|
67
|
-
readonly progress?: {
|
|
68
|
-
readonly completed?: number;
|
|
69
|
-
readonly failed?: number;
|
|
70
|
-
readonly total?: number;
|
|
71
|
-
} | null;
|
|
72
|
-
}
|
|
73
|
-
export declare function mimeTypeForName(name: string): string;
|
|
74
|
-
/** Same scheme, host, and effective port; the only target that may receive the API key. */
|
|
75
|
-
export declare function isSameOriginUrl(target: URL, baseUrl: URL): boolean;
|
|
76
|
-
/** True when an HTTPS endpoint points the byte upload at a cleartext origin elsewhere. */
|
|
77
|
-
export declare function isInsecureCrossOriginUpload(target: URL, baseUrl: URL): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Maps a MinerU V1 job status to the plugin's aggregate job state.
|
|
80
|
-
* `canceled` has no dedicated plugin state and is reported as a failed job.
|
|
81
|
-
*/
|
|
82
|
-
export declare function mapSelfHostedV1JobState(rawStatus: unknown): MinerUJobState;
|
|
83
|
-
/** Maps a MinerU V1 per-file status to the plugin's file state. */
|
|
84
|
-
export declare function mapSelfHostedV1FileState(rawStatus: unknown): MinerUFileState;
|
|
85
|
-
/**
|
|
86
|
-
* Matches a submitted file to its upstream job entry. The V1 API echoes job files in
|
|
87
|
-
* submission order, so the positional entry wins when its name agrees; otherwise a
|
|
88
|
-
* unique name match is used.
|
|
89
|
-
*/
|
|
90
|
-
export declare function matchV1JobFile(jobFiles: readonly SelfHostedV1JobFile[], file: ProviderSubmittedFile, index: number): SelfHostedV1JobFile | undefined;
|
|
91
|
-
/**
|
|
92
|
-
* Positive shape check for the MinerU 4.x health document. The V1 schema always carries a
|
|
93
|
-
* `version` and never the legacy `protocol_version`/queue counters, so a generic proxy or an
|
|
94
|
-
* earlier self-hosted server answering 200 with some other JSON object is not mistaken for V1.
|
|
95
|
-
*/
|
|
96
|
-
export declare function isSelfHostedV1Health(value: unknown): value is SelfHostedV1HealthResponse;
|
|
97
|
-
/**
|
|
98
|
-
* Converts the MinerU 4.x `structured_content.json` document into the plugin's canonical
|
|
99
|
-
* content-list array: the page container supplies each block's `page_idx`, MinerU title
|
|
100
|
-
* types map onto the canonical heading fields, and image/table references map onto the
|
|
101
|
-
* canonical caption and image-path fields. Unknown fields are preserved as-is.
|
|
102
|
-
*/
|
|
103
|
-
export declare function canonicalizeStructuredContent(parsed: unknown): readonly unknown[] | undefined;
|
|
104
|
-
/**
|
|
105
|
-
* The plugin's canonical layout document exposes the ordered page list as `pdf_info[]`.
|
|
106
|
-
* MinerU 4.x publishes the same list as `pages[]`; keep the upstream document and add the
|
|
107
|
-
* canonical alias so physical page bounds stay verifiable.
|
|
108
|
-
*/
|
|
109
|
-
export declare function canonicalizeLayoutDocument(parsed: unknown): Record<string, unknown> | undefined;
|
|
110
|
-
export declare class SelfHostedV1Provider implements MinerUProvider {
|
|
111
|
-
readonly id: "self-hosted-v1";
|
|
112
|
-
readonly config: SelfHostedV1Config;
|
|
113
|
-
readonly capabilities: ProviderCapabilities;
|
|
114
|
-
private readonly options;
|
|
115
|
-
constructor(config: SelfHostedV1Config, options?: ProviderOptions);
|
|
116
|
-
compatibilityKey(_request: CanonicalParseRequest, context: ProviderCompatibilityContext): Promise<string>;
|
|
117
|
-
probe(context: ProviderCallContext): Promise<ProviderProbeResult>;
|
|
118
|
-
/** Cheap protocol probe: answers whether the configured endpoint speaks the V1 API. */
|
|
119
|
-
health(context: ProviderCallContext): Promise<SelfHostedV1HealthResponse>;
|
|
120
|
-
private discoverDeployment;
|
|
121
|
-
private deploymentIssue;
|
|
122
|
-
private probeHealth;
|
|
123
|
-
submit(request: CanonicalParseRequest, sources: readonly PreparedSourceFile[], context: ProviderCallContext): Promise<ProviderSubmission>;
|
|
124
|
-
inspect(ref: ProviderJobRef, context: ProviderCallContext): Promise<ProviderJobSnapshot>;
|
|
125
|
-
collect(ref: ProviderJobRef, request: CanonicalParseRequest, sink: ArtifactSink, context: ProviderCallContext): Promise<ProviderCollection>;
|
|
126
|
-
private snapshotFromJob;
|
|
127
|
-
private uploadSource;
|
|
128
|
-
private requireFileId;
|
|
129
|
-
/**
|
|
130
|
-
* Streams source bytes to the service-provided upload URL. The API key is attached only
|
|
131
|
-
* when the target is same-origin with the configured endpoint; service-provided upload
|
|
132
|
-
* headers are otherwise preserved verbatim. PUT is idempotent, so transient failures retry
|
|
133
|
-
* with a freshly opened source file.
|
|
134
|
-
*/
|
|
135
|
-
private putUploadBytes;
|
|
136
|
-
private resolveUploadUrl;
|
|
137
|
-
private isSameOrigin;
|
|
138
|
-
/** Downloads the result archive of a completed file into a bounded staging temporary file. */
|
|
139
|
-
private downloadResultArchive;
|
|
140
|
-
private requestJson;
|
|
141
|
-
}
|
package/lib/types/rpc.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* rpc.ts — host-side RPC handler for MinerU config CRUD and draft probe.
|
|
3
|
-
*
|
|
4
|
-
* Endpoints (on the `/dsh-pdf-mineru-api` channel, loopback authority):
|
|
5
|
-
* - `mineru/config.get` payload: {} → { config: MinerUConfig }
|
|
6
|
-
* - `mineru/config.set` payload: { config: unknown } → { config: MinerUConfig }
|
|
7
|
-
* - `mineru/probe` payload: { provider?: unknown } → ProbeView
|
|
8
|
-
*
|
|
9
|
-
* Security:
|
|
10
|
-
* - Authority: strictly 'loopback'
|
|
11
|
-
* - Credential values and tokens are never returned or leaked in responses/errors.
|
|
12
|
-
* - Errors sanitized via sanitizeDiagnostic and mapped to allowlisted actionable error codes.
|
|
13
|
-
*/
|
|
14
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
15
|
-
import type { ConnectionRpcResult } from '@deepseek-ai/dsh-client-connection';
|
|
16
|
-
import type { MinerUConfig } from './config.js';
|
|
17
|
-
import type { ProbeView } from './service/mineru-service.js';
|
|
18
|
-
import type { StorageMaintenanceService } from './storage/maintenance-service.js';
|
|
19
|
-
export interface MineruRpcDeps {
|
|
20
|
-
readonly getConfig: () => MinerUConfig;
|
|
21
|
-
readonly setConfig: (value: unknown) => Promise<MinerUConfig>;
|
|
22
|
-
readonly probe: (providerDraft: unknown | undefined, signal: AbortSignal) => Promise<ProbeView>;
|
|
23
|
-
readonly maintenance: Pick<StorageMaintenanceService, 'getStatistics' | 'scanIntegrity' | 'listQuarantine' | 'cleanupQuarantine' | 'gcDryRun' | 'clearCache'>;
|
|
24
|
-
}
|
|
25
|
-
export type RpcResult<T> = ConnectionRpcResult<T>;
|
|
26
|
-
export declare const RPC_CHANNEL = "/dsh-pdf-mineru-api";
|
|
27
|
-
export declare function mapRpcError(err: unknown): {
|
|
28
|
-
code: string;
|
|
29
|
-
message: string;
|
|
30
|
-
};
|
|
31
|
-
export declare function registerRpc(ctx: Context, deps: MineruRpcDeps): () => void | Promise<void>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { ContentListBlock } from '../service/result-presenter.js';
|
|
2
|
-
/** Version of the provider-content projection semantics. */
|
|
3
|
-
export declare const DOCUMENT_INDEX_VERSION: 2;
|
|
4
|
-
/** A bounded, block-scoped diagnostic suitable for chunk delivery. */
|
|
5
|
-
export interface BlockDiagnostic {
|
|
6
|
-
readonly id: string;
|
|
7
|
-
readonly code: string;
|
|
8
|
-
readonly scope: 'chunk';
|
|
9
|
-
readonly message: string;
|
|
10
|
-
readonly block_id: string;
|
|
11
|
-
readonly page?: number;
|
|
12
|
-
}
|
|
13
|
-
/** A content-list block with an identity fixed before page/focus selection. */
|
|
14
|
-
export interface IndexedContentBlock extends ContentListBlock {
|
|
15
|
-
readonly block_id: string;
|
|
16
|
-
readonly document_label?: string;
|
|
17
|
-
/** One-based position in the provider's original content-list. */
|
|
18
|
-
readonly document_order: number;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Extract an author/provider supplied figure, table, or equation label.
|
|
22
|
-
*
|
|
23
|
-
* Only a label at the beginning of a relevant caption is accepted. This
|
|
24
|
-
* deliberately does not synthesize labels from the block's return position.
|
|
25
|
-
*/
|
|
26
|
-
export declare function extractDocumentLabel(block: ContentListBlock): string | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* Add stable document identities and faithfully expose known MinerU content.
|
|
29
|
-
* The input array and its blocks are never mutated.
|
|
30
|
-
*/
|
|
31
|
-
export declare function normalizeDocumentBlocks(contentList: readonly ContentListBlock[], resultId: string, warningBlockOrders?: ReadonlySet<number>): {
|
|
32
|
-
blocks: readonly IndexedContentBlock[];
|
|
33
|
-
warnings: readonly string[];
|
|
34
|
-
};
|
|
35
|
-
/** Diagnose only selected one-based original-order blocks without renumbering. */
|
|
36
|
-
export declare function collectBlockDiagnostics(contentList: readonly ContentListBlock[], resultId: string, orders: ReadonlySet<number>): readonly BlockDiagnostic[];
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** Internal image attachment byte policy (no model-facing options). */
|
|
2
|
-
/** Total decoded byte budget across one read response. */
|
|
3
|
-
export declare const MAX_INLINE_IMAGE_TOTAL_BYTES: number;
|
|
4
|
-
/** Per-image decoded byte budget. */
|
|
5
|
-
export declare const MAX_INLINE_IMAGE_SINGLE_BYTES: number;
|
|
6
|
-
export declare const SUPPORTED_IMAGE_EXTENSIONS: ReadonlySet<string>;
|
|
7
|
-
export type SupportedImageMediaType = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif';
|
|
8
|
-
/** Map a file extension to a supported raster media type, or undefined when unsupported. */
|
|
9
|
-
export declare function mediaTypeForExtension(ext: string): SupportedImageMediaType | undefined;
|
|
10
|
-
/** True when the file extension names a supported raster image format. */
|
|
11
|
-
export declare function isSupportedImageExtension(ext: string): boolean;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { type MinerUConfig, type ProviderConfig } from '../config.js';
|
|
2
|
-
import type { MinerUProviderId } from '../domain/errors.js';
|
|
3
|
-
import type { MinerUResultId } from '../domain/ids.js';
|
|
4
|
-
import type { ParseRequestInput } from '../domain/request.js';
|
|
5
|
-
import { ProviderRegistry } from '../providers/registry.js';
|
|
6
|
-
import type { ResultRepository } from '../storage/result-repository.js';
|
|
7
|
-
import type { StorageAccessGate } from '../storage/access-gate.js';
|
|
8
|
-
import { type MinerUDiagnosticSink } from '../observability.js';
|
|
9
|
-
import { SharedOperationRegistry } from './shared-operations.js';
|
|
10
|
-
import type { ParseSummaryView, ResultView } from './result-presenter.js';
|
|
11
|
-
export * from './result-presenter.js';
|
|
12
|
-
/** Invocation-local progress only; never carries provider refs, paths or credentials. */
|
|
13
|
-
export type ParseProgress = 'preparing' | 'waiting-for-parse' | 'reading-result' | 'summarizing';
|
|
14
|
-
export type ParseProgressListener = (phase: ParseProgress) => void;
|
|
15
|
-
export interface ServiceSession {
|
|
16
|
-
readonly header: {
|
|
17
|
-
readonly id: string;
|
|
18
|
-
readonly cwd?: string;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export type CredentialResolver = (reference: string, signal: AbortSignal) => Promise<string | undefined>;
|
|
22
|
-
export interface ProbeView {
|
|
23
|
-
readonly available: boolean;
|
|
24
|
-
readonly provider: MinerUProviderId;
|
|
25
|
-
readonly authentication: 'valid' | 'invalid' | 'not-configured' | 'unknown';
|
|
26
|
-
readonly protocol_version: string;
|
|
27
|
-
readonly server_version?: string;
|
|
28
|
-
readonly available_tiers?: readonly string[];
|
|
29
|
-
readonly output_formats?: readonly string[];
|
|
30
|
-
readonly source_types?: readonly string[];
|
|
31
|
-
readonly queue?: {
|
|
32
|
-
readonly queued?: number;
|
|
33
|
-
readonly processing?: number;
|
|
34
|
-
readonly completed?: number;
|
|
35
|
-
readonly failed?: number;
|
|
36
|
-
readonly max_concurrent?: number;
|
|
37
|
-
};
|
|
38
|
-
readonly diagnostics?: string;
|
|
39
|
-
}
|
|
40
|
-
export interface MinerUServiceOptions {
|
|
41
|
-
readonly getConfig: () => MinerUConfig;
|
|
42
|
-
readonly providers: ProviderRegistry;
|
|
43
|
-
readonly results: ResultRepository;
|
|
44
|
-
readonly operations: SharedOperationRegistry;
|
|
45
|
-
readonly resolveCredential: CredentialResolver;
|
|
46
|
-
readonly diagnostics?: MinerUDiagnosticSink;
|
|
47
|
-
readonly accessGate?: StorageAccessGate;
|
|
48
|
-
}
|
|
49
|
-
export declare class MinerUService {
|
|
50
|
-
private readonly options;
|
|
51
|
-
constructor(options: MinerUServiceOptions);
|
|
52
|
-
private config;
|
|
53
|
-
private diagnostic;
|
|
54
|
-
private callContext;
|
|
55
|
-
probe(signal: AbortSignal, draft?: ProviderConfig): Promise<ProbeView>;
|
|
56
|
-
private prepare;
|
|
57
|
-
private runOperation;
|
|
58
|
-
private runOperationCore;
|
|
59
|
-
private fitSingleCandidate;
|
|
60
|
-
private projectSingle;
|
|
61
|
-
private createWaitSignal;
|
|
62
|
-
/** Ensure publication and return a bounded synopsis, never a body projection. */
|
|
63
|
-
ensureParsed(session: ServiceSession, input: ParseRequestInput, signal: AbortSignal, onProgress?: ParseProgressListener): Promise<ParseSummaryView>;
|
|
64
|
-
/** Local original-page verification; never invokes a Provider or persists a source. */
|
|
65
|
-
previewPage(session: ServiceSession, input: {
|
|
66
|
-
file_path: string;
|
|
67
|
-
page: number;
|
|
68
|
-
expectedSha256?: string;
|
|
69
|
-
}, signal: AbortSignal): Promise<{
|
|
70
|
-
result_id: MinerUResultId;
|
|
71
|
-
file_id: import("../domain/ids.js").MinerUFileId;
|
|
72
|
-
output_limit_chars: number;
|
|
73
|
-
renderer: "poppler" | "pdfjs";
|
|
74
|
-
name: string;
|
|
75
|
-
page: number;
|
|
76
|
-
page_count: number;
|
|
77
|
-
sha256: string;
|
|
78
|
-
data: Uint8Array;
|
|
79
|
-
media_type: "image/png";
|
|
80
|
-
width?: number;
|
|
81
|
-
height?: number;
|
|
82
|
-
}>;
|
|
83
|
-
/** Read selected content from a published result. */
|
|
84
|
-
parseDocument(session: ServiceSession, input: ParseRequestInput, signal: AbortSignal, pollTimeoutMs?: number | null): Promise<ResultView>;
|
|
85
|
-
private projectSummary;
|
|
86
|
-
/** Shared parse/publication path. Repository integrity checks remain mandatory. */
|
|
87
|
-
private resolveParsedResult;
|
|
88
|
-
}
|