@gixcopilot/knowledge 0.1.0

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 (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/dist/acl.d.ts +16 -0
  4. package/dist/acl.d.ts.map +1 -0
  5. package/dist/acl.js +10 -0
  6. package/dist/acl.js.map +1 -0
  7. package/dist/document.d.ts +59 -0
  8. package/dist/document.d.ts.map +1 -0
  9. package/dist/document.js +29 -0
  10. package/dist/document.js.map +1 -0
  11. package/dist/index.d.ts +32 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +44 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/loader.d.ts +14 -0
  16. package/dist/loader.d.ts.map +1 -0
  17. package/dist/loader.js +6 -0
  18. package/dist/loader.js.map +1 -0
  19. package/dist/loaders/api.d.ts +10 -0
  20. package/dist/loaders/api.d.ts.map +1 -0
  21. package/dist/loaders/api.js +42 -0
  22. package/dist/loaders/api.js.map +1 -0
  23. package/dist/loaders/database.d.ts +12 -0
  24. package/dist/loaders/database.d.ts.map +1 -0
  25. package/dist/loaders/database.js +46 -0
  26. package/dist/loaders/database.js.map +1 -0
  27. package/dist/loaders/docx.d.ts +9 -0
  28. package/dist/loaders/docx.d.ts.map +1 -0
  29. package/dist/loaders/docx.js +58 -0
  30. package/dist/loaders/docx.js.map +1 -0
  31. package/dist/loaders/file.d.ts +5 -0
  32. package/dist/loaders/file.d.ts.map +1 -0
  33. package/dist/loaders/file.js +56 -0
  34. package/dist/loaders/file.js.map +1 -0
  35. package/dist/loaders/html-structure.d.ts +20 -0
  36. package/dist/loaders/html-structure.d.ts.map +1 -0
  37. package/dist/loaders/html-structure.js +79 -0
  38. package/dist/loaders/html-structure.js.map +1 -0
  39. package/dist/loaders/html.d.ts +5 -0
  40. package/dist/loaders/html.d.ts.map +1 -0
  41. package/dist/loaders/html.js +52 -0
  42. package/dist/loaders/html.js.map +1 -0
  43. package/dist/loaders/markdown.d.ts +7 -0
  44. package/dist/loaders/markdown.d.ts.map +1 -0
  45. package/dist/loaders/markdown.js +28 -0
  46. package/dist/loaders/markdown.js.map +1 -0
  47. package/dist/loaders/mcp-resource.d.ts +11 -0
  48. package/dist/loaders/mcp-resource.d.ts.map +1 -0
  49. package/dist/loaders/mcp-resource.js +60 -0
  50. package/dist/loaders/mcp-resource.js.map +1 -0
  51. package/dist/loaders/object-storage.d.ts +5 -0
  52. package/dist/loaders/object-storage.d.ts.map +1 -0
  53. package/dist/loaders/object-storage.js +50 -0
  54. package/dist/loaders/object-storage.js.map +1 -0
  55. package/dist/loaders/pdf.d.ts +5 -0
  56. package/dist/loaders/pdf.d.ts.map +1 -0
  57. package/dist/loaders/pdf.js +102 -0
  58. package/dist/loaders/pdf.js.map +1 -0
  59. package/dist/loaders/text.d.ts +5 -0
  60. package/dist/loaders/text.d.ts.map +1 -0
  61. package/dist/loaders/text.js +21 -0
  62. package/dist/loaders/text.js.map +1 -0
  63. package/dist/loaders/web.d.ts +9 -0
  64. package/dist/loaders/web.d.ts.map +1 -0
  65. package/dist/loaders/web.js +102 -0
  66. package/dist/loaders/web.js.map +1 -0
  67. package/dist/net/ssrf-guard.d.ts +13 -0
  68. package/dist/net/ssrf-guard.d.ts.map +1 -0
  69. package/dist/net/ssrf-guard.js +88 -0
  70. package/dist/net/ssrf-guard.js.map +1 -0
  71. package/dist/normalize.d.ts +7 -0
  72. package/dist/normalize.d.ts.map +1 -0
  73. package/dist/normalize.js +14 -0
  74. package/dist/normalize.js.map +1 -0
  75. package/dist/registry.d.ts +10 -0
  76. package/dist/registry.d.ts.map +1 -0
  77. package/dist/registry.js +27 -0
  78. package/dist/registry.js.map +1 -0
  79. package/dist/source.d.ts +136 -0
  80. package/dist/source.d.ts.map +1 -0
  81. package/dist/source.js +55 -0
  82. package/dist/source.js.map +1 -0
  83. package/package.json +57 -0
@@ -0,0 +1,20 @@
1
+ import { HTMLElement } from 'node-html-parser';
2
+ /**
3
+ * Deterministic table-to-text representation (Section 33) - one line per row, cells joined by
4
+ * " | ", header row (if any `<th>` is present) separated by a divider line. Not full table
5
+ * layout understanding, just enough to keep a table's rows readable after chunking rather than
6
+ * collapsing into an unreadable run-on fragment.
7
+ */
8
+ export declare function serializeTable(table: HTMLElement): string;
9
+ export interface HtmlStructureResult {
10
+ readonly title?: string;
11
+ /** Markdown-flavored plain text: headings become `#`.."######" lines, tables use serializeTable. */
12
+ readonly text: string;
13
+ }
14
+ /**
15
+ * Normalizes arbitrary HTML into readable structured text (Section 20/19), stripping script/
16
+ * style/navigation noise while preserving headings/paragraphs/tables where practical - no claim
17
+ * of perfect layout understanding (Section 18's caveat applies here too).
18
+ */
19
+ export declare function extractHtmlStructure(html: string): HtmlStructureResult;
20
+ //# sourceMappingURL=html-structure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html-structure.d.ts","sourceRoot":"","sources":["../../src/loaders/html-structure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,kBAAkB,CAAC;AASjE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAYzD;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,oGAAoG;IACpG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAiDtE"}
@@ -0,0 +1,79 @@
1
+ import { HTMLElement, parse } from 'node-html-parser';
2
+ const NOISE_SELECTORS = 'script,style,nav,noscript,iframe,svg,header,footer';
3
+ const HEADING_TAGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
4
+ function textOf(node) {
5
+ return node.textContent.replace(/\s+/g, ' ').trim();
6
+ }
7
+ /**
8
+ * Deterministic table-to-text representation (Section 33) - one line per row, cells joined by
9
+ * " | ", header row (if any `<th>` is present) separated by a divider line. Not full table
10
+ * layout understanding, just enough to keep a table's rows readable after chunking rather than
11
+ * collapsing into an unreadable run-on fragment.
12
+ */
13
+ export function serializeTable(table) {
14
+ const rows = table.querySelectorAll('tr');
15
+ const lines = [];
16
+ for (const row of rows) {
17
+ const cells = row.querySelectorAll('th,td').map((cell) => textOf(cell));
18
+ if (cells.length === 0)
19
+ continue;
20
+ lines.push(cells.join(' | '));
21
+ if (row.querySelector('th')) {
22
+ lines.push(cells.map(() => '---').join(' | '));
23
+ }
24
+ }
25
+ return lines.join('\n');
26
+ }
27
+ /**
28
+ * Normalizes arbitrary HTML into readable structured text (Section 20/19), stripping script/
29
+ * style/navigation noise while preserving headings/paragraphs/tables where practical - no claim
30
+ * of perfect layout understanding (Section 18's caveat applies here too).
31
+ */
32
+ export function extractHtmlStructure(html) {
33
+ const root = parse(html, { blockTextElements: { script: false, style: false } });
34
+ root.querySelectorAll(NOISE_SELECTORS).forEach((node) => node.remove());
35
+ const title = root.querySelector('title')?.text.trim() || undefined;
36
+ const body = root.querySelector('body') ?? root;
37
+ const lines = [];
38
+ const visited = new Set();
39
+ const walk = (node) => {
40
+ if (visited.has(node))
41
+ return;
42
+ const tag = node.tagName?.toLowerCase();
43
+ if (tag === 'table') {
44
+ visited.add(node);
45
+ const serialized = serializeTable(node);
46
+ if (serialized)
47
+ lines.push(serialized);
48
+ return;
49
+ }
50
+ if (tag && HEADING_TAGS.has(tag)) {
51
+ visited.add(node);
52
+ const level = Number(tag.slice(1));
53
+ const text = textOf(node);
54
+ if (text)
55
+ lines.push(`${'#'.repeat(level)} ${text}`);
56
+ return;
57
+ }
58
+ if (tag === 'p' || tag === 'li') {
59
+ visited.add(node);
60
+ const text = textOf(node);
61
+ if (text)
62
+ lines.push(text);
63
+ return;
64
+ }
65
+ for (const child of node.childNodes) {
66
+ if (child instanceof HTMLElement) {
67
+ walk(child);
68
+ }
69
+ }
70
+ };
71
+ walk(body);
72
+ const text = lines.length > 0 ? lines.join('\n\n') : textOf(body);
73
+ // Falls back to the first extracted heading when there is no <title> tag - real-world HTML
74
+ // fragments (mammoth's DOCX->HTML output has no <head>) still get a usable title this way.
75
+ const firstHeadingMatch = /^#{1,6}\s+(.+)$/m.exec(text);
76
+ const resolvedTitle = title ?? firstHeadingMatch?.[1]?.trim();
77
+ return resolvedTitle !== undefined ? { title: resolvedTitle, text } : { text };
78
+ }
79
+ //# sourceMappingURL=html-structure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html-structure.js","sourceRoot":"","sources":["../../src/loaders/html-structure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAa,MAAM,kBAAkB,CAAC;AAEjE,MAAM,eAAe,GAAG,oDAAoD,CAAC;AAC7E,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEnE,SAAS,MAAM,CAAC,IAAU;IACxB,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAkB;IAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACxE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QACjC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAA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Aa,GAAG,KAAK,IAAI,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;IAC9D,OAAO,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;AACjF,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type DocumentLoader } from '../loader.js';
2
+ import type { HtmlSourceConfig } from '../source.js';
3
+ /** HTML loader (Section 20) - local/pre-fetched HTML only; see web.ts for remote fetching. */
4
+ export declare const htmlLoader: DocumentLoader<HtmlSourceConfig>;
5
+ //# sourceMappingURL=html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/loaders/html.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,KAAK,cAAc,EAAsB,MAAM,cAAc,CAAC;AAEvF,OAAO,KAAK,EAAE,gBAAgB,EAAmB,MAAM,cAAc,CAAC;AAStE,8FAA8F;AAC9F,eAAO,MAAM,UAAU,EAAE,cAAc,CAAC,gBAAgB,CAuCvD,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { CopilotError } from '@gixcopilot/protocol';
3
+ import { createKnowledgeDocument } from '../document.js';
4
+ import { throwIfAborted } from '../loader.js';
5
+ import { normalizeText } from '../normalize.js';
6
+ import { extractHtmlStructure } from './html-structure.js';
7
+ async function readHtml(config) {
8
+ if (config.html !== undefined)
9
+ return config.html;
10
+ if (config.path)
11
+ return readFile(config.path, 'utf8');
12
+ throw CopilotError.sourceLoadFailed('An HTML source requires either "html" or "path".');
13
+ }
14
+ /** HTML loader (Section 20) - local/pre-fetched HTML only; see web.ts for remote fetching. */
15
+ export const htmlLoader = {
16
+ async *load(source, context) {
17
+ throwIfAborted(context?.signal);
18
+ const html = await readHtml(source.config).catch((error) => {
19
+ if (CopilotError.isCopilotError(error))
20
+ throw error;
21
+ throw CopilotError.sourceLoadFailed(`Failed to read HTML source: ${String(error)}`, {
22
+ sourceId: source.id,
23
+ });
24
+ });
25
+ let structure;
26
+ try {
27
+ structure = extractHtmlStructure(html);
28
+ }
29
+ catch (error) {
30
+ throw CopilotError.parseFailed(`Failed to parse HTML source: ${String(error)}`, {
31
+ sourceId: source.id,
32
+ });
33
+ }
34
+ throwIfAborted(context?.signal);
35
+ const content = normalizeText(structure.text);
36
+ if (content.length === 0)
37
+ return;
38
+ yield createKnowledgeDocument({
39
+ sourceId: source.id,
40
+ content,
41
+ metadata: {
42
+ ...(source.name !== undefined || structure.title !== undefined
43
+ ? { title: source.name ?? structure.title }
44
+ : {}),
45
+ mimeType: 'text/html',
46
+ tenantId: source.tenantId,
47
+ acl: source.acl,
48
+ },
49
+ });
50
+ },
51
+ };
52
+ //# sourceMappingURL=html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/loaders/html.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAA2C,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,KAAK,UAAU,QAAQ,CAAC,MAAwB;IAC9C,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IAClD,IAAI,MAAM,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtD,MAAM,YAAY,CAAC,gBAAgB,CAAC,kDAAkD,CAAC,CAAC;AAC1F,CAAC;AAED,8FAA8F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,CAAC;gBACP,QAAQ,EAAE,WAAW;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,GAAG,EAAE,MAAM,CAAC,GAAG;aAChB;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type DocumentLoader } from '../loader.js';
2
+ import type { TextSourceConfig } from '../source.js';
3
+ /** First ATX heading (`# Title`) in a markdown document, used as a title fallback (Section 17). */
4
+ export declare function extractMarkdownTitle(content: string): string | undefined;
5
+ /** Markdown loader (Section 17) - preserves the source text as-is; heading structure is picked up during chunking. */
6
+ export declare const markdownLoader: DocumentLoader<TextSourceConfig>;
7
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/loaders/markdown.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,cAAc,EAAsB,MAAM,cAAc,CAAC;AAEvF,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEtE,mGAAmG;AACnG,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGxE;AAED,sHAAsH;AACtH,eAAO,MAAM,cAAc,EAAE,cAAc,CAAC,gBAAgB,CAoB3D,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { createKnowledgeDocument } from '../document.js';
2
+ import { throwIfAborted } from '../loader.js';
3
+ import { normalizeText } from '../normalize.js';
4
+ /** First ATX heading (`# Title`) in a markdown document, used as a title fallback (Section 17). */
5
+ export function extractMarkdownTitle(content) {
6
+ const match = /^#\s+(.+)$/m.exec(content);
7
+ return match?.[1]?.trim();
8
+ }
9
+ /** Markdown loader (Section 17) - preserves the source text as-is; heading structure is picked up during chunking. */
10
+ export const markdownLoader = {
11
+ async *load(source, context) {
12
+ throwIfAborted(context?.signal);
13
+ await Promise.resolve(); // keep every loader's first yield microtask-deferred, not just the I/O-bound ones
14
+ const content = normalizeText(source.config.content);
15
+ const title = source.name ?? extractMarkdownTitle(content);
16
+ yield createKnowledgeDocument({
17
+ sourceId: source.id,
18
+ content,
19
+ metadata: {
20
+ ...(title !== undefined ? { title } : {}),
21
+ mimeType: 'text/markdown',
22
+ tenantId: source.tenantId,
23
+ acl: source.acl,
24
+ },
25
+ });
26
+ },
27
+ };
28
+ //# sourceMappingURL=markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/loaders/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAA2C,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,mGAAmG;AACnG,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC;AAED,sHAAsH;AACtH,MAAM,CAAC,MAAM,cAAc,GAAqC;IAC9D,KAAK,CAAC,CAAC,IAAI,CACT,MAAyC,EACzC,OAAuB;QAEvB,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAChC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,kFAAkF;QAC3G,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACrD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC3D,MAAM,uBAAuB,CAAC;YAC5B,QAAQ,EAAE,MAAM,CAAC,EAAE;YACnB,OAAO;YACP,QAAQ,EAAE;gBACR,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzC,QAAQ,EAAE,eAAe;gBACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,GAAG,EAAE,MAAM,CAAC,GAAG;aAChB;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type DocumentLoader } from '../loader.js';
2
+ import type { McpResourceSourceConfig } from '../source.js';
3
+ /**
4
+ * MCP resource loader (Section 24) - reuses Phase 8's MCP client/integration
5
+ * (`listResources`/`readResource`) rather than a second MCP client. Per @gixcopilot/mcp's own
6
+ * documented boundary, a resource's content is untrusted data, exactly like a tool result -
7
+ * nothing here elevates it to a trusted instruction. Text resources only: binary/blob MCP
8
+ * resources are not supported this phase, matching @gixcopilot/mcp's own current limitation.
9
+ */
10
+ export declare const mcpResourceLoader: DocumentLoader<McpResourceSourceConfig>;
11
+ //# sourceMappingURL=mcp-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-resource.d.ts","sourceRoot":"","sources":["../../src/loaders/mcp-resource.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,cAAc,EAAsB,MAAM,cAAc,CAAC;AAEvF,OAAO,KAAK,EAAmB,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE7E;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,cAAc,CAAC,uBAAuB,CAgDrE,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { CopilotError } from '@gixcopilot/protocol';
2
+ import { createKnowledgeDocument } from '../document.js';
3
+ import { throwIfAborted } from '../loader.js';
4
+ import { normalizeText } from '../normalize.js';
5
+ /**
6
+ * MCP resource loader (Section 24) - reuses Phase 8's MCP client/integration
7
+ * (`listResources`/`readResource`) rather than a second MCP client. Per @gixcopilot/mcp's own
8
+ * documented boundary, a resource's content is untrusted data, exactly like a tool result -
9
+ * nothing here elevates it to a trusted instruction. Text resources only: binary/blob MCP
10
+ * resources are not supported this phase, matching @gixcopilot/mcp's own current limitation.
11
+ */
12
+ export const mcpResourceLoader = {
13
+ async *load(source, context) {
14
+ throwIfAborted(context?.signal);
15
+ const { client } = source.config;
16
+ let uris = source.config.uris;
17
+ if (!uris) {
18
+ try {
19
+ const resources = await client.listResources();
20
+ uris = resources.map((resource) => resource.uri);
21
+ }
22
+ catch (error) {
23
+ throw CopilotError.sourceLoadFailed(`Failed to list MCP resources: ${String(error)}`, {
24
+ sourceId: source.id,
25
+ });
26
+ }
27
+ }
28
+ for (const uri of uris) {
29
+ throwIfAborted(context?.signal);
30
+ let resourceContent;
31
+ try {
32
+ resourceContent = await client.readResource(uri);
33
+ }
34
+ catch (error) {
35
+ throw CopilotError.sourceLoadFailed(`Failed to read MCP resource "${uri}": ${String(error)}`, {
36
+ sourceId: source.id,
37
+ uri,
38
+ });
39
+ }
40
+ if (resourceContent.text === undefined) {
41
+ continue; // binary resource content is not supported this phase
42
+ }
43
+ const content = normalizeText(resourceContent.text);
44
+ if (content.length === 0)
45
+ continue;
46
+ yield createKnowledgeDocument({
47
+ sourceId: source.id,
48
+ discriminator: uri,
49
+ content,
50
+ metadata: {
51
+ uri,
52
+ mimeType: resourceContent.mimeType,
53
+ tenantId: source.tenantId,
54
+ acl: source.acl,
55
+ },
56
+ });
57
+ }
58
+ },
59
+ };
60
+ //# sourceMappingURL=mcp-resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-resource.js","sourceRoot":"","sources":["../../src/loaders/mcp-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAA2C,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA4C;IACxE,KAAK,CAAC,CAAC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,MAAM,KAAK,CAAC;gBAAE,SAAS;YACnC,MAAM,uBAAuB,CAAC;gBAC5B,QAAQ,EAAE,MAAM,CAAC,EAAE;gBACnB,aAAa,EAAE,GAAG;gBAClB,OAAO;gBACP,QAAQ,EAAE;oBACR,GAAG;oBACH,QAAQ,EAAE,eAAe,CAAC,QAAQ;oBAClC,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,GAAG,EAAE,MAAM,CAAC,GAAG;iBAChB;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type DocumentLoader } from '../loader.js';
2
+ import type { ObjectStorageSourceConfig } from '../source.js';
3
+ /** Object-storage loader (Section 23) - works against any ObjectStorageClient, no cloud SDK dependency. */
4
+ export declare const objectStorageLoader: DocumentLoader<ObjectStorageSourceConfig>;
5
+ //# sourceMappingURL=object-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-storage.d.ts","sourceRoot":"","sources":["../../src/loaders/object-storage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,cAAc,EAAsB,MAAM,cAAc,CAAC;AAEvF,OAAO,KAAK,EAAmB,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAE/E,2GAA2G;AAC3G,eAAO,MAAM,mBAAmB,EAAE,cAAc,CAAC,yBAAyB,CA4CzE,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { CopilotError } from '@gixcopilot/protocol';
2
+ import { createKnowledgeDocument } from '../document.js';
3
+ import { throwIfAborted } from '../loader.js';
4
+ import { normalizeText } from '../normalize.js';
5
+ /** Object-storage loader (Section 23) - works against any ObjectStorageClient, no cloud SDK dependency. */
6
+ export const objectStorageLoader = {
7
+ async *load(source, context) {
8
+ throwIfAborted(context?.signal);
9
+ const { client } = source.config;
10
+ let keys = source.config.keys;
11
+ if (!keys) {
12
+ try {
13
+ keys = await client.list(source.config.prefix);
14
+ }
15
+ catch (error) {
16
+ throw CopilotError.sourceLoadFailed(`Failed to list object storage keys: ${String(error)}`, {
17
+ sourceId: source.id,
18
+ });
19
+ }
20
+ }
21
+ for (const key of keys) {
22
+ throwIfAborted(context?.signal);
23
+ let object;
24
+ try {
25
+ object = await client.get(key);
26
+ }
27
+ catch (error) {
28
+ throw CopilotError.sourceLoadFailed(`Failed to read object "${key}": ${String(error)}`, {
29
+ sourceId: source.id,
30
+ key,
31
+ });
32
+ }
33
+ const content = normalizeText(object.content);
34
+ if (content.length === 0)
35
+ continue;
36
+ yield createKnowledgeDocument({
37
+ sourceId: source.id,
38
+ discriminator: key,
39
+ content,
40
+ metadata: {
41
+ uri: key,
42
+ ...object.metadata,
43
+ tenantId: source.tenantId,
44
+ acl: object.metadata?.acl ?? source.acl,
45
+ },
46
+ });
47
+ }
48
+ },
49
+ };
50
+ //# sourceMappingURL=object-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-storage.js","sourceRoot":"","sources":["../../src/loaders/object-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAA2C,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,2GAA2G;AAC3G,MAAM,CAAC,MAAM,mBAAmB,GAA8C;IAC5E,KAAK,CAAC,CAAC,IAAI,CACT,MAAkD,EAClD,OAAuB;QAEvB,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAChC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC;QACjC,IAAI,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAC9B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,CAAC;gBACH,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACjD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,YAAY,CAAC,gBAAgB,CAAC,uCAAuC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE;oBAC1F,QAAQ,EAAE,MAAM,CAAC,EAAE;iBACpB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAChC,IAAI,MAAM,CAAC;YACX,IAAI,CAAC;gBACH,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACjC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,YAAY,CAAC,gBAAgB,CAAC,0BAA0B,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE;oBACtF,QAAQ,EAAE,MAAM,CAAC,EAAE;oBACnB,GAAG;iBACJ,CAAC,CAAC;YACL,CAAC;YACD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAS;YACnC,MAAM,uBAAuB,CAAC;gBAC5B,QAAQ,EAAE,MAAM,CAAC,EAAE;gBACnB,aAAa,EAAE,GAAG;gBAClB,OAAO;gBACP,QAAQ,EAAE;oBACR,GAAG,EAAE,GAAG;oBACR,GAAG,MAAM,CAAC,QAAQ;oBAClB,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,GAAG,EAAE,MAAM,CAAC,QAAQ,EAAE,GAAG,IAAI,MAAM,CAAC,GAAG;iBACxC;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type DocumentLoader } from '../loader.js';
2
+ import type { BinarySourceConfig } from '../source.js';
3
+ /** PDF loader (Section 18) - one KnowledgeDocument per page, so page provenance is exact rather than reconstructed. */
4
+ export declare const pdfLoader: DocumentLoader<BinarySourceConfig>;
5
+ //# sourceMappingURL=pdf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf.d.ts","sourceRoot":"","sources":["../../src/loaders/pdf.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,cAAc,EAAsB,MAAM,cAAc,CAAC;AAEvF,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,cAAc,CAAC;AA6CxE,uHAAuH;AACvH,eAAO,MAAM,SAAS,EAAE,cAAc,CAAC,kBAAkB,CAmExD,CAAC"}
@@ -0,0 +1,102 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { CopilotError } from '@gixcopilot/protocol';
3
+ import { getDocument } from 'pdfjs-dist/legacy/build/pdf.mjs';
4
+ import { createKnowledgeDocument } from '../document.js';
5
+ import { throwIfAborted } from '../loader.js';
6
+ import { normalizeText } from '../normalize.js';
7
+ function isTextItem(item) {
8
+ return typeof item.str === 'string';
9
+ }
10
+ /** pdfjs-dist types the document info dictionary as the near-opaque `Object` - narrow it defensively. */
11
+ function extractTitle(info) {
12
+ if (!info || typeof info !== 'object' || !('Title' in info))
13
+ return undefined;
14
+ return typeof info.Title === 'string' ? info.Title.trim() || undefined : undefined;
15
+ }
16
+ async function readPdfBuffer(config) {
17
+ if (config.buffer)
18
+ return config.buffer;
19
+ if (config.path)
20
+ return readFile(config.path);
21
+ throw CopilotError.sourceLoadFailed('A PDF source requires either "path" or "buffer".');
22
+ }
23
+ /** Joins a page's text items using pdfjs's own `hasEOL` flag rather than a Y-position heuristic. */
24
+ function joinTextItems(items) {
25
+ let text = '';
26
+ for (const item of items) {
27
+ if (!isTextItem(item))
28
+ continue;
29
+ text += item.str;
30
+ if (item.hasEOL)
31
+ text += '\n';
32
+ }
33
+ return text;
34
+ }
35
+ /** PDF loader (Section 18) - one KnowledgeDocument per page, so page provenance is exact rather than reconstructed. */
36
+ export const pdfLoader = {
37
+ async *load(source, context) {
38
+ throwIfAborted(context?.signal);
39
+ const buffer = await readPdfBuffer(source.config).catch((error) => {
40
+ if (CopilotError.isCopilotError(error))
41
+ throw error;
42
+ throw CopilotError.sourceLoadFailed(`Failed to read PDF source: ${String(error)}`, {
43
+ sourceId: source.id,
44
+ });
45
+ });
46
+ let numPages;
47
+ let title;
48
+ let getPage;
49
+ try {
50
+ // pdfjs-dist rejects a Node Buffer at runtime even though it is a Uint8Array subclass -
51
+ // it must be a plain Uint8Array.
52
+ const data = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
53
+ // A harmless "Ensure that the standardFontDataUrl API parameter is provided" warning is
54
+ // expected here for text-only extraction (no glyph rendering happens in this loader) -
55
+ // pointing pdfjs-dist at its bundled standard_fonts/ directory instead produces a
56
+ // *different* warning in this Node runtime (it cannot fetch a file:// URL for the font),
57
+ // so the default (undefined) is left as-is rather than trading one cosmetic warning for
58
+ // another.
59
+ const doc = await getDocument({ data, isEvalSupported: false }).promise;
60
+ numPages = doc.numPages;
61
+ const metadata = await doc.getMetadata().catch(() => null);
62
+ title = extractTitle(metadata?.info);
63
+ getPage = (pageNumber) => doc.getPage(pageNumber);
64
+ }
65
+ catch (error) {
66
+ throw CopilotError.parseFailed(`Failed to parse PDF source: ${String(error)}`, {
67
+ sourceId: source.id,
68
+ });
69
+ }
70
+ for (let pageNumber = 1; pageNumber <= numPages; pageNumber++) {
71
+ throwIfAborted(context?.signal);
72
+ let rawPageText;
73
+ try {
74
+ const page = await getPage(pageNumber);
75
+ const textContent = await page.getTextContent();
76
+ rawPageText = joinTextItems(textContent.items);
77
+ }
78
+ catch (error) {
79
+ throw CopilotError.parseFailed(`Failed to extract text from PDF page ${pageNumber}: ${String(error)}`, {
80
+ sourceId: source.id,
81
+ page: pageNumber,
82
+ });
83
+ }
84
+ const content = normalizeText(rawPageText);
85
+ if (content.length === 0)
86
+ continue;
87
+ yield createKnowledgeDocument({
88
+ sourceId: source.id,
89
+ discriminator: pageNumber,
90
+ content,
91
+ metadata: {
92
+ ...(title !== undefined || source.name !== undefined ? { title: title ?? source.name } : {}),
93
+ mimeType: 'application/pdf',
94
+ page: pageNumber,
95
+ tenantId: source.tenantId,
96
+ acl: source.acl,
97
+ },
98
+ });
99
+ }
100
+ },
101
+ };
102
+ //# sourceMappingURL=pdf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf.js","sourceRoot":"","sources":["../../src/loaders/pdf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAA2C,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAmBhD,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,OAAQ,IAA6B,CAAC,GAAG,KAAK,QAAQ,CAAC;AAChE,CAAC;AAED,yGAAyG;AACzG,SAAS,YAAY,CAAC,IAAa;IACjC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9E,OAAO,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACrF,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,MAA0B;IACrD,IAAI,MAAM,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC;IACxC,IAAI,MAAM,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC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C,WAAW,CAAC,CAAC;YAC3C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAS;YACnC,MAAM,uBAAuB,CAAC;gBAC5B,QAAQ,EAAE,MAAM,CAAC,EAAE;gBACnB,aAAa,EAAE,UAAU;gBACzB,OAAO;gBACP,QAAQ,EAAE;oBACR,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC5F,QAAQ,EAAE,iBAAiB;oBAC3B,IAAI,EAAE,UAAU;oBAChB,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,GAAG,EAAE,MAAM,CAAC,GAAG;iBAChB;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type DocumentLoader } from '../loader.js';
2
+ import type { TextSourceConfig } from '../source.js';
3
+ /** Plain-text loader (Section 16). */
4
+ export declare const textLoader: DocumentLoader<TextSourceConfig>;
5
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/loaders/text.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,cAAc,EAAsB,MAAM,cAAc,CAAC;AAEvF,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEtE,sCAAsC;AACtC,eAAO,MAAM,UAAU,EAAE,cAAc,CAAC,gBAAgB,CAkBvD,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { createKnowledgeDocument } from '../document.js';
2
+ import { throwIfAborted } from '../loader.js';
3
+ import { normalizeText } from '../normalize.js';
4
+ /** Plain-text loader (Section 16). */
5
+ export const textLoader = {
6
+ async *load(source, context) {
7
+ throwIfAborted(context?.signal);
8
+ await Promise.resolve(); // keep every loader's first yield microtask-deferred, not just the I/O-bound ones
9
+ yield createKnowledgeDocument({
10
+ sourceId: source.id,
11
+ content: normalizeText(source.config.content),
12
+ metadata: {
13
+ ...(source.name !== undefined ? { title: source.name } : {}),
14
+ mimeType: 'text/plain',
15
+ tenantId: source.tenantId,
16
+ acl: source.acl,
17
+ },
18
+ });
19
+ },
20
+ };
21
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/loaders/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAA2C,MAAM,cAAc,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,sCAAsC;AACtC,MAAM,CAAC,MAAM,UAAU,GAAqC;IAC1D,KAAK,CAAC,CAAC,IAAI,CACT,MAAyC,EACzC,OAAuB;QAEvB,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAChC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,kFAAkF;QAC3G,MAAM,uBAAuB,CAAC;YAC5B,QAAQ,EAAE,MAAM,CAAC,EAAE;YACnB,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;YAC7C,QAAQ,EAAE;gBACR,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5D,QAAQ,EAAE,YAAY;gBACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,GAAG,EAAE,MAAM,CAAC,GAAG;aAChB;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { type DocumentLoader } from '../loader.js';
2
+ import type { WebSourceConfig } from '../source.js';
3
+ /**
4
+ * Remote web loader (Section 20). Deliberately narrow: no arbitrary model-controlled fetch
5
+ * capability (Section 20's explicit prohibition) - the URL comes from a developer-configured
6
+ * `webSource`, never from model output, and is checked with `assertSafeWebUrl` before fetching.
7
+ */
8
+ export declare const webLoader: DocumentLoader<WebSourceConfig>;
9
+ //# sourceMappingURL=web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/loaders/web.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,cAAc,EAAsB,MAAM,cAAc,CAAC;AAEvF,OAAO,KAAK,EAAmB,eAAe,EAAE,MAAM,cAAc,CAAC;AAMrE;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,cAAc,CAAC,eAAe,CAuGrD,CAAC"}