Merge branch 'main' into jess/cleaned-imports

This commit is contained in:
Paul Tagliamonte
2025-04-14 12:50:05 -04:00
committed by GitHub
20 changed files with 164 additions and 245 deletions

View File

@ -82,7 +82,7 @@ sketch001 = startSketchOn(XY)
.poll(() => .poll(() =>
page.locator('[data-receive-command-type="scene_clear_all"]').count() page.locator('[data-receive-command-type="scene_clear_all"]').count()
) )
.toBe(1) .toBe(2)
await expect await expect
.poll(() => page.locator('[data-message-type="execution-done"]').count()) .poll(() => page.locator('[data-message-type="execution-done"]').count())
.toBe(2) .toBe(2)
@ -106,7 +106,7 @@ sketch001 = startSketchOn(XY)
).toHaveCount(3) ).toHaveCount(3)
await expect( await expect(
page.locator('[data-receive-command-type="scene_clear_all"]') page.locator('[data-receive-command-type="scene_clear_all"]')
).toHaveCount(1) ).toHaveCount(2)
}) })
test('ensure we use the cache, and do not clear on append', async ({ test('ensure we use the cache, and do not clear on append', async ({
@ -133,7 +133,7 @@ sketch001 = startSketchOn(XY)
await u.openDebugPanel() await u.openDebugPanel()
await expect( await expect(
page.locator('[data-receive-command-type="scene_clear_all"]') page.locator('[data-receive-command-type="scene_clear_all"]')
).toHaveCount(1) ).toHaveCount(2)
await expect( await expect(
page.locator('[data-message-type="execution-done"]') page.locator('[data-message-type="execution-done"]')
).toHaveCount(2) ).toHaveCount(2)
@ -161,7 +161,7 @@ sketch001 = startSketchOn(XY)
).toHaveCount(3) ).toHaveCount(3)
await expect( await expect(
page.locator('[data-receive-command-type="scene_clear_all"]') page.locator('[data-receive-command-type="scene_clear_all"]')
).toHaveCount(1) ).toHaveCount(2)
}) })
test('if you click the format button it formats your code', async ({ test('if you click the format button it formats your code', async ({

View File

@ -1,33 +0,0 @@
{
"original_source_code": "sketch001 = startSketchOn(XZ)\nprofile001 = startProfileAt([57.81, 250.51], sketch001)\n |> line(end = [121.13, 56.63], tag = $seg02)\n |> line(end = [83.37, -34.61], tag = $seg01)\n |> line(end = [19.66, -116.4])\n |> line(end = [-221.8, -41.69])\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\nextrude001 = extrude(profile001, length = 200)\nsketch002 = startSketchOn('XZ')\n |> startProfileAt([-73.64, -42.89], %)\n |> xLine(length = 173.71)\n |> line(end = [-22.12, -94.4])\n |> xLine(length = -156.98)\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\nextrude002 = extrude(sketch002, length = 50)\nsketch003 = startSketchOn(XY)\n |> startProfileAt([52.92, 157.81], %)\n |> angledLine(angle = 0, length = 176.4, tag = $rectangleSegmentA001)\n |> angledLine(angle = segAng(rectangleSegmentA001) - 90,\n length = 53.4\n ], tag = $rectangleSegmentB001)\n |> angledLine(angle = segAng(rectangleSegmentA001),\n length = -segLen(rectangleSegmentA001)\n tag = $rectangleSegmentC001)\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\nextrude003 = extrude(sketch003, length = 20)\n",
"prompt": "make this neon green please, use #39FF14",
"source_ranges": [
{
"prompt": "The users main selection is the end cap of a general-sweep (that is an extrusion, revolve, sweep or loft).\nThe source range most likely refers to \"startProfileAt\" simply because this is the start of the profile that was swept.\nIf you need to operate on this cap, for example for sketching on the face, you can use the special string END i.e. `startSketchOn(someSweepVariable, END)`\nWhen they made this selection they main have intended this surface directly or meant something more general like the sweep body.\nSee later source ranges for more context.",
"range": {
"start": {
"line": 11,
"column": 5
},
"end": {
"line": 11,
"column": 40
}
}
},
{
"prompt": "This is the sweep's source range from the user's main selection of the end cap.",
"range": {
"start": {
"line": 17,
"column": 13
},
"end": {
"line": 17,
"column": 44
}
}
}
],
"kcl_version": "0.2.48"
}

View File

@ -1,9 +1,9 @@
{ {
"original_source_code": "sketch001 = startSketchOn(XZ)\nprofile001 = startProfileAt([57.81, 250.51], sketch001)\n |> line(end = [121.13, 56.63], tag = $seg02)\n |> line(end = [83.37, -34.61], tag = $seg01)\n |> line(end = [19.66, -116.4])\n |> line(end = [-221.8, -41.69])\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\nextrude001 = extrude(profile001, length = 200)\nsketch002 = startSketchOn(XZ)\n |> startProfileAt([-73.64, -42.89], %)\n |> xLine(length = 173.71)\n |> line(end = [-22.12, -94.4])\n |> xLine(length = -156.98)\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\nextrude002 = extrude(sketch002, length = 50)\nsketch003 = startSketchOn(XY)\n |> startProfileAt([52.92, 157.81], %)\n |> angledLine(angle = 0, 176.4], %, $rectangleSegmentA001)\n |> angledLine([\n segAng(rectangleSegmentA001) - 90,\n 53.4\n ], %, length = $rectangleSegmentB001)\n |> angledLine(\n angle = segAng(rectangleSegmentA001),\n length = -segLen(rectangleSegmentA001),\n tag = $rectangleSegmentC001)\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\nextrude003 = extrude(sketch003, length = 20)\n", "original_source_code": "sketch001 = startSketchOn(XZ)\nprofile001 = startProfileAt([57.81, 250.51], sketch001)\n |> line(end = [121.13, 56.63], tag = $seg02)\n |> line(end = [83.37, -34.61], tag = $seg01)\n |> line(end = [19.66, -116.4])\n |> line(end = [-221.8, -41.69])\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\nextrude001 = extrude(profile001, length = 200)\nsketch002 = startSketchOn(XZ)\n |> startProfileAt([-73.64, -42.89], %)\n |> xLine(length = 173.71)\n |> line(end = [-22.12, -94.4])\n |> xLine(length = -156.98)\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\nextrude002 = extrude(sketch002, length = 50)\nsketch003 = startSketchOn(XY)\n |> startProfileAt([52.92, 157.81], %)\n |> angledLine(angle = 0, length = 176.4, tag = $rectangleSegmentA001)\n |> angledLine(\n angle = segAng(rectangleSegmentA001) - 90,\n length = 53.4,\n tag = $rectangleSegmentB001,\n )\n |> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $rectangleSegmentC001)\n |> line(endAbsolute = [profileStartX(%), profileStartY(%)])\n |> close()\nextrude003 = extrude(sketch003, length = 20)\n",
"prompt": "make this neon green please, use #39FF14", "prompt": "make this neon green please, use #39FF14",
"source_ranges": [ "source_ranges": [
{ {
"prompt": "The users main selection is the end cap of a general-sweep (that is an extrusion, revolve, sweep or loft).\nThe source range most likely refers to \"startProfileAt\" simply because this is the start of the profile that was swept.\nIf you need to operate on this cap, for example for sketching on the face, you can use the special string END i.e. `startSketchOn(someSweepVariable, END)`\nWhen they made this selection they main have intended this surface directly or meant something more general like the sweep body.\nSee later source ranges for more context.", "prompt": "The users main selection is the end cap of a general-sweep (that is an extrusion, revolve, sweep or loft).\nThe source range most likely refers to \"startProfileAt\" simply because this is the start of the profile that was swept.\nIf you need to operate on this cap, for example for sketching on the face, you can use the special string END i.e. `startSketchOn(someSweepVariable, face = END)`\nWhen they made this selection they main have intended this surface directly or meant something more general like the sweep body.\nSee later source ranges for more context.",
"range": { "range": {
"start": { "start": {
"line": 11, "line": 11,
@ -29,5 +29,6 @@
} }
} }
], ],
"kcl_version": "0.2.57" "project_name": "testDefault",
} "kcl_version": "0.2.61"
}

40
rust/Cargo.lock generated
View File

@ -133,9 +133,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.97" version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
dependencies = [ dependencies = [
"backtrace", "backtrace",
] ]
@ -482,9 +482,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.32" version = "4.5.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83" checksum = "2df961d8c8a0d08aa9945718ccf584145eee3f3aa06cddbeac12933781102e04"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@ -492,9 +492,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.32" version = "4.5.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8" checksum = "132dbda40fb6753878316a489d5a1242a8ef2f0d9e47ba01c951ea8aa7d013a5"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@ -995,9 +995,9 @@ dependencies = [
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.1.0" version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc" checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"miniz_oxide", "miniz_oxide",
@ -1615,9 +1615,9 @@ dependencies = [
[[package]] [[package]]
name = "image" name = "image"
version = "0.25.5" version = "0.25.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd6f44aed642f18953a158afeb30206f4d50da59fbc66ecb53c66488de73563b" checksum = "db35664ce6b9810857a38a906215e75a9c879f0696556a39f59c62829710251a"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"byteorder-lite", "byteorder-lite",
@ -2034,9 +2034,9 @@ dependencies = [
[[package]] [[package]]
name = "kittycad-modeling-cmds" name = "kittycad-modeling-cmds"
version = "0.2.113" version = "0.2.114"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa1c927569925425a1b03711617c384a30cb7554394e8a6a01266910b22421de" checksum = "681ce29b9da92aa6f8bfc003ccb79a9f1a84368e064d68684327b3181dfe16ec"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@ -2157,9 +2157,9 @@ checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e"
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.26" version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
dependencies = [ dependencies = [
"serde", "serde",
] ]
@ -2415,9 +2415,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.21.1" version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]] [[package]]
name = "oncemutex" name = "oncemutex"
@ -3910,9 +3910,9 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.40" version = "0.3.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d9c75b47bdff86fa3334a3db91356b8d7d86a9b839dab7d0bdc5c3d3a077618" checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40"
dependencies = [ dependencies = [
"deranged", "deranged",
"itoa", "itoa",
@ -3931,9 +3931,9 @@ checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c"
[[package]] [[package]]
name = "time-macros" name = "time-macros"
version = "0.2.21" version = "0.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29aa485584182073ed57fd5004aa09c371f021325014694e432313345865fd04" checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49"
dependencies = [ dependencies = [
"num-conv", "num-conv",
"time-core", "time-core",

View File

@ -30,12 +30,12 @@ debug = "line-tables-only"
async-trait = "0.1.88" async-trait = "0.1.88"
anyhow = { version = "1" } anyhow = { version = "1" }
bson = { version = "2.13.0", features = ["uuid-1", "chrono"] } bson = { version = "2.13.0", features = ["uuid-1", "chrono"] }
clap = { version = "4.5.31", features = ["derive"] } clap = { version = "4.5.36", features = ["derive"] }
dashmap = { version = "6.1.0" } dashmap = { version = "6.1.0" }
http = "1" http = "1"
indexmap = "2.7.0" indexmap = "2.7.0"
kittycad = { version = "0.3.36", default-features = false, features = ["js", "requests"] } kittycad = { version = "0.3.36", default-features = false, features = ["js", "requests"] }
kittycad-modeling-cmds = { version = "0.2.113", features = ["ts-rs", "websocket"] } kittycad-modeling-cmds = { version = "0.2.114", features = ["ts-rs", "websocket"] }
lazy_static = "1.5.0" lazy_static = "1.5.0"
miette = "7.5.0" miette = "7.5.0"
pyo3 = { version = "0.24.1" } pyo3 = { version = "0.24.1" }

View File

@ -14,7 +14,7 @@ bench = false
[dependencies] [dependencies]
Inflector = "0.11.4" Inflector = "0.11.4"
convert_case = "0.8.0" convert_case = "0.8.0"
once_cell = "1.20.3" once_cell = "1.21.3"
proc-macro2 = "1" proc-macro2 = "1"
quote = "1" quote = "1"
regex = "1.11" regex = "1.11"

View File

@ -14,14 +14,14 @@ bench = false
[dependencies] [dependencies]
anyhow = { workspace = true } anyhow = { workspace = true }
clap = { workspace = true, features = ["cargo", "derive", "env", "unicode"] } clap = { workspace = true, features = ["cargo", "derive", "env", "unicode"] }
flate2 = "1.1.0" flate2 = "1.1.1"
lazy_static = { workspace = true } lazy_static = { workspace = true }
log = { version = "0.4.26", features = ["serde"] } log = { version = "0.4.27", features = ["serde"] }
slog = { workspace = true } slog = { workspace = true }
slog-async = { workspace = true } slog-async = { workspace = true }
slog-json = { workspace = true } slog-json = { workspace = true }
slog-term = { workspace = true } slog-term = { workspace = true }
time = "0.3.40" time = "0.3.41"
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
tracing-subscriber = { workspace = true } tracing-subscriber = { workspace = true }
xshell = "0.2.6" xshell = "0.2.6"

View File

@ -23,7 +23,7 @@ kcl-lib = { path = "../kcl-lib", default-features = false, features = [
] } ] }
kittycad = { workspace = true } kittycad = { workspace = true }
lazy_static = { workspace = true } lazy_static = { workspace = true }
log = { version = "0.4.26", features = ["serde"] } log = { version = "0.4.27", features = ["serde"] }
slog = { workspace = true } slog = { workspace = true }
slog-async = { workspace = true } slog-async = { workspace = true }
slog-json = { workspace = true } slog-json = { workspace = true }

View File

@ -26,7 +26,7 @@ async-trait = { workspace = true }
base64 = "0.22.1" base64 = "0.22.1"
bson = { workspace = true } bson = { workspace = true }
chrono = "0.4.38" chrono = "0.4.38"
clap = { version = "4.5.27", default-features = false, optional = true, features = [ clap = { version = "4.5.36", default-features = false, optional = true, features = [
"std", "std",
"derive", "derive",
] } ] }
@ -39,7 +39,7 @@ futures = { version = "0.3.31" }
git_rev = "0.1.0" git_rev = "0.1.0"
gltf-json = "1.4.1" gltf-json = "1.4.1"
http = { workspace = true } http = { workspace = true }
image = { version = "0.25.5", default-features = false, features = ["png"] } image = { version = "0.25.6", default-features = false, features = ["png"] }
indexmap = { workspace = true, features = ["serde"] } indexmap = { workspace = true, features = ["serde"] }
itertools = "0.13.0" itertools = "0.13.0"
kcl-derive-docs = { version = "0.1", path = "../kcl-derive-docs" } kcl-derive-docs = { version = "0.1", path = "../kcl-derive-docs" }
@ -122,7 +122,7 @@ base64 = "0.22.1"
criterion = { version = "0.5.1", features = ["async_tokio"] } criterion = { version = "0.5.1", features = ["async_tokio"] }
expectorate = "1.1.0" expectorate = "1.1.0"
handlebars = "6.3.2" handlebars = "6.3.2"
image = { version = "0.25.5", default-features = false, features = ["png"] } image = { version = "0.25.6", default-features = false, features = ["png"] }
insta = { version = "1.41.1", features = ["json", "filters", "redactions"] } insta = { version = "1.41.1", features = ["json", "filters", "redactions"] }
kcl-directory-test-macro = { version = "0.1", path = "../kcl-directory-test-macro" } kcl-directory-test-macro = { version = "0.1", path = "../kcl-directory-test-macro" }
miette = { version = "7.5.0", features = ["fancy"] } miette = { version = "7.5.0", features = ["fancy"] }

View File

@ -9,7 +9,7 @@ license = "MIT"
bench = false bench = false
[dependencies] [dependencies]
anyhow = "1.0.95" anyhow = "1.0.98"
hyper = { version = "0.14.29", features = ["http1", "server", "tcp"] } hyper = { version = "0.14.29", features = ["http1", "server", "tcp"] }
kcl-lib = { version = "0.2", path = "../kcl-lib" } kcl-lib = { version = "0.2", path = "../kcl-lib" }
pico-args = "0.5.0" pico-args = "0.5.0"

View File

@ -1,6 +1,6 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import type { CommandLog } from '@src/lang/std/engineConnection' import type { CommandLog } from '@src/lang/std/commandLog'
import { engineCommandManager } from '@src/lib/singletons' import { engineCommandManager } from '@src/lib/singletons'
import { reportRejection } from '@src/lib/trap' import { reportRejection } from '@src/lib/trap'

View File

@ -101,7 +101,10 @@ export function SettingsFieldInput({
type: `set.${category}.${settingName}`, type: `set.${category}.${settingName}`,
data: { data: {
level: settingsLevel, level: settingsLevel,
value: e.target.value, // undefined is the only special string due to no way to
// encode it in the string-only options.
value:
e.target.value === 'undefined' ? undefined : e.target.value,
}, },
} as unknown as EventFrom<WildcardSetEvent>) } as unknown as EventFrom<WildcardSetEvent>)
} }

View File

@ -27,6 +27,8 @@ import {
} from '@src/lib/singletons' } from '@src/lib/singletons'
import { err, reportRejection } from '@src/lib/trap' import { err, reportRejection } from '@src/lib/trap'
import { getModuleId } from '@src/lib/utils' import { getModuleId } from '@src/lib/utils'
import { engineStreamActor } from '@src/machines/appMachine'
import { EngineStreamState } from '@src/machines/engineStreamMachine'
import type { import type {
EdgeCutInfo, EdgeCutInfo,
ExtrudeFacePlane, ExtrudeFacePlane,
@ -38,8 +40,11 @@ export function useEngineConnectionSubscriptions() {
const stateRef = useRef(state) const stateRef = useRef(state)
stateRef.current = state stateRef.current = state
const engineStreamState = engineStreamActor.getSnapshot()
useEffect(() => { useEffect(() => {
if (!engineCommandManager) return if (!engineCommandManager) return
if (engineStreamState.value !== EngineStreamState.Playing) return
const unSubHover = engineCommandManager.subscribeToUnreliable({ const unSubHover = engineCommandManager.subscribeToUnreliable({
// Note this is our hover logic, "highlight_set_entity" is the event that is fired when we hover over an entity // Note this is our hover logic, "highlight_set_entity" is the event that is fired when we hover over an entity
@ -76,9 +81,12 @@ export function useEngineConnectionSubscriptions() {
unSubHover() unSubHover()
unSubClick() unSubClick()
} }
}, [engineCommandManager, context?.sketchEnginePathId]) }, [engineCommandManager, engineStreamState, context?.sketchEnginePathId])
useEffect(() => { useEffect(() => {
if (!engineCommandManager) return
if (engineStreamState.value !== EngineStreamState.Playing) return
const unSub = engineCommandManager.subscribeTo({ const unSub = engineCommandManager.subscribeTo({
event: 'select_with_point', event: 'select_with_point',
callback: state.matches('Sketch no face') callback: state.matches('Sketch no face')
@ -342,5 +350,5 @@ export function useEngineConnectionSubscriptions() {
: () => {}, : () => {},
}) })
return unSub return unSub
}, [state]) }, [engineCommandManager, engineStreamState, state])
} }

View File

@ -19,8 +19,8 @@ import {
} from '@src/lang/errors' } from '@src/lang/errors'
import { executeAst, executeAstMock, lintAst } from '@src/lang/langHelpers' import { executeAst, executeAstMock, lintAst } from '@src/lang/langHelpers'
import { getNodeFromPath, getSettingsAnnotation } from '@src/lang/queryAst' import { getNodeFromPath, getSettingsAnnotation } from '@src/lang/queryAst'
import { CommandLogType } from '@src/lang/std/commandLog'
import type { EngineCommandManager } from '@src/lang/std/engineConnection' import type { EngineCommandManager } from '@src/lang/std/engineConnection'
import { CommandLogType } from '@src/lang/std/engineConnection'
import { topLevelRange } from '@src/lang/util' import { topLevelRange } from '@src/lang/util'
import type { import type {
ArtifactGraph, ArtifactGraph,

View File

@ -0,0 +1,31 @@
import type { Models } from '@kittycad/lib'
import type { EngineCommand } from '@src/lang/std/artifactGraph'
export enum CommandLogType {
SendModeling = 'send-modeling',
SendScene = 'send-scene',
ReceiveReliable = 'receive-reliable',
ExecutionDone = 'execution-done',
ExportDone = 'export-done',
SetDefaultSystemProperties = 'set_default_system_properties',
}
export type CommandLog =
| {
type: CommandLogType.SendModeling
data: EngineCommand
}
| {
type: CommandLogType.SendScene
data: EngineCommand
}
| {
type: CommandLogType.ReceiveReliable
data: Models['OkWebSocketResponseData_type']
id: string
cmd_type?: string
}
| {
type: CommandLogType.ExecutionDone
data: null
}

View File

@ -1,15 +1,20 @@
import type { Models } from '@kittycad/lib' import type { Models } from '@kittycad/lib'
import { VITE_KC_API_WS_MODELING_URL, VITE_KC_DEV_TOKEN } from '@src/env' import { VITE_KC_API_WS_MODELING_URL, VITE_KC_DEV_TOKEN } from '@src/env'
import { jsAppSettings } from '@src/lib/settings/settingsUtils'
import { BSON } from 'bson' import { BSON } from 'bson'
import type { MachineManager } from '@src/components/MachineManagerProvider' import type { MachineManager } from '@src/components/MachineManagerProvider'
import type { useModelingContext } from '@src/hooks/useModelingContext' import type { useModelingContext } from '@src/hooks/useModelingContext'
import type CodeManager from '@src/lang/codeManager'
import type { KclManager } from '@src/lang/KclSingleton' import type { KclManager } from '@src/lang/KclSingleton'
import type { EngineCommand, ResponseMap } from '@src/lang/std/artifactGraph' import type { EngineCommand, ResponseMap } from '@src/lang/std/artifactGraph'
import type { CommandLog } from '@src/lang/std/commandLog'
import { CommandLogType } from '@src/lang/std/commandLog'
import type { SourceRange } from '@src/lang/wasm' import type { SourceRange } from '@src/lang/wasm'
import { defaultSourceRange } from '@src/lang/wasm' import { defaultSourceRange } from '@src/lang/wasm'
import { EXECUTE_AST_INTERRUPT_ERROR_MESSAGE } from '@src/lib/constants' import { EXECUTE_AST_INTERRUPT_ERROR_MESSAGE } from '@src/lib/constants'
import { markOnce } from '@src/lib/performance' import { markOnce } from '@src/lib/performance'
import type RustContext from '@src/lib/rustContext'
import type { SettingsViaQueryString } from '@src/lib/settings/settingsTypes' import type { SettingsViaQueryString } from '@src/lib/settings/settingsTypes'
import { import {
Themes, Themes,
@ -28,8 +33,6 @@ function isHighlightSetEntity_type(
return data.entity_id && data.sequence return data.entity_id && data.sequence
} }
type OkWebSocketResponseData = Models['OkWebSocketResponseData_type']
interface NewTrackArgs { interface NewTrackArgs {
conn: EngineConnection conn: EngineConnection
mediaStream: MediaStream mediaStream: MediaStream
@ -658,6 +661,22 @@ class EngineConnection extends EventTarget {
detail: { conn: this, mediaStream: this.mediaStream! }, detail: { conn: this, mediaStream: this.mediaStream! },
}) })
) )
setTimeout(() => {
// Everything is now connected.
this.state = {
type: EngineConnectionStateType.ConnectionEstablished,
}
this.engineCommandManager.inSequence = 1
this.dispatchEvent(
new CustomEvent(EngineConnectionEvents.Opened, {
detail: this,
})
)
markOnce('code/endInitialEngineConnect')
}, 2000)
break break
case 'connecting': case 'connecting':
break break
@ -785,18 +804,6 @@ class EngineConnection extends EventTarget {
type: ConnectingType.DataChannelEstablished, type: ConnectingType.DataChannelEstablished,
}, },
} }
// Everything is now connected.
this.state = {
type: EngineConnectionStateType.ConnectionEstablished,
}
this.engineCommandManager.inSequence = 1
this.dispatchEvent(
new CustomEvent(EngineConnectionEvents.Opened, { detail: this })
)
markOnce('code/endInitialEngineConnect')
} }
this.unreliableDataChannel?.addEventListener( this.unreliableDataChannel?.addEventListener(
'open', 'open',
@ -1269,35 +1276,6 @@ export interface Subscription<T extends ModelTypes> {
) => void ) => void
} }
export enum CommandLogType {
SendModeling = 'send-modeling',
SendScene = 'send-scene',
ReceiveReliable = 'receive-reliable',
ExecutionDone = 'execution-done',
ExportDone = 'export-done',
SetDefaultSystemProperties = 'set_default_system_properties',
}
export type CommandLog =
| {
type: CommandLogType.SendModeling
data: EngineCommand
}
| {
type: CommandLogType.SendScene
data: EngineCommand
}
| {
type: CommandLogType.ReceiveReliable
data: OkWebSocketResponseData
id: string
cmd_type?: string
}
| {
type: CommandLogType.ExecutionDone
data: null
}
export enum EngineCommandManagerEvents { export enum EngineCommandManagerEvents {
// engineConnection is available but scene setup may not have run // engineConnection is available but scene setup may not have run
EngineAvailable = 'engine-available', EngineAvailable = 'engine-available',
@ -1398,6 +1376,7 @@ export class EngineCommandManager extends EventTarget {
private onEngineConnectionOpened = () => {} private onEngineConnectionOpened = () => {}
private onEngineConnectionClosed = () => {} private onEngineConnectionClosed = () => {}
private onVideoTrackMute = () => {}
private onDarkThemeMediaQueryChange = (e: MediaQueryListEvent) => { private onDarkThemeMediaQueryChange = (e: MediaQueryListEvent) => {
this.setTheme(e.matches ? Themes.Dark : Themes.Light).catch(reportRejection) this.setTheme(e.matches ? Themes.Dark : Themes.Light).catch(reportRejection)
} }
@ -1408,6 +1387,8 @@ export class EngineCommandManager extends EventTarget {
modelingSend: ReturnType<typeof useModelingContext>['send'] = modelingSend: ReturnType<typeof useModelingContext>['send'] =
(() => {}) as any (() => {}) as any
kclManager: null | KclManager = null kclManager: null | KclManager = null
codeManager?: CodeManager
rustContext?: RustContext
// The current "manufacturing machine" aka 3D printer, CNC, etc. // The current "manufacturing machine" aka 3D printer, CNC, etc.
public machineManager: MachineManager | null = null public machineManager: MachineManager | null = null
@ -1480,6 +1461,11 @@ export class EngineCommandManager extends EventTarget {
// eslint-disable-next-line @typescript-eslint/no-misused-promises // eslint-disable-next-line @typescript-eslint/no-misused-promises
this.onEngineConnectionOpened = async () => { this.onEngineConnectionOpened = async () => {
await this.rustContext?.clearSceneAndBustCache(
{ settings: await jsAppSettings() },
this.codeManager?.currentFilePath || undefined
)
// Set the stream's camera projection type // Set the stream's camera projection type
// We don't send a command to the engine if in perspective mode because // We don't send a command to the engine if in perspective mode because
// for now it's the engine's default. // for now it's the engine's default.
@ -1695,15 +1681,17 @@ export class EngineCommandManager extends EventTarget {
delete this.pendingCommands[message.request_id || ''] delete this.pendingCommands[message.request_id || '']
}) as EventListener) }) as EventListener)
this.onVideoTrackMute = () => {
console.error('video track mute: check webrtc internals -> inbound rtp')
}
this.onEngineConnectionNewTrack = ({ this.onEngineConnectionNewTrack = ({
detail: { mediaStream }, detail: { mediaStream },
}: CustomEvent<NewTrackArgs>) => { }: CustomEvent<NewTrackArgs>) => {
mediaStream.getVideoTracks()[0].addEventListener('mute', () => { // Engine side had an oopsie (client sent trickle_ice, engine no happy)
console.error( mediaStream
'video track mute: check webrtc internals -> inbound rtp' .getVideoTracks()[0]
) .addEventListener('mute', this.onVideoTrackMute)
})
setMediaStream(mediaStream) setMediaStream(mediaStream)
} }
this.engineConnection?.addEventListener( this.engineConnection?.addEventListener(

View File

@ -5,10 +5,8 @@ import type { OsInfo } from '@rust/kcl-lib/bindings/OsInfo'
import type { WebrtcStats } from '@rust/kcl-lib/bindings/WebrtcStats' import type { WebrtcStats } from '@rust/kcl-lib/bindings/WebrtcStats'
import type CodeManager from '@src/lang/codeManager' import type CodeManager from '@src/lang/codeManager'
import type { import type { CommandLog } from '@src/lang/std/commandLog'
CommandLog, import type { EngineCommandManager } from '@src/lang/std/engineConnection'
EngineCommandManager,
} from '@src/lang/std/engineConnection'
import { isDesktop } from '@src/lib/isDesktop' import { isDesktop } from '@src/lib/isDesktop'
import type RustContext from '@src/lib/rustContext' import type RustContext from '@src/lib/rustContext'
import screenshot from '@src/lib/screenshot' import screenshot from '@src/lib/screenshot'

View File

@ -1,4 +1,4 @@
import { useRef, useState } from 'react' import { useRef } from 'react'
import type { CameraOrbitType } from '@rust/kcl-lib/bindings/CameraOrbitType' import type { CameraOrbitType } from '@rust/kcl-lib/bindings/CameraOrbitType'
import type { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType' import type { CameraProjectionType } from '@rust/kcl-lib/bindings/CameraProjectionType'
@ -6,7 +6,6 @@ import type { NamedView } from '@rust/kcl-lib/bindings/NamedView'
import type { OnboardingStatus } from '@rust/kcl-lib/bindings/OnboardingStatus' import type { OnboardingStatus } from '@rust/kcl-lib/bindings/OnboardingStatus'
import { CustomIcon } from '@src/components/CustomIcon' import { CustomIcon } from '@src/components/CustomIcon'
import { Toggle } from '@src/components/Toggle/Toggle'
import Tooltip from '@src/components/Tooltip' import Tooltip from '@src/components/Tooltip'
import type { CameraSystem } from '@src/lib/cameraControls' import type { CameraSystem } from '@src/lib/cameraControls'
import { cameraMouseDragGuards, cameraSystems } from '@src/lib/cameraControls' import { cameraMouseDragGuards, cameraSystems } from '@src/lib/cameraControls'
@ -216,104 +215,37 @@ export function createSettings() {
hideOnLevel: 'project', hideOnLevel: 'project',
description: 'Save bandwidth & battery', description: 'Save bandwidth & battery',
validate: (v) => validate: (v) =>
v === undefined || String(v) == 'undefined' ||
(typeof v === 'number' && (Number(v) >= 0 && Number(v) <= 60 * MS_IN_MINUTE),
v >= 1 * MS_IN_MINUTE && commandConfig: {
v <= 60 * MS_IN_MINUTE), inputType: 'options',
Component: ({ defaultValueFromContext: (context) =>
value: settingValueInStorage, context.app.streamIdleMode.current,
updateValue: writeSettingValueToStorage, options: (cmdContext, settingsContext) =>
}) => { [
const [timeoutId, setTimeoutId] = useState< undefined,
ReturnType<typeof setTimeout> | undefined 5 * 1000,
>(undefined) 30 * 1000,
const [preview, setPreview] = useState( 1 * MS_IN_MINUTE,
settingValueInStorage === undefined 2 * MS_IN_MINUTE,
? settingValueInStorage 5 * MS_IN_MINUTE,
: settingValueInStorage / MS_IN_MINUTE 15 * MS_IN_MINUTE,
) 30 * MS_IN_MINUTE,
const onChangeRange = (e: React.SyntheticEvent) => { 60 * MS_IN_MINUTE,
if ( ].map((v) => ({
!( name:
e.isTrusted && v === undefined
'value' in e.currentTarget && ? 'Off'
e.currentTarget.value : v < MS_IN_MINUTE
) ? `${Math.floor(v / 1000)} seconds`
) : `${Math.floor(v / MS_IN_MINUTE)} minutes`,
return value: v,
setPreview(Number(e.currentTarget.value)) isCurrent:
} v ===
const onSaveRange = (e: React.SyntheticEvent) => { settingsContext.app.streamIdleMode[
if (preview === undefined) return cmdContext.argumentsToSubmit.level as SettingsLevel
if ( ],
!( })),
e.isTrusted &&
'value' in e.currentTarget &&
e.currentTarget.value
)
)
return
writeSettingValueToStorage(
Number(e.currentTarget.value) * MS_IN_MINUTE
)
}
return (
<div className="flex item-center gap-4 m-0 py-0">
<Toggle
name="streamIdleModeToggle"
offLabel="Off"
onLabel="On"
checked={settingValueInStorage !== undefined}
onChange={(event: React.SyntheticEvent<HTMLInputElement>) => {
if (timeoutId) {
return
}
const isChecked = event.currentTarget.checked
clearTimeout(timeoutId)
setTimeoutId(
setTimeout(() => {
const requested = !isChecked ? undefined : 5
setPreview(requested)
writeSettingValueToStorage(
requested === undefined
? undefined
: Number(requested) * MS_IN_MINUTE
)
setTimeoutId(undefined)
}, 100)
)
}}
className="block w-4 h-4"
/>
<div className="flex flex-col grow">
<input
type="range"
onChange={onChangeRange}
onMouseUp={onSaveRange}
onKeyUp={onSaveRange}
onPointerUp={onSaveRange}
disabled={preview === undefined}
value={
preview !== null && preview !== undefined ? preview : 5
}
min={1}
max={60}
step={1}
className="block flex-1"
/>
{preview !== undefined && preview !== null && (
<div>
{preview / MS_IN_MINUTE === 60
? '1 hour'
: preview / MS_IN_MINUTE === 1
? '1 minute'
: preview + ' minutes'}
</div>
)}
</div>
</div>
)
}, },
}), }),
allowOrbitInSketchMode: new Setting<boolean>({ allowOrbitInSketchMode: new Setting<boolean>({

View File

@ -44,7 +44,12 @@ export const kclManager = new KclManager(engineCommandManager, {
// CYCLIC REF // CYCLIC REF
editorManager.kclManager = kclManager editorManager.kclManager = kclManager
// These are all late binding because of their circular dependency.
// TODO: proper dependency injection.
engineCommandManager.kclManager = kclManager engineCommandManager.kclManager = kclManager
engineCommandManager.codeManager = codeManager
engineCommandManager.rustContext = rustContext
kclManager.sceneInfraBaseUnitMultiplierSetter = (unit: BaseUnit) => { kclManager.sceneInfraBaseUnitMultiplierSetter = (unit: BaseUnit) => {
sceneInfra.baseUnit = unit sceneInfra.baseUnit = unit
} }

View File

@ -1,10 +1,4 @@
import { jsAppSettings } from '@src/lib/settings/settingsUtils' import { engineCommandManager, sceneInfra } from '@src/lib/singletons'
import {
codeManager,
engineCommandManager,
rustContext,
sceneInfra,
} from '@src/lib/singletons'
import type { MutableRefObject } from 'react' import type { MutableRefObject } from 'react'
import type { ActorRefFrom } from 'xstate' import type { ActorRefFrom } from 'xstate'
import { assign, fromPromise, setup } from 'xstate' import { assign, fromPromise, setup } from 'xstate'
@ -129,14 +123,6 @@ export const engineStreamMachine = setup({
await holdOntoVideoFrameInCanvas(video, canvas) await holdOntoVideoFrameInCanvas(video, canvas)
video.style.display = 'none' video.style.display = 'none'
// Before doing anything else clear the cache
// Originally I (lee) had this on the reconnect but it was interfering
// with kclManager.executeCode()?
await rustContext.clearSceneAndBustCache(
{ settings: await jsAppSettings() },
codeManager.currentFilePath || undefined
)
await sceneInfra.camControls.saveRemoteCameraState() await sceneInfra.camControls.saveRemoteCameraState()
// Make sure we're on the next frame for no flickering between canvas // Make sure we're on the next frame for no flickering between canvas