@aeye/resources 0.3.9

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 (125) hide show
  1. package/aeye-resources-graph.md +158 -0
  2. package/aeye-resources-parsers.md +175 -0
  3. package/aeye-resources-slicers.md +158 -0
  4. package/aeye-resources.md +186 -0
  5. package/dist/default.d.ts +8 -0
  6. package/dist/default.d.ts.map +1 -0
  7. package/dist/default.js +31 -0
  8. package/dist/default.js.map +1 -0
  9. package/dist/graph.d.ts +93 -0
  10. package/dist/graph.d.ts.map +1 -0
  11. package/dist/graph.js +154 -0
  12. package/dist/graph.js.map +1 -0
  13. package/dist/index.d.ts +8 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +7 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/parsers/code.d.ts +3 -0
  18. package/dist/parsers/code.d.ts.map +1 -0
  19. package/dist/parsers/code.js +28 -0
  20. package/dist/parsers/code.js.map +1 -0
  21. package/dist/parsers/docx.d.ts +10 -0
  22. package/dist/parsers/docx.d.ts.map +1 -0
  23. package/dist/parsers/docx.js +89 -0
  24. package/dist/parsers/docx.js.map +1 -0
  25. package/dist/parsers/excel.d.ts +9 -0
  26. package/dist/parsers/excel.d.ts.map +1 -0
  27. package/dist/parsers/excel.js +161 -0
  28. package/dist/parsers/excel.js.map +1 -0
  29. package/dist/parsers/html.d.ts +3 -0
  30. package/dist/parsers/html.d.ts.map +1 -0
  31. package/dist/parsers/html.js +37 -0
  32. package/dist/parsers/html.js.map +1 -0
  33. package/dist/parsers/image.d.ts +3 -0
  34. package/dist/parsers/image.d.ts.map +1 -0
  35. package/dist/parsers/image.js +45 -0
  36. package/dist/parsers/image.js.map +1 -0
  37. package/dist/parsers/index.d.ts +10 -0
  38. package/dist/parsers/index.d.ts.map +1 -0
  39. package/dist/parsers/index.js +10 -0
  40. package/dist/parsers/index.js.map +1 -0
  41. package/dist/parsers/markdown.d.ts +3 -0
  42. package/dist/parsers/markdown.d.ts.map +1 -0
  43. package/dist/parsers/markdown.js +28 -0
  44. package/dist/parsers/markdown.js.map +1 -0
  45. package/dist/parsers/pdf.d.ts +10 -0
  46. package/dist/parsers/pdf.d.ts.map +1 -0
  47. package/dist/parsers/pdf.js +165 -0
  48. package/dist/parsers/pdf.js.map +1 -0
  49. package/dist/parsers/text.d.ts +4 -0
  50. package/dist/parsers/text.d.ts.map +1 -0
  51. package/dist/parsers/text.js +42 -0
  52. package/dist/parsers/text.js.map +1 -0
  53. package/dist/parsers/zip.d.ts +3 -0
  54. package/dist/parsers/zip.d.ts.map +1 -0
  55. package/dist/parsers/zip.js +131 -0
  56. package/dist/parsers/zip.js.map +1 -0
  57. package/dist/registry.d.ts +81 -0
  58. package/dist/registry.d.ts.map +1 -0
  59. package/dist/registry.js +322 -0
  60. package/dist/registry.js.map +1 -0
  61. package/dist/renderers/index.d.ts +3 -0
  62. package/dist/renderers/index.d.ts.map +1 -0
  63. package/dist/renderers/index.js +2 -0
  64. package/dist/renderers/index.js.map +1 -0
  65. package/dist/renderers/poppler.d.ts +38 -0
  66. package/dist/renderers/poppler.d.ts.map +1 -0
  67. package/dist/renderers/poppler.js +92 -0
  68. package/dist/renderers/poppler.js.map +1 -0
  69. package/dist/resolvers/file.d.ts +3 -0
  70. package/dist/resolvers/file.d.ts.map +1 -0
  71. package/dist/resolvers/file.js +68 -0
  72. package/dist/resolvers/file.js.map +1 -0
  73. package/dist/resolvers/index.d.ts +4 -0
  74. package/dist/resolvers/index.d.ts.map +1 -0
  75. package/dist/resolvers/index.js +4 -0
  76. package/dist/resolvers/index.js.map +1 -0
  77. package/dist/resolvers/url.d.ts +3 -0
  78. package/dist/resolvers/url.d.ts.map +1 -0
  79. package/dist/resolvers/url.js +91 -0
  80. package/dist/resolvers/url.js.map +1 -0
  81. package/dist/resolvers/zip.d.ts +8 -0
  82. package/dist/resolvers/zip.d.ts.map +1 -0
  83. package/dist/resolvers/zip.js +73 -0
  84. package/dist/resolvers/zip.js.map +1 -0
  85. package/dist/segmenters/default.d.ts +7 -0
  86. package/dist/segmenters/default.d.ts.map +1 -0
  87. package/dist/segmenters/default.js +7 -0
  88. package/dist/segmenters/default.js.map +1 -0
  89. package/dist/segmenters/index.d.ts +4 -0
  90. package/dist/segmenters/index.d.ts.map +1 -0
  91. package/dist/segmenters/index.js +3 -0
  92. package/dist/segmenters/index.js.map +1 -0
  93. package/dist/segmenters/langchain.d.ts +33 -0
  94. package/dist/segmenters/langchain.d.ts.map +1 -0
  95. package/dist/segmenters/langchain.js +110 -0
  96. package/dist/segmenters/langchain.js.map +1 -0
  97. package/dist/slicers/code.d.ts +3 -0
  98. package/dist/slicers/code.d.ts.map +1 -0
  99. package/dist/slicers/code.js +78 -0
  100. package/dist/slicers/code.js.map +1 -0
  101. package/dist/slicers/index.d.ts +4 -0
  102. package/dist/slicers/index.d.ts.map +1 -0
  103. package/dist/slicers/index.js +4 -0
  104. package/dist/slicers/index.js.map +1 -0
  105. package/dist/slicers/markdown.d.ts +3 -0
  106. package/dist/slicers/markdown.d.ts.map +1 -0
  107. package/dist/slicers/markdown.js +70 -0
  108. package/dist/slicers/markdown.js.map +1 -0
  109. package/dist/slicers/text.d.ts +3 -0
  110. package/dist/slicers/text.d.ts.map +1 -0
  111. package/dist/slicers/text.js +43 -0
  112. package/dist/slicers/text.js.map +1 -0
  113. package/dist/types.d.ts +306 -0
  114. package/dist/types.d.ts.map +1 -0
  115. package/dist/types.js +2 -0
  116. package/dist/types.js.map +1 -0
  117. package/dist/utils.d.ts +97 -0
  118. package/dist/utils.d.ts.map +1 -0
  119. package/dist/utils.js +788 -0
  120. package/dist/utils.js.map +1 -0
  121. package/dist/zip-internal.d.ts +28 -0
  122. package/dist/zip-internal.d.ts.map +1 -0
  123. package/dist/zip-internal.js +52 -0
  124. package/dist/zip-internal.js.map +1 -0
  125. package/package.json +104 -0
@@ -0,0 +1,131 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { createParsedResource } from "../registry";
3
+ import { assertNotAborted, buildZipEntryLocation, createPartId, createResourceId, dedupeLinks, imageMimeTypeFromLocation, toFilePath, } from "../utils";
4
+ import { ZIP_LIMITS, getCachedZip, loadJSZip } from "../zip-internal";
5
+ export const zipParser = {
6
+ id: "zip-parser",
7
+ supportedTypes: ["zip"],
8
+ defaultSlicer: "text",
9
+ async isSupported(_type, _context) {
10
+ return Boolean(await loadJSZip());
11
+ },
12
+ async parse(source, context) {
13
+ assertNotAborted(context.options.signal);
14
+ if (!(await loadJSZip())) {
15
+ throw new Error("jszip is not installed. Install it to parse ZIP resources: npm install jszip");
16
+ }
17
+ // Read (and cache) the zip from the file system to avoid holding the entire zip in JS heap.
18
+ const filePath = toFilePath(source.location);
19
+ const zip = await getCachedZip(filePath);
20
+ if (!zip) {
21
+ throw new Error("jszip is not installed. Install it to parse ZIP resources: npm install jszip");
22
+ }
23
+ const resource = createParsedResource(source);
24
+ resource.defaultSlicer = "text";
25
+ resource.children = [];
26
+ const entries = Object.values(zip.files);
27
+ let fileCount = 0;
28
+ let totalSize = 0;
29
+ // Build a text listing of zip contents as the main part
30
+ const listing = [];
31
+ // Extract entries one at a time to keep memory usage low
32
+ for (const entry of entries) {
33
+ assertNotAborted(context.options.signal);
34
+ if (entry.dir) {
35
+ continue;
36
+ }
37
+ fileCount++;
38
+ if (fileCount > ZIP_LIMITS.MAX_FILES) {
39
+ throw new Error(`Zip file contains too many files (max: ${ZIP_LIMITS.MAX_FILES})`);
40
+ }
41
+ // Extract one entry at a time to avoid holding all in memory simultaneously
42
+ const entryData = await entry.async("uint8array");
43
+ const uncompressedSize = entryData.length;
44
+ if (uncompressedSize > ZIP_LIMITS.MAX_FILE_SIZE) {
45
+ throw new Error(`File in zip exceeds size limit: ${entry.name}`);
46
+ }
47
+ totalSize += uncompressedSize;
48
+ if (totalSize > ZIP_LIMITS.MAX_TOTAL_SIZE) {
49
+ throw new Error(`Zip file total uncompressed size exceeds limit (max: ${Math.round(ZIP_LIMITS.MAX_TOTAL_SIZE / 1024 / 1024)}MB)`);
50
+ }
51
+ listing.push(entry.name);
52
+ // Create a child resource for each file entry
53
+ const childLocation = buildZipEntryLocation(source.location, entry.name);
54
+ const entryType = context.registry.inferType(entry.name);
55
+ const modifiedAt = entry.date instanceof Date ? entry.date.getTime() : undefined;
56
+ // Try to parse the entry through the registry so its links/parts join the resource graph.
57
+ // Parsers that read from the filesystem (e.g. nested pdf/zip) cannot handle in-memory entries
58
+ // and will throw, in which case we fall back to a raw representation below.
59
+ let childResource;
60
+ if (entryType) {
61
+ const childSource = {
62
+ location: childLocation,
63
+ input: entryData,
64
+ type: entryType,
65
+ name: entry.name,
66
+ modifiedAt,
67
+ size: uncompressedSize,
68
+ metadata: { size: uncompressedSize, parentLocation: source.location },
69
+ };
70
+ try {
71
+ childResource = await context.registry.parseSource(childSource, context.options);
72
+ }
73
+ catch {
74
+ childResource = undefined;
75
+ }
76
+ }
77
+ if (!childResource) {
78
+ childResource = createRawEntryResource(childLocation, entry.name, entryType, entryData, uncompressedSize, modifiedAt);
79
+ }
80
+ childResource.parentLocation = source.location;
81
+ childResource.modifiedAt = childResource.modifiedAt ?? modifiedAt;
82
+ resource.children.push(childResource);
83
+ }
84
+ // Add a text listing part to the parent resource
85
+ const listingText = `Zip archive: ${source.name ?? source.location}\nFiles (${fileCount}):\n${listing.map((f) => ` ${f}`).join("\n")}`;
86
+ const listingPart = {
87
+ id: createPartId(resource, 0),
88
+ location: `${resource.location}#listing`,
89
+ kind: "text",
90
+ text: listingText,
91
+ metadata: { fileCount, totalSize },
92
+ };
93
+ resource.parts.push(listingPart);
94
+ resource.links = dedupeLinks(resource.children.flatMap((c) => c.links));
95
+ return resource;
96
+ }
97
+ };
98
+ /** Builds a minimal child resource for an entry that could not be parsed by a registered parser. */
99
+ function createRawEntryResource(childLocation, name, entryType, entryData, size, modifiedAt) {
100
+ const childResource = {
101
+ id: createResourceId(childLocation, entryType ?? "unknown"),
102
+ location: childLocation,
103
+ type: entryType ?? "unknown",
104
+ name,
105
+ modifiedAt,
106
+ size,
107
+ metadata: { size },
108
+ defaultSlicer: "text",
109
+ parts: [],
110
+ links: [],
111
+ };
112
+ const childPart = {
113
+ id: createPartId(childResource, 0),
114
+ location: `${childLocation}#part/0`,
115
+ kind: entryType === "image" ? "image" : "text",
116
+ data: entryData,
117
+ mimeType: entryType === "image" ? imageMimeTypeFromLocation(name) : undefined,
118
+ };
119
+ // For text-like files, decode the content
120
+ if (childPart.kind === "text") {
121
+ try {
122
+ childPart.text = Buffer.from(entryData).toString("utf8");
123
+ }
124
+ catch {
125
+ // Binary file that isn't an image; leave data only
126
+ }
127
+ }
128
+ childResource.parts.push(childPart);
129
+ return childResource;
130
+ }
131
+ //# sourceMappingURL=zip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip.js","sourceRoot":"","sources":["../../src/parsers/zip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,yBAAyB,EACzB,UAAU,GACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEtE,MAAM,CAAC,MAAM,SAAS,GAAmB;IACvC,EAAE,EAAE,YAAY;IAChB,cAAc,EAAE,CAAC,KAAK,CAAC;IACvB,aAAa,EAAE,MAAM;IACrB,KAAK,CAAC,WAAW,CAAC,KAAa,EAAE,QAAwB;QACvD,OAAO,OAAO,CAAC,MAAM,SAAS,EAAE,CAAC,CAAC;IACpC,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;QACzB,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,CAAC,MAAM,SAAS,E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AY,EACZ,SAA6B,EAC7B,SAAqB,EACrB,IAAY,EACZ,UAA8B;IAE9B,MAAM,aAAa,GAAmB;QACpC,EAAE,EAAE,gBAAgB,CAAC,aAAa,EAAE,SAAS,IAAI,SAAS,CAAC;QAC3D,QAAQ,EAAE,aAAa;QACvB,IAAI,EAAE,SAAS,IAAI,SAAS;QAC5B,IAAI;QACJ,UAAU;QACV,IAAI;QACJ,QAAQ,EAAE,EAAE,IAAI,EAAE;QAClB,aAAa,EAAE,MAAM;QACrB,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,EAAE;KACV,CAAC;IAEF,MAAM,SAAS,GAAiB;QAC9B,EAAE,EAAE,YAAY,CAAC,aAAa,EAAE,CAAC,CAAC;QAClC,QAAQ,EAAE,GAAG,aAAa,SAAS;QACnC,IAAI,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;QAC9C,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;KAC9E,CAAC;IAEF,0CAA0C;IAC1C,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,SAAS,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC3D,CAAC;QAAC,MAAM,CAAC;YACP,mDAAmD;QACrD,CAAC;IACH,CAAC;IAED,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACpC,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,81 @@
1
+ import type { LoadedResource, LoadResourceOptions, ParsedResource, ParseOptions, RegisterParserOptions, ResolveOptions, ResourceParser, ResourceRegistryLike, ResourceResolver, ResourceSlice, ResourceSlicer, ResourceSource, ResourceStat, ResourceSupport, ResourceType, SliceOptions } from "./types";
2
+ /** Declarative definition of how a resource type is detected, registered on the registry. */
3
+ export interface ResourceTypeDefinition {
4
+ type: ResourceType;
5
+ /** File extensions (with or without leading dot) that map to this type. */
6
+ extensions?: string[];
7
+ /** Mime-type patterns that map to this type. */
8
+ mimePatterns?: RegExp[];
9
+ }
10
+ export declare class ResourceRegistry implements ResourceRegistryLike {
11
+ private readonly parsers;
12
+ private readonly slicers;
13
+ private readonly resolvers;
14
+ private readonly parserTypes;
15
+ private readonly slicerTypes;
16
+ private readonly typeConfigs;
17
+ private readonly extensionTypes;
18
+ private readonly mimeTypePatterns;
19
+ private parserOrder;
20
+ registerParser(parser: ResourceParser, options?: RegisterParserOptions): this;
21
+ /**
22
+ * Registers per-type options on the registry, covering both parse and slice behavior. These are
23
+ * merged underneath any per-call options (per-call wins), letting callers configure capabilities
24
+ * once — e.g. `renderPdfPages` / `convertToPdf`, PDF flags, `maxChars`/`minChars`, slicer choice,
25
+ * code patterns, or boundary strings — per type rather than on every call.
26
+ */
27
+ configureType(type: ResourceType, options: Partial<LoadResourceOptions>): this;
28
+ getTypeConfig(type: ResourceType): Partial<LoadResourceOptions> | undefined;
29
+ /** Returns the parsers registered for a type, ordered from highest to lowest priority. */
30
+ getParsers(type: ResourceType): ResourceParser[];
31
+ private recomputeDefaultSlicer;
32
+ registerSlicer(slicer: ResourceSlicer): this;
33
+ registerResolver(resolver: ResourceResolver): this;
34
+ inferType(location: string, mimeType?: string): ResourceType | undefined;
35
+ /** Maps a file extension (with or without leading dot) to a resource type. */
36
+ registerExtensionType(extension: string, type: ResourceType): this;
37
+ /** Maps a mime-type pattern to a resource type. Newly registered patterns take precedence. */
38
+ registerMimeType(pattern: RegExp, type: ResourceType): this;
39
+ /** Registers a resource type's detection rules (extensions and/or mime patterns) in one call. */
40
+ registerType(definition: ResourceTypeDefinition): this;
41
+ getDefaultSlicer(type: ResourceType): string | undefined;
42
+ getParser(type: ResourceType): ResourceParser | undefined;
43
+ getSlicer(typeOrId: ResourceType): ResourceSlicer | undefined;
44
+ getTypeSupport(type: ResourceType, signal?: AbortSignal): Promise<ResourceSupport>;
45
+ isTypeSupported(type: ResourceType, signal?: AbortSignal): Promise<boolean>;
46
+ canResolve(link: string, options?: ResolveOptions): Promise<boolean>;
47
+ /**
48
+ * Cheaply probes a link for its canonical location and modified time without loading it, using the
49
+ * first resolver that can both resolve and stat it. Returns undefined when no resolver supports it
50
+ * or none can stat cheaply. Useful for de-duplication and incremental-build decisions.
51
+ */
52
+ statLink(link: string, options?: ResolveOptions): Promise<ResourceStat | undefined>;
53
+ resolveLink(link: string, options?: ResolveOptions): Promise<ResourceSource>;
54
+ /**
55
+ * Resolves a fully-qualified, self-contained location (an http(s) URL, an absolute file path /
56
+ * file:// URL, or a zip-entry location) directly to a source — no base location required. Throws if
57
+ * the location is relative and therefore cannot be fetched on its own; pass `resolveLink` with a
58
+ * `baseLocation` for relative links instead.
59
+ */
60
+ locate(location: string, options?: ResolveOptions): Promise<ResourceSource>;
61
+ /** Returns the id of the first resolver that can handle a link, or undefined if none can. */
62
+ getResolverId(link: string, options?: ResolveOptions): Promise<string | undefined>;
63
+ parse(input: string | ResourceSource, options?: LoadResourceOptions): Promise<{
64
+ source: ResourceSource;
65
+ resource: ParsedResource;
66
+ }>;
67
+ /**
68
+ * Runs the parser stack for an already-resolved source. Parsers are attempted in priority order;
69
+ * a parser that returns `undefined` (declines) or throws causes a fallback to the next parser.
70
+ * If every parser throws, the collected errors are surfaced.
71
+ */
72
+ parseSource(source: ResourceSource, options?: ParseOptions): Promise<ParsedResource>;
73
+ slice(resource: ParsedResource, options?: SliceOptions): Promise<ResourceSlice[]>;
74
+ load(input: string | ResourceSource, options?: LoadResourceOptions): Promise<LoadedResource>;
75
+ private normalizeSource;
76
+ }
77
+ export declare function createFileResourceSource(filePath: string, type?: ResourceType): Promise<ResourceSource>;
78
+ export declare function createUrlResourceSource(url: string, input: Uint8Array, mimeType?: string): ResourceSource;
79
+ export declare function toFileUrl(location: string): string;
80
+ export declare function createParsedResource(source: ResourceSource): ParsedResource;
81
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,YAAY,EAEb,MAAM,SAAS,CAAC;AAqBjB,6FAA6F;AAC7F,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,YAAY,CAAC;IACnB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,qBAAa,gBAAiB,YAAW,oBAAoB;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqC;IAC7D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqC;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IACpD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0C;IACtE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmC;IAC/D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyD;IACrF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0E;IACzG,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkE;IACnG,OAAO,CAAC,WAAW,CAAK;IAExB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,GAAE,qBAA0B,GAAG,IAAI;IAgBjF;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,IAAI;IAM9E,aAAa,CAAC,IA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pathToFileURL } from "node:url";
4
+ import { DEFAULT_EXTENSION_TYPES, DEFAULT_MIME_TYPE_PATTERNS, assertNotAborted, basenameFromLocation, createResourceId, dedupeLinks, inferTypeFromExtension, inferTypeFromLocation, inferTypeFromMimePatterns, isSelfContainedLocation, mergeOptions } from "./utils";
5
+ export class ResourceRegistry {
6
+ parsers = new Map();
7
+ slicers = new Map();
8
+ resolvers = [];
9
+ parserTypes = new Map();
10
+ slicerTypes = new Map();
11
+ typeConfigs = new Map();
12
+ extensionTypes = new Map(Object.entries(DEFAULT_EXTENSION_TYPES));
13
+ mimeTypePatterns = [...DEFAULT_MIME_TYPE_PATTERNS];
14
+ parserOrder = 0;
15
+ registerParser(parser, options = {}) {
16
+ this.parsers.set(parser.id, parser);
17
+ const priority = options.priority ?? parser.priority ?? 0;
18
+ for (const type of parser.supportedTypes) {
19
+ const entries = (this.parserTypes.get(type) ?? []).filter((entry) => entry.id !== parser.id);
20
+ entries.push({ id: parser.id, priority, order: this.parserOrder++ });
21
+ // Higher priority first; ties broken by most-recent registration so later parsers override earlier ones.
22
+ entries.sort((a, b) => b.priority - a.priority || b.order - a.order);
23
+ this.parserTypes.set(type, entries);
24
+ this.recomputeDefaultSlicer(type);
25
+ }
26
+ return this;
27
+ }
28
+ /**
29
+ * Registers per-type options on the registry, covering both parse and slice behavior. These are
30
+ * merged underneath any per-call options (per-call wins), letting callers configure capabilities
31
+ * once — e.g. `renderPdfPages` / `convertToPdf`, PDF flags, `maxChars`/`minChars`, slicer choice,
32
+ * code patterns, or boundary strings — per type rather than on every call.
33
+ */
34
+ configureType(type, options) {
35
+ const existing = this.typeConfigs.get(type) ?? {};
36
+ this.typeConfigs.set(type, mergeOptions(existing, options));
37
+ return this;
38
+ }
39
+ getTypeConfig(type) {
40
+ return this.typeConfigs.get(type);
41
+ }
42
+ /** Returns the parsers registered for a type, ordered from highest to lowest priority. */
43
+ getParsers(type) {
44
+ const entries = this.parserTypes.get(type) ?? [];
45
+ return entries.map((entry) => this.parsers.get(entry.id)).filter((parser) => Boolean(parser));
46
+ }
47
+ recomputeDefaultSlicer(type) {
48
+ for (const parser of this.getParsers(type)) {
49
+ const defaultSlicer = typeof parser.defaultSlicer === "string" ? parser.defaultSlicer : parser.defaultSlicer[type];
50
+ if (defaultSlicer) {
51
+ this.slicerTypes.set(type, defaultSlicer);
52
+ return;
53
+ }
54
+ }
55
+ }
56
+ registerSlicer(slicer) {
57
+ this.slicers.set(slicer.id, slicer);
58
+ return this;
59
+ }
60
+ registerResolver(resolver) {
61
+ this.resolvers.push(resolver);
62
+ return this;
63
+ }
64
+ inferType(location, mimeType) {
65
+ return inferTypeFromMimePatterns(mimeType, this.mimeTypePatterns)
66
+ ?? inferTypeFromExtension(location, this.extensionTypes);
67
+ }
68
+ /** Maps a file extension (with or without leading dot) to a resource type. */
69
+ registerExtensionType(extension, type) {
70
+ const normalized = extension.startsWith(".") ? extension.toLowerCase() : `.${extension.toLowerCase()}`;
71
+ this.extensionTypes.set(normalized, type);
72
+ return this;
73
+ }
74
+ /** Maps a mime-type pattern to a resource type. Newly registered patterns take precedence. */
75
+ registerMimeType(pattern, type) {
76
+ this.mimeTypePatterns.unshift([pattern, type]);
77
+ return this;
78
+ }
79
+ /** Registers a resource type's detection rules (extensions and/or mime patterns) in one call. */
80
+ registerType(definition) {
81
+ for (const extension of definition.extensions ?? []) {
82
+ this.registerExtensionType(extension, definition.type);
83
+ }
84
+ for (const pattern of definition.mimePatterns ?? []) {
85
+ this.registerMimeType(pattern, definition.type);
86
+ }
87
+ return this;
88
+ }
89
+ getDefaultSlicer(type) {
90
+ return this.slicerTypes.get(type);
91
+ }
92
+ getParser(type) {
93
+ return this.getParsers(type)[0];
94
+ }
95
+ getSlicer(typeOrId) {
96
+ return this.slicers.get(typeOrId) ?? (this.slicerTypes.has(typeOrId) ? this.slicers.get(this.slicerTypes.get(typeOrId)) : undefined);
97
+ }
98
+ async getTypeSupport(type, signal) {
99
+ const parsers = this.getParsers(type);
100
+ const slicerId = this.getDefaultSlicer(type);
101
+ const slicer = slicerId ? this.slicers.get(slicerId) : undefined;
102
+ const context = { registry: this, signal };
103
+ // A type is parseable if any parser in its stack reports support.
104
+ let parserSupported = false;
105
+ let supportingParser;
106
+ for (const parser of parsers) {
107
+ if (await parser.isSupported?.(type, context) ?? true) {
108
+ parserSupported = true;
109
+ supportingParser = parser;
110
+ break;
111
+ }
112
+ }
113
+ const slicerSupported = slicer ? await slicer.isSupported?.(type, context) ?? true : false;
114
+ return {
115
+ type,
116
+ parserId: (supportingParser ?? parsers[0])?.id,
117
+ slicerId,
118
+ parser: parserSupported,
119
+ slicer: slicerSupported,
120
+ supported: parserSupported && slicerSupported && parsers.length > 0 && Boolean(slicer)
121
+ };
122
+ }
123
+ async isTypeSupported(type, signal) {
124
+ const support = await this.getTypeSupport(type, signal);
125
+ return support.supported;
126
+ }
127
+ async canResolve(link, options = {}) {
128
+ const context = { registry: this, options };
129
+ for (const resolver of this.resolvers) {
130
+ if (await resolver.canResolve(link, context)) {
131
+ return true;
132
+ }
133
+ }
134
+ return false;
135
+ }
136
+ /**
137
+ * Cheaply probes a link for its canonical location and modified time without loading it, using the
138
+ * first resolver that can both resolve and stat it. Returns undefined when no resolver supports it
139
+ * or none can stat cheaply. Useful for de-duplication and incremental-build decisions.
140
+ */
141
+ async statLink(link, options = {}) {
142
+ assertNotAborted(options.signal);
143
+ const context = { registry: this, options };
144
+ for (const resolver of this.resolvers) {
145
+ if (!resolver.stat)
146
+ continue;
147
+ if (await resolver.canResolve(link, context)) {
148
+ const result = await resolver.stat(link, context);
149
+ if (result)
150
+ return result;
151
+ }
152
+ }
153
+ return undefined;
154
+ }
155
+ async resolveLink(link, options = {}) {
156
+ assertNotAborted(options.signal);
157
+ const context = { registry: this, options };
158
+ for (const resolver of this.resolvers) {
159
+ if (await resolver.canResolve(link, context)) {
160
+ const source = await resolver.resolve(link, context);
161
+ if (source) {
162
+ return this.normalizeSource(source, options);
163
+ }
164
+ }
165
+ }
166
+ throw new Error(`No resolver available for resource link: ${link}`);
167
+ }
168
+ /**
169
+ * Resolves a fully-qualified, self-contained location (an http(s) URL, an absolute file path /
170
+ * file:// URL, or a zip-entry location) directly to a source — no base location required. Throws if
171
+ * the location is relative and therefore cannot be fetched on its own; pass `resolveLink` with a
172
+ * `baseLocation` for relative links instead.
173
+ */
174
+ async locate(location, options = {}) {
175
+ if (!isSelfContainedLocation(location)) {
176
+ throw new Error(`Location is not self-contained and cannot be fetched without a base: ${location}`);
177
+ }
178
+ return this.resolveLink(location, options);
179
+ }
180
+ /** Returns the id of the first resolver that can handle a link, or undefined if none can. */
181
+ async getResolverId(link, options = {}) {
182
+ const context = { registry: this, options };
183
+ for (const resolver of this.resolvers) {
184
+ if (await resolver.canResolve(link, context)) {
185
+ return resolver.id;
186
+ }
187
+ }
188
+ return undefined;
189
+ }
190
+ async parse(input, options = {}) {
191
+ const source = typeof input === "string"
192
+ ? await this.resolveLink(input, options)
193
+ : await this.normalizeSource(input, options);
194
+ const resource = await this.parseSource(source, options);
195
+ return { source, resource };
196
+ }
197
+ /**
198
+ * Runs the parser stack for an already-resolved source. Parsers are attempted in priority order;
199
+ * a parser that returns `undefined` (declines) or throws causes a fallback to the next parser.
200
+ * If every parser throws, the collected errors are surfaced.
201
+ */
202
+ async parseSource(source, options = {}) {
203
+ const type = source.type;
204
+ const parsers = this.getParsers(type);
205
+ if (parsers.length === 0) {
206
+ throw new Error(`No parser registered for resource type: ${type}`);
207
+ }
208
+ const mergedOptions = mergeOptions(this.typeConfigs.get(type), options);
209
+ const context = { registry: this, options: mergedOptions };
210
+ const errors = [];
211
+ for (const parser of parsers) {
212
+ assertNotAborted(mergedOptions.signal);
213
+ try {
214
+ const resource = await parser.parse(source, context);
215
+ if (resource) {
216
+ resource.links = dedupeLinks(resource.links);
217
+ return resource;
218
+ }
219
+ // Parser declined; fall through to the next one in the stack.
220
+ }
221
+ catch (error) {
222
+ // Never swallow aborts — propagate immediately rather than falling back.
223
+ if (mergedOptions.signal?.aborted) {
224
+ throw error;
225
+ }
226
+ errors.push(error);
227
+ }
228
+ }
229
+ if (errors.length === 1) {
230
+ throw errors[0];
231
+ }
232
+ if (errors.length > 1) {
233
+ throw new AggregateError(errors, `All ${errors.length} parsers failed for resource type: ${type}`);
234
+ }
235
+ throw new Error(`No parser could parse resource type: ${type} (all parsers declined)`);
236
+ }
237
+ async slice(resource, options = {}) {
238
+ // Merge per-type registry options (maxChars, slicer, boundaries, code patterns, …) under per-call.
239
+ const mergedOptions = mergeOptions(this.typeConfigs.get(resource.type), options);
240
+ const slicerId = mergedOptions.slicer ?? resource.defaultSlicer ?? this.getDefaultSlicer(resource.type);
241
+ if (!slicerId) {
242
+ throw new Error(`No default slicer registered for resource type: ${resource.type}`);
243
+ }
244
+ const slicer = this.slicers.get(slicerId);
245
+ if (!slicer) {
246
+ throw new Error(`Unknown slicer: ${slicerId}`);
247
+ }
248
+ const supported = await slicer.isSupported?.(resource.type, { registry: this, signal: mergedOptions.signal }) ?? true;
249
+ if (!supported) {
250
+ throw new Error(`Slicer ${slicer.id} reported that type ${resource.type} is not supported in this environment`);
251
+ }
252
+ const slices = await slicer.slice(resource, { registry: this, options: mergedOptions });
253
+ return slices;
254
+ }
255
+ async load(input, options = {}) {
256
+ const { source, resource } = await this.parse(input, options);
257
+ const slices = await this.slice(resource, options);
258
+ return { source, resource, slices };
259
+ }
260
+ async normalizeSource(source, options) {
261
+ const location = source.location;
262
+ const fallbackMimeType = "mimeType" in options ? options.mimeType : undefined;
263
+ const inferredType = source.type ?? this.inferType(location, source.mimeType ?? fallbackMimeType);
264
+ if (!inferredType) {
265
+ throw new Error(`Unable to infer resource type for ${location}`);
266
+ }
267
+ return {
268
+ ...source,
269
+ type: inferredType,
270
+ name: source.name ?? ("name" in options ? options.name : undefined) ?? basenameFromLocation(location),
271
+ mimeType: source.mimeType ?? fallbackMimeType,
272
+ metadata: {
273
+ ...(options.metadata ?? {}),
274
+ ...(source.metadata ?? {})
275
+ }
276
+ };
277
+ }
278
+ }
279
+ export async function createFileResourceSource(filePath, type) {
280
+ const absolutePath = path.isAbsolute(filePath) ? filePath : path.resolve(filePath);
281
+ const [input, stats] = await Promise.all([
282
+ readFile(absolutePath),
283
+ stat(absolutePath).catch(() => undefined)
284
+ ]);
285
+ return {
286
+ location: absolutePath,
287
+ input,
288
+ type,
289
+ name: path.basename(absolutePath),
290
+ modifiedAt: stats?.mtimeMs,
291
+ size: stats?.size
292
+ };
293
+ }
294
+ export function createUrlResourceSource(url, input, mimeType) {
295
+ return {
296
+ location: url,
297
+ input,
298
+ mimeType,
299
+ type: inferTypeFromLocation(url, mimeType),
300
+ name: basenameFromLocation(url)
301
+ };
302
+ }
303
+ export function toFileUrl(location) {
304
+ return pathToFileURL(location).toString();
305
+ }
306
+ export function createParsedResource(source) {
307
+ const type = source.type;
308
+ return {
309
+ id: createResourceId(source.location, type),
310
+ location: source.location,
311
+ type,
312
+ name: source.name ?? basenameFromLocation(source.location),
313
+ mimeType: source.mimeType,
314
+ modifiedAt: source.modifiedAt,
315
+ size: source.size,
316
+ metadata: source.metadata,
317
+ defaultSlicer: "text",
318
+ parts: [],
319
+ links: []
320
+ };
321
+ }
322
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAoBzC,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,YAAY,EACb,MAAM,SAAS,CAAC;AAiBjB,MAAM,OAAO,gBAAgB;IACV,OAAO,GAAG,IAAI,GAAG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M,CAAC,UAAU;QAC7B,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,aAAa,EAAE,MAAM;QACrB,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,EAAE;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { createPopplerRenderer, isPopplerAvailable, orderRenderedPages, } from "./poppler";
2
+ export type { PopplerImageFormat, PopplerRendererOptions, } from "./poppler";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/renderers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createPopplerRenderer, isPopplerAvailable, orderRenderedPages, } from "./poppler";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/renderers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,WAAW,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { RenderedPage, RenderPdfPagesFn } from "../types";
2
+ /** Output image format for poppler page rendering. */
3
+ export type PopplerImageFormat = "png" | "jpeg" | "tiff";
4
+ export interface PopplerRendererOptions {
5
+ /** Path to the directory containing the poppler binaries, passed to the node-poppler constructor. */
6
+ binaryPath?: string;
7
+ /** Output image format. Defaults to "png". */
8
+ format?: PopplerImageFormat;
9
+ /** Enable/disable font anti-aliasing. Defaults to "yes". */
10
+ antialiasFonts?: "yes" | "no";
11
+ /** Enable/disable vector anti-aliasing. Defaults to "yes". */
12
+ antialiasVectors?: "yes" | "no";
13
+ }
14
+ /**
15
+ * Maps the raw image files produced by poppler into ordered {@link RenderedPage} entries. Poppler
16
+ * names files "<base>-<pageNumber>.<ext>" (page number zero-padded by the total page count), so files
17
+ * are filtered by extension, ordered by their numeric page number, and given a 1-based fallback.
18
+ */
19
+ export declare function orderRenderedPages(files: string[], outputDir: string, format?: PopplerImageFormat): RenderedPage[];
20
+ /** Returns true if node-poppler (and its underlying poppler binaries) can be loaded. */
21
+ export declare function isPopplerAvailable(binaryPath?: string): Promise<boolean>;
22
+ /**
23
+ * Creates a {@link RenderPdfPagesFn} backed by poppler (via node-poppler's `pdfToPpm`). Pages are
24
+ * written one image per page into the output directory and returned in page order.
25
+ *
26
+ * Requires the optional `node-poppler` dependency and the poppler binaries to be installed:
27
+ * `npm install node-poppler`.
28
+ *
29
+ * @example
30
+ * const registry = createDefaultResourceRegistry();
31
+ * registry.configureType("pdf", {
32
+ * pdf: { renderPages: true, transcribePages: true },
33
+ * renderPdfPages: createPopplerRenderer(),
34
+ * transcribeImage: myTranscriber,
35
+ * });
36
+ */
37
+ export declare function createPopplerRenderer(options?: PopplerRendererOptions): RenderPdfPagesFn;
38
+ //# sourceMappingURL=poppler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poppler.d.ts","sourceRoot":"","sources":["../../src/renderers/poppler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAoB/D,sDAAsD;AACtD,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzD,MAAM,WAAW,sBAAsB;IACrC,qGAAqG;IACrG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,4DAA4D;IAC5D,cAAc,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IAC9B,8DAA8D;IAC9D,gBAAgB,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CACjC;AAQD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAE,kBAA0B,GAAG,YAAY,EAAE,CAazH;AAED,wFAAwF;AACxF,wBAAsB,kBAAkB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAS9E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B,GAAG,gBAAgB,CA6B5F"}