[Feature]: Enable Text-to-CAD at the application level (#6501)

* chore: saving off skeleton

* fix: saving skeleton

* chore: skeleton for loading projects from project directory path

* chore: cleaning up useless state transition to be an on event direct to action state

* fix: new structure for web vs desktop vs react machine provider code

* chore: saving off skeleton

* fix: skeleton logic for react? going to move it from a string to obj.string

* fix: trying to prevent error element unmount on global react components. This is bricking JS state

* fix: we are so back

* chore: implemented navigating to specfic KCL file

* chore: implementing renaming project

* chore: deleting project

* fix: auto fixes

* fix: old debug/testing file oops

* chore: generic create new file

* chore: skeleton for web create file provide

* chore: basic machine vitest... need to figure out how to get window.electron implemented in vitest?

* chore: save off progress before deleting other project implementation, a few missing features still

* chore: trying a different init skeleton? most likely will migrate

* chore: first attempt of purging projects context provider

* chore: enabling toast for some machine state

* chore: enabling more toast success and error

* chore: writing read write state to the system io based on the project path

* fix: tsc fixes

* fix: use file system watcher, navigate to project after creation via the requestProjectName

* chore: open project command, hooks vs snapshot context helpers

* chore: implemented open and create project for e2e testing. They are hard coded in poor spot for now.

* fix: codespell fixes

* chore: implementing more project commands

* chore: PR improvements for root.tsx

* chore: leaving comment about new Router.tsx layout

* fix: removing debugging code

* fix: rewriting component for readability

* fix: improving web initialization

* chore: implementing import file from url which is not actually that?

* fix: clearing search params on import file from url

* fix: fixed two e2e tests, forgot needsReview when making new command

* fix: fixing some import from url business logic to pass e2e tests

* chore: script for diffing circular deps +/-

* fix: formatting

* fix: massive fix for circular depsga!

* fix: trying to fix some errors and auto fmt

* fix: updating deps

* fix: removing debugging code

* fix: big clean up

* fix: more deletion

* fix: tsc cleanup

* fix: TSC TSC TSC TSC!

* fix: typo fix

* fix: clear query params on web only, desktop not required

* fix: removing unused code

* fmt

* Bring back `trap` removed in merge

* Use explicit types instead of `any`s on arg configs

* Add project commands directly to command palette

* fix: deleting debugging code, from PR review

* fix: this got added back(?)

* fix: using referred type

* fix: more PR clean up

* fix: big block comment for xstate architecture decision

* fix: more pr comment fixes

* fix: saving off logic, need a big cleanup because I hacked it together to get a POC

* fix: extra business?

* fix: merge conflict just added them back why dude

* fix: more PR comments

* fix: big ciruclar deps fix, commandBarActor in appActor

* chore: writing e2e test, still need to fix 3 bugs

* chore: adding more scenarios

* fix: formatting

* fix: fixing tsc errors

* chore: deleting the old text to cad and using the new application level one, almost there

* fix: prompt to edit works

* fix: large push to get 1 text to cad command... the usage is a little buggy with delete and navigate within /file

* fix: settings for highlight edges now works

* chore: adding another e2e test

* fix: cleaning up e2e tests and writing more of them

* fix: tsc type

* chore: more e2e improvements, unique project name  in text to cad

* chore: e2e tests should be good to go

* fix: gotcha comment

* fix: enabled web t2c, codespell fixes

* fix: fixing merge conflcits??

* fix: t2c is back

* Remove spaces in command bar test

* fmt

---------

Co-authored-by: Frank Noirot <frankjohnson1993@gmail.com>
Co-authored-by: lee-at-zoo-corp <lee@zoo.dev>
This commit is contained in:
Kevin Nadro
2025-04-25 18:04:47 -05:00
committed by GitHub
parent f8e53d941d
commit 5a4f8bd522
20 changed files with 1218 additions and 242 deletions

View File

@ -21,20 +21,17 @@ import {
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader'
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'
import { codeManager, kclManager, systemIOActor } from '@src/lib/singletons'
import { sendTelemetry } from '@src/lib/textToCadTelemetry'
import type { Themes } from '@src/lib/theme'
import { reportRejection } from '@src/lib/trap'
import { commandBarActor } from '@src/lib/singletons'
import type { fileMachine } from '@src/machines/fileMachine'
import { SystemIOMachineEvents } from '@src/machines/systemIO/utils'
import { useProjectDirectoryPath } from '@src/machines/systemIO/hooks'
const CANVAS_SIZE = 128
const PROMPT_TRUNCATE_LENGTH = 128
@ -82,10 +79,16 @@ export function ToastTextToCadError({
toastId,
message,
prompt,
method,
projectName,
newProjectName,
}: {
toastId: string
message: string
prompt: string
method: string
projectName: string
newProjectName: string
}) {
return (
<div className="flex flex-col justify-between gap-6">
@ -118,10 +121,13 @@ export function ToastTextToCadError({
commandBarActor.send({
type: 'Find and select command',
data: {
groupId: 'modeling',
groupId: 'application',
name: 'Text-to-CAD',
argDefaultValues: {
prompt,
method,
projectName,
newProjectName,
},
},
})
@ -139,24 +145,22 @@ export function ToastTextToCadSuccess({
toastId,
data,
navigate,
context,
token,
fileMachineSend,
settings,
projectName,
fileName,
isProjectNew,
}: {
toastId: string
data: TextToCad_type & { fileName: string }
navigate: (to: string) => void
context: ReturnType<typeof useFileContext>['context']
token?: string
fileMachineSend: (
event: EventFrom<typeof fileMachine>,
data?: unknown
) => void
settings: {
theme: Themes
settings?: {
highlightEdges: boolean
}
projectName: string
fileName: string
isProjectNew: boolean
}) {
const wrapperRef = useRef<HTMLDivElement | null>(null)
const canvasRef = useRef<HTMLCanvasElement | null>(null)
@ -164,6 +168,7 @@ export function ToastTextToCadSuccess({
const [hasCopied, setHasCopied] = useState(false)
const [showCopiedUi, setShowCopiedUi] = useState(false)
const modelId = data.id
const projectDirectoryPath = useProjectDirectoryPath()
const animate = useCallback(
({
@ -198,7 +203,11 @@ export function ToastTextToCadSuccess({
if (!canvasRef.current) return
const canvas = canvasRef.current
const renderer = new WebGLRenderer({ canvas, antialias: true, alpha: true })
const renderer = new WebGLRenderer({
canvas,
antialias: true,
alpha: true,
})
renderer.setSize(CANVAS_SIZE, CANVAS_SIZE)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
@ -344,15 +353,30 @@ export function ToastTextToCadSuccess({
}
if (isDesktop()) {
// Delete the file from the project
fileMachineSend({
type: 'Delete file',
data: {
name: data.fileName,
path: `${context.project.path}${window.electron.sep}${data.fileName}`,
children: null,
},
})
if (projectName && fileName) {
// You are in the new workflow for text to cad at the global application level
if (isProjectNew) {
// Delete the entire project if it was newly created from text to CAD
systemIOActor.send({
type: SystemIOMachineEvents.deleteProject,
data: {
requestedProjectName: projectName,
},
})
} else {
// Only delete the file if the project was preexisting
systemIOActor.send({
type: SystemIOMachineEvents.deleteKCLFile,
data: {
requestedProjectName: projectName,
requestedFileName: fileName,
},
})
}
}
}
toast.dismiss(toastId)
}}
>
@ -368,11 +392,9 @@ export function ToastTextToCadSuccess({
onClick={() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
sendTelemetry(modelId, 'accepted', token)
navigate(
`${PATHS.FILE}/${encodeURIComponent(
`${context.project.path}${window.electron.sep}${data.fileName}`
)}`
)
const path = `${projectDirectoryPath}${window.electron.path.sep}${projectName}${window.electron.sep}${fileName}`
navigate(`${PATHS.FILE}/${encodeURIComponent(path)}`)
toast.dismiss(toastId)
}}
>
@ -426,7 +448,6 @@ function traverseSceneToStyleObjects({
}: {
scene: Scene
color?: number
theme: Themes
highlightEdges?: boolean
}) {
scene.traverse((child) => {