@cyanheads/mcp-ts-core 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/CLAUDE.md +1 -1
- package/README.md +1 -1
- package/biome.json +1 -1
- package/changelog/0.11.x/0.11.2.md +98 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +27 -13
- package/dist/config/index.js.map +1 -1
- package/dist/core/app.d.ts +37 -14
- package/dist/core/app.d.ts.map +1 -1
- package/dist/core/app.js +56 -23
- package/dist/core/app.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/worker.d.ts.map +1 -1
- package/dist/core/worker.js +35 -18
- package/dist/core/worker.js.map +1 -1
- package/dist/mcp-server/elicitation.d.ts +64 -0
- package/dist/mcp-server/elicitation.d.ts.map +1 -0
- package/dist/mcp-server/elicitation.js +81 -0
- package/dist/mcp-server/elicitation.js.map +1 -0
- package/dist/mcp-server/protocolSession.d.ts +34 -0
- package/dist/mcp-server/protocolSession.d.ts.map +1 -0
- package/dist/mcp-server/protocolSession.js +13 -0
- package/dist/mcp-server/protocolSession.js.map +1 -0
- package/dist/mcp-server/resources/resource-registration.d.ts +2 -1
- package/dist/mcp-server/resources/resource-registration.d.ts.map +1 -1
- package/dist/mcp-server/resources/resource-registration.js +6 -2
- package/dist/mcp-server/resources/resource-registration.js.map +1 -1
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts +7 -12
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts.map +1 -1
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.js +24 -31
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.js.map +1 -1
- package/dist/mcp-server/server.d.ts +3 -0
- package/dist/mcp-server/server.d.ts.map +1 -1
- package/dist/mcp-server/server.js +12 -2
- package/dist/mcp-server/server.js.map +1 -1
- package/dist/mcp-server/tools/tool-registration.d.ts +2 -1
- package/dist/mcp-server/tools/tool-registration.d.ts.map +1 -1
- package/dist/mcp-server/tools/tool-registration.js +6 -2
- package/dist/mcp-server/tools/tool-registration.js.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +7 -13
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js +11 -44
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
- package/dist/mcp-server/transports/http/httpErrorHandler.js +1 -1
- package/dist/mcp-server/transports/http/httpErrorHandler.js.map +1 -1
- package/dist/mcp-server/transports/http/httpServer.d.ts +2 -2
- package/dist/mcp-server/transports/http/httpServer.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/httpServer.js.map +1 -1
- package/dist/mcp-server/transports/http/httpTransport.d.ts +2 -2
- package/dist/mcp-server/transports/http/httpTransport.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/httpTransport.js +113 -55
- package/dist/mcp-server/transports/http/httpTransport.js.map +1 -1
- package/dist/mcp-server/transports/http/sessionStore.d.ts +17 -0
- package/dist/mcp-server/transports/http/sessionStore.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/sessionStore.js +71 -0
- package/dist/mcp-server/transports/http/sessionStore.js.map +1 -1
- package/dist/mcp-server/transports/manager.d.ts +2 -6
- package/dist/mcp-server/transports/manager.d.ts.map +1 -1
- package/dist/mcp-server/transports/manager.js +4 -0
- package/dist/mcp-server/transports/manager.js.map +1 -1
- package/dist/services/canvas/core/CanvasRegistry.d.ts +2 -2
- package/dist/services/canvas/core/CanvasRegistry.d.ts.map +1 -1
- package/dist/services/canvas/core/CanvasRegistry.js +14 -3
- package/dist/services/canvas/core/CanvasRegistry.js.map +1 -1
- package/dist/services/canvas/core/DataCanvas.d.ts +1 -1
- package/dist/services/canvas/core/DataCanvas.d.ts.map +1 -1
- package/dist/services/canvas/core/DataCanvas.js +2 -2
- package/dist/services/canvas/core/DataCanvas.js.map +1 -1
- package/dist/services/canvas/providers/duckdb/DuckdbProvider.d.ts.map +1 -1
- package/dist/services/canvas/providers/duckdb/DuckdbProvider.js +11 -3
- package/dist/services/canvas/providers/duckdb/DuckdbProvider.js.map +1 -1
- package/dist/services/canvas/providers/duckdb/exportWriter.d.ts.map +1 -1
- package/dist/services/canvas/providers/duckdb/exportWriter.js +23 -2
- package/dist/services/canvas/providers/duckdb/exportWriter.js.map +1 -1
- package/dist/services/mirror/core/defineMirror.d.ts.map +1 -1
- package/dist/services/mirror/core/defineMirror.js +18 -7
- package/dist/services/mirror/core/defineMirror.js.map +1 -1
- package/dist/services/mirror/core/runner.d.ts.map +1 -1
- package/dist/services/mirror/core/runner.js +3 -0
- package/dist/services/mirror/core/runner.js.map +1 -1
- package/dist/services/mirror/index.d.ts +1 -1
- package/dist/services/mirror/index.d.ts.map +1 -1
- package/dist/services/mirror/index.js.map +1 -1
- package/dist/services/mirror/sqlite/sqliteMirrorStore.d.ts +20 -0
- package/dist/services/mirror/sqlite/sqliteMirrorStore.d.ts.map +1 -1
- package/dist/services/mirror/sqlite/sqliteMirrorStore.js +87 -8
- package/dist/services/mirror/sqlite/sqliteMirrorStore.js.map +1 -1
- package/dist/storage/core/StorageService.d.ts.map +1 -1
- package/dist/storage/core/StorageService.js +4 -1
- package/dist/storage/core/StorageService.js.map +1 -1
- package/dist/storage/core/storageValidation.d.ts +8 -0
- package/dist/storage/core/storageValidation.d.ts.map +1 -1
- package/dist/storage/core/storageValidation.js +38 -0
- package/dist/storage/core/storageValidation.js.map +1 -1
- package/dist/storage/providers/inMemory/inMemoryProvider.d.ts +1 -1
- package/dist/storage/providers/inMemory/inMemoryProvider.d.ts.map +1 -1
- package/dist/storage/providers/inMemory/inMemoryProvider.js +67 -25
- package/dist/storage/providers/inMemory/inMemoryProvider.js.map +1 -1
- package/dist/testing/fuzz.d.ts.map +1 -1
- package/dist/testing/fuzz.js +33 -14
- package/dist/testing/fuzz.js.map +1 -1
- package/dist/testing/vitest.d.ts +11 -2
- package/dist/testing/vitest.d.ts.map +1 -1
- package/dist/testing/vitest.js +3 -0
- package/dist/testing/vitest.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/network/fetchWithTimeout.d.ts +7 -6
- package/dist/utils/network/fetchWithTimeout.d.ts.map +1 -1
- package/dist/utils/network/fetchWithTimeout.js +141 -51
- package/dist/utils/network/fetchWithTimeout.js.map +1 -1
- package/dist/utils/network/httpError.d.ts.map +1 -1
- package/dist/utils/network/httpError.js +3 -2
- package/dist/utils/network/httpError.js.map +1 -1
- package/dist/utils/network/responseBody.d.ts +15 -0
- package/dist/utils/network/responseBody.d.ts.map +1 -0
- package/dist/utils/network/responseBody.js +63 -0
- package/dist/utils/network/responseBody.js.map +1 -0
- package/dist/utils/parsing/frontmatterParser.d.ts +3 -1
- package/dist/utils/parsing/frontmatterParser.d.ts.map +1 -1
- package/dist/utils/parsing/frontmatterParser.js +6 -7
- package/dist/utils/parsing/frontmatterParser.js.map +1 -1
- package/dist/utils/parsing/htmlExtractor.d.ts +4 -0
- package/dist/utils/parsing/htmlExtractor.d.ts.map +1 -1
- package/dist/utils/parsing/htmlExtractor.js +4 -5
- package/dist/utils/parsing/htmlExtractor.js.map +1 -1
- package/dist/utils/parsing/index.d.ts +1 -0
- package/dist/utils/parsing/index.d.ts.map +1 -1
- package/dist/utils/parsing/index.js +1 -0
- package/dist/utils/parsing/index.js.map +1 -1
- package/dist/utils/parsing/inputBudget.d.ts +28 -0
- package/dist/utils/parsing/inputBudget.d.ts.map +1 -0
- package/dist/utils/parsing/inputBudget.js +76 -0
- package/dist/utils/parsing/inputBudget.js.map +1 -0
- package/dist/utils/parsing/jsonParser.d.ts +3 -1
- package/dist/utils/parsing/jsonParser.d.ts.map +1 -1
- package/dist/utils/parsing/jsonParser.js +5 -6
- package/dist/utils/parsing/jsonParser.js.map +1 -1
- package/dist/utils/parsing/pdfParser.d.ts +11 -3
- package/dist/utils/parsing/pdfParser.d.ts.map +1 -1
- package/dist/utils/parsing/pdfParser.js +65 -50
- package/dist/utils/parsing/pdfParser.js.map +1 -1
- package/dist/utils/parsing/xmlParser.d.ts +3 -1
- package/dist/utils/parsing/xmlParser.d.ts.map +1 -1
- package/dist/utils/parsing/xmlParser.js +8 -6
- package/dist/utils/parsing/xmlParser.js.map +1 -1
- package/dist/utils/parsing/yamlParser.d.ts +3 -1
- package/dist/utils/parsing/yamlParser.d.ts.map +1 -1
- package/dist/utils/parsing/yamlParser.js +5 -6
- package/dist/utils/parsing/yamlParser.js.map +1 -1
- package/package.json +17 -15
- package/skills/git-wrapup/SKILL.md +22 -1
- package/dist/logs/combined.log +0 -8
- package/dist/logs/error.log +0 -4
- package/dist/logs/interactions.log +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlExtractor.js","sourceRoot":"","sources":["../../../src/utils/parsing/htmlExtractor.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAuB,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"htmlExtractor.js","sourceRoot":"","sources":["../../../src/utils/parsing/htmlExtractor.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAuB,qBAAqB,EAAE,MAAM,oCAAo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M,CAAC,SAAS,KAAK,QAAQ;gBAAE,GAAG,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;YAC3E,IAAI,MAAM,CAAC,aAAa;gBAAE,GAAG,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;YACnE,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAClD,IAAI,QAAQ;gBAAE,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACtC,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,IAAI,CAAC,YAAY,QAAQ;gBAAE,MAAM,CAAC,CAAC;YACnC,MAAM,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5D,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE;gBACnD,GAAG,UAAU;gBACb,YAAY,EAAE,KAAK,CAAC,OAAO;aAC5B,CAAC,CAAC;YACH,MAAM,eAAe,CACnB,sCAAsC,EACtC,EAAE,MAAM,EAAE,qBAAqB,EAAE,EACjC,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -8,6 +8,7 @@ export { CsvParser, csvParser } from './csvParser.js';
|
|
|
8
8
|
export { dateParser, parseDateString, parseDateStringDetailed } from './dateParser.js';
|
|
9
9
|
export { FrontmatterParser, type FrontmatterResult, frontmatterParser, } from './frontmatterParser.js';
|
|
10
10
|
export { type ExtractArticleOptions, type ExtractArticleResult, HtmlExtractor, htmlExtractor, } from './htmlExtractor.js';
|
|
11
|
+
export { DEFAULT_BINARY_PARSER_MAX_BYTES, DEFAULT_TEXT_PARSER_MAX_BYTES, type ParserInputBudgetOptions, } from './inputBudget.js';
|
|
11
12
|
export { Allow, JsonParser, jsonParser } from './jsonParser.js';
|
|
12
13
|
export { type AddPageOptions, type DrawImageOptions, type DrawTextOptions, type EmbedImageOptions, type ExtractTextOptions, type ExtractTextResult, type FillFormOptions, type PageRange, type PdfMetadata, PdfParser, pdfParser, type SetMetadataOptions, } from './pdfParser.js';
|
|
13
14
|
export { thinkBlockRegex } from './thinkBlock.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACvF,OAAO,EACL,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,aAAa,EACb,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,SAAS,EACT,SAAS,EACT,KAAK,kBAAkB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACvF,OAAO,EACL,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,aAAa,EACb,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,EAC7B,KAAK,wBAAwB,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,SAAS,EACT,SAAS,EACT,KAAK,kBAAkB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -8,6 +8,7 @@ export { CsvParser, csvParser } from './csvParser.js';
|
|
|
8
8
|
export { dateParser, parseDateString, parseDateStringDetailed } from './dateParser.js';
|
|
9
9
|
export { FrontmatterParser, frontmatterParser, } from './frontmatterParser.js';
|
|
10
10
|
export { HtmlExtractor, htmlExtractor, } from './htmlExtractor.js';
|
|
11
|
+
export { DEFAULT_BINARY_PARSER_MAX_BYTES, DEFAULT_TEXT_PARSER_MAX_BYTES, } from './inputBudget.js';
|
|
11
12
|
export { Allow, JsonParser, jsonParser } from './jsonParser.js';
|
|
12
13
|
export { PdfParser, pdfParser, } from './pdfParser.js';
|
|
13
14
|
export { thinkBlockRegex } from './thinkBlock.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/parsing/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACvF,OAAO,EACL,iBAAiB,EAEjB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGL,aAAa,EACb,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAUL,SAAS,EACT,SAAS,GAEV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/parsing/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACvF,OAAO,EACL,iBAAiB,EAEjB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGL,aAAa,EACb,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,GAE9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAUL,SAAS,EACT,SAAS,GAEV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Input byte budgets shared by the parsing utilities. Bounds the
|
|
3
|
+
* work a single parse can schedule, so a hostile document cannot amplify a
|
|
4
|
+
* modest request into unbounded CPU or memory in the parser dependency.
|
|
5
|
+
* @module src/utils/parsing/inputBudget
|
|
6
|
+
*/
|
|
7
|
+
/** Default UTF-8 input budget for text parsers (1 MiB). */
|
|
8
|
+
export declare const DEFAULT_TEXT_PARSER_MAX_BYTES: number;
|
|
9
|
+
/** Default input budget for binary parsers (25 MiB). */
|
|
10
|
+
export declare const DEFAULT_BINARY_PARSER_MAX_BYTES: number;
|
|
11
|
+
/**
|
|
12
|
+
* Caller override for a parser's input budget. The defaults are a safe starting
|
|
13
|
+
* point rather than a security boundary — the input is already resident in
|
|
14
|
+
* memory by the time a parser sees it — so a caller that knowingly handles
|
|
15
|
+
* larger documents may raise as well as lower the limit.
|
|
16
|
+
*/
|
|
17
|
+
export interface ParserInputBudgetOptions {
|
|
18
|
+
maxBytes?: number;
|
|
19
|
+
}
|
|
20
|
+
/** Return the UTF-8 byte length without allocating a second copy of the input. */
|
|
21
|
+
export declare function utf8ByteLength(input: string): number;
|
|
22
|
+
/** Assert a text input fits its budget. Returns the input's UTF-8 byte length. */
|
|
23
|
+
export declare function assertTextInputBudget(input: string, options?: ParserInputBudgetOptions): number;
|
|
24
|
+
/** Assert a binary input fits its budget. Returns the input's byte length. */
|
|
25
|
+
export declare function assertBinaryInputBudget(input: Uint8Array | ArrayBuffer, options?: ParserInputBudgetOptions): number;
|
|
26
|
+
/** Assert a set of binary inputs fits one shared budget. Returns their combined byte length. */
|
|
27
|
+
export declare function assertBinaryInputsBudget(inputs: readonly (Uint8Array | ArrayBuffer)[], options?: ParserInputBudgetOptions): number;
|
|
28
|
+
//# sourceMappingURL=inputBudget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputBudget.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/inputBudget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,2DAA2D;AAC3D,eAAO,MAAM,6BAA6B,QAAc,CAAC;AAEzD,wDAAwD;AACxD,eAAO,MAAM,+BAA+B,QAAmB,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAgBD,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAyBpD;AAcD,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,MAAM,CAG/F;AAED,8EAA8E;AAC9E,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,UAAU,GAAG,WAAW,EAC/B,OAAO,CAAC,EAAE,wBAAwB,GACjC,MAAM,CAGR;AAED,gGAAgG;AAChG,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,CAAC,UAAU,GAAG,WAAW,CAAC,EAAE,EAC7C,OAAO,CAAC,EAAE,wBAAwB,GACjC,MAAM,CAIR"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Input byte budgets shared by the parsing utilities. Bounds the
|
|
3
|
+
* work a single parse can schedule, so a hostile document cannot amplify a
|
|
4
|
+
* modest request into unbounded CPU or memory in the parser dependency.
|
|
5
|
+
* @module src/utils/parsing/inputBudget
|
|
6
|
+
*/
|
|
7
|
+
import { validationError } from '../../types-global/errors.js';
|
|
8
|
+
/** Default UTF-8 input budget for text parsers (1 MiB). */
|
|
9
|
+
export const DEFAULT_TEXT_PARSER_MAX_BYTES = 1024 * 1024;
|
|
10
|
+
/** Default input budget for binary parsers (25 MiB). */
|
|
11
|
+
export const DEFAULT_BINARY_PARSER_MAX_BYTES = 25 * 1024 * 1024;
|
|
12
|
+
function resolveLimit(options, defaultLimit) {
|
|
13
|
+
const requested = options?.maxBytes;
|
|
14
|
+
if (requested === undefined)
|
|
15
|
+
return defaultLimit;
|
|
16
|
+
if (!Number.isSafeInteger(requested) || requested < 1) {
|
|
17
|
+
throw validationError('Parser input byte limit must be a positive safe integer.', {
|
|
18
|
+
reason: 'parser_input_limit_invalid',
|
|
19
|
+
limitBytes: defaultLimit,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return requested;
|
|
23
|
+
}
|
|
24
|
+
/** Return the UTF-8 byte length without allocating a second copy of the input. */
|
|
25
|
+
export function utf8ByteLength(input) {
|
|
26
|
+
let bytes = 0;
|
|
27
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
28
|
+
const codeUnit = input.charCodeAt(index);
|
|
29
|
+
if (codeUnit <= 0x7f) {
|
|
30
|
+
bytes += 1;
|
|
31
|
+
}
|
|
32
|
+
else if (codeUnit <= 0x7ff) {
|
|
33
|
+
bytes += 2;
|
|
34
|
+
}
|
|
35
|
+
else if (codeUnit >= 0xd800 &&
|
|
36
|
+
codeUnit <= 0xdbff &&
|
|
37
|
+
index + 1 < input.length &&
|
|
38
|
+
input.charCodeAt(index + 1) >= 0xdc00 &&
|
|
39
|
+
input.charCodeAt(index + 1) <= 0xdfff) {
|
|
40
|
+
bytes += 4;
|
|
41
|
+
index += 1;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// BMP characters and unpaired surrogates both encode as three bytes.
|
|
45
|
+
bytes += 3;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return bytes;
|
|
49
|
+
}
|
|
50
|
+
function assertWithinLimit(sizeBytes, limitBytes) {
|
|
51
|
+
if (sizeBytes > limitBytes) {
|
|
52
|
+
throw validationError('Parser input exceeds the maximum allowed byte size.', {
|
|
53
|
+
reason: 'parser_input_too_large',
|
|
54
|
+
sizeBytes,
|
|
55
|
+
limitBytes,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return sizeBytes;
|
|
59
|
+
}
|
|
60
|
+
/** Assert a text input fits its budget. Returns the input's UTF-8 byte length. */
|
|
61
|
+
export function assertTextInputBudget(input, options) {
|
|
62
|
+
const limitBytes = resolveLimit(options, DEFAULT_TEXT_PARSER_MAX_BYTES);
|
|
63
|
+
return assertWithinLimit(utf8ByteLength(input), limitBytes);
|
|
64
|
+
}
|
|
65
|
+
/** Assert a binary input fits its budget. Returns the input's byte length. */
|
|
66
|
+
export function assertBinaryInputBudget(input, options) {
|
|
67
|
+
const limitBytes = resolveLimit(options, DEFAULT_BINARY_PARSER_MAX_BYTES);
|
|
68
|
+
return assertWithinLimit(input.byteLength, limitBytes);
|
|
69
|
+
}
|
|
70
|
+
/** Assert a set of binary inputs fits one shared budget. Returns their combined byte length. */
|
|
71
|
+
export function assertBinaryInputsBudget(inputs, options) {
|
|
72
|
+
const limitBytes = resolveLimit(options, DEFAULT_BINARY_PARSER_MAX_BYTES);
|
|
73
|
+
const sizeBytes = inputs.reduce((total, input) => total + input.byteLength, 0);
|
|
74
|
+
return assertWithinLimit(sizeBytes, limitBytes);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=inputBudget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputBudget.js","sourceRoot":"","sources":["../../../src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EAAE,CAAC,CAAC,CAAC;IAC/E,OAAO,iBAAiB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type RequestContext } from '../../utils/internal/requestContext.js';
|
|
2
|
+
import { type ParserInputBudgetOptions } from './inputBudget.js';
|
|
2
3
|
/**
|
|
3
4
|
* Bit flags specifying which partial JSON types are permissible during parsing.
|
|
4
5
|
* Mirrors `partial-json`'s `Allow` constants. Combine flags with bitwise OR
|
|
@@ -68,6 +69,7 @@ export declare class JsonParser {
|
|
|
68
69
|
* @param allowPartial - Bitwise OR combination of `Allow` flags controlling which
|
|
69
70
|
* partial JSON types are accepted. Defaults to `Allow.ALL`.
|
|
70
71
|
* @param context - Optional `RequestContext` for correlated logging and error metadata.
|
|
72
|
+
* @param budget - Optional UTF-8 byte budget for the input. Defaults to 1 MiB.
|
|
71
73
|
* @returns The parsed JavaScript value cast to `T`.
|
|
72
74
|
* @throws {McpError} With `ValidationError` if the string is empty after stripping the
|
|
73
75
|
* `<think>` block and trimming, or if `partial-json` fails to parse the content.
|
|
@@ -86,7 +88,7 @@ export declare class JsonParser {
|
|
|
86
88
|
* console.log(result); // { items: [1, 2] }
|
|
87
89
|
* ```
|
|
88
90
|
*/
|
|
89
|
-
parse<T = unknown>(jsonString: string, allowPartial?: number, context?: RequestContext): Promise<T>;
|
|
91
|
+
parse<T = unknown>(jsonString: string, allowPartial?: number, context?: RequestContext, budget?: ParserInputBudgetOptions): Promise<T>;
|
|
90
92
|
}
|
|
91
93
|
/**
|
|
92
94
|
* Singleton instance of `JsonParser`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonParser.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/jsonParser.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"jsonParser.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/jsonParser.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,oCAAoC,CAAC;AAChG,OAAO,EAAyB,KAAK,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAQxF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK;IAChB,6BAA6B;aAC7B,GAAG,EAAE,CAAG;IACR,6BAA6B;aAC7B,GAAG,EAAE,CAAG;IACR,4BAA4B;aAC5B,GAAG,EAAE,CAAG;IACR,6BAA6B;aAC7B,GAAG,EAAE,CAAG;IACR,iCAAiC;aACjC,IAAI,EAAE,EAAI;IACV,8BAA8B;aAC9B,IAAI,EAAE,EAAI;IACV,wBAAwB;aACxB,GAAG,EAAE,EAAI;IACT,+BAA+B;aAC/B,QAAQ,EAAE,GAAI;IACd,+BAA+B;aAC/B,SAAS,EAAE,GAAK;IAChB,0EAA0E;aAC1E,GAAG;IACH,sEAAsE;aACtE,OAAO;IACP,8EAA8E;aAC9E,IAAI;IACJ,8CAA8C;aAC9C,UAAU;IACV,+BAA+B;aAC/B,GAAG;CACK,CAAC;AAEX;;;;;;;GAOG;AACH,qBAAa,UAAU;IACrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,KAAK,CAAC,CAAC,GAAG,OAAO,EACrB,UAAU,EAAE,MAAM,EAClB,YAAY,GAAE,MAAkB,EAChC,OAAO,CAAC,EAAE,cAAc,EACxB,MAAM,CAAC,EAAE,wBAAwB,GAChC,OAAO,CAAC,CAAC,CAAC,CAyDZ;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,UAAU,YAAmB,CAAC"}
|
|
@@ -8,6 +8,7 @@ import { validationError } from '../../types-global/errors.js';
|
|
|
8
8
|
import { lazyImport } from '../../utils/internal/lazyImport.js';
|
|
9
9
|
import { logger } from '../../utils/internal/logger.js';
|
|
10
10
|
import { requestContextService } from '../../utils/internal/requestContext.js';
|
|
11
|
+
import { assertTextInputBudget } from './inputBudget.js';
|
|
11
12
|
import { thinkBlockRegex } from './thinkBlock.js';
|
|
12
13
|
const getPartialJson = lazyImport(() => import('partial-json'), 'Install "partial-json" to use partial JSON parsing: bun add partial-json');
|
|
13
14
|
/**
|
|
@@ -79,6 +80,7 @@ export class JsonParser {
|
|
|
79
80
|
* @param allowPartial - Bitwise OR combination of `Allow` flags controlling which
|
|
80
81
|
* partial JSON types are accepted. Defaults to `Allow.ALL`.
|
|
81
82
|
* @param context - Optional `RequestContext` for correlated logging and error metadata.
|
|
83
|
+
* @param budget - Optional UTF-8 byte budget for the input. Defaults to 1 MiB.
|
|
82
84
|
* @returns The parsed JavaScript value cast to `T`.
|
|
83
85
|
* @throws {McpError} With `ValidationError` if the string is empty after stripping the
|
|
84
86
|
* `<think>` block and trimming, or if `partial-json` fails to parse the content.
|
|
@@ -97,7 +99,8 @@ export class JsonParser {
|
|
|
97
99
|
* console.log(result); // { items: [1, 2] }
|
|
98
100
|
* ```
|
|
99
101
|
*/
|
|
100
|
-
async parse(jsonString, allowPartial = Allow.ALL, context) {
|
|
102
|
+
async parse(jsonString, allowPartial = Allow.ALL, context, budget) {
|
|
103
|
+
assertTextInputBudget(jsonString, budget);
|
|
101
104
|
let stringToParse = jsonString;
|
|
102
105
|
const match = jsonString.match(thinkBlockRegex);
|
|
103
106
|
if (match) {
|
|
@@ -137,11 +140,7 @@ export class JsonParser {
|
|
|
137
140
|
errorDetails: error.message,
|
|
138
141
|
contentAttempted: stringToParse.substring(0, 200),
|
|
139
142
|
});
|
|
140
|
-
throw validationError(
|
|
141
|
-
...context,
|
|
142
|
-
originalContentSample: stringToParse.substring(0, 200) + (stringToParse.length > 200 ? '...' : ''),
|
|
143
|
-
rawError: error instanceof Error ? error.stack : String(error),
|
|
144
|
-
});
|
|
143
|
+
throw validationError('Failed to parse JSON content.', { reason: 'json_parse_failed' }, { cause: error });
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
146
|
}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ED,aAAa,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC;QAErC,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,eAAe,CACnB,iEAAiE,EACjE,OAAO,CACR,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,cAAc,EAAE,CAAC;YAC3D,OAAO,gBAAgB,CAAC,aAAa,EAAE,YAAY,CAAM,CAAC;QAC5D,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5D,MAAM,eAAe,GACnB,OAAO;gBACP,qBAAqB,CAAC,oBAAoB,CAAC;oBACzC,SAAS,EAAE,uBAAuB;iBACnC,CAAC,CAAC;YACL,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE;gBAC5C,GAAG,eAAe;gBAClB,YAAY,EAAE,KAAK,CAAC,OAAO;gBAC3B,gBAAgB,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC;aAClD,CAAC,CAAC;YAEH,MAAM,eAAe,CACnB,+BAA+B,EAC/B,EAAE,MAAM,EAAE,mBAAmB,EAAE,EAC/B,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { PDFDocument, PDFFont, PDFImage, PDFPage, RGB } from 'pdf-lib';
|
|
8
8
|
import { type RequestContext } from '../../utils/internal/requestContext.js';
|
|
9
|
+
import { type ParserInputBudgetOptions } from './inputBudget.js';
|
|
9
10
|
/**
|
|
10
11
|
* Options for adding a new page to a PDF document.
|
|
11
12
|
*/
|
|
@@ -73,6 +74,8 @@ export interface EmbedImageOptions {
|
|
|
73
74
|
* Image data as Uint8Array or ArrayBuffer.
|
|
74
75
|
*/
|
|
75
76
|
imageBytes: Uint8Array | ArrayBuffer;
|
|
77
|
+
/** Input budget in bytes. Defaults to 25 MiB; raise it for known-large images. */
|
|
78
|
+
maxBytes?: number;
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
78
81
|
* Options for drawing an embedded image on a page.
|
|
@@ -208,6 +211,8 @@ export interface FillFormOptions {
|
|
|
208
211
|
* Options for extracting text from a PDF document.
|
|
209
212
|
*/
|
|
210
213
|
export interface ExtractTextOptions {
|
|
214
|
+
/** Input budget in bytes. Defaults to 25 MiB; raise it for known-large documents. */
|
|
215
|
+
maxBytes?: number;
|
|
211
216
|
/**
|
|
212
217
|
* Whether to merge all pages into a single string.
|
|
213
218
|
* If true, returns text as a single string.
|
|
@@ -263,6 +268,7 @@ export declare class PdfParser {
|
|
|
263
268
|
*
|
|
264
269
|
* @param pdfBytes - The PDF file contents as `Uint8Array` or `ArrayBuffer`.
|
|
265
270
|
* @param context - Optional `RequestContext` for correlated logging and error metadata.
|
|
271
|
+
* @param budget - Optional byte budget for the input. Defaults to 25 MiB.
|
|
266
272
|
* @returns The loaded `PDFDocument` instance.
|
|
267
273
|
* @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
|
|
268
274
|
* @throws {McpError} With `ValidationError` if the bytes are not a valid PDF.
|
|
@@ -273,7 +279,7 @@ export declare class PdfParser {
|
|
|
273
279
|
* const doc = await pdfParser.loadDocument(pdfBytes);
|
|
274
280
|
* ```
|
|
275
281
|
*/
|
|
276
|
-
loadDocument(pdfBytes: Uint8Array | ArrayBuffer, context?: RequestContext): Promise<PDFDocument>;
|
|
282
|
+
loadDocument(pdfBytes: Uint8Array | ArrayBuffer, context?: RequestContext, budget?: ParserInputBudgetOptions): Promise<PDFDocument>;
|
|
277
283
|
/**
|
|
278
284
|
* Adds a new blank page to a PDF document.
|
|
279
285
|
*
|
|
@@ -386,6 +392,7 @@ export declare class PdfParser {
|
|
|
386
392
|
*
|
|
387
393
|
* @param pdfBytesArray - Source PDF files as `Uint8Array` or `ArrayBuffer` elements.
|
|
388
394
|
* @param context - Optional `RequestContext` for correlated logging and error metadata.
|
|
395
|
+
* @param budget - Optional aggregate byte budget across all inputs. Defaults to 25 MiB.
|
|
389
396
|
* @returns A new `PDFDocument` containing all pages from the input documents.
|
|
390
397
|
* @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
|
|
391
398
|
* @throws {McpError} With `InternalError` if any source PDF is invalid or merging fails.
|
|
@@ -398,7 +405,7 @@ export declare class PdfParser {
|
|
|
398
405
|
* const bytes = await pdfParser.saveDocument(merged);
|
|
399
406
|
* ```
|
|
400
407
|
*/
|
|
401
|
-
mergePdfs(pdfBytesArray: (Uint8Array | ArrayBuffer)[], context?: RequestContext): Promise<PDFDocument>;
|
|
408
|
+
mergePdfs(pdfBytesArray: (Uint8Array | ArrayBuffer)[], context?: RequestContext, budget?: ParserInputBudgetOptions): Promise<PDFDocument>;
|
|
402
409
|
/**
|
|
403
410
|
* Splits a PDF document into multiple new documents based on page ranges.
|
|
404
411
|
*
|
|
@@ -409,6 +416,7 @@ export declare class PdfParser {
|
|
|
409
416
|
* @param pdfBytes - The source PDF as `Uint8Array` or `ArrayBuffer`.
|
|
410
417
|
* @param ranges - Page ranges to extract; each produces one output document.
|
|
411
418
|
* @param context - Optional `RequestContext` for correlated logging and error metadata.
|
|
419
|
+
* @param budget - Optional byte budget for the input. Defaults to 25 MiB.
|
|
412
420
|
* @returns An array of new `PDFDocument` instances, one per range, in order.
|
|
413
421
|
* @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
|
|
414
422
|
* @throws {McpError} With `InternalError` if the source PDF is invalid or a page index is out of bounds.
|
|
@@ -422,7 +430,7 @@ export declare class PdfParser {
|
|
|
422
430
|
* ]);
|
|
423
431
|
* ```
|
|
424
432
|
*/
|
|
425
|
-
splitPdf(pdfBytes: Uint8Array | ArrayBuffer, ranges: PageRange[], context?: RequestContext): Promise<PDFDocument[]>;
|
|
433
|
+
splitPdf(pdfBytes: Uint8Array | ArrayBuffer, ranges: PageRange[], context?: RequestContext, budget?: ParserInputBudgetOptions): Promise<PDFDocument[]>;
|
|
426
434
|
/**
|
|
427
435
|
* Fills form fields in a PDF document.
|
|
428
436
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdfParser.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/pdfParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAK5E,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"pdfParser.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/pdfParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAK5E,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,oCAAoC,CAAC;AAChG,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,kBAAkB,CAAC;AAgC1B;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,GAAG,CAAC;IAEZ;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,UAAU,CAAC,EAAE,MA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AChC,OAAO,CAAC,WAAW,EAAE,CAAC,CAoDxB;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,CAqEnF;IAED;;;;;;;;;;;;;;OAcG;IACH,eAAe,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW,CAwB7C;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAOhE;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,WAAW,CACf,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,WAAW,EAC7C,OAAO,CAAC,EAAE,kBAAkB,EAC5B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,iBAAiB,CAAC,CA6E5B;IAED;;;;;;;;;;;;;;;;OAgBG;IACG,YAAY,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CA6BlF;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,SAAS,WAAkB,CAAC;AAEzC,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
import { JsonRpcErrorCode, McpError
|
|
1
|
+
import { JsonRpcErrorCode, McpError } from '../../types-global/errors.js';
|
|
2
2
|
import { lazyImport } from '../../utils/internal/lazyImport.js';
|
|
3
3
|
import { logger } from '../../utils/internal/logger.js';
|
|
4
4
|
import { requestContextService } from '../../utils/internal/requestContext.js';
|
|
5
|
+
import { assertBinaryInputBudget, assertBinaryInputsBudget, } from './inputBudget.js';
|
|
5
6
|
const getPdfLib = lazyImport(() => import('pdf-lib'), 'Install "pdf-lib" to use PDF operations: bun add pdf-lib');
|
|
6
7
|
const getUnpdf = lazyImport(() => import('unpdf'), 'Install "unpdf" to use PDF text extraction: bun add unpdf');
|
|
8
|
+
/**
|
|
9
|
+
* Build the client-facing PDF failure envelope without copying parser/library
|
|
10
|
+
* diagnostics into `McpError.data` or `message`. The original failure remains
|
|
11
|
+
* available to the internal error pipeline through `cause`.
|
|
12
|
+
*
|
|
13
|
+
* An `McpError` thrown from inside the operation is already classified and
|
|
14
|
+
* client-safe — most often the `ConfigurationError` a lazy import raises for a
|
|
15
|
+
* missing peer dependency — so it passes through with its code and remediation
|
|
16
|
+
* intact rather than being relabelled as a PDF failure.
|
|
17
|
+
*/
|
|
18
|
+
function pdfFailure(code, message, reason, cause) {
|
|
19
|
+
if (cause instanceof McpError)
|
|
20
|
+
return cause;
|
|
21
|
+
return new McpError(code, message, { reason }, { cause });
|
|
22
|
+
}
|
|
7
23
|
/**
|
|
8
24
|
* Utility class for creating, modifying, and parsing PDF documents.
|
|
9
25
|
*
|
|
@@ -45,10 +61,7 @@ export class PdfParser {
|
|
|
45
61
|
...logContext,
|
|
46
62
|
errorDetails: error.message,
|
|
47
63
|
});
|
|
48
|
-
throw
|
|
49
|
-
...context,
|
|
50
|
-
rawError: error instanceof Error ? error.stack : String(error),
|
|
51
|
-
});
|
|
64
|
+
throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to create PDF document.', 'pdf_create_failed', error);
|
|
52
65
|
}
|
|
53
66
|
}
|
|
54
67
|
/**
|
|
@@ -58,6 +71,7 @@ export class PdfParser {
|
|
|
58
71
|
*
|
|
59
72
|
* @param pdfBytes - The PDF file contents as `Uint8Array` or `ArrayBuffer`.
|
|
60
73
|
* @param context - Optional `RequestContext` for correlated logging and error metadata.
|
|
74
|
+
* @param budget - Optional byte budget for the input. Defaults to 25 MiB.
|
|
61
75
|
* @returns The loaded `PDFDocument` instance.
|
|
62
76
|
* @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
|
|
63
77
|
* @throws {McpError} With `ValidationError` if the bytes are not a valid PDF.
|
|
@@ -68,7 +82,8 @@ export class PdfParser {
|
|
|
68
82
|
* const doc = await pdfParser.loadDocument(pdfBytes);
|
|
69
83
|
* ```
|
|
70
84
|
*/
|
|
71
|
-
async loadDocument(pdfBytes, context) {
|
|
85
|
+
async loadDocument(pdfBytes, context, budget) {
|
|
86
|
+
const byteLength = assertBinaryInputBudget(pdfBytes, budget);
|
|
72
87
|
const logContext = context ||
|
|
73
88
|
requestContextService.createRequestContext({
|
|
74
89
|
operation: 'PdfParser.loadDocument',
|
|
@@ -77,7 +92,7 @@ export class PdfParser {
|
|
|
77
92
|
const pdfLib = await getPdfLib();
|
|
78
93
|
logger.debug('Loading PDF document from bytes.', {
|
|
79
94
|
...logContext,
|
|
80
|
-
byteLength
|
|
95
|
+
byteLength,
|
|
81
96
|
});
|
|
82
97
|
const doc = await pdfLib.PDFDocument.load(pdfBytes);
|
|
83
98
|
return doc;
|
|
@@ -88,10 +103,7 @@ export class PdfParser {
|
|
|
88
103
|
...logContext,
|
|
89
104
|
errorDetails: error.message,
|
|
90
105
|
});
|
|
91
|
-
throw
|
|
92
|
-
...context,
|
|
93
|
-
rawError: error instanceof Error ? error.stack : String(error),
|
|
94
|
-
});
|
|
106
|
+
throw pdfFailure(JsonRpcErrorCode.ValidationError, 'Failed to load PDF document.', 'pdf_load_failed', error);
|
|
95
107
|
}
|
|
96
108
|
}
|
|
97
109
|
/**
|
|
@@ -151,10 +163,7 @@ export class PdfParser {
|
|
|
151
163
|
fontName,
|
|
152
164
|
errorDetails: error.message,
|
|
153
165
|
});
|
|
154
|
-
throw
|
|
155
|
-
...context,
|
|
156
|
-
rawError: error instanceof Error ? error.stack : String(error),
|
|
157
|
-
});
|
|
166
|
+
throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to embed PDF font.', 'pdf_font_embed_failed', error);
|
|
158
167
|
}
|
|
159
168
|
}
|
|
160
169
|
/**
|
|
@@ -178,6 +187,7 @@ export class PdfParser {
|
|
|
178
187
|
* ```
|
|
179
188
|
*/
|
|
180
189
|
async embedImage(doc, options, context) {
|
|
190
|
+
assertBinaryInputBudget(options.imageBytes, options);
|
|
181
191
|
const logContext = context ||
|
|
182
192
|
requestContextService.createRequestContext({
|
|
183
193
|
operation: 'PdfParser.embedImage',
|
|
@@ -199,10 +209,7 @@ export class PdfParser {
|
|
|
199
209
|
format: options.format,
|
|
200
210
|
errorDetails: error.message,
|
|
201
211
|
});
|
|
202
|
-
throw
|
|
203
|
-
...context,
|
|
204
|
-
rawError: error instanceof Error ? error.stack : String(error),
|
|
205
|
-
});
|
|
212
|
+
throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to embed PDF image.', 'pdf_image_embed_failed', error);
|
|
206
213
|
}
|
|
207
214
|
}
|
|
208
215
|
/**
|
|
@@ -325,6 +332,7 @@ export class PdfParser {
|
|
|
325
332
|
*
|
|
326
333
|
* @param pdfBytesArray - Source PDF files as `Uint8Array` or `ArrayBuffer` elements.
|
|
327
334
|
* @param context - Optional `RequestContext` for correlated logging and error metadata.
|
|
335
|
+
* @param budget - Optional aggregate byte budget across all inputs. Defaults to 25 MiB.
|
|
328
336
|
* @returns A new `PDFDocument` containing all pages from the input documents.
|
|
329
337
|
* @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
|
|
330
338
|
* @throws {McpError} With `InternalError` if any source PDF is invalid or merging fails.
|
|
@@ -337,7 +345,9 @@ export class PdfParser {
|
|
|
337
345
|
* const bytes = await pdfParser.saveDocument(merged);
|
|
338
346
|
* ```
|
|
339
347
|
*/
|
|
340
|
-
async mergePdfs(pdfBytesArray, context) {
|
|
348
|
+
async mergePdfs(pdfBytesArray, context, budget) {
|
|
349
|
+
const presentInputs = pdfBytesArray.filter(Boolean);
|
|
350
|
+
assertBinaryInputsBudget(presentInputs, budget);
|
|
341
351
|
const logContext = context ||
|
|
342
352
|
requestContextService.createRequestContext({
|
|
343
353
|
operation: 'PdfParser.mergePdfs',
|
|
@@ -349,10 +359,7 @@ export class PdfParser {
|
|
|
349
359
|
documentCount: pdfBytesArray.length,
|
|
350
360
|
});
|
|
351
361
|
const mergedPdf = await pdfLib.PDFDocument.create();
|
|
352
|
-
for (
|
|
353
|
-
const pdfBytes = pdfBytesArray[i];
|
|
354
|
-
if (!pdfBytes)
|
|
355
|
-
continue;
|
|
362
|
+
for (const pdfBytes of presentInputs) {
|
|
356
363
|
const pdfDoc = await pdfLib.PDFDocument.load(pdfBytes);
|
|
357
364
|
const copiedPages = await mergedPdf.copyPages(pdfDoc, pdfDoc.getPageIndices());
|
|
358
365
|
for (const page of copiedPages)
|
|
@@ -370,10 +377,7 @@ export class PdfParser {
|
|
|
370
377
|
...logContext,
|
|
371
378
|
errorDetails: error.message,
|
|
372
379
|
});
|
|
373
|
-
throw
|
|
374
|
-
...context,
|
|
375
|
-
rawError: error instanceof Error ? error.stack : String(error),
|
|
376
|
-
});
|
|
380
|
+
throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to merge PDF documents.', 'pdf_merge_failed', error);
|
|
377
381
|
}
|
|
378
382
|
}
|
|
379
383
|
/**
|
|
@@ -386,6 +390,7 @@ export class PdfParser {
|
|
|
386
390
|
* @param pdfBytes - The source PDF as `Uint8Array` or `ArrayBuffer`.
|
|
387
391
|
* @param ranges - Page ranges to extract; each produces one output document.
|
|
388
392
|
* @param context - Optional `RequestContext` for correlated logging and error metadata.
|
|
393
|
+
* @param budget - Optional byte budget for the input. Defaults to 25 MiB.
|
|
389
394
|
* @returns An array of new `PDFDocument` instances, one per range, in order.
|
|
390
395
|
* @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
|
|
391
396
|
* @throws {McpError} With `InternalError` if the source PDF is invalid or a page index is out of bounds.
|
|
@@ -399,7 +404,8 @@ export class PdfParser {
|
|
|
399
404
|
* ]);
|
|
400
405
|
* ```
|
|
401
406
|
*/
|
|
402
|
-
async splitPdf(pdfBytes, ranges, context) {
|
|
407
|
+
async splitPdf(pdfBytes, ranges, context, budget) {
|
|
408
|
+
assertBinaryInputBudget(pdfBytes, budget);
|
|
403
409
|
const logContext = context ||
|
|
404
410
|
requestContextService.createRequestContext({
|
|
405
411
|
operation: 'PdfParser.splitPdf',
|
|
@@ -435,10 +441,7 @@ export class PdfParser {
|
|
|
435
441
|
...logContext,
|
|
436
442
|
errorDetails: error.message,
|
|
437
443
|
});
|
|
438
|
-
throw
|
|
439
|
-
...context,
|
|
440
|
-
rawError: error instanceof Error ? error.stack : String(error),
|
|
441
|
-
});
|
|
444
|
+
throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to split PDF document.', 'pdf_split_failed', error);
|
|
442
445
|
}
|
|
443
446
|
}
|
|
444
447
|
/**
|
|
@@ -521,10 +524,7 @@ export class PdfParser {
|
|
|
521
524
|
...logContext,
|
|
522
525
|
errorDetails: error.message,
|
|
523
526
|
});
|
|
524
|
-
throw
|
|
525
|
-
...context,
|
|
526
|
-
rawError: error instanceof Error ? error.stack : String(error),
|
|
527
|
-
});
|
|
527
|
+
throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to fill PDF form.', 'pdf_form_fill_failed', error);
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
530
|
/**
|
|
@@ -639,18 +639,39 @@ export class PdfParser {
|
|
|
639
639
|
requestContextService.createRequestContext({
|
|
640
640
|
operation: 'PdfParser.extractText',
|
|
641
641
|
});
|
|
642
|
+
const mergePages = options?.mergePages ?? false;
|
|
643
|
+
const isBytes = input instanceof Uint8Array || input instanceof ArrayBuffer;
|
|
644
|
+
let pdfBytes;
|
|
645
|
+
if (isBytes) {
|
|
646
|
+
assertBinaryInputBudget(input, options);
|
|
647
|
+
pdfBytes = input instanceof ArrayBuffer ? new Uint8Array(input) : input;
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
let rawBytes;
|
|
651
|
+
try {
|
|
652
|
+
rawBytes = await input.save();
|
|
653
|
+
}
|
|
654
|
+
catch (e) {
|
|
655
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
656
|
+
logger.error('Failed to extract text from PDF.', {
|
|
657
|
+
...logContext,
|
|
658
|
+
errorDetails: error.message,
|
|
659
|
+
});
|
|
660
|
+
throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to extract text from PDF.', 'pdf_text_extract_failed', error);
|
|
661
|
+
}
|
|
662
|
+
assertBinaryInputBudget(rawBytes, options);
|
|
663
|
+
pdfBytes = rawBytes;
|
|
664
|
+
}
|
|
642
665
|
try {
|
|
643
|
-
const mergePages = options?.mergePages ?? false;
|
|
644
|
-
const isBytes = input instanceof Uint8Array || input instanceof ArrayBuffer;
|
|
645
666
|
logger.debug('Extracting text from PDF using unpdf.', {
|
|
646
667
|
...logContext,
|
|
647
668
|
mergePages,
|
|
648
669
|
inputKind: isBytes ? 'bytes' : 'document',
|
|
649
670
|
});
|
|
650
|
-
const rawBytes = isBytes ? input : await input.save();
|
|
651
|
-
const pdfBytes = rawBytes instanceof ArrayBuffer ? new Uint8Array(rawBytes) : rawBytes;
|
|
652
671
|
const { getDocumentProxy, extractText: unpdfExtractText } = await getUnpdf();
|
|
653
|
-
|
|
672
|
+
// Cap decoded images at 4096×4096 pixels (pdf.js defaults to unbounded), so a
|
|
673
|
+
// crafted page cannot force a huge raster allocation during extraction.
|
|
674
|
+
const pdfProxy = await getDocumentProxy(pdfBytes, { maxImageSize: 4096 * 4096 });
|
|
654
675
|
const result = mergePages
|
|
655
676
|
? await unpdfExtractText(pdfProxy, { mergePages: true })
|
|
656
677
|
: await unpdfExtractText(pdfProxy, { mergePages: false });
|
|
@@ -672,10 +693,7 @@ export class PdfParser {
|
|
|
672
693
|
...logContext,
|
|
673
694
|
errorDetails: error.message,
|
|
674
695
|
});
|
|
675
|
-
throw
|
|
676
|
-
...context,
|
|
677
|
-
rawError: error instanceof Error ? error.stack : String(error),
|
|
678
|
-
});
|
|
696
|
+
throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to extract text from PDF.', 'pdf_text_extract_failed', error);
|
|
679
697
|
}
|
|
680
698
|
}
|
|
681
699
|
/**
|
|
@@ -715,10 +733,7 @@ export class PdfParser {
|
|
|
715
733
|
...logContext,
|
|
716
734
|
errorDetails: error.message,
|
|
717
735
|
});
|
|
718
|
-
throw
|
|
719
|
-
...context,
|
|
720
|
-
rawError: error instanceof Error ? error.stack : String(error),
|
|
721
|
-
});
|
|
736
|
+
throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to save PDF document.', 'pdf_save_failed', error);
|
|
722
737
|
}
|
|
723
738
|
}
|
|
724
739
|
}
|