@gui-chat-plugin/brep 0.0.0-stage → 0.2.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/CHANGELOG.md +38 -0
- package/README.md +181 -2
- package/dist/core/definition.d.ts +24 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/mesh.d.ts +34 -0
- package/dist/core/packed.d.ts +4 -0
- package/dist/core/paths.d.ts +15 -0
- package/dist/core/plugin.d.ts +12 -0
- package/dist/core/types.d.ts +68 -0
- package/dist/errors-BANLyHzz.js +27 -0
- package/dist/errors-BgFaRg0j.cjs +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +136 -0
- package/dist/kernel/errors.d.ts +33 -0
- package/dist/kernel/index.d.ts +26 -0
- package/dist/kernel/load.d.ts +9 -0
- package/dist/kernel/output.d.ts +15 -0
- package/dist/kernel/record.d.ts +32 -0
- package/dist/kernel/report.d.ts +52 -0
- package/dist/kernel/script.d.ts +9 -0
- package/dist/kernel-75dHFfjx.js +565 -0
- package/dist/kernel-BA8zZi78.cjs +2 -0
- package/dist/lang/en.d.ts +3 -0
- package/dist/lang/index.d.ts +5 -0
- package/dist/lang/ja.d.ts +3 -0
- package/dist/lang/messages.d.ts +41 -0
- package/dist/mesh-Cmm66x_I.js +128 -0
- package/dist/mesh-DLZoiBza.cjs +1 -0
- package/dist/style.css +3 -0
- package/dist/vue/Preview.vue.d.ts +8 -0
- package/dist/vue/View.vue.d.ts +8 -0
- package/dist/vue/index.d.ts +23 -0
- package/dist/vue/scene.d.ts +24 -0
- package/dist/vue/split.d.ts +26 -0
- package/dist/vue.cjs +1 -0
- package/dist/vue.js +941 -0
- package/package.json +72 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- **The View takes the host's theme.** Its panel, text, border, button and accent colours are the
|
|
6
|
+
host's custom properties when it has them (`--bg-panel`, `--bg-elevated`, `--text`,
|
|
7
|
+
`--text-muted`, `--border`, `--accent-bg`, `--on-accent`, `--warn`; they reach a shadow root), so
|
|
8
|
+
under a dark theme the card is dark instead of a white box. A host without them sees the light
|
|
9
|
+
slate colours it had. The ground behind the model is a soft gradient in those colours, and the
|
|
10
|
+
canvas is transparent. The model's own face and edge colours, the lighting and the exports are
|
|
11
|
+
unchanged.
|
|
12
|
+
|
|
13
|
+
## 0.1.0
|
|
14
|
+
|
|
15
|
+
- First release: `presentBrep` builds a solid model from a replicad script with the OpenCascade
|
|
16
|
+
kernel, in Node. It returns a check report (size, volume, faces and edges by kind, and what each
|
|
17
|
+
fillet, chamfer and shell selected) and writes the script, a STEP file, a binary STL and a sheet
|
|
18
|
+
of line drawings under `artifacts/brep/`.
|
|
19
|
+
- A View on `./vue`: the model in 3D with its edges, four standard views, the report, a
|
|
20
|
+
download button for each file (script, STEP, STL, drawings) and the script. The exports travel
|
|
21
|
+
packed in the tool result for that, as the mesh does. The mesh it draws travels in the tool result, so the page never
|
|
22
|
+
loads the kernel.
|
|
23
|
+
The model is on top at a height the user sets by dragging the bar under it; the report, the
|
|
24
|
+
files and the script scroll below, so nothing is cut off or overlaps in a short pane. That
|
|
25
|
+
layout is the component's own CSS: as Tailwind variants it was overridden by the other plugins'
|
|
26
|
+
stylesheets in MulmoChat.
|
|
27
|
+
- The guide, the system prompt and every result say which side the user sees first (-Y): chairs
|
|
28
|
+
built in MulmoChat had their backs to the viewer, the second one after the guide alone said so.
|
|
29
|
+
- A build's warnings come first in the message, say what to do, and lead the result's
|
|
30
|
+
instructions: a model in MulmoChat read past three of them, listed after the operations, and
|
|
31
|
+
told the user the model was done.
|
|
32
|
+
- A failure in a profile or a sketch names the call and its line, an arc given points where it
|
|
33
|
+
takes distances is refused with the method to use, and an extrusion that is not a valid solid
|
|
34
|
+
stops the build there: a model in MulmoChat was told "Standard_OutOfRange" and "[object
|
|
35
|
+
WebAssembly.Exception]", and took its script apart.
|
|
36
|
+
- An `async main` is refused before it runs: the time limit ends where a script first awaits, and
|
|
37
|
+
a loop after that held the host. A radius function's edges with a radius of 0 are not counted
|
|
38
|
+
as selected.
|
package/README.md
CHANGED
|
@@ -1,3 +1,182 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gui-chat-plugin/brep
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`presentBrep` — solid models for manufacturing. The model writes a
|
|
4
|
+
[replicad](https://replicad.xyz) script; the plugin builds it with the OpenCascade kernel, checks
|
|
5
|
+
the result, and writes STEP, STL and a sheet of line drawings.
|
|
6
|
+
|
|
7
|
+
It sits beside [`@gui-chat-plugin/shapescript`](../shapescript), and is for a different job.
|
|
8
|
+
ShapeScript combines triangle meshes: fast, in the browser, with colour and AR export, for models
|
|
9
|
+
that are looked at. This keeps exact surfaces (B-rep), so an edge can be selected and rounded, a
|
|
10
|
+
20 mm bore is a true cylinder, and the result opens in a CAD program as a solid. Use it for parts
|
|
11
|
+
that are made or that must fit.
|
|
12
|
+
|
|
13
|
+
## What a host provides
|
|
14
|
+
|
|
15
|
+
| | Used for | Without it |
|
|
16
|
+
| ----------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------ |
|
|
17
|
+
| `execute()` run in Node | the kernel (22 MB of WebAssembly) and `node:vm`, which runs the script | the plugin does not work: it cannot run in a page |
|
|
18
|
+
| `files.artifacts` (`FileOps`) | saving the script and its exports under `artifacts/brep/`; `path` rebuilds | the model is built and reported, nothing is saved; no `path` |
|
|
19
|
+
|
|
20
|
+
## Exports
|
|
21
|
+
|
|
22
|
+
| Entry | Contents |
|
|
23
|
+
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `.` | **Node only.** `TOOL_NAME`, `TOOL_DEFINITION`, `executePresentBrep`, `pluginCore`, the path rules, and `encodeMesh` / `decodeMesh` / `isBrepMesh` |
|
|
25
|
+
| `./vue` | For the page: the `ToolPlugin` (View + Preview + `SYSTEM_PROMPT`), `View`, `Preview`, `TOOL_DEFINITION`. Its `execute` refuses: it never loads the kernel |
|
|
26
|
+
| `./style.css` | the compiled component styles |
|
|
27
|
+
|
|
28
|
+
A host wires the two halves itself: the tool on its server with `executePresentBrep` from `.`, and
|
|
29
|
+
the View in its page with `plugin` from `./vue`. The page entry imports nothing that reaches the
|
|
30
|
+
kernel, so a browser bundle carries neither `node:vm` nor the WebAssembly; `plugin.execute` there
|
|
31
|
+
answers with a message saying where the tool runs, in place of building anything.
|
|
32
|
+
|
|
33
|
+
Two things a host has to know before enabling it:
|
|
34
|
+
|
|
35
|
+
- **The script is code, and it is not sandboxed.** It runs in the host's process with everything
|
|
36
|
+
the host's own code can reach. Enable the plugin only where the model can already run code on
|
|
37
|
+
the machine (MulmoClaude, MulmoTerminal). The time limit (60 s) stops a script that loops; it is
|
|
38
|
+
not a defence.
|
|
39
|
+
- **A build blocks the event loop** while the kernel works: 0.2 to 1.6 s for the parts in the
|
|
40
|
+
tests. Builds run one at a time.
|
|
41
|
+
|
|
42
|
+
`replicad` (MIT) and `replicad-opencascadejs` (LGPL-2.1) are dependencies, imported on the first
|
|
43
|
+
build and never bundled.
|
|
44
|
+
|
|
45
|
+
## The tool
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { executePresentBrep } from "@gui-chat-plugin/brep";
|
|
49
|
+
|
|
50
|
+
const result = await executePresentBrep(
|
|
51
|
+
{ files: { artifacts } },
|
|
52
|
+
{
|
|
53
|
+
title: "Flanged hub",
|
|
54
|
+
script: `
|
|
55
|
+
const { draw, makeCylinder } = replicad;
|
|
56
|
+
|
|
57
|
+
function main() {
|
|
58
|
+
let hub = draw([10, 0]).lineTo([40, 0]).lineTo([40, 8]).lineTo([20, 8]).lineTo([20, 30]).lineTo([10, 30]).close()
|
|
59
|
+
.sketchOnPlane("XZ").revolve();
|
|
60
|
+
const circle = (radius) => (length) => Math.abs(length - 2 * Math.PI * radius) < 0.01;
|
|
61
|
+
hub = hub.fillet(4, (e) => e.ofCurveType("CIRCLE").inPlane("XY", 8).ofLength(circle(20)));
|
|
62
|
+
for (let i = 0; i < 6; i++) {
|
|
63
|
+
const a = (i * Math.PI) / 3;
|
|
64
|
+
hub = hub.cut(makeCylinder(3.3, 10, [30 * Math.cos(a), 30 * Math.sin(a), -1], [0, 0, 1]));
|
|
65
|
+
}
|
|
66
|
+
return hub;
|
|
67
|
+
}`,
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
A script is JavaScript in replicad Studio's form: `replicad` is in scope and `main()` returns the
|
|
73
|
+
solid, an array of solids, or `{ shape, name }` objects. It is not a module: `import` and `export`
|
|
74
|
+
are refused, with what to write instead. `main` is an ordinary function: an `async` one is
|
|
75
|
+
refused before it runs, because the time limit ends where a script first awaits. Units are millimetres, Z is up, and the front of a part
|
|
76
|
+
faces -Y.
|
|
77
|
+
|
|
78
|
+
- `script` builds a new model and saves it as `artifacts/brep/<slug>-<epoch-ms>-<token>.replicad.js`.
|
|
79
|
+
- `path` rebuilds a script that is already saved, after the model has edited the file. The exports
|
|
80
|
+
beside it are replaced.
|
|
81
|
+
|
|
82
|
+
Beside the script, under the same name:
|
|
83
|
+
|
|
84
|
+
| File | Contents |
|
|
85
|
+
| ------- | -------------------------------------------------------------------------------------- |
|
|
86
|
+
| `.step` | the exact surfaces, in millimetres, one named product per part |
|
|
87
|
+
| `.stl` | binary, in millimetres, within 0.05 mm of the true surface |
|
|
88
|
+
| `.svg` | a sheet of four line drawings (top, front, right, and from above), hidden edges dashed |
|
|
89
|
+
|
|
90
|
+
`result.data` is `{ script, report, mesh, files?, downloads }`, for the View; `result.jsonData` is
|
|
91
|
+
`{ report, files? }`, for the model. `downloads` is the three exports themselves, gzipped and
|
|
92
|
+
base64 (`src/core/packed.ts`), under the saved files' name: about 95 kB for the hub in the tests,
|
|
93
|
+
about 220 kB for a chair. It is there on a host that saves nothing, too.
|
|
94
|
+
|
|
95
|
+
## The View
|
|
96
|
+
|
|
97
|
+
The model in 3D, turned with the mouse, with its true edges drawn as lines; four standard views
|
|
98
|
+
(from above front-right, top, front, right, the same four as the drawing sheet, Z up); the report,
|
|
99
|
+
with any warnings first; a button to download each file (script, STEP, STL, drawings); and the
|
|
100
|
+
script, read-only. The downloads are the saved files byte for byte: they travel in the result,
|
|
101
|
+
because a host owes a View no way to read a file.
|
|
102
|
+
|
|
103
|
+
The View cannot run the kernel, so the mesh it draws is made where the model is built and travels
|
|
104
|
+
in `result.data.mesh`: triangles and edge segments, positions as 16-bit steps across the bounding
|
|
105
|
+
box, base64. The enclosure in the tests is about 110 kB. It is for looking at; the STL and STEP
|
|
106
|
+
files are the model. The Preview is a card of text (title, size, warning count), not a second 3D
|
|
107
|
+
view: a page is allowed only a few WebGL contexts.
|
|
108
|
+
|
|
109
|
+
The View is the model on top, a bar, and everything else (report, files, script) below. The user
|
|
110
|
+
drags the bar to give the model more or less height (arrow keys move it too, a double click puts
|
|
111
|
+
it back), and the choice is kept in `localStorage` for the next result. What is below the bar
|
|
112
|
+
scrolls in the height that is left. The View never overflows its box: a host mounts it in one that
|
|
113
|
+
clips, and in a short pane the model and the scrolling part each keep a share. The layout is the
|
|
114
|
+
component's own scoped CSS, not Tailwind variants: a host loads every plugin's stylesheet, and a
|
|
115
|
+
later one's plain `flex-col` overrides an earlier one's `@3xl:flex-row`.
|
|
116
|
+
|
|
117
|
+
It uses no `dispatch` and no host route, so it works in any host that shows the result. That is
|
|
118
|
+
also why it does not edit: changing the script means building again, which is the tool's job. The
|
|
119
|
+
model edits the saved file and calls `presentBrep` with its `path`.
|
|
120
|
+
|
|
121
|
+
## The report
|
|
122
|
+
|
|
123
|
+
Every build returns what the solid is made of, so the model can check it against what it meant.
|
|
124
|
+
For the script above:
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
Built "Flanged hub": 80 x 80 x 30 mm, volume 57242.21 mm3, surface 16461.04 mm2, 1 solid.
|
|
128
|
+
Faces: 9 cylinder, 3 plane, 1 torus.
|
|
129
|
+
Edges: 20 circle, 9 line.
|
|
130
|
+
Operations:
|
|
131
|
+
line 7: fillet(4) selected 1 of 9 edges, volume +450.76 mm3
|
|
132
|
+
line 10: cut() x6 volume -1642.17 mm3
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The checks exist because of what a trial of three parts showed (the parts are in `test/parts.ts`):
|
|
136
|
+
|
|
137
|
+
- **A selector that picks too much is not an error.** A chamfer meant for four hole rims,
|
|
138
|
+
selected as "circles in this plane", also matched the arcs of the rounded corners and ran round
|
|
139
|
+
the whole outline. The build succeeded. It shows in `selected` and in the face counts: sixteen
|
|
140
|
+
cones where four countersinks make four.
|
|
141
|
+
- **A fillet that does not fit can return a broken solid.** `makeBaseBox(40, 20, 5).fillet(3)`
|
|
142
|
+
returns a shape with a larger volume than the box. Each operation's result is checked with the
|
|
143
|
+
kernel's own shape check, and the build stops with `INVALID_RESULT`.
|
|
144
|
+
- **The kernel's failures carry no message.** They are WebAssembly exceptions with no text and no
|
|
145
|
+
stack. An error names the operation, its line, and what it had to fit in:
|
|
146
|
+
`fillet(12) at line 5 failed: StdFail_NotDone: BRep_API: command not done. When it ran, it
|
|
147
|
+
selected 4 of 12 edges; the shortest selected edge is 5 mm; the solid is 40 x 20 x 5 mm.`
|
|
148
|
+
- **A boolean can do nothing.** A `cut` whose tool misses the solid, and pieces that are fused but
|
|
149
|
+
do not touch, are warnings in the report.
|
|
150
|
+
- **A warning has to be where the model reads.** A train came back with three warnings below two
|
|
151
|
+
dozen lines of operations, and the model called it done. Warnings are now the second thing in
|
|
152
|
+
the message, each says what to do about it, and the result's instructions begin with them:
|
|
153
|
+
correct each and build again, or tell the user about it.
|
|
154
|
+
|
|
155
|
+
- **A profile drawn wrong fails somewhere else.** `threePointsArc([x, y], [x, y])` (it takes
|
|
156
|
+
distances from the pen; `threePointsArcTo` takes points) was "Standard_OutOfRange" with no
|
|
157
|
+
line, and a profile that crossed itself extruded in silence and failed two steps later, in the
|
|
158
|
+
export, as "[object WebAssembly.Exception]". The model took its script apart to find them. Now
|
|
159
|
+
the first is refused where it is written, with the method to use, and an extrusion or
|
|
160
|
+
revolution that is not a valid solid stops the build at its line.
|
|
161
|
+
|
|
162
|
+
The operations checked and recorded are `fillet`, `chamfer`, `shell`, `fuse`, `cut` and
|
|
163
|
+
`intersect`. The other methods of a pen, a drawing, a sketch and a shape are guarded: nothing is
|
|
164
|
+
recorded, and a kernel failure in one is reported with the call and its line. All of them are
|
|
165
|
+
wrapped on replicad's classes when the kernel loads, so a script needs nothing extra; the
|
|
166
|
+
wrappers call straight through outside a build. A host that uses replicad itself, from the same
|
|
167
|
+
copy, gets the wrapped methods.
|
|
168
|
+
|
|
169
|
+
An error result has no `data`, and `jsonData.error` is `{ code, message, line?, completed? }`:
|
|
170
|
+
`INVALID_ARGUMENT`, `SYNTAX_ERROR`, `SCRIPT_ERROR`, `OPERATION_FAILED`, `INVALID_RESULT` or
|
|
171
|
+
`TIMEOUT`. `completed` lists what the operations before the failure did.
|
|
172
|
+
|
|
173
|
+
## Not here yet
|
|
174
|
+
|
|
175
|
+
- **Editing in the View.** It would send the script back to the host to rebuild, over
|
|
176
|
+
`dispatch`, which each host has to route.
|
|
177
|
+
- **A picture the model can look at.** The drawing sheet is SVG; a model that reads images needs
|
|
178
|
+
it rasterised.
|
|
179
|
+
- **Text.** replicad loads a font asynchronously, and `main` cannot be `async` until a build runs
|
|
180
|
+
where it can be stopped.
|
|
181
|
+
- **Isolation.** Each build could run in a worker, which would free the kernel's memory after it
|
|
182
|
+
and keep the host's event loop free.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const TOOL_NAME = "presentBrep";
|
|
2
|
+
export declare const TOOL_DEFINITION: {
|
|
3
|
+
type: "function";
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
parameters: {
|
|
7
|
+
type: "object";
|
|
8
|
+
properties: {
|
|
9
|
+
title: {
|
|
10
|
+
type: string;
|
|
11
|
+
description: string;
|
|
12
|
+
};
|
|
13
|
+
script: {
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
path: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
required: string[];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { BrepDiagnostic, BrepErrorCode, BrepFiles, ModelReport, PresentBrepArgs, PresentBrepBuiltResult, PresentBrepData, PresentBrepErrorResult, PresentBrepResult, } from "./types";
|
|
2
|
+
export type { OperationSummary, PartReport } from "../kernel/index";
|
|
3
|
+
export { TOOL_NAME, TOOL_DEFINITION } from "./definition";
|
|
4
|
+
export { pluginCore, presentBrep, executePresentBrep } from "./plugin";
|
|
5
|
+
export type { BrepExecuteContext } from "./plugin";
|
|
6
|
+
export { SCRIPT_EXTENSION, newScriptRelPath, relPathsFor, scriptRelPathOf, workspacePathsFor, } from "./paths";
|
|
7
|
+
export { decodeMesh, encodeMesh, isBrepMesh } from "./mesh";
|
|
8
|
+
export type { BrepMesh, DecodedMesh, RawMesh } from "./mesh";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface BrepMesh {
|
|
2
|
+
/** The corners of the box the positions and edges are quantised in, mm. */
|
|
3
|
+
min: [number, number, number];
|
|
4
|
+
max: [number, number, number];
|
|
5
|
+
/** base64 of Uint16 x y z per vertex. */
|
|
6
|
+
positions: string;
|
|
7
|
+
/** base64 of Int8 x y z per vertex. */
|
|
8
|
+
normals: string;
|
|
9
|
+
/** base64 of Uint16 per index, or Uint32 when `wideIndices`. */
|
|
10
|
+
indices: string;
|
|
11
|
+
/** Set when the mesh has more than 65 535 vertices. */
|
|
12
|
+
wideIndices?: true;
|
|
13
|
+
/** base64 of Uint16 x y z per point, two points per segment. */
|
|
14
|
+
edges: string;
|
|
15
|
+
}
|
|
16
|
+
/** What the kernel hands over: flat arrays of numbers. */
|
|
17
|
+
export interface RawMesh {
|
|
18
|
+
vertices: ArrayLike<number>;
|
|
19
|
+
normals: ArrayLike<number>;
|
|
20
|
+
triangles: ArrayLike<number>;
|
|
21
|
+
/** x y z per point, two points per segment. */
|
|
22
|
+
lines: ArrayLike<number>;
|
|
23
|
+
}
|
|
24
|
+
export interface DecodedMesh {
|
|
25
|
+
positions: Float32Array;
|
|
26
|
+
normals: Float32Array;
|
|
27
|
+
indices: Uint16Array | Uint32Array;
|
|
28
|
+
edges: Float32Array;
|
|
29
|
+
}
|
|
30
|
+
export declare function encodeMesh(raw: RawMesh): BrepMesh;
|
|
31
|
+
export declare function decodeMesh(mesh: BrepMesh): DecodedMesh;
|
|
32
|
+
/** True for a mesh a View can decode: a result kept from an earlier version,
|
|
33
|
+
* or one a host rewrote, is data like any other. */
|
|
34
|
+
export declare function isBrepMesh(value: unknown): value is BrepMesh;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Text (as UTF-8) or bytes, gzipped and base64-encoded. */
|
|
2
|
+
export declare function pack(content: string | Uint8Array): Promise<string>;
|
|
3
|
+
/** The bytes `pack` was given. Rejects for text that `pack` did not make. */
|
|
4
|
+
export declare function unpack(packed: string): Promise<Uint8Array<ArrayBuffer>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BrepFiles } from "./types";
|
|
2
|
+
/** A model's script. Not `.brep`, which is OpenCascade's own file format. */
|
|
3
|
+
export declare const SCRIPT_EXTENSION = ".replicad.js";
|
|
4
|
+
/** A fresh path for a new script, relative to the artifacts root. The token
|
|
5
|
+
* is what makes it fresh: two calls with one title in one millisecond would
|
|
6
|
+
* otherwise mint the same name, and the second write replace the first. */
|
|
7
|
+
export declare function newScriptRelPath(title: string | undefined, now?: Date, token?: string): string;
|
|
8
|
+
/** `artifacts/brep/x.replicad.js` -> `brep/x.replicad.js`, or undefined for a
|
|
9
|
+
* path that is not one of this plugin's scripts: outside `artifacts/brep/`,
|
|
10
|
+
* another extension, or with a `.` / `..` / empty segment. */
|
|
11
|
+
export declare function scriptRelPathOf(filePath: string): string | undefined;
|
|
12
|
+
/** The script's path and its exports', relative to the artifacts root. */
|
|
13
|
+
export declare function relPathsFor(scriptRelPath: string): BrepFiles;
|
|
14
|
+
/** The same four paths as the user and the model see them. */
|
|
15
|
+
export declare function workspacePathsFor(scriptRelPath: string): BrepFiles;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FileOps, ToolContext, ToolPluginCore } from "gui-chat-protocol";
|
|
2
|
+
import type { PresentBrepArgs, PresentBrepData, PresentBrepResult } from "./types";
|
|
3
|
+
/** What the plugin takes from its host: `files.artifacts`, optional. Without
|
|
4
|
+
* it a model is built and checked and nothing is saved. */
|
|
5
|
+
export interface BrepExecuteContext extends ToolContext {
|
|
6
|
+
files?: {
|
|
7
|
+
artifacts: FileOps;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export declare const presentBrep: (context: BrepExecuteContext, args: PresentBrepArgs) => Promise<PresentBrepResult>;
|
|
11
|
+
export declare const pluginCore: ToolPluginCore<PresentBrepData, unknown, PresentBrepArgs>;
|
|
12
|
+
export declare const executePresentBrep: (context: BrepExecuteContext, args: PresentBrepArgs) => Promise<PresentBrepResult>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ToolResult } from "gui-chat-protocol";
|
|
2
|
+
import type { BrepErrorCode, ModelReport } from "../kernel/index";
|
|
3
|
+
import type { BrepMesh } from "./mesh";
|
|
4
|
+
export type { BrepErrorCode, ModelReport };
|
|
5
|
+
/** Args the model passes. `script` builds a new model and saves it; `path`
|
|
6
|
+
* rebuilds one that is already saved (after an edit to the file). Only
|
|
7
|
+
* `title` is `required` in the schema, which cannot say "one or the other";
|
|
8
|
+
* the executor does. */
|
|
9
|
+
export interface PresentBrepArgs {
|
|
10
|
+
title: string;
|
|
11
|
+
script?: string;
|
|
12
|
+
path?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Workspace-relative paths of what a build wrote. */
|
|
15
|
+
export interface BrepFiles {
|
|
16
|
+
/** The script: `artifacts/brep/<name>.replicad.js`. */
|
|
17
|
+
script: string;
|
|
18
|
+
step: string;
|
|
19
|
+
stl: string;
|
|
20
|
+
/** The sheet of line drawings, SVG. */
|
|
21
|
+
views: string;
|
|
22
|
+
}
|
|
23
|
+
/** The exports themselves, each as `pack` (`packed.ts`) makes it, for the
|
|
24
|
+
* View's download buttons. The script is not here: `data.script` is it. */
|
|
25
|
+
export interface BrepDownloads {
|
|
26
|
+
/** The file name without an extension: the saved files' own, or one made
|
|
27
|
+
* from the title on a host that saved nothing. */
|
|
28
|
+
name: string;
|
|
29
|
+
step: string;
|
|
30
|
+
stl: string;
|
|
31
|
+
/** The sheet of line drawings, SVG. */
|
|
32
|
+
views: string;
|
|
33
|
+
}
|
|
34
|
+
/** What a View draws from. The mesh is here, packed, because a View cannot
|
|
35
|
+
* run the kernel and a host owes it no way to read a file. */
|
|
36
|
+
export interface PresentBrepData {
|
|
37
|
+
script: string;
|
|
38
|
+
report: ModelReport;
|
|
39
|
+
mesh: BrepMesh;
|
|
40
|
+
/** Absent on a host with no file layer: the model was built and checked,
|
|
41
|
+
* and nothing was saved. */
|
|
42
|
+
files?: BrepFiles;
|
|
43
|
+
/** Absent in a result from before the View had downloads. */
|
|
44
|
+
downloads?: BrepDownloads;
|
|
45
|
+
}
|
|
46
|
+
export interface BrepDiagnostic {
|
|
47
|
+
code: BrepErrorCode;
|
|
48
|
+
message: string;
|
|
49
|
+
/** 1-based line of the script. */
|
|
50
|
+
line?: number;
|
|
51
|
+
/** What the operations before the failure did. */
|
|
52
|
+
completed?: string[];
|
|
53
|
+
}
|
|
54
|
+
export type PresentBrepBuiltResult = ToolResult<PresentBrepData, {
|
|
55
|
+
report: ModelReport;
|
|
56
|
+
files?: BrepFiles;
|
|
57
|
+
}> & {
|
|
58
|
+
data: PresentBrepData;
|
|
59
|
+
};
|
|
60
|
+
/** An error carries no `data`: nothing to draw. `jsonData` goes back to the
|
|
61
|
+
* model. */
|
|
62
|
+
export type PresentBrepErrorResult = ToolResult<never, {
|
|
63
|
+
error: BrepDiagnostic;
|
|
64
|
+
}> & {
|
|
65
|
+
data?: never;
|
|
66
|
+
error: BrepDiagnostic;
|
|
67
|
+
};
|
|
68
|
+
export type PresentBrepResult = PresentBrepBuiltResult | PresentBrepErrorResult;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/kernel/errors.ts
|
|
2
|
+
var e = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
line;
|
|
5
|
+
completed = [];
|
|
6
|
+
constructor(e, t, n) {
|
|
7
|
+
super(t), this.name = "BrepError", this.code = e, this.line = n;
|
|
8
|
+
}
|
|
9
|
+
}, t = "brep-model-script.js", n = /brep-model-script\.js:(\d+)/;
|
|
10
|
+
function r(e) {
|
|
11
|
+
let t = e ? n.exec(e) : null;
|
|
12
|
+
return t?.[1] ? Number(t[1]) : void 0;
|
|
13
|
+
}
|
|
14
|
+
function i() {
|
|
15
|
+
return r((/* @__PURE__ */ Error()).stack);
|
|
16
|
+
}
|
|
17
|
+
var a = (e) => typeof WebAssembly < "u" && "Exception" in WebAssembly && e instanceof WebAssembly.Exception;
|
|
18
|
+
function o(e, t) {
|
|
19
|
+
if (a(t)) try {
|
|
20
|
+
let [n, r] = e.getExceptionMessage(t);
|
|
21
|
+
return r ? `${n}: ${r}` : n;
|
|
22
|
+
} catch {
|
|
23
|
+
return "the kernel raised an exception it could not describe";
|
|
24
|
+
}
|
|
25
|
+
return t instanceof Error ? t.message : String(t);
|
|
26
|
+
}
|
|
27
|
+
export { r as a, o as i, t as n, i as r, e as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=class extends Error{code;line;completed=[];constructor(e,t,n){super(t),this.name=`BrepError`,this.code=e,this.line=n}},t=`brep-model-script.js`,n=/brep-model-script\.js:(\d+)/;function r(e){let t=e?n.exec(e):null;return t?.[1]?Number(t[1]):void 0}function i(){return r(Error().stack)}var a=e=>typeof WebAssembly<`u`&&`Exception`in WebAssembly&&e instanceof WebAssembly.Exception;function o(e,t){if(a(t))try{let[n,r]=e.getExceptionMessage(t);return r?`${n}: ${r}`:n}catch{return`the kernel raised an exception it could not describe`}return t instanceof Error?t.message:String(t)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return e}});
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors-BgFaRg0j.cjs"),t=require("./mesh-DLZoiBza.cjs");let n=require("gui-chat-protocol"),r=require("@gui-chat-plugin/common");var i=`brep`,a=`.replicad.js`,o={step:`.step`,stl:`.stl`,views:`.svg`};function s(){let e=globalThis.crypto.getRandomValues(new Uint8Array(4));return Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}function c(e,t=new Date,n=s()){return(0,r.buildArtifactRelPath)({dir:i,title:e,ext:a,fallback:`model`,now:t,partitioned:!1,suffix:n})}function l(e){let t=`${n.ARTIFACTS_ROOT}/${i}/`;if(e.startsWith(t)&&e.endsWith(`.replicad.js`)&&!(0,r.hasUnsafePathSegment)(e)&&e.length!==t.length+12)return e.slice(n.ARTIFACTS_ROOT.length+1)}function u(e){let t=e.slice(0,-12);return{script:e,step:`${t}${o.step}`,stl:`${t}${o.stl}`,views:`${t}${o.views}`}}function d(e){let t=u(e);return{script:(0,r.toWorkspaceArtifactPath)(t.script),step:(0,r.toWorkspaceArtifactPath)(t.step),stl:(0,r.toWorkspaceArtifactPath)(t.stl),views:(0,r.toWorkspaceArtifactPath)(t.views)}}var f=`Read the report against what you meant to build before telling the user it is done: the size, the face counts, and how many edges each fillet and chamfer selected. A selector that picked too many edges is not an error and shows only there. Check which side the user sees first (the message says): if the part has its back to them, turn it and build again. Then look at the drawing sheet if you can open it. Tell the user they can download the script, STEP, STL and drawings from the view; the message has the saved paths.`,p=e=>`The build has ${e} warning${e===1?``:`s`}, at the top of the message. Do not tell the user it is done before each one is dealt with: correct the script and build again, or, where the warning describes what you meant, tell the user what it says and why it is intended. `,m=`
|
|
2
|
+
Shown to the user from -Y first (the 3D view and the Front drawing look from -Y toward +Y): whatever is at -Y faces them.`,h=`The model was not built. Correct the script using the diagnostic (the line, and what the operation had to work with) and call presentBrep again.`,g=e=>typeof e==`string`&&e.trim()!==``,_=e=>typeof e==`object`&&!!e,v=t=>new e.t(`INVALID_ARGUMENT`,t),y=5;async function b(e,t){for(let n=0;n<y;n++){let n=c(t);if(!await e.exists(n))return n}throw v(`Could not allocate a free path under artifacts/brep; try again with a different title`)}async function x(e,t){if(g(t.path)&&g(t.script))throw v("Provide either `script` or `path`, not both");if(g(t.path)){let n=e.files?.artifacts;if(!n)throw v("This host cannot open a script by path; pass the source as `script`");let r=l(t.path);if(!r)throw v(`\`path\` must be a ${a} file under artifacts/brep/, without \`.\` or \`..\` segments`);if(!await n.exists(r))throw v(`No script exists at ${t.path}`);return{script:await n.read(r),relPath:r}}if(!g(t.script))throw v("A `script` or a `path` is required");return{script:t.script}}function S(t){return t instanceof e.t?{code:t.code,message:t.message,...t.line===void 0?{}:{line:t.line},...t.completed.length?{completed:t.completed}:{}}:{code:`SCRIPT_ERROR`,message:t instanceof Error?t.message:String(t)}}function C(e){let t=e.line===void 0?``:` (line ${e.line})`,n=e.completed?.length?`\nBefore it:\n${e.completed.map(e=>` ${e}`).join(`
|
|
3
|
+
`)}`:``;return`presentBrep error${t}: ${e.message}${n}`}var w=async(e,n)=>{try{if(!_(n))throw v("presentBrep takes an object with `script` or `path`");if(!g(n.title))throw v("A nonempty `title` is required");let r=e??{},i=await x(r,n),{buildModel:o,formatReport:s}=await Promise.resolve().then(()=>require("./kernel-BA8zZi78.cjs")),l=await o(i.script),h=r.files?.artifacts,y,S=i.relPath??c(n.title);if(h){S=i.relPath??await b(h,n.title);let e=u(S);i.relPath||await h.write(e.script,i.script),await h.write(e.step,l.step),await h.write(e.stl,l.stl),await h.write(e.views,l.views),y=d(S)}let C=y?`\nSaved: ${y.script} (script), ${y.step}, ${y.stl}, ${y.views} (drawings).`:`
|
|
4
|
+
Not saved: this host has no file layer.`,w={script:i.script,report:l.report,mesh:l.mesh,...y?{files:y}:{},downloads:{name:S.slice(S.lastIndexOf(`/`)+1,-a.length),step:await t.i(l.step),stl:await t.i(l.stl),views:await t.i(l.views)}};return{message:`Built "${n.title}": ${s(l.report)}${m}${C}`,title:n.title,data:w,jsonData:{report:l.report,...y?{files:y}:{}},instructions:(l.report.warnings.length?p(l.report.warnings.length):``)+f}}catch(e){let t=S(e);return{message:C(t),error:t,jsonData:{error:t},instructions:h}}},T={toolDefinition:t.o,execute:w,generatingMessage:`Building the solid model...`,waitingMessage:`Tell the user that the solid model is being built and will be shown shortly.`,isEnabled:()=>!0},E=w;exports.SCRIPT_EXTENSION=a,exports.TOOL_DEFINITION=t.o,exports.TOOL_NAME=t.s,exports.decodeMesh=t.t,exports.encodeMesh=t.n,exports.executePresentBrep=E,exports.isBrepMesh=t.r,exports.newScriptRelPath=c,exports.pluginCore=T,exports.presentBrep=w,exports.relPathsFor=u,exports.scriptRelPathOf=l,exports.workspacePathsFor=d;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core/index";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { t as e } from "./errors-BANLyHzz.js";
|
|
2
|
+
import { i as t, n, o as r, r as i, s as a, t as o } from "./mesh-Cmm66x_I.js";
|
|
3
|
+
import { ARTIFACTS_ROOT as s } from "gui-chat-protocol";
|
|
4
|
+
import { buildArtifactRelPath as c, hasUnsafePathSegment as l, toWorkspaceArtifactPath as u } from "@gui-chat-plugin/common";
|
|
5
|
+
// src/core/paths.ts
|
|
6
|
+
var d = "brep", f = ".replicad.js", p = {
|
|
7
|
+
step: ".step",
|
|
8
|
+
stl: ".stl",
|
|
9
|
+
views: ".svg"
|
|
10
|
+
};
|
|
11
|
+
function m() {
|
|
12
|
+
let e = globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(4));
|
|
13
|
+
return Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
14
|
+
}
|
|
15
|
+
function h(e, t = /* @__PURE__ */ new Date(), n = m()) {
|
|
16
|
+
return c({
|
|
17
|
+
dir: d,
|
|
18
|
+
title: e,
|
|
19
|
+
ext: f,
|
|
20
|
+
fallback: "model",
|
|
21
|
+
now: t,
|
|
22
|
+
partitioned: !1,
|
|
23
|
+
suffix: n
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function g(e) {
|
|
27
|
+
let t = `${s}/${d}/`;
|
|
28
|
+
if (e.startsWith(t) && e.endsWith(".replicad.js") && !l(e) && e.length !== t.length + 12) return e.slice(s.length + 1);
|
|
29
|
+
}
|
|
30
|
+
function _(e) {
|
|
31
|
+
let t = e.slice(0, -12);
|
|
32
|
+
return {
|
|
33
|
+
script: e,
|
|
34
|
+
step: `${t}${p.step}`,
|
|
35
|
+
stl: `${t}${p.stl}`,
|
|
36
|
+
views: `${t}${p.views}`
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function v(e) {
|
|
40
|
+
let t = _(e);
|
|
41
|
+
return {
|
|
42
|
+
script: u(t.script),
|
|
43
|
+
step: u(t.step),
|
|
44
|
+
stl: u(t.stl),
|
|
45
|
+
views: u(t.views)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// src/core/plugin.ts
|
|
49
|
+
var y = "Read the report against what you meant to build before telling the user it is done: the size, the face counts, and how many edges each fillet and chamfer selected. A selector that picked too many edges is not an error and shows only there. Check which side the user sees first (the message says): if the part has its back to them, turn it and build again. Then look at the drawing sheet if you can open it. Tell the user they can download the script, STEP, STL and drawings from the view; the message has the saved paths.", b = (e) => `The build has ${e} warning${e === 1 ? "" : "s"}, at the top of the message. Do not tell the user it is done before each one is dealt with: correct the script and build again, or, where the warning describes what you meant, tell the user what it says and why it is intended. `, x = "\nShown to the user from -Y first (the 3D view and the Front drawing look from -Y toward +Y): whatever is at -Y faces them.", S = "The model was not built. Correct the script using the diagnostic (the line, and what the operation had to work with) and call presentBrep again.", C = (e) => typeof e == "string" && e.trim() !== "", w = (e) => typeof e == "object" && !!e, T = (t) => new e("INVALID_ARGUMENT", t), E = 5;
|
|
50
|
+
async function D(e, t) {
|
|
51
|
+
for (let n = 0; n < E; n++) {
|
|
52
|
+
let n = h(t);
|
|
53
|
+
if (!await e.exists(n)) return n;
|
|
54
|
+
}
|
|
55
|
+
throw T("Could not allocate a free path under artifacts/brep; try again with a different title");
|
|
56
|
+
}
|
|
57
|
+
async function O(e, t) {
|
|
58
|
+
if (C(t.path) && C(t.script)) throw T("Provide either `script` or `path`, not both");
|
|
59
|
+
if (C(t.path)) {
|
|
60
|
+
let n = e.files?.artifacts;
|
|
61
|
+
if (!n) throw T("This host cannot open a script by path; pass the source as `script`");
|
|
62
|
+
let r = g(t.path);
|
|
63
|
+
if (!r) throw T(`\`path\` must be a ${f} file under artifacts/brep/, without \`.\` or \`..\` segments`);
|
|
64
|
+
if (!await n.exists(r)) throw T(`No script exists at ${t.path}`);
|
|
65
|
+
return {
|
|
66
|
+
script: await n.read(r),
|
|
67
|
+
relPath: r
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (!C(t.script)) throw T("A `script` or a `path` is required");
|
|
71
|
+
return { script: t.script };
|
|
72
|
+
}
|
|
73
|
+
function k(t) {
|
|
74
|
+
return t instanceof e ? {
|
|
75
|
+
code: t.code,
|
|
76
|
+
message: t.message,
|
|
77
|
+
...t.line === void 0 ? {} : { line: t.line },
|
|
78
|
+
...t.completed.length ? { completed: t.completed } : {}
|
|
79
|
+
} : {
|
|
80
|
+
code: "SCRIPT_ERROR",
|
|
81
|
+
message: t instanceof Error ? t.message : String(t)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function A(e) {
|
|
85
|
+
let t = e.line === void 0 ? "" : ` (line ${e.line})`, n = e.completed?.length ? `\nBefore it:\n${e.completed.map((e) => ` ${e}`).join("\n")}` : "";
|
|
86
|
+
return `presentBrep error${t}: ${e.message}${n}`;
|
|
87
|
+
}
|
|
88
|
+
var j = async (e, n) => {
|
|
89
|
+
try {
|
|
90
|
+
if (!w(n)) throw T("presentBrep takes an object with `script` or `path`");
|
|
91
|
+
if (!C(n.title)) throw T("A nonempty `title` is required");
|
|
92
|
+
let r = e ?? {}, i = await O(r, n), { buildModel: a, formatReport: o } = await import("./kernel-75dHFfjx.js"), s = await a(i.script), c = r.files?.artifacts, l, u = i.relPath ?? h(n.title);
|
|
93
|
+
if (c) {
|
|
94
|
+
u = i.relPath ?? await D(c, n.title);
|
|
95
|
+
let e = _(u);
|
|
96
|
+
i.relPath || await c.write(e.script, i.script), await c.write(e.step, s.step), await c.write(e.stl, s.stl), await c.write(e.views, s.views), l = v(u);
|
|
97
|
+
}
|
|
98
|
+
let d = l ? `\nSaved: ${l.script} (script), ${l.step}, ${l.stl}, ${l.views} (drawings).` : "\nNot saved: this host has no file layer.", p = {
|
|
99
|
+
script: i.script,
|
|
100
|
+
report: s.report,
|
|
101
|
+
mesh: s.mesh,
|
|
102
|
+
...l ? { files: l } : {},
|
|
103
|
+
downloads: {
|
|
104
|
+
name: u.slice(u.lastIndexOf("/") + 1, -f.length),
|
|
105
|
+
step: await t(s.step),
|
|
106
|
+
stl: await t(s.stl),
|
|
107
|
+
views: await t(s.views)
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
message: `Built "${n.title}": ${o(s.report)}${x}${d}`,
|
|
112
|
+
title: n.title,
|
|
113
|
+
data: p,
|
|
114
|
+
jsonData: {
|
|
115
|
+
report: s.report,
|
|
116
|
+
...l ? { files: l } : {}
|
|
117
|
+
},
|
|
118
|
+
instructions: (s.report.warnings.length ? b(s.report.warnings.length) : "") + y
|
|
119
|
+
};
|
|
120
|
+
} catch (e) {
|
|
121
|
+
let t = k(e);
|
|
122
|
+
return {
|
|
123
|
+
message: A(t),
|
|
124
|
+
error: t,
|
|
125
|
+
jsonData: { error: t },
|
|
126
|
+
instructions: S
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}, M = {
|
|
130
|
+
toolDefinition: r,
|
|
131
|
+
execute: j,
|
|
132
|
+
generatingMessage: "Building the solid model...",
|
|
133
|
+
waitingMessage: "Tell the user that the solid model is being built and will be shown shortly.",
|
|
134
|
+
isEnabled: () => !0
|
|
135
|
+
}, N = j;
|
|
136
|
+
export { f as SCRIPT_EXTENSION, r as TOOL_DEFINITION, a as TOOL_NAME, o as decodeMesh, n as encodeMesh, N as executePresentBrep, i as isBrepMesh, h as newScriptRelPath, M as pluginCore, j as presentBrep, _ as relPathsFor, g as scriptRelPathOf, v as workspacePathsFor };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { OpenCascadeInstance } from "replicad-opencascadejs";
|
|
2
|
+
export type BrepErrorCode =
|
|
3
|
+
/** The arguments, or a `path` this plugin does not own. */
|
|
4
|
+
"INVALID_ARGUMENT"
|
|
5
|
+
/** The script does not compile. */
|
|
6
|
+
| "SYNTAX_ERROR"
|
|
7
|
+
/** The script threw, or `main` is missing or returned something unusable. */
|
|
8
|
+
| "SCRIPT_ERROR"
|
|
9
|
+
/** A modelling operation failed in the kernel. */
|
|
10
|
+
| "OPERATION_FAILED"
|
|
11
|
+
/** An operation returned, but its result is not a valid solid. */
|
|
12
|
+
| "INVALID_RESULT"
|
|
13
|
+
/** The script ran past the time limit. */
|
|
14
|
+
| "TIMEOUT";
|
|
15
|
+
export declare class BrepError extends Error {
|
|
16
|
+
readonly code: BrepErrorCode;
|
|
17
|
+
/** 1-based line of the script, where one is known. */
|
|
18
|
+
readonly line: number | undefined;
|
|
19
|
+
/** What the operations before the failure did, as the report lists them:
|
|
20
|
+
* set by the build, for an error raised while the script ran. */
|
|
21
|
+
completed: string[];
|
|
22
|
+
constructor(code: BrepErrorCode, message: string, line?: number);
|
|
23
|
+
}
|
|
24
|
+
/** The name the script is compiled under: what its frames carry in a stack. */
|
|
25
|
+
export declare const SCRIPT_FILENAME = "brep-model-script.js";
|
|
26
|
+
/** The script line a stack passes through, innermost first: for a helper
|
|
27
|
+
* defined in the script, the line inside the helper. */
|
|
28
|
+
export declare function scriptLineOf(stack: string | undefined): number | undefined;
|
|
29
|
+
/** The script line this call was made from. */
|
|
30
|
+
export declare function currentScriptLine(): number | undefined;
|
|
31
|
+
/** A thrown value as text: the kernel's exception class and message for a
|
|
32
|
+
* WebAssembly exception, the message for an Error. */
|
|
33
|
+
export declare function describeThrown(oc: OpenCascadeInstance, thrown: unknown): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BrepError } from "./errors";
|
|
2
|
+
import type { BrepMesh } from "../core/mesh";
|
|
3
|
+
import { formatReport, type ModelReport } from "./report";
|
|
4
|
+
export { BrepError } from "./errors";
|
|
5
|
+
export type { BrepErrorCode } from "./errors";
|
|
6
|
+
export type { ModelReport, OperationSummary, PartReport } from "./report";
|
|
7
|
+
export { formatReport };
|
|
8
|
+
export interface BuiltModel {
|
|
9
|
+
report: ModelReport;
|
|
10
|
+
step: Uint8Array;
|
|
11
|
+
stl: Uint8Array;
|
|
12
|
+
/** A sheet of four line drawings, as SVG. */
|
|
13
|
+
views: string;
|
|
14
|
+
/** The model as a View draws it. */
|
|
15
|
+
mesh: BrepMesh;
|
|
16
|
+
}
|
|
17
|
+
/** A model's script usually builds in under a second; a minute is a script
|
|
18
|
+
* that loops, or a model far past what this is for. */
|
|
19
|
+
export declare const DEFAULT_TIMEOUT_MS = 60000;
|
|
20
|
+
export interface BuildOptions {
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Build the model a script describes. Throws `BrepError` for anything the
|
|
24
|
+
* script's author can correct. */
|
|
25
|
+
export declare function buildModel(script: string, options?: BuildOptions): Promise<BuiltModel>;
|
|
26
|
+
export declare const isBrepError: (value: unknown) => value is BrepError;
|