topotopo 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +40 -10
- package/README.md +475 -111
- package/dist/cli.js +328 -133
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/analysis.d.ts +5 -1
- package/dist/core/analysis.js +8 -3
- package/dist/core/bake.d.ts +16 -8
- package/dist/core/bake.js +165 -29
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +238 -97
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +204 -4
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/imageops.d.ts +6 -0
- package/dist/core/imageops.js +51 -0
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +11 -0
- package/dist/core/materials.js +56 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/packed.js +11 -0
- package/dist/core/particles.d.ts +1 -1
- package/dist/core/particles.js +1 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/rbd.js +13 -1
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scatter.d.ts +1 -1
- package/dist/core/scatter.js +1 -1
- package/dist/core/scene.d.ts +20 -0
- package/dist/core/scene.js +72 -0
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +15 -2
- package/dist/core/snippet-lib.js +40 -14
- package/dist/core/solidify.d.ts +38 -0
- package/dist/core/solidify.js +356 -0
- package/dist/core/tangents.d.ts +54 -0
- package/dist/core/tangents.js +218 -0
- package/dist/core/texcoord.d.ts +4 -0
- package/dist/core/texcoord.js +14 -0
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +32 -0
- package/dist/core/topology.js +238 -7
- package/dist/core/traceimage.d.ts +7 -0
- package/dist/core/traceimage.js +221 -0
- package/dist/core/tritri.d.ts +5 -0
- package/dist/core/tritri.js +120 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +15 -16
- package/dist/core/uv.js +36 -189
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +127 -0
- package/dist/core/uvreport.js +372 -0
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +95 -61
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -2
- package/dist/inspect.d.ts +84 -1
- package/dist/inspect.js +271 -24
- package/dist/io/common.d.ts +33 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +355 -51
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +149 -14
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +816 -119
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +70 -24
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +207 -108
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +207 -83
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +54 -5
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +22 -10
- package/dist/nodes/curves.js +440 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +13 -39
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.d.ts +1 -0
- package/dist/nodes/imageops.js +203 -0
- package/dist/nodes/index.d.ts +4 -0
- package/dist/nodes/index.js +4 -0
- package/dist/nodes/material.js +91 -23
- package/dist/nodes/measure.js +45 -18
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/rbd.js +1 -1
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.d.ts +1 -0
- package/dist/nodes/scene.js +55 -0
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/solidify.d.ts +1 -0
- package/dist/nodes/solidify.js +52 -0
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +11 -3
- package/dist/nodes/util.d.ts +1 -1
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +6 -2
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +44 -5
- package/dist/render/pbr.d.ts +28 -0
- package/dist/render/pbr.js +378 -0
- package/dist/render/preview.d.ts +69 -0
- package/dist/render/preview.js +26 -0
- package/dist/render/raster.d.ts +78 -7
- package/dist/render/raster.js +600 -145
- package/dist/render/texview.d.ts +7 -1
- package/dist/render/texview.js +34 -2
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/camera.js +1 -1
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +100 -0
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +6 -2
- package/dist/viewer/app/guides.js +123 -1
- package/dist/viewer/app/keymap.js +7 -4
- package/dist/viewer/app/layers.js +5 -5
- package/dist/viewer/app/main.js +186 -53
- package/dist/viewer/app/markers.js +61 -1
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +177 -53
- package/dist/viewer/app/scene.js +35 -6
- package/dist/viewer/app/select.js +5 -4
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +66 -8
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +48 -1
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +24 -11
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +24 -7
- package/dist/viewer/server.js +289 -31
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/web/bake.d.ts +34 -0
- package/dist/web/bake.js +153 -0
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -105
- package/dist/workspace.js +359 -375
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +23 -29
- package/kernels/pkg-simd/README.md +23 -29
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +23 -8
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/shelf/index.json +0 -190
package/dist/viewer/server.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
// Live preview web server: serves the viewer page (index.html, a shell loading the ES modules of app/ and three.js
|
|
2
|
-
// from /vendor/three
|
|
2
|
+
// from /vendor/three/) that shows any graph/node of the package and refreshes over
|
|
3
3
|
// Server-Sent Events whenever a graph is rebuilt/edited.
|
|
4
|
-
// It is also the human's control surface: files dropped on the page are stored in the
|
|
4
|
+
// It is also the human's control surface: files dropped on the page are stored in the package's inputs/ (under
|
|
5
5
|
// `topotopo view`, the inputs/ beside the graph file) and shown as reference layers, the graph's exposed vars are set
|
|
6
6
|
// from generated controls (POST /api/vars), and markers clicked into the view (sites, paths, zones, volumes) become
|
|
7
7
|
// inputs/markers.json (POST /api/markers).
|
|
8
|
+
// Cooks report their progress (the node cooking, the time) as {cook} events, and POST /api/cook/stop stops them at
|
|
9
|
+
// the next node boundary. A new value supersedes the cook of the one before: the latest value wins.
|
|
10
|
+
// Over a graph file (`topotopo view`, ViewerOptions.source) the controls set session values over the graph, which
|
|
11
|
+
// survive reloads of the file; POST /api/vars/save writes them into its vars.
|
|
12
|
+
// The packages the open package uses (/api/packages*, src/viewer/packages.ts): their updates, the before/after of one and
|
|
13
|
+
// Update, and following a package's working folder for the viewer's session. /api/package says which package the
|
|
14
|
+
// viewer shows (the page's title, its default graph, and what an empty package or a folder that is no package says),
|
|
15
|
+
// with TopoTopo's built-in packages for the welcome.
|
|
8
16
|
// Bound to 127.0.0.1 only; requests must name this server as their Host, and writes must come from its own page.
|
|
9
17
|
import http from 'node:http';
|
|
10
18
|
import fs from 'node:fs';
|
|
@@ -13,23 +21,31 @@ import zlib from 'node:zlib';
|
|
|
13
21
|
import { Transform } from 'node:stream';
|
|
14
22
|
import { pipeline } from 'node:stream/promises';
|
|
15
23
|
import { fileURLToPath } from 'node:url';
|
|
24
|
+
import { varDeclaration, graphVarValue } from '../session.js';
|
|
16
25
|
import { GeoBuilder } from '../core/geometry.js';
|
|
17
|
-
import { exportGeometry
|
|
26
|
+
import { exportGeometry } from '../io/export.js';
|
|
27
|
+
import { previewGLB } from '../render/preview.js';
|
|
18
28
|
import { summarize } from '../inspect.js';
|
|
19
29
|
import { withHeightfieldPreview } from '../core/heightfield.js';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
30
|
+
import { STOPPED, wiringOf } from '../graph/engine.js';
|
|
31
|
+
import { packagesNamedIn } from '../graph/packages.js';
|
|
22
32
|
import { createOutputs } from './outputs.js';
|
|
33
|
+
import { createPackages } from './packages.js';
|
|
34
|
+
import { PackageUses, builtinLibrary, isDefaultOutput } from '../packages/registry.js';
|
|
35
|
+
import { packageDirOf, packageId, readManifest } from '../package.js';
|
|
23
36
|
import { renderGeometry } from '../render/raster.js';
|
|
24
37
|
import { encodePNG } from '../render/png.js';
|
|
25
38
|
import { imageFromPNGFile } from '../io/textures.js';
|
|
39
|
+
import { SIDECAR_NAMES, SIDECAR_TEXT } from '../io/sidecars.js';
|
|
40
|
+
import { outputKind } from '../io/kinds.js';
|
|
41
|
+
import { sidecarFile } from '../host/sidecars.js';
|
|
26
42
|
// the page's guide rules, shared so the page and this server check a marker list the same way
|
|
27
43
|
import { MARKER_KINDS as KINDS, MarkerError, parseMarkers as parseMarkerList } from './app/markers.js';
|
|
28
44
|
// index.html and app/ sit next to this module (the build copies them to dist/viewer/)
|
|
29
45
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
30
|
-
const appDir = path.join(here, 'app');
|
|
46
|
+
export const appDir = path.join(here, 'app');
|
|
31
47
|
// three.js where Node resolves it: this checkout's node_modules, or the hoisted copy next to an installed package
|
|
32
|
-
const threeDir = (() => {
|
|
48
|
+
export const threeDir = (() => {
|
|
33
49
|
try {
|
|
34
50
|
return path.resolve(path.dirname(fileURLToPath(import.meta.resolve('three'))), '..');
|
|
35
51
|
}
|
|
@@ -37,7 +53,7 @@ const threeDir = (() => {
|
|
|
37
53
|
return path.resolve(here, '..', '..', 'node_modules', 'three');
|
|
38
54
|
}
|
|
39
55
|
})();
|
|
40
|
-
const MIME = { '.js': 'text/javascript', '.html': 'text/html; charset=utf-8', '.css': 'text/css', '.json': 'application/json', '.glb': 'model/gltf-binary' };
|
|
56
|
+
export const MIME = { '.js': 'text/javascript', '.html': 'text/html; charset=utf-8', '.css': 'text/css', '.json': 'application/json', '.glb': 'model/gltf-binary' };
|
|
41
57
|
/** largest file POST /api/inputs accepts */
|
|
42
58
|
export const MAX_UPLOAD = 512 * 1024 * 1024;
|
|
43
59
|
/** uploads in progress are written next to their target as `.<name>.<n>.part`, then renamed */
|
|
@@ -46,8 +62,13 @@ class HttpError extends Error {
|
|
|
46
62
|
status;
|
|
47
63
|
constructor(status, msg) { super(msg); this.status = status; }
|
|
48
64
|
}
|
|
65
|
+
/** A built-in package's outputs in a line, its line-up left out: "7 outputs: bench, bollard, cable …". */
|
|
66
|
+
function outputsLine(v, most = 6) {
|
|
67
|
+
const names = Object.entries(v.outputs).filter(([, o]) => !isDefaultOutput(v, o)).map(([k]) => k);
|
|
68
|
+
return `${names.length} output${names.length === 1 ? '' : 's'}${names.length ? `: ${names.slice(0, most).join(', ')}${names.length > most ? ' …' : ''}` : ''}`;
|
|
69
|
+
}
|
|
49
70
|
/** The shape every geometry route serves: the same GLB options as /api/geo; images alone show as textured quads. */
|
|
50
|
-
const toGLB = (g) =>
|
|
71
|
+
const toGLB = (g) => previewGLB(g);
|
|
51
72
|
const issueText = (e) => `[${e.node}] ${e.message}`;
|
|
52
73
|
/**
|
|
53
74
|
* A dropped file's name as stored in inputs/: a plain basename with its extension. Path separators and ".." are
|
|
@@ -150,13 +171,81 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
150
171
|
for (const c of clients)
|
|
151
172
|
c.write(msg);
|
|
152
173
|
};
|
|
153
|
-
|
|
154
|
-
const
|
|
174
|
+
// a graph changed: after a stop the page keeps the geometry it has instead of fetching (and cooking) it again
|
|
175
|
+
const graphChanged = (ev) => broadcast({ ...ev, ...(ws.held(ev.graph) ? { stopped: true } : {}) });
|
|
176
|
+
ws.listeners.add(graphChanged);
|
|
177
|
+
/** The package the viewer shows: that of the packages attached to the session, else the one its folder is in. */
|
|
178
|
+
const packageOf = (refresh = false) => {
|
|
179
|
+
const pk = ws.packages instanceof PackageUses ? ws.packages : null;
|
|
180
|
+
if (refresh && pk?.dir)
|
|
181
|
+
pk.refresh();
|
|
182
|
+
const dir = pk ? pk.dir : packageDirOf(ws.dir);
|
|
183
|
+
let m = pk?.manifest ?? null;
|
|
184
|
+
if (!pk && dir)
|
|
185
|
+
try {
|
|
186
|
+
m = readManifest(dir);
|
|
187
|
+
}
|
|
188
|
+
catch { /* unreadable: no package to name */ }
|
|
189
|
+
return m && dir ? { id: packageId(dir), title: m.title, description: m.description, graph: m.graph, name: m.name ?? null, dir } : null;
|
|
190
|
+
};
|
|
191
|
+
// TopoTopo's built-in packages, read once: they change only with TopoTopo itself
|
|
192
|
+
let builtin = null;
|
|
193
|
+
/**
|
|
194
|
+
* GET /api/package: the package the viewer shows (null for a folder that is in no package), the folder, the graph
|
|
195
|
+
* file of `topotopo view`, and TopoTopo's built-in packages.
|
|
196
|
+
*/
|
|
197
|
+
const packageInfo = () => {
|
|
198
|
+
builtin ??= builtinLibrary().map((b) => {
|
|
199
|
+
const v = b.versions.at(-1);
|
|
200
|
+
return { name: b.name, title: b.manifest.title, description: b.manifest.description, version: v?.version ?? null, outputs: v ? outputsLine(v) : '0 outputs' };
|
|
201
|
+
});
|
|
202
|
+
return { package: packageOf(true), folder: ws.dir, file: opts.source?.label ?? null, builtin };
|
|
203
|
+
};
|
|
204
|
+
// the package's default graph cooks its cards first
|
|
205
|
+
const makeOutputs = () => createOutputs(ws, () => broadcast({ outputs: true }), { source: opts.source, first: () => packageOf()?.graph });
|
|
206
|
+
let outputs = makeOutputs();
|
|
207
|
+
const makePackages = () => createPackages(ws, broadcast);
|
|
208
|
+
let packages = makePackages();
|
|
209
|
+
// ---------------------------------------------------------------- the state of the cooks
|
|
210
|
+
// {cook: {graph, running, last}} events: each node of the graph as it starts (before it can hold the thread for
|
|
211
|
+
// long: the session yields there), the rest of the progress at most every 100 ms, the end at once. A cook that
|
|
212
|
+
// only finds cached results is announced only when it lasts past 120 ms.
|
|
213
|
+
const sessionMode = (graph) => opts.source?.graph === graph;
|
|
214
|
+
const cookState = (graph) => {
|
|
215
|
+
const last = ws.lastCook.get(graph);
|
|
216
|
+
return { running: ws.activity(graph), last: last ? { ...last, error: last.error ? { node: last.error.node, message: last.error.message } : undefined } : null };
|
|
217
|
+
};
|
|
218
|
+
const cookTimers = new Map(), cookSent = new Map();
|
|
219
|
+
const sendCook = (graph) => {
|
|
220
|
+
cookTimers.delete(graph);
|
|
221
|
+
const state = cookState(graph), sent = cookSent.get(graph), last = JSON.stringify(state.last);
|
|
222
|
+
if (!state.running && !sent?.running && sent?.last === last)
|
|
223
|
+
return;
|
|
224
|
+
cookSent.set(graph, { at: performance.now(), running: !!state.running, last });
|
|
225
|
+
broadcast({ cook: { graph, ...state } });
|
|
226
|
+
};
|
|
227
|
+
const onActivity = (graph, ev) => {
|
|
228
|
+
if (closed)
|
|
229
|
+
return;
|
|
230
|
+
if (ev?.phase === 'start' && ev.depth === 0) {
|
|
231
|
+
clearTimeout(cookTimers.get(graph));
|
|
232
|
+
sendCook(graph);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (cookTimers.has(graph))
|
|
236
|
+
return;
|
|
237
|
+
const sent = cookSent.get(graph), running = !!ws.activity(graph);
|
|
238
|
+
const wait = !running ? 0 : sent?.running ? Math.max(0, 100 - (performance.now() - sent.at)) : 120;
|
|
239
|
+
cookTimers.set(graph, setTimeout(() => sendCook(graph), wait));
|
|
240
|
+
};
|
|
241
|
+
ws.activityListeners.add(onActivity);
|
|
155
242
|
// ---------------------------------------------------------------- inputs/
|
|
156
243
|
let inputsVersion = 0;
|
|
157
244
|
const inputsChanged = () => broadcast({ inputs: ++inputsVersion });
|
|
158
|
-
|
|
159
|
-
const
|
|
245
|
+
// an export's sidecar (kind "metadata") says what it is: the page shows it with the file it describes
|
|
246
|
+
const listInputs = () => ws.listInputs().filter((f) => !PART_RE.test(f.path))
|
|
247
|
+
.map((f) => (f.sidecar ? { ...f, about: `${SIDECAR_NAMES[f.sidecar.role]}: ${SIDECAR_TEXT[f.sidecar.role]}` } : f));
|
|
248
|
+
const inputsWhere = () => opts.inputsWhere ?? (path.dirname(ws.inputDir) === ws.dir ? (packageOf() ? 'in the package' : 'in this folder') : `in ${path.dirname(ws.inputDir)}`);
|
|
160
249
|
// Files copied into inputs/ by other means (file manager, an agent) show up too, once the folder exists. The viewer
|
|
161
250
|
// does not make it just to watch it (`topotopo view`'s inputs/ beside the graph file appears with the first drop):
|
|
162
251
|
// uploads and listings start the watch when the folder is there by then.
|
|
@@ -211,8 +300,8 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
211
300
|
/** The one-node graph that loads an input. */
|
|
212
301
|
const inputGraph = (rel, abs) => {
|
|
213
302
|
// "inputs/<rel>", the path a graph's file node uses, resolves against the host's base directory: the folder that
|
|
214
|
-
// holds inputs/ under the MCP server (
|
|
215
|
-
//
|
|
303
|
+
// holds inputs/ under the MCP server (its folder) and under `topotopo view` (the graph file's folder). A
|
|
304
|
+
// session whose engine resolves paths elsewhere (an embedding app, a test) gets the absolute path.
|
|
216
305
|
const ref = `inputs/${rel}`;
|
|
217
306
|
const p = path.resolve(ws.engine.host.resolvePath(ref)) === abs ? ref : abs;
|
|
218
307
|
return { nodes: { f: { type: 'file', params: { path: p } } }, output: 'f' };
|
|
@@ -307,16 +396,49 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
307
396
|
return { ok: true, count: list.length, path: list.length ? 'markers.json' : null, ...counts };
|
|
308
397
|
};
|
|
309
398
|
// ---------------------------------------------------------------- POST /api/vars
|
|
310
|
-
// One
|
|
311
|
-
//
|
|
399
|
+
// One cook at a time per graph. A request that arrives while one runs stops it at its next node boundary (the
|
|
400
|
+
// latest value wins; values in between may never cook); the waiting requests are merged (the latest value of each
|
|
401
|
+
// var wins) and applied by a single further cook. Every request is answered once its values are applied, or when a
|
|
402
|
+
// stop (POST /api/cook/stop) ends the cook. Over a graph file the values are session values, set at once; in a
|
|
403
|
+
// package they edit the stored graph (an agent reads them there).
|
|
312
404
|
const varQueues = new Map();
|
|
405
|
+
const varsState = (name) => {
|
|
406
|
+
const g = ws.graphs.get(name);
|
|
407
|
+
return { vars: g ? ws.effectiveGraph(name).vars ?? {} : {}, graphVars: g?.vars ?? {}, overrides: Object.keys(ws.sessionVars(name)) };
|
|
408
|
+
};
|
|
409
|
+
const reply = (name, report) => ({ status: 200, body: { ok: report.ok, ms: report.ms, errors: report.errors.map(issueText), ...varsState(name), ...(report.stopped ? { stopped: report.stopped } : {}) } });
|
|
410
|
+
/** Session values a request sets, checked against the graph: its own vars only, and a graph that still validates. */
|
|
411
|
+
const sessionErrors = (name, vars) => {
|
|
412
|
+
const g = ws.getGraph(name);
|
|
413
|
+
const unknown = Object.keys(vars).filter((k) => varDeclaration(g, k) === null);
|
|
414
|
+
if (unknown.length)
|
|
415
|
+
return [`graph ${name} has no var ${unknown.map((k) => JSON.stringify(k)).join(', ')}: the controls set the graph's own vars`];
|
|
416
|
+
const trial = { ...(ws.effectiveGraph(name).vars ?? {}) };
|
|
417
|
+
for (const [k, v] of Object.entries(vars)) {
|
|
418
|
+
const back = graphVarValue(g, k);
|
|
419
|
+
if (v !== null)
|
|
420
|
+
trial[k] = v;
|
|
421
|
+
else if (back === undefined)
|
|
422
|
+
delete trial[k];
|
|
423
|
+
else
|
|
424
|
+
trial[k] = back;
|
|
425
|
+
}
|
|
426
|
+
// nothing is written yet: a package the graph names for the first time counts as the version its first use adds
|
|
427
|
+
const tried = { ...g, vars: trial };
|
|
428
|
+
return ws.engine.validate(tried, '', ws.dryScope(tried).scope).errors.map(issueText);
|
|
429
|
+
};
|
|
313
430
|
const applyBatch = async (name, b) => {
|
|
314
|
-
|
|
315
|
-
if (!prev)
|
|
431
|
+
if (!ws.graphs.get(name))
|
|
316
432
|
return { status: 404, body: { ok: false, ms: 0, errors: [`no graph ${name}`] } };
|
|
433
|
+
if (sessionMode(name)) {
|
|
434
|
+
const report = await ws.cook(name, undefined, undefined, { kind: 'edit' });
|
|
435
|
+
if (!report.stopped)
|
|
436
|
+
ws.bump(name);
|
|
437
|
+
return reply(name, report);
|
|
438
|
+
}
|
|
317
439
|
try {
|
|
318
|
-
const {
|
|
319
|
-
return
|
|
440
|
+
const { report } = await ws.edit(name, [{ op: 'vars', vars: b.vars }], { kind: 'edit' });
|
|
441
|
+
return reply(name, report);
|
|
320
442
|
}
|
|
321
443
|
catch (e) {
|
|
322
444
|
// rejected edits carry their issues (one string each); op errors are plain messages
|
|
@@ -324,6 +446,12 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
324
446
|
}
|
|
325
447
|
};
|
|
326
448
|
const applyVars = (name, vars) => new Promise((resolve) => {
|
|
449
|
+
if (sessionMode(name)) {
|
|
450
|
+
const errors = sessionErrors(name, vars);
|
|
451
|
+
if (errors.length)
|
|
452
|
+
return resolve({ status: 400, body: { ok: false, ms: 0, errors } });
|
|
453
|
+
ws.setSessionVars(name, vars);
|
|
454
|
+
}
|
|
327
455
|
let q = varQueues.get(name);
|
|
328
456
|
if (!q)
|
|
329
457
|
varQueues.set(name, q = { busy: false, next: null });
|
|
@@ -333,8 +461,11 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
333
461
|
}
|
|
334
462
|
else
|
|
335
463
|
q.next = { vars: { ...vars }, waiters: [resolve] };
|
|
336
|
-
|
|
464
|
+
// the latest value wins: the cook of the values before (and the previews of them) stop at their next node boundary
|
|
465
|
+
if (q.busy) {
|
|
466
|
+
ws.stop(name, ['edit', 'preview'], { superseded: true });
|
|
337
467
|
return;
|
|
468
|
+
}
|
|
338
469
|
q.busy = true;
|
|
339
470
|
(async () => {
|
|
340
471
|
try {
|
|
@@ -342,6 +473,13 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
342
473
|
const b = q.next;
|
|
343
474
|
q.next = null;
|
|
344
475
|
const r = await applyBatch(name, b).catch((e) => ({ status: 500, body: { ok: false, ms: 0, errors: [String(e?.message ?? e)] } }));
|
|
476
|
+
// superseded: its values are in the batch that came after it, and that cook answers its requests too
|
|
477
|
+
const later = q.next;
|
|
478
|
+
if (r.body.stopped && later) {
|
|
479
|
+
later.vars = { ...b.vars, ...later.vars };
|
|
480
|
+
later.waiters.unshift(...b.waiters);
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
345
483
|
for (const w of b.waiters)
|
|
346
484
|
w(r);
|
|
347
485
|
}
|
|
@@ -351,6 +489,42 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
351
489
|
}
|
|
352
490
|
})();
|
|
353
491
|
});
|
|
492
|
+
/** POST /api/cook/stop: stop every cook of the graph, and the values waiting to cook (they stay set). */
|
|
493
|
+
const stopCooks = (name) => {
|
|
494
|
+
const n = ws.stop(name);
|
|
495
|
+
const q = varQueues.get(name), waiting = q?.next;
|
|
496
|
+
if (q)
|
|
497
|
+
q.next = null;
|
|
498
|
+
if (waiting) {
|
|
499
|
+
const at = ws.activity(name)?.node ?? ws.engine.findOutput(ws.getGraph(name)).name;
|
|
500
|
+
const r = { status: 200, body: { ok: false, ms: 0, errors: [], ...varsState(name), stopped: at } };
|
|
501
|
+
for (const w of waiting.waiters)
|
|
502
|
+
w(r);
|
|
503
|
+
}
|
|
504
|
+
// nothing cooks it again on its own until the graph or a value changes
|
|
505
|
+
if (n || waiting)
|
|
506
|
+
ws.hold(name);
|
|
507
|
+
return { ok: true, stopping: n > 0 };
|
|
508
|
+
};
|
|
509
|
+
/** POST /api/vars/save: the session values into the graph file's vars; the graph holds them from now on. */
|
|
510
|
+
const saveVars = (name) => {
|
|
511
|
+
const src = opts.source;
|
|
512
|
+
if (!src || src.graph !== name)
|
|
513
|
+
throw new HttpError(400, sessionMode(name)
|
|
514
|
+
? 'this viewer cannot write the graph file: start it with `topotopo view <graph.json>` to save values'
|
|
515
|
+
: `graph ${name} is the package's own: its values are saved as they change`);
|
|
516
|
+
const values = ws.sessionVars(name), names = Object.keys(values);
|
|
517
|
+
if (names.length) {
|
|
518
|
+
try {
|
|
519
|
+
src.save(names.map((k) => ({ path: ['vars', k], value: values[k] })));
|
|
520
|
+
}
|
|
521
|
+
catch (e) {
|
|
522
|
+
throw new HttpError(500, `could not write ${src.label}: ${e?.message ?? e}`);
|
|
523
|
+
}
|
|
524
|
+
ws.bump(name);
|
|
525
|
+
}
|
|
526
|
+
return { ok: true, saved: names, file: src.label, ...varsState(name) };
|
|
527
|
+
};
|
|
354
528
|
const readJSON = (req, max = 4 << 20) => new Promise((resolve, reject) => {
|
|
355
529
|
const chunks = [];
|
|
356
530
|
let n = 0;
|
|
@@ -389,6 +563,8 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
389
563
|
route = u.pathname;
|
|
390
564
|
if (await outputs.handle(req, res, u, readJSON))
|
|
391
565
|
return;
|
|
566
|
+
if (await packages.handle(req, res, u, readJSON))
|
|
567
|
+
return;
|
|
392
568
|
if (u.pathname === '/' || u.pathname === '/index.html')
|
|
393
569
|
return send(200, fs.readFileSync(path.join(here, 'index.html')), MIME['.html']);
|
|
394
570
|
// the page's modules and style sheet
|
|
@@ -412,16 +588,28 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
412
588
|
req.on('close', () => clients.delete(res));
|
|
413
589
|
return;
|
|
414
590
|
}
|
|
591
|
+
if (u.pathname === '/api/package')
|
|
592
|
+
return json(200, packageInfo());
|
|
415
593
|
if (u.pathname === '/api/graphs') {
|
|
416
594
|
const out = [...ws.graphs].map(([name, g]) => {
|
|
417
595
|
const last = ws.lastReport.get(name);
|
|
418
596
|
return {
|
|
419
|
-
|
|
420
|
-
|
|
597
|
+
// a cook that failed validation (a package update the graph must follow) has no target
|
|
598
|
+
name, output: last?.target || g.output || null, version: ws.versions.get(name) ?? 0,
|
|
599
|
+
// vars: what the controls show; graphVars: the graph's own; overrides: the session values among them
|
|
600
|
+
...varsState(name), params: g.params ?? {},
|
|
601
|
+
// "file": the controls set session values over a graph file (saveable when it names the file); "package":
|
|
602
|
+
// they edit the stored graph
|
|
603
|
+
mode: sessionMode(name) ? 'file' : 'package', file: opts.source?.graph === name ? opts.source.label : null,
|
|
604
|
+
cook: cookState(name),
|
|
421
605
|
nodes: Object.entries(g.nodes).map(([n, spec]) => {
|
|
422
606
|
const def = ws.engine.resolveDef(spec.type);
|
|
423
607
|
const r = last?.results.get(n);
|
|
424
|
-
|
|
608
|
+
// the packages it names, as its type or in its nested graphs: the Scene tree marks those with an update
|
|
609
|
+
const named = packagesNamedIn({ nodes: { [n]: spec } });
|
|
610
|
+
// its error: from its cook, or from the graph's validation (a slider a package version does not have)
|
|
611
|
+
const error = r?.error?.message ?? (last && !last.ok ? last.errors.find((e) => e.node === n)?.message : undefined) ?? null;
|
|
612
|
+
return { name: n, type: spec.type, in: def ? wiringOf(spec, def).list : [], error, ms: r?.ms ?? null, ...(named.length ? { packages: named } : {}) };
|
|
425
613
|
}),
|
|
426
614
|
};
|
|
427
615
|
});
|
|
@@ -450,6 +638,27 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
450
638
|
const r = await applyVars(name, vars);
|
|
451
639
|
return json(r.status, r.body);
|
|
452
640
|
}
|
|
641
|
+
if (u.pathname === '/api/vars/save' || u.pathname === '/api/cook/stop') {
|
|
642
|
+
if (req.method !== 'POST')
|
|
643
|
+
throw new HttpError(405, 'POST required');
|
|
644
|
+
const name = u.searchParams.get('graph') ?? 'main';
|
|
645
|
+
const body = await readJSON(req);
|
|
646
|
+
if (!ws.graphs.has(name))
|
|
647
|
+
throw new HttpError(404, `no graph ${name}`);
|
|
648
|
+
if (u.pathname === '/api/cook/stop')
|
|
649
|
+
return json(200, stopCooks(name));
|
|
650
|
+
// the save may carry the values the page shows (some may still be on their way): they are set first
|
|
651
|
+
const vars = body?.vars;
|
|
652
|
+
if (vars !== undefined && (!vars || typeof vars !== 'object' || Array.isArray(vars)))
|
|
653
|
+
throw new HttpError(400, '"vars" must be an object {name: value}');
|
|
654
|
+
if (vars && Object.keys(vars).length && sessionMode(name)) {
|
|
655
|
+
const errors = sessionErrors(name, vars);
|
|
656
|
+
if (errors.length)
|
|
657
|
+
throw new HttpError(400, errors.join('; '));
|
|
658
|
+
ws.setSessionVars(name, vars);
|
|
659
|
+
}
|
|
660
|
+
return json(200, saveVars(name));
|
|
661
|
+
}
|
|
453
662
|
if (u.pathname === '/api/inputs') {
|
|
454
663
|
if (req.method === 'POST') {
|
|
455
664
|
const r = await upload(req, u);
|
|
@@ -460,7 +669,7 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
460
669
|
}
|
|
461
670
|
// where dropped files go: the absolute folder, and in words for the page ("beside house.json")
|
|
462
671
|
if (u.pathname === '/api/inputs_dir')
|
|
463
|
-
return json(200, { dir: ws.inputDir, where: inputsWhere });
|
|
672
|
+
return json(200, { dir: ws.inputDir, where: inputsWhere() });
|
|
464
673
|
if (u.pathname === '/api/markers') {
|
|
465
674
|
if (req.method === 'POST')
|
|
466
675
|
return json(200, saveMarkers(parseMarkers(await readJSON(req))));
|
|
@@ -476,6 +685,8 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
476
685
|
return send(200, fs.readFileSync(abs), mime);
|
|
477
686
|
if (u.pathname === '/api/input_image')
|
|
478
687
|
throw new HttpError(400, 'choose a PNG, JPEG or WebP image');
|
|
688
|
+
if (sidecarFile(abs))
|
|
689
|
+
throw new HttpError(400, `inputs/${rel} is an export's sidecar (metadata), not geometry: it has no thumbnail`);
|
|
479
690
|
const stat = fs.statSync(abs), key = `${abs}:${stat.size}:${stat.mtimeMs}`;
|
|
480
691
|
if (!inputThumbs.has(key)) {
|
|
481
692
|
if (inputThumbs.size >= 128)
|
|
@@ -494,6 +705,14 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
494
705
|
}
|
|
495
706
|
if (u.pathname === '/api/input' || u.pathname === '/api/input_info') {
|
|
496
707
|
const { rel, abs } = inputPath(u.searchParams.get('path'));
|
|
708
|
+
// an export's sidecar (io/sidecars.ts) is metadata of the file beside it: described, never cooked
|
|
709
|
+
const side = sidecarFile(abs);
|
|
710
|
+
if (side) {
|
|
711
|
+
const what = `${SIDECAR_NAMES[side.role]} of ${side.of ? `inputs/${path.relative(ws.inputDir, side.of).split(path.sep).join('/')}` : 'an export that is not in inputs/'}: ${SIDECAR_TEXT[side.role]}`;
|
|
712
|
+
if (u.pathname === '/api/input_info')
|
|
713
|
+
return json(200, { path: rel, summary: `${what} (metadata, not geometry)`, metadata: true });
|
|
714
|
+
throw new HttpError(400, `inputs/${rel} is ${what}: metadata, not geometry to show`);
|
|
715
|
+
}
|
|
497
716
|
if (u.pathname === '/api/input_info' && imageType(abs)) {
|
|
498
717
|
let summary = `${imageType(abs)} · ${fs.statSync(abs).size} bytes`;
|
|
499
718
|
// Preserve the existing PNG summary contract without cooking a file-node graph.
|
|
@@ -513,16 +732,23 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
513
732
|
}
|
|
514
733
|
if (u.pathname === '/api/geo' || u.pathname === '/api/info') {
|
|
515
734
|
const name = u.searchParams.get('graph') ?? 'main';
|
|
516
|
-
const node = u.searchParams.get('node') || undefined;
|
|
517
735
|
const g = ws.graphs.get(name);
|
|
518
736
|
if (!g)
|
|
519
737
|
return send(404, JSON.stringify({ error: `no graph ${name}` }), MIME['.json']);
|
|
520
|
-
|
|
738
|
+
// a preview with the session values; the output by name, so it never counts as the graph's own cook (lastCook).
|
|
739
|
+
// After a stop the output is the last finished cook's: asking for it does not cook again what was stopped.
|
|
740
|
+
const last = ws.lastReport.get(name);
|
|
741
|
+
const node = u.searchParams.get('node') || ws.engine.findOutput(g).name;
|
|
742
|
+
const r = !u.searchParams.get('node') && ws.held(name) && last?.ok && last.target === node ? last : await ws.cook(name, node, undefined, { kind: 'preview' });
|
|
743
|
+
if (r.stopped)
|
|
744
|
+
return send(409, JSON.stringify({ error: `${STOPPED} at ${r.stopped}`, stopped: r.stopped }), MIME['.json']);
|
|
521
745
|
if (!r.ok || !r.geo)
|
|
522
746
|
return send(500, JSON.stringify({ error: r.errors.map(issueText).join('\n') }), MIME['.json']);
|
|
747
|
+
// info: what it is (io/kinds.ts), for the properties and their heightfield layer picker
|
|
523
748
|
if (u.pathname === '/api/info')
|
|
524
|
-
return send(200, JSON.stringify({ target: r.target, summary: summarize(r.geo), ms: r.ms }), MIME['.json']);
|
|
525
|
-
|
|
749
|
+
return send(200, JSON.stringify({ target: r.target, summary: summarize(r.geo), ms: r.ms, about: outputKind(r.geo) }), MIME['.json']);
|
|
750
|
+
// heightfields: the layer drawn in red (the page's layer picker; the mask by default)
|
|
751
|
+
return send(200, await previewGLB(r.geo, { heightfieldLayer: u.searchParams.get('heightfield_layer') || undefined }), MIME['.glb']);
|
|
526
752
|
}
|
|
527
753
|
send(404, 'not found');
|
|
528
754
|
}
|
|
@@ -557,13 +783,45 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
557
783
|
keepAlive.unref();
|
|
558
784
|
return {
|
|
559
785
|
url: `http://127.0.0.1:${actual}/`,
|
|
786
|
+
clients: () => clients.size,
|
|
787
|
+
pokePackages: (pkg, rel) => packages.poke(pkg, rel),
|
|
788
|
+
setSession: (next) => {
|
|
789
|
+
if (next === ws || closed)
|
|
790
|
+
return;
|
|
791
|
+
ws.listeners.delete(graphChanged);
|
|
792
|
+
ws.activityListeners.delete(onActivity);
|
|
793
|
+
outputs.close();
|
|
794
|
+
packages.close();
|
|
795
|
+
clearTimeout(watchTimer);
|
|
796
|
+
for (const t of cookTimers.values())
|
|
797
|
+
clearTimeout(t);
|
|
798
|
+
cookTimers.clear();
|
|
799
|
+
cookSent.clear();
|
|
800
|
+
unwatch();
|
|
801
|
+
varQueues.clear();
|
|
802
|
+
inputThumbs.clear();
|
|
803
|
+
ws = next;
|
|
804
|
+
ws.listeners.add(graphChanged);
|
|
805
|
+
ws.activityListeners.add(onActivity);
|
|
806
|
+
outputs = makeOutputs();
|
|
807
|
+
packages = makePackages();
|
|
808
|
+
watchInputs();
|
|
809
|
+
// the pages reconnect (EventSource retries) and reload graphs, layers and guides from the new package
|
|
810
|
+
for (const c of clients)
|
|
811
|
+
c.end();
|
|
812
|
+
clients.clear();
|
|
813
|
+
},
|
|
560
814
|
close: () => {
|
|
561
815
|
closed = true;
|
|
562
816
|
outputs.close();
|
|
817
|
+
packages.close();
|
|
563
818
|
clearInterval(keepAlive);
|
|
564
819
|
clearTimeout(watchTimer);
|
|
820
|
+
for (const t of cookTimers.values())
|
|
821
|
+
clearTimeout(t);
|
|
565
822
|
unwatch();
|
|
566
|
-
ws.listeners.delete(
|
|
823
|
+
ws.listeners.delete(graphChanged);
|
|
824
|
+
ws.activityListeners.delete(onActivity);
|
|
567
825
|
for (const c of clients)
|
|
568
826
|
c.end();
|
|
569
827
|
server.close();
|