import { SimSession, CONTEXT_ID, PROTOCOL_SCHEMA } from "./sim-session.mjs"; import { XyzacCommandLedger, XYZAC_COMMAND_LEDGER_SCHEMA } from "./xyzac-command-ledger.mjs"; import { XyzacScheduler, XYZAC_SCHEDULER_SCHEMA } from "./xyzac-scheduler.mjs"; import { DEFAULT_MACHINE } from "../workspace/machine-definitions.mjs"; export const XYZAC_SESSION_SCHEMA = "xyzac-session.v1"; export class XyzacSession extends SimSession { constructor(core, options = {}) { super(core, options); this.ledger = new XyzacCommandLedger(); this.scheduler = new XyzacScheduler(core); this.session_scope = "selected_xyzac_simulation"; } authority() { const machine = this.machineDefinition ?? DEFAULT_MACHINE; return { schema: XYZAC_SESSION_SCHEMA, authority: "linuxcnc-wasm-worker", context_id: this.contextId, session_id: this.sessionId, scope: this.session_scope, protocol_schema: PROTOCOL_SCHEMA, ledger_schema: XYZAC_COMMAND_LEDGER_SCHEMA, scheduler_schema: XYZAC_SCHEDULER_SCHEMA, machine: { coordinates: machine.coordinates, joint_count: machine.joint_count, kinematics: machine.id, rotary_units: "degrees" }, }; } accept(input) { const response = super.accept(input); if (!response?.payload || typeof response.payload !== "object") return response; // super.accept stores the response in the operation ledger. Enrich a // shallow client copy so the next ledger audit cannot recursively embed // every previous response inside the stored response object. const payload = { ...response.payload }; payload.xyzac_session = this.authority(); // The operation ledger remains complete inside the worker for recovery. // Browser responses need only an audit summary: including historical // PROGRAM_LOAD responses repeatedly clones the full toolpath after every // control click, which can starve an abort behind a large G-code preview. payload.xyzac_ledger = this.ledger.audit({ includeResponses: false, maxEntries: input.kind === "SIM_STEP" ? 32 : 128 }); payload.xyzac_scheduler = this.scheduler.export(); return { ...response, payload }; } } export { CONTEXT_ID, PROTOCOL_SCHEMA };