5.1 Session and boot ​

Contract 2.0.0 · package sha256 a857eca95b35921109faf997094bb4192f12527d9d0fcd4be7e97f06425bad6e · generated from examples/section-5/5.01-session-and-boot.ts by services/onsite-scripter/scripts/build-contract-docs.mjs; edit the source, not this file.

Imports: values (has, validate, the Holo*Error classes, the pure helpers) from @holostep-configurators/runtime-client, types from @holostep-configurators/runtime-client/contract, /math and /testing names from those entries; boot from the runtime module the root's loadRuntimeAtFloor resolves to. A type your page defines is your app's: declare it there, never import it from the package.

ts
import { loadRuntimeAtFloor, normalizeNodeIds } from '@holostep-configurators/runtime-client';
import type { IConfigurator, Report, Writer } from '@holostep-configurators/runtime-client/contract';
declare const signal: AbortSignal;
declare const el: HTMLElement;
declare const unmount: AbortController;                             // aborted when the view unmounts
declare const runtimeUrl: string;                                   // src/config/runtime.ts: the compiled pin
declare const id: string;                                           // the saved design
declare const assetBaseUrl: string;
declare function loadSavedDesign(id: string): Promise<IConfigurator>;
declare function reassemble(writer: Writer): Promise<void>;         // app code: snap the elements once
declare function showLoadError(report: Report): void;              // app code: a failure state, not an empty canvas
const runtime = await loadRuntimeAtFloor(runtimeUrl, {              // the runtime module, which exports boot
  apiVersion: '2.0.0',                                              // src/runtime/REQUIRED_CONTRACT.json
  documentSchema: 'holo.viewer-document',
  documentVersion: 2,
});
const session = await runtime.boot({ el, accountId: 164, contract: '2.0', signal: unmount.signal });
const { doc } = normalizeNodeIds(await loadSavedDesign(id));       // old saves: mint and remap ids; keep doc as your document
const load = () => session.transaction(async (tx) => {
  const set = await tx.setSceneModel(doc, { assetBaseUrl });        // a member option: legal through a tx
  const outdated = set.problems.some((p) => p.code === 'connections-outdated');
  if (!doc.connections || outdated) await reassemble(tx);           // an old save, or a v1 re-save: assemble once
}, { origin: 'load', undo: 'rebase' });                             // the loaded state is the floor of history
// An internal failure resolves 'rolled-back' with the scene restored, here empty (6.4):
// load once more while the view is mounted; then show the failure, as app-f9a32142f1 does.
let r = await load();
const failed = r.outcome === 'rolled-back' && r.reason === 'internal-error';
if (failed && !unmount.signal.aborted) r = await load();
if (r.outcome === 'rolled-back') showLoadError(r);

Back to the examples · llms.txt