Skip to content

Commit 5252ba9

Browse files
committed
Update Configurations stories to use provider_name and refactor commit message prompt to use structured XML format
1 parent ac1045a commit 5252ba9

2 files changed

Lines changed: 60 additions & 23 deletions

File tree

‎packages/ui/src/components/editor/panel/Configurations/Configurations.stories.tsx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@ const configurations: Configurations.Configuration[] = [
88
{
99
id: '1',
1010
model: 'claude-3-haiku-20240307',
11-
provider: 'Anthropic',
11+
provider_name: 'Anthropic',
1212
temperature: 0.7
1313
},
1414
{
1515
id: '2',
1616
model: 'gpt-4o',
17-
provider: 'OpenAI',
17+
provider_name: 'OpenAI',
1818
reasoning_effort: 'low',
1919
is_pinned: true
2020
},
2121
{
2222
id: '3',
2323
model: 'gemini-1.5-flash',
24-
provider: 'Google',
25-
cache_enabled: true
24+
provider_name: 'Google'
2625
}
2726
]
2827

‎packages/vscode/src/views/panel/backend/message-handlers/handle-commit-changes/utils/prompt-utils.ts‎

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ export const build_commit_message_prompt = (
2929

3030
const file_diffs = diff.split(/^diff --git /m).filter((d) => d.trim() != '')
3131

32-
let changes_content = ''
32+
let changes_content = '<files>\n'
3333
for (const file_diff_content of file_diffs) {
3434
const full_file_diff = 'diff --git ' + file_diff_content
3535
const lines = full_file_diff.split('\n')
3636
const old_path_line = lines.find((l) => l.startsWith('--- a/'))
3737
const new_path_line = lines.find((l) => l.startsWith('+++ b/'))
38+
const rename_from_line = lines.find((l) => l.startsWith('rename from '))
3839

3940
const old_path = old_path_line
4041
? old_path_line.substring('--- a/'.length)
@@ -77,38 +78,75 @@ export const build_commit_message_prompt = (
7778
(f) => f.relative_path == file_path
7879
)
7980

80-
let heading = 'Updated file'
81-
let display_path = `\`${file_path}\``
81+
let status = 'updated'
8282

8383
if (file_data) {
84-
if (file_data.status === 2) {
85-
heading = 'New file'
86-
} else if (file_data.status === 3) {
87-
heading = 'Deleted file'
84+
if (file_data.status == 2) {
85+
status = 'created'
86+
} else if (file_data.status == 3) {
87+
status = 'deleted'
8888
is_deleted = true
89-
} else if (file_data.status === 4) {
90-
heading = 'Renamed file'
91-
if (file_data.original_relative_path) {
92-
display_path = `\`${file_data.original_relative_path}\` (old) \`${file_path}\` (new)`
93-
}
89+
} else if (file_data.status == 4) {
90+
status = 'renamed'
9491
}
9592
} else {
9693
if (is_deleted) {
97-
heading = 'Deleted file'
94+
status = 'deleted'
9895
} else if (!old_path && new_path) {
99-
heading = 'New file'
96+
status = 'created'
10097
}
10198
}
10299

103-
changes_content += `\n### ${heading}: ${display_path}\n\n`
104-
if (file_data) {
105-
changes_content += `The original state of the file for reference:\n\n<![CDATA[\n${file_data.content}\n]]>\n\n`
100+
let old_path_attr: string | undefined
101+
if (status == 'renamed') {
102+
if (rename_from_line) {
103+
old_path_attr = rename_from_line
104+
.substring('rename from '.length)
105+
.trim()
106+
} else {
107+
const diff_header = lines[0]
108+
const b_part = ` b/${file_path}`
109+
if (diff_header.endsWith(b_part)) {
110+
const prefix_len = 'diff --git '.length
111+
const a_part = diff_header.substring(
112+
prefix_len,
113+
diff_header.length - b_part.length
114+
)
115+
if (a_part.startsWith('a/')) {
116+
old_path_attr = a_part.substring(2)
117+
}
118+
}
119+
}
106120
}
107-
if (!is_deleted) {
108-
changes_content += `**New changes:**\n\n<![CDATA[\n${final_diff_content}\n]]>\n`
121+
122+
changes_content += `<file path="${file_path}" status="${status}"`
123+
if (old_path_attr) {
124+
changes_content += ` old_path="${old_path_attr}"`
109125
}
126+
changes_content += '>\n'
127+
128+
if (status == 'created' || status == 'deleted') {
129+
if (file_data) {
130+
changes_content += `<![CDATA[\n${file_data.content}\n]]>\n`
131+
}
132+
} else if (status == 'renamed') {
133+
if (old_path && new_path) {
134+
changes_content += `<![CDATA[\n${final_diff_content}\n]]>\n`
135+
}
136+
if (file_data) {
137+
changes_content += `<![CDATA[\n${file_data.content}\n]]>\n`
138+
}
139+
} else {
140+
changes_content += `<![CDATA[\n${final_diff_content}\n]]>\n`
141+
if (file_data) {
142+
changes_content += `<![CDATA[\n${file_data.content}\n]]>\n`
143+
}
144+
}
145+
changes_content += `</file>\n`
110146
}
111147
}
112148

149+
changes_content += '</files>'
150+
113151
return `${commit_message_prompt}\n${changes_content}\n${commit_message_prompt}`
114152
}

0 commit comments

Comments
 (0)