feat: AI redaction, Instant JSON, credit tracking & enhanced document processing#12
feat: AI redaction, Instant JSON, credit tracking & enhanced document processing#12
Conversation
…k positioning - Add new 'ai_redactor' MCP tool wrapping /ai/redact endpoint - AI-powered PII detection and permanent redaction - 5-minute timeout for 60-120s AI analysis - Supports custom criteria (default: all PII) - Enable 'applyInstantJson' build action (was commented out) - PDF form filling, form field creation, annotation import - Same file reference pattern as applyXfdf - Add HTML-to-PDF layout options to FilePartSchema - Page orientation (landscape/portrait) - Page size presets (A0-A8, Letter, Legal) and custom dimensions - Margin control (top/right/bottom/left in mm) - Uncomment watermark positioning and font options - Position offsets (top/right/bottom/left) - Font customization (fontFamily, fontSize, fontStyle) - Add optional timeout parameter to callNutrientApi() - 8 new unit tests for AI redaction (51 total, all passing) - Update document_processor tool description
…sections - Add AI Redaction, Form Filling, and HTML-to-PDF sections to features table - Add detailed usage sections with example prompts - Note 60-120s latency for AI redaction - Link to Instant JSON documentation - Update example prompts to include form filling
Architecture review fixes: - Add .min(1).max(1000) validation on criteria param - Add guard: output path !== input path (corruption prevention) - Add applyInstantJson test in build pipeline (was P0 with zero tests) - Add FormData structure assertion for AI redaction - Add output===input rejection test Code review fixes: - Use ES6 shorthand for criteria in JSON.stringify - Simplify timeout spread in api.ts - Remove unused path import in ai-redact.test.ts Test count: 54 passing (was 51)
- Add SQLite-based credit usage storage (better-sqlite3 + env-paths) - Intercept x-pspdfkit-credit-usage and x-pspdfkit-remaining-credits response headers after each API call - Classify operations from endpoint and /build instructions - Add aggregator with period-based usage summaries (day/week/month/all) - Add forecaster projecting credit exhaustion with confidence levels - Register check_credits tool with balance/usage/forecast actions - 13 new tests for storage, aggregator, and forecaster
nickwinder
left a comment
There was a problem hiding this comment.
-
I don't agree with adding a local DB for credit tracking. I would opt for querying the API instead to get the most up-to-date and 100% correct credit information. https://www.nutrient.io/api/reference/public/#tag/Account/operation/get-account-info
-
We should split the addition of each feature into it's own PR to follow best development practices and make reviews easier.
-
The addition of the apply JSON action testing should follow the same pattern as the other build tests, i.e. create a build example and add it to build.tests.ts file.
-
AI redaction should support
stageandapplyoptions in the payload. Right now it takes the default which may not be desirable. https://www.nutrient.io/api/reference/public/#tag/AI/operation/ai-redact.body.data
|
Nick - Thanks for the thorough review! I've split the original PR into four focused PRs addressing your feedback:
Each PR is independent and can be reviewed/merged in any order. All tests passing. This PR can be closed once the replacements are reviewed. |
|
Closing — this has been split into focused PRs per review feedback:
|
Summary
This PR adds several major features to the Nutrient DWS MCP Server:
AI Redaction (
ai_redactortool)/ai/redactendpointForm Filling & Annotations (
applyInstantJsonaction)document_processortoolHTML-to-PDF Layout
Watermark Positioning
Credit Tracking (
check_creditstool) — NEWx-pspdfkit-credit-usage,x-pspdfkit-remaining-credits)better-sqlite3+env-paths)balance— remaining credits, daily rate, days until exhaustionusage— breakdown by operation type (day/week/month/all)forecast— projected exhaustion date with confidence level/buildinstructions and endpoint routingTesting
Commits
feat: add AI redaction tool, applyInstantJson, HTML layout & watermark positioningdocs: update README with AI redaction, form filling, and HTML layout sectionsfix: address review findings — validation, safety guards, test gapsfeat: add credit tracking with check_credits MCP toolNew Files
src/credits/storage.ts— SQLite database layersrc/credits/aggregator.ts— Usage summaries + forecastingsrc/credits/index.ts— Module exportsModified Files
src/dws/api.ts— Header interception for credit tracking + operation classificationsrc/index.ts— Newcheck_creditsandai_redactortools registeredsrc/schemas.ts— Schemas for credit tracking and AI redactionpackage.json— Addedbetter-sqlite3,env-pathsdependenciesREADME.md— Documentation for all new features