Prompt to edit (#4830)
* initial plumbing for getting the new option into the cmd-bar * start of prompt edit * update AI poll * add spinner * more prompt engineering * add success toast, allowing user's to reject code * select code that changed in prompt to edit * selection in scene should not disappear when opening prompt cmd * tweak * fmt * add tests * some clean up * clean up * fix tests
This commit is contained in:
@ -4,7 +4,10 @@ import { useFileContext } from 'hooks/useFileContext'
|
||||
import { isDesktop } from 'lib/isDesktop'
|
||||
import { PATHS } from 'lib/paths'
|
||||
import toast from 'react-hot-toast'
|
||||
import { TextToCad_type } from '@kittycad/lib/dist/types/src/models'
|
||||
import {
|
||||
TextToCad_type,
|
||||
TextToCadIteration_type,
|
||||
} from '@kittycad/lib/dist/types/src/models'
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import {
|
||||
Box3,
|
||||
@ -29,6 +32,7 @@ import { commandBarMachine } from 'machines/commandBarMachine'
|
||||
import { EventFrom } from 'xstate'
|
||||
import { fileMachine } from 'machines/fileMachine'
|
||||
import { reportRejection } from 'lib/trap'
|
||||
import { codeManager, kclManager } from 'lib/singletons'
|
||||
|
||||
const CANVAS_SIZE = 128
|
||||
const PROMPT_TRUNCATE_LENGTH = 128
|
||||
@ -411,3 +415,69 @@ function traverseSceneToStyleObjects({
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function ToastPromptToEditCadSuccess({
|
||||
toastId,
|
||||
token,
|
||||
data,
|
||||
oldCode,
|
||||
}: {
|
||||
toastId: string
|
||||
oldCode: string
|
||||
data: TextToCadIteration_type
|
||||
token?: string
|
||||
}) {
|
||||
const modelId = data.id
|
||||
|
||||
return (
|
||||
<div className="flex gap-4 min-w-80">
|
||||
<div className="flex flex-col justify-between gap-6">
|
||||
<section>
|
||||
<h2>Prompt to edit successful</h2>
|
||||
<p className="text-sm text-chalkboard-70 dark:text-chalkboard-30">
|
||||
Prompt: "
|
||||
{data?.prompt && data?.prompt?.length > PROMPT_TRUNCATE_LENGTH
|
||||
? data.prompt.slice(0, PROMPT_TRUNCATE_LENGTH) + '...'
|
||||
: data.prompt}
|
||||
"
|
||||
</p>
|
||||
<p>Do you want to keep the change?</p>
|
||||
</section>
|
||||
<div className="flex justify-between gap-8">
|
||||
<ActionButton
|
||||
Element="button"
|
||||
iconStart={{
|
||||
icon: 'close',
|
||||
}}
|
||||
data-negative-button={'reject'}
|
||||
name={'Reject'}
|
||||
onClick={() => {
|
||||
// TODO add telemetry when we know how sendTelemetry is setup for /user/text-to-cad/
|
||||
// sendTelemetry(modelId, 'rejected', token).catch(reportRejection)
|
||||
codeManager.updateCodeEditor(oldCode)
|
||||
kclManager.executeCode().catch(reportRejection)
|
||||
toast.dismiss(toastId)
|
||||
}}
|
||||
>
|
||||
{'Reject'}
|
||||
</ActionButton>
|
||||
|
||||
<ActionButton
|
||||
Element="button"
|
||||
iconStart={{
|
||||
icon: 'checkmark',
|
||||
}}
|
||||
name="Accept"
|
||||
onClick={() => {
|
||||
// TODO add telemetry when we know how sendTelemetry is setup for /user/text-to-cad/
|
||||
sendTelemetry(modelId, 'accepted', token).catch(reportRejection)
|
||||
toast.dismiss(toastId)
|
||||
}}
|
||||
>
|
||||
Accept
|
||||
</ActionButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user