@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,8 @@
1
+ import { ResourceRegistry } from "./registry";
2
+ import { textParser, markdownParser, htmlParser, codeParser, imageParser, pdfParser, pdfRenderParser, excelParser, excelPdfParser, docxParser, docxPdfParser, zipParser } from "./parsers";
3
+ import { textSlicer, markdownSlicer, codeSlicer } from "./slicers";
4
+ import { fileResolver, urlResolver, zipResolver } from "./resolvers";
5
+ export { textParser, markdownParser, htmlParser, codeParser, imageParser, pdfParser, pdfRenderParser, excelParser, excelPdfParser, docxParser, docxPdfParser, zipParser, textSlicer, markdownSlicer, codeSlicer, fileResolver, urlResolver, zipResolver, };
6
+ export declare function createDefaultResourceRegistry(): ResourceRegistry;
7
+ export declare const defaultResourceRegistry: ResourceRegistry;
8
+ //# sourceMappingURL=default.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,UAAU,EACV,cAAc,EACd,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,WAAW,EACX,cAAc,EACd,UAAU,EACV,aAAa,EACb,SAAS,EACV,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,UAAU,EACV,cAAc,EACd,UAAU,EACX,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,YAAY,EACZ,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,UAAU,EACV,cAAc,EACd,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,WAAW,EACX,cAAc,EACd,UAAU,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACV,cAAc,EACd,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,GACZ,CAAC;AAEF,wBAAgB,6BAA6B,IAAI,gBAAgB,CAuBhE;AAED,eAAO,MAAM,uBAAuB,kBAAkC,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { ResourceRegistry } from "./registry";
2
+ import { textParser, markdownParser, htmlParser, codeParser, imageParser, pdfParser, pdfRenderParser, excelParser, excelPdfParser, docxParser, docxPdfParser, zipParser, } from "./parsers";
3
+ import { textSlicer, markdownSlicer, codeSlicer, } from "./slicers";
4
+ import { fileResolver, urlResolver, zipResolver, } from "./resolvers";
5
+ export { textParser, markdownParser, htmlParser, codeParser, imageParser, pdfParser, pdfRenderParser, excelParser, excelPdfParser, docxParser, docxPdfParser, zipParser, textSlicer, markdownSlicer, codeSlicer, fileResolver, urlResolver, zipResolver, };
6
+ export function createDefaultResourceRegistry() {
7
+ return new ResourceRegistry()
8
+ .registerParser(textParser)
9
+ .registerParser(markdownParser)
10
+ .registerParser(htmlParser)
11
+ .registerParser(codeParser)
12
+ .registerParser(imageParser)
13
+ // PDF: render-based parser is attempted first, falling back to plain text extraction.
14
+ .registerParser(pdfRenderParser)
15
+ .registerParser(pdfParser)
16
+ // Spreadsheets & DOCX: PDF-conversion parser is attempted first, falling back to native extraction.
17
+ .registerParser(excelPdfParser)
18
+ .registerParser(excelParser)
19
+ .registerParser(docxPdfParser)
20
+ .registerParser(docxParser)
21
+ .registerParser(zipParser)
22
+ .registerSlicer(textSlicer)
23
+ .registerSlicer(markdownSlicer)
24
+ .registerSlicer(codeSlicer)
25
+ // Zip resolver first so entry-relative links win over the generic file/url resolvers.
26
+ .registerResolver(zipResolver)
27
+ .registerResolver(fileResolver)
28
+ .registerResolver(urlResolver);
29
+ }
30
+ export const defaultResourceRegistry = createDefaultResourceRegistry();
31
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,UAAU,EACV,cAAc,EACd,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,WAAW,EACX,cAAc,EACd,UAAU,EACV,aAAa,EACb,SAAS,GACV,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,UAAU,EACV,cAAc,EACd,UAAU,GACX,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,YAAY,EACZ,WAAW,EACX,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,UAAU,EACV,cAAc,EACd,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,WAAW,EACX,cAAc,EACd,UAAU,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACV,cAAc,EACd,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,GACZ,CAAC;AAEF,MAAM,UAAU,6BAA6B;IAC3C,OAAO,IAAI,gBAAgB,EAAE;SAC1B,cAAc,CAAC,UAAU,CAAC;SAC1B,cAAc,CAAC,cAAc,CAAC;SAC9B,cAAc,CAAC,UAAU,CAAC;SAC1B,cAAc,CAAC,UAAU,CAAC;SAC1B,cAAc,CAAC,WAAW,CAAC;QAC5B,sFAAsF;SACrF,cAAc,CAAC,eAAe,CAAC;SAC/B,cAAc,CAAC,SAAS,CAAC;QAC1B,oGAAoG;SACnG,cAAc,CAAC,cAAc,CAAC;SAC9B,cAAc,CAAC,WAAW,CAAC;SAC3B,cAAc,CAAC,aAAa,CAAC;SAC7B,cAAc,CAAC,UAAU,CAAC;SAC1B,cAAc,CAAC,SAAS,CAAC;SACzB,cAAc,CAAC,UAAU,CAAC;SAC1B,cAAc,CAAC,cAAc,CAAC;SAC9B,cAAc,CAAC,UAAU,CAAC;QAC3B,sFAAsF;SACrF,gBAAgB,CAAC,WAAW,CAAC;SAC7B,gBAAgB,CAAC,YAAY,CAAC;SAC9B,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,6BAA6B,EAAE,CAAC"}
@@ -0,0 +1,93 @@
1
+ import type { ResourceRegistry } from "./registry";
2
+ import type { LoadResourceOptions, ParsedResource, ResourceLink, ResourceLocation, ResourceSlice, ResourceSource } from "./types";
3
+ /** Why a link's target was not loaded into the graph. */
4
+ export type GraphEdgeSkipReason = "external" | "resource-links-disabled" | "filtered" | "unresolved" | "max-depth" | "max-resources" | "skipped" | "error";
5
+ export interface ResourceGraphEdge {
6
+ /** The originating link. */
7
+ link: ResourceLink;
8
+ /** Canonical location of the resolved target, if it could be determined. */
9
+ targetLocation?: ResourceLocation;
10
+ /** Node id of the target, if it was loaded into the graph. */
11
+ targetId?: string;
12
+ /** Whether the target is present as a node in the graph. */
13
+ loaded: boolean;
14
+ /** Why the target was not loaded (only set when `loaded` is false). */
15
+ reason?: GraphEdgeSkipReason;
16
+ /** Error message when `reason` is "error". */
17
+ error?: string;
18
+ }
19
+ export interface ResourceGraphNode {
20
+ id: string;
21
+ location: ResourceLocation;
22
+ type: string;
23
+ /** Shortest distance (in links/children) from a root. */
24
+ depth: number;
25
+ /** Estimated last-modified time of the underlying source, in epoch milliseconds, if known. */
26
+ modifiedAt?: number;
27
+ resource: ParsedResource;
28
+ /** Slices for this resource, if `includeSlices` was enabled. */
29
+ slices?: ResourceSlice[];
30
+ /** True when the resource was reused from the caller's cache rather than freshly parsed. */
31
+ reused: boolean;
32
+ /** Outgoing link edges. */
33
+ edges: ResourceGraphEdge[];
34
+ /** Locations of child resources (e.g. zip entries, rendered PDF pages) contained by this node. */
35
+ children: ResourceLocation[];
36
+ /** Locations of nodes that link to / contain this node. */
37
+ parents: ResourceLocation[];
38
+ }
39
+ export interface ResourceGraph {
40
+ /** Locations of the root nodes the graph was built from. */
41
+ roots: ResourceLocation[];
42
+ /** All nodes keyed by canonical location. */
43
+ nodes: Map<ResourceLocation, ResourceGraphNode>;
44
+ }
45
+ /** Information about a prospective link target, passed to incremental-build hooks. */
46
+ export interface GraphTarget {
47
+ location: ResourceLocation;
48
+ modifiedAt?: number;
49
+ link: ResourceLink;
50
+ depth: number;
51
+ }
52
+ export interface BuildGraphOptions extends LoadResourceOptions {
53
+ /** Maximum link/child distance from a root to traverse. Defaults to unlimited. */
54
+ maxDepth?: number;
55
+ /** Maximum number of nodes to load. Defaults to unlimited. Existing nodes are never re-counted. */
56
+ maxResources?: number;
57
+ /** Traverse child resources (zip entries, rendered PDF pages, …) as nodes. Defaults to true. */
58
+ followChildren?: boolean;
59
+ /** Follow external (e.g. http) links. Defaults to true. */
60
+ followExternal?: boolean;
61
+ /** Follow internal/relative resource links. Defaults to true. */
62
+ followResourceLinks?: boolean;
63
+ /** Also slice each loaded resource and attach the slices to its node. Defaults to false. */
64
+ includeSlices?: boolean;
65
+ /** Per-link filter; return false to skip following a link. */
66
+ shouldFollow?: (link: ResourceLink, from: ResourceGraphNode) => boolean;
67
+ /**
68
+ * Incremental-build hook: decide whether to (re)load a target. Return false to skip parsing; if a
69
+ * cached resource is available via {@link BuildGraphOptions.getCached} it is reused instead, keeping
70
+ * the graph connected. The `modifiedAt` is supplied (when known) so callers can compare against a
71
+ * previously-stored build time.
72
+ */
73
+ shouldLoad?: (target: GraphTarget) => boolean | Promise<boolean>;
74
+ /**
75
+ * Supplies a previously-parsed resource for a location, avoiding a re-parse. Combined with
76
+ * {@link BuildGraphOptions.shouldLoad}, enables incremental graph rebuilds: unchanged resources are
77
+ * reused from a cache, changed ones are re-parsed.
78
+ */
79
+ getCached?: (location: ResourceLocation, modifiedAt?: number) => ParsedResource | undefined;
80
+ /** Invoked whenever a node is added to the graph (freshly loaded or reused). */
81
+ onNode?: (node: ResourceGraphNode) => void;
82
+ }
83
+ /**
84
+ * Builds a graph of resources and the links between them, starting from one or more roots, by loading
85
+ * each link target as a resource and recursing into its links and children. Effort is de-duplicated:
86
+ * each canonical location is loaded at most once, so cycles and shared references are handled and the
87
+ * traversal terminates even on infinitely cross-referencing content.
88
+ *
89
+ * Pass {@link BuildGraphOptions.shouldLoad} + {@link BuildGraphOptions.getCached} to perform
90
+ * incremental rebuilds against a target system, using each resource's `modifiedAt` to detect staleness.
91
+ */
92
+ export declare function buildResourceGraph(registry: ResourceRegistry, inputs: string | ResourceSource | Array<string | ResourceSource>, options?: BuildGraphOptions): Promise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AkB,CACtC,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,MAAM,GAAG,cAAc,GAAG,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,EAChE,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,aAAa,CAAC,CA+JxB"}
package/dist/graph.js ADDED
@@ -0,0 +1,154 @@
1
+ import { assertNotAborted } from "./utils";
2
+ /**
3
+ * Builds a graph of resources and the links between them, starting from one or more roots, by loading
4
+ * each link target as a resource and recursing into its links and children. Effort is de-duplicated:
5
+ * each canonical location is loaded at most once, so cycles and shared references are handled and the
6
+ * traversal terminates even on infinitely cross-referencing content.
7
+ *
8
+ * Pass {@link BuildGraphOptions.shouldLoad} + {@link BuildGraphOptions.getCached} to perform
9
+ * incremental rebuilds against a target system, using each resource's `modifiedAt` to detect staleness.
10
+ */
11
+ export async function buildResourceGraph(registry, inputs, options = {}) {
12
+ const maxDepth = options.maxDepth ?? Number.POSITIVE_INFINITY;
13
+ const maxResources = options.maxResources ?? Number.POSITIVE_INFINITY;
14
+ const followChildren = options.followChildren ?? true;
15
+ const followExternal = options.followExternal ?? true;
16
+ const followResourceLinks = options.followResourceLinks ?? true;
17
+ const nodes = new Map();
18
+ const roots = [];
19
+ const queue = [];
20
+ const addParent = (node, parent) => {
21
+ if (parent !== node.location && !node.parents.includes(parent)) {
22
+ node.parents.push(parent);
23
+ }
24
+ };
25
+ const registerNode = async (resource, depth, reused) => {
26
+ const existing = nodes.get(resource.location);
27
+ if (existing) {
28
+ existing.depth = Math.min(existing.depth, depth);
29
+ return existing;
30
+ }
31
+ const node = {
32
+ id: resource.id,
33
+ location: resource.location,
34
+ type: resource.type,
35
+ depth,
36
+ modifiedAt: resource.modifiedAt,
37
+ resource,
38
+ reused,
39
+ edges: [],
40
+ children: [],
41
+ parents: [],
42
+ };
43
+ if (options.includeSlices) {
44
+ node.slices = await registry.slice(resource, options);
45
+ }
46
+ nodes.set(node.location, node);
47
+ options.onNode?.(node);
48
+ queue.push(node.location);
49
+ return node;
50
+ };
51
+ // Seed roots.
52
+ const rootInputs = Array.isArray(inputs) ? inputs : [inputs];
53
+ for (const input of rootInputs) {
54
+ assertNotAborted(options.signal);
55
+ const { resource } = await registry.parse(input, options);
56
+ const node = await registerNode(resource, 0, false);
57
+ if (!roots.includes(node.location)) {
58
+ roots.push(node.location);
59
+ }
60
+ }
61
+ // Breadth-first expansion.
62
+ while (queue.length > 0) {
63
+ assertNotAborted(options.signal);
64
+ const location = queue.shift();
65
+ const node = nodes.get(location);
66
+ if (node.depth >= maxDepth) {
67
+ continue;
68
+ }
69
+ if (followChildren) {
70
+ for (const child of node.resource.children ?? []) {
71
+ if (!nodes.has(child.location) && nodes.size >= maxResources) {
72
+ continue;
73
+ }
74
+ const childNode = await registerNode(child, node.depth + 1, false);
75
+ addParent(childNode, node.location);
76
+ if (!node.children.includes(child.location)) {
77
+ node.children.push(child.location);
78
+ }
79
+ }
80
+ }
81
+ for (const link of node.resource.links) {
82
+ assertNotAborted(options.signal);
83
+ node.edges.push(await followLink(link, node));
84
+ }
85
+ }
86
+ return { roots, nodes };
87
+ async function followLink(link, from) {
88
+ const isExternal = link.kind === "external";
89
+ if (isExternal && !followExternal) {
90
+ return { link, loaded: false, reason: "external" };
91
+ }
92
+ if (!isExternal && !followResourceLinks) {
93
+ return { link, loaded: false, reason: "resource-links-disabled" };
94
+ }
95
+ if (options.shouldFollow && !options.shouldFollow(link, from)) {
96
+ return { link, loaded: false, reason: "filtered" };
97
+ }
98
+ const linkOptions = { ...options, baseLocation: from.location };
99
+ const targetDepth = from.depth + 1;
100
+ if (!(await registry.canResolve(link.value, linkOptions))) {
101
+ return { link, loaded: false, reason: "unresolved" };
102
+ }
103
+ // Probe the canonical location (and modified time) cheaply for de-duplication / incrementality.
104
+ const stat = await registry.statLink(link.value, linkOptions).catch(() => undefined);
105
+ const probedLocation = stat?.location;
106
+ if (probedLocation) {
107
+ const known = nodes.get(probedLocation);
108
+ if (known) {
109
+ addParent(known, from.location);
110
+ return { link, loaded: true, targetLocation: known.location, targetId: known.id };
111
+ }
112
+ }
113
+ if (targetDepth > maxDepth) {
114
+ return { link, loaded: false, reason: "max-depth", targetLocation: probedLocation };
115
+ }
116
+ // Incremental-build hook: optionally skip (re)parsing and reuse a cached resource.
117
+ if (options.shouldLoad) {
118
+ const shouldLoad = await options.shouldLoad({
119
+ location: probedLocation ?? link.value,
120
+ modifiedAt: stat?.modifiedAt,
121
+ link,
122
+ depth: targetDepth,
123
+ });
124
+ if (!shouldLoad) {
125
+ const cached = options.getCached?.(probedLocation ?? link.value, stat?.modifiedAt);
126
+ if (cached) {
127
+ const node = await registerNode(cached, targetDepth, true);
128
+ addParent(node, from.location);
129
+ return { link, loaded: true, targetLocation: node.location, targetId: node.id };
130
+ }
131
+ return { link, loaded: false, reason: "skipped", targetLocation: probedLocation };
132
+ }
133
+ }
134
+ if (nodes.size >= maxResources) {
135
+ return { link, loaded: false, reason: "max-resources", targetLocation: probedLocation };
136
+ }
137
+ try {
138
+ const { resource } = await registry.parse(link.value, linkOptions);
139
+ const node = await registerNode(resource, targetDepth, false);
140
+ addParent(node, from.location);
141
+ return { link, loaded: true, targetLocation: node.location, targetId: node.id };
142
+ }
143
+ catch (error) {
144
+ return {
145
+ link,
146
+ loaded: false,
147
+ reason: "error",
148
+ error: error instanceof Error ? error.message : String(error),
149
+ targetLocation: probedLocation,
150
+ };
151
+ }
152
+ }
153
+ }
154
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAgG3C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAA0B,EAC1B,MAAgE,EAChE,UAA6B,EAAE;IAE/B,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,MAAM,CAAC,iBAAiB,CAAC;IAC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EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;QAC1F,CAAC;QAED,IAAI,CAAC;YACH,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;YACnE,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;YAC9D,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;QAClF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,IAAI;gBACJ,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,OAAO;gBACf,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7D,cAAc,EAAE,cAAc;aAC/B,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ export * from "./types";
2
+ export * from "./registry";
3
+ export * from "./renderers";
4
+ export * from "./segmenters";
5
+ export * from "./graph";
6
+ export { CODE_TYPES, DEFAULT_EXTENSION_TYPES, DEFAULT_IMAGE_EXTENSION_MIME, DEFAULT_MARKUP_TYPES, DEFAULT_MAX_CHARS, DEFAULT_MIME_TYPE_PATTERNS, DEFAULT_MIN_CHARS, ZIP_ENTRY_MARKER, basenameFromLocation, buildZipEntryLocation, imageMimeTypeFromLocation, inferLocationScheme, inferTypeFromExtension, inferTypeFromLocation, inferTypeFromMimePatterns, inferTypeFromMimeType, isHttpUrl, isSelfContainedLocation, isZipEntryLocation, mergeOptions, parseZipEntryLocation, resolveZipEntryName, extractLinksFromCode, extractLinksFromHtml, extractLinksFromMarkdown, extractLinksFromText, htmlToMarkdown, splitTextByBoundaries } from "./utils";
7
+ export type { LocationScheme } from "./utils";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,4BAA4B,EAC5B,oBAAoB,EACpB,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,SAAS,EACT,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACtB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./types";
2
+ export * from "./registry";
3
+ export * from "./renderers";
4
+ export * from "./segmenters";
5
+ export * from "./graph";
6
+ export { CODE_TYPES, DEFAULT_EXTENSION_TYPES, DEFAULT_IMAGE_EXTENSION_MIME, DEFAULT_MARKUP_TYPES, DEFAULT_MAX_CHARS, DEFAULT_MIME_TYPE_PATTERNS, DEFAULT_MIN_CHARS, ZIP_ENTRY_MARKER, basenameFromLocation, buildZipEntryLocation, imageMimeTypeFromLocation, inferLocationScheme, inferTypeFromExtension, inferTypeFromLocation, inferTypeFromMimePatterns, inferTypeFromMimeType, isHttpUrl, isSelfContainedLocation, isZipEntryLocation, mergeOptions, parseZipEntryLocation, resolveZipEntryName, extractLinksFromCode, extractLinksFromHtml, extractLinksFromMarkdown, extractLinksFromText, htmlToMarkdown, splitTextByBoundaries } from "./utils";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,4BAA4B,EAC5B,oBAAoB,EACpB,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,SAAS,EACT,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACtB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ResourceParser } from "../types";
2
+ export declare const codeParser: ResourceParser;
3
+ //# sourceMappingURL=code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/parsers/code.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,UAAU,CAAC;AAW7D,eAAO,MAAM,UAAU,EAAE,cAuBxB,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { createParsedResource } from "../registry";
3
+ import { CODE_TYPES, assertNotAborted, collectInput, createPartId, dedupeLinks, extractLinksFromCode, extractLinksFromText, } from "../utils";
4
+ export const codeParser = {
5
+ id: "code-parser",
6
+ supportedTypes: [...CODE_TYPES],
7
+ defaultSlicer: "code",
8
+ async parse(source, context) {
9
+ assertNotAborted(context.options.signal);
10
+ const rawText = Buffer.from(await collectInput(source.input)).toString("utf8");
11
+ const resource = createParsedResource(source);
12
+ resource.defaultSlicer = "code";
13
+ const part = {
14
+ id: createPartId(resource, 0),
15
+ location: `${resource.location}#part/0`,
16
+ kind: "text",
17
+ text: rawText,
18
+ links: dedupeLinks([
19
+ ...extractLinksFromCode(rawText, `${resource.location}#part/0`),
20
+ ...extractLinksFromText(rawText, `${resource.location}#part/0`)
21
+ ])
22
+ };
23
+ resource.parts.push(part);
24
+ resource.links = part.links ?? [];
25
+ return resource;
26
+ }
27
+ };
28
+ //# sourceMappingURL=code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/parsers/code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAElB,MAAM,CAAC,MAAM,UAAU,GAAmB;IACxC,EAAE,EAAE,aAAa;IACjB,cAAc,EAAE,CAAC,GAAG,UAAU,CAAC;IAC/B,aAAa,EAAE,MAAM;IACrB,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;QACzB,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/E,MAAM,QAAQ,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;QAC9C,QAAQ,CAAC,aAAa,GAAG,MAAM,CAAC;QAChC,MAAM,IAAI,GAAiB;YACzB,EAAE,EAAE,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC7B,QAAQ,EAAE,GAAG,QAAQ,CAAC,QAAQ,SAAS;YACvC,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,WAAW,CAAC;gBACjB,GAAG,oBAAoB,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,QAAQ,SAAS,CAAC;gBAC/D,GAAG,oBAAoB,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,QAAQ,SAAS,CAAC;aAChE,CAAC;SACH,CAAC;QACF,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAClC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ResourceParser } from "../types";
2
+ /**
3
+ * Higher-priority DOCX parser that converts the document to PDF and delegates to the PDF parser stack
4
+ * for richer output (rendered pages, transcription, etc.). Declines (falls back to {@link docxParser})
5
+ * when no `convertToPdf` function is configured or conversion fails.
6
+ */
7
+ export declare const docxPdfParser: ResourceParser;
8
+ /** Base DOCX parser that converts the document to markdown via mammoth. Fallback in the DOCX stack. */
9
+ export declare const docxParser: ResourceParser;
10
+ //# sourceMappingURL=docx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docx.d.ts","sourceRoot":"","sources":["../../src/parsers/docx.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAgC,MAAM,UAAU,CAAC;AAuB7E;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,cAkC3B,CAAC;AAEF,uGAAuG;AACvG,eAAO,MAAM,UAAU,EAAE,cAmCxB,CAAC"}
@@ -0,0 +1,89 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { createReadStream } from "node:fs";
3
+ import { createParsedResource } from "../registry";
4
+ import { assertNotAborted, collectInput, createPartId, dedupeLinks, extractLinksFromText, htmlToMarkdown, toFilePath, } from "../utils";
5
+ let mammothModule;
6
+ async function loadMammoth() {
7
+ if (mammothModule)
8
+ return mammothModule;
9
+ try {
10
+ mammothModule = await import("mammoth");
11
+ return mammothModule;
12
+ }
13
+ catch {
14
+ return undefined;
15
+ }
16
+ }
17
+ /**
18
+ * Higher-priority DOCX parser that converts the document to PDF and delegates to the PDF parser stack
19
+ * for richer output (rendered pages, transcription, etc.). Declines (falls back to {@link docxParser})
20
+ * when no `convertToPdf` function is configured or conversion fails.
21
+ */
22
+ export const docxPdfParser = {
23
+ id: "docx-pdf-parser",
24
+ supportedTypes: ["docx"],
25
+ defaultSlicer: "markdown",
26
+ priority: 10,
27
+ async isSupported(_type, context) {
28
+ return Boolean(context.registry.getTypeConfig?.("docx")?.convertToPdf);
29
+ },
30
+ async parse(source, context) {
31
+ assertNotAborted(context.options.signal);
32
+ const convertToPdf = context.options.convertToPdf;
33
+ if (!convertToPdf) {
34
+ return undefined;
35
+ }
36
+ const sourceFilePath = toFilePath(source.location);
37
+ const pdfPath = await convertToPdf(sourceFilePath, context.options.signal);
38
+ const pdfSource = {
39
+ ...source,
40
+ location: pdfPath,
41
+ type: "pdf",
42
+ mimeType: "application/pdf",
43
+ input: (() => createReadStream(pdfPath))(),
44
+ metadata: { ...source.metadata, convertedFrom: source.location },
45
+ };
46
+ // Delegate through the registry so the full PDF parser stack (render + text) applies.
47
+ const result = await context.registry.parseSource(pdfSource, context.options);
48
+ // Restore original location info
49
+ result.location = source.location;
50
+ result.name = source.name ?? result.name;
51
+ result.metadata = { ...result.metadata, convertedFrom: "docx", pdfPath };
52
+ return result;
53
+ }
54
+ };
55
+ /** Base DOCX parser that converts the document to markdown via mammoth. Fallback in the DOCX stack. */
56
+ export const docxParser = {
57
+ id: "docx-parser",
58
+ supportedTypes: ["docx"],
59
+ defaultSlicer: "markdown",
60
+ async isSupported(_type, _context) {
61
+ return Boolean(await loadMammoth());
62
+ },
63
+ async parse(source, context) {
64
+ assertNotAborted(context.options.signal);
65
+ const mammoth = await loadMammoth();
66
+ if (!mammoth) {
67
+ throw new Error("mammoth is not installed. Install it to parse DOCX resources: npm install mammoth");
68
+ }
69
+ const data = await collectInput(source.input);
70
+ const result = await mammoth.convertToHtml({ buffer: Buffer.from(data) });
71
+ const markdown = htmlToMarkdown(result.value);
72
+ const resource = createParsedResource(source);
73
+ resource.defaultSlicer = "markdown";
74
+ const part = {
75
+ id: createPartId(resource, 0),
76
+ location: `${resource.location}#part/0`,
77
+ kind: "text",
78
+ text: markdown,
79
+ metadata: { originalType: "docx" },
80
+ links: dedupeLinks([
81
+ ...extractLinksFromText(markdown, `${resource.location}#part/0`)
82
+ ])
83
+ };
84
+ resource.parts.push(part);
85
+ resource.links = part.links ?? [];
86
+ return resource;
87
+ }
88
+ };
89
+ //# sourceMappingURL=docx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docx.js","sourceRoot":"","sources":["../../src/parsers/docx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,UAAU,GACX,MAAM,UAAU,CAAC;AAElB,IAAI,aAAkB,CAAC;AAEvB,KAAK,UAAU,WAAW;IACxB,IAAI,aAAa;QAAE,OAAO,aAAa,CAAC;IACxC,IAAI,CAAC;QACH,aAAa,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;QACxC,OAAO,aAAa,CAAC;IACvB,CAAC;IAAC,MAAM,CAA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AAE,CAAC,CAAC;YAC7B,QAAQ,EAAE,GAAG,QAAQ,CAAC,QAAQ,SAAS;YACvC,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE;YAClC,KAAK,EAAE,WAAW,CAAC;gBACjB,GAAG,oBAAoB,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,QAAQ,SAAS,CAAC;aACjE,CAAC;SACH,CAAC;QACF,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAClC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { ResourceParser } from "../types";
2
+ /**
3
+ * Higher-priority spreadsheet parser that converts to PDF and delegates to the PDF parser stack when
4
+ * PDF rendering is enabled. Declines (falls back to {@link excelParser}) when conversion/rendering is
5
+ * not configured or conversion fails.
6
+ */
7
+ export declare const excelPdfParser: ResourceParser;
8
+ export declare const excelParser: ResourceParser;
9
+ //# sourceMappingURL=excel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excel.d.ts","sourceRoot":"","sources":["../../src/parsers/excel.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAkB,cAAc,EAAgC,MAAM,UAAU,CAAC;AAuE7F;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,cAkC5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,cAoEzB,CAAC"}