-
Notifications
You must be signed in to change notification settings - Fork 478
Fix diff preview to operate at field level for prompt changes #3601
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,25 @@ import {transformedPromptsAtomFamily} from "@/oss/state/newPlayground/core/promp | |
|
|
||
| import {CommitVariantChangesModalContentProps} from "../types" | ||
|
|
||
| // ===== Diff helpers (field-level diff) ===== | ||
| type DiffInput = Record<string, unknown> | ||
|
|
||
| function buildPromptDiffInput(params?: Record<string, any>): DiffInput { | ||
| if (!params) return {} | ||
| return { | ||
| prompt: params.prompt, | ||
| } | ||
| } | ||
|
Comment on lines
+23
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 buildPromptDiffInput extracts non-existent The Click to expandData Structure MismatchThe
The function buildPromptDiffInput(params?: Record<string, any>): DiffInput {
if (!params) return {}
return {
prompt: params.prompt, // This will be undefined!
}
}Since ImpactThe diff preview in the commit modal will always show an empty or near-empty comparison (e.g., Recommendation: The function should iterate over the prompt keys in the config object and extract the nested function buildPromptDiffInput(params?: Record<string, any>): DiffInput {
if (!params) return {}
const result: DiffInput = {}
for (const [key, value] of Object.entries(params)) {
if (value && typeof value === 'object' && 'prompt' in value) {
result[key] = { prompt: value.prompt }
}
}
return result
}Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| function stringifyForDiff(input: DiffInput): string { | ||
| try { | ||
| return JSON.stringify(input, null, 2) | ||
| } catch { | ||
| return "" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| const {Text} = Typography | ||
|
|
||
| const CommitVariantChangesModalContent = ({ | ||
|
|
@@ -80,10 +99,14 @@ const CommitVariantChangesModalContent = ({ | |
| // Compute snapshot lazily on first render after mount | ||
| if (variant && initialOriginalRef.current === null && initialModifiedRef.current === null) { | ||
| try { | ||
| initialOriginalRef.current = JSON.stringify(sanitizedOldParams) | ||
| initialOriginalRef.current = stringifyForDiff( | ||
| buildPromptDiffInput(sanitizedOldParams), | ||
| ) | ||
| // Use the same transformed local prompts ag_config that drives dirty-state | ||
| if (params !== undefined) { | ||
| initialModifiedRef.current = JSON.stringify(sanitizedParams) | ||
| initialModifiedRef.current = stringifyForDiff( | ||
| buildPromptDiffInput(sanitizedParams), | ||
| ) | ||
| } | ||
| } catch { | ||
| // Keep refs null; we will fall back to live values below | ||
|
|
@@ -98,9 +121,13 @@ const CommitVariantChangesModalContent = ({ | |
| })) | ||
|
|
||
| // Ensure DiffView gets strings even when params are undefined | ||
| const originalForDiff = initialOriginalRef.current ?? JSON.stringify(sanitizedOldParams ?? {}) | ||
| const originalForDiff = | ||
| initialOriginalRef.current ?? | ||
| stringifyForDiff(buildPromptDiffInput(sanitizedOldParams)) | ||
|
|
||
| const modifiedForDiff = | ||
| initialModifiedRef.current ?? JSON.stringify(sanitizedParams ?? sanitizedOldParams ?? {}) | ||
| initialModifiedRef.current ?? | ||
| stringifyForDiff(buildPromptDiffInput(sanitizedParams ?? sanitizedOldParams)) | ||
|
|
||
| return ( | ||
| <div className="flex h-full min-h-0 flex-col gap-6 md:flex-row"> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes there is a property called prompt in params. That is not always the case (for instance with custom workflows)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point — agreed.
The current version assumes a top-level prompt field, which won’t hold for custom workflows or alternative config shapes.
I’ll update the diff input builder to iterate over the config entries and extract nested prompt fields only when present, so the diff remains field-level without making assumptions about the schema.