2025-04-01 23:54:26 -07:00
|
|
|
import type {
|
2025-04-01 15:31:19 -07:00
|
|
|
TextToCadIteration_type,
|
2025-04-01 23:54:26 -07:00
|
|
|
TextToCad_type,
|
2025-04-01 15:31:19 -07:00
|
|
|
} from '@kittycad/lib/dist/types/src/models'
|
|
|
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
2025-04-01 23:54:26 -07:00
|
|
|
import toast from 'react-hot-toast'
|
|
|
|
import type { Mesh } from 'three'
|
2024-08-14 14:26:44 -04:00
|
|
|
import {
|
|
|
|
Box3,
|
|
|
|
Color,
|
|
|
|
DirectionalLight,
|
|
|
|
EdgesGeometry,
|
|
|
|
LineBasicMaterial,
|
|
|
|
LineSegments,
|
|
|
|
MeshBasicMaterial,
|
|
|
|
OrthographicCamera,
|
|
|
|
Scene,
|
|
|
|
Vector3,
|
|
|
|
WebGLRenderer,
|
|
|
|
} from 'three'
|
2025-04-01 23:54:26 -07:00
|
|
|
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
|
2024-08-14 14:26:44 -04:00
|
|
|
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader'
|
2025-04-01 23:54:26 -07:00
|
|
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
|
|
|
|
import type { EventFrom } from 'xstate'
|
|
|
|
|
|
|
|
import { ActionButton } from '@src/components/ActionButton'
|
|
|
|
import type { useFileContext } from '@src/hooks/useFileContext'
|
|
|
|
import { base64Decode } from '@src/lang/wasm'
|
|
|
|
import { isDesktop } from '@src/lib/isDesktop'
|
|
|
|
import { openExternalBrowserIfDesktop } from '@src/lib/openWindow'
|
|
|
|
import { PATHS } from '@src/lib/paths'
|
|
|
|
import { codeManager, kclManager } from '@src/lib/singletons'
|
2025-04-02 15:10:57 -07:00
|
|
|
import { sendTelemetry } from '@src/lib/textToCadTelemetry'
|
2025-04-01 23:54:26 -07:00
|
|
|
import type { Themes } from '@src/lib/theme'
|
|
|
|
import { reportRejection } from '@src/lib/trap'
|
|
|
|
import { commandBarActor } from '@src/machines/commandBarMachine'
|
|
|
|
import type { fileMachine } from '@src/machines/fileMachine'
|
2024-08-14 14:26:44 -04:00
|
|
|
|
|
|
|
const CANVAS_SIZE = 128
|
|
|
|
const PROMPT_TRUNCATE_LENGTH = 128
|
|
|
|
const FRUSTUM_SIZE = 0.5
|
|
|
|
const OUTPUT_KEY = 'source.glb'
|
|
|
|
|
2025-02-28 16:26:11 -05:00
|
|
|
function TextToCadImprovementMessage({
|
|
|
|
label,
|
|
|
|
...rest
|
|
|
|
}: React.HTMLAttributes<HTMLDetailsElement> & { label: string }) {
|
|
|
|
return (
|
|
|
|
<details {...rest}>
|
|
|
|
<summary className="text-chalkboard-70 dark:text-chalkboard-30">
|
|
|
|
{label}
|
|
|
|
</summary>
|
|
|
|
<p className="text-sm text-chalkboard-70 dark:text-chalkboard-30">
|
|
|
|
Text-to-CAD is a new ML model. There will be prompts that work and
|
|
|
|
prompts that don't and prompts that generate something a little bit off.
|
|
|
|
Sometimes even a small tweak to your prompt will make it better on the
|
|
|
|
next run. Try our prompt-to-edit feature to iterate on your result with
|
|
|
|
AI. We look at all the failures to make the model better and see our
|
|
|
|
weaknesses. Over time the model will get better. See our{' '}
|
|
|
|
<a
|
|
|
|
href="https://discord.gg/JQEpHR7Nt2"
|
|
|
|
onClick={openExternalBrowserIfDesktop(
|
|
|
|
'https://discord.gg/JQEpHR7Nt2'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
Discord
|
|
|
|
</a>{' '}
|
|
|
|
or{' '}
|
|
|
|
<a
|
|
|
|
href="https://community.zoo.dev/"
|
|
|
|
onClick={openExternalBrowserIfDesktop('https://community.zoo.dev/')}
|
|
|
|
>
|
|
|
|
Discourse
|
|
|
|
</a>{' '}
|
|
|
|
or some prompting tips from the community or our team.
|
|
|
|
</p>
|
|
|
|
</details>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-08-14 14:26:44 -04:00
|
|
|
export function ToastTextToCadError({
|
2024-08-14 23:08:37 -07:00
|
|
|
toastId,
|
2024-08-14 14:26:44 -04:00
|
|
|
message,
|
|
|
|
prompt,
|
|
|
|
}: {
|
2024-08-14 23:08:37 -07:00
|
|
|
toastId: string
|
2024-08-14 14:26:44 -04:00
|
|
|
message: string
|
|
|
|
prompt: string
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<div className="flex flex-col justify-between gap-6">
|
|
|
|
<section>
|
|
|
|
<h2>Text-to-CAD failed</h2>
|
|
|
|
<p className="text-sm text-chalkboard-70 dark:text-chalkboard-30">
|
|
|
|
{message}
|
|
|
|
</p>
|
|
|
|
</section>
|
|
|
|
<div className="flex justify-between gap-8">
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
iconStart={{
|
|
|
|
icon: 'close',
|
|
|
|
}}
|
|
|
|
name="Dismiss"
|
|
|
|
onClick={() => {
|
2024-08-14 23:08:37 -07:00
|
|
|
toast.dismiss(toastId)
|
2024-08-14 14:26:44 -04:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
Dismiss
|
|
|
|
</ActionButton>
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
iconStart={{
|
|
|
|
icon: 'refresh',
|
|
|
|
}}
|
|
|
|
name="Edit prompt"
|
|
|
|
onClick={() => {
|
2025-01-23 10:25:21 -05:00
|
|
|
commandBarActor.send({
|
2024-08-14 14:26:44 -04:00
|
|
|
type: 'Find and select command',
|
|
|
|
data: {
|
|
|
|
groupId: 'modeling',
|
|
|
|
name: 'Text-to-CAD',
|
|
|
|
argDefaultValues: {
|
|
|
|
prompt,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2024-08-14 23:08:37 -07:00
|
|
|
toast.dismiss(toastId)
|
2024-08-14 14:26:44 -04:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
Edit prompt
|
|
|
|
</ActionButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ToastTextToCadSuccess({
|
2024-08-14 23:08:37 -07:00
|
|
|
toastId,
|
2024-08-14 14:26:44 -04:00
|
|
|
data,
|
|
|
|
navigate,
|
|
|
|
context,
|
|
|
|
token,
|
|
|
|
fileMachineSend,
|
|
|
|
settings,
|
|
|
|
}: {
|
2024-08-14 23:08:37 -07:00
|
|
|
toastId: string
|
2024-08-14 14:26:44 -04:00
|
|
|
data: TextToCad_type & { fileName: string }
|
|
|
|
navigate: (to: string) => void
|
|
|
|
context: ReturnType<typeof useFileContext>['context']
|
|
|
|
token?: string
|
|
|
|
fileMachineSend: (
|
|
|
|
event: EventFrom<typeof fileMachine>,
|
2024-09-09 19:59:36 +03:00
|
|
|
data?: unknown
|
2024-08-14 14:26:44 -04:00
|
|
|
) => void
|
|
|
|
settings: {
|
|
|
|
theme: Themes
|
|
|
|
highlightEdges: boolean
|
|
|
|
}
|
|
|
|
}) {
|
|
|
|
const wrapperRef = useRef<HTMLDivElement | null>(null)
|
|
|
|
const canvasRef = useRef<HTMLCanvasElement | null>(null)
|
2024-08-19 09:38:47 -04:00
|
|
|
const animationRequestRef = useRef<number>()
|
2024-08-14 14:26:44 -04:00
|
|
|
const [hasCopied, setHasCopied] = useState(false)
|
|
|
|
const [showCopiedUi, setShowCopiedUi] = useState(false)
|
|
|
|
const modelId = data.id
|
|
|
|
|
2024-08-19 09:38:47 -04:00
|
|
|
const animate = useCallback(
|
|
|
|
({
|
|
|
|
renderer,
|
|
|
|
scene,
|
|
|
|
camera,
|
|
|
|
controls,
|
|
|
|
isFirstRender = false,
|
|
|
|
}: {
|
|
|
|
renderer: WebGLRenderer
|
|
|
|
scene: Scene
|
|
|
|
camera: OrthographicCamera
|
|
|
|
controls: OrbitControls
|
|
|
|
isFirstRender?: boolean
|
|
|
|
}) => {
|
|
|
|
if (
|
|
|
|
!wrapperRef.current ||
|
|
|
|
!(isFirstRender || animationRequestRef.current)
|
|
|
|
)
|
|
|
|
return
|
|
|
|
animationRequestRef.current = requestAnimationFrame(() =>
|
|
|
|
animate({ renderer, scene, camera, controls })
|
|
|
|
)
|
|
|
|
// required if controls.enableDamping or controls.autoRotate are set to true
|
|
|
|
controls.update()
|
|
|
|
renderer.render(scene, camera)
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
|
2024-08-14 14:26:44 -04:00
|
|
|
useEffect(() => {
|
|
|
|
if (!canvasRef.current) return
|
|
|
|
|
|
|
|
const canvas = canvasRef.current
|
|
|
|
const renderer = new WebGLRenderer({ canvas, antialias: true, alpha: true })
|
|
|
|
renderer.setSize(CANVAS_SIZE, CANVAS_SIZE)
|
|
|
|
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
|
|
|
|
|
|
|
|
const scene = new Scene()
|
|
|
|
const ambientLight = new DirectionalLight(new Color('white'), 8.0)
|
|
|
|
scene.add(ambientLight)
|
|
|
|
const camera = createCamera()
|
|
|
|
const controls = new OrbitControls(camera, renderer.domElement)
|
|
|
|
controls.enableDamping = true
|
|
|
|
const loader = new GLTFLoader()
|
|
|
|
const dracoLoader = new DRACOLoader()
|
|
|
|
dracoLoader.setDecoderPath('/examples/jsm/libs/draco/')
|
|
|
|
loader.setDRACOLoader(dracoLoader)
|
|
|
|
scene.add(camera)
|
|
|
|
|
|
|
|
// Get the base64 encoded GLB file
|
|
|
|
const buffer = base64Decode(data.outputs[OUTPUT_KEY])
|
|
|
|
|
|
|
|
if (buffer instanceof Error) {
|
|
|
|
toast.error('Error loading GLB file: ' + buffer.message)
|
|
|
|
console.error('decoding buffer from base64 failed', buffer)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
loader.parse(
|
|
|
|
buffer,
|
|
|
|
'',
|
|
|
|
// called when the resource is loaded
|
|
|
|
function (gltf) {
|
|
|
|
scene.add(gltf.scene)
|
|
|
|
|
|
|
|
// Style the objects in the scene
|
|
|
|
traverseSceneToStyleObjects({
|
|
|
|
scene,
|
|
|
|
...settings,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Then we'll calculate the max distance of the bounding box
|
|
|
|
// and set that as the camera's position
|
|
|
|
const size = new Vector3()
|
|
|
|
const boundingBox = new Box3()
|
|
|
|
boundingBox.setFromObject(gltf.scene)
|
|
|
|
boundingBox.getSize(size)
|
|
|
|
const maxDistance = Math.max(size.x, size.y, size.z)
|
|
|
|
|
|
|
|
camera.position.set(maxDistance * 2, maxDistance * 2, maxDistance * 2)
|
|
|
|
camera.lookAt(0, 0, 0)
|
|
|
|
camera.left = -maxDistance
|
|
|
|
camera.right = maxDistance
|
|
|
|
camera.top = maxDistance
|
|
|
|
camera.bottom = -maxDistance
|
|
|
|
camera.near = 0
|
|
|
|
camera.far = maxDistance * 10
|
|
|
|
|
|
|
|
// Create and attach the lights,
|
|
|
|
// since their position depends on the bounding box
|
|
|
|
const cameraLight1 = new DirectionalLight(new Color('white'), 1)
|
|
|
|
cameraLight1.position.set(maxDistance * -5, -maxDistance, maxDistance)
|
|
|
|
camera.add(cameraLight1)
|
|
|
|
|
|
|
|
const cameraLight2 = new DirectionalLight(new Color('white'), 1.4)
|
|
|
|
cameraLight2.position.set(0, 0, 2 * maxDistance)
|
|
|
|
camera.add(cameraLight2)
|
|
|
|
|
|
|
|
const sceneLight = new DirectionalLight(new Color('white'), 1)
|
|
|
|
sceneLight.position.set(
|
|
|
|
-2 * maxDistance,
|
|
|
|
-2 * maxDistance,
|
|
|
|
2 * maxDistance
|
|
|
|
)
|
|
|
|
scene.add(sceneLight)
|
|
|
|
|
|
|
|
camera.updateProjectionMatrix()
|
|
|
|
controls.update()
|
2024-08-19 09:38:47 -04:00
|
|
|
// render the scene once...
|
|
|
|
renderer.render(scene, camera)
|
2024-08-14 14:26:44 -04:00
|
|
|
},
|
|
|
|
// called when loading has errors
|
|
|
|
function (error) {
|
|
|
|
toast.error('Error loading GLB file: ' + error.message)
|
|
|
|
console.error('Error loading GLB file', error)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-08-19 09:38:47 -04:00
|
|
|
// ...and set a mouseover listener on the canvas to enable the orbit controls
|
|
|
|
canvasRef.current.addEventListener('mouseover', () => {
|
|
|
|
renderer.setAnimationLoop(() =>
|
|
|
|
animate({ renderer, scene, camera, controls, isFirstRender: true })
|
|
|
|
)
|
|
|
|
})
|
|
|
|
canvasRef.current.addEventListener('mouseout', () => {
|
|
|
|
renderer.setAnimationLoop(null)
|
|
|
|
if (animationRequestRef.current) {
|
|
|
|
cancelAnimationFrame(animationRequestRef.current)
|
|
|
|
animationRequestRef.current = undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-08-14 14:26:44 -04:00
|
|
|
return () => {
|
|
|
|
renderer.dispose()
|
2024-08-19 09:38:47 -04:00
|
|
|
if (animationRequestRef.current) {
|
|
|
|
cancelAnimationFrame(animationRequestRef.current)
|
|
|
|
animationRequestRef.current = undefined
|
|
|
|
}
|
2024-08-14 14:26:44 -04:00
|
|
|
}
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex gap-4 min-w-80" ref={wrapperRef}>
|
|
|
|
<div
|
|
|
|
className="flex-none overflow-hidden"
|
|
|
|
style={{ width: CANVAS_SIZE + 'px', height: CANVAS_SIZE + 'px' }}
|
|
|
|
>
|
|
|
|
<canvas ref={canvasRef} width={CANVAS_SIZE} height={CANVAS_SIZE} />
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col justify-between gap-6">
|
|
|
|
<section>
|
|
|
|
<h2>Text-to-CAD successful</h2>
|
|
|
|
<p className="text-sm text-chalkboard-70 dark:text-chalkboard-30">
|
|
|
|
Prompt: "
|
|
|
|
{data.prompt.length > PROMPT_TRUNCATE_LENGTH
|
|
|
|
? data.prompt.slice(0, PROMPT_TRUNCATE_LENGTH) + '...'
|
|
|
|
: data.prompt}
|
|
|
|
"
|
|
|
|
</p>
|
2025-02-28 16:26:11 -05:00
|
|
|
<TextToCadImprovementMessage
|
|
|
|
className="text-sm mt-2"
|
|
|
|
label="Not what you expected?"
|
|
|
|
/>
|
2024-08-14 14:26:44 -04:00
|
|
|
</section>
|
|
|
|
<div className="flex justify-between gap-8">
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
iconStart={{
|
|
|
|
icon: 'close',
|
|
|
|
}}
|
2024-08-19 22:38:17 +10:00
|
|
|
data-negative-button={hasCopied ? 'close' : 'reject'}
|
2024-08-14 14:26:44 -04:00
|
|
|
name={hasCopied ? 'Close' : 'Reject'}
|
|
|
|
onClick={() => {
|
|
|
|
if (!hasCopied) {
|
2024-09-09 18:17:45 -04:00
|
|
|
sendTelemetry(modelId, 'rejected', token).catch(reportRejection)
|
2024-08-14 14:26:44 -04:00
|
|
|
}
|
2024-08-16 07:15:42 -04:00
|
|
|
if (isDesktop()) {
|
2024-08-14 14:26:44 -04:00
|
|
|
// Delete the file from the project
|
|
|
|
fileMachineSend({
|
|
|
|
type: 'Delete file',
|
|
|
|
data: {
|
|
|
|
name: data.fileName,
|
2024-08-16 07:15:42 -04:00
|
|
|
path: `${context.project.path}${window.electron.sep}${data.fileName}`,
|
2024-08-14 14:26:44 -04:00
|
|
|
children: null,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2024-08-14 23:08:37 -07:00
|
|
|
toast.dismiss(toastId)
|
2024-08-14 14:26:44 -04:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{hasCopied ? 'Close' : 'Reject'}
|
|
|
|
</ActionButton>
|
2024-08-16 07:15:42 -04:00
|
|
|
{isDesktop() ? (
|
2024-08-14 14:26:44 -04:00
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
iconStart={{
|
|
|
|
icon: 'checkmark',
|
|
|
|
}}
|
|
|
|
name="Accept"
|
|
|
|
onClick={() => {
|
2024-09-09 18:17:45 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
2024-08-14 14:26:44 -04:00
|
|
|
sendTelemetry(modelId, 'accepted', token)
|
|
|
|
navigate(
|
|
|
|
`${PATHS.FILE}/${encodeURIComponent(
|
2024-08-16 07:15:42 -04:00
|
|
|
`${context.project.path}${window.electron.sep}${data.fileName}`
|
2024-08-14 14:26:44 -04:00
|
|
|
)}`
|
|
|
|
)
|
2024-08-14 23:08:37 -07:00
|
|
|
toast.dismiss(toastId)
|
2024-08-14 14:26:44 -04:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
Accept
|
|
|
|
</ActionButton>
|
|
|
|
) : (
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
iconStart={{
|
|
|
|
icon: showCopiedUi ? 'clipboardCheckmark' : 'clipboardPlus',
|
|
|
|
}}
|
|
|
|
name="Copy to clipboard"
|
|
|
|
onClick={() => {
|
2024-09-09 18:17:45 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
2024-08-14 14:26:44 -04:00
|
|
|
sendTelemetry(modelId, 'accepted', token)
|
2024-09-09 18:17:45 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
2024-08-14 14:26:44 -04:00
|
|
|
navigator.clipboard.writeText(data.code || '// no code found')
|
|
|
|
setShowCopiedUi(true)
|
|
|
|
setHasCopied(true)
|
|
|
|
|
|
|
|
// Reset the button text after 5 seconds
|
|
|
|
setTimeout(() => {
|
|
|
|
setShowCopiedUi(false)
|
|
|
|
}, 5000)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{showCopiedUi ? 'Copied' : 'Copy to clipboard'}
|
|
|
|
</ActionButton>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const createCamera = (): OrthographicCamera => {
|
|
|
|
return new OrthographicCamera(
|
|
|
|
-FRUSTUM_SIZE,
|
|
|
|
FRUSTUM_SIZE,
|
|
|
|
FRUSTUM_SIZE,
|
|
|
|
-FRUSTUM_SIZE,
|
|
|
|
0.5,
|
|
|
|
3
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function traverseSceneToStyleObjects({
|
|
|
|
scene,
|
|
|
|
color = 0x29ffa4,
|
|
|
|
highlightEdges = false,
|
|
|
|
}: {
|
|
|
|
scene: Scene
|
|
|
|
color?: number
|
|
|
|
theme: Themes
|
|
|
|
highlightEdges?: boolean
|
|
|
|
}) {
|
|
|
|
scene.traverse((child) => {
|
|
|
|
if ('isMesh' in child && child.isMesh) {
|
|
|
|
// Replace the material with our flat color one
|
|
|
|
;(child as Mesh).material = new MeshBasicMaterial({
|
|
|
|
color,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Add edges to the mesh if the option is enabled
|
|
|
|
if (!highlightEdges) return
|
|
|
|
const edges = new EdgesGeometry((child as Mesh).geometry, 30)
|
|
|
|
const lines = new LineSegments(
|
|
|
|
edges,
|
|
|
|
new LineBasicMaterial({
|
|
|
|
// We don't respect the theme here on purpose,
|
|
|
|
// because I found the dark edges to work better
|
|
|
|
// in light and dark themes,
|
|
|
|
// but we can change that if needed, it is wired up
|
|
|
|
color: 0x1f2020,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
scene.add(lines)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2024-12-20 13:39:06 +11:00
|
|
|
|
|
|
|
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>
|
2025-02-28 16:26:11 -05:00
|
|
|
<TextToCadImprovementMessage
|
|
|
|
className="text-sm mt-2"
|
|
|
|
label="Not what you expected?"
|
|
|
|
/>
|
2024-12-20 13:39:06 +11:00
|
|
|
<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={() => {
|
2024-12-20 14:50:05 +11:00
|
|
|
sendTelemetry(modelId, 'rejected', token).catch(reportRejection)
|
2024-12-20 13:39:06 +11:00
|
|
|
codeManager.updateCodeEditor(oldCode)
|
|
|
|
kclManager.executeCode().catch(reportRejection)
|
|
|
|
toast.dismiss(toastId)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{'Reject'}
|
|
|
|
</ActionButton>
|
|
|
|
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
iconStart={{
|
|
|
|
icon: 'checkmark',
|
|
|
|
}}
|
|
|
|
name="Accept"
|
|
|
|
onClick={() => {
|
|
|
|
sendTelemetry(modelId, 'accepted', token).catch(reportRejection)
|
|
|
|
toast.dismiss(toastId)
|
2025-01-06 13:26:22 -05:00
|
|
|
|
|
|
|
// Write new content to disk since they have accepted.
|
|
|
|
codeManager
|
|
|
|
.writeToFile()
|
|
|
|
.then(() => {
|
|
|
|
// no-op
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
console.error('Failed to save prompt-to-edit to disk')
|
|
|
|
console.error(e)
|
|
|
|
})
|
2024-12-20 13:39:06 +11:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
Accept
|
|
|
|
</ActionButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|