[Fix]: P2E base path is always the project directory, P2E when completed stays in your current file (#7091)
* fix: fixes for p2e * fix: yep tsc fixes * fix: fixing reject workflow and navigate
This commit is contained in:
@ -75,6 +75,7 @@ import {
|
||||
MAKE_TOAST_MESSAGES,
|
||||
EXECUTION_TYPE_MOCK,
|
||||
FILE_EXT,
|
||||
PROJECT_ENTRYPOINT,
|
||||
} from '@src/lib/constants'
|
||||
import { exportMake } from '@src/lib/exportMake'
|
||||
import { exportSave } from '@src/lib/exportSave'
|
||||
@ -1759,7 +1760,8 @@ export const ModelingMachineProvider = ({
|
||||
)
|
||||
let basePath = ''
|
||||
if (isDesktop() && context?.project?.children) {
|
||||
basePath = context?.selectedDirectory?.path
|
||||
// Use the entire project directory as the basePath for prompt to edit, do not use relative subdir paths
|
||||
basePath = context?.project?.path
|
||||
const filePromises: Promise<FileMeta | null>[] = []
|
||||
let uploadSize = 0
|
||||
const recursivelyPushFilePromises = (files: FileEntry[]) => {
|
||||
@ -1826,6 +1828,13 @@ export const ModelingMachineProvider = ({
|
||||
)
|
||||
}
|
||||
}
|
||||
let filePath = file?.path
|
||||
// When prompt to edit finishes, try to route to the file they were in otherwise go to main.kcl
|
||||
if (filePath) {
|
||||
filePath = window.electron.path.relative(basePath, filePath)
|
||||
} else {
|
||||
filePath = PROJECT_ENTRYPOINT
|
||||
}
|
||||
return await promptToEditFlow({
|
||||
projectFiles,
|
||||
prompt: input.prompt,
|
||||
@ -1833,6 +1842,7 @@ export const ModelingMachineProvider = ({
|
||||
token,
|
||||
artifactGraph: kclManager.artifactGraph,
|
||||
projectName: context.project.name,
|
||||
filePath,
|
||||
})
|
||||
}),
|
||||
},
|
||||
|
@ -35,6 +35,7 @@ import {
|
||||
} from '@src/machines/systemIO/utils'
|
||||
import {
|
||||
useProjectDirectoryPath,
|
||||
useRequestedFileName,
|
||||
useRequestedProjectName,
|
||||
} from '@src/machines/systemIO/hooks'
|
||||
import { commandBarActor } from '@src/lib/singletons'
|
||||
@ -498,7 +499,14 @@ export function ToastPromptToEditCadSuccess({
|
||||
token?: string
|
||||
}) {
|
||||
const modelId = data.id
|
||||
const requestedProjectName = useRequestedProjectName()
|
||||
const possibleRequestedProjectName = useRequestedProjectName()
|
||||
const possibleRequestedFileName = useRequestedFileName()
|
||||
|
||||
// Depends on navigation method
|
||||
const requestedProjectName = {
|
||||
name:
|
||||
possibleRequestedProjectName.name || possibleRequestedFileName.project,
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex gap-4 min-w-80">
|
||||
@ -548,6 +556,7 @@ export function ToastPromptToEditCadSuccess({
|
||||
await writeOverFilesAndExecute({
|
||||
requestedFiles: requestedFiles,
|
||||
projectName: requestedProjectName.name,
|
||||
filePath: possibleRequestedFileName.file,
|
||||
})
|
||||
} else {
|
||||
codeManager.updateCodeEditor(oldCode)
|
||||
@ -588,10 +597,23 @@ export function ToastPromptToEditCadSuccess({
|
||||
export const writeOverFilesAndExecute = async ({
|
||||
requestedFiles,
|
||||
projectName,
|
||||
filePath,
|
||||
}: {
|
||||
requestedFiles: RequestedKCLFile[]
|
||||
projectName: string
|
||||
filePath?: string | undefined
|
||||
}) => {
|
||||
if (filePath) {
|
||||
systemIOActor.send({
|
||||
type: SystemIOMachineEvents.bulkCreateKCLFilesAndNavigateToFile,
|
||||
data: {
|
||||
files: requestedFiles,
|
||||
requestedProjectName: projectName,
|
||||
requestedFileNameWithExtension: filePath,
|
||||
override: true,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
systemIOActor.send({
|
||||
type: SystemIOMachineEvents.bulkCreateKCLFilesAndNavigateToProject,
|
||||
data: {
|
||||
@ -600,6 +622,7 @@ export const writeOverFilesAndExecute = async ({
|
||||
override: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// to await the result of the send event above
|
||||
await waitForIdleState({ systemIOActor })
|
||||
|
@ -415,6 +415,7 @@ export async function promptToEditFlow({
|
||||
token,
|
||||
artifactGraph,
|
||||
projectName,
|
||||
filePath,
|
||||
}: {
|
||||
prompt: string
|
||||
selections: Selections
|
||||
@ -422,6 +423,7 @@ export async function promptToEditFlow({
|
||||
token?: string
|
||||
artifactGraph: ArtifactGraph
|
||||
projectName: string
|
||||
filePath: string | undefined
|
||||
}) {
|
||||
const result = await doPromptEdit({
|
||||
prompt,
|
||||
@ -498,6 +500,7 @@ export async function promptToEditFlow({
|
||||
await writeOverFilesAndExecute({
|
||||
requestedFiles,
|
||||
projectName,
|
||||
filePath,
|
||||
})
|
||||
} else {
|
||||
const newCode = result.outputs['main.kcl']
|
||||
|
@ -102,6 +102,16 @@ export const systemIOMachine = setup({
|
||||
requestedSubRoute?: string
|
||||
}
|
||||
}
|
||||
| {
|
||||
type: SystemIOMachineEvents.bulkCreateKCLFilesAndNavigateToFile
|
||||
data: {
|
||||
files: RequestedKCLFile[]
|
||||
requestedProjectName: string
|
||||
requestedFileNameWithExtension: string
|
||||
override?: boolean
|
||||
requestedSubRoute?: string
|
||||
}
|
||||
}
|
||||
| {
|
||||
type: SystemIOMachineEvents.importFileFromURL
|
||||
data: {
|
||||
@ -339,6 +349,27 @@ export const systemIOMachine = setup({
|
||||
return { message: '', fileName: '', projectName: '', subRoute: '' }
|
||||
}
|
||||
),
|
||||
[SystemIOMachineActors.bulkCreateKCLFilesAndNavigateToFile]: fromPromise(
|
||||
async ({
|
||||
input,
|
||||
}: {
|
||||
input: {
|
||||
context: SystemIOContext
|
||||
files: RequestedKCLFile[]
|
||||
rootContext: AppMachineContext
|
||||
requestedProjectName: string
|
||||
requestedFileNameWithExtension: string
|
||||
requestedSubRoute?: string
|
||||
}
|
||||
}): Promise<{
|
||||
message: string
|
||||
fileName: string
|
||||
projectName: string
|
||||
subRoute: string
|
||||
}> => {
|
||||
return { message: '', fileName: '', projectName: '', subRoute: '' }
|
||||
}
|
||||
),
|
||||
},
|
||||
}).createMachine({
|
||||
initial: SystemIOMachineStates.idle,
|
||||
@ -414,6 +445,9 @@ export const systemIOMachine = setup({
|
||||
target:
|
||||
SystemIOMachineStates.bulkCreatingKCLFilesAndNavigateToProject,
|
||||
},
|
||||
[SystemIOMachineEvents.bulkCreateKCLFilesAndNavigateToFile]: {
|
||||
target: SystemIOMachineStates.bulkCreatingKCLFilesAndNavigateToFile,
|
||||
},
|
||||
},
|
||||
},
|
||||
[SystemIOMachineStates.readingFolders]: {
|
||||
@ -683,5 +717,53 @@ export const systemIOMachine = setup({
|
||||
},
|
||||
},
|
||||
},
|
||||
[SystemIOMachineStates.bulkCreatingKCLFilesAndNavigateToFile]: {
|
||||
invoke: {
|
||||
id: SystemIOMachineActors.bulkCreateKCLFilesAndNavigateToFile,
|
||||
src: SystemIOMachineActors.bulkCreateKCLFilesAndNavigateToFile,
|
||||
input: ({ context, event, self }) => {
|
||||
assertEvent(
|
||||
event,
|
||||
SystemIOMachineEvents.bulkCreateKCLFilesAndNavigateToFile
|
||||
)
|
||||
return {
|
||||
context,
|
||||
files: event.data.files,
|
||||
rootContext: self.system.get('root').getSnapshot().context,
|
||||
requestedProjectName: event.data.requestedProjectName,
|
||||
override: event.data.override,
|
||||
requestedFileNameWithExtension:
|
||||
event.data.requestedFileNameWithExtension,
|
||||
requestedSubRoute: event.data.requestedSubRoute,
|
||||
}
|
||||
},
|
||||
onDone: {
|
||||
target: SystemIOMachineStates.readingFolders,
|
||||
actions: [
|
||||
assign({
|
||||
requestedFileName: ({ event }) => {
|
||||
assertEvent(
|
||||
event,
|
||||
SystemIOMachineEvents.done_bulkCreateKCLFilesAndNavigateToFile
|
||||
)
|
||||
// Gotcha: file could have an ending of .kcl...
|
||||
const file = event.output.fileName.endsWith('.kcl')
|
||||
? event.output.fileName
|
||||
: event.output.fileName + '.kcl'
|
||||
return {
|
||||
project: event.output.projectName,
|
||||
file,
|
||||
}
|
||||
},
|
||||
}),
|
||||
SystemIOMachineActions.toastSuccess,
|
||||
],
|
||||
},
|
||||
onError: {
|
||||
target: SystemIOMachineStates.idle,
|
||||
actions: [SystemIOMachineActions.toastError],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -73,6 +73,10 @@ const sharedBulkCreateWorkflow = async ({
|
||||
baseDir,
|
||||
}).name
|
||||
|
||||
console.log('why?')
|
||||
console.log('override', input.override)
|
||||
console.log('override', newProjectName)
|
||||
console.log('override', fileName)
|
||||
// Create the project around the file if newProject
|
||||
await createNewProjectDirectory(
|
||||
newProjectName,
|
||||
@ -370,5 +374,33 @@ export const systemIOMachineDesktop = systemIOMachine.provide({
|
||||
}
|
||||
}
|
||||
),
|
||||
[SystemIOMachineActors.bulkCreateKCLFilesAndNavigateToFile]: fromPromise(
|
||||
async ({
|
||||
input,
|
||||
}: {
|
||||
input: {
|
||||
context: SystemIOContext
|
||||
files: RequestedKCLFile[]
|
||||
rootContext: AppMachineContext
|
||||
requestedProjectName: string
|
||||
override?: boolean
|
||||
requestedFileNameWithExtension: string
|
||||
requestedSubRoute?: string
|
||||
}
|
||||
}) => {
|
||||
const message = await sharedBulkCreateWorkflow({
|
||||
input: {
|
||||
...input,
|
||||
override: input.override,
|
||||
},
|
||||
})
|
||||
return {
|
||||
...message,
|
||||
projectName: input.requestedProjectName,
|
||||
fileName: input.requestedFileNameWithExtension || '',
|
||||
subRoute: input.requestedSubRoute || '',
|
||||
}
|
||||
}
|
||||
),
|
||||
},
|
||||
})
|
||||
|
@ -15,6 +15,7 @@ export enum SystemIOMachineActors {
|
||||
deleteKCLFile = 'delete kcl delete',
|
||||
bulkCreateKCLFiles = 'bulk create kcl files',
|
||||
bulkCreateKCLFilesAndNavigateToProject = 'bulk create kcl files and navigate to project',
|
||||
bulkCreateKCLFilesAndNavigateToFile = 'bulk create kcl files and navigate to file',
|
||||
}
|
||||
|
||||
export enum SystemIOMachineStates {
|
||||
@ -31,6 +32,7 @@ export enum SystemIOMachineStates {
|
||||
deletingKCLFile = 'deletingKCLFile',
|
||||
bulkCreatingKCLFiles = 'bulkCreatingKCLFiles',
|
||||
bulkCreatingKCLFilesAndNavigateToProject = 'bulkCreatingKCLFilesAndNavigateToProject',
|
||||
bulkCreatingKCLFilesAndNavigateToFile = 'bulkCreatingKCLFilesAndNavigateToFile',
|
||||
}
|
||||
|
||||
const donePrefix = 'xstate.done.actor.'
|
||||
@ -56,6 +58,9 @@ export enum SystemIOMachineEvents {
|
||||
deleteKCLFile = 'delete kcl file',
|
||||
bulkCreateKCLFiles = 'bulk create kcl files',
|
||||
bulkCreateKCLFilesAndNavigateToProject = 'bulk create kcl files and navigate to project',
|
||||
bulkCreateKCLFilesAndNavigateToFile = 'bulk create kcl files and navigate to file',
|
||||
done_bulkCreateKCLFilesAndNavigateToFile = donePrefix +
|
||||
'bulk create kcl files and navigate to file',
|
||||
}
|
||||
|
||||
export enum SystemIOMachineActions {
|
||||
|
Reference in New Issue
Block a user