dsh-pdf-mineru 0.0.8 → 0.0.10
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 +18 -0
- package/lib/index.js +57 -26
- package/lib/types/domain/request.d.ts +1 -1
- package/lib/types/service/result-presenter.d.ts +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.10
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Guarded `shouldInline` in `read_pdf` to only activate when `focus` includes the image modality, preventing inline image emission for non-image focus modes (`toc`, `text`, `table`).
|
|
8
|
+
- Prevented `inlineImagesForSingleResult` from falling back to full document scanning when `ordered_images` for candidate pages is empty, adding comprehensive regression tests for per-page image isolation.
|
|
9
|
+
|
|
10
|
+
## 0.0.9
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Added `toc` option (with `outline` alias) to `focus` parameter in `read_pdf`, formatting and projecting document table of contents with hierarchical indentation and page indexing as Markdown.
|
|
15
|
+
- Added comprehensive unit tests covering TOC markdown formatting, focus normalization, and outline-only content projection.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Omitted undeclared internal `attachmentRef` property from `inlined_images` tool output items to strictly conform to `readPdfResultSchema` (`additionalProperties: false`), reconstructing `ImageAttachmentRef` within `renderResult`.
|
|
20
|
+
|
|
3
21
|
## 0.0.8
|
|
4
22
|
|
|
5
23
|
### Changed
|
package/lib/index.js
CHANGED
|
@@ -584,7 +584,8 @@ const FOCUS_KINDS = [
|
|
|
584
584
|
"all",
|
|
585
585
|
"text",
|
|
586
586
|
"table",
|
|
587
|
-
"image"
|
|
587
|
+
"image",
|
|
588
|
+
"toc"
|
|
588
589
|
];
|
|
589
590
|
function parsePageRangeTokens(input) {
|
|
590
591
|
const intervals = [];
|
|
@@ -642,22 +643,20 @@ function normalizePageSelection(input) {
|
|
|
642
643
|
}
|
|
643
644
|
throw new TypeError(`Invalid page selection: ${String(input)}`);
|
|
644
645
|
}
|
|
646
|
+
function parseFocusToken(item) {
|
|
647
|
+
if (typeof item !== "string") throw new TypeError(`Invalid focus option: ${String(item)}`);
|
|
648
|
+
let trimmed = item.trim().toLowerCase();
|
|
649
|
+
if (trimmed === "outline") trimmed = "toc";
|
|
650
|
+
if (!FOCUS_KINDS.includes(trimmed)) throw new TypeError(`Invalid focus option: ${String(item)}`);
|
|
651
|
+
return trimmed;
|
|
652
|
+
}
|
|
645
653
|
function normalizeFocusSelection(input) {
|
|
646
654
|
if (input === void 0 || input === null) return /* @__PURE__ */ new Set(["all"]);
|
|
647
|
-
if (typeof input === "string")
|
|
648
|
-
const trimmed = input.trim().toLowerCase();
|
|
649
|
-
if (!FOCUS_KINDS.includes(trimmed)) throw new TypeError(`Invalid focus option: ${String(input)}`);
|
|
650
|
-
return /* @__PURE__ */ new Set([trimmed]);
|
|
651
|
-
}
|
|
655
|
+
if (typeof input === "string") return /* @__PURE__ */ new Set([parseFocusToken(input)]);
|
|
652
656
|
if (Array.isArray(input)) {
|
|
653
657
|
if (input.length === 0) return /* @__PURE__ */ new Set(["all"]);
|
|
654
658
|
const set = /* @__PURE__ */ new Set();
|
|
655
|
-
for (const item of input)
|
|
656
|
-
if (typeof item !== "string") throw new TypeError(`Invalid focus option: ${String(item)}`);
|
|
657
|
-
const trimmed = item.trim().toLowerCase();
|
|
658
|
-
if (!FOCUS_KINDS.includes(trimmed)) throw new TypeError(`Invalid focus option: ${String(item)}`);
|
|
659
|
-
set.add(trimmed);
|
|
660
|
-
}
|
|
659
|
+
for (const item of input) set.add(parseFocusToken(item));
|
|
661
660
|
return set;
|
|
662
661
|
}
|
|
663
662
|
throw new TypeError(`Invalid focus option: ${String(input)}`);
|
|
@@ -3622,6 +3621,16 @@ function getRasterMediaType(ext) {
|
|
|
3622
3621
|
default: return "image/png";
|
|
3623
3622
|
}
|
|
3624
3623
|
}
|
|
3624
|
+
function formatTocMarkdown(headings, options) {
|
|
3625
|
+
if (!headings || headings.length === 0) return options?.pageRange ? `*(No headings found in pages: ${options.pageRange})*` : "*(No headings detected in document outline)*";
|
|
3626
|
+
const lines = ["# Document Outline", ""];
|
|
3627
|
+
for (const heading of headings) {
|
|
3628
|
+
const indent = " ".repeat(Math.max(0, heading.level - 1));
|
|
3629
|
+
const location = heading.page !== void 0 ? ` (Page ${String(heading.page)})` : ` (line ${String(heading.line)})`;
|
|
3630
|
+
lines.push(`${indent}- ${heading.title}${location}`);
|
|
3631
|
+
}
|
|
3632
|
+
return lines.join("\n");
|
|
3633
|
+
}
|
|
3625
3634
|
function computeDocumentSummary(contentList, fallbackFullText) {
|
|
3626
3635
|
const maxPage = contentList.reduce((max, b) => typeof b.page_idx === "number" ? Math.max(max, b.page_idx) : max, -1);
|
|
3627
3636
|
const page_count = maxPage >= 0 ? maxPage + 1 : 1;
|
|
@@ -3931,7 +3940,8 @@ function formatResultProse(value) {
|
|
|
3931
3940
|
lines.push("", "Document Outline:");
|
|
3932
3941
|
for (const heading of value.toc) {
|
|
3933
3942
|
const indent = " ".repeat(Math.max(0, heading.level - 1));
|
|
3934
|
-
|
|
3943
|
+
const location = heading.page !== void 0 ? ` (Page ${String(heading.page)})` : ` (line ${String(heading.line)})`;
|
|
3944
|
+
lines.push(`${indent}- ${heading.title}${location}`);
|
|
3935
3945
|
}
|
|
3936
3946
|
lines.push("", "Note: To read specific sections, call read_pdf with pages=\"X-Y\" or use the read tool starting from the given line offset.");
|
|
3937
3947
|
}
|
|
@@ -3969,7 +3979,7 @@ function formatSingleSummaryProse(value) {
|
|
|
3969
3979
|
lines.push(`${indent}- ${heading.title}${pageInfo}`);
|
|
3970
3980
|
}
|
|
3971
3981
|
}
|
|
3972
|
-
lines.push("", "---", "💡 **Next Steps**: The document has been fully parsed and cached in local storage. Use `read_pdf` to inspect content on demand:", `- Read specific pages: \`read_pdf({ file_path: "${fileName}", pages: "1-3" })\``, `- Focus on tables: \`read_pdf({ file_path: "${fileName}", focus: "table" })\``, `- Focus on figures/images: \`read_pdf({ file_path: "${fileName}", focus: "image" })\``, `- Read complete text: \`read_pdf({ file_path: "${fileName}" })\``);
|
|
3982
|
+
lines.push("", "---", "💡 **Next Steps**: The document has been fully parsed and cached in local storage. Use `read_pdf` to inspect content on demand:", `- Read specific pages: \`read_pdf({ file_path: "${fileName}", pages: "1-3" })\``, `- Focus on tables: \`read_pdf({ file_path: "${fileName}", focus: "table" })\``, `- Focus on figures/images: \`read_pdf({ file_path: "${fileName}", focus: "image" })\``, `- Inspect outline / TOC: \`read_pdf({ file_path: "${fileName}", focus: "toc" })\``, `- Read complete text: \`read_pdf({ file_path: "${fileName}" })\``);
|
|
3973
3983
|
return lines.join("\n");
|
|
3974
3984
|
}
|
|
3975
3985
|
function formatParseSummaryProse(value) {
|
|
@@ -4319,6 +4329,15 @@ var MinerUService = class {
|
|
|
4319
4329
|
docSummary = fallback.summary;
|
|
4320
4330
|
toc = fallback.summary.toc;
|
|
4321
4331
|
}
|
|
4332
|
+
if (focusSet.has("toc")) {
|
|
4333
|
+
const filteredToc = pagesSet !== void 0 && toc !== void 0 ? toc.filter((h) => h.page !== void 0 ? pagesSet.has(h.page) : true) : toc;
|
|
4334
|
+
const tocMd = formatTocMarkdown(filteredToc, { pageRange: typeof data.inputPages === "string" ? data.inputPages : Array.isArray(data.inputPages) ? data.inputPages.join(",") : data.inputPages !== void 0 ? String(data.inputPages) : void 0 });
|
|
4335
|
+
if (!focusSet.has("all") && !focusSet.has("text") && !focusSet.has("table") && !focusSet.has("image")) {
|
|
4336
|
+
fullSourceText = tocMd;
|
|
4337
|
+
orderedImages = [];
|
|
4338
|
+
} else fullSourceText = fullSourceText.trim().length > 0 ? `${tocMd}\n\n---\n\n${fullSourceText}` : tocMd;
|
|
4339
|
+
toc = filteredToc;
|
|
4340
|
+
}
|
|
4322
4341
|
const skeleton = {
|
|
4323
4342
|
state: "completed",
|
|
4324
4343
|
source: data.item.source,
|
|
@@ -6488,7 +6507,8 @@ const readPdfParameters = {
|
|
|
6488
6507
|
"all",
|
|
6489
6508
|
"text",
|
|
6490
6509
|
"table",
|
|
6491
|
-
"image"
|
|
6510
|
+
"image",
|
|
6511
|
+
"toc"
|
|
6492
6512
|
],
|
|
6493
6513
|
description: "Focus content type"
|
|
6494
6514
|
}, {
|
|
@@ -6499,12 +6519,13 @@ const readPdfParameters = {
|
|
|
6499
6519
|
"all",
|
|
6500
6520
|
"text",
|
|
6501
6521
|
"table",
|
|
6502
|
-
"image"
|
|
6522
|
+
"image",
|
|
6523
|
+
"toc"
|
|
6503
6524
|
]
|
|
6504
6525
|
},
|
|
6505
6526
|
description: "Focus content types"
|
|
6506
6527
|
}],
|
|
6507
|
-
description: "Content types to extract: \"all\" (default), \"text\" (paragraphs, headers, code, formulas), \"table\" (tables and captions),
|
|
6528
|
+
description: "Content types to extract: \"all\" (default), \"text\" (paragraphs, headers, code, formulas), \"table\" (tables and captions), \"image\" (charts, figures, and captions), or \"toc\" (document outline / table of contents). Accepts a single kind or an array."
|
|
6508
6529
|
},
|
|
6509
6530
|
inline_images: {
|
|
6510
6531
|
type: "boolean",
|
|
@@ -6597,10 +6618,19 @@ function renderResult(value) {
|
|
|
6597
6618
|
return [{
|
|
6598
6619
|
type: "text",
|
|
6599
6620
|
text: clampRenderText(formatResultProse(value), limit)
|
|
6600
|
-
}, ...(value.inlined_images ?? []).flatMap((img) =>
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6621
|
+
}, ...(value.inlined_images ?? []).flatMap((img) => {
|
|
6622
|
+
return [{
|
|
6623
|
+
type: "image",
|
|
6624
|
+
attachment: img.attachmentRef ?? {
|
|
6625
|
+
attachmentId: img.attachment_id,
|
|
6626
|
+
mediaType: img.media_type,
|
|
6627
|
+
bytes: img.bytes ?? 0,
|
|
6628
|
+
width: img.width ?? 0,
|
|
6629
|
+
height: img.height ?? 0,
|
|
6630
|
+
...img.name !== void 0 ? { name: img.name } : {}
|
|
6631
|
+
}
|
|
6632
|
+
}];
|
|
6633
|
+
})];
|
|
6604
6634
|
}
|
|
6605
6635
|
function renderParseDocument(value) {
|
|
6606
6636
|
return renderResult(value);
|
|
@@ -6661,7 +6691,7 @@ async function collectImageCandidates(view) {
|
|
|
6661
6691
|
}
|
|
6662
6692
|
async function inlineImagesForSingleResult(view, attachments, signal) {
|
|
6663
6693
|
let candidates = [];
|
|
6664
|
-
if (view.ordered_images
|
|
6694
|
+
if (view.ordered_images !== void 0) candidates = view.ordered_images.map((img) => ({
|
|
6665
6695
|
path: img.path,
|
|
6666
6696
|
bytes: img.bytes,
|
|
6667
6697
|
name: img.name,
|
|
@@ -6685,8 +6715,7 @@ async function inlineImagesForSingleResult(view, attachments, signal) {
|
|
|
6685
6715
|
media_type: ref.mediaType,
|
|
6686
6716
|
...ref.width !== void 0 ? { width: ref.width } : {},
|
|
6687
6717
|
...ref.height !== void 0 ? { height: ref.height } : {},
|
|
6688
|
-
...ref.bytes !== void 0 ? { bytes: ref.bytes } : {}
|
|
6689
|
-
attachmentRef: ref
|
|
6718
|
+
...ref.bytes !== void 0 ? { bytes: ref.bytes } : {}
|
|
6690
6719
|
});
|
|
6691
6720
|
} catch {}
|
|
6692
6721
|
}
|
|
@@ -6857,7 +6886,9 @@ function registerTools(ctx, getService, accessGate) {
|
|
|
6857
6886
|
const { input, pollTimeoutMs, inline_images } = parseReadInput(args);
|
|
6858
6887
|
const supportsImage = await checkCallingModelSupportsImage(exec, ctx);
|
|
6859
6888
|
const attachments = ctx.get("attachments");
|
|
6860
|
-
const
|
|
6889
|
+
const focusSet = normalizeFocusSelection(input.focus);
|
|
6890
|
+
const focusIncludesImages = focusSet.has("all") || focusSet.has("image");
|
|
6891
|
+
const shouldInline = inline_images !== false && focusIncludesImages && supportsImage && attachments !== void 0;
|
|
6861
6892
|
const rawResult = await withStorageAccess(() => getService().parseDocument(agent.session, input, exec.signal, pollTimeoutMs));
|
|
6862
6893
|
if (shouldInline && attachments) return await processInlineImages(rawResult, attachments, exec.signal);
|
|
6863
6894
|
return rawResult;
|
|
@@ -7206,4 +7237,4 @@ async function apply(ctx, entryConfig = {}) {
|
|
|
7206
7237
|
}
|
|
7207
7238
|
}
|
|
7208
7239
|
//#endregion
|
|
7209
|
-
export { ARTIFACT_KINDS, CACHE_KEY_SPEC_VERSION, CANONICAL_PARSE_REQUEST_SCHEMA_VERSION, Config, DEFAULT_RETRY_POLICY, FOCUS_KINDS, MINERU_RESULT_MANIFEST_SCHEMA_VERSION, MinerUError, MinerUService, OfficialV4Provider, ProviderHttpClient, RESULT_SCHEMA_VERSION, SelfHostedV2Provider, StorageMaintenanceService, allocateReclaimedShares, apply, asCacheKey, asFileId, asOperationId, asProviderConfigId, asResultId, asSessionId, assertSafePathSegment, cacheClearConfirmationToken, calculateBackoffDelay, computeDocumentSummary, confirmationToken, createFileId, createHttpStatusError, createOperationId, createStructuredDiagnosticSink, defaultMinerUConfig, defaultProviderConfig, defaultSleep, emitDiagnostic, executeJsonRequest, executeWithRetry, extractBlocksMarkdown, extractErrorMessage, extractMarkdownHeadings, failure, fallbackExtractFromMarkdown, findMarkdownArtifactPath, formatCaption, formatParseDocumentProse, formatParseSummaryProse, formatResultProse, formatSingleSummaryProse, getBlockCategory, getRasterMediaType, inject, isRetryableError, isRetryableHttpStatus, mergeRetryOptions, migrateConfig, name, normalizeArtifactKinds, normalizeFocusSelection, normalizePageRanges, normalizePageSelection, parseRetryAfter, providerById, readBoundedResponseText, readMarkdownFile, resolveProviderUrl, resolveRetryPolicy, resultIdForCacheKey, safeStringSlice, sanitizeDiagnostic, throwMinerU, toMinerUFailure, truncateAtCleanBoundary, validateProviderCapabilities };
|
|
7240
|
+
export { ARTIFACT_KINDS, CACHE_KEY_SPEC_VERSION, CANONICAL_PARSE_REQUEST_SCHEMA_VERSION, Config, DEFAULT_RETRY_POLICY, FOCUS_KINDS, MINERU_RESULT_MANIFEST_SCHEMA_VERSION, MinerUError, MinerUService, OfficialV4Provider, ProviderHttpClient, RESULT_SCHEMA_VERSION, SelfHostedV2Provider, StorageMaintenanceService, allocateReclaimedShares, apply, asCacheKey, asFileId, asOperationId, asProviderConfigId, asResultId, asSessionId, assertSafePathSegment, cacheClearConfirmationToken, calculateBackoffDelay, computeDocumentSummary, confirmationToken, createFileId, createHttpStatusError, createOperationId, createStructuredDiagnosticSink, defaultMinerUConfig, defaultProviderConfig, defaultSleep, emitDiagnostic, executeJsonRequest, executeWithRetry, extractBlocksMarkdown, extractErrorMessage, extractMarkdownHeadings, failure, fallbackExtractFromMarkdown, findMarkdownArtifactPath, formatCaption, formatParseDocumentProse, formatParseSummaryProse, formatResultProse, formatSingleSummaryProse, formatTocMarkdown, getBlockCategory, getRasterMediaType, inject, isRetryableError, isRetryableHttpStatus, mergeRetryOptions, migrateConfig, name, normalizeArtifactKinds, normalizeFocusSelection, normalizePageRanges, normalizePageSelection, parseRetryAfter, providerById, readBoundedResponseText, readMarkdownFile, resolveProviderUrl, resolveRetryPolicy, resultIdForCacheKey, safeStringSlice, sanitizeDiagnostic, throwMinerU, toMinerUFailure, truncateAtCleanBoundary, validateProviderCapabilities };
|
|
@@ -6,7 +6,7 @@ export declare const ARTIFACT_KINDS: readonly ["markdown", "layout", "model-outp
|
|
|
6
6
|
export type ArtifactKind = typeof ARTIFACT_KINDS[number];
|
|
7
7
|
export type MinerUModel = 'pipeline' | 'vlm';
|
|
8
8
|
export type ParseMethod = 'auto' | 'txt' | 'ocr';
|
|
9
|
-
export declare const FOCUS_KINDS: readonly ["all", "text", "table", "image"];
|
|
9
|
+
export declare const FOCUS_KINDS: readonly ["all", "text", "table", "image", "toc"];
|
|
10
10
|
export type FocusKind = typeof FOCUS_KINDS[number];
|
|
11
11
|
export type PageSelection = number | string | readonly (number | string)[];
|
|
12
12
|
export interface ParseSemantics {
|
|
@@ -93,6 +93,9 @@ export interface ContentListBlock {
|
|
|
93
93
|
export declare function getBlockCategory(type?: string): 'text' | 'table' | 'image';
|
|
94
94
|
export declare function formatCaption(caption: unknown): string;
|
|
95
95
|
export declare function getRasterMediaType(ext: string): 'image/jpeg' | 'image/webp' | 'image/gif' | 'image/png';
|
|
96
|
+
export declare function formatTocMarkdown(headings: readonly DocumentHeading[] | undefined, options?: {
|
|
97
|
+
pageRange?: string;
|
|
98
|
+
}): string;
|
|
96
99
|
export declare function computeDocumentSummary(contentList: readonly ContentListBlock[], fallbackFullText?: string): DocumentSummary;
|
|
97
100
|
export declare function extractBlocksMarkdown(contentList: readonly ContentListBlock[], pagesSet: ReadonlySet<number> | undefined, focusSet: ReadonlySet<FocusKind>, imageArtifacts: readonly ArtifactView[]): {
|
|
98
101
|
text: string;
|
package/package.json
CHANGED