Migrate Text-to-CAD (edit) to multi-file endpoint (#6066)

* start of migrate to multi file endpoint

* get some relative path stuff sorted

* blobifying files, and making selections work with imports working

* add write to disk

* warn about big projects

* update known circular

* update snapshot

* remove log

* tweak selection filters

* Update src/components/ModelingMachineProvider.tsx

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>

* fmt

* fix one thing

* typo

* raw dog form data like a fucking peasant

* remove fake data

* fmt

* steal Kevin's stuff

* good progress

* clean up

* fix writing to files when response returns

* comment the terriable code

* push fix of sorts

* better fix

* spot of clean up

* fix: Needed to support the bad request flow, the toast will hang forever, the return control flows don't dismiss a forever toast

* fix: handling more error flows by dismissing the toast

* chore: leaving a comment for a confusing workflow

* fix: trying to clean up some async logic

* fix: trying to fix a few things at once...

* fix: fixing toast success

* fix: how did this desync?

* fix: removing useless logic, we write to disk ahead of time, the continue is to say ya no problem

* fix: typo

* Change back to `spawnChild`, forego `actors` by reference

* fix: updating PR comments

* fix: found a bug with paths from rust! it is actually OS paths!

* fix: updated type still is failing tsc

* fix: the type of the machine was wrong, we always set it to at least ''

* fix: idk man

* Fix happy path test (button labels)

---------

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Frank Noirot <frankjohnson1993@gmail.com>
Co-authored-by: Kevin Nadro <nadr0@users.noreply.github.com>
Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
This commit is contained in:
Kurt Hutten
2025-05-08 03:54:40 +10:00
committed by GitHub
parent f938364d54
commit 43d5a72514
19 changed files with 931 additions and 307 deletions

View File

@ -12,8 +12,8 @@ import { SceneInfra } from '@src/clientSideScene/sceneInfra'
import type { BaseUnit } from '@src/lib/settings/settingsTypes'
import { useSelector } from '@xstate/react'
import type { SnapshotFrom } from 'xstate'
import { createActor, setup, assign } from 'xstate'
import type { ActorRefFrom, SnapshotFrom } from 'xstate'
import { createActor, setup, spawnChild } from 'xstate'
import { isDesktop } from '@src/lib/isDesktop'
import { createSettings } from '@src/lib/settings/initialSettings'
@ -131,7 +131,6 @@ const appMachine = setup({
types: {} as {
context: AppMachineContext
},
actors: appMachineActors,
}).createMachine({
id: 'modeling-app',
context: {
@ -143,49 +142,35 @@ const appMachine = setup({
},
entry: [
/**
* We originally wanted to use spawnChild but the inferred type blew up. The more children we
* created the type complexity went through the roof. This functionally should act the same.
* the system and parent internals are tracked properly. After reading the documentation
* it suggests either method but this method requires manual clean up as described in the gotcha
* comment block below. If this becomes an issue we can always move this spawn into createActor functions
* in javascript above and reference those directly but the system and parent internals within xstate
* will not work.
* We have been battling XState's type unions exploding in size,
* so for these global actors, we have decided to forego creating them by reference
* using the `actors` property in the `setup` function, and
* inline them instead.
*/
assign({
// Gotcha, if you use spawn, make sure you remove the ActorRef from context
// to prevent memory leaks when the spawned actor is no longer needed
authActor: ({ spawn }) => spawn(AUTH, { id: AUTH, systemId: AUTH }),
settingsActor: ({ spawn }) =>
spawn(SETTINGS, {
id: SETTINGS,
systemId: SETTINGS,
input: createSettings(),
}),
systemIOActor: ({ spawn }) =>
spawn(SYSTEM_IO, { id: SYSTEM_IO, systemId: SYSTEM_IO }),
engineStreamActor: ({ spawn }) =>
spawn(ENGINE_STREAM, {
id: ENGINE_STREAM,
systemId: ENGINE_STREAM,
input: engineStreamContextCreate(),
}),
commandBarActor: ({ spawn }) =>
spawn(COMMAND_BAR, {
id: COMMAND_BAR,
systemId: COMMAND_BAR,
input: {
commands: [],
},
}),
billingActor: ({ spawn }) =>
spawn(BILLING, {
id: BILLING,
systemId: BILLING,
input: {
...BILLING_CONTEXT_DEFAULTS,
urlUserService: VITE_KC_API_BASE_URL,
},
}),
spawnChild(appMachineActors[AUTH], { systemId: AUTH }),
spawnChild(appMachineActors[SETTINGS], {
systemId: SETTINGS,
input: createSettings(),
}),
spawnChild(appMachineActors[ENGINE_STREAM], {
systemId: ENGINE_STREAM,
input: engineStreamContextCreate(),
}),
spawnChild(appMachineActors[SYSTEM_IO], {
systemId: SYSTEM_IO,
}),
spawnChild(appMachineActors[COMMAND_BAR], {
systemId: COMMAND_BAR,
input: {
commands: [],
},
}),
spawnChild(appMachineActors[BILLING], {
systemId: BILLING,
input: {
...BILLING_CONTEXT_DEFAULTS,
urlUserService: VITE_KC_API_BASE_URL,
},
}),
],
})
@ -199,7 +184,9 @@ export const appActor = createActor(appMachine, {
* the lifetime of {appActor}, but would not work if it were invoked
* or if it were destroyed under any conditions during {appActor}'s life
*/
export const authActor = appActor.getSnapshot().context.authActor!
export const authActor = appActor.system.get(AUTH) as ActorRefFrom<
(typeof appMachineActors)[typeof AUTH]
>
export const useAuthState = () => useSelector(authActor, (state) => state)
export const useToken = () =>
useSelector(authActor, (state) => state.context.token)
@ -211,7 +198,9 @@ export const useUser = () =>
* the lifetime of {appActor}, but would not work if it were invoked
* or if it were destroyed under any conditions during {appActor}'s life
*/
export const settingsActor = appActor.getSnapshot().context.settingsActor!
export const settingsActor = appActor.system.get(SETTINGS) as ActorRefFrom<
(typeof appMachineActors)[typeof SETTINGS]
>
export const getSettings = () => {
const { currentProject: _, ...settings } = settingsActor.getSnapshot().context
return settings
@ -223,14 +212,21 @@ export const useSettings = () =>
return settings
})
export const systemIOActor = appActor.getSnapshot().context.systemIOActor!
export const systemIOActor = appActor.system.get(SYSTEM_IO) as ActorRefFrom<
(typeof appMachineActors)[typeof SYSTEM_IO]
>
export const engineStreamActor =
appActor.getSnapshot().context.engineStreamActor!
export const engineStreamActor = appActor.system.get(
ENGINE_STREAM
) as ActorRefFrom<(typeof appMachineActors)[typeof ENGINE_STREAM]>
export const commandBarActor = appActor.getSnapshot().context.commandBarActor!
export const commandBarActor = appActor.system.get(COMMAND_BAR) as ActorRefFrom<
(typeof appMachineActors)[typeof COMMAND_BAR]
>
export const billingActor = appActor.system.get(BILLING)
export const billingActor = appActor.system.get(BILLING) as ActorRefFrom<
(typeof appMachineActors)[typeof BILLING]
>
const cmdBarStateSelector = (state: SnapshotFrom<typeof commandBarActor>) =>
state