{"version":3,"file":"predict-bridge.cjs","sources":["../../src/debug/predict-bridge.ts"],"sourcesContent":["/**\n * Bridges a Predict's engine-level `PredictCore` (published to the global\n * `__colyseusDebug` registry) into the panel-facing `PredictDebugHandle` that\n * the debug card renders.\n *\n * The engine deliberately exposes only portable state; everything panel-shaped\n * — notably the profile → field-names mapping shown on each sub-card — is\n * derived HERE by subscribing to the core's `onTrack` stream, so none of it\n * lives in (or has to be ported with) the engine.\n *\n * Duck-typed: no import dependency on the engine, so engine-side refactors\n * don't force SDK churn.\n */\n\ntype StepFn = (state: any, dt: number, elapsedMs: number) => void;\ntype SmoothMode = \"lerp\" | \"extrapolate\" | \"damped\";\nexport type PredictMode = SmoothMode | \"reckon\" | \"raw\";\n\n/** Engine-level profile snapshot, as published by Predict (no `fields`). */\nexport interface ProfileCore {\n    readonly id: number;\n    readonly isDefault: boolean;\n    /** Attach-group this profile belongs to (collection key passed to\n     *  `attachAll`, or \"(attach)\" for standalone attaches). */\n    readonly label?: string;\n    readonly mode: PredictMode;\n    readonly delay: number;\n    readonly smoothMs: number;\n    readonly maxExtrapolate: number;\n    readonly tickInterval: number;\n    /** Value-space teleport threshold (0 = off). */\n    readonly snap: number;\n}\n\n/**\n * Engine-introspection contract Predict publishes to the registry. Exposes only\n * portable state plus an `onTrack` subscription the bridge uses to reconstruct\n * the per-profile field list.\n */\n/** The actionable read of a reconciler's drift. */\nexport type DriftStatus = \"matched\" | \"jitter\" | \"diverging\";\n\n/** Per-reconciler drift snapshot — mirrors the engine's `ReconcilerStat`\n *  (duck-typed; no engine import). */\nexport interface ReconcilerStat {\n    readonly label: string;\n    readonly status: DriftStatus;\n    readonly severity?: number;\n    readonly ema: number;\n    readonly peak: number;\n    readonly lastCorrectionMag: number;\n    readonly reconcileSeq: number;\n}\n\nexport interface PredictCore {\n    readonly name: string;\n    mode(): PredictMode;\n    smoothingDefaults(): { mode: PredictMode; delay: number; smoothMs: number; maxExtrapolate: number; tickInterval?: number };\n    reckonDefaults(): { step: StepFn | undefined; smoothMs: number; substep: number };\n    attachedCount(): number;\n    reconcilers(): ReconcilerStat[];\n    setDefaults(opts: any): void;\n    profiles(): ProfileCore[];\n    setProfile(id: number, opts: any): void;\n    onTrack(cb: (profileIdx: number, field: string) => void): () => void;\n    onDispose(cb: () => void): () => void;\n}\n\n/** Panel-facing profile snapshot — core profile plus the derived field list. */\nexport interface ProfileInfo extends ProfileCore {\n    /** Field names that have been associated with this profile (any instance). */\n    readonly fields: readonly string[];\n}\n\n/**\n * Panel-facing handle — identical to the core except `profiles()` carries the\n * derived `fields`, and `onTrack` is consumed internally (not re-exposed).\n */\nexport interface PredictDebugHandle {\n    readonly name: string;\n    mode(): PredictMode;\n    smoothingDefaults(): { mode: PredictMode; delay: number; smoothMs: number; maxExtrapolate: number; tickInterval?: number };\n    reckonDefaults(): { step: StepFn | undefined; smoothMs: number; substep: number };\n    attachedCount(): number;\n    reconcilers(): ReconcilerStat[];\n    setDefaults(opts: any): void;\n    profiles(): ProfileInfo[];\n    setProfile(id: number, opts: any): void;\n    onDispose(cb: () => void): () => void;\n}\n\n/**\n * Wrap an engine `PredictCore` into the panel's `PredictDebugHandle`,\n * maintaining the profile → field-names map from the core's track stream.\n *\n * The core is published during Predict's construction — before any\n * attach/track — so subscribing synchronously here misses no track event. No\n * removal on detach: a field name stays listed even after every instance\n * detaches, which is the right behaviour for a debug overview (and matches the\n * old engine-side `profileFields`).\n */\nexport function toDebugHandle(core: PredictCore): PredictDebugHandle {\n    const fieldsByProfile = new Map<number, Set<string>>();\n    core.onTrack((profileIdx, field) => {\n        let s = fieldsByProfile.get(profileIdx);\n        if (!s) { s = new Set(); fieldsByProfile.set(profileIdx, s); }\n        s.add(field);\n    });\n    return {\n        name: core.name,\n        mode: () => core.mode(),\n        smoothingDefaults: () => core.smoothingDefaults(),\n        reckonDefaults: () => core.reckonDefaults(),\n        attachedCount: () => core.attachedCount(),\n        reconcilers: () => core.reconcilers(),\n        setDefaults: (opts) => core.setDefaults(opts),\n        setProfile: (id, opts) => core.setProfile(id, opts),\n        onDispose: (cb) => core.onDispose(cb),\n        profiles: () => core.profiles().map((p) => ({\n            ...p,\n            fields: fieldsByProfile.get(p.id) ? [...fieldsByProfile.get(p.id)!] : [],\n        })),\n    };\n}\n"],"names":[],"mappings":";;;;;;;;AAAA;;;;;;;;;;;;AAYG;AA+EH;;;;;;;;;AASG;AACG,SAAU,aAAa,CAAC,IAAiB,EAAA;AAC3C,IAAA,MAAM,eAAe,GAAG,IAAI,GAAG,EAAuB;IACtD,IAAI,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,KAAK,KAAI;QAC/B,IAAI,CAAC,GAAG,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC;QACvC,IAAI,CAAC,CAAC,EAAE;AAAE,YAAA,CAAC,GAAG,IAAI,GAAG,EAAE;AAAE,YAAA,eAAe,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;QAAE;AAC7D,QAAA,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;AAChB,IAAA,CAAC,CAAC;IACF,OAAO;QACH,IAAI,EAAE,IAAI,CAAC,IAAI;AACf,QAAA,IAAI,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE;AACvB,QAAA,iBAAiB,EAAE,MAAM,IAAI,CAAC,iBAAiB,EAAE;AACjD,QAAA,cAAc,EAAE,MAAM,IAAI,CAAC,cAAc,EAAE;AAC3C,QAAA,aAAa,EAAE,MAAM,IAAI,CAAC,aAAa,EAAE;AACzC,QAAA,WAAW,EAAE,MAAM,IAAI,CAAC,WAAW,EAAE;QACrC,WAAW,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;AAC7C,QAAA,UAAU,EAAE,CAAC,EAAE,EAAE,IAAI,KAAK,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC;QACnD,SAAS,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACrC,QAAQ,EAAE,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,MAAK,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACpC,CAAC,CAAA,EAAA,EACJ,MAAM,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,CAAC,GAAG,EAAE,EAAA,CAAA,CAC1E,CAAC;KACN;AACL;;;;"}