opencode-rehydar 0.14.1 → 0.14.3
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/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 +63 -0
- package/dist/opencode-plugin/v2/options.d.ts.map +1 -0
- package/dist/opencode-plugin/v2/options.js +183 -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/index.js +14 -13
- package/package.json +19 -5
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
function object(value) {
|
|
2
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
3
|
+
throw new Error('Invalid streaming response object');
|
|
4
|
+
}
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
function index(value) {
|
|
8
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0) {
|
|
9
|
+
throw new Error('Invalid streaming response index');
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function append(target, key, value) {
|
|
14
|
+
if (typeof value === 'string')
|
|
15
|
+
target[key] = String(target[key] ?? '') + value;
|
|
16
|
+
}
|
|
17
|
+
function event(data, type = 'message') {
|
|
18
|
+
return { event: type, data: JSON.stringify(data) };
|
|
19
|
+
}
|
|
20
|
+
function validateTool(id, name, args) {
|
|
21
|
+
if (typeof id !== 'string' || id === '' || typeof name !== 'string' || name === '') {
|
|
22
|
+
throw new Error('Incomplete streamed tool call');
|
|
23
|
+
}
|
|
24
|
+
object(JSON.parse(args));
|
|
25
|
+
}
|
|
26
|
+
export const openAIStreamingToolLoop = {
|
|
27
|
+
createAccumulator() {
|
|
28
|
+
const metadata = {};
|
|
29
|
+
const message = { role: 'assistant', content: '' };
|
|
30
|
+
const calls = new Map();
|
|
31
|
+
let finishReason;
|
|
32
|
+
return {
|
|
33
|
+
push(data) {
|
|
34
|
+
const chunk = object(data);
|
|
35
|
+
if (chunk.error !== undefined)
|
|
36
|
+
throw new Error('Upstream streaming error');
|
|
37
|
+
for (const key of ['id', 'model', 'created', 'system_fingerprint', 'usage']) {
|
|
38
|
+
if (chunk[key] !== undefined)
|
|
39
|
+
metadata[key] = chunk[key];
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(chunk.choices))
|
|
42
|
+
throw new Error('Missing streaming choices');
|
|
43
|
+
for (const value of chunk.choices) {
|
|
44
|
+
const choice = object(value);
|
|
45
|
+
if (index(choice.index) !== 0)
|
|
46
|
+
throw new Error('Streaming tool loops require a single completion choice');
|
|
47
|
+
const delta = object(choice.delta);
|
|
48
|
+
if (choice.finish_reason !== undefined && choice.finish_reason !== null)
|
|
49
|
+
finishReason = choice.finish_reason;
|
|
50
|
+
for (const key of ['content', 'refusal', 'reasoning_content'])
|
|
51
|
+
append(message, key, delta[key]);
|
|
52
|
+
if (Array.isArray(delta.tool_calls))
|
|
53
|
+
for (const item of delta.tool_calls) {
|
|
54
|
+
const fragment = object(item);
|
|
55
|
+
const i = index(fragment.index);
|
|
56
|
+
const call = calls.get(i) ?? { id: '', type: 'function', function: { name: '', arguments: '' } };
|
|
57
|
+
append(call, 'id', fragment.id);
|
|
58
|
+
if (fragment.function !== undefined) {
|
|
59
|
+
const fn = object(fragment.function);
|
|
60
|
+
append(call.function, 'name', fn.name);
|
|
61
|
+
append(call.function, 'arguments', fn.arguments);
|
|
62
|
+
}
|
|
63
|
+
calls.set(i, call);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
finish() {
|
|
68
|
+
if (finishReason === undefined)
|
|
69
|
+
throw new Error('Truncated streaming completion');
|
|
70
|
+
if (calls.size > 0) {
|
|
71
|
+
if (finishReason !== 'tool_calls')
|
|
72
|
+
throw new Error('Streamed tool calls did not complete');
|
|
73
|
+
const tools = [...calls].sort(([a], [b]) => a - b).map(([, call]) => call);
|
|
74
|
+
if (new Set(tools.map(call => call.id)).size !== tools.length)
|
|
75
|
+
throw new Error('Duplicate streamed tool call ID');
|
|
76
|
+
for (const call of tools)
|
|
77
|
+
validateTool(call.id, call.function.name, call.function.arguments);
|
|
78
|
+
message.tool_calls = tools;
|
|
79
|
+
}
|
|
80
|
+
return { ...metadata, object: 'chat.completion', choices: [{ index: 0, message, finish_reason: finishReason }] };
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
*encode(body) {
|
|
85
|
+
const response = object(body);
|
|
86
|
+
if (!Array.isArray(response.choices))
|
|
87
|
+
throw new Error('Missing completion choices');
|
|
88
|
+
const metadata = { ...response, object: 'chat.completion.chunk', usage: undefined };
|
|
89
|
+
for (const value of response.choices) {
|
|
90
|
+
const choice = object(value);
|
|
91
|
+
const message = object(choice.message);
|
|
92
|
+
const delta = { ...message };
|
|
93
|
+
if (Array.isArray(message.tool_calls))
|
|
94
|
+
delta.tool_calls = message.tool_calls.map((call, i) => ({ ...object(call), index: i }));
|
|
95
|
+
yield event({ ...metadata, choices: [{ index: choice.index ?? 0, delta, finish_reason: null }] });
|
|
96
|
+
yield event({ ...metadata, choices: [{ index: choice.index ?? 0, delta: {}, finish_reason: choice.finish_reason }] });
|
|
97
|
+
}
|
|
98
|
+
if (response.usage !== undefined)
|
|
99
|
+
yield event({ ...metadata, choices: [], usage: response.usage });
|
|
100
|
+
yield { event: 'message', data: '[DONE]' };
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
export const anthropicStreamingToolLoop = {
|
|
104
|
+
createAccumulator() {
|
|
105
|
+
let message;
|
|
106
|
+
const blocks = new Map();
|
|
107
|
+
const args = new Map();
|
|
108
|
+
const stoppedBlocks = new Set();
|
|
109
|
+
let stopped = false;
|
|
110
|
+
return {
|
|
111
|
+
push(data) {
|
|
112
|
+
const value = object(data);
|
|
113
|
+
if (value.type === 'error')
|
|
114
|
+
throw new Error('Upstream streaming error');
|
|
115
|
+
switch (value.type) {
|
|
116
|
+
case 'message_start':
|
|
117
|
+
if (message !== undefined)
|
|
118
|
+
throw new Error('Duplicate message start');
|
|
119
|
+
message = { ...object(value.message) };
|
|
120
|
+
break;
|
|
121
|
+
case 'content_block_start': {
|
|
122
|
+
const i = index(value.index);
|
|
123
|
+
if (blocks.has(i))
|
|
124
|
+
throw new Error('Duplicate content block');
|
|
125
|
+
blocks.set(i, { ...object(value.content_block) });
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case 'content_block_delta': {
|
|
129
|
+
const i = index(value.index);
|
|
130
|
+
const block = blocks.get(i);
|
|
131
|
+
if (block === undefined || stoppedBlocks.has(i))
|
|
132
|
+
throw new Error('Unexpected content delta');
|
|
133
|
+
const delta = object(value.delta);
|
|
134
|
+
if (delta.type === 'input_json_delta') {
|
|
135
|
+
if (typeof delta.partial_json !== 'string')
|
|
136
|
+
throw new Error('Invalid tool argument delta');
|
|
137
|
+
args.set(i, (args.get(i) ?? '') + delta.partial_json);
|
|
138
|
+
}
|
|
139
|
+
else if (delta.type === 'text_delta')
|
|
140
|
+
append(block, 'text', delta.text);
|
|
141
|
+
else if (delta.type === 'thinking_delta')
|
|
142
|
+
append(block, 'thinking', delta.thinking);
|
|
143
|
+
else if (delta.type === 'signature_delta')
|
|
144
|
+
append(block, 'signature', delta.signature);
|
|
145
|
+
else
|
|
146
|
+
throw new Error('Unsupported content delta in streaming tool loop');
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case 'content_block_stop': {
|
|
150
|
+
const i = index(value.index);
|
|
151
|
+
if (!blocks.has(i) || stoppedBlocks.has(i))
|
|
152
|
+
throw new Error('Unexpected content block stop');
|
|
153
|
+
stoppedBlocks.add(i);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case 'message_delta':
|
|
157
|
+
if (message === undefined)
|
|
158
|
+
throw new Error('Missing message start');
|
|
159
|
+
Object.assign(message, object(value.delta));
|
|
160
|
+
if (value.usage !== undefined)
|
|
161
|
+
message.usage = { ...object(message.usage ?? {}), ...object(value.usage) };
|
|
162
|
+
break;
|
|
163
|
+
case 'message_stop':
|
|
164
|
+
stopped = true;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
finish() {
|
|
169
|
+
if (message === undefined || !stopped)
|
|
170
|
+
throw new Error('Truncated streaming message');
|
|
171
|
+
const content = [...blocks].sort(([a], [b]) => a - b).map(([i, block]) => {
|
|
172
|
+
if (!stoppedBlocks.has(i))
|
|
173
|
+
throw new Error('Unfinished content block');
|
|
174
|
+
if (block.type === 'tool_use') {
|
|
175
|
+
if (message.stop_reason !== 'tool_use')
|
|
176
|
+
throw new Error('Streamed tool calls did not complete');
|
|
177
|
+
const json = args.get(i) ?? JSON.stringify(block.input ?? {});
|
|
178
|
+
validateTool(block.id, block.name, json);
|
|
179
|
+
block.input = JSON.parse(json);
|
|
180
|
+
}
|
|
181
|
+
return block;
|
|
182
|
+
});
|
|
183
|
+
const ids = content.filter(block => block.type === 'tool_use').map(block => block.id);
|
|
184
|
+
if (new Set(ids).size !== ids.length)
|
|
185
|
+
throw new Error('Duplicate streamed tool call ID');
|
|
186
|
+
return { ...message, content };
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
*encode(body) {
|
|
191
|
+
const response = object(body);
|
|
192
|
+
if (!Array.isArray(response.content))
|
|
193
|
+
throw new Error('Missing message content');
|
|
194
|
+
yield event({ type: 'message_start', message: { ...response, content: [], stop_reason: null, stop_sequence: null } }, 'message_start');
|
|
195
|
+
for (const [i, item] of response.content.entries()) {
|
|
196
|
+
const block = object(item);
|
|
197
|
+
const start = { ...block };
|
|
198
|
+
const deltas = [];
|
|
199
|
+
if (block.type === 'text') {
|
|
200
|
+
start.text = '';
|
|
201
|
+
deltas.push({ type: 'text_delta', text: block.text });
|
|
202
|
+
}
|
|
203
|
+
if (block.type === 'tool_use') {
|
|
204
|
+
start.input = {};
|
|
205
|
+
deltas.push({ type: 'input_json_delta', partial_json: JSON.stringify(block.input) });
|
|
206
|
+
}
|
|
207
|
+
if (block.type === 'thinking') {
|
|
208
|
+
start.thinking = '';
|
|
209
|
+
start.signature = '';
|
|
210
|
+
deltas.push({ type: 'thinking_delta', thinking: block.thinking });
|
|
211
|
+
if (typeof block.signature === 'string')
|
|
212
|
+
deltas.push({ type: 'signature_delta', signature: block.signature });
|
|
213
|
+
}
|
|
214
|
+
yield event({ type: 'content_block_start', index: i, content_block: start }, 'content_block_start');
|
|
215
|
+
for (const delta of deltas)
|
|
216
|
+
yield event({ type: 'content_block_delta', index: i, delta }, 'content_block_delta');
|
|
217
|
+
yield event({ type: 'content_block_stop', index: i }, 'content_block_stop');
|
|
218
|
+
}
|
|
219
|
+
yield event({ type: 'message_delta', delta: { stop_reason: response.stop_reason, stop_sequence: response.stop_sequence }, usage: response.usage ?? {} }, 'message_delta');
|
|
220
|
+
yield event({ type: 'message_stop' }, 'message_stop');
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
//# sourceMappingURL=streaming-tool-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-tool-loop.js","sourceRoot":"","sources":["../../../src/proxy/providers/streaming-tool-loop.ts"],"names":[],"mappings":"AASA,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,KAAoB,CAAC;AAC9B,CAAC;AACD,SAAS,KAAK,CAAC,KAAc;IAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC3E,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AACD,SAAS,MAAM,CAAC,MAAmB,EAAE,GAAW,EAAE,KAAc;IAC9D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC;AACjF,CAAC;AACD,SAAS,KAAK,CAAC,IAAa,EAAE,IAAI,GAAG,SAAS;IAC5C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;AACrD,CAAC;AACD,SAAS,YAAY,CAAC,EAAW,EAAE,IAAa,EAAE,IAAY;IAC5D,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,KAAK,EAAE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EAAE,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BAAE,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,qBAAqB,CAAC,CAAC;YACjH,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,oBAAoB,CAAC,CAAC;QAC9E,CAAC;QACD,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,aAAa,EAAE,QAAQ,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,IAAI,EAAE,EAAE,EAAE,eAAe,CAAC,CAAC;QAC1K,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { StreamingToolLoopAdapter } from './streaming-tool-loop.js';
|
|
2
|
+
/**
|
|
3
|
+
* LLM Content Provider Interface
|
|
4
|
+
* Abstracts LLM-specific request/response formats for the proxy middleware.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Structured tool call information extracted from a non-streaming response.
|
|
8
|
+
* Used by the tool execution loop to invoke user callbacks.
|
|
9
|
+
*/
|
|
10
|
+
export interface ToolCallInfo {
|
|
11
|
+
/** Tool call ID (e.g., "call_abc123" for OpenAI, "toolu_01A..." for Anthropic) */
|
|
12
|
+
id: string;
|
|
13
|
+
/** Function/tool name */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Raw arguments as JSON string (in anonymized form from LLM) */
|
|
16
|
+
arguments: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A tool result to be sent back to the LLM in the next round.
|
|
20
|
+
*/
|
|
21
|
+
export interface ToolResultMessage {
|
|
22
|
+
/** The tool call ID this result corresponds to */
|
|
23
|
+
toolCallId: string;
|
|
24
|
+
/** The tool result content (JSON-stringified, anonymized) */
|
|
25
|
+
content: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A tool call argument fragment from an SSE chunk.
|
|
29
|
+
* Keyed by index to support interleaved multi-tool streaming.
|
|
30
|
+
*/
|
|
31
|
+
export interface ToolCallDelta {
|
|
32
|
+
/** Numeric index identifying which tool call this fragment belongs to */
|
|
33
|
+
index: number;
|
|
34
|
+
/** The partial argument string fragment */
|
|
35
|
+
arguments: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Interface for extracting and rebuilding text content from LLM API requests/responses.
|
|
39
|
+
* Each provider handles a specific LLM API format (OpenAI, Anthropic, etc.).
|
|
40
|
+
*/
|
|
41
|
+
export interface LLMContentProvider {
|
|
42
|
+
/** Provider name (e.g., "openai", "anthropic") */
|
|
43
|
+
readonly name: string;
|
|
44
|
+
/** Optional SSE conversion for server-side tool execution loops. */
|
|
45
|
+
readonly streamingToolLoop?: StreamingToolLoopAdapter;
|
|
46
|
+
/** Detect if a request matches this provider based on URL/headers */
|
|
47
|
+
matchesRequest(url: string, headers: Headers): boolean;
|
|
48
|
+
/** Extract text strings from a request body for anonymization */
|
|
49
|
+
extractRequestText(body: unknown): string[];
|
|
50
|
+
/** Rebuild the request body with anonymized text (same order as extractRequestText) */
|
|
51
|
+
rebuildRequestBody(body: unknown, anonymizedTexts: string[]): unknown;
|
|
52
|
+
/** Extract text strings from a non-streaming response body for rehydration */
|
|
53
|
+
extractResponseText(body: unknown): string[];
|
|
54
|
+
/** Rebuild the response body with rehydrated text (same order as extractResponseText) */
|
|
55
|
+
rebuildResponseBody(body: unknown, rehydratedTexts: string[]): unknown;
|
|
56
|
+
/** Extract text delta from a parsed SSE data payload (returns null if no text content) */
|
|
57
|
+
extractSSEDelta(data: unknown): string | null;
|
|
58
|
+
/** Rebuild an SSE data payload with rehydrated text */
|
|
59
|
+
rebuildSSEDelta(data: unknown, rehydratedText: string): unknown;
|
|
60
|
+
/** Check if the request body indicates a streaming response is expected */
|
|
61
|
+
isStreamingRequest(body: unknown): boolean;
|
|
62
|
+
/** Extract tool call argument strings from a non-streaming response body for rehydration */
|
|
63
|
+
extractResponseToolCalls?(body: unknown): string[];
|
|
64
|
+
/** Rebuild the response body with rehydrated tool call arguments (same order as extractResponseToolCalls) */
|
|
65
|
+
rebuildResponseToolCalls?(body: unknown, rehydratedArgs: string[]): unknown;
|
|
66
|
+
/** Extract tool call argument deltas from a parsed SSE data payload */
|
|
67
|
+
extractSSEToolCallDeltas?(data: unknown): ToolCallDelta[] | null;
|
|
68
|
+
/** Rebuild an SSE data payload with rehydrated tool call arguments */
|
|
69
|
+
rebuildSSEToolCallDeltas?(data: unknown, rehydratedArgs: Map<number, string>): unknown;
|
|
70
|
+
/**
|
|
71
|
+
* Detect a "tool call block finished" SSE event and return its block index.
|
|
72
|
+
* Used to flush per-index tag buffers before the stop event is forwarded.
|
|
73
|
+
* Returns null if this event is not a tool call stop signal.
|
|
74
|
+
*/
|
|
75
|
+
extractSSEToolCallStop?(data: unknown): number | null;
|
|
76
|
+
/**
|
|
77
|
+
* Check if a non-streaming response body contains tool calls that need execution.
|
|
78
|
+
* Returns true if the response has tool_calls (OpenAI) or tool_use blocks (Anthropic).
|
|
79
|
+
*/
|
|
80
|
+
hasResponseToolCalls?(body: unknown): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Extract structured tool call information from a non-streaming response.
|
|
83
|
+
* Arguments are returned as raw JSON strings (in anonymized form from the LLM).
|
|
84
|
+
*/
|
|
85
|
+
extractResponseToolCallInfo?(body: unknown): ToolCallInfo[];
|
|
86
|
+
/**
|
|
87
|
+
* Extract the messages array from a request body.
|
|
88
|
+
*/
|
|
89
|
+
extractMessages?(body: unknown): unknown[];
|
|
90
|
+
/**
|
|
91
|
+
* Build the next-round request body for a tool execution loop.
|
|
92
|
+
* Appends the assistant's tool-call response and tool result messages
|
|
93
|
+
* to the current message array without re-anonymizing existing messages.
|
|
94
|
+
*
|
|
95
|
+
* @param originalBody - The original request body (used as template for non-message fields)
|
|
96
|
+
* @param currentMessages - The current (anonymized) messages array
|
|
97
|
+
* @param assistantResponse - The raw LLM response body containing tool calls
|
|
98
|
+
* @param toolResults - Tool results to append (already anonymized)
|
|
99
|
+
* @returns A new request body with updated messages and stream: false
|
|
100
|
+
*/
|
|
101
|
+
buildToolLoopBody?(originalBody: unknown, currentMessages: unknown[], assistantResponse: unknown, toolResults: ToolResultMessage[]): unknown;
|
|
102
|
+
/**
|
|
103
|
+
* Inject a system-level instruction into the request body.
|
|
104
|
+
* Used to tell the model how to handle PII placeholders in tool calls.
|
|
105
|
+
* Returns a new body with the instruction prepended to the system prompt.
|
|
106
|
+
*/
|
|
107
|
+
injectSystemInstruction?(body: unknown, instruction: string): unknown;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/proxy/providers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACzE;;;GAGG;AAEH;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,kFAAkF;IAClF,EAAE,EAAE,MAAM,CAAC;IACX,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,kDAAkD;IACl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CAAC;IAEX;;;;OAIG;IACH,sBAAsB,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;IAItD;;;OAGG;IACH,oBAAoB,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;IAE9C;;;OAGG;IACH,2BAA2B,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,EAAE,CAAC;IAE5D;;OAEG;IACH,eAAe,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC;IAE3C;;;;;;;;;;OAUG;IACH,iBAAiB,CAAC,CAChB,YAAY,EAAE,OAAO,EACrB,eAAe,EAAE,OAAO,EAAE,EAC1B,iBAAiB,EAAE,OAAO,EAC1B,WAAW,EAAE,iBAAiB,EAAE,GAC/B,OAAO,CAAC;IAEX;;;;OAIG;IACH,uBAAuB,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;CACvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/proxy/providers/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rehydra Proxy Server
|
|
3
|
+
* Standalone HTTP server that proxies LLM API requests with
|
|
4
|
+
* automatic PII anonymization and rehydration.
|
|
5
|
+
*/
|
|
6
|
+
import { type Server, type IncomingMessage, type ServerResponse } from "node:http";
|
|
7
|
+
import type { RehydraProxyConfig } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for the standalone proxy server
|
|
10
|
+
*/
|
|
11
|
+
export interface RehydraProxyServerConfig extends RehydraProxyConfig {
|
|
12
|
+
/** Port to listen on */
|
|
13
|
+
port: number;
|
|
14
|
+
/** Host to bind to (default: "127.0.0.1") */
|
|
15
|
+
host?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A running Rehydra proxy server
|
|
19
|
+
*/
|
|
20
|
+
export interface RehydraProxyServer {
|
|
21
|
+
/** The underlying HTTP server */
|
|
22
|
+
server: Server;
|
|
23
|
+
/** The port the server is listening on */
|
|
24
|
+
port: number;
|
|
25
|
+
/** The host the server is bound to */
|
|
26
|
+
host: string;
|
|
27
|
+
/** Gracefully close the server */
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates and starts a standalone HTTP proxy server that anonymizes
|
|
32
|
+
* LLM API requests and rehydrates responses.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const proxy = await createRehydraProxyServer({
|
|
37
|
+
* port: 8080,
|
|
38
|
+
* upstream: 'https://api.openai.com',
|
|
39
|
+
* keyProvider: new ConfigKeyProvider(process.env.PII_KEY!),
|
|
40
|
+
* piiStorageProvider: new SQLitePIIStorageProvider('proxy.db'),
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* console.log(`Proxy running on http://${proxy.host}:${proxy.port}`);
|
|
44
|
+
*
|
|
45
|
+
* // Point your OpenAI client at the proxy:
|
|
46
|
+
* const openai = new OpenAI({ baseURL: `http://localhost:${proxy.port}/v1` });
|
|
47
|
+
*
|
|
48
|
+
* // Stop the server
|
|
49
|
+
* await proxy.close();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function createRehydraProxyServer(config: RehydraProxyServerConfig): Promise<RehydraProxyServer>;
|
|
53
|
+
/**
|
|
54
|
+
* Convert a Node.js IncomingMessage to a Web API Request
|
|
55
|
+
*/
|
|
56
|
+
export declare function incomingMessageToRequest(req: IncomingMessage, host: string, port: number): Request;
|
|
57
|
+
/**
|
|
58
|
+
* Write a Web API Response to a Node.js ServerResponse
|
|
59
|
+
*/
|
|
60
|
+
export declare function writeResponse(res: ServerResponse, webResponse: Response): Promise<void>;
|
|
61
|
+
//# sourceMappingURL=proxy-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-server.d.ts","sourceRoot":"","sources":["../../src/proxy/proxy-server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAgB,KAAK,MAAM,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,kBAAkB;IAClE,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAwC7B;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,OAAO,CA0BT;AAqBD;;GAEG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,cAAc,EACnB,WAAW,EAAE,QAAQ,GACpB,OAAO,CAAC,IAAI,CAAC,CA0Bf"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rehydra Proxy Server
|
|
3
|
+
* Standalone HTTP server that proxies LLM API requests with
|
|
4
|
+
* automatic PII anonymization and rehydration.
|
|
5
|
+
*/
|
|
6
|
+
import { createServer } from "node:http";
|
|
7
|
+
import { createRehydraProxy } from "./rehydra-proxy.js";
|
|
8
|
+
/**
|
|
9
|
+
* Creates and starts a standalone HTTP proxy server that anonymizes
|
|
10
|
+
* LLM API requests and rehydrates responses.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const proxy = await createRehydraProxyServer({
|
|
15
|
+
* port: 8080,
|
|
16
|
+
* upstream: 'https://api.openai.com',
|
|
17
|
+
* keyProvider: new ConfigKeyProvider(process.env.PII_KEY!),
|
|
18
|
+
* piiStorageProvider: new SQLitePIIStorageProvider('proxy.db'),
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* console.log(`Proxy running on http://${proxy.host}:${proxy.port}`);
|
|
22
|
+
*
|
|
23
|
+
* // Point your OpenAI client at the proxy:
|
|
24
|
+
* const openai = new OpenAI({ baseURL: `http://localhost:${proxy.port}/v1` });
|
|
25
|
+
*
|
|
26
|
+
* // Stop the server
|
|
27
|
+
* await proxy.close();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export async function createRehydraProxyServer(config) {
|
|
31
|
+
const host = config.host ?? "127.0.0.1";
|
|
32
|
+
const proxy = createRehydraProxy(config);
|
|
33
|
+
const server = createServer((req, res) => {
|
|
34
|
+
void (async () => {
|
|
35
|
+
try {
|
|
36
|
+
const webRequest = incomingMessageToRequest(req, host, config.port);
|
|
37
|
+
const webResponse = await proxy(webRequest);
|
|
38
|
+
await writeResponse(res, webResponse);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
res.writeHead(502, { "Content-Type": "application/json" });
|
|
42
|
+
res.end(JSON.stringify({
|
|
43
|
+
error: "proxy_error",
|
|
44
|
+
message: error instanceof Error ? error.message : "Unknown proxy error",
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
})();
|
|
48
|
+
});
|
|
49
|
+
await new Promise((resolve, reject) => {
|
|
50
|
+
server.on("error", reject);
|
|
51
|
+
server.listen(config.port, host, () => {
|
|
52
|
+
resolve();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
server,
|
|
57
|
+
port: config.port,
|
|
58
|
+
host,
|
|
59
|
+
async close() {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
server.close((err) => {
|
|
62
|
+
if (err !== undefined)
|
|
63
|
+
reject(err);
|
|
64
|
+
else
|
|
65
|
+
resolve();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Convert a Node.js IncomingMessage to a Web API Request
|
|
73
|
+
*/
|
|
74
|
+
export function incomingMessageToRequest(req, host, port) {
|
|
75
|
+
const url = `http://${host}:${port}${req.url ?? "/"}`;
|
|
76
|
+
const headers = new Headers();
|
|
77
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
78
|
+
if (value !== undefined) {
|
|
79
|
+
if (Array.isArray(value)) {
|
|
80
|
+
for (const v of value) {
|
|
81
|
+
headers.append(key, v);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
headers.set(key, value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const method = req.method ?? "GET";
|
|
90
|
+
const hasBody = method !== "GET" && method !== "HEAD";
|
|
91
|
+
return new Request(url, {
|
|
92
|
+
method,
|
|
93
|
+
headers,
|
|
94
|
+
body: hasBody ? nodeStreamToReadableStream(req) : undefined,
|
|
95
|
+
// @ts-expect-error - duplex is needed for streaming request bodies
|
|
96
|
+
duplex: hasBody ? "half" : undefined,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Convert a Node.js Readable stream to a Web API ReadableStream
|
|
101
|
+
*/
|
|
102
|
+
function nodeStreamToReadableStream(nodeStream) {
|
|
103
|
+
return new ReadableStream({
|
|
104
|
+
start(controller) {
|
|
105
|
+
nodeStream.on("data", (chunk) => {
|
|
106
|
+
controller.enqueue(new Uint8Array(chunk));
|
|
107
|
+
});
|
|
108
|
+
nodeStream.on("end", () => {
|
|
109
|
+
controller.close();
|
|
110
|
+
});
|
|
111
|
+
nodeStream.on("error", (err) => {
|
|
112
|
+
controller.error(err);
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Write a Web API Response to a Node.js ServerResponse
|
|
119
|
+
*/
|
|
120
|
+
export async function writeResponse(res, webResponse) {
|
|
121
|
+
// Copy status and headers
|
|
122
|
+
const headers = {};
|
|
123
|
+
webResponse.headers.forEach((value, key) => {
|
|
124
|
+
headers[key] = value;
|
|
125
|
+
});
|
|
126
|
+
res.writeHead(webResponse.status, headers);
|
|
127
|
+
if (webResponse.body === null) {
|
|
128
|
+
res.end();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
// Stream the response body
|
|
132
|
+
const reader = webResponse.body.getReader();
|
|
133
|
+
try {
|
|
134
|
+
for (;;) {
|
|
135
|
+
const { done, value } = await reader.read();
|
|
136
|
+
if (done)
|
|
137
|
+
break;
|
|
138
|
+
res.write(value);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
reader.releaseLock();
|
|
143
|
+
res.end();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=proxy-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-server.js","sourceRoot":"","sources":["../../src/proxy/proxy-server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AACjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AA2BxD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,MAAgC;IAEhC,MAAM,IAAI,GAAG,MAAM,CA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AAC;QACH,SAAS,CAAC;YACR,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI;gBAAE,MAAM;YAChB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;QACrB,GAAG,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rehydra Fetch Wrapper
|
|
3
|
+
* Wraps the native fetch to anonymize outgoing LLM requests
|
|
4
|
+
* and rehydrate incoming LLM responses.
|
|
5
|
+
*/
|
|
6
|
+
import type { RehydraFetchConfig } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Creates a fetch-compatible function that automatically:
|
|
9
|
+
* 1. Anonymizes text in outgoing LLM API requests
|
|
10
|
+
* 2. Rehydrates text in incoming LLM API responses
|
|
11
|
+
*
|
|
12
|
+
* PII never leaves your infrastructure.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import OpenAI from 'openai';
|
|
17
|
+
* import { createRehydraFetch, InMemoryKeyProvider, InMemoryPIIStorageProvider } from 'rehydra';
|
|
18
|
+
*
|
|
19
|
+
* const rehydraFetch = createRehydraFetch({
|
|
20
|
+
* keyProvider: new InMemoryKeyProvider(),
|
|
21
|
+
* piiStorageProvider: new InMemoryPIIStorageProvider(),
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* const openai = new OpenAI({ fetch: rehydraFetch });
|
|
25
|
+
*
|
|
26
|
+
* // PII is automatically anonymized before being sent to OpenAI
|
|
27
|
+
* const response = await openai.chat.completions.create({
|
|
28
|
+
* model: 'gpt-4',
|
|
29
|
+
* messages: [{ role: 'user', content: 'Email john@example.com about the meeting' }],
|
|
30
|
+
* });
|
|
31
|
+
* // Response is automatically rehydrated — contains original PII
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function createRehydraFetch(config: RehydraFetchConfig): typeof globalThis.fetch;
|
|
35
|
+
//# sourceMappingURL=rehydra-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehydra-fetch.d.ts","sourceRoot":"","sources":["../../src/proxy/rehydra-fetch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAgDrD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,kBAAkB,GACzB,OAAO,UAAU,CAAC,KAAK,CAkMzB"}
|