@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,78 @@
1
+ import { CODE_TYPES, DEFAULT_MAX_CHARS, DEFAULT_MIN_CHARS, createSliceId, dedupeLinks, extractLinksFromCode, extractLinksFromText, finalizeSlice, normalizeDeclaration, } from "../utils";
2
+ import { defaultTextSegmenter } from "../segmenters";
3
+ const DEFAULT_DECLARATION_PATTERN = /^(export\s+)?(async\s+)?(function|class|interface|type|enum|const|let|var)\s+([^=(<{]+)/;
4
+ const DEFAULT_IMPORT_PATTERN = /^(import\b|export\b[^;]*\bfrom\b|const\b[^;]*=\s*require\()/;
5
+ const DEFAULT_CODE_BOUNDARIES = ["\n\n", "\n", " "];
6
+ const DEFAULT_MAX_IMPORT_PREFIXES = 5;
7
+ export const codeSlicer = {
8
+ id: "code",
9
+ supportedTypes: [...CODE_TYPES],
10
+ async slice(resource, context) {
11
+ const slices = [];
12
+ const maxChars = context.options.maxChars ?? DEFAULT_MAX_CHARS;
13
+ const minChars = context.options.minChars ?? DEFAULT_MIN_CHARS;
14
+ const boundaries = context.options.boundaries ?? DEFAULT_CODE_BOUNDARIES;
15
+ const segment = context.options.segmenter ?? defaultTextSegmenter;
16
+ const codeOpts = context.options.code ?? {};
17
+ const declarationPattern = codeOpts.declarationPattern ?? DEFAULT_DECLARATION_PATTERN;
18
+ const importPattern = codeOpts.importPattern ?? DEFAULT_IMPORT_PATTERN;
19
+ const maxImportPrefixes = codeOpts.maxImportPrefixes ?? DEFAULT_MAX_IMPORT_PREFIXES;
20
+ for (const part of resource.parts) {
21
+ if (!part.text) {
22
+ continue;
23
+ }
24
+ const lines = part.text.split(/(?<=\n)/);
25
+ const declarationIndexes = [];
26
+ let offset = 0;
27
+ const importLines = [];
28
+ lines.forEach((line) => {
29
+ const trimmed = line.trim();
30
+ if (importPattern.test(trimmed)) {
31
+ importLines.push(normalizeDeclaration(trimmed));
32
+ }
33
+ if (declarationPattern.test(trimmed)) {
34
+ declarationIndexes.push(offset);
35
+ }
36
+ offset += line.length;
37
+ });
38
+ const starts = declarationIndexes.length > 0 ? declarationIndexes : [0];
39
+ for (const [index, start] of starts.entries()) {
40
+ const end = starts[index + 1] ?? part.text.length;
41
+ const block = part.text.slice(start, end);
42
+ const declaration = normalizeDeclaration(block.split(/\r?\n/, 1)[0] ?? "");
43
+ const segments = await segment(block, {
44
+ maxChars,
45
+ minChars,
46
+ boundaries,
47
+ type: resource.type,
48
+ slicerId: "code",
49
+ signal: context.options.signal,
50
+ });
51
+ segments.forEach((seg, segmentIndex) => {
52
+ const location = `${part.location}#block/${index}/slice/${segmentIndex}`;
53
+ const rawSlice = {
54
+ id: createSliceId(part, slices.length),
55
+ resourceId: resource.id,
56
+ partId: part.id,
57
+ location,
58
+ text: seg.text,
59
+ start: start + seg.start,
60
+ end: start + seg.end,
61
+ context: {
62
+ declaration,
63
+ prefixes: importLines.slice(0, maxImportPrefixes)
64
+ },
65
+ links: dedupeLinks([
66
+ ...(part.links ?? []),
67
+ ...extractLinksFromCode(seg.text, location),
68
+ ...extractLinksFromText(seg.text, location)
69
+ ])
70
+ };
71
+ slices.push(finalizeSlice(resource, part, rawSlice, context.options));
72
+ });
73
+ }
74
+ }
75
+ return slices;
76
+ }
77
+ };
78
+ //# sourceMappingURL=code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/slicers/code.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,2BAA2B,GAAG,yFAAyF,CAAC;AAC9H,MAAM,sBAAsB,GAAG,6DAA6D,CAAC;AAC7F,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;AACpD,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,UAAU,GAAmB;IACxC,EAAE,EAAE,MAAM;IACV,c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AAI,EAAE,MAAM,CAAC,MAAM,CAAC;wBACtC,UAAU,EAAE,QAAQ,CAAC,EAAE;wBACvB,MAAM,EAAE,IAAI,CAAC,EAAE;wBACf,QAAQ;wBACR,IAAI,EAAE,GAAG,CAAC,IAAI;wBACd,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,KAAK;wBACxB,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG;wBACpB,OAAO,EAAE;4BACP,WAAW;4BACX,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC;yBAClD;wBACD,KAAK,EAAE,WAAW,CAAC;4BACjB,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;4BACrB,GAAG,oBAAoB,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;4BAC3C,GAAG,oBAAoB,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;yBAC5C,CAAC;qBACH,CAAC;oBACF,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;gBACxE,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { textSlicer } from "./text";
2
+ export { markdownSlicer } from "./markdown";
3
+ export { codeSlicer } from "./code";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/slicers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { textSlicer } from "./text";
2
+ export { markdownSlicer } from "./markdown";
3
+ export { codeSlicer } from "./code";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/slicers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ResourceSlicer } from "../types";
2
+ export declare const markdownSlicer: ResourceSlicer;
3
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/slicers/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,UAAU,CAAC;AAe9D,eAAO,MAAM,cAAc,EAAE,cAqE5B,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { DEFAULT_MAX_CHARS, DEFAULT_MIN_CHARS, createSliceId, dedupeLinks, extractLinksFromMarkdown, extractLinksFromText, finalizeSlice, toHeadingContext, } from "../utils";
2
+ import { defaultTextSegmenter } from "../segmenters";
3
+ const DEFAULT_MARKDOWN_BOUNDARIES = ["\n\n", "\n", ". ", " "];
4
+ export const markdownSlicer = {
5
+ id: "markdown",
6
+ supportedTypes: ["markdown", "html"],
7
+ async slice(resource, context) {
8
+ const slices = [];
9
+ const maxChars = context.options.maxChars ?? DEFAULT_MAX_CHARS;
10
+ const minChars = context.options.minChars ?? DEFAULT_MIN_CHARS;
11
+ const boundaries = context.options.boundaries ?? DEFAULT_MARKDOWN_BOUNDARIES;
12
+ const segment = context.options.segmenter ?? defaultTextSegmenter;
13
+ for (const part of resource.parts) {
14
+ if (!part.text) {
15
+ continue;
16
+ }
17
+ const text = part.text;
18
+ const headingMatches = [...text.matchAll(/^(#{1,6}) (.+)$/gm)];
19
+ const sections = headingMatches.length === 0
20
+ ? [{ start: 0, end: text.length, headings: [] }]
21
+ : headingMatches.map((match, index) => {
22
+ const level = match[1].length;
23
+ const title = match[2].trim();
24
+ const start = match.index ?? 0;
25
+ const end = headingMatches[index + 1]?.index ?? text.length;
26
+ const headings = headingMatches
27
+ .slice(0, index + 1)
28
+ .reduce((stack, current) => {
29
+ const currentLevel = current[1].length;
30
+ const currentTitle = current[2].trim();
31
+ stack.splice(currentLevel - 1);
32
+ stack[currentLevel - 1] = currentTitle;
33
+ return stack.filter(Boolean);
34
+ }, [])
35
+ .slice(0, level);
36
+ return { start, end, headings: headings.length > 0 ? headings : [title] };
37
+ });
38
+ for (const [sectionIndex, section] of sections.entries()) {
39
+ const sectionText = text.slice(section.start, section.end);
40
+ const segments = await segment(sectionText, {
41
+ maxChars,
42
+ minChars,
43
+ boundaries,
44
+ type: resource.type,
45
+ slicerId: "markdown",
46
+ signal: context.options.signal,
47
+ });
48
+ segments.forEach((seg, index) => {
49
+ const rawSlice = {
50
+ id: createSliceId(part, slices.length),
51
+ resourceId: resource.id,
52
+ partId: part.id,
53
+ location: `${part.location}#section/${sectionIndex}/slice/${index}`,
54
+ text: seg.text,
55
+ start: section.start + seg.start,
56
+ end: section.start + seg.end,
57
+ context: toHeadingContext(section.headings),
58
+ links: dedupeLinks([
59
+ ...extractLinksFromMarkdown(seg.text, `${part.location}#section/${sectionIndex}/slice/${index}`),
60
+ ...extractLinksFromText(seg.text, `${part.location}#section/${sectionIndex}/slice/${index}`)
61
+ ])
62
+ };
63
+ slices.push(finalizeSlice(resource, part, rawSlice, context.options));
64
+ });
65
+ }
66
+ }
67
+ return slices;
68
+ }
69
+ };
70
+ //# sourceMappingURL=markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/slicers/markdown.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,wBAAwB,EACxB,oBAAoB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ChB,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ResourceSlicer } from "../types";
2
+ export declare const textSlicer: ResourceSlicer;
3
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/slicers/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,UAAU,CAAC;AAW9D,eAAO,MAAM,UAAU,EAAE,cA0CxB,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { DEFAULT_MAX_CHARS, DEFAULT_MIN_CHARS, createSliceId, dedupeLinks, extractLinksFromText, finalizeSlice, } from "../utils";
2
+ import { defaultTextSegmenter } from "../segmenters";
3
+ export const textSlicer = {
4
+ id: "text",
5
+ supportedTypes: ["*"],
6
+ async slice(resource, context) {
7
+ const slices = [];
8
+ const maxChars = context.options.maxChars ?? DEFAULT_MAX_CHARS;
9
+ const minChars = context.options.minChars ?? DEFAULT_MIN_CHARS;
10
+ const segment = context.options.segmenter ?? defaultTextSegmenter;
11
+ for (const part of resource.parts) {
12
+ if (!part.text) {
13
+ continue;
14
+ }
15
+ const segments = await segment(part.text, {
16
+ maxChars,
17
+ minChars,
18
+ boundaries: context.options.boundaries,
19
+ type: resource.type,
20
+ slicerId: "text",
21
+ signal: context.options.signal,
22
+ });
23
+ segments.forEach((segment, index) => {
24
+ const rawSlice = {
25
+ id: createSliceId(part, slices.length),
26
+ resourceId: resource.id,
27
+ partId: part.id,
28
+ location: `${part.location}#slice/${index}`,
29
+ text: segment.text,
30
+ start: segment.start,
31
+ end: segment.end,
32
+ links: dedupeLinks([
33
+ ...(part.links ?? []).filter((link) => part.text?.includes(link.value)),
34
+ ...extractLinksFromText(segment.text, `${part.location}#slice/${index}`)
35
+ ])
36
+ };
37
+ slices.push(finalizeSlice(resource, part, rawSlice, context.options));
38
+ });
39
+ }
40
+ return slices;
41
+ }
42
+ };
43
+ //# sourceMappingURL=text.js.map
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,UAAU,EAAE,QAAQ,CAAC,EAAE;oBACvB,MAAM,EAAE,IAAI,CAAC,EAAE;oBACf,QAAQ,EAAE,GAAG,IAAI,CAAC,QAAQ,UAAU,KAAK,EAAE;oBAC3C,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,KAAK,EAAE,OAAO,CAAC,KAAK;oBACpB,GAAG,EAAE,OAAO,CAAC,GAAG;oBAChB,KAAK,EAAE,WAAW,CAAC;wBACjB,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBACvE,GAAG,oBAAoB,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,QAAQ,UAAU,KAAK,EAAE,CAAC;qBACzE,CAAC;iBACH,CAAC;gBACF,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;YACxE,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAC"}
@@ -0,0 +1,306 @@
1
+ import type { Readable } from "node:stream";
2
+ export type ResourceType = string;
3
+ export type ResourceInput = string | Uint8Array | ArrayBuffer | URL | Readable | ReadableStream<Uint8Array> | AsyncIterable<string | Uint8Array> | Iterable<string | Uint8Array> | (() => AsyncIterable<Uint8Array>);
4
+ export type ResourceLocation = string;
5
+ export type ResourcePartKind = "text" | "image";
6
+ /** A function that renders a URL to HTML (e.g. using puppeteer). */
7
+ export type RenderUrlFn = (url: string, signal?: AbortSignal) => Promise<string>;
8
+ /**
9
+ * Renders all pages of a PDF to image files in a directory. Receives the PDF file path, an output
10
+ * directory, and the target DPI; should write one image per page and return the rendered page files.
11
+ * This avoids loading the entire PDF into memory.
12
+ */
13
+ export type RenderPdfPagesFn = (pdfFilePath: string, outputDir: string, dpi: number, signal?: AbortSignal) => Promise<RenderedPage[]>;
14
+ /** Converts a document file to PDF for richer parsing. Returns the path to the converted PDF file. */
15
+ export type ConvertToPdfFn = (sourceFilePath: string, signal?: AbortSignal) => Promise<string>;
16
+ export interface ResourceLink {
17
+ id: string;
18
+ value: string;
19
+ location: string;
20
+ kind: "resource" | "external";
21
+ title?: string;
22
+ targetType?: ResourceType;
23
+ metadata?: Record<string, unknown>;
24
+ }
25
+ export interface ResourceSource {
26
+ location: ResourceLocation;
27
+ input: ResourceInput;
28
+ type?: ResourceType;
29
+ name?: string;
30
+ mimeType?: string;
31
+ /** Estimated last-modified time of the underlying source, in epoch milliseconds, if known. */
32
+ modifiedAt?: number;
33
+ /** Size of the underlying source in bytes, if known. */
34
+ size?: number;
35
+ metadata?: Record<string, unknown>;
36
+ }
37
+ /** Lightweight metadata about a resource location, obtainable without fully loading/parsing it. */
38
+ export interface ResourceStat {
39
+ location: ResourceLocation;
40
+ /** Estimated last-modified time, in epoch milliseconds, if known. */
41
+ modifiedAt?: number;
42
+ size?: number;
43
+ mimeType?: string;
44
+ type?: ResourceType;
45
+ }
46
+ export interface ResourcePart {
47
+ id: string;
48
+ location: string;
49
+ kind: ResourcePartKind;
50
+ text?: string;
51
+ mimeType?: string;
52
+ pageNumber?: number;
53
+ data?: Uint8Array;
54
+ metadata?: Record<string, unknown>;
55
+ links?: ResourceLink[];
56
+ }
57
+ export interface ParsedResource {
58
+ id: string;
59
+ location: ResourceLocation;
60
+ type: ResourceType;
61
+ name: string;
62
+ mimeType?: string;
63
+ /**
64
+ * Estimated last-modified time of the source this resource was built from, in epoch milliseconds.
65
+ * Lets a target system decide whether a previously-built resource is stale and needs rebuilding.
66
+ */
67
+ modifiedAt?: number;
68
+ /** Size of the underlying source in bytes, if known. */
69
+ size?: number;
70
+ metadata?: Record<string, unknown>;
71
+ defaultSlicer: string;
72
+ parts: ResourcePart[];
73
+ links: ResourceLink[];
74
+ /** Child resources (e.g. files inside a zip, rendered pages of a PDF). */
75
+ children?: ParsedResource[];
76
+ /** Location of the parent resource, if this resource is a child. */
77
+ parentLocation?: ResourceLocation;
78
+ }
79
+ export interface SliceContext {
80
+ headings?: string[];
81
+ declaration?: string;
82
+ summary?: string;
83
+ prefixes?: string[];
84
+ }
85
+ /** A contiguous span of text produced by a {@link TextSegmenter}, with offsets into the input text. */
86
+ export interface TextSegment {
87
+ start: number;
88
+ end: number;
89
+ text: string;
90
+ }
91
+ /** Inputs a slicer hands to a segmenter so it can size and (optionally) language-tune its splitting. */
92
+ export interface SegmentContext {
93
+ maxChars: number;
94
+ minChars: number;
95
+ /** Preferred break strings (longest-context first), when the segmenter honors them. */
96
+ boundaries?: string[];
97
+ /** The resource type being sliced (lets language-aware segmenters pick a grammar). */
98
+ type?: ResourceType;
99
+ /** The id of the slicer requesting segmentation ("text" | "markdown" | "code" | …). */
100
+ slicerId?: string;
101
+ signal?: AbortSignal;
102
+ }
103
+ /**
104
+ * Pluggable text-segmentation strategy. The default segmenter is lossless and offset-exact (the
105
+ * concatenation of segments reproduces the input). Alternative segmenters (e.g. the LangChain adapter)
106
+ * may overlap or trim, in which case offsets are best-effort and the round-trip guarantee is relaxed.
107
+ */
108
+ export type TextSegmenter = (text: string, context: SegmentContext) => TextSegment[] | Promise<TextSegment[]>;
109
+ export interface ResourceSlice {
110
+ id: string;
111
+ resourceId: string;
112
+ partId: string;
113
+ location: string;
114
+ text: string;
115
+ embedText: string;
116
+ start: number;
117
+ end: number;
118
+ context?: SliceContext;
119
+ links: ResourceLink[];
120
+ metadata?: Record<string, unknown>;
121
+ }
122
+ export interface EmbedTextContext {
123
+ resource: ParsedResource;
124
+ part: ResourcePart;
125
+ slice: ResourceSlice;
126
+ contextLines: string[];
127
+ }
128
+ export interface CodeParserOptions {
129
+ /** Pattern to detect top-level declarations in code. Defaults to export/function/class/interface/type/enum/const/let/var */
130
+ declarationPattern?: RegExp;
131
+ /** Pattern to detect import/require lines. */
132
+ importPattern?: RegExp;
133
+ /** Maximum number of detected import lines to attach as slice context prefixes. Defaults to 5. */
134
+ maxImportPrefixes?: number;
135
+ }
136
+ export interface PdfParseOptions {
137
+ /** When true, render PDF pages to images and include as image parts/children. */
138
+ renderPages?: boolean;
139
+ /** DPI for rendered page images. Defaults to 150. */
140
+ renderDpi?: number;
141
+ /** When true, use transcription on rendered page images to produce markdown text parts. */
142
+ transcribePages?: boolean;
143
+ /** When true, extract embedded images from the PDF as image parts. */
144
+ extractImages?: boolean;
145
+ }
146
+ export interface RenderedPage {
147
+ /** Path to the rendered image file on disk. */
148
+ filePath: string;
149
+ /** 1-based page number. */
150
+ pageNumber: number;
151
+ /** MIME type of the image (e.g. "image/png"). */
152
+ mimeType: string;
153
+ }
154
+ /** Structured table extracted from tabular data. */
155
+ export interface ExtractedTable {
156
+ /** Optional name/title for the table. */
157
+ name?: string;
158
+ /** Column headers. */
159
+ headers: string[];
160
+ /** Rows of data (each row is an array of cell values). */
161
+ rows: string[][];
162
+ /** Sheet name if from a multi-sheet source. */
163
+ sheetName?: string;
164
+ /** 0-based sheet index if from a multi-sheet source. */
165
+ sheetIndex?: number;
166
+ }
167
+ export interface ParseOptions {
168
+ signal?: AbortSignal;
169
+ describeImage?: (image: Uint8Array, part: ResourcePart, source: ResourceSource) => Promise<string | undefined>;
170
+ transcribeImage?: (image: Uint8Array, part: ResourcePart, source: ResourceSource) => Promise<string | undefined>;
171
+ /** Renders a URL to final HTML (e.g. after JS executes). Used for html resources when provided. */
172
+ renderUrl?: RenderUrlFn;
173
+ /** Options for code parsing/slicing behavior. */
174
+ code?: CodeParserOptions;
175
+ /** Options for PDF parsing behavior. */
176
+ pdf?: PdfParseOptions;
177
+ /**
178
+ * Resource types whose textual content should have href/src markup links extracted (in addition to
179
+ * bare URLs). Defaults to {@link DEFAULT_MARKUP_TYPES} (xml, svg).
180
+ */
181
+ markupTypes?: ResourceType[];
182
+ /**
183
+ * Renders all pages of a PDF to image files in a directory.
184
+ * See {@link RenderPdfPagesFn}. Use {@link createPopplerRenderer} for a poppler-based implementation.
185
+ */
186
+ renderPdfPages?: RenderPdfPagesFn;
187
+ /**
188
+ * Converts a document file to PDF for richer parsing (render pages, transcribe, etc.).
189
+ * See {@link ConvertToPdfFn}. Supported for types like docx, excel, etc. that can be "pdfified".
190
+ */
191
+ convertToPdf?: ConvertToPdfFn;
192
+ }
193
+ export interface SliceOptions {
194
+ signal?: AbortSignal;
195
+ slicer?: string;
196
+ maxChars?: number;
197
+ minChars?: number;
198
+ /** Ordered boundary strings a slicer prefers to break on, longest-context first. Slicer-specific defaults apply. */
199
+ boundaries?: string[];
200
+ /**
201
+ * Strategy used to split text into segments. Defaults to the built-in lossless, offset-exact
202
+ * boundary segmenter. Provide e.g. a LangChain-backed segmenter for overlap / token sizing /
203
+ * language-aware splitting. Can be set per type via the registry's `configureType`.
204
+ */
205
+ segmenter?: TextSegmenter;
206
+ includeResourceLocation?: boolean;
207
+ includeResourceType?: boolean;
208
+ includePartLocation?: boolean;
209
+ includePartKind?: boolean;
210
+ includeContext?: boolean;
211
+ includeLinks?: boolean;
212
+ embedSeparator?: string;
213
+ buildEmbedText?: (context: EmbedTextContext) => string;
214
+ /** Options for code slicing behavior. */
215
+ code?: CodeParserOptions;
216
+ }
217
+ export interface ResolveOptions {
218
+ signal?: AbortSignal;
219
+ baseLocation?: string;
220
+ headers?: Record<string, string>;
221
+ metadata?: Record<string, unknown>;
222
+ }
223
+ export interface LoadResourceOptions extends ParseOptions, SliceOptions, ResolveOptions {
224
+ type?: ResourceType;
225
+ name?: string;
226
+ mimeType?: string;
227
+ }
228
+ export interface LoadedResource {
229
+ source: ResourceSource;
230
+ resource: ParsedResource;
231
+ slices: ResourceSlice[];
232
+ }
233
+ export interface ResourceSupport {
234
+ type: ResourceType;
235
+ parserId?: string;
236
+ slicerId?: string;
237
+ parser: boolean;
238
+ slicer: boolean;
239
+ supported: boolean;
240
+ }
241
+ export interface ResourceRegistryLike {
242
+ inferType(location: string, mimeType?: string): ResourceType | undefined;
243
+ getDefaultSlicer(type: ResourceType): string | undefined;
244
+ /** Returns the per-type parse config registered on the registry for this type, if any. */
245
+ getTypeConfig(type: ResourceType): Partial<ParseOptions> | undefined;
246
+ resolveLink(link: string, options?: ResolveOptions): Promise<ResourceSource>;
247
+ /** Runs the parser stack for an already-resolved source, falling back through registered parsers. */
248
+ parseSource(source: ResourceSource, options?: ParseOptions): Promise<ParsedResource>;
249
+ }
250
+ export interface SupportContext {
251
+ registry: ResourceRegistryLike;
252
+ signal?: AbortSignal;
253
+ }
254
+ export interface ParserContext {
255
+ registry: ResourceRegistryLike;
256
+ options: ParseOptions;
257
+ }
258
+ export interface SlicerContext {
259
+ registry: ResourceRegistryLike;
260
+ options: SliceOptions;
261
+ }
262
+ export interface ResolverContext {
263
+ registry: ResourceRegistryLike;
264
+ options: ResolveOptions;
265
+ }
266
+ export interface ResourceParser {
267
+ id: string;
268
+ supportedTypes: ResourceType[];
269
+ defaultSlicer: string | Partial<Record<ResourceType, string>>;
270
+ /**
271
+ * Relative ordering within a type's parser stack. Higher priority parsers are attempted first
272
+ * before falling back to lower priority ones; ties are broken by most-recent registration so a
273
+ * later parser overrides an earlier one of equal priority. Defaults to 0.
274
+ */
275
+ priority?: number;
276
+ isSupported?: (type: ResourceType, context: SupportContext) => boolean | Promise<boolean>;
277
+ /**
278
+ * Parses the source into a resource. Returning `undefined` declines this source so the registry
279
+ * falls back to the next parser in the stack (e.g. a render-based PDF parser that is not configured
280
+ * yields to the plain text-extraction parser). Throwing also triggers fallback to the next parser.
281
+ */
282
+ parse: (source: ResourceSource, context: ParserContext) => Promise<ParsedResource | undefined>;
283
+ }
284
+ /** Options controlling how a parser is placed within a type's parser stack. */
285
+ export interface RegisterParserOptions {
286
+ /** Overrides the parser's own `priority`. Higher is attempted first. Defaults to the parser's priority or 0. */
287
+ priority?: number;
288
+ }
289
+ export interface ResourceSlicer {
290
+ id: string;
291
+ supportedTypes: ResourceType[];
292
+ isSupported?: (type: ResourceType, context: SupportContext) => boolean | Promise<boolean>;
293
+ slice: (resource: ParsedResource, context: SlicerContext) => Promise<ResourceSlice[]>;
294
+ }
295
+ export interface ResourceResolver {
296
+ id: string;
297
+ canResolve: (link: string, context: ResolverContext) => boolean | Promise<boolean>;
298
+ resolve: (link: string, context: ResolverContext) => Promise<ResourceSource | undefined>;
299
+ /**
300
+ * Cheaply determines the canonical location (and, if available, modified time) of a link without
301
+ * loading its contents. Used for de-duplication and incremental-build decisions when walking a
302
+ * resource graph. Optional; resolvers that cannot probe cheaply may omit it.
303
+ */
304
+ stat?: (link: string, context: ResolverContext) => Promise<ResourceStat | undefined>;
305
+ }
306
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAClC,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,GAAG,GAAG,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,MAAM,GAAG,UAAU,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;AACrN,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AACtC,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAAC;AAEhD,oEAAoE;AACpE,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAEjF;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,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AAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;CACtF"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}