feat(ai-security-guard): add fallback JSON paths for response content extraction#3738
Open
JianweiWang wants to merge 11 commits intohigress-group:mainfrom
Open
feat(ai-security-guard): add fallback JSON paths for response content extraction#3738JianweiWang wants to merge 11 commits intohigress-group:mainfrom
JianweiWang wants to merge 11 commits intohigress-group:mainfrom
Conversation
… extraction Add configurable fallback paths (responseContentFallbackJsonPaths and responseStreamContentFallbackJsonPaths) to support extracting response content from non-OpenAI formats such as Anthropic Claude. When the primary extraction path yields empty content, the plugin tries fallback paths in order. Paths equal to the primary path are automatically skipped. Setting either field to an empty array disables fallback explicitly. Key implementation details: - Default fallback paths cover OpenAI and Claude response formats - Effective fallback paths are pre-computed in the response header phase and cached in request context to avoid per-chunk recalculation - Handles bare JSON, SSE data payloads, and multi-line data events - Default variables are unexported; exposed via functions returning copies
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Add focused fallback extraction and config-validation test cases to cover previously missed patch branches, including streaming SSE edge cases and fallback-path caching behavior. Refactor the fallback context helper to a minimal interface so cache logic can be unit-tested without wasm host coupling. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add configurable fallback JSON paths (
responseContentFallbackJsonPathsandresponseStreamContentFallbackJsonPaths) to theai-security-guardplugin, enabling response content extraction from non-OpenAI formats such as Anthropic Claude.When the primary extraction path yields empty content, the plugin tries fallback paths in order. Paths equal to the primary path are automatically skipped. Setting either field to an empty array disables fallback explicitly.
Key implementation details
Changed files
plugins/wasm-go/extensions/ai-security-guard/config/config.go— config struct & fallback path logicplugins/wasm-go/extensions/ai-security-guard/lvwang/common/text/openai.go— response content extraction with fallbackplugins/wasm-go/extensions/ai-security-guard/lvwang/common/text/openai_test.go— unit tests for fallback extraction (new)plugins/wasm-go/extensions/ai-security-guard/main_test.go— integration testsplugins/wasm-go/extensions/ai-security-guard/README.md/README_EN.md— documentation updates