-
Notifications
You must be signed in to change notification settings - Fork 648
feat: add request trace for llm #1085
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
5 commits
Select commit
Hold shift + click to select a range
5c56a43
feat: add trace support wip
zerob13 5b62fd3
feat: add trace dialog with monaco
zerob13 8101b00
feat: add i18n for trace dialog
zerob13 e0d35df
feat: add config for trace params
zerob13 efc874d
fix: prevent stale previews when messageId changes
zerob13 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,138 @@ | ||
| /** | ||
| * Redaction utilities for sensitive information in request preview | ||
| */ | ||
|
|
||
| /** | ||
| * Sensitive header keys that should be redacted | ||
| */ | ||
| const SENSITIVE_HEADER_KEYS = [ | ||
| 'authorization', | ||
| 'api-key', | ||
| 'x-api-key', | ||
| 'apikey', | ||
| 'bearer', | ||
| 'token', | ||
| 'secret', | ||
| 'password', | ||
| 'credential', | ||
| 'auth' | ||
| ] | ||
|
|
||
| /** | ||
| * Sensitive body keys that should be redacted | ||
| * Note: We use exact match to avoid filtering legitimate keys like 'max_tokens' | ||
| */ | ||
| const SENSITIVE_BODY_KEYS = ['api_key', 'apiKey', 'apikey', 'secret', 'password', 'token'] | ||
|
|
||
| /** | ||
| * Body keys that should never be redacted (even if they contain sensitive keywords) | ||
| */ | ||
| const ALLOWED_BODY_KEYS = [ | ||
| 'max_tokens', | ||
| 'max_completion_tokens', | ||
| 'max_output_tokens', | ||
| 'temperature', | ||
| 'stream', | ||
| 'model', | ||
| 'messages', | ||
| 'tools' | ||
| ] | ||
|
|
||
| /** | ||
| * Redact sensitive values in headers | ||
| * @param headers Original headers | ||
| * @returns Redacted headers | ||
| */ | ||
| export function redactHeaders(headers: Record<string, string>): Record<string, string> { | ||
| const redacted: Record<string, string> = {} | ||
|
|
||
| for (const [key, value] of Object.entries(headers)) { | ||
| const keyLower = key.toLowerCase() | ||
| const shouldRedact = SENSITIVE_HEADER_KEYS.some((sensitiveKey) => | ||
| keyLower.includes(sensitiveKey) | ||
| ) | ||
|
|
||
| if (shouldRedact) { | ||
| redacted[key] = '***REDACTED***' | ||
| } else { | ||
| redacted[key] = value | ||
| } | ||
| } | ||
|
|
||
| return redacted | ||
| } | ||
|
|
||
| /** | ||
| * Redact sensitive values in request body | ||
| * @param body Original body | ||
| * @returns Redacted body | ||
| */ | ||
| export function redactBody(body: unknown): unknown { | ||
| if (body === null || body === undefined) { | ||
| return body | ||
| } | ||
|
|
||
| if (Array.isArray(body)) { | ||
| return body.map((item) => redactBody(item)) | ||
| } | ||
|
|
||
| if (typeof body === 'object') { | ||
| const redacted: Record<string, unknown> = {} | ||
|
|
||
| for (const [key, value] of Object.entries(body)) { | ||
| // Skip redaction for allowed keys (like max_tokens, max_completion_tokens, etc.) | ||
| if (ALLOWED_BODY_KEYS.includes(key)) { | ||
| if (typeof value === 'object' && value !== null) { | ||
| redacted[key] = redactBody(value) | ||
| } else { | ||
| redacted[key] = value | ||
| } | ||
| continue | ||
| } | ||
|
|
||
| // Check if key matches sensitive patterns (exact match or ends with sensitive keyword) | ||
| const keyLower = key.toLowerCase() | ||
| const shouldRedact = SENSITIVE_BODY_KEYS.some((sensitiveKey) => { | ||
| const sensitiveKeyLower = sensitiveKey.toLowerCase() | ||
| // Exact match | ||
| if (keyLower === sensitiveKeyLower) { | ||
| return true | ||
| } | ||
| // Key ends with sensitive keyword (e.g., 'api_token', 'access_token') | ||
| // But exclude keys that contain allowed patterns (e.g., 'max_tokens') | ||
| if (keyLower.endsWith(`_${sensitiveKeyLower}`) || keyLower.endsWith(sensitiveKeyLower)) { | ||
| // Double check: make sure it's not a false positive | ||
| return !ALLOWED_BODY_KEYS.some((allowed) => keyLower.includes(allowed.toLowerCase())) | ||
| } | ||
| return false | ||
| }) | ||
|
|
||
| if (shouldRedact) { | ||
| redacted[key] = '***REDACTED***' | ||
| } else if (typeof value === 'object' && value !== null) { | ||
| redacted[key] = redactBody(value) | ||
| } else { | ||
| redacted[key] = value | ||
| } | ||
| } | ||
|
|
||
| return redacted | ||
| } | ||
|
|
||
| return body | ||
| } | ||
|
|
||
| /** | ||
| * Redact sensitive information in full request preview | ||
| * @param preview Request preview data | ||
| * @returns Redacted preview | ||
| */ | ||
| export function redactRequestPreview(preview: { headers: Record<string, string>; body: unknown }): { | ||
| headers: Record<string, string> | ||
| body: unknown | ||
| } { | ||
| return { | ||
| headers: redactHeaders(preview.headers), | ||
| body: redactBody(preview.body) | ||
| } | ||
| } |
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
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.