Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Enable qualified Worker-backed Web runtime

Yuechen Li712a89deeccc
diff --git a/Aetheris.Web.Runtime/sdk/README.md b/Aetheris.Web.Runtime/sdk/README.md
index fdab71cd..89e759b0 100644
--- a/Aetheris.Web.Runtime/sdk/README.md
+++ b/Aetheris.Web.Runtime/sdk/README.md
@@ -18,6 +18,6 @@ Geometry provenance is assigned during Firmament parsing and BRep construction,
For a single, unmodified Firmament `Box`, the Web runtime tessellates the canonical BRep directly. Construction-owned face IDs map its six faces to `face(±X)`, `face(±Y)`, and `face(±Z)`. A single simple through-hole also retains its construction-owned wall and rim identity through direct display, but the wall and rim have no qualified Firmament selector yet. Display definitions include BRep edge polylines for a truthful edge overlay; these are not source selectors. The STEP export remains available. Other routes that reimport STEP currently return `RuntimeOnly` display faces with no source selector. A display `faceId` or triangle index is never itself a Firmament selector.
-X1 runs on the page thread. `worker: true` fails with the typed `worker-unavailable` error; a qualified Worker transport is deferred rather than silently changing behavior.
+`Aetheris.create({ worker: true })` hosts the same runtime in a dedicated module Worker. Its mesh arrays and STEP bytes cross the boundary as transferable buffers. `cad.workerTiming` and `model.workerTiming` expose the last Worker operation's execution time, message delay, and transferred buffer bytes. Terminate a wedged Worker with `cad.terminate()` and create a fresh instance; termination rejects outstanding and future requests on the old instance. The .NET 10 runtime needs a message event listener rather than an assigned `onmessage` handler during Worker initialization.
The preview package is AGPL-3.0-only. Contact the Aetheris project for commercial licensing; this statement is package metadata, not legal advice.
diff --git a/Aetheris.Web.Runtime/sdk/src/index.d.ts b/Aetheris.Web.Runtime/sdk/src/index.d.ts
index a253e86f..51010dfc 100644
--- a/Aetheris.Web.Runtime/sdk/src/index.d.ts
+++ b/Aetheris.Web.Runtime/sdk/src/index.d.ts
@@ -17,7 +17,8 @@ export interface ChangeSet { readonly changedEntityIds: readonly string[]; reado
export interface RebuildResult { readonly success: boolean; readonly revision: number; readonly diagnostics: readonly Diagnostic[]; readonly retainedPreviousGeometry: boolean; readonly changes?: ChangeSet }
export interface RuntimeCapabilities { readonly compile: boolean; readonly solidModeling: boolean; readonly assembly: boolean; readonly displayMesh: boolean; readonly propertyInspection: boolean; readonly parameterRebuild: boolean; readonly stepExport: boolean; readonly sheetMetal: boolean; readonly fea: boolean; readonly externalStepImport: boolean; readonly forgeSubprocess: boolean; readonly cancellation: boolean; readonly worker: boolean }
export interface RuntimeInfo { readonly packageVersion: string; readonly runtimeVersion: string; readonly contractVersion: 'aetheris/web-editor-contract/1'; readonly language: 'Firmament'; readonly capabilities: RuntimeCapabilities }
-export interface OperationOptions { readonly signal?: AbortSignal }
+export interface WorkerTiming { readonly operation: string; readonly executionMilliseconds: number; readonly transportMilliseconds: number; readonly payloadBytes: number }
+export interface OperationOptions { readonly signal?: AbortSignal; readonly sourceRevision?: string }
export interface CompileOptions extends OperationOptions { readonly sourceName?: string }
export interface LanguageOptions { readonly sourceName?: string; readonly sourceRevision: string }
export interface LanguageField { readonly name: string; readonly type: string; readonly required: boolean; readonly meaning: string; readonly default?: string | null; readonly choices?: readonly string[] | null }
@@ -37,15 +38,19 @@ export class AetherisError extends Error { readonly code: string; readonly detai
export class Aetheris {
static create(options?: AetherisOptions): Promise<Aetheris>;
readonly runtimeInfo: RuntimeInfo;
+ readonly workerTiming: WorkerTiming | null;
readonly language: { complete(source: string, offset: number, options: LanguageOptions): Promise<LanguageCompletion>; schema(): Promise<SemanticSchema> };
info(): Promise<RuntimeInfo>;
capabilities(): Promise<RuntimeCapabilities>;
compile(source: string, options?: CompileOptions): Promise<{ model: ModelSession | null; diagnostics: readonly Diagnostic[] }>;
dispose(): Promise<void>;
+ terminate(): void;
}
export class ModelSession {
readonly id: string; readonly name: string; readonly revision: number; readonly source: string; readonly sourceName: string;
readonly tree: ModelTree; readonly properties: readonly EditableProperty[]; readonly mesh: DisplayMesh; readonly diagnostics: readonly Diagnostic[]; readonly changes: ChangeSet;
+ readonly timings?: { readonly compileMilliseconds: number; readonly meshMilliseconds?: number };
+ readonly workerTiming: WorkerTiming | null;
entity(id: string): ModelTreeNode | undefined;
property(id: string): EditableProperty | undefined;
setProperty(propertyId: string, value: UnitValue, options?: OperationOptions): Promise<RebuildResult>;
diff --git a/Aetheris.Web.Runtime/sdk/src/index.js b/Aetheris.Web.Runtime/sdk/src/index.js
index d78f72f0..2f521514 100644
--- a/Aetheris.Web.Runtime/sdk/src/index.js
+++ b/Aetheris.Web.Runtime/sdk/src/index.js
@@ -27,30 +27,50 @@ class WorkerTransport {
this.worker.onmessage = ({ data }) => {
const pending = this.pending.get(data.id); if (!pending) return;
this.pending.delete(data.id);
+ if (data.version !== 1) { pending.reject(new AetherisError('worker-protocol', `Unsupported Aetheris worker protocol ${data.version}.`)); return; }
+ if (data.sourceRevision !== pending.sourceRevision) { pending.reject(new AetherisError('worker-revision', 'The Aetheris worker returned a mismatched source revision.')); return; }
+ this.lastTiming = { operation: pending.operation, executionMilliseconds: data.executionMilliseconds ?? 0,
+ transportMilliseconds: Math.max(0, performance.now() - pending.started - (data.executionMilliseconds ?? 0)), payloadBytes: data.payloadBytes ?? 0 };
data.error ? pending.reject(new AetherisError(data.error.code, data.error.message, data.error.details)) : pending.resolve(data.result);
};
this.worker.onerror = event => {
const error = new AetherisError('worker-error', event.message || 'The Aetheris worker failed to start.');
+ this.failure = error;
+ for (const pending of this.pending.values()) pending.reject(error);
+ this.pending.clear();
+ };
+ this.worker.onmessageerror = () => {
+ const error = new AetherisError('worker-message-error', 'The Aetheris worker returned an unreadable result.');
+ this.failure = error;
for (const pending of this.pending.values()) pending.reject(error);
this.pending.clear();
};
}
request(request) {
+ if (this.failure) return Promise.reject(this.failure);
return new Promise((resolve, reject) => {
- const id = ++this.nextId; this.pending.set(id, { resolve, reject });
- this.worker.postMessage({ id, request, runtimeBase: this.runtimeBase?.href });
+ const id = ++this.nextId; const sourceRevision = request.sourceRevision ?? null;
+ this.pending.set(id, { resolve, reject, operation: request.operation, sourceRevision, started: performance.now() });
+ try { this.worker.postMessage({ version: 1, id, sourceRevision, request, runtimeBase: this.runtimeBase?.href }); }
+ catch (error) { this.pending.delete(id); reject(error); }
});
}
- async dispose() { try { await this.request({ operation: 'disposeRuntime' }); } finally { this.worker.terminate(); } }
+ async dispose() { try { if (!this.failure) await this.request({ operation: 'disposeRuntime' }); } finally { this.terminate(); } }
+ terminate() {
+ this.worker.terminate();
+ this.failure = new AetherisError('worker-terminated', 'The Aetheris worker was restarted.');
+ for (const pending of this.pending.values()) pending.reject(this.failure);
+ this.pending.clear();
+ }
}
export class Aetheris {
static async create(options = {}) {
- if (options.worker === true) throw new AetherisError('worker-unavailable', 'Worker-backed execution is not qualified in Web SDK X1. Use the default in-page runtime.');
const runtimeBase = options.wasmUrl ? new URL(options.wasmUrl, globalThis.location?.href) : defaultRuntimeBase;
- const transport = new DirectTransport(runtimeBase);
+ const transport = options.worker === true ? new WorkerTransport(runtimeBase) : new DirectTransport(runtimeBase);
const cad = new Aetheris(transport, options.diagnostics);
- cad.runtimeInfo = await cad.info();
+ try { cad.runtimeInfo = await cad.info(); }
+ catch (error) { transport.terminate?.(); throw error; }
return cad;
}
constructor(transport, diagnostics) {
@@ -61,19 +81,25 @@ export class Aetheris {
sourceName: options.sourceName, sourceRevision: options.sourceRevision })
};
}
- info() { return this.transport.request({ operation: 'info' }); }
+ async info() {
+ const info = await this.transport.request({ operation: 'info' });
+ return this.transport instanceof WorkerTransport ? { ...info, capabilities: { ...info.capabilities, worker: true } } : info;
+ }
async capabilities() { return (await this.info()).capabilities; }
async compile(source, options = {}) {
throwIfAborted(options.signal);
- const result = await this.transport.request({ operation: 'compile', source, sourceName: options.sourceName });
+ const result = await this.transport.request({ operation: 'compile', source, sourceName: options.sourceName, sourceRevision: options.sourceRevision });
this.diagnostics?.(result.diagnostics);
return { model: result.success ? new ModelSession(this.transport, result.model) : null, diagnostics: result.diagnostics };
}
dispose() { return this.transport.dispose(); }
+ terminate() { this.transport.terminate?.(); }
+ get workerTiming() { return this.transport.lastTiming ?? null; }
}
export class ModelSession {
constructor(transport, snapshot) { this.transport = transport; this.apply(snapshot); this.queue = Promise.resolve(); }
+ get workerTiming() { return this.transport.lastTiming ?? null; }
apply(snapshot) {
Object.assign(this, snapshot);
this._rangesBySemantic = new Map();
@@ -104,7 +130,7 @@ export class ModelSession {
return this.serial(async () => { throwIfAborted(options.signal); await this.transport.request({ operation: 'setProperty', sessionId: this.id, propertyId, value }); return this.rebuild(options); });
}
async setSource(source, options = {}) {
- return this.serial(async () => { throwIfAborted(options.signal); await this.transport.request({ operation: 'setSource', sessionId: this.id, source, sourceName: options.sourceName }); return this.rebuild(options); });
+ return this.serial(async () => { throwIfAborted(options.signal); await this.transport.request({ operation: 'setSource', sessionId: this.id, source, sourceName: options.sourceName, sourceRevision: options.sourceRevision }); return this.rebuild(options); });
}
async describeConstruct(semanticId, options = {}) {
throwIfAborted(options.signal);
@@ -118,7 +144,7 @@ export class ModelSession {
}
async rebuild(options = {}) {
throwIfAborted(options.signal);
- const result = await this.transport.request({ operation: 'rebuild', sessionId: this.id });
+ const result = await this.transport.request({ operation: 'rebuild', sessionId: this.id, sourceRevision: options.sourceRevision });
if (result.success) this.apply(result.model);
return result;
}
@@ -180,6 +206,7 @@ export class ModelSession {
async exportSTEP(options = {}) {
throwIfAborted(options.signal);
const result = await this.transport.request({ operation: 'exportStep', sessionId: this.id });
+ if (result.bytes instanceof Uint8Array) return result.bytes;
const binary = atob(result.base64); const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
return bytes;
diff --git a/Aetheris.Web.Runtime/sdk/src/worker.js b/Aetheris.Web.Runtime/sdk/src/worker.js
index bf6313b7..a31394fa 100644
--- a/Aetheris.Web.Runtime/sdk/src/worker.js
+++ b/Aetheris.Web.Runtime/sdk/src/worker.js
@@ -1,13 +1,25 @@
import { createRuntime, transferables } from './runtime.js';
-let invoke;
-self.onmessage = async event => {
- const { id, request, runtimeBase } = event.data;
+let runtimePromise;
+// .NET 10 detects a truthy onmessage as a runtime sidecar Worker and can hang
+// during asset loading. A listener leaves that property unset.
+self.addEventListener('message', async event => {
+ const { version, id, sourceRevision, request, runtimeBase } = event.data;
try {
- invoke ??= await createRuntime(runtimeBase ? new URL(runtimeBase) : undefined);
+ if (version !== 1) throw new Error(`Unsupported Aetheris worker protocol ${version}.`);
+ const invoke = await (runtimePromise ??= createRuntime(runtimeBase ? new URL(runtimeBase) : undefined));
+ const started = performance.now();
const result = invoke(request);
- self.postMessage({ id, result }, { transfer: transferables(result) });
+ const executionMilliseconds = performance.now() - started;
+ if (request.operation === 'exportStep') {
+ const binary = atob(result.base64);
+ const bytes = Uint8Array.from(binary, character => character.charCodeAt(0));
+ self.postMessage({ version, id, sourceRevision, result: { bytes }, executionMilliseconds, payloadBytes: bytes.byteLength }, { transfer: [bytes.buffer] });
+ } else {
+ const buffers = transferables(result);
+ self.postMessage({ version, id, sourceRevision, result, executionMilliseconds, payloadBytes: buffers.reduce((size, buffer) => size + buffer.byteLength, 0) }, { transfer: buffers });
+ }
} catch (error) {
- self.postMessage({ id, error: { name: error.name, code: error.code ?? 'internal-error', message: error.message, details: error.details } });
+ self.postMessage({ version, id, sourceRevision, error: { name: error.name, code: error.code ?? 'internal-error', message: error.message, details: error.details } });
}
-};
+});