@@ -12,6 +12,7 @@ import type {
12
12
PromptToEditRequest ,
13
13
TextToCadErrorResponse ,
14
14
} from '@src/lib/promptToEditTypes'
15
+ import { parentPathRelativeToProject } from '@src/lib/paths'
15
16
16
17
function sourceIndexToLineColumn (
17
18
code : string ,
@@ -57,7 +58,10 @@ export async function submitTextToCadMultiFileIterationRequest(
57
58
)
58
59
59
60
if ( ! response . ok ) {
60
- return new Error ( `HTTP error! status: ${ response . status } ` )
61
+ const errorBody = await response . json ( )
62
+ return new Error (
63
+ `HTTP error! status: ${ response . status } , error: ${ JSON . stringify ( errorBody ) } `
64
+ )
61
65
}
62
66
63
67
const data = await response . json ( )
@@ -77,16 +81,15 @@ export function constructMultiFileIterationRequestWithPromptHelpers({
77
81
prompt,
78
82
selections,
79
83
projectFiles,
84
+ applicationProjectDirectory,
80
85
artifactGraph,
81
86
projectName,
82
87
currentFile,
83
88
kclVersion,
84
89
} : ConstructRequestArgs ) : PromptToEditRequest {
85
90
const kclFilesMap : KclFileMetaMap = { }
86
91
const files : KittyCadLibFile [ ] = [ ]
87
- const currentFileMeta = projectFiles . find (
88
- ( f ) => f . type !== 'other' && f . absPath === currentFile . entry ?. path
89
- )
92
+
90
93
projectFiles . forEach ( ( file ) => {
91
94
let data : Blob
92
95
if ( file . type === 'other' ) {
@@ -104,21 +107,31 @@ export function constructMultiFileIterationRequestWithPromptHelpers({
104
107
105
108
// Way to patch in supplying the currently-opened file without updating the API.
106
109
// TODO: update the API to support currently-opened files as other parts of the payload
107
- const currentFilePrompt : Models [ 'SourceRangePrompt_type' ] = {
108
- prompt : 'This is the active file' ,
109
- range : convertAppRangeToApiRange (
110
- [ 0 , currentFile . content . length , 0 ] ,
111
- currentFile . content
112
- ) ,
113
- file : currentFileMeta ?. relPath ,
114
- }
110
+ const currentFilePrompt : Models [ 'SourceRangePrompt_type' ] | null =
111
+ currentFile . entry
112
+ ? {
113
+ prompt : 'This is the active file' ,
114
+ range : convertAppRangeToApiRange (
115
+ [ 0 , currentFile . content . length , 0 ] ,
116
+ currentFile . content
117
+ ) ,
118
+ file : parentPathRelativeToProject (
119
+ currentFile . entry ?. path ,
120
+ applicationProjectDirectory
121
+ ) ,
122
+ }
123
+ : null
115
124
116
125
// If no selection, use whole file
117
126
if ( selections === null ) {
127
+ const rangePrompts : Models [ 'SourceRangePrompt_type' ] [ ] = [ ]
128
+ if ( currentFilePrompt !== null ) {
129
+ rangePrompts . push ( currentFilePrompt )
130
+ }
118
131
return {
119
132
body : {
120
133
prompt,
121
- source_ranges : [ currentFilePrompt ] ,
134
+ source_ranges : rangePrompts ,
122
135
project_name :
123
136
projectName !== '' && projectName !== 'browser'
124
137
? projectName
@@ -145,11 +158,9 @@ export function constructMultiFileIterationRequestWithPromptHelpers({
145
158
prompts . push ( {
146
159
prompt : `The users main selection is the end cap of a general-sweep (that is an extrusion, revolve, sweep or loft).
147
160
The source range most likely refers to "startProfile" simply because this is the start of the profile that was swept.
148
- If you need to operate on this cap, for example for sketching on the face, you can use the special string ${
149
- artifact . subType === 'end' ? 'END' : 'START'
150
- } i.e. \`startSketchOn(someSweepVariable, face = ${
151
- artifact . subType === 'end' ? 'END' : 'START'
152
- } )\`
161
+ If you need to operate on this cap, for example for sketching on the face, you can use the special string ${ artifact . subType === 'end' ? 'END' : 'START'
162
+ } i.e. \`startSketchOn(someSweepVariable, face = ${ artifact . subType === 'end' ? 'END' : 'START'
163
+ } )\`
153
164
When they made this selection they main have intended this surface directly or meant something more general like the sweep body.
154
165
See later source ranges for more context.` ,
155
166
range : convertAppRangeToApiRange ( selection . codeRef . range , code ) ,
@@ -190,14 +201,12 @@ But it's also worth bearing in mind that the user may have intended to select th
190
201
if ( artifact ?. type === 'sweepEdge' ) {
191
202
prompts . push ( {
192
203
prompt : `The users main selection is the edge of a general-sweep (that is an extrusion, revolve, sweep or loft).
193
- it is an ${
194
- artifact . subType
195
- } edge, in order to refer to this edge you should add a tag to the segment function in this source range,
196
- and then use the function ${
197
- artifact . subType === 'adjacent'
204
+ it is an ${ artifact . subType
205
+ } edge, in order to refer to this edge you should add a tag to the segment function in this source range,
206
+ and then use the function ${ artifact . subType === 'adjacent'
198
207
? 'getAdjacentEdge'
199
208
: 'getOppositeEdge'
200
- }
209
+ }
201
210
See later source ranges for more context. about the sweep` ,
202
211
range : convertAppRangeToApiRange ( selection . codeRef . range , code ) ,
203
212
file : filePath ,
@@ -261,7 +270,9 @@ See later source ranges for more context. about the sweep`,
261
270
return prompts
262
271
} )
263
272
// Push the current file prompt alongside the selection-based prompts
264
- ranges . push ( currentFilePrompt )
273
+ if ( currentFilePrompt !== null ) {
274
+ ranges . push ( currentFilePrompt )
275
+ }
265
276
let payload = {
266
277
body : {
267
278
prompt,
0 commit comments