/** * Preview boarding with the CANDIDATE's own seat ids. * * `helix vehicle preview` draws and drives the candidate in the real runtime, but the room that hosts the Try Now car reserved its * entity from the STAND-IN (proxy) car: its seat vars, its module identity, its action table. The client, which runs the candidate's * package, asks for a seat in the candidate's vocabulary (its `seatVars` key, its enter-seat function). The room only knows the * stand-in's, so a candidate whose seat keys differ ("driver" against the stand-in's "seat_dside_f") was refused with * "E pressed, not seated" — the preview then reported it could not board, which is a statement about the stand-in, not the candidate. * * The fix is a translation at the one place the two vocabularies meet — the client's room send — and only for the four seat * intents (enter a seat, enter the driver's seat, exit a seat, exit the driver's seat): * * candidate cabin seat (read off the candidate GLB's `seat_*` nodes) -> the candidate's seat key (its manifest, as the engine * resolves it) -> the STAND-IN's key for the same physical seat -> sent under the stand-in's module identity and function. * * What the avatar sits in is still the candidate's seat: the engine adopts the grant against the candidate's cabin, and the summary * records both vocabularies, the seat actually used, and every translated send. When the vocabularies already agree nothing is * rewritten and the summary says so. * * SEATS THE STAND-IN ROOM DOES NOT HAVE (every rear seat, whatever the stand-in car is). The room's seat table is server-owned and * comes from the stand-in's package, so a 2+2 or a four-seater candidate used to be refused at its rear seats ("the stand-in room only * has front seats") and only a hosted run could judge a rear occupant. The room's seat table is synthesised on the CLIENT for those * seats: the hook adds the candidate's own seat key to the Try Now vehicle's replicated seat map in this page's room state and * fills it with this session when the avatar asks for the seat (E), clears it when the avatar asks to leave. From there the engine's * own custody path runs unchanged (the grant is read off the room state, the rig seats the occupant in the candidate's cabin), so the * rear occupant is drawn, measured and judged exactly like a front one. Nothing is sent to the room for such a seat, and nobody else in the * room sees it: a preview is single-client, and the summary says which seats were granted this way. * * Pure parts (vocabularies, bridge table) are here and unit-tested; the page-side hook is `INSTALL_SEAT_BRIDGE`. */ import type { Json } from '../visualQa/vehiclePreview'; export declare const isSeatId: (id: string) => boolean; /** Only the driver's front seat drives (the engine's `seatRole`). */ export declare const DRIVER_CABIN_SEAT_ID = "seat_dside_f"; export interface SeatManifest { /** `module.seatVars`: the manifest's own seat key -> the room's ref var for it. */ seatVars: Record; /** `module.driverSeat`: which seatVars key is the driver's (absent: the literal key "driver"). */ driverSeat: string | null; module: { id: string | null; bundleId: string | null; bundleChecksumSha256: string | null; }; /** Declared action functions by control kind (enter-seat, exit-seat, enter-driver, exit-driver). */ calls: Partial>; /** true when the package declares no `specialty` (the platform's default controls apply, which only the engine can spell out). */ platformDefault: boolean; } /** The seat vocabulary a vehicle package declares. A package with no `specialty` has the platform default (reported as such). */ export declare function seatManifestOf(pkg: Json): SeatManifest; /** The manifest key that addresses a cabin seat (the engine's `seatVarsKeyFor`): the id itself, else the legacy driver / passenger role key. */ export declare function seatKeyFor(m: Pick, cabinSeatId: string): string | undefined; /** The cabin seat a manifest key stands for (the engine's `cabinSeatIdFor`). */ export declare function cabinSeatOf(m: Pick, key: string): string | undefined; /** `seat_*` node names of a GLB, in canonical order (front row first, driver's side first): the candidate's physical seats. */ export declare function glbSeatNodes(nodeNames: readonly string[]): string[]; export interface SeatBridgeTable { /** What the stand-in room understands. Null when the stand-in declares no specialty (its default controls are the engine's, so no table can be built here). */ proxy: { moduleId: string; bundleId: string | null; bundleChecksumSha256: string; revision: number; calls: SeatManifest['calls']; seatKeyForCabin: Record; } | null; /** Cabin seat -> the candidate's own manifest key (null: the candidate's manifest cannot address that seat). */ candidateKeyForCabin: Record; /** The vocabularies agree for every candidate seat that has a stand-in seat: nothing needs rewriting. */ identical: boolean; /** Candidate cabin seats the stand-in room has no seat for (they cannot be granted by this room). */ unmapped: string[]; problems: string[]; } export interface SeatReport { candidate: { keys: string[]; driverKey: string | null; declaredCabinSeats: string[]; glbSeatNodes: string[]; platformDefault: boolean; }; proxy: { keys: string[]; driverKey: string | null; cabinSeats: string[]; platformDefault: boolean; }; table: SeatBridgeTable; } /** * Build the bridge from the candidate's package (+ the seat nodes of its GLB) and the stand-in's package as the Try Now session * delivered it. `proxyRevision` is the stand-in package artifact's revision (the room's identity pin). */ export declare function buildSeatBridge(candidatePkg: Json, glbSeatNodeNames: readonly string[], proxyPkg: Json, proxyRevision: number): SeatReport; /** * Page-side hook (plain JS string; `table` is `SeatBridgeTable`). Wraps the three seat entry points of every spawned vehicle's * specialty runtime so the seat INTENT is known when the room send happens, and rewrites that one send into the stand-in's * vocabulary. Everything it sends or declines to rewrite is appended to `globalThis.__vqaSeatLog`. */ export declare const INSTALL_SEAT_BRIDGE = "(table) => {\n const G = globalThis;\n if (G.__vqaSeatBridge) return { ok: true, again: true };\n const mp = G.__assetGym && G.__assetGym.mp;\n const room = mp && mp.room;\n if (!room || typeof room.sendModuleAction !== 'function') return { ok: false, why: 'no room.sendModuleAction to wrap' };\n const log = G.__vqaSeatLog = [];\n let intent = null;\n const proxy = table && table.proxy;\n const orig = room.sendModuleAction.bind(room);\n const unmapped = (table && table.unmapped) || [];\n // The Try Now vehicle's replicated seat map (format 7 `vehicleSeats`), where the engine reads who sits where.\n const seatMap = () => {\n let found = null;\n try { room.state.entities.forEach((e) => { if (!found && e && e.kind === 'universal-vehicle' && e.vehicleSeats && typeof e.vehicleSeats.set === 'function') found = e.vehicleSeats; }); } catch (err) { /* no entities */ }\n return found;\n };\n const synthGrant = (key, enter) => {\n const seats = seatMap();\n if (!seats) return { ok: false, why: 'the room state has no replicated seat map on the vehicle (a package-var seat table): the rear seat cannot be granted locally' };\n try {\n if (enter) {\n // a session holds one seat: leave any synthetic seat first\n for (const k of G.__vqaSyntheticSeats || []) if (k !== key) seats.set(k, '');\n seats.set(key, room.sessionId);\n G.__vqaSyntheticSeats = Array.from(new Set([...(G.__vqaSyntheticSeats || []), key]));\n } else seats.set(key, '');\n return { ok: true };\n } catch (err) { return { ok: false, why: String(err && err.message || err).slice(0, 160) }; }\n };\n room.sendModuleAction = function (req) {\n if (intent && intent.cabin && unmapped.indexOf(intent.cabin) >= 0 && table.candidateKeyForCabin && table.candidateKeyForCabin[intent.cabin]) {\n const key = table.candidateKeyForCabin[intent.cabin];\n const enter = intent.kind === 'enter-seat' || intent.kind === 'enter-driver';\n const r = synthGrant(key, enter);\n log.push({ t: Math.round(performance.now()), intent: { kind: intent.kind, cabin: intent.cabin }, candidate: { moduleId: req.identity && req.identity.moduleId, action: req.action, args: req.args }, sent: null, translated: false, synthetic: { key, enter, ok: r.ok }, why: r.ok ? null : r.why });\n return undefined;\n }\n let sent = req, translated = false, why = null;\n if (intent && proxy && !table.identical) {\n const call = intent.kind === 'enter-seat' ? proxy.calls['enter-seat'] || (intent.cabin === 'seat_dside_f' ? proxy.calls['enter-driver'] : null)\n : intent.kind === 'exit-seat' ? proxy.calls['exit-seat'] || (intent.cabin === 'seat_dside_f' ? proxy.calls['exit-driver'] : null)\n : intent.kind === 'enter-driver' ? proxy.calls['enter-driver'] || proxy.calls['enter-seat'] : proxy.calls['exit-driver'] || proxy.calls['exit-seat'];\n const key = proxy.seatKeyForCabin[intent.cabin];\n const generic = call && call === (intent.kind.indexOf('enter') === 0 ? proxy.calls['enter-seat'] : proxy.calls['exit-seat']);\n if (!call) why = 'the stand-in declares no function for ' + intent.kind;\n else if (generic && !key) why = 'the stand-in has no seat for ' + intent.cabin;\n else {\n // The room's module id is derived from the BUNDLE and the placement (itx..): the placement\n // is this car's, the bundle is the stand-in's.\n const cm = String(req.identity && req.identity.moduleId || '');\n const tail = cm.indexOf('itx.') === 0 ? cm.split('.').pop() : null;\n const slug = String(proxy.bundleId || '').replace(/[^a-z0-9-]/g, '').slice(0, 13) || 'item';\n const moduleId = tail && proxy.bundleId ? 'itx.' + slug + '.' + tail : proxy.moduleId;\n sent = { identity: Object.assign({}, req.identity, { moduleId, bundleChecksumSha256: proxy.bundleChecksumSha256, revision: proxy.revision }), action: call, args: generic ? { seatId: key } : {} };\n translated = true;\n }\n }\n log.push({ t: Math.round(performance.now()), intent: intent && { kind: intent.kind, cabin: intent.cabin }, candidate: { moduleId: req.identity && req.identity.moduleId, action: req.action, args: req.args }, sent: translated ? { moduleId: sent.identity.moduleId, action: sent.action, args: sent.args } : null, translated, why });\n return orig(sent);\n };\n const wrap = (spec) => {\n for (const name of ['requestSeatControl', 'requestSeatExit', 'requestDriverControl']) {\n const f = spec[name];\n if (typeof f !== 'function' || f.__vqaWrapped) continue;\n const w = function (a) {\n const prev = intent;\n const cabin = name === 'requestDriverControl' ? 'seat_dside_f' : String(a);\n intent = { kind: name === 'requestSeatControl' ? 'enter-seat' : name === 'requestSeatExit' ? 'exit-seat' : String(a), cabin };\n try { return f.apply(this, arguments); } finally { intent = prev; }\n };\n w.__vqaWrapped = true; spec[name] = w;\n }\n };\n const proto = (() => { try { const e = mp.portableVehicles.presentationRows()[0].entity; return e.specialty ? Object.getPrototypeOf(e.specialty) : null; } catch (err) { return null; } })();\n if (!proto) return { ok: false, why: 'no vehicle specialty runtime to wrap' };\n wrap(proto);\n G.__vqaSeatBridge = true;\n return { ok: true };\n}";