opencode-rehydra-core 0.14.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.
- package/LICENSE +22 -0
- package/README.en.md +191 -0
- package/README.md +191 -0
- package/dist/browser.d.ts +54 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +74 -0
- package/dist/browser.js.map +1 -0
- package/dist/core/anonymizer.d.ts +309 -0
- package/dist/core/anonymizer.d.ts.map +1 -0
- package/dist/core/anonymizer.js +555 -0
- package/dist/core/anonymizer.js.map +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +6 -0
- package/dist/core/index.js.map +1 -0
- package/dist/crypto/index.d.ts +6 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +6 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/pii-map-crypto.d.ts +114 -0
- package/dist/crypto/pii-map-crypto.d.ts.map +1 -0
- package/dist/crypto/pii-map-crypto.js +228 -0
- package/dist/crypto/pii-map-crypto.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/ner/bio-decoder.d.ts +64 -0
- package/dist/ner/bio-decoder.d.ts.map +1 -0
- package/dist/ner/bio-decoder.js +218 -0
- package/dist/ner/bio-decoder.js.map +1 -0
- package/dist/ner/index.d.ts +12 -0
- package/dist/ner/index.d.ts.map +1 -0
- package/dist/ner/index.js +12 -0
- package/dist/ner/index.js.map +1 -0
- package/dist/ner/inference-server-client.d.ts +81 -0
- package/dist/ner/inference-server-client.d.ts.map +1 -0
- package/dist/ner/inference-server-client.js +120 -0
- package/dist/ner/inference-server-client.js.map +1 -0
- package/dist/ner/inference-server-ner-model.d.ts +43 -0
- package/dist/ner/inference-server-ner-model.d.ts.map +1 -0
- package/dist/ner/inference-server-ner-model.js +119 -0
- package/dist/ner/inference-server-ner-model.js.map +1 -0
- package/dist/ner/model-manager.d.ts +111 -0
- package/dist/ner/model-manager.d.ts.map +1 -0
- package/dist/ner/model-manager.js +334 -0
- package/dist/ner/model-manager.js.map +1 -0
- package/dist/ner/ner-model.d.ts +172 -0
- package/dist/ner/ner-model.d.ts.map +1 -0
- package/dist/ner/ner-model.js +514 -0
- package/dist/ner/ner-model.js.map +1 -0
- package/dist/ner/onnx-runtime.browser.d.ts +46 -0
- package/dist/ner/onnx-runtime.browser.d.ts.map +1 -0
- package/dist/ner/onnx-runtime.browser.js +90 -0
- package/dist/ner/onnx-runtime.browser.js.map +1 -0
- package/dist/ner/onnx-runtime.d.ts +72 -0
- package/dist/ner/onnx-runtime.d.ts.map +1 -0
- package/dist/ner/onnx-runtime.js +132 -0
- package/dist/ner/onnx-runtime.js.map +1 -0
- package/dist/ner/token-window.d.ts +19 -0
- package/dist/ner/token-window.d.ts.map +1 -0
- package/dist/ner/token-window.js +101 -0
- package/dist/ner/token-window.js.map +1 -0
- package/dist/ner/tokenizer.d.ts +142 -0
- package/dist/ner/tokenizer.d.ts.map +1 -0
- package/dist/ner/tokenizer.js +362 -0
- package/dist/ner/tokenizer.js.map +1 -0
- package/dist/opencode-plugin/git-identity.d.ts +3 -0
- package/dist/opencode-plugin/git-identity.d.ts.map +1 -0
- package/dist/opencode-plugin/git-identity.js +37 -0
- package/dist/opencode-plugin/git-identity.js.map +1 -0
- package/dist/opencode-plugin/github-username.d.ts +3 -0
- package/dist/opencode-plugin/github-username.d.ts.map +1 -0
- package/dist/opencode-plugin/github-username.js +41 -0
- package/dist/opencode-plugin/github-username.js.map +1 -0
- package/dist/opencode-plugin/identity-recognizer.d.ts +5 -0
- package/dist/opencode-plugin/identity-recognizer.d.ts.map +1 -0
- package/dist/opencode-plugin/identity-recognizer.js +21 -0
- package/dist/opencode-plugin/identity-recognizer.js.map +1 -0
- package/dist/opencode-plugin/index.d.ts +7 -0
- package/dist/opencode-plugin/index.d.ts.map +1 -0
- package/dist/opencode-plugin/index.js +6 -0
- package/dist/opencode-plugin/index.js.map +1 -0
- package/dist/opencode-plugin/plugin.d.ts +39 -0
- package/dist/opencode-plugin/plugin.d.ts.map +1 -0
- package/dist/opencode-plugin/plugin.js +294 -0
- package/dist/opencode-plugin/plugin.js.map +1 -0
- package/dist/opencode-plugin/types.d.ts +33 -0
- package/dist/opencode-plugin/types.d.ts.map +1 -0
- package/dist/opencode-plugin/types.js +5 -0
- package/dist/opencode-plugin/types.js.map +1 -0
- package/dist/opencode-plugin/v2/anon-state.d.ts +12 -0
- package/dist/opencode-plugin/v2/anon-state.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/anon-state.js +14 -0
- package/dist/opencode-plugin/v2/anon-state.js.map +1 -0
- package/dist/opencode-plugin/v2/deep-rehydrate.d.ts +13 -0
- package/dist/opencode-plugin/v2/deep-rehydrate.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/deep-rehydrate.js +33 -0
- package/dist/opencode-plugin/v2/deep-rehydrate.js.map +1 -0
- package/dist/opencode-plugin/v2/index.d.ts +17 -0
- package/dist/opencode-plugin/v2/index.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/index.js +17 -0
- package/dist/opencode-plugin/v2/index.js.map +1 -0
- package/dist/opencode-plugin/v2/logger.d.ts +24 -0
- package/dist/opencode-plugin/v2/logger.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/logger.js +73 -0
- package/dist/opencode-plugin/v2/logger.js.map +1 -0
- package/dist/opencode-plugin/v2/options.d.ts +40 -0
- package/dist/opencode-plugin/v2/options.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/options.js +132 -0
- package/dist/opencode-plugin/v2/options.js.map +1 -0
- package/dist/opencode-plugin/v2/register-hooks.d.ts +43 -0
- package/dist/opencode-plugin/v2/register-hooks.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/register-hooks.js +160 -0
- package/dist/opencode-plugin/v2/register-hooks.js.map +1 -0
- package/dist/opencode-plugin/v2/rehydrate-tail.d.ts +101 -0
- package/dist/opencode-plugin/v2/rehydrate-tail.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/rehydrate-tail.js +147 -0
- package/dist/opencode-plugin/v2/rehydrate-tail.js.map +1 -0
- package/dist/opencode-plugin/v2/response-rehydrate.d.ts +78 -0
- package/dist/opencode-plugin/v2/response-rehydrate.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/response-rehydrate.js +210 -0
- package/dist/opencode-plugin/v2/response-rehydrate.js.map +1 -0
- package/dist/opencode-plugin/v2/scrub-messages.d.ts +39 -0
- package/dist/opencode-plugin/v2/scrub-messages.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/scrub-messages.js +260 -0
- package/dist/opencode-plugin/v2/scrub-messages.js.map +1 -0
- package/dist/opencode-plugin/v2/sessions.d.ts +17 -0
- package/dist/opencode-plugin/v2/sessions.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/sessions.js +23 -0
- package/dist/opencode-plugin/v2/sessions.js.map +1 -0
- package/dist/opencode-plugin/v2/sse.d.ts +101 -0
- package/dist/opencode-plugin/v2/sse.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/sse.js +235 -0
- package/dist/opencode-plugin/v2/sse.js.map +1 -0
- package/dist/opencode-plugin/v2/types.d.ts +188 -0
- package/dist/opencode-plugin/v2/types.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/types.js +10 -0
- package/dist/opencode-plugin/v2/types.js.map +1 -0
- package/dist/opencode-plugin/vcs-command.d.ts +3 -0
- package/dist/opencode-plugin/vcs-command.d.ts.map +1 -0
- package/dist/opencode-plugin/vcs-command.js +34 -0
- package/dist/opencode-plugin/vcs-command.js.map +1 -0
- package/dist/pipeline/index.d.ts +12 -0
- package/dist/pipeline/index.d.ts.map +1 -0
- package/dist/pipeline/index.js +12 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/prenormalize.d.ts +48 -0
- package/dist/pipeline/prenormalize.d.ts.map +1 -0
- package/dist/pipeline/prenormalize.js +94 -0
- package/dist/pipeline/prenormalize.js.map +1 -0
- package/dist/pipeline/resolver.d.ts +56 -0
- package/dist/pipeline/resolver.d.ts.map +1 -0
- package/dist/pipeline/resolver.js +239 -0
- package/dist/pipeline/resolver.js.map +1 -0
- package/dist/pipeline/semantic-data-loader.d.ts +171 -0
- package/dist/pipeline/semantic-data-loader.d.ts.map +1 -0
- package/dist/pipeline/semantic-data-loader.js +677 -0
- package/dist/pipeline/semantic-data-loader.js.map +1 -0
- package/dist/pipeline/semantic-enricher.d.ts +112 -0
- package/dist/pipeline/semantic-enricher.d.ts.map +1 -0
- package/dist/pipeline/semantic-enricher.js +322 -0
- package/dist/pipeline/semantic-enricher.js.map +1 -0
- package/dist/pipeline/tagger.d.ts +121 -0
- package/dist/pipeline/tagger.d.ts.map +1 -0
- package/dist/pipeline/tagger.js +545 -0
- package/dist/pipeline/tagger.js.map +1 -0
- package/dist/pipeline/title-extractor.d.ts +79 -0
- package/dist/pipeline/title-extractor.d.ts.map +1 -0
- package/dist/pipeline/title-extractor.js +801 -0
- package/dist/pipeline/title-extractor.js.map +1 -0
- package/dist/pipeline/validator.d.ts +65 -0
- package/dist/pipeline/validator.d.ts.map +1 -0
- package/dist/pipeline/validator.js +292 -0
- package/dist/pipeline/validator.js.map +1 -0
- package/dist/proxy/index.d.ts +13 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/index.js +12 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/proxy/providers/anthropic.d.ts +28 -0
- package/dist/proxy/providers/anthropic.d.ts.map +1 -0
- package/dist/proxy/providers/anthropic.js +265 -0
- package/dist/proxy/providers/anthropic.js.map +1 -0
- package/dist/proxy/providers/index.d.ts +19 -0
- package/dist/proxy/providers/index.d.ts.map +1 -0
- package/dist/proxy/providers/index.js +41 -0
- package/dist/proxy/providers/index.js.map +1 -0
- package/dist/proxy/providers/openai.d.ts +27 -0
- package/dist/proxy/providers/openai.d.ts.map +1 -0
- package/dist/proxy/providers/openai.js +203 -0
- package/dist/proxy/providers/openai.js.map +1 -0
- package/dist/proxy/providers/streaming-tool-loop.d.ts +12 -0
- package/dist/proxy/providers/streaming-tool-loop.d.ts.map +1 -0
- package/dist/proxy/providers/streaming-tool-loop.js +223 -0
- package/dist/proxy/providers/streaming-tool-loop.js.map +1 -0
- package/dist/proxy/providers/types.d.ts +109 -0
- package/dist/proxy/providers/types.d.ts.map +1 -0
- package/dist/proxy/providers/types.js +2 -0
- package/dist/proxy/providers/types.js.map +1 -0
- package/dist/proxy/proxy-server.d.ts +61 -0
- package/dist/proxy/proxy-server.d.ts.map +1 -0
- package/dist/proxy/proxy-server.js +146 -0
- package/dist/proxy/proxy-server.js.map +1 -0
- package/dist/proxy/rehydra-fetch.d.ts +35 -0
- package/dist/proxy/rehydra-fetch.d.ts.map +1 -0
- package/dist/proxy/rehydra-fetch.js +631 -0
- package/dist/proxy/rehydra-fetch.js.map +1 -0
- package/dist/proxy/rehydra-proxy.d.ts +40 -0
- package/dist/proxy/rehydra-proxy.d.ts.map +1 -0
- package/dist/proxy/rehydra-proxy.js +150 -0
- package/dist/proxy/rehydra-proxy.js.map +1 -0
- package/dist/proxy/sse-parser.d.ts +59 -0
- package/dist/proxy/sse-parser.d.ts.map +1 -0
- package/dist/proxy/sse-parser.js +112 -0
- package/dist/proxy/sse-parser.js.map +1 -0
- package/dist/proxy/system-instruction.d.ts +19 -0
- package/dist/proxy/system-instruction.d.ts.map +1 -0
- package/dist/proxy/system-instruction.js +33 -0
- package/dist/proxy/system-instruction.js.map +1 -0
- package/dist/proxy/tool-loop-stream.d.ts +7 -0
- package/dist/proxy/tool-loop-stream.d.ts.map +1 -0
- package/dist/proxy/tool-loop-stream.js +65 -0
- package/dist/proxy/tool-loop-stream.js.map +1 -0
- package/dist/proxy/types.d.ts +138 -0
- package/dist/proxy/types.d.ts.map +1 -0
- package/dist/proxy/types.js +5 -0
- package/dist/proxy/types.js.map +1 -0
- package/dist/proxy/wrap-client.d.ts +47 -0
- package/dist/proxy/wrap-client.d.ts.map +1 -0
- package/dist/proxy/wrap-client.js +70 -0
- package/dist/proxy/wrap-client.js.map +1 -0
- package/dist/recognizers/address.d.ts +2 -0
- package/dist/recognizers/address.d.ts.map +1 -0
- package/dist/recognizers/address.js +23 -0
- package/dist/recognizers/address.js.map +1 -0
- package/dist/recognizers/base.d.ts +78 -0
- package/dist/recognizers/base.d.ts.map +1 -0
- package/dist/recognizers/base.js +100 -0
- package/dist/recognizers/base.js.map +1 -0
- package/dist/recognizers/bic-swift.d.ts +10 -0
- package/dist/recognizers/bic-swift.d.ts.map +1 -0
- package/dist/recognizers/bic-swift.js +107 -0
- package/dist/recognizers/bic-swift.js.map +1 -0
- package/dist/recognizers/credit-card.d.ts +32 -0
- package/dist/recognizers/credit-card.d.ts.map +1 -0
- package/dist/recognizers/credit-card.js +160 -0
- package/dist/recognizers/credit-card.js.map +1 -0
- package/dist/recognizers/custom-id.d.ts +28 -0
- package/dist/recognizers/custom-id.d.ts.map +1 -0
- package/dist/recognizers/custom-id.js +116 -0
- package/dist/recognizers/custom-id.js.map +1 -0
- package/dist/recognizers/date.d.ts +10 -0
- package/dist/recognizers/date.d.ts.map +1 -0
- package/dist/recognizers/date.js +228 -0
- package/dist/recognizers/date.js.map +1 -0
- package/dist/recognizers/email.d.ts +10 -0
- package/dist/recognizers/email.d.ts.map +1 -0
- package/dist/recognizers/email.js +75 -0
- package/dist/recognizers/email.js.map +1 -0
- package/dist/recognizers/iban.d.ts +14 -0
- package/dist/recognizers/iban.d.ts.map +1 -0
- package/dist/recognizers/iban.js +67 -0
- package/dist/recognizers/iban.js.map +1 -0
- package/dist/recognizers/index.d.ts +25 -0
- package/dist/recognizers/index.d.ts.map +1 -0
- package/dist/recognizers/index.js +53 -0
- package/dist/recognizers/index.js.map +1 -0
- package/dist/recognizers/ip-address.d.ts +14 -0
- package/dist/recognizers/ip-address.d.ts.map +1 -0
- package/dist/recognizers/ip-address.js +183 -0
- package/dist/recognizers/ip-address.js.map +1 -0
- package/dist/recognizers/phone.d.ts +10 -0
- package/dist/recognizers/phone.d.ts.map +1 -0
- package/dist/recognizers/phone.js +145 -0
- package/dist/recognizers/phone.js.map +1 -0
- package/dist/recognizers/postal-code.d.ts +16 -0
- package/dist/recognizers/postal-code.d.ts.map +1 -0
- package/dist/recognizers/postal-code.js +42 -0
- package/dist/recognizers/postal-code.js.map +1 -0
- package/dist/recognizers/registry.d.ts +59 -0
- package/dist/recognizers/registry.d.ts.map +1 -0
- package/dist/recognizers/registry.js +113 -0
- package/dist/recognizers/registry.js.map +1 -0
- package/dist/recognizers/secrets/api-key.d.ts +6 -0
- package/dist/recognizers/secrets/api-key.d.ts.map +1 -0
- package/dist/recognizers/secrets/api-key.js +40 -0
- package/dist/recognizers/secrets/api-key.js.map +1 -0
- package/dist/recognizers/secrets/aws-credentials.d.ts +7 -0
- package/dist/recognizers/secrets/aws-credentials.d.ts.map +1 -0
- package/dist/recognizers/secrets/aws-credentials.js +68 -0
- package/dist/recognizers/secrets/aws-credentials.js.map +1 -0
- package/dist/recognizers/secrets/config-secret.d.ts +8 -0
- package/dist/recognizers/secrets/config-secret.d.ts.map +1 -0
- package/dist/recognizers/secrets/config-secret.js +59 -0
- package/dist/recognizers/secrets/config-secret.js.map +1 -0
- package/dist/recognizers/secrets/connection-string.d.ts +6 -0
- package/dist/recognizers/secrets/connection-string.d.ts.map +1 -0
- package/dist/recognizers/secrets/connection-string.js +40 -0
- package/dist/recognizers/secrets/connection-string.js.map +1 -0
- package/dist/recognizers/secrets/env-var.d.ts +8 -0
- package/dist/recognizers/secrets/env-var.d.ts.map +1 -0
- package/dist/recognizers/secrets/env-var.js +54 -0
- package/dist/recognizers/secrets/env-var.js.map +1 -0
- package/dist/recognizers/secrets/index.d.ts +22 -0
- package/dist/recognizers/secrets/index.d.ts.map +1 -0
- package/dist/recognizers/secrets/index.js +41 -0
- package/dist/recognizers/secrets/index.js.map +1 -0
- package/dist/recognizers/secrets/jwt.d.ts +6 -0
- package/dist/recognizers/secrets/jwt.d.ts.map +1 -0
- package/dist/recognizers/secrets/jwt.js +47 -0
- package/dist/recognizers/secrets/jwt.js.map +1 -0
- package/dist/recognizers/secrets/key-patterns.d.ts +10 -0
- package/dist/recognizers/secrets/key-patterns.d.ts.map +1 -0
- package/dist/recognizers/secrets/key-patterns.js +15 -0
- package/dist/recognizers/secrets/key-patterns.js.map +1 -0
- package/dist/recognizers/secrets/literal-value.d.ts +10 -0
- package/dist/recognizers/secrets/literal-value.d.ts.map +1 -0
- package/dist/recognizers/secrets/literal-value.js +48 -0
- package/dist/recognizers/secrets/literal-value.js.map +1 -0
- package/dist/recognizers/secrets/private-key.d.ts +6 -0
- package/dist/recognizers/secrets/private-key.d.ts.map +1 -0
- package/dist/recognizers/secrets/private-key.js +16 -0
- package/dist/recognizers/secrets/private-key.js.map +1 -0
- package/dist/recognizers/url.d.ts +14 -0
- package/dist/recognizers/url.d.ts.map +1 -0
- package/dist/recognizers/url.js +121 -0
- package/dist/recognizers/url.js.map +1 -0
- package/dist/storage/browser.d.ts +13 -0
- package/dist/storage/browser.d.ts.map +1 -0
- package/dist/storage/browser.js +13 -0
- package/dist/storage/browser.js.map +1 -0
- package/dist/storage/in-memory.d.ts +60 -0
- package/dist/storage/in-memory.d.ts.map +1 -0
- package/dist/storage/in-memory.js +108 -0
- package/dist/storage/in-memory.js.map +1 -0
- package/dist/storage/index.d.ts +11 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +11 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/indexeddb.d.ts +69 -0
- package/dist/storage/indexeddb.d.ts.map +1 -0
- package/dist/storage/indexeddb.js +274 -0
- package/dist/storage/indexeddb.js.map +1 -0
- package/dist/storage/session-base.d.ts +34 -0
- package/dist/storage/session-base.d.ts.map +1 -0
- package/dist/storage/session-base.js +122 -0
- package/dist/storage/session-base.js.map +1 -0
- package/dist/storage/session.d.ts +19 -0
- package/dist/storage/session.d.ts.map +1 -0
- package/dist/storage/session.js +31 -0
- package/dist/storage/session.js.map +1 -0
- package/dist/storage/sqlite.d.ts +80 -0
- package/dist/storage/sqlite.d.ts.map +1 -0
- package/dist/storage/sqlite.js +255 -0
- package/dist/storage/sqlite.js.map +1 -0
- package/dist/storage/types.d.ts +208 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +6 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/streaming/anonymizer-stream.d.ts +63 -0
- package/dist/streaming/anonymizer-stream.d.ts.map +1 -0
- package/dist/streaming/anonymizer-stream.js +184 -0
- package/dist/streaming/anonymizer-stream.js.map +1 -0
- package/dist/streaming/index.d.ts +9 -0
- package/dist/streaming/index.d.ts.map +1 -0
- package/dist/streaming/index.js +8 -0
- package/dist/streaming/index.js.map +1 -0
- package/dist/streaming/sentence-buffer.d.ts +78 -0
- package/dist/streaming/sentence-buffer.d.ts.map +1 -0
- package/dist/streaming/sentence-buffer.js +239 -0
- package/dist/streaming/sentence-buffer.js.map +1 -0
- package/dist/streaming/stream-factory.d.ts +38 -0
- package/dist/streaming/stream-factory.d.ts.map +1 -0
- package/dist/streaming/stream-factory.js +69 -0
- package/dist/streaming/stream-factory.js.map +1 -0
- package/dist/streaming/types.d.ts +121 -0
- package/dist/streaming/types.d.ts.map +1 -0
- package/dist/streaming/types.js +5 -0
- package/dist/streaming/types.js.map +1 -0
- package/dist/types/index.d.ts +269 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +95 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/pii-types.d.ts +64 -0
- package/dist/types/pii-types.d.ts.map +1 -0
- package/dist/types/pii-types.js +153 -0
- package/dist/types/pii-types.js.map +1 -0
- package/dist/utils/iban-checksum.d.ts +23 -0
- package/dist/utils/iban-checksum.d.ts.map +1 -0
- package/dist/utils/iban-checksum.js +106 -0
- package/dist/utils/iban-checksum.js.map +1 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/json-walk.d.ts +21 -0
- package/dist/utils/json-walk.d.ts.map +1 -0
- package/dist/utils/json-walk.js +44 -0
- package/dist/utils/json-walk.js.map +1 -0
- package/dist/utils/luhn.d.ts +17 -0
- package/dist/utils/luhn.d.ts.map +1 -0
- package/dist/utils/luhn.js +55 -0
- package/dist/utils/luhn.js.map +1 -0
- package/dist/utils/offsets.d.ts +86 -0
- package/dist/utils/offsets.d.ts.map +1 -0
- package/dist/utils/offsets.js +124 -0
- package/dist/utils/offsets.js.map +1 -0
- package/dist/utils/path.d.ts +34 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +96 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/regex.d.ts +11 -0
- package/dist/utils/regex.d.ts.map +1 -0
- package/dist/utils/regex.js +14 -0
- package/dist/utils/regex.js.map +1 -0
- package/dist/utils/storage-browser.d.ts +51 -0
- package/dist/utils/storage-browser.d.ts.map +1 -0
- package/dist/utils/storage-browser.js +381 -0
- package/dist/utils/storage-browser.js.map +1 -0
- package/dist/utils/storage-node.d.ts +51 -0
- package/dist/utils/storage-node.d.ts.map +1 -0
- package/dist/utils/storage-node.js +153 -0
- package/dist/utils/storage-node.js.map +1 -0
- package/dist/utils/storage.browser.d.ts +75 -0
- package/dist/utils/storage.browser.d.ts.map +1 -0
- package/dist/utils/storage.browser.js +69 -0
- package/dist/utils/storage.browser.js.map +1 -0
- package/dist/utils/storage.d.ts +73 -0
- package/dist/utils/storage.d.ts.map +1 -0
- package/dist/utils/storage.js +69 -0
- package/dist/utils/storage.js.map +1 -0
- package/package.json +148 -0
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replacement Tagger
|
|
3
|
+
* Replaces PII spans with placeholder tags and builds the PII map
|
|
4
|
+
*/
|
|
5
|
+
import { PIIType, DEFAULT_TAG_FORMAT, } from "../types/index.js";
|
|
6
|
+
import { sortSpansByPosition } from "../utils/offsets.js";
|
|
7
|
+
import { escapeRegExp } from "../utils/regex.js";
|
|
8
|
+
/**
|
|
9
|
+
* Character class for tag IDs.
|
|
10
|
+
*
|
|
11
|
+
* Lowercase alphanumerics only: decimal digits keep counter-assigned IDs
|
|
12
|
+
* working unchanged, while letters give callers enough space to seed
|
|
13
|
+
* value-derived IDs without relying on long decimal strings. Uppercase is
|
|
14
|
+
* excluded so a PII map key `${TYPE}_${id}` stays unambiguous — types are
|
|
15
|
+
* `[A-Z_]+` and may themselves contain underscores.
|
|
16
|
+
*/
|
|
17
|
+
const ID_CHARS = "[0-9a-z]+";
|
|
18
|
+
/**
|
|
19
|
+
* Converts a raw id attribute value into a {@link TagId}.
|
|
20
|
+
* Decimal-only IDs become numbers (preserving the existing numeric API);
|
|
21
|
+
* everything else is folded to a lowercase string.
|
|
22
|
+
*/
|
|
23
|
+
function parseTagId(raw) {
|
|
24
|
+
return /^[0-9]+$/.test(raw) ? parseInt(raw, 10) : raw.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generates a PII placeholder tag
|
|
28
|
+
* Format depends on TagFormat configuration:
|
|
29
|
+
* - Default: <PII type="TYPE" id="N"/>
|
|
30
|
+
* - Custom: [[PII type="TYPE" id="N"]]
|
|
31
|
+
*
|
|
32
|
+
* Semantic attributes (gender, scope) are included when provided and not 'unknown'
|
|
33
|
+
*/
|
|
34
|
+
export function generateTag(type, id, semantic, tagFormat = DEFAULT_TAG_FORMAT) {
|
|
35
|
+
const keyword = tagFormat.keyword ?? "PII";
|
|
36
|
+
let attrs = `type="${type}"`;
|
|
37
|
+
// Add semantic attributes if present and meaningful
|
|
38
|
+
if (semantic?.gender && semantic.gender !== "unknown") {
|
|
39
|
+
attrs += ` gender="${semantic.gender}"`;
|
|
40
|
+
}
|
|
41
|
+
if (semantic?.scope && semantic.scope !== "unknown") {
|
|
42
|
+
attrs += ` scope="${semantic.scope}"`;
|
|
43
|
+
}
|
|
44
|
+
attrs += ` id="${id}"`;
|
|
45
|
+
return `${tagFormat.open}${keyword} ${attrs}${tagFormat.close}`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parses a PII tag to extract type, id, and semantic attributes
|
|
49
|
+
* Returns null if not a valid tag
|
|
50
|
+
*
|
|
51
|
+
* Supports formats (with configurable delimiters):
|
|
52
|
+
* - <PII type="TYPE" id="N"/> (default)
|
|
53
|
+
* - [[PII type="TYPE" id="N"]] (custom)
|
|
54
|
+
* - Plus optional gender/scope attributes
|
|
55
|
+
*/
|
|
56
|
+
export function parseTag(tag, tagFormat = DEFAULT_TAG_FORMAT) {
|
|
57
|
+
const keyword = tagFormat.keyword ?? "PII";
|
|
58
|
+
const open = escapeRegExp(tagFormat.open);
|
|
59
|
+
const close = escapeRegExp(tagFormat.close);
|
|
60
|
+
// Build regex dynamically from tag format
|
|
61
|
+
const match = tag.match(new RegExp(`^${open}${escapeRegExp(keyword)}\\s+type="([A-Z_]+)"(?:\\s+gender="(\\w+)")?(?:\\s+scope="([\\w-]+)")?\\s+id="(${ID_CHARS})"\\s*${close}$`));
|
|
62
|
+
if (match === null) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const [, typeStr, genderStr, scopeStr, idStr] = match;
|
|
66
|
+
if (typeStr === undefined || idStr === undefined) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
// Allow any [A-Z_]+ type string — custom recognizers (createCustomIdRecognizer)
|
|
70
|
+
// may emit types that are not members of the PIIType enum. Downstream code
|
|
71
|
+
// treats `type` as an opaque string when building PII map keys.
|
|
72
|
+
const type = typeStr;
|
|
73
|
+
const id = parseTagId(idStr);
|
|
74
|
+
// Build semantic attributes if present
|
|
75
|
+
let semantic;
|
|
76
|
+
if ((genderStr !== undefined && genderStr !== "") ||
|
|
77
|
+
(scopeStr !== undefined && scopeStr !== "")) {
|
|
78
|
+
semantic = {};
|
|
79
|
+
if (genderStr !== undefined &&
|
|
80
|
+
genderStr !== "" &&
|
|
81
|
+
["male", "female", "neutral", "unknown"].includes(genderStr)) {
|
|
82
|
+
semantic.gender = genderStr;
|
|
83
|
+
}
|
|
84
|
+
if (scopeStr !== undefined &&
|
|
85
|
+
scopeStr !== "" &&
|
|
86
|
+
["city", "country", "region", "macro-region", "unknown"].includes(scopeStr)) {
|
|
87
|
+
semantic.scope = scopeStr;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { type, id, semantic };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Creates a key for the PII map
|
|
94
|
+
*/
|
|
95
|
+
export function createPIIMapKey(type, id) {
|
|
96
|
+
return `${type}_${id}`;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parses a PII map key to extract type and id
|
|
100
|
+
* @param key - Key in format "TYPE_ID" (e.g., "PERSON_1")
|
|
101
|
+
* @returns Parsed type and id, or null if invalid
|
|
102
|
+
*/
|
|
103
|
+
function parsePIIMapKey(key) {
|
|
104
|
+
const match = key.match(new RegExp(`^([A-Z_]+)_(${ID_CHARS})$`));
|
|
105
|
+
if (!match || match[1] === undefined || match[2] === undefined) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
// Allow any [A-Z_]+ type — matches what parseTag accepts, so custom-type
|
|
109
|
+
// entries survive `buildExistingEntityLookup` and session-level ID reuse.
|
|
110
|
+
const type = match[1];
|
|
111
|
+
const id = parseTagId(match[2]);
|
|
112
|
+
return { type, id };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Builds a reverse lookup and max ID from an existing PII map
|
|
116
|
+
* @param existingPiiMap - Existing PII map (key → value)
|
|
117
|
+
* @returns Reverse lookup (type:value → id) and global max numeric ID
|
|
118
|
+
*/
|
|
119
|
+
function buildExistingEntityLookup(existingPiiMap) {
|
|
120
|
+
const reverseLookup = new Map(); // "TYPE:value" → id
|
|
121
|
+
let maxId = 0;
|
|
122
|
+
for (const [key, value] of existingPiiMap) {
|
|
123
|
+
const parsed = parsePIIMapKey(key);
|
|
124
|
+
if (parsed !== null) {
|
|
125
|
+
// Build reverse lookup: "PERSON:Tom" → 1
|
|
126
|
+
const lookupKey = `${parsed.type}:${value}`;
|
|
127
|
+
reverseLookup.set(lookupKey, parsed.id);
|
|
128
|
+
// Track global max ID. Only numeric IDs feed the counter — an
|
|
129
|
+
// alphanumeric ID has no successor, so it must not affect `nextId`.
|
|
130
|
+
if (typeof parsed.id === "number" && parsed.id > maxId) {
|
|
131
|
+
maxId = parsed.id;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { reverseLookup, maxId };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Tags PII spans in text and builds the PII map
|
|
139
|
+
* @param text - Input text to tag
|
|
140
|
+
* @param matches - Detected PII spans
|
|
141
|
+
* @param policy - Anonymization policy
|
|
142
|
+
* @param existingPiiMap - Optional existing PII map for session-level ID reuse
|
|
143
|
+
* @param tagFormat - Tag format configuration (defaults to XML-style)
|
|
144
|
+
*/
|
|
145
|
+
export function tagEntities(text, matches, policy, existingPiiMap, tagFormat = DEFAULT_TAG_FORMAT) {
|
|
146
|
+
if (matches.length === 0) {
|
|
147
|
+
return {
|
|
148
|
+
anonymizedText: text,
|
|
149
|
+
entities: [],
|
|
150
|
+
piiMap: new Map(),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
// Sort by start position ascending for ID assignment
|
|
154
|
+
const sortedAscending = sortSpansByPosition(matches);
|
|
155
|
+
// Build lookup from existing PII map (if provided)
|
|
156
|
+
const { reverseLookup, maxId } = existingPiiMap
|
|
157
|
+
? buildExistingEntityLookup(existingPiiMap)
|
|
158
|
+
: { reverseLookup: new Map(), maxId: 0 };
|
|
159
|
+
// Assign IDs
|
|
160
|
+
const entitiesWithIds = [];
|
|
161
|
+
// Global ID counter (starts from max existing + 1)
|
|
162
|
+
let nextId = maxId + 1;
|
|
163
|
+
// Track seen text for ID reuse within this call (if enabled)
|
|
164
|
+
const seenText = new Map(); // "type:text" -> id
|
|
165
|
+
for (const match of sortedAscending) {
|
|
166
|
+
let id;
|
|
167
|
+
const lookupKey = `${match.type}:${match.text}`;
|
|
168
|
+
// First, check if this value exists in the existing PII map (session-level reuse)
|
|
169
|
+
const existingId = reverseLookup.get(lookupKey);
|
|
170
|
+
if (existingId !== undefined) {
|
|
171
|
+
id = existingId;
|
|
172
|
+
// Also add to seenText so repeated occurrences in this call use the same ID
|
|
173
|
+
seenText.set(lookupKey, id);
|
|
174
|
+
}
|
|
175
|
+
else if (policy.reuseIdsForRepeatedPII) {
|
|
176
|
+
// Check if we've seen this value earlier in this call
|
|
177
|
+
const seenId = seenText.get(lookupKey);
|
|
178
|
+
if (seenId !== undefined) {
|
|
179
|
+
id = seenId;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
id = nextId++;
|
|
183
|
+
seenText.set(lookupKey, id);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
id = nextId++;
|
|
188
|
+
}
|
|
189
|
+
entitiesWithIds.push({ ...match, id });
|
|
190
|
+
}
|
|
191
|
+
// Build PII map
|
|
192
|
+
const piiMap = new Map();
|
|
193
|
+
for (const entity of entitiesWithIds) {
|
|
194
|
+
const key = createPIIMapKey(entity.type, entity.id);
|
|
195
|
+
piiMap.set(key, entity.text);
|
|
196
|
+
}
|
|
197
|
+
// Sort by start position descending for replacement
|
|
198
|
+
// (replacing from end to start preserves earlier offsets)
|
|
199
|
+
const sortedDescending = [...entitiesWithIds].sort((a, b) => b.start - a.start);
|
|
200
|
+
// Perform replacements
|
|
201
|
+
let anonymizedText = text;
|
|
202
|
+
for (const entity of sortedDescending) {
|
|
203
|
+
const tag = generateTag(entity.type, entity.id, entity.semantic, tagFormat);
|
|
204
|
+
anonymizedText =
|
|
205
|
+
anonymizedText.slice(0, entity.start) +
|
|
206
|
+
tag +
|
|
207
|
+
anonymizedText.slice(entity.end);
|
|
208
|
+
}
|
|
209
|
+
// Build final entities list (sorted by position)
|
|
210
|
+
const entities = entitiesWithIds.map((e) => ({
|
|
211
|
+
type: e.type,
|
|
212
|
+
id: e.id,
|
|
213
|
+
start: e.start,
|
|
214
|
+
end: e.end,
|
|
215
|
+
confidence: e.confidence,
|
|
216
|
+
source: e.source,
|
|
217
|
+
original: e.text,
|
|
218
|
+
semantic: e.semantic,
|
|
219
|
+
}));
|
|
220
|
+
return {
|
|
221
|
+
anonymizedText,
|
|
222
|
+
entities: sortSpansByPosition(entities),
|
|
223
|
+
piiMap,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Validates that a tag is well-formed
|
|
228
|
+
*/
|
|
229
|
+
export function isValidTag(tag, tagFormat = DEFAULT_TAG_FORMAT) {
|
|
230
|
+
return parseTag(tag, tagFormat) !== null;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Quote characters that might appear after translation
|
|
234
|
+
* Includes: standard quotes, smart quotes, German quotes, French quotes, etc.
|
|
235
|
+
*
|
|
236
|
+
* Unicode references:
|
|
237
|
+
* - \u0022 (") Standard double quote
|
|
238
|
+
* - \u0027 (') Standard single quote
|
|
239
|
+
* - \u0060 (`) Backtick
|
|
240
|
+
* - \u00AB («) Left guillemet
|
|
241
|
+
* - \u00BB (») Right guillemet
|
|
242
|
+
* - \u2018 (') Left single curly quote
|
|
243
|
+
* - \u2019 (') Right single curly quote
|
|
244
|
+
* - \u201A (‚) Single low-9 quote
|
|
245
|
+
* - \u201C (") Left double curly quote
|
|
246
|
+
* - \u201D (") Right double curly quote
|
|
247
|
+
* - \u201E („) Double low-9 quote (German)
|
|
248
|
+
*/
|
|
249
|
+
const QUOTE_CHARS = "(?:\\\\\"|[\"'`\u00AB\u00BB\u2018\u2019\u201A\u201C\u201D\u201E])";
|
|
250
|
+
/**
|
|
251
|
+
* Whitespace pattern including various unicode spaces
|
|
252
|
+
*/
|
|
253
|
+
const FLEXIBLE_WS = `[\\s\\u00A0\\u2000-\\u200B]*`;
|
|
254
|
+
const FLEXIBLE_WS_REQUIRED = `[\\s\\u00A0\\u2000-\\u200B]+`;
|
|
255
|
+
/**
|
|
256
|
+
* Builds the opening bracket pattern for fuzzy matching.
|
|
257
|
+
* For XML-style delimiters, also matches HTML-encoded variants (< / >).
|
|
258
|
+
* For custom delimiters, matches the literal (escaped) delimiter with flexible internal whitespace.
|
|
259
|
+
*/
|
|
260
|
+
function buildOpenBracketPattern(tagFormat) {
|
|
261
|
+
const open = tagFormat.open;
|
|
262
|
+
if (open === "<") {
|
|
263
|
+
return `(?:<|<)`;
|
|
264
|
+
}
|
|
265
|
+
// For multi-character delimiters, allow flexible whitespace between characters
|
|
266
|
+
// e.g., "[[" → "\[[\s]*\["
|
|
267
|
+
if (open.length > 1) {
|
|
268
|
+
return open
|
|
269
|
+
.split("")
|
|
270
|
+
.map((ch) => escapeRegExp(ch))
|
|
271
|
+
.join(FLEXIBLE_WS);
|
|
272
|
+
}
|
|
273
|
+
return escapeRegExp(open);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Builds the closing bracket/self-closing pattern for fuzzy matching.
|
|
277
|
+
* For XML-style "/>", handles various mangled forms (/>, / >, >, etc.).
|
|
278
|
+
* For custom delimiters, matches the literal delimiter with flexible internal whitespace.
|
|
279
|
+
*/
|
|
280
|
+
function buildClosingPattern(tagFormat) {
|
|
281
|
+
const close = tagFormat.close;
|
|
282
|
+
if (close === "/>") {
|
|
283
|
+
// XML self-closing: />, / >, >, />, >, or nothing if already closed inside quotes
|
|
284
|
+
const CLOSE_BRACKET = `(?:>|>)`;
|
|
285
|
+
return `(?:${FLEXIBLE_WS}(?:\\/(?:${FLEXIBLE_WS}${CLOSE_BRACKET})?|${CLOSE_BRACKET}))?`;
|
|
286
|
+
}
|
|
287
|
+
// For custom close delimiters, allow flexible whitespace between characters
|
|
288
|
+
if (close.length > 1) {
|
|
289
|
+
const pattern = close
|
|
290
|
+
.split("")
|
|
291
|
+
.map((ch) => escapeRegExp(ch))
|
|
292
|
+
.join(FLEXIBLE_WS);
|
|
293
|
+
return `${FLEXIBLE_WS}${pattern}`;
|
|
294
|
+
}
|
|
295
|
+
return `${FLEXIBLE_WS}${escapeRegExp(close)}`;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Builds the malformed id-close pattern for fuzzy matching.
|
|
299
|
+
* For XML-style tags, handles cases where /> got placed inside the id quotes (e.g., id="7/>").
|
|
300
|
+
* For custom formats, handles the close delimiter leaking into the id value.
|
|
301
|
+
*/
|
|
302
|
+
function buildIdCloseLeakPattern(tagFormat) {
|
|
303
|
+
const close = tagFormat.close;
|
|
304
|
+
if (close === "/>") {
|
|
305
|
+
return `(?:\\/?(?:>|>)?)?`;
|
|
306
|
+
}
|
|
307
|
+
// For custom delimiters, allow individual close-delimiter characters to
|
|
308
|
+
// partially leak into the id value (e.g., id="7]" for close="]]"),
|
|
309
|
+
// but not the full delimiter which would consume a valid closing.
|
|
310
|
+
if (close.length > 1) {
|
|
311
|
+
const partial = close
|
|
312
|
+
.slice(0, -1)
|
|
313
|
+
.split("")
|
|
314
|
+
.map((ch) => `${escapeRegExp(ch)}?`)
|
|
315
|
+
.join("");
|
|
316
|
+
return `(?:${partial})?`;
|
|
317
|
+
}
|
|
318
|
+
return "";
|
|
319
|
+
}
|
|
320
|
+
// Cache compiled fuzzy patterns keyed by "open\0close\0keyword"
|
|
321
|
+
const fuzzyPatternCache = new Map();
|
|
322
|
+
function fuzzyPatternCacheKey(tagFormat) {
|
|
323
|
+
return `${tagFormat.open}\0${tagFormat.close}\0${tagFormat.keyword ?? "PII"}`;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Builds patterns for fuzzy PII tag matching
|
|
327
|
+
* Handles various translation artifacts and optional semantic attributes
|
|
328
|
+
*
|
|
329
|
+
* For XML-style tags, also handles HTML-encoded brackets (< / >).
|
|
330
|
+
* For custom formats, handles flexible whitespace within multi-character delimiters.
|
|
331
|
+
*
|
|
332
|
+
* Results are cached per unique TagFormat configuration.
|
|
333
|
+
*/
|
|
334
|
+
function buildFuzzyTagPatterns(tagFormat = DEFAULT_TAG_FORMAT) {
|
|
335
|
+
const cacheKey = fuzzyPatternCacheKey(tagFormat);
|
|
336
|
+
const cached = fuzzyPatternCache.get(cacheKey);
|
|
337
|
+
if (cached !== undefined)
|
|
338
|
+
return cached;
|
|
339
|
+
const keyword = tagFormat.keyword ?? "PII";
|
|
340
|
+
const openPattern = buildOpenBracketPattern(tagFormat);
|
|
341
|
+
const closingPattern = buildClosingPattern(tagFormat);
|
|
342
|
+
const idCloseLeak = buildIdCloseLeakPattern(tagFormat);
|
|
343
|
+
// Pattern for type attribute: type = "VALUE" (flexible spacing and quotes)
|
|
344
|
+
const typeAttr = `type${FLEXIBLE_WS}=${FLEXIBLE_WS}${QUOTE_CHARS}([A-Z_]+)${QUOTE_CHARS}`;
|
|
345
|
+
// Pattern for id attribute: id = "VALUE" (flexible spacing and quotes)
|
|
346
|
+
// Also handles malformed cases where close delimiter got placed inside the quotes
|
|
347
|
+
const idAttr = `id${FLEXIBLE_WS}=${FLEXIBLE_WS}${QUOTE_CHARS}(${ID_CHARS})${idCloseLeak}${QUOTE_CHARS}`;
|
|
348
|
+
// Optional gender attribute
|
|
349
|
+
const genderAttr = `(?:${FLEXIBLE_WS}gender${FLEXIBLE_WS}=${FLEXIBLE_WS}${QUOTE_CHARS}(\\w+)${QUOTE_CHARS})?`;
|
|
350
|
+
// Optional scope attribute
|
|
351
|
+
const scopeAttr = `(?:${FLEXIBLE_WS}scope${FLEXIBLE_WS}=${FLEXIBLE_WS}${QUOTE_CHARS}([\\w-]+)${QUOTE_CHARS})?`;
|
|
352
|
+
const escapedKeyword = escapeRegExp(keyword);
|
|
353
|
+
const patterns = [
|
|
354
|
+
// type first with optional gender/scope
|
|
355
|
+
// Groups: type=1, gender=2, scope=3, id=4
|
|
356
|
+
new RegExp(`${openPattern}${FLEXIBLE_WS}${escapedKeyword}${FLEXIBLE_WS_REQUIRED}${typeAttr}${genderAttr}${scopeAttr}${FLEXIBLE_WS_REQUIRED}${idAttr}${closingPattern}`, "gi"),
|
|
357
|
+
// id first
|
|
358
|
+
// Groups: id=1, type=2
|
|
359
|
+
new RegExp(`${openPattern}${FLEXIBLE_WS}${escapedKeyword}${FLEXIBLE_WS_REQUIRED}${idAttr}${FLEXIBLE_WS_REQUIRED}${typeAttr}${closingPattern}`, "gi"),
|
|
360
|
+
];
|
|
361
|
+
fuzzyPatternCache.set(cacheKey, patterns);
|
|
362
|
+
return patterns;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Extracts all PII tags from anonymized text using fuzzy matching
|
|
366
|
+
* Handles mangled tags that may occur after translation
|
|
367
|
+
*
|
|
368
|
+
* Translation can mangle tags by:
|
|
369
|
+
* - Changing quote types (" → " or „ or « etc.)
|
|
370
|
+
* - Adding/removing whitespace
|
|
371
|
+
* - Changing case (type → Type, PII → pii)
|
|
372
|
+
* - Reordering attributes (id before type)
|
|
373
|
+
* - Modifying self-closing syntax (/> → / > or >)
|
|
374
|
+
*/
|
|
375
|
+
export function extractTags(anonymizedText, tagFormat = DEFAULT_TAG_FORMAT) {
|
|
376
|
+
const tags = [];
|
|
377
|
+
const patterns = buildFuzzyTagPatterns(tagFormat);
|
|
378
|
+
// Track positions we've already matched to avoid duplicates from overlapping patterns
|
|
379
|
+
const matchedPositions = new Set();
|
|
380
|
+
for (let patternIndex = 0; patternIndex < patterns.length; patternIndex++) {
|
|
381
|
+
const pattern = patterns[patternIndex];
|
|
382
|
+
if (pattern === undefined)
|
|
383
|
+
continue;
|
|
384
|
+
let match;
|
|
385
|
+
// Reset lastIndex for each pattern
|
|
386
|
+
pattern.lastIndex = 0;
|
|
387
|
+
while ((match = pattern.exec(anonymizedText)) !== null) {
|
|
388
|
+
if (matchedPositions.has(match.index)) {
|
|
389
|
+
continue; // Skip duplicates from overlapping patterns
|
|
390
|
+
}
|
|
391
|
+
// Extract type, id, and semantic attributes based on which pattern matched
|
|
392
|
+
// Pattern 0: type first with optional gender/scope (groups: type=1, gender=2, scope=3, id=4)
|
|
393
|
+
// Pattern 1: id first (groups: id=1, type=2)
|
|
394
|
+
let typeStr;
|
|
395
|
+
let idStr;
|
|
396
|
+
let genderStr;
|
|
397
|
+
let scopeStr;
|
|
398
|
+
if (patternIndex === 0) {
|
|
399
|
+
typeStr = match[1];
|
|
400
|
+
genderStr = match[2];
|
|
401
|
+
scopeStr = match[3];
|
|
402
|
+
idStr = match[4];
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
idStr = match[1];
|
|
406
|
+
typeStr = match[2];
|
|
407
|
+
}
|
|
408
|
+
if (typeStr !== undefined && idStr !== undefined) {
|
|
409
|
+
// Accept any [A-Z_]+ type. Custom recognizers registered via
|
|
410
|
+
// createCustomIdRecognizer may emit types that are not PIIType enum
|
|
411
|
+
// members; rehydrate() must still be able to restore them.
|
|
412
|
+
const type = typeStr.toUpperCase();
|
|
413
|
+
// Fuzzy matching is case-insensitive, so fold the id back to lowercase
|
|
414
|
+
// (lossless: ids never contain uppercase).
|
|
415
|
+
const id = parseTagId(idStr);
|
|
416
|
+
// Build semantic attributes if present
|
|
417
|
+
let semantic;
|
|
418
|
+
if ((genderStr !== undefined && genderStr !== "") ||
|
|
419
|
+
(scopeStr !== undefined && scopeStr !== "")) {
|
|
420
|
+
semantic = {};
|
|
421
|
+
if (genderStr !== undefined &&
|
|
422
|
+
genderStr !== "" &&
|
|
423
|
+
["male", "female", "neutral", "unknown"].includes(genderStr.toLowerCase())) {
|
|
424
|
+
semantic.gender =
|
|
425
|
+
genderStr.toLowerCase();
|
|
426
|
+
}
|
|
427
|
+
if (scopeStr !== undefined &&
|
|
428
|
+
scopeStr !== "" &&
|
|
429
|
+
["city", "country", "region", "macro-region", "unknown"].includes(scopeStr.toLowerCase())) {
|
|
430
|
+
semantic.scope =
|
|
431
|
+
scopeStr.toLowerCase();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
tags.push({
|
|
435
|
+
type,
|
|
436
|
+
id,
|
|
437
|
+
position: match.index,
|
|
438
|
+
matchedText: match[0],
|
|
439
|
+
semantic,
|
|
440
|
+
});
|
|
441
|
+
matchedPositions.add(match.index);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
// Sort by position ascending
|
|
446
|
+
tags.sort((a, b) => a.position - b.position);
|
|
447
|
+
return tags;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Extracts tags using strict matching (original behavior)
|
|
451
|
+
* Useful when you know tags haven't been mangled
|
|
452
|
+
* Supports optional gender and scope attributes
|
|
453
|
+
*/
|
|
454
|
+
export function extractTagsStrict(anonymizedText, tagFormat = DEFAULT_TAG_FORMAT) {
|
|
455
|
+
const tags = [];
|
|
456
|
+
const keyword = tagFormat.keyword ?? "PII";
|
|
457
|
+
const open = escapeRegExp(tagFormat.open);
|
|
458
|
+
const close = escapeRegExp(tagFormat.close);
|
|
459
|
+
// Pattern matches: OPEN KEYWORD type="X" [gender="Y"] [scope="Z"] id="N" CLOSE
|
|
460
|
+
const tagPattern = new RegExp(`${open}${escapeRegExp(keyword)}\\s+type="([A-Z_]+)"(?:\\s+gender="(\\w+)")?(?:\\s+scope="([\\w-]+)")?\\s+id="(${ID_CHARS})"\\s*${close}`, "g");
|
|
461
|
+
let match;
|
|
462
|
+
while ((match = tagPattern.exec(anonymizedText)) !== null) {
|
|
463
|
+
const typeStr = match[1];
|
|
464
|
+
const genderStr = match[2];
|
|
465
|
+
const scopeStr = match[3];
|
|
466
|
+
const idStr = match[4];
|
|
467
|
+
if (typeStr !== undefined && idStr !== undefined) {
|
|
468
|
+
// Accept any [A-Z_]+ type (see extractTags for rationale).
|
|
469
|
+
const type = typeStr;
|
|
470
|
+
const id = parseTagId(idStr);
|
|
471
|
+
// Build semantic attributes if present
|
|
472
|
+
let semantic;
|
|
473
|
+
if ((genderStr !== undefined && genderStr !== "") ||
|
|
474
|
+
(scopeStr !== undefined && scopeStr !== "")) {
|
|
475
|
+
semantic = {};
|
|
476
|
+
if (genderStr !== undefined &&
|
|
477
|
+
genderStr !== "" &&
|
|
478
|
+
["male", "female", "neutral", "unknown"].includes(genderStr)) {
|
|
479
|
+
semantic.gender = genderStr;
|
|
480
|
+
}
|
|
481
|
+
if (scopeStr !== undefined &&
|
|
482
|
+
scopeStr !== "" &&
|
|
483
|
+
["city", "country", "region", "macro-region", "unknown"].includes(scopeStr)) {
|
|
484
|
+
semantic.scope = scopeStr;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
tags.push({
|
|
488
|
+
type,
|
|
489
|
+
id,
|
|
490
|
+
position: match.index,
|
|
491
|
+
matchedText: match[0],
|
|
492
|
+
semantic,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return tags;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Counts entities by type
|
|
500
|
+
*/
|
|
501
|
+
export function countEntitiesByType(entities) {
|
|
502
|
+
const counts = {};
|
|
503
|
+
// Initialize all types to 0
|
|
504
|
+
for (const type of Object.values(PIIType)) {
|
|
505
|
+
counts[type] = 0;
|
|
506
|
+
}
|
|
507
|
+
// Count entities
|
|
508
|
+
for (const entity of entities) {
|
|
509
|
+
counts[entity.type] = (counts[entity.type] ?? 0) + 1;
|
|
510
|
+
}
|
|
511
|
+
return counts;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Rehydrates anonymized text using the PII map
|
|
515
|
+
* Uses fuzzy matching to handle tags that may have been mangled by translation
|
|
516
|
+
*
|
|
517
|
+
* @param anonymizedText - Text containing PII tags (possibly mangled)
|
|
518
|
+
* @param piiMap - Map of PII keys to original values
|
|
519
|
+
* @param strict - If true, use strict matching (original behavior). Default: false
|
|
520
|
+
* @param tagFormat - Tag format configuration (defaults to XML-style)
|
|
521
|
+
* @returns Text with PII tags replaced by original values
|
|
522
|
+
*/
|
|
523
|
+
export function rehydrate(anonymizedText, piiMap, strict = false, tagFormat = DEFAULT_TAG_FORMAT) {
|
|
524
|
+
let result = anonymizedText;
|
|
525
|
+
const tags = strict
|
|
526
|
+
? extractTagsStrict(anonymizedText, tagFormat)
|
|
527
|
+
: extractTags(anonymizedText, tagFormat);
|
|
528
|
+
// Sort by position descending for replacement
|
|
529
|
+
// (replacing from end to start preserves earlier offsets)
|
|
530
|
+
tags.sort((a, b) => b.position - a.position);
|
|
531
|
+
for (const { type, id, position, matchedText } of tags) {
|
|
532
|
+
const key = createPIIMapKey(type, id);
|
|
533
|
+
const original = piiMap.get(key);
|
|
534
|
+
if (original !== undefined) {
|
|
535
|
+
// Use the actual matched text length for replacement
|
|
536
|
+
// This handles mangled tags where the length differs from the canonical form
|
|
537
|
+
result =
|
|
538
|
+
result.slice(0, position) +
|
|
539
|
+
original +
|
|
540
|
+
result.slice(position + matchedText.length);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
//# sourceMappingURL=tagger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tagger.js","sourceRoot":"","sources":["../../src/pipeline/tagger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,OAAO,EAOP,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,QAAQ,GAAG,WAAW,CAAC;AAE7B;;;;GAIG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;AACtE,CAAC;AA+BD;;;;;;;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C;IAE7C,KAAK,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC;QACvD,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEjC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,qDAAqD;YACrD,6EAA6E;YAC7E,MAAM;gBACJ,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC;oBACzB,QAAQ;oBACR,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Title Extractor
|
|
3
|
+
* Extracts and strips honorific titles/prefixes from PERSON entities
|
|
4
|
+
* so that titles remain visible in anonymized text for translation.
|
|
5
|
+
*
|
|
6
|
+
* Supported languages: ar, de, en, es, fr, it, lv, nl, pt, zh
|
|
7
|
+
*/
|
|
8
|
+
import { SpanMatch, SemanticAttributes } from "../types/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Title extraction result
|
|
11
|
+
*/
|
|
12
|
+
export interface TitleExtractionResult {
|
|
13
|
+
/** The extracted title (e.g., "Dr.", "Mr.") or undefined if no title */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** The name without the title */
|
|
16
|
+
nameWithoutTitle: string;
|
|
17
|
+
/** Character offset where the name starts (after title + space) */
|
|
18
|
+
titleLength: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Extracts a title from the beginning of a name
|
|
22
|
+
*
|
|
23
|
+
* @param name - Full name potentially starting with a title
|
|
24
|
+
* @returns Extraction result with title, remaining name, and offset
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* extractTitle("Dr. John Smith") // { title: "Dr.", nameWithoutTitle: "John Smith", titleLength: 4 }
|
|
28
|
+
* extractTitle("John Smith") // { title: undefined, nameWithoutTitle: "John Smith", titleLength: 0 }
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractTitle(name: string): TitleExtractionResult;
|
|
31
|
+
/**
|
|
32
|
+
* Extended semantic attributes including title
|
|
33
|
+
*/
|
|
34
|
+
export interface SemanticAttributesWithTitle extends SemanticAttributes {
|
|
35
|
+
/** Extracted title prefix (e.g., "Dr.", "Mrs.") */
|
|
36
|
+
title?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Processes PERSON spans to extract titles
|
|
40
|
+
* Titles are removed from the span and stored in semantic attributes
|
|
41
|
+
* The span boundaries are adjusted so the title remains visible
|
|
42
|
+
*
|
|
43
|
+
* @param spans - Array of detected PII spans
|
|
44
|
+
* @param originalText - The original text (needed to verify span boundaries)
|
|
45
|
+
* @returns Array of spans with titles extracted from PERSON entities
|
|
46
|
+
*/
|
|
47
|
+
export declare function extractTitlesFromSpans(spans: SpanMatch[], originalText: string): SpanMatch[];
|
|
48
|
+
/**
|
|
49
|
+
* Gets all supported titles for a specific language
|
|
50
|
+
*/
|
|
51
|
+
export declare function getTitlesForLanguage(langCode: "ar" | "de" | "en" | "es" | "fr" | "it" | "lv" | "nl" | "pt" | "zh"): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Gets all supported titles across all languages
|
|
54
|
+
*/
|
|
55
|
+
export declare function getAllTitles(): string[];
|
|
56
|
+
/**
|
|
57
|
+
* Checks if a string starts with a known title
|
|
58
|
+
*/
|
|
59
|
+
export declare function startsWithTitle(text: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Checks if a text consists entirely of a title (with optional punctuation)
|
|
62
|
+
*/
|
|
63
|
+
export declare function isOnlyTitle(text: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Merges adjacent PERSON spans when one is a title
|
|
66
|
+
*
|
|
67
|
+
* This fixes issues where NER models split "Mrs. Smith" into two entities:
|
|
68
|
+
* - PERSON: "Mrs" (or "Mrs.")
|
|
69
|
+
* - PERSON: "Smith"
|
|
70
|
+
*
|
|
71
|
+
* After merging: PERSON: "Mrs. Smith"
|
|
72
|
+
*
|
|
73
|
+
* @param spans - Array of detected PII spans
|
|
74
|
+
* @param originalText - The original text
|
|
75
|
+
* @param maxGap - Maximum characters between spans to consider them adjacent (default: 3)
|
|
76
|
+
* @returns Array of spans with adjacent title+name PERSON entities merged
|
|
77
|
+
*/
|
|
78
|
+
export declare function mergeAdjacentTitleSpans(spans: SpanMatch[], originalText: string, maxGap?: number): SpanMatch[];
|
|
79
|
+
//# sourceMappingURL=title-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"title-extractor.d.ts","sourceRoot":"","sources":["../../src/pipeline/title-extractor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,SAAS,EAET,kBAAkB,EAEnB,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,gBAAgB,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;CACrB;AAqjBD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,CAyBhE;AAED;;GAEG;AACH,MAAM,WAAW,2BAA4B,SAAQ,kBAAkB;IACrE,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,SAAS,EAAE,EAClB,YAAY,EAAE,MAAM,GACnB,SAAS,EAAE,CAiEb;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAC5E,MAAM,EAAE,CAcV;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,EAAE,CAEvC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGrD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CA0BjD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,EAAE,EAClB,YAAY,EAAE,MAAM,EACpB,MAAM,GAAE,MAAU,GACjB,SAAS,EAAE,CAuFb"}
|