-
Notifications
You must be signed in to change notification settings - Fork 553
feat: updates prompts plugin flow #2545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d3fbfdb
Add support for variables in prompt messages
impoiler a1f8922
Add support for variables in the prompt messages backend
impoiler f538e6e
refactor moved CELRuleBuilder to lib for reusability
impoiler ee19296
refactor/remove prompt repo subpages
impoiler 3df2fd7
feat/prompt-deployment-strategies-fallback-screens
impoiler a9ceab4
refactor: Extracts routing utilites to a separate package
roroghost17 944dd72
feat: updates prompts plugin flow
roroghost17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package routing | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "regexp" | ||
| "strings" | ||
| ) | ||
|
|
||
| // headerKeyPattern matches header map access patterns like headers["X-Api-Key"] or headers['X-Api-Key'] | ||
| var headerKeyPattern = regexp.MustCompile(`headers\[["']([^"']+)["']\]`) | ||
|
|
||
| // headerInPattern matches "in headers" membership test patterns like "X-Api-Key" in headers or 'X-Api-Key' in headers | ||
| var headerInPattern = regexp.MustCompile(`["']([^"']+)["']\s+in\s+headers`) | ||
|
|
||
| // paramKeyPattern matches param map access patterns like params["Region"] or params['Region'] | ||
| var paramKeyPattern = regexp.MustCompile(`params\[["']([^"']+)["']\]`) | ||
|
|
||
| // paramInPattern matches "in params" membership test patterns like "Region" in params or 'Region' in params | ||
| var paramInPattern = regexp.MustCompile(`["']([^"']+)["']\s+in\s+params`) | ||
|
|
||
| // normalizeMapKeysInCEL lowercases header and param keys in CEL expressions | ||
| // so that headers["X-Api-Key"] becomes headers["x-api-key"], "X-Api-Key" in headers becomes "x-api-key" in headers, | ||
| // params["Region"] becomes params["region"], and "Region" in params becomes "region" in params. | ||
| // This ensures CEL expressions match against the normalized (lowercase) map keys at runtime. | ||
| func NormalizeMapKeysInCEL(expr string) string { | ||
| toLower := func(match string) string { | ||
| return strings.ToLower(match) | ||
| } | ||
| // Normalize bracket access | ||
| expr = headerKeyPattern.ReplaceAllStringFunc(expr, toLower) | ||
| expr = paramKeyPattern.ReplaceAllStringFunc(expr, toLower) | ||
| // Normalize "in" membership test | ||
| expr = headerInPattern.ReplaceAllStringFunc(expr, toLower) | ||
| expr = paramInPattern.ReplaceAllStringFunc(expr, toLower) | ||
| return expr | ||
| } | ||
|
|
||
| // validateCELExpression performs basic validation on CEL expression format | ||
| func ValidateCELExpression(expr string) error { | ||
| normalized := strings.TrimSpace(expr) | ||
| if normalized == "" || normalized == "true" || normalized == "false" { | ||
| return nil // Empty, true, or false are valid | ||
| } | ||
|
|
||
| // List of allowed operators and keywords | ||
| validPatterns := []string{ | ||
| "==", "!=", "&&", "||", ">", "<", ">=", "<=", | ||
| "in ", "matches ", ".startsWith(", ".contains(", ".endsWith(", | ||
| "[", "]", "(", ")", "!", | ||
| } | ||
|
|
||
| // Check if expression contains at least one valid operator | ||
| hasPattern := false | ||
| for _, pattern := range validPatterns { | ||
| if strings.Contains(normalized, pattern) { | ||
| hasPattern = true | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if !hasPattern { | ||
| return fmt.Errorf("expression must contain at least one operator: %s", expr) | ||
| } | ||
|
|
||
| return nil | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.